@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,125 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { HorizontalRuleIcon } from '@contentful/f36-icons';
|
|
3
|
+
import tokens from '@contentful/f36-tokens';
|
|
4
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
5
|
+
import { css, cx } from 'emotion';
|
|
6
|
+
import * as Slate from 'slate-react';
|
|
7
|
+
import { useContentfulEditor } from '../../ContentfulEditorProvider';
|
|
8
|
+
import { getNodeEntryFromSelection, isBlockSelected, moveToTheNextLine, focus } from '../../helpers/editor';
|
|
9
|
+
import { getText } from '../../internal/queries';
|
|
10
|
+
import { insertNodes, setNodes, removeNodes } from '../../internal/transforms';
|
|
11
|
+
import { ToolbarButton } from '../shared/ToolbarButton';
|
|
12
|
+
const styles = {
|
|
13
|
+
container: css`
|
|
14
|
+
margin: 0 0 ${tokens.spacingL};
|
|
15
|
+
`,
|
|
16
|
+
hr: css`
|
|
17
|
+
margin: 0;
|
|
18
|
+
height: ${tokens.spacingM};
|
|
19
|
+
background: transparent;
|
|
20
|
+
position: relative;
|
|
21
|
+
border: 0;
|
|
22
|
+
user-select: none;
|
|
23
|
+
&:hover {
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
}
|
|
26
|
+
&::after {
|
|
27
|
+
content: '';
|
|
28
|
+
position: absolute;
|
|
29
|
+
width: 100%;
|
|
30
|
+
height: 1px;
|
|
31
|
+
background: ${tokens.gray300};
|
|
32
|
+
top: 50%;
|
|
33
|
+
}
|
|
34
|
+
`,
|
|
35
|
+
hrSelected: css`
|
|
36
|
+
&::after {
|
|
37
|
+
background: ${tokens.colorPrimary};
|
|
38
|
+
-webkit-box-shadow: 0px 0px 5px ${tokens.colorPrimary};
|
|
39
|
+
box-shadow: 0px 0px 5px ${tokens.colorPrimary};
|
|
40
|
+
}
|
|
41
|
+
`
|
|
42
|
+
};
|
|
43
|
+
export function withHrEvents(editor) {
|
|
44
|
+
return (event)=>{
|
|
45
|
+
if (!editor) return;
|
|
46
|
+
const [, pathToSelectedHr] = getNodeEntryFromSelection(editor, BLOCKS.HR);
|
|
47
|
+
if (pathToSelectedHr) {
|
|
48
|
+
const isBackspace = event.key === 'Backspace';
|
|
49
|
+
const isDelete = event.key === 'Delete';
|
|
50
|
+
if (isBackspace || isDelete) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
removeNodes(editor, {
|
|
53
|
+
at: pathToSelectedHr
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function ToolbarHrButton(props) {
|
|
60
|
+
const editor = useContentfulEditor();
|
|
61
|
+
function handleOnClick() {
|
|
62
|
+
if (!editor?.selection) return;
|
|
63
|
+
const hr = {
|
|
64
|
+
type: BLOCKS.HR,
|
|
65
|
+
data: {},
|
|
66
|
+
children: [
|
|
67
|
+
{
|
|
68
|
+
text: ''
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
isVoid: true
|
|
72
|
+
};
|
|
73
|
+
const hasText = !!getText(editor, editor.selection.focus.path);
|
|
74
|
+
hasText ? insertNodes(editor, hr) : setNodes(editor, hr);
|
|
75
|
+
moveToTheNextLine(editor);
|
|
76
|
+
focus(editor);
|
|
77
|
+
}
|
|
78
|
+
if (!editor) return null;
|
|
79
|
+
return React.createElement(ToolbarButton, {
|
|
80
|
+
title: "HR",
|
|
81
|
+
isDisabled: props.isDisabled,
|
|
82
|
+
onClick: handleOnClick,
|
|
83
|
+
testId: "hr-toolbar-button",
|
|
84
|
+
isActive: isBlockSelected(editor, BLOCKS.HR)
|
|
85
|
+
}, React.createElement(HorizontalRuleIcon, null));
|
|
86
|
+
}
|
|
87
|
+
export function Hr(props) {
|
|
88
|
+
const isSelected = Slate.useSelected();
|
|
89
|
+
const isFocused = Slate.useFocused();
|
|
90
|
+
return React.createElement("div", {
|
|
91
|
+
...props.attributes,
|
|
92
|
+
className: styles.container,
|
|
93
|
+
"data-void-element": BLOCKS.HR
|
|
94
|
+
}, React.createElement("div", {
|
|
95
|
+
draggable: true,
|
|
96
|
+
contentEditable: false
|
|
97
|
+
}, React.createElement("hr", {
|
|
98
|
+
className: cx(styles.hr, isSelected && isFocused ? styles.hrSelected : undefined)
|
|
99
|
+
})), props.children);
|
|
100
|
+
}
|
|
101
|
+
export const createHrPlugin = ()=>({
|
|
102
|
+
key: BLOCKS.HR,
|
|
103
|
+
type: BLOCKS.HR,
|
|
104
|
+
isVoid: true,
|
|
105
|
+
isElement: true,
|
|
106
|
+
component: Hr,
|
|
107
|
+
handlers: {
|
|
108
|
+
onKeyDown: withHrEvents
|
|
109
|
+
},
|
|
110
|
+
deserializeHtml: {
|
|
111
|
+
rules: [
|
|
112
|
+
{
|
|
113
|
+
validNodeName: [
|
|
114
|
+
'HR'
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
validAttribute: {
|
|
119
|
+
'data-void-element': BLOCKS.HR
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
withoutChildren: true
|
|
124
|
+
}
|
|
125
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TextLink, Button, FormControl, FormLabel, Select, TextInput, Form, ModalContent, ModalControls } from '@contentful/f36-components';
|
|
3
|
+
import tokens from '@contentful/f36-tokens';
|
|
4
|
+
import { EntityProvider } from '@contentful/field-editor-reference';
|
|
5
|
+
import { ModalDialogLauncher } from '@contentful/field-editor-shared';
|
|
6
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
7
|
+
import { css } from 'emotion';
|
|
8
|
+
import { getNodeEntryFromSelection, insertLink, LINK_TYPES, focus } from '../../helpers/editor';
|
|
9
|
+
import getLinkedContentTypeIdsForNodeType from '../../helpers/getLinkedContentTypeIdsForNodeType';
|
|
10
|
+
import { isNodeTypeEnabled } from '../../helpers/validations';
|
|
11
|
+
import { withoutNormalizing } from '../../internal';
|
|
12
|
+
import { getText, isEditorReadOnly } from '../../internal/queries';
|
|
13
|
+
import { select } from '../../internal/transforms';
|
|
14
|
+
import { FetchingWrappedAssetCard } from '../shared/FetchingWrappedAssetCard';
|
|
15
|
+
import { FetchingWrappedEntryCard } from '../shared/FetchingWrappedEntryCard';
|
|
16
|
+
const styles = {
|
|
17
|
+
removeSelectionLabel: css`
|
|
18
|
+
margin-left: ${tokens.spacingS};
|
|
19
|
+
`
|
|
20
|
+
};
|
|
21
|
+
const SYS_LINK_TYPES = {
|
|
22
|
+
[INLINES.ENTRY_HYPERLINK]: 'Entry',
|
|
23
|
+
[INLINES.ASSET_HYPERLINK]: 'Asset'
|
|
24
|
+
};
|
|
25
|
+
const LINK_TYPE_SELECTION_VALUES = {
|
|
26
|
+
[INLINES.HYPERLINK]: 'URL',
|
|
27
|
+
[INLINES.ENTRY_HYPERLINK]: 'Entry',
|
|
28
|
+
[INLINES.ASSET_HYPERLINK]: 'Asset'
|
|
29
|
+
};
|
|
30
|
+
export function HyperlinkModal(props) {
|
|
31
|
+
const enabledLinkTypes = LINK_TYPES.filter((nodeType)=>isNodeTypeEnabled(props.sdk.field, nodeType));
|
|
32
|
+
const [defaultLinkType] = enabledLinkTypes;
|
|
33
|
+
const [linkText, setLinkText] = React.useState(props.linkText ?? '');
|
|
34
|
+
const [linkType, setLinkType] = React.useState(props.linkType ?? defaultLinkType);
|
|
35
|
+
const [linkTarget, setLinkTarget] = React.useState(props.linkTarget ?? '');
|
|
36
|
+
const [linkEntity, setLinkEntity] = React.useState(props.linkEntity ?? null);
|
|
37
|
+
function isLinkComplete() {
|
|
38
|
+
const isRegularLink = linkType === INLINES.HYPERLINK;
|
|
39
|
+
if (isRegularLink) {
|
|
40
|
+
return !!(linkText && linkTarget);
|
|
41
|
+
}
|
|
42
|
+
const entityLinks = Object.keys(SYS_LINK_TYPES);
|
|
43
|
+
const isEntityLink = entityLinks.includes(linkType);
|
|
44
|
+
if (isEntityLink) {
|
|
45
|
+
return !!(linkText && linkEntity);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function handleOnSubmit(event) {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
props.onClose({
|
|
52
|
+
linkText,
|
|
53
|
+
linkType,
|
|
54
|
+
linkTarget,
|
|
55
|
+
linkEntity
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function entityToLink(entity) {
|
|
59
|
+
const { id , type } = entity.sys;
|
|
60
|
+
return {
|
|
61
|
+
sys: {
|
|
62
|
+
id,
|
|
63
|
+
type: 'Link',
|
|
64
|
+
linkType: type
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function selectEntry() {
|
|
69
|
+
const options = {
|
|
70
|
+
locale: props.sdk.field.locale,
|
|
71
|
+
contentTypes: getLinkedContentTypeIdsForNodeType(props.sdk.field, INLINES.ENTRY_HYPERLINK)
|
|
72
|
+
};
|
|
73
|
+
const entry = await props.sdk.dialogs.selectSingleEntry(options);
|
|
74
|
+
setLinkTarget('');
|
|
75
|
+
setLinkEntity(entityToLink(entry));
|
|
76
|
+
}
|
|
77
|
+
async function selectAsset() {
|
|
78
|
+
const options = {
|
|
79
|
+
locale: props.sdk.field.locale
|
|
80
|
+
};
|
|
81
|
+
const asset = await props.sdk.dialogs.selectSingleAsset(options);
|
|
82
|
+
setLinkTarget('');
|
|
83
|
+
setLinkEntity(entityToLink(asset));
|
|
84
|
+
}
|
|
85
|
+
function resetLinkEntity(event) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
setLinkEntity(null);
|
|
88
|
+
}
|
|
89
|
+
return React.createElement(EntityProvider, {
|
|
90
|
+
sdk: props.sdk
|
|
91
|
+
}, React.createElement(React.Fragment, null, React.createElement(ModalContent, null, React.createElement(Form, null, !props.linkType && React.createElement(FormControl, {
|
|
92
|
+
id: "link-text",
|
|
93
|
+
isRequired: true
|
|
94
|
+
}, React.createElement(FormControl.Label, null, "Link text"), React.createElement(TextInput, {
|
|
95
|
+
testId: "link-text-input",
|
|
96
|
+
name: "link-text",
|
|
97
|
+
value: linkText,
|
|
98
|
+
onChange: (event)=>setLinkText(event.target.value)
|
|
99
|
+
})), enabledLinkTypes.length > 1 && React.createElement(FormControl, {
|
|
100
|
+
id: "link-type"
|
|
101
|
+
}, React.createElement(FormControl.Label, null, "Link type"), React.createElement(Select, {
|
|
102
|
+
value: linkType,
|
|
103
|
+
onChange: (event)=>setLinkType(event.target.value),
|
|
104
|
+
testId: "link-type-input",
|
|
105
|
+
isDisabled: props.readonly
|
|
106
|
+
}, enabledLinkTypes.map((nodeType)=>React.createElement(Select.Option, {
|
|
107
|
+
key: nodeType,
|
|
108
|
+
value: nodeType
|
|
109
|
+
}, LINK_TYPE_SELECTION_VALUES[nodeType])))), linkType === INLINES.HYPERLINK && React.createElement(FormControl, {
|
|
110
|
+
id: "linkTarget",
|
|
111
|
+
isRequired: true
|
|
112
|
+
}, React.createElement(FormControl.Label, null, "Link target"), React.createElement(TextInput, {
|
|
113
|
+
name: "linkTarget",
|
|
114
|
+
value: linkTarget,
|
|
115
|
+
onChange: (event)=>{
|
|
116
|
+
setLinkEntity(null);
|
|
117
|
+
setLinkTarget(event.target.value);
|
|
118
|
+
},
|
|
119
|
+
testId: "link-target-input",
|
|
120
|
+
isDisabled: props.readonly
|
|
121
|
+
}), React.createElement(FormControl.HelpText, null, "A protocol may be required, e.g. https://")), linkType !== INLINES.HYPERLINK && React.createElement("div", null, React.createElement(FormLabel, {
|
|
122
|
+
isRequired: true,
|
|
123
|
+
htmlFor: ""
|
|
124
|
+
}, "Link target", ' '), linkEntity && linkEntity.sys.linkType === SYS_LINK_TYPES[linkType] ? React.createElement(React.Fragment, null, !props.readonly && React.createElement(TextLink, {
|
|
125
|
+
testId: "entity-selection-link",
|
|
126
|
+
onClick: resetLinkEntity,
|
|
127
|
+
className: styles.removeSelectionLabel
|
|
128
|
+
}, "Remove selection"), React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && React.createElement(FetchingWrappedEntryCard, {
|
|
129
|
+
sdk: props.sdk,
|
|
130
|
+
locale: props.sdk.field.locale,
|
|
131
|
+
entryId: linkEntity.sys.id,
|
|
132
|
+
isDisabled: true,
|
|
133
|
+
isSelected: false
|
|
134
|
+
}), linkType === INLINES.ASSET_HYPERLINK && React.createElement(FetchingWrappedAssetCard, {
|
|
135
|
+
sdk: props.sdk,
|
|
136
|
+
locale: props.sdk.field.locale,
|
|
137
|
+
assetId: linkEntity.sys.id,
|
|
138
|
+
isDisabled: true,
|
|
139
|
+
isSelected: false
|
|
140
|
+
}))) : React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && React.createElement(TextLink, {
|
|
141
|
+
testId: "entity-selection-link",
|
|
142
|
+
onClick: selectEntry
|
|
143
|
+
}, "Select entry"), linkType === INLINES.ASSET_HYPERLINK && React.createElement(TextLink, {
|
|
144
|
+
testId: "entity-selection-link",
|
|
145
|
+
onClick: selectAsset
|
|
146
|
+
}, "Select asset"))))), React.createElement(ModalControls, null, React.createElement(Button, {
|
|
147
|
+
type: "button",
|
|
148
|
+
onClick: ()=>props.onClose(null),
|
|
149
|
+
variant: "secondary",
|
|
150
|
+
testId: "cancel-cta",
|
|
151
|
+
size: "small"
|
|
152
|
+
}, "Cancel"), React.createElement(Button, {
|
|
153
|
+
type: "submit",
|
|
154
|
+
variant: "positive",
|
|
155
|
+
size: "small",
|
|
156
|
+
isDisabled: props.readonly || !isLinkComplete(),
|
|
157
|
+
onClick: handleOnSubmit,
|
|
158
|
+
testId: "confirm-cta"
|
|
159
|
+
}, props.linkType ? 'Update' : 'Insert'))));
|
|
160
|
+
}
|
|
161
|
+
export async function addOrEditLink(editor, sdk, logAction, targetPath) {
|
|
162
|
+
const isReadOnly = isEditorReadOnly(editor);
|
|
163
|
+
const selectionBeforeBlur = editor.selection ? {
|
|
164
|
+
...editor.selection
|
|
165
|
+
} : undefined;
|
|
166
|
+
if (!targetPath && !selectionBeforeBlur) return;
|
|
167
|
+
let linkType;
|
|
168
|
+
let linkText;
|
|
169
|
+
let linkTarget;
|
|
170
|
+
let linkEntity;
|
|
171
|
+
const [node, path] = getNodeEntryFromSelection(editor, LINK_TYPES, targetPath);
|
|
172
|
+
if (node && path) {
|
|
173
|
+
linkType = node.type;
|
|
174
|
+
linkText = getText(editor, path);
|
|
175
|
+
linkTarget = node.data.uri || '';
|
|
176
|
+
linkEntity = node.data.target;
|
|
177
|
+
}
|
|
178
|
+
const selectionAfterFocus = targetPath ?? selectionBeforeBlur;
|
|
179
|
+
const currentLinkText = linkText || (editor.selection ? getText(editor, editor.selection) : '');
|
|
180
|
+
const isEditing = Boolean(node && path);
|
|
181
|
+
logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
|
|
182
|
+
const data = await ModalDialogLauncher.openDialog({
|
|
183
|
+
title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
|
|
184
|
+
width: 'large',
|
|
185
|
+
shouldCloseOnEscapePress: true,
|
|
186
|
+
shouldCloseOnOverlayClick: true,
|
|
187
|
+
allowHeightOverflow: true
|
|
188
|
+
}, ({ onClose })=>{
|
|
189
|
+
return React.createElement(HyperlinkModal, {
|
|
190
|
+
linkTarget: linkTarget,
|
|
191
|
+
linkText: currentLinkText,
|
|
192
|
+
linkType: linkType,
|
|
193
|
+
linkEntity: linkEntity,
|
|
194
|
+
onClose: onClose,
|
|
195
|
+
sdk: sdk,
|
|
196
|
+
readonly: isReadOnly
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
select(editor, selectionAfterFocus);
|
|
200
|
+
if (!data) {
|
|
201
|
+
focus(editor);
|
|
202
|
+
logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const { linkText: text , linkTarget: url , linkType: type , linkEntity: target } = data;
|
|
206
|
+
withoutNormalizing(editor, ()=>{
|
|
207
|
+
insertLink(editor, {
|
|
208
|
+
text,
|
|
209
|
+
url,
|
|
210
|
+
type,
|
|
211
|
+
target,
|
|
212
|
+
path
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
logAction(isEditing ? 'edit' : 'insert', {
|
|
216
|
+
nodeType: type,
|
|
217
|
+
linkType: target?.sys.linkType ?? 'uri'
|
|
218
|
+
});
|
|
219
|
+
focus(editor);
|
|
220
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assertOutput, jsx } from '../../../test-utils';
|
|
2
|
+
describe('normalization', ()=>{
|
|
3
|
+
it('removes empty links from the document structure', ()=>{
|
|
4
|
+
const input = jsx("editor", null, jsx("hp", null, jsx("htext", null, "link"), jsx("hlink", {
|
|
5
|
+
uri: "https://link.com"
|
|
6
|
+
})), jsx("hp", null, jsx("htext", null, "asset"), jsx("hlink", {
|
|
7
|
+
asset: "asset-id"
|
|
8
|
+
})), jsx("hp", null, jsx("htext", null, "entry"), jsx("hlink", {
|
|
9
|
+
entry: "entry-id"
|
|
10
|
+
})), jsx("hp", null, jsx("htext", null, "explicit empty link"), jsx("hlink", {
|
|
11
|
+
uri: "https://link.com"
|
|
12
|
+
}, '')), jsx("hp", null, jsx("htext", null, "link with empty space"), jsx("hlink", {
|
|
13
|
+
uri: "https://link.com"
|
|
14
|
+
}, " ")));
|
|
15
|
+
const expected = jsx("editor", null, jsx("hp", null, jsx("htext", null, "link")), jsx("hp", null, jsx("htext", null, "asset")), jsx("hp", null, jsx("htext", null, "entry")), jsx("hp", null, jsx("htext", null, "explicit empty link")), jsx("hp", null, jsx("htext", null, "link with empty space")));
|
|
16
|
+
assertOutput({
|
|
17
|
+
input,
|
|
18
|
+
expected
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Tooltip, TextLink } from '@contentful/f36-components';
|
|
3
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
+
import { fromDOMPoint } from '../../../internal';
|
|
5
|
+
import { useSdkContext } from '../../../SdkProvider';
|
|
6
|
+
import { addOrEditLink } from '../HyperlinkModal';
|
|
7
|
+
import { useEntityInfo } from '../useEntityInfo';
|
|
8
|
+
import { styles } from './styles';
|
|
9
|
+
export function EntityHyperlink(props) {
|
|
10
|
+
const editor = useContentfulEditor();
|
|
11
|
+
const sdk = useSdkContext();
|
|
12
|
+
const { target } = props.element.data;
|
|
13
|
+
const { onEntityFetchComplete } = props;
|
|
14
|
+
const tooltipContent = useEntityInfo({
|
|
15
|
+
target,
|
|
16
|
+
sdk,
|
|
17
|
+
onEntityFetchComplete
|
|
18
|
+
});
|
|
19
|
+
if (!target) return null;
|
|
20
|
+
function handleClick(event) {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
if (!editor) return;
|
|
24
|
+
const p = fromDOMPoint(editor, [
|
|
25
|
+
event.target,
|
|
26
|
+
0
|
|
27
|
+
]);
|
|
28
|
+
if (p) {
|
|
29
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return React.createElement(Tooltip, {
|
|
33
|
+
content: tooltipContent,
|
|
34
|
+
targetWrapperClassName: styles.hyperlinkWrapper,
|
|
35
|
+
placement: "bottom",
|
|
36
|
+
maxWidth: "auto"
|
|
37
|
+
}, React.createElement(TextLink, {
|
|
38
|
+
as: "a",
|
|
39
|
+
onClick: handleClick,
|
|
40
|
+
className: styles.hyperlink,
|
|
41
|
+
"data-link-type": target.sys.linkType,
|
|
42
|
+
"data-link-id": target.sys.id
|
|
43
|
+
}, props.children));
|
|
44
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LinkIcon } from '@contentful/f36-icons';
|
|
3
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
+
import { isLinkActive, unwrapLink } from '../../../helpers/editor';
|
|
5
|
+
import { useSdkContext } from '../../../SdkProvider';
|
|
6
|
+
import { ToolbarButton } from '../../shared/ToolbarButton';
|
|
7
|
+
import { addOrEditLink } from '../HyperlinkModal';
|
|
8
|
+
export function ToolbarHyperlinkButton(props) {
|
|
9
|
+
const editor = useContentfulEditor();
|
|
10
|
+
const isActive = !!(editor && isLinkActive(editor));
|
|
11
|
+
const sdk = useSdkContext();
|
|
12
|
+
async function handleClick() {
|
|
13
|
+
if (!editor) return;
|
|
14
|
+
if (isActive) {
|
|
15
|
+
unwrapLink(editor);
|
|
16
|
+
editor.tracking.onToolbarAction('unlinkHyperlinks');
|
|
17
|
+
} else {
|
|
18
|
+
addOrEditLink(editor, sdk, editor.tracking.onToolbarAction);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!editor) return null;
|
|
22
|
+
return React.createElement(ToolbarButton, {
|
|
23
|
+
title: "Hyperlink",
|
|
24
|
+
testId: "hyperlink-toolbar-button",
|
|
25
|
+
onClick: handleClick,
|
|
26
|
+
isActive: isActive,
|
|
27
|
+
isDisabled: props.isDisabled
|
|
28
|
+
}, React.createElement(LinkIcon, null));
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Tooltip, TextLink } from '@contentful/f36-components';
|
|
3
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
+
import { fromDOMPoint } from '../../../internal';
|
|
5
|
+
import { useSdkContext } from '../../../SdkProvider';
|
|
6
|
+
import { addOrEditLink } from '../HyperlinkModal';
|
|
7
|
+
import { styles } from './styles';
|
|
8
|
+
export function UrlHyperlink(props) {
|
|
9
|
+
const editor = useContentfulEditor();
|
|
10
|
+
const sdk = useSdkContext();
|
|
11
|
+
const { uri } = props.element.data;
|
|
12
|
+
function handleClick(event) {
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
event.stopPropagation();
|
|
15
|
+
if (!editor) return;
|
|
16
|
+
const p = fromDOMPoint(editor, [
|
|
17
|
+
event.target,
|
|
18
|
+
0
|
|
19
|
+
], {
|
|
20
|
+
exactMatch: false,
|
|
21
|
+
suppressThrow: false
|
|
22
|
+
});
|
|
23
|
+
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p?.path);
|
|
24
|
+
}
|
|
25
|
+
return React.createElement(Tooltip, {
|
|
26
|
+
content: uri,
|
|
27
|
+
targetWrapperClassName: styles.hyperlinkWrapper,
|
|
28
|
+
placement: "bottom",
|
|
29
|
+
maxWidth: "auto"
|
|
30
|
+
}, React.createElement(TextLink, {
|
|
31
|
+
as: "a",
|
|
32
|
+
href: uri,
|
|
33
|
+
rel: "noopener noreferrer",
|
|
34
|
+
onClick: handleClick,
|
|
35
|
+
className: styles.hyperlink
|
|
36
|
+
}, props.children));
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import tokens from '@contentful/f36-tokens';
|
|
2
|
+
import { css } from 'emotion';
|
|
3
|
+
export const styles = {
|
|
4
|
+
hyperlinkWrapper: css({
|
|
5
|
+
display: 'inline',
|
|
6
|
+
position: 'static',
|
|
7
|
+
a: {
|
|
8
|
+
fontSize: 'inherit !important'
|
|
9
|
+
}
|
|
10
|
+
}),
|
|
11
|
+
hyperlink: css({
|
|
12
|
+
fontSize: 'inherit !important',
|
|
13
|
+
display: 'inline !important',
|
|
14
|
+
'&:hover': {
|
|
15
|
+
fill: tokens.gray900
|
|
16
|
+
},
|
|
17
|
+
'&:focus': {
|
|
18
|
+
fill: tokens.gray900
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { INLINES } from '@contentful/rich-text-types';
|
|
3
|
+
import isHotkey from 'is-hotkey';
|
|
4
|
+
import { isLinkActive, unwrapLink } from '../../helpers/editor';
|
|
5
|
+
import { transformRemove } from '../../helpers/transformers';
|
|
6
|
+
import { withLinkTracking } from '../links-tracking';
|
|
7
|
+
import { EntityHyperlink } from './components/EntityHyperlink';
|
|
8
|
+
import { UrlHyperlink } from './components/UrlHyperlink';
|
|
9
|
+
import { addOrEditLink } from './HyperlinkModal';
|
|
10
|
+
import { hasText } from './utils';
|
|
11
|
+
const isAnchor = (element)=>element.nodeName === 'A' && !!element.getAttribute('href') && element.getAttribute('href') !== '#';
|
|
12
|
+
const isEntryAnchor = (element)=>element.nodeName === 'A' && element.getAttribute('data-link-type') === 'Entry';
|
|
13
|
+
const isAssetAnchor = (element)=>element.nodeName === 'A' && element.getAttribute('data-link-type') === 'Asset';
|
|
14
|
+
const buildHyperlinkEventHandler = (sdk)=>(editor, { options: { hotkey } })=>{
|
|
15
|
+
return (event)=>{
|
|
16
|
+
if (!editor.selection) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (hotkey && !isHotkey(hotkey, event)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (isLinkActive(editor)) {
|
|
23
|
+
unwrapLink(editor);
|
|
24
|
+
editor.tracking.onShortcutAction('unlinkHyperlinks');
|
|
25
|
+
} else {
|
|
26
|
+
addOrEditLink(editor, sdk, editor.tracking.onShortcutAction);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const getNodeOfType = (type)=>(el, node)=>({
|
|
31
|
+
type,
|
|
32
|
+
children: node.children,
|
|
33
|
+
data: type === INLINES.HYPERLINK ? {
|
|
34
|
+
uri: el.getAttribute('href')
|
|
35
|
+
} : {
|
|
36
|
+
target: {
|
|
37
|
+
sys: {
|
|
38
|
+
id: el.getAttribute('data-link-id'),
|
|
39
|
+
linkType: el.getAttribute('data-link-type'),
|
|
40
|
+
type: 'Link'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export const createHyperlinkPlugin = (sdk)=>{
|
|
46
|
+
const common = {
|
|
47
|
+
isElement: true,
|
|
48
|
+
isInline: true
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
key: 'HyperlinkPlugin',
|
|
52
|
+
options: {
|
|
53
|
+
hotkey: 'mod+k'
|
|
54
|
+
},
|
|
55
|
+
handlers: {
|
|
56
|
+
onKeyDown: buildHyperlinkEventHandler(sdk)
|
|
57
|
+
},
|
|
58
|
+
plugins: [
|
|
59
|
+
{
|
|
60
|
+
...common,
|
|
61
|
+
key: INLINES.HYPERLINK,
|
|
62
|
+
type: INLINES.HYPERLINK,
|
|
63
|
+
component: UrlHyperlink,
|
|
64
|
+
deserializeHtml: {
|
|
65
|
+
rules: [
|
|
66
|
+
{
|
|
67
|
+
validNodeName: [
|
|
68
|
+
'A'
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
query: (el)=>isAnchor(el) && !(isEntryAnchor(el) || isAssetAnchor(el)),
|
|
73
|
+
getNode: getNodeOfType(INLINES.HYPERLINK)
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
...common,
|
|
78
|
+
key: INLINES.ENTRY_HYPERLINK,
|
|
79
|
+
type: INLINES.ENTRY_HYPERLINK,
|
|
80
|
+
component: withLinkTracking(EntityHyperlink),
|
|
81
|
+
deserializeHtml: {
|
|
82
|
+
rules: [
|
|
83
|
+
{
|
|
84
|
+
validNodeName: [
|
|
85
|
+
'A'
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
query: (el)=>isEntryAnchor(el),
|
|
90
|
+
getNode: getNodeOfType(INLINES.ENTRY_HYPERLINK)
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
...common,
|
|
95
|
+
key: INLINES.ASSET_HYPERLINK,
|
|
96
|
+
type: INLINES.ASSET_HYPERLINK,
|
|
97
|
+
component: withLinkTracking(EntityHyperlink),
|
|
98
|
+
deserializeHtml: {
|
|
99
|
+
rules: [
|
|
100
|
+
{
|
|
101
|
+
validNodeName: [
|
|
102
|
+
'A'
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
query: (el)=>isAssetAnchor(el),
|
|
107
|
+
getNode: getNodeOfType(INLINES.ASSET_HYPERLINK)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
normalizer: [
|
|
112
|
+
{
|
|
113
|
+
match: {
|
|
114
|
+
type: [
|
|
115
|
+
INLINES.HYPERLINK,
|
|
116
|
+
INLINES.ASSET_HYPERLINK,
|
|
117
|
+
INLINES.ENTRY_HYPERLINK
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
validNode: hasText,
|
|
121
|
+
transform: transformRemove
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
};
|