diff --git a/public/src/components/Dropdown/Dropdown.tsx b/public/src/components/Dropdown/Dropdown.tsx
index 8b1c78a5..1fbbaceb 100644
--- a/public/src/components/Dropdown/Dropdown.tsx
+++ b/public/src/components/Dropdown/Dropdown.tsx
@@ -2,7 +2,6 @@ import {ScReact} from '@veglem/screact';
import './Dropdown.sass';
import {Img} from '../Image/Image';
import {AppDispatcher} from '../../modules/dispatcher';
-import {AppNoteStore, NoteStoreActions} from '../../modules/stores/NoteStore';
import {AppNotesStore, NotesActions} from '../../modules/stores/NotesStore';
import {MAX_ATTACH_SIZE} from '../../utils/consts';
import {AppToasts} from '../../modules/toasts';
@@ -47,9 +46,6 @@ export class Dropdown extends ScReact.Component
{
};
handleOnClick = (id:string) => {
- let tag = id;
- let attr = null;
- let content = [];
if (id === "h1") {
insertBlockPlugin('header', 'h1')
diff --git a/public/src/components/Editor/Editor.ts b/public/src/components/Editor/Editor.ts
index 8aec5255..2d17e672 100644
--- a/public/src/components/Editor/Editor.ts
+++ b/public/src/components/Editor/Editor.ts
@@ -35,6 +35,30 @@ export class Editor {
this.tippyCallbacks = tippy;
this.addPlugins();
+ document.onpaste = (event) => {
+ const isInEditor = (node: Node) => {
+ if (node.nodeType === Node.ELEMENT_NODE && (node as HTMLElement).contentEditable === 'true' && !(node as HTMLElement).classList.contains("note-title")) {
+ return true
+ } else if (node.parentElement == null) {
+ return false
+ } else {
+ return isInEditor(node.parentElement);
+ }
+ }
+
+
+
+ if (isInEditor(document.getSelection().anchorNode)) {
+ event.preventDefault();
+ let paste = (event.clipboardData).getData("text");
+ const selection = window.getSelection();
+ if (!selection.rangeCount) return;
+ selection.deleteFromDocument();
+ selection.getRangeAt(0).insertNode(document.createTextNode(paste));
+ selection.collapseToEnd();
+ }
+ }
+
this.editable = document.createElement('div');
this.editable.id = "note-editor-inner"
this.editable.contentEditable = "true";
@@ -105,7 +129,7 @@ export class Editor {
: selection.anchorNode.parentElement;
scanTree(this.editable);
- console.log(`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replaceAll('-','').toLowerCase()}`)
+
elem.dataset[`cursor${AppUserStore.state.username}${AppNotesStore.socket_id?.toString().replaceAll('-','').toLowerCase()}`] = `${getCaretPosition(elem)}`;
// elem.scrollIntoView();
diff --git a/public/src/components/Editor/Plugin.ts b/public/src/components/Editor/Plugin.ts
index c4a7723c..104d30bc 100644
--- a/public/src/components/Editor/Plugin.ts
+++ b/public/src/components/Editor/Plugin.ts
@@ -1,10 +1,11 @@
import {AppUserStore} from "../../modules/stores/UserStore";
import {parseNoteTitle, setCursorAtNodePosition, truncate} from "../../modules/utils";
import {AppNotesStore, NotesActions} from "../../modules/stores/NotesStore";
-import {AppNoteRequests} from "../../modules/api";
+import {AppNoteRequests, AppSharedNoteRequests} from '../../modules/api';
import {AppDispatcher} from "../../modules/dispatcher";
import {AppToasts} from "../../modules/toasts";
import {AppNoteStore, NoteStoreActions} from "../../modules/stores/NoteStore";
+import {AppRouter} from '../../modules/router';
interface EditorPlugin {
pluginName: string;
@@ -494,8 +495,6 @@ export const defaultPlugins: EditorPlugin[] = [
img.dataset.imgid = id;
img.className = "img"
-
-
if (id in AppNoteStore.state.cache) {
img.src = AppNoteStore.state.cache[id]
} else {
@@ -503,7 +502,7 @@ export const defaultPlugins: EditorPlugin[] = [
img.src = url;
AppDispatcher.dispatch(NoteStoreActions.PUT_TO_CACHE, {key: id, value: url})
}).catch(error => {
- console.log(error)
+
})
}
@@ -525,7 +524,7 @@ export const defaultPlugins: EditorPlugin[] = [
img.src = url;
AppDispatcher.dispatch(NoteStoreActions.PUT_TO_CACHE, {key: id, value: url})
}).catch(error => {
- console.log(error)
+
})
return img
@@ -912,7 +911,7 @@ export const insertBlockPlugin = (pluginName: string, ...args: any) => {
});
}
const newNode = plugin.insertNode([], args);
- console.log(newNode)
+
if (newNode) {
(nodeToReplace as HTMLElement).replaceWith(newNode);
document.getSelection().setPosition(newNode, 0);
@@ -1051,6 +1050,8 @@ const RenderAttach = (attach_filename:string, attach_id:string) => {
}
const RenderSubNote = (subNoteId:string) => {
+
+
const subNoteWrapper = document.createElement("button")
subNoteWrapper.className = "subnote-wrapper"
@@ -1072,8 +1073,9 @@ const RenderSubNote = (subNoteId:string) => {
subNoteContainer.appendChild(subNoteTitle)
const isOwner= AppNotesStore.state.selectedNote?.owner_id == AppUserStore.state.user_id
+ const isAuth = AppUserStore.state.isAuth
- if (isOwner) {
+ if (isAuth && isOwner && pluginSettings.isEditable) {
const deleteSubNoteBtnContainer = document.createElement("div")
deleteSubNoteBtnContainer.className = "delete-subnote-btn-container"
@@ -1095,7 +1097,6 @@ const RenderSubNote = (subNoteId:string) => {
}
}
-
deleteSubNoteBtnContainer.appendChild(deleteSubNoteBtn)
subNoteContainer.appendChild(deleteSubNoteBtnContainer)
}
@@ -1104,35 +1105,58 @@ const RenderSubNote = (subNoteId:string) => {
let loaded = false
- if (subNoteId in AppNoteStore.state.cache) {
- subNoteTitle.innerHTML = AppNoteStore.state.cache[subNoteId]
- loaded = true
- } else {
- AppNoteRequests.Get(subNoteId, AppUserStore.state.JWT).then(result => {
+ // if (subNoteId in AppNoteStore.state.cache) {
+ // subNoteTitle.innerHTML = AppNoteStore.state.cache[subNoteId]
+ // loaded = true
+ // } else {
+ //
+ // const request = pluginSettings.isEditable ? AppNoteRequests.Get(subNoteId, AppUserStore.state.JWT) : AppSharedNoteRequests.Get(subNoteId)
+ // request.then(result => {
+ // if (result.data.title == null) {
+ // subNoteTitle.innerHTML = 'Подзаметка'
+ // }
+ //
+ // //subNoteWrapper.dataset.title = parseNoteTitle(result.data.title)
+ // subNoteTitle.innerHTML = parseNoteTitle(result.data.title)
+ //
+ // AppDispatcher.dispatch(NoteStoreActions.PUT_TO_CACHE, {key: subNoteId, value: parseNoteTitle(result.data.title)})
+ //
+ // loaded = true
+ //
+ // }).catch((e) => {
+ // subNoteTitle.innerHTML = "Заметка не найдена"
+ // subNoteWrapper.dataset.deleted = "true"
+ // });
+ // }
+
+ const request = pluginSettings.isEditable ? AppNoteRequests.Get(subNoteId, AppUserStore.state.JWT) : AppSharedNoteRequests.Get(subNoteId)
+ request.then(result => {
if (result.data.title == null) {
subNoteTitle.innerHTML = 'Подзаметка'
}
- //subNoteWrapper.dataset.title = parseNoteTitle(result.data.title)
subNoteTitle.innerHTML = parseNoteTitle(result.data.title)
- AppDispatcher.dispatch(NoteStoreActions.PUT_TO_CACHE, {key: subNoteId, value: parseNoteTitle(result.data.title)})
-
loaded = true
}).catch((e) => {
subNoteTitle.innerHTML = "Заметка не найдена"
subNoteWrapper.dataset.deleted = "true"
});
- }
- if (pluginSettings.isEditable) {
- subNoteWrapper.onclick = () => {
- if (!subNoteWrapper.dataset.deleted && loaded) {
+ subNoteWrapper.onclick = () => {
+ if (!subNoteWrapper.dataset.deleted && loaded) {
+ if (isAuth) {
AppDispatcher.dispatch(NotesActions.OPEN_NOTE, subNoteId)
} else {
- AppToasts.error("Заметка не найдена")
+ AppSharedNoteRequests.Get(subNoteId).then(result => {
+ AppRouter.openSharedNotePage(result)
+ }).catch((e) => {
+ AppToasts.error("Заметка не найдена")
+ });
}
+ } else {
+ AppToasts.error("Заметка не найдена")
}
}
diff --git a/public/src/components/Editor/EditorWrapper.tsx b/public/src/components/EditorWrapper/EditorWrapper.tsx
similarity index 95%
rename from public/src/components/Editor/EditorWrapper.tsx
rename to public/src/components/EditorWrapper/EditorWrapper.tsx
index 8c127468..9b372798 100644
--- a/public/src/components/Editor/EditorWrapper.tsx
+++ b/public/src/components/EditorWrapper/EditorWrapper.tsx
@@ -1,13 +1,13 @@
import {Component} from "@veglem/screact/dist/component";
import {VDomNode} from "@veglem/screact/dist/vdom";
-import "./Editor.sass"
-import {Editor} from "./Editor";
+import "../Editor/Editor.sass"
+import {Editor} from "../Editor/Editor";
import {AppNoteStore, NoteStoreState} from "../../modules/stores/NoteStore";
import {Tippy} from "../Tippy/Tippy";
import {isEqual} from "@veglem/screact/dist/isEqual";
-import {Viewer} from "./Viewer";
+import {Viewer} from "../Editor/Viewer";
import {NoteType} from "../../utils/types";
-import {PluginProps} from "./Plugin";
+import {PluginProps} from "../Editor/Plugin";
import {parseNoteTitle} from "../../modules/utils";
window['mobileCheck'] = function() {
@@ -61,7 +61,7 @@ export class EditorWrapper extends Component {
updateState = (store:NoteStoreState) => {
this.syncTitle(store.note.title)
- if (!this.props.isOwner && this.props.note?.public) {
+ if (!this.props.isOwner && this.props.note?.public && !this.props.isEditable) {
this.self.innerHTML = ""
new Viewer(
store.note.blocks,
diff --git a/public/src/components/Header/Header.tsx b/public/src/components/Header/Header.tsx
index 1342ff1c..e96ac6b4 100644
--- a/public/src/components/Header/Header.tsx
+++ b/public/src/components/Header/Header.tsx
@@ -1,6 +1,5 @@
import {ScReact} from '@veglem/screact';
import './Header.sass';
-import {Button} from '../Button/Button';
import {AppRouter} from '../../modules/router';
import {Logo} from '../Logo/logo';
import {Profile} from '../Profile/Profile';
@@ -8,6 +7,7 @@ import {AuthPage} from '../../pages/Auth';
import {AppUserStore, UserActions, UserStoreState} from '../../modules/stores/UserStore';
import {AppDispatcher} from '../../modules/dispatcher';
import {AppNotesStore, NotesStoreState} from "../../modules/stores/NotesStore";
+import {uiKit} from '@veglem/ui-kit/dist/ui';
export class Header extends ScReact.Component{
state = {
@@ -44,6 +44,8 @@ export class Header extends ScReact.Component{
};
render() {
+ const {Button} = uiKit
+
return (