@seafile/sdoc-editor 1.0.210 → 1.0.211-test-0.2

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.
@@ -62,6 +62,61 @@
62
62
  caret-color: transparent;
63
63
  }
64
64
 
65
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-placeholder-wrapper {
66
+ width: 360px;
67
+ aspect-ratio: 1 / 1;
68
+ background-color: #f0f0f0;
69
+ border: 1px solid #ccc;
70
+ padding: 0 3%;
71
+ max-width: 100%;
72
+ user-select: all;
73
+ pointer-events: all;
74
+ }
75
+
76
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-tip-content,
77
+ .sdoc-editor__article .sdoc-image-wrapper .sdoc-image-title {
78
+ user-select: none;
79
+ pointer-events: none;
80
+ }
81
+
82
+ .sdoc-editor__article .sdoc-image-title .sdoc-exclamation-circle {
83
+ font-size: 18px;
84
+ align-items: center;
85
+ justify-content: center;
86
+ color: red;
87
+ display: flex;
88
+ }
89
+
90
+ .sdoc-editor__article .sdoc-image-title .sdoc-image-tip-title {
91
+ color: red;
92
+ font-size: 18px;
93
+ user-select: none;
94
+ pointer-events: none;
95
+ }
96
+
97
+ .sdoc-editor__article .sdoc-image-process-container {
98
+ width: 40px;
99
+ height: 40px;
100
+ display: flex;
101
+ align-items: center;
102
+ }
103
+
104
+ .sdoc-editor__article .sdoc-image-process-container .loading-spinner {
105
+ border: 5px solid #d8d8d8;
106
+ border-top: 5px solid #939393;
107
+ border-radius: 50%;
108
+ width: 30px;
109
+ height: 30px;
110
+ animation: spin 1s linear infinite;
111
+ user-select: none;
112
+ pointer-events: none;
113
+ }
114
+
115
+ @keyframes spin {
116
+ 0% { transform: rotate(0deg); }
117
+ 100% { transform: rotate(360deg); }
118
+ }
119
+
65
120
  .sdoc-editor__article .sdoc-image-inner {
66
121
  position: relative;
67
122
  display: inline-block;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
7
+ exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isMiddlePoint = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isEmptyArticle = exports.isCursorAtBlockStart = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isContainsVoidElement = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
8
8
  var _slate = require("@seafile/slate");
9
9
  var _slateReact = require("@seafile/slate-react");
10
10
  var _utils = require("../utils");
@@ -455,6 +455,27 @@ const isBlockAboveEmpty = editor => {
455
455
  return isAncestorEmpty(editor, block);
456
456
  };
457
457
  exports.isBlockAboveEmpty = isBlockAboveEmpty;
458
+ const isCursorAtBlockStart = (editor, options) => {
459
+ const {
460
+ selection
461
+ } = editor;
462
+ if (!selection) return false;
463
+ const nodeEntry = getAboveBlockNode(editor, options);
464
+ let [node, path] = nodeEntry || [];
465
+ if (!path) return false;
466
+
467
+ // Special handling of placeholders, such as link, inline image
468
+ if (_slate.Node.string(node.children[0]).length === 0) {
469
+ const {
470
+ offset,
471
+ path: point
472
+ } = selection.focus;
473
+ if (offset !== 0) return false;
474
+ return _slate.Path.equals(point, [path[0], 1, 0]);
475
+ }
476
+ return isStartPoint(editor, selection.focus, path);
477
+ };
478
+ exports.isCursorAtBlockStart = isCursorAtBlockStart;
458
479
  const isSelectionAtBlockStart = (editor, options) => {
459
480
  const {
460
481
  selection
@@ -40,19 +40,22 @@ const withCheckList = editor => {
40
40
  }
41
41
 
42
42
  // If it is check-list-item, handle your own business logic
43
- if (_slate.Node.string(node).length > 0) {
44
- _slate.Transforms.splitNodes(editor, {
45
- always: true
46
- });
47
- _slate.Transforms.setNodes(editor, {
48
- checked: false
49
- }, {
50
- at: node[1]
43
+ if ((0, _core.isCursorAtBlockStart)(editor)) {
44
+ const path = (0, _core.findPath)(editor, node);
45
+ const newNode = (0, _core.generateEmptyElement)(_constants.CHECK_LIST_ITEM);
46
+ _slate.Transforms.insertNodes(editor, newNode, {
47
+ at: path
51
48
  });
52
49
  return;
53
50
  }
54
- insertBreak();
55
- return;
51
+ _slate.Transforms.splitNodes(editor, {
52
+ always: true
53
+ });
54
+ _slate.Transforms.setNodes(editor, {
55
+ checked: false
56
+ }, {
57
+ at: node[1]
58
+ });
56
59
  };
57
60
  newEditor.deleteBackward = unit => {
58
61
  const {
@@ -68,47 +68,47 @@ const withCodeBlock = editor => {
68
68
  }
69
69
  });
70
70
  return insertFragment(data);
71
- } else {
72
- // Paste into code block
73
- if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
74
- // Pasted data is code block split with code-line
75
- data.forEach((node, index) => {
76
- if (node.type === _constants.CODE_BLOCK) {
77
- const codeLineArr = node.children.map(line => line);
78
- data.splice(index, 1, ...codeLineArr);
79
- }
80
- });
81
- const newData = data.map(node => {
82
- const text = _slate.Node.string(node);
83
- const codeLine = {
84
- id: _slugid.default.nice(),
85
- type: _constants.CODE_LINE,
86
- children: [{
87
- text: text,
88
- id: _slugid.default.nice()
89
- }]
90
- };
91
- return codeLine;
92
- });
71
+ }
93
72
 
94
- // current focus code-line string not empty
95
- const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
96
- if (string.length !== 0 && _slate.Range.isCollapsed(newEditor.selection)) {
97
- const [node, ...restNode] = newData;
98
- const text = _slate.Node.string(node);
99
- insertText(text);
100
- if (restNode.length !== 0) {
101
- insertBreak();
102
- insertFragment(restNode);
103
- }
104
- return;
73
+ // Paste into code block
74
+ if ((0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
75
+ // Pasted data is code block split with code-line
76
+ data.forEach((node, index) => {
77
+ if (node.type === _constants.CODE_BLOCK) {
78
+ const codeLineArr = node.children.map(line => line);
79
+ data.splice(index, 1, ...codeLineArr);
105
80
  }
106
- return insertFragment(newData);
107
- } else {
108
- // Paste into not a code block
109
- return insertFragment(data);
81
+ });
82
+ const newData = data.map(node => {
83
+ const text = _slate.Node.string(node);
84
+ const codeLine = {
85
+ id: _slugid.default.nice(),
86
+ type: _constants.CODE_LINE,
87
+ children: [{
88
+ text: text,
89
+ id: _slugid.default.nice()
90
+ }]
91
+ };
92
+ return codeLine;
93
+ });
94
+
95
+ // current focus code-line string not empty
96
+ const string = _slate.Editor.string(newEditor, newEditor.selection.focus.path);
97
+ if (string.length !== 0 && _slate.Range.isCollapsed(newEditor.selection)) {
98
+ const [node, ...restNode] = newData;
99
+ const text = _slate.Node.string(node);
100
+ insertText(text);
101
+ if (restNode.length !== 0) {
102
+ insertBreak();
103
+ insertFragment(restNode);
104
+ }
105
+ return;
110
106
  }
107
+ return insertFragment(newData);
111
108
  }
109
+
110
+ // Paste into not a code block
111
+ return insertFragment(data);
112
112
  };
113
113
 
114
114
  // Rewrite normalizeNode
@@ -213,6 +213,17 @@ const withCodeBlock = editor => {
213
213
  }
214
214
  }
215
215
  };
216
+ newEditor.insertBreak = () => {
217
+ const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.CODE_LINE);
218
+ if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
219
+ const line = (0, _core.generateEmptyElement)(_constants.CODE_LINE);
220
+ _slate.Transforms.insertNodes(editor, line, {
221
+ at: selectedNode[1]
222
+ });
223
+ return;
224
+ }
225
+ insertBreak();
226
+ };
216
227
  return newEditor;
217
228
  };
