@seafile/seafile-editor 0.3.83 → 0.3.87

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.
@@ -124,7 +124,7 @@
124
124
  content: "\e755";
125
125
  }
126
126
 
127
- .sf-editor-image-previewer .dtable-icon-fork-number {
127
+ .sf-editor-image-previewer button.dtable-icon-fork-number {
128
128
  font-family: "iconfont" !important;
129
129
  font-size: 16px;
130
130
  font-style: normal;
@@ -1,7 +1,7 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- import { Editor } from 'slate';
4
+ import { Editor, Path, Node } from 'slate';
5
5
  import ListUtils from '../editor-utils/block-element-utils/list-utils';
6
6
  import CodeUtils from '../editor-utils/block-element-utils/code-utils';
7
7
  import { isRangeCollapsed } from '../editor-utils/range-utils';
@@ -311,6 +311,35 @@ var withBlock = function withBlock(editor) {
311
311
  });
312
312
  break;
313
313
 
314
+ case 'modify_sublist_type':
315
+ var target_list_type = command.target_list_type;
316
+ var items = listUtils.getCurrentListItem();
317
+ var firstListItem = items.at(0);
318
+ var currentListPath = Path.parent(firstListItem[1]);
319
+ var parentPath = Path.parent(currentListPath);
320
+ Editor.withoutNormalizing(editor, function () {
321
+ for (var i = items.length - 1; i >= 0; i--) {
322
+ var _item = items[i];
323
+ var _path = _item[1];
324
+ Editor.liftNodes(editor, {
325
+ at: _path,
326
+ split: true
327
+ });
328
+ var currentListIndex = currentListPath.at(-1);
329
+
330
+ var currentListItemIndex = _path.at(-1);
331
+
332
+ Editor.wrapNodes(editor, {
333
+ type: target_list_type,
334
+ children: []
335
+ }, {
336
+ at: [].concat(_toConsumableArray(parentPath), [currentListItemIndex === 0 ? currentListIndex : currentListIndex + 1]),
337
+ split: true
338
+ });
339
+ }
340
+ });
341
+ break;
342
+
314
343
  case 'set_code_block':
315
344
  codeUtils.wrapCodeBlock();
316
345
  break;
@@ -336,7 +336,7 @@ var withMarkdownShortcut = function withMarkdownShortcut(editor) {
336
336
  var listItemPath = _node3[1];
337
337
  var listNode = Node.parent(editor, listItemPath); // Unwrap the list item when the selection is at the first list item of the first node of document
338
338
 
339
- if (anchor.path[0] === 0 && anchor.path[1] === 0) {
339
+ if (anchor.path[0] === 0 && anchor.path[1] === 0 && anchor.path[listItemPath.length] === 0) {
340
340
  listUtils.unwrapList();
341
341
  return;
342
342
  } // unwrap an empty list
@@ -210,43 +210,47 @@ var Plugin = function Plugin(_editor) {
210
210
 
211
211
  var table = _this.tableUtils.getSelectedTableCells();
212
212
 
213
- if (!table) {
214
- setEventTransfer(event, 'text', SfEditor.text(editor, editor.selection));
213
+ if (table) {
214
+ setEventTransfer(event, 'fragment', table);
215
215
  return;
216
216
  }
217
-
218
- setEventTransfer(event, 'fragment', table);
219
- return;
220
217
  }
221
218
 
222
- if (_this.codeUtils.isInCodeBlock() && !Range.isCollapsed(editor.selection)) {
223
- var anchorPoint = editor.selection.anchor;
224
- var focusPoint = editor.selection.focus;
225
- var anchorCodeBlock = Editor.match(_this.editor, anchorPoint, {
226
- type: 'code_block'
219
+ if (editor.selection && !Range.isCollapsed(editor.selection)) {
220
+ // get block deepest block node.
221
+ // for example: code line in a code block, paragraph in a list
222
+ var blockList = Editor.nodes(editor, {
223
+ at: editor.selection,
224
+ match: 'block'
227
225
  });
228
- var focusCodeBlock = Editor.match(_this.editor, focusPoint, {
229
- type: 'code_block'
230
- });
231
- /*
232
- If the selection is within the range of the selected code block
233
- copy the selected code line as paragraph
234
- */
235
226
 
236
- if (anchorCodeBlock && focusCodeBlock && Path.equals(focusCodeBlock[1], anchorCodeBlock[1])) {
237
- event.preventDefault();
238
- var fragment = Node.fragment(editor, editor.selection);
239
- fragment = fragment[0].children.map(function (codeLine) {
240
- var text = Node.text(codeLine);
241
- return {
242
- type: 'paragraph',
243
- children: [{
244
- text: text
245
- }]
246
- };
247
- });
248
- setEventTransfer(event, 'fragment', fragment);
249
- return;
227
+ if (blockList) {
228
+ var nodeList = Array.from(blockList);
229
+ /**
230
+ * if only one block element selected, write the selected content as paragraph or text to clipboard
231
+ * instead of use slate default behavior which write the outest element to clipboard
232
+ */
233
+
234
+ if (nodeList.length === 1) {
235
+ event.preventDefault();
236
+
237
+ var _nodeList$ = _slicedToArray(nodeList[0], 2),
238
+ node = _nodeList$[0],
239
+ path = _nodeList$[1];
240
+
241
+ path = path.slice(1);
242
+
243
+ if (node && node.type === 'paragraph') {
244
+ // get selected paragraph node in selection and write to clipboard
245
+ var fragment = Node.fragment(editor, editor.selection);
246
+ var selectedNode = Node.get(fragment[0], Array(path.length).fill(0));
247
+ setEventTransfer(event, 'fragment', [selectedNode]);
248
+ } else {
249
+ setEventTransfer(event, 'text', SfEditor.text(editor, editor.selection));
250
+ }
251
+
252
+ return;
253
+ }
250
254
  }
251
255
  }
252
256
  };
@@ -324,10 +324,10 @@ var LitsUtils = function LitsUtils(editor) {
324
324
  var listItems = [];
325
325
  list.children.forEach(function (listItem) {
326
326
  var children = listItem.children || [];
327
- var firstChild = children[0];
327
+ var child = children[0];
328
328
 
329
- if (firstChild && firstChild.type.includes('_list')) {
330
- listItems.push.apply(listItems, _toConsumableArray(_this.getNormalizedListItems(firstChild)));
329
+ if (child && child.type.includes('_list') && children.length === 1) {
330
+ listItems.push.apply(listItems, _toConsumableArray(_this.getNormalizedListItems(child)));
331
331
  } else {
332
332
  listItems.push(listItem);
333
333
  }
@@ -371,10 +371,18 @@ var LitsUtils = function LitsUtils(editor) {
371
371
 
372
372
  listItems.forEach(function (listItem, index) {
373
373
  var itemChildren = listItem.children;
374
- SfEditor.insertFragment(_this.editor, [itemChildren[0]]);
374
+
375
+ if (itemChildren[0].type.includes('list')) {
376
+ SfEditor.insertNodes(_this.editor, [itemChildren[0]]);
377
+ } else {
378
+ SfEditor.insertFragment(_this.editor, [itemChildren[0]]);
379
+ }
375
380
 
376
381
  if (itemChildren.length > 1) {
377
- SfEditor.insertNodes(_this.editor, itemChildren.slice(1));
382
+ var currentListItem = Node.get(_this.editor, [].concat(_toConsumableArray(listPath), [currentItemIndex + index]));
383
+ SfEditor.insertNodes(_this.editor, itemChildren.slice(1), {
384
+ at: [].concat(_toConsumableArray(listPath), [currentItemIndex + index, currentListItem.children.length])
385
+ });
378
386
  }
379
387
 
380
388
  if (index < listItems.length - 1) {
@@ -339,9 +339,14 @@ var EditorUtils = /*#__PURE__*/function () {
339
339
  });
340
340
  } else {
341
341
  var currentListPath = Path.parent(item[1]);
342
- var listAncesstor = Node.get(_this.editor, Path.parent(currentListPath)); // if the current selected list is a children of a different kind of list prevent modify the list type
342
+ var listAncesstor = Node.get(_this.editor, Path.parent(currentListPath)); // modify the sublist to different types
343
343
 
344
344
  if (listAncesstor.type && listAncesstor.type.includes('list')) {
345
+ _this.editor.exec({
346
+ type: "modify_sublist_type",
347
+ target_list_type: type
348
+ });
349
+
345
350
  return;
346
351
  }
347
352
 
@@ -496,7 +496,7 @@ function _nodeToSlate(node, opts) {
496
496
  return {
497
497
  type: 'link',
498
498
  data: data,
499
- nodes: children
499
+ children: children
500
500
  };
501
501
  } else {
502
502
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "0.3.83",
3
+ "version": "0.3.87",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "^0.0.9",