@seafile/sdoc-editor 3.0.257 → 3.0.258
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/extension/plugins/table/popover/table-size-popover/index.css +2 -1
- package/dist/extension/plugins/table/popover/table-size-popover/index.js +30 -13
- package/dist/extension/plugins/table/popover/table-template/index.js +14 -1
- package/dist/extension/toolbar/quick-insert-toolbar/index.js +117 -15
- package/dist/extension/toolbar/quick-insert-toolbar/style.css +14 -2
- package/dist/extension/utils/index.js +15 -20
- package/dist/node-id/index.js +94 -15
- package/package.json +2 -2
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
min-height: 32px;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom:hover
|
|
15
|
+
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom:hover,
|
|
16
|
+
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom.keyboard-selected {
|
|
16
17
|
cursor: pointer;
|
|
17
18
|
background: #f5f5f5;
|
|
18
19
|
border-radius: 4px;
|
|
@@ -38,6 +38,10 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
38
38
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
39
39
|
selectedSize = _useState4[0],
|
|
40
40
|
setSelectedSize = _useState4[1];
|
|
41
|
+
var _useState5 = (0, _react.useState)(false),
|
|
42
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
43
|
+
isTemplateSelected = _useState6[0],
|
|
44
|
+
setIsTemplateSelected = _useState6[1];
|
|
41
45
|
var ref = (0, _react.useRef)(null);
|
|
42
46
|
var templateRef = (0, _react.useRef)(null);
|
|
43
47
|
(0, _react.useEffect)(function () {
|
|
@@ -68,9 +72,12 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
68
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
73
|
}, [selectedSize, ref]);
|
|
70
74
|
var onTemplateItemSelectedStyle = (0, _react.useCallback)(function (color) {
|
|
71
|
-
|
|
72
|
-
templateEl.style['backgroundColor'] = color;
|
|
75
|
+
setIsTemplateSelected(Boolean(color));
|
|
73
76
|
}, []);
|
|
77
|
+
var selectFirstMenuItem = (0, _react.useCallback)(function () {
|
|
78
|
+
ref.current['firstRender'] = false;
|
|
79
|
+
onTemplateItemSelectedStyle('#f5f5f5');
|
|
80
|
+
}, [onTemplateItemSelectedStyle]);
|
|
74
81
|
var handleSizeDown = (0, _react.useCallback)(function (e) {
|
|
75
82
|
var keyCode = e.keyCode;
|
|
76
83
|
var UpArrow = _constants.KeyCodes.UpArrow,
|
|
@@ -118,9 +125,8 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
118
125
|
LeftArrow = _constants.KeyCodes.LeftArrow,
|
|
119
126
|
Esc = _constants.KeyCodes.Esc;
|
|
120
127
|
var isInitSize = selectedSize[0] === 1 && selectedSize[1] === 1;
|
|
121
|
-
var templateEl = document.getElementById('sdoc-table-template-review-btn');
|
|
122
128
|
// Currently focusing on the template menu item
|
|
123
|
-
if (
|
|
129
|
+
if (isTemplateSelected) {
|
|
124
130
|
if (keyCode === DownArrow) {
|
|
125
131
|
e.preventDefault();
|
|
126
132
|
onTemplateItemSelectedStyle('');
|
|
@@ -134,8 +140,11 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
134
140
|
}
|
|
135
141
|
if (keyCode === Enter) {
|
|
136
142
|
e.preventDefault();
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
templateRef.current.openWithKeyboard();
|
|
144
|
+
}
|
|
145
|
+
if (keyCode === RightArrow) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
templateRef.current.openWithKeyboard();
|
|
139
148
|
}
|
|
140
149
|
if (keyCode === Esc) {
|
|
141
150
|
e.preventDefault();
|
|
@@ -153,7 +162,7 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
153
162
|
e.preventDefault();
|
|
154
163
|
if (ref.current['firstRender']) {
|
|
155
164
|
ref.current['firstRender'] = false;
|
|
156
|
-
onTemplateItemSelectedStyle('#
|
|
165
|
+
onTemplateItemSelectedStyle('#f5f5f5');
|
|
157
166
|
return;
|
|
158
167
|
}
|
|
159
168
|
handleSizeDown(e);
|
|
@@ -163,7 +172,7 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
163
172
|
if (keyCode === UpArrow) {
|
|
164
173
|
e.preventDefault();
|
|
165
174
|
if (isInitSize) {
|
|
166
|
-
onTemplateItemSelectedStyle('#
|
|
175
|
+
onTemplateItemSelectedStyle('#f5f5f5');
|
|
167
176
|
} else {
|
|
168
177
|
handleSizeDown(e);
|
|
169
178
|
}
|
|
@@ -183,10 +192,15 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
183
192
|
e.preventDefault();
|
|
184
193
|
handleClosePopover();
|
|
185
194
|
}
|
|
186
|
-
}, [handleClosePopover, handleSizeDown, onTemplateItemSelectedStyle, selectedSize]);
|
|
195
|
+
}, [handleClosePopover, handleSizeDown, isTemplateSelected, onTemplateItemSelectedStyle, selectedSize]);
|
|
196
|
+
var onPopoverClosed = (0, _react.useCallback)(function () {
|
|
197
|
+
setIsTemplateSelected(false);
|
|
198
|
+
ref.current['firstRender'] = true;
|
|
199
|
+
}, []);
|
|
187
200
|
(0, _react.useImperativeHandle)(tableSizeRef, function () {
|
|
188
201
|
return {
|
|
189
202
|
handleTableSizeKeyDown: handleTableSizeKeyDown,
|
|
203
|
+
selectFirstMenuItem: selectFirstMenuItem,
|
|
190
204
|
uncontrolledPopoverRef: ref
|
|
191
205
|
};
|
|
192
206
|
});
|
|
@@ -230,6 +244,7 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
230
244
|
placement: placement,
|
|
231
245
|
hideArrow: true,
|
|
232
246
|
fade: false,
|
|
247
|
+
onClosed: onPopoverClosed,
|
|
233
248
|
ref: ref,
|
|
234
249
|
popperClassName: "".concat(popperClassName, " sdoc-popover-box-shadow"),
|
|
235
250
|
offset: offset
|
|
@@ -240,7 +255,8 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
240
255
|
}, /*#__PURE__*/_react["default"].createElement(MenuItem, {
|
|
241
256
|
id: "sdoc-table-template-review-btn",
|
|
242
257
|
text: "Table_template",
|
|
243
|
-
iconClassname: "sdocfont sdoc-arrow-right sdoc-dropdown-item-right-icon"
|
|
258
|
+
iconClassname: "sdocfont sdoc-arrow-right sdoc-dropdown-item-right-icon",
|
|
259
|
+
isSelected: isTemplateSelected
|
|
244
260
|
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
245
261
|
className: "sdoc-table-size-select"
|
|
246
262
|
}, renderTableSize()), /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -258,13 +274,14 @@ var MenuItem = function MenuItem(_ref2) {
|
|
|
258
274
|
var id = _ref2.id,
|
|
259
275
|
className = _ref2.className,
|
|
260
276
|
text = _ref2.text,
|
|
261
|
-
iconClassname = _ref2.iconClassname
|
|
277
|
+
iconClassname = _ref2.iconClassname,
|
|
278
|
+
isSelected = _ref2.isSelected;
|
|
262
279
|
var _useTranslation = (0, _reactI18next.useTranslation)('sdoc-editor'),
|
|
263
280
|
t = _useTranslation.t;
|
|
264
281
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
265
282
|
id: id,
|
|
266
|
-
className: (0, _classnames["default"])('sdoc-selected-table-size-custom', {
|
|
267
|
-
|
|
283
|
+
className: (0, _classnames["default"])('sdoc-selected-table-size-custom', className, {
|
|
284
|
+
'keyboard-selected': isSelected
|
|
268
285
|
})
|
|
269
286
|
}, /*#__PURE__*/_react["default"].createElement("span", null, t(text)), /*#__PURE__*/_react["default"].createElement("i", {
|
|
270
287
|
className: iconClassname
|
|
@@ -51,7 +51,13 @@ var TableTemplate = function TableTemplate(_ref) {
|
|
|
51
51
|
var newPosition = [position[0] - 1, position[1]];
|
|
52
52
|
ref.current.position = newPosition;
|
|
53
53
|
setPosition(newPosition);
|
|
54
|
+
} else {
|
|
55
|
+
var initialPosition = [-1, -1];
|
|
56
|
+
ref.current.position = initialPosition;
|
|
57
|
+
setPosition(initialPosition);
|
|
58
|
+
ref.current.toggle();
|
|
54
59
|
}
|
|
60
|
+
return;
|
|
55
61
|
}
|
|
56
62
|
if (keyCode === RightArrow) {
|
|
57
63
|
e.preventDefault();
|
|
@@ -101,12 +107,19 @@ var TableTemplate = function TableTemplate(_ref) {
|
|
|
101
107
|
handleClosePopover();
|
|
102
108
|
}
|
|
103
109
|
}, [handleClickTemplate, handleClosePopover]);
|
|
110
|
+
var openWithKeyboard = (0, _react.useCallback)(function () {
|
|
111
|
+
var firstPosition = [0, 0];
|
|
112
|
+
ref.current.position = firstPosition;
|
|
113
|
+
setPosition(firstPosition);
|
|
114
|
+
ref.current.toggle();
|
|
115
|
+
}, []);
|
|
104
116
|
(0, _react.useImperativeHandle)(templateRef, function () {
|
|
105
117
|
return {
|
|
106
118
|
handleTableTemplateKeyDown: handleTableTemplateKeyDown,
|
|
119
|
+
openWithKeyboard: openWithKeyboard,
|
|
107
120
|
uncontrolledTemplatePopoverRef: ref
|
|
108
121
|
};
|
|
109
|
-
});
|
|
122
|
+
}, [handleTableTemplateKeyDown, openWithKeyboard]);
|
|
110
123
|
(0, _react.useEffect)(function () {
|
|
111
124
|
ref.current.position = [-1, -1];
|
|
112
125
|
}, []);
|
|
@@ -45,6 +45,10 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
45
45
|
handleClosePopover = _ref.handleClosePopover;
|
|
46
46
|
var editor = (0, _slateReact.useSlateStatic)();
|
|
47
47
|
var tableSizeRef = (0, _react.useRef)(null);
|
|
48
|
+
var videoMenuRef = (0, _react.useRef)(null);
|
|
49
|
+
var videoMenuKeyboardNavigationRef = (0, _react.useRef)(false);
|
|
50
|
+
var videoMenuSelectIndexRef = (0, _react.useRef)(-1);
|
|
51
|
+
var preserveSearchInputFocusRef = (0, _react.useRef)(false);
|
|
48
52
|
var inputWrapperRef = (0, _react.useRef)(null);
|
|
49
53
|
var downDownWrapperRef = (0, _react.useRef)(null);
|
|
50
54
|
var _useTranslation = (0, _reactI18next.useTranslation)('sdoc-editor'),
|
|
@@ -304,9 +308,18 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
304
308
|
}, /*#__PURE__*/_react["default"].createElement("i", {
|
|
305
309
|
className: "sdocfont sdoc-arrow-right sdoc-dropdown-item-right-icon"
|
|
306
310
|
}), /*#__PURE__*/_react["default"].createElement(_reactstrap.UncontrolledPopover, {
|
|
311
|
+
ref: videoMenuRef,
|
|
307
312
|
target: "sdoc-side-menu-item-video",
|
|
308
313
|
trigger: "hover",
|
|
309
|
-
className: "sdoc-dropdown-menu sdoc-sub-dropdown-menu sdoc-insert-video-menu-popover",
|
|
314
|
+
className: "sdoc-dropdown-menu sdoc-sub-dropdown-menu sdoc-insert-video-menu-popover sdoc-quick-insert-video-menu-popover",
|
|
315
|
+
onEntered: function onEntered() {
|
|
316
|
+
if (!videoMenuKeyboardNavigationRef.current) return;
|
|
317
|
+
var videoMenuItems = document.querySelectorAll('.sdoc-quick-insert-video-menu-popover .popover.show .sdoc-dropdown-menu-item');
|
|
318
|
+
videoMenuItems.forEach(function (item) {
|
|
319
|
+
return item.classList.remove(_const.SELECTED_ITEM_CLASS_NAME);
|
|
320
|
+
});
|
|
321
|
+
if (videoMenuItems.length > 0) videoMenuItems[0].classList.add(_const.SELECTED_ITEM_CLASS_NAME);
|
|
322
|
+
},
|
|
310
323
|
popperClassName: "sdoc-popover-box-shadow",
|
|
311
324
|
placement: "right-start",
|
|
312
325
|
hideArrow: true,
|
|
@@ -429,7 +442,7 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
429
442
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
430
443
|
}, [quickInsertMenuSearchMap, isDisableImage, onInsertImageToggle, isDisableVideo, isDisableMultiColumn, onInsertVideoToggle, isDisableTable, editor, createTable, callback, handleClosePopover, openLinkDialog, addEmbedLinkDialog, onInsertCodeBlock, isDisableCallout, onInsertCheckList, isEmptyNode, onInsertCallout, onInsertList, onInsert, createMultiColumn, isDisableHeader]);
|
|
431
444
|
var getSelectItemDom = function getSelectItemDom(selectIndex) {
|
|
432
|
-
var dropDownItemWrapper = downDownWrapperRef.current;
|
|
445
|
+
var dropDownItemWrapper = downDownWrapperRef.current.querySelector('.sdoc-side-menu-inner-container');
|
|
433
446
|
var searchedDropDownItemWrapper = [];
|
|
434
447
|
Array.from(dropDownItemWrapper.children).forEach(function (item) {
|
|
435
448
|
if (!Array.from(item.classList).includes('sdoc-dropdown-menu-item-hidden')) {
|
|
@@ -439,15 +452,70 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
439
452
|
var currentSelectItem = searchedDropDownItemWrapper[selectIndex];
|
|
440
453
|
return currentSelectItem;
|
|
441
454
|
};
|
|
442
|
-
var
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
455
|
+
var getVideoMenuItems = (0, _react.useCallback)(function () {
|
|
456
|
+
var videoMenu = document.querySelector('.sdoc-quick-insert-video-menu-popover .popover.show .sdoc-insert-video-menu-popover-container');
|
|
457
|
+
return videoMenu ? Array.from(videoMenu.querySelectorAll('.sdoc-dropdown-menu-item')) : [];
|
|
458
|
+
}, []);
|
|
459
|
+
var setVideoMenuSelection = (0, _react.useCallback)(function (index) {
|
|
460
|
+
var videoMenuItems = getVideoMenuItems();
|
|
461
|
+
videoMenuItems.forEach(function (item) {
|
|
462
|
+
return item.classList.remove(_const.SELECTED_ITEM_CLASS_NAME);
|
|
463
|
+
});
|
|
464
|
+
if (index >= 0 && index < videoMenuItems.length) {
|
|
465
|
+
videoMenuSelectIndexRef.current = index;
|
|
466
|
+
videoMenuItems[index].classList.add(_const.SELECTED_ITEM_CLASS_NAME);
|
|
446
467
|
}
|
|
468
|
+
}, [getVideoMenuItems]);
|
|
469
|
+
var handleKeyDown = (0, _react.useCallback)(function (e) {
|
|
447
470
|
var UpArrow = _constants.KeyCodes.UpArrow,
|
|
448
471
|
DownArrow = _constants.KeyCodes.DownArrow,
|
|
472
|
+
LeftArrow = _constants.KeyCodes.LeftArrow,
|
|
473
|
+
RightArrow = _constants.KeyCodes.RightArrow,
|
|
449
474
|
Enter = _constants.KeyCodes.Enter,
|
|
450
475
|
Esc = _constants.KeyCodes.Esc;
|
|
476
|
+
var tableSizePopover = document.querySelector('.sdoc-selected-table-size-popover.show');
|
|
477
|
+
if (tableSizePopover) {
|
|
478
|
+
tableSizeRef.current.handleTableSizeKeyDown(e);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
var videoMenuPopover = document.querySelector('.sdoc-quick-insert-video-menu-popover .popover.show');
|
|
482
|
+
if (!videoMenuPopover) {
|
|
483
|
+
videoMenuKeyboardNavigationRef.current = false;
|
|
484
|
+
videoMenuSelectIndexRef.current = -1;
|
|
485
|
+
}
|
|
486
|
+
if (videoMenuPopover && videoMenuKeyboardNavigationRef.current) {
|
|
487
|
+
var videoMenuItems = getVideoMenuItems();
|
|
488
|
+
if (e.keyCode === UpArrow || e.keyCode === DownArrow) {
|
|
489
|
+
e.preventDefault();
|
|
490
|
+
if (videoMenuItems.length === 0) return;
|
|
491
|
+
var direction = e.keyCode === DownArrow ? 1 : -1;
|
|
492
|
+
var nextIndex = (videoMenuSelectIndexRef.current + direction + videoMenuItems.length) % videoMenuItems.length;
|
|
493
|
+
setVideoMenuSelection(nextIndex);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (e.keyCode === Enter) {
|
|
497
|
+
var _videoMenuItems$video;
|
|
498
|
+
e.preventDefault();
|
|
499
|
+
(_videoMenuItems$video = videoMenuItems[videoMenuSelectIndexRef.current]) === null || _videoMenuItems$video === void 0 ? void 0 : _videoMenuItems$video.click();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (e.keyCode === LeftArrow) {
|
|
503
|
+
e.preventDefault();
|
|
504
|
+
videoMenuKeyboardNavigationRef.current = false;
|
|
505
|
+
videoMenuSelectIndexRef.current = -1;
|
|
506
|
+
setVideoMenuSelection(-1);
|
|
507
|
+
videoMenuRef.current.toggle();
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (e.keyCode === LeftArrow && videoMenuPopover) {
|
|
512
|
+
e.preventDefault();
|
|
513
|
+
videoMenuKeyboardNavigationRef.current = false;
|
|
514
|
+
videoMenuSelectIndexRef.current = -1;
|
|
515
|
+
setVideoMenuSelection(-1);
|
|
516
|
+
videoMenuRef.current.toggle();
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
451
519
|
var renderItems = [];
|
|
452
520
|
Reflect.ownKeys(dropDownItems).forEach(function (key) {
|
|
453
521
|
if (quickInsertMenuSearchMap[key]) renderItems.push(key);
|
|
@@ -458,26 +526,55 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
458
526
|
var currentSelectItem = getSelectItemDom(currentSelectIndex);
|
|
459
527
|
if (currentSelectItem) currentSelectItem.classList.remove(_const.SELECTED_ITEM_CLASS_NAME);
|
|
460
528
|
if (currentSelectIndex > -1) {
|
|
461
|
-
setCurrentSelectIndex(currentSelectIndex - 1);
|
|
529
|
+
setCurrentSelectIndex(currentSelectIndex === 0 ? renderItems.length - 1 : currentSelectIndex - 1);
|
|
462
530
|
}
|
|
463
531
|
}
|
|
464
532
|
if (keyCode === DownArrow) {
|
|
465
533
|
e.preventDefault();
|
|
466
|
-
if (
|
|
534
|
+
if (renderItems.length === 0) return;
|
|
467
535
|
var _currentSelectItem = getSelectItemDom(currentSelectIndex);
|
|
468
536
|
if (_currentSelectItem) _currentSelectItem.classList.remove(_const.SELECTED_ITEM_CLASS_NAME);
|
|
469
|
-
|
|
470
|
-
|
|
537
|
+
setCurrentSelectIndex(currentSelectIndex === renderItems.length - 1 ? 0 : currentSelectIndex + 1);
|
|
538
|
+
}
|
|
539
|
+
if (keyCode === RightArrow && currentSelectIndex > -1) {
|
|
540
|
+
var _dropDownItems$select, _tableSizeRef$current, _tableSizeRef$current2;
|
|
541
|
+
var selectedItem = renderItems[currentSelectIndex];
|
|
542
|
+
if ((_dropDownItems$select = dropDownItems[selectedItem]) !== null && _dropDownItems$select !== void 0 && _dropDownItems$select.props.disabled) return;
|
|
543
|
+
if (selectedItem === _constants2.TABLE && (_tableSizeRef$current = tableSizeRef.current) !== null && _tableSizeRef$current !== void 0 && (_tableSizeRef$current2 = _tableSizeRef$current.uncontrolledPopoverRef) !== null && _tableSizeRef$current2 !== void 0 && _tableSizeRef$current2.current) {
|
|
544
|
+
e.preventDefault();
|
|
545
|
+
tableSizeRef.current.selectFirstMenuItem();
|
|
546
|
+
tableSizeRef.current.uncontrolledPopoverRef.current.toggle();
|
|
547
|
+
}
|
|
548
|
+
if (selectedItem === _constants2.VIDEO && videoMenuRef.current) {
|
|
549
|
+
e.preventDefault();
|
|
550
|
+
videoMenuKeyboardNavigationRef.current = true;
|
|
551
|
+
videoMenuSelectIndexRef.current = 0;
|
|
552
|
+
if (!videoMenuPopover) videoMenuRef.current.toggle();
|
|
553
|
+
requestAnimationFrame(function () {
|
|
554
|
+
return setVideoMenuSelection(0);
|
|
555
|
+
});
|
|
471
556
|
}
|
|
472
557
|
}
|
|
473
558
|
if (keyCode === Enter) {
|
|
559
|
+
var _dropDownItems$item;
|
|
474
560
|
e.preventDefault();
|
|
475
561
|
if (currentSelectIndex === -1) return;
|
|
476
562
|
var item = renderItems[currentSelectIndex];
|
|
563
|
+
if ((_dropDownItems$item = dropDownItems[item]) !== null && _dropDownItems$item !== void 0 && _dropDownItems$item.props.disabled) return;
|
|
477
564
|
if (item === _constants2.TABLE) {
|
|
565
|
+
tableSizeRef.current.selectFirstMenuItem();
|
|
478
566
|
tableSizeRef.current.uncontrolledPopoverRef.current.toggle();
|
|
479
567
|
return;
|
|
480
568
|
}
|
|
569
|
+
if (item === _constants2.VIDEO && videoMenuRef.current) {
|
|
570
|
+
videoMenuKeyboardNavigationRef.current = true;
|
|
571
|
+
videoMenuSelectIndexRef.current = 0;
|
|
572
|
+
if (!videoMenuPopover) videoMenuRef.current.toggle();
|
|
573
|
+
requestAnimationFrame(function () {
|
|
574
|
+
return setVideoMenuSelection(0);
|
|
575
|
+
});
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
481
578
|
if (dropDownItems[item]) {
|
|
482
579
|
var _dropDownItems$item$p = dropDownItems[item].props,
|
|
483
580
|
disabled = _dropDownItems$item$p.disabled,
|
|
@@ -489,7 +586,7 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
489
586
|
e.preventDefault();
|
|
490
587
|
handleClosePopover();
|
|
491
588
|
}
|
|
492
|
-
}, [currentSelectIndex, dropDownItems, handleClosePopover, quickInsertMenuSearchMap]);
|
|
589
|
+
}, [currentSelectIndex, dropDownItems, getVideoMenuItems, handleClosePopover, quickInsertMenuSearchMap, setVideoMenuSelection]);
|
|
493
590
|
(0, _react.useEffect)(function () {
|
|
494
591
|
document.addEventListener('keydown', handleKeyDown);
|
|
495
592
|
return function () {
|
|
@@ -498,7 +595,8 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
498
595
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
499
596
|
}, [handleKeyDown]);
|
|
500
597
|
var clearSelectStyle = (0, _react.useCallback)(function () {
|
|
501
|
-
var
|
|
598
|
+
var dropDownItemWrapper = downDownWrapperRef.current.querySelector('.sdoc-side-menu-inner-container');
|
|
599
|
+
var domList = Array.from(dropDownItemWrapper.children);
|
|
502
600
|
domList.forEach(function (dom) {
|
|
503
601
|
return dom.classList.remove(_const.SELECTED_ITEM_CLASS_NAME);
|
|
504
602
|
});
|
|
@@ -514,19 +612,23 @@ var QuickInsertBlockMenu = function QuickInsertBlockMenu(_ref) {
|
|
|
514
612
|
if (currentSelectIndex === -1) {
|
|
515
613
|
onHandleInputFocus(true);
|
|
516
614
|
} else {
|
|
517
|
-
onHandleInputFocus(false);
|
|
615
|
+
if (!preserveSearchInputFocusRef.current) onHandleInputFocus(false);
|
|
616
|
+
preserveSearchInputFocusRef.current = false;
|
|
518
617
|
clearSelectStyle();
|
|
519
618
|
var currentSelectItem = getSelectItemDom(currentSelectIndex);
|
|
520
619
|
if (currentSelectItem) {
|
|
521
|
-
(0, _utils.onHandleOverflowScroll)(currentSelectItem, downDownWrapperRef);
|
|
620
|
+
(0, _utils.onHandleOverflowScroll)(currentSelectItem, downDownWrapperRef, !getSelectItemDom(currentSelectIndex + 1));
|
|
522
621
|
currentSelectItem.classList.add(_const.SELECTED_ITEM_CLASS_NAME);
|
|
523
622
|
}
|
|
524
623
|
}
|
|
525
|
-
}, [clearSelectStyle, currentSelectIndex, downDownWrapperRef, onHandleInputFocus]);
|
|
624
|
+
}, [clearSelectStyle, currentSelectIndex, downDownWrapperRef, onHandleInputFocus, quickInsertMenuSearchMap]);
|
|
526
625
|
var onChange = (0, _react.useCallback)(function (e) {
|
|
527
626
|
if (!downDownWrapperRef.current.isInputtingChinese) {
|
|
528
627
|
var newMenuSearchMap = (0, _helpers5.getSearchedOperations)(_constants2.SIDE_QUICK_INSERT_MENUS_SEARCH_MAP, true, e, t, editor);
|
|
628
|
+
var hasResults = Object.keys(newMenuSearchMap).length > 0;
|
|
629
|
+
preserveSearchInputFocusRef.current = hasResults;
|
|
529
630
|
setQuickInsertMenuSearchMap(newMenuSearchMap);
|
|
631
|
+
setCurrentSelectIndex(hasResults ? 0 : -1);
|
|
530
632
|
}
|
|
531
633
|
}, [editor, t]);
|
|
532
634
|
var onCompositionStart = (0, _react.useCallback)(function () {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
.sdoc-quick-insert-toolbar .sdoc-dropdown-menu-item.sdoc-dropdown-item-selected
|
|
2
|
-
|
|
1
|
+
.sdoc-quick-insert-toolbar .sdoc-dropdown-menu-item.sdoc-dropdown-item-selected,
|
|
2
|
+
.sdoc-quick-insert-video-menu-popover .sdoc-dropdown-menu-item.sdoc-dropdown-item-selected {
|
|
3
|
+
background-color: rgba(0, 0, 0, 0.04);
|
|
4
|
+
border-radius: 4px;
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
.sdoc-quick-insert-toolbar .sdoc-insert-element-content-wrapper {
|
|
@@ -7,3 +9,13 @@
|
|
|
7
9
|
overflow-y: auto;
|
|
8
10
|
padding: 0 8px 8px;
|
|
9
11
|
}
|
|
12
|
+
|
|
13
|
+
.sdoc-quick-insert-toolbar .sdoc-insert-element-content-wrapper .sdoc-dropdown-menu-item-no-results {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
padding: 48px 0;
|
|
18
|
+
height: auto;
|
|
19
|
+
color: #666666;
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
}
|
|
@@ -40,27 +40,22 @@ var isOverflowPortByDirection = exports.isOverflowPortByDirection = function isO
|
|
|
40
40
|
return right >= viewWidth;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
var onHandleOverflowScroll = exports.onHandleOverflowScroll = function onHandleOverflowScroll(currentSelectItem, downDownWrapperRef) {
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
containerBottom = _downDownWrapperRef$c.bottom;
|
|
49
|
-
var _downDownWrapperRef$c2 = downDownWrapperRef.current.getBoundingClientRect(),
|
|
50
|
-
containerTop = _downDownWrapperRef$c2.top;
|
|
51
|
-
if (curBottom > containerBottom) {
|
|
52
|
-
var scrollTop = downDownWrapperRef.current.scrollTop + 100;
|
|
53
|
-
downDownWrapperRef.current.scrollTo({
|
|
54
|
-
top: scrollTop,
|
|
55
|
-
behavior: 'smooth'
|
|
56
|
-
});
|
|
43
|
+
var onHandleOverflowScroll = exports.onHandleOverflowScroll = function onHandleOverflowScroll(currentSelectItem, downDownWrapperRef, isLastItem) {
|
|
44
|
+
var scrollContainer = downDownWrapperRef.current;
|
|
45
|
+
if (isLastItem) {
|
|
46
|
+
scrollContainer.scrollTop = scrollContainer.scrollHeight - scrollContainer.clientHeight;
|
|
47
|
+
return;
|
|
57
48
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
var _currentSelectItem$ge = currentSelectItem.getBoundingClientRect(),
|
|
50
|
+
itemBottom = _currentSelectItem$ge.bottom,
|
|
51
|
+
itemTop = _currentSelectItem$ge.top;
|
|
52
|
+
var containerRect = scrollContainer.getBoundingClientRect();
|
|
53
|
+
var containerTop = containerRect.top + scrollContainer.clientTop;
|
|
54
|
+
var containerBottom = containerTop + scrollContainer.clientHeight;
|
|
55
|
+
if (itemBottom > containerBottom) {
|
|
56
|
+
scrollContainer.scrollTop += itemBottom - containerBottom;
|
|
57
|
+
} else if (itemTop < containerTop) {
|
|
58
|
+
scrollContainer.scrollTop -= containerTop - itemTop;
|
|
64
59
|
}
|
|
65
60
|
};
|
|
66
61
|
var getMenuPosition = exports.getMenuPosition = function getMenuPosition(element, editor) {
|
package/dist/node-id/index.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
8
10
|
var _slate = require("@seafile/slate");
|
|
9
11
|
var _constants = require("../extension/constants");
|
|
10
12
|
var _documentUtils = require("../utils/document-utils");
|
|
@@ -12,7 +14,9 @@ var _localStorageUtils = _interopRequireDefault(require("../utils/local-storage-
|
|
|
12
14
|
var _helpers = require("./helpers");
|
|
13
15
|
var withNodeId = function withNodeId(editor) {
|
|
14
16
|
var apply = editor.apply,
|
|
15
|
-
insertText = editor.insertText
|
|
17
|
+
insertText = editor.insertText,
|
|
18
|
+
insertBreak = editor.insertBreak,
|
|
19
|
+
insertSoftBreak = editor.insertSoftBreak;
|
|
16
20
|
var newEditor = editor;
|
|
17
21
|
newEditor.apply = function (op) {
|
|
18
22
|
var newOp = (0, _helpers.decorateOperation)(newEditor, op);
|
|
@@ -20,12 +24,37 @@ var withNodeId = function withNodeId(editor) {
|
|
|
20
24
|
};
|
|
21
25
|
newEditor.insertText = function (text) {
|
|
22
26
|
var selection = editor.selection;
|
|
23
|
-
// Remove context comment marks
|
|
24
|
-
if (selection
|
|
25
|
-
var
|
|
27
|
+
// Remove context comment marks at comment boundaries.
|
|
28
|
+
if (selection) {
|
|
29
|
+
var _Range$edges = _slate.Range.edges(selection),
|
|
30
|
+
_Range$edges2 = (0, _slicedToArray2["default"])(_Range$edges, 2),
|
|
31
|
+
start = _Range$edges2[0],
|
|
32
|
+
end = _Range$edges2[1];
|
|
33
|
+
if (_slate.Range.isExpanded(selection) && _slate.Editor["void"](editor, {
|
|
34
|
+
at: end
|
|
35
|
+
})) {
|
|
36
|
+
return insertText(text);
|
|
37
|
+
}
|
|
38
|
+
var _Editor$above = _slate.Editor.above(editor, {
|
|
39
|
+
at: start,
|
|
40
|
+
match: function match(n) {
|
|
41
|
+
return _slate.Editor.isBlock(editor, n);
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
_Editor$above2 = (0, _slicedToArray2["default"])(_Editor$above, 2),
|
|
45
|
+
startBlockPath = _Editor$above2[1];
|
|
46
|
+
var _Editor$above3 = _slate.Editor.above(editor, {
|
|
47
|
+
at: end,
|
|
48
|
+
match: function match(n) {
|
|
49
|
+
return _slate.Editor.isBlock(editor, n);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
_Editor$above4 = (0, _slicedToArray2["default"])(_Editor$above3, 2),
|
|
53
|
+
endBlockPath = _Editor$above4[1];
|
|
54
|
+
var beforePoint = !_slate.Editor.isStart(editor, start, startBlockPath) && _slate.Editor.before(editor, start, {
|
|
26
55
|
unit: 'character'
|
|
27
56
|
});
|
|
28
|
-
var afterPoint = _slate.Editor.
|
|
57
|
+
var afterPoint = !_slate.Editor.isEnd(editor, end, endBlockPath) && _slate.Editor.after(editor, end, {
|
|
29
58
|
unit: 'character'
|
|
30
59
|
});
|
|
31
60
|
var beforeText = beforePoint && _slate.Editor.node(editor, beforePoint);
|
|
@@ -36,20 +65,32 @@ var withNodeId = function withNodeId(editor) {
|
|
|
36
65
|
var hasCommentAfter = afterText && _slate.Text.isText(afterText[0]) && Object.keys(afterText[0]).some(function (k) {
|
|
37
66
|
return k.includes('sdoc_comment');
|
|
38
67
|
});
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
var marks = _slate.Editor.marks(editor);
|
|
69
|
+
if (marks) {
|
|
70
|
+
var _Editor$leaf = _slate.Editor.leaf(editor, start),
|
|
71
|
+
_Editor$leaf2 = (0, _slicedToArray2["default"])(_Editor$leaf, 1),
|
|
72
|
+
currentText = _Editor$leaf2[0];
|
|
73
|
+
if (hasCommentBefore || hasCommentAfter || Object.keys(currentText).some(function (k) {
|
|
74
|
+
return k.includes('sdoc_comment');
|
|
75
|
+
}) || Object.keys(marks).some(function (k) {
|
|
76
|
+
return k.includes('sdoc_comment');
|
|
77
|
+
})) {
|
|
78
|
+
var inputMarks = (0, _objectSpread2["default"])({}, marks);
|
|
47
79
|
for (var _i = 0, _Object$keys = Object.keys(marks); _i < _Object$keys.length; _i++) {
|
|
48
80
|
var key = _Object$keys[_i];
|
|
49
|
-
if (key.includes('sdoc_comment')) {
|
|
50
|
-
|
|
81
|
+
if (key === 'id' || key.includes('sdoc_comment') && (!hasCommentBefore || !hasCommentAfter || !(key in beforeText[0]) || !(key in afterText[0]))) {
|
|
82
|
+
delete inputMarks[key];
|
|
51
83
|
}
|
|
52
84
|
}
|
|
85
|
+
if (Object.keys(marks).some(function (key) {
|
|
86
|
+
return key.includes('sdoc_comment') && !(key in inputMarks);
|
|
87
|
+
}) || Object.keys(currentText).some(function (key) {
|
|
88
|
+
return key.includes('sdoc_comment') && !(key in inputMarks);
|
|
89
|
+
}) || Object.keys(inputMarks).some(function (key) {
|
|
90
|
+
return key.includes('sdoc_comment') && !(key in currentText);
|
|
91
|
+
})) {
|
|
92
|
+
editor.marks = inputMarks;
|
|
93
|
+
}
|
|
53
94
|
}
|
|
54
95
|
}
|
|
55
96
|
}
|
|
@@ -72,6 +113,44 @@ var withNodeId = function withNodeId(editor) {
|
|
|
72
113
|
return newEditor;
|
|
73
114
|
}
|
|
74
115
|
};
|
|
116
|
+
var insertWithCommentCleanup = function insertWithCommentCleanup(insertMethod) {
|
|
117
|
+
var start = editor.selection && _slate.Range.start(editor.selection);
|
|
118
|
+
var atStart = start && _slate.Editor.isStart(editor, start, start.path.slice(0, -1));
|
|
119
|
+
insertMethod();
|
|
120
|
+
_slate.Editor.withoutNormalizing(editor, function () {
|
|
121
|
+
var selection = editor.selection;
|
|
122
|
+
if (!selection || !_slate.Range.isCollapsed(selection)) return;
|
|
123
|
+
var currentText = _slate.Editor.leaf(editor, selection.focus);
|
|
124
|
+
var previousText = atStart && _slate.Editor.previous(editor, {
|
|
125
|
+
at: selection.focus.path,
|
|
126
|
+
match: _slate.Text.isText
|
|
127
|
+
});
|
|
128
|
+
// A split at the start can leave the new empty leaf before the cursor.
|
|
129
|
+
for (var _i2 = 0, _arr = [previousText, currentText]; _i2 < _arr.length; _i2++) {
|
|
130
|
+
var entry = _arr[_i2];
|
|
131
|
+
if (!entry) continue;
|
|
132
|
+
var _entry = (0, _slicedToArray2["default"])(entry, 2),
|
|
133
|
+
node = _entry[0],
|
|
134
|
+
path = _entry[1];
|
|
135
|
+
if (node.text === '') {
|
|
136
|
+
var commentKeys = Object.keys(node).filter(function (key) {
|
|
137
|
+
return key.startsWith('sdoc_comment_');
|
|
138
|
+
});
|
|
139
|
+
if (commentKeys.length) {
|
|
140
|
+
_slate.Transforms.unsetNodes(editor, commentKeys, {
|
|
141
|
+
at: path
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
newEditor.insertBreak = function () {
|
|
149
|
+
insertWithCommentCleanup(insertBreak);
|
|
150
|
+
};
|
|
151
|
+
newEditor.insertSoftBreak = function () {
|
|
152
|
+
insertWithCommentCleanup(insertSoftBreak);
|
|
153
|
+
};
|
|
75
154
|
return newEditor;
|
|
76
155
|
};
|
|
77
156
|
var _default = exports["default"] = withNodeId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.258",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a34ba7377c7a32f95eda07ae613a53b62008a2ca"
|
|
74
74
|
}
|