@contentful/field-editor-rich-text 3.15.0 → 3.15.2

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 (321) hide show
  1. package/dist/cjs/ContentfulEditorProvider.js +8 -8
  2. package/dist/cjs/RichTextEditor.js +22 -20
  3. package/dist/cjs/RichTextEditor.styles.js +2 -1
  4. package/dist/cjs/SdkProvider.js +7 -5
  5. package/dist/cjs/SyncEditorChanges.js +15 -6
  6. package/dist/cjs/Toolbar/_tests_/toolbar.test.js +17 -15
  7. package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +14 -10
  8. package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +10 -8
  9. package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +2 -2
  10. package/dist/cjs/Toolbar/index.js +33 -30
  11. package/dist/cjs/__fixtures__/FakeSdk.js +3 -3
  12. package/dist/cjs/__fixtures__/asset/index.js +10 -10
  13. package/dist/cjs/__fixtures__/content-type/index.js +1 -1
  14. package/dist/cjs/__fixtures__/entry/index.js +7 -7
  15. package/dist/cjs/__fixtures__/fixtures.js +8 -6
  16. package/dist/cjs/__fixtures__/locale/index.js +2 -2
  17. package/dist/cjs/__fixtures__/space/index.js +1 -1
  18. package/dist/cjs/constants/Schema.js +1 -0
  19. package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +43 -38
  20. package/dist/cjs/dialogs/openRichTextDialog.js +6 -4
  21. package/dist/cjs/dialogs/renderRichTextDialog.js +6 -4
  22. package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +10 -10
  23. package/dist/cjs/helpers/callbacks.js +3 -3
  24. package/dist/cjs/helpers/config.js +2 -2
  25. package/dist/cjs/helpers/editor.js +53 -44
  26. package/dist/cjs/helpers/environment.js +3 -3
  27. package/dist/cjs/helpers/formatDateAndTime.js +5 -4
  28. package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +22 -5
  29. package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +29 -5
  30. package/dist/cjs/helpers/nodeFactory.js +6 -6
  31. package/dist/cjs/helpers/sdkNavigatorSlideIn.js +14 -6
  32. package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +3 -2
  33. package/dist/cjs/helpers/toSlateValue.js +14 -3
  34. package/dist/cjs/helpers/transformers.js +5 -5
  35. package/dist/cjs/helpers/validations.js +12 -9
  36. package/dist/cjs/index.js +7 -5
  37. package/dist/cjs/internal/constants.js +4 -2
  38. package/dist/cjs/internal/hooks.js +8 -6
  39. package/dist/cjs/internal/misc.js +15 -12
  40. package/dist/cjs/internal/queries.js +115 -108
  41. package/dist/cjs/internal/transforms.js +51 -48
  42. package/dist/cjs/internal/types/editor.js +3 -1
  43. package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +4 -3
  44. package/dist/cjs/plugins/Break/createResetNodePlugin.js +1 -0
  45. package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +3 -3
  46. package/dist/cjs/plugins/CommandPalette/components/CommandList.js +35 -33
  47. package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +1 -1
  48. package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +7 -5
  49. package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +7 -3
  50. package/dist/cjs/plugins/CommandPalette/onKeyDown.js +6 -1
  51. package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +6 -4
  52. package/dist/cjs/plugins/CommandPalette/useCommands.js +3 -3
  53. package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +2 -0
  54. package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
  55. package/dist/cjs/plugins/DragAndDrop/index.js +9 -1
  56. package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +10 -8
  57. package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -3
  58. package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +19 -17
  59. package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +9 -7
  60. package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +5 -5
  61. package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +13 -11
  62. package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +5 -5
  63. package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
  64. package/dist/cjs/plugins/Heading/components/Heading.js +13 -10
  65. package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +19 -11
  66. package/dist/cjs/plugins/Heading/createHeadingPlugin.js +7 -2
  67. package/dist/cjs/plugins/Hr/index.js +19 -14
  68. package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +32 -28
  69. package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
  70. package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +8 -6
  71. package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +8 -6
  72. package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +6 -4
  73. package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +7 -5
  74. package/dist/cjs/plugins/Hyperlink/components/styles.js +1 -1
  75. package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +10 -4
  76. package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +6 -3
  77. package/dist/cjs/plugins/Hyperlink/useResourceEntityInfo.js +6 -4
  78. package/dist/cjs/plugins/Hyperlink/utils.js +4 -4
  79. package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +13 -13
  80. package/dist/cjs/plugins/List/__tests__/insertListBreak.test.js +29 -25
  81. package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +22 -22
  82. package/dist/cjs/plugins/List/components/List.js +9 -7
  83. package/dist/cjs/plugins/List/components/ListItem.js +6 -4
  84. package/dist/cjs/plugins/List/components/ToolbarListButton.js +7 -5
  85. package/dist/cjs/plugins/List/createListPlugin.js +4 -0
  86. package/dist/cjs/plugins/List/insertListBreak.js +13 -4
  87. package/dist/cjs/plugins/List/insertListFragment.js +18 -5
  88. package/dist/cjs/plugins/List/onKeyDownList.js +7 -4
  89. package/dist/cjs/plugins/List/transforms/insertListItem.js +17 -2
  90. package/dist/cjs/plugins/List/transforms/moveListItemDown.js +8 -2
  91. package/dist/cjs/plugins/List/transforms/moveListItems.js +7 -2
  92. package/dist/cjs/plugins/List/transforms/moveListItems.test.js +15 -14
  93. package/dist/cjs/plugins/List/transforms/toggleList.js +8 -3
  94. package/dist/cjs/plugins/List/transforms/toggleList.spec.js +28 -28
  95. package/dist/cjs/plugins/List/transforms/unwrapList.js +7 -2
  96. package/dist/cjs/plugins/List/utils.js +12 -11
  97. package/dist/cjs/plugins/List/withList.js +6 -2
  98. package/dist/cjs/plugins/Marks/Bold.js +9 -7
  99. package/dist/cjs/plugins/Marks/Code.js +15 -7
  100. package/dist/cjs/plugins/Marks/Italic.js +9 -7
  101. package/dist/cjs/plugins/Marks/Subscript.js +10 -8
  102. package/dist/cjs/plugins/Marks/Superscript.js +10 -8
  103. package/dist/cjs/plugins/Marks/Underline.js +6 -4
  104. package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +9 -7
  105. package/dist/cjs/plugins/Marks/helpers.js +5 -5
  106. package/dist/cjs/plugins/Normalizer/baseRules.js +2 -0
  107. package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
  108. package/dist/cjs/plugins/Normalizer/utils.js +4 -3
  109. package/dist/cjs/plugins/Normalizer/withNormalizer.js +23 -3
  110. package/dist/cjs/plugins/Paragraph/Paragraph.js +6 -4
  111. package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
  112. package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +3 -2
  113. package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -6
  114. package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
  115. package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +9 -0
  116. package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
  117. package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
  118. package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
  119. package/dist/cjs/plugins/Quote/components/Quote.js +6 -4
  120. package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +6 -4
  121. package/dist/cjs/plugins/Quote/createQuotePlugin.js +1 -0
  122. package/dist/cjs/plugins/Quote/toggleQuote.js +5 -5
  123. package/dist/cjs/plugins/Quote/withQuote.js +4 -2
  124. package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
  125. package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
  126. package/dist/cjs/plugins/Table/__tests__/helpers.test.js +4 -4
  127. package/dist/cjs/plugins/Table/actions/addColumn.js +5 -4
  128. package/dist/cjs/plugins/Table/actions/addRow.js +6 -3
  129. package/dist/cjs/plugins/Table/components/Cell.js +7 -5
  130. package/dist/cjs/plugins/Table/components/HeaderCell.js +7 -5
  131. package/dist/cjs/plugins/Table/components/Row.js +6 -4
  132. package/dist/cjs/plugins/Table/components/Table.js +8 -6
  133. package/dist/cjs/plugins/Table/components/TableActions.js +19 -16
  134. package/dist/cjs/plugins/Table/components/ToolbarButton.js +7 -4
  135. package/dist/cjs/plugins/Table/createTablePlugin.js +11 -1
  136. package/dist/cjs/plugins/Table/helpers.js +16 -12
  137. package/dist/cjs/plugins/Table/insertTableFragment.js +15 -2
  138. package/dist/cjs/plugins/Table/onKeyDownTable.js +10 -2
  139. package/dist/cjs/plugins/Table/tableTracking.js +6 -6
  140. package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
  141. package/dist/cjs/plugins/Text/createTextPlugin.js +22 -5
  142. package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +5 -4
  143. package/dist/cjs/plugins/Tracking/utils.js +6 -3
  144. package/dist/cjs/plugins/Voids/createVoidsPlugin.js +5 -0
  145. package/dist/cjs/plugins/Voids/transformVoid.js +1 -0
  146. package/dist/cjs/plugins/index.js +15 -3
  147. package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +12 -10
  148. package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +16 -6
  149. package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +10 -8
  150. package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +9 -5
  151. package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +13 -11
  152. package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +14 -12
  153. package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +14 -11
  154. package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +8 -4
  155. package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +10 -6
  156. package/dist/cjs/plugins/shared/ResourceNewBadge.js +5 -3
  157. package/dist/cjs/plugins/shared/ToolbarButton.js +8 -6
  158. package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +10 -5
  159. package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +11 -6
  160. package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +15 -13
  161. package/dist/cjs/plugins/shared/utils.js +4 -1
  162. package/dist/cjs/test-utils/assertOutput.js +1 -0
  163. package/dist/cjs/test-utils/hyperscript.d.js +1 -0
  164. package/dist/cjs/test-utils/randomId.js +3 -1
  165. package/dist/cjs/test-utils/validation.js +8 -5
  166. package/dist/esm/ContentfulEditorProvider.js +4 -1
  167. package/dist/esm/RichTextEditor.js +13 -13
  168. package/dist/esm/RichTextEditor.styles.js +1 -0
  169. package/dist/esm/SdkProvider.js +2 -2
  170. package/dist/esm/SyncEditorChanges.js +18 -3
  171. package/dist/esm/Toolbar/_tests_/toolbar.test.js +12 -12
  172. package/dist/esm/Toolbar/components/EmbedEntityWidget.js +10 -8
  173. package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +6 -6
  174. package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +1 -1
  175. package/dist/esm/Toolbar/index.js +28 -27
  176. package/dist/esm/__fixtures__/FakeSdk.js +3 -3
  177. package/dist/esm/constants/Schema.js +1 -0
  178. package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +34 -31
  179. package/dist/esm/dialogs/openRichTextDialog.js +2 -2
  180. package/dist/esm/dialogs/renderRichTextDialog.js +2 -2
  181. package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +10 -10
  182. package/dist/esm/helpers/callbacks.js +1 -1
  183. package/dist/esm/helpers/config.js +9 -1
  184. package/dist/esm/helpers/editor.js +22 -6
  185. package/dist/esm/helpers/extractNodes.js +3 -1
  186. package/dist/esm/helpers/formatDateAndTime.js +11 -2
  187. package/dist/esm/helpers/getAllowedResourcesForNodeType.js +19 -2
  188. package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +26 -2
  189. package/dist/esm/helpers/sdkNavigatorSlideIn.js +20 -6
  190. package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +1 -0
  191. package/dist/esm/helpers/toSlateValue.js +17 -3
  192. package/dist/esm/helpers/validations.js +5 -1
  193. package/dist/esm/internal/misc.js +23 -2
  194. package/dist/esm/internal/queries.js +11 -2
  195. package/dist/esm/internal/transforms.js +14 -3
  196. package/dist/esm/internal/types/editor.js +3 -1
  197. package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +4 -3
  198. package/dist/esm/plugins/Break/createResetNodePlugin.js +1 -0
  199. package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +3 -3
  200. package/dist/esm/plugins/CommandPalette/components/CommandList.js +30 -30
  201. package/dist/esm/plugins/CommandPalette/components/CommandPrompt.js +2 -2
  202. package/dist/esm/plugins/CommandPalette/createCommandPalettePlugin.js +11 -1
  203. package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +2 -0
  204. package/dist/esm/plugins/CommandPalette/onKeyDown.js +5 -0
  205. package/dist/esm/plugins/CommandPalette/onKeyDown.spec.js +2 -2
  206. package/dist/esm/plugins/CommandPalette/useCommands.js +3 -3
  207. package/dist/esm/plugins/CommandPalette/utils/fetchEntries.js +2 -0
  208. package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
  209. package/dist/esm/plugins/DragAndDrop/index.js +9 -1
  210. package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +6 -6
  211. package/dist/esm/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +14 -14
  212. package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +5 -5
  213. package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +4 -4
  214. package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +9 -9
  215. package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +4 -4
  216. package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
  217. package/dist/esm/plugins/Heading/components/Heading.js +8 -7
  218. package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +14 -8
  219. package/dist/esm/plugins/Heading/createHeadingPlugin.js +6 -1
  220. package/dist/esm/plugins/Hr/index.js +8 -5
  221. package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +25 -23
  222. package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
  223. package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +4 -4
  224. package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +4 -4
  225. package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +2 -2
  226. package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +3 -3
  227. package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +5 -1
  228. package/dist/esm/plugins/Hyperlink/useEntityInfo.js +6 -3
  229. package/dist/esm/plugins/Hyperlink/useResourceEntityInfo.js +2 -2
  230. package/dist/esm/plugins/Hyperlink/utils.js +1 -1
  231. package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +13 -13
  232. package/dist/esm/plugins/List/__tests__/insertListBreak.test.js +29 -25
  233. package/dist/esm/plugins/List/__tests__/insertListFragment.test.js +22 -22
  234. package/dist/esm/plugins/List/components/List.js +1 -1
  235. package/dist/esm/plugins/List/components/ListItem.js +1 -1
  236. package/dist/esm/plugins/List/components/ToolbarListButton.js +3 -3
  237. package/dist/esm/plugins/List/createListPlugin.js +4 -0
  238. package/dist/esm/plugins/List/insertListBreak.js +13 -4
  239. package/dist/esm/plugins/List/insertListFragment.js +18 -5
  240. package/dist/esm/plugins/List/onKeyDownList.js +5 -2
  241. package/dist/esm/plugins/List/transforms/insertListItem.js +20 -3
  242. package/dist/esm/plugins/List/transforms/moveListItemDown.js +8 -2
  243. package/dist/esm/plugins/List/transforms/moveListItems.js +7 -2
  244. package/dist/esm/plugins/List/transforms/moveListItems.test.js +15 -14
  245. package/dist/esm/plugins/List/transforms/toggleList.js +8 -3
  246. package/dist/esm/plugins/List/transforms/toggleList.spec.js +28 -28
  247. package/dist/esm/plugins/List/transforms/unwrapList.js +7 -2
  248. package/dist/esm/plugins/List/utils.js +7 -2
  249. package/dist/esm/plugins/List/withList.js +6 -2
  250. package/dist/esm/plugins/Marks/Bold.js +2 -2
  251. package/dist/esm/plugins/Marks/Code.js +8 -2
  252. package/dist/esm/plugins/Marks/Italic.js +2 -2
  253. package/dist/esm/plugins/Marks/Subscript.js +2 -2
  254. package/dist/esm/plugins/Marks/Superscript.js +2 -2
  255. package/dist/esm/plugins/Marks/Underline.js +2 -2
  256. package/dist/esm/plugins/Marks/components/MarkToolbarButton.js +4 -4
  257. package/dist/esm/plugins/Marks/helpers.js +1 -1
  258. package/dist/esm/plugins/Normalizer/baseRules.js +4 -0
  259. package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
  260. package/dist/esm/plugins/Normalizer/utils.js +1 -0
  261. package/dist/esm/plugins/Normalizer/withNormalizer.js +22 -2
  262. package/dist/esm/plugins/Paragraph/Paragraph.js +1 -1
  263. package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
  264. package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +2 -1
  265. package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -3
  266. package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
  267. package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +27 -1
  268. package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
  269. package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
  270. package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
  271. package/dist/esm/plugins/Quote/components/Quote.js +1 -1
  272. package/dist/esm/plugins/Quote/components/ToolbarQuoteButton.js +2 -2
  273. package/dist/esm/plugins/Quote/createQuotePlugin.js +1 -0
  274. package/dist/esm/plugins/Quote/shouldResetQuote.js +6 -1
  275. package/dist/esm/plugins/Quote/toggleQuote.js +1 -1
  276. package/dist/esm/plugins/Quote/withQuote.js +4 -2
  277. package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
  278. package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
  279. package/dist/esm/plugins/Table/__tests__/helpers.test.js +4 -4
  280. package/dist/esm/plugins/Table/actions/addColumn.js +2 -1
  281. package/dist/esm/plugins/Table/actions/addRow.js +3 -0
  282. package/dist/esm/plugins/Table/components/Cell.js +2 -2
  283. package/dist/esm/plugins/Table/components/HeaderCell.js +2 -2
  284. package/dist/esm/plugins/Table/components/Row.js +1 -1
  285. package/dist/esm/plugins/Table/components/Table.js +3 -3
  286. package/dist/esm/plugins/Table/components/TableActions.js +12 -11
  287. package/dist/esm/plugins/Table/components/ToolbarButton.js +3 -2
  288. package/dist/esm/plugins/Table/createTablePlugin.js +11 -1
  289. package/dist/esm/plugins/Table/helpers.js +10 -1
  290. package/dist/esm/plugins/Table/insertTableFragment.js +15 -2
  291. package/dist/esm/plugins/Table/onKeyDownTable.js +10 -2
  292. package/dist/esm/plugins/Table/tableTracking.js +6 -6
  293. package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
  294. package/dist/esm/plugins/Text/createTextPlugin.js +22 -5
  295. package/dist/esm/plugins/Tracking/createTrackingPlugin.js +2 -1
  296. package/dist/esm/plugins/Tracking/utils.js +1 -0
  297. package/dist/esm/plugins/Voids/createVoidsPlugin.js +5 -0
  298. package/dist/esm/plugins/Voids/transformVoid.js +4 -1
  299. package/dist/esm/plugins/index.js +12 -0
  300. package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +5 -5
  301. package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +15 -5
  302. package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +5 -5
  303. package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +8 -4
  304. package/dist/esm/plugins/shared/FetchingWrappedAssetCard.js +8 -8
  305. package/dist/esm/plugins/shared/FetchingWrappedEntryCard.js +9 -9
  306. package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +9 -8
  307. package/dist/esm/plugins/shared/LinkedBlockWrapper.js +7 -3
  308. package/dist/esm/plugins/shared/LinkedInlineWrapper.js +5 -3
  309. package/dist/esm/plugins/shared/ResourceNewBadge.js +1 -1
  310. package/dist/esm/plugins/shared/ToolbarButton.js +3 -3
  311. package/dist/esm/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +5 -2
  312. package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +5 -2
  313. package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +8 -8
  314. package/dist/esm/plugins/shared/utils.js +4 -1
  315. package/dist/esm/test-utils/assertOutput.js +1 -0
  316. package/dist/esm/test-utils/hyperscript.d.js +1 -0
  317. package/dist/esm/test-utils/jsx.js +5 -1
  318. package/dist/esm/test-utils/randomId.js +3 -1
  319. package/dist/esm/test-utils/setEmptyDataAttribute.js +4 -1
  320. package/dist/esm/test-utils/validation.js +7 -4
  321. package/package.json +3 -3
