@seafile/sdoc-editor 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/basic-sdk/comment/components/elements-comment-count/element-comment-count.js +3 -1
- package/dist/basic-sdk/constants/index.js +2 -0
- package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +0 -1
- package/dist/basic-sdk/extension/plugins/file-link/helpers.js +0 -1
- package/dist/basic-sdk/extension/plugins/list/helpers.js +22 -0
- package/dist/basic-sdk/extension/plugins/list/plugin/index.js +8 -1
- package/dist/basic-sdk/extension/plugins/list/plugin/shortcut.js +79 -0
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +61 -4
- package/dist/basic-sdk/extension/plugins/sdoc-link/plugin.js +19 -2
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +6 -0
- package/dist/basic-sdk/extension/plugins/table/helpers.js +37 -5
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +2 -8
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.css +11 -4
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +20 -12
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/index.css +35 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/index.js +33 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/sample-table.js +33 -0
- package/dist/basic-sdk/extension/plugins/table/render/alternate-color.css +37 -0
- package/dist/basic-sdk/extension/plugins/table/render/index.js +5 -3
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +2 -11
- package/dist/components/doc-operations/revision-operations/view-changes/index.js +46 -2
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +2 -1
- package/public/locales/zh_CN/sdoc-editor.json +2 -1
|
@@ -6,6 +6,7 @@ import { getNodeById, focusEditor, findPath } from '../../../extension/core';
|
|
|
6
6
|
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
7
7
|
import { getElementCommentCountTop } from '../../helper';
|
|
8
8
|
import { eventStopPropagation } from '../../../utils/mouse-event';
|
|
9
|
+
import { ELEMENT_TYPE } from '../../../extension/constants';
|
|
9
10
|
var ElementCommentCount = function ElementCommentCount(_ref) {
|
|
10
11
|
var elementId = _ref.elementId,
|
|
11
12
|
commentsCount = _ref.commentsCount;
|
|
@@ -20,8 +21,9 @@ var ElementCommentCount = function ElementCommentCount(_ref) {
|
|
|
20
21
|
eventStopPropagation(event);
|
|
21
22
|
var path = findPath(editor, element);
|
|
22
23
|
var endOfFirstNode = Editor.end(editor, path);
|
|
24
|
+
var startOfFirstNode = Editor.start(editor, path);
|
|
23
25
|
var range = {
|
|
24
|
-
anchor: endOfFirstNode,
|
|
26
|
+
anchor: [ELEMENT_TYPE.LIST_ITEM, ELEMENT_TYPE.ORDERED_LIST, ELEMENT_TYPE.UNORDERED_LIST].includes(element.type) ? startOfFirstNode : endOfFirstNode,
|
|
25
27
|
focus: endOfFirstNode
|
|
26
28
|
};
|
|
27
29
|
focusEditor(editor, range);
|
|
@@ -11,6 +11,8 @@ export var INTERNAL_EVENT = {
|
|
|
11
11
|
COMMENT_LIST_CLICK: 'comment_list_click',
|
|
12
12
|
UNSEEN_NOTIFICATIONS_COUNT: 'unseen_notifications_count'
|
|
13
13
|
};
|
|
14
|
+
export var REVISION_DIFF_KEY = 'diff';
|
|
15
|
+
export var REVISION_DIFF_VALUE = '1';
|
|
14
16
|
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
|
15
17
|
|
|
16
18
|
export var MODIFY_TYPE = {
|
|
@@ -50,7 +50,6 @@ export var getType = function getType(editor) {
|
|
|
50
50
|
};
|
|
51
51
|
export var insertFileLink = function insertFileLink(editor, text, uuid) {
|
|
52
52
|
if (isMenuDisabled(editor)) return;
|
|
53
|
-
|
|
54
53
|
// Selection folded or not
|
|
55
54
|
var selection = editor.selection;
|
|
56
55
|
if (selection == null) return;
|
|
@@ -80,4 +80,26 @@ export var getListType = function getListType(editor, type) {
|
|
|
80
80
|
};
|
|
81
81
|
export var setListType = function setListType(editor, type) {
|
|
82
82
|
toggleList(editor, type);
|
|
83
|
+
};
|
|
84
|
+
export var getBeforeText = function getBeforeText(editor) {
|
|
85
|
+
var selection = editor.selection;
|
|
86
|
+
if (selection == null) return {
|
|
87
|
+
beforeText: '',
|
|
88
|
+
range: null
|
|
89
|
+
};
|
|
90
|
+
var anchor = selection.anchor;
|
|
91
|
+
// Find the near text node above the current text
|
|
92
|
+
var _Editor$above = Editor.above(editor),
|
|
93
|
+
_Editor$above2 = _slicedToArray(_Editor$above, 2),
|
|
94
|
+
aboveNodePath = _Editor$above2[1];
|
|
95
|
+
var aboveNodeStartPoint = Editor.start(editor, aboveNodePath); // The starting position of the text node
|
|
96
|
+
var range = {
|
|
97
|
+
anchor: anchor,
|
|
98
|
+
focus: aboveNodeStartPoint
|
|
99
|
+
};
|
|
100
|
+
var beforeText = Editor.string(editor, range) || '';
|
|
101
|
+
return {
|
|
102
|
+
beforeText: beforeText,
|
|
103
|
+
range: range
|
|
104
|
+
};
|
|
83
105
|
};
|
|
@@ -2,10 +2,12 @@ import { insertBreakList } from './insert-break-list';
|
|
|
2
2
|
import { onTabHandle } from './on-tab-handle';
|
|
3
3
|
import { normalizeList } from './normalize-list';
|
|
4
4
|
import { insertFragmentList } from './insert-fragment-list';
|
|
5
|
+
import { handleShortcut } from './shortcut';
|
|
5
6
|
var withList = function withList(editor) {
|
|
6
7
|
var insertBreak = editor.insertBreak,
|
|
7
8
|
deleteBackWord = editor.deleteBackWord,
|
|
8
|
-
handleTab = editor.handleTab
|
|
9
|
+
handleTab = editor.handleTab,
|
|
10
|
+
insertText = editor.insertText;
|
|
9
11
|
var newEditor = editor;
|
|
10
12
|
newEditor.insertBreak = function () {
|
|
11
13
|
if (insertBreakList(editor)) return;
|
|
@@ -31,6 +33,11 @@ var withList = function withList(editor) {
|
|
|
31
33
|
};
|
|
32
34
|
newEditor.insertFragment = insertFragmentList(newEditor);
|
|
33
35
|
newEditor.normalizeNode = normalizeList(editor);
|
|
36
|
+
newEditor.insertText = function (text) {
|
|
37
|
+
var isPreventInsert = handleShortcut(newEditor, text);
|
|
38
|
+
if (isPreventInsert) return;
|
|
39
|
+
return insertText(text);
|
|
40
|
+
};
|
|
34
41
|
return newEditor;
|
|
35
42
|
};
|
|
36
43
|
export default withList;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { Editor, Path, Range, Transforms } from '@seafile/slate';
|
|
3
|
+
import { ORDERED_LIST, PARAGRAPH } from '../../../constants';
|
|
4
|
+
import { getBeforeText, setListType } from '../helpers';
|
|
5
|
+
import { focusEditor, getLastChild, getPreviousPath } from '../../../core';
|
|
6
|
+
import { generateEmptyListItem } from '../model';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {Editor} editor
|
|
10
|
+
* @param {String} text
|
|
11
|
+
* @returns {Boolean} isPreventInsert
|
|
12
|
+
*/
|
|
13
|
+
export var handleShortcut = function handleShortcut(editor, text) {
|
|
14
|
+
if (text !== ' ') return false;
|
|
15
|
+
var selection = editor.selection;
|
|
16
|
+
if (!Range.isCollapsed(selection)) return false;
|
|
17
|
+
var _Editor$above = Editor.above(editor),
|
|
18
|
+
_Editor$above2 = _slicedToArray(_Editor$above, 2),
|
|
19
|
+
aboveNode = _Editor$above2[0],
|
|
20
|
+
aboveNodePath = _Editor$above2[1];
|
|
21
|
+
var aboveNodeRef = Editor.pathRef(editor, aboveNodePath);
|
|
22
|
+
if (aboveNode.type !== PARAGRAPH) return false;
|
|
23
|
+
// Match ordered list shortcut
|
|
24
|
+
var regShortcut = /^\s*[1-9]+\.\s*$/;
|
|
25
|
+
var _getBeforeText = getBeforeText(editor),
|
|
26
|
+
beforeText = _getBeforeText.beforeText,
|
|
27
|
+
range = _getBeforeText.range;
|
|
28
|
+
var matchResult = beforeText.match(regShortcut);
|
|
29
|
+
var matchedText = matchResult && matchResult[0];
|
|
30
|
+
// If the match fails or the match is not at the beginning of the line, it is not a shortcut
|
|
31
|
+
if (!matchResult || matchResult.index !== 0) return false;
|
|
32
|
+
var previousNodePath = getPreviousPath(aboveNodePath);
|
|
33
|
+
var _Editor$node = Editor.node(editor, previousNodePath),
|
|
34
|
+
_Editor$node2 = _slicedToArray(_Editor$node, 2),
|
|
35
|
+
previousNode = _Editor$node2[0],
|
|
36
|
+
previousPath = _Editor$node2[1];
|
|
37
|
+
// If the previous node is not an ordered list and is not start with `1.`,it is not a shortcut
|
|
38
|
+
if (previousNode.type !== ORDERED_LIST && matchedText !== '1.') return false;
|
|
39
|
+
// If the previous node is not an ordered list and is start with `1.`,transforms to ordered list
|
|
40
|
+
if (previousNode.type !== ORDERED_LIST && matchedText === '1.') {
|
|
41
|
+
// Delete shortcut key text
|
|
42
|
+
Transforms.delete(editor, {
|
|
43
|
+
at: range
|
|
44
|
+
});
|
|
45
|
+
setListType(editor, ORDERED_LIST);
|
|
46
|
+
focusEditor(editor);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Record the order number of the shortcut that will be inserted as a list item
|
|
50
|
+
var shortcutOrderNum = parseInt(matchResult[0].slice(0, -1));
|
|
51
|
+
|
|
52
|
+
// Check If order number is continuous
|
|
53
|
+
if (previousNode.children.length + 1 !== shortcutOrderNum) return false;
|
|
54
|
+
|
|
55
|
+
// Delete shortcut key text
|
|
56
|
+
Transforms.delete(editor, {
|
|
57
|
+
at: range
|
|
58
|
+
});
|
|
59
|
+
// Update aboveNode after delete shortcut text
|
|
60
|
+
var _Editor$above3 = Editor.above(editor);
|
|
61
|
+
var _Editor$above4 = _slicedToArray(_Editor$above3, 1);
|
|
62
|
+
aboveNode = _Editor$above4[0];
|
|
63
|
+
var _getLastChild = getLastChild([previousNode, previousPath]),
|
|
64
|
+
_getLastChild2 = _slicedToArray(_getLastChild, 2),
|
|
65
|
+
lastListItemPath = _getLastChild2[1];
|
|
66
|
+
var targetInsertPath = Path.next(lastListItemPath);
|
|
67
|
+
// Wrap the paragraph in a list item
|
|
68
|
+
var insertedListItem = generateEmptyListItem();
|
|
69
|
+
insertedListItem.children.push(aboveNode);
|
|
70
|
+
Transforms.insertNodes(editor, insertedListItem, {
|
|
71
|
+
at: targetInsertPath
|
|
72
|
+
});
|
|
73
|
+
Transforms.removeNodes(editor, {
|
|
74
|
+
at: aboveNodeRef.unref()
|
|
75
|
+
});
|
|
76
|
+
// Set the selection to the end of the inserted list item
|
|
77
|
+
Transforms.select(editor, Editor.end(editor, targetInsertPath));
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import { ReactEditor } from '@seafile/slate-react';
|
|
3
|
-
import { Editor, Transforms, Range } from '@seafile/slate';
|
|
4
|
+
import { Editor, Transforms, Range, Text } from '@seafile/slate';
|
|
4
5
|
import slugid from 'slugid';
|
|
5
6
|
import copy from 'copy-to-clipboard';
|
|
6
7
|
import context from '../../../../context';
|
|
7
8
|
import { SDOC_LINK, LINK, INSERT_FILE_DISPLAY_TYPE, CODE_BLOCK, CODE_LINE, PARAGRAPH } from '../../constants';
|
|
8
|
-
import { getNodeType, getSelectedElems } from '../../core';
|
|
9
|
+
import { focusEditor, getNodeType, getSelectedElems } from '../../core';
|
|
9
10
|
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
10
11
|
if (readonly) return true;
|
|
11
12
|
if (editor.selection == null) return true;
|
|
@@ -26,7 +27,7 @@ export var generateSdocFileNode = function generateSdocFileNode(uuid, text) {
|
|
|
26
27
|
type: SDOC_LINK,
|
|
27
28
|
doc_uuid: uuid,
|
|
28
29
|
title: text,
|
|
29
|
-
display_type: INSERT_FILE_DISPLAY_TYPE[
|
|
30
|
+
display_type: INSERT_FILE_DISPLAY_TYPE[1],
|
|
30
31
|
children: [{
|
|
31
32
|
id: slugid.nice(),
|
|
32
33
|
text: text || ''
|
|
@@ -50,11 +51,13 @@ export var getType = function getType(editor) {
|
|
|
50
51
|
};
|
|
51
52
|
export var insertSdocFileLink = function insertSdocFileLink(editor, text, uuid) {
|
|
52
53
|
if (isMenuDisabled(editor)) return;
|
|
53
|
-
|
|
54
54
|
// Selection folded or not
|
|
55
55
|
var selection = editor.selection;
|
|
56
56
|
if (selection == null) return;
|
|
57
57
|
var isCollapsed = Range.isCollapsed(selection);
|
|
58
|
+
|
|
59
|
+
// Remove shortcut symbol,if trigger by shortcut
|
|
60
|
+
removeShortCutSymbol(editor);
|
|
58
61
|
if (isCollapsed) {
|
|
59
62
|
// Insert Spaces before and after sdoclinks for easy operation
|
|
60
63
|
editor.insertText(' ');
|
|
@@ -121,4 +124,58 @@ export var onCopySdocLinkNode = function onCopySdocLinkNode(editor, element) {
|
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
});
|
|
127
|
+
};
|
|
128
|
+
export var getBeforeText = function getBeforeText(editor) {
|
|
129
|
+
var selection = editor.selection;
|
|
130
|
+
if (selection == null) return {
|
|
131
|
+
beforeText: '',
|
|
132
|
+
range: null
|
|
133
|
+
};
|
|
134
|
+
var anchor = selection.anchor;
|
|
135
|
+
// Find the near text node above the current text
|
|
136
|
+
var _Editor$nodes3 = Editor.nodes(editor, {
|
|
137
|
+
match: function match(node) {
|
|
138
|
+
return Text.isText(node);
|
|
139
|
+
},
|
|
140
|
+
mode: 'lowest'
|
|
141
|
+
}),
|
|
142
|
+
_Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
|
|
143
|
+
_Editor$nodes4$ = _slicedToArray(_Editor$nodes4[0], 2),
|
|
144
|
+
beforeNodePath = _Editor$nodes4$[1];
|
|
145
|
+
var beforeNodeStartPoint = Editor.start(editor, beforeNodePath); // The starting position of the text node
|
|
146
|
+
var range = {
|
|
147
|
+
anchor: anchor,
|
|
148
|
+
focus: beforeNodeStartPoint
|
|
149
|
+
};
|
|
150
|
+
var beforeText = Editor.string(editor, range) || '';
|
|
151
|
+
return {
|
|
152
|
+
beforeText: beforeText,
|
|
153
|
+
range: range
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
export var isTriggeredByShortCut = function isTriggeredByShortCut(editor) {
|
|
157
|
+
var _getBeforeText = getBeforeText(editor),
|
|
158
|
+
beforeText = _getBeforeText.beforeText;
|
|
159
|
+
return beforeText.slice(-2) === '[[';
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// If insert operation is triggered by shortcut, remove the '[[' symbol
|
|
163
|
+
export var removeShortCutSymbol = function removeShortCutSymbol(editor) {
|
|
164
|
+
// Check is trigger by short cut
|
|
165
|
+
var selection = editor.selection;
|
|
166
|
+
var _getBeforeText2 = getBeforeText(editor),
|
|
167
|
+
beforeText = _getBeforeText2.beforeText,
|
|
168
|
+
beforeRange = _getBeforeText2.range;
|
|
169
|
+
var isTrrigeredByShortCut = beforeText.slice(-3) === '[[ ';
|
|
170
|
+
isTrrigeredByShortCut && Transforms.delete(editor, {
|
|
171
|
+
at: {
|
|
172
|
+
anchor: {
|
|
173
|
+
path: beforeRange.focus.path,
|
|
174
|
+
offset: beforeText.length - 3
|
|
175
|
+
},
|
|
176
|
+
focus: _objectSpread({}, selection.focus)
|
|
177
|
+
},
|
|
178
|
+
voids: true
|
|
179
|
+
});
|
|
180
|
+
focusEditor(editor);
|
|
124
181
|
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Transforms, Node, Editor } from '@seafile/slate';
|
|
2
|
-
import { SDOC_LINK } from '../../constants';
|
|
2
|
+
import { ELEMENT_TYPE, SDOC_LINK } from '../../constants';
|
|
3
|
+
import EventBus from '../../../utils/event-bus';
|
|
4
|
+
import { INTERNAL_EVENT } from '../../../constants';
|
|
5
|
+
import { insertSdocFileLink, isTriggeredByShortCut } from './helpers';
|
|
3
6
|
var withSdocLink = function withSdocLink(editor) {
|
|
4
7
|
var isInline = editor.isInline,
|
|
5
|
-
deleteBackward = editor.deleteBackward
|
|
8
|
+
deleteBackward = editor.deleteBackward,
|
|
9
|
+
onHotKeyDown = editor.onHotKeyDown;
|
|
6
10
|
var newEditor = editor;
|
|
7
11
|
|
|
8
12
|
// Rewrite isInline
|
|
@@ -35,6 +39,19 @@ var withSdocLink = function withSdocLink(editor) {
|
|
|
35
39
|
}
|
|
36
40
|
return deleteBackward(unit);
|
|
37
41
|
};
|
|
42
|
+
newEditor.onHotKeyDown = function (event) {
|
|
43
|
+
var key = event.key;
|
|
44
|
+
if (key !== ' ') return onHotKeyDown && onHotKeyDown(event);
|
|
45
|
+
// If user press whitespace after '[[', open file modal
|
|
46
|
+
var eventBus = EventBus.getInstance();
|
|
47
|
+
if (isTriggeredByShortCut(newEditor)) {
|
|
48
|
+
eventBus.dispatch(INTERNAL_EVENT.INSERT_ELEMENT, {
|
|
49
|
+
type: ELEMENT_TYPE.SDOC_LINK,
|
|
50
|
+
insertSdocFileLinkCallback: insertSdocFileLink
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return onHotKeyDown && onHotKeyDown(event);
|
|
54
|
+
};
|
|
38
55
|
return newEditor;
|
|
39
56
|
};
|
|
40
57
|
export default withSdocLink;
|
|
@@ -28,4 +28,10 @@ export var TABLE_CELL_STYLE = {
|
|
|
28
28
|
};
|
|
29
29
|
export var TABLE_ROW_STYLE = {
|
|
30
30
|
MIN_HEIGHT: 'min_height'
|
|
31
|
+
};
|
|
32
|
+
export var TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP = {
|
|
33
|
+
'#3f495d': 'sdoc-table-3f495d',
|
|
34
|
+
'#2367f2': 'sdoc-table-2367f2',
|
|
35
|
+
'#f77d21': 'sdoc-table-f77d21',
|
|
36
|
+
'#0099f4': 'sdoc-table-0099f4'
|
|
31
37
|
};
|
|
@@ -67,8 +67,20 @@ export var generateTableRow = function generateTableRow(colsCount) {
|
|
|
67
67
|
style: _defineProperty({}, TABLE_ROW_STYLE.MIN_HEIGHT, TABLE_ROW_MIN_HEIGHT)
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {Editor} editor
|
|
73
|
+
* @param {Object} tableProps
|
|
74
|
+
* @param {[number,number]} tableProps.size - table size, [row,column]
|
|
75
|
+
* @param {Boolean} tableProps.alternate_highlight - is alternate highlight
|
|
76
|
+
* @param {string} tableProps.alternate_highlight_color - table alternate highlight color
|
|
77
|
+
*/
|
|
78
|
+
export var generateEmptyTable = function generateEmptyTable(editor, tableProps) {
|
|
79
|
+
var _tableProps$size = tableProps.size,
|
|
80
|
+
size = _tableProps$size === void 0 ? [0, 0] : _tableProps$size,
|
|
81
|
+
_tableProps$alternate = tableProps.alternate_highlight,
|
|
82
|
+
alternate_highlight = _tableProps$alternate === void 0 ? false : _tableProps$alternate,
|
|
83
|
+
alternate_highlight_color = tableProps.alternate_highlight_color;
|
|
72
84
|
var rowsCount = size[0];
|
|
73
85
|
var colsCount = size[1];
|
|
74
86
|
var children = [];
|
|
@@ -87,7 +99,11 @@ export var generateEmptyTable = function generateEmptyTable(editor) {
|
|
|
87
99
|
id: slugid.nice(),
|
|
88
100
|
type: ELEMENT_TYPE.TABLE,
|
|
89
101
|
children: children,
|
|
90
|
-
columns: columns
|
|
102
|
+
columns: columns,
|
|
103
|
+
style: {
|
|
104
|
+
alternate_highlight: alternate_highlight,
|
|
105
|
+
alternate_highlight_color: alternate_highlight_color
|
|
106
|
+
}
|
|
91
107
|
};
|
|
92
108
|
};
|
|
93
109
|
export var insertTable = function insertTable(editor, size, selection) {
|
|
@@ -96,7 +112,9 @@ export var insertTable = function insertTable(editor, size, selection) {
|
|
|
96
112
|
if (position !== INSERT_POSITION.AFTER) {
|
|
97
113
|
if (isTableMenuDisabled(editor)) return;
|
|
98
114
|
}
|
|
99
|
-
var tableNode = generateEmptyTable(editor,
|
|
115
|
+
var tableNode = generateEmptyTable(editor, {
|
|
116
|
+
size: size
|
|
117
|
+
});
|
|
100
118
|
var validSelection = selection || editor.selection;
|
|
101
119
|
var path = Editor.path(editor, validSelection);
|
|
102
120
|
if (position === INSERT_POSITION.AFTER) {
|
|
@@ -926,7 +944,9 @@ var normalizeTableCell = function normalizeTableCell(cell) {
|
|
|
926
944
|
export var normalizeTableELement = function normalizeTableELement(editor, element) {
|
|
927
945
|
if (element.type !== ELEMENT_TYPE.TABLE) {
|
|
928
946
|
var size = [element.children.length, element.children[0].children.length];
|
|
929
|
-
return generateEmptyTable(editor,
|
|
947
|
+
return generateEmptyTable(editor, {
|
|
948
|
+
size: size
|
|
949
|
+
});
|
|
930
950
|
}
|
|
931
951
|
var newElement = _objectSpread({}, element);
|
|
932
952
|
for (var i = 0; i < element.children.length; i++) {
|
|
@@ -937,4 +957,16 @@ export var normalizeTableELement = function normalizeTableELement(editor, elemen
|
|
|
937
957
|
newElement.children[i] = row;
|
|
938
958
|
}
|
|
939
959
|
return newElement;
|
|
960
|
+
};
|
|
961
|
+
export var insertTableByTemplate = function insertTableByTemplate(editor, alternateColor) {
|
|
962
|
+
var size = [4, 4];
|
|
963
|
+
var tableNode = generateEmptyTable(editor, {
|
|
964
|
+
size: size,
|
|
965
|
+
alternate_highlight_color: alternateColor,
|
|
966
|
+
alternate_highlight: true
|
|
967
|
+
});
|
|
968
|
+
var path = Editor.path(editor, editor.selection);
|
|
969
|
+
Transforms.insertNodes(editor, tableNode, {
|
|
970
|
+
at: [path[0]]
|
|
971
|
+
});
|
|
940
972
|
};
|
|
@@ -4,7 +4,6 @@ import { insertTable, isTableMenuDisabled } from '../../helpers';
|
|
|
4
4
|
import { MENUS_CONFIG_MAP, ELEMENT_TYPE, INSERT_POSITION } from '../../../../constants';
|
|
5
5
|
import TableSizePopover from '../../popover/table-size-popover';
|
|
6
6
|
import ElementDropdownMenuItem from '../../../../commons/dropdown-menu-item';
|
|
7
|
-
import { INTERNAL_EVENT } from '../../../../../constants';
|
|
8
7
|
var TableMenu = function TableMenu(_ref) {
|
|
9
8
|
var editor = _ref.editor,
|
|
10
9
|
readonly = _ref.readonly,
|
|
@@ -14,11 +13,6 @@ var TableMenu = function TableMenu(_ref) {
|
|
|
14
13
|
var createTable = useCallback(function (size) {
|
|
15
14
|
insertTable(editor, size, editor.selection, INSERT_POSITION.CURRENT);
|
|
16
15
|
}, [editor]);
|
|
17
|
-
var openDialog = useCallback(function () {
|
|
18
|
-
eventBus.dispatch(INTERNAL_EVENT.INSERT_ELEMENT, {
|
|
19
|
-
type: ELEMENT_TYPE.TABLE
|
|
20
|
-
});
|
|
21
|
-
}, [eventBus]);
|
|
22
16
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ElementDropdownMenuItem, {
|
|
23
17
|
disabled: disabled,
|
|
24
18
|
menuConfig: menuConfig,
|
|
@@ -26,11 +20,11 @@ var TableMenu = function TableMenu(_ref) {
|
|
|
26
20
|
}, !disabled && /*#__PURE__*/React.createElement("i", {
|
|
27
21
|
className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
|
|
28
22
|
})), !disabled && /*#__PURE__*/React.createElement(TableSizePopover, {
|
|
23
|
+
editor: editor,
|
|
29
24
|
target: menuConfig.id,
|
|
30
25
|
trigger: "hover",
|
|
31
26
|
placement: "right-start",
|
|
32
|
-
createTable: createTable
|
|
33
|
-
openDialog: openDialog
|
|
27
|
+
createTable: createTable
|
|
34
28
|
}));
|
|
35
29
|
};
|
|
36
30
|
export default withTranslation('sdoc-editor')(TableMenu);
|
|
@@ -45,13 +45,20 @@
|
|
|
45
45
|
margin-top: 5px;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
.sdoc-selected-table-size-container .sdoc-selected-table-tools-container {
|
|
49
|
+
padding: 10px 0;
|
|
50
|
+
margin-bottom: 10px;
|
|
51
|
+
border-bottom: 1px solid #dedede;
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
padding: 5px 10px 0;
|
|
58
|
+
min-height: 32px;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom:hover {
|
|
56
62
|
cursor: pointer;
|
|
63
|
+
background: #f5f5f5;
|
|
57
64
|
}
|
|
@@ -3,25 +3,26 @@ import React, { useCallback, useRef, useState } from 'react';
|
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { UncontrolledPopover } from 'reactstrap';
|
|
6
|
+
import TableTemplate from '../table-template';
|
|
6
7
|
import './index.css';
|
|
7
8
|
var TableSizePopover = function TableSizePopover(_ref) {
|
|
8
|
-
var
|
|
9
|
+
var editor = _ref.editor,
|
|
10
|
+
target = _ref.target,
|
|
9
11
|
_ref$trigger = _ref.trigger,
|
|
10
12
|
trigger = _ref$trigger === void 0 ? 'legacy' : _ref$trigger,
|
|
11
13
|
_ref$placement = _ref.placement,
|
|
12
14
|
placement = _ref$placement === void 0 ? 'bottom-start' : _ref$placement,
|
|
13
15
|
popperClassName = _ref.popperClassName,
|
|
14
|
-
createTable = _ref.createTable
|
|
15
|
-
|
|
16
|
-
var minSize = [4, 4];
|
|
16
|
+
createTable = _ref.createTable;
|
|
17
|
+
var minSize = [5, 10];
|
|
17
18
|
var maxSize = [10, 10];
|
|
18
19
|
var _useTranslation = useTranslation(),
|
|
19
20
|
t = _useTranslation.t;
|
|
20
|
-
var _useState = useState([
|
|
21
|
+
var _useState = useState([5, 10]),
|
|
21
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
23
|
displaySize = _useState2[0],
|
|
23
24
|
setDisplaySize = _useState2[1];
|
|
24
|
-
var _useState3 = useState([
|
|
25
|
+
var _useState3 = useState([1, 1]),
|
|
25
26
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
26
27
|
selectedSize = _useState4[0],
|
|
27
28
|
setSelectedSize = _useState4[1];
|
|
@@ -85,7 +86,7 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
85
86
|
}, [displaySize, selectedSize]);
|
|
86
87
|
return /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
87
88
|
target: target,
|
|
88
|
-
className: "sdoc-selected-table-size-popover sdoc-sub-dropdown-menu",
|
|
89
|
+
className: "sdoc-selected-table-size-popover sdoc-sub-dropdown-menu sdoc-dropdown-menu",
|
|
89
90
|
trigger: trigger,
|
|
90
91
|
placement: placement,
|
|
91
92
|
hideArrow: true,
|
|
@@ -95,12 +96,19 @@ var TableSizePopover = function TableSizePopover(_ref) {
|
|
|
95
96
|
}, /*#__PURE__*/React.createElement("div", {
|
|
96
97
|
className: "sdoc-selected-table-size-container w-100 h-100 d-flex flex-column"
|
|
97
98
|
}, /*#__PURE__*/React.createElement("div", {
|
|
98
|
-
className: "sdoc-selected-table-
|
|
99
|
-
},
|
|
99
|
+
className: "sdoc-selected-table-tools-container"
|
|
100
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
id: "sdoc-table-template-review-btn",
|
|
102
|
+
className: "sdoc-selected-table-size-custom"
|
|
103
|
+
}, /*#__PURE__*/React.createElement("span", null, t('Table_template')), /*#__PURE__*/React.createElement("i", {
|
|
104
|
+
className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
|
|
105
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
100
106
|
className: "sdoc-table-size-select"
|
|
101
107
|
}, renderTableSize()), /*#__PURE__*/React.createElement("div", {
|
|
102
|
-
className: "sdoc-selected-table-size-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
className: "sdoc-selected-table-size-tip w-100 "
|
|
109
|
+
}, "".concat(selectedSize[0], " x ").concat(selectedSize[1])), /*#__PURE__*/React.createElement(TableTemplate, {
|
|
110
|
+
editor: editor,
|
|
111
|
+
targetId: "sdoc-table-template-review-btn"
|
|
112
|
+
})));
|
|
105
113
|
};
|
|
106
114
|
export default TableSizePopover;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.sdoc-table-template-inner-popover {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-wrap: wrap;
|
|
4
|
+
padding: 20px;
|
|
5
|
+
width: 430px;
|
|
6
|
+
height: 100%;
|
|
7
|
+
background-color: #fff;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.sdoc-table-template-view-table {
|
|
11
|
+
padding: 10px;
|
|
12
|
+
margin: 10px 5px;
|
|
13
|
+
border: 1px solid #e2e3e6;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sdoc-table-template-view-table .sdoc-table-template-row .sdoc-table-template-cell {
|
|
18
|
+
width: 40px;
|
|
19
|
+
height: 20px;
|
|
20
|
+
border-left: 1px solid #e2e3e6;
|
|
21
|
+
border-right: 1px solid #e2e3e6;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sdoc-table-template-view-table .sdoc-table-template-row {
|
|
25
|
+
display: flex;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.sdoc-table-template-view-table .sdoc-table-template-row:first-child .sdoc-table-template-cell {
|
|
29
|
+
border: none;
|
|
30
|
+
border-top: 1px solid #e2e3e6;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.sdoc-table-template-view-table .sdoc-table-template-row:last-child .sdoc-table-template-cell {
|
|
34
|
+
border-bottom: 1px solid #e2e3e6;
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
2
|
+
import { UncontrolledPopover } from 'reactstrap';
|
|
3
|
+
import { TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP } from '../../constants';
|
|
4
|
+
import SmapleTable from './sample-table';
|
|
5
|
+
import { insertTableByTemplate } from '../../helpers';
|
|
6
|
+
import './index.css';
|
|
7
|
+
import '../../render/alternate-color.css';
|
|
8
|
+
var TableTemplate = function TableTemplate(_ref) {
|
|
9
|
+
var editor = _ref.editor,
|
|
10
|
+
targetId = _ref.targetId;
|
|
11
|
+
var tableTemplatePreviewList = useMemo(function () {
|
|
12
|
+
return Reflect.ownKeys(TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP);
|
|
13
|
+
}, []);
|
|
14
|
+
var handleClickTemplate = useCallback(function (e, alternateColor) {
|
|
15
|
+
insertTableByTemplate(editor, alternateColor);
|
|
16
|
+
}, [editor]);
|
|
17
|
+
return /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
18
|
+
target: targetId,
|
|
19
|
+
trigger: "hover",
|
|
20
|
+
placement: "right-start",
|
|
21
|
+
hideArrow: true,
|
|
22
|
+
fade: false,
|
|
23
|
+
className: "sdoc-sub-dropdown-menu sdoc-table-template-popover",
|
|
24
|
+
innerClassName: "sdoc-table-template-inner-popover"
|
|
25
|
+
}, tableTemplatePreviewList.map(function (alternateColor, index) {
|
|
26
|
+
return /*#__PURE__*/React.createElement(SmapleTable, {
|
|
27
|
+
key: alternateColor + index,
|
|
28
|
+
alternateColor: alternateColor,
|
|
29
|
+
onClickTemplate: handleClickTemplate
|
|
30
|
+
});
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
export default TableTemplate;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP } from '../../constants';
|
|
4
|
+
import './index.css';
|
|
5
|
+
var SmapleTable = function SmapleTable(_ref) {
|
|
6
|
+
var alternateColor = _ref.alternateColor,
|
|
7
|
+
onClickTemplate = _ref.onClickTemplate;
|
|
8
|
+
// generate table
|
|
9
|
+
var renderTableRow = useCallback(function (row, column) {
|
|
10
|
+
return new Array(row).fill(null).map(function (_, index) {
|
|
11
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
12
|
+
className: "sdoc-table-template-row table-row",
|
|
13
|
+
key: "sdoc-template-table-row-".concat(index),
|
|
14
|
+
onClick: function onClick(e) {
|
|
15
|
+
return onClickTemplate(e, alternateColor);
|
|
16
|
+
}
|
|
17
|
+
}, new Array(column).fill(null).map(function (_, index) {
|
|
18
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
19
|
+
className: "sdoc-table-template-cell",
|
|
20
|
+
key: "sdoc-template-table-cell-".concat(index)
|
|
21
|
+
});
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
24
|
+
}, [onClickTemplate, alternateColor]);
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
className: "sdoc-table-template-view-table ".concat(TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP[alternateColor])
|
|
27
|
+
}, renderTableRow(4, 4));
|
|
28
|
+
};
|
|
29
|
+
SmapleTable.proptoTypes = {
|
|
30
|
+
alternateColor: PropTypes.string.isRequired,
|
|
31
|
+
onClickTemplate: PropTypes.func.isRequired
|
|
32
|
+
};
|
|
33
|
+
export default SmapleTable;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* type1 */
|
|
2
|
+
.sdoc-table-3f495d .table-row:nth-child(2n + 1) {
|
|
3
|
+
background-color: #f1f3f6;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.sdoc-table-3f495d .table-row:first-child {
|
|
7
|
+
background-color: #3f495d;
|
|
8
|
+
color: white;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* type2 */
|
|
12
|
+
.sdoc-table-2367f2 .table-row:nth-child(2n + 1) {
|
|
13
|
+
background-color: #e1edff;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.sdoc-table-2367f2 .table-row:first-child {
|
|
17
|
+
background-color: #2367f2;
|
|
18
|
+
color: white;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* type3 */
|
|
22
|
+
.sdoc-table-f77d21 .table-row:nth-child(2n + 1) {
|
|
23
|
+
background-color: #fff1e8;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.sdoc-table-f77d21 .table-row:first-child {
|
|
27
|
+
background-color: #f77d21;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* type4 */
|
|
31
|
+
.sdoc-table-0099f4 .table-row:nth-child(2n + 1) {
|
|
32
|
+
background-color: #e1f5ff;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.sdoc-table-0099f4 .table-row:first-child {
|
|
36
|
+
background-color: #0099f4;
|
|
37
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
4
|
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
@@ -5,7 +6,7 @@ import classnames from 'classnames';
|
|
|
5
6
|
import throttle from 'lodash.throttle';
|
|
6
7
|
import { useSelected, useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
7
8
|
import { Transforms, Editor } from '@seafile/slate';
|
|
8
|
-
import { EMPTY_SELECTED_RANGE } from '../constants';
|
|
9
|
+
import { EMPTY_SELECTED_RANGE, TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP } from '../constants';
|
|
9
10
|
import { ResizeHandlersContext, TableSelectedRangeContext, SettingSelectRangeContext } from './hooks';
|
|
10
11
|
import EventBus from '../../../../utils/event-bus';
|
|
11
12
|
import { INTERNAL_EVENT } from '../../../../constants';
|
|
@@ -17,7 +18,9 @@ import TableRoot from './table-root';
|
|
|
17
18
|
import TableHeader from './table-header';
|
|
18
19
|
import { findPath } from '../../../core';
|
|
19
20
|
import './index.css';
|
|
21
|
+
import './alternate-color.css';
|
|
20
22
|
var Table = function Table(_ref) {
|
|
23
|
+
var _element$style, _element$style2;
|
|
21
24
|
var className = _ref.className,
|
|
22
25
|
attributes = _ref.attributes,
|
|
23
26
|
children = _ref.children,
|
|
@@ -181,7 +184,7 @@ var Table = function Table(_ref) {
|
|
|
181
184
|
table: element,
|
|
182
185
|
setSelectedRange: setSelectedRangeByClick
|
|
183
186
|
}), /*#__PURE__*/React.createElement("div", {
|
|
184
|
-
className: tableContainerClassName,
|
|
187
|
+
className: classnames(tableContainerClassName, _defineProperty({}, TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP[element === null || element === void 0 ? void 0 : (_element$style = element.style) === null || _element$style === void 0 ? void 0 : _element$style.alternate_highlight_color], element === null || element === void 0 ? void 0 : (_element$style2 = element.style) === null || _element$style2 === void 0 ? void 0 : _element$style2.alternate_highlight)),
|
|
185
188
|
onMouseDown: onMouseDown,
|
|
186
189
|
ref: table,
|
|
187
190
|
"data-id": element.id
|
|
@@ -197,7 +200,6 @@ function renderTable(props) {
|
|
|
197
200
|
attributes = props.attributes,
|
|
198
201
|
children = props.children,
|
|
199
202
|
element = props.element;
|
|
200
|
-
|
|
201
203
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
202
204
|
var editor = useSlateStatic();
|
|
203
205
|
return /*#__PURE__*/React.createElement(TableRoot, {
|
|
@@ -52,15 +52,6 @@ var InsertBlockMenu = function InsertBlockMenu(_ref) {
|
|
|
52
52
|
|
|
53
53
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
54
|
}, [editor, insertPosition, slateNode]);
|
|
55
|
-
var openTableDialog = useCallback(function () {
|
|
56
|
-
var eventBus = EventBus.getInstance();
|
|
57
|
-
eventBus.dispatch(INTERNAL_EVENT.INSERT_ELEMENT, {
|
|
58
|
-
type: ELEMENT_TYPE.TABLE,
|
|
59
|
-
insertPosition: insertPosition
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
-
}, [insertPosition]);
|
|
64
55
|
var onInsertList = useCallback(function (type) {
|
|
65
56
|
toggleList(editor, type, insertPosition);
|
|
66
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -82,12 +73,12 @@ var InsertBlockMenu = function InsertBlockMenu(_ref) {
|
|
|
82
73
|
}, /*#__PURE__*/React.createElement("i", {
|
|
83
74
|
className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
|
|
84
75
|
}), /*#__PURE__*/React.createElement(TableSizePopover, {
|
|
76
|
+
editor: editor,
|
|
85
77
|
target: "sdoc-side-menu-item-table",
|
|
86
78
|
trigger: "hover",
|
|
87
79
|
placement: "right-start",
|
|
88
80
|
popperClassName: "sdoc-side-menu-table-size",
|
|
89
|
-
createTable: createTable
|
|
90
|
-
openDialog: openTableDialog
|
|
81
|
+
createTable: createTable
|
|
91
82
|
})), /*#__PURE__*/React.createElement(DropdownMenuItem, {
|
|
92
83
|
menuConfig: _objectSpread({}, SIDE_INSERT_MENUS_CONFIG[ELEMENT_TYPE.LINK]),
|
|
93
84
|
onClick: openLinkDialog
|
|
@@ -1,15 +1,59 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import React, { useCallback, useEffect } from 'react';
|
|
2
3
|
import { useTranslation } from 'react-i18next';
|
|
3
4
|
import Switch from '../../../switch';
|
|
4
5
|
import Tooltip from '../../../tooltip';
|
|
6
|
+
import { REVISION_DIFF_KEY, REVISION_DIFF_VALUE } from '../../../../basic-sdk/constants';
|
|
5
7
|
import './index.css';
|
|
6
8
|
var ViewChanges = function ViewChanges(_ref) {
|
|
7
9
|
var isShowChanges = _ref.isShowChanges,
|
|
8
10
|
propsOnViewChangesToggle = _ref.onViewChangesToggle;
|
|
9
11
|
var _useTranslation = useTranslation(),
|
|
10
12
|
t = _useTranslation.t;
|
|
13
|
+
useEffect(function () {
|
|
14
|
+
var url = new URL(window.location.href);
|
|
15
|
+
var searchParams = new URLSearchParams(url.search);
|
|
16
|
+
if (!searchParams.has(REVISION_DIFF_KEY)) return;
|
|
17
|
+
var firstLoadValue = searchParams.get(REVISION_DIFF_KEY);
|
|
18
|
+
if (firstLoadValue === REVISION_DIFF_VALUE) {
|
|
19
|
+
propsOnViewChangesToggle(true);
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
}, []);
|
|
11
23
|
var onViewChangesToggle = useCallback(function () {
|
|
12
|
-
|
|
24
|
+
var nextIsShowChanges = !isShowChanges;
|
|
25
|
+
var url = new URL(window.location.href);
|
|
26
|
+
var searchParams = new URLSearchParams(url.search);
|
|
27
|
+
var newParamsString = '';
|
|
28
|
+
var _iterator = _createForOfIteratorHelper(searchParams.entries()),
|
|
29
|
+
_step;
|
|
30
|
+
try {
|
|
31
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
32
|
+
var item = _step.value;
|
|
33
|
+
if (item[0] !== REVISION_DIFF_KEY) {
|
|
34
|
+
if (newParamsString) {
|
|
35
|
+
newParamsString = newParamsString + "&".concat(item[0], "=").concat(item[1]);
|
|
36
|
+
} else {
|
|
37
|
+
newParamsString = "".concat(item[0], "=").concat(item[1]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_iterator.e(err);
|
|
43
|
+
} finally {
|
|
44
|
+
_iterator.f();
|
|
45
|
+
}
|
|
46
|
+
if (!searchParams.has(REVISION_DIFF_KEY) && nextIsShowChanges) {
|
|
47
|
+
if (newParamsString) {
|
|
48
|
+
newParamsString = newParamsString + "&".concat(REVISION_DIFF_KEY, "=").concat(REVISION_DIFF_VALUE);
|
|
49
|
+
} else {
|
|
50
|
+
newParamsString = "".concat(REVISION_DIFF_KEY, "=").concat(REVISION_DIFF_VALUE);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var validPathName = url.pathname.endsWith('/') ? url.pathname : url.pathname + '/';
|
|
54
|
+
var newURL = "".concat(url.origin).concat(validPathName).concat(newParamsString ? '?' + newParamsString : '');
|
|
55
|
+
window.history.replaceState(null, null, newURL);
|
|
56
|
+
propsOnViewChangesToggle(nextIsShowChanges);
|
|
13
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
58
|
}, [isShowChanges, propsOnViewChangesToggle]);
|
|
15
59
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
package/package.json
CHANGED