@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,137 @@
1
+ import { ExtensionTag, NodeExtensionSpec, ApplySchemaAttributes } from '@remirror/core';
2
+ import { NodeName } from '../Extensions';
3
+ import CollapseBox from '../../ui/CollapseBox/CollapseBox';
4
+ import { UnsupportedNodeExtension } from './UnsupportedNodeExtension';
5
+ import { renderWithEditor } from '../../../tests';
6
+
7
+ describe('UnsupportedNodeExtension', () => {
8
+ it('should have the correct extension name', () => {
9
+ const extension = new UnsupportedNodeExtension();
10
+ expect(extension.name).toBe(NodeName.Unsupported);
11
+ });
12
+
13
+ it('should use the CollapseBox component as the ReactComponent', () => {
14
+ const extension = new UnsupportedNodeExtension();
15
+ expect(extension.ReactComponent).toBe(CollapseBox);
16
+ });
17
+
18
+ it('should create the correct tags', () => {
19
+ const extension = new UnsupportedNodeExtension();
20
+ expect(extension.createTags()).toEqual([ExtensionTag.InlineNode]);
21
+ });
22
+
23
+ it('should create the correct node spec', () => {
24
+ const extension = new UnsupportedNodeExtension();
25
+ const extra: ApplySchemaAttributes = {
26
+ defaults: () => ({}),
27
+ parse: () => ({}),
28
+ dom: () => ({}),
29
+ };
30
+
31
+ const override: NodeExtensionSpec = {
32
+ selectable: true,
33
+ };
34
+
35
+ const nodeSpec = extension.createNodeSpec(extra, override);
36
+
37
+ expect(nodeSpec.selectable).toBe(true);
38
+ expect(nodeSpec.draggable).toBe(false);
39
+ expect(nodeSpec.atom).toBe(true);
40
+ expect(nodeSpec.inline).toBe(true);
41
+ expect(nodeSpec.attrs).toEqual({ originalNode: {}, errorMessage: {} });
42
+ expect(nodeSpec.parseDOM).toEqual([
43
+ {
44
+ tag: '[data-unsupported-node]',
45
+ getAttrs: expect.any(Function),
46
+ },
47
+ ]);
48
+
49
+ expect(nodeSpec.toDOM).toEqual(expect.any(Function));
50
+ });
51
+
52
+ it('should generate the correct toDOM representation', async () => {
53
+ const { getJsonContent } = await renderWithEditor(null, {
54
+ content: `<div data-unsupported-node="{&quot;originalNode&quot;:{&quot;type&quot;:&quot;tag&quot;,&quot;tag&quot;:&quot;p&quot;,&quot;children&quot;:[{&quot;type&quot;:&quot;tag&quot;,&quot;tag&quot;:&quot;p&quot;,&quot;children&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;value&quot;:&quot;some text before&quot;},{&quot;type&quot;:&quot;sup&quot;,&quot;children&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;value&quot;:&quot;Hello&quot;}]},{&quot;type&quot;:&quot;text&quot;,&quot;value&quot;:&quot; and after&quot;},{&quot;type&quot;:&quot;tag&quot;,&quot;tag&quot;:&quot;strike&quot;,&quot;children&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;value&quot;:&quot;Some text.&quot;}]}]}]},&quot;errorMessage&quot;:&quot;Unsupported node type provided: sup&quot;}" />`,
55
+ });
56
+
57
+ expect(getJsonContent()).toEqual({
58
+ type: 'paragraph',
59
+ attrs: {
60
+ nodeIndent: null,
61
+ nodeTextAlignment: null,
62
+ nodeLineHeight: null,
63
+ style: '',
64
+ },
65
+ content: [
66
+ {
67
+ type: 'unsupportedNode',
68
+ attrs: {
69
+ originalNode: {
70
+ type: 'tag',
71
+ tag: 'p',
72
+ children: [
73
+ {
74
+ type: 'tag',
75
+ tag: 'p',
76
+ children: [
77
+ {
78
+ type: 'text',
79
+ value: 'some text before',
80
+ },
81
+ {
82
+ type: 'sup',
83
+ children: [
84
+ {
85
+ type: 'text',
86
+ value: 'Hello',
87
+ },
88
+ ],
89
+ },
90
+ {
91
+ type: 'text',
92
+ value: ' and after',
93
+ },
94
+ {
95
+ type: 'tag',
96
+ tag: 'strike',
97
+ children: [
98
+ {
99
+ type: 'text',
100
+ value: 'Some text.',
101
+ },
102
+ ],
103
+ },
104
+ ],
105
+ },
106
+ ],
107
+ },
108
+ errorMessage: 'Unsupported node type provided: sup',
109
+ },
110
+ },
111
+ ],
112
+ });
113
+ });
114
+
115
+ it('should omit extra attributes from node.attrs in toDOM representation', async () => {
116
+ const { getHtmlContent } = await renderWithEditor(null, {
117
+ content: {
118
+ type: 'doc',
119
+ content: [
120
+ {
121
+ type: 'unsupportedNode',
122
+ content: [
123
+ {
124
+ type: 'text',
125
+ text: 'This is some preformatted text',
126
+ },
127
+ ],
128
+ },
129
+ ],
130
+ },
131
+ });
132
+
133
+ expect(getHtmlContent()).toBe(
134
+ '<span class="unsupported-node-node-view-wrapper" originalnode="null" errormessage="null" data-unsupported-node="{&quot;originalNode&quot;:null,&quot;errorMessage&quot;:null}"><div class="collapse-box" contenteditable="false"><button class="collapse-box__header" type="button"><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium collapse-box__icon--warning css-i4bv87-MuiSvgIcon-root" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="MotionPhotosOffOutlinedIcon"><path d="M2.81 2.81 1.39 4.22l2.27 2.27C2.61 8.07 2 9.96 2 12c0 5.52 4.48 10 10 10 2.04 0 3.93-.61 5.51-1.66l2.27 2.27 1.41-1.42L2.81 2.81zM12 20c-4.41 0-8-3.59-8-8 0-1.48.41-2.86 1.12-4.06l10.93 10.94C14.86 19.59 13.48 20 12 20zm0-16c4.41 0 8 3.59 8 8 0 1.48-.41 2.86-1.12 4.05l1.45 1.45C21.39 15.93 22 14.04 22 12c0-5.52-4.48-10-10-10-2.04 0-3.93.61-5.51 1.66l1.45 1.45C9.14 4.41 10.52 4 12 4z"></path></svg><div class="collapse-box__label">This section cannot be displayed here due to unsupported HTML elements. The front-end view of your page won’t be affected.</div><svg class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-i4bv87-MuiSvgIcon-root" focusable="false" aria-hidden="true" viewBox="0 0 24 24" data-testid="UnfoldLessOutlinedIcon"><path d="M7.41 18.59 8.83 20 12 16.83 15.17 20l1.41-1.41L12 14l-4.59 4.59zm9.18-13.18L15.17 4 12 7.17 8.83 4 7.41 5.41 12 10l4.59-4.59z"></path></svg></button><div class="collapse-box__content" hidden="" data-testid="content"><br>null</div></div></span>',
135
+ );
136
+ });
137
+ });
@@ -0,0 +1,80 @@
1
+ import {
2
+ ApplySchemaAttributes,
3
+ ExtensionTag,
4
+ NodeExtension,
5
+ NodeExtensionSpec,
6
+ NodeSpecOverride,
7
+ ProsemirrorNode,
8
+ extension,
9
+ isElementDomNode,
10
+ omitExtraAttributes,
11
+ } from '@remirror/core';
12
+
13
+ import { NodeName } from '../Extensions';
14
+ import { ComponentType } from 'react';
15
+ import { NodeViewComponentProps } from '@remirror/react';
16
+ import CollapseBox from '../../ui/CollapseBox/CollapseBox';
17
+
18
+ @extension({})
19
+ export class UnsupportedNodeExtension extends NodeExtension {
20
+ get name() {
21
+ return NodeName.Unsupported as const;
22
+ }
23
+
24
+ ReactComponent: ComponentType<NodeViewComponentProps> = CollapseBox;
25
+
26
+ createTags() {
27
+ return [ExtensionTag.InlineNode];
28
+ }
29
+
30
+ createNodeSpec(extra: ApplySchemaAttributes, override: NodeSpecOverride): NodeExtensionSpec {
31
+ return {
32
+ selectable: false,
33
+ draggable: false,
34
+ atom: true,
35
+ inline: true,
36
+ ...override,
37
+ attrs: {
38
+ ...extra.defaults(),
39
+ originalNode: {},
40
+ errorMessage: {},
41
+ },
42
+ parseDOM: [
43
+ {
44
+ tag: `[data-unsupported-node]`,
45
+ getAttrs: (node) => {
46
+ if (!isElementDomNode(node)) {
47
+ return false;
48
+ }
49
+ const unsupportedNodes = node.getAttribute('data-unsupported-node');
50
+
51
+ try {
52
+ const decodedNodes = JSON.parse(unsupportedNodes as string);
53
+
54
+ return {
55
+ ...extra.parse(node),
56
+ originalNode: decodedNodes?.originalNode,
57
+ errorMessage: decodedNodes?.errorMessage,
58
+ };
59
+ } catch (error) {
60
+ console.error('Failed to parse Remirror nodes from data-unsupported-node', error);
61
+ return false;
62
+ }
63
+ },
64
+ },
65
+ ],
66
+ toDOM: (node: ProsemirrorNode) => {
67
+ const { originalNode, errorMessage, ...rest } = omitExtraAttributes(node.attrs, extra);
68
+
69
+ const attrs = {
70
+ ...extra.dom(node),
71
+ ...rest,
72
+ originalNode,
73
+ errorMessage,
74
+ 'data-unsupported-node': JSON.stringify({ originalNode, errorMessage }),
75
+ };
76
+ return ['div', attrs];
77
+ },
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useExtensionNames';
2
+ export * from './useExpandedSelection';
@@ -0,0 +1,44 @@
1
+ import { Selection } from '@remirror/core';
2
+ import { GetMarkRange, getMarkRanges, getTextSelection, Mark, MarkType } from 'remirror';
3
+ import { useEditorState } from '@remirror/react';
4
+
5
+ export type ExpandedSelection = {
6
+ selection: Selection;
7
+ marks: Mark[];
8
+ };
9
+
10
+ /**
11
+ * Returns a single range that is either:
12
+ * 1. The current selection if the current selection does not contain any of the indicated marks.
13
+ * 2. An expanded version of the current selection if the range contains any of the indicated marks.
14
+ *
15
+ * For example, given the content:
16
+ *
17
+ * <strong>Bold</strong> regular <u>underline</u> <u>more underline</u>
18
+ *
19
+ * If the marks passed in are 'bold' and 'underline' and the text "old regular under" is selected
20
+ * the returned range will be "Bold regular underline".
21
+ *
22
+ * @param {(MarkType|string)[]} markTypes
23
+ *
24
+ * @return {ExpandedSelection}
25
+ */
26
+ export const useExpandedSelection = (markTypes: (MarkType | string)[]): ExpandedSelection => {
27
+ const { doc, selection } = useEditorState();
28
+ const ranges: GetMarkRange[] = [];
29
+
30
+ markTypes.forEach((markType) => {
31
+ ranges.push(...getMarkRanges(selection, markType));
32
+ });
33
+
34
+ if (ranges.length === 0) {
35
+ return { selection, marks: [] };
36
+ }
37
+
38
+ // work out the start position of the first link and end position of the last link in the selection.
39
+ const from = Math.min(selection.from, ...ranges.map((range) => range.from));
40
+ const to = Math.max(selection.to, ...ranges.map((range) => range.to));
41
+ const marks = ranges.map((range) => range.mark);
42
+
43
+ return { selection: getTextSelection({ from, to }, doc), marks };
44
+ };
@@ -0,0 +1,15 @@
1
+ import { useRemirrorContext } from '@remirror/react';
2
+ import { useMemo } from 'react';
3
+
4
+ export const useExtensionNames = () => {
5
+ const { manager } = useRemirrorContext();
6
+ return useMemo(() => {
7
+ const extensionNames: Record<string, true> = {};
8
+
9
+ manager.extensions.forEach((extension) => {
10
+ extensionNames[extension.name] = true;
11
+ });
12
+
13
+ return extensionNames;
14
+ }, [manager]);
15
+ };
@@ -0,0 +1,61 @@
1
+ import { useState, useCallback, FocusEvent, FocusEventHandler, RefObject, createRef } from 'react';
2
+
3
+ const useFocus = (
4
+ initialState: boolean,
5
+ ): {
6
+ handleFocus: (event: FocusEvent) => void;
7
+ handleBlur: FocusEventHandler<HTMLDivElement>;
8
+ isVisible: boolean;
9
+ wrapperRef: RefObject<HTMLDivElement>;
10
+ } => {
11
+ const wrapperRef = createRef<HTMLDivElement>();
12
+ const [isVisible, setIsVisible] = useState(initialState);
13
+
14
+ const handleFocus = useCallback(
15
+ (event: FocusEvent) => {
16
+ // Ignore elements flagged to be ignored, this allows us to add extra, clickable, elements
17
+ // without triggering a focus, such as action menus.
18
+ if (!event.target?.classList?.contains('fte-ignore') && !event.target?.closest('.fte-ignore')) {
19
+ setIsVisible(true);
20
+ }
21
+ },
22
+ [wrapperRef],
23
+ );
24
+
25
+ const handleBlur = useCallback(
26
+ (event: FocusEvent<HTMLDivElement>) => {
27
+ // React event bubbling is interesting, it bubbles up the React tree rather than the DOM tree.
28
+ // The tree deviates when rendering portals (eg. for modals).
29
+ //
30
+ // Only hide the toolbar if:
31
+ // 1. We are blurring a node in the editor **DOM** tree.
32
+ // 2. We are focusing on something that is not in the editor DOM tree
33
+ // (elements in the portal won't be in the tree but don't influence the focus state per #1).
34
+ //
35
+ // This avoids the scenario where an element in a portal is blurred and another one in the portal focused.
36
+ // Without this logic the blur and focus handlers are called (in that order). The impact of these handlers being
37
+ // called is that the "isFocused" state changes inconsistently. This state changing then causes subtle issues.
38
+ // eg. unable to drill down in resource browser, toolbar appearing/disappearing.
39
+ //
40
+ // Ideally we would instead solely seeing if the "relatedTarget" is in the React tree. This isn't easily
41
+ // identifiable however without reaching into React internals.
42
+ //
43
+ // An assumption here is that anything in a portal will only blur to another element that is also in the portal
44
+ // (and therefore still in our React tree resulting in the element still effectively being focused).
45
+ const isBlurringEditor = wrapperRef.current?.contains(event.target);
46
+ const isFocusedInEditor = wrapperRef.current?.contains(event.relatedTarget);
47
+
48
+ // Detect if the blur event happens when the related/clicked target is the floating popover
49
+ const isClickingFloatingToolbar = !!event.relatedTarget?.closest('.squiz-fte-scope__floating-popover');
50
+
51
+ if (isBlurringEditor && !isFocusedInEditor && !isClickingFloatingToolbar) {
52
+ setIsVisible(false);
53
+ }
54
+ },
55
+ [wrapperRef],
56
+ );
57
+
58
+ return { handleFocus, handleBlur, isVisible, wrapperRef };
59
+ };
60
+
61
+ export default useFocus;
package/src/index.scss ADDED
@@ -0,0 +1,24 @@
1
+ /* Tailwind base styles, but scoped to the editor */
2
+ @import 'tailwindcss/base';
3
+ @import 'tailwindcss/components';
4
+ @import 'tailwindcss/utilities';
5
+
6
+ /* So we can use icons inside of FTE content */
7
+ @import 'https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded';
8
+
9
+ /* Global */
10
+ @import './ui/typography';
11
+ @import './ui/forms';
12
+
13
+ /* Components */
14
+ @import './Editor/editor';
15
+ @import './EditorToolbar/toolbar';
16
+ @import './EditorToolbar/floating-toolbar';
17
+
18
+ @import './ui/Button/button';
19
+ @import './ui/ToolbarDropdown/toolbar-dropdown';
20
+ @import './ui/ToolbarDropdownButton/toolbar-dropdown-button';
21
+ @import './ui/Fields/Checkbox/checkbox';
22
+ @import './ui/CollapseBox/collapseBox';
23
+
24
+ @import './ui/Modal/modal';
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import Editor from './Editor/Editor';
2
+ import { EditorContext } from './Editor/EditorContext';
3
+ import { remirrorNodeToSquizNode } from './utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode';
4
+ import { squizNodeToRemirrorNode } from './utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode';
5
+ import { htmlToSquizNode } from './utils/converters/htmlToSquizNode/htmlToSquizNode';
6
+ import { ResolveNodeType, ResolveNodeToUrl } from './types';
7
+
8
+ export { Editor, EditorContext, remirrorNodeToSquizNode, squizNodeToRemirrorNode, htmlToSquizNode };
9
+ export type { ResolveNodeType, ResolveNodeToUrl };
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ export type DeepPartial<T> = {
2
+ [P in keyof T]?: T[P] extends Array<infer U>
3
+ ? Array<DeepPartial<U>>
4
+ : T[P] extends ReadonlyArray<infer U>
5
+ ? ReadonlyArray<DeepPartial<U>>
6
+ : DeepPartial<T[P]>;
7
+ };
8
+
9
+ export type ResolveNodeType = { [attr: string]: any };
10
+ export type ResolveNodeToUrl = (node: ResolveNodeType) => Promise<string>;
@@ -0,0 +1,44 @@
1
+ import '@testing-library/jest-dom';
2
+ import { render, screen } from '@testing-library/react';
3
+ import React from 'react';
4
+ import Button from './Button';
5
+ import AccessTimeRoundedIcon from '@mui/icons-material/AccessTimeRounded';
6
+
7
+ describe('Button', () => {
8
+ const mockOnClick = jest.fn();
9
+
10
+ const ButtonComponent = () => {
11
+ return (
12
+ <Button
13
+ handleOnClick={mockOnClick}
14
+ isDisabled
15
+ isActive
16
+ label="Am a button"
17
+ text="Hello"
18
+ icon={<AccessTimeRoundedIcon />}
19
+ />
20
+ );
21
+ };
22
+
23
+ it('Renders the label, text and icon', () => {
24
+ render(<ButtonComponent />);
25
+ const label = screen.getByLabelText('Am a button');
26
+ expect(label).toBeInTheDocument();
27
+ const text = screen.getByText('Hello');
28
+ expect(text).toBeInTheDocument();
29
+ const icon = screen.getByTestId('AccessTimeRoundedIcon');
30
+ expect(icon).toBeInTheDocument();
31
+ });
32
+
33
+ it('Renders the button in a disabled state if set to be disabled', () => {
34
+ render(<ButtonComponent />);
35
+ const button = screen.getByLabelText('Am a button');
36
+ expect(button).toBeDisabled();
37
+ });
38
+
39
+ it('Adds the active class is set to be active', () => {
40
+ render(<ButtonComponent />);
41
+ const button = screen.getByLabelText('Am a button');
42
+ expect(button).toHaveClass('squiz-fte-btn--is-active');
43
+ });
44
+ });
@@ -0,0 +1,35 @@
1
+ import React, { ReactElement } from 'react';
2
+ import clsx from 'clsx';
3
+
4
+ type ButtonProps = {
5
+ handleOnClick: () => void;
6
+ isDisabled?: boolean;
7
+ isActive: boolean;
8
+ label: string;
9
+ text?: string;
10
+ icon?: ReactElement;
11
+ className?: string;
12
+ };
13
+
14
+ const Button = ({ handleOnClick, isDisabled, isActive, label, text, icon, className }: ButtonProps) => {
15
+ return (
16
+ <button
17
+ aria-label={label}
18
+ title={label}
19
+ type="button"
20
+ onClick={handleOnClick}
21
+ disabled={isDisabled}
22
+ className={clsx(
23
+ 'squiz-fte-btn',
24
+ isActive && 'squiz-fte-btn--is-active',
25
+ icon && ' squiz-fte-btn--is-icon',
26
+ className,
27
+ )}
28
+ >
29
+ {text && <span>{text}</span>}
30
+ {icon && icon}
31
+ </button>
32
+ );
33
+ };
34
+
35
+ export default Button;
@@ -0,0 +1,37 @@
1
+ button.squiz-fte-btn {
2
+ @apply font-bold rounded ease-linear transition-all bg-white text-gray-600 duration-150;
3
+ display: flex;
4
+ align-items: center;
5
+ text-align: center;
6
+ white-space: nowrap;
7
+ vertical-align: middle;
8
+ touch-action: manipulation;
9
+ cursor: pointer;
10
+ background-image: none;
11
+ border: 1px solid transparent;
12
+ padding: 6px 12px;
13
+
14
+ &--is-icon {
15
+ padding: 6px;
16
+ }
17
+
18
+ ~ .squiz-fte-btn {
19
+ margin-left: 2px;
20
+ }
21
+
22
+ &.disabled,
23
+ &[disabled] {
24
+ cursor: not-allowed;
25
+ @apply opacity-50;
26
+ }
27
+
28
+ &:hover,
29
+ &:focus {
30
+ background-color: rgba(black, 0.04);
31
+ }
32
+
33
+ &--is-active,
34
+ &:active {
35
+ @apply text-blue-300 bg-blue-100;
36
+ }
37
+ }
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import { NodeViewComponentProps } from '@remirror/react';
5
+ import CollapseBox, { CollapseBoxProps } from './CollapseBox';
6
+
7
+ jest.mock('@remirror/react');
8
+
9
+ describe('CollapseBox', () => {
10
+ const createProps = (): CollapseBoxProps => ({
11
+ node: jest.fn() as unknown as NodeViewComponentProps['node'],
12
+ });
13
+
14
+ const props = createProps();
15
+
16
+ it('should display the label correctly', () => {
17
+ const label =
18
+ 'This section cannot be displayed here due to unsupported HTML elements. The front-end view of your page won’t be affected.';
19
+ const { getByText } = render(<CollapseBox {...props} />);
20
+
21
+ expect(getByText(label)).toBeInTheDocument();
22
+ });
23
+
24
+ it('should display the warning icon correctly', () => {
25
+ const { getByTestId } = render(<CollapseBox {...props} />);
26
+
27
+ expect(getByTestId('MotionPhotosOffOutlinedIcon')).toBeInTheDocument();
28
+ });
29
+
30
+ it('should display the collapse icons correctly', () => {
31
+ const { getByTestId, getByRole } = render(<CollapseBox {...props} />);
32
+
33
+ expect(getByTestId('UnfoldLessOutlinedIcon')).toBeInTheDocument();
34
+
35
+ fireEvent.click(getByRole('button'));
36
+
37
+ expect(getByTestId('UnfoldMoreOutlinedIcon')).toBeInTheDocument();
38
+ });
39
+
40
+ it('should hide the content when isVisible is false', () => {
41
+ const { getByTestId, getByRole } = render(<CollapseBox {...props} />);
42
+
43
+ expect(getByTestId('content')).not.toBeVisible();
44
+
45
+ fireEvent.click(getByRole('button'));
46
+
47
+ expect(getByTestId('content')).toBeVisible();
48
+ });
49
+ });
@@ -0,0 +1,36 @@
1
+ import React, { useState } from 'react';
2
+ import { NodeViewComponentProps } from '@remirror/react';
3
+ import MotionPhotosOffOutlinedIcon from '@mui/icons-material/MotionPhotosOffOutlined';
4
+ import UnfoldLessOutlinedIcon from '@mui/icons-material/UnfoldLessOutlined';
5
+ import UnfoldMoreOutlinedIcon from '@mui/icons-material/UnfoldMoreOutlined';
6
+
7
+ export interface CollapseBoxProps {
8
+ node: NodeViewComponentProps['node'];
9
+ }
10
+
11
+ const CollapseBox: React.FC<CollapseBoxProps> = ({ node }) => {
12
+ const [isVisible, setIsVisible] = useState(true);
13
+
14
+ const label =
15
+ 'This section cannot be displayed here due to unsupported HTML elements. The front-end view of your page won’t be affected.';
16
+
17
+ const errorMessage = node?.attrs?.errorMessage;
18
+ const errorNode = JSON.stringify(node?.attrs?.originalNode, null, 3);
19
+
20
+ return (
21
+ <div className="collapse-box" suppressContentEditableWarning={true} contentEditable={false}>
22
+ <button className="collapse-box__header" onClick={() => setIsVisible(!isVisible)} type={'button'}>
23
+ <MotionPhotosOffOutlinedIcon className="collapse-box__icon--warning" />
24
+ <div className="collapse-box__label">{label}</div>
25
+ {isVisible ? <UnfoldLessOutlinedIcon /> : <UnfoldMoreOutlinedIcon />}
26
+ </button>
27
+ <div className="collapse-box__content" hidden={isVisible} data-testid="content">
28
+ {errorMessage}
29
+ <br />
30
+ {errorNode}
31
+ </div>
32
+ </div>
33
+ );
34
+ };
35
+
36
+ export default CollapseBox;
@@ -0,0 +1,23 @@
1
+ .collapse-box {
2
+ @apply text-gray-800 p-2 bg-gray-100 rounded-lg;
3
+
4
+ &__header {
5
+ @apply flex items-center w-full;
6
+ }
7
+
8
+ &__label {
9
+ @apply ml-2 mr-auto text-left;
10
+ }
11
+
12
+ &__icon {
13
+ @apply text-gray-600;
14
+
15
+ &--warning {
16
+ @apply text-red-300;
17
+ }
18
+ }
19
+
20
+ &__content {
21
+ @apply bg-white mt-2 p-2 rounded-lg;
22
+ }
23
+ }
@@ -0,0 +1,50 @@
1
+ import '@testing-library/jest-dom';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import React from 'react';
4
+ import { Checkbox } from './Checkbox';
5
+ import { LinkTarget } from '../../../Extensions/LinkExtension/common';
6
+
7
+ describe('Input', () => {
8
+ const mockOnChange = jest.fn();
9
+
10
+ const CheckboxComponent = ({ defaultChecked = false }: { defaultChecked?: boolean }) => {
11
+ return (
12
+ <Checkbox
13
+ label="This is a test checkbox"
14
+ onChange={mockOnChange}
15
+ defaultChecked={defaultChecked}
16
+ unchecked={'self' as LinkTarget}
17
+ checked={'_blank' as LinkTarget}
18
+ />
19
+ );
20
+ };
21
+
22
+ it('Renders the checkbox label', () => {
23
+ render(<CheckboxComponent />);
24
+ // Check that the supplied label renders
25
+ const checkboxLabel = screen.getByText('This is a test checkbox');
26
+ expect(checkboxLabel).toBeInTheDocument();
27
+ });
28
+
29
+ it('Renders the default checkmark', () => {
30
+ render(<CheckboxComponent defaultChecked={true} />);
31
+ // Check that default value supplied renders
32
+ expect(screen.getByTestId('CheckRoundedIcon')).toBeInTheDocument();
33
+ });
34
+
35
+ it('Does not render the default checkmark', () => {
36
+ render(<CheckboxComponent defaultChecked={false} />);
37
+ expect(screen.queryByTestId('CheckRoundedIcon')).toBeFalsy();
38
+ });
39
+
40
+ it('Toggles checkbox when it is clicked', () => {
41
+ render(<CheckboxComponent />);
42
+ const checkbox = screen.getAllByRole('button')[0];
43
+
44
+ expect(checkbox).toBeTruthy();
45
+ fireEvent.click(checkbox);
46
+
47
+ expect(mockOnChange).toHaveBeenCalled();
48
+ expect(screen.getByTestId('CheckRoundedIcon')).toBeInTheDocument();
49
+ });
50
+ });