@seafile/sdoc-editor 0.1.157 → 0.1.159-beta10

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 (47) hide show
  1. package/dist/api/seafile-api.js +28 -9
  2. package/dist/basic-sdk/constants/index.js +25 -1
  3. package/dist/basic-sdk/editor/common-editor.js +50 -0
  4. package/dist/basic-sdk/editor/index.css +29 -0
  5. package/dist/basic-sdk/editor/index.js +132 -0
  6. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  7. package/dist/basic-sdk/extension/constants/element-type.js +14 -9
  8. package/dist/basic-sdk/extension/constants/menus-config.js +27 -16
  9. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  10. package/dist/basic-sdk/extension/plugins/file-link/render-elem.css +4 -0
  11. package/dist/basic-sdk/extension/plugins/file-link/render-elem.js +1 -4
  12. package/dist/basic-sdk/extension/plugins/font/helpers.js +16 -12
  13. package/dist/basic-sdk/extension/plugins/html/rules/text.js +5 -5
  14. package/dist/basic-sdk/extension/plugins/markdown/plugin.js +4 -4
  15. package/dist/basic-sdk/extension/plugins/table/constants/index.js +5 -2
  16. package/dist/basic-sdk/extension/plugins/table/helpers.js +13 -8
  17. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-bg-color-menu.js +1 -1
  18. package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +3 -3
  19. package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +2 -2
  20. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +7 -9
  21. package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +3 -3
  22. package/dist/basic-sdk/extension/plugins/text-style/plugin.js +3 -2
  23. package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +20 -19
  24. package/dist/basic-sdk/extension/render/render-element.js +221 -1
  25. package/dist/basic-sdk/socket/helpers.js +2 -0
  26. package/dist/basic-sdk/socket/socket-client.js +58 -0
  27. package/dist/basic-sdk/socket/socket-manager.js +34 -2
  28. package/dist/basic-sdk/socket/with-socket-io.js +40 -12
  29. package/dist/basic-sdk/utils/diff.js +20 -19
  30. package/dist/basic-sdk/utils/rebase.js +193 -0
  31. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  32. package/dist/basic-sdk/views/viewer.js +9 -12
  33. package/dist/components/doc-operations/index.js +4 -2
  34. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  35. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  36. package/dist/components/tip-dialog/index.js +48 -0
  37. package/dist/components/tip-dialog/tip-content.js +47 -0
  38. package/dist/constants/index.js +26 -2
  39. package/dist/context.js +43 -9
  40. package/dist/pages/simple-editor.js +245 -88
  41. package/package.json +1 -1
  42. package/public/locales/en/sdoc-editor.json +12 -1
  43. package/public/locales/fr/sdoc-editor.json +154 -152
  44. package/public/locales/ru/sdoc-editor.json +50 -48
  45. package/public/locales/zh_CN/sdoc-editor.json +11 -1
  46. package/dist/basic-sdk/editor.js +0 -105
  47. package/dist/basic-sdk/extension/plugins/text-style/model.js +0 -11
