@seafile/seafile-editor 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/event-types.js +16 -0
- package/dist/constants/hot-keys.js +43 -0
- package/dist/containers/article-info/index.js +57 -0
- package/dist/containers/custom/get-event-transfer.js +38 -0
- package/dist/containers/custom/set-event-transfer.js +36 -0
- package/dist/containers/hotkeys-helper/classify-hotkeys.js +39 -0
- package/dist/containers/hotkeys-helper/index.js +52 -0
- package/dist/containers/loading/index.js +33 -0
- package/dist/containers/outline/index.js +80 -0
- package/dist/containers/outline/outline-item.js +30 -0
- package/dist/editors/plain-markdown-editor/code-mirror.js +84 -0
- package/dist/editors/plain-markdown-editor/index.js +149 -0
- package/dist/editors/simple-slate-editor /index.js +90 -0
- package/dist/editors/simple-slate-editor /with-props-editor.js +18 -0
- package/dist/editors/slate-editor/editor-help/index.js +53 -0
- package/dist/editors/slate-editor/index.js +102 -0
- package/dist/editors/slate-editor/with-props-editor.js +18 -0
- package/dist/editors/slate-viewer/index.js +42 -0
- package/dist/extension/commons/element-popover/index.js +64 -0
- package/dist/extension/commons/index.js +26 -0
- package/dist/extension/commons/menu/index.js +21 -0
- package/dist/extension/commons/menu/menu-drop-down.js +104 -0
- package/dist/extension/commons/menu/menu-group.js +18 -0
- package/dist/extension/commons/menu/menu-item.js +54 -0
- package/dist/extension/commons/tooltip/index.js +26 -0
- package/dist/extension/constants/element-types.js +29 -0
- package/dist/extension/constants/index.js +46 -0
- package/dist/extension/constants/keyboard.js +33 -0
- package/dist/extension/constants/menus-config.js +121 -0
- package/dist/extension/core/index.js +38 -0
- package/dist/extension/core/queries/index.js +479 -0
- package/dist/extension/core/transforms/focus-editor.js +17 -0
- package/dist/extension/core/transforms/index.js +49 -0
- package/dist/extension/core/transforms/move-children.js +35 -0
- package/dist/extension/core/transforms/remove-node-children.js +31 -0
- package/dist/extension/core/transforms/replace-node-children.js +22 -0
- package/dist/extension/core/utils/index.js +103 -0
- package/dist/extension/editor.js +19 -0
- package/dist/extension/index.js +48 -0
- package/dist/extension/plugins/blockquote/helpers.js +77 -0
- package/dist/extension/plugins/blockquote/index.js +18 -0
- package/dist/extension/plugins/blockquote/menu/index.js +33 -0
- package/dist/extension/plugins/blockquote/plugin.js +70 -0
- package/dist/extension/plugins/blockquote/render-elem.js +18 -0
- package/dist/extension/plugins/check-list/helper.js +35 -0
- package/dist/extension/plugins/check-list/index.js +19 -0
- package/dist/extension/plugins/check-list/menu/index.js +40 -0
- package/dist/extension/plugins/check-list/plugin.js +50 -0
- package/dist/extension/plugins/check-list/render-elem.js +44 -0
- package/dist/extension/plugins/clear-format/helpers.js +65 -0
- package/dist/extension/plugins/clear-format/menu/index.js +34 -0
- package/dist/extension/plugins/code-block/helpers.js +175 -0
- package/dist/extension/plugins/code-block/index.js +20 -0
- package/dist/extension/plugins/code-block/menu/index.js +37 -0
- package/dist/extension/plugins/code-block/plugin.js +270 -0
- package/dist/extension/plugins/code-block/render-elem/constant.js +12 -0
- package/dist/extension/plugins/code-block/render-elem/index.js +62 -0
- package/dist/extension/plugins/code-block/render-elem/language-selector.js +39 -0
- package/dist/extension/plugins/formula/helper.js +74 -0
- package/dist/extension/plugins/formula/index.js +19 -0
- package/dist/extension/plugins/formula/menu/formula-modal.js +97 -0
- package/dist/extension/plugins/formula/menu/index.js +71 -0
- package/dist/extension/plugins/formula/plugin.js +18 -0
- package/dist/extension/plugins/formula/render-elem.js +48 -0
- package/dist/extension/plugins/header/helper.js +57 -0
- package/dist/extension/plugins/header/index.js +19 -0
- package/dist/extension/plugins/header/menu/index.js +110 -0
- package/dist/extension/plugins/header/plugin.js +146 -0
- package/dist/extension/plugins/header/render-elem.js +34 -0
- package/dist/extension/plugins/image/helper.js +62 -0
- package/dist/extension/plugins/image/index.js +19 -0
- package/dist/extension/plugins/image/menu/image-menu-dialog.js +79 -0
- package/dist/extension/plugins/image/menu/image-menu-popover.js +96 -0
- package/dist/extension/plugins/image/menu/index.js +58 -0
- package/dist/extension/plugins/image/plugin.js +24 -0
- package/dist/extension/plugins/image/render-element/image-previewer.js +78 -0
- package/dist/extension/plugins/image/render-element/index.js +122 -0
- package/dist/extension/plugins/index.js +95 -0
- package/dist/extension/plugins/link/helper.js +235 -0
- package/dist/extension/plugins/link/index.js +19 -0
- package/dist/extension/plugins/link/menu/index.js +98 -0
- package/dist/extension/plugins/link/menu/link-modal.js +163 -0
- package/dist/extension/plugins/link/plugin.js +104 -0
- package/dist/extension/plugins/link/render-elem/index.js +83 -0
- package/dist/extension/plugins/link/render-elem/link-popover.js +77 -0
- package/dist/extension/plugins/list/constant.js +8 -0
- package/dist/extension/plugins/list/helpers.js +78 -0
- package/dist/extension/plugins/list/index.js +19 -0
- package/dist/extension/plugins/list/menu/index.js +46 -0
- package/dist/extension/plugins/list/plugin/index.js +48 -0
- package/dist/extension/plugins/list/plugin/insert-break-list.js +28 -0
- package/dist/extension/plugins/list/plugin/insert-fragment-list.js +190 -0
- package/dist/extension/plugins/list/plugin/normalize-list.js +81 -0
- package/dist/extension/plugins/list/plugin/on-tab-handle.js +52 -0
- package/dist/extension/plugins/list/queries/index.js +51 -0
- package/dist/extension/plugins/list/render-elem/index.js +38 -0
- package/dist/extension/plugins/list/transforms/index.js +75 -0
- package/dist/extension/plugins/list/transforms/insert-list-item.js +100 -0
- package/dist/extension/plugins/list/transforms/move-list-item-down.js +51 -0
- package/dist/extension/plugins/list/transforms/move-list-item-up.js +124 -0
- package/dist/extension/plugins/list/transforms/move-list-items-to-list.js +62 -0
- package/dist/extension/plugins/list/transforms/move-list-items.js +73 -0
- package/dist/extension/plugins/list/transforms/normalize-list-item.js +125 -0
- package/dist/extension/plugins/list/transforms/normalize-nested-list.js +40 -0
- package/dist/extension/plugins/list/transforms/remove-first-list-item.js +24 -0
- package/dist/extension/plugins/list/transforms/transforms-to-list.js +148 -0
- package/dist/extension/plugins/list/transforms/unwrap-list.js +50 -0
- package/dist/extension/plugins/node-id/constants.js +24 -0
- package/dist/extension/plugins/node-id/helpers.js +69 -0
- package/dist/extension/plugins/node-id/index.js +12 -0
- package/dist/extension/plugins/node-id/with-node-id.js +39 -0
- package/dist/extension/plugins/paragraph/helper.js +16 -0
- package/dist/extension/plugins/paragraph/index.js +17 -0
- package/dist/extension/plugins/paragraph/plugin.js +47 -0
- package/dist/extension/plugins/paragraph/render-elem.js +18 -0
- package/dist/extension/plugins/table/constant.js +9 -0
- package/dist/extension/plugins/table/helper.js +232 -0
- package/dist/extension/plugins/table/index.js +21 -0
- package/dist/extension/plugins/table/menu/index.js +64 -0
- package/dist/extension/plugins/table/menu/table-operator.js +98 -0
- package/dist/extension/plugins/table/menu/table-size-selector.js +100 -0
- package/dist/extension/plugins/table/model.js +95 -0
- package/dist/extension/plugins/table/plugin.js +173 -0
- package/dist/extension/plugins/table/render-elem/context-menu.js +93 -0
- package/dist/extension/plugins/table/render-elem/index.js +189 -0
- package/dist/extension/plugins/table/table-operations.js +187 -0
- package/dist/extension/plugins/text-style/helpers.js +44 -0
- package/dist/extension/plugins/text-style/index.js +17 -0
- package/dist/extension/plugins/text-style/menu/index.js +34 -0
- package/dist/extension/plugins/text-style/plugin.js +36 -0
- package/dist/extension/plugins/text-style/render-elem.js +52 -0
- package/dist/extension/render/render-element.js +113 -0
- package/dist/extension/render/render-leaf.js +21 -0
- package/dist/extension/toolbar/header-toolbar/index.js +113 -0
- package/dist/extension/toolbar/index.js +13 -0
- package/dist/extension/toolbar/user-help/shortcut-dialog.js +141 -0
- package/dist/hooks/use-mathjax.js +51 -0
- package/dist/hooks/use-scroll-context.js +17 -0
- package/dist/hooks/use-selection-update.js +25 -0
- package/dist/index.js +80 -0
- package/dist/pages/markdown-editor.js +65 -0
- package/dist/pages/markdown-view.js +49 -0
- package/dist/pages/rich-markdown-editor.js +111 -0
- package/dist/pages/simple-editor.js +63 -0
- package/dist/slate-convert/html-to-slate/constants.js +40 -0
- package/dist/slate-convert/html-to-slate/helper.js +60 -0
- package/dist/slate-convert/html-to-slate/index.js +138 -0
- package/dist/slate-convert/html-to-slate/rules/blockquote.js +22 -0
- package/dist/slate-convert/html-to-slate/rules/check-list.js +25 -0
- package/dist/slate-convert/html-to-slate/rules/code-block.js +93 -0
- package/dist/slate-convert/html-to-slate/rules/header.js +22 -0
- package/dist/slate-convert/html-to-slate/rules/image.js +27 -0
- package/dist/slate-convert/html-to-slate/rules/index.js +18 -0
- package/dist/slate-convert/html-to-slate/rules/link.js +27 -0
- package/dist/slate-convert/html-to-slate/rules/list.js +55 -0
- package/dist/slate-convert/html-to-slate/rules/paragraph.js +22 -0
- package/dist/slate-convert/html-to-slate/rules/table.js +39 -0
- package/dist/slate-convert/html-to-slate/rules/text.js +61 -0
- package/dist/slate-convert/index.js +34 -0
- package/dist/slate-convert/md-to-html/index.js +53 -0
- package/dist/slate-convert/md-to-html/sanitize-schema.js +24 -0
- package/dist/slate-convert/md-to-slate/index.js +44 -0
- package/dist/slate-convert/md-to-slate/transform.js +326 -0
- package/dist/slate-convert/slate-to-md/index.js +43 -0
- package/dist/slate-convert/slate-to-md/transform.js +269 -0
- package/dist/utils/common.js +26 -0
- package/dist/utils/deserialize-html.js +260 -0
- package/dist/utils/dom-utils.js +51 -0
- package/dist/utils/event-bus.js +54 -0
- package/dist/utils/event-handler.js +40 -0
- package/dist/utils/object-utils.js +73 -0
- package/package.json +7 -2
- package/.babelrc +0 -5
- package/.eslintignore +0 -19
- package/.eslintrc.json +0 -52
- package/.github/workflows/nodejs.yml +0 -25
- package/.vscode/settings.json +0 -5
- package/config/config.common.js +0 -157
- package/config/config.dev.js +0 -53
- package/config/jest/cssTransform.js +0 -16
- package/config/jest/fileTransform.js +0 -40
- package/config/utils/theme.css.js +0 -103
- package/config.js +0 -61
- package/dev-server.js +0 -145
- package/jest.config.js +0 -16
- package/scripts/ejs.js +0 -16
- package/site/_i18n/index.js +0 -35
- package/site/api/index.js +0 -212
- package/site/app.js +0 -21
- package/site/assets/css/app.css +0 -47
- package/site/assets/css/seafile-editor.css +0 -33
- package/site/commons/loading/index.js +0 -14
- package/site/commons/switch/index.css +0 -14
- package/site/commons/switch/index.js +0 -37
- package/site/commons/toast/alert.js +0 -106
- package/site/commons/toast/index.js +0 -5
- package/site/commons/toast/toast.js +0 -195
- package/site/commons/toast/toastManager.js +0 -138
- package/site/commons/toast/toaster.js +0 -64
- package/site/index.html +0 -23
- package/site/index.js +0 -21
- package/site/pages/home.js +0 -21
- package/site/pages/plain-markdown-view.js +0 -6
- package/site/pages/rich-seafile-editor.js +0 -72
- package/site/pages/seafile-editor.js +0 -39
- package/site/pages/seafile-viewer.js +0 -45
- package/site/pages/simple-editor.js +0 -44
- package/site/pages/wiki-viewer.js +0 -7
- package/site/setting.js +0 -36
- package/site/setting.local.dist.js +0 -23
- package/src/constants/event-types.js +0 -11
- package/src/constants/hot-keys.js +0 -47
- package/src/containers/article-info/index.js +0 -49
- package/src/containers/custom/get-event-transfer.js +0 -28
- package/src/containers/custom/set-event-transfer.js +0 -32
- package/src/containers/hotkeys-helper/classify-hotkeys.js +0 -30
- package/src/containers/hotkeys-helper/index.js +0 -43
- package/src/containers/loading/index.js +0 -14
- package/src/containers/loading/style.css +0 -49
- package/src/containers/outline/index.js +0 -75
- package/src/containers/outline/outline-item.js +0 -28
- package/src/editors/plain-markdown-editor/code-mirror.js +0 -73
- package/src/editors/plain-markdown-editor/index.js +0 -136
- package/src/editors/simple-slate-editor /index.js +0 -71
- package/src/editors/simple-slate-editor /with-props-editor.js +0 -15
- package/src/editors/slate-editor/editor-help/index.js +0 -46
- package/src/editors/slate-editor/index.js +0 -77
- package/src/editors/slate-editor/with-props-editor.js +0 -15
- package/src/editors/slate-viewer/index.js +0 -35
- package/src/extension/commons/element-popover/index.js +0 -52
- package/src/extension/commons/index.js +0 -10
- package/src/extension/commons/menu/index.js +0 -9
- package/src/extension/commons/menu/menu-drop-down.js +0 -110
- package/src/extension/commons/menu/menu-group.js +0 -20
- package/src/extension/commons/menu/menu-item.js +0 -60
- package/src/extension/commons/tooltip/index.js +0 -26
- package/src/extension/constants/element-types.js +0 -23
- package/src/extension/constants/index.js +0 -37
- package/src/extension/constants/keyboard.js +0 -29
- package/src/extension/constants/menus-config.js +0 -149
- package/src/extension/core/index.js +0 -3
- package/src/extension/core/queries/index.js +0 -410
- package/src/extension/core/transforms/focus-editor.js +0 -12
- package/src/extension/core/transforms/index.js +0 -4
- package/src/extension/core/transforms/move-children.js +0 -23
- package/src/extension/core/transforms/remove-node-children.js +0 -8
- package/src/extension/core/transforms/replace-node-children.js +0 -14
- package/src/extension/core/utils/index.js +0 -76
- package/src/extension/editor.js +0 -14
- package/src/extension/index.js +0 -15
- package/src/extension/plugins/blockquote/helpers.js +0 -65
- package/src/extension/plugins/blockquote/index.js +0 -13
- package/src/extension/plugins/blockquote/menu/index.js +0 -31
- package/src/extension/plugins/blockquote/plugin.js +0 -64
- package/src/extension/plugins/blockquote/render-elem.js +0 -9
- package/src/extension/plugins/check-list/helper.js +0 -34
- package/src/extension/plugins/check-list/index.js +0 -14
- package/src/extension/plugins/check-list/menu/index.js +0 -44
- package/src/extension/plugins/check-list/plugin.js +0 -46
- package/src/extension/plugins/check-list/render-elem.js +0 -23
- package/src/extension/plugins/clear-format/helpers.js +0 -48
- package/src/extension/plugins/clear-format/menu/index.js +0 -39
- package/src/extension/plugins/code-block/helpers.js +0 -107
- package/src/extension/plugins/code-block/index.js +0 -14
- package/src/extension/plugins/code-block/menu/index.js +0 -40
- package/src/extension/plugins/code-block/plugin.js +0 -210
- package/src/extension/plugins/code-block/render-elem/constant.js +0 -17
- package/src/extension/plugins/code-block/render-elem/index.js +0 -55
- package/src/extension/plugins/code-block/render-elem/language-selector.js +0 -38
- package/src/extension/plugins/formula/helper.js +0 -68
- package/src/extension/plugins/formula/index.js +0 -14
- package/src/extension/plugins/formula/menu/formula-modal.js +0 -73
- package/src/extension/plugins/formula/menu/index.js +0 -63
- package/src/extension/plugins/formula/plugin.js +0 -18
- package/src/extension/plugins/formula/render-elem.js +0 -40
- package/src/extension/plugins/header/helper.js +0 -47
- package/src/extension/plugins/header/index.js +0 -14
- package/src/extension/plugins/header/menu/index.js +0 -114
- package/src/extension/plugins/header/plugin.js +0 -134
- package/src/extension/plugins/header/render-elem.js +0 -31
- package/src/extension/plugins/image/helper.js +0 -50
- package/src/extension/plugins/image/index.js +0 -14
- package/src/extension/plugins/image/menu/image-menu-dialog.js +0 -68
- package/src/extension/plugins/image/menu/image-menu-popover.js +0 -76
- package/src/extension/plugins/image/menu/index.js +0 -61
- package/src/extension/plugins/image/plugin.js +0 -23
- package/src/extension/plugins/image/render-element/image-previewer.js +0 -71
- package/src/extension/plugins/image/render-element/index.js +0 -94
- package/src/extension/plugins/index.js +0 -47
- package/src/extension/plugins/link/helper.js +0 -161
- package/src/extension/plugins/link/index.js +0 -14
- package/src/extension/plugins/link/menu/index.js +0 -82
- package/src/extension/plugins/link/menu/link-modal.js +0 -135
- package/src/extension/plugins/link/plugin.js +0 -85
- package/src/extension/plugins/link/render-elem/index.js +0 -69
- package/src/extension/plugins/link/render-elem/link-popover.js +0 -79
- package/src/extension/plugins/list/constant.js +0 -3
- package/src/extension/plugins/list/helpers.js +0 -53
- package/src/extension/plugins/list/index.js +0 -14
- package/src/extension/plugins/list/menu/index.js +0 -48
- package/src/extension/plugins/list/plugin/index.js +0 -48
- package/src/extension/plugins/list/plugin/insert-break-list.js +0 -25
- package/src/extension/plugins/list/plugin/insert-fragment-list.js +0 -162
- package/src/extension/plugins/list/plugin/normalize-list.js +0 -64
- package/src/extension/plugins/list/plugin/on-tab-handle.js +0 -34
- package/src/extension/plugins/list/queries/index.js +0 -39
- package/src/extension/plugins/list/render-elem/index.js +0 -26
- package/src/extension/plugins/list/transforms/index.js +0 -23
- package/src/extension/plugins/list/transforms/insert-list-item.js +0 -65
- package/src/extension/plugins/list/transforms/move-list-item-down.js +0 -40
- package/src/extension/plugins/list/transforms/move-list-item-up.js +0 -105
- package/src/extension/plugins/list/transforms/move-list-items-to-list.js +0 -58
- package/src/extension/plugins/list/transforms/move-list-items.js +0 -76
- package/src/extension/plugins/list/transforms/normalize-list-item.js +0 -92
- package/src/extension/plugins/list/transforms/normalize-nested-list.js +0 -31
- package/src/extension/plugins/list/transforms/remove-first-list-item.js +0 -11
- package/src/extension/plugins/list/transforms/transforms-to-list.js +0 -91
- package/src/extension/plugins/list/transforms/unwrap-list.js +0 -44
- package/src/extension/plugins/node-id/constants.js +0 -18
- package/src/extension/plugins/node-id/helpers.js +0 -61
- package/src/extension/plugins/node-id/index.js +0 -7
- package/src/extension/plugins/node-id/with-node-id.js +0 -37
- package/src/extension/plugins/paragraph/helper.js +0 -9
- package/src/extension/plugins/paragraph/index.js +0 -12
- package/src/extension/plugins/paragraph/plugin.js +0 -40
- package/src/extension/plugins/paragraph/render-elem.js +0 -11
- package/src/extension/plugins/table/constant.js +0 -3
- package/src/extension/plugins/table/helper.js +0 -175
- package/src/extension/plugins/table/index.js +0 -15
- package/src/extension/plugins/table/menu/index.js +0 -69
- package/src/extension/plugins/table/menu/table-operator.js +0 -101
- package/src/extension/plugins/table/menu/table-size-selector.js +0 -71
- package/src/extension/plugins/table/model.js +0 -69
- package/src/extension/plugins/table/plugin.js +0 -159
- package/src/extension/plugins/table/render-elem/context-menu.js +0 -78
- package/src/extension/plugins/table/render-elem/index.js +0 -157
- package/src/extension/plugins/table/table-operations.js +0 -162
- package/src/extension/plugins/text-style/helpers.js +0 -38
- package/src/extension/plugins/text-style/index.js +0 -12
- package/src/extension/plugins/text-style/menu/index.js +0 -41
- package/src/extension/plugins/text-style/plugin.js +0 -37
- package/src/extension/plugins/text-style/render-elem.js +0 -45
- package/src/extension/render/render-element.js +0 -82
- package/src/extension/render/render-leaf.js +0 -16
- package/src/extension/toolbar/header-toolbar/index.js +0 -129
- package/src/extension/toolbar/index.js +0 -5
- package/src/extension/toolbar/user-help/shortcut-dialog.js +0 -144
- package/src/hooks/use-mathjax.js +0 -44
- package/src/hooks/use-scroll-context.js +0 -14
- package/src/hooks/use-selection-update.js +0 -14
- package/src/index.js +0 -22
- package/src/pages/markdown-editor.js +0 -53
- package/src/pages/markdown-view.js +0 -36
- package/src/pages/rich-markdown-editor.js +0 -95
- package/src/pages/simple-editor.js +0 -52
- package/src/slate-convert/html-to-slate/constants.js +0 -54
- package/src/slate-convert/html-to-slate/helper.js +0 -22
- package/src/slate-convert/html-to-slate/index.js +0 -144
- package/src/slate-convert/html-to-slate/rules/blockquote.js +0 -16
- package/src/slate-convert/html-to-slate/rules/check-list.js +0 -22
- package/src/slate-convert/html-to-slate/rules/code-block.js +0 -91
- package/src/slate-convert/html-to-slate/rules/header.js +0 -18
- package/src/slate-convert/html-to-slate/rules/image.js +0 -18
- package/src/slate-convert/html-to-slate/rules/index.js +0 -23
- package/src/slate-convert/html-to-slate/rules/link.js +0 -24
- package/src/slate-convert/html-to-slate/rules/list.js +0 -52
- package/src/slate-convert/html-to-slate/rules/paragraph.js +0 -16
- package/src/slate-convert/html-to-slate/rules/table.js +0 -37
- package/src/slate-convert/html-to-slate/rules/text.js +0 -63
- package/src/slate-convert/index.js +0 -11
- package/src/slate-convert/md-to-html/index.js +0 -44
- package/src/slate-convert/md-to-html/sanitize-schema.js +0 -41
- package/src/slate-convert/md-to-slate/index.js +0 -42
- package/src/slate-convert/md-to-slate/transform.js +0 -336
- package/src/slate-convert/slate-to-md/index.js +0 -44
- package/src/slate-convert/slate-to-md/transform.js +0 -248
- package/src/utils/common.js +0 -30
- package/src/utils/deserialize-html.js +0 -174
- package/src/utils/dom-utils.js +0 -45
- package/src/utils/event-bus.js +0 -37
- package/src/utils/event-handler.js +0 -36
- package/src/utils/object-utils.js +0 -51
- package/tests/core/constants/index.js +0 -54
- package/tests/core/index.js +0 -11
- package/tests/core/jsx/index.js +0 -9
- package/tests/core/stub-editor/index.js +0 -26
- package/tests/core/utils.js +0 -58
- package/tests/extension/plugins/list/insert-block.test.js +0 -40
- package/tests/extension/plugins/list/insert-fragment-list.test.js +0 -392
- package/tests/extension/plugins/list/toggle-list.test.js +0 -160
- package/tests/extension/plugins/text/text.test.js +0 -29
- package/tests/extension/plugins/text-style/toggle-text-style.test.js +0 -148
- package/tests/slate-convert/html-to-slate/blockquote.test.js +0 -107
- package/tests/slate-convert/html-to-slate/code-block.test.js +0 -32
- package/tests/slate-convert/html-to-slate/header.test.js +0 -56
- package/tests/slate-convert/html-to-slate/link.test.js +0 -77
- package/tests/slate-convert/html-to-slate/list.test.js +0 -190
- package/tests/slate-convert/html-to-slate/paragraph.test.js +0 -40
- package/tests/slate-convert/html-to-slate/text.test.js +0 -131
- package/tests/slate-convert/md-to-html/blockquote.test.js +0 -110
- package/tests/slate-convert/md-to-html/check-list.test.js +0 -19
- package/tests/slate-convert/md-to-html/code-block.test.js +0 -19
- package/tests/slate-convert/md-to-html/header.test.js +0 -20
- package/tests/slate-convert/md-to-html/image.test.js +0 -17
- package/tests/slate-convert/md-to-html/image_reference.test.js +0 -17
- package/tests/slate-convert/md-to-html/link.test.js +0 -15
- package/tests/slate-convert/md-to-html/link_reference.test.js +0 -15
- package/tests/slate-convert/md-to-html/list-ordered.test.js +0 -22
- package/tests/slate-convert/md-to-html/list-unordered.test.js +0 -22
- package/tests/slate-convert/md-to-html/paragraph.test.js +0 -15
- package/tests/slate-convert/md-to-html/table.test.js +0 -29
- package/tests/slate-convert/md-to-html/text_base.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_bold.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_bold_italic.test.js +0 -15
- package/tests/slate-convert/md-to-html/text_code.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_code_bold.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_code_bold_italic.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_code_italic.test.js +0 -14
- package/tests/slate-convert/md-to-html/text_italic.test.js +0 -14
- package/tests/slate-convert/md-to-slate/blockquote.test.js +0 -200
- package/tests/slate-convert/md-to-slate/check-list.test.js +0 -34
- package/tests/slate-convert/md-to-slate/code-block.test.js +0 -32
- package/tests/slate-convert/md-to-slate/header.test.js +0 -49
- package/tests/slate-convert/md-to-slate/image.test.js +0 -31
- package/tests/slate-convert/md-to-slate/link.test.js +0 -30
- package/tests/slate-convert/md-to-slate/list-ordered.test.js +0 -42
- package/tests/slate-convert/md-to-slate/list-unordered.test.js +0 -42
- package/tests/slate-convert/md-to-slate/paragraph.test.js +0 -19
- package/tests/slate-convert/md-to-slate/table.test.js +0 -34
- package/tests/slate-convert/md-to-slate/text_base.test.js +0 -19
- package/tests/slate-convert/md-to-slate/text_bold.test.js +0 -22
- package/tests/slate-convert/md-to-slate/text_bold_italic.test.js +0 -23
- package/tests/slate-convert/md-to-slate/text_code.test.js +0 -22
- package/tests/slate-convert/md-to-slate/text_code_bold.test.js +0 -23
- package/tests/slate-convert/md-to-slate/text_code_bold_italic.test.js +0 -24
- package/tests/slate-convert/md-to-slate/text_code_italic.test.js +0 -23
- package/tests/slate-convert/md-to-slate/text_italic.test.js +0 -22
- package/tests/slate-convert/slate-to-md/blockquote.test.js +0 -416
- package/tests/slate-convert/slate-to-md/check-list.test.js +0 -96
- package/tests/slate-convert/slate-to-md/code-block.test.js +0 -35
- package/tests/slate-convert/slate-to-md/formula.test.js +0 -26
- package/tests/slate-convert/slate-to-md/header.test.js +0 -109
- package/tests/slate-convert/slate-to-md/image.test.js +0 -98
- package/tests/slate-convert/slate-to-md/link.test.js +0 -52
- package/tests/slate-convert/slate-to-md/list-ordered.test.js +0 -87
- package/tests/slate-convert/slate-to-md/list-unordered.test.js +0 -81
- package/tests/slate-convert/slate-to-md/paragraph.test.js +0 -28
- package/tests/slate-convert/slate-to-md/table.test.js +0 -56
- package/tests/slate-convert/slate-to-md/text_base.test.js +0 -28
- package/tests/slate-convert/slate-to-md/text_bold.test.js +0 -36
- package/tests/slate-convert/slate-to-md/text_bold_italic.test.js +0 -42
- package/tests/slate-convert/slate-to-md/text_code.test.js +0 -31
- package/tests/slate-convert/slate-to-md/text_code_bold.test.js +0 -37
- package/tests/slate-convert/slate-to-md/text_code_bold_italic.test.js +0 -43
- package/tests/slate-convert/slate-to-md/text_code_italic.test.js +0 -37
- package/tests/slate-convert/slate-to-md/text_italic.test.js +0 -36
- /package/{src → dist}/assets/css/slate-editor.css +0 -0
- /package/{src → dist}/containers/article-info/style.css +0 -0
- /package/{src → dist}/containers/hotkeys-helper/style.css +0 -0
- /package/{site/commons → dist/containers}/loading/style.css +0 -0
- /package/{src → dist}/containers/outline/style.css +0 -0
- /package/{src → dist}/editors/plain-markdown-editor/code-mirror.css +0 -0
- /package/{src → dist}/editors/plain-markdown-editor/style.css +0 -0
- /package/{src → dist}/editors/slate-editor/editor-help/style.css +0 -0
- /package/{src → dist}/editors/slate-viewer/style.css +0 -0
- /package/{src → dist}/extension/commons/menu/menu.css +0 -0
- /package/{src → dist}/extension/commons/tooltip/index.css +0 -0
- /package/{src → dist}/extension/plugins/code-block/render-elem/style.css +0 -0
- /package/{src → dist}/extension/plugins/formula/formula.css +0 -0
- /package/{src → dist}/extension/plugins/header/menu/style.css +0 -0
- /package/{src → dist}/extension/plugins/image/menu/style.css +0 -0
- /package/{src → dist}/extension/plugins/image/render-element/style.css +0 -0
- /package/{src → dist}/extension/plugins/link/render-elem/style.css +0 -0
- /package/{src → dist}/extension/plugins/list/render-elem/style.css +0 -0
- /package/{src → dist}/extension/plugins/table/menu/style.css +0 -0
- /package/{src → dist}/extension/plugins/table/render-elem/style.css +0 -0
- /package/{src → dist}/extension/toolbar/header-toolbar/style.css +0 -0
- /package/{src → dist}/extension/toolbar/user-help/style.css +0 -0
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
const generateDefaultText = () => {
|
|
2
|
-
return {
|
|
3
|
-
type: 'text',
|
|
4
|
-
value: '',
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const transformTextNode = (textNode) => {
|
|
9
|
-
let mdNode = { type: 'text', value: textNode.text };
|
|
10
|
-
|
|
11
|
-
// code = true, override text type
|
|
12
|
-
if (textNode['code']) {
|
|
13
|
-
mdNode = { ...mdNode, type: 'inlineCode' };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// blob = true, add strong parent
|
|
17
|
-
if (textNode['bold']) {
|
|
18
|
-
mdNode = { type: 'strong', children: [mdNode] };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// italic = true, add emphasis parent
|
|
22
|
-
if (textNode['italic']) {
|
|
23
|
-
mdNode = { type: 'emphasis', children: [mdNode] };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return mdNode;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const transformInlineChildren = (result, item) => {
|
|
30
|
-
// image
|
|
31
|
-
if (item.type && item.type === 'image') {
|
|
32
|
-
const { data } = item;
|
|
33
|
-
let image = {
|
|
34
|
-
type: 'image',
|
|
35
|
-
url: data.src,
|
|
36
|
-
alt: data.alt || null,
|
|
37
|
-
title: data.title || null,
|
|
38
|
-
};
|
|
39
|
-
if (data.height || data.width) {
|
|
40
|
-
image = {
|
|
41
|
-
type: 'html',
|
|
42
|
-
value: `<img src="${data.src}" alt="${data.alt}" title="${data.title}" width="${data.width}" height="${data.height}" />`
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
result.push(image);
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// link
|
|
50
|
-
if (item.type && item.type === 'link') {
|
|
51
|
-
const link = {
|
|
52
|
-
type: 'link',
|
|
53
|
-
url: item.url,
|
|
54
|
-
title: item.title || null,
|
|
55
|
-
children: [transformTextNode(item.children[0])],
|
|
56
|
-
};
|
|
57
|
-
result.push(link);
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// text
|
|
62
|
-
const nodes = transformTextNode(item);
|
|
63
|
-
result.push(nodes);
|
|
64
|
-
return result;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const transformNodeWithInlineChildren = (node) => {
|
|
68
|
-
const { children } = node;
|
|
69
|
-
const defaultChildren = [generateDefaultText()];
|
|
70
|
-
if (!children || !Array.isArray(children) || children.length === 0) {
|
|
71
|
-
return defaultChildren;
|
|
72
|
-
}
|
|
73
|
-
const result = [];
|
|
74
|
-
children.forEach(item => transformInlineChildren(result, item));
|
|
75
|
-
return result.flat();
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const transformHeader = (node) => {
|
|
79
|
-
const level = node.type.replace('header', '');
|
|
80
|
-
return {
|
|
81
|
-
type: 'heading',
|
|
82
|
-
depth: parseInt(level),
|
|
83
|
-
children: transformNodeWithInlineChildren(node)
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const transformParagraph = (node) => {
|
|
88
|
-
return {
|
|
89
|
-
type: 'paragraph',
|
|
90
|
-
children: transformNodeWithInlineChildren(node)
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const transformBlockquote = (node) => {
|
|
95
|
-
const { children } = node;
|
|
96
|
-
return {
|
|
97
|
-
type: 'blockquote',
|
|
98
|
-
children: children.map(child => {
|
|
99
|
-
const handler = elementHandlers[child.type];
|
|
100
|
-
return handler(child);
|
|
101
|
-
}).flat(), // flat
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const transformCheckList = (node) => {
|
|
106
|
-
return {
|
|
107
|
-
type: 'list',
|
|
108
|
-
ordered: false,
|
|
109
|
-
start: null,
|
|
110
|
-
spread: false,
|
|
111
|
-
children: [
|
|
112
|
-
{
|
|
113
|
-
type: 'listItem',
|
|
114
|
-
spread: false,
|
|
115
|
-
checked: node.checked,
|
|
116
|
-
children: [
|
|
117
|
-
transformParagraph(node),
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
],
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const transformListContent = (node) => {
|
|
125
|
-
return transformParagraph(node);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const transformListItem = (node) => {
|
|
129
|
-
let loose = false;
|
|
130
|
-
const { children } = node;
|
|
131
|
-
// eslint-disable-next-line array-callback-return
|
|
132
|
-
const newChildren = children.map(child => {
|
|
133
|
-
if (child.type === 'paragraph') {
|
|
134
|
-
return transformListContent(child);
|
|
135
|
-
}
|
|
136
|
-
if (child.type === 'unordered_list' || child.type === 'ordered_list') {
|
|
137
|
-
return transformList(child);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
if (newChildren.length === 1) {
|
|
141
|
-
loose = false;
|
|
142
|
-
} else if (newChildren.length === 2 && newChildren[1].type === 'list') {
|
|
143
|
-
loose = true;
|
|
144
|
-
} else {
|
|
145
|
-
loose = true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
type: 'listItem',
|
|
150
|
-
loose: loose,
|
|
151
|
-
checked: null,
|
|
152
|
-
children: newChildren
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const transformList = (node) => {
|
|
157
|
-
const { children } = node;
|
|
158
|
-
const newChildren = children.map(child => transformListItem(child));
|
|
159
|
-
let loose = false;
|
|
160
|
-
for (let node of newChildren) {
|
|
161
|
-
if (node.loose === true) {
|
|
162
|
-
loose = true;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
type: 'list',
|
|
168
|
-
ordered: node.type === 'ordered_list', // ordered_list | unordered_list
|
|
169
|
-
start: 1,
|
|
170
|
-
loose: loose,
|
|
171
|
-
children: newChildren,
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const transformTableCell = (cell) => {
|
|
176
|
-
return {
|
|
177
|
-
type: 'tableCell',
|
|
178
|
-
children: transformNodeWithInlineChildren(cell),
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const transformTableRow = (row) => {
|
|
183
|
-
const { children: cells } = row;
|
|
184
|
-
return {
|
|
185
|
-
type: 'tableRow',
|
|
186
|
-
children: cells.map(cell => transformTableCell(cell)),
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const transformTable = (node) => {
|
|
191
|
-
const { children: rows } = node;
|
|
192
|
-
const align = rows.map(row => {
|
|
193
|
-
const { children: cells } = row;
|
|
194
|
-
return cells[0]?.align || null;
|
|
195
|
-
});
|
|
196
|
-
return {
|
|
197
|
-
type: 'table',
|
|
198
|
-
align: align,
|
|
199
|
-
children: rows.map(row => transformTableRow(row)),
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const transformCodeLine = (node) => {
|
|
204
|
-
const text = node.children[0]?.text || '';
|
|
205
|
-
return text;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const transformCodeBlock = (node) => {
|
|
209
|
-
const { children } = node;
|
|
210
|
-
return {
|
|
211
|
-
type: 'code',
|
|
212
|
-
lang: node.lang ? node.lang : null,
|
|
213
|
-
value: children.map(child => transformCodeLine(child)).join('\n'),
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const transformFormula = (node) => {
|
|
218
|
-
const data = node.data;
|
|
219
|
-
return {
|
|
220
|
-
type: 'math',
|
|
221
|
-
value: data.formula,
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const elementHandlers = {
|
|
226
|
-
'paragraph': transformParagraph,
|
|
227
|
-
'header1': transformHeader,
|
|
228
|
-
'header2': transformHeader,
|
|
229
|
-
'header3': transformHeader,
|
|
230
|
-
'header4': transformHeader,
|
|
231
|
-
'header5': transformHeader,
|
|
232
|
-
'header6': transformHeader,
|
|
233
|
-
'blockquote': transformBlockquote,
|
|
234
|
-
'table': transformTable,
|
|
235
|
-
'check_list_item': transformCheckList,
|
|
236
|
-
'ordered_list': transformList,
|
|
237
|
-
'unordered_list': transformList,
|
|
238
|
-
'code_block': transformCodeBlock,
|
|
239
|
-
'formula': transformFormula,
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export const formatSlateToMd = (children) => {
|
|
243
|
-
const validChildren = children.filter(child => elementHandlers[child.type]);
|
|
244
|
-
return validChildren.map(child => {
|
|
245
|
-
const handler = elementHandlers[child.type];
|
|
246
|
-
return handler(child);
|
|
247
|
-
}).flat();
|
|
248
|
-
};
|
package/src/utils/common.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import checkIsUrl from 'is-url';
|
|
2
|
-
|
|
3
|
-
export const isMac = () => {
|
|
4
|
-
const platform = navigator.platform;
|
|
5
|
-
return (platform === 'Mac68K') || (platform === 'MacPPC') || (platform === 'Macintosh') || (platform === 'MacIntel');
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const IMAGE_TYPES = [
|
|
9
|
-
'png',
|
|
10
|
-
'jpg',
|
|
11
|
-
'gif',
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
export const isImage = (url) => {
|
|
15
|
-
if (!url) return false;
|
|
16
|
-
|
|
17
|
-
if (!isUrl(url)) return false;
|
|
18
|
-
|
|
19
|
-
const suffix = url.split('.')[1]; // http://xx/mm/*.png
|
|
20
|
-
if (!suffix) return false;
|
|
21
|
-
|
|
22
|
-
return IMAGE_TYPES.includes(suffix.toLowerCase());
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const isUrl = (url) => {
|
|
26
|
-
if (!url) return false;
|
|
27
|
-
if (!url.startsWith('http')) return false;
|
|
28
|
-
if (!checkIsUrl(url)) return false;
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'slate-hyperscript';
|
|
2
|
-
import {
|
|
3
|
-
BLOCKQUOTE,
|
|
4
|
-
HEADER1,
|
|
5
|
-
HEADER2,
|
|
6
|
-
HEADER3,
|
|
7
|
-
HEADER4,
|
|
8
|
-
HEADER5,
|
|
9
|
-
HEADER6,
|
|
10
|
-
IMAGE,
|
|
11
|
-
LINK,
|
|
12
|
-
LIST_ITEM,
|
|
13
|
-
ORDERED_LIST,
|
|
14
|
-
PARAGRAPH,
|
|
15
|
-
TABLE,
|
|
16
|
-
UNORDERED_LIST,
|
|
17
|
-
} from '../extension/constants/element-types';
|
|
18
|
-
import { generateTableCell, generateTableRow } from '../extension/plugins/table/model';
|
|
19
|
-
import { generateElement } from '../extension/core';
|
|
20
|
-
|
|
21
|
-
const ELEMENT_TAGS = {
|
|
22
|
-
A: el => ({ type: LINK, data: { href: el.getAttribute('href') } }),
|
|
23
|
-
BLOCKQUOTE: () => ({ type: BLOCKQUOTE }),
|
|
24
|
-
H1: () => ({ type: HEADER1 }),
|
|
25
|
-
H2: () => ({ type: HEADER2 }),
|
|
26
|
-
H3: () => ({ type: HEADER3 }),
|
|
27
|
-
H4: () => ({ type: HEADER4 }),
|
|
28
|
-
H5: () => ({ type: HEADER5 }),
|
|
29
|
-
H6: () => ({ type: HEADER6 }),
|
|
30
|
-
IMG: el => ({ type: IMAGE, children: [{ text: '' }], data: { src: el.getAttribute('src') } }),
|
|
31
|
-
LI: () => ({ type: LIST_ITEM, data: {} }),
|
|
32
|
-
OL: () => ({ type: ORDERED_LIST }),
|
|
33
|
-
P: () => ({ type: PARAGRAPH }),
|
|
34
|
-
UL: () => ({ type: UNORDERED_LIST }),
|
|
35
|
-
TABLE: () => ({ type: TABLE }),
|
|
36
|
-
BR: () => ({ text: '' })
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const HEADER_LIST = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
|
|
40
|
-
|
|
41
|
-
const TEXT_TAGS = {
|
|
42
|
-
CODE: () => ({ CODE: true }),
|
|
43
|
-
DEL: () => ({ DELETE: true }),
|
|
44
|
-
EM: () => ({ ITALIC: true }),
|
|
45
|
-
I: () => ({ ITALIC: true }),
|
|
46
|
-
STRONG: () => ({ BOLD: true }),
|
|
47
|
-
INS: () => ({ INS: true })
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const parseTable = (el) => {
|
|
51
|
-
|
|
52
|
-
if (el.parentNode.nodeName !== 'BODY') {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let tableWidth = 0;
|
|
57
|
-
Array.from(el.rows[0].childNodes).forEach((cell, index) => {
|
|
58
|
-
if (cell.nodeName === 'TD' || cell.nodeName === 'TH') {
|
|
59
|
-
tableWidth += (Number(cell.getAttribute('colspan')) || 1);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
let rowList = [];
|
|
64
|
-
for (let rowIndex = 0; rowIndex < el.rows.length; rowIndex++) {
|
|
65
|
-
let cells = el.rows[rowIndex].cells;
|
|
66
|
-
const cellsList = [];
|
|
67
|
-
for (let columnIndex = 0; columnIndex < cells.length; columnIndex++) {
|
|
68
|
-
const cell = cells[columnIndex];
|
|
69
|
-
cellsList.push(generateTableCell({ childrenOrText: [generateElement(PARAGRAPH, { childrenOrText: cell.textContent })] }));
|
|
70
|
-
}
|
|
71
|
-
if (cellsList.length < tableWidth) {
|
|
72
|
-
let count = tableWidth - cellsList.length;
|
|
73
|
-
for (let i = 0; i < count; i++) {
|
|
74
|
-
cellsList.push(generateTableCell({ childrenOrText: [generateElement(PARAGRAPH)] }));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
rowList.push(generateTableRow({ childrenOrText: cellsList }));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return rowList;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const deserializeHtml = el => {
|
|
84
|
-
if (el.nodeType === 3) {
|
|
85
|
-
// remove \n character
|
|
86
|
-
if (el.textContent === '\n' || el.textContent === '\r') {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
if (el.parentElement.nodeName === 'BODY') {
|
|
90
|
-
let text = el.textContent.replace(/(\n|\r\n)/g, '');
|
|
91
|
-
if (text.length === 0) return null;
|
|
92
|
-
return { type: PARAGRAPH, children: [{ text }] };
|
|
93
|
-
}
|
|
94
|
-
return el.textContent;
|
|
95
|
-
} else if (el.nodeType !== 1) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const { nodeName } = el;
|
|
100
|
-
let parent = el;
|
|
101
|
-
|
|
102
|
-
let children = Array.from(parent.childNodes)
|
|
103
|
-
.map(deserializeHtml)
|
|
104
|
-
.flat();
|
|
105
|
-
|
|
106
|
-
// deserialize task list
|
|
107
|
-
if (nodeName === 'LI') {
|
|
108
|
-
if (el.className && el.className.indexOf('task-list-item') >= 0) {
|
|
109
|
-
return jsx('element', { data: { checked: false }, type: 'list_item' }, children);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
nodeName === 'PRE' &&
|
|
115
|
-
el.childNodes[0] &&
|
|
116
|
-
el.childNodes[0].nodeName === 'CODE'
|
|
117
|
-
) {
|
|
118
|
-
// deserialize code block
|
|
119
|
-
const code = el.childNodes[0];
|
|
120
|
-
const codeChildren = [];
|
|
121
|
-
code.childNodes.forEach((codeLine, index) => {
|
|
122
|
-
if (codeLine.innerText) {
|
|
123
|
-
codeChildren.push({
|
|
124
|
-
type: 'code_line',
|
|
125
|
-
children: [{ text: codeLine.innerText }]
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
data: { syntax: null },
|
|
132
|
-
children: codeChildren,
|
|
133
|
-
type: 'code_block'
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (el.nodeName === 'BODY') {
|
|
138
|
-
return jsx('fragment', {}, children);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (ELEMENT_TAGS[nodeName]) {
|
|
142
|
-
const attrs = ELEMENT_TAGS[nodeName](el);
|
|
143
|
-
if (nodeName === 'IMG') {
|
|
144
|
-
return jsx('element', attrs, [{ text: '' }]);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// modify BR into an empty text node
|
|
148
|
-
if (nodeName === 'BR') {
|
|
149
|
-
return '';
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (nodeName === 'TABLE') {
|
|
153
|
-
return jsx('element', attrs, parseTable(el));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (nodeName === 'A' || HEADER_LIST.includes(nodeName)) {
|
|
157
|
-
return jsx('element', attrs, [{ text: el.textContent }]);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return jsx('element', attrs, children);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (TEXT_TAGS[nodeName]) {
|
|
164
|
-
const attrs = TEXT_TAGS[nodeName](el);
|
|
165
|
-
return children.map(child => jsx('text', attrs, child));
|
|
166
|
-
}
|
|
167
|
-
return children;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
export const htmlDeserializer = (html) => {
|
|
172
|
-
const parsed = new DOMParser().parseFromString(html, 'text/html');
|
|
173
|
-
return deserializeHtml(parsed.body);
|
|
174
|
-
};
|
package/src/utils/dom-utils.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export const getDomHeight = (dom) => {
|
|
2
|
-
const styles = window.getComputedStyle(dom);
|
|
3
|
-
const rect = dom.getBoundingClientRect();
|
|
4
|
-
const marginTop = styles['marginTop'];
|
|
5
|
-
// margin-bottom overlaps margin-top
|
|
6
|
-
// const marginBottom = styles['marginBottom'];
|
|
7
|
-
const { height } = rect;
|
|
8
|
-
|
|
9
|
-
return height + parseInt(marginTop);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getDomMarginTop = (dom) => {
|
|
13
|
-
const styles = window.getComputedStyle(dom);
|
|
14
|
-
const marginTop = styles['marginTop'];
|
|
15
|
-
return parseInt(marginTop);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getSelectionRange = () => {
|
|
19
|
-
if (window.getSelection) {
|
|
20
|
-
const sel = window.getSelection();
|
|
21
|
-
if (sel.getRangeAt && sel.rangeCount) {
|
|
22
|
-
return sel.getRangeAt(0);
|
|
23
|
-
}
|
|
24
|
-
} else if (document.selection && document.selection.createRange) {
|
|
25
|
-
return document.selection.createRange();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const getCursorPosition = (isScrollUp = true) => {
|
|
32
|
-
let x = 0, y = 0;
|
|
33
|
-
let range = getSelectionRange();
|
|
34
|
-
if (range) {
|
|
35
|
-
const rect = range.getBoundingClientRect();
|
|
36
|
-
const headerHeight = 100;
|
|
37
|
-
x = rect.x || 0;
|
|
38
|
-
if (isScrollUp) {
|
|
39
|
-
y = rect.y - headerHeight;
|
|
40
|
-
} else {
|
|
41
|
-
y = rect.y - headerHeight + rect.height;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return { x: x, y: y };
|
|
45
|
-
};
|
package/src/utils/event-bus.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
class EventBus {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.instance = null;
|
|
4
|
-
this.subscribers = {};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
static getInstance() {
|
|
8
|
-
if (this.instance) return this.instance;
|
|
9
|
-
this.instance = new EventBus();
|
|
10
|
-
return this.instance;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
subscribe(type, handler) {
|
|
14
|
-
if (!this.subscribers[type]) {
|
|
15
|
-
this.subscribers[type] = [];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const handlers = this.subscribers[type];
|
|
19
|
-
handlers.push(handler);
|
|
20
|
-
|
|
21
|
-
return () => {
|
|
22
|
-
const index = handlers.indexOf(handler);
|
|
23
|
-
if (index > -1) {
|
|
24
|
-
handlers.splice(index, 1);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
dispatch(type, ...data) {
|
|
30
|
-
const handlers = this.subscribers[type];
|
|
31
|
-
if (Array.isArray(handlers)) {
|
|
32
|
-
handlers.forEach(handler => handler(...data));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default EventBus;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import isHotkey from 'is-hotkey';
|
|
2
|
-
|
|
3
|
-
class EventProxy {
|
|
4
|
-
|
|
5
|
-
constructor(editor) {
|
|
6
|
-
this.editor = editor;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
onKeyDown = (event) => {
|
|
10
|
-
const editor = this.editor;
|
|
11
|
-
if (editor.onHotKeyDown) {
|
|
12
|
-
const isHandled = editor.onHotKeyDown(event);
|
|
13
|
-
if (isHandled) return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Disable the default 'save page'
|
|
17
|
-
if (isHotkey('mod+s', event)) {
|
|
18
|
-
event.preventDefault();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Disable default 'tab' behavior
|
|
22
|
-
if (isHotkey('tab', event)) {
|
|
23
|
-
event.preventDefault();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
onCopy = (event) => {
|
|
28
|
-
const editor = this.editor;
|
|
29
|
-
if (editor.onCopy) {
|
|
30
|
-
const isHandled = editor.onCopy(event);
|
|
31
|
-
if (isHandled) return;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default EventProxy;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
class ObjectUtils {
|
|
2
|
-
|
|
3
|
-
static getDataType(data){
|
|
4
|
-
let type = typeof data;
|
|
5
|
-
if (type !== 'object') {
|
|
6
|
-
return type;
|
|
7
|
-
}
|
|
8
|
-
return Object.prototype.toString.call(data).replace(/^\[object (\S+)\]$/, '$1');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static isObject = (data) => {
|
|
12
|
-
return this.getDataType(data) === 'Object';
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
static iterable(data){
|
|
16
|
-
return ['Object', 'Array'].includes(this.getDataType(data));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static isObjectChanged(source, comparison, notIncludeKeys) {
|
|
20
|
-
if (!this.iterable(source)) {
|
|
21
|
-
throw new Error(`source should be a Object or Array , but got ${this.getDataType(source)}`);
|
|
22
|
-
}
|
|
23
|
-
if (this.getDataType(source) !== this.getDataType(comparison)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
const sourceKeys = Object.keys(source);
|
|
27
|
-
const comparisonKeys = Object.keys({ ...source, ...comparison }).filter(key => !notIncludeKeys.includes(key));
|
|
28
|
-
if (sourceKeys.length !== comparisonKeys.length) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return comparisonKeys.some(key => {
|
|
32
|
-
if (this.iterable(source[key])) {
|
|
33
|
-
return this.isObjectChanged(source[key], comparison[key], notIncludeKeys);
|
|
34
|
-
} else {
|
|
35
|
-
return source[key] !== comparison[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static isSameObject(source, comparison, notIncludeKeys = []) {
|
|
41
|
-
if (!source || !comparison) return false;
|
|
42
|
-
return !this.isObjectChanged(source, comparison, notIncludeKeys);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static hasProperty = (obj, prop) => {
|
|
46
|
-
if (!obj) return false;
|
|
47
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default ObjectUtils;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// extension plugin
|
|
2
|
-
export const BLOCKQUOTE = 'blockquote';
|
|
3
|
-
export const HEADER = 'header';
|
|
4
|
-
export const HEADER1 = 'header1';
|
|
5
|
-
export const HEADER2 = 'header2';
|
|
6
|
-
export const HEADER3 = 'header3';
|
|
7
|
-
export const HEADER4 = 'header4';
|
|
8
|
-
export const HEADER5 = 'header5';
|
|
9
|
-
export const HEADER6 = 'header6';
|
|
10
|
-
export const ORDERED_LIST = 'ordered_list';
|
|
11
|
-
export const UNORDERED_LIST = 'unordered_list';
|
|
12
|
-
export const LIST_ITEM = 'list_item';
|
|
13
|
-
export const LIST_LIC = 'list_lic'; // placeholder
|
|
14
|
-
export const CHECK_LIST_ITEM = 'check_list_item';
|
|
15
|
-
export const PARAGRAPH = 'paragraph';
|
|
16
|
-
export const CODE_BLOCK = 'code_block';
|
|
17
|
-
export const CODE_LINE = 'code_line';
|
|
18
|
-
export const TABLE = 'table';
|
|
19
|
-
export const TABLE_CELL = 'table_cell';
|
|
20
|
-
export const TABLE_ROW = 'table_row';
|
|
21
|
-
export const TABLE_TH = 'table_th';
|
|
22
|
-
export const TABLE_TD = 'table_td';
|
|
23
|
-
export const TABLE_TR = 'table_tr';
|
|
24
|
-
export const LINK = 'link';
|
|
25
|
-
export const IMAGE = 'image';
|
|
26
|
-
export const FORMULA = 'formula';
|
|
27
|
-
export const COLUMN = 'column';
|
|
28
|
-
|
|
29
|
-
export const voidChildren = [{ text: '' }];
|
|
30
|
-
|
|
31
|
-
export const ELEMENTS = {
|
|
32
|
-
ha: { type: LINK },
|
|
33
|
-
hblockquote: { type: BLOCKQUOTE },
|
|
34
|
-
hcodeblock: { type: CODE_BLOCK },
|
|
35
|
-
hcodeline: { type: CODE_LINE },
|
|
36
|
-
hdefault: { type: PARAGRAPH },
|
|
37
|
-
hh1: { type: HEADER1 },
|
|
38
|
-
hh2: { type: HEADER2 },
|
|
39
|
-
hh3: { type: HEADER3 },
|
|
40
|
-
hh4: { type: HEADER4 },
|
|
41
|
-
hh5: { type: HEADER5 },
|
|
42
|
-
hh6: { type: HEADER6 },
|
|
43
|
-
himg: { type: IMAGE, children: voidChildren },
|
|
44
|
-
hli: { type: LIST_ITEM },
|
|
45
|
-
hlic: { type: LIST_LIC },
|
|
46
|
-
hol: { type: ORDERED_LIST },
|
|
47
|
-
hp: { type: PARAGRAPH },
|
|
48
|
-
htable: { type: TABLE },
|
|
49
|
-
htd: { type: TABLE_TD },
|
|
50
|
-
hth: { type: TABLE_TH },
|
|
51
|
-
htodoli: { type: CHECK_LIST_ITEM },
|
|
52
|
-
htr: { type: TABLE_TR },
|
|
53
|
-
hul: { type: UNORDERED_LIST }
|
|
54
|
-
};
|
package/tests/core/index.js
DELETED
package/tests/core/jsx/index.js
DELETED