@seafile/sdoc-editor 0.1.2 → 0.1.3

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 (86) hide show
  1. package/dist/assets/css/textlink-hovermenu.css +51 -0
  2. package/dist/editor.js +13 -20
  3. package/dist/{slate-extension → extension}/constants/index.js +4 -0
  4. package/dist/{slate-extension → extension}/core/queries/index.js +44 -15
  5. package/dist/{slate-extension → extension}/core/transforms/focus-editor.js +2 -2
  6. package/dist/extension/core/transforms/index.js +3 -0
  7. package/dist/{slate-extension → extension}/core/transforms/move-children.js +1 -1
  8. package/dist/extension/core/transforms/remove-node-children.js +24 -0
  9. package/dist/{slate-extension → extension}/core/utils/index.js +10 -0
  10. package/dist/{slate-extension → extension}/index.js +2 -2
  11. package/dist/{slate-extension → extension}/plugins/blockquote/helpers.js +1 -1
  12. package/dist/{slate-extension → extension}/plugins/blockquote/menu/index.js +1 -2
  13. package/dist/{slate-extension → extension}/plugins/blockquote/plugin.js +5 -9
  14. package/dist/extension/plugins/blockquote/render-elem.js +10 -0
  15. package/dist/{slate-extension → extension}/plugins/check-list/helpers.js +1 -1
  16. package/dist/{slate-extension → extension}/plugins/check-list/plugin.js +1 -1
  17. package/dist/{slate-extension → extension}/plugins/check-list/render-elem.js +5 -3
  18. package/dist/{slate-extension → extension}/plugins/header/helpers.js +1 -1
  19. package/dist/{slate-extension → extension}/plugins/header/plugin.js +4 -7
  20. package/dist/{slate-extension → extension}/plugins/header/render-elem.js +3 -1
  21. package/dist/extension/plugins/index.js +9 -0
  22. package/dist/extension/plugins/link/helpers.js +152 -0
  23. package/dist/extension/plugins/link/index.js +14 -0
  24. package/dist/extension/plugins/link/menu/add-link-dialog.js +146 -0
  25. package/dist/extension/plugins/link/menu/hover-link-dialog.js +49 -0
  26. package/dist/extension/plugins/link/menu/index.js +67 -0
  27. package/dist/extension/plugins/link/model.js +13 -0
  28. package/dist/extension/plugins/link/plugin.js +60 -0
  29. package/dist/extension/plugins/link/render-elem.js +114 -0
  30. package/dist/{slate-extension → extension}/plugins/list/helpers.js +1 -1
  31. package/dist/{slate-extension → extension}/plugins/list/menu/index.js +1 -1
  32. package/dist/{slate-extension → extension}/plugins/list/plugin/normalize-list.js +1 -1
  33. package/dist/{slate-extension → extension}/plugins/list/plugin/on-tab-handle.js +1 -1
  34. package/dist/{slate-extension → extension}/plugins/list/queries/index.js +1 -1
  35. package/dist/{slate-extension → extension}/plugins/list/render-elem.js +11 -4
  36. package/dist/{slate-extension → extension}/plugins/list/transforms/insert-list-item.js +17 -22
  37. package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-item-down.js +1 -1
  38. package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-item-up.js +1 -1
  39. package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-items-to-list.js +1 -1
  40. package/dist/{slate-extension → extension}/plugins/list/transforms/move-list-items.js +1 -1
  41. package/dist/{slate-extension → extension}/plugins/list/transforms/normalize-list-item.js +1 -1
  42. package/dist/{slate-extension → extension}/plugins/list/transforms/normalize-nested-list.js +1 -1
  43. package/dist/{slate-extension → extension}/plugins/list/transforms/toggle-list.js +1 -1
  44. package/dist/{slate-extension → extension}/plugins/list/transforms/unwrap-list.js +1 -1
  45. package/dist/{slate-extension → extension}/plugins/text-style/render-elem.js +3 -1
  46. package/dist/{slate-extension → extension}/render/render-element.js +14 -4
  47. package/dist/{slate-extension → extension}/toolbar/index.js +4 -1
  48. package/dist/node-id/constants.js +18 -0
  49. package/dist/node-id/helpers.js +80 -0
  50. package/dist/node-id/index.js +11 -0
  51. package/dist/socket/helpers.js +258 -0
  52. package/dist/socket/index.js +3 -0
  53. package/dist/socket/socket-client.js +138 -0
  54. package/dist/socket/socket-manager.js +180 -0
  55. package/dist/socket/with-socket-io.js +18 -0
  56. package/package.json +9 -6
  57. package/public/locales/en/seafile-editor.json +4 -1
  58. package/public/locales/zh-CN/seafile-editor.json +4 -1
  59. package/dist/slate-extension/core/transforms/index.js +0 -2
  60. package/dist/slate-extension/plugins/blockquote/render-elem.js +0 -7
  61. package/dist/slate-extension/plugins/index.js +0 -9
  62. package/dist/slate-extension/plugins/socket/index.js +0 -6
  63. package/dist/slate-extension/plugins/socket/plugin.js +0 -23
  64. package/dist/slate-extension/socket/socket-client.js +0 -94
  65. package/dist/slate-extension/socket/socket-manager.js +0 -63
  66. /package/dist/{slate-extension → extension}/core/index.js +0 -0
  67. /package/dist/{slate-extension → extension}/menu/index.js +0 -0
  68. /package/dist/{slate-extension → extension}/menu/menu-group.js +0 -0
  69. /package/dist/{slate-extension → extension}/menu/menu-item.js +0 -0
  70. /package/dist/{slate-extension → extension}/menu/menu.css +0 -0
  71. /package/dist/{slate-extension → extension}/plugins/blockquote/index.js +0 -0
  72. /package/dist/{slate-extension → extension}/plugins/blockquote/model.js +0 -0
  73. /package/dist/{slate-extension → extension}/plugins/check-list/index.js +0 -0
  74. /package/dist/{slate-extension → extension}/plugins/check-list/menu/index.js +0 -0
  75. /package/dist/{slate-extension → extension}/plugins/check-list/model.js +0 -0
  76. /package/dist/{slate-extension → extension}/plugins/header/index.js +0 -0
  77. /package/dist/{slate-extension → extension}/plugins/header/menu/index.js +0 -0
  78. /package/dist/{slate-extension → extension}/plugins/list/index.js +0 -0
  79. /package/dist/{slate-extension → extension}/plugins/list/model.js +0 -0
  80. /package/dist/{slate-extension → extension}/plugins/list/plugin/index.js +0 -0
  81. /package/dist/{slate-extension → extension}/plugins/list/plugin/insert-break-list.js +0 -0
  82. /package/dist/{slate-extension → extension}/plugins/list/transforms/index.js +0 -0
  83. /package/dist/{slate-extension → extension}/plugins/list/transforms/remove-first-list-item.js +0 -0
  84. /package/dist/{slate-extension → extension}/plugins/text-style/index.js +0 -0
  85. /package/dist/{slate-extension → extension}/plugins/text-style/model.js +0 -0
  86. /package/dist/{slate-extension → extension}/render/render-leaf.js +0 -0
