@vc-shell/framework 1.1.44 → 1.1.45

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.
Files changed (453) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/core/plugins/modularity/loader.ts +120 -74
  3. package/core/services/app-bar-mobile-buttons-service.ts +1 -1
  4. package/dist/core/plugins/modularity/loader.d.ts.map +1 -1
  5. package/dist/core/services/app-bar-mobile-buttons-service.d.ts +1 -1
  6. package/dist/core/services/app-bar-mobile-buttons-service.d.ts.map +1 -1
  7. package/dist/framework.js +33347 -295
  8. package/dist/index.css +1 -9
  9. package/dist/index.d.ts +0 -4
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/locales/de.json +0 -84
  12. package/dist/locales/en.json +0 -84
  13. package/dist/shared/components/blade-navigation/components/vc-blade-navigation/_internal/vc-mobile-back-button.vue.d.ts.map +1 -1
  14. package/dist/shared/components/blade-navigation/components/vc-blade-view/vc-blade-view.d.ts +1 -1
  15. package/dist/shared/components/blade-navigation/components/vc-blade-view/vc-blade-view.d.ts.map +1 -1
  16. package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeRouteResolver.d.ts.map +1 -1
  17. package/dist/shared/components/change-password-button/change-password-button.vue.d.ts.map +1 -1
  18. package/dist/shared/components/logout-button/logout-button.vue.d.ts.map +1 -1
  19. package/dist/shared/components/settings-menu-item/settings-menu-item.vue.d.ts.map +1 -1
  20. package/dist/shared/modules/dynamic/pages/dynamic-blade-form.vue.d.ts +2 -2
  21. package/dist/shared/modules/dynamic/pages/dynamic-blade-list.vue.d.ts +6 -6
  22. package/dist/shared/modules/dynamic/pages/dynamic-blade-list.vue.d.ts.map +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/dist/ui/components/atoms/vc-hint/vc-hint.vue.d.ts.map +1 -1
  25. package/dist/ui/components/atoms/vc-icon/icons/MenuBurgerIcon.vue.d.ts.map +1 -1
  26. package/dist/ui/components/atoms/vc-icon/icons/index.d.ts +0 -26
  27. package/dist/ui/components/atoms/vc-icon/icons/index.d.ts.map +1 -1
  28. package/dist/ui/components/atoms/vc-icon/vc-bootstrap-icon.vue.d.ts.map +1 -1
  29. package/dist/ui/components/atoms/vc-icon/vc-fontawesome-icon.vue.d.ts.map +1 -1
  30. package/dist/ui/components/atoms/vc-icon/vc-icon.vue.d.ts.map +1 -1
  31. package/dist/ui/components/atoms/vc-icon/vc-lucide-icon.vue.d.ts +0 -5
  32. package/dist/ui/components/atoms/vc-icon/vc-lucide-icon.vue.d.ts.map +1 -1
  33. package/dist/ui/components/atoms/vc-icon/vc-material-icon.vue.d.ts +0 -20
  34. package/dist/ui/components/atoms/vc-icon/vc-material-icon.vue.d.ts.map +1 -1
  35. package/dist/ui/components/molecules/vc-breadcrumbs/vc-breadcrumbs.vue.d.ts.map +1 -1
  36. package/dist/ui/components/molecules/vc-editor/_internal/vc-editor-button.vue.d.ts +36 -0
  37. package/dist/ui/components/molecules/vc-editor/_internal/vc-editor-button.vue.d.ts.map +1 -0
  38. package/dist/ui/components/molecules/vc-editor/_internal/vc-editor-toolbar.vue.d.ts +17 -0
  39. package/dist/ui/components/molecules/vc-editor/_internal/vc-editor-toolbar.vue.d.ts.map +1 -0
  40. package/dist/ui/components/molecules/vc-editor/vc-editor.vue.d.ts +16 -2381
  41. package/dist/ui/components/molecules/vc-editor/vc-editor.vue.d.ts.map +1 -1
  42. package/dist/ui/components/molecules/vc-form/vc-form.vue.d.ts.map +1 -1
  43. package/dist/ui/components/molecules/vc-input-currency/vc-input-currency.vue.d.ts +1 -1
  44. package/dist/ui/components/molecules/vc-input-currency/vc-input-currency.vue.d.ts.map +1 -1
  45. package/dist/ui/components/molecules/vc-multivalue/vc-multivalue.vue.d.ts +1 -1
  46. package/dist/ui/components/molecules/vc-pagination/vc-pagination.vue.d.ts.map +1 -1
  47. package/dist/ui/components/organisms/vc-app/_internal/vc-app-bar/_internal/MenuSidebar.vue.d.ts.map +1 -1
  48. package/dist/ui/components/organisms/vc-app/_internal/vc-app-bar/vc-app-bar.vue.d.ts.map +1 -1
  49. package/dist/ui/components/organisms/vc-app/_internal/vc-app-menu/_internal/vc-app-menu-item/_internal/vc-app-menu-link.vue.d.ts.map +1 -1
  50. package/dist/ui/components/organisms/vc-app/vc-app.vue.d.ts.map +1 -1
  51. package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-header/vc-blade-header.vue.d.ts.map +1 -1
  52. package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-widget-container/_internal/vc-widget-container-desktop.vue.d.ts.map +1 -1
  53. package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-widget-container/_internal/vc-widget-container-mobile.vue.d.ts.map +1 -1
  54. package/dist/ui/components/organisms/vc-blade/vc-blade.vue.d.ts.map +1 -1
  55. package/dist/ui/components/organisms/vc-gallery/_internal/vc-gallery-item/vc-gallery-item.vue.d.ts +2 -2
  56. package/dist/ui/components/organisms/vc-gallery/vc-gallery.vue.d.ts +2 -2
  57. package/dist/ui/components/organisms/vc-table/_internal/vc-table-filter/vc-table-filter.vue.d.ts.map +1 -1
  58. package/dist/ui/components/organisms/vc-table/_internal/vc-table-header/vc-table-header.vue.d.ts.map +1 -1
  59. package/dist/vendor-boolbase-Cp9L0GAZ.js +25 -0
  60. package/dist/vendor-cheerio-HN9zIPZn.js +3135 -0
  61. package/dist/vendor-cheerio-select-5Ry0HvBq.js +306 -0
  62. package/dist/vendor-core-js-l0sNRNKZ.js +1 -0
  63. package/dist/vendor-css-select-DRIZ9kfZ.js +966 -0
  64. package/dist/vendor-css-what-DuPJ1HEF.js +448 -0
  65. package/dist/vendor-cypress-signalr-mock-BKdBJpdt.js +778 -0
  66. package/dist/vendor-date-fns-515YWkk-.js +6724 -0
  67. package/dist/vendor-dom-serializer-nQMsqjYW.js +286 -0
  68. package/dist/vendor-dom7-CJLPMwy5.js +941 -0
  69. package/dist/vendor-domelementtype-CjSzQey5.js +53 -0
  70. package/dist/vendor-domhandler-9z8cS16a.js +484 -0
  71. package/dist/vendor-dompurify-CRFzu7ib.js +1336 -0
  72. package/dist/vendor-domutils-Bc-Opz-v.js +981 -0
  73. package/dist/vendor-entities-Bfsx4xOQ.js +636 -0
  74. package/dist/vendor-floating-ui-core-wV8u8QP4.js +511 -0
  75. package/dist/vendor-floating-ui-dom-DDnRPs17.js +706 -0
  76. package/dist/vendor-floating-ui-utils-OMIFy1QU.js +296 -0
  77. package/dist/vendor-floating-ui-vue-D-tCDAMm.js +167 -0
  78. package/dist/vendor-fontsource-plus-jakarta-sans.css +1 -0
  79. package/dist/vendor-headlessui-vue-CY9FRgTb.js +83 -0
  80. package/dist/vendor-htmlparser2-B1dhFPOs.js +1426 -0
  81. package/dist/vendor-iconify-vue-DfRGgyNu.js +1840 -0
  82. package/dist/vendor-intlify-core-base-BuknsFQe.js +1876 -0
  83. package/dist/vendor-intlify-message-compiler-CuOQDWx1.js +1508 -0
  84. package/dist/vendor-intlify-shared-Cz4YRMuC.js +241 -0
  85. package/dist/vendor-iso-639-1-BJCk9DvE.js +819 -0
  86. package/dist/vendor-linkify-it-CKUf4vsc.js +830 -0
  87. package/dist/vendor-linkifyjs-BfyGgbCh.js +1756 -0
  88. package/dist/vendor-lodash-es-BySUOlwf.js +18333 -0
  89. package/dist/vendor-markdown-it-D-apazHa.js +6000 -0
  90. package/dist/vendor-markdown-it-task-lists-rxMVH6Ku.js +131 -0
  91. package/dist/vendor-mdurl-BNh2CCgT.js +537 -0
  92. package/dist/vendor-microsoft-applicationinsights-analytics-js-kG3lLg8X.js +1275 -0
  93. package/dist/vendor-microsoft-applicationinsights-cfgsync-js-C0uQkiQq.js +591 -0
  94. package/dist/vendor-microsoft-applicationinsights-channel-js-Dyd_PXA3.js +2153 -0
  95. package/dist/vendor-microsoft-applicationinsights-common-CfmP1_Qr.js +2470 -0
  96. package/dist/vendor-microsoft-applicationinsights-core-js-Cq4YSEvZ.js +6589 -0
  97. package/dist/vendor-microsoft-applicationinsights-dependencies-js-C56OBFr4.js +1510 -0
  98. package/dist/vendor-microsoft-applicationinsights-properties-js-CBJTBawx.js +761 -0
  99. package/dist/vendor-microsoft-applicationinsights-shims-CX8sJgar.js +70 -0
  100. package/dist/vendor-microsoft-applicationinsights-web-pim2ri-g.js +667 -0
  101. package/dist/vendor-microsoft-dynamicproto-js-CFBBUu9p.js +520 -0
  102. package/dist/vendor-microsoft-signalr-dUnlRsGm.js +3339 -0
  103. package/dist/vendor-moment-Mki5YqAR.js +5679 -0
  104. package/dist/vendor-nevware21-ts-async-CLMApQ9E.js +395 -0
  105. package/dist/vendor-nevware21-ts-utils-e8v8Jty3.js +1160 -0
  106. package/dist/vendor-normalize-css.css +1 -0
  107. package/dist/vendor-nth-check-Bx8TxtJt.js +157 -0
  108. package/dist/vendor-orderedmap-dGG6uMFJ.js +137 -0
  109. package/dist/vendor-parse5-Bt2NhSzR.js +8432 -0
  110. package/dist/vendor-parse5-htmlparser2-tree-adapter-BUUtKzf8.js +216 -0
  111. package/dist/vendor-popperjs-core-Cr2byIky.js +1790 -0
  112. package/dist/vendor-prettier-B4PaeWRQ.js +98 -0
  113. package/dist/vendor-prosemirror-commands-BH9lWGpW.js +561 -0
  114. package/dist/vendor-prosemirror-dropcursor-CeyPcxrA.js +146 -0
  115. package/dist/vendor-prosemirror-gapcursor-U8UoUJII.js +236 -0
  116. package/dist/vendor-prosemirror-history-BDaJkvNx.js +414 -0
  117. package/dist/vendor-prosemirror-keymap-BbWvIWmH.js +128 -0
  118. package/dist/vendor-prosemirror-markdown-gB0PXBbz.js +866 -0
  119. package/dist/vendor-prosemirror-model-BZu3WVcD.js +3463 -0
  120. package/dist/vendor-prosemirror-schema-list-Bl9NpKA7.js +158 -0
  121. package/dist/vendor-prosemirror-state-BvL9Pxph.js +1003 -0
  122. package/dist/vendor-prosemirror-tables-17qAnviK.js +2159 -0
  123. package/dist/vendor-prosemirror-transform-CE9VV3qg.js +2156 -0
  124. package/dist/vendor-prosemirror-view-CU2WTHT7.js +5811 -0
  125. package/dist/vendor-punycode-js-iAs5RxMf.js +441 -0
  126. package/dist/vendor-rope-sequence-BdXDKoGt.js +207 -0
  127. package/dist/vendor-semver-CVLMK-S4.js +2702 -0
  128. package/dist/vendor-ssr-window-s6OpKa3O.js +150 -0
  129. package/dist/vendor-swiper-CdiyNHVt.js +5679 -0
  130. package/dist/vendor-swiper.css +1 -0
  131. package/dist/vendor-tanstack-virtual-core-l0sNRNKZ.js +1 -0
  132. package/dist/vendor-tanstack-vue-virtual-l0sNRNKZ.js +1 -0
  133. package/dist/vendor-tippy-js-DWFe2TfK.js +1647 -0
  134. package/dist/vendor-tiptap-core-NfwGfaQk.js +4910 -0
  135. package/dist/vendor-tiptap-extension-blockquote-jmWBTtsI.js +57 -0
  136. package/dist/vendor-tiptap-extension-bold-p5frh4ak.js +97 -0
  137. package/dist/vendor-tiptap-extension-bubble-menu-KUhZSfrs.js +218 -0
  138. package/dist/vendor-tiptap-extension-bullet-list-COmZRoSB.js +73 -0
  139. package/dist/vendor-tiptap-extension-code-block-DyTARZss.js +221 -0
  140. package/dist/vendor-tiptap-extension-code-jVv6CXpX.js +75 -0
  141. package/dist/vendor-tiptap-extension-document-DssuotYs.js +13 -0
  142. package/dist/vendor-tiptap-extension-dropcursor-BoO0Qv91.js +26 -0
  143. package/dist/vendor-tiptap-extension-floating-menu-CrO8CN5w.js +165 -0
  144. package/dist/vendor-tiptap-extension-gapcursor-KpsWEoMD.js +30 -0
  145. package/dist/vendor-tiptap-extension-hard-break-ldOzhSvf.js +68 -0
  146. package/dist/vendor-tiptap-extension-heading-CKz2llX0.js +77 -0
  147. package/dist/vendor-tiptap-extension-history-DeKZ2VQ9.js +48 -0
  148. package/dist/vendor-tiptap-extension-horizontal-rule-CAjWRyDS.js +92 -0
  149. package/dist/vendor-tiptap-extension-image-ZagcEYuk.js +76 -0
  150. package/dist/vendor-tiptap-extension-italic-CM4xdznY.js +96 -0
  151. package/dist/vendor-tiptap-extension-link-Z-AMC4Ri.js +414 -0
  152. package/dist/vendor-tiptap-extension-list-item-BJi5QpXc.js +37 -0
  153. package/dist/vendor-tiptap-extension-ordered-list-C_TMrfBE.js +97 -0
  154. package/dist/vendor-tiptap-extension-paragraph-CQw0E0Au.js +39 -0
  155. package/dist/vendor-tiptap-extension-placeholder-BBNVKfa_.js +66 -0
  156. package/dist/vendor-tiptap-extension-strike-DUyMYX1Z.js +79 -0
  157. package/dist/vendor-tiptap-extension-table-cell-CoDIMPA5.js +47 -0
  158. package/dist/vendor-tiptap-extension-table-header-DvbGHnmw.js +47 -0
  159. package/dist/vendor-tiptap-extension-table-row-D1uqN5Aj.js +26 -0
  160. package/dist/vendor-tiptap-extension-table-tKS4MOM4.js +354 -0
  161. package/dist/vendor-tiptap-extension-text-DtRBhKB2.js +12 -0
  162. package/dist/vendor-tiptap-extension-underline-DqaSFp_P.js +50 -0
  163. package/dist/vendor-tiptap-markdown-7-PCADTU.js +1017 -0
  164. package/dist/vendor-tiptap-pm-l0sNRNKZ.js +1 -0
  165. package/dist/vendor-tiptap-starter-kit-CDSV_Zuu.js +88 -0
  166. package/dist/vendor-tiptap-vue-3-DZg2fjq_.js +268 -0
  167. package/dist/vendor-truncate-html-3qQY0Djo.js +196 -0
  168. package/dist/vendor-uc-micro-jjt6LQ65.js +23 -0
  169. package/dist/vendor-vee-validate-i18n-v_gHjRmD.js +154 -0
  170. package/dist/vendor-vee-validate-rules-DzV3VY3N.js +536 -0
  171. package/dist/vendor-vue-currency-input-DGAkEFBO.js +545 -0
  172. package/dist/vendor-vue-demi-l0sNRNKZ.js +1 -0
  173. package/dist/vendor-vue-devtools-api-DXYR8qBG.js +169 -0
  174. package/dist/vendor-vue-i18n-Co752uk3.js +1897 -0
  175. package/dist/vendor-vue3-application-insights-CYWFCr_J.js +119 -0
  176. package/dist/vendor-vue3-touch-events-BJEAiSa3.js +416 -0
  177. package/dist/vendor-vuepic-vue-datepicker-BSWXRSiu.js +5019 -0
  178. package/dist/vendor-vuepic-vue-datepicker.css +1 -0
  179. package/dist/vendor-vueuse-components-l1bL12mE.js +339 -0
  180. package/dist/vendor-vueuse-core-DGcJOmwG.js +7743 -0
  181. package/dist/vendor-vueuse-shared-_mOXsFuM.js +1568 -0
  182. package/dist/vendor-w3c-keyname-BOm2dtJm.js +121 -0
  183. package/package.json +22 -11
  184. package/shared/components/blade-navigation/components/vc-blade-navigation/_internal/vc-mobile-back-button.vue +3 -3
  185. package/shared/components/blade-navigation/components/vc-blade-view/vc-blade-view.ts +2 -1
  186. package/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeRouteResolver.ts +1 -0
  187. package/shared/components/change-password-button/change-password-button.vue +1 -2
  188. package/shared/components/logout-button/logout-button.vue +1 -2
  189. package/shared/components/notifications/components/notification-container/index.ts +1 -1
  190. package/shared/components/notifications/core/notification.ts +1 -1
  191. package/shared/components/settings-menu-item/settings-menu-item.vue +1 -0
  192. package/shared/components/sidebar/sidebar.vue +2 -2
  193. package/shared/modules/dynamic/pages/dynamic-blade-list.vue +2 -1
  194. package/ui/components/atoms/vc-hint/vc-hint.vue +2 -0
  195. package/ui/components/atoms/vc-icon/composables/use-icon.ts +1 -1
  196. package/ui/components/atoms/vc-icon/icons/MenuBurgerIcon.vue +18 -14
  197. package/ui/components/atoms/vc-icon/icons/index.ts +1 -27
  198. package/ui/components/atoms/vc-icon/vc-bootstrap-icon.vue +7 -11
  199. package/ui/components/atoms/vc-icon/vc-fontawesome-icon.vue +37 -31
  200. package/ui/components/atoms/vc-icon/vc-icon-examples.vue +1 -1
  201. package/ui/components/atoms/vc-icon/vc-icon.stories.ts +4 -5
  202. package/ui/components/atoms/vc-icon/vc-icon.vue +33 -163
  203. package/ui/components/atoms/vc-icon/vc-lucide-icon.vue +22 -70
  204. package/ui/components/atoms/vc-icon/vc-material-icon.vue +28 -59
  205. package/ui/components/molecules/vc-breadcrumbs/vc-breadcrumbs.vue +2 -3
  206. package/ui/components/molecules/vc-editor/_internal/vc-editor-button.vue +103 -0
  207. package/ui/components/molecules/vc-editor/_internal/vc-editor-toolbar.vue +252 -0
  208. package/ui/components/molecules/vc-editor/vc-editor.stories.ts +1 -4
  209. package/ui/components/molecules/vc-editor/vc-editor.vue +666 -360
  210. package/ui/components/molecules/vc-form/vc-form.vue +7 -5
  211. package/ui/components/molecules/vc-input/vc-input.vue +1 -1
  212. package/ui/components/molecules/vc-pagination/vc-pagination.vue +4 -17
  213. package/ui/components/organisms/vc-app/_internal/vc-app-bar/_internal/AppBarMobileActions.vue +1 -1
  214. package/ui/components/organisms/vc-app/_internal/vc-app-bar/_internal/MenuSidebar.vue +1 -3
  215. package/ui/components/organisms/vc-app/_internal/vc-app-bar/vc-app-bar.vue +1 -4
  216. package/ui/components/organisms/vc-app/_internal/vc-app-menu/_internal/vc-app-menu-item/_internal/vc-app-menu-link.vue +1 -3
  217. package/ui/components/organisms/vc-app/vc-app.backupsb.ts +214 -214
  218. package/ui/components/organisms/vc-app/vc-app.vue +3 -5
  219. package/ui/components/organisms/vc-blade/_internal/vc-blade-header/vc-blade-header.vue +3 -10
  220. package/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/mobile/vc-blade-toolbar-mobile.vue +1 -1
  221. package/ui/components/organisms/vc-blade/_internal/vc-blade-widget-container/_internal/vc-widget-container-desktop.vue +2 -2
  222. package/ui/components/organisms/vc-blade/_internal/vc-blade-widget-container/_internal/vc-widget-container-mobile.vue +2 -2
  223. package/ui/components/organisms/vc-blade/vc-blade.vue +4 -5
  224. package/ui/components/organisms/vc-table/_internal/vc-table-filter/vc-table-filter.vue +1 -3
  225. package/ui/components/organisms/vc-table/_internal/vc-table-header/vc-table-header.vue +1 -2
  226. package/ui/components/organisms/vc-table/composables/useTableState.ts +5 -5
  227. package/dist/apl-B2DGVGxc.js +0 -76
  228. package/dist/asciiarmor-2LVJmxlE.js +0 -34
  229. package/dist/asn1-jKiBa2Ya.js +0 -95
  230. package/dist/asterisk-DS281yxp.js +0 -271
  231. package/dist/brainfuck-C_p9pTT8.js +0 -34
  232. package/dist/clike-DGTaUp48.js +0 -620
  233. package/dist/clojure-CCKyeQKf.js +0 -800
  234. package/dist/cmake-CuaCgAKt.js +0 -28
  235. package/dist/cobol-BlTKFDRj.js +0 -72
  236. package/dist/coffeescript-BVCvwO8I.js +0 -179
  237. package/dist/commonlisp-D_kxz07b.js +0 -75
  238. package/dist/crystal-D309uH6_.js +0 -217
  239. package/dist/css-BkF-NPzE.js +0 -1553
  240. package/dist/cypher-BMq4Fwjl.js +0 -68
  241. package/dist/d-BZcgY6La.js +0 -127
  242. package/dist/diff-Cg9d_RX2.js +0 -18
  243. package/dist/dockerfile-DIy8NleC.js +0 -194
  244. package/dist/dtd-CtLokQ-U.js +0 -84
  245. package/dist/dylan-QYeExnWK.js +0 -234
  246. package/dist/ebnf-DUPDuY4r.js +0 -78
  247. package/dist/ecl-CiXN-g_D.js +0 -121
  248. package/dist/eiffel-yQhjl4T1.js +0 -110
  249. package/dist/elm-CNT9vbN0.js +0 -108
  250. package/dist/erlang-CFOYdy9e.js +0 -487
  251. package/dist/factor-DDOC7X6P.js +0 -65
  252. package/dist/fcl-CPC2WYrI.js +0 -103
  253. package/dist/forth-BmxRyE9S.js +0 -60
  254. package/dist/fortran-9bvPyrOW.js +0 -442
  255. package/dist/gas-cpmYfFX2.js +0 -183
  256. package/dist/gherkin-CJuwpceU.js +0 -34
  257. package/dist/groovy-DZeT_VM-.js +0 -146
  258. package/dist/haskell-Bvt3Qq1t.js +0 -375
  259. package/dist/haxe-70NVW1pR.js +0 -359
  260. package/dist/http-D9LttvKF.js +0 -44
  261. package/dist/idl-B6TRFYjl.js +0 -947
  262. package/dist/index-4DWvmoYg.js +0 -71
  263. package/dist/index-52o7mJaX.js +0 -156
  264. package/dist/index-B0KatioT.js +0 -98
  265. package/dist/index-BP3W8zuk.js +0 -268
  266. package/dist/index-BykT5L1A.js +0 -148134
  267. package/dist/index-CfXo9hsG.js +0 -75
  268. package/dist/index-Ch37pBUt.js +0 -308
  269. package/dist/index-D2KGkAYT.js +0 -93
  270. package/dist/index-D83zQom_.js +0 -58
  271. package/dist/index-DuQrVLbu.js +0 -134
  272. package/dist/index-_fdMid5h.js +0 -288
  273. package/dist/index-a1wO-owY.js +0 -545
  274. package/dist/index-crMpNSFe.js +0 -611
  275. package/dist/index-dmBRpHHY.js +0 -137
  276. package/dist/index-kBdB14Fz.js +0 -341
  277. package/dist/index-uBhy41le.js +0 -249
  278. package/dist/index-zZrijNsr.js +0 -299
  279. package/dist/javascript-C2yteZeJ.js +0 -691
  280. package/dist/jinja2-DnB6dQmV.js +0 -154
  281. package/dist/julia-DpvXAuO6.js +0 -241
  282. package/dist/livescript-CanGTf8u.js +0 -272
  283. package/dist/lua-XplVlWi_.js +0 -217
  284. package/dist/mathematica-jaRHnSxC.js +0 -35
  285. package/dist/mbox-BctzC1hL.js +0 -76
  286. package/dist/mirc-CFBPAOaF.js +0 -72
  287. package/dist/mllike-BSnXJBGA.js +0 -272
  288. package/dist/modelica-vUgVs--1.js +0 -93
  289. package/dist/mscgen-Cpl0NYLN.js +0 -104
  290. package/dist/mumps-CQoS1kWX.js +0 -25
  291. package/dist/nginx-zDPm3Z74.js +0 -89
  292. package/dist/nsis-fePjrhq7.js +0 -62
  293. package/dist/ntriples-CsNjv2QF.js +0 -79
  294. package/dist/octave-C8PmmSRH.js +0 -143
  295. package/dist/oz-Ce8aN8oE.js +0 -151
  296. package/dist/pascal-De0D6mP7.js +0 -77
  297. package/dist/perl-B4bSCe1C.js +0 -915
  298. package/dist/pig-D24Z8EXi.js +0 -54
  299. package/dist/powershell-DkYVfTzP.js +0 -249
  300. package/dist/properties-Dn9wna3M.js +0 -26
  301. package/dist/protobuf-BPIjwpzm.js +0 -49
  302. package/dist/pug-CwAQJzGR.js +0 -248
  303. package/dist/puppet-nyd4dhjf.js +0 -45
  304. package/dist/python-BkR3uSy8.js +0 -313
  305. package/dist/q-DXjKs-tC.js +0 -83
  306. package/dist/r-LKEuhEGI.js +0 -104
  307. package/dist/rpm-IznJm2Xc.js +0 -57
  308. package/dist/ruby-CcYfvIk6.js +0 -228
  309. package/dist/sas-7E8yHoCW.js +0 -105
  310. package/dist/scheme-DjibxsNh.js +0 -124
  311. package/dist/shared/modules/dynamic/components/fields/storybook/common/args.d.ts +0 -113
  312. package/dist/shared/modules/dynamic/components/fields/storybook/common/args.d.ts.map +0 -1
  313. package/dist/shared/modules/dynamic/components/fields/storybook/common/templates.d.ts +0 -3
  314. package/dist/shared/modules/dynamic/components/fields/storybook/common/templates.d.ts.map +0 -1
  315. package/dist/shared/modules/dynamic/components/fields/storybook/pages/DynamicRender.d.ts +0 -102
  316. package/dist/shared/modules/dynamic/components/fields/storybook/pages/DynamicRender.d.ts.map +0 -1
  317. package/dist/shared/modules/dynamic/components/fields/storybook/utils/sourceHighlighter.d.ts +0 -4
  318. package/dist/shared/modules/dynamic/components/fields/storybook/utils/sourceHighlighter.d.ts.map +0 -1
  319. package/dist/shared/modules/dynamic/components/fields/storybook/utils/sourceTransform.d.ts +0 -3
  320. package/dist/shared/modules/dynamic/components/fields/storybook/utils/sourceTransform.d.ts.map +0 -1
  321. package/dist/shell-C0C2sNA_.js +0 -182
  322. package/dist/sieve-Bwz7vjP5.js +0 -72
  323. package/dist/simple-mode-B0dvCdAA.js +0 -89
  324. package/dist/smalltalk-Bhddl2pB.js +0 -48
  325. package/dist/solr-BNlsLglM.js +0 -41
  326. package/dist/sparql-FarWu_Gb.js +0 -197
  327. package/dist/spreadsheet-C-cy4P5N.js +0 -49
  328. package/dist/sql-CfG5lQ3l.js +0 -282
  329. package/dist/stex-Du4h4KAU.js +0 -129
  330. package/dist/stylus-CAdqWld3.js +0 -250
  331. package/dist/swift-DSxqR9R6.js +0 -230
  332. package/dist/tcl-xfoLljhY.js +0 -81
  333. package/dist/textile-D1AWE-pc.js +0 -295
  334. package/dist/tiddlywiki-5wqsXtSk.js +0 -155
  335. package/dist/tiki-__Kn3CeS.js +0 -181
  336. package/dist/toml-BHiuTcfn.js +0 -49
  337. package/dist/troff-D2UO-fKf.js +0 -35
  338. package/dist/ttcn-Bsa4sfRm.js +0 -123
  339. package/dist/ttcn-cfg-Bac_acMi.js +0 -88
  340. package/dist/turtle-xwJUxoPV.js +0 -80
  341. package/dist/ui/components/atoms/vc-icon/icons/AppWindowIcon.vue.d.ts +0 -7
  342. package/dist/ui/components/atoms/vc-icon/icons/AppWindowIcon.vue.d.ts.map +0 -1
  343. package/dist/ui/components/atoms/vc-icon/icons/ArrowLeftIcon.vue.d.ts +0 -7
  344. package/dist/ui/components/atoms/vc-icon/icons/ArrowLeftIcon.vue.d.ts.map +0 -1
  345. package/dist/ui/components/atoms/vc-icon/icons/ArrowRightIcon.vue.d.ts +0 -7
  346. package/dist/ui/components/atoms/vc-icon/icons/ArrowRightIcon.vue.d.ts.map +0 -1
  347. package/dist/ui/components/atoms/vc-icon/icons/BellIcon.vue.d.ts +0 -7
  348. package/dist/ui/components/atoms/vc-icon/icons/BellIcon.vue.d.ts.map +0 -1
  349. package/dist/ui/components/atoms/vc-icon/icons/ChevronDownIcon.vue.d.ts +0 -7
  350. package/dist/ui/components/atoms/vc-icon/icons/ChevronDownIcon.vue.d.ts.map +0 -1
  351. package/dist/ui/components/atoms/vc-icon/icons/ChevronLeftIcon.vue.d.ts +0 -7
  352. package/dist/ui/components/atoms/vc-icon/icons/ChevronLeftIcon.vue.d.ts.map +0 -1
  353. package/dist/ui/components/atoms/vc-icon/icons/ChevronRightIcon.vue.d.ts +0 -7
  354. package/dist/ui/components/atoms/vc-icon/icons/ChevronRightIcon.vue.d.ts.map +0 -1
  355. package/dist/ui/components/atoms/vc-icon/icons/ChevronUpIcon.vue.d.ts +0 -7
  356. package/dist/ui/components/atoms/vc-icon/icons/ChevronUpIcon.vue.d.ts.map +0 -1
  357. package/dist/ui/components/atoms/vc-icon/icons/CircleDotsIcon.vue.d.ts +0 -7
  358. package/dist/ui/components/atoms/vc-icon/icons/CircleDotsIcon.vue.d.ts.map +0 -1
  359. package/dist/ui/components/atoms/vc-icon/icons/CrossSignIcon.vue.d.ts +0 -7
  360. package/dist/ui/components/atoms/vc-icon/icons/CrossSignIcon.vue.d.ts.map +0 -1
  361. package/dist/ui/components/atoms/vc-icon/icons/DoubleArrowLeftIcon.vue.d.ts +0 -7
  362. package/dist/ui/components/atoms/vc-icon/icons/DoubleArrowLeftIcon.vue.d.ts.map +0 -1
  363. package/dist/ui/components/atoms/vc-icon/icons/DoubleArrowRightIcon.vue.d.ts +0 -7
  364. package/dist/ui/components/atoms/vc-icon/icons/DoubleArrowRightIcon.vue.d.ts.map +0 -1
  365. package/dist/ui/components/atoms/vc-icon/icons/FulfillmentCentersIcon.vue.d.ts +0 -7
  366. package/dist/ui/components/atoms/vc-icon/icons/FulfillmentCentersIcon.vue.d.ts.map +0 -1
  367. package/dist/ui/components/atoms/vc-icon/icons/GridDotsIcon.vue.d.ts +0 -7
  368. package/dist/ui/components/atoms/vc-icon/icons/GridDotsIcon.vue.d.ts.map +0 -1
  369. package/dist/ui/components/atoms/vc-icon/icons/LogoutIcon.vue.d.ts +0 -7
  370. package/dist/ui/components/atoms/vc-icon/icons/LogoutIcon.vue.d.ts.map +0 -1
  371. package/dist/ui/components/atoms/vc-icon/icons/MinusSignIcon.vue.d.ts +0 -7
  372. package/dist/ui/components/atoms/vc-icon/icons/MinusSignIcon.vue.d.ts.map +0 -1
  373. package/dist/ui/components/atoms/vc-icon/icons/OffersIcon.vue.d.ts +0 -7
  374. package/dist/ui/components/atoms/vc-icon/icons/OffersIcon.vue.d.ts.map +0 -1
  375. package/dist/ui/components/atoms/vc-icon/icons/OrdersIcon.vue.d.ts +0 -7
  376. package/dist/ui/components/atoms/vc-icon/icons/OrdersIcon.vue.d.ts.map +0 -1
  377. package/dist/ui/components/atoms/vc-icon/icons/PeopleIcon.vue.d.ts +0 -7
  378. package/dist/ui/components/atoms/vc-icon/icons/PeopleIcon.vue.d.ts.map +0 -1
  379. package/dist/ui/components/atoms/vc-icon/icons/PlusSignIcon.vue.d.ts +0 -7
  380. package/dist/ui/components/atoms/vc-icon/icons/PlusSignIcon.vue.d.ts.map +0 -1
  381. package/dist/ui/components/atoms/vc-icon/icons/ProductsIcon.vue.d.ts +0 -7
  382. package/dist/ui/components/atoms/vc-icon/icons/ProductsIcon.vue.d.ts.map +0 -1
  383. package/dist/ui/components/atoms/vc-icon/icons/ProfileIcon.vue.d.ts +0 -7
  384. package/dist/ui/components/atoms/vc-icon/icons/ProfileIcon.vue.d.ts.map +0 -1
  385. package/dist/ui/components/atoms/vc-icon/icons/SearchIcon.vue.d.ts +0 -7
  386. package/dist/ui/components/atoms/vc-icon/icons/SearchIcon.vue.d.ts.map +0 -1
  387. package/dist/ui/components/atoms/vc-icon/icons/SettingsBoltIcon.vue.d.ts +0 -7
  388. package/dist/ui/components/atoms/vc-icon/icons/SettingsBoltIcon.vue.d.ts.map +0 -1
  389. package/dist/ui/components/atoms/vc-icon/icons/ShoppingCardIcon.vue.d.ts +0 -7
  390. package/dist/ui/components/atoms/vc-icon/icons/ShoppingCardIcon.vue.d.ts.map +0 -1
  391. package/dist/ui/components/atoms/vc-icon/icons/VendorSwitchIcon.vue.d.ts +0 -7
  392. package/dist/ui/components/atoms/vc-icon/icons/VendorSwitchIcon.vue.d.ts.map +0 -1
  393. package/dist/ui/components/atoms/vc-icon/icons/VertDotsIcon.vue.d.ts +0 -7
  394. package/dist/ui/components/atoms/vc-icon/icons/VertDotsIcon.vue.d.ts.map +0 -1
  395. package/dist/vb-c2kQGd6-.js +0 -74
  396. package/dist/vbscript-1f_Dhg5H.js +0 -324
  397. package/dist/velocity-DJd0pTTC.js +0 -96
  398. package/dist/verilog-CiS1jyi5.js +0 -262
  399. package/dist/vhdl-T9HkrbI2.js +0 -106
  400. package/dist/webidl-CjfDENEo.js +0 -155
  401. package/dist/xquery-BUQdORAS.js +0 -422
  402. package/dist/yacas-C0absKBh.js +0 -73
  403. package/dist/z80-Pki2zAjW.js +0 -61
  404. package/shared/modules/dynamic/components/fields/storybook/Button.stories.ts +0 -186
  405. package/shared/modules/dynamic/components/fields/storybook/Card.stories.ts +0 -175
  406. package/shared/modules/dynamic/components/fields/storybook/Checkbox.stories.ts +0 -185
  407. package/shared/modules/dynamic/components/fields/storybook/ContentField.stories.ts +0 -245
  408. package/shared/modules/dynamic/components/fields/storybook/EditorField.stories.ts +0 -192
  409. package/shared/modules/dynamic/components/fields/storybook/Fieldset.stories.ts +0 -347
  410. package/shared/modules/dynamic/components/fields/storybook/GalleryField.stories.ts +0 -239
  411. package/shared/modules/dynamic/components/fields/storybook/ImageField.stories.ts +0 -186
  412. package/shared/modules/dynamic/components/fields/storybook/InputCurrency.stories.ts +0 -281
  413. package/shared/modules/dynamic/components/fields/storybook/InputField.stories.ts +0 -312
  414. package/shared/modules/dynamic/components/fields/storybook/MultivalueField.stories.ts +0 -361
  415. package/shared/modules/dynamic/components/fields/storybook/RadioButtonGroup.stories.ts +0 -224
  416. package/shared/modules/dynamic/components/fields/storybook/RatingField.stories.ts +0 -131
  417. package/shared/modules/dynamic/components/fields/storybook/SelectField.stories.ts +0 -666
  418. package/shared/modules/dynamic/components/fields/storybook/StatusField.stories.ts +0 -202
  419. package/shared/modules/dynamic/components/fields/storybook/SwitchField.stories.ts +0 -178
  420. package/shared/modules/dynamic/components/fields/storybook/TextareaField.stories.ts +0 -203
  421. package/shared/modules/dynamic/components/fields/storybook/VideoField.stories.ts +0 -92
  422. package/shared/modules/dynamic/components/fields/storybook/common/args.ts +0 -130
  423. package/shared/modules/dynamic/components/fields/storybook/common/templates.ts +0 -8
  424. package/shared/modules/dynamic/components/fields/storybook/pages/DynamicRender.ts +0 -54
  425. package/shared/modules/dynamic/components/fields/storybook/utils/sourceHighlighter.ts +0 -16
  426. package/shared/modules/dynamic/components/fields/storybook/utils/sourceTransform.ts +0 -41
  427. package/ui/components/atoms/vc-icon/icons/AppWindowIcon.vue +0 -15
  428. package/ui/components/atoms/vc-icon/icons/ArrowLeftIcon.vue +0 -20
  429. package/ui/components/atoms/vc-icon/icons/ArrowRightIcon.vue +0 -13
  430. package/ui/components/atoms/vc-icon/icons/BellIcon.vue +0 -14
  431. package/ui/components/atoms/vc-icon/icons/ChevronDownIcon.vue +0 -13
  432. package/ui/components/atoms/vc-icon/icons/ChevronLeftIcon.vue +0 -13
  433. package/ui/components/atoms/vc-icon/icons/ChevronRightIcon.vue +0 -13
  434. package/ui/components/atoms/vc-icon/icons/ChevronUpIcon.vue +0 -13
  435. package/ui/components/atoms/vc-icon/icons/CircleDotsIcon.vue +0 -16
  436. package/ui/components/atoms/vc-icon/icons/CrossSignIcon.vue +0 -20
  437. package/ui/components/atoms/vc-icon/icons/DoubleArrowLeftIcon.vue +0 -14
  438. package/ui/components/atoms/vc-icon/icons/DoubleArrowRightIcon.vue +0 -14
  439. package/ui/components/atoms/vc-icon/icons/FulfillmentCentersIcon.vue +0 -27
  440. package/ui/components/atoms/vc-icon/icons/GridDotsIcon.vue +0 -22
  441. package/ui/components/atoms/vc-icon/icons/LogoutIcon.vue +0 -13
  442. package/ui/components/atoms/vc-icon/icons/MinusSignIcon.vue +0 -14
  443. package/ui/components/atoms/vc-icon/icons/OffersIcon.vue +0 -23
  444. package/ui/components/atoms/vc-icon/icons/OrdersIcon.vue +0 -19
  445. package/ui/components/atoms/vc-icon/icons/PeopleIcon.vue +0 -21
  446. package/ui/components/atoms/vc-icon/icons/PlusSignIcon.vue +0 -20
  447. package/ui/components/atoms/vc-icon/icons/ProductsIcon.vue +0 -23
  448. package/ui/components/atoms/vc-icon/icons/ProfileIcon.vue +0 -18
  449. package/ui/components/atoms/vc-icon/icons/SearchIcon.vue +0 -14
  450. package/ui/components/atoms/vc-icon/icons/SettingsBoltIcon.vue +0 -21
  451. package/ui/components/atoms/vc-icon/icons/ShoppingCardIcon.vue +0 -16
  452. package/ui/components/atoms/vc-icon/icons/VendorSwitchIcon.vue +0 -26
  453. package/ui/components/atoms/vc-icon/icons/VertDotsIcon.vue +0 -19
