@seafile/sdoc-editor 0.1.142-beta → 0.1.143

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.
Files changed (44) hide show
  1. package/dist/api/sdoc-server-api.js +0 -15
  2. package/dist/api/seafile-api.js +5 -27
  3. package/dist/basic-sdk/constants/index.js +1 -14
  4. package/dist/basic-sdk/editor.js +105 -0
  5. package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +12 -3
  6. package/dist/basic-sdk/extension/constants/index.js +2 -0
  7. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +0 -26
  8. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +2 -20
  9. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -6
  10. package/dist/basic-sdk/extension/plugins/html/plugin.js +23 -2
  11. package/dist/basic-sdk/extension/plugins/image/helpers.js +13 -3
  12. package/dist/basic-sdk/extension/plugins/link/dialog/add-link-dialog/index.js +2 -1
  13. package/dist/basic-sdk/extension/plugins/link/helpers.js +14 -4
  14. package/dist/basic-sdk/extension/plugins/link/plugin.js +8 -13
  15. package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +30 -2
  16. package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -3
  17. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +5 -2
  18. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +13 -8
  19. package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +7 -4
  20. package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +13 -2
  21. package/dist/basic-sdk/{editor/slate-editor.js → slate-editor.js} +16 -21
  22. package/dist/basic-sdk/socket/helpers.js +0 -1
  23. package/dist/basic-sdk/socket/socket-client.js +0 -5
  24. package/dist/basic-sdk/socket/socket-manager.js +2 -8
  25. package/dist/basic-sdk/socket/with-socket-io.js +12 -20
  26. package/dist/basic-sdk/utils/diff.js +2 -2
  27. package/dist/basic-sdk/views/diff-viewer.js +1 -3
  28. package/dist/basic-sdk/views/viewer.js +11 -8
  29. package/dist/components/doc-operations/index.js +2 -8
  30. package/dist/components/doc-operations/revision-operations/index.js +3 -11
  31. package/dist/components/doc-operations/revision-operations/publish-button.js +13 -16
  32. package/dist/constants/index.js +1 -8
  33. package/dist/context.js +4 -30
  34. package/dist/pages/simple-editor.js +71 -221
  35. package/package.json +1 -1
  36. package/public/locales/en/sdoc-editor.json +1 -7
  37. package/public/locales/zh_CN/sdoc-editor.json +1 -7
  38. package/dist/basic-sdk/editor/common-editor.js +0 -45
  39. package/dist/basic-sdk/editor/index.js +0 -135
  40. package/dist/basic-sdk/editor/rebase-editor/index.css +0 -29
  41. package/dist/basic-sdk/editor/rebase-editor/index.js +0 -276
  42. package/dist/basic-sdk/utils/rebase.js +0 -193
  43. package/dist/components/tip-dialog/index.css +0 -0
  44. package/dist/components/tip-dialog/index.js +0 -45
@@ -58,21 +58,6 @@ var SDocServerApi = /*#__PURE__*/function () {
58
58
  }
59
59
  });
60
60
  }
