@seafile/sdoc-editor 0.1.0 → 0.1.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.
Files changed (149) hide show
  1. package/dist/{new-editors/editor.js → editor.js} +38 -17
  2. package/dist/index.js +2 -36
  3. package/dist/slate-extension/core/transforms/move-children.js +1 -1
  4. package/dist/slate-extension/plugins/blockquote/helpers.js +3 -3
  5. package/dist/slate-extension/plugins/index.js +3 -2
  6. package/dist/slate-extension/plugins/list/transforms/normalize-list-item.js +2 -2
  7. package/dist/slate-extension/plugins/list/transforms/toggle-list.js +6 -8
  8. package/dist/slate-extension/plugins/socket/index.js +6 -0
  9. package/dist/slate-extension/plugins/socket/plugin.js +23 -0
  10. package/dist/slate-extension/socket/socket-client.js +94 -0
  11. package/dist/slate-extension/socket/socket-manager.js +63 -0
  12. package/dist/slate-extension/toolbar/index.js +1 -1
  13. package/dist/utils/event-bus.js +39 -0
  14. package/package.json +5 -25
  15. package/dist/assets/css/comment-dialog.css +0 -50
  16. package/dist/assets/css/diff-viewer.css +0 -105
  17. package/dist/assets/css/formula.css +0 -19
  18. package/dist/assets/css/history-viewer.css +0 -104
  19. package/dist/assets/css/image.css +0 -134
  20. package/dist/assets/css/issue-card.css +0 -43
  21. package/dist/assets/css/keyboard-shortcuts.css +0 -58
  22. package/dist/assets/css/link.css +0 -7
  23. package/dist/assets/css/markdown-editor.css +0 -12
  24. package/dist/assets/css/markdown-viewer.css +0 -69
  25. package/dist/assets/css/navbar-imgbutton.css +0 -83
  26. package/dist/assets/css/outline.css +0 -29
  27. package/dist/assets/css/table.css +0 -57
  28. package/dist/assets/css/textlink-hovermenu.css +0 -47
  29. package/dist/assets/css/topbar.css +0 -350
  30. package/dist/assets/css/tree-view.css +0 -67
  31. package/dist/assets/css/user-help.css +0 -84
  32. package/dist/assets/editor/plain-editor.css +0 -30
  33. package/dist/assets/editor/seatable-editor.css +0 -77
  34. package/dist/assets/editor/simple-editor.css +0 -77
  35. package/dist/components/click-outside.js +0 -46
  36. package/dist/components/context-menu.js +0 -97
  37. package/dist/components/dialogs/add-formula-dialog.js +0 -116
  38. package/dist/components/dialogs/add-image-dialog.js +0 -69
  39. package/dist/components/dialogs/add-link-dialog.js +0 -133
  40. package/dist/components/dialogs/comment-dialog.js +0 -97
  41. package/dist/components/dialogs/shortcut-dialog.js +0 -131
  42. package/dist/components/error-boundary.js +0 -28
  43. package/dist/components/load-script/index.js +0 -69
  44. package/dist/components/loading.js +0 -25
  45. package/dist/components/markdown-lint.js +0 -72
  46. package/dist/components/menu/index.js +0 -4
  47. package/dist/components/menu/item.js +0 -49
  48. package/dist/components/menu/menu.js +0 -38
  49. package/dist/components/menu/style.css +0 -42
  50. package/dist/components/modal-portal.js +0 -38
  51. package/dist/components/outline/index.js +0 -92
  52. package/dist/components/outline/outline-item.js +0 -58
  53. package/dist/components/select/_option.js +0 -44
  54. package/dist/components/select/field-setting.js +0 -106
  55. package/dist/components/select/index.js +0 -149
  56. package/dist/components/select/style.css +0 -144
  57. package/dist/components/svg-icons/check-mark-icon.js +0 -14
  58. package/dist/components/svg-icons/column-icon.js +0 -17
  59. package/dist/components/svg-icons/text-icon.js +0 -34
  60. package/dist/components/text-link-hover-menu/index.js +0 -123
  61. package/dist/components/toast/alert.js +0 -138
  62. package/dist/components/toast/index.js +0 -3
  63. package/dist/components/toast/toast.js +0 -159
  64. package/dist/components/toast/toastManager.js +0 -139
  65. package/dist/components/toast/toaster.js +0 -65
  66. package/dist/components/toolbar/header-list.js +0 -114
  67. package/dist/components/toolbar/help-group.js +0 -33
  68. package/dist/components/toolbar/index.js +0 -4
  69. package/dist/components/toolbar/insert-image.js +0 -106
  70. package/dist/components/toolbar/insert-table.js +0 -136
  71. package/dist/components/toolbar/table-group.js +0 -74
  72. package/dist/components/toolbar/toolbar.js +0 -317
  73. package/dist/components/toolbar/widgets/button-group.js +0 -24
  74. package/dist/components/toolbar/widgets/button-item.js +0 -129
  75. package/dist/components/toolbar/widgets/drop-list.js +0 -88
  76. package/dist/components/user-help/index.js +0 -179
  77. package/dist/config-0.js +0 -15
  78. package/dist/config.js +0 -16
  79. package/dist/constants/cell-types.js +0 -29
  80. package/dist/constants/column.js +0 -4
  81. package/dist/containers/code-highlight-package.js +0 -14
  82. package/dist/containers/controller/block-element-controller.js +0 -375
  83. package/dist/containers/controller/index.js +0 -5
  84. package/dist/containers/controller/inline-element-controller.js +0 -134
  85. package/dist/containers/controller/normalize-controller.js +0 -95
  86. package/dist/containers/controller/shortcut-controller.js +0 -385
  87. package/dist/containers/controller/void-element-controller.js +0 -9
  88. package/dist/containers/custom/custom.js +0 -18
  89. package/dist/containers/custom/get-event-transfer.js +0 -33
  90. package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
  91. package/dist/containers/custom/insertNodes.js +0 -120
  92. package/dist/containers/custom/is-empty-paragraph.js +0 -9
  93. package/dist/containers/custom/set-event-transfer.js +0 -30
  94. package/dist/containers/custom/split-nodes-at-point.js +0 -136
  95. package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
  96. package/dist/containers/editor-context.js +0 -85
  97. package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
  98. package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
  99. package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
  100. package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
  101. package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
  102. package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
  103. package/dist/containers/editor-utils/clear-format-utils.js +0 -84
  104. package/dist/containers/editor-utils/common-editor-utils.js +0 -492
  105. package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
  106. package/dist/containers/editor-utils/mark-utils.js +0 -20
  107. package/dist/containers/editor-utils/range-utils.js +0 -7
  108. package/dist/containers/editor-utils/selection-utils.js +0 -30
  109. package/dist/containers/editor-utils/text-utils.js +0 -117
  110. package/dist/containers/editor-widgets/check-list-item.js +0 -53
  111. package/dist/containers/editor-widgets/code-block.js +0 -128
  112. package/dist/containers/editor-widgets/column.js +0 -100
  113. package/dist/containers/editor-widgets/formula.js +0 -67
  114. package/dist/containers/editor-widgets/image.js +0 -237
  115. package/dist/containers/editor-widgets/link.js +0 -9
  116. package/dist/containers/editor-widgets/table.js +0 -144
  117. package/dist/containers/element-model/blockquote.js +0 -13
  118. package/dist/containers/element-model/column.js +0 -19
  119. package/dist/containers/element-model/image.js +0 -16
  120. package/dist/containers/element-model/link.js +0 -16
  121. package/dist/containers/element-model/table.js +0 -57
  122. package/dist/containers/element-model/text.js +0 -10
  123. package/dist/containers/render-utils/common-utils.js +0 -80
  124. package/dist/containers/render-utils/editor-utils.js +0 -133
  125. package/dist/containers/render-utils/viewer-utils.js +0 -198
  126. package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
  127. package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
  128. package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
  129. package/dist/editors/index.js +0 -78
  130. package/dist/editors/markdown-editor.js +0 -280
  131. package/dist/editors/plain-markdown-editor.js +0 -285
  132. package/dist/editors/seatable-editor.js +0 -210
  133. package/dist/editors/simple-editor.js +0 -200
  134. package/dist/utils/deserialize-html.js +0 -260
  135. package/dist/utils/diff/compare-strings.js +0 -35
  136. package/dist/utils/diff/diff.js +0 -769
  137. package/dist/utils/diff/index.js +0 -2
  138. package/dist/utils/seafile-markdown2html.js +0 -52
  139. package/dist/utils/slate2markdown/deserialize.js +0 -588
  140. package/dist/utils/slate2markdown/index.js +0 -3
  141. package/dist/utils/slate2markdown/serialize.js +0 -366
  142. package/dist/utils/utils.js +0 -69
  143. package/dist/viewer/diff-viewer.js +0 -85
  144. package/dist/viewer/index.js +0 -4
  145. package/dist/viewer/markdown-viewer.js +0 -121
  146. package/dist/viewer/seatable-viewer.js +0 -63
  147. package/dist/viewer/slate-viewer.js +0 -71
  148. /package/dist/assets/css/{new-editor-toolbar.css → sdoc-editor-toolbar.css} +0 -0
  149. /package/dist/assets/css/{new-editor.css → sdoc-editor.css} +0 -0
