@contentful/field-editor-rich-text 3.15.0 → 3.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ContentfulEditorProvider.js +8 -8
- package/dist/cjs/RichTextEditor.js +22 -20
- package/dist/cjs/RichTextEditor.styles.js +2 -1
- package/dist/cjs/SdkProvider.js +7 -5
- package/dist/cjs/SyncEditorChanges.js +15 -6
- package/dist/cjs/Toolbar/_tests_/toolbar.test.js +17 -15
- package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +14 -10
- package/dist/cjs/Toolbar/components/EmbeddedEntityDropdownButton.js +10 -8
- package/dist/cjs/Toolbar/components/StickyToolbarWrapper.js +2 -2
- package/dist/cjs/Toolbar/index.js +33 -30
- 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 +8 -6
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/constants/Schema.js +1 -0
- package/dist/cjs/dialogs/HypelinkDialog/HyperlinkDialog.js +43 -38
- package/dist/cjs/dialogs/openRichTextDialog.js +6 -4
- package/dist/cjs/dialogs/renderRichTextDialog.js +6 -4
- 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 +53 -44
- package/dist/cjs/helpers/environment.js +3 -3
- package/dist/cjs/helpers/formatDateAndTime.js +5 -4
- package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +22 -5
- package/dist/cjs/helpers/getLinkedContentTypeIdsForNodeType.js +29 -5
- package/dist/cjs/helpers/nodeFactory.js +6 -6
- package/dist/cjs/helpers/sdkNavigatorSlideIn.js +14 -6
- package/dist/cjs/helpers/sdkNavigatorSlideIn.spec.js +3 -2
- package/dist/cjs/helpers/toSlateValue.js +14 -3
- package/dist/cjs/helpers/transformers.js +5 -5
- package/dist/cjs/helpers/validations.js +12 -9
- package/dist/cjs/index.js +7 -5
- package/dist/cjs/internal/constants.js +4 -2
- package/dist/cjs/internal/hooks.js +8 -6
- package/dist/cjs/internal/misc.js +15 -12
- package/dist/cjs/internal/queries.js +115 -108
- package/dist/cjs/internal/transforms.js +51 -48
- package/dist/cjs/internal/types/editor.js +3 -1
- package/dist/cjs/plugins/Break/createExitBreakPlugin.test.js +4 -3
- package/dist/cjs/plugins/Break/createResetNodePlugin.js +1 -0
- package/dist/cjs/plugins/Break/createSoftBreakPlugin.test.js +3 -3
- package/dist/cjs/plugins/CommandPalette/components/CommandList.js +35 -33
- package/dist/cjs/plugins/CommandPalette/components/CommandList.styles.js +1 -1
- package/dist/cjs/plugins/CommandPalette/components/CommandPrompt.js +7 -5
- package/dist/cjs/plugins/CommandPalette/hooks/useCommandList.js +7 -3
- package/dist/cjs/plugins/CommandPalette/onKeyDown.js +6 -1
- package/dist/cjs/plugins/CommandPalette/onKeyDown.spec.js +6 -4
- package/dist/cjs/plugins/CommandPalette/useCommands.js +3 -3
- package/dist/cjs/plugins/CommandPalette/utils/fetchEntries.js +2 -0
- package/dist/cjs/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
- package/dist/cjs/plugins/DragAndDrop/index.js +9 -1
- package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +10 -8
- package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -3
- package/dist/cjs/plugins/EmbeddedEntityInline/FetchingWrappedInlineEntryCard.js +19 -17
- package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +9 -7
- package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +5 -5
- package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +13 -11
- 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 +13 -10
- package/dist/cjs/plugins/Heading/components/ToolbarHeadingButton.js +19 -11
- package/dist/cjs/plugins/Heading/createHeadingPlugin.js +7 -2
- package/dist/cjs/plugins/Hr/index.js +19 -14
- package/dist/cjs/plugins/Hyperlink/HyperlinkModal.js +32 -28
- package/dist/cjs/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +8 -6
- package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +8 -6
- package/dist/cjs/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +6 -4
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +7 -5
- package/dist/cjs/plugins/Hyperlink/components/styles.js +1 -1
- package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +10 -4
- package/dist/cjs/plugins/Hyperlink/useEntityInfo.js +6 -3
- package/dist/cjs/plugins/Hyperlink/useResourceEntityInfo.js +6 -4
- 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 +29 -25
- package/dist/cjs/plugins/List/__tests__/insertListFragment.test.js +22 -22
- package/dist/cjs/plugins/List/components/List.js +9 -7
- package/dist/cjs/plugins/List/components/ListItem.js +6 -4
- package/dist/cjs/plugins/List/components/ToolbarListButton.js +7 -5
- package/dist/cjs/plugins/List/createListPlugin.js +4 -0
- package/dist/cjs/plugins/List/insertListBreak.js +13 -4
- package/dist/cjs/plugins/List/insertListFragment.js +18 -5
- package/dist/cjs/plugins/List/onKeyDownList.js +7 -4
- package/dist/cjs/plugins/List/transforms/insertListItem.js +17 -2
- package/dist/cjs/plugins/List/transforms/moveListItemDown.js +8 -2
- package/dist/cjs/plugins/List/transforms/moveListItems.js +7 -2
- package/dist/cjs/plugins/List/transforms/moveListItems.test.js +15 -14
- package/dist/cjs/plugins/List/transforms/toggleList.js +8 -3
- package/dist/cjs/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/cjs/plugins/List/transforms/unwrapList.js +7 -2
- package/dist/cjs/plugins/List/utils.js +12 -11
- package/dist/cjs/plugins/List/withList.js +6 -2
- package/dist/cjs/plugins/Marks/Bold.js +9 -7
- package/dist/cjs/plugins/Marks/Code.js +15 -7
- package/dist/cjs/plugins/Marks/Italic.js +9 -7
- package/dist/cjs/plugins/Marks/Subscript.js +10 -8
- package/dist/cjs/plugins/Marks/Superscript.js +10 -8
- package/dist/cjs/plugins/Marks/Underline.js +6 -4
- package/dist/cjs/plugins/Marks/components/MarkToolbarButton.js +9 -7
- package/dist/cjs/plugins/Marks/helpers.js +5 -5
- package/dist/cjs/plugins/Normalizer/baseRules.js +2 -0
- package/dist/cjs/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/cjs/plugins/Normalizer/utils.js +4 -3
- package/dist/cjs/plugins/Normalizer/withNormalizer.js +23 -3
- package/dist/cjs/plugins/Paragraph/Paragraph.js +6 -4
- package/dist/cjs/plugins/Paragraph/__tests__/createParagraphPlugin.test.js +32 -32
- package/dist/cjs/plugins/Paragraph/createParagraphPlugin.js +3 -2
- package/dist/cjs/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -6
- package/dist/cjs/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeAnchors.js +9 -0
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
- package/dist/cjs/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
- package/dist/cjs/plugins/Quote/__test__/createQuotePlugin.test.js +21 -21
- package/dist/cjs/plugins/Quote/components/Quote.js +6 -4
- package/dist/cjs/plugins/Quote/components/ToolbarQuoteButton.js +6 -4
- package/dist/cjs/plugins/Quote/createQuotePlugin.js +1 -0
- package/dist/cjs/plugins/Quote/toggleQuote.js +5 -5
- package/dist/cjs/plugins/Quote/withQuote.js +4 -2
- package/dist/cjs/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
- 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 +5 -4
- package/dist/cjs/plugins/Table/actions/addRow.js +6 -3
- package/dist/cjs/plugins/Table/components/Cell.js +7 -5
- package/dist/cjs/plugins/Table/components/HeaderCell.js +7 -5
- package/dist/cjs/plugins/Table/components/Row.js +6 -4
- package/dist/cjs/plugins/Table/components/Table.js +8 -6
- package/dist/cjs/plugins/Table/components/TableActions.js +19 -16
- package/dist/cjs/plugins/Table/components/ToolbarButton.js +7 -4
- package/dist/cjs/plugins/Table/createTablePlugin.js +11 -1
- package/dist/cjs/plugins/Table/helpers.js +16 -12
- package/dist/cjs/plugins/Table/insertTableFragment.js +15 -2
- package/dist/cjs/plugins/Table/onKeyDownTable.js +10 -2
- package/dist/cjs/plugins/Table/tableTracking.js +6 -6
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
- package/dist/cjs/plugins/Text/createTextPlugin.js +22 -5
- package/dist/cjs/plugins/Tracking/createTrackingPlugin.js +5 -4
- package/dist/cjs/plugins/Tracking/utils.js +6 -3
- package/dist/cjs/plugins/Voids/createVoidsPlugin.js +5 -0
- package/dist/cjs/plugins/Voids/transformVoid.js +1 -0
- package/dist/cjs/plugins/index.js +15 -3
- package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +12 -10
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +16 -6
- package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +10 -8
- package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +9 -5
- package/dist/cjs/plugins/shared/FetchingWrappedAssetCard.js +13 -11
- package/dist/cjs/plugins/shared/FetchingWrappedEntryCard.js +14 -12
- package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +14 -11
- package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +8 -4
- package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +10 -6
- package/dist/cjs/plugins/shared/ResourceNewBadge.js +5 -3
- package/dist/cjs/plugins/shared/ToolbarButton.js +8 -6
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedAssetCard.test.js +10 -5
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +11 -6
- package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +15 -13
- package/dist/cjs/plugins/shared/utils.js +4 -1
- package/dist/cjs/test-utils/assertOutput.js +1 -0
- package/dist/cjs/test-utils/hyperscript.d.js +1 -0
- package/dist/cjs/test-utils/randomId.js +3 -1
- package/dist/cjs/test-utils/validation.js +8 -5
- package/dist/esm/ContentfulEditorProvider.js +4 -1
- package/dist/esm/RichTextEditor.js +13 -13
- package/dist/esm/RichTextEditor.styles.js +1 -0
- package/dist/esm/SdkProvider.js +2 -2
- package/dist/esm/SyncEditorChanges.js +18 -3
- package/dist/esm/Toolbar/_tests_/toolbar.test.js +12 -12
- package/dist/esm/Toolbar/components/EmbedEntityWidget.js +10 -8
- package/dist/esm/Toolbar/components/EmbeddedEntityDropdownButton.js +6 -6
- package/dist/esm/Toolbar/components/StickyToolbarWrapper.js +1 -1
- package/dist/esm/Toolbar/index.js +28 -27
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/constants/Schema.js +1 -0
- package/dist/esm/dialogs/HypelinkDialog/HyperlinkDialog.js +34 -31
- 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 +9 -1
- package/dist/esm/helpers/editor.js +22 -6
- package/dist/esm/helpers/extractNodes.js +3 -1
- package/dist/esm/helpers/formatDateAndTime.js +11 -2
- package/dist/esm/helpers/getAllowedResourcesForNodeType.js +19 -2
- package/dist/esm/helpers/getLinkedContentTypeIdsForNodeType.js +26 -2
- package/dist/esm/helpers/sdkNavigatorSlideIn.js +20 -6
- package/dist/esm/helpers/sdkNavigatorSlideIn.spec.js +1 -0
- package/dist/esm/helpers/toSlateValue.js +17 -3
- package/dist/esm/helpers/validations.js +5 -1
- package/dist/esm/internal/misc.js +23 -2
- package/dist/esm/internal/queries.js +11 -2
- package/dist/esm/internal/transforms.js +14 -3
- package/dist/esm/internal/types/editor.js +3 -1
- package/dist/esm/plugins/Break/createExitBreakPlugin.test.js +4 -3
- package/dist/esm/plugins/Break/createResetNodePlugin.js +1 -0
- 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 +11 -1
- package/dist/esm/plugins/CommandPalette/hooks/useCommandList.js +2 -0
- package/dist/esm/plugins/CommandPalette/onKeyDown.js +5 -0
- 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 +2 -0
- package/dist/esm/plugins/CommandPalette/utils/trimLeadingSlash.js +6 -1
- package/dist/esm/plugins/DragAndDrop/index.js +9 -1
- 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 +8 -7
- package/dist/esm/plugins/Heading/components/ToolbarHeadingButton.js +14 -8
- package/dist/esm/plugins/Heading/createHeadingPlugin.js +6 -1
- package/dist/esm/plugins/Hr/index.js +8 -5
- package/dist/esm/plugins/Hyperlink/HyperlinkModal.js +25 -23
- package/dist/esm/plugins/Hyperlink/__tests__/createHyperlinkPlugin.test.js +8 -8
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +4 -4
- package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +4 -4
- package/dist/esm/plugins/Hyperlink/components/ToolbarHyperlinkButton.js +2 -2
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +3 -3
- package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +5 -1
- package/dist/esm/plugins/Hyperlink/useEntityInfo.js +6 -3
- 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 +29 -25
- 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 +4 -0
- package/dist/esm/plugins/List/insertListBreak.js +13 -4
- package/dist/esm/plugins/List/insertListFragment.js +18 -5
- package/dist/esm/plugins/List/onKeyDownList.js +5 -2
- package/dist/esm/plugins/List/transforms/insertListItem.js +20 -3
- package/dist/esm/plugins/List/transforms/moveListItemDown.js +8 -2
- package/dist/esm/plugins/List/transforms/moveListItems.js +7 -2
- package/dist/esm/plugins/List/transforms/moveListItems.test.js +15 -14
- package/dist/esm/plugins/List/transforms/toggleList.js +8 -3
- package/dist/esm/plugins/List/transforms/toggleList.spec.js +28 -28
- package/dist/esm/plugins/List/transforms/unwrapList.js +7 -2
- package/dist/esm/plugins/List/utils.js +7 -2
- package/dist/esm/plugins/List/withList.js +6 -2
- package/dist/esm/plugins/Marks/Bold.js +2 -2
- package/dist/esm/plugins/Marks/Code.js +8 -2
- 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 +4 -0
- package/dist/esm/plugins/Normalizer/createNormalizerPlugin.test.js +12 -12
- package/dist/esm/plugins/Normalizer/utils.js +1 -0
- package/dist/esm/plugins/Normalizer/withNormalizer.js +22 -2
- 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 +2 -1
- package/dist/esm/plugins/PasteHTML/createPasteHTMLPlugin.js +9 -3
- package/dist/esm/plugins/PasteHTML/utils/__tests__/sanitizeHTML.test.js +2 -0
- package/dist/esm/plugins/PasteHTML/utils/sanitizeAnchors.js +27 -1
- package/dist/esm/plugins/PasteHTML/utils/sanitizeHTML.js +17 -2
- package/dist/esm/plugins/PasteHTML/utils/sanitizeSheets.js +13 -1
- 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 +1 -0
- package/dist/esm/plugins/Quote/shouldResetQuote.js +6 -1
- package/dist/esm/plugins/Quote/toggleQuote.js +1 -1
- package/dist/esm/plugins/Quote/withQuote.js +4 -2
- package/dist/esm/plugins/SelectOnBackspace/createSelectOnBackspacePlugin.js +1 -0
- 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 +2 -1
- package/dist/esm/plugins/Table/actions/addRow.js +3 -0
- 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 +12 -11
- package/dist/esm/plugins/Table/components/ToolbarButton.js +3 -2
- package/dist/esm/plugins/Table/createTablePlugin.js +11 -1
- package/dist/esm/plugins/Table/helpers.js +10 -1
- package/dist/esm/plugins/Table/insertTableFragment.js +15 -2
- package/dist/esm/plugins/Table/onKeyDownTable.js +10 -2
- package/dist/esm/plugins/Table/tableTracking.js +6 -6
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +19 -17
- package/dist/esm/plugins/Text/createTextPlugin.js +22 -5
- package/dist/esm/plugins/Tracking/createTrackingPlugin.js +2 -1
- package/dist/esm/plugins/Tracking/utils.js +1 -0
- package/dist/esm/plugins/Voids/createVoidsPlugin.js +5 -0
- package/dist/esm/plugins/Voids/transformVoid.js +4 -1
- package/dist/esm/plugins/index.js +12 -0
- package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +15 -5
- package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +5 -5
- package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +8 -4
- 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 +9 -8
- package/dist/esm/plugins/shared/LinkedBlockWrapper.js +7 -3
- package/dist/esm/plugins/shared/LinkedInlineWrapper.js +5 -3
- 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 +5 -2
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedEntryCard.test.js +5 -2
- package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +8 -8
- package/dist/esm/plugins/shared/utils.js +4 -1
- package/dist/esm/test-utils/assertOutput.js +1 -0
- package/dist/esm/test-utils/hyperscript.d.js +1 -0
- package/dist/esm/test-utils/jsx.js +5 -1
- package/dist/esm/test-utils/randomId.js +3 -1
- package/dist/esm/test-utils/setEmptyDataAttribute.js +4 -1
- package/dist/esm/test-utils/validation.js +7 -4
- package/package.json +3 -3
|
@@ -14,13 +14,13 @@ export const CommandPrompt = (props)=>{
|
|
|
14
14
|
]);
|
|
15
15
|
const editor = props.editor;
|
|
16
16
|
const [textElement, setTextElement] = React.useState();
|
|
17
|
-
return React.createElement("span", {
|
|
17
|
+
return /*#__PURE__*/ React.createElement("span", {
|
|
18
18
|
className: styles.commandPrompt,
|
|
19
19
|
ref: (e)=>{
|
|
20
20
|
setTextElement(e);
|
|
21
21
|
},
|
|
22
22
|
...props.attributes
|
|
23
|
-
}, props.children, React.createElement(CommandList, {
|
|
23
|
+
}, props.children, /*#__PURE__*/ React.createElement(CommandList, {
|
|
24
24
|
query: query,
|
|
25
25
|
editor: editor,
|
|
26
26
|
textContainer: textElement
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { CommandPrompt } from './components/CommandPrompt';
|
|
2
2
|
import { COMMAND_PROMPT } from './constants';
|
|
3
3
|
import { createOnKeyDown } from './onKeyDown';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A command palette plugin (aka slash commands)
|
|
6
|
+
*
|
|
7
|
+
* How does it work?
|
|
8
|
+
* * When the user presses the slash key, the editor will show a command palette
|
|
9
|
+
* * When the user presses a key, the command palette will show the command suggestions
|
|
10
|
+
* * When the user presses enter, the command palette will execute the command
|
|
11
|
+
* * When the user presses escape, the command palette will hide
|
|
12
|
+
* * When the user presses a letter, number, or space, the command palette will show the command suggestions
|
|
13
|
+
* * When the user presses backspace, the command palette will remove the last character from the command string
|
|
14
|
+
*/ export const createCommandPalettePlugin = ()=>{
|
|
5
15
|
return {
|
|
6
16
|
key: COMMAND_PROMPT,
|
|
7
17
|
type: COMMAND_PROMPT,
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import isHotkey from 'is-hotkey';
|
|
3
3
|
export const useCommandList = (commandItems, container)=>{
|
|
4
4
|
const [selectedItem, setSelectedItem] = React.useState(()=>{
|
|
5
|
+
// select the first item on initial render
|
|
5
6
|
if (!commandItems.length) {
|
|
6
7
|
return '';
|
|
7
8
|
}
|
|
@@ -54,6 +55,7 @@ export const useCommandList = (commandItems, container)=>{
|
|
|
54
55
|
currBtn.click();
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
//TODO: handle shift+enter, which must be detected using separate events
|
|
57
59
|
}
|
|
58
60
|
if (commandItems.length) {
|
|
59
61
|
window.addEventListener('keydown', handleKeyDown);
|
|
@@ -5,6 +5,10 @@ import { COMMAND_PROMPT } from './constants';
|
|
|
5
5
|
export const createOnKeyDown = ()=>{
|
|
6
6
|
return (editor)=>{
|
|
7
7
|
return (event)=>{
|
|
8
|
+
// Support for different keyboard layouts:
|
|
9
|
+
// `isHotKey` uses by default `event.which`, which will never generates a match for all layouts (QWERTY: `/`, QWERTZ: `shift+7`)
|
|
10
|
+
// with `byKey: true` `isHotKey` uses `event.key` which will return the interpreted key '/'
|
|
11
|
+
// It would still fail without the the optional `shift?` param, as it first checks the modKeys (`shiftKey` would be true on QWERTZ)
|
|
8
12
|
if (isHotkey('shift?+/', {
|
|
9
13
|
byKey: true
|
|
10
14
|
}, event)) {
|
|
@@ -21,6 +25,7 @@ export const createOnKeyDown = ()=>{
|
|
|
21
25
|
const [, path] = getAboveNode(editor);
|
|
22
26
|
const range = getRange(editor, path);
|
|
23
27
|
if (isHotkey('backspace', event)) {
|
|
28
|
+
// if it is the last character in the command string
|
|
24
29
|
if (range.focus.offset - range.anchor.offset === 1) {
|
|
25
30
|
removeMark(editor, COMMAND_PROMPT, range);
|
|
26
31
|
}
|
|
@@ -9,7 +9,7 @@ jest.mock('../../internal/transforms', ()=>{
|
|
|
9
9
|
};
|
|
10
10
|
});
|
|
11
11
|
describe('onKeyDown', ()=>{
|
|
12
|
-
const { editor
|
|
12
|
+
const { editor } = createTestEditor({});
|
|
13
13
|
const addMark = jest.spyOn(internal, 'addMark');
|
|
14
14
|
const onCommandPaletteAction = jest.spyOn(editor.tracking, 'onCommandPaletteAction');
|
|
15
15
|
afterEach(()=>{
|
|
@@ -27,7 +27,7 @@ describe('onKeyDown', ()=>{
|
|
|
27
27
|
which: 55,
|
|
28
28
|
shiftKey: true
|
|
29
29
|
}}
|
|
30
|
-
`('supports hotKeys for every keyboard layout #{layout}', ({ key
|
|
30
|
+
`('supports hotKeys for every keyboard layout #{layout}', ({ key })=>{
|
|
31
31
|
createOnKeyDown()(editor, {})({
|
|
32
32
|
type: 'keydown',
|
|
33
33
|
...key
|
|
@@ -39,7 +39,7 @@ export function isCommandPromptPluginEnabled(sdk) {
|
|
|
39
39
|
}
|
|
40
40
|
function getCommandPermissions(sdk, editor) {
|
|
41
41
|
const canInsertBlocks = !isNodeTypeSelected(editor, BLOCKS.TABLE);
|
|
42
|
-
const { inlineAllowed
|
|
42
|
+
const { inlineAllowed, entriesAllowed, assetsAllowed } = isCommandPromptPluginEnabled(sdk);
|
|
43
43
|
return {
|
|
44
44
|
inlineAllowed,
|
|
45
45
|
entriesAllowed: entriesAllowed && canInsertBlocks,
|
|
@@ -68,7 +68,7 @@ const getAllowedContentTypesFromValidation = (validations)=>{
|
|
|
68
68
|
};
|
|
69
69
|
export const useCommands = (sdk, query, editor)=>{
|
|
70
70
|
const contentTypes = sdk.space.getCachedContentTypes();
|
|
71
|
-
const { inlineAllowed
|
|
71
|
+
const { inlineAllowed, entriesAllowed, assetsAllowed } = getCommandPermissions(sdk, editor);
|
|
72
72
|
const allowedContentTypesFromValidation = getAllowedContentTypesFromValidation(sdk.field.validations);
|
|
73
73
|
const filterContentTypesByValidation = (type)=>contentTypes.filter((contentType)=>allowedContentTypesFromValidation[type]?.[contentType.sys.id]);
|
|
74
74
|
const filteredBlockContentTypes = filterContentTypesByValidation(BLOCKS.EMBEDDED_ENTRY);
|
|
@@ -217,7 +217,7 @@ export const useCommands = (sdk, query, editor)=>{
|
|
|
217
217
|
}
|
|
218
218
|
return contentTypeCommands;
|
|
219
219
|
});
|
|
220
|
-
return query ? commands.reduce((list, nextItem)=>{
|
|
220
|
+
/* filter both commands and groups of commands with the user typed query */ return query ? commands.reduce((list, nextItem)=>{
|
|
221
221
|
if ('group' in nextItem) {
|
|
222
222
|
const subcommands = nextItem.commands.filter((command)=>{
|
|
223
223
|
return command.label.toLowerCase().includes(query.toLowerCase());
|
|
@@ -7,11 +7,13 @@ export async function fetchEntries(sdk, contentType, query) {
|
|
|
7
7
|
return entries.items.map((entry)=>{
|
|
8
8
|
const description = entityHelpers.getEntityDescription({
|
|
9
9
|
contentType,
|
|
10
|
+
// @ts-expect-error inconsistent in typing between app-sdk & field-editors-shared
|
|
10
11
|
entity: entry,
|
|
11
12
|
localeCode: sdk.field.locale,
|
|
12
13
|
defaultLocaleCode: sdk.locales.default
|
|
13
14
|
});
|
|
14
15
|
const displayTitle = entityHelpers.getEntryTitle({
|
|
16
|
+
// @ts-expect-error inconsistent in typing between app-sdk & field-editors-shared
|
|
15
17
|
entry,
|
|
16
18
|
contentType,
|
|
17
19
|
localeCode: sdk.field.locale,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Trim leading slash character if found. Bails otherwise.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* trimLeadingSlash("/my query") // --> "my query"
|
|
6
|
+
*/ export function trimLeadingSlash(text) {
|
|
2
7
|
if (!text.startsWith('/')) {
|
|
3
8
|
return text;
|
|
4
9
|
}
|
|
@@ -9,7 +9,11 @@ export function createDragAndDropPlugin() {
|
|
|
9
9
|
INLINES.EMBEDDED_ENTRY,
|
|
10
10
|
INLINES.EMBEDDED_RESOURCE
|
|
11
11
|
];
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* HTML node names where dropping should be allowed
|
|
14
|
+
* Usually for elements where `Transforms.removeNodes` is needed
|
|
15
|
+
* TODO: looking up for html nodes is not the best solution and it won't scale but it works fine for our current cases/elements
|
|
16
|
+
*/ const ON_DROP_ALLOWED_TYPES = {
|
|
13
17
|
TABLE: [
|
|
14
18
|
INLINES.EMBEDDED_ENTRY,
|
|
15
19
|
INLINES.EMBEDDED_RESOURCE
|
|
@@ -18,6 +22,7 @@ export function createDragAndDropPlugin() {
|
|
|
18
22
|
return {
|
|
19
23
|
key: 'DragAndDropPlugin',
|
|
20
24
|
handlers: {
|
|
25
|
+
// If true, the next handlers will be skipped.
|
|
21
26
|
onDrop: (editor)=>(event)=>{
|
|
22
27
|
const [draggingBlock] = Array.from(getNodeEntries(editor, {
|
|
23
28
|
match: (node)=>DRAGGABLE_TYPES.includes(node.type)
|
|
@@ -25,10 +30,13 @@ export function createDragAndDropPlugin() {
|
|
|
25
30
|
if (!draggingBlock) return false;
|
|
26
31
|
const [draggingNode] = draggingBlock;
|
|
27
32
|
if (!event.nativeEvent.target) return false;
|
|
33
|
+
// TODO: looking up for html nodes is not the best solution and it won't scale, we need to find a way to know the dropping target slate element
|
|
28
34
|
const dropDisallowed = getParents(event.nativeEvent.target).some((node)=>{
|
|
29
35
|
return ON_DROP_ALLOWED_TYPES[node.nodeName] ? !ON_DROP_ALLOWED_TYPES[node.nodeName]?.includes(draggingNode.type) : false;
|
|
30
36
|
});
|
|
31
37
|
if (!dropDisallowed) {
|
|
38
|
+
// Move the drop event to a new undo batch mitigating the bug where undo not only moves it back,
|
|
39
|
+
// but also undoes a previous action: https://github.com/ianstormtaylor/slate/issues/4694
|
|
32
40
|
editor.history.undos.push([]);
|
|
33
41
|
}
|
|
34
42
|
return dropDisallowed;
|
|
@@ -9,13 +9,13 @@ import { FetchingWrappedAssetCard } from '../shared/FetchingWrappedAssetCard';
|
|
|
9
9
|
import { FetchingWrappedEntryCard } from '../shared/FetchingWrappedEntryCard';
|
|
10
10
|
import { LinkedBlockWrapper } from '../shared/LinkedBlockWrapper';
|
|
11
11
|
export function LinkedEntityBlock(props) {
|
|
12
|
-
const { attributes
|
|
13
|
-
const { onEntityFetchComplete
|
|
12
|
+
const { attributes, children, element } = props;
|
|
13
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
14
14
|
const isSelected = useSelected();
|
|
15
15
|
const editor = useContentfulEditor();
|
|
16
16
|
const sdk = useSdkContext();
|
|
17
17
|
const isDisabled = useReadOnly();
|
|
18
|
-
const { id: entityId
|
|
18
|
+
const { id: entityId, linkType: entityType } = element.data.target.sys;
|
|
19
19
|
const handleEditClick = React.useCallback(()=>{
|
|
20
20
|
const openEntity = entityType === 'Asset' ? sdk.navigator.openAsset : sdk.navigator.openEntry;
|
|
21
21
|
return openEntity(entityId, {
|
|
@@ -36,9 +36,9 @@ export function LinkedEntityBlock(props) {
|
|
|
36
36
|
editor,
|
|
37
37
|
element
|
|
38
38
|
]);
|
|
39
|
-
return React.createElement(LinkedBlockWrapper, {
|
|
39
|
+
return /*#__PURE__*/ React.createElement(LinkedBlockWrapper, {
|
|
40
40
|
attributes: attributes,
|
|
41
|
-
card: React.createElement(React.Fragment, null, entityType === 'Entry' && React.createElement(FetchingWrappedEntryCard, {
|
|
41
|
+
card: /*#__PURE__*/ React.createElement(React.Fragment, null, entityType === 'Entry' && /*#__PURE__*/ React.createElement(FetchingWrappedEntryCard, {
|
|
42
42
|
sdk: sdk,
|
|
43
43
|
entryId: entityId,
|
|
44
44
|
locale: sdk.field.locale,
|
|
@@ -47,7 +47,7 @@ export function LinkedEntityBlock(props) {
|
|
|
47
47
|
onRemove: handleRemoveClick,
|
|
48
48
|
onEdit: handleEditClick,
|
|
49
49
|
onEntityFetchComplete: onEntityFetchComplete
|
|
50
|
-
}), entityType === 'Asset' && React.createElement(FetchingWrappedAssetCard, {
|
|
50
|
+
}), entityType === 'Asset' && /*#__PURE__*/ React.createElement(FetchingWrappedAssetCard, {
|
|
51
51
|
sdk: sdk,
|
|
52
52
|
assetId: entityId,
|
|
53
53
|
locale: sdk.field.locale,
|
|
@@ -6,7 +6,7 @@ import { ScheduledIconWithTooltip, useEntity, useEntityLoader } from '@contentfu
|
|
|
6
6
|
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
7
7
|
import { INLINES } from '@contentful/rich-text-types';
|
|
8
8
|
import { css } from 'emotion';
|
|
9
|
-
const { getEntryTitle
|
|
9
|
+
const { getEntryTitle, getEntryStatus } = entityHelpers;
|
|
10
10
|
const styles = {
|
|
11
11
|
scheduledIcon: css({
|
|
12
12
|
verticalAlign: 'text-bottom',
|
|
@@ -14,11 +14,11 @@ const styles = {
|
|
|
14
14
|
})
|
|
15
15
|
};
|
|
16
16
|
export function FetchingWrappedInlineEntryCard(props) {
|
|
17
|
-
const { data: entry
|
|
18
|
-
const { getEntityScheduledActions
|
|
17
|
+
const { data: entry, status: requestStatus } = useEntity('Entry', props.entryId);
|
|
18
|
+
const { getEntityScheduledActions } = useEntityLoader();
|
|
19
19
|
const loadEntityScheduledActions = ()=>getEntityScheduledActions('Entry', props.entryId);
|
|
20
20
|
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
21
|
-
const { onEntityFetchComplete
|
|
21
|
+
const { onEntityFetchComplete } = props;
|
|
22
22
|
const contentType = React.useMemo(()=>{
|
|
23
23
|
if (!entry || !allContentTypes) return undefined;
|
|
24
24
|
return allContentTypes.find((contentType)=>contentType.sys.id === entry.sys.contentType.sys.id);
|
|
@@ -49,25 +49,25 @@ export function FetchingWrappedInlineEntryCard(props) {
|
|
|
49
49
|
props.sdk.locales.default
|
|
50
50
|
]);
|
|
51
51
|
if (requestStatus === 'error') {
|
|
52
|
-
return React.createElement(InlineEntryCard, {
|
|
52
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
53
53
|
title: "Entry missing or inaccessible",
|
|
54
54
|
testId: INLINES.EMBEDDED_ENTRY,
|
|
55
55
|
isSelected: props.isSelected
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
if (requestStatus === 'loading') {
|
|
59
|
-
return React.createElement(InlineEntryCard, {
|
|
59
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
60
60
|
isLoading: true
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const entryStatus = getEntryStatus(entry.sys);
|
|
64
64
|
if (entryStatus === 'deleted') {
|
|
65
|
-
return React.createElement(InlineEntryCard, {
|
|
65
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
66
66
|
title: "Entry missing or inaccessible",
|
|
67
67
|
testId: INLINES.EMBEDDED_ENTRY,
|
|
68
68
|
isSelected: props.isSelected,
|
|
69
69
|
actions: [
|
|
70
|
-
React.createElement(MenuItem, {
|
|
70
|
+
/*#__PURE__*/ React.createElement(MenuItem, {
|
|
71
71
|
key: "remove",
|
|
72
72
|
onClick: props.onRemove,
|
|
73
73
|
testId: "delete"
|
|
@@ -75,30 +75,30 @@ export function FetchingWrappedInlineEntryCard(props) {
|
|
|
75
75
|
]
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
return React.createElement(InlineEntryCard, {
|
|
78
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
79
79
|
testId: INLINES.EMBEDDED_ENTRY,
|
|
80
80
|
isSelected: props.isSelected,
|
|
81
81
|
title: `${contentTypeName}: ${title}`,
|
|
82
82
|
status: entryStatus,
|
|
83
83
|
actions: [
|
|
84
|
-
React.createElement(MenuItem, {
|
|
84
|
+
/*#__PURE__*/ React.createElement(MenuItem, {
|
|
85
85
|
key: "edit",
|
|
86
86
|
onClick: props.onEdit
|
|
87
87
|
}, "Edit"),
|
|
88
|
-
React.createElement(MenuItem, {
|
|
88
|
+
/*#__PURE__*/ React.createElement(MenuItem, {
|
|
89
89
|
key: "remove",
|
|
90
90
|
onClick: props.onRemove,
|
|
91
91
|
disabled: props.isDisabled,
|
|
92
92
|
testId: "delete"
|
|
93
93
|
}, "Remove")
|
|
94
94
|
]
|
|
95
|
-
}, React.createElement(ScheduledIconWithTooltip, {
|
|
95
|
+
}, /*#__PURE__*/ React.createElement(ScheduledIconWithTooltip, {
|
|
96
96
|
getEntityScheduledActions: loadEntityScheduledActions,
|
|
97
97
|
entityType: "Entry",
|
|
98
98
|
entityId: entry.sys.id
|
|
99
|
-
}, React.createElement(ClockIcon, {
|
|
99
|
+
}, /*#__PURE__*/ React.createElement(ClockIcon, {
|
|
100
100
|
className: styles.scheduledIcon,
|
|
101
101
|
variant: "muted",
|
|
102
102
|
testId: "scheduled-icon"
|
|
103
|
-
})), React.createElement(Text, null, title));
|
|
103
|
+
})), /*#__PURE__*/ React.createElement(Text, null, title));
|
|
104
104
|
}
|
|
@@ -9,13 +9,13 @@ import { useLinkTracking } from '../links-tracking';
|
|
|
9
9
|
import { LinkedInlineWrapper } from '../shared/LinkedInlineWrapper';
|
|
10
10
|
import { FetchingWrappedInlineEntryCard } from './FetchingWrappedInlineEntryCard';
|
|
11
11
|
export function LinkedEntityInline(props) {
|
|
12
|
-
const { attributes
|
|
13
|
-
const { onEntityFetchComplete
|
|
12
|
+
const { attributes, children, element } = props;
|
|
13
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
14
14
|
const isSelected = useSelected();
|
|
15
15
|
const editor = useContentfulEditor();
|
|
16
16
|
const sdk = useSdkContext();
|
|
17
17
|
const isDisabled = useReadOnly();
|
|
18
|
-
const { id: entryId
|
|
18
|
+
const { id: entryId } = element.data.target.sys;
|
|
19
19
|
function handleEditClick() {
|
|
20
20
|
return sdk.navigator.openEntry(entryId, {
|
|
21
21
|
slideIn: {
|
|
@@ -32,9 +32,9 @@ export function LinkedEntityInline(props) {
|
|
|
32
32
|
at: pathToElement
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
return React.createElement(LinkedInlineWrapper, {
|
|
35
|
+
return /*#__PURE__*/ React.createElement(LinkedInlineWrapper, {
|
|
36
36
|
attributes: attributes,
|
|
37
|
-
card: React.createElement(FetchingWrappedInlineEntryCard, {
|
|
37
|
+
card: /*#__PURE__*/ React.createElement(FetchingWrappedInlineEntryCard, {
|
|
38
38
|
sdk: sdk,
|
|
39
39
|
entryId: entryId,
|
|
40
40
|
isSelected: isSelected,
|
|
@@ -7,8 +7,8 @@ import { useLinkTracking } from '../links-tracking';
|
|
|
7
7
|
import { FetchingWrappedResourceCard } from '../shared/FetchingWrappedResourceCard';
|
|
8
8
|
import { LinkedBlockWrapper } from '../shared/LinkedBlockWrapper';
|
|
9
9
|
export function LinkedResourceBlock(props) {
|
|
10
|
-
const { attributes
|
|
11
|
-
const { onEntityFetchComplete
|
|
10
|
+
const { attributes, children, element } = props;
|
|
11
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
12
12
|
const isSelected = useSelected();
|
|
13
13
|
const editor = useContentfulEditor();
|
|
14
14
|
const sdk = useSdkContext();
|
|
@@ -24,10 +24,10 @@ export function LinkedResourceBlock(props) {
|
|
|
24
24
|
editor,
|
|
25
25
|
element
|
|
26
26
|
]);
|
|
27
|
-
return React.createElement(LinkedBlockWrapper, {
|
|
27
|
+
return /*#__PURE__*/ React.createElement(LinkedBlockWrapper, {
|
|
28
28
|
attributes: attributes,
|
|
29
29
|
link: element.data.target,
|
|
30
|
-
card: React.createElement(FetchingWrappedResourceCard, {
|
|
30
|
+
card: /*#__PURE__*/ React.createElement(FetchingWrappedResourceCard, {
|
|
31
31
|
sdk: sdk,
|
|
32
32
|
link: link,
|
|
33
33
|
isDisabled: isDisabled,
|
|
@@ -4,10 +4,10 @@ import { useResource } from '@contentful/field-editor-reference';
|
|
|
4
4
|
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
5
5
|
import { INLINES } from '@contentful/rich-text-types';
|
|
6
6
|
import { truncateTitle } from '../../plugins/shared/utils';
|
|
7
|
-
const { getEntryTitle
|
|
7
|
+
const { getEntryTitle, getEntryStatus } = entityHelpers;
|
|
8
8
|
export function FetchingWrappedResourceInlineCard(props) {
|
|
9
|
-
const { link
|
|
10
|
-
const { data
|
|
9
|
+
const { link, onEntityFetchComplete } = props;
|
|
10
|
+
const { data, status: requestStatus } = useResource(link.linkType, link.urn);
|
|
11
11
|
React.useEffect(()=>{
|
|
12
12
|
if (requestStatus === 'success') {
|
|
13
13
|
onEntityFetchComplete?.();
|
|
@@ -17,18 +17,18 @@ export function FetchingWrappedResourceInlineCard(props) {
|
|
|
17
17
|
requestStatus
|
|
18
18
|
]);
|
|
19
19
|
if (requestStatus === 'error') {
|
|
20
|
-
return React.createElement(InlineEntryCard, {
|
|
20
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
21
21
|
title: "Entry missing or inaccessible",
|
|
22
22
|
testId: INLINES.EMBEDDED_RESOURCE,
|
|
23
23
|
isSelected: props.isSelected
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
if (requestStatus === 'loading' || data === undefined) {
|
|
27
|
-
return React.createElement(InlineEntryCard, {
|
|
27
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
28
28
|
isLoading: true
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
const { resource: entry
|
|
31
|
+
const { resource: entry, contentType, defaultLocaleCode, space } = data;
|
|
32
32
|
const title = getEntryTitle({
|
|
33
33
|
entry,
|
|
34
34
|
contentType,
|
|
@@ -38,18 +38,18 @@ export function FetchingWrappedResourceInlineCard(props) {
|
|
|
38
38
|
});
|
|
39
39
|
const truncatedTitle = truncateTitle(title, 40);
|
|
40
40
|
const status = getEntryStatus(entry.sys);
|
|
41
|
-
return React.createElement(InlineEntryCard, {
|
|
41
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
42
42
|
testId: INLINES.EMBEDDED_RESOURCE,
|
|
43
43
|
isSelected: props.isSelected,
|
|
44
44
|
title: `${contentType.name}: ${truncatedTitle} (Space: ${space.name} – Env.: ${entry.sys.environment.sys.id})`,
|
|
45
45
|
status: status,
|
|
46
46
|
actions: [
|
|
47
|
-
React.createElement(MenuItem, {
|
|
47
|
+
/*#__PURE__*/ React.createElement(MenuItem, {
|
|
48
48
|
key: "remove",
|
|
49
49
|
onClick: props.onRemove,
|
|
50
50
|
disabled: props.isDisabled,
|
|
51
51
|
testId: "delete"
|
|
52
52
|
}, "Remove")
|
|
53
53
|
]
|
|
54
|
-
}, React.createElement(Text, null, title));
|
|
54
|
+
}, /*#__PURE__*/ React.createElement(Text, null, title));
|
|
55
55
|
}
|
|
@@ -7,8 +7,8 @@ import { useLinkTracking } from '../links-tracking';
|
|
|
7
7
|
import { LinkedInlineWrapper } from '../shared/LinkedInlineWrapper';
|
|
8
8
|
import { FetchingWrappedResourceInlineCard } from './FetchingWrappedResourceInlineCard';
|
|
9
9
|
export function LinkedResourceInline(props) {
|
|
10
|
-
const { attributes
|
|
11
|
-
const { onEntityFetchComplete
|
|
10
|
+
const { attributes, children, element } = props;
|
|
11
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
12
12
|
const isSelected = useSelected();
|
|
13
13
|
const editor = useContentfulEditor();
|
|
14
14
|
const sdk = useSdkContext();
|
|
@@ -21,10 +21,10 @@ export function LinkedResourceInline(props) {
|
|
|
21
21
|
at: pathToElement
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
return React.createElement(LinkedInlineWrapper, {
|
|
24
|
+
return /*#__PURE__*/ React.createElement(LinkedInlineWrapper, {
|
|
25
25
|
attributes: attributes,
|
|
26
26
|
link: element.data.target,
|
|
27
|
-
card: React.createElement(FetchingWrappedResourceInlineCard, {
|
|
27
|
+
card: /*#__PURE__*/ React.createElement(FetchingWrappedResourceInlineCard, {
|
|
28
28
|
sdk: sdk,
|
|
29
29
|
link: link,
|
|
30
30
|
isDisabled: isDisabled,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { assertOutput, jsx } from '../../../test-utils';
|
|
1
|
+
/* eslint-disable react/no-unknown-property */ /** @jsx jsx */ import { assertOutput, jsx } from '../../../test-utils';
|
|
2
2
|
describe('normalization', ()=>{
|
|
3
3
|
it('can contain inline entries & hyperlinks', ()=>{
|
|
4
|
-
const input = jsx("editor", null, jsx("hh1", null, "some text before", jsx("hinline", {
|
|
4
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some text before", /*#__PURE__*/ jsx("hinline", {
|
|
5
5
|
type: "Entry",
|
|
6
6
|
id: "inline-entry"
|
|
7
|
-
}), jsx("hlink", {
|
|
7
|
+
}), /*#__PURE__*/ jsx("hlink", {
|
|
8
8
|
uri: "https://contentful.com"
|
|
9
|
-
}), jsx("hlink", {
|
|
9
|
+
}), /*#__PURE__*/ jsx("hlink", {
|
|
10
10
|
entry: "entry-id"
|
|
11
|
-
}), jsx("hlink", {
|
|
11
|
+
}), /*#__PURE__*/ jsx("hlink", {
|
|
12
12
|
resource: "resource-urn"
|
|
13
|
-
}), jsx("hlink", {
|
|
13
|
+
}), /*#__PURE__*/ jsx("hlink", {
|
|
14
14
|
asset: "asset-id"
|
|
15
|
-
}), "some text after"), jsx("hp", null, jsx("htext", null)));
|
|
15
|
+
}), "some text after"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
16
16
|
assertOutput({
|
|
17
17
|
input,
|
|
18
18
|
expected: input
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
it('unwraps nested paragraphs', ()=>{
|
|
22
|
-
const input = jsx("editor", null, jsx("hh1", null, "one", ' ', jsx("hp", null, "two ", jsx("hp", null, "three ")), "four"));
|
|
23
|
-
const expected = jsx("editor", null, jsx("hh1", null, "one two three four"), jsx("hp", null, jsx("htext", null)));
|
|
22
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "one", ' ', /*#__PURE__*/ jsx("hp", null, "two ", /*#__PURE__*/ jsx("hp", null, "three ")), "four"));
|
|
23
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "one two three four"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
24
24
|
assertOutput({
|
|
25
25
|
input,
|
|
26
26
|
expected
|
|
@@ -28,84 +28,84 @@ describe('normalization', ()=>{
|
|
|
28
28
|
});
|
|
29
29
|
describe('lifts other invalid children', ()=>{
|
|
30
30
|
it('block void elements', ()=>{
|
|
31
|
-
const input = jsx("editor", null, jsx("hh1", null, jsx("hembed", {
|
|
31
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("hembed", {
|
|
32
32
|
type: "Asset",
|
|
33
33
|
id: "1"
|
|
34
|
-
}), " start"), jsx("hh1", null, "end ", jsx("hembed", {
|
|
34
|
+
}), " start"), /*#__PURE__*/ jsx("hh1", null, "end ", /*#__PURE__*/ jsx("hembed", {
|
|
35
35
|
type: "Asset",
|
|
36
36
|
id: "2"
|
|
37
|
-
})), jsx("hh1", null, "in ", jsx("hembed", {
|
|
37
|
+
})), /*#__PURE__*/ jsx("hh1", null, "in ", /*#__PURE__*/ jsx("hembed", {
|
|
38
38
|
type: "Asset",
|
|
39
39
|
id: "3"
|
|
40
|
-
}), " between"), jsx("hh1", null, jsx("hembed", {
|
|
40
|
+
}), " between"), /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("hembed", {
|
|
41
41
|
type: "Entry",
|
|
42
42
|
id: "1"
|
|
43
|
-
}), " start"), jsx("hh1", null, "end ", jsx("hembed", {
|
|
43
|
+
}), " start"), /*#__PURE__*/ jsx("hh1", null, "end ", /*#__PURE__*/ jsx("hembed", {
|
|
44
44
|
type: "Entry",
|
|
45
45
|
id: "2"
|
|
46
|
-
})), jsx("hh1", null, "in ", jsx("hembed", {
|
|
46
|
+
})), /*#__PURE__*/ jsx("hh1", null, "in ", /*#__PURE__*/ jsx("hembed", {
|
|
47
47
|
type: "Entry",
|
|
48
48
|
id: "3"
|
|
49
|
-
}), " between"), jsx("hh1", null, jsx("hhr", null), " start"), jsx("hh1", null, "end ", jsx("hhr", null)), jsx("hh1", null, "in ", jsx("hhr", null), " between"));
|
|
50
|
-
const expected = jsx("editor", null, jsx("hembed", {
|
|
49
|
+
}), " between"), /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("hhr", null), " start"), /*#__PURE__*/ jsx("hh1", null, "end ", /*#__PURE__*/ jsx("hhr", null)), /*#__PURE__*/ jsx("hh1", null, "in ", /*#__PURE__*/ jsx("hhr", null), " between"));
|
|
50
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hembed", {
|
|
51
51
|
type: "Asset",
|
|
52
52
|
id: "1"
|
|
53
|
-
}), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hembed", {
|
|
53
|
+
}), /*#__PURE__*/ jsx("hh1", null, " start"), /*#__PURE__*/ jsx("hh1", null, "end "), /*#__PURE__*/ jsx("hembed", {
|
|
54
54
|
type: "Asset",
|
|
55
55
|
id: "2"
|
|
56
|
-
}), jsx("hh1", null, "in "), jsx("hembed", {
|
|
56
|
+
}), /*#__PURE__*/ jsx("hh1", null, "in "), /*#__PURE__*/ jsx("hembed", {
|
|
57
57
|
type: "Asset",
|
|
58
58
|
id: "3"
|
|
59
|
-
}), jsx("hh1", null, " between"), jsx("hembed", {
|
|
59
|
+
}), /*#__PURE__*/ jsx("hh1", null, " between"), /*#__PURE__*/ jsx("hembed", {
|
|
60
60
|
type: "Entry",
|
|
61
61
|
id: "1"
|
|
62
|
-
}), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hembed", {
|
|
62
|
+
}), /*#__PURE__*/ jsx("hh1", null, " start"), /*#__PURE__*/ jsx("hh1", null, "end "), /*#__PURE__*/ jsx("hembed", {
|
|
63
63
|
type: "Entry",
|
|
64
64
|
id: "2"
|
|
65
|
-
}), jsx("hh1", null, "in "), jsx("hembed", {
|
|
65
|
+
}), /*#__PURE__*/ jsx("hh1", null, "in "), /*#__PURE__*/ jsx("hembed", {
|
|
66
66
|
type: "Entry",
|
|
67
67
|
id: "3"
|
|
68
|
-
}), jsx("hh1", null, " between"), jsx("hhr", null), jsx("hh1", null, " start"), jsx("hh1", null, "end "), jsx("hhr", null), jsx("hh1", null, "in "), jsx("hhr", null), jsx("hh1", null, " between"), jsx("hp", null, jsx("htext", null)));
|
|
68
|
+
}), /*#__PURE__*/ jsx("hh1", null, " between"), /*#__PURE__*/ jsx("hhr", null), /*#__PURE__*/ jsx("hh1", null, " start"), /*#__PURE__*/ jsx("hh1", null, "end "), /*#__PURE__*/ jsx("hhr", null), /*#__PURE__*/ jsx("hh1", null, "in "), /*#__PURE__*/ jsx("hhr", null), /*#__PURE__*/ jsx("hh1", null, " between"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
69
69
|
assertOutput({
|
|
70
70
|
input,
|
|
71
71
|
expected
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
it('nested headings', ()=>{
|
|
75
|
-
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hh1", null, jsx("htext", {
|
|
75
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some", /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("htext", {
|
|
76
76
|
bold: true,
|
|
77
77
|
italic: true,
|
|
78
78
|
underline: true
|
|
79
79
|
}, "paragraph")), "text"));
|
|
80
|
-
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hh1", null, jsx("htext", {
|
|
80
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some"), /*#__PURE__*/ jsx("hh1", null, /*#__PURE__*/ jsx("htext", {
|
|
81
81
|
bold: true,
|
|
82
82
|
italic: true,
|
|
83
83
|
underline: true
|
|
84
|
-
}, "paragraph")), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
84
|
+
}, "paragraph")), /*#__PURE__*/ jsx("hh1", null, "text"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
85
85
|
assertOutput({
|
|
86
86
|
input,
|
|
87
87
|
expected
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
90
|
it('handles quotes', ()=>{
|
|
91
|
-
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hquote", null, jsx("hp", null, "quote")), "text"));
|
|
92
|
-
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hquote", null, jsx("hp", null, "quote")), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
91
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some", /*#__PURE__*/ jsx("hquote", null, /*#__PURE__*/ jsx("hp", null, "quote")), "text"));
|
|
92
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some"), /*#__PURE__*/ jsx("hquote", null, /*#__PURE__*/ jsx("hp", null, "quote")), /*#__PURE__*/ jsx("hh1", null, "text"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
93
93
|
assertOutput({
|
|
94
94
|
input,
|
|
95
95
|
expected
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
it('handles lists', ()=>{
|
|
99
|
-
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), "text"));
|
|
100
|
-
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "list item"))), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
99
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some", /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "list item"))), "text"));
|
|
100
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "list item"))), /*#__PURE__*/ jsx("hh1", null, "text"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
101
101
|
assertOutput({
|
|
102
102
|
input,
|
|
103
103
|
expected
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
106
|
it('handles tables', ()=>{
|
|
107
|
-
const input = jsx("editor", null, jsx("hh1", null, "some", jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2")))), "text"));
|
|
108
|
-
const expected = jsx("editor", null, jsx("hh1", null, "some"), jsx("htable", null, jsx("htr", null, jsx("htd", null, jsx("hp", null, "cell 1")), jsx("htd", null, jsx("hp", null, "cell 2")))), jsx("hh1", null, "text"), jsx("hp", null, jsx("htext", null)));
|
|
107
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some", /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 2")))), "text"));
|
|
108
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hh1", null, "some"), /*#__PURE__*/ jsx("htable", null, /*#__PURE__*/ jsx("htr", null, /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 1")), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "cell 2")))), /*#__PURE__*/ jsx("hh1", null, "text"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
109
109
|
assertOutput({
|
|
110
110
|
input,
|
|
111
111
|
expected
|
|
@@ -55,19 +55,20 @@ const styles = {
|
|
|
55
55
|
`
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: explain this disable
|
|
58
59
|
function createHeading(Tag, block) {
|
|
59
60
|
return function Heading(props) {
|
|
60
|
-
return React.createElement(Tag, {
|
|
61
|
+
return /*#__PURE__*/ React.createElement(Tag, {
|
|
61
62
|
...props.attributes,
|
|
62
63
|
className: cx(styles.headings.root, styles.headings[block])
|
|
63
64
|
}, props.children);
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
export const HeadingComponents = {
|
|
67
|
-
[BLOCKS.HEADING_1]: React.memo(createHeading('h1', BLOCKS.HEADING_1)),
|
|
68
|
-
[BLOCKS.HEADING_2]: React.memo(createHeading('h2', BLOCKS.HEADING_2)),
|
|
69
|
-
[BLOCKS.HEADING_3]: React.memo(createHeading('h3', BLOCKS.HEADING_3)),
|
|
70
|
-
[BLOCKS.HEADING_4]: React.memo(createHeading('h4', BLOCKS.HEADING_4)),
|
|
71
|
-
[BLOCKS.HEADING_5]: React.memo(createHeading('h5', BLOCKS.HEADING_5)),
|
|
72
|
-
[BLOCKS.HEADING_6]: React.memo(createHeading('h6', BLOCKS.HEADING_6))
|
|
68
|
+
[BLOCKS.HEADING_1]: /*#__PURE__*/ React.memo(createHeading('h1', BLOCKS.HEADING_1)),
|
|
69
|
+
[BLOCKS.HEADING_2]: /*#__PURE__*/ React.memo(createHeading('h2', BLOCKS.HEADING_2)),
|
|
70
|
+
[BLOCKS.HEADING_3]: /*#__PURE__*/ React.memo(createHeading('h3', BLOCKS.HEADING_3)),
|
|
71
|
+
[BLOCKS.HEADING_4]: /*#__PURE__*/ React.memo(createHeading('h4', BLOCKS.HEADING_4)),
|
|
72
|
+
[BLOCKS.HEADING_5]: /*#__PURE__*/ React.memo(createHeading('h5', BLOCKS.HEADING_5)),
|
|
73
|
+
[BLOCKS.HEADING_6]: /*#__PURE__*/ React.memo(createHeading('h6', BLOCKS.HEADING_6))
|
|
73
74
|
};
|