@seafile/seafile-editor 0.4.7 → 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 -132
- 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/comment-dialog.css +0 -50
- 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/issue-card.css +0 -43
- 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/comment-dialog.js +0 -97
- 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/markdown-lint.js +0 -72
- 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/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 -280
- 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/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,28 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
|
|
5
|
+
const OutlineItem = ({ node, activeId }) => {
|
|
6
|
+
const onItemClick = useCallback(() => {
|
|
7
|
+
const { id } = node;
|
|
8
|
+
document.getElementById(id).scrollIntoView();
|
|
9
|
+
}, [node]);
|
|
10
|
+
|
|
11
|
+
const className = classNames({
|
|
12
|
+
'outline-h2': node.type === 'header2',
|
|
13
|
+
'outline-h3': node.type === 'header3',
|
|
14
|
+
'active': node.id === activeId,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className={className} onClick={onItemClick}>
|
|
19
|
+
{node.children.map(child => child.text).join('')}
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
OutlineItem.propTypes = {
|
|
25
|
+
node: PropTypes.object,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default OutlineItem;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
.sf-editor-outline {
|
|
2
|
+
border-left: 1px solid #ddd;
|
|
3
|
+
padding: .5rem 1rem .5rem 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.sf-editor-outline .outline-h2,
|
|
7
|
+
.sf-editor-outline .outline-h3 {
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
text-overflow: ellipsis;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.sf-editor-outline .outline-h2 {
|
|
14
|
+
margin-left: 20px;
|
|
15
|
+
line-height: 2.5;
|
|
16
|
+
color:#364149;
|
|
17
|
+
white-space: nowrap;
|
|
18
|
+
cursor:pointer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.sf-editor-outline .outline-h2:hover {
|
|
22
|
+
color: #eb8205;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.sf-editor-outline .outline-h3 {
|
|
26
|
+
margin-left: 40px;
|
|
27
|
+
line-height: 2.5;
|
|
28
|
+
color:#364149;
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
cursor:pointer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.sf-editor-outline .outline-h3:hover {
|
|
34
|
+
color: #eb8205;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.sf-editor-outline .empty-container {
|
|
38
|
+
margin-top: 10px;
|
|
39
|
+
text-align: center;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.sf-editor-outline .outline-h2.active,
|
|
43
|
+
.sf-editor-outline .outline-h3.active {
|
|
44
|
+
color: #eb8205;
|
|
45
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import className from 'classnames';
|
|
4
|
+
import { basicSetup, EditorView } from 'codemirror';
|
|
5
|
+
import { markdown } from '@codemirror/lang-markdown';
|
|
6
|
+
import { languages } from '@codemirror/language-data';
|
|
7
|
+
|
|
8
|
+
import './code-mirror.css';
|
|
9
|
+
|
|
10
|
+
const propTypes = {
|
|
11
|
+
autoFocus: PropTypes.bool,
|
|
12
|
+
initialValue: PropTypes.string,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class SeafileCodeMirror extends React.Component {
|
|
16
|
+
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
const { initialValue, autoFocus } = this.props;
|
|
19
|
+
this.view = new EditorView({
|
|
20
|
+
doc: initialValue,
|
|
21
|
+
extensions: [
|
|
22
|
+
basicSetup,
|
|
23
|
+
markdown({ codeLanguages: languages }),
|
|
24
|
+
EditorView.updateListener.of((viewUpdate) => {
|
|
25
|
+
this.onValueChanged(viewUpdate);
|
|
26
|
+
})
|
|
27
|
+
],
|
|
28
|
+
parent: this.codeMirrorRef,
|
|
29
|
+
});
|
|
30
|
+
if (autoFocus) this.focus();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentWillUnmount() {
|
|
34
|
+
if (this.view) {
|
|
35
|
+
this.view.destroy();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onValueChanged = (viewUpdate) => {
|
|
40
|
+
const { onChange } = this.props;
|
|
41
|
+
if (onChange && viewUpdate.docChanged) {
|
|
42
|
+
const doc = viewUpdate.state.doc;
|
|
43
|
+
const value = doc.toString();
|
|
44
|
+
onChange(value);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
focus = () => {
|
|
49
|
+
this.view.focus();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
scrollIntoView = (pos) => {
|
|
53
|
+
EditorView.scrollIntoView(pos);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
setCodeMirrorRef = (ref) => {
|
|
58
|
+
this.codeMirrorRef = ref;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
render() {
|
|
62
|
+
return (
|
|
63
|
+
<div className={className('sf-code-mirror', this.props.className)}>
|
|
64
|
+
<div ref={this.setCodeMirrorRef} />
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
SeafileCodeMirror.propTypes = propTypes;
|
|
72
|
+
|
|
73
|
+
export default SeafileCodeMirror;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import isHotkey from 'is-hotkey';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import processor from '../../slate-convert/md-to-html';
|
|
5
|
+
import SeafileCodeMirror from './code-mirror';
|
|
6
|
+
|
|
7
|
+
import './style.css';
|
|
8
|
+
|
|
9
|
+
const propTypes = {
|
|
10
|
+
autoFocus: PropTypes.bool,
|
|
11
|
+
value: PropTypes.string,
|
|
12
|
+
onSave: PropTypes.func,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class PlainMarkdownEditor extends React.Component {
|
|
16
|
+
|
|
17
|
+
constructor(props) {
|
|
18
|
+
super(props);
|
|
19
|
+
this.state = {
|
|
20
|
+
editorValue: props.value,
|
|
21
|
+
previewValue: '',
|
|
22
|
+
isMouseInLeftSide: false,
|
|
23
|
+
isMouseInRightSide: false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* the data about scroll, these variable has nothing to width react
|
|
29
|
+
* they are not state
|
|
30
|
+
* */
|
|
31
|
+
scrollData = {
|
|
32
|
+
scrollPercentage: 0,
|
|
33
|
+
leftPanel: null,
|
|
34
|
+
rightPanel: null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
componentDidMount() {
|
|
38
|
+
// get relevant dom when component mounted instead of get them when scrolling to improve performance
|
|
39
|
+
this.scrollData.leftPanel = document.querySelector('.sf-plain-editor-left-panel');
|
|
40
|
+
this.scrollData.rightPanel = document.querySelector('.sf-plain-editor-right-panel');
|
|
41
|
+
this.setContent(this.props.value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
componentDidUpdate() {
|
|
45
|
+
// render math formula
|
|
46
|
+
// window.MathJax.typesetPromise(document.querySelectorAll('.math-display'));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setContent = (markdownContent) => {
|
|
50
|
+
this.setState({ editorValue: markdownContent });
|
|
51
|
+
processor.process(markdownContent, (error, vfile) => {
|
|
52
|
+
var html = String(vfile);
|
|
53
|
+
this.setState({ previewValue: html });
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
updateCode = (newCode) => {
|
|
58
|
+
this.setContent(newCode);
|
|
59
|
+
this.props.onSave && this.props.onSave(newCode);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
onEnterLeftPanel = () => {
|
|
63
|
+
this.setState({ isMouseInLeftSide: true });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
onLeaveLeftPanel = () => {
|
|
67
|
+
this.setState({ isMouseInLeftSide: false });
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
onLeftScroll = (e) => {
|
|
71
|
+
const { isMouseInLeftSide } = this.state;
|
|
72
|
+
if (!isMouseInLeftSide) return;
|
|
73
|
+
let srcElement = this.scrollData.leftPanel;
|
|
74
|
+
this.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
|
|
75
|
+
this.scrollData.rightPanel.scrollTop = this.scrollData.scrollPercentage * this.scrollData.rightPanel.scrollHeight;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
onEnterRightPanel = () => {
|
|
79
|
+
this.setState({ isMouseInRightSide: true });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
onLeaveRightPanel = () => {
|
|
83
|
+
this.setState({ isMouseInRightSide: false });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
onRightScroll = (e) => {
|
|
87
|
+
const { isMouseInRightSide } = this.state;
|
|
88
|
+
if (!isMouseInRightSide) return;
|
|
89
|
+
let srcElement = this.scrollData.rightPanel;
|
|
90
|
+
this.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
|
|
91
|
+
this.scrollData.leftPanel.scrollTop = this.scrollData.scrollPercentage * this.scrollData.leftPanel.scrollHeight;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
onHotKey = (event) => {
|
|
95
|
+
const { onSave } = this.props;
|
|
96
|
+
if (isHotkey('mod+s', event)) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
onSave && onSave(this.state.editorValue);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
render() {
|
|
104
|
+
const { editorValue, previewValue } = this.state;
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div className='sf-plain-editor'>
|
|
108
|
+
<div className="sf-plain-editor-main d-flex" onKeyDown={this.onHotKey}>
|
|
109
|
+
<div
|
|
110
|
+
className="sf-plain-editor-left-panel"
|
|
111
|
+
onMouseLeave={this.onLeaveLeftPanel}
|
|
112
|
+
onMouseEnter={this.onEnterLeftPanel}
|
|
113
|
+
onScroll={this.onLeftScroll}
|
|
114
|
+
>
|
|
115
|
+
<SeafileCodeMirror autoFocus={true} initialValue={editorValue} onChange={this.updateCode} />
|
|
116
|
+
</div>
|
|
117
|
+
<div
|
|
118
|
+
className="sf-plain-editor-right-panel"
|
|
119
|
+
onMouseEnter={this.onEnterRightPanel}
|
|
120
|
+
onMouseLeave={this.onLeaveRightPanel}
|
|
121
|
+
onScroll={this.onRightScroll}
|
|
122
|
+
>
|
|
123
|
+
<div className="preview">
|
|
124
|
+
<div className="rendered-markdown article" dangerouslySetInnerHTML={{ __html: previewValue }}></div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
PlainMarkdownEditor.propTypes = propTypes;
|
|
135
|
+
|
|
136
|
+
export default PlainMarkdownEditor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.plain-editor {
|
|
1
|
+
.sf-plain-editor {
|
|
2
2
|
flex: 1;
|
|
3
3
|
display: flex;
|
|
4
4
|
min-height: 0;
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/* fix plain editor main height */
|
|
10
|
-
.plain-editor-main {
|
|
10
|
+
.sf-plain-editor-main {
|
|
11
11
|
position: absolute;
|
|
12
12
|
inset: 0;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
.plain-editor-left-panel {
|
|
15
|
+
.sf-plain-editor-left-panel {
|
|
16
16
|
height: 100%;
|
|
17
17
|
width: 50%;
|
|
18
18
|
background-color: #fff;
|
|
@@ -21,10 +21,18 @@
|
|
|
21
21
|
overflow-x: hidden;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
.plain-editor-right-panel {
|
|
24
|
+
.sf-plain-editor-right-panel {
|
|
25
25
|
height: 100%;
|
|
26
26
|
width: 50%;
|
|
27
27
|
background-color: rgb(250,250,249);
|
|
28
28
|
overflow-y: scroll;
|
|
29
29
|
overflow-x: hidden;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
.rendered-markdown.article {
|
|
33
|
+
padding:0 20px 20px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.rendered-markdown tbody tr:first-child {
|
|
37
|
+
font-weight: 400;
|
|
38
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { useCallback, useState, useMemo, useEffect } from 'react';
|
|
2
|
+
import { Editable, Slate } from 'slate-react';
|
|
3
|
+
import { Editor } from 'slate';
|
|
4
|
+
import { baseEditor, Toolbar, renderElement, renderLeaf } from '../../extension';
|
|
5
|
+
import EventBus from '../../utils/event-bus';
|
|
6
|
+
import EventProxy from '../../utils/event-handler';
|
|
7
|
+
import withPropsEditor from './with-props-editor';
|
|
8
|
+
import { focusEditor } from '../../extension/core';
|
|
9
|
+
|
|
10
|
+
import '../../assets/css/slate-editor.css';
|
|
11
|
+
|
|
12
|
+
export default function SimpleSlateEditor({ value, editorApi, onSave, isSupportFormula }) {
|
|
13
|
+
const [slateValue, setSlateValue] = useState(value);
|
|
14
|
+
|
|
15
|
+
const editor = useMemo(() => withPropsEditor(baseEditor, { editorApi, onSave }), [editorApi, onSave]);
|
|
16
|
+
const eventProxy = useMemo(() => {
|
|
17
|
+
return new EventProxy(editor);
|
|
18
|
+
}, [editor]);
|
|
19
|
+
|
|
20
|
+
const onChange = useCallback((value) => {
|
|
21
|
+
setSlateValue(value);
|
|
22
|
+
onSave && onSave(value);
|
|
23
|
+
const eventBus = EventBus.getInstance();
|
|
24
|
+
eventBus.dispatch('change');
|
|
25
|
+
}, [onSave]);
|
|
26
|
+
|
|
27
|
+
// useMount: focus editor
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const timer = setTimeout(() => {
|
|
30
|
+
const [firstNode] = editor.children;
|
|
31
|
+
if (firstNode) {
|
|
32
|
+
const [firstNodeFirstChild] = firstNode.children;
|
|
33
|
+
|
|
34
|
+
if (firstNodeFirstChild) {
|
|
35
|
+
const endOfFirstNode = Editor.end(editor, [0, 0]);
|
|
36
|
+
const range = {
|
|
37
|
+
anchor: endOfFirstNode,
|
|
38
|
+
focus: endOfFirstNode,
|
|
39
|
+
};
|
|
40
|
+
focusEditor(editor, range);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, 300);
|
|
44
|
+
return () => {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
};
|
|
47
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className='sf-slate-editor-container'>
|
|
52
|
+
<Toolbar editor={editor} isSupportFormula={isSupportFormula} />
|
|
53
|
+
<div className='sf-slate-editor-content'>
|
|
54
|
+
<Slate editor={editor} initialValue={slateValue} onChange={onChange}>
|
|
55
|
+
<div className='sf-slate-scroll-container'>
|
|
56
|
+
<div className='sf-slate-article-container'>
|
|
57
|
+
<div className='article'>
|
|
58
|
+
<Editable
|
|
59
|
+
renderElement={renderElement}
|
|
60
|
+
renderLeaf={renderLeaf}
|
|
61
|
+
onKeyDown={eventProxy.onKeyDown}
|
|
62
|
+
onCopy={eventProxy.onCopy}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</Slate>
|
|
68
|
+
</div>
|
|
69
|
+
</div >
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
const withPropsEditor = (editor, props = {}) => {
|
|
3
|
+
const newEditor = editor;
|
|
4
|
+
if (props.editorApi) {
|
|
5
|
+
newEditor.api = props.editorApi;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (props.onSave) {
|
|
9
|
+
newEditor.onSave = props.onSave;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return newEditor;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default withPropsEditor;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import EventBus from '../../../utils/event-bus';
|
|
4
|
+
import { EXTERNAL_EVENTS, INTERNAL_EVENTS } from '../../../constants/event-types';
|
|
5
|
+
import HotKeysHelper from '../../../containers/hotkeys-helper';
|
|
6
|
+
import ArticleInfo from '../../../containers/article-info';
|
|
7
|
+
|
|
8
|
+
import './style.css';
|
|
9
|
+
|
|
10
|
+
export default function EditorHelp({ children }) {
|
|
11
|
+
|
|
12
|
+
const [isShowHelpInfo, setIsShowHelpInfo] = useState(false);
|
|
13
|
+
const [isShowArticleInfo, setIsShowArticleInfo] = useState(false);
|
|
14
|
+
|
|
15
|
+
const updateArticleInfoState = useCallback((state) => {
|
|
16
|
+
setIsShowArticleInfo(state);
|
|
17
|
+
setIsShowHelpInfo(false);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
const updateHelpInfoState = useCallback((state) => {
|
|
21
|
+
setIsShowHelpInfo(state);
|
|
22
|
+
setIsShowArticleInfo(false);
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const eventBus = EventBus.getInstance();
|
|
27
|
+
const unsubscribeArticleInfo = eventBus.subscribe(INTERNAL_EVENTS.ON_ARTICLE_INFO_TOGGLE, updateArticleInfoState);
|
|
28
|
+
const unsubscribeHelpInfo = eventBus.subscribe(EXTERNAL_EVENTS.ON_HELP_INFO_TOGGLE, updateHelpInfoState);
|
|
29
|
+
return () => {
|
|
30
|
+
unsubscribeHelpInfo();
|
|
31
|
+
unsubscribeArticleInfo();
|
|
32
|
+
};
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const containerClass = classNames('sf-markdown-help-wrapper', {
|
|
37
|
+
'active': isShowArticleInfo || isShowHelpInfo
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className={containerClass}>
|
|
42
|
+
{isShowArticleInfo && <ArticleInfo children={children} />}
|
|
43
|
+
{isShowHelpInfo && <HotKeysHelper />}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.sf-markdown-help-wrapper {
|
|
2
|
+
display: none;
|
|
3
|
+
background-color: #fff;
|
|
4
|
+
border-left: 1px solid #eee;
|
|
5
|
+
flex: 0 0 350px;
|
|
6
|
+
height: 100%;
|
|
7
|
+
overflow-x: hidden;
|
|
8
|
+
overflow-y: auto;
|
|
9
|
+
width: 250px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sf-markdown-help-wrapper.active {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { useCallback, useState, useMemo, useEffect, useRef } from 'react';
|
|
2
|
+
import { Editable, Slate } from 'slate-react';
|
|
3
|
+
import { Editor } from 'slate';
|
|
4
|
+
import { baseEditor, Toolbar, renderElement, renderLeaf } from '../../extension';
|
|
5
|
+
import EventBus from '../../utils/event-bus';
|
|
6
|
+
import EventProxy from '../../utils/event-handler';
|
|
7
|
+
import withPropsEditor from './with-props-editor';
|
|
8
|
+
import EditorHelp from './editor-help';
|
|
9
|
+
import { focusEditor } from '../../extension/core';
|
|
10
|
+
import { ScrollContext } from '../../hooks/use-scroll-context';
|
|
11
|
+
|
|
12
|
+
import '../../assets/css/slate-editor.css';
|
|
13
|
+
|
|
14
|
+
export default function SlateEditor({ value, editorApi, onSave, isSupportFormula, children }) {
|
|
15
|
+
const [slateValue, setSlateValue] = useState(value);
|
|
16
|
+
|
|
17
|
+
const scrollRef = useRef(null);
|
|
18
|
+
const editor = useMemo(() => withPropsEditor(baseEditor, { editorApi, onSave }), [editorApi, onSave]);
|
|
19
|
+
const eventProxy = useMemo(() => {
|
|
20
|
+
return new EventProxy(editor);
|
|
21
|
+
}, [editor]);
|
|
22
|
+
|
|
23
|
+
const onChange = useCallback((value) => {
|
|
24
|
+
setSlateValue(value);
|
|
25
|
+
onSave && onSave(value);
|
|
26
|
+
const eventBus = EventBus.getInstance();
|
|
27
|
+
eventBus.dispatch('change');
|
|
28
|
+
}, [onSave]);
|
|
29
|
+
|
|
30
|
+
// useMount: focus editor
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
const [firstNode] = editor.children;
|
|
34
|
+
if (firstNode) {
|
|
35
|
+
const [firstNodeFirstChild] = firstNode.children;
|
|
36
|
+
|
|
37
|
+
if (firstNodeFirstChild) {
|
|
38
|
+
const endOfFirstNode = Editor.end(editor, [0, 0]);
|
|
39
|
+
const range = {
|
|
40
|
+
anchor: endOfFirstNode,
|
|
41
|
+
focus: endOfFirstNode,
|
|
42
|
+
};
|
|
43
|
+
focusEditor(editor, range);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, 300);
|
|
47
|
+
return () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
};
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div className='sf-slate-editor-container'>
|
|
55
|
+
<Toolbar editor={editor} isRichEditor={true} isSupportFormula={isSupportFormula} />
|
|
56
|
+
<div className='sf-slate-editor-content'>
|
|
57
|
+
<ScrollContext.Provider value={{ scrollRef }}>
|
|
58
|
+
<Slate editor={editor} initialValue={slateValue} onChange={onChange}>
|
|
59
|
+
<div ref={scrollRef} className='sf-slate-scroll-container'>
|
|
60
|
+
<div className='sf-slate-article-container'>
|
|
61
|
+
<div className='article'>
|
|
62
|
+
<Editable
|
|
63
|
+
renderElement={renderElement}
|
|
64
|
+
renderLeaf={renderLeaf}
|
|
65
|
+
onKeyDown={eventProxy.onKeyDown}
|
|
66
|
+
onCopy={eventProxy.onCopy}
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<EditorHelp children={children}></EditorHelp>
|
|
72
|
+
</Slate>
|
|
73
|
+
</ScrollContext.Provider>
|
|
74
|
+
</div>
|
|
75
|
+
</div >
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
const withPropsEditor = (editor, props = {}) => {
|
|
3
|
+
const newEditor = editor;
|
|
4
|
+
if (props.editorApi) {
|
|
5
|
+
newEditor.api = props.editorApi;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (props.onSave) {
|
|
9
|
+
newEditor.onSave = props.onSave;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return newEditor;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default withPropsEditor;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { baseEditor, renderElement, renderLeaf } from '../../extension';
|
|
3
|
+
import { Editable, Slate } from 'slate-react';
|
|
4
|
+
import Outline from '../../containers/outline';
|
|
5
|
+
import { ScrollContext } from '../../hooks/use-scroll-context';
|
|
6
|
+
|
|
7
|
+
import './style.css';
|
|
8
|
+
|
|
9
|
+
export default function SlateViewer({ value, isShowOutline }) {
|
|
10
|
+
|
|
11
|
+
const scrollRef = useRef(null);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Slate editor={baseEditor} initialValue={value}>
|
|
15
|
+
<ScrollContext.Provider value={{ scrollRef }}>
|
|
16
|
+
<div ref={scrollRef} className={`sf-slate-viewer-scroll-container ${isShowOutline ? 'outline' : ''}`}>
|
|
17
|
+
<div className='sf-slate-viewer-article-container'>
|
|
18
|
+
<div className='article'>
|
|
19
|
+
<Editable
|
|
20
|
+
readOnly
|
|
21
|
+
renderElement={renderElement}
|
|
22
|
+
renderLeaf={renderLeaf}
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
{isShowOutline && (
|
|
27
|
+
<div className='sf-slate-viewer-outline'>
|
|
28
|
+
<Outline editor={baseEditor} />
|
|
29
|
+
</div>
|
|
30
|
+
)}
|
|
31
|
+
</div>
|
|
32
|
+
</ScrollContext.Provider>
|
|
33
|
+
</Slate>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.sf-slate-viewer-scroll-container {
|
|
2
|
+
flex: 1;
|
|
3
|
+
display: flex;
|
|
4
|
+
min-height: 0;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
overflow: auto;
|
|
7
|
+
background: #f4f4f4;
|
|
8
|
+
border: 1px solid #ededed;
|
|
9
|
+
padding: 30px 0 15px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sf-slate-viewer-scroll-container .sf-slate-viewer-article-container {
|
|
13
|
+
flex: 1;
|
|
14
|
+
margin: 0 auto 15px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sf-slate-viewer-scroll-container.outline .sf-slate-viewer-article-container {
|
|
18
|
+
margin: 0 340px 15px 40px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.sf-slate-viewer-scroll-container .sf-slate-viewer-outline {
|
|
22
|
+
height: 80%;
|
|
23
|
+
overflow: auto;
|
|
24
|
+
padding-right: 1rem;
|
|
25
|
+
position: fixed;
|
|
26
|
+
right: 0;
|
|
27
|
+
top: 97px;
|
|
28
|
+
width: 300px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.sf-slate-viewer-scroll-container .article {
|
|
32
|
+
margin: 0 auto;
|
|
33
|
+
padding: 40px 60px;
|
|
34
|
+
max-width: 950px;
|
|
35
|
+
min-height: calc(100% - 15px);
|
|
36
|
+
border: 1px solid #e6e6dd;
|
|
37
|
+
background: #fff;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|