@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,249 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import isHotKey from 'is-hotkey';
|
|
4
|
+
import { Range, Editor, Path, Node } from 'slate';
|
|
5
|
+
import ListUtils from './editor-utils/block-element-utils/list-utils';
|
|
6
|
+
import CodeUtils from './editor-utils/block-element-utils/code-utils';
|
|
7
|
+
import TableUtils from './editor-utils/block-element-utils/table-utils';
|
|
8
|
+
import setEventTransfer from './custom/set-event-transfer';
|
|
9
|
+
import { SfEditor } from '../editor/custom/custom';
|
|
10
|
+
|
|
11
|
+
var Plugin = function Plugin(_editor) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
|
|
14
|
+
_classCallCheck(this, Plugin);
|
|
15
|
+
|
|
16
|
+
this.onKeyDown = function (event) {
|
|
17
|
+
if (event.nativeEvent.keyCode === 13) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
|
|
20
|
+
if (isHotKey('shift+enter', event)) {
|
|
21
|
+
if (_this.listUtils.isInlist()) {
|
|
22
|
+
_this.editor.exec({
|
|
23
|
+
type: 'split_list_item'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
} else if (isHotKey('mod+enter', event)) {
|
|
27
|
+
if (_this.codeUtils.isInCodeBlock()) {
|
|
28
|
+
_this.editor.exec({
|
|
29
|
+
type: 'exit_code_block'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (_this.tableUtils.isInTable()) {
|
|
34
|
+
_this.editor.exec({
|
|
35
|
+
type: 'exit_table'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
_this.editor.exec({
|
|
40
|
+
type: 'insert_break'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isHotKey('shift+tab', event)) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
|
|
48
|
+
if (_this.listUtils.isInlist()) {
|
|
49
|
+
var _Editor$nodes = Editor.nodes(_this.editor, {
|
|
50
|
+
match: [{
|
|
51
|
+
type: 'unordered_list'
|
|
52
|
+
}, {
|
|
53
|
+
type: 'ordered_list'
|
|
54
|
+
}],
|
|
55
|
+
at: _this.editor.selection,
|
|
56
|
+
mode: 'highest'
|
|
57
|
+
}),
|
|
58
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
59
|
+
listNode = _Editor$nodes2[0];
|
|
60
|
+
|
|
61
|
+
if (!listNode) return;
|
|
62
|
+
var type = listNode[0].type;
|
|
63
|
+
|
|
64
|
+
_this.editor.exec({
|
|
65
|
+
type: "unwrap_".concat(type)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (isHotKey('mod+s', event)) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
_this.editor.onSave && _this.editor.onSave();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isHotKey('tab', event) && Range.isCollapsed(_this.editor.selection)) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
|
|
78
|
+
if (_this.codeUtils.isInCodeBlock()) {
|
|
79
|
+
_this.editor.exec({
|
|
80
|
+
type: 'increase_code_block_indent'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (_this.listUtils.isInlist()) {
|
|
85
|
+
_this.editor.exec({
|
|
86
|
+
type: 'increase_list_item_depth'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isHotKey('mod+b', event)) {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
|
|
94
|
+
if (!_this.codeUtils.isInCodeBlock()) {
|
|
95
|
+
_this.editor.exec({
|
|
96
|
+
type: 'format_text',
|
|
97
|
+
properties: {
|
|
98
|
+
BOLD: true
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (isHotKey('mod+i', event)) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
|
|
107
|
+
if (!_this.codeUtils.isInCodeBlock()) {
|
|
108
|
+
_this.editor.exec({
|
|
109
|
+
type: 'format_text',
|
|
110
|
+
properties: {
|
|
111
|
+
ITALIC: true
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (isHotKey('mod+/', event)) {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
|
|
120
|
+
if (!_this.codeUtils.isInCodeBlock()) {
|
|
121
|
+
_this.editor.exec({
|
|
122
|
+
type: 'format_text',
|
|
123
|
+
properties: {
|
|
124
|
+
CODE: true
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (isHotKey('mod+4', {
|
|
131
|
+
byKey: true
|
|
132
|
+
})(event)) {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
window.richMarkdownEditor.onToggleFormulaDialog();
|
|
135
|
+
return;
|
|
136
|
+
} // compate chrome: in chrome press backspace would not exec delete_backward command
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if (isHotKey('backspace', event)) {
|
|
140
|
+
var voidNode = SfEditor.match(_this.editor, _this.editor.selection, 'void');
|
|
141
|
+
|
|
142
|
+
if (voidNode && (voidNode[0].type === 'image' || voidNode[0].type === 'formula')) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
|
|
145
|
+
_this.editor.exec({
|
|
146
|
+
type: 'delete_backward',
|
|
147
|
+
unit: 'character'
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (isHotKey('mod+a', event)) {
|
|
155
|
+
if (_this.codeUtils.isInCodeBlock()) {
|
|
156
|
+
var anchorPoint = _this.editor.selection.anchor;
|
|
157
|
+
var focusPoint = _this.editor.selection.focus;
|
|
158
|
+
var anchorCodeBlock = Editor.match(_this.editor, anchorPoint, {
|
|
159
|
+
type: 'code_block'
|
|
160
|
+
});
|
|
161
|
+
var focusCodeBlock = Editor.match(_this.editor, focusPoint, {
|
|
162
|
+
type: 'code_block'
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (anchorCodeBlock && focusCodeBlock && Path.equals(focusCodeBlock[1], anchorCodeBlock[1])) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
Editor.select(_this.editor, focusCodeBlock[1]);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
this.onCut = function (event, editor) {
|
|
175
|
+
var image = SfEditor.match(_this.editor, _this.editor.selection, {
|
|
176
|
+
type: 'image'
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (image) {
|
|
180
|
+
// write the image element to clipboard
|
|
181
|
+
setEventTransfer(event, 'fragment', [{
|
|
182
|
+
type: 'paragraph',
|
|
183
|
+
children: [image[0]]
|
|
184
|
+
}]); // remove the image element when cut an image due to slate did not has the action when cut a image
|
|
185
|
+
|
|
186
|
+
_this.editor.exec({
|
|
187
|
+
type: 'delete_backward',
|
|
188
|
+
unit: 'character'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
this.onCopy = function (event, editor) {
|
|
196
|
+
if (_this.tableUtils.isInTable()) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
|
|
199
|
+
var table = _this.tableUtils.getSelectedTableCells();
|
|
200
|
+
|
|
201
|
+
if (!table) {
|
|
202
|
+
setEventTransfer(event, 'text', SfEditor.text(editor, editor.selection));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setEventTransfer(event, 'fragment', table);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (_this.codeUtils.isInCodeBlock() && !Range.isCollapsed(editor.selection)) {
|
|
211
|
+
var anchorPoint = editor.selection.anchor;
|
|
212
|
+
var focusPoint = editor.selection.focus;
|
|
213
|
+
var anchorCodeBlock = Editor.match(_this.editor, anchorPoint, {
|
|
214
|
+
type: 'code_block'
|
|
215
|
+
});
|
|
216
|
+
var focusCodeBlock = Editor.match(_this.editor, focusPoint, {
|
|
217
|
+
type: 'code_block'
|
|
218
|
+
});
|
|
219
|
+
/*
|
|
220
|
+
If the selection is within the range of the selected code block
|
|
221
|
+
copy the selected code line as paragraph
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
if (anchorCodeBlock && focusCodeBlock && Path.equals(focusCodeBlock[1], anchorCodeBlock[1])) {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
var fragment = Node.fragment(editor, editor.selection);
|
|
227
|
+
fragment = fragment[0].children.map(function (codeLine) {
|
|
228
|
+
var text = Node.text(codeLine);
|
|
229
|
+
return {
|
|
230
|
+
type: 'paragraph',
|
|
231
|
+
children: [{
|
|
232
|
+
text: text
|
|
233
|
+
}]
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
setEventTransfer(event, 'fragment', fragment);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
this.editor = _editor;
|
|
243
|
+
this.listUtils = new ListUtils(_editor);
|
|
244
|
+
this.codeUtils = new CodeUtils(_editor);
|
|
245
|
+
this.tableUtils = new TableUtils(_editor);
|
|
246
|
+
this.onSave = _editor.onSave;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export default Plugin;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import { SfEditor } from '../../custom/custom';
|
|
3
|
+
import { Node } from 'slate';
|
|
4
|
+
import generateBlockquote from '../../element-model/blockquote';
|
|
5
|
+
import getEventTransfer from '../../custom/get-event-transfer';
|
|
6
|
+
import { htmlDeserializer } from '../../../utils/deserialize-html';
|
|
7
|
+
import { normailizeSelection } from '../selection-utils';
|
|
8
|
+
|
|
9
|
+
var BlockquoteUtils = function BlockquoteUtils(editor) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
|
|
12
|
+
_classCallCheck(this, BlockquoteUtils);
|
|
13
|
+
|
|
14
|
+
this.getCurrentBlockquote = function () {
|
|
15
|
+
var block = SfEditor.match(_this.editor, _this.editor.selection.anchor, 'block');
|
|
16
|
+
var blockPath = block[1];
|
|
17
|
+
var parent = Node.parent(_this.editor, blockPath);
|
|
18
|
+
|
|
19
|
+
if (parent && parent.type === 'blockquote') {
|
|
20
|
+
return parent;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.isInBlockquote = function () {
|
|
27
|
+
return Boolean(_this.getCurrentBlockquote());
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.wrapBlockquote = function () {
|
|
31
|
+
normailizeSelection(_this.editor);
|
|
32
|
+
var selection = _this.editor.selection;
|
|
33
|
+
var currentPath = SfEditor.path(_this.editor, selection);
|
|
34
|
+
var outestElementAtPath = _this.editor.children[currentPath[0]];
|
|
35
|
+
var blockquote = generateBlockquote({
|
|
36
|
+
children: [outestElementAtPath]
|
|
37
|
+
});
|
|
38
|
+
SfEditor.wrapNodes(_this.editor, blockquote);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
this.unwrapBlockquote = function () {
|
|
42
|
+
normailizeSelection(_this.editor);
|
|
43
|
+
SfEditor.unwrapNodes(_this.editor, {
|
|
44
|
+
split: true,
|
|
45
|
+
match: {
|
|
46
|
+
type: 'blockquote'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.pasteContentInBlockquote = function (command) {
|
|
52
|
+
var data = command.data;
|
|
53
|
+
|
|
54
|
+
var _getEventTransfer = getEventTransfer(data),
|
|
55
|
+
fragment = _getEventTransfer.fragment,
|
|
56
|
+
text = _getEventTransfer.text,
|
|
57
|
+
type = _getEventTransfer.type,
|
|
58
|
+
html = _getEventTransfer.html;
|
|
59
|
+
|
|
60
|
+
if (type === 'text') {
|
|
61
|
+
var textArray = text.split(/\r\n|\n/g);
|
|
62
|
+
textArray.forEach(function (text, index) {
|
|
63
|
+
if (index === 0) {
|
|
64
|
+
SfEditor.insertText(_this.editor, text);
|
|
65
|
+
} else {
|
|
66
|
+
SfEditor.insertNodes(_this.editor, {
|
|
67
|
+
type: 'paragraph',
|
|
68
|
+
children: [{
|
|
69
|
+
text: text
|
|
70
|
+
}]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (type === 'html') {
|
|
78
|
+
fragment = htmlDeserializer(html);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var block = SfEditor.match(_this.editor, _this.editor.selection, 'block');
|
|
82
|
+
|
|
83
|
+
if (Node.text(block[0]).length === 0) {
|
|
84
|
+
SfEditor.removeNodes(_this.editor, {
|
|
85
|
+
match: 'block'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
SfEditor.insertNodes(_this.editor, fragment);
|
|
90
|
+
return;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
this.editor = editor;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default BlockquoteUtils;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import { SfEditor } from '../../custom/custom';
|
|
5
|
+
import { Node } from 'slate';
|
|
6
|
+
import detectIndent from 'detect-indent';
|
|
7
|
+
import getEventTransfer from '../../custom/get-event-transfer';
|
|
8
|
+
import { normailizeSelection } from '../selection-utils';
|
|
9
|
+
|
|
10
|
+
var CodeUtils = /*#__PURE__*/function () {
|
|
11
|
+
function CodeUtils(editor) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
|
|
14
|
+
_classCallCheck(this, CodeUtils);
|
|
15
|
+
|
|
16
|
+
this.isInCodeBlock = function () {
|
|
17
|
+
var block = SfEditor.match(_this.editor, _this.editor.selection.anchor, 'block');
|
|
18
|
+
var blockParent = Node.parent(_this.editor, block[1]);
|
|
19
|
+
if (blockParent.type === 'code_block') return true;
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.getIndent = function (text) {
|
|
24
|
+
return detectIndent(text).indent;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
this.insertIndent = function (indent) {
|
|
28
|
+
SfEditor.insertText(_this.editor, indent, {
|
|
29
|
+
at: _this.editor.selection
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
this.wrapCodeBlock = function () {
|
|
34
|
+
normailizeSelection(_this.editor);
|
|
35
|
+
SfEditor.setNodes(_this.editor, {
|
|
36
|
+
type: 'code_line'
|
|
37
|
+
}, {
|
|
38
|
+
match: 'block',
|
|
39
|
+
at: _this.editor.selection
|
|
40
|
+
});
|
|
41
|
+
SfEditor.wrapNodes(_this.editor, {
|
|
42
|
+
type: 'code_block',
|
|
43
|
+
children: [],
|
|
44
|
+
data: {}
|
|
45
|
+
});
|
|
46
|
+
SfEditor.collapse(_this.editor, {
|
|
47
|
+
edge: 'end'
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.splitCodeLine = function () {
|
|
52
|
+
var block = SfEditor.match(_this.editor, _this.editor.selection, 'block');
|
|
53
|
+
|
|
54
|
+
var indent = _this.getIndent(Node.text(block[0]));
|
|
55
|
+
|
|
56
|
+
SfEditor.splitNodes(_this.editor, {
|
|
57
|
+
split: true,
|
|
58
|
+
always: true,
|
|
59
|
+
at: _this.editor.selection
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
_this.insertIndent(indent);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
this.unwrapCodeBlock = function () {
|
|
66
|
+
var split = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
67
|
+
var codeBlock = SfEditor.match(_this.editor, _this.editor.selection, {
|
|
68
|
+
type: 'code_block'
|
|
69
|
+
});
|
|
70
|
+
var codeBlockPath = codeBlock[1]; // unwrap whole code block
|
|
71
|
+
|
|
72
|
+
if (!split) {
|
|
73
|
+
codeBlock[0].children.forEach(function (codeLine, index) {
|
|
74
|
+
var path = [].concat(_toConsumableArray(codeBlockPath), [index]);
|
|
75
|
+
SfEditor.setNodes(_this.editor, {
|
|
76
|
+
type: 'paragraph'
|
|
77
|
+
}, {
|
|
78
|
+
at: path
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
// unwrap a code line
|
|
83
|
+
SfEditor.setNodes(_this.editor, {
|
|
84
|
+
type: 'paragraph'
|
|
85
|
+
}, {
|
|
86
|
+
at: _this.editor.selection,
|
|
87
|
+
match: 'block'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
SfEditor.unwrapNodesByTypeAtRange(_this.editor, {
|
|
92
|
+
at: _this.editor.selection,
|
|
93
|
+
split: split,
|
|
94
|
+
match: {
|
|
95
|
+
type: 'code_block'
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
this.editor = editor;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_createClass(CodeUtils, [{
|
|
104
|
+
key: "pasteContentInCodeBlock",
|
|
105
|
+
value: function pasteContentInCodeBlock(command) {
|
|
106
|
+
var _this2 = this;
|
|
107
|
+
|
|
108
|
+
var data = command.data;
|
|
109
|
+
|
|
110
|
+
var _getEventTransfer = getEventTransfer(data),
|
|
111
|
+
text = _getEventTransfer.text,
|
|
112
|
+
fragment = _getEventTransfer.fragment,
|
|
113
|
+
type = _getEventTransfer.type;
|
|
114
|
+
|
|
115
|
+
if (text.length === 0) return;
|
|
116
|
+
|
|
117
|
+
if (type === 'text' || type === 'html') {
|
|
118
|
+
var codeLineFragment = text.split(/\r\n|\n/).map(function (textLine) {
|
|
119
|
+
return {
|
|
120
|
+
type: 'code_line',
|
|
121
|
+
children: [{
|
|
122
|
+
text: textLine
|
|
123
|
+
}]
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
SfEditor.insertFragment(this.editor, codeLineFragment);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fragment.map(function (node, index) {
|
|
131
|
+
if (node.type === 'code_block') {
|
|
132
|
+
node.children.forEach(function (codeLine, index1) {
|
|
133
|
+
if (index1 === 0) {
|
|
134
|
+
SfEditor.insertText(_this2.editor, Node.text(codeLine));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
SfEditor.insertNodes(_this2.editor, codeLine);
|
|
139
|
+
});
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (index === 0) {
|
|
144
|
+
SfEditor.insertText(_this2.editor, Node.text(node));
|
|
145
|
+
} else {
|
|
146
|
+
SfEditor.insertNodes(_this2.editor, {
|
|
147
|
+
type: 'code_line',
|
|
148
|
+
children: [{
|
|
149
|
+
text: Node.text(node)
|
|
150
|
+
}]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return true;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}]);
|
|
158
|
+
|
|
159
|
+
return CodeUtils;
|
|
160
|
+
}();
|
|
161
|
+
|
|
162
|
+
export default CodeUtils;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import { SfEditor } from '../../custom/custom';
|
|
4
|
+
|
|
5
|
+
var FormulaUtils = /*#__PURE__*/function () {
|
|
6
|
+
function FormulaUtils(editor) {
|
|
7
|
+
_classCallCheck(this, FormulaUtils);
|
|
8
|
+
|
|
9
|
+
this.editor = editor;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_createClass(FormulaUtils, [{
|
|
13
|
+
key: "isFormulaActive",
|
|
14
|
+
value: function isFormulaActive() {
|
|
15
|
+
var nodes = SfEditor.match(this.editor, this.editor.selection, {
|
|
16
|
+
type: 'formula'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (nodes) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
key: "insertFormula",
|
|
27
|
+
value: function insertFormula(data) {
|
|
28
|
+
SfEditor.insertNodes(this.editor, {
|
|
29
|
+
type: 'formula',
|
|
30
|
+
children: [{
|
|
31
|
+
text: ''
|
|
32
|
+
}],
|
|
33
|
+
data: data
|
|
34
|
+
}, {
|
|
35
|
+
at: data.at,
|
|
36
|
+
void: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "setFormula",
|
|
41
|
+
value: function setFormula(data) {
|
|
42
|
+
var formula = data.formula,
|
|
43
|
+
at = data.at;
|
|
44
|
+
SfEditor.setNodes(this.editor, {
|
|
45
|
+
data: {
|
|
46
|
+
formula: formula
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
at: at,
|
|
50
|
+
void: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}]);
|
|
54
|
+
|
|
55
|
+
return FormulaUtils;
|
|
56
|
+
}();
|
|
57
|
+
|
|
58
|
+
export default FormulaUtils;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import { Editor } from 'slate';
|
|
4
|
+
|
|
5
|
+
var BlockElementUtils = function BlockElementUtils(editor) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
|
|
8
|
+
_classCallCheck(this, BlockElementUtils);
|
|
9
|
+
|
|
10
|
+
this.getActiveHeader = function (types) {
|
|
11
|
+
var selection = _this.editor.selection;
|
|
12
|
+
if (!selection) return false;
|
|
13
|
+
var match = Editor.match(_this.editor, selection, types);
|
|
14
|
+
if (!match) return [{
|
|
15
|
+
type: 'paragraph'
|
|
16
|
+
}];
|
|
17
|
+
return match;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
this.isBlockActive = function (type) {
|
|
21
|
+
var selection = _this.editor.selection;
|
|
22
|
+
if (!selection) return false;
|
|
23
|
+
|
|
24
|
+
var _Editor$nodes = Editor.nodes(_this.editor, {
|
|
25
|
+
match: {
|
|
26
|
+
type: type
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
30
|
+
match = _Editor$nodes2[0];
|
|
31
|
+
|
|
32
|
+
return !!match;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.editor = editor;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default BlockElementUtils;
|