@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
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "LinkedBlockWrapper", {
|
|
|
8
8
|
return LinkedBlockWrapper;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_default(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
12
12
|
const _emotion = require("emotion");
|
|
13
13
|
const _environment = require("../../helpers/environment");
|
|
14
14
|
const _utils = require("./utils");
|
|
@@ -23,20 +23,24 @@ const styles = {
|
|
|
23
23
|
display: 'block'
|
|
24
24
|
}),
|
|
25
25
|
container: (0, _emotion.css)({
|
|
26
|
+
// The next 2 properties ensure Entity card won't be aligned above
|
|
27
|
+
// a list item marker (i.e. bullet)
|
|
26
28
|
display: 'inline-block',
|
|
27
29
|
verticalAlign: 'text-top',
|
|
28
30
|
width: '100%'
|
|
29
31
|
})
|
|
30
32
|
};
|
|
31
|
-
function LinkedBlockWrapper({ attributes
|
|
32
|
-
return _react.default.createElement("div", {
|
|
33
|
+
function LinkedBlockWrapper({ attributes, card, children, link }) {
|
|
34
|
+
return /*#__PURE__*/ _react.default.createElement("div", {
|
|
33
35
|
...attributes,
|
|
34
36
|
className: styles.root,
|
|
35
37
|
"data-entity-type": link.sys.linkType,
|
|
36
38
|
"data-entity-id": (0, _utils.getLinkEntityId)(link),
|
|
39
|
+
// COMPAT: This makes copy & paste work for Firefox
|
|
37
40
|
contentEditable: _environment.IS_CHROME ? undefined : false,
|
|
38
41
|
draggable: _environment.IS_CHROME ? true : undefined
|
|
39
|
-
}, _react.default.createElement("div", {
|
|
42
|
+
}, /*#__PURE__*/ _react.default.createElement("div", {
|
|
43
|
+
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
40
44
|
contentEditable: _environment.IS_CHROME ? false : undefined,
|
|
41
45
|
draggable: _environment.IS_CHROME ? true : undefined,
|
|
42
46
|
className: styles.container
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "LinkedInlineWrapper", {
|
|
|
8
8
|
return LinkedInlineWrapper;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
-
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
|
|
13
13
|
const _emotion = require("emotion");
|
|
14
14
|
const _environment = require("../../helpers/environment");
|
|
15
15
|
const _utils = require("./utils");
|
|
@@ -39,7 +39,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
39
39
|
if (cache && cache.has(obj)) {
|
|
40
40
|
return cache.get(obj);
|
|
41
41
|
}
|
|
42
|
-
var newObj = {
|
|
42
|
+
var newObj = {
|
|
43
|
+
__proto__: null
|
|
44
|
+
};
|
|
43
45
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
46
|
for(var key in obj){
|
|
45
47
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -70,15 +72,17 @@ const styles = {
|
|
|
70
72
|
}
|
|
71
73
|
})
|
|
72
74
|
};
|
|
73
|
-
function LinkedInlineWrapper({ attributes
|
|
74
|
-
return _react.createElement("span", {
|
|
75
|
+
function LinkedInlineWrapper({ attributes, card, children, link }) {
|
|
76
|
+
return /*#__PURE__*/ _react.createElement("span", {
|
|
75
77
|
...attributes,
|
|
76
78
|
className: styles.root,
|
|
77
79
|
"data-entity-type": link.sys.linkType,
|
|
78
80
|
"data-entity-id": (0, _utils.getLinkEntityId)(link),
|
|
81
|
+
// COMPAT: This makes copy & paste work for Firefox
|
|
79
82
|
contentEditable: _environment.IS_CHROME ? undefined : false,
|
|
80
83
|
draggable: _environment.IS_CHROME ? true : undefined
|
|
81
|
-
}, _react.createElement("span", {
|
|
84
|
+
}, /*#__PURE__*/ _react.createElement("span", {
|
|
85
|
+
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
82
86
|
contentEditable: _environment.IS_CHROME ? false : undefined,
|
|
83
87
|
draggable: _environment.IS_CHROME ? true : undefined
|
|
84
88
|
}, card), children);
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "ResourceNewBadge", {
|
|
|
8
8
|
return ResourceNewBadge;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
13
|
function _getRequireWildcardCache(nodeInterop) {
|
|
14
14
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -31,7 +31,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
31
31
|
if (cache && cache.has(obj)) {
|
|
32
32
|
return cache.get(obj);
|
|
33
33
|
}
|
|
34
|
-
var newObj = {
|
|
34
|
+
var newObj = {
|
|
35
|
+
__proto__: null
|
|
36
|
+
};
|
|
35
37
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
36
38
|
for(var key in obj){
|
|
37
39
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -50,7 +52,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
50
52
|
return newObj;
|
|
51
53
|
}
|
|
52
54
|
const ResourceNewBadge = ()=>{
|
|
53
|
-
return _react.createElement(_react.Fragment, null, ' ', "(different space)", ' ', _react.createElement(_f36components.Badge, {
|
|
55
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, ' ', "(different space)", ' ', /*#__PURE__*/ _react.createElement(_f36components.Badge, {
|
|
54
56
|
variant: "primary-filled",
|
|
55
57
|
size: "small"
|
|
56
58
|
}, "new"));
|
|
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "ToolbarButton", {
|
|
|
8
8
|
return ToolbarButton;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
11
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
|
-
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
13
|
+
const _f36tokens = /*#__PURE__*/ _interop_require_default(require("@contentful/f36-tokens"));
|
|
14
14
|
const _emotion = require("emotion");
|
|
15
15
|
function _interop_require_default(obj) {
|
|
16
16
|
return obj && obj.__esModule ? obj : {
|
|
@@ -38,7 +38,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
38
38
|
if (cache && cache.has(obj)) {
|
|
39
39
|
return cache.get(obj);
|
|
40
40
|
}
|
|
41
|
-
var newObj = {
|
|
41
|
+
var newObj = {
|
|
42
|
+
__proto__: null
|
|
43
|
+
};
|
|
42
44
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
45
|
for(var key in obj){
|
|
44
46
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -68,12 +70,12 @@ const styles = {
|
|
|
68
70
|
})
|
|
69
71
|
};
|
|
70
72
|
function ToolbarButton(props) {
|
|
71
|
-
const { title
|
|
73
|
+
const { title, testId, isActive, children, className, isDisabled = false } = props;
|
|
72
74
|
const handleClick = (event)=>{
|
|
73
75
|
event.preventDefault();
|
|
74
76
|
props.onClick();
|
|
75
77
|
};
|
|
76
|
-
const button = _react.createElement(_f36components.Button, {
|
|
78
|
+
const button = /*#__PURE__*/ _react.createElement(_f36components.Button, {
|
|
77
79
|
className: (0, _emotion.cx)(styles.button, className),
|
|
78
80
|
isDisabled: isDisabled,
|
|
79
81
|
startIcon: children,
|
|
@@ -83,7 +85,7 @@ function ToolbarButton(props) {
|
|
|
83
85
|
size: "small"
|
|
84
86
|
});
|
|
85
87
|
if (title) {
|
|
86
|
-
return _react.createElement(_f36components.Tooltip, {
|
|
88
|
+
return /*#__PURE__*/ _react.createElement(_f36components.Tooltip, {
|
|
87
89
|
className: styles.tooltip,
|
|
88
90
|
placement: "bottom",
|
|
89
91
|
content: title
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
7
7
|
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
8
8
|
require("@testing-library/jest-dom/extend-expect");
|
|
9
9
|
const _react1 = require("@testing-library/react");
|
|
10
|
-
const _published_assetjson = _interop_require_default(require("../__fixtures__/published_asset.json"));
|
|
10
|
+
const _published_assetjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/published_asset.json"));
|
|
11
11
|
const _FetchingWrappedAssetCard = require("../FetchingWrappedAssetCard");
|
|
12
12
|
function _interop_require_default(obj) {
|
|
13
13
|
return obj && obj.__esModule ? obj : {
|
|
@@ -35,7 +35,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
35
35
|
if (cache && cache.has(obj)) {
|
|
36
36
|
return cache.get(obj);
|
|
37
37
|
}
|
|
38
|
-
var newObj = {
|
|
38
|
+
var newObj = {
|
|
39
|
+
__proto__: null
|
|
40
|
+
};
|
|
39
41
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
42
|
for(var key in obj){
|
|
41
43
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -86,17 +88,20 @@ beforeEach(()=>{
|
|
|
86
88
|
};
|
|
87
89
|
});
|
|
88
90
|
test('some dropdown actions should be disabled', async ()=>{
|
|
89
|
-
const { getByTestId
|
|
91
|
+
const { getByTestId, queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_fieldeditorreference.EntityProvider, {
|
|
90
92
|
sdk: sdk
|
|
91
|
-
}, _react.createElement(_FetchingWrappedAssetCard.FetchingWrappedAssetCard, {
|
|
93
|
+
}, /*#__PURE__*/ _react.createElement(_FetchingWrappedAssetCard.FetchingWrappedAssetCard, {
|
|
92
94
|
sdk: sdk,
|
|
93
95
|
assetId: "asset-id",
|
|
94
96
|
locale: "en-US",
|
|
97
|
+
// eslint-disable-next-line -- TODO: explain this disable
|
|
95
98
|
onEdit: ()=>{},
|
|
99
|
+
// eslint-disable-next-line -- TODO: explain this disable
|
|
96
100
|
onRemove: ()=>{},
|
|
97
101
|
isDisabled: true,
|
|
98
102
|
isSelected: true
|
|
99
103
|
})));
|
|
104
|
+
// Assert Asset title
|
|
100
105
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-asset').textContent).toBe('asset title'));
|
|
101
106
|
_react1.fireEvent.click(getByTestId('cf-ui-card-actions'));
|
|
102
107
|
await (0, _react1.waitFor)(()=>{
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
7
7
|
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
8
8
|
require("@testing-library/jest-dom/extend-expect");
|
|
9
9
|
const _react1 = require("@testing-library/react");
|
|
10
|
-
const _published_content_typejson = _interop_require_default(require("../__fixtures__/published_content_type.json"));
|
|
11
|
-
const _published_entryjson = _interop_require_default(require("../__fixtures__/published_entry.json"));
|
|
10
|
+
const _published_content_typejson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/published_content_type.json"));
|
|
11
|
+
const _published_entryjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/published_entry.json"));
|
|
12
12
|
const _FetchingWrappedEntryCard = require("../FetchingWrappedEntryCard");
|
|
13
13
|
function _interop_require_default(obj) {
|
|
14
14
|
return obj && obj.__esModule ? obj : {
|
|
@@ -36,7 +36,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
36
36
|
if (cache && cache.has(obj)) {
|
|
37
37
|
return cache.get(obj);
|
|
38
38
|
}
|
|
39
|
-
var newObj = {
|
|
39
|
+
var newObj = {
|
|
40
|
+
__proto__: null
|
|
41
|
+
};
|
|
40
42
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
43
|
for(var key in obj){
|
|
42
44
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -90,17 +92,20 @@ beforeEach(()=>{
|
|
|
90
92
|
};
|
|
91
93
|
});
|
|
92
94
|
test('some dropdown actions should be disabled/removed', async ()=>{
|
|
93
|
-
const { getByTestId
|
|
95
|
+
const { getByTestId, queryByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_fieldeditorreference.EntityProvider, {
|
|
94
96
|
sdk: sdk
|
|
95
|
-
}, _react.createElement(_FetchingWrappedEntryCard.FetchingWrappedEntryCard, {
|
|
97
|
+
}, /*#__PURE__*/ _react.createElement(_FetchingWrappedEntryCard.FetchingWrappedEntryCard, {
|
|
96
98
|
sdk: sdk,
|
|
97
99
|
entryId: "entry-id",
|
|
98
100
|
locale: "en-US",
|
|
101
|
+
// eslint-disable-next-line -- TODO: explain this disable
|
|
99
102
|
onEdit: ()=>{},
|
|
103
|
+
// eslint-disable-next-line -- TODO: explain this disable
|
|
100
104
|
onRemove: ()=>{},
|
|
101
105
|
isDisabled: true,
|
|
102
106
|
isSelected: true
|
|
103
107
|
})));
|
|
108
|
+
// Assert Asset title
|
|
104
109
|
await (0, _react1.waitFor)(()=>expect(getByTestId('title').textContent).toBe('The best article ever'));
|
|
105
110
|
_react1.fireEvent.click(getByTestId('cf-ui-card-actions'));
|
|
106
111
|
await (0, _react1.waitFor)(()=>{
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
const _react = _interop_require_wildcard(require("react"));
|
|
5
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
6
6
|
require("@testing-library/jest-dom/extend-expect");
|
|
7
7
|
const _fieldeditorreference = require("@contentful/field-editor-reference");
|
|
8
8
|
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
9
9
|
const _react1 = require("@testing-library/react");
|
|
10
|
-
const _published_content_typejson = _interop_require_default(require("../__fixtures__/published_content_type.json"));
|
|
11
|
-
const _published_entryjson = _interop_require_default(require("../__fixtures__/published_entry.json"));
|
|
12
|
-
const _spacejson = _interop_require_default(require("../__fixtures__/space.json"));
|
|
10
|
+
const _published_content_typejson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/published_content_type.json"));
|
|
11
|
+
const _published_entryjson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/published_entry.json"));
|
|
12
|
+
const _spacejson = /*#__PURE__*/ _interop_require_default(require("../__fixtures__/space.json"));
|
|
13
13
|
const _FetchingWrappedResourceCard = require("../FetchingWrappedResourceCard");
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
@@ -37,7 +37,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
37
37
|
if (cache && cache.has(obj)) {
|
|
38
38
|
return cache.get(obj);
|
|
39
39
|
}
|
|
40
|
-
var newObj = {
|
|
40
|
+
var newObj = {
|
|
41
|
+
__proto__: null
|
|
42
|
+
};
|
|
41
43
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
44
|
for(var key in obj){
|
|
43
45
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -71,7 +73,7 @@ beforeEach(()=>{
|
|
|
71
73
|
get: jest.fn().mockReturnValue(_published_content_typejson.default)
|
|
72
74
|
},
|
|
73
75
|
Entry: {
|
|
74
|
-
get: jest.fn().mockImplementation(({ entryId
|
|
76
|
+
get: jest.fn().mockImplementation(({ entryId })=>{
|
|
75
77
|
if (entryId === 'linked-entry-urn') {
|
|
76
78
|
return Promise.resolve(_published_entryjson.default);
|
|
77
79
|
}
|
|
@@ -108,10 +110,10 @@ beforeEach(()=>{
|
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
112
|
});
|
|
111
|
-
function renderResourceCard({ linkType ='Contentful:Entry'
|
|
112
|
-
return (0, _react1.render)(_react.createElement(_fieldeditorreference.EntityProvider, {
|
|
113
|
+
function renderResourceCard({ linkType = 'Contentful:Entry', entryUrn = resolvableEntryUrn } = {}) {
|
|
114
|
+
return (0, _react1.render)(/*#__PURE__*/ _react.createElement(_fieldeditorreference.EntityProvider, {
|
|
113
115
|
sdk: sdk
|
|
114
|
-
}, _react.createElement(_FetchingWrappedResourceCard.FetchingWrappedResourceCard, {
|
|
116
|
+
}, /*#__PURE__*/ _react.createElement(_FetchingWrappedResourceCard.FetchingWrappedResourceCard, {
|
|
115
117
|
isDisabled: false,
|
|
116
118
|
isSelected: false,
|
|
117
119
|
sdk: sdk,
|
|
@@ -123,23 +125,23 @@ function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvabl
|
|
|
123
125
|
})));
|
|
124
126
|
}
|
|
125
127
|
test('renders entry card', async ()=>{
|
|
126
|
-
const { getByTestId
|
|
128
|
+
const { getByTestId, getByText } = renderResourceCard();
|
|
127
129
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
128
130
|
expect(getByText(_published_entryjson.default.fields.exField.en)).toBeDefined();
|
|
129
131
|
expect(getByText(_spacejson.default.name)).toBeDefined();
|
|
130
132
|
});
|
|
131
133
|
test('renders skeleton when no data is provided', ()=>{
|
|
132
|
-
const { getByTestId
|
|
134
|
+
const { getByTestId } = renderResourceCard();
|
|
133
135
|
expect(getByTestId('cf-ui-skeleton-form')).toBeDefined();
|
|
134
136
|
});
|
|
135
137
|
test('renders unsupported entity card when unsupported link is passed', async ()=>{
|
|
136
|
-
const { getByText
|
|
138
|
+
const { getByText } = renderResourceCard({
|
|
137
139
|
linkType: 'Contentful:UnsupportedLink'
|
|
138
140
|
});
|
|
139
141
|
await (0, _react1.waitFor)(()=>expect(getByText('Resource type Contentful:UnsupportedLink is currently not supported')).toBeDefined());
|
|
140
142
|
});
|
|
141
143
|
test('renders missing entity card when unknown error is returned', async ()=>{
|
|
142
|
-
const { getByTestId
|
|
144
|
+
const { getByTestId } = renderResourceCard({
|
|
143
145
|
entryUrn: unknownEntryUrn
|
|
144
146
|
});
|
|
145
147
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-missing-entry-card')).toBeDefined());
|
|
@@ -20,7 +20,10 @@ const isResourceLink = (link)=>!!link.sys.urn;
|
|
|
20
20
|
const getLinkEntityId = (link)=>isResourceLink(link) ? link.sys.urn : link.sys.id;
|
|
21
21
|
function truncateTitle(str, length) {
|
|
22
22
|
if (typeof str === 'string' && str.length > length) {
|
|
23
|
-
return str && str.substr(0, length + 1).
|
|
23
|
+
return str && str.substr(0, length + 1) // +1 to look ahead and be replaced below.
|
|
24
|
+
// Get rid of orphan letters but not one letter words (I, a, 2).
|
|
25
|
+
// Try to not have “.” as last character to avoid awkward “....”.
|
|
26
|
+
.replace(/(\s+\S(?=\S)|\s*)\.?.$/, '…');
|
|
24
27
|
}
|
|
25
28
|
return str;
|
|
26
29
|
}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "validateRichTextDocument", {
|
|
|
10
10
|
});
|
|
11
11
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
12
12
|
const _schemas = require("@contentful/rich-text-types/dist/schemas");
|
|
13
|
-
const _ajv = _interop_require_default(require("ajv"));
|
|
13
|
+
const _ajv = /*#__PURE__*/ _interop_require_default(require("ajv"));
|
|
14
14
|
function _interop_require_default(obj) {
|
|
15
15
|
return obj && obj.__esModule ? obj : {
|
|
16
16
|
default: obj
|
|
@@ -75,7 +75,7 @@ function buildSchemaErrors(validateSchema, _, errors) {
|
|
|
75
75
|
errors.push(...schemaErrors);
|
|
76
76
|
}
|
|
77
77
|
function resetChildNodes(node) {
|
|
78
|
-
const { content
|
|
78
|
+
const { content } = node;
|
|
79
79
|
if (isLeafNode(node)) {
|
|
80
80
|
return node;
|
|
81
81
|
}
|
|
@@ -84,7 +84,7 @@ function resetChildNodes(node) {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
function resetNode(node) {
|
|
87
|
-
const { nodeType
|
|
87
|
+
const { nodeType } = node;
|
|
88
88
|
if (_richtexttypes.helpers.isText(node)) {
|
|
89
89
|
return {
|
|
90
90
|
nodeType,
|
|
@@ -100,7 +100,7 @@ function resetNode(node) {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
function removeGrandChildNodes(node) {
|
|
103
|
-
const { content
|
|
103
|
+
const { content } = node;
|
|
104
104
|
if (isLeafNode(node)) {
|
|
105
105
|
return node;
|
|
106
106
|
}
|
|
@@ -119,7 +119,10 @@ function removeChildNodes(node) {
|
|
|
119
119
|
function isLeafNode(node) {
|
|
120
120
|
return _richtexttypes.helpers.isText(node) || !Array.isArray(node.content);
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Removes minItems errors occurred in grand-children to avoid
|
|
124
|
+
* false positives caused by the use of `removeGrandChildNodes`
|
|
125
|
+
*/ function removeGrandChildrenMinItemsErrors(errors) {
|
|
123
126
|
return errors.filter((error)=>{
|
|
124
127
|
const level = error.instancePath.split('/').length;
|
|
125
128
|
return !(level > 3 && error.keyword === 'minItems');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
import { usePlateEditorRef, usePlateEditorState } from './internal/hooks';
|
|
3
3
|
export function getContentfulEditorId(sdk) {
|
|
4
|
-
const { entry
|
|
4
|
+
const { entry, field } = sdk;
|
|
5
5
|
const sys = entry.getSys();
|
|
6
6
|
return `rich-text-editor-${sys.id}-${field.id}-${field.locale}`;
|
|
7
7
|
}
|
|
@@ -17,11 +17,14 @@ export function useContentfulEditorId(id) {
|
|
|
17
17
|
}
|
|
18
18
|
return contextId;
|
|
19
19
|
}
|
|
20
|
+
// This hook re-renders when the value changes
|
|
21
|
+
// Use case: Toolbar icons, for example
|
|
20
22
|
export function useContentfulEditor(id) {
|
|
21
23
|
const editorId = useContentfulEditorId(id);
|
|
22
24
|
const editor = usePlateEditorState(editorId);
|
|
23
25
|
return editor;
|
|
24
26
|
}
|
|
27
|
+
// This doesn't re-render when the value changes
|
|
25
28
|
export function useContentfulEditorRef(id) {
|
|
26
29
|
const editorId = useContentfulEditorId(id);
|
|
27
30
|
const editor = usePlateEditorRef(editorId);
|
|
@@ -16,7 +16,7 @@ import { SyncEditorChanges } from './SyncEditorChanges';
|
|
|
16
16
|
import Toolbar from './Toolbar';
|
|
17
17
|
import StickyToolbarWrapper from './Toolbar/components/StickyToolbarWrapper';
|
|
18
18
|
export const ConnectedRichTextEditor = (props)=>{
|
|
19
|
-
const { sdk
|
|
19
|
+
const { sdk, onAction, restrictedMarks } = props;
|
|
20
20
|
const id = getContentfulEditorId(sdk);
|
|
21
21
|
const plugins = React.useMemo(()=>getPlugins(sdk, onAction ?? noop, restrictedMarks), [
|
|
22
22
|
sdk,
|
|
@@ -37,26 +37,26 @@ export const ConnectedRichTextEditor = (props)=>{
|
|
|
37
37
|
}) : undefined, props.maxHeight !== undefined ? css({
|
|
38
38
|
maxHeight: props.maxHeight
|
|
39
39
|
}) : undefined, props.isDisabled ? styles.disabled : styles.enabled, props.isToolbarHidden && styles.hiddenToolbar);
|
|
40
|
-
return React.createElement(SdkProvider, {
|
|
40
|
+
return /*#__PURE__*/ React.createElement(SdkProvider, {
|
|
41
41
|
sdk: sdk
|
|
42
|
-
}, React.createElement(ContentfulEditorIdProvider, {
|
|
42
|
+
}, /*#__PURE__*/ React.createElement(ContentfulEditorIdProvider, {
|
|
43
43
|
value: id
|
|
44
|
-
}, React.createElement("div", {
|
|
44
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
45
45
|
className: styles.root,
|
|
46
46
|
"data-test-id": "rich-text-editor"
|
|
47
|
-
}, React.createElement(PlateProvider, {
|
|
47
|
+
}, /*#__PURE__*/ React.createElement(PlateProvider, {
|
|
48
48
|
id: id,
|
|
49
49
|
initialValue: initialValue,
|
|
50
50
|
plugins: plugins,
|
|
51
51
|
disableCorePlugins: disableCorePlugins
|
|
52
|
-
}, !props.isToolbarHidden && React.createElement(StickyToolbarWrapper, {
|
|
52
|
+
}, !props.isToolbarHidden && /*#__PURE__*/ React.createElement(StickyToolbarWrapper, {
|
|
53
53
|
isDisabled: props.isDisabled
|
|
54
|
-
}, React.createElement(Toolbar, {
|
|
54
|
+
}, /*#__PURE__*/ React.createElement(Toolbar, {
|
|
55
55
|
isDisabled: props.isDisabled
|
|
56
|
-
})), React.createElement(SyncEditorChanges, {
|
|
56
|
+
})), /*#__PURE__*/ React.createElement(SyncEditorChanges, {
|
|
57
57
|
incomingValue: initialValue,
|
|
58
58
|
onChange: props.onChange
|
|
59
|
-
}), React.createElement(Plate, {
|
|
59
|
+
}), /*#__PURE__*/ React.createElement(Plate, {
|
|
60
60
|
id: id,
|
|
61
61
|
editableProps: {
|
|
62
62
|
className: classNames,
|
|
@@ -65,18 +65,18 @@ export const ConnectedRichTextEditor = (props)=>{
|
|
|
65
65
|
})))));
|
|
66
66
|
};
|
|
67
67
|
const RichTextEditor = (props)=>{
|
|
68
|
-
const { sdk
|
|
68
|
+
const { sdk, isInitiallyDisabled, onAction, restrictedMarks, ...otherProps } = props;
|
|
69
69
|
const isEmptyValue = React.useCallback((value)=>!value || deepEquals(value, Contentful.EMPTY_DOCUMENT), []);
|
|
70
70
|
const id = getContentfulEditorId(props.sdk);
|
|
71
|
-
return React.createElement(EntityProvider, {
|
|
71
|
+
return /*#__PURE__*/ React.createElement(EntityProvider, {
|
|
72
72
|
sdk: sdk
|
|
73
|
-
}, React.createElement(FieldConnector, {
|
|
73
|
+
}, /*#__PURE__*/ React.createElement(FieldConnector, {
|
|
74
74
|
debounce: 0,
|
|
75
75
|
field: sdk.field,
|
|
76
76
|
isInitiallyDisabled: isInitiallyDisabled,
|
|
77
77
|
isEmptyValue: isEmptyValue,
|
|
78
78
|
isEqualValues: deepEquals
|
|
79
|
-
}, ({ lastRemoteValue
|
|
79
|
+
}, ({ lastRemoteValue, disabled, setValue })=>/*#__PURE__*/ React.createElement(ConnectedRichTextEditor, {
|
|
80
80
|
...otherProps,
|
|
81
81
|
key: `rich-text-editor-${id}`,
|
|
82
82
|
value: lastRemoteValue,
|
package/dist/esm/SdkProvider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import constate from 'constate';
|
|
3
|
-
function useSdk({ sdk
|
|
4
|
-
const sdkMemo = React.useMemo(()=>sdk, []);
|
|
3
|
+
function useSdk({ sdk }) {
|
|
4
|
+
const sdkMemo = React.useMemo(()=>sdk, []); // eslint-disable-line -- TODO: explain this disable
|
|
5
5
|
return sdkMemo;
|
|
6
6
|
}
|
|
7
7
|
export const [SdkProvider, useSdkContext] = constate(useSdk);
|
|
@@ -4,8 +4,12 @@ import equal from 'fast-deep-equal';
|
|
|
4
4
|
import { createOnChangeCallback } from './helpers/callbacks';
|
|
5
5
|
import { usePlateSelectors } from './internal/hooks';
|
|
6
6
|
import { setEditorValue } from './internal/transforms';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* A hook responsible for keeping the editor state in sync with incoming
|
|
9
|
+
* changes (aka. external updates
|
|
10
|
+
*/ const useAcceptIncomingChanges = (incomingValue)=>{
|
|
8
11
|
const editor = usePlateSelectors().editor();
|
|
12
|
+
// Cache latest editor value to avoid unnecessary updates
|
|
9
13
|
const lastIncomingValue = React.useRef(incomingValue);
|
|
10
14
|
React.useEffect(()=>{
|
|
11
15
|
if (equal(lastIncomingValue.current, incomingValue)) {
|
|
@@ -18,13 +22,16 @@ const useAcceptIncomingChanges = (incomingValue)=>{
|
|
|
18
22
|
incomingValue
|
|
19
23
|
]);
|
|
20
24
|
};
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Attaches a custom onChange callback that
|
|
27
|
+
*/ const useOnValueChanged = (onChange)=>{
|
|
22
28
|
const editor = usePlateSelectors().editor();
|
|
23
29
|
const setEditorOnChange = usePlateActions().onChange();
|
|
24
30
|
React.useEffect(()=>{
|
|
25
31
|
const cb = createOnChangeCallback(onChange);
|
|
26
32
|
setEditorOnChange({
|
|
27
33
|
fn: (document)=>{
|
|
34
|
+
// Skip irrelevant events e.g. mouse selection
|
|
28
35
|
const operations = editor?.operations.filter((op)=>{
|
|
29
36
|
return op.type !== 'set_selection';
|
|
30
37
|
});
|
|
@@ -40,7 +47,15 @@ const useOnValueChanged = (onChange)=>{
|
|
|
40
47
|
setEditorOnChange
|
|
41
48
|
]);
|
|
42
49
|
};
|
|
43
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A void component that's responsible for keeping the editor
|
|
52
|
+
* state in sync with incoming changes (aka. external updates) and
|
|
53
|
+
* triggering onChange events.
|
|
54
|
+
*
|
|
55
|
+
* This component is a hack to work around the limitation of Plate v17+
|
|
56
|
+
* where we can no longer access the editor instance outside the Plate
|
|
57
|
+
* provider.
|
|
58
|
+
*/ export const SyncEditorChanges = ({ incomingValue, onChange })=>{
|
|
44
59
|
useAcceptIncomingChanges(incomingValue);
|
|
45
60
|
useOnValueChanged(onChange);
|
|
46
61
|
return null;
|
|
@@ -37,13 +37,13 @@ describe('Toolbar', ()=>{
|
|
|
37
37
|
test('everything on the toolbar should be disabled', async ()=>{
|
|
38
38
|
const sdk = mockSdk();
|
|
39
39
|
const id = getContentfulEditorId(sdk);
|
|
40
|
-
const { getByTestId
|
|
40
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(Plate, {
|
|
41
41
|
id: id
|
|
42
|
-
}, React.createElement(SdkProvider, {
|
|
42
|
+
}, /*#__PURE__*/ React.createElement(SdkProvider, {
|
|
43
43
|
sdk: sdk
|
|
44
|
-
}, React.createElement(ContentfulEditorIdProvider, {
|
|
44
|
+
}, /*#__PURE__*/ React.createElement(ContentfulEditorIdProvider, {
|
|
45
45
|
value: id
|
|
46
|
-
}, React.createElement(Toolbar, {
|
|
46
|
+
}, /*#__PURE__*/ React.createElement(Toolbar, {
|
|
47
47
|
isDisabled: true
|
|
48
48
|
})))));
|
|
49
49
|
await waitFor(()=>{
|
|
@@ -71,13 +71,13 @@ describe('Toolbar', ()=>{
|
|
|
71
71
|
MARKS.SUPERSCRIPT
|
|
72
72
|
]);
|
|
73
73
|
const id = getContentfulEditorId(sdk);
|
|
74
|
-
const { queryByTestId
|
|
74
|
+
const { queryByTestId } = render(/*#__PURE__*/ React.createElement(Plate, {
|
|
75
75
|
id: id
|
|
76
|
-
}, React.createElement(SdkProvider, {
|
|
76
|
+
}, /*#__PURE__*/ React.createElement(SdkProvider, {
|
|
77
77
|
sdk: sdk
|
|
78
|
-
}, React.createElement(ContentfulEditorIdProvider, {
|
|
78
|
+
}, /*#__PURE__*/ React.createElement(ContentfulEditorIdProvider, {
|
|
79
79
|
value: id
|
|
80
|
-
}, React.createElement(Toolbar, {
|
|
80
|
+
}, /*#__PURE__*/ React.createElement(Toolbar, {
|
|
81
81
|
isDisabled: true
|
|
82
82
|
})))));
|
|
83
83
|
expect(queryByTestId('dropdown-toolbar-button')).toBeVisible();
|
|
@@ -89,13 +89,13 @@ describe('Toolbar', ()=>{
|
|
|
89
89
|
MARKS.CODE
|
|
90
90
|
]);
|
|
91
91
|
const id = getContentfulEditorId(sdk);
|
|
92
|
-
const { queryByTestId
|
|
92
|
+
const { queryByTestId } = render(/*#__PURE__*/ React.createElement(Plate, {
|
|
93
93
|
id: id
|
|
94
|
-
}, React.createElement(SdkProvider, {
|
|
94
|
+
}, /*#__PURE__*/ React.createElement(SdkProvider, {
|
|
95
95
|
sdk: sdk
|
|
96
|
-
}, React.createElement(ContentfulEditorIdProvider, {
|
|
96
|
+
}, /*#__PURE__*/ React.createElement(ContentfulEditorIdProvider, {
|
|
97
97
|
value: id
|
|
98
|
-
}, React.createElement(Toolbar, {
|
|
98
|
+
}, /*#__PURE__*/ React.createElement(Toolbar, {
|
|
99
99
|
isDisabled: true
|
|
100
100
|
})))));
|
|
101
101
|
expect(queryByTestId('dropdown-toolbar-button')).not.toBeInTheDocument();
|