@squiz/formatted-text-editor 0.0.0-rbv2-20240530041851

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 (457) hide show
  1. package/.eslintrc.json +41 -0
  2. package/CHANGELOG.md +155 -0
  3. package/README.md +74 -0
  4. package/build.js +21 -0
  5. package/coverage/clover.xml +1544 -0
  6. package/coverage/coverage-final.json +74 -0
  7. package/coverage/lcov-report/base.css +224 -0
  8. package/coverage/lcov-report/block-navigation.js +87 -0
  9. package/coverage/lcov-report/favicon.png +0 -0
  10. package/coverage/lcov-report/index.html +911 -0
  11. package/coverage/lcov-report/prettify.css +1 -0
  12. package/coverage/lcov-report/prettify.js +2 -0
  13. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  14. package/coverage/lcov-report/sorter.js +196 -0
  15. package/coverage/lcov-report/src/Editor/Editor.tsx.html +436 -0
  16. package/coverage/lcov-report/src/Editor/EditorContext.ts.html +145 -0
  17. package/coverage/lcov-report/src/Editor/index.html +131 -0
  18. package/coverage/lcov-report/src/EditorToolbar/FloatingToolbar.tsx.html +271 -0
  19. package/coverage/lcov-report/src/EditorToolbar/Toolbar.tsx.html +265 -0
  20. package/coverage/lcov-report/src/EditorToolbar/Tools/Bold/BoldButton.tsx.html +178 -0
  21. package/coverage/lcov-report/src/EditorToolbar/Tools/Bold/index.html +116 -0
  22. package/coverage/lcov-report/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.tsx.html +229 -0
  23. package/coverage/lcov-report/src/EditorToolbar/Tools/ClearFormatting/index.html +116 -0
  24. package/coverage/lcov-report/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.tsx.html +187 -0
  25. package/coverage/lcov-report/src/EditorToolbar/Tools/HorizontalLine/index.html +116 -0
  26. package/coverage/lcov-report/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx.html +688 -0
  27. package/coverage/lcov-report/src/EditorToolbar/Tools/Image/Form/index.html +116 -0
  28. package/coverage/lcov-report/src/EditorToolbar/Tools/Image/ImageButton.tsx.html +301 -0
  29. package/coverage/lcov-report/src/EditorToolbar/Tools/Image/ImageModal.tsx.html +181 -0
  30. package/coverage/lcov-report/src/EditorToolbar/Tools/Image/index.html +131 -0
  31. package/coverage/lcov-report/src/EditorToolbar/Tools/Italic/ItalicButton.tsx.html +178 -0
  32. package/coverage/lcov-report/src/EditorToolbar/Tools/Italic/index.html +116 -0
  33. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx.html +508 -0
  34. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/Form/index.html +116 -0
  35. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/LinkButton.tsx.html +286 -0
  36. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/LinkModal.tsx.html +196 -0
  37. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx.html +211 -0
  38. package/coverage/lcov-report/src/EditorToolbar/Tools/Link/index.html +146 -0
  39. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/ListButtons.tsx.html +127 -0
  40. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.tsx.html +175 -0
  41. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/OrderedList/index.html +116 -0
  42. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.tsx.html +175 -0
  43. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/UnorderedList/index.html +116 -0
  44. package/coverage/lcov-report/src/EditorToolbar/Tools/Lists/index.html +116 -0
  45. package/coverage/lcov-report/src/EditorToolbar/Tools/Redo/RedoButton.tsx.html +178 -0
  46. package/coverage/lcov-report/src/EditorToolbar/Tools/Redo/index.html +116 -0
  47. package/coverage/lcov-report/src/EditorToolbar/Tools/Table/TableButton.tsx.html +181 -0
  48. package/coverage/lcov-report/src/EditorToolbar/Tools/Table/index.html +116 -0
  49. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx.html +178 -0
  50. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/CenterAlign/index.html +116 -0
  51. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx.html +178 -0
  52. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/JustifyAlign/index.html +116 -0
  53. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx.html +178 -0
  54. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/LeftAlign/index.html +116 -0
  55. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx.html +178 -0
  56. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/RightAlign/index.html +116 -0
  57. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/TextAlignButtons.tsx.html +148 -0
  58. package/coverage/lcov-report/src/EditorToolbar/Tools/TextAlign/index.html +116 -0
  59. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.tsx.html +181 -0
  60. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/CodeBlock/index.html +116 -0
  61. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.tsx.html +241 -0
  62. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Heading/index.html +116 -0
  63. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.tsx.html +160 -0
  64. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Paragraph/index.html +116 -0
  65. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.tsx.html +181 -0
  66. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/Preformatted/index.html +116 -0
  67. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/TextTypeDropdown.tsx.html +247 -0
  68. package/coverage/lcov-report/src/EditorToolbar/Tools/TextType/index.html +116 -0
  69. package/coverage/lcov-report/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx.html +178 -0
  70. package/coverage/lcov-report/src/EditorToolbar/Tools/Underline/index.html +116 -0
  71. package/coverage/lcov-report/src/EditorToolbar/Tools/Undo/UndoButton.tsx.html +178 -0
  72. package/coverage/lcov-report/src/EditorToolbar/Tools/Undo/index.html +116 -0
  73. package/coverage/lcov-report/src/EditorToolbar/index.html +146 -0
  74. package/coverage/lcov-report/src/EditorToolbar/index.ts.html +91 -0
  75. package/coverage/lcov-report/src/Extensions/ClearFormattingExtension/ClearFormattingExtension.ts.html +256 -0
  76. package/coverage/lcov-report/src/Extensions/ClearFormattingExtension/index.html +116 -0
  77. package/coverage/lcov-report/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts.html +187 -0
  78. package/coverage/lcov-report/src/Extensions/CodeBlockExtension/index.html +116 -0
  79. package/coverage/lcov-report/src/Extensions/CommandsExtension/CommandsExtension.ts.html +247 -0
  80. package/coverage/lcov-report/src/Extensions/CommandsExtension/index.html +116 -0
  81. package/coverage/lcov-report/src/Extensions/Extensions.ts.html +349 -0
  82. package/coverage/lcov-report/src/Extensions/FetchUrlExtension/FetchUrlExtension.ts.html +289 -0
  83. package/coverage/lcov-report/src/Extensions/FetchUrlExtension/index.html +116 -0
  84. package/coverage/lcov-report/src/Extensions/ImageExtension/AssetImageExtension.ts.html +412 -0
  85. package/coverage/lcov-report/src/Extensions/ImageExtension/ImageExtension.ts.html +142 -0
  86. package/coverage/lcov-report/src/Extensions/ImageExtension/index.html +131 -0
  87. package/coverage/lcov-report/src/Extensions/LinkExtension/AssetLinkExtension.ts.html +466 -0
  88. package/coverage/lcov-report/src/Extensions/LinkExtension/LinkExtension.ts.html +400 -0
  89. package/coverage/lcov-report/src/Extensions/LinkExtension/common.ts.html +115 -0
  90. package/coverage/lcov-report/src/Extensions/LinkExtension/index.html +146 -0
  91. package/coverage/lcov-report/src/Extensions/PreformattedExtension/PreformattedExtension.ts.html +340 -0
  92. package/coverage/lcov-report/src/Extensions/PreformattedExtension/index.html +116 -0
  93. package/coverage/lcov-report/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.tsx.html +325 -0
  94. package/coverage/lcov-report/src/Extensions/UnsuportedExtension/index.html +116 -0
  95. package/coverage/lcov-report/src/Extensions/index.html +116 -0
  96. package/coverage/lcov-report/src/hooks/index.html +161 -0
  97. package/coverage/lcov-report/src/hooks/index.ts.html +91 -0
  98. package/coverage/lcov-report/src/hooks/useExpandedSelection.ts.html +217 -0
  99. package/coverage/lcov-report/src/hooks/useExtensionNames.ts.html +130 -0
  100. package/coverage/lcov-report/src/hooks/useFocus.ts.html +268 -0
  101. package/coverage/lcov-report/src/index.html +116 -0
  102. package/coverage/lcov-report/src/index.ts.html +112 -0
  103. package/coverage/lcov-report/src/ui/Button/Button.tsx.html +190 -0
  104. package/coverage/lcov-report/src/ui/Button/index.html +116 -0
  105. package/coverage/lcov-report/src/ui/CollapseBox/CollapseBox.tsx.html +193 -0
  106. package/coverage/lcov-report/src/ui/CollapseBox/index.html +116 -0
  107. package/coverage/lcov-report/src/ui/Fields/Checkbox/Checkbox.tsx.html +232 -0
  108. package/coverage/lcov-report/src/ui/Fields/Checkbox/index.html +116 -0
  109. package/coverage/lcov-report/src/ui/Fields/Input/Input.tsx.html +160 -0
  110. package/coverage/lcov-report/src/ui/Fields/Input/index.html +116 -0
  111. package/coverage/lcov-report/src/ui/Fields/InputContainer/InputContainer.tsx.html +172 -0
  112. package/coverage/lcov-report/src/ui/Fields/InputContainer/index.html +116 -0
  113. package/coverage/lcov-report/src/ui/Fields/MatrixAsset/MatrixAsset.tsx.html +256 -0
  114. package/coverage/lcov-report/src/ui/Fields/MatrixAsset/index.html +116 -0
  115. package/coverage/lcov-report/src/ui/Fields/Select/Select.tsx.html +283 -0
  116. package/coverage/lcov-report/src/ui/Fields/Select/index.html +116 -0
  117. package/coverage/lcov-report/src/ui/Modal/FormModal.tsx.html +136 -0
  118. package/coverage/lcov-report/src/ui/Modal/Modal.tsx.html +397 -0
  119. package/coverage/lcov-report/src/ui/Modal/index.html +131 -0
  120. package/coverage/lcov-report/src/ui/Tabs/Tabs.tsx.html +208 -0
  121. package/coverage/lcov-report/src/ui/Tabs/index.html +116 -0
  122. package/coverage/lcov-report/src/ui/ToolbarDropdown/ToolbarDropdown.tsx.html +211 -0
  123. package/coverage/lcov-report/src/ui/ToolbarDropdown/index.html +116 -0
  124. package/coverage/lcov-report/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.tsx.html +184 -0
  125. package/coverage/lcov-report/src/ui/ToolbarDropdownButton/index.html +116 -0
  126. package/coverage/lcov-report/src/utils/converters/htmlToSquizNode/htmlToSquizNode.ts.html +166 -0
  127. package/coverage/lcov-report/src/utils/converters/htmlToSquizNode/index.html +116 -0
  128. package/coverage/lcov-report/src/utils/converters/mocks/index.html +116 -0
  129. package/coverage/lcov-report/src/utils/converters/mocks/squizNodeJson.mock.ts.html +895 -0
  130. package/coverage/lcov-report/src/utils/converters/remirrorNodeToSquizNode/index.html +116 -0
  131. package/coverage/lcov-report/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts.html +976 -0
  132. package/coverage/lcov-report/src/utils/converters/squizNodeToRemirrorNode/index.html +116 -0
  133. package/coverage/lcov-report/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts.html +748 -0
  134. package/coverage/lcov-report/src/utils/createToolbarPositioner.ts.html +469 -0
  135. package/coverage/lcov-report/src/utils/getCursorRect.ts.html +100 -0
  136. package/coverage/lcov-report/src/utils/getMarkNamesByGroup.ts.html +106 -0
  137. package/coverage/lcov-report/src/utils/getNodeNamesByGroup.ts.html +106 -0
  138. package/coverage/lcov-report/src/utils/getShortcutSymbol.ts.html +97 -0
  139. package/coverage/lcov-report/src/utils/index.html +206 -0
  140. package/coverage/lcov-report/src/utils/undefinedIfEmpty.ts.html +94 -0
  141. package/coverage/lcov-report/src/utils/validation.ts.html +133 -0
  142. package/coverage/lcov.info +2737 -0
  143. package/cypress/e2e/bold.spec.cy.ts +18 -0
  144. package/cypress/global.d.ts +9 -0
  145. package/cypress/support/commands.ts +130 -0
  146. package/cypress/support/e2e.ts +20 -0
  147. package/cypress/tsconfig.json +8 -0
  148. package/cypress.config.ts +7 -0
  149. package/demo/App.tsx +107 -0
  150. package/demo/AppContext.tsx +70 -0
  151. package/demo/index.html +13 -0
  152. package/demo/index.scss +33 -0
  153. package/demo/main.tsx +12 -0
  154. package/demo/public/favicon-dxp.svg +3 -0
  155. package/demo/resources.json +204 -0
  156. package/demo/sources.json +27 -0
  157. package/demo/vite-env.d.ts +1 -0
  158. package/file-transformer.js +1 -0
  159. package/jest.bootstrap.ts +3 -0
  160. package/jest.config.ts +27 -0
  161. package/lib/Editor/Editor.d.ts +16 -0
  162. package/lib/Editor/Editor.js +85 -0
  163. package/lib/Editor/EditorContext.d.ts +10 -0
  164. package/lib/Editor/EditorContext.js +16 -0
  165. package/lib/EditorToolbar/FloatingToolbar.d.ts +2 -0
  166. package/lib/EditorToolbar/FloatingToolbar.js +76 -0
  167. package/lib/EditorToolbar/Toolbar.d.ts +7 -0
  168. package/lib/EditorToolbar/Toolbar.js +47 -0
  169. package/lib/EditorToolbar/Tools/Bold/BoldButton.d.ts +3 -0
  170. package/lib/EditorToolbar/Tools/Bold/BoldButton.js +23 -0
  171. package/lib/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.d.ts +3 -0
  172. package/lib/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.js +57 -0
  173. package/lib/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.d.ts +3 -0
  174. package/lib/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.js +25 -0
  175. package/lib/EditorToolbar/Tools/Image/Form/ImageForm.d.ts +18 -0
  176. package/lib/EditorToolbar/Tools/Image/Form/ImageForm.js +143 -0
  177. package/lib/EditorToolbar/Tools/Image/ImageButton.d.ts +6 -0
  178. package/lib/EditorToolbar/Tools/Image/ImageButton.js +76 -0
  179. package/lib/EditorToolbar/Tools/Image/ImageModal.d.ts +9 -0
  180. package/lib/EditorToolbar/Tools/Image/ImageModal.js +24 -0
  181. package/lib/EditorToolbar/Tools/Italic/ItalicButton.d.ts +3 -0
  182. package/lib/EditorToolbar/Tools/Italic/ItalicButton.js +23 -0
  183. package/lib/EditorToolbar/Tools/Link/Form/LinkForm.d.ts +19 -0
  184. package/lib/EditorToolbar/Tools/Link/Form/LinkForm.js +63 -0
  185. package/lib/EditorToolbar/Tools/Link/LinkButton.d.ts +6 -0
  186. package/lib/EditorToolbar/Tools/Link/LinkButton.js +71 -0
  187. package/lib/EditorToolbar/Tools/Link/LinkModal.d.ts +9 -0
  188. package/lib/EditorToolbar/Tools/Link/LinkModal.js +27 -0
  189. package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.d.ts +4 -0
  190. package/lib/EditorToolbar/Tools/Link/RemoveLinkButton.js +54 -0
  191. package/lib/EditorToolbar/Tools/Lists/ListButtons.d.ts +3 -0
  192. package/lib/EditorToolbar/Tools/Lists/ListButtons.js +14 -0
  193. package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.d.ts +3 -0
  194. package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.js +22 -0
  195. package/lib/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.d.ts +3 -0
  196. package/lib/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.js +22 -0
  197. package/lib/EditorToolbar/Tools/Redo/RedoButton.d.ts +3 -0
  198. package/lib/EditorToolbar/Tools/Redo/RedoButton.js +22 -0
  199. package/lib/EditorToolbar/Tools/Table/TableButton.d.ts +3 -0
  200. package/lib/EditorToolbar/Tools/Table/TableButton.js +22 -0
  201. package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.d.ts +3 -0
  202. package/lib/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.js +22 -0
  203. package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.d.ts +3 -0
  204. package/lib/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.js +22 -0
  205. package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.d.ts +3 -0
  206. package/lib/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.js +22 -0
  207. package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.d.ts +3 -0
  208. package/lib/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.js +22 -0
  209. package/lib/EditorToolbar/Tools/TextAlign/TextAlignButtons.d.ts +3 -0
  210. package/lib/EditorToolbar/Tools/TextAlign/TextAlignButtons.js +21 -0
  211. package/lib/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.d.ts +3 -0
  212. package/lib/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.js +22 -0
  213. package/lib/EditorToolbar/Tools/TextType/Heading/HeadingButton.d.ts +6 -0
  214. package/lib/EditorToolbar/Tools/TextType/Heading/HeadingButton.js +37 -0
  215. package/lib/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.d.ts +3 -0
  216. package/lib/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.js +21 -0
  217. package/lib/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.d.ts +3 -0
  218. package/lib/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.js +22 -0
  219. package/lib/EditorToolbar/Tools/TextType/TextTypeDropdown.d.ts +3 -0
  220. package/lib/EditorToolbar/Tools/TextType/TextTypeDropdown.js +46 -0
  221. package/lib/EditorToolbar/Tools/Underline/UnderlineButton.d.ts +3 -0
  222. package/lib/EditorToolbar/Tools/Underline/UnderlineButton.js +23 -0
  223. package/lib/EditorToolbar/Tools/Undo/UndoButton.d.ts +3 -0
  224. package/lib/EditorToolbar/Tools/Undo/UndoButton.js +22 -0
  225. package/lib/EditorToolbar/index.d.ts +2 -0
  226. package/lib/EditorToolbar/index.js +18 -0
  227. package/lib/Extensions/ClearFormattingExtension/ClearFormattingExtension.d.ts +5 -0
  228. package/lib/Extensions/ClearFormattingExtension/ClearFormattingExtension.js +63 -0
  229. package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.d.ts +5 -0
  230. package/lib/Extensions/CodeBlockExtension/CodeBlockExtension.js +30 -0
  231. package/lib/Extensions/CommandsExtension/CommandsExtension.d.ts +20 -0
  232. package/lib/Extensions/CommandsExtension/CommandsExtension.js +52 -0
  233. package/lib/Extensions/Extensions.d.ts +17 -0
  234. package/lib/Extensions/Extensions.js +73 -0
  235. package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.d.ts +12 -0
  236. package/lib/Extensions/FetchUrlExtension/FetchUrlExtension.js +63 -0
  237. package/lib/Extensions/ImageExtension/AssetImageExtension.d.ts +17 -0
  238. package/lib/Extensions/ImageExtension/AssetImageExtension.js +91 -0
  239. package/lib/Extensions/ImageExtension/ImageExtension.d.ts +7 -0
  240. package/lib/Extensions/ImageExtension/ImageExtension.js +18 -0
  241. package/lib/Extensions/LinkExtension/AssetLinkExtension.d.ts +27 -0
  242. package/lib/Extensions/LinkExtension/AssetLinkExtension.js +101 -0
  243. package/lib/Extensions/LinkExtension/LinkExtension.d.ts +23 -0
  244. package/lib/Extensions/LinkExtension/LinkExtension.js +87 -0
  245. package/lib/Extensions/LinkExtension/common.d.ts +7 -0
  246. package/lib/Extensions/LinkExtension/common.js +14 -0
  247. package/lib/Extensions/PreformattedExtension/PreformattedExtension.d.ts +12 -0
  248. package/lib/Extensions/PreformattedExtension/PreformattedExtension.js +76 -0
  249. package/lib/Extensions/UnsuportedExtension/UnsupportedNodeExtension.d.ts +10 -0
  250. package/lib/Extensions/UnsuportedExtension/UnsupportedNodeExtension.js +76 -0
  251. package/lib/hooks/index.d.ts +2 -0
  252. package/lib/hooks/index.js +18 -0
  253. package/lib/hooks/useExpandedSelection.d.ts +23 -0
  254. package/lib/hooks/useExpandedSelection.js +37 -0
  255. package/lib/hooks/useExtensionNames.d.ts +1 -0
  256. package/lib/hooks/useExtensionNames.js +16 -0
  257. package/lib/hooks/useFocus.d.ts +8 -0
  258. package/lib/hooks/useFocus.js +43 -0
  259. package/lib/index.css +1525 -0
  260. package/lib/index.d.ts +8 -0
  261. package/lib/index.js +16 -0
  262. package/lib/types.d.ts +7 -0
  263. package/lib/types.js +2 -0
  264. package/lib/ui/Button/Button.d.ts +12 -0
  265. package/lib/ui/Button/Button.js +13 -0
  266. package/lib/ui/CollapseBox/CollapseBox.d.ts +7 -0
  267. package/lib/ui/CollapseBox/CollapseBox.js +48 -0
  268. package/lib/ui/Fields/Checkbox/Checkbox.d.ts +9 -0
  269. package/lib/ui/Fields/Checkbox/Checkbox.js +47 -0
  270. package/lib/ui/Fields/Input/Input.d.ts +3 -0
  271. package/lib/ui/Fields/Input/Input.js +33 -0
  272. package/lib/ui/Fields/InputContainer/InputContainer.d.ts +9 -0
  273. package/lib/ui/Fields/InputContainer/InputContainer.js +16 -0
  274. package/lib/ui/Fields/MatrixAsset/MatrixAsset.d.ts +19 -0
  275. package/lib/ui/Fields/MatrixAsset/MatrixAsset.js +30 -0
  276. package/lib/ui/Modal/FormModal.d.ts +5 -0
  277. package/lib/ui/Modal/FormModal.js +39 -0
  278. package/lib/ui/Modal/Modal.d.ts +11 -0
  279. package/lib/ui/Modal/Modal.js +79 -0
  280. package/lib/ui/Tabs/Tabs.d.ts +11 -0
  281. package/lib/ui/Tabs/Tabs.js +46 -0
  282. package/lib/ui/ToolbarDropdown/ToolbarDropdown.d.ts +7 -0
  283. package/lib/ui/ToolbarDropdown/ToolbarDropdown.js +48 -0
  284. package/lib/ui/ToolbarDropdownButton/ToolbarDropdownButton.d.ts +11 -0
  285. package/lib/ui/ToolbarDropdownButton/ToolbarDropdownButton.js +15 -0
  286. package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.d.ts +5 -0
  287. package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.js +23 -0
  288. package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.props.d.ts +3 -0
  289. package/lib/utils/converters/htmlToSquizNode/htmlToSquizNode.props.js +2 -0
  290. package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.d.ts +11 -0
  291. package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.js +229 -0
  292. package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.d.ts +9 -0
  293. package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +205 -0
  294. package/lib/utils/createToolbarPositioner.d.ts +18 -0
  295. package/lib/utils/createToolbarPositioner.js +96 -0
  296. package/lib/utils/getCursorRect.d.ts +2 -0
  297. package/lib/utils/getCursorRect.js +7 -0
  298. package/lib/utils/getMarkNamesByGroup.d.ts +2 -0
  299. package/lib/utils/getMarkNamesByGroup.js +9 -0
  300. package/lib/utils/getNodeNamesByGroup.d.ts +2 -0
  301. package/lib/utils/getNodeNamesByGroup.js +9 -0
  302. package/lib/utils/getShortcutSymbol.d.ts +1 -0
  303. package/lib/utils/getShortcutSymbol.js +8 -0
  304. package/lib/utils/undefinedIfEmpty.d.ts +1 -0
  305. package/lib/utils/undefinedIfEmpty.js +7 -0
  306. package/lib/utils/validation.d.ts +3 -0
  307. package/lib/utils/validation.js +16 -0
  308. package/package.json +83 -0
  309. package/postcss.config.js +12 -0
  310. package/src/Editor/Editor.spec.tsx +465 -0
  311. package/src/Editor/Editor.tsx +117 -0
  312. package/src/Editor/EditorContext.spec.tsx +25 -0
  313. package/src/Editor/EditorContext.ts +20 -0
  314. package/src/Editor/_editor.scss +430 -0
  315. package/src/EditorToolbar/FloatingToolbar.spec.tsx +49 -0
  316. package/src/EditorToolbar/FloatingToolbar.tsx +62 -0
  317. package/src/EditorToolbar/Toolbar.tsx +60 -0
  318. package/src/EditorToolbar/Tools/Bold/BoldButton.spec.tsx +19 -0
  319. package/src/EditorToolbar/Tools/Bold/BoldButton.tsx +31 -0
  320. package/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.spec.tsx +34 -0
  321. package/src/EditorToolbar/Tools/ClearFormatting/ClearFormattingButton.tsx +48 -0
  322. package/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.spec.tsx +23 -0
  323. package/src/EditorToolbar/Tools/HorizontalLine/HorizontalLineButton.tsx +34 -0
  324. package/src/EditorToolbar/Tools/Image/Form/ImageForm.spec.tsx +117 -0
  325. package/src/EditorToolbar/Tools/Image/Form/ImageForm.tsx +201 -0
  326. package/src/EditorToolbar/Tools/Image/ImageButton.spec.tsx +385 -0
  327. package/src/EditorToolbar/Tools/Image/ImageButton.tsx +72 -0
  328. package/src/EditorToolbar/Tools/Image/ImageModal.spec.tsx +123 -0
  329. package/src/EditorToolbar/Tools/Image/ImageModal.tsx +32 -0
  330. package/src/EditorToolbar/Tools/Italic/ItalicButton.spec.tsx +19 -0
  331. package/src/EditorToolbar/Tools/Italic/ItalicButton.tsx +31 -0
  332. package/src/EditorToolbar/Tools/Link/Form/LinkForm.spec.tsx +79 -0
  333. package/src/EditorToolbar/Tools/Link/Form/LinkForm.tsx +141 -0
  334. package/src/EditorToolbar/Tools/Link/LinkButton.spec.tsx +402 -0
  335. package/src/EditorToolbar/Tools/Link/LinkButton.tsx +67 -0
  336. package/src/EditorToolbar/Tools/Link/LinkModal.tsx +37 -0
  337. package/src/EditorToolbar/Tools/Link/RemoveLinkButton.spec.tsx +143 -0
  338. package/src/EditorToolbar/Tools/Link/RemoveLinkButton.tsx +42 -0
  339. package/src/EditorToolbar/Tools/Lists/ListButtons.tsx +14 -0
  340. package/src/EditorToolbar/Tools/Lists/OrderedList/OrderListButton.spec.tsx +39 -0
  341. package/src/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.tsx +30 -0
  342. package/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedList.spec.tsx +19 -0
  343. package/src/EditorToolbar/Tools/Lists/UnorderedList/UnorderedListButton.tsx +30 -0
  344. package/src/EditorToolbar/Tools/Redo/RedoButton.spec.tsx +59 -0
  345. package/src/EditorToolbar/Tools/Redo/RedoButton.tsx +31 -0
  346. package/src/EditorToolbar/Tools/Table/TableButton.spec.tsx +25 -0
  347. package/src/EditorToolbar/Tools/Table/TableButton.tsx +32 -0
  348. package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.spec.tsx +39 -0
  349. package/src/EditorToolbar/Tools/TextAlign/CenterAlign/CenterAlignButton.tsx +31 -0
  350. package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.spec.tsx +39 -0
  351. package/src/EditorToolbar/Tools/TextAlign/JustifyAlign/JustifyAlignButton.tsx +31 -0
  352. package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.spec.tsx +39 -0
  353. package/src/EditorToolbar/Tools/TextAlign/LeftAlign/LeftAlignButton.tsx +31 -0
  354. package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.spec.tsx +39 -0
  355. package/src/EditorToolbar/Tools/TextAlign/RightAlign/RightAlignButton.tsx +31 -0
  356. package/src/EditorToolbar/Tools/TextAlign/TextAlignButtons.tsx +21 -0
  357. package/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.spec.tsx +47 -0
  358. package/src/EditorToolbar/Tools/TextType/CodeBlock/CodeBlockButton.tsx +32 -0
  359. package/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.spec.tsx +56 -0
  360. package/src/EditorToolbar/Tools/TextType/Heading/HeadingButton.tsx +52 -0
  361. package/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.spec.tsx +30 -0
  362. package/src/EditorToolbar/Tools/TextType/Paragraph/ParagraphButton.tsx +25 -0
  363. package/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.spec.tsx +47 -0
  364. package/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.tsx +32 -0
  365. package/src/EditorToolbar/Tools/TextType/TextTypeDropdown.spec.tsx +51 -0
  366. package/src/EditorToolbar/Tools/TextType/TextTypeDropdown.tsx +54 -0
  367. package/src/EditorToolbar/Tools/Underline/Underline.spec.tsx +19 -0
  368. package/src/EditorToolbar/Tools/Underline/UnderlineButton.tsx +31 -0
  369. package/src/EditorToolbar/Tools/Undo/UndoButton.spec.tsx +70 -0
  370. package/src/EditorToolbar/Tools/Undo/UndoButton.tsx +31 -0
  371. package/src/EditorToolbar/_floating-toolbar.scss +9 -0
  372. package/src/EditorToolbar/_toolbar.scss +37 -0
  373. package/src/EditorToolbar/index.ts +2 -0
  374. package/src/Extensions/ClearFormattingExtension/ClearFormattingExtension.ts +57 -0
  375. package/src/Extensions/CodeBlockExtension/CodeBlockExtension.ts +34 -0
  376. package/src/Extensions/CommandsExtension/CommandsExtension.ts +54 -0
  377. package/src/Extensions/Extensions.ts +88 -0
  378. package/src/Extensions/FetchUrlExtension/FetchUrlExtension.ts +68 -0
  379. package/src/Extensions/ImageExtension/AssetImageExtension.spec.ts +77 -0
  380. package/src/Extensions/ImageExtension/AssetImageExtension.ts +109 -0
  381. package/src/Extensions/ImageExtension/ImageExtension.ts +19 -0
  382. package/src/Extensions/LinkExtension/AssetLinkExtension.spec.ts +106 -0
  383. package/src/Extensions/LinkExtension/AssetLinkExtension.ts +127 -0
  384. package/src/Extensions/LinkExtension/LinkExtension.spec.ts +68 -0
  385. package/src/Extensions/LinkExtension/LinkExtension.ts +105 -0
  386. package/src/Extensions/LinkExtension/common.ts +10 -0
  387. package/src/Extensions/PreformattedExtension/PreformattedExtension.spec.ts +43 -0
  388. package/src/Extensions/PreformattedExtension/PreformattedExtension.ts +85 -0
  389. package/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.spec.ts +137 -0
  390. package/src/Extensions/UnsuportedExtension/UnsupportedNodeExtension.tsx +80 -0
  391. package/src/hooks/index.ts +2 -0
  392. package/src/hooks/useExpandedSelection.ts +44 -0
  393. package/src/hooks/useExtensionNames.ts +15 -0
  394. package/src/hooks/useFocus.ts +61 -0
  395. package/src/index.scss +24 -0
  396. package/src/index.ts +9 -0
  397. package/src/types.ts +10 -0
  398. package/src/ui/Button/Button.spec.tsx +44 -0
  399. package/src/ui/Button/Button.tsx +35 -0
  400. package/src/ui/Button/_button.scss +37 -0
  401. package/src/ui/CollapseBox/CollapseBox.spec.tsx +49 -0
  402. package/src/ui/CollapseBox/CollapseBox.tsx +36 -0
  403. package/src/ui/CollapseBox/_collapseBox.scss +23 -0
  404. package/src/ui/Fields/Checkbox/Checkbox.spec.tsx +50 -0
  405. package/src/ui/Fields/Checkbox/Checkbox.tsx +49 -0
  406. package/src/ui/Fields/Checkbox/_checkbox.scss +26 -0
  407. package/src/ui/Fields/Input/Input.spec.tsx +49 -0
  408. package/src/ui/Fields/Input/Input.tsx +25 -0
  409. package/src/ui/Fields/InputContainer/InputContainer.spec.tsx +18 -0
  410. package/src/ui/Fields/InputContainer/InputContainer.tsx +29 -0
  411. package/src/ui/Fields/MatrixAsset/MatrixAsset.spec.tsx +121 -0
  412. package/src/ui/Fields/MatrixAsset/MatrixAsset.tsx +57 -0
  413. package/src/ui/Fields/Select/Select.spec.tsx +30 -0
  414. package/src/ui/Fields/Select/Select.tsx +66 -0
  415. package/src/ui/Modal/FormModal.spec.tsx +21 -0
  416. package/src/ui/Modal/FormModal.tsx +17 -0
  417. package/src/ui/Modal/Modal.spec.tsx +136 -0
  418. package/src/ui/Modal/Modal.tsx +104 -0
  419. package/src/ui/Modal/_modal.scss +24 -0
  420. package/src/ui/Tabs/Tabs.spec.tsx +44 -0
  421. package/src/ui/Tabs/Tabs.tsx +41 -0
  422. package/src/ui/ToolbarDropdown/ToolbarDropdown.spec.tsx +80 -0
  423. package/src/ui/ToolbarDropdown/ToolbarDropdown.tsx +42 -0
  424. package/src/ui/ToolbarDropdown/_toolbar-dropdown.scss +32 -0
  425. package/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.spec.tsx +48 -0
  426. package/src/ui/ToolbarDropdownButton/ToolbarDropdownButton.tsx +33 -0
  427. package/src/ui/ToolbarDropdownButton/_toolbar-dropdown-button.scss +25 -0
  428. package/src/ui/_forms.scss +32 -0
  429. package/src/ui/_typography.scss +95 -0
  430. package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.props.ts +3 -0
  431. package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.spec.ts +179 -0
  432. package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.ts +27 -0
  433. package/src/utils/converters/mocks/squizNodeJson.mock.ts +270 -0
  434. package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +1058 -0
  435. package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +297 -0
  436. package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +878 -0
  437. package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +221 -0
  438. package/src/utils/createToolbarPositioner.ts +128 -0
  439. package/src/utils/getCursorRect.ts +5 -0
  440. package/src/utils/getMarkNamesByGroup.spec.ts +20 -0
  441. package/src/utils/getMarkNamesByGroup.ts +7 -0
  442. package/src/utils/getNodeNamesByGroup.spec.ts +37 -0
  443. package/src/utils/getNodeNamesByGroup.ts +7 -0
  444. package/src/utils/getShortcutSymbol.spec.ts +27 -0
  445. package/src/utils/getShortcutSymbol.ts +4 -0
  446. package/src/utils/undefinedIfEmpty.spec.ts +12 -0
  447. package/src/utils/undefinedIfEmpty.ts +3 -0
  448. package/src/utils/validation.spec.ts +22 -0
  449. package/src/utils/validation.ts +16 -0
  450. package/tailwind.config.cjs +87 -0
  451. package/tests/index.ts +4 -0
  452. package/tests/mockResourceBrowserContext.tsx +99 -0
  453. package/tests/renderWithContext.tsx +75 -0
  454. package/tests/renderWithEditor.tsx +123 -0
  455. package/tests/select.ts +16 -0
  456. package/tsconfig.json +22 -0
  457. package/vite.config.ts +27 -0
