@globalpayments/vega 2.98.0 → 2.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (645) hide show
  1. package/dist/cjs/{accessibility-88f8af84.js → accessibility-6ca2a237.js} +21 -0
  2. package/dist/cjs/{action-color-accessibility-validator-24498816.js → action-color-accessibility-validator-b8a9ef0f.js} +2 -2
  3. package/dist/cjs/{app-globals-b3f05631.js → app-globals-48d067a7.js} +11 -10
  4. package/dist/cjs/{aria-attributes-value-mapper-9a41b9cf.js → aria-attributes-value-mapper-e8c6b0e0.js} +1 -1
  5. package/dist/cjs/{code-block-d78c2b2c.js → code-block-3b42c364.js} +95 -6
  6. package/dist/cjs/{component-global-style-slimmer-93c5fb50.js → component-global-style-slimmer-ba588eb4.js} +1 -1
  7. package/dist/cjs/{component-value-history-controller-slimmer.abstract-beb00fea.js → component-value-history-controller-slimmer.abstract-bbe3bcaf.js} +24 -5
  8. package/dist/cjs/{content-state-78a620a9.js → content-state-87a06c1a.js} +104 -8
  9. package/dist/cjs/{dark-mode-style-controller-32d4054a.js → dark-mode-style-controller-f3da3342.js} +2 -2
  10. package/dist/cjs/{date-required-rule-5250f26d.js → date-required-rule-45c802d3.js} +1 -1
  11. package/dist/cjs/{design-token-74674ee7.js → design-token-9d762da0.js} +3 -3
  12. package/dist/cjs/{element-appender-slimmer-597e9e48.js → element-appender-slimmer-f7ba5d9a.js} +2 -2
  13. package/dist/cjs/{form-field-controller-slimmer-a743be34.js → form-field-controller-slimmer-fbaddc91.js} +2 -2
  14. package/dist/cjs/{image-annotation-action-85c4bd83.js → image-annotation-action-03d3e01a.js} +7 -6
  15. package/dist/cjs/{image-extension-260fa69c.js → image-extension-ccda26d3.js} +2 -2
  16. package/dist/cjs/{index-592b4052.js → index-5d1adcd1.js} +86 -0
  17. package/dist/cjs/index.cjs.js +20 -19
  18. package/dist/cjs/{inject-keyboard-manager-6a6f5c9f.js → inject-keyboard-manager-540f0876.js} +1 -1
  19. package/dist/cjs/{internal-calendar-period-factory-dfcdd3f6.js → internal-calendar-period-factory-b11918ee.js} +1 -1
  20. package/dist/cjs/{internal-translation-controller-1dac2df8.js → internal-translation-controller-27bfc8c7.js} +17 -0
  21. package/dist/cjs/{keyboard-manager-c56033b1.js → keyboard-manager-16e96b62.js} +12 -5
  22. package/dist/cjs/{keyboard-manager-slimmer-7043a106.js → keyboard-manager-slimmer-0a4e556d.js} +1 -1
  23. package/dist/cjs/{link-extension-220ff6a9.js → link-extension-71eeaa9f.js} +26 -7
  24. package/dist/cjs/loader.cjs.js +14 -14
  25. package/dist/cjs/{month-view-generator-7b704a80.js → month-view-generator-0a3e04de.js} +1 -1
  26. package/dist/cjs/overlay-escape-coordination-901d8942.js +38 -0
  27. package/dist/cjs/{public-rules-5657bce4.js → public-rules-3dc5d02d.js} +9 -9
  28. package/dist/cjs/{range-c5afd53a.js → range-d29751e3.js} +1 -1
  29. package/dist/cjs/{responsive-format-facade-493d1763.js → responsive-format-facade-c6d7f0a1.js} +1 -1
  30. package/dist/cjs/{rich-text-editor-required-rule-385c1b61.js → rich-text-editor-required-rule-05de7f0c.js} +1 -1
  31. package/dist/cjs/{split-cell-operation-873d5db7.js → split-cell-operation-ef783850.js} +14 -4
  32. package/dist/cjs/{state-border-formatter-711c7aaa.js → state-border-formatter-dda9109a.js} +1 -1
  33. package/dist/cjs/{string-format-strategy.abstract-b61bdcbd.js → string-format-strategy.abstract-3a968a59.js} +1 -1
  34. package/dist/cjs/{string-input-formatter-slimmer-ef65cca7.js → string-input-formatter-slimmer-9747039f.js} +1 -1
  35. package/dist/cjs/{string-mask-strategy-ad3fa0ac.js → string-mask-strategy-d9f85c21.js} +2 -2
  36. package/dist/cjs/{style-formatter-8f711cb0.js → style-formatter-d21a9784.js} +2 -2
  37. package/dist/cjs/{time-required-rule-87417359.js → time-required-rule-580cbd3d.js} +1 -1
  38. package/dist/cjs/{token-extension-78b5a026.js → token-extension-8d7bd451.js} +3773 -252
  39. package/dist/cjs/{translation-slimmer-77c7f37d.js → translation-slimmer-31cd5a57.js} +1 -1
  40. package/dist/cjs/{type-guard-a57ef3ac.js → type-guard-00b8efc0.js} +1 -1
  41. package/dist/cjs/{valid-credit-card-number-rule-4c0a3040.js → valid-credit-card-number-rule-70885128.js} +1 -1
  42. package/dist/cjs/vega-accordion.cjs.entry.js +6 -6
  43. package/dist/cjs/vega-app-footer.cjs.entry.js +2 -2
  44. package/dist/cjs/vega-app-header-button.cjs.entry.js +6 -6
  45. package/dist/cjs/vega-banner.cjs.entry.js +1 -1
  46. package/dist/cjs/vega-box.cjs.entry.js +7 -7
  47. package/dist/cjs/vega-brand-logo.cjs.entry.js +2 -2
  48. package/dist/cjs/vega-breadcrumb.cjs.entry.js +2 -2
  49. package/dist/cjs/vega-button-circle.cjs.entry.js +7 -7
  50. package/dist/cjs/vega-button-group_2.cjs.entry.js +13 -6
  51. package/dist/cjs/vega-button-link.cjs.entry.js +4 -4
  52. package/dist/cjs/vega-button.cjs.entry.js +22 -6
  53. package/dist/cjs/vega-calendar_5.cjs.entry.js +22 -11
  54. package/dist/cjs/vega-card.cjs.entry.js +5 -5
  55. package/dist/cjs/vega-carousel.cjs.entry.js +4 -4
  56. package/dist/cjs/vega-checkbox_2.cjs.entry.js +4 -4
  57. package/dist/cjs/vega-chip.cjs.entry.js +6 -6
  58. package/dist/cjs/vega-code-block.cjs.entry.js +12 -12
  59. package/dist/cjs/vega-color-picker.cjs.entry.js +4 -4
  60. package/dist/cjs/vega-color-swatch-picker.cjs.entry.js +4 -4
  61. package/dist/cjs/vega-color-swatch.cjs.entry.js +3 -3
  62. package/dist/cjs/vega-combo-box.cjs.entry.js +10 -10
  63. package/dist/cjs/vega-counter-badge.cjs.entry.js +2 -2
  64. package/dist/cjs/vega-date-picker_2.cjs.entry.js +15 -15
  65. package/dist/cjs/vega-dialog_2.cjs.entry.js +72 -6
  66. package/dist/cjs/vega-divider.cjs.entry.js +5 -5
  67. package/dist/cjs/vega-dropdown_5.cjs.entry.js +116 -24
  68. package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
  69. package/dist/cjs/vega-field-label.cjs.entry.js +27 -34
  70. package/dist/cjs/vega-file-uploader.cjs.entry.js +5 -5
  71. package/dist/cjs/vega-flag-icon.cjs.entry.js +5 -5
  72. package/dist/cjs/vega-flex.cjs.entry.js +6 -6
  73. package/dist/cjs/vega-font.cjs.entry.js +5 -5
  74. package/dist/cjs/vega-form.cjs.entry.js +2 -2
  75. package/dist/cjs/vega-grid.cjs.entry.js +5 -5
  76. package/dist/cjs/vega-icon.cjs.entry.js +6 -6
  77. package/dist/cjs/vega-image-uploader.cjs.entry.js +8 -8
  78. package/dist/cjs/vega-input-credit-card.cjs.entry.js +7 -7
  79. package/dist/cjs/vega-input-numeric.cjs.entry.js +6 -6
  80. package/dist/cjs/vega-input-passcode.cjs.entry.js +6 -6
  81. package/dist/cjs/vega-input-phone-number.cjs.entry.js +42 -8
  82. package/dist/cjs/vega-input-range.cjs.entry.js +5 -5
  83. package/dist/cjs/vega-input-select.cjs.entry.js +25 -8
  84. package/dist/cjs/vega-input.cjs.entry.js +9 -9
  85. package/dist/cjs/vega-left-nav_5.cjs.entry.js +10 -10
  86. package/dist/cjs/vega-loader-wrapper_2.cjs.entry.js +3 -3
  87. package/dist/cjs/vega-page-notification_2.cjs.entry.js +1 -1
  88. package/dist/cjs/vega-pagination-page-size-selector-mobile.cjs.entry.js +2 -2
  89. package/dist/cjs/vega-pagination.cjs.entry.js +4 -4
  90. package/dist/cjs/vega-popover_2.cjs.entry.js +58 -9
  91. package/dist/cjs/vega-progress-tracker_2.cjs.entry.js +4 -4
  92. package/dist/cjs/vega-radio_2.cjs.entry.js +7 -7
  93. package/dist/cjs/vega-rich-text-content.cjs.entry.js +44 -13
  94. package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +767 -248
  95. package/dist/cjs/vega-rich-text-find-replace-panel.cjs.entry.js +3 -3
  96. package/dist/cjs/vega-rich-text-special-characters-panel.cjs.entry.js +5 -5
  97. package/dist/cjs/vega-rich-text-table-properties_3.cjs.entry.js +158 -105
  98. package/dist/cjs/vega-selection-chip_2.cjs.entry.js +6 -6
  99. package/dist/cjs/vega-selection-tile_2.cjs.entry.js +3 -3
  100. package/dist/cjs/vega-sidenav_3.cjs.entry.js +4 -4
  101. package/dist/cjs/vega-signature-capture.cjs.entry.js +8 -8
  102. package/dist/cjs/vega-stepper.cjs.entry.js +3 -3
  103. package/dist/cjs/vega-tab-group_2.cjs.entry.js +22 -9
  104. package/dist/cjs/vega-table_11.cjs.entry.js +82 -46
  105. package/dist/cjs/vega-textarea.cjs.entry.js +3 -3
  106. package/dist/cjs/vega-time-picker_2.cjs.entry.js +11 -11
  107. package/dist/cjs/vega-toggle-switch.cjs.entry.js +4 -4
  108. package/dist/cjs/vega-tooltip_2.cjs.entry.js +6 -6
  109. package/dist/cjs/vega.cjs.js +14 -14
  110. package/dist/collection/components/vega-button/vega-button.js +17 -2
  111. package/dist/collection/components/vega-button-group/vega-button-group-item/slimmers/renderers/vega-button-group-item-renderer.js +13 -6
  112. package/dist/collection/components/vega-button-link/vega-button-link.js +2 -2
  113. package/dist/collection/components/vega-calendar/slimmers/common/renderers/vega-calendar-event-item-renderer.js +5 -2
  114. package/dist/collection/components/vega-calendar/vega-calendar-event-preview/slimmers/renderers/vega-calendar-event-preview-detail-renderer.js +9 -1
  115. package/dist/collection/components/vega-code-block/vega-code-block.css +4 -4
  116. package/dist/collection/components/vega-counter-badge/vega-counter-badge.js +2 -2
  117. package/dist/collection/components/vega-dropdown/slimmers/controllers/vega-dropdown-keyboard-controller.js +148 -0
  118. package/dist/collection/components/vega-dropdown/slimmers/controllers/vega-dropdown-scrollable-controller.js +5 -2
  119. package/dist/collection/components/vega-dropdown/slimmers/renderers/vega-dropdown-renderer.js +17 -0
  120. package/dist/collection/components/vega-dropdown/vega-dropdown-group/slimmers/renderers/vega-dropdown-group-renderer.js +6 -4
  121. package/dist/collection/components/vega-dropdown/vega-dropdown-item/slimmers/renderers/vega-dropdown-item-renderer.js +12 -4
  122. package/dist/collection/components/vega-dropdown/vega-dropdown-item/vega-dropdown-item.css +2 -1
  123. package/dist/collection/components/vega-dropdown/vega-dropdown.js +1 -1
  124. package/dist/collection/components/vega-field-label/slimmers/renderers/vega-field-label-label-announcement-renderer.js +21 -30
  125. package/dist/collection/components/vega-field-label/vega-field-label.css +1 -0
  126. package/dist/collection/components/vega-field-label/vega-field-label.js +7 -5
  127. package/dist/collection/components/vega-input-select/slimmers/renderers/vega-input-select-dropdown-renderer.js +19 -2
  128. package/dist/collection/components/vega-modal/slimmers/controllers/vega-modal-open-state-controller.js +66 -0
  129. package/dist/collection/components/vega-popover/slimmers/renderers/vega-popover-appender-renderer.js +17 -0
  130. package/dist/collection/components/vega-popover/vega-popover.js +33 -1
  131. package/dist/collection/components/vega-rich-text-content/slimmers/renderers/vega-rich-text-content-renderer.js +4 -1
  132. package/dist/collection/components/vega-rich-text-editor/constants/constant.js +25 -0
  133. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/commit-value-strategy.js +13 -0
  134. package/dist/collection/components/vega-rich-text-editor/dto/actions/commit-value-action.js +20 -0
  135. package/dist/collection/components/vega-rich-text-editor/dto/annotations/text-style-default-styles.js +2 -1
  136. package/dist/collection/components/vega-rich-text-editor/dto/blocks/block.abstract.js +22 -0
  137. package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-item-block.js +10 -0
  138. package/dist/collection/components/vega-rich-text-editor/dto/content-state.js +11 -0
  139. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy-registry.js +2 -1
  140. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy.abstract.js +5 -2
  141. package/dist/collection/components/vega-rich-text-editor/dto/filter-styles-strategies/text-node/title-heading-node-filter-styles-strategy.js +36 -2
  142. package/dist/collection/components/vega-rich-text-editor/dto/nodes/code-block-node.js +6 -0
  143. package/dist/collection/components/vega-rich-text-editor/dto/nodes/node.abstract.js +8 -0
  144. package/dist/collection/components/vega-rich-text-editor/dto/nodes/text-node.js +6 -0
  145. package/dist/collection/components/vega-rich-text-editor/dto/renderers/blocks/block-text-nodes-renderer.abstract.js +20 -3
  146. package/dist/collection/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.js +12 -0
  147. package/dist/collection/components/vega-rich-text-editor/extensions/base-toolbar-button-renderer.js +30 -18
  148. package/dist/collection/components/vega-rich-text-editor/extensions/block-boundary-registry.js +34 -0
  149. package/dist/collection/components/vega-rich-text-editor/extensions/blockquote/renderers/blockquote-toolbar-button-renderer.js +1 -0
  150. package/dist/collection/components/vega-rich-text-editor/extensions/copy/copy-toolbar-button-renderer.js +1 -0
  151. package/dist/collection/components/vega-rich-text-editor/extensions/cut/cut-toolbar-button-renderer.js +1 -0
  152. package/dist/collection/components/vega-rich-text-editor/extensions/extension.abstract.js +20 -0
  153. package/dist/collection/components/vega-rich-text-editor/extensions/find-replace/slimmer/renderers/find-replace-toolbar-button-renderer.js +51 -0
  154. package/dist/collection/components/vega-rich-text-editor/extensions/find-replace/vega-rich-text-find-replace-panel/slimmers/renderers/find-replace-panel-renderer.js +2 -2
  155. package/dist/collection/components/vega-rich-text-editor/extensions/fullscreen/fullscreen-toolbar-button-renderer.js +3 -0
  156. package/dist/collection/components/vega-rich-text-editor/extensions/functions/action-handler-strategies/insert-function-block-strategy.js +3 -2
  157. package/dist/collection/components/vega-rich-text-editor/extensions/functions/constants.js +8 -0
  158. package/dist/collection/components/vega-rich-text-editor/extensions/functions/dto/function-block.js +14 -3
  159. package/dist/collection/components/vega-rich-text-editor/extensions/functions/dto/logic-control-block.js +2 -1
  160. package/dist/collection/components/vega-rich-text-editor/extensions/functions/dto/logic-control-node.js +6 -0
  161. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-containing-function-block-strategy.js +19 -0
  162. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-function-block-strategy.js +9 -5
  163. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-function-content-strategy.js +3 -3
  164. package/dist/collection/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-to-logic-control-block-strategy.js +4 -2
  165. package/dist/collection/components/vega-rich-text-editor/extensions/functions/function-extension.js +18 -0
  166. package/dist/collection/components/vega-rich-text-editor/extensions/functions/renderers/function-block-renderer.js +5 -2
  167. package/dist/collection/components/vega-rich-text-editor/extensions/functions/renderers/function-toolbar-button-renderer.js +1 -0
  168. package/dist/collection/components/vega-rich-text-editor/extensions/functions/renderers/logic-control-block-renderer.js +2 -1
  169. package/dist/collection/components/vega-rich-text-editor/extensions/functions/utils.js +36 -0
  170. package/dist/collection/components/vega-rich-text-editor/extensions/horizontal-line/renderers/horizontal-line-toolbar-button-renderer.js +1 -0
  171. package/dist/collection/components/vega-rich-text-editor/extensions/languages/language-extension.js +1 -0
  172. package/dist/collection/components/vega-rich-text-editor/extensions/languages/language-toolbar-button-renderer.js +5 -3
  173. package/dist/collection/components/vega-rich-text-editor/extensions/line-height/line-height-toolbar-button-renderer.js +16 -0
  174. package/dist/collection/components/vega-rich-text-editor/extensions/paste/action-handler-strategies/image-replace-src-strategy.js +21 -0
  175. package/dist/collection/components/vega-rich-text-editor/extensions/paste/actions/image-replace-src-action.js +13 -0
  176. package/dist/collection/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/paste-image-parser.js +295 -0
  177. package/dist/collection/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/pending-image-registry.js +116 -0
  178. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-chooser-ui.js +13 -4
  179. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-extension.js +70 -7
  180. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/default-paste-strategy.js +38 -0
  181. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/paste-processing-strategy.abstract.js +55 -0
  182. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/paste-strategy-selector.js +59 -0
  183. package/dist/collection/components/vega-rich-text-editor/extensions/paste/strategies/word-paste-strategy.js +416 -0
  184. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-code-block-transformer.js +106 -0
  185. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-image-transformer.js +198 -0
  186. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-list-transformer.js +591 -0
  187. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-paragraph-transformer.js +112 -0
  188. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-table-transformer.js +551 -0
  189. package/dist/collection/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-transformer.js +7 -0
  190. package/dist/collection/components/vega-rich-text-editor/extensions/special-characters/special-characters-toolbar-button-renderer.js +2 -0
  191. package/dist/collection/components/vega-rich-text-editor/extensions/table/dto/table-block.js +10 -0
  192. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-caption-renderer.js +3 -9
  193. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-cell-renderer.js +2 -2
  194. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-dynamic-popover-renderer.js +81 -1
  195. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-popover-base-renderer.js +148 -0
  196. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-renderer.js +151 -5
  197. package/dist/collection/components/vega-rich-text-editor/extensions/table/renderers/table-setting-popover-renderer.js +144 -2
  198. package/dist/collection/components/vega-rich-text-editor/extensions/table/table-selection.js +26 -1
  199. package/dist/collection/components/vega-rich-text-editor/extensions/table/table-toolbar-button-renderer.js +1 -0
  200. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-cell-properties-form-field-renderer.js +11 -2
  201. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-basic-form-field-renderer.abstract.js +5 -2
  202. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-form-field-renderer.js +5 -1
  203. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.css +5 -0
  204. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.js +16 -1
  205. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/caption-button-slimmer.js +1 -0
  206. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/cell-properties-button-slimmer.js +1 -0
  207. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/column-button-slimmer.js +10 -9
  208. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/merge-cells-button-slimmer.js +9 -8
  209. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/row-button-slimmer.js +25 -10
  210. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/table-properties-button-slimmer.js +1 -0
  211. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/table-setting-button-slimmer.abstract.js +5 -4
  212. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/vega-rich-text-table-setting-renderer.js +1 -1
  213. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/vega-rich-text-table-setting.css +10 -0
  214. package/dist/collection/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/vega-rich-text-table-setting.js +2 -0
  215. package/dist/collection/components/vega-rich-text-editor/extensions/tokens/span-to-token-node-strategy.js +4 -2
  216. package/dist/collection/components/vega-rich-text-editor/extensions/tokens/token-node.js +44 -0
  217. package/dist/collection/components/vega-rich-text-editor/extensions/tokens/token-toolbar-button-renderer.js +1 -0
  218. package/dist/collection/components/vega-rich-text-editor/extensions/word-count/action-handler-interceptors/prevent-hard-limit-exceed-interceptor.js +70 -0
  219. package/dist/collection/components/vega-rich-text-editor/extensions/word-count/type.js +1 -0
  220. package/dist/collection/components/vega-rich-text-editor/extensions/word-count/word-count-extension.js +62 -0
  221. package/dist/collection/components/vega-rich-text-editor/public-api.js +1 -0
  222. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/extension-controller.js +2 -0
  223. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/annotation-handler/text-style-annotation-handler.js +7 -4
  224. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.js +17 -0
  225. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/helper/input-event-handler/insert-paste-handler.js +18 -4
  226. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/insert-composition-text-controller.js +2 -1
  227. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/selection-controller.js +21 -2
  228. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/user-input-controller.js +7 -1
  229. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/value-controller.js +52 -2
  230. package/dist/collection/components/vega-rich-text-editor/slimmers/controllers/word-count-controller.js +79 -0
  231. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/toolbar-renderer.js +6 -3
  232. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/bullets-numbers/bullets-numbers-toolbar-button-slimmer.js +2 -1
  233. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/horizontal-alignment/horizontal-alignment-toolbar-button-slimmer.js +2 -1
  234. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/image-toolbar-button-slimmer.js +3 -2
  235. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/link-toolbar-button-slimmer.js +111 -2
  236. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/source-edit-toolbar-button-slimmer.js +24 -6
  237. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/text-color-toolbar-button-slimmer.js +1 -1
  238. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/text-styles-toolbar-button-slimmer.js +1 -1
  239. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/toolbar-button-slimmer.abstract.js +3 -2
  240. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/vega-rich-text-editor-renderer.js +59 -8
  241. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/vega-rich-text-editor-source-view-renderer.js +5 -2
  242. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-editor-toolbar-button/slimmers/renderers/vega-rich-text-editor-toolbar-button-renderer.js +1 -1
  243. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-editor-toolbar-button/vega-rich-text-editor-toolbar-button.js +13 -1
  244. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-editor.js +16 -0
  245. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-link-editor/slimmers/controllers/link-editor-controller.js +124 -0
  246. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-link-editor/slimmers/renderers/vega-rich-text-link-editor-renderer.js +9 -1
  247. package/dist/collection/components/vega-tab-group/slimmers/vega-tab-group/renderers/vega-tab-group-tab-list-renderer.js +14 -7
  248. package/dist/collection/components/vega-tab-group/vega-tab-group.css +6 -0
  249. package/dist/collection/components/vega-tab-group/vega-tab-group.js +5 -0
  250. package/dist/collection/components/vega-table/slimmers/controllers/vega-table-body-col-span-controller.js +31 -1
  251. package/dist/collection/components/vega-table/slimmers/renderers/vega-table-body-col-span-resolver.js +18 -11
  252. package/dist/collection/global/scripts/before-vega-load.js +2 -0
  253. package/dist/collection/helpers/keyboard/keyboard-manager.js +11 -4
  254. package/dist/collection/helpers/keyboard/overlay-escape-coordination.js +33 -0
  255. package/dist/collection/helpers/slimmers/mutation-observer/aria-attributes-value-mapper.js +1 -1
  256. package/dist/collection/helpers/translation/locales/en.js +17 -0
  257. package/dist/collection/polyfill/libphonenumber/as-you-type.js +21 -3
  258. package/dist/collection/polyfill/libphonenumber/metadata.js +16 -0
  259. package/dist/collection/utils/accessibility.js +20 -0
  260. package/dist/collection/utils/sanitize/index.js +3 -2
  261. package/dist/collection/utils/sanitize/strategies/index.js +1 -0
  262. package/dist/collection/utils/sanitize/strategies/label-sanitize-strategy.js +14 -0
  263. package/dist/collection/utils/sanitize/strategies/plain-text-sanitize-strategy.js +70 -0
  264. package/dist/esm/{accessibility-6af5cf2e.js → accessibility-c899a968.js} +21 -1
  265. package/dist/esm/{action-color-accessibility-validator-ce55cb07.js → action-color-accessibility-validator-08877515.js} +2 -2
  266. package/dist/esm/{app-globals-95c7110a.js → app-globals-1e1371d5.js} +11 -10
  267. package/dist/esm/{aria-attributes-value-mapper-2c632641.js → aria-attributes-value-mapper-a5c7478e.js} +1 -1
  268. package/dist/esm/{aria-dialog-focusable-trap-slimmer-f069f54d.js → aria-dialog-focusable-trap-slimmer-b2a24a45.js} +2 -2
  269. package/dist/esm/{child-nodes-notify-observer-slimmer-499a3aa7.js → child-nodes-notify-observer-slimmer-034bc78c.js} +1 -1
  270. package/dist/esm/{code-block-9c513169.js → code-block-741d6b8e.js} +91 -9
  271. package/dist/esm/{component-global-style-slimmer-ac703085.js → component-global-style-slimmer-7d60a04a.js} +1 -1
  272. package/dist/esm/{component-value-history-controller-slimmer.abstract-9cef2a2a.js → component-value-history-controller-slimmer.abstract-2bcd749e.js} +26 -7
  273. package/dist/esm/{content-state-25c81c08.js → content-state-2f6f4204.js} +104 -11
  274. package/dist/esm/{dark-mode-style-controller-ca5afd2d.js → dark-mode-style-controller-352f15ff.js} +2 -2
  275. package/dist/esm/{date-required-rule-85334d0c.js → date-required-rule-2ea3aec8.js} +1 -1
  276. package/dist/esm/{design-token-10ff79b5.js → design-token-82a4e107.js} +3 -3
  277. package/dist/esm/{dom-node-subject-observer-factory-ddff8662.js → dom-node-subject-observer-factory-bb7e68a0.js} +1 -1
  278. package/dist/esm/{element-appender-slimmer-8a06ecdd.js → element-appender-slimmer-c820c0bf.js} +4 -4
  279. package/dist/esm/{event-emit-slimmer-2452278f.js → event-emit-slimmer-e8bb2292.js} +1 -1
  280. package/dist/esm/{form-field-controller-slimmer-68fc5380.js → form-field-controller-slimmer-02165dbe.js} +5 -5
  281. package/dist/esm/{image-annotation-action-d7f2aecc.js → image-annotation-action-972c1074.js} +8 -7
  282. package/dist/esm/{image-extension-fbd1ed6e.js → image-extension-59484e9a.js} +2 -2
  283. package/dist/esm/{index-3b327f29.js → index-35451d12.js} +86 -1
  284. package/dist/esm/index.js +21 -21
  285. package/dist/esm/{inject-keyboard-manager-ea1aad5b.js → inject-keyboard-manager-6a10c9b7.js} +1 -1
  286. package/dist/esm/{internal-calendar-period-factory-7b294fb6.js → internal-calendar-period-factory-d1a60f81.js} +1 -1
  287. package/dist/esm/{internal-translation-controller-fac22598.js → internal-translation-controller-fff376d2.js} +17 -0
  288. package/dist/esm/{keyboard-manager-50da85d7.js → keyboard-manager-a58288df.js} +13 -6
  289. package/dist/esm/{keyboard-manager-slimmer-1f7c8bfb.js → keyboard-manager-slimmer-133b86cd.js} +1 -1
  290. package/dist/esm/{link-extension-e8ee103e.js → link-extension-e89acb5c.js} +26 -7
  291. package/dist/esm/loader.js +16 -16
  292. package/dist/esm/{month-view-generator-a1a9a4ec.js → month-view-generator-20e32b22.js} +1 -1
  293. package/dist/esm/overlay-escape-coordination-439f7d6f.js +35 -0
  294. package/dist/esm/{public-rules-49de79c7.js → public-rules-c154201b.js} +11 -11
  295. package/dist/esm/{range-b678c693.js → range-c818a1eb.js} +2 -2
  296. package/dist/esm/{responsive-format-facade-f19b601c.js → responsive-format-facade-07843ec3.js} +1 -1
  297. package/dist/esm/{rich-text-editor-required-rule-578e0958.js → rich-text-editor-required-rule-878e91c6.js} +1 -1
  298. package/dist/esm/{split-cell-operation-1c8e7585.js → split-cell-operation-cc0cdf90.js} +15 -5
  299. package/dist/esm/{state-border-formatter-bfda33aa.js → state-border-formatter-3b3dcfe8.js} +1 -1
  300. package/dist/esm/{string-format-strategy.abstract-1f4ff1b3.js → string-format-strategy.abstract-44381dcb.js} +1 -1
  301. package/dist/esm/{string-input-formatter-slimmer-0006a107.js → string-input-formatter-slimmer-76fe52d3.js} +3 -3
  302. package/dist/esm/{string-mask-strategy-bbbcdbef.js → string-mask-strategy-999fba4b.js} +2 -2
  303. package/dist/esm/{style-formatter-e9adc8f4.js → style-formatter-c4192c99.js} +2 -2
  304. package/dist/esm/{sub-state-notify-slimmer-23b7d0e8.js → sub-state-notify-slimmer-e306c849.js} +1 -1
  305. package/dist/esm/{sub-state-observer-slimmer-722f6b92.js → sub-state-observer-slimmer-bd85f381.js} +2 -2
  306. package/dist/esm/{time-required-rule-1ce2d0a0.js → time-required-rule-0554b114.js} +1 -1
  307. package/dist/esm/{token-extension-f2d009e3.js → token-extension-35c66684.js} +3773 -253
  308. package/dist/esm/{translation-slimmer-ee0f0e76.js → translation-slimmer-77022f2e.js} +1 -1
  309. package/dist/esm/{type-guard-f2624334.js → type-guard-26d83e7e.js} +1 -1
  310. package/dist/esm/{ui-d73f756a.js → ui-80e610f4.js} +1 -1
  311. package/dist/esm/{valid-credit-card-number-rule-60212b1d.js → valid-credit-card-number-rule-f60b6904.js} +1 -1
  312. package/dist/esm/vega-accordion.entry.js +9 -9
  313. package/dist/esm/vega-app-footer.entry.js +5 -5
  314. package/dist/esm/vega-app-header-button.entry.js +9 -9
  315. package/dist/esm/vega-backdrop.entry.js +1 -1
  316. package/dist/esm/vega-banner.entry.js +4 -4
  317. package/dist/esm/vega-box.entry.js +8 -8
  318. package/dist/esm/vega-brand-logo.entry.js +2 -2
  319. package/dist/esm/vega-breadcrumb.entry.js +5 -5
  320. package/dist/esm/vega-button-circle.entry.js +10 -10
  321. package/dist/esm/vega-button-group_2.entry.js +18 -11
  322. package/dist/esm/vega-button-link.entry.js +7 -7
  323. package/dist/esm/vega-button.entry.js +25 -9
  324. package/dist/esm/vega-calendar_5.entry.js +27 -16
  325. package/dist/esm/vega-card.entry.js +6 -6
  326. package/dist/esm/vega-carousel.entry.js +7 -7
  327. package/dist/esm/vega-checkbox_2.entry.js +9 -9
  328. package/dist/esm/vega-chip.entry.js +9 -9
  329. package/dist/esm/vega-code-block.entry.js +15 -15
  330. package/dist/esm/vega-color-picker.entry.js +8 -8
  331. package/dist/esm/vega-color-swatch-picker.entry.js +8 -8
  332. package/dist/esm/vega-color-swatch.entry.js +6 -6
  333. package/dist/esm/vega-combo-box.entry.js +14 -14
  334. package/dist/esm/vega-counter-badge.entry.js +2 -2
  335. package/dist/esm/vega-date-picker_2.entry.js +21 -21
  336. package/dist/esm/vega-dialog_2.entry.js +76 -10
  337. package/dist/esm/vega-divider.entry.js +5 -5
  338. package/dist/esm/vega-dropdown_5.entry.js +123 -31
  339. package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
  340. package/dist/esm/vega-field-label.entry.js +30 -37
  341. package/dist/esm/vega-file-uploader.entry.js +9 -9
  342. package/dist/esm/vega-flag-icon.entry.js +5 -5
  343. package/dist/esm/vega-flex.entry.js +7 -7
  344. package/dist/esm/vega-font.entry.js +6 -6
  345. package/dist/esm/vega-form.entry.js +8 -8
  346. package/dist/esm/vega-grid.entry.js +6 -6
  347. package/dist/esm/vega-icon.entry.js +7 -7
  348. package/dist/esm/vega-image-uploader.entry.js +12 -12
  349. package/dist/esm/vega-input-credit-card.entry.js +11 -11
  350. package/dist/esm/vega-input-numeric.entry.js +11 -11
  351. package/dist/esm/vega-input-passcode.entry.js +10 -10
  352. package/dist/esm/vega-input-phone-number.entry.js +46 -12
  353. package/dist/esm/vega-input-range.entry.js +9 -9
  354. package/dist/esm/vega-input-select.entry.js +29 -12
  355. package/dist/esm/vega-input.entry.js +14 -14
  356. package/dist/esm/vega-item-toggle.entry.js +3 -3
  357. package/dist/esm/vega-left-nav_5.entry.js +15 -15
  358. package/dist/esm/vega-loader-wrapper_2.entry.js +4 -4
  359. package/dist/esm/vega-page-notification_2.entry.js +3 -3
  360. package/dist/esm/vega-pagination-page-selector-mobile.entry.js +2 -2
  361. package/dist/esm/vega-pagination-page-size-selector-mobile.entry.js +4 -4
  362. package/dist/esm/vega-pagination.entry.js +7 -7
  363. package/dist/esm/vega-popover_2.entry.js +62 -13
  364. package/dist/esm/vega-progress-tracker_2.entry.js +9 -9
  365. package/dist/esm/vega-radio_2.entry.js +12 -12
  366. package/dist/esm/vega-rich-text-content.entry.js +48 -17
  367. package/dist/esm/vega-rich-text-editor_4.entry.js +774 -255
  368. package/dist/esm/vega-rich-text-find-replace-panel.entry.js +6 -6
  369. package/dist/esm/vega-rich-text-special-characters-panel.entry.js +8 -8
  370. package/dist/esm/vega-rich-text-table-properties_3.entry.js +160 -107
  371. package/dist/esm/vega-segment-control.entry.js +3 -3
  372. package/dist/esm/vega-selection-chip_2.entry.js +11 -11
  373. package/dist/esm/vega-selection-tile_2.entry.js +9 -9
  374. package/dist/esm/vega-sidenav_3.entry.js +9 -9
  375. package/dist/esm/vega-signature-capture.entry.js +12 -12
  376. package/dist/esm/vega-stepper.entry.js +7 -7
  377. package/dist/esm/vega-tab-group_2.entry.js +25 -12
  378. package/dist/esm/vega-table_11.entry.js +59 -23
  379. package/dist/esm/vega-textarea.entry.js +7 -7
  380. package/dist/esm/vega-time-picker_2.entry.js +15 -15
  381. package/dist/esm/vega-toggle-switch.entry.js +8 -8
  382. package/dist/esm/vega-tooltip_2.entry.js +8 -8
  383. package/dist/esm/vega.js +16 -16
  384. package/dist/esm/{wait-for-component-did-render-ff7062aa.js → wait-for-component-did-render-9b91a826.js} +1 -1
  385. package/dist/sri/vega-sri-manifest.json +399 -395
  386. package/dist/types/components/vega-button/vega-button.d.ts +2 -0
  387. package/dist/types/components/vega-button-group/types.d.ts +12 -6
  388. package/dist/types/components/vega-calendar/vega-calendar-event-preview/slimmers/renderers/vega-calendar-event-preview-detail-renderer.d.ts +2 -0
  389. package/dist/types/components/vega-dropdown/vega-dropdown-item/slimmers/renderers/vega-dropdown-item-renderer.d.ts +1 -0
  390. package/dist/types/components/vega-dropdown/vega-dropdown.d.ts +1 -1
  391. package/dist/types/components/vega-field-label/slimmers/renderers/vega-field-label-label-announcement-renderer.d.ts +3 -10
  392. package/dist/types/components/vega-input-select/slimmers/renderers/vega-input-select-dropdown-renderer.d.ts +8 -0
  393. package/dist/types/components/vega-modal/slimmers/controllers/vega-modal-open-state-controller.d.ts +33 -0
  394. package/dist/types/components/vega-modal/types.d.ts +2 -1
  395. package/dist/types/components/vega-popover/slimmers/renderers/vega-popover-appender-renderer.d.ts +9 -0
  396. package/dist/types/components/vega-rich-text-editor/constants/constant.d.ts +22 -0
  397. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/commit-value-strategy.d.ts +13 -0
  398. package/dist/types/components/vega-rich-text-editor/dto/actions/commit-value-action.d.ts +20 -0
  399. package/dist/types/components/vega-rich-text-editor/dto/annotations/text-style-default-styles.d.ts +1 -0
  400. package/dist/types/components/vega-rich-text-editor/dto/blocks/block.abstract.d.ts +15 -0
  401. package/dist/types/components/vega-rich-text-editor/dto/blocks/list-item-block.d.ts +4 -0
  402. package/dist/types/components/vega-rich-text-editor/dto/content-state.d.ts +6 -0
  403. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy-registry.d.ts +1 -0
  404. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/filter-styles-strategy.abstract.d.ts +3 -2
  405. package/dist/types/components/vega-rich-text-editor/dto/filter-styles-strategies/text-node/title-heading-node-filter-styles-strategy.d.ts +25 -3
  406. package/dist/types/components/vega-rich-text-editor/dto/nodes/code-block-node.d.ts +4 -0
  407. package/dist/types/components/vega-rich-text-editor/dto/nodes/node.abstract.d.ts +6 -0
  408. package/dist/types/components/vega-rich-text-editor/dto/nodes/text-node.d.ts +4 -0
  409. package/dist/types/components/vega-rich-text-editor/dto/renderers/blocks/block-text-nodes-renderer.abstract.d.ts +7 -0
  410. package/dist/types/components/vega-rich-text-editor/dto/renderers/nodes/text-node-renderer.d.ts +11 -0
  411. package/dist/types/components/vega-rich-text-editor/extensions/base-toolbar-button-renderer.d.ts +5 -0
  412. package/dist/types/components/vega-rich-text-editor/extensions/block-boundary-registry.d.ts +21 -0
  413. package/dist/types/components/vega-rich-text-editor/extensions/extension.abstract.d.ts +15 -0
  414. package/dist/types/components/vega-rich-text-editor/extensions/find-replace/slimmer/renderers/find-replace-toolbar-button-renderer.d.ts +19 -0
  415. package/dist/types/components/vega-rich-text-editor/extensions/functions/constants.d.ts +4 -0
  416. package/dist/types/components/vega-rich-text-editor/extensions/functions/dto/function-block.d.ts +7 -0
  417. package/dist/types/components/vega-rich-text-editor/extensions/functions/dto/logic-control-node.d.ts +4 -0
  418. package/dist/types/components/vega-rich-text-editor/extensions/functions/element-to-dto-strategies/div-containing-function-block-strategy.d.ts +8 -0
  419. package/dist/types/components/vega-rich-text-editor/extensions/functions/function-extension.d.ts +6 -0
  420. package/dist/types/components/vega-rich-text-editor/extensions/functions/utils.d.ts +29 -0
  421. package/dist/types/components/vega-rich-text-editor/extensions/line-height/line-height-toolbar-button-renderer.d.ts +14 -1
  422. package/dist/types/components/vega-rich-text-editor/extensions/paste/action-handler-strategies/image-replace-src-strategy.d.ts +12 -0
  423. package/dist/types/components/vega-rich-text-editor/extensions/paste/actions/image-replace-src-action.d.ts +11 -0
  424. package/dist/types/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/paste-image-parser.d.ts +136 -0
  425. package/dist/types/components/vega-rich-text-editor/extensions/paste/parse-local-images-helper/pending-image-registry.d.ts +68 -0
  426. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-chooser-ui.d.ts +9 -4
  427. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-extension.d.ts +39 -2
  428. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/default-paste-strategy.d.ts +29 -0
  429. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/paste-processing-strategy.abstract.d.ts +61 -0
  430. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/paste-strategy-selector.d.ts +45 -0
  431. package/dist/types/components/vega-rich-text-editor/extensions/paste/strategies/word-paste-strategy.d.ts +186 -0
  432. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-code-block-transformer.d.ts +51 -0
  433. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-image-transformer.d.ts +86 -0
  434. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-list-transformer.d.ts +271 -0
  435. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-paragraph-transformer.d.ts +25 -0
  436. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-table-transformer.d.ts +240 -0
  437. package/dist/types/components/vega-rich-text-editor/extensions/paste/word-paste-transformers/word-structure-transformer.d.ts +36 -0
  438. package/dist/types/components/vega-rich-text-editor/extensions/table/dto/table-block.d.ts +8 -0
  439. package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-caption-renderer.d.ts +2 -2
  440. package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-dynamic-popover-renderer.d.ts +31 -1
  441. package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-popover-base-renderer.d.ts +91 -0
  442. package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-renderer.d.ts +46 -0
  443. package/dist/types/components/vega-rich-text-editor/extensions/table/renderers/table-setting-popover-renderer.d.ts +58 -0
  444. package/dist/types/components/vega-rich-text-editor/extensions/table/table-selection.d.ts +8 -0
  445. package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/slimmers/renderers/vega-rich-text-table-properties-basic-form-field-renderer.abstract.d.ts +2 -1
  446. package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-properties/vega-rich-text-table-properties.d.ts +2 -0
  447. package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/row-button-slimmer.d.ts +3 -0
  448. package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/slimmers/renderers/table-setting-button-slimmer.abstract.d.ts +3 -1
  449. package/dist/types/components/vega-rich-text-editor/extensions/table/vega-rich-text-table-setting/vega-rich-text-table-setting.d.ts +1 -0
  450. package/dist/types/components/vega-rich-text-editor/extensions/tokens/span-to-token-node-strategy.d.ts +2 -2
  451. package/dist/types/components/vega-rich-text-editor/extensions/tokens/token-node.d.ts +19 -1
  452. package/dist/types/components/vega-rich-text-editor/extensions/word-count/action-handler-interceptors/prevent-hard-limit-exceed-interceptor.d.ts +38 -0
  453. package/dist/types/components/vega-rich-text-editor/extensions/word-count/type.d.ts +46 -0
  454. package/dist/types/components/vega-rich-text-editor/extensions/word-count/word-count-extension.d.ts +38 -0
  455. package/dist/types/components/vega-rich-text-editor/interface.d.ts +22 -0
  456. package/dist/types/components/vega-rich-text-editor/public-api.d.ts +1 -0
  457. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/annotation-handler/text-style-annotation-handler.d.ts +4 -1
  458. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/helper/element-to-dto-strategy/continue-inline-to-rte-text-block-strategy.d.ts +8 -0
  459. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/value-controller.d.ts +11 -1
  460. package/dist/types/components/vega-rich-text-editor/slimmers/controllers/word-count-controller.d.ts +40 -0
  461. package/dist/types/components/vega-rich-text-editor/slimmers/renderers/tools/link-toolbar-button-slimmer.d.ts +14 -0
  462. package/dist/types/components/vega-rich-text-editor/slimmers/renderers/tools/source-edit-toolbar-button-slimmer.d.ts +4 -1
  463. package/dist/types/components/vega-rich-text-editor/slimmers/renderers/tools/toolbar-button-slimmer.abstract.d.ts +3 -2
  464. package/dist/types/components/vega-rich-text-editor/slimmers/renderers/vega-rich-text-editor-renderer.d.ts +12 -0
  465. package/dist/types/components/vega-rich-text-editor/vega-rich-text-editor-toolbar-button/vega-rich-text-editor-toolbar-button.d.ts +2 -0
  466. package/dist/types/components/vega-rich-text-editor/vega-rich-text-editor.d.ts +4 -0
  467. package/dist/types/components/vega-rich-text-editor/vega-rich-text-link-editor/slimmers/controllers/link-editor-controller.d.ts +68 -0
  468. package/dist/types/components/vega-rich-text-editor/vega-rich-text-link-editor/slimmers/renderers/vega-rich-text-link-editor-renderer.d.ts +3 -0
  469. package/dist/types/components/vega-tab-group/slimmers/vega-tab-group/renderers/vega-tab-group-tab-list-renderer.d.ts +1 -0
  470. package/dist/types/components/vega-tab-group/types.d.ts +3 -1
  471. package/dist/types/components/vega-tab-group/vega-tab-group.d.ts +2 -0
  472. package/dist/types/components/vega-table/interface.d.ts +4 -4
  473. package/dist/types/components/vega-table/slimmers/controllers/vega-table-body-col-span-controller.d.ts +16 -0
  474. package/dist/types/components/vega-table/slimmers/renderers/vega-table-body-col-span-resolver.d.ts +8 -10
  475. package/dist/types/helpers/keyboard/keyboard-manager.d.ts +9 -0
  476. package/dist/types/helpers/keyboard/overlay-escape-coordination.d.ts +28 -0
  477. package/dist/types/helpers/slimmers/mutation-observer/aria-attributes-value-mapper.d.ts +1 -1
  478. package/dist/types/helpers/translation/interface.d.ts +18 -1
  479. package/dist/types/polyfill/libphonenumber/as-you-type.d.ts +1 -0
  480. package/dist/types/polyfill/libphonenumber/metadata.d.ts +10 -0
  481. package/dist/types/types/public-api.d.ts +2 -0
  482. package/dist/types/utils/accessibility.d.ts +9 -0
  483. package/dist/types/utils/sanitize/index.d.ts +3 -2
  484. package/dist/types/utils/sanitize/strategies/index.d.ts +1 -0
  485. package/dist/types/utils/sanitize/strategies/label-sanitize-strategy.d.ts +9 -0
  486. package/dist/types/utils/sanitize/strategies/plain-text-sanitize-strategy.d.ts +36 -0
  487. package/dist/vega/index.esm.js +1 -1
  488. package/dist/vega/{p-6f537797.entry.js → p-01ca92e6.entry.js} +1 -1
  489. package/dist/vega/{p-02d3ce79.entry.js → p-02b5d4ac.entry.js} +1 -1
  490. package/dist/vega/p-06a42a9f.entry.js +1 -0
  491. package/dist/vega/{p-fd23c365.entry.js → p-0cd362f3.entry.js} +1 -1
  492. package/dist/vega/p-0e10798b.entry.js +1 -0
  493. package/dist/vega/{p-2c2e8615.js → p-0eea1ca8.js} +1 -1
  494. package/dist/vega/{p-c98c2f5f.entry.js → p-0f344e02.entry.js} +1 -1
  495. package/dist/vega/{p-4cbfc01e.entry.js → p-23db0a92.entry.js} +1 -1
  496. package/dist/vega/{p-ccbe3f1b.entry.js → p-284a8828.entry.js} +1 -1
  497. package/dist/vega/{p-ac94ba1b.entry.js → p-2b26e182.entry.js} +1 -1
  498. package/dist/vega/{p-56598858.entry.js → p-2c8dc0d2.entry.js} +1 -1
  499. package/dist/vega/{p-2bb5a232.js → p-3091b105.js} +1 -1
  500. package/dist/vega/{p-9abf7d0a.entry.js → p-35d37477.entry.js} +1 -1
  501. package/dist/vega/{p-526e3634.js → p-36a57431.js} +1 -1
  502. package/dist/vega/{p-810c9c29.js → p-379736e2.js} +1 -1
  503. package/dist/vega/p-3abb793c.entry.js +1 -0
  504. package/dist/vega/{p-f29ea345.entry.js → p-3d6a43df.entry.js} +1 -1
  505. package/dist/vega/{p-c2277448.entry.js → p-3f2a4b34.entry.js} +1 -1
  506. package/dist/vega/p-401c6764.js +1 -0
  507. package/dist/vega/{p-da867019.entry.js → p-411cadbc.entry.js} +1 -1
  508. package/dist/vega/{p-ec64cc59.entry.js → p-46f22f6c.entry.js} +1 -1
  509. package/dist/vega/{p-8d2501b2.js → p-493108d5.js} +1 -1
  510. package/dist/vega/{p-085d1647.entry.js → p-49de5559.entry.js} +1 -1
  511. package/dist/vega/{p-781b7a54.js → p-4b35c748.js} +1 -1
  512. package/dist/vega/{p-a8174ad8.entry.js → p-4d1896e0.entry.js} +1 -1
  513. package/dist/vega/{p-b00ec194.entry.js → p-4e23e56c.entry.js} +1 -1
  514. package/dist/vega/{p-1cff027b.entry.js → p-5006404e.entry.js} +1 -1
  515. package/dist/vega/{p-56417ec5.entry.js → p-5789690b.entry.js} +1 -1
  516. package/dist/vega/{p-461100b8.entry.js → p-594cb986.entry.js} +1 -1
  517. package/dist/vega/p-5a086e93.js +1 -0
  518. package/dist/vega/{p-3e09aeed.js → p-5b3c8a56.js} +1 -1
  519. package/dist/vega/p-5b9b1631.entry.js +1 -0
  520. package/dist/vega/{p-c41a2d4a.js → p-5c3649f9.js} +1 -1
  521. package/dist/vega/{p-fb9475ab.entry.js → p-5d9be870.entry.js} +1 -1
  522. package/dist/vega/p-5f377954.js +1 -1
  523. package/dist/vega/{p-d609c3fd.js → p-60a74fb7.js} +1 -1
  524. package/dist/vega/{p-2acf9b42.entry.js → p-61ed7268.entry.js} +1 -1
  525. package/dist/vega/p-6336d446.entry.js +1 -0
  526. package/dist/vega/{p-dbb4b1d1.js → p-638b6a7d.js} +1 -1
  527. package/dist/vega/{p-bdb5180c.js → p-68744e7e.js} +1 -1
  528. package/dist/vega/p-6e9e7131.js +1 -0
  529. package/dist/vega/{p-014cd411.js → p-6eedbc4f.js} +1 -1
  530. package/dist/vega/{p-a090b2be.js → p-6fd8f14b.js} +1 -1
  531. package/dist/vega/{p-0cf3b5c1.entry.js → p-7469d0d1.entry.js} +1 -1
  532. package/dist/vega/p-74b20563.entry.js +1 -0
  533. package/dist/vega/{p-17c69503.entry.js → p-76999ea1.entry.js} +1 -1
  534. package/dist/vega/p-77bcdd35.js +1 -0
  535. package/dist/vega/{p-035e2f05.entry.js → p-79b49e8d.entry.js} +1 -1
  536. package/dist/vega/{p-8d96f0e8.entry.js → p-7a03ef96.entry.js} +1 -1
  537. package/dist/vega/{p-c5fb8a69.entry.js → p-7ae4cf82.entry.js} +1 -1
  538. package/dist/vega/{p-f9bfee81.entry.js → p-7cc8855d.entry.js} +1 -1
  539. package/dist/vega/{p-d470fce2.entry.js → p-7ddc0bec.entry.js} +1 -1
  540. package/dist/vega/{p-ca3c1317.entry.js → p-7e22610b.entry.js} +1 -1
  541. package/dist/vega/p-7f395622.entry.js +1 -0
  542. package/dist/vega/{p-3737b9e2.entry.js → p-816b5fd2.entry.js} +1 -1
  543. package/dist/vega/p-8387896e.js +1 -0
  544. package/dist/vega/p-844ad6aa.entry.js +1 -0
  545. package/dist/vega/p-853a05eb.js +1 -0
  546. package/dist/vega/p-85de755f.js +1 -0
  547. package/dist/vega/p-8663314e.js +1 -0
  548. package/dist/vega/{p-95c18f79.entry.js → p-86fb46d2.entry.js} +1 -1
  549. package/dist/vega/p-8cfdd0e8.entry.js +1 -0
  550. package/dist/vega/p-8ebe30a8.js +1 -0
  551. package/dist/vega/p-8f00dfe6.js +1 -0
  552. package/dist/vega/{p-66647244.js → p-8fc0a820.js} +1 -1
  553. package/dist/vega/{p-4fd0cf01.js → p-9034f709.js} +1 -1
  554. package/dist/vega/{p-456f678b.js → p-941a83db.js} +1 -1
  555. package/dist/vega/{p-ae2abdfa.js → p-96c090c4.js} +1 -1
  556. package/dist/vega/p-9ba2fdff.js +1 -0
  557. package/dist/vega/{p-d319ebb5.js → p-9e9f49f4.js} +1 -1
  558. package/dist/vega/p-9efa5d76.js +1 -0
  559. package/dist/vega/{p-a81ad3bd.js → p-a306bb39.js} +1 -1
  560. package/dist/vega/{p-db11134b.entry.js → p-a48468b5.entry.js} +1 -1
  561. package/dist/vega/{p-56db3323.js → p-a488447f.js} +1 -1
  562. package/dist/vega/p-a647c856.entry.js +1 -0
  563. package/dist/vega/{p-a484e32d.entry.js → p-a6a89f09.entry.js} +1 -1
  564. package/dist/vega/p-a92cd703.js +1 -0
  565. package/dist/vega/p-a93b3aed.js +1 -0
  566. package/dist/vega/{p-528748fa.js → p-aa135628.js} +1 -1
  567. package/dist/vega/{p-4bfe3258.entry.js → p-aaaf21eb.entry.js} +1 -1
  568. package/dist/vega/{p-36d9e782.entry.js → p-ab253867.entry.js} +1 -1
  569. package/dist/vega/{p-dcd3e3a7.js → p-ab9d53e9.js} +1 -1
  570. package/dist/vega/p-ad367b48.entry.js +1 -0
  571. package/dist/vega/{p-e18c0656.entry.js → p-af0cfea0.entry.js} +1 -1
  572. package/dist/vega/p-b07f587a.entry.js +1 -0
  573. package/dist/vega/p-b21cc390.entry.js +1 -0
  574. package/dist/vega/{p-12e8a1b2.js → p-b2a4314a.js} +1 -1
  575. package/dist/vega/p-b52d7724.js +3 -0
  576. package/dist/vega/{p-5f96e741.entry.js → p-b97ed9f7.entry.js} +1 -1
  577. package/dist/vega/{p-7dcd2850.entry.js → p-bc0e5598.entry.js} +1 -1
  578. package/dist/vega/p-bc119e75.entry.js +1 -0
  579. package/dist/vega/{p-0cbf09f7.entry.js → p-bedb575c.entry.js} +1 -1
  580. package/dist/vega/{p-cb81126a.entry.js → p-bfe5dff7.entry.js} +1 -1
  581. package/dist/vega/{p-52c69f9e.entry.js → p-c032f626.entry.js} +1 -1
  582. package/dist/vega/{p-1ea9ad9a.js → p-c34f4cbc.js} +1 -1
  583. package/dist/vega/{p-72ab5cd5.entry.js → p-c422ee02.entry.js} +1 -1
  584. package/dist/vega/{p-39c5054b.js → p-c576e846.js} +1 -1
  585. package/dist/vega/{p-c70748f7.entry.js → p-c7d46740.entry.js} +1 -1
  586. package/dist/vega/p-cc569b54.js +1 -0
  587. package/dist/vega/{p-4e065ef7.entry.js → p-cd04b149.entry.js} +1 -1
  588. package/dist/vega/{p-2a245138.entry.js → p-cd0a108b.entry.js} +1 -1
  589. package/dist/vega/{p-8c56d74d.entry.js → p-d1bb6e7a.entry.js} +1 -1
  590. package/dist/vega/{p-200c8914.entry.js → p-d340ee3d.entry.js} +1 -1
  591. package/dist/vega/p-d897acd5.js +1 -0
  592. package/dist/vega/p-debf9e06.entry.js +1 -0
  593. package/dist/vega/p-e0a51e49.js +1 -0
  594. package/dist/vega/{p-1aedbfd2.entry.js → p-e11c6ec4.entry.js} +1 -1
  595. package/dist/vega/{p-1e0a8fd3.js → p-e14323f3.js} +1 -1
  596. package/dist/vega/{p-6d4518d7.entry.js → p-e5abc288.entry.js} +1 -1
  597. package/dist/vega/{p-544ce391.entry.js → p-ea1a0046.entry.js} +1 -1
  598. package/dist/vega/{p-72fd17a1.entry.js → p-edd7aa92.entry.js} +1 -1
  599. package/dist/vega/p-ef1bbf14.js +1 -0
  600. package/dist/vega/{p-9834d5d4.entry.js → p-efc08027.entry.js} +1 -1
  601. package/dist/vega/{p-874e5624.js → p-f485448a.js} +1 -1
  602. package/dist/vega/{p-92528dc9.entry.js → p-f8b2dbb9.entry.js} +1 -1
  603. package/dist/vega/{p-cf4b3d40.entry.js → p-f8bf379c.entry.js} +1 -1
  604. package/dist/vega/{p-b98ead05.entry.js → p-f902305d.entry.js} +1 -1
  605. package/dist/vega/p-fe985b52.js +1 -0
  606. package/dist/vega/vega.esm.js +1 -1
  607. package/package.json +1 -1
  608. package/dist/collection/components/vega-dropdown/slimmers/controllers/vega-dropdown-keyboard-conttroller.js +0 -85
  609. package/dist/collection/components/vega-rich-text-editor/extensions/paste/paste-constants.js +0 -6
  610. package/dist/types/components/vega-rich-text-editor/extensions/paste/paste-constants.d.ts +0 -6
  611. package/dist/vega/p-03eeadc1.entry.js +0 -1
  612. package/dist/vega/p-0eb29065.js +0 -3
  613. package/dist/vega/p-10d30c03.js +0 -1
  614. package/dist/vega/p-1250b1ab.entry.js +0 -1
  615. package/dist/vega/p-1abd3c17.js +0 -1
  616. package/dist/vega/p-2d158cbd.js +0 -1
  617. package/dist/vega/p-2f07d719.entry.js +0 -1
  618. package/dist/vega/p-36d2df7a.entry.js +0 -1
  619. package/dist/vega/p-373541fa.js +0 -1
  620. package/dist/vega/p-3a620268.js +0 -1
  621. package/dist/vega/p-3d0b4074.js +0 -1
  622. package/dist/vega/p-56493601.js +0 -1
  623. package/dist/vega/p-571ec00b.js +0 -1
  624. package/dist/vega/p-585e4f1c.entry.js +0 -1
  625. package/dist/vega/p-5b1f5e4a.entry.js +0 -1
  626. package/dist/vega/p-6234852e.entry.js +0 -1
  627. package/dist/vega/p-67eaf77e.js +0 -1
  628. package/dist/vega/p-6c95a6a3.js +0 -1
  629. package/dist/vega/p-6fd4f2c6.js +0 -1
  630. package/dist/vega/p-7e8fdac4.js +0 -1
  631. package/dist/vega/p-83ad8988.js +0 -1
  632. package/dist/vega/p-94975537.entry.js +0 -1
  633. package/dist/vega/p-a91927eb.entry.js +0 -1
  634. package/dist/vega/p-b3733762.entry.js +0 -1
  635. package/dist/vega/p-b622c455.js +0 -1
  636. package/dist/vega/p-c6d775b8.entry.js +0 -1
  637. package/dist/vega/p-cd69aeae.js +0 -1
  638. package/dist/vega/p-cfe268a8.entry.js +0 -1
  639. package/dist/vega/p-daba4af1.js +0 -1
  640. package/dist/vega/p-de8f0d98.js +0 -1
  641. package/dist/vega/p-f0e828d8.js +0 -1
  642. package/dist/vega/p-f62c5a20.entry.js +0 -1
  643. package/dist/vega/p-f6c0e9e7.entry.js +0 -1
  644. package/dist/vega/p-fa65956c.entry.js +0 -1
  645. /package/dist/types/components/vega-dropdown/slimmers/controllers/{vega-dropdown-keyboard-conttroller.d.ts → vega-dropdown-keyboard-controller.d.ts} +0 -0
