@contentful/field-editor-rich-text 3.12.6 → 3.13.0

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.
Files changed (67) hide show
  1. package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +8 -2
  2. package/dist/cjs/constants/Schema.js +3 -0
  3. package/dist/cjs/helpers/{newEntitySelectorConfigFromRichTextField.js → config.js} +19 -5
  4. package/dist/cjs/plugins/DragAndDrop/index.js +4 -2
  5. package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +1 -1
  6. package/dist/cjs/plugins/EmbeddedEntityInline/LinkedEntityInline.js +97 -0
  7. package/dist/cjs/plugins/EmbeddedEntityInline/index.js +27 -193
  8. package/dist/cjs/plugins/{shared/FetchingWrappedResourceCard.js → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.js} +3 -3
  9. package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +3 -3
  10. package/dist/cjs/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +102 -0
  11. package/dist/cjs/plugins/EmbeddedResourceInline/LinkedResourceInline.js +51 -0
  12. package/dist/cjs/plugins/EmbeddedResourceInline/index.js +56 -0
  13. package/dist/cjs/plugins/index.js +2 -0
  14. package/dist/cjs/plugins/shared/EmbeddedBlockToolbarIcon.js +2 -4
  15. package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +3 -4
  16. package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +105 -0
  17. package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +127 -0
  18. package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +4 -5
  19. package/dist/cjs/plugins/shared/LinkedInlineWrapper.js +85 -0
  20. package/dist/cjs/plugins/shared/ResourceNewBadge.js +57 -0
  21. package/dist/cjs/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +2 -2
  22. package/dist/cjs/plugins/shared/utils.js +12 -0
  23. package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -2
  24. package/dist/esm/constants/Schema.js +3 -0
  25. package/dist/esm/helpers/{newEntitySelectorConfigFromRichTextField.js → config.js} +8 -2
  26. package/dist/esm/plugins/DragAndDrop/index.js +4 -2
  27. package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +1 -1
  28. package/dist/esm/plugins/EmbeddedEntityInline/LinkedEntityInline.js +48 -0
  29. package/dist/esm/plugins/EmbeddedEntityInline/index.js +24 -138
  30. package/dist/esm/plugins/{shared/FetchingWrappedResourceCard.js → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.js} +1 -1
  31. package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +3 -3
  32. package/dist/esm/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.js +53 -0
  33. package/dist/esm/plugins/EmbeddedResourceInline/LinkedResourceInline.js +36 -0
  34. package/dist/esm/plugins/EmbeddedResourceInline/index.js +46 -0
  35. package/dist/esm/plugins/index.js +2 -0
  36. package/dist/esm/plugins/shared/EmbeddedBlockToolbarIcon.js +3 -5
  37. package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +1 -2
  38. package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +51 -0
  39. package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +101 -0
  40. package/dist/esm/plugins/shared/LinkedBlockWrapper.js +4 -5
  41. package/dist/esm/plugins/shared/LinkedInlineWrapper.js +31 -0
  42. package/dist/esm/plugins/shared/ResourceNewBadge.js +8 -0
  43. package/dist/esm/plugins/shared/__tests__/FetchingWrappedResourceCard.test.js +2 -2
  44. package/dist/esm/plugins/shared/utils.js +2 -0
  45. package/dist/types/constants/Schema.d.ts +3 -0
  46. package/dist/types/helpers/config.d.ts +33 -0
  47. package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +2 -7
  48. package/dist/types/plugins/EmbeddedEntityInline/LinkedEntityInline.d.ts +14 -0
  49. package/dist/types/plugins/EmbeddedEntityInline/index.d.ts +0 -7
  50. package/dist/types/plugins/{shared/FetchingWrappedResourceCard.d.ts → EmbeddedResourceBlock/FetchingWrappedResourceBlockCard.d.ts} +2 -2
  51. package/dist/types/plugins/EmbeddedResourceInline/FetchingWrappedResourceInlineCard.d.ts +13 -0
  52. package/dist/types/plugins/EmbeddedResourceInline/LinkedResourceInline.d.ts +13 -0
  53. package/dist/types/plugins/EmbeddedResourceInline/index.d.ts +3 -0
  54. package/dist/types/plugins/shared/EmbeddedInlineToolbarIcon.d.ts +8 -0
  55. package/dist/types/plugins/shared/EmbeddedInlineUtil.d.ts +8 -0
  56. package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +4 -19
  57. package/dist/types/plugins/shared/LinkedInlineWrapper.d.ts +10 -0
  58. package/dist/types/plugins/shared/ResourceNewBadge.d.ts +2 -0
  59. package/dist/types/plugins/shared/utils.d.ts +2 -0
  60. package/package.json +2 -2
  61. package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +0 -21
  62. package/dist/cjs/plugins/EmbeddedEntityInline/Util.js +0 -30
  63. package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +0 -6
  64. package/dist/esm/plugins/EmbeddedEntityInline/Util.js +0 -20
  65. package/dist/types/helpers/newEntitySelectorConfigFromRichTextField.d.ts +0 -14
  66. package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +0 -16
  67. package/dist/types/plugins/EmbeddedEntityInline/Util.d.ts +0 -16
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { Badge } from '@contentful/f36-components';
3
+ export const ResourceNewBadge = ()=>{
4
+ return React.createElement(React.Fragment, null, ' ', "(different space)", ' ', React.createElement(Badge, {
5
+ variant: "primary-filled",
6
+ size: "small"
7
+ }, "new"));
8
+ };
@@ -6,7 +6,7 @@ import { configure, render, waitFor } from '@testing-library/react';
6
6
  import publishedCT from '../__fixtures__/published_content_type.json';
