@limetech/lime-elements 39.33.2 → 39.34.1

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 (306) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/{checkbox.template-CHtKKyY1.js → checkbox.template-BLkvZRs6.js} +1 -1
  3. package/dist/cjs/{index-BjHIBY-I.js → index-8x93m5oI.js} +57 -21
  4. package/dist/cjs/lime-elements.cjs.js +3 -3
  5. package/dist/cjs/limel-3d-hover-effect-glow.cjs.entry.js +2 -2
  6. package/dist/cjs/limel-action-bar_3.cjs.entry.js +4 -4
  7. package/dist/cjs/limel-ai-avatar.cjs.entry.js +2 -2
  8. package/dist/cjs/limel-badge.cjs.entry.js +3 -3
  9. package/dist/cjs/limel-banner.cjs.entry.js +2 -2
  10. package/dist/cjs/limel-breadcrumbs_8.cjs.entry.js +9 -9
  11. package/dist/cjs/limel-button-group.cjs.entry.js +2 -2
  12. package/dist/cjs/limel-button.cjs.entry.js +3 -3
  13. package/dist/cjs/limel-callout.cjs.entry.js +2 -2
  14. package/dist/cjs/limel-card.cjs.entry.js +2 -2
  15. package/dist/cjs/limel-chart.cjs.entry.js +1 -1
  16. package/dist/cjs/limel-checkbox.cjs.entry.js +3 -3
  17. package/dist/cjs/limel-chip-set.cjs.entry.js +2 -2
  18. package/dist/cjs/limel-chip_2.cjs.entry.js +2 -2
  19. package/dist/cjs/limel-circular-progress.cjs.entry.js +2 -2
  20. package/dist/cjs/limel-code-diff.cjs.entry.js +75 -34
  21. package/dist/cjs/limel-code-editor.cjs.entry.js +2 -2
  22. package/dist/cjs/limel-collapsible-section.cjs.entry.js +2 -2
  23. package/dist/cjs/limel-color-picker-palette.cjs.entry.js +3 -3
  24. package/dist/cjs/limel-color-picker.cjs.entry.js +2 -2
  25. package/dist/cjs/limel-config.cjs.entry.js +1 -1
  26. package/dist/cjs/limel-date-picker.cjs.entry.js +1 -1
  27. package/dist/cjs/limel-dialog.cjs.entry.js +3 -3
  28. package/dist/cjs/limel-dock-button.cjs.entry.js +1 -1
  29. package/dist/cjs/limel-dock.cjs.entry.js +3 -3
  30. package/dist/cjs/limel-drag-handle.cjs.entry.js +2 -2
  31. package/dist/cjs/limel-dynamic-label.cjs.entry.js +1 -1
  32. package/dist/cjs/limel-email-viewer.cjs.entry.js +2 -2
  33. package/dist/cjs/limel-file-dropzone_2.cjs.entry.js +3 -3
  34. package/dist/cjs/limel-file-viewer.cjs.entry.js +61 -49
  35. package/dist/cjs/limel-file.cjs.entry.js +2 -2
  36. package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +2 -2
  37. package/dist/cjs/limel-flex-container.cjs.entry.js +2 -2
  38. package/dist/cjs/limel-form.cjs.entry.js +7831 -6820
  39. package/dist/cjs/limel-grid.cjs.entry.js +2 -2
  40. package/dist/cjs/limel-header.cjs.entry.js +2 -2
  41. package/dist/cjs/limel-help-content.cjs.entry.js +2 -2
  42. package/dist/cjs/limel-help.cjs.entry.js +3 -3
  43. package/dist/cjs/limel-helper-line.cjs.entry.js +3 -3
  44. package/dist/cjs/limel-hotkey_4.cjs.entry.js +6 -6
  45. package/dist/cjs/limel-icon-button.cjs.entry.js +2 -2
  46. package/dist/cjs/limel-icon.cjs.entry.js +2 -2
  47. package/dist/cjs/limel-info-tile.cjs.entry.js +3 -3
  48. package/dist/cjs/limel-list-item.cjs.entry.js +5 -5
  49. package/dist/cjs/limel-markdown.cjs.entry.js +3 -3
  50. package/dist/cjs/limel-masonry-layout.cjs.entry.js +2 -2
  51. package/dist/cjs/limel-menu-item-meta.cjs.entry.js +2 -2
  52. package/dist/cjs/limel-picker.cjs.entry.js +2 -2
  53. package/dist/cjs/limel-popover_2.cjs.entry.js +3 -3
  54. package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
  55. package/dist/cjs/limel-progress-flow-item.cjs.entry.js +1 -1
  56. package/dist/cjs/limel-progress-flow.cjs.entry.js +1 -1
  57. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1633 -1516
  58. package/dist/cjs/limel-radio-button-group.cjs.entry.js +2 -2
  59. package/dist/cjs/limel-radio-button.cjs.entry.js +3 -3
  60. package/dist/cjs/limel-select.cjs.entry.js +3 -3
  61. package/dist/cjs/limel-shortcut.cjs.entry.js +2 -2
  62. package/dist/cjs/limel-slider.cjs.entry.js +3 -3
  63. package/dist/cjs/limel-snackbar.cjs.entry.js +3 -3
  64. package/dist/cjs/limel-split-button.cjs.entry.js +3 -3
  65. package/dist/cjs/limel-switch.cjs.entry.js +2 -2
  66. package/dist/cjs/limel-tab-bar.cjs.entry.js +3 -3
  67. package/dist/cjs/limel-tab-panel.cjs.entry.js +2 -2
  68. package/dist/cjs/limel-table.cjs.entry.js +255 -154
  69. package/dist/cjs/limel-text-editor-link-menu.cjs.entry.js +4 -4
  70. package/dist/cjs/limel-text-editor.cjs.entry.js +16 -3
  71. package/dist/cjs/loader.cjs.js +2 -2
  72. package/dist/cjs/{markdown-parser-BIa99LAc.js → markdown-parser-ZtNkFlPt.js} +336 -370
  73. package/dist/cjs/{render-list-component-DgRQ8H3v.js → render-list-component-DAV1Dyg1.js} +1 -1
  74. package/dist/collection/collection-manifest.json +2 -1
  75. package/dist/collection/components/3d-hover-effect-glow/3d-hover-effect-glow.js +1 -1
  76. package/dist/collection/components/action-bar/action-bar-item/action-bar-overflow-menu.js +1 -1
  77. package/dist/collection/components/action-bar/action-bar.js +2 -2
  78. package/dist/collection/components/ai-avatar/ai-avatar.js +1 -1
  79. package/dist/collection/components/badge/badge.js +2 -2
  80. package/dist/collection/components/banner/banner.js +1 -1
  81. package/dist/collection/components/breadcrumbs/breadcrumbs.js +1 -1
  82. package/dist/collection/components/button/button.js +2 -2
  83. package/dist/collection/components/button-group/button-group.js +1 -1
  84. package/dist/collection/components/callout/callout.js +1 -1
  85. package/dist/collection/components/card/card.js +1 -1
  86. package/dist/collection/components/checkbox/checkbox.js +1 -1
  87. package/dist/collection/components/chip/chip.js +11 -7
  88. package/dist/collection/components/chip-set/chip-set.js +1 -1
  89. package/dist/collection/components/circular-progress/circular-progress.js +2 -2
  90. package/dist/collection/components/code-diff/code-diff.js +1 -1
  91. package/dist/collection/components/code-editor/code-editor.js +1 -1
  92. package/dist/collection/components/collapsible-section/collapsible-section.js +1 -1
  93. package/dist/collection/components/color-picker/color-picker-palette.js +2 -2
  94. package/dist/collection/components/color-picker/color-picker.js +1 -1
  95. package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.js +1 -1
  96. package/dist/collection/components/dialog/dialog.js +2 -2
  97. package/dist/collection/components/dock/dock.js +3 -3
  98. package/dist/collection/components/drag-handle/drag-handle.js +1 -1
  99. package/dist/collection/components/email-viewer/email-viewer.js +1 -1
  100. package/dist/collection/components/file/file.js +1 -1
  101. package/dist/collection/components/file-dropzone/file-dropzone.js +1 -1
  102. package/dist/collection/components/file-input/file-input.js +1 -1
  103. package/dist/collection/components/flex-container/flex-container.js +1 -1
  104. package/dist/collection/components/form/form.js +1 -1
  105. package/dist/collection/components/grid/grid.js +1 -1
  106. package/dist/collection/components/header/header.js +1 -1
  107. package/dist/collection/components/help/help-content.js +1 -1
  108. package/dist/collection/components/help/help.js +2 -2
  109. package/dist/collection/components/helper-line/helper-line.js +2 -2
  110. package/dist/collection/components/hotkey/hotkey.js +1 -1
  111. package/dist/collection/components/icon/icon.js +1 -1
  112. package/dist/collection/components/icon-button/icon-button.js +1 -1
  113. package/dist/collection/components/info-tile/info-tile.js +2 -2
  114. package/dist/collection/components/input-field/input-field.js +1 -1
  115. package/dist/collection/components/list/list.js +1 -1
  116. package/dist/collection/components/list-item/list-item.js +2 -2
  117. package/dist/collection/components/list-item/menu-item-meta/menu-item-meta.js +1 -1
  118. package/dist/collection/components/markdown/markdown.js +1 -1
  119. package/dist/collection/components/masonry-layout/masonry-layout.js +1 -1
  120. package/dist/collection/components/menu/menu.js +2 -2
  121. package/dist/collection/components/menu-list/menu-list.js +1 -1
  122. package/dist/collection/components/menu-surface/menu-surface.js +1 -1
  123. package/dist/collection/components/notched-outline/notched-outline.js +1 -1
  124. package/dist/collection/components/picker/picker.js +1 -1
  125. package/dist/collection/components/popover/popover.js +1 -1
  126. package/dist/collection/components/popover-surface/popover-surface.js +1 -1
  127. package/dist/collection/components/portal/portal.js +1 -1
  128. package/dist/collection/components/radio-button-group/radio-button-group.js +1 -1
  129. package/dist/collection/components/radio-button-group/radio-button.js +2 -2
  130. package/dist/collection/components/select/select.js +1 -1
  131. package/dist/collection/components/shortcut/shortcut.js +1 -1
  132. package/dist/collection/components/slider/slider.js +5 -5
  133. package/dist/collection/components/snackbar/snackbar.js +2 -2
  134. package/dist/collection/components/spinner/spinner.js +1 -1
  135. package/dist/collection/components/split-button/split-button.js +2 -2
  136. package/dist/collection/components/switch/switch.js +1 -1
  137. package/dist/collection/components/tab-bar/tab-bar.js +2 -2
  138. package/dist/collection/components/tab-panel/tab-panel.js +1 -1
  139. package/dist/collection/components/table/table.css +1 -0
  140. package/dist/collection/components/table/table.js +3 -3
  141. package/dist/collection/components/text-editor/link-menu/editor-link-menu.js +3 -3
  142. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +42 -3
  143. package/dist/collection/components/text-editor/text-editor.js +37 -3
  144. package/dist/collection/components/tooltip/tooltip-content.js +1 -1
  145. package/dist/collection/components/tooltip/tooltip.js +3 -3
  146. package/dist/esm/{checkbox.template-CfWJ3CAC.js → checkbox.template-CtIjSGPt.js} +1 -1
  147. package/dist/esm/{index-DBTJNfo7.js → index-VCOjLfyP.js} +57 -21
  148. package/dist/esm/lime-elements.js +4 -4
  149. package/dist/esm/limel-3d-hover-effect-glow.entry.js +2 -2
  150. package/dist/esm/limel-action-bar_3.entry.js +4 -4
  151. package/dist/esm/limel-ai-avatar.entry.js +2 -2
  152. package/dist/esm/limel-badge.entry.js +3 -3
  153. package/dist/esm/limel-banner.entry.js +2 -2
  154. package/dist/esm/limel-breadcrumbs_8.entry.js +9 -9
  155. package/dist/esm/limel-button-group.entry.js +2 -2
  156. package/dist/esm/limel-button.entry.js +3 -3
  157. package/dist/esm/limel-callout.entry.js +2 -2
  158. package/dist/esm/limel-card.entry.js +2 -2
  159. package/dist/esm/limel-chart.entry.js +1 -1
  160. package/dist/esm/limel-checkbox.entry.js +3 -3
  161. package/dist/esm/limel-chip-set.entry.js +2 -2
  162. package/dist/esm/limel-chip_2.entry.js +2 -2
  163. package/dist/esm/limel-circular-progress.entry.js +2 -2
  164. package/dist/esm/limel-code-diff.entry.js +75 -34
  165. package/dist/esm/limel-code-editor.entry.js +2 -2
  166. package/dist/esm/limel-collapsible-section.entry.js +2 -2
  167. package/dist/esm/limel-color-picker-palette.entry.js +3 -3
  168. package/dist/esm/limel-color-picker.entry.js +2 -2
  169. package/dist/esm/limel-config.entry.js +1 -1
  170. package/dist/esm/limel-date-picker.entry.js +1 -1
  171. package/dist/esm/limel-dialog.entry.js +3 -3
  172. package/dist/esm/limel-dock-button.entry.js +1 -1
  173. package/dist/esm/limel-dock.entry.js +3 -3
  174. package/dist/esm/limel-drag-handle.entry.js +2 -2
  175. package/dist/esm/limel-dynamic-label.entry.js +1 -1
  176. package/dist/esm/limel-email-viewer.entry.js +2 -2
  177. package/dist/esm/limel-file-dropzone_2.entry.js +3 -3
  178. package/dist/esm/limel-file-viewer.entry.js +61 -49
  179. package/dist/esm/limel-file.entry.js +2 -2
  180. package/dist/esm/limel-flatpickr-adapter.entry.js +2 -2
  181. package/dist/esm/limel-flex-container.entry.js +2 -2
  182. package/dist/esm/limel-form.entry.js +7831 -6820
  183. package/dist/esm/limel-grid.entry.js +2 -2
  184. package/dist/esm/limel-header.entry.js +2 -2
  185. package/dist/esm/limel-help-content.entry.js +2 -2
  186. package/dist/esm/limel-help.entry.js +3 -3
  187. package/dist/esm/limel-helper-line.entry.js +3 -3
  188. package/dist/esm/limel-hotkey_4.entry.js +6 -6
  189. package/dist/esm/limel-icon-button.entry.js +2 -2
  190. package/dist/esm/limel-icon.entry.js +2 -2
  191. package/dist/esm/limel-info-tile.entry.js +3 -3
  192. package/dist/esm/limel-list-item.entry.js +5 -5
  193. package/dist/esm/limel-markdown.entry.js +3 -3
  194. package/dist/esm/limel-masonry-layout.entry.js +2 -2
  195. package/dist/esm/limel-menu-item-meta.entry.js +2 -2
  196. package/dist/esm/limel-picker.entry.js +2 -2
  197. package/dist/esm/limel-popover_2.entry.js +3 -3
  198. package/dist/esm/limel-profile-picture.entry.js +1 -1
  199. package/dist/esm/limel-progress-flow-item.entry.js +1 -1
  200. package/dist/esm/limel-progress-flow.entry.js +1 -1
  201. package/dist/esm/limel-prosemirror-adapter.entry.js +1633 -1516
  202. package/dist/esm/limel-radio-button-group.entry.js +2 -2
  203. package/dist/esm/limel-radio-button.entry.js +3 -3
  204. package/dist/esm/limel-select.entry.js +3 -3
  205. package/dist/esm/limel-shortcut.entry.js +2 -2
  206. package/dist/esm/limel-slider.entry.js +3 -3
  207. package/dist/esm/limel-snackbar.entry.js +3 -3
  208. package/dist/esm/limel-split-button.entry.js +3 -3
  209. package/dist/esm/limel-switch.entry.js +2 -2
  210. package/dist/esm/limel-tab-bar.entry.js +3 -3
  211. package/dist/esm/limel-tab-panel.entry.js +2 -2
  212. package/dist/esm/limel-table.entry.js +255 -154
  213. package/dist/esm/limel-text-editor-link-menu.entry.js +4 -4
  214. package/dist/esm/limel-text-editor.entry.js +16 -3
  215. package/dist/esm/loader.js +3 -3
  216. package/dist/esm/{markdown-parser-D7vLKElE.js → markdown-parser-nW7FzScN.js} +294 -328
  217. package/dist/esm/{render-list-component-D7LjGxDF.js → render-list-component-BdncB2vG.js} +1 -1
  218. package/dist/lime-elements/lime-elements.esm.js +1 -1
  219. package/dist/lime-elements/{p-1efd78ee.entry.js → p-0605c490.entry.js} +1 -1
  220. package/dist/lime-elements/p-063b8d0a.entry.js +1 -0
  221. package/dist/lime-elements/{p-5d9adcbb.entry.js → p-08e7006f.entry.js} +1 -1
  222. package/dist/lime-elements/p-10955e5d.entry.js +1 -0
  223. package/dist/lime-elements/p-1153e2ba.entry.js +1 -0
  224. package/dist/lime-elements/{p-49901dd7.entry.js → p-17ff8353.entry.js} +1 -1
  225. package/dist/lime-elements/{p-19a259ff.entry.js → p-2a27bf12.entry.js} +1 -1
  226. package/dist/lime-elements/{p-d8b640e8.entry.js → p-2cb55d62.entry.js} +1 -1
  227. package/dist/lime-elements/{p-0f8672fe.entry.js → p-2ef433e0.entry.js} +1 -1
  228. package/dist/lime-elements/{p-12aa0d06.entry.js → p-317d56a7.entry.js} +1 -1
  229. package/dist/lime-elements/{p-d5f189b9.entry.js → p-31965f6c.entry.js} +2 -2
  230. package/dist/lime-elements/{p-61ec46d5.entry.js → p-33ab319b.entry.js} +1 -1
  231. package/dist/lime-elements/p-444e3088.entry.js +1 -0
  232. package/dist/lime-elements/p-44bd59ac.entry.js +1 -0
  233. package/dist/lime-elements/{p-08a261ce.entry.js → p-44f4d02e.entry.js} +1 -1
  234. package/dist/lime-elements/{p-5f121609.entry.js → p-45801616.entry.js} +1 -1
  235. package/dist/lime-elements/{p-1ae8b33a.entry.js → p-53b7bee8.entry.js} +1 -1
  236. package/dist/lime-elements/{p-122cd39d.entry.js → p-66600fc3.entry.js} +1 -1
  237. package/dist/lime-elements/{p-46900c5b.entry.js → p-6c60d915.entry.js} +1 -1
  238. package/dist/lime-elements/{p-a85b2734.entry.js → p-6fa4b1b3.entry.js} +1 -1
  239. package/dist/lime-elements/{p-59716b48.entry.js → p-719dc4c0.entry.js} +1 -1
  240. package/dist/lime-elements/{p-7b074737.entry.js → p-7776313e.entry.js} +1 -1
  241. package/dist/lime-elements/{p-6ca1da96.entry.js → p-7b687fc6.entry.js} +1 -1
  242. package/dist/lime-elements/{p-2a92790c.entry.js → p-7f891de4.entry.js} +1 -1
  243. package/dist/lime-elements/{p-a7764b6d.entry.js → p-80b0bcb3.entry.js} +1 -1
  244. package/dist/lime-elements/{p-871eb795.entry.js → p-8376ac0d.entry.js} +2 -2
  245. package/dist/lime-elements/{p-dee5717c.entry.js → p-8aaf4f50.entry.js} +1 -1
  246. package/dist/lime-elements/{p-8fde4714.entry.js → p-90a506aa.entry.js} +1 -1
  247. package/dist/lime-elements/{p-d0288858.entry.js → p-9b7966f1.entry.js} +1 -1
  248. package/dist/lime-elements/{p-bffbd011.entry.js → p-9bb07225.entry.js} +1 -1
  249. package/dist/lime-elements/{p-a6805c64.entry.js → p-9e8eaa86.entry.js} +1 -1
  250. package/dist/lime-elements/{p-989f4a52.entry.js → p-9eb06bf7.entry.js} +1 -1
  251. package/dist/lime-elements/{p-faceccc0.entry.js → p-9eb6879d.entry.js} +1 -1
  252. package/dist/lime-elements/{p--9pvUs5M.js → p-D9twpDvz.js} +1 -1
  253. package/dist/lime-elements/p-NN0EYecx.js +1 -0
  254. package/dist/lime-elements/p-VCOjLfyP.js +2 -0
  255. package/dist/lime-elements/{p-e5e8a734.entry.js → p-a0720aca.entry.js} +8 -8
  256. package/dist/lime-elements/{p-f5d60f9c.entry.js → p-a11abcb0.entry.js} +4 -4
  257. package/dist/lime-elements/p-a73f70d7.entry.js +1 -0
  258. package/dist/lime-elements/{p-129a19c7.entry.js → p-a7e9e96c.entry.js} +1 -1
  259. package/dist/lime-elements/{p-140afd9f.entry.js → p-a827a280.entry.js} +1 -1
  260. package/dist/lime-elements/{p-d0607ba8.entry.js → p-aa6190e8.entry.js} +1 -1
  261. package/dist/lime-elements/{p-b8a31121.entry.js → p-aa8d7faa.entry.js} +1 -1
  262. package/dist/lime-elements/{p-5da0315f.entry.js → p-aba01020.entry.js} +1 -1
  263. package/dist/lime-elements/{p-b61a1d27.entry.js → p-ac5d5099.entry.js} +2 -2
  264. package/dist/lime-elements/{p-9b3e8f43.entry.js → p-b3b53dbc.entry.js} +1 -1
  265. package/dist/lime-elements/{p-9359e870.entry.js → p-b7649589.entry.js} +1 -1
  266. package/dist/lime-elements/{p-1a5541f1.entry.js → p-bcc2cb1a.entry.js} +1 -1
  267. package/dist/lime-elements/{p-4d948ed5.entry.js → p-c447d311.entry.js} +1 -1
  268. package/dist/lime-elements/{p-33bd5212.entry.js → p-c6cbd842.entry.js} +1 -1
  269. package/dist/lime-elements/{p-df0b927e.entry.js → p-caf1bca2.entry.js} +1 -1
  270. package/dist/lime-elements/{p-f85dbaec.entry.js → p-cdbab1d5.entry.js} +1 -1
  271. package/dist/lime-elements/{p-DdYOzHlg.js → p-csTwzWL7.js} +2 -2
  272. package/dist/lime-elements/p-d8d6e12a.entry.js +13 -0
  273. package/dist/lime-elements/{p-60518e6b.entry.js → p-db0bd965.entry.js} +1 -1
  274. package/dist/lime-elements/{p-22f34040.entry.js → p-dc415221.entry.js} +1 -1
  275. package/dist/lime-elements/{p-91990c64.entry.js → p-e31d0b36.entry.js} +1 -1
  276. package/dist/lime-elements/p-e38a13fb.entry.js +1 -0
  277. package/dist/lime-elements/{p-fa0d7b8c.entry.js → p-e4549e8b.entry.js} +1 -1
  278. package/dist/lime-elements/{p-d09e74b1.entry.js → p-e59d7177.entry.js} +1 -1
  279. package/dist/lime-elements/{p-50f51eb9.entry.js → p-e7b9716f.entry.js} +1 -1
  280. package/dist/lime-elements/{p-9e1a4d63.entry.js → p-ed70059b.entry.js} +1 -1
  281. package/dist/lime-elements/{p-afd4be62.entry.js → p-eef0cd8b.entry.js} +1 -1
  282. package/dist/lime-elements/{p-de203f64.entry.js → p-f7695614.entry.js} +1 -1
  283. package/dist/lime-elements/{p-198f3179.entry.js → p-f91de6bd.entry.js} +1 -1
  284. package/dist/lime-elements/{p-2a9e7bf5.entry.js → p-f9b74b03.entry.js} +1 -1
  285. package/dist/lime-elements/p-f9c8e4d2.entry.js +1 -0
  286. package/dist/lime-elements/{p-6b7e58c3.entry.js → p-fac02bae.entry.js} +1 -1
  287. package/dist/lime-elements/{p-82fb5c74.entry.js → p-fc435802.entry.js} +1 -1
  288. package/dist/lime-elements/p-fe64b285.entry.js +1 -0
  289. package/dist/types/components/form/widgets/code-editor.d.ts +2 -2
  290. package/dist/types/components/text-editor/prosemirror-adapter/prosemirror-adapter.d.ts +14 -0
  291. package/dist/types/components/text-editor/text-editor.d.ts +11 -0
  292. package/dist/types/components.d.ts +30 -20
  293. package/dist/types/stencil-public-runtime.d.ts +1 -0
  294. package/package.json +34 -36
  295. package/dist/lime-elements/p-00e54ccf.entry.js +0 -1
  296. package/dist/lime-elements/p-1614ad86.entry.js +0 -1
  297. package/dist/lime-elements/p-16254e4a.entry.js +0 -1
  298. package/dist/lime-elements/p-3f78362b.entry.js +0 -13
  299. package/dist/lime-elements/p-444e571b.entry.js +0 -1
  300. package/dist/lime-elements/p-6015621e.entry.js +0 -1
  301. package/dist/lime-elements/p-730ba357.entry.js +0 -1
  302. package/dist/lime-elements/p-8203eea8.entry.js +0 -1
  303. package/dist/lime-elements/p-84f5727c.entry.js +0 -1
  304. package/dist/lime-elements/p-BaPK7VfG.js +0 -1
  305. package/dist/lime-elements/p-DBTJNfo7.js +0 -2
  306. package/dist/lime-elements/p-c9fa7a09.entry.js +0 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var index$1 = require('./index-BjHIBY-I.js');
