@contentful/field-editor-rich-text 2.0.0-next.41 → 2.0.0-next.44
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/field-editor-rich-text.cjs.development.js +113 -68
- 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 +114 -69
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/environment.d.ts +1 -1
- package/dist/plugins/shared/FetchingWrappedEntryCard.d.ts +1 -1
- package/dist/plugins/shared/useFetchedEntity.d.ts +8 -0
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +6 -5
|
@@ -11,7 +11,7 @@ var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
|
11
11
|
var Contentful = require('@contentful/rich-text-types');
|
|
12
12
|
var plateCore = require('@udecode/plate-core');
|
|
13
13
|
var emotion = require('emotion');
|
|
14
|
-
var
|
|
14
|
+
var areEqual = _interopDefault(require('fast-deep-equal'));
|
|
15
15
|
var noop = _interopDefault(require('lodash/noop'));
|
|
16
16
|
var plateSerializerDocx = require('@udecode/plate-serializer-docx');
|
|
17
17
|
var plateBreak = require('@udecode/plate-break');
|
|
@@ -400,17 +400,8 @@ function getParents(el) {
|
|
|
400
400
|
return parents;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
// "modern" Edge was released at 79.x
|
|
404
|
-
var IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Edge?\/(?:[0-6][0-9]|[0-7][0-8])/i.test(navigator.userAgent); // Native `beforeInput` events don't work well with react on Chrome 75
|
|
405
|
-
// and older, Chrome 76+ can use `beforeInput` though.
|
|
406
|
-
|
|
407
|
-
var IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /*#__PURE__*/ /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent); // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
|
|
408
|
-
// Chrome Legacy doesn't support `beforeinput` correctly
|
|
409
|
-
|
|
410
|
-
var HAS_BEFORE_INPUT_SUPPORT = !IS_CHROME_LEGACY && !IS_EDGE_LEGACY && // globalThis is undefined in older browsers
|
|
411
|
-
typeof globalThis !== 'undefined' && globalThis.InputEvent && typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'; // The `getTargetRanges` property isn't recognized.
|
|
412
|
-
|
|
413
403
|
var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
404
|
+
var IS_CHROME = /*#__PURE__*/ /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/.test(navigator.userAgent);
|
|
414
405
|
|
|
415
406
|
var LINK_TYPES = [Contentful.INLINES.HYPERLINK, Contentful.INLINES.ENTRY_HYPERLINK, Contentful.INLINES.ASSET_HYPERLINK];
|
|
416
407
|
function isBlockSelected(editor, type) {
|
|
@@ -638,26 +629,56 @@ var _constate = /*#__PURE__*/constate(useSdk),
|
|
|
638
629
|
SdkProvider = _constate[0],
|
|
639
630
|
useSdkContext = _constate[1];
|
|
640
631
|
|
|
641
|
-
function
|
|
642
|
-
var
|
|
643
|
-
|
|
632
|
+
function useFetchedEntity(_ref) {
|
|
633
|
+
var type = _ref.type,
|
|
634
|
+
id = _ref.id,
|
|
635
|
+
onEntityFetchComplete = _ref.onEntityFetchComplete;
|
|
644
636
|
|
|
645
637
|
var _useEntities = fieldEditorReference.useEntities(),
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
638
|
+
entries = _useEntities.entries,
|
|
639
|
+
assets = _useEntities.assets,
|
|
640
|
+
getOrLoadEntry = _useEntities.getOrLoadEntry,
|
|
641
|
+
getOrLoadAsset = _useEntities.getOrLoadAsset;
|
|
642
|
+
|
|
643
|
+
var store = type === 'Entry' ? entries : assets;
|
|
644
|
+
|
|
645
|
+
var _useState = React.useState(store[id]),
|
|
646
|
+
entity = _useState[0],
|
|
647
|
+
setEntity = _useState[1]; // Deep compare the entity value to keep re-rendering to minimal
|
|
648
|
+
|
|
649
649
|
|
|
650
650
|
React.useEffect(function () {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
651
|
+
var newValue = store[id];
|
|
652
|
+
|
|
653
|
+
if (!areEqual(entity, newValue)) {
|
|
654
|
+
setEntity(newValue);
|
|
655
|
+
}
|
|
656
|
+
}, [store, entity, id]); // Fetch the entity if needed
|
|
657
|
+
|
|
654
658
|
React.useEffect(function () {
|
|
655
|
-
|
|
659
|
+
(type === 'Entry' ? getOrLoadEntry : getOrLoadAsset)(id); // "getOrLoadEntry" and "getOrLoadAsset" instances change with every
|
|
660
|
+
// entity store update causing page lag on initial load
|
|
661
|
+
// TODO: consider rewriting useEntities() hook to avoid that happening in
|
|
662
|
+
// first place.
|
|
663
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
664
|
+
}, [type, id]);
|
|
665
|
+
React.useEffect(function () {
|
|
666
|
+
if (entity) {
|
|
656
667
|
onEntityFetchComplete == null ? void 0 : onEntityFetchComplete();
|
|
657
668
|
}
|
|
658
|
-
}, [onEntityFetchComplete,
|
|
669
|
+
}, [onEntityFetchComplete, entity]);
|
|
670
|
+
return entity;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
var InternalAssetCard = /*#__PURE__*/React.memo(function (props) {
|
|
674
|
+
if (props.asset === undefined) {
|
|
675
|
+
return /*#__PURE__*/React.createElement(f36Components.AssetCard, {
|
|
676
|
+
size: "default",
|
|
677
|
+
isLoading: true
|
|
678
|
+
});
|
|
679
|
+
}
|
|
659
680
|
|
|
660
|
-
if (asset === 'failed') {
|
|
681
|
+
if (props.asset === 'failed') {
|
|
661
682
|
return /*#__PURE__*/React.createElement(fieldEditorReference.MissingEntityCard, {
|
|
662
683
|
entityType: "Asset",
|
|
663
684
|
isDisabled: props.isDisabled,
|
|
@@ -665,45 +686,48 @@ function FetchingWrappedAssetCard(props) {
|
|
|
665
686
|
});
|
|
666
687
|
}
|
|
667
688
|
|
|
668
|
-
if (asset === undefined) {
|
|
669
|
-
return /*#__PURE__*/React.createElement(f36Components.AssetCard, {
|
|
670
|
-
size: "default",
|
|
671
|
-
isLoading: true
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
|
|
675
689
|
return /*#__PURE__*/React.createElement(fieldEditorReference.WrappedAssetCard, {
|
|
676
|
-
getEntityScheduledActions: loadEntityScheduledActions,
|
|
690
|
+
getEntityScheduledActions: props.loadEntityScheduledActions,
|
|
677
691
|
size: "small",
|
|
678
692
|
isSelected: props.isSelected,
|
|
679
693
|
isDisabled: props.isDisabled,
|
|
680
694
|
localeCode: props.locale,
|
|
681
695
|
defaultLocaleCode: props.sdk.locales["default"],
|
|
682
|
-
asset: asset,
|
|
696
|
+
asset: props.asset,
|
|
683
697
|
onEdit: props.onEdit,
|
|
684
698
|
onRemove: props.isDisabled ? undefined : props.onRemove,
|
|
685
699
|
isClickable: false
|
|
686
700
|
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
function
|
|
690
|
-
var
|
|
691
|
-
|
|
701
|
+
}, areEqual);
|
|
702
|
+
InternalAssetCard.displayName = 'InternalAssetCard';
|
|
703
|
+
function FetchingWrappedAssetCard(props) {
|
|
704
|
+
var onEntityFetchComplete = props.onEntityFetchComplete,
|
|
705
|
+
assetId = props.assetId;
|
|
692
706
|
|
|
693
707
|
var _useEntities = fieldEditorReference.useEntities(),
|
|
694
|
-
|
|
695
|
-
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions,
|
|
696
|
-
entries = _useEntities.entries;
|
|
708
|
+
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
|
|
697
709
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
710
|
+
var asset = useFetchedEntity({
|
|
711
|
+
type: 'Asset',
|
|
712
|
+
id: assetId,
|
|
713
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
714
|
+
});
|
|
715
|
+
return /*#__PURE__*/React.createElement(InternalAssetCard, {
|
|
716
|
+
asset: asset,
|
|
717
|
+
sdk: props.sdk,
|
|
718
|
+
isDisabled: props.isDisabled,
|
|
719
|
+
isSelected: props.isSelected,
|
|
720
|
+
loadEntityScheduledActions: loadEntityScheduledActions,
|
|
721
|
+
locale: props.locale,
|
|
722
|
+
onEdit: props.onEdit,
|
|
723
|
+
onRemove: props.onRemove
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
var InternalEntryCard = /*#__PURE__*/React.memo(function (props) {
|
|
728
|
+
var entry = props.entry,
|
|
729
|
+
sdk = props.sdk,
|
|
730
|
+
loadEntityScheduledActions = props.loadEntityScheduledActions;
|
|
707
731
|
|
|
708
732
|
if (entry === undefined) {
|
|
709
733
|
return /*#__PURE__*/React.createElement(f36Components.EntryCard, {
|
|
@@ -719,7 +743,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
719
743
|
});
|
|
720
744
|
}
|
|
721
745
|
|
|
722
|
-
var contentType =
|
|
746
|
+
var contentType = sdk.space.getCachedContentTypes().find(function (contentType) {
|
|
723
747
|
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
724
748
|
});
|
|
725
749
|
return /*#__PURE__*/React.createElement(fieldEditorReference.WrappedEntryCard, {
|
|
@@ -736,7 +760,31 @@ function FetchingWrappedEntryCard(props) {
|
|
|
736
760
|
onRemove: props.isDisabled ? undefined : props.onRemove,
|
|
737
761
|
isClickable: false
|
|
738
762
|
});
|
|
739
|
-
}
|
|
763
|
+
}, areEqual);
|
|
764
|
+
InternalEntryCard.displayName = 'ReferenceCard';
|
|
765
|
+
var FetchingWrappedEntryCard = function FetchingWrappedEntryCard(props) {
|
|
766
|
+
var entryId = props.entryId,
|
|
767
|
+
onEntityFetchComplete = props.onEntityFetchComplete;
|
|
768
|
+
|
|
769
|
+
var _useEntities = fieldEditorReference.useEntities(),
|
|
770
|
+
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
|
|
771
|
+
|
|
772
|
+
var entry = useFetchedEntity({
|
|
773
|
+
type: 'Entry',
|
|
774
|
+
id: entryId,
|
|
775
|
+
onEntityFetchComplete: onEntityFetchComplete
|
|
776
|
+
});
|
|
777
|
+
return /*#__PURE__*/React.createElement(InternalEntryCard, {
|
|
778
|
+
entry: entry,
|
|
779
|
+
sdk: props.sdk,
|
|
780
|
+
locale: props.locale,
|
|
781
|
+
isDisabled: props.isDisabled,
|
|
782
|
+
isSelected: props.isSelected,
|
|
783
|
+
onEdit: props.onEdit,
|
|
784
|
+
onRemove: props.onRemove,
|
|
785
|
+
loadEntityScheduledActions: loadEntityScheduledActions
|
|
786
|
+
});
|
|
787
|
+
};
|
|
740
788
|
|
|
741
789
|
var styles = {
|
|
742
790
|
root: /*#__PURE__*/emotion.css({
|
|
@@ -763,33 +811,30 @@ function LinkedEntityBlock(props) {
|
|
|
763
811
|
var _element$data$target$ = element.data.target.sys,
|
|
764
812
|
entityId = _element$data$target$.id,
|
|
765
813
|
entityType = _element$data$target$.linkType;
|
|
766
|
-
|
|
767
|
-
var handleEditClick = function handleEditClick() {
|
|
814
|
+
var handleEditClick = React__default.useCallback(function () {
|
|
768
815
|
var openEntity = entityType === 'Asset' ? sdk.navigator.openAsset : sdk.navigator.openEntry;
|
|
769
816
|
return openEntity(entityId, {
|
|
770
817
|
slideIn: true
|
|
771
818
|
});
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
var handleRemoveClick = function handleRemoveClick() {
|
|
819
|
+
}, [sdk, entityId, entityType]);
|
|
820
|
+
var handleRemoveClick = React__default.useCallback(function () {
|
|
775
821
|
if (!editor) return;
|
|
776
822
|
var pathToElement = Slate.ReactEditor.findPath(editor, element);
|
|
777
823
|
slate.Transforms.removeNodes(editor, {
|
|
778
824
|
at: pathToElement
|
|
779
825
|
});
|
|
780
|
-
};
|
|
781
|
-
|
|
826
|
+
}, [editor, element]);
|
|
782
827
|
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
|
783
828
|
className: styles.root,
|
|
784
829
|
"data-entity-type": entityType,
|
|
785
830
|
"data-entity-id": entityId,
|
|
786
831
|
// COMPAT: This makes copy & paste work for Firefox
|
|
787
|
-
contentEditable:
|
|
788
|
-
draggable:
|
|
832
|
+
contentEditable: IS_CHROME ? undefined : false,
|
|
833
|
+
draggable: IS_CHROME ? true : undefined
|
|
789
834
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
790
835
|
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
791
|
-
contentEditable:
|
|
792
|
-
draggable:
|
|
836
|
+
contentEditable: IS_CHROME ? false : undefined,
|
|
837
|
+
draggable: IS_CHROME ? true : undefined,
|
|
793
838
|
className: styles.container
|
|
794
839
|
}, entityType === 'Entry' && /*#__PURE__*/React__default.createElement(FetchingWrappedEntryCard, {
|
|
795
840
|
sdk: sdk,
|
|
@@ -2043,12 +2088,12 @@ function EmbeddedEntityInline(props) {
|
|
|
2043
2088
|
className: styles$3.root,
|
|
2044
2089
|
"data-embedded-entity-inline-id": entryId,
|
|
2045
2090
|
// COMPAT: This makes copy & paste work for Firefox
|
|
2046
|
-
contentEditable:
|
|
2047
|
-
draggable:
|
|
2091
|
+
contentEditable: IS_CHROME ? undefined : false,
|
|
2092
|
+
draggable: IS_CHROME ? true : undefined
|
|
2048
2093
|
}), /*#__PURE__*/React.createElement("span", {
|
|
2049
2094
|
// COMPAT: This makes copy & paste work for Chromium/Blink browsers and Safari
|
|
2050
|
-
contentEditable:
|
|
2051
|
-
draggable:
|
|
2095
|
+
contentEditable: IS_CHROME ? false : undefined,
|
|
2096
|
+
draggable: IS_CHROME ? true : undefined
|
|
2052
2097
|
}, /*#__PURE__*/React.createElement(FetchingWrappedInlineEntryCard, {
|
|
2053
2098
|
sdk: sdk,
|
|
2054
2099
|
entryId: entryId,
|
|
@@ -6957,7 +7002,7 @@ var RichTextEditor = function RichTextEditor(props) {
|
|
|
6957
7002
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
6958
7003
|
|
|
6959
7004
|
var isEmptyValue = React.useCallback(function (value) {
|
|
6960
|
-
return !value ||
|
|
7005
|
+
return !value || areEqual(value, Contentful.EMPTY_DOCUMENT);
|
|
6961
7006
|
}, []);
|
|
6962
7007
|
var id = getContentfulEditorId(props.sdk);
|
|
6963
7008
|
return /*#__PURE__*/React__default.createElement(fieldEditorReference.EntityProvider, {
|
|
@@ -6967,7 +7012,7 @@ var RichTextEditor = function RichTextEditor(props) {
|
|
|
6967
7012
|
field: sdk.field,
|
|
6968
7013
|
isInitiallyDisabled: isInitiallyDisabled,
|
|
6969
7014
|
isEmptyValue: isEmptyValue,
|
|
6970
|
-
isEqualValues:
|
|
7015
|
+
isEqualValues: areEqual
|
|
6971
7016
|
}, function (_ref) {
|
|
6972
7017
|
var lastRemoteValue = _ref.lastRemoteValue,
|
|
6973
7018
|
disabled = _ref.disabled,
|