@@ -1,4 +1,7 @@
1
- import { BLOCKS } from '@contentful/rich-text-types';
1
+ /**
2
+ * Credit: Modified version of Plate's list plugin
3
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4
+ */ import { BLOCKS } from '@contentful/rich-text-types';
2
5
  import { ELEMENT_LIC } from '@udecode/plate-list';
3
6
  import { getListItemEntry } from '@udecode/plate-list';
4
7
  import { withoutNormalizing } from '../../../internal';
@@ -10,14 +13,15 @@ const listTypes = [
10
13
  BLOCKS.UL_LIST,
11
14
  BLOCKS.OL_LIST
12
15
  ];
13
- export const toggleList = (editor, { type })=>withoutNormalizing(editor, ()=>{
16
+ export const toggleList = (editor, { type })=>withoutNormalizing(editor, ()=>{
14
17
  if (!editor.selection) {
15
18
  return;
16
19
  }
17
20
  if (isRangeCollapsed(editor.selection) || !isRangeAcrossBlocks(editor)) {
21
+ // selection is collapsed
18
22
  const res = getListItemEntry(editor);
19
23
  if (res) {
20
- const { list } = res;
24
+ const { list } = res;
21
25
  if (list[0].type !== type) {
22
26
  setNodes(editor, {
23
27
  type
@@ -55,6 +59,7 @@ export const toggleList = (editor, { type })=>withoutNormalizing(editor, ()=>{
55
59
  }
56
60
  }
57
61
  } else {
62
+ // selection is a range
58
63
  const [startPoint, endPoint] = getRangeEdges(editor.selection);
59
64
  const commonEntry = getCommonNode(editor, startPoint.path, endPoint.path);
60
65
  if (listTypes.includes(commonEntry[0].type) || commonEntry[0].type === BLOCKS.LIST_ITEM) {
@@ -1,11 +1,11 @@
1
- import { BLOCKS } from '@contentful/rich-text-types';
1
+ /** @jsx jsx */ import { BLOCKS } from '@contentful/rich-text-types';
2
2
  import { assertOutput, jsx, createTestEditor } from '../../../test-utils';
3
3
  import { toggleList } from './toggleList';
4
4
  describe('toggle on', ()=>{
5
5
  it('should turn a p to list', ()=>{
6
- const input = jsx("editor", null, jsx("hp", null, "1", jsx("cursor", null)));
7
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1", jsx("cursor", null)))), jsx("hp", null, jsx("htext", null)));
8
- const { editor } = createTestEditor({
6
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, "1", /*#__PURE__*/ jsx("cursor", null)));
7
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1", /*#__PURE__*/ jsx("cursor", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
8
+ const { editor } = createTestEditor({
9
9
  input
10
10
  });
11
11
  toggleList(editor, {
@@ -17,9 +17,9 @@ describe('toggle on', ()=>{
17
17
  });
18
18
  });
19
19
  it('should turn a p with a selection to list', ()=>{
20
- const input = jsx("editor", null, jsx("hp", null, "Planetas ", jsx("anchor", null), "mori in", jsx("focus", null), " gandavum!"));
21
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Planetas ", jsx("anchor", null), "mori in", jsx("focus", null), " gandavum!"))), jsx("hp", null, jsx("htext", null)));
22
- const { editor } = createTestEditor({
20
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, "Planetas ", /*#__PURE__*/ jsx("anchor", null), "mori in", /*#__PURE__*/ jsx("focus", null), " gandavum!"));
21
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Planetas ", /*#__PURE__*/ jsx("anchor", null), "mori in", /*#__PURE__*/ jsx("focus", null), " gandavum!"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
22
+ const { editor } = createTestEditor({
23
23
  input
24
24
  });
25
25
  toggleList(editor, {
@@ -31,9 +31,9 @@ describe('toggle on', ()=>{
31
31
  });
32
32
  });
33
33
  it('should turn multiple p to list', ()=>{
34
- const input = jsx("editor", null, jsx("hp", null, jsx("anchor", null), "1"), jsx("hp", null, "2"), jsx("hp", null, "3", jsx("focus", null)));
35
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("anchor", null), "1")), jsx("hli", null, jsx("hp", null, "2")), jsx("hli", null, jsx("hp", null, "3", jsx("focus", null)))), jsx("hp", null, jsx("htext", null)));
36
- const { editor } = createTestEditor({
34
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1"), /*#__PURE__*/ jsx("hp", null, "2"), /*#__PURE__*/ jsx("hp", null, "3", /*#__PURE__*/ jsx("focus", null)));
35
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "2")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "3", /*#__PURE__*/ jsx("focus", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
36
+ const { editor } = createTestEditor({
37
37
  input
38
38
  });
39
39
  toggleList(editor, {
@@ -47,9 +47,9 @@ describe('toggle on', ()=>{
47
47
  });
48
48
  describe('toggle off', ()=>{
49
49
  it('should split a simple list to two', ()=>{
50
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1")), jsx("hli", null, jsx("hp", null, "2", jsx("cursor", null))), jsx("hli", null, jsx("hp", null, "3"))));
51
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1"))), jsx("hp", null, "2", jsx("cursor", null)), jsx("hul", null, jsx("hli", null, jsx("hp", null, "3"))), jsx("hp", null, jsx("htext", null)));
52
- const { editor } = createTestEditor({
50
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "2", /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "3"))));
51
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"))), /*#__PURE__*/ jsx("hp", null, "2", /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "3"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
52
+ const { editor } = createTestEditor({
53
53
  input
54
54
  });
55
55
  toggleList(editor, {
@@ -61,9 +61,9 @@ describe('toggle off', ()=>{
61
61
  });
62
62
  });
63
63
  it('should split a nested list', ()=>{
64
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "11")), jsx("hli", null, jsx("hp", null, "12", jsx("cursor", null))), jsx("hli", null, jsx("hp", null, "13"))))));
65
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "11"))))), jsx("hp", null, "12", jsx("cursor", null)), jsx("hul", null, jsx("hli", null, jsx("hp", null, "13"))), jsx("hp", null, jsx("htext", null)));
66
- const { editor } = createTestEditor({
64
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "12", /*#__PURE__*/ jsx("cursor", null))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "13"))))));
65
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11"))))), /*#__PURE__*/ jsx("hp", null, "12", /*#__PURE__*/ jsx("cursor", null)), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "13"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
66
+ const { editor } = createTestEditor({
67
67
  input
68
68
  });
69
69
  toggleList(editor, {
@@ -75,9 +75,9 @@ describe('toggle off', ()=>{
75
75
  });
76
76
  });
77
77
  it('should turn a list to multiple p', ()=>{
78
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("anchor", null), "1")), jsx("hli", null, jsx("hp", null, "2")), jsx("hli", null, jsx("hp", null, "3", jsx("focus", null)))));
79
- const expected = jsx("editor", null, jsx("hp", null, jsx("anchor", null), "1"), jsx("hp", null, "2"), jsx("hp", null, "3", jsx("focus", null)));
80
- const { editor } = createTestEditor({
78
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "2")), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "3", /*#__PURE__*/ jsx("focus", null)))));
79
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1"), /*#__PURE__*/ jsx("hp", null, "2"), /*#__PURE__*/ jsx("hp", null, "3", /*#__PURE__*/ jsx("focus", null)));
80
+ const { editor } = createTestEditor({
81
81
  input
82
82
  });
