@contentful/field-editor-rich-text 3.16.8 → 3.16.10
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 +8 -8
- package/dist/cjs/RichTextEditor.js +20 -22
- package/dist/cjs/RichTextEditor.styles.js +1 -2
- package/dist/cjs/SdkProvider.js +5 -7
- package/dist/cjs/SyncEditorChanges.js +6 -15
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +15 -17
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +9 -13
- package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +8 -10
- package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +2 -2
- package/dist/cjs/Toolbar/index.js +30 -33
- package/dist/cjs/__fixtures__/FakeSdk.js +3 -3
- package/dist/cjs/__fixtures__/asset/index.js +10 -10
- package/dist/cjs/__fixtures__/content-type/index.js +1 -1
- package/dist/cjs/__fixtures__/entry/index.js +7 -7
- package/dist/cjs/__fixtures__/fixtures.js +6 -8
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/constants/Schema.js +0 -1
- package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +38 -43
- package/dist/cjs/dialogs/openRichTextDialog.js +4 -6
- package/dist/cjs/dialogs/renderRichTextDialog.js +4 -6
- package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +10 -10
- package/dist/cjs/helpers/callbacks.js +3 -3
- package/dist/cjs/helpers/config.js +2 -2
- package/dist/cjs/helpers/editor.js +44 -53
- package/dist/cjs/helpers/environment.js +3 -3
- package/dist/cjs/helpers/formatDateAndTime.js +4 -5
- package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +5 -22
- package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +5 -29
- package/dist/cjs/helpers/nodeFactory.js +6 -6
- package/dist/cjs/helpers/sdkNavigatorSlideIn.js +6 -14
- package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +2 -3
- package/dist/cjs/helpers/toSlateValue.js +3 -14
- package/dist/cjs/helpers/transformers.js +5 -5
- package/dist/cjs/helpers/validations.js +9 -12
- package/dist/cjs/index.js +5 -7
- package/dist/cjs/internal/constants.js +2 -4
- package/dist/cjs/internal/hooks.js +7 -9
- package/dist/cjs/internal/misc.js +12 -15
- package/dist/cjs/internal/queries.js +108 -115
- package/dist/cjs/internal/transforms.js +48 -51
- package/dist/cjs/internal/types/editor.js +1 -3
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +3 -4
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +0 -1
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +3 -3
- package/dist/cjs/plugins/CommandPalette/components/CommandList.js +33 -35
- package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +1 -1
- package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +5 -7
- package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +3 -7
- package/dist/cjs/plugins/CommandPalette/onKeyDown.js +1 -6
- package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +4 -6
- package/dist/cjs/plugins/CommandPalette/useCommands.js +3 -3
- package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +0 -2
- package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +1 -6
- package/dist/cjs/plugins/DragAndDrop/index.js +1 -9
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +8 -10
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -3
- package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +17 -19
- package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +7 -9
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +5 -5
- package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +11 -13
- package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +5 -5
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
- package/dist/cjs/plugins/Heading/components/Heading.js +10 -13
- package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +29 -23
- package/dist/cjs/plugins/Heading/createHeadingPlugin.js +2 -7
- package/dist/cjs/plugins/Hr/index.js +14 -19
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +28 -32
- package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +8 -10
- package/dist/cjs/plugins/Hyperlink/components/LinkPopover.js +17 -23
- package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +8 -10
- package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +4 -6
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +6 -8
- package/dist/cjs/plugins/Hyperlink/components/linkHandlers.js +3 -3
- package/dist/cjs/plugins/Hyperlink/components/styles.js +1 -1
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +4 -10
- package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +3 -6
- package/dist/cjs/plugins/Hyperlink/useResourceEntityInfo.js +4 -6
- package/dist/cjs/plugins/Hyperlink/utils.js +4 -4
- package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +13 -13
- package/dist/cjs/plugins/List/__tests__/insertListBreak.test.js +25 -29
- package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +22 -22
- package/dist/cjs/plugins/List/components/List.js +7 -9
- package/dist/cjs/plugins/List/components/ListItem.js +4 -6
- package/dist/cjs/plugins/List/components/ToolbarListButton.js +5 -7
- package/dist/cjs/plugins/List/createListPlugin.js +0 -4
- package/dist/cjs/plugins/List/insertListBreak.js +4 -13
- package/dist/cjs/plugins/List/insertListFragment.js +5 -18
- package/dist/cjs/plugins/List/onKeyDownList.js +6 -8
- package/dist/cjs/plugins/List/transforms/insertListItem.js +2 -17
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +2 -8
- package/dist/cjs/plugins/List/transforms/moveListItems.js +2 -7
- package/dist/cjs/plugins/List/transforms/moveListItems.test.js +14 -15
- package/dist/cjs/plugins/List/transforms/toggleList.js +3 -8
- package/dist/cjs/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/cjs/plugins/List/transforms/unwrapList.js +2 -7
- package/dist/cjs/plugins/List/utils.js +11 -12
- package/dist/cjs/plugins/List/withList.js +2 -6
- package/dist/cjs/plugins/Marks/Bold.js +7 -9
- package/dist/cjs/plugins/Marks/Code.js +7 -15
- package/dist/cjs/plugins/Marks/Italic.js +7 -9
- package/dist/cjs/plugins/Marks/Subscript.js +8 -10
- package/dist/cjs/plugins/Marks/Superscript.js +8 -10
- package/dist/cjs/plugins/Marks/Underline.js +4 -6
- package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +7 -9
- package/dist/cjs/plugins/Marks/helpers.js +5 -5
- package/dist/cjs/plugins/Normalizer/baseRules.js +0 -2
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/cjs/plugins/Normalizer/utils.js +3 -4
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +3 -23
- package/dist/cjs/plugins/Paragraph/Paragraph.js +4 -6
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +2 -3
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +6 -9
- package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +0 -2
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +0 -9
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +2 -17
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +1 -13
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
- package/dist/cjs/plugins/Quote/components/Quote.js +4 -6
- package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +4 -6
- package/dist/cjs/plugins/Quote/createQuotePlugin.js +0 -1
- package/dist/cjs/plugins/Quote/toggleQuote.js +5 -5
- package/dist/cjs/plugins/Quote/withQuote.js +2 -4
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +0 -1
- package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
- package/dist/cjs/plugins/Table/__tests__/helpers.test.js +4 -4
- package/dist/cjs/plugins/Table/actions/addColumn.js +4 -5
- package/dist/cjs/plugins/Table/actions/addRow.js +3 -6
- package/dist/cjs/plugins/Table/components/Cell.js +5 -7
- package/dist/cjs/plugins/Table/components/HeaderCell.js +5 -7
- package/dist/cjs/plugins/Table/components/Row.js +4 -6
- package/dist/cjs/plugins/Table/components/Table.js +6 -8
- package/dist/cjs/plugins/Table/components/TableActions.js +16 -19
- package/dist/cjs/plugins/Table/components/ToolbarButton.js +4 -7
- package/dist/cjs/plugins/Table/createTablePlugin.js +1 -11
- package/dist/cjs/plugins/Table/helpers.js +12 -16
- package/dist/cjs/plugins/Table/insertTableFragment.js +2 -15
- package/dist/cjs/plugins/Table/onKeyDownTable.js +2 -11
- package/dist/cjs/plugins/Table/tableTracking.js +6 -6
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +17 -19
- package/dist/cjs/plugins/Text/createTextPlugin.js +5 -22
- package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +4 -5
- package/dist/cjs/plugins/Tracking/utils.js +3 -6
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +0 -5
- package/dist/cjs/plugins/Voids/transformVoid.js +0 -1
- package/dist/cjs/plugins/index.js +3 -15
- package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +10 -12
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +6 -16
- package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +8 -10
- package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +5 -9
- package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +11 -13
- package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +12 -14
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +11 -14
- package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +4 -8
- package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +6 -10
- package/dist/cjs/plugins/shared/ResourceNewBadge.js +3 -5
- package/dist/cjs/plugins/shared/ToolbarButton.js +6 -8
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +5 -10
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +6 -11
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +13 -15
- package/dist/cjs/plugins/shared/utils.js +1 -4
- package/dist/cjs/test-utils/assertOutput.js +0 -1
- package/dist/cjs/test-utils/hyperscript.d.js +0 -1
- package/dist/cjs/test-utils/randomId.js +1 -3
- package/dist/cjs/test-utils/validation.js +5 -8
- package/dist/esm/ContentfulEditorProvider.js +1 -4
- package/dist/esm/RichTextEditor.js +13 -13
- package/dist/esm/RichTextEditor.styles.js +0 -1
- package/dist/esm/SdkProvider.js +2 -2
- package/dist/esm/SyncEditorChanges.js +3 -18
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +12 -12
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +7 -9
- package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +6 -6
- package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +1 -1
- package/dist/esm/Toolbar/index.js +27 -28
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/constants/Schema.js +0 -1
- package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +31 -34
- package/dist/esm/dialogs/openRichTextDialog.js +2 -2
- package/dist/esm/dialogs/renderRichTextDialog.js +2 -2
- package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +10 -10
- package/dist/esm/helpers/callbacks.js +1 -1
- package/dist/esm/helpers/config.js +1 -9
- package/dist/esm/helpers/editor.js +6 -22
- package/dist/esm/helpers/extractNodes.js +1 -3
- package/dist/esm/helpers/formatDateAndTime.js +2 -11
- package/dist/esm/helpers/getAllowedResourcesForNodeType.js +2 -19
- package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +2 -26
- package/dist/esm/helpers/sdkNavigatorSlideIn.js +6 -20
- package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +0 -1
- package/dist/esm/helpers/toSlateValue.js +3 -17
- package/dist/esm/helpers/validations.js +1 -5
- package/dist/esm/internal/misc.js +2 -23
- package/dist/esm/internal/queries.js +2 -11
- package/dist/esm/internal/transforms.js +3 -14
- package/dist/esm/internal/types/editor.js +1 -3
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +3 -4
- package/dist/esm/plugins/Break/createResetNodePlugin.js +0 -1
- package/dist/esm/plugins/Break/createSoftBreakPlugin.test.js +3 -3
- package/dist/esm/plugins/CommandPalette/components/CommandList.js +30 -30
- package/dist/esm/plugins/CommandPalette/components/CommandPrompt.js +2 -2
- package/dist/esm/plugins/CommandPalette/createCommandPalettePlugin.js +1 -11
- package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +0 -2
- package/dist/esm/plugins/CommandPalette/onKeyDown.js +0 -5
- package/dist/esm/plugins/CommandPalette/onKeyDown.spec.js +2 -2
- package/dist/esm/plugins/CommandPalette/useCommands.js +3 -3
- package/dist/esm/plugins/CommandPalette/utils/fetchEntries.js +0 -2
- package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +1 -6
- package/dist/esm/plugins/DragAndDrop/index.js +1 -9
- package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +6 -6
- package/dist/esm/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +14 -14
- package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +5 -5
- package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +4 -4
- package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +9 -9
- package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +4 -4
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +32 -32
- package/dist/esm/plugins/Heading/components/Heading.js +7 -8
- package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +26 -18
- package/dist/esm/plugins/Heading/createHeadingPlugin.js +1 -6
- package/dist/esm/plugins/Hr/index.js +5 -8
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +23 -25
- package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +6 -6
- package/dist/esm/plugins/Hyperlink/components/LinkPopover.js +15 -19
- package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +6 -6
- package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +2 -2
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +4 -4
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +1 -5
- package/dist/esm/plugins/Hyperlink/useEntityInfo.js +3 -6
- package/dist/esm/plugins/Hyperlink/useResourceEntityInfo.js +2 -2
- package/dist/esm/plugins/Hyperlink/utils.js +1 -1
- package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +13 -13
- package/dist/esm/plugins/List/__tests__/insertListBreak.test.js +25 -29
- package/dist/esm/plugins/List/__tests__/insertListFragment.test.js +22 -22
- package/dist/esm/plugins/List/components/List.js +1 -1
- package/dist/esm/plugins/List/components/ListItem.js +1 -1
- package/dist/esm/plugins/List/components/ToolbarListButton.js +3 -3
- package/dist/esm/plugins/List/createListPlugin.js +0 -4
- package/dist/esm/plugins/List/insertListBreak.js +4 -13
- package/dist/esm/plugins/List/insertListFragment.js +5 -18
- package/dist/esm/plugins/List/onKeyDownList.js +5 -7
- package/dist/esm/plugins/List/transforms/insertListItem.js +3 -20
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +2 -8
- package/dist/esm/plugins/List/transforms/moveListItems.js +2 -7
- package/dist/esm/plugins/List/transforms/moveListItems.test.js +14 -15
- package/dist/esm/plugins/List/transforms/toggleList.js +3 -8
- package/dist/esm/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/esm/plugins/List/transforms/unwrapList.js +2 -7
- package/dist/esm/plugins/List/utils.js +2 -7
- package/dist/esm/plugins/List/withList.js +2 -6
- package/dist/esm/plugins/Marks/Bold.js +2 -2
- package/dist/esm/plugins/Marks/Code.js +2 -8
- package/dist/esm/plugins/Marks/Italic.js +2 -2
- package/dist/esm/plugins/Marks/Subscript.js +2 -2
- package/dist/esm/plugins/Marks/Superscript.js +2 -2
- package/dist/esm/plugins/Marks/Underline.js +2 -2
- package/dist/esm/plugins/Marks/components/MarkToolbarButton.js +4 -4
- package/dist/esm/plugins/Marks/helpers.js +1 -1
- package/dist/esm/plugins/Normalizer/baseRules.js +0 -4
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/esm/plugins/Normalizer/utils.js +0 -1
- package/dist/esm/plugins/Normalizer/withNormalizer.js +2 -22
- package/dist/esm/plugins/Paragraph/Paragraph.js +1 -1
- package/dist/esm/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
- package/dist/esm/plugins/Paragraph/createParagraphPlugin.js +1 -2
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +3 -9
- package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +0 -2
- package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +1 -27
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +2 -17
- package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +1 -13
- package/dist/esm/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
- package/dist/esm/plugins/Quote/components/Quote.js +1 -1
- package/dist/esm/plugins/Quote/components/ToolbarQuoteButton.js +2 -2
- package/dist/esm/plugins/Quote/createQuotePlugin.js +0 -1
- package/dist/esm/plugins/Quote/shouldResetQuote.js +1 -6
- package/dist/esm/plugins/Quote/toggleQuote.js +1 -1
- package/dist/esm/plugins/Quote/withQuote.js +2 -4
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +0 -1
- package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +22 -22
- package/dist/esm/plugins/Table/__tests__/helpers.test.js +4 -4
- package/dist/esm/plugins/Table/actions/addColumn.js +1 -2
- package/dist/esm/plugins/Table/actions/addRow.js +0 -3
- package/dist/esm/plugins/Table/components/Cell.js +2 -2
- package/dist/esm/plugins/Table/components/HeaderCell.js +2 -2
- package/dist/esm/plugins/Table/components/Row.js +1 -1
- package/dist/esm/plugins/Table/components/Table.js +3 -3
- package/dist/esm/plugins/Table/components/TableActions.js +11 -12
- package/dist/esm/plugins/Table/components/ToolbarButton.js +2 -3
- package/dist/esm/plugins/Table/createTablePlugin.js +1 -11
- package/dist/esm/plugins/Table/helpers.js +1 -10
- package/dist/esm/plugins/Table/insertTableFragment.js +2 -15
- package/dist/esm/plugins/Table/onKeyDownTable.js +2 -11
- package/dist/esm/plugins/Table/tableTracking.js +6 -6
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +17 -19
- package/dist/esm/plugins/Text/createTextPlugin.js +5 -22
- package/dist/esm/plugins/Tracking/createTrackingPlugin.js +1 -2
- package/dist/esm/plugins/Tracking/utils.js +0 -1
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +0 -5
- package/dist/esm/plugins/Voids/transformVoid.js +1 -4
- package/dist/esm/plugins/index.js +0 -12
- package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +5 -15
- package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +4 -8
- package/dist/esm/plugins/shared/FetchingWrappedAssetCard.js +8 -8
- package/dist/esm/plugins/shared/FetchingWrappedEntryCard.js +9 -9
- package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +8 -9
- package/dist/esm/plugins/shared/LinkedBlockWrapper.js +3 -7
- package/dist/esm/plugins/shared/LinkedInlineWrapper.js +3 -5
- package/dist/esm/plugins/shared/ResourceNewBadge.js +1 -1
- package/dist/esm/plugins/shared/ToolbarButton.js +3 -3
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +2 -5
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +2 -5
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +8 -8
- package/dist/esm/plugins/shared/utils.js +1 -4
- package/dist/esm/test-utils/assertOutput.js +0 -1
- package/dist/esm/test-utils/hyperscript.d.js +0 -1
- package/dist/esm/test-utils/jsx.js +1 -5
- package/dist/esm/test-utils/randomId.js +1 -3
- package/dist/esm/test-utils/setEmptyDataAttribute.js +1 -4
- package/dist/esm/test-utils/validation.js +4 -7
- package/dist/types/RichTextEditor.d.ts +2 -3
- package/dist/types/Toolbar/components/EmbedEntityWidget.d.ts +1 -2
- package/dist/types/Toolbar/components/EmbeddedEntityDropdownButton.d.ts +1 -1
- package/dist/types/Toolbar/components/StickyToolbarWrapper.d.ts +2 -2
- package/dist/types/Toolbar/index.d.ts +1 -2
- package/dist/types/dialogs/HypelinkDialog/HyperlinkDialog.d.ts +4 -4
- package/dist/types/dialogs/renderRichTextDialog.d.ts +1 -2
- package/dist/types/plugins/CommandPalette/components/CommandList.d.ts +1 -2
- package/dist/types/plugins/CommandPalette/components/CommandPrompt.d.ts +1 -2
- package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +1 -2
- package/dist/types/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.d.ts +1 -1
- package/dist/types/plugins/EmbeddedEntityInline/LinkedEntityInline.d.ts +1 -2
- package/dist/types/plugins/EmbeddedResourceBlock/LinkedResourceBlock.d.ts +1 -2
- package/dist/types/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.d.ts +1 -1
- package/dist/types/plugins/EmbeddedResourceInline/LinkedResourceInline.d.ts +1 -2
- package/dist/types/plugins/Heading/components/Heading.d.ts +6 -6
- package/dist/types/plugins/Heading/components/ToolbarHeadingButton.d.ts +1 -2
- package/dist/types/plugins/Hr/index.d.ts +2 -2
- package/dist/types/plugins/Hyperlink/HyperlinkModal.d.ts +1 -2
- package/dist/types/plugins/Hyperlink/components/EntityHyperlink.d.ts +1 -2
- package/dist/types/plugins/Hyperlink/components/LinkPopover.d.ts +1 -1
- package/dist/types/plugins/Hyperlink/components/ResourceHyperlink.d.ts +1 -2
- package/dist/types/plugins/Hyperlink/components/ToolbarHyperlinkButton.d.ts +1 -2
- package/dist/types/plugins/Hyperlink/components/UrlHyperlink.d.ts +1 -2
- package/dist/types/plugins/List/components/List.d.ts +2 -3
- package/dist/types/plugins/List/components/ListItem.d.ts +1 -2
- package/dist/types/plugins/List/components/ToolbarListButton.d.ts +1 -2
- package/dist/types/plugins/Marks/Bold.d.ts +2 -3
- package/dist/types/plugins/Marks/Code.d.ts +3 -4
- package/dist/types/plugins/Marks/Italic.d.ts +2 -3
- package/dist/types/plugins/Marks/Subscript.d.ts +3 -4
- package/dist/types/plugins/Marks/Superscript.d.ts +3 -4
- package/dist/types/plugins/Marks/Underline.d.ts +2 -3
- package/dist/types/plugins/Marks/components/MarkToolbarButton.d.ts +1 -1
- package/dist/types/plugins/Paragraph/Paragraph.d.ts +1 -2
- package/dist/types/plugins/Quote/components/Quote.d.ts +1 -2
- package/dist/types/plugins/Quote/components/ToolbarQuoteButton.d.ts +1 -2
- package/dist/types/plugins/Table/components/Cell.d.ts +1 -2
- package/dist/types/plugins/Table/components/HeaderCell.d.ts +1 -2
- package/dist/types/plugins/Table/components/Row.d.ts +1 -2
- package/dist/types/plugins/Table/components/Table.d.ts +1 -2
- package/dist/types/plugins/Table/components/TableActions.d.ts +1 -2
- package/dist/types/plugins/Table/components/ToolbarButton.d.ts +1 -2
- package/dist/types/plugins/shared/EmbeddedBlockToolbarIcon.d.ts +1 -2
- package/dist/types/plugins/shared/EmbeddedInlineToolbarIcon.d.ts +1 -2
- package/dist/types/plugins/shared/FetchingWrappedAssetCard.d.ts +1 -2
- package/dist/types/plugins/shared/FetchingWrappedEntryCard.d.ts +1 -2
- package/dist/types/plugins/shared/FetchingWrappedResourceCard.d.ts +1 -2
- package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +1 -1
- package/dist/types/plugins/shared/LinkedInlineWrapper.d.ts +1 -1
- package/dist/types/plugins/shared/ResourceNewBadge.d.ts +1 -2
- package/dist/types/plugins/shared/ToolbarButton.d.ts +1 -2
- package/package.json +8 -5
|
@@ -28,7 +28,7 @@ function isFeaturingEntitySelector(entitySelectorConfigs = {}) {
|
|
|
28
28
|
return !!entitySelectorConfigs.Entry || !!entitySelectorConfigs.Asset;
|
|
29
29
|
}
|
|
30
30
|
function entityToLink(entity) {
|
|
31
|
-
const { id, type
|
|
31
|
+
const { id , type } = entity.sys;
|
|
32
32
|
return {
|
|
33
33
|
sys: {
|
|
34
34
|
id,
|
|
@@ -48,7 +48,7 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
48
48
|
}));
|
|
49
49
|
}
|
|
50
50
|
getValue() {
|
|
51
|
-
const { text, type, uri
|
|
51
|
+
const { text , type , uri } = this.state;
|
|
52
52
|
const value = {
|
|
53
53
|
type
|
|
54
54
|
};
|
|
@@ -63,7 +63,7 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
63
63
|
return value;
|
|
64
64
|
}
|
|
65
65
|
isLinkComplete() {
|
|
66
|
-
const { text, type, uri, target
|
|
66
|
+
const { text , type , uri , target } = this.getValue();
|
|
67
67
|
const requiresText = !this.props.hideText;
|
|
68
68
|
if (requiresText && !text) {
|
|
69
69
|
return false;
|
|
@@ -71,16 +71,16 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
71
71
|
return type === LINK_TYPES.URI && uri || target;
|
|
72
72
|
}
|
|
73
73
|
render() {
|
|
74
|
-
const { labels
|
|
75
|
-
return
|
|
74
|
+
const { labels } = this.props;
|
|
75
|
+
return React.createElement(EntityProvider, {
|
|
76
76
|
sdk: this.props.sdk
|
|
77
|
-
},
|
|
77
|
+
}, React.createElement(React.Fragment, null, React.createElement(ModalContent, null, this.renderFields()), React.createElement(ModalControls, null, React.createElement(Button, {
|
|
78
78
|
type: "button",
|
|
79
79
|
onClick: ()=>this.props.onClose(null),
|
|
80
80
|
variant: "secondary",
|
|
81
81
|
testId: "cancel-cta",
|
|
82
82
|
size: "small"
|
|
83
|
-
}, "Cancel"),
|
|
83
|
+
}, "Cancel"), React.createElement(Button, {
|
|
84
84
|
type: "submit",
|
|
85
85
|
variant: "positive",
|
|
86
86
|
onClick: this.handleSubmit,
|
|
@@ -90,40 +90,39 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
90
90
|
}, labels.confirm))));
|
|
91
91
|
}
|
|
92
92
|
renderFields() {
|
|
93
|
-
const { hideText, allowedHyperlinkTypes, entitySelectorConfigs
|
|
94
|
-
const { uri, text, type
|
|
93
|
+
const { hideText , allowedHyperlinkTypes , entitySelectorConfigs } = this.props;
|
|
94
|
+
const { uri , text , type } = this.state;
|
|
95
95
|
const isUriInputAutoFocused = type === LINK_TYPES.URI && (hideText || !!text);
|
|
96
|
-
return
|
|
96
|
+
return React.createElement(Form, null, hideText ? null : React.createElement(FormControl, {
|
|
97
97
|
id: "link-text",
|
|
98
98
|
isRequired: true
|
|
99
|
-
},
|
|
99
|
+
}, React.createElement(FormControl.Label, null, "Link text"), React.createElement(TextInput, {
|
|
100
100
|
testId: "link-text-input",
|
|
101
101
|
name: "link-text",
|
|
102
102
|
value: text || '',
|
|
103
103
|
onChange: (e)=>this.setState({
|
|
104
104
|
text: e.target.value
|
|
105
105
|
}),
|
|
106
|
-
// eslint-disable-next-line -- TODO: describe this disable jsx-a11y/no-autofocus
|
|
107
106
|
autoFocus: !isUriInputAutoFocused
|
|
108
|
-
})), isFeaturingEntitySelector(entitySelectorConfigs) &&
|
|
107
|
+
})), isFeaturingEntitySelector(entitySelectorConfigs) && React.createElement(FormControl, {
|
|
109
108
|
id: "link-type",
|
|
110
109
|
name: "link-type"
|
|
111
|
-
},
|
|
110
|
+
}, React.createElement(FormControl.Label, null, "Link type"), React.createElement(Select, {
|
|
112
111
|
value: type,
|
|
113
112
|
onChange: (e)=>this.setState({
|
|
114
113
|
type: e.target.value
|
|
115
114
|
}),
|
|
116
115
|
testId: "link-type-select"
|
|
117
|
-
}, allowedHyperlinkTypes.includes(LINK_TYPES.URI) || type === LINK_TYPES.URI ?
|
|
116
|
+
}, allowedHyperlinkTypes.includes(LINK_TYPES.URI) || type === LINK_TYPES.URI ? React.createElement(Select.Option, {
|
|
118
117
|
value: LINK_TYPES.URI
|
|
119
|
-
}, "URL") : null, allowedHyperlinkTypes.includes(LINK_TYPES.ENTRY) || type === LINK_TYPES.ENTRY ?
|
|
118
|
+
}, "URL") : null, allowedHyperlinkTypes.includes(LINK_TYPES.ENTRY) || type === LINK_TYPES.ENTRY ? React.createElement(Select.Option, {
|
|
120
119
|
value: LINK_TYPES.ENTRY
|
|
121
|
-
}, "Entry") : null, allowedHyperlinkTypes.includes(LINK_TYPES.ASSET) || type === LINK_TYPES.ASSET ?
|
|
120
|
+
}, "Entry") : null, allowedHyperlinkTypes.includes(LINK_TYPES.ASSET) || type === LINK_TYPES.ASSET ? React.createElement(Select.Option, {
|
|
122
121
|
value: LINK_TYPES.ASSET
|
|
123
|
-
}, "Asset") : null)), type === LINK_TYPES.URI ?
|
|
122
|
+
}, "Asset") : null)), type === LINK_TYPES.URI ? React.createElement(FormControl, {
|
|
124
123
|
id: "link-uri",
|
|
125
124
|
isRequired: true
|
|
126
|
-
},
|
|
125
|
+
}, React.createElement(FormControl.Label, null, "Link target"), React.createElement(TextInput, {
|
|
127
126
|
testId: "link-target-input",
|
|
128
127
|
name: "link-uri",
|
|
129
128
|
value: uri || '',
|
|
@@ -131,31 +130,30 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
131
130
|
onChange: (e)=>this.setState({
|
|
132
131
|
uri: e.target.value
|
|
133
132
|
}),
|
|
134
|
-
// eslint-disable-next-line -- TODO: describe this disable jsx-a11y/no-autofocus
|
|
135
133
|
autoFocus: isUriInputAutoFocused
|
|
136
|
-
}),
|
|
134
|
+
}), React.createElement(FormControl.HelpText, null, "A protocol may be required, e.g. https://")) : this.renderEntityField());
|
|
137
135
|
}
|
|
138
136
|
renderEntityField() {
|
|
139
|
-
const { type, entityLinks
|
|
137
|
+
const { type , entityLinks } = this.state;
|
|
140
138
|
const resetEntity = ()=>this.setTargetEntity(type, null);
|
|
141
139
|
const entityLink = entityLinks[type];
|
|
142
140
|
const isEntitySelectorVisible = !entityLink;
|
|
143
|
-
return
|
|
141
|
+
return React.createElement("div", null, React.createElement(FormLabel, {
|
|
144
142
|
required: true,
|
|
145
143
|
htmlFor: ""
|
|
146
|
-
}, "Link target"), !isEntitySelectorVisible &&
|
|
144
|
+
}, "Link target"), !isEntitySelectorVisible && React.createElement(TextLink, {
|
|
147
145
|
as: "button",
|
|
148
146
|
className: css({
|
|
149
147
|
marginLeft: tokens.spacingS
|
|
150
148
|
}),
|
|
151
149
|
onClick: resetEntity
|
|
152
|
-
}, "Remove selection"), entityLink &&
|
|
150
|
+
}, "Remove selection"), entityLink && React.createElement("div", null, type === LINK_TYPES.ENTRY && React.createElement(FetchingWrappedEntryCard, {
|
|
153
151
|
sdk: this.props.sdk,
|
|
154
152
|
locale: this.props.entitySelectorConfigs.Entry.locale,
|
|
155
153
|
entryId: entityLink.sys.id,
|
|
156
154
|
isDisabled: true,
|
|
157
155
|
isSelected: false
|
|
158
|
-
}), type == LINK_TYPES.ASSET &&
|
|
156
|
+
}), type == LINK_TYPES.ASSET && React.createElement(FetchingWrappedAssetCard, {
|
|
159
157
|
sdk: this.props.sdk,
|
|
160
158
|
locale: this.props.entitySelectorConfigs.Asset.locale,
|
|
161
159
|
assetId: entityLink.sys.id,
|
|
@@ -164,14 +162,14 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
164
162
|
})), isEntitySelectorVisible && this.renderEntitySelector(type, isEntitySelectorVisible));
|
|
165
163
|
}
|
|
166
164
|
renderEntitySelector(type) {
|
|
167
|
-
return
|
|
165
|
+
return React.createElement("div", {
|
|
168
166
|
className: css({
|
|
169
167
|
marginTop: tokens.spacingS
|
|
170
168
|
})
|
|
171
|
-
}, type === LINK_TYPES.ENTRY &&
|
|
169
|
+
}, type === LINK_TYPES.ENTRY && React.createElement(TextLink, {
|
|
172
170
|
as: "button",
|
|
173
171
|
onClick: this.selectEntry
|
|
174
|
-
}, "Select entry"), type === LINK_TYPES.ASSET &&
|
|
172
|
+
}, "Select entry"), type === LINK_TYPES.ASSET && React.createElement(TextLink, {
|
|
175
173
|
as: "button",
|
|
176
174
|
onClick: this.selectAsset
|
|
177
175
|
}, "Select asset"));
|
|
@@ -183,7 +181,7 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
183
181
|
this.props.onClose(this.getValue());
|
|
184
182
|
});
|
|
185
183
|
_define_property(this, "selectEntry", async ()=>{
|
|
186
|
-
const { locale, contentTypes
|
|
184
|
+
const { locale , contentTypes } = this.props.entitySelectorConfigs.Entry;
|
|
187
185
|
const entry = await this.props.sdk.dialogs.selectSingleEntry({
|
|
188
186
|
locale,
|
|
189
187
|
contentTypes
|
|
@@ -191,13 +189,13 @@ export class HyperlinkDialog extends (_React_Component = React.Component) {
|
|
|
191
189
|
this.setTargetEntity(LINK_TYPES.ENTRY, entry);
|
|
192
190
|
});
|
|
193
191
|
_define_property(this, "selectAsset", async ()=>{
|
|
194
|
-
const { locale
|
|
192
|
+
const { locale } = this.props.entitySelectorConfigs.Asset;
|
|
195
193
|
const asset = await this.props.sdk.dialogs.selectSingleAsset({
|
|
196
194
|
locale
|
|
197
195
|
});
|
|
198
196
|
this.setTargetEntity(LINK_TYPES.ASSET, asset);
|
|
199
197
|
});
|
|
200
|
-
const { text, type, uri, target
|
|
198
|
+
const { text , type , uri , target } = props.value;
|
|
201
199
|
const isEntityLink = Boolean(target);
|
|
202
200
|
const entityLinks = {
|
|
203
201
|
[LINK_TYPES.ENTRY]: null,
|
|
@@ -230,7 +228,6 @@ _define_property(HyperlinkDialog, "propTypes", {
|
|
|
230
228
|
text: PropTypes.string,
|
|
231
229
|
uri: PropTypes.string,
|
|
232
230
|
target: PropTypes.object,
|
|
233
|
-
// Will be overwritten accordingly if `uri` or `target.sys.linkType` are set.
|
|
234
231
|
type: PropTypes.oneOf([
|
|
235
232
|
'uri',
|
|
236
233
|
'Entry',
|
|
@@ -260,7 +257,7 @@ _define_property(HyperlinkDialog, "defaultProps", {
|
|
|
260
257
|
LINK_TYPES.URI
|
|
261
258
|
]
|
|
262
259
|
});
|
|
263
|
-
export const openHyperlinkDialog = (dialogs, { value, showTextInput, allowedHyperlinkTypes, entitySelectorConfigs
|
|
260
|
+
export const openHyperlinkDialog = (dialogs, { value , showTextInput , allowedHyperlinkTypes , entitySelectorConfigs })=>{
|
|
264
261
|
const isNew = !(value.uri || value.target);
|
|
265
262
|
const props = {
|
|
266
263
|
labels: {
|
|
@@ -3,8 +3,8 @@ import { ModalDialogLauncher } from '@contentful/field-editor-shared';
|
|
|
3
3
|
import { HyperlinkDialog } from './HypelinkDialog/HyperlinkDialog';
|
|
4
4
|
export const openRichTextDialog = (sdk)=>(options)=>{
|
|
5
5
|
if (options.parameters?.type === 'rich-text-hyperlink-dialog') {
|
|
6
|
-
return ModalDialogLauncher.openDialog(options, ({ onClose
|
|
7
|
-
return
|
|
6
|
+
return ModalDialogLauncher.openDialog(options, ({ onClose })=>{
|
|
7
|
+
return React.createElement(HyperlinkDialog, {
|
|
8
8
|
...options.parameters,
|
|
9
9
|
onClose: onClose,
|
|
10
10
|
sdk: sdk
|
|
@@ -4,11 +4,11 @@ export const renderRichTextDialog = (sdk)=>{
|
|
|
4
4
|
const parameters = sdk.parameters.invocation;
|
|
5
5
|
if (parameters?.type === 'rich-text-hyperlink-dialog') {
|
|
6
6
|
sdk.window.startAutoResizer();
|
|
7
|
-
return
|
|
7
|
+
return React.createElement(HyperlinkDialog, {
|
|
8
8
|
...parameters,
|
|
9
9
|
onClose: sdk.close,
|
|
10
10
|
sdk: sdk
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return React.createElement("div", null);
|
|
14
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { toContentfulDocument } from '@contentful/contentful-slatejs-adapter';
|
|
2
2
|
import { COMMAND_PROMPT } from '../../plugins/CommandPalette/constants';
|
|
3
3
|
import { jsx } from '../../test-utils';
|
|
4
4
|
import { removeInternalMarks } from '../removeInternalMarks';
|
|
@@ -8,54 +8,54 @@ describe('internal mark', ()=>{
|
|
|
8
8
|
{
|
|
9
9
|
title: 'Paragraph mark is removed',
|
|
10
10
|
input: toContentfulDocument({
|
|
11
|
-
document:
|
|
11
|
+
document: jsx("editor", null, jsx("hp", null, jsx("htext", {
|
|
12
12
|
[COMMAND_PROMPT]: true
|
|
13
13
|
}))).children
|
|
14
14
|
}),
|
|
15
15
|
expected: toContentfulDocument({
|
|
16
|
-
document:
|
|
16
|
+
document: jsx("editor", null, jsx("hp", null, jsx("htext", null))).children
|
|
17
17
|
})
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
title: 'Heading mark is removed',
|
|
21
21
|
input: toContentfulDocument({
|
|
22
|
-
document:
|
|
22
|
+
document: jsx("editor", null, jsx("hh1", null, jsx("htext", {
|
|
23
23
|
[COMMAND_PROMPT]: true
|
|
24
24
|
}))).children
|
|
25
25
|
}),
|
|
26
26
|
expected: toContentfulDocument({
|
|
27
|
-
document:
|
|
27
|
+
document: jsx("editor", null, jsx("hh1", null, jsx("htext", null))).children
|
|
28
28
|
})
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
title: 'Block quote mark is removed',
|
|
32
32
|
input: toContentfulDocument({
|
|
33
|
-
document:
|
|
33
|
+
document: jsx("editor", null, jsx("hquote", null, jsx("hp", null, jsx("htext", {
|
|
34
34
|
[COMMAND_PROMPT]: true
|
|
35
35
|
})))).children
|
|
36
36
|
}),
|
|
37
37
|
expected: toContentfulDocument({
|
|
38
|
-
document:
|
|
38
|
+
document: jsx("editor", null, jsx("hquote", null, jsx("hp", null, jsx("htext", null)))).children
|
|
39
39
|
})
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
title: 'Other marks are not removed',
|
|
43
43
|
input: toContentfulDocument({
|
|
44
|
-
document:
|
|
44
|
+
document: jsx("editor", null, jsx("hquote", null, jsx("hp", null, jsx("htext", {
|
|
45
45
|
bold: true,
|
|
46
46
|
underline: true,
|
|
47
47
|
[COMMAND_PROMPT]: true
|
|
48
48
|
})))).children
|
|
49
49
|
}),
|
|
50
50
|
expected: toContentfulDocument({
|
|
51
|
-
document:
|
|
51
|
+
document: jsx("editor", null, jsx("hquote", null, jsx("hp", null, jsx("htext", {
|
|
52
52
|
bold: true,
|
|
53
53
|
underline: true
|
|
54
54
|
})))).children
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
];
|
|
58
|
-
for (const { input, expected, title
|
|
58
|
+
for (const { input , expected , title } of data){
|
|
59
59
|
it(`${title}`, ()=>{
|
|
60
60
|
expect(removeInternalMarks(input)).toEqual(expected);
|
|
61
61
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { toContentfulDocument } from '@contentful/contentful-slatejs-adapter';
|
|
2
2
|
import debounce from 'lodash/debounce';
|
|
3
3
|
import schema from '../constants/Schema';
|
|
4
4
|
import { removeInternalMarks } from './removeInternalMarks';
|
|
@@ -17,15 +17,7 @@ function getEntityTypeFromRichTextNode(nodeType) {
|
|
|
17
17
|
}
|
|
18
18
|
throw new Error(`RichText node type \`${nodeType}\` has no associated \`entityType\``);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
* Returns a config for the entity selector based on a given rich text field and a
|
|
22
|
-
* rich text node type that the entity should be picked for. Takes the field
|
|
23
|
-
* validations for the given node type into account.
|
|
24
|
-
*
|
|
25
|
-
* @param {object} field
|
|
26
|
-
* @param {string} nodeType
|
|
27
|
-
* @returns {object}
|
|
28
|
-
*/ export const newResourceEntitySelectorConfigFromRichTextField = (field, nodeType)=>{
|
|
20
|
+
export const newResourceEntitySelectorConfigFromRichTextField = (field, nodeType)=>{
|
|
29
21
|
return {
|
|
30
22
|
allowedResources: getAllowedResourcesForNodeType(field, nodeType)
|
|
31
23
|
};
|
|
@@ -67,11 +67,7 @@ export function insertEmptyParagraph(editor, options) {
|
|
|
67
67
|
export function getElementFromCurrentSelection(editor) {
|
|
68
68
|
if (!editor.selection) return [];
|
|
69
69
|
return Array.from(getNodeEntries(editor, {
|
|
70
|
-
|
|
71
|
-
* editor.select is a Range, which includes anchor and focus, the beginning and the end of a selection
|
|
72
|
-
* when using only editor.selection.focus, we might get only the end of the selection, or where the text cursor is
|
|
73
|
-
* and in some cases getting the next element instead of the one we want
|
|
74
|
-
**/ at: editor.selection,
|
|
70
|
+
at: editor.selection,
|
|
75
71
|
match: (node)=>isElement(node)
|
|
76
72
|
})).flat();
|
|
77
73
|
}
|
|
@@ -92,13 +88,11 @@ export function getTableSize(table) {
|
|
|
92
88
|
numColumns
|
|
93
89
|
};
|
|
94
90
|
}
|
|
95
|
-
// TODO: move to hyperlink plugin
|
|
96
91
|
export function insertLink(editor, options) {
|
|
97
92
|
if (editor.selection) {
|
|
98
93
|
wrapLink(editor, options);
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
|
-
// TODO: move to hyperlink plugin
|
|
102
96
|
export function isLinkActive(editor) {
|
|
103
97
|
if (!editor) {
|
|
104
98
|
return false;
|
|
@@ -108,18 +102,16 @@ export function isLinkActive(editor) {
|
|
|
108
102
|
}));
|
|
109
103
|
return !!link;
|
|
110
104
|
}
|
|
111
|
-
// TODO: move to hyperlink plugin
|
|
112
105
|
export function unwrapLink(editor) {
|
|
113
106
|
unwrapNodes(editor, {
|
|
114
107
|
match: (node)=>!isEditor(node) && isElement(node) && LINK_TYPES.includes(node.type)
|
|
115
108
|
});
|
|
116
109
|
}
|
|
117
|
-
|
|
118
|
-
export function wrapLink(editor, { text, url, target, type, path }) {
|
|
110
|
+
export function wrapLink(editor, { text , url , target , type , path }) {
|
|
119
111
|
if (isLinkActive(editor) && !path) {
|
|
120
112
|
unwrapLink(editor);
|
|
121
113
|
}
|
|
122
|
-
const { selection
|
|
114
|
+
const { selection } = editor;
|
|
123
115
|
const isCollapsed = selection && isSelectionCollapsed(selection);
|
|
124
116
|
const link = {
|
|
125
117
|
type,
|
|
@@ -140,7 +132,6 @@ export function wrapLink(editor, { text, url, target, type, path }) {
|
|
|
140
132
|
target
|
|
141
133
|
};
|
|
142
134
|
}
|
|
143
|
-
// TODO: always set the selection to the end of the inserted link
|
|
144
135
|
if (path) {
|
|
145
136
|
setNodes(editor, link, {
|
|
146
137
|
at: path
|
|
@@ -167,19 +158,15 @@ export function getAncestorPathFromSelection(editor) {
|
|
|
167
158
|
return getPathLevels(editor.selection.focus.path).find((level)=>level.length === 1);
|
|
168
159
|
}
|
|
169
160
|
export const isAtEndOfTextSelection = (editor)=>editor.selection?.focus.offset === getText(editor, editor.selection?.focus.path).length;
|
|
170
|
-
|
|
171
|
-
* This traversal strategy is unfortunately necessary because Slate doesn't
|
|
172
|
-
* expose something like Node.next(editor).
|
|
173
|
-
*/ export function getNextNode(editor) {
|
|
161
|
+
export function getNextNode(editor) {
|
|
174
162
|
if (!editor.selection) {
|
|
175
163
|
return null;
|
|
176
164
|
}
|
|
177
165
|
const descendants = getNodeDescendants(editor, {
|
|
178
166
|
from: editor.selection.focus.path
|
|
179
167
|
});
|
|
180
|
-
// eslint-disable-next-line no-constant-condition -- TODO: explain this disable
|
|
181
168
|
while(true){
|
|
182
|
-
const { done, value
|
|
169
|
+
const { done , value } = descendants.next();
|
|
183
170
|
if (done) {
|
|
184
171
|
return null;
|
|
185
172
|
}
|
|
@@ -192,23 +179,20 @@ export const isAtEndOfTextSelection = (editor)=>editor.selection?.focus.offset =
|
|
|
192
179
|
}
|
|
193
180
|
export const INLINE_TYPES = Object.values(INLINES);
|
|
194
181
|
export const isInlineOrText = (node)=>{
|
|
195
|
-
// either text or inline elements
|
|
196
182
|
return isText(node) || isElement(node) && INLINE_TYPES.includes(node.type);
|
|
197
183
|
};
|
|
198
184
|
export const focus = (editor)=>{
|
|
199
185
|
const x = window.scrollX;
|
|
200
186
|
const y = window.scrollY;
|
|
201
187
|
focusEditor(editor);
|
|
202
|
-
// Safari has issues with `editor.focus({ preventScroll: true })`, it ignores the option `preventScroll`
|
|
203
188
|
if (IS_SAFARI) {
|
|
204
189
|
setTimeout(function() {
|
|
205
|
-
window.scrollTo(x, y);
|
|
190
|
+
window.scrollTo(x, y);
|
|
206
191
|
}, 0);
|
|
207
192
|
}
|
|
208
193
|
};
|
|
209
194
|
export function toggleElement(editor, options, editorOptions) {
|
|
210
195
|
toggleNodeType(editor, options, editorOptions);
|
|
211
|
-
// We must reset `data` from one element to another
|
|
212
196
|
setNodes(editor, {
|
|
213
197
|
data: {}
|
|
214
198
|
});
|
|
@@ -7,9 +7,7 @@ function extractNodes(editor, path, match) {
|
|
|
7
7
|
mode: 'lowest'
|
|
8
8
|
})).map(([node])=>node);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* It filters out all paragraphs and headings from a path and convert them into paragraphs.
|
|
12
|
-
*/ export function extractParagraphs(editor, path) {
|
|
10
|
+
export function extractParagraphs(editor, path) {
|
|
13
11
|
return extractNodes(editor, path, {
|
|
14
12
|
type: TEXT_CONTAINERS
|
|
15
13
|
}).map((node)=>({
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
// eslint-disable-next-line no-restricted-imports -- TODO: explain this disable
|
|
2
1
|
import moment from 'moment';
|
|
3
|
-
|
|
4
|
-
* @param {Date|string} date A valid constructor argument for moment()
|
|
5
|
-
* @param {boolean=} short Render only Today/Tomorrow/Yesterday if valid. Defaults to false
|
|
6
|
-
*/ export const formatDate = (date, short)=>{
|
|
2
|
+
export const formatDate = (date, short)=>{
|
|
7
3
|
switch(moment().startOf('day').diff(moment(date).startOf('day'), 'days')){
|
|
8
4
|
case 0:
|
|
9
5
|
return short ? 'Today' : `Today, ${moment(date).format('DD MMM YYYY')}`;
|
|
@@ -15,12 +11,7 @@ import moment from 'moment';
|
|
|
15
11
|
return moment(date).format('ddd, DD MMM YYYY');
|
|
16
12
|
}
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
* Returns the time portion of a date in the local time in the format H:MM AM/PM
|
|
20
|
-
*
|
|
21
|
-
* == Examples
|
|
22
|
-
* * `T15:36:45.000Z` => 3:36 PM (if in +0:00 offset)
|
|
23
|
-
*/ export const formatTime = (date)=>{
|
|
14
|
+
export const formatTime = (date)=>{
|
|
24
15
|
return moment.utc(date).local().format('h:mm A');
|
|
25
16
|
};
|
|
26
17
|
export const formatDateAndTime = (date, short)=>{
|
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import find from 'lodash/find';
|
|
2
2
|
import flow from 'lodash/flow';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
|
-
|
|
5
|
-
* Given a field object and a rich text node type, return a list of allowed
|
|
6
|
-
* resources associated with the node type, based on that node type's
|
|
7
|
-
* `allowedResources` property.
|
|
8
|
-
*
|
|
9
|
-
* The navigation here is explained by the `nodes` validation having signature:
|
|
10
|
-
* { nodes: { [nodeType]: { allowedResources: AllowedResource[] } } }
|
|
11
|
-
*
|
|
12
|
-
* We defensively navigate through this object because
|
|
13
|
-
* 1) the field may not have a `validations` array,
|
|
14
|
-
* 2) the `validations` array may be empty,
|
|
15
|
-
* 3) the `validations` array may not have a `nodes` validation, and
|
|
16
|
-
* 4) the `nodes` validation may not validate the `nodeType`.
|
|
17
|
-
*
|
|
18
|
-
* @param {object} field
|
|
19
|
-
* @param {string} nodeType
|
|
20
|
-
* @returns {AllowedResource[]}
|
|
21
|
-
*/ export default function getAllowedResourcesForNodeType(field, nodeType) {
|
|
4
|
+
export default function getAllowedResourcesForNodeType(field, nodeType) {
|
|
22
5
|
return flow((validations)=>find(validations, 'nodes'), (validations)=>get(validations, [
|
|
23
6
|
'nodes',
|
|
24
7
|
nodeType,
|
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import find from 'lodash/find';
|
|
2
2
|
import flow from 'lodash/flow';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
|
-
|
|
5
|
-
* Given a field object and a rich text node type, return a list of valid
|
|
6
|
-
* content type IDs associated with the node type, based on that node type's
|
|
7
|
-
* `linkContentType` validation.
|
|
8
|
-
*
|
|
9
|
-
* If there is no such validation or the validation is empty, return an empty
|
|
10
|
-
* array.
|
|
11
|
-
*
|
|
12
|
-
* The navigation here is explained by the `nodes` validation having signature:
|
|
13
|
-
* { nodes: { [nodeType]: validationObject[] } }
|
|
14
|
-
*
|
|
15
|
-
* We defensively navigate through this object because
|
|
16
|
-
* 1) the field may not have a `validations` array,
|
|
17
|
-
* 2) the `validations` array may be empty,
|
|
18
|
-
* 3) the `validations` array may not have a `nodes` validation,
|
|
19
|
-
* 4) the `nodes` validation may not validate the `nodeType`, and
|
|
20
|
-
* 5) the `nodeType` validations may not have a `linkContentType` validation.
|
|
21
|
-
*
|
|
22
|
-
* Note that passing an empty array will result in all possible content types
|
|
23
|
-
* being whitelisted.
|
|
24
|
-
*
|
|
25
|
-
* @param {object} field
|
|
26
|
-
* @param {string} nodeType
|
|
27
|
-
* @returns {string[]}
|
|
28
|
-
*/ export default function getLinkedContentTypeIdsForNodeType(field, nodeType) {
|
|
4
|
+
export default function getLinkedContentTypeIdsForNodeType(field, nodeType) {
|
|
29
5
|
return flow((v)=>find(v, 'nodes'), (v)=>get(v, [
|
|
30
6
|
'nodes',
|
|
31
7
|
nodeType
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import noop from 'lodash/noop';
|
|
2
|
-
|
|
3
|
-
* Allows to observe when the current slide-in navigation slide gets e.g.
|
|
4
|
-
* re-activated after opening another slide on top. This is useful as the sdk
|
|
5
|
-
* does not give full insights into e.g. whether sdk.dialogs.selectSingleEntry()
|
|
6
|
-
* with `withCreate: true` option opens the slide-in navigation to edit the
|
|
7
|
-
* created entry after returning it.
|
|
8
|
-
*/ export function watchCurrentSlide(navigator) {
|
|
2
|
+
export function watchCurrentSlide(navigator) {
|
|
9
3
|
const onActiveCallbacks = new Set();
|
|
10
4
|
let wasSlideClosed = false;
|
|
11
5
|
let initialSlideLevel;
|
|
@@ -14,34 +8,26 @@ import noop from 'lodash/noop';
|
|
|
14
8
|
wasClosed: wasSlideClosed,
|
|
15
9
|
isActive: !wasSlideClosed && lastSlideLevel === initialSlideLevel
|
|
16
10
|
});
|
|
17
|
-
const off = navigator.onSlideInNavigation(({ oldSlideLevel, newSlideLevel
|
|
11
|
+
const off = navigator.onSlideInNavigation(({ oldSlideLevel , newSlideLevel })=>{
|
|
18
12
|
if (initialSlideLevel === undefined) {
|
|
19
13
|
initialSlideLevel = oldSlideLevel;
|
|
20
14
|
}
|
|
21
15
|
lastSlideLevel = newSlideLevel;
|
|
22
16
|
if (newSlideLevel < initialSlideLevel) {
|
|
23
17
|
wasSlideClosed = true;
|
|
24
|
-
off();
|
|
18
|
+
off();
|
|
25
19
|
onActiveCallbacks.clear();
|
|
26
20
|
}
|
|
27
21
|
if (status().isActive && newSlideLevel !== oldSlideLevel) {
|
|
28
22
|
onActiveCallbacks.forEach((cb)=>cb());
|
|
29
23
|
}
|
|
30
24
|
});
|
|
31
|
-
|
|
32
|
-
* Call to unsubscribe from navigator events when the watcher is no longer
|
|
33
|
-
* needed.
|
|
34
|
-
*/ function unwatch() {
|
|
25
|
+
function unwatch() {
|
|
35
26
|
off();
|
|
36
27
|
onActiveCallbacks.clear();
|
|
37
28
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* it becomes active again, if there are slides on top that get closed. Does not
|
|
41
|
-
* fire when the observed slide gets closed, and then re-opened through browser
|
|
42
|
-
* back, as this technically opens a new slide and editor instance.
|
|
43
|
-
*/ function onActive(cb) {
|
|
44
|
-
if (wasSlideClosed) return noop; // Can't re-activate already closed slide.
|
|
29
|
+
function onActive(cb) {
|
|
30
|
+
if (wasSlideClosed) return noop;
|
|
45
31
|
if (status().isActive) {
|
|
46
32
|
cb();
|
|
47
33
|
}
|
|
@@ -195,7 +195,6 @@ describe('watchCurrentSlide().unwatch()', ()=>{
|
|
|
195
195
|
newSlideLevel: 0
|
|
196
196
|
});
|
|
197
197
|
expect(spy).toHaveBeenCalledTimes(0);
|
|
198
|
-
// Demonstrate that normally this would fire an event if it wasn't for the unwatch()
|
|
199
198
|
expect(spy2).toHaveBeenCalledTimes(1);
|
|
200
199
|
});
|
|
201
200
|
});
|
|
@@ -2,10 +2,7 @@ import { toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
|
2
2
|
import { EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
3
3
|
import schema from '../constants/Schema';
|
|
4
4
|
const isTextElement = (node)=>'text' in node;
|
|
5
|
-
|
|
6
|
-
* Ensures all nodes have a child leaf text element. This should be handled by
|
|
7
|
-
* Slate but its behavior has proven to be buggy and unpredictable.
|
|
8
|
-
*/ function sanitizeIncomingSlateDoc(nodes = []) {
|
|
5
|
+
function sanitizeIncomingSlateDoc(nodes = []) {
|
|
9
6
|
return nodes.map((node)=>{
|
|
10
7
|
if (isTextElement(node)) {
|
|
11
8
|
return node;
|
|
@@ -27,23 +24,12 @@ const isTextElement = (node)=>'text' in node;
|
|
|
27
24
|
};
|
|
28
25
|
});
|
|
29
26
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* value
|
|
33
|
-
*/ export const toSlateValue = (doc)=>{
|
|
34
|
-
/**
|
|
35
|
-
* For legacy reasons, a document may not have any content at all
|
|
36
|
-
* e.g:
|
|
37
|
-
*
|
|
38
|
-
* {nodeType: document, data: {}, content: []}
|
|
39
|
-
*
|
|
40
|
-
* Rendering such document will break the Slate editor
|
|
41
|
-
*/ const hasContent = (doc)=>{
|
|
27
|
+
export const toSlateValue = (doc)=>{
|
|
28
|
+
const hasContent = (doc)=>{
|
|
42
29
|
return (doc?.content || []).length > 0;
|
|
43
30
|
};
|
|
44
31
|
const slateDoc = toSlatejsDocument({
|
|
45
32
|
document: doc && hasContent(doc) ? doc : EMPTY_DOCUMENT,
|
|
46
|
-
// TODO: get rid of schema, https://github.com/contentful/field-editors/pull/1065#discussion_r826723248
|
|
47
33
|
schema
|
|
48
34
|
});
|
|
49
35
|
return sanitizeIncomingSlateDoc(slateDoc);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { BLOCKS, INLINES, TOP_LEVEL_BLOCKS } from '@contentful/rich-text-types';
|
|
2
2
|
import find from 'lodash/find';
|
|
3
3
|
import flow from 'lodash/flow';
|
|
4
4
|
import get from 'lodash/get';
|
|
5
|
-
// TODO: Move these into separate package (maybe rich-text-types) and share with FE.
|
|
6
5
|
export const VALIDATIONS = {
|
|
7
6
|
ENABLED_MARKS: 'enabledMarks',
|
|
8
7
|
ENABLED_NODE_TYPES: 'enabledNodeTypes'
|
|
@@ -13,12 +12,9 @@ export const DEFAULT_ENABLED_NODE_TYPES = [
|
|
|
13
12
|
'text'
|
|
14
13
|
];
|
|
15
14
|
export const VALIDATABLE_NODE_TYPES = [].concat(TOP_LEVEL_BLOCKS).filter((type)=>type !== BLOCKS.PARAGRAPH).concat(Object.values(INLINES));
|
|
16
|
-
// TODO: Memoize
|
|
17
15
|
const getRichTextValidation = (field, validationType)=>flow((v)=>find(v, validationType), (v)=>get(v, validationType))(field.validations);
|
|
18
16
|
const isFormattingOptionEnabled = (field, validationType, nodeTypeOrMark)=>{
|
|
19
17
|
const enabledFormattings = getRichTextValidation(field, validationType);
|
|
20
|
-
// TODO: In the future, validations will always be opt-in. In that case
|
|
21
|
-
// we don't need this step.
|
|
22
18
|
if (enabledFormattings === undefined) {
|
|
23
19
|
return true;
|
|
24
20
|
}
|