@@ -3,7 +3,12 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import axios from 'axios';
4
4
  var SeafileAPI = /*#__PURE__*/function () {
5
5
  function SeafileAPI(server, token) {
6
+ var _this = this;
6
7
  _classCallCheck(this, SeafileAPI);
8
+ this.deleteSdocRevision = function (docUuid) {
9
+ var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
10
+ return _this.req.delete(url);
11
+ };
7
12
  this.req = axios.create({
8
13
  baseURL: server,
9
14
  headers: {
@@ -46,12 +51,6 @@ var SeafileAPI = /*#__PURE__*/function () {
46
51
  var url = '/api/v2.1/seadoc/download-image/' + docUuid + '/' + encodeURIComponent(imageName);
47
52
  return this.req.get(url);
48
53
  }
49
- }, {
50
- key: "sdocPublishRevision",
51
- value: function sdocPublishRevision(docUuid) {
52
- var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
53
- return this.req.post(url);
54
- }
55
54
  }, {
56
55
  key: "startRevise",
57
56
  value: function startRevise(repoID, fileUuid, path) {
@@ -63,9 +62,9 @@ var SeafileAPI = /*#__PURE__*/function () {
63
62
  return this._sendPostRequest(url, form);
64
63
  }
65
64
  }, {
66
- key: "getSeadocRevisionDownloadLinks",
67
- value: function getSeadocRevisionDownloadLinks(docUuid) {
68
- var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
65
+ key: "getSeadocOriginFileContent",
66
+ value: function getSeadocOriginFileContent(docUuid) {
67
+ var url = '/api/v2.1/seadoc/revision/origin-file-content/' + docUuid + '/';
69
68
  return this.req.get(url);
70
69
  }
71
70
  }, {
@@ -81,6 +80,26 @@ var SeafileAPI = /*#__PURE__*/function () {
81
80
  var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
82
81
  return this.req.get(url);
83
82
  }
83
+ }, {
84
+ key: "publishRevision",
85
+ value: function publishRevision(docUuid) {
86
+ var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
87
+ return this._sendPostRequest(url);
88
+ }
89
+ }, {
90
+ key: "updateSdocRevision",
91
+ value: function updateSdocRevision(docUuid) {
92
+ var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
93
+ return this.req.put(url);
94
+ }
95
+ }, {
96
+ key: "getRevisionBasicVersionContent",
97
+ value: function getRevisionBasicVersionContent(docUuid) {
98
+ var url = 'api/v2.1/seadoc/revision/basic-version-content/' + docUuid + '/';
99
+ return this.req.get(url);
100
+ }
101
+
102
+ // local files
84
103
  }, {
85
104
  key: "getSdocFiles",
86
105
  value: function getSdocFiles(docUuid, p, type) {
@@ -6,4 +6,28 @@ export var INTERNAL_EVENT = {
6
6
  INSERT_ELEMENT: 'insert_element',
7
7
  OUTLINE_STATE_CHANGED: 'outline_state_changed'
8
8
  };
9
- export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
9
+ export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
10
+
11
+ export var MODIFY_TYPE = {
12
+ ADD: 'add',
13
+ DELETE: 'delete',
14
+ MODIFY: 'modify',
15
+ CHILDREN_MODIFY: 'children_modify'
16
+ };
17
+ export var REBASE_TYPE = {
18
+ MODIFY_MODIFY: 'modify_modify',
19
+ DELETE_MODIFY: 'delete_modify',
20
+ MODIFY_DELETE: 'modify_delete',
21
+ CHILDREN_MODIFY: 'children_modify'
22
+ };
23
+ export var REBASE_MARK_KEY = {
24
+ ORIGIN: 'origin',
25
+ REBASE_TYPE: 'rebase_type',
26
+ MODIFY_TYPE: 'modify_type',
27
+ OLD_ELEMENT: 'old_element'
28
+ };
29
+ export var REBASE_ORIGIN = {
30
+ OTHER: 'other',
31
+ MY: 'my'
32
+ };
33
+ export var REBASE_MARKS = [REBASE_MARK_KEY.ORIGIN, REBASE_MARK_KEY.REBASE_TYPE, REBASE_MARK_KEY.MODIFY_TYPE, REBASE_MARK_KEY.OLD_ELEMENT];
@@ -0,0 +1,50 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect } from 'react';
3
+ import { Editor } from '@seafile/slate';
4
+ import { focusEditor } from '../extension/core';
5
+ import { EditorContainer, EditorContent } from '../layout';
6
+ import SlateEditor from './slate-editor';
7
+ import InsertElementDialog from '../extension/commons/insert-element-dialog';
8
+ var CommonEditor = function CommonEditor(_ref) {
9
+ var slateValue = _ref.slateValue,
10
+ updateSlateValue = _ref.updateSlateValue,
11
+ editor = _ref.editor,
12
+ renderElement = _ref.renderElement;
13
+ // useMount: focus editor
14
+ useEffect(function () {
15
+ var timer = setTimeout(function () {
16
+ var _editor$children = _slicedToArray(editor.children, 1),
17
+ firstNode = _editor$children[0];
18
+ if (firstNode) {
19
+ var _firstNode$children = _slicedToArray(firstNode.children, 1),
20
+ firstNodeFirstChild = _firstNode$children[0];
21
+ if (firstNodeFirstChild) {
22
+ var endOfFirstNode = Editor.end(editor, [0, 0]);
23
+ var range = {
24
+ anchor: endOfFirstNode,
25
+ focus: endOfFirstNode
26
+ };
27
+ focusEditor(editor, range);
28
+ }
29
+ }
30
+ }, 300);
31
+ return function () {
32
+ clearTimeout(timer);
33
+ };
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
37
+ editor: editor
38
+ }, /*#__PURE__*/React.createElement(EditorContent, {
39
+ docValue: slateValue,
40
+ showOutline: true
41
+ }, /*#__PURE__*/React.createElement(SlateEditor, {
42
+ editor: editor,
43
+ slateValue: slateValue,
44
+ setSlateValue: updateSlateValue,
45
+ renderElement: renderElement
46
+ }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
47
+ editor: editor
48
+ }));
49
+ };
50
+ export default CommonEditor;
@@ -0,0 +1,29 @@
1
+ .sdoc-rebase-btn-group {
2
+ color: #aaa;
3
+ }
4
+
5
+ .sdoc-rebase-btn-group .sdoc-rebase-btn {
6
+ cursor: pointer;
7
+ }
8
+
9
+ .sdoc-rebase-current-changes-start {
10
+ background-color: rgb(202, 232, 254);
11
+ }
12
+
13
+ .sdoc-rebase-current-changes {
14
+ background-color: rgba(202, 232, 254, .8);
15
+ }
16
+
17
+ .sdoc-rebase-incoming-changes {
18
+ background-color: rgb(222, 232, 254);
19
+ }
20
+
21
+ .sdoc-rebase-incoming-changes > *:first-child,
22
+ .sdoc-rebase-current-changes > *:first-child {
23
+ margin: 0;
24
+ padding: 0.8em 0 0.8em 0.2em;
25
+ }
26
+
27
+ .sdoc-rebase-incoming-changes-end {
28
+ background-color: rgb(212, 212, 254);
29
+ }
@@ -0,0 +1,132 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
4
+ import deepCopy from 'deep-copy';
5
+ import { createDefaultEditor, renderElement } from '../extension';
6
+ import { withSocketIO } from '../socket';
7
+ import withNodeId from '../node-id';
8
+ import { PAGE_EDIT_AREA_WIDTH } from '../constants';
9
+ import { MODE } from '../../constants';
10
+ import DiffViewer from '../views/diff-viewer';
11
+ import SDocEditor from './common-editor';
12
+ import CommonLoading from '../../components/common-loading';
13
+ import context from '../../context';
14
+ import './index.css';
15
+ var Editor = forwardRef(function (_ref, ref) {
16
+ var mode = _ref.mode,
17
+ document = _ref.document,
18
+ setDiffChanges = _ref.setDiffChanges;
19
+ var editor = useMemo(function () {
20
+ var defaultEditor = createDefaultEditor();
21
+ var editorConfig = context.getEditorConfig();
22
+ defaultEditor.mode = MODE.EDITOR;
23
+ var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
+ document: document,
25
+ config: editorConfig
26
+ }));
27
+ var cursors = document.cursors;
28
+ newEditor.cursors = cursors || {};
29
+ newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
+ return newEditor;
31
+
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
+ var _useState3 = useState(false),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ isLoading = _useState4[0],
41
+ _setLoading = _useState4[1];
42
+ var _useState5 = useState(null),
43
+ _useState6 = _slicedToArray(_useState5, 2),
44
+ diffContent = _useState6[0],
45
+ _setDiffContent = _useState6[1];
46
+ var _useState7 = useState(null),
47
+ _useState8 = _slicedToArray(_useState7, 2),
48
+ currentContent = _useState8[0],
49
+ setCurrentContent = _useState8[1];
50
+
51
+ // useMount: init socket connection
52
+ useEffect(function () {
53
+ editor.openConnection();
54
+ return function () {
55
+ editor.closeConnection();
56
+ };
57
+
58
+ // eslint-disable-next-line react-hooks/exhaustive-deps
59
+ }, []);
60
+ var updateSlateValue = useCallback(function (value) {
61
+ _setSlateValue(value);
62
+
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, []);
65
+
66
+ // The parent component can call the method of this component through ref
67
+ useImperativeHandle(ref, function () {
68
+ return {
69
+ // set value
70
+ setLoading: function setLoading(isLoading) {
71
+ _setLoading(isLoading);
72
+ },
73
+ setDiffContent: function setDiffContent(content) {
74
+ setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
75
+ children: slateValue
76
+ })));
77
+ _setDiffContent(content);
78
+ },
79
+ setEditorMode: function setEditorMode(mode) {
80
+ editor.cursors = {};
81
+ editor.selection = null;
82
+ if (mode === MODE.EDITOR) {
83
+ editor.operations = [];
84
+ }
85
+ editor.mode = mode;
86
+ },
87
+ setSlateValue: function setSlateValue(document) {
88
+ _setSlateValue(document.children);
89
+ },
90
+ // get value
91
+ getSlateValue: function getSlateValue() {
92
+ return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
93
+ children: slateValue
94
+ }));
95
+ },
96
+ saveDocument: function saveDocument(callback) {
97
+ return editor.saveDocument(callback);
98
+ },
99
+ // send message
100
+ publishDocument: function publishDocument(originDocUuid, originDocName, callback) {
101
+ editor.publishDocument(originDocUuid, originDocName, callback);
102
+ },
103
+ replaceDocument: function replaceDocument(value, originFileVersion) {
104
+ editor.replaceDocument(value, originFileVersion);
105
+ }
106
+
107
+ // eslint-disable-next-line react-hooks/exhaustive-deps
108
+ };
109
+ }, [document, editor, slateValue]);
110
+ if (isLoading) {
111
+ return /*#__PURE__*/React.createElement("div", {
112
+ className: "h-100 w-100 d-flex align-items-center justify-content-center"
113
+ }, /*#__PURE__*/React.createElement(CommonLoading, null));
114
+ }
115
+ if (mode === MODE.DIFF_VIEWER) {
116
+ return /*#__PURE__*/React.createElement(DiffViewer, {
117
+ showToolbar: true,
118
+ showOutline: true,
119
+ editor: editor,
120
+ currentContent: currentContent,
121
+ lastContent: diffContent,
122
+ didMountCallback: setDiffChanges
123
+ });
124
+ }
125
+ return /*#__PURE__*/React.createElement(SDocEditor, {
126
+ slateValue: slateValue,
127
+ editor: editor,
128
+ updateSlateValue: updateSlateValue,
129
+ renderElement: renderElement
130
+ });
131
+ });
132
+ export default Editor;
@@ -1,22 +1,24 @@
1
1
  import React, { useCallback, useMemo, Fragment } from 'react';
