@contentful/field-editor-rich-text 3.4.21 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ContentfulEditorProvider.js +59 -0
- package/dist/cjs/RichTextEditor.js +170 -0
- package/dist/cjs/RichTextEditor.styles.js +66 -0
- package/dist/cjs/SdkProvider.js +69 -0
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +152 -0
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +87 -0
- package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +69 -0
- package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +29 -0
- package/dist/cjs/Toolbar/index.js +222 -0
- package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/constants/Schema.js +172 -0
- package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +348 -0
- package/dist/cjs/dialogs/openRichTextDialog.js +64 -0
- package/dist/cjs/dialogs/renderRichTextDialog.js +63 -0
- package/dist/cjs/helpers/__tests__/extractNodes.test.js +299 -0
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +52 -0
- package/dist/cjs/helpers/__tests__/validations.test.js +49 -0
- package/dist/cjs/helpers/editor.js +276 -0
- package/dist/cjs/helpers/environment.js +20 -0
- package/dist/cjs/helpers/extractNodes.js +27 -0
- package/dist/cjs/helpers/formatDateAndTime.js +45 -0
- package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +24 -0
- package/dist/cjs/helpers/newEntitySelectorConfigFromRichTextField.js +33 -0
- package/dist/cjs/helpers/nodeFactory.js +51 -0
- package/dist/cjs/helpers/removeInternalMarks.js +26 -0
- package/dist/cjs/helpers/sanitizeIncomingSlateDoc.js +33 -0
- package/dist/cjs/helpers/sdkNavigatorSlideIn.js +57 -0
- package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +209 -0
- package/dist/cjs/helpers/transformers.js +61 -0
- package/dist/cjs/helpers/validations.js +56 -0
- package/dist/cjs/index.js +66 -0
- package/dist/cjs/internal/constants.js +51 -0
- package/dist/cjs/internal/hooks.js +65 -0
- package/dist/cjs/internal/index.js +21 -0
- package/dist/cjs/internal/misc.js +103 -0
- package/dist/cjs/internal/queries.js +407 -0
- package/dist/cjs/internal/transforms.js +195 -0
- package/dist/cjs/internal/types/editor.js +4 -0
- package/dist/cjs/internal/types/index.js +19 -0
- package/dist/cjs/internal/types/plugins.js +4 -0
- package/dist/cjs/plugins/Break/createExitBreakPlugin.js +26 -0
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +36 -0
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +32 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.js +23 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +47 -0
- package/dist/cjs/plugins/Break/index.js +20 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandList.js +167 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +103 -0
- package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +69 -0
- package/dist/cjs/plugins/CommandPalette/constants.js +11 -0
- package/dist/cjs/plugins/CommandPalette/createCommandPalettePlugin.js +24 -0
- package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +138 -0
- package/dist/cjs/plugins/CommandPalette/index.js +11 -0
- package/dist/cjs/plugins/CommandPalette/onKeyDown.js +51 -0
- package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +83 -0
- package/dist/cjs/plugins/CommandPalette/useCommands.js +222 -0
- package/dist/cjs/plugins/CommandPalette/utils/createInlineEntryNode.js +30 -0
- package/dist/cjs/plugins/CommandPalette/utils/fetchAssets.js +31 -0
- package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +39 -0
- package/dist/cjs/plugins/CommandPalette/utils/insertBlock.js +42 -0
- package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +16 -0
- package/dist/cjs/plugins/DragAndDrop/index.js +54 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +128 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/ToolbarIcon.js +106 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +108 -0
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +100 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +158 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/Util.js +30 -0
- package/dist/cjs/plugins/EmbeddedEntityInline/index.js +221 -0
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +117 -0
- package/dist/cjs/plugins/Heading/components/Heading.js +127 -0
- package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +173 -0
- package/dist/cjs/plugins/Heading/createHeadingPlugin.js +102 -0
- package/dist/cjs/plugins/Heading/index.js +19 -0
- package/dist/cjs/plugins/Hr/index.js +193 -0
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +282 -0
- package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +25 -0
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +93 -0
- package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +78 -0
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +86 -0
- package/dist/cjs/plugins/Hyperlink/components/styles.js +36 -0
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +179 -0
- package/dist/cjs/plugins/Hyperlink/index.js +20 -0
- package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +95 -0
- package/dist/cjs/plugins/Hyperlink/utils.js +43 -0
- package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +47 -0
- package/dist/cjs/plugins/List/__tests__/insertListBreak.test.js +77 -0
- package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +64 -0
- package/dist/cjs/plugins/List/components/List.js +108 -0
- package/dist/cjs/plugins/List/components/ListItem.js +73 -0
- package/dist/cjs/plugins/List/components/ToolbarListButton.js +86 -0
- package/dist/cjs/plugins/List/createListPlugin.js +76 -0
- package/dist/cjs/plugins/List/index.js +19 -0
- package/dist/cjs/plugins/List/insertListBreak.js +60 -0
- package/dist/cjs/plugins/List/insertListFragment.js +98 -0
- package/dist/cjs/plugins/List/onKeyDownList.js +46 -0
- package/dist/cjs/plugins/List/transforms/insertListItem.js +92 -0
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +47 -0
- package/dist/cjs/plugins/List/transforms/moveListItems.js +56 -0
- package/dist/cjs/plugins/List/transforms/moveListItems.test.js +72 -0
- package/dist/cjs/plugins/List/transforms/toggleList.js +141 -0
- package/dist/cjs/plugins/List/transforms/toggleList.spec.js +139 -0
- package/dist/cjs/plugins/List/transforms/unwrapList.js +38 -0
- package/dist/cjs/plugins/List/utils.js +122 -0
- package/dist/cjs/plugins/List/withList.js +32 -0
- package/dist/cjs/plugins/Marks/Bold.js +119 -0
- package/dist/cjs/plugins/Marks/Code.js +122 -0
- package/dist/cjs/plugins/Marks/Italic.js +114 -0
- package/dist/cjs/plugins/Marks/Subscript.js +109 -0
- package/dist/cjs/plugins/Marks/Superscript.js +107 -0
- package/dist/cjs/plugins/Marks/Underline.js +106 -0
- package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +105 -0
- package/dist/cjs/plugins/Marks/helpers.js +48 -0
- package/dist/cjs/plugins/Marks/index.js +27 -0
- package/dist/cjs/plugins/Normalizer/baseRules.js +38 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.js +15 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +117 -0
- package/dist/cjs/plugins/Normalizer/index.js +19 -0
- package/dist/cjs/plugins/Normalizer/types.js +4 -0
- package/dist/cjs/plugins/Normalizer/utils.js +39 -0
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +88 -0
- package/dist/cjs/plugins/Paragraph/Paragraph.js +70 -0
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +125 -0
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +73 -0
- package/dist/cjs/plugins/Paragraph/index.js +18 -0
- package/dist/cjs/plugins/Paragraph/utils.js +24 -0
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +63 -0
- package/dist/cjs/plugins/PasteHTML/index.js +18 -0
- package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +54 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +43 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +50 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +44 -0
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +78 -0
- package/dist/cjs/plugins/Quote/components/Quote.js +69 -0
- package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +72 -0
- package/dist/cjs/plugins/Quote/createQuotePlugin.js +57 -0
- package/dist/cjs/plugins/Quote/index.js +19 -0
- package/dist/cjs/plugins/Quote/shouldResetQuote.js +40 -0
- package/dist/cjs/plugins/Quote/toggleQuote.js +56 -0
- package/dist/cjs/plugins/Quote/withQuote.js +48 -0
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +21 -0
- package/dist/cjs/plugins/SelectOnBackspace/index.js +18 -0
- package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +92 -0
- package/dist/cjs/plugins/Table/__tests__/helpers.test.js +18 -0
- package/dist/cjs/plugins/Table/actions/addColumn.js +63 -0
- package/dist/cjs/plugins/Table/actions/addRow.js +57 -0
- package/dist/cjs/plugins/Table/actions/index.js +20 -0
- package/dist/cjs/plugins/Table/actions/setHeader.js +34 -0
- package/dist/cjs/plugins/Table/components/Cell.js +79 -0
- package/dist/cjs/plugins/Table/components/HeaderCell.js +82 -0
- package/dist/cjs/plugins/Table/components/Row.js +69 -0
- package/dist/cjs/plugins/Table/components/Table.js +76 -0
- package/dist/cjs/plugins/Table/components/TableActions.js +175 -0
- package/dist/cjs/plugins/Table/components/ToolbarButton.js +73 -0
- package/dist/cjs/plugins/Table/createTablePlugin.js +119 -0
- package/dist/cjs/plugins/Table/helpers.js +152 -0
- package/dist/cjs/plugins/Table/index.js +19 -0
- package/dist/cjs/plugins/Table/insertTableFragment.js +50 -0
- package/dist/cjs/plugins/Table/onKeyDownTable.js +62 -0
- package/dist/cjs/plugins/Table/tableTracking.js +64 -0
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +79 -0
- package/dist/cjs/plugins/Text/createTextPlugin.js +136 -0
- package/dist/cjs/plugins/Text/index.js +18 -0
- package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +101 -0
- package/dist/cjs/plugins/Tracking/index.js +18 -0
- package/dist/cjs/plugins/Tracking/utils.js +64 -0
- package/dist/cjs/plugins/TrailingParagraph/index.js +20 -0
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +31 -0
- package/dist/cjs/plugins/Voids/index.js +18 -0
- package/dist/cjs/plugins/Voids/transformVoid.js +29 -0
- package/dist/cjs/plugins/index.js +76 -0
- package/dist/cjs/plugins/links-tracking.js +29 -0
- package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +113 -0
- package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +116 -0
- package/dist/cjs/plugins/shared/ToolbarButton.js +93 -0
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +107 -0
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +110 -0
- package/dist/cjs/prepareDocument.js +86 -0
- package/dist/cjs/test-utils/assertOutput.js +31 -0
- package/dist/cjs/test-utils/createEditor.js +31 -0
- package/dist/cjs/test-utils/hyperscript.d.js +1 -0
- package/dist/cjs/test-utils/index.js +21 -0
- package/dist/cjs/test-utils/jsx.js +159 -0
- package/dist/cjs/test-utils/mockPlugin.js +16 -0
- package/dist/cjs/test-utils/randomId.js +13 -0
- package/dist/cjs/test-utils/setEmptyDataAttribute.js +21 -0
- package/dist/cjs/test-utils/validation.js +127 -0
- package/dist/cjs/useOnValueChanged.js +58 -0
- package/dist/esm/ContentfulEditorProvider.js +29 -0
- package/dist/esm/RichTextEditor.js +108 -0
- package/dist/esm/RichTextEditor.styles.js +51 -0
- package/dist/esm/SdkProvider.js +7 -0
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +104 -0
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +38 -0
- package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +20 -0
- package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +14 -0
- package/dist/esm/Toolbar/index.js +168 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/constants/Schema.js +162 -0
- package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +283 -0
- package/dist/esm/dialogs/openRichTextDialog.js +15 -0
- package/dist/esm/dialogs/renderRichTextDialog.js +14 -0
- package/dist/esm/helpers/__tests__/extractNodes.test.js +295 -0
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +48 -0
- package/dist/esm/helpers/__tests__/validations.test.js +45 -0
- package/dist/esm/helpers/editor.js +198 -0
- package/dist/esm/helpers/environment.js +2 -0
- package/dist/esm/helpers/extractNodes.js +17 -0
- package/dist/esm/helpers/formatDateAndTime.js +19 -0
- package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +9 -0
- package/dist/esm/helpers/newEntitySelectorConfigFromRichTextField.js +18 -0
- package/dist/esm/helpers/nodeFactory.js +24 -0
- package/dist/esm/helpers/removeInternalMarks.js +16 -0
- package/dist/esm/helpers/sanitizeIncomingSlateDoc.js +23 -0
- package/dist/esm/helpers/sdkNavigatorSlideIn.js +42 -0
- package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +200 -0
- package/dist/esm/helpers/transformers.js +34 -0
- package/dist/esm/helpers/validations.js +24 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/internal/constants.js +2 -0
- package/dist/esm/internal/hooks.js +5 -0
- package/dist/esm/internal/index.js +4 -0
- package/dist/esm/internal/misc.js +28 -0
- package/dist/esm/internal/queries.js +182 -0
- package/dist/esm/internal/transforms.js +75 -0
- package/dist/esm/internal/types/editor.js +1 -0
- package/dist/esm/internal/types/index.js +2 -0
- package/dist/esm/internal/types/plugins.js +1 -0
- package/dist/esm/plugins/Break/createExitBreakPlugin.js +16 -0
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +32 -0
- package/dist/esm/plugins/Break/createResetNodePlugin.js +22 -0
- package/dist/esm/plugins/Break/createSoftBreakPlugin.js +13 -0
- package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +43 -0
- package/dist/esm/plugins/Break/index.js +3 -0
- package/dist/esm/plugins/CommandPalette/components/CommandList.js +113 -0
- package/dist/esm/plugins/CommandPalette/components/CommandList.styles.js +88 -0
- package/dist/esm/plugins/CommandPalette/components/CommandPrompt.js +20 -0
- package/dist/esm/plugins/CommandPalette/constants.js +1 -0
- package/dist/esm/plugins/CommandPalette/createCommandPalettePlugin.js +14 -0
- package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +84 -0
- package/dist/esm/plugins/CommandPalette/index.js +1 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.js +36 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.spec.js +40 -0
- package/dist/esm/plugins/CommandPalette/useCommands.js +204 -0
- package/dist/esm/plugins/CommandPalette/utils/createInlineEntryNode.js +20 -0
- package/dist/esm/plugins/CommandPalette/utils/fetchAssets.js +21 -0
- package/dist/esm/plugins/CommandPalette/utils/fetchEntries.js +29 -0
- package/dist/esm/plugins/CommandPalette/utils/insertBlock.js +32 -0
- package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -0
- package/dist/esm/plugins/DragAndDrop/index.js +44 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +79 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/ToolbarIcon.js +49 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +85 -0
- package/dist/esm/plugins/EmbeddedEntityBlock/index.js +74 -0
- package/dist/esm/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +104 -0
- package/dist/esm/plugins/EmbeddedEntityInline/Util.js +20 -0
- package/dist/esm/plugins/EmbeddedEntityInline/index.js +159 -0
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +113 -0
- package/dist/esm/plugins/Heading/components/Heading.js +73 -0
- package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +119 -0
- package/dist/esm/plugins/Heading/createHeadingPlugin.js +87 -0
- package/dist/esm/plugins/Heading/index.js +2 -0
- package/dist/esm/plugins/Hr/index.js +125 -0
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +220 -0
- package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +21 -0
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +44 -0
- package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +29 -0
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +37 -0
- package/dist/esm/plugins/Hyperlink/components/styles.js +21 -0
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +125 -0
- package/dist/esm/plugins/Hyperlink/index.js +2 -0
- package/dist/esm/plugins/Hyperlink/useEntityInfo.js +85 -0
- package/dist/esm/plugins/Hyperlink/utils.js +25 -0
- package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +43 -0
- package/dist/esm/plugins/List/__tests__/insertListBreak.test.js +73 -0
- package/dist/esm/plugins/List/__tests__/insertListFragment.test.js +60 -0
- package/dist/esm/plugins/List/components/List.js +46 -0
- package/dist/esm/plugins/List/components/ListItem.js +19 -0
- package/dist/esm/plugins/List/components/ToolbarListButton.js +37 -0
- package/dist/esm/plugins/List/createListPlugin.js +66 -0
- package/dist/esm/plugins/List/index.js +2 -0
- package/dist/esm/plugins/List/insertListBreak.js +50 -0
- package/dist/esm/plugins/List/insertListFragment.js +88 -0
- package/dist/esm/plugins/List/onKeyDownList.js +31 -0
- package/dist/esm/plugins/List/transforms/insertListItem.js +82 -0
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +37 -0
- package/dist/esm/plugins/List/transforms/moveListItems.js +46 -0
- package/dist/esm/plugins/List/transforms/moveListItems.test.js +68 -0
- package/dist/esm/plugins/List/transforms/toggleList.js +132 -0
- package/dist/esm/plugins/List/transforms/toggleList.spec.js +135 -0
- package/dist/esm/plugins/List/transforms/unwrapList.js +28 -0
- package/dist/esm/plugins/List/utils.js +89 -0
- package/dist/esm/plugins/List/withList.js +22 -0
- package/dist/esm/plugins/Marks/Bold.js +59 -0
- package/dist/esm/plugins/Marks/Code.js +59 -0
- package/dist/esm/plugins/Marks/Italic.js +54 -0
- package/dist/esm/plugins/Marks/Subscript.js +46 -0
- package/dist/esm/plugins/Marks/Superscript.js +44 -0
- package/dist/esm/plugins/Marks/Underline.js +46 -0
- package/dist/esm/plugins/Marks/components/MarkToolbarButton.js +51 -0
- package/dist/esm/plugins/Marks/helpers.js +25 -0
- package/dist/esm/plugins/Marks/index.js +17 -0
- package/dist/esm/plugins/Normalizer/baseRules.js +28 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.js +5 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +113 -0
- package/dist/esm/plugins/Normalizer/index.js +2 -0
- package/dist/esm/plugins/Normalizer/types.js +1 -0
- package/dist/esm/plugins/Normalizer/utils.js +18 -0
- package/dist/esm/plugins/Normalizer/withNormalizer.js +73 -0
- package/dist/esm/plugins/Paragraph/Paragraph.js +16 -0
- package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +121 -0
- package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +58 -0
- package/dist/esm/plugins/Paragraph/index.js +1 -0
- package/dist/esm/plugins/Paragraph/utils.js +6 -0
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +42 -0
- package/dist/esm/plugins/PasteHTML/index.js +1 -0
- package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +50 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +33 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +40 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +34 -0
- package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +74 -0
- package/dist/esm/plugins/Quote/components/Quote.js +15 -0
- package/dist/esm/plugins/Quote/components/ToolbarQuoteButton.js +23 -0
- package/dist/esm/plugins/Quote/createQuotePlugin.js +47 -0
- package/dist/esm/plugins/Quote/index.js +2 -0
- package/dist/esm/plugins/Quote/shouldResetQuote.js +30 -0
- package/dist/esm/plugins/Quote/toggleQuote.js +33 -0
- package/dist/esm/plugins/Quote/withQuote.js +38 -0
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +11 -0
- package/dist/esm/plugins/SelectOnBackspace/index.js +1 -0
- package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +88 -0
- package/dist/esm/plugins/Table/__tests__/helpers.test.js +14 -0
- package/dist/esm/plugins/Table/actions/addColumn.js +45 -0
- package/dist/esm/plugins/Table/actions/addRow.js +39 -0
- package/dist/esm/plugins/Table/actions/index.js +3 -0
- package/dist/esm/plugins/Table/actions/setHeader.js +24 -0
- package/dist/esm/plugins/Table/components/Cell.js +25 -0
- package/dist/esm/plugins/Table/components/HeaderCell.js +28 -0
- package/dist/esm/plugins/Table/components/Row.js +15 -0
- package/dist/esm/plugins/Table/components/Table.js +22 -0
- package/dist/esm/plugins/Table/components/TableActions.js +118 -0
- package/dist/esm/plugins/Table/components/ToolbarButton.js +24 -0
- package/dist/esm/plugins/Table/createTablePlugin.js +109 -0
- package/dist/esm/plugins/Table/helpers.js +116 -0
- package/dist/esm/plugins/Table/index.js +2 -0
- package/dist/esm/plugins/Table/insertTableFragment.js +40 -0
- package/dist/esm/plugins/Table/onKeyDownTable.js +52 -0
- package/dist/esm/plugins/Table/tableTracking.js +46 -0
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +75 -0
- package/dist/esm/plugins/Text/createTextPlugin.js +126 -0
- package/dist/esm/plugins/Text/index.js +1 -0
- package/dist/esm/plugins/Tracking/createTrackingPlugin.js +83 -0
- package/dist/esm/plugins/Tracking/index.js +1 -0
- package/dist/esm/plugins/Tracking/utils.js +10 -0
- package/dist/esm/plugins/TrailingParagraph/index.js +10 -0
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +21 -0
- package/dist/esm/plugins/Voids/index.js +1 -0
- package/dist/esm/plugins/Voids/transformVoid.js +19 -0
- package/dist/esm/plugins/index.js +58 -0
- package/dist/esm/plugins/links-tracking.js +14 -0
- package/dist/esm/plugins/shared/FetchingWrappedAssetCard.js +59 -0
- package/dist/esm/plugins/shared/FetchingWrappedEntryCard.js +62 -0
- package/dist/esm/plugins/shared/ToolbarButton.js +39 -0
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +59 -0
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +62 -0
- package/dist/esm/prepareDocument.js +57 -0
- package/dist/esm/test-utils/assertOutput.js +21 -0
- package/dist/esm/test-utils/createEditor.js +21 -0
- package/dist/esm/test-utils/hyperscript.d.js +0 -0
- package/dist/esm/test-utils/index.js +4 -0
- package/dist/esm/test-utils/jsx.js +149 -0
- package/dist/esm/test-utils/mockPlugin.js +6 -0
- package/dist/esm/test-utils/randomId.js +3 -0
- package/dist/esm/test-utils/setEmptyDataAttribute.js +11 -0
- package/dist/esm/test-utils/validation.js +112 -0
- package/dist/esm/useOnValueChanged.js +43 -0
- package/dist/{ContentfulEditorProvider.d.ts → types/ContentfulEditorProvider.d.ts} +9 -9
- package/dist/{RichTextEditor.d.ts → types/RichTextEditor.d.ts} +21 -20
- package/dist/{RichTextEditor.styles.d.ts → types/RichTextEditor.styles.d.ts} +7 -7
- package/dist/{SdkProvider.d.ts → types/SdkProvider.d.ts} +7 -7
- package/dist/types/Toolbar/_tests_/toolbar.test.d.ts +1 -0
- package/dist/{Toolbar → types/Toolbar}/components/EmbedEntityWidget.d.ts +6 -5
- package/dist/{Toolbar → types/Toolbar}/components/EmbeddedEntityDropdownButton.d.ts +9 -9
- package/dist/{Toolbar → types/Toolbar}/components/StickyToolbarWrapper.d.ts +7 -7
- package/dist/types/Toolbar/index.d.ts +6 -0
- package/dist/types/__fixtures__/FakeSdk.d.ts +8 -0
- package/dist/types/__fixtures__/asset/index.d.ts +6 -0
- package/dist/types/__fixtures__/content-type/index.d.ts +2 -0
- package/dist/types/__fixtures__/entry/index.d.ts +5 -0
- package/dist/types/__fixtures__/fixtures.d.ts +6 -0
- package/dist/types/__fixtures__/locale/index.d.ts +42 -0
- package/dist/types/__fixtures__/space/index.d.ts +2 -0
- package/dist/{constants → types/constants}/Schema.d.ts +111 -111
- package/dist/{dialogs → types/dialogs}/HypelinkDialog/HyperlinkDialog.d.ts +63 -54
- package/dist/{dialogs → types/dialogs}/openRichTextDialog.d.ts +2 -2
- package/dist/{dialogs → types/dialogs}/renderRichTextDialog.d.ts +3 -2
- package/dist/types/helpers/__tests__/extractNodes.test.d.ts +1 -0
- package/dist/types/helpers/__tests__/removeInternalMarks.test.d.ts +2 -0
- package/dist/types/helpers/__tests__/validations.test.d.ts +1 -0
- package/dist/{helpers → types/helpers}/editor.d.ts +40 -40
- package/dist/{helpers → types/helpers}/environment.d.ts +2 -2
- package/dist/{helpers → types/helpers}/extractNodes.d.ts +5 -5
- package/dist/{helpers → types/helpers}/formatDateAndTime.d.ts +15 -15
- package/dist/{helpers → types/helpers}/getLinkedContentTypeIdsForNodeType.d.ts +26 -26
- package/dist/{helpers → types/helpers}/newEntitySelectorConfigFromRichTextField.d.ts +14 -14
- package/dist/{helpers → types/helpers}/nodeFactory.d.ts +24 -24
- package/dist/{helpers → types/helpers}/removeInternalMarks.d.ts +1 -1
- package/dist/{helpers → types/helpers}/sanitizeIncomingSlateDoc.d.ts +6 -6
- package/dist/{helpers → types/helpers}/sdkNavigatorSlideIn.d.ts +16 -16
- package/dist/types/helpers/sdkNavigatorSlideIn.spec.d.ts +1 -0
- package/dist/{helpers → types/helpers}/transformers.d.ts +7 -7
- package/dist/{helpers → types/helpers}/validations.d.ts +10 -10
- package/dist/{index.d.ts → types/index.d.ts} +4 -4
- package/dist/{internal → types/internal}/constants.d.ts +1 -1
- package/dist/{internal → types/internal}/hooks.d.ts +4 -4
- package/dist/{internal → types/internal}/index.d.ts +4 -4
- package/dist/{internal → types/internal}/misc.d.ts +37 -37
- package/dist/{internal → types/internal}/queries.d.ts +78 -78
- package/dist/{internal → types/internal}/transforms.d.ts +33 -33
- package/dist/types/internal/types/editor.d.ts +51 -0
- package/dist/{internal → types/internal}/types/index.d.ts +2 -2
- package/dist/{internal → types/internal}/types/plugins.d.ts +12 -12
- package/dist/{plugins → types/plugins}/Break/createExitBreakPlugin.d.ts +2 -2
- package/dist/types/plugins/Break/createExitBreakPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Break/createResetNodePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Break/createSoftBreakPlugin.d.ts +2 -2
- package/dist/types/plugins/Break/createSoftBreakPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Break/index.d.ts +5 -5
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandList.d.ts +8 -7
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandList.styles.d.ts +14 -14
- package/dist/{plugins → types/plugins}/CommandPalette/components/CommandPrompt.d.ts +5 -4
- package/dist/{plugins → types/plugins}/CommandPalette/constants.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/createCommandPalettePlugin.d.ts +13 -13
- package/dist/{plugins → types/plugins}/CommandPalette/hooks/useCommandList.d.ts +4 -4
- package/dist/{plugins → types/plugins}/CommandPalette/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/onKeyDown.d.ts +2 -2
- package/dist/types/plugins/CommandPalette/onKeyDown.spec.d.ts +1 -0
- package/dist/{plugins → types/plugins}/CommandPalette/useCommands.d.ts +19 -19
- package/dist/{plugins → types/plugins}/CommandPalette/utils/createInlineEntryNode.d.ts +16 -16
- package/dist/{plugins → types/plugins}/CommandPalette/utils/fetchAssets.d.ts +8 -8
- package/dist/{plugins → types/plugins}/CommandPalette/utils/fetchEntries.d.ts +9 -9
- package/dist/{plugins → types/plugins}/CommandPalette/utils/insertBlock.d.ts +1 -1
- package/dist/{plugins → types/plugins}/CommandPalette/utils/trimLeadingSlash.d.ts +7 -7
- package/dist/{plugins → types/plugins}/DragAndDrop/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +20 -19
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/ToolbarIcon.d.ts +11 -10
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/Util.d.ts +4 -4
- package/dist/{plugins → types/plugins}/EmbeddedEntityBlock/index.d.ts +5 -5
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.d.ts +13 -13
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/Util.d.ts +16 -16
- package/dist/{plugins → types/plugins}/EmbeddedEntityInline/index.d.ts +10 -9
- package/dist/types/plugins/Heading/__tests__/createHeadingPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Heading/components/Heading.d.ts +10 -10
- package/dist/{plugins → types/plugins}/Heading/components/ToolbarHeadingButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Heading/createHeadingPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Heading/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Hr/index.d.ts +11 -11
- package/dist/{plugins → types/plugins}/Hyperlink/HyperlinkModal.d.ts +17 -16
- package/dist/types/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Hyperlink/components/EntityHyperlink.d.ts +21 -20
- package/dist/{plugins → types/plugins}/Hyperlink/components/ToolbarHyperlinkButton.d.ts +6 -5
- package/dist/{plugins → types/plugins}/Hyperlink/components/UrlHyperlink.d.ts +22 -21
- package/dist/{plugins → types/plugins}/Hyperlink/components/styles.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Hyperlink/createHyperlinkPlugin.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Hyperlink/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Hyperlink/useEntityInfo.d.ts +16 -16
- package/dist/{plugins → types/plugins}/Hyperlink/utils.d.ts +5 -5
- package/dist/types/plugins/List/__tests__/createListPlugin.test.d.ts +1 -0
- package/dist/types/plugins/List/__tests__/insertListBreak.test.d.ts +1 -0
- package/dist/types/plugins/List/__tests__/insertListFragment.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/components/List.d.ts +4 -3
- package/dist/{plugins → types/plugins}/List/components/ListItem.d.ts +3 -2
- package/dist/{plugins → types/plugins}/List/components/ToolbarListButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/List/createListPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/insertListBreak.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/insertListFragment.d.ts +2 -2
- package/dist/{plugins → types/plugins}/List/onKeyDownList.d.ts +7 -7
- package/dist/{plugins → types/plugins}/List/transforms/insertListItem.d.ts +5 -5
- package/dist/{plugins → types/plugins}/List/transforms/moveListItemDown.d.ts +6 -6
- package/dist/{plugins → types/plugins}/List/transforms/moveListItems.d.ts +6 -6
- package/dist/types/plugins/List/transforms/moveListItems.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/transforms/toggleList.d.ts +4 -4
- package/dist/types/plugins/List/transforms/toggleList.spec.d.ts +1 -0
- package/dist/{plugins → types/plugins}/List/transforms/unwrapList.d.ts +4 -4
- package/dist/{plugins → types/plugins}/List/utils.d.ts +14 -14
- package/dist/{plugins → types/plugins}/List/withList.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Marks/Bold.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/Code.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Italic.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/Subscript.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Superscript.d.ts +17 -16
- package/dist/{plugins → types/plugins}/Marks/Underline.d.ts +11 -10
- package/dist/{plugins → types/plugins}/Marks/components/MarkToolbarButton.d.ts +13 -13
- package/dist/{plugins → types/plugins}/Marks/helpers.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Marks/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/baseRules.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/createNormalizerPlugin.d.ts +2 -2
- package/dist/types/plugins/Normalizer/createNormalizerPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Normalizer/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Normalizer/types.d.ts +38 -38
- package/dist/{plugins → types/plugins}/Normalizer/utils.d.ts +5 -5
- package/dist/{plugins → types/plugins}/Normalizer/withNormalizer.d.ts +2 -2
- package/dist/types/plugins/Paragraph/Paragraph.d.ts +3 -0
- package/dist/types/plugins/Paragraph/__tests__/createParagraphPlugin.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Paragraph/createParagraphPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Paragraph/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Paragraph/utils.d.ts +2 -2
- package/dist/{plugins → types/plugins}/PasteHTML/createPasteHTMLPlugin.d.ts +8 -8
- package/dist/{plugins → types/plugins}/PasteHTML/index.d.ts +1 -1
- package/dist/types/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeAnchors.d.ts +19 -19
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeHTML.d.ts +1 -1
- package/dist/{plugins → types/plugins}/PasteHTML/utils/sanitizeSheets.d.ts +4 -4
- package/dist/types/plugins/Quote/__test__/createQuotePlugin.test.d.ts +1 -0
- package/dist/types/plugins/Quote/components/Quote.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Quote/components/ToolbarQuoteButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Quote/createQuotePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Quote/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Quote/shouldResetQuote.d.ts +8 -8
- package/dist/{plugins → types/plugins}/Quote/toggleQuote.d.ts +4 -4
- package/dist/{plugins → types/plugins}/Quote/withQuote.d.ts +2 -2
- package/dist/{plugins → types/plugins}/SelectOnBackspace/createSelectOnBackspacePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/SelectOnBackspace/index.d.ts +1 -1
- package/dist/types/plugins/Table/__tests__/createTablePlugin.test.d.ts +1 -0
- package/dist/types/plugins/Table/__tests__/helpers.test.d.ts +1 -0
- package/dist/{plugins → types/plugins}/Table/actions/addColumn.d.ts +7 -7
- package/dist/{plugins → types/plugins}/Table/actions/addRow.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/actions/index.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/actions/setHeader.d.ts +2 -2
- package/dist/types/plugins/Table/components/Cell.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Table/components/HeaderCell.d.ts +3 -2
- package/dist/types/plugins/Table/components/Row.d.ts +3 -0
- package/dist/{plugins → types/plugins}/Table/components/Table.d.ts +3 -2
- package/dist/types/plugins/Table/components/TableActions.d.ts +5 -0
- package/dist/{plugins → types/plugins}/Table/components/ToolbarButton.d.ts +5 -4
- package/dist/{plugins → types/plugins}/Table/createTablePlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/helpers.d.ts +15 -15
- package/dist/{plugins → types/plugins}/Table/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/insertTableFragment.d.ts +3 -3
- package/dist/{plugins → types/plugins}/Table/onKeyDownTable.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Table/tableTracking.d.ts +4 -4
- package/dist/types/plugins/Text/__tests__/createTextPlugin.test.d.ts +2 -0
- package/dist/{plugins → types/plugins}/Text/createTextPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Text/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Tracking/createTrackingPlugin.d.ts +12 -12
- package/dist/{plugins → types/plugins}/Tracking/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Tracking/utils.d.ts +2 -2
- package/dist/{plugins → types/plugins}/TrailingParagraph/index.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Voids/createVoidsPlugin.d.ts +2 -2
- package/dist/{plugins → types/plugins}/Voids/index.d.ts +1 -1
- package/dist/{plugins → types/plugins}/Voids/transformVoid.d.ts +5 -5
- package/dist/{plugins → types/plugins}/index.d.ts +6 -6
- package/dist/{plugins → types/plugins}/links-tracking.d.ts +3 -3
- package/dist/{plugins → types/plugins}/shared/FetchingWrappedAssetCard.d.ts +14 -13
- package/dist/{plugins → types/plugins}/shared/FetchingWrappedEntryCard.d.ts +14 -13
- package/dist/{plugins → types/plugins}/shared/ToolbarButton.d.ts +12 -11
- package/dist/types/plugins/shared/__tests__/FetchingWrappedAssetCard.test.d.ts +1 -0
- package/dist/types/plugins/shared/__tests__/FetchingWrappedEntryCard.test.d.ts +1 -0
- package/dist/{prepareDocument.d.ts → types/prepareDocument.d.ts} +19 -19
- package/dist/{test-utils → types/test-utils}/assertOutput.d.ts +7 -7
- package/dist/{test-utils → types/test-utils}/createEditor.d.ts +31 -31
- package/dist/{test-utils → types/test-utils}/index.d.ts +4 -4
- package/dist/{test-utils → types/test-utils}/jsx.d.ts +28 -28
- package/dist/{test-utils → types/test-utils}/mockPlugin.d.ts +2 -2
- package/dist/{test-utils → types/test-utils}/randomId.d.ts +4 -4
- package/dist/{test-utils → types/test-utils}/setEmptyDataAttribute.d.ts +6 -6
- package/dist/{test-utils → types/test-utils}/validation.d.ts +1 -1
- package/dist/{useOnValueChanged.d.ts → types/useOnValueChanged.d.ts} +8 -8
- package/package.json +27 -21
- package/CHANGELOG.md +0 -946
- package/dist/Toolbar/index.d.ts +0 -5
- package/dist/field-editor-rich-text.cjs.development.js +0 -7210
- package/dist/field-editor-rich-text.cjs.development.js.map +0 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +0 -163
- package/dist/field-editor-rich-text.cjs.production.min.js.map +0 -1
- package/dist/field-editor-rich-text.esm.js +0 -7200
- package/dist/field-editor-rich-text.esm.js.map +0 -1
- package/dist/index.js +0 -8
- package/dist/internal/types/editor.d.ts +0 -51
- package/dist/plugins/List/transforms/deleteBackwardList.d.ts +0 -2
- package/dist/plugins/Paragraph/Paragraph.d.ts +0 -2
- package/dist/plugins/Quote/components/Quote.d.ts +0 -2
- package/dist/plugins/Table/components/Cell.d.ts +0 -2
- package/dist/plugins/Table/components/Row.d.ts +0 -2
- package/dist/plugins/Table/components/TableActions.d.ts +0 -4
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { assertOutput, jsx } from '../../../test-utils';
|
|
2
|
+
describe('normalization', ()=>{
|
|
3
|
+
it('can contain inline entries & hyperlinks', ()=>{
|
|
4
|
+
const input = jsx("editor", null, jsx("hp", null, "some text before", jsx("hinline", {
|
|
5
|
+
type: "Entry",
|
|
6
|
+
id: "inline-entry"
|
|
7
|
+
}), jsx("hlink", {
|
|
8
|
+
uri: "https://contentful.com"
|
|
9
|
+
}), jsx("hlink", {
|
|
10
|
+
entry: "entry-id"
|
|
11
|
+
}), jsx("hlink", {
|
|
12
|
+
asset: "asset-id"
|
|
13
|
+
}), "some text after"));
|
|
14
|
+
assertOutput({
|
|
15
|
+
input,
|
|
16
|
+
expected: input
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('wraps orphaned text nodes in a paragraph', ()=>{
|
|
20
|
+
const input = jsx("editor", null, jsx("hp", null, "valid text"), jsx("hh1", null, "valid text"), jsx("htable", null, jsx("htr", null, jsx("htd", null, "invalid text"))));
|
|
21
|
+
const expected = jsx("editor", null, jsx("hp", null, "valid text"), jsx("hh1", null, "valid text"), jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "invalid text")))), jsx("hp", null, jsx("htext", null)));
|
|
22
|
+
assertOutput({
|
|
23
|
+
input,
|
|
24
|
+
expected
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('unwraps nested paragraphs', ()=>{
|
|
28
|
+
const input = jsx("editor", null, jsx("hp", null, "some", jsx("hp", null, jsx("htext", {
|
|
29
|
+
bold: true,
|
|
30
|
+
italic: true,
|
|
31
|
+
underline: true
|
|
32
|
+
}, "paragraph")), "text"));
|
|
33
|
+
const expected = jsx("editor", null, jsx("hp", null, "some", jsx("htext", {
|
|
34
|
+
bold: true,
|
|
35
|
+
italic: true,
|
|
36
|
+
underline: true
|
|
37
|
+
}, "paragraph"), "text"));
|
|
38
|
+
assertOutput({
|
|
39
|
+
input,
|
|
40
|
+
expected
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('lifts other invalid children', ()=>{
|
|
44
|
+
it('block void elements', ()=>{
|
|
45
|
+
const input = jsx("editor", null, jsx("hp", null, jsx("hembed", {
|
|
46
|
+
type: "Asset",
|
|
47
|
+
id: "1"
|
|
48
|
+
}), " start"), jsx("hp", null, "end ", jsx("hembed", {
|
|
49
|
+
type: "Asset",
|
|
50
|
+
id: "2"
|
|
51
|
+
})), jsx("hp", null, "in ", jsx("hembed", {
|
|
52
|
+
type: "Asset",
|
|
53
|
+
id: "3"
|
|
54
|
+
}), " between"), jsx("hp", null, jsx("hembed", {
|
|
55
|
+
type: "Entry",
|
|
56
|
+
id: "1"
|
|
57
|
+
}), " start"), jsx("hp", null, "end ", jsx("hembed", {
|
|
58
|
+
type: "Entry",
|
|
59
|
+
id: "2"
|
|
60
|
+
})), jsx("hp", null, "in ", jsx("hembed", {
|
|
61
|
+
type: "Entry",
|
|
62
|
+
id: "3"
|
|
63
|
+
}), " between"), jsx("hp", null, jsx("hhr", null), " start"), jsx("hp", null, "end ", jsx("hhr", null)), jsx("hp", null, "in ", jsx("hhr", null), " between"));
|
|
64
|
+
const expected = jsx("editor", null, jsx("hembed", {
|
|
65
|
+
type: "Asset",
|
|
66
|
+
id: "1"
|
|
67
|
+
}), jsx("hp", null, " start"), jsx("hp", null, "end "), jsx("hembed", {
|
|
68
|
+
type: "Asset",
|
|
69
|
+
id: "2"
|
|
70
|
+
}), jsx("hp", null, "in "), jsx("hembed", {
|
|
71
|
+
type: "Asset",
|
|
72
|
+
id: "3"
|
|
73
|
+
}), jsx("hp", null, " between"), jsx("hembed", {
|
|
74
|
+
type: "Entry",
|
|
75
|
+
id: "1"
|
|
76
|
+
}), jsx("hp", null, " start"), jsx("hp", null, "end "), jsx("hembed", {
|
|
77
|
+
type: "Entry",
|
|
78
|
+
id: "2"
|
|
79
|
+
}), jsx("hp", null, "in "), jsx("hembed", {
|
|
80
|
+
type: "Entry",
|
|
81
|
+
id: "3"
|
|
82
|
+
}), jsx("hp", null, " between"), jsx("hhr", null), jsx("hp", null, " start"), jsx("hp", null, "end "), jsx("hhr", null), jsx("hp", null, "in "), jsx("hhr", null), jsx("hp", null, " between"));
|
|
83
|
+
assertOutput({
|
|
84
|
+
input,
|
|
85
|
+
expected
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it('handles heading', ()=>{
|
|
89
|
+
const input = jsx("editor", null, jsx("hp", null, "some", jsx("hh1", null, "heading"), "text"));
|
|
90
|
+
const expected = jsx("editor", null, jsx("hp", null, "some"), jsx("hh1", null, "heading"), jsx("hp", null, "text"));
|
|
91
|
+
assertOutput({
|
|
92
|
+
input,
|
|
93
|
+
expected
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('handles quotes', ()=>{
|
|
97
|
+
const input = jsx("editor", null, jsx("hp", null, "some", jsx("hquote", null, jsx("hp", null, "quote")), "text"));
|
|
98
|
+
const expected = jsx("editor", null, jsx("hp", null, "some"), jsx("hquote", null, jsx("hp", null, "quote")), jsx("hp", null, "text"));
|
|
99
|
+
assertOutput({
|
|
100
|
+
input,
|
|
101
|
+
expected
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it('handles lists', ()=>{
|
|
105
|
+
const input = jsx("editor", null, jsx("hp", null, "some", jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), "text"));
|
|
106
|
+
const expected = jsx("editor", null, jsx("hp", null, "some"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), jsx("hp", null, "text"));
|
|
107
|
+
assertOutput({
|
|
108
|
+
input,
|
|
109
|
+
expected
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it('handles tables', ()=>{
|
|
113
|
+
const input = jsx("editor", null, jsx("hp", null, "some", jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2")))), "text"));
|
|
114
|
+
const expected = jsx("editor", null, jsx("hp", null, "some"), jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2")))), jsx("hp", null, "text"));
|
|
115
|
+
assertOutput({
|
|
116
|
+
input,
|
|
117
|
+
expected
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import { createParagraphPlugin as createDefaultParagraphPlugin } from '@udecode/plate-paragraph';
|
|
3
|
+
import isHotkey from 'is-hotkey';
|
|
4
|
+
import { isInlineOrText, toggleElement } from '../../helpers/editor';
|
|
5
|
+
import { transformUnwrap, transformLift } from '../../helpers/transformers';
|
|
6
|
+
import { Paragraph } from './Paragraph';
|
|
7
|
+
import { isEmbedElement, isEmptyElement } from './utils';
|
|
8
|
+
const buildParagraphKeyDownHandler = (editor, { options: { hotkey } })=>(event)=>{
|
|
9
|
+
if (editor.selection && hotkey && isHotkey(hotkey, event)) {
|
|
10
|
+
toggleElement(editor, {
|
|
11
|
+
activeType: BLOCKS.PARAGRAPH,
|
|
12
|
+
inactiveType: BLOCKS.PARAGRAPH
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const createParagraphPlugin = ()=>{
|
|
17
|
+
const config = {
|
|
18
|
+
type: BLOCKS.PARAGRAPH,
|
|
19
|
+
component: Paragraph,
|
|
20
|
+
options: {
|
|
21
|
+
hotkey: [
|
|
22
|
+
'mod+opt+0'
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
handlers: {
|
|
26
|
+
onKeyDown: buildParagraphKeyDownHandler
|
|
27
|
+
},
|
|
28
|
+
softBreak: [
|
|
29
|
+
{
|
|
30
|
+
hotkey: 'shift+enter',
|
|
31
|
+
query: {
|
|
32
|
+
allow: BLOCKS.PARAGRAPH
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
deserializeHtml: {
|
|
37
|
+
rules: [
|
|
38
|
+
{
|
|
39
|
+
validNodeName: [
|
|
40
|
+
'P',
|
|
41
|
+
'DIV'
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
query: (el)=>!isEmptyElement(el) && !isEmbedElement(el)
|
|
46
|
+
},
|
|
47
|
+
normalizer: [
|
|
48
|
+
{
|
|
49
|
+
validChildren: (_, [node])=>isInlineOrText(node),
|
|
50
|
+
transform: {
|
|
51
|
+
[BLOCKS.PARAGRAPH]: transformUnwrap,
|
|
52
|
+
default: transformLift
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
return createDefaultParagraphPlugin(config);
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createParagraphPlugin';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { KEY_DESERIALIZE_HTML } from '@udecode/plate-core';
|
|
2
|
+
import { sanitizeHTML } from './utils/sanitizeHTML';
|
|
3
|
+
const catchSlateFragment = /data-slate-fragment="(.+?)"/m;
|
|
4
|
+
export const getSlateFragmentAttribute = (dataTransfer)=>{
|
|
5
|
+
const htmlData = dataTransfer.getData('text/html');
|
|
6
|
+
const [, fragment] = htmlData.match(catchSlateFragment) || [];
|
|
7
|
+
return fragment;
|
|
8
|
+
};
|
|
9
|
+
export const ensureXSlateFragment = (dataTransfer)=>{
|
|
10
|
+
if (!dataTransfer.getData('application/x-slate-fragment')) {
|
|
11
|
+
const fragment = getSlateFragmentAttribute(dataTransfer);
|
|
12
|
+
if (fragment) {
|
|
13
|
+
const clipboardData = new DataTransfer();
|
|
14
|
+
dataTransfer.types.forEach((type)=>{
|
|
15
|
+
clipboardData.setData(type, dataTransfer.getData(type));
|
|
16
|
+
});
|
|
17
|
+
clipboardData.setData('application/x-slate-fragment', fragment);
|
|
18
|
+
return clipboardData;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return dataTransfer;
|
|
22
|
+
};
|
|
23
|
+
export const createPasteHTMLPlugin = ()=>({
|
|
24
|
+
key: 'PasteHTMLPlugin',
|
|
25
|
+
withOverrides: (editor)=>{
|
|
26
|
+
const { insertData } = editor;
|
|
27
|
+
editor.insertData = (data)=>insertData(ensureXSlateFragment(data));
|
|
28
|
+
return editor;
|
|
29
|
+
},
|
|
30
|
+
inject: {
|
|
31
|
+
pluginsByKey: {
|
|
32
|
+
[KEY_DESERIALIZE_HTML]: {
|
|
33
|
+
editor: {
|
|
34
|
+
insertData: {
|
|
35
|
+
format: 'text/html',
|
|
36
|
+
transformData: sanitizeHTML
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createPasteHTMLPlugin';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { sanitizeHTML } from '../sanitizeHTML';
|
|
2
|
+
describe('HTML Sanitization', ()=>{
|
|
3
|
+
it('removes unsupported elements from <a>', ()=>{
|
|
4
|
+
const cases = [
|
|
5
|
+
{
|
|
6
|
+
input: '<h1><a href="#">Link in h1</a></h1>',
|
|
7
|
+
output: 'unchanged'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
input: '<div><a href="#">Link in div</a></div>',
|
|
11
|
+
output: 'unchanged'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
input: '<a href="#"><strong>strong in Link</strong></a>',
|
|
15
|
+
output: 'unchanged'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
input: '<a href="#"><b>b in Link</b></a>',
|
|
19
|
+
output: 'unchanged'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
input: '<a href="#"><em>em in Link</em></a>',
|
|
23
|
+
output: 'unchanged'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
input: '<a href="#"><i>i in Link</i></a>',
|
|
27
|
+
output: 'unchanged'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
input: '<a href="#"><u>u in Link</u></a>',
|
|
31
|
+
output: 'unchanged'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
input: '<a href="#"><h1>h1 in Link</h1><h2>this is h2</h2></a>',
|
|
35
|
+
output: '<a href="#">h1 in Link this is h2</a>'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
input: '<a href="#"><p>p in Link</p></a>',
|
|
39
|
+
output: '<a href="#">p in Link</a>'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
input: '<a href="#"><h1>h1 in Link <i>with</i> <b>marks</b></h1></a>',
|
|
43
|
+
output: '<a href="#">h1 in Link <i>with</i> <b>marks</b></a>'
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
cases.forEach((case_)=>{
|
|
47
|
+
expect(sanitizeHTML(case_.input)).toBe(case_.output === 'unchanged' ? case_.input : case_.output);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const wrapSpaceAround = (el)=>{
|
|
2
|
+
const spacer = new Text(' ');
|
|
3
|
+
const parent = el.parentNode;
|
|
4
|
+
if (!parent) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (el.previousSibling) {
|
|
8
|
+
parent.insertBefore(spacer, el);
|
|
9
|
+
}
|
|
10
|
+
if (el.nextSibling) {
|
|
11
|
+
parent.insertBefore(spacer, el.nextSibling);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const unwrap = (el)=>{
|
|
15
|
+
wrapSpaceAround(el);
|
|
16
|
+
el.replaceWith(...Array.from(el.childNodes));
|
|
17
|
+
};
|
|
18
|
+
export const sanitizeAnchors = (doc)=>{
|
|
19
|
+
const unsupportedTagSelector = `a :not(${[
|
|
20
|
+
'b',
|
|
21
|
+
'strong',
|
|
22
|
+
'code',
|
|
23
|
+
'pre',
|
|
24
|
+
'em',
|
|
25
|
+
'i',
|
|
26
|
+
'sub',
|
|
27
|
+
'sup',
|
|
28
|
+
'u',
|
|
29
|
+
'span'
|
|
30
|
+
].join(',')})`;
|
|
31
|
+
doc.querySelectorAll(unsupportedTagSelector).forEach(unwrap);
|
|
32
|
+
return doc;
|
|
33
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { sanitizeAnchors } from './sanitizeAnchors';
|
|
2
|
+
import { sanitizeSheets } from './sanitizeSheets';
|
|
3
|
+
const stripStyleTags = (doc)=>{
|
|
4
|
+
doc.querySelectorAll('style').forEach((e)=>{
|
|
5
|
+
e.remove();
|
|
6
|
+
});
|
|
7
|
+
return doc;
|
|
8
|
+
};
|
|
9
|
+
const stripMetaTags = (doc)=>{
|
|
10
|
+
doc.querySelectorAll('meta').forEach((el)=>el.remove());
|
|
11
|
+
return doc;
|
|
12
|
+
};
|
|
13
|
+
const transformers = [
|
|
14
|
+
stripStyleTags,
|
|
15
|
+
sanitizeSheets,
|
|
16
|
+
stripMetaTags,
|
|
17
|
+
sanitizeAnchors
|
|
18
|
+
];
|
|
19
|
+
function removeTableWrappers(table) {
|
|
20
|
+
const parent = table.parentElement;
|
|
21
|
+
if (parent && parent.tagName === 'DIV' && parent.children.length === 1) {
|
|
22
|
+
parent.replaceWith(table);
|
|
23
|
+
removeTableWrappers(table);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export const sanitizeHTML = (html)=>{
|
|
27
|
+
const doc = transformers.reduce((value, cb)=>cb(value), new DOMParser().parseFromString(html, 'text/html'));
|
|
28
|
+
const replacers = [
|
|
29
|
+
(innerHtml)=>innerHtml.replace(/<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)(.*)>\s+<(\/)?(table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '<$1$2$3><$4$5'),
|
|
30
|
+
(innerHtml)=>innerHtml.replace(/(?:<[^>^/]*>)\s*(?:<\/[^>]*>)<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1'),
|
|
31
|
+
(innerHTML)=>innerHTML.replace(/\s*<\/(div|p|table|thead|tbody|tr|td|th|caption|col|colgroup|ol|ul|li)/g, '</$1')
|
|
32
|
+
];
|
|
33
|
+
let previous;
|
|
34
|
+
do {
|
|
35
|
+
previous = doc.body.innerHTML;
|
|
36
|
+
doc.body.innerHTML = replacers.reduce((innerHTML, replacer)=>replacer(innerHTML), doc.body.innerHTML);
|
|
37
|
+
}while (doc.body.innerHTML !== previous)
|
|
38
|
+
doc.querySelectorAll('table').forEach(removeTableWrappers);
|
|
39
|
+
return doc.body.innerHTML;
|
|
40
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const sanitizeSheets = (doc)=>{
|
|
2
|
+
const supported = [
|
|
3
|
+
'google-sheets-html-origin',
|
|
4
|
+
'meta[content="Excel.Sheet"]',
|
|
5
|
+
'meta[content*="Microsoft Excel"]'
|
|
6
|
+
];
|
|
7
|
+
if (!supported.some((selector)=>!!doc.querySelector(selector))) {
|
|
8
|
+
return doc;
|
|
9
|
+
}
|
|
10
|
+
const isEmptyElement = (el)=>{
|
|
11
|
+
return (el.textContent ?? '').trim() === '';
|
|
12
|
+
};
|
|
13
|
+
const tables = Array.from(doc.querySelectorAll('table'));
|
|
14
|
+
for (const table of tables){
|
|
15
|
+
table.querySelectorAll('tr').forEach((row)=>{
|
|
16
|
+
isEmptyElement(row) && row.remove();
|
|
17
|
+
});
|
|
18
|
+
const rows = Array.from(table.querySelectorAll('tr'));
|
|
19
|
+
let colIndex = 1;
|
|
20
|
+
while(true){
|
|
21
|
+
const cells = rows.map((row)=>row.querySelector(`th:nth-of-type(${colIndex}), td:nth-of-type(${colIndex})`)).filter((cell)=>!!cell);
|
|
22
|
+
if (cells.length === 0) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
const isEmpty = cells.every((cell)=>isEmptyElement(cell));
|
|
26
|
+
if (!isEmpty) {
|
|
27
|
+
colIndex += 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
cells.forEach((cell)=>cell.remove());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return doc;
|
|
34
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { assertOutput, jsx } from '../../../test-utils';
|
|
2
|
+
describe('normalization', ()=>{
|
|
3
|
+
it('can contain inline entries & hyperlinks', ()=>{
|
|
4
|
+
const input = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some text before", jsx("hinline", {
|
|
5
|
+
type: "Entry",
|
|
6
|
+
id: "inline-entry"
|
|
7
|
+
}), jsx("hlink", {
|
|
8
|
+
uri: "https://contentful.com"
|
|
9
|
+
}), jsx("hlink", {
|
|
10
|
+
entry: "entry-id"
|
|
11
|
+
}), jsx("hlink", {
|
|
12
|
+
asset: "asset-id"
|
|
13
|
+
}), "some text after")));
|
|
14
|
+
assertOutput({
|
|
15
|
+
input,
|
|
16
|
+
expected: input
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('unwraps nested quotes', ()=>{
|
|
20
|
+
const input = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some"), jsx("hquote", null, jsx("hp", null, jsx("htext", {
|
|
21
|
+
bold: true,
|
|
22
|
+
italic: true,
|
|
23
|
+
underline: true
|
|
24
|
+
}, "paragraph"))), jsx("hp", null, "text")));
|
|
25
|
+
const expected = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some"), jsx("hp", null, jsx("htext", {
|
|
26
|
+
bold: true,
|
|
27
|
+
italic: true,
|
|
28
|
+
underline: true
|
|
29
|
+
}, "paragraph")), jsx("hp", null, "text")), jsx("hp", null, jsx("htext", null)));
|
|
30
|
+
assertOutput({
|
|
31
|
+
input,
|
|
32
|
+
expected
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('lifts other invalid children', ()=>{
|
|
36
|
+
it('block void elements', ()=>{
|
|
37
|
+
const input = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "this"), jsx("hembed", {
|
|
38
|
+
type: "Asset",
|
|
39
|
+
id: "1"
|
|
40
|
+
}), jsx("hp", null, "is"), jsx("hembed", {
|
|
41
|
+
type: "Entry",
|
|
42
|
+
id: "1"
|
|
43
|
+
}), jsx("hp", null, "a blockquote"), jsx("hhr", null), jsx("hh1", null, "Heading 1")));
|
|
44
|
+
const expected = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "this")), jsx("hembed", {
|
|
45
|
+
type: "Asset",
|
|
46
|
+
id: "1"
|
|
47
|
+
}), jsx("hquote", null, jsx("hp", null, "is")), jsx("hembed", {
|
|
48
|
+
type: "Entry",
|
|
49
|
+
id: "1"
|
|
50
|
+
}), jsx("hquote", null, jsx("hp", null, "a blockquote")), jsx("hhr", null), jsx("hh1", null, "Heading 1"), jsx("hp", null, jsx("text", null)));
|
|
51
|
+
assertOutput({
|
|
52
|
+
input,
|
|
53
|
+
expected
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it('handles lists', ()=>{
|
|
57
|
+
const input = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some", jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), "text")));
|
|
58
|
+
const expected = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some")), jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), jsx("hquote", null, jsx("hp", null, "text")), jsx("hp", null, jsx("text", null)));
|
|
59
|
+
assertOutput({
|
|
60
|
+
input,
|
|
61
|
+
expected
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('handles tables', ()=>{
|
|
65
|
+
const table = jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2"))));
|
|
66
|
+
const input = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some", table, "text")));
|
|
67
|
+
const expected = jsx("editor", null, jsx("hquote", null, jsx("hp", null, "some")), table, jsx("hquote", null, jsx("hp", null, "text")), jsx("hp", null, jsx("text", null)));
|
|
68
|
+
assertOutput({
|
|
69
|
+
input,
|
|
70
|
+
expected
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { css } from 'emotion';
|
|
4
|
+
const style = css({
|
|
5
|
+
margin: '0 0 1.3125rem',
|
|
6
|
+
borderLeft: `6px solid ${tokens.gray200}`,
|
|
7
|
+
paddingLeft: '0.875rem',
|
|
8
|
+
fontStyle: 'normal'
|
|
9
|
+
});
|
|
10
|
+
export function Quote(props) {
|
|
11
|
+
return React.createElement("blockquote", {
|
|
12
|
+
...props.attributes,
|
|
13
|
+
className: style
|
|
14
|
+
}, props.children);
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { QuoteIcon } from '@contentful/f36-icons';
|
|
3
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
4
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
5
|
+
import { isBlockSelected, focus } from '../../../helpers/editor';
|
|
6
|
+
import { ToolbarButton } from '../../shared/ToolbarButton';
|
|
7
|
+
import { toggleQuote } from '../toggleQuote';
|
|
8
|
+
export function ToolbarQuoteButton(props) {
|
|
9
|
+
const editor = useContentfulEditor();
|
|
10
|
+
function handleOnClick() {
|
|
11
|
+
if (!editor) return;
|
|
12
|
+
toggleQuote(editor, editor.tracking.onToolbarAction);
|
|
13
|
+
focus(editor);
|
|
14
|
+
}
|
|
15
|
+
if (!editor) return null;
|
|
16
|
+
return React.createElement(ToolbarButton, {
|
|
17
|
+
title: "Blockquote",
|
|
18
|
+
onClick: handleOnClick,
|
|
19
|
+
testId: "quote-toolbar-button",
|
|
20
|
+
isDisabled: props.isDisabled,
|
|
21
|
+
isActive: isBlockSelected(editor, BLOCKS.QUOTE)
|
|
22
|
+
}, React.createElement(QuoteIcon, null));
|
|
23
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BLOCKS, CONTAINERS } from '@contentful/rich-text-types';
|
|
2
|
+
import { transformLift, transformUnwrap } from '../../helpers/transformers';
|
|
3
|
+
import { Quote } from './components/Quote';
|
|
4
|
+
import { shouldResetQuoteOnBackspace } from './shouldResetQuote';
|
|
5
|
+
import { onKeyDownToggleQuote, toggleQuote } from './toggleQuote';
|
|
6
|
+
import { withQuote } from './withQuote';
|
|
7
|
+
export function createQuotePlugin() {
|
|
8
|
+
return {
|
|
9
|
+
key: BLOCKS.QUOTE,
|
|
10
|
+
type: BLOCKS.QUOTE,
|
|
11
|
+
isElement: true,
|
|
12
|
+
component: Quote,
|
|
13
|
+
options: {
|
|
14
|
+
hotkey: 'mod+shift+1'
|
|
15
|
+
},
|
|
16
|
+
handlers: {
|
|
17
|
+
onKeyDown: onKeyDownToggleQuote
|
|
18
|
+
},
|
|
19
|
+
deserializeHtml: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
validNodeName: 'BLOCKQUOTE'
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
resetNode: [
|
|
27
|
+
{
|
|
28
|
+
hotkey: 'backspace',
|
|
29
|
+
types: [
|
|
30
|
+
BLOCKS.QUOTE
|
|
31
|
+
],
|
|
32
|
+
predicate: shouldResetQuoteOnBackspace,
|
|
33
|
+
onReset: toggleQuote
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
normalizer: [
|
|
37
|
+
{
|
|
38
|
+
validChildren: CONTAINERS[BLOCKS.QUOTE],
|
|
39
|
+
transform: {
|
|
40
|
+
[BLOCKS.QUOTE]: transformUnwrap,
|
|
41
|
+
default: transformLift
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
withOverrides: withQuote
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
|
+
import { isLastChild, hasSingleChild } from '@udecode/plate-core';
|
|
3
|
+
import { getAboveNode, getBlockAbove, isAncestorEmpty } from '../../internal/queries';
|
|
4
|
+
export const shouldResetQuoteOnBackspace = (editor)=>{
|
|
5
|
+
const container = getAboveNode(editor, {
|
|
6
|
+
match: {
|
|
7
|
+
type: TEXT_CONTAINERS
|
|
8
|
+
},
|
|
9
|
+
mode: 'lowest'
|
|
10
|
+
});
|
|
11
|
+
if (!container) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!isAncestorEmpty(editor, container[0])) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const quote = getBlockAbove(editor, {
|
|
18
|
+
match: {
|
|
19
|
+
type: BLOCKS.QUOTE
|
|
20
|
+
},
|
|
21
|
+
mode: 'lowest'
|
|
22
|
+
});
|
|
23
|
+
if (!quote) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (hasSingleChild(quote[0]) && isLastChild(quote, container[1])) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import isHotkey from 'is-hotkey';
|
|
3
|
+
import { isBlockSelected } from '../../helpers/editor';
|
|
4
|
+
import { withoutNormalizing, wrapNodes, unwrapNodes, isElement } from '../../internal';
|
|
5
|
+
export function toggleQuote(editor, logAction) {
|
|
6
|
+
if (!editor.selection) return;
|
|
7
|
+
const isActive = isBlockSelected(editor, BLOCKS.QUOTE);
|
|
8
|
+
logAction?.(isActive ? 'remove' : 'insert', {
|
|
9
|
+
nodeType: BLOCKS.QUOTE
|
|
10
|
+
});
|
|
11
|
+
withoutNormalizing(editor, ()=>{
|
|
12
|
+
if (!editor.selection) return;
|
|
13
|
+
unwrapNodes(editor, {
|
|
14
|
+
match: (node)=>isElement(node) && node.type === BLOCKS.QUOTE,
|
|
15
|
+
split: true
|
|
16
|
+
});
|
|
17
|
+
if (!isActive) {
|
|
18
|
+
const quote = {
|
|
19
|
+
type: BLOCKS.QUOTE,
|
|
20
|
+
data: {},
|
|
21
|
+
children: []
|
|
22
|
+
};
|
|
23
|
+
wrapNodes(editor, quote);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export const onKeyDownToggleQuote = (editor, plugin)=>(event)=>{
|
|
28
|
+
const { hotkey } = plugin.options;
|
|
29
|
+
if (hotkey && isHotkey(hotkey, event)) {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
toggleQuote(editor, editor.tracking.onShortcutAction);
|
|
32
|
+
}
|
|
33
|
+
};
|