@seafile/seafile-editor 1.0.2 → 1.0.4
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/constants/event-types.js +2 -8
- package/dist/constants/hot-keys.js +1 -7
- package/dist/containers/article-info/index.js +24 -34
- package/dist/containers/custom/get-event-transfer.js +10 -16
- package/dist/containers/custom/set-event-transfer.js +10 -16
- package/dist/containers/hotkeys-helper/classify-hotkeys.js +20 -25
- package/dist/containers/hotkeys-helper/index.js +32 -35
- package/dist/containers/loading/index.js +11 -32
- package/dist/containers/outline/index.js +41 -51
- package/dist/containers/outline/outline-item.js +15 -21
- package/dist/editors/plain-markdown-editor/code-mirror.js +51 -75
- package/dist/editors/plain-markdown-editor/index.js +90 -107
- package/dist/editors/simple-slate-editor /index.js +43 -57
- package/dist/editors/simple-slate-editor /with-props-editor.js +4 -10
- package/dist/editors/slate-editor/editor-help/index.js +24 -37
- package/dist/editors/slate-editor/index.js +50 -64
- package/dist/editors/slate-editor/with-props-editor.js +4 -10
- package/dist/editors/slate-viewer/index.js +25 -31
- package/dist/extension/commons/element-popover/index.js +30 -55
- package/dist/extension/commons/index.js +3 -26
- package/dist/extension/commons/menu/index.js +4 -21
- package/dist/extension/commons/menu/menu-drop-down.js +50 -63
- package/dist/extension/commons/menu/menu-group.js +4 -11
- package/dist/extension/commons/menu/menu-item.js +25 -30
- package/dist/extension/commons/tooltip/index.js +14 -19
- package/dist/extension/constants/element-types.js +22 -28
- package/dist/extension/constants/index.js +15 -37
- package/dist/extension/constants/keyboard.js +3 -9
- package/dist/extension/constants/menus-config.js +118 -105
- package/dist/extension/core/index.js +3 -38
- package/dist/extension/core/queries/index.js +209 -304
- package/dist/extension/core/transforms/focus-editor.js +7 -13
- package/dist/extension/core/transforms/index.js +4 -49
- package/dist/extension/core/transforms/move-children.js +18 -25
- package/dist/extension/core/transforms/remove-node-children.js +8 -27
- package/dist/extension/core/transforms/replace-node-children.js +14 -19
- package/dist/extension/core/utils/index.js +36 -44
- package/dist/extension/editor.js +8 -15
- package/dist/extension/index.js +7 -48
- package/dist/extension/plugins/blockquote/helpers.js +38 -57
- package/dist/extension/plugins/blockquote/index.js +8 -15
- package/dist/extension/plugins/blockquote/menu/index.js +20 -25
- package/dist/extension/plugins/blockquote/plugin.js +35 -41
- package/dist/extension/plugins/blockquote/render-elem.js +9 -14
- package/dist/extension/plugins/check-list/helper.js +14 -24
- package/dist/extension/plugins/check-list/index.js +10 -17
- package/dist/extension/plugins/check-list/menu/index.js +21 -29
- package/dist/extension/plugins/check-list/plugin.js +24 -26
- package/dist/extension/plugins/check-list/render-elem.js +22 -28
- package/dist/extension/plugins/clear-format/helpers.js +25 -47
- package/dist/extension/plugins/clear-format/menu/index.js +22 -29
- package/dist/extension/plugins/code-block/helpers.js +74 -126
- package/dist/extension/plugins/code-block/index.js +10 -18
- package/dist/extension/plugins/code-block/menu/index.js +20 -27
- package/dist/extension/plugins/code-block/plugin.js +123 -144
- package/dist/extension/plugins/code-block/render-elem/constant.js +15 -11
- package/dist/extension/plugins/code-block/render-elem/index.js +30 -39
- package/dist/extension/plugins/code-block/render-elem/language-selector.js +19 -27
- package/dist/extension/plugins/formula/helper.js +39 -45
- package/dist/extension/plugins/formula/index.js +10 -17
- package/dist/extension/plugins/formula/menu/formula-modal.js +37 -52
- package/dist/extension/plugins/formula/menu/index.js +34 -50
- package/dist/extension/plugins/formula/plugin.js +12 -14
- package/dist/extension/plugins/formula/render-elem.js +27 -33
- package/dist/extension/plugins/header/helper.js +35 -48
- package/dist/extension/plugins/header/index.js +10 -17
- package/dist/extension/plugins/header/menu/index.js +52 -66
- package/dist/extension/plugins/header/plugin.js +72 -83
- package/dist/extension/plugins/header/render-elem.js +15 -20
- package/dist/extension/plugins/image/helper.js +28 -37
- package/dist/extension/plugins/image/index.js +10 -17
- package/dist/extension/plugins/image/menu/image-menu-dialog.js +31 -42
- package/dist/extension/plugins/image/menu/image-menu-popover.js +35 -67
- package/dist/extension/plugins/image/menu/index.js +24 -34
- package/dist/extension/plugins/image/plugin.js +18 -18
- package/dist/extension/plugins/image/render-element/image-previewer.js +32 -42
- package/dist/extension/plugins/image/render-element/index.js +58 -74
- package/dist/extension/plugins/index.js +18 -94
- package/dist/extension/plugins/link/helper.js +102 -139
- package/dist/extension/plugins/link/index.js +10 -17
- package/dist/extension/plugins/link/menu/index.js +46 -62
- package/dist/extension/plugins/link/menu/link-modal.js +67 -87
- package/dist/extension/plugins/link/plugin.js +52 -56
- package/dist/extension/plugins/link/render-elem/index.js +39 -54
- package/dist/extension/plugins/link/render-elem/link-popover.js +38 -42
- package/dist/extension/plugins/list/constant.js +2 -8
- package/dist/extension/plugins/list/helpers.js +40 -54
- package/dist/extension/plugins/list/index.js +10 -17
- package/dist/extension/plugins/list/menu/index.js +23 -33
- package/dist/extension/plugins/list/plugin/index.js +28 -31
- package/dist/extension/plugins/list/plugin/insert-break-list.js +9 -15
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +86 -109
- package/dist/extension/plugins/list/plugin/normalize-list.js +31 -42
- package/dist/extension/plugins/list/plugin/on-tab-handle.js +35 -34
- package/dist/extension/plugins/list/queries/index.js +22 -30
- package/dist/extension/plugins/list/render-elem/index.js +27 -27
- package/dist/extension/plugins/list/transforms/index.js +11 -75
- package/dist/extension/plugins/list/transforms/insert-list-item.js +38 -47
- package/dist/extension/plugins/list/transforms/move-list-item-down.js +22 -32
- package/dist/extension/plugins/list/transforms/move-list-item-up.js +45 -56
- package/dist/extension/plugins/list/transforms/move-list-items-to-list.js +25 -31
- package/dist/extension/plugins/list/transforms/move-list-items.js +37 -44
- package/dist/extension/plugins/list/transforms/normalize-list-item.js +57 -81
- package/dist/extension/plugins/list/transforms/normalize-nested-list.js +17 -26
- package/dist/extension/plugins/list/transforms/remove-first-list-item.js +12 -19
- package/dist/extension/plugins/list/transforms/transforms-to-list.js +60 -84
- package/dist/extension/plugins/list/transforms/unwrap-list.js +20 -29
- package/dist/extension/plugins/node-id/constants.js +9 -15
- package/dist/extension/plugins/node-id/helpers.js +33 -35
- package/dist/extension/plugins/node-id/index.js +4 -11
- package/dist/extension/plugins/node-id/with-node-id.js +18 -26
- package/dist/extension/plugins/paragraph/helper.js +7 -13
- package/dist/extension/plugins/paragraph/index.js +8 -15
- package/dist/extension/plugins/paragraph/plugin.js +25 -27
- package/dist/extension/plugins/paragraph/render-elem.js +9 -14
- package/dist/extension/plugins/table/constant.js +3 -9
- package/dist/extension/plugins/table/helper.js +133 -154
- package/dist/extension/plugins/table/index.js +11 -19
- package/dist/extension/plugins/table/menu/index.js +26 -38
- package/dist/extension/plugins/table/menu/table-operator.js +62 -77
- package/dist/extension/plugins/table/menu/table-size-selector.js +41 -62
- package/dist/extension/plugins/table/model.js +39 -41
- package/dist/extension/plugins/table/plugin.js +95 -102
- package/dist/extension/plugins/table/render-elem/context-menu.js +42 -65
- package/dist/extension/plugins/table/render-elem/index.js +85 -93
- package/dist/extension/plugins/table/table-operations.js +101 -118
- package/dist/extension/plugins/text-style/helpers.js +18 -28
- package/dist/extension/plugins/text-style/index.js +8 -15
- package/dist/extension/plugins/text-style/menu/index.js +19 -25
- package/dist/extension/plugins/text-style/plugin.js +16 -21
- package/dist/extension/plugins/text-style/render-elem.js +28 -33
- package/dist/extension/render/render-element.js +26 -47
- package/dist/extension/render/render-leaf.js +9 -18
- package/dist/extension/toolbar/header-toolbar/index.js +66 -84
- package/dist/extension/toolbar/index.js +2 -13
- package/dist/extension/toolbar/user-help/shortcut-dialog.js +108 -131
- package/dist/hooks/use-mathjax.js +9 -20
- package/dist/hooks/use-scroll-context.js +7 -12
- package/dist/hooks/use-selection-update.js +9 -21
- package/dist/index.js +9 -80
- package/dist/pages/markdown-editor.js +30 -43
- package/dist/pages/markdown-view.js +25 -37
- package/dist/pages/rich-markdown-editor.js +54 -67
- package/dist/pages/simple-editor.js +29 -42
- package/dist/slate-convert/html-to-slate/constants.js +26 -32
- package/dist/slate-convert/html-to-slate/helper.js +1 -7
- package/dist/slate-convert/html-to-slate/index.js +44 -51
- package/dist/slate-convert/html-to-slate/rules/blockquote.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/check-list.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/code-block.js +40 -51
- package/dist/slate-convert/html-to-slate/rules/header.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/image.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/index.js +11 -18
- package/dist/slate-convert/html-to-slate/rules/link.js +11 -16
- package/dist/slate-convert/html-to-slate/rules/list.js +21 -26
- package/dist/slate-convert/html-to-slate/rules/paragraph.js +10 -15
- package/dist/slate-convert/html-to-slate/rules/table.js +14 -19
- package/dist/slate-convert/html-to-slate/rules/text.js +14 -19
- package/dist/slate-convert/index.js +8 -34
- package/dist/slate-convert/md-to-html/index.js +26 -31
- package/dist/slate-convert/md-to-html/sanitize-schema.js +5 -12
- package/dist/slate-convert/md-to-slate/index.js +17 -23
- package/dist/slate-convert/md-to-slate/transform.js +183 -175
- package/dist/slate-convert/slate-to-md/index.js +14 -20
- package/dist/slate-convert/slate-to-md/transform.js +76 -87
- package/dist/utils/common.js +8 -15
- package/dist/utils/deserialize-html.js +118 -166
- package/dist/utils/dom-utils.js +18 -22
- package/dist/utils/event-bus.js +27 -47
- package/dist/utils/event-handler.js +29 -38
- package/dist/utils/object-utils.js +39 -62
- package/package.json +5 -4
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.focusEditor = void 0;
|
|
7
|
-
var _slate = require("slate");
|
|
8
|
-
var _slateReact = require("slate-react");
|
|
9
|
-
var focusEditor = exports.focusEditor = function focusEditor(editor, target) {
|
|
1
|
+
import { Editor, Transforms } from 'slate';
|
|
2
|
+
import { ReactEditor } from 'slate-react';
|
|
3
|
+
export const focusEditor = (editor, target) => {
|
|
10
4
|
if (target) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
Editor.withoutNormalizing(editor, () => {
|
|
6
|
+
Transforms.deselect(editor);
|
|
7
|
+
Transforms.select(editor, target);
|
|
14
8
|
});
|
|
15
9
|
}
|
|
16
|
-
|
|
10
|
+
ReactEditor.focus(editor);
|
|
17
11
|
};
|
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
var _moveChildren = require("./move-children");
|
|
7
|
-
Object.keys(_moveChildren).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _moveChildren[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _moveChildren[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _removeNodeChildren = require("./remove-node-children");
|
|
18
|
-
Object.keys(_removeNodeChildren).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _removeNodeChildren[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _removeNodeChildren[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _focusEditor = require("./focus-editor");
|
|
29
|
-
Object.keys(_focusEditor).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _focusEditor[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function get() {
|
|
35
|
-
return _focusEditor[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _replaceNodeChildren = require("./replace-node-children");
|
|
40
|
-
Object.keys(_replaceNodeChildren).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _replaceNodeChildren[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function get() {
|
|
46
|
-
return _replaceNodeChildren[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
export * from './move-children';
|
|
2
|
+
export * from './remove-node-children';
|
|
3
|
+
export * from './focus-editor';
|
|
4
|
+
export * from './replace-node-children';
|
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
to = _ref.to,
|
|
14
|
-
match = _ref.match,
|
|
15
|
-
_ref$fromStartIndex = _ref.fromStartIndex,
|
|
16
|
-
fromStartIndex = _ref$fromStartIndex === void 0 ? 0 : _ref$fromStartIndex;
|
|
17
|
-
var moved = 0;
|
|
18
|
-
var parentPath = _slate.Path.isPath(at) ? at : at[1];
|
|
19
|
-
var parentNode = _slate.Path.isPath(at) ? (0, _queries.getNode)(editor, parentPath) : at[0];
|
|
1
|
+
import { Editor, Path, Transforms } from 'slate';
|
|
2
|
+
import { getNode } from '../queries';
|
|
3
|
+
export const moveChildren = (editor, _ref) => {
|
|
4
|
+
let {
|
|
5
|
+
at,
|
|
6
|
+
to,
|
|
7
|
+
match,
|
|
8
|
+
fromStartIndex = 0
|
|
9
|
+
} = _ref;
|
|
10
|
+
let moved = 0;
|
|
11
|
+
const parentPath = Path.isPath(at) ? at : at[1];
|
|
12
|
+
const parentNode = Path.isPath(at) ? getNode(editor, parentPath) : at[0];
|
|
20
13
|
if (!parentNode) return moved;
|
|
21
14
|
// There have none children in a not block element
|
|
22
|
-
if (!
|
|
23
|
-
for (
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
if (!Editor.isBlock(editor, parentNode)) return moved;
|
|
16
|
+
for (let i = parentNode.children.length - 1; i >= fromStartIndex; i--) {
|
|
17
|
+
const childPath = [...parentPath, i];
|
|
18
|
+
const childNode = getNode(editor, childPath);
|
|
26
19
|
if (!match || childNode && match([childNode, childPath])) {
|
|
27
|
-
|
|
20
|
+
Transforms.moveNodes(editor, {
|
|
28
21
|
at: childPath,
|
|
29
|
-
to
|
|
22
|
+
to
|
|
30
23
|
});
|
|
31
24
|
moved++;
|
|
32
25
|
}
|
|
@@ -1,31 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.removeNodeChildren = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
10
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createForOfIteratorHelper"));
|
|
11
|
-
var _slate = require("slate");
|
|
12
|
-
var removeNodeChildren = exports.removeNodeChildren = function removeNodeChildren(editor, path, options) {
|
|
13
|
-
var nodeChildren = _slate.Node.children(editor, path, {
|
|
1
|
+
import { Transforms, Node } from 'slate';
|
|
2
|
+
export const removeNodeChildren = (editor, path, options) => {
|
|
3
|
+
const nodeChildren = Node.children(editor, path, {
|
|
14
4
|
reverse: true
|
|
15
5
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
childPath = _step$value[1];
|
|
22
|
-
_slate.Transforms.removeNodes(editor, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, options), {}, {
|
|
23
|
-
at: childPath
|
|
24
|
-
}));
|
|
25
|
-
}
|
|
26
|
-
} catch (err) {
|
|
27
|
-
_iterator.e(err);
|
|
28
|
-
} finally {
|
|
29
|
-
_iterator.f();
|
|
6
|
+
for (const [, childPath] of nodeChildren) {
|
|
7
|
+
Transforms.removeNodes(editor, {
|
|
8
|
+
...options,
|
|
9
|
+
at: childPath
|
|
10
|
+
});
|
|
30
11
|
}
|
|
31
12
|
};
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
insertOptions = _ref.insertOptions,
|
|
15
|
-
removeOptions = _ref.removeOptions;
|
|
16
|
-
_slate.Editor.withoutNormalizing(editor, function () {
|
|
17
|
-
(0, _removeNodeChildren.removeNodeChildren)(editor, at, removeOptions);
|
|
18
|
-
_slate.Transforms.insertNodes(editor, nodes, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, insertOptions), {}, {
|
|
1
|
+
import { Editor, Transforms } from 'slate';
|
|
2
|
+
import { removeNodeChildren } from './remove-node-children';
|
|
3
|
+
export const replaceNodeChildren = (editor, _ref) => {
|
|
4
|
+
let {
|
|
5
|
+
at,
|
|
6
|
+
nodes,
|
|
7
|
+
insertOptions,
|
|
8
|
+
removeOptions
|
|
9
|
+
} = _ref;
|
|
10
|
+
Editor.withoutNormalizing(editor, () => {
|
|
11
|
+
removeNodeChildren(editor, at, removeOptions);
|
|
12
|
+
Transforms.insertNodes(editor, nodes, {
|
|
13
|
+
...insertOptions,
|
|
19
14
|
at: at.concat([0])
|
|
20
|
-
})
|
|
15
|
+
});
|
|
21
16
|
});
|
|
22
17
|
};
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.match = exports.isEmptyParagraph = exports.generateEmptyElement = exports.generateElement = exports.generateDefaultText = exports.generateDefaultParagraph = exports.Placeholder = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
10
|
-
var _slugid = _interopRequireDefault(require("slugid"));
|
|
11
|
-
var _reactI18next = require("react-i18next");
|
|
12
|
-
var _elementTypes = require("../../constants/element-types");
|
|
13
|
-
var match = exports.match = function match(node, path, predicate) {
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { PARAGRAPH } from '../../constants/element-types';
|
|
4
|
+
export const match = (node, path, predicate) => {
|
|
14
5
|
if (!predicate) return true;
|
|
15
6
|
if (typeof predicate === 'object') {
|
|
16
|
-
return Object.entries(predicate).every(
|
|
17
|
-
|
|
18
|
-
key = _ref2[0],
|
|
19
|
-
value = _ref2[1];
|
|
7
|
+
return Object.entries(predicate).every(_ref => {
|
|
8
|
+
let [key, value] = _ref;
|
|
20
9
|
if (value && !Array.isArray(value)) {
|
|
21
10
|
return node[key] === value;
|
|
22
11
|
}
|
|
@@ -26,23 +15,23 @@ var match = exports.match = function match(node, path, predicate) {
|
|
|
26
15
|
}
|
|
27
16
|
return predicate(node, path);
|
|
28
17
|
};
|
|
29
|
-
|
|
18
|
+
export const generateDefaultText = () => {
|
|
30
19
|
return {
|
|
31
|
-
id:
|
|
20
|
+
id: slugid.nice(),
|
|
32
21
|
text: ''
|
|
33
22
|
};
|
|
34
23
|
};
|
|
35
|
-
|
|
24
|
+
export const generateDefaultParagraph = () => {
|
|
36
25
|
return {
|
|
37
|
-
id:
|
|
38
|
-
type:
|
|
26
|
+
id: slugid.nice(),
|
|
27
|
+
type: PARAGRAPH,
|
|
39
28
|
children: [generateDefaultText()]
|
|
40
29
|
};
|
|
41
30
|
};
|
|
42
|
-
|
|
31
|
+
export const generateEmptyElement = type => {
|
|
43
32
|
return {
|
|
44
|
-
id:
|
|
45
|
-
type
|
|
33
|
+
id: slugid.nice(),
|
|
34
|
+
type,
|
|
46
35
|
children: [generateDefaultText()]
|
|
47
36
|
};
|
|
48
37
|
};
|
|
@@ -54,39 +43,42 @@ var generateEmptyElement = exports.generateEmptyElement = function generateEmpty
|
|
|
54
43
|
* @param {object} [options.props = {}]
|
|
55
44
|
* @returns {Node}
|
|
56
45
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
childrenOrText =
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
export const generateElement = function (type) {
|
|
47
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
48
|
+
let {
|
|
49
|
+
childrenOrText = '',
|
|
50
|
+
props = {}
|
|
51
|
+
} = options;
|
|
63
52
|
if (typeof childrenOrText === 'string') {
|
|
64
53
|
childrenOrText = [{
|
|
65
|
-
id:
|
|
54
|
+
id: slugid.nice(),
|
|
66
55
|
text: childrenOrText
|
|
67
56
|
}];
|
|
68
57
|
}
|
|
69
58
|
if (!Array.isArray(childrenOrText)) {
|
|
70
59
|
throw Error('childrenOrText must be a string or a Node array!');
|
|
71
60
|
}
|
|
72
|
-
return
|
|
73
|
-
id:
|
|
74
|
-
type
|
|
75
|
-
children: childrenOrText
|
|
76
|
-
|
|
61
|
+
return {
|
|
62
|
+
id: slugid.nice(),
|
|
63
|
+
type,
|
|
64
|
+
children: childrenOrText,
|
|
65
|
+
...props
|
|
66
|
+
};
|
|
77
67
|
};
|
|
78
|
-
|
|
68
|
+
export const isEmptyParagraph = node => {
|
|
79
69
|
if (node.type !== 'paragraph') return false;
|
|
80
70
|
if (node.children.length !== 1) return false;
|
|
81
|
-
|
|
82
|
-
child = _node$children[0];
|
|
71
|
+
const [child] = node.children;
|
|
83
72
|
if (Text.isText(child) && child.text === '' && child.type !== 'image') return true;
|
|
84
73
|
return false;
|
|
85
74
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
export const Placeholder = props => {
|
|
76
|
+
const {
|
|
77
|
+
title
|
|
78
|
+
} = props;
|
|
79
|
+
const {
|
|
80
|
+
t
|
|
81
|
+
} = useTranslation();
|
|
90
82
|
return /*#__PURE__*/React.createElement("span", {
|
|
91
83
|
style: {
|
|
92
84
|
position: 'absolute',
|
package/dist/extension/editor.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _slate = require("slate");
|
|
9
|
-
var _slateHistory = require("slate-history");
|
|
10
|
-
var _slateReact = require("slate-react");
|
|
11
|
-
var _plugins = _interopRequireDefault(require("./plugins"));
|
|
12
|
-
var baseEditor = _plugins.default.reduce(function (editor, pluginItem) {
|
|
13
|
-
var withPlugin = pluginItem.editorPlugin;
|
|
1
|
+
import { createEditor } from 'slate';
|
|
2
|
+
import { withHistory } from 'slate-history';
|
|
3
|
+
import { withReact } from 'slate-react';
|
|
4
|
+
import Plugins from './plugins';
|
|
5
|
+
const baseEditor = Plugins.reduce((editor, pluginItem) => {
|
|
6
|
+
const withPlugin = pluginItem.editorPlugin;
|
|
14
7
|
if (withPlugin) {
|
|
15
8
|
return withPlugin(editor);
|
|
16
9
|
}
|
|
17
10
|
return editor;
|
|
18
|
-
},
|
|
19
|
-
|
|
11
|
+
}, withHistory(withReact(createEditor())));
|
|
12
|
+
export default baseEditor;
|
package/dist/extension/index.js
CHANGED
|
@@ -1,48 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function get() {
|
|
10
|
-
return _constants.ELementTypes;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "Toolbar", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function get() {
|
|
16
|
-
return _toolbar.Toolbar;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "baseEditor", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function get() {
|
|
22
|
-
return _editor.default;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(exports, "isEmptyParagraph", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function get() {
|
|
28
|
-
return _core.isEmptyParagraph;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "renderElement", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function get() {
|
|
34
|
-
return _renderElement.default;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, "renderLeaf", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function get() {
|
|
40
|
-
return _renderLeaf.default;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
var _constants = require("./constants");
|
|
44
|
-
var _core = require("./core");
|
|
45
|
-
var _renderElement = _interopRequireDefault(require("./render/render-element"));
|
|
46
|
-
var _renderLeaf = _interopRequireDefault(require("./render/render-leaf"));
|
|
47
|
-
var _toolbar = require("./toolbar");
|
|
48
|
-
var _editor = _interopRequireDefault(require("./editor"));
|
|
1
|
+
import { ELementTypes } from './constants';
|
|
2
|
+
import { isEmptyParagraph } from './core';
|
|
3
|
+
import renderElement from './render/render-element';
|
|
4
|
+
import renderLeaf from './render/render-leaf';
|
|
5
|
+
import { Toolbar } from './toolbar';
|
|
6
|
+
import baseEditor from './editor';
|
|
7
|
+
export { ELementTypes, isEmptyParagraph, renderElement, renderLeaf, Toolbar, baseEditor };
|
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.setBlockQuoteType = exports.isMenuDisabled = exports.getBlockQuoteType = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
9
|
-
var _slate = require("slate");
|
|
10
|
-
var _slugid = _interopRequireDefault(require("slugid"));
|
|
11
|
-
var _elementTypes = require("../../constants/element-types");
|
|
12
|
-
var _core = require("../../core");
|
|
13
|
-
var isMenuDisabled = exports.isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
1
|
+
import { Editor, Transforms, Element } from 'slate';
|
|
2
|
+
import slugid from 'slugid';
|
|
3
|
+
import { BLOCKQUOTE, CHECK_LIST_ITEM, IMAGE, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST } from '../../constants/element-types';
|
|
4
|
+
import { focusEditor, getNodeType } from '../../core';
|
|
5
|
+
export const isMenuDisabled = (editor, readonly) => {
|
|
14
6
|
if (readonly) return true;
|
|
15
7
|
if (editor.selection == null) return true;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const [nodeEntry] = Editor.nodes(editor, {
|
|
9
|
+
match: n => {
|
|
10
|
+
const type = getNodeType(n);
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_Editor$nodes2 = (0, _slicedToArray2.default)(_Editor$nodes, 1),
|
|
34
|
-
nodeEntry = _Editor$nodes2[0];
|
|
12
|
+
// Only available for p and blockquote
|
|
13
|
+
if (type === PARAGRAPH) return true;
|
|
14
|
+
if (type === BLOCKQUOTE) return true;
|
|
15
|
+
if (type === UNORDERED_LIST) return true;
|
|
16
|
+
if (type === ORDERED_LIST) return true;
|
|
17
|
+
if (type === CHECK_LIST_ITEM) return true;
|
|
18
|
+
if (type && type.startWith && type.startWith('header')) return true;
|
|
19
|
+
if (type === IMAGE) return true;
|
|
20
|
+
return false;
|
|
21
|
+
},
|
|
22
|
+
universal: true,
|
|
23
|
+
mode: 'highest' // Match top level
|
|
24
|
+
});
|
|
35
25
|
|
|
36
26
|
// Match to p blockquote, do not disable
|
|
37
27
|
if (nodeEntry) {
|
|
@@ -39,39 +29,30 @@ var isMenuDisabled = exports.isMenuDisabled = function isMenuDisabled(editor, re
|
|
|
39
29
|
}
|
|
40
30
|
return true;
|
|
41
31
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
match = _Editor$nodes4[0];
|
|
51
|
-
if (!match) return _elementTypes.PARAGRAPH;
|
|
52
|
-
var _match = (0, _slicedToArray2.default)(match, 1),
|
|
53
|
-
n = _match[0];
|
|
54
|
-
return (0, _core.getNodeType)(n);
|
|
32
|
+
export const getBlockQuoteType = editor => {
|
|
33
|
+
const [match] = Editor.nodes(editor, {
|
|
34
|
+
match: n => getNodeType(n) === BLOCKQUOTE,
|
|
35
|
+
universal: true
|
|
36
|
+
});
|
|
37
|
+
if (!match) return PARAGRAPH;
|
|
38
|
+
const [n] = match;
|
|
39
|
+
return getNodeType(n);
|
|
55
40
|
};
|
|
56
|
-
|
|
41
|
+
export const setBlockQuoteType = (editor, active) => {
|
|
57
42
|
if (!active) {
|
|
58
|
-
|
|
59
|
-
id:
|
|
60
|
-
type:
|
|
43
|
+
const blockquoteNode = {
|
|
44
|
+
id: slugid.nice(),
|
|
45
|
+
type: BLOCKQUOTE
|
|
61
46
|
};
|
|
62
|
-
|
|
47
|
+
Transforms.wrapNodes(editor, blockquoteNode, {
|
|
63
48
|
mode: 'highest',
|
|
64
|
-
match:
|
|
65
|
-
return _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n);
|
|
66
|
-
}
|
|
49
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n)
|
|
67
50
|
});
|
|
68
51
|
} else {
|
|
69
|
-
|
|
52
|
+
Transforms.unwrapNodes(editor, {
|
|
70
53
|
mode: 'highest',
|
|
71
|
-
match:
|
|
72
|
-
return _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n);
|
|
73
|
-
}
|
|
54
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n)
|
|
74
55
|
});
|
|
75
56
|
}
|
|
76
|
-
|
|
57
|
+
focusEditor(editor);
|
|
77
58
|
};
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _elementTypes = require("../../constants/element-types");
|
|
9
|
-
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
10
|
-
var _renderElem = _interopRequireDefault(require("./render-elem"));
|
|
11
|
-
var BlockquotePlugin = {
|
|
12
|
-
type: _elementTypes.BLOCKQUOTE,
|
|
1
|
+
import { BLOCKQUOTE } from '../../constants/element-types';
|
|
2
|
+
import withBlockquote from './plugin';
|
|
3
|
+
import renderBlockquote from './render-elem';
|
|
4
|
+
const BlockquotePlugin = {
|
|
5
|
+
type: BLOCKQUOTE,
|
|
13
6
|
nodeType: 'element',
|
|
14
7
|
editorMenus: [],
|
|
15
|
-
editorPlugin:
|
|
16
|
-
renderElements: [
|
|
8
|
+
editorPlugin: withBlockquote,
|
|
9
|
+
renderElements: [renderBlockquote]
|
|
17
10
|
};
|
|
18
|
-
|
|
11
|
+
export default BlockquotePlugin;
|
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _commons = require("../../../commons");
|
|
10
|
-
var _menusConfig = require("../../../constants/menus-config");
|
|
11
|
-
var _elementTypes = require("../../../constants/element-types");
|
|
12
|
-
var _helpers = require("../helpers");
|
|
13
|
-
var menuConfig = _menusConfig.MENUS_CONFIG_MAP[_elementTypes.BLOCKQUOTE];
|
|
14
|
-
var isActive = function isActive(editor) {
|
|
15
|
-
return (0, _helpers.getBlockQuoteType)(editor) === _elementTypes.BLOCKQUOTE;
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { MenuItem } from '../../../commons';
|
|
3
|
+
import { MENUS_CONFIG_MAP } from '../../../constants/menus-config';
|
|
4
|
+
import { BLOCKQUOTE } from '../../../constants/element-types';
|
|
5
|
+
import { getBlockQuoteType, isMenuDisabled, setBlockQuoteType } from '../helpers';
|
|
6
|
+
const menuConfig = MENUS_CONFIG_MAP[BLOCKQUOTE];
|
|
7
|
+
const isActive = editor => {
|
|
8
|
+
return getBlockQuoteType(editor) === BLOCKQUOTE;
|
|
16
9
|
};
|
|
17
|
-
function BlockquoteMenu(_ref) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
export default function BlockquoteMenu(_ref) {
|
|
11
|
+
let {
|
|
12
|
+
isRichEditor,
|
|
13
|
+
className,
|
|
14
|
+
readonly,
|
|
15
|
+
editor
|
|
16
|
+
} = _ref;
|
|
17
|
+
const onMousedown = useCallback(event => {
|
|
18
|
+
const active = isActive(editor);
|
|
19
|
+
setBlockQuoteType(editor, active);
|
|
25
20
|
}, [editor]);
|
|
26
|
-
return /*#__PURE__*/
|
|
21
|
+
return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
|
|
27
22
|
isRichEditor: isRichEditor,
|
|
28
23
|
className: className,
|
|
29
|
-
disabled:
|
|
24
|
+
disabled: isMenuDisabled(editor, readonly),
|
|
30
25
|
isActive: isActive(editor),
|
|
31
26
|
onMouseDown: onMousedown
|
|
32
27
|
}, menuConfig));
|