2
2
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
3
- import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from './extension';
4
- import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
5
- import EventProxy from './utils/event-handler';
6
- import { useCursors } from './cursor/use-cursors';
7
- import { INTERNAL_EVENT } from './constants';
8
- import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
9
- import CommentContextProvider from './comment/comment-context-provider';
10
- import CommentWrapper from './comment';
11
- import { usePipDecorate } from './decorates';
12
- import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
13
- import EventBus from './utils/event-bus';
14
- import { ArticleContainer } from './layout';
15
- import { useScrollContext } from './hooks/use-scroll-context';
3
+ import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
4
+ import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
5
+ import EventProxy from '../utils/event-handler';
6
+ import { useCursors } from '../cursor/use-cursors';
7
+ import { INTERNAL_EVENT } from '../constants';
8
+ import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
9
+ import CommentContextProvider from '../comment/comment-context-provider';
10
+ import CommentWrapper from '../comment';
11
+ import { usePipDecorate } from '../decorates';
12
+ import { getCursorPosition, getDomHeight, getDomMarginTop } from '../utils/dom-utils';
13
+ import EventBus from '../utils/event-bus';
14
+ import { ArticleContainer } from '../layout';
15
+ import { useScrollContext } from '../hooks/use-scroll-context';
16
16
  var SlateEditor = function SlateEditor(_ref) {
17
17
  var editor = _ref.editor,
18
18
  setSlateValue = _ref.setSlateValue,
19
- slateValue = _ref.slateValue;
19
+ slateValue = _ref.slateValue,
20
+ customRenderElement = _ref.renderElement,
21
+ isShowComment = _ref.isShowComment;
20
22
  var _useCursors = useCursors(editor),
21
23
  cursors = _useCursors.cursors;
22
24
  var decorate = usePipDecorate(editor);
@@ -138,12 +140,15 @@ var SlateEditor = function SlateEditor(_ref) {
138
140
  editor: editor
139
141
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
140
142
  cursors: cursors,
141
- renderElement: renderElement,
143
+ renderElement: customRenderElement || renderElement,
142
144
  renderLeaf: renderLeaf,
143
145
  onKeyDown: onKeyDown,
144
146
  onMouseDown: onMouseDown,
145
147
  decorate: decorate,
146
148
  onCut: eventProxy.onCut
147
- })), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
149
+ })), /*#__PURE__*/React.createElement(SideToolbar, null), isShowComment && /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
150
+ };
151
+ SlateEditor.defaultProps = {
152
+ isShowComment: true
148
153
  };
