@seafile/sdoc-editor 1.0.37 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -123,26 +123,20 @@ const FileLinkInsertDialog = _ref => {
123
123
  break;
124
124
  }
125
125
  }, [closeDialog, deleteInputAndInsertText]);
126
- const onInsertLink = useCallback(params => {
127
- insertSdocFileLink(editor, params.data.obj_name, params.data.doc_uuid);
128
- removeTempInput();
129
- }, [editor]);
130
126
  useEffect(() => {
131
127
  getPosition();
132
128
  const sdocScrollContainer = document.getElementById('sdoc-scroll-container');
133
129
  document.addEventListener('click', onClick);
134
130
  document.addEventListener('keydown', onKeydown);
135
131
  sdocScrollContainer.addEventListener('scroll', onScroll);
136
- const unsubscribeInsertLink = eventBus.subscribe(EXTERNAL_EVENT.INSERT_LINK, onInsertLink);
137
132
  const unsubscribeCloseDialog = eventBus.subscribe(INTERNAL_EVENT.CLOSE_FILE_INSET_DIALOG, closeDialog);
138
133
  return () => {
139
134
  sdocScrollContainer.removeEventListener('scroll', onScroll);
140
135
  document.removeEventListener('click', onClick);
141
136
  document.removeEventListener('keydown', onKeydown);
142
- unsubscribeInsertLink();
143
137
  unsubscribeCloseDialog();
144
138
  };
145
- }, [closeDialog, editor, eventBus, files, getPosition, onClick, onInsertLink, onKeydown, onScroll]);
139
+ }, [closeDialog, editor, eventBus, files, getPosition, onClick, onKeydown, onScroll]);
146
140
  const onSearch = useCallback(async searchText => {
147
141
  // Show history files when search is empty
148
142
  if (searchText.trim().length === 0) {
@@ -206,13 +200,22 @@ const FileLinkInsertDialog = _ref => {
206
200
  });
207
201
  removeTempInput(editor, element);
208
202
  }, [editor, element, eventBus]);
209
- const onCreateFile = useCallback(() => {
203
+ const onCreateFile = useCallback(e => {
204
+ e.stopPropagation();
205
+ removeTempInput(editor, element);
210
206
  const eventBus = EventBus.getInstance();
211
207
  const dispatchEventKey = editor.editorType === WIKI_EDITOR ? EXTERNAL_EVENT.CREATE_WIKI_PAGE : EXTERNAL_EVENT.CREATE_SDOC_FILE;
212
- eventBus.dispatch(dispatchEventKey, {
208
+ let external_props = {};
209
+ if (dispatchEventKey === EXTERNAL_EVENT.CREATE_SDOC_FILE) {
210
+ external_props = {
211
+ insertSdocFileLink,
212
+ editor
213
+ };
214
+ }
215
+ eventBus.dispatch(dispatchEventKey, _objectSpread({
213
216
  newFileName: newFileName.trim()
214
- });
215
- }, [editor.editorType, newFileName]);
217
+ }, external_props));
218
+ }, [editor, element, newFileName]);
216
219
  const createFileTipDefault = useMemo(() => {
217
220
  return editor.editorType === WIKI_EDITOR ? 'New_page' : 'Create_a_new_sdoc_file';
218
221
  }, [editor.editorType]);
@@ -1,4 +1,4 @@
1
- import { Transforms, Node, Editor } from '@seafile/slate';
1
+ import { Transforms, Node, Editor, Range } from '@seafile/slate';
2
2
  import { ReactEditor } from '@seafile/slate-react';
3
3
  import { FILE_LINK_INSET_INPUT_TEMP, SDOC_LINK } from '../../constants';
4
4
  import { getFileSearchInputEntry, insertTempInput, isTriggeredByShortcut } from './helpers';
@@ -9,7 +9,8 @@ const withSdocLink = editor => {
9
9
  isInline,
10
10
  deleteBackward,
11
11
  insertText,
12
- onCompositionStart
12
+ onCompositionStart,
13
+ onHotKeyDown
13
14
  } = editor;
14
15
  const newEditor = editor;
15
16
 
@@ -72,6 +73,39 @@ const withSdocLink = editor => {
72
73
  }
73
74
  return onCompositionStart && onCompositionStart(event);
74
75
  };
76
+ newEditor.onHotKeyDown = e => {
77
+ const {
78
+ selection
79
+ } = newEditor;
80
+ const isCollapsed = Range.isCollapsed(selection);
81
+ if (isCollapsed) {
82
+ if (e.key === 'ArrowLeft') {
83
+ const prePoint = Editor.before(newEditor, selection);
84
+ const [preNode, prePath] = Editor.node(newEditor, prePoint.path, {
85
+ depth: 2
86
+ });
87
+ if ((preNode === null || preNode === void 0 ? void 0 : preNode.type) === SDOC_LINK) {
88
+ const beforePointSdocLink = Editor.before(newEditor, prePath);
89
+ Transforms.select(newEditor, beforePointSdocLink);
90
+ e.preventDefault();
91
+ return;
92
+ }
93
+ }
94
+ if (e.key === 'ArrowRight') {
95
+ const nextPoint = Editor.after(newEditor, selection);
96
+ const [nextNode, nextPath] = Editor.node(newEditor, nextPoint.path, {
97
+ depth: 2
98
+ });
99
+ if ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === SDOC_LINK) {
100
+ const afterPointSdocLink = Editor.after(newEditor, nextPath);
101
+ Transforms.select(newEditor, afterPointSdocLink);
102
+ e.preventDefault();
103
+ return;
104
+ }
105
+ }
106
+ }
107
+ return onHotKeyDown && onHotKeyDown(e);
108
+ };
75
109
  return newEditor;
76
110
  };
77
111
  export default withSdocLink;
@@ -11,6 +11,10 @@ const Layout = _ref => {
11
11
  } = _ref,
12
12
  restProps = _objectWithoutProperties(_ref, _excluded);
13
13
  const cacheHistoryfiles = () => {
14
+ const isPublished = context.getSetting('isPublished') || false;
15
+ const isSdocRevision = context.getSetting('isSdocRevision') || false;
16
+ if (isPublished) return;
17
+ if (isSdocRevision) return;
14
18
  const docUuid = context.getSetting('docUuid');
15
19
  const docName = context.getSetting('docName');
16
20
  const rencentFiles = LocalStorage.getItem('sdoc-recent-files', []);
@@ -44,6 +48,7 @@ const Layout = _ref => {
44
48
  }
45
49
  }, 500);
46
50
  cacheHistoryfiles();
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
52
  }, []);
48
53
  return /*#__PURE__*/React.createElement("div", Object.assign({
49
54
  className: classnames('sdoc-editor-page-wrapper', className)
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {
8
- "@seafile/print-js": "1.6.5",
8
+ "@seafile/print-js": "1.6.6",
9
9
  "@seafile/react-image-lightbox": "2.0.4",
10
10
  "@seafile/slate": "0.91.8",
11
11
  "@seafile/slate-history": "0.86.2",