61
- }, {
62
- key: "saveDocContentByRebase",
63
- value: function saveDocContentByRebase(content) {
64
- var server = this.server,
65
- docUuid = this.docUuid,
66
- accessToken = this.accessToken;
67
- var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/rebase/");
68
- var formData = new FormData();
69
- formData.append('doc_content', JSON.stringify(content));
70
- return axios.post(url, formData, {
71
- headers: {
72
- Authorization: "Token ".concat(accessToken)
73
- }
74
- });
75
- }
76
61
  }, {
77
62
  key: "getCollaborators",
78
63
  value: function getCollaborators() {
@@ -48,11 +48,9 @@ var SeafileAPI = /*#__PURE__*/function () {
48
48
  }
49
49
  }, {
50
50
  key: "sdocPublishRevision",
51
- value: function sdocPublishRevision(docUuid, replace) {
51
+ value: function sdocPublishRevision(docUuid) {
52
52
  var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
53
- var form = new FormData();
54
- form.append('replace', replace);
55
- return this._sendPostRequest(url, form);
53
+ return this.req.post(url);
56
54
  }
57
55
  }, {
58
56
  key: "startRevise",
@@ -65,9 +63,9 @@ var SeafileAPI = /*#__PURE__*/function () {
65
63
  return this._sendPostRequest(url, form);
66
64
  }
67
65
  }, {
68
- key: "getSeadocOriginFileDownloadLink",
69
- value: function getSeadocOriginFileDownloadLink(docUuid) {
70
- var url = '/api/v2.1/seadoc/origin-file-download-link/' + docUuid + '/';
66
+ key: "getSeadocRevisionDownloadLinks",
67
+ value: function getSeadocRevisionDownloadLinks(docUuid) {
68
+ var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
71
69
  return this.req.get(url);
72
70
  }
73
71
  }, {
@@ -83,26 +81,6 @@ var SeafileAPI = /*#__PURE__*/function () {
83
81
  var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
84
82
  return this.req.get(url);
85
83
  }
86
- }, {
87
- key: "deleteSdocRevision",
88
- value: function deleteSdocRevision(docUuid) {
89
- var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
90
- return this.req.delete(url);
91
- }
92
- }, {
93
- key: "rebaseSdocRevision",
94
- value: function rebaseSdocRevision(docUuid) {
95
- var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
96
- return this.req.put(url);
97
- }
98
- }, {
99
- key: "getFileHistoryVersion",
100
- value: function getFileHistoryVersion(docUuid, fileVersion, docPath) {
101
- var url = 'api/v2.1/seadoc/history-content/' + docUuid + '/?p=' + encodeURIComponent(docPath) + '&file_version=' + fileVersion;
102
- return this.req.get(url);
103
- }
104
-
105
- // local files
106
84
  }, {
107
85
  key: "getSdocFiles",
108
86
  value: function getSdocFiles(docUuid, p) {
@@ -5,17 +5,4 @@ export var INTERNAL_EVENT = {
5
5
  ON_MOUSE_ENTER_BLOCK: 'on_mouse_enter_block',
6
6
  INSERT_ELEMENT: 'insert_element'
7
7
  };
8
- export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
9
-
10
- export var MODIFY_TYPE = {
11
- ADD: 'add',
12
- DELETE: 'delete',
13
- MODIFY: 'modify',
14
- CHILDREN_MODIFY: 'children-modify'
15
- };
16
- export var REBASE_TYPE = {
17
- MODIFY_MODIFY: 'modify-modify',
18
- DELETE_MODIFY: 'delete-modify',
19
- CHILDREN_MODIFY: 'children-modify'
20
- };
21
- export var REBASE_MARKS = ['origin', 'rebaseType', 'oldElement'];
8
+ export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
@@ -0,0 +1,105 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
3
+ import { Editor } from '@seafile/slate';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { createDefaultEditor } from './extension';
6
+ import { focusEditor } from './extension/core';
7
+ import { withSocketIO } from './socket';
8
+ import withNodeId from './node-id';
9
+ import { PAGE_EDIT_AREA_WIDTH } from './constants';
10
+ import context from '../context';
11
+ import { EditorContainer, EditorContent } from './layout';
12
+ import SlateEditor from './slate-editor';
13
+ import InsertElementDialog from './extension/commons/insert-element-dialog';
14
+ var SDocEditor = forwardRef(function (_ref, ref) {
15
+ var document = _ref.document,
16
+ config = _ref.config;
17
+ var _useTranslation = useTranslation(),
18
+ t = _useTranslation.t;
19
+
20
+ // init editor
21
+ var editor = useMemo(function () {
22
+ var defaultEditor = createDefaultEditor();
23
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
+ document: document,
25
+ config: config
26
+ }));
27
+ var cursors = document.cursors;
28
+ newEditor.cursors = cursors || {};
29
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
+ newEditor.readonly = false;
31
+ return newEditor;
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
34
+ var _useState = useState(document.children),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ slateValue = _useState2[0],
37
+ setSlateValue = _useState2[1];
38
+
39
+ // The parent component can call the method of this component through ref
40
+ useImperativeHandle(ref, function () {
41
+ return {
42
+ // get latest value
43
+ getValue: function getValue() {
44
+ return slateValue;
45
+ }
46
+ };
47
+ }, [slateValue]);
48
+
49
+ // useMount: init socket connection
50
+ useEffect(function () {
51
+ editor.openConnection();
52
+ return function () {
53
+ editor.closeConnection();
54
+ };
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, []);
57
+
58
+ // useMount: focus editor
59
+ useEffect(function () {
60
+ var timer = setTimeout(function () {
61
+ var _editor$children = _slicedToArray(editor.children, 1),
62
+ firstNode = _editor$children[0];
63
+ if (firstNode) {
64
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
65
+ firstNodeFirstChild = _firstNode$children[0];
66
+ if (firstNodeFirstChild) {
67
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
68
+ var range = {
69
+ anchor: endOfFirstNode,
70
+ focus: endOfFirstNode
71
+ };
72
+ focusEditor(editor, range);
73
+ }
74
+ }
75
+ }, 300);
76
+ return function () {
77
+ clearTimeout(timer);
78
+ };
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, []);
81
+
82
+ // useMount: reset title
83
+ useEffect(function () {
84
+ var isSdocRevision = context.getSetting('isSdocRevision');
85
+ var originFilename = context.getSetting('originFilename');
86
+ if (isSdocRevision) {
87
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
88
+ }
89
+
90
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
+ }, []);
92
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
93
+ editor: editor
94
+ }, /*#__PURE__*/React.createElement(EditorContent, {
95
+ docValue: slateValue,
96
+ showOutline: true
97
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
98
+ editor: editor,
99
+ slateValue: slateValue,
100
+ setSlateValue: setSlateValue
101
+ }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
102
+ editor: editor
103
+ }));
104
+ });
105
+ export default SDocEditor;
@@ -23,16 +23,21 @@ var InsertElementDialog = function InsertElementDialog(_ref) {
23
23
  _useState6 = _slicedToArray(_useState5, 2),
24
24
  insertPosition = _useState6[0],
25
25
  setInsertPosition = _useState6[1];
26
+ var _useState7 = useState(null),
27
+ _useState8 = _slicedToArray(_useState7, 2),
28
+ slateNode = _useState8[0],
29
+ setSlateNode = _useState8[1];
26
30
  var uploadLocalImageInputRef = useRef();
27
31
  var onFileChanged = useCallback(function (event) {
28
32
  var file = event.target.files[0];
29
33
  context.uploadLocalImage(file).then(function (fileUrl) {
30
- insertImage(editor, fileUrl, editor.selection, insertPosition);
34
+ insertImage(editor, fileUrl, editor.selection, insertPosition, slateNode);
31
35
  if (uploadLocalImageInputRef.current) {
32
36
  uploadLocalImageInputRef.current.value = '';
33
37
  }
34
38
  });
35
- }, [editor, uploadLocalImageInputRef, insertPosition]);
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [editor, uploadLocalImageInputRef, insertPosition, slateNode]);
36
41
  useEffect(function () {
37
42
  var eventBus = EventBus.getInstance();
38
43
  var toggleDialogSubscribe = eventBus.subscribe(INTERNAL_EVENT.INSERT_ELEMENT, toggleDialog);
@@ -46,8 +51,10 @@ var InsertElementDialog = function InsertElementDialog(_ref) {
46
51
  var type = _ref2.type,
47
52
  element = _ref2.element,
48
53
  _ref2$insertPosition = _ref2.insertPosition,
49
- insertPosition = _ref2$insertPosition === void 0 ? INSERT_POSITION.CURRENT : _ref2$insertPosition;
54
+ insertPosition = _ref2$insertPosition === void 0 ? INSERT_POSITION.CURRENT : _ref2$insertPosition,
55
+ slateNode = _ref2.slateNode;
50
56
  setInsertPosition(insertPosition);
57
+ setSlateNode(slateNode);
51
58
  setElement(element);
52
59
  setDialogType(type);
53
60
  if (type === INSERT_IMAGE_TYPE.LOCAL_IMAGE) {
@@ -58,11 +65,13 @@ var InsertElementDialog = function InsertElementDialog(_ref) {
58
65
  }, [uploadLocalImageInputRef]);
59
66
  var closeDialog = useCallback(function () {
60
67
  setInsertPosition(INSERT_POSITION.CURRENT);
68
+ setSlateNode(null);
61
69
  setElement('');
62
70
  setDialogType('');
63
71
  }, []);
64
72
  var props = {
65
73
  insertPosition: insertPosition,
74
+ slateNode: slateNode,
66
75
  editor: editor,
67
76
  element: element,
68
77
  closeDialog: closeDialog
@@ -240,4 +240,6 @@ export var INSERT_IMAGE_TYPE = {
240
240
  LOCAL_IMAGE: 'local-image',
241
241
  WEB_IMAGE: 'web-image'
242
242
  };
243
+ export var LIST_ITEM_CORRELATION_TYPE = ['unordered_list', 'ordered_list', 'list-item'];
244
+ export var LIST_ITEM_SUPPORTED_TRANSFORMATION = ['unordered_list', 'ordered_list', 'left', 'center', 'right', 'blockquote'];
243
245
  export { BLOCKQUOTE, HEADER, TITLE, SUBTITLE, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, MAC_HOTKEYS, WIN_HOTKEYS, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, CLEAR_FORMAT, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BG_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BG_COLOR, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, SDOC_FONT_SIZE, SDOC_LINK };
@@ -12,30 +12,4 @@ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
12
12
  at: at.concat([0])
13
13
  }));
14
14
  });
15
- };
16
- export var replaceNode = function replaceNode(editor) {
17
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
18
- at = _ref2.at,
19
- nodes = _ref2.nodes,
20
- insertOptions = _ref2.insertOptions,
21
- removeOptions = _ref2.removeOptions;
22
- Editor.withoutNormalizing(editor, function () {
23
- Transforms.removeNodes(editor, _objectSpread({
24
- at: at
25
- }, removeOptions));
26
- Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
27
- at: at
28
- }));
29
- });
30
- };
31
- export var deleteNodeMark = function deleteNodeMark(editor, path, element) {
32
- var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
33
- var newElement = _objectSpread({}, element);
34
- marks.forEach(function (markItem) {
35
- newElement[markItem] && delete newElement[markItem];
36
- });
37
- replaceNode(editor, {
38
- at: path,
39
- nodes: newElement
40
- });
41
15
  };