149
154
  export default SlateEditor;
@@ -10,16 +10,21 @@ export var HEADER5 = 'header5';
10
10
  export var HEADER6 = 'header6';
11
11
  export var ORDERED_LIST = 'ordered_list';
12
12
  export var UNORDERED_LIST = 'unordered_list';
13
- export var LIST_ITEM = 'list-item';
14
- export var LIST_LIC = 'list-lic'; // placeholder
15
- export var CHECK_LIST_ITEM = 'check-list-item';
13
+ export var LIST_ITEM = 'list_item';
14
+ export var LIST_LIC = 'list_lic'; // placeholder
15
+ export var CHECK_LIST_ITEM = 'check_list_item';
16
16
  export var PARAGRAPH = 'paragraph';
17
- export var CODE_BLOCK = 'code-block';
18
- export var CODE_LINE = 'code-line';
17
+ export var CODE_BLOCK = 'code_block';
18
+ export var CODE_LINE = 'code_line';
19
19
  export var TABLE = 'table';
20
- export var TABLE_ROW = 'table-row';
21
- export var TABLE_CELL = 'table-cell';
20
+ export var TABLE_ROW = 'table_row';
21
+ export var TABLE_CELL = 'table_cell';
22
22
  export var LINK = 'link';
23
- export var SDOC_LINK = 'sdoc-link';
23
+ export var SDOC_LINK = 'sdoc_link';
24
24
  export var FILE_LINK = 'file_link';