@@ -0,0 +1,51 @@
1
+ .seafile-ed-hovermenu {
2
+ width: 250px;
3
+ height: 40px;
4
+ display: flex;
5
+ position: absolute;
6
+ background-color: #fff;
7
+ border: 1px solid rgba(0, 40, 100, 0.12);
8
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
9
+ z-index: 1000;
10
+ }
11
+
12
+ .seafile-ed-hovermenu .seafile-ed-hovermenu-triangle {
13
+ width: 8px;
14
+ height: 8px;
15
+ transform: rotate(45deg);
16
+ background: #fff;
17
+ border-right: 1px solid rgba(0, 40, 100, 0.12);
18
+ border-bottom: 1px solid rgba(0, 40, 100, 0.12);
19
+ position: absolute;
20
+ top: 34px;
21
+ right: 50%;
22
+ z-index: 1001;
23
+ }
24
+
25
+ .seafile-ed-hovermenu .seafile-ed-hovermenu-link {
26
+ height: 38px;
27
+ max-width: 170px;
28
+ padding: 6px 12px;
29
+ display: inline-block;
30
+ line-height: 28px;
31
+ overflow: hidden;
32
+ cursor: pointer;
33
+ }
34
+
35
+ .seafile-ed-hovermenu .seafile-ed-hovermenu-btn {
36
+ background-color: #fff;
37
+ width: 35px;
38
+ font-weight: normal;
39
+ color: #999999;
40
+ line-height: 26px;
41
+ font-size: 16px;
42
+ }
43
+
44
+ .seafile-ed-hovermenu .seafile-ed-hovermenu-btn, .seafile-ed-hovermenu .seafile-ed-hovermenu-btn:focus {
45
+ border: 0;
46
+ box-shadow: 0;
47
+ }
48
+
49
+ .seafile-ed-hovermenu-mouseclick {
50
+ background-color: #ddd;
51
+ }
package/dist/editor.js CHANGED
@@ -1,13 +1,13 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
3
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
5
  import React from 'react';