3
+ var index$1 = require('./index-8x93m5oI.js');
4
4
  var types = require('./types-Bu6wcdI0.js');
5
- var markdownParser = require('./markdown-parser-BIa99LAc.js');
5
+ var markdownParser = require('./markdown-parser-ZtNkFlPt.js');
6
6
  var cloneDeep = require('./cloneDeep-hE40Q8aw.js');
7
7
  var index = require('./index-BgFEL6FF.js');
8
8
  var translations = require('./translations-VEsa81QY.js');
@@ -235,7 +235,7 @@ class Fragment {
235
235
  */
236
236
  constructor(
237
237
  /**
238
- @internal
238
+ The child nodes in this fragment.
239
239
  */
240
240
  content, size) {
241
241
  this.content = content;
@@ -439,7 +439,7 @@ class Fragment {
439
439
  position in this fragment. The result object will be reused
440
440
  (overwritten) the next time the function is called. @internal
441
441
  */
442
- findIndex(pos, round = -1) {
442
+ findIndex(pos) {
443
443
  if (pos == 0)
444
444
  return retIndex(0, pos);
445
445
  if (pos == this.size)
@@ -449,7 +449,7 @@ class Fragment {
449
449
  for (let i = 0, curPos = 0;; i++) {
450
450
  let cur = this.child(i), end = curPos + cur.nodeSize;
451
451
  if (end >= pos) {
452
- if (end == pos || round > 0)
452
+ if (end == pos)
453
453
  return retIndex(i + 1, end);
454
454
  return retIndex(i, curPos);
455
455
  }
@@ -478,7 +478,7 @@ class Fragment {
478
478
  return Fragment.empty;
479
479
  if (!Array.isArray(value))
480
480
  throw new RangeError("Invalid input for Fragment.fromJSON");
481
- return new Fragment(value.map(schema.nodeFromJSON));
481
+ return Fragment.fromArray(value.map(schema.nodeFromJSON));
482
482
  }
483
483
  /**
484
484
  Build a fragment from an array of nodes. Ensures that adjacent
@@ -712,17 +712,6 @@ given an invalid replacement.
712
712
  */
713
713
  class ReplaceError extends Error {
714
714
  }
715
- /*
716
- ReplaceError = function(this: any, message: string) {
717
- let err = Error.call(this, message)
718
- ;(err as any).__proto__ = ReplaceError.prototype
719
- return err
720
- } as any
721
-
722
- ReplaceError.prototype = Object.create(Error.prototype)
723
- ReplaceError.prototype.constructor = ReplaceError
724
- ReplaceError.prototype.name = "ReplaceError"
725
- */
726
715
  /**
727
716
  A slice represents a piece cut out of a larger document. It
728
717
  stores not only a fragment, but also the depth up to which nodes on
@@ -768,7 +757,7 @@ class Slice {
768
757
  @internal
769
758
  */
770
759
  insertAt(pos, fragment) {
771
- let content = insertInto(this.content, pos + this.openStart, fragment);
760
+ let content = insertInto(this.content, pos + this.openStart, fragment, this.openStart + 1, this.openEnd + 1);
772
761
  return content && new Slice(content, this.openStart, this.openEnd);
773
762
  }
774
763
  /**
@@ -842,12 +831,14 @@ function removeRange(content, from, to) {
842
831
  throw new RangeError("Removing non-flat range");
843
832
  return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
844
833
  }
845
- function insertInto(content, dist, insert, parent) {
834
+ function insertInto(content, dist, insert, openStart, openEnd, parent) {
846
835
  let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
847
836
  if (offset == dist || child.isText) {
837
+ if (parent && openStart <= 0 && openEnd <= 0 && !parent.canReplace(index, index, insert))
838
+ return null;
848
839
  return content.cut(0, dist).append(insert).append(content.cut(dist));
849
840
  }
850
- let inner = insertInto(child.content, dist - offset - 1, insert);
841
+ let inner = insertInto(child.content, dist - offset - 1, insert, index == 0 ? openStart - 1 : 0, index == content.childCount - 1 ? openEnd - 1 : 0, child);
851
842
  return inner && content.replaceChild(index, child.copy(inner));
852
843
  }
853
844
  function replace$1($from, $to, slice) {
@@ -1317,7 +1308,7 @@ structure between the old and new data as much as possible, which a
1317
1308
  tree shape like this (without back pointers) makes easy.
1318
1309
 
1319
1310
  **Do not** directly mutate the properties of a `Node` object. See
1320
- [the guide](/docs/guide/#doc) for more information.
1311
+ [the guide](https://prosemirror.net/docs/guide/#doc) for more information.
1321
1312
  */
1322
1313
  class Node {
1323
1314
  /**
@@ -1347,8 +1338,12 @@ class Node {
1347
1338
  this.content = content || Fragment.empty;
1348
1339
  }
1349
1340
  /**
1341
+ The array of this node's child nodes.
1342
+ */
1343
+ get children() { return this.content.content; }
1344
+ /**
1350
1345
  The size of this node, as defined by the integer-based [indexing
1351
- scheme](/docs/guide/#doc.indexing). For text nodes, this is the
1346
+ scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
1352
1347
  amount of characters. For other leaf nodes, it is one. For
1353
1348
  non-leaf nodes, it is the size of the content plus two (the
1354
1349
  start and end token).
@@ -1373,10 +1368,11 @@ class Node {
1373
1368
  */
1374
1369
  forEach(f) { this.content.forEach(f); }
1375
1370
  /**
1376
- Invoke a callback for all descendant nodes recursively between
1371
+ Invoke a callback for all descendant nodes recursively overlapping
1377
1372
  the given two positions that are relative to start of this
1378
- node's content. The callback is invoked with the node, its
1379
- position relative to the original node (method receiver),
1373
+ node's content. This includes all ancestors of the nodes
1374
+ containing the two positions. The callback is invoked with the
1375
+ node, its position relative to the original node (method receiver),
1380
1376
  its parent node, and its child index. When the callback returns
1381
1377
  false for a given node, that node's children will not be
1382
1378
  recursed over. The last parameter can be used to specify a
@@ -1406,7 +1402,7 @@ class Node {
1406
1402
  `blockSeparator` is given, it will be inserted to separate text
1407
1403
  from different block nodes. If `leafText` is given, it'll be
1408
1404
  inserted for every non-text leaf node encountered, otherwise
1409
- [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
1405
+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
1410
1406
  */
1411
1407
  textBetween(from, to, blockSeparator, leafText) {
1412
1408
  return this.content.textBetween(from, to, blockSeparator, leafText);
@@ -2013,7 +2009,7 @@ function resolveName(stream, name) {
2013
2009
  let result = [];
2014
2010
  for (let typeName in types) {
2015
2011
  let type = types[typeName];
2016
- if (type.groups.indexOf(name) > -1)
2012
+ if (type.isInGroup(name))
2017
2013
  result.push(type);
2018
2014
  }
2019
2015
  if (result.length == 0)
@@ -2042,16 +2038,14 @@ function parseExprAtom(stream) {
2042
2038
  stream.err("Unexpected token '" + stream.next + "'");
2043
2039
  }
2044
2040
  }
2045
- /**
2046
- Construct an NFA from an expression as returned by the parser. The
2047
- NFA is represented as an array of states, which are themselves
2048
- arrays of edges, which are `{term, to}` objects. The first state is
2049
- the entry state and the last node is the success state.
2050
-
2051
- Note that unlike typical NFAs, the edge ordering in this one is
2052
- significant, in that it is used to contruct filler content when
2053
- necessary.
2054
- */
2041
+ // Construct an NFA from an expression as returned by the parser. The
2042
+ // NFA is represented as an array of states, which are themselves
2043
+ // arrays of edges, which are `{term, to}` objects. The first state is
2044
+ // the entry state and the last node is the success state.
2045
+ //
2046
+ // Note that unlike typical NFAs, the edge ordering in this one is
2047
+ // significant, in that it is used to contruct filler content when
2048
+ // necessary.
2055
2049
  function nfa(expr) {
2056
2050
  let nfa = [[]];
2057
2051
  connect(compile(expr, 0), node());
@@ -2292,6 +2286,13 @@ let NodeType$1 = class NodeType {
2292
2286
  */
2293
2287
  get isAtom() { return this.isLeaf || !!this.spec.atom; }
2294
2288
  /**
2289
+ Return true when this node type is part of the given
2290
+ [group](https://prosemirror.net/docs/ref/#model.NodeSpec.group).
2291
+ */
2292
+ isInGroup(group) {
2293
+ return this.groups.indexOf(group) > -1;
2294
+ }
2295
+ /**
2295
2296
  The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
2296
2297
  */
2297
2298
  get whitespace() {
@@ -2611,8 +2612,8 @@ class Schema {
2611
2612
  let type = this.marks[prop], excl = type.spec.excludes;
2612
2613
  type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" "));
2613
2614
  }
2614
- this.nodeFromJSON = this.nodeFromJSON.bind(this);
2615
- this.markFromJSON = this.markFromJSON.bind(this);
2615
+ this.nodeFromJSON = json => Node.fromJSON(this, json);
2616
+ this.markFromJSON = json => Mark.fromJSON(this, json);
2616
2617
  this.topNodeType = this.nodes[this.spec.topNode || "doc"];
2617
2618
  this.cached.wrappings = Object.create(null);
2618
2619
  }
@@ -2648,20 +2649,6 @@ class Schema {
2648
2649
  return type.create(attrs);
2649
2650
  }
2650
2651
  /**
2651
- Deserialize a node from its JSON representation. This method is
2652
- bound.
2653
- */
2654
- nodeFromJSON(json) {
2655
- return Node.fromJSON(this, json);
2656
- }
2657
- /**
2658
- Deserialize a mark from its JSON representation. This method is
2659
- bound.
2660
- */
2661
- markFromJSON(json) {
2662
- return Mark.fromJSON(this, json);
2663
- }
2664
- /**
2665
2652
  @internal
2666
2653
  */
2667
2654
  nodeType(name) {
@@ -2843,7 +2830,7 @@ class DOMParser {
2843
2830
  /**
2844
2831
  Construct a DOM parser using the parsing rules listed in a
2845
2832
  schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
2846
- [priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
2833
+ [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority).
2847
2834
  */
2848
2835
  static fromSchema(schema) {
2849
2836
  return schema.cached.domParser ||
@@ -2936,6 +2923,7 @@ class ParseContext {
2936
2923
  this.options = options;
2937
2924
  this.isOpen = isOpen;
2938
2925
  this.open = 0;
2926
+ this.localPreserveWS = false;
2939
2927
  let topNode = options.topNode, topContext;
2940
2928
  let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0);
2941
2929
  if (topNode)
@@ -2962,11 +2950,13 @@ class ParseContext {
2962
2950
  }
2963
2951
  addTextNode(dom, marks) {
2964
2952
  let value = dom.nodeValue;
2965
- let top = this.top;
2966
- if (top.options & OPT_PRESERVE_WS_FULL ||
2953
+ let top = this.top, preserveWS = (top.options & OPT_PRESERVE_WS_FULL) ? "full"
2954
+ : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;
2955
+ let { schema } = this.parser;
2956
+ if (preserveWS === "full" ||
2967
2957
  top.inlineContext(dom) ||
2968
2958
  /[^ \t\r\n\u000c]/.test(value)) {
2969
- if (!(top.options & OPT_PRESERVE_WS)) {
2959
+ if (!preserveWS) {
2970
2960
  value = value.replace(/[ \t\r\n\u000c]+/g, " ");
2971
2961
  // If this starts with whitespace, and there is no node before it, or
2972
2962
  // a hard break, or a text node that ends with whitespace, strip the
@@ -2980,14 +2970,24 @@ class ParseContext {
2980
2970
  value = value.slice(1);
2981
2971
  }
2982
2972
  }
2983
- else if (!(top.options & OPT_PRESERVE_WS_FULL)) {
2984
- value = value.replace(/\r?\n|\r/g, " ");
2973
+ else if (preserveWS === "full") {
2974
+ value = value.replace(/\r\n?/g, "\n");
2975
+ }
2976
+ else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) {
2977
+ let lines = value.split(/\r?\n|\r/);
2978
+ for (let i = 0; i < lines.length; i++) {
2979
+ if (i)
2980
+ this.insertNode(schema.linebreakReplacement.create(), marks, true);
2981
+ if (lines[i])
2982
+ this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i]));
2983
+ }
2984
+ value = "";
2985
2985
  }
2986
2986
  else {
2987
- value = value.replace(/\r\n?/g, "\n");
2987
+ value = value.replace(/\r?\n|\r/g, " ");
2988
2988
  }
2989
2989
  if (value)
2990
- this.insertNode(this.parser.schema.text(value), marks);
2990
+ this.insertNode(schema.text(value), marks, !/\S/.test(value));
2991
2991
  this.findInText(dom);
2992
2992
  }
2993
2993
  else {
@@ -2997,12 +2997,15 @@ class ParseContext {
2997
2997
  // Try to find a handler for the given tag and use that to parse. If
2998
2998
  // none is found, the element's content nodes are added directly.
2999
2999
  addElement(dom, marks, matchAfter) {
3000
+ let outerWS = this.localPreserveWS, top = this.top;
3001
+ if (dom.tagName == "PRE" || /pre/.test(dom.style && dom.style.whiteSpace))
3002
+ this.localPreserveWS = true;
3000
3003
  let name = dom.nodeName.toLowerCase(), ruleID;
3001
3004
  if (listTags.hasOwnProperty(name) && this.parser.normalizeLists)
3002
3005
  normalizeList(dom);
3003
3006
  let rule = (this.options.ruleFromNode && this.options.ruleFromNode(dom)) ||
3004
3007
  (ruleID = this.parser.matchTag(dom, this, matchAfter));
3005
- if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {
3008
+ out: if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {
3006
3009
  this.findInside(dom);
3007
3010
  this.ignoreFallback(dom, marks);
3008
3011
  }
@@ -3011,7 +3014,7 @@ class ParseContext {
3011
3014
  this.open = Math.max(0, this.open - 1);
3012
3015
  else if (rule && rule.skip.nodeType)
3013
3016
  dom = rule.skip;
3014
- let sync, top = this.top, oldNeedsBlock = this.needsBlock;
3017
+ let sync, oldNeedsBlock = this.needsBlock;
3015
3018
  if (blockTags.hasOwnProperty(name)) {
3016
3019
  if (top.content.length && top.content[0].isInline && this.open) {
3017
3020
  this.open--;
@@ -3023,7 +3026,7 @@ class ParseContext {
3023
3026
  }
3024
3027
  else if (!dom.firstChild) {
3025
3028
  this.leafFallback(dom, marks);
3026
- return;
3029
+ break out;
3027
3030
  }
3028
3031
  let innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks);
3029
3032
  if (innerMarks)
@@ -3037,6 +3040,7 @@ class ParseContext {
3037
3040
  if (innerMarks)
3038
3041
  this.addElementByRule(dom, rule, innerMarks, rule.consuming === false ? ruleID : undefined);
3039
3042
  }
3043
+ this.localPreserveWS = outerWS;
3040
3044
  }
3041
3045
  // Called for leaf DOM nodes that would otherwise be ignored
3042
3046
  leafFallback(dom, marks) {
@@ -3047,7 +3051,7 @@ class ParseContext {
3047
3051
  ignoreFallback(dom, marks) {
3048
3052
  // Ignored BR nodes should at least create an inline context
3049
3053
  if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent))
3050
- this.findPlace(this.parser.schema.text("-"), marks);
3054
+ this.findPlace(this.parser.schema.text("-"), marks, true);
3051
3055
  }
3052
3056
  // Run any style parser associated with the node's styles. Either
3053
3057
  // return an updated array of marks, or null to indicate some of the
@@ -3095,7 +3099,7 @@ class ParseContext {
3095
3099
  marks = inner;
3096
3100
  }
3097
3101
  }
3098
- else if (!this.insertNode(nodeType.create(rule.attrs), marks)) {
3102
+ else if (!this.insertNode(nodeType.create(rule.attrs), marks, dom.nodeName == "BR")) {
3099
3103
  this.leafFallback(dom, marks);
3100
3104
  }
3101
3105
  }
@@ -3112,7 +3116,7 @@ class ParseContext {
3112
3116
  }
3113
3117
  else if (rule.getContent) {
3114
3118
  this.findInside(dom);
3115
- rule.getContent(dom, this.parser.schema).forEach(node => this.insertNode(node, marks));
3119
+ rule.getContent(dom, this.parser.schema).forEach(node => this.insertNode(node, marks, false));
3116
3120
  }
3117
3121
  else {
3118
3122
  let contentDOM = dom;
@@ -3124,6 +3128,7 @@ class ParseContext {
3124
3128
  contentDOM = rule.contentElement;
3125
3129
  this.findAround(dom, contentDOM, true);
3126
3130
  this.addAll(contentDOM, marks);
3131
+ this.findAround(dom, contentDOM, false);
3127
3132
  }
3128
3133
  if (sync && this.sync(startIn))
3129
3134
  this.open--;
@@ -3142,19 +3147,22 @@ class ParseContext {
3142
3147
  // Try to find a way to fit the given node type into the current
3143
3148
  // context. May add intermediate wrappers and/or leave non-solid
3144
3149
  // nodes that we're in.
3145
- findPlace(node, marks) {
3150
+ findPlace(node, marks, cautious) {
3146
3151
  let route, sync;
3147
- for (let depth = this.open; depth >= 0; depth--) {
3152
+ for (let depth = this.open, penalty = 0; depth >= 0; depth--) {
3148
3153
  let cx = this.nodes[depth];
3149
3154
  let found = cx.findWrapping(node);
3150
- if (found && (!route || route.length > found.length)) {
3155
+ if (found && (!route || route.length > found.length + penalty)) {
3151
3156
  route = found;
3152
3157
  sync = cx;
3153
3158
  if (!found.length)
3154
3159
  break;
3155
3160
  }
3156
- if (cx.solid)
3157
- break;
3161
+ if (cx.solid) {
3162
+ if (cautious)
3163
+ break;
3164
+ penalty += 2;
3165
+ }
3158
3166
  }
3159
3167
  if (!route)
3160
3168
  return null;
@@ -3164,13 +3172,13 @@ class ParseContext {
3164
3172
  return marks;
3165
3173
  }
3166
3174
  // Try to insert the given node, adjusting the context when needed.
3167
- insertNode(node, marks) {
3175
+ insertNode(node, marks, cautious) {
3168
3176
  if (node.isInline && this.needsBlock && !this.top.type) {
3169
3177
  let block = this.textblockFromContext();
3170
3178
  if (block)
3171
3179
  marks = this.enterInner(block, null, marks);
3172
3180
  }
3173
- let innerMarks = this.findPlace(node, marks);
3181
+ let innerMarks = this.findPlace(node, marks, cautious);
3174
3182
  if (innerMarks) {
3175
3183
  this.closeExtra();
3176
3184
  let top = this.top;
@@ -3188,7 +3196,7 @@ class ParseContext {
3188
3196
  // Try to start a node of the given type, adjusting the context when
3189
3197
  // necessary.
3190
3198
  enter(type, attrs, marks, preserveWS) {
3191
- let innerMarks = this.findPlace(type.create(attrs), marks);
3199
+ let innerMarks = this.findPlace(type.create(attrs), marks, false);
3192
3200
  if (innerMarks)
3193
3201
  innerMarks = this.enterInner(type, attrs, marks, true, preserveWS);
3194
3202
  return innerMarks;
@@ -3226,14 +3234,18 @@ class ParseContext {
3226
3234
  finish() {
3227
3235
  this.open = 0;
3228
3236
  this.closeExtra(this.isOpen);
3229
- return this.nodes[0].finish(this.isOpen || this.options.topOpen);
3237
+ return this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));
3230
3238
  }
3231
3239
  sync(to) {
3232
- for (let i = this.open; i >= 0; i--)
3240
+ for (let i = this.open; i >= 0; i--) {
3233
3241
  if (this.nodes[i] == to) {
3234
3242
  this.open = i;
3235
3243
  return true;
3236
3244
  }
3245
+ else if (this.localPreserveWS) {
3246
+ this.nodes[i].options |= OPT_PRESERVE_WS;
3247
+ }
3248
+ }
3237
3249
  return false;
3238
3250
  }
3239
3251
  get currentPos() {
@@ -3302,7 +3314,7 @@ class ParseContext {
3302
3314
  let next = depth > 0 || (depth == 0 && useRoot) ? this.nodes[depth].type
3303
3315
  : option && depth >= minDepth ? option.node(depth - minDepth).type
3304
3316
  : null;
3305
- if (!next || (next.name != part && next.groups.indexOf(part) == -1))
3317
+ if (!next || (next.name != part && !next.isInGroup(part)))
3306
3318
  return false;
3307
3319
  depth--;
3308
3320
  }
@@ -3448,6 +3460,8 @@ class DOMSerializer {
3448
3460
  @internal
3449
3461
  */
3450
3462
  serializeNodeInner(node, options) {
3463
+ if (node.isText)
3464
+ return doc$1(options).createTextNode(node.text);
3451
3465
  let { dom, contentDOM } = renderSpec(doc$1(options), this.nodes[node.type.name](node), null, node.attrs);
3452
3466
  if (contentDOM) {
3453
3467
  if (node.isLeaf)
@@ -3482,6 +3496,9 @@ class DOMSerializer {
3482
3496
  return toDOM && renderSpec(doc$1(options), toDOM(mark, inline), null, mark.attrs);
3483
3497
  }
3484
3498
  static renderSpec(doc, structure, xmlNS = null, blockArraysIn) {
3499
+ // Kludge for backwards-compatibility with accidental original behavious
3500
+ if (typeof structure == "string")
3501
+ return { dom: doc.createTextNode(structure) };
3485
3502
  return renderSpec(doc, structure, xmlNS, blockArraysIn);
3486
3503
  }
3487
3504
  /**
@@ -3553,11 +3570,9 @@ function suspiciousAttributesInner(attrs) {
3553
3570
  return result;
3554
3571
  }
3555
3572
  function renderSpec(doc, structure, xmlNS, blockArraysIn) {
3556
- if (typeof structure == "string")
3557
- return { dom: doc.createTextNode(structure) };
3558
- if (structure.nodeType != null)
3573
+ if (structure.nodeType == 1)
3559
3574
  return { dom: structure };
3560
- if (structure.dom && structure.dom.nodeType != null)
3575
+ if (structure.dom && structure.dom.nodeType == 1)
3561
3576
  return structure;
3562
3577
  let tagName = structure[0], suspicious;
3563
3578
  if (typeof tagName != "string")
@@ -3580,6 +3595,8 @@ function renderSpec(doc, structure, xmlNS, blockArraysIn) {
3580
3595
  let space = name.indexOf(" ");
3581
3596
  if (space > 0)
3582
3597
  dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);
3598
+ else if (name == "style" && dom.style)
3599
+ dom.style.cssText = attrs[name];
3583
3600
  else
3584
3601
  dom.setAttribute(name, attrs[name]);
3585
3602
  }
@@ -3591,6 +3608,9 @@ function renderSpec(doc, structure, xmlNS, blockArraysIn) {
3591
3608
  throw new RangeError("Content hole must be the only child of its parent node");
3592
3609
  return { dom, contentDOM: dom };
3593
3610
  }
3611
+ else if (typeof child == "string") {
3612
+ dom.appendChild(doc.createTextNode(child));
3613
+ }
3594
3614
  else {
3595
3615
  let { dom: inner, contentDOM: innerContent } = renderSpec(doc, child, xmlNS, blockArraysIn);
3596
3616
  dom.appendChild(inner);
@@ -3789,18 +3809,14 @@ A mapping represents a pipeline of zero or more [step
3789
3809
  maps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly
3790
3810
  handling mapping positions through a series of steps in which some
3791
3811
  steps are inverted versions of earlier steps. (This comes up when
3792
- ‘[rebasing](/docs/guide/#transform.rebasing)’ steps for
3812
+ ‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for
3793
3813
  collaboration or history management.)
3794
3814
  */
3795
3815
  class Mapping {
3796
3816
  /**
3797
3817
  Create a new mapping with the given position maps.
3798
3818
  */
3799
- constructor(
3800
- /**
3801
- The step maps in this mapping.
3802
- */
3803
- maps = [],
3819
+ constructor(maps,
3804
3820
  /**
3805
3821
  @internal
3806
3822
  */
@@ -3813,23 +3829,22 @@ class Mapping {
3813
3829
  /**
3814
3830
  The end position in the `maps` array.
3815
3831
  */
3816
- to = maps.length) {
3817
- this.maps = maps;
3832
+ to = maps ? maps.length : 0) {
3818
3833
  this.mirror = mirror;
3819
3834
  this.from = from;
3820
3835
  this.to = to;
3836
+ this._maps = maps || [];
3837
+ this.ownData = !(maps || mirror);
3821
3838
  }
3822
3839
  /**
3823
- Create a mapping that maps only through a part of this one.
3840
+ The step maps in this mapping.
3824
3841
  */
3825
- slice(from = 0, to = this.maps.length) {
3826
- return new Mapping(this.maps, this.mirror, from, to);
3827
- }
3842
+ get maps() { return this._maps; }
3828
3843
  /**
3829
- @internal
3844
+ Create a mapping that maps only through a part of this one.
3830
3845
  */
3831
- copy() {
3832
- return new Mapping(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to);
3846
+ slice(from = 0, to = this.maps.length) {
3847
+ return new Mapping(this._maps, this.mirror, from, to);
3833
3848
  }
3834
3849
  /**
3835
3850
  Add a step map to the end of this mapping. If `mirrors` is
@@ -3837,18 +3852,23 @@ class Mapping {
3837
3852
  image of this one.
3838
3853
  */
3839
3854
  appendMap(map, mirrors) {
3840
- this.to = this.maps.push(map);
3855
+ if (!this.ownData) {
3856
+ this._maps = this._maps.slice();
3857
+ this.mirror = this.mirror && this.mirror.slice();
3858
+ this.ownData = true;
3859
+ }
3860
+ this.to = this._maps.push(map);
3841
3861
  if (mirrors != null)
3842
- this.setMirror(this.maps.length - 1, mirrors);
3862
+ this.setMirror(this._maps.length - 1, mirrors);
3843
3863
  }
3844
3864
  /**
3845
3865
  Add all the step maps in a given mapping to this one (preserving
3846
3866
  mirroring information).
3847
3867
  */
3848
3868
  appendMapping(mapping) {
3849
- for (let i = 0, startSize = this.maps.length; i < mapping.maps.length; i++) {
3869
+ for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {
3850
3870
  let mirr = mapping.getMirror(i);
3851
- this.appendMap(mapping.maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
3871
+ this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);
3852
3872
  }
3853
3873
  }
3854
3874
  /**
@@ -3874,9 +3894,9 @@ class Mapping {
3874
3894
  Append the inverse of the given mapping to this one.
3875
3895
  */
3876
3896
  appendMappingInverted(mapping) {
3877
- for (let i = mapping.maps.length - 1, totalSize = this.maps.length + mapping.maps.length; i >= 0; i--) {
3897
+ for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {
3878
3898
  let mirr = mapping.getMirror(i);
3879
- this.appendMap(mapping.maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
3899
+ this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);
3880
3900
  }
3881
3901
  }
3882
3902
  /**
@@ -3894,7 +3914,7 @@ class Mapping {
3894
3914
  if (this.mirror)
3895
3915
  return this._map(pos, assoc, true);
3896
3916
  for (let i = this.from; i < this.to; i++)
3897
- pos = this.maps[i].map(pos, assoc);
3917
+ pos = this._maps[i].map(pos, assoc);
3898
3918
  return pos;
3899
3919
  }
3900
3920
  /**
@@ -3908,12 +3928,12 @@ class Mapping {
3908
3928
  _map(pos, assoc, simple) {
3909
3929
  let delInfo = 0;
3910
3930
  for (let i = this.from; i < this.to; i++) {
3911
- let map = this.maps[i], result = map.mapResult(pos, assoc);
3931
+ let map = this._maps[i], result = map.mapResult(pos, assoc);
3912
3932
  if (result.recover != null) {
3913
3933
  let corr = this.getMirror(i);
3914
3934
  if (corr != null && corr > i && corr < this.to) {
3915
3935
  i = corr;
3916
- pos = this.maps[corr].recover(result.recover);
3936
+ pos = this._maps[corr].recover(result.recover);
3917
3937
  continue;
3918
3938
  }
3919
3939
  }
@@ -4315,10 +4335,11 @@ class ReplaceStep extends Step {
4315
4335
  return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
4316
4336
  }
4317
4337
  map(mapping) {
4318
- let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
4338
+ let to = mapping.mapResult(this.to, -1);
4339
+ let from = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1);
4319
4340
  if (from.deletedAcross && to.deletedAcross)
4320
4341
  return null;
4321
- return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice);
4342
+ return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
4322
4343
  }
4323
4344
  merge(other) {
4324
4345
  if (!(other instanceof ReplaceStep) || other.structure || this.structure)
@@ -4354,6 +4375,15 @@ class ReplaceStep extends Step {
4354
4375
  return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
4355
4376
  }
4356
4377
  }
4378
+ /**
4379
+ By default, for backwards compatibility, an inserting step
4380
+ mapped over an insertion at that same position fill move after
4381
+ the inserted content. In a collaborative editing situation, that
4382
+ can make redone insertions appear in unexpected places. You can
4383
+ set this to -1 to make such mapping keep the step before the
4384
+ insertion instead.
4385
+ */
4386
+ ReplaceStep.MAP_BIAS = 1;
4357
4387
  Step.jsonID("replace", ReplaceStep);
4358
4388
  /**
4359
4389
  Replace a part of the document with a slice of content, but
@@ -4586,13 +4616,17 @@ can be lifted. Will not go across
4586
4616
  function liftTarget(range) {
4587
4617
  let parent = range.parent;
4588
4618
  let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
4589
- for (let depth = range.depth;; --depth) {
4619
+ for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
4590
4620
  let node = range.$from.node(depth);
4591
- let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
4621
+ let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;
4592
4622
  if (depth < range.depth && node.canReplace(index, endIndex, content))
4593
4623
  return depth;
4594
4624
  if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
4595
4625
  break;
4626
+ if (index)
4627
+ contentBefore = 1;
4628
+ if (endIndex < node.childCount)
4629
+ contentAfter = 1;
4596
4630
  }
4597
4631
  return null;
4598
4632
  }
@@ -5243,7 +5277,7 @@ function replaceRange(tr, from, to, slice) {
5243
5277
  let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
5244
5278
  if (fitsTrivially($from, $to, slice))
5245
5279
  return tr.step(new ReplaceStep(from, to, slice));
5246
- let targetDepths = coveredDepths($from, tr.doc.resolve(to));
5280
+ let targetDepths = coveredDepths($from, $to);
5247
5281
  // Can't replace the whole document, so remove 0 if it's present
5248
5282
  if (targetDepths[targetDepths.length - 1] == 0)
5249
5283
  targetDepths.pop();
@@ -5336,6 +5370,26 @@ function replaceRangeWith(tr, from, to, node) {
5336
5370
  }
5337
5371
  function deleteRange(tr, from, to) {
5338
5372
  let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
5373
+ // When the deleted range spans from the start of one textblock to
5374
+ // the start of another one, move out of the start of both blocks.
5375
+ if ($from.parent.isTextblock && $to.parent.isTextblock && $from.start() != $to.start() &&
5376
+ $from.parentOffset == 0 && $to.parentOffset == 0) {
5377
+ let shared = $from.sharedDepth(to), isolated = false;
5378
+ for (let d = $from.depth; d > shared; d--)
5379
+ if ($from.node(d).type.spec.isolating)
5380
+ isolated = true;
5381
+ for (let d = $to.depth; d > shared; d--)
5382
+ if ($to.node(d).type.spec.isolating)
5383
+ isolated = true;
5384
+ if (!isolated) {
5385
+ for (let d = $from.depth; d > 0 && from == $from.start(d); d--)
5386
+ from = $from.before(d);
5387
+ for (let d = $to.depth; d > 0 && to == $to.start(d); d--)
5388
+ to = $to.before(d);
5389
+ $from = tr.doc.resolve(from);
5390
+ $to = tr.doc.resolve(to);
5391
+ }
5392
+ }
5339
5393
  let covered = coveredDepths($from, $to);
5340
5394
  for (let i = 0; i < covered.length; i++) {
5341
5395
  let depth = covered[i], last = i == covered.length - 1;
@@ -5546,6 +5600,27 @@ class Transform {
5546
5600
  return this.steps.length > 0;
5547
5601
  }
5548
5602
  /**
5603
+ Return a single range, in post-transform document positions,
5604
+ that covers all content changed by this transform. Returns null
5605
+ if no replacements are made. Note that this will ignore changes
5606
+ that add/remove marks without replacing the underlying content.
5607
+ */
5608
+ changedRange() {
5609
+ let from = 1e9, to = -1e9;
5610
+ for (let i = 0; i < this.mapping.maps.length; i++) {
5611
+ let map = this.mapping.maps[i];
5612
+ if (i) {
5613
+ from = map.map(from, 1);
5614
+ to = map.map(to, -1);
5615
+ }
5616
+ map.forEach((_f, _t, fromB, toB) => {
5617
+ from = Math.min(from, fromB);
5618
+ to = Math.max(to, toB);
5619
+ });
5620
+ }
5621
+ return from == 1e9 ? null : { from, to };
5622
+ }
5623
+ /**
5549
5624
  @internal
5550
5625
  */
5551
5626
  addStep(step, doc) {
@@ -5695,19 +5770,26 @@ class Transform {
5695
5770
  return this;
5696
5771
  }
5697
5772
  /**
5698
- Remove a mark (or a mark of the given type) from the node at
5773
+ Remove a mark (or all marks of the given type) from the node at
5699
5774
  position `pos`.
5700
5775
  */
5701
5776
  removeNodeMark(pos, mark) {
5702
- if (!(mark instanceof Mark)) {
5703
- let node = this.doc.nodeAt(pos);
5704
- if (!node)
5705
- throw new RangeError("No node at position " + pos);
5706
- mark = mark.isInSet(node.marks);
5707
- if (!mark)
5708
- return this;
5777
+ let node = this.doc.nodeAt(pos);
5778
+ if (!node)
5779
+ throw new RangeError("No node at position " + pos);
5780
+ if (mark instanceof Mark) {
5781
+ if (mark.isInSet(node.marks))
5782
+ this.step(new RemoveNodeMarkStep(pos, mark));
5783
+ }
5784
+ else {
5785
+ let set = node.marks, found, steps = [];
5786
+ while (found = mark.isInSet(set)) {
5787
+ steps.push(new RemoveNodeMarkStep(pos, found));
5788
+ set = found.removeFromSet(set);
5789
+ }
5790
+ for (let i = steps.length - 1; i >= 0; i--)
5791
+ this.step(steps[i]);
5709
5792
  }
5710
- this.step(new RemoveNodeMarkStep(pos, mark));
5711
5793
  return this;
5712
5794
  }
5713
5795
  /**
@@ -5715,7 +5797,7 @@ class Transform {
5715
5797
  greater than one, any number of nodes above that. By default, the
5716
5798
  parts split off will inherit the node type of the original node.
5717
5799
  This can be changed by passing an array of types and attributes to
5718
- use after the split.
5800
+ use after the split (with the outermost nodes coming first).
5719
5801
  */
5720
5802
  split(pos, depth = 1, typesAfter) {
5721
5803
  split(this, pos, depth, typesAfter);
@@ -6383,7 +6465,6 @@ class Transaction extends Transform {
6383
6465
  else {
6384
6466
  if (to == null)
6385
6467
  to = from;
6386
- to = to == null ? from : to;
6387
6468
  if (!text)
6388
6469
  return this.deleteRange(from, to);
6389
6470
  let marks = this.storedMarks;
@@ -6392,7 +6473,7 @@ class Transaction extends Transform {
6392
6473
  marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));
6393
6474
  }
6394
6475
  this.replaceRangeWith(from, to, schema.text(text, marks));
6395
- if (!this.selection.empty)
6476
+ if (!this.selection.empty && this.selection.to == from + text.length)
6396
6477
  this.setSelection(Selection.near(this.selection.$to));
6397
6478
  return this;
6398
6479
  }
@@ -6588,7 +6669,7 @@ class EditorState {
6588
6669
  return newInstance;
6589
6670
  }
6590
6671
  /**
6591
- Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
6672
+ Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
6592
6673
  */
6593
6674
  get tr() { return new Transaction(this); }
6594
6675
  /**
@@ -6782,6 +6863,7 @@ const isEquivalentPosition = function (node, off, targetNode, targetOff) {
6782
6863
  };
6783
6864
  const atomElements = /^(img|br|input|textarea|hr)$/i;
6784
6865
  function scanFor(node, off, targetNode, targetOff, dir) {
6866
+ var _a;
6785
6867
  for (;;) {
6786
6868
  if (node == targetNode && off == targetOff)
6787
6869
  return true;
@@ -6794,10 +6876,17 @@ function scanFor(node, off, targetNode, targetOff, dir) {
6794
6876
  node = parent;
6795
6877
  }
6796
6878
  else if (node.nodeType == 1) {
6797
- node = node.childNodes[off + (dir < 0 ? -1 : 0)];
6798
- if (node.contentEditable == "false")
6799
- return false;
6800
- off = dir < 0 ? nodeSize(node) : 0;
6879
+ let child = node.childNodes[off + (dir < 0 ? -1 : 0)];
6880
+ if (child.nodeType == 1 && child.contentEditable == "false") {
6881
+ if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection)
6882
+ off += dir;
6883
+ else
6884
+ return false;
6885
+ }
6886
+ else {
6887
+ node = child;
6888
+ off = dir < 0 ? nodeSize(node) : 0;
6889
+ }
6801
6890
  }
6802
6891
  else {
6803
6892
  return false;
@@ -6917,7 +7006,7 @@ const safari = !ie$1 && !!nav && /Apple Computer/.test(nav.vendor);
6917
7006
  // Is true for both iOS and iPadOS for convenience
6918
7007
  const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
6919
7008
  const mac$4 = ios || (nav ? /Mac/.test(nav.platform) : false);
6920
- const windows = nav ? /Win/.test(nav.platform) : false;
7009
+ const windows$1 = nav ? /Win/.test(nav.platform) : false;
6921
7010
  const android = /Android \d/.test(agent);
6922
7011
  const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
6923
7012
  const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
@@ -6947,11 +7036,13 @@ function clientRect(node) {
6947
7036
  function scrollRectIntoView(view, rect, startDOM) {
6948
7037
  let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5;
6949
7038
  let doc = view.dom.ownerDocument;
6950
- for (let parent = startDOM || view.dom;; parent = parentNode(parent)) {
7039
+ for (let parent = startDOM || view.dom;;) {
6951
7040
  if (!parent)
6952
7041
  break;
6953
- if (parent.nodeType != 1)
7042
+ if (parent.nodeType != 1) {
7043
+ parent = parentNode(parent);
6954
7044
  continue;
7045
+ }
6955
7046
  let elt = parent;
6956
7047
  let atTop = elt == doc.body;
6957
7048
  let bounding = atTop ? windowRect(doc) : clientRect(elt);
@@ -6980,8 +7071,10 @@ function scrollRectIntoView(view, rect, startDOM) {
6980
7071
  rect = { left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY };
6981
7072
  }
6982
7073
  }
6983
- if (atTop || /^(fixed|sticky)$/.test(getComputedStyle(parent).position))
7074
+ let pos = atTop ? "fixed" : getComputedStyle(parent).position;
7075
+ if (/^(fixed|sticky)$/.test(pos))
6984
7076
  break;
7077
+ parent = pos == "absolute" ? parent.offsetParent : parentNode(parent);
6985
7078
  }
6986
7079
  }
6987
7080
  // Store the scroll position of the editor's parent nodes, along with
@@ -7101,17 +7194,20 @@ function findOffsetInNode(node, coords) {
7101
7194
  }
7102
7195
  function findOffsetInText(node, coords) {
7103
7196
  let len = node.nodeValue.length;
7104
- let range = document.createRange();
7197
+ let range = document.createRange(), result;
7105
7198
  for (let i = 0; i < len; i++) {
7106
7199
  range.setEnd(node, i + 1);
7107
7200
  range.setStart(node, i);
7108
7201
  let rect = singleRect(range, 1);
7109
7202
  if (rect.top == rect.bottom)
7110
7203
  continue;
7111
- if (inRect(coords, rect))
7112
- return { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) };
7204
+ if (inRect(coords, rect)) {
7205
+ result = { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) };
7206
+ break;
7207
+ }
7113
7208
  }
7114
- return { node, offset: 0 };
7209
+ range.detach();
7210
+ return result || { node, offset: 0 };
7115
7211
  }
7116
7212
  function inRect(coords, rect) {
7117
7213
  return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 &&
@@ -7148,7 +7244,7 @@ function posFromCaret(view, node, offset, coords) {
7148
7244
  if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) &&
7149
7245
  // Ignore elements with zero-size bounding rectangles
7150
7246
  ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
7151
- if (desc.node.isBlock && desc.parent) {
7247
+ if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) {
7152
7248
  // Only apply the horizontal test to the innermost block. Vertical for any parent.
7153
7249
  if (!sawBlock && rect.left > coords.left || rect.top > coords.top)
7154
7250
  outsideBlock = desc.posBefore;
@@ -7806,7 +7902,7 @@ class ViewDesc {
7806
7902
  // (one where the focus is before the anchor), but not all
7807
7903
  // browsers support it yet.
7808
7904
  let domSelExtended = false;
7809
- if ((domSel.extend || anchor == head) && !brKludge) {
7905
+ if ((domSel.extend || anchor == head) && !(brKludge && gecko)) {
7810
7906
  domSel.collapse(anchorDOM.node, anchorDOM.offset);
7811
7907
  try {
7812
7908
  if (anchor != head)
@@ -7876,6 +7972,7 @@ class ViewDesc {
7876
7972
  }
7877
7973
  get domAtom() { return false; }
7878
7974
  get ignoreForCoords() { return false; }
7975
+ get ignoreForSelection() { return false; }
7879
7976
  isText(text) { return false; }
7880
7977
  }
7881
7978
  // A widget desc represents a widget decoration, which is a DOM node
@@ -7920,6 +8017,7 @@ class WidgetViewDesc extends ViewDesc {
7920
8017
  super.destroy();
7921
8018
  }
7922
8019
  get domAtom() { return true; }
8020
+ get ignoreForSelection() { return !!this.widget.type.spec.relaxedSide; }
7923
8021
  get side() { return this.widget.type.side; }
7924
8022
  }
7925
8023
  class CompositionViewDesc extends ViewDesc {
@@ -8105,15 +8203,15 @@ class NodeViewDesc extends ViewDesc {
8105
8203
  let updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
8106
8204
  iterDeco(this.node, this.innerDeco, (widget, i, insideNode) => {
8107
8205
  if (widget.spec.marks)
8108
- updater.syncToMarks(widget.spec.marks, inline, view);
8206
+ updater.syncToMarks(widget.spec.marks, inline, view, i);
8109
8207
  else if (widget.type.side >= 0 && !insideNode)
8110
- updater.syncToMarks(i == this.node.childCount ? Mark.none : this.node.child(i).marks, inline, view);
8208
+ updater.syncToMarks(i == this.node.childCount ? Mark.none : this.node.child(i).marks, inline, view, i);
8111
8209
  // If the next node is a desc matching this widget, reuse it,
8112
8210
  // otherwise insert the widget as a new view desc.
8113
8211
  updater.placeWidget(widget, view, off);
8114
8212
  }, (child, outerDeco, innerDeco, i) => {
8115
8213
  // Make sure the wrapping mark descs match the node's marks.
8116
- updater.syncToMarks(child.marks, inline, view);
8214
+ updater.syncToMarks(child.marks, inline, view, i);
8117
8215
  // Try several strategies for drawing this node
8118
8216
  let compIndex;
8119
8217
  if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ;
@@ -8129,7 +8227,7 @@ class NodeViewDesc extends ViewDesc {
8129
8227
  off += child.nodeSize;
8130
8228
  });
8131
8229
  // Drop all remaining descs after the current position.
8132
- updater.syncToMarks([], inline, view);
8230
+ updater.syncToMarks([], inline, view, 0);
8133
8231
  if (this.node.isTextblock)
8134
8232
  updater.addTextblockHacks();
8135
8233
  updater.destroyRest();
@@ -8216,17 +8314,18 @@ class NodeViewDesc extends ViewDesc {
8216
8314
  }
8217
8315
  // Mark this node as being the selected node.
8218
8316
  selectNode() {
8219
- if (this.nodeDOM.nodeType == 1)
8317
+ if (this.nodeDOM.nodeType == 1) {
8220
8318
  this.nodeDOM.classList.add("ProseMirror-selectednode");
8221
- if (this.contentDOM || !this.node.type.spec.draggable)
8222
- this.dom.draggable = true;
8319
+ if (this.contentDOM || !this.node.type.spec.draggable)
8320
+ this.nodeDOM.draggable = true;
8321
+ }
8223
8322
  }
8224
8323
  // Remove selected node marking from this node.
8225
8324
  deselectNode() {
8226
8325
  if (this.nodeDOM.nodeType == 1) {
8227
8326
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
8228
8327
  if (this.contentDOM || !this.node.type.spec.draggable)
8229
- this.dom.removeAttribute("draggable");
8328
+ this.nodeDOM.removeAttribute("draggable");
8230
8329
  }
8231
8330
  }
8232
8331
  get domAtom() { return this.node.isAtom; }
@@ -8518,7 +8617,7 @@ class ViewTreeUpdater {
8518
8617
  }
8519
8618
  // Sync the current stack of mark descs with the given array of
8520
8619
  // marks, reusing existing mark descs when possible.
8521
- syncToMarks(marks, inline, view) {
8620
+ syncToMarks(marks, inline, view, parentIndex) {
8522
8621
  let keep = 0, depth = this.stack.length >> 1;
8523
8622
  let maxKeep = Math.min(depth, marks.length);
8524
8623
  while (keep < maxKeep &&
@@ -8534,8 +8633,10 @@ class ViewTreeUpdater {
8534
8633
  }
8535
8634
  while (depth < marks.length) {
8536
8635
  this.stack.push(this.top, this.index + 1);
8537
- let found = -1;
8538
- for (let i = this.index; i < Math.min(this.index + 3, this.top.children.length); i++) {
8636
+ let found = -1, scanTo = this.top.children.length;
8637
+ if (parentIndex < this.preMatch.index)
8638
+ scanTo = Math.min(this.index + 3, scanTo);
8639
+ for (let i = this.index; i < scanTo; i++) {
8539
8640
  let next = this.top.children[i];
8540
8641
  if (next.matchesMark(marks[depth]) && !this.isLocked(next.dom)) {
8541
8642
  found = i;
@@ -8731,9 +8832,7 @@ class ViewTreeUpdater {
8731
8832
  }
8732
8833
  // Iterate from the end of the fragment and array of descs to find
8733
8834
  // directly matching ones, in order to avoid overeagerly reusing those
8734
- // for other nodes. Returns the fragment index of the first node that
8735
- // is part of the sequence of matched nodes at the end of the
8736
- // fragment.
8835
+ // for other nodes.
8737
8836
  function preMatch(frag, parentDesc) {
8738
8837
  let curDesc = parentDesc, descI = curDesc.children.length;
8739
8838
  let fI = frag.childCount, matched = new Map, matches = [];
@@ -8756,7 +8855,6 @@ function preMatch(frag, parentDesc) {
8756
8855
  break outer;
8757
8856
  }
8758
8857
  else {
8759
- // FIXME
8760
8858
  descI = curDesc.parent.children.indexOf(curDesc);
8761
8859
  curDesc = curDesc.parent;
8762
8860
  }
@@ -9065,17 +9163,14 @@ function removeClassOnSelectionChange(view) {
9065
9163
  });
9066
9164
  }
9067
9165
  function selectCursorWrapper(view) {
9068
- let domSel = view.domSelection(), range = document.createRange();
9166
+ let domSel = view.domSelection();
9069
9167
  if (!domSel)
9070
9168
  return;
9071
9169
  let node = view.cursorWrapper.dom, img = node.nodeName == "IMG";
9072
9170
  if (img)
9073
- range.setStart(node.parentNode, domIndex(node) + 1);
9171
+ domSel.collapse(node.parentNode, domIndex(node) + 1);
9074
9172
  else
9075
- range.setStart(node, 0);
9076
- range.collapse(true);
9077
- domSel.removeAllRanges();
9078
- domSel.addRange(range);
9173
+ domSel.collapse(node, 0);
9079
9174
  // Kludge to kill 'control selection' in IE11 when selecting an
9080
9175
  // invisible cursor wrapper, since that would result in those weird
9081
9176
  // resize handles and a selection that considers the absolutely
@@ -9383,7 +9478,7 @@ function setSelFocus(view, node, offset) {
9383
9478
  }
9384
9479
  function findDirection(view, pos) {
9385
9480
  let $pos = view.state.doc.resolve(pos);
9386
- if (!(chrome || windows) && $pos.parent.inlineContent) {
9481
+ if (!(chrome || windows$1) && $pos.parent.inlineContent) {
9387
9482
  let coords = view.coordsAtPos(pos);
9388
9483
  if (pos > $pos.start()) {
9389
9484
  let before = view.coordsAtPos(pos - 1);
@@ -9553,11 +9648,14 @@ function parseFromClipboard(view, text, html, plainText, $context) {
9553
9648
  let dom, slice;
9554
9649
  if (!html && !text)
9555
9650
  return null;
9556
- let asText = text && (plainText || inCode || !html);
9651
+ let asText = !!text && (plainText || inCode || !html);
9557
9652
  if (asText) {
9558
9653
  view.someProp("transformPastedText", f => { text = f(text, inCode || plainText, view); });
9559
- if (inCode)
9560
- return text ? new Slice(Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0) : Slice.empty;
9654
+ if (inCode) {
9655
+ slice = new Slice(Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0);
9656
+ view.someProp("transformPasted", f => { slice = f(slice, view, true); });
9657
+ return slice;
9658
+ }
9561
9659
  let parsed = view.someProp("clipboardTextParser", f => f(text, $context, plainText, view));
9562
9660
  if (parsed) {
9563
9661
  slice = parsed;
@@ -9615,7 +9713,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
9615
9713
  slice = closeSlice(slice, openStart, openEnd);
9616
9714
  }
9617
9715
  }
9618
- view.someProp("transformPasted", f => { slice = f(slice, view); });
9716
+ view.someProp("transformPasted", f => { slice = f(slice, view, asText); });
9619
9717
  return slice;
9620
9718
  }
9621
9719
  const inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;
@@ -9726,7 +9824,7 @@ function maybeWrapTrusted(html) {
9726
9824
  // innerHTML, even on a detached document. This wraps the string in
9727
9825
  // a way that makes the browser allow us to use its parser again.
9728
9826
  if (!_policy)
9729
- _policy = trustedTypes.createPolicy("ProseMirrorClipboard", { createHTML: (s) => s });
9827
+ _policy = trustedTypes.defaultPolicy || trustedTypes.createPolicy("ProseMirrorClipboard", { createHTML: (s) => s });
9730
9828
  return _policy.createHTML(html);
9731
9829
  }
9732
9830
  function readHTML(html) {
@@ -9789,7 +9887,7 @@ class InputState {
9789
9887
  this.mouseDown = null;
9790
9888
  this.lastKeyCode = null;
9791
9889
  this.lastKeyCodeTime = 0;
9792
- this.lastClick = { time: 0, x: 0, y: 0, type: "" };
9890
+ this.lastClick = { time: 0, x: 0, y: 0, type: "", button: 0 };
9793
9891
  this.lastSelectionOrigin = null;
9794
9892
  this.lastSelectionTime = 0;
9795
9893
  this.lastIOSEnter = 0;
@@ -9803,6 +9901,7 @@ class InputState {
9803
9901
  this.compositionNodes = [];
9804
9902
  this.compositionEndedAt = -2e8;
9805
9903
  this.compositionID = 1;
9904
+ this.badSafariComposition = false;
9806
9905
  // Set to a composition ID when there are pending changes at compositionend
9807
9906
  this.compositionPendingChanges = 0;
9808
9907
  this.domChangeCount = 0;
@@ -9917,8 +10016,9 @@ editHandlers.keypress = (view, _event) => {
9917
10016
  let sel = view.state.selection;
9918
10017
  if (!(sel instanceof TextSelection) || !sel.$from.sameParent(sel.$to)) {
9919
10018
  let text = String.fromCharCode(event.charCode);
9920
- if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", f => f(view, sel.$from.pos, sel.$to.pos, text)))
9921
- view.dispatch(view.state.tr.insertText(text).scrollIntoView());
10019
+ let deflt = () => view.state.tr.insertText(text).scrollIntoView();
10020
+ if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", f => f(view, sel.$from.pos, sel.$to.pos, text, deflt)))
10021
+ view.dispatch(deflt());
9922
10022
  event.preventDefault();
9923
10023
  }
9924
10024
  };
@@ -10030,13 +10130,14 @@ handlers.mousedown = (view, _event) => {
10030
10130
  view.input.shiftKey = event.shiftKey;
10031
10131
  let flushed = forceDOMFlush(view);
10032
10132
  let now = Date.now(), type = "singleClick";
10033
- if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier]) {
10133
+ if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier] &&
10134
+ view.input.lastClick.button == event.button) {
10034
10135
  if (view.input.lastClick.type == "singleClick")
10035
10136
  type = "doubleClick";
10036
10137
  else if (view.input.lastClick.type == "doubleClick")
10037
10138
  type = "tripleClick";
10038
10139
  }
10039
- view.input.lastClick = { time: now, x: event.clientX, y: event.clientY, type };
10140
+ view.input.lastClick = { time: now, x: event.clientX, y: event.clientY, type, button: event.button };
10040
10141
  let pos = view.posAtCoords(eventCoords(event));
10041
10142
  if (!pos)
10042
10143
  return;
@@ -10075,11 +10176,11 @@ class MouseDown {
10075
10176
  }
10076
10177
  const target = flushed ? null : event.target;
10077
10178
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
10078
- this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
10179
+ this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null;
10079
10180
  let { selection } = view.state;
10080
10181
  if (event.button == 0 &&
10081
- targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
10082
- selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)
10182
+ (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
10183
+ selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos))
10083
10184
  this.mightDrag = {
10084
10185
  node: targetNode,
10085
10186
  pos: targetPos,
@@ -10199,7 +10300,8 @@ editHandlers.compositionstart = editHandlers.compositionupdate = view => {
10199
10300
  let { state } = view, $pos = state.selection.$to;
10200
10301
  if (state.selection instanceof TextSelection &&
10201
10302
  (state.storedMarks ||
10202
- (!$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(m => m.type.spec.inclusive === false)))) {
10303
+ (!$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some(m => m.type.spec.inclusive === false)) ||
10304
+ chrome && windows$1 && selectionBeforeUneditable(view))) { // Issue #1500
10203
10305
  // Need to wrap the cursor in mark nodes different from the ones in the DOM context
10204
10306
  view.markCursor = view.state.storedMarks || $pos.marks();
10205
10307
  endComposition(view, true);
@@ -10233,13 +10335,22 @@ editHandlers.compositionstart = editHandlers.compositionupdate = view => {
10233
10335
  }
10234
10336
  scheduleComposeEnd(view, timeoutComposition);
10235
10337
  };
10338
+ function selectionBeforeUneditable(view) {
10339
+ let { focusNode, focusOffset } = view.domSelectionRange();
10340
+ if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length)
10341
+ return false;
10342
+ let next = focusNode.childNodes[focusOffset];
10343
+ return next.nodeType == 1 && next.contentEditable == "false";
10344
+ }
10236
10345
  editHandlers.compositionend = (view, event) => {
10237
10346
  if (view.composing) {
10238
10347
  view.input.composing = false;
10239
10348
  view.input.compositionEndedAt = event.timeStamp;
10240
10349
  view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0;
10241
10350
  view.input.compositionNode = null;
10242
- if (view.input.compositionPendingChanges)
10351
+ if (view.input.badSafariComposition)
10352
+ view.domObserver.forceFlush();
10353
+ else if (view.input.compositionPendingChanges)
10243
10354
  Promise.resolve().then(() => view.domObserver.flush());
10244
10355
  view.input.compositionID++;
10245
10356
  scheduleComposeEnd(view, 20);
@@ -10293,10 +10404,10 @@ function endComposition(view, restarting = false) {
10293
10404
  view.domObserver.forceFlush();
10294
10405
  clearComposition(view);
10295
10406
  if (restarting || view.docView && view.docView.dirty) {
10296
- let sel = selectionFromDOM(view);
10297
- if (sel && !sel.eq(view.state.selection))
10407
+ let sel = selectionFromDOM(view), cur = view.state.selection;
10408
+ if (sel && !sel.eq(cur))
10298
10409
  view.dispatch(view.state.tr.setSelection(sel));
10299
- else if ((view.markCursor || restarting) && !view.state.selection.empty)
10410
+ else if ((view.markCursor || restarting) && !cur.$from.node(cur.$from.sharedDepth(cur.to)).inlineContent)
10300
10411
  view.dispatch(view.state.tr.deleteSelection());
10301
10412
  else
10302
10413
  view.updateState(view.state);
@@ -10417,6 +10528,11 @@ class Dragging {
10417
10528
  }
10418
10529
  }
10419
10530
  const dragCopyModifier = mac$4 ? "altKey" : "ctrlKey";
10531
+ function dragMoves(view, event) {
10532
+ let copy;
10533
+ view.someProp("dragCopies", test => { copy = copy || test(event); });
10534
+ return copy != null ? !copy : !event[dragCopyModifier];
10535
+ }
10420
10536
  handlers.dragstart = (view, _event) => {
10421
10537
  let event = _event;
10422
10538
  let mouseDown = view.input.mouseDown;
@@ -10442,11 +10558,11 @@ handlers.dragstart = (view, _event) => {
10442
10558
  if (!event.dataTransfer.files.length || !chrome || chrome_version > 120)
10443
10559
  event.dataTransfer.clearData();
10444
10560
  event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML);
10445
- // See https://github.com/ProseMirror/prosemirror/issues/1156
10561
+ // See https://code.haverbeke.berlin/prosemirror/prosemirror/issues/1156
10446
10562
  event.dataTransfer.effectAllowed = "copyMove";
10447
10563
  if (!brokenClipboardAPI)
10448
10564
  event.dataTransfer.setData("text/plain", text);
10449
- view.dragging = new Dragging(slice, !event[dragCopyModifier], node);
10565
+ view.dragging = new Dragging(slice, dragMoves(view, event), node);
10450
10566
  };
10451
10567
  handlers.dragend = view => {
10452
10568
  let dragging = view.dragging;
@@ -10456,10 +10572,15 @@ handlers.dragend = view => {
10456
10572
  }, 50);
10457
10573
  };
10458
10574
  editHandlers.dragover = editHandlers.dragenter = (_, e) => e.preventDefault();
10459
- editHandlers.drop = (view, _event) => {
10460
- let event = _event;
10461
- let dragging = view.dragging;
10462
- view.dragging = null;
10575
+ editHandlers.drop = (view, event) => {
10576
+ try {
10577
+ handleDrop(view, event, view.dragging);
10578
+ }
10579
+ finally {
10580
+ view.dragging = null;
10581
+ }
10582
+ };
10583
+ function handleDrop(view, event, dragging) {
10463
10584
  if (!event.dataTransfer)
10464
10585
  return;
10465
10586
  let eventPos = view.posAtCoords(eventCoords(event));
@@ -10468,12 +10589,12 @@ editHandlers.drop = (view, _event) => {
10468
10589
  let $mouse = view.state.doc.resolve(eventPos.pos);
10469
10590
  let slice = dragging && dragging.slice;
10470
10591
  if (slice) {
10471
- view.someProp("transformPasted", f => { slice = f(slice, view); });
10592
+ view.someProp("transformPasted", f => { slice = f(slice, view, false); });
10472
10593
  }
10473
10594
  else {
10474
10595
  slice = parseFromClipboard(view, getText(event.dataTransfer), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse);
10475
10596
  }
10476
- let move = !!(dragging && !event[dragCopyModifier]);
10597
+ let move = !!(dragging && dragMoves(view, event));
10477
10598
  if (view.someProp("handleDrop", f => f(view, event, slice || Slice.empty, move))) {
10478
10599
  event.preventDefault();
10479
10600
  return;
@@ -10513,7 +10634,7 @@ editHandlers.drop = (view, _event) => {
10513
10634
  }
10514
10635
  view.focus();
10515
10636
  view.dispatch(tr.setMeta("uiEvent", "drop"));
10516
- };
10637
+ }
10517
10638
  handlers.focus = view => {
10518
10639
  view.input.lastFocus = Date.now();
10519
10640
  if (!view.focused) {
@@ -11293,15 +11414,24 @@ class DOMObserver {
11293
11414
  new window.MutationObserver(mutations => {
11294
11415
  for (let i = 0; i < mutations.length; i++)
11295
11416
  this.queue.push(mutations[i]);
11296
- // IE11 will sometimes (on backspacing out a single character
11297
- // text node after a BR node) call the observer callback
11298
- // before actually updating the DOM, which will cause
11299
- // ProseMirror to miss the change (see #930)
11300
11417
  if (ie$1 && ie_version <= 11 && mutations.some(m => m.type == "childList" && m.removedNodes.length ||
11301
- m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length))
11418
+ m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length)) {
11419
+ // IE11 will sometimes (on backspacing out a single character
11420
+ // text node after a BR node) call the observer callback
11421
+ // before actually updating the DOM, which will cause
11422
+ // ProseMirror to miss the change (see #930)
11302
11423
  this.flushSoon();
11303
- else
11424
+ }
11425
+ else if (safari && view.composing && mutations.some(m => m.type == "childList" && m.target.nodeName == "TR")) {
11426
+ // Safari does weird stuff when finishing a composition in a
11427
+ // table cell, which tends to involve inserting inappropriate
11428
+ // nodes in the table row.
11429
+ view.input.badSafariComposition = true;
11430
+ this.flushSoon();
11431
+ }
11432
+ else {
11304
11433
  this.flush();
11434
+ }
11305
11435
  });
11306
11436
  if (useCharData) {
11307
11437
  this.onCharData = e => {
@@ -11421,7 +11551,22 @@ class DOMObserver {
11421
11551
  }
11422
11552
  }
11423
11553
  }
11424
- if (gecko && added.length) {
11554
+ if (added.some(n => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) {
11555
+ // Browsers sometimes insert a bogus break node if you
11556
+ // backspace out the last bit of text before an inline-flex node (#1552)
11557
+ for (let node of added)
11558
+ if (node.nodeName == "BR" && node.parentNode) {
11559
+ let after = node.nextSibling;
11560
+ while (after && after.nodeType == 1) {
11561
+ if (after.contentEditable == "false") {
11562
+ node.parentNode.removeChild(node);
11563
+ break;
11564
+ }
11565
+ after = after.firstChild;
11566
+ }
11567
+ }
11568
+ }
11569
+ else if (gecko && added.length) {
11425
11570
  let brs = added.filter(n => n.nodeName == "BR");
11426
11571
  if (brs.length == 2) {
11427
11572
  let [a, b] = brs;
@@ -11457,6 +11602,10 @@ class DOMObserver {
11457
11602
  view.docView.markDirty(from, to);
11458
11603
  checkCSS(view);
11459
11604
  }
11605
+ if (view.input.badSafariComposition) {
11606
+ view.input.badSafariComposition = false;
11607
+ fixUpBadSafariComposition(view, added);
11608
+ }
11460
11609
  this.handleDOMChange(from, to, typeOver, added);
11461
11610
  if (view.docView && view.docView.dirty)
11462
11611
  view.updateState(view.state);
@@ -11580,6 +11729,37 @@ function blockParent(view, node) {
11580
11729
  }
11581
11730
  return null;
11582
11731
  }
11732
+ // Kludge for a Safari bug where, on ending a composition in an
11733
+ // otherwise empty table cell, it randomly moves the composed text
11734
+ // into the table row around that cell, greatly confusing everything
11735
+ // (#188).
11736
+ function fixUpBadSafariComposition(view, addedNodes) {
11737
+ var _a;
11738
+ let { focusNode, focusOffset } = view.domSelectionRange();
11739
+ for (let node of addedNodes) {
11740
+ if (((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName) == "TR") {
11741
+ let nextCell = node.nextSibling;
11742
+ while (nextCell && (nextCell.nodeName != "TD" && nextCell.nodeName != "TH"))
11743
+ nextCell = nextCell.nextSibling;
11744
+ if (nextCell) {
11745
+ let parent = nextCell;
11746
+ for (;;) {
11747
+ let first = parent.firstChild;
11748
+ if (!first || first.nodeType != 1 || first.contentEditable == "false" ||
11749
+ /^(BR|IMG)$/.test(first.nodeName))
11750
+ break;
11751
+ parent = first;
11752
+ }
11753
+ parent.insertBefore(node, parent.firstChild);
11754
+ if (focusNode == node)
11755
+ view.domSelection().collapse(node, focusOffset);
11756
+ }
11757
+ else {
11758
+ node.parentNode.removeChild(node);
11759
+ }
11760
+ }
11761
+ }
11762
+ }
11583
11763
 
11584
11764
  // Note that all referencing and parsing is done with the
11585
11765
  // start-of-operation selection and document, since that's the one
@@ -11654,7 +11834,7 @@ function ruleFromNode(dom) {
11654
11834
  }
11655
11835
  return null;
11656
11836
  }
11657
- const isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
11837
+ const isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
11658
11838
  function readDOMChange(view, from, to, typeOver, addedNodes) {
11659
11839
  let compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0);
11660
11840
  view.input.compositionPendingChanges = 0;
@@ -11753,14 +11933,13 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
11753
11933
  let $to = parse.doc.resolveNoCache(change.endB - parse.from);
11754
11934
  let $fromA = doc.resolve(change.start);
11755
11935
  let inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
11756
- let nextSel;
11757
11936
  // If this looks like the effect of pressing Enter (or was recorded
11758
11937
  // as being an iOS enter press), just dispatch an Enter key instead.
11759
11938
  if (((ios && view.input.lastIOSEnter > Date.now() - 225 &&
11760
11939
  (!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) ||
11761
- (!inlineChange && $from.pos < parse.doc.content.size && !$from.sameParent($to) &&
11762
- (nextSel = Selection.findFrom(parse.doc.resolve($from.pos + 1), 1, true)) &&
11763
- nextSel.head == $to.pos)) &&
11940
+ (!inlineChange && $from.pos < parse.doc.content.size &&
11941
+ (!$from.sameParent($to) || !$from.parent.inlineContent) &&
11942
+ $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", "")))) &&
11764
11943
  view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
11765
11944
  view.input.lastIOSEnter = 0;
11766
11945
  return;
@@ -11795,7 +11974,26 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
11795
11974
  }, 20);
11796
11975
  }
11797
11976
  let chFrom = change.start, chTo = change.endA;
11798
- let tr, storedMarks, markChange;
11977
+ let mkTr = (base) => {
11978
+ let tr = base || view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from));
11979
+ if (parse.sel) {
11980
+ let sel = resolveSelection(view, tr.doc, parse.sel);
11981
+ // Chrome will sometimes, during composition, report the
11982
+ // selection in the wrong place. If it looks like that is
11983
+ // happening, don't update the selection.
11984
+ // Edge just doesn't move the cursor forward when you start typing
11985
+ // in an empty block or between br nodes.
11986
+ if (sel && !(chrome && view.composing && sel.empty &&
11987
+ (change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) &&
11988
+ (sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1) ||
11989
+ ie$1 && sel.empty && sel.head == chFrom))
11990
+ tr.setSelection(sel);
11991
+ }
11992
+ if (compositionID)
11993
+ tr.setMeta("composition", compositionID);
11994
+ return tr.scrollIntoView();
11995
+ };
11996
+ let markChange;
11799
11997
  if (inlineChange) {
11800
11998
  if ($from.pos == $to.pos) { // Deletion
11801
11999
  // IE11 sometimes weirdly moves the DOM selection around after
@@ -11804,46 +12002,36 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
11804
12002
  view.domObserver.suppressSelectionUpdates();
11805
12003
  setTimeout(() => selectionToDOM(view), 20);
11806
12004
  }
11807
- tr = view.state.tr.delete(chFrom, chTo);
11808
- storedMarks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA));
12005
+ let tr = mkTr(view.state.tr.delete(chFrom, chTo));
12006
+ let marks = doc.resolve(change.start).marksAcross(doc.resolve(change.endA));
12007
+ if (marks)
12008
+ tr.ensureMarks(marks);
12009
+ view.dispatch(tr);
11809
12010
  }
11810
12011
  else if ( // Adding or removing a mark
11811
12012
  change.endA == change.endB &&
11812
12013
  (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), $fromA.parent.content.cut($fromA.parentOffset, change.endA - $fromA.start())))) {
11813
- tr = view.state.tr;
12014
+ let tr = mkTr(view.state.tr);
11814
12015
  if (markChange.type == "add")
11815
12016
  tr.addMark(chFrom, chTo, markChange.mark);
11816
12017
  else
11817
12018
  tr.removeMark(chFrom, chTo, markChange.mark);
12019
+ view.dispatch(tr);
11818
12020
  }
11819
12021
  else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) {
11820
12022
  // Both positions in the same text node -- simply insert text
11821
12023
  let text = $from.parent.textBetween($from.parentOffset, $to.parentOffset);
11822
- if (view.someProp("handleTextInput", f => f(view, chFrom, chTo, text)))
11823
- return;
11824
- tr = view.state.tr.insertText(text, chFrom, chTo);
11825
- }
11826
- }
11827
- if (!tr)
11828
- tr = view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from));
11829
- if (parse.sel) {
11830
- let sel = resolveSelection(view, tr.doc, parse.sel);
11831
- // Chrome will sometimes, during composition, report the
11832
- // selection in the wrong place. If it looks like that is
11833
- // happening, don't update the selection.
11834
- // Edge just doesn't move the cursor forward when you start typing
11835
- // in an empty block or between br nodes.
11836
- if (sel && !(chrome && view.composing && sel.empty &&
11837
- (change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) &&
11838
- (sel.head == chFrom || sel.head == tr.mapping.map(chTo) - 1) ||
11839
- ie$1 && sel.empty && sel.head == chFrom))
11840
- tr.setSelection(sel);
11841
- }
11842
- if (storedMarks)
11843
- tr.ensureMarks(storedMarks);
11844
- if (compositionID)
11845
- tr.setMeta("composition", compositionID);
11846
- view.dispatch(tr.scrollIntoView());
12024
+ let deflt = () => mkTr(view.state.tr.insertText(text, chFrom, chTo));
12025
+ if (!view.someProp("handleTextInput", f => f(view, chFrom, chTo, text, deflt)))
12026
+ view.dispatch(deflt());
12027
+ }
12028
+ else {
12029
+ view.dispatch(mkTr());
12030
+ }
12031
+ }
12032
+ else {
12033
+ view.dispatch(mkTr());
12034
+ }
11847
12035
  }
11848
12036
  function resolveSelection(view, doc, parsedSel) {
11849
12037
  if (Math.max(parsedSel.anchor, parsedSel.head) > doc.content.size)
@@ -11995,7 +12183,7 @@ class EditorView {
11995
12183
  this.pluginViews = [];
11996
12184
  /**
11997
12185
  Holds `true` when a hack node is needed in Firefox to prevent the
11998
- [space is eaten issue](https://github.com/ProseMirror/prosemirror/issues/651)
12186
+ [space is eaten issue](https://code.haverbeke.berlin/prosemirror/prosemirror/issues/651)
11999
12187
  @internal
12000
12188
  */
12001
12189
  this.requiresGeckoHackNode = false;
@@ -12135,7 +12323,7 @@ class EditorView {
12135
12323
  this.docView.destroy();
12136
12324
  this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this);
12137
12325
  }
12138
- if (chromeKludge && !this.trackWrites)
12326
+ if (chromeKludge && (!this.trackWrites || !this.dom.contains(this.trackWrites)))
12139
12327
  forceSelUpdate = true;
12140
12328
  }
12141
12329
  // Work around for an issue where an update arriving right between
@@ -12213,12 +12401,12 @@ class EditorView {
12213
12401
  }
12214
12402
  updateDraggedNode(dragging, prev) {
12215
12403
  let sel = dragging.node, found = -1;
12216
- if (this.state.doc.nodeAt(sel.from) == sel.node) {
12404
+ if (sel.from < this.state.doc.content.size && this.state.doc.nodeAt(sel.from) == sel.node) {
12217
12405
  found = sel.from;
12218
12406
  }
12219
12407
  else {
12220
12408
  let movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size);
12221
- let moved = movedPos > 0 && this.state.doc.nodeAt(movedPos);
12409
+ let moved = movedPos > 0 && movedPos < this.state.doc.content.size && this.state.doc.nodeAt(movedPos);
12222
12410
  if (moved == sel.node)
12223
12411
  found = movedPos;
12224
12412
  }
@@ -12392,6 +12580,17 @@ class EditorView {
12392
12580
  return doPaste(this, text, null, true, event || new ClipboardEvent("paste"));
12393
12581
  }
12394
12582
  /**
12583
+ Serialize the given slice as it would be if it was copied from
12584
+ this editor. Returns a DOM element that contains a
12585
+ representation of the slice as its children, a textual
12586
+ representation, and the transformed slice (which can be
12587
+ different from the given input due to hooks like
12588
+ [`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)).
12589
+ */
12590
+ serializeForClipboard(slice) {
12591
+ return serializeForClipboard(this, slice);
12592
+ }
12593
+ /**
12395
12594
  Removes the editor from the DOM and destroys all [node
12396
12595
  views](https://prosemirror.net/docs/ref/#view.NodeView).
12397
12596
  */
@@ -12426,22 +12625,6 @@ class EditorView {
12426
12625
  return dispatchEvent(this, event);
12427
12626
  }
12428
12627
  /**
12429
- Dispatch a transaction. Will call
12430
- [`dispatchTransaction`](https://prosemirror.net/docs/ref/#view.DirectEditorProps.dispatchTransaction)
12431
- when given, and otherwise defaults to applying the transaction to
12432
- the current state and calling
12433
- [`updateState`](https://prosemirror.net/docs/ref/#view.EditorView.updateState) with the result.
12434
- This method is bound to the view instance, so that it can be
12435
- easily passed around.
12436
- */
12437
- dispatch(tr) {
12438
- let dispatchTransaction = this._props.dispatchTransaction;
12439
- if (dispatchTransaction)
12440
- dispatchTransaction.call(this, tr);
12441
- else
12442
- this.updateState(this.state.apply(tr));
12443
- }
12444
- /**
12445
12628
  @internal
12446
12629
  */
12447
12630
  domSelectionRange() {
@@ -12458,6 +12641,13 @@ class EditorView {
12458
12641
  return this.root.getSelection();
12459
12642
  }
12460
12643
  }
12644
+ EditorView.prototype.dispatch = function (tr) {
12645
+ let dispatchTransaction = this._props.dispatchTransaction;
12646
+ if (dispatchTransaction)
12647
+ dispatchTransaction.call(this, tr);
12648
+ else
12649
+ this.updateState(this.state.apply(tr));
12650
+ };
12461
12651
  function computeDocDeco(view) {
12462
12652
  let attrs = Object.create(null);
12463
12653
  attrs.class = "ProseMirror";
@@ -13078,7 +13268,8 @@ function keyName(event) {
13078
13268
  return name
13079
13269
  }
13080
13270
 
13081
- const mac$2 = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false;
13271
+ const mac$2 = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
13272
+ const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
13082
13273
  function normalizeKeyName(name) {
13083
13274
  let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
13084
13275
  if (result == "Space")
@@ -13184,12 +13375,14 @@ function keydownHandler(bindings) {
13184
13375
  if (noShift && noShift(view.state, view.dispatch, view))
13185
13376
  return true;
13186
13377
  }
13187
- if ((event.shiftKey || event.altKey || event.metaKey || name.charCodeAt(0) > 127) &&
13378
+ if ((event.altKey || event.metaKey || event.ctrlKey) &&
13379
+ // Ctrl-Alt may be used for AltGr on Windows
13380
+ !(windows && event.ctrlKey && event.altKey) &&
13188
13381
  (baseName = base$1[event.keyCode]) && baseName != name) {
13189
13382
  // Try falling back to the keyCode when there's a modifier
13190
13383
  // active or the character produced isn't ASCII, and our table
13191
13384
  // produces a different name from the the keyCode. See #668,
13192
- // #1060
13385
+ // #1060, #1529.
13193
13386
  let fromCode = map[modifiers(baseName, event)];
13194
13387
  if (fromCode && fromCode(view.state, view.dispatch, view))
13195
13388
  return true;
@@ -24226,8 +24419,7 @@ class MarkdownSerializerState {
24226
24419
  }
24227
24420
  if (node && node.isText && marks.some(mark => {
24228
24421
  let info = this.getMark(mark.type.name);
24229
- return info && info.expelEnclosingWhitespace &&
24230
- (index == parent.childCount - 1 || !mark.isInSet(parent.child(index + 1).marks));
24422
+ return info && info.expelEnclosingWhitespace && !this.isMarkAhead(parent, index + 1, mark);
24231
24423
  })) {
24232
24424
  let [_, rest, trail] = /^(.*?)(\s*)$/m.exec(node.text);
24233
24425
  if (trail) {
@@ -24371,6 +24563,19 @@ class MarkdownSerializerState {
24371
24563
  trailing: (text.match(/(\s+)$/) || [undefined])[0]
24372
24564
  };
24373
24565
  }
24566
+ /**
24567
+ @internal
24568
+ */
24569
+ isMarkAhead(parent, index, mark) {
24570
+ for (;; index++) {
24571
+ if (index >= parent.childCount)
24572
+ return false;
24573
+ let next = parent.child(index);
24574
+ if (next.type.name != this.options.hardBreakNodeName)
24575
+ return mark.isInSet(next.marks);
24576
+ index++;
24577
+ }
24578
+ }
24374
24579
  }
24375
24580
 
24376
24581
  const imageCache = new Map();
@@ -25697,1354 +25902,1248 @@ const createTriggerPlugin = (triggerCharacters, contentConverter) => {
25697
25902
  });
25698
25903
  };
25699
25904
 
25700
- // src/index.ts
25701
-
25702
- // src/tablemap.ts
25703
- var readFromCache;
25704
- var addToCache;
25905
+ //#region src/tablemap.ts
25906
+ let readFromCache;
25907
+ let addToCache;
25705
25908
  if (typeof WeakMap != "undefined") {
25706
- let cache = /* @__PURE__ */ new WeakMap();
25707
- readFromCache = (key) => cache.get(key);
25708
- addToCache = (key, value) => {
25709
- cache.set(key, value);
25710
- return value;
25711
- };
25909
+ let cache = /* @__PURE__ */ new WeakMap();
25910
+ readFromCache = (key) => cache.get(key);
25911
+ addToCache = (key, value) => {
25912
+ cache.set(key, value);
25913
+ return value;
25914
+ };
25712
25915
  } else {
25713
- const cache = [];
25714
- const cacheSize = 10;
25715
- let cachePos = 0;
25716
- readFromCache = (key) => {
25717
- for (let i = 0; i < cache.length; i += 2)
25718
- if (cache[i] == key) return cache[i + 1];
25719
- };
25720
- addToCache = (key, value) => {
25721
- if (cachePos == cacheSize) cachePos = 0;
25722
- cache[cachePos++] = key;
25723
- return cache[cachePos++] = value;
25724
- };
25916
+ const cache = [];
25917
+ const cacheSize = 10;
25918
+ let cachePos = 0;
25919
+ readFromCache = (key) => {
25920
+ for (let i = 0; i < cache.length; i += 2) if (cache[i] == key) return cache[i + 1];
25921
+ };
25922
+ addToCache = (key, value) => {
25923
+ if (cachePos == cacheSize) cachePos = 0;
25924
+ cache[cachePos++] = key;
25925
+ return cache[cachePos++] = value;
25926
+ };
25725
25927
  }
25928
+ /**
25929
+ * A table map describes the structure of a given table. To avoid
25930
+ * recomputing them all the time, they are cached per table node. To
25931
+ * be able to do that, positions saved in the map are relative to the
25932
+ * start of the table, rather than the start of the document.
25933
+ *
25934
+ * @public
25935
+ */
25726
25936
  var TableMap = class {
25727
- constructor(width, height, map, problems) {
25728
- this.width = width;
25729
- this.height = height;
25730
- this.map = map;
25731
- this.problems = problems;
25732
- }
25733
- // Find the dimensions of the cell at the given position.
25734
- findCell(pos) {
25735
- for (let i = 0; i < this.map.length; i++) {
25736
- const curPos = this.map[i];
25737
- if (curPos != pos) continue;
25738
- const left = i % this.width;
25739
- const top = i / this.width | 0;
25740
- let right = left + 1;
25741
- let bottom = top + 1;
25742
- for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) {
25743
- right++;
25744
- }
25745
- for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) {
25746
- bottom++;
25747
- }
25748
- return { left, top, right, bottom };
25749
- }
25750
- throw new RangeError(`No cell with offset ${pos} found`);
25751
- }
25752
- // Find the left side of the cell at the given position.
25753
- colCount(pos) {
25754
- for (let i = 0; i < this.map.length; i++) {
25755
- if (this.map[i] == pos) {
25756
- return i % this.width;
25757
- }
25758
- }
25759
- throw new RangeError(`No cell with offset ${pos} found`);
25760
- }
25761
- // Find the next cell in the given direction, starting from the cell
25762
- // at `pos`, if any.
25763
- nextCell(pos, axis, dir) {
25764
- const { left, right, top, bottom } = this.findCell(pos);
25765
- if (axis == "horiz") {
25766
- if (dir < 0 ? left == 0 : right == this.width) return null;
25767
- return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
25768
- } else {
25769
- if (dir < 0 ? top == 0 : bottom == this.height) return null;
25770
- return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
25771
- }
25772
- }
25773
- // Get the rectangle spanning the two given cells.
25774
- rectBetween(a, b) {
25775
- const {
25776
- left: leftA,
25777
- right: rightA,
25778
- top: topA,
25779
- bottom: bottomA
25780
- } = this.findCell(a);
25781
- const {
25782
- left: leftB,
25783
- right: rightB,
25784
- top: topB,
25785
- bottom: bottomB
25786
- } = this.findCell(b);
25787
- return {
25788
- left: Math.min(leftA, leftB),
25789
- top: Math.min(topA, topB),
25790
- right: Math.max(rightA, rightB),
25791
- bottom: Math.max(bottomA, bottomB)
25792
- };
25793
- }
25794
- // Return the position of all cells that have the top left corner in
25795
- // the given rectangle.
25796
- cellsInRect(rect) {
25797
- const result = [];
25798
- const seen = {};
25799
- for (let row = rect.top; row < rect.bottom; row++) {
25800
- for (let col = rect.left; col < rect.right; col++) {
25801
- const index = row * this.width + col;
25802
- const pos = this.map[index];
25803
- if (seen[pos]) continue;
25804
- seen[pos] = true;
25805
- if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) {
25806
- continue;
25807
- }
25808
- result.push(pos);
25809
- }
25810
- }
25811
- return result;
25812
- }
25813
- // Return the position at which the cell at the given row and column
25814
- // starts, or would start, if a cell started there.
25815
- positionAt(row, col, table) {
25816
- for (let i = 0, rowStart = 0; ; i++) {
25817
- const rowEnd = rowStart + table.child(i).nodeSize;
25818
- if (i == row) {
25819
- let index = col + row * this.width;
25820
- const rowEndIndex = (row + 1) * this.width;
25821
- while (index < rowEndIndex && this.map[index] < rowStart) index++;
25822
- return index == rowEndIndex ? rowEnd - 1 : this.map[index];
25823
- }
25824
- rowStart = rowEnd;
25825
- }
25826
- }
25827
- // Find the table map for the given table node.
25828
- static get(table) {
25829
- return readFromCache(table) || addToCache(table, computeMap(table));
25830
- }
25937
+ constructor(width, height, map, problems) {
25938
+ this.width = width;
25939
+ this.height = height;
25940
+ this.map = map;
25941
+ this.problems = problems;
25942
+ }
25943
+ findCell(pos) {
25944
+ for (let i = 0; i < this.map.length; i++) {
25945
+ const curPos = this.map[i];
25946
+ if (curPos != pos) continue;
25947
+ const left = i % this.width;
25948
+ const top = i / this.width | 0;
25949
+ let right = left + 1;
25950
+ let bottom = top + 1;
25951
+ for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) right++;
25952
+ for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) bottom++;
25953
+ return {
25954
+ left,
25955
+ top,
25956
+ right,
25957
+ bottom
25958
+ };
25959
+ }
25960
+ throw new RangeError(`No cell with offset ${pos} found`);
25961
+ }
25962
+ colCount(pos) {
25963
+ for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;
25964
+ throw new RangeError(`No cell with offset ${pos} found`);
25965
+ }
25966
+ nextCell(pos, axis, dir) {
25967
+ const { left, right, top, bottom } = this.findCell(pos);
25968
+ if (axis == "horiz") {
25969
+ if (dir < 0 ? left == 0 : right == this.width) return null;
25970
+ return this.map[top * this.width + (dir < 0 ? left - 1 : right)];
25971
+ } else {
25972
+ if (dir < 0 ? top == 0 : bottom == this.height) return null;
25973
+ return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];
25974
+ }
25975
+ }
25976
+ rectBetween(a, b) {
25977
+ const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);
25978
+ const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b);
25979
+ return {
25980
+ left: Math.min(leftA, leftB),
25981
+ top: Math.min(topA, topB),
25982
+ right: Math.max(rightA, rightB),
25983
+ bottom: Math.max(bottomA, bottomB)
25984
+ };
25985
+ }
25986
+ cellsInRect(rect) {
25987
+ const result = [];
25988
+ const seen = {};
25989
+ for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {
25990
+ const index = row * this.width + col;
25991
+ const pos = this.map[index];
25992
+ if (seen[pos]) continue;
25993
+ seen[pos] = true;
25994
+ if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) continue;
25995
+ result.push(pos);
25996
+ }
25997
+ return result;
25998
+ }
25999
+ positionAt(row, col, table) {
26000
+ for (let i = 0, rowStart = 0;; i++) {
26001
+ const rowEnd = rowStart + table.child(i).nodeSize;
26002
+ if (i == row) {
26003
+ let index = col + row * this.width;
26004
+ const rowEndIndex = (row + 1) * this.width;
26005
+ while (index < rowEndIndex && this.map[index] < rowStart) index++;
26006
+ return index == rowEndIndex ? rowEnd - 1 : this.map[index];
26007
+ }
26008
+ rowStart = rowEnd;
26009
+ }
26010
+ }
26011
+ static get(table) {
26012
+ return readFromCache(table) || addToCache(table, computeMap(table));
26013
+ }
25831
26014
  };
25832
26015
  function computeMap(table) {
25833
- if (table.type.spec.tableRole != "table")
25834
- throw new RangeError("Not a table node: " + table.type.name);
25835
- const width = findWidth(table), height = table.childCount;
25836
- const map = [];
25837
- let mapPos = 0;
25838
- let problems = null;
25839
- const colWidths = [];
25840
- for (let i = 0, e = width * height; i < e; i++) map[i] = 0;
25841
- for (let row = 0, pos = 0; row < height; row++) {
25842
- const rowNode = table.child(row);
25843
- pos++;
25844
- for (let i = 0; ; i++) {
25845
- while (mapPos < map.length && map[mapPos] != 0) mapPos++;
25846
- if (i == rowNode.childCount) break;
25847
- const cellNode = rowNode.child(i);
25848
- const { colspan, rowspan, colwidth } = cellNode.attrs;
25849
- for (let h = 0; h < rowspan; h++) {
25850
- if (h + row >= height) {
25851
- (problems || (problems = [])).push({
25852
- type: "overlong_rowspan",
25853
- pos,
25854
- n: rowspan - h
25855
- });
25856
- break;
25857
- }
25858
- const start = mapPos + h * width;
25859
- for (let w = 0; w < colspan; w++) {
25860
- if (map[start + w] == 0) map[start + w] = pos;
25861
- else
25862
- (problems || (problems = [])).push({
25863
- type: "collision",
25864
- row,
25865
- pos,
25866
- n: colspan - w
25867
- });
25868
- const colW = colwidth && colwidth[w];
25869
- if (colW) {
25870
- const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];
25871
- if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
25872
- colWidths[widthIndex] = colW;
25873
- colWidths[widthIndex + 1] = 1;
25874
- } else if (prev == colW) {
25875
- colWidths[widthIndex + 1]++;
25876
- }
25877
- }
25878
- }
25879
- }
25880
- mapPos += colspan;
25881
- pos += cellNode.nodeSize;
25882
- }
25883
- const expectedPos = (row + 1) * width;
25884
- let missing = 0;
25885
- while (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;
25886
- if (missing)
25887
- (problems || (problems = [])).push({ type: "missing", row, n: missing });
25888
- pos++;
25889
- }
25890
- if (width === 0 || height === 0)
25891
- (problems || (problems = [])).push({ type: "zero_sized" });
25892
- const tableMap = new TableMap(width, height, map, problems);
25893
- let badWidths = false;
25894
- for (let i = 0; !badWidths && i < colWidths.length; i += 2)
25895
- if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
25896
- if (badWidths) findBadColWidths(tableMap, colWidths, table);
25897
- return tableMap;
26016
+ if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name);
26017
+ const width = findWidth(table), height = table.childCount;
26018
+ const map = [];
26019
+ let mapPos = 0;
26020
+ let problems = null;
26021
+ const colWidths = [];
26022
+ for (let i = 0, e = width * height; i < e; i++) map[i] = 0;
26023
+ for (let row = 0, pos = 0; row < height; row++) {
26024
+ const rowNode = table.child(row);
26025
+ pos++;
26026
+ for (let i = 0;; i++) {
26027
+ while (mapPos < map.length && map[mapPos] != 0) mapPos++;
26028
+ if (i == rowNode.childCount) break;
26029
+ const cellNode = rowNode.child(i);
26030
+ const { colspan, rowspan, colwidth } = cellNode.attrs;
26031
+ for (let h = 0; h < rowspan; h++) {
26032
+ if (h + row >= height) {
26033
+ (problems || (problems = [])).push({
26034
+ type: "overlong_rowspan",
26035
+ pos,
26036
+ n: rowspan - h
26037
+ });
26038
+ break;
26039
+ }
26040
+ const start = mapPos + h * width;
26041
+ for (let w = 0; w < colspan; w++) {
26042
+ if (map[start + w] == 0) map[start + w] = pos;
26043
+ else (problems || (problems = [])).push({
26044
+ type: "collision",
26045
+ row,
26046
+ pos,
26047
+ n: colspan - w
26048
+ });
26049
+ const colW = colwidth && colwidth[w];
26050
+ if (colW) {
26051
+ const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];
26052
+ if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {
26053
+ colWidths[widthIndex] = colW;
26054
+ colWidths[widthIndex + 1] = 1;
26055
+ } else if (prev == colW) colWidths[widthIndex + 1]++;
26056
+ }
26057
+ }
26058
+ }
26059
+ mapPos += colspan;
26060
+ pos += cellNode.nodeSize;
26061
+ }
26062
+ const expectedPos = (row + 1) * width;
26063
+ let missing = 0;
26064
+ while (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;
26065
+ if (missing) (problems || (problems = [])).push({
26066
+ type: "missing",
26067
+ row,
26068
+ n: missing
26069
+ });
26070
+ pos++;
26071
+ }
26072
+ if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" });
26073
+ const tableMap = new TableMap(width, height, map, problems);
26074
+ let badWidths = false;
26075
+ for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;
26076
+ if (badWidths) findBadColWidths(tableMap, colWidths, table);
26077
+ return tableMap;
25898
26078
  }
25899
26079
  function findWidth(table) {
25900
- let width = -1;
25901
- let hasRowSpan = false;
25902
- for (let row = 0; row < table.childCount; row++) {
25903
- const rowNode = table.child(row);
25904
- let rowWidth = 0;
25905
- if (hasRowSpan)
25906
- for (let j = 0; j < row; j++) {
25907
- const prevRow = table.child(j);
25908
- for (let i = 0; i < prevRow.childCount; i++) {
25909
- const cell = prevRow.child(i);
25910
- if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
25911
- }
25912
- }
25913
- for (let i = 0; i < rowNode.childCount; i++) {
25914
- const cell = rowNode.child(i);
25915
- rowWidth += cell.attrs.colspan;
25916
- if (cell.attrs.rowspan > 1) hasRowSpan = true;
25917
- }
25918
- if (width == -1) width = rowWidth;
25919
- else if (width != rowWidth) width = Math.max(width, rowWidth);
25920
- }
25921
- return width;
26080
+ let width = -1;
26081
+ let hasRowSpan = false;
26082
+ for (let row = 0; row < table.childCount; row++) {
26083
+ const rowNode = table.child(row);
26084
+ let rowWidth = 0;
26085
+ if (hasRowSpan) for (let j = 0; j < row; j++) {
26086
+ const prevRow = table.child(j);
26087
+ for (let i = 0; i < prevRow.childCount; i++) {
26088
+ const cell = prevRow.child(i);
26089
+ if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;
26090
+ }
26091
+ }
26092
+ for (let i = 0; i < rowNode.childCount; i++) {
26093
+ const cell = rowNode.child(i);
26094
+ rowWidth += cell.attrs.colspan;
26095
+ if (cell.attrs.rowspan > 1) hasRowSpan = true;
26096
+ }
26097
+ if (width == -1) width = rowWidth;
26098
+ else if (width != rowWidth) width = Math.max(width, rowWidth);
26099
+ }
26100
+ return width;
25922
26101
  }
25923
26102
  function findBadColWidths(map, colWidths, table) {
25924
- if (!map.problems) map.problems = [];
25925
- const seen = {};
25926
- for (let i = 0; i < map.map.length; i++) {
25927
- const pos = map.map[i];
25928
- if (seen[pos]) continue;
25929
- seen[pos] = true;
25930
- const node = table.nodeAt(pos);
25931
- if (!node) {
25932
- throw new RangeError(`No cell with offset ${pos} found`);
25933
- }
25934
- let updated = null;
25935
- const attrs = node.attrs;
25936
- for (let j = 0; j < attrs.colspan; j++) {
25937
- const col = (i + j) % map.width;
25938
- const colWidth = colWidths[col * 2];
25939
- if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))
25940
- (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
25941
- }
25942
- if (updated)
25943
- map.problems.unshift({
25944
- type: "colwidth mismatch",
25945
- pos,
25946
- colwidth: updated
25947
- });
25948
- }
26103
+ if (!map.problems) map.problems = [];
26104
+ const seen = {};
26105
+ for (let i = 0; i < map.map.length; i++) {
26106
+ const pos = map.map[i];
26107
+ if (seen[pos]) continue;
26108
+ seen[pos] = true;
26109
+ const node = table.nodeAt(pos);
26110
+ if (!node) throw new RangeError(`No cell with offset ${pos} found`);
26111
+ let updated = null;
26112
+ const attrs = node.attrs;
26113
+ for (let j = 0; j < attrs.colspan; j++) {
26114
+ const colWidth = colWidths[(i + j) % map.width * 2];
26115
+ if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth;
26116
+ }
26117
+ if (updated) map.problems.unshift({
26118
+ type: "colwidth mismatch",
26119
+ pos,
26120
+ colwidth: updated
26121
+ });
26122
+ }
25949
26123
  }
25950
26124
  function freshColWidth(attrs) {
25951
- if (attrs.colwidth) return attrs.colwidth.slice();
25952
- const result = [];
25953
- for (let i = 0; i < attrs.colspan; i++) result.push(0);
25954
- return result;
26125
+ if (attrs.colwidth) return attrs.colwidth.slice();
26126
+ const result = [];
26127
+ for (let i = 0; i < attrs.colspan; i++) result.push(0);
26128
+ return result;
25955
26129
  }
25956
26130
 
25957
- // src/schema.ts
26131
+ //#endregion
26132
+ //#region src/schema.ts
25958
26133
  function getCellAttrs(dom, extraAttrs) {
25959
- if (typeof dom === "string") {
25960
- return {};
25961
- }
25962
- const widthAttr = dom.getAttribute("data-colwidth");
25963
- const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
25964
- const colspan = Number(dom.getAttribute("colspan") || 1);
25965
- const result = {
25966
- colspan,
25967
- rowspan: Number(dom.getAttribute("rowspan") || 1),
25968
- colwidth: widths && widths.length == colspan ? widths : null
25969
- };
25970
- for (const prop in extraAttrs) {
25971
- const getter = extraAttrs[prop].getFromDOM;
25972
- const value = getter && getter(dom);
25973
- if (value != null) {
25974
- result[prop] = value;
25975
- }
25976
- }
25977
- return result;
26134
+ if (typeof dom === "string") return {};
26135
+ const widthAttr = dom.getAttribute("data-colwidth");
26136
+ const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
26137
+ const colspan = Number(dom.getAttribute("colspan") || 1);
26138
+ const result = {
26139
+ colspan,
26140
+ rowspan: Number(dom.getAttribute("rowspan") || 1),
26141
+ colwidth: widths && widths.length == colspan ? widths : null
26142
+ };
26143
+ for (const prop in extraAttrs) {
26144
+ const getter = extraAttrs[prop].getFromDOM;
26145
+ const value = getter && getter(dom);
26146
+ if (value != null) result[prop] = value;
26147
+ }
26148
+ return result;
25978
26149
  }
25979
26150
  function setCellAttrs(node, extraAttrs) {
25980
- const attrs = {};
25981
- if (node.attrs.colspan != 1) attrs.colspan = node.attrs.colspan;
25982
- if (node.attrs.rowspan != 1) attrs.rowspan = node.attrs.rowspan;
25983
- if (node.attrs.colwidth)
25984
- attrs["data-colwidth"] = node.attrs.colwidth.join(",");
25985
- for (const prop in extraAttrs) {
25986
- const setter = extraAttrs[prop].setDOMAttr;
25987
- if (setter) setter(node.attrs[prop], attrs);
25988
- }
25989
- return attrs;
26151
+ const attrs = {};
26152
+ if (node.attrs.colspan != 1) attrs.colspan = node.attrs.colspan;
26153
+ if (node.attrs.rowspan != 1) attrs.rowspan = node.attrs.rowspan;
26154
+ if (node.attrs.colwidth) attrs["data-colwidth"] = node.attrs.colwidth.join(",");
26155
+ for (const prop in extraAttrs) {
26156
+ const setter = extraAttrs[prop].setDOMAttr;
26157
+ if (setter) setter(node.attrs[prop], attrs);
26158
+ }
26159
+ return attrs;
26160
+ }
26161
+ function validateColwidth(value) {
26162
+ if (value === null) return;
26163
+ if (!Array.isArray(value)) throw new TypeError("colwidth must be null or an array");
26164
+ for (const item of value) if (typeof item !== "number") throw new TypeError("colwidth must be null or an array of numbers");
25990
26165
  }
26166
+ /**
26167
+ * This function creates a set of [node
26168
+ * specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for
26169
+ * `table`, `table_row`, and `table_cell` nodes types as used by this
26170
+ * module. The result can then be added to the set of nodes when
26171
+ * creating a schema.
26172
+ *
26173
+ * @public
26174
+ */
25991
26175
  function tableNodes(options) {
25992
- const extraAttrs = options.cellAttributes || {};
25993
- const cellAttrs = {
25994
- colspan: { default: 1 },
25995
- rowspan: { default: 1 },
25996
- colwidth: { default: null }
25997
- };
25998
- for (const prop in extraAttrs)
25999
- cellAttrs[prop] = { default: extraAttrs[prop].default };
26000
- return {
26001
- table: {
26002
- content: "table_row+",
26003
- tableRole: "table",
26004
- isolating: true,
26005
- group: options.tableGroup,
26006
- parseDOM: [{ tag: "table" }],
26007
- toDOM() {
26008
- return ["table", ["tbody", 0]];
26009
- }
26010
- },
26011
- table_row: {
26012
- content: "(table_cell | table_header)*",
26013
- tableRole: "row",
26014
- parseDOM: [{ tag: "tr" }],
26015
- toDOM() {
26016
- return ["tr", 0];
26017
- }
26018
- },
26019
- table_cell: {
26020
- content: options.cellContent,
26021
- attrs: cellAttrs,
26022
- tableRole: "cell",
26023
- isolating: true,
26024
- parseDOM: [
26025
- { tag: "td", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }
26026
- ],
26027
- toDOM(node) {
26028
- return ["td", setCellAttrs(node, extraAttrs), 0];
26029
- }
26030
- },
26031
- table_header: {
26032
- content: options.cellContent,
26033
- attrs: cellAttrs,
26034
- tableRole: "header_cell",
26035
- isolating: true,
26036
- parseDOM: [
26037
- { tag: "th", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }
26038
- ],
26039
- toDOM(node) {
26040
- return ["th", setCellAttrs(node, extraAttrs), 0];
26041
- }
26042
- }
26043
- };
26176
+ const extraAttrs = options.cellAttributes || {};
26177
+ const cellAttrs = {
26178
+ colspan: {
26179
+ default: 1,
26180
+ validate: "number"
26181
+ },
26182
+ rowspan: {
26183
+ default: 1,
26184
+ validate: "number"
26185
+ },
26186
+ colwidth: {
26187
+ default: null,
26188
+ validate: validateColwidth
26189
+ }
26190
+ };
26191
+ for (const prop in extraAttrs) cellAttrs[prop] = {
26192
+ default: extraAttrs[prop].default,
26193
+ validate: extraAttrs[prop].validate
26194
+ };
26195
+ return {
26196
+ table: {
26197
+ content: "table_row+",
26198
+ tableRole: "table",
26199
+ isolating: true,
26200
+ group: options.tableGroup,
26201
+ parseDOM: [{ tag: "table" }],
26202
+ toDOM() {
26203
+ return ["table", ["tbody", 0]];
26204
+ }
26205
+ },
26206
+ table_row: {
26207
+ content: "(table_cell | table_header)*",
26208
+ tableRole: "row",
26209
+ parseDOM: [{ tag: "tr" }],
26210
+ toDOM() {
26211
+ return ["tr", 0];
26212
+ }
26213
+ },
26214
+ table_cell: {
26215
+ content: options.cellContent,
26216
+ attrs: cellAttrs,
26217
+ tableRole: "cell",
26218
+ isolating: true,
26219
+ parseDOM: [{
26220
+ tag: "td",
26221
+ getAttrs: (dom) => getCellAttrs(dom, extraAttrs)
26222
+ }],
26223
+ toDOM(node) {
26224
+ return [
26225
+ "td",
26226
+ setCellAttrs(node, extraAttrs),
26227
+ 0
26228
+ ];
26229
+ }
26230
+ },
26231
+ table_header: {
26232
+ content: options.cellContent,
26233
+ attrs: cellAttrs,
26234
+ tableRole: "header_cell",
26235
+ isolating: true,
26236
+ parseDOM: [{
26237
+ tag: "th",
26238
+ getAttrs: (dom) => getCellAttrs(dom, extraAttrs)
26239
+ }],
26240
+ toDOM(node) {
26241
+ return [
26242
+ "th",
26243
+ setCellAttrs(node, extraAttrs),
26244
+ 0
26245
+ ];
26246
+ }
26247
+ }
26248
+ };
26044
26249
  }
26250
+ /**
26251
+ * @public
26252
+ */
26045
26253
  function tableNodeTypes(schema) {
26046
- let result = schema.cached.tableNodeTypes;
26047
- if (!result) {
26048
- result = schema.cached.tableNodeTypes = {};
26049
- for (const name in schema.nodes) {
26050
- const type = schema.nodes[name], role = type.spec.tableRole;
26051
- if (role) result[role] = type;
26052
- }
26053
- }
26054
- return result;
26254
+ let result = schema.cached.tableNodeTypes;
26255
+ if (!result) {
26256
+ result = schema.cached.tableNodeTypes = {};
26257
+ for (const name in schema.nodes) {
26258
+ const type = schema.nodes[name], role = type.spec.tableRole;
26259
+ if (role) result[role] = type;
26260
+ }
26261
+ }
26262
+ return result;
26055
26263
  }
26056
26264
 
26057
- // src/util.ts
26058
- var tableEditingKey = new PluginKey("selectingCells");
26059
- function cellAround($pos) {
26060
- for (let d = $pos.depth - 1; d > 0; d--)
26061
- if ($pos.node(d).type.spec.tableRole == "row")
26062
- return $pos.node(0).resolve($pos.before(d + 1));
26063
- return null;
26265
+ //#endregion
26266
+ //#region src/util.ts
26267
+ /**
26268
+ * @public
26269
+ */
26270
+ const tableEditingKey = new PluginKey("selectingCells");
26271
+ /**
26272
+ * @public
26273
+ */
26274
+ function cellAround($pos) {
26275
+ for (let d = $pos.depth - 1; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1));
26276
+ return null;
26064
26277
  }
26278
+ /**
26279
+ * @public
26280
+ */
26065
26281
  function isInTable(state) {
26066
- const $head = state.selection.$head;
26067
- for (let d = $head.depth; d > 0; d--)
26068
- if ($head.node(d).type.spec.tableRole == "row") return true;
26069
- return false;
26282
+ const $head = state.selection.$head;
26283
+ for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true;
26284
+ return false;
26070
26285
  }
26286
+ /**
26287
+ * @internal
26288
+ */
26071
26289
  function selectionCell(state) {
26072
- const sel = state.selection;
26073
- if ("$anchorCell" in sel && sel.$anchorCell) {
26074
- return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
26075
- } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
26076
- return sel.$anchor;
26077
- }
26078
- const $cell = cellAround(sel.$head) || cellNear(sel.$head);
26079
- if ($cell) {
26080
- return $cell;
26081
- }
26082
- throw new RangeError(`No cell found around position ${sel.head}`);
26290
+ const sel = state.selection;
26291
+ if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
26292
+ else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor;
26293
+ const $cell = cellAround(sel.$head) || cellNear(sel.$head);
26294
+ if ($cell) return $cell;
26295
+ throw new RangeError(`No cell found around position ${sel.head}`);
26083
26296
  }
26297
+ /**
26298
+ * @public
26299
+ */
26084
26300
  function cellNear($pos) {
26085
- for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
26086
- const role = after.type.spec.tableRole;
26087
- if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos);
26088
- }
26089
- for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
26090
- const role = before.type.spec.tableRole;
26091
- if (role == "cell" || role == "header_cell")
26092
- return $pos.doc.resolve(pos - before.nodeSize);
26093
- }
26301
+ for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
26302
+ const role = after.type.spec.tableRole;
26303
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos);
26304
+ }
26305
+ for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
26306
+ const role = before.type.spec.tableRole;
26307
+ if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize);
26308
+ }
26094
26309
  }
26310
+ /**
26311
+ * @public
26312
+ */
26095
26313
  function pointsAtCell($pos) {
26096
- return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
26314
+ return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter;
26097
26315
  }
26316
+ /**
26317
+ * @internal
26318
+ */
26098
26319
  function inSameTable($cellA, $cellB) {
26099
- return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
26320
+ return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);
26100
26321
  }
26322
+ /**
26323
+ * @public
26324
+ */
26101
26325
  function nextCell($pos, axis, dir) {
26102
- const table = $pos.node(-1);
26103
- const map = TableMap.get(table);
26104
- const tableStart = $pos.start(-1);
26105
- const moved = map.nextCell($pos.pos - tableStart, axis, dir);
26106
- return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
26326
+ const table = $pos.node(-1);
26327
+ const map = TableMap.get(table);
26328
+ const tableStart = $pos.start(-1);
26329
+ const moved = map.nextCell($pos.pos - tableStart, axis, dir);
26330
+ return moved == null ? null : $pos.node(0).resolve(tableStart + moved);
26107
26331
  }
26332
+ /**
26333
+ * @public
26334
+ */
26108
26335
  function removeColSpan(attrs, pos, n = 1) {
26109
- const result = { ...attrs, colspan: attrs.colspan - n };
26110
- if (result.colwidth) {
26111
- result.colwidth = result.colwidth.slice();
26112
- result.colwidth.splice(pos, n);
26113
- if (!result.colwidth.some((w) => w > 0)) result.colwidth = null;
26114
- }
26115
- return result;
26116
- }
26117
-
26118
- // src/cellselection.ts
26119
- var CellSelection = class _CellSelection extends Selection {
26120
- // A table selection is identified by its anchor and head cells. The
26121
- // positions given to this constructor should point _before_ two
26122
- // cells in the same table. They may be the same, to select a single
26123
- // cell.
26124
- constructor($anchorCell, $headCell = $anchorCell) {
26125
- const table = $anchorCell.node(-1);
26126
- const map = TableMap.get(table);
26127
- const tableStart = $anchorCell.start(-1);
26128
- const rect = map.rectBetween(
26129
- $anchorCell.pos - tableStart,
26130
- $headCell.pos - tableStart
26131
- );
26132
- const doc = $anchorCell.node(0);
26133
- const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
26134
- cells.unshift($headCell.pos - tableStart);
26135
- const ranges = cells.map((pos) => {
26136
- const cell = table.nodeAt(pos);
26137
- if (!cell) {
26138
- throw RangeError(`No cell with offset ${pos} found`);
26139
- }
26140
- const from = tableStart + pos + 1;
26141
- return new SelectionRange(
26142
- doc.resolve(from),
26143
- doc.resolve(from + cell.content.size)
26144
- );
26145
- });
26146
- super(ranges[0].$from, ranges[0].$to, ranges);
26147
- this.$anchorCell = $anchorCell;
26148
- this.$headCell = $headCell;
26149
- }
26150
- map(doc, mapping) {
26151
- const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
26152
- const $headCell = doc.resolve(mapping.map(this.$headCell.pos));
26153
- if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
26154
- const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
26155
- if (tableChanged && this.isRowSelection())
26156
- return _CellSelection.rowSelection($anchorCell, $headCell);
26157
- else if (tableChanged && this.isColSelection())
26158
- return _CellSelection.colSelection($anchorCell, $headCell);
26159
- else return new _CellSelection($anchorCell, $headCell);
26160
- }
26161
- return TextSelection.between($anchorCell, $headCell);
26162
- }
26163
- // Returns a rectangular slice of table rows containing the selected
26164
- // cells.
26165
- content() {
26166
- const table = this.$anchorCell.node(-1);
26167
- const map = TableMap.get(table);
26168
- const tableStart = this.$anchorCell.start(-1);
26169
- const rect = map.rectBetween(
26170
- this.$anchorCell.pos - tableStart,
26171
- this.$headCell.pos - tableStart
26172
- );
26173
- const seen = {};
26174
- const rows = [];
26175
- for (let row = rect.top; row < rect.bottom; row++) {
26176
- const rowContent = [];
26177
- for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
26178
- const pos = map.map[index];
26179
- if (seen[pos]) continue;
26180
- seen[pos] = true;
26181
- const cellRect = map.findCell(pos);
26182
- let cell = table.nodeAt(pos);
26183
- if (!cell) {
26184
- throw RangeError(`No cell with offset ${pos} found`);
26185
- }
26186
- const extraLeft = rect.left - cellRect.left;
26187
- const extraRight = cellRect.right - rect.right;
26188
- if (extraLeft > 0 || extraRight > 0) {
26189
- let attrs = cell.attrs;
26190
- if (extraLeft > 0) {
26191
- attrs = removeColSpan(attrs, 0, extraLeft);
26192
- }
26193
- if (extraRight > 0) {
26194
- attrs = removeColSpan(
26195
- attrs,
26196
- attrs.colspan - extraRight,
26197
- extraRight
26198
- );
26199
- }
26200
- if (cellRect.left < rect.left) {
26201
- cell = cell.type.createAndFill(attrs);
26202
- if (!cell) {
26203
- throw RangeError(
26204
- `Could not create cell with attrs ${JSON.stringify(attrs)}`
26205
- );
26206
- }
26207
- } else {
26208
- cell = cell.type.create(attrs, cell.content);
26209
- }
26210
- }
26211
- if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
26212
- const attrs = {
26213
- ...cell.attrs,
26214
- rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
26215
- };
26216
- if (cellRect.top < rect.top) {
26217
- cell = cell.type.createAndFill(attrs);
26218
- } else {
26219
- cell = cell.type.create(attrs, cell.content);
26220
- }
26221
- }
26222
- rowContent.push(cell);
26223
- }
26224
- rows.push(table.child(row).copy(Fragment.from(rowContent)));
26225
- }
26226
- const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
26227
- return new Slice(Fragment.from(fragment), 1, 1);
26228
- }
26229
- replace(tr, content = Slice.empty) {
26230
- const mapFrom = tr.steps.length, ranges = this.ranges;
26231
- for (let i = 0; i < ranges.length; i++) {
26232
- const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
26233
- tr.replace(
26234
- mapping.map($from.pos),
26235
- mapping.map($to.pos),
26236
- i ? Slice.empty : content
26237
- );
26238
- }
26239
- const sel = Selection.findFrom(
26240
- tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),
26241
- -1
26242
- );
26243
- if (sel) tr.setSelection(sel);
26244
- }
26245
- replaceWith(tr, node) {
26246
- this.replace(tr, new Slice(Fragment.from(node), 0, 0));
26247
- }
26248
- forEachCell(f) {
26249
- const table = this.$anchorCell.node(-1);
26250
- const map = TableMap.get(table);
26251
- const tableStart = this.$anchorCell.start(-1);
26252
- const cells = map.cellsInRect(
26253
- map.rectBetween(
26254
- this.$anchorCell.pos - tableStart,
26255
- this.$headCell.pos - tableStart
26256
- )
26257
- );
26258
- for (let i = 0; i < cells.length; i++) {
26259
- f(table.nodeAt(cells[i]), tableStart + cells[i]);
26260
- }
26261
- }
26262
- // True if this selection goes all the way from the top to the
26263
- // bottom of the table.
26264
- isColSelection() {
26265
- const anchorTop = this.$anchorCell.index(-1);
26266
- const headTop = this.$headCell.index(-1);
26267
- if (Math.min(anchorTop, headTop) > 0) return false;
26268
- const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
26269
- const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
26270
- return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
26271
- }
26272
- // Returns the smallest column selection that covers the given anchor
26273
- // and head cell.
26274
- static colSelection($anchorCell, $headCell = $anchorCell) {
26275
- const table = $anchorCell.node(-1);
26276
- const map = TableMap.get(table);
26277
- const tableStart = $anchorCell.start(-1);
26278
- const anchorRect = map.findCell($anchorCell.pos - tableStart);
26279
- const headRect = map.findCell($headCell.pos - tableStart);
26280
- const doc = $anchorCell.node(0);
26281
- if (anchorRect.top <= headRect.top) {
26282
- if (anchorRect.top > 0)
26283
- $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);
26284
- if (headRect.bottom < map.height)
26285
- $headCell = doc.resolve(
26286
- tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]
26287
- );
26288
- } else {
26289
- if (headRect.top > 0)
26290
- $headCell = doc.resolve(tableStart + map.map[headRect.left]);
26291
- if (anchorRect.bottom < map.height)
26292
- $anchorCell = doc.resolve(
26293
- tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]
26294
- );
26295
- }
26296
- return new _CellSelection($anchorCell, $headCell);
26297
- }
26298
- // True if this selection goes all the way from the left to the
26299
- // right of the table.
26300
- isRowSelection() {
26301
- const table = this.$anchorCell.node(-1);
26302
- const map = TableMap.get(table);
26303
- const tableStart = this.$anchorCell.start(-1);
26304
- const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);
26305
- const headLeft = map.colCount(this.$headCell.pos - tableStart);
26306
- if (Math.min(anchorLeft, headLeft) > 0) return false;
26307
- const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
26308
- const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
26309
- return Math.max(anchorRight, headRight) == map.width;
26310
- }
26311
- eq(other) {
26312
- return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
26313
- }
26314
- // Returns the smallest row selection that covers the given anchor
26315
- // and head cell.
26316
- static rowSelection($anchorCell, $headCell = $anchorCell) {
26317
- const table = $anchorCell.node(-1);
26318
- const map = TableMap.get(table);
26319
- const tableStart = $anchorCell.start(-1);
26320
- const anchorRect = map.findCell($anchorCell.pos - tableStart);
26321
- const headRect = map.findCell($headCell.pos - tableStart);
26322
- const doc = $anchorCell.node(0);
26323
- if (anchorRect.left <= headRect.left) {
26324
- if (anchorRect.left > 0)
26325
- $anchorCell = doc.resolve(
26326
- tableStart + map.map[anchorRect.top * map.width]
26327
- );
26328
- if (headRect.right < map.width)
26329
- $headCell = doc.resolve(
26330
- tableStart + map.map[map.width * (headRect.top + 1) - 1]
26331
- );
26332
- } else {
26333
- if (headRect.left > 0)
26334
- $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);
26335
- if (anchorRect.right < map.width)
26336
- $anchorCell = doc.resolve(
26337
- tableStart + map.map[map.width * (anchorRect.top + 1) - 1]
26338
- );
26339
- }
26340
- return new _CellSelection($anchorCell, $headCell);
26341
- }
26342
- toJSON() {
26343
- return {
26344
- type: "cell",
26345
- anchor: this.$anchorCell.pos,
26346
- head: this.$headCell.pos
26347
- };
26348
- }
26349
- static fromJSON(doc, json) {
26350
- return new _CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
26351
- }
26352
- static create(doc, anchorCell, headCell = anchorCell) {
26353
- return new _CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
26354
- }
26355
- getBookmark() {
26356
- return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
26357
- }
26336
+ const result = {
26337
+ ...attrs,
26338
+ colspan: attrs.colspan - n
26339
+ };
26340
+ if (result.colwidth) {
26341
+ result.colwidth = result.colwidth.slice();
26342
+ result.colwidth.splice(pos, n);
26343
+ if (!result.colwidth.some((w) => w > 0)) result.colwidth = null;
26344
+ }
26345
+ return result;
26346
+ }
26347
+
26348
+ //#endregion
26349
+ //#region src/cellselection.ts
26350
+ /**
26351
+ * A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
26352
+ * subclass that represents a cell selection spanning part of a table.
26353
+ * With the plugin enabled, these will be created when the user
26354
+ * selects across cells, and will be drawn by giving selected cells a
26355
+ * `selectedCell` CSS class.
26356
+ *
26357
+ * @public
26358
+ */
26359
+ var CellSelection = class CellSelection extends Selection {
26360
+ constructor($anchorCell, $headCell = $anchorCell) {
26361
+ const table = $anchorCell.node(-1);
26362
+ const map = TableMap.get(table);
26363
+ const tableStart = $anchorCell.start(-1);
26364
+ const rect = map.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);
26365
+ const doc = $anchorCell.node(0);
26366
+ const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);
26367
+ cells.unshift($headCell.pos - tableStart);
26368
+ const ranges = cells.map((pos) => {
26369
+ const cell = table.nodeAt(pos);
26370
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
26371
+ const from = tableStart + pos + 1;
26372
+ return new SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));
26373
+ });
26374
+ super(ranges[0].$from, ranges[0].$to, ranges);
26375
+ this.$anchorCell = $anchorCell;
26376
+ this.$headCell = $headCell;
26377
+ }
26378
+ map(doc, mapping) {
26379
+ const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));
26380
+ const $headCell = doc.resolve(mapping.map(this.$headCell.pos));
26381
+ if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {
26382
+ const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);
26383
+ if (tableChanged && this.isRowSelection()) return CellSelection.rowSelection($anchorCell, $headCell);
26384
+ else if (tableChanged && this.isColSelection()) return CellSelection.colSelection($anchorCell, $headCell);
26385
+ else return new CellSelection($anchorCell, $headCell);
26386
+ }
26387
+ return TextSelection.between($anchorCell, $headCell);
26388
+ }
26389
+ content() {
26390
+ const table = this.$anchorCell.node(-1);
26391
+ const map = TableMap.get(table);
26392
+ const tableStart = this.$anchorCell.start(-1);
26393
+ const rect = map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);
26394
+ const seen = {};
26395
+ const rows = [];
26396
+ for (let row = rect.top; row < rect.bottom; row++) {
26397
+ const rowContent = [];
26398
+ for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {
26399
+ const pos = map.map[index];
26400
+ if (seen[pos]) continue;
26401
+ seen[pos] = true;
26402
+ const cellRect = map.findCell(pos);
26403
+ let cell = table.nodeAt(pos);
26404
+ if (!cell) throw new RangeError(`No cell with offset ${pos} found`);
26405
+ const extraLeft = rect.left - cellRect.left;
26406
+ const extraRight = cellRect.right - rect.right;
26407
+ if (extraLeft > 0 || extraRight > 0) {
26408
+ let attrs = cell.attrs;
26409
+ if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);
26410
+ if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);
26411
+ if (cellRect.left < rect.left) {
26412
+ cell = cell.type.createAndFill(attrs);
26413
+ if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);
26414
+ } else cell = cell.type.create(attrs, cell.content);
26415
+ }
26416
+ if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {
26417
+ const attrs = {
26418
+ ...cell.attrs,
26419
+ rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)
26420
+ };
26421
+ if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);
26422
+ else cell = cell.type.create(attrs, cell.content);
26423
+ }
26424
+ rowContent.push(cell);
26425
+ }
26426
+ rows.push(table.child(row).copy(Fragment.from(rowContent)));
26427
+ }
26428
+ const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;
26429
+ return new Slice(Fragment.from(fragment), 1, 1);
26430
+ }
26431
+ replace(tr, content = Slice.empty) {
26432
+ const mapFrom = tr.steps.length, ranges = this.ranges;
26433
+ for (let i = 0; i < ranges.length; i++) {
26434
+ const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
26435
+ tr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
26436
+ }
26437
+ const sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);
26438
+ if (sel) tr.setSelection(sel);
26439
+ }
26440
+ replaceWith(tr, node) {
26441
+ this.replace(tr, new Slice(Fragment.from(node), 0, 0));
26442
+ }
26443
+ forEachCell(f) {
26444
+ const table = this.$anchorCell.node(-1);
26445
+ const map = TableMap.get(table);
26446
+ const tableStart = this.$anchorCell.start(-1);
26447
+ const cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));
26448
+ for (let i = 0; i < cells.length; i++) f(table.nodeAt(cells[i]), tableStart + cells[i]);
26449
+ }
26450
+ isColSelection() {
26451
+ const anchorTop = this.$anchorCell.index(-1);
26452
+ const headTop = this.$headCell.index(-1);
26453
+ if (Math.min(anchorTop, headTop) > 0) return false;
26454
+ const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;
26455
+ const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;
26456
+ return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;
26457
+ }
26458
+ static colSelection($anchorCell, $headCell = $anchorCell) {
26459
+ const table = $anchorCell.node(-1);
26460
+ const map = TableMap.get(table);
26461
+ const tableStart = $anchorCell.start(-1);
26462
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
26463
+ const headRect = map.findCell($headCell.pos - tableStart);
26464
+ const doc = $anchorCell.node(0);
26465
+ if (anchorRect.top <= headRect.top) {
26466
+ if (anchorRect.top > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);
26467
+ if (headRect.bottom < map.height) $headCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]);
26468
+ } else {
26469
+ if (headRect.top > 0) $headCell = doc.resolve(tableStart + map.map[headRect.left]);
26470
+ if (anchorRect.bottom < map.height) $anchorCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]);
26471
+ }
26472
+ return new CellSelection($anchorCell, $headCell);
26473
+ }
26474
+ isRowSelection() {
26475
+ const table = this.$anchorCell.node(-1);
26476
+ const map = TableMap.get(table);
26477
+ const tableStart = this.$anchorCell.start(-1);
26478
+ const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);
26479
+ const headLeft = map.colCount(this.$headCell.pos - tableStart);
26480
+ if (Math.min(anchorLeft, headLeft) > 0) return false;
26481
+ const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;
26482
+ const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;
26483
+ return Math.max(anchorRight, headRight) == map.width;
26484
+ }
26485
+ eq(other) {
26486
+ return other instanceof CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;
26487
+ }
26488
+ static rowSelection($anchorCell, $headCell = $anchorCell) {
26489
+ const table = $anchorCell.node(-1);
26490
+ const map = TableMap.get(table);
26491
+ const tableStart = $anchorCell.start(-1);
26492
+ const anchorRect = map.findCell($anchorCell.pos - tableStart);
26493
+ const headRect = map.findCell($headCell.pos - tableStart);
26494
+ const doc = $anchorCell.node(0);
26495
+ if (anchorRect.left <= headRect.left) {
26496
+ if (anchorRect.left > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.top * map.width]);
26497
+ if (headRect.right < map.width) $headCell = doc.resolve(tableStart + map.map[map.width * (headRect.top + 1) - 1]);
26498
+ } else {
26499
+ if (headRect.left > 0) $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);
26500
+ if (anchorRect.right < map.width) $anchorCell = doc.resolve(tableStart + map.map[map.width * (anchorRect.top + 1) - 1]);
26501
+ }
26502
+ return new CellSelection($anchorCell, $headCell);
26503
+ }
26504
+ toJSON() {
26505
+ return {
26506
+ type: "cell",
26507
+ anchor: this.$anchorCell.pos,
26508
+ head: this.$headCell.pos
26509
+ };
26510
+ }
26511
+ static fromJSON(doc, json) {
26512
+ return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));
26513
+ }
26514
+ static create(doc, anchorCell, headCell = anchorCell) {
26515
+ return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));
26516
+ }
26517
+ getBookmark() {
26518
+ return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);
26519
+ }
26358
26520
  };
