@seafile/seafile-editor 1.0.62 → 1.0.63

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.
@@ -66,6 +66,7 @@
66
66
  background-color: #fff;
67
67
  border: 1px solid #e5e6e8;
68
68
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.06);
69
+ color: #212529;
69
70
  }
70
71
 
71
72
  .sf-slate-editor-container .sf-slate-editor-content .article div:first-child {
@@ -52,6 +52,7 @@
52
52
  min-height: calc(100% - 15px);
53
53
  border: 1px solid #e6e6dd;
54
54
  background: #fff;
55
+ color: #212529;
55
56
  }
56
57
 
57
58
  @media (max-width: 991.98px) {
@@ -11,7 +11,7 @@
11
11
  box-shadow: 0 4px 10px #eee;
12
12
  border-radius: 4px;
13
13
  background: #fff;
14
- color: #333;
14
+ color: #212529;
15
15
  z-index: 1080;
16
16
  }
17
17
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
6
+ exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeAcrossBlocks = exports.isLastNode = exports.isLastChild = exports.isFirstNode = exports.isFirstChild = exports.isEndPoint = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getSelectedNodeEntryByTypes = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEditorString = exports.getDeepInlineChildren = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
7
7
  var _slate = require("slate");
8
8
  var _slateReact = require("slate-react");
9
9
  var _utils = require("../utils");
@@ -101,6 +101,15 @@ const getSelectedNodeEntryByType = (editor, type) => {
101
101
  return nodeEntry ? nodeEntry : null;
102
102
  };
103
103
  exports.getSelectedNodeEntryByType = getSelectedNodeEntryByType;
104
+ const getSelectedNodeEntryByTypes = (editor, types) => {
105
+ const match = n => types.includes(getNodeType(n));
106
+ const [nodeEntry] = _slate.Editor.nodes(editor, {
107
+ match,
108
+ universal: false
109
+ });
110
+ return nodeEntry ? nodeEntry : null;
111
+ };
112
+ exports.getSelectedNodeEntryByTypes = getSelectedNodeEntryByTypes;
104
113
  const getNodeEntries = (editor, options) => {
105
114
  return _slate.Editor.nodes(editor, getQueryOptions(editor, options));
106
115
  };
@@ -119,17 +119,34 @@ const withBlockquote = editor => {
119
119
  }
120
120
  deleteBackward(unit);
121
121
  };
122
- newEditor.insertFragment = data => {
122
+ newEditor.insertFragment = fragment => {
123
123
  const {
124
124
  selection
125
125
  } = editor;
126
- if (selection == null) return insertFragment(data);
126
+ if (selection == null) return insertFragment(fragment);
127
127
  const [blockquoteEntry] = _slate.Editor.nodes(editor, {
128
128
  match: n => _slate.Element.isElement(n) && n.type === _elementTypes.BLOCKQUOTE,
129
129
  universal: true
130
130
  });
131
- if (!blockquoteEntry) return insertFragment(data);
132
- const insertData = data.filter(node => node.type !== _elementTypes.TABLE);
131
+ if (!blockquoteEntry) return insertFragment(fragment);
132
+ const firstChild = fragment[0];
133
+ if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
134
+ // const nodeEntry = Editor.nodes(newEditor, { mode: 'highest' });
135
+ const nextPath = _slate.Path.next(blockquoteEntry[1]);
136
+ _slate.Transforms.insertNodes(newEditor, fragment, {
137
+ at: nextPath
138
+ });
139
+ return;
140
+ }
141
+ const insertData = fragment.map(node => {
142
+ if (node.type === _elementTypes.TABLE) {
143
+ const text = _slate.Node.string(node);
144
+ return (0, _core.generateElement)(_elementTypes.PARAGRAPH, {
145
+ childrenOrText: text
146
+ });
147
+ }
148
+ return node;
149
+ });
133
150
  return insertFragment(insertData);
134
151
  };
135
152
  return newEditor;
@@ -11,7 +11,8 @@ var _helper = require("../paragraph/helper");
11
11
  const withCheckList = editor => {
12
12
  const {
13
13
  insertBreak,
14
- deleteBackward
14
+ deleteBackward,
15
+ insertFragment
15
16
  } = editor;
16
17
  const newEditor = editor;
17
18
  newEditor.insertBreak = () => {
@@ -49,6 +50,24 @@ const withCheckList = editor => {
49
50
  }
50
51
  deleteBackward(unit);
51
52
  };
53
+ newEditor.insertFragment = fragment => {
54
+ const match = {
55
+ type: [_elementTypes.CHECK_LIST_ITEM]
56
+ };
57
+ const [checkListEntry] = (0, _core.getNodeEntries)(newEditor, {
58
+ match
59
+ });
60
+ if (!checkListEntry) return insertFragment(fragment);
61
+ const firstChild = fragment[0];
62
+ if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
63
+ const nextPath = _slate.Path.next(checkListEntry[1]);
64
+ _slate.Transforms.insertNodes(newEditor, fragment, {
65
+ at: nextPath
66
+ });
67
+ return;
68
+ }
69
+ return insertFragment(fragment);
70
+ };
52
71
  return newEditor;
