@seafile/sdoc-editor 1.0.38 → 1.0.40

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.
@@ -4,6 +4,8 @@
4
4
  }
5
5
 
6
6
  .sdoc-dropdown-menu .sdoc-seatable-selected-table-list-wrapper {
7
+ position: absolute;
8
+ background-color: #ffff;
7
9
  max-height: 300px;
8
10
  overflow: auto;
9
11
  }
@@ -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]);
@@ -17,7 +17,8 @@ const withCallout = editor => {
17
17
  insertFragment,
18
18
  deleteBackward,
19
19
  onHotKeyDown,
20
- insertData
20
+ insertData,
21
+ onCopy
21
22
  } = editor;
22
23
  const newEditor = editor;
23
24
  newEditor.deleteBackward = unit => {
@@ -105,6 +106,7 @@ const withCallout = editor => {
105
106
  if (getCalloutEntry(editor)) {
106
107
  event.stopPropagation();
107
108
  }
109
+ return onCopy(event);
108
110
  };
109
111
  return newEditor;
110
112
  };
@@ -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;
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useCallback } from 'react';
1
+ import React, { useMemo, useCallback, useRef, useEffect, useState } from 'react';
2
2
  import { COLUMNS_ICON_CONFIG } from '../constants/column';
3
3
  import { insertSeaTableColumn, getColumnType } from '../helpers';
4
4
  import { COLUMN } from '../../../constants/element-type';
@@ -9,7 +9,21 @@ export default function ColumnListMenu(_ref) {
9
9
  editor,
10
10
  insertPosition
11
11
  } = _ref;
12
- const computedBottom = insertPosition ? '0px' : '';
12
+ const columnRef = useRef(null);
13
+ const [computedStyle, setComputedStyle] = useState({});
14
+ useEffect(() => {
15
+ if (insertPosition) {
16
+ setComputedStyle({
17
+ bottom: '0px'
18
+ });
19
+ }
20
+ if (!insertPosition && (columnRef === null || columnRef === void 0 ? void 0 : columnRef.current)) {
21
+ const centerPosition = parseInt(columnRef.current.getBoundingClientRect().height / 2);
22
+ setComputedStyle({
23
+ top: "-".concat(centerPosition, "px")
24
+ });
25
+ }
26
+ }, [insertPosition]);
13
27
  const columns = useMemo(() => {
14
28
  if (!editor.columns) return [];
15
29
  return editor.columns.filter(column => !NOT_SUPPORT_COLUMN_TYPES.includes(column.type));
@@ -32,10 +46,9 @@ export default function ColumnListMenu(_ref) {
32
46
  insertSeaTableColumn(editor, active, option, insertPosition);
33
47
  }, [editor, insertPosition]);
34
48
  return /*#__PURE__*/React.createElement("div", {
49
+ ref: columnRef,
35
50
  className: "column-list-menu",
36
- style: {
37
- bottom: computedBottom
38
- }
51
+ style: computedStyle
39
52
  }, options.map(option => {
40
53
  return /*#__PURE__*/React.createElement("div", {
41
54
  key: option.value,
@@ -1,8 +1,9 @@
1
- import React, { useCallback } from 'react';
1
+ import React, { useCallback, useRef } from 'react';
2
2
  import { UncontrolledPopover } from 'reactstrap';
3
3
  import { insertSeaTableTable, isInsertSeaTableTableDisabled } from '../helpers';
4
4
  import { MENUS_CONFIG_MAP, SEATABLE_TABLE } from '../../../constants';
5
5
  import DropdownMenuItem from '../../../commons/dropdown-menu-item';
6
+ import SeaTableList from './seatable-list';
6
7
  import './index.css';
7
8
  const SeaTableTableMenu = _ref => {
8
9
  let {
@@ -10,10 +11,9 @@ const SeaTableTableMenu = _ref => {
10
11
  readonly,
11
12
  insertPosition
12
13
  } = _ref;
14
+ const seatableRef = useRef(null);
13
15
  const disabled = isInsertSeaTableTableDisabled(editor, readonly);
14
16
  const menuConfig = MENUS_CONFIG_MAP[SEATABLE_TABLE];
15
- const computedBottom = insertPosition ? '0px' : '';
16
- const tables = editor.tables;
17
17
  const onViewClick = useCallback(item => {
18
18
  insertSeaTableTable(editor, item, insertPosition);
19
19
  }, [editor, insertPosition]);
@@ -29,18 +29,13 @@ const SeaTableTableMenu = _ref => {
29
29
  className: "sdoc-menu-popover sdoc-dropdown-menu sdoc-sub-dropdown-menu",
30
30
  placement: "right-start",
31
31
  hideArrow: true,
32
- fade: false
33
- }, /*#__PURE__*/React.createElement("div", {
34
- className: "sdoc-dropdown-menu-container sdoc-seatable-selected-table-list-wrapper",
35
- style: {
36
- bottom: computedBottom
37
- }
38
- }, tables.map(item => {
39
- return /*#__PURE__*/React.createElement("div", {
40
- key: item._id,
41
- className: "sdoc-dropdown-menu-item",
42
- onClick: () => onViewClick(item)
43
- }, item.name);
44
- })))));
32
+ fade: false,
33
+ ref: seatableRef
34
+ }, /*#__PURE__*/React.createElement(SeaTableList, {
35
+ editor: editor,
36
+ readonly: readonly,
37
+ insertPosition: insertPosition,
38
+ onViewClick: onViewClick
39
+ }))));
45
40
  };
46
41
  export default SeaTableTableMenu;
@@ -0,0 +1,37 @@
1
+ import React, { useState, useEffect, useRef } from 'react';
2
+ const SeaTableList = _ref => {
3
+ let {
4
+ editor,
5
+ insertPosition,
6
+ onViewClick
7
+ } = _ref;
8
+ const seatableRef = useRef(null);
9
+ const [computedStyle, setComputedStyle] = useState({});
10
+ const tables = editor.tables;
11
+ useEffect(() => {
12
+ if (insertPosition) {
13
+ setComputedStyle({
14
+ bottom: '0px'
15
+ });
16
+ }
17
+ if (!insertPosition && (seatableRef === null || seatableRef === void 0 ? void 0 : seatableRef.current)) {
18
+ const centerPosition = parseInt(seatableRef.current.getBoundingClientRect().height / 2);
19
+ // 30 is seatable menu height
20
+ setComputedStyle({
21
+ top: "-".concat(centerPosition + 30, "px")
22
+ });
23
+ }
24
+ }, [insertPosition]);
25
+ return /*#__PURE__*/React.createElement("div", {
26
+ ref: seatableRef,
27
+ className: "sdoc-dropdown-menu-container sdoc-seatable-selected-table-list-wrapper",
28
+ style: computedStyle
29
+ }, tables.map(item => {
30
+ return /*#__PURE__*/React.createElement("div", {
31
+ key: item._id,
32
+ className: "sdoc-dropdown-menu-item",
33
+ onClick: () => onViewClick(item)
34
+ }, item.name);
35
+ }));
36
+ };
37
+ export default SeaTableList;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",