@contentful/field-editor-rich-text 3.4.7 → 3.4.9
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/CHANGELOG.md +12 -0
- package/dist/field-editor-rich-text.cjs.development.js +119 -44
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +119 -44
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/sdkNavigatorSlideIn.d.ts +16 -0
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.4.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.8...@contentful/field-editor-rich-text@3.4.9) (2023-03-03)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- 🐛 do not focus RTE on inline embed + create entry ([#1354](https://github.com/contentful/field-editors/issues/1354)) ([3c54787](https://github.com/contentful/field-editors/commit/3c54787d740f7220e55976bac97fb8d542f26d4d))
|
|
11
|
+
|
|
12
|
+
## [3.4.8](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.7...@contentful/field-editor-rich-text@3.4.8) (2023-03-01)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- do not focus RTE when another slide is open [TOL-989] ([#1353](https://github.com/contentful/field-editors/issues/1353)) ([db07c18](https://github.com/contentful/field-editors/commit/db07c180ab1e9bbd197f8b4b5eb74c1e0b5e251d))
|
|
17
|
+
|
|
6
18
|
## [3.4.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-rich-text@3.4.6...@contentful/field-editor-rich-text@3.4.7) (2023-02-21)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @contentful/field-editor-rich-text
|
|
@@ -2758,13 +2758,94 @@ function getEntityTypeFromRichTextNode(nodeType) {
|
|
|
2758
2758
|
throw new Error("RichText node type `" + nodeType + "` has no associated `entityType`");
|
|
2759
2759
|
}
|
|
2760
2760
|
|
|
2761
|
+
/**
|
|
2762
|
+
* Allows to observe when the current slide-in navigation slide gets e.g.
|
|
2763
|
+
* re-activated after opening another slide on top. This is useful as the sdk
|
|
2764
|
+
* does not give full insights into e.g. whether sdk.dialogs.selectSingleEntry()
|
|
2765
|
+
* with `withCreate: true` option opens the slide-in navigation to edit the
|
|
2766
|
+
* created entry after returning it.
|
|
2767
|
+
*/
|
|
2768
|
+
|
|
2769
|
+
function watchCurrentSlide(navigator) {
|
|
2770
|
+
var onActiveCallbacks = new Set();
|
|
2771
|
+
var wasSlideClosed = false;
|
|
2772
|
+
var initialSlideLevel;
|
|
2773
|
+
var lastSlideLevel;
|
|
2774
|
+
|
|
2775
|
+
var status = function status() {
|
|
2776
|
+
return {
|
|
2777
|
+
wasClosed: wasSlideClosed,
|
|
2778
|
+
isActive: !wasSlideClosed && lastSlideLevel === initialSlideLevel
|
|
2779
|
+
};
|
|
2780
|
+
};
|
|
2781
|
+
|
|
2782
|
+
var off = navigator.onSlideInNavigation(function (_ref) {
|
|
2783
|
+
var oldSlideLevel = _ref.oldSlideLevel,
|
|
2784
|
+
newSlideLevel = _ref.newSlideLevel;
|
|
2785
|
+
|
|
2786
|
+
if (initialSlideLevel === undefined) {
|
|
2787
|
+
initialSlideLevel = oldSlideLevel;
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
lastSlideLevel = newSlideLevel;
|
|
2791
|
+
|
|
2792
|
+
if (newSlideLevel < initialSlideLevel) {
|
|
2793
|
+
wasSlideClosed = true;
|
|
2794
|
+
off(); // No more point in watching, slide got closed.
|
|
2795
|
+
|
|
2796
|
+
onActiveCallbacks.clear();
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
if (status().isActive && newSlideLevel !== oldSlideLevel) {
|
|
2800
|
+
onActiveCallbacks.forEach(function (cb) {
|
|
2801
|
+
return cb();
|
|
2802
|
+
});
|
|
2803
|
+
}
|
|
2804
|
+
});
|
|
2805
|
+
/**
|
|
2806
|
+
* Call to unsubscribe from navigator events when the watcher is no longer
|
|
2807
|
+
* needed.
|
|
2808
|
+
*/
|
|
2809
|
+
|
|
2810
|
+
function unwatch() {
|
|
2811
|
+
off();
|
|
2812
|
+
onActiveCallbacks.clear();
|
|
2813
|
+
}
|
|
2814
|
+
/**
|
|
2815
|
+
* Fires immediately when the slide is currently active, or at the point when
|
|
2816
|
+
* it becomes active again, if there are slides on top that get closed. Does not
|
|
2817
|
+
* fire when the observed slide gets closed, and then re-opened through browser
|
|
2818
|
+
* back, as this technically opens a new slide and editor instance.
|
|
2819
|
+
*/
|
|
2820
|
+
|
|
2821
|
+
|
|
2822
|
+
function onActive(cb) {
|
|
2823
|
+
if (wasSlideClosed) return noop; // Can't re-activate already closed slide.
|
|
2824
|
+
|
|
2825
|
+
if (status().isActive) {
|
|
2826
|
+
cb();
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
onActiveCallbacks.add(cb);
|
|
2830
|
+
return function () {
|
|
2831
|
+
return onActiveCallbacks["delete"](cb);
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
return {
|
|
2836
|
+
status: status,
|
|
2837
|
+
onActive: onActive,
|
|
2838
|
+
unwatch: unwatch
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2761
2842
|
function selectEntityAndInsert(_x, _x2, _x3, _x4) {
|
|
2762
2843
|
return _selectEntityAndInsert.apply(this, arguments);
|
|
2763
2844
|
} // TODO: incorporate this logic inside the trailingParagraph plugin instead
|
|
2764
2845
|
|
|
2765
2846
|
function _selectEntityAndInsert() {
|
|
2766
2847
|
_selectEntityAndInsert = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(nodeType, sdk, editor, logAction) {
|
|
2767
|
-
var field, dialogs, baseConfig, selectEntity, config,
|
|
2848
|
+
var field, dialogs, baseConfig, selectEntity, config, rteSlide, entity;
|
|
2768
2849
|
return runtime_1.wrap(function _callee$(_context) {
|
|
2769
2850
|
while (1) {
|
|
2770
2851
|
switch (_context.prev = _context.next) {
|
|
@@ -2778,32 +2859,33 @@ function _selectEntityAndInsert() {
|
|
|
2778
2859
|
config = _extends({}, baseConfig, {
|
|
2779
2860
|
withCreate: true
|
|
2780
2861
|
});
|
|
2781
|
-
|
|
2862
|
+
rteSlide = watchCurrentSlide(sdk.navigator);
|
|
2782
2863
|
_context.next = 8;
|
|
2783
2864
|
return selectEntity(config);
|
|
2784
2865
|
|
|
2785
2866
|
case 8:
|
|
2786
2867
|
entity = _context.sent;
|
|
2787
2868
|
|
|
2788
|
-
if (entity) {
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2869
|
+
if (!entity) {
|
|
2870
|
+
logAction('cancelCreateEmbedDialog', {
|
|
2871
|
+
nodeType: nodeType
|
|
2872
|
+
});
|
|
2873
|
+
} else {
|
|
2874
|
+
insertBlock$1(editor, nodeType, entity);
|
|
2875
|
+
ensureFollowingParagraph(editor);
|
|
2876
|
+
logAction('insert', {
|
|
2877
|
+
nodeType: nodeType
|
|
2878
|
+
});
|
|
2879
|
+
} // If user chose to create a new entity, this might open slide-in to edit the
|
|
2880
|
+
// entity. In this case, no point in focusing RTE which is now in the slide below.
|
|
2792
2881
|
|
|
2793
|
-
logAction('cancelCreateEmbedDialog', {
|
|
2794
|
-
nodeType: nodeType
|
|
2795
|
-
});
|
|
2796
|
-
return _context.abrupt("return");
|
|
2797
2882
|
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
ensureFollowingParagraph(editor);
|
|
2802
|
-
logAction('insert', {
|
|
2803
|
-
nodeType: nodeType
|
|
2883
|
+
rteSlide.onActive(function () {
|
|
2884
|
+
rteSlide.unwatch();
|
|
2885
|
+
focus(editor);
|
|
2804
2886
|
});
|
|
2805
2887
|
|
|
2806
|
-
case
|
|
2888
|
+
case 11:
|
|
2807
2889
|
case "end":
|
|
2808
2890
|
return _context.stop();
|
|
2809
2891
|
}
|
|
@@ -2868,8 +2950,6 @@ function insertBlock$1(editor, nodeType, entity) {
|
|
|
2868
2950
|
} else {
|
|
2869
2951
|
setNodes(editor, linkedEntityBlock);
|
|
2870
2952
|
}
|
|
2871
|
-
|
|
2872
|
-
focus(editor);
|
|
2873
2953
|
}
|
|
2874
2954
|
|
|
2875
2955
|
var styles$2 = {
|
|
@@ -3167,7 +3247,11 @@ function EmbeddedEntityInline(props) {
|
|
|
3167
3247
|
|
|
3168
3248
|
function handleEditClick() {
|
|
3169
3249
|
return sdk.navigator.openEntry(entryId, {
|
|
3170
|
-
slideIn:
|
|
3250
|
+
slideIn: {
|
|
3251
|
+
waitForClose: true
|
|
3252
|
+
}
|
|
3253
|
+
}).then(function () {
|
|
3254
|
+
editor && focus(editor);
|
|
3171
3255
|
});
|
|
3172
3256
|
}
|
|
3173
3257
|
|
|
@@ -3206,7 +3290,7 @@ function selectEntityAndInsert$1(_x, _x2, _x3) {
|
|
|
3206
3290
|
|
|
3207
3291
|
function _selectEntityAndInsert$1() {
|
|
3208
3292
|
_selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk, logAction) {
|
|
3209
|
-
var config,
|
|
3293
|
+
var config, rteSlide, entry;
|
|
3210
3294
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
3211
3295
|
while (1) {
|
|
3212
3296
|
switch (_context2.prev = _context2.next) {
|
|
@@ -3217,39 +3301,30 @@ function _selectEntityAndInsert$1() {
|
|
|
3217
3301
|
config = _extends({}, newEntitySelectorConfigFromRichTextField(sdk.field, Contentful.INLINES.EMBEDDED_ENTRY), {
|
|
3218
3302
|
withCreate: true
|
|
3219
3303
|
});
|
|
3220
|
-
|
|
3304
|
+
rteSlide = watchCurrentSlide(sdk.navigator);
|
|
3221
3305
|
_context2.next = 5;
|
|
3222
3306
|
return sdk.dialogs.selectSingleEntry(config);
|
|
3223
3307
|
|
|
3224
3308
|
case 5:
|
|
3225
3309
|
entry = _context2.sent;
|
|
3226
|
-
focus(editor); // Dialog steals focus from editor, return it.
|
|
3227
3310
|
|
|
3228
|
-
if (entry) {
|
|
3229
|
-
|
|
3230
|
-
|
|
3311
|
+
if (!entry) {
|
|
3312
|
+
logAction('cancelCreateEmbedDialog', {
|
|
3313
|
+
nodeType: Contentful.INLINES.EMBEDDED_ENTRY
|
|
3314
|
+
});
|
|
3315
|
+
} else {
|
|
3316
|
+
insertNodes(editor, createInlineEntryNode$1(entry.sys.id));
|
|
3317
|
+
logAction('insert', {
|
|
3318
|
+
nodeType: Contentful.INLINES.EMBEDDED_ENTRY
|
|
3319
|
+
});
|
|
3231
3320
|
}
|
|
3232
3321
|
|
|
3233
|
-
|
|
3234
|
-
|
|
3322
|
+
rteSlide.onActive(function () {
|
|
3323
|
+
rteSlide.unwatch();
|
|
3324
|
+
focus(editor);
|
|
3235
3325
|
});
|
|
3236
|
-
return _context2.abrupt("return");
|
|
3237
3326
|
|
|
3238
|
-
case
|
|
3239
|
-
inlineEntryNode = createInlineEntryNode$1(entry.sys.id);
|
|
3240
|
-
logAction('insert', {
|
|
3241
|
-
nodeType: Contentful.INLINES.EMBEDDED_ENTRY
|
|
3242
|
-
}); // Got to wait until focus is really back on the editor or setSelection() won't work.
|
|
3243
|
-
|
|
3244
|
-
return _context2.abrupt("return", new Promise(function (resolve) {
|
|
3245
|
-
setTimeout(function () {
|
|
3246
|
-
setSelection(editor, selection);
|
|
3247
|
-
insertNodes(editor, inlineEntryNode);
|
|
3248
|
-
resolve();
|
|
3249
|
-
}, 0);
|
|
3250
|
-
}));
|
|
3251
|
-
|
|
3252
|
-
case 13:
|
|
3327
|
+
case 8:
|
|
3253
3328
|
case "end":
|
|
3254
3329
|
return _context2.stop();
|
|
3255
3330
|
}
|