@@ -0,0 +1,2159 @@
1
+ import { P as Plugin, a as PluginKey, S as Selection, b as SelectionRange, T as TextSelection, N as NodeSelection } from './vendor-prosemirror-state-BvL9Pxph.js';
2
+ import { F as Fragment, S as Slice } from './vendor-prosemirror-model-BZu3WVcD.js';
3
+ import { D as DecorationSet, a as Decoration } from './vendor-prosemirror-view-CU2WTHT7.js';
4
+ import { k as keydownHandler } from './vendor-prosemirror-keymap-BbWvIWmH.js';
5
+ import { T as Transform } from './vendor-prosemirror-transform-CE9VV3qg.js';
6
+
7
+ // src/index.ts
8
+
9
+ // src/tablemap.ts
10
+ var readFromCache;
11
+ var addToCache;
12
+ if (typeof WeakMap != "undefined") {
13
+ let cache = /* @__PURE__ */ new WeakMap();
14
+ readFromCache = (key) => cache.get(key);
15
+ addToCache = (key, value) => {
16
+ cache.set(key, value);
17
+ return value;
18
+ };
19
+ } else {
20
+ const cache = [];
21
+ const cacheSize = 10;
22
+ let cachePos = 0;
23
+ readFromCache = (key) => {
24
+ for (let i = 0; i < cache.length; i += 2)
25
+ if (cache[i] == key) return cache[i + 1];
26
+ };
27
+ addToCache = (key, value) => {
28
+ if (cachePos == cacheSize) cachePos = 0;
29
+ cache[cachePos++] = key;
30
+ return cache[cachePos++] = value;
31
+ };
32
+ }
33
+ var TableMap = class {
34
+ constructor(width, height, map, problems) {
35
+ this.width = width;
36
+ this.height = height;
37
+ this.map = map;
38
+ this.problems = problems;
39
+ }
40
+ // Find the dimensions of the cell at the given position.
41
+ findCell(pos) {
42
+ for (let i = 0; i < this.map.length; i++) {
43
+ const curPos = this.map[i];
44
+ if (curPos != pos) continue;
45
+ const left = i % this.width;
46
+ const top = i / this.width | 0;
47
+ let right = left + 1;
48
+ let bottom = top + 1;
49
+ for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) {
50
+ right++;
51
+ }
52
+ for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) {
53
+ bottom++;
54
+ }
55
+ return { left, top, right, bottom };
56
+ }
57
+ throw new RangeError(`No cell with offset ${pos} found`);
58
+ }
59
+ // Find the left side of the cell at the given position.
60
+ colCount(pos) {
61
+ for (let i = 0; i < this.map.length; i++) {
62
+ if (this.map[i] == pos) {
63
+ return i % this.width;
64
+ }
65
+ }
66
+ throw new RangeError(`No cell with offset ${pos} found`);
67
+ }
68
+ // Find the next cell in the given direction, starting from the cell
69
+ // at `pos`, if any.
70
+ nextCell(pos, axis, dir) {
71
+ const { left, right, top, bottom } = this.findCell(pos);
72
+ if (axis == "horiz") {
73
+ if (dir < 0 ? left == 0 : right == this.width) return null;
74
+ return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
75
+ } else {
76
+ if (dir < 0 ? top == 0 : bottom == this.height) return null;
77
+ return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
78
+ }
79
+ }
80
+ // Get the rectangle spanning the two given cells.
81
+ rectBetween(a, b) {
82
+ const {
83
+ left: leftA,
84
+ right: rightA,
85
+ top: topA,
86
+ bottom: bottomA
87
+ } = this.findCell(a);
88
+ const {
89
+ left: leftB,
90
+ right: rightB,
91
+ top: topB,
92
+ bottom: bottomB
93
+ } = this.findCell(b);
94
+ return {
95
+ left: Math.min(leftA, leftB),
96
+ top: Math.min(topA, topB),
97
+ right: Math.max(rightA, rightB),
98
+ bottom: Math.max(bottomA, bottomB)
99
+ };
100
+ }
101
+ // Return the position of all cells that have the top left corner in
102
+ // the given rectangle.
103
+ cellsInRect(rect) {
104
+ const result = [];
105
+ const seen = {};
106
+ for (let row = rect.top; row < rect.bottom; row++) {
107
+ for (let col = rect.left; col < rect.right; col++) {
108
+ const index = row * this.width + col;
109
+ const pos = this.map[index];
110
+ if (seen[pos]) continue;
111
+ seen[pos] = true;
112
+ if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) {
113
+ continue;
114
+ }
115
+ result.push(pos);
116
+ }
117
+ }
118
+ return result;
119
+ }
120
+ // Return the position at which the cell at the given row and column
121
+ // starts, or would start, if a cell started there.
122
+ positionAt(row, col, table) {
123
+ for (let i = 0, rowStart = 0; ; i++) {
124
+ const rowEnd = rowStart + table.child(i).nodeSize;
125
+ if (i == row) {
126
+ let index = col + row * this.width;
127
+ const rowEndIndex = (row + 1) * this.width;
128
+ while (index < rowEndIndex && this.map[index] < rowStart) index++;
129
+ return index == rowEndIndex ? rowEnd - 1 : this.map[index];
130
+ }
131
+ rowStart = rowEnd;
132
+ }
133
+ }
134
+ // Find the table map for the given table node.
135
+ static get(table) {
136
+ return readFromCache(table) || addToCache(table, computeMap(table));
137
+ }
138
+ };
139
+ function computeMap(table) {
140
+ if (table.type.spec.tableRole != "table")
141
+ throw new RangeError("Not a table node: " + table.type.name);
142
+ const width = findWidth(table), height = table.childCount;
143
+ const map = [];
144
+ let mapPos = 0;
145
+ let problems = null;
146
+ const colWidths = [];
147
+ for (let i = 0, e = width * height; i < e; i++) map[i] = 0;
148
+ for (let row = 0, pos = 0; row < height; row++) {
149
+ const rowNode = table.child(row);
150
+ pos++;
151
+ for (let i = 0; ; i++) {
152
+ while (mapPos < map.length && map[mapPos] != 0) mapPos++;
153
+ if (i == rowNode.childCount) break;
154
+ const cellNode = rowNode.child(i);
155
+ const { colspan, rowspan, colwidth } = cellNode.attrs;
156
+ for (let h = 0; h < rowspan; h++) {
157
+ if (h + row >= height) {
158
+ (problems || (problems = [])).push({
159
+ type: "overlong_rowspan",
160
+ pos,
161
+ n: rowspan - h
162
+ });
163
+ break;
164
+ }
165
+ const start = mapPos + h * width;
166
+ for (let w = 0; w < colspan; w++) {
167
+ if (map[start + w] == 0) map[start + w] = pos;
168
+ else
169
+ (problems || (problems = [])).push({
170
+ type: "collision",
171
+ row,
172
+ pos,
173
+ n: colspan - w
174
+ });
175
+ const colW = colwidth && colwidth[w];
176
+ if (colW) {
177
+ const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];
178
+ if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
179
+ colWidths[widthIndex] = colW;
180
+ colWidths[widthIndex + 1] = 1;
181
+ } else if (prev == colW) {
182
+ colWidths[widthIndex + 1]++;
183
+ }
184
+ }
185
+ }
186
+ }
187
+ mapPos += colspan;
188
+ pos += cellNode.nodeSize;
189
+ }
190
+ const expectedPos = (row + 1) * width;
191
+ let missing = 0;
192
+ while (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;
193
+ if (missing)
194
+ (problems || (problems = [])).push({ type: "missing", row, n: missing });
195
+ pos++;
196
+ }
197
+ if (width === 0 || height === 0)
198
+ (problems || (problems = [])).push({ type: "zero_sized" });
199
+ const tableMap = new TableMap(width, height, map, problems);
200
+ let badWidths = false;
201
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2)
202
+ if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
203
+ if (badWidths) findBadColWidths(tableMap, colWidths, table);
204
+ return tableMap;
205
+ }
206
+ function findWidth(table) {
207
+ let width = -1;
208
+ let hasRowSpan = false;
209
+ for (let row = 0; row < table.childCount; row++) {
210
+ const rowNode = table.child(row);
211
+ let rowWidth = 0;
212
+ if (hasRowSpan)
213
+ for (let j = 0; j < row; j++) {
214
+ const prevRow = table.child(j);
215
+ for (let i = 0; i < prevRow.childCount; i++) {
216
+ const cell = prevRow.child(i);
217
+ if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
218
+ }
219
+ }
220
+ for (let i = 0; i < rowNode.childCount; i++) {
221
+ const cell = rowNode.child(i);
222
+ rowWidth += cell.attrs.colspan;
223
+ if (cell.attrs.rowspan > 1) hasRowSpan = true;
224
+ }
225
+ if (width == -1) width = rowWidth;
226
+ else if (width != rowWidth) width = Math.max(width, rowWidth);
227
+ }
228
+ return width;
229
+ }
230
+ function findBadColWidths(map, colWidths, table) {
231
+ if (!map.problems) map.problems = [];
232
+ const seen = {};
233
+ for (let i = 0; i < map.map.length; i++) {
234
+ const pos = map.map[i];
235
+ if (seen[pos]) continue;
236
+ seen[pos] = true;
237
+ const node = table.nodeAt(pos);
238
+ if (!node) {
239
+ throw new RangeError(`No cell with offset ${pos} found`);
240
+ }
241
+ let updated = null;
242
+ const attrs = node.attrs;
243
+ for (let j = 0; j < attrs.colspan; j++) {
244
+ const col = (i + j) % map.width;
245
+ const colWidth = colWidths[col * 2];
246
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))
247
+ (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
248
+ }
249
+ if (updated)
250
+ map.problems.unshift({
251
+ type: "colwidth mismatch",
252
+ pos,
253
+ colwidth: updated
254
+ });
255
+ }
256
+ }
257
+ function freshColWidth(attrs) {
258
+ if (attrs.colwidth) return attrs.colwidth.slice();
259
+ const result = [];
260
+ for (let i = 0; i < attrs.colspan; i++) result.push(0);
261
+ return result;
262
+ }
263
+ function tableNodeTypes(schema) {
264
+ let result = schema.cached.tableNodeTypes;
265
+ if (!result) {
266
+ result = schema.cached.tableNodeTypes = {};
267
+ for (const name in schema.nodes) {
268
+ const type = schema.nodes[name], role = type.spec.tableRole;
269
+ if (role) result[role] = type;
270
+ }
271
+ }
272
+ return result;
273
+ }
274
+
275
+ // src/util.ts
276
+ var tableEditingKey = new PluginKey("selectingCells");
277
+ function cellAround($pos) {
278
+ for (let d = $pos.depth - 1; d > 0; d--)
279
+ if ($pos.node(d).type.spec.tableRole == "row")
280
+ return $pos.node(0).resolve($pos.before(d + 1));
281
+ return null;
282
+ }
283
+ function cellWrapping($pos) {
284
+ for (let d = $pos.depth; d > 0; d--) {
285
+ const role = $pos.node(d).type.spec.tableRole;
286
+ if (role === "cell" || role === "header_cell") return $pos.node(d);
287
+ }
288
+ return null;
289
+ }
290
+ function isInTable(state) {
291
+ const $head = state.selection.$head;
292
+ for (let d = $head.depth; d > 0; d--)
293
+ if ($head.node(d).type.spec.tableRole == "row") return true;
294
+ return false;
295
+ }
296
+ function selectionCell(state) {
297
+ const sel = state.selection;
298
+ if ("$anchorCell" in sel && sel.$anchorCell) {
299
+ return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
300
+ } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
301
+ return sel.$anchor;
302
+ }
303
+ const $cell = cellAround(sel.$head) || cellNear(sel.$head);
304
+ if ($cell) {
305
+ return $cell;
306
+ }
307
+ throw new RangeError(`No cell found around position ${sel.head}`);
308
+ }
309
+ function cellNear($pos) {
310
+ for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
311
+ const role = after.type.spec.tableRole;
312
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos);
313
+ }
314
+ for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
315
+ const role = before.type.spec.tableRole;
316
+ if (role == "cell" || role == "header_cell")
317
+ return $pos.doc.resolve(pos - before.nodeSize);
318
+ }
319
+ }
320
+ function pointsAtCell($pos) {
321
+ return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
322
+ }
323
+ function moveCellForward($pos) {
324
+ return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize);
325
+ }
326
+ function inSameTable($cellA, $cellB) {
327
+ return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
328
+ }
329
+ function nextCell($pos, axis, dir) {
330
+ const table = $pos.node(-1);
331
+ const map = TableMap.get(table);
332
+ const tableStart = $pos.start(-1);
333
+ const moved = map.nextCell($pos.pos - tableStart, axis, dir);
334
+ return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
335
+ }
336
+ function removeColSpan(attrs, pos, n = 1) {
337
+ const result = { ...attrs, colspan: attrs.colspan - n };
338
+ if (result.colwidth) {
339
+ result.colwidth = result.colwidth.slice();
340
+ result.colwidth.splice(pos, n);
341
+ if (!result.colwidth.some((w) => w > 0)) result.colwidth = null;
342
+ }
343
+ return result;
344
+ }
345
+ function addColSpan(attrs, pos, n = 1) {
346
+ const result = { ...attrs, colspan: attrs.colspan + n };
347
+ if (result.colwidth) {
348
+ result.colwidth = result.colwidth.slice();
349
+ for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);
350
+ }
351
+ return result;
352
+ }
353
+ function columnIsHeader(map, table, col) {
354
+ const headerCell = tableNodeTypes(table.type.schema).header_cell;
355
+ for (let row = 0; row < map.height; row++)
356
+ if (table.nodeAt(map.map[col + row * map.width]).type != headerCell)
357
+ return false;
358
+ return true;
359
+ }
360
+
361
+ // src/cellselection.ts
362
+ var CellSelection = class _CellSelection extends Selection {
363
+ // A table selection is identified by its anchor and head cells. The
364
+ // positions given to this constructor should point _before_ two
365
+ // cells in the same table. They may be the same, to select a single
366
+ // cell.
367
+ constructor($anchorCell, $headCell = $anchorCell) {
368
+ const table = $anchorCell.node(-1);
369
+ const map = TableMap.get(table);
370
+ const tableStart = $anchorCell.start(-1);
371
+ const rect = map.rectBetween(
372
+ $anchorCell.pos - tableStart,
373
+ $headCell.pos - tableStart
374
+ );
375
+ const doc = $anchorCell.node(0);
376
+ const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
377
+ cells.unshift($headCell.pos - tableStart);
378
+ const ranges = cells.map((pos) => {
379
+ const cell = table.nodeAt(pos);
380
+ if (!cell) {
381
+ throw RangeError(`No cell with offset ${pos} found`);
382
+ }
383
+ const from = tableStart + pos + 1;
384
+ return new SelectionRange(
385
+ doc.resolve(from),
386
+ doc.resolve(from + cell.content.size)
387
+ );
388
+ });
389
+ super(ranges[0].$from, ranges[0].$to, ranges);
390
+ this.$anchorCell = $anchorCell;
391
+ this.$headCell = $headCell;
392
+ }
393
+ map(doc, mapping) {
394
+ const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
395
+ const $headCell = doc.resolve(mapping.map(this.$headCell.pos));
396
+ if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
397
+ const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
398
+ if (tableChanged && this.isRowSelection())
399
+ return _CellSelection.rowSelection($anchorCell, $headCell);
400
+ else if (tableChanged && this.isColSelection())
401
+ return _CellSelection.colSelection($anchorCell, $headCell);
402
+ else return new _CellSelection($anchorCell, $headCell);
403
+ }
404
+ return TextSelection.between($anchorCell, $headCell);
405
+ }
406
+ // Returns a rectangular slice of table rows containing the selected
407
+ // cells.
408
+ content() {
409
+ const table = this.$anchorCell.node(-1);
410
+ const map = TableMap.get(table);
411
+ const tableStart = this.$anchorCell.start(-1);
412
+ const rect = map.rectBetween(
413
+ this.$anchorCell.pos - tableStart,
414
+ this.$headCell.pos - tableStart
415
+ );
416
+ const seen = {};
417
+ const rows = [];
418
+ for (let row = rect.top; row < rect.bottom; row++) {
419
+ const rowContent = [];
420
+ for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
421
+ const pos = map.map[index];
422
+ if (seen[pos]) continue;
423
+ seen[pos] = true;
424
+ const cellRect = map.findCell(pos);
425
+ let cell = table.nodeAt(pos);
426
+ if (!cell) {
427
+ throw RangeError(`No cell with offset ${pos} found`);
428
+ }
429
+ const extraLeft = rect.left - cellRect.left;
430
+ const extraRight = cellRect.right - rect.right;
431
+ if (extraLeft > 0 || extraRight > 0) {
432
+ let attrs = cell.attrs;
433
+ if (extraLeft > 0) {
434
+ attrs = removeColSpan(attrs, 0, extraLeft);
435
+ }
436
+ if (extraRight > 0) {
437
+ attrs = removeColSpan(
438
+ attrs,
439
+ attrs.colspan - extraRight,
440
+ extraRight
441
+ );
442
+ }
443
+ if (cellRect.left < rect.left) {
444
+ cell = cell.type.createAndFill(attrs);
445
+ if (!cell) {
446
+ throw RangeError(
447
+ `Could not create cell with attrs ${JSON.stringify(attrs)}`
448
+ );
449
+ }
450
+ } else {
451
+ cell = cell.type.create(attrs, cell.content);
452
+ }
453
+ }
454
+ if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
455
+ const attrs = {
456
+ ...cell.attrs,
457
+ rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
458
+ };
459
+ if (cellRect.top < rect.top) {
460
+ cell = cell.type.createAndFill(attrs);
461
+ } else {
462
+ cell = cell.type.create(attrs, cell.content);
463
+ }
464
+ }
465
+ rowContent.push(cell);
466
+ }
467
+ rows.push(table.child(row).copy(Fragment.from(rowContent)));
468
+ }
469
+ const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
470
+ return new Slice(Fragment.from(fragment), 1, 1);
471
+ }
472
+ replace(tr, content = Slice.empty) {
473
+ const mapFrom = tr.steps.length, ranges = this.ranges;
474
+ for (let i = 0; i < ranges.length; i++) {
475
+ const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
476
+ tr.replace(
477
+ mapping.map($from.pos),
478
+ mapping.map($to.pos),
479
+ i ? Slice.empty : content
480
+ );
481
+ }
482
+ const sel = Selection.findFrom(
483
+ tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
484
+ -1
485
+ );
486
+ if (sel) tr.setSelection(sel);
487
+ }
488
+ replaceWith(tr, node) {
489
+ this.replace(tr, new Slice(Fragment.from(node), 0, 0));
490
+ }
491
+ forEachCell(f) {
492
+ const table = this.$anchorCell.node(-1);
493
+ const map = TableMap.get(table);
494
+ const tableStart = this.$anchorCell.start(-1);
495
+ const cells = map.cellsInRect(
496
+ map.rectBetween(
497
+ this.$anchorCell.pos - tableStart,
498
+ this.$headCell.pos - tableStart
499
+ )
500
+ );
501
+ for (let i = 0; i < cells.length; i++) {
502
+ f(table.nodeAt(cells[i]), tableStart + cells[i]);
503
+ }
504
+ }
505
+ // True if this selection goes all the way from the top to the
506
+ // bottom of the table.
507
+ isColSelection() {
508
+ const anchorTop = this.$anchorCell.index(-1);
509
+ const headTop = this.$headCell.index(-1);
510
+ if (Math.min(anchorTop, headTop) > 0) return false;
511
+ const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
512
+ const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
513
+ return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
514
+ }
515
+ // Returns the smallest column selection that covers the given anchor
516
+ // and head cell.
517
+ static colSelection($anchorCell, $headCell = $anchorCell) {
518
+ const table = $anchorCell.node(-1);
519
+ const map = TableMap.get(table);
520
+ const tableStart = $anchorCell.start(-1);
521
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
522
+ const headRect = map.findCell($headCell.pos - tableStart);
523
+ const doc = $anchorCell.node(0);
524
+ if (anchorRect.top <= headRect.top) {
525
+ if (anchorRect.top > 0)
526
+ $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);
527
+ if (headRect.bottom < map.height)
528
+ $headCell = doc.resolve(
529
+ tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]
530
+ );
531
+ } else {
532
+ if (headRect.top > 0)
533
+ $headCell = doc.resolve(tableStart + map.map[headRect.left]);
534
+ if (anchorRect.bottom < map.height)
535
+ $anchorCell = doc.resolve(
536
+ tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]
537
+ );
538
+ }
539
+ return new _CellSelection($anchorCell, $headCell);
540
+ }
541
+ // True if this selection goes all the way from the left to the
542
+ // right of the table.
543
+ isRowSelection() {
544
+ const table = this.$anchorCell.node(-1);
545
+ const map = TableMap.get(table);
546
+ const tableStart = this.$anchorCell.start(-1);
547
+ const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);
548
+ const headLeft = map.colCount(this.$headCell.pos - tableStart);
549
+ if (Math.min(anchorLeft, headLeft) > 0) return false;
550
+ const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
551
+ const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
552
+ return Math.max(anchorRight, headRight) == map.width;
553
+ }
554
+ eq(other) {
555
+ return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
556
+ }
557
+ // Returns the smallest row selection that covers the given anchor
558
+ // and head cell.
559
+ static rowSelection($anchorCell, $headCell = $anchorCell) {
560
+ const table = $anchorCell.node(-1);
561
+ const map = TableMap.get(table);
562
+ const tableStart = $anchorCell.start(-1);
563
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
564
+ const headRect = map.findCell($headCell.pos - tableStart);
565
+ const doc = $anchorCell.node(0);
566
+ if (anchorRect.left <= headRect.left) {
567
+ if (anchorRect.left > 0)
568
+ $anchorCell = doc.resolve(
569
+ tableStart + map.map[anchorRect.top * map.width]
570
+ );
571
+ if (headRect.right < map.width)
572
+ $headCell = doc.resolve(
573
+ tableStart + map.map[map.width * (headRect.top + 1) - 1]
574
+ );
575
+ } else {
576
+ if (headRect.left > 0)
577
+ $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);
578
+ if (anchorRect.right < map.width)
579
+ $anchorCell = doc.resolve(
580
+ tableStart + map.map[map.width * (anchorRect.top + 1) - 1]
581
+ );
582
+ }
583
+ return new _CellSelection($anchorCell, $headCell);
584
+ }
585
+ toJSON() {
586
+ return {
587
+ type: "cell",
588
+ anchor: this.$anchorCell.pos,
589
+ head: this.$headCell.pos
590
+ };
591
+ }
592
+ static fromJSON(doc, json) {
593
+ return new _CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
594
+ }
595
+ static create(doc, anchorCell, headCell = anchorCell) {
596
+ return new _CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
597
+ }
598
+ getBookmark() {
599
+ return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
600
+ }
601
+ };
602
+ CellSelection.prototype.visible = false;
603
+ Selection.jsonID("cell", CellSelection);
604
+ var CellBookmark = class _CellBookmark {
605
+ constructor(anchor, head) {
606
+ this.anchor = anchor;
607
+ this.head = head;
608
+ }
609
+ map(mapping) {
610
+ return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
611
+ }
612
+ resolve(doc) {
613
+ const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
614
+ 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))
615
+ return new CellSelection($anchorCell, $headCell);
616
+ else return Selection.near($headCell, 1);
617
+ }
618
+ };
619
+ function drawCellSelection(state) {
620
+ if (!(state.selection instanceof CellSelection)) return null;
621
+ const cells = [];
622
+ state.selection.forEachCell((node, pos) => {
623
+ cells.push(
624
+ Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
625
+ );
626
+ });
627
+ return DecorationSet.create(state.doc, cells);
628
+ }
629
+ function isCellBoundarySelection({ $from, $to }) {
630
+ if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;
631
+ let afterFrom = $from.pos;
632
+ let beforeTo = $to.pos;
633
+ let depth = $from.depth;
634
+ for (; depth >= 0; depth--, afterFrom++)
635
+ if ($from.after(depth + 1) < $from.end(depth)) break;
636
+ for (let d = $to.depth; d >= 0; d--, beforeTo--)
637
+ if ($to.before(d + 1) > $to.start(d)) break;
638
+ return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
639
+ }
640
+ function isTextSelectionAcrossCells({ $from, $to }) {
641
+ let fromCellBoundaryNode;
642
+ let toCellBoundaryNode;
643
+ for (let i = $from.depth; i > 0; i--) {
644
+ const node = $from.node(i);
645
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
646
+ fromCellBoundaryNode = node;
647
+ break;
648
+ }
649
+ }
650
+ for (let i = $to.depth; i > 0; i--) {
651
+ const node = $to.node(i);
652
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
653
+ toCellBoundaryNode = node;
654
+ break;
655
+ }
656
+ }
657
+ return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
658
+ }
659
+ function normalizeSelection(state, tr, allowTableNodeSelection) {
660
+ const sel = (tr || state).selection;
661
+ const doc = (tr || state).doc;
662
+ let normalize;
663
+ let role;
664
+ if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
665
+ if (role == "cell" || role == "header_cell") {
666
+ normalize = CellSelection.create(doc, sel.from);
667
+ } else if (role == "row") {
668
+ const $cell = doc.resolve(sel.from + 1);
669
+ normalize = CellSelection.rowSelection($cell, $cell);
670
+ } else if (!allowTableNodeSelection) {
671
+ const map = TableMap.get(sel.node);
672
+ const start = sel.from + 1;
673
+ const lastCell = start + map.map[map.width * map.height - 1];
674
+ normalize = CellSelection.create(doc, start + 1, lastCell);
675
+ }
676
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
677
+ normalize = TextSelection.create(doc, sel.from);
678
+ } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
679
+ normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
680
+ }
681
+ if (normalize) (tr || (tr = state.tr)).setSelection(normalize);
682
+ return tr;
683
+ }
684
+ var fixTablesKey = new PluginKey("fix-tables");
685
+ function changedDescendants(old, cur, offset, f) {
686
+ const oldSize = old.childCount, curSize = cur.childCount;
687
+ outer: for (let i = 0, j = 0; i < curSize; i++) {
688
+ const child = cur.child(i);
689
+ for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
690
+ if (old.child(scan) == child) {
691
+ j = scan + 1;
692
+ offset += child.nodeSize;
693
+ continue outer;
694
+ }
695
+ }
696
+ f(child, offset);
697
+ if (j < oldSize && old.child(j).sameMarkup(child))
698
+ changedDescendants(old.child(j), child, offset + 1, f);
699
+ else child.nodesBetween(0, child.content.size, f, offset + 1);
700
+ offset += child.nodeSize;
701
+ }
702
+ }
703
+ function fixTables(state, oldState) {
704
+ let tr;
705
+ const check = (node, pos) => {
706
+ if (node.type.spec.tableRole == "table")
707
+ tr = fixTable(state, node, pos, tr);
708
+ };
709
+ if (!oldState) state.doc.descendants(check);
710
+ else if (oldState.doc != state.doc)
711
+ changedDescendants(oldState.doc, state.doc, 0, check);
712
+ return tr;
713
+ }
714
+ function fixTable(state, table, tablePos, tr) {
715
+ const map = TableMap.get(table);
716
+ if (!map.problems) return tr;
717
+ if (!tr) tr = state.tr;
718
+ const mustAdd = [];
719
+ for (let i = 0; i < map.height; i++) mustAdd.push(0);
720
+ for (let i = 0; i < map.problems.length; i++) {
721
+ const prob = map.problems[i];
722
+ if (prob.type == "collision") {
723
+ const cell = table.nodeAt(prob.pos);
724
+ if (!cell) continue;
725
+ const attrs = cell.attrs;
726
+ for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
727
+ tr.setNodeMarkup(
728
+ tr.mapping.map(tablePos + 1 + prob.pos),
729
+ null,
730
+ removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
731
+ );
732
+ } else if (prob.type == "missing") {
733
+ mustAdd[prob.row] += prob.n;
734
+ } else if (prob.type == "overlong_rowspan") {
735
+ const cell = table.nodeAt(prob.pos);
736
+ if (!cell) continue;
737
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
738
+ ...cell.attrs,
739
+ rowspan: cell.attrs.rowspan - prob.n
740
+ });
741
+ } else if (prob.type == "colwidth mismatch") {
742
+ const cell = table.nodeAt(prob.pos);
743
+ if (!cell) continue;
744
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
745
+ ...cell.attrs,
746
+ colwidth: prob.colwidth
747
+ });
748
+ } else if (prob.type == "zero_sized") {
749
+ const pos = tr.mapping.map(tablePos);
750
+ tr.delete(pos, pos + table.nodeSize);
751
+ }
752
+ }
753
+ let first, last;
754
+ for (let i = 0; i < mustAdd.length; i++)
755
+ if (mustAdd[i]) {
756
+ if (first == null) first = i;
757
+ last = i;
758
+ }
759
+ for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
760
+ const row = table.child(i);
761
+ const end = pos + row.nodeSize;
762
+ const add = mustAdd[i];
763
+ if (add > 0) {
764
+ let role = "cell";
765
+ if (row.firstChild) {
766
+ role = row.firstChild.type.spec.tableRole;
767
+ }
768
+ const nodes = [];
769
+ for (let j = 0; j < add; j++) {
770
+ const node = tableNodeTypes(state.schema)[role].createAndFill();
771
+ if (node) nodes.push(node);
772
+ }
773
+ const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
774
+ tr.insert(tr.mapping.map(side), nodes);
775
+ }
776
+ pos = end;
777
+ }
778
+ return tr.setMeta(fixTablesKey, { fixTables: true });
779
+ }
780
+ function selectedRect(state) {
781
+ const sel = state.selection;
782
+ const $pos = selectionCell(state);
783
+ const table = $pos.node(-1);
784
+ const tableStart = $pos.start(-1);
785
+ const map = TableMap.get(table);
786
+ const rect = sel instanceof CellSelection ? map.rectBetween(
787
+ sel.$anchorCell.pos - tableStart,
788
+ sel.$headCell.pos - tableStart
789
+ ) : map.findCell($pos.pos - tableStart);
790
+ return { ...rect, tableStart, map, table };
791
+ }
792
+ function addColumn(tr, { map, tableStart, table }, col) {
793
+ let refColumn = col > 0 ? -1 : 0;
794
+ if (columnIsHeader(map, table, col + refColumn)) {
795
+ refColumn = col == 0 || col == map.width ? null : 0;
796
+ }
797
+ for (let row = 0; row < map.height; row++) {
798
+ const index = row * map.width + col;
799
+ if (col > 0 && col < map.width && map.map[index - 1] == map.map[index]) {
800
+ const pos = map.map[index];
801
+ const cell = table.nodeAt(pos);
802
+ tr.setNodeMarkup(
803
+ tr.mapping.map(tableStart + pos),
804
+ null,
805
+ addColSpan(cell.attrs, col - map.colCount(pos))
806
+ );
807
+ row += cell.attrs.rowspan - 1;
808
+ } else {
809
+ const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;
810
+ const pos = map.positionAt(row, col, table);
811
+ tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill());
812
+ }
813
+ }
814
+ return tr;
815
+ }
816
+ function addColumnBefore(state, dispatch) {
817
+ if (!isInTable(state)) return false;
818
+ if (dispatch) {
819
+ const rect = selectedRect(state);
820
+ dispatch(addColumn(state.tr, rect, rect.left));
821
+ }
822
+ return true;
823
+ }
824
+ function addColumnAfter(state, dispatch) {
825
+ if (!isInTable(state)) return false;
826
+ if (dispatch) {
827
+ const rect = selectedRect(state);
828
+ dispatch(addColumn(state.tr, rect, rect.right));
829
+ }
830
+ return true;
831
+ }
832
+ function removeColumn(tr, { map, table, tableStart }, col) {
833
+ const mapStart = tr.mapping.maps.length;
834
+ for (let row = 0; row < map.height; ) {
835
+ const index = row * map.width + col;
836
+ const pos = map.map[index];
837
+ const cell = table.nodeAt(pos);
838
+ const attrs = cell.attrs;
839
+ if (col > 0 && map.map[index - 1] == pos || col < map.width - 1 && map.map[index + 1] == pos) {
840
+ tr.setNodeMarkup(
841
+ tr.mapping.slice(mapStart).map(tableStart + pos),
842
+ null,
843
+ removeColSpan(attrs, col - map.colCount(pos))
844
+ );
845
+ } else {
846
+ const start = tr.mapping.slice(mapStart).map(tableStart + pos);
847
+ tr.delete(start, start + cell.nodeSize);
848
+ }
849
+ row += attrs.rowspan;
850
+ }
851
+ }
852
+ function deleteColumn(state, dispatch) {
853
+ if (!isInTable(state)) return false;
854
+ if (dispatch) {
855
+ const rect = selectedRect(state);
856
+ const tr = state.tr;
857
+ if (rect.left == 0 && rect.right == rect.map.width) return false;
858
+ for (let i = rect.right - 1; ; i--) {
859
+ removeColumn(tr, rect, i);
860
+ if (i == rect.left) break;
861
+ const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
862
+ if (!table) {
863
+ throw RangeError("No table found");
864
+ }
865
+ rect.table = table;
866
+ rect.map = TableMap.get(table);
867
+ }
868
+ dispatch(tr);
869
+ }
870
+ return true;
871
+ }
872
+ function rowIsHeader(map, table, row) {
873
+ var _a;
874
+ const headerCell = tableNodeTypes(table.type.schema).header_cell;
875
+ for (let col = 0; col < map.width; col++)
876
+ if (((_a = table.nodeAt(map.map[col + row * map.width])) == null ? void 0 : _a.type) != headerCell)
877
+ return false;
878
+ return true;
879
+ }
880
+ function addRow(tr, { map, tableStart, table }, row) {
881
+ var _a;
882
+ let rowPos = tableStart;
883
+ for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
884
+ const cells = [];
885
+ let refRow = row > 0 ? -1 : 0;
886
+ if (rowIsHeader(map, table, row + refRow))
887
+ refRow = row == 0 || row == map.height ? null : 0;
888
+ for (let col = 0, index = map.width * row; col < map.width; col++, index++) {
889
+ if (row > 0 && row < map.height && map.map[index] == map.map[index - map.width]) {
890
+ const pos = map.map[index];
891
+ const attrs = table.nodeAt(pos).attrs;
892
+ tr.setNodeMarkup(tableStart + pos, null, {
893
+ ...attrs,
894
+ rowspan: attrs.rowspan + 1
895
+ });
896
+ col += attrs.colspan - 1;
897
+ } else {
898
+ const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a = table.nodeAt(map.map[index + refRow * map.width])) == null ? void 0 : _a.type;
899
+ const node = type == null ? void 0 : type.createAndFill();
900
+ if (node) cells.push(node);
901
+ }
902
+ }
903
+ tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));
904
+ return tr;
905
+ }
906
+ function addRowBefore(state, dispatch) {
907
+ if (!isInTable(state)) return false;
908
+ if (dispatch) {
909
+ const rect = selectedRect(state);
910
+ dispatch(addRow(state.tr, rect, rect.top));
911
+ }
912
+ return true;
913
+ }
914
+ function addRowAfter(state, dispatch) {
915
+ if (!isInTable(state)) return false;
916
+ if (dispatch) {
917
+ const rect = selectedRect(state);
918
+ dispatch(addRow(state.tr, rect, rect.bottom));
919
+ }
920
+ return true;
921
+ }
922
+ function removeRow(tr, { map, table, tableStart }, row) {
923
+ let rowPos = 0;
924
+ for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;
925
+ const nextRow = rowPos + table.child(row).nodeSize;
926
+ const mapFrom = tr.mapping.maps.length;
927
+ tr.delete(rowPos + tableStart, nextRow + tableStart);
928
+ const seen = /* @__PURE__ */ new Set();
929
+ for (let col = 0, index = row * map.width; col < map.width; col++, index++) {
930
+ const pos = map.map[index];
931
+ if (seen.has(pos)) continue;
932
+ seen.add(pos);
933
+ if (row > 0 && pos == map.map[index - map.width]) {
934
+ const attrs = table.nodeAt(pos).attrs;
935
+ tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, {
936
+ ...attrs,
937
+ rowspan: attrs.rowspan - 1
938
+ });
939
+ col += attrs.colspan - 1;
940
+ } else if (row < map.height && pos == map.map[index + map.width]) {
941
+ const cell = table.nodeAt(pos);
942
+ const attrs = cell.attrs;
943
+ const copy = cell.type.create(
944
+ { ...attrs, rowspan: cell.attrs.rowspan - 1 },
945
+ cell.content
946
+ );
947
+ const newPos = map.positionAt(row + 1, col, table);
948
+ tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);
949
+ col += attrs.colspan - 1;
950
+ }
951
+ }
952
+ }
953
+ function deleteRow(state, dispatch) {
954
+ if (!isInTable(state)) return false;
955
+ if (dispatch) {
956
+ const rect = selectedRect(state), tr = state.tr;
957
+ if (rect.top == 0 && rect.bottom == rect.map.height) return false;
958
+ for (let i = rect.bottom - 1; ; i--) {
959
+ removeRow(tr, rect, i);
960
+ if (i == rect.top) break;
961
+ const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;
962
+ if (!table) {
963
+ throw RangeError("No table found");
964
+ }
965
+ rect.table = table;
966
+ rect.map = TableMap.get(rect.table);
967
+ }
968
+ dispatch(tr);
969
+ }
970
+ return true;
971
+ }
972
+ function isEmpty(cell) {
973
+ const c = cell.content;
974
+ return c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0;
975
+ }
976
+ function cellsOverlapRectangle({ width, height, map }, rect) {
977
+ let indexTop = rect.top * width + rect.left, indexLeft = indexTop;
978
+ let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);
979
+ for (let i = rect.top; i < rect.bottom; i++) {
980
+ if (rect.left > 0 && map[indexLeft] == map[indexLeft - 1] || rect.right < width && map[indexRight] == map[indexRight + 1])
981
+ return true;
982
+ indexLeft += width;
983
+ indexRight += width;
984
+ }
985
+ for (let i = rect.left; i < rect.right; i++) {
986
+ if (rect.top > 0 && map[indexTop] == map[indexTop - width] || rect.bottom < height && map[indexBottom] == map[indexBottom + width])
987
+ return true;
988
+ indexTop++;
989
+ indexBottom++;
990
+ }
991
+ return false;
992
+ }
993
+ function mergeCells(state, dispatch) {
994
+ const sel = state.selection;
995
+ if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
996
+ return false;
997
+ const rect = selectedRect(state), { map } = rect;
998
+ if (cellsOverlapRectangle(map, rect)) return false;
999
+ if (dispatch) {
1000
+ const tr = state.tr;
1001
+ const seen = {};
1002
+ let content = Fragment.empty;
1003
+ let mergedPos;
1004
+ let mergedCell;
1005
+ for (let row = rect.top; row < rect.bottom; row++) {
1006
+ for (let col = rect.left; col < rect.right; col++) {
1007
+ const cellPos = map.map[row * map.width + col];
1008
+ const cell = rect.table.nodeAt(cellPos);
1009
+ if (seen[cellPos] || !cell) continue;
1010
+ seen[cellPos] = true;
1011
+ if (mergedPos == null) {
1012
+ mergedPos = cellPos;
1013
+ mergedCell = cell;
1014
+ } else {
1015
+ if (!isEmpty(cell)) content = content.append(cell.content);
1016
+ const mapped = tr.mapping.map(cellPos + rect.tableStart);
1017
+ tr.delete(mapped, mapped + cell.nodeSize);
1018
+ }
1019
+ }
1020
+ }
1021
+ if (mergedPos == null || mergedCell == null) {
1022
+ return true;
1023
+ }
1024
+ tr.setNodeMarkup(mergedPos + rect.tableStart, null, {
1025
+ ...addColSpan(
1026
+ mergedCell.attrs,
1027
+ mergedCell.attrs.colspan,
1028
+ rect.right - rect.left - mergedCell.attrs.colspan
1029
+ ),
1030
+ rowspan: rect.bottom - rect.top
1031
+ });
1032
+ if (content.size) {
1033
+ const end = mergedPos + 1 + mergedCell.content.size;
1034
+ const start = isEmpty(mergedCell) ? mergedPos + 1 : end;
1035
+ tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);
1036
+ }
1037
+ tr.setSelection(
1038
+ new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
1039
+ );
1040
+ dispatch(tr);
1041
+ }
1042
+ return true;
1043
+ }
1044
+ function splitCell(state, dispatch) {
1045
+ const nodeTypes = tableNodeTypes(state.schema);
1046
+ return splitCellWithType(({ node }) => {
1047
+ return nodeTypes[node.type.spec.tableRole];
1048
+ })(state, dispatch);
1049
+ }
1050
+ function splitCellWithType(getCellType) {
1051
+ return (state, dispatch) => {
1052
+ var _a;
1053
+ const sel = state.selection;
1054
+ let cellNode;
1055
+ let cellPos;
1056
+ if (!(sel instanceof CellSelection)) {
1057
+ cellNode = cellWrapping(sel.$from);
1058
+ if (!cellNode) return false;
1059
+ cellPos = (_a = cellAround(sel.$from)) == null ? void 0 : _a.pos;
1060
+ } else {
1061
+ if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
1062
+ cellNode = sel.$anchorCell.nodeAfter;
1063
+ cellPos = sel.$anchorCell.pos;
1064
+ }
1065
+ if (cellNode == null || cellPos == null) {
1066
+ return false;
1067
+ }
1068
+ if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
1069
+ return false;
1070
+ }
1071
+ if (dispatch) {
1072
+ let baseAttrs = cellNode.attrs;
1073
+ const attrs = [];
1074
+ const colwidth = baseAttrs.colwidth;
1075
+ if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };
1076
+ if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };
1077
+ const rect = selectedRect(state), tr = state.tr;
1078
+ for (let i = 0; i < rect.right - rect.left; i++)
1079
+ attrs.push(
1080
+ colwidth ? {
1081
+ ...baseAttrs,
1082
+ colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null
1083
+ } : baseAttrs
1084
+ );
1085
+ let lastCell;
1086
+ for (let row = rect.top; row < rect.bottom; row++) {
1087
+ let pos = rect.map.positionAt(row, rect.left, rect.table);
1088
+ if (row == rect.top) pos += cellNode.nodeSize;
1089
+ for (let col = rect.left, i = 0; col < rect.right; col++, i++) {
1090
+ if (col == rect.left && row == rect.top) continue;
1091
+ tr.insert(
1092
+ lastCell = tr.mapping.map(pos + rect.tableStart, 1),
1093
+ getCellType({ node: cellNode, row, col }).createAndFill(attrs[i])
1094
+ );
1095
+ }
1096
+ }
1097
+ tr.setNodeMarkup(
1098
+ cellPos,
1099
+ getCellType({ node: cellNode, row: rect.top, col: rect.left }),
1100
+ attrs[0]
1101
+ );
1102
+ if (sel instanceof CellSelection)
1103
+ tr.setSelection(
1104
+ new CellSelection(
1105
+ tr.doc.resolve(sel.$anchorCell.pos),
1106
+ lastCell ? tr.doc.resolve(lastCell) : void 0
1107
+ )
1108
+ );
1109
+ dispatch(tr);
1110
+ }
1111
+ return true;
1112
+ };
1113
+ }
1114
+ function setCellAttr(name, value) {
1115
+ return function(state, dispatch) {
1116
+ if (!isInTable(state)) return false;
1117
+ const $cell = selectionCell(state);
1118
+ if ($cell.nodeAfter.attrs[name] === value) return false;
1119
+ if (dispatch) {
1120
+ const tr = state.tr;
1121
+ if (state.selection instanceof CellSelection)
1122
+ state.selection.forEachCell((node, pos) => {
1123
+ if (node.attrs[name] !== value)
1124
+ tr.setNodeMarkup(pos, null, {
1125
+ ...node.attrs,
1126
+ [name]: value
1127
+ });
1128
+ });
1129
+ else
1130
+ tr.setNodeMarkup($cell.pos, null, {
1131
+ ...$cell.nodeAfter.attrs,
1132
+ [name]: value
1133
+ });
1134
+ dispatch(tr);
1135
+ }
1136
+ return true;
1137
+ };
1138
+ }
1139
+ function deprecated_toggleHeader(type) {
1140
+ return function(state, dispatch) {
1141
+ if (!isInTable(state)) return false;
1142
+ if (dispatch) {
1143
+ const types = tableNodeTypes(state.schema);
1144
+ const rect = selectedRect(state), tr = state.tr;
1145
+ const cells = rect.map.cellsInRect(
1146
+ type == "column" ? {
1147
+ left: rect.left,
1148
+ top: 0,
1149
+ right: rect.right,
1150
+ bottom: rect.map.height
1151
+ } : type == "row" ? {
1152
+ left: 0,
1153
+ top: rect.top,
1154
+ right: rect.map.width,
1155
+ bottom: rect.bottom
1156
+ } : rect
1157
+ );
1158
+ const nodes = cells.map((pos) => rect.table.nodeAt(pos));
1159
+ for (let i = 0; i < cells.length; i++)
1160
+ if (nodes[i].type == types.header_cell)
1161
+ tr.setNodeMarkup(
1162
+ rect.tableStart + cells[i],
1163
+ types.cell,
1164
+ nodes[i].attrs
1165
+ );
1166
+ if (tr.steps.length == 0)
1167
+ for (let i = 0; i < cells.length; i++)
1168
+ tr.setNodeMarkup(
1169
+ rect.tableStart + cells[i],
1170
+ types.header_cell,
1171
+ nodes[i].attrs
1172
+ );
1173
+ dispatch(tr);
1174
+ }
1175
+ return true;
1176
+ };
1177
+ }
1178
+ function isHeaderEnabledByType(type, rect, types) {
1179
+ const cellPositions = rect.map.cellsInRect({
1180
+ left: 0,
1181
+ top: 0,
1182
+ right: type == "row" ? rect.map.width : 1,
1183
+ bottom: type == "column" ? rect.map.height : 1
1184
+ });
1185
+ for (let i = 0; i < cellPositions.length; i++) {
1186
+ const cell = rect.table.nodeAt(cellPositions[i]);
1187
+ if (cell && cell.type !== types.header_cell) {
1188
+ return false;
1189
+ }
1190
+ }
1191
+ return true;
1192
+ }
1193
+ function toggleHeader(type, options) {
1194
+ options = options || { useDeprecatedLogic: false };
1195
+ if (options.useDeprecatedLogic) return deprecated_toggleHeader(type);
1196
+ return function(state, dispatch) {
1197
+ if (!isInTable(state)) return false;
1198
+ if (dispatch) {
1199
+ const types = tableNodeTypes(state.schema);
1200
+ const rect = selectedRect(state), tr = state.tr;
1201
+ const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types);
1202
+ const isHeaderColumnEnabled = isHeaderEnabledByType(
1203
+ "column",
1204
+ rect,
1205
+ types
1206
+ );
1207
+ const isHeaderEnabled = type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false;
1208
+ const selectionStartsAt = isHeaderEnabled ? 1 : 0;
1209
+ const cellsRect = type == "column" ? {
1210
+ left: 0,
1211
+ top: selectionStartsAt,
1212
+ right: 1,
1213
+ bottom: rect.map.height
1214
+ } : type == "row" ? {
1215
+ left: selectionStartsAt,
1216
+ top: 0,
1217
+ right: rect.map.width,
1218
+ bottom: 1
1219
+ } : rect;
1220
+ const newType = type == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell;
1221
+ rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {
1222
+ const cellPos = relativeCellPos + rect.tableStart;
1223
+ const cell = tr.doc.nodeAt(cellPos);
1224
+ if (cell) {
1225
+ tr.setNodeMarkup(cellPos, newType, cell.attrs);
1226
+ }
1227
+ });
1228
+ dispatch(tr);
1229
+ }
1230
+ return true;
1231
+ };
1232
+ }
1233
+ toggleHeader("row", {
1234
+ useDeprecatedLogic: true
1235
+ });
1236
+ toggleHeader("column", {
1237
+ useDeprecatedLogic: true
1238
+ });
1239
+ var toggleHeaderCell = toggleHeader("cell", {
1240
+ useDeprecatedLogic: true
1241
+ });
1242
+ function findNextCell($cell, dir) {
1243
+ if (dir < 0) {
1244
+ const before = $cell.nodeBefore;
1245
+ if (before) return $cell.pos - before.nodeSize;
1246
+ for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {
1247
+ const rowNode = $cell.node(-1).child(row);
1248
+ const lastChild = rowNode.lastChild;
1249
+ if (lastChild) {
1250
+ return rowEnd - 1 - lastChild.nodeSize;
1251
+ }
1252
+ rowEnd -= rowNode.nodeSize;
1253
+ }
1254
+ } else {
1255
+ if ($cell.index() < $cell.parent.childCount - 1) {
1256
+ return $cell.pos + $cell.nodeAfter.nodeSize;
1257
+ }
1258
+ const table = $cell.node(-1);
1259
+ for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {
1260
+ const rowNode = table.child(row);
1261
+ if (rowNode.childCount) return rowStart + 1;
1262
+ rowStart += rowNode.nodeSize;
1263
+ }
1264
+ }
1265
+ return null;
1266
+ }
1267
+ function goToNextCell(direction) {
1268
+ return function(state, dispatch) {
1269
+ if (!isInTable(state)) return false;
1270
+ const cell = findNextCell(selectionCell(state), direction);
1271
+ if (cell == null) return false;
1272
+ if (dispatch) {
1273
+ const $cell = state.doc.resolve(cell);
1274
+ dispatch(
1275
+ state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
1276
+ );
1277
+ }
1278
+ return true;
1279
+ };
1280
+ }
1281
+ function deleteTable(state, dispatch) {
1282
+ const $pos = state.selection.$anchor;
1283
+ for (let d = $pos.depth; d > 0; d--) {
1284
+ const node = $pos.node(d);
1285
+ if (node.type.spec.tableRole == "table") {
1286
+ if (dispatch)
1287
+ dispatch(
1288
+ state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()
1289
+ );
1290
+ return true;
1291
+ }
1292
+ }
1293
+ return false;
1294
+ }
1295
+ function deleteCellSelection(state, dispatch) {
1296
+ const sel = state.selection;
1297
+ if (!(sel instanceof CellSelection)) return false;
1298
+ if (dispatch) {
1299
+ const tr = state.tr;
1300
+ const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
1301
+ sel.forEachCell((cell, pos) => {
1302
+ if (!cell.content.eq(baseContent))
1303
+ tr.replace(
1304
+ tr.mapping.map(pos + 1),
1305
+ tr.mapping.map(pos + cell.nodeSize - 1),
1306
+ new Slice(baseContent, 0, 0)
1307
+ );
1308
+ });
1309
+ if (tr.docChanged) dispatch(tr);
1310
+ }
1311
+ return true;
1312
+ }
1313
+ function pastedCells(slice) {
1314
+ if (!slice.size) return null;
1315
+ let { content, openStart, openEnd } = slice;
1316
+ while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
1317
+ openStart--;
1318
+ openEnd--;
1319
+ content = content.child(0).content;
1320
+ }
1321
+ const first = content.child(0);
1322
+ const role = first.type.spec.tableRole;
1323
+ const schema = first.type.schema, rows = [];
1324
+ if (role == "row") {
1325
+ for (let i = 0; i < content.childCount; i++) {
1326
+ let cells = content.child(i).content;
1327
+ const left = i ? 0 : Math.max(0, openStart - 1);
1328
+ const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
1329
+ if (left || right)
1330
+ cells = fitSlice(
1331
+ tableNodeTypes(schema).row,
1332
+ new Slice(cells, left, right)
1333
+ ).content;
1334
+ rows.push(cells);
1335
+ }
1336
+ } else if (role == "cell" || role == "header_cell") {
1337
+ rows.push(
1338
+ openStart || openEnd ? fitSlice(
1339
+ tableNodeTypes(schema).row,
1340
+ new Slice(content, openStart, openEnd)
1341
+ ).content : content
1342
+ );
1343
+ } else {
1344
+ return null;
1345
+ }
1346
+ return ensureRectangular(schema, rows);
1347
+ }
1348
+ function ensureRectangular(schema, rows) {
1349
+ const widths = [];
1350
+ for (let i = 0; i < rows.length; i++) {
1351
+ const row = rows[i];
1352
+ for (let j = row.childCount - 1; j >= 0; j--) {
1353
+ const { rowspan, colspan } = row.child(j).attrs;
1354
+ for (let r = i; r < i + rowspan; r++)
1355
+ widths[r] = (widths[r] || 0) + colspan;
1356
+ }
1357
+ }
1358
+ let width = 0;
1359
+ for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);
1360
+ for (let r = 0; r < widths.length; r++) {
1361
+ if (r >= rows.length) rows.push(Fragment.empty);
1362
+ if (widths[r] < width) {
1363
+ const empty = tableNodeTypes(schema).cell.createAndFill();
1364
+ const cells = [];
1365
+ for (let i = widths[r]; i < width; i++) {
1366
+ cells.push(empty);
1367
+ }
1368
+ rows[r] = rows[r].append(Fragment.from(cells));
1369
+ }
1370
+ }
1371
+ return { height: rows.length, width, rows };
1372
+ }
1373
+ function fitSlice(nodeType, slice) {
1374
+ const node = nodeType.createAndFill();
1375
+ const tr = new Transform(node).replace(0, node.content.size, slice);
1376
+ return tr.doc;
1377
+ }
1378
+ function clipCells({ width, height, rows }, newWidth, newHeight) {
1379
+ if (width != newWidth) {
1380
+ const added = [];
1381
+ const newRows = [];
1382
+ for (let row = 0; row < rows.length; row++) {
1383
+ const frag = rows[row], cells = [];
1384
+ for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
1385
+ let cell = frag.child(i % frag.childCount);
1386
+ if (col + cell.attrs.colspan > newWidth)
1387
+ cell = cell.type.createChecked(
1388
+ removeColSpan(
1389
+ cell.attrs,
1390
+ cell.attrs.colspan,
1391
+ col + cell.attrs.colspan - newWidth
1392
+ ),
1393
+ cell.content
1394
+ );
1395
+ cells.push(cell);
1396
+ col += cell.attrs.colspan;
1397
+ for (let j = 1; j < cell.attrs.rowspan; j++)
1398
+ added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
1399
+ }
1400
+ newRows.push(Fragment.from(cells));
1401
+ }
1402
+ rows = newRows;
1403
+ width = newWidth;
1404
+ }
1405
+ if (height != newHeight) {
1406
+ const newRows = [];
1407
+ for (let row = 0, i = 0; row < newHeight; row++, i++) {
1408
+ const cells = [], source = rows[i % height];
1409
+ for (let j = 0; j < source.childCount; j++) {
1410
+ let cell = source.child(j);
1411
+ if (row + cell.attrs.rowspan > newHeight)
1412
+ cell = cell.type.create(
1413
+ {
1414
+ ...cell.attrs,
1415
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
1416
+ },
1417
+ cell.content
1418
+ );
1419
+ cells.push(cell);
1420
+ }
1421
+ newRows.push(Fragment.from(cells));
1422
+ }
1423
+ rows = newRows;
1424
+ height = newHeight;
1425
+ }
1426
+ return { width, height, rows };
1427
+ }
1428
+ function growTable(tr, map, table, start, width, height, mapFrom) {
1429
+ const schema = tr.doc.type.schema;
1430
+ const types = tableNodeTypes(schema);
1431
+ let empty;
1432
+ let emptyHead;
1433
+ if (width > map.width) {
1434
+ for (let row = 0, rowEnd = 0; row < map.height; row++) {
1435
+ const rowNode = table.child(row);
1436
+ rowEnd += rowNode.nodeSize;
1437
+ const cells = [];
1438
+ let add;
1439
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
1440
+ add = empty || (empty = types.cell.createAndFill());
1441
+ else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
1442
+ for (let i = map.width; i < width; i++) cells.push(add);
1443
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
1444
+ }
1445
+ }
1446
+ if (height > map.height) {
1447
+ const cells = [];
1448
+ for (let i = 0, start2 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
1449
+ const header = i >= map.width ? false : table.nodeAt(map.map[start2 + i]).type == types.header_cell;
1450
+ cells.push(
1451
+ header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill())
1452
+ );
1453
+ }
1454
+ const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
1455
+ for (let i = map.height; i < height; i++) rows.push(emptyRow);
1456
+ tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
1457
+ }
1458
+ return !!(empty || emptyHead);
1459
+ }
1460
+ function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
1461
+ if (top == 0 || top == map.height) return false;
1462
+ let found = false;
1463
+ for (let col = left; col < right; col++) {
1464
+ const index = top * map.width + col, pos = map.map[index];
1465
+ if (map.map[index - map.width] == pos) {
1466
+ found = true;
1467
+ const cell = table.nodeAt(pos);
1468
+ const { top: cellTop, left: cellLeft } = map.findCell(pos);
1469
+ tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {
1470
+ ...cell.attrs,
1471
+ rowspan: top - cellTop
1472
+ });
1473
+ tr.insert(
1474
+ tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),
1475
+ cell.type.createAndFill({
1476
+ ...cell.attrs,
1477
+ rowspan: cellTop + cell.attrs.rowspan - top
1478
+ })
1479
+ );
1480
+ col += cell.attrs.colspan - 1;
1481
+ }
1482
+ }
1483
+ return found;
1484
+ }
1485
+ function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
1486
+ if (left == 0 || left == map.width) return false;
1487
+ let found = false;
1488
+ for (let row = top; row < bottom; row++) {
1489
+ const index = row * map.width + left, pos = map.map[index];
1490
+ if (map.map[index - 1] == pos) {
1491
+ found = true;
1492
+ const cell = table.nodeAt(pos);
1493
+ const cellLeft = map.colCount(pos);
1494
+ const updatePos = tr.mapping.slice(mapFrom).map(pos + start);
1495
+ tr.setNodeMarkup(
1496
+ updatePos,
1497
+ null,
1498
+ removeColSpan(
1499
+ cell.attrs,
1500
+ left - cellLeft,
1501
+ cell.attrs.colspan - (left - cellLeft)
1502
+ )
1503
+ );
1504
+ tr.insert(
1505
+ updatePos + cell.nodeSize,
1506
+ cell.type.createAndFill(
1507
+ removeColSpan(cell.attrs, 0, left - cellLeft)
1508
+ )
1509
+ );
1510
+ row += cell.attrs.rowspan - 1;
1511
+ }
1512
+ }
1513
+ return found;
1514
+ }
1515
+ function insertCells(state, dispatch, tableStart, rect, cells) {
1516
+ let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
1517
+ if (!table) {
1518
+ throw new Error("No table found");
1519
+ }
1520
+ let map = TableMap.get(table);
1521
+ const { top, left } = rect;
1522
+ const right = left + cells.width, bottom = top + cells.height;
1523
+ const tr = state.tr;
1524
+ let mapFrom = 0;
1525
+ function recomp() {
1526
+ table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
1527
+ if (!table) {
1528
+ throw new Error("No table found");
1529
+ }
1530
+ map = TableMap.get(table);
1531
+ mapFrom = tr.mapping.maps.length;
1532
+ }
1533
+ if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();
1534
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom))
1535
+ recomp();
1536
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom))
1537
+ recomp();
1538
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom))
1539
+ recomp();
1540
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom))
1541
+ recomp();
1542
+ for (let row = top; row < bottom; row++) {
1543
+ const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);
1544
+ tr.replace(
1545
+ tr.mapping.slice(mapFrom).map(from + tableStart),
1546
+ tr.mapping.slice(mapFrom).map(to + tableStart),
1547
+ new Slice(cells.rows[row - top], 0, 0)
1548
+ );
1549
+ }
1550
+ recomp();
1551
+ tr.setSelection(
1552
+ new CellSelection(
1553
+ tr.doc.resolve(tableStart + map.positionAt(top, left, table)),
1554
+ tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))
1555
+ )
1556
+ );
1557
+ dispatch(tr);
1558
+ }
1559
+
1560
+ // src/input.ts
1561
+ var handleKeyDown = keydownHandler({
1562
+ ArrowLeft: arrow("horiz", -1),
1563
+ ArrowRight: arrow("horiz", 1),
1564
+ ArrowUp: arrow("vert", -1),
1565
+ ArrowDown: arrow("vert", 1),
1566
+ "Shift-ArrowLeft": shiftArrow("horiz", -1),
1567
+ "Shift-ArrowRight": shiftArrow("horiz", 1),
1568
+ "Shift-ArrowUp": shiftArrow("vert", -1),
1569
+ "Shift-ArrowDown": shiftArrow("vert", 1),
1570
+ Backspace: deleteCellSelection,
1571
+ "Mod-Backspace": deleteCellSelection,
1572
+ Delete: deleteCellSelection,
1573
+ "Mod-Delete": deleteCellSelection
1574
+ });
1575
+ function maybeSetSelection(state, dispatch, selection) {
1576
+ if (selection.eq(state.selection)) return false;
1577
+ if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());
1578
+ return true;
1579
+ }
1580
+ function arrow(axis, dir) {
1581
+ return (state, dispatch, view) => {
1582
+ if (!view) return false;
1583
+ const sel = state.selection;
1584
+ if (sel instanceof CellSelection) {
1585
+ return maybeSetSelection(
1586
+ state,
1587
+ dispatch,
1588
+ Selection.near(sel.$headCell, dir)
1589
+ );
1590
+ }
1591
+ if (axis != "horiz" && !sel.empty) return false;
1592
+ const end = atEndOfCell(view, axis, dir);
1593
+ if (end == null) return false;
1594
+ if (axis == "horiz") {
1595
+ return maybeSetSelection(
1596
+ state,
1597
+ dispatch,
1598
+ Selection.near(state.doc.resolve(sel.head + dir), dir)
1599
+ );
1600
+ } else {
1601
+ const $cell = state.doc.resolve(end);
1602
+ const $next = nextCell($cell, axis, dir);
1603
+ let newSel;
1604
+ if ($next) newSel = Selection.near($next, 1);
1605
+ else if (dir < 0)
1606
+ newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
1607
+ else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
1608
+ return maybeSetSelection(state, dispatch, newSel);
1609
+ }
1610
+ };
1611
+ }
1612
+ function shiftArrow(axis, dir) {
1613
+ return (state, dispatch, view) => {
1614
+ if (!view) return false;
1615
+ const sel = state.selection;
1616
+ let cellSel;
1617
+ if (sel instanceof CellSelection) {
1618
+ cellSel = sel;
1619
+ } else {
1620
+ const end = atEndOfCell(view, axis, dir);
1621
+ if (end == null) return false;
1622
+ cellSel = new CellSelection(state.doc.resolve(end));
1623
+ }
1624
+ const $head = nextCell(cellSel.$headCell, axis, dir);
1625
+ if (!$head) return false;
1626
+ return maybeSetSelection(
1627
+ state,
1628
+ dispatch,
1629
+ new CellSelection(cellSel.$anchorCell, $head)
1630
+ );
1631
+ };
1632
+ }
1633
+ function handleTripleClick(view, pos) {
1634
+ const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));
1635
+ if (!$cell) return false;
1636
+ view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
1637
+ return true;
1638
+ }
1639
+ function handlePaste(view, _, slice) {
1640
+ if (!isInTable(view.state)) return false;
1641
+ let cells = pastedCells(slice);
1642
+ const sel = view.state.selection;
1643
+ if (sel instanceof CellSelection) {
1644
+ if (!cells)
1645
+ cells = {
1646
+ width: 1,
1647
+ height: 1,
1648
+ rows: [
1649
+ Fragment.from(
1650
+ fitSlice(tableNodeTypes(view.state.schema).cell, slice)
1651
+ )
1652
+ ]
1653
+ };
1654
+ const table = sel.$anchorCell.node(-1);
1655
+ const start = sel.$anchorCell.start(-1);
1656
+ const rect = TableMap.get(table).rectBetween(
1657
+ sel.$anchorCell.pos - start,
1658
+ sel.$headCell.pos - start
1659
+ );
1660
+ cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
1661
+ insertCells(view.state, view.dispatch, start, rect, cells);
1662
+ return true;
1663
+ } else if (cells) {
1664
+ const $cell = selectionCell(view.state);
1665
+ const start = $cell.start(-1);
1666
+ insertCells(
1667
+ view.state,
1668
+ view.dispatch,
1669
+ start,
1670
+ TableMap.get($cell.node(-1)).findCell($cell.pos - start),
1671
+ cells
1672
+ );
1673
+ return true;
1674
+ } else {
1675
+ return false;
1676
+ }
1677
+ }
1678
+ function handleMouseDown(view, startEvent) {
1679
+ var _a;
1680
+ if (startEvent.ctrlKey || startEvent.metaKey) return;
1681
+ const startDOMCell = domInCell(view, startEvent.target);
1682
+ let $anchor;
1683
+ if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
1684
+ setCellSelection(view.state.selection.$anchorCell, startEvent);
1685
+ startEvent.preventDefault();
1686
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
1687
+ setCellSelection($anchor, startEvent);
1688
+ startEvent.preventDefault();
1689
+ } else if (!startDOMCell) {
1690
+ return;
1691
+ }
1692
+ function setCellSelection($anchor2, event) {
1693
+ let $head = cellUnderMouse(view, event);
1694
+ const starting = tableEditingKey.getState(view.state) == null;
1695
+ if (!$head || !inSameTable($anchor2, $head)) {
1696
+ if (starting) $head = $anchor2;
1697
+ else return;
1698
+ }
1699
+ const selection = new CellSelection($anchor2, $head);
1700
+ if (starting || !view.state.selection.eq(selection)) {
1701
+ const tr = view.state.tr.setSelection(selection);
1702
+ if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);
1703
+ view.dispatch(tr);
1704
+ }
1705
+ }
1706
+ function stop() {
1707
+ view.root.removeEventListener("mouseup", stop);
1708
+ view.root.removeEventListener("dragstart", stop);
1709
+ view.root.removeEventListener("mousemove", move);
1710
+ if (tableEditingKey.getState(view.state) != null)
1711
+ view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
1712
+ }
1713
+ function move(_event) {
1714
+ const event = _event;
1715
+ const anchor = tableEditingKey.getState(view.state);
1716
+ let $anchor2;
1717
+ if (anchor != null) {
1718
+ $anchor2 = view.state.doc.resolve(anchor);
1719
+ } else if (domInCell(view, event.target) != startDOMCell) {
1720
+ $anchor2 = cellUnderMouse(view, startEvent);
1721
+ if (!$anchor2) return stop();
1722
+ }
1723
+ if ($anchor2) setCellSelection($anchor2, event);
1724
+ }
1725
+ view.root.addEventListener("mouseup", stop);
1726
+ view.root.addEventListener("dragstart", stop);
1727
+ view.root.addEventListener("mousemove", move);
1728
+ }
1729
+ function atEndOfCell(view, axis, dir) {
1730
+ if (!(view.state.selection instanceof TextSelection)) return null;
1731
+ const { $head } = view.state.selection;
1732
+ for (let d = $head.depth - 1; d >= 0; d--) {
1733
+ const parent = $head.node(d), index = dir < 0 ? $head.index(d) : $head.indexAfter(d);
1734
+ if (index != (dir < 0 ? 0 : parent.childCount)) return null;
1735
+ if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
1736
+ const cellPos = $head.before(d);
1737
+ const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
1738
+ return view.endOfTextblock(dirStr) ? cellPos : null;
1739
+ }
1740
+ }
1741
+ return null;
1742
+ }
1743
+ function domInCell(view, dom) {
1744
+ for (; dom && dom != view.dom; dom = dom.parentNode) {
1745
+ if (dom.nodeName == "TD" || dom.nodeName == "TH") {
1746
+ return dom;
1747
+ }
1748
+ }
1749
+ return null;
1750
+ }
1751
+ function cellUnderMouse(view, event) {
1752
+ const mousePos = view.posAtCoords({
1753
+ left: event.clientX,
1754
+ top: event.clientY
1755
+ });
1756
+ if (!mousePos) return null;
1757
+ return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
1758
+ }
1759
+
1760
+ // src/tableview.ts
1761
+ var TableView = class {
1762
+ constructor(node, defaultCellMinWidth) {
1763
+ this.node = node;
1764
+ this.defaultCellMinWidth = defaultCellMinWidth;
1765
+ this.dom = document.createElement("div");
1766
+ this.dom.className = "tableWrapper";
1767
+ this.table = this.dom.appendChild(document.createElement("table"));
1768
+ this.table.style.setProperty(
1769
+ "--default-cell-min-width",
1770
+ `${defaultCellMinWidth}px`
1771
+ );
1772
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
1773
+ updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);
1774
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
1775
+ }
1776
+ update(node) {
1777
+ if (node.type != this.node.type) return false;
1778
+ this.node = node;
1779
+ updateColumnsOnResize(
1780
+ node,
1781
+ this.colgroup,
1782
+ this.table,
1783
+ this.defaultCellMinWidth
1784
+ );
1785
+ return true;
1786
+ }
1787
+ ignoreMutation(record) {
1788
+ return record.type == "attributes" && (record.target == this.table || this.colgroup.contains(record.target));
1789
+ }
1790
+ };
1791
+ function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {
1792
+ var _a;
1793
+ let totalWidth = 0;
1794
+ let fixedWidth = true;
1795
+ let nextDOM = colgroup.firstChild;
1796
+ const row = node.firstChild;
1797
+ if (!row) return;
1798
+ for (let i = 0, col = 0; i < row.childCount; i++) {
1799
+ const { colspan, colwidth } = row.child(i).attrs;
1800
+ for (let j = 0; j < colspan; j++, col++) {
1801
+ const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];
1802
+ const cssWidth = hasWidth ? hasWidth + "px" : "";
1803
+ totalWidth += hasWidth || defaultCellMinWidth;
1804
+ if (!hasWidth) fixedWidth = false;
1805
+ if (!nextDOM) {
1806
+ const col2 = document.createElement("col");
1807
+ col2.style.width = cssWidth;
1808
+ colgroup.appendChild(col2);
1809
+ } else {
1810
+ if (nextDOM.style.width != cssWidth) {
1811
+ nextDOM.style.width = cssWidth;
1812
+ }
1813
+ nextDOM = nextDOM.nextSibling;
1814
+ }
1815
+ }
1816
+ }
1817
+ while (nextDOM) {
1818
+ const after = nextDOM.nextSibling;
1819
+ (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
1820
+ nextDOM = after;
1821
+ }
1822
+ if (fixedWidth) {
1823
+ table.style.width = totalWidth + "px";
1824
+ table.style.minWidth = "";
1825
+ } else {
1826
+ table.style.width = "";
1827
+ table.style.minWidth = totalWidth + "px";
1828
+ }
1829
+ }
1830
+
1831
+ // src/columnresizing.ts
1832
+ var columnResizingPluginKey = new PluginKey(
1833
+ "tableColumnResizing"
1834
+ );
1835
+ function columnResizing({
1836
+ handleWidth = 5,
1837
+ cellMinWidth = 25,
1838
+ defaultCellMinWidth = 100,
1839
+ View = TableView,
1840
+ lastColumnResizable = true
1841
+ } = {}) {
1842
+ const plugin = new Plugin({
1843
+ key: columnResizingPluginKey,
1844
+ state: {
1845
+ init(_, state) {
1846
+ var _a, _b;
1847
+ const nodeViews = (_b = (_a = plugin.spec) == null ? void 0 : _a.props) == null ? void 0 : _b.nodeViews;
1848
+ const tableName = tableNodeTypes(state.schema).table.name;
1849
+ if (View && nodeViews) {
1850
+ nodeViews[tableName] = (node, view) => {
1851
+ return new View(node, defaultCellMinWidth, view);
1852
+ };
1853
+ }
1854
+ return new ResizeState(-1, false);
1855
+ },
1856
+ apply(tr, prev) {
1857
+ return prev.apply(tr);
1858
+ }
1859
+ },
1860
+ props: {
1861
+ attributes: (state) => {
1862
+ const pluginState = columnResizingPluginKey.getState(state);
1863
+ return pluginState && pluginState.activeHandle > -1 ? { class: "resize-cursor" } : {};
1864
+ },
1865
+ handleDOMEvents: {
1866
+ mousemove: (view, event) => {
1867
+ handleMouseMove(view, event, handleWidth, lastColumnResizable);
1868
+ },
1869
+ mouseleave: (view) => {
1870
+ handleMouseLeave(view);
1871
+ },
1872
+ mousedown: (view, event) => {
1873
+ handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth);
1874
+ }
1875
+ },
1876
+ decorations: (state) => {
1877
+ const pluginState = columnResizingPluginKey.getState(state);
1878
+ if (pluginState && pluginState.activeHandle > -1) {
1879
+ return handleDecorations(state, pluginState.activeHandle);
1880
+ }
1881
+ },
1882
+ nodeViews: {}
1883
+ }
1884
+ });
1885
+ return plugin;
1886
+ }
1887
+ var ResizeState = class _ResizeState {
1888
+ constructor(activeHandle, dragging) {
1889
+ this.activeHandle = activeHandle;
1890
+ this.dragging = dragging;
1891
+ }
1892
+ apply(tr) {
1893
+ const state = this;
1894
+ const action = tr.getMeta(columnResizingPluginKey);
1895
+ if (action && action.setHandle != null)
1896
+ return new _ResizeState(action.setHandle, false);
1897
+ if (action && action.setDragging !== void 0)
1898
+ return new _ResizeState(state.activeHandle, action.setDragging);
1899
+ if (state.activeHandle > -1 && tr.docChanged) {
1900
+ let handle = tr.mapping.map(state.activeHandle, -1);
1901
+ if (!pointsAtCell(tr.doc.resolve(handle))) {
1902
+ handle = -1;
1903
+ }
1904
+ return new _ResizeState(handle, state.dragging);
1905
+ }
1906
+ return state;
1907
+ }
1908
+ };
1909
+ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
1910
+ if (!view.editable) return;
1911
+ const pluginState = columnResizingPluginKey.getState(view.state);
1912
+ if (!pluginState) return;
1913
+ if (!pluginState.dragging) {
1914
+ const target = domCellAround(event.target);
1915
+ let cell = -1;
1916
+ if (target) {
1917
+ const { left, right } = target.getBoundingClientRect();
1918
+ if (event.clientX - left <= handleWidth)
1919
+ cell = edgeCell(view, event, "left", handleWidth);
1920
+ else if (right - event.clientX <= handleWidth)
1921
+ cell = edgeCell(view, event, "right", handleWidth);
1922
+ }
1923
+ if (cell != pluginState.activeHandle) {
1924
+ if (!lastColumnResizable && cell !== -1) {
1925
+ const $cell = view.state.doc.resolve(cell);
1926
+ const table = $cell.node(-1);
1927
+ const map = TableMap.get(table);
1928
+ const tableStart = $cell.start(-1);
1929
+ const col = map.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;
1930
+ if (col == map.width - 1) {
1931
+ return;
1932
+ }
1933
+ }
1934
+ updateHandle(view, cell);
1935
+ }
1936
+ }
1937
+ }
1938
+ function handleMouseLeave(view) {
1939
+ if (!view.editable) return;
1940
+ const pluginState = columnResizingPluginKey.getState(view.state);
1941
+ if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)
1942
+ updateHandle(view, -1);
1943
+ }
1944
+ function handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth) {
1945
+ var _a;
1946
+ if (!view.editable) return false;
1947
+ const win = (_a = view.dom.ownerDocument.defaultView) != null ? _a : window;
1948
+ const pluginState = columnResizingPluginKey.getState(view.state);
1949
+ if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)
1950
+ return false;
1951
+ const cell = view.state.doc.nodeAt(pluginState.activeHandle);
1952
+ const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);
1953
+ view.dispatch(
1954
+ view.state.tr.setMeta(columnResizingPluginKey, {
1955
+ setDragging: { startX: event.clientX, startWidth: width }
1956
+ })
1957
+ );
1958
+ function finish(event2) {
1959
+ win.removeEventListener("mouseup", finish);
1960
+ win.removeEventListener("mousemove", move);
1961
+ const pluginState2 = columnResizingPluginKey.getState(view.state);
1962
+ if (pluginState2 == null ? void 0 : pluginState2.dragging) {
1963
+ updateColumnWidth(
1964
+ view,
1965
+ pluginState2.activeHandle,
1966
+ draggedWidth(pluginState2.dragging, event2, cellMinWidth)
1967
+ );
1968
+ view.dispatch(
1969
+ view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })
1970
+ );
1971
+ }
1972
+ }
1973
+ function move(event2) {
1974
+ if (!event2.which) return finish(event2);
1975
+ const pluginState2 = columnResizingPluginKey.getState(view.state);
1976
+ if (!pluginState2) return;
1977
+ if (pluginState2.dragging) {
1978
+ const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth);
1979
+ displayColumnWidth(
1980
+ view,
1981
+ pluginState2.activeHandle,
1982
+ dragged,
1983
+ defaultCellMinWidth
1984
+ );
1985
+ }
1986
+ }
1987
+ displayColumnWidth(
1988
+ view,
1989
+ pluginState.activeHandle,
1990
+ width,
1991
+ defaultCellMinWidth
1992
+ );
1993
+ win.addEventListener("mouseup", finish);
1994
+ win.addEventListener("mousemove", move);
1995
+ event.preventDefault();
1996
+ return true;
1997
+ }
1998
+ function currentColWidth(view, cellPos, { colspan, colwidth }) {
1999
+ const width = colwidth && colwidth[colwidth.length - 1];
2000
+ if (width) return width;
2001
+ const dom = view.domAtPos(cellPos);
2002
+ const node = dom.node.childNodes[dom.offset];
2003
+ let domWidth = node.offsetWidth, parts = colspan;
2004
+ if (colwidth) {
2005
+ for (let i = 0; i < colspan; i++)
2006
+ if (colwidth[i]) {
2007
+ domWidth -= colwidth[i];
2008
+ parts--;
2009
+ }
2010
+ }
2011
+ return domWidth / parts;
2012
+ }
2013
+ function domCellAround(target) {
2014
+ while (target && target.nodeName != "TD" && target.nodeName != "TH")
2015
+ target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode;
2016
+ return target;
2017
+ }
2018
+ function edgeCell(view, event, side, handleWidth) {
2019
+ const offset = side == "right" ? -handleWidth : handleWidth;
2020
+ const found = view.posAtCoords({
2021
+ left: event.clientX + offset,
2022
+ top: event.clientY
2023
+ });
2024
+ if (!found) return -1;
2025
+ const { pos } = found;
2026
+ const $cell = cellAround(view.state.doc.resolve(pos));
2027
+ if (!$cell) return -1;
2028
+ if (side == "right") return $cell.pos;
2029
+ const map = TableMap.get($cell.node(-1)), start = $cell.start(-1);
2030
+ const index = map.map.indexOf($cell.pos - start);
2031
+ return index % map.width == 0 ? -1 : start + map.map[index - 1];
2032
+ }
2033
+ function draggedWidth(dragging, event, resizeMinWidth) {
2034
+ const offset = event.clientX - dragging.startX;
2035
+ return Math.max(resizeMinWidth, dragging.startWidth + offset);
2036
+ }
2037
+ function updateHandle(view, value) {
2038
+ view.dispatch(
2039
+ view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })
2040
+ );
2041
+ }
2042
+ function updateColumnWidth(view, cell, width) {
2043
+ const $cell = view.state.doc.resolve(cell);
2044
+ const table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);
2045
+ const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
2046
+ const tr = view.state.tr;
2047
+ for (let row = 0; row < map.height; row++) {
2048
+ const mapIndex = row * map.width + col;
2049
+ if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) continue;
2050
+ const pos = map.map[mapIndex];
2051
+ const attrs = table.nodeAt(pos).attrs;
2052
+ const index = attrs.colspan == 1 ? 0 : col - map.colCount(pos);
2053
+ if (attrs.colwidth && attrs.colwidth[index] == width) continue;
2054
+ const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);
2055
+ colwidth[index] = width;
2056
+ tr.setNodeMarkup(start + pos, null, { ...attrs, colwidth });
2057
+ }
2058
+ if (tr.docChanged) view.dispatch(tr);
2059
+ }
2060
+ function displayColumnWidth(view, cell, width, defaultCellMinWidth) {
2061
+ const $cell = view.state.doc.resolve(cell);
2062
+ const table = $cell.node(-1), start = $cell.start(-1);
2063
+ const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
2064
+ let dom = view.domAtPos($cell.start(-1)).node;
2065
+ while (dom && dom.nodeName != "TABLE") {
2066
+ dom = dom.parentNode;
2067
+ }
2068
+ if (!dom) return;
2069
+ updateColumnsOnResize(
2070
+ table,
2071
+ dom.firstChild,
2072
+ dom,
2073
+ defaultCellMinWidth,
2074
+ col,
2075
+ width
2076
+ );
2077
+ }
2078
+ function zeroes(n) {
2079
+ return Array(n).fill(0);
2080
+ }
2081
+ function handleDecorations(state, cell) {
2082
+ var _a;
2083
+ const decorations = [];
2084
+ const $cell = state.doc.resolve(cell);
2085
+ const table = $cell.node(-1);
2086
+ if (!table) {
2087
+ return DecorationSet.empty;
2088
+ }
2089
+ const map = TableMap.get(table);
2090
+ const start = $cell.start(-1);
2091
+ const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;
2092
+ for (let row = 0; row < map.height; row++) {
2093
+ const index = col + row * map.width;
2094
+ if ((col == map.width - 1 || map.map[index] != map.map[index + 1]) && (row == 0 || map.map[index] != map.map[index - map.width])) {
2095
+ const cellPos = map.map[index];
2096
+ const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;
2097
+ const dom = document.createElement("div");
2098
+ dom.className = "column-resize-handle";
2099
+ if ((_a = columnResizingPluginKey.getState(state)) == null ? void 0 : _a.dragging) {
2100
+ decorations.push(
2101
+ Decoration.node(
2102
+ start + cellPos,
2103
+ start + cellPos + table.nodeAt(cellPos).nodeSize,
2104
+ {
2105
+ class: "column-resize-dragging"
2106
+ }
2107
+ )
2108
+ );
2109
+ }
2110
+ decorations.push(Decoration.widget(pos, dom));
2111
+ }
2112
+ }
2113
+ return DecorationSet.create(state.doc, decorations);
2114
+ }
2115
+
2116
+ // src/index.ts
2117
+ function tableEditing({
2118
+ allowTableNodeSelection = false
2119
+ } = {}) {
2120
+ return new Plugin({
2121
+ key: tableEditingKey,
2122
+ // This piece of state is used to remember when a mouse-drag
2123
+ // cell-selection is happening, so that it can continue even as
2124
+ // transactions (which might move its anchor cell) come in.
2125
+ state: {
2126
+ init() {
2127
+ return null;
2128
+ },
2129
+ apply(tr, cur) {
2130
+ const set = tr.getMeta(tableEditingKey);
2131
+ if (set != null) return set == -1 ? null : set;
2132
+ if (cur == null || !tr.docChanged) return cur;
2133
+ const { deleted, pos } = tr.mapping.mapResult(cur);
2134
+ return deleted ? null : pos;
2135
+ }
2136
+ },
2137
+ props: {
2138
+ decorations: drawCellSelection,
2139
+ handleDOMEvents: {
2140
+ mousedown: handleMouseDown
2141
+ },
2142
+ createSelectionBetween(view) {
2143
+ return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
2144
+ },
2145
+ handleTripleClick,
2146
+ handleKeyDown,
2147
+ handlePaste
2148
+ },
2149
+ appendTransaction(_, oldState, state) {
2150
+ return normalizeSelection(
2151
+ state,
2152
+ fixTables(state, oldState),
2153
+ allowTableNodeSelection
2154
+ );
2155
+ }
2156
+ });
2157
+ }
2158
+
2159
+ export { CellSelection as C, splitCell as a, toggleHeaderCell as b, columnResizing as c, toggleHeader as d, deleteTable as e, fixTables as f, goToNextCell as g, deleteRow as h, addRowAfter as i, addRowBefore as j, deleteColumn as k, addColumnAfter as l, mergeCells as m, addColumnBefore as n, setCellAttr as s, tableEditing as t };