26359
26521
  CellSelection.prototype.visible = false;
26360
26522
  Selection.jsonID("cell", CellSelection);
26361
- var CellBookmark = class _CellBookmark {
26362
- constructor(anchor, head) {
26363
- this.anchor = anchor;
26364
- this.head = head;
26365
- }
26366
- map(mapping) {
26367
- return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
26368
- }
26369
- resolve(doc) {
26370
- const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
26371
- 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))
26372
- return new CellSelection($anchorCell, $headCell);
26373
- else return Selection.near($headCell, 1);
26374
- }
26523
+ /**
26524
+ * @public
26525
+ */
26526
+ var CellBookmark = class CellBookmark {
26527
+ constructor(anchor, head) {
26528
+ this.anchor = anchor;
26529
+ this.head = head;
26530
+ }
26531
+ map(mapping) {
26532
+ return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
26533
+ }
26534
+ resolve(doc) {
26535
+ const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);
26536
+ if ($anchorCell.parent.type.spec.tableRole == "row" && $headCell.parent.type.spec.tableRole == "row" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);
26537
+ else return Selection.near($headCell, 1);
26538
+ }
26375
26539
  };
26376
26540
  function drawCellSelection(state) {
26377
- if (!(state.selection instanceof CellSelection)) return null;
26378
- const cells = [];
26379
- state.selection.forEachCell((node, pos) => {
26380
- cells.push(
26381
- Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })
26382
- );
26383
- });
26384
- return DecorationSet.create(state.doc, cells);
26541
+ if (!(state.selection instanceof CellSelection)) return null;
26542
+ const cells = [];
26543
+ state.selection.forEachCell((node, pos) => {
26544
+ cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" }));
26545
+ });
26546
+ return DecorationSet.create(state.doc, cells);
26385
26547
  }
