@contentful/field-editor-rich-text 3.5.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/cjs/RichTextEditor.js +42 -53
  2. package/dist/cjs/SyncEditorValue.js +107 -0
  3. package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +8 -3
  4. package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +37 -21
  5. package/dist/cjs/helpers/callbacks.js +35 -0
  6. package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +25 -0
  7. package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +21 -0
  8. package/dist/cjs/helpers/toSlateValue.js +51 -0
  9. package/dist/cjs/internal/hooks.js +12 -2
  10. package/dist/cjs/internal/misc.js +0 -6
  11. package/dist/cjs/plugins/DragAndDrop/index.js +1 -0
  12. package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
  13. package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -35
  14. package/dist/cjs/plugins/EmbeddedEntityInline/index.js +3 -2
  15. package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +54 -0
  16. package/dist/cjs/plugins/EmbeddedResourceBlock/index.js +55 -0
  17. package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
  18. package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
  19. package/dist/cjs/plugins/Table/onKeyDownTable.js +14 -0
  20. package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
  21. package/dist/cjs/plugins/Text/createTextPlugin.js +1 -0
  22. package/dist/cjs/plugins/index.js +2 -5
  23. package/dist/cjs/plugins/links-tracking.js +8 -17
  24. package/dist/cjs/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +15 -7
  25. package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +170 -0
  26. package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +110 -0
  27. package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +45 -0
  28. package/dist/esm/RichTextEditor.js +37 -48
  29. package/dist/esm/SyncEditorValue.js +53 -0
  30. package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -3
  31. package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +37 -21
  32. package/dist/esm/helpers/callbacks.js +20 -0
  33. package/dist/esm/helpers/getAllowedResourcesForNodeType.js +10 -0
  34. package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +6 -0
  35. package/dist/{cjs/helpers/sanitizeIncomingSlateDoc.js → esm/helpers/toSlateValue.js} +13 -10
  36. package/dist/esm/internal/hooks.js +9 -2
  37. package/dist/esm/internal/misc.js +0 -3
  38. package/dist/esm/plugins/DragAndDrop/index.js +1 -0
  39. package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
  40. package/dist/esm/plugins/EmbeddedEntityBlock/index.js +3 -27
  41. package/dist/esm/plugins/EmbeddedEntityInline/index.js +4 -3
  42. package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +39 -0
  43. package/dist/esm/plugins/EmbeddedResourceBlock/index.js +45 -0
  44. package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
  45. package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
  46. package/dist/esm/plugins/Table/onKeyDownTable.js +15 -1
  47. package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +5 -15
  48. package/dist/esm/plugins/Text/createTextPlugin.js +1 -0
  49. package/dist/esm/plugins/index.js +2 -5
  50. package/dist/esm/plugins/links-tracking.js +6 -10
  51. package/dist/esm/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +14 -6
  52. package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +144 -0
  53. package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +56 -0
  54. package/dist/esm/plugins/shared/LinkedBlockWrapper.js +30 -0
  55. package/dist/types/ContentfulEditorProvider.d.ts +2 -3
  56. package/dist/types/RichTextEditor.d.ts +2 -2
  57. package/dist/types/SyncEditorValue.d.ts +13 -0
  58. package/dist/types/dialogs/HypelinkDialog/HyperlinkDialog.d.ts +3 -3
  59. package/dist/types/helpers/callbacks.d.ts +3 -0
  60. package/dist/types/helpers/getAllowedResourcesForNodeType.d.ts +25 -0
  61. package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +16 -0
  62. package/dist/types/helpers/toSlateValue.d.ts +7 -0
  63. package/dist/types/internal/hooks.d.ts +4 -2
  64. package/dist/types/internal/misc.d.ts +2 -2
  65. package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +0 -1
  66. package/dist/types/plugins/EmbeddedEntityBlock/index.d.ts +1 -2
  67. package/dist/types/plugins/EmbeddedResourceBlock/LinkedResourceBlock.d.ts +18 -0
  68. package/dist/types/plugins/EmbeddedResourceBlock/index.d.ts +3 -0
  69. package/dist/types/plugins/links-tracking.d.ts +3 -3
  70. package/dist/types/plugins/shared/EmbeddedBlockToolbarIcon.d.ts +11 -0
  71. package/dist/types/plugins/shared/EmbeddedBlockUtil.d.ts +8 -0
  72. package/dist/types/plugins/shared/FetchingWrappedResourceCard.d.ts +14 -0
  73. package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +25 -0
  74. package/dist/types/test-utils/createEditor.d.ts +2 -0
  75. package/dist/types/test-utils/jsx.d.ts +1 -1
  76. package/package.json +18 -18
  77. package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +0 -108
  78. package/dist/cjs/prepareDocument.js +0 -86
  79. package/dist/cjs/useOnValueChanged.js +0 -58
  80. package/dist/esm/helpers/sanitizeIncomingSlateDoc.js +0 -23
  81. package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +0 -85
  82. package/dist/esm/prepareDocument.js +0 -57
  83. package/dist/esm/useOnValueChanged.js +0 -43
  84. package/dist/types/helpers/sanitizeIncomingSlateDoc.d.ts +0 -6
  85. package/dist/types/plugins/EmbeddedEntityBlock/ToolbarIcon.d.ts +0 -11
  86. package/dist/types/plugins/EmbeddedEntityBlock/Util.d.ts +0 -4
  87. package/dist/types/prepareDocument.d.ts +0 -19
  88. package/dist/types/useOnValueChanged.d.ts +0 -8
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { FieldExtensionSDK } from '@contentful/app-sdk';
3
3
  import * as Contentful from '@contentful/rich-text-types';