53
72
  };
54
73
  var _default = exports.default = withCheckList;
@@ -5,6 +5,7 @@
5
5
  padding: 6px 8px;
6
6
  position: relative;
7
7
  align-items: center;
8
+ color: #212529;
8
9
  }
9
10
 
10
11
  .sf-header-menu.header-toggle-disabled::after {
@@ -12,6 +12,7 @@ var _helper = require("./helper");
12
12
  var _keyboard = require("../../constants/keyboard");
13
13
  var _common = require("../../../utils/common");
14
14
  var _constants = require("../../constants");
15
+ var _elementTypes = require("../../constants/element-types");
15
16
  const isSelectionAtLineEnd = (editor, path) => {
16
17
  const {
17
18
  selection
@@ -89,20 +90,33 @@ const withHeader = editor => {
89
90
  }
90
91
  return deleteBackward(unit);
91
92
  };
92
- newEditor.insertFragment = data => {
93
- var _data$, _data$$children;
94
- const headerNode = (0, _core.getSelectedNodeByTypes)(editor, _constants.HEADERS);
95
- const headerText = _slate.Node.string(headerNode || {
96
- children: []
97
- });
98
- const isSingleListItem = data.length === 1 && ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : (_data$$children = _data$.children) === null || _data$$children === void 0 ? void 0 : _data$$children.length) === 1 && _constants.LIST_TYPE_ARRAY.includes(data[0].type);
99
- // Insert a list item when the header is empty, insert only the text
100
- if (headerNode && headerText.length === 0 && isSingleListItem) {
101
- const text = _slate.Node.string(data[0]);
102
- insertText(text);
103
- return;
93
+ newEditor.insertFragment = fragment => {
94
+ const headerEntry = (0, _core.getSelectedNodeEntryByTypes)(editor, _constants.HEADERS);
95
+ if (!headerEntry) return insertFragment(fragment);
96
+ const firstChild = fragment[0];
97
+ if (fragment.length === 1) {
98
+ // is single list item
99
+ if (_constants.LIST_TYPE_ARRAY.includes(firstChild.type)) {
100
+ if (firstChild.children.length === 1) {
101
+ const text = _slate.Node.string(fragment[0]);
102
+ insertText(text);
103
+ return;
104
+ }
105
+ const nextPath = _slate.Path.next(headerEntry[1]);
106
+ _slate.Transforms.insertNodes(newEditor, fragment, {
107
+ at: nextPath
108
+ });
109
+ return;
110
+ }
111
+ if (firstChild.type === _elementTypes.TABLE) {
112
+ const nextPath = _slate.Path.next(headerEntry[1]);
113
+ _slate.Transforms.insertNodes(newEditor, fragment, {
114
+ at: nextPath
115
+ });
116
+ return;
117
+ }
104
118
  }
105
- return insertFragment(data);
119
+ return insertFragment(fragment);
106
120
  };
107
121
  newEditor.onHotKeyDown = event => {
108
122
  const HOT_KEYS = (0, _common.isMac)() ? _keyboard.MAC_HOTKEYS_EVENT_HEADER : _keyboard.WIN_HOTKEYS_EVENT_HEADER;
@@ -50,10 +50,18 @@ const trimList = listRoot => {
50
50
  return [...findListItemsWithContent(first), ...rest];
51
51
  };
52
52
  const wrapNodeIntoListItem = node => {
53
- return node.type === _elementTypes.LIST_ITEM ? node : {
53
+ if (node.type === _elementTypes.LIST_ITEM) return node;
54
+ return {
54
55
  id: _slugid.default.nice(),
55
56
  type: _elementTypes.LIST_ITEM,
56
- children: [node]
57
+ children: [{
58
+ id: _slugid.default.nice(),
59
+ type: _elementTypes.PARAGRAPH,
60
+ children: [{
61
+ id: _slugid.default.nice(),
62
+ text: _slate.Node.string(node)
63
+ }]
64
+ }]
57
65
  };
58
66
  };
59
67
  const isSingleLic = fragment => {
@@ -26,7 +26,8 @@ const isSelectionAtLineStart = (editor, path) => {
26
26
  const withParagraph = editor => {
27
27
  const {
28
28
  deleteBackward,
29
- insertBreak
29
+ insertBreak,
30
+ insertFragment
30
31
  } = editor;
31
32
  const newEditor = editor;
32
33
  newEditor.insertBreak = () => {
@@ -88,6 +89,30 @@ const withParagraph = editor => {
88
89
  }
89
90
  return deleteBackward(unit);
90
91
  };
92
+ newEditor.insertFragment = fragment => {
93
+ const match = {
94
+ type: [_elementTypes.PARAGRAPH]
95
+ };
96
+ const [paragraphEntry] = (0, _core.getNodeEntries)(newEditor, {
97
+ match
98
+ });
99
+ if (!paragraphEntry) return insertFragment(fragment);
100
+ const firstChild = fragment[0];
101
+ if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
102
+ const hasVoidNode = paragraphEntry[0].children.some(item => _slate.Editor.isVoid(newEditor, item));
103
+ if (_slate.Node.string(paragraphEntry[0]).length === 0 && !hasVoidNode) {
104
+ _slate.Transforms.removeNodes(newEditor);
105
+ _slate.Transforms.insertNodes(newEditor, fragment);
106
+ return;
107
+ }
108
+ const nextPath = _slate.Path.next(paragraphEntry[1]);
109
+ _slate.Transforms.insertNodes(newEditor, fragment, {
110
+ at: nextPath
111
+ });
112
+ return;
113
+ }
114
+ return insertFragment(fragment);
115
+ };
91
116
  return newEditor;
92
117
  };
93
118
  var _default = exports.default = withParagraph;
@@ -103,10 +103,11 @@ const selectCellByGrid = (editor, rowIndex, colIndex) => {
103
103
  exports.selectCellByGrid = selectCellByGrid;
104
104
  const getSelectedTableCells = editor => {
105
105
  const [tableEntry] = getTableEntry(editor);
106
- if (!tableEntry) return [];
106
+ if (!tableEntry) return null;
107
107
  const [tableNode] = tableEntry;
108
108
  const tableRows = tableNode.children;
109
109
  const selectGrid = getSelectGrid(editor);
110
+ if (!selectGrid) return null;
110
111
  const {
111
112
  startRowIndex,
112
113
  endRowIndex,
@@ -72,8 +72,9 @@ const generateTable = options => {
72
72
  childrenOrText = ''
73
73
  } = options;
74
74
  let rows = [];
75
- const align = new Array(columnNum).fill(null);
75
+ let align = [];
76
76
  if (rowNum) {
77
+ align = new Array(columnNum).fill(null);
77
78
  rows = Array.from({
78
79
  length: rowNum
79
80
  }, () => generateTableRow({
@@ -89,6 +90,8 @@ const generateTable = options => {
89
90
  if (!Array.isArray(childrenOrText)) {
90
91
  throw Error('childrenOrText must be a string or a Node array!');
91
92
  }
93
+ const columns = childrenOrText[0].children.length;
94
+ align = new Array(columns).fill(null);
92
95
  }
93
96
  return (0, _core.generateElement)(_elementTypes.TABLE, {
94
97
  childrenOrText: rowNum ? rows : childrenOrText,
@@ -66,21 +66,77 @@ const withTable = editor => {
66
66
  }
67
67
  return (0, _helper.pasteContentIntoTable)(newEditor, data);
68
68
  };
69
- newEditor.insertFragment = data => {
69
+ newEditor.insertFragment = fragment => {
70
70
  const isTableActive = (0, _helper.isInTable)(newEditor);
71
- if (!isTableActive) return insertFragment && insertFragment(data);
72
- if (!Array.isArray(data)) return;
71
+ if (!isTableActive) return insertFragment && insertFragment(fragment);
72
+ if (!Array.isArray(fragment)) return;
73
+ const firstChild = fragment[0];
74
+ if (fragment.length === 1 && firstChild.type === _elementTypes.TABLE) {
75
+ const {
76
+ tableEntry,
77
+ rowEntry
78
+ } = (0, _helper.getTableFocusingInfos)(editor);
79
+ let selectedInfo = (0, _helper.getSelectGrid)(editor);
80
+ if (!selectedInfo) {
81
+ const tableCellEntry = (0, _core.getSelectedNodeEntryByType)(editor, _elementTypes.TABLE_CELL);
82
+ if (!tableCellEntry) return;
83
+ const [, path] = tableCellEntry;
84
+ const startColIndex = path.pop();
85
+ const startRowIndex = path.pop();
86
+ selectedInfo = {
87
+ startRowIndex,
88
+ startColIndex
89
+ };
90
+ }
91
+ const {
92
+ startRowIndex,
93
+ startColIndex
94
+ } = selectedInfo;
95
+ const [tableNode, tablePath] = tableEntry;
96
+ const [rowNode] = rowEntry;
97
+ const tableWidth = rowNode.children.length;
98
+ const tableHeight = tableNode.children.length;
99
+ firstChild.children.forEach((clipRow, clipRowIndex) => {
100
+ // Out of table
101
+ if (startRowIndex + clipRowIndex >= tableHeight) return true;
102
+
103
+ // rowPath = [...tablePath, rowIndex + clipRowIndex];
104
+ const currentRowPath = [...tablePath, startRowIndex + clipRowIndex];
105
+ clipRow.children.forEach((clipCol, clipColIndex) => {
106
+ // Out of table
107
+ if (startColIndex + clipColIndex >= tableWidth) return true;
108
+
109
+ // cellPath = [...rowPath, columnIndex + clipColIndex];
110
+ const currentCellPath = [...currentRowPath, startColIndex + clipColIndex];
111
+ const currentCellChildPath = currentCellPath.concat(0);
112
+ _slate.Transforms.removeNodes(editor, {
113
+ at: currentCellChildPath
114
+ });
115
+ const otherBlockTypes = [..._constants.HEADERS, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH];
116
+ const newChildren = clipCol.children.map(item => {
117
+ if (otherBlockTypes.includes(item.type)) return item.children;
118
+ return item;
119
+ }).flat();
120
+ _slate.Transforms.insertNodes(editor, newChildren, {
121
+ at: currentCellChildPath
122
+ });
123
+ return false;
124
+ });
125
+ return false;
126
+ });
127
+ return;
128
+ }
73
129
  const notSupportTypes = [_elementTypes.TABLE, _elementTypes.BLOCKQUOTE, _elementTypes.UNORDERED_LIST, _elementTypes.ORDERED_LIST, _elementTypes.CODE_BLOCK];
74
- const isDataValid = data.some(item => notSupportTypes.includes(item.type));
130
+ const isDataValid = fragment.some(item => notSupportTypes.includes(item.type));
75
131
  if (isDataValid) {
76
- const strContent = data.reduce((ret, item) => {
132
+ const strContent = fragment.reduce((ret, item) => {
77
133
  return ret + _slate.Node.string(item);
78
134
  }, '');
79
135
  _slate.Editor.insertText(newEditor, strContent);
80
136
  return;
81
137
  }
82
138
  const otherBlockTypes = [..._constants.HEADERS, _elementTypes.CHECK_LIST_ITEM, _elementTypes.PARAGRAPH];
83
- const newChildren = data.map(item => {
139
+ const newChildren = fragment.map(item => {
84
140
  if (otherBlockTypes.includes(item.type)) return item.children;
85
141
  return item;
86
142
  }).flat();
@@ -219,11 +275,19 @@ const withTable = editor => {
219
275
  }
220
276
  event.preventDefault();
221
277
  event.stopPropagation();
278
+ // selected multiple cells
222
279
  const tableNode = (0, _helper.getSelectedTableCells)(newEditor);
223
280
  if (tableNode) {
224
281
  (0, _setEventTransfer.default)(event, 'fragment', tableNode);
225
282
  return true;
226
283
  }
284
+ // selected only one cell
285
+ const tableCell = (0, _core.getSelectedNodeByType)(newEditor, _elementTypes.TABLE_CELL);
286
+ if (tableCell) {
287
+ (0, _setEventTransfer.default)(event, 'fragment', tableCell.children);
288
+ return true;
289
+ }
290
+ return false;
227
291
  };
228
292
  newEditor.normalizeNode = _ref => {
229
293
  let [node, path] = _ref;
@@ -43,7 +43,7 @@
43
43
  text-transform: uppercase;
44
44
  text-align: center;
45
45
  border-radius: 3px;
46
- color: #333333;
46
+ color: #212529;
47
47
  box-sizing: border-box;
48
48
  border-style: solid;
49
49
  border-width: 1px;
@@ -155,6 +155,7 @@
155
155
  height: auto;
156
156
  min-height: 100% !important;
157
157
  margin: 0 !important;
158
+ color: #212529;
158
159
  }
159
160
 
160
161
  .longtext-content-container .sf-simple-slate-editor-container .article > div[role="textbox"] > :first-child {
@@ -23,6 +23,7 @@
23
23
  height: auto;
24
24
  min-height: 100% !important;
25
25
  border: 0;
26
+ color: #212529;
26
27
  }
27
28
 
28
29
  .longtext-preview-container .article :first-child {
@@ -73,7 +73,7 @@ const codeBlockRule = (element, parseChild) => {
73
73
  }]
74
74
  };
75
75
  }
76
- const codes = content.slugid('\n').filter(Boolean);
76
+ const codes = content.split('\n').filter(Boolean);
77
77
  return codes.map(item => {
78
78
  return {
79
79
  id: _slugid.default.nice(),
@@ -34,8 +34,9 @@ class EventProxy {
34
34
  const editor = this.editor;
35
35
  if (editor.onCopy) {
36
36
  const isHandled = editor.onCopy(event);
37
- if (isHandled) return;
37
+ if (isHandled) return true;
38
38
  }
39
+ return false;
39
40
  });
40
41
  this.editor = _editor;
41
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {