@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,104 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { InlineEntryCard, MenuItem, Text } from '@contentful/f36-components';
|
|
3
|
+
import { ClockIcon } from '@contentful/f36-icons';
|
|
4
|
+
import tokens from '@contentful/f36-tokens';
|
|
5
|
+
import { ScheduledIconWithTooltip, useEntity, useEntityLoader } from '@contentful/field-editor-reference';
|
|
6
|
+
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
7
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
8
|
+
import { css } from 'emotion';
|
|
9
|
+
const { getEntryTitle , getEntryStatus } = entityHelpers;
|
|
10
|
+
const styles = {
|
|
11
|
+
scheduledIcon: css({
|
|
12
|
+
verticalAlign: 'text-bottom',
|
|
13
|
+
marginRight: tokens.spacing2Xs
|
|
14
|
+
})
|
|
15
|
+
};
|
|
16
|
+
export function FetchingWrappedInlineEntryCard(props) {
|
|
17
|
+
const { data: entry , status: requestStatus } = useEntity('Entry', props.entryId);
|
|
18
|
+
const { getEntityScheduledActions } = useEntityLoader();
|
|
19
|
+
const loadEntityScheduledActions = ()=>getEntityScheduledActions('Entry', props.entryId);
|
|
20
|
+
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
21
|
+
const { onEntityFetchComplete } = props;
|
|
22
|
+
const contentType = React.useMemo(()=>{
|
|
23
|
+
if (!entry || !allContentTypes) return undefined;
|
|
24
|
+
return allContentTypes.find((contentType)=>contentType.sys.id === entry.sys.contentType.sys.id);
|
|
25
|
+
}, [
|
|
26
|
+
allContentTypes,
|
|
27
|
+
entry
|
|
28
|
+
]);
|
|
29
|
+
React.useEffect(()=>{
|
|
30
|
+
if (requestStatus !== 'success') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
onEntityFetchComplete?.();
|
|
34
|
+
}, [
|
|
35
|
+
requestStatus,
|
|
36
|
+
onEntityFetchComplete
|
|
37
|
+
]);
|
|
38
|
+
const contentTypeName = contentType ? contentType.name : '';
|
|
39
|
+
const title = React.useMemo(()=>getEntryTitle({
|
|
40
|
+
entry,
|
|
41
|
+
contentType,
|
|
42
|
+
localeCode: props.sdk.field.locale,
|
|
43
|
+
defaultLocaleCode: props.sdk.locales.default,
|
|
44
|
+
defaultTitle: 'Untitled'
|
|
45
|
+
}), [
|
|
46
|
+
entry,
|
|
47
|
+
contentType,
|
|
48
|
+
props.sdk.field.locale,
|
|
49
|
+
props.sdk.locales.default
|
|
50
|
+
]);
|
|
51
|
+
if (requestStatus === 'error') {
|
|
52
|
+
return React.createElement(InlineEntryCard, {
|
|
53
|
+
title: "Entry missing or inaccessible",
|
|
54
|
+
testId: INLINES.EMBEDDED_ENTRY,
|
|
55
|
+
isSelected: props.isSelected
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (requestStatus === 'loading') {
|
|
59
|
+
return React.createElement(InlineEntryCard, {
|
|
60
|
+
isLoading: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const entryStatus = getEntryStatus(entry.sys);
|
|
64
|
+
if (entryStatus === 'deleted') {
|
|
65
|
+
return React.createElement(InlineEntryCard, {
|
|
66
|
+
title: "Entry missing or inaccessible",
|
|
67
|
+
testId: INLINES.EMBEDDED_ENTRY,
|
|
68
|
+
isSelected: props.isSelected,
|
|
69
|
+
actions: [
|
|
70
|
+
React.createElement(MenuItem, {
|
|
71
|
+
key: "remove",
|
|
72
|
+
onClick: props.onRemove,
|
|
73
|
+
testId: "delete"
|
|
74
|
+
}, "Remove")
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return React.createElement(InlineEntryCard, {
|
|
79
|
+
testId: INLINES.EMBEDDED_ENTRY,
|
|
80
|
+
isSelected: props.isSelected,
|
|
81
|
+
title: `${contentTypeName}: ${title}`,
|
|
82
|
+
status: entryStatus,
|
|
83
|
+
actions: [
|
|
84
|
+
React.createElement(MenuItem, {
|
|
85
|
+
key: "edit",
|
|
86
|
+
onClick: props.onEdit
|
|
87
|
+
}, "Edit"),
|
|
88
|
+
React.createElement(MenuItem, {
|
|
89
|
+
key: "remove",
|
|
90
|
+
onClick: props.onRemove,
|
|
91
|
+
disabled: props.isDisabled,
|
|
92
|
+
testId: "delete"
|
|
93
|
+
}, "Remove")
|
|
94
|
+
]
|
|
95
|
+
}, React.createElement(ScheduledIconWithTooltip, {
|
|
96
|
+
getEntityScheduledActions: loadEntityScheduledActions,
|
|
97
|
+
entityType: "Entry",
|
|
98
|
+
entityId: entry.sys.id
|
|
99
|
+
}, React.createElement(ClockIcon, {
|
|
100
|
+
className: styles.scheduledIcon,
|
|
101
|
+
variant: "muted",
|
|
102
|
+
testId: "scheduled-icon"
|
|
103
|
+
})), React.createElement(Text, null, title));
|
|
104
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
2
|
+
export function createInlineEntryNode(id) {
|
|
3
|
+
return {
|
|
4
|
+
type: INLINES.EMBEDDED_ENTRY,
|
|
5
|
+
children: [
|
|
6
|
+
{
|
|
7
|
+
text: ''
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
data: {
|
|
11
|
+
target: {
|
|
12
|
+
sys: {
|
|
13
|
+
id,
|
|
14
|
+
type: 'Link',
|
|
15
|
+
linkType: 'Entry'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Menu, Flex } from '@contentful/f36-components';
|
|
3
|
+
import { EmbeddedEntryInlineIcon } from '@contentful/f36-icons';
|
|
4
|
+
import tokens from '@contentful/f36-tokens';
|
|
5
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
6
|
+
import { css } from 'emotion';
|
|
7
|
+
import isHotkey from 'is-hotkey';
|
|
8
|
+
import { useSelected, useReadOnly } from 'slate-react';
|
|
9
|
+
import { useContentfulEditor } from '../../ContentfulEditorProvider';
|
|
10
|
+
import { focus, moveToTheNextChar } from '../../helpers/editor';
|
|
11
|
+
import { IS_CHROME } from '../../helpers/environment';
|
|
12
|
+
import newEntitySelectorConfigFromRichTextField from '../../helpers/newEntitySelectorConfigFromRichTextField';
|
|
13
|
+
import { watchCurrentSlide } from '../../helpers/sdkNavigatorSlideIn';
|
|
14
|
+
import { findNodePath } from '../../internal/queries';
|
|
15
|
+
import { insertNodes, removeNodes, select } from '../../internal/transforms';
|
|
16
|
+
import { useSdkContext } from '../../SdkProvider';
|
|
17
|
+
import { withLinkTracking } from '../links-tracking';
|
|
18
|
+
import { FetchingWrappedInlineEntryCard } from './FetchingWrappedInlineEntryCard';
|
|
19
|
+
import { createInlineEntryNode } from './Util';
|
|
20
|
+
const styles = {
|
|
21
|
+
icon: css({
|
|
22
|
+
marginRight: '10px'
|
|
23
|
+
}),
|
|
24
|
+
root: css({
|
|
25
|
+
display: 'inline-block',
|
|
26
|
+
margin: `0 ${tokens.spacing2Xs}`,
|
|
27
|
+
fontSize: 'inherit',
|
|
28
|
+
span: {
|
|
29
|
+
userSelect: 'none'
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
function EmbeddedEntityInline(props) {
|
|
34
|
+
const editor = useContentfulEditor();
|
|
35
|
+
const sdk = useSdkContext();
|
|
36
|
+
const isSelected = useSelected();
|
|
37
|
+
const { id: entryId } = props.element.data.target.sys;
|
|
38
|
+
const isDisabled = useReadOnly();
|
|
39
|
+
function handleEditClick() {
|
|
40
|
+
return sdk.navigator.openEntry(entryId, {
|
|
41
|
+
slideIn: {
|
|
42
|
+
waitForClose: true
|
|
43
|
+
}
|
|
44
|
+
}).then(()=>{
|
|
45
|
+
editor && focus(editor);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function handleRemoveClick() {
|
|
49
|
+
if (!editor) return;
|
|
50
|
+
const pathToElement = findNodePath(editor, props.element);
|
|
51
|
+
removeNodes(editor, {
|
|
52
|
+
at: pathToElement
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return React.createElement("span", {
|
|
56
|
+
...props.attributes,
|
|
57
|
+
className: styles.root,
|
|
58
|
+
"data-embedded-entity-inline-id": entryId,
|
|
59
|
+
contentEditable: IS_CHROME ? undefined : false,
|
|
60
|
+
draggable: IS_CHROME ? true : undefined
|
|
61
|
+
}, React.createElement("span", {
|
|
62
|
+
contentEditable: IS_CHROME ? false : undefined,
|
|
63
|
+
draggable: IS_CHROME ? true : undefined
|
|
64
|
+
}, React.createElement(FetchingWrappedInlineEntryCard, {
|
|
65
|
+
sdk: sdk,
|
|
66
|
+
entryId: entryId,
|
|
67
|
+
isSelected: isSelected,
|
|
68
|
+
isDisabled: isDisabled,
|
|
69
|
+
onRemove: handleRemoveClick,
|
|
70
|
+
onEdit: handleEditClick,
|
|
71
|
+
onEntityFetchComplete: props.onEntityFetchComplete
|
|
72
|
+
})), props.children);
|
|
73
|
+
}
|
|
74
|
+
async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
75
|
+
logAction('openCreateEmbedDialog', {
|
|
76
|
+
nodeType: INLINES.EMBEDDED_ENTRY
|
|
77
|
+
});
|
|
78
|
+
const config = {
|
|
79
|
+
...newEntitySelectorConfigFromRichTextField(sdk.field, INLINES.EMBEDDED_ENTRY),
|
|
80
|
+
withCreate: true
|
|
81
|
+
};
|
|
82
|
+
const { selection } = editor;
|
|
83
|
+
const rteSlide = watchCurrentSlide(sdk.navigator);
|
|
84
|
+
const entry = await sdk.dialogs.selectSingleEntry(config);
|
|
85
|
+
if (!entry) {
|
|
86
|
+
logAction('cancelCreateEmbedDialog', {
|
|
87
|
+
nodeType: INLINES.EMBEDDED_ENTRY
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
select(editor, selection);
|
|
91
|
+
insertNodes(editor, createInlineEntryNode(entry.sys.id));
|
|
92
|
+
logAction('insert', {
|
|
93
|
+
nodeType: INLINES.EMBEDDED_ENTRY
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
rteSlide.onActive(()=>{
|
|
97
|
+
rteSlide.unwatch();
|
|
98
|
+
focus(editor);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export function ToolbarEmbeddedEntityInlineButton(props) {
|
|
102
|
+
const editor = useContentfulEditor();
|
|
103
|
+
const sdk = useSdkContext();
|
|
104
|
+
async function handleClick(event) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
if (!editor) return;
|
|
107
|
+
props.onClose();
|
|
108
|
+
await selectEntityAndInsert(editor, sdk, editor.tracking.onToolbarAction);
|
|
109
|
+
moveToTheNextChar(editor);
|
|
110
|
+
}
|
|
111
|
+
return React.createElement(Menu.Item, {
|
|
112
|
+
disabled: props.isDisabled,
|
|
113
|
+
className: "rich-text__entry-link-block-button",
|
|
114
|
+
testId: `toolbar-toggle-${INLINES.EMBEDDED_ENTRY}`,
|
|
115
|
+
onClick: handleClick
|
|
116
|
+
}, React.createElement(Flex, {
|
|
117
|
+
alignItems: "center",
|
|
118
|
+
flexDirection: "row"
|
|
119
|
+
}, React.createElement(EmbeddedEntryInlineIcon, {
|
|
120
|
+
variant: "secondary",
|
|
121
|
+
className: `rich-text__embedded-entry-list-icon ${styles.icon}`
|
|
122
|
+
}), React.createElement("span", null, "Inline entry")));
|
|
123
|
+
}
|
|
124
|
+
export function createEmbeddedEntityInlinePlugin(sdk) {
|
|
125
|
+
const htmlAttributeName = 'data-embedded-entity-inline-id';
|
|
126
|
+
return {
|
|
127
|
+
key: INLINES.EMBEDDED_ENTRY,
|
|
128
|
+
type: INLINES.EMBEDDED_ENTRY,
|
|
129
|
+
isElement: true,
|
|
130
|
+
isInline: true,
|
|
131
|
+
isVoid: true,
|
|
132
|
+
component: withLinkTracking(EmbeddedEntityInline),
|
|
133
|
+
options: {
|
|
134
|
+
hotkey: 'mod+shift+2'
|
|
135
|
+
},
|
|
136
|
+
handlers: {
|
|
137
|
+
onKeyDown: getWithEmbeddedEntryInlineEvents(sdk)
|
|
138
|
+
},
|
|
139
|
+
deserializeHtml: {
|
|
140
|
+
rules: [
|
|
141
|
+
{
|
|
142
|
+
validAttribute: htmlAttributeName
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
withoutChildren: true,
|
|
146
|
+
getNode: (el)=>createInlineEntryNode(el.getAttribute(htmlAttributeName))
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function getWithEmbeddedEntryInlineEvents(sdk) {
|
|
151
|
+
return function withEmbeddedEntryInlineEvents(editor, { options: { hotkey } }) {
|
|
152
|
+
return function handleEvent(event) {
|
|
153
|
+
if (!editor) return;
|
|
154
|
+
if (hotkey && isHotkey(hotkey, event)) {
|
|
155
|
+
selectEntityAndInsert(editor, sdk, editor.tracking.onShortcutAction);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { assertOutput, jsx } from '../../../test-utils';
|
|
2
|
+
describe('normalization', ()=>{
|
|
3
|
+
it('can contain inline entries & hyperlinks', ()=>{
|
|
4
|
+
const input = jsx("editor", null, jsx("hh1", 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"), jsx("hp", null, jsx("htext", null)));
|
|
14
|
+
assertOutput({
|
|
15
|
+
input,
|
|
16
|
+
expected: input
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('unwraps nested paragraphs', ()=>{
|
|
20
|
+
const input = jsx("editor", null, jsx("hh1", null, "one", ' ', jsx("hp", null, "two ", jsx("hp", null, "three ")), "four"));
|
|
21
|
+
const expected = jsx("editor", null, jsx("hh1", null, "one two three four"), jsx("hp", null, jsx("htext", null)));
|
|
22
|
+
assertOutput({
|
|
23
|
+
input,
|
|
24
|
+
expected
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('lifts other invalid children', ()=>{
|
|
28
|
+
it('block void elements', ()=>{
|
|
29
|
+
const input = jsx("editor", null, jsx("hh1", null, jsx("hembed", {
|
|
30
|
+
type: "Asset",
|
|
31
|
+
id: "1"
|
|
32
|
+
}), " start"), jsx("hh1", null, "end ", jsx("hembed", {
|
|
33
|
+
type: "Asset",
|
|
34
|
+
id: "2"
|
|
35
|
+
})), jsx("hh1", null, "in ", jsx("hembed", {
|
|
36
|
+
type: "Asset",
|
|
37
|
+
id: "3"
|
|
38
|
+
}), " between"), jsx("hh1", null, jsx("hembed", {
|
|
39
|
+
type: "Entry",
|
|
40
|
+
id: "1"
|
|
41
|
+
}), " start"), jsx("hh1", null, "end ", jsx("hembed", {
|
|
42
|
+
type: "Entry",
|
|
43
|
+
id: "2"
|
|
44
|
+
})), jsx("hh1", null, "in ", jsx("hembed", {
|
|
45
|
+
type: "Entry",
|
|
46
|
+
id: "3"
|
|
47
|
+
}), " between"), jsx("hh1", null, jsx("hhr", null), " start"), jsx("hh1", null, "end ", jsx("hhr", null)), jsx("hh1", null, "in ", jsx("hhr", null), " between"));
|
|
48
|
+
const expected = jsx("editor", null, jsx("hembed", {
|
|
49
|
+
type: "Asset",
|
|
50
|
+
id: "1"
|
|
51
|
+
}), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hembed", {
|
|
52
|
+
type: "Asset",
|
|
53
|
+
id: "2"
|
|
54
|
+
}), jsx("hh1", null, "in "), jsx("hembed", {
|
|
55
|
+
type: "Asset",
|
|
56
|
+
id: "3"
|
|
57
|
+
}), jsx("hh1", null, " between"), jsx("hembed", {
|
|
58
|
+
type: "Entry",
|
|
59
|
+
id: "1"
|
|
60
|
+
}), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hembed", {
|
|
61
|
+
type: "Entry",
|
|
62
|
+
id: "2"
|
|
63
|
+
}), jsx("hh1", null, "in "), jsx("hembed", {
|
|
64
|
+
type: "Entry",
|
|
65
|
+
id: "3"
|
|
66
|
+
}), jsx("hh1", null, " between"), jsx("hhr", null), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hhr", null), jsx("hh1", null, "in "), jsx("hhr", null), jsx("hh1", null, " between"), jsx("hp", null, jsx("htext", null)));
|
|
67
|
+
assertOutput({
|
|
68
|
+
input,
|
|
69
|
+
expected
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('nested headings', ()=>{
|
|
73
|
+
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hh1", null, jsx("htext", {
|
|
74
|
+
bold: true,
|
|
75
|
+
italic: true,
|
|
76
|
+
underline: true
|
|
77
|
+
}, "paragraph")), "text"));
|
|
78
|
+
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hh1", null, jsx("htext", {
|
|
79
|
+
bold: true,
|
|
80
|
+
italic: true,
|
|
81
|
+
underline: true
|
|
82
|
+
}, "paragraph")), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
83
|
+
assertOutput({
|
|
84
|
+
input,
|
|
85
|
+
expected
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it('handles quotes', ()=>{
|
|
89
|
+
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hquote", null, jsx("hp", null, "quote")), "text"));
|
|
90
|
+
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hquote", null, jsx("hp", null, "quote")), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
91
|
+
assertOutput({
|
|
92
|
+
input,
|
|
93
|
+
expected
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('handles lists', ()=>{
|
|
97
|
+
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), "text"));
|
|
98
|
+
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
99
|
+
assertOutput({
|
|
100
|
+
input,
|
|
101
|
+
expected
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it('handles tables', ()=>{
|
|
105
|
+
const input = jsx("editor", null, jsx("hh1", 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"));
|
|
106
|
+
const expected = jsx("editor", null, jsx("hh1", 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("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
107
|
+
assertOutput({
|
|
108
|
+
input,
|
|
109
|
+
expected
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import tokens from '@contentful/f36-tokens';
|
|
3
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
4
|
+
import { css, cx } from 'emotion';
|
|
5
|
+
const styles = {
|
|
6
|
+
dropdown: {
|
|
7
|
+
root: css`
|
|
8
|
+
font-weight: ${tokens.fontWeightDemiBold};
|
|
9
|
+
`,
|
|
10
|
+
[BLOCKS.PARAGRAPH]: css`
|
|
11
|
+
font-size: ${tokens.fontSizeL};
|
|
12
|
+
`,
|
|
13
|
+
[BLOCKS.HEADING_1]: css`
|
|
14
|
+
font-size: 1.625rem;
|
|
15
|
+
`,
|
|
16
|
+
[BLOCKS.HEADING_2]: css`
|
|
17
|
+
font-size: 1.4375rem;
|
|
18
|
+
`,
|
|
19
|
+
[BLOCKS.HEADING_3]: css`
|
|
20
|
+
font-size: 1.25rem;
|
|
21
|
+
`,
|
|
22
|
+
[BLOCKS.HEADING_4]: css`
|
|
23
|
+
font-size: 1.125rem;
|
|
24
|
+
`,
|
|
25
|
+
[BLOCKS.HEADING_5]: css`
|
|
26
|
+
font-size: 1rem;
|
|
27
|
+
`,
|
|
28
|
+
[BLOCKS.HEADING_6]: css`
|
|
29
|
+
font-size: 0.875rem;
|
|
30
|
+
`
|
|
31
|
+
},
|
|
32
|
+
headings: {
|
|
33
|
+
root: css`
|
|
34
|
+
font-weight: ${tokens.fontWeightMedium};
|
|
35
|
+
line-height: 1.3;
|
|
36
|
+
margin: 0 0 ${tokens.spacingS};
|
|
37
|
+
`,
|
|
38
|
+
[BLOCKS.HEADING_1]: css`
|
|
39
|
+
font-size: 1.875rem;
|
|
40
|
+
`,
|
|
41
|
+
[BLOCKS.HEADING_2]: css`
|
|
42
|
+
font-size: 1.5625rem;
|
|
43
|
+
`,
|
|
44
|
+
[BLOCKS.HEADING_3]: css`
|
|
45
|
+
font-size: 1.375rem;
|
|
46
|
+
`,
|
|
47
|
+
[BLOCKS.HEADING_4]: css`
|
|
48
|
+
font-size: 1.25rem;
|
|
49
|
+
`,
|
|
50
|
+
[BLOCKS.HEADING_5]: css`
|
|
51
|
+
font-size: 1.125rem;
|
|
52
|
+
`,
|
|
53
|
+
[BLOCKS.HEADING_6]: css`
|
|
54
|
+
font-size: 1rem;
|
|
55
|
+
`
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function createHeading(Tag, block) {
|
|
59
|
+
return function Heading(props) {
|
|
60
|
+
return React.createElement(Tag, {
|
|
61
|
+
...props.attributes,
|
|
62
|
+
className: cx(styles.headings.root, styles.headings[block])
|
|
63
|
+
}, props.children);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export const HeadingComponents = {
|
|
67
|
+
[BLOCKS.HEADING_1]: React.memo(createHeading('h1', BLOCKS.HEADING_1)),
|
|
68
|
+
[BLOCKS.HEADING_2]: React.memo(createHeading('h2', BLOCKS.HEADING_2)),
|
|
69
|
+
[BLOCKS.HEADING_3]: React.memo(createHeading('h3', BLOCKS.HEADING_3)),
|
|
70
|
+
[BLOCKS.HEADING_4]: React.memo(createHeading('h4', BLOCKS.HEADING_4)),
|
|
71
|
+
[BLOCKS.HEADING_5]: React.memo(createHeading('h5', BLOCKS.HEADING_5)),
|
|
72
|
+
[BLOCKS.HEADING_6]: React.memo(createHeading('h6', BLOCKS.HEADING_6))
|
|
73
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Menu, Button } from '@contentful/f36-components';
|
|
3
|
+
import { ChevronDownIcon } from '@contentful/f36-icons';
|
|
4
|
+
import tokens from '@contentful/f36-tokens';
|
|
5
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
6
|
+
import { css, cx } from 'emotion';
|
|
7
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
8
|
+
import { getElementFromCurrentSelection, focus, isBlockSelected, toggleElement } from '../../../helpers/editor';
|
|
9
|
+
import { isNodeTypeEnabled } from '../../../helpers/validations';
|
|
10
|
+
import { useSdkContext } from '../../../SdkProvider';
|
|
11
|
+
const styles = {
|
|
12
|
+
dropdown: {
|
|
13
|
+
root: css`
|
|
14
|
+
font-weight: ${tokens.fontWeightDemiBold};
|
|
15
|
+
`,
|
|
16
|
+
[BLOCKS.PARAGRAPH]: css`
|
|
17
|
+
font-size: ${tokens.fontSizeL};
|
|
18
|
+
`,
|
|
19
|
+
[BLOCKS.HEADING_1]: css`
|
|
20
|
+
font-size: 1.625rem;
|
|
21
|
+
`,
|
|
22
|
+
[BLOCKS.HEADING_2]: css`
|
|
23
|
+
font-size: 1.4375rem;
|
|
24
|
+
`,
|
|
25
|
+
[BLOCKS.HEADING_3]: css`
|
|
26
|
+
font-size: 1.25rem;
|
|
27
|
+
`,
|
|
28
|
+
[BLOCKS.HEADING_4]: css`
|
|
29
|
+
font-size: 1.125rem;
|
|
30
|
+
`,
|
|
31
|
+
[BLOCKS.HEADING_5]: css`
|
|
32
|
+
font-size: 1rem;
|
|
33
|
+
`,
|
|
34
|
+
[BLOCKS.HEADING_6]: css`
|
|
35
|
+
font-size: 0.875rem;
|
|
36
|
+
`
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const LABELS = {
|
|
40
|
+
[BLOCKS.PARAGRAPH]: 'Normal text',
|
|
41
|
+
[BLOCKS.HEADING_1]: 'Heading 1',
|
|
42
|
+
[BLOCKS.HEADING_2]: 'Heading 2',
|
|
43
|
+
[BLOCKS.HEADING_3]: 'Heading 3',
|
|
44
|
+
[BLOCKS.HEADING_4]: 'Heading 4',
|
|
45
|
+
[BLOCKS.HEADING_5]: 'Heading 5',
|
|
46
|
+
[BLOCKS.HEADING_6]: 'Heading 6'
|
|
47
|
+
};
|
|
48
|
+
export function ToolbarHeadingButton(props) {
|
|
49
|
+
const sdk = useSdkContext();
|
|
50
|
+
const editor = useContentfulEditor();
|
|
51
|
+
const [isOpen, setOpen] = React.useState(false);
|
|
52
|
+
const [selected, setSelected] = React.useState(BLOCKS.PARAGRAPH);
|
|
53
|
+
React.useEffect(()=>{
|
|
54
|
+
if (!editor?.selection) return;
|
|
55
|
+
const [element] = getElementFromCurrentSelection(editor);
|
|
56
|
+
const type = element.type;
|
|
57
|
+
setSelected(LABELS[type] ? type : BLOCKS.PARAGRAPH);
|
|
58
|
+
}, [
|
|
59
|
+
editor?.operations,
|
|
60
|
+
editor?.selection
|
|
61
|
+
]);
|
|
62
|
+
const [nodeTypesByEnablement, someHeadingsEnabled] = React.useMemo(()=>{
|
|
63
|
+
const nodeTypesByEnablement = Object.fromEntries(Object.keys(LABELS).map((nodeType)=>[
|
|
64
|
+
nodeType,
|
|
65
|
+
isNodeTypeEnabled(sdk.field, nodeType)
|
|
66
|
+
]));
|
|
67
|
+
const someHeadingsEnabled = Object.values(nodeTypesByEnablement).filter(Boolean).length > 0;
|
|
68
|
+
return [
|
|
69
|
+
nodeTypesByEnablement,
|
|
70
|
+
someHeadingsEnabled
|
|
71
|
+
];
|
|
72
|
+
}, [
|
|
73
|
+
sdk.field
|
|
74
|
+
]);
|
|
75
|
+
function handleOnSelectItem(type) {
|
|
76
|
+
return (event)=>{
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
if (!editor?.selection) return;
|
|
79
|
+
setSelected(type);
|
|
80
|
+
setOpen(false);
|
|
81
|
+
const prevOnChange = editor.onChange;
|
|
82
|
+
editor.onChange = (...args)=>{
|
|
83
|
+
focus(editor);
|
|
84
|
+
editor.onChange = prevOnChange;
|
|
85
|
+
prevOnChange(...args);
|
|
86
|
+
};
|
|
87
|
+
const isActive = isBlockSelected(editor, type);
|
|
88
|
+
editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
|
|
89
|
+
nodeType: type
|
|
90
|
+
});
|
|
91
|
+
toggleElement(editor, {
|
|
92
|
+
activeType: type,
|
|
93
|
+
inactiveType: type
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (!editor) return null;
|
|
98
|
+
return React.createElement(Menu, {
|
|
99
|
+
isOpen: isOpen,
|
|
100
|
+
onClose: ()=>setOpen(false)
|
|
101
|
+
}, React.createElement(Menu.Trigger, null, React.createElement(Button, {
|
|
102
|
+
size: "small",
|
|
103
|
+
testId: "toolbar-heading-toggle",
|
|
104
|
+
variant: "transparent",
|
|
105
|
+
endIcon: React.createElement(ChevronDownIcon, null),
|
|
106
|
+
isDisabled: props.isDisabled,
|
|
107
|
+
onClick: ()=>someHeadingsEnabled && setOpen(!isOpen)
|
|
108
|
+
}, LABELS[selected])), React.createElement(Menu.List, {
|
|
109
|
+
testId: "dropdown-heading-list"
|
|
110
|
+
}, ' ', Object.keys(LABELS).map((nodeType)=>nodeTypesByEnablement[nodeType] && React.createElement(Menu.Item, {
|
|
111
|
+
key: nodeType,
|
|
112
|
+
isInitiallyFocused: selected === nodeType,
|
|
113
|
+
onClick: handleOnSelectItem(nodeType),
|
|
114
|
+
testId: `dropdown-option-${nodeType}`,
|
|
115
|
+
disabled: props.isDisabled
|
|
116
|
+
}, React.createElement("span", {
|
|
117
|
+
className: cx(styles.dropdown.root, styles.dropdown[nodeType])
|
|
118
|
+
}, LABELS[nodeType]))).filter(Boolean)));
|
|
119
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BLOCKS, HEADINGS } from '@contentful/rich-text-types';
|
|
2
|
+
import isHotkey from 'is-hotkey';
|
|
3
|
+
import { isBlockSelected, isInlineOrText, toggleElement } from '../../helpers/editor';
|
|
4
|
+
import { transformLift, transformUnwrap } from '../../helpers/transformers';
|
|
5
|
+
import { isMarkActive, getAboveNode } from '../../internal/queries';
|
|
6
|
+
import { COMMAND_PROMPT } from '../CommandPalette/constants';
|
|
7
|
+
import { HeadingComponents } from './components/Heading';
|
|
8
|
+
const buildHeadingEventHandler = (type)=>(editor, { options: { hotkey } })=>(event)=>{
|
|
9
|
+
if (editor.selection && hotkey && isHotkey(hotkey, event)) {
|
|
10
|
+
const isActive = isBlockSelected(editor, type);
|
|
11
|
+
editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
|
|
12
|
+
nodeType: type
|
|
13
|
+
});
|
|
14
|
+
toggleElement(editor, {
|
|
15
|
+
activeType: type,
|
|
16
|
+
inactiveType: BLOCKS.PARAGRAPH
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const createHeadingPlugin = ()=>({
|
|
21
|
+
key: 'HeadingPlugin',
|
|
22
|
+
softBreak: [
|
|
23
|
+
{
|
|
24
|
+
hotkey: 'shift+enter',
|
|
25
|
+
query: {
|
|
26
|
+
allow: HEADINGS
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
normalizer: [
|
|
31
|
+
{
|
|
32
|
+
match: {
|
|
33
|
+
type: HEADINGS
|
|
34
|
+
},
|
|
35
|
+
validChildren: (_, [node])=>isInlineOrText(node),
|
|
36
|
+
transform: {
|
|
37
|
+
[BLOCKS.PARAGRAPH]: transformUnwrap,
|
|
38
|
+
default: transformLift
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
then: (editor)=>{
|
|
43
|
+
return {
|
|
44
|
+
exitBreak: [
|
|
45
|
+
{
|
|
46
|
+
hotkey: 'enter',
|
|
47
|
+
query: {
|
|
48
|
+
allow: HEADINGS,
|
|
49
|
+
end: true,
|
|
50
|
+
start: true,
|
|
51
|
+
filter: ([, path])=>!getAboveNode(editor, {
|
|
52
|
+
at: path,
|
|
53
|
+
match: {
|
|
54
|
+
type: BLOCKS.LIST_ITEM
|
|
55
|
+
}
|
|
56
|
+
}) && !isMarkActive(editor, COMMAND_PROMPT)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
plugins: HEADINGS.map((nodeType, idx)=>{
|
|
63
|
+
const level = idx + 1;
|
|
64
|
+
const tagName = `h${level}`;
|
|
65
|
+
return {
|
|
66
|
+
key: nodeType,
|
|
67
|
+
type: nodeType,
|
|
68
|
+
isElement: true,
|
|
69
|
+
component: HeadingComponents[nodeType],
|
|
70
|
+
options: {
|
|
71
|
+
hotkey: [
|
|
72
|
+
`mod+alt+${level}`
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
handlers: {
|
|
76
|
+
onKeyDown: buildHeadingEventHandler(nodeType)
|
|
77
|
+
},
|
|
78
|
+
deserializeHtml: {
|
|
79
|
+
rules: [
|
|
80
|
+
{
|
|
81
|
+
validNodeName: tagName.toUpperCase()
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
})
|
|
87
|
+
});
|