4
4
  import { RichTextTrackingActionHandler } from './plugins/Tracking';
@@ -6,7 +6,7 @@ type ConnectedProps = {
6
6
  sdk: FieldExtensionSDK;
7
7
  onAction?: RichTextTrackingActionHandler;
8
8
  minHeight?: string | number;
9
- value?: object;
9
+ value?: Contentful.Document;
10
10
  isDisabled?: boolean;
11
11
  onChange?: (doc: Contentful.Document) => unknown;
12
12
  isToolbarHidden?: boolean;
@@ -0,0 +1,13 @@
1
+ import { Value } from './internal/types';
2
+ export type SyncEditorStateProps = {
3
+ incomingValue?: Value;
4
+ };
5
+ /**
6
+ * A void component that's responsible for keeping the editor
7
+ * state in sync with incoming changes (aka. external updates)
8
+ *
9
+ * This component is a hack to workaround the limitation of Plate v17+
10
+ * where we can no longer access the editor instance outside the Plate
11
+ * provider.
12
+ */
13
+ export declare const SyncEditorValue: ({ incomingValue }: SyncEditorStateProps) => null;
@@ -1,7 +1,7 @@
1
1
  export namespace LINK_TYPES {
2
- const URI: string;
3
- const ENTRY: string;
4
- const ASSET: string;
2
+ let URI: string;
3
+ let ENTRY: string;
4
+ let ASSET: string;
5
5
  }
6
6
  export class HyperlinkDialog extends React.Component<any, any, any> {
7
7
  static propTypes: {
@@ -0,0 +1,3 @@
1
+ /// <reference types="lodash" />
2
+ import { Document } from '@contentful/rich-text-types';
3
+ export declare const createOnChangeCallback: (handler?: ((value: Document) => void) | undefined) => import("lodash").DebouncedFunc<(document: unknown) => void>;
@@ -0,0 +1,25 @@
1
+ type AllowedResource = {
2
+ type: 'Contentful:Entry';
3
+ source: string;
4
+ contentTypes: string[];
5
+ };
6
+ /**
7
+ * Given a field object and a rich text node type, return a list of allowed
8
+ * resources associated with the node type, based on that node type's
9
+ * `allowedResources` property.
10
+ *
11
+ * The navigation here is explained by the `nodes` validation having signature:
12
+ * { nodes: { [nodeType]: { allowedResources: AllowedResource[] } } }
13
+ *
14
+ * We defensively navigate through this object because
15
+ * 1) the field may not have a `validations` array,
16
+ * 2) the `validations` array may be empty,
17
+ * 3) the `validations` array may not have a `nodes` validation, and
18
+ * 4) the `nodes` validation may not validate the `nodeType`.
19
+ *
20
+ * @param {object} field
21
+ * @param {string} nodeType
22
+ * @returns {AllowedResource[]}
23
+ */
24
+ export default function getAllowedResourcesForNodeType(field: any, nodeType: any): AllowedResource[];
25
+ export {};
@@ -0,0 +1,16 @@
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
+ };
@@ -0,0 +1,7 @@
1
+ import { Document } from '@contentful/rich-text-types';
2
+ import { Element } from '../internal/types';
3
+ /**
4
+ * Converts a Contentful rich text document to the corresponding slate editor
5
+ * value
6
+ */
7
+ export declare const toSlateValue: (doc?: Document) => Element[];
@@ -1,4 +1,6 @@
1
1
  import * as p from '@udecode/plate-core';
2
+ import { PlateEditor, Value } from './types';
2
3
  export declare const useReadOnly: () => boolean;
3
- export declare const usePlateEditorRef: <V extends p.Value = p.Value, E extends p.PlateEditor<V> = p.PlateEditor<V>>(id?: string | undefined) => E | null;
4
- export declare const usePlateEditorState: <V extends p.Value = p.Value, E extends p.PlateEditor<V> = p.PlateEditor<V>>(id?: string | undefined) => E | null;
4
+ export declare const usePlateEditorRef: (id?: string) => PlateEditor;
5
+ export declare const usePlateEditorState: (id?: string) => PlateEditor;
6
+ export declare const usePlateSelectors: (id?: string) => p.GetRecord<p.PlateStoreState<Value, PlateEditor>>;
@@ -1,6 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import * as p from '@udecode/plate-core';
3
- import { StoreApiGet } from '@udecode/zustood';
4
3
  import * as s from 'slate';
5
4
  import type { Value, PlateEditor, Location, PlatePlugin } from './types';
6
5
  export type CreatePlateEditorOptions = Omit<p.CreatePlateEditorOptions<Value, PlateEditor>, 'plugins'> & {
@@ -23,6 +22,8 @@ export declare const createPlateEditor: (options?: CreatePlateEditorOptions) =>
23
22
  plugins: p.WithPlatePlugin<{}, Value, p.PlateEditor<Value>>[];
24
23
  pluginsByKey: Record<string, p.WithPlatePlugin<{}, Value, p.PlateEditor<Value>>>;
25
24
  prevSelection: s.BaseRange | null;
25
+ blockFactory: (node?: Partial<p.TElement> | undefined, path?: s.Path | undefined) => p.TElement;
26
+ childrenFactory: () => Value;
26
27
  currentKeyboardEvent: import("react").KeyboardEvent<Element> | null;
27
28
  };
28
29
  export declare const withoutNormalizing: (editor: PlateEditor, fn: () => boolean | void) => boolean;
@@ -34,4 +35,3 @@ export declare const fromDOMPoint: (editor: PlateEditor, domPoint: [Node, number
34
35
  suppressThrow: boolean;
35
36
  }) => s.BasePoint | null | undefined;
36
37
  export declare const mockPlugin: (plugin?: Partial<PlatePlugin> | undefined) => p.WithPlatePlugin<p.AnyObject, p.Value, p.PlateEditor<p.Value>>;
37
- export declare const getPlateSelectors: (id?: string | undefined) => StoreApiGet<p.PlateStoreState<Value, PlateEditor>, {}>;
@@ -14,7 +14,6 @@ type LinkedEntityBlockProps = {
14
14
  };
15
15
  attributes: Pick<RenderElementProps, 'attributes'>;
16
16
  children: Pick<RenderElementProps, 'children'>;
17
- onEntityFetchComplete: VoidFunction;
18
17
  };
19
18
  export declare function LinkedEntityBlock(props: LinkedEntityBlockProps): React.JSX.Element;
20
19
  export {};
@@ -1,5 +1,4 @@
1
1
  import { FieldExtensionSDK } from '@contentful/app-sdk';
2
- import { PlatePlugin } from '../../internal/types';
3
- export { EmbeddedEntityBlockToolbarIcon as ToolbarIcon } from './ToolbarIcon';
2
+ import { PlatePlugin } from '../../internal';
4
3
  export declare const createEmbeddedEntryBlockPlugin: (sdk: FieldExtensionSDK) => PlatePlugin;
5
4
  export declare const createEmbeddedAssetBlockPlugin: (sdk: FieldExtensionSDK) => PlatePlugin;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { Element, RenderElementProps } from '../../internal';
3
+ export type LinkedResourceBlockProps = {
4
+ element: Element & {
5
+ data: {
6
+ target: {
7
+ sys: {
8
+ urn: string;
9
+ linkType: 'Contentful:Entry';
10
+ type: 'ResourceLink';
11
+ };
12
+ };
13
+ };
14
+ };
15
+ attributes: Pick<RenderElementProps, 'attributes'>;
16
+ children: Pick<RenderElementProps, 'children'>;
17
+ };
18
+ export declare function LinkedResourceBlock(props: LinkedResourceBlockProps): React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { FieldExtensionSDK } from '@contentful/app-sdk';
2
+ import { PlatePlugin } from '../../internal';
3
+ export declare const createEmbeddedResourceBlockPlugin: (sdk: FieldExtensionSDK) => PlatePlugin;
@@ -1,3 +1,3 @@
1
- import React, { ComponentProps } from 'react';
2
- import { HyperlinkElementProps } from './Hyperlink/components/EntityHyperlink';
3
- export declare function withLinkTracking(Component: React.ComponentType<HyperlinkElementProps>): (props: ComponentProps<typeof Component>) => React.JSX.Element;
1
+ export declare function useLinkTracking(): {
2
+ onEntityFetchComplete: () => unknown;
3
+ };
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ export declare const styles: {
3
+ icon: string;
4
+ };
5
+ interface EmbeddedBlockToolbarIconProps {
6
+ isDisabled: boolean;
7
+ nodeType: string;
8
+ onClose: () => void;
9
+ }
10
+ export declare function EmbeddedBlockToolbarIcon({ isDisabled, nodeType, onClose, }: EmbeddedBlockToolbarIconProps): React.JSX.Element;
11
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FieldExtensionSDK } from '@contentful/app-sdk';
2
+ import { BLOCKS } from '@contentful/rich-text-types';
3
+ import { HotkeyPlugin } from '@udecode/plate-core';
4
+ import { KeyboardHandler } from '../../internal';
5
+ import { TrackingPluginActions } from '../Tracking';
6
+ export declare function getWithEmbeddedBlockEvents(nodeType: BLOCKS.EMBEDDED_ENTRY | BLOCKS.EMBEDDED_ASSET | BLOCKS.EMBEDDED_RESOURCE, sdk: FieldExtensionSDK): KeyboardHandler<HotkeyPlugin>;
7
+ export declare function selectEntityAndInsert(nodeType: any, sdk: any, editor: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
8
+ export declare function selectResourceEntityAndInsert(sdk: any, editor: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import { FieldExtensionSDK } from '@contentful/app-sdk';
3
+ import { ResourceLink } from '@contentful/rich-text-types';
4
+ interface FetchingWrappedResourceCardProps {
5
+ link: ResourceLink['sys'];
6
+ isDisabled: boolean;
7
+ isSelected: boolean;
8
+ sdk: FieldExtensionSDK;
9
+ onEntityFetchComplete?: VoidFunction;
10
+ onEdit?: VoidFunction;
11
+ onRemove?: VoidFunction;
12
+ }
13
+ export declare const FetchingWrappedResourceCard: (props: FetchingWrappedResourceCardProps) => React.JSX.Element;
14
+ export {};
@@ -0,0 +1,25 @@
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
+ };
13
+ type LinkedBlockWrapperProps = React.PropsWithChildren<{
14
+ attributes: Pick<RenderElementProps, 'attributes'>;
15
+ card: JSX.Element;
16
+ element: Element & {
17
+ data: {
18
+ target: {
19
+ sys: ResourceLink | EntityLink;
20
+ };
21
+ };
22
+ };
23
+ }>;
24
+ export declare function LinkedBlockWrapper({ attributes, card, children, element, }: LinkedBlockWrapperProps): React.JSX.Element;
25
+ export {};
@@ -25,6 +25,8 @@ export declare const createTestEditor: (options: {
25
25
  plugins: import("@udecode/plate-core").WithPlatePlugin<{}, Value, import("@udecode/plate-core").PlateEditor<Value>>[];
26
26
  pluginsByKey: Record<string, import("@udecode/plate-core").WithPlatePlugin<{}, Value, import("@udecode/plate-core").PlateEditor<Value>>>;
27
27
  prevSelection: import("slate").BaseRange | null;
28
+ blockFactory: (node?: Partial<import("@udecode/plate-core").TElement> | undefined, path?: import("slate").Path | undefined) => import("@udecode/plate-core").TElement;
29
+ childrenFactory: () => Value;
28
30
  currentKeyboardEvent: import("react").KeyboardEvent<Element> | null;
29
31
  };
30
32
  normalize: () => void;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Add items as needed. Don't forget to adjust hyperscript.d.ts
5
5
  */
6
- export declare const jsx: <S extends "text" | "selection" | "editor" | "anchor" | "focus" | "element" | "cursor" | "fragment">(tagName: S, attributes?: Object | undefined, ...children: any[]) => ReturnType<({
6
+ export declare const jsx: <S extends "text" | "selection" | "editor" | "anchor" | "element" | "focus" | "cursor" | "fragment">(tagName: S, attributes?: Object | undefined, ...children: any[]) => ReturnType<({
7
7
  anchor: typeof import("slate-hyperscript/dist/creators").createAnchor;
8
8
  cursor: typeof import("slate-hyperscript/dist/creators").createCursor;
9
9
  editor: (tagName: string, attributes: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,27 +39,27 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@contentful/app-sdk": "^4.6.0",
42
- "@contentful/contentful-slatejs-adapter": "15.13.1",
42
+ "@contentful/contentful-slatejs-adapter": "^15.16.5",
43
43
  "@contentful/f36-components": "^4.20.6",
44
44
  "@contentful/f36-icons": "^4.1.1",
45
45
  "@contentful/f36-tokens": "^4.0.0",
46
46
  "@contentful/f36-utils": "^4.19.0",
47
- "@contentful/field-editor-reference": "^5.10.0",
47
+ "@contentful/field-editor-reference": "^5.11.0",
48
48
  "@contentful/field-editor-shared": "^1.3.0",
49
- "@contentful/rich-text-plain-text-renderer": "^15.12.1",
50
- "@contentful/rich-text-types": "15.14.1",
49
+ "@contentful/rich-text-plain-text-renderer": "^16.0.4",
50
+ "@contentful/rich-text-types": "16.1.0",
51
51
  "@popperjs/core": "^2.11.5",
52
- "@udecode/plate-basic-marks": "16.8.0",
53
- "@udecode/plate-break": "16.8.0",
54
- "@udecode/plate-core": "16.8.0",
55
- "@udecode/plate-list": "16.8.0",
56
- "@udecode/plate-paragraph": "16.8.0",
57
- "@udecode/plate-reset-node": "16.8.0",
58
- "@udecode/plate-select": "16.8.0",
59
- "@udecode/plate-serializer-docx": "16.8.0",
60
- "@udecode/plate-serializer-html": "16.8.0",
61
- "@udecode/plate-table": "16.8.0",
62
- "@udecode/plate-trailing-block": "16.8.0",
52
+ "@udecode/plate-basic-marks": "18.15.0",
53
+ "@udecode/plate-break": "18.15.0",
54
+ "@udecode/plate-core": "18.15.0",
55
+ "@udecode/plate-list": "18.15.0",
56
+ "@udecode/plate-paragraph": "18.15.0",
57
+ "@udecode/plate-reset-node": "18.15.0",
58
+ "@udecode/plate-select": "18.15.0",
59
+ "@udecode/plate-serializer-docx": "18.15.0",
60
+ "@udecode/plate-serializer-html": "18.15.0",
61
+ "@udecode/plate-table": "18.15.0",
62
+ "@udecode/plate-trailing-block": "18.15.0",
63
63
  "fast-deep-equal": "^3.1.3",
64
64
  "is-hotkey": "^0.2.0",
65
65
  "is-plain-obj": "^3.0.0",
@@ -75,10 +75,10 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@contentful/field-editor-test-utils": "^1.4.0",
78
- "@contentful/rich-text-react-renderer": "^15.11.0",
78
+ "@contentful/rich-text-react-renderer": "^15.16.4",
79
79
  "@types/is-hotkey": "^0.1.6",
80
80
  "@udecode/plate-test-utils": "^3.2.0",
81
81
  "react": ">=16.14.0"
82
82
  },
83
- "gitHead": "543e02672a8dd4edc810f9f3568d6b69c454e1f9"
83
+ "gitHead": "83b651f1638ad6bab53565479e76b8d29b86af3a"
84
84
  }
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- selectEntityAndInsert: function() {
13
- return selectEntityAndInsert;
14
- },
15
- insertBlock: function() {
16
- return insertBlock;
17
- }
18
- });
19
- const _richtexttypes = require("@contentful/rich-text-types");
20
- const _editor = require("../../helpers/editor");
21
- const _newEntitySelectorConfigFromRichTextField = _interop_require_default(require("../../helpers/newEntitySelectorConfigFromRichTextField"));
22
- const _sdkNavigatorSlideIn = require("../../helpers/sdkNavigatorSlideIn");
23
- const _queries = require("../../internal/queries");
24
- const _transforms = require("../../internal/transforms");
25
- function _interop_require_default(obj) {
26
- return obj && obj.__esModule ? obj : {
27
- default: obj
28
- };
29
- }
30
- async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
31
- logAction('openCreateEmbedDialog', {
32
- nodeType
33
- });
34
- const { field , dialogs } = sdk;
35
- const baseConfig = (0, _newEntitySelectorConfigFromRichTextField.default)(field, nodeType);
36
- const selectEntity = baseConfig.entityType === 'Asset' ? dialogs.selectSingleAsset : dialogs.selectSingleEntry;
37
- const config = {
38
- ...baseConfig,
39
- withCreate: true
40
- };
41
- const { selection } = editor;
42
- const rteSlide = (0, _sdkNavigatorSlideIn.watchCurrentSlide)(sdk.navigator);
43
- const entity = await selectEntity(config);
44
- if (!entity) {
45
- logAction('cancelCreateEmbedDialog', {
46
- nodeType
47
- });
48
- } else {
49
- (0, _transforms.select)(editor, selection);
50
- insertBlock(editor, nodeType, entity);
51
- ensureFollowingParagraph(editor);
52
- logAction('insert', {
53
- nodeType
54
- });
55
- }
56
- rteSlide.onActive(()=>{
57
- rteSlide.unwatch();
58
- (0, _editor.focus)(editor);
59
- });
60
- }
61
- function ensureFollowingParagraph(editor) {
62
- const entityBlock = (0, _queries.getAboveNode)(editor, {
63
- match: {
64
- type: [
65
- _richtexttypes.BLOCKS.EMBEDDED_ASSET,
66
- _richtexttypes.BLOCKS.EMBEDDED_ENTRY
67
- ]
68
- }
69
- });
70
- if (!entityBlock) {
71
- return;
72
- }
73
- const level = entityBlock[1].length - 1;
74
- const lastNode = (0, _queries.getLastNodeByLevel)(editor, level);
75
- const isTextContainer = _richtexttypes.TEXT_CONTAINERS.includes(lastNode?.[0].type ?? '');
76
- if (level !== 0 && !isTextContainer) {
77
- (0, _editor.insertEmptyParagraph)(editor);
78
- }
79
- (0, _editor.moveToTheNextChar)(editor);
80
- }
81
- const createNode = (nodeType, entity)=>({
82
- type: nodeType,
83
- data: {
84
- target: {
85
- sys: {
86
- id: entity.sys.id,
87
- type: 'Link',
88
- linkType: entity.sys.type
89
- }
90
- }
91
- },
92
- children: [
93
- {
94
- text: ''
95
- }
96
- ],
97
- isVoid: true
98
- });
99
- function insertBlock(editor, nodeType, entity) {
100
- if (!editor?.selection) return;
101
- const linkedEntityBlock = createNode(nodeType, entity);
102
- const hasText = editor.selection && !!(0, _queries.getText)(editor, editor.selection.focus.path);
103
- if (hasText) {
104
- (0, _transforms.insertNodes)(editor, linkedEntityBlock);
105
- } else {
106
- (0, _transforms.setNodes)(editor, linkedEntityBlock);
107
- }
108
- }
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- hasContent: function() {
13
- return hasContent;
14
- },
15
- setEditorContent: function() {
16
- return setEditorContent;
17
- },
18
- documentToEditorValue: function() {
19
- return documentToEditorValue;
20
- },
21
- normalizeEditorValue: function() {
22
- return normalizeEditorValue;
23
- }
24
- });
25
- const _contentfulslatejsadapter = require("@contentful/contentful-slatejs-adapter");
26
- const _richtexttypes = require("@contentful/rich-text-types");
27
- const _Schema = _interop_require_default(require("./constants/Schema"));
28
- const _sanitizeIncomingSlateDoc = require("./helpers/sanitizeIncomingSlateDoc");
29
- const _internal = require("./internal");
30
- const _queries = require("./internal/queries");
31
- const _transforms = require("./internal/transforms");
32
- function _interop_require_default(obj) {
33
- return obj && obj.__esModule ? obj : {
34
- default: obj
35
- };
36
- }
37
- const hasContent = (doc)=>{
38
- return (doc?.content || []).length > 0;
39
- };
40
- const setEditorContent = (editor, nodes)=>{
41
- (0, _internal.withoutNormalizing)(editor, ()=>{
42
- const children = [
43
- ...editor.children
44
- ];
45
- children.forEach((node)=>editor.apply({
46
- type: 'remove_node',
47
- path: [
48
- 0
49
- ],
50
- node
51
- }));
52
- if (nodes) {
53
- const nodesArray = (0, _queries.isNode)(nodes) ? [
54
- nodes
55
- ] : nodes;
56
- nodesArray.forEach((node, i)=>{
57
- editor.apply({
58
- type: 'insert_node',
59
- path: [
60
- i
61
- ],
62
- node
63
- });
64
- });
65
- }
66
- const point = (0, _queries.getEndPoint)(editor, []);
67
- if (point) {
68
- (0, _transforms.select)(editor, point);
69
- }
70
- });
71
- };
72
- const documentToEditorValue = (doc)=>{
73
- const slateDoc = (0, _contentfulslatejsadapter.toSlatejsDocument)({
74
- document: hasContent(doc) ? doc : _richtexttypes.EMPTY_DOCUMENT,
75
- schema: _Schema.default
76
- });
77
- return (0, _sanitizeIncomingSlateDoc.sanitizeIncomingSlateDoc)(slateDoc);
78
- };
79
- const normalizeEditorValue = (value, options)=>{
80
- const editor = (0, _internal.createPlateEditor)(options);
81
- editor.children = value;
82
- (0, _transforms.normalize)(editor, {
83
- force: true
84
- });
85
- return editor.children;
86
- };
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useOnValueChanged", {
6
- enumerable: true,
7
- get: function() {
8
- return useOnValueChanged;
9
- }
10
- });
11
- const _react = require("react");
12
- const _contentfulslatejsadapter = require("@contentful/contentful-slatejs-adapter");
13
- const _platecore = require("@udecode/plate-core");
14
- const _debounce = _interop_require_default(require("lodash/debounce"));
15
- const _Schema = _interop_require_default(require("./constants/Schema"));
16
- const _removeInternalMarks = require("./helpers/removeInternalMarks");
17
- function _interop_require_default(obj) {
18
- return obj && obj.__esModule ? obj : {
19
- default: obj
20
- };
21
- }
22
- const isRelevantOperation = (op)=>{
23
- if (op.type === 'set_selection') {
24
- return false;
25
- }
26
- return true;
27
- };
28
- const useOnValueChanged = ({ editorId , handler , skip , onSkip })=>{
29
- const onChange = (0, _react.useMemo)(()=>(0, _debounce.default)((document)=>{
30
- const contentfulDocument = (0, _contentfulslatejsadapter.toContentfulDocument)({
31
- document,
32
- schema: _Schema.default
33
- });
34
- const cleanedDocument = (0, _removeInternalMarks.removeInternalMarks)(contentfulDocument);
35
- handler?.(cleanedDocument);
36
- }, 500), [
37
- handler
38
- ]);
39
- return (0, _react.useCallback)((value)=>{
40
- const editor = (0, _platecore.getPlateSelectors)(editorId).editor();
41
- if (!editor) {
42
- throw new Error('Editor change callback called but editor not defined. Editor id: ' + editorId);
43
- }
44
- const operations = editor?.operations.filter(isRelevantOperation);
45
- if (operations.length > 0) {
46
- if (skip) {
47
- onSkip?.();
48
- return;
49
- }
50
- onChange(value);
51
- }
52
- }, [
53
- editorId,
54
- onChange,
55
- skip,
56
- onSkip
57
- ]);
58
- };
@@ -1,23 +0,0 @@
1
- const isTextElement = (node)=>'text' in node;
2
- export function sanitizeIncomingSlateDoc(nodes = []) {
3
- return nodes.map((node)=>{
4
- if (isTextElement(node)) {
5
- return node;
6
- }
7
- if (node.children?.length === 0) {
8
- return {
9
- ...node,
10
- children: [
11
- {
12
- text: '',
13
- data: {}
14
- }
15
- ]
16
- };
17
- }
18
- return {
19
- ...node,
20
- children: sanitizeIncomingSlateDoc(node?.children)
21
- };
22
- });
23
- }