@contentful/field-editor-rich-text 3.14.3 → 3.15.1
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 +17 -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 +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 +7 -5
- package/dist/cjs/plugins/Hyperlink/utils.js +6 -14
- 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 +20 -3
- 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 +13 -11
- 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 +3 -3
- package/dist/esm/plugins/Hyperlink/utils.js +2 -7
- 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 +9 -0
- 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/dist/types/plugins/Hyperlink/utils.d.ts +0 -1
- package/dist/types/plugins/shared/utils.d.ts +1 -0
- package/package.json +2 -2
|
@@ -7,47 +7,47 @@ import { useSdkContext } from '../../../SdkProvider';
|
|
|
7
7
|
import { useCommandList } from '../hooks/useCommandList';
|
|
8
8
|
import { useCommands } from '../useCommands';
|
|
9
9
|
import styles from './CommandList.styles';
|
|
10
|
-
const Group = ({ commandGroup
|
|
10
|
+
const Group = ({ commandGroup, selectedItem })=>/*#__PURE__*/ React.createElement("section", {
|
|
11
11
|
key: commandGroup.group
|
|
12
|
-
}, React.createElement(SectionHeading, {
|
|
12
|
+
}, /*#__PURE__*/ React.createElement(SectionHeading, {
|
|
13
13
|
as: "h3",
|
|
14
14
|
marginBottom: "spacingS",
|
|
15
15
|
marginTop: "spacingS",
|
|
16
16
|
marginLeft: "spacingM",
|
|
17
17
|
marginRight: "spacingM"
|
|
18
|
-
}, commandGroup.group), commandGroup.commands.map((command)
|
|
18
|
+
}, commandGroup.group), commandGroup.commands.map((command)=>/*#__PURE__*/ React.createElement("button", {
|
|
19
19
|
key: command.id,
|
|
20
20
|
id: command.id,
|
|
21
21
|
className: cx(styles.menuItem, {
|
|
22
22
|
[styles.menuItemSelected]: command.id === selectedItem
|
|
23
23
|
}),
|
|
24
24
|
onClick: command.callback
|
|
25
|
-
}, command.label)), React.createElement("hr", {
|
|
25
|
+
}, command.label)), /*#__PURE__*/ React.createElement("hr", {
|
|
26
26
|
className: styles.menuDivider,
|
|
27
27
|
"aria-orientation": "horizontal"
|
|
28
28
|
}));
|
|
29
|
-
const Asset = ({ command
|
|
29
|
+
const Asset = ({ command, selectedItem })=>/*#__PURE__*/ React.createElement("button", {
|
|
30
30
|
key: command.id,
|
|
31
31
|
id: command.id,
|
|
32
32
|
className: cx(styles.menuItem, {
|
|
33
33
|
[styles.menuItemSelected]: command.id === selectedItem
|
|
34
34
|
}),
|
|
35
35
|
onClick: command.callback
|
|
36
|
-
}, React.createElement(Flex, {
|
|
36
|
+
}, /*#__PURE__*/ React.createElement(Flex, {
|
|
37
37
|
alignItems: "center",
|
|
38
38
|
gap: "spacingS"
|
|
39
|
-
}, command.thumbnail ? React.createElement("img", {
|
|
39
|
+
}, command.thumbnail ? /*#__PURE__*/ React.createElement("img", {
|
|
40
40
|
width: "30",
|
|
41
41
|
height: "30",
|
|
42
42
|
src: command.thumbnail,
|
|
43
43
|
alt: "",
|
|
44
44
|
className: styles.thumbnail
|
|
45
|
-
}) : React.createElement(AssetIcon, {
|
|
45
|
+
}) : /*#__PURE__*/ React.createElement(AssetIcon, {
|
|
46
46
|
width: "30",
|
|
47
47
|
height: "30",
|
|
48
48
|
className: styles.thumbnail
|
|
49
|
-
}), React.createElement("span", null, command.label)));
|
|
50
|
-
const Item = ({ command
|
|
49
|
+
}), /*#__PURE__*/ React.createElement("span", null, command.label)));
|
|
50
|
+
const Item = ({ command, selectedItem })=>/*#__PURE__*/ React.createElement("button", {
|
|
51
51
|
key: command.id,
|
|
52
52
|
id: command.id,
|
|
53
53
|
className: cx(styles.menuItem, {
|
|
@@ -55,70 +55,70 @@ const Item = ({ command , selectedItem })=>React.createElement("button", {
|
|
|
55
55
|
}),
|
|
56
56
|
onClick: command.callback
|
|
57
57
|
}, command.label);
|
|
58
|
-
const CommandListItems = ({ commandItems
|
|
59
|
-
return React.createElement(React.Fragment, null, commandItems.map((command)=>{
|
|
60
|
-
return 'group' in command ? React.createElement(Group, {
|
|
58
|
+
const CommandListItems = ({ commandItems, selectedItem })=>{
|
|
59
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, commandItems.map((command)=>{
|
|
60
|
+
return 'group' in command ? /*#__PURE__*/ React.createElement(Group, {
|
|
61
61
|
key: command.group,
|
|
62
62
|
commandGroup: command,
|
|
63
63
|
selectedItem: selectedItem
|
|
64
|
-
}) : command.asset ? React.createElement(Asset, {
|
|
64
|
+
}) : command.asset ? /*#__PURE__*/ React.createElement(Asset, {
|
|
65
65
|
key: command.id,
|
|
66
66
|
command: command,
|
|
67
67
|
selectedItem: selectedItem
|
|
68
|
-
}) : React.createElement(Item, {
|
|
68
|
+
}) : /*#__PURE__*/ React.createElement(Item, {
|
|
69
69
|
key: command.id,
|
|
70
70
|
command: command,
|
|
71
71
|
selectedItem: selectedItem
|
|
72
72
|
});
|
|
73
73
|
}));
|
|
74
74
|
};
|
|
75
|
-
export const CommandList = ({ query
|
|
75
|
+
export const CommandList = ({ query, editor, textContainer })=>{
|
|
76
76
|
const sdk = useSdkContext();
|
|
77
77
|
const popoverContainer = React.useRef(null);
|
|
78
78
|
const popper = usePopper(textContainer, popoverContainer?.current, {
|
|
79
79
|
placement: 'bottom-start'
|
|
80
80
|
});
|
|
81
81
|
const commandItems = useCommands(sdk, query, editor);
|
|
82
|
-
const { selectedItem
|
|
82
|
+
const { selectedItem, isOpen } = useCommandList(commandItems, popoverContainer);
|
|
83
83
|
if (!commandItems.length) {
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
|
-
return React.createElement("div", {
|
|
86
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
87
87
|
className: styles.container,
|
|
88
88
|
tabIndex: -1,
|
|
89
89
|
contentEditable: false
|
|
90
|
-
}, React.createElement("div", {
|
|
90
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
91
91
|
role: "alert"
|
|
92
|
-
}, React.createElement(ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", React.createElement("kbd", null, "enter"), " to select, ", React.createElement("kbd", null, "arrows"), " to navigate, ", React.createElement("kbd", null, "escape"), " to close.")), React.createElement(Portal, null, React.createElement("div", {
|
|
92
|
+
}, /*#__PURE__*/ React.createElement(ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/ React.createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/ React.createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/ React.createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/ React.createElement(Portal, null, /*#__PURE__*/ React.createElement("div", {
|
|
93
93
|
"aria-hidden": true,
|
|
94
94
|
ref: popoverContainer,
|
|
95
95
|
className: styles.menuPoper,
|
|
96
96
|
style: popper.styles.popper,
|
|
97
97
|
...popper.attributes.popper
|
|
98
|
-
}, React.createElement(Popover, {
|
|
98
|
+
}, /*#__PURE__*/ React.createElement(Popover, {
|
|
99
99
|
isOpen: isOpen,
|
|
100
100
|
usePortal: false,
|
|
101
|
-
autoFocus: false
|
|
102
|
-
}, React.createElement(Popover.Trigger, null, React.createElement("span", null)), React.createElement(Popover.Content, {
|
|
101
|
+
/* eslint-disable-next-line jsx-a11y/no-autofocus -- we want to keep focus on text input*/ autoFocus: false
|
|
102
|
+
}, /*#__PURE__*/ React.createElement(Popover.Trigger, null, /*#__PURE__*/ React.createElement("span", null)), /*#__PURE__*/ React.createElement(Popover.Content, {
|
|
103
103
|
className: styles.menuContent,
|
|
104
104
|
testId: "rich-text-commands"
|
|
105
|
-
}, React.createElement("header", {
|
|
105
|
+
}, /*#__PURE__*/ React.createElement("header", {
|
|
106
106
|
className: styles.menuHeader
|
|
107
|
-
}, React.createElement(SectionHeading, {
|
|
107
|
+
}, /*#__PURE__*/ React.createElement(SectionHeading, {
|
|
108
108
|
marginBottom: "none"
|
|
109
|
-
}, "Richtext commands")), React.createElement("div", {
|
|
109
|
+
}, "Richtext commands")), /*#__PURE__*/ React.createElement("div", {
|
|
110
110
|
className: styles.menuList,
|
|
111
111
|
"data-test-id": "rich-text-commands-list"
|
|
112
|
-
}, React.createElement(CommandListItems, {
|
|
112
|
+
}, /*#__PURE__*/ React.createElement(CommandListItems, {
|
|
113
113
|
commandItems: commandItems,
|
|
114
114
|
selectedItem: selectedItem
|
|
115
|
-
})), React.createElement("footer", {
|
|
115
|
+
})), /*#__PURE__*/ React.createElement("footer", {
|
|
116
116
|
className: styles.menuFooter
|
|
117
|
-
}, React.createElement(Stack, {
|
|
117
|
+
}, /*#__PURE__*/ React.createElement(Stack, {
|
|
118
118
|
as: "ul",
|
|
119
119
|
margin: "none",
|
|
120
120
|
padding: "none",
|
|
121
121
|
spacing: "spacingS",
|
|
122
122
|
className: styles.footerList
|
|
123
|
-
}, React.createElement("li", null, React.createElement("kbd", null, "↑"), React.createElement("kbd", null, "↓"), " to navigate"), React.createElement("li", null, React.createElement("kbd", null, "↵"), " to confirm"), React.createElement("li", null, React.createElement("kbd", null, "esc"), " to close"))))))));
|
|
123
|
+
}, /*#__PURE__*/ React.createElement("li", null, /*#__PURE__*/ React.createElement("kbd", null, "↑"), /*#__PURE__*/ React.createElement("kbd", null, "↓"), " to navigate"), /*#__PURE__*/ React.createElement("li", null, /*#__PURE__*/ React.createElement("kbd", null, "↵"), " to confirm"), /*#__PURE__*/ React.createElement("li", null, /*#__PURE__*/ React.createElement("kbd", null, "esc"), " to close"))))))));
|
|
124
124
|
};
|
|
@@ -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,
|
|
@@ -3,10 +3,11 @@ import { InlineEntryCard, MenuItem, Text } from '@contentful/f36-components';
|
|
|
3
3
|
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, getEntryStatus } = entityHelpers;
|
|
7
8
|
export function FetchingWrappedResourceInlineCard(props) {
|
|
8
|
-
const { link
|
|
9
|
-
const { data
|
|
9
|
+
const { link, onEntityFetchComplete } = props;
|
|
10
|
+
const { data, status: requestStatus } = useResource(link.linkType, link.urn);
|
|
10
11
|
React.useEffect(()=>{
|
|
11
12
|
if (requestStatus === 'success') {
|
|
12
13
|
onEntityFetchComplete?.();
|
|
@@ -16,18 +17,18 @@ export function FetchingWrappedResourceInlineCard(props) {
|
|
|
16
17
|
requestStatus
|
|
17
18
|
]);
|
|
18
19
|
if (requestStatus === 'error') {
|
|
19
|
-
return React.createElement(InlineEntryCard, {
|
|
20
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
20
21
|
title: "Entry missing or inaccessible",
|
|
21
22
|
testId: INLINES.EMBEDDED_RESOURCE,
|
|
22
23
|
isSelected: props.isSelected
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
if (requestStatus === 'loading' || data === undefined) {
|
|
26
|
-
return React.createElement(InlineEntryCard, {
|
|
27
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
27
28
|
isLoading: true
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
const { resource: entry
|
|
31
|
+
const { resource: entry, contentType, defaultLocaleCode, space } = data;
|
|
31
32
|
const title = getEntryTitle({
|
|
32
33
|
entry,
|
|
33
34
|
contentType,
|
|
@@ -35,19 +36,20 @@ export function FetchingWrappedResourceInlineCard(props) {
|
|
|
35
36
|
localeCode: defaultLocaleCode,
|
|
36
37
|
defaultTitle: 'Untitled'
|
|
37
38
|
});
|
|
38
|
-
const
|
|
39
|
-
|
|
39
|
+
const truncatedTitle = truncateTitle(title, 40);
|
|
40
|
+
const status = getEntryStatus(entry.sys);
|
|
41
|
+
return /*#__PURE__*/ React.createElement(InlineEntryCard, {
|
|
40
42
|
testId: INLINES.EMBEDDED_RESOURCE,
|
|
41
43
|
isSelected: props.isSelected,
|
|
42
|
-
title: `${
|
|
44
|
+
title: `${contentType.name}: ${truncatedTitle} (Space: ${space.name} – Env.: ${entry.sys.environment.sys.id})`,
|
|
43
45
|
status: status,
|
|
44
46
|
actions: [
|
|
45
|
-
React.createElement(MenuItem, {
|
|
47
|
+
/*#__PURE__*/ React.createElement(MenuItem, {
|
|
46
48
|
key: "remove",
|
|
47
49
|
onClick: props.onRemove,
|
|
48
50
|
disabled: props.isDisabled,
|
|
49
51
|
testId: "delete"
|
|
50
52
|
}, "Remove")
|
|
51
53
|
]
|
|
52
|
-
}, React.createElement(Text, null, title));
|
|
54
|
+
}, /*#__PURE__*/ React.createElement(Text, null, title));
|
|
53
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,
|