25
- export var IMAGE = 'image';
25
+ export var IMAGE = 'image';
26
+
27
+ // font
28
+ export var FONT_SIZE = 'font-size';
29
+ export var FONT_SIZE_INCREASE = 'font-size-increase';
30
+ export var FONT_SIZE_REDUCE = 'font-size-reduce';
@@ -8,18 +8,12 @@ export var CLEAR_FORMAT = 'clear_format';
8
8
  export var REMOVE_TABLE = 'remove_table';
9
9
 
10
10
  // text style
11
+ export var TEXT_STYLE = 'text_style';
11
12
  var ITALIC = 'italic';
12
13
  var BOLD = 'bold';
13
14
  var UNDERLINE = 'underline';
14
- var HIGHLIGHT_COLOR = 'highlight-color';
15
+ var HIGHLIGHT_COLOR = 'highlight_color';
15
16
  var COLOR = 'color';
16
- export var TEXT_STYLE = 'text_style';
17
- export var TEXT_STYLE_MAP = {
18
- ITALIC: ITALIC,
19
- BOLD: BOLD,
20
- BOLD_ITALIC: "".concat(BOLD, "-").concat(ITALIC),
21
- COLOR: COLOR
22
- };
23
17
 
24
18
  // text-align
25
19
  export var TEXT_ALIGN = 'text_align';
