@contentful/field-editor-rich-text 3.5.0 → 3.6.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 (58) hide show
  1. package/dist/cjs/Toolbar/components/EmbedEntityWidget.js +8 -3
  2. package/dist/cjs/helpers/__tests__/removeInternalMarks.test.js +37 -21
  3. package/dist/cjs/helpers/getAllowedResourcesForNodeType.js +25 -0
  4. package/dist/cjs/helpers/newResourceEntitySelectorConfigFromRichTextField.js +21 -0
  5. package/dist/cjs/plugins/DragAndDrop/index.js +1 -0
  6. package/dist/cjs/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
  7. package/dist/cjs/plugins/EmbeddedEntityBlock/index.js +3 -35
  8. package/dist/cjs/plugins/EmbeddedEntityInline/index.js +3 -2
  9. package/dist/cjs/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +54 -0
  10. package/dist/cjs/plugins/EmbeddedResourceBlock/index.js +55 -0
  11. package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
  12. package/dist/cjs/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
  13. package/dist/cjs/plugins/Text/createTextPlugin.js +1 -0
  14. package/dist/cjs/plugins/index.js +2 -0
  15. package/dist/cjs/plugins/links-tracking.js +8 -17
  16. package/dist/cjs/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +15 -7
  17. package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +170 -0
  18. package/dist/cjs/plugins/shared/FetchingWrappedResourceCard.js +110 -0
  19. package/dist/cjs/plugins/shared/LinkedBlockWrapper.js +45 -0
  20. package/dist/cjs/useOnValueChanged.js +1 -1
  21. package/dist/esm/Toolbar/components/EmbedEntityWidget.js +8 -3
  22. package/dist/esm/helpers/__tests__/removeInternalMarks.test.js +37 -21
  23. package/dist/esm/helpers/getAllowedResourcesForNodeType.js +10 -0
  24. package/dist/esm/helpers/newResourceEntitySelectorConfigFromRichTextField.js +6 -0
  25. package/dist/esm/plugins/DragAndDrop/index.js +1 -0
  26. package/dist/esm/plugins/EmbeddedEntityBlock/LinkedEntityBlock.js +27 -44
  27. package/dist/esm/plugins/EmbeddedEntityBlock/index.js +3 -27
  28. package/dist/esm/plugins/EmbeddedEntityInline/index.js +4 -3
  29. package/dist/esm/plugins/EmbeddedResourceBlock/LinkedResourceBlock.js +39 -0
  30. package/dist/esm/plugins/EmbeddedResourceBlock/index.js +45 -0
  31. package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +2 -1
  32. package/dist/esm/plugins/Hyperlink/createHyperlinkPlugin.js +2 -3
  33. package/dist/esm/plugins/Text/createTextPlugin.js +1 -0
  34. package/dist/esm/plugins/index.js +2 -0
  35. package/dist/esm/plugins/links-tracking.js +6 -10
  36. package/dist/esm/plugins/{EmbeddedEntityBlock/ToolbarIcon.js → shared/EmbeddedBlockToolbarIcon.js} +14 -6
  37. package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +144 -0
  38. package/dist/esm/plugins/shared/FetchingWrappedResourceCard.js +56 -0
  39. package/dist/esm/plugins/shared/LinkedBlockWrapper.js +30 -0
  40. package/dist/esm/useOnValueChanged.js +1 -1
  41. package/dist/types/dialogs/HypelinkDialog/HyperlinkDialog.d.ts +3 -3
  42. package/dist/types/helpers/getAllowedResourcesForNodeType.d.ts +25 -0
  43. package/dist/types/helpers/newResourceEntitySelectorConfigFromRichTextField.d.ts +16 -0
  44. package/dist/types/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +0 -1
  45. package/dist/types/plugins/EmbeddedEntityBlock/index.d.ts +1 -2
  46. package/dist/types/plugins/EmbeddedResourceBlock/LinkedResourceBlock.d.ts +18 -0
  47. package/dist/types/plugins/EmbeddedResourceBlock/index.d.ts +3 -0
  48. package/dist/types/plugins/links-tracking.d.ts +3 -3
  49. package/dist/types/plugins/shared/EmbeddedBlockToolbarIcon.d.ts +11 -0
  50. package/dist/types/plugins/shared/EmbeddedBlockUtil.d.ts +8 -0
  51. package/dist/types/plugins/shared/FetchingWrappedResourceCard.d.ts +14 -0
  52. package/dist/types/plugins/shared/LinkedBlockWrapper.d.ts +25 -0
  53. package/dist/types/test-utils/jsx.d.ts +1 -1
  54. package/package.json +7 -7
  55. package/dist/cjs/plugins/EmbeddedEntityBlock/Util.js +0 -108
  56. package/dist/esm/plugins/EmbeddedEntityBlock/Util.js +0 -85
  57. package/dist/types/plugins/EmbeddedEntityBlock/ToolbarIcon.d.ts +0 -11
  58. package/dist/types/plugins/EmbeddedEntityBlock/Util.d.ts +0 -4
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.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,15 +39,15 @@
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
52
  "@udecode/plate-basic-marks": "16.8.0",