7
7
  import publishedEntry from '../__fixtures__/published_entry.json';
8
8
  import space from '../__fixtures__/space.json';
9
- import { FetchingWrappedResourceCard } from '../FetchingWrappedResourceCard';
9
+ import { FetchingWrappedResourceBlockCard } from '../../EmbeddedResourceBlock/FetchingWrappedResourceBlockCard';
10
10
  configure({
11
11
  testIdAttribute: 'data-test-id'
12
12
  });
@@ -63,7 +63,7 @@ beforeEach(()=>{
63
63
  function renderResourceCard({ linkType ='Contentful:Entry' , entryUrn =resolvableEntryUrn } = {}) {
64
64
  return render(React.createElement(EntityProvider, {
65
65
  sdk: sdk
66
- }, React.createElement(FetchingWrappedResourceCard, {
66
+ }, React.createElement(FetchingWrappedResourceBlockCard, {
67
67
  isDisabled: false,
68
68
  isSelected: false,
69
69
  sdk: sdk,
@@ -0,0 +1,2 @@
1
+ const isResourceLink = (link)=>!!link.sys.urn;
2
+ export const getLinkEntityId = (link)=>isResourceLink(link) ? link.sys.urn : link.sys.id;
@@ -106,6 +106,9 @@ declare const _default: {
106
106
  "embedded-entry-inline": {
107
107
  isVoid: boolean;
108
108
  };
109
+ "embedded-resource-inline": {
110
+ isVoid: boolean;
111
+ };
109
112
  };
110
113
  };
111
114
  export default _default;
@@ -0,0 +1,33 @@
1
+ import { FieldAPI } from '@contentful/app-sdk';
2
+ /**
3
+ * Returns a config for the entity selector based on a given rich text field and a
4
+ * rich text node type that the entity should be picked for. Takes the field
5
+ * validations for the given node type into account.
6
+ *
7
+ * @param {object} field
8
+ * @param {string} nodeType
9
+ * @returns {object}
10
+ */
11
+ type EntitySelectorConfig = {
12
+ entityType: string;
13
+ locale: string | null;
14
+ contentTypes: string[];
15
+ };
16
+ export declare const newEntitySelectorConfigFromRichTextField: (field: FieldAPI, nodeType: any) => EntitySelectorConfig;
17
+ /**
18
+ * Returns a config for the entity selector based on a given rich text field and a
19
+ * rich text node type that the entity should be picked for. Takes the field
20
+ * validations for the given node type into account.
21
+ *
22
+ * @param {object} field
23
+ * @param {string} nodeType
24
+ * @returns {object}
25
+ */
26
+ export declare const newResourceEntitySelectorConfigFromRichTextField: (field: any, nodeType: any) => {
27
+ allowedResources: {
28
+ type: "Contentful:Entry";
29
+ source: string;
30
+ contentTypes: string[];
31
+ }[];
32
+ };
33
+ export {};
@@ -1,15 +1,10 @@
1
1
  import * as React from 'react';
2
+ import { EntityLink } from '@contentful/field-editor-reference';
2
3
  import { Element, RenderElementProps } from '../../internal/types';
3
4
  type LinkedEntityBlockProps = {
4
5
  element: Element & {
5
6
  data: {
6
- target: {
7
- sys: {
8
- id: string;
9
- linkType: 'Entry' | 'Asset';
10
- type: 'Link';
11
- };
12
- };
7
+ target: EntityLink;
13
8
  };
14
9
  };
15
10
  attributes: Pick<RenderElementProps, 'attributes'>;
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { EntryLink } from '@contentful/field-editor-reference';
3
+ import { Element, RenderElementProps } from '../../internal/types';
4
+ type LinkedEntityInlineProps = {
5
+ element: Element & {
6
+ data: {
7
+ target: EntryLink;
8
+ };
9
+ };
10
+ attributes: Pick<RenderElementProps, 'attributes'>;
11
+ children: Pick<RenderElementProps, 'children'>;
12
+ };
13
+ export declare function LinkedEntityInline(props: LinkedEntityInlineProps): React.JSX.Element;
14
+ export {};
@@ -1,10 +1,3 @@
1
- import * as React from 'react';
2
1
  import { FieldAppSDK } from '@contentful/app-sdk';
3
2
  import { PlatePlugin } from '../../internal/types';
4
- interface ToolbarEmbeddedEntityInlineButtonProps {
5
- onClose: () => void;
6
- isDisabled: boolean;
7
- }
8
- export declare function ToolbarEmbeddedEntityInlineButton(props: ToolbarEmbeddedEntityInlineButtonProps): React.JSX.Element;
9
3
  export declare function createEmbeddedEntityInlinePlugin(sdk: FieldAppSDK): PlatePlugin;
10
- export {};
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { FieldAppSDK } from '@contentful/app-sdk';
3
3
  import { ResourceLink } from '@contentful/rich-text-types';
4
- interface FetchingWrappedResourceCardProps {
4
+ interface FetchingWrappedResourceBlockCardProps {
5
5
  link: ResourceLink['sys'];
6
6
  isDisabled: boolean;
7
7
  isSelected: boolean;
@@ -10,5 +10,5 @@ interface FetchingWrappedResourceCardProps {
10
10
  onEdit?: VoidFunction;
11
11
  onRemove?: VoidFunction;
12
12
  }
13
- export declare const FetchingWrappedResourceCard: (props: FetchingWrappedResourceCardProps) => React.JSX.Element;
13
+ export declare const FetchingWrappedResourceBlockCard: (props: FetchingWrappedResourceBlockCardProps) => React.JSX.Element;
14
14
  export {};
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { ResourceLink } from '@contentful/field-editor-reference';
3
+ import { FieldAppSDK } from '@contentful/field-editor-shared';
4
+ interface FetchingWrappedResourceInlineCardProps {
5
+ link: ResourceLink['sys'];
6
+ sdk: FieldAppSDK;
7
+ isSelected: boolean;
8
+ isDisabled: boolean;
9
+ onRemove: (event: React.MouseEvent<Element, MouseEvent>) => void;
10
+ onEntityFetchComplete?: VoidFunction;
11
+ }
12
+ export declare function FetchingWrappedResourceInlineCard(props: FetchingWrappedResourceInlineCardProps): React.JSX.Element;
13
+ export {};
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ResourceLink } from '@contentful/field-editor-reference';
3
+ import { Element, RenderElementProps } from '../../internal';
4
+ export type LinkedResourceInlineProps = {
5
+ element: Element & {
6
+ data: {
7
+ target: ResourceLink;
8
+ };
9
+ };
10
+ attributes: Pick<RenderElementProps, 'attributes'>;
11
+ children: Pick<RenderElementProps, 'children'>;
12
+ };
13
+ export declare function LinkedResourceInline(props: LinkedResourceInlineProps): React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { FieldAppSDK } from '@contentful/app-sdk';
2
+ import { PlatePlugin } from '../../internal';
3
+ export declare function createEmbeddedResourceInlinePlugin(sdk: FieldAppSDK): PlatePlugin;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ interface EmbeddedInlineToolbarIconProps {
3
+ onClose: () => void;
4
+ nodeType: string;
5
+ isDisabled: boolean;
6
+ }
7
+ export declare function EmbeddedInlineToolbarIcon({ onClose, nodeType, isDisabled, }: EmbeddedInlineToolbarIconProps): React.JSX.Element;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FieldAppSDK } from '@contentful/app-sdk';
2
+ import { INLINES } from '@contentful/rich-text-types';
3
+ import { HotkeyPlugin } from '@udecode/plate-common';
4
+ import { KeyboardHandler } from '../../internal/types';
5
+ import { TrackingPluginActions } from '../../plugins/Tracking';
6
+ export declare function getWithEmbeddedEntryInlineEvents(nodeType: INLINES.EMBEDDED_ENTRY | INLINES.EMBEDDED_RESOURCE, sdk: FieldAppSDK): KeyboardHandler<HotkeyPlugin>;
7
+ export declare function selectEntityAndInsert(editor: any, sdk: any, logAction: TrackingPluginActions['onShortcutAction'] | TrackingPluginActions['onToolbarAction']): Promise<void>;
8
+ export declare function selectResourceEntityAndInsert(editor: any, sdk: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
@@ -1,25 +1,10 @@
1
1
  import React from 'react';
2
- import { Element, RenderElementProps } from '../../internal';
3
- type EntityLink = {
4
- id: string;
5
- linkType: 'Entry' | 'Asset';
6
- type: 'Link';
7
- };
8
- type ResourceLink = {
9
- urn: string;
10
- linkType: 'Contentful:Entry';
11
- type: 'ResourceLink';
12
- };
2
+ import { EntityLink, ResourceLink } from '@contentful/field-editor-reference';
3
+ import { RenderElementProps } from '../../internal';
13
4
  type LinkedBlockWrapperProps = React.PropsWithChildren<{
14
5
  attributes: Pick<RenderElementProps, 'attributes'>;
15
6
  card: JSX.Element;
16
- element: Element & {
17
- data: {
18
- target: {
19
- sys: ResourceLink | EntityLink;
20
- };
21
- };
22
- };
7
+ link: ResourceLink | EntityLink;
23
8
  }>;
24
- export declare function LinkedBlockWrapper({ attributes, card, children, element, }: LinkedBlockWrapperProps): React.JSX.Element;
9
+ export declare function LinkedBlockWrapper({ attributes, card, children, link }: LinkedBlockWrapperProps): React.JSX.Element;
25
10
  export {};
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { EntryLink, ResourceLink } from '@contentful/field-editor-reference';
3
+ import { RenderElementProps } from '../../internal/types';
4
+ type LinkedInlineWrapperProps = React.PropsWithChildren<{
5
+ attributes: Pick<RenderElementProps, 'attributes'>;
6
+ card: JSX.Element;
7
+ link: ResourceLink | EntryLink;
8
+ }>;
9
+ export declare function LinkedInlineWrapper({ attributes, card, children, link, }: LinkedInlineWrapperProps): React.JSX.Element;
10
+ export {};
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare const ResourceNewBadge: () => React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { EntityLink, ResourceLink } from '@contentful/field-editor-reference';
2
+ export declare const getLinkEntityId: (link: EntityLink | ResourceLink) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.12.6",
3
+ "version": "3.13.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -81,5 +81,5 @@
81
81
  "prism-react-renderer": "2.0.5",
82
82
  "react": ">=16.14.0"
83
83
  },
84
- "gitHead": "ff0704c0aa9e0f0cdbb4fc70de7ac4ca337529e4"
84
+ "gitHead": "8cbc98b0d9bd617de2199269659c6ce16807fbeb"
85
85
  }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return newResourceEntitySelectorConfigFromRichTextField;
9
- }
10
- });
11
- const _getAllowedResourcesForNodeType = _interop_require_default(require("./getAllowedResourcesForNodeType"));
12
- function _interop_require_default(obj) {
13
- return obj && obj.__esModule ? obj : {
14
- default: obj
15
- };
16
- }
17
- function newResourceEntitySelectorConfigFromRichTextField(field, nodeType) {
18
- return {
19
- allowedResources: (0, _getAllowedResourcesForNodeType.default)(field, nodeType)
20
- };
21
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createInlineEntryNode", {
6
- enumerable: true,
7
- get: function() {
8
- return createInlineEntryNode;
9
- }
10
- });
11
- const _richtexttypes = require("@contentful/rich-text-types");
12
- function createInlineEntryNode(id) {
13
- return {
14
- type: _richtexttypes.INLINES.EMBEDDED_ENTRY,
15
- children: [
16
- {
17
- text: ''
18
- }
19
- ],
20
- data: {
21
- target: {
22
- sys: {
23
- id,
24
- type: 'Link',
25
- linkType: 'Entry'
26
- }
27
- }
28
- }
29
- };
30
- }
@@ -1,6 +0,0 @@
1
- import getAllowedResourcesForNodeType from './getAllowedResourcesForNodeType';
2
- export default function newResourceEntitySelectorConfigFromRichTextField(field, nodeType) {
3
- return {
4
- allowedResources: getAllowedResourcesForNodeType(field, nodeType)
5
- };
6
- }
@@ -1,20 +0,0 @@
1
- import { INLINES } from '@contentful/rich-text-types';
2
- export function createInlineEntryNode(id) {
3
- return {
4
- type: INLINES.EMBEDDED_ENTRY,
5
- children: [
6
- {
7
- text: ''
8
- }
9
- ],
10
- data: {
11
- target: {
12
- sys: {
13
- id,
14
- type: 'Link',
15
- linkType: 'Entry'
16
- }
17
- }
18
- }
19
- };
20
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Returns a config for the entity selector based on a given rich text field and a
3
- * rich text node type that the entity should be picked for. Takes the field
4
- * validations for the given node type into account.
5
- *
6
- * @param {object} field
7
- * @param {string} nodeType
8
- * @returns {object}
9
- */
10
- export default function newEntitySelectorConfigFromRichTextField(field: any, nodeType: any): {
11
- entityType: "Entry" | "Asset";
12
- locale: any;
13
- contentTypes: string[];
14
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * Returns a config for the entity selector based on a given rich text field and a
3
- * rich text node type that the entity should be picked for. Takes the field
4
- * validations for the given node type into account.
5
- *
6
- * @param {object} field
7
- * @param {string} nodeType
8
- * @returns {object}
9
- */
10
- export default function newResourceEntitySelectorConfigFromRichTextField(field: any, nodeType: any): {
11
- allowedResources: {
12
- type: "Contentful:Entry";
13
- source: string;
14
- contentTypes: string[];
15
- }[];
16
- };
@@ -1,16 +0,0 @@
1
- import { INLINES } from '@contentful/rich-text-types';
2
- export declare function createInlineEntryNode(id: string): {
3
- type: INLINES;
4
- children: {
5
- text: string;
6
- }[];
7
- data: {
8
- target: {
9
- sys: {
10
- id: string;
11
- type: string;
12
- linkType: string;
13
- };
14
- };
15
- };
16
- };