@ecomcx/ecomweb-editor 0.0.0-stage → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -2
- package/node_modules/@floating-ui/core/LICENSE +20 -0
- package/node_modules/@floating-ui/core/README.md +4 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.browser.min.mjs +1 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.browser.mjs +1164 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.d.mts +535 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.d.ts +535 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js +1038 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.mjs +1038 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.umd.js +1183 -0
- package/node_modules/@floating-ui/core/dist/floating-ui.core.umd.min.js +1 -0
- package/node_modules/@floating-ui/core/package.json +63 -0
- package/node_modules/@floating-ui/dom/LICENSE +20 -0
- package/node_modules/@floating-ui/dom/README.md +4 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.browser.min.mjs +1 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.browser.mjs +964 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.d.mts +362 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.d.ts +362 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js +789 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs +789 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.umd.js +983 -0
- package/node_modules/@floating-ui/dom/dist/floating-ui.dom.umd.min.js +1 -0
- package/node_modules/@floating-ui/dom/package.json +72 -0
- package/node_modules/@floating-ui/utils/LICENSE +20 -0
- package/node_modules/@floating-ui/utils/README.md +4 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.mts +105 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.ts +105 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.d.mts +47 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.d.ts +47 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.esm.js +165 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs +165 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.umd.js +192 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.umd.min.js +1 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.esm.js +136 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs +136 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.umd.js +167 -0
- package/node_modules/@floating-ui/utils/dist/floating-ui.utils.umd.min.js +1 -0
- package/node_modules/@floating-ui/utils/dom/floating-ui.utils.dom.d.ts +47 -0
- package/node_modules/@floating-ui/utils/dom/floating-ui.utils.dom.esm.js +165 -0
- package/node_modules/@floating-ui/utils/dom/floating-ui.utils.dom.umd.js +192 -0
- package/node_modules/@floating-ui/utils/dom/package.json +6 -0
- package/node_modules/@floating-ui/utils/package.json +70 -0
- package/node_modules/@tiptap/core/LICENSE.md +21 -0
- package/node_modules/@tiptap/core/README.md +18 -0
- package/node_modules/@tiptap/core/dist/index.cjs +8463 -0
- package/node_modules/@tiptap/core/dist/index.d.cts +5798 -0
- package/node_modules/@tiptap/core/dist/index.d.ts +5797 -0
- package/node_modules/@tiptap/core/dist/index.js +8288 -0
- package/node_modules/@tiptap/core/dist/jsx-runtime/jsx-runtime.cjs +70 -0
- package/node_modules/@tiptap/core/dist/jsx-runtime/jsx-runtime.d.cts +28 -0
- package/node_modules/@tiptap/core/dist/jsx-runtime/jsx-runtime.d.ts +28 -0
- package/node_modules/@tiptap/core/dist/jsx-runtime/jsx-runtime.js +64 -0
- package/node_modules/@tiptap/core/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/node_modules/@tiptap/core/jsx-dev-runtime/index.cjs +1 -0
- package/node_modules/@tiptap/core/jsx-dev-runtime/index.d.cts +1 -0
- package/node_modules/@tiptap/core/jsx-dev-runtime/index.d.ts +1 -0
- package/node_modules/@tiptap/core/jsx-dev-runtime/index.js +1 -0
- package/node_modules/@tiptap/core/jsx-runtime/index.cjs +1 -0
- package/node_modules/@tiptap/core/jsx-runtime/index.d.cts +1 -0
- package/node_modules/@tiptap/core/jsx-runtime/index.d.ts +1 -0
- package/node_modules/@tiptap/core/jsx-runtime/index.js +1 -0
- package/node_modules/@tiptap/core/package.json +74 -0
- package/node_modules/@tiptap/extension-blockquote/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-blockquote/README.md +18 -0
- package/node_modules/@tiptap/extension-blockquote/dist/index.cjs +132 -0
- package/node_modules/@tiptap/extension-blockquote/dist/index.d.cts +40 -0
- package/node_modules/@tiptap/extension-blockquote/dist/index.d.ts +40 -0
- package/node_modules/@tiptap/extension-blockquote/dist/index.js +126 -0
- package/node_modules/@tiptap/extension-blockquote/package.json +52 -0
- package/node_modules/@tiptap/extension-bold/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-bold/README.md +18 -0
- package/node_modules/@tiptap/extension-bold/dist/index.cjs +117 -0
- package/node_modules/@tiptap/extension-bold/dist/index.d.cts +52 -0
- package/node_modules/@tiptap/extension-bold/dist/index.d.ts +52 -0
- package/node_modules/@tiptap/extension-bold/dist/index.js +108 -0
- package/node_modules/@tiptap/extension-bold/package.json +50 -0
- package/node_modules/@tiptap/extension-bubble-menu/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-bubble-menu/README.md +18 -0
- package/node_modules/@tiptap/extension-bubble-menu/dist/index.cjs +333 -0
- package/node_modules/@tiptap/extension-bubble-menu/dist/index.d.cts +170 -0
- package/node_modules/@tiptap/extension-bubble-menu/dist/index.d.ts +170 -0
- package/node_modules/@tiptap/extension-bubble-menu/dist/index.js +326 -0
- package/node_modules/@tiptap/extension-bubble-menu/package.json +56 -0
- package/node_modules/@tiptap/extension-bullet-list/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-bullet-list/README.md +18 -0
- package/node_modules/@tiptap/extension-bullet-list/dist/index.cjs +17 -0
- package/node_modules/@tiptap/extension-bullet-list/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-bullet-list/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-bullet-list/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-bullet-list/package.json +50 -0
- package/node_modules/@tiptap/extension-code/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-code/README.md +18 -0
- package/node_modules/@tiptap/extension-code/dist/index.cjs +136 -0
- package/node_modules/@tiptap/extension-code/dist/index.d.cts +60 -0
- package/node_modules/@tiptap/extension-code/dist/index.d.ts +60 -0
- package/node_modules/@tiptap/extension-code/dist/index.js +127 -0
- package/node_modules/@tiptap/extension-code/package.json +50 -0
- package/node_modules/@tiptap/extension-code-block/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-code-block/README.md +18 -0
- package/node_modules/@tiptap/extension-code-block/dist/index.cjs +255 -0
- package/node_modules/@tiptap/extension-code-block/dist/index.d.cts +84 -0
- package/node_modules/@tiptap/extension-code-block/dist/index.d.ts +84 -0
- package/node_modules/@tiptap/extension-code-block/dist/index.js +248 -0
- package/node_modules/@tiptap/extension-code-block/package.json +52 -0
- package/node_modules/@tiptap/extension-document/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-document/README.md +18 -0
- package/node_modules/@tiptap/extension-document/dist/index.cjs +26 -0
- package/node_modules/@tiptap/extension-document/dist/index.d.cts +10 -0
- package/node_modules/@tiptap/extension-document/dist/index.d.ts +10 -0
- package/node_modules/@tiptap/extension-document/dist/index.js +22 -0
- package/node_modules/@tiptap/extension-document/package.json +50 -0
- package/node_modules/@tiptap/extension-dropcursor/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-dropcursor/README.md +18 -0
- package/node_modules/@tiptap/extension-dropcursor/dist/index.cjs +17 -0
- package/node_modules/@tiptap/extension-dropcursor/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-dropcursor/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-dropcursor/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-dropcursor/package.json +50 -0
- package/node_modules/@tiptap/extension-floating-menu/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-floating-menu/README.md +18 -0
- package/node_modules/@tiptap/extension-floating-menu/dist/index.cjs +272 -0
- package/node_modules/@tiptap/extension-floating-menu/dist/index.d.cts +180 -0
- package/node_modules/@tiptap/extension-floating-menu/dist/index.d.ts +180 -0
- package/node_modules/@tiptap/extension-floating-menu/dist/index.js +265 -0
- package/node_modules/@tiptap/extension-floating-menu/package.json +55 -0
- package/node_modules/@tiptap/extension-gapcursor/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-gapcursor/README.md +18 -0
- package/node_modules/@tiptap/extension-gapcursor/dist/index.cjs +17 -0
- package/node_modules/@tiptap/extension-gapcursor/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-gapcursor/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-gapcursor/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-gapcursor/package.json +50 -0
- package/node_modules/@tiptap/extension-hard-break/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-hard-break/README.md +18 -0
- package/node_modules/@tiptap/extension-hard-break/dist/index.cjs +69 -0
- package/node_modules/@tiptap/extension-hard-break/dist/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-hard-break/dist/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-hard-break/dist/index.js +64 -0
- package/node_modules/@tiptap/extension-hard-break/package.json +50 -0
- package/node_modules/@tiptap/extension-heading/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-heading/README.md +18 -0
- package/node_modules/@tiptap/extension-heading/dist/index.cjs +93 -0
- package/node_modules/@tiptap/extension-heading/dist/index.d.cts +50 -0
- package/node_modules/@tiptap/extension-heading/dist/index.d.ts +50 -0
- package/node_modules/@tiptap/extension-heading/dist/index.js +88 -0
- package/node_modules/@tiptap/extension-heading/package.json +50 -0
- package/node_modules/@tiptap/extension-highlight/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-highlight/README.md +18 -0
- package/node_modules/@tiptap/extension-highlight/dist/index.cjs +113 -0
- package/node_modules/@tiptap/extension-highlight/dist/index.d.cts +59 -0
- package/node_modules/@tiptap/extension-highlight/dist/index.d.ts +59 -0
- package/node_modules/@tiptap/extension-highlight/dist/index.js +106 -0
- package/node_modules/@tiptap/extension-highlight/package.json +50 -0
- package/node_modules/@tiptap/extension-horizontal-rule/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-horizontal-rule/README.md +18 -0
- package/node_modules/@tiptap/extension-horizontal-rule/dist/index.cjs +78 -0
- package/node_modules/@tiptap/extension-horizontal-rule/dist/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-horizontal-rule/dist/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-horizontal-rule/dist/index.js +73 -0
- package/node_modules/@tiptap/extension-horizontal-rule/package.json +52 -0
- package/node_modules/@tiptap/extension-image/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-image/README.md +18 -0
- package/node_modules/@tiptap/extension-image/dist/index.cjs +181 -0
- package/node_modules/@tiptap/extension-image/dist/index.d.cts +69 -0
- package/node_modules/@tiptap/extension-image/dist/index.d.ts +69 -0
- package/node_modules/@tiptap/extension-image/dist/index.js +175 -0
- package/node_modules/@tiptap/extension-image/package.json +50 -0
- package/node_modules/@tiptap/extension-italic/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-italic/README.md +18 -0
- package/node_modules/@tiptap/extension-italic/dist/index.cjs +113 -0
- package/node_modules/@tiptap/extension-italic/dist/index.d.cts +55 -0
- package/node_modules/@tiptap/extension-italic/dist/index.d.ts +55 -0
- package/node_modules/@tiptap/extension-italic/dist/index.js +104 -0
- package/node_modules/@tiptap/extension-italic/package.json +50 -0
- package/node_modules/@tiptap/extension-link/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-link/README.md +18 -0
- package/node_modules/@tiptap/extension-link/dist/index.cjs +560 -0
- package/node_modules/@tiptap/extension-link/dist/index.d.cts +159 -0
- package/node_modules/@tiptap/extension-link/dist/index.d.ts +159 -0
- package/node_modules/@tiptap/extension-link/dist/index.js +553 -0
- package/node_modules/@tiptap/extension-link/package.json +56 -0
- package/node_modules/@tiptap/extension-list/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-list/README.md +18 -0
- package/node_modules/@tiptap/extension-list/dist/bullet-list/index.cjs +84 -0
- package/node_modules/@tiptap/extension-list/dist/bullet-list/index.d.cts +52 -0
- package/node_modules/@tiptap/extension-list/dist/bullet-list/index.d.ts +52 -0
- package/node_modules/@tiptap/extension-list/dist/bullet-list/index.js +82 -0
- package/node_modules/@tiptap/extension-list/dist/index.cjs +1570 -0
- package/node_modules/@tiptap/extension-list/dist/index.d.cts +391 -0
- package/node_modules/@tiptap/extension-list/dist/index.d.ts +390 -0
- package/node_modules/@tiptap/extension-list/dist/index.js +1533 -0
- package/node_modules/@tiptap/extension-list/dist/item/index.cjs +308 -0
- package/node_modules/@tiptap/extension-list/dist/item/index.d.cts +30 -0
- package/node_modules/@tiptap/extension-list/dist/item/index.d.ts +30 -0
- package/node_modules/@tiptap/extension-list/dist/item/index.js +307 -0
- package/node_modules/@tiptap/extension-list/dist/keymap/index.cjs +263 -0
- package/node_modules/@tiptap/extension-list/dist/keymap/index.d.cts +66 -0
- package/node_modules/@tiptap/extension-list/dist/keymap/index.d.ts +65 -0
- package/node_modules/@tiptap/extension-list/dist/keymap/index.js +245 -0
- package/node_modules/@tiptap/extension-list/dist/keymap/rolldown-runtime-D7D4PA-g.js +13 -0
- package/node_modules/@tiptap/extension-list/dist/kit/index.cjs +1487 -0
- package/node_modules/@tiptap/extension-list/dist/kit/index.d.cts +235 -0
- package/node_modules/@tiptap/extension-list/dist/kit/index.d.ts +235 -0
- package/node_modules/@tiptap/extension-list/dist/kit/index.js +1486 -0
- package/node_modules/@tiptap/extension-list/dist/ordered-list/index.cjs +671 -0
- package/node_modules/@tiptap/extension-list/dist/ordered-list/index.d.cts +120 -0
- package/node_modules/@tiptap/extension-list/dist/ordered-list/index.d.ts +120 -0
- package/node_modules/@tiptap/extension-list/dist/ordered-list/index.js +659 -0
- package/node_modules/@tiptap/extension-list/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/node_modules/@tiptap/extension-list/dist/task-item/index.cjs +327 -0
- package/node_modules/@tiptap/extension-list/dist/task-item/index.d.cts +69 -0
- package/node_modules/@tiptap/extension-list/dist/task-item/index.d.ts +69 -0
- package/node_modules/@tiptap/extension-list/dist/task-item/index.js +325 -0
- package/node_modules/@tiptap/extension-list/dist/task-list/index.cjs +121 -0
- package/node_modules/@tiptap/extension-list/dist/task-list/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-list/dist/task-list/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-list/dist/task-list/index.js +120 -0
- package/node_modules/@tiptap/extension-list/package.json +108 -0
- package/node_modules/@tiptap/extension-list-item/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-list-item/README.md +18 -0
- package/node_modules/@tiptap/extension-list-item/dist/index.cjs +17 -0
- package/node_modules/@tiptap/extension-list-item/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-list-item/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-list-item/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-list-item/package.json +50 -0
- package/node_modules/@tiptap/extension-list-keymap/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-list-keymap/README.md +18 -0
- package/node_modules/@tiptap/extension-list-keymap/dist/index.cjs +23 -0
- package/node_modules/@tiptap/extension-list-keymap/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-list-keymap/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-list-keymap/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-list-keymap/package.json +50 -0
- package/node_modules/@tiptap/extension-ordered-list/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-ordered-list/README.md +18 -0
- package/node_modules/@tiptap/extension-ordered-list/dist/index.cjs +17 -0
- package/node_modules/@tiptap/extension-ordered-list/dist/index.d.cts +2 -0
- package/node_modules/@tiptap/extension-ordered-list/dist/index.d.ts +2 -0
- package/node_modules/@tiptap/extension-ordered-list/dist/index.js +7 -0
- package/node_modules/@tiptap/extension-ordered-list/package.json +50 -0
- package/node_modules/@tiptap/extension-paragraph/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-paragraph/README.md +18 -0
- package/node_modules/@tiptap/extension-paragraph/dist/index.cjs +73 -0
- package/node_modules/@tiptap/extension-paragraph/dist/index.d.cts +29 -0
- package/node_modules/@tiptap/extension-paragraph/dist/index.d.ts +29 -0
- package/node_modules/@tiptap/extension-paragraph/dist/index.js +68 -0
- package/node_modules/@tiptap/extension-paragraph/package.json +50 -0
- package/node_modules/@tiptap/extension-strike/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-strike/README.md +18 -0
- package/node_modules/@tiptap/extension-strike/dist/index.cjs +88 -0
- package/node_modules/@tiptap/extension-strike/dist/index.d.cts +47 -0
- package/node_modules/@tiptap/extension-strike/dist/index.d.ts +47 -0
- package/node_modules/@tiptap/extension-strike/dist/index.js +81 -0
- package/node_modules/@tiptap/extension-strike/package.json +50 -0
- package/node_modules/@tiptap/extension-subscript/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-subscript/README.md +18 -0
- package/node_modules/@tiptap/extension-subscript/dist/index.cjs +56 -0
- package/node_modules/@tiptap/extension-subscript/dist/index.d.cts +39 -0
- package/node_modules/@tiptap/extension-subscript/dist/index.d.ts +39 -0
- package/node_modules/@tiptap/extension-subscript/dist/index.js +51 -0
- package/node_modules/@tiptap/extension-subscript/package.json +52 -0
- package/node_modules/@tiptap/extension-superscript/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-superscript/README.md +18 -0
- package/node_modules/@tiptap/extension-superscript/dist/index.cjs +56 -0
- package/node_modules/@tiptap/extension-superscript/dist/index.d.cts +39 -0
- package/node_modules/@tiptap/extension-superscript/dist/index.d.ts +39 -0
- package/node_modules/@tiptap/extension-superscript/dist/index.js +51 -0
- package/node_modules/@tiptap/extension-superscript/package.json +52 -0
- package/node_modules/@tiptap/extension-table/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-table/README.md +18 -0
- package/node_modules/@tiptap/extension-table/dist/cell/index.cjs +142 -0
- package/node_modules/@tiptap/extension-table/dist/cell/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-table/dist/cell/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-table/dist/cell/index.js +141 -0
- package/node_modules/@tiptap/extension-table/dist/header/index.cjs +142 -0
- package/node_modules/@tiptap/extension-table/dist/header/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-table/dist/header/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-table/dist/header/index.js +141 -0
- package/node_modules/@tiptap/extension-table/dist/index.cjs +832 -0
- package/node_modules/@tiptap/extension-table/dist/index.d.cts +344 -0
- package/node_modules/@tiptap/extension-table/dist/index.d.ts +344 -0
- package/node_modules/@tiptap/extension-table/dist/index.js +819 -0
- package/node_modules/@tiptap/extension-table/dist/kit/index.cjs +817 -0
- package/node_modules/@tiptap/extension-table/dist/kit/index.d.cts +265 -0
- package/node_modules/@tiptap/extension-table/dist/kit/index.d.ts +265 -0
- package/node_modules/@tiptap/extension-table/dist/kit/index.js +816 -0
- package/node_modules/@tiptap/extension-table/dist/row/index.cjs +29 -0
- package/node_modules/@tiptap/extension-table/dist/row/index.d.cts +35 -0
- package/node_modules/@tiptap/extension-table/dist/row/index.d.ts +35 -0
- package/node_modules/@tiptap/extension-table/dist/row/index.js +28 -0
- package/node_modules/@tiptap/extension-table/dist/table/index.cjs +616 -0
- package/node_modules/@tiptap/extension-table/dist/table/index.d.cts +254 -0
- package/node_modules/@tiptap/extension-table/dist/table/index.d.ts +254 -0
- package/node_modules/@tiptap/extension-table/dist/table/index.js +609 -0
- package/node_modules/@tiptap/extension-table/package.json +92 -0
- package/node_modules/@tiptap/extension-text/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-text/README.md +18 -0
- package/node_modules/@tiptap/extension-text/dist/index.cjs +28 -0
- package/node_modules/@tiptap/extension-text/dist/index.d.cts +10 -0
- package/node_modules/@tiptap/extension-text/dist/index.d.ts +10 -0
- package/node_modules/@tiptap/extension-text/dist/index.js +24 -0
- package/node_modules/@tiptap/extension-text/package.json +50 -0
- package/node_modules/@tiptap/extension-text-align/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-text-align/README.md +18 -0
- package/node_modules/@tiptap/extension-text-align/dist/index.cjs +73 -0
- package/node_modules/@tiptap/extension-text-align/dist/index.d.cts +53 -0
- package/node_modules/@tiptap/extension-text-align/dist/index.d.ts +53 -0
- package/node_modules/@tiptap/extension-text-align/dist/index.js +68 -0
- package/node_modules/@tiptap/extension-text-align/package.json +50 -0
- package/node_modules/@tiptap/extension-text-style/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-text-style/README.md +18 -0
- package/node_modules/@tiptap/extension-text-style/dist/background-color/index.cjs +121 -0
- package/node_modules/@tiptap/extension-text-style/dist/background-color/index.d.cts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/background-color/index.d.ts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/background-color/index.js +116 -0
- package/node_modules/@tiptap/extension-text-style/dist/color/index.cjs +121 -0
- package/node_modules/@tiptap/extension-text-style/dist/color/index.d.cts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/color/index.d.ts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/color/index.js +116 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-family/index.cjs +120 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-family/index.d.cts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-family/index.d.ts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-family/index.js +115 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-size/index.cjs +120 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-size/index.d.cts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-size/index.d.ts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/font-size/index.js +115 -0
- package/node_modules/@tiptap/extension-text-style/dist/index.cjs +298 -0
- package/node_modules/@tiptap/extension-text-style/dist/index.d.cts +275 -0
- package/node_modules/@tiptap/extension-text-style/dist/index.d.ts +275 -0
- package/node_modules/@tiptap/extension-text-style/dist/index.js +291 -0
- package/node_modules/@tiptap/extension-text-style/dist/line-height/index.cjs +120 -0
- package/node_modules/@tiptap/extension-text-style/dist/line-height/index.d.cts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/line-height/index.d.ts +161 -0
- package/node_modules/@tiptap/extension-text-style/dist/line-height/index.js +115 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style/index.cjs +80 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style/index.d.cts +170 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style/index.d.ts +170 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style/index.js +79 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style-kit/index.cjs +292 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style-kit/index.d.cts +244 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style-kit/index.d.ts +244 -0
- package/node_modules/@tiptap/extension-text-style/dist/text-style-kit/index.js +291 -0
- package/node_modules/@tiptap/extension-text-style/package.json +106 -0
- package/node_modules/@tiptap/extension-underline/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-underline/README.md +18 -0
- package/node_modules/@tiptap/extension-underline/dist/index.cjs +81 -0
- package/node_modules/@tiptap/extension-underline/dist/index.d.cts +39 -0
- package/node_modules/@tiptap/extension-underline/dist/index.d.ts +39 -0
- package/node_modules/@tiptap/extension-underline/dist/index.js +76 -0
- package/node_modules/@tiptap/extension-underline/package.json +50 -0
- package/node_modules/@tiptap/extension-youtube/LICENSE.md +21 -0
- package/node_modules/@tiptap/extension-youtube/README.md +18 -0
- package/node_modules/@tiptap/extension-youtube/dist/index.cjs +254 -0
- package/node_modules/@tiptap/extension-youtube/dist/index.d.cts +204 -0
- package/node_modules/@tiptap/extension-youtube/dist/index.d.ts +204 -0
- package/node_modules/@tiptap/extension-youtube/dist/index.js +246 -0
- package/node_modules/@tiptap/extension-youtube/package.json +50 -0
- package/node_modules/@tiptap/extensions/LICENSE.md +21 -0
- package/node_modules/@tiptap/extensions/README.md +18 -0
- package/node_modules/@tiptap/extensions/dist/character-count/index.cjs +87 -0
- package/node_modules/@tiptap/extensions/dist/character-count/index.d.cts +70 -0
- package/node_modules/@tiptap/extensions/dist/character-count/index.d.ts +70 -0
- package/node_modules/@tiptap/extensions/dist/character-count/index.js +86 -0
- package/node_modules/@tiptap/extensions/dist/drop-cursor/index.cjs +27 -0
- package/node_modules/@tiptap/extensions/dist/drop-cursor/index.d.cts +32 -0
- package/node_modules/@tiptap/extensions/dist/drop-cursor/index.d.ts +32 -0
- package/node_modules/@tiptap/extensions/dist/drop-cursor/index.js +26 -0
- package/node_modules/@tiptap/extensions/dist/focus/index.cjs +48 -0
- package/node_modules/@tiptap/extensions/dist/focus/index.d.cts +29 -0
- package/node_modules/@tiptap/extensions/dist/focus/index.d.ts +29 -0
- package/node_modules/@tiptap/extensions/dist/focus/index.js +47 -0
- package/node_modules/@tiptap/extensions/dist/gap-cursor/index.cjs +29 -0
- package/node_modules/@tiptap/extensions/dist/gap-cursor/index.d.cts +26 -0
- package/node_modules/@tiptap/extensions/dist/gap-cursor/index.d.ts +26 -0
- package/node_modules/@tiptap/extensions/dist/gap-cursor/index.js +28 -0
- package/node_modules/@tiptap/extensions/dist/index.cjs +711 -0
- package/node_modules/@tiptap/extensions/dist/index.d.cts +321 -0
- package/node_modules/@tiptap/extensions/dist/index.d.ts +321 -0
- package/node_modules/@tiptap/extensions/dist/index.js +699 -0
- package/node_modules/@tiptap/extensions/dist/placeholder/index.cjs +372 -0
- package/node_modules/@tiptap/extensions/dist/placeholder/index.d.cts +91 -0
- package/node_modules/@tiptap/extensions/dist/placeholder/index.d.ts +91 -0
- package/node_modules/@tiptap/extensions/dist/placeholder/index.js +368 -0
- package/node_modules/@tiptap/extensions/dist/selection/index.cjs +72 -0
- package/node_modules/@tiptap/extensions/dist/selection/index.d.cts +20 -0
- package/node_modules/@tiptap/extensions/dist/selection/index.d.ts +20 -0
- package/node_modules/@tiptap/extensions/dist/selection/index.js +71 -0
- package/node_modules/@tiptap/extensions/dist/trailing-node/index.cjs +62 -0
- package/node_modules/@tiptap/extensions/dist/trailing-node/index.d.cts +30 -0
- package/node_modules/@tiptap/extensions/dist/trailing-node/index.d.ts +30 -0
- package/node_modules/@tiptap/extensions/dist/trailing-node/index.js +60 -0
- package/node_modules/@tiptap/extensions/dist/undo-redo/index.cjs +48 -0
- package/node_modules/@tiptap/extensions/dist/undo-redo/index.d.cts +45 -0
- package/node_modules/@tiptap/extensions/dist/undo-redo/index.d.ts +45 -0
- package/node_modules/@tiptap/extensions/dist/undo-redo/index.js +47 -0
- package/node_modules/@tiptap/extensions/package.json +116 -0
- package/node_modules/@tiptap/pm/LICENSE +21 -0
- package/node_modules/@tiptap/pm/README.md +22 -0
- package/node_modules/@tiptap/pm/THIRD_PARTY_LICENSES.md +47 -0
- package/node_modules/@tiptap/pm/changeset/index.ts +1 -0
- package/node_modules/@tiptap/pm/commands/index.ts +1 -0
- package/node_modules/@tiptap/pm/dist/changeset/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/changeset/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/changeset/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/changeset/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/commands/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/commands/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/commands/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/commands/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/dropcursor/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/dropcursor/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/dropcursor/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/dropcursor/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/gapcursor/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/gapcursor/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/gapcursor/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/gapcursor/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/history/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/history/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/history/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/history/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/inputrules/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/inputrules/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/inputrules/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/inputrules/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/keymap/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/keymap/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/keymap/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/keymap/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/model/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/model/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/model/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/model/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/schema-list/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/schema-list/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/schema-list/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/schema-list/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/state/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/state/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/state/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/state/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/tables/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/tables/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/tables/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/tables/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/transform/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/transform/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/transform/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/transform/index.js +2 -0
- package/node_modules/@tiptap/pm/dist/view/index.cjs +9 -0
- package/node_modules/@tiptap/pm/dist/view/index.d.cts +1 -0
- package/node_modules/@tiptap/pm/dist/view/index.d.ts +1 -0
- package/node_modules/@tiptap/pm/dist/view/index.js +2 -0
- package/node_modules/@tiptap/pm/dropcursor/index.ts +1 -0
- package/node_modules/@tiptap/pm/gapcursor/index.ts +1 -0
- package/node_modules/@tiptap/pm/history/index.ts +1 -0
- package/node_modules/@tiptap/pm/inputrules/index.ts +1 -0
- package/node_modules/@tiptap/pm/keymap/index.ts +1 -0
- package/node_modules/@tiptap/pm/model/index.ts +1 -0
- package/node_modules/@tiptap/pm/package.json +166 -0
- package/node_modules/@tiptap/pm/schema-list/index.ts +1 -0
- package/node_modules/@tiptap/pm/state/index.ts +1 -0
- package/node_modules/@tiptap/pm/tables/index.ts +1 -0
- package/node_modules/@tiptap/pm/transform/index.ts +1 -0
- package/node_modules/@tiptap/pm/view/index.ts +1 -0
- package/node_modules/@tiptap/react/LICENSE.md +21 -0
- package/node_modules/@tiptap/react/README.md +18 -0
- package/node_modules/@tiptap/react/dist/index.cjs +1396 -0
- package/node_modules/@tiptap/react/dist/index.d.cts +632 -0
- package/node_modules/@tiptap/react/dist/index.d.ts +632 -0
- package/node_modules/@tiptap/react/dist/index.js +1337 -0
- package/node_modules/@tiptap/react/dist/menus/index.cjs +469 -0
- package/node_modules/@tiptap/react/dist/menus/index.d.cts +21 -0
- package/node_modules/@tiptap/react/dist/menus/index.d.ts +21 -0
- package/node_modules/@tiptap/react/dist/menus/index.js +444 -0
- package/node_modules/@tiptap/react/package.json +80 -0
- package/node_modules/@tiptap/starter-kit/LICENSE.md +21 -0
- package/node_modules/@tiptap/starter-kit/README.md +18 -0
- package/node_modules/@tiptap/starter-kit/dist/index.cjs +76 -0
- package/node_modules/@tiptap/starter-kit/dist/index.d.cts +137 -0
- package/node_modules/@tiptap/starter-kit/dist/index.d.ts +137 -0
- package/node_modules/@tiptap/starter-kit/dist/index.js +71 -0
- package/node_modules/@tiptap/starter-kit/package.json +70 -0
- package/node_modules/@tiptap/suggestion/LICENSE.md +21 -0
- package/node_modules/@tiptap/suggestion/README.md +18 -0
- package/node_modules/@tiptap/suggestion/dist/index.cjs +665 -0
- package/node_modules/@tiptap/suggestion/dist/index.d.cts +419 -0
- package/node_modules/@tiptap/suggestion/dist/index.d.ts +419 -0
- package/node_modules/@tiptap/suggestion/dist/index.js +657 -0
- package/node_modules/@tiptap/suggestion/package.json +54 -0
- package/node_modules/@types/use-sync-external-store/LICENSE +21 -0
- package/node_modules/@types/use-sync-external-store/README.md +15 -0
- package/node_modules/@types/use-sync-external-store/index.d.ts +5 -0
- package/node_modules/@types/use-sync-external-store/package.json +30 -0
- package/node_modules/@types/use-sync-external-store/shim/index.d.ts +1 -0
- package/node_modules/@types/use-sync-external-store/shim/with-selector.d.ts +1 -0
- package/node_modules/@types/use-sync-external-store/with-selector.d.ts +7 -0
- package/node_modules/fast-equals/LICENSE +21 -0
- package/node_modules/fast-equals/README.md +479 -0
- package/node_modules/fast-equals/dist/cjs/index.cjs +796 -0
- package/node_modules/fast-equals/dist/cjs/index.d.cts +211 -0
- package/node_modules/fast-equals/dist/es/index.d.mts +211 -0
- package/node_modules/fast-equals/dist/es/index.mjs +785 -0
- package/node_modules/fast-equals/dist/umd/index.d.ts +211 -0
- package/node_modules/fast-equals/dist/umd/index.js +802 -0
- package/node_modules/fast-equals/index.d.ts +211 -0
- package/node_modules/fast-equals/package.json +120 -0
- package/node_modules/linkifyjs/LICENSE +19 -0
- package/node_modules/linkifyjs/README.md +47 -0
- package/node_modules/linkifyjs/dist/linkify.cjs +1854 -0
- package/node_modules/linkifyjs/dist/linkify.d.cts +637 -0
- package/node_modules/linkifyjs/dist/linkify.d.mts +637 -0
- package/node_modules/linkifyjs/dist/linkify.js +1859 -0
- package/node_modules/linkifyjs/dist/linkify.min.js +1 -0
- package/node_modules/linkifyjs/dist/linkify.mjs +1836 -0
- package/node_modules/linkifyjs/package.json +38 -0
- package/node_modules/orderedmap/LICENSE +19 -0
- package/node_modules/orderedmap/README.md +69 -0
- package/node_modules/orderedmap/dist/index.cjs +139 -0
- package/node_modules/orderedmap/dist/index.d.cts +33 -0
- package/node_modules/orderedmap/dist/index.d.ts +33 -0
- package/node_modules/orderedmap/dist/index.js +137 -0
- package/node_modules/orderedmap/package.json +39 -0
- package/node_modules/prosemirror-changeset/CHANGELOG.md +171 -0
- package/node_modules/prosemirror-changeset/LICENSE +19 -0
- package/node_modules/prosemirror-changeset/README.md +175 -0
- package/node_modules/prosemirror-changeset/dist/index.cjs +588 -0
- package/node_modules/prosemirror-changeset/dist/index.d.cts +187 -0
- package/node_modules/prosemirror-changeset/dist/index.d.ts +187 -0
- package/node_modules/prosemirror-changeset/dist/index.js +722 -0
- package/node_modules/prosemirror-changeset/package.json +40 -0
- package/node_modules/prosemirror-changeset/test/test-changed-range.ts +48 -0
- package/node_modules/prosemirror-changeset/test/test-changes.ts +211 -0
- package/node_modules/prosemirror-changeset/test/test-diff.ts +77 -0
- package/node_modules/prosemirror-changeset/test/test-merge.ts +56 -0
- package/node_modules/prosemirror-changeset/test/test-simplify.ts +74 -0
- package/node_modules/prosemirror-commands/.tern-project +8 -0
- package/node_modules/prosemirror-commands/CHANGELOG.md +328 -0
- package/node_modules/prosemirror-commands/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-commands/LICENSE +19 -0
- package/node_modules/prosemirror-commands/README.md +28 -0
- package/node_modules/prosemirror-commands/dist/index.cjs +688 -0
- package/node_modules/prosemirror-commands/dist/index.d.cts +215 -0
- package/node_modules/prosemirror-commands/dist/index.d.ts +215 -0
- package/node_modules/prosemirror-commands/dist/index.js +852 -0
- package/node_modules/prosemirror-commands/package.json +39 -0
- package/node_modules/prosemirror-dropcursor/CHANGELOG.md +149 -0
- package/node_modules/prosemirror-dropcursor/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-dropcursor/LICENSE +19 -0
- package/node_modules/prosemirror-dropcursor/README.md +50 -0
- package/node_modules/prosemirror-dropcursor/dist/index.cjs +200 -0
- package/node_modules/prosemirror-dropcursor/dist/index.d.cts +38 -0
- package/node_modules/prosemirror-dropcursor/dist/index.d.ts +38 -0
- package/node_modules/prosemirror-dropcursor/dist/index.js +163 -0
- package/node_modules/prosemirror-dropcursor/package.json +38 -0
- package/node_modules/prosemirror-gapcursor/CHANGELOG.md +122 -0
- package/node_modules/prosemirror-gapcursor/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-gapcursor/LICENSE +19 -0
- package/node_modules/prosemirror-gapcursor/README.md +31 -0
- package/node_modules/prosemirror-gapcursor/dist/index.cjs +239 -0
- package/node_modules/prosemirror-gapcursor/dist/index.d.cts +31 -0
- package/node_modules/prosemirror-gapcursor/dist/index.d.ts +31 -0
- package/node_modules/prosemirror-gapcursor/dist/index.js +239 -0
- package/node_modules/prosemirror-gapcursor/package.json +43 -0
- package/node_modules/prosemirror-gapcursor/style/gapcursor.css +25 -0
- package/node_modules/prosemirror-history/.tern-project +8 -0
- package/node_modules/prosemirror-history/CHANGELOG.md +176 -0
- package/node_modules/prosemirror-history/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-history/LICENSE +19 -0
- package/node_modules/prosemirror-history/README.md +27 -0
- package/node_modules/prosemirror-history/dist/index.cjs +383 -0
- package/node_modules/prosemirror-history/dist/index.d.cts +64 -0
- package/node_modules/prosemirror-history/dist/index.d.ts +64 -0
- package/node_modules/prosemirror-history/dist/index.js +454 -0
- package/node_modules/prosemirror-history/package.json +40 -0
- package/node_modules/prosemirror-inputrules/.tern-project +8 -0
- package/node_modules/prosemirror-inputrules/CHANGELOG.md +127 -0
- package/node_modules/prosemirror-inputrules/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-inputrules/LICENSE +19 -0
- package/node_modules/prosemirror-inputrules/README.md +29 -0
- package/node_modules/prosemirror-inputrules/dist/index.cjs +194 -0
- package/node_modules/prosemirror-inputrules/dist/index.d.cts +131 -0
- package/node_modules/prosemirror-inputrules/dist/index.d.ts +131 -0
- package/node_modules/prosemirror-inputrules/dist/index.js +239 -0
- package/node_modules/prosemirror-inputrules/package.json +36 -0
- package/node_modules/prosemirror-keymap/.tern-project +8 -0
- package/node_modules/prosemirror-keymap/CHANGELOG.md +104 -0
- package/node_modules/prosemirror-keymap/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-keymap/LICENSE +19 -0
- package/node_modules/prosemirror-keymap/README.md +27 -0
- package/node_modules/prosemirror-keymap/dist/index.cjs +65 -0
- package/node_modules/prosemirror-keymap/dist/index.d.cts +47 -0
- package/node_modules/prosemirror-keymap/dist/index.d.ts +47 -0
- package/node_modules/prosemirror-keymap/dist/index.js +128 -0
- package/node_modules/prosemirror-keymap/package.json +38 -0
- package/node_modules/prosemirror-model/.tern-project +8 -0
- package/node_modules/prosemirror-model/CHANGELOG.md +782 -0
- package/node_modules/prosemirror-model/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-model/LICENSE +19 -0
- package/node_modules/prosemirror-model/README.md +29 -0
- package/node_modules/prosemirror-model/dist/index.cjs +2911 -0
- package/node_modules/prosemirror-model/dist/index.d.cts +1683 -0
- package/node_modules/prosemirror-model/dist/index.d.ts +1683 -0
- package/node_modules/prosemirror-model/dist/index.js +3463 -0
- package/node_modules/prosemirror-model/package.json +38 -0
- package/node_modules/prosemirror-schema-list/.tern-project +8 -0
- package/node_modules/prosemirror-schema-list/CHANGELOG.md +140 -0
- package/node_modules/prosemirror-schema-list/CONTRIBUTING.md +100 -0
- package/node_modules/prosemirror-schema-list/LICENSE +19 -0
- package/node_modules/prosemirror-schema-list/README.md +28 -0
- package/node_modules/prosemirror-schema-list/dist/index.cjs +253 -0
- package/node_modules/prosemirror-schema-list/dist/index.d.cts +71 -0
- package/node_modules/prosemirror-schema-list/dist/index.d.ts +71 -0
- package/node_modules/prosemirror-schema-list/dist/index.js +289 -0
- package/node_modules/prosemirror-schema-list/package.json +40 -0
- package/node_modules/prosemirror-state/.tern-project +8 -0
- package/node_modules/prosemirror-state/CHANGELOG.md +296 -0
- package/node_modules/prosemirror-state/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-state/LICENSE +19 -0
- package/node_modules/prosemirror-state/README.md +28 -0
- package/node_modules/prosemirror-state/dist/index.cjs +884 -0
- package/node_modules/prosemirror-state/dist/index.d.cts +709 -0
- package/node_modules/prosemirror-state/dist/index.d.ts +709 -0
- package/node_modules/prosemirror-state/dist/index.js +1002 -0
- package/node_modules/prosemirror-state/package.json +39 -0
- package/node_modules/prosemirror-tables/LICENSE +19 -0
- package/node_modules/prosemirror-tables/README.md +254 -0
- package/node_modules/prosemirror-tables/dist/index.cjs +2683 -0
- package/node_modules/prosemirror-tables/dist/index.d.cts +751 -0
- package/node_modules/prosemirror-tables/dist/index.d.ts +751 -0
- package/node_modules/prosemirror-tables/dist/index.js +2626 -0
- package/node_modules/prosemirror-tables/package.json +80 -0
- package/node_modules/prosemirror-tables/style/tables.css +48 -0
- package/node_modules/prosemirror-transform/.tern-project +8 -0
- package/node_modules/prosemirror-transform/CHANGELOG.md +530 -0
- package/node_modules/prosemirror-transform/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-transform/LICENSE +19 -0
- package/node_modules/prosemirror-transform/README.md +29 -0
- package/node_modules/prosemirror-transform/dist/index.cjs +2014 -0
- package/node_modules/prosemirror-transform/dist/index.d.cts +857 -0
- package/node_modules/prosemirror-transform/dist/index.d.ts +857 -0
- package/node_modules/prosemirror-transform/dist/index.js +2272 -0
- package/node_modules/prosemirror-transform/package.json +37 -0
- package/node_modules/prosemirror-view/.tern-project +8 -0
- package/node_modules/prosemirror-view/CHANGELOG.md +2543 -0
- package/node_modules/prosemirror-view/CONTRIBUTING.md +104 -0
- package/node_modules/prosemirror-view/LICENSE +19 -0
- package/node_modules/prosemirror-view/README.md +28 -0
- package/node_modules/prosemirror-view/dist/index.cjs +5549 -0
- package/node_modules/prosemirror-view/dist/index.d.cts +913 -0
- package/node_modules/prosemirror-view/dist/index.d.ts +913 -0
- package/node_modules/prosemirror-view/dist/index.js +6053 -0
- package/node_modules/prosemirror-view/package.json +43 -0
- package/node_modules/prosemirror-view/style/prosemirror.css +54 -0
- package/node_modules/rope-sequence/LICENSE +19 -0
- package/node_modules/rope-sequence/README.md +63 -0
- package/node_modules/rope-sequence/dist/index.cjs +209 -0
- package/node_modules/rope-sequence/dist/index.d.cts +11 -0
- package/node_modules/rope-sequence/dist/index.d.ts +11 -0
- package/node_modules/rope-sequence/dist/index.js +207 -0
- package/node_modules/rope-sequence/index.js +190 -0
- package/node_modules/rope-sequence/package.json +34 -0
- package/node_modules/rope-sequence/test.js +78 -0
- package/node_modules/use-sync-external-store/LICENSE +21 -0
- package/node_modules/use-sync-external-store/README.md +5 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +97 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js +85 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +95 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.native.development.js +88 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.native.production.js +59 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +66 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +96 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +84 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store.development.js +27 -0
- package/node_modules/use-sync-external-store/cjs/use-sync-external-store.production.js +13 -0
- package/node_modules/use-sync-external-store/index.js +7 -0
- package/node_modules/use-sync-external-store/package.json +43 -0
- package/node_modules/use-sync-external-store/shim/index.js +7 -0
- package/node_modules/use-sync-external-store/shim/index.native.js +7 -0
- package/node_modules/use-sync-external-store/shim/with-selector.js +7 -0
- package/node_modules/use-sync-external-store/with-selector.js +7 -0
- package/node_modules/w3c-keyname/.tern-port +1 -0
- package/node_modules/w3c-keyname/LICENSE +19 -0
- package/node_modules/w3c-keyname/README.md +18 -0
- package/node_modules/w3c-keyname/index.cjs +127 -0
- package/node_modules/w3c-keyname/index.d.cts +5 -0
- package/node_modules/w3c-keyname/index.d.ts +5 -0
- package/node_modules/w3c-keyname/index.js +119 -0
- package/node_modules/w3c-keyname/package.json +37 -0
- package/package.json +79 -4
- package/src/Editor.tsx +424 -0
- package/src/ask.tsx +154 -0
- package/src/basic.tsx +149 -0
- package/src/blockMeta.ts +42 -0
- package/src/blockops.ts +179 -0
- package/src/blocks.tsx +189 -0
- package/src/content.ts +22 -0
- package/src/dynamic.tsx +105 -0
- package/src/editor.css +345 -0
- package/src/extensions.ts +78 -0
- package/src/handle.tsx +186 -0
- package/src/handles.tsx +149 -0
- package/src/index.ts +29 -0
- package/src/insert.ts +9 -0
- package/src/inserter.tsx +163 -0
- package/src/inspector.tsx +237 -0
- package/src/labels.ts +135 -0
- package/src/layout.tsx +174 -0
- package/src/layoutUi.tsx +226 -0
- package/src/media.ts +31 -0
- package/src/nodes.tsx +107 -0
- package/src/outline.tsx +124 -0
- package/src/panels.ts +59 -0
- package/src/paste.ts +100 -0
- package/src/patterns.ts +129 -0
- package/src/rank.ts +22 -0
- package/src/registry.ts +20 -0
- package/src/styleattr.ts +55 -0
- package/src/stylepanel.tsx +275 -0
- package/src/synced.tsx +128 -0
- package/src/toolbar.tsx +238 -0
- package/src/types.ts +55 -0
- package/src/unknown.tsx +74 -0
- package/src/util.ts +3 -0
|
@@ -0,0 +1,2626 @@
|
|
|
1
|
+
import { NodeSelection, Plugin, PluginKey, Selection, SelectionRange, TextSelection } from "prosemirror-state";
|
|
2
|
+
import { Fragment, Slice } from "prosemirror-model";
|
|
3
|
+
import { Decoration, DecorationSet } from "prosemirror-view";
|
|
4
|
+
import { keydownHandler } from "prosemirror-keymap";
|
|
5
|
+
import { Transform } from "prosemirror-transform";
|
|
6
|
+
|
|
7
|
+
//#region src/tablemap.ts
|
|
8
|
+
let readFromCache;
|
|
9
|
+
let addToCache;
|
|
10
|
+
if (typeof WeakMap != "undefined") {
|
|
11
|
+
let cache = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
readFromCache = (key) => cache.get(key);
|
|
13
|
+
addToCache = (key, value) => {
|
|
14
|
+
cache.set(key, value);
|
|
15
|
+
return value;
|
|
16
|
+
};
|
|
17
|
+
} else {
|
|
18
|
+
const cache = [];
|
|
19
|
+
const cacheSize = 10;
|
|
20
|
+
let cachePos = 0;
|
|
21
|
+
readFromCache = (key) => {
|
|
22
|
+
for (let i = 0; i < cache.length; i += 2) if (cache[i] == key) return cache[i + 1];
|
|
23
|
+
};
|
|
24
|
+
addToCache = (key, value) => {
|
|
25
|
+
if (cachePos == cacheSize) cachePos = 0;
|
|
26
|
+
cache[cachePos++] = key;
|
|
27
|
+
return cache[cachePos++] = value;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A table map describes the structure of a given table. To avoid
|
|
32
|
+
* recomputing them all the time, they are cached per table node. To
|
|
33
|
+
* be able to do that, positions saved in the map are relative to the
|
|
34
|
+
* start of the table, rather than the start of the document.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
var TableMap = class {
|
|
39
|
+
constructor(width, height, map, problems) {
|
|
40
|
+
this.width = width;
|
|
41
|
+
this.height = height;
|
|
42
|
+
this.map = map;
|
|
43
|
+
this.problems = problems;
|
|
44
|
+
}
|
|
45
|
+
findCell(pos) {
|
|
46
|
+
for (let i = 0; i < this.map.length; i++) {
|
|
47
|
+
const curPos = this.map[i];
|
|
48
|
+
if (curPos != pos) continue;
|
|
49
|
+
const left = i % this.width;
|
|
50
|
+
const top = i / this.width | 0;
|
|
51
|
+
let right = left + 1;
|
|
52
|
+
let bottom = top + 1;
|
|
53
|
+
for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) right++;
|
|
54
|
+
for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) bottom++;
|
|
55
|
+
return {
|
|
56
|
+
left,
|
|
57
|
+
top,
|
|
58
|
+
right,
|
|
59
|
+
bottom
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
throw new RangeError(`No cell with offset ${pos} found`);
|
|
63
|
+
}
|
|
64
|
+
colCount(pos) {
|
|
65
|
+
for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
|
|
66
|
+
throw new RangeError(`No cell with offset ${pos} found`);
|
|
67
|
+
}
|
|
68
|
+
nextCell(pos, axis, dir) {
|
|
69
|
+
const { left, right, top, bottom } = this.findCell(pos);
|
|
70
|
+
if (axis == "horiz") {
|
|
71
|
+
if (dir < 0 ? left == 0 : right == this.width) return null;
|
|
72
|
+
return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
|
|
73
|
+
} else {
|
|
74
|
+
if (dir < 0 ? top == 0 : bottom == this.height) return null;
|
|
75
|
+
return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
rectBetween(a, b) {
|
|
79
|
+
const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
|
|
80
|
+
const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b);
|
|
81
|
+
return {
|
|
82
|
+
left: Math.min(leftA, leftB),
|
|
83
|
+
top: Math.min(topA, topB),
|
|
84
|
+
right: Math.max(rightA, rightB),
|
|
85
|
+
bottom: Math.max(bottomA, bottomB)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
cellsInRect(rect) {
|
|
89
|
+
const result = [];
|
|
90
|
+
const seen = {};
|
|
91
|
+
for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
|
|
92
|
+
const index = row * this.width + col;
|
|
93
|
+
const pos = this.map[index];
|
|
94
|
+
if (seen[pos]) continue;
|
|
95
|
+
seen[pos] = true;
|
|
96
|
+
if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) continue;
|
|
97
|
+
result.push(pos);
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
positionAt(row, col, table) {
|
|
102
|
+
for (let i = 0, rowStart = 0;; i++) {
|
|
103
|
+
const rowEnd = rowStart + table.child(i).nodeSize;
|
|
104
|
+
if (i == row) {
|
|
105
|
+
let index = col + row * this.width;
|
|
106
|
+
const rowEndIndex = (row + 1) * this.width;
|
|
107
|
+
while (index < rowEndIndex && this.map[index] < rowStart) index++;
|
|
108
|
+
return index == rowEndIndex ? rowEnd - 1 : this.map[index];
|
|
109
|
+
}
|
|
110
|
+
rowStart = rowEnd;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
static get(table) {
|
|
114
|
+
return readFromCache(table) || addToCache(table, computeMap(table));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function computeMap(table) {
|
|
118
|
+
if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
|
|
119
|
+
const width = findWidth(table), height = table.childCount;
|
|
120
|
+
const map = [];
|
|
121
|
+
let mapPos = 0;
|
|
122
|
+
let problems = null;
|
|
123
|
+
const colWidths = [];
|
|
124
|
+
for (let i = 0, e = width * height; i < e; i++) map[i] = 0;
|
|
125
|
+
for (let row = 0, pos = 0; row < height; row++) {
|
|
126
|
+
const rowNode = table.child(row);
|
|
127
|
+
pos++;
|
|
128
|
+
for (let i = 0;; i++) {
|
|
129
|
+
while (mapPos < map.length && map[mapPos] != 0) mapPos++;
|
|
130
|
+
if (i == rowNode.childCount) break;
|
|
131
|
+
const cellNode = rowNode.child(i);
|
|
132
|
+
const { colspan, rowspan, colwidth } = cellNode.attrs;
|
|
133
|
+
for (let h = 0; h < rowspan; h++) {
|
|
134
|
+
if (h + row >= height) {
|
|
135
|
+
(problems || (problems = [])).push({
|
|
136
|
+
type: "overlong_rowspan",
|
|
137
|
+
pos,
|
|
138
|
+
n: rowspan - h
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
const start = mapPos + h * width;
|
|
143
|
+
for (let w = 0; w < colspan; w++) {
|
|
144
|
+
if (map[start + w] == 0) map[start + w] = pos;
|
|
145
|
+
else (problems || (problems = [])).push({
|
|
146
|
+
type: "collision",
|
|
147
|
+
row,
|
|
148
|
+
pos,
|
|
149
|
+
n: colspan - w
|
|
150
|
+
});
|
|
151
|
+
const colW = colwidth && colwidth[w];
|
|
152
|
+
if (colW) {
|
|
153
|
+
const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];
|
|
154
|
+
if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
|
|
155
|
+
colWidths[widthIndex] = colW;
|
|
156
|
+
colWidths[widthIndex + 1] = 1;
|
|
157
|
+
} else if (prev == colW) colWidths[widthIndex + 1]++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
mapPos += colspan;
|
|
162
|
+
pos += cellNode.nodeSize;
|
|
163
|
+
}
|
|
164
|
+
const expectedPos = (row + 1) * width;
|
|
165
|
+
let missing = 0;
|
|
166
|
+
while (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;
|
|
167
|
+
if (missing) (problems || (problems = [])).push({
|
|
168
|
+
type: "missing",
|
|
169
|
+
row,
|
|
170
|
+
n: missing
|
|
171
|
+
});
|
|
172
|
+
pos++;
|
|
173
|
+
}
|
|
174
|
+
if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
|
|
175
|
+
const tableMap = new TableMap(width, height, map, problems);
|
|
176
|
+
let badWidths = false;
|
|
177
|
+
for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
|
|
178
|
+
if (badWidths) findBadColWidths(tableMap, colWidths, table);
|
|
179
|
+
return tableMap;
|
|
180
|
+
}
|
|
181
|
+
function findWidth(table) {
|
|
182
|
+
let width = -1;
|
|
183
|
+
let hasRowSpan = false;
|
|
184
|
+
for (let row = 0; row < table.childCount; row++) {
|
|
185
|
+
const rowNode = table.child(row);
|
|
186
|
+
let rowWidth = 0;
|
|
187
|
+
if (hasRowSpan) for (let j = 0; j < row; j++) {
|
|
188
|
+
const prevRow = table.child(j);
|
|
189
|
+
for (let i = 0; i < prevRow.childCount; i++) {
|
|
190
|
+
const cell = prevRow.child(i);
|
|
191
|
+
if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (let i = 0; i < rowNode.childCount; i++) {
|
|
195
|
+
const cell = rowNode.child(i);
|
|
196
|
+
rowWidth += cell.attrs.colspan;
|
|
197
|
+
if (cell.attrs.rowspan > 1) hasRowSpan = true;
|
|
198
|
+
}
|
|
199
|
+
if (width == -1) width = rowWidth;
|
|
200
|
+
else if (width != rowWidth) width = Math.max(width, rowWidth);
|
|
201
|
+
}
|
|
202
|
+
return width;
|
|
203
|
+
}
|
|
204
|
+
function findBadColWidths(map, colWidths, table) {
|
|
205
|
+
if (!map.problems) map.problems = [];
|
|
206
|
+
const seen = {};
|
|
207
|
+
for (let i = 0; i < map.map.length; i++) {
|
|
208
|
+
const pos = map.map[i];
|
|
209
|
+
if (seen[pos]) continue;
|
|
210
|
+
seen[pos] = true;
|
|
211
|
+
const node = table.nodeAt(pos);
|
|
212
|
+
if (!node) throw new RangeError(`No cell with offset ${pos} found`);
|
|
213
|
+
let updated = null;
|
|
214
|
+
const attrs = node.attrs;
|
|
215
|
+
for (let j = 0; j < attrs.colspan; j++) {
|
|
216
|
+
const colWidth = colWidths[(i + j) % map.width * 2];
|
|
217
|
+
if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
|
|
218
|
+
}
|
|
219
|
+
if (updated) map.problems.unshift({
|
|
220
|
+
type: "colwidth mismatch",
|
|
221
|
+
pos,
|
|
222
|
+
colwidth: updated
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function freshColWidth(attrs) {
|
|
227
|
+
if (attrs.colwidth) return attrs.colwidth.slice();
|
|
228
|
+
const result = [];
|
|
229
|
+
for (let i = 0; i < attrs.colspan; i++) result.push(0);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/schema.ts
|
|
235
|
+
function getCellAttrs(dom, extraAttrs) {
|
|
236
|
+
if (typeof dom === "string") return {};
|
|
237
|
+
const widthAttr = dom.getAttribute("data-colwidth");
|
|
238
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
|
|
239
|
+
const colspan = Number(dom.getAttribute("colspan") || 1);
|
|
240
|
+
const result = {
|
|
241
|
+
colspan,
|
|
242
|
+
rowspan: Number(dom.getAttribute("rowspan") || 1),
|
|
243
|
+
colwidth: widths && widths.length == colspan ? widths : null
|
|
244
|
+
};
|
|
245
|
+
for (const prop in extraAttrs) {
|
|
246
|
+
const getter = extraAttrs[prop].getFromDOM;
|
|
247
|
+
const value = getter && getter(dom);
|
|
248
|
+
if (value != null) result[prop] = value;
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
function setCellAttrs(node, extraAttrs) {
|
|
253
|
+
const attrs = {};
|
|
254
|
+
if (node.attrs.colspan != 1) attrs.colspan = node.attrs.colspan;
|
|
255
|
+
if (node.attrs.rowspan != 1) attrs.rowspan = node.attrs.rowspan;
|
|
256
|
+
if (node.attrs.colwidth) attrs["data-colwidth"] = node.attrs.colwidth.join(",");
|
|
257
|
+
for (const prop in extraAttrs) {
|
|
258
|
+
const setter = extraAttrs[prop].setDOMAttr;
|
|
259
|
+
if (setter) setter(node.attrs[prop], attrs);
|
|
260
|
+
}
|
|
261
|
+
return attrs;
|
|
262
|
+
}
|
|
263
|
+
function validateColwidth(value) {
|
|
264
|
+
if (value === null) return;
|
|
265
|
+
if (!Array.isArray(value)) throw new TypeError("colwidth must be null or an array");
|
|
266
|
+
for (const item of value) if (typeof item !== "number") throw new TypeError("colwidth must be null or an array of numbers");
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* This function creates a set of [node
|
|
270
|
+
* specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for
|
|
271
|
+
* `table`, `table_row`, and `table_cell` nodes types as used by this
|
|
272
|
+
* module. The result can then be added to the set of nodes when
|
|
273
|
+
* creating a schema.
|
|
274
|
+
*
|
|
275
|
+
* @public
|
|
276
|
+
*/
|
|
277
|
+
function tableNodes(options) {
|
|
278
|
+
const extraAttrs = options.cellAttributes || {};
|
|
279
|
+
const cellAttrs = {
|
|
280
|
+
colspan: {
|
|
281
|
+
default: 1,
|
|
282
|
+
validate: "number"
|
|
283
|
+
},
|
|
284
|
+
rowspan: {
|
|
285
|
+
default: 1,
|
|
286
|
+
validate: "number"
|
|
287
|
+
},
|
|
288
|
+
colwidth: {
|
|
289
|
+
default: null,
|
|
290
|
+
validate: validateColwidth
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
for (const prop in extraAttrs) cellAttrs[prop] = {
|
|
294
|
+
default: extraAttrs[prop].default,
|
|
295
|
+
validate: extraAttrs[prop].validate
|
|
296
|
+
};
|
|
297
|
+
return {
|
|
298
|
+
table: {
|
|
299
|
+
content: "table_row+",
|
|
300
|
+
tableRole: "table",
|
|
301
|
+
isolating: true,
|
|
302
|
+
group: options.tableGroup,
|
|
303
|
+
parseDOM: [{ tag: "table" }],
|
|
304
|
+
toDOM() {
|
|
305
|
+
return ["table", ["tbody", 0]];
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
table_row: {
|
|
309
|
+
content: "(table_cell | table_header)*",
|
|
310
|
+
tableRole: "row",
|
|
311
|
+
parseDOM: [{ tag: "tr" }],
|
|
312
|
+
toDOM() {
|
|
313
|
+
return ["tr", 0];
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
table_cell: {
|
|
317
|
+
content: options.cellContent,
|
|
318
|
+
attrs: cellAttrs,
|
|
319
|
+
tableRole: "cell",
|
|
320
|
+
isolating: true,
|
|
321
|
+
parseDOM: [{
|
|
322
|
+
tag: "td",
|
|
323
|
+
getAttrs: (dom) => getCellAttrs(dom, extraAttrs)
|
|
324
|
+
}],
|
|
325
|
+
toDOM(node) {
|
|
326
|
+
return [
|
|
327
|
+
"td",
|
|
328
|
+
setCellAttrs(node, extraAttrs),
|
|
329
|
+
0
|
|
330
|
+
];
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
table_header: {
|
|
334
|
+
content: options.cellContent,
|
|
335
|
+
attrs: cellAttrs,
|
|
336
|
+
tableRole: "header_cell",
|
|
337
|
+
isolating: true,
|
|
338
|
+
parseDOM: [{
|
|
339
|
+
tag: "th",
|
|
340
|
+
getAttrs: (dom) => getCellAttrs(dom, extraAttrs)
|
|
341
|
+
}],
|
|
342
|
+
toDOM(node) {
|
|
343
|
+
return [
|
|
344
|
+
"th",
|
|
345
|
+
setCellAttrs(node, extraAttrs),
|
|
346
|
+
0
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @public
|
|
354
|
+
*/
|
|
355
|
+
function tableNodeTypes(schema) {
|
|
356
|
+
let result = schema.cached.tableNodeTypes;
|
|
357
|
+
if (!result) {
|
|
358
|
+
result = schema.cached.tableNodeTypes = {};
|
|
359
|
+
for (const name in schema.nodes) {
|
|
360
|
+
const type = schema.nodes[name], role = type.spec.tableRole;
|
|
361
|
+
if (role) result[role] = type;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/util.ts
|
|
369
|
+
/**
|
|
370
|
+
* @public
|
|
371
|
+
*/
|
|
372
|
+
const tableEditingKey = new PluginKey("selectingCells");
|
|
373
|
+
/**
|
|
374
|
+
* @public
|
|
375
|
+
*/
|
|
376
|
+
function cellAround($pos) {
|
|
377
|
+
for (let d = $pos.depth - 1; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1));
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
function cellWrapping($pos) {
|
|
381
|
+
for (let d = $pos.depth; d > 0; d--) {
|
|
382
|
+
const role = $pos.node(d).type.spec.tableRole;
|
|
383
|
+
if (role === "cell" || role === "header_cell") return $pos.node(d);
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @public
|
|
389
|
+
*/
|
|
390
|
+
function isInTable(state) {
|
|
391
|
+
const $head = state.selection.$head;
|
|
392
|
+
for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true;
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @internal
|
|
397
|
+
*/
|
|
398
|
+
function selectionCell(state) {
|
|
399
|
+
const sel = state.selection;
|
|
400
|
+
if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
|
|
401
|
+
else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
|
|
402
|
+
const $cell = cellAround(sel.$head) || cellNear(sel.$head);
|
|
403
|
+
if ($cell) return $cell;
|
|
404
|
+
throw new RangeError(`No cell found around position ${sel.head}`);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* @public
|
|
408
|
+
*/
|
|
409
|
+
function cellNear($pos) {
|
|
410
|
+
for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
|
|
411
|
+
const role = after.type.spec.tableRole;
|
|
412
|
+
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos);
|
|
413
|
+
}
|
|
414
|
+
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
415
|
+
const role = before.type.spec.tableRole;
|
|
416
|
+
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @public
|
|
421
|
+
*/
|
|
422
|
+
function pointsAtCell($pos) {
|
|
423
|
+
return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @public
|
|
427
|
+
*/
|
|
428
|
+
function moveCellForward($pos) {
|
|
429
|
+
return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* @internal
|
|
433
|
+
*/
|
|
434
|
+
function inSameTable($cellA, $cellB) {
|
|
435
|
+
return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* @public
|
|
439
|
+
*/
|
|
440
|
+
function findCell($pos) {
|
|
441
|
+
return TableMap.get($pos.node(-1)).findCell($pos.pos - $pos.start(-1));
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* @public
|
|
445
|
+
*/
|
|
446
|
+
function colCount($pos) {
|
|
447
|
+
return TableMap.get($pos.node(-1)).colCount($pos.pos - $pos.start(-1));
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* @public
|
|
451
|
+
*/
|
|
452
|
+
function nextCell($pos, axis, dir) {
|
|
453
|
+
const table = $pos.node(-1);
|
|
454
|
+
const map = TableMap.get(table);
|
|
455
|
+
const tableStart = $pos.start(-1);
|
|
456
|
+
const moved = map.nextCell($pos.pos - tableStart, axis, dir);
|
|
457
|
+
return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @public
|
|
461
|
+
*/
|
|
462
|
+
function removeColSpan(attrs, pos, n = 1) {
|
|
463
|
+
const result = {
|
|
464
|
+
...attrs,
|
|
465
|
+
colspan: attrs.colspan - n
|
|
466
|
+
};
|
|
467
|
+
if (result.colwidth) {
|
|
468
|
+
result.colwidth = result.colwidth.slice();
|
|
469
|
+
result.colwidth.splice(pos, n);
|
|
470
|
+
if (!result.colwidth.some((w) => w > 0)) result.colwidth = null;
|
|
471
|
+
}
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* @public
|
|
476
|
+
*/
|
|
477
|
+
function addColSpan(attrs, pos, n = 1) {
|
|
478
|
+
const result = {
|
|
479
|
+
...attrs,
|
|
480
|
+
colspan: attrs.colspan + n
|
|
481
|
+
};
|
|
482
|
+
if (result.colwidth) {
|
|
483
|
+
result.colwidth = result.colwidth.slice();
|
|
484
|
+
for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
|
|
485
|
+
}
|
|
486
|
+
return result;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* @public
|
|
490
|
+
*/
|
|
491
|
+
function columnIsHeader(map, table, col) {
|
|
492
|
+
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
493
|
+
for (let row = 0; row < map.height; row++) if (table.nodeAt(map.map[col + row * map.width]).type != headerCell) return false;
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/cellselection.ts
|
|
499
|
+
/**
|
|
500
|
+
* A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
|
|
501
|
+
* subclass that represents a cell selection spanning part of a table.
|
|
502
|
+
* With the plugin enabled, these will be created when the user
|
|
503
|
+
* selects across cells, and will be drawn by giving selected cells a
|
|
504
|
+
* `selectedCell` CSS class.
|
|
505
|
+
*
|
|
506
|
+
* @public
|
|
507
|
+
*/
|
|
508
|
+
var CellSelection = class CellSelection extends Selection {
|
|
509
|
+
constructor($anchorCell, $headCell = $anchorCell) {
|
|
510
|
+
const table = $anchorCell.node(-1);
|
|
511
|
+
const map = TableMap.get(table);
|
|
512
|
+
const tableStart = $anchorCell.start(-1);
|
|
513
|
+
const rect = map.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
|
|
514
|
+
const doc = $anchorCell.node(0);
|
|
515
|
+
const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
|
|
516
|
+
cells.unshift($headCell.pos - tableStart);
|
|
517
|
+
const ranges = cells.map((pos) => {
|
|
518
|
+
const cell = table.nodeAt(pos);
|
|
519
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
520
|
+
const from = tableStart + pos + 1;
|
|
521
|
+
return new SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));
|
|
522
|
+
});
|
|
523
|
+
super(ranges[0].$from, ranges[0].$to, ranges);
|
|
524
|
+
this.$anchorCell = $anchorCell;
|
|
525
|
+
this.$headCell = $headCell;
|
|
526
|
+
}
|
|
527
|
+
map(doc, mapping) {
|
|
528
|
+
const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
|
|
529
|
+
const $headCell = doc.resolve(mapping.map(this.$headCell.pos));
|
|
530
|
+
if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
|
|
531
|
+
const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
|
|
532
|
+
if (tableChanged && this.isRowSelection()) return CellSelection.rowSelection($anchorCell, $headCell);
|
|
533
|
+
else if (tableChanged && this.isColSelection()) return CellSelection.colSelection($anchorCell, $headCell);
|
|
534
|
+
else return new CellSelection($anchorCell, $headCell);
|
|
535
|
+
}
|
|
536
|
+
return TextSelection.between($anchorCell, $headCell);
|
|
537
|
+
}
|
|
538
|
+
content() {
|
|
539
|
+
const table = this.$anchorCell.node(-1);
|
|
540
|
+
const map = TableMap.get(table);
|
|
541
|
+
const tableStart = this.$anchorCell.start(-1);
|
|
542
|
+
const rect = map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
|
|
543
|
+
const seen = {};
|
|
544
|
+
const rows = [];
|
|
545
|
+
for (let row = rect.top; row < rect.bottom; row++) {
|
|
546
|
+
const rowContent = [];
|
|
547
|
+
for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
|
|
548
|
+
const pos = map.map[index];
|
|
549
|
+
if (seen[pos]) continue;
|
|
550
|
+
seen[pos] = true;
|
|
551
|
+
const cellRect = map.findCell(pos);
|
|
552
|
+
let cell = table.nodeAt(pos);
|
|
553
|
+
if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
|
|
554
|
+
const extraLeft = rect.left - cellRect.left;
|
|
555
|
+
const extraRight = cellRect.right - rect.right;
|
|
556
|
+
if (extraLeft > 0 || extraRight > 0) {
|
|
557
|
+
let attrs = cell.attrs;
|
|
558
|
+
if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
|
|
559
|
+
if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
|
|
560
|
+
if (cellRect.left < rect.left) {
|
|
561
|
+
cell = cell.type.createAndFill(attrs);
|
|
562
|
+
if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
|
|
563
|
+
} else cell = cell.type.create(attrs, cell.content);
|
|
564
|
+
}
|
|
565
|
+
if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
|
|
566
|
+
const attrs = {
|
|
567
|
+
...cell.attrs,
|
|
568
|
+
rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
|
|
569
|
+
};
|
|
570
|
+
if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
|
|
571
|
+
else cell = cell.type.create(attrs, cell.content);
|
|
572
|
+
}
|
|
573
|
+
rowContent.push(cell);
|
|
574
|
+
}
|
|
575
|
+
rows.push(table.child(row).copy(Fragment.from(rowContent)));
|
|
576
|
+
}
|
|
577
|
+
const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
|
|
578
|
+
return new Slice(Fragment.from(fragment), 1, 1);
|
|
579
|
+
}
|
|
580
|
+
replace(tr, content = Slice.empty) {
|
|
581
|
+
const mapFrom = tr.steps.length, ranges = this.ranges;
|
|
582
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
583
|
+
const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
|
|
584
|
+
tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
|
|
585
|
+
}
|
|
586
|
+
const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
|
|
587
|
+
if (sel) tr.setSelection(sel);
|
|
588
|
+
}
|
|
589
|
+
replaceWith(tr, node) {
|
|
590
|
+
this.replace(tr, new Slice(Fragment.from(node), 0, 0));
|
|
591
|
+
}
|
|
592
|
+
forEachCell(f) {
|
|
593
|
+
const table = this.$anchorCell.node(-1);
|
|
594
|
+
const map = TableMap.get(table);
|
|
595
|
+
const tableStart = this.$anchorCell.start(-1);
|
|
596
|
+
const cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
|
|
597
|
+
for (let i = 0; i < cells.length; i++) f(table.nodeAt(cells[i]), tableStart + cells[i]);
|
|
598
|
+
}
|
|
599
|
+
isColSelection() {
|
|
600
|
+
const anchorTop = this.$anchorCell.index(-1);
|
|
601
|
+
const headTop = this.$headCell.index(-1);
|
|
602
|
+
if (Math.min(anchorTop, headTop) > 0) return false;
|
|
603
|
+
const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
|
|
604
|
+
const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
|
|
605
|
+
return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
|
|
606
|
+
}
|
|
607
|
+
static colSelection($anchorCell, $headCell = $anchorCell) {
|
|
608
|
+
const table = $anchorCell.node(-1);
|
|
609
|
+
const map = TableMap.get(table);
|
|
610
|
+
const tableStart = $anchorCell.start(-1);
|
|
611
|
+
const anchorRect = map.findCell($anchorCell.pos - tableStart);
|
|
612
|
+
const headRect = map.findCell($headCell.pos - tableStart);
|
|
613
|
+
const doc = $anchorCell.node(0);
|
|
614
|
+
if (anchorRect.top <= headRect.top) {
|
|
615
|
+
if (anchorRect.top > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);
|
|
616
|
+
if (headRect.bottom < map.height) $headCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]);
|
|
617
|
+
} else {
|
|
618
|
+
if (headRect.top > 0) $headCell = doc.resolve(tableStart + map.map[headRect.left]);
|
|
619
|
+
if (anchorRect.bottom < map.height) $anchorCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]);
|
|
620
|
+
}
|
|
621
|
+
return new CellSelection($anchorCell, $headCell);
|
|
622
|
+
}
|
|
623
|
+
isRowSelection() {
|
|
624
|
+
const table = this.$anchorCell.node(-1);
|
|
625
|
+
const map = TableMap.get(table);
|
|
626
|
+
const tableStart = this.$anchorCell.start(-1);
|
|
627
|
+
const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);
|
|
628
|
+
const headLeft = map.colCount(this.$headCell.pos - tableStart);
|
|
629
|
+
if (Math.min(anchorLeft, headLeft) > 0) return false;
|
|
630
|
+
const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
|
|
631
|
+
const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
|
|
632
|
+
return Math.max(anchorRight, headRight) == map.width;
|
|
633
|
+
}
|
|
634
|
+
eq(other) {
|
|
635
|
+
return other instanceof CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
|
|
636
|
+
}
|
|
637
|
+
static rowSelection($anchorCell, $headCell = $anchorCell) {
|
|
638
|
+
const table = $anchorCell.node(-1);
|
|
639
|
+
const map = TableMap.get(table);
|
|
640
|
+
const tableStart = $anchorCell.start(-1);
|
|
641
|
+
const anchorRect = map.findCell($anchorCell.pos - tableStart);
|
|
642
|
+
const headRect = map.findCell($headCell.pos - tableStart);
|
|
643
|
+
const doc = $anchorCell.node(0);
|
|
644
|
+
if (anchorRect.left <= headRect.left) {
|
|
645
|
+
if (anchorRect.left > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.top * map.width]);
|
|
646
|
+
if (headRect.right < map.width) $headCell = doc.resolve(tableStart + map.map[map.width * (headRect.top + 1) - 1]);
|
|
647
|
+
} else {
|
|
648
|
+
if (headRect.left > 0) $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);
|
|
649
|
+
if (anchorRect.right < map.width) $anchorCell = doc.resolve(tableStart + map.map[map.width * (anchorRect.top + 1) - 1]);
|
|
650
|
+
}
|
|
651
|
+
return new CellSelection($anchorCell, $headCell);
|
|
652
|
+
}
|
|
653
|
+
toJSON() {
|
|
654
|
+
return {
|
|
655
|
+
type: "cell",
|
|
656
|
+
anchor: this.$anchorCell.pos,
|
|
657
|
+
head: this.$headCell.pos
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
static fromJSON(doc, json) {
|
|
661
|
+
return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
|
|
662
|
+
}
|
|
663
|
+
static create(doc, anchorCell, headCell = anchorCell) {
|
|
664
|
+
return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
|
|
665
|
+
}
|
|
666
|
+
getBookmark() {
|
|
667
|
+
return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
CellSelection.prototype.visible = false;
|
|
671
|
+
Selection.jsonID("cell", CellSelection);
|
|
672
|
+
/**
|
|
673
|
+
* @public
|
|
674
|
+
*/
|
|
675
|
+
var CellBookmark = class CellBookmark {
|
|
676
|
+
constructor(anchor, head) {
|
|
677
|
+
this.anchor = anchor;
|
|
678
|
+
this.head = head;
|
|
679
|
+
}
|
|
680
|
+
map(mapping) {
|
|
681
|
+
return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
682
|
+
}
|
|
683
|
+
resolve(doc) {
|
|
684
|
+
const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
|
|
685
|
+
if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);
|
|
686
|
+
else return Selection.near($headCell, 1);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
function drawCellSelection(state) {
|
|
690
|
+
if (!(state.selection instanceof CellSelection)) return null;
|
|
691
|
+
const cells = [];
|
|
692
|
+
state.selection.forEachCell((node, pos) => {
|
|
693
|
+
cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
|
|
694
|
+
});
|
|
695
|
+
return DecorationSet.create(state.doc, cells);
|
|
696
|
+
}
|
|
697
|
+
function isCellBoundarySelection({ $from, $to }) {
|
|
698
|
+
if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;
|
|
699
|
+
let afterFrom = $from.pos;
|
|
700
|
+
let beforeTo = $to.pos;
|
|
701
|
+
let depth = $from.depth;
|
|
702
|
+
for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
|
|
703
|
+
for (let d = $to.depth; d >= 0; d--, beforeTo--) if ($to.before(d + 1) > $to.start(d)) break;
|
|
704
|
+
return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
|
|
705
|
+
}
|
|
706
|
+
function isTextSelectionAcrossCells({ $from, $to }) {
|
|
707
|
+
let fromCellBoundaryNode;
|
|
708
|
+
let toCellBoundaryNode;
|
|
709
|
+
for (let i = $from.depth; i > 0; i--) {
|
|
710
|
+
const node = $from.node(i);
|
|
711
|
+
if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
|
|
712
|
+
fromCellBoundaryNode = node;
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
for (let i = $to.depth; i > 0; i--) {
|
|
717
|
+
const node = $to.node(i);
|
|
718
|
+
if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
|
|
719
|
+
toCellBoundaryNode = node;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
|
|
724
|
+
}
|
|
725
|
+
function normalizeSelection(state, tr, allowTableNodeSelection) {
|
|
726
|
+
const sel = (tr || state).selection;
|
|
727
|
+
const doc = (tr || state).doc;
|
|
728
|
+
let normalize;
|
|
729
|
+
let role;
|
|
730
|
+
if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
|
|
731
|
+
if (role == "cell" || role == "header_cell") normalize = CellSelection.create(doc, sel.from);
|
|
732
|
+
else if (role == "row") {
|
|
733
|
+
const $cell = doc.resolve(sel.from + 1);
|
|
734
|
+
normalize = CellSelection.rowSelection($cell, $cell);
|
|
735
|
+
} else if (!allowTableNodeSelection) {
|
|
736
|
+
const map = TableMap.get(sel.node);
|
|
737
|
+
const start = sel.from + 1;
|
|
738
|
+
const lastCell = start + map.map[map.width * map.height - 1];
|
|
739
|
+
normalize = CellSelection.create(doc, start + 1, lastCell);
|
|
740
|
+
}
|
|
741
|
+
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize = TextSelection.create(doc, sel.from);
|
|
742
|
+
else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
|
|
743
|
+
if (normalize) (tr || (tr = state.tr)).setSelection(normalize);
|
|
744
|
+
return tr;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/fixtables.ts
|
|
749
|
+
/**
|
|
750
|
+
* @public
|
|
751
|
+
*/
|
|
752
|
+
const fixTablesKey = new PluginKey("fix-tables");
|
|
753
|
+
/**
|
|
754
|
+
* Helper for iterating through the nodes in a document that changed
|
|
755
|
+
* compared to the given previous document. Useful for avoiding
|
|
756
|
+
* duplicate work on each transaction.
|
|
757
|
+
*
|
|
758
|
+
* @public
|
|
759
|
+
*/
|
|
760
|
+
function changedDescendants(old, cur, offset, f) {
|
|
761
|
+
const oldSize = old.childCount, curSize = cur.childCount;
|
|
762
|
+
outer: for (let i = 0, j = 0; i < curSize; i++) {
|
|
763
|
+
const child = cur.child(i);
|
|
764
|
+
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {
|
|
765
|
+
j = scan + 1;
|
|
766
|
+
offset += child.nodeSize;
|
|
767
|
+
continue outer;
|
|
768
|
+
}
|
|
769
|
+
f(child, offset);
|
|
770
|
+
if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset + 1, f);
|
|
771
|
+
else child.nodesBetween(0, child.content.size, f, offset + 1);
|
|
772
|
+
offset += child.nodeSize;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Inspect all tables in the given state's document and return a
|
|
777
|
+
* transaction that fixes them, if necessary. If `oldState` was
|
|
778
|
+
* provided, that is assumed to hold a previous, known-good state,
|
|
779
|
+
* which will be used to avoid re-scanning unchanged parts of the
|
|
780
|
+
* document.
|
|
781
|
+
*
|
|
782
|
+
* @public
|
|
783
|
+
*/
|
|
784
|
+
function fixTables(state, oldState) {
|
|
785
|
+
let tr;
|
|
786
|
+
const check = (node, pos) => {
|
|
787
|
+
if (node.type.spec.tableRole == "table") tr = fixTable(state, node, pos, tr);
|
|
788
|
+
};
|
|
789
|
+
if (!oldState) state.doc.descendants(check);
|
|
790
|
+
else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);
|
|
791
|
+
return tr;
|
|
792
|
+
}
|
|
793
|
+
function fixTable(state, table, tablePos, tr) {
|
|
794
|
+
const map = TableMap.get(table);
|
|
795
|
+
if (!map.problems) return tr;
|
|
796
|
+
if (!tr) tr = state.tr;
|
|
797
|
+
const mustAdd = [];
|
|
798
|
+
for (let i = 0; i < map.height; i++) mustAdd.push(0);
|
|
799
|
+
for (let i = 0; i < map.problems.length; i++) {
|
|
800
|
+
const prob = map.problems[i];
|
|
801
|
+
if (prob.type == "collision") {
|
|
802
|
+
const cell = table.nodeAt(prob.pos);
|
|
803
|
+
if (!cell) continue;
|
|
804
|
+
const attrs = cell.attrs;
|
|
805
|
+
for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
|
|
806
|
+
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
|
|
807
|
+
} else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
|
|
808
|
+
else if (prob.type == "overlong_rowspan") {
|
|
809
|
+
const cell = table.nodeAt(prob.pos);
|
|
810
|
+
if (!cell) continue;
|
|
811
|
+
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
|
|
812
|
+
...cell.attrs,
|
|
813
|
+
rowspan: cell.attrs.rowspan - prob.n
|
|
814
|
+
});
|
|
815
|
+
} else if (prob.type == "colwidth mismatch") {
|
|
816
|
+
const cell = table.nodeAt(prob.pos);
|
|
817
|
+
if (!cell) continue;
|
|
818
|
+
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
|
|
819
|
+
...cell.attrs,
|
|
820
|
+
colwidth: prob.colwidth
|
|
821
|
+
});
|
|
822
|
+
} else if (prob.type == "zero_sized") {
|
|
823
|
+
const pos = tr.mapping.map(tablePos);
|
|
824
|
+
tr.delete(pos, pos + table.nodeSize);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
let first, last;
|
|
828
|
+
for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
|
|
829
|
+
if (first == null) first = i;
|
|
830
|
+
last = i;
|
|
831
|
+
}
|
|
832
|
+
for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
|
|
833
|
+
const row = table.child(i);
|
|
834
|
+
const end = pos + row.nodeSize;
|
|
835
|
+
const add = mustAdd[i];
|
|
836
|
+
if (add > 0) {
|
|
837
|
+
let role = "cell";
|
|
838
|
+
if (row.firstChild) role = row.firstChild.type.spec.tableRole;
|
|
839
|
+
const nodes = [];
|
|
840
|
+
for (let j = 0; j < add; j++) {
|
|
841
|
+
const node = tableNodeTypes(state.schema)[role].createAndFill();
|
|
842
|
+
if (node) nodes.push(node);
|
|
843
|
+
}
|
|
844
|
+
const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
|
|
845
|
+
tr.insert(tr.mapping.map(side), nodes);
|
|
846
|
+
}
|
|
847
|
+
pos = end;
|
|
848
|
+
}
|
|
849
|
+
return tr.setMeta(fixTablesKey, { fixTables: true });
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/utils/convert.ts
|
|
854
|
+
/**
|
|
855
|
+
* This function will transform the table node into a matrix of rows and columns
|
|
856
|
+
* respecting merged cells, for example this table:
|
|
857
|
+
*
|
|
858
|
+
* ```
|
|
859
|
+
* ┌──────┬──────┬─────────────┐
|
|
860
|
+
* │ A1 │ B1 │ C1 │
|
|
861
|
+
* ├──────┼──────┴──────┬──────┤
|
|
862
|
+
* │ A2 │ B2 │ │
|
|
863
|
+
* ├──────┼─────────────┤ D1 │
|
|
864
|
+
* │ A3 │ B3 │ C3 │ │
|
|
865
|
+
* └──────┴──────┴──────┴──────┘
|
|
866
|
+
* ```
|
|
867
|
+
*
|
|
868
|
+
* will be converted to the below:
|
|
869
|
+
*
|
|
870
|
+
* ```javascript
|
|
871
|
+
* [
|
|
872
|
+
* [A1, B1, C1, null],
|
|
873
|
+
* [A2, B2, null, D1],
|
|
874
|
+
* [A3, B3, C3, null],
|
|
875
|
+
* ]
|
|
876
|
+
* ```
|
|
877
|
+
* @internal
|
|
878
|
+
*/
|
|
879
|
+
function convertTableNodeToArrayOfRows(tableNode) {
|
|
880
|
+
const map = TableMap.get(tableNode);
|
|
881
|
+
const rows = [];
|
|
882
|
+
const rowCount = map.height;
|
|
883
|
+
const colCount$1 = map.width;
|
|
884
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
885
|
+
const row = [];
|
|
886
|
+
for (let colIndex = 0; colIndex < colCount$1; colIndex++) {
|
|
887
|
+
const cellIndex = rowIndex * colCount$1 + colIndex;
|
|
888
|
+
const cellPos = map.map[cellIndex];
|
|
889
|
+
if (rowIndex > 0) {
|
|
890
|
+
const topCellIndex = cellIndex - colCount$1;
|
|
891
|
+
if (cellPos === map.map[topCellIndex]) {
|
|
892
|
+
row.push(null);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (colIndex > 0) {
|
|
897
|
+
const leftCellIndex = cellIndex - 1;
|
|
898
|
+
if (cellPos === map.map[leftCellIndex]) {
|
|
899
|
+
row.push(null);
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
row.push(tableNode.nodeAt(cellPos));
|
|
904
|
+
}
|
|
905
|
+
rows.push(row);
|
|
906
|
+
}
|
|
907
|
+
return rows;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Convert an array of rows to a table node.
|
|
911
|
+
*
|
|
912
|
+
* @internal
|
|
913
|
+
*/
|
|
914
|
+
function convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {
|
|
915
|
+
const newRows = [];
|
|
916
|
+
const map = TableMap.get(tableNode);
|
|
917
|
+
const rowCount = map.height;
|
|
918
|
+
const colCount$1 = map.width;
|
|
919
|
+
for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
920
|
+
const oldRow = tableNode.child(rowIndex);
|
|
921
|
+
const newCells = [];
|
|
922
|
+
for (let colIndex = 0; colIndex < colCount$1; colIndex++) {
|
|
923
|
+
const cell = arrayOfNodes[rowIndex][colIndex];
|
|
924
|
+
if (!cell) continue;
|
|
925
|
+
const cellPos = map.map[rowIndex * map.width + colIndex];
|
|
926
|
+
const oldCell = tableNode.nodeAt(cellPos);
|
|
927
|
+
if (!oldCell) continue;
|
|
928
|
+
const newCell = oldCell.type.createChecked(cell.attrs, cell.content, cell.marks);
|
|
929
|
+
newCells.push(newCell);
|
|
930
|
+
}
|
|
931
|
+
const newRow = oldRow.type.createChecked(oldRow.attrs, newCells, oldRow.marks);
|
|
932
|
+
newRows.push(newRow);
|
|
933
|
+
}
|
|
934
|
+
return tableNode.type.createChecked(tableNode.attrs, newRows, tableNode.marks);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/utils/move-row-in-array-of-rows.ts
|
|
939
|
+
/**
|
|
940
|
+
* Move a row in an array of rows.
|
|
941
|
+
*
|
|
942
|
+
* @internal
|
|
943
|
+
*/
|
|
944
|
+
function moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) {
|
|
945
|
+
const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;
|
|
946
|
+
const rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length);
|
|
947
|
+
const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;
|
|
948
|
+
let target;
|
|
949
|
+
if (directionOverride === -1 && direction === 1) target = indexesTarget[0] - 1;
|
|
950
|
+
else if (directionOverride === 1 && direction === -1) target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1;
|
|
951
|
+
else target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;
|
|
952
|
+
rows.splice(target, 0, ...rowsExtracted);
|
|
953
|
+
return rows;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
//#endregion
|
|
957
|
+
//#region src/utils/query.ts
|
|
958
|
+
/**
|
|
959
|
+
* Checks if the given object is a `CellSelection` instance.
|
|
960
|
+
*
|
|
961
|
+
* @internal
|
|
962
|
+
*/
|
|
963
|
+
function isCellSelection(value) {
|
|
964
|
+
return value instanceof CellSelection;
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Find the closest table node for a given position.
|
|
968
|
+
*
|
|
969
|
+
* @public
|
|
970
|
+
*/
|
|
971
|
+
function findTable($pos) {
|
|
972
|
+
return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Try to find the anchor and head cell in the same table by using the given
|
|
976
|
+
* anchor and head as hit points, or fallback to the selection's anchor and
|
|
977
|
+
* head.
|
|
978
|
+
*
|
|
979
|
+
* @public
|
|
980
|
+
*/
|
|
981
|
+
function findCellRange(selection, anchorHit, headHit) {
|
|
982
|
+
var _ref, _ref2;
|
|
983
|
+
if (anchorHit == null && headHit == null && isCellSelection(selection)) return [selection.$anchorCell, selection.$headCell];
|
|
984
|
+
const anchor = (_ref = anchorHit !== null && anchorHit !== void 0 ? anchorHit : headHit) !== null && _ref !== void 0 ? _ref : selection.anchor;
|
|
985
|
+
const head = (_ref2 = headHit !== null && headHit !== void 0 ? headHit : anchorHit) !== null && _ref2 !== void 0 ? _ref2 : selection.head;
|
|
986
|
+
const doc = selection.$head.doc;
|
|
987
|
+
const $anchorCell = findCellPos(doc, anchor);
|
|
988
|
+
const $headCell = findCellPos(doc, head);
|
|
989
|
+
if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) return [$anchorCell, $headCell];
|
|
990
|
+
return null;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Try to find a resolved pos of a cell by using the given pos as a hit point.
|
|
994
|
+
*
|
|
995
|
+
* @public
|
|
996
|
+
*/
|
|
997
|
+
function findCellPos(doc, pos) {
|
|
998
|
+
const $pos = doc.resolve(pos);
|
|
999
|
+
return cellAround($pos) || cellNear($pos);
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Find the closest parent node that satisfies the predicate.
|
|
1003
|
+
*
|
|
1004
|
+
* @internal
|
|
1005
|
+
*/
|
|
1006
|
+
function findParentNode(predicate, $pos) {
|
|
1007
|
+
for (let depth = $pos.depth; depth >= 0; depth -= 1) {
|
|
1008
|
+
const node = $pos.node(depth);
|
|
1009
|
+
if (predicate(node)) return {
|
|
1010
|
+
node,
|
|
1011
|
+
pos: depth === 0 ? 0 : $pos.before(depth),
|
|
1012
|
+
start: $pos.start(depth),
|
|
1013
|
+
depth
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
return null;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region src/utils/get-cells.ts
|
|
1021
|
+
/**
|
|
1022
|
+
* Returns an array of cells in a column at the specified column index.
|
|
1023
|
+
*
|
|
1024
|
+
* @internal
|
|
1025
|
+
*/
|
|
1026
|
+
function getCellsInColumn(columnIndex, selection) {
|
|
1027
|
+
const table = findTable(selection.$from);
|
|
1028
|
+
if (!table) return;
|
|
1029
|
+
const map = TableMap.get(table.node);
|
|
1030
|
+
if (columnIndex < 0 || columnIndex > map.width - 1) return;
|
|
1031
|
+
return map.cellsInRect({
|
|
1032
|
+
left: columnIndex,
|
|
1033
|
+
right: columnIndex + 1,
|
|
1034
|
+
top: 0,
|
|
1035
|
+
bottom: map.height
|
|
1036
|
+
}).map((nodePos) => {
|
|
1037
|
+
const node = table.node.nodeAt(nodePos);
|
|
1038
|
+
const pos = nodePos + table.start;
|
|
1039
|
+
return {
|
|
1040
|
+
pos,
|
|
1041
|
+
start: pos + 1,
|
|
1042
|
+
node,
|
|
1043
|
+
depth: table.depth + 2
|
|
1044
|
+
};
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Returns an array of cells in a row at the specified row index.
|
|
1049
|
+
*
|
|
1050
|
+
* @internal
|
|
1051
|
+
*/
|
|
1052
|
+
function getCellsInRow(rowIndex, selection) {
|
|
1053
|
+
const table = findTable(selection.$from);
|
|
1054
|
+
if (!table) return;
|
|
1055
|
+
const map = TableMap.get(table.node);
|
|
1056
|
+
if (rowIndex < 0 || rowIndex > map.height - 1) return;
|
|
1057
|
+
return map.cellsInRect({
|
|
1058
|
+
left: 0,
|
|
1059
|
+
right: map.width,
|
|
1060
|
+
top: rowIndex,
|
|
1061
|
+
bottom: rowIndex + 1
|
|
1062
|
+
}).map((nodePos) => {
|
|
1063
|
+
const node = table.node.nodeAt(nodePos);
|
|
1064
|
+
const pos = nodePos + table.start;
|
|
1065
|
+
return {
|
|
1066
|
+
pos,
|
|
1067
|
+
start: pos + 1,
|
|
1068
|
+
node,
|
|
1069
|
+
depth: table.depth + 2
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/utils/selection-range.ts
|
|
1076
|
+
/**
|
|
1077
|
+
* Returns a range of rectangular selection spanning all merged cells around a
|
|
1078
|
+
* column at index `columnIndex`.
|
|
1079
|
+
*
|
|
1080
|
+
* Original implementation from Atlassian (Apache License 2.0)
|
|
1081
|
+
*
|
|
1082
|
+
* https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-column.ts#editor/editor-tables/src/utils/get-selection-range-in-column.ts
|
|
1083
|
+
*
|
|
1084
|
+
* @internal
|
|
1085
|
+
*/
|
|
1086
|
+
function getSelectionRangeInColumn(tr, startColIndex, endColIndex = startColIndex) {
|
|
1087
|
+
let startIndex = startColIndex;
|
|
1088
|
+
let endIndex = endColIndex;
|
|
1089
|
+
for (let i = startColIndex; i >= 0; i--) {
|
|
1090
|
+
const cells = getCellsInColumn(i, tr.selection);
|
|
1091
|
+
if (cells) cells.forEach((cell) => {
|
|
1092
|
+
const maybeEndIndex = cell.node.attrs.colspan + i - 1;
|
|
1093
|
+
if (maybeEndIndex >= startIndex) startIndex = i;
|
|
1094
|
+
if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
for (let i = startColIndex; i <= endIndex; i++) {
|
|
1098
|
+
const cells = getCellsInColumn(i, tr.selection);
|
|
1099
|
+
if (cells) cells.forEach((cell) => {
|
|
1100
|
+
const maybeEndIndex = cell.node.attrs.colspan + i - 1;
|
|
1101
|
+
if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
const indexes = [];
|
|
1105
|
+
for (let i = startIndex; i <= endIndex; i++) {
|
|
1106
|
+
const maybeCells = getCellsInColumn(i, tr.selection);
|
|
1107
|
+
if (maybeCells && maybeCells.length > 0) indexes.push(i);
|
|
1108
|
+
}
|
|
1109
|
+
startIndex = indexes[0];
|
|
1110
|
+
endIndex = indexes[indexes.length - 1];
|
|
1111
|
+
const firstSelectedColumnCells = getCellsInColumn(startIndex, tr.selection);
|
|
1112
|
+
const firstRowCells = getCellsInRow(0, tr.selection);
|
|
1113
|
+
if (!firstSelectedColumnCells || !firstRowCells) return;
|
|
1114
|
+
const $anchor = tr.doc.resolve(firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos);
|
|
1115
|
+
let headCell;
|
|
1116
|
+
for (let i = endIndex; i >= startIndex; i--) {
|
|
1117
|
+
const columnCells = getCellsInColumn(i, tr.selection);
|
|
1118
|
+
if (columnCells && columnCells.length > 0) {
|
|
1119
|
+
for (let j = firstRowCells.length - 1; j >= 0; j--) if (firstRowCells[j].pos === columnCells[0].pos) {
|
|
1120
|
+
headCell = columnCells[0];
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
if (headCell) break;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
if (!headCell) return;
|
|
1127
|
+
return {
|
|
1128
|
+
$anchor,
|
|
1129
|
+
$head: tr.doc.resolve(headCell.pos),
|
|
1130
|
+
indexes
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Returns a range of rectangular selection spanning all merged cells around a
|
|
1135
|
+
* row at index `rowIndex`.
|
|
1136
|
+
*
|
|
1137
|
+
* Original implementation from Atlassian (Apache License 2.0)
|
|
1138
|
+
*
|
|
1139
|
+
* https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-row.ts#editor/editor-tables/src/utils/get-selection-range-in-row.ts
|
|
1140
|
+
*
|
|
1141
|
+
* @internal
|
|
1142
|
+
*/
|
|
1143
|
+
function getSelectionRangeInRow(tr, startRowIndex, endRowIndex = startRowIndex) {
|
|
1144
|
+
let startIndex = startRowIndex;
|
|
1145
|
+
let endIndex = endRowIndex;
|
|
1146
|
+
for (let i = startRowIndex; i >= 0; i--) {
|
|
1147
|
+
const cells = getCellsInRow(i, tr.selection);
|
|
1148
|
+
if (cells) cells.forEach((cell) => {
|
|
1149
|
+
const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
|
|
1150
|
+
if (maybeEndIndex >= startIndex) startIndex = i;
|
|
1151
|
+
if (maybeEndIndex > endIndex) endIndex = maybeEndIndex;
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
for (let i = startRowIndex; i <= endIndex; i++) {
|
|
1155
|
+
const cells = getCellsInRow(i, tr.selection);
|
|
1156
|
+
if (cells) cells.forEach((cell) => {
|
|
1157
|
+
const maybeEndIndex = cell.node.attrs.rowspan + i - 1;
|
|
1158
|
+
if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
const indexes = [];
|
|
1162
|
+
for (let i = startIndex; i <= endIndex; i++) {
|
|
1163
|
+
const maybeCells = getCellsInRow(i, tr.selection);
|
|
1164
|
+
if (maybeCells && maybeCells.length > 0) indexes.push(i);
|
|
1165
|
+
}
|
|
1166
|
+
startIndex = indexes[0];
|
|
1167
|
+
endIndex = indexes[indexes.length - 1];
|
|
1168
|
+
const firstSelectedRowCells = getCellsInRow(startIndex, tr.selection);
|
|
1169
|
+
const firstColumnCells = getCellsInColumn(0, tr.selection);
|
|
1170
|
+
if (!firstSelectedRowCells || !firstColumnCells) return;
|
|
1171
|
+
const $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1].pos);
|
|
1172
|
+
let headCell;
|
|
1173
|
+
for (let i = endIndex; i >= startIndex; i--) {
|
|
1174
|
+
const rowCells = getCellsInRow(i, tr.selection);
|
|
1175
|
+
if (rowCells && rowCells.length > 0) {
|
|
1176
|
+
for (let j = firstColumnCells.length - 1; j >= 0; j--) if (firstColumnCells[j].pos === rowCells[0].pos) {
|
|
1177
|
+
headCell = rowCells[0];
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
if (headCell) break;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if (!headCell) return;
|
|
1184
|
+
return {
|
|
1185
|
+
$anchor,
|
|
1186
|
+
$head: tr.doc.resolve(headCell.pos),
|
|
1187
|
+
indexes
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region src/utils/transpose.ts
|
|
1193
|
+
/**
|
|
1194
|
+
* Transposes a 2D array by flipping columns to rows.
|
|
1195
|
+
*
|
|
1196
|
+
* Transposition is a familiar algebra concept where the matrix is flipped
|
|
1197
|
+
* along its diagonal. For more details, see:
|
|
1198
|
+
* https://en.wikipedia.org/wiki/Transpose
|
|
1199
|
+
*
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```javascript
|
|
1202
|
+
* const arr = [
|
|
1203
|
+
* ['a1', 'a2', 'a3'],
|
|
1204
|
+
* ['b1', 'b2', 'b3'],
|
|
1205
|
+
* ['c1', 'c2', 'c3'],
|
|
1206
|
+
* ['d1', 'd2', 'd3'],
|
|
1207
|
+
* ];
|
|
1208
|
+
*
|
|
1209
|
+
* const result = transpose(arr);
|
|
1210
|
+
* result === [
|
|
1211
|
+
* ['a1', 'b1', 'c1', 'd1'],
|
|
1212
|
+
* ['a2', 'b2', 'c2', 'd2'],
|
|
1213
|
+
* ['a3', 'b3', 'c3', 'd3'],
|
|
1214
|
+
* ]
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
function transpose(array) {
|
|
1218
|
+
return array[0].map((_, i) => {
|
|
1219
|
+
return array.map((column) => column[i]);
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region src/utils/move-column.ts
|
|
1225
|
+
/**
|
|
1226
|
+
* Move a column from index `origin` to index `target`.
|
|
1227
|
+
*
|
|
1228
|
+
* @internal
|
|
1229
|
+
*/
|
|
1230
|
+
function moveColumn(moveColParams) {
|
|
1231
|
+
var _getSelectionRangeInC, _getSelectionRangeInC2;
|
|
1232
|
+
const { tr, originIndex, targetIndex, select, pos } = moveColParams;
|
|
1233
|
+
const table = findTable(tr.doc.resolve(pos));
|
|
1234
|
+
if (!table) return false;
|
|
1235
|
+
const indexesOriginColumn = (_getSelectionRangeInC = getSelectionRangeInColumn(tr, originIndex)) === null || _getSelectionRangeInC === void 0 ? void 0 : _getSelectionRangeInC.indexes;
|
|
1236
|
+
const indexesTargetColumn = (_getSelectionRangeInC2 = getSelectionRangeInColumn(tr, targetIndex)) === null || _getSelectionRangeInC2 === void 0 ? void 0 : _getSelectionRangeInC2.indexes;
|
|
1237
|
+
if (!indexesOriginColumn || !indexesTargetColumn) return false;
|
|
1238
|
+
if (indexesOriginColumn.includes(targetIndex)) return false;
|
|
1239
|
+
const newTable = moveTableColumn$1(table.node, indexesOriginColumn, indexesTargetColumn, 0);
|
|
1240
|
+
tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
|
|
1241
|
+
if (!select) return true;
|
|
1242
|
+
const map = TableMap.get(newTable);
|
|
1243
|
+
const start = table.start;
|
|
1244
|
+
const index = targetIndex;
|
|
1245
|
+
const lastCell = map.positionAt(map.height - 1, index, newTable);
|
|
1246
|
+
const $lastCell = tr.doc.resolve(start + lastCell);
|
|
1247
|
+
const firstCell = map.positionAt(0, index, newTable);
|
|
1248
|
+
const $firstCell = tr.doc.resolve(start + firstCell);
|
|
1249
|
+
tr.setSelection(CellSelection.colSelection($lastCell, $firstCell));
|
|
1250
|
+
return true;
|
|
1251
|
+
}
|
|
1252
|
+
function moveTableColumn$1(table, indexesOrigin, indexesTarget, direction) {
|
|
1253
|
+
let rows = transpose(convertTableNodeToArrayOfRows(table));
|
|
1254
|
+
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
|
|
1255
|
+
rows = transpose(rows);
|
|
1256
|
+
return convertArrayOfRowsToTableNode(table, rows);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region src/utils/move-row.ts
|
|
1261
|
+
/**
|
|
1262
|
+
* Move a row from index `origin` to index `target`.
|
|
1263
|
+
*
|
|
1264
|
+
* @internal
|
|
1265
|
+
*/
|
|
1266
|
+
function moveRow(moveRowParams) {
|
|
1267
|
+
var _getSelectionRangeInR, _getSelectionRangeInR2;
|
|
1268
|
+
const { tr, originIndex, targetIndex, select, pos } = moveRowParams;
|
|
1269
|
+
const table = findTable(tr.doc.resolve(pos));
|
|
1270
|
+
if (!table) return false;
|
|
1271
|
+
const indexesOriginRow = (_getSelectionRangeInR = getSelectionRangeInRow(tr, originIndex)) === null || _getSelectionRangeInR === void 0 ? void 0 : _getSelectionRangeInR.indexes;
|
|
1272
|
+
const indexesTargetRow = (_getSelectionRangeInR2 = getSelectionRangeInRow(tr, targetIndex)) === null || _getSelectionRangeInR2 === void 0 ? void 0 : _getSelectionRangeInR2.indexes;
|
|
1273
|
+
if (!indexesOriginRow || !indexesTargetRow) return false;
|
|
1274
|
+
if (indexesOriginRow.includes(targetIndex)) return false;
|
|
1275
|
+
const newTable = moveTableRow$1(table.node, indexesOriginRow, indexesTargetRow, 0);
|
|
1276
|
+
tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);
|
|
1277
|
+
if (!select) return true;
|
|
1278
|
+
const map = TableMap.get(newTable);
|
|
1279
|
+
const start = table.start;
|
|
1280
|
+
const index = targetIndex;
|
|
1281
|
+
const lastCell = map.positionAt(index, map.width - 1, newTable);
|
|
1282
|
+
const $lastCell = tr.doc.resolve(start + lastCell);
|
|
1283
|
+
const firstCell = map.positionAt(index, 0, newTable);
|
|
1284
|
+
const $firstCell = tr.doc.resolve(start + firstCell);
|
|
1285
|
+
tr.setSelection(CellSelection.rowSelection($lastCell, $firstCell));
|
|
1286
|
+
return true;
|
|
1287
|
+
}
|
|
1288
|
+
function moveTableRow$1(table, indexesOrigin, indexesTarget, direction) {
|
|
1289
|
+
let rows = convertTableNodeToArrayOfRows(table);
|
|
1290
|
+
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);
|
|
1291
|
+
return convertArrayOfRowsToTableNode(table, rows);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region src/commands.ts
|
|
1296
|
+
/**
|
|
1297
|
+
* Helper to get the selected rectangle in a table, if any. Adds table
|
|
1298
|
+
* map, table node, and table start offset to the object for
|
|
1299
|
+
* convenience.
|
|
1300
|
+
*
|
|
1301
|
+
* @public
|
|
1302
|
+
*/
|
|
1303
|
+
function selectedRect(state) {
|
|
1304
|
+
const sel = state.selection;
|
|
1305
|
+
const $pos = selectionCell(state);
|
|
1306
|
+
const table = $pos.node(-1);
|
|
1307
|
+
const tableStart = $pos.start(-1);
|
|
1308
|
+
const map = TableMap.get(table);
|
|
1309
|
+
return {
|
|
1310
|
+
...sel instanceof CellSelection ? map.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map.findCell($pos.pos - tableStart),
|
|
1311
|
+
tableStart,
|
|
1312
|
+
map,
|
|
1313
|
+
table
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
/**
|
|
1317
|
+
* Add a column at the given position in a table.
|
|
1318
|
+
*
|
|
1319
|
+
* @public
|
|
1320
|
+
*/
|
|
1321
|
+
function addColumn(tr, { map, tableStart, table }, col) {
|
|
1322
|
+
let refColumn = col > 0 ? -1 : 0;
|
|
1323
|
+
if (columnIsHeader(map, table, col + refColumn)) refColumn = col == 0 || col == map.width ? null : 0;
|
|
1324
|
+
for (let row = 0; row < map.height; row++) {
|
|
1325
|
+
const index = row * map.width + col;
|
|
1326
|
+
if (col > 0 && col < map.width && map.map[index - 1] == map.map[index]) {
|
|
1327
|
+
const pos = map.map[index];
|
|
1328
|
+
const cell = table.nodeAt(pos);
|
|
1329
|
+
tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map.colCount(pos)));
|
|
1330
|
+
row += cell.attrs.rowspan - 1;
|
|
1331
|
+
} else {
|
|
1332
|
+
const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
|
|
1333
|
+
const pos = map.positionAt(row, col, table);
|
|
1334
|
+
tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill());
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
return tr;
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Command to add a column before the column with the selection.
|
|
1341
|
+
*
|
|
1342
|
+
* @public
|
|
1343
|
+
*/
|
|
1344
|
+
function addColumnBefore(state, dispatch) {
|
|
1345
|
+
if (!isInTable(state)) return false;
|
|
1346
|
+
if (dispatch) {
|
|
1347
|
+
const rect = selectedRect(state);
|
|
1348
|
+
dispatch(addColumn(state.tr, rect, rect.left));
|
|
1349
|
+
}
|
|
1350
|
+
return true;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Command to add a column after the column with the selection.
|
|
1354
|
+
*
|
|
1355
|
+
* @public
|
|
1356
|
+
*/
|
|
1357
|
+
function addColumnAfter(state, dispatch) {
|
|
1358
|
+
if (!isInTable(state)) return false;
|
|
1359
|
+
if (dispatch) {
|
|
1360
|
+
const rect = selectedRect(state);
|
|
1361
|
+
dispatch(addColumn(state.tr, rect, rect.right));
|
|
1362
|
+
}
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* @public
|
|
1367
|
+
*/
|
|
1368
|
+
function removeColumn(tr, { map, table, tableStart }, col) {
|
|
1369
|
+
const mapStart = tr.mapping.maps.length;
|
|
1370
|
+
for (let row = 0; row < map.height;) {
|
|
1371
|
+
const index = row * map.width + col;
|
|
1372
|
+
const pos = map.map[index];
|
|
1373
|
+
const cell = table.nodeAt(pos);
|
|
1374
|
+
const attrs = cell.attrs;
|
|
1375
|
+
if (col > 0 && map.map[index - 1] == pos || col < map.width - 1 && map.map[index + 1] == pos) tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map.colCount(pos)));
|
|
1376
|
+
else {
|
|
1377
|
+
const start = tr.mapping.slice(mapStart).map(tableStart + pos);
|
|
1378
|
+
tr.delete(start, start + cell.nodeSize);
|
|
1379
|
+
}
|
|
1380
|
+
row += attrs.rowspan;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Command function that removes the selected columns from a table.
|
|
1385
|
+
*
|
|
1386
|
+
* @public
|
|
1387
|
+
*/
|
|
1388
|
+
function deleteColumn(state, dispatch) {
|
|
1389
|
+
if (!isInTable(state)) return false;
|
|
1390
|
+
if (dispatch) {
|
|
1391
|
+
const rect = selectedRect(state);
|
|
1392
|
+
const tr = state.tr;
|
|
1393
|
+
if (rect.left == 0 && rect.right == rect.map.width) return false;
|
|
1394
|
+
for (let i = rect.right - 1;; i--) {
|
|
1395
|
+
removeColumn(tr, rect, i);
|
|
1396
|
+
if (i == rect.left) break;
|
|
1397
|
+
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
1398
|
+
if (!table) throw new RangeError("No table found");
|
|
1399
|
+
rect.table = table;
|
|
1400
|
+
rect.map = TableMap.get(table);
|
|
1401
|
+
}
|
|
1402
|
+
dispatch(tr);
|
|
1403
|
+
}
|
|
1404
|
+
return true;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* @public
|
|
1408
|
+
*/
|
|
1409
|
+
function rowIsHeader(map, table, row) {
|
|
1410
|
+
var _table$nodeAt;
|
|
1411
|
+
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
1412
|
+
for (let col = 0; col < map.width; col++) if (((_table$nodeAt = table.nodeAt(map.map[col + row * map.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;
|
|
1413
|
+
return true;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* @public
|
|
1417
|
+
*/
|
|
1418
|
+
function addRow(tr, { map, tableStart, table }, row) {
|
|
1419
|
+
let rowPos = tableStart;
|
|
1420
|
+
for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
|
|
1421
|
+
const cells = [];
|
|
1422
|
+
let refRow = row > 0 ? -1 : 0;
|
|
1423
|
+
if (rowIsHeader(map, table, row + refRow)) refRow = row == 0 || row == map.height ? null : 0;
|
|
1424
|
+
for (let col = 0, index = map.width * row; col < map.width; col++, index++) if (row > 0 && row < map.height && map.map[index] == map.map[index - map.width]) {
|
|
1425
|
+
const pos = map.map[index];
|
|
1426
|
+
const attrs = table.nodeAt(pos).attrs;
|
|
1427
|
+
tr.setNodeMarkup(tableStart + pos, null, {
|
|
1428
|
+
...attrs,
|
|
1429
|
+
rowspan: attrs.rowspan + 1
|
|
1430
|
+
});
|
|
1431
|
+
col += attrs.colspan - 1;
|
|
1432
|
+
} else {
|
|
1433
|
+
var _table$nodeAt2;
|
|
1434
|
+
const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map.map[index + refRow * map.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;
|
|
1435
|
+
const node = type === null || type === void 0 ? void 0 : type.createAndFill();
|
|
1436
|
+
if (node) cells.push(node);
|
|
1437
|
+
}
|
|
1438
|
+
tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
|
|
1439
|
+
return tr;
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Add a table row before the selection.
|
|
1443
|
+
*
|
|
1444
|
+
* @public
|
|
1445
|
+
*/
|
|
1446
|
+
function addRowBefore(state, dispatch) {
|
|
1447
|
+
if (!isInTable(state)) return false;
|
|
1448
|
+
if (dispatch) {
|
|
1449
|
+
const rect = selectedRect(state);
|
|
1450
|
+
dispatch(addRow(state.tr, rect, rect.top));
|
|
1451
|
+
}
|
|
1452
|
+
return true;
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Add a table row after the selection.
|
|
1456
|
+
*
|
|
1457
|
+
* @public
|
|
1458
|
+
*/
|
|
1459
|
+
function addRowAfter(state, dispatch) {
|
|
1460
|
+
if (!isInTable(state)) return false;
|
|
1461
|
+
if (dispatch) {
|
|
1462
|
+
const rect = selectedRect(state);
|
|
1463
|
+
dispatch(addRow(state.tr, rect, rect.bottom));
|
|
1464
|
+
}
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
/**
|
|
1468
|
+
* @public
|
|
1469
|
+
*/
|
|
1470
|
+
function removeRow(tr, { map, table, tableStart }, row) {
|
|
1471
|
+
let rowPos = 0;
|
|
1472
|
+
for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
|
|
1473
|
+
const nextRow = rowPos + table.child(row).nodeSize;
|
|
1474
|
+
const mapFrom = tr.mapping.maps.length;
|
|
1475
|
+
tr.delete(rowPos + tableStart, nextRow + tableStart);
|
|
1476
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1477
|
+
for (let col = 0, index = row * map.width; col < map.width; col++, index++) {
|
|
1478
|
+
const pos = map.map[index];
|
|
1479
|
+
if (seen.has(pos)) continue;
|
|
1480
|
+
seen.add(pos);
|
|
1481
|
+
if (row > 0 && pos == map.map[index - map.width]) {
|
|
1482
|
+
const attrs = table.nodeAt(pos).attrs;
|
|
1483
|
+
tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, {
|
|
1484
|
+
...attrs,
|
|
1485
|
+
rowspan: attrs.rowspan - 1
|
|
1486
|
+
});
|
|
1487
|
+
col += attrs.colspan - 1;
|
|
1488
|
+
} else if (row < map.height && pos == map.map[index + map.width]) {
|
|
1489
|
+
const cell = table.nodeAt(pos);
|
|
1490
|
+
const attrs = cell.attrs;
|
|
1491
|
+
const copy = cell.type.create({
|
|
1492
|
+
...attrs,
|
|
1493
|
+
rowspan: cell.attrs.rowspan - 1
|
|
1494
|
+
}, cell.content);
|
|
1495
|
+
const newPos = map.positionAt(row + 1, col, table);
|
|
1496
|
+
tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
|
|
1497
|
+
col += attrs.colspan - 1;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Remove the selected rows from a table.
|
|
1503
|
+
*
|
|
1504
|
+
* @public
|
|
1505
|
+
*/
|
|
1506
|
+
function deleteRow(state, dispatch) {
|
|
1507
|
+
if (!isInTable(state)) return false;
|
|
1508
|
+
if (dispatch) {
|
|
1509
|
+
const rect = selectedRect(state), tr = state.tr;
|
|
1510
|
+
if (rect.top == 0 && rect.bottom == rect.map.height) return false;
|
|
1511
|
+
for (let i = rect.bottom - 1;; i--) {
|
|
1512
|
+
removeRow(tr, rect, i);
|
|
1513
|
+
if (i == rect.top) break;
|
|
1514
|
+
const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
|
|
1515
|
+
if (!table) throw new RangeError("No table found");
|
|
1516
|
+
rect.table = table;
|
|
1517
|
+
rect.map = TableMap.get(rect.table);
|
|
1518
|
+
}
|
|
1519
|
+
dispatch(tr);
|
|
1520
|
+
}
|
|
1521
|
+
return true;
|
|
1522
|
+
}
|
|
1523
|
+
function isEmpty(cell) {
|
|
1524
|
+
const c = cell.content;
|
|
1525
|
+
return c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0;
|
|
1526
|
+
}
|
|
1527
|
+
function cellsOverlapRectangle({ width, height, map }, rect) {
|
|
1528
|
+
let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
|
|
1529
|
+
let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
|
|
1530
|
+
for (let i = rect.top; i < rect.bottom; i++) {
|
|
1531
|
+
if (rect.left > 0 && map[indexLeft] == map[indexLeft - 1] || rect.right < width && map[indexRight] == map[indexRight + 1]) return true;
|
|
1532
|
+
indexLeft += width;
|
|
1533
|
+
indexRight += width;
|
|
1534
|
+
}
|
|
1535
|
+
for (let i = rect.left; i < rect.right; i++) {
|
|
1536
|
+
if (rect.top > 0 && map[indexTop] == map[indexTop - width] || rect.bottom < height && map[indexBottom] == map[indexBottom + width]) return true;
|
|
1537
|
+
indexTop++;
|
|
1538
|
+
indexBottom++;
|
|
1539
|
+
}
|
|
1540
|
+
return false;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Merge the selected cells into a single cell. Only available when
|
|
1544
|
+
* the selected cells' outline forms a rectangle.
|
|
1545
|
+
*
|
|
1546
|
+
* @public
|
|
1547
|
+
*/
|
|
1548
|
+
function mergeCells(state, dispatch) {
|
|
1549
|
+
const sel = state.selection;
|
|
1550
|
+
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;
|
|
1551
|
+
const rect = selectedRect(state), { map } = rect;
|
|
1552
|
+
if (cellsOverlapRectangle(map, rect)) return false;
|
|
1553
|
+
if (dispatch) {
|
|
1554
|
+
const tr = state.tr;
|
|
1555
|
+
const seen = {};
|
|
1556
|
+
let content = Fragment.empty;
|
|
1557
|
+
let mergedPos;
|
|
1558
|
+
let mergedCell;
|
|
1559
|
+
for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
|
|
1560
|
+
const cellPos = map.map[row * map.width + col];
|
|
1561
|
+
const cell = rect.table.nodeAt(cellPos);
|
|
1562
|
+
if (seen[cellPos] || !cell) continue;
|
|
1563
|
+
seen[cellPos] = true;
|
|
1564
|
+
if (mergedPos == null) {
|
|
1565
|
+
mergedPos = cellPos;
|
|
1566
|
+
mergedCell = cell;
|
|
1567
|
+
} else {
|
|
1568
|
+
if (!isEmpty(cell)) content = content.append(cell.content);
|
|
1569
|
+
const mapped = tr.mapping.map(cellPos + rect.tableStart);
|
|
1570
|
+
tr.delete(mapped, mapped + cell.nodeSize);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (mergedPos == null || mergedCell == null) return true;
|
|
1574
|
+
tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
|
|
1575
|
+
...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),
|
|
1576
|
+
rowspan: rect.bottom - rect.top
|
|
1577
|
+
});
|
|
1578
|
+
if (content.size > 0) {
|
|
1579
|
+
const end = mergedPos + 1 + mergedCell.content.size;
|
|
1580
|
+
const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
|
|
1581
|
+
tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
|
|
1582
|
+
}
|
|
1583
|
+
tr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));
|
|
1584
|
+
dispatch(tr);
|
|
1585
|
+
}
|
|
1586
|
+
return true;
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Split a selected cell, whose rowpan or colspan is greater than one,
|
|
1590
|
+
* into smaller cells. Use the first cell type for the new cells.
|
|
1591
|
+
*
|
|
1592
|
+
* @public
|
|
1593
|
+
*/
|
|
1594
|
+
function splitCell(state, dispatch) {
|
|
1595
|
+
const nodeTypes = tableNodeTypes(state.schema);
|
|
1596
|
+
return splitCellWithType(({ node }) => {
|
|
1597
|
+
return nodeTypes[node.type.spec.tableRole];
|
|
1598
|
+
})(state, dispatch);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Split a selected cell, whose rowpan or colspan is greater than one,
|
|
1602
|
+
* into smaller cells with the cell type (th, td) returned by getType function.
|
|
1603
|
+
*
|
|
1604
|
+
* @public
|
|
1605
|
+
*/
|
|
1606
|
+
function splitCellWithType(getCellType) {
|
|
1607
|
+
return (state, dispatch) => {
|
|
1608
|
+
const sel = state.selection;
|
|
1609
|
+
let cellNode;
|
|
1610
|
+
let cellPos;
|
|
1611
|
+
if (!(sel instanceof CellSelection)) {
|
|
1612
|
+
var _cellAround;
|
|
1613
|
+
cellNode = cellWrapping(sel.$from);
|
|
1614
|
+
if (!cellNode) return false;
|
|
1615
|
+
cellPos = (_cellAround = cellAround(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;
|
|
1616
|
+
} else {
|
|
1617
|
+
if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
|
|
1618
|
+
cellNode = sel.$anchorCell.nodeAfter;
|
|
1619
|
+
cellPos = sel.$anchorCell.pos;
|
|
1620
|
+
}
|
|
1621
|
+
if (cellNode == null || cellPos == null) return false;
|
|
1622
|
+
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;
|
|
1623
|
+
if (dispatch) {
|
|
1624
|
+
let baseAttrs = cellNode.attrs;
|
|
1625
|
+
const attrs = [];
|
|
1626
|
+
const colwidth = baseAttrs.colwidth;
|
|
1627
|
+
if (baseAttrs.rowspan > 1) baseAttrs = {
|
|
1628
|
+
...baseAttrs,
|
|
1629
|
+
rowspan: 1
|
|
1630
|
+
};
|
|
1631
|
+
if (baseAttrs.colspan > 1) baseAttrs = {
|
|
1632
|
+
...baseAttrs,
|
|
1633
|
+
colspan: 1
|
|
1634
|
+
};
|
|
1635
|
+
const rect = selectedRect(state), tr = state.tr;
|
|
1636
|
+
for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {
|
|
1637
|
+
...baseAttrs,
|
|
1638
|
+
colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
|
|
1639
|
+
} : baseAttrs);
|
|
1640
|
+
let lastCell;
|
|
1641
|
+
for (let row = rect.top; row < rect.bottom; row++) {
|
|
1642
|
+
let pos = rect.map.positionAt(row, rect.left, rect.table);
|
|
1643
|
+
if (row == rect.top) pos += cellNode.nodeSize;
|
|
1644
|
+
for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
|
|
1645
|
+
if (col == rect.left && row == rect.top) continue;
|
|
1646
|
+
tr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType({
|
|
1647
|
+
node: cellNode,
|
|
1648
|
+
row,
|
|
1649
|
+
col
|
|
1650
|
+
}).createAndFill(attrs[i]));
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
tr.setNodeMarkup(cellPos, getCellType({
|
|
1654
|
+
node: cellNode,
|
|
1655
|
+
row: rect.top,
|
|
1656
|
+
col: rect.left
|
|
1657
|
+
}), attrs[0]);
|
|
1658
|
+
if (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));
|
|
1659
|
+
dispatch(tr);
|
|
1660
|
+
}
|
|
1661
|
+
return true;
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Returns a command that sets the given attribute to the given value,
|
|
1666
|
+
* and is only available when the currently selected cell doesn't
|
|
1667
|
+
* already have that attribute set to that value.
|
|
1668
|
+
*
|
|
1669
|
+
* @public
|
|
1670
|
+
*/
|
|
1671
|
+
function setCellAttr(name, value) {
|
|
1672
|
+
return function(state, dispatch) {
|
|
1673
|
+
if (!isInTable(state)) return false;
|
|
1674
|
+
const $cell = selectionCell(state);
|
|
1675
|
+
if ($cell.nodeAfter.attrs[name] === value) return false;
|
|
1676
|
+
if (dispatch) {
|
|
1677
|
+
const tr = state.tr;
|
|
1678
|
+
if (state.selection instanceof CellSelection) state.selection.forEachCell((node, pos) => {
|
|
1679
|
+
if (node.attrs[name] !== value) tr.setNodeMarkup(pos, null, {
|
|
1680
|
+
...node.attrs,
|
|
1681
|
+
[name]: value
|
|
1682
|
+
});
|
|
1683
|
+
});
|
|
1684
|
+
else tr.setNodeMarkup($cell.pos, null, {
|
|
1685
|
+
...$cell.nodeAfter.attrs,
|
|
1686
|
+
[name]: value
|
|
1687
|
+
});
|
|
1688
|
+
dispatch(tr);
|
|
1689
|
+
}
|
|
1690
|
+
return true;
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
function deprecated_toggleHeader(type) {
|
|
1694
|
+
return function(state, dispatch) {
|
|
1695
|
+
if (!isInTable(state)) return false;
|
|
1696
|
+
if (dispatch) {
|
|
1697
|
+
const types = tableNodeTypes(state.schema);
|
|
1698
|
+
const rect = selectedRect(state), tr = state.tr;
|
|
1699
|
+
const cells = rect.map.cellsInRect(type == "column" ? {
|
|
1700
|
+
left: rect.left,
|
|
1701
|
+
top: 0,
|
|
1702
|
+
right: rect.right,
|
|
1703
|
+
bottom: rect.map.height
|
|
1704
|
+
} : type == "row" ? {
|
|
1705
|
+
left: 0,
|
|
1706
|
+
top: rect.top,
|
|
1707
|
+
right: rect.map.width,
|
|
1708
|
+
bottom: rect.bottom
|
|
1709
|
+
} : rect);
|
|
1710
|
+
const nodes = cells.map((pos) => rect.table.nodeAt(pos));
|
|
1711
|
+
for (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs);
|
|
1712
|
+
if (tr.steps.length === 0) for (let i = 0; i < cells.length; i++) tr.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs);
|
|
1713
|
+
dispatch(tr);
|
|
1714
|
+
}
|
|
1715
|
+
return true;
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
function isHeaderEnabledByType(type, rect, types) {
|
|
1719
|
+
const cellPositions = rect.map.cellsInRect({
|
|
1720
|
+
left: 0,
|
|
1721
|
+
top: 0,
|
|
1722
|
+
right: type == "row" ? rect.map.width : 1,
|
|
1723
|
+
bottom: type == "column" ? rect.map.height : 1
|
|
1724
|
+
});
|
|
1725
|
+
for (let i = 0; i < cellPositions.length; i++) {
|
|
1726
|
+
const cell = rect.table.nodeAt(cellPositions[i]);
|
|
1727
|
+
if (cell && cell.type !== types.header_cell) return false;
|
|
1728
|
+
}
|
|
1729
|
+
return true;
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Toggles between row/column header and normal cells (Only applies to first row/column).
|
|
1733
|
+
* For deprecated behavior pass `useDeprecatedLogic` in options with true.
|
|
1734
|
+
*
|
|
1735
|
+
* @public
|
|
1736
|
+
*/
|
|
1737
|
+
function toggleHeader(type, options) {
|
|
1738
|
+
options = options || { useDeprecatedLogic: false };
|
|
1739
|
+
if (options.useDeprecatedLogic) return deprecated_toggleHeader(type);
|
|
1740
|
+
return function(state, dispatch) {
|
|
1741
|
+
if (!isInTable(state)) return false;
|
|
1742
|
+
if (dispatch) {
|
|
1743
|
+
const types = tableNodeTypes(state.schema);
|
|
1744
|
+
const rect = selectedRect(state), tr = state.tr;
|
|
1745
|
+
const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
|
|
1746
|
+
const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types);
|
|
1747
|
+
const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0;
|
|
1748
|
+
const cellsRect = type == "column" ? {
|
|
1749
|
+
left: 0,
|
|
1750
|
+
top: selectionStartsAt,
|
|
1751
|
+
right: 1,
|
|
1752
|
+
bottom: rect.map.height
|
|
1753
|
+
} : type == "row" ? {
|
|
1754
|
+
left: selectionStartsAt,
|
|
1755
|
+
top: 0,
|
|
1756
|
+
right: rect.map.width,
|
|
1757
|
+
bottom: 1
|
|
1758
|
+
} : rect;
|
|
1759
|
+
const newType = type == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell;
|
|
1760
|
+
rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
|
|
1761
|
+
const cellPos = relativeCellPos + rect.tableStart;
|
|
1762
|
+
const cell = tr.doc.nodeAt(cellPos);
|
|
1763
|
+
if (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);
|
|
1764
|
+
});
|
|
1765
|
+
dispatch(tr);
|
|
1766
|
+
}
|
|
1767
|
+
return true;
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Toggles whether the selected row contains header cells.
|
|
1772
|
+
*
|
|
1773
|
+
* @public
|
|
1774
|
+
*/
|
|
1775
|
+
const toggleHeaderRow = toggleHeader("row", { useDeprecatedLogic: true });
|
|
1776
|
+
/**
|
|
1777
|
+
* Toggles whether the selected column contains header cells.
|
|
1778
|
+
*
|
|
1779
|
+
* @public
|
|
1780
|
+
*/
|
|
1781
|
+
const toggleHeaderColumn = toggleHeader("column", { useDeprecatedLogic: true });
|
|
1782
|
+
/**
|
|
1783
|
+
* Toggles whether the selected cells are header cells.
|
|
1784
|
+
*
|
|
1785
|
+
* @public
|
|
1786
|
+
*/
|
|
1787
|
+
const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true });
|
|
1788
|
+
function findNextCell($cell, dir) {
|
|
1789
|
+
if (dir < 0) {
|
|
1790
|
+
const before = $cell.nodeBefore;
|
|
1791
|
+
if (before) return $cell.pos - before.nodeSize;
|
|
1792
|
+
for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
|
|
1793
|
+
const rowNode = $cell.node(-1).child(row);
|
|
1794
|
+
const lastChild = rowNode.lastChild;
|
|
1795
|
+
if (lastChild) return rowEnd - 1 - lastChild.nodeSize;
|
|
1796
|
+
rowEnd -= rowNode.nodeSize;
|
|
1797
|
+
}
|
|
1798
|
+
} else {
|
|
1799
|
+
if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;
|
|
1800
|
+
const table = $cell.node(-1);
|
|
1801
|
+
for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
|
|
1802
|
+
const rowNode = table.child(row);
|
|
1803
|
+
if (rowNode.childCount) return rowStart + 1;
|
|
1804
|
+
rowStart += rowNode.nodeSize;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Returns a command for selecting the next (direction=1) or previous
|
|
1811
|
+
* (direction=-1) cell in a table.
|
|
1812
|
+
*
|
|
1813
|
+
* @public
|
|
1814
|
+
*/
|
|
1815
|
+
function goToNextCell(direction) {
|
|
1816
|
+
return function(state, dispatch) {
|
|
1817
|
+
if (!isInTable(state)) return false;
|
|
1818
|
+
const cell = findNextCell(selectionCell(state), direction);
|
|
1819
|
+
if (cell == null) return false;
|
|
1820
|
+
if (dispatch) {
|
|
1821
|
+
const $cell = state.doc.resolve(cell);
|
|
1822
|
+
dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
|
|
1823
|
+
}
|
|
1824
|
+
return true;
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Deletes the table around the selection, if any.
|
|
1829
|
+
*
|
|
1830
|
+
* @public
|
|
1831
|
+
*/
|
|
1832
|
+
function deleteTable(state, dispatch) {
|
|
1833
|
+
const $pos = state.selection.$anchor;
|
|
1834
|
+
for (let d = $pos.depth; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "table") {
|
|
1835
|
+
if (dispatch) dispatch(state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView());
|
|
1836
|
+
return true;
|
|
1837
|
+
}
|
|
1838
|
+
return false;
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Deletes the content of the selected cells, if they are not empty.
|
|
1842
|
+
*
|
|
1843
|
+
* @public
|
|
1844
|
+
*/
|
|
1845
|
+
function deleteCellSelection(state, dispatch) {
|
|
1846
|
+
const sel = state.selection;
|
|
1847
|
+
if (!(sel instanceof CellSelection)) return false;
|
|
1848
|
+
if (dispatch) {
|
|
1849
|
+
const tr = state.tr;
|
|
1850
|
+
const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
|
|
1851
|
+
sel.forEachCell((cell, pos) => {
|
|
1852
|
+
if (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
|
|
1853
|
+
});
|
|
1854
|
+
if (tr.docChanged) dispatch(tr);
|
|
1855
|
+
}
|
|
1856
|
+
return true;
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Move a table row from index `from` to index `to`.
|
|
1860
|
+
*
|
|
1861
|
+
* @public
|
|
1862
|
+
*/
|
|
1863
|
+
function moveTableRow(options) {
|
|
1864
|
+
return (state, dispatch) => {
|
|
1865
|
+
const { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;
|
|
1866
|
+
const tr = state.tr;
|
|
1867
|
+
if (moveRow({
|
|
1868
|
+
tr,
|
|
1869
|
+
originIndex,
|
|
1870
|
+
targetIndex,
|
|
1871
|
+
select,
|
|
1872
|
+
pos
|
|
1873
|
+
})) {
|
|
1874
|
+
dispatch === null || dispatch === void 0 || dispatch(tr);
|
|
1875
|
+
return true;
|
|
1876
|
+
}
|
|
1877
|
+
return false;
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Move a table column from index `from` to index `to`.
|
|
1882
|
+
*
|
|
1883
|
+
* @public
|
|
1884
|
+
*/
|
|
1885
|
+
function moveTableColumn(options) {
|
|
1886
|
+
return (state, dispatch) => {
|
|
1887
|
+
const { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;
|
|
1888
|
+
const tr = state.tr;
|
|
1889
|
+
if (moveColumn({
|
|
1890
|
+
tr,
|
|
1891
|
+
originIndex,
|
|
1892
|
+
targetIndex,
|
|
1893
|
+
select,
|
|
1894
|
+
pos
|
|
1895
|
+
})) {
|
|
1896
|
+
dispatch === null || dispatch === void 0 || dispatch(tr);
|
|
1897
|
+
return true;
|
|
1898
|
+
}
|
|
1899
|
+
return false;
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
//#endregion
|
|
1904
|
+
//#region src/copypaste.ts
|
|
1905
|
+
/**
|
|
1906
|
+
* Get a rectangular area of cells from a slice, or null if the outer
|
|
1907
|
+
* nodes of the slice aren't table cells or rows.
|
|
1908
|
+
*
|
|
1909
|
+
* @internal
|
|
1910
|
+
*/
|
|
1911
|
+
function pastedCells(slice) {
|
|
1912
|
+
if (slice.size === 0) return null;
|
|
1913
|
+
let { content, openStart, openEnd } = slice;
|
|
1914
|
+
while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
|
|
1915
|
+
openStart--;
|
|
1916
|
+
openEnd--;
|
|
1917
|
+
content = content.child(0).content;
|
|
1918
|
+
}
|
|
1919
|
+
const first = content.child(0);
|
|
1920
|
+
const role = first.type.spec.tableRole;
|
|
1921
|
+
const schema = first.type.schema, rows = [];
|
|
1922
|
+
if (role == "row") for (let i = 0; i < content.childCount; i++) {
|
|
1923
|
+
let cells = content.child(i).content;
|
|
1924
|
+
const left = i ? 0 : Math.max(0, openStart - 1);
|
|
1925
|
+
const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
|
|
1926
|
+
if (left || right) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content;
|
|
1927
|
+
rows.push(cells);
|
|
1928
|
+
}
|
|
1929
|
+
else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
|
|
1930
|
+
else return null;
|
|
1931
|
+
return ensureRectangular(schema, rows);
|
|
1932
|
+
}
|
|
1933
|
+
function ensureRectangular(schema, rows) {
|
|
1934
|
+
const widths = [];
|
|
1935
|
+
for (let i = 0; i < rows.length; i++) {
|
|
1936
|
+
const row = rows[i];
|
|
1937
|
+
for (let j = row.childCount - 1; j >= 0; j--) {
|
|
1938
|
+
const { rowspan, colspan } = row.child(j).attrs;
|
|
1939
|
+
for (let r = i; r < i + rowspan; r++) widths[r] = (widths[r] || 0) + colspan;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
let width = 0;
|
|
1943
|
+
for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);
|
|
1944
|
+
for (let r = 0; r < widths.length; r++) {
|
|
1945
|
+
if (r >= rows.length) rows.push(Fragment.empty);
|
|
1946
|
+
if (widths[r] < width) {
|
|
1947
|
+
const empty = tableNodeTypes(schema).cell.createAndFill();
|
|
1948
|
+
const cells = [];
|
|
1949
|
+
for (let i = widths[r]; i < width; i++) cells.push(empty);
|
|
1950
|
+
rows[r] = rows[r].append(Fragment.from(cells));
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
return {
|
|
1954
|
+
height: rows.length,
|
|
1955
|
+
width,
|
|
1956
|
+
rows
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
function fitSlice(nodeType, slice) {
|
|
1960
|
+
const node = nodeType.createAndFill();
|
|
1961
|
+
return new Transform(node).replace(0, node.content.size, slice).doc;
|
|
1962
|
+
}
|
|
1963
|
+
/**
|
|
1964
|
+
* Clip or extend (repeat) the given set of cells to cover the given
|
|
1965
|
+
* width and height. Will clip rowspan/colspan cells at the edges when
|
|
1966
|
+
* they stick out.
|
|
1967
|
+
*
|
|
1968
|
+
* @internal
|
|
1969
|
+
*/
|
|
1970
|
+
function clipCells({ width, height, rows }, newWidth, newHeight) {
|
|
1971
|
+
if (width != newWidth) {
|
|
1972
|
+
const added = [];
|
|
1973
|
+
const newRows = [];
|
|
1974
|
+
for (let row = 0; row < rows.length; row++) {
|
|
1975
|
+
const frag = rows[row], cells = [];
|
|
1976
|
+
for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
|
|
1977
|
+
let cell = frag.child(i % frag.childCount);
|
|
1978
|
+
if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
|
|
1979
|
+
cells.push(cell);
|
|
1980
|
+
col += cell.attrs.colspan;
|
|
1981
|
+
for (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
|
|
1982
|
+
}
|
|
1983
|
+
newRows.push(Fragment.from(cells));
|
|
1984
|
+
}
|
|
1985
|
+
rows = newRows;
|
|
1986
|
+
width = newWidth;
|
|
1987
|
+
}
|
|
1988
|
+
if (height != newHeight) {
|
|
1989
|
+
const newRows = [];
|
|
1990
|
+
for (let row = 0, i = 0; row < newHeight; row++, i++) {
|
|
1991
|
+
const cells = [], source = rows[i % height];
|
|
1992
|
+
for (let j = 0; j < source.childCount; j++) {
|
|
1993
|
+
let cell = source.child(j);
|
|
1994
|
+
if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
|
|
1995
|
+
...cell.attrs,
|
|
1996
|
+
rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
|
|
1997
|
+
}, cell.content);
|
|
1998
|
+
cells.push(cell);
|
|
1999
|
+
}
|
|
2000
|
+
newRows.push(Fragment.from(cells));
|
|
2001
|
+
}
|
|
2002
|
+
rows = newRows;
|
|
2003
|
+
height = newHeight;
|
|
2004
|
+
}
|
|
2005
|
+
return {
|
|
2006
|
+
width,
|
|
2007
|
+
height,
|
|
2008
|
+
rows
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
function growTable(tr, map, table, start, width, height, mapFrom) {
|
|
2012
|
+
const schema = tr.doc.type.schema;
|
|
2013
|
+
const types = tableNodeTypes(schema);
|
|
2014
|
+
let empty;
|
|
2015
|
+
let emptyHead;
|
|
2016
|
+
if (width > map.width) for (let row = 0, rowEnd = 0; row < map.height; row++) {
|
|
2017
|
+
const rowNode = table.child(row);
|
|
2018
|
+
rowEnd += rowNode.nodeSize;
|
|
2019
|
+
const cells = [];
|
|
2020
|
+
let add;
|
|
2021
|
+
if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty || (empty = types.cell.createAndFill());
|
|
2022
|
+
else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
|
|
2023
|
+
for (let i = map.width; i < width; i++) cells.push(add);
|
|
2024
|
+
tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
|
|
2025
|
+
}
|
|
2026
|
+
if (height > map.height) {
|
|
2027
|
+
const cells = [];
|
|
2028
|
+
for (let i = 0, start$1 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
|
|
2029
|
+
const header = i >= map.width ? false : table.nodeAt(map.map[start$1 + i]).type == types.header_cell;
|
|
2030
|
+
cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill()));
|
|
2031
|
+
}
|
|
2032
|
+
const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
|
|
2033
|
+
for (let i = map.height; i < height; i++) rows.push(emptyRow);
|
|
2034
|
+
tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
|
|
2035
|
+
}
|
|
2036
|
+
return !!(empty || emptyHead);
|
|
2037
|
+
}
|
|
2038
|
+
function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
|
|
2039
|
+
if (top == 0 || top == map.height) return false;
|
|
2040
|
+
let found = false;
|
|
2041
|
+
for (let col = left; col < right; col++) {
|
|
2042
|
+
const index = top * map.width + col, pos = map.map[index];
|
|
2043
|
+
if (map.map[index - map.width] == pos) {
|
|
2044
|
+
found = true;
|
|
2045
|
+
const cell = table.nodeAt(pos);
|
|
2046
|
+
const { top: cellTop, left: cellLeft } = map.findCell(pos);
|
|
2047
|
+
tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {
|
|
2048
|
+
...cell.attrs,
|
|
2049
|
+
rowspan: top - cellTop
|
|
2050
|
+
});
|
|
2051
|
+
tr.insert(tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)), cell.type.createAndFill({
|
|
2052
|
+
...cell.attrs,
|
|
2053
|
+
rowspan: cellTop + cell.attrs.rowspan - top
|
|
2054
|
+
}));
|
|
2055
|
+
col += cell.attrs.colspan - 1;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return found;
|
|
2059
|
+
}
|
|
2060
|
+
function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
|
|
2061
|
+
if (left == 0 || left == map.width) return false;
|
|
2062
|
+
let found = false;
|
|
2063
|
+
for (let row = top; row < bottom; row++) {
|
|
2064
|
+
const index = row * map.width + left, pos = map.map[index];
|
|
2065
|
+
if (map.map[index - 1] == pos) {
|
|
2066
|
+
found = true;
|
|
2067
|
+
const cell = table.nodeAt(pos);
|
|
2068
|
+
const cellLeft = map.colCount(pos);
|
|
2069
|
+
const updatePos = tr.mapping.slice(mapFrom).map(pos + start);
|
|
2070
|
+
tr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)));
|
|
2071
|
+
tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft)));
|
|
2072
|
+
row += cell.attrs.rowspan - 1;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
return found;
|
|
2076
|
+
}
|
|
2077
|
+
/**
|
|
2078
|
+
* Insert the given set of cells (as returned by `pastedCells`) into a
|
|
2079
|
+
* table, at the position pointed at by rect.
|
|
2080
|
+
*
|
|
2081
|
+
* @internal
|
|
2082
|
+
*/
|
|
2083
|
+
function insertCells(state, dispatch, tableStart, rect, cells) {
|
|
2084
|
+
let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
|
|
2085
|
+
if (!table) throw new Error("No table found");
|
|
2086
|
+
let map = TableMap.get(table);
|
|
2087
|
+
const { top, left } = rect;
|
|
2088
|
+
const right = left + cells.width, bottom = top + cells.height;
|
|
2089
|
+
const tr = state.tr;
|
|
2090
|
+
let mapFrom = 0;
|
|
2091
|
+
function recomp() {
|
|
2092
|
+
table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
|
|
2093
|
+
if (!table) throw new Error("No table found");
|
|
2094
|
+
map = TableMap.get(table);
|
|
2095
|
+
mapFrom = tr.mapping.maps.length;
|
|
2096
|
+
}
|
|
2097
|
+
if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();
|
|
2098
|
+
if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom)) recomp();
|
|
2099
|
+
if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom)) recomp();
|
|
2100
|
+
if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom)) recomp();
|
|
2101
|
+
if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom)) recomp();
|
|
2102
|
+
for (let row = top; row < bottom; row++) {
|
|
2103
|
+
const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);
|
|
2104
|
+
tr.replace(tr.mapping.slice(mapFrom).map(from + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top], 0, 0));
|
|
2105
|
+
}
|
|
2106
|
+
recomp();
|
|
2107
|
+
tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map.positionAt(top, left, table)), tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))));
|
|
2108
|
+
dispatch(tr);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
//#endregion
|
|
2112
|
+
//#region src/input.ts
|
|
2113
|
+
const handleKeyDown = keydownHandler({
|
|
2114
|
+
ArrowLeft: arrow("horiz", -1),
|
|
2115
|
+
ArrowRight: arrow("horiz", 1),
|
|
2116
|
+
ArrowUp: arrow("vert", -1),
|
|
2117
|
+
ArrowDown: arrow("vert", 1),
|
|
2118
|
+
"Shift-ArrowLeft": shiftArrow("horiz", -1),
|
|
2119
|
+
"Shift-ArrowRight": shiftArrow("horiz", 1),
|
|
2120
|
+
"Shift-ArrowUp": shiftArrow("vert", -1),
|
|
2121
|
+
"Shift-ArrowDown": shiftArrow("vert", 1),
|
|
2122
|
+
Backspace: deleteCellSelection,
|
|
2123
|
+
"Mod-Backspace": deleteCellSelection,
|
|
2124
|
+
Delete: deleteCellSelection,
|
|
2125
|
+
"Mod-Delete": deleteCellSelection
|
|
2126
|
+
});
|
|
2127
|
+
function maybeSetSelection(state, dispatch, selection) {
|
|
2128
|
+
if (selection.eq(state.selection)) return false;
|
|
2129
|
+
if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());
|
|
2130
|
+
return true;
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* @internal
|
|
2134
|
+
*/
|
|
2135
|
+
function arrow(axis, dir) {
|
|
2136
|
+
return (state, dispatch, view) => {
|
|
2137
|
+
if (!view) return false;
|
|
2138
|
+
const sel = state.selection;
|
|
2139
|
+
if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
|
|
2140
|
+
if (axis != "horiz" && !sel.empty) return false;
|
|
2141
|
+
const end = atEndOfCell(view, axis, dir);
|
|
2142
|
+
if (end == null) return false;
|
|
2143
|
+
if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
|
|
2144
|
+
else {
|
|
2145
|
+
const $cell = state.doc.resolve(end);
|
|
2146
|
+
const $next = nextCell($cell, axis, dir);
|
|
2147
|
+
let newSel;
|
|
2148
|
+
if ($next) newSel = Selection.near($next, 1);
|
|
2149
|
+
else if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
|
|
2150
|
+
else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
|
|
2151
|
+
return maybeSetSelection(state, dispatch, newSel);
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
function shiftArrow(axis, dir) {
|
|
2156
|
+
return (state, dispatch, view) => {
|
|
2157
|
+
if (!view) return false;
|
|
2158
|
+
const sel = state.selection;
|
|
2159
|
+
let cellSel;
|
|
2160
|
+
if (sel instanceof CellSelection) cellSel = sel;
|
|
2161
|
+
else {
|
|
2162
|
+
const end = atEndOfCell(view, axis, dir);
|
|
2163
|
+
if (end == null) return false;
|
|
2164
|
+
cellSel = new CellSelection(state.doc.resolve(end));
|
|
2165
|
+
}
|
|
2166
|
+
const $head = nextCell(cellSel.$headCell, axis, dir);
|
|
2167
|
+
if (!$head) return false;
|
|
2168
|
+
return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
function handleTripleClick(view, pos) {
|
|
2172
|
+
const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));
|
|
2173
|
+
if (!$cell) return false;
|
|
2174
|
+
view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
|
|
2175
|
+
return true;
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* @public
|
|
2179
|
+
*/
|
|
2180
|
+
function handlePaste(view, _, slice) {
|
|
2181
|
+
if (!isInTable(view.state)) return false;
|
|
2182
|
+
let cells = pastedCells(slice);
|
|
2183
|
+
const sel = view.state.selection;
|
|
2184
|
+
if (sel instanceof CellSelection) {
|
|
2185
|
+
if (!cells) cells = {
|
|
2186
|
+
width: 1,
|
|
2187
|
+
height: 1,
|
|
2188
|
+
rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice))]
|
|
2189
|
+
};
|
|
2190
|
+
const table = sel.$anchorCell.node(-1);
|
|
2191
|
+
const start = sel.$anchorCell.start(-1);
|
|
2192
|
+
const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start);
|
|
2193
|
+
cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
|
|
2194
|
+
insertCells(view.state, view.dispatch, start, rect, cells);
|
|
2195
|
+
return true;
|
|
2196
|
+
} else if (cells) {
|
|
2197
|
+
const $cell = selectionCell(view.state);
|
|
2198
|
+
const start = $cell.start(-1);
|
|
2199
|
+
insertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells);
|
|
2200
|
+
return true;
|
|
2201
|
+
} else return false;
|
|
2202
|
+
}
|
|
2203
|
+
function handleMouseDown$1(view, startEvent) {
|
|
2204
|
+
var _cellUnderMouse;
|
|
2205
|
+
if (startEvent.button != 0) return;
|
|
2206
|
+
if (startEvent.ctrlKey || startEvent.metaKey) return;
|
|
2207
|
+
const startDOMCell = domInCell(view, startEvent.target);
|
|
2208
|
+
let $anchor;
|
|
2209
|
+
if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
|
|
2210
|
+
setCellSelection(view.state.selection.$anchorCell, startEvent);
|
|
2211
|
+
startEvent.preventDefault();
|
|
2212
|
+
} else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {
|
|
2213
|
+
setCellSelection($anchor, startEvent);
|
|
2214
|
+
startEvent.preventDefault();
|
|
2215
|
+
} else if (!startDOMCell) return;
|
|
2216
|
+
function setCellSelection($anchor$1, event) {
|
|
2217
|
+
let $head = cellUnderMouse(view, event);
|
|
2218
|
+
const starting = tableEditingKey.getState(view.state) == null;
|
|
2219
|
+
if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
|
|
2220
|
+
else return;
|
|
2221
|
+
const selection = new CellSelection($anchor$1, $head);
|
|
2222
|
+
if (starting || !view.state.selection.eq(selection)) {
|
|
2223
|
+
const tr = view.state.tr.setSelection(selection);
|
|
2224
|
+
if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
|
|
2225
|
+
view.dispatch(tr);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
function stop() {
|
|
2229
|
+
view.root.removeEventListener("mouseup", stop);
|
|
2230
|
+
view.root.removeEventListener("dragstart", stop);
|
|
2231
|
+
view.root.removeEventListener("mousemove", move);
|
|
2232
|
+
if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
|
|
2233
|
+
}
|
|
2234
|
+
function move(_event) {
|
|
2235
|
+
const event = _event;
|
|
2236
|
+
const anchor = tableEditingKey.getState(view.state);
|
|
2237
|
+
let $anchor$1;
|
|
2238
|
+
if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
|
|
2239
|
+
else if (domInCell(view, event.target) != startDOMCell) {
|
|
2240
|
+
$anchor$1 = cellUnderMouse(view, startEvent);
|
|
2241
|
+
if (!$anchor$1) return stop();
|
|
2242
|
+
}
|
|
2243
|
+
if ($anchor$1) setCellSelection($anchor$1, event);
|
|
2244
|
+
}
|
|
2245
|
+
view.root.addEventListener("mouseup", stop);
|
|
2246
|
+
view.root.addEventListener("dragstart", stop);
|
|
2247
|
+
view.root.addEventListener("mousemove", move);
|
|
2248
|
+
}
|
|
2249
|
+
function atEndOfCell(view, axis, dir) {
|
|
2250
|
+
if (!(view.state.selection instanceof TextSelection)) return null;
|
|
2251
|
+
const { $head } = view.state.selection;
|
|
2252
|
+
for (let d = $head.depth - 1; d >= 0; d--) {
|
|
2253
|
+
const parent = $head.node(d);
|
|
2254
|
+
if ((dir < 0 ? $head.index(d) : $head.indexAfter(d)) != (dir < 0 ? 0 : parent.childCount)) return null;
|
|
2255
|
+
if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
|
|
2256
|
+
const cellPos = $head.before(d);
|
|
2257
|
+
const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
|
|
2258
|
+
return view.endOfTextblock(dirStr) ? cellPos : null;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
return null;
|
|
2262
|
+
}
|
|
2263
|
+
function domInCell(view, dom) {
|
|
2264
|
+
for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
function cellUnderMouse(view, event) {
|
|
2268
|
+
const mousePos = view.posAtCoords({
|
|
2269
|
+
left: event.clientX,
|
|
2270
|
+
top: event.clientY
|
|
2271
|
+
});
|
|
2272
|
+
if (!mousePos) return null;
|
|
2273
|
+
let { inside, pos } = mousePos;
|
|
2274
|
+
return inside >= 0 && cellAround(view.state.doc.resolve(inside)) || cellAround(view.state.doc.resolve(pos));
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
//#endregion
|
|
2278
|
+
//#region src/tableview.ts
|
|
2279
|
+
/**
|
|
2280
|
+
* @public
|
|
2281
|
+
*/
|
|
2282
|
+
var TableView = class {
|
|
2283
|
+
constructor(node, defaultCellMinWidth) {
|
|
2284
|
+
this.node = node;
|
|
2285
|
+
this.defaultCellMinWidth = defaultCellMinWidth;
|
|
2286
|
+
this.dom = document.createElement("div");
|
|
2287
|
+
this.dom.className = "tableWrapper";
|
|
2288
|
+
this.table = this.dom.appendChild(document.createElement("table"));
|
|
2289
|
+
this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`);
|
|
2290
|
+
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
2291
|
+
updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
|
|
2292
|
+
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
2293
|
+
}
|
|
2294
|
+
update(node) {
|
|
2295
|
+
if (node.type != this.node.type) return false;
|
|
2296
|
+
this.node = node;
|
|
2297
|
+
updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);
|
|
2298
|
+
return true;
|
|
2299
|
+
}
|
|
2300
|
+
ignoreMutation(record) {
|
|
2301
|
+
return record.type == "attributes" && (record.target == this.table || this.colgroup.contains(record.target));
|
|
2302
|
+
}
|
|
2303
|
+
};
|
|
2304
|
+
/**
|
|
2305
|
+
* @public
|
|
2306
|
+
*/
|
|
2307
|
+
function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
|
|
2308
|
+
let totalWidth = 0;
|
|
2309
|
+
let fixedWidth = true;
|
|
2310
|
+
let nextDOM = colgroup.firstChild;
|
|
2311
|
+
const row = node.firstChild;
|
|
2312
|
+
if (!row) return;
|
|
2313
|
+
for (let i = 0, col = 0; i < row.childCount; i++) {
|
|
2314
|
+
const { colspan, colwidth } = row.child(i).attrs;
|
|
2315
|
+
for (let j = 0; j < colspan; j++, col++) {
|
|
2316
|
+
const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];
|
|
2317
|
+
const cssWidth = hasWidth ? hasWidth + "px" : "";
|
|
2318
|
+
totalWidth += hasWidth || defaultCellMinWidth;
|
|
2319
|
+
if (!hasWidth) fixedWidth = false;
|
|
2320
|
+
if (!nextDOM) {
|
|
2321
|
+
const col$1 = document.createElement("col");
|
|
2322
|
+
col$1.style.width = cssWidth;
|
|
2323
|
+
colgroup.appendChild(col$1);
|
|
2324
|
+
} else {
|
|
2325
|
+
if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;
|
|
2326
|
+
nextDOM = nextDOM.nextSibling;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
while (nextDOM) {
|
|
2331
|
+
var _nextDOM$parentNode;
|
|
2332
|
+
const after = nextDOM.nextSibling;
|
|
2333
|
+
(_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);
|
|
2334
|
+
nextDOM = after;
|
|
2335
|
+
}
|
|
2336
|
+
if (fixedWidth) {
|
|
2337
|
+
table.style.width = totalWidth + "px";
|
|
2338
|
+
table.style.minWidth = "";
|
|
2339
|
+
} else {
|
|
2340
|
+
table.style.width = "";
|
|
2341
|
+
table.style.minWidth = totalWidth + "px";
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
//#endregion
|
|
2346
|
+
//#region src/columnresizing.ts
|
|
2347
|
+
/**
|
|
2348
|
+
* @public
|
|
2349
|
+
*/
|
|
2350
|
+
const columnResizingPluginKey = new PluginKey("tableColumnResizing");
|
|
2351
|
+
/**
|
|
2352
|
+
* @public
|
|
2353
|
+
*/
|
|
2354
|
+
function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {
|
|
2355
|
+
const plugin = new Plugin({
|
|
2356
|
+
key: columnResizingPluginKey,
|
|
2357
|
+
state: {
|
|
2358
|
+
init(_, state) {
|
|
2359
|
+
var _plugin$spec;
|
|
2360
|
+
const nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;
|
|
2361
|
+
const tableName = tableNodeTypes(state.schema).table.name;
|
|
2362
|
+
if (View && nodeViews) nodeViews[tableName] = (node, view) => {
|
|
2363
|
+
return new View(node, defaultCellMinWidth, view);
|
|
2364
|
+
};
|
|
2365
|
+
return new ResizeState(-1, false);
|
|
2366
|
+
},
|
|
2367
|
+
apply(tr, prev) {
|
|
2368
|
+
return prev.apply(tr);
|
|
2369
|
+
}
|
|
2370
|
+
},
|
|
2371
|
+
props: {
|
|
2372
|
+
attributes: (state) => {
|
|
2373
|
+
const pluginState = columnResizingPluginKey.getState(state);
|
|
2374
|
+
return pluginState && pluginState.activeHandle > -1 ? { class: "resize-cursor" } : {};
|
|
2375
|
+
},
|
|
2376
|
+
handleDOMEvents: {
|
|
2377
|
+
mousemove: (view, event) => {
|
|
2378
|
+
handleMouseMove(view, event, handleWidth, lastColumnResizable);
|
|
2379
|
+
},
|
|
2380
|
+
mouseleave: (view) => {
|
|
2381
|
+
handleMouseLeave(view);
|
|
2382
|
+
},
|
|
2383
|
+
mousedown: (view, event) => {
|
|
2384
|
+
handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth);
|
|
2385
|
+
}
|
|
2386
|
+
},
|
|
2387
|
+
decorations: (state) => {
|
|
2388
|
+
const pluginState = columnResizingPluginKey.getState(state);
|
|
2389
|
+
if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);
|
|
2390
|
+
},
|
|
2391
|
+
nodeViews: {}
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
return plugin;
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* @public
|
|
2398
|
+
*/
|
|
2399
|
+
var ResizeState = class ResizeState {
|
|
2400
|
+
constructor(activeHandle, dragging) {
|
|
2401
|
+
this.activeHandle = activeHandle;
|
|
2402
|
+
this.dragging = dragging;
|
|
2403
|
+
}
|
|
2404
|
+
apply(tr) {
|
|
2405
|
+
const state = this;
|
|
2406
|
+
const action = tr.getMeta(columnResizingPluginKey);
|
|
2407
|
+
if (action && action.setHandle != null) return new ResizeState(action.setHandle, false);
|
|
2408
|
+
if (action && action.setDragging !== void 0) return new ResizeState(state.activeHandle, action.setDragging);
|
|
2409
|
+
if (state.activeHandle > -1 && tr.docChanged) {
|
|
2410
|
+
let handle = tr.mapping.map(state.activeHandle, -1);
|
|
2411
|
+
if (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;
|
|
2412
|
+
return new ResizeState(handle, state.dragging);
|
|
2413
|
+
}
|
|
2414
|
+
return state;
|
|
2415
|
+
}
|
|
2416
|
+
};
|
|
2417
|
+
function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
|
|
2418
|
+
if (!view.editable) return;
|
|
2419
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
2420
|
+
if (!pluginState) return;
|
|
2421
|
+
if (!pluginState.dragging) {
|
|
2422
|
+
const target = domCellAround(event.target);
|
|
2423
|
+
let cell = -1;
|
|
2424
|
+
if (target) {
|
|
2425
|
+
const { left, right } = target.getBoundingClientRect();
|
|
2426
|
+
if (event.clientX - left <= handleWidth) cell = edgeCell(view, event, "left", handleWidth);
|
|
2427
|
+
else if (right - event.clientX <= handleWidth) cell = edgeCell(view, event, "right", handleWidth);
|
|
2428
|
+
}
|
|
2429
|
+
if (cell != pluginState.activeHandle) {
|
|
2430
|
+
if (!lastColumnResizable && cell !== -1) {
|
|
2431
|
+
const $cell = view.state.doc.resolve(cell);
|
|
2432
|
+
const table = $cell.node(-1);
|
|
2433
|
+
const map = TableMap.get(table);
|
|
2434
|
+
const tableStart = $cell.start(-1);
|
|
2435
|
+
if (map.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map.width - 1) return;
|
|
2436
|
+
}
|
|
2437
|
+
updateHandle(view, cell);
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
function handleMouseLeave(view) {
|
|
2442
|
+
if (!view.editable) return;
|
|
2443
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
2444
|
+
if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);
|
|
2445
|
+
}
|
|
2446
|
+
function handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth) {
|
|
2447
|
+
var _view$dom$ownerDocume;
|
|
2448
|
+
if (!view.editable) return false;
|
|
2449
|
+
const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;
|
|
2450
|
+
const pluginState = columnResizingPluginKey.getState(view.state);
|
|
2451
|
+
if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;
|
|
2452
|
+
const cell = view.state.doc.nodeAt(pluginState.activeHandle);
|
|
2453
|
+
const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
|
|
2454
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {
|
|
2455
|
+
startX: event.clientX,
|
|
2456
|
+
startWidth: width
|
|
2457
|
+
} }));
|
|
2458
|
+
function finish(event$1) {
|
|
2459
|
+
win.removeEventListener("mouseup", finish);
|
|
2460
|
+
win.removeEventListener("mousemove", move);
|
|
2461
|
+
const pluginState$1 = columnResizingPluginKey.getState(view.state);
|
|
2462
|
+
if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {
|
|
2463
|
+
updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth));
|
|
2464
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
function move(event$1) {
|
|
2468
|
+
if (!event$1.which) return finish(event$1);
|
|
2469
|
+
const pluginState$1 = columnResizingPluginKey.getState(view.state);
|
|
2470
|
+
if (!pluginState$1) return;
|
|
2471
|
+
if (pluginState$1.dragging) {
|
|
2472
|
+
const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth);
|
|
2473
|
+
displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);
|
|
2477
|
+
win.addEventListener("mouseup", finish);
|
|
2478
|
+
win.addEventListener("mousemove", move);
|
|
2479
|
+
event.preventDefault();
|
|
2480
|
+
return true;
|
|
2481
|
+
}
|
|
2482
|
+
function currentColWidth(view, cellPos, { colspan, colwidth }) {
|
|
2483
|
+
const width = colwidth && colwidth[colwidth.length - 1];
|
|
2484
|
+
if (width) return width;
|
|
2485
|
+
const dom = view.domAtPos(cellPos);
|
|
2486
|
+
let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;
|
|
2487
|
+
if (colwidth) {
|
|
2488
|
+
for (let i = 0; i < colspan; i++) if (colwidth[i]) {
|
|
2489
|
+
domWidth -= colwidth[i];
|
|
2490
|
+
parts--;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
return domWidth / parts;
|
|
2494
|
+
}
|
|
2495
|
+
function domCellAround(target) {
|
|
2496
|
+
while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
|
|
2497
|
+
return target;
|
|
2498
|
+
}
|
|
2499
|
+
function edgeCell(view, event, side, handleWidth) {
|
|
2500
|
+
const offset = side == "right" ? -handleWidth : handleWidth;
|
|
2501
|
+
const found = view.posAtCoords({
|
|
2502
|
+
left: event.clientX + offset,
|
|
2503
|
+
top: event.clientY
|
|
2504
|
+
});
|
|
2505
|
+
if (!found) return -1;
|
|
2506
|
+
const { pos } = found;
|
|
2507
|
+
const $cell = cellAround(view.state.doc.resolve(pos));
|
|
2508
|
+
if (!$cell) return -1;
|
|
2509
|
+
if (side == "right") return $cell.pos;
|
|
2510
|
+
const map = TableMap.get($cell.node(-1)), start = $cell.start(-1);
|
|
2511
|
+
const index = map.map.indexOf($cell.pos - start);
|
|
2512
|
+
return index % map.width == 0 ? -1 : start + map.map[index - 1];
|
|
2513
|
+
}
|
|
2514
|
+
function draggedWidth(dragging, event, resizeMinWidth) {
|
|
2515
|
+
const offset = event.clientX - dragging.startX;
|
|
2516
|
+
return Math.max(resizeMinWidth, dragging.startWidth + offset);
|
|
2517
|
+
}
|
|
2518
|
+
function updateHandle(view, value) {
|
|
2519
|
+
view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));
|
|
2520
|
+
}
|
|
2521
|
+
function updateColumnWidth(view, cell, width) {
|
|
2522
|
+
const $cell = view.state.doc.resolve(cell);
|
|
2523
|
+
const table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
|
|
2524
|
+
const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
|
|
2525
|
+
const tr = view.state.tr;
|
|
2526
|
+
for (let row = 0; row < map.height; row++) {
|
|
2527
|
+
const mapIndex = row * map.width + col;
|
|
2528
|
+
if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) continue;
|
|
2529
|
+
const pos = map.map[mapIndex];
|
|
2530
|
+
const attrs = table.nodeAt(pos).attrs;
|
|
2531
|
+
const index = attrs.colspan == 1 ? 0 : col - map.colCount(pos);
|
|
2532
|
+
if (attrs.colwidth && attrs.colwidth[index] == width) continue;
|
|
2533
|
+
const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
|
|
2534
|
+
colwidth[index] = width;
|
|
2535
|
+
tr.setNodeMarkup(start + pos, null, {
|
|
2536
|
+
...attrs,
|
|
2537
|
+
colwidth
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
if (tr.docChanged) view.dispatch(tr);
|
|
2541
|
+
}
|
|
2542
|
+
function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
|
|
2543
|
+
const $cell = view.state.doc.resolve(cell);
|
|
2544
|
+
const table = $cell.node(-1), start = $cell.start(-1);
|
|
2545
|
+
const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
|
|
2546
|
+
let dom = view.domAtPos($cell.start(-1)).node;
|
|
2547
|
+
while (dom && dom.nodeName != "TABLE") dom = dom.parentNode;
|
|
2548
|
+
if (!dom) return;
|
|
2549
|
+
updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);
|
|
2550
|
+
}
|
|
2551
|
+
function zeroes(n) {
|
|
2552
|
+
return Array(n).fill(0);
|
|
2553
|
+
}
|
|
2554
|
+
function handleDecorations(state, cell) {
|
|
2555
|
+
const decorations = [];
|
|
2556
|
+
const $cell = state.doc.resolve(cell);
|
|
2557
|
+
const table = $cell.node(-1);
|
|
2558
|
+
if (!table) return DecorationSet.empty;
|
|
2559
|
+
const map = TableMap.get(table);
|
|
2560
|
+
const start = $cell.start(-1);
|
|
2561
|
+
const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
|
|
2562
|
+
for (let row = 0; row < map.height; row++) {
|
|
2563
|
+
const index = col + row * map.width;
|
|
2564
|
+
if ((col == map.width - 1 || map.map[index] != map.map[index + 1]) && (row == 0 || map.map[index] != map.map[index - map.width])) {
|
|
2565
|
+
var _columnResizingPlugin;
|
|
2566
|
+
const cellPos = map.map[index];
|
|
2567
|
+
const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
|
|
2568
|
+
const dom = document.createElement("div");
|
|
2569
|
+
dom.className = "column-resize-handle";
|
|
2570
|
+
if ((_columnResizingPlugin = columnResizingPluginKey.getState(state)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start + cellPos, start + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" }));
|
|
2571
|
+
decorations.push(Decoration.widget(pos, dom));
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
return DecorationSet.create(state.doc, decorations);
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
//#endregion
|
|
2578
|
+
//#region src/index.ts
|
|
2579
|
+
/**
|
|
2580
|
+
* Creates a [plugin](http://prosemirror.net/docs/ref/#state.Plugin)
|
|
2581
|
+
* that, when added to an editor, enables cell-selection, handles
|
|
2582
|
+
* cell-based copy/paste, and makes sure tables stay well-formed (each
|
|
2583
|
+
* row has the same width, and cells don't overlap).
|
|
2584
|
+
*
|
|
2585
|
+
* You should probably put this plugin near the end of your array of
|
|
2586
|
+
* plugins, since it handles mouse and arrow key events in tables
|
|
2587
|
+
* rather broadly, and other plugins, like the gap cursor or the
|
|
2588
|
+
* column-width dragging plugin, might want to get a turn first to
|
|
2589
|
+
* perform more specific behavior.
|
|
2590
|
+
*
|
|
2591
|
+
* @public
|
|
2592
|
+
*/
|
|
2593
|
+
function tableEditing({ allowTableNodeSelection = false } = {}) {
|
|
2594
|
+
return new Plugin({
|
|
2595
|
+
key: tableEditingKey,
|
|
2596
|
+
state: {
|
|
2597
|
+
init() {
|
|
2598
|
+
return null;
|
|
2599
|
+
},
|
|
2600
|
+
apply(tr, cur) {
|
|
2601
|
+
const set = tr.getMeta(tableEditingKey);
|
|
2602
|
+
if (set != null) return set == -1 ? null : set;
|
|
2603
|
+
if (cur == null || !tr.docChanged) return cur;
|
|
2604
|
+
const { deleted, pos } = tr.mapping.mapResult(cur);
|
|
2605
|
+
return deleted ? null : pos;
|
|
2606
|
+
}
|
|
2607
|
+
},
|
|
2608
|
+
props: {
|
|
2609
|
+
decorations: drawCellSelection,
|
|
2610
|
+
handleDOMEvents: { mousedown: handleMouseDown$1 },
|
|
2611
|
+
createSelectionBetween(view) {
|
|
2612
|
+
return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
|
|
2613
|
+
},
|
|
2614
|
+
handleTripleClick,
|
|
2615
|
+
handleKeyDown,
|
|
2616
|
+
handlePaste
|
|
2617
|
+
},
|
|
2618
|
+
appendTransaction(_, oldState, state) {
|
|
2619
|
+
return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
//#endregion
|
|
2625
|
+
export { CellBookmark, CellSelection, ResizeState, TableMap, TableView, clipCells as __clipCells, insertCells as __insertCells, pastedCells as __pastedCells, addColSpan, addColumn, addColumnAfter, addColumnBefore, addRow, addRowAfter, addRowBefore, cellAround, cellNear, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, deleteCellSelection, deleteColumn, deleteRow, deleteTable, findCell, findCellPos, findCellRange, findTable, fixTables, fixTablesKey, goToNextCell, handlePaste, inSameTable, isInTable, mergeCells, moveCellForward, moveTableColumn, moveTableRow, nextCell, pointsAtCell, removeColSpan, removeColumn, removeRow, rowIsHeader, selectedRect, selectionCell, setCellAttr, splitCell, splitCellWithType, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, updateColumnsOnResize };
|
|
2626
|
+
//# sourceMappingURL=index.js.map
|