218
229
  var _default = exports.default = withCodeBlock;
@@ -55,6 +55,14 @@ const withHeader = editor => {
55
55
  insertBreak();
56
56
  return;
57
57
  }
58
+ if ((0, _core.isCursorAtBlockStart)(newEditor)) {
59
+ const [currentNode, path] = match;
60
+ const newNode = (0, _core.generateEmptyElement)(currentNode.type);
61
+ _slate.Transforms.insertNodes(editor, newNode, {
62
+ at: path
63
+ });
64
+ return;
65
+ }
58
66
  const isAtLineEnd = isSelectionAtLineEnd(editor, match[1]);
59
67
  const nextNode = _slate.Editor.next(editor, {
60
68
  at: match[1]
@@ -20,9 +20,8 @@ var _useScrollContext = require("../../../hooks/use-scroll-context");
20
20
  var _constants2 = require("./constants");
21
21
  var _constants3 = require("../../constants");
22
22
  var _constants4 = require("../../../../constants");
23
- var _imagePlaceholder = _interopRequireDefault(require("../../../assets/images/image-placeholder.png"));
24
23
  const Image = _ref => {
25
- var _imageRef$current, _imageRef$current2;
24
+ var _imageRef$current, _imageRef$current2, _imageRef$current3;
26
25
  let {
27
26
  element,
28
27
  editor,
@@ -57,6 +56,7 @@ const Image = _ref => {
57
56
  const [isShowImageHoverMenu, setIsShowImageHoverMenu] = (0, _react.useState)(false);
58
57
  const [menuPosition, setMenuPosition] = (0, _react.useState)({});
59
58
  const [caption, setCaption] = (0, _react.useState)((data === null || data === void 0 ? void 0 : data.caption) || '');
59
+ const [isLoading, setIsLoading] = (0, _react.useState)(true);
60
60
  const registerEvent = (0, _react.useCallback)(eventList => {
61
61
  eventList.forEach(element => {
62
62
  document.addEventListener(element.eventName, element.event);
@@ -71,12 +71,17 @@ const Image = _ref => {
71
71
  var _resizerRef$current;
72
72
  event.preventDefault();
73
73
  event.stopPropagation();
74
+ if (!imageRef.current) return;
74
75
  const changeX = event.clientX - ((_resizerRef$current = resizerRef.current) === null || _resizerRef$current === void 0 ? void 0 : _resizerRef$current.getBoundingClientRect().left) - 5;
75
- const imageWidth = imageRef.current.width + changeX;
76
- if (imageWidth < 20) return;
77
- imageRef.current.width = imageWidth;
78
- setMovingWidth(imageWidth);
79
- }, []);
76
+ let newWidth = isShowImagePlaceholder ? imageRef.current.getBoundingClientRect().width + changeX : imageRef.current.width + changeX;
77
+ if (newWidth < 20) return;
78
+ if (isShowImagePlaceholder) {
79
+ imageRef.current.width.baseVal.value = newWidth;
80
+ } else {
81
+ imageRef.current.width = newWidth;
82
+ }
83
+ setMovingWidth(newWidth);
84
+ }, [isShowImagePlaceholder]);
80
85
  const onResizeEnd = (0, _react.useCallback)(event => {
81
86
  event.preventDefault();
82
87
  event.stopPropagation();
@@ -202,6 +207,7 @@ const Image = _ref => {
202
207
  if (data.src.startsWith('data:image/jpeg;base64')) {
203
208
  return (0, _helpers.handleBase64Image)(editor, path, data);
204
209
  }
210
+ setIsLoading(false);
205
211
  setIsShowImagePlaceholder(true);
206
212
  // External network images do not reload after failure to load
207
213
  if (!data.src.startsWith('http')) {
@@ -224,7 +230,22 @@ const Image = _ref => {
224
230
  });
225
231
  }
226
232
  }, [data, editor, element]);
227
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
233
+ (0, _react.useEffect)(() => {
234
+ if (imageRef.current) {
235
+ imageRef.current.onload = () => setIsLoading(false);
236
+ imageRef.current.onerror = onImageLoadError;
237
+ }
238
+ }, [data, editor]);
239
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
240
+ className: "sdoc-image-process-container",
241
+ style: {
242
+ display: isLoading ? 'inline-block' : 'none'
243
+ }
244
+ }, /*#__PURE__*/_react.default.createElement("div", {
245
+ className: "loading-spinner"
246
+ }, /*#__PURE__*/_react.default.createElement("div", {
247
+ className: "spinner"
248
+ })), children), isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement("span", Object.assign({
228
249
  className: (0, _classnames.default)('sdoc-image-wrapper', className)
229
250
  }, attributes, {
230
251
  style: {
@@ -232,14 +253,68 @@ const Image = _ref => {
232
253
  },
233
254
  onMouseOver: e => (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected),
234
255
  contentEditable: "false",
235
- suppressContentEditableWarning: true
236
- }), /*#__PURE__*/_react.default.createElement("img", {
256
+ suppressContentEditableWarning: true,
257
+ tabindex: "0"
258
+ }), /*#__PURE__*/_react.default.createElement("svg", {
259
+ xmlns: "http://www.w3.org/2000/svg",
260
+ viewBox: "0 0 360 360",
261
+ preserveAspectRatio: "xMinYMin meet",
262
+ className: (0, _classnames.default)('sdoc-image-placeholder-wrapper', {
263
+ 'image-selected': isSelected
264
+ }),
237
265
  ref: imageRef,
238
- src: _imagePlaceholder.default,
239
266
  style: getImageStyle(),
240
267
  draggable: false,
241
- alt: ""
242
- }), children), !isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
268
+ tabindex: "0"
269
+ }, /*#__PURE__*/_react.default.createElement("rect", {
270
+ width: "100%",
271
+ height: "100%",
272
+ fill: "#f0f0f0"
273
+ }), /*#__PURE__*/_react.default.createElement("g", {
274
+ className: "sdoc-image-content-wrapper",
275
+ textAnchor: "middle",
276
+ dominantBaseline: "middle",
277
+ transform: "translate(180, 180)",
278
+ contentEditable: "false"
279
+ }, /*#__PURE__*/_react.default.createElement("g", {
280
+ className: "sdoc-image-title",
281
+ transform: "translate(0, 0)"
282
+ }, /*#__PURE__*/_react.default.createElement("foreignObject", {
283
+ x: "-22%",
284
+ y: "-16",
285
+ width: "20",
286
+ height: "28"
287
+ }, /*#__PURE__*/_react.default.createElement("div", {
288
+ className: "sdocfont sdoc-exclamation-circle"
289
+ })), /*#__PURE__*/_react.default.createElement("text", {
290
+ className: "sdoc-image-tip-title",
291
+ x: "5%",
292
+ fontSize: "20",
293
+ fill: "red",
294
+ fontFamily: "Arial, sans-serif"
295
+ }, t('Image_copy_error'))), /*#__PURE__*/_react.default.createElement("text", {
296
+ className: "sdoc-image-tip-content",
297
+ x: "0",
298
+ y: "10%",
299
+ fontSize: "12",
300
+ textAnchor: "middle",
301
+ fill: "black",
302
+ fontFamily: "Arial, sans-serif"
303
+ }, t('Image_cannot_be_copied_Please_download_the_source_image')), /*#__PURE__*/_react.default.createElement("text", {
304
+ className: "sdoc-image-tip-content",
305
+ x: "0",
306
+ y: "16%",
307
+ fontSize: "12",
308
+ textAnchor: "middle",
309
+ fill: "black",
310
+ fontFamily: "Arial, sans-serif"
311
+ }, t('And_select_insert_-_image_to_upload')))), isSelected && /*#__PURE__*/_react.default.createElement("span", {
312
+ className: "image-resizer",
313
+ ref: resizerRef,
314
+ onMouseDown: onResizeStart
315
+ }), isResizing && /*#__PURE__*/_react.default.createElement("span", {
316
+ className: "image-size"
317
+ }, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.clientWidth))), /*#__PURE__*/_react.default.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/_react.default.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight)), children), !isShowImagePlaceholder && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", Object.assign({
243
318
  "data-id": element.id,
