@contentful/field-editor-rich-text 6.0.0 → 6.0.1-canary.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.
- package/dist/cjs/plugins/shared/EmbeddedBlockUtil.js +26 -5
- package/dist/cjs/plugins/shared/EmbeddedInlineToolbarIcon.js +3 -1
- package/dist/cjs/plugins/shared/EmbeddedInlineUtil.js +0 -2
- package/dist/esm/plugins/shared/EmbeddedBlockUtil.js +25 -7
- package/dist/esm/plugins/shared/EmbeddedInlineToolbarIcon.js +3 -1
- package/dist/esm/plugins/shared/EmbeddedInlineUtil.js +0 -2
- package/dist/types/plugins/shared/EmbeddedBlockUtil.d.ts +2 -1
- package/package.json +2 -2
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
getWithEmbeddedBlockEvents: function() {
|
|
13
13
|
return getWithEmbeddedBlockEvents;
|
|
14
14
|
},
|
|
15
|
+
replaceEmptyParagraphWithBlock: function() {
|
|
16
|
+
return replaceEmptyParagraphWithBlock;
|
|
17
|
+
},
|
|
15
18
|
selectEntityAndInsert: function() {
|
|
16
19
|
return selectEntityAndInsert;
|
|
17
20
|
},
|
|
@@ -64,7 +67,6 @@ async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
|
|
|
64
67
|
...baseConfig,
|
|
65
68
|
withCreate: true
|
|
66
69
|
};
|
|
67
|
-
const { selection } = editor;
|
|
68
70
|
const rteSlide = (0, _sdkNavigatorSlideIn.watchCurrentSlide)(sdk.navigator);
|
|
69
71
|
const entity = await selectEntity(config);
|
|
70
72
|
if (!entity) {
|
|
@@ -72,7 +74,6 @@ async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
|
|
|
72
74
|
nodeType
|
|
73
75
|
});
|
|
74
76
|
} else {
|
|
75
|
-
(0, _internal.select)(editor, selection);
|
|
76
77
|
insertBlock(editor, nodeType, entity);
|
|
77
78
|
ensureFollowingParagraph(editor, [
|
|
78
79
|
_richtexttypes.BLOCKS.EMBEDDED_ASSET,
|
|
@@ -94,14 +95,12 @@ async function selectResourceEntityAndInsert(sdk, editor, logAction) {
|
|
|
94
95
|
});
|
|
95
96
|
const { field, dialogs } = sdk;
|
|
96
97
|
const config = (0, _config.newResourceEntitySelectorConfigFromRichTextField)(field, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE);
|
|
97
|
-
const { selection } = editor;
|
|
98
98
|
const entityLink = await dialogs.selectSingleResourceEntity(config);
|
|
99
99
|
if (!entityLink) {
|
|
100
100
|
logAction('cancelCreateEmbedDialog', {
|
|
101
101
|
nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
102
102
|
});
|
|
103
103
|
} else {
|
|
104
|
-
(0, _internal.select)(editor, selection);
|
|
105
104
|
insertBlock(editor, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE, entityLink);
|
|
106
105
|
ensureFollowingParagraph(editor, [
|
|
107
106
|
_richtexttypes.BLOCKS.EMBEDDED_RESOURCE
|
|
@@ -152,7 +151,6 @@ const createNode = (nodeType, entity)=>{
|
|
|
152
151
|
};
|
|
153
152
|
};
|
|
154
153
|
function insertBlock(editor, nodeType, entity) {
|
|
155
|
-
if (!editor?.selection) return;
|
|
156
154
|
const linkedEntityBlock = createNode(nodeType, entity);
|
|
157
155
|
const elementPath = (0, _internal.getSelectionElementPath)(editor);
|
|
158
156
|
if (elementPath && (0, _internal.isEmptyTextContainer)(editor, elementPath)) {
|
|
@@ -162,4 +160,27 @@ function insertBlock(editor, nodeType, entity) {
|
|
|
162
160
|
return;
|
|
163
161
|
}
|
|
164
162
|
(0, _internal.insertNodes)(editor, linkedEntityBlock);
|
|
163
|
+
replaceEmptyParagraphWithBlock(editor);
|
|
164
|
+
}
|
|
165
|
+
function replaceEmptyParagraphWithBlock(editor) {
|
|
166
|
+
const blockPath = (0, _editor.getAncestorPathFromSelection)(editor);
|
|
167
|
+
if (!blockPath || (0, _internal.isFirstChildPath)(blockPath)) return;
|
|
168
|
+
const previousPath = (0, _internal.getPreviousPath)(blockPath);
|
|
169
|
+
if (!previousPath) return;
|
|
170
|
+
const [nodes] = (0, _internal.getNodeEntries)(editor, {
|
|
171
|
+
at: previousPath,
|
|
172
|
+
match: (node)=>node.type === _richtexttypes.BLOCKS.PARAGRAPH
|
|
173
|
+
});
|
|
174
|
+
if (!nodes) return;
|
|
175
|
+
const [previousNode] = nodes;
|
|
176
|
+
const isPreviousNodeTextEmpty = (0, _internal.isAncestorEmpty)(editor, previousNode);
|
|
177
|
+
if (isPreviousNodeTextEmpty) {
|
|
178
|
+
(0, _internal.moveNodes)(editor, {
|
|
179
|
+
at: blockPath,
|
|
180
|
+
to: previousPath
|
|
181
|
+
});
|
|
182
|
+
(0, _internal.removeNodes)(editor, {
|
|
183
|
+
at: blockPath
|
|
184
|
+
});
|
|
185
|
+
}
|
|
165
186
|
}
|
|
@@ -83,7 +83,9 @@ function EmbeddedInlineToolbarIcon({ onClose, nodeType, isDisabled }) {
|
|
|
83
83
|
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
84
84
|
async function handleClick(event) {
|
|
85
85
|
event.preventDefault();
|
|
86
|
-
if (!editor)
|
|
86
|
+
if (!editor) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
87
89
|
onClose();
|
|
88
90
|
if (nodeType === _richtexttypes.INLINES.EMBEDDED_RESOURCE) {
|
|
89
91
|
await (0, _EmbeddedInlineUtil.selectResourceEntityAndInsert)(editor, sdk, editor.tracking.onToolbarAction);
|
|
@@ -75,7 +75,6 @@ async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
|
75
75
|
...(0, _config.newEntitySelectorConfigFromRichTextField)(sdk.field, nodeType),
|
|
76
76
|
withCreate: true
|
|
77
77
|
};
|
|
78
|
-
const { selection } = editor;
|
|
79
78
|
const rteSlide = (0, _sdkNavigatorSlideIn.watchCurrentSlide)(sdk.navigator);
|
|
80
79
|
const entry = await sdk.dialogs.selectSingleEntry(config);
|
|
81
80
|
if (!entry) {
|
|
@@ -83,7 +82,6 @@ async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
|
83
82
|
nodeType
|
|
84
83
|
});
|
|
85
84
|
} else {
|
|
86
|
-
(0, _transforms.select)(editor, selection);
|
|
87
85
|
(0, _transforms.insertNodes)(editor, createInlineEntryNode(nodeType, entry));
|
|
88
86
|
logAction('insert', {
|
|
89
87
|
nodeType,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BLOCKS, TEXT_CONTAINERS } from '@contentful/rich-text-types';
|
|
2
2
|
import isHotkey from 'is-hotkey';
|
|
3
3
|
import { newEntitySelectorConfigFromRichTextField, newResourceEntitySelectorConfigFromRichTextField } from '../../helpers/config';
|
|
4
|
-
import { focus, getNodeEntryFromSelection, insertEmptyParagraph, moveToTheNextChar } from '../../helpers/editor';
|
|
4
|
+
import { focus, getAncestorPathFromSelection, getNodeEntryFromSelection, insertEmptyParagraph, moveToTheNextChar } from '../../helpers/editor';
|
|
5
5
|
import { watchCurrentSlide } from '../../helpers/sdkNavigatorSlideIn';
|
|
6
|
-
import { getAboveNode, getLastNodeByLevel, insertNodes, getSelectionElementPath, isEmptyTextContainer, setNodes,
|
|
6
|
+
import { getAboveNode, getLastNodeByLevel, insertNodes, getSelectionElementPath, isEmptyTextContainer, setNodes, removeNodes, moveNodes, isFirstChildPath, getPreviousPath, getNodeEntries, isAncestorEmpty } from '../../internal';
|
|
7
7
|
export function getWithEmbeddedBlockEvents(nodeType, sdk) {
|
|
8
8
|
return (editor, { options: { hotkey } })=>(event)=>{
|
|
9
9
|
const [, pathToSelectedElement] = getNodeEntryFromSelection(editor, nodeType);
|
|
@@ -38,7 +38,6 @@ export async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
|
|
|
38
38
|
...baseConfig,
|
|
39
39
|
withCreate: true
|
|
40
40
|
};
|
|
41
|
-
const { selection } = editor;
|
|
42
41
|
const rteSlide = watchCurrentSlide(sdk.navigator);
|
|
43
42
|
const entity = await selectEntity(config);
|
|
44
43
|
if (!entity) {
|
|
@@ -46,7 +45,6 @@ export async function selectEntityAndInsert(nodeType, sdk, editor, logAction) {
|
|
|
46
45
|
nodeType
|
|
47
46
|
});
|
|
48
47
|
} else {
|
|
49
|
-
select(editor, selection);
|
|
50
48
|
insertBlock(editor, nodeType, entity);
|
|
51
49
|
ensureFollowingParagraph(editor, [
|
|
52
50
|
BLOCKS.EMBEDDED_ASSET,
|
|
@@ -68,14 +66,12 @@ export async function selectResourceEntityAndInsert(sdk, editor, logAction) {
|
|
|
68
66
|
});
|
|
69
67
|
const { field, dialogs } = sdk;
|
|
70
68
|
const config = newResourceEntitySelectorConfigFromRichTextField(field, BLOCKS.EMBEDDED_RESOURCE);
|
|
71
|
-
const { selection } = editor;
|
|
72
69
|
const entityLink = await dialogs.selectSingleResourceEntity(config);
|
|
73
70
|
if (!entityLink) {
|
|
74
71
|
logAction('cancelCreateEmbedDialog', {
|
|
75
72
|
nodeType: BLOCKS.EMBEDDED_RESOURCE
|
|
76
73
|
});
|
|
77
74
|
} else {
|
|
78
|
-
select(editor, selection);
|
|
79
75
|
insertBlock(editor, BLOCKS.EMBEDDED_RESOURCE, entityLink);
|
|
80
76
|
ensureFollowingParagraph(editor, [
|
|
81
77
|
BLOCKS.EMBEDDED_RESOURCE
|
|
@@ -126,7 +122,6 @@ const createNode = (nodeType, entity)=>{
|
|
|
126
122
|
};
|
|
127
123
|
};
|
|
128
124
|
function insertBlock(editor, nodeType, entity) {
|
|
129
|
-
if (!editor?.selection) return;
|
|
130
125
|
const linkedEntityBlock = createNode(nodeType, entity);
|
|
131
126
|
const elementPath = getSelectionElementPath(editor);
|
|
132
127
|
if (elementPath && isEmptyTextContainer(editor, elementPath)) {
|
|
@@ -136,4 +131,27 @@ function insertBlock(editor, nodeType, entity) {
|
|
|
136
131
|
return;
|
|
137
132
|
}
|
|
138
133
|
insertNodes(editor, linkedEntityBlock);
|
|
134
|
+
replaceEmptyParagraphWithBlock(editor);
|
|
135
|
+
}
|
|
136
|
+
export function replaceEmptyParagraphWithBlock(editor) {
|
|
137
|
+
const blockPath = getAncestorPathFromSelection(editor);
|
|
138
|
+
if (!blockPath || isFirstChildPath(blockPath)) return;
|
|
139
|
+
const previousPath = getPreviousPath(blockPath);
|
|
140
|
+
if (!previousPath) return;
|
|
141
|
+
const [nodes] = getNodeEntries(editor, {
|
|
142
|
+
at: previousPath,
|
|
143
|
+
match: (node)=>node.type === BLOCKS.PARAGRAPH
|
|
144
|
+
});
|
|
145
|
+
if (!nodes) return;
|
|
146
|
+
const [previousNode] = nodes;
|
|
147
|
+
const isPreviousNodeTextEmpty = isAncestorEmpty(editor, previousNode);
|
|
148
|
+
if (isPreviousNodeTextEmpty) {
|
|
149
|
+
moveNodes(editor, {
|
|
150
|
+
at: blockPath,
|
|
151
|
+
to: previousPath
|
|
152
|
+
});
|
|
153
|
+
removeNodes(editor, {
|
|
154
|
+
at: blockPath
|
|
155
|
+
});
|
|
156
|
+
}
|
|
139
157
|
}
|
|
@@ -27,7 +27,9 @@ export function EmbeddedInlineToolbarIcon({ onClose, nodeType, isDisabled }) {
|
|
|
27
27
|
const sdk = useSdkContext();
|
|
28
28
|
async function handleClick(event) {
|
|
29
29
|
event.preventDefault();
|
|
30
|
-
if (!editor)
|
|
30
|
+
if (!editor) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
31
33
|
onClose();
|
|
32
34
|
if (nodeType === INLINES.EMBEDDED_RESOURCE) {
|
|
33
35
|
await selectResourceEntityAndInsert(editor, sdk, editor.tracking.onToolbarAction);
|
|
@@ -49,7 +49,6 @@ export async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
|
49
49
|
...newEntitySelectorConfigFromRichTextField(sdk.field, nodeType),
|
|
50
50
|
withCreate: true
|
|
51
51
|
};
|
|
52
|
-
const { selection } = editor;
|
|
53
52
|
const rteSlide = watchCurrentSlide(sdk.navigator);
|
|
54
53
|
const entry = await sdk.dialogs.selectSingleEntry(config);
|
|
55
54
|
if (!entry) {
|
|
@@ -57,7 +56,6 @@ export async function selectEntityAndInsert(editor, sdk, logAction) {
|
|
|
57
56
|
nodeType
|
|
58
57
|
});
|
|
59
58
|
} else {
|
|
60
|
-
select(editor, selection);
|
|
61
59
|
insertNodes(editor, createInlineEntryNode(nodeType, entry));
|
|
62
60
|
logAction('insert', {
|
|
63
61
|
nodeType,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FieldAppSDK } from '@contentful/app-sdk';
|
|
2
2
|
import { BLOCKS } from '@contentful/rich-text-types';
|
|
3
3
|
import { HotkeyPlugin } from '@udecode/plate-common';
|
|
4
|
-
import { KeyboardHandler } from '../../internal';
|
|
4
|
+
import { PlateEditor, KeyboardHandler } from '../../internal';
|
|
5
5
|
import { TrackingPluginActions } from '../Tracking';
|
|
6
6
|
export declare function getWithEmbeddedBlockEvents(nodeType: BLOCKS.EMBEDDED_ENTRY | BLOCKS.EMBEDDED_ASSET | BLOCKS.EMBEDDED_RESOURCE, sdk: FieldAppSDK): KeyboardHandler<HotkeyPlugin>;
|
|
7
7
|
export declare function selectEntityAndInsert(nodeType: any, sdk: any, editor: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
|
|
8
8
|
export declare function selectResourceEntityAndInsert(sdk: any, editor: any, logAction: TrackingPluginActions['onToolbarAction'] | TrackingPluginActions['onShortcutAction']): Promise<void>;
|
|
9
|
+
export declare function replaceEmptyParagraphWithBlock(editor: PlateEditor): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1-canary.1+eafc10c9",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"publishConfig": {
|
|
95
95
|
"registry": "https://npm.pkg.github.com/"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "eafc10c961d06739843380b49133adb2099a3f5b"
|
|
98
98
|
}
|