53
53
  "@udecode/plate-break": "16.8.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": "8d9a4c6609496a27db64f964bdc388a552eae59b"
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,85 +0,0 @@
1
- import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
2
- import { focus, insertEmptyParagraph, moveToTheNextChar } from '../../helpers/editor';
3
- import newEntitySelectorConfigFromRichTextField from '../../helpers/newEntitySelectorConfigFromRichTextField';
4
- import { watchCurrentSlide } from '../../helpers/sdkNavigatorSlideIn';
5
- import { getText, getAboveNode, getLastNodeByLevel } from '../../internal/queries';
6
- import { insertNodes, select, setNodes } from '../../internal/transforms';
7
- export async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
8
- logAction('openCreateEmbedDialog', {
9
- nodeType
10
- });
11
- const { field , dialogs } = sdk;
12
- const baseConfig = newEntitySelectorConfigFromRichTextField(field, nodeType);
13
- const selectEntity = baseConfig.entityType === 'Asset' ? dialogs.selectSingleAsset : dialogs.selectSingleEntry;
14
- const config = {
15
- ...baseConfig,
16
- withCreate: true
17
- };
18
- const { selection } = editor;
19
- const rteSlide = watchCurrentSlide(sdk.navigator);
20
- const entity = await selectEntity(config);
21
- if (!entity) {
22
- logAction('cancelCreateEmbedDialog', {
23
- nodeType
24
- });
25
- } else {
26
- select(editor, selection);
27
- insertBlock(editor, nodeType, entity);
28
- ensureFollowingParagraph(editor);
29
- logAction('insert', {
30
- nodeType
31
- });
32
- }
33
- rteSlide.onActive(()=>{
34
- rteSlide.unwatch();
35
- focus(editor);
36
- });
37
- }
38
- function ensureFollowingParagraph(editor) {
39
- const entityBlock = getAboveNode(editor, {
40
- match: {
41
- type: [
42
- BLOCKS.EMBEDDED_ASSET,
43
- BLOCKS.EMBEDDED_ENTRY
44
- ]
45
- }
46
- });
47
- if (!entityBlock) {
48
- return;
49
- }
50
- const level = entityBlock[1].length - 1;
51
- const lastNode = getLastNodeByLevel(editor, level);
52
- const isTextContainer = TEXT_CONTAINERS.includes(lastNode?.[0].type ?? '');
53
- if (level !== 0 && !isTextContainer) {
54
- insertEmptyParagraph(editor);
55
- }
56
- moveToTheNextChar(editor);
57
- }
58
- const createNode = (nodeType, entity)=>({
59
- type: nodeType,
60
- data: {
61
- target: {
62
- sys: {
63
- id: entity.sys.id,
64
- type: 'Link',
65
- linkType: entity.sys.type
66
- }
67
- }
68
- },
69
- children: [
70
- {
71
- text: ''
72
- }
73
- ],
74
- isVoid: true
75
- });
76
- export function insertBlock(editor, nodeType, entity) {
77
- if (!editor?.selection) return;
78
- const linkedEntityBlock = createNode(nodeType, entity);
79
- const hasText = editor.selection && !!getText(editor, editor.selection.focus.path);
80
- if (hasText) {
81
- insertNodes(editor, linkedEntityBlock);
82
- } else {
83
- setNodes(editor, linkedEntityBlock);
84
- }
85
- }
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- export declare const styles: {
3
- icon: string;
4
- };
5
- interface EmbeddedEntityBlockToolbarIconProps {
6
- isDisabled: boolean;
7
- nodeType: string;
8
- onClose: () => void;
9
- }
10
- export declare function EmbeddedEntityBlockToolbarIcon({ isDisabled, nodeType, onClose, }: EmbeddedEntityBlockToolbarIconProps): React.JSX.Element;
11
- export {};
@@ -1,4 +0,0 @@
1
- import { PlateEditor } from '../../internal/types';
2
- import { TrackingPluginActions } from '../../plugins/Tracking';
3
- export declare function selectEntityAndInsert(nodeType: any, sdk: any, editor: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
4
- export declare function insertBlock(editor: PlateEditor, nodeType: string, entity: any): void;