@@ -8,27 +8,27 @@ const internalVegaZIndexManager = require('./internal-vega-z-index-manager-f03dd
8
8
  const dynamicSlimmer = require('./dynamic-slimmer-f31fdfd7.js');
9
9
  const pageResizeObserverSlimmer = require('./page-resize-observer-slimmer-273d62ef.js');
10
10
  const internalVegaEventManager = require('./internal-vega-event-manager-7003c84a.js');
11
- const internalTranslationController = require('./internal-translation-controller-1dac2df8.js');
12
- const internalCalendarPeriodFactory = require('./internal-calendar-period-factory-dfcdd3f6.js');
13
- const linkExtension = require('./link-extension-220ff6a9.js');
14
- const codeBlock = require('./code-block-d78c2b2c.js');
15
- const contentState = require('./content-state-78a620a9.js');
16
- const typeGuard = require('./type-guard-a57ef3ac.js');
11
+ const internalTranslationController = require('./internal-translation-controller-27bfc8c7.js');
12
+ const internalCalendarPeriodFactory = require('./internal-calendar-period-factory-b11918ee.js');
13
+ const codeBlock = require('./code-block-3b42c364.js');
14
+ const contentState = require('./content-state-87a06c1a.js');
15
+ const typeGuard = require('./type-guard-00b8efc0.js');
16
+ const linkExtension = require('./link-extension-71eeaa9f.js');
17
17
  const internalIconManager = require('./internal-icon-manager-40bcac72.js');
18
18
  const vegaNonceManager = require('./vega-nonce-manager-df69d3ed.js');
19
19
  const domNodeSubjectObserverFactory = require('./dom-node-subject-observer-factory-c82df135.js');
20
20
  const vegaEventId = require('./vega-event-id-58afed7a.js');
21
- const splitCellOperation = require('./split-cell-operation-873d5db7.js');
21
+ const splitCellOperation = require('./split-cell-operation-ef783850.js');
22
22
  const changeManager = require('./change-manager-a297e4d2.js');
23
23
  const vegaInternalEventId = require('./vega-internal-event-id-f4d33037.js');
24
24
  const remoteInvocationRegistry = require('./remote-invocation-registry-fc22fdd0.js');
25
- const darkModeStyleController = require('./dark-mode-style-controller-32d4054a.js');
25
+ const darkModeStyleController = require('./dark-mode-style-controller-f3da3342.js');
26
26
  const tryGetDocument = require('./try-get-document-c0ebd39a.js');
27
27
  const pixel = require('./pixel-98f2a10c.js');
28
28
  const object = require('./object-b53e9416.js');
29
29
  const timer = require('./timer-5f33058b.js');
30
30
  const string = require('./string-39438062.js');
31
- const imageExtension = require('./image-extension-260fa69c.js');
31
+ const imageExtension = require('./image-extension-ccda26d3.js');
32
32
  const copy = require('./copy-d021c780.js');
33
33
 
34
34
  const VegaLoaderRuntimeMetricsPayloadDefinition = [
@@ -1105,7 +1105,7 @@ class VegaRTEToolbarButtonRenderer {
1105
1105
  * @returns {Nullable<RTEExtensionContext>} - The extension context associated with the host.
1106
1106
  */
1107
1107
  getExtensionContext(el) {
1108
- return linkExtension.RTEExtensionContextManager.getExtensionContext(el);
1108
+ return linkExtension.extensionContextManager.getExtensionContext(el);
1109
1109
  }
1110
1110
  /**
1111
1111
  * Renders a dropdown component with the specified properties and children.
@@ -1117,7 +1117,7 @@ class VegaRTEToolbarButtonRenderer {
1117
1117
  * @returns {VegaRTERenderResult} - The render result for the dropdown.
1118
1118
  */
1119
1119
  renderDropdown(h, editorContext, dropdownProps, children) {
1120
- return h('vega-dropdown', Object.assign({ trigger: 'click', searchable: false, maxWidth: '200', itemDisplayRule: 'ellipsis', isScreenPosition: true,
1120
+ return h('vega-dropdown', Object.assign({ trigger: 'click', searchable: false, maxWidth: '200', itemDisplayRule: 'ellipsis', isScreenPosition: true, role: 'presentation',
1121
1121
  // eslint-disable-next-line jsdoc/require-jsdoc
1122
1122
  ref: (el) => {
1123
1123
  this.dropdownEl = el;
@@ -1201,29 +1201,31 @@ class VegaRTEToolbarButtonRenderer {
1201
1201
  * @returns {VegaRTERenderResult} - The render result for the button.
1202
1202
  */
1203
1203
  renderButton(h, editorContext, buttonProps) {
1204
- const { icon, label, showArrowIcon, tooltip } = buttonProps;
1204
+ const { icon, label, showArrowIcon, tooltip, ariaLabel } = buttonProps;
1205
1205
  const isDisabled = this.isDisabled(editorContext);
1206
1206
  const button = h('vega-rich-text-editor-toolbar-button', {
1207
- disabled: isDisabled,
1208
- icon: icon,
1209
- hidden: this.isHidden(editorContext),
1210
- selected: this.isSelected(editorContext),
1207
+ 'disabled': isDisabled,
1208
+ 'icon': icon,
1209
+ 'data-aria-label': ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : label,
1210
+ 'hidden': this.isHidden(editorContext),
1211
+ 'selected': this.isSelected(editorContext),
1211
1212
  // eslint-disable-next-line jsdoc/require-jsdoc
1212
- ref: (el) => {
1213
+ 'ref': (el) => {
1213
1214
  this.buttonEl = el;
1214
1215
  domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(el, vegaEventId.VegaClick, () => this.handleButtonClick(editorContext));
1215
1216
  },
1216
- onMouseDown: this.preventDefault,
1217
+ 'onMouseDown': this.preventDefault,
1217
1218
  // eslint-disable-next-line jsdoc/require-jsdoc
1218
- onKeyDown: (e) => this.handleButtonKeyDown(e),
1219
+ 'onKeyDown': (e) => this.handleButtonKeyDown(e),
1219
1220
  }, [
1220
1221
  this.renderButtonLabel(h, editorContext, label),
1221
1222
  showArrowIcon
1222
1223
  ? h('vega-icon', {
1223
- size: 'size-8',
1224
- color: isDisabled ? 'text-disabled' : 'text-secondary',
1225
- style: { marginLeft: '8px' },
1226
- icon: internalIconManager.VegaInternalIconManager.getIconKey('chevron-down'),
1224
+ 'size': 'size-8',
1225
+ 'color': isDisabled ? 'text-disabled' : 'text-secondary',
1226
+ 'style': { marginLeft: '8px' },
1227
+ 'aria-hidden': 'true',
1228
+ 'icon': internalIconManager.VegaInternalIconManager.getIconKey('chevron-down'),
1227
1229
  })
1228
1230
  : null,
1229
1231
  ].filter(typeGuard.isNonNullable));
@@ -1244,8 +1246,9 @@ class VegaRTEToolbarButtonRenderer {
1244
1246
  if (label) {
1245
1247
  const isDisabled = this.isDisabled(editorContext);
1246
1248
  return h('vega-font', {
1247
- variant: 'font-field-label-sm',
1248
- color: isDisabled ? 'text-disabled' : 'text-primary',
1249
+ 'variant': 'font-field-label-sm',
1250
+ 'color': isDisabled ? 'text-disabled' : 'text-primary',
1251
+ 'aria-hidden': 'true',
1249
1252
  }, editorContext.translation.t(label));
1250
1253
  }
1251
1254
  return null;
@@ -1277,6 +1280,15 @@ class VegaRTEToolbarButtonRenderer {
1277
1280
  preventDefault(e) {
1278
1281
  e.preventDefault();
1279
1282
  }
1283
+ /**
1284
+ * Moves focus to the toolbar button. Targets the inner focusable `<button>`
1285
+ * inside the button's shadow root, falling back to the host element.
1286
+ */
1287
+ focusToolbarButton() {
1288
+ var _a, _b, _c, _d;
1289
+ const innerButton = (_c = (_b = (_a = this.buttonEl) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('button')) !== null && _c !== void 0 ? _c : null;
1290
+ (_d = (innerButton !== null && innerButton !== void 0 ? innerButton : this.buttonEl)) === null || _d === void 0 ? void 0 : _d.focus();
1291
+ }
1280
1292
  /**
1281
1293
  * Recursively searches for a dropdown list item by its key.
1282
1294
  *
@@ -1330,14 +1342,14 @@ class VegaRTEToolbarButtonRenderer {
1330
1342
  * @param {KeyboardEvent} e The keyboard event.
1331
1343
  */
1332
1344
  handleItemsKeyDown(e) {
1333
- var _a, _b, _c;
1345
+ var _a, _b;
1334
1346
  if (e.code === 'Escape') {
1335
1347
  e.preventDefault();
1336
1348
  e.stopPropagation();
1337
1349
  if (this.dropdownEl) {
1338
1350
  void this.dropdownEl.hide();
1339
1351
  }
1340
- (_a = this.buttonEl) === null || _a === void 0 ? void 0 : _a.focus();
1352
+ this.focusToolbarButton();
1341
1353
  return;
1342
1354
  }
1343
1355
  if (e.code !== 'ArrowDown' && e.code !== 'ArrowUp') {
@@ -1355,7 +1367,7 @@ class VegaRTEToolbarButtonRenderer {
1355
1367
  for (let offset = 0; offset < items.length; offset++) {
1356
1368
  const index = (startIndex + offset * direction + items.length) % items.length;
1357
1369
  if (!items[index].disabled) {
1358
- (_c = (_b = items[index].shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('li')) === null || _c === void 0 ? void 0 : _c.focus();
1370
+ (_b = (_a = items[index].shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('li')) === null || _b === void 0 ? void 0 : _b.focus();
1359
1371
  return;
1360
1372
  }
1361
1373
  }
@@ -1425,6 +1437,7 @@ class RTETokenToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
1425
1437
  return this.renderDropdown(createElement, editorContext, {}, [
1426
1438
  this.renderButton(createElement, editorContext, {
1427
1439
  label: 'Tokens',
1440
+ ariaLabel: 'Tokens',
1428
1441
  showArrowIcon: true,
1429
1442
  tooltip: { text: 'Insert token' },
1430
1443
  }),
@@ -1544,6 +1557,47 @@ class RTETokenNode extends codeBlock.RTETextNode {
1544
1557
  toHtml() {
1545
1558
  return `<span class="token" contenteditable="false" template-token-key="${this.token}" token-key="${this.token}"${super.generateAttributeString()}>${this.text}</span>`;
1546
1559
  }
1560
+ /**
1561
+ * @inheritDoc
1562
+ */
1563
+ renderHtmlFromDepth(depth, options) {
1564
+ const annotation = this.getInlineHtmlAnnotationAtDepth(depth);
1565
+ if (!annotation)
1566
+ return this.toHtml();
1567
+ return this.renderTokenWithWrapperStr(annotation);
1568
+ }
1569
+ /**
1570
+ * Render token markup wrapped by inline HTML annotations, preserving token attributes.
1571
+ *
1572
+ * @param {InlineHtmlAnnotation} inlineHtmlNode - Current wrapper annotation.
1573
+ * @returns {string} Token HTML wrapped by inline HTML annotations.
1574
+ */
1575
+ renderTokenWithWrapperStr(inlineHtmlNode) {
1576
+ const { htmlTag, child } = inlineHtmlNode;
1577
+ const attrStr = this.inlineHtmlAnnotationAttrStr(inlineHtmlNode);
1578
+ if (!child) {
1579
+ if (codeBlock.HTML_VOID_TAGS.has(htmlTag)) {
1580
+ return `<${htmlTag}${attrStr}>`;
1581
+ }
1582
+ return `<${htmlTag}${attrStr}>${this.toHtml()}</${htmlTag}>`;
1583
+ }
1584
+ return `<${htmlTag}${attrStr}>${this.renderTokenWithWrapperStr(child)}</${htmlTag}>`;
1585
+ }
1586
+ /**
1587
+ * Build inline HTML wrapper attributes string.
1588
+ *
1589
+ * @param {InlineHtmlAnnotation} annotation - Inline HTML annotation.
1590
+ * @returns {string} Serialized attribute string.
1591
+ */
1592
+ inlineHtmlAnnotationAttrStr(annotation) {
1593
+ const { customAttribute, customClass, customStyle } = annotation;
1594
+ const attrs = [
1595
+ ...((customAttribute === null || customAttribute === void 0 ? void 0 : customAttribute.toString()) || []),
1596
+ customClass === null || customClass === void 0 ? void 0 : customClass.toString(),
1597
+ customStyle === null || customStyle === void 0 ? void 0 : customStyle.toString(),
1598
+ ].filter(typeGuard.isNonNullable);
1599
+ return attrs.length > 0 ? ` ${attrs.join(' ')}` : '';
1600
+ }
1547
1601
  }
1548
1602
  RTETokenNode.dtoName = 'RTETokenNode';
1549
1603
 
@@ -1667,6 +1721,7 @@ class RTELanguageToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
1667
1721
  return this.renderDropdown(createElement, editorContext, { source: translatedSource }, [
1668
1722
  this.renderButton(createElement, editorContext, {
1669
1723
  label: this.getLanguageLabelByKey(this.selectedLanguage),
1724
+ ariaLabel: 'Language',
1670
1725
  showArrowIcon: true,
1671
1726
  tooltip: { text: 'Select language' },
1672
1727
  }),
@@ -1682,10 +1737,11 @@ class RTELanguageToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
1682
1737
  this.translation = editorContext.translation;
1683
1738
  const isDisabled = this.isDisabled(editorContext);
1684
1739
  return h('vega-font', {
1685
- variant: 'font-field-label-sm',
1686
- color: isDisabled ? 'text-disabled' : 'text-primary',
1740
+ 'variant': 'font-field-label-sm',
1741
+ 'color': isDisabled ? 'text-disabled' : 'text-primary',
1742
+ 'aria-hidden': 'true',
1687
1743
  // eslint-disable-next-line jsdoc/require-jsdoc
1688
- ref: (el) => {
1744
+ 'ref': (el) => {
1689
1745
  this.labelRef = el;
1690
1746
  },
1691
1747
  }, editorContext.translation.t(label));
@@ -1855,6 +1911,7 @@ class VegaRTELanguageExtension extends linkExtension.VegaRTEExtension {
1855
1911
  options = {
1856
1912
  autoMatchFormat: (_a = host.sourceEditConfig.autoMatchFormat) !== null && _a !== void 0 ? _a : true,
1857
1913
  filterInlineStyles: host.sourceEditConfig.filterInlineStyles,
1914
+ blockBoundaryRegistry: this.extensionContext.blockBoundaryRegistry,
1858
1915
  };
1859
1916
  }
1860
1917
  result = contentState.VegaRTEContent.fromHtml(codeBlock.value.code, options);
@@ -1880,6 +1937,15 @@ class InsertFunctionBlockAction extends codeBlock.ModifyContentAction {
1880
1937
  }
1881
1938
  }
1882
1939
 
1940
+ const FUNCTION_BLOCK_CLASS = 'statement';
1941
+ const FUNCTION_CONTENT_CLASS = 'statementelement';
1942
+ const FUNCTION_SYNTAX_CLASS = 'statementsyntax';
1943
+ const FUNCTION_ELEMENT_CLASSES = [
1944
+ FUNCTION_BLOCK_CLASS,
1945
+ FUNCTION_CONTENT_CLASS,
1946
+ FUNCTION_SYNTAX_CLASS,
1947
+ ];
1948
+
1883
1949
  /**
1884
1950
  * RTE Function Block
1885
1951
  */
@@ -1899,7 +1965,7 @@ class RTEFunctionBlock extends codeBlock.RTEBlock {
1899
1965
  */
1900
1966
  static from(block, options) {
1901
1967
  const functionBlock = new RTEFunctionBlock(block.id);
1902
- const defaultAnnotation = { customClass: ['statement'] };
1968
+ const defaultAnnotation = { customClass: [FUNCTION_BLOCK_CLASS] };
1903
1969
  let { annotations } = block;
1904
1970
  annotations = annotations
1905
1971
  ? Object.assign(Object.assign({}, annotations), defaultAnnotation) : defaultAnnotation;
@@ -1917,14 +1983,14 @@ class RTEFunctionBlock extends codeBlock.RTEBlock {
1917
1983
  .map((child) => {
1918
1984
  if (child instanceof codeBlock.RTETextBlock) {
1919
1985
  const attrStr = this.getFunctionContentStyle(child);
1920
- return `<div class="statementelement"${attrStr}>${child.getChildrenHtml()}</div>`;
1986
+ return `<div class="${FUNCTION_CONTENT_CLASS}"${attrStr}>${child.getChildrenHtml()}</div>`;
1921
1987
  }
1922
1988
  else {
1923
1989
  return child.toHtml();
1924
1990
  }
1925
1991
  })
1926
1992
  .join('');
1927
- return `<div class="statement">${childrenHtml}</div>`;
1993
+ return `<div class="${FUNCTION_BLOCK_CLASS}" ${codeBlock.RTE_BLOCK_BOUNDARY_ATTRIBUTE}>${childrenHtml}</div>`;
1928
1994
  }
1929
1995
  /**
1930
1996
  * @inheritDoc
@@ -1945,6 +2011,15 @@ class RTEFunctionBlock extends codeBlock.RTEBlock {
1945
2011
  getLastNode() {
1946
2012
  return this.children[this.children.length - 1].getLastNode();
1947
2013
  }
2014
+ /**
2015
+ * The function block is an atomic caret boundary: descending would resolve the caret onto a
2016
+ * `contenteditable="false"` logic-control node instead of staying anchored to the block.
2017
+ *
2018
+ * @inheritDoc
2019
+ */
2020
+ allowsCaretDescend() {
2021
+ return false;
2022
+ }
1948
2023
  /**
1949
2024
  * @inheritDoc
1950
2025
  */
@@ -2018,7 +2093,7 @@ class InsertFunctionBlockStrategy extends codeBlock.ActionHandleStrategy {
2018
2093
  {
2019
2094
  id: `${id}-2`,
2020
2095
  annotations: {
2021
- customClass: ['statementelement'],
2096
+ customClass: [FUNCTION_CONTENT_CLASS],
2022
2097
  },
2023
2098
  type: 'paragraph',
2024
2099
  nodes: [
@@ -2037,7 +2112,7 @@ class InsertFunctionBlockStrategy extends codeBlock.ActionHandleStrategy {
2037
2112
  {
2038
2113
  id: `${id}-4`,
2039
2114
  annotations: {
2040
- customClass: ['statementelement'],
2115
+ customClass: [FUNCTION_CONTENT_CLASS],
2041
2116
  },
2042
2117
  type: 'paragraph',
2043
2118
  nodes: [
@@ -2137,6 +2212,12 @@ class RTELogicControlNode extends codeBlock.RTENode {
2137
2212
  isContentEditable() {
2138
2213
  return false;
2139
2214
  }
2215
+ /**
2216
+ * @inheritDoc
2217
+ */
2218
+ getPlainText() {
2219
+ return this.text;
2220
+ }
2140
2221
  }
2141
2222
  RTELogicControlNode.dtoName = 'RTELogicControlNode';
2142
2223
 
@@ -2188,7 +2269,7 @@ class RTELogicControlBlock extends codeBlock.RTEBlock {
2188
2269
  * @returns {string} - The HTML string of the logic control block.
2189
2270
  */
2190
2271
  toHtml() {
2191
- return `<div class='statementsyntax' contenteditable='false'>${this.statementText}</div>`;
2272
+ return `<div class='${FUNCTION_SYNTAX_CLASS}' contenteditable='false'>${this.statementText}</div>`;
2192
2273
  }
2193
2274
  /**
2194
2275
  * Clone the current block instance.
@@ -2225,6 +2306,7 @@ class FunctionToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
2225
2306
  return this.renderDropdown(h, editorContext, {}, [
2226
2307
  this.renderButton(h, editorContext, {
2227
2308
  label: 'Functions',
2309
+ ariaLabel: 'Functions',
2228
2310
  showArrowIcon: true,
2229
2311
  tooltip: { text: 'Insert function' },
2230
2312
  }),
@@ -2296,7 +2378,7 @@ class RTELogicControlBlockRenderer extends linkExtension.VegaRTEExtensionRendere
2296
2378
  doRender(h, renderData) {
2297
2379
  return h('div', {
2298
2380
  key: renderData.id,
2299
- class: 'statementsyntax',
2381
+ class: FUNCTION_SYNTAX_CLASS,
2300
2382
  ref: this.useRef(renderData),
2301
2383
  }, h('span', {
2302
2384
  key: `${renderData.id}-1`,
@@ -2306,13 +2388,48 @@ class RTELogicControlBlockRenderer extends linkExtension.VegaRTEExtensionRendere
2306
2388
  }
2307
2389
  }
2308
2390
 
2391
+ /**
2392
+ * Returns true when the element belongs to function extension blocks by semantic
2393
+ * boundary attribute or known function element classes.
2394
+ *
2395
+ * Use this helper for broad detection (e.g., extension-level boundary predicate
2396
+ * registration) where both container and child function elements should be
2397
+ * treated as part of the function block structure.
2398
+ *
2399
+ * @param {HTMLElement} element - Element to inspect.
2400
+ * @returns {boolean} Whether the element belongs to a function block structure.
2401
+ * @example
2402
+ * this.registerBlockBoundaryPredicate(isFunctionBlockElement);
2403
+ */
2404
+ const isFunctionBlockElement = (element) => {
2405
+ return (element.hasAttribute(codeBlock.RTE_BLOCK_BOUNDARY_ATTRIBUTE) ||
2406
+ FUNCTION_ELEMENT_CLASSES.some((functionClass) => element.classList.contains(functionClass)));
2407
+ };
2408
+ /**
2409
+ * Returns true when the element is a function block boundary container.
2410
+ *
2411
+ * Use this helper when conversion logic must identify only the function block
2412
+ * container element (the DIV that maps to RTEFunctionBlock), not function child
2413
+ * elements such as syntax/content nodes.
2414
+ *
2415
+ * @param {HTMLElement} element - Element to inspect.
2416
+ * @returns {boolean} Whether the element is a function block boundary container.
2417
+ * @example
2418
+ * if (isFunctionBoundaryContainer(element)) {
2419
+ * // map the DIV to RTEFunctionBlock
2420
+ * }
2421
+ */
2422
+ const isFunctionBoundaryContainer = (element) => {
2423
+ return (element.hasAttribute(codeBlock.RTE_BLOCK_BOUNDARY_ATTRIBUTE) || element.classList.contains(FUNCTION_BLOCK_CLASS));
2424
+ };
2425
+
2309
2426
  /**
2310
2427
  * Strategy to convert a div with class 'statementsyntax' into an RTELogicControlBlock DTO.
2311
2428
  */
2312
2429
  class DivToLogicControlBlockStrategy extends contentState.BlockToRTEBlockStrategyAbstract {
2313
2430
  constructor() {
2314
2431
  super(...arguments);
2315
- this.blockClassName = 'statementsyntax';
2432
+ this.blockClassName = FUNCTION_SYNTAX_CLASS;
2316
2433
  }
2317
2434
  /**
2318
2435
  * @inheritDoc
@@ -2355,7 +2472,7 @@ class DivToLogicControlBlockStrategy extends contentState.BlockToRTEBlockStrateg
2355
2472
  * @returns {boolean} True if the element is a child of a function block, false otherwise
2356
2473
  */
2357
2474
  isFunctionBlockChild(element) {
2358
- return !!(element.parentElement && element.parentElement.classList.contains('statement'));
2475
+ return !!(element.parentElement && isFunctionBoundaryContainer(element.parentElement));
2359
2476
  }
2360
2477
  }
2361
2478
 
@@ -2368,11 +2485,13 @@ class DivToFunctionBlockStrategy extends contentState.ElementToDTOStrategy {
2368
2485
  */
2369
2486
  canHandle(elementsArray, currentIndex) {
2370
2487
  const element = elementsArray[currentIndex];
2371
- return element &&
2372
- element.tagName === 'DIV' &&
2373
- element.classList.contains('statement') &&
2488
+ if (element.nodeType !== Node.ELEMENT_NODE)
2489
+ return 0;
2490
+ const isFunctionBoundary = isFunctionBoundaryContainer(element);
2491
+ return element.tagName === 'DIV' &&
2492
+ isFunctionBoundary &&
2374
2493
  element.childNodes.length &&
2375
- element.querySelector('.statementsyntax')
2494
+ element.querySelector(`.${FUNCTION_SYNTAX_CLASS}`)
2376
2495
  ? 1
2377
2496
  : 0;
2378
2497
  }
@@ -2384,7 +2503,7 @@ class DivToFunctionBlockStrategy extends contentState.ElementToDTOStrategy {
2384
2503
  id: misc.generateUUID(),
2385
2504
  type: 'function-block',
2386
2505
  annotations: {
2387
- customClass: ['statement'],
2506
+ customClass: [FUNCTION_BLOCK_CLASS],
2388
2507
  },
2389
2508
  children: [],
2390
2509
  });
@@ -2412,7 +2531,7 @@ class DivToFunctionBlockStrategy extends contentState.ElementToDTOStrategy {
2412
2531
  class DivToFunctionContentStrategy extends DivToLogicControlBlockStrategy {
2413
2532
  constructor() {
2414
2533
  super(...arguments);
2415
- this.blockClassName = 'statementelement';
2534
+ this.blockClassName = FUNCTION_CONTENT_CLASS;
2416
2535
  }
2417
2536
  /**
2418
2537
  * @inheritDoc
@@ -2420,16 +2539,31 @@ class DivToFunctionContentStrategy extends DivToLogicControlBlockStrategy {
2420
2539
  handle(elementsArray, options) {
2421
2540
  const element = elementsArray[0];
2422
2541
  const annotations = contentState.htmlElementToAnnotationGenerator.generate(codeBlock.RTETextBlock, element);
2423
- const nodes = Array.from(elementsArray[0].childNodes);
2424
2542
  return codeBlock.RTETextBlock.from({
2425
2543
  id: misc.generateUUID(),
2426
2544
  type: 'paragraph',
2427
2545
  annotations: Object.assign({ customClass: [this.blockClassName] }, annotations),
2428
- nodes: this.generateChildNodes(nodes, undefined, options),
2546
+ nodes: this.generateChildNodes(Array.from(elementsArray[0].childNodes), undefined, options),
2429
2547
  });
2430
2548
  }
2431
2549
  }
2432
2550
 
2551
+ /** Preserve a div that contains a function block during auto-formatting. */
2552
+ class FunctionBlockContainerStrategy extends contentState.HtmlBlockStrategy {
2553
+ /**
2554
+ * @inheritDoc
2555
+ */
2556
+ canHandle(elementsArray, currentIndex) {
2557
+ const element = elementsArray[currentIndex];
2558
+ if (element.nodeType !== Node.ELEMENT_NODE)
2559
+ return 0;
2560
+ const containsFunctionBlock = !!element.querySelector(`[${codeBlock.RTE_BLOCK_BOUNDARY_ATTRIBUTE}], .${FUNCTION_BLOCK_CLASS}`);
2561
+ return element.nodeName === 'DIV' && !isFunctionBlockElement(element) && containsFunctionBlock
2562
+ ? 1
2563
+ : 0;
2564
+ }
2565
+ }
2566
+
2433
2567
  const functionBlockStylesCss = "div.statement{padding:2px 4px;background:rgba(var(--v-bg-accent3-secondary, 255, 239, 200));border:1px solid rgba(var(--v-bg-accent3-primary, 255, 220, 131));border-radius:4px;display:flex;flex-direction:row;justify-content:flex-start;align-items:stretch;gap:4px}div.statement .statementsyntax{padding:3px 0;line-height:22px}.rich-text-content div.statement .statementsyntax,.rich-text-content div.statement .statementelement{display:inline-block}div.statement+div.statement{margin-top:2px}div.statement .statementsyntax span{color:rgb(38, 42, 255);font-weight:bold}div.statement .statementelement{padding:2px 4px;background:rgba(var(--v-bg-secondary, 245, 247, 247));border:1px solid rgba(var(--v-border-color-input-field, 171, 198, 216));border-radius:4px;margin:0;min-width:8px}";
2434
2568
 
2435
2569
  /**
@@ -2443,6 +2577,7 @@ class RTEFunctionBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
2443
2577
  return createElement('div', {
2444
2578
  key: renderData.id,
2445
2579
  class: this.getElementClassName(renderData),
2580
+ [codeBlock.RTE_BLOCK_BOUNDARY_ATTRIBUTE]: '',
2446
2581
  ref: this.useRef(renderData),
2447
2582
  });
2448
2583
  }
@@ -2462,8 +2597,8 @@ class RTEFunctionBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
2462
2597
  */
2463
2598
  getElementClassName(block) {
2464
2599
  let classes = block.getClasses();
2465
- if (classes.indexOf('statement') < 0) {
2466
- classes = 'statement ' + classes;
2600
+ if (classes.indexOf(FUNCTION_BLOCK_CLASS) < 0) {
2601
+ classes = FUNCTION_BLOCK_CLASS + ' ' + classes;
2467
2602
  }
2468
2603
  return classes.trim();
2469
2604
  }
@@ -2637,12 +2772,14 @@ class PastePlainTextStrategy extends codeBlock.ActionHandleStrategy {
2637
2772
  const convertLogicControlBlockStrategy = new DivToLogicControlBlockStrategy();
2638
2773
  const convertFunctionContentStrategy = new DivToFunctionContentStrategy();
2639
2774
  const convertFunctionBlockStrategy = new DivToFunctionBlockStrategy();
2775
+ const convertFunctionBlockContainerStrategy = new FunctionBlockContainerStrategy();
2640
2776
  /**
2641
2777
  * Function extension class for Vega Rich Text Editor.
2642
2778
  */
2643
2779
  class VegaRTEFunctionExtension extends linkExtension.VegaRTEExtension {
2644
2780
  constructor() {
2645
2781
  super();
2782
+ this.unregisterBlockBoundaryPredicate = null;
2646
2783
  this.registerBlockBasicStrategies(RTELogicControlBlock.name);
2647
2784
  this.registerBlockBasicStrategies(RTEFunctionBlock.name);
2648
2785
  this.preventFunctionBlockDefaultInsertNewParagraph();
@@ -2653,11 +2790,25 @@ class VegaRTEFunctionExtension extends linkExtension.VegaRTEExtension {
2653
2790
  this.registerElementToBlockDTOClassStrategy(convertLogicControlBlockStrategy);
2654
2791
  this.registerElementToBlockDTOClassStrategy(convertFunctionContentStrategy);
2655
2792
  this.registerElementToBlockDTOClassStrategy(convertFunctionBlockStrategy);
2793
+ this.registerElementToBlockDTOClassStrategy(convertFunctionBlockContainerStrategy);
2656
2794
  }
2657
2795
  /** @inheritDoc */
2658
2796
  prepareBeforeLoad(host) {
2659
2797
  this.registerToolbarButtonRenderer(VegaRTEFunctionExtension.TOOLBAR_BUTTON_KEY, new FunctionToolbarButtonRenderer(), host);
2660
2798
  }
2799
+ /** @inheritDoc */
2800
+ initialExtensionAfterLoad(context) {
2801
+ var _a;
2802
+ super.initialExtensionAfterLoad(context);
2803
+ (_a = this.unregisterBlockBoundaryPredicate) === null || _a === void 0 ? void 0 : _a.call(this);
2804
+ this.unregisterBlockBoundaryPredicate = this.registerBlockBoundaryPredicate(isFunctionBlockElement);
2805
+ }
2806
+ /** @inheritDoc */
2807
+ destroyExtension() {
2808
+ var _a;
2809
+ (_a = this.unregisterBlockBoundaryPredicate) === null || _a === void 0 ? void 0 : _a.call(this);
2810
+ this.unregisterBlockBoundaryPredicate = null;
2811
+ }
2661
2812
  /**
2662
2813
  * Remove the appen children strategies to prevent default insert new paragraph logic in function block
2663
2814
  */
@@ -2682,7 +2833,7 @@ class VegaRTEFunctionExtension extends linkExtension.VegaRTEExtension {
2682
2833
  })();
2683
2834
  VegaRTEFunctionExtension.TOOLBAR_BUTTON_KEY = 'functions';
2684
2835
 
2685
- const tableBlockStylesCss = ".v-rte--extension-table-container{display:table}table.v-rte--extension-table{border-collapse:collapse}table.v-rte--extension-table th,table.v-rte--extension-table td{border:1px solid #ddd;padding:12px;text-align:left;vertical-align:middle;min-width:55px;box-sizing:border-box;position:relative}table.v-rte--extension-table th{background-color:#f2f2f2}.rte-table-setting-popover,.rte-table-dynamic-popover{display:block}table.v-rte--extension-table .v-rte-table-cell-focused::after,table.v-rte--extension-table .v-rte-table-cell-selected::after{content:'';position:absolute;top:0;left:0;right:0;bottom:0;pointer-events:none;background-color:rgba(158, 207, 250, 0.3)}table.v-rte--extension-table:has(.v-rte-table-cell-selected){caret-color:transparent}table.v-rte--extension-table:has(.v-rte-table-cell-selected) ::selection{background-color:transparent}table.v-rte--extension-table:has(.v-rte-table-cell-selected) ::-moz-selection{background-color:transparent}.v-rte--extension-table-caption{padding:8px;border:1px solid #ddd;border-bottom:none;background-color:rgba(var(--v-bg-table-header, 240, 243, 247, 1));position:relative;display:table-caption;caption-side:top;min-height:22px;text-align:center;word-break:break-word;overflow-wrap:break-word}.v-rte--extension-table-caption.showPlaceholder::before{position:absolute;left:0;right:0;content:attr(data-placeholder);font-family:'Inter', sans-serif;font-size:16px;font-weight:400;line-height:24px;letter-spacing:0;color:rgba(var(--v-text-input-placeholder, 176, 180, 181, 1));text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
2836
+ const tableBlockStylesCss = ".v-rte--extension-table-container{display:table}table.v-rte--extension-table{border-collapse:collapse}table.v-rte--extension-table th,table.v-rte--extension-table td{border:1px solid #ddd;padding:12px;text-align:left;vertical-align:middle;min-width:55px;box-sizing:border-box;position:relative}table.v-rte--extension-table th:focus,table.v-rte--extension-table td:focus{outline:none}table.v-rte--extension-table th{background-color:#f2f2f2}.rte-table-setting-popover,.rte-table-dynamic-popover{display:block}table.v-rte--extension-table .v-rte-table-cell-focused::after,table.v-rte--extension-table .v-rte-table-cell-selected::after{content:'';position:absolute;top:0;left:0;right:0;bottom:0;pointer-events:none;background-color:rgba(158, 207, 250, 0.3)}table.v-rte--extension-table:has(.v-rte-table-cell-selected){caret-color:transparent}table.v-rte--extension-table:has(.v-rte-table-cell-selected) ::selection{background-color:transparent}table.v-rte--extension-table:has(.v-rte-table-cell-selected) ::-moz-selection{background-color:transparent}.v-rte--extension-table-caption{padding:8px;border:1px solid #ddd;border-bottom:none;background-color:rgba(var(--v-bg-table-header, 240, 243, 247, 1));position:relative;display:table-caption;caption-side:top;min-height:22px;text-align:center;word-break:break-word;overflow-wrap:break-word}.v-rte--extension-table-caption.showPlaceholder::before{position:absolute;left:0;right:0;content:attr(data-placeholder);font-family:'Inter', sans-serif;font-size:16px;font-weight:400;line-height:24px;letter-spacing:0;color:rgba(var(--v-text-input-placeholder, 176, 180, 181, 1));text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}";
2686
2837
 
2687
2838
  const DELETE_TABLE_BLOCK = 'DELETE_TABLE_BLOCK';
2688
2839
  /**
@@ -3300,9 +3451,42 @@ class CellPropertiesCancelEventHandler extends CellPropertiesEventHandler {
3300
3451
 
3301
3452
  /**
3302
3453
  * Base renderer for table-related popovers, providing common functionalities such as accessing the table extension context.
3454
+ *
3455
+ * Popovers that move keyboard/VoiceOver focus into themselves (the setting toolbar and the
3456
+ * properties dialog) share the same focus-restoration machinery: they make the editor content
3457
+ * `inert` while open, track Escape presses at the document level, and return focus (and the caret)
3458
+ * to the originating cell when an Escape dismisses the popover. That behavior lives here so the two
3459
+ * renderers do not each carry a copy; subclasses only supply the two pieces that differ — how to
3460
+ * resolve the editor content root ({@link getInertContentTarget}) and how to tell whether an event
3461
+ * originated inside their own popover subtree ({@link isEventWithinPopover}).
3303
3462
  */
3304
3463
  class TablePopoverBaseRenderer {
3305
3464
  constructor(renderContext) {
3465
+ /** The editor content element made inert while the popover holds focus, cached so it can be restored. */
3466
+ this.inertedContentEl = null;
3467
+ /** The table cell to return focus to when the popover is dismissed via Escape. */
3468
+ this.returnFocusCell = null;
3469
+ /** Tracks whether Escape was pressed while the popover was open. */
3470
+ this.escapePressed = false;
3471
+ /** Document the Escape tracker keydown listener is bound to, for later removal. */
3472
+ this.keydownListenerDocument = null;
3473
+ /**
3474
+ * Tracks Escape key presses that originate inside the popover so focus can be returned to the
3475
+ * originating cell when that Escape dismisses the popover. vega-popover's own Escape handler hides
3476
+ * the popover without restoring focus, so the restore is coordinated here.
3477
+ *
3478
+ * The listener is bound at the document level (the popover renders in a portal, so its Escape does
3479
+ * not bubble back to the table), so scope it to the popover subtree via {@link isEventWithinPopover}:
3480
+ * a stray Escape elsewhere must not arm the restore and hijack focus on a later non-Escape dismissal
3481
+ * (e.g. click-outside).
3482
+ *
3483
+ * @param {KeyboardEvent} event - The keydown event.
3484
+ */
3485
+ this.handleDocumentKeydown = (event) => {
3486
+ if (event.code === 'Escape' && this.isEventWithinPopover(event)) {
3487
+ this.escapePressed = true;
3488
+ }
3489
+ };
3306
3490
  this.renderContext = renderContext;
3307
3491
  }
3308
3492
  /**
@@ -3312,9 +3496,124 @@ class TablePopoverBaseRenderer {
3312
3496
  */
3313
3497
  getTableExtensionContext() {
3314
3498
  return this.renderContext
3315
- ? linkExtension.RTEExtensionContextManager.getExtensionContext(this.renderContext.host)
3499
+ ? linkExtension.extensionContextManager.getExtensionContext(this.renderContext.host)
3316
3500
  : null;
3317
3501
  }
3502
+ /**
3503
+ * Begins tracking so a later Escape can return focus to `returnCell`. Records the cell and clears
3504
+ * any stale Escape observed before the popover was opened.
3505
+ *
3506
+ * @param {Nullable<HTMLElement>} returnCell - The cell to return focus to if the popover is dismissed with Escape.
3507
+ */
3508
+ beginReturnFocusTracking(returnCell) {
3509
+ this.returnFocusCell = returnCell !== null && returnCell !== void 0 ? returnCell : null;
3510
+ this.escapePressed = false;
3511
+ }
3512
+ /**
3513
+ * Registers the document-level (capture phase) Escape tracker. The popover renders in a portal, so
3514
+ * its Escape does not bubble back to the table; observing on the document lets us know when to
3515
+ * return focus to the cell.
3516
+ *
3517
+ * @param {Document} doc - The document to bind the keydown listener to.
3518
+ */
3519
+ attachEscapeTracker(doc) {
3520
+ doc.addEventListener('keydown', this.handleDocumentKeydown, { capture: true });
3521
+ this.keydownListenerDocument = doc;
3522
+ }
3523
+ /**
3524
+ * Removes the document-level Escape tracker if one was registered.
3525
+ */
3526
+ detachEscapeTracker() {
3527
+ if (this.keydownListenerDocument) {
3528
+ this.keydownListenerDocument.removeEventListener('keydown', this.handleDocumentKeydown, {
3529
+ capture: true,
3530
+ });
3531
+ this.keydownListenerDocument = null;
3532
+ }
3533
+ }
3534
+ /**
3535
+ * Whether the given event originated inside this popover's subtree. Subclasses override this to
3536
+ * match their own portal-rendered content; the base returns `false` so renderers that do not move
3537
+ * focus never arm the restore.
3538
+ *
3539
+ * @param {Event} _event - The event to test.
3540
+ * @returns {boolean} `true` when the event originated inside the popover subtree.
3541
+ */
3542
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3543
+ isEventWithinPopover(_event) {
3544
+ return false;
3545
+ }
3546
+ /**
3547
+ * When the popover hides after an Escape press, returns focus (and the caret) to the table cell
3548
+ * that had focus before the popover was opened.
3549
+ *
3550
+ * vegaPopoverHide fires synchronously from the popover's own Escape handler, before the
3551
+ * document-capture keydown observes the key and before the popover settles focus on `<body>`.
3552
+ * Defer past that so the flag is set and this focus restore wins.
3553
+ */
3554
+ restoreFocusOnEscapeHide() {
3555
+ // eslint-disable-next-line no-restricted-globals
3556
+ setTimeout(() => {
3557
+ const shouldRestore = this.escapePressed;
3558
+ const cell = this.returnFocusCell;
3559
+ this.escapePressed = false;
3560
+ this.returnFocusCell = null;
3561
+ if (shouldRestore && cell && cell.isConnected) {
3562
+ this.restoreFocusToCell(cell);
3563
+ }
3564
+ }, 0);
3565
+ }
3566
+ /**
3567
+ * Focuses the given table cell and collapses the caret at its start.
3568
+ *
3569
+ * @param {HTMLElement} cell - The table cell to focus.
3570
+ */
3571
+ restoreFocusToCell(cell) {
3572
+ var _a, _b, _c;
3573
+ cell.focus();
3574
+ const extensionContext = this.getTableExtensionContext();
3575
+ const selection = (_c = (_a = extensionContext === null || extensionContext === void 0 ? void 0 : extensionContext.getSelection()) !== null && _a !== void 0 ? _a : (_b = cell.ownerDocument) === null || _b === void 0 ? void 0 : _b.getSelection()) !== null && _c !== void 0 ? _c : null;
3576
+ if (selection) {
3577
+ const range = new Range();
3578
+ range.setStart(cell, 0);
3579
+ range.setEnd(cell, 0);
3580
+ selection.removeAllRanges();
3581
+ selection.addRange(range);
3582
+ }
3583
+ }
3584
+ /**
3585
+ * Resolves the `.rich-text-content` editor root to toggle `inert` on while the popover holds focus.
3586
+ * Subclasses override this because they reach the content from different anchors (the toolbar's
3587
+ * target vs. the current table ref); the base returns `null` so renderers that do not use inert are
3588
+ * unaffected.
3589
+ *
3590
+ * @returns {Nullable<HTMLElement>} The editor content element, or `null` when it cannot be resolved.
3591
+ */
3592
+ getInertContentTarget() {
3593
+ return null;
3594
+ }
3595
+ /**
3596
+ * Toggles `inert` on the editor content region while the popover holds keyboard/VoiceOver focus.
3597
+ * Safari VoiceOver keeps its reading cursor anchored to the cell caret and does not follow the
3598
+ * programmatic focus moved into the popover; making the editor content inert removes that text
3599
+ * context so the VoiceOver cursor lands inside the popover. The popover is a body-level portal, so it
3600
+ * is not a descendant of the inert content and stays interactive.
3601
+ *
3602
+ * @param {boolean} inert - Whether the editor content should be inert.
3603
+ */
3604
+ setEditorContentInert(inert) {
3605
+ if (inert) {
3606
+ const content = this.getInertContentTarget();
3607
+ if (content) {
3608
+ content.setAttribute('inert', '');
3609
+ this.inertedContentEl = content;
3610
+ }
3611
+ }
3612
+ else if (this.inertedContentEl) {
3613
+ this.inertedContentEl.removeAttribute('inert');
3614
+ this.inertedContentEl = null;
3615
+ }
3616
+ }
3318
3617
  }
3319
3618
 
3320
3619
  /**
@@ -3384,6 +3683,8 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3384
3683
  * and clears the internal reference.
3385
3684
  */
3386
3685
  destroy() {
3686
+ this.setEditorContentInert(false);
3687
+ this.detachEscapeTracker();
3387
3688
  if (this.selectionAnchorRef && this.selectionAnchorRef.parentNode) {
3388
3689
  domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.removeUniqueObserverFromNode(this.selectionAnchorRef, vegaInternalEventId.VegaInternalRTEExtensionTableCellsSelectionAnchor);
3389
3690
  this.selectionAnchorRef.parentNode.removeChild(this.selectionAnchorRef);
@@ -3396,8 +3697,13 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3396
3697
  *
3397
3698
  * @param {string} type - The table setting type determining which
3398
3699
  * content variant to display (for example, table properties or cell properties).
3700
+ * @param {Nullable<HTMLElement>} returnCell - The cell to move focus into the dialog for and
3701
+ * return focus to if the dialog is dismissed with Escape (set for keyboard/screen-reader users).
3399
3702
  */
3400
- async show(type) {
3703
+ async show(type, returnCell) {
3704
+ // Remember the cell to return focus to if the dialog is dismissed with Escape, and clear any
3705
+ // stale Escape recorded before the dialog was opened.
3706
+ this.beginReturnFocusTracking(returnCell);
3401
3707
  let target = this.getTableRef();
3402
3708
  const extensionContext = this.getTableExtensionContext();
3403
3709
  let cells = [];
@@ -3417,6 +3723,11 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3417
3723
  this.storeCurrentFocusNode();
3418
3724
  remoteInvocationRegistry.remoteInvocationRegistry.call(domNodeSubjectObserverFactory.domNodeSubjectFactory.getSubject(this.popoverRef, vegaInternalEventId.VegaInternalPopoverUpdateTarget), target);
3419
3725
  await this.popoverRef.show();
3726
+ // When opened for keyboard/screen-reader users (a return cell is known), move focus into the
3727
+ // dialog so it lands on the first focusable field (the Border Style control).
3728
+ if (returnCell) {
3729
+ this.focusFirstFormField(type);
3730
+ }
3420
3731
  }
3421
3732
  /**
3422
3733
  * hide the popover.
@@ -3451,7 +3762,11 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3451
3762
  if (this.popoverCloseType === 'change' && extensionContext) {
3452
3763
  extensionContext.flushValue(extensionContext.host.value);
3453
3764
  }
3765
+ this.handleDialogHide();
3454
3766
  });
3767
+ // Escape inside the dialog (rendered in a portal) does not bubble back to the table, so
3768
+ // observe it on the document (capture phase) to know when to return focus to the cell.
3769
+ this.attachEscapeTracker(safeDocument);
3455
3770
  const slotDiv = safeDocument.createElement('div');
3456
3771
  slotDiv.setAttribute('slot', 'popover');
3457
3772
  slotDiv.className = 'rte-table-dynamic-popover-content';
@@ -3478,6 +3793,28 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3478
3793
  return popover;
3479
3794
  }
3480
3795
  }
3796
+ /**
3797
+ * Whether the given event originated inside the properties dialog subtree (either the table or the
3798
+ * cell properties form).
3799
+ *
3800
+ * @param {Event} event - The event to test.
3801
+ * @returns {boolean} `true` when an active form is rendered and the event's composed path includes it.
3802
+ */
3803
+ isEventWithinPopover(event) {
3804
+ const path = event.composedPath();
3805
+ return ((!!this.tablePropertiesFormRef && path.includes(this.tablePropertiesFormRef)) ||
3806
+ (!!this.cellPropertiesFormRef && path.includes(this.cellPropertiesFormRef)));
3807
+ }
3808
+ /**
3809
+ * Resolves the `.rich-text-content` editor root from the current table ref so the content can be
3810
+ * made inert while the properties dialog holds keyboard/VoiceOver focus.
3811
+ *
3812
+ * @returns {Nullable<HTMLElement>} The editor content element, or `null` when it cannot be resolved.
3813
+ */
3814
+ getInertContentTarget() {
3815
+ var _a, _b, _c;
3816
+ return (_c = (_b = (_a = this.getTableRef) === null || _a === void 0 ? void 0 : _a.call(this)) === null || _b === void 0 ? void 0 : _b.closest('.rich-text-content')) !== null && _c !== void 0 ? _c : null;
3817
+ }
3481
3818
  /**
3482
3819
  * Updates the visibility of the pre-rendered content blocks based on type.
3483
3820
  *
@@ -3515,6 +3852,48 @@ class TableDynamicPopoverRenderer extends TablePopoverBaseRenderer {
3515
3852
  const extensionContext = this.getTableExtensionContext();
3516
3853
  extensionContext && (this.currentFocusNode = extensionContext.getSelectedNodes()[0]);
3517
3854
  }
3855
+ /**
3856
+ * Moves focus to the first focusable control in the active properties form so keyboard and
3857
+ * screen-reader users land inside the dialog when it opens. The first form field is the Border
3858
+ * Style select; its focusable trigger is the `.vega-input-select-container` element.
3859
+ *
3860
+ * @param {string} type - The table setting type that determines which form is visible.
3861
+ */
3862
+ focusFirstFormField(type) {
3863
+ const formRef = type === splitCellOperation.TableSettingType.TABLE ? this.tablePropertiesFormRef : this.cellPropertiesFormRef;
3864
+ if (!formRef) {
3865
+ return;
3866
+ }
3867
+ // Make the editor content inert up front so the table/cell cannot steal focus while the dialog
3868
+ // lays out. The cell form applies the selected cell's styles on open, whose async reset fires a
3869
+ // selectionchange that would otherwise re-focus the cell before we reach Border Style. Inert also
3870
+ // gives VoiceOver no cell-caret text context, so its cursor follows the focus. Lifted on hide.
3871
+ this.setEditorContentInert(true);
3872
+ // The CELL form applies the selected cell's styles on open (it sets both `styleMap` and
3873
+ // `defaultValue`), a heavier re-render than TABLE, so on the first open its Border Style control is
3874
+ // present but 0×0 for a frame. WebKit's VoiceOver cursor does not follow `.focus()` onto a
3875
+ // zero-area element, so defer through a double animation frame: the first schedules past the
3876
+ // popover's async reveal, the second runs after the browser has committed the layout pass that
3877
+ // sizes the control.
3878
+ requestAnimationFrame(() => {
3879
+ requestAnimationFrame(() => {
3880
+ var _a, _b, _c, _d, _e;
3881
+ const firstField = (_b = (_a = formRef.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('[data-vega-form]')) !== null && _b !== void 0 ? _b : null;
3882
+ const container = (_d = (_c = firstField === null || firstField === void 0 ? void 0 : firstField.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('.vega-input-select-container')) !== null && _d !== void 0 ? _d : null;
3883
+ (_e = (container !== null && container !== void 0 ? container : firstField)) === null || _e === void 0 ? void 0 : _e.focus();
3884
+ });
3885
+ });
3886
+ }
3887
+ /**
3888
+ * When the properties dialog hides after an Escape press, returns focus (and the caret) to the
3889
+ * table cell that had focus before the dialog was opened via the setting toolbar.
3890
+ */
3891
+ handleDialogHide() {
3892
+ // Lift the inert guard on the editor content synchronously, before any focus restore runs, so the
3893
+ // cell can receive focus and the editor is interactive again.
3894
+ this.setEditorContentInert(false);
3895
+ this.restoreFocusOnEscapeHide();
3896
+ }
3518
3897
  /**
3519
3898
  * Create and position an invisible anchor element whose position and size are identical to the geometry of the current multi-cell selection.
3520
3899
  * This anchor element will then be used as the target of the popup, so that the popup appears near the entire selection area.
@@ -3609,6 +3988,62 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3609
3988
  this.tableSettingRef.selectedCells = this.getTableSelectedCells();
3610
3989
  }
3611
3990
  };
3991
+ /**
3992
+ * Hides the table setting toolbar and its dynamic popover. Used when focus leaves the table (e.g.
3993
+ * Escape moves focus from a cell back onto the table) so the contextual toolbar does not linger.
3994
+ */
3995
+ this.hide = () => {
3996
+ var _a;
3997
+ void this.tableDynamicPopover.hide();
3998
+ void ((_a = this.popoverRef) === null || _a === void 0 ? void 0 : _a.hide());
3999
+ };
4000
+ /**
4001
+ * Opens the table setting toolbar for keyboard/screen-reader users and moves focus to its first
4002
+ * enabled button. Used by the Alt+F10 shortcut so the toolbar can be reached from inside a cell
4003
+ * even when it is currently closed: it re-targets and shows the popover (the same path as a table
4004
+ * click) before deferring focus to the first enabled button.
4005
+ *
4006
+ * @param {RTETableBlock} tableBlock - The table's block data.
4007
+ * @param {() => HTMLElement} getTableRef - Getter for the table's DOM element.
4008
+ * @param {Nullable<HTMLElement>} returnCell - The cell to return focus to if the toolbar is dismissed with Escape.
4009
+ */
4010
+ this.openSettingToolbarForKeyboard = (tableBlock, getTableRef, returnCell) => {
4011
+ // Re-target and show the popover through the same path as a table click so the toolbar is
4012
+ // actually visible before focus lands on it — otherwise focus would be pushed onto a hidden
4013
+ // or stale toolbar that isn't shown.
4014
+ this.reTarget(tableBlock, getTableRef);
4015
+ void this.tableDynamicPopover.hide();
4016
+ remoteInvocationRegistry.remoteInvocationRegistry.call(domNodeSubjectObserverFactory.domNodeSubjectFactory.getSubject(this.popoverRef, vegaInternalEventId.VegaInternalPopoverUpdateTarget), getTableRef());
4017
+ void this.popoverRef.show(true);
4018
+ this.focusFirstSettingButton(returnCell);
4019
+ };
4020
+ /**
4021
+ * Moves focus to the first enabled button in the table setting toolbar. Used by the Alt+F10
4022
+ * shortcut so keyboard and screen-reader users can reach the toolbar from inside the table.
4023
+ *
4024
+ * @param {Nullable<HTMLElement>} returnCell - The cell to return focus to if the toolbar is dismissed with Escape.
4025
+ */
4026
+ this.focusFirstSettingButton = (returnCell) => {
4027
+ var _a, _b;
4028
+ // Remember the cell to return focus to if the toolbar is dismissed with Escape, and clear any
4029
+ // stale Escape recorded before the toolbar was focused.
4030
+ this.beginReturnFocusTracking(returnCell);
4031
+ // Safari VoiceOver ignores the toolbar's aria-modal and keeps driving a caret through the still
4032
+ // editable content, so on Ctrl+Opt+Right it walks the DOM caret out of the table into the editor
4033
+ // instead of staying on the toolbar. Clear the caret AND make the editor content inert so there is
4034
+ // no text context for VoiceOver to advance; the inert flag is lifted again when the toolbar hides.
4035
+ (_b = (_a = this.getTableExtensionContext()) === null || _a === void 0 ? void 0 : _a.getSelection()) === null || _b === void 0 ? void 0 : _b.removeAllRanges();
4036
+ this.setEditorContentInert(true);
4037
+ // The popover reveals its content asynchronously, so defer to the next tick to make sure
4038
+ // the setting buttons are present and focusable.
4039
+ // eslint-disable-next-line no-restricted-globals
4040
+ setTimeout(() => {
4041
+ var _a, _b, _c;
4042
+ const buttons = Array.from((_c = (_b = (_a = this.tableSettingRef) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll('.rte-table-setting-item')) !== null && _c !== void 0 ? _c : []);
4043
+ const firstEnabled = buttons.find((button) => !button.hasAttribute('disabled'));
4044
+ firstEnabled === null || firstEnabled === void 0 ? void 0 : firstEnabled.focus();
4045
+ }, 0);
4046
+ };
3612
4047
  /**
3613
4048
  * Handles setting menu click events.
3614
4049
  *
@@ -3621,11 +4056,16 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3621
4056
  extensionContext && handler.execute(event.detail, extensionContext, this.tableBlock);
3622
4057
  if (event.detail[0] === splitCellOperation.TableSettingType.CAPTION) {
3623
4058
  this.updateTableSettingCaption();
4059
+ this.moveFocusToCaption();
3624
4060
  }
3625
4061
  }
3626
4062
  if (event.detail[0] === splitCellOperation.TableSettingType.TABLE || event.detail[0] === splitCellOperation.TableSettingType.CELL) {
4063
+ // Capture the return cell before hiding the setting popover, whose own hide handler clears
4064
+ // it, so the properties dialog can move focus into itself and restore it to the cell on
4065
+ // Escape for keyboard/screen-reader users.
4066
+ const returnCell = this.returnFocusCell;
3627
4067
  void this.popoverRef.hide();
3628
- void this.tableDynamicPopover.show(event.detail[0]);
4068
+ void this.tableDynamicPopover.show(event.detail[0], returnCell);
3629
4069
  }
3630
4070
  };
3631
4071
  /**
@@ -3633,6 +4073,17 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3633
4073
  */
3634
4074
  this.handleTableSettingPopoverShow = () => {
3635
4075
  this.syncSelectedCells();
4076
+ this.labelSettingDialog();
4077
+ };
4078
+ /**
4079
+ * When the setting popover hides after an Escape press, returns focus (and the caret) to the
4080
+ * table cell that had focus before the toolbar was reached via Alt+F10.
4081
+ */
4082
+ this.handleTableSettingPopoverHide = () => {
4083
+ // Lift the inert guard on the editor content synchronously, before any focus restore runs, so the
4084
+ // cell (or the properties dialog) can receive focus and the editor is interactive again.
4085
+ this.setEditorContentInert(false);
4086
+ this.restoreFocusOnEscapeHide();
3636
4087
  };
3637
4088
  this.tableDynamicPopover = new TableDynamicPopoverRenderer(splitCellOperation.RTETableColorManager.getTableColors(), renderContext);
3638
4089
  }
@@ -3641,6 +4092,8 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3641
4092
  */
3642
4093
  destroy() {
3643
4094
  this.tableDynamicPopover.destroy();
4095
+ this.setEditorContentInert(false);
4096
+ this.detachEscapeTracker();
3644
4097
  if (this.popoverContainer) {
3645
4098
  this.popoverContainer.remove();
3646
4099
  }
@@ -3661,6 +4114,10 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3661
4114
  popover.isScreenPosition = true;
3662
4115
  popover.className = 'rte-table-setting-popover';
3663
4116
  domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(popover, vegaEventId.VegaPopoverShow, this.handleTableSettingPopoverShow);
4117
+ domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(popover, vegaEventId.VegaPopoverHide, this.handleTableSettingPopoverHide);
4118
+ // Escape inside the popover (rendered in a portal) does not bubble back to the table, so
4119
+ // observe it on the document (capture phase) to know when to return focus to the cell.
4120
+ this.attachEscapeTracker(safeDocument);
3664
4121
  const slotDiv = safeDocument.createElement('div');
3665
4122
  slotDiv.setAttribute('slot', 'popover');
3666
4123
  const tableSetting = safeDocument.createElement('vega-rich-text-table-setting');
@@ -3673,6 +4130,25 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3673
4130
  this.tableSettingRef = tableSetting;
3674
4131
  }
3675
4132
  }
4133
+ /**
4134
+ * Whether the given event originated inside the setting toolbar subtree.
4135
+ *
4136
+ * @param {Event} event - The event to test.
4137
+ * @returns {boolean} `true` when the toolbar is rendered and the event's composed path includes it.
4138
+ */
4139
+ isEventWithinPopover(event) {
4140
+ return !!this.tableSettingRef && event.composedPath().includes(this.tableSettingRef);
4141
+ }
4142
+ /**
4143
+ * Resolves the `.rich-text-content` editor root from the setting toolbar's target so the content
4144
+ * can be made inert while the toolbar holds keyboard/VoiceOver focus.
4145
+ *
4146
+ * @returns {Nullable<HTMLElement>} The editor content element, or `null` when it cannot be resolved.
4147
+ */
4148
+ getInertContentTarget() {
4149
+ var _a, _b, _c;
4150
+ return (_c = (_b = (_a = this.tableSettingRef) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.closest('.rich-text-content')) !== null && _c !== void 0 ? _c : null;
4151
+ }
3676
4152
  /**
3677
4153
  * Updates the table setting component caption state to match the current table data.
3678
4154
  */
@@ -3682,6 +4158,35 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3682
4158
  this.tableSettingRef.hasCaption = hasCaption;
3683
4159
  }
3684
4160
  }
4161
+ /**
4162
+ * When the caption is toggled on, moves keyboard/VoiceOver focus and the caret into the caption so
4163
+ * the user lands in it to start typing. The setting toolbar is opened as inert-guarded for
4164
+ * keyboard/screen-reader users, so lift that guard first; the caption is re-rendered by the toggle,
4165
+ * so defer the focus to the next tick when the `<caption>` element exists.
4166
+ */
4167
+ moveFocusToCaption() {
4168
+ if (!this.tableBlock.hasCaption()) {
4169
+ return;
4170
+ }
4171
+ this.setEditorContentInert(false);
4172
+ // eslint-disable-next-line no-restricted-globals
4173
+ setTimeout(() => {
4174
+ var _a, _b, _c, _d, _e, _f, _g;
4175
+ const caption = (_c = (_b = (_a = this.tableSettingRef) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.querySelector('caption')) !== null && _c !== void 0 ? _c : null;
4176
+ if (!caption) {
4177
+ return;
4178
+ }
4179
+ caption.focus();
4180
+ const selection = (_g = (_e = (_d = this.getTableExtensionContext()) === null || _d === void 0 ? void 0 : _d.getSelection()) !== null && _e !== void 0 ? _e : (_f = caption.ownerDocument) === null || _f === void 0 ? void 0 : _f.getSelection()) !== null && _g !== void 0 ? _g : null;
4181
+ if (selection) {
4182
+ const range = new Range();
4183
+ range.selectNodeContents(caption);
4184
+ range.collapse(false);
4185
+ selection.removeAllRanges();
4186
+ selection.addRange(range);
4187
+ }
4188
+ }, 0);
4189
+ }
3685
4190
  /**
3686
4191
  * Re-targets the shared popovers to the given table.
3687
4192
  *
@@ -3696,6 +4201,22 @@ class TableSettingPopoverRenderer extends TablePopoverBaseRenderer {
3696
4201
  this.tableDynamicPopover.reTarget(tableBlock, getTableRef);
3697
4202
  }
3698
4203
  }
4204
+ /**
4205
+ * `vega-popover-content-box` renders `role="dialog"` + `aria-modal="true"`, which on WebKit
4206
+ * VoiceOver confines the reading cursor to the popover. Keep those semantics so Ctrl+Opt+Arrow
4207
+ * cannot walk the VoiceOver cursor out of the toolbar past the last button (VoiceOver swallows
4208
+ * those keys, so this cannot be trapped in JS), and give the dialog an accessible name so it
4209
+ * announces "Table tools" on entry.
4210
+ */
4211
+ labelSettingDialog() {
4212
+ var _a, _b;
4213
+ const dialog = (_b = (_a = this.tableSettingRef) === null || _a === void 0 ? void 0 : _a.closest('vega-popover-content-box')) !== null && _b !== void 0 ? _b : null;
4214
+ if (dialog) {
4215
+ dialog.setAttribute('role', 'dialog');
4216
+ dialog.setAttribute('aria-modal', 'true');
4217
+ dialog.setAttribute('aria-label', 'Table tools');
4218
+ }
4219
+ }
3699
4220
  /**
3700
4221
  * Collects and returns the currently selected table cells.
3701
4222
  *
@@ -3721,7 +4242,7 @@ class RTETableBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
3721
4242
  */
3722
4243
  doRender(h, renderData, rteContext) {
3723
4244
  let tableRef;
3724
- const table = this.renderTable(h, renderData, (ref) => (tableRef = ref));
4245
+ const table = this.renderTable(h, renderData, (ref) => (tableRef = ref), rteContext);
3725
4246
  this.renderTableToolbar(rteContext);
3726
4247
  const tableAnnotation = renderData.getAnnotationByType(splitCellOperation.RTETableExtensionAnnotationTypeEnum.TABLE);
3727
4248
  const children = rteContext.editable
@@ -3745,9 +4266,16 @@ class RTETableBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
3745
4266
  }
3746
4267
  },
3747
4268
  }, [
3748
- // Add an extra div as slot container, to make sure the cursor can move to before/end of the table.
4269
+ // The table is a fully non-editable "widget" wrapped by a
4270
+ // `<div contenteditable="false">`: there is NO editable element wrapping the
4271
+ // table, so Chrome/VoiceOver exposes it as a real table ("table, N columns, M
4272
+ // rows") instead of flattening it into the surrounding text entry area. The
4273
+ // <table> stays a plain, semantically clean table and each cell re-enables editing
4274
+ // via contentEditable=true. The cursor moves to before/after the table via the
4275
+ // adjacent paragraphs in the editor content, treating the table as an atomic widget.
3749
4276
  h('div', {
3750
- contentEditable: true,
4277
+ class: 'v-rte--extension-table-widget',
4278
+ contentEditable: false,
3751
4279
  ref: this.useRef(renderData),
3752
4280
  }, [table]),
3753
4281
  ]),
@@ -3761,6 +4289,11 @@ class RTETableBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
3761
4289
  }
3762
4290
  const result = h('div', {
3763
4291
  class: 'v-rte--extension-table-container',
4292
+ // The container is `display: table` (for shrink-to-fit centering), which WebKit maps to an
4293
+ // AXTable. Without this, Safari VoiceOver lands its cursor on the container (or groups up to
4294
+ // the widget host) instead of the real `<table>`. `role="presentation"` strips the container's
4295
+ // implicit table semantics so VO descends to `table.v-rte--extension-table` like Chrome does.
4296
+ role: 'presentation',
3764
4297
  style: Object.assign({}, containerStyle),
3765
4298
  }, children);
3766
4299
  /**
@@ -3789,17 +4322,151 @@ class RTETableBlockRenderer extends linkExtension.VegaRTEExtensionRenderer {
3789
4322
  * @param {VegaRTECreateElementFunction} h - The create element function.
3790
4323
  * @param {RTETableBlock} renderData - The table block to render.
3791
4324
  * @param {(ref: HTMLElement) => HTMLElement} setTableRef - Set table ref to tableRef
4325
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
3792
4326
  * @returns {VegaRTERenderResult} - The rendered table element.
3793
4327
  */
3794
- renderTable(h, renderData, setTableRef) {
4328
+ renderTable(h, renderData, setTableRef, rteContext) {
3795
4329
  var _a;
3796
- return h('table', Object.assign(Object.assign({ key: renderData.id }, (_a = renderData.getCustomAttributesAnnotation()) === null || _a === void 0 ? void 0 : _a.render()), { style: renderData.getStyles(), class: renderData.getClasses(),
4330
+ const editable = !!rteContext.editable;
4331
+ return h('table', Object.assign(Object.assign(Object.assign(Object.assign({ key: renderData.id }, (_a = renderData.getCustomAttributesAnnotation()) === null || _a === void 0 ? void 0 : _a.render()), { style: renderData.getStyles(), class: renderData.getClasses() }), (editable
4332
+ ? {
4333
+ // eslint-disable-next-line jsdoc/require-jsdoc
4334
+ onClick: (event) => this.handleTableActivate(event, rteContext),
4335
+ // eslint-disable-next-line jsdoc/require-jsdoc
4336
+ onKeyDown: (event) => this.handleTableKeyDown(event, rteContext, renderData),
4337
+ }
4338
+ : undefined)), {
3797
4339
  // eslint-disable-next-line jsdoc/require-jsdoc
3798
4340
  ref: (ref) => {
3799
4341
  this.useRef(renderData)(ref);
3800
4342
  setTableRef(ref);
3801
4343
  } }));
3802
4344
  }
4345
+ /**
4346
+ * Handles activation of the table itself (e.g. VoiceOver Ctrl+Option+Space, which dispatches a
4347
+ * click on the focused table) by moving focus into the first cell so the user can start editing.
4348
+ *
4349
+ * @param {MouseEvent} event - The click event dispatched on the table.
4350
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
4351
+ */
4352
+ handleTableActivate(event, rteContext) {
4353
+ const tableRef = event.currentTarget;
4354
+ // Only treat this as "activate the table" when the click truly targets the table element
4355
+ // itself — i.e. VoiceOver Ctrl+Option+Space (which dispatches a click on the focused table)
4356
+ // or a click on the table's own padding/border. Clicks that bubble up from editable
4357
+ // descendants (cells, or the supported <caption>) keep their native contentEditable caret
4358
+ // placement, so we must not force focus into the first cell and break that interaction.
4359
+ if (event.target !== event.currentTarget) {
4360
+ return;
4361
+ }
4362
+ this.focusFirstCell(tableRef, rteContext);
4363
+ }
4364
+ /**
4365
+ * Handles table-scoped keyboard shortcuts while focus is inside the table:
4366
+ * - Alt+F10 opens the table setting toolbar (re-targeting and showing it when needed) and moves
4367
+ * focus to it (the common "focus the contextual toolbar" shortcut), so keyboard/screen-reader
4368
+ * users can reach the toolbar buttons even when it is currently closed.
4369
+ * - Escape moves focus back onto the table, so the caret leaves the cell (its focus highlight
4370
+ * is cleared), the contextual setting toolbar is dismissed, and screen readers announce the
4371
+ * table again.
4372
+ *
4373
+ * @param {KeyboardEvent} event - The keydown event.
4374
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
4375
+ * @param {RTETableBlock} renderData - The table block being rendered.
4376
+ */
4377
+ handleTableKeyDown(event, rteContext, renderData) {
4378
+ var _a, _b;
4379
+ if (event.altKey && event.key === 'F10') {
4380
+ event.preventDefault();
4381
+ event.stopPropagation();
4382
+ const tableRef = event.currentTarget;
4383
+ const f10Target = event.target;
4384
+ const f10Cell = f10Target
4385
+ ? f10Target.closest('td, th')
4386
+ : null;
4387
+ (_a = this.tableToolbar) === null || _a === void 0 ? void 0 : _a.openSettingToolbarForKeyboard(renderData, () => tableRef, f10Cell);
4388
+ return;
4389
+ }
4390
+ if (event.key !== 'Escape') {
4391
+ return;
4392
+ }
4393
+ const tableRef = event.currentTarget;
4394
+ const target = event.target;
4395
+ const cell = target
4396
+ ? target.closest('td, th')
4397
+ : null;
4398
+ if (!cell || !tableRef.contains(cell)) {
4399
+ return;
4400
+ }
4401
+ event.preventDefault();
4402
+ event.stopPropagation();
4403
+ this.focusTable(tableRef, rteContext);
4404
+ // Focus moved from the cell back onto the table, so dismiss the contextual setting toolbar
4405
+ // that may have been opened (e.g. by activating the table) — otherwise it lingers with no
4406
+ // focused cell to act on.
4407
+ (_b = this.tableToolbar) === null || _b === void 0 ? void 0 : _b.hide();
4408
+ }
4409
+ /**
4410
+ * Moves focus (and the caret) into the first cell of the table.
4411
+ *
4412
+ * @param {HTMLElement} tableRef - The table element.
4413
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
4414
+ */
4415
+ focusFirstCell(tableRef, rteContext) {
4416
+ const firstCell = tableRef.querySelector('td, th');
4417
+ if (!firstCell) {
4418
+ return;
4419
+ }
4420
+ firstCell.focus();
4421
+ const selection = this.getSelection(rteContext, tableRef);
4422
+ if (selection) {
4423
+ // Collapse the caret at the start of the cell content so the user can start typing.
4424
+ const range = new Range();
4425
+ range.setStart(firstCell, 0);
4426
+ range.setEnd(firstCell, 0);
4427
+ selection.removeAllRanges();
4428
+ selection.addRange(range);
4429
+ }
4430
+ }
4431
+ /**
4432
+ * Moves focus onto the table element and clears any cell caret and selection highlight.
4433
+ *
4434
+ * @param {HTMLElement} tableRef - The table element.
4435
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
4436
+ */
4437
+ focusTable(tableRef, rteContext) {
4438
+ var _a;
4439
+ const selection = this.getSelection(rteContext, tableRef);
4440
+ selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
4441
+ const extensionContext = this.getExtensionContext(rteContext.host);
4442
+ (_a = extensionContext === null || extensionContext === void 0 ? void 0 : extensionContext.tableSelection) === null || _a === void 0 ? void 0 : _a.setSelectedCells([]);
4443
+ // The table is contentEditable=false, so it is not focusable by default. Add tabindex ONLY
4444
+ // while moving focus onto it, and remove it again on blur, so that during normal navigation
4445
+ // VoiceOver still announces it as "table, N columns, M rows" rather than a focusable widget.
4446
+ tableRef.setAttribute('tabindex', '-1');
4447
+ // eslint-disable-next-line jsdoc/require-jsdoc
4448
+ const removeTabindex = () => {
4449
+ tableRef.removeAttribute('tabindex');
4450
+ tableRef.removeEventListener('blur', removeTabindex);
4451
+ };
4452
+ tableRef.addEventListener('blur', removeTabindex);
4453
+ tableRef.focus();
4454
+ }
4455
+ /**
4456
+ * Resolves the editor selection, preferring the shadow-aware selection from the extension
4457
+ * context and falling back to the table's owning document.
4458
+ *
4459
+ * @param {RTERenderContext} rteContext - The rendering context of the rich text editor.
4460
+ * @param {HTMLElement} tableRef - The table element.
4461
+ * @returns {Nullable<Selection>} - The resolved selection, or null when unavailable.
4462
+ */
4463
+ getSelection(rteContext, tableRef) {
4464
+ const extensionContext = this.getExtensionContext(rteContext.host);
4465
+ if (extensionContext) {
4466
+ return extensionContext.getSelection();
4467
+ }
4468
+ return tableRef.ownerDocument ? tableRef.ownerDocument.getSelection() : null;
4469
+ }
3803
4470
  /**
3804
4471
  * Handles the removal of the table block.
3805
4472
  *
@@ -3902,9 +4569,9 @@ class RTETableCellRenderer extends linkExtension.VegaRTEExtensionRenderer {
3902
4569
  */
3903
4570
  renderByCellType(h, renderData, rteContext, elementType) {
3904
4571
  var _a;
3905
- return h(elementType, Object.assign(Object.assign(Object.assign({ key: `${renderData.id}-${elementType}`,
4572
+ return h(elementType, Object.assign(Object.assign(Object.assign(Object.assign({ key: `${renderData.id}-${elementType}`,
3906
4573
  // eslint-disable-next-line jsdoc/require-jsdoc
3907
- ref: this.useRef(renderData) }, (_a = renderData.getCustomAttributesAnnotation()) === null || _a === void 0 ? void 0 : _a.render()), { style: renderData.getStyles(rteContext), class: renderData.getClasses() }), (rteContext.editable ? this.onSelectionListeners(renderData, rteContext) : undefined)));
4574
+ ref: this.useRef(renderData) }, (rteContext.editable ? { contentEditable: true, tabindex: -1 } : undefined)), (_a = renderData.getCustomAttributesAnnotation()) === null || _a === void 0 ? void 0 : _a.render()), { style: renderData.getStyles(rteContext), class: renderData.getClasses() }), (rteContext.editable ? this.onSelectionListeners(renderData, rteContext) : undefined)));
3908
4575
  }
3909
4576
  /**
3910
4577
  * Returns the mouse event listeners for selection handling.
@@ -4183,6 +4850,7 @@ class RTETableToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
4183
4850
  return createTablePopoverRenderer.render(h, super.renderButton(h, editorContext, {
4184
4851
  showArrowIcon: true,
4185
4852
  icon: 'rte-table',
4853
+ ariaLabel: 'Table',
4186
4854
  tooltip: { text: 'Insert table' },
4187
4855
  }));
4188
4856
  }
@@ -4363,16 +5031,10 @@ class RTETableCaptionRenderer extends linkExtension.VegaRTEExtensionRenderer {
4363
5031
  /**
4364
5032
  * @inheritDoc
4365
5033
  */
4366
- doRender(h, renderData) {
4367
- return h('caption', {
4368
- 'key': renderData.id,
4369
- 'ref': this.useRef(renderData),
4370
- 'style': renderData.getStyles(),
4371
- 'class': [renderData.getClasses(), renderData.isNotEmpty() ? null : 'showPlaceholder']
5034
+ doRender(h, renderData, rteContext) {
5035
+ return h('caption', Object.assign(Object.assign({ 'key': renderData.id, 'ref': this.useRef(renderData) }, (rteContext.editable ? { contentEditable: true } : undefined)), { 'style': renderData.getStyles(), 'class': [renderData.getClasses(), renderData.isNotEmpty() ? null : 'showPlaceholder']
4372
5036
  .filter(typeGuard.isNonNullable)
4373
- .join(' '),
4374
- 'data-placeholder': TABLE_CAPTION_PLACEHOLDER_TEXT,
4375
- });
5037
+ .join(' '), 'data-placeholder': TABLE_CAPTION_PLACEHOLDER_TEXT }));
4376
5038
  }
4377
5039
  }
4378
5040
 
@@ -5168,11 +5830,36 @@ class RTETableSelection {
5168
5830
  const commonAncestorContainer = range.commonAncestorContainer;
5169
5831
  const rangeInTable = !!ui.findParent(commonAncestorContainer, `table`);
5170
5832
  if (rangeInTable) {
5171
- const selectedCells = this.filterSelectedCell(range, commonAncestorContainer);
5833
+ let selectedCells = this.filterSelectedCell(range, commonAncestorContainer);
5834
+ if (selectedCells.length === 0) {
5835
+ // A collapsed caret placed at an element boundary (e.g. keyboard/VoiceOver entry via
5836
+ // Ctrl+Option+Space) does not intersect a text node, so filterSelectedCell finds nothing
5837
+ // on browsers that keep the caret on the element (Firefox) instead of normalizing it into
5838
+ // the text node (Chrome). Resolve the containing cell directly so the setting toolbar is
5839
+ // still enabled.
5840
+ selectedCells = this.resolveCaretCell(commonAncestorContainer);
5841
+ }
5172
5842
  this.setSelectedCells(selectedCells);
5173
5843
  }
5174
5844
  }
5175
5845
  }
5846
+ /**
5847
+ * Resolve the single table cell that contains the given selection node. Used as a fallback when a
5848
+ * collapsed caret does not intersect any text node (see handleSelectionChange).
5849
+ *
5850
+ * @param {Node} node - The selection's common ancestor container.
5851
+ * @returns {RTETableCellBlock[]} The containing cell block, or an empty list when none is found.
5852
+ */
5853
+ resolveCaretCell(node) {
5854
+ var _a;
5855
+ const startElement = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
5856
+ const cellRef = (_a = startElement === null || startElement === void 0 ? void 0 : startElement.closest('td, th')) !== null && _a !== void 0 ? _a : null;
5857
+ if (!cellRef) {
5858
+ return [];
5859
+ }
5860
+ const cellBlock = codeBlock.stateEntityRenderingRegistry.getEntityByDOM(cellRef);
5861
+ return cellBlock ? [cellBlock] : [];
5862
+ }
5176
5863
  /**
5177
5864
  * Mark the beginning of a drag operation.
5178
5865
  */
@@ -7741,6 +8428,7 @@ class RTEHorizontalLineToolbarButtonRenderer extends VegaRTEToolbarButtonRendere
7741
8428
  render(createElement, editorContext) {
7742
8429
  return this.renderButton(createElement, editorContext, {
7743
8430
  icon: 'horizontal-line',
8431
+ ariaLabel: internalTranslationController.VegaInternalTranslation.t('Horizontal line'),
7744
8432
  tooltip: { text: internalTranslationController.VegaInternalTranslation.t('Horizontal line') },
7745
8433
  });
7746
8434
  }
@@ -8336,6 +9024,7 @@ class RTEBlockquoteToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
8336
9024
  render(createElement, editorContext) {
8337
9025
  return this.renderButton(createElement, editorContext, {
8338
9026
  icon: 'quote-left',
9027
+ ariaLabel: editorContext.translation.t('Block quote'),
8339
9028
  tooltip: { text: 'Block quote' },
8340
9029
  });
8341
9030
  }
@@ -8968,6 +9657,7 @@ class RTESpecialCharactersToolbarButtonRenderer extends VegaRTEToolbarButtonRend
8968
9657
  placement: 'bottom',
8969
9658
  showArrow: false,
8970
9659
  isScreenPosition: true,
9660
+ role: 'presentation',
8971
9661
  // eslint-disable-next-line jsdoc/require-jsdoc
8972
9662
  ref: (ref) => {
8973
9663
  if (ref) {
@@ -8995,6 +9685,7 @@ class RTESpecialCharactersToolbarButtonRenderer extends VegaRTEToolbarButtonRend
8995
9685
  ]),
8996
9686
  h('div', { slot: 'popover-content' }, this.renderButton(h, editorContext, {
8997
9687
  icon: 'rte-special-characters',
9688
+ ariaLabel: editorContext.translation.t('Special Characters'),
8998
9689
  tooltip: { text: 'Special Characters' },
8999
9690
  })),
9000
9691
  ]);
@@ -10208,14 +10899,22 @@ class FindReplaceToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
10208
10899
  placement: 'bottom',
10209
10900
  showArrow: false,
10210
10901
  isScreenPosition: true,
10902
+ role: 'presentation',
10211
10903
  // eslint-disable-next-line jsdoc/require-jsdoc
10212
10904
  ref: (ref) => {
10213
10905
  if (ref) {
10214
10906
  this.popoverRef = ref;
10215
10907
  domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaPopoverHide, () => {
10908
+ const shouldRestoreFocus = this.shouldRestoreFocusToButton();
10216
10909
  this.isPopoverOpen = false;
10217
10910
  this.findController.clear();
10218
10911
  this.updatePanel({ current: 0, total: 0 });
10912
+ if (shouldRestoreFocus) {
10913
+ // Defer so it runs after the popover's own focus-restore
10914
+ // (AriaDialogFocusableTrapSlimmer), returning focus to the toolbar
10915
+ // button for keyboard and VoiceOver users when the panel is dismissed.
10916
+ setTimeout(() => this.focusToolbarButton());
10917
+ }
10219
10918
  });
10220
10919
  domNodeSubjectObserverFactory.DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, vegaEventId.VegaPopoverShow, () => {
10221
10920
  this.isPopoverOpen = true;
@@ -10246,6 +10945,7 @@ class FindReplaceToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
10246
10945
  ]),
10247
10946
  h('div', { slot: 'popover-content' }, this.renderButton(h, editorContext, {
10248
10947
  icon: 'rte-find-replace',
10948
+ ariaLabel: editorContext.translation.t('Find and replace'),
10249
10949
  tooltip: { text: internalTranslationController.VegaInternalTranslation.t('Find and replace') },
10250
10950
  })),
10251
10951
  ]);
@@ -10348,13 +11048,54 @@ class FindReplaceToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
10348
11048
  void this.popoverRef.hide();
10349
11049
  }
10350
11050
  }
10351
- }
10352
- (() => {
10353
- internalIconManager.VegaInternalIconManager.register({ 'rte-find-replace': findReplaceIcon });
10354
- })();
10355
-
10356
- /**
10357
- * Find & Replace extension for Vega Rich Text Editor.
11051
+ /**
11052
+ * Decides whether closing the panel should return focus to the toolbar button.
11053
+ *
11054
+ * Focus is restored when the panel is dismissed while focus is still inside it
11055
+ * (Escape key or the Close button) — including the VoiceOver case where the
11056
+ * dialog's `inert` blur has already moved focus to `<body>`. It is not restored
11057
+ * when focus has intentionally moved to another element (Tab out of the panel
11058
+ * or interacting with something else), so we don't yank focus back.
11059
+ *
11060
+ * @returns {boolean} True when focus should return to the toolbar button.
11061
+ */
11062
+ shouldRestoreFocusToButton() {
11063
+ // eslint-disable-next-line no-restricted-globals
11064
+ const activeEl = ui.getDeepActiveElementInShadow(document, true);
11065
+ // eslint-disable-next-line no-restricted-globals
11066
+ return !activeEl || activeEl === document.body || this.isElementWithinPanel(activeEl);
11067
+ }
11068
+ /**
11069
+ * Checks whether an element is inside the panel, crossing shadow boundaries.
11070
+ *
11071
+ * @param {Nullable<HTMLElement>} el - The element to test.
11072
+ * @returns {boolean} True when the element is contained by the panel.
11073
+ */
11074
+ isElementWithinPanel(el) {
11075
+ if (!el || !this.panelRef) {
11076
+ return false;
11077
+ }
11078
+ let node = el;
11079
+ while (node) {
11080
+ if (node === this.panelRef) {
11081
+ return true;
11082
+ }
11083
+ const parent = node.parentNode;
11084
+ // Cross shadow boundaries: a shadow root (nodeType 11) exposes its `host`.
11085
+ node =
11086
+ parent && parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE
11087
+ ? parent.host
11088
+ : parent;
11089
+ }
11090
+ return false;
11091
+ }
11092
+ }
11093
+ (() => {
11094
+ internalIconManager.VegaInternalIconManager.register({ 'rte-find-replace': findReplaceIcon });
11095
+ })();
11096
+
11097
+ /**
11098
+ * Find & Replace extension for Vega Rich Text Editor.
10358
11099
  *
10359
11100
  * Registers a toolbar button (magnifying-glass icon) that toggles the find-replace panel.
10360
11101
  * Each editor host gets its own isolated FindReplaceState and toolbar renderer instance,
@@ -10509,12 +11250,28 @@ class RTELineHeightToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
10509
11250
  }, [
10510
11251
  this.renderButton(createElement, editorContext, {
10511
11252
  icon: 'line-height',
11253
+ ariaLabel: editorContext.translation.t('Line Height'),
10512
11254
  showArrowIcon: true,
10513
11255
  tooltip: { text: internalTranslationController.VegaInternalTranslation.t('Line Height') },
10514
11256
  }),
10515
11257
  this.renderDropdownListTemplate(createElement, dropdownItems, editorContext),
10516
11258
  ]);
10517
11259
  }
11260
+ /**
11261
+ * Renders each line-height option with its label as light-DOM children rather than the
11262
+ * `label` prop. This gives the focusable menuitem a light-DOM text anchor so Safari
11263
+ * VoiceOver's reading cursor follows focus into the item (Ctrl+Opt+Right walks item→item
11264
+ * instead of escaping to the next toolbar button).
11265
+ *
11266
+ * The label is wrapped in a `<span>` (not a bare text node) so a click targeting the label
11267
+ * lands on a slotted element that composes into the item's shadow `<li>`; a bare text node
11268
+ * resolves to the `vega-dropdown-item` host, whose click never reaches the shadow handler.
11269
+ *
11270
+ * @inheritDoc
11271
+ */
11272
+ renderDropdownItem(h, item, editorContext) {
11273
+ return h('vega-dropdown-item', { key: item.key, itemKey: item.key, prefixIcon: item.icon }, h('span', undefined, editorContext.translation.t(item.label)));
11274
+ }
10518
11275
  /**
10519
11276
  * @inheritDoc
10520
11277
  */
@@ -10816,6 +11573,9 @@ class RTEFullscreenToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
10816
11573
  const selected = this.isSelected();
10817
11574
  return this.renderButton(createElement, editorContext, {
10818
11575
  icon: selected ? 'rte-fullscreen-exit' : 'rte-fullscreen-enter',
11576
+ ariaLabel: selected
11577
+ ? editorContext.translation.t('Exit fullscreen mode')
11578
+ : editorContext.translation.t('Enter fullscreen mode'),
10819
11579
  tooltip: {
10820
11580
  text: selected
10821
11581
  ? internalTranslationController.VegaInternalTranslation.t('Exit fullscreen mode')
@@ -10990,225 +11750,2807 @@ class FullscreenController {
10990
11750
  FullscreenController.documentScrollLockStates.set(ownerDocument, Object.assign(Object.assign({}, currentState), { lockCount: currentState.lockCount - 1 }));
10991
11751
  return;
10992
11752
  }
10993
- ownerDocument.body.style.overflow = currentState.bodyOverflow;
10994
- ownerDocument.documentElement.style.overflow = currentState.documentOverflow;
10995
- FullscreenController.documentScrollLockStates.delete(ownerDocument);
11753
+ ownerDocument.body.style.overflow = currentState.bodyOverflow;
11754
+ ownerDocument.documentElement.style.overflow = currentState.documentOverflow;
11755
+ FullscreenController.documentScrollLockStates.delete(ownerDocument);
11756
+ }
11757
+ }
11758
+ FullscreenController.STYLE_TAG_ID = 'v-rte-fullscreen-styles';
11759
+ FullscreenController.HOST_FULLSCREEN_STYLE = 'position:fixed;inset:0;background-color:rgba(var(--v-bg-primary, 252, 252, 252, 1));';
11760
+ /**
11761
+ * Only three things need overriding inside the shadow root:
11762
+ * 1. The outer vega-flex wrapper must fill the host height (`:host >`
11763
+ * avoids hitting the toolbar's nested vega-flex).
11764
+ * 2. The editor container must grow to fill remaining space and drop
11765
+ * the fixed pixel height that Stencil injects from the `rows` prop.
11766
+ * 3. The source-view container (shown in source-edit mode) also grows
11767
+ * and owns vertical scrolling so long source code is reachable.
11768
+ * 4. overflow:auto on the container lets content scroll without clipping
11769
+ * internal pop-ups (link editor, color picker, etc.) at the host level.
11770
+ */
11771
+ FullscreenController.INNER_FULLSCREEN_CSS = ':host > vega-flex { height: 100%; padding: 5px; box-sizing: border-box; }' +
11772
+ ' .rich-text-editor-container { flex: 1 !important; height: auto !important; min-height: 0 !important; resize: none !important; overflow: auto !important; }' +
11773
+ ' .source-view-container:not(.vega-hidden) { display: flex !important; flex: 1 !important; min-height: 0 !important; overflow: auto !important; flex-direction: column; }';
11774
+ FullscreenController.documentScrollLockStates = new WeakMap();
11775
+
11776
+ /**
11777
+ * Rich Text Editor extension that adds a toolbar button for viewport fullscreen mode.
11778
+ *
11779
+ * OOP Pattern: Extends VegaRTEExtension with fullscreen feature.
11780
+ * Uses a per-host controller store to isolate state across hosts.
11781
+ */
11782
+ class VegaRTEFullscreenExtension extends linkExtension.VegaRTEExtension {
11783
+ /** @inheritDoc */
11784
+ prepareBeforeLoad(host) {
11785
+ const controller = new FullscreenController(host);
11786
+ VegaRTEFullscreenExtension.controllerStore.set(host, controller);
11787
+ this.registerToolbarButtonRenderer(VegaRTEFullscreenExtension.TOOLBAR_BUTTON_KEY, new RTEFullscreenToolbarButtonRenderer(controller), host);
11788
+ }
11789
+ /**
11790
+ * Restore document scroll if the editor is removed while fullscreen is active.
11791
+ * Without this, body overflow:hidden would persist after the host is gone.
11792
+ */
11793
+ destroyExtension() {
11794
+ var _a, _b;
11795
+ if ((_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.host) {
11796
+ const host = this.extensionContext.host;
11797
+ (_b = VegaRTEFullscreenExtension.controllerStore.get(host)) === null || _b === void 0 ? void 0 : _b.exitFullscreen();
11798
+ VegaRTEFullscreenExtension.controllerStore.delete(host);
11799
+ }
11800
+ }
11801
+ }
11802
+ VegaRTEFullscreenExtension.TOOLBAR_BUTTON_KEY = 'fullscreen';
11803
+ VegaRTEFullscreenExtension.controllerStore = VegaRTEFullscreenExtension.createStateStore();
11804
+
11805
+ var RTEPasteMode;
11806
+ (function (RTEPasteMode) {
11807
+ RTEPasteMode["RICH"] = "rich";
11808
+ RTEPasteMode["WORD"] = "word";
11809
+ })(RTEPasteMode || (RTEPasteMode = {}));
11810
+ /**
11811
+ * Priority scale shared by all paste processing strategies.
11812
+ */
11813
+ var PasteProcessingStrategyPriority;
11814
+ (function (PasteProcessingStrategyPriority) {
11815
+ /** Fallback strategy used only when no specialized strategy matches. */
11816
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["DEFAULT_FALLBACK"] = -1] = "DEFAULT_FALLBACK";
11817
+ /** Baseline priority for generic strategies. */
11818
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["BASE"] = 0] = "BASE";
11819
+ /** Word strategy priority so it outranks generic strategies. */
11820
+ PasteProcessingStrategyPriority[PasteProcessingStrategyPriority["WORD"] = 10] = "WORD";
11821
+ })(PasteProcessingStrategyPriority || (PasteProcessingStrategyPriority = {}));
11822
+ /**
11823
+ * Abstract base class for paste processing strategies.
11824
+ *
11825
+ * Each strategy implements detection logic (`canHandle`) and transformation
11826
+ * logic (`process`) for a specific clipboard source (Word, Google Docs, etc.).
11827
+ * The strategy selector chooses the highest-priority strategy that can handle
11828
+ * the given HTML.
11829
+ */
11830
+ class AbstractPasteProcessingStrategy {
11831
+ /**
11832
+ * Downstream paste mode marker associated with this strategy.
11833
+ *
11834
+ * Defaults to regular rich-text paste unless a specialized strategy overrides it.
11835
+ *
11836
+ * @returns {RTEPasteMode} Paste mode marker for downstream handlers.
11837
+ */
11838
+ get type() {
11839
+ return RTEPasteMode.RICH;
11840
+ }
11841
+ /**
11842
+ * Optional: Strategy priority when multiple strategies match.
11843
+ * Higher numbers = higher priority. Default: 0.
11844
+ *
11845
+ * @returns {number} Strategy priority.
11846
+ */
11847
+ get priority() {
11848
+ return PasteProcessingStrategyPriority.BASE;
11849
+ }
11850
+ /**
11851
+ * Whether pasted images from this source should be extracted into local
11852
+ * previews by the paste extension after {@link process} runs.
11853
+ *
11854
+ * @returns {boolean} `false` unless a strategy opts into image processing.
11855
+ */
11856
+ get supportsImageProcessing() {
11857
+ return false;
11858
+ }
11859
+ }
11860
+
11861
+ const paste = {
11862
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.3.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path fill="currentColor" d="M80 96v16c0 17.7 14.3 32 32 32h60.8c16.6-28.7 47.6-48 83.2-48h62c-7.1-27.6-32.2-48-62-48H215.4C211.6 20.9 188.2 0 160 0s-51.6 20.9-55.4 48H64C28.7 48 0 76.7 0 112V384c0 35.3 28.7 64 64 64h96V400H64c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16H80zm64-40a16 16 0 1 1 32 0 16 16 0 1 1 -32 0zM256 464c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H384v48c0 17.7 14.3 32 32 32h48V448c0 8.8-7.2 16-16 16H256zm192 48c35.3 0 64-28.7 64-64V227.9c0-12.7-5.1-24.9-14.1-33.9l-51.9-51.9c-9-9-21.2-14.1-33.9-14.1H256c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H448z"/></svg>`,
11863
+ };
11864
+
11865
+ /**
11866
+ * Renders and manages the paste format chooser UI.
11867
+ */
11868
+ class RTEPasteChooserUI {
11869
+ constructor(hostRoot, callbacks, options = {}) {
11870
+ this.hostRoot = hostRoot;
11871
+ this.callbacks = callbacks;
11872
+ this.options = options;
11873
+ this.chooserEl = null;
11874
+ this.dropdownEl = null;
11875
+ this.triggerButtonEl = null;
11876
+ }
11877
+ /**
11878
+ * Opens the paste-mode chooser at the given position.
11879
+ *
11880
+ * @param {PasteChooserPosition} position Viewport position for the chooser.
11881
+ */
11882
+ open(position) {
11883
+ this.destroy();
11884
+ const doc = this.hostRoot.ownerDocument;
11885
+ const chooser = doc.createElement('div');
11886
+ chooser.setAttribute(RTEPasteChooserUI.CHOOSER_ATTR, 'true');
11887
+ chooser.style.position = 'fixed';
11888
+ chooser.style.zIndex = '1000';
11889
+ chooser.style.left = `${position.left}px`;
11890
+ chooser.style.top = `${position.top}px`;
11891
+ const dropdownEl = this.createPasteChooserDropdown(doc, position.placement);
11892
+ dropdownEl.placement = position.placement;
11893
+ chooser.append(dropdownEl);
11894
+ this.hostRoot.appendChild(chooser);
11895
+ this.chooserEl = chooser;
11896
+ this.dropdownEl = dropdownEl;
11897
+ dropdownEl.addEventListener('vegaShow', () => {
11898
+ if (this.triggerButtonEl) {
11899
+ this.triggerButtonEl.selected = true;
11900
+ }
11901
+ });
11902
+ dropdownEl.addEventListener('vegaHide', () => {
11903
+ if (this.triggerButtonEl) {
11904
+ this.triggerButtonEl.selected = false;
11905
+ }
11906
+ });
11907
+ }
11908
+ /**
11909
+ * Removes the chooser from the DOM.
11910
+ */
11911
+ destroy() {
11912
+ var _a;
11913
+ if (this.dropdownEl && typeof this.dropdownEl.hide === 'function') {
11914
+ void this.dropdownEl.hide();
11915
+ }
11916
+ if ((_a = this.chooserEl) === null || _a === void 0 ? void 0 : _a.parentNode) {
11917
+ this.chooserEl.parentNode.removeChild(this.chooserEl);
11918
+ }
11919
+ if (this.triggerButtonEl) {
11920
+ this.triggerButtonEl.selected = false;
11921
+ }
11922
+ this.dropdownEl = null;
11923
+ this.chooserEl = null;
11924
+ this.triggerButtonEl = null;
11925
+ }
11926
+ /**
11927
+ * Determines whether the given event path targets the chooser.
11928
+ *
11929
+ * @param {EventTarget[]} eventPath Composed path of an event.
11930
+ * @returns {boolean} `true` when the path includes the chooser.
11931
+ */
11932
+ includesEventPath(eventPath) {
11933
+ if (!this.chooserEl) {
11934
+ return false;
11935
+ }
11936
+ const isDropdownContentClick = eventPath.some((target) => {
11937
+ return 'tagName' in target && target.tagName === 'VEGA-DROPDOWN-CONTENT-BOX';
11938
+ });
11939
+ return eventPath.includes(this.chooserEl) || isDropdownContentClick;
11940
+ }
11941
+ /**
11942
+ * Builds the dropdown element with the rich text paste option.
11943
+ *
11944
+ * @param {Document} doc Document used to create elements.
11945
+ * @param {['bottom', 'top'] | ['top', 'bottom']} placement Preferred placement order.
11946
+ * @returns {HTMLElement} Configured dropdown element.
11947
+ */
11948
+ createPasteChooserDropdown(doc, placement) {
11949
+ const dropdownEl = doc.createElement('vega-dropdown');
11950
+ dropdownEl.trigger = 'click';
11951
+ dropdownEl.selectType = 'single';
11952
+ dropdownEl.selectedSourceKey = 'rich';
11953
+ dropdownEl.maxWidth = 220;
11954
+ dropdownEl.alignment = 'start';
11955
+ dropdownEl.itemDisplayRule = 'ellipsis';
11956
+ dropdownEl.isScreenPosition = true;
11957
+ const triggerButton = doc.createElement('vega-rich-text-editor-toolbar-button');
11958
+ const arrowIcon = placement[0] === 'top' ? 'chevron-up' : 'chevron-down';
11959
+ triggerButton.setAttribute(RTEPasteChooserUI.CHOOSER_TRIGGER_ATTR, 'true');
11960
+ triggerButton.setAttribute('aria-label', internalTranslationController.VegaInternalTranslation.t('Paste options'));
11961
+ triggerButton.setAttribute('arrow-icon', arrowIcon);
11962
+ triggerButton.icon = 'rte-paste';
11963
+ triggerButton.showArrowIcon = true;
11964
+ triggerButton.selected = false;
11965
+ this.triggerButtonEl = triggerButton;
11966
+ const tooltipEl = doc.createElement('vega-tooltip');
11967
+ tooltipEl.text = internalTranslationController.VegaInternalTranslation.t('Paste options');
11968
+ tooltipEl.placement = ['bottom', 'top'];
11969
+ tooltipEl.append(triggerButton);
11970
+ dropdownEl.append(tooltipEl);
11971
+ const itemsContainer = doc.createElement('div');
11972
+ itemsContainer.setAttribute('slot', 'items');
11973
+ const dropdownItems = [
11974
+ this.createDropdownItem(doc, RTEPasteMode.RICH, internalTranslationController.VegaInternalTranslation.t('Use rich text'), RTEPasteChooserUI.CHOOSER_RICH_ATTR),
11975
+ ];
11976
+ if (this.options.showWordOption) {
11977
+ dropdownItems.push(this.createDropdownItem(doc, RTEPasteMode.WORD, internalTranslationController.VegaInternalTranslation.t('Use Word'), RTEPasteChooserUI.CHOOSER_WORD_ATTR));
11978
+ }
11979
+ itemsContainer.append(...dropdownItems);
11980
+ dropdownEl.append(itemsContainer);
11981
+ dropdownEl.addEventListener('vegaDropdownClick', (event) => {
11982
+ const mode = event.detail;
11983
+ if (mode === RTEPasteMode.RICH || mode === RTEPasteMode.WORD) {
11984
+ this.callbacks.onModeSelect(mode);
11985
+ }
11986
+ });
11987
+ return dropdownEl;
11988
+ }
11989
+ /**
11990
+ * Creates a single dropdown item element for a paste mode.
11991
+ *
11992
+ * @param {Document} doc Document used to create the element.
11993
+ * @param {RTEPasteMode} key Paste mode key for the item.
11994
+ * @param {string} label Display label for the item.
11995
+ * @param {string} dataAttrName Data attribute marker for the item.
11996
+ * @returns {HTMLVegaDropdownItemElement} Configured dropdown item element.
11997
+ */
11998
+ createDropdownItem(doc, key, label, dataAttrName) {
11999
+ const itemEl = doc.createElement('vega-dropdown-item');
12000
+ itemEl.itemKey = key;
12001
+ itemEl.label = label;
12002
+ itemEl.setAttribute(dataAttrName, 'true');
12003
+ return itemEl;
12004
+ }
12005
+ }
12006
+ (() => {
12007
+ internalIconManager.VegaInternalIconManager.register({
12008
+ 'rte-paste': paste,
12009
+ });
12010
+ })();
12011
+ RTEPasteChooserUI.CHOOSER_ATTR = 'data-rte-paste-chooser';
12012
+ RTEPasteChooserUI.CHOOSER_RICH_ATTR = 'data-rte-paste-type-rich';
12013
+ RTEPasteChooserUI.CHOOSER_WORD_ATTR = 'data-rte-paste-type-word';
12014
+ RTEPasteChooserUI.CHOOSER_TRIGGER_ATTR = 'data-rte-paste-trigger';
12015
+
12016
+ /**
12017
+ * Default paste processing strategy that acts as a fallback when no other
12018
+ * strategy matches. This strategy always accepts the content and passes it
12019
+ * through unchanged — the normal RTE paste pipeline (DOMParser +
12020
+ * ElementToDtoStrategyProcessor) handles the rest.
12021
+ */
12022
+ class DefaultPasteProcessingStrategy extends AbstractPasteProcessingStrategy {
12023
+ /**
12024
+ * Always matches as the terminal fallback strategy.
12025
+ *
12026
+ * @param {string} html Raw clipboard HTML.
12027
+ * @returns {boolean} Always `true`.
12028
+ */
12029
+ canHandle(html) {
12030
+ // Default strategy is the fallback — always returns true.
12031
+ return html !== undefined;
12032
+ }
12033
+ /**
12034
+ * Returns the original HTML unchanged.
12035
+ *
12036
+ * @param {string} html Raw clipboard HTML.
12037
+ * @returns {string} Unchanged HTML.
12038
+ */
12039
+ process(html) {
12040
+ // Current default behavior: pass through unchanged
12041
+ // (DOMParser + ElementToDtoStrategyProcessor handles the rest)
12042
+ return html;
12043
+ }
12044
+ /**
12045
+ * Fallback priority so other strategies can win when matched.
12046
+ *
12047
+ * @returns {number} Strategy priority.
12048
+ */
12049
+ get priority() {
12050
+ return PasteProcessingStrategyPriority.DEFAULT_FALLBACK;
12051
+ }
12052
+ }
12053
+
12054
+ /**
12055
+ * Contract for Word DOM structure transformers. Each transformer is responsible
12056
+ * for one structural concern (list markers, paragraph roles, tables, images…).
12057
+ * Register new transformers in {@link WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS}
12058
+ * to extend Word paste support without touching the core pipeline.
12059
+ */
12060
+ const WORD_SANITIZE_ALL_TAGS_KEY = '*';
12061
+
12062
+ /** CSS class prefix used by the RTE to encode text-style roles on elements. */
12063
+ const RTE_TEXT_STYLE_CLASS_PREFIX = 'v-rte--text-style-';
12064
+ /**
12065
+ * Maps Word title / subtitle / heading paragraph style class names onto RTE
12066
+ * CSS text-style classes. Any pre-existing `data-type` attributes are stripped
12067
+ * first so only trusted values remain. Using a class instead of a custom
12068
+ * attribute prevents the value from leaking into the DTO's custom-attribute
12069
+ * annotation and subsequently into the serialized HTML output.
12070
+ */
12071
+ class WordParagraphRoleTransformer {
12072
+ /** @inheritDoc */
12073
+ apply(root) {
12074
+ // Strip any pre-existing data-type attributes so untrusted source values
12075
+ // can never influence the role resolution.
12076
+ Array.from(root.querySelectorAll('[data-type]')).forEach((element) => {
12077
+ element.removeAttribute('data-type');
12078
+ });
12079
+ Array.from(root.querySelectorAll('p')).forEach((paragraph) => {
12080
+ const rawClass = paragraph.getAttribute('class');
12081
+ const role = this.resolveRole(rawClass);
12082
+ // Drop the Word paragraph class once its role has been extracted so
12083
+ // that Word artifacts (e.g. `MsoTitle`, `MsoNormal`) never leak into
12084
+ // the sanitized output.
12085
+ if (rawClass !== null) {
12086
+ paragraph.removeAttribute('class');
12087
+ }
12088
+ if (role) {
12089
+ // Encode the role as an RTE text-style CSS class so the downstream
12090
+ // DTO processor can resolve it via getElementTypeByClassName().
12091
+ paragraph.classList.add(`${RTE_TEXT_STYLE_CLASS_PREFIX}${role}`);
12092
+ }
12093
+ });
12094
+ }
12095
+ /** @inheritDoc */
12096
+ getAllowedTags() {
12097
+ return [
12098
+ 'P',
12099
+ 'BR',
12100
+ 'SPAN',
12101
+ 'STRONG',
12102
+ 'B',
12103
+ 'EM',
12104
+ 'I',
12105
+ 'U',
12106
+ 'S',
12107
+ 'STRIKE',
12108
+ 'DEL',
12109
+ 'H1',
12110
+ 'H2',
12111
+ 'H3',
12112
+ 'H4',
12113
+ 'H5',
12114
+ 'H6',
12115
+ 'A',
12116
+ // Inline `<code>` is treated as an inline text annotation (like
12117
+ // STRONG/EM/U) and therefore lives with the paragraph/inline
12118
+ // allowlist. Block-level `<pre>` code blocks are owned by
12119
+ // {@link WordCodeBlockTransformer}.
12120
+ 'CODE',
12121
+ ];
12122
+ }
12123
+ /** @inheritDoc */
12124
+ getAllowedAttributes() {
12125
+ // `class` must be preserved so this transformer can parse Word paragraph
12126
+ // roles (e.g., MsoTitle, MsoSubtitle, MsoHeadingN) in Phase 1. These classes
12127
+ // are ultimately stripped when pasting in autoMatchFormat mode.
12128
+ return new Map([
12129
+ [WORD_SANITIZE_ALL_TAGS_KEY, ['class', 'style']],
12130
+ ['A', ['href', 'target', 'title']],
12131
+ ]);
12132
+ }
12133
+ /** @inheritDoc */
12134
+ getAllowedStyles() {
12135
+ return [
12136
+ 'color',
12137
+ 'background',
12138
+ 'text-align',
12139
+ 'text-indent',
12140
+ 'text-decoration',
12141
+ 'margin',
12142
+ 'padding',
12143
+ 'font',
12144
+ 'line-height',
12145
+ 'letter-spacing',
12146
+ 'vertical-align',
12147
+ ];
12148
+ }
12149
+ /**
12150
+ * Resolves the RTE text style for a Word paragraph class name.
12151
+ *
12152
+ * @param {string | null} className Raw `class` attribute value.
12153
+ * @returns {WordParagraphRole | null} Matched role or `null`.
12154
+ */
12155
+ resolveRole(className) {
12156
+ if (!className) {
12157
+ return null;
12158
+ }
12159
+ const normalized = className.toLowerCase();
12160
+ const headingMatch = /msoheading([1-6])/.exec(normalized);
12161
+ if (headingMatch) {
12162
+ return `heading-${headingMatch[1]}`;
12163
+ }
12164
+ if (/msosubtitle/.test(normalized)) {
12165
+ return 'subtitle';
12166
+ }
12167
+ if (/msotitle/.test(normalized)) {
12168
+ return 'title';
12169
+ }
12170
+ return null;
12171
+ }
12172
+ }
12173
+
12174
+ /** Font families Word uses to render bullet symbols rather than real characters. */
12175
+ const BULLET_FONT_PATTERN = /symbol|wingdings|webdings/i;
12176
+ /**
12177
+ * Matches the paragraph-level Word list marker (`mso-list:l0 level1 lfo1`). The
12178
+ * presence of `l<number>` distinguishes a genuine list paragraph from the inner
12179
+ * `mso-list:Ignore` marker span.
12180
+ */
12181
+ const PARAGRAPH_LIST_PATTERN = /mso-list\s*:\s*l\d+/i;
12182
+ /** Extracts the Word nesting depth (`level<number>`) from a list paragraph. */
12183
+ const LIST_LEVEL_PATTERN = /mso-list\s*:\s*l\d+\s+level(\d+)/i;
12184
+ /** Extracts the abstract Word list template id (`l<number>`). */
12185
+ const LIST_TEMPLATE_ID_PATTERN = /mso-list\s*:\s*l(\d+)/i;
12186
+ /** Extracts the Word list-format override id (`lfo<number>`), unique per list instance. */
12187
+ const LIST_OVERRIDE_ID_PATTERN = /\blfo(\d+)/i;
12188
+ /** Matches the inner span that holds the Word-rendered bullet / number glyph. */
12189
+ const LIST_IGNORE_PATTERN = /mso-list\s*:\s*ignore/i;
12190
+ /** Extracts a `font-family` declaration value from a preserved style string. */
12191
+ const FONT_FAMILY_PATTERN = /font-family\s*:\s*([^;]+)/i;
12192
+ /** Fallback Word list paragraph class when no `mso-list` style is present. */
12193
+ const LIST_PARAGRAPH_CLASS_PATTERN = /MsoListParagraph/i;
12194
+ /**
12195
+ * CSS `list-style-type` values keyed by the shape of the Word marker token.
12196
+ * Decimal markers are intentionally absent: a plain `<ol>` already renders as
12197
+ * `1. 2. 3.`, so numeric lists keep the current behavior with no inline style.
12198
+ *
12199
+ * Roman patterns explicitly accept a lone `i` / `I` (representing 1), which is
12200
+ * the typical first item of a Roman-numeral list. Multi-character sequences
12201
+ * must contain only Roman letters.
12202
+ */
12203
+ const LOWER_ROMAN_PATTERN = /^(i|[ivxlcdm]{2,})$/;
12204
+ const UPPER_ROMAN_PATTERN = /^(I|[IVXLCDM]{2,})$/;
12205
+ const LOWER_ALPHA_PATTERN = /^[a-z]+$/;
12206
+ const UPPER_ALPHA_PATTERN = /^[A-Z]+$/;
12207
+ const DECIMAL_PATTERN = /^[0-9]+$/;
12208
+ /** Extracts the `list-style-type` value from a preserved style string. */
12209
+ const LIST_STYLE_TYPE_PATTERN = /list-style-type\s*:\s*([^;]+)/i;
12210
+ /**
12211
+ * Maps the HTML `<ol type>` attribute values Word emits on real ordered lists
12212
+ * to the equivalent CSS `list-style-type`. Decimal (`type=1`) is intentionally
12213
+ * absent: a plain `<ol>` already renders as `1. 2. 3.`, so it needs no inline
12214
+ * style (matching the marker-derived handling above).
12215
+ */
12216
+ const OL_TYPE_TO_LIST_STYLE_TYPE = {
12217
+ a: 'lower-alpha',
12218
+ A: 'upper-alpha',
12219
+ i: 'lower-roman',
12220
+ I: 'upper-roman',
12221
+ };
12222
+ /**
12223
+ * Rebuilds Word list paragraphs into real `<ul>` / `<ol>` / `<li>` structures.
12224
+ *
12225
+ * Word does not emit list elements: it emits a flat sequence of `<p>` blocks
12226
+ * that each carry an `mso-list:l<id> level<depth> lfo<override>` marker plus an
12227
+ * inner `mso-list:Ignore` span that renders the visible bullet or number. This
12228
+ * transformer walks every container that hosts list paragraphs (so nested
12229
+ * `<div>` / table cells are covered), strips the marker span, decides bullet
12230
+ * vs. numbered from the marker text / font, and folds the flat items back into
12231
+ * a nested list tree the RTE slimmer can parse.
12232
+ *
12233
+ * Runs before {@link WordParagraphRoleTransformer} so the converted `<li>`
12234
+ * elements are no longer seen as paragraphs during role resolution.
12235
+ */
12236
+ class WordListRoleTransformer {
12237
+ /** @inheritDoc */
12238
+ apply(root) {
12239
+ // Word can also emit real `<ol>` / `<ul>` structures where a nested list
12240
+ // is a **sibling** of the preceding `<li>` rather than a child of it (an
12241
+ // invalid nesting the HTML parser preserves as-is). Fix that first so the
12242
+ // rest of the pipeline sees the standard `<li><ol>…</ol></li>` shape.
12243
+ this.nestSiblingLists(root);
12244
+ // Word may nest list paragraphs inside containers (e.g. `<div>`, table
12245
+ // cells). Group by their direct parent so contiguous siblings in each
12246
+ // container are folded together, regardless of where they sit in the tree.
12247
+ const containers = new Set();
12248
+ Array.from(root.querySelectorAll('p')).forEach((paragraph) => {
12249
+ if (this.isWordListParagraph(paragraph) && paragraph.parentElement) {
12250
+ containers.add(paragraph.parentElement);
12251
+ }
12252
+ });
12253
+ // Include the root itself when it hosts list paragraphs directly.
12254
+ if (Array.from(root.children).some((child) => this.isWordListParagraph(child))) {
12255
+ containers.add(root);
12256
+ }
12257
+ containers.forEach((container) => this.processContainer(container));
12258
+ // Word also emits real `<ol type=...>` elements whose numbering style lives
12259
+ // on the (non-allowlisted) `type` attribute. Fold that into a preserved
12260
+ // `list-style-type` so the marker style survives the allowlist pass.
12261
+ this.applyOrderedListTypeAttributes(root);
12262
+ }
12263
+ /** @inheritDoc */
12264
+ getAllowedTags() {
12265
+ return ['UL', 'OL', 'LI'];
12266
+ }
12267
+ /** @inheritDoc */
12268
+ getAllowedAttributes() {
12269
+ return new Map();
12270
+ }
12271
+ /** @inheritDoc */
12272
+ getAllowedStyles() {
12273
+ return ['list-style'];
12274
+ }
12275
+ /**
12276
+ * Moves any `<ol>` / `<ul>` that appears as a direct child of another
12277
+ * `<ol>` / `<ul>` into the preceding `<li>` sibling, so downstream strategies
12278
+ * see a well-formed nested list. Word emits this invalid shape when it uses
12279
+ * real list elements (rather than flat `mso-list` paragraphs) — the browser
12280
+ * parser keeps the nested list as a sibling of the `<li>` it should belong
12281
+ * to, and the RTE's OL/UL block strategy would drop it because its
12282
+ * `appendChildBlocks` only keeps `<li>` children.
12283
+ *
12284
+ * Runs bottom-up so a nested list that also has misplaced children is fixed
12285
+ * before its own parent list picks it up.
12286
+ *
12287
+ * @param {HTMLElement} root Parsed body element.
12288
+ */
12289
+ nestSiblingLists(root) {
12290
+ const lists = Array.from(root.querySelectorAll('ol, ul'));
12291
+ for (let index = lists.length - 1; index >= 0; index--) {
12292
+ Array.from(lists[index].children).forEach((child) => {
12293
+ if (child.tagName !== 'OL' && child.tagName !== 'UL') {
12294
+ return;
12295
+ }
12296
+ const previousItem = child.previousElementSibling;
12297
+ if (previousItem && previousItem.tagName === 'LI') {
12298
+ previousItem.appendChild(child);
12299
+ }
12300
+ });
12301
+ }
12302
+ }
12303
+ /**
12304
+ * Converts the HTML `<ol type>` attribute into a preserved
12305
+ * `list-style-type` declaration for every ordered list that carries one.
12306
+ *
12307
+ * Word can paste genuine `<ol>` elements (rather than flat list paragraphs)
12308
+ * that encode alpha / Roman numbering via the legacy `type` attribute
12309
+ * (`type=a`, `type=i`, `type=I`, …). The `type` attribute is not on the
12310
+ * allowlist and would be dropped, losing the numbering style, so it is mapped
12311
+ * onto `list-style-type` inside `data-style`. Decimal (`type=1`) lists are
12312
+ * left untouched because a bare `<ol>` already renders as `1. 2. 3.`. An
12313
+ * existing `list-style-type` declaration wins and is never overwritten.
12314
+ *
12315
+ * @param {HTMLElement} root Parsed body element.
12316
+ */
12317
+ applyOrderedListTypeAttributes(root) {
12318
+ Array.from(root.querySelectorAll('ol[type]')).forEach((orderedList) => {
12319
+ const type = orderedList.getAttribute('type') || '';
12320
+ const listStyleType = OL_TYPE_TO_LIST_STYLE_TYPE[type];
12321
+ if (!listStyleType) {
12322
+ return;
12323
+ }
12324
+ const style = orderedList.getAttribute('data-style') || '';
12325
+ if (LIST_STYLE_TYPE_PATTERN.test(style)) {
12326
+ return;
12327
+ }
12328
+ const prefix = style.trim() === '' ? '' : `${style.replace(/;\s*$/, '')}; `;
12329
+ orderedList.setAttribute('data-style', `${prefix}list-style-type: ${listStyleType}`);
12330
+ });
12331
+ }
12332
+ /**
12333
+ * Walks a container, folding each contiguous run of Word list paragraphs
12334
+ * into a nested list tree in place of the original paragraphs.
12335
+ *
12336
+ * @param {HTMLElement} container Element whose direct children may include list paragraphs.
12337
+ */
12338
+ processContainer(container) {
12339
+ const children = Array.from(container.children);
12340
+ let index = 0;
12341
+ while (index < children.length) {
12342
+ if (!this.isWordListParagraph(children[index])) {
12343
+ index++;
12344
+ continue;
12345
+ }
12346
+ const run = [];
12347
+ while (index < children.length && this.isWordListParagraph(children[index])) {
12348
+ run.push(children[index]);
12349
+ index++;
12350
+ }
12351
+ this.transformRun(run, container);
12352
+ }
12353
+ }
12354
+ /**
12355
+ * Determines whether an element is a Word list paragraph.
12356
+ *
12357
+ * A paragraph is only treated as a list when it carries a genuine Word list
12358
+ * marker: either the `mso-list:l<n>` paragraph style, or the `MsoListParagraph`
12359
+ * class **together with** an inner `mso-list:Ignore` marker span. The
12360
+ * `MsoListParagraph` class alone is not sufficient — Word also uses that
12361
+ * paragraph style for plain indented content (e.g. headings), which must not
12362
+ * be folded into a `<ul>` / `<ol>`.
12363
+ *
12364
+ * @param {HTMLElement} element Candidate element.
12365
+ * @returns {boolean} `true` when the element is a `<p>` carrying a Word list marker.
12366
+ */
12367
+ isWordListParagraph(element) {
12368
+ if (element.tagName !== 'P') {
12369
+ return false;
12370
+ }
12371
+ const style = element.getAttribute('data-style') || '';
12372
+ if (PARAGRAPH_LIST_PATTERN.test(style)) {
12373
+ return true;
12374
+ }
12375
+ const className = element.getAttribute('class') || '';
12376
+ return LIST_PARAGRAPH_CLASS_PATTERN.test(className) && this.findMarker(element) !== undefined;
12377
+ }
12378
+ /**
12379
+ * Folds a flat run of Word list paragraphs into a nested list tree inserted
12380
+ * before the run, then removes the original paragraphs.
12381
+ *
12382
+ * @param {HTMLElement[]} run Consecutive Word list paragraphs.
12383
+ * @param {HTMLElement} container Element hosting the run.
12384
+ */
12385
+ transformRun(run, container) {
12386
+ const anchor = run[0];
12387
+ const stack = [];
12388
+ run.forEach((paragraph) => {
12389
+ // Compute the marker once per paragraph and thread it through the
12390
+ // helpers that need it, so the DOM is not re-queried multiple times.
12391
+ const marker = this.findMarker(paragraph);
12392
+ const level = this.resolveLevel(paragraph);
12393
+ const ordered = marker ? this.isOrderedMarker(marker, paragraph) : false;
12394
+ const listId = this.resolveListId(paragraph);
12395
+ // Close any lists deeper than the current item.
12396
+ while (stack.length > 0 && stack[stack.length - 1].level > level) {
12397
+ stack.pop();
12398
+ }
12399
+ // Resolve the marker style with the same-level list already open in
12400
+ // context, so an ambiguous lone "i" / "I" continues an alpha list
12401
+ // instead of being misread as Roman 1. The marker text is still on the
12402
+ // paragraph here (buildListItem strips it below).
12403
+ let top = stack[stack.length - 1];
12404
+ const listStyleType = ordered && marker ? this.resolveListStyleType(marker, top, level, listId) : null;
12405
+ const listItem = this.buildListItem(paragraph, marker);
12406
+ if (!top || top.level < level) {
12407
+ top = this.openNestedList(stack, container, anchor, ordered, level, listStyleType, listId);
12408
+ }
12409
+ else if (this.needsSiblingList(top, ordered, listStyleType, listId)) {
12410
+ top = this.openSiblingList(stack, ordered, level, listStyleType, listId);
12411
+ }
12412
+ top.listEl.appendChild(listItem);
12413
+ });
12414
+ run.forEach((paragraph) => paragraph.remove());
12415
+ }
12416
+ /**
12417
+ * Reports whether a same-level item must break out into a new sibling list.
12418
+ * A different Word list instance always splits (so two separate lists pasted
12419
+ * back-to-back keep independent numbering). Bullet-vs-numbered switches also
12420
+ * split, and numbered lists additionally split when the CSS `list-style-type`
12421
+ * changes (e.g. `1.` → `a)`).
12422
+ *
12423
+ * @param {OpenList} top Currently open list at the same nesting depth.
12424
+ * @param {boolean} ordered Whether the incoming item is numbered.
12425
+ * @param {string | null} listStyleType Incoming numbered list style, if any.
12426
+ * @param {string | null} listId Incoming Word list instance id, if any.
12427
+ * @returns {boolean} `true` when a new sibling list should be opened.
12428
+ */
12429
+ needsSiblingList(top, ordered, listStyleType, listId) {
12430
+ // A known change of list instance means the two runs are distinct lists.
12431
+ if (top.listId !== null && listId !== null && top.listId !== listId) {
12432
+ return true;
12433
+ }
12434
+ if (top.ordered !== ordered) {
12435
+ return true;
12436
+ }
12437
+ if (!ordered) {
12438
+ return false;
12439
+ }
12440
+ return this.readListStyleType(top.listEl) !== listStyleType;
12441
+ }
12442
+ /**
12443
+ * Reads a previously-written `list-style-type` from an open list element.
12444
+ *
12445
+ * @param {HTMLElement} listEl List element.
12446
+ * @returns {string | null} The style value, or `null` when none is set.
12447
+ */
12448
+ readListStyleType(listEl) {
12449
+ const match = LIST_STYLE_TYPE_PATTERN.exec(listEl.getAttribute('data-style') || '');
12450
+ return match ? match[1].trim() : null;
12451
+ }
12452
+ /**
12453
+ * Opens a new list nested one or more levels deeper than the current top.
12454
+ * Word occasionally skips indent levels on paste (e.g. jumping from `level1`
12455
+ * to `level3`); this walks the gap one level at a time, inserting placeholder
12456
+ * lists so the deeper list is nested through empty `<li>` anchors instead of
12457
+ * appearing as a sibling of the shallower list.
12458
+ *
12459
+ * @param {OpenList[]} stack Stack of currently open lists.
12460
+ * @param {HTMLElement} container Host element for the top-level list.
12461
+ * @param {HTMLElement} anchor Element the top-level list is inserted before.
12462
+ * @param {boolean} ordered Whether the new list is numbered.
12463
+ * @param {number} level Word nesting depth for the new list.
12464
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
12465
+ * @param {string | null} listId Word list instance id for the new list.
12466
+ * @returns {OpenList} The newly opened list.
12467
+ */
12468
+ openNestedList(stack, container, anchor, ordered, level, listStyleType, listId) {
12469
+ let currentTop = stack[stack.length - 1];
12470
+ let currentLevel = currentTop ? currentTop.level : 0;
12471
+ while (currentLevel < level - 1) {
12472
+ const bridge = this.createListElement(container, ordered, null);
12473
+ this.attachList(bridge, currentTop, container, anchor);
12474
+ // Empty `<li>` anchor so the next deeper list can be nested inside it.
12475
+ bridge.appendChild(bridge.ownerDocument.createElement('li'));
12476
+ stack.push({ level: currentLevel + 1, ordered, listId, listEl: bridge });
12477
+ currentTop = stack[stack.length - 1];
12478
+ currentLevel = currentTop.level;
12479
+ }
12480
+ const parent = stack[stack.length - 1];
12481
+ const listEl = this.createListElement(container, ordered, listStyleType);
12482
+ this.attachList(listEl, parent, container, anchor);
12483
+ const opened = { level, ordered, listId, listEl };
12484
+ stack.push(opened);
12485
+ return opened;
12486
+ }
12487
+ /**
12488
+ * Replaces the current top list with a sibling list at the same nesting
12489
+ * depth. Used when the list flavor (bullet vs. numbered, or the ordered
12490
+ * marker style) flips between two consecutive same-level items.
12491
+ *
12492
+ * @param {OpenList[]} stack Stack of currently open lists.
12493
+ * @param {boolean} ordered Whether the sibling list is numbered.
12494
+ * @param {number} level Word nesting depth for the sibling list.
12495
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
12496
+ * @param {string | null} listId Word list instance id for the sibling list.
12497
+ * @returns {OpenList} The newly opened sibling list.
12498
+ */
12499
+ openSiblingList(stack, ordered, level, listStyleType, listId) {
12500
+ const current = stack[stack.length - 1];
12501
+ const listEl = this.createListElement(current.listEl, ordered, listStyleType);
12502
+ const parentNode = current.listEl.parentNode;
12503
+ if (parentNode) {
12504
+ parentNode.insertBefore(listEl, current.listEl.nextSibling);
12505
+ }
12506
+ stack.pop();
12507
+ const opened = { level, ordered, listId, listEl };
12508
+ stack.push(opened);
12509
+ return opened;
12510
+ }
12511
+ /**
12512
+ * Attaches a freshly created list element either inside the last item of the
12513
+ * parent list (for nested lists) or before the run anchor (top-level lists).
12514
+ *
12515
+ * @param {HTMLElement} listEl List element to attach.
12516
+ * @param {OpenList | undefined} parent Currently open parent list, if any.
12517
+ * @param {HTMLElement} container Host element used for top-level insertion.
12518
+ * @param {HTMLElement} anchor Element the top-level list is inserted before.
12519
+ */
12520
+ attachList(listEl, parent, container, anchor) {
12521
+ if (parent) {
12522
+ const parentItem = parent.listEl.lastElementChild;
12523
+ (parentItem || parent.listEl).appendChild(listEl);
12524
+ }
12525
+ else {
12526
+ container.insertBefore(listEl, anchor);
12527
+ }
12528
+ }
12529
+ /**
12530
+ * Creates an empty `<ol>` or `<ul>` element, tagging ordered lists with a
12531
+ * `list-style-type` when their markers are not plain decimals.
12532
+ *
12533
+ * @param {HTMLElement} reference Element whose document creates the list.
12534
+ * @param {boolean} ordered Whether to create a numbered list.
12535
+ * @param {string | null} listStyleType CSS `list-style-type` for ordered lists.
12536
+ * @returns {HTMLElement} The new list element.
12537
+ */
12538
+ createListElement(reference, ordered, listStyleType) {
12539
+ const listEl = reference.ownerDocument.createElement(ordered ? 'ol' : 'ul');
12540
+ if (ordered && listStyleType) {
12541
+ // Styles are preserved as `data-style` across the DOMParser boundary and
12542
+ // restored to `style` after the allowlist pass.
12543
+ listEl.setAttribute('data-style', `list-style-type: ${listStyleType}`);
12544
+ }
12545
+ return listEl;
12546
+ }
12547
+ /**
12548
+ * Converts a Word list paragraph into an `<li>` element: the marker span is
12549
+ * removed and the remaining content is moved into the list item.
12550
+ *
12551
+ * @param {HTMLElement} paragraph Word list paragraph.
12552
+ * @param {HTMLElement | undefined} marker Pre-resolved `mso-list:Ignore` span.
12553
+ * @returns {HTMLLIElement} The populated list item.
12554
+ */
12555
+ buildListItem(paragraph, marker) {
12556
+ const listItem = paragraph.ownerDocument.createElement('li');
12557
+ if (marker) {
12558
+ this.preserveMarkerPlaceholderImages(marker, paragraph);
12559
+ this.removeMarker(marker, paragraph);
12560
+ }
12561
+ while (paragraph.firstChild) {
12562
+ listItem.appendChild(paragraph.firstChild);
12563
+ }
12564
+ return listItem;
12565
+ }
12566
+ /**
12567
+ * Moves any local (`file://`) images out of the marker span so they survive
12568
+ * marker removal as list-item placeholders.
12569
+ *
12570
+ * Word renders a picture bullet as an `<img>` inside the `mso-list:Ignore`
12571
+ * marker span. That bullet still occupies one image slot in the clipboard RTF,
12572
+ * so silently dropping it here would leave its RTF blip unconsumed and shift
12573
+ * every following image onto the wrong file. Keeping the bullet as a `file://`
12574
+ * placeholder inside the `<li>` lets downstream preview pairing consume its RTF
12575
+ * slot and then drop it (list images have no editor representation), keeping the
12576
+ * remaining images aligned with their files. Non-local bullet images have no RTF
12577
+ * counterpart and are left in the marker to be removed with it.
12578
+ *
12579
+ * @param {HTMLElement} marker Marker span holding the bullet glyph / image.
12580
+ * @param {HTMLElement} paragraph Owning list paragraph (placeholder host).
12581
+ */
12582
+ preserveMarkerPlaceholderImages(marker, paragraph) {
12583
+ const localImages = Array.from(marker.querySelectorAll('img')).filter((image) => (image.getAttribute('src') || '').startsWith('file://'));
12584
+ // Capture the original first child once so images land ahead of the list
12585
+ // content in their document order (repeated inserts before a stable anchor).
12586
+ const anchor = paragraph.firstChild;
12587
+ localImages.forEach((image) => {
12588
+ paragraph.insertBefore(image, anchor);
12589
+ });
12590
+ }
12591
+ /**
12592
+ * Removes the `mso-list:Ignore` marker span and any wrapper elements it
12593
+ * leaves empty behind.
12594
+ *
12595
+ * @param {HTMLElement} marker Marker span to remove.
12596
+ * @param {HTMLElement} paragraph Owning list paragraph (stop boundary).
12597
+ */
12598
+ removeMarker(marker, paragraph) {
12599
+ let current = marker;
12600
+ while (current !== paragraph) {
12601
+ const parent = current.parentElement;
12602
+ current.remove();
12603
+ if (!parent || parent === paragraph || !this.isEmptyElement(parent)) {
12604
+ break;
12605
+ }
12606
+ current = parent;
12607
+ }
12608
+ }
12609
+ /**
12610
+ * Finds the `mso-list:Ignore` marker span within a list paragraph.
12611
+ *
12612
+ * @param {HTMLElement} paragraph Word list paragraph.
12613
+ * @returns {HTMLElement | undefined} The marker span, if present.
12614
+ */
12615
+ findMarker(paragraph) {
12616
+ return Array.from(paragraph.querySelectorAll('span')).find((span) => LIST_IGNORE_PATTERN.test(span.getAttribute('data-style') || ''));
12617
+ }
12618
+ /**
12619
+ * Reports whether an element has no meaningful (non-whitespace) content left.
12620
+ *
12621
+ * @param {HTMLElement} element Element to inspect.
12622
+ * @returns {boolean} `true` when only whitespace remains.
12623
+ */
12624
+ isEmptyElement(element) {
12625
+ return (element.textContent || '').replace(/[\s\u00A0]/g, '') === '';
12626
+ }
12627
+ /**
12628
+ * Resolves the Word nesting depth for a list paragraph (defaults to 1).
12629
+ *
12630
+ * @param {HTMLElement} paragraph Word list paragraph.
12631
+ * @returns {number} One-based nesting depth.
12632
+ */
12633
+ resolveLevel(paragraph) {
12634
+ const style = paragraph.getAttribute('data-style') || '';
12635
+ const match = LIST_LEVEL_PATTERN.exec(style);
12636
+ return match ? parseInt(match[1], 10) : 1;
12637
+ }
12638
+ /**
12639
+ * Resolves the Word list instance id for a paragraph. Prefers the list-format
12640
+ * override (`lfo<n>`), which is unique per pasted list, and falls back to the
12641
+ * abstract list template id (`l<n>`). Returns `null` when neither is present
12642
+ * (e.g. the `MsoListParagraph` class fallback).
12643
+ *
12644
+ * @param {HTMLElement} paragraph Word list paragraph.
12645
+ * @returns {string | null} The list instance id, or `null` when unknown.
12646
+ */
12647
+ resolveListId(paragraph) {
12648
+ const style = paragraph.getAttribute('data-style') || '';
12649
+ const override = LIST_OVERRIDE_ID_PATTERN.exec(style);
12650
+ if (override) {
12651
+ return `lfo${override[1]}`;
12652
+ }
12653
+ const template = LIST_TEMPLATE_ID_PATTERN.exec(style);
12654
+ return template ? `l${template[1]}` : null;
12655
+ }
12656
+ /**
12657
+ * Decides whether a resolved marker span represents a numbered (`<ol>`) or
12658
+ * bulleted (`<ul>`) item based on its text and font.
12659
+ *
12660
+ * @param {HTMLElement} marker Marker span.
12661
+ * @param {HTMLElement} paragraph Owning list paragraph.
12662
+ * @returns {boolean} `true` for numbered items, `false` for bulleted items.
12663
+ */
12664
+ isOrderedMarker(marker, paragraph) {
12665
+ const markerText = marker.textContent.replace(/[\s\u00A0]/g, '');
12666
+ if (BULLET_FONT_PATTERN.test(this.resolveMarkerFont(marker, paragraph))) {
12667
+ return false;
12668
+ }
12669
+ // Numbered markers are alphanumeric sequences ("1.", "a)", "iv)");
12670
+ // bullet markers are standalone symbols.
12671
+ return /[0-9]/.test(markerText) || /^[a-z]+[.)]/i.test(markerText);
12672
+ }
12673
+ /**
12674
+ * Resolves the CSS `list-style-type` for a numbered list marker.
12675
+ * Plain decimal markers ("1.", "2.") return `null` so a bare `<ol>` is used;
12676
+ * alphabetic and Roman markers map to the matching CSS value so their marker
12677
+ * style is preserved.
12678
+ *
12679
+ * A lone `i` / `I` is ambiguous: it is both Roman numeral 1 and the 9th
12680
+ * letter of the alphabet. When the same-level list already open for this
12681
+ * instance is alpha, the marker is kept alpha so a long `a) ... h) i) j)`
12682
+ * run does not split into a Roman sibling at item 9; otherwise the lone
12683
+ * marker is treated as Roman 1 (the first item of a Roman list).
12684
+ *
12685
+ * @param {HTMLElement} marker Marker span.
12686
+ * @param {OpenList | undefined} openList Same-depth list already open, if any.
12687
+ * @param {number} level Word nesting depth of the incoming item.
12688
+ * @param {string | null} listId Word list instance id of the incoming item.
12689
+ * @returns {string | null} The CSS `list-style-type`, or `null` for decimals.
12690
+ */
12691
+ resolveListStyleType(marker, openList, level, listId) {
12692
+ // Drop surrounding whitespace and the trailing "." / ")" separator to
12693
+ // isolate the numbering token (e.g. "a)" -> "a", "iv." -> "iv").
12694
+ const token = marker.textContent.replace(/[\s\u00A0]/g, '').replace(/[.)]+$/, '');
12695
+ if (DECIMAL_PATTERN.test(token)) {
12696
+ return null;
12697
+ }
12698
+ // Disambiguate a lone "i" / "I" from list context before the Roman check:
12699
+ // if the current same-level list is already alpha, continue it.
12700
+ if (token === 'i' || token === 'I') {
12701
+ const alphaStyle = token === 'i' ? 'lower-alpha' : 'upper-alpha';
12702
+ if (this.continuesAlphaList(openList, level, listId, alphaStyle)) {
12703
+ return alphaStyle;
12704
+ }
12705
+ }
12706
+ // Roman tokens are checked before alpha so "i" / "I" (Roman numeral 1) and
12707
+ // multi-character sequences like "ii" / "IV" are not mistaken for letters.
12708
+ if (LOWER_ROMAN_PATTERN.test(token)) {
12709
+ return 'lower-roman';
12710
+ }
12711
+ if (UPPER_ROMAN_PATTERN.test(token)) {
12712
+ return 'upper-roman';
12713
+ }
12714
+ if (LOWER_ALPHA_PATTERN.test(token)) {
12715
+ return 'lower-alpha';
12716
+ }
12717
+ if (UPPER_ALPHA_PATTERN.test(token)) {
12718
+ return 'upper-alpha';
12719
+ }
12720
+ return null;
12721
+ }
12722
+ /**
12723
+ * Reports whether a lone `i` / `I` marker continues an already-open alpha
12724
+ * list rather than starting a Roman one. True only when the same-depth list
12725
+ * is a matching alpha `<ol>` for the same Word list instance, so an ambiguous
12726
+ * marker at item 9 stays part of the surrounding `lower-alpha` / `upper-alpha`
12727
+ * run instead of opening a Roman sibling.
12728
+ *
12729
+ * @param {OpenList | undefined} openList Same-depth list already open, if any.
12730
+ * @param {number} level Word nesting depth of the incoming item.
12731
+ * @param {string | null} listId Word list instance id of the incoming item.
12732
+ * @param {string} alphaStyle The alpha style the marker would continue.
12733
+ * @returns {boolean} `true` when the marker should be treated as alpha.
12734
+ */
12735
+ continuesAlphaList(openList, level, listId, alphaStyle) {
12736
+ if (!openList || !openList.ordered || openList.level !== level) {
12737
+ return false;
12738
+ }
12739
+ // Distinct Word list instances are separate lists; do not carry style over.
12740
+ if (openList.listId !== null && listId !== null && openList.listId !== listId) {
12741
+ return false;
12742
+ }
12743
+ return this.readListStyleType(openList.listEl) === alphaStyle;
12744
+ }
12745
+ /**
12746
+ * Resolves the effective `font-family` for a marker by walking up to the
12747
+ * paragraph, so Word's `Symbol` / `Wingdings` bullet fonts can be detected.
12748
+ *
12749
+ * @param {HTMLElement} marker Marker span.
12750
+ * @param {HTMLElement} paragraph Owning list paragraph.
12751
+ * @returns {string} The resolved font family, or an empty string.
12752
+ */
12753
+ resolveMarkerFont(marker, paragraph) {
12754
+ let node = marker;
12755
+ while (node && node !== paragraph.parentElement) {
12756
+ const match = FONT_FAMILY_PATTERN.exec(node.getAttribute('data-style') || '');
12757
+ if (match) {
12758
+ return match[1];
12759
+ }
12760
+ node = node.parentElement;
12761
+ }
12762
+ return '';
12763
+ }
12764
+ }
12765
+
12766
+ /**
12767
+ * Normalizes Word image markup into plain <img> tags, drops list-marker images,
12768
+ * and optionally remaps image source paths.
12769
+ */
12770
+ class WordImageTransformer {
12771
+ /** @inheritDoc */
12772
+ getAllowedTags() {
12773
+ return ['IMG'];
12774
+ }
12775
+ /** @inheritDoc */
12776
+ getAllowedAttributes() {
12777
+ return new Map([['IMG', ['src', 'alt', 'title', 'width', 'height']]]);
12778
+ }
12779
+ /** @inheritDoc */
12780
+ getAllowedStyles() {
12781
+ return [];
12782
+ }
12783
+ /** @inheritDoc */
12784
+ apply(root) {
12785
+ this.normalizeWordImageDataElements(root);
12786
+ this.normalizeStandardImages(root);
12787
+ this.liftImagesOutOfTextStyleBlocks(root);
12788
+ this.insertSpanBetweenAdjacentImages(root);
12789
+ }
12790
+ /**
12791
+ * Lifts images out of text-style blocks (`h1`-`h6`, Word title / subtitle
12792
+ * paragraphs) so they become standalone top-level images.
12793
+ *
12794
+ * The RTE data model represents these blocks as text blocks whose children
12795
+ * are text nodes only, so an `<img>` nested inside one has no text-node
12796
+ * representation and would be silently dropped during DTO conversion. Moving
12797
+ * each image to a sibling position right after its block lets the downstream
12798
+ * image-block strategies pick it up. Images are re-inserted in document order
12799
+ * so they stay aligned with the RTF files paired later.
12800
+ *
12801
+ * Word title / subtitle paragraphs still carry their raw `MsoTitle` /
12802
+ * `MsoSubtitle` class here because {@link WordParagraphRoleTransformer} runs
12803
+ * after this transformer.
12804
+ *
12805
+ * @param {HTMLElement} root Parsed Word fragment root.
12806
+ */
12807
+ liftImagesOutOfTextStyleBlocks(root) {
12808
+ const blockElements = Array.from(root.querySelectorAll('h1, h2, h3, h4, h5, h6, p')).filter((element) => this.isImageLiftTargetBlock(element));
12809
+ blockElements.forEach((blockElement) => {
12810
+ if (!blockElement.parentNode) {
12811
+ return;
12812
+ }
12813
+ const imageElements = Array.from(blockElement.querySelectorAll('img'));
12814
+ let referenceNode = blockElement;
12815
+ imageElements.forEach((imageElement) => {
12816
+ blockElement.parentNode.insertBefore(imageElement, referenceNode.nextSibling);
12817
+ referenceNode = imageElement;
12818
+ });
12819
+ });
12820
+ }
12821
+ /**
12822
+ * Reports whether a block hosts its images as text-only children, requiring
12823
+ * nested images to be lifted out: any heading (`h1`-`h6`) or a Word title /
12824
+ * subtitle paragraph.
12825
+ *
12826
+ * @param {HTMLElement} element Candidate block element.
12827
+ * @returns {boolean} `true` when nested images must be lifted out of the block.
12828
+ */
12829
+ isImageLiftTargetBlock(element) {
12830
+ const tagName = element.tagName.toLowerCase();
12831
+ if (/^h[1-6]$/.test(tagName)) {
12832
+ return true;
12833
+ }
12834
+ if (tagName === 'p') {
12835
+ const className = (element.getAttribute('class') || '').toLowerCase();
12836
+ return /msotitle/.test(className) || /msosubtitle/.test(className);
12837
+ }
12838
+ return false;
12839
+ }
12840
+ /**
12841
+ * Converts Word VML `v:imagedata` elements to plain `<img>` elements.
12842
+ *
12843
+ * @param {HTMLElement} root Parsed Word fragment root.
12844
+ */
12845
+ normalizeWordImageDataElements(root) {
12846
+ const imageDataElements = Array.from(root.querySelectorAll('v\\:imagedata, imagedata'));
12847
+ imageDataElements.forEach((imageDataElement) => {
12848
+ const src = imageDataElement.getAttribute('src') ||
12849
+ imageDataElement.getAttribute('o:href') ||
12850
+ imageDataElement.getAttribute('href') ||
12851
+ '';
12852
+ const alt = imageDataElement.getAttribute('alt') ||
12853
+ imageDataElement.getAttribute('o:title') ||
12854
+ imageDataElement.getAttribute('title') ||
12855
+ '';
12856
+ const wrapperElement = imageDataElement.closest('v\\:shape, shape') || imageDataElement;
12857
+ if (!src) {
12858
+ wrapperElement.remove();
12859
+ return;
12860
+ }
12861
+ // Non-local list images have no RTF counterpart, so drop them now. Local
12862
+ // (file://) list images are kept as placeholders and removed later during
12863
+ // preview pairing so the image order stays aligned with the RTF files.
12864
+ if (this.isListImage(wrapperElement) && !src.startsWith('file://')) {
12865
+ wrapperElement.remove();
12866
+ return;
12867
+ }
12868
+ const imageElement = root.ownerDocument.createElement('img');
12869
+ imageElement.setAttribute('src', src);
12870
+ if (alt) {
12871
+ imageElement.setAttribute('alt', alt);
12872
+ }
12873
+ if (wrapperElement.parentNode) {
12874
+ const shapeId = wrapperElement.getAttribute('id') || '';
12875
+ if (shapeId) {
12876
+ this.removeFallbackImagesForShapeId(root, shapeId);
12877
+ }
12878
+ wrapperElement.parentNode.insertBefore(imageElement, wrapperElement);
12879
+ wrapperElement.parentNode.removeChild(wrapperElement);
12880
+ }
12881
+ });
12882
+ }
12883
+ /**
12884
+ * Removes non-VML fallback images that reference a specific Word VML shape id.
12885
+ *
12886
+ * Word clipboard HTML often includes both `v:imagedata` and an `<img v:shapes="...">`
12887
+ * fallback for the same visual image. Once VML is normalized, the fallback must
12888
+ * be removed to avoid duplicated image handling.
12889
+ *
12890
+ * @param {HTMLElement} root Parsed Word fragment root.
12891
+ * @param {string} shapeId VML shape id referenced by fallback images.
12892
+ */
12893
+ removeFallbackImagesForShapeId(root, shapeId) {
12894
+ const imageElements = Array.from(root.querySelectorAll('img'));
12895
+ imageElements.forEach((imageElement) => {
12896
+ const referencedShapeId = imageElement.getAttribute('v:shapes') || imageElement.getAttribute('shapes') || '';
12897
+ if (referencedShapeId === shapeId) {
12898
+ imageElement.remove();
12899
+ }
12900
+ });
12901
+ }
12902
+ /**
12903
+ * Removes list-marker images and sourceless `<img>` elements.
12904
+ *
12905
+ * @param {HTMLElement} root Parsed Word fragment root.
12906
+ */
12907
+ normalizeStandardImages(root) {
12908
+ const imageElements = Array.from(root.querySelectorAll('img'));
12909
+ imageElements.forEach((imageElement) => {
12910
+ const src = imageElement.getAttribute('src') || '';
12911
+ if (this.isListImage(imageElement)) {
12912
+ // Non-local list images have no RTF counterpart, so drop them now. Local
12913
+ // (file://) list images are kept as placeholders and removed later during
12914
+ // preview pairing so the image order stays aligned with the RTF files.
12915
+ if (!src.startsWith('file://')) {
12916
+ imageElement.remove();
12917
+ }
12918
+ return;
12919
+ }
12920
+ if (!src) {
12921
+ imageElement.remove();
12922
+ }
12923
+ });
12924
+ }
12925
+ /**
12926
+ * Inserts an empty `<span> </span>` between adjacent images to avoid
12927
+ * downstream image-block parsing treating a compact image run as a single image.
12928
+ *
12929
+ * @param {HTMLElement} root Parsed Word fragment root.
12930
+ */
12931
+ insertSpanBetweenAdjacentImages(root) {
12932
+ const imageElements = Array.from(root.querySelectorAll('img'));
12933
+ imageElements.forEach((imageElement) => {
12934
+ if (!imageElement.parentNode) {
12935
+ return;
12936
+ }
12937
+ const nextSibling = imageElement.nextSibling;
12938
+ if (nextSibling &&
12939
+ nextSibling.nodeType === Node.ELEMENT_NODE &&
12940
+ nextSibling.tagName.toLowerCase() === 'img') {
12941
+ const spacerElement = root.ownerDocument.createElement('span');
12942
+ spacerElement.innerHTML = ' ';
12943
+ imageElement.parentNode.insertBefore(spacerElement, nextSibling);
12944
+ }
12945
+ });
12946
+ }
12947
+ /**
12948
+ * Currently the RTE does not support list images, so they must be removed from the paste content.
12949
+ * Local (file://) list images are kept as placeholders here and removed later during preview pairing
12950
+ * so the local images stay aligned with the RTF images; non-local list images are removed immediately.
12951
+ * Returns true when the image is part of list content and should be ignored.
12952
+ *
12953
+ * Word list markup (`MsoListParagraph` / `mso-list`) is already normalized into
12954
+ * real `li/ul/ol` by {@link WordListRoleTransformer}, which runs before this
12955
+ * transformer, so a plain list-ancestor check is sufficient here.
12956
+ *
12957
+ * @param {Element} element Image element (or its wrapper).
12958
+ * @returns {boolean} Whether this image belongs to list content.
12959
+ */
12960
+ isListImage(element) {
12961
+ return Boolean(element.closest('li,ul,ol'));
12962
+ }
12963
+ }
12964
+
12965
+ /**
12966
+ * Attribute that carries inline styles after `StylePreservator` renamed `style`
12967
+ * to `data-style`. All style reads/writes in Phase 1 target this name so the
12968
+ * declarations survive the CSP-sensitive `DOMParser` boundary (mirrors the
12969
+ * handling in {@link WordListRoleTransformer}).
12970
+ */
12971
+ const PRESERVED_STYLE_ATTR$1 = 'data-style';
12972
+ /** Table structural tags Word decorates with `Mso*` class artifacts. */
12973
+ const TABLE_SECTION_SELECTOR = 'thead, tbody, tfoot, caption, tr';
12974
+ /**
12975
+ * Table containers whose direct text children are always layout whitespace.
12976
+ * Word exports newlines and indentation between structural tags; those text
12977
+ * nodes are not valid table content and must be dropped so they do not surface
12978
+ * as stray spaces in the pasted table.
12979
+ */
12980
+ const TABLE_CONTAINER_SELECTOR = 'thead, tbody, tfoot, tr';
12981
+ /** Cell tags that may carry Word presentational attributes and span markers. */
12982
+ const TABLE_CELL_SELECTOR = 'td, th';
12983
+ /**
12984
+ * Block-level tags that mark a cell as containing block content. When a cell
12985
+ * holds one of these, any whitespace-only text node sitting beside it is Word
12986
+ * indentation (layout whitespace) rather than meaningful inline text.
12987
+ */
12988
+ const CELL_BLOCK_CHILD_TAGS = new Set([
12989
+ 'P',
12990
+ 'DIV',
12991
+ 'UL',
12992
+ 'OL',
12993
+ 'LI',
12994
+ 'H1',
12995
+ 'H2',
12996
+ 'H3',
12997
+ 'H4',
12998
+ 'H5',
12999
+ 'H6',
13000
+ 'TABLE',
13001
+ 'BLOCKQUOTE',
13002
+ 'PRE',
13003
+ ]);
13004
+ /** Span attributes whose value must be a positive integer greater than one. */
13005
+ const SPAN_ATTRIBUTES = ['colspan', 'rowspan'];
13006
+ /** Strict span values Word should emit after normalization. */
13007
+ const SPAN_VALUE_PATTERN = /^\d+$/;
13008
+ /**
13009
+ * Matches the border box-model declarations (shorthand, per-side, and the
13010
+ * width/style/color long-hands) that Word writes with point/centimeter units
13011
+ * and system color keywords the RTE table model cannot parse. Word also emits
13012
+ * per-side `border-*: none` resets to avoid double borders in its own layout,
13013
+ * which would leave the pasted table with inconsistent cell borders. All of
13014
+ * these are removed so the editor applies its uniform default border.
13015
+ * `border-collapse` / `border-spacing` are intentionally excluded so table
13016
+ * collapsing is preserved.
13017
+ */
13018
+ const BORDER_BOX_STYLE_PATTERN = /^border(-(top|right|bottom|left))?(-(width|style|color))?$/;
13019
+ /**
13020
+ * Matches padding declarations (shorthand and per-side) that Word writes with
13021
+ * point/centimeter units the RTE cannot parse. Removed so the editor applies
13022
+ * its default cell padding.
13023
+ */
13024
+ const PADDING_STYLE_PATTERN = /^padding(-(top|right|bottom|left))?$/;
13025
+ /**
13026
+ * Matches the standalone `width` declaration (not `min-width` / `max-width`).
13027
+ * Word writes cell widths in points, so the point-based declaration is removed
13028
+ * and replaced with the clean pixel value carried by the `width` attribute.
13029
+ */
13030
+ const WIDTH_STYLE_PATTERN = /^width$/;
13031
+ /** Numeric zero (with optional decimal and optional unit suffix). */
13032
+ const ZERO_LENGTH_PATTERN = /^0+(\.0+)?([a-z%]+)?$/i;
13033
+ /**
13034
+ * Maps Word cell presentational attributes onto the CSS declarations the RTE
13035
+ * table cell annotation understands. These attributes are not on the paste
13036
+ * allowlist, so migrating them into `data-style` is the only way to preserve
13037
+ * the author's intent (shading, alignment) through sanitization. Only
13038
+ * properties whose prefix is retained by the sanitizer are migrated, so
13039
+ * fixed-width/height artifacts are intentionally dropped.
13040
+ */
13041
+ const CELL_ATTRIBUTE_STYLE_MAP = [
13042
+ // eslint-disable-next-line spellcheck/spell-checker
13043
+ { attribute: 'valign', property: 'vertical-align' },
13044
+ { attribute: 'align', property: 'text-align' },
13045
+ // eslint-disable-next-line spellcheck/spell-checker
13046
+ { attribute: 'bgcolor', property: 'background-color' },
13047
+ ];
13048
+ /**
13049
+ * Normalizes Microsoft Word table markup into clean, RTE-friendly tables.
13050
+ *
13051
+ * Word emits real `<table>/<tr>/<td>` elements, so the paste allowlist already
13052
+ * keeps the structure. What it cannot fix is the Word-specific decoration that
13053
+ * rides along:
13054
+ * - `Mso*` class names (e.g. `MsoTableGrid`) survive because `class` is globally
13055
+ * allowed; they are Word artifacts and must not leak into the output.
13056
+ * - Cell shading and alignment live in presentational attributes (`bgcolor`,
13057
+ * `align`, `valign`) that the allowlist strips, losing the formatting; they
13058
+ * are migrated into `data-style` so the RTE cell annotation can read them.
13059
+ * - `colspan`/`rowspan` may carry redundant `1` values or non-numeric junk that
13060
+ * is normalized so span tables map cleanly onto the RTE table model.
13061
+ * - Table and cell borders/padding are written with point/centimeter units,
13062
+ * system color keywords, and per-side `border-*: none` resets that the RTE
13063
+ * cannot parse and that render inconsistent borders; they are stripped so the
13064
+ * editor applies its uniform default border and padding.
13065
+ * - Cell widths arrive both as a point-based `width` style (which the RTE cannot
13066
+ * parse) and a pixel `width` attribute; the point style is dropped and the
13067
+ * attribute is migrated into a clean pixel `width` declaration.
13068
+ */
13069
+ class WordTableTransformer {
13070
+ /** @inheritDoc */
13071
+ apply(root) {
13072
+ Array.from(root.querySelectorAll('table')).forEach((table) => this.normalizeTable(table));
13073
+ }
13074
+ /** @inheritDoc */
13075
+ getAllowedTags() {
13076
+ return ['TABLE', 'THEAD', 'TBODY', 'TR', 'TH', 'TD', 'CAPTION'];
13077
+ }
13078
+ /** @inheritDoc */
13079
+ getAllowedAttributes() {
13080
+ return new Map([
13081
+ ['TD', ['colspan', 'rowspan']],
13082
+ ['TH', ['colspan', 'rowspan']],
13083
+ ]);
13084
+ }
13085
+ /** @inheritDoc */
13086
+ getAllowedStyles() {
13087
+ return ['border', 'width'];
13088
+ }
13089
+ /**
13090
+ * Strips Word class artifacts from a table and its structural descendants,
13091
+ * then normalizes every cell's span attributes and presentational styling.
13092
+ *
13093
+ * @param {HTMLTableElement} table Word table element to normalize in place.
13094
+ */
13095
+ normalizeTable(table) {
13096
+ this.removeStructuralWhitespace(table);
13097
+ this.stripClass(table);
13098
+ this.removeBorderAndPaddingStyles(table);
13099
+ Array.from(table.querySelectorAll(TABLE_SECTION_SELECTOR)).forEach((section) => this.stripClass(section));
13100
+ this.removeHiddenMisalignedCells(table);
13101
+ this.mergeFooterIntoBody(table);
13102
+ this.promoteHeadCells(table);
13103
+ Array.from(table.querySelectorAll(TABLE_CELL_SELECTOR)).forEach((cell) => {
13104
+ this.removeCellLayoutWhitespace(cell);
13105
+ this.stripClass(cell);
13106
+ this.normalizeSpanAttributes(cell);
13107
+ this.migrateCellAttributes(cell);
13108
+ this.migrateCellWidth(cell);
13109
+ this.removeBorderAndPaddingStyles(cell);
13110
+ });
13111
+ }
13112
+ /**
13113
+ * Removes Word's hidden `!supportMisalignedRows` placeholder cell. Word
13114
+ * appends it as a zero-width trailing cell to keep legacy layout engines
13115
+ * aligned, but it is not real content and should not survive paste as an
13116
+ * extra visible column. Only the row's last cell is considered so an
13117
+ * intentional interior zero-width cell is never dropped, and only rows that
13118
+ * belong to this table (not a nested one) are touched.
13119
+ *
13120
+ * @param {HTMLTableElement} table Word table element.
13121
+ */
13122
+ removeHiddenMisalignedCells(table) {
13123
+ Array.from(table.querySelectorAll('tr'))
13124
+ .filter((row) => this.isRowOfTable(table, row))
13125
+ .forEach((row) => {
13126
+ const lastCell = row.lastElementChild;
13127
+ if (lastCell &&
13128
+ (lastCell.tagName === 'TD' || lastCell.tagName === 'TH') &&
13129
+ this.isHiddenMisalignedCell(lastCell)) {
13130
+ row.removeChild(lastCell);
13131
+ }
13132
+ });
13133
+ }
13134
+ /**
13135
+ * Reports whether a row belongs directly to the given table rather than to a
13136
+ * nested table, so the recursive `tr` query never reaches into a child table.
13137
+ *
13138
+ * @param {HTMLTableElement} table Table being normalized.
13139
+ * @param {HTMLTableRowElement} row Row to test.
13140
+ * @returns {boolean} `true` when the row's nearest ancestor table is `table`.
13141
+ */
13142
+ isRowOfTable(table, row) {
13143
+ let ancestor = row.parentElement;
13144
+ while (ancestor && ancestor.tagName !== 'BODY') {
13145
+ if (ancestor.tagName === 'TABLE') {
13146
+ return ancestor === table;
13147
+ }
13148
+ ancestor = ancestor.parentElement;
13149
+ }
13150
+ return false;
13151
+ }
13152
+ /**
13153
+ * Detects Word's hidden misaligned-row placeholder cell.
13154
+ *
13155
+ * @param {HTMLTableCellElement} cell Cell to inspect.
13156
+ * @returns {boolean} `true` when the cell is a hidden placeholder.
13157
+ */
13158
+ isHiddenMisalignedCell(cell) {
13159
+ if (this.hasExplicitSpan(cell)) {
13160
+ return false;
13161
+ }
13162
+ if (!this.hasZeroWidthMarker(cell)) {
13163
+ return false;
13164
+ }
13165
+ return !this.hasMeaningfulCellContent(cell);
13166
+ }
13167
+ /**
13168
+ * Reports whether a cell explicitly spans rows/columns.
13169
+ *
13170
+ * @param {HTMLTableCellElement} cell Cell to inspect.
13171
+ * @returns {boolean} `true` when colspan/rowspan is present.
13172
+ */
13173
+ hasExplicitSpan(cell) {
13174
+ return SPAN_ATTRIBUTES.some((attribute) => cell.hasAttribute(attribute));
13175
+ }
13176
+ /**
13177
+ * Reports whether a cell is explicitly marked with zero width via attribute
13178
+ * or preserved inline style.
13179
+ *
13180
+ * @param {HTMLTableCellElement} cell Cell to inspect.
13181
+ * @returns {boolean} `true` when width is explicitly zero.
13182
+ */
13183
+ hasZeroWidthMarker(cell) {
13184
+ const widthAttribute = cell.getAttribute('width');
13185
+ if (widthAttribute !== null && ZERO_LENGTH_PATTERN.test(widthAttribute.trim())) {
13186
+ return true;
13187
+ }
13188
+ const style = cell.getAttribute(PRESERVED_STYLE_ATTR$1);
13189
+ if (style === null) {
13190
+ return false;
13191
+ }
13192
+ const widthDeclarationValue = this.readStyleDeclaration(style, 'width');
13193
+ return widthDeclarationValue !== null && ZERO_LENGTH_PATTERN.test(widthDeclarationValue);
13194
+ }
13195
+ /**
13196
+ * Reports whether a cell has meaningful text content. `trim()` already treats
13197
+ * the non-breaking space Word emits as blank, so a zero-width cell holding
13198
+ * only markup (including an image) is intentionally treated as empty and
13199
+ * removed.
13200
+ *
13201
+ * @param {HTMLTableCellElement} cell Cell to inspect.
13202
+ * @returns {boolean} `true` when the cell has meaningful text.
13203
+ */
13204
+ hasMeaningfulCellContent(cell) {
13205
+ return (cell.textContent || '').trim() !== '';
13206
+ }
13207
+ /**
13208
+ * Reads one declaration value from a style string.
13209
+ *
13210
+ * @param {string} style Preserved style text.
13211
+ * @param {string} property CSS property name to read.
13212
+ * @returns {string | null} Declaration value when present.
13213
+ */
13214
+ readStyleDeclaration(style, property) {
13215
+ const declarations = style
13216
+ .split(';')
13217
+ .map((declaration) => declaration.trim())
13218
+ .filter((declaration) => declaration !== '');
13219
+ for (const declaration of declarations) {
13220
+ const separator = declaration.indexOf(':');
13221
+ if (separator === -1) {
13222
+ continue;
13223
+ }
13224
+ const name = declaration.slice(0, separator).trim().toLowerCase();
13225
+ if (name !== property.toLowerCase()) {
13226
+ continue;
13227
+ }
13228
+ const value = declaration.slice(separator + 1).trim();
13229
+ return value === '' ? null : value;
13230
+ }
13231
+ return null;
13232
+ }
13233
+ /**
13234
+ * Collapses every `<tfoot>` into the table body because the RTE table model
13235
+ * has no footer section. Left in place, an unsupported `<tfoot>` is unwrapped
13236
+ * by the paste sanitizer into a bare `<tr>` under `<table>`, so its rows lose
13237
+ * their section placement. When the table already has a `<tbody>`, the
13238
+ * footer's rows are appended to the last body so they stay in document order;
13239
+ * otherwise the `<tfoot>` itself is renamed to `<tbody>` so its rows survive
13240
+ * as body content.
13241
+ *
13242
+ * @param {HTMLTableElement} table Word table element.
13243
+ */
13244
+ mergeFooterIntoBody(table) {
13245
+ const footers = Array.from(table.children).filter((child) => child.tagName === 'TFOOT');
13246
+ footers.forEach((footer) => {
13247
+ const bodies = Array.from(table.children).filter((child) => child.tagName === 'TBODY');
13248
+ const targetBody = bodies[bodies.length - 1];
13249
+ if (targetBody) {
13250
+ while (footer.firstChild) {
13251
+ targetBody.appendChild(footer.firstChild);
13252
+ }
13253
+ if (footer.parentNode) {
13254
+ footer.parentNode.removeChild(footer);
13255
+ }
13256
+ }
13257
+ else {
13258
+ this.replaceElementTag(footer, 'tbody');
13259
+ }
13260
+ });
13261
+ }
13262
+ /**
13263
+ * Promotes `<td>` cells that Word places directly inside a `<thead>` row to
13264
+ * `<th>`. The RTE identifies header cells solely by the `TH` tag, so without
13265
+ * this the head row would be parsed as ordinary body cells and lose its
13266
+ * header annotations and rendering. Only direct `thead > tr > td` cells are
13267
+ * converted so cells of a nested table are never touched.
13268
+ *
13269
+ * @param {HTMLTableElement} table Word table element.
13270
+ */
13271
+ promoteHeadCells(table) {
13272
+ Array.from(table.querySelectorAll('thead')).forEach((head) => {
13273
+ Array.from(head.children).forEach((row) => {
13274
+ if (row.tagName !== 'TR') {
13275
+ return;
13276
+ }
13277
+ Array.from(row.children).forEach((cell) => {
13278
+ if (cell.tagName === 'TD') {
13279
+ this.renameCell(cell, 'th');
13280
+ }
13281
+ });
13282
+ });
13283
+ });
13284
+ }
13285
+ /**
13286
+ * Replaces a table cell element with an equivalent cell of a different tag,
13287
+ * preserving its attributes and child nodes.
13288
+ *
13289
+ * @param {HTMLTableCellElement} cell Cell to replace.
13290
+ * @param {string} tagName Target cell tag name (`th` / `td`).
13291
+ */
13292
+ renameCell(cell, tagName) {
13293
+ this.replaceElementTag(cell, tagName);
13294
+ }
13295
+ /**
13296
+ * Replaces an element with an equivalent element of a different tag,
13297
+ * preserving its attributes and child nodes and its position in the tree.
13298
+ *
13299
+ * @param {Element} element Element to replace.
13300
+ * @param {string} tagName Target tag name.
13301
+ * @returns {HTMLElement} The replacement element.
13302
+ */
13303
+ replaceElementTag(element, tagName) {
13304
+ const replacement = element.ownerDocument.createElement(tagName);
13305
+ Array.from(element.attributes).forEach((attr) => {
13306
+ replacement.setAttribute(attr.name, attr.value);
13307
+ });
13308
+ while (element.firstChild) {
13309
+ replacement.appendChild(element.firstChild);
13310
+ }
13311
+ if (element.parentNode) {
13312
+ element.parentNode.replaceChild(replacement, element);
13313
+ }
13314
+ return replacement;
13315
+ }
13316
+ /**
13317
+ * Removes the `class` attribute so Word style class names cannot leak into
13318
+ * the sanitized output (the global allowlist keeps `class` on every tag).
13319
+ *
13320
+ * @param {HTMLElement} element Table structural element.
13321
+ */
13322
+ stripClass(element) {
13323
+ if (element.hasAttribute('class')) {
13324
+ element.removeAttribute('class');
13325
+ }
13326
+ }
13327
+ /**
13328
+ * Drops whitespace-only text nodes that sit directly inside the table and its
13329
+ * row containers. Word exports newlines/indentation between structural tags,
13330
+ * which are invalid as table content and would otherwise render as stray
13331
+ * spaces once the table is pasted.
13332
+ *
13333
+ * @param {HTMLTableElement} table Word table element.
13334
+ */
13335
+ removeStructuralWhitespace(table) {
13336
+ const containers = [
13337
+ table,
13338
+ ...Array.from(table.querySelectorAll(TABLE_CONTAINER_SELECTOR)),
13339
+ ];
13340
+ containers.forEach((container) => {
13341
+ Array.from(container.childNodes).forEach((node) => {
13342
+ if (node.nodeType === Node.TEXT_NODE && (node.textContent || '').trim() === '') {
13343
+ container.removeChild(node);
13344
+ }
13345
+ });
13346
+ });
13347
+ }
13348
+ /**
13349
+ * Drops whitespace-only text nodes that sit directly inside a cell whose
13350
+ * content is block-level (e.g. Word wraps every cell's text in `<p>`). Word
13351
+ * indents its markup, so these text nodes are pure layout whitespace; left in
13352
+ * place each one is wrapped into its own paragraph by the RTE, producing the
13353
+ * stray empty lines seen above and below the real cell content. Cells that
13354
+ * only hold inline content are skipped so meaningful spaces between inline
13355
+ * runs are never merged.
13356
+ *
13357
+ * @param {HTMLTableCellElement} cell Table cell element.
13358
+ */
13359
+ removeCellLayoutWhitespace(cell) {
13360
+ const hasBlockChild = Array.from(cell.children).some((child) => CELL_BLOCK_CHILD_TAGS.has(child.tagName));
13361
+ if (!hasBlockChild) {
13362
+ return;
13363
+ }
13364
+ Array.from(cell.childNodes).forEach((node) => {
13365
+ if (node.nodeType === Node.TEXT_NODE && (node.textContent || '').trim() === '') {
13366
+ cell.removeChild(node);
13367
+ }
13368
+ });
13369
+ }
13370
+ /**
13371
+ * Normalizes `colspan` / `rowspan` values: a redundant span of `1` or any
13372
+ * non-numeric value is removed, and valid spans are rewritten as a clean
13373
+ * integer so the RTE table model reads them consistently.
13374
+ *
13375
+ * @param {HTMLTableCellElement} cell Table cell element.
13376
+ */
13377
+ normalizeSpanAttributes(cell) {
13378
+ SPAN_ATTRIBUTES.forEach((attribute) => {
13379
+ const raw = cell.getAttribute(attribute);
13380
+ if (raw === null) {
13381
+ return;
13382
+ }
13383
+ const value = Number(raw);
13384
+ if (!SPAN_VALUE_PATTERN.test(raw) || value <= 1) {
13385
+ cell.removeAttribute(attribute);
13386
+ }
13387
+ else {
13388
+ cell.setAttribute(attribute, String(value));
13389
+ }
13390
+ });
13391
+ }
13392
+ /**
13393
+ * Migrates Word cell presentational attributes into `data-style` so the RTE
13394
+ * cell annotation can read the shading and alignment, then removes the
13395
+ * original attributes. An existing declaration for the same property always
13396
+ * wins and is never overwritten.
13397
+ *
13398
+ * @param {HTMLTableCellElement} cell Table cell element.
13399
+ */
13400
+ migrateCellAttributes(cell) {
13401
+ CELL_ATTRIBUTE_STYLE_MAP.forEach(({ attribute, property }) => {
13402
+ const value = cell.getAttribute(attribute);
13403
+ if (value && value.trim() !== '') {
13404
+ this.appendStyleDeclaration(cell, property, value.trim().toLowerCase());
13405
+ }
13406
+ cell.removeAttribute(attribute);
13407
+ });
13408
+ }
13409
+ /**
13410
+ * Converts a cell's `width` attribute into a `width` style declaration. Word
13411
+ * emits the width both as a point-based inline style (which the RTE cannot
13412
+ * parse) and as a pixel `width` attribute; the point style is dropped and the
13413
+ * attribute value becomes a clean pixel `width` declaration (a bare number is
13414
+ * treated as pixels, any explicit unit such as `%` is kept as-is).
13415
+ *
13416
+ * @param {HTMLTableCellElement} cell Table cell element.
13417
+ */
13418
+ migrateCellWidth(cell) {
13419
+ const attributeWidth = cell.getAttribute('width');
13420
+ cell.removeAttribute('width');
13421
+ // Drop Word's point-based width so it cannot survive as an unparseable value.
13422
+ this.removeMatchingStyleDeclarations(cell, (property) => WIDTH_STYLE_PATTERN.test(property));
13423
+ const cssWidth = this.toCssWidth(attributeWidth);
13424
+ if (cssWidth !== null) {
13425
+ this.appendStyleDeclaration(cell, 'width', cssWidth);
13426
+ }
13427
+ }
13428
+ /**
13429
+ * Normalizes a cell `width` attribute value into a CSS width value. A bare
13430
+ * number is treated as pixels; any value carrying an explicit unit (e.g. `%`)
13431
+ * is kept as-is. An empty or missing value yields `null`.
13432
+ *
13433
+ * @param {string | null} value Raw `width` attribute value.
13434
+ * @returns {string | null} CSS width value, or `null` when there is nothing to migrate.
13435
+ */
13436
+ toCssWidth(value) {
13437
+ if (value === null || value.trim() === '') {
13438
+ return null;
13439
+ }
13440
+ const trimmed = value.trim();
13441
+ return /^\d+(\.\d+)?$/.test(trimmed) ? `${trimmed}px` : trimmed;
13442
+ }
13443
+ /**
13444
+ * Appends a `property: value` declaration to the preserved style attribute
13445
+ * unless the property is already declared.
13446
+ *
13447
+ * @param {HTMLElement} element Element receiving the declaration.
13448
+ * @param {string} property CSS property name.
13449
+ * @param {string} value CSS value.
13450
+ */
13451
+ appendStyleDeclaration(element, property, value) {
13452
+ const existing = element.getAttribute(PRESERVED_STYLE_ATTR$1) || '';
13453
+ if (this.styleHasProperty(existing, property)) {
13454
+ return;
13455
+ }
13456
+ const prefix = existing.trim() === '' ? '' : `${existing.replace(/;\s*$/, '')}; `;
13457
+ element.setAttribute(PRESERVED_STYLE_ATTR$1, `${prefix}${property}: ${value}`);
13458
+ }
13459
+ /**
13460
+ * Removes every border box-model and padding declaration from the preserved
13461
+ * style so Word's point/centimeter units, system color keywords, and per-side
13462
+ * `border-*: none` resets cannot reach the RTE. Once these are gone the table
13463
+ * and cell annotations fall back to the editor's default border
13464
+ * (`solid 1px #ddd`) and padding (`12px`), giving every pasted cell a uniform
13465
+ * border. `border-collapse` / `border-spacing` are preserved so table
13466
+ * collapsing is unaffected.
13467
+ *
13468
+ * @param {HTMLElement} element Table or cell element to normalize.
13469
+ */
13470
+ removeBorderAndPaddingStyles(element) {
13471
+ this.removeMatchingStyleDeclarations(element, (property) => BORDER_BOX_STYLE_PATTERN.test(property) || PADDING_STYLE_PATTERN.test(property));
13472
+ }
13473
+ /**
13474
+ * Removes every preserved-style declaration whose property name matches the
13475
+ * given predicate, rewriting (or dropping) the `data-style` attribute.
13476
+ *
13477
+ * @param {HTMLElement} element Element whose preserved style is filtered.
13478
+ * @param {(property: string) => boolean} shouldRemove Predicate that returns
13479
+ * `true` for property names to drop (receives the lower-cased name).
13480
+ */
13481
+ removeMatchingStyleDeclarations(element, shouldRemove) {
13482
+ const raw = element.getAttribute(PRESERVED_STYLE_ATTR$1);
13483
+ if (raw === null || raw.trim() === '') {
13484
+ return;
13485
+ }
13486
+ const kept = raw
13487
+ .split(';')
13488
+ .map((declaration) => declaration.trim())
13489
+ .filter((declaration) => declaration !== '')
13490
+ .filter((declaration) => {
13491
+ const separator = declaration.indexOf(':');
13492
+ if (separator === -1) {
13493
+ return true;
13494
+ }
13495
+ const property = declaration.slice(0, separator).trim().toLowerCase();
13496
+ return !shouldRemove(property);
13497
+ });
13498
+ if (kept.length > 0) {
13499
+ element.setAttribute(PRESERVED_STYLE_ATTR$1, kept.join('; '));
13500
+ }
13501
+ else {
13502
+ element.removeAttribute(PRESERVED_STYLE_ATTR$1);
13503
+ }
13504
+ }
13505
+ /**
13506
+ * Reports whether a preserved style string already declares a property.
13507
+ *
13508
+ * @param {string} style Preserved style attribute value.
13509
+ * @param {string} property CSS property name.
13510
+ * @returns {boolean} `true` when the property is already present.
13511
+ */
13512
+ styleHasProperty(style, property) {
13513
+ return new RegExp(`(^|;)\\s*${property}\\s*:`, 'i').test(style);
13514
+ }
13515
+ }
13516
+
13517
+ /**
13518
+ * Attribute that the RTE code-block parser uses to recognize code content.
13519
+ */
13520
+ const CODE_LANGUAGE_ATTR = 'data-language';
13521
+ /**
13522
+ * Default language applied when pasted code has no language metadata.
13523
+ */
13524
+ const DEFAULT_CODE_LANGUAGE = 'plainText';
13525
+ /**
13526
+ * Matches language hints encoded as CSS classes (for example `language-js`).
13527
+ */
13528
+ const LANGUAGE_CLASS_PATTERN = /(?:^|\s)(?:language|lang)-([a-z0-9+_.-]+)(?:\s|$)/i;
13529
+ /**
13530
+ * Removes Word-only class artifacts from code elements while preserving other
13531
+ * classes. Kept as defense-in-depth: even though the shared sanitizer allowlist
13532
+ * generally strips `Mso*` classes, this transformer normalizes the `<pre>`
13533
+ * class list before language resolution so a stray `MsoPlainText` can never
13534
+ * leak into `LANGUAGE_CLASS_PATTERN` matching.
13535
+ */
13536
+ const WORD_CLASS_NAME_PATTERN = /^mso[a-z0-9_-]*$/i;
13537
+ /**
13538
+ * Normalizes pasted `<pre>` nodes so they can be parsed as RTE code blocks.
13539
+ *
13540
+ * The RTE recognizes a code block only when `data-language` is present on
13541
+ * `<pre>`. Word-exported snippets commonly use plain `<pre>` with no
13542
+ * language metadata, so this transformer adds a default language and copies any
13543
+ * detectable language hint from nested code markup when available.
13544
+ */
13545
+ class WordCodeBlockTransformer {
13546
+ /**
13547
+ * Determines whether a node is a code block whose whitespace must be preserved.
13548
+ *
13549
+ * @param {Node} node Node to inspect.
13550
+ * @returns {boolean} `true` when the node is a `<pre>` element.
13551
+ */
13552
+ static isCodeBlock(node) {
13553
+ return node.nodeType === Node.ELEMENT_NODE && node.tagName.toUpperCase() === 'PRE';
13554
+ }
13555
+ /** @inheritDoc */
13556
+ apply(root) {
13557
+ Array.from(root.querySelectorAll('pre')).forEach((preElement) => {
13558
+ this.stripWordClassArtifacts(preElement);
13559
+ if (!preElement.hasAttribute(CODE_LANGUAGE_ATTR)) {
13560
+ preElement.setAttribute(CODE_LANGUAGE_ATTR, this.resolveLanguage(preElement));
13561
+ }
13562
+ });
13563
+ }
13564
+ /** @inheritDoc */
13565
+ getAllowedTags() {
13566
+ return ['PRE'];
13567
+ }
13568
+ /** @inheritDoc */
13569
+ getAllowedAttributes() {
13570
+ return new Map([['PRE', [CODE_LANGUAGE_ATTR]]]);
13571
+ }
13572
+ /** @inheritDoc */
13573
+ getAllowedStyles() {
13574
+ return [];
13575
+ }
13576
+ /**
13577
+ * Resolves code language metadata from `<pre>` class hints, falling back to
13578
+ * {@link DEFAULT_CODE_LANGUAGE}.
13579
+ *
13580
+ * `apply()` only invokes this method when the `<pre>` has no
13581
+ * `data-language` attribute, so class-based inference is the only source
13582
+ * this method needs to consult.
13583
+ *
13584
+ * @param {HTMLElement} preElement Source `<pre>` element.
13585
+ * @returns {string} Resolved language id or `plainText` fallback.
13586
+ */
13587
+ resolveLanguage(preElement) {
13588
+ const classLanguage = this.resolveLanguageFromClassName(preElement).trim();
13589
+ return classLanguage !== '' ? classLanguage : DEFAULT_CODE_LANGUAGE;
13590
+ }
13591
+ /**
13592
+ * Extracts a language id from class names like `language-js` or `lang-ts`.
13593
+ *
13594
+ * @param {HTMLElement} preElement Source `<pre>` element.
13595
+ * @returns {string} Extracted language id or empty string.
13596
+ */
13597
+ resolveLanguageFromClassName(preElement) {
13598
+ const className = preElement.getAttribute('class') || '';
13599
+ const match = LANGUAGE_CLASS_PATTERN.exec(className);
13600
+ return match ? match[1] : '';
13601
+ }
13602
+ /**
13603
+ * Removes Word-only `Mso*` class names and keeps any non-Word classes.
13604
+ *
13605
+ * @param {HTMLElement} preElement Source `<pre>` element.
13606
+ */
13607
+ stripWordClassArtifacts(preElement) {
13608
+ const className = preElement.getAttribute('class') || '';
13609
+ if (!className) {
13610
+ return;
13611
+ }
13612
+ const filteredClasses = className
13613
+ .split(/\s+/)
13614
+ .map((name) => name.trim())
13615
+ .filter((name) => name !== '' && !WORD_CLASS_NAME_PATTERN.test(name));
13616
+ if (filteredClasses.length === 0) {
13617
+ preElement.removeAttribute('class');
13618
+ return;
13619
+ }
13620
+ preElement.setAttribute('class', filteredClasses.join(' '));
13621
+ }
13622
+ }
13623
+
13624
+ /**
13625
+ * Default Word transformers. Sanitizer allowlist is aggregated from these
13626
+ * transformer contracts so adding a new transformer automatically extends the
13627
+ * allowlist surface.
13628
+ */
13629
+ const WORD_STRUCTURE_TRANSFORMERS = [
13630
+ new WordTableTransformer(),
13631
+ new WordListRoleTransformer(),
13632
+ new WordImageTransformer(),
13633
+ new WordCodeBlockTransformer(),
13634
+ new WordParagraphRoleTransformer(),
13635
+ ];
13636
+ /**
13637
+ * Aggregates the sanitizer allowlist from each transformer's declared contract
13638
+ * (tags, attributes, style prefixes), removing duplicates and normalizing case
13639
+ * so the strategy allowlist can never drift from the transformers that depend on
13640
+ * it.
13641
+ *
13642
+ * @param {WordStructureTransformer[]} transformers Registered structure transformers.
13643
+ * @returns {WordSanitizeConfig} Combined sanitizer configuration.
13644
+ */
13645
+ function buildWordSanitizeConfig(transformers) {
13646
+ const tags = new Set();
13647
+ const stylePrefixes = new Set();
13648
+ const attributesMap = new Map();
13649
+ transformers.forEach((transformer) => {
13650
+ transformer.getAllowedTags().forEach((tag) => {
13651
+ tags.add(tag.toUpperCase());
13652
+ });
13653
+ transformer.getAllowedStyles().forEach((prefix) => {
13654
+ stylePrefixes.add(prefix.toLowerCase());
13655
+ });
13656
+ transformer.getAllowedAttributes().forEach((attrs, tagName) => {
13657
+ const normalizedTagName = tagName === WORD_SANITIZE_ALL_TAGS_KEY ? tagName : tagName.toUpperCase();
13658
+ if (!attributesMap.has(normalizedTagName)) {
13659
+ attributesMap.set(normalizedTagName, new Set());
13660
+ }
13661
+ const attrSet = attributesMap.get(normalizedTagName);
13662
+ attrs.forEach((attr) => {
13663
+ attrSet.add(attr.toLowerCase());
13664
+ });
13665
+ });
13666
+ });
13667
+ const allowedAttributes = {};
13668
+ attributesMap.forEach((attrs, tagName) => {
13669
+ allowedAttributes[tagName] = Array.from(attrs);
13670
+ });
13671
+ return {
13672
+ allowedTags: Array.from(tags),
13673
+ allowedAttributes,
13674
+ allowedStylePrefixes: Array.from(stylePrefixes),
13675
+ };
13676
+ }
13677
+ /**
13678
+ * Default sanitizer allowlist aggregated from
13679
+ * {@link WORD_STRUCTURE_TRANSFORMERS}. Exported so tests and callers can still
13680
+ * provide stable overrides.
13681
+ */
13682
+ const WORD_SANITIZE_CONFIG = buildWordSanitizeConfig(WORD_STRUCTURE_TRANSFORMERS);
13683
+ /**
13684
+ * Attribute name that carries inline styles after {@link StylePreservator} has
13685
+ * renamed `style` to `data-style`. All sanitization runs against this name so
13686
+ * the styles survive the CSP-sensitive `DOMParser` boundary.
13687
+ */
13688
+ const PRESERVED_STYLE_ATTR = 'data-style';
13689
+ /**
13690
+ * Block tag that can represent an intentional blank line pasted from Word
13691
+ * (an "empty" paragraph whose only content is a non-breaking space). Headings
13692
+ * are excluded — an empty heading is treated as noise, not an intentional
13693
+ * blank line.
13694
+ */
13695
+ const BLANK_LINE_ELIGIBLE_TAGS = 'p';
13696
+ /**
13697
+ * Zero-width space used to keep an intentional blank line alive. Unlike a
13698
+ * non-breaking space, it is not stripped by `String.prototype.trim()`, so the
13699
+ * downstream empty-block removal keeps the paragraph while it still renders as
13700
+ * blank.
13701
+ */
13702
+ const ZERO_WIDTH_SPACE = '\u200B';
13703
+ /**
13704
+ * Style values the RTE cannot resolve, so any declaration whose value contains
13705
+ * one of them is dropped during sanitization. These ride on allowed properties
13706
+ * (`color`, `border`, `background`, …), so the prefix allowlist alone cannot
13707
+ * remove them. Add legacy Word keywords here to filter them everywhere.
13708
+ */
13709
+ // eslint-disable-next-line spellcheck/spell-checker
13710
+ const INVALID_STYLE_VALUES = ['windowtext'];
13711
+ /**
13712
+ * Pre processes raw Word/Office clipboard HTML into clean, RTE-friendly HTML.
13713
+ *
13714
+ * The pipeline mirrors the two-phase design of the source Word cleaner:
13715
+ * 1. Structure fixing — maps Word paragraph styles onto RTE text styles and
13716
+ * drops Word list marker artifacts.
13717
+ * 2. Dynamic allowlist sanitizing — recursively strips disallowed tags,
13718
+ * attributes and inline style declarations while keeping inner content.
13719
+ */
13720
+ class WordPasteProcessingStrategy extends AbstractPasteProcessingStrategy {
13721
+ /**
13722
+ * Downstream paste mode marker for Word-specific processing.
13723
+ *
13724
+ * @returns {RTEPasteMode} `word` so downstream handlers preserve Word annotations.
13725
+ */
13726
+ get type() {
13727
+ return RTEPasteMode.WORD;
13728
+ }
13729
+ /**
13730
+ * Detects whether raw clipboard HTML originated from Microsoft Word / Office.
13731
+ *
13732
+ * Used to auto-route a normal "rich text" paste through the Word cleaning
13733
+ * pipeline when the source is actually Word, so users get correct formatting
13734
+ * without having to explicitly pick the Word paste option.
13735
+ *
13736
+ * @param {string} html Raw `text/html` clipboard payload.
13737
+ * @returns {boolean} `true` when the HTML carries Word/Office signatures.
13738
+ */
13739
+ canHandle(html) {
13740
+ if (!html) {
13741
+ return false;
13742
+ }
13743
+ return WordPasteProcessingStrategy.WORD_SIGNATURE_PATTERNS.some((pattern) => pattern.test(html));
13744
+ }
13745
+ /**
13746
+ * Returns the priority of this strategy relative to others; higher values run first.
13747
+ *
13748
+ * @returns {number} The priority value.
13749
+ */
13750
+ get priority() {
13751
+ return PasteProcessingStrategyPriority.WORD;
13752
+ }
13753
+ /**
13754
+ * Whether this strategy extracts pasted images and produces local previews.
13755
+ *
13756
+ * @returns {boolean} Always `true`; Word paste swaps `file://` images to previews.
13757
+ */
13758
+ get supportsImageProcessing() {
13759
+ return true;
13760
+ }
13761
+ /**
13762
+ * Cleans raw Word clipboard HTML so it can flow through the normal RTE paste
13763
+ * pipeline.
13764
+ *
13765
+ * @param {string} html Raw `text/html` clipboard payload from Word.
13766
+ * @param {WordSanitizeConfig} [config] Optional allowlist override.
13767
+ * @returns {string} Sanitized HTML string.
13768
+ */
13769
+ process(html, config = WORD_SANITIZE_CONFIG) {
13770
+ if (!html) {
13771
+ return '';
13772
+ }
13773
+ const withoutComments = this.stripWordComments(html);
13774
+ // Preserve inline styles across the DOMParser boundary to avoid
13775
+ // style-src-attr CSP violations (styles become data-style attributes).
13776
+ const preservedHtml = contentState.StylePreservator.preserve(withoutComments).getProcessedHtml();
13777
+ const parsedDoc = new DOMParser().parseFromString(preservedHtml, 'text/html');
13778
+ const container = parsedDoc.body;
13779
+ this.fixWordStructure(container);
13780
+ // Sanitize each top-level child instead of the <body> itself so the body
13781
+ // container is never unwrapped away.
13782
+ Array.from(container.childNodes).forEach((child) => {
13783
+ this.sanitizeNode(child, config);
13784
+ });
13785
+ // Collapse the source line wraps Word inserts inside text so a single
13786
+ // logical line does not paste as multiple lines.
13787
+ this.collapseInsignificantWhitespace(container);
13788
+ // Drop the whitespace Word inserts directly between block elements so it
13789
+ // does not paste as empty lines.
13790
+ this.removeInterBlockWhitespace(container);
13791
+ // Keep intentional blank lines (Word empty paragraphs) from being dropped by
13792
+ // the downstream empty-block removal.
13793
+ this.preserveWordEmptyLines(container);
13794
+ return this.restoreStyleAttributeName(container.innerHTML);
13795
+ }
13796
+ /**
13797
+ * Removes Office XML comments and down-level conditional markup that would
13798
+ * otherwise confuse `DOMParser`.
13799
+ *
13800
+ * @param {string} html Raw HTML string.
13801
+ * @returns {string} HTML without Word comment blocks.
13802
+ */
13803
+ stripWordComments(html) {
13804
+ return html.replace(/<!--[\s\S]*?-->/g, '').replace(/<!\[[\s\S]*?\]>/g, '');
13805
+ }
13806
+ /**
13807
+ * First phase: repairs Word-specific structure so it aligns with RTE text
13808
+ * styles before the allowlist pass runs.
13809
+ *
13810
+ * @param {HTMLElement} root Parsed body element.
13811
+ */
13812
+ fixWordStructure(root) {
13813
+ WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS.forEach((transformer) => {
13814
+ transformer.apply(root);
13815
+ });
13816
+ }
13817
+ /**
13818
+ * Removes the whitespace-only text nodes Word emits directly between block
13819
+ * elements (the `\n\n` at the top level of the fragment). After the allowlist
13820
+ * pass, disallowed containers are already unwrapped, so any remaining
13821
+ * top-level text node that is pure whitespace is an inter-block artifact.
13822
+ * Whitespace inside inline/text elements is left untouched.
13823
+ *
13824
+ * @param {HTMLElement} root Parsed body element.
13825
+ */
13826
+ removeInterBlockWhitespace(root) {
13827
+ Array.from(root.childNodes).forEach((node) => {
13828
+ if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() === '') {
13829
+ root.removeChild(node);
13830
+ }
13831
+ });
13832
+ }
13833
+ /**
13834
+ * Collapses insignificant ASCII whitespace inside text nodes the way a
13835
+ * browser would when rendering. Word wraps long runs of text across multiple
13836
+ * source lines, so a single logical line such as "Number list 1" arrives as
13837
+ * "Number\nlist 1"; without normalization the newline surfaces as a spurious
13838
+ * line break in the editor. Non-breaking spaces (`\u00A0`) are left untouched
13839
+ * so intentional Word spacing and blank lines survive.
13840
+ *
13841
+ * @param {Node} node Node whose text descendants are normalized in place.
13842
+ */
13843
+ collapseInsignificantWhitespace(node) {
13844
+ // Code blocks preserve their original whitespace, so skip the whole subtree.
13845
+ if (WordCodeBlockTransformer.isCodeBlock(node)) {
13846
+ return;
13847
+ }
13848
+ if (node.nodeType === Node.TEXT_NODE) {
13849
+ const original = node.textContent;
13850
+ const collapsed = original.replace(/[ \t\r\n\f]+/g, ' ');
13851
+ if (collapsed !== original) {
13852
+ node.textContent = collapsed;
13853
+ }
13854
+ return;
13855
+ }
13856
+ Array.from(node.childNodes).forEach((child) => {
13857
+ this.collapseInsignificantWhitespace(child);
13858
+ });
13859
+ }
13860
+ /**
13861
+ * Preserves intentional blank lines authored in Word (empty paragraphs whose
13862
+ * only content is a non-breaking space). The downstream paste pipeline drops
13863
+ * any block whose text content trims to empty, and `trim()` also removes a
13864
+ * non-breaking space; replacing the content with a zero-width space keeps the
13865
+ * blank line because it survives `trim()` while still rendering as empty.
13866
+ *
13867
+ * @param {HTMLElement} root Parsed body element.
13868
+ */
13869
+ preserveWordEmptyLines(root) {
13870
+ Array.from(root.querySelectorAll(BLANK_LINE_ELIGIBLE_TAGS)).forEach((block) => {
13871
+ // Word paragraphs that host an image also carry a trailing
13872
+ // `<o:p>&nbsp;</o:p>` whose non-breaking space would misidentify the
13873
+ // paragraph as an empty line and wipe the image out.
13874
+ if (block.querySelector('img')) {
13875
+ return;
13876
+ }
13877
+ const text = block.textContent;
13878
+ const hasRealText = text.replace(/[\s\u200B]+/g, '') !== '';
13879
+ // Only an "empty" block that carries a non-breaking space is treated as
13880
+ // an intentional Word blank line.
13881
+ if (!hasRealText && /\u00A0/.test(text)) {
13882
+ block.textContent = ZERO_WIDTH_SPACE;
13883
+ }
13884
+ });
13885
+ }
13886
+ /**
13887
+ * Second phase: recursively enforces the dynamic allowlist on a node tree.
13888
+ *
13889
+ * @param {Node} node Node to sanitize in place.
13890
+ * @param {WordSanitizeConfig} config Active allowlist configuration.
13891
+ */
13892
+ sanitizeNode(node, config) {
13893
+ if (node.nodeType === Node.TEXT_NODE) {
13894
+ return;
13895
+ }
13896
+ if (node.nodeType !== Node.ELEMENT_NODE) {
13897
+ this.removeSelf(node);
13898
+ return;
13899
+ }
13900
+ const element = node;
13901
+ const tagName = element.tagName.toUpperCase();
13902
+ // Sanitize children first (reverse order keeps indices stable while nodes
13903
+ // may be removed or unwrapped).
13904
+ const children = Array.from(element.childNodes);
13905
+ for (let i = children.length - 1; i >= 0; i--) {
13906
+ this.sanitizeNode(children[i], config);
13907
+ }
13908
+ // Tag-level filter: unwrap disallowed elements but keep their content.
13909
+ if (!config.allowedTags.includes(tagName)) {
13910
+ while (element.firstChild) {
13911
+ if (element.parentNode && typeof element.parentNode.insertBefore === 'function') {
13912
+ element.parentNode.insertBefore(element.firstChild, element);
13913
+ }
13914
+ }
13915
+ this.removeSelf(element);
13916
+ return;
13917
+ }
13918
+ this.sanitizeAttributes(element, tagName, config);
13919
+ }
13920
+ /**
13921
+ * Removes disallowed attributes and filters style declarations.
13922
+ *
13923
+ * @param {Element} element Element being sanitized.
13924
+ * @param {string} tagName Upper-case tag name.
13925
+ * @param {WordSanitizeConfig} config Active sanitize configuration.
13926
+ */
13927
+ sanitizeAttributes(element, tagName, config) {
13928
+ const commonAttrs = config.allowedAttributes[WORD_SANITIZE_ALL_TAGS_KEY] || [];
13929
+ const tagAttrs = config.allowedAttributes[tagName] || [];
13930
+ const allowedAttrs = new Set([...commonAttrs, ...tagAttrs]);
13931
+ Array.from(element.attributes).forEach((attr) => {
13932
+ const attrName = attr.name.toLowerCase();
13933
+ const isStyle = attrName === PRESERVED_STYLE_ATTR;
13934
+ const normalizedName = isStyle ? 'style' : attrName;
13935
+ if (!allowedAttrs.has(normalizedName)) {
13936
+ element.removeAttribute(attr.name);
13937
+ return;
13938
+ }
13939
+ if (isStyle) {
13940
+ this.sanitizeStyleAttribute(element, attr.name, config);
13941
+ }
13942
+ });
13943
+ }
13944
+ /**
13945
+ * Filters CSS declarations inside a preserved style attribute: keeps only
13946
+ * properties matching a prefix in {@link WordSanitizeConfig.allowedStylePrefixes};
13947
+ * all others (including `mso-*` Word artifacts) are stripped.
13948
+ *
13949
+ * @param {Element} element Element owning the style attribute.
13950
+ * @param {string} attrName Preserved style attribute name.
13951
+ * @param {WordSanitizeConfig} config Active sanitize configuration.
13952
+ */
13953
+ sanitizeStyleAttribute(element, attrName, config) {
13954
+ const rawStyle = element.getAttribute(attrName) || '';
13955
+ // Delegate CSS parsing to the browser engine via a temporary element so
13956
+ // that edge cases (values containing semicolons, multi-value shorthand,
13957
+ // etc.) are handled correctly without a hand-rolled parser.
13958
+ const tempEl = element.ownerDocument.createElement('span');
13959
+ tempEl.setAttribute('style', rawStyle);
13960
+ const parsedStyle = tempEl.style;
13961
+ const cleanDeclarations = [];
13962
+ for (let i = 0; i < parsedStyle.length; i++) {
13963
+ const key = parsedStyle[i];
13964
+ // Keep only properties whose name starts with an allowed prefix.
13965
+ const isAllowed = config.allowedStylePrefixes.some((prefix) => key === prefix || key.startsWith(`${prefix}-`));
13966
+ const value = parsedStyle.getPropertyValue(key);
13967
+ // Drop declarations carrying a value the RTE cannot resolve (e.g. Word's
13968
+ // legacy `windowText` system color), even on otherwise allowed properties.
13969
+ const lowerCaseValue = value.toLowerCase();
13970
+ const hasInvalidValue = INVALID_STYLE_VALUES.some((invalid) => lowerCaseValue.includes(invalid));
13971
+ if (isAllowed && !hasInvalidValue) {
13972
+ cleanDeclarations.push(`${key}: ${value}`);
13973
+ }
13974
+ }
13975
+ const cleanStyle = cleanDeclarations.join('; ');
13976
+ if (cleanStyle) {
13977
+ element.setAttribute(attrName, cleanStyle);
13978
+ }
13979
+ else {
13980
+ element.removeAttribute(attrName);
13981
+ }
13982
+ }
13983
+ /**
13984
+ * Converts preserved `data-style` attributes back to `style` in the final
13985
+ * HTML string so downstream paste handling receives standard markup.
13986
+ *
13987
+ * @param {string} html Serialized sanitized HTML.
13988
+ * @returns {string} HTML with `style` attributes restored.
13989
+ */
13990
+ restoreStyleAttributeName(html) {
13991
+ return html.replace(/\sdata-style=/g, ' style=');
13992
+ }
13993
+ /**
13994
+ * Removes the element from its parent node if it has one.
13995
+ *
13996
+ * @param {Node | Element} elementToBeRemoved The element to be removed from the DOM.
13997
+ */
13998
+ removeSelf(elementToBeRemoved) {
13999
+ if (elementToBeRemoved.parentNode &&
14000
+ typeof elementToBeRemoved.parentNode.removeChild === 'function') {
14001
+ elementToBeRemoved.parentNode.removeChild(elementToBeRemoved);
14002
+ }
14003
+ }
14004
+ }
14005
+ /**
14006
+ * Ordered list of structure transformers applied in Phase 1 before allowlist
14007
+ * sanitization. To add support for a new node type (table, image, list…),
14008
+ * create a class that implements {@link WordStructureTransformer} and append
14009
+ * it here — no other changes to the pipeline are needed.
14010
+ */
14011
+ WordPasteProcessingStrategy.STRUCTURE_TRANSFORMERS = [
14012
+ ...WORD_STRUCTURE_TRANSFORMERS,
14013
+ ];
14014
+ /**
14015
+ * Signatures that identify clipboard HTML produced by Microsoft Word / Office.
14016
+ * Any single match is enough to treat the payload as Word content because
14017
+ * these markers do not appear in ordinary web or plain rich-text clipboards.
14018
+ */
14019
+ WordPasteProcessingStrategy.WORD_SIGNATURE_PATTERNS = [
14020
+ // <meta name=Generator content="Microsoft Word ...">
14021
+ /content=["']?Microsoft\s+Word/i,
14022
+ // eslint-disable-next-line spellcheck/spell-checker
14023
+ // Office namespace declarations (urn:schemas-microsoft-com:office:word).
14024
+ /urn:schemas-microsoft-com:office/i,
14025
+ // Word paragraph/character style classes (MsoNormal, MsoTitle, MsoListParagraph…).
14026
+ /class=["']?Mso[A-Za-z]/i,
14027
+ // Word-only inline style properties.
14028
+ /mso-[a-z-]+\s*:/i,
14029
+ // Office XML paragraph marker elements (<o:p></o:p>).
14030
+ /<\/?o:p>/i,
14031
+ ];
14032
+
14033
+ /**
14034
+ * Centralized selector for paste processing strategies.
14035
+ *
14036
+ * Maintains a registry of available strategies and selects the highest-priority
14037
+ * strategy that can handle the given clipboard HTML. Provides an extension
14038
+ * point for adding support for new clipboard sources (e.g., Google Docs, Notion)
14039
+ * without modifying the paste extension core logic.
14040
+ */
14041
+ class PasteStrategySelector {
14042
+ constructor() {
14043
+ this.defaultStrategy = new DefaultPasteProcessingStrategy();
14044
+ this.strategies = [
14045
+ new WordPasteProcessingStrategy(),
14046
+ this.defaultStrategy, // Fallback
14047
+ ];
14048
+ }
14049
+ /**
14050
+ * Select the appropriate strategy for the given HTML content.
14051
+ * Returns the highest-priority strategy that can handle the content.
14052
+ *
14053
+ * @param {string} html Raw clipboard HTML.
14054
+ * @returns {AbstractPasteProcessingStrategy} The selected strategy (always returns a strategy; default is the fallback).
14055
+ */
14056
+ selectStrategy(html) {
14057
+ return this.selectHighestPriorityStrategy(this.strategies.filter((strategy) => strategy.canHandle(html)));
14058
+ }
14059
+ /**
14060
+ * Selects the highest-priority registered strategy for an explicitly chosen paste mode.
14061
+ *
14062
+ * Used when the user manually chooses a non-default mode from the paste chooser.
14063
+ *
14064
+ * @param {RTEPasteMode} type Explicit paste mode selected by the user.
14065
+ * @returns {AbstractPasteProcessingStrategy} The matching strategy or the default fallback.
14066
+ */
14067
+ selectStrategyByType(type) {
14068
+ return this.selectHighestPriorityStrategy(this.strategies.filter((strategy) => strategy.type === type));
14069
+ }
14070
+ /**
14071
+ * Register a new paste processing strategy.
14072
+ * Useful for future extensions (e.g., GoogleDocsPasteStrategy).
14073
+ *
14074
+ * @param {AbstractPasteProcessingStrategy} strategy The strategy to register.
14075
+ */
14076
+ registerStrategy(strategy) {
14077
+ this.strategies.push(strategy);
14078
+ }
14079
+ /**
14080
+ * Returns the highest-priority strategy from a candidate set or the default fallback.
14081
+ *
14082
+ * @param {AbstractPasteProcessingStrategy[]} strategies Candidate strategies.
14083
+ * @returns {AbstractPasteProcessingStrategy} Selected strategy.
14084
+ */
14085
+ selectHighestPriorityStrategy(strategies) {
14086
+ const selectedStrategy = strategies.sort((a, b) => b.priority - a.priority)[0];
14087
+ return selectedStrategy || this.defaultStrategy;
14088
+ }
14089
+ }
14090
+
14091
+ /**
14092
+ * Extracts pasted image files from clipboard payloads and swaps matching
14093
+ * `<img>` elements to local object-URL previews.
14094
+ *
14095
+ * The parser is stateless: callers own the returned {@link PasteImagePreview}
14096
+ * list and decide how to track pending uploads.
14097
+ */
14098
+ class PasteImageParser {
14099
+ /**
14100
+ * Parses local `file://` images from the HTML, swaps matching `<img>`
14101
+ * elements to object-URL previews, and returns the rewritten HTML alongside
14102
+ * the resolved pending previews.
14103
+ *
14104
+ * When no local images are resolved, the original HTML is returned unchanged
14105
+ * with an empty preview list.
14106
+ *
14107
+ * @param {string} html HTML content to parse.
14108
+ * @param {ClipboardFileContent | null} clipboardFileContent Clipboard payload for image extraction.
14109
+ * @returns {ParseLocalImagesResult} Rewritten HTML and resolved previews.
14110
+ */
14111
+ parseLocalImages(html, clipboardFileContent) {
14112
+ if (!html.includes('<img')) {
14113
+ return { html, previews: [] };
14114
+ }
14115
+ const safeHtml = html.replace(/\s+style=/g, ' data-style=');
14116
+ const parser = new DOMParser();
14117
+ const parsedDoc = parser.parseFromString(safeHtml, 'text/html');
14118
+ const localImageElements = Array.from(parsedDoc.querySelectorAll('img')).filter((img) => img.src.startsWith('file://'));
14119
+ if (localImageElements.length === 0) {
14120
+ return { html, previews: [] };
14121
+ }
14122
+ const imageFiles = this.extractImageFiles(clipboardFileContent, localImageElements);
14123
+ if (imageFiles.length === 0) {
14124
+ return { html, previews: [] };
14125
+ }
14126
+ const previews = this.createImagePreviews(localImageElements, imageFiles);
14127
+ const rewrittenHtml = parsedDoc.body.innerHTML.replace(/ data-style=/g, ' style=');
14128
+ return { html: rewrittenHtml, previews };
14129
+ }
14130
+ /**
14131
+ * Swaps each `<img>` src to a local object-URL preview using the provided
14132
+ * image files (paired by order), returning one preview per resolved image.
14133
+ *
14134
+ * Images that live inside a list are dropped instead of being previewed: the
14135
+ * RTE does not support list images. They are removed here (after holding their
14136
+ * position while the RTF images are paired by order) so the remaining images
14137
+ * stay aligned with their files even when a list image is not the last one.
14138
+ *
14139
+ * @param {HTMLImageElement[]} images Placeholder `<img>` elements in document order.
14140
+ * @param {File[]} files Image files to pair with the elements, in the same order.
14141
+ * @returns {PasteImagePreview[]} Previews for the images that were resolved to a file.
14142
+ */
14143
+ createImagePreviews(images, files) {
14144
+ const previews = [];
14145
+ images.forEach((imageElement, index) => {
14146
+ // List images have no editor representation, so drop them here instead of
14147
+ // creating a preview. Removing them at this stage (rather than earlier)
14148
+ // keeps the remaining images aligned with their files.
14149
+ if (this.isListImage(imageElement)) {
14150
+ imageElement.remove();
14151
+ return;
14152
+ }
14153
+ const file = files[index];
14154
+ if (!file) {
14155
+ return;
14156
+ }
14157
+ const objectUrl = URL.createObjectURL(file);
14158
+ imageElement.setAttribute('src', objectUrl);
14159
+ const imageId = misc.generateUUID();
14160
+ imageElement.setAttribute(PasteImageParser.PREVIEW_IMG_KEY, imageId);
14161
+ previews.push({ id: imageId, file, objectUrl });
14162
+ });
14163
+ return previews;
14164
+ }
14165
+ /**
14166
+ * Extracts image files from clipboard data, preferring Word RTF-decoded
14167
+ * images and falling back to the clipboard file list when RTF yields none.
14168
+ *
14169
+ * @param {ClipboardFileContent | null} clipboardFileContent Clipboard payload from a paste event.
14170
+ * @param {HTMLElement[]} images `<img>` elements the files will be paired with.
14171
+ * @returns {File[]} Image files found on the clipboard.
14172
+ */
14173
+ extractImageFiles(clipboardFileContent, images) {
14174
+ let result = [];
14175
+ if (clipboardFileContent) {
14176
+ if (clipboardFileContent.rtf) {
14177
+ result = this.safeExtractWordImages(clipboardFileContent.rtf, images);
14178
+ }
14179
+ if (result.length === 0 && clipboardFileContent.files) {
14180
+ result = clipboardFileContent.files.filter((file) => file.type.startsWith('image/'));
14181
+ }
14182
+ }
14183
+ return result;
14184
+ }
14185
+ /**
14186
+ * Safely extracts image files from Word RTF clipboard data.
14187
+ *
14188
+ * @param {string} rtf Clipboard payload from a paste event.
14189
+ * @param {HTMLElement[]} images Array of `<img>` elements that may be updated with staged previews.
14190
+ * @returns {File[]} Image files found in the clipboard data.
14191
+ */
14192
+ safeExtractWordImages(rtf, images) {
14193
+ // Word defines a list's picture bullet once in the list table
14194
+ // (`{\*\listpicture ...}`) with no rendered counterpart. Drop that
14195
+ // definition so its blip is not counted as a content image; the per-item
14196
+ // `{\listtext ...}` bullet blips are kept because each still pairs with a
14197
+ // preserved bullet placeholder `<img>`.
14198
+ const contentRtf = this.stripListPictureDefinitions(rtf);
14199
+ const fileObjects = [];
14200
+ const imageRegex = /\\pngblip|\\jpegblip/g;
14201
+ const matches = [...contentRtf.matchAll(imageRegex)];
14202
+ matches.forEach((match, index) => {
14203
+ if (index >= images.length || match.index === undefined) {
14204
+ return;
14205
+ }
14206
+ const mimeType = match[0].includes('png') ? 'image/png' : 'image/jpeg';
14207
+ const startIndex = match.index + match[0].length;
14208
+ const bytes = this.extractImageBytes(contentRtf, startIndex);
14209
+ if (bytes.length === 0) {
14210
+ return;
14211
+ }
14212
+ const extension = mimeType.split('/')[1];
14213
+ const file = new File(
14214
+ // eslint-disable-next-line spellcheck/spell-checker
14215
+ [new Uint8Array(bytes)], `word_img_${Date.now()}_${index}.${extension}`, { type: mimeType });
14216
+ fileObjects.push(file);
14217
+ });
14218
+ return fileObjects;
14219
+ }
14220
+ /**
14221
+ * Removes Word list-table picture-bullet definitions from the RTF so they are
14222
+ * not counted as content images.
14223
+ *
14224
+ * Word declares a list's picture bullet once as a `{\*\listpicture ...}`
14225
+ * destination inside the list table. It renders nothing on its own, so its
14226
+ * blip has no matching content `<img>`; leaving it in shifts the ordinal
14227
+ * pairing and makes the first real image resolve to the bullet. The per-item
14228
+ * `{\listtext ...}` bullets are intentionally left untouched because each is
14229
+ * kept as a placeholder `<img>` that consumes its blip downstream.
14230
+ *
14231
+ * @param {string} rtf Full RTF clipboard payload.
14232
+ * @returns {string} RTF with list-table picture-bullet definitions removed.
14233
+ */
14234
+ stripListPictureDefinitions(rtf) {
14235
+ // eslint-disable-next-line spellcheck/spell-checker
14236
+ return this.removeBalancedGroups(rtf, '{\\*\\listpicture');
14237
+ }
14238
+ /**
14239
+ * Removes every balanced-brace RTF group that starts with the given marker.
14240
+ *
14241
+ * @param {string} rtf RTF payload to scan.
14242
+ * @param {string} marker Opening delimiter of the group to remove (including its `{`).
14243
+ * @returns {string} RTF with the matching groups removed.
14244
+ */
14245
+ removeBalancedGroups(rtf, marker) {
14246
+ let index = rtf.indexOf(marker);
14247
+ while (index !== -1) {
14248
+ const end = this.findGroupEnd(rtf, index);
14249
+ rtf = rtf.slice(0, index) + rtf.slice(end);
14250
+ index = rtf.indexOf(marker, index);
14251
+ }
14252
+ return rtf;
14253
+ }
14254
+ /**
14255
+ * Finds the index just past the brace that closes the group opened at `start`.
14256
+ *
14257
+ * A backslash escapes the next character (such as `\{` or `\}`) so escaped
14258
+ * braces are not counted. When the group is unbalanced the RTF length is
14259
+ * returned so the trailing remainder is dropped.
14260
+ *
14261
+ * @param {string} rtf RTF payload to scan.
14262
+ * @param {number} start Index of the group's opening `{`.
14263
+ * @returns {number} Index immediately after the matching closing `}`.
14264
+ */
14265
+ findGroupEnd(rtf, start) {
14266
+ const length = rtf.length;
14267
+ let depth = 0;
14268
+ let position = start;
14269
+ while (position < length) {
14270
+ const char = rtf[position];
14271
+ if (char === '\\') {
14272
+ position += 2;
14273
+ continue;
14274
+ }
14275
+ if (char === '{') {
14276
+ depth++;
14277
+ }
14278
+ else if (char === '}') {
14279
+ depth--;
14280
+ if (depth === 0) {
14281
+ return position + 1;
14282
+ }
14283
+ }
14284
+ position++;
14285
+ }
14286
+ return length;
14287
+ }
14288
+ /**
14289
+ * Extracts the raw image bytes that follow a Word RTF blip marker.
14290
+ *
14291
+ * Starting just after the blip control word, RTF control words (such as
14292
+ * `\bliptag`) and nested groups (such as `{\*\blipuid ...}`) are skipped so
14293
+ * their hex is not mistaken for image data. Hex digits are decoded into bytes
14294
+ * until the enclosing `{\pict}` group is closed.
14295
+ *
14296
+ * @param {string} rtf Full RTF clipboard payload.
14297
+ * @param {number} startIndex Index immediately after the blip marker.
14298
+ * @returns {number[]} Decoded image byte values.
14299
+ */
14300
+ extractImageBytes(rtf, startIndex) {
14301
+ const length = rtf.length;
14302
+ const bytes = [];
14303
+ let depth = 0;
14304
+ let highNibble = -1;
14305
+ let position = startIndex;
14306
+ while (position < length) {
14307
+ const char = rtf[position];
14308
+ if (char === '{') {
14309
+ depth++;
14310
+ position++;
14311
+ continue;
14312
+ }
14313
+ if (char === '}') {
14314
+ if (depth === 0) {
14315
+ break;
14316
+ }
14317
+ depth--;
14318
+ position++;
14319
+ continue;
14320
+ }
14321
+ if (depth > 0) {
14322
+ position++;
14323
+ continue;
14324
+ }
14325
+ if (char === '\\') {
14326
+ position++;
14327
+ while (position < length && /[a-zA-Z]/.test(rtf[position])) {
14328
+ position++;
14329
+ }
14330
+ if (position < length && rtf[position] === '-') {
14331
+ position++;
14332
+ }
14333
+ while (position < length && /[0-9]/.test(rtf[position])) {
14334
+ position++;
14335
+ }
14336
+ continue;
14337
+ }
14338
+ const nibble = this.hexNibble(char);
14339
+ if (nibble >= 0) {
14340
+ if (highNibble < 0) {
14341
+ highNibble = nibble;
14342
+ }
14343
+ else {
14344
+ bytes.push((highNibble << 4) | nibble);
14345
+ highNibble = -1;
14346
+ }
14347
+ }
14348
+ position++;
14349
+ }
14350
+ return bytes;
14351
+ }
14352
+ /**
14353
+ * Converts a single hex character to its numeric value.
14354
+ *
14355
+ * @param {string} char Candidate hex character.
14356
+ * @returns {number} Value in `[0, 15]`, or `-1` when not a hex digit.
14357
+ */
14358
+ hexNibble(char) {
14359
+ if (char >= '0' && char <= '9') {
14360
+ return char.charCodeAt(0) - 48;
14361
+ }
14362
+ if (char >= 'a' && char <= 'f') {
14363
+ return char.charCodeAt(0) - 87;
14364
+ }
14365
+ if (char >= 'A' && char <= 'F') {
14366
+ return char.charCodeAt(0) - 55;
14367
+ }
14368
+ return -1;
14369
+ }
14370
+ /**
14371
+ * Returns whether an `<img>` element is nested inside list content.
14372
+ *
14373
+ * The Word paste sanitizer strips non-allowlisted attributes but keeps the
14374
+ * `ul`/`ol`/`li` structure, so list membership is detected by DOM ancestry
14375
+ * here rather than by a marker attribute set upstream.
14376
+ *
14377
+ * @param {HTMLImageElement} imageElement Image element to test.
14378
+ * @returns {boolean} Whether the image is part of list content.
14379
+ */
14380
+ isListImage(imageElement) {
14381
+ return Boolean(imageElement.closest('li,ul,ol'));
10996
14382
  }
10997
14383
  }
10998
- FullscreenController.STYLE_TAG_ID = 'v-rte-fullscreen-styles';
10999
- FullscreenController.HOST_FULLSCREEN_STYLE = 'position:fixed;inset:0;background-color:rgba(var(--v-bg-primary, 252, 252, 252, 1));';
14384
+ PasteImageParser.PREVIEW_IMG_KEY = 'data-rte-id';
14385
+
14386
+ const REPLACE_IMAGE_SRC = 'REPLACE_IMAGE_SRC';
11000
14387
  /**
11001
- * Only three things need overriding inside the shadow root:
11002
- * 1. The outer vega-flex wrapper must fill the host height (`:host >`
11003
- * avoids hitting the toolbar's nested vega-flex).
11004
- * 2. The editor container must grow to fill remaining space and drop
11005
- * the fixed pixel height that Stencil injects from the `rows` prop.
11006
- * 3. The source-view container (shown in source-edit mode) also grows
11007
- * and owns vertical scrolling so long source code is reachable.
11008
- * 4. overflow:auto on the container lets content scroll without clipping
11009
- * internal pop-ups (link editor, color picker, etc.) at the host level.
14388
+ * Action to replace the `src` attribute of an `<img>` element in the RTE content.
11010
14389
  */
11011
- FullscreenController.INNER_FULLSCREEN_CSS = ':host > vega-flex { height: 100%; padding: 5px; box-sizing: border-box; }' +
11012
- ' .rich-text-editor-container { flex: 1 !important; height: auto !important; min-height: 0 !important; resize: none !important; overflow: auto !important; }' +
11013
- ' .source-view-container:not(.vega-hidden) { display: flex !important; flex: 1 !important; min-height: 0 !important; overflow: auto !important; flex-direction: column; }';
11014
- FullscreenController.documentScrollLockStates = new WeakMap();
14390
+ class ImageReplaceSrcAction extends codeBlock.ModifyContentAction {
14391
+ constructor(imageElement, url) {
14392
+ super();
14393
+ this.type = REPLACE_IMAGE_SRC;
14394
+ this.img = imageElement;
14395
+ this.url = url;
14396
+ }
14397
+ }
11015
14398
 
11016
14399
  /**
11017
- * Rich Text Editor extension that adds a toolbar button for viewport fullscreen mode.
11018
- *
11019
- * OOP Pattern: Extends VegaRTEExtension with fullscreen feature.
11020
- * Uses a per-host controller store to isolate state across hosts.
14400
+ * Strategy to handle the `ImageReplaceSrcAction` for replacing the `src` attribute of an `<img>` element in the RTE content.
11021
14401
  */
11022
- class VegaRTEFullscreenExtension extends linkExtension.VegaRTEExtension {
11023
- /** @inheritDoc */
11024
- prepareBeforeLoad(host) {
11025
- const controller = new FullscreenController(host);
11026
- VegaRTEFullscreenExtension.controllerStore.set(host, controller);
11027
- this.registerToolbarButtonRenderer(VegaRTEFullscreenExtension.TOOLBAR_BUTTON_KEY, new RTEFullscreenToolbarButtonRenderer(controller), host);
11028
- }
14402
+ class ImageReplaceSrcStrategy extends codeBlock.ActionHandleStrategy {
11029
14403
  /**
11030
- * Restore document scroll if the editor is removed while fullscreen is active.
11031
- * Without this, body overflow:hidden would persist after the host is gone.
14404
+ * @inheritDoc
11032
14405
  */
11033
- destroyExtension() {
11034
- var _a, _b;
11035
- if ((_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.host) {
11036
- const host = this.extensionContext.host;
11037
- (_b = VegaRTEFullscreenExtension.controllerStore.get(host)) === null || _b === void 0 ? void 0 : _b.exitFullscreen();
11038
- VegaRTEFullscreenExtension.controllerStore.delete(host);
14406
+ handleAction(action, target) {
14407
+ const { img, url } = action;
14408
+ img.setAttribute('src', url);
14409
+ img.removeAttribute(PasteImageParser.PREVIEW_IMG_KEY);
14410
+ target.url = url;
14411
+ if (target.annotationMap && target.annotationMap.has('CUSTOM_ATTRIBUTE')) {
14412
+ const customAttributeAnnotation = target.annotationMap.get('CUSTOM_ATTRIBUTE');
14413
+ customAttributeAnnotation.customAttribute.src = url;
14414
+ delete customAttributeAnnotation.customAttribute[PasteImageParser.PREVIEW_IMG_KEY];
11039
14415
  }
11040
14416
  }
11041
14417
  }
11042
- VegaRTEFullscreenExtension.TOOLBAR_BUTTON_KEY = 'fullscreen';
11043
- VegaRTEFullscreenExtension.controllerStore = VegaRTEFullscreenExtension.createStateStore();
11044
-
11045
- const paste = {
11046
- icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.3.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path fill="currentColor" d="M80 96v16c0 17.7 14.3 32 32 32h60.8c16.6-28.7 47.6-48 83.2-48h62c-7.1-27.6-32.2-48-62-48H215.4C211.6 20.9 188.2 0 160 0s-51.6 20.9-55.4 48H64C28.7 48 0 76.7 0 112V384c0 35.3 28.7 64 64 64h96V400H64c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16H80zm64-40a16 16 0 1 1 32 0 16 16 0 1 1 -32 0zM256 464c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H384v48c0 17.7 14.3 32 32 32h48V448c0 8.8-7.2 16-16 16H256zm192 48c35.3 0 64-28.7 64-64V227.9c0-12.7-5.1-24.9-14.1-33.9l-51.9-51.9c-9-9-21.2-14.1-33.9-14.1H256c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H448z"/></svg>`,
11047
- };
11048
14418
 
11049
14419
  /**
11050
- * Renders and manages the paste format chooser UI.
14420
+ * Owns the lifecycle of pasted images awaiting upload: it tracks their local
14421
+ * object-URL previews, notifies the consumer once they are inserted, applies the
14422
+ * uploaded URL back onto the live preview, and revokes object URLs on teardown.
14423
+ *
14424
+ * Keeping this state here rather than on the paste extension keeps the extension
14425
+ * focused on clipboard capture and the chooser UI.
11051
14426
  */
11052
- class RTEPasteChooserUI {
11053
- constructor(hostRoot, callbacks) {
11054
- this.hostRoot = hostRoot;
11055
- this.callbacks = callbacks;
11056
- this.chooserEl = null;
11057
- this.dropdownEl = null;
11058
- this.triggerButtonEl = null;
14427
+ class PendingImageRegistry {
14428
+ constructor() {
14429
+ /** Ids of pending images still holding an object URL owned by this registry. */
14430
+ this.ownedImageIds = new Set();
14431
+ /** Ids queued for the next {@link notifyInserted} call. */
14432
+ this.pendingNotifyImageIds = [];
11059
14433
  }
11060
14434
  /**
11061
- * Opens the paste-mode chooser at the given position.
14435
+ * Registers freshly created previews so they can be notified and later
14436
+ * resolved to their uploaded URLs.
11062
14437
  *
11063
- * @param {PasteChooserPosition} position Viewport position for the chooser.
14438
+ * @param {PasteImagePreview[]} previews Previews produced for the current paste.
11064
14439
  */
11065
- open(position) {
11066
- this.destroy();
11067
- const doc = this.hostRoot.ownerDocument;
11068
- const chooser = doc.createElement('div');
11069
- chooser.setAttribute(RTEPasteChooserUI.CHOOSER_ATTR, 'true');
11070
- chooser.style.position = 'fixed';
11071
- chooser.style.zIndex = '1000';
11072
- chooser.style.left = `${position.left}px`;
11073
- chooser.style.top = `${position.top}px`;
11074
- const dropdownEl = this.createPasteChooserDropdown(doc, position.placement);
11075
- dropdownEl.placement = position.placement;
11076
- chooser.append(dropdownEl);
11077
- this.hostRoot.appendChild(chooser);
11078
- this.chooserEl = chooser;
11079
- this.dropdownEl = dropdownEl;
11080
- dropdownEl.addEventListener('vegaShow', () => {
11081
- if (this.triggerButtonEl) {
11082
- this.triggerButtonEl.selected = true;
11083
- }
11084
- });
11085
- dropdownEl.addEventListener('vegaHide', () => {
11086
- if (this.triggerButtonEl) {
11087
- this.triggerButtonEl.selected = false;
11088
- }
14440
+ register(previews) {
14441
+ this.pendingNotifyImageIds = [];
14442
+ previews.forEach((preview) => {
14443
+ this.pendingNotifyImageIds.push(preview.id);
14444
+ this.ownedImageIds.add(preview.id);
14445
+ PendingImageRegistry.pendingImages.set(preview.id, preview);
11089
14446
  });
11090
14447
  }
11091
14448
  /**
11092
- * Removes the chooser from the DOM.
14449
+ * @returns {boolean} Whether previews are queued for notification.
11093
14450
  */
11094
- destroy() {
11095
- var _a;
11096
- if (this.dropdownEl && typeof this.dropdownEl.hide === 'function') {
11097
- void this.dropdownEl.hide();
11098
- }
11099
- if ((_a = this.chooserEl) === null || _a === void 0 ? void 0 : _a.parentNode) {
11100
- this.chooserEl.parentNode.removeChild(this.chooserEl);
11101
- }
11102
- if (this.triggerButtonEl) {
11103
- this.triggerButtonEl.selected = false;
11104
- }
11105
- this.dropdownEl = null;
11106
- this.chooserEl = null;
11107
- this.triggerButtonEl = null;
14451
+ hasPendingNotifications() {
14452
+ return this.pendingNotifyImageIds.length > 0;
11108
14453
  }
11109
14454
  /**
11110
- * Determines whether the given event path targets the chooser.
14455
+ * Notifies the consumer about newly inserted pasted images so they can upload
14456
+ * them and fill in the real URLs via the supplied `replaceUrl` callback.
11111
14457
  *
11112
- * @param {EventTarget[]} eventPath Composed path of an event.
11113
- * @returns {boolean} `true` when the path includes the chooser.
14458
+ * @param {ImageInsertedCallback | undefined} callback Consumer callback to invoke.
14459
+ * @param {GetEditableElement} getEditableElement Resolves the live editable element.
14460
+ * @param {ResolveImageNode} resolveImageNode Resolves the DTO node for a preview element.
11114
14461
  */
11115
- includesEventPath(eventPath) {
11116
- if (!this.chooserEl) {
11117
- return false;
14462
+ notifyInserted(callback, getEditableElement, resolveImageNode) {
14463
+ const images = this.pendingNotifyImageIds
14464
+ .map((id) => PendingImageRegistry.pendingImages.get(id))
14465
+ .filter((preview) => !!preview);
14466
+ this.pendingNotifyImageIds = [];
14467
+ if (images.length && typeof callback === 'function') {
14468
+ // Mark as handed to the consumer so teardown keeps them for a later replaceUrl.
14469
+ images.forEach((image) => (image.notified = true));
14470
+ const pasteImages = images.map((image) => ({
14471
+ id: image.id,
14472
+ file: image.file,
14473
+ }));
14474
+ callback(pasteImages, (imageId, url) => this.replaceUrl(imageId, url, getEditableElement, resolveImageNode));
11118
14475
  }
11119
- const isDropdownContentClick = eventPath.some((target) => {
11120
- return 'tagName' in target && target.tagName === 'VEGA-DROPDOWN-CONTENT-BOX';
11121
- });
11122
- return eventPath.includes(this.chooserEl) || isDropdownContentClick;
11123
14476
  }
11124
14477
  /**
11125
- * Builds the dropdown element with the rich text paste option.
11126
- *
11127
- * @param {Document} doc Document used to create elements.
11128
- * @param {['bottom', 'top'] | ['top', 'bottom']} placement Preferred placement order.
11129
- * @returns {HTMLElement} Configured dropdown element.
14478
+ * Revokes and forgets only previews that were never handed to a consumer for
14479
+ * upload. Previews already notified via {@link notifyInserted} are left intact
14480
+ * so an async {@link replaceUrl} can still resolve them after the extension is
14481
+ * recreated; that callback owns their teardown.
11130
14482
  */
11131
- createPasteChooserDropdown(doc, placement) {
11132
- const dropdownEl = doc.createElement('vega-dropdown');
11133
- dropdownEl.trigger = 'click';
11134
- dropdownEl.selectType = 'single';
11135
- dropdownEl.selectedSourceKey = 'rich';
11136
- dropdownEl.maxWidth = 220;
11137
- dropdownEl.alignment = 'start';
11138
- dropdownEl.itemDisplayRule = 'ellipsis';
11139
- dropdownEl.isScreenPosition = true;
11140
- const triggerButton = doc.createElement('vega-rich-text-editor-toolbar-button');
11141
- const arrowIcon = placement[0] === 'top' ? 'chevron-up' : 'chevron-down';
11142
- triggerButton.setAttribute(RTEPasteChooserUI.CHOOSER_TRIGGER_ATTR, 'true');
11143
- triggerButton.setAttribute('aria-label', internalTranslationController.VegaInternalTranslation.t('Paste options'));
11144
- triggerButton.setAttribute('arrow-icon', arrowIcon);
11145
- triggerButton.icon = 'rte-paste';
11146
- triggerButton.showArrowIcon = true;
11147
- triggerButton.selected = false;
11148
- this.triggerButtonEl = triggerButton;
11149
- const tooltipEl = doc.createElement('vega-tooltip');
11150
- tooltipEl.text = internalTranslationController.VegaInternalTranslation.t('Paste options');
11151
- tooltipEl.placement = ['bottom', 'top'];
11152
- tooltipEl.append(triggerButton);
11153
- dropdownEl.append(tooltipEl);
11154
- const itemsContainer = doc.createElement('div');
11155
- itemsContainer.setAttribute('slot', 'items');
11156
- itemsContainer.append(this.createDropdownItem(doc, 'rich', internalTranslationController.VegaInternalTranslation.t('Use rich text'), RTEPasteChooserUI.CHOOSER_RICH_ATTR));
11157
- dropdownEl.append(itemsContainer);
11158
- dropdownEl.addEventListener('vegaDropdownClick', (event) => {
11159
- const mode = event.detail;
11160
- if (mode === 'rich') {
11161
- this.callbacks.onModeSelect(mode);
14483
+ discardUnsentPreviews() {
14484
+ this.ownedImageIds.forEach((imageId) => {
14485
+ const pending = PendingImageRegistry.pendingImages.get(imageId);
14486
+ if (pending && pending.notified) {
14487
+ return;
14488
+ }
14489
+ if (pending && pending.objectUrl.startsWith('blob:')) {
14490
+ URL.revokeObjectURL(pending.objectUrl);
11162
14491
  }
14492
+ PendingImageRegistry.pendingImages.delete(imageId);
14493
+ this.ownedImageIds.delete(imageId);
11163
14494
  });
11164
- return dropdownEl;
14495
+ this.pendingNotifyImageIds = [];
11165
14496
  }
11166
14497
  /**
11167
- * Creates a single dropdown item element for a paste mode.
14498
+ * Applies the uploaded URL for a pending pasted image, replacing its local
14499
+ * preview `src` and revoking the object URL.
11168
14500
  *
11169
- * @param {Document} doc Document used to create the element.
11170
- * @param {PasteMode} key Paste mode key for the item.
11171
- * @param {string} label Display label for the item.
11172
- * @param {string} dataAttrName Data attribute marker for the item.
11173
- * @returns {HTMLVegaDropdownItemElement} Configured dropdown item element.
14501
+ * @param {string} imageId Pending image id supplied to the consumer callback.
14502
+ * @param {string} url Uploaded image URL to apply.
14503
+ * @param {GetEditableElement} getEditableElement Resolves the live editable element.
14504
+ * @param {ResolveImageNode} resolveImageNode Resolves the DTO node for a preview element.
11174
14505
  */
11175
- createDropdownItem(doc, key, label, dataAttrName) {
11176
- const itemEl = doc.createElement('vega-dropdown-item');
11177
- itemEl.itemKey = key;
11178
- itemEl.label = label;
11179
- itemEl.setAttribute(dataAttrName, 'true');
11180
- return itemEl;
14506
+ replaceUrl(imageId, url, getEditableElement, resolveImageNode) {
14507
+ var _a;
14508
+ const editableEl = getEditableElement();
14509
+ if (editableEl) {
14510
+ const imageElement = (_a = editableEl.querySelector(`img[data-rte-id="${imageId}"]`)) !== null && _a !== void 0 ? _a : null;
14511
+ if (imageElement) {
14512
+ const imageNode = resolveImageNode(imageElement);
14513
+ imageNode && imageNode.apply(new ImageReplaceSrcAction(imageElement, url));
14514
+ }
14515
+ }
14516
+ const pending = PendingImageRegistry.pendingImages.get(imageId);
14517
+ if (pending) {
14518
+ if (pending.objectUrl.startsWith('blob:')) {
14519
+ URL.revokeObjectURL(pending.objectUrl);
14520
+ }
14521
+ PendingImageRegistry.pendingImages.delete(imageId);
14522
+ this.ownedImageIds.delete(imageId);
14523
+ }
11181
14524
  }
11182
14525
  }
11183
- (() => {
11184
- internalIconManager.VegaInternalIconManager.register({
11185
- 'rte-paste': paste,
11186
- });
11187
- })();
11188
- RTEPasteChooserUI.CHOOSER_ATTR = 'data-rte-paste-chooser';
11189
- RTEPasteChooserUI.CHOOSER_RICH_ATTR = 'data-rte-paste-type-rich';
11190
- RTEPasteChooserUI.CHOOSER_TRIGGER_ATTR = 'data-rte-paste-trigger';
11191
-
11192
14526
  /**
11193
- * Custom DataTransfer MIME type used to tag a synthetic paste with the chosen
11194
- * paste mode (e.g. 'rich' or 'plain'), so downstream paste handling can decide
11195
- * whether to preserve the original inline styles.
14527
+ * Pasted images awaiting upload, keyed by their {@link VegaRTEPasteImage.id}.
14528
+ *
14529
+ * Shared statically across instances so previews survive a paste-extension
14530
+ * re-instantiation: the consumer may resolve `replaceUrl` after the editor
14531
+ * has re-mounted and created a new extension/registry instance.
11196
14532
  */
11197
- const RTE_PASTE_MODE_DATA_TYPE = 'application/x-vega-rte-paste-mode';
14533
+ PendingImageRegistry.pendingImages = new Map();
11198
14534
 
11199
14535
  /**
11200
14536
  * Vega Rich Text Editor paste extension.
11201
14537
  * Intercepts keyboard paste and allows users to choose paste mode.
11202
14538
  */
11203
14539
  class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11204
- constructor() {
11205
- super(...arguments);
14540
+ constructor(options = {}) {
14541
+ super();
11206
14542
  this.editableEl = null;
11207
14543
  this.contentHostEl = null;
11208
14544
  this.chooserUI = null;
11209
14545
  this.pendingPastePayload = null;
11210
14546
  this.listenerDocument = null;
11211
14547
  this.listenerWindow = null;
14548
+ this.options = {};
14549
+ this.strategySelector = new PasteStrategySelector();
14550
+ this.clipboardFileContent = null;
14551
+ this.imageParser = new PasteImageParser();
14552
+ /** Owns pending pasted-image previews awaiting upload and their URL replacement. */
14553
+ this.pendingImageRegistry = new PendingImageRegistry();
11212
14554
  /**
11213
14555
  * Handles a native paste event by capturing the clipboard payload and
11214
14556
  * rendering the paste-mode chooser.
@@ -11224,6 +14566,9 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11224
14566
  // HTML is sanitized via DOMParser and ElementToDtoStrategyProcessor pipeline
11225
14567
  const html = clipboardData.getData('text/html') || '';
11226
14568
  const text = clipboardData.getData('text/plain') || '';
14569
+ // RTF must be read synchronously here: the paste event's DataTransfer is only
14570
+ // readable during event dispatch, so reading it later (after the chooser) returns ''.
14571
+ const rtf = clipboardData.getData('text/rtf') || '';
11227
14572
  if (!html && !text) {
11228
14573
  // Empty clipboard paste should not mutate editor content.
11229
14574
  event.preventDefault();
@@ -11235,6 +14580,10 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11235
14580
  const range = this.cloneCurrentSelectionRange();
11236
14581
  const selectedNodes = ((_b = (_a = this.extensionContext) === null || _a === void 0 ? void 0 : _a.getSelectedNodes) === null || _b === void 0 ? void 0 : _b.call(_a)) || [];
11237
14582
  this.pendingPastePayload = { html, text, range, selectedNodes: [...selectedNodes] };
14583
+ this.clipboardFileContent = {
14584
+ files: clipboardData.files ? Array.from(clipboardData.files) : [],
14585
+ rtf,
14586
+ };
11238
14587
  this.renderPasteChooser(event);
11239
14588
  };
11240
14589
  /**
@@ -11268,6 +14617,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11268
14617
  this.handleOutsideScroll = () => {
11269
14618
  this.clearPasteChooser();
11270
14619
  };
14620
+ this.options = options;
11271
14621
  }
11272
14622
  /** @inheritDoc */
11273
14623
  initialExtensionAfterLoad(context) {
@@ -11279,6 +14629,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11279
14629
  destroyExtension() {
11280
14630
  this.detachPasteListener();
11281
14631
  this.clearPasteChooser();
14632
+ this.pendingImageRegistry.discardUnsentPreviews();
11282
14633
  }
11283
14634
  /**
11284
14635
  * Attaches the paste listener to the editable element.
@@ -11341,7 +14692,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11341
14692
  * @param {ClipboardEvent} pasteEvent Originating paste event used for positioning.
11342
14693
  */
11343
14694
  renderPasteChooser(pasteEvent) {
11344
- var _a, _b;
14695
+ var _a, _b, _c;
11345
14696
  const hostRoot = (_b = (_a = this.hostEl) === null || _a === void 0 ? void 0 : _a.shadowRoot) !== null && _b !== void 0 ? _b : null;
11346
14697
  if (!hostRoot) {
11347
14698
  return;
@@ -11353,6 +14704,8 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11353
14704
  onModeSelect: (mode) => {
11354
14705
  this.applyPasteMode(mode);
11355
14706
  },
14707
+ }, {
14708
+ showWordOption: ((_c = this.options) === null || _c === void 0 ? void 0 : _c.enableWordPaste) === true,
11356
14709
  });
11357
14710
  this.chooserUI.open(position);
11358
14711
  this.listenerDocument = this.hostEl.ownerDocument;
@@ -11482,7 +14835,10 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11482
14835
  /**
11483
14836
  * Applies the chosen paste mode by dispatching a synthetic paste input event.
11484
14837
  *
11485
- * @param {PasteMode} mode Selected paste mode.
14838
+ * `rich` keeps auto-detection enabled; any other explicit mode forces the
14839
+ * corresponding registered strategy.
14840
+ *
14841
+ * @param {RTEPasteMode} mode Selected paste mode.
11486
14842
  */
11487
14843
  applyPasteMode(mode) {
11488
14844
  var _a;
@@ -11498,9 +14854,42 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11498
14854
  editableEl.focus();
11499
14855
  this.restoreSelectionRange(this.pendingPastePayload.range);
11500
14856
  this.restoreSelectionControllerState(this.pendingPastePayload);
11501
- const dataTransfer = this.createDataTransfer(this.pendingPastePayload.html, this.pendingPastePayload.text, mode);
14857
+ const strategy = mode === RTEPasteMode.RICH
14858
+ ? this.strategySelector.selectStrategy(this.pendingPastePayload.html)
14859
+ : this.strategySelector.selectStrategyByType(mode);
14860
+ let processedHtml = strategy.process(this.pendingPastePayload.html);
14861
+ // If the strategy supports image processing and there is clipboard file content, parse local images.
14862
+ if (strategy.supportsImageProcessing && this.clipboardFileContent) {
14863
+ processedHtml = this.parseLocalImages(processedHtml, this.clipboardFileContent);
14864
+ }
14865
+ this.clipboardFileContent = null;
14866
+ const dataTransfer = this.createDataTransfer(processedHtml, this.pendingPastePayload.text, strategy.type);
11502
14867
  this.dispatchBeforeInputPaste(editableEl, dataTransfer);
11503
14868
  this.clearPasteChooser();
14869
+ this.emitLocalImageInsertedEvent();
14870
+ }
14871
+ /**
14872
+ * Parses local images from the HTML and emits events for further processing.
14873
+ *
14874
+ * @param {string} html HTML content to parse.
14875
+ * @param {ClipboardFileContent} clipboardFileContent Clipboard file content for image extraction.
14876
+ * @returns {string} Processed HTML with local image references replaced.
14877
+ */
14878
+ parseLocalImages(html, clipboardFileContent) {
14879
+ const { html: result, previews } = this.imageParser.parseLocalImages(html, clipboardFileContent);
14880
+ if (previews.length > 0) {
14881
+ this.pendingImageRegistry.register(previews);
14882
+ }
14883
+ return result;
14884
+ }
14885
+ /**
14886
+ * Emits the `imageInsertedCallback` for any pending previews, allowing the
14887
+ * consumer to upload them and resolve their URLs.
14888
+ */
14889
+ emitLocalImageInsertedEvent() {
14890
+ if (this.pendingImageRegistry.hasPendingNotifications()) {
14891
+ this.pendingImageRegistry.notifyInserted(this.options.imageInsertedCallback, () => { var _a; return (_a = this.editableEl) !== null && _a !== void 0 ? _a : this.getEditableElement(); }, (imageElement) => this.getDTOEntityByDom(imageElement));
14892
+ }
11504
14893
  }
11505
14894
  /**
11506
14895
  * Restores SelectionController state from the captured selection so synthetic
@@ -11574,7 +14963,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11574
14963
  *
11575
14964
  * @param {string} html HTML clipboard content.
11576
14965
  * @param {string} text Plain text clipboard content.
11577
- * @param {PasteMode} [mode] Selected paste mode marker.
14966
+ * @param {RTEPasteMode} [mode] Selected paste mode marker.
11578
14967
  * @returns {DataTransfer} Populated data transfer payload.
11579
14968
  */
11580
14969
  createDataTransfer(html, text, mode) {
@@ -11587,7 +14976,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11587
14976
  dataTransfer.setData('text/plain', text);
11588
14977
  }
11589
14978
  if (mode) {
11590
- dataTransfer.setData(RTE_PASTE_MODE_DATA_TYPE, mode);
14979
+ dataTransfer.setData(codeBlock.RTE_PASTE_MODE_DATA_TYPE, mode);
11591
14980
  }
11592
14981
  return dataTransfer;
11593
14982
  }
@@ -11600,7 +14989,7 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11600
14989
  if (type === 'text/plain') {
11601
14990
  return text;
11602
14991
  }
11603
- if (type === RTE_PASTE_MODE_DATA_TYPE) {
14992
+ if (type === codeBlock.RTE_PASTE_MODE_DATA_TYPE) {
11604
14993
  return mode !== null && mode !== void 0 ? mode : '';
11605
14994
  }
11606
14995
  return '';
@@ -11635,6 +15024,9 @@ class VegaRTEPasteExtension extends linkExtension.VegaRTEExtension {
11635
15024
  }
11636
15025
  }
11637
15026
  }
15027
+ (() => {
15028
+ linkExtension.VegaRTEExtension.registerActionHandleStrategy(contentState.RTEImageNode.name, REPLACE_IMAGE_SRC, new ImageReplaceSrcStrategy());
15029
+ })();
11638
15030
 
11639
15031
  /**
11640
15032
  * Action to extract the currently selected content (HTML and plain text) from the editor.
@@ -11672,6 +15064,7 @@ class RTECopyToolbarButtonRenderer extends VegaRTEToolbarButtonRenderer {
11672
15064
  render(h, editorContext) {
11673
15065
  return this.renderButton(h, editorContext, {
11674
15066
  icon: 'rte-copy',
15067
+ ariaLabel: editorContext.translation.t('Copy'),
11675
15068
  tooltip: { text: 'Copy' },
11676
15069
  });
11677
15070
  }
@@ -11987,6 +15380,7 @@ class RTECutToolbarButtonRenderer extends RTECopyToolbarButtonRenderer {
11987
15380
  render(h, editorContext) {
11988
15381
  return this.renderButton(h, editorContext, {
11989
15382
  icon: 'rte-cut',
15383
+ ariaLabel: editorContext.translation.t('Cut'),
11990
15384
  tooltip: { text: 'Cut' },
11991
15385
  });
11992
15386
  }
@@ -12025,6 +15419,130 @@ class VegaRTECutExtension extends linkExtension.VegaRTEExtension {
12025
15419
  // The unique key for the cut toolbar button, used for registration and retrieval.
12026
15420
  VegaRTECutExtension.TOOLBAR_BUTTON_KEY = 'cut';
12027
15421
 
15422
+ /**
15423
+ * Vetoes a commit that would push the character count past the hard limit, while
15424
+ * still allowing deletions and formatting that keep or reduce the count.
15425
+ */
15426
+ class PreventHardLimitExceedInterceptor extends ActionHandlerInterceptor {
15427
+ /**
15428
+ * Intercept when the candidate exceeds the configured maximum. Hard-limit
15429
+ * commits are vetoed only when they increase the count.
15430
+ *
15431
+ * @param {CommitValueAction} action - the commit action carrying the candidate and previous values
15432
+ * @returns {boolean} - whether the commit should be vetoed
15433
+ */
15434
+ canIntercept(action) {
15435
+ var _a;
15436
+ const extension = (_a = action.host.extensions) === null || _a === void 0 ? void 0 : _a.find((item) => this.isWordCountExtension(item));
15437
+ if (!extension) {
15438
+ return false;
15439
+ }
15440
+ const { hardLimit, maxChars } = extension.getConfig();
15441
+ const nextContent = action.candidate.getPlainText();
15442
+ const nextCount = extension.calculateTextCount(nextContent);
15443
+ if (!typeGuard.isNonNullable(maxChars) || nextCount <= maxChars) {
15444
+ return false;
15445
+ }
15446
+ let result = false;
15447
+ let prevContent = '';
15448
+ if (hardLimit && action.previous) {
15449
+ prevContent = action.previous.getPlainText();
15450
+ result = nextCount > extension.calculateTextCount(prevContent);
15451
+ }
15452
+ this.notifyCharsLimitExceeded(nextContent, prevContent, extension, action);
15453
+ return result;
15454
+ }
15455
+ /**
15456
+ * Not invoke the origin action handle to veto the commit that would push the character count past the hard limit.
15457
+ */
15458
+ intercept() {
15459
+ }
15460
+ /**
15461
+ * Notify the consumer when the candidate exceeds the configured character limit.
15462
+ * The previous content is empty when hard limit is not enabled for the performance optimization.
15463
+ *
15464
+ * @param {string} nextContent - the candidate content string
15465
+ * @param {string} prevContent - the previous content string
15466
+ * @param {VegaRTEWordCountExtension} extension - the configured word count extension
15467
+ * @param {CommitValueAction} action - the commit action carrying the candidate value
15468
+ */
15469
+ notifyCharsLimitExceeded(nextContent, prevContent, extension, action) {
15470
+ const { maxChars, hardLimit, onCharsLimitExceeded } = extension.getConfig();
15471
+ if (typeof onCharsLimitExceeded === 'function') {
15472
+ if (!hardLimit || prevContent !== nextContent) {
15473
+ onCharsLimitExceeded(action.host, maxChars);
15474
+ }
15475
+ }
15476
+ }
15477
+ /**
15478
+ * Check if the given extension is a word count extension.
15479
+ *
15480
+ * @param {VegaRTEExtension} extension - the extension to check
15481
+ * @returns {boolean} - whether the extension is a word count extension
15482
+ */
15483
+ isWordCountExtension(extension) {
15484
+ return extension['type'] === codeBlock.RTE_WORD_COUNT_KEY;
15485
+ }
15486
+ }
15487
+
15488
+ /**
15489
+ * Default configuration applied when a word count option is not provided.
15490
+ */
15491
+ const DEFAULT_WORD_COUNT_CONFIG = {
15492
+ showCharCount: true,
15493
+ countInlineBreak: false,
15494
+ hardLimit: false,
15495
+ };
15496
+ /**
15497
+ * Rich Text Editor extension that provides character counting.
15498
+ */
15499
+ class VegaRTEWordCountExtension extends linkExtension.VegaRTEExtension {
15500
+ constructor(config = {}) {
15501
+ super();
15502
+ /**
15503
+ * Runtime discriminator used by the core to identify this extension.
15504
+ */
15505
+ this.type = codeBlock.RTE_WORD_COUNT_KEY;
15506
+ this.config = Object.assign(Object.assign({}, DEFAULT_WORD_COUNT_CONFIG), config);
15507
+ }
15508
+ /**
15509
+ * Get the extension configuration.
15510
+ *
15511
+ * @returns {ResolvedRTEWordCountConfig} The word count configuration.
15512
+ */
15513
+ getConfig() {
15514
+ return this.config;
15515
+ }
15516
+ /**
15517
+ * Compute the character count data for the given editor content.
15518
+ *
15519
+ * @param {VegaRTEContent} value - The editor content.
15520
+ * @returns {VegaRTEWordCountData} The computed character count data.
15521
+ */
15522
+ getData(value) {
15523
+ const plainText = value.getPlainText();
15524
+ const { maxChars, hardLimit } = this.config;
15525
+ const count = this.calculateTextCount(plainText);
15526
+ return { count, maxChars, hardLimit };
15527
+ }
15528
+ /**
15529
+ * Get the character count for the given content string.
15530
+ *
15531
+ * @param {string} content - The content string.
15532
+ * @returns {number} The character count.
15533
+ */
15534
+ calculateTextCount(content) {
15535
+ const { countInlineBreak } = this.config;
15536
+ const text = countInlineBreak ? content : content.replace(/\n/g, '');
15537
+ // Use the spread operator so that surrogate pairs (e.g. emoji) count as a single character.
15538
+ return [...text].length;
15539
+ }
15540
+ }
15541
+ (() => {
15542
+ // Gate over-limit commits through the shared action-interceptor pipeline.
15543
+ linkExtension.VegaRTEExtension.registerActionHandlerInterceptor(contentState.VegaRTEContent.name, contentState.COMMIT_VALUE, new PreventHardLimitExceedInterceptor());
15544
+ })();
15545
+
12028
15546
  /**
12029
15547
  * Insert a new children to the nearest position of the parent container
12030
15548
  *
@@ -12089,7 +15607,7 @@ class SpanToTokenNodeStrategy extends contentState.ElementToDTOStrategy {
12089
15607
  /**
12090
15608
  * @inheritDoc
12091
15609
  */
12092
- handle(elementsArray) {
15610
+ handle(elementsArray, _options, parentTextAnnotations) {
12093
15611
  const element = elementsArray[0];
12094
15612
  const tokenKey = element.getAttribute('token-key');
12095
15613
  const text = element.textContent;
@@ -12102,7 +15620,9 @@ class SpanToTokenNodeStrategy extends contentState.ElementToDTOStrategy {
12102
15620
  type: 'token',
12103
15621
  token: tokenKey,
12104
15622
  text,
12105
- annotations: Object.assign(Object.assign({}, restAnnotations), { customAttribute: this.createCustomAttrs(customAttribute) }),
15623
+ annotations: Object.assign(Object.assign(Object.assign({}, restAnnotations), ((parentTextAnnotations === null || parentTextAnnotations === void 0 ? void 0 : parentTextAnnotations.inlineHtml)
15624
+ ? { inlineHtml: parentTextAnnotations.inlineHtml }
15625
+ : {})), { customAttribute: this.createCustomAttrs(customAttribute) }),
12106
15626
  };
12107
15627
  }
12108
15628
  /**
@@ -12186,6 +15706,7 @@ exports.VegaRTESpecialCharactersText = VegaRTESpecialCharactersText;
12186
15706
  exports.VegaRTETableExtension = VegaRTETableExtension;
12187
15707
  exports.VegaRTETokenExtension = VegaRTETokenExtension;
12188
15708
  exports.VegaRTEToolbarButtonRenderer = VegaRTEToolbarButtonRenderer;
15709
+ exports.VegaRTEWordCountExtension = VegaRTEWordCountExtension;
12189
15710
  exports.VegaSkeletonLoader = VegaSkeletonLoader;
12190
15711
  exports.VegaTranslation = VegaTranslation;
12191
15712
  exports.VegaZIndexManager = VegaZIndexManager$1;