7
- import { Editable, Slate } from 'slate-react';
6
+ import { Editable, Slate } from '@seafile/slate-react';
8
7
  import isHotkey from 'is-hotkey';
9
- import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './slate-extension';
10
- import SocketManager from './slate-extension/socket/socket-manager';
8
+ import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './extension';
9
+ import { SocketManager, withSocketIO } from './socket';
10
+ import withNodeId from './node-id';
11
11
  import './assets/css/sdoc-editor.css';
12
12
  var SDocEditor = /*#__PURE__*/function (_React$Component) {
13
13
  _inherits(SDocEditor, _React$Component);
@@ -16,12 +16,6 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
16
16
  var _this;
17
17
  _classCallCheck(this, SDocEditor);
18
18
  _this = _super.call(this, props);
19
- _this.updateWithRemoteOperation = function (params) {
20
- var operation = params.operation;
21
- _this.editor.apply(_objectSpread(_objectSpread({}, operation), {}, {
22
- is_remote: true
23
- }));
24
- };
25
19
  _this.onChange = function (slateValue) {
26
20
  var onValueChanged = _this.props.onValueChanged;
27
21
  _this.setState({
@@ -34,8 +28,12 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
34
28
  slateValue: children,
35
29
  isLoading: true
36
30
  };
37
- _this.editor = editor;
38
31
  _this.socketManager = null;
32
+ if (!props.isOpenSocket) {
33
+ _this.editor = withNodeId(editor);
34
+ } else {
35
+ _this.editor = withSocketIO(withNodeId(editor));
36
+ }
39
37
  return _this;
40
38
  }
41
39
  _createClass(SDocEditor, [{
@@ -46,21 +44,16 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
46
44
  document = _this$props.document,
47
45
  config = _this$props.config;
48
46
  if (isOpenSocket) {
49
- this.socketManager = SocketManager.getInstance(document, config);
50
- var eventBus = this.socketManager.eventBus;
51
- this.unsubscribeReceiveOption = eventBus.subscribe('receive-operation', this.updateWithRemoteOperation);
47
+ this.socketManager = SocketManager.getInstance(this.editor, document, config);
52
48
  }
53
49
  }
54
- }, {
55
- key: "componentWillUnmount",
56
- value: function componentWillUnmount() {
57
- this.unsubscribeReceiveOption();
58
- }
59
50
  }, {
60
51
  key: "render",
61
52
  value: function render() {
62
53
  var _this2 = this;
63
- var slateValue = this.state.slateValue;
54
+ var _this$state = this.state,
55
+ slateValue = _this$state.slateValue,
56
+ isEditorBlur = _this$state.isEditorBlur;
64
57
  return /*#__PURE__*/React.createElement("div", {
65
58
  className: "sf-editor-container"
66
59
  }, /*#__PURE__*/React.createElement(Toolbar, {
@@ -45,5 +45,9 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
45
45
  id: CHECK_LIST,
46
46
  iconClass: 'iconfont icon-check-square',
47
47
  text: 'check_list_item'
48
+ }), _defineProperty(_MENUS_CONFIG_MAP, LINK, {
49
+ id: LINK,
50
+ iconClass: 'iconfont icon-link',
51
+ text: 'link'
48
52
  }), _MENUS_CONFIG_MAP);
49
53
  export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_1'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_2'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_3'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_4'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_5'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_6'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'pargraph'), _HEADER_TITLE_MAP);
@@ -4,7 +4,7 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
6
6
  var _excluded = ["at"];
7
- import { Editor, Text, Path, Span, Element, Node, Range } from 'slate';
7
+ import { Editor, Text, Path, Span, Element, Node, Range } from '@seafile/slate';
8
8
  import { match } from '../utils';
9
9
 
10
10
  // options
@@ -62,6 +62,14 @@ export var getSelectedNodeEntryByType = function getSelectedNodeEntryByType(edit
62
62
  export var getNodeEntries = function getNodeEntries(editor, options) {
63
63
  return Editor.nodes(editor, getQueryOptions(editor, options));
64
64
  };
65
+ export var getEditorString = function getEditorString(editor, at, options) {
66
+ if (!at) return '';
67
+ try {
68
+ return Editor.string(editor, at, options);
69
+ } catch (error) {
70
+ return '';
71
+ }
72
+ };
65
73
 
66
74
  // children & child
67
75
  export var getChildren = function getChildren(nodeEntry) {
@@ -124,6 +132,27 @@ export var isLastChild = function isLastChild(nodeEntry, childPath) {
124
132
  var lastChildPath = getLastChildPath(nodeEntry);
125
133
  return Path.equals(lastChildPath, childPath);
126
134
  };
135
+ export var getSelectedElems = function getSelectedElems(editor) {
136
+ var elems = [];
137
+ var nodeEntries = Editor.nodes(editor, {
138
+ universal: true
139
+ });
140
+ var _iterator2 = _createForOfIteratorHelper(nodeEntries),
141
+ _step2;
142
+ try {
143
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
144
+ var nodeEntry = _step2.value;
145
+ var _nodeEntry3 = _slicedToArray(nodeEntry, 1),
146
+ node = _nodeEntry3[0];
147
+ if (Element.isElement(node)) elems.push(node);
148
+ }
149
+ } catch (err) {
150
+ _iterator2.e(err);
151
+ } finally {
152
+ _iterator2.f();
153
+ }
154
+ return elems;
155
+ };
127
156
 
128
157
  // siblings
129
158
  export var getNextSiblingNodes = function getNextSiblingNodes(ancestorEntry, path) {
@@ -197,21 +226,21 @@ export var findDescendant = function findDescendant(editor, options) {
197
226
  return voids ? false : Editor.isVoid(editor, n);
198
227
  }
199
228
  });
200
- var _iterator2 = _createForOfIteratorHelper(nodeEntries),
201
- _step2;
229
+ var _iterator3 = _createForOfIteratorHelper(nodeEntries),
230
+ _step3;
202
231
  try {
203
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
204
- var _step2$value = _slicedToArray(_step2.value, 2),
205
- node = _step2$value[0],
206
- path = _step2$value[1];
232
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
233
+ var _step3$value = _slicedToArray(_step3.value, 2),
234
+ node = _step3$value[0],
235
+ path = _step3$value[1];
207
236
  if (match(node, path, _match)) {
208
237
  return [node, at.concat(path)];
209
238
  }
210
239
  }
211
240
  } catch (err) {
212
- _iterator2.e(err);
241
+ _iterator3.e(err);
213
242
  } finally {
214
- _iterator2.f();
243
+ _iterator3.f();
215
244
  }
216
245
  return undefined;
217
246
  };
@@ -238,19 +267,19 @@ export var isBlockTextEmptyAfterSelection = function isBlockTextEmptyAfterSelect
238
267
  var siblingNodes = getNextSiblingNodes(blockAbove, cursor.path);
239
268
  if (siblingNodes.length) {
240
269
  // 子节点包含 文本节点
241
- var _iterator3 = _createForOfIteratorHelper(siblingNodes),
242
- _step3;
270
+ var _iterator4 = _createForOfIteratorHelper(siblingNodes),
271
+ _step4;
243
272
  try {
244
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
245
- var siblingNode = _step3.value;
273
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
274
+ var siblingNode = _step4.value;
246
275
  if (Text.isText(siblingNode) && siblingNode.text) {
247
276
  return false;
248
277
  }
249
278
  }
250
279
  } catch (err) {
251
- _iterator3.e(err);
280
+ _iterator4.e(err);
252
281
  } finally {
253
- _iterator3.f();
282
+ _iterator4.f();
254
283
  }
255
284
  } else {
256
285
  return isEndPoint(editor, cursor, blockAbove[1]);
@@ -1,5 +1,5 @@
1
- import { Editor, Transforms } from 'slate';
2
- import { ReactEditor } from 'slate-react';
1
+ import { Editor, Transforms } from '@seafile/slate';
2
+ import { ReactEditor } from '@seafile/slate-react';
3
3
  export var focusEditor = function focusEditor(editor, target) {
4
4
  if (target) {
5
5
  Editor.withoutNormalizing(editor, function () {
@@ -0,0 +1,3 @@
1
+ export * from './move-children';
2
+ export * from './remove-node-children';
3
+ export * from './focus-editor';
@@ -1,5 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import { Editor, Path, Transforms } from 'slate';
2
+ import { Editor, Path, Transforms } from '@seafile/slate';
3
3
  import { getNode } from '../queries';
4
4
  export var moveChildren = function moveChildren(editor, _ref) {
5
5
  var at = _ref.at,
@@ -0,0 +1,24 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
+ import { Transforms, Node } from '@seafile/slate';
5
+ export var removeNodeChildren = function removeNodeChildren(editor, path, options) {
6
+ var nodeChildren = Node.children(editor, path, {
7
+ reverse: true
8
+ });
9
+ var _iterator = _createForOfIteratorHelper(nodeChildren),
10
+ _step;
11
+ try {
12
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
13
+ var _step$value = _slicedToArray(_step.value, 2),
14
+ childPath = _step$value[1];
15
+ Transforms.removeNodes(editor, _objectSpread(_objectSpread({}, options), {}, {
16
+ at: childPath
17
+ }));
18
+ }
19
+ } catch (err) {
20
+ _iterator.e(err);
21
+ } finally {
22
+ _iterator.f();
23
+ }
24
+ };
@@ -1,4 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import slugid from 'slugid';
2
3
  export var match = function match(node, path, predicate) {
3
4
  if (!predicate) return true;
4
5
  if (typeof predicate === 'object') {
@@ -14,4 +15,13 @@ export var match = function match(node, path, predicate) {
14
15
  });
15
16
  }
16
17
  return predicate(node, path);
18
+ };
19
+ export var generateEmptyElement = function generateEmptyElement(type) {
20
+ return {
21
+ type: type,
22
+ children: [{
23
+ id: slugid.nice(),
24
+ text: ''
25
+ }]
26
+ };
17
27
  };
@@ -1,5 +1,5 @@
1
- import { createEditor } from 'slate';
2
- import { withReact } from 'slate-react';
1
+ import { createEditor } from '@seafile/slate';
2
+ import { withReact } from '@seafile/slate-react';
3
3
  import Plugins from './plugins';
4
4
  import renderElement from './render/render-element';
5
5
  import renderLeaf from './render/render-leaf';
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { Editor, Transforms } from 'slate';
2
+ import { Editor, Transforms } from '@seafile/slate';
3
3
  import { BLOCKQUOTE } from '../../constants';
4
4
  import { getNodeType } from '../../core';
5
5
  export var isMenuDisabled = function isMenuDisabled(editor) {
@@ -5,7 +5,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
7
  import { BLOCKQUOTE, MENUS_CONFIG_MAP, PARAGRAPH } from '../../../constants';
8
- import { MenuItem } from '../../../menu/';
8
+ import { MenuItem } from '../../../menu';
9
9
  import { getBlockQuoteType, isMenuDisabled, setBlockQuoteType } from '../helpers';
10
10
  var QuoteMenu = /*#__PURE__*/function (_React$Component) {
11
11
  _inherits(QuoteMenu, _React$Component);
@@ -29,7 +29,6 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
29
29
  var editor = _this.props.editor;
30
30
  var active = _this.isActive(editor);
31
31
  var newType = active ? PARAGRAPH : BLOCKQUOTE;
32
- console.log(newType);
33
32
  setBlockQuoteType(editor, newType);
34
33
  };
35
34
  return _this;
@@ -1,7 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { Editor, Element, Point, Transforms, Node } from 'slate';
3
- import { ReactEditor } from 'slate-react';
4
- import { BLOCKQUOTE } from '../../constants';
2
+ import { Editor, Element, Point, Transforms, Node } from '@seafile/slate';
3
+ import { ReactEditor } from '@seafile/slate-react';
4
+ import { generateEmptyElement } from '../../core';
5
+ import { BLOCKQUOTE, PARAGRAPH } from '../../constants';
5
6
  var withBlockquote = function withBlockquote(editor) {
6
7
  var insertBreak = editor.insertBreak,
7
8
  insertText = editor.insertText;
@@ -29,12 +30,7 @@ var withBlockquote = function withBlockquote(editor) {
29
30
  // 第一步:删除最后一个 \n
30
31
  editor.deleteBackward('character');
31
32
  // 第二步:插入一个 paragraph
32
- var p = {
33
- type: 'paragraph',
34
- children: [{
35
- text: ''
36
- }]
37
- };
33
+ var p = generateEmptyElement(PARAGRAPH);
38
34
  Transforms.insertNodes(newEditor, p, {
39
35
  mode: 'highest'
40
36
  });
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ var renderBlockquote = function renderBlockquote(props, editor) {
3
+ var attributes = props.attributes,
4
+ children = props.children,
5
+ element = props.element;
6
+ return /*#__PURE__*/React.createElement("blockquote", Object.assign({
7
+ "data-id": element.id
8
+ }, attributes), children);
9
+ };
10
+ export default renderBlockquote;
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import { Transforms, Editor, Element } from 'slate';
3
+ import { Transforms, Editor, Element } from '@seafile/slate';
4
4
  import { CHECK_LIST_ITEM, PARAGRAPH } from '../../constants';
5
5
  import { getSelectedNodeByType } from '../../core';
6
6
  export var isMenuDisabled = function isMenuDisabled(editor) {
@@ -1,4 +1,4 @@
1
- import { Node, Range, Transforms } from 'slate';
1
+ import { Node, Range, Transforms } from '@seafile/slate';
2
2
  import { CHECK_LIST_ITEM, PARAGRAPH } from '../../constants';
3
3
  import { getSelectedNodeByType } from '../../core';
4
4
  var withCheckList = function withCheckList(editor) {
@@ -3,8 +3,8 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
- import { Transforms } from 'slate';
7
- import { ReactEditor } from 'slate-react';
6
+ import { Transforms } from '@seafile/slate';
7
+ import { ReactEditor } from '@seafile/slate-react';
8
8
  var renderCheckList = function renderCheckList(props, editor) {
9
9
  var attributes = props.attributes,
10
10
  children = props.children,
@@ -48,7 +48,9 @@ var CheckListItem = /*#__PURE__*/function (_React$PureComponent) {
48
48
  var _ref = node || {},
49
49
  _ref$checked = _ref.checked,
50
50
  checked = _ref$checked === void 0 ? false : _ref$checked;
51
- return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
51
+ return /*#__PURE__*/React.createElement("div", Object.assign({
52
+ "data-id": node.id
53
+ }, attributes, {
52
54
  style: style
53
55
  }), /*#__PURE__*/React.createElement("span", {
54
56
  contentEditable: false,
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { Editor, Transforms } from "slate";
2
+ import { Editor, Transforms } from "@seafile/slate";
3
3
  import { getNodeType } from "../../core";
4
4
  export var isMenuDisabled = function isMenuDisabled(editor) {
5
5
  if (!editor.selection) return true;
@@ -1,5 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { Editor, Element, Transforms } from 'slate';
2
+ import { Editor, Element, Transforms } from '@seafile/slate';
3
+ import { PARAGRAPH } from '../../constants';
4
+ import { generateEmptyElement } from '../../core';
3
5
  var isSelectionAtLineEnd = function isSelectionAtLineEnd(editor, path) {
4
6
  var selection = editor.selection;
5
7
  if (!selection) return false;
@@ -31,12 +33,7 @@ var withHeader = function withHeader(editor) {
31
33
 
32
34
  // 如果在行末插入一个空 p,否则正常换行
33
35
  if (isAtLineEnd) {
34
- var p = {
35
- type: 'paragraph',
36
- children: [{
37
- text: ''
38
- }]
39
- };
36
+ var p = generateEmptyElement(PARAGRAPH);
40
37
  Transforms.insertNodes(newEditor, p, {
41
38
  mode: 'highest'
42
39
  });
@@ -6,6 +6,8 @@ var renderHeader = function renderHeader(props, editor) {
6
6
  var type = element.type;
7
7
  var level = type.split('header')[1];
8
8
  var Tag = "h".concat(level);
9
- return /*#__PURE__*/React.createElement(Tag, attributes, children);
9
+ return /*#__PURE__*/React.createElement(Tag, Object.assign({
10
+ "data-id": element.id
11
+ }, attributes), children);
10
12
  };
11
13
  export default renderHeader;
@@ -0,0 +1,9 @@
1
+ import HeaderPlugin from './header';
2
+ import LinkPlugin from './link';
3
+ import BlockquotePlugin from './blockquote';
4
+ import ListPlugin from './list';
5
+ import CheckListPlugin from './check-list';
6
+ import TextPlugin from './text-style';
7
+ var Plugins = [HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin];
8
+ export default Plugins;
9
+ export { HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin };
@@ -0,0 +1,152 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
+ import { Editor, Transforms, Range } from '@seafile/slate';
5
+ import { LINK } from '../../constants';
6
+ import { getNodeType, getSelectedElems, removeNodeChildren, getAboveNode, getEditorString } from '../../core';
7
+ export var isMenuDisabled = function isMenuDisabled(editor) {
8
+ if (editor.selection == null) return true;
9
+ var selectedElems = getSelectedElems(editor);
10
+ var notMatch = selectedElems.some(function (elem) {
11
+ var type = elem.type;
12
+ if (editor.isVoid(elem)) return true;
13
+ if (['pre', 'code', 'link'].includes(type)) return true;
14
+ return false;
15
+ });
16
+ if (notMatch) return true; // disabled
17
+ return false; // enable
18
+ };
19
+
20
+ export var checkLink = function checkLink(url) {
21
+ if (url.indexOf('http') !== 0) {
22
+ return true;
23
+ }
24
+ return false;
25
+ };
26
+ export var genLinkNode = function genLinkNode(url, text) {
27
+ var linkNode = {
28
+ type: 'link',
29
+ href: url,
30
+ title: text,
31
+ children: text ? [{
32
+ text: text
33
+ }] : []
34
+ };
35
+ return linkNode;
36
+ };
37
+ export var getLinkType = function getLinkType(editor) {
38
+ var _Editor$nodes = Editor.nodes(editor, {
39
+ match: function match(n) {
40
+ return getNodeType(n) === LINK;
41
+ },
42
+ universal: true
43
+ }),
44
+ _Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
45
+ match = _Editor$nodes2[0];
46
+ if (!match) return 'paragraph';
47
+ var _match = _slicedToArray(match, 1),
48
+ n = _match[0];
49
+ return getNodeType(n);
50
+ };
51
+ export var insertLink = function insertLink(editor, text, url) {
52
+ if (isMenuDisabled(editor)) return;
53
+
54
+ // Selection folded or not
55
+ var selection = editor.selection;
56
+ if (selection == null) return;
57
+ var isCollapsed = Range.isCollapsed(selection);
58
+ if (isCollapsed) {
59
+ // Insert Spaces before and after links for easy operation
60
+ editor.insertText(' ');
61
+ var linkNode = genLinkNode(url, text);
62
+ Transforms.insertNodes(editor, linkNode);
63
+
64
+ // Not being able to use insertText directly causes the added Spaces to be added to the linked text, as in the issue above, replaced by insertFragment
65
+ editor.insertFragment([{
66
+ text: ' '
67
+ }]);
68
+ } else {
69
+ var selectedText = Editor.string(editor, selection); // Selected text
70
+ if (selectedText !== text) {
71
+ // If the selected text is different from the typed text, delete the text and insert the link
72
+ editor.deleteFragment();
73
+ var _linkNode = genLinkNode(url, text);
74
+ Transforms.insertNodes(editor, _linkNode);
75
+ } else {
76
+ // If the selected text is the same as the entered text, only the link can be wrapped
77
+ var _linkNode2 = genLinkNode(url, text);
78
+ Transforms.wrapNodes(editor, _linkNode2, {
79
+ split: true
80
+ });
81
+ Transforms.collapse(editor, {
82
+ edge: 'end'
83
+ });
84
+ }
85
+ }
86
+ };
87
+ export var updateLink = function updateLink(editor, newText, newUrl) {
88
+ // Update children
89
+ var oldLink = getAboveNode(editor, {
90
+ match: {
91
+ type: 'link'
92
+ }
93
+ });
94
+ if (oldLink) {
95
+ var _oldLink = _slicedToArray(oldLink, 2),
96
+ oldLinkNode = _oldLink[0],
97
+ oldLinkPath = _oldLink[1];
98
+ var oldUrl = oldLinkNode.href;
99
+ if (newText !== getEditorString(editor, oldLinkPath) || newUrl !== oldUrl) {
100
+ // Remove link children
101
+ removeNodeChildren(editor, oldLinkPath, {
102
+ select: true
103
+ });
104
+
105
+ // insert link node
106
+ var linkNode = genLinkNode(newUrl, newText);
107
+ Transforms.insertNodes(editor, linkNode, {
108
+ select: true
109
+ });
110
+ }
111
+ }
112
+ };
113
+ export var unWrapLinkNode = /*#__PURE__*/function () {
114
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(editor) {
115
+ var _Editor$nodes3, _Editor$nodes4, nodeEntry;
116
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
117
+ while (1) switch (_context.prev = _context.next) {
118
+ case 0:
119
+ if (!(editor.selection == null)) {
120
+ _context.next = 2;
121
+ break;
122
+ }
123
+ return _context.abrupt("return");
124
+ case 2:
125
+ _Editor$nodes3 = Editor.nodes(editor, {
126
+ match: function match(n) {
127
+ return getNodeType(n) === 'link';
128
+ },
129
+ universal: true
130
+ }), _Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1), nodeEntry = _Editor$nodes4[0]; // If the selection is not in a link node, it is disabled
131
+ if (!(nodeEntry == null || nodeEntry[0] == null)) {
132
+ _context.next = 5;
133
+ break;
134
+ }
135
+ return _context.abrupt("return");
136
+ case 5:
137
+ // unlink
138
+ Transforms.unwrapNodes(editor, {
139
+ match: function match(n) {
140
+ return getNodeType(n) === 'link';
141
+ }
142
+ });
143
+ case 6:
144
+ case "end":
145
+ return _context.stop();
146
+ }
147
+ }, _callee);
148
+ }));
149
+ return function unWrapLinkNode(_x) {
150
+ return _ref.apply(this, arguments);
151
+ };
152
+ }();