@seafile/sdoc-editor 3.0.261 → 3.0.263
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/assets/css/sdoc-editor-plugins.css +4 -0
- package/dist/editor/editable-article.js +23 -7
- package/dist/extension/commons/color-menu/index.js +94 -28
- package/dist/extension/commons/more-dropdown/index.js +3 -2
- package/dist/extension/plugins/image/render-elem.js +3 -1
- package/dist/extension/plugins/text-style/menu/index.js +9 -5
- package/dist/extension/plugins/video/dialog/add-video-link-dialog/index.js +1 -5
- package/dist/extension/plugins/video/helpers.js +16 -11
- package/dist/extension/toolbar/context-toolbar/index.js +62 -14
- package/dist/hooks/use-color-context.js +39 -8
- package/package.json +3 -3
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = void 0;
|
|
9
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
10
9
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createForOfIteratorHelper"));
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _slate = require("@seafile/slate");
|
|
@@ -39,16 +39,29 @@ var EditableArticle = function EditableArticle(_ref) {
|
|
|
39
39
|
updateSlateValue = _ref.updateSlateValue;
|
|
40
40
|
var _useCursors = (0, _useCursors2.useCursors)(editor),
|
|
41
41
|
cursors = _useCursors.cursors;
|
|
42
|
-
var
|
|
42
|
+
var _useState = (0, _react.useState)(false),
|
|
43
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
44
|
+
isColorInputFocused = _useState2[0],
|
|
45
|
+
setColorInputFocused = _useState2[1];
|
|
46
|
+
var pipDecorate = (0, _decorates.usePipDecorate)(editor);
|
|
47
|
+
var decorate = function decorate(entry) {
|
|
48
|
+
var ranges = pipDecorate(entry);
|
|
49
|
+
if (isColorInputFocused && entry[0] === editor && editor.selection && _slate.Range.isExpanded(editor.selection)) {
|
|
50
|
+
ranges.push((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, editor.selection), {}, {
|
|
51
|
+
'sdoc-color-selection': true
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
return ranges;
|
|
55
|
+
};
|
|
43
56
|
var forceUpdate = (0, _useForceUpdate["default"])();
|
|
44
|
-
var
|
|
57
|
+
var _useState3 = (0, _react.useState)({
|
|
45
58
|
top: 0,
|
|
46
59
|
left: 0,
|
|
47
60
|
type: null // 'link-start' | 'link-end' | 'next-start' | 'prev-end'
|
|
48
61
|
}),
|
|
49
|
-
|
|
50
|
-
cursorState =
|
|
51
|
-
setCursorState =
|
|
62
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
63
|
+
cursorState = _useState4[0],
|
|
64
|
+
setCursorState = _useState4[1];
|
|
52
65
|
|
|
53
66
|
// init eventHandler
|
|
54
67
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -376,7 +389,10 @@ var EditableArticle = function EditableArticle(_ref) {
|
|
|
376
389
|
onChange: updateSlateValue
|
|
377
390
|
}, /*#__PURE__*/_react["default"].createElement(_layout.ArticleContainer, {
|
|
378
391
|
editor: editor
|
|
379
|
-
}, /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, !_commonUtils.isMobile && /*#__PURE__*/_react["default"].createElement(_extension.ContextToolbar,
|
|
392
|
+
}, /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, !_commonUtils.isMobile && /*#__PURE__*/_react["default"].createElement(_extension.ContextToolbar, {
|
|
393
|
+
isColorInputFocused: isColorInputFocused,
|
|
394
|
+
onColorInputFocusChange: setColorInputFocused
|
|
395
|
+
}), /*#__PURE__*/_react["default"].createElement(_highlight.SetNodeToDecorations, null), /*#__PURE__*/_react["default"].createElement(_slateReact.Editable, {
|
|
380
396
|
scrollSelectionIntoView: handleScrollIntoView,
|
|
381
397
|
cursors: cursors,
|
|
382
398
|
renderElement: _extension.renderElement,
|
|
@@ -13,7 +13,7 @@ var _reactI18next = require("react-i18next");
|
|
|
13
13
|
var _reactstrap = require("reactstrap");
|
|
14
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
15
|
var _tooltip = _interopRequireDefault(require("../../../components/tooltip"));
|
|
16
|
-
var
|
|
16
|
+
var _useColorContext2 = require("../../../hooks/use-color-context");
|
|
17
17
|
var _mouseEvent = require("../../../utils/mouse-event");
|
|
18
18
|
var _constants = require("../../constants");
|
|
19
19
|
var _colorItem = _interopRequireDefault(require("./color-item"));
|
|
@@ -49,48 +49,64 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
49
49
|
defaultColorTip = _ref.defaultColorTip,
|
|
50
50
|
defaultColor = _ref.defaultColor,
|
|
51
51
|
lastUsedColor = _ref.lastUsedColor,
|
|
52
|
-
updateLastUsedColor = _ref.updateLastUsedColor
|
|
52
|
+
updateLastUsedColor = _ref.updateLastUsedColor,
|
|
53
|
+
onColorPickerUnmount = _ref.onColorPickerUnmount;
|
|
53
54
|
var popoverRef = (0, _react.useRef)(null);
|
|
54
55
|
var moreColorsPopoverRef = (0, _react.useRef)(null);
|
|
55
|
-
var
|
|
56
|
+
var pickerDragsRef = (0, _react.useRef)([]);
|
|
57
|
+
var pickerContainerRef = (0, _react.useRef)(null);
|
|
58
|
+
var setPickerContainer = (0, _react.useCallback)(function (element) {
|
|
59
|
+
if (!element && pickerContainerRef.current) {
|
|
60
|
+
onColorPickerUnmount === null || onColorPickerUnmount === void 0 ? void 0 : onColorPickerUnmount(pickerContainerRef.current);
|
|
61
|
+
}
|
|
62
|
+
pickerContainerRef.current = element;
|
|
63
|
+
}, [onColorPickerUnmount]);
|
|
64
|
+
var _useColorContext = (0, _useColorContext2.useColorContext)(),
|
|
65
|
+
recentUsedColorsMap = _useColorContext.recentUsedColors,
|
|
66
|
+
updateRecentUsedColors = _useColorContext.updateRecentUsedColors;
|
|
67
|
+
var recentUsedColors = recentUsedColorsMap[recentUsedColorsKey];
|
|
68
|
+
var _useState = (0, _react.useState)(false),
|
|
56
69
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
isShowMenu = _useState2[0],
|
|
71
|
+
setMenuShow = _useState2[1];
|
|
59
72
|
var _useState3 = (0, _react.useState)(false),
|
|
60
73
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
isPickerShow = _useState4[0],
|
|
75
|
+
setPickerShow = _useState4[1];
|
|
76
|
+
(0, _react.useEffect)(function () {
|
|
77
|
+
return function () {
|
|
78
|
+
pickerDragsRef.current.forEach(function (drag) {
|
|
79
|
+
return drag.cleanup();
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
67
83
|
var onSetColor = (0, _react.useCallback)(function (color) {
|
|
68
84
|
var shouldClose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
69
85
|
var shouldFocus = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
86
|
+
var shouldRecord = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
70
87
|
if (disabled) return;
|
|
71
88
|
var validColor = color || '';
|
|
72
89
|
setColor(validColor, shouldFocus);
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
if (shouldRecord) {
|
|
91
|
+
pickerDragsRef.current.filter(function (drag) {
|
|
92
|
+
return drag.ended;
|
|
93
|
+
}).forEach(function (drag) {
|
|
94
|
+
return drag.finish();
|
|
95
|
+
});
|
|
96
|
+
updateRecentUsedColors(recentUsedColorsKey, validColor);
|
|
78
97
|
}
|
|
79
98
|
updateLastUsedColor && updateLastUsedColor(validColor);
|
|
80
99
|
if (shouldClose) {
|
|
81
100
|
popoverRef.current.toggle();
|
|
82
101
|
setMenuShow(!isShowMenu);
|
|
83
102
|
}
|
|
84
|
-
|
|
85
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
|
-
}, [recentUsedColors, recentUsedColorsKey, isShowMenu, isPickerShow, disabled]);
|
|
103
|
+
}, [disabled, setColor, recentUsedColorsKey, updateRecentUsedColors, updateLastUsedColor, isShowMenu]);
|
|
87
104
|
var setColorProxy = (0, _react.useCallback)(function (event) {
|
|
88
105
|
if (event.target.className.includes('sdoc-color-item')) {
|
|
89
106
|
var color = event.target.dataset.color;
|
|
90
107
|
onSetColor(color);
|
|
91
108
|
}
|
|
92
|
-
|
|
93
|
-
}, [recentUsedColors, recentUsedColorsKey, isShowMenu, isPickerShow]);
|
|
109
|
+
}, [onSetColor]);
|
|
94
110
|
var toggle = (0, _react.useCallback)(function () {
|
|
95
111
|
if (isPickerShow) return;
|
|
96
112
|
popoverRef.current.toggle();
|
|
@@ -106,21 +122,68 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
106
122
|
var _event$currentTarget$;
|
|
107
123
|
if (event.target.tagName === 'INPUT') (0, _mouseEvent.eventStopPropagation)(event);else (_event$currentTarget$ = event.currentTarget.querySelector('input:focus')) === null || _event$currentTarget$ === void 0 ? void 0 : _event$currentTarget$.blur();
|
|
108
124
|
}, []);
|
|
125
|
+
var onPickerDragStart = (0, _react.useCallback)(function (event) {
|
|
126
|
+
if (disabled || event.target.tagName === 'INPUT' || event.type === 'mousedown' && event.button !== 0) return;
|
|
127
|
+
var pickerWindow = event.currentTarget.ownerDocument.defaultView;
|
|
128
|
+
var drag = {
|
|
129
|
+
startTime: event.timeStamp,
|
|
130
|
+
color: null,
|
|
131
|
+
ended: false
|
|
132
|
+
};
|
|
133
|
+
var endEvents = ['mouseup', 'touchend', 'touchcancel'];
|
|
134
|
+
var _onEnd = function onEnd(endEvent) {
|
|
135
|
+
drag.ended = true;
|
|
136
|
+
drag.endTime = endEvent.timeStamp;
|
|
137
|
+
endEvents.forEach(function (type) {
|
|
138
|
+
return pickerWindow.removeEventListener(type, _onEnd);
|
|
139
|
+
});
|
|
140
|
+
// react-color's Saturation can deliver its trailing change up to 50ms after mouseup.
|
|
141
|
+
drag.timer = setTimeout(drag.finish, 50);
|
|
142
|
+
};
|
|
143
|
+
drag.cleanup = function () {
|
|
144
|
+
endEvents.forEach(function (type) {
|
|
145
|
+
return pickerWindow.removeEventListener(type, _onEnd);
|
|
146
|
+
});
|
|
147
|
+
clearTimeout(drag.timer);
|
|
148
|
+
};
|
|
149
|
+
drag.finish = function () {
|
|
150
|
+
drag.cleanup();
|
|
151
|
+
updateRecentUsedColors(recentUsedColorsKey, drag.color);
|
|
152
|
+
pickerDragsRef.current = pickerDragsRef.current.filter(function (item) {
|
|
153
|
+
return item !== drag;
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
pickerDragsRef.current.push(drag);
|
|
157
|
+
endEvents.forEach(function (type) {
|
|
158
|
+
return pickerWindow.addEventListener(type, _onEnd);
|
|
159
|
+
});
|
|
160
|
+
}, [disabled, recentUsedColorsKey, updateRecentUsedColors]);
|
|
109
161
|
var onClick = (0, _react.useCallback)(function (event) {
|
|
110
162
|
(0, _mouseEvent.eventStopPropagation)(event);
|
|
111
163
|
}, []);
|
|
112
164
|
var onChange = (0, _react.useCallback)(function (color, event) {
|
|
113
165
|
var _event$target;
|
|
166
|
+
if (disabled) return;
|
|
114
167
|
var validColor = color.hex;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
168
|
+
var isDrag = ['mousedown', 'mousemove', 'touchstart', 'touchmove'].includes(event === null || event === void 0 ? void 0 : event.type);
|
|
169
|
+
if (isDrag) {
|
|
170
|
+
var drags = pickerDragsRef.current;
|
|
171
|
+
var drag = drags.slice().reverse().find(function (item) {
|
|
172
|
+
return event.timeStamp >= item.startTime && (!item.ended || event.timeStamp <= item.endTime);
|
|
173
|
+
});
|
|
174
|
+
if (!drag) return;
|
|
175
|
+
drag.color = validColor;
|
|
176
|
+
// A trailing change from an earlier drag must not overwrite a newer selection.
|
|
177
|
+
if (drag !== drags[drags.length - 1]) return;
|
|
178
|
+
}
|
|
179
|
+
onSetColor(validColor, false, isDrag || (event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.tagName) !== 'INPUT', !isDrag);
|
|
180
|
+
}, [disabled, onSetColor]);
|
|
118
181
|
var setLastUsedColor = (0, _react.useCallback)(function (event) {
|
|
119
182
|
(0, _mouseEvent.eventStopPropagation)(event);
|
|
120
183
|
onSetColor(lastUsedColor, false);
|
|
121
|
-
|
|
122
|
-
}, [recentUsedColors, lastUsedColor, disabled]);
|
|
184
|
+
}, [lastUsedColor, onSetColor]);
|
|
123
185
|
var buttonId = "button-".concat(id);
|
|
186
|
+
var moreColorsId = "".concat(id, "-more-colors");
|
|
124
187
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("button", {
|
|
125
188
|
type: "button",
|
|
126
189
|
"aria-label": ariaLabel,
|
|
@@ -217,11 +280,11 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
217
280
|
className: (0, _classnames["default"])('sdoc-more-colors pr-2', {
|
|
218
281
|
'show-pick': isPickerShow
|
|
219
282
|
}),
|
|
220
|
-
id:
|
|
283
|
+
id: moreColorsId
|
|
221
284
|
}, /*#__PURE__*/_react["default"].createElement("span", null, t('More_color')), /*#__PURE__*/_react["default"].createElement("i", {
|
|
222
285
|
className: "sdocfont sdoc-arrow-right"
|
|
223
286
|
})), /*#__PURE__*/_react["default"].createElement(_reactstrap.UncontrolledPopover, {
|
|
224
|
-
target:
|
|
287
|
+
target: moreColorsId,
|
|
225
288
|
className: "sdoc-more-colors-popover",
|
|
226
289
|
trigger: "hover",
|
|
227
290
|
placement: "right",
|
|
@@ -232,7 +295,10 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
232
295
|
ref: moreColorsPopoverRef,
|
|
233
296
|
offset: [0, 0]
|
|
234
297
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
298
|
+
ref: setPickerContainer,
|
|
235
299
|
className: "sdoc-more-colors-container",
|
|
300
|
+
onMouseDownCapture: onPickerDragStart,
|
|
301
|
+
onTouchStartCapture: onPickerDragStart,
|
|
236
302
|
onMouseDown: onPickerMouseDown,
|
|
237
303
|
onClick: onClick
|
|
238
304
|
}, /*#__PURE__*/_react["default"].createElement(_reactColor.ChromePicker, {
|
|
@@ -13,7 +13,9 @@ var _reactstrap = require("reactstrap");
|
|
|
13
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
14
14
|
var _tooltip = _interopRequireDefault(require("../../../components/tooltip"));
|
|
15
15
|
var MoreDropdown = function MoreDropdown(_ref) {
|
|
16
|
-
var _ref$
|
|
16
|
+
var _ref$buttonId = _ref.buttonId,
|
|
17
|
+
buttonId = _ref$buttonId === void 0 ? 'sdoc-more-text-operations' : _ref$buttonId,
|
|
18
|
+
_ref$isRichEditor = _ref.isRichEditor,
|
|
17
19
|
isRichEditor = _ref$isRichEditor === void 0 ? true : _ref$isRichEditor,
|
|
18
20
|
_ref$className = _ref.className,
|
|
19
21
|
className = _ref$className === void 0 ? 'menu-group-item' : _ref$className,
|
|
@@ -27,7 +29,6 @@ var MoreDropdown = function MoreDropdown(_ref) {
|
|
|
27
29
|
'rich-icon-btn-hover': isRichEditor && !disabled,
|
|
28
30
|
'btn btn-icon btn-secondary btn-active': !isRichEditor
|
|
29
31
|
});
|
|
30
|
-
var buttonId = 'sdoc-more-text-operations';
|
|
31
32
|
var _useTranslation = (0, _reactI18next.useTranslation)('sdoc-editor'),
|
|
32
33
|
t = _useTranslation.t;
|
|
33
34
|
var _useState = (0, _react.useState)(false),
|
|
@@ -515,6 +515,8 @@ function renderImageBlock(props, editor) {
|
|
|
515
515
|
var align = element.align;
|
|
516
516
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
517
517
|
var isSelected = (0, _slateReact.useSelected)();
|
|
518
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
519
|
+
var readOnly = (0, _slateReact.useReadOnly)();
|
|
518
520
|
var justifyContent = '';
|
|
519
521
|
if (align) {
|
|
520
522
|
justifyContent = align === 'left' ? 'start' : align === 'right' ? 'end' : align;
|
|
@@ -529,7 +531,7 @@ function renderImageBlock(props, editor) {
|
|
|
529
531
|
onMouseOver: function onMouseOver(e) {
|
|
530
532
|
return (0, _helpers.selectImageWhenSelectPartial)(e, editor, element, isSelected);
|
|
531
533
|
},
|
|
532
|
-
contentEditable:
|
|
534
|
+
contentEditable: !readOnly,
|
|
533
535
|
suppressContentEditableWarning: true
|
|
534
536
|
}), children);
|
|
535
537
|
}
|
|
@@ -30,7 +30,8 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
30
30
|
isRichEditor = _ref.isRichEditor,
|
|
31
31
|
className = _ref.className,
|
|
32
32
|
idPrefix = _ref.idPrefix,
|
|
33
|
-
readonly = _ref.readonly
|
|
33
|
+
readonly = _ref.readonly,
|
|
34
|
+
onColorPickerUnmount = _ref.onColorPickerUnmount;
|
|
34
35
|
var selectedFontSize = (0, _helpers.getFontSize)(editor);
|
|
35
36
|
var selectedFontSizeValue = selectedFontSize;
|
|
36
37
|
var enableSeafileAI = _context["default"].getSetting('enableSeafileAI');
|
|
@@ -118,6 +119,7 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
118
119
|
onMouseDown: item.isColor ? function () {} : onMouseDown
|
|
119
120
|
};
|
|
120
121
|
if (item.isColor) {
|
|
122
|
+
itemProps['onColorPickerUnmount'] = onColorPickerUnmount;
|
|
121
123
|
itemProps['setColor'] = function (color, shouldFocus) {
|
|
122
124
|
return setColor(item.type, color, shouldFocus);
|
|
123
125
|
};
|
|
@@ -131,7 +133,7 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
131
133
|
});
|
|
132
134
|
|
|
133
135
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
134
|
-
}, [editor, lastUsedFontColor, lastUsedHighlightColor, readonly]);
|
|
136
|
+
}, [editor, lastUsedFontColor, lastUsedHighlightColor, readonly, onColorPickerUnmount]);
|
|
135
137
|
var list = getTextStyleList(_constants2.TEXT_STYLE);
|
|
136
138
|
var dropdownList = getTextStyleList(_constants2.TEXT_STYLE_MORE);
|
|
137
139
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, list.map(function (itemProps, index) {
|
|
@@ -139,21 +141,23 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
139
141
|
return /*#__PURE__*/_react["default"].createElement(Component, Object.assign({
|
|
140
142
|
key: index
|
|
141
143
|
}, itemProps));
|
|
142
|
-
}), /*#__PURE__*/_react["default"].createElement(_commons.MoreDropdown,
|
|
144
|
+
}), /*#__PURE__*/_react["default"].createElement(_commons.MoreDropdown, {
|
|
145
|
+
buttonId: idPrefix ? "".concat(idPrefix, "_sdoc-more-text-operations") : 'sdoc-more-text-operations'
|
|
146
|
+
}, dropdownList.map(function (itemProps, index) {
|
|
143
147
|
return /*#__PURE__*/_react["default"].createElement(_commons.MenuItem, Object.assign({
|
|
144
148
|
key: index
|
|
145
149
|
}, itemProps));
|
|
146
150
|
}), /*#__PURE__*/_react["default"].createElement(_fontSizeScale["default"], {
|
|
147
151
|
disabled: isDisabled(),
|
|
148
152
|
onClick: increaseFontSize,
|
|
149
|
-
id: "sdoc-increase-font-size
|
|
153
|
+
id: idPrefix ? "".concat(idPrefix, "_sdoc-increase-font-size") : 'sdoc-increase-font-size',
|
|
150
154
|
tipMessage: t('Increase_font_size')
|
|
151
155
|
}, /*#__PURE__*/_react["default"].createElement("i", {
|
|
152
156
|
className: "sdocfont sdoc-increase-font-size"
|
|
153
157
|
})), /*#__PURE__*/_react["default"].createElement(_fontSizeScale["default"], {
|
|
154
158
|
disabled: isDisabled(),
|
|
155
159
|
onClick: reduceFontSize,
|
|
156
|
-
id: "sdoc-reduce-font-size
|
|
160
|
+
id: idPrefix ? "".concat(idPrefix, "_sdoc-reduce-font-size") : 'sdoc-reduce-font-size',
|
|
157
161
|
tipMessage: t('Reduce_font_size')
|
|
158
162
|
}, /*#__PURE__*/_react["default"].createElement("i", {
|
|
159
163
|
className: "sdocfont sdoc-reduce-font-size"
|
|
@@ -26,17 +26,13 @@ var AddVideoLinkDialog = function AddVideoLinkDialog(_ref) {
|
|
|
26
26
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
27
27
|
url = _useState4[0],
|
|
28
28
|
setURL = _useState4[1];
|
|
29
|
-
var isValidVideoLink = function isValidVideoLink(link) {
|
|
30
|
-
var videoRegex = /v\.qq\.com|youtube\.com|v\.youku\.com|bilibili\.com/i;
|
|
31
|
-
return videoRegex.test(link);
|
|
32
|
-
};
|
|
33
29
|
var submit = (0, _react.useCallback)(function () {
|
|
34
30
|
setLinkErrorMessage('');
|
|
35
31
|
if (!url) {
|
|
36
32
|
setLinkErrorMessage(t('The_link_address_is_required'));
|
|
37
33
|
return;
|
|
38
34
|
}
|
|
39
|
-
if (!
|
|
35
|
+
if (!(0, _helpers.parseVideoLink)(url)) {
|
|
40
36
|
setLinkErrorMessage(t('The_link_address_is_invalid'));
|
|
41
37
|
return;
|
|
42
38
|
}
|
|
@@ -12,6 +12,7 @@ var _slateReact = require("@seafile/slate-react");
|
|
|
12
12
|
var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));
|
|
13
13
|
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
14
14
|
var _context = _interopRequireDefault(require("../../../context"));
|
|
15
|
+
var _urlUtils = require("../../../utils/url-utils");
|
|
15
16
|
var _constants = require("../../constants");
|
|
16
17
|
var _core = require("../../core");
|
|
17
18
|
var _constants2 = require("./constants");
|
|
@@ -63,32 +64,36 @@ var generateVideoNode = exports.generateVideoNode = function generateVideoNode(s
|
|
|
63
64
|
})];
|
|
64
65
|
};
|
|
65
66
|
var parseVideoLink = exports.parseVideoLink = function parseVideoLink(url) {
|
|
66
|
-
|
|
67
|
+
var link = (0, _urlUtils.normalizeWebUrl)(url);
|
|
68
|
+
if (!link) return false;
|
|
69
|
+
var parsedUrl = new URL(link);
|
|
70
|
+
var hostname = parsedUrl.hostname,
|
|
71
|
+
pathname = parsedUrl.pathname;
|
|
67
72
|
|
|
68
73
|
// Youtube url conversion
|
|
69
|
-
if (
|
|
70
|
-
var videoId =
|
|
71
|
-
var videoUrl = videoId ? "https://www.youtube.com/embed/".concat(videoId, "/?rel=0") : false;
|
|
74
|
+
if (hostname === 'youtube.com' || hostname.endsWith('.youtube.com')) {
|
|
75
|
+
var videoId = parsedUrl.searchParams.get('v');
|
|
76
|
+
var videoUrl = videoId ? "https://www.youtube.com/embed/".concat(encodeURIComponent(videoId), "/?rel=0") : false;
|
|
72
77
|
return videoUrl;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
// Tencent url conversion
|
|
76
|
-
if (
|
|
77
|
-
var vidMatch =
|
|
78
|
-
var _videoUrl = vidMatch !== null && vidMatch !== void 0 && vidMatch[1] ? "https://v.qq.com/txp/iframe/player.html?vid=".concat(vidMatch[1]) : false;
|
|
81
|
+
if (hostname === 'v.qq.com') {
|
|
82
|
+
var vidMatch = pathname.match(/\/([^/]+)\.html/);
|
|
83
|
+
var _videoUrl = vidMatch !== null && vidMatch !== void 0 && vidMatch[1] ? "https://v.qq.com/txp/iframe/player.html?vid=".concat(encodeURIComponent(vidMatch[1])) : false;
|
|
79
84
|
return _videoUrl;
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
// Bilibili url conversion
|
|
83
|
-
if (
|
|
84
|
-
var _vidMatch =
|
|
88
|
+
if (hostname === 'bilibili.com' || hostname.endsWith('.bilibili.com')) {
|
|
89
|
+
var _vidMatch = pathname.match(/\/video\/(BV[0-9A-Za-z]+)/);
|
|
85
90
|
var _videoUrl2 = _vidMatch !== null && _vidMatch !== void 0 && _vidMatch[1] ? "https://player.bilibili.com/player.html?bvid=".concat(_vidMatch[1], "&autoplay=0") : false;
|
|
86
91
|
return _videoUrl2;
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
// Youku url conversion
|
|
90
|
-
if (
|
|
91
|
-
var _vidMatch2 =
|
|
95
|
+
if (hostname === 'v.youku.com') {
|
|
96
|
+
var _vidMatch2 = pathname.match(/id_([A-Za-z0-9=]+)\.html/);
|
|
92
97
|
var _videoUrl3 = _vidMatch2 !== null && _vidMatch2 !== void 0 && _vidMatch2[1] ? "https://player.youku.com/embed/".concat(_vidMatch2[1]) : false;
|
|
93
98
|
return _videoUrl3;
|
|
94
99
|
}
|
|
@@ -17,22 +17,43 @@ var _constants = require("../../constants");
|
|
|
17
17
|
var _core = require("../../core");
|
|
18
18
|
var _menu = _interopRequireDefault(require("../../plugins/text-style/menu"));
|
|
19
19
|
require("./index.css");
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
var ContextToolbar = function ContextToolbar() {
|
|
20
|
+
var ContextToolbar = function ContextToolbar(_ref) {
|
|
21
|
+
var isColorInputFocused = _ref.isColorInputFocused,
|
|
22
|
+
onColorInputFocusChange = _ref.onColorInputFocusChange;
|
|
25
23
|
var ref = (0, _react.useRef)(null);
|
|
26
24
|
var editor = (0, _slateReact.useSlateStatic)();
|
|
27
25
|
var scrollRef = (0, _useScrollContext.useScrollContext)();
|
|
28
26
|
var inFocus = (0, _slateReact.useFocused)();
|
|
29
27
|
var readOnly = (0, _slateReact.useReadOnly)();
|
|
30
28
|
var clickedCommentRef = (0, _react.useRef)(false);
|
|
29
|
+
var colorInputRef = (0, _react.useRef)(null);
|
|
30
|
+
var internalDragRef = (0, _react.useRef)(false);
|
|
31
|
+
var clearColorInput = (0, _react.useCallback)(function () {
|
|
32
|
+
if (!colorInputRef.current) return;
|
|
33
|
+
colorInputRef.current = null;
|
|
34
|
+
onColorInputFocusChange(false);
|
|
35
|
+
}, [onColorInputFocusChange]);
|
|
36
|
+
var onColorPickerUnmount = (0, _react.useCallback)(function (container) {
|
|
37
|
+
if (!container.contains(colorInputRef.current)) return;
|
|
38
|
+
if (document.activeElement === colorInputRef.current && ref.current && editor.selection && !_slateReact.ReactEditor.isReadOnly(editor)) {
|
|
39
|
+
(0, _core.focusEditor)(editor);
|
|
40
|
+
}
|
|
41
|
+
clearColorInput();
|
|
42
|
+
}, [clearColorInput, editor]);
|
|
43
|
+
var onFocus = (0, _react.useCallback)(function (event) {
|
|
44
|
+
if (!event.target.matches('.sdoc-more-colors-container input')) return;
|
|
45
|
+
colorInputRef.current = event.target;
|
|
46
|
+
onColorInputFocusChange(true);
|
|
47
|
+
}, [onColorInputFocusChange]);
|
|
48
|
+
var onBlur = (0, _react.useCallback)(function (event) {
|
|
49
|
+
if (event.target !== colorInputRef.current) return;
|
|
50
|
+
var picker = event.target.closest('.sdoc-more-colors-container');
|
|
51
|
+
if (!(picker !== null && picker !== void 0 && picker.contains(event.relatedTarget))) clearColorInput();
|
|
52
|
+
}, [clearColorInput]);
|
|
31
53
|
var setContextToolbarPosition = (0, _react.useCallback)(function () {
|
|
32
54
|
var el = ref.current;
|
|
33
|
-
|
|
34
|
-
var domRange =
|
|
35
|
-
if (!domRange) return;
|
|
55
|
+
if (!el || !editor.selection) return;
|
|
56
|
+
var domRange = _slateReact.ReactEditor.toDOMRange(editor, editor.selection);
|
|
36
57
|
var rect = domRange.getBoundingClientRect();
|
|
37
58
|
var top = rect.top - 42 - 12; // top = Current top - Element height - Shaded part
|
|
38
59
|
el.style.top = "".concat(top, "px");
|
|
@@ -53,8 +74,7 @@ var ContextToolbar = function ContextToolbar() {
|
|
|
53
74
|
// context menu is in current screen
|
|
54
75
|
el.style.display = 'block';
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
}, []);
|
|
77
|
+
}, [editor]);
|
|
58
78
|
var onScroll = (0, _react.useCallback)(function (e) {
|
|
59
79
|
setContextToolbarPosition();
|
|
60
80
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -69,15 +89,39 @@ var ContextToolbar = function ContextToolbar() {
|
|
|
69
89
|
clickedCommentRef.current = false;
|
|
70
90
|
return;
|
|
71
91
|
}
|
|
72
|
-
if (readOnly || !selection || !inFocus || _slate.Range.isCollapsed(selection) || _slate.Editor.string(editor, selection) === '' || (0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
92
|
+
if (readOnly || !selection || !inFocus && !isColorInputFocused || _slate.Range.isCollapsed(selection) || _slate.Editor.string(editor, selection) === '' || (0, _core.getSelectedNodeByType)(editor, _constants.CODE_BLOCK)) {
|
|
73
93
|
scrollRef.current && scrollRef.current.removeEventListener('scroll', onScroll);
|
|
74
94
|
(0, _domUtils.hideToolbarTooltips)(el);
|
|
75
95
|
el.removeAttribute('style');
|
|
96
|
+
clearColorInput();
|
|
76
97
|
return;
|
|
77
98
|
}
|
|
78
99
|
scrollRef.current && scrollRef.current.addEventListener('scroll', onScroll);
|
|
79
100
|
setContextToolbarPosition();
|
|
80
101
|
});
|
|
102
|
+
(0, _react.useEffect)(function () {
|
|
103
|
+
var resetInternalDrag = function resetInternalDrag() {
|
|
104
|
+
internalDragRef.current = false;
|
|
105
|
+
};
|
|
106
|
+
document.addEventListener('mousedown', resetInternalDrag, true);
|
|
107
|
+
window.addEventListener('mouseup', resetInternalDrag);
|
|
108
|
+
window.addEventListener('blur', resetInternalDrag);
|
|
109
|
+
return function () {
|
|
110
|
+
document.removeEventListener('mousedown', resetInternalDrag, true);
|
|
111
|
+
window.removeEventListener('mouseup', resetInternalDrag);
|
|
112
|
+
window.removeEventListener('blur', resetInternalDrag);
|
|
113
|
+
clearColorInput();
|
|
114
|
+
};
|
|
115
|
+
}, [clearColorInput]);
|
|
116
|
+
var onMouseDownCapture = (0, _react.useCallback)(function (event) {
|
|
117
|
+
if (event.button !== 0) return;
|
|
118
|
+
internalDragRef.current = true;
|
|
119
|
+
onFocus(event);
|
|
120
|
+
var picker = event.target.closest('.sdoc-more-colors-container');
|
|
121
|
+
if (picker && event.target.tagName !== 'INPUT' && picker.contains(document.activeElement)) {
|
|
122
|
+
(0, _core.focusEditor)(editor);
|
|
123
|
+
}
|
|
124
|
+
}, [editor, onFocus]);
|
|
81
125
|
(0, _react.useEffect)(function () {
|
|
82
126
|
var handleClickCommentBtn = function handleClickCommentBtn(e) {
|
|
83
127
|
var target = e.target;
|
|
@@ -95,7 +139,7 @@ var ContextToolbar = function ContextToolbar() {
|
|
|
95
139
|
}, []);
|
|
96
140
|
var onMouseMove = (0, _react.useCallback)(function (e) {
|
|
97
141
|
var isMouseLeftDown = e.buttons === 1;
|
|
98
|
-
if (isMouseLeftDown) {
|
|
142
|
+
if (isMouseLeftDown && !internalDragRef.current) {
|
|
99
143
|
var el = ref.current;
|
|
100
144
|
(0, _domUtils.hideToolbarTooltips)(el);
|
|
101
145
|
el.removeAttribute('style');
|
|
@@ -104,11 +148,15 @@ var ContextToolbar = function ContextToolbar() {
|
|
|
104
148
|
return /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react["default"].createElement("div", {
|
|
105
149
|
ref: ref,
|
|
106
150
|
className: "sdoc-context-toolbar",
|
|
151
|
+
onMouseDownCapture: onMouseDownCapture,
|
|
107
152
|
onMouseDown: onMouseDown,
|
|
108
|
-
onMouseOver: onMouseMove
|
|
153
|
+
onMouseOver: onMouseMove,
|
|
154
|
+
onFocus: onFocus,
|
|
155
|
+
onBlur: onBlur
|
|
109
156
|
}, /*#__PURE__*/_react["default"].createElement(_commons.MenuGroup, null, /*#__PURE__*/_react["default"].createElement(_menu["default"], {
|
|
110
157
|
editor: editor,
|
|
111
|
-
idPrefix: 'sdoc_context_toolbar'
|
|
158
|
+
idPrefix: 'sdoc_context_toolbar',
|
|
159
|
+
onColorPickerUnmount: onColorPickerUnmount
|
|
112
160
|
}))), document.body);
|
|
113
161
|
};
|
|
114
162
|
var _default = exports["default"] = ContextToolbar;
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.useColorContext = exports.ColorProvider = void 0;
|
|
9
|
+
var _objectSpread4 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
10
|
-
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _context = _interopRequireDefault(require("../context"));
|
|
@@ -15,11 +15,12 @@ var _constants = require("../extension/constants");
|
|
|
15
15
|
var _localStorageUtils = _interopRequireDefault(require("../utils/local-storage-utils"));
|
|
16
16
|
var ColorContext = /*#__PURE__*/_react["default"].createContext(null);
|
|
17
17
|
var getLastUsedTextColors = function getLastUsedTextColors(storageKey) {
|
|
18
|
-
|
|
18
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
+
if (typeof window === 'undefined' || !storageKey) return defaultValue;
|
|
19
20
|
try {
|
|
20
|
-
return _localStorageUtils["default"].getItem(storageKey,
|
|
21
|
+
return _localStorageUtils["default"].getItem(storageKey, defaultValue);
|
|
21
22
|
} catch (_unused) {
|
|
22
|
-
return
|
|
23
|
+
return defaultValue;
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
var ColorProvider = exports.ColorProvider = function ColorProvider(props) {
|
|
@@ -43,9 +44,33 @@ var ColorProvider = exports.ColorProvider = function ColorProvider(props) {
|
|
|
43
44
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
44
45
|
lastUsedTableCellBackgroundColor = _useState6[0],
|
|
45
46
|
updateLastUsedTableCellBackgroundColor = _useState6[1];
|
|
47
|
+
var _useState7 = (0, _react.useState)(function () {
|
|
48
|
+
return (0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, _constants.RECENT_USED_FONT_COLORS_KEY, getLastUsedTextColors(_constants.RECENT_USED_FONT_COLORS_KEY, _constants.DEFAULT_RECENT_USED_LIST)), _constants.RECENT_USED_HIGHLIGHT_COLORS_KEY, getLastUsedTextColors(_constants.RECENT_USED_HIGHLIGHT_COLORS_KEY, _constants.DEFAULT_RECENT_USED_LIST));
|
|
49
|
+
}),
|
|
50
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
|
51
|
+
recentUsedColors = _useState8[0],
|
|
52
|
+
setRecentUsedColors = _useState8[1];
|
|
53
|
+
var recentUsedFontColors = recentUsedColors[_constants.RECENT_USED_FONT_COLORS_KEY];
|
|
54
|
+
var recentUsedHighlightColors = recentUsedColors[_constants.RECENT_USED_HIGHLIGHT_COLORS_KEY];
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
_localStorageUtils["default"].setItem(_constants.RECENT_USED_FONT_COLORS_KEY, recentUsedFontColors);
|
|
57
|
+
}, [recentUsedFontColors]);
|
|
58
|
+
(0, _react.useEffect)(function () {
|
|
59
|
+
_localStorageUtils["default"].setItem(_constants.RECENT_USED_HIGHLIGHT_COLORS_KEY, recentUsedHighlightColors);
|
|
60
|
+
}, [recentUsedHighlightColors]);
|
|
61
|
+
var updateRecentUsedColors = function updateRecentUsedColors(key, color) {
|
|
62
|
+
if (!color) return;
|
|
63
|
+
setRecentUsedColors(function (previous) {
|
|
64
|
+
var colors = previous[key];
|
|
65
|
+
if (colors[0] === color) return previous;
|
|
66
|
+
var newRecentUsedColors = colors.slice(0, 9);
|
|
67
|
+
newRecentUsedColors.unshift(color);
|
|
68
|
+
return (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, previous), {}, (0, _defineProperty2["default"])({}, key, newRecentUsedColors));
|
|
69
|
+
});
|
|
70
|
+
};
|
|
46
71
|
var saveLastUsedTextColor = function saveLastUsedTextColor(colorKey, color) {
|
|
47
72
|
if (!storageKey) return;
|
|
48
|
-
_localStorageUtils["default"].setItem(storageKey, (0,
|
|
73
|
+
_localStorageUtils["default"].setItem(storageKey, (0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, getLastUsedTextColors(storageKey)), {}, (0, _defineProperty2["default"])({}, colorKey, color)));
|
|
49
74
|
};
|
|
50
75
|
var updateLastUsedFontColor = function updateLastUsedFontColor(color) {
|
|
51
76
|
setLastUsedFontColor(color);
|
|
@@ -62,7 +87,9 @@ var ColorProvider = exports.ColorProvider = function ColorProvider(props) {
|
|
|
62
87
|
lastUsedHighlightColor: lastUsedHighlightColor,
|
|
63
88
|
updateLastUsedHighlightColor: updateLastUsedHighlightColor,
|
|
64
89
|
lastUsedTableCellBackgroundColor: lastUsedTableCellBackgroundColor,
|
|
65
|
-
updateLastUsedTableCellBackgroundColor: updateLastUsedTableCellBackgroundColor
|
|
90
|
+
updateLastUsedTableCellBackgroundColor: updateLastUsedTableCellBackgroundColor,
|
|
91
|
+
recentUsedColors: recentUsedColors,
|
|
92
|
+
updateRecentUsedColors: updateRecentUsedColors
|
|
66
93
|
}
|
|
67
94
|
}, props.children);
|
|
68
95
|
};
|
|
@@ -76,13 +103,17 @@ var useColorContext = exports.useColorContext = function useColorContext() {
|
|
|
76
103
|
lastUsedTableCellBackgroundColor = context.lastUsedTableCellBackgroundColor,
|
|
77
104
|
updateLastUsedFontColor = context.updateLastUsedFontColor,
|
|
78
105
|
updateLastUsedHighlightColor = context.updateLastUsedHighlightColor,
|
|
79
|
-
updateLastUsedTableCellBackgroundColor = context.updateLastUsedTableCellBackgroundColor
|
|
106
|
+
updateLastUsedTableCellBackgroundColor = context.updateLastUsedTableCellBackgroundColor,
|
|
107
|
+
recentUsedColors = context.recentUsedColors,
|
|
108
|
+
updateRecentUsedColors = context.updateRecentUsedColors;
|
|
80
109
|
return {
|
|
81
110
|
lastUsedFontColor: lastUsedFontColor,
|
|
82
111
|
updateLastUsedFontColor: updateLastUsedFontColor,
|
|
83
112
|
lastUsedHighlightColor: lastUsedHighlightColor,
|
|
84
113
|
updateLastUsedHighlightColor: updateLastUsedHighlightColor,
|
|
85
114
|
lastUsedTableCellBackgroundColor: lastUsedTableCellBackgroundColor,
|
|
86
|
-
updateLastUsedTableCellBackgroundColor: updateLastUsedTableCellBackgroundColor
|
|
115
|
+
updateLastUsedTableCellBackgroundColor: updateLastUsedTableCellBackgroundColor,
|
|
116
|
+
recentUsedColors: recentUsedColors,
|
|
117
|
+
updateRecentUsedColors: updateRecentUsedColors
|
|
87
118
|
};
|
|
88
119
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.263",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"description": "",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@seafile/comment-editor": "1.0.
|
|
20
|
+
"@seafile/comment-editor": "1.0.34",
|
|
21
21
|
"@seafile/print-js": "1.6.6",
|
|
22
22
|
"@seafile/react-image-lightbox": "^5.0.6",
|
|
23
23
|
"@seafile/slate": "0.91.8",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "2856bc842753ede907c64dca27fbb5e68d40d2f8"
|
|
74
74
|
}
|