26386
26548
  function isCellBoundarySelection({ $from, $to }) {
26387
- if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;
26388
- let afterFrom = $from.pos;
26389
- let beforeTo = $to.pos;
26390
- let depth = $from.depth;
26391
- for (; depth >= 0; depth--, afterFrom++)
26392
- if ($from.after(depth + 1) < $from.end(depth)) break;
26393
- for (let d = $to.depth; d >= 0; d--, beforeTo--)
26394
- if ($to.before(d + 1) > $to.start(d)) break;
26395
- return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
26549
+ if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;
26550
+ let afterFrom = $from.pos;
26551
+ let beforeTo = $to.pos;
26552
+ let depth = $from.depth;
26553
+ for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;
26554
+ for (let d = $to.depth; d >= 0; d--, beforeTo--) if ($to.before(d + 1) > $to.start(d)) break;
26555
+ return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);
26396
26556
  }
26397
26557
  function isTextSelectionAcrossCells({ $from, $to }) {
26398
- let fromCellBoundaryNode;
26399
- let toCellBoundaryNode;
26400
- for (let i = $from.depth; i > 0; i--) {
26401
- const node = $from.node(i);
26402
- if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
26403
- fromCellBoundaryNode = node;
26404
- break;
26405
- }
26406
- }
26407
- for (let i = $to.depth; i > 0; i--) {
26408
- const node = $to.node(i);
26409
- if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
26410
- toCellBoundaryNode = node;
26411
- break;
26412
- }
26413
- }
26414
- return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
26558
+ let fromCellBoundaryNode;
26559
+ let toCellBoundaryNode;
26560
+ for (let i = $from.depth; i > 0; i--) {
26561
+ const node = $from.node(i);
26562
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
26563
+ fromCellBoundaryNode = node;
26564
+ break;
26565
+ }
26566
+ }
26567
+ for (let i = $to.depth; i > 0; i--) {
26568
+ const node = $to.node(i);
26569
+ if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") {
26570
+ toCellBoundaryNode = node;
26571
+ break;
26572
+ }
26573
+ }
26574
+ return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
26415
26575
  }