244
319
  className: (0, _classnames.default)('sdoc-image-wrapper', className)
245
320
  }, attributes, {
@@ -272,12 +347,12 @@ const Image = _ref => {
272
347
  onMouseDown: onResizeStart
273
348
  }), isResizing && /*#__PURE__*/_react.default.createElement("span", {
274
349
  className: "image-size"
275
- }, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.clientWidth))), /*#__PURE__*/_react.default.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/_react.default.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === _constants3.IMAGE_BLOCK && show_caption && /*#__PURE__*/_react.default.createElement("input", {
350
+ }, /*#__PURE__*/_react.default.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.clientWidth))), /*#__PURE__*/_react.default.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/_react.default.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === _constants3.IMAGE_BLOCK && show_caption && /*#__PURE__*/_react.default.createElement("input", {
276
351
  id: "sdoc-image-caption-input",
277
352
  ref: imageCaptionInputRef,
278
353
  className: "sdoc-image-caption-input-wrapper",
279
354
  style: {
280
- width: (data === null || data === void 0 ? void 0 : data.width) || ((_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.clientWidth)
355
+ width: (data === null || data === void 0 ? void 0 : data.width) || ((_imageRef$current3 = imageRef.current) === null || _imageRef$current3 === void 0 ? void 0 : _imageRef$current3.clientWidth)
281
356
  },
282
357
  placeholder: t('Caption'),
283
358
  autoComplete: "off",
@@ -62,8 +62,8 @@ const insertLink = function (editor, title, url) {
62
62
  let slateNode = arguments.length > 4 ? arguments[4] : undefined;
63
63
  if (position === _constants.INSERT_POSITION.CURRENT && isMenuDisabled(editor)) return;
64
64
  if (!title || !url) return;
65
+ const linkNode = genLinkNode(url, title);
65
66
  if (position === _constants.INSERT_POSITION.AFTER) {
66
- const linkNode = genLinkNode(url, title);
67
67
  let path = _slate.Editor.path(editor, editor.selection);
68
68
  if (slateNode && (slateNode === null || slateNode === void 0 ? void 0 : slateNode.type) === _constants.LIST_ITEM) {
69
69
  path = _slateReact.ReactEditor.findPath(editor, slateNode);
@@ -88,26 +88,25 @@ const insertLink = function (editor, title, url) {
88
88
  if (selection == null) return;
89
89
  const isCollapsed = _slate.Range.isCollapsed(selection);
90
90
  if (isCollapsed) {
91
- const linkNode = genLinkNode(url, title);
92
91
  _slate.Transforms.insertNodes(editor, linkNode);
93
- } else {
94
- const selectedText = _slate.Editor.string(editor, selection); // Selected text
95
- if (selectedText !== title) {
96
- // If the selected text is different from the typed text, delete the text and insert the link
97
- editor.deleteFragment();
98
- const linkNode = genLinkNode(url, title);
99
- _slate.Transforms.insertNodes(editor, linkNode);
100
- } else {
101
- // If the selected text is the same as the entered text, only the link can be wrapped
102
- const linkNode = genLinkNode(url, title);
103
- _slate.Transforms.wrapNodes(editor, linkNode, {
104
- split: true
105
- });
106
- _slate.Transforms.collapse(editor, {
107
- edge: 'end'
108
- });
109
- }
92
+ return;
110
93
  }
94
+ const selectedText = _slate.Editor.string(editor, selection); // Selected text
95
+
96
+ // If the selected text is different from the typed text, delete the text and insert the link
97
+ if (selectedText !== title) {
98
+ editor.deleteFragment();
99
+ _slate.Transforms.insertNodes(editor, linkNode);
100
+ return;
101
+ }
102
+
103
+ // If the selected text is the same as the entered text, only the link can be wrapped
104
+ _slate.Transforms.wrapNodes(editor, linkNode, {
105
+ split: true
106
+ });
107
+ _slate.Transforms.collapse(editor, {
108
+ edge: 'end'
109
+ });
111
110
  };
112
111
  exports.insertLink = insertLink;
113
112
  const updateLink = (editor, newText, newUrl) => {
@@ -129,7 +129,7 @@ const withLink = editor => {
129
129
  }
130
130
  return normalizeNode([node, path]);
131
131
  };
132
- editor.onCompositionStart = e => {
132
+ newEditor.onCompositionStart = e => {
133
133
  const {
134
134
  selection
135
135
  } = editor;
@@ -16,7 +16,8 @@ const withParagraph = editor => {
16
16
  insertText,
17
17
  deleteBackward,
18
18
  onHotKeyDown,
19
- insertFragment
19
+ insertFragment,
20
+ insertBreak
20
21
  } = editor;
21
22
  const newEditor = editor;
22
23
  newEditor.handleTab = event => {
@@ -135,6 +136,21 @@ const withParagraph = editor => {
135
136
  }
136
137
  return onHotKeyDown && onHotKeyDown(event);
137
138
  };
139
+ newEditor.insertBreak = () => {
140
+ const selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants.PARAGRAPH);
141
+ if (selectedNode != null && (0, _core.isCursorAtBlockStart)(newEditor)) {
142
+ const paragraph = (0, _core.generateDefaultParagraph)();
143
+ const targetPath = (0, _core.findPath)(editor, selectedNode);
144
+ const parentNode = (0, _core.getParentNode)(newEditor.children, selectedNode.id);
145
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) !== _constants.LIST_ITEM) {
146
+ _slate.Transforms.insertNodes(editor, paragraph, {
147
+ at: targetPath
148
+ });
149
+ return;
150
+ }
151
+ }
152
+ insertBreak();
153
+ };
138
154
  newEditor.insertFragment = data => {
139
155
  const paragraphBlock = (0, _core.getSelectedNodeByType)(editor, _constants.PARAGRAPH);
140
156
  const onlyOneListItem = data.length === 1 && (0, _helpers.isSingleListItem)(data[0]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.210",
3
+ "version": "1.0.211-test-0.2",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -606,5 +606,7 @@
606
606
  "Ask_AI": "Ask AI",
607
607
  "Enter_reply": "Enter reply",
608
608
  "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
- "AI_error_message": "Request error, please try again"
609
+ "AI_error_message": "Request error, please try again",
610
+ "Image_cannot_be_copied_Please_download_the_source_image": "Image cannot be copied. Please download the source image,",
611
+ "And_select_insert_-_image_to_upload": "and select 「insert」 - 「image」 to upload."
610
612
  }