@seafile/sdoc-editor 3.0.253 → 3.0.255
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/comment/components/editor-comment.js +14 -0
- package/dist/extension/commons/color-menu/index.js +10 -3
- package/dist/extension/constants/color.js +2 -1
- package/dist/extension/constants/index.js +6 -0
- package/dist/extension/plugins/header/helpers.js +2 -8
- package/dist/extension/plugins/image/helpers.js +106 -1
- package/dist/extension/plugins/image/use-copy-image.js +73 -49
- package/dist/extension/plugins/text-style/menu/index.js +4 -3
- package/dist/hooks/use-color-context.js +36 -4
- package/dist/utils/local-storage-utils.js +14 -10
- package/package.json +2 -2
|
@@ -124,6 +124,20 @@ var EditorComment = function EditorComment(_ref) {
|
|
|
124
124
|
|
|
125
125
|
// Comments are updated to modify the current comment
|
|
126
126
|
(0, _react.useEffect)(function () {
|
|
127
|
+
if (isShowComments && Object.keys(commentDetail).length) {
|
|
128
|
+
var comments = Object.values(element_comments_map).flat();
|
|
129
|
+
var newCommentDetail = (0, _objectSpread2["default"])({}, commentDetail);
|
|
130
|
+
Object.keys(newCommentDetail).forEach(function (key) {
|
|
131
|
+
var comment = comments.find(function (item) {
|
|
132
|
+
var _newCommentDetail$key;
|
|
133
|
+
return item.id === ((_newCommentDetail$key = newCommentDetail[key]) === null || _newCommentDetail$key === void 0 ? void 0 : _newCommentDetail$key.id);
|
|
134
|
+
});
|
|
135
|
+
if (comment) {
|
|
136
|
+
newCommentDetail[key] = comment;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
setCommentDetail(newCommentDetail);
|
|
140
|
+
}
|
|
127
141
|
if (isContextComment && activeElementIds) {
|
|
128
142
|
var unresolvedComments = element_comments_map[activeElementIds[0].element.id].filter(function (item) {
|
|
129
143
|
return !item.resolved;
|
|
@@ -66,9 +66,10 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
66
66
|
setPickerShow = _useState6[1];
|
|
67
67
|
var onSetColor = (0, _react.useCallback)(function (color) {
|
|
68
68
|
var shouldClose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
69
|
+
var shouldFocus = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
69
70
|
if (disabled) return;
|
|
70
71
|
var validColor = color || '';
|
|
71
|
-
setColor(validColor);
|
|
72
|
+
setColor(validColor, shouldFocus);
|
|
72
73
|
if (validColor !== '' && recentUsedColors[0] !== validColor) {
|
|
73
74
|
var newRecentUsedColors = recentUsedColors.slice(0, 9);
|
|
74
75
|
newRecentUsedColors.unshift(validColor);
|
|
@@ -101,12 +102,17 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
101
102
|
setPickerShow(!isPickerShow);
|
|
102
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
103
104
|
}, [moreColorsPopoverRef, isPickerShow]);
|
|
105
|
+
var onPickerMouseDown = (0, _react.useCallback)(function (event) {
|
|
106
|
+
var _event$currentTarget$;
|
|
107
|
+
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
|
+
}, []);
|
|
104
109
|
var onClick = (0, _react.useCallback)(function (event) {
|
|
105
110
|
(0, _mouseEvent.eventStopPropagation)(event);
|
|
106
111
|
}, []);
|
|
107
|
-
var onChange = (0, _react.useCallback)(function (color) {
|
|
112
|
+
var onChange = (0, _react.useCallback)(function (color, event) {
|
|
113
|
+
var _event$target;
|
|
108
114
|
var validColor = color.hex;
|
|
109
|
-
onSetColor(validColor, false);
|
|
115
|
+
onSetColor(validColor, false, (event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.tagName) !== 'INPUT');
|
|
110
116
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
117
|
}, [disabled]);
|
|
112
118
|
var setLastUsedColor = (0, _react.useCallback)(function (event) {
|
|
@@ -227,6 +233,7 @@ var ColorMenu = function ColorMenu(_ref) {
|
|
|
227
233
|
offset: [0, 0]
|
|
228
234
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
229
235
|
className: "sdoc-more-colors-container",
|
|
236
|
+
onMouseDown: onPickerMouseDown,
|
|
230
237
|
onClick: onClick
|
|
231
238
|
}, /*#__PURE__*/_react["default"].createElement(_reactColor.ChromePicker, {
|
|
232
239
|
disableAlpha: true,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.STANDARD_COLORS = exports.RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY = exports.RECENT_USED_HIGHLIGHT_COLORS_KEY = exports.RECENT_USED_FONT_COLORS_KEY = exports.DEFAULT_RECENT_USED_LIST = exports.DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR = exports.DEFAULT_LAST_USED_HIGHLIGHT_COLOR = exports.DEFAULT_LAST_USED_FONT_COLOR = exports.DEFAULT_FONT_COLOR = exports.DEFAULT_COLORS = void 0;
|
|
6
|
+
exports.STANDARD_COLORS = exports.RECENT_USED_TABLE_CELL_BACKGROUND_COLORS_KEY = exports.RECENT_USED_HIGHLIGHT_COLORS_KEY = exports.RECENT_USED_FONT_COLORS_KEY = exports.LAST_USED_TEXT_COLORS_KEY = exports.DEFAULT_RECENT_USED_LIST = exports.DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR = exports.DEFAULT_LAST_USED_HIGHLIGHT_COLOR = exports.DEFAULT_LAST_USED_FONT_COLOR = exports.DEFAULT_FONT_COLOR = exports.DEFAULT_COLORS = void 0;
|
|
7
7
|
var DEFAULT_COLORS = exports.DEFAULT_COLORS = [{
|
|
8
8
|
value: '#FFFFFF',
|
|
9
9
|
name: 'White'
|
|
@@ -275,6 +275,7 @@ var DEFAULT_FONT_COLOR = exports.DEFAULT_FONT_COLOR = '#333333';
|
|
|
275
275
|
var DEFAULT_LAST_USED_FONT_COLOR = exports.DEFAULT_LAST_USED_FONT_COLOR = '#FFFF00';
|
|
276
276
|
var DEFAULT_LAST_USED_HIGHLIGHT_COLOR = exports.DEFAULT_LAST_USED_HIGHLIGHT_COLOR = '#FF0000';
|
|
277
277
|
var DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR = exports.DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR = '#FF0000';
|
|
278
|
+
var LAST_USED_TEXT_COLORS_KEY = exports.LAST_USED_TEXT_COLORS_KEY = 'sdoc-last-used-text-colors';
|
|
278
279
|
|
|
279
280
|
// recent used colors key
|
|
280
281
|
var RECENT_USED_HIGHLIGHT_COLORS_KEY = exports.RECENT_USED_HIGHLIGHT_COLORS_KEY = 'sdoc-recent-used-highlight-colors';
|
|
@@ -246,6 +246,12 @@ Object.defineProperty(exports, "KEYBOARD", {
|
|
|
246
246
|
return _keyboard.KEYBOARD;
|
|
247
247
|
}
|
|
248
248
|
});
|
|
249
|
+
Object.defineProperty(exports, "LAST_USED_TEXT_COLORS_KEY", {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function get() {
|
|
252
|
+
return _color.LAST_USED_TEXT_COLORS_KEY;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
249
255
|
Object.defineProperty(exports, "LINK", {
|
|
250
256
|
enumerable: true,
|
|
251
257
|
get: function get() {
|
|
@@ -29,15 +29,9 @@ var getCollapsedHeaderState = function getCollapsedHeaderState() {
|
|
|
29
29
|
return _localStorageUtils["default"].getItem(getHeaderStorageKey(), {});
|
|
30
30
|
};
|
|
31
31
|
var persistCollapsedHeaderState = function persistCollapsedHeaderState(collapsedHeaderState) {
|
|
32
|
-
|
|
33
|
-
_localStorageUtils["default"].setItem(getHeaderStorageKey(), collapsedHeaderState);
|
|
34
|
-
} catch (error) {
|
|
32
|
+
if (_localStorageUtils["default"].setItem(getHeaderStorageKey(), collapsedHeaderState) === false) {
|
|
35
33
|
clearAllHeaderCollapsedState();
|
|
36
|
-
|
|
37
|
-
_localStorageUtils["default"].setItem(getHeaderStorageKey(), collapsedHeaderState);
|
|
38
|
-
} catch (_unused) {
|
|
39
|
-
// Ignore storage failures after cleanup.
|
|
40
|
-
}
|
|
34
|
+
_localStorageUtils["default"].setItem(getHeaderStorageKey(), collapsedHeaderState);
|
|
41
35
|
}
|
|
42
36
|
};
|
|
43
37
|
var getHeaderId = function getHeaderId(editor, element, defaultPath) {
|
|
@@ -11,7 +11,7 @@ Object.defineProperty(exports, "getImageWikiPageUrl", {
|
|
|
11
11
|
return _linkHelpers.getImageWikiPageUrl;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
exports.updateImage = exports.selectImageWhenSelectPartial = exports.resetCursor = exports.removeImageWikiPageLinks = exports.removeImageBlockNode = exports.queryCopyMoveProgressView = exports.isInsertImageMenuDisabled = exports.isImageUrlIsFromUpload = exports.isImageUrlIsFromCopy = exports.isCommentEditor = exports.insertImageFiles = exports.insertImage = exports.hasSdocImages = exports.handleBase64Image = exports.getSingleImageFromFragment = void 0;
|
|
14
|
+
exports.updateImage = exports.selectImageWhenSelectPartial = exports.resetCursor = exports.removeImageWikiPageLinks = exports.removeImageBlockNode = exports.queryCopyMoveProgressView = exports.isInsertImageMenuDisabled = exports.isImageUrlIsFromUpload = exports.isImageUrlIsFromCopy = exports.isForbiddenImageUrl = exports.isCommentEditor = exports.insertImageFiles = exports.insertImage = exports.hasSdocImages = exports.handleBase64Image = exports.getSingleImageFromFragment = void 0;
|
|
15
15
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
|
|
16
16
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
|
|
17
17
|
var _regenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/regenerator"));
|
|
@@ -380,6 +380,111 @@ var isImageUrlIsFromUpload = exports.isImageUrlIsFromUpload = function isImageUr
|
|
|
380
380
|
if (url && url.startsWith('blob:http')) return true;
|
|
381
381
|
return false;
|
|
382
382
|
};
|
|
383
|
+
var isForbiddenIPv4Octets = function isForbiddenIPv4Octets(first, second) {
|
|
384
|
+
if (first === 127 || first === 10 || first === 0) return true;
|
|
385
|
+
if (first === 169 && second === 254) return true;
|
|
386
|
+
if (first === 172 && second >= 16 && second <= 31) return true;
|
|
387
|
+
if (first === 192 && second === 168) return true;
|
|
388
|
+
return false;
|
|
389
|
+
};
|
|
390
|
+
var matchIPv4 = function matchIPv4(value) {
|
|
391
|
+
var match = value.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
392
|
+
if (!match) return null;
|
|
393
|
+
var octets = match.slice(1).map(function (part) {
|
|
394
|
+
return parseInt(part, 10);
|
|
395
|
+
});
|
|
396
|
+
if (octets.some(function (octet) {
|
|
397
|
+
return octet > 255;
|
|
398
|
+
})) return null;
|
|
399
|
+
return octets;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// Expands a bracketed/bare IPv6 literal (handling "::" compression and a
|
|
403
|
+
// trailing embedded IPv4 address, e.g. "::ffff:127.0.0.1") into 8 16-bit groups.
|
|
404
|
+
var parseIPv6Hostname = function parseIPv6Hostname(hostname) {
|
|
405
|
+
var literal = hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
406
|
+
if (!literal.includes(':')) return null;
|
|
407
|
+
var sides = literal.split('::');
|
|
408
|
+
if (sides.length > 2) return null;
|
|
409
|
+
var toGroups = function toGroups(side) {
|
|
410
|
+
if (side === '') return [];
|
|
411
|
+
var parts = side.split(':');
|
|
412
|
+
var last = parts[parts.length - 1];
|
|
413
|
+
if (last.includes('.')) {
|
|
414
|
+
var ipv4 = matchIPv4(last);
|
|
415
|
+
if (!ipv4) return null;
|
|
416
|
+
var _ipv = (0, _slicedToArray2["default"])(ipv4, 4),
|
|
417
|
+
a = _ipv[0],
|
|
418
|
+
b = _ipv[1],
|
|
419
|
+
c = _ipv[2],
|
|
420
|
+
d = _ipv[3];
|
|
421
|
+
parts.splice(parts.length - 1, 1, ((a << 8 | b) & 0xffff).toString(16), ((c << 8 | d) & 0xffff).toString(16));
|
|
422
|
+
}
|
|
423
|
+
if (parts.some(function (part) {
|
|
424
|
+
return !/^[0-9a-f]{1,4}$/i.test(part);
|
|
425
|
+
})) return null;
|
|
426
|
+
return parts.map(function (part) {
|
|
427
|
+
return parseInt(part, 16);
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
var head = toGroups(sides[0]);
|
|
431
|
+
var tail = sides.length === 2 ? toGroups(sides[1]) : [];
|
|
432
|
+
if (head === null || tail === null) return null;
|
|
433
|
+
var groups;
|
|
434
|
+
if (sides.length === 1) {
|
|
435
|
+
groups = head;
|
|
436
|
+
} else {
|
|
437
|
+
var missing = 8 - head.length - tail.length;
|
|
438
|
+
if (missing < 0) return null;
|
|
439
|
+
groups = [].concat((0, _toConsumableArray2["default"])(head), (0, _toConsumableArray2["default"])(Array(missing).fill(0)), (0, _toConsumableArray2["default"])(tail));
|
|
440
|
+
}
|
|
441
|
+
return groups.length === 8 ? groups : null;
|
|
442
|
+
};
|
|
443
|
+
var isForbiddenIPv6 = function isForbiddenIPv6(groups) {
|
|
444
|
+
var _groups = (0, _slicedToArray2["default"])(groups, 8),
|
|
445
|
+
g0 = _groups[0],
|
|
446
|
+
g1 = _groups[1],
|
|
447
|
+
g2 = _groups[2],
|
|
448
|
+
g3 = _groups[3],
|
|
449
|
+
g4 = _groups[4],
|
|
450
|
+
g5 = _groups[5],
|
|
451
|
+
g6 = _groups[6],
|
|
452
|
+
g7 = _groups[7];
|
|
453
|
+
// ::1 loopback
|
|
454
|
+
if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0 && g6 === 0 && g7 === 1) return true;
|
|
455
|
+
// fe80::/10 link-local
|
|
456
|
+
if (g0 >= 0xfe80 && g0 <= 0xfebf) return true;
|
|
457
|
+
// fc00::/7 unique-local
|
|
458
|
+
if (g0 >= 0xfc00 && g0 <= 0xfdff) return true;
|
|
459
|
+
// ::ffff:a.b.c.d IPv4-mapped — re-check the embedded IPv4 address
|
|
460
|
+
if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0xffff) {
|
|
461
|
+
return isForbiddenIPv4Octets(g6 >> 8 & 0xff, g6 & 0xff);
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// Blocks requests to loopback, link-local (incl. cloud metadata) and private network ranges,
|
|
467
|
+
// which a crafted copy/pasted image URL could otherwise force the browser to fetch. URLs on the
|
|
468
|
+
// deployment's own configured server are explicitly allowed even if that server itself resolves
|
|
469
|
+
// to a private address (e.g. a self-hosted/on-prem instance).
|
|
470
|
+
var isForbiddenImageUrl = exports.isForbiddenImageUrl = function isForbiddenImageUrl(urlString) {
|
|
471
|
+
try {
|
|
472
|
+
var _URL = new URL(urlString),
|
|
473
|
+
protocol = _URL.protocol,
|
|
474
|
+
hostname = _URL.hostname;
|
|
475
|
+
if (protocol !== 'http:' && protocol !== 'https:') return true;
|
|
476
|
+
if ((0, _linkHelpers.isCurrentServerUrl)(urlString)) return false;
|
|
477
|
+
if (hostname === 'localhost') return true;
|
|
478
|
+
if (hostname.startsWith('[') || hostname.includes(':')) {
|
|
479
|
+
var groups = parseIPv6Hostname(hostname);
|
|
480
|
+
return groups ? isForbiddenIPv6(groups) : true;
|
|
481
|
+
}
|
|
482
|
+
var ipv4 = matchIPv4(hostname);
|
|
483
|
+
return ipv4 ? isForbiddenIPv4Octets(ipv4[0], ipv4[1]) : false;
|
|
484
|
+
} catch (e) {
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
383
488
|
var isCommentEditor = exports.isCommentEditor = function isCommentEditor(editor) {
|
|
384
489
|
return editor.editorType === _constants.COMMENT_EDITOR;
|
|
385
490
|
};
|
|
@@ -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["default"] = void 0;
|
|
7
|
+
exports.downloadAndUploadImage = exports["default"] = void 0;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
9
9
|
var _regenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/regenerator"));
|
|
10
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
@@ -12,7 +12,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
var _slate = require("@seafile/slate");
|
|
14
14
|
var _slateReact = require("@seafile/slate-react");
|
|
15
|
-
var
|
|
15
|
+
var _context4 = _interopRequireDefault(require("../../../context"));
|
|
16
16
|
var _localStorageUtils = _interopRequireDefault(require("../../../utils/local-storage-utils"));
|
|
17
17
|
var _constants = require("../../constants");
|
|
18
18
|
var _helpers = require("./helpers");
|
|
@@ -49,9 +49,53 @@ var updateImageNode = /*#__PURE__*/function () {
|
|
|
49
49
|
return _ref.apply(this, arguments);
|
|
50
50
|
};
|
|
51
51
|
}();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
|
|
53
|
+
// Downloads a copied/pasted image URL and re-uploads it to our own storage.
|
|
54
|
+
// Exported for direct unit testing of the forbidden-URL guard.
|
|
55
|
+
var downloadAndUploadImage = exports.downloadAndUploadImage = /*#__PURE__*/function () {
|
|
56
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee2(url) {
|
|
57
|
+
var response, blob, file, imageUrl;
|
|
58
|
+
return (0, _regenerator2["default"])().w(function (_context2) {
|
|
59
|
+
while (1) switch (_context2.n) {
|
|
60
|
+
case 0:
|
|
61
|
+
if (!(0, _helpers.isForbiddenImageUrl)(url)) {
|
|
62
|
+
_context2.n = 1;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
throw new Error("Blocked potentially unsafe image URL: ".concat(url));
|
|
66
|
+
case 1:
|
|
67
|
+
_context2.n = 2;
|
|
68
|
+
return fetch(url);
|
|
69
|
+
case 2:
|
|
70
|
+
response = _context2.v;
|
|
71
|
+
if (response.ok) {
|
|
72
|
+
_context2.n = 3;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
throw new Error("HTTP error status: ".concat(response.status));
|
|
76
|
+
case 3:
|
|
77
|
+
_context2.n = 4;
|
|
78
|
+
return response.blob();
|
|
79
|
+
case 4:
|
|
80
|
+
blob = _context2.v;
|
|
81
|
+
file = new File([blob], 'downloaded_image.png', {
|
|
82
|
+
type: blob.type
|
|
83
|
+
});
|
|
84
|
+
_context2.n = 5;
|
|
85
|
+
return _context4["default"].uploadLocalImage([file]);
|
|
86
|
+
case 5:
|
|
87
|
+
imageUrl = _context2.v;
|
|
88
|
+
return _context2.a(2, imageUrl && imageUrl[0] ? imageUrl[0] : null);
|
|
89
|
+
}
|
|
90
|
+
}, _callee2);
|
|
91
|
+
}));
|
|
92
|
+
return function downloadAndUploadImage(_x4) {
|
|
93
|
+
return _ref2.apply(this, arguments);
|
|
94
|
+
};
|
|
95
|
+
}();
|
|
96
|
+
var useCopyImage = function useCopyImage(_ref3) {
|
|
97
|
+
var editor = _ref3.editor,
|
|
98
|
+
element = _ref3.element;
|
|
55
99
|
var data = element.data;
|
|
56
100
|
var _data$is_copy_error = data.is_copy_error,
|
|
57
101
|
is_copy_error = _data$is_copy_error === void 0 ? false : _data$is_copy_error;
|
|
@@ -74,64 +118,44 @@ var useCopyImage = function useCopyImage(_ref2) {
|
|
|
74
118
|
// sync content from another user's copy
|
|
75
119
|
if (!cacheContent || JSON.stringify(cacheContent).indexOf(url) === -1) return;
|
|
76
120
|
}
|
|
77
|
-
var
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
return (0, _regenerator2["default"])().w(function (
|
|
81
|
-
while (1) switch (
|
|
121
|
+
var run = /*#__PURE__*/function () {
|
|
122
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee3(url) {
|
|
123
|
+
var imageUrl, _t;
|
|
124
|
+
return (0, _regenerator2["default"])().w(function (_context3) {
|
|
125
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
82
126
|
case 0:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
127
|
+
_context3.p = 0;
|
|
128
|
+
_context3.n = 1;
|
|
129
|
+
return downloadAndUploadImage(url);
|
|
86
130
|
case 1:
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
break;
|
|
131
|
+
imageUrl = _context3.v;
|
|
132
|
+
if (imageUrl) {
|
|
133
|
+
updateImageNode(editor, element, imageUrl);
|
|
91
134
|
}
|
|
92
|
-
|
|
93
|
-
return response.blob();
|
|
94
|
-
case 2:
|
|
95
|
-
blob = _context2.v;
|
|
96
|
-
file = new File([blob], 'downloaded_image.png', {
|
|
97
|
-
type: blob.type
|
|
98
|
-
});
|
|
99
|
-
_context2.n = 3;
|
|
100
|
-
return _context3["default"].uploadLocalImage([file]);
|
|
101
|
-
case 3:
|
|
102
|
-
imageUrl = _context2.v;
|
|
103
|
-
if (imageUrl && imageUrl[0]) {
|
|
104
|
-
updateImageNode(editor, element, imageUrl[0]);
|
|
105
|
-
}
|
|
106
|
-
_context2.n = 5;
|
|
135
|
+
_context3.n = 3;
|
|
107
136
|
break;
|
|
108
|
-
case
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
_context2.n = 7;
|
|
112
|
-
break;
|
|
113
|
-
case 6:
|
|
114
|
-
_context2.p = 6;
|
|
115
|
-
_t = _context2.v;
|
|
137
|
+
case 2:
|
|
138
|
+
_context3.p = 2;
|
|
139
|
+
_t = _context3.v;
|
|
116
140
|
console.error(_t);
|
|
117
141
|
updateImageNode(editor, element, url, true);
|
|
118
142
|
setIsCopyError(true);
|
|
119
|
-
case
|
|
120
|
-
|
|
143
|
+
case 3:
|
|
144
|
+
_context3.p = 3;
|
|
121
145
|
setTimeout(function () {
|
|
122
146
|
setIsLoading(false);
|
|
123
147
|
}, 500);
|
|
124
|
-
return
|
|
125
|
-
case
|
|
126
|
-
return
|
|
148
|
+
return _context3.f(3);
|
|
149
|
+
case 4:
|
|
150
|
+
return _context3.a(2);
|
|
127
151
|
}
|
|
128
|
-
},
|
|
152
|
+
}, _callee3, null, [[0, 2, 3, 4]]);
|
|
129
153
|
}));
|
|
130
|
-
return function
|
|
131
|
-
return
|
|
154
|
+
return function run(_x5) {
|
|
155
|
+
return _ref4.apply(this, arguments);
|
|
132
156
|
};
|
|
133
157
|
}();
|
|
134
|
-
|
|
158
|
+
run(url);
|
|
135
159
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
160
|
}, []);
|
|
137
161
|
(0, _react.useEffect)(function () {
|
|
@@ -82,8 +82,9 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
82
82
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
83
|
}, [editor]);
|
|
84
84
|
var setColor = (0, _react.useCallback)(function (type, color) {
|
|
85
|
+
var shouldFocus = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
85
86
|
_slate.Editor.addMark(editor, type, color);
|
|
86
|
-
(0, _core.focusEditor)(editor);
|
|
87
|
+
if (shouldFocus) (0, _core.focusEditor)(editor);
|
|
87
88
|
|
|
88
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
90
|
}, [editor]);
|
|
@@ -117,8 +118,8 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
117
118
|
onMouseDown: item.isColor ? function () {} : onMouseDown
|
|
118
119
|
};
|
|
119
120
|
if (item.isColor) {
|
|
120
|
-
itemProps['setColor'] = function (color) {
|
|
121
|
-
return setColor(item.type, color);
|
|
121
|
+
itemProps['setColor'] = function (color, shouldFocus) {
|
|
122
|
+
return setColor(item.type, color, shouldFocus);
|
|
122
123
|
};
|
|
123
124
|
itemProps['defaultColorTip'] = item.type === _constants2.TEXT_STYLE_MAP.COLOR ? t('Default') : '';
|
|
124
125
|
itemProps['lastUsedColor'] = item.type === _constants2.TEXT_STYLE_MAP.COLOR ? lastUsedFontColor : lastUsedHighlightColor;
|
|
@@ -6,23 +6,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.useColorContext = exports.ColorProvider = void 0;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
10
|
+
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
10
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _context = _interopRequireDefault(require("../context"));
|
|
11
14
|
var _constants = require("../extension/constants");
|
|
15
|
+
var _localStorageUtils = _interopRequireDefault(require("../utils/local-storage-utils"));
|
|
12
16
|
var ColorContext = /*#__PURE__*/_react["default"].createContext(null);
|
|
17
|
+
var getLastUsedTextColors = function getLastUsedTextColors(storageKey) {
|
|
18
|
+
if (typeof window === 'undefined' || !storageKey) return {};
|
|
19
|
+
try {
|
|
20
|
+
return _localStorageUtils["default"].getItem(storageKey, {});
|
|
21
|
+
} catch (_unused) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
13
25
|
var ColorProvider = exports.ColorProvider = function ColorProvider(props) {
|
|
14
|
-
var
|
|
26
|
+
var username = _context["default"].getSetting('username');
|
|
27
|
+
var storageKey = username ? "".concat(_constants.LAST_USED_TEXT_COLORS_KEY, ":").concat(username) : '';
|
|
28
|
+
var _useState = (0, _react.useState)(function () {
|
|
29
|
+
var _getLastUsedTextColor;
|
|
30
|
+
return (_getLastUsedTextColor = getLastUsedTextColors(storageKey).fontColor) !== null && _getLastUsedTextColor !== void 0 ? _getLastUsedTextColor : _constants.DEFAULT_LAST_USED_FONT_COLOR;
|
|
31
|
+
}),
|
|
15
32
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
16
33
|
lastUsedFontColor = _useState2[0],
|
|
17
|
-
|
|
18
|
-
var _useState3 = (0, _react.useState)(
|
|
34
|
+
setLastUsedFontColor = _useState2[1];
|
|
35
|
+
var _useState3 = (0, _react.useState)(function () {
|
|
36
|
+
var _getLastUsedTextColor2;
|
|
37
|
+
return (_getLastUsedTextColor2 = getLastUsedTextColors(storageKey).highlightColor) !== null && _getLastUsedTextColor2 !== void 0 ? _getLastUsedTextColor2 : _constants.DEFAULT_LAST_USED_HIGHLIGHT_COLOR;
|
|
38
|
+
}),
|
|
19
39
|
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
20
40
|
lastUsedHighlightColor = _useState4[0],
|
|
21
|
-
|
|
41
|
+
setLastUsedHighlightColor = _useState4[1];
|
|
22
42
|
var _useState5 = (0, _react.useState)(_constants.DEFAULT_LAST_USED_TABLE_CELL_BACKGROUND_COLOR),
|
|
23
43
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
24
44
|
lastUsedTableCellBackgroundColor = _useState6[0],
|
|
25
45
|
updateLastUsedTableCellBackgroundColor = _useState6[1];
|
|
46
|
+
var saveLastUsedTextColor = function saveLastUsedTextColor(colorKey, color) {
|
|
47
|
+
if (!storageKey) return;
|
|
48
|
+
_localStorageUtils["default"].setItem(storageKey, (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, getLastUsedTextColors(storageKey)), {}, (0, _defineProperty2["default"])({}, colorKey, color)));
|
|
49
|
+
};
|
|
50
|
+
var updateLastUsedFontColor = function updateLastUsedFontColor(color) {
|
|
51
|
+
setLastUsedFontColor(color);
|
|
52
|
+
saveLastUsedTextColor('fontColor', color);
|
|
53
|
+
};
|
|
54
|
+
var updateLastUsedHighlightColor = function updateLastUsedHighlightColor(color) {
|
|
55
|
+
setLastUsedHighlightColor(color);
|
|
56
|
+
saveLastUsedTextColor('highlightColor', color);
|
|
57
|
+
};
|
|
26
58
|
return /*#__PURE__*/_react["default"].createElement(ColorContext.Provider, {
|
|
27
59
|
value: {
|
|
28
60
|
lastUsedFontColor: lastUsedFontColor,
|
|
@@ -14,16 +14,20 @@ var LocalStorage = /*#__PURE__*/function () {
|
|
|
14
14
|
return (0, _createClass2["default"])(LocalStorage, null, [{
|
|
15
15
|
key: "setItem",
|
|
16
16
|
value: function setItem(key, value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
try {
|
|
18
|
+
var savedValue;
|
|
19
|
+
var valueType = typeof value;
|
|
20
|
+
if (valueType === 'string') {
|
|
21
|
+
savedValue = value;
|
|
22
|
+
} else if (valueType === 'number') {
|
|
23
|
+
savedValue = value + '';
|
|
24
|
+
} else {
|
|
25
|
+
savedValue = JSON.stringify(value);
|
|
26
|
+
}
|
|
27
|
+
return window.localStorage.setItem(key, savedValue);
|
|
28
|
+
} catch (_unused) {
|
|
29
|
+
return false;
|
|
25
30
|
}
|
|
26
|
-
return window.localStorage.setItem(key, savedValue);
|
|
27
31
|
}
|
|
28
32
|
}, {
|
|
29
33
|
key: "getItem",
|
|
@@ -31,7 +35,7 @@ var LocalStorage = /*#__PURE__*/function () {
|
|
|
31
35
|
var value = window.localStorage.getItem(key);
|
|
32
36
|
try {
|
|
33
37
|
return JSON.parse(value) || defaultValue;
|
|
34
|
-
} catch (
|
|
38
|
+
} catch (_unused2) {
|
|
35
39
|
return value || defaultValue;
|
|
36
40
|
}
|
|
37
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.255",
|
|
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": "23e458f8e50ab0eded01a781c9add9240400af3e"
|
|
74
74
|
}
|