@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,175 @@
|
|
|
1
|
+
import { Editor, Node, Path, Transforms, insertFragment } from 'slate';
|
|
2
|
+
import { generateTable, generateTableRow } from './model';
|
|
3
|
+
import { CODE_BLOCK, COLUMN, FORMULA, PARAGRAPH, TABLE, TABLE_CELL, TABLE_ROW } from '../../constants/element-types';
|
|
4
|
+
import { focusEditor, generateElement } from '../../core';
|
|
5
|
+
import getEventTransfer from '../../../containers/custom/get-event-transfer';
|
|
6
|
+
import { htmlDeserializer } from '../../../utils/deserialize-html';
|
|
7
|
+
|
|
8
|
+
export const isDisabled = (editor, readonly) => {
|
|
9
|
+
const { selection } = editor;
|
|
10
|
+
if (readonly || !selection) return true;
|
|
11
|
+
const disableTypes = [TABLE, TABLE_ROW, TABLE_CELL, FORMULA, CODE_BLOCK, COLUMN];
|
|
12
|
+
const [nodeEntry] = Editor.nodes(editor, {
|
|
13
|
+
match: n => disableTypes.includes(n.type),
|
|
14
|
+
mode: 'highest'
|
|
15
|
+
});
|
|
16
|
+
if (nodeEntry) return true;
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isInTable = (editor) => {
|
|
21
|
+
const { selection } = editor;
|
|
22
|
+
if (!selection) return false;
|
|
23
|
+
const [nodeEntry] = getTableEntry(editor);
|
|
24
|
+
if (!nodeEntry) return false;
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const insertTable = (editor, rowNum, columnNum) => {
|
|
29
|
+
const table = generateTable({ rowNum, columnNum });
|
|
30
|
+
Editor.insertNode(editor, table);
|
|
31
|
+
// Auto focus at the first cell in table
|
|
32
|
+
const [nodeEntry] = Editor.nodes(editor, {
|
|
33
|
+
match: node => node.id === table.id,
|
|
34
|
+
mode: 'highest'
|
|
35
|
+
});
|
|
36
|
+
const focusPoint = Editor.start(editor, nodeEntry[1]);
|
|
37
|
+
focusEditor(editor, focusPoint);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const getTableFocusingInfos = (editor) => {
|
|
41
|
+
if (!isInTable(editor)) return null;
|
|
42
|
+
const nodeEntries = Editor.nodes(editor, {
|
|
43
|
+
match: n => [TABLE, TABLE_ROW, TABLE_CELL].includes(n.type),
|
|
44
|
+
});
|
|
45
|
+
const nodeEntryList = Array.from(nodeEntries);
|
|
46
|
+
const [tableEntry, rowEntry, cellEntry] = nodeEntryList;
|
|
47
|
+
const columnIndex = cellEntry[1].at(-1);
|
|
48
|
+
const rowIndex = cellEntry[1].at(-2);
|
|
49
|
+
return { cellEntry, tableEntry, rowEntry, columnIndex, rowIndex };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const selectCellByGrid = (editor, rowIndex, colIndex) => {
|
|
53
|
+
const { tableEntry: [, tablePath] } = getTableFocusingInfos(editor);
|
|
54
|
+
const selectRange = Editor.range(editor, tablePath.concat(rowIndex, colIndex));
|
|
55
|
+
focusEditor(editor, selectRange);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getSelectedTableCells = (editor) => {
|
|
59
|
+
const [tableEntry] = getTableEntry(editor);
|
|
60
|
+
if (!tableEntry) return [];
|
|
61
|
+
|
|
62
|
+
const [tableNode] = tableEntry;
|
|
63
|
+
const tableRows = tableNode.children;
|
|
64
|
+
const selectGrid = getSelectGrid(editor);
|
|
65
|
+
|
|
66
|
+
const { startRowIndex, endRowIndex, startColIndex, endColIndex } = selectGrid;
|
|
67
|
+
|
|
68
|
+
const selectedTableRows = [];
|
|
69
|
+
for (let rowIndex = startRowIndex; rowIndex <= endRowIndex; rowIndex++) {
|
|
70
|
+
const currentRow = tableRows[rowIndex];
|
|
71
|
+
let selectedTableCells = [];
|
|
72
|
+
for (let colIndex = startColIndex; colIndex <= endColIndex; colIndex++) {
|
|
73
|
+
const currentCell = currentRow.children[colIndex];
|
|
74
|
+
selectedTableCells.push(currentCell);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
selectedTableRows.push(generateTableRow({ childrenOrText: selectedTableCells }));
|
|
78
|
+
selectedTableCells = [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return [generateTable({ childrenOrText: selectedTableRows })];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const getSelectGrid = (editor) => {
|
|
85
|
+
const [tableEntry] = getTableEntry(editor);
|
|
86
|
+
if (!tableEntry) return null;
|
|
87
|
+
|
|
88
|
+
const selectedTableCells = document.querySelectorAll('.selected-cell');
|
|
89
|
+
if (selectedTableCells.length === 0) return null;
|
|
90
|
+
|
|
91
|
+
const selectGrid = Array.from(selectedTableCells).reduce((grid, cell) => {
|
|
92
|
+
const { startRowIndex, endRowIndex, startColIndex, endColIndex } = grid;
|
|
93
|
+
const { cellIndex: colIndex } = cell;
|
|
94
|
+
const { rowIndex } = cell.parentNode;
|
|
95
|
+
if (endRowIndex === -1 || rowIndex > endRowIndex) grid.endRowIndex = rowIndex;
|
|
96
|
+
if (startRowIndex === -1 || rowIndex < startRowIndex) grid.startRowIndex = rowIndex;
|
|
97
|
+
if (endColIndex === -1 || colIndex > endColIndex) grid.endColIndex = colIndex;
|
|
98
|
+
if (startColIndex === -1 || colIndex < startColIndex) grid.startColIndex = colIndex;
|
|
99
|
+
return { ...grid };
|
|
100
|
+
}, { startRowIndex: -1, endRowIndex: -1, startColIndex: -1, endColIndex: -1 });
|
|
101
|
+
|
|
102
|
+
return selectGrid;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const pasteContentIntoTable = (editor, content) => {
|
|
106
|
+
const data = content;
|
|
107
|
+
let { fragment, text, type, html } = getEventTransfer(data);
|
|
108
|
+
const newText = text.replace(/\r\n|\n/g, ' ');
|
|
109
|
+
|
|
110
|
+
if (!fragment && type === 'text') {
|
|
111
|
+
Transforms.insertText(this.editor, newText);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (type === 'html') {
|
|
116
|
+
fragment = htmlDeserializer(html);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (fragment.length === 1) {
|
|
120
|
+
if (fragment[0].type === TABLE) {
|
|
121
|
+
const clipboardTable = fragment[0];
|
|
122
|
+
const {
|
|
123
|
+
tableEntry: [tableNode, tablePath],
|
|
124
|
+
rowEntry: [rowNode],
|
|
125
|
+
rowIndex,
|
|
126
|
+
columnIndex
|
|
127
|
+
} = getTableFocusingInfos(editor);
|
|
128
|
+
const tableWidth = rowNode.children.length;
|
|
129
|
+
const tableHeight = tableNode.children.length;
|
|
130
|
+
clipboardTable.children.some((clipRow, clipRowIndex) => {
|
|
131
|
+
const currentInsertPath = tablePath.concat(rowIndex + clipRowIndex + rowIndex);
|
|
132
|
+
// Out of table
|
|
133
|
+
if (rowIndex + clipRowIndex >= tableHeight + 1) return true;
|
|
134
|
+
clipRow.children.some((clipCol, clipColIndex) => {
|
|
135
|
+
// Out of table
|
|
136
|
+
if (columnIndex + clipColIndex >= tableWidth + 1) return true;
|
|
137
|
+
const currentCellPath = currentInsertPath.concat(columnIndex + clipColIndex);
|
|
138
|
+
const currentCellChildPath = currentCellPath.concat(0);
|
|
139
|
+
Transforms.removeNodes(editor, { at: currentCellChildPath });
|
|
140
|
+
if (clipCol.children.type !== PARAGRAPH) {
|
|
141
|
+
const text = Node.string(clipCol);
|
|
142
|
+
const newChild = generateElement(PARAGRAPH, { childrenOrText: text });
|
|
143
|
+
Transforms.insertNodes(editor, newChild, { at: currentCellChildPath });
|
|
144
|
+
} else {
|
|
145
|
+
Transforms.insertNodes(editor, clipCol.children, { at: currentCellChildPath });
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
});
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
} else if (fragment[0].type === PARAGRAPH) {
|
|
152
|
+
insertFragment(editor, fragment);
|
|
153
|
+
} else {
|
|
154
|
+
Transforms.insertText(editor, text.replace(/\r\n|\n/g, ' '));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const jumpOutTableInEditor = (editor) => {
|
|
160
|
+
const [tableEntry] = getTableEntry(editor);
|
|
161
|
+
if (!tableEntry) return;
|
|
162
|
+
|
|
163
|
+
const [, tablePath] = tableEntry;
|
|
164
|
+
const tableParentPath = Path.parent(tablePath);
|
|
165
|
+
const insertPath = tableParentPath.concat(tablePath.at(-1) + 1);
|
|
166
|
+
Transforms.insertNodes(editor, generateElement(PARAGRAPH), { at: insertPath });
|
|
167
|
+
Transforms.select(editor, { path: insertPath.concat(0), offset: 0 });
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const getTableEntry = (editor) => {
|
|
171
|
+
return Editor.nodes(editor, {
|
|
172
|
+
match: n => n.type === TABLE,
|
|
173
|
+
mode: 'highest'
|
|
174
|
+
});
|
|
175
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TABLE } from '../../constants/element-types';
|
|
2
|
+
import TableMenu from './menu';
|
|
3
|
+
import { AlignmentDropDown, ColumnOperationDropDownList, RowOperationDropDownList, RemoveTableMenu } from './menu/table-operator';
|
|
4
|
+
import withTable from './plugin';
|
|
5
|
+
import RenderTableContainer, { RenderTableCell, RenderTableRow } from './render-elem';
|
|
6
|
+
|
|
7
|
+
const TablePlugin = {
|
|
8
|
+
type: TABLE,
|
|
9
|
+
nodeType: 'element',
|
|
10
|
+
editorMenus: [TableMenu, AlignmentDropDown, ColumnOperationDropDownList, RowOperationDropDownList, RemoveTableMenu],
|
|
11
|
+
editorPlugin: withTable,
|
|
12
|
+
renderElements: [RenderTableCell, RenderTableRow, RenderTableContainer],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default TablePlugin;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import MenuItem from '../../../commons/menu/menu-item';
|
|
4
|
+
import { MENUS_CONFIG_MAP } from '../../../constants';
|
|
5
|
+
import { TABLE } from '../../../constants/element-types';
|
|
6
|
+
import { isDisabled, isInTable } from '../helper';
|
|
7
|
+
import TableSizeSelector from './table-size-selector';
|
|
8
|
+
|
|
9
|
+
import './style.css';
|
|
10
|
+
|
|
11
|
+
const menuConfig = MENUS_CONFIG_MAP[TABLE];
|
|
12
|
+
const propTypes = {
|
|
13
|
+
editor: PropTypes.object.isRequired,
|
|
14
|
+
readonly: PropTypes.bool.isRequired,
|
|
15
|
+
className: PropTypes.string,
|
|
16
|
+
isRichEditor: PropTypes.bool,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const TableMenu = ({ editor, readonly, className, isRichEditor }) => {
|
|
20
|
+
const [isOpenTableSizeSelector, setIsOpenTableSizeSelector] = useState(false);
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
const disabled = useMemo(() => isDisabled(editor, readonly), [editor.selection, readonly]);
|
|
23
|
+
const isActive = isInTable(editor);
|
|
24
|
+
|
|
25
|
+
const onSelectorHide = useCallback(() => {
|
|
26
|
+
setIsOpenTableSizeSelector(false);
|
|
27
|
+
unregisterEvent();
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, [setIsOpenTableSizeSelector]);
|
|
30
|
+
|
|
31
|
+
const registerEvent = useCallback(() => {
|
|
32
|
+
document.addEventListener('click', onSelectorHide);
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const unregisterEvent = useCallback(() => {
|
|
37
|
+
document.removeEventListener('click', onSelectorHide);
|
|
38
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
const onMouseDown = useCallback((e) => {
|
|
42
|
+
e.stopPropagation();
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
setIsOpenTableSizeSelector(true);
|
|
45
|
+
registerEvent();
|
|
46
|
+
}, [setIsOpenTableSizeSelector, registerEvent]);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className='sf-table-menu-item'>
|
|
50
|
+
<MenuItem
|
|
51
|
+
isRichEditor={isRichEditor}
|
|
52
|
+
className={className}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
isActive={isActive}
|
|
55
|
+
onMouseDown={onMouseDown}
|
|
56
|
+
editor={editor}
|
|
57
|
+
{...menuConfig}
|
|
58
|
+
/>
|
|
59
|
+
{isOpenTableSizeSelector && (
|
|
60
|
+
<TableSizeSelector
|
|
61
|
+
editor={editor}
|
|
62
|
+
/>)}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
TableMenu.propTypes = propTypes;
|
|
68
|
+
|
|
69
|
+
export default TableMenu;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.sf-table-menu-item {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.sf-table-size-selector-card {
|
|
6
|
+
position: absolute;
|
|
7
|
+
z-index: 1;
|
|
8
|
+
top: 30px;
|
|
9
|
+
padding: 12px;
|
|
10
|
+
background-color: #fff;
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.sf-table-size-selector-card .sf-table-grid-info {
|
|
15
|
+
margin-bottom: 5px;
|
|
16
|
+
width: 100%;
|
|
17
|
+
text-align: center;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.sf-table-size-selector-card .sf-table-selector-cell {
|
|
21
|
+
height: 15px;
|
|
22
|
+
width: 20px;
|
|
23
|
+
border: 1px solid #ccc;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.sf-table-size-selector-card .sf-table-row {
|
|
27
|
+
display: flex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.sf-table-size-selector-card .sf-table-selector-cell.selected {
|
|
31
|
+
background-color: #ffa94d;
|
|
32
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import MenuDropDown from '../../../commons/menu/menu-drop-down';
|
|
3
|
+
import { MENUS_CONFIG_MAP, TABLE_SUBMENU_MAP, TEXT_ALIGN } from '../../../constants';
|
|
4
|
+
import MenuItem from '../../../commons/menu/menu-item';
|
|
5
|
+
import { changeCellAlign, insertColumn, insertRow, removeColumn, removeRow, removeTable } from '../table-operations';
|
|
6
|
+
|
|
7
|
+
const AlignmentDropDown = ({ editor, readonly }) => {
|
|
8
|
+
const alignmentOperationDropDownList = useMemo(() => [
|
|
9
|
+
{
|
|
10
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_ALIGN_LEFT],
|
|
11
|
+
handleClick: (item) => changeCellAlign(editor, TEXT_ALIGN.LEFT)
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_ALIGN_CENTER],
|
|
15
|
+
handleClick: (item) => changeCellAlign(editor, TEXT_ALIGN.CENTER)
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_ALIGN_RIGHT],
|
|
19
|
+
handleClick: (item) => changeCellAlign(editor, TEXT_ALIGN.RIGHT)
|
|
20
|
+
},
|
|
21
|
+
], [editor]);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<MenuDropDown
|
|
25
|
+
editor={editor}
|
|
26
|
+
readonly={readonly}
|
|
27
|
+
isDisabled={false}
|
|
28
|
+
dropDownList={alignmentOperationDropDownList}
|
|
29
|
+
isShowListItemIcon={true}
|
|
30
|
+
{...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_ALIGN_LEFT]}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const ColumnOperationDropDownList = ({ editor, readonly }) => {
|
|
36
|
+
const columnOperationDropDownList = useMemo(() => [
|
|
37
|
+
{
|
|
38
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_INSERT_COLUMN],
|
|
39
|
+
handleClick: (item) => insertColumn(editor)
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_REMOVE_COLUMN],
|
|
43
|
+
handleClick: (item) => removeColumn(editor)
|
|
44
|
+
},
|
|
45
|
+
], [editor]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<MenuDropDown
|
|
49
|
+
editor={editor}
|
|
50
|
+
readonly={readonly}
|
|
51
|
+
isDisabled={false}
|
|
52
|
+
dropDownList={columnOperationDropDownList}
|
|
53
|
+
{...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_INSERT_COLUMN]}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const RowOperationDropDownList = ({ editor, readonly }) => {
|
|
59
|
+
const rowOperationDropDownList = useMemo(() => [
|
|
60
|
+
{
|
|
61
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_INSERT_ROW],
|
|
62
|
+
handleClick: (item) => insertRow(editor)
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_REMOVE_ROW],
|
|
66
|
+
handleClick: (item) => removeRow(editor)
|
|
67
|
+
},
|
|
68
|
+
], [editor]);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<MenuDropDown
|
|
72
|
+
editor={editor}
|
|
73
|
+
readonly={readonly}
|
|
74
|
+
isDisabled={false}
|
|
75
|
+
dropDownList={rowOperationDropDownList}
|
|
76
|
+
{...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_INSERT_ROW]}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const RemoveTableMenu = ({ editor, readonly, className, isRichEditor }) => {
|
|
82
|
+
return (
|
|
83
|
+
<MenuItem
|
|
84
|
+
isRichEditor={isRichEditor}
|
|
85
|
+
className={className}
|
|
86
|
+
disabled={false}
|
|
87
|
+
isActive={false}
|
|
88
|
+
onMouseDown={() => removeTable(editor)}
|
|
89
|
+
editor={editor}
|
|
90
|
+
|
|
91
|
+
{...MENUS_CONFIG_MAP[TABLE_SUBMENU_MAP.TABLE_DELETE_TABLE]}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
AlignmentDropDown,
|
|
98
|
+
ColumnOperationDropDownList,
|
|
99
|
+
RowOperationDropDownList,
|
|
100
|
+
RemoveTableMenu
|
|
101
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import propType from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { insertTable } from '../helper';
|
|
5
|
+
|
|
6
|
+
import './style.css';
|
|
7
|
+
|
|
8
|
+
const TableSizeSelector = ({ editor }) => {
|
|
9
|
+
const [selectedGridInfo, setSelectedGridInfo] = useState({ row: 0, column: 0 });
|
|
10
|
+
const [showingGridInfo, setShowingGridInfo] = useState({ row: 4, column: 4 });
|
|
11
|
+
|
|
12
|
+
const preRenderTableGrid = useCallback((rowIndex, columnIndex) => {
|
|
13
|
+
const selectedRowNums = rowIndex + 1;
|
|
14
|
+
const selectedColumnNums = columnIndex + 1;
|
|
15
|
+
let preRenderRowNum = selectedRowNums + 1;
|
|
16
|
+
let preRenderColumnNum = selectedColumnNums + 1;
|
|
17
|
+
if (preRenderRowNum < 4) {
|
|
18
|
+
preRenderRowNum = 4;
|
|
19
|
+
} else if (preRenderRowNum > 10) {
|
|
20
|
+
preRenderRowNum = 10;
|
|
21
|
+
}
|
|
22
|
+
if (preRenderColumnNum < 4) {
|
|
23
|
+
preRenderColumnNum = 4;
|
|
24
|
+
} else if (preRenderColumnNum > 10) {
|
|
25
|
+
preRenderColumnNum = 10;
|
|
26
|
+
}
|
|
27
|
+
setSelectedGridInfo({ row: selectedRowNums, column: selectedColumnNums });
|
|
28
|
+
setShowingGridInfo({ row: preRenderRowNum, column: preRenderColumnNum });
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
const handleClickTableCell = useCallback(() => {
|
|
32
|
+
insertTable(editor, selectedGridInfo.row, selectedGridInfo.column);
|
|
33
|
+
}, [editor, selectedGridInfo]);
|
|
34
|
+
|
|
35
|
+
const generateTableGrid = useCallback((rowNum, columnNum) => {
|
|
36
|
+
const { row: selectedRowIndex, column: selectedColumnIndex } = selectedGridInfo;
|
|
37
|
+
const rowElements = [];
|
|
38
|
+
for (let rowIndex = 0; rowIndex < rowNum; rowIndex++) {
|
|
39
|
+
const columnElements = [];
|
|
40
|
+
for (let columnIndex = 0; columnIndex < columnNum; columnIndex++) {
|
|
41
|
+
const isCellSelected = selectedRowIndex > rowIndex && selectedColumnIndex > columnIndex;
|
|
42
|
+
columnElements.push(
|
|
43
|
+
<div
|
|
44
|
+
onClick={handleClickTableCell}
|
|
45
|
+
onMouseEnter={() => preRenderTableGrid(rowIndex, columnIndex)}
|
|
46
|
+
className={classNames('sf-table-selector-cell', { selected: isCellSelected })}
|
|
47
|
+
key={`${rowIndex}-${columnIndex}`}
|
|
48
|
+
></div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
rowElements.push(<div className='sf-table-row' key={rowIndex}>{columnElements}</div>);
|
|
52
|
+
}
|
|
53
|
+
return rowElements;
|
|
54
|
+
}, [handleClickTableCell, preRenderTableGrid, selectedGridInfo]);
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
const tableGridElement = useMemo(() => generateTableGrid(showingGridInfo.row, showingGridInfo.column), [generateTableGrid]);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className='sf-table-size-selector-card'>
|
|
61
|
+
<p className='sf-table-grid-info'>{`${selectedGridInfo.row} x ${selectedGridInfo.column}`}</p>
|
|
62
|
+
{tableGridElement}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
TableSizeSelector.propTypes = {
|
|
68
|
+
editor: propType.object.isRequired,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default TableSizeSelector;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { generateElement } from '../../core';
|
|
2
|
+
import { TABLE, TABLE_CELL, TABLE_ROW } from '../../constants/element-types';
|
|
3
|
+
import { TEXT_ALIGN } from '../../constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {Node[] | String} [options.childrenOrText = ''] If provide a string,that will generate a text node as children automatically
|
|
8
|
+
* @param {keyof TEXT_ALIGN} [options.align = TEXT_ALIGN.left]
|
|
9
|
+
*/
|
|
10
|
+
const generateTableCell = (options = {}) => {
|
|
11
|
+
const { align = TEXT_ALIGN.LEFT, childrenOrText = '' } = options;
|
|
12
|
+
return generateElement(TABLE_CELL, {
|
|
13
|
+
childrenOrText,
|
|
14
|
+
props: { align, },
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @param {Node[] | String} [options.childrenOrText = ''] If provide a string,that will generate a text node as children automatically
|
|
21
|
+
* @param {number | undefined} columnNum If provide a number,that will generate a table row with the number of cells,or will fill the childrenOrText as cells,or will generate a empty cell(if not provide childrenOrText)
|
|
22
|
+
*/
|
|
23
|
+
const generateTableRow = (options) => {
|
|
24
|
+
const { columnNum } = options;
|
|
25
|
+
let { childrenOrText = '' } = options;
|
|
26
|
+
let cells = [];
|
|
27
|
+
if (columnNum) {
|
|
28
|
+
cells = Array.from({ length: columnNum }, () => generateTableCell());
|
|
29
|
+
} else {
|
|
30
|
+
// If not type of string,we'll consider it as a cell array,or throw an error
|
|
31
|
+
if (typeof childrenOrText === 'string') {
|
|
32
|
+
childrenOrText = [generateTableCell({ childrenOrText })];
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(childrenOrText)) {
|
|
35
|
+
throw Error('childrenOrText must be a string or a Node array!');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return generateElement(TABLE_ROW, { childrenOrText: columnNum ? cells : childrenOrText, });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @param {Node[] | String} [options.childrenOrText = ''] If provide a string,that will generate a text node as children automatically
|
|
44
|
+
* @param {number | undefined} rowNum If provide a number,that will generate a table with the number of rows,or will fill the childrenOrText as rows,or will generate a empty row(if not provide childrenOrText)
|
|
45
|
+
* @param {number | undefined} columnNum If provide a number,that will generate a table row with the number of cells,or will fill the childrenOrText as cells,or will generate a empty cell(if not provide childrenOrText)
|
|
46
|
+
*/
|
|
47
|
+
const generateTable = (options) => {
|
|
48
|
+
const { rowNum, columnNum } = options;
|
|
49
|
+
let { childrenOrText = '' } = options;
|
|
50
|
+
let rows = [];
|
|
51
|
+
if (rowNum) {
|
|
52
|
+
rows = Array.from({ length: rowNum }, () => generateTableRow({ columnNum }));
|
|
53
|
+
} else {
|
|
54
|
+
// If not type of string,we'll consider it as a row array,or throw an error
|
|
55
|
+
if (typeof childrenOrText === 'string') {
|
|
56
|
+
childrenOrText = [generateTableRow({ childrenOrText })];
|
|
57
|
+
}
|
|
58
|
+
if (!Array.isArray(childrenOrText)) {
|
|
59
|
+
throw Error('childrenOrText must be a string or a Node array!');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return generateElement(TABLE, { childrenOrText: rowNum ? rows : childrenOrText, });
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
generateTableCell,
|
|
67
|
+
generateTableRow,
|
|
68
|
+
generateTable,
|
|
69
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Editor, Range, Transforms } from 'slate';
|
|
2
|
+
import isHotKey from 'is-hotkey';
|
|
3
|
+
import { jumpOutTableInEditor, getSelectedTableCells, getTableFocusingInfos, isInTable, pasteContentIntoTable, selectCellByGrid } from './helper';
|
|
4
|
+
import { INSERT_POSITION } from '../../constants';
|
|
5
|
+
import setEventTransfer from '../../../containers/custom/set-event-transfer';
|
|
6
|
+
import { TABLE_CELL } from '../../constants/element-types';
|
|
7
|
+
import { insertRow } from './table-operations';
|
|
8
|
+
import getEventTransfer from '../../../containers/custom/get-event-transfer';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {Editor} editor
|
|
12
|
+
*/
|
|
13
|
+
const withTable = (editor) => {
|
|
14
|
+
const { insertBreak, deleteBackward, onHotKeyDown, insertText, deleteForward, onCopy, insertData } = editor;
|
|
15
|
+
const newEditor = editor;
|
|
16
|
+
|
|
17
|
+
newEditor.insertBreak = () => {
|
|
18
|
+
const isTableActive = isInTable(newEditor);
|
|
19
|
+
if (!isTableActive) return insertBreak && insertBreak();
|
|
20
|
+
insertRow(newEditor);
|
|
21
|
+
Transforms.collapse(newEditor, { edge: 'end' });
|
|
22
|
+
Transforms.select(newEditor, editor.selection);
|
|
23
|
+
return;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
newEditor.insertText = (text) => {
|
|
27
|
+
const isTableActive = isInTable(newEditor);
|
|
28
|
+
if (!isTableActive) return insertText && insertText(text);
|
|
29
|
+
const { selection } = newEditor;
|
|
30
|
+
// set element by markdown shortcut;
|
|
31
|
+
if (text === ' ' && selection && Range.isCollapsed(selection)) {
|
|
32
|
+
insertText(text);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return insertText(text);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
newEditor.insertData = (data) => {
|
|
39
|
+
const isTableActive = isInTable(newEditor);
|
|
40
|
+
if (!isTableActive) return insertData && insertData(data);
|
|
41
|
+
const { fragment, type, html, text } = getEventTransfer(data);
|
|
42
|
+
if (type === 'file') {
|
|
43
|
+
return insertData(data);
|
|
44
|
+
}
|
|
45
|
+
return pasteContentIntoTable(newEditor, data);
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
newEditor.deleteBackward = (unit) => {
|
|
50
|
+
const isTableActive = isInTable(newEditor);
|
|
51
|
+
if (!isTableActive) return deleteBackward(unit);
|
|
52
|
+
const { selection } = newEditor;
|
|
53
|
+
// If select range,prevent to delete
|
|
54
|
+
if (!Range.isRange(selection)) return;
|
|
55
|
+
const [tableCellEntry] = Editor.nodes(editor, {
|
|
56
|
+
match: node => node.type === TABLE_CELL,
|
|
57
|
+
mode: 'lowest'
|
|
58
|
+
});
|
|
59
|
+
// If delete empty cell,prevent to delete
|
|
60
|
+
const isStartOfCellText = Editor.isStart(newEditor, selection.anchor, tableCellEntry[1]);
|
|
61
|
+
if (isStartOfCellText) return;
|
|
62
|
+
return deleteBackward && deleteBackward(unit);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
newEditor.deleteForward = (unit) => {
|
|
66
|
+
const isTableActive = isInTable(newEditor);
|
|
67
|
+
if (!isTableActive) return deleteForward(unit);
|
|
68
|
+
const { selection } = newEditor;
|
|
69
|
+
// If select range,prevent to delete
|
|
70
|
+
if (!Range.isRange(selection)) return;
|
|
71
|
+
const [tableCellEntry] = Editor.nodes(editor, {
|
|
72
|
+
match: node => node.type === TABLE_CELL,
|
|
73
|
+
mode: 'lowest'
|
|
74
|
+
});
|
|
75
|
+
// If delete empty cell,prevent to delete
|
|
76
|
+
const isEndOfCellText = Editor.isEnd(newEditor, selection.anchor, tableCellEntry[1]);
|
|
77
|
+
if (isEndOfCellText) return;
|
|
78
|
+
return deleteForward(unit);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
newEditor.onHotKeyDown = (event) => {
|
|
82
|
+
if (!isInTable(newEditor)) return onHotKeyDown && onHotKeyDown(event);
|
|
83
|
+
|
|
84
|
+
if (isHotKey('tab', event)) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
const {
|
|
87
|
+
tableEntry: [tableNode],
|
|
88
|
+
rowEntry: [rowNode],
|
|
89
|
+
columnIndex,
|
|
90
|
+
rowIndex
|
|
91
|
+
} = getTableFocusingInfos(newEditor);
|
|
92
|
+
let nextColumnIndex, nextRowIndex;
|
|
93
|
+
// If focus not at end of columns
|
|
94
|
+
if (columnIndex < rowNode.children.length - 1) {
|
|
95
|
+
nextColumnIndex = columnIndex + 1;
|
|
96
|
+
nextRowIndex = rowIndex;
|
|
97
|
+
} else {
|
|
98
|
+
// If focus not at end of rows,add new row
|
|
99
|
+
const shouldAddNewRow = rowIndex === tableNode.children.length - 1;
|
|
100
|
+
nextColumnIndex = 0;
|
|
101
|
+
nextRowIndex = rowIndex + 1;
|
|
102
|
+
shouldAddNewRow && insertRow(newEditor, INSERT_POSITION.AFTER);
|
|
103
|
+
}
|
|
104
|
+
selectCellByGrid(newEditor, nextRowIndex, nextColumnIndex);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (isHotKey('shift+tab', event)) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
const {
|
|
111
|
+
rowEntry: [rowNode],
|
|
112
|
+
columnIndex,
|
|
113
|
+
rowIndex
|
|
114
|
+
} = getTableFocusingInfos(newEditor);
|
|
115
|
+
let previousColumnIndex, previousRowIndex;
|
|
116
|
+
// If focus not at start of columns
|
|
117
|
+
if (columnIndex > 0) {
|
|
118
|
+
previousRowIndex = rowIndex;
|
|
119
|
+
previousColumnIndex = columnIndex - 1;
|
|
120
|
+
} else {
|
|
121
|
+
// If focus not at start of rows
|
|
122
|
+
if (rowIndex > 0) {
|
|
123
|
+
previousRowIndex = rowIndex - 1;
|
|
124
|
+
previousColumnIndex = rowNode.children.length - 1;
|
|
125
|
+
} else {
|
|
126
|
+
previousRowIndex = 0;
|
|
127
|
+
previousColumnIndex = 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
selectCellByGrid(newEditor, previousRowIndex, previousColumnIndex);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (isHotKey('mod+enter', event)) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
jumpOutTableInEditor(newEditor);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return onHotKeyDown && onHotKeyDown(event);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
newEditor.onCopy = (event) => {
|
|
144
|
+
if (!isInTable(newEditor)) {
|
|
145
|
+
return onCopy && onCopy(event);
|
|
146
|
+
}
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
event.stopPropagation();
|
|
149
|
+
const tableNode = getSelectedTableCells(newEditor);
|
|
150
|
+
if (tableNode) {
|
|
151
|
+
setEventTransfer(event, 'fragment', tableNode);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return newEditor;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export default withTable;
|