@seafile/sdoc-editor 1.0.84 → 1.0.86
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.
- package/dist/basic-sdk/extension/core/queries/index.js +10 -2
- package/dist/basic-sdk/extension/core/transforms/delete-merge.js +174 -0
- package/dist/basic-sdk/extension/core/utils/index.js +2 -0
- package/dist/basic-sdk/extension/plugins/image/helpers.js +22 -1
- package/dist/basic-sdk/extension/plugins/image/plugin.js +3 -0
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +21 -4
- package/dist/basic-sdk/extension/plugins/list/model.js +9 -1
- package/dist/basic-sdk/extension/plugins/list/plugin/index.js +80 -19
- package/dist/basic-sdk/extension/plugins/list/transforms/is-across-list-items.js +25 -0
- package/dist/basic-sdk/extension/plugins/list/transforms/move-list-item-sublist-to-list-item-sublist.js +63 -0
- package/dist/basic-sdk/extension/plugins/list/transforms/remove-list-item.js +64 -0
- package/dist/basic-sdk/extension/plugins/seatable-column/helpers.js +37 -10
- package/dist/basic-sdk/extension/plugins/seatable-tables/formatter/link-formatter/utils.js +2 -1
- package/dist/constants/index.js +2 -1
- package/dist/pages/document-plugin-editor.js +2 -0
- package/package.json +1 -1
|
@@ -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.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = 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.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = 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");
|
|
@@ -553,4 +553,12 @@ exports.getEndPoint = getEndPoint;
|
|
|
553
553
|
const getPointBefore = (editor, at) => {
|
|
554
554
|
return _slate.Editor.before(editor, at);
|
|
555
555
|
};
|
|
556
|
-
exports.getPointBefore = getPointBefore;
|
|
556
|
+
exports.getPointBefore = getPointBefore;
|
|
557
|
+
const isFirstChild = path => {
|
|
558
|
+
return path.at(-1) === 0;
|
|
559
|
+
};
|
|
560
|
+
exports.isFirstChild = isFirstChild;
|
|
561
|
+
const someNode = (editor, options) => {
|
|
562
|
+
return !!findNode(editor, options);
|
|
563
|
+
};
|
|
564
|
+
exports.someNode = someNode;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deleteMerge = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {*} editor
|
|
11
|
+
* @param {*} options { at, distance, hanging, reverse, test, unit, voids }
|
|
12
|
+
*/
|
|
13
|
+
const deleteMerge = function (editor) {
|
|
14
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
16
|
+
const {
|
|
17
|
+
distance = 1,
|
|
18
|
+
reverse = false,
|
|
19
|
+
unit = 'character',
|
|
20
|
+
voids = false
|
|
21
|
+
} = options;
|
|
22
|
+
let {
|
|
23
|
+
at = editor.selection,
|
|
24
|
+
hanging = false
|
|
25
|
+
} = options;
|
|
26
|
+
if (!at) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (_slate.Range.isRange(at) && _slate.Range.isCollapsed(at)) {
|
|
30
|
+
at = at.anchor;
|
|
31
|
+
}
|
|
32
|
+
if (_slate.Point.isPoint(at)) {
|
|
33
|
+
const furthestVoid = _slate.Editor.void(editor, {
|
|
34
|
+
at,
|
|
35
|
+
mode: 'highest'
|
|
36
|
+
});
|
|
37
|
+
if (!voids && furthestVoid) {
|
|
38
|
+
const [, voidPath] = furthestVoid;
|
|
39
|
+
at = voidPath;
|
|
40
|
+
} else {
|
|
41
|
+
const opts = {
|
|
42
|
+
distance,
|
|
43
|
+
unit
|
|
44
|
+
};
|
|
45
|
+
const target = reverse ? _slate.Editor.before(editor, at, opts) || _slate.Editor.start(editor, []) : _slate.Editor.after(editor, at.opts) || _slate.Editor.end(editor, []);
|
|
46
|
+
at = {
|
|
47
|
+
anchor: at,
|
|
48
|
+
focus: target
|
|
49
|
+
};
|
|
50
|
+
hanging = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (_slate.Path.isPath(at)) {
|
|
54
|
+
_slate.Transforms.removeNodes(editor, at, {
|
|
55
|
+
voids
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (_slate.Range.isCollapsed(at)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!hanging) {
|
|
63
|
+
at = _slate.Editor.unhangRange(editor, at, {
|
|
64
|
+
voids
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
let [start, end] = _slate.Range.edges(at);
|
|
68
|
+
const startBlock = _slate.Editor.above(editor, {
|
|
69
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
70
|
+
at: start,
|
|
71
|
+
voids
|
|
72
|
+
});
|
|
73
|
+
const endBlock = _slate.Editor.above(editor, {
|
|
74
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
75
|
+
at: end,
|
|
76
|
+
voids
|
|
77
|
+
});
|
|
78
|
+
const isAcrossBlocks = startBlock && endBlock && !_slate.Path.equals(startBlock[1], endBlock[1]);
|
|
79
|
+
const isSingleText = _slate.Path.equals(start.path, end.path);
|
|
80
|
+
const startVoid = voids ? null : _slate.Editor.void(editor, {
|
|
81
|
+
at: start,
|
|
82
|
+
mode: 'highest'
|
|
83
|
+
});
|
|
84
|
+
const endVoid = voids ? null : _slate.Editor.void(editor, {
|
|
85
|
+
at: end,
|
|
86
|
+
mode: 'highest'
|
|
87
|
+
});
|
|
88
|
+
if (startVoid) {
|
|
89
|
+
const before = _slate.Editor.before(editor, start);
|
|
90
|
+
if (before && startBlock && _slate.Path.isAncestor(startBlock[1], before.path)) {
|
|
91
|
+
start = before;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (endVoid) {
|
|
95
|
+
const after = _slate.Editor.after(editor, end);
|
|
96
|
+
if (after && endVoid && _slate.Path.isAncestor(endBlock[1], after.path)) {
|
|
97
|
+
end = after;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const matches = [];
|
|
101
|
+
let lastPath = undefined;
|
|
102
|
+
const _nodes = _slate.Editor.nodes(editor, {
|
|
103
|
+
at,
|
|
104
|
+
voids
|
|
105
|
+
});
|
|
106
|
+
for (const entry of _nodes) {
|
|
107
|
+
const [node, path] = entry;
|
|
108
|
+
if (lastPath && _slate.Path.compare(path, lastPath) === 0) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!voids && _slate.Editor.isVoid(editor, node) || !_slate.Path.isCommon(path, start.path) && !_slate.Path.isCommon(path, end.path)) {
|
|
112
|
+
matches.push(entry);
|
|
113
|
+
lastPath = path;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const pathRefs = Array.from(matches, _ref => {
|
|
117
|
+
let [, p] = _ref;
|
|
118
|
+
return _slate.Editor.pathRef(editor, p);
|
|
119
|
+
});
|
|
120
|
+
const startRef = _slate.Editor.pointRef(editor, start);
|
|
121
|
+
const endRef = _slate.Editor.pointRef(editor, end);
|
|
122
|
+
if (!isSingleText && !startVoid) {
|
|
123
|
+
const point = startRef.current;
|
|
124
|
+
const [node] = _slate.Editor.leaf(editor, point);
|
|
125
|
+
const {
|
|
126
|
+
path
|
|
127
|
+
} = point;
|
|
128
|
+
const {
|
|
129
|
+
offset
|
|
130
|
+
} = start;
|
|
131
|
+
const text = node.text.slice(offset);
|
|
132
|
+
editor.apply({
|
|
133
|
+
type: 'remove_text',
|
|
134
|
+
path,
|
|
135
|
+
offset,
|
|
136
|
+
text
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
for (const pathRef of pathRefs) {
|
|
140
|
+
const path = pathRef.unref();
|
|
141
|
+
_slate.Transforms.removeNodes(editor, {
|
|
142
|
+
at: path,
|
|
143
|
+
voids
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!endVoid) {
|
|
147
|
+
const point = endRef.current;
|
|
148
|
+
const [node] = _slate.Editor.leaf(editor, point);
|
|
149
|
+
const {
|
|
150
|
+
path
|
|
151
|
+
} = point;
|
|
152
|
+
const offset = isSingleText ? start.offset : 0;
|
|
153
|
+
const text = node.text.slice(offset, end.offset);
|
|
154
|
+
editor.apply({
|
|
155
|
+
offset,
|
|
156
|
+
path,
|
|
157
|
+
text,
|
|
158
|
+
type: 'remove_text'
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!isSingleText && isAcrossBlocks && endRef.current && start.current) {
|
|
162
|
+
_slate.Transforms.mergeNodes(editor, {
|
|
163
|
+
at: endRef.current,
|
|
164
|
+
hanging: true,
|
|
165
|
+
voids
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const point = endRef.unref() || startRef.unref();
|
|
169
|
+
if (options.at == null && point) {
|
|
170
|
+
_slate.Transforms.select(editor, point);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
exports.deleteMerge = deleteMerge;
|
|
@@ -60,6 +60,8 @@ function Placeholder(props) {
|
|
|
60
60
|
t
|
|
61
61
|
} = (0, _reactI18next.useTranslation)();
|
|
62
62
|
return /*#__PURE__*/_react.default.createElement("span", {
|
|
63
|
+
contentEditable: "false",
|
|
64
|
+
suppressContentEditableWarning: true,
|
|
63
65
|
style: {
|
|
64
66
|
position: 'absolute',
|
|
65
67
|
top: `${top}px`,
|
|
@@ -9,10 +9,12 @@ var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
|
9
9
|
var _slate = require("@seafile/slate");
|
|
10
10
|
var _slateReact = require("@seafile/slate-react");
|
|
11
11
|
var _slugid = _interopRequireDefault(require("slugid"));
|
|
12
|
+
var _dtableUtils = require("dtable-utils");
|
|
12
13
|
var _context = _interopRequireDefault(require("../../../../context"));
|
|
13
14
|
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
14
15
|
var _core = require("../../core");
|
|
15
16
|
var _helpers = require("../../toolbar/side-toolbar/helpers");
|
|
17
|
+
var _helpers2 = require("../seatable-column/helpers");
|
|
16
18
|
var _constants = require("../../../constants");
|
|
17
19
|
var _constants2 = require("../../constants");
|
|
18
20
|
var _base64ToUnit8array = _interopRequireDefault(require("../../../../utils/base64-to-unit8array"));
|
|
@@ -129,7 +131,26 @@ const updateImage = (editor, data) => {
|
|
|
129
131
|
});
|
|
130
132
|
};
|
|
131
133
|
exports.updateImage = updateImage;
|
|
132
|
-
const getImageURL =
|
|
134
|
+
const getImageURL = (data, editor) => {
|
|
135
|
+
const {
|
|
136
|
+
src: url,
|
|
137
|
+
column_key
|
|
138
|
+
} = data;
|
|
139
|
+
if (column_key) {
|
|
140
|
+
const column = (0, _helpers2.getColumnByKey)(editor.columns || [], column_key);
|
|
141
|
+
const {
|
|
142
|
+
type
|
|
143
|
+
} = column || {};
|
|
144
|
+
if (type === _dtableUtils.CellType.IMAGE) {
|
|
145
|
+
const imgUrl = editor.getColumnCellValue(column_key) || '';
|
|
146
|
+
const firstSrc = imgUrl.split(',')[0];
|
|
147
|
+
return firstSrc;
|
|
148
|
+
} else if (type === _dtableUtils.CellType.DIGITAL_SIGN) {
|
|
149
|
+
const partUrl = editor.getColumnCellValue(column_key) || '';
|
|
150
|
+
const imgUrl = (0, _helpers2.getDigitalSignImgUrl)(partUrl);
|
|
151
|
+
return imgUrl;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
133
154
|
if (url && url.startsWith('http')) return url;
|
|
134
155
|
const serviceUrl = _context.default.getSetting('serviceUrl');
|
|
135
156
|
const assetsUrl = _context.default.getSetting('assetsUrl');
|
|
@@ -159,6 +159,9 @@ const withImage = editor => {
|
|
|
159
159
|
}
|
|
160
160
|
if ((0, _core.isSelectionAtBlockStart)(editor)) {
|
|
161
161
|
const path = selection.anchor.path;
|
|
162
|
+
if ((0, _core.isFirstChild)(path)) {
|
|
163
|
+
return deleteBackward(unit);
|
|
164
|
+
}
|
|
162
165
|
const beforePath = [path[0] - 1];
|
|
163
166
|
const beforeBlock = _slate.Editor.node(editor, beforePath);
|
|
164
167
|
if (beforeBlock && beforeBlock[0].type === _constants.IMAGE_BLOCK) {
|
|
@@ -19,6 +19,7 @@ var _hoverMenu = _interopRequireDefault(require("./hover-menu"));
|
|
|
19
19
|
var _useScrollContext = require("../../../hooks/use-scroll-context");
|
|
20
20
|
var _constants2 = require("./constants");
|
|
21
21
|
var _constants3 = require("../../constants");
|
|
22
|
+
var _constants4 = require("../../../../constants");
|
|
22
23
|
var _imagePlaceholder = _interopRequireDefault(require("../../../assets/images/image-placeholder.png"));
|
|
23
24
|
const Image = _ref => {
|
|
24
25
|
var _imageRef$current, _imageRef$current2;
|
|
@@ -37,7 +38,8 @@ const Image = _ref => {
|
|
|
37
38
|
border_type = _constants2.IMAGE_BORDER_TYPE[0].type
|
|
38
39
|
} = element;
|
|
39
40
|
const {
|
|
40
|
-
show_caption = false
|
|
41
|
+
show_caption = false,
|
|
42
|
+
column_key
|
|
41
43
|
} = data;
|
|
42
44
|
const path = _slateReact.ReactEditor.findPath(editor, element);
|
|
43
45
|
const nodeEntry = _slate.Editor.node(editor, [path[0]]);
|
|
@@ -158,6 +160,21 @@ const Image = _ref => {
|
|
|
158
160
|
};
|
|
159
161
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
162
|
}, [isShowImageHoverMenu, onHideImageHoverMenu]);
|
|
163
|
+
const onImageColumnToggle = (0, _react.useCallback)(() => {
|
|
164
|
+
// Handle switching to empty data and switching back
|
|
165
|
+
setIsShowImagePlaceholder(false);
|
|
166
|
+
}, []);
|
|
167
|
+
(0, _react.useEffect)(() => {
|
|
168
|
+
let unsubscribeImageColumnToggle = null;
|
|
169
|
+
if (column_key) {
|
|
170
|
+
const eventBus = _eventBus.default.getInstance();
|
|
171
|
+
unsubscribeImageColumnToggle = eventBus.subscribe(_constants4.EXTERNAL_EVENT.IMAGE_COLUMN_TOGGLE, onImageColumnToggle);
|
|
172
|
+
}
|
|
173
|
+
return () => {
|
|
174
|
+
unsubscribeImageColumnToggle && unsubscribeImageColumnToggle();
|
|
175
|
+
};
|
|
176
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
|
+
}, [column_key]);
|
|
161
178
|
const setPosition = (0, _react.useCallback)(() => {
|
|
162
179
|
if (imageRef.current) {
|
|
163
180
|
const {
|
|
@@ -176,10 +193,10 @@ const Image = _ref => {
|
|
|
176
193
|
}, [setPosition]);
|
|
177
194
|
const reloadImage = (0, _react.useCallback)(() => {
|
|
178
195
|
if (imageRef.current) {
|
|
179
|
-
imageRef.current['src'] = (0, _helpers.getImageURL)(data
|
|
196
|
+
imageRef.current['src'] = (0, _helpers.getImageURL)(data, editor);
|
|
180
197
|
setIsShowImagePlaceholder(false);
|
|
181
198
|
}
|
|
182
|
-
}, [data
|
|
199
|
+
}, [data, editor]);
|
|
183
200
|
const onImageLoadError = (0, _react.useCallback)(() => {
|
|
184
201
|
// Check is due to the image is pasted from the clipboard in base64
|
|
185
202
|
if (data.src.startsWith('data:image/jpeg;base64')) {
|
|
@@ -244,7 +261,7 @@ const Image = _ref => {
|
|
|
244
261
|
}),
|
|
245
262
|
onClick: onClickImage,
|
|
246
263
|
ref: imageRef,
|
|
247
|
-
src: (0, _helpers.getImageURL)(data
|
|
264
|
+
src: (0, _helpers.getImageURL)(data, editor),
|
|
248
265
|
style: getImageStyle(),
|
|
249
266
|
draggable: false,
|
|
250
267
|
onError: onImageLoadError,
|
|
@@ -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.generateEmptyListItem = exports.generateEmptyListContent = exports.generateEmptyList = exports.default = void 0;
|
|
7
|
+
exports.generateListItem = exports.generateEmptyListItem = exports.generateEmptyListContent = exports.generateEmptyList = exports.default = void 0;
|
|
8
8
|
var _slugid = _interopRequireDefault(require("slugid"));
|
|
9
9
|
var _constants = require("../../constants");
|
|
10
10
|
var _core = require("../../core");
|
|
@@ -25,6 +25,14 @@ const generateEmptyListItem = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
exports.generateEmptyListItem = generateEmptyListItem;
|
|
28
|
+
const generateListItem = () => {
|
|
29
|
+
return {
|
|
30
|
+
id: _slugid.default.nice(),
|
|
31
|
+
type: _constants.LIST_ITEM,
|
|
32
|
+
children: [generateEmptyListContent()]
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.generateListItem = generateListItem;
|
|
28
36
|
const generateEmptyListContent = () => {
|
|
29
37
|
return (0, _core.generateEmptyElement)(_constants.PARAGRAPH);
|
|
30
38
|
};
|
|
@@ -14,6 +14,10 @@ var _core = require("../../../core");
|
|
|
14
14
|
var _constants = require("../../../constants");
|
|
15
15
|
var _helpers = require("../../../toolbar/side-toolbar/helpers");
|
|
16
16
|
var _transforms = require("../transforms");
|
|
17
|
+
var _queries = require("../queries");
|
|
18
|
+
var _removeListItem = require("../transforms/remove-list-item");
|
|
19
|
+
var _isAcrossListItems = require("../transforms/is-across-list-items");
|
|
20
|
+
var _deleteMerge = require("../../../core/transforms/delete-merge");
|
|
17
21
|
const withList = editor => {
|
|
18
22
|
const {
|
|
19
23
|
insertBreak,
|
|
@@ -35,28 +39,85 @@ const withList = editor => {
|
|
|
35
39
|
deleteBackward(unit);
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
const deleteBackwardList = () => {
|
|
43
|
+
const res = (0, _queries.getListItemEntry)(editor, {});
|
|
44
|
+
let moved = false;
|
|
45
|
+
if (res) {
|
|
46
|
+
const {
|
|
47
|
+
list,
|
|
48
|
+
listItem
|
|
49
|
+
} = res;
|
|
50
|
+
if ((0, _core.isSelectionAtBlockStart)(editor, {
|
|
51
|
+
match: node => node.type === _constants.LIST_ITEM
|
|
52
|
+
})) {
|
|
53
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
54
|
+
let moved = (0, _transforms.removeFirstListItem)(editor, {
|
|
55
|
+
list,
|
|
56
|
+
listItem
|
|
57
|
+
});
|
|
58
|
+
if (moved) return true;
|
|
59
|
+
moved = (0, _removeListItem.removeListItem)(editor, {
|
|
60
|
+
list,
|
|
61
|
+
listItem
|
|
62
|
+
});
|
|
63
|
+
if (moved) {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
const previousLiPath = (0, _core.getPreviousPath)(listItem[1]);
|
|
66
|
+
(0, _core.focusEditor)(editor, _slate.Editor.end(editor, [...previousLiPath, 0]));
|
|
67
|
+
}, 0);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if ((0, _core.isFirstChild)(listItem[1]) && !(0, _queries.isListNested)(editor, list[1])) {
|
|
71
|
+
(0, _transforms.unwrapList)(newEditor, {
|
|
72
|
+
at: listItem[1]
|
|
73
|
+
});
|
|
74
|
+
const focusPoint = _slate.Editor.start(newEditor, listItem[1]);
|
|
75
|
+
(0, _core.focusEditor)(newEditor, focusPoint);
|
|
76
|
+
moved = true;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const pointBeforeListItem = _slate.Editor.before(editor, editor.selection.focus);
|
|
80
|
+
let currentLic = null;
|
|
81
|
+
let hasMultipleChildren = false;
|
|
82
|
+
const editorOptions = {
|
|
83
|
+
...editor,
|
|
84
|
+
selection: {
|
|
85
|
+
anchor: editor.selection.anchor,
|
|
86
|
+
focus: pointBeforeListItem
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (pointBeforeListItem && (0, _isAcrossListItems.isAcrossListItems)(editorOptions)) {
|
|
90
|
+
// get closest lic ancestor of current selectable
|
|
91
|
+
const _licNodes = (0, _core.getNodeEntries)(editor, {
|
|
92
|
+
at: listItem[1],
|
|
93
|
+
match: node => node.type === _constants.PARAGRAPH,
|
|
94
|
+
mode: 'lowest'
|
|
95
|
+
});
|
|
96
|
+
currentLic = [..._licNodes][0];
|
|
97
|
+
hasMultipleChildren = currentLic[0].children.length > 1;
|
|
98
|
+
}
|
|
99
|
+
(0, _deleteMerge.deleteMerge)(editor, {
|
|
100
|
+
reverse: true,
|
|
101
|
+
unit
|
|
102
|
+
});
|
|
103
|
+
moved = true;
|
|
104
|
+
if (!currentLic || !hasMultipleChildren) return;
|
|
105
|
+
const leftoverListItem = _slate.Editor.node(editor, {
|
|
106
|
+
at: _slate.Path.parent(currentLic[1])
|
|
107
|
+
});
|
|
108
|
+
if (leftoverListItem && leftoverListItem[0].children.length === 0) {
|
|
109
|
+
// remove the leftover empty list item
|
|
110
|
+
_slate.Transforms.removeNodes(editor, {
|
|
111
|
+
at: leftoverListItem[1]
|
|
112
|
+
});
|
|
113
|
+
}
|
|
53
114
|
});
|
|
54
|
-
const focusPoint = _slate.Editor.start(newEditor, listItemPath);
|
|
55
|
-
(0, _core.focusEditor)(newEditor, focusPoint);
|
|
56
|
-
return;
|
|
57
115
|
}
|
|
58
116
|
}
|
|
59
|
-
|
|
117
|
+
return moved;
|
|
118
|
+
};
|
|
119
|
+
if (deleteBackwardList()) return;
|
|
120
|
+
|
|
60
121
|
// nothing todo
|
|
61
122
|
deleteBackward(unit);
|
|
62
123
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAcrossListItems = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _constants = require("../../../constants");
|
|
10
|
+
const isAcrossListItems = editor => {
|
|
11
|
+
const {
|
|
12
|
+
selection
|
|
13
|
+
} = editor;
|
|
14
|
+
if (!selection || _slate.Range.isCollapsed(selection)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const isAcrossBlocks = (0, _core.isRangeAcrossBlocks)(editor);
|
|
18
|
+
if (!isAcrossBlocks) return false;
|
|
19
|
+
return (0, _core.someNode)(editor, {
|
|
20
|
+
match: {
|
|
21
|
+
type: _constants.LIST_ITEM
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.isAcrossListItems = isAcrossListItems;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveListItemSublistItemsToListItemSublist = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _constants = require("../../../constants");
|
|
10
|
+
var _model = require("../model");
|
|
11
|
+
const moveListItemSublistItemsToListItemSublist = (editor, _ref) => {
|
|
12
|
+
let {
|
|
13
|
+
fromListItem,
|
|
14
|
+
start,
|
|
15
|
+
toListItem
|
|
16
|
+
} = _ref;
|
|
17
|
+
const [, fromListItemPath] = fromListItem;
|
|
18
|
+
const [, toListItemPath] = toListItem;
|
|
19
|
+
let moved = 0;
|
|
20
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
21
|
+
const fromListItemSublist = (0, _core.findDescendant)(editor, {
|
|
22
|
+
at: fromListItemPath,
|
|
23
|
+
match: {
|
|
24
|
+
type: _constants.LIST_TYPE_ARRAY
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (!fromListItemSublist) return;
|
|
28
|
+
const [, fromListItemSublistPath] = fromListItemSublist;
|
|
29
|
+
const toListItemSublist = (0, _core.findDescendant)(editor, {
|
|
30
|
+
at: toListItemPath,
|
|
31
|
+
match: {
|
|
32
|
+
type: _constants.LIST_TYPE_ARRAY
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
let to = null;
|
|
36
|
+
if (!toListItemSublist) {
|
|
37
|
+
const fromList = _slate.Editor.parent(editor, fromListItemPath);
|
|
38
|
+
if (!fromList) return;
|
|
39
|
+
const [fromListNode] = fromList;
|
|
40
|
+
const fromListType = fromListNode.type;
|
|
41
|
+
const toListItemSublistPath = toListItemPath.concat([1]);
|
|
42
|
+
const list = (0, _model.generateEmptyList)(fromListType);
|
|
43
|
+
_slate.Transforms.insertNodes(editor, list, {
|
|
44
|
+
at: toListItemSublistPath
|
|
45
|
+
});
|
|
46
|
+
to = toListItemSublistPath.concat([0]);
|
|
47
|
+
} else if (start) {
|
|
48
|
+
const [, toListItemSublistPath] = toListItemSublist;
|
|
49
|
+
to = toListItemSublistPath.concat([0]);
|
|
50
|
+
} else {
|
|
51
|
+
to = _slate.Path.next((0, _core.getLastChildPath)(toListItemSublist));
|
|
52
|
+
}
|
|
53
|
+
moved = (0, _core.moveChildren)(editor, {
|
|
54
|
+
at: fromListItemSublistPath,
|
|
55
|
+
to
|
|
56
|
+
});
|
|
57
|
+
_slate.Transforms.delete(editor, {
|
|
58
|
+
at: fromListItemSublistPath
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return moved;
|
|
62
|
+
};
|
|
63
|
+
exports.moveListItemSublistItemsToListItemSublist = moveListItemSublistItemsToListItemSublist;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeListItem = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _queries = require("../queries");
|
|
9
|
+
var _core = require("../../../core");
|
|
10
|
+
var _model = require("../model");
|
|
11
|
+
var _moveListItemSublistToListItemSublist = require("./move-list-item-sublist-to-list-item-sublist");
|
|
12
|
+
var _deleteMerge = require("../../../core/transforms/delete-merge");
|
|
13
|
+
var _moveListItemsToList = require("./move-list-items-to-list");
|
|
14
|
+
const removeListItem = (editor, _ref) => {
|
|
15
|
+
let {
|
|
16
|
+
list,
|
|
17
|
+
listItem,
|
|
18
|
+
reverse = true
|
|
19
|
+
} = _ref;
|
|
20
|
+
const [liNode, liPath] = listItem;
|
|
21
|
+
if (_slate.Range.isExpanded(editor.selection) || !(0, _queries.hasListChild)(liNode)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const previousLiPath = (0, _core.getPreviousPath)(liPath);
|
|
25
|
+
let success = false;
|
|
26
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
27
|
+
if (previousLiPath) {
|
|
28
|
+
const previousLi = _slate.Editor.node(editor, previousLiPath);
|
|
29
|
+
if (!previousLi) return;
|
|
30
|
+
let tempLiPath = _slate.Path.next(liPath);
|
|
31
|
+
let tempLiNode = (0, _model.generateListItem)();
|
|
32
|
+
_slate.Transforms.insertNodes(editor, tempLiNode, {
|
|
33
|
+
at: tempLiPath
|
|
34
|
+
});
|
|
35
|
+
const tempLi = _slate.Editor.node(editor, tempLiPath);
|
|
36
|
+
if (!tempLi) return;
|
|
37
|
+
const tempLiPathRef = _slate.Editor.pathRef(editor, tempLi[1]);
|
|
38
|
+
(0, _moveListItemSublistToListItemSublist.moveListItemSublistItemsToListItemSublist)(editor, {
|
|
39
|
+
fromListItem: listItem,
|
|
40
|
+
toListItem: tempLi
|
|
41
|
+
});
|
|
42
|
+
(0, _deleteMerge.deleteMerge)(editor, {
|
|
43
|
+
reverse
|
|
44
|
+
});
|
|
45
|
+
tempLiPath = tempLiPathRef.unref();
|
|
46
|
+
(0, _moveListItemSublistToListItemSublist.moveListItemSublistItemsToListItemSublist)(editor, {
|
|
47
|
+
fromListItem: [tempLi[0], tempLiPath],
|
|
48
|
+
toListItem: previousLi
|
|
49
|
+
});
|
|
50
|
+
_slate.Transforms.removeNodes(editor, {
|
|
51
|
+
at: tempLiPath
|
|
52
|
+
});
|
|
53
|
+
success = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
(0, _moveListItemsToList.moveListItemsToList)(editor, {
|
|
57
|
+
fromListItem: listItem,
|
|
58
|
+
toList: list,
|
|
59
|
+
toListIndex: 1
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return success;
|
|
63
|
+
};
|
|
64
|
+
exports.removeListItem = removeListItem;
|
|
@@ -5,12 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.setSeaTableColumn = exports.isMenuDisabled = exports.insertSeaTableColumn = exports.getColumnWidth = exports.getColumnType = exports.getColumnByKey = void 0;
|
|
8
|
+
exports.setSeaTableColumn = exports.isMenuDisabled = exports.insertSeaTableColumn = exports.getDigitalSignImgUrl = exports.getColumnWidth = exports.getColumnType = exports.getColumnByKey = void 0;
|
|
9
9
|
var _slate = require("@seafile/slate");
|
|
10
10
|
var _slugid = _interopRequireDefault(require("slugid"));
|
|
11
|
+
var _context = _interopRequireDefault(require("../../../../context"));
|
|
11
12
|
var _elementType = require("../../constants/element-type");
|
|
12
13
|
var _constants = require("../../constants");
|
|
13
14
|
var _core = require("../../core");
|
|
15
|
+
var _helpers = require("../image/helpers");
|
|
14
16
|
var _model = _interopRequireDefault(require("./model"));
|
|
15
17
|
var CellType = _interopRequireWildcard(require("./constants/cell-types"));
|
|
16
18
|
const isMenuDisabled = (editor, readonly) => {
|
|
@@ -56,15 +58,45 @@ const getColumnType = editor => {
|
|
|
56
58
|
return (0, _core.getNodeType)(n);
|
|
57
59
|
};
|
|
58
60
|
exports.getColumnType = getColumnType;
|
|
61
|
+
const getDigitalSignImgUrl = partUrl => {
|
|
62
|
+
const server = _context.default.getSetting('serviceUrl');
|
|
63
|
+
const workspaceID = _context.default.getSetting('workspaceID');
|
|
64
|
+
const dtableUuid = _context.default.getSetting('dtableUuid');
|
|
65
|
+
if (!partUrl || typeof partUrl !== 'string') return '';
|
|
66
|
+
return `${server}/workspace/${workspaceID}/asset/${dtableUuid}${partUrl}`;
|
|
67
|
+
};
|
|
68
|
+
exports.getDigitalSignImgUrl = getDigitalSignImgUrl;
|
|
69
|
+
const getColumnByKey = (columns, key) => {
|
|
70
|
+
const column = columns.find(item => item.key === key);
|
|
71
|
+
return column || null;
|
|
72
|
+
};
|
|
73
|
+
exports.getColumnByKey = getColumnByKey;
|
|
59
74
|
const insertSeaTableColumn = function (editor, active, option) {
|
|
60
75
|
let insertPosition = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _constants.INSERT_POSITION.CURRENT;
|
|
61
76
|
if (!active) {
|
|
62
|
-
const
|
|
63
|
-
|
|
77
|
+
const {
|
|
78
|
+
value
|
|
79
|
+
} = option;
|
|
80
|
+
const column = getColumnByKey(editor.columns || [], value);
|
|
81
|
+
const {
|
|
82
|
+
type,
|
|
83
|
+
key
|
|
84
|
+
} = column || {};
|
|
85
|
+
let columnNode = {};
|
|
86
|
+
if (type === CellType.IMAGE) {
|
|
87
|
+
columnNode = (0, _helpers.generateImageNode)('');
|
|
88
|
+
columnNode['data']['column_key'] = key;
|
|
89
|
+
} else if (type === CellType.DIGITAL_SIGN) {
|
|
90
|
+
columnNode = (0, _helpers.generateImageNode)('');
|
|
91
|
+
columnNode['data']['column_key'] = key;
|
|
92
|
+
} else {
|
|
93
|
+
columnNode = new _model.default(option);
|
|
94
|
+
columnNode.id = _slugid.default.nice();
|
|
95
|
+
}
|
|
64
96
|
if (insertPosition === _constants.INSERT_POSITION.AFTER) {
|
|
65
97
|
const path = _slate.Editor.path(editor, editor.selection);
|
|
66
98
|
path && _slate.Transforms.insertNodes(editor, {
|
|
67
|
-
...
|
|
99
|
+
...columnNode
|
|
68
100
|
}, {
|
|
69
101
|
at: [path[0] + 1]
|
|
70
102
|
});
|
|
@@ -72,7 +104,7 @@ const insertSeaTableColumn = function (editor, active, option) {
|
|
|
72
104
|
return;
|
|
73
105
|
}
|
|
74
106
|
_slate.Transforms.insertNodes(editor, {
|
|
75
|
-
...
|
|
107
|
+
...columnNode
|
|
76
108
|
});
|
|
77
109
|
}
|
|
78
110
|
(0, _core.focusEditor)(editor);
|
|
@@ -87,11 +119,6 @@ const setSeaTableColumn = (editor, data) => {
|
|
|
87
119
|
});
|
|
88
120
|
};
|
|
89
121
|
exports.setSeaTableColumn = setSeaTableColumn;
|
|
90
|
-
const getColumnByKey = (columns, key) => {
|
|
91
|
-
const column = columns.find(item => item.key === key);
|
|
92
|
-
return column || null;
|
|
93
|
-
};
|
|
94
|
-
exports.getColumnByKey = getColumnByKey;
|
|
95
122
|
const getColumnWidth = column => {
|
|
96
123
|
let {
|
|
97
124
|
type,
|
|
@@ -16,7 +16,7 @@ const isValidCellValue = value => {
|
|
|
16
16
|
return true;
|
|
17
17
|
};
|
|
18
18
|
exports.isValidCellValue = isValidCellValue;
|
|
19
|
-
const getCellDisplayValue = (record, column, collaborators) => {
|
|
19
|
+
const getCellDisplayValue = (record, column, collaborators, formulaRows) => {
|
|
20
20
|
const {
|
|
21
21
|
type,
|
|
22
22
|
data,
|
|
@@ -25,6 +25,7 @@ const getCellDisplayValue = (record, column, collaborators) => {
|
|
|
25
25
|
return (0, _dtableUtils.getCellValueDisplayString)(record, type, key, {
|
|
26
26
|
data,
|
|
27
27
|
collaborators,
|
|
28
|
+
formulaRows,
|
|
28
29
|
geolocationHyphen: ' '
|
|
29
30
|
});
|
|
30
31
|
};
|
package/dist/constants/index.js
CHANGED
|
@@ -39,7 +39,8 @@ const EXTERNAL_EVENT = exports.EXTERNAL_EVENT = {
|
|
|
39
39
|
// wiki
|
|
40
40
|
INSERT_LINK: 'insert_link',
|
|
41
41
|
// document
|
|
42
|
-
COLLABORATORS_UPDATED: 'collaborators_updated'
|
|
42
|
+
COLLABORATORS_UPDATED: 'collaborators_updated',
|
|
43
|
+
IMAGE_COLUMN_TOGGLE: 'Image_column_toggle'
|
|
43
44
|
};
|
|
44
45
|
const TIP_TYPE = exports.TIP_TYPE = {
|
|
45
46
|
DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
|
|
@@ -32,6 +32,7 @@ const DocumentPluginEditor = _ref => {
|
|
|
32
32
|
tables,
|
|
33
33
|
getTableById,
|
|
34
34
|
collaborators,
|
|
35
|
+
formulaRows,
|
|
35
36
|
getTableFormulaResults,
|
|
36
37
|
getArticleStyle
|
|
37
38
|
} = _ref;
|
|
@@ -63,6 +64,7 @@ const DocumentPluginEditor = _ref => {
|
|
|
63
64
|
newEditor.tables = tables || [];
|
|
64
65
|
newEditor.getTableById = getTableById;
|
|
65
66
|
newEditor.collaborators = collaborators;
|
|
67
|
+
newEditor.formulaRows = formulaRows;
|
|
66
68
|
newEditor.getTableFormulaResults = getTableFormulaResults;
|
|
67
69
|
newEditor.cursors = cursors || {};
|
|
68
70
|
newEditor.width = _constants.PAGE_EDIT_AREA_WIDTH; // default width
|