@seafile/sdoc-editor 0.1.53 → 0.1.55
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/editor.js +23 -3
- package/dist/basic-sdk/extension/constants/index.js +2 -1
- package/dist/basic-sdk/extension/menu/context-menu/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/html/helper.js +135 -0
- package/dist/basic-sdk/extension/plugins/html/index.js +6 -0
- package/dist/basic-sdk/extension/plugins/html/plugin.js +16 -0
- package/dist/basic-sdk/extension/plugins/html/rules/blockquote.js +16 -0
- package/dist/basic-sdk/extension/plugins/html/rules/check-list.js +20 -0
- package/dist/basic-sdk/extension/plugins/html/rules/code-block.js +28 -0
- package/dist/basic-sdk/extension/plugins/html/rules/header.js +24 -0
- package/dist/basic-sdk/extension/plugins/html/rules/image.js +21 -0
- package/dist/basic-sdk/extension/plugins/html/rules/index.js +11 -0
- package/dist/basic-sdk/extension/plugins/html/rules/link.js +22 -0
- package/dist/basic-sdk/extension/plugins/html/rules/list.js +53 -0
- package/dist/basic-sdk/extension/plugins/html/rules/paragraph.js +16 -0
- package/dist/basic-sdk/extension/plugins/html/rules/table.js +35 -0
- package/dist/basic-sdk/extension/plugins/html/rules/text.js +61 -0
- package/dist/basic-sdk/extension/plugins/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/link/menu/hover-link-dialog.js +4 -4
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +7 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +216 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +10 -10
- package/dist/basic-sdk/extension/plugins/table/menu/context-menu/index.js +18 -6
- package/dist/basic-sdk/extension/plugins/table/menu/context-menu/insert-table-element.js +1 -1
- package/dist/basic-sdk/extension/plugins/table/plugin.js +67 -258
- package/dist/basic-sdk/extension/plugins/table/render/context.js +5 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +35 -16
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +7 -16
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +34 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +81 -28
- package/dist/basic-sdk/extension/plugins/text-style/index.js +2 -1
- package/dist/basic-sdk/extension/toolbar/index.js +32 -47
- package/dist/constants/index.js +2 -1
- package/package.json +3 -1
- package/public/locales/en/sdoc-editor.json +3 -8
- package/public/locales/zh-CN/sdoc-editor.json +5 -5
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +6 -0
- package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
- package/public/media/sdoc-editor-font.css +4 -0
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -9,6 +9,9 @@ import withNodeId from './node-id';
|
|
|
9
9
|
import SDocOutline from './outline';
|
|
10
10
|
import EventProxy from './utils/event-handler';
|
|
11
11
|
import { useCursors } from './cursor/use-cursors';
|
|
12
|
+
import EventBus from './utils/event-bus';
|
|
13
|
+
import { EXTERNAL_EVENT } from '../constants';
|
|
14
|
+
import { isAllInTable } from './extension/plugins/table/helpers';
|
|
12
15
|
import './assets/css/layout.css';
|
|
13
16
|
import './assets/css/sdoc-editor-plugins.css';
|
|
14
17
|
var SDocEditor = function SDocEditor(_ref) {
|
|
@@ -39,12 +42,17 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
39
42
|
setMenuPosition = _useState6[1];
|
|
40
43
|
var _useCursors = useCursors(editor),
|
|
41
44
|
cursors = _useCursors.cursors;
|
|
45
|
+
var _useState7 = useState({}),
|
|
46
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
47
|
+
forceUpdateValue = _useState8[0],
|
|
48
|
+
setForceUpdateValue = _useState8[1];
|
|
42
49
|
|
|
43
50
|
// init eventHandler
|
|
44
51
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
52
|
var eventProxy = useMemo(function () {
|
|
46
53
|
return new EventProxy(editor);
|
|
47
54
|
}, []);
|
|
55
|
+
var eventBus = EventBus.getInstance();
|
|
48
56
|
|
|
49
57
|
// useMount: init socket connection
|
|
50
58
|
useEffect(function () {
|
|
@@ -64,7 +72,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
64
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
73
|
}, []);
|
|
66
74
|
var onContextMenu = useCallback(function (event) {
|
|
67
|
-
if (
|
|
75
|
+
if (isAllInTable(editor)) {
|
|
68
76
|
event.preventDefault();
|
|
69
77
|
var contextMenuPosition = {
|
|
70
78
|
left: event.clientX,
|
|
@@ -80,10 +88,20 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
80
88
|
setContextMenu(false);
|
|
81
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
90
|
}, []);
|
|
91
|
+
var onMouseDown = useCallback(function (event) {
|
|
92
|
+
if (event.button === 0) {
|
|
93
|
+
eventBus.dispatch(EXTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
94
|
+
}
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, []);
|
|
97
|
+
var onSelect = useCallback(function () {
|
|
98
|
+
setForceUpdateValue({});
|
|
99
|
+
}, []);
|
|
83
100
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
84
101
|
className: "sdoc-editor-container"
|
|
85
102
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
86
|
-
editor: editor
|
|
103
|
+
editor: editor,
|
|
104
|
+
forceUpdateValue: forceUpdateValue
|
|
87
105
|
}), /*#__PURE__*/React.createElement("div", {
|
|
88
106
|
className: "sdoc-editor-content"
|
|
89
107
|
}, /*#__PURE__*/React.createElement(SDocOutline, {
|
|
@@ -102,7 +120,9 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
102
120
|
renderLeaf: renderLeaf,
|
|
103
121
|
onKeyDown: eventProxy.onKeyDown,
|
|
104
122
|
cursors: cursors,
|
|
105
|
-
onContextMenu: onContextMenu
|
|
123
|
+
onContextMenu: onContextMenu,
|
|
124
|
+
onMouseDown: onMouseDown,
|
|
125
|
+
onSelect: onSelect
|
|
106
126
|
})))))), isShowContextMenu && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
107
127
|
editor: editor,
|
|
108
128
|
contextMenuPosition: menuPosition
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
|
|
2
|
+
var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP, _TABLE_ELEMENT_SPAN;
|
|
3
3
|
// extension plugin
|
|
4
4
|
import * as ELEMENT_TYPE from './element-type';
|
|
5
5
|
import { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
|
|
@@ -96,6 +96,7 @@ export var TABLE_ELEMENT = {
|
|
|
96
96
|
COLUMN: 'column',
|
|
97
97
|
CELL: 'cell'
|
|
98
98
|
};
|
|
99
|
+
export var TABLE_ELEMENT_SPAN = (_TABLE_ELEMENT_SPAN = {}, _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.TABLE, 'table'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.ROW, 'tr'), _defineProperty(_TABLE_ELEMENT_SPAN, TABLE_ELEMENT.CELL, 'td'), _TABLE_ELEMENT_SPAN);
|
|
99
100
|
export var TABLE_ELEMENT_POSITION = {
|
|
100
101
|
AFTER: 'after',
|
|
101
102
|
BEFORE: 'before'
|
|
@@ -5,6 +5,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
5
|
import React, { Component } from 'react';
|
|
6
6
|
import ModalPortal from '../../../../components/modal-portal';
|
|
7
7
|
import { TablePlugin } from '../../plugins';
|
|
8
|
+
import { isAllInTable } from '../../plugins/table/helpers';
|
|
8
9
|
var ContextMenu = /*#__PURE__*/function (_Component) {
|
|
9
10
|
_inherits(ContextMenu, _Component);
|
|
10
11
|
var _super = _createSuper(ContextMenu);
|
|
@@ -17,7 +18,7 @@ var ContextMenu = /*#__PURE__*/function (_Component) {
|
|
|
17
18
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
18
19
|
_this.renderContextMenu = function () {
|
|
19
20
|
var editor = _this.props.editor;
|
|
20
|
-
if (
|
|
21
|
+
if (isAllInTable(editor)) {
|
|
21
22
|
var ContextMenuComponent = TablePlugin.contextMenu;
|
|
22
23
|
return /*#__PURE__*/React.createElement(ContextMenuComponent, _this.props);
|
|
23
24
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import typeOf from 'type-of';
|
|
3
|
+
import { LIST_ITEM, PARAGRAPH, UNORDERED_LIST } from '../../constants';
|
|
4
|
+
import rules from './rules';
|
|
5
|
+
var cruftNewline = function cruftNewline(element) {
|
|
6
|
+
return !(element.nodeName === '#text' && element.nodeValue === '\n');
|
|
7
|
+
};
|
|
8
|
+
var deserializeElement = function deserializeElement(element) {
|
|
9
|
+
var node;
|
|
10
|
+
var next = function next(elements) {
|
|
11
|
+
if (Object.prototype.toString.call(elements) === '[object NodeList]') {
|
|
12
|
+
elements = Array.from(elements);
|
|
13
|
+
}
|
|
14
|
+
switch (typeOf(elements)) {
|
|
15
|
+
case 'array':
|
|
16
|
+
return deserializeElements(elements);
|
|
17
|
+
case 'object':
|
|
18
|
+
return deserializeElement(elements);
|
|
19
|
+
case 'null':
|
|
20
|
+
case 'undefined':
|
|
21
|
+
return;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("The `next` argument was called with invalid children: \"".concat(elements, "\"."));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
for (var i = 0; i < rules.length; i++) {
|
|
27
|
+
var rule = rules[i];
|
|
28
|
+
if (!rule) continue;
|
|
29
|
+
var ret = rule(element, next);
|
|
30
|
+
var type = typeOf(ret);
|
|
31
|
+
if (type !== 'array' && type !== 'object' && type !== 'null' && type !== 'undefined') {
|
|
32
|
+
throw new Error("A rule returned an invalid deserialized representation: \"".concat(node, "\"."));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Not eligible for current component processing
|
|
36
|
+
if (ret === undefined) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Empty tags will be discarded and not converted accordingly
|
|
41
|
+
if (ret === null) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Assign the final processing result to node
|
|
46
|
+
node = ret;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// If node is undefined, it means that the label is not processed, and continue to process the child nodes of the element
|
|
51
|
+
return node || next(element.childNodes);
|
|
52
|
+
};
|
|
53
|
+
var deserializeElements = function deserializeElements() {
|
|
54
|
+
var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
55
|
+
var isTopLevel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
56
|
+
var nodes = [];
|
|
57
|
+
elements.filter(cruftNewline).forEach(function (element) {
|
|
58
|
+
var node = deserializeElement(element);
|
|
59
|
+
switch (typeOf(node)) {
|
|
60
|
+
case 'array':
|
|
61
|
+
var formatNode = isTopLevel ? formatElementNodes(node, true) : node;
|
|
62
|
+
nodes = nodes.concat(formatNode);
|
|
63
|
+
break;
|
|
64
|
+
case 'object':
|
|
65
|
+
nodes.push(node);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
// nothing todo
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return nodes;
|
|
73
|
+
};
|
|
74
|
+
var formatElementNodes = function formatElementNodes(nodes) {
|
|
75
|
+
var isMergeForward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
76
|
+
if (nodes.length === 0) return nodes;
|
|
77
|
+
nodes = nodes.reduce(function (memo, node) {
|
|
78
|
+
if (node.level === 'level1') {
|
|
79
|
+
memo.push(node);
|
|
80
|
+
}
|
|
81
|
+
if (node.level === 'level2') {
|
|
82
|
+
if (node.type === LIST_ITEM) {
|
|
83
|
+
var newNode = {
|
|
84
|
+
level: 'level1',
|
|
85
|
+
id: slugid.nice(),
|
|
86
|
+
type: UNORDERED_LIST,
|
|
87
|
+
children: [node]
|
|
88
|
+
};
|
|
89
|
+
memo.push(newNode);
|
|
90
|
+
return memo;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (node.level === 'level3') {
|
|
94
|
+
var prevNode = memo[memo.length - 1];
|
|
95
|
+
if (prevNode && prevNode.type === PARAGRAPH && isMergeForward) {
|
|
96
|
+
prevNode.children.push(node);
|
|
97
|
+
return memo;
|
|
98
|
+
}
|
|
99
|
+
var _newNode = {
|
|
100
|
+
level: 'level1',
|
|
101
|
+
id: slugid.nice(),
|
|
102
|
+
type: PARAGRAPH,
|
|
103
|
+
children: [node]
|
|
104
|
+
};
|
|
105
|
+
memo.push(_newNode);
|
|
106
|
+
return memo;
|
|
107
|
+
}
|
|
108
|
+
return memo;
|
|
109
|
+
}, []);
|
|
110
|
+
return nodes;
|
|
111
|
+
};
|
|
112
|
+
var parseHtml = function parseHtml(html) {
|
|
113
|
+
var parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
114
|
+
var body = parsed.body;
|
|
115
|
+
return body;
|
|
116
|
+
};
|
|
117
|
+
export var deserializeHtml = function deserializeHtml(html) {
|
|
118
|
+
var fragment = parseHtml(html);
|
|
119
|
+
var children = Array.from(fragment.childNodes);
|
|
120
|
+
var nodes = [];
|
|
121
|
+
nodes = deserializeElements(children, true);
|
|
122
|
+
nodes = formatElementNodes(nodes);
|
|
123
|
+
if (nodes.length === 0) {
|
|
124
|
+
nodes = [{
|
|
125
|
+
level: 'level1',
|
|
126
|
+
id: slugid.nice(),
|
|
127
|
+
type: PARAGRAPH,
|
|
128
|
+
children: [{
|
|
129
|
+
text: '',
|
|
130
|
+
id: slugid.nice()
|
|
131
|
+
}]
|
|
132
|
+
}];
|
|
133
|
+
}
|
|
134
|
+
return nodes;
|
|
135
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { deserializeHtml } from './helper';
|
|
2
|
+
var withHtml = function withHtml(editor) {
|
|
3
|
+
var insertData = editor.insertData;
|
|
4
|
+
var newEditor = editor;
|
|
5
|
+
newEditor.insertData = function (data) {
|
|
6
|
+
var htmlContent = data.getData('text/html') || '';
|
|
7
|
+
if (htmlContent) {
|
|
8
|
+
var content = deserializeHtml(htmlContent);
|
|
9
|
+
editor.insertFragment(content);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
insertData(data);
|
|
13
|
+
};
|
|
14
|
+
return newEditor;
|
|
15
|
+
};
|
|
16
|
+
export default withHtml;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { BLOCKQUOTE } from '../../../constants';
|
|
3
|
+
var blockquoteRule = function blockquoteRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName,
|
|
5
|
+
childNodes = element.childNodes;
|
|
6
|
+
if (nodeName === 'BLOCKQUOTE') {
|
|
7
|
+
return {
|
|
8
|
+
level: 'level1',
|
|
9
|
+
id: slugid.nice(),
|
|
10
|
+
type: BLOCKQUOTE,
|
|
11
|
+
children: parseChild(childNodes)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
};
|
|
16
|
+
export default blockquoteRule;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { CHECK_LIST_ITEM } from '../../../constants';
|
|
3
|
+
var checkListRule = function checkListRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName;
|
|
5
|
+
if (nodeName === 'INPUT' && element.getAttribute('type') === 'checkbox') {
|
|
6
|
+
return {
|
|
7
|
+
level: 'level1',
|
|
8
|
+
id: slugid.nice(),
|
|
9
|
+
type: CHECK_LIST_ITEM,
|
|
10
|
+
checked: element.getAttribute('checked') !== null,
|
|
11
|
+
children: [{
|
|
12
|
+
level: 'level3',
|
|
13
|
+
id: slugid.nice(),
|
|
14
|
+
text: ''
|
|
15
|
+
}]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return;
|
|
19
|
+
};
|
|
20
|
+
export default checkListRule;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { CODE_BLOCK, CODE_LINE } from '../../../constants';
|
|
3
|
+
var codeBlockRule = function codeBlockRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName,
|
|
5
|
+
childNodes = element.childNodes;
|
|
6
|
+
if (nodeName === 'PRE') {
|
|
7
|
+
return {
|
|
8
|
+
level: 'level1',
|
|
9
|
+
id: slugid.nice(),
|
|
10
|
+
type: CODE_BLOCK,
|
|
11
|
+
children: parseChild(childNodes)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
|
|
15
|
+
return {
|
|
16
|
+
level: 'level2',
|
|
17
|
+
id: slugid.nice(),
|
|
18
|
+
type: CODE_LINE,
|
|
19
|
+
children: [{
|
|
20
|
+
level: 'level3',
|
|
21
|
+
id: slugid.nice(),
|
|
22
|
+
text: element.textContent
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
};
|
|
28
|
+
export default codeBlockRule;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
var HEADER_LIST = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
|
|
3
|
+
var HEADER_TYPE_MAP = {
|
|
4
|
+
H1: 'header1',
|
|
5
|
+
H2: 'header2',
|
|
6
|
+
H3: 'header3',
|
|
7
|
+
H4: 'header4',
|
|
8
|
+
H5: 'header5',
|
|
9
|
+
H6: 'header6'
|
|
10
|
+
};
|
|
11
|
+
var headerRule = function headerRule(element, parseChild) {
|
|
12
|
+
var nodeName = element.nodeName,
|
|
13
|
+
childNodes = element.childNodes;
|
|
14
|
+
if (nodeName && HEADER_LIST.includes(nodeName)) {
|
|
15
|
+
return {
|
|
16
|
+
level: 'level1',
|
|
17
|
+
id: slugid.nice(),
|
|
18
|
+
type: HEADER_TYPE_MAP[nodeName],
|
|
19
|
+
children: parseChild(childNodes)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
};
|
|
24
|
+
export default headerRule;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { IMAGE } from '../../../constants';
|
|
3
|
+
var imageRule = function imageRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName;
|
|
5
|
+
if (nodeName === 'IMG') {
|
|
6
|
+
return {
|
|
7
|
+
level: 'level3',
|
|
8
|
+
id: slugid.nice(),
|
|
9
|
+
type: IMAGE,
|
|
10
|
+
data: {
|
|
11
|
+
src: element.getAttribute('src')
|
|
12
|
+
},
|
|
13
|
+
children: [{
|
|
14
|
+
text: '',
|
|
15
|
+
id: slugid.nice()
|
|
16
|
+
}]
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
};
|
|
21
|
+
export default imageRule;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import blockquoteRule from './blockquote';
|
|
2
|
+
import codeBlockRule from './code-block';
|
|
3
|
+
import headerRule from './header';
|
|
4
|
+
import imageRule from './image';
|
|
5
|
+
import linkRule from './link';
|
|
6
|
+
import listRule from './list';
|
|
7
|
+
import paragraphRule from './paragraph';
|
|
8
|
+
import tableRule from './table';
|
|
9
|
+
import textRule from './text';
|
|
10
|
+
var rules = [blockquoteRule, codeBlockRule, headerRule, imageRule, linkRule, listRule, tableRule, paragraphRule, textRule];
|
|
11
|
+
export default rules;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { LINK } from '../../../constants';
|
|
3
|
+
var linkRule = function linkRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName;
|
|
5
|
+
var content = element.textContent || element.getAttribute('title') || element.getAttribute('href');
|
|
6
|
+
if (nodeName === 'A') {
|
|
7
|
+
return {
|
|
8
|
+
level: 'level3',
|
|
9
|
+
id: slugid.nice(),
|
|
10
|
+
type: LINK,
|
|
11
|
+
href: element.getAttribute('href'),
|
|
12
|
+
title: element.getAttribute('title'),
|
|
13
|
+
children: [{
|
|
14
|
+
level: 'level3',
|
|
15
|
+
id: slugid.nice(),
|
|
16
|
+
text: content
|
|
17
|
+
}]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
};
|
|
22
|
+
export default linkRule;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { LIST_ITEM, LIST_LIC, ORDERED_LIST, UNORDERED_LIST } from '../../../constants';
|
|
3
|
+
var PARAGRAPH_TAGS = ['DIV', 'P'];
|
|
4
|
+
var listRule = function listRule(element, parseChild) {
|
|
5
|
+
var nodeName = element.nodeName,
|
|
6
|
+
childNodes = element.childNodes;
|
|
7
|
+
if (nodeName === 'UL') {
|
|
8
|
+
return {
|
|
9
|
+
level: 'level1',
|
|
10
|
+
id: slugid.nice(),
|
|
11
|
+
type: UNORDERED_LIST,
|
|
12
|
+
children: parseChild(childNodes)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (nodeName === 'OL') {
|
|
16
|
+
return {
|
|
17
|
+
level: 'level1',
|
|
18
|
+
id: slugid.nice(),
|
|
19
|
+
type: ORDERED_LIST,
|
|
20
|
+
children: parseChild(childNodes)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (nodeName === 'LI' && PARAGRAPH_TAGS.includes(element.firstChild.nodeName)) {
|
|
24
|
+
return {
|
|
25
|
+
level: 'level2',
|
|
26
|
+
id: slugid.nice(),
|
|
27
|
+
type: LIST_ITEM,
|
|
28
|
+
children: parseChild(childNodes)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (nodeName === 'LI' && !PARAGRAPH_TAGS.includes(element.firstChild.nodeName)) {
|
|
32
|
+
return {
|
|
33
|
+
level: 'level2',
|
|
34
|
+
id: slugid.nice(),
|
|
35
|
+
type: LIST_ITEM,
|
|
36
|
+
children: [{
|
|
37
|
+
level: 'level3',
|
|
38
|
+
type: LIST_LIC,
|
|
39
|
+
children: parseChild(childNodes)
|
|
40
|
+
}]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (PARAGRAPH_TAGS.includes(nodeName) && element.parentElement.nodeName === 'LI') {
|
|
44
|
+
return {
|
|
45
|
+
level: 'level3',
|
|
46
|
+
id: slugid.nice(),
|
|
47
|
+
type: LIST_LIC,
|
|
48
|
+
children: parseChild(childNodes)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
};
|
|
53
|
+
export default listRule;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { PARAGRAPH } from '../../../constants';
|
|
3
|
+
var paragraphRule = function paragraphRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName,
|
|
5
|
+
childNodes = element.childNodes;
|
|
6
|
+
if (nodeName === 'P' && element.parentElement.nodeName !== 'LI') {
|
|
7
|
+
return {
|
|
8
|
+
level: 'level1',
|
|
9
|
+
id: slugid.nice(),
|
|
10
|
+
type: PARAGRAPH,
|
|
11
|
+
children: parseChild(childNodes)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
};
|
|
16
|
+
export default paragraphRule;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { TABLE, TABLE_CELL, TABLE_ROW } from '../../../constants';
|
|
3
|
+
var tableRule = function tableRule(element, parseChild) {
|
|
4
|
+
var nodeName = element.nodeName,
|
|
5
|
+
childNodes = element.childNodes;
|
|
6
|
+
if (nodeName === 'TABLE') {
|
|
7
|
+
return {
|
|
8
|
+
level: 'level1',
|
|
9
|
+
id: slugid.nice(),
|
|
10
|
+
type: TABLE,
|
|
11
|
+
children: parseChild(childNodes)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (nodeName === 'THEAD' || nodeName === 'TBODY') {
|
|
15
|
+
return parseChild(childNodes);
|
|
16
|
+
}
|
|
17
|
+
if (nodeName === 'TR') {
|
|
18
|
+
return {
|
|
19
|
+
level: 'level2',
|
|
20
|
+
id: slugid.nice(),
|
|
21
|
+
type: TABLE_ROW,
|
|
22
|
+
children: parseChild(childNodes)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (nodeName === 'TH' || nodeName === 'TD') {
|
|
26
|
+
return {
|
|
27
|
+
level: 'level3',
|
|
28
|
+
id: slugid.nice(),
|
|
29
|
+
type: TABLE_CELL,
|
|
30
|
+
children: parseChild(childNodes)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
};
|
|
35
|
+
export default tableRule;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
var textRule = function textRule(element, parseChild) {
|
|
3
|
+
var nodeName = element.nodeName,
|
|
4
|
+
nodeType = element.nodeType;
|
|
5
|
+
if (nodeName === 'SPAN') {
|
|
6
|
+
return {
|
|
7
|
+
level: 'level3',
|
|
8
|
+
id: slugid.nice(),
|
|
9
|
+
text: element.textContent
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (nodeName === 'STRONG' || nodeName === 'B') {
|
|
13
|
+
return {
|
|
14
|
+
level: 'level3',
|
|
15
|
+
id: slugid.nice(),
|
|
16
|
+
BOLD: true,
|
|
17
|
+
text: element.textContent
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (nodeName === 'CODE' && element.parentElement.nodeName !== 'PRE') {
|
|
21
|
+
return {
|
|
22
|
+
level: 'level3',
|
|
23
|
+
id: slugid.nice(),
|
|
24
|
+
CODE: true,
|
|
25
|
+
text: element.textContent
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (nodeName === 'DEL') {
|
|
29
|
+
return {
|
|
30
|
+
level: 'level3',
|
|
31
|
+
id: slugid.nice(),
|
|
32
|
+
DELETE: true,
|
|
33
|
+
text: element.textContent
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (nodeName === 'I') {
|
|
37
|
+
return {
|
|
38
|
+
level: 'level3',
|
|
39
|
+
id: slugid.nice(),
|
|
40
|
+
ITALIC: true,
|
|
41
|
+
text: element.textContent
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (nodeName === 'INS') {
|
|
45
|
+
return {
|
|
46
|
+
level: 'level3',
|
|
47
|
+
id: slugid.nice(),
|
|
48
|
+
ADD: true,
|
|
49
|
+
text: element.textContent
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (nodeType === 3) {
|
|
53
|
+
return {
|
|
54
|
+
level: 'level3',
|
|
55
|
+
id: slugid.nice(),
|
|
56
|
+
text: element.textContent
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
};
|
|
61
|
+
export default textRule;
|
|
@@ -8,6 +8,7 @@ import TextPlugin from './text-style';
|
|
|
8
8
|
import CodeBlockPlugin from './code-block';
|
|
9
9
|
import ImagePlugin from './image';
|
|
10
10
|
import TablePlugin from './table';
|
|
11
|
-
|
|
11
|
+
import HtmlPlugin from './html';
|
|
12
|
+
var Plugins = [MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, HtmlPlugin];
|
|
12
13
|
export default Plugins;
|
|
13
|
-
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin,
|
|
14
|
+
export { MarkDownPlugin, HeaderPlugin, LinkPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, TextPlugin, HtmlPlugin };
|
|
@@ -34,15 +34,15 @@ var LinkHoverComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
34
34
|
}, /*#__PURE__*/React.createElement("span", {
|
|
35
35
|
role: "button",
|
|
36
36
|
className: "link-op-icon",
|
|
37
|
-
onClick: this.props.
|
|
37
|
+
onClick: this.props.onEditLink
|
|
38
38
|
}, /*#__PURE__*/React.createElement("i", {
|
|
39
|
-
className: "sdocfont sdoc-
|
|
39
|
+
className: "sdocfont sdoc-rename"
|
|
40
40
|
})), /*#__PURE__*/React.createElement("span", {
|
|
41
41
|
role: "button",
|
|
42
42
|
className: "link-op-icon",
|
|
43
|
-
onClick: this.props.
|
|
43
|
+
onClick: this.props.onDeleteLink
|
|
44
44
|
}, /*#__PURE__*/React.createElement("i", {
|
|
45
|
-
className: "sdocfont sdoc-
|
|
45
|
+
className: "sdocfont sdoc-unlink"
|
|
46
46
|
}))), /*#__PURE__*/React.createElement("span", {
|
|
47
47
|
className: "link-op-menu-triangle"
|
|
48
48
|
})), document.body));
|