@@ -33,6 +27,23 @@ var SUBSCRIPT = 'subscript';
33
27
  // const FONT_SIZE_INCREASE = 'font-size-increase';
34
28
  // const FONT_SIZE_REDUCE = 'font-size-reduce';
35
29
 
30
+ export var TEXT_STYLE_MAP = {
31
+ COLOR: COLOR,
32
+ HIGHLIGHT_COLOR: HIGHLIGHT_COLOR,
33
+ FONT_SIZE: 'font_size',
34
+ FONT: 'font',
35
+ BOLD: BOLD,
36
+ ITALIC: ITALIC,
37
+ BOLD_ITALIC: "".concat(BOLD, "_").concat(ITALIC),
38
+ UNDERLINE: UNDERLINE,
39
+ STRIKETHROUGH: STRIKETHROUGH,
40
+ SUPERSCRIPT: SUPERSCRIPT,
41
+ SUBSCRIPT: SUBSCRIPT,
42
+ CODE: 'code',
43
+ DELETE: 'delete',
44
+ ADD: 'add'
45
+ };
46
+
36
47
  // header menu config
37
48
  export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CONFIG_MAP, BLOCKQUOTE, {
38
49
  id: "sdoc_".concat(BLOCKQUOTE),
@@ -74,22 +85,22 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
74
85
  id: ITALIC,
75
86
  iconClass: 'sdocfont sdoc-italic',
76
87
  text: 'Italic',
77
- type: 'ITALIC'
88
+ type: TEXT_STYLE_MAP.ITALIC
78
89
  }, {
79
90
  id: BOLD,
80
91
  iconClass: 'sdocfont sdoc-bold',
81
92
  text: 'Bold',
82
- type: 'BOLD'
93
+ type: TEXT_STYLE_MAP.BOLD
83
94
  }, {
84
95
  id: UNDERLINE,
85
96
  iconClass: 'sdocfont sdoc-underline',
86
97
  text: 'Underline',
87
- type: 'UNDERLINE'
98
+ type: TEXT_STYLE_MAP.UNDERLINE
88
99
  }, {
89
100
  id: "sdoc-".concat(HIGHLIGHT_COLOR),
90
101
  iconClass: 'sdocfont sdoc-highlight-color',
91
102
  text: 'Highlight_color',
92
- type: HIGHLIGHT_COLOR,
103
+ type: TEXT_STYLE_MAP.HIGHLIGHT_COLOR,
93
104
  isColor: true,
94
105
  recentUsedColorsKey: RECENT_USED_HIGHLIGHT_COLORS_KEY,
95
106
  defaultLastUsedColor: DEFAULT_LAST_USED_HIGHLIGHT_COLOR
@@ -97,7 +108,7 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
97
108
  id: "sdoc-font-".concat(COLOR),
98
109
  iconClass: 'sdocfont sdoc-font-color',
99
110
  text: 'Font_color',
100
- type: COLOR,
111
+ type: TEXT_STYLE_MAP.COLOR,
101
112
  defaultColor: DEFAULT_FONT_COLOR,
102
113
  isColor: true,
103
114
  recentUsedColorsKey: RECENT_USED_FONT_COLORS_KEY,
@@ -108,17 +119,17 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
108
119
  id: STRIKETHROUGH,
109
120
  iconClass: 'sdocfont sdoc-strikethrough',
110
121
  text: 'Strikethrough',
111
- type: 'STRIKETHROUGH'
122
+ type: TEXT_STYLE_MAP.STRIKETHROUGH
112
123
  }, {
113
124
  id: SUPERSCRIPT,
114
125
  iconClass: 'sdocfont sdoc-subscripts',
115
126
  text: 'Superscript',
116
- type: 'SUPERSCRIPT'
127
+ type: TEXT_STYLE_MAP.SUPERSCRIPT
117
128
  }, {
118
129
  id: SUBSCRIPT,
119
130
  iconClass: 'sdocfont sdoc-subscripts',
120
131
  text: 'Subscript',
121
- type: 'SUBSCRIPT'
132
+ type: TEXT_STYLE_MAP.SUBSCRIPT
122
133
  }]), _defineProperty(_MENUS_CONFIG_MAP, TEXT_ALIGN, [{
123
134
  id: ALIGN_LEFT,
124
135
  iconClass: 'sdocfont sdoc-align-left',
@@ -12,4 +12,30 @@ 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
+ });
15
41
  };
