@globalpayments/vega 2.38.0 → 2.39.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 (262) hide show
  1. package/dist/cjs/{app-globals-7087f121.js → app-globals-dd3e7925.js} +2 -3
  2. package/dist/cjs/content-state-c5b47ca1.js +6644 -0
  3. package/dist/cjs/{image-annotation-action-7d82f7e1.js → image-annotation-action-75b9c0d3.js} +5 -6
  4. package/dist/cjs/index.cjs.js +13 -14
  5. package/dist/cjs/loader.cjs.js +8 -9
  6. package/dist/cjs/vega-date-picker_2.cjs.entry.js +1 -1
  7. package/dist/cjs/vega-env-manager-23b8b23c.js +2 -2
  8. package/dist/cjs/vega-input-phone-number.cjs.entry.js +31 -7
  9. package/dist/cjs/vega-popover_2.cjs.entry.js +14 -0
  10. package/dist/cjs/vega-rich-text-content.cjs.entry.js +18 -19
  11. package/dist/cjs/vega-rich-text-editor_4.cjs.entry.js +75 -79
  12. package/dist/cjs/vega.cjs.js +8 -9
  13. package/dist/collection/components/vega-input-phone-number/slimmers/controllers/vega-input-phone-number-value-controller.js +18 -2
  14. package/dist/collection/components/vega-input-phone-number/vega-input-phone-number.js +7 -4
  15. package/dist/collection/components/vega-popover/slimmers/controllers/vega-popover-appender-controller.js +4 -0
  16. package/dist/collection/components/vega-popover/vega-popover.js +37 -0
  17. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/action-handle-strategy-registry.js +52 -0
  18. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/action-handle-strategy.abstract.js +63 -0
  19. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/block-update-link-group-strategy.js +21 -0
  20. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/block-update-text-style-strategy.js +32 -0
  21. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/image-set-annotation-map-strategy.js +13 -0
  22. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/node-split-text-strategy.js +134 -0
  23. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/node-update-annotation-map-strategy.js +47 -0
  24. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-append-blocks-strategy.js +19 -0
  25. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-append-nodes-strategy.js +21 -0
  26. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-image-strategy.js +54 -0
  27. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-node-content-strategy.js +152 -0
  28. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-text-content-strategy.js +99 -0
  29. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-blocks-after-strategy.js +15 -0
  30. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-blocks-before-strategy.js +38 -0
  31. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-image-into-text-strategy.js +31 -0
  32. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-line-break-strategy.js +57 -0
  33. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-line-break-with-blocks-strategy.js +60 -0
  34. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-new-paragraph-strategy.js +55 -0
  35. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-nodes-after-node-strategy.js +14 -0
  36. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-nodes-before-node-strategy.js +14 -0
  37. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-merge-nodes-strategy.js +25 -0
  38. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-remove-child-block-strategy.js +15 -0
  39. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-remove-node-strategy.js +21 -0
  40. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-replace-node-with-nodes-strategy.js +28 -0
  41. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-replace-nodes-strategy.js +17 -0
  42. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-split-with-image-node-strategy.js +48 -0
  43. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-split-with-text-node-strategy.js +43 -0
  44. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-transform-to-list-strategy.js +26 -0
  45. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-block-insert-image-strategy.js +32 -0
  46. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-line-break-strategy.js +21 -0
  47. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-line-break-with-blocks-strategy.js +55 -0
  48. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-new-paragraph-strategy.js +44 -0
  49. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-update-url-strategy.js +12 -0
  50. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-insert-image-strategy.js +22 -0
  51. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-delete-text-content-strategy.js +20 -0
  52. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-insert-image-strategy.js +15 -0
  53. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-insert-new-paragraph-strategy.js +92 -0
  54. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-remove-nest-list-strategy.js +22 -0
  55. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-remove-node-strategy.js +19 -0
  56. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-replace-nest-list-strategy.js +15 -0
  57. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-remove-list-item-strategy.js +27 -0
  58. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-transform-to-list-strategy.js +36 -0
  59. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-transform-to-paragraph-strategy.js +63 -0
  60. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/node-replace-selected-text-strategy.js +46 -0
  61. package/dist/collection/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/node-update-text-strategy.js +20 -0
  62. package/dist/collection/components/vega-rich-text-editor/dto/actions/image-update-url-action.js +13 -0
  63. package/dist/collection/components/vega-rich-text-editor/dto/actions/modify-content-action.abstract.js +1 -1
  64. package/dist/collection/components/vega-rich-text-editor/dto/blocks/block.abstract.js +3 -215
  65. package/dist/collection/components/vega-rich-text-editor/dto/blocks/image-block.js +31 -244
  66. package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-block.js +17 -155
  67. package/dist/collection/components/vega-rich-text-editor/dto/blocks/list-item-block.js +33 -184
  68. package/dist/collection/components/vega-rich-text-editor/dto/blocks/text-block.js +40 -352
  69. package/dist/collection/components/vega-rich-text-editor/dto/content-state.js +13 -23
  70. package/dist/collection/components/vega-rich-text-editor/dto/nodes/image-node.js +14 -6
  71. package/dist/collection/components/vega-rich-text-editor/dto/nodes/text-node.js +23 -182
  72. package/dist/collection/components/vega-rich-text-editor/slimmers/renderers/tools/image-toolbar-button-slimmer.js +2 -1
  73. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/action-handle-strategy-registry.test.js +41 -0
  74. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/block-insert-line-break-with-blocks-strategy.test.js +24 -0
  75. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/content-state-strategy-registry.test.js +14 -0
  76. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-block-strategy-register.test.js +30 -0
  77. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-set-annotation-map-strategy.test.js +11 -0
  78. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-update-url-strategy.test.js +16 -0
  79. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/list-block-strategy-register.test.js +20 -0
  80. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/list-item-strategy-register.test.js +31 -0
  81. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/node-split-text-strategy.test.js +31 -0
  82. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/node-update-annotation-map-strategy.test.js +17 -0
  83. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/text-block-strategy-register.test.js +55 -0
  84. package/dist/collection/components/vega-rich-text-editor/test/dto/action-handle-strategies/update-selected-text-strategy.test.js +23 -0
  85. package/dist/collection/components/vega-rich-text-editor/vega-rich-text-editor.js +2 -2
  86. package/dist/collection/helpers/validator/rules/valid-phone-number-rule.js +7 -2
  87. package/dist/collection/helpers/validator/test/rules/valid-phone-number-rule.test.js +8 -0
  88. package/dist/esm/{app-globals-4cca4a96.js → app-globals-c954167a.js} +2 -3
  89. package/dist/esm/content-state-2edba4ec.js +6600 -0
  90. package/dist/esm/{form-field-controller-slimmer-3535e76a.js → form-field-controller-slimmer-7a9f2b2e.js} +1 -1
  91. package/dist/esm/{image-annotation-action-3da42221.js → image-annotation-action-b6668f48.js} +1 -2
  92. package/dist/esm/{index-6e05b241.js → index-d172bafa.js} +1 -1
  93. package/dist/esm/index.js +5 -6
  94. package/dist/esm/loader.js +9 -10
  95. package/dist/esm/{string-input-formatter-slimmer-d4132497.js → string-input-formatter-slimmer-418b54f0.js} +2 -2
  96. package/dist/esm/{sub-state-notify-slimmer-51151fc3.js → sub-state-notify-slimmer-b36fd081.js} +1 -1
  97. package/dist/esm/{sub-state-observer-slimmer-d77a1c46.js → sub-state-observer-slimmer-09452523.js} +1 -1
  98. package/dist/esm/vega-button-group_2.entry.js +3 -3
  99. package/dist/esm/vega-calendar_3.entry.js +3 -3
  100. package/dist/esm/vega-checkbox_2.entry.js +2 -2
  101. package/dist/esm/vega-color-picker.entry.js +2 -2
  102. package/dist/esm/vega-combo-box.entry.js +2 -2
  103. package/dist/esm/vega-date-picker_2.entry.js +5 -5
  104. package/dist/esm/vega-dropdown_5.entry.js +3 -3
  105. package/dist/esm/vega-env-manager-8f8dc473.js +2 -2
  106. package/dist/esm/vega-file-uploader.entry.js +2 -2
  107. package/dist/esm/vega-form.entry.js +2 -2
  108. package/dist/esm/vega-image-uploader.entry.js +2 -2
  109. package/dist/esm/vega-input-credit-card.entry.js +2 -2
  110. package/dist/esm/vega-input-numeric.entry.js +3 -3
  111. package/dist/esm/vega-input-phone-number.entry.js +33 -9
  112. package/dist/esm/vega-input-range.entry.js +2 -2
  113. package/dist/esm/vega-input-select.entry.js +2 -2
  114. package/dist/esm/vega-input.entry.js +5 -5
  115. package/dist/esm/{vega-internal-event-id-d0690d0d.js → vega-internal-event-id-f269c42f.js} +1 -1
  116. package/dist/esm/vega-left-nav_5.entry.js +3 -3
  117. package/dist/esm/vega-popover_2.entry.js +15 -1
  118. package/dist/esm/vega-radio_2.entry.js +2 -2
  119. package/dist/esm/vega-rich-text-content.entry.js +6 -7
  120. package/dist/esm/vega-rich-text-editor_4.entry.js +21 -25
  121. package/dist/esm/vega-selection-chip_2.entry.js +4 -4
  122. package/dist/esm/vega-selection-tile_2.entry.js +4 -4
  123. package/dist/esm/vega-sidenav_3.entry.js +3 -3
  124. package/dist/esm/vega-signature-capture.entry.js +2 -2
  125. package/dist/esm/vega-stepper.entry.js +2 -2
  126. package/dist/esm/vega-table_8.entry.js +3 -3
  127. package/dist/esm/vega-textarea.entry.js +2 -2
  128. package/dist/esm/vega-time-picker_2.entry.js +2 -2
  129. package/dist/esm/vega-toggle-switch.entry.js +2 -2
  130. package/dist/esm/vega.js +9 -10
  131. package/dist/types/components/vega-input-phone-number/slimmers/controllers/vega-input-phone-number-value-controller.d.ts +7 -0
  132. package/dist/types/components/vega-popover/slimmers/controllers/vega-popover-appender-controller.d.ts +1 -0
  133. package/dist/types/components/vega-popover/vega-popover.d.ts +10 -0
  134. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/action-handle-strategy-registry.d.ts +37 -0
  135. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/action-handle-strategy.abstract.d.ts +66 -0
  136. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/block-update-link-group-strategy.d.ts +15 -0
  137. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/block-update-text-style-strategy.d.ts +15 -0
  138. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/image-set-annotation-map-strategy.d.ts +13 -0
  139. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/node-split-text-strategy.d.ts +47 -0
  140. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/apply-annotation-strategies/node-update-annotation-map-strategy.d.ts +15 -0
  141. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-append-blocks-strategy.d.ts +13 -0
  142. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-append-nodes-strategy.d.ts +16 -0
  143. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-image-strategy.d.ts +19 -0
  144. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-node-content-strategy.d.ts +61 -0
  145. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-delete-text-content-strategy.d.ts +19 -0
  146. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-blocks-after-strategy.d.ts +13 -0
  147. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-blocks-before-strategy.d.ts +23 -0
  148. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-image-into-text-strategy.d.ts +15 -0
  149. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-line-break-strategy.d.ts +30 -0
  150. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-line-break-with-blocks-strategy.d.ts +36 -0
  151. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-new-paragraph-strategy.d.ts +29 -0
  152. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-nodes-after-node-strategy.d.ts +13 -0
  153. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-insert-nodes-before-node-strategy.d.ts +13 -0
  154. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-merge-nodes-strategy.d.ts +16 -0
  155. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-remove-child-block-strategy.d.ts +13 -0
  156. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-remove-node-strategy.d.ts +17 -0
  157. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-replace-node-with-nodes-strategy.d.ts +20 -0
  158. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-replace-nodes-strategy.d.ts +16 -0
  159. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-split-with-image-node-strategy.d.ts +30 -0
  160. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-split-with-text-node-strategy.d.ts +24 -0
  161. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/block-transform-to-list-strategy.d.ts +15 -0
  162. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-block-insert-image-strategy.d.ts +12 -0
  163. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-line-break-strategy.d.ts +15 -0
  164. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-line-break-with-blocks-strategy.d.ts +27 -0
  165. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-insert-new-paragraph-strategy.d.ts +21 -0
  166. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/image-update-url-strategy.d.ts +12 -0
  167. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-insert-image-strategy.d.ts +15 -0
  168. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-delete-text-content-strategy.d.ts +15 -0
  169. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-insert-image-strategy.d.ts +15 -0
  170. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-insert-new-paragraph-strategy.d.ts +38 -0
  171. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-remove-nest-list-strategy.d.ts +15 -0
  172. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-remove-node-strategy.d.ts +15 -0
  173. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-item-replace-nest-list-strategy.d.ts +12 -0
  174. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-remove-list-item-strategy.d.ts +15 -0
  175. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-transform-to-list-strategy.d.ts +12 -0
  176. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/list-transform-to-paragraph-strategy.d.ts +19 -0
  177. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/node-replace-selected-text-strategy.d.ts +20 -0
  178. package/dist/types/components/vega-rich-text-editor/dto/action-handle-strategies/modify-content-strategies/node-update-text-strategy.d.ts +15 -0
  179. package/dist/types/components/vega-rich-text-editor/dto/actions/image-update-url-action.d.ts +11 -0
  180. package/dist/types/components/vega-rich-text-editor/dto/actions/modify-content-action.abstract.d.ts +2 -2
  181. package/dist/types/components/vega-rich-text-editor/dto/blocks/block.abstract.d.ts +1 -79
  182. package/dist/types/components/vega-rich-text-editor/dto/blocks/image-block.d.ts +3 -77
  183. package/dist/types/components/vega-rich-text-editor/dto/blocks/list-block.d.ts +0 -38
  184. package/dist/types/components/vega-rich-text-editor/dto/blocks/list-item-block.d.ts +3 -58
  185. package/dist/types/components/vega-rich-text-editor/dto/blocks/text-block.d.ts +5 -93
  186. package/dist/types/components/vega-rich-text-editor/dto/content-state.d.ts +1 -2
  187. package/dist/types/components/vega-rich-text-editor/dto/nodes/text-node.d.ts +0 -43
  188. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/action-handle-strategy-registry.test.d.ts +1 -0
  189. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/block-insert-line-break-with-blocks-strategy.test.d.ts +1 -0
  190. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/content-state-strategy-registry.test.d.ts +1 -0
  191. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-block-strategy-register.test.d.ts +1 -0
  192. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-set-annotation-map-strategy.test.d.ts +1 -0
  193. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/image-update-url-strategy.test.d.ts +1 -0
  194. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/list-block-strategy-register.test.d.ts +1 -0
  195. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/list-item-strategy-register.test.d.ts +1 -0
  196. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/node-split-text-strategy.test.d.ts +1 -0
  197. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/node-update-annotation-map-strategy.test.d.ts +1 -0
  198. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/text-block-strategy-register.test.d.ts +1 -0
  199. package/dist/types/components/vega-rich-text-editor/test/dto/action-handle-strategies/update-selected-text-strategy.test.d.ts +1 -0
  200. package/dist/types/components.d.ts +14 -0
  201. package/dist/types/helpers/validator/rules/valid-phone-number-rule.d.ts +3 -1
  202. package/dist/vega/index.esm.js +1 -1
  203. package/dist/vega/{p-ba077ca8.entry.js → p-073beb31.entry.js} +1 -1
  204. package/dist/vega/{p-6419e13e.entry.js → p-0b697841.entry.js} +1 -1
  205. package/dist/vega/p-0cc1ad76.js +1 -0
  206. package/dist/vega/{p-29d6ec6c.js → p-239bae84.js} +1 -1
  207. package/dist/vega/{p-7198d675.entry.js → p-24ac5151.entry.js} +1 -1
  208. package/dist/vega/{p-cb4fd6e1.entry.js → p-257b1bc2.entry.js} +1 -1
  209. package/dist/vega/{p-ba2833c0.entry.js → p-3c85a11b.entry.js} +1 -1
  210. package/dist/vega/{p-b517ed15.js → p-49bf2b3a.js} +1 -1
  211. package/dist/vega/p-4a8db510.entry.js +1 -0
  212. package/dist/vega/p-4b19706c.entry.js +1 -0
  213. package/dist/vega/{p-bf4996d5.entry.js → p-4e436842.entry.js} +1 -1
  214. package/dist/vega/{p-12fe63c1.entry.js → p-59834ea4.entry.js} +1 -1
  215. package/dist/vega/{p-50eabdca.entry.js → p-59cfed37.entry.js} +1 -1
  216. package/dist/vega/p-5f377954.js +1 -1
  217. package/dist/vega/p-60e1ebe1.entry.js +1 -0
  218. package/dist/vega/{p-23fd9401.entry.js → p-629bd266.entry.js} +1 -1
  219. package/dist/vega/p-6408d3dc.entry.js +1 -0
  220. package/dist/vega/{p-3e8f9fcf.entry.js → p-64e0c944.entry.js} +1 -1
  221. package/dist/vega/{p-b9a0f136.entry.js → p-64e49394.entry.js} +1 -1
  222. package/dist/vega/p-6e5db02b.js +1 -0
  223. package/dist/vega/{p-9689ad99.entry.js → p-74ff73d6.entry.js} +1 -1
  224. package/dist/vega/{p-b809f3d7.entry.js → p-8120e7a1.entry.js} +1 -1
  225. package/dist/vega/p-894c067a.entry.js +1 -0
  226. package/dist/vega/{p-e9785742.entry.js → p-989b36a2.entry.js} +1 -1
  227. package/dist/vega/{p-a2a34239.entry.js → p-9ee23f34.entry.js} +1 -1
  228. package/dist/vega/{p-34bd9204.js → p-a9e1123a.js} +1 -1
  229. package/dist/vega/{p-267cde46.entry.js → p-b071be5c.entry.js} +1 -1
  230. package/dist/vega/{p-1b67c443.entry.js → p-b6bffdf3.entry.js} +1 -1
  231. package/dist/vega/{p-20326c64.js → p-bd0116f9.js} +1 -1
  232. package/dist/vega/{p-a7e078ac.entry.js → p-bf6d3c00.entry.js} +1 -1
  233. package/dist/vega/{p-ecaf4cfa.entry.js → p-c00fde35.entry.js} +1 -1
  234. package/dist/vega/{p-7baa4fae.entry.js → p-c2e96537.entry.js} +1 -1
  235. package/dist/vega/{p-3cb90bdf.entry.js → p-ce94a9c5.entry.js} +1 -1
  236. package/dist/vega/{p-904b489a.entry.js → p-d03945cb.entry.js} +1 -1
  237. package/dist/vega/p-d2e6090a.js +1 -0
  238. package/dist/vega/{p-348e95ba.js → p-d2ff56d8.js} +1 -1
  239. package/dist/vega/p-e0d3ca2d.js +1 -0
  240. package/dist/vega/{p-ee2e4bff.entry.js → p-ea78ddfa.entry.js} +1 -1
  241. package/dist/vega/{p-e9a5bd12.entry.js → p-f1ebe86b.entry.js} +1 -1
  242. package/dist/vega/{p-497f2f86.entry.js → p-fc49a98e.entry.js} +1 -1
  243. package/dist/vega/vega.esm.js +1 -1
  244. package/package.json +1 -1
  245. package/dist/cjs/content-state-f97d3278.js +0 -2990
  246. package/dist/cjs/node-annotation.abstract-4f6df9cf.js +0 -3223
  247. package/dist/collection/components/vega-rich-text-editor/dto/actions/clear-child-nodes-action.js +0 -12
  248. package/dist/collection/components/vega-rich-text-editor/dto/helper/block-base-operator.js +0 -47
  249. package/dist/esm/content-state-ccf5f960.js +0 -2954
  250. package/dist/esm/node-annotation.abstract-b2e36bc4.js +0 -3214
  251. package/dist/types/components/vega-rich-text-editor/dto/actions/clear-child-nodes-action.d.ts +0 -9
  252. package/dist/types/components/vega-rich-text-editor/dto/helper/block-base-operator.d.ts +0 -24
  253. package/dist/vega/p-0461e318.js +0 -1
  254. package/dist/vega/p-1d93b3a9.js +0 -1
  255. package/dist/vega/p-2fecbcf9.entry.js +0 -1
  256. package/dist/vega/p-52a8a4f8.js +0 -1
  257. package/dist/vega/p-7edcb8d0.entry.js +0 -1
  258. package/dist/vega/p-9728d571.entry.js +0 -1
  259. package/dist/vega/p-a7f40a65.entry.js +0 -1
  260. package/dist/vega/p-a8b16ff2.js +0 -1
  261. package/dist/vega/p-aed80794.entry.js +0 -1
  262. package/dist/vega/p-f86ec91b.js +0 -1