26416
26576
  function normalizeSelection(state, tr, allowTableNodeSelection) {
26417
- const sel = (tr || state).selection;
26418
- const doc = (tr || state).doc;
26419
- let normalize;
26420
- let role;
26421
- if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
26422
- if (role == "cell" || role == "header_cell") {
26423
- normalize = CellSelection.create(doc, sel.from);
26424
- } else if (role == "row") {
26425
- const $cell = doc.resolve(sel.from + 1);
26426
- normalize = CellSelection.rowSelection($cell, $cell);
26427
- } else if (!allowTableNodeSelection) {
26428
- const map = TableMap.get(sel.node);
26429
- const start = sel.from + 1;
26430
- const lastCell = start + map.map[map.width * map.height - 1];
26431
- normalize = CellSelection.create(doc, start + 1, lastCell);
26432
- }
26433
- } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
26434
- normalize = TextSelection.create(doc, sel.from);
26435
- } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
26436
- normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
26437
- }
26438
- if (normalize) (tr || (tr = state.tr)).setSelection(normalize);
26439
- return tr;
26577
+ const sel = (tr || state).selection;
26578
+ const doc = (tr || state).doc;
26579
+ let normalize;
26580
+ let role;
26581
+ if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {
26582
+ if (role == "cell" || role == "header_cell") normalize = CellSelection.create(doc, sel.from);
26583
+ else if (role == "row") {
26584
+ const $cell = doc.resolve(sel.from + 1);
26585
+ normalize = CellSelection.rowSelection($cell, $cell);
26586
+ } else if (!allowTableNodeSelection) {
26587
+ const map = TableMap.get(sel.node);
26588
+ const start = sel.from + 1;
26589
+ const lastCell = start + map.map[map.width * map.height - 1];
26590
+ normalize = CellSelection.create(doc, start + 1, lastCell);
26591
+ }
26592
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize = TextSelection.create(doc, sel.from);
26593
+ else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
26594
+ if (normalize) (tr || (tr = state.tr)).setSelection(normalize);
26595
+ return tr;
26440
26596
  }
