@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
|
@@ -58,7 +58,7 @@ export function ToolbarHeadingButton(props) {
|
|
|
58
58
|
}, [
|
|
59
59
|
editor?.operations,
|
|
60
60
|
editor?.selection
|
|
61
|
-
]);
|
|
61
|
+
]); // eslint-disable-line -- TODO: explain this disable
|
|
62
62
|
const [nodeTypesByEnablement, someHeadingsEnabled] = React.useMemo(()=>{
|
|
63
63
|
const nodeTypesByEnablement = Object.fromEntries(Object.keys(LABELS).map((nodeType)=>[
|
|
64
64
|
nodeType,
|
|
@@ -79,7 +79,13 @@ export function ToolbarHeadingButton(props) {
|
|
|
79
79
|
setSelected(type);
|
|
80
80
|
setOpen(false);
|
|
81
81
|
const prevOnChange = editor.onChange;
|
|
82
|
-
|
|
82
|
+
/*
|
|
83
|
+
The focus might happen at point in time when
|
|
84
|
+
`toggleElement` (helper for toggleNodeType) changes aren't rendered yet, causing the browser
|
|
85
|
+
to place the cursor at the start of the text.
|
|
86
|
+
We wait for the change event before focusing
|
|
87
|
+
the editor again. This ensures the cursor is back at the previous
|
|
88
|
+
position.*/ editor.onChange = (...args)=>{
|
|
83
89
|
focus(editor);
|
|
84
90
|
editor.onChange = prevOnChange;
|
|
85
91
|
prevOnChange(...args);
|
|
@@ -95,25 +101,25 @@ export function ToolbarHeadingButton(props) {
|
|
|
95
101
|
};
|
|
96
102
|
}
|
|
97
103
|
if (!editor) return null;
|
|
98
|
-
return React.createElement(Menu, {
|
|
104
|
+
return /*#__PURE__*/ React.createElement(Menu, {
|
|
99
105
|
isOpen: isOpen,
|
|
100
106
|
onClose: ()=>setOpen(false)
|
|
101
|
-
}, React.createElement(Menu.Trigger, null, React.createElement(Button, {
|
|
107
|
+
}, /*#__PURE__*/ React.createElement(Menu.Trigger, null, /*#__PURE__*/ React.createElement(Button, {
|
|
102
108
|
size: "small",
|
|
103
109
|
testId: "toolbar-heading-toggle",
|
|
104
110
|
variant: "transparent",
|
|
105
|
-
endIcon: React.createElement(ChevronDownIcon, null),
|
|
111
|
+
endIcon: /*#__PURE__*/ React.createElement(ChevronDownIcon, null),
|
|
106
112
|
isDisabled: props.isDisabled,
|
|
107
113
|
onClick: ()=>someHeadingsEnabled && setOpen(!isOpen)
|
|
108
|
-
}, LABELS[selected])), React.createElement(Menu.List, {
|
|
114
|
+
}, LABELS[selected])), /*#__PURE__*/ React.createElement(Menu.List, {
|
|
109
115
|
testId: "dropdown-heading-list"
|
|
110
|
-
}, ' ', Object.keys(LABELS).map((nodeType)=>nodeTypesByEnablement[nodeType] && React.createElement(Menu.Item, {
|
|
116
|
+
}, ' ', Object.keys(LABELS).map((nodeType)=>nodeTypesByEnablement[nodeType] && /*#__PURE__*/ React.createElement(Menu.Item, {
|
|
111
117
|
key: nodeType,
|
|
112
118
|
isInitiallyFocused: selected === nodeType,
|
|
113
119
|
onClick: handleOnSelectItem(nodeType),
|
|
114
120
|
testId: `dropdown-option-${nodeType}`,
|
|
115
121
|
disabled: props.isDisabled
|
|
116
|
-
}, React.createElement("span", {
|
|
122
|
+
}, /*#__PURE__*/ React.createElement("span", {
|
|
117
123
|
className: cx(styles.dropdown.root, styles.dropdown[nodeType])
|
|
118
124
|
}, LABELS[nodeType]))).filter(Boolean)));
|
|
119
125
|
}
|
|
@@ -5,7 +5,7 @@ import { transformLift, transformUnwrap } from '../../helpers/transformers';
|
|
|
5
5
|
import { isMarkActive, getAboveNode } from '../../internal/queries';
|
|
6
6
|
import { COMMAND_PROMPT } from '../CommandPalette/constants';
|
|
7
7
|
import { HeadingComponents } from './components/Heading';
|
|
8
|
-
const buildHeadingEventHandler = (type)=>(editor, { options: { hotkey
|
|
8
|
+
const buildHeadingEventHandler = (type)=>(editor, { options: { hotkey } })=>(event)=>{
|
|
9
9
|
if (editor.selection && hotkey && isHotkey(hotkey, event)) {
|
|
10
10
|
const isActive = isBlockSelected(editor, type);
|
|
11
11
|
editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
|
|
@@ -20,6 +20,7 @@ const buildHeadingEventHandler = (type)=>(editor, { options: { hotkey } })=>(e
|
|
|
20
20
|
export const createHeadingPlugin = ()=>({
|
|
21
21
|
key: 'HeadingPlugin',
|
|
22
22
|
softBreak: [
|
|
23
|
+
// create a new line with SHIFT+Enter inside a heading
|
|
23
24
|
{
|
|
24
25
|
hotkey: 'shift+enter',
|
|
25
26
|
query: {
|
|
@@ -42,12 +43,16 @@ export const createHeadingPlugin = ()=>({
|
|
|
42
43
|
then: (editor)=>{
|
|
43
44
|
return {
|
|
44
45
|
exitBreak: [
|
|
46
|
+
// Pressing ENTER at the start or end of a heading text inserts a
|
|
47
|
+
// normal paragraph.
|
|
45
48
|
{
|
|
46
49
|
hotkey: 'enter',
|
|
47
50
|
query: {
|
|
48
51
|
allow: HEADINGS,
|
|
49
52
|
end: true,
|
|
50
53
|
start: true,
|
|
54
|
+
// Exclude headings inside lists as it interferes with the list's
|
|
55
|
+
// insertBreak implementation
|
|
51
56
|
filter: ([, path])=>!getAboveNode(editor, {
|
|
52
57
|
at: path,
|
|
53
58
|
match: {
|
|
@@ -72,29 +72,32 @@ export function ToolbarHrButton(props) {
|
|
|
72
72
|
};
|
|
73
73
|
const hasText = !!getText(editor, editor.selection.focus.path);
|
|
74
74
|
hasText ? insertNodes(editor, hr) : setNodes(editor, hr);
|
|
75
|
+
// Move focus to the next paragraph (added by TrailingParagraph plugin)
|
|
75
76
|
moveToTheNextLine(editor);
|
|
76
77
|
focus(editor);
|
|
77
78
|
}
|
|
78
79
|
if (!editor) return null;
|
|
79
|
-
return React.createElement(ToolbarButton, {
|
|
80
|
+
return /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
80
81
|
title: "HR",
|
|
81
82
|
isDisabled: props.isDisabled,
|
|
82
83
|
onClick: handleOnClick,
|
|
83
84
|
testId: "hr-toolbar-button",
|
|
84
85
|
isActive: isBlockSelected(editor, BLOCKS.HR)
|
|
85
|
-
}, React.createElement(HorizontalRuleIcon, null));
|
|
86
|
+
}, /*#__PURE__*/ React.createElement(HorizontalRuleIcon, null));
|
|
86
87
|
}
|
|
87
88
|
export function Hr(props) {
|
|
88
89
|
const isSelected = Slate.useSelected();
|
|
89
90
|
const isFocused = Slate.useFocused();
|
|
90
|
-
return React.createElement("div", {
|
|
91
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
91
92
|
...props.attributes,
|
|
92
93
|
className: styles.container,
|
|
94
|
+
// COMPAT: To make HR copyable in Safari, we verify this attribute below on `deserialize`
|
|
93
95
|
"data-void-element": BLOCKS.HR
|
|
94
|
-
}, React.createElement("div", {
|
|
96
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
95
97
|
draggable: true,
|
|
98
|
+
// Moving `contentEditable` to this div makes it to be selectable when being the first void element, e.g pressing ctrl + a to select everything
|
|
96
99
|
contentEditable: false
|
|
97
|
-
}, React.createElement("hr", {
|
|
100
|
+
}, /*#__PURE__*/ React.createElement("hr", {
|
|
98
101
|
className: cx(styles.hr, isSelected && isFocused ? styles.hrSelected : undefined)
|
|
99
102
|
})), props.children);
|
|
100
103
|
}
|
|
@@ -78,7 +78,7 @@ export function HyperlinkModal(props) {
|
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
function entityToLink(entity) {
|
|
81
|
-
const { id
|
|
81
|
+
const { id, type } = entity.sys;
|
|
82
82
|
return {
|
|
83
83
|
sys: {
|
|
84
84
|
id,
|
|
@@ -88,7 +88,8 @@ export function HyperlinkModal(props) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
function entityToResourceLink(entity) {
|
|
91
|
-
const { urn
|
|
91
|
+
const { urn } = entity.sys;
|
|
92
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
92
93
|
return {
|
|
93
94
|
sys: {
|
|
94
95
|
urn,
|
|
@@ -121,6 +122,7 @@ export function HyperlinkModal(props) {
|
|
|
121
122
|
const options = {
|
|
122
123
|
allowedResources: getAllowedResourcesForNodeType(props.sdk.field, INLINES.RESOURCE_HYPERLINK)
|
|
123
124
|
};
|
|
125
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
124
126
|
const entry = await props.sdk.dialogs.selectSingleResourceEntry(options);
|
|
125
127
|
if (entry) {
|
|
126
128
|
setLinkTarget('');
|
|
@@ -141,30 +143,30 @@ export function HyperlinkModal(props) {
|
|
|
141
143
|
event.preventDefault();
|
|
142
144
|
setLinkEntity(null);
|
|
143
145
|
}
|
|
144
|
-
return React.createElement(EntityProvider, {
|
|
146
|
+
return /*#__PURE__*/ React.createElement(EntityProvider, {
|
|
145
147
|
sdk: props.sdk
|
|
146
|
-
}, React.createElement(React.Fragment, null, React.createElement(ModalContent, null, React.createElement(Form, null, !props.linkType && React.createElement(FormControl, {
|
|
148
|
+
}, /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ModalContent, null, /*#__PURE__*/ React.createElement(Form, null, !props.linkType && /*#__PURE__*/ React.createElement(FormControl, {
|
|
147
149
|
id: "link-text",
|
|
148
150
|
isRequired: true
|
|
149
|
-
}, React.createElement(FormControl.Label, null, "Link text"), React.createElement(TextInput, {
|
|
151
|
+
}, /*#__PURE__*/ React.createElement(FormControl.Label, null, "Link text"), /*#__PURE__*/ React.createElement(TextInput, {
|
|
150
152
|
testId: "link-text-input",
|
|
151
153
|
name: "link-text",
|
|
152
154
|
value: linkText,
|
|
153
155
|
onChange: (event)=>setLinkText(event.target.value)
|
|
154
|
-
})), enabledLinkTypes.length > 1 && React.createElement(FormControl, {
|
|
156
|
+
})), enabledLinkTypes.length > 1 && /*#__PURE__*/ React.createElement(FormControl, {
|
|
155
157
|
id: "link-type"
|
|
156
|
-
}, React.createElement(FormControl.Label, null, "Link type"), React.createElement(Select, {
|
|
158
|
+
}, /*#__PURE__*/ React.createElement(FormControl.Label, null, "Link type"), /*#__PURE__*/ React.createElement(Select, {
|
|
157
159
|
value: linkType,
|
|
158
160
|
onChange: (event)=>setLinkType(event.target.value),
|
|
159
161
|
testId: "link-type-input",
|
|
160
162
|
isDisabled: props.readonly
|
|
161
|
-
}, enabledLinkTypes.map((nodeType)
|
|
163
|
+
}, enabledLinkTypes.map((nodeType)=>/*#__PURE__*/ React.createElement(Select.Option, {
|
|
162
164
|
key: nodeType,
|
|
163
165
|
value: nodeType
|
|
164
|
-
}, LINK_TYPE_SELECTION_VALUES[nodeType])))), linkType === INLINES.HYPERLINK && React.createElement(FormControl, {
|
|
166
|
+
}, LINK_TYPE_SELECTION_VALUES[nodeType])))), linkType === INLINES.HYPERLINK && /*#__PURE__*/ React.createElement(FormControl, {
|
|
165
167
|
id: "linkTarget",
|
|
166
168
|
isRequired: true
|
|
167
|
-
}, React.createElement(FormControl.Label, null, "Link target"), React.createElement(TextInput, {
|
|
169
|
+
}, /*#__PURE__*/ React.createElement(FormControl.Label, null, "Link target"), /*#__PURE__*/ React.createElement(TextInput, {
|
|
168
170
|
ref: linkTargetInputRef,
|
|
169
171
|
name: "linkTarget",
|
|
170
172
|
value: linkTarget,
|
|
@@ -174,46 +176,46 @@ export function HyperlinkModal(props) {
|
|
|
174
176
|
},
|
|
175
177
|
testId: "link-target-input",
|
|
176
178
|
isDisabled: props.readonly
|
|
177
|
-
}), React.createElement(FormControl.HelpText, null, "A protocol may be required, e.g. https://")), linkType !== INLINES.HYPERLINK && React.createElement("div", null, React.createElement(FormLabel, {
|
|
179
|
+
}), /*#__PURE__*/ React.createElement(FormControl.HelpText, null, "A protocol may be required, e.g. https://")), linkType !== INLINES.HYPERLINK && /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(FormLabel, {
|
|
178
180
|
isRequired: true,
|
|
179
181
|
htmlFor: ""
|
|
180
|
-
}, "Link target", ' '), linkEntity && linkEntity.sys.linkType === SYS_LINK_TYPES[linkType] ? React.createElement(React.Fragment, null, !props.readonly && React.createElement(TextLink, {
|
|
182
|
+
}, "Link target", ' '), linkEntity && linkEntity.sys.linkType === SYS_LINK_TYPES[linkType] ? /*#__PURE__*/ React.createElement(React.Fragment, null, !props.readonly && /*#__PURE__*/ React.createElement(TextLink, {
|
|
181
183
|
testId: "entity-selection-link",
|
|
182
184
|
onClick: resetLinkEntity,
|
|
183
185
|
className: styles.removeSelectionLabel
|
|
184
|
-
}, "Remove selection"), React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && isEntryLink(linkEntity) && React.createElement(FetchingWrappedEntryCard, {
|
|
186
|
+
}, "Remove selection"), /*#__PURE__*/ React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && isEntryLink(linkEntity) && /*#__PURE__*/ React.createElement(FetchingWrappedEntryCard, {
|
|
185
187
|
sdk: props.sdk,
|
|
186
188
|
locale: props.sdk.field.locale,
|
|
187
189
|
entryId: linkEntity.sys.id,
|
|
188
190
|
isDisabled: true,
|
|
189
191
|
isSelected: false
|
|
190
|
-
}), linkType === INLINES.RESOURCE_HYPERLINK && isResourceLink(linkEntity) && React.createElement(FetchingWrappedResourceCard, {
|
|
192
|
+
}), linkType === INLINES.RESOURCE_HYPERLINK && isResourceLink(linkEntity) && /*#__PURE__*/ React.createElement(FetchingWrappedResourceCard, {
|
|
191
193
|
sdk: props.sdk,
|
|
192
194
|
link: linkEntity.sys,
|
|
193
195
|
isDisabled: true,
|
|
194
196
|
isSelected: false
|
|
195
|
-
}), linkType === INLINES.ASSET_HYPERLINK && isAssetLink(linkEntity) && React.createElement(FetchingWrappedAssetCard, {
|
|
197
|
+
}), linkType === INLINES.ASSET_HYPERLINK && isAssetLink(linkEntity) && /*#__PURE__*/ React.createElement(FetchingWrappedAssetCard, {
|
|
196
198
|
sdk: props.sdk,
|
|
197
199
|
locale: props.sdk.field.locale,
|
|
198
200
|
assetId: linkEntity.sys.id,
|
|
199
201
|
isDisabled: true,
|
|
200
202
|
isSelected: false
|
|
201
|
-
}))) : React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && React.createElement(TextLink, {
|
|
203
|
+
}))) : /*#__PURE__*/ React.createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && /*#__PURE__*/ React.createElement(TextLink, {
|
|
202
204
|
testId: "entity-selection-link",
|
|
203
205
|
onClick: selectEntry
|
|
204
|
-
}, "Select entry"), linkType === INLINES.RESOURCE_HYPERLINK && React.createElement(TextLink, {
|
|
206
|
+
}, "Select entry"), linkType === INLINES.RESOURCE_HYPERLINK && /*#__PURE__*/ React.createElement(TextLink, {
|
|
205
207
|
testId: "entity-selection-link",
|
|
206
208
|
onClick: selectResourceEntry
|
|
207
|
-
}, "Select entry"), linkType === INLINES.ASSET_HYPERLINK && React.createElement(TextLink, {
|
|
209
|
+
}, "Select entry"), linkType === INLINES.ASSET_HYPERLINK && /*#__PURE__*/ React.createElement(TextLink, {
|
|
208
210
|
testId: "entity-selection-link",
|
|
209
211
|
onClick: selectAsset
|
|
210
|
-
}, "Select asset"))))), React.createElement(ModalControls, null, React.createElement(Button, {
|
|
212
|
+
}, "Select asset"))))), /*#__PURE__*/ React.createElement(ModalControls, null, /*#__PURE__*/ React.createElement(Button, {
|
|
211
213
|
type: "button",
|
|
212
214
|
onClick: ()=>props.onClose(null),
|
|
213
215
|
variant: "secondary",
|
|
214
216
|
testId: "cancel-cta",
|
|
215
217
|
size: "small"
|
|
216
|
-
}, "Cancel"), React.createElement(Button, {
|
|
218
|
+
}, "Cancel"), /*#__PURE__*/ React.createElement(Button, {
|
|
217
219
|
type: "submit",
|
|
218
220
|
variant: "positive",
|
|
219
221
|
size: "small",
|
|
@@ -249,8 +251,8 @@ export async function addOrEditLink(editor, sdk, logAction, targetPath) {
|
|
|
249
251
|
shouldCloseOnEscapePress: true,
|
|
250
252
|
shouldCloseOnOverlayClick: true,
|
|
251
253
|
allowHeightOverflow: true
|
|
252
|
-
}, ({ onClose
|
|
253
|
-
return React.createElement(HyperlinkModal, {
|
|
254
|
+
}, ({ onClose })=>{
|
|
255
|
+
return /*#__PURE__*/ React.createElement(HyperlinkModal, {
|
|
254
256
|
linkTarget: linkTarget,
|
|
255
257
|
linkText: currentLinkText,
|
|
256
258
|
linkType: linkType,
|
|
@@ -266,7 +268,7 @@ export async function addOrEditLink(editor, sdk, logAction, targetPath) {
|
|
|
266
268
|
logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
|
|
267
269
|
return;
|
|
268
270
|
}
|
|
269
|
-
const { linkText: text
|
|
271
|
+
const { linkText: text, linkTarget: url, linkType: type, linkEntity: target } = data;
|
|
270
272
|
withoutNormalizing(editor, ()=>{
|
|
271
273
|
insertLink(editor, {
|
|
272
274
|
text,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { assertOutput, jsx } from '../../../test-utils';
|
|
1
|
+
/* eslint-disable react/no-unknown-property */ /** @jsx jsx */ import { assertOutput, jsx } from '../../../test-utils';
|
|
2
2
|
describe('normalization', ()=>{
|
|
3
3
|
it('removes empty links from the document structure', ()=>{
|
|
4
|
-
const input = jsx("editor", null, jsx("hp", null, jsx("htext", null, "link"), jsx("hlink", {
|
|
4
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "link"), /*#__PURE__*/ jsx("hlink", {
|
|
5
5
|
uri: "https://link.com"
|
|
6
|
-
})), jsx("hp", null, jsx("htext", null, "asset"), jsx("hlink", {
|
|
6
|
+
})), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "asset"), /*#__PURE__*/ jsx("hlink", {
|
|
7
7
|
asset: "asset-id"
|
|
8
|
-
})), jsx("hp", null, jsx("htext", null, "entry"), jsx("hlink", {
|
|
8
|
+
})), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "entry"), /*#__PURE__*/ jsx("hlink", {
|
|
9
9
|
entry: "entry-id"
|
|
10
|
-
})), jsx("hp", null, jsx("htext", null, "resource"), jsx("hlink", {
|
|
10
|
+
})), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "resource"), /*#__PURE__*/ jsx("hlink", {
|
|
11
11
|
resource: "resource-urn"
|
|
12
|
-
})), jsx("hp", null, jsx("htext", null, "explicit empty link"), jsx("hlink", {
|
|
12
|
+
})), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "explicit empty link"), /*#__PURE__*/ jsx("hlink", {
|
|
13
13
|
uri: "https://link.com"
|
|
14
|
-
}, '')), jsx("hp", null, jsx("htext", null, "link with empty space"), jsx("hlink", {
|
|
14
|
+
}, '')), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "link with empty space"), /*#__PURE__*/ jsx("hlink", {
|
|
15
15
|
uri: "https://link.com"
|
|
16
16
|
}, " ")));
|
|
17
|
-
const expected = jsx("editor", null, jsx("hp", null, jsx("htext", null, "link")), jsx("hp", null, jsx("htext", null, "asset")), jsx("hp", null, jsx("htext", null, "entry")), jsx("hp", null, jsx("htext", null, "resource")), jsx("hp", null, jsx("htext", null, "explicit empty link")), jsx("hp", null, jsx("htext", null, "link with empty space")));
|
|
17
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "link")), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "asset")), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "entry")), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "resource")), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "explicit empty link")), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null, "link with empty space")));
|
|
18
18
|
assertOutput({
|
|
19
19
|
input,
|
|
20
20
|
expected
|
|
@@ -10,8 +10,8 @@ import { styles } from './styles';
|
|
|
10
10
|
export function EntityHyperlink(props) {
|
|
11
11
|
const editor = useContentfulEditor();
|
|
12
12
|
const sdk = useSdkContext();
|
|
13
|
-
const { target
|
|
14
|
-
const { onEntityFetchComplete
|
|
13
|
+
const { target } = props.element.data;
|
|
14
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
15
15
|
const tooltipContent = useEntityInfo({
|
|
16
16
|
target,
|
|
17
17
|
sdk,
|
|
@@ -30,12 +30,12 @@ export function EntityHyperlink(props) {
|
|
|
30
30
|
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
return React.createElement(Tooltip, {
|
|
33
|
+
return /*#__PURE__*/ React.createElement(Tooltip, {
|
|
34
34
|
content: tooltipContent,
|
|
35
35
|
targetWrapperClassName: styles.hyperlinkWrapper,
|
|
36
36
|
placement: "bottom",
|
|
37
37
|
maxWidth: "auto"
|
|
38
|
-
}, React.createElement(TextLink, {
|
|
38
|
+
}, /*#__PURE__*/ React.createElement(TextLink, {
|
|
39
39
|
as: "a",
|
|
40
40
|
onClick: handleClick,
|
|
41
41
|
className: styles.hyperlink,
|
|
@@ -10,8 +10,8 @@ import { styles } from './styles';
|
|
|
10
10
|
export function ResourceHyperlink(props) {
|
|
11
11
|
const editor = useContentfulEditor();
|
|
12
12
|
const sdk = useSdkContext();
|
|
13
|
-
const { target
|
|
14
|
-
const { onEntityFetchComplete
|
|
13
|
+
const { target } = props.element.data;
|
|
14
|
+
const { onEntityFetchComplete } = useLinkTracking();
|
|
15
15
|
const tooltipContent = useResourceEntityInfo({
|
|
16
16
|
target,
|
|
17
17
|
onEntityFetchComplete
|
|
@@ -29,12 +29,12 @@ export function ResourceHyperlink(props) {
|
|
|
29
29
|
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p.path);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
return React.createElement(Tooltip, {
|
|
32
|
+
return /*#__PURE__*/ React.createElement(Tooltip, {
|
|
33
33
|
content: tooltipContent,
|
|
34
34
|
targetWrapperClassName: styles.hyperlinkWrapper,
|
|
35
35
|
placement: "bottom",
|
|
36
36
|
maxWidth: "auto"
|
|
37
|
-
}, React.createElement(TextLink, {
|
|
37
|
+
}, /*#__PURE__*/ React.createElement(TextLink, {
|
|
38
38
|
as: "a",
|
|
39
39
|
onClick: handleClick,
|
|
40
40
|
className: styles.hyperlink,
|
|
@@ -19,11 +19,11 @@ export function ToolbarHyperlinkButton(props) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
if (!editor) return null;
|
|
22
|
-
return React.createElement(ToolbarButton, {
|
|
22
|
+
return /*#__PURE__*/ React.createElement(ToolbarButton, {
|
|
23
23
|
title: "Hyperlink",
|
|
24
24
|
testId: "hyperlink-toolbar-button",
|
|
25
25
|
onClick: handleClick,
|
|
26
26
|
isActive: isActive,
|
|
27
27
|
isDisabled: props.isDisabled
|
|
28
|
-
}, React.createElement(LinkIcon, null));
|
|
28
|
+
}, /*#__PURE__*/ React.createElement(LinkIcon, null));
|
|
29
29
|
}
|
|
@@ -8,7 +8,7 @@ import { styles } from './styles';
|
|
|
8
8
|
export function UrlHyperlink(props) {
|
|
9
9
|
const editor = useContentfulEditor();
|
|
10
10
|
const sdk = useSdkContext();
|
|
11
|
-
const { uri
|
|
11
|
+
const { uri } = props.element.data;
|
|
12
12
|
function handleClick(event) {
|
|
13
13
|
event.preventDefault();
|
|
14
14
|
event.stopPropagation();
|
|
@@ -22,13 +22,13 @@ export function UrlHyperlink(props) {
|
|
|
22
22
|
});
|
|
23
23
|
addOrEditLink(editor, sdk, editor.tracking.onViewportAction, p?.path);
|
|
24
24
|
}
|
|
25
|
-
return React.createElement(Tooltip, {
|
|
25
|
+
return /*#__PURE__*/ React.createElement(Tooltip, {
|
|
26
26
|
usePortal: true,
|
|
27
27
|
content: uri,
|
|
28
28
|
targetWrapperClassName: styles.hyperlinkWrapper,
|
|
29
29
|
placement: "bottom",
|
|
30
30
|
maxWidth: "min-content"
|
|
31
|
-
}, React.createElement(TextLink, {
|
|
31
|
+
}, /*#__PURE__*/ React.createElement(TextLink, {
|
|
32
32
|
as: "a",
|
|
33
33
|
href: uri,
|
|
34
34
|
rel: "noopener noreferrer",
|
|
@@ -12,7 +12,7 @@ const isAnchor = (element)=>element.nodeName === 'A' && !!element.getAttribute('
|
|
|
12
12
|
const isEntryAnchor = (element)=>element.nodeName === 'A' && element.getAttribute('data-link-type') === 'Entry';
|
|
13
13
|
const isAssetAnchor = (element)=>element.nodeName === 'A' && element.getAttribute('data-link-type') === 'Asset';
|
|
14
14
|
const isResourceAnchor = (element)=>element.nodeName === 'A' && element.getAttribute('data-resource-link-type') === 'Contentful:Entry';
|
|
15
|
-
const buildHyperlinkEventHandler = (sdk)=>(editor, { options: { hotkey
|
|
15
|
+
const buildHyperlinkEventHandler = (sdk)=>(editor, { options: { hotkey } })=>{
|
|
16
16
|
return (event)=>{
|
|
17
17
|
if (!editor.selection) {
|
|
18
18
|
return;
|
|
@@ -65,6 +65,7 @@ export const createHyperlinkPlugin = (sdk)=>{
|
|
|
65
65
|
onKeyDown: buildHyperlinkEventHandler(sdk)
|
|
66
66
|
},
|
|
67
67
|
plugins: [
|
|
68
|
+
// URL Hyperlink
|
|
68
69
|
{
|
|
69
70
|
...common,
|
|
70
71
|
key: INLINES.HYPERLINK,
|
|
@@ -82,6 +83,7 @@ export const createHyperlinkPlugin = (sdk)=>{
|
|
|
82
83
|
getNode: getNodeOfType(INLINES.HYPERLINK)
|
|
83
84
|
}
|
|
84
85
|
},
|
|
86
|
+
// Entry Hyperlink
|
|
85
87
|
{
|
|
86
88
|
...common,
|
|
87
89
|
key: INLINES.ENTRY_HYPERLINK,
|
|
@@ -99,6 +101,7 @@ export const createHyperlinkPlugin = (sdk)=>{
|
|
|
99
101
|
getNode: getNodeOfType(INLINES.ENTRY_HYPERLINK)
|
|
100
102
|
}
|
|
101
103
|
},
|
|
104
|
+
// Resource Hyperlink
|
|
102
105
|
{
|
|
103
106
|
...common,
|
|
104
107
|
key: INLINES.RESOURCE_HYPERLINK,
|
|
@@ -116,6 +119,7 @@ export const createHyperlinkPlugin = (sdk)=>{
|
|
|
116
119
|
getNode: getNodeOfType(INLINES.RESOURCE_HYPERLINK)
|
|
117
120
|
}
|
|
118
121
|
},
|
|
122
|
+
// Asset Hyperlink
|
|
119
123
|
{
|
|
120
124
|
...common,
|
|
121
125
|
key: INLINES.ASSET_HYPERLINK,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
3
3
|
import { getEntityInfo } from './utils';
|
|
4
|
-
async function fetchAllData({ sdk
|
|
4
|
+
async function fetchAllData({ sdk, entityId, entityType, localeCode, defaultLocaleCode }) {
|
|
5
5
|
let contentType;
|
|
6
6
|
const getEntity = entityType === 'Entry' ? sdk.space.getEntry : sdk.space.getAsset;
|
|
7
7
|
const entity = await getEntity(entityId);
|
|
@@ -10,6 +10,7 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
10
10
|
contentType = sdk.space.getCachedContentTypes().find((ct)=>ct.sys.id === contentTypeId);
|
|
11
11
|
}
|
|
12
12
|
const entityTitle = entityType === 'Entry' ? entityHelpers.getEntryTitle({
|
|
13
|
+
//@ts-expect-error
|
|
13
14
|
entry: entity,
|
|
14
15
|
contentType,
|
|
15
16
|
localeCode,
|
|
@@ -22,12 +23,14 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
22
23
|
defaultTitle: 'Untitled'
|
|
23
24
|
});
|
|
24
25
|
const entityDescription = entityHelpers.getEntityDescription({
|
|
26
|
+
// @ts-expect-error
|
|
25
27
|
entity,
|
|
26
28
|
contentType,
|
|
27
29
|
localeCode,
|
|
28
30
|
defaultLocaleCode
|
|
29
31
|
});
|
|
30
32
|
const jobs = await sdk.space.getEntityScheduledActions(entityType, entityId);
|
|
33
|
+
// @ts-expect-error
|
|
31
34
|
const entityStatus = entityHelpers.getEntryStatus(entity.sys);
|
|
32
35
|
return {
|
|
33
36
|
jobs,
|
|
@@ -38,7 +41,7 @@ async function fetchAllData({ sdk , entityId , entityType , localeCode , default
|
|
|
38
41
|
contentTypeName: contentType ? contentType.name : ''
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
|
-
function useRequestStatus({ sdk
|
|
44
|
+
function useRequestStatus({ sdk, target, onEntityFetchComplete }) {
|
|
42
45
|
const [requestStatus, setRequestStatus] = useState({
|
|
43
46
|
type: 'loading'
|
|
44
47
|
});
|
|
@@ -74,7 +77,7 @@ function useRequestStatus({ sdk , target , onEntityFetchComplete }) {
|
|
|
74
77
|
}
|
|
75
78
|
export function useEntityInfo(props) {
|
|
76
79
|
const status = useRequestStatus(props);
|
|
77
|
-
const { linkType
|
|
80
|
+
const { linkType } = props.target.sys;
|
|
78
81
|
if (status.type === 'loading') {
|
|
79
82
|
return `Loading ${linkType.toLowerCase()}...`;
|
|
80
83
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useResource } from '@contentful/field-editor-reference';
|
|
3
3
|
import { truncateTitle } from '../../plugins/shared/utils';
|
|
4
|
-
export function useResourceEntityInfo({ onEntityFetchComplete
|
|
5
|
-
const { data
|
|
4
|
+
export function useResourceEntityInfo({ onEntityFetchComplete, target }) {
|
|
5
|
+
const { data, error, status } = useResource(target.sys.linkType, target.sys.urn);
|
|
6
6
|
React.useEffect(()=>{
|
|
7
7
|
if (status === 'success') {
|
|
8
8
|
onEntityFetchComplete?.();
|
|
@@ -10,7 +10,7 @@ export function getEntityInfo(data) {
|
|
|
10
10
|
if (!data) {
|
|
11
11
|
return '';
|
|
12
12
|
}
|
|
13
|
-
const { entityTitle
|
|
13
|
+
const { entityTitle, contentTypeName, entityStatus, jobs } = data;
|
|
14
14
|
const title = truncateTitle(entityTitle, 60) || 'Untitled';
|
|
15
15
|
const scheduledActions = jobs.length > 0 ? getScheduleTooltipContent({
|
|
16
16
|
job: jobs[0],
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { assertOutput, jsx } from '../../../test-utils';
|
|
1
|
+
/* eslint-disable react/no-unknown-property */ /** @jsx jsx */ import { assertOutput, jsx } from '../../../test-utils';
|
|
2
2
|
describe('normalization', ()=>{
|
|
3
3
|
it('wraps orphaned list items in a list', ()=>{
|
|
4
|
-
const input = jsx("editor", null, jsx("hli", null, jsx("hp", null, "Item")), jsx("hp", null));
|
|
5
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"))), jsx("hp", null, jsx("htext", null)));
|
|
4
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item")), /*#__PURE__*/ jsx("hp", null));
|
|
5
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
6
6
|
assertOutput({
|
|
7
7
|
input,
|
|
8
8
|
expected
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
it('adds empty paragraph to empty list items', ()=>{
|
|
12
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null)), jsx("hp", null));
|
|
13
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, jsx("htext", null)))), jsx("hp", null, jsx("htext", null)));
|
|
12
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null)), /*#__PURE__*/ jsx("hp", null));
|
|
13
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
14
14
|
assertOutput({
|
|
15
15
|
input,
|
|
16
16
|
expected
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
it('replaces invalid list items with text', ()=>{
|
|
20
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"), jsx("htd", null, jsx("hp", null, jsx("htext", {
|
|
20
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
21
21
|
bold: true
|
|
22
|
-
}, "bold text"))), jsx("htd", null, jsx("hp", null, "Take a look at this ", jsx("hlink", {
|
|
22
|
+
}, "bold text"))), /*#__PURE__*/ jsx("htd", null, /*#__PURE__*/ jsx("hp", null, "Take a look at this ", /*#__PURE__*/ jsx("hlink", {
|
|
23
23
|
uri: "https://google.com"
|
|
24
|
-
}, "link"))))), jsx("hp", null));
|
|
25
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item"), jsx("hp", null, jsx("htext", {
|
|
24
|
+
}, "link"))))), /*#__PURE__*/ jsx("hp", null));
|
|
25
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item"), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", {
|
|
26
26
|
bold: true
|
|
27
|
-
}, "bold text")), jsx("hp", null, "Take a look at this ", jsx("hlink", {
|
|
27
|
+
}, "bold text")), /*#__PURE__*/ jsx("hp", null, "Take a look at this ", /*#__PURE__*/ jsx("hlink", {
|
|
28
28
|
uri: "https://google.com"
|
|
29
|
-
}, "link"), jsx("htext", null)))), jsx("hp", null, jsx("htext", null)));
|
|
29
|
+
}, "link"), /*#__PURE__*/ jsx("htext", null)))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
30
30
|
assertOutput({
|
|
31
31
|
input,
|
|
32
32
|
expected
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
it('replaces list items with nested lists as a first child', ()=>{
|
|
36
|
-
const input = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1.1")))), jsx("hli", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.2"))))), jsx("hp", null, jsx("htext", null)));
|
|
37
|
-
const expected = jsx("editor", null, jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.1"), jsx("hul", null, jsx("hli", null, jsx("hp", null, "Item 2.1.1")))), jsx("hli", null, jsx("hp", null, "Item 2.2"))), jsx("hp", null, jsx("htext", null)));
|
|
36
|
+
const input = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.2"))))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
37
|
+
const expected = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1"), /*#__PURE__*/ jsx("hul", null, /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.1.1")))), /*#__PURE__*/ jsx("hli", null, /*#__PURE__*/ jsx("hp", null, "Item 2.2"))), /*#__PURE__*/ jsx("hp", null, /*#__PURE__*/ jsx("htext", null)));
|
|
38
38
|
assertOutput({
|
|
39
39
|
input,
|
|
40
40
|
expected
|