@@ -1,2990 +0,0 @@
1
- 'use strict';
2
-
3
- const nodeAnnotation_abstract = require('./node-annotation.abstract-4f6df9cf.js');
4
- const changeManager = require('./change-manager-a297e4d2.js');
5
- const domNodeSubjectFactory = require('./dom-node-subject-factory-ce1777a9.js');
6
- const vegaInternalEventId = require('./vega-internal-event-id-bda63e14.js');
7
- const typeGuard = require('./type-guard-4ba85fdc.js');
8
- require('./global-slimmer-registry-b3bce7e0.js');
9
- const createPublicApiRuntimeMetricsSlimmer = require('./create-public-api-runtime-metrics-slimmer-54c3f73b.js');
10
-
11
- /**
12
- * Annotation to make block with horizontal alignment
13
- */
14
- class HorizontalAlignmentAnnotation extends nodeAnnotation_abstract.BlockAnnotation {
15
- constructor(textAlign) {
16
- super();
17
- this.type = nodeAnnotation_abstract.BlockAnnotationTypeEnum.ALIGNMENT;
18
- this.textAlign = textAlign;
19
- }
20
- /**
21
- * Generate the map item for the annotation
22
- *
23
- * @param {VegaRTEBlockAlignment} textAlign - Text alignment
24
- * @returns {[BlockAnnotationTypeEnum.ALIGNMENT, HorizontalAlignmentAnnotation]} Map item for the annotation
25
- */
26
- static from(textAlign) {
27
- return [nodeAnnotation_abstract.BlockAnnotationTypeEnum.ALIGNMENT, new HorizontalAlignmentAnnotation(textAlign)];
28
- }
29
- /**
30
- * Generate the JSON item of the annotation
31
- *
32
- * @returns {Record<string, unknown>} JSON representation of the annotation
33
- */
34
- toJSON() {
35
- return {
36
- textAlign: this.textAlign,
37
- };
38
- }
39
- /**
40
- * Generate the class for the annotation
41
- *
42
- * @returns {string} - Annotation class
43
- */
44
- renderClass() {
45
- return `v-rte--horizontal-alignment-${this.textAlign}`;
46
- }
47
- /**
48
- * Generate the style for the annotation
49
- *
50
- * @returns {Nullable<AnnotationStyle>} - Annotation style
51
- */
52
- render() {
53
- return null;
54
- }
55
- }
56
-
57
- /**
58
- * Annotation for block indentation
59
- */
60
- class IndentAnnotation extends nodeAnnotation_abstract.BlockAnnotation {
61
- constructor(indent) {
62
- super();
63
- this.type = nodeAnnotation_abstract.BlockAnnotationTypeEnum.INDENT;
64
- this.indent = Math.max(0, indent);
65
- }
66
- /**
67
- * Generate the map item for the annotation
68
- *
69
- * @param {number} indent - Text alignment
70
- * @returns {[BlockAnnotationTypeEnum.INDENT, IndentAnnotation]} Map item for the annotation
71
- */
72
- static from(indent) {
73
- return [nodeAnnotation_abstract.BlockAnnotationTypeEnum.INDENT, new IndentAnnotation(indent)];
74
- }
75
- /**
76
- * Generate the JSON item of the annotation
77
- *
78
- * @returns {Record<string, unknown>} JSON representation of the annotation
79
- */
80
- toJSON() {
81
- return this.indent > 0 ? { indent: this.indent } : null;
82
- }
83
- /**
84
- * Generate the style for the annotation
85
- *
86
- * @returns {Nullable<AnnotationStyle>} - Annotation style
87
- */
88
- render() {
89
- return this.indent > 0 ? { 'margin-left': `${this.indent * 16}px` } : null;
90
- }
91
- }
92
-
93
- /** The class contains some common method to modify the blocks property */
94
- class BlockBaseOperator {
95
- /**
96
- * Replaces a specific block with an array of blocks within a RTEContentBlock array.
97
- *
98
- * @param {RTEBlock} referBlock - Used as a reference block to identify the block that needs to be replaced in the `blocks` array.
99
- * @param {RTEBlock[]} blocks - An array of RTEBlock objects that you want to replace the `referBlock` with in the `blocks` array.
100
- */
101
- replaceBlockWithBlocks(referBlock, blocks) {
102
- if (this.blocks) {
103
- blocks.forEach((block) => {
104
- block.parent = this;
105
- });
106
- this.blocks = this.blocks.flatMap((block) => {
107
- if (block === referBlock) {
108
- return blocks;
109
- }
110
- else {
111
- return block;
112
- }
113
- });
114
- }
115
- }
116
- /**
117
- * Appends new blocks to an array and sets their parent property to a specific type.
118
- *
119
- * @param {RTEBlock[]} newBlocks - An array of `RTEBlock` objects that are being passed to the `appendChildBlocks` method.
120
- */
121
- appendChildBlocks(newBlocks) {
122
- if (this.blocks) {
123
- newBlocks.forEach((block) => {
124
- block.parent = this;
125
- });
126
- this.blocks = this.blocks.concat(newBlocks);
127
- }
128
- }
129
- /**
130
- * Removes a specified RTEBlock from an array of blocks.
131
- *
132
- * @param {RTEBlock} blockToBeRemoved - The block that needs to be removed from the `blocks` array.
133
- */
134
- removeChildBlock(blockToBeRemoved) {
135
- if (this.blocks) {
136
- this.blocks = this.blocks.filter((block) => block !== blockToBeRemoved);
137
- }
138
- }
139
- }
140
-
141
- /** Append blocks or nodes to a block */
142
- class AppendChildNodesAction extends nodeAnnotation_abstract.ModifyContentAction {
143
- constructor(childNodes) {
144
- super();
145
- this.type = nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES;
146
- this.entityToBeAppended = childNodes;
147
- }
148
- }
149
-
150
- /**
151
- * Delete child node or child block from the current list action
152
- *
153
- * @example needRemovedNode.parentBlock.apply(new RemoveChildAction(needRemovedNode))
154
- * @example needRemovedBlock.parent.apply(new RemoveChildAction(needRemovedBlock))
155
- */
156
- class RemoveChildAction extends nodeAnnotation_abstract.ModifyContentAction {
157
- constructor(childNode) {
158
- super();
159
- this.type = nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD;
160
- this.entityToBeRemoved = childNode;
161
- }
162
- }
163
-
164
- const RTE_TEXT_COLORS = [
165
- {
166
- key: 'black',
167
- light: '#111128',
168
- dark: '#E3E3E8',
169
- },
170
- {
171
- key: 'gray',
172
- light: '#5E5E6D',
173
- dark: '#B9B9C1',
174
- },
175
- {
176
- key: 'green',
177
- light: '#01801F',
178
- dark: '#59D977',
179
- },
180
- {
181
- key: 'red',
182
- light: '#BD2947',
183
- dark: '#FFB2B5',
184
- },
185
- {
186
- key: 'purple',
187
- light: '#563D82',
188
- dark: '#BEB2FF',
189
- },
190
- {
191
- key: 'teal',
192
- light: '#17758F',
193
- dark: '#4CD8FF',
194
- },
195
- ];
196
- const ZERO_WIDTH_SPACE = '\u200b';
197
-
198
- /**
199
- * Abstract class for block
200
- */
201
- class RTEBlock extends BlockBaseOperator {
202
- constructor(id) {
203
- super();
204
- this.annotationMap = new Map();
205
- this.id = id;
206
- }
207
- /**
208
- * The function `createAnnotationEntity` creates a block annotation entity based on the provided type
209
- * and value.
210
- *
211
- * @param {keyof VegaRTEBlockAnnotations} type - The `type` parameter is a key of the `VegaRTEBlockAnnotations` enum, which specifies
212
- * the type of annotation entity to create.
213
- * @param {unknown} value - The `value` parameter in the `createAnnotationEntity` function is the value
214
- * that will be used to create the annotation entity. It can be of any type depending on the specific
215
- * annotation being created.
216
- * @returns {Nullable<[BlockAnnotationTypeEnum, BlockAnnotation]>} The `createAnnotationEntity` function returns a nullable tuple containing a
217
- * `BlockAnnotationTypeEnum` and a `BlockAnnotation` object.
218
- */
219
- static createAnnotationEntity(type, value) {
220
- switch (type) {
221
- case 'textAlign':
222
- return HorizontalAlignmentAnnotation.from(value);
223
- case 'indent':
224
- return IndentAnnotation.from(value);
225
- }
226
- }
227
- /**
228
- * Class to JSON object
229
- *
230
- * @returns {VegaRTEBlockBase} - JSON object
231
- */
232
- toJSON() {
233
- const annotations = Array.from(this.annotationMap.values())
234
- .filter((annotation) => annotation instanceof nodeAnnotation_abstract.BlockAnnotation)
235
- .reduce((record, annotation) => {
236
- return Object.assign(Object.assign({}, record), annotation.toJSON());
237
- }, {});
238
- return Object.assign({ id: this.id }, (Object.keys(annotations).length > 0 ? { annotations } : {}));
239
- }
240
- /**
241
- * Get annotation by type
242
- *
243
- * @param {keyof typeof BlockAnnotationTypeEnum} type - Annotation type
244
- * @returns {Nullable<BlockAnnotation> | Nullable<LinkGroupAnnotation>} - Annotation
245
- */
246
- getAnnotationByType(type) {
247
- return this.annotationMap.get(type);
248
- }
249
- /**
250
- * Apply action to block
251
- *
252
- * @param {AnnotationAction} action - Annotation action
253
- */
254
- apply(action) {
255
- this.doApply(action);
256
- if (action.isFlushable) {
257
- const domNode = nodeAnnotation_abstract.stateEntityRenderingRegistry.getDOMByEntity(this);
258
- if (domNode) {
259
- const nodeSubject = domNodeSubjectFactory.domNodeSubjectFactory.getSubjectFromParentNodeByEventId(domNode, vegaInternalEventId.VegaInternalRichTextEditorFlushChanges);
260
- if (nodeSubject) {
261
- changeManager.ChangeManager.notify(nodeSubject, {});
262
- }
263
- }
264
- }
265
- }
266
- /**
267
- * Apply action to block
268
- *
269
- * @param {AnnotationAction|ModifyContentAction} action - Annotation action
270
- */
271
- doApply(action) {
272
- if (action instanceof nodeAnnotation_abstract.ModifyContentAction) {
273
- this.doModifyActionApply(action);
274
- }
275
- else {
276
- this.applyAnnotationAction(action);
277
- }
278
- }
279
- /**
280
- * Apply annotation action to block
281
- *
282
- * @param {AnnotationAction} action - Annotation action
283
- */
284
- applyAnnotationAction(action) {
285
- const annotation = action.toAnnotation();
286
- this.annotationMap.set(annotation.type, annotation);
287
- typeof this.doAnnotationActionApply === 'function' && this.doAnnotationActionApply(action);
288
- }
289
- /**
290
- * Appends a list of RTENode objects to the current node's child nodes and sets the parent block of each node to the current node.
291
- *
292
- * @param {RTENode[]} nodesToBeAppended - An array of `RTENode` objects that you want to append to the current block.
293
- */
294
- appendChildNodes(nodesToBeAppended) {
295
- nodesToBeAppended.forEach((node) => {
296
- node.parentBlock = this;
297
- });
298
- this['nodes'] = this['nodes'].concat(nodesToBeAppended);
299
- }
300
- /**
301
- * Merges the child nodes of two RTEBlocks if they have the same type or both are not images.
302
- *
303
- * @param {RTEBlock} secondBlock - A block of content in a rich text editor, such as a paragraph, heading, image, etc.
304
- */
305
- mergeTwoBlocksNodes(secondBlock) {
306
- if (this.type === secondBlock.type || (this.type !== 'image' && secondBlock.type !== 'image')) {
307
- let shouldMergeNodes = secondBlock['nodes'];
308
- if (this.type !== 'image') {
309
- shouldMergeNodes = secondBlock['nodes'].filter((node) => node['text'] && node['text'] !== ZERO_WIDTH_SPACE);
310
- }
311
- this.apply(new AppendChildNodesAction(shouldMergeNodes));
312
- secondBlock.parent.apply(new RemoveChildAction(secondBlock));
313
- }
314
- }
315
- /**
316
- * Concat the child nodes of multiple RTEBlocks if both are not images.
317
- *
318
- * @param {RTEBlock[]} blocks - multiple block of content in a rich text editor, such as a paragraph, heading, image, etc.
319
- * @returns {RTENode[]} Array of connected block nodes
320
- */
321
- concatBlocksNodes(blocks) {
322
- const nodes = [];
323
- blocks.map((block) => {
324
- if (block.type !== 'image') {
325
- nodes.push(...block['nodes']);
326
- block.parent.apply(new RemoveChildAction(block));
327
- }
328
- });
329
- return nodes;
330
- }
331
- /**
332
- * Returns the previous node relative to the current node in a rich text editor structure.
333
- *
334
- * @param {RTENode} currentNode - An object of type `RTENode`.
335
- * @returns {Nullable<RTENode>} the previous block last node
336
- */
337
- getPreviousNode(currentNode) {
338
- const currentBlock = currentNode.parentBlock;
339
- const currentIndex = currentBlock['nodes'].indexOf(currentNode);
340
- if (currentIndex > 0) {
341
- return currentBlock['nodes'][currentIndex - 1];
342
- }
343
- else if (currentBlock.parent) {
344
- const previousBlock = this.getPreviousBlock(currentBlock);
345
- if (previousBlock) {
346
- return this.getBlockLastNode(previousBlock);
347
- }
348
- }
349
- }
350
- /**
351
- * Returns the next node relative to the current node in a rich text editor structure.
352
- *
353
- * @param {RTENode} currentNode - An object of type `RTENode`.
354
- * @returns {Nullable<RTENode>} the next block first node
355
- */
356
- getNextNode(currentNode) {
357
- const currentBlock = currentNode.parentBlock;
358
- const currentIndex = currentBlock['nodes'].indexOf(currentNode);
359
- if (currentBlock['nodes'][currentIndex + 1]) {
360
- return currentBlock['nodes'][currentIndex + 1];
361
- }
362
- else if (currentBlock.parent) {
363
- const nextBlock = this.getNextBlock(currentBlock);
364
- if (nextBlock) {
365
- return this.getBlockFirstNode(nextBlock);
366
- }
367
- }
368
- }
369
- /**
370
- * Determines if a given node is the first node within the current state.
371
- *
372
- * @param {RTENode} currentNode - An object representing a node in a rich text editor (RTE).
373
- * @returns {boolean} True or false;
374
- */
375
- isContentFirstNode(currentNode) {
376
- const currentBlock = currentNode.parentBlock;
377
- const currentIndex = currentBlock['nodes'].indexOf(currentNode);
378
- const parent = currentBlock.parent;
379
- if (currentBlock.type === 'list-item') {
380
- const listParent = parent.parent;
381
- return (currentIndex === 0 &&
382
- Array.isArray(parent.blocks) &&
383
- parent.blocks[0] === currentBlock &&
384
- listParent['type'] !== 'list-item' &&
385
- Array.isArray(listParent.blocks) &&
386
- listParent.blocks[0] === parent);
387
- }
388
- else {
389
- return currentIndex === 0 && Array.isArray(parent.blocks) && parent.blocks[0] === currentBlock;
390
- }
391
- }
392
- /**
393
- * Returns the last node within a given RTE block, handling different block types accordingly.
394
- *
395
- * @param {RTEBlock} currentBlock - Returns the last node within that block.
396
- * @returns {Nullable<RTENode>} Returns the last node of the given `currentBlock` object.
397
- */
398
- getBlockLastNode(currentBlock) {
399
- if (currentBlock.type === 'list-item') {
400
- if (currentBlock['children'] && currentBlock['children'].length > 0) {
401
- return this.getBlockLastNode(currentBlock['children'][currentBlock['children'].length - 1]);
402
- }
403
- else {
404
- return currentBlock['nodes'][currentBlock['nodes'].length - 1];
405
- }
406
- }
407
- else if (currentBlock.type === 'number-list' || currentBlock.type === 'bullet-list') {
408
- if (currentBlock.blocks) {
409
- const lastListItem = currentBlock.blocks[currentBlock.blocks.length - 1];
410
- return this.getBlockLastNode(lastListItem);
411
- }
412
- }
413
- else {
414
- if (currentBlock['nodes']) {
415
- return currentBlock['nodes'][currentBlock['nodes'].length - 1];
416
- }
417
- }
418
- }
419
- /**
420
- * Returns the first node within a given RTE block, handling different block types accordingly.
421
- *
422
- * @param {RTEBlock} currentBlock - Returns the first node within that block.
423
- * @returns {Nullable<RTENode>} Returns the first node of the given `currentBlock` object.
424
- */
425
- getBlockFirstNode(currentBlock) {
426
- if (currentBlock.type === 'number-list' || currentBlock.type === 'bullet-list') {
427
- if (currentBlock.blocks) {
428
- const firstListItem = currentBlock.blocks[0];
429
- return this.getBlockFirstNode(firstListItem);
430
- }
431
- }
432
- else {
433
- if (currentBlock['nodes']) {
434
- return currentBlock['nodes'][0];
435
- }
436
- }
437
- }
438
- /**
439
- * TODO: The getPreviousBlock add nest list support
440
- * This function retrieves the previous block in a rich text editor, considering different scenarios such as being in a bullet list.
441
- *
442
- * @param {RTEBlock} currentBlock - Used to retrieve the previous block relative to the given `currentBlock` within a rich text editor context.
443
- * @returns {Nullable<RTEBlock>} The previous block if existing
444
- */
445
- getPreviousBlock(currentBlock) {
446
- if (currentBlock && currentBlock.parent && currentBlock.parent.blocks) {
447
- const currentBlockIndex = currentBlock.parent.blocks.indexOf(currentBlock);
448
- if (currentBlockIndex > 0) {
449
- return currentBlock.parent.blocks[currentBlockIndex - 1];
450
- }
451
- else if ((currentBlock.parent['type'] === 'number-list' ||
452
- currentBlock.parent['type'] === 'bullet-list') &&
453
- currentBlockIndex === 0) {
454
- return this.getPreviousBlock(currentBlock.parent);
455
- }
456
- }
457
- }
458
- /**
459
- * This function retrieves the next block in a rich text editor, considering different scenarios such as being in a bullet list.
460
- *
461
- * @param {RTEBlock} currentBlock - Used to retrieve the next block relative to the given `currentBlock` within a rich text editor context.
462
- * @returns {Nullable<RTEBlock>} The next block if existing
463
- */
464
- getNextBlock(currentBlock) {
465
- if (currentBlock && currentBlock.parent && currentBlock.parent.blocks) {
466
- const currentBlockIndex = currentBlock.parent.blocks.indexOf(currentBlock);
467
- if (currentBlock.parent.blocks[currentBlockIndex + 1]) {
468
- return currentBlock.parent.blocks[currentBlockIndex + 1];
469
- }
470
- else if (currentBlock.type === 'list-item' &&
471
- currentBlock.parent.blocks.length === currentBlockIndex + 1) {
472
- return this.getNextBlock(currentBlock.parent);
473
- }
474
- }
475
- }
476
- /**
477
- * Replaces a specific node with an array of nodes within a RTENode array.
478
- *
479
- * @param {RTENode} referNode - Used as a reference node to identify the node that needs to be replaced in the `nodes` array.
480
- * @param {RTENode[]} nodes - An array of RTENode objects that you want to replace the `referNode` with in the `nodes` array.
481
- */
482
- replaceNodeWithNodes(referNode, nodes) {
483
- if (this['nodes']) {
484
- nodes.forEach((node) => {
485
- node.parentBlock = this;
486
- });
487
- this['nodes'] = this['nodes'].flatMap((node) => {
488
- if (node === referNode) {
489
- return nodes;
490
- }
491
- else {
492
- return node;
493
- }
494
- });
495
- }
496
- }
497
- }
498
-
499
- /**
500
- * Annotation for image
501
- */
502
- class ImageAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
503
- constructor(size = 'md', alt) {
504
- super();
505
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.IMAGE;
506
- this.size = size;
507
- this.alt = alt;
508
- }
509
- /**
510
- * Generate the map item for the annotation
511
- *
512
- * @param {string} size - Image size
513
- * @param {string} alt - Image alt
514
- * @returns {[NodeAnnotationTypeEnum.IMAGE, ImageAnnotation]} Map item for the annotation
515
- */
516
- static from(size, alt) {
517
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.IMAGE, new ImageAnnotation(size, alt)];
518
- }
519
- /**
520
- * Generate the JSON representation of the annotation
521
- *
522
- * @returns {Nullable<Record<string, unknown>>} JSON representation of the annotation
523
- */
524
- toJSON() {
525
- return typeGuard.isNonNullable(this.alt)
526
- ? {
527
- size: this.size,
528
- alt: this.alt,
529
- }
530
- : {
531
- size: this.size,
532
- };
533
- }
534
- /**
535
- * Generate the style for the image
536
- *
537
- * @returns {Nullable<AnnotationStyle>} image style
538
- */
539
- render() {
540
- switch (this.size) {
541
- case 'sm': {
542
- return { width: '25%' };
543
- }
544
- case 'md': {
545
- return { width: '50%' };
546
- }
547
- case 'lg': {
548
- return { width: '100%' };
549
- }
550
- }
551
- }
552
- }
553
-
554
- /**
555
- * Image node
556
- */
557
- class RTEImageNode extends nodeAnnotation_abstract.RTENode {
558
- constructor(id, url, parentBlock, annotationMap) {
559
- super(id, annotationMap);
560
- this.type = nodeAnnotation_abstract.NodeTypeEnum.IMAGE;
561
- this.url = url;
562
- this.parentBlock = parentBlock;
563
- }
564
- /**
565
- * Converts a VegaRTEImageNode into an RTEImageNode by mapping nodes and creating annotations.
566
- *
567
- * @param {VegaRTEImageNode} node - The node to be converted.
568
- * @param {RTEImageBlock} parentBlock - The parent block
569
- * @returns {RTEImageBlock} An instance of `RTEImageBlock`
570
- */
571
- static from(node, parentBlock) {
572
- const imageNode = new RTEImageNode(node.id, node.url, parentBlock);
573
- let annotations;
574
- if (!node.annotations || Object.keys(node.annotations).length === 0) {
575
- annotations = { size: 'md' };
576
- }
577
- else {
578
- annotations = node.annotations;
579
- }
580
- imageNode.annotationMap = new Map(Object.keys(annotations)
581
- .map(() => ImageAnnotation.from(annotations.size, annotations.alt))
582
- .filter(typeGuard.isNonNullable));
583
- return imageNode;
584
- }
585
- /**
586
- * @inheritDoc
587
- */
588
- toJSON() {
589
- const imageAnnotation = this.annotationMap.get(nodeAnnotation_abstract.NodeAnnotationTypeEnum.IMAGE);
590
- const annotations = {};
591
- if (imageAnnotation === null || imageAnnotation === void 0 ? void 0 : imageAnnotation.size) {
592
- annotations.size = imageAnnotation.size;
593
- }
594
- if (imageAnnotation === null || imageAnnotation === void 0 ? void 0 : imageAnnotation.alt) {
595
- annotations.alt = imageAnnotation.alt;
596
- }
597
- return Object.assign(Object.assign({ id: this.id }, (Object.keys(annotations).length > 0 ? { annotations } : {})), { type: 'image', url: this.url });
598
- }
599
- /**
600
- * @inheritDoc
601
- */
602
- doAnnotationActionApply(action) {
603
- const annotation = action.toAnnotation();
604
- this.annotationMap.set(annotation.type, annotation);
605
- }
606
- // placeholder method
607
- /* istanbul ignore next */
608
- /**
609
- * @inheritDoc
610
- */
611
- doModifyActionApply(action) {
612
- }
613
- }
614
-
615
- /**
616
- * Clear the current block nodes and append new nodes
617
- *
618
- * @example block.apply(new ReplaceChildNodesAction(newNodes))
619
- */
620
- class ReplaceChildNodesAction extends nodeAnnotation_abstract.ModifyContentAction {
621
- constructor(newChildNodes) {
622
- super();
623
- this.type = nodeAnnotation_abstract.ModifyContentActionType.REPLACE_CHILD_NODES;
624
- this.newChildNodes = newChildNodes;
625
- }
626
- }
627
-
628
- /**
629
- * Insert a new block after a existing block
630
- *
631
- * @example currentBlock.parent.apply(new InsertBlocksAfterAction(currentBlock, newBlock, ...))
632
- */
633
- class InsertBlocksAfterAction extends nodeAnnotation_abstract.ModifyContentAction {
634
- constructor(referBlock, ...blocksToBeInserted) {
635
- super();
636
- this.type = nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_AFTER;
637
- this.referBlock = referBlock;
638
- this.blocksToBeInserted = blocksToBeInserted;
639
- }
640
- }
641
-
642
- /**
643
- * Split the block with a split point node.
644
- * The property `newBlock` use to store the new create block if need.
645
- *
646
- * @example block.apply(new SplitBlockWithNodeAction(node, offset))
647
- */
648
- class SplitBlockWithNodeAction extends nodeAnnotation_abstract.ModifyContentAction {
649
- constructor(splitPointNode, startOffsetOfNode) {
650
- super();
651
- this.type = nodeAnnotation_abstract.ModifyContentActionType.SPLIT_BLOCK_WITH_NODE;
652
- this.splitPointNode = splitPointNode;
653
- this.startOffsetOfNode = startOffsetOfNode;
654
- }
655
- }
656
-
657
- /**
658
- * Abstract class for annotation actions
659
- */
660
- class AnnotationAction {
661
- }
662
-
663
- /**
664
- * Abstract class for which can be splittable
665
- */
666
- class TextSplittableAction extends AnnotationAction {
667
- constructor() {
668
- super(...arguments);
669
- /**
670
- * Whether the action should split the node
671
- */
672
- this.doSplit = true;
673
- }
674
- }
675
-
676
- /**
677
- * Annotation to represent a selection range
678
- */
679
- class SelectionRangeAnnotation extends nodeAnnotation_abstract.Annotation {
680
- constructor(range) {
681
- super();
682
- this.type = nodeAnnotation_abstract.InternalAnnotationTypeEnum.SELECTION_RANGE;
683
- this.range = range;
684
- }
685
- }
686
-
687
- /**
688
- * Annotation to make text with strikethrough
689
- */
690
- class StrikethroughAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
691
- constructor(underline) {
692
- super();
693
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.STRIKETHROUGH;
694
- this.strikethrough = underline;
695
- }
696
- /**
697
- * Generate the map item for the annotation
698
- *
699
- * @param {Nullable<boolean>} strikethrough - Strikethrough annotation
700
- * @returns {[NodeAnnotationTypeEnum.STRIKETHROUGH, StrikethroughAnnotation]} Map item for the annotation
701
- */
702
- static from(strikethrough) {
703
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.STRIKETHROUGH, new StrikethroughAnnotation(strikethrough)];
704
- }
705
- /**
706
- * Generate the JSON representation of the annotation
707
- *
708
- * @returns {Record<string, unknown>} JSON representation of the annotation
709
- */
710
- toJSON() {
711
- return {
712
- strikethrough: this.strikethrough,
713
- };
714
- }
715
- /**
716
- * Generate the class for the annotation
717
- *
718
- * @returns {Nullable<string>} - Annotation class
719
- */
720
- renderClass() {
721
- return this.strikethrough ? 'v-rte--strikethrough' : null;
722
- }
723
- /**
724
- * Generate the style for the annotation
725
- *
726
- * @returns {Nullable<AnnotationStyle>} - Annotation style
727
- */
728
- render() {
729
- return null;
730
- }
731
- }
732
-
733
- /**
734
- * Annotation to make text with underline
735
- */
736
- class UnderlineAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
737
- constructor(underline) {
738
- super();
739
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.UNDERLINE;
740
- this.underline = underline;
741
- }
742
- /**
743
- * Generate the map item for the annotation
744
- *
745
- * @param {boolean} underline - Underline annotation
746
- * @returns {[NodeAnnotationTypeEnum.UNDERLINE, UnderlineAnnotation]} Map item for the annotation
747
- */
748
- static from(underline) {
749
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.UNDERLINE, new UnderlineAnnotation(underline)];
750
- }
751
- /**
752
- * Generate the JSON representation of the annotation
753
- *
754
- * @returns {Record<string, unknown>} JSON representation of the annotation
755
- */
756
- toJSON() {
757
- return {
758
- underline: this.underline,
759
- };
760
- }
761
- /**
762
- * Generate the class for the annotation
763
- *
764
- * @returns {Nullable<string>} - Annotation class
765
- */
766
- renderClass() {
767
- return this.underline ? 'v-rte--underline' : null;
768
- }
769
- /**
770
- * Generate the style for the annotation
771
- *
772
- * @returns {Nullable<AnnotationStyle>} - Annotation style
773
- */
774
- render() {
775
- return null;
776
- }
777
- }
778
-
779
- /**
780
- * Annotation to make text Italic
781
- */
782
- class ItalicAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
783
- constructor(italic) {
784
- super();
785
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.ITALIC;
786
- this.italic = italic;
787
- }
788
- /**
789
- * Generate the map item for the annotation
790
- *
791
- * @param {boolean} italic - Italic annotation
792
- * @returns {Nullable<[NodeAnnotationTypeEnum.ITALIC, ItalicAnnotation]>} Map item for the annotation
793
- */
794
- static from(italic) {
795
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.ITALIC, new ItalicAnnotation(italic)];
796
- }
797
- /**
798
- * Generate the JSON representation of the annotation
799
- *
800
- * @returns {Record<string, unknown>} JSON representation of the annotation
801
- */
802
- toJSON() {
803
- return {
804
- italic: this.italic,
805
- };
806
- }
807
- /**
808
- * Generate the style for the annotation
809
- *
810
- * @returns {Nullable<AnnotationStyle>} Italic style
811
- */
812
- render() {
813
- return this.italic ? { 'font-style': 'italic' } : null;
814
- }
815
- }
816
-
817
- /**
818
- * Annotation to make text bold
819
- */
820
- class BoldAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
821
- constructor(bold) {
822
- super();
823
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.BOLD;
824
- this.bold = bold;
825
- }
826
- /**
827
- * Generate the map item for the annotation
828
- *
829
- * @param {boolean} bold - Bold annotation
830
- * @returns {[NodeAnnotationTypeEnum.BOLD, BoldAnnotation]} Map item for the annotation
831
- */
832
- static from(bold) {
833
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.BOLD, new BoldAnnotation(bold)];
834
- }
835
- /**
836
- * Generate the JSON representation of the annotation
837
- *
838
- * @returns {Record<string, unknown>} JSON representation of the annotation
839
- */
840
- toJSON() {
841
- return {
842
- bold: this.bold,
843
- };
844
- }
845
- /**
846
- * Generate the style for the annotation
847
- *
848
- * @returns {Nullable<AnnotationStyle>} Bold style
849
- */
850
- render() {
851
- return this.bold ? { 'font-weight': '700' } : null;
852
- }
853
- }
854
-
855
- /**
856
- * Annotation to host which annotations will be clear formatting
857
- */
858
- class ClearFormattingAnnotation extends nodeAnnotation_abstract.Annotation {
859
- constructor() {
860
- super(...arguments);
861
- this.type = nodeAnnotation_abstract.InternalAnnotationTypeEnum.CLEAR_FORMATTING;
862
- this.items = [
863
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.BOLD,
864
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.ITALIC,
865
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.UNDERLINE,
866
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.STRIKETHROUGH,
867
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.TEXT_COLOR,
868
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.CODE,
869
- ];
870
- }
871
- }
872
-
873
- /**
874
- * Annotation to make text code
875
- */
876
- class CodeAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
877
- constructor(code) {
878
- super();
879
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.CODE;
880
- this.code = code;
881
- }
882
- /**
883
- * Generate the map item for the annotation
884
- *
885
- * @param {boolean} code - Bold annotation
886
- * @returns {[NodeAnnotationTypeEnum.CODE, CodeAnnotation]} Map item for the annotation
887
- */
888
- static from(code) {
889
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.CODE, new CodeAnnotation(code)];
890
- }
891
- /**
892
- * Generate the JSON representation of the annotation
893
- *
894
- * @returns {Record<string, unknown>} JSON representation of the annotation
895
- */
896
- toJSON() {
897
- return {
898
- code: this.code,
899
- };
900
- }
901
- /**
902
- * Generate the class for the annotation
903
- *
904
- * @returns {Nullable<string>} - Annotation class
905
- */
906
- renderClass() {
907
- return this.code ? 'v-rte--code' : null;
908
- }
909
- /**
910
- * Generate the style for the annotation
911
- *
912
- * @returns {Nullable<AnnotationStyle>} Bold style
913
- */
914
- render() {
915
- return null;
916
- }
917
- }
918
-
919
- /**
920
- * Annotation to make text with text color
921
- */
922
- class TextColorAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
923
- constructor(textColor) {
924
- super();
925
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.TEXT_COLOR;
926
- this.textColor = this.formatTextColor(textColor);
927
- }
928
- /**
929
- * Generate the map item for the annotation
930
- *
931
- * @param {string} textColor - text color annotation
932
- * @returns {[NodeAnnotationTypeEnum.TEXT_COLOR, TextColorAnnotation]} Map item for the annotation
933
- */
934
- static from(textColor) {
935
- return [nodeAnnotation_abstract.NodeAnnotationTypeEnum.TEXT_COLOR, new TextColorAnnotation(textColor)];
936
- }
937
- /**
938
- * Generate the JSON representation of the annotation
939
- *
940
- * @returns {Record<string, unknown>} JSON representation of the annotation
941
- */
942
- toJSON() {
943
- return {
944
- textColor: this.textColor.key,
945
- };
946
- }
947
- /**
948
- * Generate the class for the annotation
949
- *
950
- * @returns {Nullable<string>} - Annotation class
951
- */
952
- renderClass() {
953
- return null;
954
- }
955
- /**
956
- * Generate the style for the annotation
957
- *
958
- * @returns {Nullable<AnnotationStyle>} - Annotation style
959
- */
960
- render() {
961
- return {
962
- color: nodeAnnotation_abstract.VegaThemeManager.isDarkMode() ? this.textColor.dark : this.textColor.light,
963
- };
964
- }
965
- /**
966
- * format text color
967
- *
968
- * @param {string} textColor - text color
969
- * @returns {VegaRTEColorSchema} - VegaRTEColorSchema
970
- */
971
- formatTextColor(textColor) {
972
- return (RTE_TEXT_COLORS.find((item) => item.key === textColor) || RTE_TEXT_COLORS[0]);
973
- }
974
- }
975
-
976
- /**
977
- * Annotation to make text a link
978
- */
979
- class LinkAnnotation extends nodeAnnotation_abstract.NodeAnnotation {
980
- constructor(link) {
981
- super();
982
- this.type = nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK;
983
- this.link = link;
984
- }
985
- /**
986
- * Generate the map item for the annotation
987
- *
988
- * @param {VegaRTELink} link - Bold annotation
989
- * @returns {[NodeAnnotationTypeEnum.LINK, LinkAnnotation]} Map item for the annotation
990
- */
991
- static from(link) {
992
- return [
993
- nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK,
994
- new LinkAnnotation({ href: link.href, groupKey: link.groupKey }),
995
- ];
996
- }
997
- /**
998
- * Generate the JSON representation of the annotation
999
- *
1000
- * @returns {Record<string, unknown>} JSON representation of the annotation
1001
- */
1002
- toJSON() {
1003
- return { link: { href: this.link.href, groupKey: this.link.groupKey } };
1004
- }
1005
- /**
1006
- * Verify whether two link annotation is same or not
1007
- *
1008
- * @param {LinkAnnotation} annotation - Compared annotation
1009
- * @returns {boolean} Whether two link annotation is same or not
1010
- */
1011
- toEqual(annotation) {
1012
- return this.link.groupKey === annotation.link.groupKey;
1013
- }
1014
- /**
1015
- * Generate the style for the annotation
1016
- *
1017
- * @returns {Nullable<AnnotationStyle>} Link style
1018
- */
1019
- render() {
1020
- return null;
1021
- }
1022
- }
1023
-
1024
- /**
1025
- * Action to toggle link annotation
1026
- */
1027
- class LinkAnnotationAction extends TextSplittableAction {
1028
- constructor({ link, newText, needMergeNode, doSplit, }) {
1029
- super();
1030
- this.isFlushable = true;
1031
- this.link = link;
1032
- this.needMergeNode = needMergeNode;
1033
- this.newText = newText;
1034
- if (typeGuard.isNonNullable(doSplit)) {
1035
- this.doSplit = doSplit;
1036
- }
1037
- }
1038
- /**
1039
- * Converts the action to an annotation
1040
- *
1041
- * @returns {LinkAnnotation} the annotation
1042
- */
1043
- toAnnotation() {
1044
- return new LinkAnnotation(this.link);
1045
- }
1046
- }
1047
-
1048
- /**
1049
- * Action to toggle code annotation
1050
- */
1051
- class CodeAnnotationAction extends TextSplittableAction {
1052
- constructor(code) {
1053
- super();
1054
- this.isFlushable = true;
1055
- this.code = code;
1056
- }
1057
- /**
1058
- * Converts the action to an annotation
1059
- *
1060
- * @returns {CodeAnnotation} the annotation
1061
- */
1062
- toAnnotation() {
1063
- return new CodeAnnotation(this.code);
1064
- }
1065
- }
1066
-
1067
- /**
1068
- * Action to toggle clear formatting
1069
- */
1070
- class ClearFormattingAnnotationAction extends TextSplittableAction {
1071
- constructor() {
1072
- super(...arguments);
1073
- this.isFlushable = true;
1074
- }
1075
- /**
1076
- * Converts the action to an annotation
1077
- *
1078
- * @returns {ClearFormattingAnnotation} the annotation
1079
- */
1080
- toAnnotation() {
1081
- return new ClearFormattingAnnotation();
1082
- }
1083
- }
1084
-
1085
- /**
1086
- * Update the text node property text action
1087
- *
1088
- * @example textNode.apply(new UpdateTextAction(newText))
1089
- */
1090
- class UpdateTextAction extends nodeAnnotation_abstract.ModifyContentAction {
1091
- constructor(text) {
1092
- super();
1093
- this.type = nodeAnnotation_abstract.ModifyContentActionType.UPDATE_TEXT;
1094
- this.newTextContent = '';
1095
- this.newTextContent = text;
1096
- }
1097
- }
1098
-
1099
- /**
1100
- * Annotation to represent a link of grouped nodes
1101
- */
1102
- class LinkGroupAnnotation extends nodeAnnotation_abstract.Annotation {
1103
- constructor(groupKey) {
1104
- super();
1105
- this.type = nodeAnnotation_abstract.InternalAnnotationTypeEnum.LINK_GROUP;
1106
- this.linkGroups = new Map();
1107
- this.linkGroups = new Map([[groupKey, []]]);
1108
- }
1109
- }
1110
-
1111
- /**
1112
- * Action to link a group of nodes
1113
- */
1114
- class LinkGroupAnnotationAction extends AnnotationAction {
1115
- constructor(groupKey, nodes) {
1116
- super();
1117
- this.isFlushable = false;
1118
- this.groupKey = groupKey;
1119
- this.nodes = nodes;
1120
- }
1121
- /**
1122
- * Converts the action to an annotation
1123
- *
1124
- * @returns {LinkGroupAnnotation} The annotation
1125
- */
1126
- toAnnotation() {
1127
- return new LinkGroupAnnotation(this.groupKey);
1128
- }
1129
- }
1130
-
1131
- /**
1132
- * Sync up selection action
1133
- */
1134
- class SyncUpSelectionAction extends AnnotationAction {
1135
- constructor() {
1136
- super();
1137
- this.isFlushable = false;
1138
- }
1139
- /**
1140
- * annotation null
1141
- *
1142
- * @returns {Nullable<Annotation>} null
1143
- */
1144
- toAnnotation() {
1145
- return null;
1146
- }
1147
- }
1148
-
1149
- /**
1150
- * Delete the node annotation by type
1151
- */
1152
- class DeleteNodeAnnotationAction extends AnnotationAction {
1153
- constructor(annotationType) {
1154
- super();
1155
- this.isFlushable = true;
1156
- this.annotationType = annotationType;
1157
- }
1158
- /**
1159
- * Don't need this for this action
1160
- *
1161
- * @returns {Nullable<Annotation>} undefined
1162
- */
1163
- toAnnotation() {
1164
- return undefined;
1165
- }
1166
- }
1167
-
1168
- /**
1169
- * Text node
1170
- */
1171
- class RTETextNode extends nodeAnnotation_abstract.RTENode {
1172
- constructor(id, text, parentBlock, annotationMap) {
1173
- super(id, annotationMap);
1174
- this.type = nodeAnnotation_abstract.NodeTypeEnum.TEXT;
1175
- this.parentBlock = parentBlock;
1176
- this.text = text;
1177
- }
1178
- /**
1179
- * Creates an RTETextNode from a VegaRTETextNode with annotations and a parent RTETextBlock.
1180
- *
1181
- * @param {VegaRTETextNode} richText - A rich text node
1182
- * @param {RTETextBlock} parentBlock - Parent block
1183
- * @returns {RTETextNode} an RTETextNode
1184
- */
1185
- static from(richText, parentBlock) {
1186
- const textNode = new RTETextNode(richText.id, richText.text, parentBlock);
1187
- const { annotations } = richText;
1188
- if (annotations) {
1189
- textNode.annotationMap = new Map(Object.keys(annotations)
1190
- .map((type) => {
1191
- if (annotations.link) {
1192
- parentBlock.apply(new LinkGroupAnnotationAction(annotations.link.groupKey, [textNode]));
1193
- }
1194
- return this.createAnnotationEntity(type, annotations[type]);
1195
- })
1196
- .filter(typeGuard.isNonNullable));
1197
- }
1198
- return textNode;
1199
- }
1200
- /**
1201
- * Creates different types of text annotations based on the provided type and value.
1202
- *
1203
- * @param {keyof VegaRTETextAnnotations} type - The key of the type.
1204
- * @param {unknown} value - The value that will be used to create the specific type of annotation entity based on the `type` provided.
1205
- * @returns {Nullable<[RTENodeAnnotationMapKey, RTENodeAnnotationMapValue]>} Returning a nullable tuple containing a key and a
1206
- * value from the `RTENodeAnnotationMapKey` and `RTENodeAnnotationMapValue` types.
1207
- */
1208
- static createAnnotationEntity(type, value) {
1209
- switch (type) {
1210
- case 'bold':
1211
- return BoldAnnotation.from(value);
1212
- case 'italic':
1213
- return ItalicAnnotation.from(value);
1214
- case 'underline':
1215
- return UnderlineAnnotation.from(value);
1216
- case 'strikethrough':
1217
- return StrikethroughAnnotation.from(value);
1218
- case 'code':
1219
- return CodeAnnotation.from(value);
1220
- case 'textColor':
1221
- return TextColorAnnotation.from(value);
1222
- case 'link':
1223
- return LinkAnnotation.from(value);
1224
- }
1225
- }
1226
- /**
1227
- * @inheritDoc
1228
- */
1229
- toJSON() {
1230
- const annotations = Array.from(this.annotationMap.values())
1231
- .filter((annotation) => annotation instanceof nodeAnnotation_abstract.NodeAnnotation)
1232
- .reduce((record, annotation) => {
1233
- return Object.assign(Object.assign({}, record), annotation.toJSON());
1234
- }, {});
1235
- return Object.assign(Object.assign({ id: this.id }, (Object.keys(annotations).length > 0 ? { annotations } : {})), { type: 'text', text: this.text });
1236
- }
1237
- /**
1238
- * Creates a new RTETextNode with the specified text and copies the parent block and annotation map from the original node.
1239
- *
1240
- * @param {string} text - The text content of the RTETextNode that will be created.
1241
- * @returns {RTETextNode} An new RTETextNode
1242
- */
1243
- cloneWithText(text) {
1244
- return new RTETextNode(createPublicApiRuntimeMetricsSlimmer.generateUUID(), text, this.parentBlock, new Map(this.annotationMap));
1245
- }
1246
- /**
1247
- * Checks if a node is empty
1248
- *
1249
- * @returns {boolean} It returns `true` if the node is empty
1250
- */
1251
- isEmpty() {
1252
- return !this.text || this.text === ZERO_WIDTH_SPACE || this.text === '\n';
1253
- }
1254
- /**
1255
- * @inheritDoc
1256
- */
1257
- doAnnotationActionApply(action) {
1258
- const selectionRangeAnnotation = this.getAnnotationByType(nodeAnnotation_abstract.InternalAnnotationTypeEnum.SELECTION_RANGE);
1259
- if (action instanceof TextSplittableAction && action.doSplit && selectionRangeAnnotation) {
1260
- const { startContainer, endContainer, startOffset, endOffset } = selectionRangeAnnotation.range;
1261
- const noTextRangeSelected = startContainer === endContainer && startOffset === endOffset;
1262
- this.parentBlock.nodes = this.parentBlock.nodes.flatMap((item) => {
1263
- if (item.id === this.id) {
1264
- if (noTextRangeSelected) {
1265
- return this.insertNewNode(startOffset, action);
1266
- }
1267
- if (this.shouldSplitSelection(selectionRangeAnnotation.range)) {
1268
- return this.splitTextNode(action, selectionRangeAnnotation.range);
1269
- }
1270
- else {
1271
- this.applyActionToNode(this, action);
1272
- return this;
1273
- }
1274
- }
1275
- return item;
1276
- });
1277
- }
1278
- else {
1279
- this.applyActionToNode(this, action);
1280
- }
1281
- this.parentBlock.mergeNodes(action);
1282
- }
1283
- /**
1284
- * @inheritDoc
1285
- */
1286
- doModifyActionApply(action) {
1287
- switch (action.type) {
1288
- case nodeAnnotation_abstract.ModifyContentActionType.UPDATE_TEXT:
1289
- this.updateText(action.newTextContent);
1290
- break;
1291
- case nodeAnnotation_abstract.ModifyContentActionType.REPLACE_SELECTED_TEXT:
1292
- this.replaceSelectedText(action.textToBeInsert, action.currentRange);
1293
- break;
1294
- }
1295
- }
1296
- /**
1297
- * Split text node with range
1298
- *
1299
- * @param {TextSplittableAction} action - Annotation action
1300
- * @param {Range} range - Selection range
1301
- * @returns {RTETextNode[] | this} RTETextNode array
1302
- */
1303
- splitTextNode(action, range) {
1304
- const { startContainer, endContainer, startOffset } = range;
1305
- const startNode = startContainer.parentElement;
1306
- const endNode = endContainer.parentElement;
1307
- /**
1308
- * Split the text from the start offset to the end offset
1309
- *
1310
- * @param {string} text - The text string
1311
- * @param {number} startOffset - The start offset position
1312
- * @param {number} endOffset - The end offset position
1313
- * @returns {RTETextNode[]} - The split text node array
1314
- */
1315
- const splitText = (text, startOffset, endOffset) => {
1316
- const beforeText = text.substring(0, startOffset);
1317
- const selectedText = text.substring(startOffset, endOffset);
1318
- const afterText = text.substring(endOffset);
1319
- return [
1320
- this.cloneWithText(beforeText),
1321
- this.cloneWithText(selectedText),
1322
- this.cloneWithText(afterText),
1323
- ];
1324
- };
1325
- const startItemDto = startNode && nodeAnnotation_abstract.stateEntityRenderingRegistry.getEntityByDOM(startNode);
1326
- const endItemDto = endNode && nodeAnnotation_abstract.stateEntityRenderingRegistry.getEntityByDOM(endNode);
1327
- if (startItemDto && startItemDto.id === this.id) {
1328
- const endOffset = startContainer === endContainer ? range.endOffset : this.text.length;
1329
- const [beforeNode, selectedNode, afterNode] = splitText(this.text, startOffset, endOffset);
1330
- this.applyActionToNode(selectedNode, action);
1331
- return [beforeNode, selectedNode, afterNode].filter((node) => !!node.text);
1332
- }
1333
- else if (endItemDto && endItemDto.id === this.id) {
1334
- const [beforeNode, selectedNode, afterNode] = splitText(this.text, 0, range.endOffset);
1335
- this.applyActionToNode(selectedNode, action);
1336
- return [beforeNode, selectedNode, afterNode].filter((node) => !!node.text);
1337
- }
1338
- else {
1339
- this.applyActionToNode(this, action);
1340
- return this;
1341
- }
1342
- }
1343
- /**
1344
- * Apply action to node
1345
- *
1346
- * @param {RTETextNode} node - Text node
1347
- * @param {AnnotationAction} action - AnnotationAction
1348
- */
1349
- applyActionToNode(node, action) {
1350
- const annotation = action.toAnnotation();
1351
- if (action instanceof SyncUpSelectionAction) {
1352
- this.syncUpSelectedNodes(node);
1353
- return;
1354
- }
1355
- // Sync up RTETextNode selected state to selection controller for any action apply, except selection range change.
1356
- if (!(annotation instanceof SelectionRangeAnnotation)) {
1357
- this.syncUpSelectedNodes(node);
1358
- }
1359
- if (action instanceof DeleteNodeAnnotationAction) {
1360
- this.annotationMap.delete(action.annotationType);
1361
- return;
1362
- }
1363
- if (annotation instanceof ClearFormattingAnnotation) {
1364
- annotation.items.forEach((item) => {
1365
- node.deleteAnnotationByType(item);
1366
- });
1367
- return;
1368
- }
1369
- if (annotation instanceof nodeAnnotation_abstract.NodeAnnotation || annotation instanceof SelectionRangeAnnotation) {
1370
- if (action instanceof LinkAnnotationAction) {
1371
- if (typeGuard.isNonNullable(action.newText)) {
1372
- node.text = action.newText;
1373
- }
1374
- this.parentBlock.apply(new LinkGroupAnnotationAction(action.link.groupKey, [node]));
1375
- }
1376
- if (action instanceof CodeAnnotationAction) {
1377
- this.applyActionToNode(node, new ClearFormattingAnnotationAction());
1378
- }
1379
- node.annotationMap.set(annotation.type, annotation);
1380
- return;
1381
- }
1382
- }
1383
- /**
1384
- * Replaces the selected text within a given range with a new text in a TypeScript class.
1385
- *
1386
- * @param {string} text - The new text that will replace the currently selected text within the specified range.
1387
- * @param {RTERange} currentRange - A range of text within a Rich Text Editor (RTE).
1388
- */
1389
- replaceSelectedText(text, currentRange) {
1390
- if (currentRange && currentRange.startContainer && currentRange.endContainer) {
1391
- const { startContainer, endContainer, startOffset, endOffset } = currentRange;
1392
- const startNode = startContainer.parentElement;
1393
- const endNode = endContainer.parentElement;
1394
- const startItemDto = startNode && nodeAnnotation_abstract.stateEntityRenderingRegistry.getEntityByDOM(startNode);
1395
- const endItemDto = endNode && nodeAnnotation_abstract.stateEntityRenderingRegistry.getEntityByDOM(endNode);
1396
- let startIndex = 0, endIndex = this.text.length;
1397
- if (startItemDto && startItemDto === this) {
1398
- startIndex = startOffset;
1399
- endIndex = startContainer === endContainer ? endOffset : endIndex;
1400
- }
1401
- else if (endItemDto && endItemDto === this) {
1402
- endIndex = endOffset;
1403
- }
1404
- this.apply(new UpdateTextAction(this.text.slice(0, startIndex) + text + this.text.slice(endIndex)));
1405
- }
1406
- }
1407
- /**
1408
- * Updates the text content of a node and unlink the node if it is a link node and the text is deleted.
1409
- *
1410
- * @param {string} newText - The new text string
1411
- */
1412
- updateText(newText) {
1413
- this.text = newText;
1414
- // The link node should unlink when delete all text
1415
- if (!this.text && this.isLinkNode()) {
1416
- this.annotationMap.delete(nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK);
1417
- }
1418
- }
1419
- /**
1420
- * Checks if a node has an annotation with the key 'LINK'.
1421
- *
1422
- * @returns {boolean} A boolean value indicating whether the `annotationMap` has a key 'LINK'.
1423
- */
1424
- isLinkNode() {
1425
- return this.annotationMap.has('LINK');
1426
- }
1427
- /**
1428
- * Whether a given range should be split based on various conditions within the range.
1429
- *
1430
- * @param {Range} range - Selection range
1431
- * @returns {boolean} Returns a boolean value indicating whether the
1432
- * selection range should be split.
1433
- */
1434
- shouldSplitSelection(range) {
1435
- const { startContainer, endContainer, startOffset, endOffset } = range;
1436
- const isCrossNode = startContainer !== endContainer;
1437
- const isPartialStart = startOffset > 0;
1438
- const isPartialEnd = endOffset < (endContainer.textContent ? endContainer.textContent.length : 0);
1439
- const isPartialSelection = isPartialStart || isPartialEnd;
1440
- return isCrossNode || isPartialSelection;
1441
- }
1442
- /**
1443
- * Sync up the selected node by change manager
1444
- *
1445
- * @param {RTETextNode} selectedNode - The selected node
1446
- */
1447
- syncUpSelectedNodes(selectedNode) {
1448
- const currentNodeDom = nodeAnnotation_abstract.stateEntityRenderingRegistry.getDOMByEntity(this);
1449
- if (currentNodeDom) {
1450
- const nodeSubject = domNodeSubjectFactory.domNodeSubjectFactory.getSubjectFromParentNodeByEventId(currentNodeDom, vegaInternalEventId.VegaInternalRichTextEditorSelectionRangeChange);
1451
- if (nodeSubject) {
1452
- changeManager.ChangeManager.notify(nodeSubject, { node: selectedNode });
1453
- }
1454
- }
1455
- }
1456
- /**
1457
- * Insert the new node at the start offset
1458
- *
1459
- * @param {number} startOffset - The start position offset
1460
- * @param {AnnotationAction} action - AnnotationAction
1461
- * @returns {RTETextNode[]} - RTETextNode array
1462
- */
1463
- insertNewNode(startOffset, action) {
1464
- if (startOffset === 0) {
1465
- const newNode = this.cloneWithText('');
1466
- this.applyActionToNode(newNode, action);
1467
- return [newNode, this];
1468
- }
1469
- if (startOffset === this.text.length) {
1470
- const newNode = this.cloneWithText('');
1471
- this.applyActionToNode(newNode, action);
1472
- return [this, newNode];
1473
- }
1474
- const beforeNode = this.cloneWithText(this.text.substring(0, startOffset));
1475
- const newNode = this.cloneWithText('');
1476
- const afterNode = this.cloneWithText(this.text.substring(startOffset));
1477
- this.applyActionToNode(newNode, action);
1478
- return [beforeNode, newNode, afterNode];
1479
- }
1480
- }
1481
-
1482
- /**
1483
- * Text style annotation
1484
- */
1485
- class TextStyleAnnotation extends nodeAnnotation_abstract.BlockAnnotation {
1486
- constructor(textStyle) {
1487
- super();
1488
- this.type = nodeAnnotation_abstract.BlockAnnotationTypeEnum.TEXT_STYLE;
1489
- this.textStyle = textStyle;
1490
- }
1491
- /**
1492
- * Generate the map item for the annotations
1493
- *
1494
- * @param {VegaRTETextStyleType} textStyle - the text style type
1495
- * @returns {[BlockAnnotationTypeEnum.TEXT_STYLE, TextStyleAnnotation]} Map item for the annotation
1496
- */
1497
- static from(textStyle) {
1498
- return [nodeAnnotation_abstract.BlockAnnotationTypeEnum.TEXT_STYLE, new TextStyleAnnotation(textStyle)];
1499
- }
1500
- /**
1501
- * Generate the JSON representation of the annotation
1502
- *
1503
- * @returns {Nullable<Record<string, unknown>>} JSON representation of the annotation
1504
- */
1505
- toJSON() {
1506
- return { textStyle: this.textStyle };
1507
- }
1508
- /**
1509
- * Render the styles by block type
1510
- *
1511
- * @returns {AnnotationStyle} the styles to apply
1512
- */
1513
- render() {
1514
- const paragraphStyle = {
1515
- fontFamily: 'Inter',
1516
- fontSize: '16px',
1517
- lineHeight: '22px',
1518
- fontWeight: '500',
1519
- };
1520
- switch (this.textStyle) {
1521
- case 'paragraph': {
1522
- return paragraphStyle;
1523
- }
1524
- case 'title': {
1525
- return { fontFamily: 'Inter', fontSize: '36px', lineHeight: '40px', fontWeight: '500' };
1526
- }
1527
- case 'subtitle': {
1528
- return { fontFamily: 'Inter', fontSize: '28px', lineHeight: '32px', fontWeight: '500' };
1529
- }
1530
- case 'heading-1': {
1531
- return { fontFamily: 'Inter', fontSize: '22px', lineHeight: '24px', fontWeight: '500' };
1532
- }
1533
- case 'heading-2': {
1534
- return { fontFamily: 'Inter', fontSize: '20px', lineHeight: '24px', fontWeight: '500' };
1535
- }
1536
- case 'heading-3': {
1537
- return { fontFamily: 'Inter', fontSize: '18px', lineHeight: '22px', fontWeight: '500' };
1538
- }
1539
- }
1540
- }
1541
- }
1542
-
1543
- /**
1544
- * Action to change the text style of a block
1545
- */
1546
- class TextStyleAnnotationAction extends AnnotationAction {
1547
- constructor(textStyle, bold) {
1548
- super();
1549
- this.isFlushable = true;
1550
- this.textStyle = textStyle;
1551
- this.bold = bold;
1552
- }
1553
- /**
1554
- * Converts the action to a block annotation
1555
- *
1556
- * @returns {BlockAnnotation} the block annotation
1557
- */
1558
- toAnnotation() {
1559
- return new TextStyleAnnotation(this.textStyle);
1560
- }
1561
- }
1562
-
1563
- /**
1564
- * Action to toggle bold annotation
1565
- */
1566
- class BoldAnnotationAction extends TextSplittableAction {
1567
- constructor(bold) {
1568
- super();
1569
- this.isFlushable = true;
1570
- this.bold = bold;
1571
- }
1572
- /**
1573
- * Converts the action to an annotation
1574
- *
1575
- * @returns {BoldAnnotation} the annotation
1576
- */
1577
- toAnnotation() {
1578
- return new BoldAnnotation(this.bold);
1579
- }
1580
- }
1581
-
1582
- /**
1583
- * Merge the two blocks node into first block if the two blocks nodes type is same(text node or image node)
1584
- *
1585
- * @example firstBlock.apply(new MergeTwoBlocksNodesAction(secondBlock))
1586
- */
1587
- class MergeTwoBlocksNodesAction extends nodeAnnotation_abstract.ModifyContentAction {
1588
- constructor(blockNeedToBeMerged) {
1589
- super();
1590
- this.type = nodeAnnotation_abstract.ModifyContentActionType.MERGE_TWO_BLOCKS_NODES;
1591
- this.blockNeedToBeMerged = blockNeedToBeMerged;
1592
- }
1593
- }
1594
-
1595
- /**
1596
- * Insert a new block before a existing block
1597
- *
1598
- * @example currentBlock.parent.apply(new InsertBlocksBeforeAction(currentBlock, newBlock, ...))
1599
- */
1600
- class InsertBlocksBeforeAction extends nodeAnnotation_abstract.ModifyContentAction {
1601
- constructor(referBlock, ...blocksToBeInserted) {
1602
- super();
1603
- this.type = nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_BEFORE;
1604
- this.referBlock = referBlock;
1605
- this.blocksToBeInserted = blocksToBeInserted;
1606
- }
1607
- }
1608
-
1609
- /**
1610
- * Text block
1611
- */
1612
- class RTETextBlock extends RTEBlock {
1613
- constructor(id, type) {
1614
- super(id);
1615
- this.nodes = [];
1616
- this.type = type;
1617
- if (RTETextBlock.isAcceptableTextStyle(type)) {
1618
- this.annotationMap = new Map([TextStyleAnnotation.from(type)]);
1619
- }
1620
- else {
1621
- this.annotationMap = new Map([TextStyleAnnotation.from('paragraph')]);
1622
- }
1623
- }
1624
- /**
1625
- * Converts a VegaRTETextBlock into an RTETextBlock.
1626
- *
1627
- * @param {VegaRTETextBlock} block - The block object
1628
- * @returns {RTETextBlock} A RTETextBlock class
1629
- */
1630
- static from(block) {
1631
- const textBlock = new RTETextBlock(block.id, block.type);
1632
- const { annotations } = block;
1633
- textBlock.nodes = block.nodes.map((richText) => RTETextNode.from(richText, textBlock));
1634
- if (annotations) {
1635
- Object.entries(annotations).forEach(([type, value]) => {
1636
- const item = this.createAnnotationEntity(type, value);
1637
- if (typeGuard.isNonNullable(item)) {
1638
- textBlock.annotationMap.set(...item);
1639
- }
1640
- });
1641
- }
1642
- return textBlock;
1643
- }
1644
- /**
1645
- * The function `createAnnotationEntity` creates a block annotation entity based on the provided type
1646
- * and value.
1647
- *
1648
- * @param {keyof VegaRTEBlockAnnotations} type - The `type` parameter is a key of the `VegaRTEBlockAnnotations` enum, which specifies
1649
- * the type of annotation entity to create.
1650
- * @param {unknown} value - The `value` parameter in the `createAnnotationEntity` function is the value
1651
- * that will be used to create the annotation entity. It can be of any type depending on the specific
1652
- * annotation being created.
1653
- * @returns {Nullable<[BlockAnnotationTypeEnum, BlockAnnotation]>} The `createAnnotationEntity` function returns a nullable tuple containing a
1654
- * `BlockAnnotationTypeEnum` and a `BlockAnnotation` object.
1655
- */
1656
- static createAnnotationEntity(type, value) {
1657
- if (type === 'textStyle') {
1658
- return TextStyleAnnotation.from(value);
1659
- }
1660
- else {
1661
- return super.createAnnotationEntity(type, value);
1662
- }
1663
- }
1664
- /**
1665
- * Checks if a given text block type is one of the acceptable text styles.
1666
- *
1667
- * @param {VegaRTETextBlockType} type - The text block type
1668
- * @returns {boolean} Return a boolean value indicating whether the `type` parameter is valid.
1669
- */
1670
- static isAcceptableTextStyle(type) {
1671
- return ['title', 'subtitle', 'paragraph', 'heading-1', 'heading-2', 'heading-3'].includes(type);
1672
- }
1673
- /**
1674
- * Merges RTETextNode nodes based on certain conditions.
1675
- *
1676
- * @param {AnnotationAction} action - AnnotationAction
1677
- */
1678
- mergeNodes(action) {
1679
- this.nodes = this.nodes.reduce((prev, cur) => {
1680
- const lastNode = prev.at(-1);
1681
- if (action instanceof LinkAnnotationAction && action.needMergeNode) {
1682
- const lastNodeLinkAnnotation = lastNode === null || lastNode === void 0 ? void 0 : lastNode.getAnnotationByType(nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK);
1683
- const curNodeLinkAnnotation = cur.getAnnotationByType(nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK);
1684
- if (lastNodeLinkAnnotation &&
1685
- curNodeLinkAnnotation &&
1686
- lastNodeLinkAnnotation.toEqual(curNodeLinkAnnotation)) {
1687
- return prev;
1688
- }
1689
- }
1690
- // TODO: handle other cases like merge bold nodes
1691
- return [...prev, cur];
1692
- }, []);
1693
- }
1694
- /**
1695
- * @inheritDoc
1696
- */
1697
- toJSON() {
1698
- return Object.assign(Object.assign({}, super.toJSON()), { type: this.type, nodes: this.nodes.map((node) => node.toJSON()) });
1699
- }
1700
- /**
1701
- * Clone the nodes to a new block
1702
- *
1703
- * @param {RTEBlock} nodes - The nodes will be copied
1704
- * @returns {RTEBlock} New block
1705
- */
1706
- cloneWithNodes(nodes) {
1707
- const block = new RTETextBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID(), this.type);
1708
- block.nodes = [];
1709
- block.apply(new AppendChildNodesAction(nodes));
1710
- return block;
1711
- }
1712
- /**
1713
- * @inheritDoc
1714
- */
1715
- isNotEmpty() {
1716
- return this.nodes.length > 0 && this.nodes.some((node) => !node.isEmpty());
1717
- }
1718
- /**
1719
- * @inheritDoc
1720
- */
1721
- getLastNode() {
1722
- return this.nodes[this.nodes.length - 1];
1723
- }
1724
- /**
1725
- * @inheritDoc
1726
- */
1727
- doAnnotationActionApply(action) {
1728
- if (action instanceof TextStyleAnnotationAction) {
1729
- if (this.type !== 'list-item') {
1730
- this.type = action.textStyle;
1731
- }
1732
- if (action.bold) {
1733
- this.nodes.forEach((node) => {
1734
- const boldAnnotationAction = new BoldAnnotationAction(true);
1735
- boldAnnotationAction.doSplit = false;
1736
- node.apply(boldAnnotationAction);
1737
- });
1738
- }
1739
- else {
1740
- this.nodes.forEach((node) => {
1741
- node.apply(new DeleteNodeAnnotationAction(nodeAnnotation_abstract.NodeAnnotationTypeEnum.BOLD));
1742
- });
1743
- }
1744
- return;
1745
- }
1746
- if (action instanceof LinkGroupAnnotationAction) {
1747
- const linkGroupAnnotation = this.getAnnotationByType(nodeAnnotation_abstract.InternalAnnotationTypeEnum.LINK_GROUP);
1748
- if (linkGroupAnnotation) {
1749
- const linkGroup = linkGroupAnnotation.linkGroups.get(action.groupKey);
1750
- linkGroupAnnotation.linkGroups.set(action.groupKey, [...linkGroup, ...action.nodes]);
1751
- this.annotationMap.set(nodeAnnotation_abstract.InternalAnnotationTypeEnum.LINK_GROUP, linkGroupAnnotation);
1752
- }
1753
- return;
1754
- }
1755
- }
1756
- /**
1757
- * Apply a modify action to block
1758
- *
1759
- * @param {ModifyContentAction} action - Modify action
1760
- */
1761
- doModifyActionApply(action) {
1762
- switch (action.type) {
1763
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD:
1764
- this.removeChildNode(action);
1765
- break;
1766
- case nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES:
1767
- this.appendChildNodes(action.entityToBeAppended);
1768
- break;
1769
- case nodeAnnotation_abstract.ModifyContentActionType.CLEAR_CHILD_NODES:
1770
- this.nodes = [];
1771
- break;
1772
- case nodeAnnotation_abstract.ModifyContentActionType.SPLIT_BLOCK_WITH_NODE:
1773
- action.newBlock = this.splitTextNodeBlock(action.splitPointNode, action.startOffsetOfNode);
1774
- break;
1775
- case nodeAnnotation_abstract.ModifyContentActionType.REPLACE_CHILD_NODES:
1776
- this.nodes = [];
1777
- this.appendChildNodes(action.newChildNodes);
1778
- break;
1779
- case nodeAnnotation_abstract.ModifyContentActionType.MERGE_TWO_BLOCKS_NODES:
1780
- this.mergeTwoBlocksNodes(action.blockNeedToBeMerged);
1781
- break;
1782
- case nodeAnnotation_abstract.ModifyContentActionType.BREAK_SINGLE_BLOCK:
1783
- action.newBlock = this.breakSingleTextBlock(action.startContainerNode, action.startOffset);
1784
- break;
1785
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_SINGLE_BLOCK:
1786
- action.lineBreakNode = this.lineBreakSingleBlock(action.startContainerNode, action.startOffset);
1787
- break;
1788
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_MULTIPLE_BLOCKS:
1789
- action.lineBreakNode = this.lineBreakMultipleBlocks(action.selectedBlocks);
1790
- break;
1791
- case nodeAnnotation_abstract.ModifyContentActionType.TRANSFORM_LIST_BLOCK:
1792
- this.convertParagraphToList(action);
1793
- break;
1794
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_BLOCK_CONTENT:
1795
- this.deleteNodeContent(action);
1796
- break;
1797
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_IMAGE_TO_BLOCK:
1798
- this.insertImage(action);
1799
- break;
1800
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_NODES_BEFORE:
1801
- this.replaceNodeWithNodes(action.referNode, [
1802
- ...action.nodesToBeInserted,
1803
- action.referNode,
1804
- ]);
1805
- break;
1806
- }
1807
- }
1808
- /**
1809
- * Splits a text node at a specified offset within a block of nodes and returns a new block with the split nodes.
1810
- *
1811
- * @param {RTETextNode} splitNode - The text node that will be split
1812
- * @param {number} startOffsetOfNode - The index at which will split the text content of the `splitNode`.
1813
- * @returns {Nullable<RTEBlock>} return either an RTEBlock object or null.
1814
- */
1815
- splitTextNodeBlock(splitNode, startOffsetOfNode) {
1816
- if (splitNode) {
1817
- const beforeText = splitNode.text.slice(0, startOffsetOfNode);
1818
- const afterText = splitNode.text.slice(startOffsetOfNode);
1819
- const nodesSplitIndex = this.nodes.indexOf(splitNode);
1820
- if (nodesSplitIndex > -1) {
1821
- const beforeNodes = this.nodes.slice(0, nodesSplitIndex);
1822
- const afterNodes = this.nodes.slice(nodesSplitIndex + 1);
1823
- if (beforeText) {
1824
- beforeNodes.push(splitNode.cloneWithText(beforeText));
1825
- }
1826
- if (afterText) {
1827
- afterNodes.unshift(splitNode.cloneWithText(afterText));
1828
- }
1829
- this.apply(new ReplaceChildNodesAction(beforeNodes));
1830
- const newBlock = this.cloneWithNodes(afterNodes);
1831
- this.parent.apply(new InsertBlocksAfterAction(this, newBlock));
1832
- return newBlock;
1833
- }
1834
- }
1835
- }
1836
- /**
1837
- * Checks if the caret position is at the start of a specified RTETextNode.
1838
- *
1839
- * @param {RTETextNode} node - `RTETextNode` - a node representing an image in a rich text editor.
1840
- * @param {number} startOffset - The position within the text node where the caret is located.
1841
- * @returns {boolean} a boolean value, which indicates whether the caret position is at the start of the RTETextNode.
1842
- */
1843
- isCaretPositionAtStart(node, startOffset) {
1844
- return node === this.nodes[0] && startOffset === 0;
1845
- }
1846
- /**
1847
- * Checks if the caret position is at the end of a specified RTETextNode.
1848
- *
1849
- * @param {RTETextNode} node - `RTETextNode` - a node representing an image in a rich text editor.
1850
- * @param {number} startOffset - The position within the text node where the caret is located.
1851
- * @returns {boolean} a boolean value, which indicates whether the caret position is at the start of the RTETextNode.
1852
- */
1853
- isCaretPositionAtEnd(node, startOffset) {
1854
- const lastNode = this.nodes[this.nodes.length - 1];
1855
- return node === lastNode && (node.isEmpty() || startOffset === lastNode.text.length);
1856
- }
1857
- /**
1858
- * lineBreakSingleBlock
1859
- *
1860
- * @param {RTETextNode} splitNode -
1861
- * @param {number} startOffsetOfNode -
1862
- * @returns {Nullable<RTETextNode>} Nullable<RTETextNode>
1863
- */
1864
- lineBreakSingleBlock(splitNode, startOffsetOfNode) {
1865
- if (splitNode) {
1866
- const lineBreakNode = new RTETextNode(createPublicApiRuntimeMetricsSlimmer.generateUUID(), '\n', this);
1867
- const beforeText = splitNode.text.slice(0, startOffsetOfNode);
1868
- const afterText = splitNode.text.slice(startOffsetOfNode);
1869
- const nodesSplitIndex = this.nodes.indexOf(splitNode);
1870
- if (nodesSplitIndex > -1) {
1871
- const beforeNodes = this.nodes.slice(0, nodesSplitIndex);
1872
- const afterNodes = this.nodes.slice(nodesSplitIndex + 1);
1873
- if (beforeText) {
1874
- beforeNodes.push(splitNode.cloneWithText(beforeText));
1875
- }
1876
- if (afterText) {
1877
- afterNodes.unshift(splitNode.cloneWithText(afterText));
1878
- }
1879
- this.mergeLineBreakNodes(beforeNodes, lineBreakNode, afterNodes);
1880
- }
1881
- return lineBreakNode;
1882
- }
1883
- }
1884
- /**
1885
- * lineBreakMultipleBlocks
1886
- *
1887
- * @param {RTEBlock[]} selectedBlocks -
1888
- * @returns {Nullable<RTETextNode>} Nullable<RTETextNode>
1889
- */
1890
- lineBreakMultipleBlocks(selectedBlocks) {
1891
- const beforeNodes = this['nodes'];
1892
- const lineBreakNode = new RTETextNode(createPublicApiRuntimeMetricsSlimmer.generateUUID(), '\n', this);
1893
- const afterNodes = this.concatBlocksNodes(selectedBlocks.slice(1));
1894
- this.mergeLineBreakNodes(beforeNodes, lineBreakNode, afterNodes);
1895
- return lineBreakNode;
1896
- }
1897
- /**
1898
- * deleteNodeContent
1899
- *
1900
- * @param {DeleteBlockContentAction} action - ModifyContentAction
1901
- */
1902
- deleteNodeContent(action) {
1903
- const startContainerNode = action.startContainerNode;
1904
- const startOffset = action.startOffset;
1905
- if (startOffset !== 0 && !startContainerNode.isEmpty()) {
1906
- const newText = startContainerNode.text.slice(0, startOffset - 1) +
1907
- startContainerNode.text.slice(startOffset);
1908
- startContainerNode.apply(new UpdateTextAction(newText));
1909
- if (newText) {
1910
- action.previousNode = startContainerNode;
1911
- return;
1912
- }
1913
- else {
1914
- const previousNode = this.getPreviousNode(startContainerNode);
1915
- // Remove the last character will not delete paragraph, the paragraph will removed after press delete again
1916
- if ((previousNode && previousNode.parentBlock === this && previousNode['text'] === '\n') ||
1917
- this.nodes.length === 1) {
1918
- action.previousNode = startContainerNode;
1919
- return;
1920
- }
1921
- else {
1922
- this.apply(new RemoveChildAction(startContainerNode));
1923
- action.previousNode = previousNode;
1924
- return;
1925
- }
1926
- }
1927
- }
1928
- else {
1929
- let previousNode = this.getPreviousNode(startContainerNode);
1930
- let nextNode = null;
1931
- if (this.nodes.length && previousNode && previousNode.parentBlock !== this) {
1932
- if (startContainerNode.isEmpty()) {
1933
- this.apply(new RemoveChildAction(startContainerNode));
1934
- }
1935
- previousNode.parentBlock.apply(new MergeTwoBlocksNodesAction(this));
1936
- }
1937
- else {
1938
- if (this.isContentFirstNode(startContainerNode) && startContainerNode.isEmpty()) {
1939
- nextNode = this.getNextNode(startContainerNode);
1940
- }
1941
- /**
1942
- * Remove line break
1943
- *
1944
- * @example caret at the first line
1945
- * \n
1946
- * test
1947
- */
1948
- if (startContainerNode.isEmpty()) {
1949
- this.apply(new RemoveChildAction(startContainerNode));
1950
- }
1951
- /**
1952
- * Remove line break
1953
- *
1954
- * @example caret at the begin of second line
1955
- * \n
1956
- * test
1957
- */
1958
- if (previousNode instanceof RTETextNode && previousNode.isEmpty()) {
1959
- const shouldRemoveNode = previousNode;
1960
- previousNode = this.getPreviousNode(previousNode);
1961
- shouldRemoveNode.parentBlock.apply(new RemoveChildAction(shouldRemoveNode));
1962
- if (!previousNode) {
1963
- nextNode = startContainerNode;
1964
- }
1965
- }
1966
- }
1967
- //Remove the paragraph block if the content is empty
1968
- if (this.nodes.length === 0) {
1969
- this.parent.apply(new RemoveChildAction(this));
1970
- }
1971
- if (previousNode) {
1972
- action.previousNode = previousNode;
1973
- }
1974
- else if (nextNode) {
1975
- action.nextNode = nextNode;
1976
- }
1977
- }
1978
- }
1979
- /**
1980
- * Remove the child node
1981
- *
1982
- * @param {RemoveChildAction} action - Modify action
1983
- */
1984
- removeChildNode(action) {
1985
- this.nodes = this.nodes.filter((node) => node !== action.entityToBeRemoved);
1986
- if (this.nodes.length === 0) {
1987
- this.parent.apply(new RemoveChildAction(this));
1988
- }
1989
- }
1990
- /**
1991
- * mergeLineBreakNodes
1992
- *
1993
- * @param {RTENode[]} beforeNodes -
1994
- * @param {RTETextNode} lineBreakNode -
1995
- * @param {RTENode[]} afterNodes -
1996
- */
1997
- mergeLineBreakNodes(beforeNodes, lineBreakNode, afterNodes) {
1998
- if (afterNodes.length === 0 || (afterNodes[0] && afterNodes[0].text === '')) {
1999
- afterNodes.push(new RTETextNode(createPublicApiRuntimeMetricsSlimmer.generateUUID(), '\n', this, beforeNodes[beforeNodes.length - 1] && beforeNodes[beforeNodes.length - 1].annotationMap));
2000
- }
2001
- this.apply(new ReplaceChildNodesAction([...beforeNodes, lineBreakNode, ...afterNodes]));
2002
- }
2003
- /**
2004
- * breakSingleTextBlock
2005
- *
2006
- * @param {RTETextNode} splitNode -
2007
- * @param {number} startOffsetOfNode -
2008
- * @returns {Nullable<RTEBlock>} Nullable<RTEBlock>
2009
- */
2010
- breakSingleTextBlock(splitNode, startOffsetOfNode) {
2011
- const newParagraph = this.copyInlineStyleToNewParagraph(splitNode);
2012
- if (this.isCaretPositionAtEnd(splitNode, startOffsetOfNode)) {
2013
- this.parent.apply(new InsertBlocksAfterAction(this, newParagraph));
2014
- }
2015
- else if (this.isCaretPositionAtStart(splitNode, startOffsetOfNode)) {
2016
- this.parent.apply(new InsertBlocksBeforeAction(this, newParagraph));
2017
- }
2018
- else {
2019
- const splitBlockAction = new SplitBlockWithNodeAction(splitNode, startOffsetOfNode);
2020
- this.apply(splitBlockAction);
2021
- return splitBlockAction.newBlock;
2022
- }
2023
- return newParagraph;
2024
- }
2025
- /**
2026
- * convertParagraphToList
2027
- *
2028
- * @param {TransformListAction} action - ModifyContentAction
2029
- */
2030
- convertParagraphToList(action) {
2031
- const bulletList = this.parent.createList(action.listType);
2032
- const listItems = action.selectedBlocks.map((node) => this.parent.toListItem(node));
2033
- bulletList.apply(new AppendChildNodesAction(listItems));
2034
- this.parent.apply(new InsertBlocksAfterAction(action.selectedBlocks[0], bulletList));
2035
- action.selectedBlocks.forEach((node) => {
2036
- node.parent.apply(new RemoveChildAction(node));
2037
- });
2038
- }
2039
- /**
2040
- * insertImage
2041
- *
2042
- * @param {InsertImageToBlockAction} action - ModifyContentAction
2043
- */
2044
- insertImage(action) {
2045
- const splitNode = action.splitPointNode;
2046
- const startOffsetOfNode = action.startOffsetOfNode;
2047
- const newImageBlock = action.imageBlockToBeInserted;
2048
- if (this.isCaretPositionAtEnd(splitNode, startOffsetOfNode)) {
2049
- this.parent.apply(new InsertBlocksAfterAction(this, newImageBlock));
2050
- }
2051
- else if (this.isCaretPositionAtStart(splitNode, startOffsetOfNode)) {
2052
- this.parent.apply(new InsertBlocksBeforeAction(this, newImageBlock));
2053
- }
2054
- else {
2055
- const splitBlockAction = new SplitBlockWithNodeAction(splitNode, startOffsetOfNode);
2056
- this.apply(splitBlockAction);
2057
- this.parent.apply(new InsertBlocksAfterAction(this, newImageBlock));
2058
- }
2059
- }
2060
- /**
2061
- * copyInlineStyleToNewParagraph
2062
- *
2063
- * @param {RTETextNode} needCopedNode -
2064
- * @returns {RTETextBlock} RTETextBlock
2065
- */
2066
- copyInlineStyleToNewParagraph(needCopedNode) {
2067
- const textNode = needCopedNode.cloneWithText('');
2068
- // The link annotation don't need inherited
2069
- textNode.annotationMap.delete(nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK);
2070
- const newParagraph = new RTETextBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID(), 'paragraph');
2071
- newParagraph.apply(new AppendChildNodesAction([textNode]));
2072
- return newParagraph;
2073
- }
2074
- }
2075
-
2076
- /**
2077
- * Image block
2078
- */
2079
- class RTEImageBlock extends RTEBlock {
2080
- constructor(id) {
2081
- super(id);
2082
- this.type = 'image';
2083
- this.nodes = [];
2084
- }
2085
- /**
2086
- * Converts a VegaRTEImageBlock object into an RTEImageBlock object by mapping nodes and creating annotations.
2087
- *
2088
- * @param {VegaRTEImageBlock} block - The block object to be converted.
2089
- * @returns {RTEImageBlock} An instance of `RTEImageBlock`
2090
- */
2091
- static from(block) {
2092
- const imageBlock = new RTEImageBlock(block.id);
2093
- const { annotations } = block;
2094
- imageBlock.nodes = block.nodes.map((image) => RTEImageNode.from(image, imageBlock));
2095
- if (annotations) {
2096
- Object.entries(annotations).forEach(([type, value]) => {
2097
- const item = this.createAnnotationEntity(type, value);
2098
- if (typeGuard.isNonNullable(item)) {
2099
- imageBlock.annotationMap.set(...item);
2100
- }
2101
- });
2102
- }
2103
- return imageBlock;
2104
- }
2105
- /**
2106
- * @inheritDoc
2107
- */
2108
- toJSON() {
2109
- return Object.assign(Object.assign({}, super.toJSON()), { type: 'image', nodes: this.nodes.map((node) => node.toJSON()) });
2110
- }
2111
- /**
2112
- * @inheritDoc
2113
- */
2114
- isNotEmpty() {
2115
- return this.nodes.length > 0 && this.nodes.some((node) => node.url.length > 0);
2116
- }
2117
- /**
2118
- * @inheritDoc
2119
- */
2120
- getLastNode() {
2121
- return this.nodes[this.nodes.length - 1];
2122
- }
2123
- /**
2124
- * Apply a modify action to block
2125
- *
2126
- * @param {ModifyContentAction} action - Modify action
2127
- */
2128
- doModifyActionApply(action) {
2129
- switch (action.type) {
2130
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD:
2131
- this.removeChildNode(action);
2132
- break;
2133
- case nodeAnnotation_abstract.ModifyContentActionType.CLEAR_CHILD_NODES:
2134
- this.nodes = [];
2135
- break;
2136
- case nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES:
2137
- this.appendChildNodes(action.entityToBeAppended);
2138
- break;
2139
- case nodeAnnotation_abstract.ModifyContentActionType.REPLACE_CHILD_NODES:
2140
- this.nodes = [];
2141
- this.appendChildNodes(action.newChildNodes);
2142
- break;
2143
- case nodeAnnotation_abstract.ModifyContentActionType.SPLIT_BLOCK_WITH_NODE:
2144
- action.newBlock = this.splitImageNodes(action.splitPointNode, action.startOffsetOfNode);
2145
- break;
2146
- case nodeAnnotation_abstract.ModifyContentActionType.MERGE_TWO_BLOCKS_NODES:
2147
- this.mergeTwoBlocksNodes(action.blockNeedToBeMerged);
2148
- break;
2149
- case nodeAnnotation_abstract.ModifyContentActionType.BREAK_SINGLE_BLOCK:
2150
- action.newBlock = this.breakSingleBlock(action.startContainerNode, action.startOffset);
2151
- break;
2152
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_SINGLE_BLOCK:
2153
- action.lineBreakNode = this.lineBreakSingleBlock(action.startContainerNode, action.startOffset);
2154
- break;
2155
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_MULTIPLE_BLOCKS:
2156
- action.lineBreakNode = this.lineBreakMultipleBlocks(action.selectedBlocks);
2157
- break;
2158
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_BLOCK_CONTENT:
2159
- this.deleteNodeContent(action);
2160
- break;
2161
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_IMAGE_TO_BLOCK:
2162
- this.insertImage(action);
2163
- break;
2164
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_NODES_AFTER:
2165
- this.replaceNodeWithNodes(action.referNode, [
2166
- action.referNode,
2167
- ...action.nodesToBeInserted,
2168
- ]);
2169
- break;
2170
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_NODES_BEFORE:
2171
- this.replaceNodeWithNodes(action.referNode, [
2172
- ...action.nodesToBeInserted,
2173
- action.referNode,
2174
- ]);
2175
- break;
2176
- }
2177
- }
2178
- /**
2179
- * Removes a specified child node from a list of nodes and triggers a parent action if the list becomes empty.
2180
- *
2181
- * @param {RemoveChildAction} action - Action to be performed when removing a child node from the list of nodes.
2182
- */
2183
- removeChildNode(action) {
2184
- this.nodes = this.nodes.filter((node) => node !== action.entityToBeRemoved);
2185
- if (this.nodes.length === 0) {
2186
- this.parent.apply(new RemoveChildAction(this));
2187
- }
2188
- }
2189
- /**
2190
- * The image offset should be 0 or 1
2191
- * <vega-rich-text-image-editor><img /></vega-rich-text-image-editor>
2192
- *
2193
- * @param {RTEImageNode} imageNode The split point image node
2194
- * @param {number} imageOffset The cursor point 0 | 1
2195
- * @returns {Nullable<RTEBlock>} The new block after split
2196
- */
2197
- splitImageNodes(imageNode, imageOffset) {
2198
- const nodesSplitIndex = this.nodes.indexOf(imageNode);
2199
- if (nodesSplitIndex > -1) {
2200
- const beforeNodes = this.nodes.slice(0, nodesSplitIndex + imageOffset);
2201
- const afterNodes = this.nodes.slice(nodesSplitIndex + imageOffset);
2202
- this.apply(new ReplaceChildNodesAction(beforeNodes));
2203
- const newBlock = this.cloneWithNodes(afterNodes);
2204
- this.parent.apply(new InsertBlocksAfterAction(this, newBlock));
2205
- return newBlock;
2206
- }
2207
- }
2208
- /**
2209
- * Creates a new RTEImageBlock instance with the provided RTEImageNode instances appended to it.
2210
- *
2211
- * @param {RTEImageNode[]} nodes - An array of RTEImageNode objects that will be used to create a new RTEImageBlock instance.
2212
- * @returns {RTEImageBlock} A new `RTEImageBlock` object with the provided `nodes` appended to it.
2213
- */
2214
- cloneWithNodes(nodes) {
2215
- const block = new RTEImageBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID());
2216
- block.nodes = [];
2217
- block.apply(new AppendChildNodesAction(nodes));
2218
- return block;
2219
- }
2220
- /**
2221
- * Used to split a block of text at a specific position and insert a new paragraph block.
2222
- *
2223
- * @param {RTEImageNode} splitNode - The node that needs to be split into separate blocks.
2224
- * @param {number} startOffsetOfNode - The index or position within the `splitNode` where the block should be broken or split.
2225
- * @returns {Nullable<RTEBlock>} Returns either a new paragraph block or the new block created after splitting the original block.
2226
- */
2227
- breakSingleBlock(splitNode, startOffsetOfNode) {
2228
- const newParagraph = RTETextBlock.from({
2229
- id: createPublicApiRuntimeMetricsSlimmer.generateUUID(),
2230
- type: 'paragraph',
2231
- nodes: [{ id: createPublicApiRuntimeMetricsSlimmer.generateUUID(), type: 'text', text: '' }],
2232
- });
2233
- if (this.isCaretPositionAtEnd(splitNode, startOffsetOfNode)) {
2234
- this.parent.apply(new InsertBlocksAfterAction(this, newParagraph));
2235
- }
2236
- else if (this.isCaretPositionAtStart(splitNode, startOffsetOfNode)) {
2237
- this.parent.apply(new InsertBlocksBeforeAction(this, newParagraph));
2238
- }
2239
- else {
2240
- const splitBlockAction = new SplitBlockWithNodeAction(splitNode, startOffsetOfNode);
2241
- this.apply(splitBlockAction);
2242
- return splitBlockAction.newBlock;
2243
- }
2244
- return newParagraph;
2245
- }
2246
- /**
2247
- * Breaks a single block of text at a specified offset and returns the first node of the new paragraph if created.
2248
- *
2249
- * @param {RTEImageNode} splitNode - It represents a node in a rich text editor that contains an image.
2250
- * @param {number} startOffset - The index at which the line break should occur within the `RTEImageNode` block.
2251
- * @returns {Nullable<RTETextNode>} Returning the first node of the `newParagraph` block if `newParagraph` is not null.
2252
- */
2253
- lineBreakSingleBlock(splitNode, startOffset) {
2254
- const newParagraph = this.breakSingleBlock(splitNode, startOffset);
2255
- if (newParagraph) {
2256
- return newParagraph['nodes'][0];
2257
- }
2258
- }
2259
- /**
2260
- * Checks if the caret position is at the start of a specified RTEImageNode.
2261
- *
2262
- * @param {RTEImageNode} node - `RTEImageNode` - a node representing an image in a rich text editor.
2263
- * @param {number} startOffset - The position within the text node where the caret is located.
2264
- * @returns {boolean} a boolean value, which indicates whether the caret position is at the start of the RTEImageNode.
2265
- */
2266
- isCaretPositionAtStart(node, startOffset) {
2267
- return node === this.nodes[0] && startOffset === 0;
2268
- }
2269
- /**
2270
- * Checks if the caret position is at the end of a given RTEImageNode.
2271
- *
2272
- * @param {RTEImageNode} node - `node` is a RTEImageNode
2273
- * @param {number} startOffset - The position within the `RTEImageNode` where the caret is located.
2274
- * @returns {boolean}Returns a boolean value indicating whether the caret position is at the end of the `RTEImageNode`.
2275
- */
2276
- isCaretPositionAtEnd(node, startOffset) {
2277
- const lastNode = this.nodes[this.nodes.length - 1];
2278
- return node === lastNode && startOffset === 1;
2279
- }
2280
- /**
2281
- * Inserts a new paragraph block with a line break after a selected block of text in a rich text editor.
2282
- *
2283
- * @param {RTEBlock[]} selectedBlocks - An array of RTEBlock objects that represent the blocks that have been selected for a specific action in the Rich Text Editor.
2284
- * @returns {Nullable<RTETextNode>} Returns a Nullable RTETextNode.
2285
- */
2286
- lineBreakMultipleBlocks(selectedBlocks) {
2287
- const newParagraph = RTETextBlock.from({
2288
- id: createPublicApiRuntimeMetricsSlimmer.generateUUID(),
2289
- type: 'paragraph',
2290
- nodes: [{ id: createPublicApiRuntimeMetricsSlimmer.generateUUID(), type: 'text', text: '\n' }],
2291
- });
2292
- this.parent.apply(new InsertBlocksAfterAction(this, newParagraph));
2293
- const afterNodes = this.concatBlocksNodes(selectedBlocks.slice(1));
2294
- if (afterNodes.length === 0 || (afterNodes[0] && afterNodes[0].text === '')) {
2295
- afterNodes.push(new RTETextNode(createPublicApiRuntimeMetricsSlimmer.generateUUID(), '\n', newParagraph));
2296
- }
2297
- newParagraph.apply(new AppendChildNodesAction(afterNodes));
2298
- return newParagraph['nodes'][0];
2299
- }
2300
- /**
2301
- * Deletes content from a block node based on specific conditions.
2302
- *
2303
- * @param {DeleteBlockContentAction} action - Delete block content action
2304
- */
2305
- deleteNodeContent(action) {
2306
- const startContainerNode = action
2307
- .startContainerNode, startOffset = action.startOffset;
2308
- let previousNode = this.getPreviousNode(startContainerNode);
2309
- let nextNode = null;
2310
- if (startOffset === 1) {
2311
- const parentBlock = startContainerNode.parentBlock;
2312
- if (this.isContentFirstNode(startContainerNode)) {
2313
- nextNode = this.getNextNode(startContainerNode);
2314
- }
2315
- if (parentBlock.nodes.length === 1) {
2316
- parentBlock.parent.apply(new RemoveChildAction(parentBlock));
2317
- }
2318
- else {
2319
- startContainerNode.parentBlock.apply(new RemoveChildAction(startContainerNode));
2320
- }
2321
- }
2322
- else {
2323
- const shouldRemoveNode = previousNode;
2324
- if (shouldRemoveNode && shouldRemoveNode instanceof RTEImageNode) {
2325
- previousNode = this.getPreviousNode(shouldRemoveNode);
2326
- shouldRemoveNode.parentBlock.apply(new RemoveChildAction(shouldRemoveNode));
2327
- if (!previousNode) {
2328
- action.nextNode = startContainerNode;
2329
- }
2330
- }
2331
- }
2332
- if (previousNode) {
2333
- action.previousNode = previousNode;
2334
- }
2335
- else if (nextNode) {
2336
- action.nextNode = nextNode;
2337
- }
2338
- }
2339
- /**
2340
- * Image will always create new image block
2341
- *
2342
- * @param {InsertImageToBlockAction} action insert image to current block
2343
- */
2344
- insertImage(action) {
2345
- const splitNode = action.splitPointNode;
2346
- const startOffsetOfNode = action.startOffsetOfNode;
2347
- const newImageNodes = action.imageBlockToBeInserted.nodes;
2348
- const newImageBlock = action.imageBlockToBeInserted;
2349
- if (this.nodes.length < 1) {
2350
- this.apply(new AppendChildNodesAction(newImageNodes));
2351
- }
2352
- else if (this.isCaretPositionAtEnd(splitNode, startOffsetOfNode)) {
2353
- this.parent.apply(new InsertBlocksAfterAction(this, newImageBlock));
2354
- }
2355
- else if (this.isCaretPositionAtStart(splitNode, startOffsetOfNode)) {
2356
- this.parent.apply(new InsertBlocksBeforeAction(this, newImageBlock));
2357
- }
2358
- else {
2359
- this.apply(new SplitBlockWithNodeAction(splitNode, startOffsetOfNode));
2360
- this.parent.apply(new InsertBlocksAfterAction(this, newImageBlock));
2361
- }
2362
- }
2363
- }
2364
-
2365
- /**
2366
- * List item block
2367
- */
2368
- class RTEListItemBlock extends RTETextBlock {
2369
- constructor(id, children) {
2370
- super(id, 'list-item');
2371
- this.children = [];
2372
- this.children = children;
2373
- }
2374
- /**
2375
- * Converts a VegaRTEListItemBlock object to an RTEListItemBlock
2376
- *
2377
- * @param {VegaRTEListBlock} block - Converts a `VegaRTEListItemBlock` object into an `RTEListItemBlock`.
2378
- * @returns {RTEListBlock} Return an instance of `RTEListItemBlock`
2379
- */
2380
- static from(block) {
2381
- const listItemBlock = new RTEListItemBlock(block.id);
2382
- listItemBlock.nodes = block.nodes.map((richText) => RTETextNode.from(richText, listItemBlock));
2383
- if (block.children) {
2384
- listItemBlock.children = block.children.map((child) => {
2385
- const listBlock = RTEListBlock.from(child);
2386
- listBlock.parent = listItemBlock;
2387
- return listBlock;
2388
- });
2389
- }
2390
- const { annotations } = block;
2391
- if (annotations) {
2392
- Object.entries(annotations).forEach(([type, value]) => {
2393
- const item = this.createAnnotationEntity(type, value);
2394
- if (typeGuard.isNonNullable(item)) {
2395
- listItemBlock.annotationMap.set(...item);
2396
- }
2397
- });
2398
- }
2399
- return listItemBlock;
2400
- }
2401
- /**
2402
- * @inheritDoc
2403
- */
2404
- toJSON() {
2405
- var _a;
2406
- return Object.assign(Object.assign({}, super.toJSON()), { type: 'list-item', children: (_a = this.children) === null || _a === void 0 ? void 0 : _a.map((block) => block.toJSON()) });
2407
- }
2408
- /**
2409
- * @inheritDoc
2410
- */
2411
- cloneWithNodes(nodes) {
2412
- const block = new RTEListItemBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID());
2413
- block.nodes = [];
2414
- block.apply(new AppendChildNodesAction(nodes));
2415
- return block;
2416
- }
2417
- /**
2418
- * @inheritDoc
2419
- */
2420
- isNotEmpty() {
2421
- if (this.children) {
2422
- return super.isNotEmpty() || this.children.some((block) => block.isNotEmpty());
2423
- }
2424
- else {
2425
- return super.isNotEmpty();
2426
- }
2427
- }
2428
- /**
2429
- * @inheritDoc
2430
- */
2431
- getLastNode() {
2432
- if (this.children && this.children.length > 0) {
2433
- const childListBlock = this.children[this.children.length - 1];
2434
- return childListBlock.getLastNode();
2435
- }
2436
- return super.getLastNode();
2437
- }
2438
- /**
2439
- * Apply a modify action to block
2440
- *
2441
- * @param {ModifyContentAction} action - Modify action
2442
- */
2443
- doModifyActionApply(action) {
2444
- switch (action.type) {
2445
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD:
2446
- this.removeListChildNode(action);
2447
- break;
2448
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_NEST_LIST:
2449
- this.removeNestList(action);
2450
- break;
2451
- case nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES:
2452
- this.appendChildNodes(action.entityToBeAppended);
2453
- break;
2454
- case nodeAnnotation_abstract.ModifyContentActionType.CLEAR_CHILD_NODES:
2455
- this.nodes = [];
2456
- break;
2457
- case nodeAnnotation_abstract.ModifyContentActionType.SPLIT_BLOCK_WITH_NODE:
2458
- this.splitListItemBlock(action);
2459
- break;
2460
- case nodeAnnotation_abstract.ModifyContentActionType.REPLACE_CHILD_NODES:
2461
- this.nodes = [];
2462
- this.appendChildNodes(action.newChildNodes);
2463
- break;
2464
- case nodeAnnotation_abstract.ModifyContentActionType.REPLACE_NEST_LIST:
2465
- this.replaceNestList(action.newList);
2466
- break;
2467
- case nodeAnnotation_abstract.ModifyContentActionType.MERGE_TWO_BLOCKS_NODES:
2468
- this.mergeTwoBlocksNodes(action.blockNeedToBeMerged);
2469
- break;
2470
- case nodeAnnotation_abstract.ModifyContentActionType.BREAK_SINGLE_BLOCK:
2471
- action.newBlock = this.breakSingleListItemBlock(action.startContainerNode, action.startOffset);
2472
- break;
2473
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_SINGLE_BLOCK:
2474
- action.lineBreakNode = this.lineBreakSingleBlock(action.startContainerNode, action.startOffset);
2475
- break;
2476
- case nodeAnnotation_abstract.ModifyContentActionType.LINE_BREAK_MULTIPLE_BLOCKS:
2477
- action.lineBreakNode = this.lineBreakMultipleBlocks(action.selectedBlocks);
2478
- break;
2479
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_BLOCK_CONTENT:
2480
- this.deleteListNodeContent(action);
2481
- break;
2482
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_IMAGE_TO_BLOCK:
2483
- this.parent.apply(action);
2484
- break;
2485
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_NODES_BEFORE:
2486
- this.replaceNodeWithNodes(action.referNode, [
2487
- ...action.nodesToBeInserted,
2488
- action.referNode,
2489
- ]);
2490
- break;
2491
- }
2492
- }
2493
- /**
2494
- * Remove the list child node
2495
- *
2496
- * @param {RemoveChildAction} action - Modify action
2497
- */
2498
- removeListChildNode(action) {
2499
- this.nodes = this.nodes.filter((node) => node !== action.entityToBeRemoved);
2500
- if (this.nodes.length === 0 && (!this.children || !this.children.length)) {
2501
- this.parent.apply(new RemoveChildAction(this));
2502
- }
2503
- }
2504
- /**
2505
- * Remove the nest list
2506
- *
2507
- * @param {RemoveNestListAction} action - Modify action
2508
- */
2509
- removeNestList(action) {
2510
- if (this.children) {
2511
- if (this.children.length > 1) {
2512
- this.children = this.children.filter((child) => child !== action.nestListBlockToBeRemoved);
2513
- }
2514
- else {
2515
- this.children = undefined;
2516
- }
2517
- }
2518
- }
2519
- /**
2520
- * Iterates through a list of RTEListBlock and sets their parent property to the current object, then replaces the children property with the new list.
2521
- *
2522
- * @param {RTEListBlock[]} newList - new list that you want to replace the existing children of the current object with.
2523
- */
2524
- replaceNestList(newList) {
2525
- newList.forEach((listBlock) => {
2526
- listBlock.parent = this;
2527
- });
2528
- this.children = newList;
2529
- }
2530
- /**
2531
- * Split list item block
2532
- *
2533
- * @param {SplitBlockWithNodeAction} action - Modify action
2534
- */
2535
- splitListItemBlock(action) {
2536
- action.newBlock = this.splitTextNodeBlock(action.splitPointNode, action.startOffsetOfNode);
2537
- }
2538
- /**
2539
- * Breaks a single list item block at a specific position.
2540
- *
2541
- * @param {RTETextNode} splitNode - The node that needs to be split within a list item block.
2542
- * @param {number} startOffsetOfNode - The index within the `splitNode` where the break operation should occur.
2543
- * @returns {Nullable<RTEBlock>} Returns either a new `RTEListItemBlock` if the caret
2544
- * position is at the end of the `splitNode`, or it returns the result of splitting the block at the
2545
- * caret position if it is neither at the start nor at the end.
2546
- */
2547
- breakSingleListItemBlock(splitNode, startOffsetOfNode) {
2548
- const newListItem = new RTEListItemBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID());
2549
- const newBreakNode = this.copyInlineStyleToNewNode(splitNode);
2550
- newListItem.apply(new AppendChildNodesAction([newBreakNode]));
2551
- if (this.isCaretPositionAtEnd(splitNode, startOffsetOfNode)) {
2552
- return this.breakListItemAtEnd(newListItem);
2553
- }
2554
- else if (this.isCaretPositionAtStart(splitNode, startOffsetOfNode)) {
2555
- this.parent.apply(new InsertBlocksBeforeAction(this, newListItem));
2556
- }
2557
- else {
2558
- const splitBlockAction = new SplitBlockWithNodeAction(splitNode, startOffsetOfNode);
2559
- this.apply(splitBlockAction);
2560
- return splitBlockAction.newBlock;
2561
- }
2562
- return newListItem;
2563
- }
2564
- /**
2565
- * Breaks a list item at the end and handles the insertion of a new list item or paragraph accordingly.
2566
- *
2567
- * @param {RTEListItemBlock} newListItem - Item that represents a new list item to be added to the existing list.
2568
- * @returns {RTEBlock} Returns a `RTEBlock`.
2569
- */
2570
- breakListItemAtEnd(newListItem) {
2571
- const lastItem = this.parent.blocks[this.parent.blocks.length - 1];
2572
- const currentItemIsEmpty = this.nodes.length === 1 && this.nodes[0].isEmpty();
2573
- if (this === lastItem && currentItemIsEmpty) {
2574
- const parentParent = this.parent.parent;
2575
- if (parentParent['type'] !== 'list-item') {
2576
- const newParagraph = RTETextBlock.from({
2577
- id: createPublicApiRuntimeMetricsSlimmer.generateUUID(),
2578
- type: 'paragraph',
2579
- nodes: [],
2580
- });
2581
- newParagraph.apply(new AppendChildNodesAction(newListItem.nodes));
2582
- parentParent.apply(new InsertBlocksAfterAction(this.parent, newParagraph));
2583
- this.parent.apply(new RemoveChildAction(this));
2584
- return newParagraph;
2585
- }
2586
- else {
2587
- parentParent.parent.apply(new InsertBlocksAfterAction(parentParent, newListItem));
2588
- this.parent.apply(new RemoveChildAction(this));
2589
- }
2590
- }
2591
- else {
2592
- this.parent.apply(new InsertBlocksAfterAction(this, newListItem));
2593
- }
2594
- return newListItem;
2595
- }
2596
- /**
2597
- * Delete list node content
2598
- *
2599
- * @param {DeleteBlockContentAction} action - Modify action
2600
- */
2601
- deleteListNodeContent(action) {
2602
- const startContainerNode = action.startContainerNode;
2603
- const listBlock = startContainerNode.parentBlock.parent;
2604
- this.deleteNodeContent(action);
2605
- if (listBlock.blocks.length === 0) {
2606
- listBlock.parent.apply(new RemoveChildAction(listBlock));
2607
- }
2608
- }
2609
- /**
2610
- * Copy the inline style to new node
2611
- *
2612
- * @param {RTETextNode} needCopedNode - The node that needed to be copied to
2613
- * @returns {RTETextNode} Returns a `RTETextNode`.
2614
- */
2615
- copyInlineStyleToNewNode(needCopedNode) {
2616
- const textNode = needCopedNode.cloneWithText('');
2617
- // The link annotation doesn't need to inherit
2618
- textNode.annotationMap.delete(nodeAnnotation_abstract.NodeAnnotationTypeEnum.LINK);
2619
- return textNode;
2620
- }
2621
- }
2622
-
2623
- /**
2624
- * Delete the nest list block action
2625
- *
2626
- * @example needRemovedNestList.parent.apply(new RemoveNestListAction(needRemovedNestList))
2627
- */
2628
- class RemoveNestListAction extends nodeAnnotation_abstract.ModifyContentAction {
2629
- constructor(childList) {
2630
- super();
2631
- this.type = nodeAnnotation_abstract.ModifyContentActionType.DELETE_NEST_LIST;
2632
- this.nestListBlockToBeRemoved = childList;
2633
- }
2634
- }
2635
-
2636
- /**
2637
- * List block
2638
- */
2639
- class RTEListBlock extends RTEBlock {
2640
- constructor(id, type) {
2641
- super(id);
2642
- this.type = 'bullet-list';
2643
- this.blocks = [];
2644
- this.type = type;
2645
- }
2646
- /**
2647
- * Converts a VegaRTEListBlock object to an RTEListBlock
2648
- *
2649
- * @param {VegaRTEListBlock} block - Converts a `VegaRTEListBlock` object into an `RTEListBlock`.
2650
- * @returns {RTEListBlock} Return an instance of `RTEListBlock`
2651
- */
2652
- static from(block) {
2653
- const listBlock = new RTEListBlock(block.id, block.type);
2654
- listBlock.blocks = block.blocks.map((item) => {
2655
- const listItemBlock = RTEListItemBlock.from(item);
2656
- listItemBlock.parent = listBlock;
2657
- return listItemBlock;
2658
- });
2659
- return listBlock;
2660
- }
2661
- /**
2662
- * @inheritDoc
2663
- */
2664
- toJSON() {
2665
- return Object.assign(Object.assign({}, super.toJSON()), { id: this.id, type: this.type, blocks: this.blocks.map((block) => block.toJSON()) });
2666
- }
2667
- /**
2668
- * @inheritDoc
2669
- */
2670
- isNotEmpty() {
2671
- return (this.blocks.length > 0 &&
2672
- this.blocks.some((listItemBlock) => listItemBlock.isNotEmpty()));
2673
- }
2674
- /**
2675
- * @inheritDoc
2676
- */
2677
- getLastNode() {
2678
- return this.blocks[this.blocks.length - 1].getLastNode();
2679
- }
2680
- /**
2681
- * Apply a modify action to block
2682
- *
2683
- * @param {ModifyContentAction} action - Modify action
2684
- */
2685
- doModifyActionApply(action) {
2686
- switch (action.type) {
2687
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD:
2688
- this.removeListItemBlock(action.entityToBeRemoved);
2689
- break;
2690
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_AFTER:
2691
- this.replaceBlockWithBlocks(action.referBlock, [
2692
- action.referBlock,
2693
- ...action.blocksToBeInserted,
2694
- ]);
2695
- break;
2696
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_BEFORE:
2697
- this.replaceBlockWithBlocks(action.referBlock, [
2698
- ...action.blocksToBeInserted,
2699
- action.referBlock,
2700
- ]);
2701
- break;
2702
- case nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES:
2703
- this.appendChildBlocks(action.entityToBeAppended);
2704
- break;
2705
- case nodeAnnotation_abstract.ModifyContentActionType.TRANSFORM_LIST_BLOCK:
2706
- this.convertToList(action);
2707
- break;
2708
- case nodeAnnotation_abstract.ModifyContentActionType.TRANSFORM_PARAGRAPH_BLOCK:
2709
- this.convertToParagraph(action);
2710
- break;
2711
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_IMAGE_TO_BLOCK:
2712
- this.insertImage(action);
2713
- break;
2714
- }
2715
- }
2716
- /**
2717
- * Converts a RTEListItemBlock to a RTETextBlock representing a paragraph.
2718
- *
2719
- * @param {RTEListItemBlock} block - The block that will be covered
2720
- * @returns {RTETextBlock} Returns a `RTETextBlock`.
2721
- */
2722
- toParagraph(block) {
2723
- const textBlock = new RTETextBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID(), 'paragraph');
2724
- textBlock.apply(new AppendChildNodesAction(block['nodes']));
2725
- textBlock['annotationMap'] = block['annotationMap'];
2726
- return textBlock;
2727
- }
2728
- /**
2729
- * Covert block to List
2730
- *
2731
- * @param {TransformListAction} action - Modify action
2732
- */
2733
- convertToList(action) {
2734
- const selectedBlocks = action.selectedBlocks;
2735
- const bulletList = this.parent.createList(action.listType);
2736
- const isSameList = selectedBlocks.every((block) => block.parent === this);
2737
- if (isSameList) {
2738
- // Select one or more list items belonging to the same list, and all items in this list should be updated
2739
- bulletList.apply(new AppendChildNodesAction(this.blocks));
2740
- this.parent.apply(new InsertBlocksAfterAction(this, bulletList));
2741
- this.parent.apply(new RemoveChildAction(this));
2742
- selectedBlocks.forEach((block) => block.nodes.map((node) => node.apply(new SyncUpSelectionAction())));
2743
- }
2744
- else {
2745
- const listItems = action.selectedBlocks.map((block) => this.parent.toListItem(block));
2746
- bulletList.apply(new AppendChildNodesAction(listItems));
2747
- this.parent.apply(new InsertBlocksAfterAction(this, bulletList));
2748
- action.selectedBlocks.forEach((block) => {
2749
- block.parent.apply(new RemoveChildAction(block));
2750
- });
2751
- if (this.blocks.length === 0) {
2752
- this.parent.apply(new RemoveChildAction(this));
2753
- }
2754
- }
2755
- }
2756
- /**
2757
- * Covert block to paragraph
2758
- *
2759
- * @param {TransformListAction} action - Modify action
2760
- */
2761
- convertToParagraph(action) {
2762
- let isSelectedFirstBlock = false;
2763
- let isSelectedLastBlock = false;
2764
- const selectedBlocks = action.selectedBlocks;
2765
- const currentParagraph = selectedBlocks.map((block) => {
2766
- block.nodes.map((node) => node.apply(new SyncUpSelectionAction()));
2767
- if (block === this.blocks[0])
2768
- isSelectedFirstBlock = true;
2769
- if (block === this.blocks[this.blocks.length - 1])
2770
- isSelectedLastBlock = true;
2771
- return this.toParagraph(block);
2772
- });
2773
- if (isSelectedFirstBlock) {
2774
- this.parent.apply(new InsertBlocksBeforeAction(this, ...currentParagraph));
2775
- }
2776
- else if (isSelectedLastBlock) {
2777
- this.parent.apply(new InsertBlocksAfterAction(this, ...currentParagraph));
2778
- }
2779
- else {
2780
- const startIndex = this.blocks.indexOf(selectedBlocks[0]);
2781
- const lastIndex = this.blocks.indexOf(selectedBlocks[selectedBlocks.length - 1]);
2782
- const firstBulletList = this.parent.createList(this.type);
2783
- firstBulletList.apply(new AppendChildNodesAction(this.blocks.slice(0, startIndex)));
2784
- const lastBulletList = this.parent.createList(this.type);
2785
- lastBulletList.apply(new AppendChildNodesAction(this.blocks.slice(lastIndex + 1)));
2786
- this.parent.apply(new InsertBlocksBeforeAction(this, firstBulletList, ...currentParagraph, lastBulletList));
2787
- this.parent.apply(new RemoveChildAction(this));
2788
- }
2789
- selectedBlocks.map((block) => {
2790
- this.apply(new RemoveChildAction(block));
2791
- });
2792
- if (this.blocks.length === 0) {
2793
- this.parent.apply(new RemoveChildAction(this));
2794
- }
2795
- }
2796
- /**
2797
- * Inserts an image block into a rich text editor block based on the parent block type.
2798
- *
2799
- * @param {InsertImageToBlockAction} action - Modify action
2800
- */
2801
- insertImage(action) {
2802
- const imageBlock = action.imageBlockToBeInserted;
2803
- if (this.parent['type'] !== 'list-item') {
2804
- this.parent.apply(new InsertBlocksAfterAction(this, imageBlock));
2805
- }
2806
- else {
2807
- this.parent.apply(action);
2808
- }
2809
- }
2810
- /**
2811
- * Removes a specified block and handles the removal of nested lists if necessary.
2812
- *
2813
- * @param {RTEBlock} blockToBeRemoved - block that will be removed
2814
- */
2815
- removeListItemBlock(blockToBeRemoved) {
2816
- super.removeChildBlock(blockToBeRemoved);
2817
- if (this.blocks.length === 0 && this.parent) {
2818
- // The parent is a list item mean the current block is a nest list, so we need to use RemoveNestListAction to remove the item
2819
- if (this.parent instanceof RTEListItemBlock) {
2820
- this.parent.apply(new RemoveNestListAction(this));
2821
- }
2822
- else {
2823
- this.parent.apply(new RemoveChildAction(this));
2824
- }
2825
- }
2826
- }
2827
- }
2828
-
2829
- /**
2830
- * Class representing the content state of the rich text editor.
2831
- */
2832
- class VegaRTEContent extends BlockBaseOperator {
2833
- constructor(blocks) {
2834
- super();
2835
- blocks.forEach((block) => {
2836
- block.parent = this;
2837
- });
2838
- this.blocks = blocks;
2839
- }
2840
- /**
2841
- * Converts a JSON array of blocks to a class array of RTEContentBlock.
2842
- *
2843
- * @param {VegaRTEContentBlock[]} value The JSON array of blocks to convert.
2844
- * @returns {RTEContentBlock[]} The converted array of RTEContentBlock.
2845
- */
2846
- static fromJSON(value) {
2847
- const blocks = value.map((block) => {
2848
- switch (block.type) {
2849
- case 'paragraph':
2850
- case 'title':
2851
- case 'subtitle':
2852
- case 'heading-1':
2853
- case 'heading-2':
2854
- case 'heading-3': {
2855
- return RTETextBlock.from(block);
2856
- }
2857
- case 'image':
2858
- return RTEImageBlock.from(block);
2859
- case 'bullet-list':
2860
- case 'number-list':
2861
- return RTEListBlock.from(block);
2862
- default: {
2863
- throw new Error(`[Vega] Unknown block type: ${block.type}`);
2864
- }
2865
- }
2866
- });
2867
- return new VegaRTEContent(blocks);
2868
- }
2869
- /**
2870
- * Create an empty content state
2871
- *
2872
- * @returns {VegaRTEContent} An empty content state
2873
- */
2874
- static createEmptyContent() {
2875
- return VegaRTEContent.fromJSON([
2876
- {
2877
- id: createPublicApiRuntimeMetricsSlimmer.generateUUID(),
2878
- type: 'paragraph',
2879
- nodes: [
2880
- {
2881
- id: createPublicApiRuntimeMetricsSlimmer.generateUUID(),
2882
- type: 'text',
2883
- text: '',
2884
- },
2885
- ],
2886
- },
2887
- ]);
2888
- }
2889
- /**
2890
- * Clones the content state.
2891
- *
2892
- * @returns {VegaRTEContent} The cloned content state.
2893
- */
2894
- clone() {
2895
- return new VegaRTEContent([...this.blocks]);
2896
- }
2897
- /**
2898
- * Converts the content state to a JSON array of blocks.
2899
- *
2900
- * @returns {VegaRTEContentBlock[]} The JSON array of blocks.
2901
- */
2902
- toJSON() {
2903
- return this.blocks.map((block) => block.toJSON());
2904
- }
2905
- /**
2906
- * Internal method to add the block item, remove the block item
2907
- *
2908
- * @param {ModifyContentAction} action - Modify content action
2909
- */
2910
- apply(action) {
2911
- switch (action.type) {
2912
- case nodeAnnotation_abstract.ModifyContentActionType.DELETE_CHILD:
2913
- this.removeChildBlock(action.entityToBeRemoved);
2914
- break;
2915
- case nodeAnnotation_abstract.ModifyContentActionType.APPEND_CHILD_NODES:
2916
- this.appendChildBlocks(action.entityToBeAppended);
2917
- break;
2918
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_AFTER:
2919
- this.replaceBlockWithBlocks(action.referBlock, [
2920
- action.referBlock,
2921
- ...action.blocksToBeInserted,
2922
- ]);
2923
- break;
2924
- case nodeAnnotation_abstract.ModifyContentActionType.INSERT_BLOCKS_BEFORE:
2925
- this.replaceBlockWithBlocks(action.referBlock, [
2926
- ...action.blocksToBeInserted,
2927
- action.referBlock,
2928
- ]);
2929
- break;
2930
- }
2931
- }
2932
- /**
2933
- * Convert text to list.
2934
- *
2935
- * @param {RTETextBlock} block - block
2936
- * @returns {RTEListItemBlock} list item block dto.
2937
- */
2938
- toListItem(block) {
2939
- block.nodes.map((node) => node.apply(new SyncUpSelectionAction()));
2940
- const listItemBlock = new RTEListItemBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID());
2941
- listItemBlock.apply(new AppendChildNodesAction(block['nodes']));
2942
- listItemBlock['annotationMap'] = block['annotationMap'];
2943
- return listItemBlock;
2944
- }
2945
- /**
2946
- * create list.
2947
- *
2948
- * @param {ListType} type - type
2949
- * @returns {RTEListBlock} list block dto.
2950
- */
2951
- createList(type) {
2952
- return new RTEListBlock(createPublicApiRuntimeMetricsSlimmer.generateUUID(), type);
2953
- }
2954
- }
2955
-
2956
- exports.AnnotationAction = AnnotationAction;
2957
- exports.AppendChildNodesAction = AppendChildNodesAction;
2958
- exports.BoldAnnotation = BoldAnnotation;
2959
- exports.BoldAnnotationAction = BoldAnnotationAction;
2960
- exports.ClearFormattingAnnotationAction = ClearFormattingAnnotationAction;
2961
- exports.CodeAnnotationAction = CodeAnnotationAction;
2962
- exports.HorizontalAlignmentAnnotation = HorizontalAlignmentAnnotation;
2963
- exports.ImageAnnotation = ImageAnnotation;
2964
- exports.IndentAnnotation = IndentAnnotation;
2965
- exports.InsertBlocksAfterAction = InsertBlocksAfterAction;
2966
- exports.InsertBlocksBeforeAction = InsertBlocksBeforeAction;
2967
- exports.ItalicAnnotation = ItalicAnnotation;
2968
- exports.LinkAnnotationAction = LinkAnnotationAction;
2969
- exports.MergeTwoBlocksNodesAction = MergeTwoBlocksNodesAction;
2970
- exports.RTEBlock = RTEBlock;
2971
- exports.RTEImageBlock = RTEImageBlock;
2972
- exports.RTEImageNode = RTEImageNode;
2973
- exports.RTEListBlock = RTEListBlock;
2974
- exports.RTEListItemBlock = RTEListItemBlock;
2975
- exports.RTETextBlock = RTETextBlock;
2976
- exports.RTETextNode = RTETextNode;
2977
- exports.RTE_TEXT_COLORS = RTE_TEXT_COLORS;
2978
- exports.RemoveChildAction = RemoveChildAction;
2979
- exports.ReplaceChildNodesAction = ReplaceChildNodesAction;
2980
- exports.SelectionRangeAnnotation = SelectionRangeAnnotation;
2981
- exports.SplitBlockWithNodeAction = SplitBlockWithNodeAction;
2982
- exports.StrikethroughAnnotation = StrikethroughAnnotation;
2983
- exports.TextColorAnnotation = TextColorAnnotation;
2984
- exports.TextSplittableAction = TextSplittableAction;
2985
- exports.TextStyleAnnotation = TextStyleAnnotation;
2986
- exports.TextStyleAnnotationAction = TextStyleAnnotationAction;
2987
- exports.UnderlineAnnotation = UnderlineAnnotation;
2988
- exports.UpdateTextAction = UpdateTextAction;
2989
- exports.VegaRTEContent = VegaRTEContent;
2990
- exports.ZERO_WIDTH_SPACE = ZERO_WIDTH_SPACE;