26441
- var fixTablesKey = new PluginKey("fix-tables");
26597
+
26598
+ //#endregion
26599
+ //#region src/fixtables.ts
26600
+ /**
26601
+ * @public
26602
+ */
26603
+ const fixTablesKey = new PluginKey("fix-tables");
26604
+ /**
26605
+ * Helper for iterating through the nodes in a document that changed
26606
+ * compared to the given previous document. Useful for avoiding
26607
+ * duplicate work on each transaction.
26608
+ *
26609
+ * @public
26610
+ */
26442
26611
  function changedDescendants(old, cur, offset, f) {
26443
- const oldSize = old.childCount, curSize = cur.childCount;
26444
- outer: for (let i = 0, j = 0; i < curSize; i++) {
26445
- const child = cur.child(i);
26446
- for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
26447
- if (old.child(scan) == child) {
26448
- j = scan + 1;
26449
- offset += child.nodeSize;
26450
- continue outer;
26451
- }
26452
- }
26453
- f(child, offset);
26454
- if (j < oldSize && old.child(j).sameMarkup(child))
26455
- changedDescendants(old.child(j), child, offset + 1, f);
26456
- else child.nodesBetween(0, child.content.size, f, offset + 1);
26457
- offset += child.nodeSize;
26458
- }
26612
+ const oldSize = old.childCount, curSize = cur.childCount;
26613
+ outer: for (let i = 0, j = 0; i < curSize; i++) {
26614
+ const child = cur.child(i);
26615
+ for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {
26616
+ j = scan + 1;
26617
+ offset += child.nodeSize;
26618
+ continue outer;
26619
+ }
26620
+ f(child, offset);
26621
+ if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset + 1, f);
26622
+ else child.nodesBetween(0, child.content.size, f, offset + 1);
26623
+ offset += child.nodeSize;
26624
+ }
26459
26625
  }