@@ -4,7 +4,7 @@ import _toArray from "@babel/runtime/helpers/esm/toArray";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
5
  import slugid from 'slugid';
6
6
  import isHotkey from 'is-hotkey';
7
- import { Transforms, Node, Range, Editor, Path } from '@seafile/slate';
7
+ import { Transforms, Node, Range, Editor } from '@seafile/slate';
8
8
  import { getNodeType, isLastNode, getSelectedNodeByType, generateEmptyElement } from '../../core';
9
9
  import { deleteBackwardByLength } from './helpers';
10
10
  import { CODE_BLOCK, PARAGRAPH, CODE_LINE } from '../../constants';
@@ -25,29 +25,11 @@ var withCodeBlock = function withCodeBlock(editor) {
25
25
  return insertText(data);
26
26
  };
27
27
  newEditor.insertData = function (data) {
28
- if (!newEditor.insertFragmentData(data) && !data.types.includes('text/code-block')) {
29
- var plaintext = data.getData('text/plain') || '';
30
- if (plaintext) {
31
- var fragmentData = [];
32
- plaintext.split('\n').forEach(function (item) {
33
- var codeLine = {
34
- id: slugid.nice(),
35
- type: CODE_LINE,
36
- children: [{
37
- text: item,
38
- id: slugid.nice()
39
- }]
40
- };
41
- fragmentData.push(codeLine);
42
- });
43
- newEditor.insertFragment(fragmentData);
44
- return;
45
- }
46
- }
47
28
  if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
48
29
  var codeBlockNode = JSON.parse(data.getData('text/code-block'));
49
30
  return insertNode(codeBlockNode);
50
31
  }
