@seafile/seafile-editor 0.4.8 → 1.0.0
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/.babelrc +5 -0
- package/.eslintignore +19 -0
- package/.eslintrc.json +52 -0
- package/.github/workflows/nodejs.yml +25 -0
- package/.vscode/settings.json +5 -0
- package/config/config.common.js +157 -0
- package/config/config.dev.js +53 -0
- package/config/jest/cssTransform.js +16 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/utils/theme.css.js +103 -0
- package/config.js +61 -0
- package/dev-server.js +145 -0
- package/jest.config.js +16 -0
- package/package.json +81 -131
- package/public/locales/en/seafile-editor.json +145 -148
- package/public/locales/zh-CN/seafile-editor.json +123 -135
- package/public/media/seafile-ui.css +6 -11166
- package/scripts/ejs.js +16 -0
- package/site/_i18n/index.js +35 -0
- package/site/api/index.js +212 -0
- package/site/app.js +21 -0
- package/site/assets/css/app.css +47 -0
- package/site/assets/css/seafile-editor.css +33 -0
- package/site/commons/loading/index.js +14 -0
- package/site/commons/loading/style.css +49 -0
- package/site/commons/switch/index.css +14 -0
- package/site/commons/switch/index.js +37 -0
- package/site/commons/toast/alert.js +106 -0
- package/site/commons/toast/index.js +5 -0
- package/site/commons/toast/toast.js +195 -0
- package/site/commons/toast/toastManager.js +138 -0
- package/site/commons/toast/toaster.js +64 -0
- package/site/index.html +23 -0
- package/site/index.js +21 -0
- package/site/pages/home.js +21 -0
- package/site/pages/plain-markdown-view.js +6 -0
- package/site/pages/rich-seafile-editor.js +72 -0
- package/site/pages/seafile-editor.js +39 -0
- package/site/pages/seafile-viewer.js +45 -0
- package/site/pages/simple-editor.js +44 -0
- package/site/pages/wiki-viewer.js +7 -0
- package/site/setting.js +36 -0
- package/site/setting.local.dist.js +23 -0
- package/src/assets/css/slate-editor.css +57 -0
- package/src/constants/event-types.js +11 -0
- package/src/constants/hot-keys.js +47 -0
- package/src/containers/article-info/index.js +49 -0
- package/src/containers/article-info/style.css +52 -0
- package/src/containers/custom/get-event-transfer.js +28 -0
- package/{dist → src}/containers/custom/set-event-transfer.js +13 -11
- package/src/containers/hotkeys-helper/classify-hotkeys.js +30 -0
- package/src/containers/hotkeys-helper/index.js +43 -0
- package/{dist/assets/css/user-help.css → src/containers/hotkeys-helper/style.css} +37 -29
- package/src/containers/loading/index.js +14 -0
- package/src/containers/loading/style.css +49 -0
- package/src/containers/outline/index.js +75 -0
- package/src/containers/outline/outline-item.js +28 -0
- package/src/containers/outline/style.css +45 -0
- package/src/editors/plain-markdown-editor/code-mirror.css +8 -0
- package/src/editors/plain-markdown-editor/code-mirror.js +73 -0
- package/src/editors/plain-markdown-editor/index.js +136 -0
- package/{dist/assets/editor/plain-editor.css → src/editors/plain-markdown-editor/style.css} +12 -4
- package/src/editors/simple-slate-editor /index.js +71 -0
- package/src/editors/simple-slate-editor /with-props-editor.js +15 -0
- package/src/editors/slate-editor/editor-help/index.js +46 -0
- package/src/editors/slate-editor/editor-help/style.css +15 -0
- package/src/editors/slate-editor/index.js +77 -0
- package/src/editors/slate-editor/with-props-editor.js +15 -0
- package/src/editors/slate-viewer/index.js +35 -0
- package/src/editors/slate-viewer/style.css +40 -0
- package/src/extension/commons/element-popover/index.js +52 -0
- package/src/extension/commons/index.js +10 -0
- package/src/extension/commons/menu/index.js +9 -0
- package/src/extension/commons/menu/menu-drop-down.js +110 -0
- package/src/extension/commons/menu/menu-group.js +20 -0
- package/src/extension/commons/menu/menu-item.js +60 -0
- package/src/extension/commons/menu/menu.css +120 -0
- package/src/extension/commons/tooltip/index.css +21 -0
- package/src/extension/commons/tooltip/index.js +26 -0
- package/src/extension/constants/element-types.js +23 -0
- package/src/extension/constants/index.js +37 -0
- package/src/extension/constants/keyboard.js +29 -0
- package/src/extension/constants/menus-config.js +149 -0
- package/src/extension/core/index.js +3 -0
- package/src/extension/core/queries/index.js +410 -0
- package/src/extension/core/transforms/focus-editor.js +12 -0
- package/src/extension/core/transforms/index.js +4 -0
- package/src/extension/core/transforms/move-children.js +23 -0
- package/src/extension/core/transforms/remove-node-children.js +8 -0
- package/src/extension/core/transforms/replace-node-children.js +14 -0
- package/src/extension/core/utils/index.js +76 -0
- package/src/extension/editor.js +14 -0
- package/src/extension/index.js +15 -0
- package/src/extension/plugins/blockquote/helpers.js +65 -0
- package/src/extension/plugins/blockquote/index.js +13 -0
- package/src/extension/plugins/blockquote/menu/index.js +31 -0
- package/src/extension/plugins/blockquote/plugin.js +64 -0
- package/src/extension/plugins/blockquote/render-elem.js +9 -0
- package/src/extension/plugins/check-list/helper.js +34 -0
- package/src/extension/plugins/check-list/index.js +14 -0
- package/src/extension/plugins/check-list/menu/index.js +44 -0
- package/src/extension/plugins/check-list/plugin.js +46 -0
- package/src/extension/plugins/check-list/render-elem.js +23 -0
- package/src/extension/plugins/clear-format/helpers.js +48 -0
- package/src/extension/plugins/clear-format/menu/index.js +39 -0
- package/src/extension/plugins/code-block/helpers.js +107 -0
- package/src/extension/plugins/code-block/index.js +14 -0
- package/src/extension/plugins/code-block/menu/index.js +40 -0
- package/src/extension/plugins/code-block/plugin.js +210 -0
- package/src/extension/plugins/code-block/render-elem/constant.js +17 -0
- package/src/extension/plugins/code-block/render-elem/index.js +55 -0
- package/src/extension/plugins/code-block/render-elem/language-selector.js +38 -0
- package/src/extension/plugins/code-block/render-elem/style.css +27 -0
- package/src/extension/plugins/formula/formula.css +22 -0
- package/src/extension/plugins/formula/helper.js +68 -0
- package/src/extension/plugins/formula/index.js +14 -0
- package/src/extension/plugins/formula/menu/formula-modal.js +73 -0
- package/src/extension/plugins/formula/menu/index.js +63 -0
- package/src/extension/plugins/formula/plugin.js +18 -0
- package/src/extension/plugins/formula/render-elem.js +40 -0
- package/src/extension/plugins/header/helper.js +47 -0
- package/src/extension/plugins/header/index.js +14 -0
- package/src/extension/plugins/header/menu/index.js +114 -0
- package/src/extension/plugins/header/menu/style.css +115 -0
- package/src/extension/plugins/header/plugin.js +134 -0
- package/src/extension/plugins/header/render-elem.js +31 -0
- package/src/extension/plugins/image/helper.js +50 -0
- package/src/extension/plugins/image/index.js +14 -0
- package/src/extension/plugins/image/menu/image-menu-dialog.js +68 -0
- package/src/extension/plugins/image/menu/image-menu-popover.js +76 -0
- package/src/extension/plugins/image/menu/index.js +61 -0
- package/src/extension/plugins/image/menu/style.css +36 -0
- package/src/extension/plugins/image/plugin.js +23 -0
- package/src/extension/plugins/image/render-element/image-previewer.js +71 -0
- package/src/extension/plugins/image/render-element/index.js +94 -0
- package/src/extension/plugins/image/render-element/style.css +60 -0
- package/src/extension/plugins/index.js +47 -0
- package/src/extension/plugins/link/helper.js +161 -0
- package/src/extension/plugins/link/index.js +14 -0
- package/src/extension/plugins/link/menu/index.js +82 -0
- package/src/extension/plugins/link/menu/link-modal.js +135 -0
- package/src/extension/plugins/link/plugin.js +85 -0
- package/src/extension/plugins/link/render-elem/index.js +69 -0
- package/src/extension/plugins/link/render-elem/link-popover.js +79 -0
- package/src/extension/plugins/link/render-elem/style.css +60 -0
- package/src/extension/plugins/list/constant.js +3 -0
- package/src/extension/plugins/list/helpers.js +53 -0
- package/src/extension/plugins/list/index.js +14 -0
- package/src/extension/plugins/list/menu/index.js +48 -0
- package/src/extension/plugins/list/plugin/index.js +48 -0
- package/src/extension/plugins/list/plugin/insert-break-list.js +25 -0
- package/src/extension/plugins/list/plugin/insert-fragment-list.js +162 -0
- package/src/extension/plugins/list/plugin/normalize-list.js +64 -0
- package/src/extension/plugins/list/plugin/on-tab-handle.js +34 -0
- package/src/extension/plugins/list/queries/index.js +39 -0
- package/src/extension/plugins/list/render-elem/index.js +26 -0
- package/src/extension/plugins/list/render-elem/style.css +6 -0
- package/src/extension/plugins/list/transforms/index.js +23 -0
- package/src/extension/plugins/list/transforms/insert-list-item.js +65 -0
- package/src/extension/plugins/list/transforms/move-list-item-down.js +40 -0
- package/src/extension/plugins/list/transforms/move-list-item-up.js +105 -0
- package/src/extension/plugins/list/transforms/move-list-items-to-list.js +58 -0
- package/src/extension/plugins/list/transforms/move-list-items.js +76 -0
- package/src/extension/plugins/list/transforms/normalize-list-item.js +92 -0
- package/src/extension/plugins/list/transforms/normalize-nested-list.js +31 -0
- package/src/extension/plugins/list/transforms/remove-first-list-item.js +11 -0
- package/src/extension/plugins/list/transforms/transforms-to-list.js +91 -0
- package/src/extension/plugins/list/transforms/unwrap-list.js +44 -0
- package/src/extension/plugins/node-id/constants.js +18 -0
- package/src/extension/plugins/node-id/helpers.js +61 -0
- package/src/extension/plugins/node-id/index.js +7 -0
- package/src/extension/plugins/node-id/with-node-id.js +37 -0
- package/src/extension/plugins/paragraph/helper.js +9 -0
- package/src/extension/plugins/paragraph/index.js +12 -0
- package/src/extension/plugins/paragraph/plugin.js +40 -0
- package/src/extension/plugins/paragraph/render-elem.js +11 -0
- package/src/extension/plugins/table/constant.js +3 -0
- package/src/extension/plugins/table/helper.js +175 -0
- package/src/extension/plugins/table/index.js +15 -0
- package/src/extension/plugins/table/menu/index.js +69 -0
- package/src/extension/plugins/table/menu/style.css +32 -0
- package/src/extension/plugins/table/menu/table-operator.js +101 -0
- package/src/extension/plugins/table/menu/table-size-selector.js +71 -0
- package/src/extension/plugins/table/model.js +69 -0
- package/src/extension/plugins/table/plugin.js +159 -0
- package/src/extension/plugins/table/render-elem/context-menu.js +78 -0
- package/src/extension/plugins/table/render-elem/index.js +157 -0
- package/src/extension/plugins/table/render-elem/style.css +94 -0
- package/src/extension/plugins/table/table-operations.js +162 -0
- package/src/extension/plugins/text-style/helpers.js +38 -0
- package/src/extension/plugins/text-style/index.js +12 -0
- package/src/extension/plugins/text-style/menu/index.js +41 -0
- package/src/extension/plugins/text-style/plugin.js +37 -0
- package/src/extension/plugins/text-style/render-elem.js +45 -0
- package/src/extension/render/render-element.js +82 -0
- package/src/extension/render/render-leaf.js +16 -0
- package/src/extension/toolbar/header-toolbar/index.js +129 -0
- package/src/extension/toolbar/header-toolbar/style.css +41 -0
- package/src/extension/toolbar/index.js +5 -0
- package/src/extension/toolbar/user-help/shortcut-dialog.js +144 -0
- package/src/hooks/use-mathjax.js +44 -0
- package/src/hooks/use-scroll-context.js +14 -0
- package/src/hooks/use-selection-update.js +14 -0
- package/src/index.js +22 -0
- package/src/pages/markdown-editor.js +53 -0
- package/src/pages/markdown-view.js +36 -0
- package/src/pages/rich-markdown-editor.js +95 -0
- package/src/pages/simple-editor.js +52 -0
- package/src/slate-convert/html-to-slate/constants.js +54 -0
- package/src/slate-convert/html-to-slate/helper.js +22 -0
- package/src/slate-convert/html-to-slate/index.js +144 -0
- package/src/slate-convert/html-to-slate/rules/blockquote.js +16 -0
- package/src/slate-convert/html-to-slate/rules/check-list.js +22 -0
- package/src/slate-convert/html-to-slate/rules/code-block.js +91 -0
- package/src/slate-convert/html-to-slate/rules/header.js +18 -0
- package/src/slate-convert/html-to-slate/rules/image.js +18 -0
- package/src/slate-convert/html-to-slate/rules/index.js +23 -0
- package/src/slate-convert/html-to-slate/rules/link.js +24 -0
- package/src/slate-convert/html-to-slate/rules/list.js +52 -0
- package/src/slate-convert/html-to-slate/rules/paragraph.js +16 -0
- package/src/slate-convert/html-to-slate/rules/table.js +37 -0
- package/src/slate-convert/html-to-slate/rules/text.js +63 -0
- package/src/slate-convert/index.js +11 -0
- package/src/slate-convert/md-to-html/index.js +44 -0
- package/src/slate-convert/md-to-html/sanitize-schema.js +41 -0
- package/src/slate-convert/md-to-slate/index.js +42 -0
- package/src/slate-convert/md-to-slate/transform.js +336 -0
- package/src/slate-convert/slate-to-md/index.js +44 -0
- package/src/slate-convert/slate-to-md/transform.js +248 -0
- package/src/utils/common.js +30 -0
- package/src/utils/deserialize-html.js +174 -0
- package/src/utils/dom-utils.js +45 -0
- package/src/utils/event-bus.js +37 -0
- package/src/utils/event-handler.js +36 -0
- package/src/utils/object-utils.js +51 -0
- package/tests/core/constants/index.js +54 -0
- package/tests/core/index.js +11 -0
- package/tests/core/jsx/index.js +9 -0
- package/tests/core/stub-editor/index.js +26 -0
- package/tests/core/utils.js +58 -0
- package/tests/extension/plugins/list/insert-block.test.js +40 -0
- package/tests/extension/plugins/list/insert-fragment-list.test.js +392 -0
- package/tests/extension/plugins/list/toggle-list.test.js +160 -0
- package/tests/extension/plugins/text/text.test.js +29 -0
- package/tests/extension/plugins/text-style/toggle-text-style.test.js +148 -0
- package/tests/slate-convert/html-to-slate/blockquote.test.js +107 -0
- package/tests/slate-convert/html-to-slate/code-block.test.js +32 -0
- package/tests/slate-convert/html-to-slate/header.test.js +56 -0
- package/tests/slate-convert/html-to-slate/link.test.js +77 -0
- package/tests/slate-convert/html-to-slate/list.test.js +190 -0
- package/tests/slate-convert/html-to-slate/paragraph.test.js +40 -0
- package/tests/slate-convert/html-to-slate/text.test.js +131 -0
- package/tests/slate-convert/md-to-html/blockquote.test.js +110 -0
- package/tests/slate-convert/md-to-html/check-list.test.js +19 -0
- package/tests/slate-convert/md-to-html/code-block.test.js +19 -0
- package/tests/slate-convert/md-to-html/header.test.js +20 -0
- package/tests/slate-convert/md-to-html/image.test.js +17 -0
- package/tests/slate-convert/md-to-html/image_reference.test.js +17 -0
- package/tests/slate-convert/md-to-html/link.test.js +15 -0
- package/tests/slate-convert/md-to-html/link_reference.test.js +15 -0
- package/tests/slate-convert/md-to-html/list-ordered.test.js +22 -0
- package/tests/slate-convert/md-to-html/list-unordered.test.js +22 -0
- package/tests/slate-convert/md-to-html/paragraph.test.js +15 -0
- package/tests/slate-convert/md-to-html/table.test.js +29 -0
- package/tests/slate-convert/md-to-html/text_base.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_bold.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_bold_italic.test.js +15 -0
- package/tests/slate-convert/md-to-html/text_code.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_bold.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_bold_italic.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_italic.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_italic.test.js +14 -0
- package/tests/slate-convert/md-to-slate/blockquote.test.js +200 -0
- package/tests/slate-convert/md-to-slate/check-list.test.js +34 -0
- package/tests/slate-convert/md-to-slate/code-block.test.js +32 -0
- package/tests/slate-convert/md-to-slate/header.test.js +49 -0
- package/tests/slate-convert/md-to-slate/image.test.js +31 -0
- package/tests/slate-convert/md-to-slate/link.test.js +30 -0
- package/tests/slate-convert/md-to-slate/list-ordered.test.js +42 -0
- package/tests/slate-convert/md-to-slate/list-unordered.test.js +42 -0
- package/tests/slate-convert/md-to-slate/paragraph.test.js +19 -0
- package/tests/slate-convert/md-to-slate/table.test.js +34 -0
- package/tests/slate-convert/md-to-slate/text_base.test.js +19 -0
- package/tests/slate-convert/md-to-slate/text_bold.test.js +22 -0
- package/tests/slate-convert/md-to-slate/text_bold_italic.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_code.test.js +22 -0
- package/tests/slate-convert/md-to-slate/text_code_bold.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_code_bold_italic.test.js +24 -0
- package/tests/slate-convert/md-to-slate/text_code_italic.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_italic.test.js +22 -0
- package/tests/slate-convert/slate-to-md/blockquote.test.js +416 -0
- package/tests/slate-convert/slate-to-md/check-list.test.js +96 -0
- package/tests/slate-convert/slate-to-md/code-block.test.js +35 -0
- package/tests/slate-convert/slate-to-md/formula.test.js +26 -0
- package/tests/slate-convert/slate-to-md/header.test.js +109 -0
- package/tests/slate-convert/slate-to-md/image.test.js +98 -0
- package/tests/slate-convert/slate-to-md/link.test.js +52 -0
- package/tests/slate-convert/slate-to-md/list-ordered.test.js +87 -0
- package/tests/slate-convert/slate-to-md/list-unordered.test.js +81 -0
- package/tests/slate-convert/slate-to-md/paragraph.test.js +28 -0
- package/tests/slate-convert/slate-to-md/table.test.js +56 -0
- package/tests/slate-convert/slate-to-md/text_base.test.js +28 -0
- package/tests/slate-convert/slate-to-md/text_bold.test.js +36 -0
- package/tests/slate-convert/slate-to-md/text_bold_italic.test.js +42 -0
- package/tests/slate-convert/slate-to-md/text_code.test.js +31 -0
- package/tests/slate-convert/slate-to-md/text_code_bold.test.js +37 -0
- package/tests/slate-convert/slate-to-md/text_code_bold_italic.test.js +43 -0
- package/tests/slate-convert/slate-to-md/text_code_italic.test.js +37 -0
- package/tests/slate-convert/slate-to-md/text_italic.test.js +36 -0
- package/README.md +0 -52
- package/TODO.md +0 -55
- package/dist/assets/css/diff-viewer.css +0 -105
- package/dist/assets/css/formula.css +0 -19
- package/dist/assets/css/history-viewer.css +0 -104
- package/dist/assets/css/image.css +0 -134
- package/dist/assets/css/link.css +0 -7
- package/dist/assets/css/markdown-editor.css +0 -12
- package/dist/assets/css/markdown-viewer.css +0 -69
- package/dist/assets/css/navbar-imgbutton.css +0 -83
- package/dist/assets/css/outline.css +0 -29
- package/dist/assets/css/table.css +0 -57
- package/dist/assets/css/textlink-hovermenu.css +0 -47
- package/dist/assets/css/topbar.css +0 -350
- package/dist/assets/css/tree-view.css +0 -67
- package/dist/assets/editor/seatable-editor.css +0 -77
- package/dist/assets/editor/simple-editor.css +0 -77
- package/dist/components/click-outside.js +0 -46
- package/dist/components/context-menu.js +0 -97
- package/dist/components/dialogs/add-formula-dialog.js +0 -116
- package/dist/components/dialogs/add-image-dialog.js +0 -69
- package/dist/components/dialogs/add-link-dialog.js +0 -133
- package/dist/components/dialogs/shortcut-dialog.js +0 -131
- package/dist/components/error-boundary.js +0 -28
- package/dist/components/load-script/index.js +0 -69
- package/dist/components/loading.js +0 -25
- package/dist/components/menu/index.js +0 -4
- package/dist/components/menu/item.js +0 -49
- package/dist/components/menu/menu.js +0 -38
- package/dist/components/menu/style.css +0 -42
- package/dist/components/modal-portal.js +0 -38
- package/dist/components/outline/index.js +0 -92
- package/dist/components/outline/outline-item.js +0 -58
- package/dist/components/select/_option.js +0 -44
- package/dist/components/select/field-setting.js +0 -106
- package/dist/components/select/index.js +0 -149
- package/dist/components/select/style.css +0 -144
- package/dist/components/svg-icons/check-mark-icon.js +0 -14
- package/dist/components/svg-icons/column-icon.js +0 -17
- package/dist/components/svg-icons/text-icon.js +0 -34
- package/dist/components/text-link-hover-menu/index.js +0 -123
- package/dist/components/toast/alert.js +0 -138
- package/dist/components/toast/index.js +0 -3
- package/dist/components/toast/toast.js +0 -159
- package/dist/components/toast/toastManager.js +0 -139
- package/dist/components/toast/toaster.js +0 -65
- package/dist/components/toolbar/header-list.js +0 -114
- package/dist/components/toolbar/help-group.js +0 -33
- package/dist/components/toolbar/index.js +0 -4
- package/dist/components/toolbar/insert-image.js +0 -106
- package/dist/components/toolbar/insert-table.js +0 -136
- package/dist/components/toolbar/table-group.js +0 -74
- package/dist/components/toolbar/toolbar.js +0 -317
- package/dist/components/toolbar/widgets/button-group.js +0 -24
- package/dist/components/toolbar/widgets/button-item.js +0 -129
- package/dist/components/toolbar/widgets/drop-list.js +0 -88
- package/dist/components/user-help/index.js +0 -179
- package/dist/config.js +0 -15
- package/dist/constants/cell-types.js +0 -29
- package/dist/constants/column.js +0 -4
- package/dist/containers/code-highlight-package.js +0 -14
- package/dist/containers/controller/block-element-controller.js +0 -375
- package/dist/containers/controller/index.js +0 -5
- package/dist/containers/controller/inline-element-controller.js +0 -134
- package/dist/containers/controller/normalize-controller.js +0 -95
- package/dist/containers/controller/shortcut-controller.js +0 -385
- package/dist/containers/controller/void-element-controller.js +0 -9
- package/dist/containers/custom/custom.js +0 -18
- package/dist/containers/custom/get-event-transfer.js +0 -33
- package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
- package/dist/containers/custom/insertNodes.js +0 -120
- package/dist/containers/custom/is-empty-paragraph.js +0 -9
- package/dist/containers/custom/split-nodes-at-point.js +0 -136
- package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
- package/dist/containers/editor-context.js +0 -85
- package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
- package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
- package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
- package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
- package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
- package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
- package/dist/containers/editor-utils/clear-format-utils.js +0 -84
- package/dist/containers/editor-utils/common-editor-utils.js +0 -492
- package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
- package/dist/containers/editor-utils/mark-utils.js +0 -20
- package/dist/containers/editor-utils/range-utils.js +0 -7
- package/dist/containers/editor-utils/selection-utils.js +0 -30
- package/dist/containers/editor-utils/text-utils.js +0 -117
- package/dist/containers/editor-widgets/check-list-item.js +0 -53
- package/dist/containers/editor-widgets/code-block.js +0 -128
- package/dist/containers/editor-widgets/column.js +0 -100
- package/dist/containers/editor-widgets/formula.js +0 -67
- package/dist/containers/editor-widgets/image.js +0 -237
- package/dist/containers/editor-widgets/link.js +0 -9
- package/dist/containers/editor-widgets/table.js +0 -144
- package/dist/containers/element-model/blockquote.js +0 -13
- package/dist/containers/element-model/column.js +0 -19
- package/dist/containers/element-model/image.js +0 -16
- package/dist/containers/element-model/link.js +0 -16
- package/dist/containers/element-model/table.js +0 -57
- package/dist/containers/element-model/text.js +0 -10
- package/dist/containers/render-utils/common-utils.js +0 -80
- package/dist/containers/render-utils/editor-utils.js +0 -133
- package/dist/containers/render-utils/viewer-utils.js +0 -198
- package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
- package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
- package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
- package/dist/editors/index.js +0 -78
- package/dist/editors/markdown-editor.js +0 -206
- package/dist/editors/plain-markdown-editor.js +0 -285
- package/dist/editors/seatable-editor.js +0 -210
- package/dist/editors/simple-editor.js +0 -200
- package/dist/index.js +0 -11
- package/dist/setting.local.js +0 -14
- package/dist/utils/deserialize-html.js +0 -260
- package/dist/utils/diff/compare-strings.js +0 -35
- package/dist/utils/diff/diff.js +0 -769
- package/dist/utils/diff/index.js +0 -2
- package/dist/utils/seafile-markdown2html.js +0 -52
- package/dist/utils/slate2markdown/deserialize.js +0 -588
- package/dist/utils/slate2markdown/index.js +0 -3
- package/dist/utils/slate2markdown/serialize.js +0 -366
- package/dist/utils/utils.js +0 -68
- package/dist/viewer/diff-viewer.js +0 -85
- package/dist/viewer/index.js +0 -4
- package/dist/viewer/markdown-viewer.js +0 -121
- package/dist/viewer/seatable-viewer.js +0 -63
- package/dist/viewer/slate-viewer.js +0 -71
- package/public/index.html +0 -45
- package/public/manifest.json +0 -15
- package/public/media/seafile-logo.png +0 -0
- /package/{dist/assets/css/keyboard-shortcuts.css → src/extension/toolbar/user-help/style.css} +0 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { Editor, Text, Path, Span, Element, Node, Range } from 'slate';
|
|
2
|
+
import { ReactEditor } from 'slate-react';
|
|
3
|
+
import { match } from '../utils';
|
|
4
|
+
|
|
5
|
+
// options
|
|
6
|
+
export const getQueryOptions = (editor, options) => {
|
|
7
|
+
const { match: _match, block } = options;
|
|
8
|
+
let newMatch = undefined;
|
|
9
|
+
if (_match || block) {
|
|
10
|
+
newMatch = (n, path) => match(n, path, _match) && (!block || Editor.isBlock(editor, n));
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
...options,
|
|
14
|
+
match: newMatch,
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const findPath = (editor, node, defaultPath) => {
|
|
19
|
+
try {
|
|
20
|
+
return ReactEditor.findPath(editor, node);
|
|
21
|
+
} catch {
|
|
22
|
+
return defaultPath;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// get node
|
|
27
|
+
export const getNode = (editor, path) => {
|
|
28
|
+
let node = null;
|
|
29
|
+
try {
|
|
30
|
+
node = Node.get(editor, path);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
node = null;
|
|
33
|
+
}
|
|
34
|
+
return node;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getNodeType = (node) => {
|
|
38
|
+
return Element.isElement(node) ? node.type : '';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const getParentNode = (nodes, nodeId) => {
|
|
42
|
+
let parentNode;
|
|
43
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
44
|
+
const node = nodes[i];
|
|
45
|
+
const { children: childrenNodes } = node;
|
|
46
|
+
if (!Array.isArray(childrenNodes)) continue;
|
|
47
|
+
if (childrenNodes.find(node => node.id === nodeId)) {
|
|
48
|
+
parentNode = node;
|
|
49
|
+
} else {
|
|
50
|
+
parentNode = getParentNode(childrenNodes, nodeId);
|
|
51
|
+
}
|
|
52
|
+
if (!parentNode) continue;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return parentNode;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getNodes = (node, options) => {
|
|
59
|
+
return Node.nodes(node, options);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const getCommonNode = (root, path, ancestor) => {
|
|
63
|
+
return Node.common(root, path, ancestor);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const getSelectedNodeByType = (editor, type) => {
|
|
67
|
+
const match = (n) => getNodeType(n) === type;
|
|
68
|
+
const [nodeEntry] = Editor.nodes(editor, { match, universal: true });
|
|
69
|
+
|
|
70
|
+
return nodeEntry ? nodeEntry[0] : null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const getSelectedNodeByTypes = (editor, types) => {
|
|
74
|
+
const match = (n) => types.includes(getNodeType(n));
|
|
75
|
+
const [nodeEntry] = Editor.nodes(editor, { match, universal: true });
|
|
76
|
+
return nodeEntry ? nodeEntry[0] : null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const getSelectedNodeEntryByType = (editor, type) => {
|
|
80
|
+
const match = (n) => getNodeType(n) === type;
|
|
81
|
+
const [nodeEntry] = Editor.nodes(editor, { match, universal: false });
|
|
82
|
+
|
|
83
|
+
return nodeEntry ? nodeEntry : null;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getNodeEntries = (editor, options) => {
|
|
87
|
+
return Editor.nodes(editor, getQueryOptions(editor, options));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const getEditorString = (editor, at, options) => {
|
|
91
|
+
if (!at) return '';
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
return Editor.string(editor, at, options);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// children & child
|
|
101
|
+
export const getChildren = (nodeEntry) => {
|
|
102
|
+
const [node, path] = nodeEntry;
|
|
103
|
+
|
|
104
|
+
if (Element.isAncestor(node)) {
|
|
105
|
+
const { children } = node;
|
|
106
|
+
return children.map((child, index) => {
|
|
107
|
+
const childPath = path.concat([index]);
|
|
108
|
+
return [child, childPath];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const getLastChild = (nodeEntry) => {
|
|
115
|
+
const [node, path] = nodeEntry;
|
|
116
|
+
if (Text.isText(node)) return null;
|
|
117
|
+
if (!node.children.length) return null;
|
|
118
|
+
const children = node.children;
|
|
119
|
+
|
|
120
|
+
return [children[children.length - 1], path.concat([children.length - 1])];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const getDeepInlineChildren = (editor, { children }) => {
|
|
124
|
+
const inlineChildren = [];
|
|
125
|
+
for (let child of children) {
|
|
126
|
+
if (Editor.isBlock(editor, child[0])) {
|
|
127
|
+
inlineChildren.push(...getDeepInlineChildren(editor, { children: getChildren(child) }));
|
|
128
|
+
} else {
|
|
129
|
+
inlineChildren.push(child);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return inlineChildren;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const getLastChildPath = (nodeEntry) => {
|
|
136
|
+
const lastChild = getLastChild(nodeEntry);
|
|
137
|
+
if (!lastChild) return nodeEntry[1].concat([-1]);
|
|
138
|
+
|
|
139
|
+
return lastChild[1];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const getPreviousPath = (path) => {
|
|
143
|
+
if (path.length === 0) return;
|
|
144
|
+
|
|
145
|
+
const last = path[path.length - 1];
|
|
146
|
+
if (last <= 0) return;
|
|
147
|
+
|
|
148
|
+
return path.slice(0, -1).concat(last - 1);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const isLastChild = (nodeEntry, childPath) => {
|
|
152
|
+
const lastChildPath = getLastChildPath(nodeEntry);
|
|
153
|
+
return Path.equals(lastChildPath, childPath);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const getSelectedElems = (editor) => {
|
|
157
|
+
const elems = [];
|
|
158
|
+
const nodeEntries = Editor.nodes(editor, { universal: true });
|
|
159
|
+
for (let nodeEntry of nodeEntries) {
|
|
160
|
+
const [node] = nodeEntry;
|
|
161
|
+
if (Element.isElement(node)) elems.push(node);
|
|
162
|
+
}
|
|
163
|
+
return elems;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// siblings
|
|
167
|
+
export const getNextSiblingNodes = (ancestorEntry, path) => {
|
|
168
|
+
const [ancestor, ancestorPath] = ancestorEntry;
|
|
169
|
+
|
|
170
|
+
const leafIndex = path[ancestorPath.length];
|
|
171
|
+
|
|
172
|
+
const siblings = [];
|
|
173
|
+
const ancestorChildren = ancestor.children;
|
|
174
|
+
|
|
175
|
+
if (leafIndex + 1 < ancestor.children.length) {
|
|
176
|
+
for (let i = leafIndex + 1; i < ancestor.children.length; i++) {
|
|
177
|
+
siblings.push(ancestorChildren[i]);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return siblings;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// parent
|
|
185
|
+
export const getAboveNode = (editor, options) => {
|
|
186
|
+
return Editor.above(editor, getQueryOptions(editor, options));
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const getAboveBlockNode = (editor, options) => {
|
|
190
|
+
return getAboveNode(editor, { ...options, block: true });
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const getPrevNode = (editor) => {
|
|
194
|
+
const [lowerNode, lowerPath] = getAboveNode(editor, {
|
|
195
|
+
mode: 'lowest',
|
|
196
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const [heightNode, heightPath] = getAboveNode(editor, {
|
|
200
|
+
mode: 'highest',
|
|
201
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
let prevNode = null;
|
|
205
|
+
try {
|
|
206
|
+
prevNode = Editor.previous(editor, {
|
|
207
|
+
at: lowerPath,
|
|
208
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
209
|
+
});
|
|
210
|
+
} catch (error) {
|
|
211
|
+
prevNode = null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (lowerNode.id !== heightNode.id && !prevNode) {
|
|
215
|
+
try {
|
|
216
|
+
prevNode = Editor.previous(editor, {
|
|
217
|
+
at: heightPath,
|
|
218
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
219
|
+
});
|
|
220
|
+
} catch (error) {
|
|
221
|
+
prevNode = null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return prevNode;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const getNextNode = (editor) => {
|
|
228
|
+
const [lowerNode, lowerPath] = getAboveNode(editor, {
|
|
229
|
+
mode: 'lowest',
|
|
230
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const [heightNode, heightPath] = getAboveNode(editor, {
|
|
234
|
+
mode: 'highest',
|
|
235
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
let nextNode = null;
|
|
239
|
+
try {
|
|
240
|
+
nextNode = Editor.next(editor, {
|
|
241
|
+
at: lowerPath,
|
|
242
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
243
|
+
});
|
|
244
|
+
} catch (error) {
|
|
245
|
+
nextNode = null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (lowerNode.id !== heightNode.id && !nextNode) {
|
|
249
|
+
try {
|
|
250
|
+
nextNode = Editor.next(editor, {
|
|
251
|
+
at: heightPath,
|
|
252
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
nextNode = null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return nextNode;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// find node
|
|
262
|
+
export const findNode = (editor, options) => {
|
|
263
|
+
const nodeEntries = Editor.nodes(editor, {
|
|
264
|
+
at: editor.selection || [],
|
|
265
|
+
...getQueryOptions(editor, options)
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const _nodeEntries = Array.from(nodeEntries);
|
|
269
|
+
if (_nodeEntries[0]) {
|
|
270
|
+
return _nodeEntries[0];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return undefined;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export const findDescendant = (editor, options) => {
|
|
277
|
+
const { at = editor.selection, reverse = false, voids = false, match: _match } = options;
|
|
278
|
+
if (!at) return;
|
|
279
|
+
|
|
280
|
+
let from;
|
|
281
|
+
let to;
|
|
282
|
+
if (Span.isSpan(at)) {
|
|
283
|
+
[from, to] = at;
|
|
284
|
+
} else if (Range.isRange(at)) {
|
|
285
|
+
const first = Editor.first(editor, at);
|
|
286
|
+
const last = Editor.last(editor, at);
|
|
287
|
+
from = reverse ? last : first;
|
|
288
|
+
to = reverse ? first : last;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let root = [editor, []];
|
|
292
|
+
if (Path.isPath(at)) {
|
|
293
|
+
root = Editor.node(editor, at);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const nodeEntries = Node.descendants(root[0], {
|
|
297
|
+
from,
|
|
298
|
+
to,
|
|
299
|
+
reverse,
|
|
300
|
+
pass: ([n]) => (voids ? false : Editor.isVoid(editor, n))
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
for (const [node, path] of nodeEntries) {
|
|
304
|
+
if (match(node, path, _match)) {
|
|
305
|
+
return [node, at.concat(path)];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return undefined;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// is
|
|
313
|
+
export const isStartPoint = (editor, point, at) => {
|
|
314
|
+
return !!point && Editor.isStart(editor, point, at);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const isEndPoint = (editor, point, at) => {
|
|
318
|
+
return !!point && Editor.isEnd(editor, point, at);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export const isBlockTextEmptyAfterSelection = (editor) => {
|
|
322
|
+
if (!editor.selection) return false;
|
|
323
|
+
|
|
324
|
+
const blockAbove = Editor.above(editor, { block: true });
|
|
325
|
+
if (!blockAbove) return false;
|
|
326
|
+
|
|
327
|
+
const cursor = editor.selection.focus;
|
|
328
|
+
|
|
329
|
+
const selectionParentEntry = Editor.parent(editor, editor.selection);
|
|
330
|
+
if (!selectionParentEntry) return false;
|
|
331
|
+
const [, selectionParentPath] = selectionParentEntry;
|
|
332
|
+
|
|
333
|
+
if (!isEndPoint(editor, cursor, selectionParentPath)) return false;
|
|
334
|
+
|
|
335
|
+
const siblingNodes = getNextSiblingNodes(blockAbove, cursor.path);
|
|
336
|
+
|
|
337
|
+
if (siblingNodes.length) {
|
|
338
|
+
// 子节点包含 文本节点
|
|
339
|
+
for (const siblingNode of siblingNodes) {
|
|
340
|
+
if (Text.isText(siblingNode) && siblingNode.text) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
return isEndPoint(editor, cursor, blockAbove[1]);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return true;
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
export const isRangeAcrossBlocks = (editor, { at, ...options } = {}) => {
|
|
352
|
+
if (!at) at = editor.selection;
|
|
353
|
+
if (!at) return;
|
|
354
|
+
|
|
355
|
+
const [start, end] = Range.edges(at);
|
|
356
|
+
const startBlock = getAboveBlockNode(editor, {
|
|
357
|
+
at: start,
|
|
358
|
+
...options,
|
|
359
|
+
});
|
|
360
|
+
const endBlock = getAboveBlockNode(editor, {
|
|
361
|
+
at: end,
|
|
362
|
+
...options,
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
if (!startBlock && !endBlock) return;
|
|
366
|
+
|
|
367
|
+
if (!startBlock || !endBlock) return true;
|
|
368
|
+
|
|
369
|
+
return !Path.equals(startBlock[1], endBlock[1]);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
export const isAncestorEmpty = (editor, node) => {
|
|
373
|
+
return !Node.string(node) && !node.children.some((n) => Editor.isInline(editor, n));
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export const isBlockAboveEmpty = (editor) => {
|
|
377
|
+
const block = getAboveBlockNode(editor)?.[0];
|
|
378
|
+
if (!block) return false;
|
|
379
|
+
return isAncestorEmpty(editor, block);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export const isSelectionAtBlockStart = (editor, options) => {
|
|
383
|
+
const { selection } = editor;
|
|
384
|
+
if (!selection) return false;
|
|
385
|
+
|
|
386
|
+
const path = getAboveBlockNode(editor, options)?.[1];
|
|
387
|
+
if (!path) return false;
|
|
388
|
+
|
|
389
|
+
return (
|
|
390
|
+
isStartPoint(editor, selection.focus, path) ||
|
|
391
|
+
(Range.isExpanded(editor.selection) && isStartPoint(editor, selection.anchor, path))
|
|
392
|
+
);
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
export const isSelectionAtBlockEnd = (editor, options) => {
|
|
396
|
+
const path = getAboveBlockNode(editor, options)?.[1];
|
|
397
|
+
|
|
398
|
+
return !!path && isEndPoint(editor, editor.selection?.focus, path);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
export const isLastNode = (editor, node) => {
|
|
402
|
+
const editorChildren = editor.children || [];
|
|
403
|
+
const editorChildrenLength = editorChildren.length;
|
|
404
|
+
return editorChildren[editorChildrenLength - 1] === node;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const isTextNode = (node) => {
|
|
408
|
+
if (!node) return false;
|
|
409
|
+
if (Reflect.has(node, 'children')) return false;
|
|
410
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Editor, Transforms } from 'slate';
|
|
2
|
+
import { ReactEditor } from 'slate-react';
|
|
3
|
+
|
|
4
|
+
export const focusEditor = (editor, target) => {
|
|
5
|
+
if (target) {
|
|
6
|
+
Editor.withoutNormalizing(editor, () => {
|
|
7
|
+
Transforms.deselect(editor);
|
|
8
|
+
Transforms.select(editor, target);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
ReactEditor.focus(editor);
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Editor, Path, Transforms } from 'slate';
|
|
2
|
+
import { getNode } from '../queries';
|
|
3
|
+
|
|
4
|
+
export const moveChildren = (editor, {at, to, match, fromStartIndex = 0}) => {
|
|
5
|
+
let moved = 0;
|
|
6
|
+
const parentPath = Path.isPath(at) ? at : at[1];
|
|
7
|
+
const parentNode = Path.isPath(at) ? getNode(editor, parentPath) : at[0];
|
|
8
|
+
|
|
9
|
+
if (!parentNode) return moved;
|
|
10
|
+
// There have none children in a not block element
|
|
11
|
+
if (!Editor.isBlock(editor, parentNode)) return moved;
|
|
12
|
+
|
|
13
|
+
for (let i = parentNode.children.length - 1; i >= fromStartIndex; i--) {
|
|
14
|
+
const childPath = [...parentPath, i];
|
|
15
|
+
const childNode = getNode(editor, childPath);
|
|
16
|
+
if (!match || (childNode && match([childNode, childPath]))) {
|
|
17
|
+
Transforms.moveNodes(editor, {at: childPath, to});
|
|
18
|
+
moved++;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return moved;
|
|
23
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transforms, Node } from 'slate';
|
|
2
|
+
|
|
3
|
+
export const removeNodeChildren = (editor, path, options) => {
|
|
4
|
+
const nodeChildren = Node.children(editor, path, {reverse: true,});
|
|
5
|
+
for (const [, childPath] of nodeChildren) {
|
|
6
|
+
Transforms.removeNodes(editor, { ...options, at: childPath });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Editor, Transforms } from 'slate';
|
|
2
|
+
import { removeNodeChildren } from './remove-node-children';
|
|
3
|
+
|
|
4
|
+
export const replaceNodeChildren = (editor, {at, nodes, insertOptions, removeOptions}) => {
|
|
5
|
+
|
|
6
|
+
Editor.withoutNormalizing(editor, () => {
|
|
7
|
+
removeNodeChildren(editor, at, removeOptions);
|
|
8
|
+
|
|
9
|
+
Transforms.insertNodes(editor, nodes, {
|
|
10
|
+
...insertOptions,
|
|
11
|
+
at: at.concat([0])
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { PARAGRAPH } from '../../constants/element-types';
|
|
4
|
+
|
|
5
|
+
export const match = (node, path, predicate) => {
|
|
6
|
+
if (!predicate) return true;
|
|
7
|
+
if (typeof predicate === 'object') {
|
|
8
|
+
return Object.entries(predicate).every(([key, value]) => {
|
|
9
|
+
if (value && !Array.isArray(value)) {
|
|
10
|
+
return node[key] === value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
value = value ? value : [];
|
|
14
|
+
return value.includes(node[key]);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return predicate(node, path);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const generateDefaultText = () => {
|
|
22
|
+
return { id: slugid.nice(), text: '' };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const generateDefaultParagraph = () => {
|
|
26
|
+
return { id: slugid.nice(), type: PARAGRAPH, children: [generateDefaultText()] };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const generateEmptyElement = (type) => {
|
|
30
|
+
return { id: slugid.nice(), type, children: [generateDefaultText()] };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {String} type
|
|
36
|
+
* @param {Object} options
|
|
37
|
+
* @param {Node[] | String} [options.childrenOrText = ''] If provide a string,that will generate a text node as children automatically
|
|
38
|
+
* @param {object} [options.props = {}]
|
|
39
|
+
* @returns {Node}
|
|
40
|
+
*/
|
|
41
|
+
export const generateElement = (type, options = {}) => {
|
|
42
|
+
let { childrenOrText = '', props = {} } = options;
|
|
43
|
+
if (typeof childrenOrText === 'string') {
|
|
44
|
+
childrenOrText = [{ id: slugid.nice(), text: childrenOrText }];
|
|
45
|
+
}
|
|
46
|
+
if (!Array.isArray(childrenOrText)) {
|
|
47
|
+
throw Error('childrenOrText must be a string or a Node array!');
|
|
48
|
+
}
|
|
49
|
+
return { id: slugid.nice(), type, children: childrenOrText, ...props };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const isEmptyParagraph = (node) => {
|
|
53
|
+
if (node.type !== 'paragraph') return false;
|
|
54
|
+
if (node.children.length !== 1) return false;
|
|
55
|
+
const [child] = node.children;
|
|
56
|
+
if (Text.isText(child) && child.text === '' && child.type !== 'image') return true;
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const Placeholder = (props) => {
|
|
61
|
+
const { title } = props;
|
|
62
|
+
const { t } = useTranslation();
|
|
63
|
+
return (
|
|
64
|
+
<span style={{
|
|
65
|
+
position: 'absolute',
|
|
66
|
+
top: '0px',
|
|
67
|
+
color: 'rgba(191,191,191,1)',
|
|
68
|
+
pointerEvents: 'none',
|
|
69
|
+
width: '100%',
|
|
70
|
+
maxWidth: '100%',
|
|
71
|
+
display: 'block',
|
|
72
|
+
userSelect: 'none',
|
|
73
|
+
textDecoration: 'none'
|
|
74
|
+
}}>{t(title)}</span>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createEditor } from 'slate';
|
|
2
|
+
import { withHistory } from 'slate-history';
|
|
3
|
+
import { withReact } from 'slate-react';
|
|
4
|
+
import Plugins from './plugins';
|
|
5
|
+
|
|
6
|
+
const baseEditor = Plugins.reduce((editor, pluginItem) => {
|
|
7
|
+
const withPlugin = pluginItem.editorPlugin;
|
|
8
|
+
if (withPlugin) {
|
|
9
|
+
return withPlugin(editor);
|
|
10
|
+
}
|
|
11
|
+
return editor;
|
|
12
|
+
}, withHistory(withReact(createEditor())));
|
|
13
|
+
|
|
14
|
+
export default baseEditor;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
|
|
8
|
+
export {
|
|
9
|
+
ELementTypes,
|
|
10
|
+
isEmptyParagraph,
|
|
11
|
+
renderElement,
|
|
12
|
+
renderLeaf,
|
|
13
|
+
Toolbar,
|
|
14
|
+
baseEditor,
|
|
15
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
|
|
6
|
+
export const isMenuDisabled = (editor, readonly) => {
|
|
7
|
+
if (readonly) return true;
|
|
8
|
+
if (editor.selection == null) return true;
|
|
9
|
+
|
|
10
|
+
const [nodeEntry] = Editor.nodes(editor, {
|
|
11
|
+
match: n => {
|
|
12
|
+
const type = getNodeType(n);
|
|
13
|
+
|
|
14
|
+
// Only available for p and blockquote
|
|
15
|
+
if (type === PARAGRAPH) return true;
|
|
16
|
+
if (type === BLOCKQUOTE) return true;
|
|
17
|
+
if (type === UNORDERED_LIST) return true;
|
|
18
|
+
if (type === ORDERED_LIST) return true;
|
|
19
|
+
if (type === CHECK_LIST_ITEM) return true;
|
|
20
|
+
if (type && type.startWith && type.startWith('header')) return true;
|
|
21
|
+
if (type === IMAGE) return true;
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
},
|
|
25
|
+
universal: true,
|
|
26
|
+
mode: 'highest', // Match top level
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Match to p blockquote, do not disable
|
|
30
|
+
if (nodeEntry) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const getBlockQuoteType = (editor) => {
|
|
37
|
+
const [match] = Editor.nodes(editor, {
|
|
38
|
+
match: (n) => getNodeType(n) === BLOCKQUOTE,
|
|
39
|
+
universal: true,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!match) return PARAGRAPH;
|
|
43
|
+
const [n] = match;
|
|
44
|
+
|
|
45
|
+
return getNodeType(n);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const setBlockQuoteType = (editor, active) => {
|
|
49
|
+
if (!active) {
|
|
50
|
+
const blockquoteNode = {
|
|
51
|
+
id: slugid.nice(),
|
|
52
|
+
type: BLOCKQUOTE,
|
|
53
|
+
};
|
|
54
|
+
Transforms.wrapNodes(editor, blockquoteNode, {
|
|
55
|
+
mode: 'highest',
|
|
56
|
+
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
Transforms.unwrapNodes(editor, {
|
|
60
|
+
mode: 'highest',
|
|
61
|
+
match: (n) => Element.isElement(n) && Editor.isBlock(editor, n),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
focusEditor(editor);
|
|
65
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BLOCKQUOTE } from '../../constants/element-types';
|
|
2
|
+
import withBlockquote from './plugin';
|
|
3
|
+
import renderBlockquote from './render-elem';
|
|
4
|
+
|
|
5
|
+
const BlockquotePlugin = {
|
|
6
|
+
type: BLOCKQUOTE,
|
|
7
|
+
nodeType: 'element',
|
|
8
|
+
editorMenus: [],
|
|
9
|
+
editorPlugin: withBlockquote,
|
|
10
|
+
renderElements: [renderBlockquote],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default BlockquotePlugin;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
7
|
+
const menuConfig = MENUS_CONFIG_MAP[BLOCKQUOTE];
|
|
8
|
+
|
|
9
|
+
const isActive = (editor) => {
|
|
10
|
+
return getBlockQuoteType(editor) === BLOCKQUOTE;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function BlockquoteMenu({ isRichEditor, className, readonly, editor }) {
|
|
14
|
+
|
|
15
|
+
const onMousedown = useCallback((event) => {
|
|
16
|
+
const active = isActive(editor);
|
|
17
|
+
setBlockQuoteType(editor, active);
|
|
18
|
+
}, [editor]);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<MenuItem
|
|
22
|
+
isRichEditor={isRichEditor}
|
|
23
|
+
className={className}
|
|
24
|
+
disabled={isMenuDisabled(editor, readonly)}
|
|
25
|
+
isActive={isActive(editor)}
|
|
26
|
+
onMouseDown={onMousedown}
|
|
27
|
+
|
|
28
|
+
{...menuConfig}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|