26626
+ /**
26627
+ * Inspect all tables in the given state's document and return a
26628
+ * transaction that fixes them, if necessary. If `oldState` was
26629
+ * provided, that is assumed to hold a previous, known-good state,
26630
+ * which will be used to avoid re-scanning unchanged parts of the
26631
+ * document.
26632
+ *
26633
+ * @public
26634
+ */
26460
26635
  function fixTables(state, oldState) {
26461
- let tr;
26462
- const check = (node, pos) => {
26463
- if (node.type.spec.tableRole == "table")
26464
- tr = fixTable(state, node, pos, tr);
26465
- };
26466
- if (!oldState) state.doc.descendants(check);
26467
- else if (oldState.doc != state.doc)
26468
- changedDescendants(oldState.doc, state.doc, 0, check);
26469
- return tr;
26636
+ let tr;
26637
+ const check = (node, pos) => {
26638
+ if (node.type.spec.tableRole == "table") tr = fixTable(state, node, pos, tr);
26639
+ };
26640
+ if (!oldState) state.doc.descendants(check);
26641
+ else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);
26642
+ return tr;
26470
26643
  }
26471
26644
  function fixTable(state, table, tablePos, tr) {
26472
- const map = TableMap.get(table);
26473
- if (!map.problems) return tr;
26474
- if (!tr) tr = state.tr;
26475
- const mustAdd = [];
26476
- for (let i = 0; i < map.height; i++) mustAdd.push(0);
26477
- for (let i = 0; i < map.problems.length; i++) {
26478
- const prob = map.problems[i];
26479
- if (prob.type == "collision") {
26480
- const cell = table.nodeAt(prob.pos);
26481
- if (!cell) continue;
26482
- const attrs = cell.attrs;
26483
- for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
26484
- tr.setNodeMarkup(
26485
- tr.mapping.map(tablePos + 1 + prob.pos),
26486
- null,
26487
- removeColSpan(attrs, attrs.colspan - prob.n, prob.n)
26488
- );
26489
- } else if (prob.type == "missing") {
26490
- mustAdd[prob.row] += prob.n;
26491
- } else if (prob.type == "overlong_rowspan") {
26492
- const cell = table.nodeAt(prob.pos);
26493
- if (!cell) continue;
26494
- tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
26495
- ...cell.attrs,
26496
- rowspan: cell.attrs.rowspan - prob.n
26497
- });
26498
- } else if (prob.type == "colwidth mismatch") {
26499
- const cell = table.nodeAt(prob.pos);
26500
- if (!cell) continue;
26501
- tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
26502
- ...cell.attrs,
26503
- colwidth: prob.colwidth
26504
- });
26505
- } else if (prob.type == "zero_sized") {
26506
- const pos = tr.mapping.map(tablePos);
26507
- tr.delete(pos, pos + table.nodeSize);
26508
- }
26509
- }
26510
- let first, last;
26511
- for (let i = 0; i < mustAdd.length; i++)
26512
- if (mustAdd[i]) {
26513
- if (first == null) first = i;
26514
- last = i;
26515
- }
26516
- for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
26517
- const row = table.child(i);
26518
- const end = pos + row.nodeSize;
26519
- const add = mustAdd[i];
26520
- if (add > 0) {
26521
- let role = "cell";
26522
- if (row.firstChild) {
26523
- role = row.firstChild.type.spec.tableRole;
26524
- }
26525
- const nodes = [];
26526
- for (let j = 0; j < add; j++) {
26527
- const node = tableNodeTypes(state.schema)[role].createAndFill();
26528
- if (node) nodes.push(node);
26529
- }
26530
- const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
26531
- tr.insert(tr.mapping.map(side), nodes);
26532
- }
26533
- pos = end;
26534
- }
26535
- return tr.setMeta(fixTablesKey, { fixTables: true });
26645
+ const map = TableMap.get(table);
26646
+ if (!map.problems) return tr;
26647
+ if (!tr) tr = state.tr;
26648
+ const mustAdd = [];
26649
+ for (let i = 0; i < map.height; i++) mustAdd.push(0);
26650
+ for (let i = 0; i < map.problems.length; i++) {
26651
+ const prob = map.problems[i];
26652
+ if (prob.type == "collision") {
26653
+ const cell = table.nodeAt(prob.pos);
26654
+ if (!cell) continue;
26655
+ const attrs = cell.attrs;
26656
+ for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;
26657
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));
26658
+ } else if (prob.type == "missing") mustAdd[prob.row] += prob.n;
26659
+ else if (prob.type == "overlong_rowspan") {
26660
+ const cell = table.nodeAt(prob.pos);
26661
+ if (!cell) continue;
26662
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
26663
+ ...cell.attrs,
26664
+ rowspan: cell.attrs.rowspan - prob.n
26665
+ });
26666
+ } else if (prob.type == "colwidth mismatch") {
26667
+ const cell = table.nodeAt(prob.pos);
26668
+ if (!cell) continue;
26669
+ tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {
26670
+ ...cell.attrs,
26671
+ colwidth: prob.colwidth
26672
+ });
26673
+ } else if (prob.type == "zero_sized") {
26674
+ const pos = tr.mapping.map(tablePos);
26675
+ tr.delete(pos, pos + table.nodeSize);
26676
+ }
26677
+ }
26678
+ let first, last;
26679
+ for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {
26680
+ if (first == null) first = i;
26681
+ last = i;
26682
+ }
26683
+ for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
26684
+ const row = table.child(i);
26685
+ const end = pos + row.nodeSize;
26686
+ const add = mustAdd[i];
26687
+ if (add > 0) {
26688
+ let role = "cell";
26689
+ if (row.firstChild) role = row.firstChild.type.spec.tableRole;
26690
+ const nodes = [];
26691
+ for (let j = 0; j < add; j++) {
26692
+ const node = tableNodeTypes(state.schema)[role].createAndFill();
26693
+ if (node) nodes.push(node);
26694
+ }
26695
+ const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
26696
+ tr.insert(tr.mapping.map(side), nodes);
26697
+ }
26698
+ pos = end;
26699
+ }
26700
+ return tr.setMeta(fixTablesKey, { fixTables: true });
26536
26701
  }
26702
+ /**
26703
+ * Deletes the content of the selected cells, if they are not empty.
26704
+ *
26705
+ * @public
26706
+ */
26537
26707
  function deleteCellSelection(state, dispatch) {
26538
- const sel = state.selection;
26539
- if (!(sel instanceof CellSelection)) return false;
26540
- if (dispatch) {
26541
- const tr = state.tr;
26542
- const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
26543
- sel.forEachCell((cell, pos) => {
26544
- if (!cell.content.eq(baseContent))
26545
- tr.replace(
26546
- tr.mapping.map(pos + 1),
26547
- tr.mapping.map(pos + cell.nodeSize - 1),
26548
- new Slice(baseContent, 0, 0)
26549
- );
26550
- });
26551
- if (tr.docChanged) dispatch(tr);
26552
- }
26553
- return true;
26708
+ const sel = state.selection;
26709
+ if (!(sel instanceof CellSelection)) return false;
26710
+ if (dispatch) {
26711
+ const tr = state.tr;
26712
+ const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
26713
+ sel.forEachCell((cell, pos) => {
26714
+ if (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));
26715
+ });
26716
+ if (tr.docChanged) dispatch(tr);
26717
+ }
26718
+ return true;
26554
26719
  }
26720
+
26721
+ //#endregion
26722
+ //#region src/copypaste.ts
26723
+ /**
26724
+ * Get a rectangular area of cells from a slice, or null if the outer
26725
+ * nodes of the slice aren't table cells or rows.
26726
+ *
26727
+ * @internal
26728
+ */
26555
26729
  function pastedCells(slice) {
26556
- if (!slice.size) return null;
26557
- let { content, openStart, openEnd } = slice;
26558
- while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
26559
- openStart--;
26560
- openEnd--;
26561
- content = content.child(0).content;
26562
- }
26563
- const first = content.child(0);
26564
- const role = first.type.spec.tableRole;
26565
- const schema = first.type.schema, rows = [];
26566
- if (role == "row") {
26567
- for (let i = 0; i < content.childCount; i++) {
26568
- let cells = content.child(i).content;
26569
- const left = i ? 0 : Math.max(0, openStart - 1);
26570
- const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
26571
- if (left || right)
26572
- cells = fitSlice(
26573
- tableNodeTypes(schema).row,
26574
- new Slice(cells, left, right)
26575
- ).content;
26576
- rows.push(cells);
26577
- }
26578
- } else if (role == "cell" || role == "header_cell") {
26579
- rows.push(
26580
- openStart || openEnd ? fitSlice(
26581
- tableNodeTypes(schema).row,
26582
- new Slice(content, openStart, openEnd)
26583
- ).content : content
26584
- );
26585
- } else {
26586
- return null;
26587
- }
26588
- return ensureRectangular(schema, rows);
26730
+ if (slice.size === 0) return null;
26731
+ let { content, openStart, openEnd } = slice;
26732
+ while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) {
26733
+ openStart--;
26734
+ openEnd--;
26735
+ content = content.child(0).content;
26736
+ }
26737
+ const first = content.child(0);
26738
+ const role = first.type.spec.tableRole;
26739
+ const schema = first.type.schema, rows = [];
26740
+ if (role == "row") for (let i = 0; i < content.childCount; i++) {
26741
+ let cells = content.child(i).content;
26742
+ const left = i ? 0 : Math.max(0, openStart - 1);
26743
+ const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);
26744
+ if (left || right) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content;
26745
+ rows.push(cells);
26746
+ }
26747
+ else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);
26748
+ else return null;
26749
+ return ensureRectangular(schema, rows);
26589
26750
  }
26590
26751
  function ensureRectangular(schema, rows) {
26591
- const widths = [];
26592
- for (let i = 0; i < rows.length; i++) {
26593
- const row = rows[i];
26594
- for (let j = row.childCount - 1; j >= 0; j--) {
26595
- const { rowspan, colspan } = row.child(j).attrs;
26596
- for (let r = i; r < i + rowspan; r++)
26597
- widths[r] = (widths[r] || 0) + colspan;
26598
- }
26599
- }
26600
- let width = 0;
26601
- for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);
26602
- for (let r = 0; r < widths.length; r++) {
26603
- if (r >= rows.length) rows.push(Fragment.empty);
26604
- if (widths[r] < width) {
26605
- const empty = tableNodeTypes(schema).cell.createAndFill();
26606
- const cells = [];
26607
- for (let i = widths[r]; i < width; i++) {
26608
- cells.push(empty);
26609
- }
26610
- rows[r] = rows[r].append(Fragment.from(cells));
26611
- }
26612
- }
26613
- return { height: rows.length, width, rows };
26752
+ const widths = [];
26753
+ for (let i = 0; i < rows.length; i++) {
26754
+ const row = rows[i];
26755
+ for (let j = row.childCount - 1; j >= 0; j--) {
26756
+ const { rowspan, colspan } = row.child(j).attrs;
26757
+ for (let r = i; r < i + rowspan; r++) widths[r] = (widths[r] || 0) + colspan;
26758
+ }
26759
+ }
26760
+ let width = 0;
26761
+ for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);
26762
+ for (let r = 0; r < widths.length; r++) {
26763
+ if (r >= rows.length) rows.push(Fragment.empty);
26764
+ if (widths[r] < width) {
26765
+ const empty = tableNodeTypes(schema).cell.createAndFill();
26766
+ const cells = [];
26767
+ for (let i = widths[r]; i < width; i++) cells.push(empty);
26768
+ rows[r] = rows[r].append(Fragment.from(cells));
26769
+ }
26770
+ }
26771
+ return {
26772
+ height: rows.length,
26773
+ width,
26774
+ rows
26775
+ };
26614
26776
  }
26615
26777
  function fitSlice(nodeType, slice) {
26616
- const node = nodeType.createAndFill();
26617
- const tr = new Transform(node).replace(0, node.content.size, slice);
26618
- return tr.doc;
26778
+ const node = nodeType.createAndFill();
26779
+ return new Transform(node).replace(0, node.content.size, slice).doc;
26619
26780
  }
26781
+ /**
26782
+ * Clip or extend (repeat) the given set of cells to cover the given
26783
+ * width and height. Will clip rowspan/colspan cells at the edges when
26784
+ * they stick out.
26785
+ *
26786
+ * @internal
26787
+ */
26620
26788
  function clipCells({ width, height, rows }, newWidth, newHeight) {
26621
- if (width != newWidth) {
26622
- const added = [];
26623
- const newRows = [];
26624
- for (let row = 0; row < rows.length; row++) {
26625
- const frag = rows[row], cells = [];
26626
- for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
26627
- let cell = frag.child(i % frag.childCount);
26628
- if (col + cell.attrs.colspan > newWidth)
26629
- cell = cell.type.createChecked(
26630
- removeColSpan(
26631
- cell.attrs,
26632
- cell.attrs.colspan,
26633
- col + cell.attrs.colspan - newWidth
26634
- ),
26635
- cell.content
26636
- );
26637
- cells.push(cell);
26638
- col += cell.attrs.colspan;
26639
- for (let j = 1; j < cell.attrs.rowspan; j++)
26640
- added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
26641
- }
26642
- newRows.push(Fragment.from(cells));
26643
- }
26644
- rows = newRows;
26645
- width = newWidth;
26646
- }
26647
- if (height != newHeight) {
26648
- const newRows = [];
26649
- for (let row = 0, i = 0; row < newHeight; row++, i++) {
26650
- const cells = [], source = rows[i % height];
26651
- for (let j = 0; j < source.childCount; j++) {
26652
- let cell = source.child(j);
26653
- if (row + cell.attrs.rowspan > newHeight)
26654
- cell = cell.type.create(
26655
- {
26656
- ...cell.attrs,
26657
- rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
26658
- },
26659
- cell.content
26660
- );
26661
- cells.push(cell);
26662
- }
26663
- newRows.push(Fragment.from(cells));
26664
- }
26665
- rows = newRows;
26666
- height = newHeight;
26667
- }
26668
- return { width, height, rows };
26789
+ if (width != newWidth) {
26790
+ const added = [];
26791
+ const newRows = [];
26792
+ for (let row = 0; row < rows.length; row++) {
26793
+ const frag = rows[row], cells = [];
26794
+ for (let col = added[row] || 0, i = 0; col < newWidth; i++) {
26795
+ let cell = frag.child(i % frag.childCount);
26796
+ if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);
26797
+ cells.push(cell);
26798
+ col += cell.attrs.colspan;
26799
+ for (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;
26800
+ }
26801
+ newRows.push(Fragment.from(cells));
26802
+ }
26803
+ rows = newRows;
26804
+ width = newWidth;
26805
+ }
26806
+ if (height != newHeight) {
26807
+ const newRows = [];
26808
+ for (let row = 0, i = 0; row < newHeight; row++, i++) {
26809
+ const cells = [], source = rows[i % height];
26810
+ for (let j = 0; j < source.childCount; j++) {
26811
+ let cell = source.child(j);
26812
+ if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({
26813
+ ...cell.attrs,
26814
+ rowspan: Math.max(1, newHeight - cell.attrs.rowspan)
26815
+ }, cell.content);
26816
+ cells.push(cell);
26817
+ }
26818
+ newRows.push(Fragment.from(cells));
26819
+ }
26820
+ rows = newRows;
26821
+ height = newHeight;
26822
+ }
26823
+ return {
26824
+ width,
26825
+ height,
26826
+ rows
26827
+ };
26669
26828
  }
26670
26829
  function growTable(tr, map, table, start, width, height, mapFrom) {
26671
- const schema = tr.doc.type.schema;
26672
- const types = tableNodeTypes(schema);
26673
- let empty;
26674
- let emptyHead;
26675
- if (width > map.width) {
26676
- for (let row = 0, rowEnd = 0; row < map.height; row++) {
26677
- const rowNode = table.child(row);
26678
- rowEnd += rowNode.nodeSize;
26679
- const cells = [];
26680
- let add;
26681
- if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)
26682
- add = empty || (empty = types.cell.createAndFill());
26683
- else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
26684
- for (let i = map.width; i < width; i++) cells.push(add);
26685
- tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
26686
- }
26687
- }
26688
- if (height > map.height) {
26689
- const cells = [];
26690
- for (let i = 0, start2 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
26691
- const header = i >= map.width ? false : table.nodeAt(map.map[start2 + i]).type == types.header_cell;
26692
- cells.push(
26693
- header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill())
26694
- );
26695
- }
26696
- const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
26697
- for (let i = map.height; i < height; i++) rows.push(emptyRow);
26698
- tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
26699
- }
26700
- return !!(empty || emptyHead);
26830
+ const schema = tr.doc.type.schema;
26831
+ const types = tableNodeTypes(schema);
26832
+ let empty;
26833
+ let emptyHead;
26834
+ if (width > map.width) for (let row = 0, rowEnd = 0; row < map.height; row++) {
26835
+ const rowNode = table.child(row);
26836
+ rowEnd += rowNode.nodeSize;
26837
+ const cells = [];
26838
+ let add;
26839
+ if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty || (empty = types.cell.createAndFill());
26840
+ else add = emptyHead || (emptyHead = types.header_cell.createAndFill());
26841
+ for (let i = map.width; i < width; i++) cells.push(add);
26842
+ tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);
26843
+ }
26844
+ if (height > map.height) {
26845
+ const cells = [];
26846
+ for (let i = 0, start$1 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {
26847
+ const header = i >= map.width ? false : table.nodeAt(map.map[start$1 + i]).type == types.header_cell;
26848
+ cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill()));
26849
+ }
26850
+ const emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];
26851
+ for (let i = map.height; i < height; i++) rows.push(emptyRow);
26852
+ tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);
26853
+ }
26854
+ return !!(empty || emptyHead);
26701
26855
  }
26702
26856
  function isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {
26703
- if (top == 0 || top == map.height) return false;
26704
- let found = false;
26705
- for (let col = left; col < right; col++) {
26706
- const index = top * map.width + col, pos = map.map[index];
26707
- if (map.map[index - map.width] == pos) {
26708
- found = true;
26709
- const cell = table.nodeAt(pos);
26710
- const { top: cellTop, left: cellLeft } = map.findCell(pos);
26711
- tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {
26712
- ...cell.attrs,
26713
- rowspan: top - cellTop
26714
- });
26715
- tr.insert(
26716
- tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),
26717
- cell.type.createAndFill({
26718
- ...cell.attrs,
26719
- rowspan: cellTop + cell.attrs.rowspan - top
26720
- })
26721
- );
26722
- col += cell.attrs.colspan - 1;
26723
- }
26724
- }
26725
- return found;
26857
+ if (top == 0 || top == map.height) return false;
26858
+ let found = false;
26859
+ for (let col = left; col < right; col++) {
26860
+ const index = top * map.width + col, pos = map.map[index];
26861
+ if (map.map[index - map.width] == pos) {
26862
+ found = true;
26863
+ const cell = table.nodeAt(pos);
26864
+ const { top: cellTop, left: cellLeft } = map.findCell(pos);
26865
+ tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {
26866
+ ...cell.attrs,
26867
+ rowspan: top - cellTop
26868
+ });
26869
+ tr.insert(tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)), cell.type.createAndFill({
26870
+ ...cell.attrs,
26871
+ rowspan: cellTop + cell.attrs.rowspan - top
26872
+ }));
26873
+ col += cell.attrs.colspan - 1;
26874
+ }
26875
+ }
26876
+ return found;
26726
26877
  }