83
83
  toggleList(editor, {
@@ -91,9 +91,9 @@ describe('toggle off', ()=>{
91
91
  });
92
92
  describe('toggle over', ()=>{
93
93
  it('should toggle different list types', ()=>{
94
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1", jsx("cursor", null)))));
95
- const expected = jsx("editor", null, jsx("hol", null, jsx("hli", null, jsx("hp", null, "1"))), jsx("hp", null, jsx("htext", null)));
96
- const { editor } = createTestEditor({
94
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1", /*#__PURE__*/ jsx("cursor", null)))));
95
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hol", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
96
+ const { editor } = createTestEditor({
97
97
  input
98
98
  });
99
99
  toggleList(editor, {
@@ -105,9 +105,9 @@ describe('toggle over', ()=>{
105
105
  });
106
106
  });
107
107
  it('should only toggle the nested list', ()=>{
108
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "11", jsx("cursor", null)))))));
109
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "1"), jsx("hol", null, jsx("hli", null, jsx("hp", null, "11", jsx("cursor", null)))))), jsx("hp", null, jsx("htext", null)));
110
- const { editor } = createTestEditor({
108
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11", /*#__PURE__*/ jsx("cursor", null)))))));
109
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "1"), /*#__PURE__*/ jsx("hol", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11", /*#__PURE__*/ jsx("cursor", null)))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
110
+ const { editor } = createTestEditor({
111
111
  input
112
112
  });
113
113
  toggleList(editor, {
@@ -119,9 +119,9 @@ describe('toggle over', ()=>{
119
119
  });
120
120
  });
121
121
  it('should only toggle everything that is selected', ()=>{
122
- const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("anchor", null), "1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "11", jsx("focus", null)))))));
123
- const expected = jsx("editor", null, jsx("hol", null, jsx("hli", null, jsx("hp", null, jsx("anchor", null), "1"), jsx("hol", null, jsx("hli", null, jsx("hp", null, "11", jsx("focus", null)))))), jsx("hp", null, jsx("htext", null)));
124
- const { editor } = createTestEditor({
122
+ const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11", /*#__PURE__*/ jsx("focus", null)))))));
123
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hol", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("anchor", null), "1"), /*#__PURE__*/ jsx("hol", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "11", /*#__PURE__*/ jsx("focus", null)))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
124
+ const { editor } = createTestEditor({
125
125
  input
126
126
  });
127
127
  toggleList(editor, {
@@ -1,4 +1,7 @@
1
- import { BLOCKS } from '@contentful/rich-text-types';
1
+ /**
2
+ * Credit: Modified version of Plate's list plugin
3
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4
+ */ import { BLOCKS } from '@contentful/rich-text-types';
2
5
  import { withoutNormalizing } from '../../../internal';
3
6
  import { getNodeEntries, isElement } from '../../../internal/queries';
4
7
  import { unwrapNodes, liftNodes } from '../../../internal/transforms';
@@ -8,15 +11,17 @@ function hasUnliftedListItems(editor, at) {
8
11
  match: (node, path)=>isElement(node) && node.type === BLOCKS.LIST_ITEM && path.length >= 2
9
12
  }).next().done;
10
13
  }
11
- export const unwrapList = (editor, { at } = {})=>{
14
+ export const unwrapList = (editor, { at } = {})=>{
12
15
  withoutNormalizing(editor, ()=>{
13
16
  do {
17
+ // lift list items to the root level
14
18
  liftNodes(editor, {
15
19
  at,
16
20
  match: (node)=>isElement(node) && node.type === BLOCKS.LIST_ITEM,
17
21
  mode: 'lowest'
18
22
  });
19
23
  }while (!hasUnliftedListItems(editor, at))
24
+ // finally unwrap all lifted items
20
25
  unwrapNodes(editor, {
21
26
  at,
22
27
  match: {
@@ -16,7 +16,11 @@ const getNearestListAncestor = (editor, path)=>{
16
16
  match: isList
17
17
  }) || [];
18
18
  };
19
- export const normalizeOrphanedListItem = (editor, [, path])=>{
19
+ /**
20
+ * Places orphaned list items in a list. If there's a list somewhere
21
+ * in the node's ancestors, defaults to that list type, else places
22
+ * the list item in an unordered list.
23
+ */ export const normalizeOrphanedListItem = (editor, [, path])=>{
20
24
  const [parentList] = getNearestListAncestor(editor, path);
21
25
  const parentListType = parentList?.type;
22
26
  wrapNodes(editor, {
@@ -65,7 +69,7 @@ export const replaceNodeWithListItems = (editor, entry)=>{
65
69
  });
66
70
  };
67
71
  export const isListTypeActive = (editor, type)=>{
68
- const { selection } = editor;
72
+ const { selection } = editor;
69
73
  if (!selection) {
70
74
  return false;
71
75
  }
@@ -76,6 +80,7 @@ export const isListTypeActive = (editor, type)=>{
76
80
  return true;
77
81
  }
78
82
  }
83
+ // Lists can be nested. Here, we take the list type at the lowest level
79
84
  const listNode = getBlockAbove(editor, {
80
85
  match: {
81
86
  type: [
@@ -1,10 +1,13 @@
1
- import { LIST_ITEM_BLOCKS } from '@contentful/rich-text-types';
1
+ /**
2
+ * Credit: Modified version of Plate's list plugin
3
+ * See: https://github.com/udecode/plate/blob/main/packages/nodes/list
4
+ */ import { LIST_ITEM_BLOCKS } from '@contentful/rich-text-types';
2
5
  import { normalizeList, deleteFragmentList, deleteForwardList } from '@udecode/plate-list';
3
6
  import { insertListBreak } from './insertListBreak';
4
7
  import { insertListFragment } from './insertListFragment';
5
8
  const validLiChildrenTypes = LIST_ITEM_BLOCKS;
6
9
  export const withList = (editor)=>{
7
- const { deleteForward , deleteFragment } = editor;
10
+ const { deleteForward, deleteFragment } = editor;
8
11
  editor.deleteForward = (unit)=>{
9
12
  if (deleteForwardList(editor)) return;
10
13
  deleteForward(unit);
@@ -15,6 +18,7 @@ export const withList = (editor)=>{
15
18
  };
16
19
  editor.insertBreak = insertListBreak(editor);
17
20
  editor.insertFragment = insertListFragment(editor);
21
+ // TODO: replace with our own Normalizer rules
18
22
  editor.normalizeNode = normalizeList(editor, {
19
23
  validLiChildrenTypes
20
24
  });
@@ -9,7 +9,7 @@ import { buildMarkEventHandler } from './helpers';
9
9
  export const ToolbarBoldButton = createMarkToolbarButton({
10
10
  title: 'Bold',
11
11
  mark: MARKS.BOLD,
12
- icon: React.createElement(FormatBoldIcon, null)
12
+ icon: /*#__PURE__*/ React.createElement(FormatBoldIcon, null)
13
13
  });
14
14
  const styles = {
15
15
  bold: css({
@@ -17,7 +17,7 @@ const styles = {
17
17
  })
18
18
  };
19
19
  export function Bold(props) {
20
- return React.createElement("strong", {
20
+ return /*#__PURE__*/ React.createElement("strong", {
21
21
  ...props.attributes,
22
22
  className: styles.bold
23
23
  }, props.children);
@@ -8,7 +8,7 @@ import { buildMarkEventHandler } from './helpers';
8
8
  export const ToolbarCodeButton = createMarkToolbarButton({
9
9
  title: 'Code',
10
10
  mark: MARKS.CODE,
11
- icon: React.createElement(CodeIcon, null)
11
+ icon: /*#__PURE__*/ React.createElement(CodeIcon, null)
12
12
  });
13
13
  export const ToolbarDropdownCodeButton = createMarkToolbarButton({
14
14
  title: 'Code',
@@ -21,7 +21,7 @@ const styles = {
21
21
  })
22
22
  };
23
23
  export function Code(props) {
24
- return React.createElement("code", {
24
+ return /*#__PURE__*/ React.createElement("code", {
25
25
  ...props.attributes,
26
26
  className: styles.code
27
27
  }, props.children);
@@ -30,6 +30,12 @@ export const createCodePlugin = ()=>createDefaultCodePlugin({
30
30
  type: MARKS.CODE,
31
31
  component: Code,
32
32
  options: {
33
+ // We need to define multiple hotkeys here,
34
+ // - mod+/ -> QWERTY keyboard layout
35
+ // - mod+shift+7 -> QWERTZ keyboard layout
36
+ // The workaround like in packages/rich-text/src/plugins/CommandPalette/onKeyDown.ts is sadly not working here,
37
+ // as `shift+7` is not interpreted as `/` with the `mod` key by the OS.
38
+ // TODO: there are a lot more different keyboard layouts out there
33
39
  hotkey: [
34
40
  'mod+/',
35
41
  'mod+shift+7'
@@ -9,7 +9,7 @@ import { buildMarkEventHandler } from './helpers';
9
9
  export const ToolbarItalicButton = createMarkToolbarButton({
10
10
  title: 'Italic',
11
11
  mark: MARKS.ITALIC,
12
- icon: React.createElement(FormatItalicIcon, null)
12
+ icon: /*#__PURE__*/ React.createElement(FormatItalicIcon, null)
13
13
  });
14
14
  const styles = {
15
15
  italic: css({
@@ -17,7 +17,7 @@ const styles = {
17
17
  })
18
18
  };
19
19
  export function Italic(props) {
20
- return React.createElement("em", {
20
+ return /*#__PURE__*/ React.createElement("em", {
21
21
  ...props.attributes,
22
22
  className: styles.italic
23
23
  }, props.children);
@@ -14,7 +14,7 @@ const styles = {
14
14
  export const ToolbarSubscriptButton = createMarkToolbarButton({
15
15
  title: 'Subscript',
16
16
  mark: MARKS.SUBSCRIPT,
17
- icon: React.createElement(SubscriptIcon, {
17
+ icon: /*#__PURE__*/ React.createElement(SubscriptIcon, {
18
18
  viewBox: "0 0 23 18"
19
19
  })
20
20
  });
@@ -23,7 +23,7 @@ export const ToolbarDropdownSubscriptButton = createMarkToolbarButton({
23
23
  mark: MARKS.SUBSCRIPT
24
24
  });
25
25
  export function Subscript(props) {
26
- return React.createElement("sub", {
26
+ return /*#__PURE__*/ React.createElement("sub", {
27
27
  ...props.attributes,
28
28
  className: styles.subscript
29
29
  }, props.children);
@@ -14,14 +14,14 @@ const styles = {
14
14
  export const ToolbarSuperscriptButton = createMarkToolbarButton({
15
15
  title: 'Superscript',
16
16
  mark: MARKS.SUPERSCRIPT,
17
- icon: React.createElement(SuperscriptIcon, null)
17
+ icon: /*#__PURE__*/ React.createElement(SuperscriptIcon, null)
18
18
  });
19
19
  export const ToolbarDropdownSuperscriptButton = createMarkToolbarButton({
20
20
  title: 'Superscript',
21
21
  mark: MARKS.SUPERSCRIPT
22
22
  });
23
23
  export function Superscript(props) {
24
- return React.createElement("sup", {
24
+ return /*#__PURE__*/ React.createElement("sup", {
25
25
  ...props.attributes,
26
26
  className: styles.superscript
27
27
  }, props.children);
@@ -8,10 +8,10 @@ import { buildMarkEventHandler } from './helpers';
8
8
  export const ToolbarUnderlineButton = createMarkToolbarButton({
9
9
  title: 'Underline',
10
10
  mark: MARKS.UNDERLINE,
11
- icon: React.createElement(FormatUnderlinedIcon, null)
11
+ icon: /*#__PURE__*/ React.createElement(FormatUnderlinedIcon, null)
12
12
  });
13
13
  export function Underline(props) {
14
- return React.createElement("u", props.attributes, props.children);
14
+ return /*#__PURE__*/ React.createElement("u", props.attributes, props.children);
15
15
  }
16
16
  export const createUnderlinePlugin = ()=>createDefaultUnderlinePlugin({
17
17
  type: MARKS.UNDERLINE,
@@ -13,8 +13,8 @@ const styles = {
13
13
  color: tokens.blue600
14
14
  })
15
15
  };
16
- export const createMarkToolbarButton = ({ mark , title , icon })=>{
17
- const Mark = ({ isDisabled })=>{
16
+ export const createMarkToolbarButton = ({ mark, title, icon })=>{
17
+ const Mark = ({ isDisabled })=>{
18
18
  const editor = useContentfulEditor();
19
19
  const handleClick = React.useCallback(()=>{
20
20
  if (!editor?.selection) return;
@@ -29,7 +29,7 @@ export const createMarkToolbarButton = ({ mark , title , icon })=>{
29
29
  ]);
30
30
  if (!editor) return null;
31
31
  if (!icon) {
32
- return React.createElement(Menu.Item, {
32
+ return /*#__PURE__*/ React.createElement(Menu.Item, {
33
33
  onClick: handleClick,
34
34
  disabled: isDisabled,
35
35
  className: cx({
@@ -38,7 +38,7 @@ export const createMarkToolbarButton = ({ mark , title , icon })=>{
38
38
  testId: `${mark}-toolbar-button`
39
39
  }, title);
40
40
  }
41
- return React.createElement(ToolbarButton, {
41
+ return /*#__PURE__*/ React.createElement(ToolbarButton, {
42
42
  title: title,
43
43
  testId: `${mark}-toolbar-button`,
44
44
  onClick: handleClick,
@@ -13,7 +13,7 @@ export const toggleMarkAndDeactivateConflictingMarks = (editor, mark)=>{
13
13
  clear
14
14
  });
15
15
  };
16
- export const buildMarkEventHandler = (type)=>(editor, { options: { hotkey } })=>(event)=>{
16
+ export const buildMarkEventHandler = (type)=>(editor, { options: { hotkey } })=>(event)=>{
17
17
  if (editor.selection && hotkey && isHotkey(hotkey, event)) {
18
18
  event.preventDefault();
19
19
  const isActive = isMarkActive(editor, type);
@@ -4,8 +4,11 @@ import { transformWrapIn } from '../../helpers/transformers';
4
4
  import { getParentNode, isText } from '../../internal/queries';
5
5
  const isInline = (node)=>INLINE_TYPES.includes(node.type);
6
6
  const isTextContainer = (node)=>TEXT_CONTAINERS.includes(node.type);
7
+ // Base rules are rules that must be enforced at all times regardless
8
+ // of which plugins are enabled.
7
9
  export const baseRules = [
8
10
  {
11
+ // Wrap orphaned text nodes in a paragraph
9
12
  match: isText,
10
13
  validNode: (editor, [, path])=>{
11
14
  const parent = getParentNode(editor, path)?.[0];
@@ -16,6 +19,7 @@ export const baseRules = [
16
19
  }
17
20
  },
18
21
  {
22
+ // Wrap orphaned inline nodes in a paragraph,
19
23
  match: {
20
24
  type: INLINE_TYPES
21
25
  },
@@ -1,4 +1,4 @@
1
- import { BLOCKS, INLINES } from '@contentful/rich-text-types';
1
+ /** @jsx jsx */ import { BLOCKS, INLINES } from '@contentful/rich-text-types';
2
2
  import { transformWrapIn } from '../../helpers/transformers';
3
3
  import { jsx, createTestEditor, mockPlugin, assertOutput } from '../../test-utils';
4
4
  import { createNormalizerPlugin } from './createNormalizerPlugin';
@@ -12,15 +12,15 @@ describe('Normalizer', ()=>{
12
12
  ];
13
13
  let input;
14
14
  beforeEach(()=>{
15
- input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hembed", {
15
+ input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hembed", {
16
16
  type: "Entry",
17
17
  id: "embedded-entry"
18
- }), jsx("hp", null, "List item"))));
18
+ }), /*#__PURE__*/ jsx("hp", null, "List item"))));
19
19
  });
20
- const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "List item"))));
20
+ const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "List item"))));
21
21
  describe('rule.match', ()=>{
22
22
  it('matches elements of type "plugin.type" by default', ()=>{
23
- const { editor } = createTestEditor({
23
+ const { editor } = createTestEditor({
24
24
  input,
25
25
  plugins: [
26
26
  mockPlugin({
@@ -50,14 +50,14 @@ describe('Normalizer', ()=>{
50
50
  });
51
51
  describe('rule.transform', ()=>{
52
52
  it('works with conditional transformation', ()=>{
53
- const { editor } = createTestEditor({
54
- input: jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hembed", {
53
+ const { editor } = createTestEditor({
54
+ input: /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hembed", {
55
55
  type: "Entry",
56
56
  id: "embedded-entry"
57
- }), jsx("hinline", {
57
+ }), /*#__PURE__*/ jsx("hinline", {
58
58
  type: "Entry",
59
59
  id: "inline-entry"
60
- }), jsx("hp", null, "List item")))),
60
+ }), /*#__PURE__*/ jsx("hp", null, "List item")))),
61
61
  plugins: [
62
62
  mockPlugin({
63
63
  isElement: true,
@@ -78,16 +78,16 @@ describe('Normalizer', ()=>{
78
78
  });
79
79
  assertOutput({
80
80
  editor,
81
- expected: jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("hinline", {
81
+ expected: /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("hinline", {
82
82
  type: "Entry",
83
83
  id: "inline-entry"
84
- })), jsx("hp", null, "List item"))))
84
+ })), /*#__PURE__*/ jsx("hp", null, "List item"))))
85
85
  });
86
86
  });
87
87
  });
88
88
  describe('rule.validChildren', ()=>{
89
89
  it('supports custom functions', ()=>{
90
- const { editor } = createTestEditor({
90
+ const { editor } = createTestEditor({
91
91
  input,
92
92
  plugins: [
93
93
  mockPlugin({
@@ -5,6 +5,7 @@ export const createValidatorFromTypes = (types)=>(_, [node])=>{
5
5
  return isElement(node) && types.includes(node.type);
6
6
  };
7
7
  export const createTransformerFromObject = (transforms)=>{
8
+ // A default transformer must always be provided
8
9
  const fallback = transforms['default'];
9
10
  if (!fallback) {
10
11
  throw new NormalizerError('A default transformer MUST be provided');
@@ -6,25 +6,35 @@ import { baseRules } from './baseRules';
6
6
  import { NormalizerError, createValidatorFromTypes, createTransformerFromObject } from './utils';
7
7
  export const withNormalizer = (editor)=>{
8
8
  const rules = baseRules;
9
+ // Derive normalization rules from other plugin's configurations
9
10
  for (const p of editor.plugins){
10
- const { normalizer: _rules } = p;
11
+ const { normalizer: _rules } = p;
11
12
  if (!_rules) {
12
13
  continue;
13
14
  }
14
15
  for (const _rule of _rules){
16
+ // Clone to avoid mutation bugs
15
17
  const rule = {
16
18
  ..._rule
17
19
  };
18
20
  if (!rule.match && !p.isElement) {
19
21
  throw new NormalizerError('rule.match MUST be defined in a non-element plugin');
20
22
  }
23
+ // By default we filter elements with given plugin type
21
24
  if (!rule.match) {
22
25
  rule.match = {
23
26
  type: getPluginType(editor, p.key)
24
27
  };
25
28
  }
29
+ // Conditional transformation e.g.
30
+ // {
31
+ // [BLOCKS.EMBEDDED_ASSET]: transformLift,
32
+ // default?: transformRemove
33
+ // }
34
+ //
26
35
  if (isPlainObject(rule.transform)) {
27
36
  if ('validNode' in rule) {
37
+ // I can't think of a use case. Disabled to prevent misuse
28
38
  throw new NormalizerError('conditional transformations are not supported in validNode rules');
29
39
  }
30
40
  rule.transform = createTransformerFromObject({
@@ -32,33 +42,43 @@ export const withNormalizer = (editor)=>{
32
42
  ...rule.transform
33
43
  });
34
44
  }
45
+ // By default all invalid nodes are removed.
35
46
  if (!rule.transform) {
36
47
  rule.transform = transformRemove;
37
48
  }
49
+ // Convert Types array syntax to a validator function
38
50
  if ('validChildren' in rule && Array.isArray(rule.validChildren)) {
39
51
  rule.validChildren = createValidatorFromTypes(rule.validChildren);
40
52
  }
41
53
  rules.push(rule);
42
54
  }
43
55
  }
56
+ // Wrap transformer in a withoutNormalizing() call to avoid unnecessary
57
+ // normalization cycles.
44
58
  const _transform = (tr, entry)=>{
45
59
  withoutNormalizing(editor, ()=>{
46
60
  tr(editor, entry);
47
61
  });
48
62
  };
49
- const { normalizeNode } = editor;
63
+ const { normalizeNode } = editor;
64
+ // @ts-expect-error
50
65
  editor.normalizeNode = (entry)=>{
51
66
  const [node, path] = entry;
52
67
  const children = getChildren(entry);
68
+ // The order of validNode rules Vs validChildren doesn't matter. Slate
69
+ // will always perform normalization in a depth-first fashion.
53
70
  for (const rule of rules){
54
71
  if (!matchNode(node, path, rule.match)) {
55
72
  continue;
56
73
  }
74
+ // Normalize node
57
75
  if ('validNode' in rule && !rule.validNode(editor, entry)) {
58
76
  _transform(rule.transform, entry);
59
77
  return;
60
78
  }
79
+ // Normalize node.children
61
80
  if ('validChildren' in rule) {
81
+ // It can not be an array since we enforced it earlier
62
82
  const isValidChild = rule.validChildren;
63
83
  const invalidChildEntry = children.find((entry)=>!isValidChild(editor, entry));
64
84
  if (invalidChildEntry) {
@@ -9,7 +9,7 @@ const styles = {
9
9
  `
10
10
  };
11
11
  export function Paragraph(props) {
12
- return React.createElement("div", {
12
+ return /*#__PURE__*/ React.createElement("div", {
13
13
  ...props.attributes,
14
14
  className: styles[BLOCKS.PARAGRAPH]
15
15
  }, props.children);