@seafile/seafile-editor 0.3.76
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/README.md +119 -0
- package/TODO.md +55 -0
- package/dist/components/add-formula-dialog.js +135 -0
- package/dist/components/add-image-dialog.js +78 -0
- package/dist/components/add-link-dialog.js +148 -0
- package/dist/components/comment-dialog.js +107 -0
- package/dist/components/comment-panel.js +452 -0
- package/dist/components/context-menu.js +112 -0
- package/dist/components/detail-list-view.js +119 -0
- package/dist/components/generate-share-link.js +412 -0
- package/dist/components/internal-link-dialog.js +96 -0
- package/dist/components/loading.js +32 -0
- package/dist/components/markdown-lint.js +87 -0
- package/dist/components/modal-portal.js +46 -0
- package/dist/components/outline.js +130 -0
- package/dist/components/participants-list.js +126 -0
- package/dist/components/related-files-list.js +75 -0
- package/dist/components/shortcut-dialog.js +167 -0
- package/dist/components/side-panel.js +175 -0
- package/dist/components/toast/alert.js +150 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +179 -0
- package/dist/components/toast/toastManager.js +158 -0
- package/dist/components/toast/toaster.js +76 -0
- package/dist/components/toolbar.js +235 -0
- package/dist/components/topbar-component/button-group.js +31 -0
- package/dist/components/topbar-component/editor-toolbar.js +545 -0
- package/dist/components/topbar-component/file-info.js +65 -0
- package/dist/components/topbar-component/header-list.js +128 -0
- package/dist/components/topbar-component/icon-button.js +99 -0
- package/dist/components/topbar-component/insert-file.js +67 -0
- package/dist/components/topbar-component/table-toolbar.js +175 -0
- package/dist/components/topbar-component/upload-img.js +122 -0
- package/dist/components/user-help.js +205 -0
- package/dist/css/diff-viewer.css +105 -0
- package/dist/css/history-viewer.css +104 -0
- package/dist/css/keyboard-shortcuts.css +59 -0
- package/dist/css/layout.css +110 -0
- package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
- package/dist/css/markdown-viewer.css +69 -0
- package/dist/css/plaineditor/markdown-editor.css +12 -0
- package/dist/css/react-mentions-default-style.js +72 -0
- package/dist/css/related-files-list.css +56 -0
- package/dist/css/richeditor/comments-list.css +184 -0
- package/dist/css/richeditor/detail-list-view.css +114 -0
- package/dist/css/richeditor/document-info.css +57 -0
- package/dist/css/richeditor/formula.css +19 -0
- package/dist/css/richeditor/image.css +141 -0
- package/dist/css/richeditor/link.css +7 -0
- package/dist/css/richeditor/navbar-imgbutton.css +79 -0
- package/dist/css/richeditor/participants-list.css +22 -0
- package/dist/css/richeditor/rich-editor-main.css +42 -0
- package/dist/css/richeditor/right-panel.css +84 -0
- package/dist/css/richeditor/side-panel.css +190 -0
- package/dist/css/richeditor/table.css +57 -0
- package/dist/css/richeditor/textlink-hovermenu.css +47 -0
- package/dist/css/richeditor/tree-view.css +67 -0
- package/dist/css/topbar.css +400 -0
- package/dist/editor/code-highlight-package.js +27 -0
- package/dist/editor/controller/block-element-controller.js +376 -0
- package/dist/editor/controller/inline-element-controller.js +129 -0
- package/dist/editor/controller/normalize-controller.js +107 -0
- package/dist/editor/controller/shortcut-controller.js +394 -0
- package/dist/editor/controller/void-element-controller.js +12 -0
- package/dist/editor/custom/custom.js +17 -0
- package/dist/editor/custom/get-event-transfer.js +34 -0
- package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
- package/dist/editor/custom/insertNodes.js +140 -0
- package/dist/editor/custom/is-empty-paragraph.js +13 -0
- package/dist/editor/custom/set-event-transfer.js +31 -0
- package/dist/editor/custom/split-nodes-at-point.js +162 -0
- package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
- package/dist/editor/editor-component/check-list-item.js +64 -0
- package/dist/editor/editor-component/code-block.js +150 -0
- package/dist/editor/editor-component/formula.js +79 -0
- package/dist/editor/editor-component/image.js +215 -0
- package/dist/editor/editor-component/link.js +11 -0
- package/dist/editor/editor-component/table.js +172 -0
- package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
- package/dist/editor/editor-plugin.js +249 -0
- package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
- package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
- package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
- package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
- package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
- package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
- package/dist/editor/editor-utils/common-editor-utils.js +587 -0
- package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
- package/dist/editor/editor-utils/mark-utils.js +25 -0
- package/dist/editor/editor-utils/range-utils.js +9 -0
- package/dist/editor/editor-utils/selection-utils.js +33 -0
- package/dist/editor/editor-utils/text-utils.js +130 -0
- package/dist/editor/editor.js +66 -0
- package/dist/editor/element-model/blockquote.js +16 -0
- package/dist/editor/element-model/image.js +19 -0
- package/dist/editor/element-model/link.js +19 -0
- package/dist/editor/element-model/table.js +50 -0
- package/dist/editor/element-model/text.js +13 -0
- package/dist/editor/load-script.js +83 -0
- package/dist/editor/plain-markdown-editor.js +324 -0
- package/dist/editor/rich-markdown-editor.js +580 -0
- package/dist/editor/seafile-editor.js +326 -0
- package/dist/editor/simple-editor.js +245 -0
- package/dist/editor-api.js +261 -0
- package/dist/index.css +97 -0
- package/dist/lib/slate-hyperscript/creators.js +263 -0
- package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
- package/dist/lib/slate-hyperscript/index.js +3 -0
- package/dist/lib/slate-hyperscript/tokens.js +102 -0
- package/dist/lib/unified/index.js +470 -0
- package/dist/lib/vfile/core.js +172 -0
- package/dist/lib/vfile/index.js +48 -0
- package/dist/seafile-editor-chooser.js +45 -0
- package/dist/seafile-markdown-editor.js +301 -0
- package/dist/seafile-markdown-viewer.js +79 -0
- package/dist/seafile-simple-editor.js +56 -0
- package/dist/utils/copy-to-clipboard.js +47 -0
- package/dist/utils/deserialize-html.js +282 -0
- package/dist/utils/diff/compare-strings.js +46 -0
- package/dist/utils/diff/diff.js +855 -0
- package/dist/utils/diff/index.js +2 -0
- package/dist/utils/render-slate.js +219 -0
- package/dist/utils/seafile-markdown2html.js +62 -0
- package/dist/utils/slate2markdown/deserialize.js +689 -0
- package/dist/utils/slate2markdown/index.js +3 -0
- package/dist/utils/slate2markdown/serialize.js +407 -0
- package/dist/utils/utils.js +28 -0
- package/dist/viewer/diff-viewer.js +98 -0
- package/dist/viewer/markdown-viewer.js +139 -0
- package/dist/viewer/slate-viewer.js +73 -0
- package/dist/viewer/viewer-formula.js +67 -0
- package/dist/viewer/viewer-image.js +93 -0
- package/dist/viewer/viewer-outline.js +118 -0
- package/package.json +215 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +45 -0
- package/public/locales/cs/seafile-editor.json +169 -0
- package/public/locales/de/seafile-editor.json +169 -0
- package/public/locales/en/seafile-editor.json +222 -0
- package/public/locales/es/seafile-editor.json +169 -0
- package/public/locales/es-AR/seafile-editor.json +169 -0
- package/public/locales/es-MX/seafile-editor.json +169 -0
- package/public/locales/fr/seafile-editor.json +169 -0
- package/public/locales/it/seafile-editor.json +169 -0
- package/public/locales/ru/seafile-editor.json +169 -0
- package/public/locales/zh-CN/seafile-editor.json +219 -0
- package/public/manifest.json +15 -0
- package/public/media/scripts/mathjax/tex-svg.js +1 -0
- package/public/media/seafile-editor-font/iconfont.eot +0 -0
- package/public/media/seafile-editor-font/iconfont.svg +164 -0
- package/public/media/seafile-editor-font/iconfont.ttf +0 -0
- package/public/media/seafile-editor-font/iconfont.woff +0 -0
- package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
- package/public/media/seafile-editor-font.css +201 -0
- package/public/media/seafile-logo.png +0 -0
- package/public/media/seafile-ui.css +11169 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import Prism from 'prismjs';
|
|
7
|
+
import MarkUtils from './mark-utils';
|
|
8
|
+
import BlockElementUtils from './block-element-utils';
|
|
9
|
+
import InlineElementUtils from './inline-element-utils';
|
|
10
|
+
import ListUtils from '../editor-utils/block-element-utils/list-utils';
|
|
11
|
+
import TableUtils from '../editor-utils/block-element-utils/table-utils';
|
|
12
|
+
import CodeUtils from '../editor-utils/block-element-utils/code-utils';
|
|
13
|
+
import FormulaUtils from '../editor-utils/block-element-utils/formula-utils';
|
|
14
|
+
import BlockquoteUtils from '../editor-utils/block-element-utils/blockquote-utils';
|
|
15
|
+
import Link from '../editor-component/link';
|
|
16
|
+
import Image from '../editor-component/image';
|
|
17
|
+
import CheckListItem from '../editor-component/check-list-item';
|
|
18
|
+
import CodeBlock from '../editor-component/code-block';
|
|
19
|
+
import Formula from '../editor-component/formula';
|
|
20
|
+
import TableContainer from '../editor-component/table';
|
|
21
|
+
import { useSelected } from '@seafile/slate-react';
|
|
22
|
+
import { Node, Path } from 'slate';
|
|
23
|
+
|
|
24
|
+
function WithSelectedState(props) {
|
|
25
|
+
var isSelected = useSelected();
|
|
26
|
+
var SlateNode = props.SlateNode;
|
|
27
|
+
return /*#__PURE__*/React.createElement(SlateNode, {
|
|
28
|
+
editor: props.editor,
|
|
29
|
+
attributes: props.attributes,
|
|
30
|
+
children: props.children,
|
|
31
|
+
isSelected: isSelected,
|
|
32
|
+
node: props.element
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function renderNode(props, editor) {
|
|
37
|
+
var attributes = props.attributes,
|
|
38
|
+
children = props.children,
|
|
39
|
+
node = props.element;
|
|
40
|
+
|
|
41
|
+
switch (node.type) {
|
|
42
|
+
case 'paragraph':
|
|
43
|
+
return /*#__PURE__*/React.createElement("p", attributes, children);
|
|
44
|
+
|
|
45
|
+
case 'header_one':
|
|
46
|
+
return /*#__PURE__*/React.createElement("h1", Object.assign({}, attributes, {
|
|
47
|
+
id: 'user-content-' + node.children[0].text
|
|
48
|
+
}), children);
|
|
49
|
+
|
|
50
|
+
case 'header_two':
|
|
51
|
+
return /*#__PURE__*/React.createElement("h2", Object.assign({}, attributes, {
|
|
52
|
+
id: 'user-content-' + node.children[0].text
|
|
53
|
+
}), children);
|
|
54
|
+
|
|
55
|
+
case 'header_three':
|
|
56
|
+
return /*#__PURE__*/React.createElement("h3", Object.assign({}, attributes, {
|
|
57
|
+
id: 'user-content-' + node.children[0].text
|
|
58
|
+
}), children);
|
|
59
|
+
|
|
60
|
+
case 'header_four':
|
|
61
|
+
return /*#__PURE__*/React.createElement("h4", attributes, children);
|
|
62
|
+
|
|
63
|
+
case 'header_five':
|
|
64
|
+
return /*#__PURE__*/React.createElement("h5", attributes, children);
|
|
65
|
+
|
|
66
|
+
case 'header_six':
|
|
67
|
+
return /*#__PURE__*/React.createElement("h6", attributes, children);
|
|
68
|
+
|
|
69
|
+
case 'link':
|
|
70
|
+
return /*#__PURE__*/React.createElement(Link, {
|
|
71
|
+
attributes: attributes,
|
|
72
|
+
children: children,
|
|
73
|
+
node: node
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
case 'image':
|
|
77
|
+
return /*#__PURE__*/React.createElement(WithSelectedState, Object.assign({}, props, {
|
|
78
|
+
SlateNode: Image
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
case 'blockquote':
|
|
82
|
+
return /*#__PURE__*/React.createElement("blockquote", attributes, children);
|
|
83
|
+
|
|
84
|
+
case 'list_item':
|
|
85
|
+
var checked = node.data.checked;
|
|
86
|
+
if (checked === undefined) return /*#__PURE__*/React.createElement("li", attributes, children);
|
|
87
|
+
return /*#__PURE__*/React.createElement(CheckListItem, Object.assign({
|
|
88
|
+
editor: editor
|
|
89
|
+
}, props));
|
|
90
|
+
|
|
91
|
+
case 'code_block':
|
|
92
|
+
return /*#__PURE__*/React.createElement(WithSelectedState, Object.assign({}, props, {
|
|
93
|
+
editor: editor,
|
|
94
|
+
SlateNode: CodeBlock
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
case 'code_line':
|
|
98
|
+
return /*#__PURE__*/React.createElement("p", attributes, children);
|
|
99
|
+
|
|
100
|
+
case 'unordered_list':
|
|
101
|
+
return /*#__PURE__*/React.createElement("ul", attributes, children);
|
|
102
|
+
|
|
103
|
+
case 'ordered_list':
|
|
104
|
+
return /*#__PURE__*/React.createElement("ol", attributes, children);
|
|
105
|
+
|
|
106
|
+
case 'table':
|
|
107
|
+
return /*#__PURE__*/React.createElement(TableContainer, Object.assign({
|
|
108
|
+
editor: editor
|
|
109
|
+
}, props));
|
|
110
|
+
|
|
111
|
+
case 'table_row':
|
|
112
|
+
return /*#__PURE__*/React.createElement("tr", attributes, children);
|
|
113
|
+
|
|
114
|
+
case 'table_cell':
|
|
115
|
+
var align = node.data.align;
|
|
116
|
+
align = ['left', 'right', 'center'].find(function (item) {
|
|
117
|
+
return item === align;
|
|
118
|
+
}) ? align : 'left';
|
|
119
|
+
return /*#__PURE__*/React.createElement("td", Object.assign({
|
|
120
|
+
style: {
|
|
121
|
+
textAlign: align
|
|
122
|
+
}
|
|
123
|
+
}, attributes), children);
|
|
124
|
+
|
|
125
|
+
case 'formula':
|
|
126
|
+
return /*#__PURE__*/React.createElement(WithSelectedState, Object.assign({}, props, {
|
|
127
|
+
editor: editor,
|
|
128
|
+
SlateNode: Formula
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
return /*#__PURE__*/React.createElement("p", attributes, children);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var renderLeaf = function renderLeaf(_ref) {
|
|
137
|
+
var attributes = _ref.attributes,
|
|
138
|
+
children = _ref.children,
|
|
139
|
+
leaf = _ref.leaf;
|
|
140
|
+
var markedChildren = React.cloneElement(children);
|
|
141
|
+
|
|
142
|
+
if (leaf.BOLD) {
|
|
143
|
+
markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (leaf.CODE) {
|
|
147
|
+
markedChildren = /*#__PURE__*/React.createElement("code", null, markedChildren);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (leaf.ITALIC) {
|
|
151
|
+
markedChildren = /*#__PURE__*/React.createElement("i", null, markedChildren);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (leaf.DELETE) {
|
|
155
|
+
markedChildren = /*#__PURE__*/React.createElement("del", null, markedChildren);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (leaf.ADD) {
|
|
159
|
+
markedChildren = /*#__PURE__*/React.createElement("ins", null, markedChildren);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (leaf.decoration) {
|
|
163
|
+
markedChildren = /*#__PURE__*/React.createElement("span", {
|
|
164
|
+
className: "token ".concat(leaf.type)
|
|
165
|
+
}, markedChildren);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return /*#__PURE__*/React.createElement("span", attributes, markedChildren);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
var decorationNode = function decorationNode(_ref2) {
|
|
172
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
173
|
+
node = _ref3[0],
|
|
174
|
+
path = _ref3[1];
|
|
175
|
+
|
|
176
|
+
if (node.type !== 'code_block') return [];
|
|
177
|
+
var languageType = node.data.syntax;
|
|
178
|
+
if (languageType === 'none') return [];
|
|
179
|
+
var grammer = Prism.languages[languageType];
|
|
180
|
+
var codeLines = node.children;
|
|
181
|
+
|
|
182
|
+
if (!grammer) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var blockText = codeLines.map(function (codeLine) {
|
|
187
|
+
return codeLine.children[0].text;
|
|
188
|
+
}).join('\n');
|
|
189
|
+
var tokens = Prism.tokenize(blockText, grammer);
|
|
190
|
+
var decorations = [];
|
|
191
|
+
var textLine = 0;
|
|
192
|
+
var offset = 0;
|
|
193
|
+
|
|
194
|
+
var _iterator = _createForOfIteratorHelper(tokens),
|
|
195
|
+
_step;
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
199
|
+
var token = _step.value;
|
|
200
|
+
|
|
201
|
+
if (typeof token === 'string' && token.indexOf('\n') >= 0) {
|
|
202
|
+
//the varialble enterNum is the num of \n in the token
|
|
203
|
+
// get the number of \n buy split the token by '\n'
|
|
204
|
+
var newlineTokens = token.split('\n');
|
|
205
|
+
var enterNum = newlineTokens.length - 1; // get the next code_line which the content of is is not ' ' or null;
|
|
206
|
+
|
|
207
|
+
textLine += enterNum; // get the initial offset of the code_line
|
|
208
|
+
|
|
209
|
+
offset = newlineTokens.pop().length;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (typeof token === 'string') {
|
|
214
|
+
var textPath = path.slice();
|
|
215
|
+
textPath.push(textLine, 0);
|
|
216
|
+
var decoration = {
|
|
217
|
+
anchor: {
|
|
218
|
+
path: textPath,
|
|
219
|
+
offset: offset
|
|
220
|
+
},
|
|
221
|
+
focus: {
|
|
222
|
+
path: textPath,
|
|
223
|
+
offset: offset + token.length
|
|
224
|
+
},
|
|
225
|
+
type: 'text'
|
|
226
|
+
};
|
|
227
|
+
decorations.push(decoration);
|
|
228
|
+
offset += token.length;
|
|
229
|
+
} else if (typeof token.content === 'string') {
|
|
230
|
+
var _textPath = path.slice();
|
|
231
|
+
|
|
232
|
+
_textPath.push(textLine, 0);
|
|
233
|
+
|
|
234
|
+
var _decoration = {
|
|
235
|
+
anchor: {
|
|
236
|
+
path: _textPath,
|
|
237
|
+
offset: offset
|
|
238
|
+
},
|
|
239
|
+
focus: {
|
|
240
|
+
path: _textPath,
|
|
241
|
+
offset: offset + token.content.length
|
|
242
|
+
},
|
|
243
|
+
decoration: true,
|
|
244
|
+
type: token.type
|
|
245
|
+
};
|
|
246
|
+
decorations.push(_decoration);
|
|
247
|
+
offset += token.content.length;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} catch (err) {
|
|
251
|
+
_iterator.e(err);
|
|
252
|
+
} finally {
|
|
253
|
+
_iterator.f();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return decorations;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
var EditorUtils = /*#__PURE__*/function () {
|
|
260
|
+
function EditorUtils(editor) {
|
|
261
|
+
var _this = this;
|
|
262
|
+
|
|
263
|
+
_classCallCheck(this, EditorUtils);
|
|
264
|
+
|
|
265
|
+
this.onClickMark = function (event, type) {
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
|
|
268
|
+
_this.markUtils.setMark(type);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
this.onClickHeader = function (event, type) {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
|
|
274
|
+
_this.editor.exec({
|
|
275
|
+
type: 'set_header',
|
|
276
|
+
headerType: type
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
this.onClickBlock = function (event, type) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
|
|
283
|
+
if (!_this.blockElementUtils.isBlockActive(type)) {
|
|
284
|
+
_this.editor.exec({
|
|
285
|
+
type: "set_".concat(type)
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
_this.editor.exec({
|
|
289
|
+
type: "unwrap_".concat(type)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
this.onClickBlock = function (event, type) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
|
|
297
|
+
if (type === 'blockquote') {
|
|
298
|
+
if (_this.blockquoteUtils.isInBlockquote()) {
|
|
299
|
+
_this.editor.exec({
|
|
300
|
+
type: 'unwrap_blockquote'
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
_this.editor.exec({
|
|
304
|
+
type: 'set_blockquote'
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (type === 'code_block') {
|
|
310
|
+
if (_this.codeUtils.isInCodeBlock()) {
|
|
311
|
+
_this.editor.exec({
|
|
312
|
+
type: 'unwrap_code_block'
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
_this.editor.exec({
|
|
316
|
+
type: 'set_code_block'
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (type === 'ordered_list' || type === 'unordered_list') {
|
|
322
|
+
if (_this.listUtils.isInlist()) {
|
|
323
|
+
var items = _this.listUtils.getCurrentListItem();
|
|
324
|
+
|
|
325
|
+
var item = items[0];
|
|
326
|
+
var currentList = Node.parent(_this.editor, item[1]);
|
|
327
|
+
|
|
328
|
+
if (currentList.type === type) {
|
|
329
|
+
if (typeof item[0].data.checked === 'boolean') {
|
|
330
|
+
_this.editor.exec({
|
|
331
|
+
type: 'unwrap_check_list_item'
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
_this.editor.exec({
|
|
338
|
+
type: "unwrap_".concat(currentList.type)
|
|
339
|
+
});
|
|
340
|
+
} else {
|
|
341
|
+
var currentListPath = Path.parent(item[1]);
|
|
342
|
+
var listAncesstor = Node.get(_this.editor, Path.parent(currentListPath)); // if the current selected list is a children of a different kind of list prevent modify the list type
|
|
343
|
+
|
|
344
|
+
if (listAncesstor.type && listAncesstor.type.includes('list')) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
_this.editor.exec({
|
|
349
|
+
type: "unwrap_".concat(currentList.type)
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
_this.editor.exec({
|
|
353
|
+
type: "set_".concat(type)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
_this.editor.exec({
|
|
358
|
+
type: "set_".concat(type)
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
this.unwrapLink = function () {
|
|
365
|
+
_this.inlineElementUtils.unwrapLink();
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
this.isLinkActive = function () {
|
|
369
|
+
return _this.inlineElementUtils.isLinkActive();
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
this.getLinkText = function (linkNode) {
|
|
373
|
+
return _this.inlineElementUtils.getLinkText(linkNode);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
this.insertLink = function (elementData) {
|
|
377
|
+
return _this.inlineElementUtils.insertLink(elementData);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
this.setLink = function (elementData) {
|
|
381
|
+
return _this.inlineElementUtils.setLink(elementData);
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
this.getSelectedText = function () {
|
|
385
|
+
var selection = window.getSelection();
|
|
386
|
+
var range = selection.getRangeAt(0);
|
|
387
|
+
return range.toString();
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
this.insertImage = function (data) {
|
|
391
|
+
_this.inlineElementUtils.insertImage(data);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
this.getCurrentLinkNode = function () {
|
|
395
|
+
return _this.inlineElementUtils.getCurrentLinkNode();
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
this.onToggleCheckItem = function (event) {
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
|
|
401
|
+
if (_this.listUtils.isInlist()) {
|
|
402
|
+
var items = _this.listUtils.getCurrentListItem();
|
|
403
|
+
|
|
404
|
+
var item = items[0];
|
|
405
|
+
|
|
406
|
+
if (typeof item[0].data.checked === 'boolean') {
|
|
407
|
+
_this.editor.exec({
|
|
408
|
+
type: 'unwrap_check_list_item'
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
_this.editor.exec({
|
|
416
|
+
type: 'wrap_check_list_item'
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
this.onAddTable = function (event) {
|
|
421
|
+
event.preventDefault();
|
|
422
|
+
|
|
423
|
+
_this.editor.exec({
|
|
424
|
+
type: 'insert_table'
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
this.onAddFormula = function (data) {
|
|
429
|
+
_this.editor.exec({
|
|
430
|
+
type: 'insert_formula',
|
|
431
|
+
data: data
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
this.setFormula = function (data) {
|
|
436
|
+
_this.editor.exec({
|
|
437
|
+
type: 'set_formula',
|
|
438
|
+
data: data
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
this.onRemoveTable = function (event) {
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
|
|
445
|
+
_this.editor.exec({
|
|
446
|
+
type: 'remove_table'
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
this.onInsertColumn = function (event) {
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
|
|
453
|
+
_this.editor.exec({
|
|
454
|
+
type: 'insert_column'
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
this.onRemoveColumn = function (event) {
|
|
459
|
+
event.preventDefault();
|
|
460
|
+
|
|
461
|
+
_this.editor.exec({
|
|
462
|
+
type: 'remove_column'
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
this.onInsertRow = function (event) {
|
|
467
|
+
event.preventDefault();
|
|
468
|
+
|
|
469
|
+
_this.editor.exec({
|
|
470
|
+
type: 'insert_row'
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
this.onRemoveRow = function (event) {
|
|
475
|
+
event.preventDefault();
|
|
476
|
+
|
|
477
|
+
_this.editor.exec({
|
|
478
|
+
type: 'remove_row'
|
|
479
|
+
});
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
this.onSetAlign = function (event, align) {
|
|
483
|
+
event.preventDefault();
|
|
484
|
+
|
|
485
|
+
_this.editor.exec({
|
|
486
|
+
type: 'set_table_cell_align',
|
|
487
|
+
align: align
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
this.adjustImageSize = function (options) {
|
|
492
|
+
return _this.inineElementUtils.adjustImageSize(options);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
this.editor = editor;
|
|
496
|
+
this.markUtils = new MarkUtils(editor);
|
|
497
|
+
this.blockElementUtils = new BlockElementUtils(editor);
|
|
498
|
+
this.inlineElementUtils = new InlineElementUtils(editor);
|
|
499
|
+
this.listUtils = new ListUtils(editor);
|
|
500
|
+
this.tableUtils = new TableUtils(editor);
|
|
501
|
+
this.codeUtils = new CodeUtils(editor);
|
|
502
|
+
this.blockquoteUtils = new BlockquoteUtils(editor);
|
|
503
|
+
this.formulaUtils = new FormulaUtils(editor);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
_createClass(EditorUtils, [{
|
|
507
|
+
key: "getToolbarStatus",
|
|
508
|
+
value: // set is Active of each button
|
|
509
|
+
function getToolbarStatus() {
|
|
510
|
+
var selection = this.editor.selection;
|
|
511
|
+
var toolbarStatus = {
|
|
512
|
+
headerType: 'paragraph'
|
|
513
|
+
};
|
|
514
|
+
if (!selection) return toolbarStatus;
|
|
515
|
+
var activeHeader = this.blockElementUtils.getActiveHeader([{
|
|
516
|
+
type: 'paragraph'
|
|
517
|
+
}, {
|
|
518
|
+
type: 'header_one'
|
|
519
|
+
}, {
|
|
520
|
+
type: 'header_two'
|
|
521
|
+
}, {
|
|
522
|
+
type: 'header_three'
|
|
523
|
+
}, {
|
|
524
|
+
type: 'header_four'
|
|
525
|
+
}, {
|
|
526
|
+
type: 'header_five'
|
|
527
|
+
}, {
|
|
528
|
+
type: 'header_six'
|
|
529
|
+
}]);
|
|
530
|
+
var isLinkActive = this.isLinkActive();
|
|
531
|
+
var isBlockquoteActive = this.blockquoteUtils.isInBlockquote();
|
|
532
|
+
var isCodeActive = this.codeUtils.isInCodeBlock();
|
|
533
|
+
var isTableActive = this.tableUtils.isInTable();
|
|
534
|
+
var block = activeHeader[0];
|
|
535
|
+
var activeMarks = this.markUtils.getActiveMarks();
|
|
536
|
+
var isCheckListActive = false;
|
|
537
|
+
var isOrderedListActive = false;
|
|
538
|
+
var isUnorderedListActive = false;
|
|
539
|
+
var isSelectedInList = this.listUtils.isInlist();
|
|
540
|
+
|
|
541
|
+
if (isSelectedInList) {
|
|
542
|
+
var items = this.listUtils.getCurrentListItem();
|
|
543
|
+
var item = items[0];
|
|
544
|
+
|
|
545
|
+
if (item[0].data && typeof item[0].data.checked === 'boolean') {
|
|
546
|
+
isCheckListActive = true;
|
|
547
|
+
isUnorderedListActive = false;
|
|
548
|
+
} else {
|
|
549
|
+
var currentList = Node.parent(this.editor, item[1]);
|
|
550
|
+
var listType = currentList.type;
|
|
551
|
+
|
|
552
|
+
if (listType === 'unordered_list') {
|
|
553
|
+
isUnorderedListActive = true;
|
|
554
|
+
} else {
|
|
555
|
+
isOrderedListActive = true;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
toolbarStatus = {
|
|
561
|
+
headerType: block.type,
|
|
562
|
+
isBoldActive: activeMarks.BOLD,
|
|
563
|
+
isItalicActive: activeMarks.ITALIC,
|
|
564
|
+
isInlineCodeActive: activeMarks.CODE,
|
|
565
|
+
isLinkActive: isLinkActive,
|
|
566
|
+
isBlockquoteActive: isBlockquoteActive,
|
|
567
|
+
isOrderedListActive: isOrderedListActive,
|
|
568
|
+
isUnorderedListActive: isUnorderedListActive,
|
|
569
|
+
isCheckListActive: isCheckListActive,
|
|
570
|
+
isCodeActive: isCodeActive,
|
|
571
|
+
isTableActive: isTableActive
|
|
572
|
+
};
|
|
573
|
+
var isFormulaActive = false;
|
|
574
|
+
|
|
575
|
+
if (window.canInsertFormula) {
|
|
576
|
+
isFormulaActive = this.formulaUtils.isFormulaActive();
|
|
577
|
+
toolbarStatus.isFormulaActive = isFormulaActive;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return toolbarStatus;
|
|
581
|
+
}
|
|
582
|
+
}]);
|
|
583
|
+
|
|
584
|
+
return EditorUtils;
|
|
585
|
+
}();
|
|
586
|
+
|
|
587
|
+
export { renderNode, renderLeaf, EditorUtils, decorationNode };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import { Editor } from 'slate';
|
|
5
|
+
|
|
6
|
+
var InlineElementUtils = /*#__PURE__*/function () {
|
|
7
|
+
function InlineElementUtils(editor) {
|
|
8
|
+
var _this = this;
|
|
9
|
+
|
|
10
|
+
_classCallCheck(this, InlineElementUtils);
|
|
11
|
+
|
|
12
|
+
this.isLinkActive = function () {
|
|
13
|
+
var _Editor$nodes = Editor.nodes(_this.editor, {
|
|
14
|
+
match: {
|
|
15
|
+
type: 'link'
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
19
|
+
link = _Editor$nodes2[0];
|
|
20
|
+
|
|
21
|
+
return !!link;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.getLinkText = function (linkNode) {
|
|
25
|
+
var linkText = '';
|
|
26
|
+
linkNode.children.forEach(function (textNode) {
|
|
27
|
+
linkText += textNode.text;
|
|
28
|
+
});
|
|
29
|
+
return linkText;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
this.getCurrentLinkNode = function () {
|
|
33
|
+
var _Editor$nodes3 = Editor.nodes(_this.editor, {
|
|
34
|
+
match: {
|
|
35
|
+
type: 'link'
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
_Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
|
|
39
|
+
link = _Editor$nodes4[0];
|
|
40
|
+
|
|
41
|
+
if (link) {
|
|
42
|
+
return link[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
this.unwrapLink = function () {
|
|
49
|
+
_this.editor.exec({
|
|
50
|
+
type: 'unwrap_link'
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
this.insertLink = function (elementData) {
|
|
55
|
+
_this.editor.exec({
|
|
56
|
+
type: 'insert_link_at_selection',
|
|
57
|
+
elementData: elementData
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
this.setLink = function (elementData) {
|
|
62
|
+
_this.editor.exec({
|
|
63
|
+
type: 'set_link',
|
|
64
|
+
elementData: elementData
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
this.insertImage = function (data) {
|
|
69
|
+
_this.editor.exec({
|
|
70
|
+
type: 'insert_image_at_selection',
|
|
71
|
+
data: {
|
|
72
|
+
src: data.url
|
|
73
|
+
},
|
|
74
|
+
at: data.selection
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
this.editor = editor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_createClass(InlineElementUtils, [{
|
|
82
|
+
key: "adjustImageSize",
|
|
83
|
+
value: function adjustImageSize(options) {
|
|
84
|
+
var data = Object.assign({}, {}, options);
|
|
85
|
+
this.editor.exec({
|
|
86
|
+
type: 'set_image',
|
|
87
|
+
data: data
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}]);
|
|
91
|
+
|
|
92
|
+
return InlineElementUtils;
|
|
93
|
+
}();
|
|
94
|
+
|
|
95
|
+
export default InlineElementUtils;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import { Editor } from 'slate';
|
|
4
|
+
|
|
5
|
+
var MarkUtils = function MarkUtils(editor) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
|
|
8
|
+
_classCallCheck(this, MarkUtils);
|
|
9
|
+
|
|
10
|
+
this.getActiveMarks = function () {
|
|
11
|
+
var marks = Editor.marks(_this.editor);
|
|
12
|
+
return marks;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
this.setMark = function (type) {
|
|
16
|
+
_this.editor.exec({
|
|
17
|
+
type: 'format_text',
|
|
18
|
+
properties: _defineProperty({}, type, true)
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
this.editor = editor;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default MarkUtils;
|