@@ -33,6 +33,10 @@
33
33
  position: absolute;
34
34
  top: 16px;
35
35
  left: 42px;
36
+ width: 330px;
37
+ overflow: hidden;
38
+ text-overflow: ellipsis;
39
+ white-space: nowrap;
36
40
  }
37
41
 
38
42
  .sdoc-file-card-link .sdoc-file-text-link a {
@@ -2,8 +2,6 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { useCallback, useEffect, useState, useRef } from 'react';
4
4
  import classnames from 'classnames';
5
- import { Range } from '@seafile/slate';
6
- import { useReadOnly } from '@seafile/slate-react';
7
5
  import { useScrollContext } from '../../../hooks/use-scroll-context';
8
6
  import { unwrapLinkNode, getUrl } from './helpers';
9
7
  import HoverMenu from './hover-menu';
@@ -25,7 +23,6 @@ var FileLink = function FileLink(_ref) {
25
23
  _useState4 = _slicedToArray(_useState3, 2),
26
24
  menuPosition = _useState4[0],
27
25
  setMenuPosition = _useState4[1];
28
- var readOnly = useReadOnly();
29
26
  var registerEventHandle = useCallback(function () {
30
27
  document.addEventListener('click', onHideInsertHoverMenu);
31
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -125,7 +122,7 @@ var FileLink = function FileLink(_ref) {
125
122
  e.preventDefault();
126
123
  },
127
124
  title: element.title
128
- }, children))), isShowInsertHoverMenu && (!readOnly && Range.isCollapsed(editor.selection) || readOnly) && /*#__PURE__*/React.createElement(HoverMenu, {
125
+ }, children))), isShowInsertHoverMenu && /*#__PURE__*/React.createElement(HoverMenu, {
129
126
  editor: editor,
130
127
  menuPosition: menuPosition,
131
128
  element: element,
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import { Editor, Element } from '@seafile/slate';
4
- import { CODE_BLOCK, IMAGE, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, SDOC_FONT_SIZE, HEADERS, TITLE, SUBTITLE, CODE_LINE } from '../../constants';
4
+ import { CODE_BLOCK, IMAGE, DEFAULT_FONT, GOOGLE_FONT_CLASS, FONT, SDOC_FONT_SIZE, HEADERS, TITLE, SUBTITLE, CODE_LINE, TEXT_STYLE_MAP } from '../../constants';
5
5
  import { focusEditor, getParentNode } from '../../core';
6
6
  import context from '../../../../context';
7
7
  import { isMac } from '../../../../utils';
@@ -28,13 +28,15 @@ export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
28
28
  export var getFontSize = function getFontSize(editor) {
29
29
  var selection = editor.selection;
30
30
  var marks = Editor.marks(editor);
31
- if (marks && marks['font-size']) return marks['font-size'];
31
+ if (marks && marks[TEXT_STYLE_MAP.FONT_SIZE]) {
32
+ return marks[TEXT_STYLE_MAP.FONT_SIZE];
33
+ }
32
34
  if (!selection) return SDOC_FONT_SIZE.DEFAULT;
33
35
  var _Editor$nodes3 = Editor.nodes(editor, {
34
36
  at: Editor.unhangRange(editor, selection),
35
37
  match: function match(n) {
36
38
  if (!Editor.isEditor(n) && !Element.isElement(n)) {
37
- if (n['font-size']) return true;
39
+ if (n[TEXT_STYLE_MAP.FONT_SIZE]) return true;
38
40
  var _parentNode = getParentNode(editor.children, n.id);
39
41
  if (!_parentNode) return false;
40
42
  if ([TITLE, SUBTITLE].concat(_toConsumableArray(HEADERS), [CODE_LINE]).includes(_parentNode.type)) {
@@ -48,14 +50,16 @@ export var getFontSize = function getFontSize(editor) {
48
50
  _Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
49
51
  match = _Editor$nodes4[0];
50
52
  if (!match) return SDOC_FONT_SIZE.DEFAULT;
51
- // has font-size attrubute
53
+ // has font-size attribute
52
54
  var matched = match[0];
53
- if (matched['font-size']) return matched['font-size'];
55
+ if (matched[TEXT_STYLE_MAP.FONT_SIZE]) {
56
+ return matched[TEXT_STYLE_MAP.FONT_SIZE];
57
+ }
54
58
  var parentNode = getParentNode(editor.children, matched.id);
55
59
  return SDOC_FONT_SIZE[parentNode.type];
56
60
  };
57
61
  export var setFontSize = function setFontSize(editor, value) {
58
- Editor.addMark(editor, 'font-size', value);
62
+ Editor.addMark(editor, TEXT_STYLE_MAP.FONT_SIZE, value);
59
63
  focusEditor(editor);
60
64
  };
61
65
  export var scaleFontSize = function scaleFontSize(editor, type) {
@@ -77,7 +81,9 @@ export var scaleFontSize = function scaleFontSize(editor, type) {
77
81
  export var getFont = function getFont(editor) {
78
82
  var selection = editor.selection;
79
83
  var marks = Editor.marks(editor);
80
- if (marks && marks['font']) return marks['font'];
84
+ if (marks && marks[TEXT_STYLE_MAP.FONT]) {
85
+ return marks[TEXT_STYLE_MAP.FONT];
86
+ }
81
87
  if (!selection) return DEFAULT_FONT;
82
88
  var _Editor$nodes5 = Editor.nodes(editor, {
83
89
  at: Editor.unhangRange(editor, selection),
@@ -88,10 +94,10 @@ export var getFont = function getFont(editor) {
88
94
  _Editor$nodes6 = _slicedToArray(_Editor$nodes5, 1),
89
95
  match = _Editor$nodes6[0];
90
96
  if (!match) return DEFAULT_FONT;
91
- return match[0]['font'];
97
+ return match[0][TEXT_STYLE_MAP.FONT];
92
98
  };
93
99
  export var setFont = function setFont(editor, value) {
94
- Editor.addMark(editor, 'font', value);
100
+ Editor.addMark(editor, TEXT_STYLE_MAP.FONT, value);
95
101
  focusEditor(editor);
96
102
  };
97
103
  export var hasFontLoaded = function hasFontLoaded() {
@@ -126,9 +132,7 @@ export var loadFont = function loadFont() {
126
132
  fontLink.className = GOOGLE_FONT_CLASS;
127
133
  document.body.appendChild(fontLink);
128
134
  };
129
- export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight, leaf) {
130
- var isCodeBlock = leaf && Object.keys(leaf).includes('token');
131
- if (isCodeBlock) return '';
135
+ export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight) {
132
136
  var lang = context.getSetting('lang') || 'zh-cn';
133
137
  if (fontName === DEFAULT_FONT) {
134
138
  return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");