32
+ insertData(data);
51
33
  };
52
34
  newEditor.insertFragment = function (data) {
53
35
  // only selected code block content
@@ -124,16 +124,17 @@ var CodeBlock = function CodeBlock(_ref) {
124
124
  eventBus.subscribe(INTERNAL_EVENT.HIDDEN_CODE_BLOCK_HOVER_MENU, onHiddenHoverMenu);
125
125
  // eslint-disable-next-line react-hooks/exhaustive-deps
126
126
  }, []);
127
- return /*#__PURE__*/React.createElement("div", {
127
+ return /*#__PURE__*/React.createElement("div", Object.assign({
128
128
  "data-id": element.id,
129
- "data-root": "true",
130
- ref: codeBlockRef,
129
+ "data-root": "true"
130
+ }, attributes, {
131
131
  className: 'sdoc-code-block-container',
132
132
  onClick: onFocusCodeBlock,
133
133
  onMouseLeave: onMouseLeave
134
- }, /*#__PURE__*/React.createElement("pre", Object.assign({
135
- className: 'sdoc-code-block-pre'
136
- }, attributes), /*#__PURE__*/React.createElement("code", {
134
+ }), /*#__PURE__*/React.createElement("pre", {
135
+ className: 'sdoc-code-block-pre',
136
+ ref: codeBlockRef
137
+ }, /*#__PURE__*/React.createElement("code", {
137
138
  className: "sdoc-code-block-code ".concat(white_space === 'nowrap' ? 'sdoc-code-no-wrap' : '')
138
139
  }, children)), showHoverMenu && /*#__PURE__*/React.createElement(CodeBlockHoverMenu, {
139
140
  menuPosition: menuPosition,
@@ -1,11 +1,32 @@
1
+ import slugid from 'slugid';
1
2
  import { deserializeHtml } from './helper';
2
3
  import { getSelectedNodeByType } from '../../core';
3
- import { CODE_BLOCK } from '../../constants';
4
+ import { CODE_BLOCK, CODE_LINE } from '../../constants';
4
5
  var withHtml = function withHtml(editor) {
5
6
  var insertData = editor.insertData;
6
7
  var newEditor = editor;
7
8
  newEditor.insertData = function (data) {
8
- if (!newEditor.insertFragmentData(data) && !getSelectedNodeByType(editor, CODE_BLOCK)) {
9
+ if (!newEditor.insertFragmentData(data)) {
10
+ // Other document paste content into code block
11
+ if (!data.types.includes('text/code-block') && getSelectedNodeByType(editor, CODE_BLOCK)) {
12
+ var plaintext = data.getData('text/plain') || '';
13
+ if (plaintext) {
14
+ var fragmentData = [];
15
+ plaintext.split('\n').forEach(function (item) {
16
+ var codeLine = {
17
+ id: slugid.nice(),
18
+ type: CODE_LINE,
19
+ children: [{
20
+ text: item,
21
+ id: slugid.nice()
22
+ }]
23
+ };
24
+ fragmentData.push(codeLine);
25
+ });
26
+ newEditor.insertFragment(fragmentData);
27
+ }
28
+ return;
29
+ }
9
30
  var htmlContent = data.getData('text/html') || '';
10
31
  if (htmlContent) {
11
32
  var content = deserializeHtml(htmlContent);
@@ -1,8 +1,9 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import urlJoin from 'url-join';
4
- import { Editor, Range, Transforms } from '@seafile/slate';
5
- import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, INSERT_POSITION } from '../../constants';
4
+ import { Editor, Range, Transforms, Path } from '@seafile/slate';
5
+ import { ReactEditor } from '@seafile/slate-react';
6
+ import { CODE_BLOCK, ELEMENT_TYPE, IMAGE, INSERT_POSITION, LIST_ITEM } from '../../constants';
6
7
  import { generateEmptyElement, getNodeType, isTextNode, getParentNode } from '../../core';
7
8
  import context from '../../../../context';
8
9
  export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor, readonly) {
@@ -39,14 +40,23 @@ export var generateImageNode = function generateImageNode(src) {
39
40
  };
40
41
  export var insertImage = function insertImage(editor, src, selection) {
41
42
  var position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : INSERT_POSITION.CURRENT;
43
+ var slateNode = arguments.length > 4 ? arguments[4] : undefined;
42
44
  if (!src) return;
43
45
  if (position !== INSERT_POSITION.AFTER) {
44
46
  if (isInsertImageMenuDisabled(editor)) return;
45
47
  }
46
48
  var imageNode = generateImageNode(src);
47
49
  var validSelection = selection || editor.selection;
48
- if (position = INSERT_POSITION.AFTER) {
50
+ if (position === INSERT_POSITION.AFTER) {
49
51
  var path = Editor.path(editor, validSelection);
52
+ if (slateNode && (slateNode === null || slateNode === void 0 ? void 0 : slateNode.type) === LIST_ITEM) {
53
+ path = ReactEditor.findPath(editor, slateNode);
54
+ var nextPath = Path.next(path);
55
+ Transforms.insertNodes(editor, imageNode, {
56
+ at: nextPath
57
+ });
58
+ return;
59
+ }
50
60
  var p = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
51
61
  p.children[0] = imageNode;
52
62
  Transforms.insertNodes(editor, p, {
@@ -8,6 +8,7 @@ var AddLinkDialog = function AddLinkDialog(_ref) {
8
8
  className = _ref.className,
9
9
  element = _ref.element,
10
10
  insertPosition = _ref.insertPosition,
11
+ slateNode = _ref.slateNode,
11
12
  closeDialog = _ref.closeDialog;
12
13
  var _useTranslation = useTranslation(),
13
14
  t = _useTranslation.t;
@@ -52,7 +53,7 @@ var AddLinkDialog = function AddLinkDialog(_ref) {
52
53
  if (isEdit) {
53
54
  updateLink(editor, title, url);
54
55
  } else {
55
- insertLink(editor, title, url, insertPosition);
56
+ insertLink(editor, title, url, insertPosition, slateNode);
56
57
  }
57
58
  closeDialog();
58
59
 
@@ -2,9 +2,10 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
- import { Editor, Transforms, Range } from '@seafile/slate';
5
+ import { Editor, Transforms, Range, Path } from '@seafile/slate';
6
+ import { ReactEditor } from '@seafile/slate-react';
6
7
  import slugid from 'slugid';
7
- import { ELEMENT_TYPE, INSERT_POSITION, LINK } from '../../constants';
8
+ import { ELEMENT_TYPE, INSERT_POSITION, LINK, LIST_ITEM } from '../../constants';
8
9
  import { getNodeType, getSelectedElems, getAboveNode, getEditorString, replaceNodeChildren, generateEmptyElement } from '../../core';
9
10
  export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
10
11
  if (readonly) return true;
@@ -55,11 +56,21 @@ export var getLinkType = function getLinkType(editor) {
55
56
  };
56
57
  export var insertLink = function insertLink(editor, title, url) {
57
58
  var position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : INSERT_POSITION.CURRENT;
59
+ var slateNode = arguments.length > 4 ? arguments[4] : undefined;
58
60
  if (position === INSERT_POSITION.CURRENT && isMenuDisabled(editor)) return;
59
61
  if (!title || !url) return;
60
62
  if (position === INSERT_POSITION.AFTER) {
61
- var p = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
62
63
  var linkNode = genLinkNode(url, title);
64
+ var path = Editor.path(editor, editor.selection);
65
+ if (slateNode && (slateNode === null || slateNode === void 0 ? void 0 : slateNode.type) === LIST_ITEM) {
66
+ path = ReactEditor.findPath(editor, slateNode);
67
+ var nextPath = Path.next(path);
68
+ Transforms.insertNodes(editor, linkNode, {
69
+ at: nextPath
70
+ });
71
+ return;
72
+ }
73
+ var p = generateEmptyElement(ELEMENT_TYPE.PARAGRAPH);
63
74
  p.children[0] = {
64
75
  id: slugid.nice(),
65
76
  text: ' '
@@ -69,7 +80,6 @@ export var insertLink = function insertLink(editor, title, url) {
69
80
  id: slugid.nice(),
70
81
  text: ' '
71
82
  };
72
- var path = Editor.path(editor, editor.selection);
73
83
  Transforms.insertNodes(editor, p, {
74
84
  at: [path[0] + 1]
75
85
  });
@@ -32,22 +32,17 @@ var withLink = function withLink(editor) {
32
32
  return insertText(text);
33
33
  };
34
34
  newEditor.insertData = function (data) {
35
- // Paste content from sdoc document
36
- if (newEditor.insertFragmentData(data)) return;
37
-
38
- // Paste content from other document
35
+ // Paste link content
39
36
  var text = data.getData('text/plain');
40
- if (!isUrl(text) && !isImage(text)) {
41
- // not a link content
42
- insertData(data);
37
+ if (isUrl(text) && !isImage(text)) {
38
+ var link = genLinkNode(text, text);
39
+ Transforms.insertNodes(newEditor, [link, {
40
+ id: slugid.nice(),
41
+ text: ' '
42
+ }]);
43
43
  return;
44
44
  }
45
- var link = genLinkNode(text, text);
46
- Transforms.insertNodes(newEditor, [link, {
47
- id: slugid.nice(),
48
- text: ' '
49
- }]);
50
- return;
45
+ insertData(data);
51
46
  };
52
47
 
53
48
  // Rewrite normalizeNode
@@ -1,8 +1,9 @@
1
- import { Transforms } from '@seafile/slate';
1
+ import { Transforms, Node, Editor, Element } from '@seafile/slate';
2
+ import slugid from 'slugid';
2
3
  import { ReactEditor } from '@seafile/slate-react';
3
4
  import copy from 'copy-to-clipboard';
4
5
  import { toggleList } from '../../plugins/list/transforms';
5
- import { ORDERED_LIST, UNORDERED_LIST, PARAGRAPH, CHECK_LIST_ITEM } from '../../constants';
6
+ import { ORDERED_LIST, UNORDERED_LIST, PARAGRAPH, CHECK_LIST_ITEM, IMAGE, TABLE, CODE_BLOCK, LIST_ITEM, BLOCKQUOTE, LIST_ITEM_CORRELATION_TYPE } from '../../constants';
6
7
  export var onSetNodeType = function onSetNodeType(editor, element, type) {
7
8
  if (!type) return;
8
9
  if ([ORDERED_LIST, UNORDERED_LIST].includes(type)) {
@@ -22,6 +23,18 @@ export var onSetNodeType = function onSetNodeType(editor, element, type) {
22
23
  });
23
24
  return;
24
25
  }
26
+ if (type === BLOCKQUOTE && LIST_ITEM_CORRELATION_TYPE.includes(element.type)) {
27
+ Transforms.wrapNodes(editor, {
28
+ id: slugid.nice(),
29
+ type: BLOCKQUOTE
30
+ }, {
31
+ mode: 'highest',
32
+ match: function match(n) {
33
+ return Element.isElement(n) && Editor.isBlock(editor, n);
34
+ }
35
+ });
36
+ return;
37
+ }
25
38
  Transforms.setNodes(editor, {
26
39
  type: type
27
40
  });
@@ -53,4 +66,19 @@ export var getDomTopHeight = function getDomTopHeight(dom) {
53
66
  var HEADER_HEIGHT = 56 + 44;
54
67
  var rect = dom.getBoundingClientRect();
55
68
  return rect.y - HEADER_HEIGHT;
69
+ };
70
+ export var isVoidNode = function isVoidNode(node) {
71
+ if (!node) return true;
72
+ var hasImage = node.children.find(function (n) {
73
+ return n.type === IMAGE;
74
+ });
75
+ var isTable = node.type === TABLE;
76
+ var isCodeBlock = node.type === CODE_BLOCK;
77
+ return Node.string(node) === '' && !hasImage && !isTable && !isCodeBlock;
78
+ };
79
+ export var isNotSupportTransform = function isNotSupportTransform(node) {
80
+ if (node.type && [CODE_BLOCK, TABLE].includes(node.type)) {
81
+ return true;
82
+ }
83
+ return false;
56
84
  };
@@ -1,12 +1,11 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import classnames from 'classnames';
4
- import { Node } from '@seafile/slate';
5
4
  import { ReactEditor, useSlateStatic } from '@seafile/slate-react';
6
5
  import EventBus from '../../../utils/event-bus';
7
6
  import { useScrollContext } from '../../../hooks/use-scroll-context';
8
7
  import { INTERNAL_EVENT } from '../../../constants';
9
- import { getDomTopHeight, setSelection } from './helpers';
8
+ import { getDomTopHeight, setSelection, isVoidNode } from './helpers';
10
9
  import SideMenu from './side-menu';
11
10
  import './index.css';
12
11
  var SideToolbar = function SideToolbar() {
@@ -72,7 +71,7 @@ var SideToolbar = function SideToolbar() {
72
71
  }
73
72
  var top = getDomTopHeight(dom);
74
73
  var node = ReactEditor.toSlateNode(editor, dom);
75
- var isEmpty = Node.string(node) === '';
74
+ var isEmpty = isVoidNode(node);
76
75
  setSidePosition({
77
76
  top: top + scrollRef.current.scrollTop,
78
77
  left: 20
@@ -3,8 +3,10 @@ import { UncontrolledPopover } from 'reactstrap';
3
3
  import InsertBlockMenu from './insert-block-menu';
4
4
  import { INSERT_POSITION } from '../../constants';
5
5
  var InsertBelowMenu = function InsertBelowMenu(_ref) {
6
- var target = _ref.target;
6
+ var target = _ref.target,
7
+ slateNode = _ref.slateNode;
7
8
  return /*#__PURE__*/React.createElement(UncontrolledPopover, {
9
+ boundariesElement: "viewport",
8
10
  target: target,
9
11
  className: "sdoc-side-menu-insert-below-popover sdoc-sub-dropdown-menu sdoc-dropdown-menu",
10
12
  trigger: "hover",
@@ -14,7 +16,8 @@ var InsertBelowMenu = function InsertBelowMenu(_ref) {
14
16
  }, /*#__PURE__*/React.createElement("div", {
15
17
  className: "sdoc-dropdown-menu-container"
16
18
  }, /*#__PURE__*/React.createElement(InsertBlockMenu, {
17
- insertPosition: INSERT_POSITION.AFTER
19
+ insertPosition: INSERT_POSITION.AFTER,
20
+ slateNode: slateNode
18
21
  })));
19
22
  };
20
23
  export default InsertBelowMenu;