@@ -0,0 +1,1058 @@
1
+ import { FORMATTED_TEXT_MODELS as FormattedTextModels } from '@squiz/dx-json-schema-lib';
2
+ import { remirrorNodeToSquizNode, resolveNodeTag } from './remirrorNodeToSquizNode';
3
+ import { renderWithEditor } from '../../../../tests';
4
+ import { RemirrorJSON } from '@remirror/core';
5
+ import { sharedNodeExamples } from '../mocks/squizNodeJson.mock';
6
+ import { ParagraphExtension, SupExtension } from 'remirror/extensions';
7
+
8
+ type FormattedText = FormattedTextModels.v1.FormattedText;
9
+ type FormattingOptions = FormattedTextModels.v1.FormattingOptions;
10
+
11
+ describe('remirrorNodeToSquizNode', () => {
12
+ it('should convert a simple Remirror node to a Squiz component JSON object', async () => {
13
+ const content: RemirrorJSON = {
14
+ type: 'doc',
15
+ content: [
16
+ {
17
+ type: 'paragraph',
18
+ content: [
19
+ {
20
+ type: 'text',
21
+ text: 'Hello world!',
22
+ },
23
+ ],
24
+ },
25
+ ],
26
+ };
27
+
28
+ const { editor } = await renderWithEditor(null, { content });
29
+
30
+ const expected: FormattedText = [
31
+ {
32
+ type: 'tag',
33
+ tag: 'p',
34
+ children: [{ type: 'text', value: 'Hello world!' }],
35
+ },
36
+ ];
37
+
38
+ const result = remirrorNodeToSquizNode(editor.doc);
39
+ expect(result).toEqual(expected);
40
+ });
41
+
42
+ it('should handle preformatted formatting', async () => {
43
+ const content: RemirrorJSON = {
44
+ type: 'doc',
45
+ content: [
46
+ {
47
+ type: 'preformatted',
48
+ attrs: {
49
+ nodeIndent: null,
50
+ nodeTextAlignment: null,
51
+ nodeLineHeight: null,
52
+ style: '',
53
+ },
54
+ content: [
55
+ {
56
+ type: 'text',
57
+ text: 'Hello world',
58
+ },
59
+ ],
60
+ },
61
+ ],
62
+ };
63
+
64
+ const { editor } = await renderWithEditor(null, { content });
65
+
66
+ const expected: FormattedText = [
67
+ {
68
+ type: 'tag',
69
+ tag: 'pre',
70
+ children: [{ type: 'text', value: 'Hello world' }],
71
+ },
72
+ ];
73
+
74
+ const result = remirrorNodeToSquizNode(editor.doc);
75
+ expect(result).toEqual(expected);
76
+ });
77
+
78
+ it('should handle code block formatting', async () => {
79
+ const content: RemirrorJSON = {
80
+ type: 'doc',
81
+ content: [
82
+ {
83
+ type: 'codeBlock',
84
+ attrs: {
85
+ language: 'js',
86
+ wrap: true,
87
+ },
88
+ content: [
89
+ {
90
+ type: 'text',
91
+ text: 'Hello world',
92
+ },
93
+ ],
94
+ },
95
+ ],
96
+ };
97
+
98
+ const { editor } = await renderWithEditor(null, { content });
99
+
100
+ const expected: FormattedText = [
101
+ {
102
+ type: 'tag',
103
+ tag: 'code',
104
+ children: [{ type: 'text', value: 'Hello world' }],
105
+ attributes: {
106
+ language: 'js',
107
+ },
108
+ },
109
+ ];
110
+
111
+ const result = remirrorNodeToSquizNode(editor.doc);
112
+ expect(result).toEqual(expected);
113
+ });
114
+
115
+ it('should handle line break formatting', async () => {
116
+ const content: RemirrorJSON = {
117
+ type: 'doc',
118
+ content: [
119
+ {
120
+ type: 'hardBreak',
121
+ },
122
+ ],
123
+ };
124
+
125
+ const { editor } = await renderWithEditor(null, { content });
126
+
127
+ const expected: FormattedText = [
128
+ {
129
+ type: 'tag',
130
+ tag: 'br',
131
+ children: [],
132
+ },
133
+ ];
134
+
135
+ const result = remirrorNodeToSquizNode(editor.doc);
136
+ expect(result).toEqual(expected);
137
+ });
138
+
139
+ it('should handle images', async () => {
140
+ const content: RemirrorJSON = {
141
+ type: 'doc',
142
+ content: [
143
+ {
144
+ type: 'paragraph',
145
+ attrs: {
146
+ nodeIndent: null,
147
+ nodeTextAlignment: null,
148
+ nodeLineHeight: null,
149
+ style: '',
150
+ },
151
+ content: [
152
+ {
153
+ type: 'image',
154
+ attrs: {
155
+ alt: '',
156
+ crop: null,
157
+ height: 150,
158
+ width: 200,
159
+ rotate: null,
160
+ src: 'https://media2.giphy.com/media/3o6ozsIxg5legYvggo/giphy.gif',
161
+ title: '',
162
+ fileName: null,
163
+ resizable: false,
164
+ },
165
+ },
166
+ ],
167
+ },
168
+ ],
169
+ };
170
+
171
+ const { editor } = await renderWithEditor(null, { content });
172
+
173
+ const expected: FormattedText = [
174
+ {
175
+ type: 'tag',
176
+ tag: 'p',
177
+ children: [
178
+ {
179
+ children: [],
180
+ attributes: {
181
+ alt: '',
182
+ height: '150',
183
+ width: '200',
184
+ src: 'https://media2.giphy.com/media/3o6ozsIxg5legYvggo/giphy.gif',
185
+ title: '',
186
+ },
187
+ type: 'tag',
188
+ tag: 'img',
189
+ },
190
+ ],
191
+ },
192
+ ];
193
+
194
+ const result = remirrorNodeToSquizNode(editor.doc);
195
+ expect(result).toEqual(expected);
196
+ });
197
+
198
+ it('should handle horizontal lines', async () => {
199
+ const content: RemirrorJSON = {
200
+ type: 'doc',
201
+ content: [
202
+ {
203
+ type: 'horizontalRule',
204
+ attrs: {
205
+ nodeIndent: null,
206
+ nodeTextAlignment: null,
207
+ nodeLineHeight: null,
208
+ style: '',
209
+ },
210
+ },
211
+ ],
212
+ };
213
+
214
+ const { editor } = await renderWithEditor(null, { content });
215
+
216
+ const expected: FormattedText = [
217
+ {
218
+ type: 'tag',
219
+ tag: 'hr',
220
+ children: [],
221
+ },
222
+ ];
223
+
224
+ const result = remirrorNodeToSquizNode(editor.doc);
225
+ expect(result).toEqual(expected);
226
+ });
227
+
228
+ it('should handle tables', async () => {
229
+ const content: RemirrorJSON = {
230
+ type: 'doc',
231
+ content: [
232
+ {
233
+ type: 'table',
234
+ attrs: {
235
+ isControllersInjected: true,
236
+ insertButtonAttrs: null,
237
+ },
238
+ content: [
239
+ {
240
+ type: 'tableRow',
241
+ content: [
242
+ {
243
+ type: 'tableControllerCell',
244
+ attrs: {
245
+ colspan: 1,
246
+ rowspan: 1,
247
+ colwidth: null,
248
+ background: null,
249
+ },
250
+ },
251
+ {
252
+ type: 'tableControllerCell',
253
+ attrs: {
254
+ colspan: 1,
255
+ rowspan: 1,
256
+ colwidth: [100],
257
+ background: null,
258
+ },
259
+ },
260
+ {
261
+ type: 'tableControllerCell',
262
+ attrs: {
263
+ colspan: 1,
264
+ rowspan: 1,
265
+ colwidth: null,
266
+ background: null,
267
+ },
268
+ },
269
+ {
270
+ type: 'tableControllerCell',
271
+ attrs: {
272
+ colspan: 1,
273
+ rowspan: 1,
274
+ colwidth: null,
275
+ background: null,
276
+ },
277
+ },
278
+ ],
279
+ },
280
+ {
281
+ type: 'tableRow',
282
+ content: [
283
+ {
284
+ type: 'tableControllerCell',
285
+ attrs: {
286
+ colspan: 1,
287
+ rowspan: 1,
288
+ colwidth: null,
289
+ background: null,
290
+ },
291
+ },
292
+ {
293
+ type: 'tableCell',
294
+ attrs: {
295
+ colspan: 1,
296
+ rowspan: 1,
297
+ colwidth: [100],
298
+ background: null,
299
+ },
300
+ content: [
301
+ {
302
+ type: 'paragraph',
303
+ attrs: {
304
+ nodeIndent: null,
305
+ nodeTextAlignment: '',
306
+ nodeLineHeight: null,
307
+ style: '',
308
+ },
309
+ content: [
310
+ {
311
+ type: 'text',
312
+ text: 'Col1Row1',
313
+ },
314
+ ],
315
+ },
316
+ ],
317
+ },
318
+ {
319
+ type: 'tableCell',
320
+ attrs: {
321
+ colspan: 1,
322
+ rowspan: 1,
323
+ colwidth: null,
324
+ background: null,
325
+ },
326
+ content: [
327
+ {
328
+ type: 'paragraph',
329
+ attrs: {
330
+ nodeIndent: null,
331
+ nodeTextAlignment: '',
332
+ nodeLineHeight: null,
333
+ style: '',
334
+ },
335
+ content: [
336
+ {
337
+ type: 'text',
338
+ text: 'Col2Row1',
339
+ },
340
+ ],
341
+ },
342
+ ],
343
+ },
344
+ {
345
+ type: 'tableCell',
346
+ attrs: {
347
+ colspan: 1,
348
+ rowspan: 1,
349
+ colwidth: null,
350
+ background: null,
351
+ },
352
+ content: [
353
+ {
354
+ type: 'paragraph',
355
+ attrs: {
356
+ nodeIndent: null,
357
+ nodeTextAlignment: '',
358
+ nodeLineHeight: null,
359
+ style: '',
360
+ },
361
+ content: [
362
+ {
363
+ type: 'text',
364
+ text: 'Col3Row1',
365
+ },
366
+ ],
367
+ },
368
+ ],
369
+ },
370
+ ],
371
+ },
372
+ {
373
+ type: 'tableRow',
374
+ content: [
375
+ {
376
+ type: 'tableControllerCell',
377
+ attrs: {
378
+ colspan: 1,
379
+ rowspan: 1,
380
+ colwidth: null,
381
+ background: null,
382
+ },
383
+ },
384
+ {
385
+ type: 'tableCell',
386
+ attrs: {
387
+ colspan: 1,
388
+ rowspan: 1,
389
+ colwidth: [100],
390
+ background: null,
391
+ },
392
+ content: [
393
+ {
394
+ type: 'paragraph',
395
+ attrs: {
396
+ nodeIndent: null,
397
+ nodeTextAlignment: '',
398
+ nodeLineHeight: null,
399
+ style: '',
400
+ },
401
+ content: [
402
+ {
403
+ type: 'text',
404
+ text: 'Col1Row2',
405
+ },
406
+ ],
407
+ },
408
+ ],
409
+ },
410
+ {
411
+ type: 'tableCell',
412
+ attrs: {
413
+ colspan: 1,
414
+ rowspan: 1,
415
+ colwidth: null,
416
+ background: null,
417
+ },
418
+ content: [
419
+ {
420
+ type: 'paragraph',
421
+ attrs: {
422
+ nodeIndent: null,
423
+ nodeTextAlignment: '',
424
+ nodeLineHeight: null,
425
+ style: '',
426
+ },
427
+ content: [
428
+ {
429
+ type: 'text',
430
+ text: 'Col2Row2',
431
+ },
432
+ ],
433
+ },
434
+ ],
435
+ },
436
+ {
437
+ type: 'tableCell',
438
+ attrs: {
439
+ colspan: 1,
440
+ rowspan: 1,
441
+ colwidth: null,
442
+ background: null,
443
+ },
444
+ content: [
445
+ {
446
+ type: 'paragraph',
447
+ attrs: {
448
+ nodeIndent: null,
449
+ nodeTextAlignment: '',
450
+ nodeLineHeight: null,
451
+ style: '',
452
+ },
453
+ content: [
454
+ {
455
+ type: 'text',
456
+ text: 'Col3Row2',
457
+ },
458
+ ],
459
+ },
460
+ ],
461
+ },
462
+ ],
463
+ },
464
+ ],
465
+ },
466
+ ],
467
+ };
468
+
469
+ const { editor } = await renderWithEditor(null, { content });
470
+
471
+ const expected: FormattedText = [
472
+ {
473
+ type: 'tag',
474
+ tag: 'table',
475
+ children: [
476
+ {
477
+ type: 'tag',
478
+ tag: 'tr',
479
+ children: [
480
+ {
481
+ type: 'tag',
482
+ tag: 'th',
483
+ children: [],
484
+ attributes: {
485
+ colspan: '1',
486
+ rowspan: '1',
487
+ tableControllerCell: 'true',
488
+ },
489
+ },
490
+ {
491
+ type: 'tag',
492
+ tag: 'th',
493
+ children: [],
494
+ attributes: {
495
+ colspan: '1',
496
+ rowspan: '1',
497
+ tableControllerCell: 'true',
498
+ colwidth: '100',
499
+ },
500
+ },
501
+ {
502
+ type: 'tag',
503
+ tag: 'th',
504
+ children: [],
505
+ attributes: {
506
+ colspan: '1',
507
+ rowspan: '1',
508
+ tableControllerCell: 'true',
509
+ },
510
+ },
511
+ {
512
+ type: 'tag',
513
+ tag: 'th',
514
+ children: [],
515
+ attributes: {
516
+ colspan: '1',
517
+ rowspan: '1',
518
+ tableControllerCell: 'true',
519
+ },
520
+ },
521
+ ],
522
+ },
523
+ {
524
+ type: 'tag',
525
+ tag: 'tr',
526
+ children: [
527
+ {
528
+ type: 'tag',
529
+ tag: 'th',
530
+ children: [],
531
+ attributes: {
532
+ colspan: '1',
533
+ rowspan: '1',
534
+ tableControllerCell: 'true',
535
+ },
536
+ },
537
+ {
538
+ type: 'tag',
539
+ tag: 'td',
540
+ children: [
541
+ {
542
+ type: 'tag',
543
+ tag: 'p',
544
+ children: [
545
+ {
546
+ type: 'text',
547
+ value: 'Col1Row1',
548
+ },
549
+ ],
550
+ },
551
+ ],
552
+ attributes: {
553
+ colspan: '1',
554
+ rowspan: '1',
555
+ colwidth: '100',
556
+ },
557
+ },
558
+ {
559
+ type: 'tag',
560
+ tag: 'td',
561
+ children: [
562
+ {
563
+ type: 'tag',
564
+ tag: 'p',
565
+ children: [
566
+ {
567
+ type: 'text',
568
+ value: 'Col2Row1',
569
+ },
570
+ ],
571
+ },
572
+ ],
573
+ attributes: {
574
+ colspan: '1',
575
+ rowspan: '1',
576
+ },
577
+ },
578
+ {
579
+ type: 'tag',
580
+ tag: 'td',
581
+ children: [
582
+ {
583
+ type: 'tag',
584
+ tag: 'p',
585
+ children: [
586
+ {
587
+ type: 'text',
588
+ value: 'Col3Row1',
589
+ },
590
+ ],
591
+ },
592
+ ],
593
+ attributes: {
594
+ colspan: '1',
595
+ rowspan: '1',
596
+ },
597
+ },
598
+ ],
599
+ },
600
+ {
601
+ type: 'tag',
602
+ tag: 'tr',
603
+ children: [
604
+ {
605
+ type: 'tag',
606
+ tag: 'th',
607
+ children: [],
608
+ attributes: {
609
+ colspan: '1',
610
+ rowspan: '1',
611
+ tableControllerCell: 'true',
612
+ },
613
+ },
614
+ {
615
+ type: 'tag',
616
+ tag: 'td',
617
+ children: [
618
+ {
619
+ type: 'tag',
620
+ tag: 'p',
621
+ children: [
622
+ {
623
+ type: 'text',
624
+ value: 'Col1Row2',
625
+ },
626
+ ],
627
+ },
628
+ ],
629
+ attributes: {
630
+ colspan: '1',
631
+ rowspan: '1',
632
+ colwidth: '100',
633
+ },
634
+ },
635
+ {
636
+ type: 'tag',
637
+ tag: 'td',
638
+ children: [
639
+ {
640
+ type: 'tag',
641
+ tag: 'p',
642
+ children: [
643
+ {
644
+ type: 'text',
645
+ value: 'Col2Row2',
646
+ },
647
+ ],
648
+ },
649
+ ],
650
+ attributes: {
651
+ colspan: '1',
652
+ rowspan: '1',
653
+ },
654
+ },
655
+ {
656
+ type: 'tag',
657
+ tag: 'td',
658
+ children: [
659
+ {
660
+ type: 'tag',
661
+ tag: 'p',
662
+ children: [
663
+ {
664
+ type: 'text',
665
+ value: 'Col3Row2',
666
+ },
667
+ ],
668
+ },
669
+ ],
670
+ attributes: {
671
+ colspan: '1',
672
+ rowspan: '1',
673
+ },
674
+ },
675
+ ],
676
+ },
677
+ ],
678
+ },
679
+ ];
680
+
681
+ const result = remirrorNodeToSquizNode(editor.doc);
682
+ expect(result).toEqual(expected);
683
+ });
684
+
685
+ it.each([1, 2, 3, 4, 5, 6])('should handle heading %s formatting', async (level) => {
686
+ const content: RemirrorJSON = {
687
+ type: 'doc',
688
+ content: [
689
+ {
690
+ type: 'heading',
691
+ attrs: {
692
+ nodeIndent: null,
693
+ nodeTextAlignment: null,
694
+ nodeLineHeight: null,
695
+ style: '',
696
+ level: level,
697
+ },
698
+ content: [
699
+ {
700
+ type: 'text',
701
+ text: 'Hello world',
702
+ },
703
+ ],
704
+ },
705
+ ],
706
+ };
707
+
708
+ const { editor } = await renderWithEditor(null, { content });
709
+
710
+ const expected: FormattedText = [
711
+ {
712
+ type: 'tag',
713
+ tag: `h${level}`,
714
+ children: [{ type: 'text', value: 'Hello world' }],
715
+ },
716
+ ];
717
+
718
+ const result = remirrorNodeToSquizNode(editor.doc);
719
+ expect(result).toEqual(expected);
720
+ });
721
+
722
+ it('should preserve font and attribute options', async () => {
723
+ const content: RemirrorJSON = {
724
+ type: 'doc',
725
+ content: [
726
+ {
727
+ type: 'paragraph',
728
+ content: [
729
+ {
730
+ type: 'text',
731
+ text: 'You can',
732
+ },
733
+ {
734
+ type: 'text',
735
+ marks: [
736
+ {
737
+ type: 'bold',
738
+ },
739
+ ],
740
+ text: ' click',
741
+ },
742
+ {
743
+ type: 'text',
744
+ text: ' ',
745
+ },
746
+ {
747
+ type: 'text',
748
+ marks: [
749
+ {
750
+ type: 'link',
751
+ attrs: {
752
+ href: 'https://www.google.com/',
753
+ target: null,
754
+ auto: false,
755
+ title: '',
756
+ },
757
+ },
758
+ {
759
+ type: 'italic',
760
+ },
761
+ ],
762
+ text: 'here',
763
+ },
764
+ {
765
+ type: 'text',
766
+ marks: [
767
+ {
768
+ type: 'italic',
769
+ },
770
+ ],
771
+ text: ' ',
772
+ },
773
+ {
774
+ type: 'text',
775
+ text: 'to go to',
776
+ },
777
+ {
778
+ type: 'text',
779
+ marks: [
780
+ {
781
+ type: 'bold',
782
+ },
783
+ {
784
+ type: 'italic',
785
+ },
786
+ {
787
+ type: 'underline',
788
+ },
789
+ ],
790
+ text: ' GOOGLE!',
791
+ },
792
+ ],
793
+ },
794
+ ],
795
+ };
796
+
797
+ const { editor } = await renderWithEditor(null, { content });
798
+
799
+ const expected: FormattedText = [
800
+ {
801
+ children: [
802
+ {
803
+ type: 'text',
804
+ value: 'You can',
805
+ },
806
+ {
807
+ children: [
808
+ {
809
+ type: 'text',
810
+ value: ' click',
811
+ },
812
+ ],
813
+ tag: 'strong',
814
+ type: 'tag',
815
+ },
816
+ {
817
+ type: 'text',
818
+ value: ' ',
819
+ },
820
+ {
821
+ children: [
822
+ {
823
+ type: 'tag',
824
+ tag: 'a',
825
+ children: [
826
+ {
827
+ type: 'text',
828
+ value: 'here',
829
+ },
830
+ ],
831
+ attributes: {
832
+ href: 'https://www.google.com/',
833
+ title: '',
834
+ },
835
+ },
836
+ ],
837
+
838
+ tag: 'em',
839
+ type: 'tag',
840
+ },
841
+ {
842
+ children: [
843
+ {
844
+ type: 'text',
845
+ value: ' ',
846
+ },
847
+ ],
848
+ tag: 'em',
849
+ type: 'tag',
850
+ },
851
+ {
852
+ type: 'text',
853
+ value: 'to go to',
854
+ },
855
+ {
856
+ children: [
857
+ {
858
+ type: 'tag',
859
+ tag: 'em',
860
+ children: [
861
+ {
862
+ type: 'tag',
863
+ tag: 'strong',
864
+ children: [
865
+ {
866
+ type: 'text',
867
+ value: ' GOOGLE!',
868
+ },
869
+ ],
870
+ },
871
+ ],
872
+ },
873
+ ],
874
+ font: {
875
+ underline: true,
876
+ },
877
+ tag: 'span',
878
+ type: 'tag',
879
+ },
880
+ ],
881
+ type: 'tag',
882
+ tag: 'p',
883
+ },
884
+ ];
885
+
886
+ const result = remirrorNodeToSquizNode(editor.doc);
887
+ expect(result).toEqual(expected);
888
+ });
889
+
890
+ describe('preserve text formatting - %s', () => {
891
+ it.each([
892
+ ['left', { alignment: 'left' } as FormattingOptions],
893
+ ['right', { alignment: 'right' } as FormattingOptions],
894
+ ['center', { alignment: 'center' } as FormattingOptions],
895
+ ['justify', { alignment: 'justify' } as FormattingOptions],
896
+ ['start', { alignment: 'left' } as FormattingOptions],
897
+ ['end', { alignment: 'right' } as FormattingOptions],
898
+ ['none', undefined],
899
+ [undefined, undefined],
900
+ ])(
901
+ 'should preserve text alignment',
902
+ async (remirrorTextAlignment: string | undefined, expectedFormattingOptions: FormattingOptions | undefined) => {
903
+ const content: RemirrorJSON = {
904
+ type: 'doc',
905
+ content: [
906
+ {
907
+ type: 'paragraph',
908
+ attrs: {
909
+ nodeIndent: null,
910
+ nodeTextAlignment: remirrorTextAlignment,
911
+ nodeLineHeight: null,
912
+ style: '',
913
+ },
914
+ content: [
915
+ {
916
+ type: 'text',
917
+ text: 'Hello world!',
918
+ },
919
+ ],
920
+ },
921
+ ],
922
+ };
923
+
924
+ const { editor } = await renderWithEditor(null, { content });
925
+
926
+ const expected: FormattedText = [
927
+ {
928
+ children: [
929
+ {
930
+ type: 'text',
931
+ value: 'Hello world!',
932
+ },
933
+ ],
934
+ formattingOptions: expectedFormattingOptions,
935
+ type: 'tag',
936
+ tag: 'p',
937
+ },
938
+ ];
939
+
940
+ const result = remirrorNodeToSquizNode(editor.doc);
941
+ expect(result).toEqual(expected);
942
+ },
943
+ );
944
+ });
945
+
946
+ it('should handle invalid Remirror node provided', () => {
947
+ expect(() => remirrorNodeToSquizNode(false as any)).toThrow(
948
+ 'Unable to convert from Remirror to Node data structure, unexpected node provided.',
949
+ );
950
+ });
951
+
952
+ it('should handle no content provided by Remirror', async () => {
953
+ const content: RemirrorJSON = {
954
+ type: 'doc',
955
+ };
956
+
957
+ const { editor } = await renderWithEditor(null, { content });
958
+
959
+ const result = remirrorNodeToSquizNode(editor.doc);
960
+ expect(result).toBeUndefined();
961
+ });
962
+
963
+ it.each(sharedNodeExamples)(
964
+ 'should convert a Remirror node to the expected Squiz representation - $description',
965
+ async ({ remirrorNode, squizNode }: any) => {
966
+ const { editor } = await renderWithEditor(null, {
967
+ content: {
968
+ type: 'doc',
969
+ content: [{ type: 'paragraph', content: [remirrorNode] }],
970
+ },
971
+ });
972
+
973
+ expect(remirrorNodeToSquizNode(editor.doc)).toEqual([
974
+ {
975
+ type: 'tag',
976
+ tag: 'p',
977
+ children: squizNode,
978
+ },
979
+ ]);
980
+ },
981
+ );
982
+
983
+ it('should throw if the remirror node has an unsupported mark applied', async () => {
984
+ const { editor } = await renderWithEditor(null, {
985
+ extensions: [new ParagraphExtension(), new SupExtension()],
986
+ content: {
987
+ type: 'doc',
988
+ content: [{ type: 'paragraph', marks: [{ type: 'sup' }], content: [] }],
989
+ },
990
+ });
991
+
992
+ expect(() => remirrorNodeToSquizNode(editor.doc)).toThrow('Unsupported mark "sup" was applied to node.');
993
+ });
994
+
995
+ it('should ignore empty root node', async () => {
996
+ const { editor } = await renderWithEditor(null, {
997
+ content: {
998
+ type: 'doc',
999
+ content: [{ type: 'paragraph', content: [] }],
1000
+ },
1001
+ });
1002
+
1003
+ expect(remirrorNodeToSquizNode(editor.doc)).toBeUndefined();
1004
+ });
1005
+ });
1006
+
1007
+ describe('resolveNodeTag', () => {
1008
+ it('should return the correct tag name for a node with a toDOM method that returns a Node', () => {
1009
+ const node: any = {
1010
+ type: {
1011
+ spec: {
1012
+ toDOM: () => document.createElement('div'),
1013
+ },
1014
+ },
1015
+ };
1016
+ expect(resolveNodeTag(node)).toBe('div');
1017
+ });
1018
+
1019
+ it('should return the correct tag name for a node with a toDOM method that returns an object with a dom property', () => {
1020
+ const node: any = {
1021
+ type: {
1022
+ spec: {
1023
+ toDOM: () => ({ dom: document.createElement('span') }),
1024
+ },
1025
+ },
1026
+ };
1027
+ expect(resolveNodeTag(node)).toBe('span');
1028
+ });
1029
+
1030
+ it('should return the correct tag name for a node with a toDOM method that returns an array', () => {
1031
+ const node: any = {
1032
+ type: {
1033
+ spec: {
1034
+ toDOM: () => ['ul', { class: 'my-list' }],
1035
+ },
1036
+ },
1037
+ };
1038
+ expect(resolveNodeTag(node)).toBe('ul');
1039
+ });
1040
+
1041
+ it('should throw for a node with a toDOM method that returns undefined', () => {
1042
+ const node: any = {
1043
+ type: {
1044
+ spec: {
1045
+ toDOM: () => undefined,
1046
+ },
1047
+ },
1048
+ };
1049
+ expect(() => resolveNodeTag(node)).toThrow('Unexpected Remirror node encountered, cannot resolve tag.');
1050
+ });
1051
+
1052
+ it('should throw for a node without a toDOM method', () => {
1053
+ const node: any = {
1054
+ type: {},
1055
+ };
1056
+ expect(() => resolveNodeTag(node)).toThrow('Unexpected Remirror node encountered, cannot resolve tag.');
1057
+ });
1058
+ });