@seafile/comment-editor 0.0.1-alpha.9 → 0.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/README.md +2 -8
- package/dist/basic-sdk/constants/index.js +2 -91
- package/dist/basic-sdk/context.js +7 -212
- package/dist/basic-sdk/cursor/helper.js +2 -31
- package/dist/basic-sdk/decorates/index.js +1 -2
- package/dist/basic-sdk/editor/comment-editor.js +10 -22
- package/dist/basic-sdk/extension/commons/index.js +1 -22
- package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +0 -136
- package/dist/basic-sdk/extension/commons/menu/menu-item.js +1 -6
- package/dist/basic-sdk/extension/constants/element-type.js +2 -36
- package/dist/basic-sdk/extension/constants/index.js +4 -421
- package/dist/basic-sdk/extension/constants/menus-config.js +2 -402
- package/dist/basic-sdk/extension/core/queries/index.js +0 -3
- package/dist/basic-sdk/extension/core/transforms/index.js +0 -11
- package/dist/basic-sdk/extension/index.js +3 -24
- package/dist/basic-sdk/extension/plugins/blockquote/helpers.js +1 -28
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +2 -2
- package/dist/basic-sdk/extension/plugins/html/helper.js +0 -1
- package/dist/basic-sdk/extension/plugins/html/plugin.js +0 -24
- package/dist/basic-sdk/extension/plugins/html/rules/index.js +1 -4
- package/dist/basic-sdk/extension/plugins/image/helpers.js +4 -6
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +5 -3
- package/dist/basic-sdk/extension/plugins/image/plugin.js +0 -14
- package/dist/basic-sdk/extension/plugins/image/render-elem.js +7 -12
- package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +4 -2
- package/dist/basic-sdk/extension/plugins/index.js +1 -102
- package/dist/basic-sdk/extension/plugins/link/helpers.js +2 -16
- package/dist/basic-sdk/extension/plugins/link/plugin.js +5 -13
- package/dist/basic-sdk/extension/plugins/list/helpers.js +0 -4
- package/dist/basic-sdk/extension/plugins/list/plugin/normalize-list.js +1 -1
- package/dist/basic-sdk/extension/plugins/list/transforms/move-list-item-sublist-to-list-item-sublist.js +2 -9
- package/dist/basic-sdk/extension/plugins/list/transforms/normalize-list-item.js +1 -1
- package/dist/basic-sdk/extension/plugins/markdown/plugin.js +1 -6
- package/dist/basic-sdk/extension/plugins/paragraph/render-elem.js +1 -9
- package/dist/basic-sdk/extension/plugins/text-style/helpers.js +0 -8
- package/dist/basic-sdk/extension/plugins/text-style/menu/comemnt-editor-menu.js +1 -2
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +0 -75
- package/dist/basic-sdk/extension/render/render-comment-editor-element.js +0 -7
- package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +13 -9
- package/dist/basic-sdk/extension/utils/index.js +1 -51
- package/dist/basic-sdk/hooks/use-comment.js +23 -11
- package/dist/basic-sdk/index.js +1 -40
- package/dist/basic-sdk/model/index.js +1 -8
- package/dist/basic-sdk/slate-convert/html-to-slate/constants.js +3 -18
- package/dist/basic-sdk/slate-convert/html-to-slate/index.js +0 -1
- package/dist/basic-sdk/slate-convert/html-to-slate/rules/index.js +1 -4
- package/dist/basic-sdk/slate-convert/md-to-slate/transform.js +1 -90
- package/dist/basic-sdk/slate-convert/slate-to-md/transform.js +0 -89
- package/dist/basic-sdk/utils/common-utils.js +1 -39
- package/dist/basic-sdk/utils/document-utils.js +2 -31
- package/dist/basic-sdk/utils/event-handler.js +2 -18
- package/dist/basic-sdk/utils/mouse-event.js +2 -57
- package/dist/constants/index.js +2 -59
- package/dist/pages/seafile-comment-editor.js +31 -20
- package/package.json +6 -19
- package/public/index.html +0 -1
- package/dist/assets/css/simple-editor.css +0 -9
- package/dist/assets/images/content-replaced.png +0 -0
- package/dist/assets/images/revision-avatar.png +0 -0
- package/dist/assets/images/sdoc-freezed.png +0 -0
- package/dist/basic-sdk/android/constants.js +0 -10
- package/dist/basic-sdk/android/js-bridge.js +0 -74
- package/dist/basic-sdk/android/outline-module.js +0 -29
- package/dist/basic-sdk/api/sdoc-server-api.js +0 -189
- package/dist/basic-sdk/api/seafile-api.js +0 -220
- package/dist/basic-sdk/assets/css/diff-viewer.css +0 -5
- package/dist/basic-sdk/assets/images/sdoc-ask-ai.png +0 -0
- package/dist/basic-sdk/components/file-loading/index.css +0 -57
- package/dist/basic-sdk/components/file-loading/index.js +0 -15
- package/dist/basic-sdk/constants/plugin.js +0 -10
- package/dist/basic-sdk/constants/z-index.js +0 -8
- package/dist/basic-sdk/extension/commons/color-menu/color-item.js +0 -31
- package/dist/basic-sdk/extension/commons/color-menu/index.css +0 -161
- package/dist/basic-sdk/extension/commons/color-menu/index.js +0 -208
- package/dist/basic-sdk/extension/commons/file-insert-dialog/index.js +0 -282
- package/dist/basic-sdk/extension/commons/file-insert-dialog/style.css +0 -91
- package/dist/basic-sdk/extension/commons/more-dropdown/index.js +0 -44
- package/dist/basic-sdk/extension/commons/search-list/index.css +0 -28
- package/dist/basic-sdk/extension/commons/search-list/index.js +0 -149
- package/dist/basic-sdk/extension/commons/select/_option.js +0 -39
- package/dist/basic-sdk/extension/commons/select/field-setting.js +0 -109
- package/dist/basic-sdk/extension/commons/select/index.js +0 -142
- package/dist/basic-sdk/extension/commons/select/menu/index.js +0 -11
- package/dist/basic-sdk/extension/commons/select/menu/item.js +0 -39
- package/dist/basic-sdk/extension/commons/select/menu/menu.js +0 -34
- package/dist/basic-sdk/extension/commons/select/menu/style.css +0 -43
- package/dist/basic-sdk/extension/commons/select/style.css +0 -149
- package/dist/basic-sdk/extension/commons/select-file-dialog/helpers.js +0 -54
- package/dist/basic-sdk/extension/commons/select-file-dialog/index.css +0 -135
- package/dist/basic-sdk/extension/commons/select-file-dialog/index.js +0 -207
- package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.css +0 -114
- package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.js +0 -191
- package/dist/basic-sdk/extension/commons/wiki-file-insert-dialog/index.js +0 -274
- package/dist/basic-sdk/extension/commons/wiki-file-insert-dialog/style.css +0 -116
- package/dist/basic-sdk/extension/constants/color.js +0 -282
- package/dist/basic-sdk/extension/constants/diff-view.js +0 -20
- package/dist/basic-sdk/extension/constants/font.js +0 -537
- package/dist/basic-sdk/extension/constants/keyboard.js +0 -45
- package/dist/basic-sdk/extension/core/transforms/update-parent-node.js +0 -34
- package/dist/basic-sdk/extension/plugins/ai/ai-icon/index.js +0 -26
- package/dist/basic-sdk/extension/plugins/ai/ai-icon/style.css +0 -22
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/ai-context-menu.js +0 -41
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/ai-dropdown-menu.js +0 -35
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/index.js +0 -20
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/menu-item.js +0 -58
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/style.css +0 -12
- package/dist/basic-sdk/extension/plugins/ai/ai-module/adjust-sub-menu.js +0 -44
- package/dist/basic-sdk/extension/plugins/ai/ai-module/helpers.js +0 -72
- package/dist/basic-sdk/extension/plugins/ai/ai-module/index.js +0 -600
- package/dist/basic-sdk/extension/plugins/ai/ai-module/lang-sub-menu.js +0 -55
- package/dist/basic-sdk/extension/plugins/ai/ai-module/style.css +0 -148
- package/dist/basic-sdk/extension/plugins/ai/ai-module/tip-dialog.js +0 -41
- package/dist/basic-sdk/extension/plugins/ai/constants/index.js +0 -137
- package/dist/basic-sdk/extension/plugins/ai/index.js +0 -1
- package/dist/basic-sdk/extension/plugins/callout/constant.js +0 -58
- package/dist/basic-sdk/extension/plugins/callout/helper.js +0 -281
- package/dist/basic-sdk/extension/plugins/callout/index.js +0 -19
- package/dist/basic-sdk/extension/plugins/callout/menu/index.css +0 -16
- package/dist/basic-sdk/extension/plugins/callout/menu/index.js +0 -52
- package/dist/basic-sdk/extension/plugins/callout/plugin.js +0 -109
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-color-selector/index.js +0 -65
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-color-selector/style.css +0 -39
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-hover-menu/index.js +0 -90
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-hover-menu/style.css +0 -45
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-icon/index.js +0 -45
- package/dist/basic-sdk/extension/plugins/callout/render-elem/callout-icon/style.css +0 -33
- package/dist/basic-sdk/extension/plugins/callout/render-elem/index.css +0 -52
- package/dist/basic-sdk/extension/plugins/callout/render-elem/index.js +0 -134
- package/dist/basic-sdk/extension/plugins/check-list/helpers.js +0 -121
- package/dist/basic-sdk/extension/plugins/check-list/index.js +0 -16
- package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +0 -58
- package/dist/basic-sdk/extension/plugins/check-list/model.js +0 -17
- package/dist/basic-sdk/extension/plugins/check-list/plugin.js +0 -110
- package/dist/basic-sdk/extension/plugins/check-list/render-elem.js +0 -71
- package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +0 -54
- package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +0 -35
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +0 -206
- package/dist/basic-sdk/extension/plugins/code-block/hover-menu/index.css +0 -148
- package/dist/basic-sdk/extension/plugins/code-block/hover-menu/index.js +0 -257
- package/dist/basic-sdk/extension/plugins/code-block/index.js +0 -19
- package/dist/basic-sdk/extension/plugins/code-block/menu/index.js +0 -35
- package/dist/basic-sdk/extension/plugins/code-block/model.js +0 -16
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +0 -229
- package/dist/basic-sdk/extension/plugins/code-block/prismjs.js +0 -189
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +0 -182
- package/dist/basic-sdk/extension/plugins/file-link/constants/index.js +0 -26
- package/dist/basic-sdk/extension/plugins/file-link/helpers.js +0 -125
- package/dist/basic-sdk/extension/plugins/file-link/hover-menu/index.css +0 -89
- package/dist/basic-sdk/extension/plugins/file-link/hover-menu/index.js +0 -120
- package/dist/basic-sdk/extension/plugins/file-link/index.js +0 -18
- package/dist/basic-sdk/extension/plugins/file-link/menu/index.js +0 -38
- package/dist/basic-sdk/extension/plugins/file-link/plugin.js +0 -72
- package/dist/basic-sdk/extension/plugins/file-link/render-elem.css +0 -56
- package/dist/basic-sdk/extension/plugins/file-link/render-elem.js +0 -164
- package/dist/basic-sdk/extension/plugins/font/helpers.js +0 -173
- package/dist/basic-sdk/extension/plugins/font/index.js +0 -13
- package/dist/basic-sdk/extension/plugins/font/menu/font-family/font-item.js +0 -39
- package/dist/basic-sdk/extension/plugins/font/menu/font-family/index.css +0 -40
- package/dist/basic-sdk/extension/plugins/font/menu/font-family/index.js +0 -145
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/font-size-scale.js +0 -38
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/index.css +0 -40
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/index.js +0 -103
- package/dist/basic-sdk/extension/plugins/font/menu/index.js +0 -24
- package/dist/basic-sdk/extension/plugins/font/plugin.js +0 -18
- package/dist/basic-sdk/extension/plugins/group/index.js +0 -13
- package/dist/basic-sdk/extension/plugins/group/render-elem.js +0 -25
- package/dist/basic-sdk/extension/plugins/header/helpers.js +0 -69
- package/dist/basic-sdk/extension/plugins/header/index.js +0 -17
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +0 -153
- package/dist/basic-sdk/extension/plugins/header/menu/style.css +0 -79
- package/dist/basic-sdk/extension/plugins/header/plugin.js +0 -140
- package/dist/basic-sdk/extension/plugins/header/render-elem.js +0 -90
- package/dist/basic-sdk/extension/plugins/history/history-menu.js +0 -70
- package/dist/basic-sdk/extension/plugins/html/rules/check-list.js +0 -27
- package/dist/basic-sdk/extension/plugins/html/rules/code-block.js +0 -89
- package/dist/basic-sdk/extension/plugins/html/rules/header.js +0 -32
- package/dist/basic-sdk/extension/plugins/html/rules/table.js +0 -41
- package/dist/basic-sdk/extension/plugins/multi-column/constants/index.js +0 -7
- package/dist/basic-sdk/extension/plugins/multi-column/helper.js +0 -192
- package/dist/basic-sdk/extension/plugins/multi-column/index.js +0 -17
- package/dist/basic-sdk/extension/plugins/multi-column/plugin.js +0 -153
- package/dist/basic-sdk/extension/plugins/multi-column/render/index.css +0 -51
- package/dist/basic-sdk/extension/plugins/multi-column/render/index.js +0 -91
- package/dist/basic-sdk/extension/plugins/multi-column/render/multi-column-root.js +0 -23
- package/dist/basic-sdk/extension/plugins/multi-column/render/render-column.js +0 -46
- package/dist/basic-sdk/extension/plugins/multi-column/render-elem.js +0 -20
- package/dist/basic-sdk/extension/plugins/multi-column/resize-handlers/column-resize-handler.js +0 -28
- package/dist/basic-sdk/extension/plugins/multi-column/resize-handlers/index.js +0 -148
- package/dist/basic-sdk/extension/plugins/sdoc-link/constants/index.js +0 -26
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +0 -291
- package/dist/basic-sdk/extension/plugins/sdoc-link/hover-menu/index.css +0 -89
- package/dist/basic-sdk/extension/plugins/sdoc-link/hover-menu/index.js +0 -119
- package/dist/basic-sdk/extension/plugins/sdoc-link/index.js +0 -19
- package/dist/basic-sdk/extension/plugins/sdoc-link/menu/index.js +0 -38
- package/dist/basic-sdk/extension/plugins/sdoc-link/plugin.js +0 -102
- package/dist/basic-sdk/extension/plugins/sdoc-link/render/render-elem.css +0 -68
- package/dist/basic-sdk/extension/plugins/sdoc-link/render/render-elem.js +0 -180
- package/dist/basic-sdk/extension/plugins/sdoc-link/render/render-file-link-temp-input.js +0 -34
- package/dist/basic-sdk/extension/plugins/search-replace/constant.js +0 -8
- package/dist/basic-sdk/extension/plugins/search-replace/helper.js +0 -355
- package/dist/basic-sdk/extension/plugins/search-replace/index.js +0 -17
- package/dist/basic-sdk/extension/plugins/search-replace/menu/index.css +0 -14
- package/dist/basic-sdk/extension/plugins/search-replace/menu/index.js +0 -89
- package/dist/basic-sdk/extension/plugins/search-replace/plugin.js +0 -28
- package/dist/basic-sdk/extension/plugins/search-replace/popover/index.css +0 -98
- package/dist/basic-sdk/extension/plugins/search-replace/popover/index.js +0 -238
- package/dist/basic-sdk/extension/plugins/search-replace/popover/replace-all-confirm-modal.js +0 -50
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +0 -64
- package/dist/basic-sdk/extension/plugins/table/dialogs/custom-table-size-dialog/index.css +0 -7
- package/dist/basic-sdk/extension/plugins/table/dialogs/custom-table-size-dialog/index.js +0 -102
- package/dist/basic-sdk/extension/plugins/table/dialogs/custom-table-size-dialog/number-input.js +0 -31
- package/dist/basic-sdk/extension/plugins/table/dialogs/index.js +0 -20
- package/dist/basic-sdk/extension/plugins/table/dialogs/split-cell-setting-dialog.js +0 -115
- package/dist/basic-sdk/extension/plugins/table/helpers.js +0 -2124
- package/dist/basic-sdk/extension/plugins/table/index.js +0 -21
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +0 -83
- package/dist/basic-sdk/extension/plugins/table/menu/color-selector-popover/color-item.js +0 -31
- package/dist/basic-sdk/extension/plugins/table/menu/color-selector-popover/index.js +0 -173
- package/dist/basic-sdk/extension/plugins/table/menu/color-selector-popover/style.css +0 -7
- package/dist/basic-sdk/extension/plugins/table/menu/horizontal-align-popover/index.js +0 -79
- package/dist/basic-sdk/extension/plugins/table/menu/index.js +0 -20
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.css +0 -40
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/index.js +0 -232
- package/dist/basic-sdk/extension/plugins/table/menu/table-context-menu/insert-table-element.js +0 -97
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +0 -41
- package/dist/basic-sdk/extension/plugins/table/menu/vertical-align-popover/index.js +0 -81
- package/dist/basic-sdk/extension/plugins/table/menu/vertical-align-popover/style.css +0 -24
- package/dist/basic-sdk/extension/plugins/table/model.js +0 -54
- package/dist/basic-sdk/extension/plugins/table/plugin.js +0 -621
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.css +0 -69
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +0 -265
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/index.css +0 -43
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/index.js +0 -129
- package/dist/basic-sdk/extension/plugins/table/popover/table-template/sample-table.js +0 -44
- package/dist/basic-sdk/extension/plugins/table/render/alternate-color.css +0 -37
- package/dist/basic-sdk/extension/plugins/table/render/drag-handlers/column-drag-handler.js +0 -24
- package/dist/basic-sdk/extension/plugins/table/render/drag-handlers/index.js +0 -53
- package/dist/basic-sdk/extension/plugins/table/render/drag-handlers/row-drag-handler.js +0 -24
- package/dist/basic-sdk/extension/plugins/table/render/hooks.js +0 -76
- package/dist/basic-sdk/extension/plugins/table/render/index.css +0 -169
- package/dist/basic-sdk/extension/plugins/table/render/index.js +0 -271
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +0 -253
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +0 -15
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/column-resize-handler.js +0 -114
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/first-column-left-resize-handler.js +0 -100
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/index.js +0 -74
- package/dist/basic-sdk/extension/plugins/table/render/resize-handlers/row-resize-handler.js +0 -90
- package/dist/basic-sdk/extension/plugins/table/render/resize-mask/index.js +0 -136
- package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/column-header.js +0 -104
- package/dist/basic-sdk/extension/plugins/table/render/table-header/columns-header/index.js +0 -92
- package/dist/basic-sdk/extension/plugins/table/render/table-header/index.css +0 -84
- package/dist/basic-sdk/extension/plugins/table/render/table-header/index.js +0 -114
- package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-columns-header.js +0 -32
- package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/index.js +0 -90
- package/dist/basic-sdk/extension/plugins/table/render/table-header/rows-header/row-header.js +0 -126
- package/dist/basic-sdk/extension/plugins/table/render/table-root.js +0 -60
- package/dist/basic-sdk/extension/plugins/table/render-elem.js +0 -27
- package/dist/basic-sdk/extension/plugins/text-align/helpers.js +0 -51
- package/dist/basic-sdk/extension/plugins/text-align/index.js +0 -8
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.css +0 -5
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +0 -98
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +0 -162
- package/dist/basic-sdk/extension/plugins/video/constants/index.js +0 -10
- package/dist/basic-sdk/extension/plugins/video/dialog/add-video-link-dialog/index.js +0 -108
- package/dist/basic-sdk/extension/plugins/video/helpers.js +0 -241
- package/dist/basic-sdk/extension/plugins/video/index.css +0 -73
- package/dist/basic-sdk/extension/plugins/video/index.js +0 -20
- package/dist/basic-sdk/extension/plugins/video/menu/index.js +0 -76
- package/dist/basic-sdk/extension/plugins/video/plugin.js +0 -52
- package/dist/basic-sdk/extension/plugins/video/render-elem.js +0 -155
- package/dist/basic-sdk/extension/plugins/wiki-link/helpers.js +0 -77
- package/dist/basic-sdk/extension/plugins/wiki-link/index.js +0 -16
- package/dist/basic-sdk/extension/render/helper.js +0 -64
- package/dist/basic-sdk/highlight/index.js +0 -26
- package/dist/basic-sdk/highlight/setNodeToDecorations.js +0 -83
- package/dist/basic-sdk/hooks/use-color-context.js +0 -49
- package/dist/basic-sdk/hooks/use-force-update.js +0 -15
- package/dist/basic-sdk/hooks/use-selection-element.js +0 -26
- package/dist/basic-sdk/hooks/use-selection-position.js +0 -68
- package/dist/basic-sdk/model/notification.js +0 -18
- package/dist/basic-sdk/slate-convert/html-to-slate/rules/code-block.js +0 -90
- package/dist/basic-sdk/slate-convert/html-to-slate/rules/header.js +0 -24
- package/dist/basic-sdk/slate-convert/html-to-slate/rules/table.js +0 -45
- package/dist/basic-sdk/utils/Kebab-to-camel.js +0 -10
- package/dist/basic-sdk/utils/debounce.js +0 -20
- package/dist/basic-sdk/utils/debug.js +0 -20
- package/dist/basic-sdk/utils/default-mode.js +0 -28
- package/dist/basic-sdk/utils/diff-text.js +0 -297
- package/dist/basic-sdk/utils/diff.js +0 -328
- package/dist/basic-sdk/utils/dom-utils.js +0 -57
- package/dist/basic-sdk/utils/full-width-mode.js +0 -36
- package/dist/basic-sdk/utils/local-storage-utils.js +0 -52
- package/dist/basic-sdk/utils/rebase.js +0 -309
- package/dist/components/error-boundary/error-page.css +0 -16
- package/dist/components/error-boundary/error-page.js +0 -36
- package/dist/components/error-boundary/index.js +0 -33
- package/dist/components/modal-header/index.css +0 -18
- package/dist/components/modal-header/index.js +0 -29
- package/dist/components/modal-portal/index.js +0 -26
- package/dist/components/tip-dialog/index.css +0 -48
- package/dist/components/tip-dialog/index.js +0 -115
- package/dist/components/tip-message/index.js +0 -194
- package/dist/components/tip-message/style.css +0 -15
- package/dist/utils/date-utils.js +0 -78
- package/dist/utils/index.js +0 -45
- package/public/media/dtable-font.css +0 -1568
- package/public/media/dtable-fonts/dtable-font.eot +0 -0
- package/public/media/dtable-fonts/dtable-font.svg +0 -793
- package/public/media/dtable-fonts/dtable-font.ttf +0 -0
- package/public/media/dtable-fonts/dtable-font.woff +0 -0
- package/public/media/dtable-fonts/dtable-font.woff2 +0 -0
- package/public/media/seafile-logo.png +0 -0
- /package/dist/basic-sdk/{extension/plugins/header → components/placeholder}/placeholder.js +0 -0
|
@@ -1,2124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.updateTableRowHeight = exports.updateColumnWidth = exports.syncRemoveTable = exports.splitCell = exports.setTableSelectedRange = exports.setTableFragmentData = exports.setCellStyle = exports.removeTableElement = exports.removeTable = exports.normalizeTableELement = exports.moveRows = exports.moveColumns = exports.isTableWidthFitScreen = exports.isTableMenuDisabled = exports.isTableLocation = exports.isSelectedAllCell = exports.isPreventResetTableSelectedRange = exports.isLastTableCell = exports.isInTableSameCell = exports.isInTable = exports.isHideDragHandlerLine = exports.isCursorAtCellStart = exports.isCursorAtCellEnd = exports.isCombineCellsDisabled = exports.isAllInTable = exports.insertTableRow = exports.insertTableElement = exports.insertTableColumn = exports.insertTableByTemplate = exports.insertTable = exports.insertMultipleRowsAndColumns = exports.handleInsertTable = exports.handleCombinedCellsBeforeDeleteTableRow = exports.handleCombinedCellsBeforeDeleteTableColumn = exports.handleCombinedCellsAfterInsertTableRow = exports.handleCombinedCellsAfterInsertTableColumn = exports.getTableSelectedRangeAfterDrag = exports.getTableRowSelectedRange = exports.getTableDragType = exports.getTableColumnsWidth = exports.getTableColumnsAfterInsertColumn = exports.getTableColumns = exports.getTableColumnSelectedRange = exports.getSelectedInfo = exports.getRowHeight = exports.getRowDomHeight = exports.getResizeMaskCellInfo = exports.getInsertPosition = exports.getHighlightClass = exports.getFirstTableCell = exports.getCellInheritStyles = exports.getCellHighlightClassName = exports.getCellColumn = exports.generateTableRow = exports.generateTableCell = exports.generateInheritStyle = exports.generateEmptyTable = exports.generateDragMoveElement = exports.focusClosestCellWhenJustifyCellSize = exports.focusCell = exports.fitTableColumnToScreen = exports.elementHasImage = exports.deleteTableSelectCells = exports.deleteTableRangeData = exports.deleteHandler = exports.combineCells = exports.colorBlend = exports.adjustCombinedCellRange = void 0;
|
|
8
|
-
var _slate = require("@seafile/slate");
|
|
9
|
-
var _slateReact = require("@seafile/slate-react");
|
|
10
|
-
var _deepCopy = _interopRequireDefault(require("deep-copy"));
|
|
11
|
-
var _slugid = _interopRequireDefault(require("slugid"));
|
|
12
|
-
var _constants = require("../../../constants");
|
|
13
|
-
var _helpers = require("../../../node-id/helpers");
|
|
14
|
-
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
15
|
-
var _objectUtils = _interopRequireDefault(require("../../../utils/object-utils"));
|
|
16
|
-
var _constants2 = require("../../constants");
|
|
17
|
-
var _core = require("../../core");
|
|
18
|
-
var _constants3 = require("./constants");
|
|
19
|
-
const isTableMenuDisabled = (editor, readonly) => {
|
|
20
|
-
if (readonly) return true;
|
|
21
|
-
const {
|
|
22
|
-
selection
|
|
23
|
-
} = editor;
|
|
24
|
-
if (selection === null) return true;
|
|
25
|
-
if (!_slate.Range.isCollapsed(selection)) return true;
|
|
26
|
-
const [match] = _slate.Editor.nodes(editor, {
|
|
27
|
-
match: n => {
|
|
28
|
-
let type = (0, _core.getNodeType)(n);
|
|
29
|
-
if (!type && (0, _core.isTextNode)(n) && n.id) {
|
|
30
|
-
const parentNode = (0, _core.getParentNode)(editor.children, n.id);
|
|
31
|
-
type = (0, _core.getNodeType)(parentNode);
|
|
32
|
-
}
|
|
33
|
-
if (type.startsWith('header')) return true;
|
|
34
|
-
if (type === _constants2.ELEMENT_TYPE.TITLE) return true;
|
|
35
|
-
if (type === _constants2.ELEMENT_TYPE.SUBTITLE) return true;
|
|
36
|
-
if (type === _constants2.ELEMENT_TYPE.CODE_BLOCK) return true;
|
|
37
|
-
if (type === _constants2.ELEMENT_TYPE.ORDERED_LIST) return true;
|
|
38
|
-
if (type === _constants2.ELEMENT_TYPE.UNORDERED_LIST) return true;
|
|
39
|
-
if (type === _constants2.ELEMENT_TYPE.BLOCKQUOTE) return true;
|
|
40
|
-
if (type === _constants2.ELEMENT_TYPE.LIST_ITEM) return true;
|
|
41
|
-
if (type === _constants2.ELEMENT_TYPE.TABLE) return true;
|
|
42
|
-
if (type === _constants2.ELEMENT_TYPE.TABLE_CELL) return true;
|
|
43
|
-
if (type === _constants2.ELEMENT_TYPE.TABLE_ROW) return true;
|
|
44
|
-
if (type === _constants2.ELEMENT_TYPE.CALL_OUT) return true;
|
|
45
|
-
if (type === _constants2.ELEMENT_TYPE.MULTI_COLUMN) return true;
|
|
46
|
-
if (_slate.Editor.isVoid(editor, n)) return true;
|
|
47
|
-
return false;
|
|
48
|
-
},
|
|
49
|
-
universal: true
|
|
50
|
-
});
|
|
51
|
-
if (match) return true;
|
|
52
|
-
return false;
|
|
53
|
-
};
|
|
54
|
-
exports.isTableMenuDisabled = isTableMenuDisabled;
|
|
55
|
-
const isCombineCellsDisabled = (editor, readonly) => {
|
|
56
|
-
if (readonly) return true;
|
|
57
|
-
const {
|
|
58
|
-
selection,
|
|
59
|
-
tableSelectedRange
|
|
60
|
-
} = editor;
|
|
61
|
-
if (!selection) return true;
|
|
62
|
-
if (!_objectUtils.default.isSameObject(tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
|
-
exports.isCombineCellsDisabled = isCombineCellsDisabled;
|
|
68
|
-
const generateTableCell = (editor, rowIndex, cellIndex) => {
|
|
69
|
-
let style = {};
|
|
70
|
-
const tableNodeEntry = (0, _core.getSelectedNodeEntryByType)(editor, _constants2.ELEMENT_TYPE.TABLE);
|
|
71
|
-
if (tableNodeEntry && rowIndex !== undefined && cellIndex !== undefined) {
|
|
72
|
-
const [, tablePath] = tableNodeEntry;
|
|
73
|
-
style = getCellInheritStyles(editor, tablePath, rowIndex, cellIndex);
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
id: _slugid.default.nice(),
|
|
77
|
-
type: _constants2.ELEMENT_TYPE.TABLE_CELL,
|
|
78
|
-
children: [{
|
|
79
|
-
text: '',
|
|
80
|
-
id: _slugid.default.nice()
|
|
81
|
-
}],
|
|
82
|
-
style,
|
|
83
|
-
inherit_style: style
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
exports.generateTableCell = generateTableCell;
|
|
87
|
-
const generateTableRow = (editor, colsCount, rowIndex) => {
|
|
88
|
-
let children = [];
|
|
89
|
-
for (let i = 0; i < colsCount; i++) {
|
|
90
|
-
const tableCell = generateTableCell(editor, rowIndex, i);
|
|
91
|
-
children.push(tableCell);
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
id: _slugid.default.nice(),
|
|
95
|
-
type: _constants2.ELEMENT_TYPE.TABLE_ROW,
|
|
96
|
-
children: children,
|
|
97
|
-
style: {
|
|
98
|
-
[_constants3.TABLE_ROW_STYLE.MIN_HEIGHT]: _constants3.TABLE_ROW_MIN_HEIGHT
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @param {Editor} editor
|
|
105
|
-
* @param {Object} tableProps
|
|
106
|
-
* @param {[number,number]} tableProps.size - table size, [row,column]
|
|
107
|
-
* @param {Boolean} tableProps.alternate_highlight - is alternate highlight
|
|
108
|
-
* @param {string} tableProps.alternate_highlight_color - table alternate highlight color
|
|
109
|
-
*/
|
|
110
|
-
exports.generateTableRow = generateTableRow;
|
|
111
|
-
const generateEmptyTable = (editor, tableProps) => {
|
|
112
|
-
const {
|
|
113
|
-
size = [0, 0],
|
|
114
|
-
alternate_highlight = false,
|
|
115
|
-
alternate_highlight_color
|
|
116
|
-
} = tableProps;
|
|
117
|
-
const rowsCount = size[0];
|
|
118
|
-
const colsCount = size[1];
|
|
119
|
-
let children = [];
|
|
120
|
-
for (let i = 0; i < rowsCount; i++) {
|
|
121
|
-
const tableRow = generateTableRow(editor, colsCount, i);
|
|
122
|
-
children.push(tableRow);
|
|
123
|
-
}
|
|
124
|
-
const columnWidth = Math.max(_constants3.TABLE_CELL_MIN_WIDTH, parseInt(editor.width / colsCount));
|
|
125
|
-
let columns = [];
|
|
126
|
-
for (let i = 0; i < colsCount; i++) {
|
|
127
|
-
columns.push({
|
|
128
|
-
width: columnWidth
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
id: _slugid.default.nice(),
|
|
133
|
-
type: _constants2.ELEMENT_TYPE.TABLE,
|
|
134
|
-
children: children,
|
|
135
|
-
columns,
|
|
136
|
-
ui: {
|
|
137
|
-
alternate_highlight,
|
|
138
|
-
alternate_highlight_color
|
|
139
|
-
},
|
|
140
|
-
style: {
|
|
141
|
-
gridTemplateColumns: `repeat(${colsCount}, ${columnWidth}px)`,
|
|
142
|
-
gridAutoRows: `minmax(${_constants3.TABLE_ROW_MIN_HEIGHT}px, auto)`
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
exports.generateEmptyTable = generateEmptyTable;
|
|
147
|
-
const insertTable = function (editor, size, selection) {
|
|
148
|
-
let position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _constants2.INSERT_POSITION.CURRENT;
|
|
149
|
-
if (!size) return;
|
|
150
|
-
if (position !== _constants2.INSERT_POSITION.AFTER) {
|
|
151
|
-
if (isTableMenuDisabled(editor)) return;
|
|
152
|
-
}
|
|
153
|
-
const tableNode = generateEmptyTable(editor, {
|
|
154
|
-
size
|
|
155
|
-
});
|
|
156
|
-
const validSelection = selection || editor.selection;
|
|
157
|
-
const path = _slate.Editor.path(editor, validSelection);
|
|
158
|
-
handleInsertTable(editor, position, path, tableNode);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// tableSize [tableHeight, tableWidth]
|
|
162
|
-
exports.insertTable = insertTable;
|
|
163
|
-
const getSelectedInfo = editor => {
|
|
164
|
-
const currentTable = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE);
|
|
165
|
-
const currentRow = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE_ROW);
|
|
166
|
-
const currentCell = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE_CELL);
|
|
167
|
-
const currentCellPath = (0, _core.findPath)(editor, currentCell);
|
|
168
|
-
return {
|
|
169
|
-
table: currentTable,
|
|
170
|
-
tablePath: (0, _core.findPath)(editor, currentTable),
|
|
171
|
-
tableSize: [currentTable.children.length, currentRow.children.length],
|
|
172
|
-
row: currentRow,
|
|
173
|
-
rowPath: (0, _core.findPath)(editor, currentRow),
|
|
174
|
-
rowIndex: currentCellPath[currentCellPath.length - 2],
|
|
175
|
-
cell: currentCell,
|
|
176
|
-
cellPath: (0, _core.findPath)(editor, currentCell),
|
|
177
|
-
cellIndex: currentCellPath[currentCellPath.length - 1]
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
exports.getSelectedInfo = getSelectedInfo;
|
|
181
|
-
const isInTable = editor => {
|
|
182
|
-
const selectedNodes = (0, _core.getSelectedElems)(editor);
|
|
183
|
-
if (!selectedNodes.some(node => node.type === _constants2.ELEMENT_TYPE.TABLE)) return false;
|
|
184
|
-
const firstSelectedNode = selectedNodes[0];
|
|
185
|
-
return firstSelectedNode.type === _constants2.ELEMENT_TYPE.TABLE;
|
|
186
|
-
};
|
|
187
|
-
exports.isInTable = isInTable;
|
|
188
|
-
const isAllInTable = editor => {
|
|
189
|
-
const selectedNodes = (0, _core.getSelectedElems)(editor);
|
|
190
|
-
if (!selectedNodes.some(node => node.type === _constants2.ELEMENT_TYPE.TABLE)) return false;
|
|
191
|
-
const firstSelectedNode = selectedNodes[0];
|
|
192
|
-
if (firstSelectedNode.type !== _constants2.ELEMENT_TYPE.TABLE) return false;
|
|
193
|
-
return selectedNodes.slice(1).every(node => [_constants2.ELEMENT_TYPE.TABLE_ROW, _constants2.ELEMENT_TYPE.TABLE_CELL].includes(node.type)); // same table element
|
|
194
|
-
};
|
|
195
|
-
exports.isAllInTable = isAllInTable;
|
|
196
|
-
const isInTableSameCell = editor => {
|
|
197
|
-
const {
|
|
198
|
-
anchor,
|
|
199
|
-
focus
|
|
200
|
-
} = editor.selection;
|
|
201
|
-
const match = n => n.type === _constants2.ELEMENT_TYPE.TABLE_CELL;
|
|
202
|
-
const anchorNode = (0, _core.getAboveBlockNode)(editor, {
|
|
203
|
-
at: anchor,
|
|
204
|
-
match
|
|
205
|
-
});
|
|
206
|
-
const focusNode = (0, _core.getAboveBlockNode)(editor, {
|
|
207
|
-
at: focus,
|
|
208
|
-
match
|
|
209
|
-
});
|
|
210
|
-
if (!anchorNode || !focusNode) return false;
|
|
211
|
-
return _slate.Path.equals(anchorNode[1], focusNode[1]);
|
|
212
|
-
};
|
|
213
|
-
exports.isInTableSameCell = isInTableSameCell;
|
|
214
|
-
const setCellStyle = (editor, style) => {
|
|
215
|
-
// Select single cell
|
|
216
|
-
if (_objectUtils.default.isSameObject(editor.tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
217
|
-
const selectedNodes = (0, _core.getSelectedElems)(editor);
|
|
218
|
-
let firstTableCellNodePath;
|
|
219
|
-
selectedNodes.forEach(node => {
|
|
220
|
-
if (node.type === _constants2.ELEMENT_TYPE.TABLE_CELL) {
|
|
221
|
-
const path = (0, _core.findPath)(editor, node);
|
|
222
|
-
if (path) {
|
|
223
|
-
firstTableCellNodePath = firstTableCellNodePath ? firstTableCellNodePath : path;
|
|
224
|
-
_slate.Transforms.setNodes(editor, {
|
|
225
|
-
style: {
|
|
226
|
-
...node.style,
|
|
227
|
-
...style
|
|
228
|
-
},
|
|
229
|
-
inherit_style: generateInheritStyle(_constants3.INHERIT_CELL_STYLE_WHEN_SELECT_SINGLE, style, node)
|
|
230
|
-
}, {
|
|
231
|
-
at: path
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
if (firstTableCellNodePath) {
|
|
237
|
-
const start = _slate.Editor.start(editor, firstTableCellNodePath);
|
|
238
|
-
const end = _slate.Editor.end(editor, firstTableCellNodePath);
|
|
239
|
-
const newSelection = {
|
|
240
|
-
anchor: start,
|
|
241
|
-
focus: end
|
|
242
|
-
};
|
|
243
|
-
_slate.Transforms.select(editor, newSelection);
|
|
244
|
-
}
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
// Select multiple cells
|
|
248
|
-
const {
|
|
249
|
-
minColIndex,
|
|
250
|
-
maxColIndex,
|
|
251
|
-
minRowIndex,
|
|
252
|
-
maxRowIndex
|
|
253
|
-
} = editor.tableSelectedRange;
|
|
254
|
-
const {
|
|
255
|
-
tablePath
|
|
256
|
-
} = getSelectedInfo(editor);
|
|
257
|
-
for (let i = minRowIndex; i <= maxRowIndex; i++) {
|
|
258
|
-
for (let j = minColIndex; j <= maxColIndex; j++) {
|
|
259
|
-
const path = [...tablePath, i, j];
|
|
260
|
-
const node = (0, _core.getNode)(editor, path);
|
|
261
|
-
_slate.Transforms.setNodes(editor, {
|
|
262
|
-
style: {
|
|
263
|
-
...node.style,
|
|
264
|
-
...style
|
|
265
|
-
},
|
|
266
|
-
inherit_style: generateInheritStyle(_constants3.INHERIT_CELL_STYLE_WHEN_SELECT_MULTIPLE, style, node)
|
|
267
|
-
}, {
|
|
268
|
-
at: path
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
exports.setCellStyle = setCellStyle;
|
|
274
|
-
const insertTableRow = function (editor, table, rowIndex) {
|
|
275
|
-
let position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _constants3.TABLE_ELEMENT_POSITION.AFTER;
|
|
276
|
-
const tableRowCount = table.children.length;
|
|
277
|
-
if (tableRowCount >= _constants3.TABLE_MAX_ROWS) return;
|
|
278
|
-
const tableColumnCount = table.children[0].children.length;
|
|
279
|
-
const row = generateTableRow(editor, tableColumnCount, rowIndex);
|
|
280
|
-
const tablePath = (0, _core.findPath)(editor, table);
|
|
281
|
-
const targetPath = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? [...tablePath, rowIndex + 1] : [...tablePath, rowIndex];
|
|
282
|
-
_slate.Transforms.insertNodes(editor, row, {
|
|
283
|
-
at: targetPath
|
|
284
|
-
});
|
|
285
|
-
const focusPath = [...targetPath, 0];
|
|
286
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
287
|
-
|
|
288
|
-
// handle cells with the rowspan > 1
|
|
289
|
-
if (position === _constants3.TABLE_ELEMENT_POSITION.AFTER) {
|
|
290
|
-
handleCombinedCellsAfterInsertTableRow(editor, tablePath, table, rowIndex);
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
exports.insertTableRow = insertTableRow;
|
|
294
|
-
const handleCombinedCellsAfterInsertTableRow = (editor, tablePath, table, rowIndex) => {
|
|
295
|
-
// important background info: the new row is inserted after rowIndex
|
|
296
|
-
const cells = table.children[rowIndex].children;
|
|
297
|
-
for (let i = 0, len = cells.length; i < len; i++) {
|
|
298
|
-
const {
|
|
299
|
-
is_combined,
|
|
300
|
-
rowspan,
|
|
301
|
-
colspan
|
|
302
|
-
} = cells[i];
|
|
303
|
-
if (is_combined) {
|
|
304
|
-
for (let ri = rowIndex - 1; ri >= 0; ri--) {
|
|
305
|
-
const {
|
|
306
|
-
is_combined: ri_is_combined,
|
|
307
|
-
rowspan: ri_rowspan,
|
|
308
|
-
colspan: ri_colspan
|
|
309
|
-
} = table.children[ri].children[i];
|
|
310
|
-
if (!ri_is_combined && ri + ri_rowspan - 1 > rowIndex) {
|
|
311
|
-
_slate.Transforms.setNodes(editor, {
|
|
312
|
-
rowspan: ri_rowspan + 1
|
|
313
|
-
}, {
|
|
314
|
-
at: [...tablePath, ri, i]
|
|
315
|
-
});
|
|
316
|
-
for (let j = 0; j < ri_colspan; j++) {
|
|
317
|
-
_slate.Transforms.setNodes(editor, {
|
|
318
|
-
'is_combined': true
|
|
319
|
-
}, {
|
|
320
|
-
at: [...tablePath, rowIndex + 1, i + j]
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
} else {
|
|
327
|
-
if (rowspan > 1) {
|
|
328
|
-
_slate.Transforms.setNodes(editor, {
|
|
329
|
-
rowspan: rowspan + 1
|
|
330
|
-
}, {
|
|
331
|
-
at: [...tablePath, rowIndex, i]
|
|
332
|
-
});
|
|
333
|
-
for (let j = 0; j < colspan; j++) {
|
|
334
|
-
_slate.Transforms.setNodes(editor, {
|
|
335
|
-
'is_combined': true
|
|
336
|
-
}, {
|
|
337
|
-
at: [...tablePath, rowIndex + 1, i + j]
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
exports.handleCombinedCellsAfterInsertTableRow = handleCombinedCellsAfterInsertTableRow;
|
|
345
|
-
const insertTableColumn = function (editor, table, columnIndex) {
|
|
346
|
-
let position = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _constants3.TABLE_ELEMENT_POSITION.AFTER;
|
|
347
|
-
const tableColumnCount = table.children[0].children.length;
|
|
348
|
-
if (tableColumnCount >= _constants3.TABLE_MAX_COLUMNS) return;
|
|
349
|
-
const newCellIndex = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? columnIndex + 1 : columnIndex;
|
|
350
|
-
const newColumns = getTableColumnsAfterInsertColumn(editor, table, newCellIndex, 1);
|
|
351
|
-
updateColumnWidth(editor, table, newColumns);
|
|
352
|
-
const tablePath = (0, _core.findPath)(editor, table);
|
|
353
|
-
const tableRowCount = table.children.length;
|
|
354
|
-
for (let i = 0; i < tableRowCount; i++) {
|
|
355
|
-
const newCellPath = [...tablePath, i, newCellIndex];
|
|
356
|
-
const newCell = generateTableCell(editor, i, columnIndex);
|
|
357
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
358
|
-
at: newCellPath
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
const focusPath = [...tablePath, 0, newCellIndex, 0];
|
|
362
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
363
|
-
|
|
364
|
-
// handle cells with the colspan > 1
|
|
365
|
-
if (position === _constants3.TABLE_ELEMENT_POSITION.AFTER) {
|
|
366
|
-
handleCombinedCellsAfterInsertTableColumn(editor, tablePath, table, columnIndex);
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
exports.insertTableColumn = insertTableColumn;
|
|
370
|
-
const handleCombinedCellsAfterInsertTableColumn = (editor, tablePath, table, columnIndex) => {
|
|
371
|
-
// important background info: the new column is inserted after columnIndex
|
|
372
|
-
for (let i = 0, len = table.children.length; i < len; i++) {
|
|
373
|
-
const {
|
|
374
|
-
is_combined,
|
|
375
|
-
rowspan,
|
|
376
|
-
colspan
|
|
377
|
-
} = table.children[i].children[columnIndex];
|
|
378
|
-
if (is_combined) {
|
|
379
|
-
for (let ci = columnIndex - 1; ci >= 0; ci--) {
|
|
380
|
-
const {
|
|
381
|
-
is_combined: ci_is_combined,
|
|
382
|
-
rowspan: ci_rowspan,
|
|
383
|
-
colspan: ci_colspan
|
|
384
|
-
} = table.children[i].children[ci];
|
|
385
|
-
if (!ci_is_combined && ci + ci_colspan - 1 > columnIndex) {
|
|
386
|
-
_slate.Transforms.setNodes(editor, {
|
|
387
|
-
colspan: ci_colspan + 1
|
|
388
|
-
}, {
|
|
389
|
-
at: [...tablePath, i, ci]
|
|
390
|
-
});
|
|
391
|
-
for (let j = 0; j < ci_rowspan; j++) {
|
|
392
|
-
_slate.Transforms.setNodes(editor, {
|
|
393
|
-
'is_combined': true
|
|
394
|
-
}, {
|
|
395
|
-
at: [...tablePath, i + j, columnIndex + 1]
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
} else {
|
|
402
|
-
if (colspan > 1) {
|
|
403
|
-
_slate.Transforms.setNodes(editor, {
|
|
404
|
-
colspan: colspan + 1
|
|
405
|
-
}, {
|
|
406
|
-
at: [...tablePath, i, columnIndex]
|
|
407
|
-
});
|
|
408
|
-
for (let j = 0; j < rowspan; j++) {
|
|
409
|
-
_slate.Transforms.setNodes(editor, {
|
|
410
|
-
'is_combined': true
|
|
411
|
-
}, {
|
|
412
|
-
at: [...tablePath, i + j, columnIndex + 1]
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
exports.handleCombinedCellsAfterInsertTableColumn = handleCombinedCellsAfterInsertTableColumn;
|
|
420
|
-
const insertTableElement = function (editor, type) {
|
|
421
|
-
let position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _constants3.TABLE_ELEMENT_POSITION.AFTER;
|
|
422
|
-
let count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
423
|
-
const {
|
|
424
|
-
table,
|
|
425
|
-
tablePath,
|
|
426
|
-
tableSize,
|
|
427
|
-
rowIndex,
|
|
428
|
-
cellIndex
|
|
429
|
-
} = getSelectedInfo(editor);
|
|
430
|
-
const eventBus = _eventBus.default.getInstance();
|
|
431
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
432
|
-
if (type === _constants3.TABLE_ELEMENT.ROW) {
|
|
433
|
-
if (tableSize[0] >= _constants3.TABLE_MAX_ROWS) return;
|
|
434
|
-
const targetPath = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? [...tablePath, rowIndex + 1] : [...tablePath, rowIndex];
|
|
435
|
-
const validCount = Math.min(_constants3.TABLE_MAX_ROWS - tableSize[0], count);
|
|
436
|
-
for (let i = 0; i < validCount; i++) {
|
|
437
|
-
const row = generateTableRow(editor, tableSize[1], rowIndex);
|
|
438
|
-
_slate.Transforms.insertNodes(editor, row, {
|
|
439
|
-
at: targetPath
|
|
440
|
-
});
|
|
441
|
-
// handle combined cells
|
|
442
|
-
if (!(rowIndex === 0 && position === _constants3.TABLE_ELEMENT_POSITION.BEFORE)) {
|
|
443
|
-
const targetRowIndex = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? rowIndex : rowIndex - 1;
|
|
444
|
-
const currentTable = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE);
|
|
445
|
-
handleCombinedCellsAfterInsertTableRow(editor, tablePath, currentTable, targetRowIndex);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const focusPath = [...targetPath, cellIndex];
|
|
449
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
if (type === _constants3.TABLE_ELEMENT.COLUMN) {
|
|
453
|
-
if (tableSize[1] >= _constants3.TABLE_MAX_COLUMNS) return;
|
|
454
|
-
const newCellIndex = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? cellIndex + 1 : cellIndex;
|
|
455
|
-
const validCount = Math.min(_constants3.TABLE_MAX_COLUMNS - tableSize[1], count);
|
|
456
|
-
const newColumns = getTableColumnsAfterInsertColumn(editor, table, newCellIndex, validCount);
|
|
457
|
-
updateColumnWidth(editor, table, newColumns);
|
|
458
|
-
for (let j = 0; j < validCount; j++) {
|
|
459
|
-
for (let i = 0; i < tableSize[0]; i++) {
|
|
460
|
-
const newCellPath = [...tablePath, i, newCellIndex];
|
|
461
|
-
const newCell = generateTableCell(editor, i, cellIndex);
|
|
462
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
463
|
-
at: newCellPath
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
// handle combined cells
|
|
467
|
-
if (!(cellIndex === 0 && position === _constants3.TABLE_ELEMENT_POSITION.BEFORE)) {
|
|
468
|
-
const targetColumnIndex = position === _constants3.TABLE_ELEMENT_POSITION.AFTER ? cellIndex : cellIndex - 1;
|
|
469
|
-
const currentTable = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE);
|
|
470
|
-
handleCombinedCellsAfterInsertTableColumn(editor, tablePath, currentTable, targetColumnIndex);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const focusPath = [...tablePath, rowIndex, cellIndex + 1, 0];
|
|
474
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
exports.insertTableElement = insertTableElement;
|
|
479
|
-
const combineCells = editor => {
|
|
480
|
-
const {
|
|
481
|
-
tablePath
|
|
482
|
-
} = getSelectedInfo(editor);
|
|
483
|
-
const {
|
|
484
|
-
minColIndex,
|
|
485
|
-
maxColIndex,
|
|
486
|
-
minRowIndex,
|
|
487
|
-
maxRowIndex
|
|
488
|
-
} = editor.tableSelectedRange;
|
|
489
|
-
let newCellContent = [];
|
|
490
|
-
for (let i = minRowIndex; i < maxRowIndex + 1; i++) {
|
|
491
|
-
for (let j = minColIndex; j < maxColIndex + 1; j++) {
|
|
492
|
-
let nodePath = [...tablePath, i, j];
|
|
493
|
-
let node = _slate.Editor.node(editor, nodePath);
|
|
494
|
-
if (node[0].is_combined) {
|
|
495
|
-
continue;
|
|
496
|
-
}
|
|
497
|
-
_slate.Transforms.setNodes(editor, {
|
|
498
|
-
'is_combined': true
|
|
499
|
-
}, {
|
|
500
|
-
at: nodePath
|
|
501
|
-
});
|
|
502
|
-
newCellContent = newCellContent.concat(node[0].children);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
const targetCellPath = [...tablePath, minRowIndex, minColIndex];
|
|
506
|
-
const newCell = generateTableCell(editor);
|
|
507
|
-
newCell.children = newCellContent;
|
|
508
|
-
newCell.rowspan = maxRowIndex - minRowIndex + 1;
|
|
509
|
-
newCell.colspan = maxColIndex - minColIndex + 1;
|
|
510
|
-
// keep row.children.length not changed
|
|
511
|
-
_slate.Transforms.removeNodes(editor, {
|
|
512
|
-
at: targetCellPath
|
|
513
|
-
});
|
|
514
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
515
|
-
at: targetCellPath
|
|
516
|
-
});
|
|
517
|
-
(0, _core.focusEditor)(editor, targetCellPath);
|
|
518
|
-
|
|
519
|
-
// for clicking the 'combine cell' icon in the toolbar
|
|
520
|
-
const eventBus = _eventBus.default.getInstance();
|
|
521
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
522
|
-
};
|
|
523
|
-
exports.combineCells = combineCells;
|
|
524
|
-
const splitCell = (editor, rowNumber, columnNumber) => {
|
|
525
|
-
if (rowNumber === 1 && columnNumber === 1) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
const {
|
|
529
|
-
cell,
|
|
530
|
-
rowIndex,
|
|
531
|
-
cellIndex,
|
|
532
|
-
cellPath,
|
|
533
|
-
tablePath
|
|
534
|
-
} = getSelectedInfo(editor);
|
|
535
|
-
const {
|
|
536
|
-
rowspan,
|
|
537
|
-
colspan
|
|
538
|
-
} = cell;
|
|
539
|
-
const rowspanBase = Math.floor(rowspan / rowNumber);
|
|
540
|
-
const rowspanLeft = rowspan % rowNumber;
|
|
541
|
-
const colspanBase = Math.floor(colspan / columnNumber);
|
|
542
|
-
const colspanLeft = colspan % columnNumber;
|
|
543
|
-
const cellNumber = rowNumber * columnNumber;
|
|
544
|
-
const dataBlockNumber = Math.ceil(cell.children.length / cellNumber);
|
|
545
|
-
let firstNewCell;
|
|
546
|
-
let rowspanSum = 0;
|
|
547
|
-
for (let i = 0; i < rowNumber; i++) {
|
|
548
|
-
let newRowSpan = rowspanBase + (i + 1 <= rowspanLeft ? 1 : 0);
|
|
549
|
-
let colspanSum = 0;
|
|
550
|
-
for (let j = 0; j < columnNumber; j++) {
|
|
551
|
-
const newCell = generateTableCell(editor);
|
|
552
|
-
let startIndex = (i * columnNumber + j) * dataBlockNumber;
|
|
553
|
-
if (startIndex < cell.children.length) {
|
|
554
|
-
let endIndex = Math.min(startIndex + dataBlockNumber, cell.children.length);
|
|
555
|
-
newCell.children = cell.children.slice(startIndex, endIndex);
|
|
556
|
-
}
|
|
557
|
-
newCell.rowspan = newRowSpan;
|
|
558
|
-
newCell.colspan = colspanBase + (j + 1 <= colspanLeft ? 1 : 0);
|
|
559
|
-
const newRowIndex = rowIndex + rowspanSum;
|
|
560
|
-
const newCellIndex = cellIndex + colspanSum;
|
|
561
|
-
const targetCellPath = [...tablePath, newRowIndex, newCellIndex];
|
|
562
|
-
if (i === 0 && j === 0) {
|
|
563
|
-
firstNewCell = newCell;
|
|
564
|
-
} else {
|
|
565
|
-
_slate.Transforms.removeNodes(editor, {
|
|
566
|
-
at: targetCellPath
|
|
567
|
-
});
|
|
568
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
569
|
-
at: targetCellPath
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
colspanSum += newCell.colspan;
|
|
573
|
-
}
|
|
574
|
-
rowspanSum += newRowSpan;
|
|
575
|
-
}
|
|
576
|
-
_slate.Transforms.removeNodes(editor, {
|
|
577
|
-
at: cellPath
|
|
578
|
-
});
|
|
579
|
-
_slate.Transforms.insertNodes(editor, firstNewCell, {
|
|
580
|
-
at: cellPath
|
|
581
|
-
});
|
|
582
|
-
};
|
|
583
|
-
exports.splitCell = splitCell;
|
|
584
|
-
const syncRemoveTable = (editor, path) => {
|
|
585
|
-
let validPath = path;
|
|
586
|
-
if (!validPath) {
|
|
587
|
-
const {
|
|
588
|
-
tablePath
|
|
589
|
-
} = getSelectedInfo(editor);
|
|
590
|
-
validPath = tablePath;
|
|
591
|
-
}
|
|
592
|
-
editor.reSetTableSelectedRange();
|
|
593
|
-
_slate.Transforms.removeNodes(editor, {
|
|
594
|
-
at: validPath
|
|
595
|
-
});
|
|
596
|
-
};
|
|
597
|
-
exports.syncRemoveTable = syncRemoveTable;
|
|
598
|
-
const removeTable = (editor, path) => {
|
|
599
|
-
let validPath = path;
|
|
600
|
-
if (!validPath) {
|
|
601
|
-
const {
|
|
602
|
-
tablePath
|
|
603
|
-
} = getSelectedInfo(editor);
|
|
604
|
-
validPath = tablePath;
|
|
605
|
-
}
|
|
606
|
-
editor.reSetTableSelectedRange();
|
|
607
|
-
|
|
608
|
-
// Clicking the menu causes the table to be re-rendered, and the deletion operation is performed synchronously. When rendering, it is found that the data is lost and an error is reported.
|
|
609
|
-
setTimeout(() => {
|
|
610
|
-
_slate.Transforms.removeNodes(editor, {
|
|
611
|
-
at: validPath
|
|
612
|
-
});
|
|
613
|
-
if (_slate.Editor.hasPath(editor, validPath)) {
|
|
614
|
-
const endOfLastNodePoint = _slate.Editor.end(editor, validPath);
|
|
615
|
-
const range = {
|
|
616
|
-
anchor: endOfLastNodePoint,
|
|
617
|
-
focus: endOfLastNodePoint
|
|
618
|
-
};
|
|
619
|
-
(0, _core.focusEditor)(editor, range);
|
|
620
|
-
}
|
|
621
|
-
}, 0);
|
|
622
|
-
};
|
|
623
|
-
exports.removeTable = removeTable;
|
|
624
|
-
const removeTableElement = (editor, type) => {
|
|
625
|
-
const {
|
|
626
|
-
table,
|
|
627
|
-
tablePath,
|
|
628
|
-
tableSize,
|
|
629
|
-
rowPath,
|
|
630
|
-
rowIndex,
|
|
631
|
-
cellIndex
|
|
632
|
-
} = getSelectedInfo(editor);
|
|
633
|
-
const eventBus = _eventBus.default.getInstance();
|
|
634
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
635
|
-
if (type === _constants3.TABLE_ELEMENT.TABLE) {
|
|
636
|
-
removeTable(editor, tablePath);
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
if (type === _constants3.TABLE_ELEMENT.ROW) {
|
|
640
|
-
if (tableSize[0] === 1) {
|
|
641
|
-
removeTable(editor, tablePath);
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
if (!_objectUtils.default.isSameObject(editor.tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
645
|
-
const {
|
|
646
|
-
minRowIndex,
|
|
647
|
-
maxRowIndex
|
|
648
|
-
} = editor.tableSelectedRange;
|
|
649
|
-
if (minRowIndex === 0 && maxRowIndex === tableSize[0] - 1) {
|
|
650
|
-
removeTable(editor, tablePath);
|
|
651
|
-
return;
|
|
652
|
-
}
|
|
653
|
-
for (let i = minRowIndex; i <= maxRowIndex; i++) {
|
|
654
|
-
queueMicrotask(() => {
|
|
655
|
-
_slate.Transforms.removeNodes(editor, {
|
|
656
|
-
at: [...tablePath, minRowIndex]
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
const focusPath = [...tablePath, minRowIndex === 0 ? 0 : minRowIndex - 1, cellIndex];
|
|
661
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
handleCombinedCellsBeforeDeleteTableRow(editor, tablePath, table, rowIndex);
|
|
665
|
-
_slate.Transforms.removeNodes(editor, {
|
|
666
|
-
at: rowPath
|
|
667
|
-
});
|
|
668
|
-
const focusRowIndex = rowIndex === tableSize[0] - 1 ? rowIndex - 1 : rowIndex;
|
|
669
|
-
const focusPath = [...tablePath, focusRowIndex, cellIndex];
|
|
670
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
if (type === _constants3.TABLE_ELEMENT.COLUMN) {
|
|
674
|
-
if (tableSize[1] === 1) {
|
|
675
|
-
removeTable(editor, tablePath);
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
if (!_objectUtils.default.isSameObject(editor.tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
679
|
-
const {
|
|
680
|
-
minColIndex,
|
|
681
|
-
maxColIndex
|
|
682
|
-
} = editor.tableSelectedRange;
|
|
683
|
-
if (minColIndex === 0 && maxColIndex === tableSize[1] - 1) {
|
|
684
|
-
removeTable(editor, tablePath);
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
const columns = getTableColumns(editor, table);
|
|
688
|
-
const newColumns = [...columns.slice(0, minColIndex), ...columns.slice(maxColIndex + 1)];
|
|
689
|
-
updateColumnWidth(editor, table, newColumns);
|
|
690
|
-
for (let i = 0; i < tableSize[0]; i++) {
|
|
691
|
-
for (let j = minColIndex; j <= maxColIndex; j++) {
|
|
692
|
-
// count
|
|
693
|
-
const cellPath = [...tablePath, i, minColIndex];
|
|
694
|
-
_slate.Transforms.removeNodes(editor, {
|
|
695
|
-
at: cellPath
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
const focusPath = [...tablePath, rowIndex, minColIndex === 0 ? 0 : minColIndex - 1];
|
|
700
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
const columns = getTableColumns(editor, table);
|
|
704
|
-
const newColumns = columns.slice(0);
|
|
705
|
-
newColumns.splice(cellIndex, 1);
|
|
706
|
-
updateColumnWidth(editor, table, newColumns);
|
|
707
|
-
handleCombinedCellsBeforeDeleteTableColumn(editor, tablePath, table, cellIndex);
|
|
708
|
-
for (let i = 0; i < tableSize[0]; i++) {
|
|
709
|
-
const cellPath = [...tablePath, i, cellIndex];
|
|
710
|
-
_slate.Transforms.removeNodes(editor, {
|
|
711
|
-
at: cellPath
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
const focusCellIndex = cellIndex === tableSize[1] - 1 ? cellIndex - 1 : cellIndex;
|
|
715
|
-
const focusPath = [...tablePath, rowIndex, focusCellIndex];
|
|
716
|
-
(0, _core.focusEditor)(editor, focusPath);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
// handle combined cells before deleting a row
|
|
722
|
-
exports.removeTableElement = removeTableElement;
|
|
723
|
-
const handleCombinedCellsBeforeDeleteTableRow = (editor, tablePath, table, rowIndex) => {
|
|
724
|
-
const cells = table.children[rowIndex].children;
|
|
725
|
-
for (let i = 0, len = cells.length; i < len; i++) {
|
|
726
|
-
const {
|
|
727
|
-
is_combined,
|
|
728
|
-
rowspan,
|
|
729
|
-
colspan
|
|
730
|
-
} = cells[i];
|
|
731
|
-
if (is_combined) {
|
|
732
|
-
for (let ri = rowIndex - 1; ri >= 0; ri--) {
|
|
733
|
-
const {
|
|
734
|
-
is_combined: ri_is_combined,
|
|
735
|
-
rowspan: ri_rowspan
|
|
736
|
-
} = table.children[ri].children[i];
|
|
737
|
-
if (!ri_is_combined && ri + ri_rowspan - 1 >= rowIndex) {
|
|
738
|
-
_slate.Transforms.setNodes(editor, {
|
|
739
|
-
rowspan: ri_rowspan - 1
|
|
740
|
-
}, {
|
|
741
|
-
at: [...tablePath, ri, i]
|
|
742
|
-
});
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
} else {
|
|
747
|
-
if (rowspan > 1) {
|
|
748
|
-
const targetCellPath = [...tablePath, rowIndex + 1, i];
|
|
749
|
-
const newCell = generateTableCell(editor);
|
|
750
|
-
newCell.rowspan = rowspan - 1;
|
|
751
|
-
newCell.colspan = colspan;
|
|
752
|
-
_slate.Transforms.removeNodes(editor, {
|
|
753
|
-
at: targetCellPath
|
|
754
|
-
});
|
|
755
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
756
|
-
at: targetCellPath
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
// handle combined cells before deleting a column
|
|
764
|
-
exports.handleCombinedCellsBeforeDeleteTableRow = handleCombinedCellsBeforeDeleteTableRow;
|
|
765
|
-
const handleCombinedCellsBeforeDeleteTableColumn = (editor, tablePath, table, columnIndex) => {
|
|
766
|
-
for (let i = 0, len = table.children.length; i < len; i++) {
|
|
767
|
-
const {
|
|
768
|
-
is_combined,
|
|
769
|
-
rowspan,
|
|
770
|
-
colspan
|
|
771
|
-
} = table.children[i].children[columnIndex];
|
|
772
|
-
if (is_combined) {
|
|
773
|
-
for (let ci = columnIndex - 1; ci >= 0; ci--) {
|
|
774
|
-
const {
|
|
775
|
-
is_combined: ci_is_combined,
|
|
776
|
-
colspan: ci_colspan
|
|
777
|
-
} = table.children[i].children[ci];
|
|
778
|
-
if (!ci_is_combined && ci + ci_colspan - 1 >= columnIndex) {
|
|
779
|
-
_slate.Transforms.setNodes(editor, {
|
|
780
|
-
colspan: ci_colspan - 1
|
|
781
|
-
}, {
|
|
782
|
-
at: [...tablePath, i, ci]
|
|
783
|
-
});
|
|
784
|
-
break;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
} else {
|
|
788
|
-
if (colspan > 1) {
|
|
789
|
-
const targetCellPath = [...tablePath, i, columnIndex + 1];
|
|
790
|
-
const newCell = generateTableCell(editor);
|
|
791
|
-
newCell.rowspan = rowspan;
|
|
792
|
-
newCell.colspan = colspan - 1;
|
|
793
|
-
_slate.Transforms.removeNodes(editor, {
|
|
794
|
-
at: targetCellPath
|
|
795
|
-
});
|
|
796
|
-
_slate.Transforms.insertNodes(editor, newCell, {
|
|
797
|
-
at: targetCellPath
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
};
|
|
803
|
-
exports.handleCombinedCellsBeforeDeleteTableColumn = handleCombinedCellsBeforeDeleteTableColumn;
|
|
804
|
-
const setTableSelectedRange = (editor, range) => {
|
|
805
|
-
if (range) {
|
|
806
|
-
editor.tableSelectedRange = range;
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
editor.tableSelectedRange = _constants3.EMPTY_SELECTED_RANGE;
|
|
810
|
-
};
|
|
811
|
-
exports.setTableSelectedRange = setTableSelectedRange;
|
|
812
|
-
const updateTableRowHeight = (editor, element, rowHeight) => {
|
|
813
|
-
const path = (0, _core.findPath)(editor, element);
|
|
814
|
-
const targetNode = (0, _core.getNode)(editor, path);
|
|
815
|
-
const {
|
|
816
|
-
style = {}
|
|
817
|
-
} = targetNode;
|
|
818
|
-
if (style[_constants3.TABLE_ROW_STYLE.MIN_HEIGHT] === rowHeight) return;
|
|
819
|
-
_slate.Transforms.setNodes(editor, {
|
|
820
|
-
style: {
|
|
821
|
-
...style,
|
|
822
|
-
[_constants3.TABLE_ROW_STYLE.MIN_HEIGHT]: rowHeight
|
|
823
|
-
}
|
|
824
|
-
}, {
|
|
825
|
-
at: path
|
|
826
|
-
});
|
|
827
|
-
};
|
|
828
|
-
exports.updateTableRowHeight = updateTableRowHeight;
|
|
829
|
-
const updateColumnWidth = (editor, element, columns) => {
|
|
830
|
-
const path = (0, _core.findPath)(editor, element);
|
|
831
|
-
_slate.Transforms.setNodes(editor, {
|
|
832
|
-
columns: columns
|
|
833
|
-
}, {
|
|
834
|
-
at: path
|
|
835
|
-
});
|
|
836
|
-
};
|
|
837
|
-
exports.updateColumnWidth = updateColumnWidth;
|
|
838
|
-
const getTableColumnsWidth = function () {
|
|
839
|
-
let columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
840
|
-
if (!Array.isArray(columns) || columns.length === 0) return 0;
|
|
841
|
-
return columns.reduce((pre, cur) => pre + cur.width, 0);
|
|
842
|
-
};
|
|
843
|
-
exports.getTableColumnsWidth = getTableColumnsWidth;
|
|
844
|
-
const getTableColumnsAfterInsertColumn = (editor, element, targetColumnIndex, insertColumnCount) => {
|
|
845
|
-
const columns = getTableColumns(editor, element);
|
|
846
|
-
let newColumns = columns.slice(0);
|
|
847
|
-
let totalColumnsWidth = getTableColumnsWidth(columns);
|
|
848
|
-
const targetColumn = columns[targetColumnIndex] || columns[targetColumnIndex - 1];
|
|
849
|
-
const targetInsertColumnsWidth = targetColumn.width * insertColumnCount;
|
|
850
|
-
|
|
851
|
-
// Currently in scrolling state, insert directly
|
|
852
|
-
if (totalColumnsWidth > editor.width) {
|
|
853
|
-
for (let i = 0; i < insertColumnCount; i++) {
|
|
854
|
-
newColumns.splice(targetColumnIndex, 0, targetColumn);
|
|
855
|
-
}
|
|
856
|
-
return newColumns;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// Not currently scrolling
|
|
860
|
-
// It is not a scroll state after inserting a new column
|
|
861
|
-
if (totalColumnsWidth + targetInsertColumnsWidth < editor.width) {
|
|
862
|
-
for (let i = 0; i < insertColumnCount; i++) {
|
|
863
|
-
newColumns.push(targetColumn);
|
|
864
|
-
}
|
|
865
|
-
return newColumns;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// After inserting a new column is a scrolling state
|
|
869
|
-
for (let i = 0; i < insertColumnCount; i++) {
|
|
870
|
-
totalColumnsWidth += targetColumn.width;
|
|
871
|
-
newColumns.splice(targetColumnIndex, 0, targetColumn);
|
|
872
|
-
}
|
|
873
|
-
const proportion = totalColumnsWidth / (editor.width - 1);
|
|
874
|
-
return newColumns.map(column => {
|
|
875
|
-
return {
|
|
876
|
-
...column,
|
|
877
|
-
width: Math.max(parseInt(column.width / proportion), _constants3.TABLE_CELL_MIN_WIDTH)
|
|
878
|
-
};
|
|
879
|
-
});
|
|
880
|
-
};
|
|
881
|
-
exports.getTableColumnsAfterInsertColumn = getTableColumnsAfterInsertColumn;
|
|
882
|
-
const getTableColumns = (editor, element) => {
|
|
883
|
-
if (!element) return [];
|
|
884
|
-
let tableElement = element;
|
|
885
|
-
if (element.type === _constants2.ELEMENT_TYPE.TABLE_CELL) {
|
|
886
|
-
const cellPath = (0, _core.findPath)(editor, element);
|
|
887
|
-
const tablePath = cellPath.slice(0, -2);
|
|
888
|
-
tableElement = (0, _core.getNode)(editor, tablePath);
|
|
889
|
-
}
|
|
890
|
-
const {
|
|
891
|
-
columns,
|
|
892
|
-
children
|
|
893
|
-
} = tableElement;
|
|
894
|
-
if (columns) return columns;
|
|
895
|
-
const columnsCount = children[0].children.length;
|
|
896
|
-
let initColumns = [];
|
|
897
|
-
const pageEditAreaWidth = editor.width || _constants.PAGE_EDIT_AREA_WIDTH;
|
|
898
|
-
for (let i = 0; i < columnsCount; i++) {
|
|
899
|
-
const column = {
|
|
900
|
-
width: Math.max(_constants3.TABLE_CELL_MIN_WIDTH, parseInt(pageEditAreaWidth / columnsCount))
|
|
901
|
-
};
|
|
902
|
-
initColumns.push(column);
|
|
903
|
-
}
|
|
904
|
-
return initColumns;
|
|
905
|
-
};
|
|
906
|
-
exports.getTableColumns = getTableColumns;
|
|
907
|
-
const getCellColumn = (editor, cellElement) => {
|
|
908
|
-
let column = {
|
|
909
|
-
width: _constants3.TABLE_CELL_MIN_WIDTH
|
|
910
|
-
};
|
|
911
|
-
if (!editor || !cellElement) return column;
|
|
912
|
-
const cellPath = (0, _core.findPath)(editor, cellElement);
|
|
913
|
-
if (!cellPath) return column;
|
|
914
|
-
const pathLength = cellPath.length;
|
|
915
|
-
const cellIndex = cellPath[pathLength - 1];
|
|
916
|
-
const tablePath = cellPath.slice(0, -2);
|
|
917
|
-
const tableElement = (0, _core.getNode)(editor, tablePath);
|
|
918
|
-
const {
|
|
919
|
-
columns
|
|
920
|
-
} = tableElement;
|
|
921
|
-
const columnsCount = tableElement.children[0].children.length;
|
|
922
|
-
const pageEditAreaWidth = editor.width || _constants.PAGE_EDIT_AREA_WIDTH;
|
|
923
|
-
if (columns) {
|
|
924
|
-
column = columns[cellIndex];
|
|
925
|
-
}
|
|
926
|
-
return column || {
|
|
927
|
-
width: Math.max(_constants3.TABLE_CELL_MIN_WIDTH, parseInt(pageEditAreaWidth / columnsCount))
|
|
928
|
-
};
|
|
929
|
-
};
|
|
930
|
-
exports.getCellColumn = getCellColumn;
|
|
931
|
-
const getFirstTableCell = element => {
|
|
932
|
-
let tableCellElement = element;
|
|
933
|
-
while (tableCellElement && !(tableCellElement.hasAttribute('row-index') && tableCellElement.hasAttribute('cell-index'))) {
|
|
934
|
-
tableCellElement = tableCellElement.parentNode;
|
|
935
|
-
}
|
|
936
|
-
return tableCellElement;
|
|
937
|
-
};
|
|
938
|
-
exports.getFirstTableCell = getFirstTableCell;
|
|
939
|
-
const elementHasImage = element => {
|
|
940
|
-
if (!element) return false;
|
|
941
|
-
if (!Array.isArray(element.children) || element.children.length === 0) return false;
|
|
942
|
-
return element.children.some(child => {
|
|
943
|
-
if (child.type === _constants2.ELEMENT_TYPE.IMAGE) return true;
|
|
944
|
-
if (_objectUtils.default.hasProperty(child, 'children')) {
|
|
945
|
-
return elementHasImage(child);
|
|
946
|
-
}
|
|
947
|
-
return false;
|
|
948
|
-
});
|
|
949
|
-
};
|
|
950
|
-
exports.elementHasImage = elementHasImage;
|
|
951
|
-
const isSelectedAllCell = editor => {
|
|
952
|
-
const {
|
|
953
|
-
tableSize
|
|
954
|
-
} = getSelectedInfo(editor);
|
|
955
|
-
return _objectUtils.default.isSameObject(editor.tableSelectedRange, {
|
|
956
|
-
minColIndex: 0,
|
|
957
|
-
maxColIndex: tableSize[1] - 1,
|
|
958
|
-
minRowIndex: 0,
|
|
959
|
-
maxRowIndex: tableSize[0] - 1
|
|
960
|
-
});
|
|
961
|
-
};
|
|
962
|
-
exports.isSelectedAllCell = isSelectedAllCell;
|
|
963
|
-
const insertMultipleRowsAndColumns = (editor, rows, columns) => {
|
|
964
|
-
const {
|
|
965
|
-
table,
|
|
966
|
-
tablePath,
|
|
967
|
-
tableSize,
|
|
968
|
-
rowIndex,
|
|
969
|
-
cellIndex
|
|
970
|
-
} = getSelectedInfo(editor);
|
|
971
|
-
let newTable = (0, _deepCopy.default)(table);
|
|
972
|
-
const eventBus = _eventBus.default.getInstance();
|
|
973
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
974
|
-
const insertRows = rows.slice(tableSize[0] - rowIndex);
|
|
975
|
-
const insertColumns = columns.slice(tableSize[1] - cellIndex);
|
|
976
|
-
const validInsertRows = insertRows.slice(0, Math.min(_constants3.TABLE_MAX_ROWS - tableSize[0], insertRows.length));
|
|
977
|
-
const validInsertColumns = insertColumns.slice(0, Math.min(_constants3.TABLE_MAX_COLUMNS - tableSize[1], columns.length));
|
|
978
|
-
for (let i = 0; i < validInsertRows.length; i++) {
|
|
979
|
-
const insertRow = validInsertRows[i];
|
|
980
|
-
const row = generateTableRow(editor, tableSize[1], rowIndex);
|
|
981
|
-
row.style = insertRow.style;
|
|
982
|
-
newTable.children.push(row);
|
|
983
|
-
}
|
|
984
|
-
if (validInsertColumns.length > 0) {
|
|
985
|
-
newTable.columns = [...table.columns, ...validInsertColumns];
|
|
986
|
-
}
|
|
987
|
-
for (let j = 0; j < validInsertColumns.length; j++) {
|
|
988
|
-
for (let i = 0; i < tableSize[0] + validInsertRows.length; i++) {
|
|
989
|
-
const newCell = generateTableCell(editor);
|
|
990
|
-
newTable.children[i].children.push(newCell);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
for (let i = rowIndex; i < Math.min(_constants3.TABLE_MAX_ROWS, rowIndex + rows.length); i++) {
|
|
994
|
-
const row = rows[i - rowIndex];
|
|
995
|
-
const cells = row.children;
|
|
996
|
-
for (let j = cellIndex; j < Math.min(_constants3.TABLE_MAX_COLUMNS, cellIndex + columns.length); j++) {
|
|
997
|
-
const replaceCellIndex = j - cellIndex;
|
|
998
|
-
const replaceCell = cells[replaceCellIndex];
|
|
999
|
-
newTable.children[i].children[j].children = (0, _helpers.replacePastedDataId)(replaceCell.children);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
(0, _core.replaceNode)(editor, {
|
|
1003
|
-
at: tablePath,
|
|
1004
|
-
nodes: newTable
|
|
1005
|
-
});
|
|
1006
|
-
(0, _core.focusEditor)(editor, [...tablePath, rowIndex, cellIndex, 0]);
|
|
1007
|
-
const {
|
|
1008
|
-
focus: newFocus
|
|
1009
|
-
} = editor.selection;
|
|
1010
|
-
_slate.Transforms.select(editor, {
|
|
1011
|
-
focus: newFocus,
|
|
1012
|
-
anchor: newFocus
|
|
1013
|
-
});
|
|
1014
|
-
return;
|
|
1015
|
-
};
|
|
1016
|
-
exports.insertMultipleRowsAndColumns = insertMultipleRowsAndColumns;
|
|
1017
|
-
const setTableFragmentData = (editor, dataTransfer) => {
|
|
1018
|
-
const selectedNode = (0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE);
|
|
1019
|
-
const fragment = editor.getFragment();
|
|
1020
|
-
const string = JSON.stringify(fragment);
|
|
1021
|
-
const encoded = window.btoa(encodeURIComponent(string));
|
|
1022
|
-
dataTransfer.setData(`application/${_constants2.CLIPBOARD_FORMAT_KEY}`, encoded);
|
|
1023
|
-
const tableDom = document.createElement('table');
|
|
1024
|
-
const {
|
|
1025
|
-
minColIndex,
|
|
1026
|
-
maxColIndex,
|
|
1027
|
-
minRowIndex,
|
|
1028
|
-
maxRowIndex
|
|
1029
|
-
} = editor.tableSelectedRange;
|
|
1030
|
-
const tablePath = (0, _core.findPath)(editor, selectedNode);
|
|
1031
|
-
for (let i = minRowIndex; i <= maxRowIndex; i++) {
|
|
1032
|
-
const tr = document.createElement('tr');
|
|
1033
|
-
for (let j = minColIndex; j <= maxColIndex; j++) {
|
|
1034
|
-
const path = [...tablePath, i, j];
|
|
1035
|
-
const node = (0, _core.getNode)(editor, path);
|
|
1036
|
-
const td = document.createElement('td');
|
|
1037
|
-
const div = document.createElement('div');
|
|
1038
|
-
div.innerHTML = _slateReact.ReactEditor.toDOMNode(editor, node).innerHTML;
|
|
1039
|
-
td.appendChild(div);
|
|
1040
|
-
tr.appendChild(td);
|
|
1041
|
-
}
|
|
1042
|
-
tableDom.appendChild(tr);
|
|
1043
|
-
}
|
|
1044
|
-
tableDom.setAttribute('data-slate-fragment', encoded);
|
|
1045
|
-
const div = document.createElement('div');
|
|
1046
|
-
div.appendChild(tableDom);
|
|
1047
|
-
dataTransfer.setData('text/html', div.innerHTML);
|
|
1048
|
-
dataTransfer.setData('text/plain', div.innerText);
|
|
1049
|
-
return dataTransfer;
|
|
1050
|
-
};
|
|
1051
|
-
exports.setTableFragmentData = setTableFragmentData;
|
|
1052
|
-
const deleteTableRangeData = editor => {
|
|
1053
|
-
const {
|
|
1054
|
-
tableSelectedRange
|
|
1055
|
-
} = editor;
|
|
1056
|
-
const {
|
|
1057
|
-
minRowIndex,
|
|
1058
|
-
maxRowIndex,
|
|
1059
|
-
minColIndex,
|
|
1060
|
-
maxColIndex
|
|
1061
|
-
} = tableSelectedRange;
|
|
1062
|
-
const {
|
|
1063
|
-
tablePath
|
|
1064
|
-
} = getSelectedInfo(editor);
|
|
1065
|
-
let forceCellPath;
|
|
1066
|
-
for (let i = minRowIndex; i <= maxRowIndex; i++) {
|
|
1067
|
-
for (let j = minColIndex; j <= maxColIndex; j++) {
|
|
1068
|
-
const path = [...tablePath, i, j];
|
|
1069
|
-
const node = (0, _core.getNode)(editor, path);
|
|
1070
|
-
if (!forceCellPath && (_slate.Node.string(node) || elementHasImage(node))) {
|
|
1071
|
-
forceCellPath = path;
|
|
1072
|
-
}
|
|
1073
|
-
const firstNode = node.children[0];
|
|
1074
|
-
(0, _core.replaceNodeChildren)(editor, {
|
|
1075
|
-
at: path,
|
|
1076
|
-
nodes: {
|
|
1077
|
-
...firstNode,
|
|
1078
|
-
text: ''
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
if (forceCellPath) {
|
|
1084
|
-
editor.tableSelectedRange = _constants3.EMPTY_SELECTED_RANGE;
|
|
1085
|
-
const eventBus = _eventBus.default.getInstance();
|
|
1086
|
-
eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
1087
|
-
(0, _core.focusEditor)(editor, forceCellPath);
|
|
1088
|
-
const {
|
|
1089
|
-
focus: newFocus
|
|
1090
|
-
} = editor.selection;
|
|
1091
|
-
_slate.Transforms.select(editor, {
|
|
1092
|
-
focus: newFocus,
|
|
1093
|
-
anchor: newFocus
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
exports.deleteTableRangeData = deleteTableRangeData;
|
|
1098
|
-
const deleteHandler = editor => {
|
|
1099
|
-
const {
|
|
1100
|
-
selection,
|
|
1101
|
-
tableSelectedRange
|
|
1102
|
-
} = editor;
|
|
1103
|
-
if (selection == null) return '';
|
|
1104
|
-
if (!_objectUtils.default.isSameObject(tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
1105
|
-
if (isSelectedAllCell(editor)) return 'table';
|
|
1106
|
-
return 'range';
|
|
1107
|
-
}
|
|
1108
|
-
const [cellNodeEntry] = _slate.Editor.nodes(editor, {
|
|
1109
|
-
match: n => {
|
|
1110
|
-
let type = (0, _core.getNodeType)(n);
|
|
1111
|
-
if (!type && (0, _core.isTextNode)(n) && n.id) {
|
|
1112
|
-
const parentNode = (0, _core.getParentNode)(editor.children, n.id);
|
|
1113
|
-
type = (0, _core.getNodeType)(parentNode);
|
|
1114
|
-
}
|
|
1115
|
-
return type === _constants2.ELEMENT_TYPE.TABLE_CELL;
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
if (cellNodeEntry) {
|
|
1119
|
-
const [, cellPath] = cellNodeEntry;
|
|
1120
|
-
const start = _slate.Editor.start(editor, cellPath);
|
|
1121
|
-
if (_slate.Point.equals(selection.anchor, start)) {
|
|
1122
|
-
return 'default';
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
return '';
|
|
1126
|
-
};
|
|
1127
|
-
exports.deleteHandler = deleteHandler;
|
|
1128
|
-
const isTableLocation = (editor, location) => {
|
|
1129
|
-
const tables = _slate.Editor.nodes(editor, {
|
|
1130
|
-
at: location,
|
|
1131
|
-
match: n => {
|
|
1132
|
-
let type = (0, _core.getNodeType)(n);
|
|
1133
|
-
if (!type && (0, _core.isTextNode)(n) && n.id) {
|
|
1134
|
-
const parentNode = (0, _core.getParentNode)(editor.children, n.id);
|
|
1135
|
-
type = (0, _core.getNodeType)(parentNode);
|
|
1136
|
-
}
|
|
1137
|
-
return type === _constants2.ELEMENT_TYPE.TABLE_CELL;
|
|
1138
|
-
}
|
|
1139
|
-
});
|
|
1140
|
-
let hasTable = false;
|
|
1141
|
-
// eslint-disable-next-line no-unused-vars
|
|
1142
|
-
for (const table of tables) {
|
|
1143
|
-
hasTable = true;
|
|
1144
|
-
}
|
|
1145
|
-
return hasTable;
|
|
1146
|
-
};
|
|
1147
|
-
exports.isTableLocation = isTableLocation;
|
|
1148
|
-
const isCursorAtCellEnd = function (cell) {
|
|
1149
|
-
let cursor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
1150
|
-
if (!cell) return false;
|
|
1151
|
-
const childrenCount = cell.children.length;
|
|
1152
|
-
const lastChildren = cell.children[childrenCount - 1];
|
|
1153
|
-
const textCount = lastChildren.text.length;
|
|
1154
|
-
return cursor === textCount;
|
|
1155
|
-
};
|
|
1156
|
-
exports.isCursorAtCellEnd = isCursorAtCellEnd;
|
|
1157
|
-
const isCursorAtCellStart = function () {
|
|
1158
|
-
let cursor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1159
|
-
return cursor === 0;
|
|
1160
|
-
};
|
|
1161
|
-
exports.isCursorAtCellStart = isCursorAtCellStart;
|
|
1162
|
-
const focusCell = function (editor, event) {
|
|
1163
|
-
let keyboardName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
1164
|
-
const {
|
|
1165
|
-
tableSize,
|
|
1166
|
-
tablePath,
|
|
1167
|
-
rowIndex,
|
|
1168
|
-
cellIndex,
|
|
1169
|
-
cell
|
|
1170
|
-
} = getSelectedInfo(editor);
|
|
1171
|
-
const tableParentPath = tablePath.slice(0, -1);
|
|
1172
|
-
const tableIndex = tablePath[tablePath.length - 1];
|
|
1173
|
-
const {
|
|
1174
|
-
selection
|
|
1175
|
-
} = editor;
|
|
1176
|
-
const {
|
|
1177
|
-
focus
|
|
1178
|
-
} = selection;
|
|
1179
|
-
if (keyboardName === _constants2.KEYBOARD.UP) {
|
|
1180
|
-
if (!isCursorAtCellStart(focus.offset)) {
|
|
1181
|
-
setTimeout(() => {
|
|
1182
|
-
if ((0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE)) {
|
|
1183
|
-
const {
|
|
1184
|
-
cellIndex: newCellIndex
|
|
1185
|
-
} = getSelectedInfo(editor);
|
|
1186
|
-
if (Math.abs(newCellIndex - cellIndex) !== 0) {
|
|
1187
|
-
if (rowIndex === 0) {
|
|
1188
|
-
if (tableIndex !== 0) {
|
|
1189
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex - 1]);
|
|
1190
|
-
}
|
|
1191
|
-
return;
|
|
1192
|
-
}
|
|
1193
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex - 1, cellIndex]);
|
|
1194
|
-
const {
|
|
1195
|
-
focus: newFocus
|
|
1196
|
-
} = editor.selection;
|
|
1197
|
-
_slate.Transforms.select(editor, {
|
|
1198
|
-
focus: newFocus,
|
|
1199
|
-
anchor: newFocus
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}, 10);
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
event.preventDefault();
|
|
1207
|
-
if (rowIndex === 0) {
|
|
1208
|
-
if (tableIndex !== 0) {
|
|
1209
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex - 1]);
|
|
1210
|
-
}
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
1213
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex - 1, cellIndex]);
|
|
1214
|
-
const {
|
|
1215
|
-
focus: newFocus
|
|
1216
|
-
} = editor.selection;
|
|
1217
|
-
_slate.Transforms.select(editor, {
|
|
1218
|
-
focus: newFocus,
|
|
1219
|
-
anchor: newFocus
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
if (keyboardName === _constants2.KEYBOARD.RIGHT) {
|
|
1223
|
-
if (!isCursorAtCellEnd(cell, focus.offset)) return;
|
|
1224
|
-
event.preventDefault();
|
|
1225
|
-
if (rowIndex === tableSize[0] - 1 && cellIndex === tableSize[1] - 1) {
|
|
1226
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex + 1]);
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
if (cellIndex === tableSize[1] - 1) {
|
|
1230
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex + 1, 0]);
|
|
1231
|
-
} else {
|
|
1232
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex, cellIndex + 1]);
|
|
1233
|
-
}
|
|
1234
|
-
const {
|
|
1235
|
-
anchor: newAnchor
|
|
1236
|
-
} = editor.selection;
|
|
1237
|
-
_slate.Transforms.select(editor, {
|
|
1238
|
-
focus: newAnchor,
|
|
1239
|
-
anchor: newAnchor
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
if (keyboardName === _constants2.KEYBOARD.DOWN) {
|
|
1243
|
-
if (!isCursorAtCellEnd(cell, focus.offset)) {
|
|
1244
|
-
setTimeout(() => {
|
|
1245
|
-
if ((0, _core.getSelectedNodeByType)(editor, _constants2.ELEMENT_TYPE.TABLE)) {
|
|
1246
|
-
const {
|
|
1247
|
-
cellIndex: newCellIndex
|
|
1248
|
-
} = getSelectedInfo(editor);
|
|
1249
|
-
if (Math.abs(newCellIndex - cellIndex) !== 0) {
|
|
1250
|
-
if (rowIndex === tableSize[0] - 1) {
|
|
1251
|
-
const nextNode = (0, _core.getNode)(editor, [...tableParentPath, tableIndex + 1]);
|
|
1252
|
-
if (!nextNode) return;
|
|
1253
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex + 1]);
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex + 1, cellIndex]);
|
|
1257
|
-
const {
|
|
1258
|
-
anchor: newAnchor
|
|
1259
|
-
} = editor.selection;
|
|
1260
|
-
_slate.Transforms.select(editor, {
|
|
1261
|
-
focus: newAnchor,
|
|
1262
|
-
anchor: newAnchor
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}, 10);
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
event.preventDefault();
|
|
1270
|
-
if (rowIndex === tableSize[0] - 1) {
|
|
1271
|
-
const nextNode = (0, _core.getNode)([...tableParentPath, tableIndex + 1]);
|
|
1272
|
-
if (!nextNode) return;
|
|
1273
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex + 1]);
|
|
1274
|
-
return;
|
|
1275
|
-
}
|
|
1276
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex + 1, cellIndex]);
|
|
1277
|
-
const {
|
|
1278
|
-
anchor: newAnchor
|
|
1279
|
-
} = editor.selection;
|
|
1280
|
-
_slate.Transforms.select(editor, {
|
|
1281
|
-
focus: newAnchor,
|
|
1282
|
-
anchor: newAnchor
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
if (keyboardName === _constants2.KEYBOARD.LEFT) {
|
|
1286
|
-
if (!isCursorAtCellStart(focus.offset)) return;
|
|
1287
|
-
event.preventDefault();
|
|
1288
|
-
if (rowIndex === 0 && cellIndex === 0) {
|
|
1289
|
-
if (tableIndex !== 0) {
|
|
1290
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex - 1]);
|
|
1291
|
-
}
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
if (cellIndex === 0) {
|
|
1295
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex - 1, tableSize[1] - 1]);
|
|
1296
|
-
} else {
|
|
1297
|
-
(0, _core.focusEditor)(editor, [...tableParentPath, tableIndex, rowIndex, cellIndex - 1]);
|
|
1298
|
-
}
|
|
1299
|
-
const {
|
|
1300
|
-
focus: newFocus
|
|
1301
|
-
} = editor.selection;
|
|
1302
|
-
_slate.Transforms.select(editor, {
|
|
1303
|
-
focus: newFocus,
|
|
1304
|
-
anchor: newFocus
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
};
|
|
1308
|
-
exports.focusCell = focusCell;
|
|
1309
|
-
const isLastTableCell = (editor, cellNode) => {
|
|
1310
|
-
if (cellNode[0].type !== _constants2.ELEMENT_TYPE.TABLE_CELL) return false;
|
|
1311
|
-
const {
|
|
1312
|
-
tableSize
|
|
1313
|
-
} = getSelectedInfo(editor);
|
|
1314
|
-
const lastRowIndex = tableSize[0] - 1;
|
|
1315
|
-
const lastColumnIndex = tableSize[1] - 1;
|
|
1316
|
-
const cellNodePath = cellNode[1];
|
|
1317
|
-
const cellNodePathDeep = cellNodePath.length;
|
|
1318
|
-
return cellNodePath[cellNodePathDeep - 1] === lastColumnIndex && cellNodePath[cellNodePathDeep - 2] === lastRowIndex;
|
|
1319
|
-
};
|
|
1320
|
-
exports.isLastTableCell = isLastTableCell;
|
|
1321
|
-
const getValidColor = color => {
|
|
1322
|
-
if (!color) return '';
|
|
1323
|
-
const validColor = color.length === 4 ? '#' + color.slice(1, 4).repeat(2) : color;
|
|
1324
|
-
return validColor.toUpperCase();
|
|
1325
|
-
};
|
|
1326
|
-
const colorBlend = (c1, c2, ratio) => {
|
|
1327
|
-
const color1 = getValidColor(c1);
|
|
1328
|
-
const color2 = getValidColor(c2);
|
|
1329
|
-
if (!color1 && !color2) return 'unset';
|
|
1330
|
-
if (color1 && !color2) return color1;
|
|
1331
|
-
if (!color1 && color2) return color2;
|
|
1332
|
-
if (color1 === '#FFFFFF') return color2;
|
|
1333
|
-
if (color2 === '#FFFFFF') return color1;
|
|
1334
|
-
const validRatio = Math.max(Math.min(Number(ratio), 1), 0);
|
|
1335
|
-
let r1 = parseInt(color1.substring(1, 3), 16);
|
|
1336
|
-
let g1 = parseInt(color1.substring(3, 5), 16);
|
|
1337
|
-
let b1 = parseInt(color1.substring(5, 7), 16);
|
|
1338
|
-
let r2 = parseInt(color2.substring(1, 3), 16);
|
|
1339
|
-
let g2 = parseInt(color2.substring(3, 5), 16);
|
|
1340
|
-
let b2 = parseInt(color2.substring(5, 7), 16);
|
|
1341
|
-
let r = Math.round(r1 * (1 - validRatio) + r2 * validRatio);
|
|
1342
|
-
let g = Math.round(g1 * (1 - validRatio) + g2 * validRatio);
|
|
1343
|
-
let b = Math.round(b1 * (1 - validRatio) + b2 * validRatio);
|
|
1344
|
-
r = ('0' + (r || 0).toString(16)).slice(-2);
|
|
1345
|
-
g = ('0' + (g || 0).toString(16)).slice(-2);
|
|
1346
|
-
b = ('0' + (b || 0).toString(16)).slice(-2);
|
|
1347
|
-
return '#' + r + g + b;
|
|
1348
|
-
};
|
|
1349
|
-
exports.colorBlend = colorBlend;
|
|
1350
|
-
const getRowHeight = (element, rowIndex) => {
|
|
1351
|
-
const {
|
|
1352
|
-
style = {}
|
|
1353
|
-
} = element;
|
|
1354
|
-
const rowHeight = style[_constants3.TABLE_ROW_STYLE.MIN_HEIGHT] || _constants3.TABLE_ROW_MIN_HEIGHT;
|
|
1355
|
-
return rowIndex === 0 ? rowHeight + 1 : rowHeight;
|
|
1356
|
-
};
|
|
1357
|
-
exports.getRowHeight = getRowHeight;
|
|
1358
|
-
const getRowDomHeight = (editor, row) => {
|
|
1359
|
-
let height = 0;
|
|
1360
|
-
for (const cell of row.children) {
|
|
1361
|
-
const {
|
|
1362
|
-
is_combined,
|
|
1363
|
-
rowspan = 1
|
|
1364
|
-
} = cell;
|
|
1365
|
-
if (is_combined || rowspan > 1) continue;
|
|
1366
|
-
let cellDom = null;
|
|
1367
|
-
try {
|
|
1368
|
-
cellDom = _slateReact.ReactEditor.toDOMNode(editor, cell);
|
|
1369
|
-
} catch (error) {
|
|
1370
|
-
if (!cellDom) break;
|
|
1371
|
-
}
|
|
1372
|
-
height = cellDom.getBoundingClientRect().height;
|
|
1373
|
-
break;
|
|
1374
|
-
}
|
|
1375
|
-
// if the row is empty, get the height from style
|
|
1376
|
-
if (!height) {
|
|
1377
|
-
height = row.style[_constants3.TABLE_ROW_STYLE.MIN_HEIGHT] || _constants3.TABLE_ROW_MIN_HEIGHT;
|
|
1378
|
-
}
|
|
1379
|
-
return height;
|
|
1380
|
-
};
|
|
1381
|
-
exports.getRowDomHeight = getRowDomHeight;
|
|
1382
|
-
const normalizeTableCell = (editor, cell) => {
|
|
1383
|
-
if (!cell) return generateTableCell(editor);
|
|
1384
|
-
let newCell = {
|
|
1385
|
-
children: [{
|
|
1386
|
-
text: '',
|
|
1387
|
-
id: _slugid.default.nice()
|
|
1388
|
-
}],
|
|
1389
|
-
...cell
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
// normalize cell children
|
|
1393
|
-
let newCellChildren = [];
|
|
1394
|
-
newCell.children.forEach(cellChild => {
|
|
1395
|
-
const cellChildType = cellChild.type;
|
|
1396
|
-
if (cellChildType === _constants2.ELEMENT_TYPE.PARAGRAPH) {
|
|
1397
|
-
newCellChildren.push(...cellChild.children);
|
|
1398
|
-
} else {
|
|
1399
|
-
newCellChildren.push(cellChild);
|
|
1400
|
-
}
|
|
1401
|
-
});
|
|
1402
|
-
newCell.children = newCellChildren.map(item => {
|
|
1403
|
-
if (item.BOLD) {
|
|
1404
|
-
item.bold = item.BOLD;
|
|
1405
|
-
delete item['BOLD'];
|
|
1406
|
-
}
|
|
1407
|
-
if (item.ITALIC) {
|
|
1408
|
-
item.italic = item.ITALIC;
|
|
1409
|
-
delete item['ITALIC'];
|
|
1410
|
-
}
|
|
1411
|
-
return item;
|
|
1412
|
-
});
|
|
1413
|
-
|
|
1414
|
-
// normalize cell style
|
|
1415
|
-
if (newCell.data) {
|
|
1416
|
-
const cellStyle = {
|
|
1417
|
-
...newCell.data
|
|
1418
|
-
};
|
|
1419
|
-
delete newCell['data'];
|
|
1420
|
-
Object.keys(cellStyle).forEach(cellStyleKey => {
|
|
1421
|
-
if (cellStyleKey === 'align') {
|
|
1422
|
-
cellStyle['text_align'] = cellStyle['align'];
|
|
1423
|
-
delete cellStyle['align'];
|
|
1424
|
-
}
|
|
1425
|
-
});
|
|
1426
|
-
newCell.style = cellStyle;
|
|
1427
|
-
}
|
|
1428
|
-
return newCell;
|
|
1429
|
-
};
|
|
1430
|
-
const normalizeTableELement = (editor, element) => {
|
|
1431
|
-
if (element.type !== _constants2.ELEMENT_TYPE.TABLE) {
|
|
1432
|
-
const size = [element.children.length, element.children[0].children.length];
|
|
1433
|
-
return generateEmptyTable(editor, {
|
|
1434
|
-
size
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
let newElement = {
|
|
1438
|
-
...element
|
|
1439
|
-
};
|
|
1440
|
-
for (let i = 0; i < element.children.length; i++) {
|
|
1441
|
-
const row = newElement.children[i];
|
|
1442
|
-
for (let j = 0; j < row.children.length; j++) {
|
|
1443
|
-
row.children[j] = normalizeTableCell(editor, row.children[j]);
|
|
1444
|
-
}
|
|
1445
|
-
newElement.children[i] = row;
|
|
1446
|
-
}
|
|
1447
|
-
return newElement;
|
|
1448
|
-
};
|
|
1449
|
-
exports.normalizeTableELement = normalizeTableELement;
|
|
1450
|
-
const insertTableByTemplate = (editor, alternateColor) => {
|
|
1451
|
-
const size = [4, 4];
|
|
1452
|
-
const tableNode = generateEmptyTable(editor, {
|
|
1453
|
-
size,
|
|
1454
|
-
alternate_highlight_color: alternateColor,
|
|
1455
|
-
alternate_highlight: true
|
|
1456
|
-
});
|
|
1457
|
-
const path = _slate.Editor.path(editor, editor.selection);
|
|
1458
|
-
const insertPosition = getInsertPosition(editor);
|
|
1459
|
-
handleInsertTable(editor, insertPosition, path, tableNode);
|
|
1460
|
-
};
|
|
1461
|
-
|
|
1462
|
-
/**
|
|
1463
|
-
* @param {Editor} editor
|
|
1464
|
-
* @param {InsertPosition} insertPosition
|
|
1465
|
-
* @param {Path} path
|
|
1466
|
-
* @param {Node} tableNode
|
|
1467
|
-
* Insert table by insertPosition
|
|
1468
|
-
*/
|
|
1469
|
-
exports.insertTableByTemplate = insertTableByTemplate;
|
|
1470
|
-
const handleInsertTable = (editor, insertPosition, path, tableNode) => {
|
|
1471
|
-
const {
|
|
1472
|
-
selection
|
|
1473
|
-
} = editor;
|
|
1474
|
-
if (insertPosition === _constants2.INSERT_POSITION.BEFORE) {
|
|
1475
|
-
const insertPath = [path[0]];
|
|
1476
|
-
_slate.Transforms.insertNodes(editor, tableNode, {
|
|
1477
|
-
at: insertPath
|
|
1478
|
-
});
|
|
1479
|
-
} else if (insertPosition === _constants2.INSERT_POSITION.AFTER) {
|
|
1480
|
-
const insertPath = [path[0] + 1];
|
|
1481
|
-
_slate.Transforms.insertNodes(editor, tableNode, {
|
|
1482
|
-
at: insertPath
|
|
1483
|
-
});
|
|
1484
|
-
} else if (insertPosition === _constants2.INSERT_POSITION.CURRENT) {
|
|
1485
|
-
_slate.Transforms.splitNodes(editor, {
|
|
1486
|
-
at: selection,
|
|
1487
|
-
always: true
|
|
1488
|
-
});
|
|
1489
|
-
_slate.Transforms.insertNodes(editor, tableNode, {
|
|
1490
|
-
at: selection.anchor
|
|
1491
|
-
});
|
|
1492
|
-
}
|
|
1493
|
-
_slateReact.ReactEditor.focus(editor);
|
|
1494
|
-
};
|
|
1495
|
-
exports.handleInsertTable = handleInsertTable;
|
|
1496
|
-
const getInsertPosition = editor => {
|
|
1497
|
-
const {
|
|
1498
|
-
selection
|
|
1499
|
-
} = editor;
|
|
1500
|
-
if (!selection) return _constants2.INSERT_POSITION.CURRENT;
|
|
1501
|
-
if (!_slate.Range.isCollapsed(selection)) return _constants2.INSERT_POSITION.CURRENT;
|
|
1502
|
-
const aboveNodeEntry = (0, _core.getAboveBlockNode)(editor);
|
|
1503
|
-
if (!aboveNodeEntry) return _constants2.INSERT_POSITION.CURRENT;
|
|
1504
|
-
const isAtStart = _slate.Editor.isStart(editor, selection.anchor, aboveNodeEntry[1]);
|
|
1505
|
-
if (isAtStart) return _constants2.INSERT_POSITION.BEFORE;
|
|
1506
|
-
const isAtEnd = _slate.Editor.isEnd(editor, selection.anchor, aboveNodeEntry[1]);
|
|
1507
|
-
if (isAtEnd) return _constants2.INSERT_POSITION.AFTER;
|
|
1508
|
-
return _constants2.INSERT_POSITION.CURRENT;
|
|
1509
|
-
};
|
|
1510
|
-
exports.getInsertPosition = getInsertPosition;
|
|
1511
|
-
const generateInheritStyle = (allowedInheritStyleList, style, cell) => {
|
|
1512
|
-
const inheritStyle = {
|
|
1513
|
-
...cell['inherit_style']
|
|
1514
|
-
} || {};
|
|
1515
|
-
for (const key in style) {
|
|
1516
|
-
if (Object.hasOwnProperty.call(style, key) && allowedInheritStyleList.includes(key)) {
|
|
1517
|
-
inheritStyle[key] = style[key];
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
return inheritStyle;
|
|
1521
|
-
};
|
|
1522
|
-
exports.generateInheritStyle = generateInheritStyle;
|
|
1523
|
-
const getCellInheritStyles = (editor, tablePath, rowIndex, colIndex) => {
|
|
1524
|
-
var _table$children$rowIn, _tableCell$inherit_st;
|
|
1525
|
-
const [tableNodeEntry] = _slate.Editor.nodes(editor, {
|
|
1526
|
-
match: n => n.type === _constants2.ELEMENT_TYPE.TABLE,
|
|
1527
|
-
at: tablePath
|
|
1528
|
-
});
|
|
1529
|
-
if (!tableNodeEntry) return {};
|
|
1530
|
-
const table = tableNodeEntry[0];
|
|
1531
|
-
const tableCell = (_table$children$rowIn = table.children[rowIndex]) === null || _table$children$rowIn === void 0 ? void 0 : _table$children$rowIn.children[colIndex];
|
|
1532
|
-
if (!tableCell) return {};
|
|
1533
|
-
return (_tableCell$inherit_st = tableCell['inherit_style']) !== null && _tableCell$inherit_st !== void 0 ? _tableCell$inherit_st : {};
|
|
1534
|
-
};
|
|
1535
|
-
exports.getCellInheritStyles = getCellInheritStyles;
|
|
1536
|
-
const getCellHighlightClassName = (primaryColorClassName, rowIndex) => {
|
|
1537
|
-
let className = '';
|
|
1538
|
-
if (rowIndex === 0) {
|
|
1539
|
-
className = primaryColorClassName;
|
|
1540
|
-
} else if (rowIndex % 2 === 0) {
|
|
1541
|
-
className = _constants3.TABLE_ALTERNATE_HIGHLIGHT_CLASS_MAP[primaryColorClassName];
|
|
1542
|
-
}
|
|
1543
|
-
return className;
|
|
1544
|
-
};
|
|
1545
|
-
exports.getCellHighlightClassName = getCellHighlightClassName;
|
|
1546
|
-
const focusClosestCellWhenJustifyCellSize = (editor, adjustingCell) => {
|
|
1547
|
-
const cellPath = _slateReact.ReactEditor.findPath(editor, adjustingCell);
|
|
1548
|
-
(0, _core.focusEditor)(editor, _slate.Editor.end(editor, cellPath));
|
|
1549
|
-
};
|
|
1550
|
-
|
|
1551
|
-
// Search main cell of combined cell
|
|
1552
|
-
exports.focusClosestCellWhenJustifyCellSize = focusClosestCellWhenJustifyCellSize;
|
|
1553
|
-
const searchCombinedMainCell = (table, startRowIndex, startColIndex) => {
|
|
1554
|
-
for (let rowIndex = startRowIndex; rowIndex >= 0; rowIndex--) {
|
|
1555
|
-
const row = table.children[rowIndex];
|
|
1556
|
-
for (let cellIndex = startColIndex; cellIndex >= 0; cellIndex--) {
|
|
1557
|
-
const currentCell = row.children[cellIndex];
|
|
1558
|
-
const {
|
|
1559
|
-
colspan = 0,
|
|
1560
|
-
rowspan = 0
|
|
1561
|
-
} = currentCell;
|
|
1562
|
-
if (colspan <= 1 && rowspan <= 1) continue;
|
|
1563
|
-
const isInColRange = cellIndex + colspan >= startColIndex;
|
|
1564
|
-
const isInRowRange = rowIndex + rowspan >= startRowIndex;
|
|
1565
|
-
if (isInColRange && isInRowRange) {
|
|
1566
|
-
return {
|
|
1567
|
-
currentCell,
|
|
1568
|
-
rowIndex,
|
|
1569
|
-
cellIndex
|
|
1570
|
-
};
|
|
1571
|
-
} else break;
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
const getResizeMaskCellInfo = (editor, table, rowIndex, cellIndex) => {
|
|
1576
|
-
// The cell shown cursor as resize (mouse is on this cell)
|
|
1577
|
-
const focusCellIndex = cellIndex;
|
|
1578
|
-
let focusCell = table.children[rowIndex].children[cellIndex];
|
|
1579
|
-
// The cell dominating resize handlers (the true cell to be resized)
|
|
1580
|
-
let cell = table.children[rowIndex].children[cellIndex];
|
|
1581
|
-
// Resolve combined cell
|
|
1582
|
-
if (cell.is_combined) {
|
|
1583
|
-
const targetCellInfo = searchCombinedMainCell(table, rowIndex, cellIndex);
|
|
1584
|
-
cellIndex = targetCellInfo.cellIndex;
|
|
1585
|
-
rowIndex = targetCellInfo.rowIndex;
|
|
1586
|
-
cell = targetCellInfo.currentCell;
|
|
1587
|
-
}
|
|
1588
|
-
const columns = table.columns;
|
|
1589
|
-
const focussedCell = _slateReact.ReactEditor.toDOMNode(editor, cell);
|
|
1590
|
-
const {
|
|
1591
|
-
colspan,
|
|
1592
|
-
rowspan
|
|
1593
|
-
} = focusCell;
|
|
1594
|
-
let width = columns[cellIndex].width;
|
|
1595
|
-
let height = focussedCell.getBoundingClientRect().height;
|
|
1596
|
-
// Calculate cell width and height
|
|
1597
|
-
if (colspan > 1) {
|
|
1598
|
-
let index = cellIndex + 1;
|
|
1599
|
-
while (index < cellIndex + colspan) {
|
|
1600
|
-
width += columns[index].width;
|
|
1601
|
-
index++;
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
if (rowspan > 1) {
|
|
1605
|
-
let index = rowIndex + 1;
|
|
1606
|
-
while (index < rowIndex + rowspan) {
|
|
1607
|
-
const currentCell = table.children[index].children[cellIndex];
|
|
1608
|
-
const currentHeight = _slateReact.ReactEditor.toDOMNode(editor, currentCell).getBoundingClientRect().height;
|
|
1609
|
-
height += currentHeight;
|
|
1610
|
-
index++;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
return {
|
|
1614
|
-
width,
|
|
1615
|
-
height,
|
|
1616
|
-
top: focussedCell.offsetTop,
|
|
1617
|
-
left: focussedCell.offsetLeft,
|
|
1618
|
-
rowIndex,
|
|
1619
|
-
cellIndex,
|
|
1620
|
-
cell,
|
|
1621
|
-
focusCellIndex
|
|
1622
|
-
};
|
|
1623
|
-
};
|
|
1624
|
-
|
|
1625
|
-
// Table alternate highlight
|
|
1626
|
-
exports.getResizeMaskCellInfo = getResizeMaskCellInfo;
|
|
1627
|
-
const getHighlightClass = (editor, cellPath) => {
|
|
1628
|
-
var _tableEntry$;
|
|
1629
|
-
const [tableEntry] = _slate.Editor.nodes(editor, {
|
|
1630
|
-
at: cellPath,
|
|
1631
|
-
match: n => n.type === _constants2.ELEMENT_TYPE.TABLE
|
|
1632
|
-
});
|
|
1633
|
-
const {
|
|
1634
|
-
alternate_highlight,
|
|
1635
|
-
alternate_highlight_color
|
|
1636
|
-
} = ((_tableEntry$ = tableEntry[0]) === null || _tableEntry$ === void 0 ? void 0 : _tableEntry$.ui) || {};
|
|
1637
|
-
if (!alternate_highlight) return '';
|
|
1638
|
-
const rowIndex = cellPath[cellPath.length - 2];
|
|
1639
|
-
const className = getCellHighlightClassName(alternate_highlight_color, rowIndex);
|
|
1640
|
-
return className;
|
|
1641
|
-
};
|
|
1642
|
-
|
|
1643
|
-
// Correct the selected range when combined cell are selected
|
|
1644
|
-
exports.getHighlightClass = getHighlightClass;
|
|
1645
|
-
const adjustCombinedCellRange = (table, range) => {
|
|
1646
|
-
const {
|
|
1647
|
-
minRowIndex,
|
|
1648
|
-
maxRowIndex,
|
|
1649
|
-
minColIndex,
|
|
1650
|
-
maxColIndex
|
|
1651
|
-
} = range;
|
|
1652
|
-
const firstCell = table.children[minRowIndex].children[minColIndex];
|
|
1653
|
-
const {
|
|
1654
|
-
colspan = 0,
|
|
1655
|
-
rowspan = 0
|
|
1656
|
-
} = firstCell;
|
|
1657
|
-
if (rowspan > 1 || colspan > 1) {
|
|
1658
|
-
const isRowCombined = minRowIndex + rowspan === maxRowIndex + 1;
|
|
1659
|
-
const isColCombined = minColIndex + colspan === maxColIndex + 1;
|
|
1660
|
-
if (isRowCombined && isColCombined) return _constants3.EMPTY_SELECTED_RANGE;
|
|
1661
|
-
}
|
|
1662
|
-
return range;
|
|
1663
|
-
};
|
|
1664
|
-
|
|
1665
|
-
/**
|
|
1666
|
-
* Do not reset table selected range, when drag table column / row
|
|
1667
|
-
* @param {MouseEvent} event
|
|
1668
|
-
* @returns {Boolean}
|
|
1669
|
-
*/
|
|
1670
|
-
exports.adjustCombinedCellRange = adjustCombinedCellRange;
|
|
1671
|
-
const isPreventResetTableSelectedRange = event => {
|
|
1672
|
-
const {
|
|
1673
|
-
target
|
|
1674
|
-
} = event;
|
|
1675
|
-
const draggable = target.getAttribute('draggable');
|
|
1676
|
-
const isColumnHeader = target.classList.contains('sdoc-table-column-header');
|
|
1677
|
-
const isRowHeader = target.classList.contains('sdoc-table-row-header');
|
|
1678
|
-
const isHeader = isColumnHeader || isRowHeader;
|
|
1679
|
-
const isPreventReset = isHeader || draggable === 'true';
|
|
1680
|
-
return isPreventReset;
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
/**
|
|
1684
|
-
* Check drag type, column or row
|
|
1685
|
-
*/
|
|
1686
|
-
exports.isPreventResetTableSelectedRange = isPreventResetTableSelectedRange;
|
|
1687
|
-
const getTableDragType = (table, selectedRange) => {
|
|
1688
|
-
const rowCount = table.children.length;
|
|
1689
|
-
const {
|
|
1690
|
-
minRowIndex,
|
|
1691
|
-
maxRowIndex
|
|
1692
|
-
} = selectedRange;
|
|
1693
|
-
const isSelectColumn = minRowIndex === 0 && maxRowIndex === rowCount - 1;
|
|
1694
|
-
return isSelectColumn ? _constants3.DRAG_HANDLER_COLUMN : _constants3.DRAG_HANDLER_ROW;
|
|
1695
|
-
};
|
|
1696
|
-
exports.getTableDragType = getTableDragType;
|
|
1697
|
-
const updateTableColumns = (editor, table, targetColIndex, startColIndex, endColIndex) => {
|
|
1698
|
-
const columns = [...table.columns];
|
|
1699
|
-
const deleteCount = endColIndex - startColIndex + 1;
|
|
1700
|
-
const newColumns = columns.splice(startColIndex, deleteCount);
|
|
1701
|
-
columns.splice(targetColIndex, 0, ...newColumns);
|
|
1702
|
-
updateColumnWidth(editor, table, columns);
|
|
1703
|
-
};
|
|
1704
|
-
const moveColumns = (editor, targetColIndex, startColIndex, endColIndex) => {
|
|
1705
|
-
// Get selected table information
|
|
1706
|
-
const {
|
|
1707
|
-
table,
|
|
1708
|
-
tablePath
|
|
1709
|
-
} = getSelectedInfo(editor);
|
|
1710
|
-
// Check if moving columns forward or backward
|
|
1711
|
-
const isMoveToFroward = targetColIndex < startColIndex;
|
|
1712
|
-
|
|
1713
|
-
// Iterate over each row in the table
|
|
1714
|
-
table.children.forEach((row, rowIndex) => {
|
|
1715
|
-
if (isMoveToFroward) {
|
|
1716
|
-
// Calculate target and source paths for moving columns forward
|
|
1717
|
-
const targetPath = [...tablePath, rowIndex, targetColIndex];
|
|
1718
|
-
const sourcePath = [...tablePath, rowIndex, endColIndex];
|
|
1719
|
-
|
|
1720
|
-
// Move columns forward by inserting nodes
|
|
1721
|
-
for (let insertIndex = endColIndex; insertIndex >= startColIndex; insertIndex--) {
|
|
1722
|
-
const insertNode = row.children[insertIndex];
|
|
1723
|
-
_slate.Transforms.removeNodes(editor, {
|
|
1724
|
-
at: sourcePath
|
|
1725
|
-
});
|
|
1726
|
-
_slate.Transforms.insertNodes(editor, insertNode, {
|
|
1727
|
-
at: targetPath
|
|
1728
|
-
});
|
|
1729
|
-
}
|
|
1730
|
-
} else {
|
|
1731
|
-
// Calculate target and source paths for moving columns backward
|
|
1732
|
-
const targetPath = [...tablePath, rowIndex, targetColIndex - 1];
|
|
1733
|
-
const sourcePath = [...tablePath, rowIndex, startColIndex];
|
|
1734
|
-
|
|
1735
|
-
// Move columns backward by inserting nodes
|
|
1736
|
-
for (let insertIndex = startColIndex; insertIndex <= endColIndex; insertIndex++) {
|
|
1737
|
-
const insertNode = row.children[insertIndex];
|
|
1738
|
-
_slate.Transforms.removeNodes(editor, {
|
|
1739
|
-
at: sourcePath
|
|
1740
|
-
});
|
|
1741
|
-
_slate.Transforms.insertNodes(editor, insertNode, {
|
|
1742
|
-
at: targetPath
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
});
|
|
1747
|
-
|
|
1748
|
-
// Update table columns after moving
|
|
1749
|
-
updateTableColumns(editor, table, targetColIndex, startColIndex, endColIndex);
|
|
1750
|
-
|
|
1751
|
-
// Set new selected range after moving columns
|
|
1752
|
-
const newSelectRange = {
|
|
1753
|
-
minRowIndex: 0,
|
|
1754
|
-
maxRowIndex: table.children.length - 1,
|
|
1755
|
-
minColIndex: targetColIndex,
|
|
1756
|
-
maxColIndex: targetColIndex + endColIndex - startColIndex
|
|
1757
|
-
};
|
|
1758
|
-
setTableSelectedRange(editor, newSelectRange);
|
|
1759
|
-
};
|
|
1760
|
-
|
|
1761
|
-
/**
|
|
1762
|
-
* Calculate the new selected range after dragging a column or row in the table.
|
|
1763
|
-
* @param {Object} table - The table object containing columns and rows.
|
|
1764
|
-
* @param {string} moveType - The type of drag operation (DRAG_HANDLER_COLUMN for column, DRAG_HANDLER_ROW for row).
|
|
1765
|
-
* @param {number} targetIndex - The index of the target column or row after dragging.
|
|
1766
|
-
* @param {number} startIndex - The index of the starting column or row before dragging.
|
|
1767
|
-
* @param {number} endIndex - The index of the ending column or row before dragging.
|
|
1768
|
-
* @returns {Object} - The new selected range after the drag operation.
|
|
1769
|
-
*/
|
|
1770
|
-
exports.moveColumns = moveColumns;
|
|
1771
|
-
const getTableSelectedRangeAfterDrag = (table, moveType, targetIndex, startIndex, endIndex) => {
|
|
1772
|
-
// Calculate the total number of columns and rows in the table
|
|
1773
|
-
const colCount = table.columns.length;
|
|
1774
|
-
const rowCount = table.children.length;
|
|
1775
|
-
|
|
1776
|
-
// Initialize the new selected range with full table range
|
|
1777
|
-
const newSelectRange = {
|
|
1778
|
-
minRowIndex: 0,
|
|
1779
|
-
maxRowIndex: rowCount - 1,
|
|
1780
|
-
minColIndex: 0,
|
|
1781
|
-
maxColIndex: colCount - 1
|
|
1782
|
-
};
|
|
1783
|
-
|
|
1784
|
-
// Determine if the drag movement is forward or backward
|
|
1785
|
-
const isMoveToFroward = targetIndex < startIndex;
|
|
1786
|
-
|
|
1787
|
-
// Adjust selected range based on the type of drag operation
|
|
1788
|
-
if (moveType === _constants3.DRAG_HANDLER_COLUMN) {
|
|
1789
|
-
if (isMoveToFroward) {
|
|
1790
|
-
newSelectRange.minColIndex = targetIndex;
|
|
1791
|
-
newSelectRange.maxColIndex = targetIndex + endIndex - startIndex;
|
|
1792
|
-
} else {
|
|
1793
|
-
const moveCount = endIndex - startIndex + 1;
|
|
1794
|
-
newSelectRange.minColIndex = targetIndex - moveCount;
|
|
1795
|
-
newSelectRange.maxColIndex = targetIndex - 1;
|
|
1796
|
-
}
|
|
1797
|
-
} else {
|
|
1798
|
-
if (isMoveToFroward) {
|
|
1799
|
-
newSelectRange.minRowIndex = targetIndex;
|
|
1800
|
-
newSelectRange.maxRowIndex = targetIndex + endIndex - startIndex;
|
|
1801
|
-
} else {
|
|
1802
|
-
const moveCount = endIndex - startIndex + 1;
|
|
1803
|
-
newSelectRange.minRowIndex = targetIndex - moveCount;
|
|
1804
|
-
newSelectRange.maxRowIndex = targetIndex - 1;
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
return newSelectRange;
|
|
1808
|
-
};
|
|
1809
|
-
exports.getTableSelectedRangeAfterDrag = getTableSelectedRangeAfterDrag;
|
|
1810
|
-
const moveRows = (editor, targetRowIndex, startRowIndex, endRowIndex) => {
|
|
1811
|
-
const {
|
|
1812
|
-
table,
|
|
1813
|
-
tablePath
|
|
1814
|
-
} = getSelectedInfo(editor);
|
|
1815
|
-
const isMoveToFroward = targetRowIndex < startRowIndex;
|
|
1816
|
-
const targetPath = [...tablePath, isMoveToFroward ? targetRowIndex : targetRowIndex - 1];
|
|
1817
|
-
const sourcePath = [...tablePath, isMoveToFroward ? endRowIndex : startRowIndex];
|
|
1818
|
-
if (isMoveToFroward) {
|
|
1819
|
-
for (let insertIndex = endRowIndex; insertIndex >= startRowIndex; insertIndex--) {
|
|
1820
|
-
const insertNode = table.children[insertIndex];
|
|
1821
|
-
_slate.Transforms.removeNodes(editor, {
|
|
1822
|
-
at: sourcePath
|
|
1823
|
-
});
|
|
1824
|
-
_slate.Transforms.insertNodes(editor, insertNode, {
|
|
1825
|
-
at: targetPath
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
} else {
|
|
1829
|
-
for (let insertIndex = startRowIndex; insertIndex <= endRowIndex; insertIndex++) {
|
|
1830
|
-
const insertNode = table.children[insertIndex];
|
|
1831
|
-
_slate.Transforms.removeNodes(editor, {
|
|
1832
|
-
at: sourcePath
|
|
1833
|
-
});
|
|
1834
|
-
_slate.Transforms.insertNodes(editor, insertNode, {
|
|
1835
|
-
at: targetPath
|
|
1836
|
-
});
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
const newSelectRange = {
|
|
1840
|
-
minRowIndex: targetRowIndex,
|
|
1841
|
-
maxRowIndex: targetRowIndex + endRowIndex - startRowIndex,
|
|
1842
|
-
minColIndex: 0,
|
|
1843
|
-
maxColIndex: table.children.length - 1
|
|
1844
|
-
};
|
|
1845
|
-
setTableSelectedRange(editor, newSelectRange);
|
|
1846
|
-
};
|
|
1847
|
-
exports.moveRows = moveRows;
|
|
1848
|
-
const generateDragMoveElement = tipText => {
|
|
1849
|
-
const canvasId = 'sdoc-drag-image';
|
|
1850
|
-
let canvas = document.getElementById(canvasId);
|
|
1851
|
-
if (!canvas) {
|
|
1852
|
-
let dpr = window.devicePixelRatio;
|
|
1853
|
-
canvas = document.createElement('canvas');
|
|
1854
|
-
canvas.width = 115;
|
|
1855
|
-
canvas.height = 30;
|
|
1856
|
-
canvas.id = canvasId;
|
|
1857
|
-
document.body.appendChild(canvas);
|
|
1858
|
-
let {
|
|
1859
|
-
width: cssWidth,
|
|
1860
|
-
height: cssHeight
|
|
1861
|
-
} = canvas.getBoundingClientRect();
|
|
1862
|
-
canvas.style.width = canvas.width + 'px';
|
|
1863
|
-
canvas.style.height = canvas.height + 'px';
|
|
1864
|
-
canvas.width = dpr * cssWidth;
|
|
1865
|
-
canvas.height = dpr * cssHeight;
|
|
1866
|
-
canvas.style.position = 'fixed';
|
|
1867
|
-
}
|
|
1868
|
-
canvas.style.display = 'block';
|
|
1869
|
-
const context = canvas.getContext('2d');
|
|
1870
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
1871
|
-
context.fillStyle = 'rgb(241,243,246)';
|
|
1872
|
-
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
1873
|
-
context.font = '22px Arial';
|
|
1874
|
-
context.textBaseline = 'middle';
|
|
1875
|
-
context.textAlign = 'center';
|
|
1876
|
-
context.fillStyle = 'black';
|
|
1877
|
-
context.fillText(tipText, canvas.width / 2, canvas.height / 2);
|
|
1878
|
-
return canvas;
|
|
1879
|
-
};
|
|
1880
|
-
exports.generateDragMoveElement = generateDragMoveElement;
|
|
1881
|
-
const isHideDragHandlerLine = (editor, displayType, table, cellPath, isDragOverCellHalf) => {
|
|
1882
|
-
const pathLength = cellPath.length;
|
|
1883
|
-
let rowIndex = cellPath[pathLength - 2];
|
|
1884
|
-
let cellIndex = cellPath[pathLength - 1];
|
|
1885
|
-
|
|
1886
|
-
// Check is above cell selected
|
|
1887
|
-
let currentCellDom = _slateReact.ReactEditor.toDOMNode(editor, table.children[rowIndex].children[cellIndex]);
|
|
1888
|
-
let isCurrentCellSelected = currentCellDom.classList.contains(_constants3.CELL_SELECTED);
|
|
1889
|
-
if (isCurrentCellSelected) return true;
|
|
1890
|
-
if (isDragOverCellHalf) {
|
|
1891
|
-
if (displayType === _constants3.DRAG_HANDLER_COLUMN) {
|
|
1892
|
-
cellIndex = cellIndex + 1;
|
|
1893
|
-
} else {
|
|
1894
|
-
rowIndex = rowIndex + 1;
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
const isEndOfRowOrColumn = displayType === _constants3.DRAG_HANDLER_COLUMN && cellIndex === table.columns.length || displayType === _constants3.DRAG_HANDLER_ROW && rowIndex === table.children.length;
|
|
1898
|
-
if (isEndOfRowOrColumn) return false;
|
|
1899
|
-
let preCellDom = null;
|
|
1900
|
-
if (displayType === _constants3.DRAG_HANDLER_COLUMN && cellIndex > 0) {
|
|
1901
|
-
const prevCell = table.children[rowIndex].children[cellIndex - 1];
|
|
1902
|
-
preCellDom = _slateReact.ReactEditor.toDOMNode(editor, prevCell);
|
|
1903
|
-
|
|
1904
|
-
// Check if there are merged cells in the columns before and after the drag line
|
|
1905
|
-
const beforeLineColumnHasCombined = table.children.find(item => {
|
|
1906
|
-
const cell = item.children[cellIndex - 1];
|
|
1907
|
-
return cell.children.length > 1;
|
|
1908
|
-
});
|
|
1909
|
-
const afterLineColumnHasCombined = table.children.find(item => {
|
|
1910
|
-
const cell = item.children[cellIndex];
|
|
1911
|
-
return (cell === null || cell === void 0 ? void 0 : cell.is_combined) === true;
|
|
1912
|
-
});
|
|
1913
|
-
if (beforeLineColumnHasCombined && afterLineColumnHasCombined) return true;
|
|
1914
|
-
} else if (displayType === _constants3.DRAG_HANDLER_ROW && rowIndex > 0) {
|
|
1915
|
-
const prevCell = table.children[rowIndex - 1].children[cellIndex];
|
|
1916
|
-
preCellDom = _slateReact.ReactEditor.toDOMNode(editor, prevCell);
|
|
1917
|
-
|
|
1918
|
-
// Check whether there are merged cells in the rows before and after the drag line
|
|
1919
|
-
const beforeLineRow = table.children[rowIndex - 1];
|
|
1920
|
-
const afterLineRow = table.children[rowIndex];
|
|
1921
|
-
const beforeLineRowHasCombined = beforeLineRow.children.find(item => item.children.length > 1);
|
|
1922
|
-
const afterLineRowHasCombined = afterLineRow.children.find(item => (item === null || item === void 0 ? void 0 : item.is_combined) === true);
|
|
1923
|
-
if (beforeLineRowHasCombined && afterLineRowHasCombined) return true;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
// Check is above cell selected
|
|
1927
|
-
currentCellDom = _slateReact.ReactEditor.toDOMNode(editor, table.children[rowIndex].children[cellIndex]);
|
|
1928
|
-
isCurrentCellSelected = currentCellDom.classList.contains(_constants3.CELL_SELECTED);
|
|
1929
|
-
if (isCurrentCellSelected) return true;
|
|
1930
|
-
|
|
1931
|
-
// Check if the previous cell is selected
|
|
1932
|
-
const isPrevCellSelected = preCellDom && preCellDom.classList.contains(_constants3.CELL_SELECTED);
|
|
1933
|
-
if (isPrevCellSelected) return true;
|
|
1934
|
-
let isCombined = false;
|
|
1935
|
-
// Check if the combined cell
|
|
1936
|
-
if (displayType === _constants3.DRAG_HANDLER_COLUMN) {
|
|
1937
|
-
isCombined = table.children.some(row => row.children[cellIndex - isDragOverCellHalf].is_combined);
|
|
1938
|
-
} else {
|
|
1939
|
-
isCombined = table.children[rowIndex - isDragOverCellHalf].children.some(cell => cell.is_combined);
|
|
1940
|
-
}
|
|
1941
|
-
if (isCombined) return true;
|
|
1942
|
-
|
|
1943
|
-
// Check is the last column
|
|
1944
|
-
if (displayType === _constants3.DRAG_HANDLER_COLUMN) {
|
|
1945
|
-
const isLastColumn = cellIndex === table.columns.length - 1;
|
|
1946
|
-
if (isLastColumn) return false;
|
|
1947
|
-
}
|
|
1948
|
-
};
|
|
1949
|
-
exports.isHideDragHandlerLine = isHideDragHandlerLine;
|
|
1950
|
-
const getTableRowSelectedRange = (table, rowIndex) => {
|
|
1951
|
-
const row = table.children[rowIndex];
|
|
1952
|
-
const columnCount = row.children.length;
|
|
1953
|
-
let minRowIndex = rowIndex;
|
|
1954
|
-
let maxRowIndex = rowIndex;
|
|
1955
|
-
let minColIndex = 0;
|
|
1956
|
-
let maxColIndex = columnCount - 1;
|
|
1957
|
-
const findRowRange = findRowIndex => {
|
|
1958
|
-
let checkRow = table.children[findRowIndex];
|
|
1959
|
-
const combinedIndexes = checkRow.children.reduce((acc, cell, index) => {
|
|
1960
|
-
if (cell.is_combined) acc.push(index);
|
|
1961
|
-
if (cell.rowspan > 1) {
|
|
1962
|
-
maxRowIndex = Math.max(maxRowIndex, findRowIndex + cell.rowspan - 1);
|
|
1963
|
-
findRowRange(maxRowIndex);
|
|
1964
|
-
}
|
|
1965
|
-
return acc;
|
|
1966
|
-
}, []);
|
|
1967
|
-
combinedIndexes.some(combinedIndex => {
|
|
1968
|
-
const {
|
|
1969
|
-
rowIndex: mainCellRowIndex,
|
|
1970
|
-
currentCell
|
|
1971
|
-
} = searchCombinedMainCell(table, findRowIndex, combinedIndex);
|
|
1972
|
-
if (minRowIndex > mainCellRowIndex) {
|
|
1973
|
-
minRowIndex = mainCellRowIndex;
|
|
1974
|
-
findRowRange(minRowIndex, 0);
|
|
1975
|
-
return false;
|
|
1976
|
-
} else if (maxRowIndex < mainCellRowIndex + currentCell.rowspan - 1) {
|
|
1977
|
-
maxRowIndex = mainCellRowIndex + currentCell.rowspan - 1;
|
|
1978
|
-
findRowRange(maxRowIndex, 0);
|
|
1979
|
-
return false;
|
|
1980
|
-
}
|
|
1981
|
-
return false;
|
|
1982
|
-
});
|
|
1983
|
-
};
|
|
1984
|
-
findRowRange(rowIndex);
|
|
1985
|
-
return {
|
|
1986
|
-
minRowIndex,
|
|
1987
|
-
maxRowIndex,
|
|
1988
|
-
minColIndex,
|
|
1989
|
-
maxColIndex
|
|
1990
|
-
};
|
|
1991
|
-
};
|
|
1992
|
-
exports.getTableRowSelectedRange = getTableRowSelectedRange;
|
|
1993
|
-
const getTableColumnSelectedRange = (table, columnIndex) => {
|
|
1994
|
-
let minRowIndex = 0;
|
|
1995
|
-
let maxRowIndex = table.children.length - 1;
|
|
1996
|
-
let minColIndex = columnIndex;
|
|
1997
|
-
let maxColIndex = columnIndex;
|
|
1998
|
-
const findColRange = findColIndex => {
|
|
1999
|
-
let combinedIndexes = [];
|
|
2000
|
-
table.children.forEach((row, rowIndex) => {
|
|
2001
|
-
const cell = row.children[findColIndex];
|
|
2002
|
-
if (cell.is_combined) combinedIndexes.push(rowIndex);
|
|
2003
|
-
if (cell.colspan > 1) {
|
|
2004
|
-
maxColIndex = Math.max(maxColIndex, findColIndex + cell.colspan - 1);
|
|
2005
|
-
findColRange(maxColIndex);
|
|
2006
|
-
}
|
|
2007
|
-
});
|
|
2008
|
-
combinedIndexes.some(combinedIndex => {
|
|
2009
|
-
const {
|
|
2010
|
-
cellIndex: mainCellColIndex,
|
|
2011
|
-
currentCell
|
|
2012
|
-
} = searchCombinedMainCell(table, combinedIndex, findColIndex);
|
|
2013
|
-
if (minColIndex > mainCellColIndex) {
|
|
2014
|
-
minColIndex = mainCellColIndex;
|
|
2015
|
-
findColRange(minColIndex, 0);
|
|
2016
|
-
return false;
|
|
2017
|
-
} else if (maxColIndex < mainCellColIndex + currentCell.colspan - 1) {
|
|
2018
|
-
maxColIndex = mainCellColIndex + currentCell.colspan - 1;
|
|
2019
|
-
findColRange(maxColIndex, 0);
|
|
2020
|
-
return false;
|
|
2021
|
-
}
|
|
2022
|
-
return false;
|
|
2023
|
-
});
|
|
2024
|
-
};
|
|
2025
|
-
findColRange(columnIndex);
|
|
2026
|
-
return {
|
|
2027
|
-
minRowIndex,
|
|
2028
|
-
maxRowIndex,
|
|
2029
|
-
minColIndex,
|
|
2030
|
-
maxColIndex
|
|
2031
|
-
};
|
|
2032
|
-
};
|
|
2033
|
-
exports.getTableColumnSelectedRange = getTableColumnSelectedRange;
|
|
2034
|
-
const isTableWidthFitScreen = editor => {
|
|
2035
|
-
const {
|
|
2036
|
-
table
|
|
2037
|
-
} = getSelectedInfo(editor);
|
|
2038
|
-
const tableNode = _slateReact.ReactEditor.toDOMNode(editor, table);
|
|
2039
|
-
if (!tableNode) return;
|
|
2040
|
-
const tableDom = tableNode.querySelector('.sdoc-table-scroll-wrapper');
|
|
2041
|
-
const {
|
|
2042
|
-
width: tableWidth
|
|
2043
|
-
} = tableDom.getBoundingClientRect();
|
|
2044
|
-
const sdocWidth = editor.width;
|
|
2045
|
-
if (tableWidth >= sdocWidth) return true;
|
|
2046
|
-
return false;
|
|
2047
|
-
};
|
|
2048
|
-
exports.isTableWidthFitScreen = isTableWidthFitScreen;
|
|
2049
|
-
const fitTableColumnToScreen = editor => {
|
|
2050
|
-
const {
|
|
2051
|
-
table,
|
|
2052
|
-
tablePath
|
|
2053
|
-
} = getSelectedInfo(editor);
|
|
2054
|
-
const colCount = table.columns.length;
|
|
2055
|
-
const columnWidth = Math.max(_constants3.TABLE_CELL_MIN_WIDTH, parseInt(editor.width / colCount));
|
|
2056
|
-
const columns = table.columns.map(column => ({
|
|
2057
|
-
...column,
|
|
2058
|
-
width: columnWidth
|
|
2059
|
-
}));
|
|
2060
|
-
_slate.Transforms.setNodes(editor, {
|
|
2061
|
-
columns
|
|
2062
|
-
}, {
|
|
2063
|
-
at: tablePath
|
|
2064
|
-
});
|
|
2065
|
-
};
|
|
2066
|
-
exports.fitTableColumnToScreen = fitTableColumnToScreen;
|
|
2067
|
-
const deleteTableSelectCells = (editor, deleteRange) => {
|
|
2068
|
-
// eslint-disable-next-line no-unused-vars
|
|
2069
|
-
const {
|
|
2070
|
-
start,
|
|
2071
|
-
end,
|
|
2072
|
-
rowsLength,
|
|
2073
|
-
columnLength
|
|
2074
|
-
} = deleteRange;
|
|
2075
|
-
// table path [tableIdx, rowIdx, colIdx, ...];
|
|
2076
|
-
if (start.length <= 3) return;
|
|
2077
|
-
const tableIndex = start[0];
|
|
2078
|
-
const minRowIndex = start[1];
|
|
2079
|
-
let deletePaths = [];
|
|
2080
|
-
if (start[1] === end[1]) {
|
|
2081
|
-
const minColIndex = start[2];
|
|
2082
|
-
const maxColIndex = end[2];
|
|
2083
|
-
for (let colIndex = minColIndex; colIndex <= maxColIndex; colIndex++) {
|
|
2084
|
-
deletePaths.push([tableIndex, minRowIndex, colIndex]);
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
if (start[1] !== end[1]) {
|
|
2088
|
-
const isAfter = end[1] - start[1] === 1;
|
|
2089
|
-
// push first row
|
|
2090
|
-
const minColIndex = start[2];
|
|
2091
|
-
for (let colIndex = minColIndex; colIndex <= columnLength - 1; colIndex++) {
|
|
2092
|
-
deletePaths.push([tableIndex, minRowIndex, colIndex]);
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
// push center row
|
|
2096
|
-
if (!isAfter) {
|
|
2097
|
-
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
|
|
2098
|
-
for (let j = 0; j <= columnLength - 1; j++) {
|
|
2099
|
-
deletePaths.push([tableIndex, i, j]);
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
// push last row
|
|
2105
|
-
const maxColIndex = end[2];
|
|
2106
|
-
const maxRowIndex = end[1];
|
|
2107
|
-
for (let colIndex = 0; colIndex <= maxColIndex; colIndex++) {
|
|
2108
|
-
deletePaths.push([tableIndex, maxRowIndex, colIndex]);
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
for (let i = 0; i < deletePaths.length; i++) {
|
|
2112
|
-
const path = deletePaths[i];
|
|
2113
|
-
const node = (0, _core.getNode)(editor, path);
|
|
2114
|
-
const firstNode = node.children[0];
|
|
2115
|
-
(0, _core.replaceNodeChildren)(editor, {
|
|
2116
|
-
at: path,
|
|
2117
|
-
nodes: {
|
|
2118
|
-
...firstNode,
|
|
2119
|
-
text: ''
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
};
|
|
2124
|
-
exports.deleteTableSelectCells = deleteTableSelectCells;
|