@@ -1,2 +0,0 @@
1
- import { Diff, Diff3, equalityFunctionForSlate, SlateDiff } from './diff';
2
- export { Diff, Diff3, equalityFunctionForSlate, SlateDiff };
@@ -1,52 +0,0 @@
1
- var unified = require('unified');
2
- var markdown = require('remark-parse');
3
- var slug = require('remark-slug');
4
- var breaks = require('remark-breaks');
5
- var remark2rehype = require('remark-rehype');
6
- var format = require('rehype-format');
7
- var raw = require('rehype-raw');
8
- var xtend = require('xtend');
9
- var toHTML = require('hast-util-to-html');
10
- var sanitize = require('hast-util-sanitize');
11
- var gh = require('hast-util-sanitize/lib/github');
12
- var deepmerge = require('deepmerge').default;
13
- var mathjax = require('rehype-mathjax/browser');
14
- var math = require('remark-math/block');
15
- function stringify(config) {
16
- var settings = xtend(config, this.data('settings'));
17
- var schema = deepmerge(gh, {
18
- 'tagNames': ['input', 'code', 'span', 'div', 'blockquote', 'pre'],
19
- 'attributes': {
20
- 'input': ['type'],
21
- 'li': ['className'],
22
- 'code': ['className'],
23
- 'span': ['className'],
24
- 'div': ['className']
25
- },
26
- 'protocols': {
27
- 'src': ['http', 'https', 'cid']
28
- }
29
- });
30
- this.Compiler = compiler;
31
- function compiler(tree) {
32
- // use sanity to remove dangerous html, the default is
33
- // GitHub style sanitation
34
- var hast = sanitize(tree, schema);
35
- return toHTML(hast, settings);
36
- }
37
- }
38
-
39
- // markdown -> mdast -> html AST -> html
40
- var processor = unified().use(markdown, {
41
- commonmark: true
42
- }).use(math).use(breaks).use(slug).use(remark2rehype, {
43
- allowDangerousHTML: true
44
- }).use(mathjax, {
45
- displayMath: ['$$', '$$']
46
- }).use(raw).use(format).use(stringify);
47
-
48
- // var processorGetAST = unified()
49
- // .use(markdown, {commonmark: true})
50
- // .use(slug);
51
-
52
- export { processor };
@@ -1,588 +0,0 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import { Text } from 'slate';
3
- import { generateTable } from '../../containers/element-model/table';
4
- import { isEmptyParagraph } from '../utils';
5
- var unified = require('unified');
6
- var markdown = require('remark-parse');
7
- var math = require('remark-math/block');
8
- var definitions = require('mdast-util-definitions');
9
- function getProcessor() {
10
- var processor = unified().use(markdown, {
11
- commonmark: true
12
- });
13
- // Parse formula md string to slate node when editor can insert formula
14
- if (window.canInsertFormula) {
15
- processor.use(math);
16
- }
17
- return processor;
18
- }
19
-
20
- // transform code value: a function used to tranform code value of markdown format to slate document
21
- function mdCodeNodeToSlate(codeValue) {
22
- // statement an array : filled width code value splited by '\n'
23
- var codeValueArr = codeValue.split(/\n/g);
24
- var slateText, slateBlock;
25
- // map codeValueArr item to slate document 'code_line'
26
- var slate_code_arr = codeValueArr.map(function (text) {
27
- // transform string to slateText object
28
- slateText = {
29
- text: text
30
- };
31
- // transform slateText to Block object
32
- slateBlock = {
33
- children: [slateText],
34
- type: 'code_line'
35
- };
36
- return slateBlock;
37
- });
38
- return slate_code_arr;
39
- }
40
-
41
- // deserialize mdTable to SlateNode
42
- function mdTableToSlateTable(tableNode, opts) {
43
- // get align array
44
- var tableAlignArr = tableNode.align;
45
- // get all table_rows, return:array
46
- var tableRows = tableNode.children;
47
- // slate table_row Node into it
48
- var tableRowsArr = [];
49
- // traverse table_rows
50
- for (var rowIndex = 0; rowIndex < tableRows.length; rowIndex++) {
51
- // slate table_cell Node into it
52
- var tableCellsArr = [];
53
- /*
54
- * traverse every table_cells of an table_rows,
55
- * the length of every table_rows is equal to tableAlign array
56
- * */
57
- for (var columnsIndex = 0; columnsIndex < tableAlignArr.length; columnsIndex++) {
58
- // get table_cell and tranlate it to slate Node: table_cell
59
- var tableCell = tableRows[rowIndex].children[columnsIndex];
60
- if (!tableCell) {
61
- tableCell = {
62
- type: 'tableCell',
63
- children: [{
64
- type: 'paragraph',
65
- children: [{
66
- text: ''
67
- }]
68
- }],
69
- data: {
70
- align: 'left'
71
- }
72
- };
73
- }
74
- var children = parseChildren(tableCell, opts);
75
- if (children.length === 0) {
76
- children.push({
77
- text: ''
78
- });
79
- }
80
- tableCell = {
81
- type: 'table_cell',
82
- children: [{
83
- type: 'paragraph',
84
- children: children
85
- }],
86
- data: {
87
- align: tableAlignArr[columnsIndex]
88
- }
89
- };
90
- tableCellsArr.push(tableCell);
91
- }
92
- // push add table_rows into tableRowsArr
93
- tableRowsArr.push({
94
- type: 'table_row',
95
- children: tableCellsArr
96
- });
97
- }
98
- return tableRowsArr;
99
- }
100
- function mdImageToSlate(node, opts) {
101
- var _DOMParser$parseFromS = new DOMParser().parseFromString(node.value, 'text/html'),
102
- body = _DOMParser$parseFromS.body;
103
- var img = body.firstChild;
104
- var data = {};
105
- data['src'] = img.getAttribute('src');
106
- if (!isNaN(img.getAttribute('width')) && img.getAttribute('width') > 0) {
107
- data['width'] = img.getAttribute('width');
108
- }
109
- if (!isNaN(img.getAttribute('height')) && img.getAttribute('height') > 0) {
110
- data['height'] = img.getAttribute('height');
111
- }
112
- if (img.getAttribute('alt')) {
113
- data['alt'] = img.getAttribute('alt');
114
- }
115
- if (img.getAttribute('title')) {
116
- data['title'] = img.getAttribute('title');
117
- }
118
- if (data['src']) {
119
- return [{
120
- text: ''
121
- }, {
122
- type: 'image',
123
- data: data,
124
- children: [{
125
- text: ''
126
- }]
127
- }, {
128
- text: ''
129
- }];
130
- }
131
- }
132
- function _applyMark(childNodeOrNodes, mark) {
133
- if (childNodeOrNodes instanceof Array) {
134
- return childNodeOrNodes.map(function (item) {
135
- return _applyMark(item, mark);
136
- });
137
- } else if (childNodeOrNodes.text) {
138
- childNodeOrNodes[mark] = true;
139
- return childNodeOrNodes;
140
- } else {
141
- return childNodeOrNodes;
142
- }
143
- }
144
- function addChildNodeOrNodes(children, childNodeOrNodes) {
145
- if (childNodeOrNodes instanceof Array) {
146
- childNodeOrNodes.map(function (item) {
147
- return children.push(item);
148
- });
149
- } else {
150
- if (childNodeOrNodes !== undefined) children.push(childNodeOrNodes);
151
- }
152
- }
153
- function parseMark(node, markString, opts) {
154
- var mark = markString;
155
- var children = [];
156
- var _iterator = _createForOfIteratorHelper(node.children),
157
- _step;
158
- try {
159
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
160
- var child = _step.value;
161
- var childNodeOrNodes = _nodeToSlate(child, opts);
162
- // ignore unrecognized node type
163
- if (!childNodeOrNodes) continue;
164
- childNodeOrNodes = _applyMark(childNodeOrNodes, mark);
165
- addChildNodeOrNodes(children, childNodeOrNodes);
166
- }
167
- } catch (err) {
168
- _iterator.e(err);
169
- } finally {
170
- _iterator.f();
171
- }
172
- return children;
173
- }
174
- function parseChildren(node, opts) {
175
- var children = [];
176
- var _iterator2 = _createForOfIteratorHelper(node.children),
177
- _step2;
178
- try {
179
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
180
- var child = _step2.value;
181
- var ret = _nodeToSlate(child, opts);
182
- addChildNodeOrNodes(children, ret);
183
- }
184
- } catch (err) {
185
- _iterator2.e(err);
186
- } finally {
187
- _iterator2.f();
188
- }
189
- return children;
190
- }
191
- function _nodeToSlate(node, opts) {
192
- var children = [];
193
- var definition = opts.definition;
194
- switch (node.type) {
195
- case 'heading':
196
- var header_string;
197
- children = parseChildren(node, opts);
198
- if (children && children.length === 0) {
199
- children.push({
200
- text: ''
201
- });
202
- }
203
- switch (node.depth) {
204
- case 1:
205
- header_string = 'header_one';
206
- break;
207
- case 2:
208
- header_string = 'header_two';
209
- break;
210
- case 3:
211
- header_string = 'header_three';
212
- break;
213
- case 4:
214
- header_string = 'header_four';
215
- break;
216
- case 5:
217
- header_string = 'header_five';
218
- break;
219
- case 6:
220
- header_string = 'header_six';
221
- break;
222
- default:
223
- console.log('Invalid depth: ' + node.depth);
224
- header_string = 'header_one';
225
- break;
226
- }
227
- return {
228
- type: header_string,
229
- children: children
230
- };
231
- case 'paragraph':
232
- children = parseChildren(node, opts);
233
- if (children.length === 0) {
234
- children.push({
235
- text: ''
236
- });
237
- }
238
- return {
239
- type: 'paragraph',
240
- children: children
241
- };
242
- case 'blockquote':
243
- children = parseChildren(node, opts);
244
- if (children.length === 0) {
245
- children.push({
246
- type: 'paragraph',
247
- children: [{
248
- text: ''
249
- }]
250
- });
251
- }
252
- return {
253
- type: 'blockquote',
254
- children: children
255
- };
256
- case 'list':
257
- opts.loose = node.loose;
258
- children = parseChildren(node, opts);
259
- if (children.length === 0) {
260
- children.push({
261
- type: 'list_item',
262
- children: [{
263
- type: 'paragraph',
264
- children: [{
265
- text: ''
266
- }]
267
- }]
268
- });
269
- }
270
- if (node.ordered) {
271
- return {
272
- type: 'ordered_list',
273
- children: children
274
- };
275
- } else {
276
- return {
277
- type: 'unordered_list',
278
- children: children
279
- };
280
- }
281
- case 'listItem':
282
- children = parseChildren(node, opts);
283
- if (children.length === 0) {
284
- /**
285
- * if children is an empty array push an empy paragaph to it
286
- */
287
- children.push({
288
- type: 'paragraph',
289
- children: [{
290
- text: ''
291
- }]
292
- });
293
- }
294
- var data = {};
295
- if (node.checked !== null) {
296
- data.checked = node.checked;
297
- }
298
- return {
299
- type: 'list_item',
300
- data: data,
301
- children: children
302
- };
303
- case 'code':
304
- var data = {};
305
- if (node.lang) {
306
- data.syntax = node.lang;
307
- }
308
- var slate_code_arr = mdCodeNodeToSlate(node.value);
309
- if (slate_code_arr.length === 0) {
310
- slate_code_arr.push({
311
- type: 'code_line',
312
- children: [{
313
- text: ''
314
- }]
315
- });
316
- }
317
- return {
318
- type: 'code_block',
319
- data: data,
320
- children: slate_code_arr
321
- };
322
- case 'strong':
323
- return parseMark(node, 'BOLD', opts);
324
- case 'emphasis':
325
- return parseMark(node, 'ITALIC', opts);
326
- case 'inlineCode':
327
- // Inline code need to be handled differently
328
- return {
329
- text: node.value,
330
- 'CODE': true
331
- };
332
- case 'text':
333
- // A plain text in markdown
334
- // text is the botton node in Markdown AST
335
- return {
336
- text: node.value
337
- };
338
- case 'thematicBreak':
339
- return {
340
- type: 'hr',
341
- children: [{
342
- text: ''
343
- }]
344
- };
345
- case 'table':
346
- // get all children of table by mdTableToSlateTable
347
- children = mdTableToSlateTable(node, opts);
348
- if (children.length === 0) {
349
- return generateTable();
350
- }
351
- return {
352
- type: 'table',
353
- children: children,
354
- data: {
355
- align: node.align
356
- }
357
- };
358
- case 'html':
359
- if (node.value.slice(0, 4).toLowerCase() === '<img') {
360
- return mdImageToSlate(node, opts);
361
- } else {
362
- return {
363
- text: ''
364
- };
365
- }
366
- case 'link':
367
- children = parseChildren(node, opts);
368
- if (children.length === 0) return {
369
- text: ''
370
- };
371
- var data = {
372
- href: node.url
373
- };
374
- if (node.title) {
375
- data.title = node.title;
376
- }
377
- return [{
378
- text: ''
379
- }, {
380
- type: 'link',
381
- data: data,
382
- children: children
383
- }, {
384
- text: ''
385
- }];
386
- case 'image':
387
- var data = {
388
- src: node.url
389
- };
390
- if (node.title) {
391
- data.title = node.title;
392
- }
393
- if (node.alt) {
394
- data.alt = node.alt;
395
- }
396
- if (node.width) {
397
- data.width = node.width;
398
- }
399
- if (node.height) {
400
- data.height = node.height;
401
- }
402
- return [{
403
- text: ''
404
- }, {
405
- type: 'image',
406
- data: data,
407
- children: [{
408
- text: ''
409
- }]
410
- }, {
411
- text: ''
412
- }];
413
- case 'linkReference':
414
- children = parseChildren(node, opts);
415
- var def = definition(node.identifier);
416
- var data = {};
417
- if (def) {
418
- data.href = def.url;
419
- if (def.title) {
420
- data.title = def.title;
421
- }
422
- return {
423
- type: 'link',
424
- data: data,
425
- children: children
426
- };
427
- } else {
428
- return {
429
- text: '[' + node.identifier + ']'
430
- };
431
- }
432
- case 'imageReference':
433
- var def = definition(node.identifier);
434
- var data = {};
435
- if (def) {
436
- data.src = def.url;
437
- if (def.title) {
438
- data.title = def.title;
439
- }
440
- if (node.alt) {
441
- data.alt = node.alt;
442
- }
443
- return {
444
- type: 'image',
445
- data: data,
446
- children: [{
447
- text: ''
448
- }]
449
- };
450
- } else {
451
- return {
452
- text: '![' + node.alt + ']'
453
- };
454
- }
455
- case 'math':
456
- {
457
- return {
458
- type: 'formula',
459
- children: [{
460
- text: ''
461
- }],
462
- data: {
463
- formula: node.value
464
- }
465
- };
466
- }
467
- case 'definition':
468
- return;
469
- default:
470
- console.log('unrecognized type: ' + node.type);
471
- return;
472
- }
473
- }
474
- function fixValue(nodes) {
475
- var c = [];
476
- var _iterator3 = _createForOfIteratorHelper(nodes),
477
- _step3;
478
- try {
479
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
480
- var node = _step3.value;
481
- // if node is image node, wrap it into paragraph node
482
- if (node.type === 'image') {
483
- var data = {};
484
- data['src'] = node.data.src;
485
- data['width'] = node.data.width || null;
486
- data['height'] = node.data.height || null;
487
- if (node.data.alt) {
488
- data['alt'] = node.data.alt;
489
- }
490
- if (node.data.title) {
491
- data['title'] = node.data.title;
492
- }
493
- var nodeNew = {
494
- type: 'paragraph',
495
- children: [{
496
- text: ''
497
- }, {
498
- type: 'image',
499
- data: data,
500
- children: [{
501
- text: '',
502
- marks: []
503
- }]
504
- }, {
505
- text: ''
506
- }]
507
- };
508
- c.push(nodeNew);
509
- } else if (node.type === 'html_block') {
510
- // convert from inline to block
511
- node = {
512
- type: 'html_block',
513
- data: {
514
- html: node.get('data').get('html')
515
- },
516
- children: node.nodes
517
- };
518
- c.push(node);
519
- } else if (!Text.isText(node)) {
520
- c.push(node);
521
- }
522
- }
523
- } catch (err) {
524
- _iterator3.e(err);
525
- } finally {
526
- _iterator3.f();
527
- }
528
- return c;
529
- }
530
- function deserialize(content) {
531
- // valid input content, maybe a number
532
- if (!isNaN(content)) {
533
- content = content.toString();
534
- }
535
- var processor = getProcessor();
536
- var root = processor.parse(content);
537
- var definition = definitions(root);
538
- var nodes = [];
539
- var _iterator4 = _createForOfIteratorHelper(root.children),
540
- _step4;
541
- try {
542
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
543
- var child = _step4.value;
544
- addChildNodeOrNodes(nodes, _nodeToSlate(child, {
545
- definition: definition
546
- }));
547
- }
548
- } catch (err) {
549
- _iterator4.e(err);
550
- } finally {
551
- _iterator4.f();
552
- }
553
- if (nodes.length === 0) {
554
- // add default paragraph
555
- var node = {
556
- type: 'paragraph',
557
- children: [{
558
- text: ''
559
- }]
560
- };
561
- nodes.push(node);
562
- }
563
-
564
- // handle image and html_block
565
- var c = fixValue(nodes);
566
- var firstBlockType = c[0] && c[0].type;
567
- if (firstBlockType === 'table' || firstBlockType === 'code_block' || firstBlockType === 'blockquote') {
568
- c.unshift({
569
- type: 'paragraph',
570
- children: [{
571
- text: ''
572
- }]
573
- });
574
- }
575
-
576
- // Do not add an empty paragraph in if the article has only an empty paragraph
577
- if (c.length === 1 && isEmptyParagraph(c[0])) {
578
- return c;
579
- }
580
- c.push({
581
- type: 'paragraph',
582
- children: [{
583
- text: ''
584
- }]
585
- });
586
- return c;
587
- }
588
- export { deserialize };
@@ -1,3 +0,0 @@
1
- import { serialize } from './serialize';
2
- import { deserialize } from './deserialize';
3
- export { serialize, deserialize };