26727
26878
  function isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {
26728
- if (left == 0 || left == map.width) return false;
26729
- let found = false;
26730
- for (let row = top; row < bottom; row++) {
26731
- const index = row * map.width + left, pos = map.map[index];
26732
- if (map.map[index - 1] == pos) {
26733
- found = true;
26734
- const cell = table.nodeAt(pos);
26735
- const cellLeft = map.colCount(pos);
26736
- const updatePos = tr.mapping.slice(mapFrom).map(pos + start);
26737
- tr.setNodeMarkup(
26738
- updatePos,
26739
- null,
26740
- removeColSpan(
26741
- cell.attrs,
26742
- left - cellLeft,
26743
- cell.attrs.colspan - (left - cellLeft)
26744
- )
26745
- );
26746
- tr.insert(
26747
- updatePos + cell.nodeSize,
26748
- cell.type.createAndFill(
26749
- removeColSpan(cell.attrs, 0, left - cellLeft)
26750
- )
26751
- );
26752
- row += cell.attrs.rowspan - 1;
26753
- }
26754
- }
26755
- return found;
26879
+ if (left == 0 || left == map.width) return false;
26880
+ let found = false;
26881
+ for (let row = top; row < bottom; row++) {
26882
+ const index = row * map.width + left, pos = map.map[index];
26883
+ if (map.map[index - 1] == pos) {
26884
+ found = true;
26885
+ const cell = table.nodeAt(pos);
26886
+ const cellLeft = map.colCount(pos);
26887
+ const updatePos = tr.mapping.slice(mapFrom).map(pos + start);
26888
+ tr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)));
26889
+ tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft)));
26890
+ row += cell.attrs.rowspan - 1;
26891
+ }
26892
+ }
26893
+ return found;
26756
26894
  }
26895
+ /**
26896
+ * Insert the given set of cells (as returned by `pastedCells`) into a
26897
+ * table, at the position pointed at by rect.
26898
+ *
26899
+ * @internal
26900
+ */
26757
26901
  function insertCells(state, dispatch, tableStart, rect, cells) {
26758
- let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
26759
- if (!table) {
26760
- throw new Error("No table found");
26761
- }
26762
- let map = TableMap.get(table);
26763
- const { top, left } = rect;
26764
- const right = left + cells.width, bottom = top + cells.height;
26765
- const tr = state.tr;
26766
- let mapFrom = 0;
26767
- function recomp() {
26768
- table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
26769
- if (!table) {
26770
- throw new Error("No table found");
26771
- }
26772
- map = TableMap.get(table);
26773
- mapFrom = tr.mapping.maps.length;
26774
- }
26775
- if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();
26776
- if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom))
26777
- recomp();
26778
- if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom))
26779
- recomp();
26780
- if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom))
26781
- recomp();
26782
- if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom))
26783
- recomp();
26784
- for (let row = top; row < bottom; row++) {
26785
- const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);
26786
- tr.replace(
26787
- tr.mapping.slice(mapFrom).map(from + tableStart),
26788
- tr.mapping.slice(mapFrom).map(to + tableStart),
26789
- new Slice(cells.rows[row - top], 0, 0)
26790
- );
26791
- }
26792
- recomp();
26793
- tr.setSelection(
26794
- new CellSelection(
26795
- tr.doc.resolve(tableStart + map.positionAt(top, left, table)),
26796
- tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))
26797
- )
26798
- );
26799
- dispatch(tr);
26800
- }
26801
-
26802
- // src/input.ts
26803
- var handleKeyDown = keydownHandler({
26804
- ArrowLeft: arrow("horiz", -1),
26805
- ArrowRight: arrow("horiz", 1),
26806
- ArrowUp: arrow("vert", -1),
26807
- ArrowDown: arrow("vert", 1),
26808
- "Shift-ArrowLeft": shiftArrow("horiz", -1),
26809
- "Shift-ArrowRight": shiftArrow("horiz", 1),
26810
- "Shift-ArrowUp": shiftArrow("vert", -1),
26811
- "Shift-ArrowDown": shiftArrow("vert", 1),
26812
- Backspace: deleteCellSelection,
26813
- "Mod-Backspace": deleteCellSelection,
26814
- Delete: deleteCellSelection,
26815
- "Mod-Delete": deleteCellSelection
26902
+ let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
26903
+ if (!table) throw new Error("No table found");
26904
+ let map = TableMap.get(table);
26905
+ const { top, left } = rect;
26906
+ const right = left + cells.width, bottom = top + cells.height;
26907
+ const tr = state.tr;
26908
+ let mapFrom = 0;
26909
+ function recomp() {
26910
+ table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;
26911
+ if (!table) throw new Error("No table found");
26912
+ map = TableMap.get(table);
26913
+ mapFrom = tr.mapping.maps.length;
26914
+ }
26915
+ if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();
26916
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom)) recomp();
26917
+ if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom)) recomp();
26918
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom)) recomp();
26919
+ if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom)) recomp();
26920
+ for (let row = top; row < bottom; row++) {
26921
+ const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);
26922
+ tr.replace(tr.mapping.slice(mapFrom).map(from + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top], 0, 0));
26923
+ }
26924
+ recomp();
26925
+ tr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map.positionAt(top, left, table)), tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))));
26926
+ dispatch(tr);
26927
+ }
26928
+
26929
+ //#endregion
26930
+ //#region src/input.ts
26931
+ const handleKeyDown = keydownHandler({
26932
+ ArrowLeft: arrow("horiz", -1),
26933
+ ArrowRight: arrow("horiz", 1),
26934
+ ArrowUp: arrow("vert", -1),
26935
+ ArrowDown: arrow("vert", 1),
26936
+ "Shift-ArrowLeft": shiftArrow("horiz", -1),
26937
+ "Shift-ArrowRight": shiftArrow("horiz", 1),
26938
+ "Shift-ArrowUp": shiftArrow("vert", -1),
26939
+ "Shift-ArrowDown": shiftArrow("vert", 1),
26940
+ Backspace: deleteCellSelection,
26941
+ "Mod-Backspace": deleteCellSelection,
26942
+ Delete: deleteCellSelection,
26943
+ "Mod-Delete": deleteCellSelection
26816
26944
  });
26817
26945
  function maybeSetSelection(state, dispatch, selection) {
26818
- if (selection.eq(state.selection)) return false;
26819
- if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());
26820
- return true;
26946
+ if (selection.eq(state.selection)) return false;
26947
+ if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());
26948
+ return true;
26821
26949
  }
26950
+ /**
26951
+ * @internal
26952
+ */
26822
26953
  function arrow(axis, dir) {
26823
- return (state, dispatch, view) => {
26824
- if (!view) return false;
26825
- const sel = state.selection;
26826
- if (sel instanceof CellSelection) {
26827
- return maybeSetSelection(
26828
- state,
26829
- dispatch,
26830
- Selection.near(sel.$headCell, dir)
26831
- );
26832
- }
26833
- if (axis != "horiz" && !sel.empty) return false;
26834
- const end = atEndOfCell(view, axis, dir);
26835
- if (end == null) return false;
26836
- if (axis == "horiz") {
26837
- return maybeSetSelection(
26838
- state,
26839
- dispatch,
26840
- Selection.near(state.doc.resolve(sel.head + dir), dir)
26841
- );
26842
- } else {
26843
- const $cell = state.doc.resolve(end);
26844
- const $next = nextCell($cell, axis, dir);
26845
- let newSel;
26846
- if ($next) newSel = Selection.near($next, 1);
26847
- else if (dir < 0)
26848
- newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
26849
- else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
26850
- return maybeSetSelection(state, dispatch, newSel);
26851
- }
26852
- };
26954
+ return (state, dispatch, view) => {
26955
+ if (!view) return false;
26956
+ const sel = state.selection;
26957
+ if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));
26958
+ if (axis != "horiz" && !sel.empty) return false;
26959
+ const end = atEndOfCell(view, axis, dir);
26960
+ if (end == null) return false;
26961
+ if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));
26962
+ else {
26963
+ const $cell = state.doc.resolve(end);
26964
+ const $next = nextCell($cell, axis, dir);
26965
+ let newSel;
26966
+ if ($next) newSel = Selection.near($next, 1);
26967
+ else if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
26968
+ else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
26969
+ return maybeSetSelection(state, dispatch, newSel);
26970
+ }
26971
+ };
26853
26972
  }
26854
26973
  function shiftArrow(axis, dir) {
26855
- return (state, dispatch, view) => {
26856
- if (!view) return false;
26857
- const sel = state.selection;
26858
- let cellSel;
26859
- if (sel instanceof CellSelection) {
26860
- cellSel = sel;
26861
- } else {
26862
- const end = atEndOfCell(view, axis, dir);
26863
- if (end == null) return false;
26864
- cellSel = new CellSelection(state.doc.resolve(end));
26865
- }
26866
- const $head = nextCell(cellSel.$headCell, axis, dir);
26867
- if (!$head) return false;
26868
- return maybeSetSelection(
26869
- state,
26870
- dispatch,
26871
- new CellSelection(cellSel.$anchorCell, $head)
26872
- );
26873
- };
26974
+ return (state, dispatch, view) => {
26975
+ if (!view) return false;
26976
+ const sel = state.selection;
26977
+ let cellSel;
26978
+ if (sel instanceof CellSelection) cellSel = sel;
26979
+ else {
26980
+ const end = atEndOfCell(view, axis, dir);
26981
+ if (end == null) return false;
26982
+ cellSel = new CellSelection(state.doc.resolve(end));
26983
+ }
26984
+ const $head = nextCell(cellSel.$headCell, axis, dir);
26985
+ if (!$head) return false;
26986
+ return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));
26987
+ };
26874
26988
  }
26875
26989
  function handleTripleClick(view, pos) {
26876
- const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));
26877
- if (!$cell) return false;
26878
- view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
26879
- return true;
26990
+ const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));
26991
+ if (!$cell) return false;
26992
+ view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
26993
+ return true;
26880
26994
  }
26995
+ /**
26996
+ * @public
26997
+ */
26881
26998
  function handlePaste(view, _, slice) {
26882
- if (!isInTable(view.state)) return false;
26883
- let cells = pastedCells(slice);
26884
- const sel = view.state.selection;
26885
- if (sel instanceof CellSelection) {
26886
- if (!cells)
26887
- cells = {
26888
- width: 1,
26889
- height: 1,
26890
- rows: [
26891
- Fragment.from(
26892
- fitSlice(tableNodeTypes(view.state.schema).cell, slice)
26893
- )
26894
- ]
26895
- };
26896
- const table = sel.$anchorCell.node(-1);
26897
- const start = sel.$anchorCell.start(-1);
26898
- const rect = TableMap.get(table).rectBetween(
26899
- sel.$anchorCell.pos - start,
26900
- sel.$headCell.pos - start
26901
- );
26902
- cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
26903
- insertCells(view.state, view.dispatch, start, rect, cells);
26904
- return true;
26905
- } else if (cells) {
26906
- const $cell = selectionCell(view.state);
26907
- const start = $cell.start(-1);
26908
- insertCells(
26909
- view.state,
26910
- view.dispatch,
26911
- start,
26912
- TableMap.get($cell.node(-1)).findCell($cell.pos - start),
26913
- cells
26914
- );
26915
- return true;
26916
- } else {
26917
- return false;
26918
- }
26919
- }
26920
- function handleMouseDown(view, startEvent) {
26921
- var _a;
26922
- if (startEvent.ctrlKey || startEvent.metaKey) return;
26923
- const startDOMCell = domInCell(view, startEvent.target);
26924
- let $anchor;
26925
- if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
26926
- setCellSelection(view.state.selection.$anchorCell, startEvent);
26927
- startEvent.preventDefault();
26928
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
26929
- setCellSelection($anchor, startEvent);
26930
- startEvent.preventDefault();
26931
- } else if (!startDOMCell) {
26932
- return;
26933
- }
26934
- function setCellSelection($anchor2, event) {
26935
- let $head = cellUnderMouse(view, event);
26936
- const starting = tableEditingKey.getState(view.state) == null;
26937
- if (!$head || !inSameTable($anchor2, $head)) {
26938
- if (starting) $head = $anchor2;
26939
- else return;
26940
- }
26941
- const selection = new CellSelection($anchor2, $head);
26942
- if (starting || !view.state.selection.eq(selection)) {
26943
- const tr = view.state.tr.setSelection(selection);
26944
- if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);
26945
- view.dispatch(tr);
26946
- }
26947
- }
26948
- function stop() {
26949
- view.root.removeEventListener("mouseup", stop);
26950
- view.root.removeEventListener("dragstart", stop);
26951
- view.root.removeEventListener("mousemove", move);
26952
- if (tableEditingKey.getState(view.state) != null)
26953
- view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
26954
- }
26955
- function move(_event) {
26956
- const event = _event;
26957
- const anchor = tableEditingKey.getState(view.state);
26958
- let $anchor2;
26959
- if (anchor != null) {
26960
- $anchor2 = view.state.doc.resolve(anchor);
26961
- } else if (domInCell(view, event.target) != startDOMCell) {
26962
- $anchor2 = cellUnderMouse(view, startEvent);
26963
- if (!$anchor2) return stop();
26964
- }
26965
- if ($anchor2) setCellSelection($anchor2, event);
26966
- }
26967
- view.root.addEventListener("mouseup", stop);
26968
- view.root.addEventListener("dragstart", stop);
26969
- view.root.addEventListener("mousemove", move);
26999
+ if (!isInTable(view.state)) return false;
27000
+ let cells = pastedCells(slice);
27001
+ const sel = view.state.selection;
27002
+ if (sel instanceof CellSelection) {
27003
+ if (!cells) cells = {
27004
+ width: 1,
27005
+ height: 1,
27006
+ rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice))]
27007
+ };
27008
+ const table = sel.$anchorCell.node(-1);
27009
+ const start = sel.$anchorCell.start(-1);
27010
+ const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start);
27011
+ cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);
27012
+ insertCells(view.state, view.dispatch, start, rect, cells);
27013
+ return true;
27014
+ } else if (cells) {
27015
+ const $cell = selectionCell(view.state);
27016
+ const start = $cell.start(-1);
27017
+ insertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells);
27018
+ return true;
27019
+ } else return false;
27020
+ }
27021
+ function handleMouseDown$1(view, startEvent) {
27022
+ var _cellUnderMouse;
27023
+ if (startEvent.button != 0) return;
27024
+ if (startEvent.ctrlKey || startEvent.metaKey) return;
27025
+ const startDOMCell = domInCell(view, startEvent.target);
27026
+ let $anchor;
27027
+ if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
27028
+ setCellSelection(view.state.selection.$anchorCell, startEvent);
27029
+ startEvent.preventDefault();
27030
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {
27031
+ setCellSelection($anchor, startEvent);
27032
+ startEvent.preventDefault();
27033
+ } else if (!startDOMCell) return;
27034
+ function setCellSelection($anchor$1, event) {
27035
+ let $head = cellUnderMouse(view, event);
27036
+ const starting = tableEditingKey.getState(view.state) == null;
27037
+ if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;
27038
+ else return;
27039
+ const selection = new CellSelection($anchor$1, $head);
27040
+ if (starting || !view.state.selection.eq(selection)) {
27041
+ const tr = view.state.tr.setSelection(selection);
27042
+ if (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);
27043
+ view.dispatch(tr);
27044
+ }
27045
+ }
27046
+ function stop() {
27047
+ view.root.removeEventListener("mouseup", stop);
27048
+ view.root.removeEventListener("dragstart", stop);
27049
+ view.root.removeEventListener("mousemove", move);
27050
+ if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));
27051
+ }
27052
+ function move(_event) {
27053
+ const event = _event;
27054
+ const anchor = tableEditingKey.getState(view.state);
27055
+ let $anchor$1;
27056
+ if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);
27057
+ else if (domInCell(view, event.target) != startDOMCell) {
27058
+ $anchor$1 = cellUnderMouse(view, startEvent);
27059
+ if (!$anchor$1) return stop();
27060
+ }
27061
+ if ($anchor$1) setCellSelection($anchor$1, event);
27062
+ }
27063
+ view.root.addEventListener("mouseup", stop);
27064
+ view.root.addEventListener("dragstart", stop);
27065
+ view.root.addEventListener("mousemove", move);
26970
27066
  }
26971
27067
  function atEndOfCell(view, axis, dir) {
26972
- if (!(view.state.selection instanceof TextSelection)) return null;
26973
- const { $head } = view.state.selection;
26974
- for (let d = $head.depth - 1; d >= 0; d--) {
26975
- const parent = $head.node(d), index = dir < 0 ? $head.index(d) : $head.indexAfter(d);
26976
- if (index != (dir < 0 ? 0 : parent.childCount)) return null;
26977
- if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
26978
- const cellPos = $head.before(d);
26979
- const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
26980
- return view.endOfTextblock(dirStr) ? cellPos : null;
26981
- }
26982
- }
26983
- return null;
27068
+ if (!(view.state.selection instanceof TextSelection)) return null;
27069
+ const { $head } = view.state.selection;
27070
+ for (let d = $head.depth - 1; d >= 0; d--) {
27071
+ const parent = $head.node(d);
27072
+ if ((dir < 0 ? $head.index(d) : $head.indexAfter(d)) != (dir < 0 ? 0 : parent.childCount)) return null;
27073
+ if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") {
27074
+ const cellPos = $head.before(d);
27075
+ const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
27076
+ return view.endOfTextblock(dirStr) ? cellPos : null;
27077
+ }
27078
+ }
27079
+ return null;
26984
27080
  }
26985
27081
  function domInCell(view, dom) {
26986
- for (; dom && dom != view.dom; dom = dom.parentNode) {
26987
- if (dom.nodeName == "TD" || dom.nodeName == "TH") {
26988
- return dom;
26989
- }
26990
- }
26991
- return null;
27082
+ for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom;
27083
+ return null;
26992
27084
  }
26993
27085
  function cellUnderMouse(view, event) {
26994
- const mousePos = view.posAtCoords({
26995
- left: event.clientX,
26996
- top: event.clientY
26997
- });
26998
- if (!mousePos) return null;
26999
- return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
27000
- }
27001
-
27002
- // src/columnresizing.ts
27003
- new PluginKey(
27004
- "tableColumnResizing"
27005
- );
27006
-
27007
- // src/index.ts
27008
- function tableEditing({
27009
- allowTableNodeSelection = false
27010
- } = {}) {
27011
- return new Plugin({
27012
- key: tableEditingKey,
27013
- // This piece of state is used to remember when a mouse-drag
27014
- // cell-selection is happening, so that it can continue even as
27015
- // transactions (which might move its anchor cell) come in.
27016
- state: {
27017
- init() {
27018
- return null;
27019
- },
27020
- apply(tr, cur) {
27021
- const set = tr.getMeta(tableEditingKey);
27022
- if (set != null) return set == -1 ? null : set;
27023
- if (cur == null || !tr.docChanged) return cur;
27024
- const { deleted, pos } = tr.mapping.mapResult(cur);
27025
- return deleted ? null : pos;
27026
- }
27027
- },
27028
- props: {
27029
- decorations: drawCellSelection,
27030
- handleDOMEvents: {
27031
- mousedown: handleMouseDown
27032
- },
27033
- createSelectionBetween(view) {
27034
- return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
27035
- },
27036
- handleTripleClick,
27037
- handleKeyDown,
27038
- handlePaste
27039
- },
27040
- appendTransaction(_, oldState, state) {
27041
- return normalizeSelection(
27042
- state,
27043
- fixTables(state, oldState),
27044
- allowTableNodeSelection
27045
- );
27046
- }
27047
- });
27086
+ const mousePos = view.posAtCoords({
27087
+ left: event.clientX,
27088
+ top: event.clientY
27089
+ });
27090
+ if (!mousePos) return null;
27091
+ let { inside, pos } = mousePos;
27092
+ return inside >= 0 && cellAround(view.state.doc.resolve(inside)) || cellAround(view.state.doc.resolve(pos));
27093
+ }
27094
+
27095
+ //#endregion
27096
+ //#region src/columnresizing.ts
27097
+ /**
27098
+ * @public
27099
+ */
27100
+ new PluginKey("tableColumnResizing");
27101
+
27102
+ //#endregion
27103
+ //#region src/index.ts
27104
+ /**
27105
+ * Creates a [plugin](http://prosemirror.net/docs/ref/#state.Plugin)
27106
+ * that, when added to an editor, enables cell-selection, handles
27107
+ * cell-based copy/paste, and makes sure tables stay well-formed (each
27108
+ * row has the same width, and cells don't overlap).
27109
+ *
27110
+ * You should probably put this plugin near the end of your array of
27111
+ * plugins, since it handles mouse and arrow key events in tables
27112
+ * rather broadly, and other plugins, like the gap cursor or the
27113
+ * column-width dragging plugin, might want to get a turn first to
27114
+ * perform more specific behavior.
27115
+ *
27116
+ * @public
27117
+ */
27118
+ function tableEditing({ allowTableNodeSelection = false } = {}) {
27119
+ return new Plugin({
27120
+ key: tableEditingKey,
27121
+ state: {
27122
+ init() {
27123
+ return null;
27124
+ },
27125
+ apply(tr, cur) {
27126
+ const set = tr.getMeta(tableEditingKey);
27127
+ if (set != null) return set == -1 ? null : set;
27128
+ if (cur == null || !tr.docChanged) return cur;
27129
+ const { deleted, pos } = tr.mapping.mapResult(cur);
27130
+ return deleted ? null : pos;
27131
+ }
27132
+ },
27133
+ props: {
27134
+ decorations: drawCellSelection,
27135
+ handleDOMEvents: { mousedown: handleMouseDown$1 },
27136
+ createSelectionBetween(view) {
27137
+ return tableEditingKey.getState(view.state) != null ? view.state.selection : null;
27138
+ },
27139
+ handleTripleClick,
27140
+ handleKeyDown,
27141
+ handlePaste
27142
+ },
27143
+ appendTransaction(_, oldState, state) {
27144
+ return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);
27145
+ }
27146
+ });
27048
27147
  }
27049
27148
 
27050
27149
  const getTableEditingPlugins = (tablesEnabled) => {
@@ -27352,6 +27451,9 @@ const ProsemirrorAdapter = class {
27352
27451
  this.lastClickedPos = (_a = result === null || result === void 0 ? void 0 : result.pos) !== null && _a !== void 0 ? _a : null;
27353
27452
  };
27354
27453
  this.changeEmitter = debounce.debounce((value) => {
27454
+ // Record the dispatched value before emitting, so that a consumer
27455
+ // that synchronously echoes the value back is correctly ignored.
27456
+ this.lastDispatchedValue = value;
27355
27457
  this.change.emit(value);
27356
27458
  this.changeWaiting = false;
27357
27459
  }, DEBOUNCE_TIMEOUT);
@@ -27360,13 +27462,28 @@ const ProsemirrorAdapter = class {
27360
27462
  };
27361
27463
  this.portalId = randomString.createRandomString();
27362
27464
  }
27465
+ /**
27466
+ * Emits any pending debounced `change` event immediately.
27467
+ * Does nothing if no change is pending.
27468
+ */
27469
+ async flushPendingChanges() {
27470
+ this.changeEmitter.flush();
27471
+ }
27363
27472
  watchValue(newValue) {
27364
27473
  if (!this.view) {
27365
27474
  return;
27366
27475
  }
27367
27476
  if (this.changeWaiting) {
27368
- // A change is pending; do not update the editor's content
27369
- return;
27477
+ if (newValue === this.lastDispatchedValue) {
27478
+ // The consumer is echoing back a value we emitted, while a
27479
+ // newer change is still pending. Ignore the echo so it does
27480
+ // not clobber the newer content in the editor.
27481
+ return;
27482
+ }
27483
+ // The consumer is intentionally setting a different value.
27484
+ // Discard the pending change and apply the new value.
27485
+ this.changeEmitter.cancel();
27486
+ this.changeWaiting = false;
27370
27487
  }
27371
27488
  const currentContent = this.contentConverter.serialize(this.view, this.schema);
27372
27489
  // If the new value is the same as the current content, do nothing
@@ -27403,7 +27520,7 @@ const ProsemirrorAdapter = class {
27403
27520
  (_e = this.view) === null || _e === void 0 ? void 0 : _e.destroy();
27404
27521
  }
27405
27522
  render() {
27406
- return (index$1.h(index$1.Host, { key: '125d6d80cfc94a3121cde5d121d3cb2a26cf1635', onFocus: this.handleFocus }, index$1.h("div", { key: 'eb076afa683c0dfcb57b6688bc94ce1b81ce5710', id: "editor" }), this.renderToolbar(), this.renderLinkMenu()));
27523
+ return (index$1.h(index$1.Host, { key: '23d1370fa319f2cca982c72d09a01d69ac26008e', onFocus: this.handleFocus }, index$1.h("div", { key: 'f3be546259d31156dde04c4f6e4e8b9bdacd68aa', id: "editor" }), this.renderToolbar(), this.renderLinkMenu()));
27407
27524
  }
27408
27525
  renderToolbar() {
27409
27526
  if (this.actionBarItems.length === 0 || this.ui === 'no-toolbar') {