@contentful/field-editor-reference 5.0.0 → 5.1.2
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 +18 -0
- package/dist/assets/MultipleMediaEditor.d.ts +1 -1
- package/dist/assets/SingleMediaEditor.d.ts +1 -1
- package/dist/field-editor-reference.cjs.development.js +451 -6
- package/dist/field-editor-reference.cjs.development.js.map +1 -1
- package/dist/field-editor-reference.cjs.production.min.js +1 -1
- package/dist/field-editor-reference.cjs.production.min.js.map +1 -1
- package/dist/field-editor-reference.esm.js +450 -7
- package/dist/field-editor-reference.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/resources/Cards/ContentfulEntryCard.d.ts +21 -0
- package/dist/resources/Cards/ResourceCard.d.ts +12 -0
- package/dist/resources/Cards/UnsupportedEntityCard.d.ts +4 -0
- package/dist/resources/MultipleResourceReferenceEditor.d.ts +7 -0
- package/dist/resources/SingleResourceReferenceEditor.d.ts +7 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/testHelpers/resourceEditorHelpers.d.ts +50 -0
- package/dist/resources/useResourceLinkActions.d.ts +7 -0
- package/dist/types.d.ts +10 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
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
|
+
## [5.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.1...@contentful/field-editor-reference@5.1.2) (2022-08-26)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- change the props type definitions ([#1222](https://github.com/contentful/field-editors/issues/1222)) ([f71394b](https://github.com/contentful/field-editors/commit/f71394b3653c4e84bb45ed5745ba81eb0522e680))
|
|
11
|
+
|
|
12
|
+
## [5.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.0...@contentful/field-editor-reference@5.1.1) (2022-08-25)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- add p-queue as dependency ([#1220](https://github.com/contentful/field-editors/issues/1220)) ([8576389](https://github.com/contentful/field-editors/commit/85763896092414acce8e3e2f81f375dcf983b49f))
|
|
17
|
+
|
|
18
|
+
# [5.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.0.0...@contentful/field-editor-reference@5.1.0) (2022-08-24)
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
- moving resource editors from web app [TOL-282] ([#1216](https://github.com/contentful/field-editors/issues/1216)) ([8e037d4](https://github.com/contentful/field-editors/commit/8e037d4f938aba8b9177de3e85a4a1d192ad3db5))
|
|
23
|
+
|
|
6
24
|
# [5.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@4.6.10...@contentful/field-editor-reference@5.0.0) (2022-08-18)
|
|
7
25
|
|
|
8
26
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ReferenceEditorProps } from '../common/ReferenceEditor';
|
|
3
|
-
declare type EditorProps =
|
|
3
|
+
declare type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
|
|
4
4
|
export declare function MultipleMediaEditor(props: EditorProps): JSX.Element;
|
|
5
5
|
export declare namespace MultipleMediaEditor {
|
|
6
6
|
var defaultProps: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ReferenceEditorProps } from '../common/ReferenceEditor';
|
|
3
|
-
declare type EditorProps =
|
|
3
|
+
declare type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
|
|
4
4
|
export declare function SingleMediaEditor(props: EditorProps): JSX.Element;
|
|
5
5
|
export declare namespace SingleMediaEditor {
|
|
6
6
|
var defaultProps: {
|
|
@@ -22,6 +22,7 @@ var isNumber = _interopDefault(require('lodash/isNumber'));
|
|
|
22
22
|
var arrayMove = _interopDefault(require('array-move'));
|
|
23
23
|
var reactSortableHoc = require('react-sortable-hoc');
|
|
24
24
|
var mimetype = _interopDefault(require('@contentful/mimetype'));
|
|
25
|
+
var reactIntersectionObserver = require('react-intersection-observer');
|
|
25
26
|
|
|
26
27
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
27
28
|
try {
|
|
@@ -1940,6 +1941,9 @@ var UnsupportedError = /*#__PURE__*/function (_Error) {
|
|
|
1940
1941
|
|
|
1941
1942
|
return UnsupportedError;
|
|
1942
1943
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1944
|
+
function isUnsupportedError(value) {
|
|
1945
|
+
return typeof value === 'object' && (value == null ? void 0 : value.isUnsupportedError) === true;
|
|
1946
|
+
}
|
|
1943
1947
|
|
|
1944
1948
|
var isEntityQueryKey = function isEntityQueryKey(queryKey) {
|
|
1945
1949
|
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
@@ -2280,8 +2284,7 @@ function useEntity(entityType, entityId, options) {
|
|
|
2280
2284
|
var _useQuery = reactQuery.useQuery(queryKey, function () {
|
|
2281
2285
|
return getEntity(entityType, entityId, options);
|
|
2282
2286
|
}, {
|
|
2283
|
-
enabled: options == null ? void 0 : options.enabled
|
|
2284
|
-
useErrorBoundary: false
|
|
2287
|
+
enabled: options == null ? void 0 : options.enabled
|
|
2285
2288
|
}),
|
|
2286
2289
|
status = _useQuery.status,
|
|
2287
2290
|
data = _useQuery.data;
|
|
@@ -2300,9 +2303,7 @@ function useResource(resourceType, urn, options) {
|
|
|
2300
2303
|
var _useQuery2 = reactQuery.useQuery(queryKey, function () {
|
|
2301
2304
|
return getResource(resourceType, urn, options);
|
|
2302
2305
|
}, {
|
|
2303
|
-
enabled: options == null ? void 0 : options.enabled
|
|
2304
|
-
// TODO: check if this is ok for all errors
|
|
2305
|
-
useErrorBoundary: false
|
|
2306
|
+
enabled: options == null ? void 0 : options.enabled
|
|
2306
2307
|
}),
|
|
2307
2308
|
status = _useQuery2.status,
|
|
2308
2309
|
data = _useQuery2.data,
|
|
@@ -2325,7 +2326,7 @@ function EntityProvider(_ref8) {
|
|
|
2325
2326
|
queryCache: queryCache,
|
|
2326
2327
|
defaultOptions: {
|
|
2327
2328
|
queries: {
|
|
2328
|
-
useErrorBoundary:
|
|
2329
|
+
useErrorBoundary: false,
|
|
2329
2330
|
refetchOnWindowFocus: false,
|
|
2330
2331
|
refetchOnReconnect: true,
|
|
2331
2332
|
refetchOnMount: false,
|
|
@@ -3819,6 +3820,448 @@ MultipleMediaEditor.defaultProps = {
|
|
|
3819
3820
|
isInitiallyDisabled: true
|
|
3820
3821
|
};
|
|
3821
3822
|
|
|
3823
|
+
var resolveAsset = function resolveAsset() {
|
|
3824
|
+
return Promise.resolve();
|
|
3825
|
+
}; // we don't want to show scheduled actions for resources
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
var resolveScheduledActions = function resolveScheduledActions() {
|
|
3829
|
+
return Promise.resolve([]);
|
|
3830
|
+
};
|
|
3831
|
+
|
|
3832
|
+
function ContentfulEntryCard(_ref) {
|
|
3833
|
+
var info = _ref.info,
|
|
3834
|
+
isDisabled = _ref.isDisabled,
|
|
3835
|
+
renderDragHandle = _ref.renderDragHandle,
|
|
3836
|
+
onRemove = _ref.onRemove,
|
|
3837
|
+
onMoveTop = _ref.onMoveTop,
|
|
3838
|
+
onMoveBottom = _ref.onMoveBottom,
|
|
3839
|
+
getEntryRouteHref = _ref.getEntryRouteHref;
|
|
3840
|
+
var resourceSys = info.resource.sys;
|
|
3841
|
+
var spaceId = resourceSys.space.sys.id;
|
|
3842
|
+
var environmentId = resourceSys.environment.sys.id;
|
|
3843
|
+
var entryId = resourceSys.id;
|
|
3844
|
+
var resourceHref = getEntryRouteHref({
|
|
3845
|
+
spaceId: spaceId,
|
|
3846
|
+
environmentId: environmentId,
|
|
3847
|
+
entryId: entryId
|
|
3848
|
+
}); // TODO: move this into `sdk.navigator.openEntry()`, note that it's signature only include the entry id (not a space or environment)
|
|
3849
|
+
|
|
3850
|
+
var openEntryDetail = function openEntryDetail() {
|
|
3851
|
+
window.open(resourceHref, '_blank', 'noopener,noreferrer');
|
|
3852
|
+
};
|
|
3853
|
+
|
|
3854
|
+
return React.createElement(WrappedEntryCard, {
|
|
3855
|
+
entry: info.resource,
|
|
3856
|
+
isDisabled: isDisabled,
|
|
3857
|
+
hasCardEditActions: false,
|
|
3858
|
+
contentType: info.contentType,
|
|
3859
|
+
// we use the default locale from the space the entry belongs to
|
|
3860
|
+
// as we assume this gives a more consistent behaviour.
|
|
3861
|
+
// locales will inevitably differ from space to space, so it's likely
|
|
3862
|
+
// that the current locale does not exist in the "remote" space
|
|
3863
|
+
localeCode: info.defaultLocaleCode,
|
|
3864
|
+
defaultLocaleCode: info.defaultLocaleCode,
|
|
3865
|
+
size: "small",
|
|
3866
|
+
getAsset: resolveAsset,
|
|
3867
|
+
getEntityScheduledActions: resolveScheduledActions,
|
|
3868
|
+
spaceName: info.space.name,
|
|
3869
|
+
renderDragHandle: renderDragHandle,
|
|
3870
|
+
isClickable: true,
|
|
3871
|
+
onEdit: openEntryDetail,
|
|
3872
|
+
hasCardRemoveActions: Boolean(onRemove),
|
|
3873
|
+
onRemove: onRemove,
|
|
3874
|
+
onMoveBottom: onMoveBottom,
|
|
3875
|
+
onMoveTop: onMoveTop,
|
|
3876
|
+
entryUrl: resourceHref
|
|
3877
|
+
});
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
var styles$7 = {
|
|
3881
|
+
card: /*#__PURE__*/emotion.css({
|
|
3882
|
+
position: 'relative'
|
|
3883
|
+
})
|
|
3884
|
+
};
|
|
3885
|
+
function UnsupportedEntityCard(props) {
|
|
3886
|
+
return React__default.createElement(f36Components.Card, {
|
|
3887
|
+
className: styles$7.card
|
|
3888
|
+
}, React__default.createElement(f36Components.SectionHeading, {
|
|
3889
|
+
marginBottom: "none"
|
|
3890
|
+
}, "Resource type ", props.entityType, " is currently not supported"));
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
function ResourceCardSkeleton() {
|
|
3894
|
+
return React.createElement(f36Components.EntryCard, {
|
|
3895
|
+
size: "small",
|
|
3896
|
+
isLoading: true
|
|
3897
|
+
});
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
function ExistingResourceCard(props) {
|
|
3901
|
+
var resourceLink = props.resourceLink,
|
|
3902
|
+
inView = props.inView,
|
|
3903
|
+
_props$index = props.index,
|
|
3904
|
+
index = _props$index === void 0 ? 0 : _props$index;
|
|
3905
|
+
var resourceOptions = {
|
|
3906
|
+
priority: index * -1,
|
|
3907
|
+
enabled: inView
|
|
3908
|
+
};
|
|
3909
|
+
|
|
3910
|
+
var _useResource = useResource(resourceLink.sys.linkType, resourceLink.sys.urn, resourceOptions),
|
|
3911
|
+
data = _useResource.data,
|
|
3912
|
+
error = _useResource.error;
|
|
3913
|
+
|
|
3914
|
+
if (!data && !error) {
|
|
3915
|
+
return React.createElement(ResourceCardSkeleton, null);
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
if (data) {
|
|
3919
|
+
return React.createElement(ContentfulEntryCard, _extends({
|
|
3920
|
+
info: data
|
|
3921
|
+
}, props));
|
|
3922
|
+
}
|
|
3923
|
+
|
|
3924
|
+
if (isUnsupportedError(error)) {
|
|
3925
|
+
return React.createElement(UnsupportedEntityCard, {
|
|
3926
|
+
entityType: resourceLink.sys.linkType
|
|
3927
|
+
});
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
return React.createElement(MissingEntityCard, {
|
|
3931
|
+
entityType: "Entry",
|
|
3932
|
+
isDisabled: props.isDisabled,
|
|
3933
|
+
onRemove: props.onRemove
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
|
|
3937
|
+
function ResourceCardWrapper(props) {
|
|
3938
|
+
if (!props.resourceLink) {
|
|
3939
|
+
return null;
|
|
3940
|
+
}
|
|
3941
|
+
|
|
3942
|
+
return React.createElement(ExistingResourceCard, _extends({}, props, {
|
|
3943
|
+
resourceLink: props.resourceLink,
|
|
3944
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
3945
|
+
}));
|
|
3946
|
+
}
|
|
3947
|
+
|
|
3948
|
+
function ResourceCard(props) {
|
|
3949
|
+
var _useInView = reactIntersectionObserver.useInView({
|
|
3950
|
+
triggerOnce: true,
|
|
3951
|
+
rootMargin: '300px 0px 0px 300px'
|
|
3952
|
+
}),
|
|
3953
|
+
ref = _useInView.ref,
|
|
3954
|
+
inView = _useInView.inView; // Forma does not offer us to pass refs, so we need an additional wrapper here
|
|
3955
|
+
|
|
3956
|
+
|
|
3957
|
+
return React.createElement("div", {
|
|
3958
|
+
ref: ref
|
|
3959
|
+
}, React.createElement(ResourceCardWrapper, _extends({}, props, {
|
|
3960
|
+
inView: inView
|
|
3961
|
+
})));
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
function useResourceLinkActions(_ref) {
|
|
3965
|
+
var apiUrl = _ref.apiUrl,
|
|
3966
|
+
dialogs = _ref.dialogs,
|
|
3967
|
+
field = _ref.field,
|
|
3968
|
+
onAfterLink = _ref.onAfterLink;
|
|
3969
|
+
var handleAfterLink = React.useCallback(function (entries) {
|
|
3970
|
+
if (!onAfterLink) {
|
|
3971
|
+
return;
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
entries.forEach(onAfterLink);
|
|
3975
|
+
}, [onAfterLink]);
|
|
3976
|
+
var multiple = field.type === 'Array';
|
|
3977
|
+
var toLinkItem = React.useMemo(function () {
|
|
3978
|
+
function toUrn(entry) {
|
|
3979
|
+
return "crn:" + apiUrl + ":::content:spaces/" + entry.sys.space.sys.id + "/entries/" + entry.sys.id;
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
return function (entry) {
|
|
3983
|
+
return {
|
|
3984
|
+
sys: {
|
|
3985
|
+
type: 'ResourceLink',
|
|
3986
|
+
linkType: 'Contentful:Entry',
|
|
3987
|
+
urn: toUrn(entry)
|
|
3988
|
+
}
|
|
3989
|
+
};
|
|
3990
|
+
};
|
|
3991
|
+
}, [apiUrl]);
|
|
3992
|
+
var onLinkedExisting = React.useMemo(function () {
|
|
3993
|
+
if (multiple) {
|
|
3994
|
+
return function (entries) {
|
|
3995
|
+
var linkItems = entries.map(toLinkItem);
|
|
3996
|
+
var prevValue = field.getValue() || [];
|
|
3997
|
+
var updatedValue = [].concat(prevValue, linkItems);
|
|
3998
|
+
field.setValue(updatedValue);
|
|
3999
|
+
handleAfterLink(entries);
|
|
4000
|
+
};
|
|
4001
|
+
} else {
|
|
4002
|
+
return function (entries) {
|
|
4003
|
+
var entry = entries[0];
|
|
4004
|
+
field.setValue(toLinkItem(entry));
|
|
4005
|
+
handleAfterLink([entry]);
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
}, [field, handleAfterLink, multiple, toLinkItem]);
|
|
4009
|
+
var onLinkExisting = React.useMemo(function () {
|
|
4010
|
+
var promptSelection = multiple ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
4011
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
4012
|
+
while (1) {
|
|
4013
|
+
switch (_context.prev = _context.next) {
|
|
4014
|
+
case 0:
|
|
4015
|
+
_context.next = 2;
|
|
4016
|
+
return dialogs.selectMultipleResourceEntries({
|
|
4017
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
4018
|
+
allowedResources: field.allowedResources
|
|
4019
|
+
});
|
|
4020
|
+
|
|
4021
|
+
case 2:
|
|
4022
|
+
return _context.abrupt("return", _context.sent);
|
|
4023
|
+
|
|
4024
|
+
case 3:
|
|
4025
|
+
case "end":
|
|
4026
|
+
return _context.stop();
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
}, _callee);
|
|
4030
|
+
})) : /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
4031
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
4032
|
+
while (1) {
|
|
4033
|
+
switch (_context2.prev = _context2.next) {
|
|
4034
|
+
case 0:
|
|
4035
|
+
_context2.next = 2;
|
|
4036
|
+
return dialogs.selectSingleResourceEntry({
|
|
4037
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
4038
|
+
allowedResources: field.allowedResources
|
|
4039
|
+
});
|
|
4040
|
+
|
|
4041
|
+
case 2:
|
|
4042
|
+
_context2.t0 = _context2.sent;
|
|
4043
|
+
return _context2.abrupt("return", [_context2.t0]);
|
|
4044
|
+
|
|
4045
|
+
case 4:
|
|
4046
|
+
case "end":
|
|
4047
|
+
return _context2.stop();
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4050
|
+
}, _callee2);
|
|
4051
|
+
}));
|
|
4052
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
4053
|
+
var res;
|
|
4054
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
4055
|
+
while (1) {
|
|
4056
|
+
switch (_context3.prev = _context3.next) {
|
|
4057
|
+
case 0:
|
|
4058
|
+
_context3.next = 2;
|
|
4059
|
+
return promptSelection();
|
|
4060
|
+
|
|
4061
|
+
case 2:
|
|
4062
|
+
res = _context3.sent;
|
|
4063
|
+
|
|
4064
|
+
if (res) {
|
|
4065
|
+
_context3.next = 5;
|
|
4066
|
+
break;
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
return _context3.abrupt("return");
|
|
4070
|
+
|
|
4071
|
+
case 5:
|
|
4072
|
+
onLinkedExisting(res);
|
|
4073
|
+
|
|
4074
|
+
case 6:
|
|
4075
|
+
case "end":
|
|
4076
|
+
return _context3.stop();
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
}, _callee3);
|
|
4080
|
+
})); // @ts-expect-error wait for update of app-sdk version
|
|
4081
|
+
}, [dialogs, field.allowedResources, multiple, onLinkedExisting]);
|
|
4082
|
+
return {
|
|
4083
|
+
onLinkExisting: onLinkExisting,
|
|
4084
|
+
onLinkedExisting: onLinkedExisting,
|
|
4085
|
+
// hardcoded values to match interface for standard reference field actions
|
|
4086
|
+
entityType: 'Entry',
|
|
4087
|
+
contentTypes: [],
|
|
4088
|
+
canCreateEntity: false,
|
|
4089
|
+
canLinkMultiple: multiple,
|
|
4090
|
+
canLinkEntity: true,
|
|
4091
|
+
isDisabled: false,
|
|
4092
|
+
isEmpty: false,
|
|
4093
|
+
isFull: false,
|
|
4094
|
+
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4095
|
+
onCreate: function () {
|
|
4096
|
+
var _onCreate = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
4097
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
4098
|
+
while (1) {
|
|
4099
|
+
switch (_context4.prev = _context4.next) {
|
|
4100
|
+
case 0:
|
|
4101
|
+
case "end":
|
|
4102
|
+
return _context4.stop();
|
|
4103
|
+
}
|
|
4104
|
+
}
|
|
4105
|
+
}, _callee4);
|
|
4106
|
+
}));
|
|
4107
|
+
|
|
4108
|
+
function onCreate() {
|
|
4109
|
+
return _onCreate.apply(this, arguments);
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4112
|
+
return onCreate;
|
|
4113
|
+
}(),
|
|
4114
|
+
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4115
|
+
onCreated: function onCreated() {}
|
|
4116
|
+
};
|
|
4117
|
+
}
|
|
4118
|
+
|
|
4119
|
+
function ResourceEditor(props) {
|
|
4120
|
+
var setValue = props.setValue,
|
|
4121
|
+
items = props.items,
|
|
4122
|
+
apiUrl = props.apiUrl;
|
|
4123
|
+
var onSortStart = React.useCallback(function (_, event) {
|
|
4124
|
+
return event.preventDefault();
|
|
4125
|
+
}, []);
|
|
4126
|
+
var onSortEnd = React.useCallback(function (_ref) {
|
|
4127
|
+
var oldIndex = _ref.oldIndex,
|
|
4128
|
+
newIndex = _ref.newIndex;
|
|
4129
|
+
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4130
|
+
setValue(newItems);
|
|
4131
|
+
}, [items, setValue]);
|
|
4132
|
+
var onMove = React.useCallback(function (oldIndex, newIndex) {
|
|
4133
|
+
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4134
|
+
setValue(newItems);
|
|
4135
|
+
}, [items, setValue]);
|
|
4136
|
+
var onRemoteItemAtIndex = React.useCallback(function (index) {
|
|
4137
|
+
setValue(items.filter(function (_v, i) {
|
|
4138
|
+
return i !== index;
|
|
4139
|
+
}));
|
|
4140
|
+
}, [items, setValue]);
|
|
4141
|
+
var _props$sdk = props.sdk,
|
|
4142
|
+
dialogs = _props$sdk.dialogs,
|
|
4143
|
+
field = _props$sdk.field;
|
|
4144
|
+
var linkActionsProps = useResourceLinkActions({
|
|
4145
|
+
dialogs: dialogs,
|
|
4146
|
+
field: field,
|
|
4147
|
+
apiUrl: apiUrl
|
|
4148
|
+
});
|
|
4149
|
+
return React.createElement(React.Fragment, null, props.children(_extends({}, props, {
|
|
4150
|
+
onSortStart: onSortStart,
|
|
4151
|
+
onSortEnd: onSortEnd,
|
|
4152
|
+
onMove: onMove,
|
|
4153
|
+
onRemoteItemAtIndex: onRemoteItemAtIndex
|
|
4154
|
+
})), React.createElement(CombinedLinkActions, _extends({}, linkActionsProps)));
|
|
4155
|
+
} // provides memoized callbacks bound to a given item
|
|
4156
|
+
|
|
4157
|
+
|
|
4158
|
+
function WithPerItemCallbacks(_ref2) {
|
|
4159
|
+
var listLength = _ref2.listLength,
|
|
4160
|
+
index = _ref2.index,
|
|
4161
|
+
onMove = _ref2.onMove,
|
|
4162
|
+
onRemoteItemAtIndex = _ref2.onRemoteItemAtIndex,
|
|
4163
|
+
children = _ref2.children;
|
|
4164
|
+
var handleMoveTop = React.useMemo(function () {
|
|
4165
|
+
return index > 0 ? function () {
|
|
4166
|
+
return onMove(index, 0);
|
|
4167
|
+
} : undefined;
|
|
4168
|
+
}, [index, onMove]);
|
|
4169
|
+
var handleMoveBottom = React.useMemo(function () {
|
|
4170
|
+
return index < listLength - 1 ? function () {
|
|
4171
|
+
return onMove(index, listLength - 1);
|
|
4172
|
+
} : undefined;
|
|
4173
|
+
}, [index, onMove, listLength]);
|
|
4174
|
+
var handleRemove = React.useCallback(function () {
|
|
4175
|
+
return onRemoteItemAtIndex(index);
|
|
4176
|
+
}, [index, onRemoteItemAtIndex]);
|
|
4177
|
+
return React.createElement(React.Fragment, null, children({
|
|
4178
|
+
onMoveBottom: handleMoveBottom,
|
|
4179
|
+
onMoveTop: handleMoveTop,
|
|
4180
|
+
onRemove: handleRemove
|
|
4181
|
+
}));
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
var EMPTY_ARRAY = [];
|
|
4185
|
+
function MultipleResourceReferenceEditor(props) {
|
|
4186
|
+
return React.createElement(EntityProvider, {
|
|
4187
|
+
sdk: props.sdk
|
|
4188
|
+
}, React.createElement(fieldEditorShared.FieldConnector, {
|
|
4189
|
+
throttle: 0,
|
|
4190
|
+
field: props.sdk.field,
|
|
4191
|
+
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4192
|
+
isEqualValues: deepEqual
|
|
4193
|
+
}, function (_ref3) {
|
|
4194
|
+
var value = _ref3.value,
|
|
4195
|
+
disabled = _ref3.disabled,
|
|
4196
|
+
setValue = _ref3.setValue,
|
|
4197
|
+
externalReset = _ref3.externalReset;
|
|
4198
|
+
return React.createElement(ResourceEditor, _extends({}, props, {
|
|
4199
|
+
items: value || EMPTY_ARRAY,
|
|
4200
|
+
isDisabled: disabled,
|
|
4201
|
+
setValue: setValue,
|
|
4202
|
+
key: externalReset + "-list"
|
|
4203
|
+
}), function (editorProps) {
|
|
4204
|
+
return React.createElement(SortableLinkList, _extends({}, editorProps), function (_ref4) {
|
|
4205
|
+
var item = _ref4.item,
|
|
4206
|
+
isDisabled = _ref4.isDisabled,
|
|
4207
|
+
DragHandle = _ref4.DragHandle,
|
|
4208
|
+
index = _ref4.index;
|
|
4209
|
+
return React.createElement(WithPerItemCallbacks, {
|
|
4210
|
+
index: index,
|
|
4211
|
+
onMove: editorProps.onMove,
|
|
4212
|
+
onRemoteItemAtIndex: editorProps.onRemoteItemAtIndex,
|
|
4213
|
+
listLength: (value == null ? void 0 : value.length) || 0
|
|
4214
|
+
}, function (_ref5) {
|
|
4215
|
+
var onMoveBottom = _ref5.onMoveBottom,
|
|
4216
|
+
onMoveTop = _ref5.onMoveTop,
|
|
4217
|
+
onRemove = _ref5.onRemove;
|
|
4218
|
+
return React.createElement(ResourceCard, {
|
|
4219
|
+
index: index,
|
|
4220
|
+
resourceLink: item,
|
|
4221
|
+
isDisabled: isDisabled,
|
|
4222
|
+
renderDragHandle: DragHandle,
|
|
4223
|
+
onMoveTop: onMoveTop,
|
|
4224
|
+
onMoveBottom: onMoveBottom,
|
|
4225
|
+
onRemove: onRemove,
|
|
4226
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
4227
|
+
});
|
|
4228
|
+
});
|
|
4229
|
+
});
|
|
4230
|
+
});
|
|
4231
|
+
}));
|
|
4232
|
+
}
|
|
4233
|
+
|
|
4234
|
+
function SingleResourceReferenceEditor(props) {
|
|
4235
|
+
var _props$sdk = props.sdk,
|
|
4236
|
+
dialogs = _props$sdk.dialogs,
|
|
4237
|
+
field = _props$sdk.field;
|
|
4238
|
+
var linkActionsProps = useResourceLinkActions({
|
|
4239
|
+
dialogs: dialogs,
|
|
4240
|
+
field: field,
|
|
4241
|
+
apiUrl: props.apiUrl
|
|
4242
|
+
});
|
|
4243
|
+
return React.createElement(EntityProvider, {
|
|
4244
|
+
sdk: props.sdk
|
|
4245
|
+
}, React.createElement(fieldEditorShared.FieldConnector, {
|
|
4246
|
+
throttle: 0,
|
|
4247
|
+
field: props.sdk.field,
|
|
4248
|
+
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4249
|
+
isEqualValues: deepEqual
|
|
4250
|
+
}, function (_ref) {
|
|
4251
|
+
var value = _ref.value,
|
|
4252
|
+
disabled = _ref.disabled;
|
|
4253
|
+
return value ? React.createElement(ResourceCard, {
|
|
4254
|
+
onRemove: function onRemove() {
|
|
4255
|
+
return props.sdk.field.removeValue();
|
|
4256
|
+
},
|
|
4257
|
+
resourceLink: value,
|
|
4258
|
+
isDisabled: disabled,
|
|
4259
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
4260
|
+
}) : // TODO: support custom actions once publicly available
|
|
4261
|
+
React.createElement(CombinedLinkActions, _extends({}, linkActionsProps));
|
|
4262
|
+
}));
|
|
4263
|
+
}
|
|
4264
|
+
|
|
3822
4265
|
exports.AssetThumbnail = AssetThumbnail;
|
|
3823
4266
|
exports.CombinedLinkActions = CombinedLinkActions;
|
|
3824
4267
|
exports.CreateEntryLinkButton = CreateEntryLinkButton;
|
|
@@ -3827,9 +4270,11 @@ exports.EntityProvider = EntityProvider;
|
|
|
3827
4270
|
exports.MissingEntityCard = MissingEntityCard;
|
|
3828
4271
|
exports.MultipleEntryReferenceEditor = MultipleEntryReferenceEditor;
|
|
3829
4272
|
exports.MultipleMediaEditor = MultipleMediaEditor;
|
|
4273
|
+
exports.MultipleResourceReferenceEditor = MultipleResourceReferenceEditor;
|
|
3830
4274
|
exports.ScheduledIconWithTooltip = ScheduledIconWithTooltip;
|
|
3831
4275
|
exports.SingleEntryReferenceEditor = SingleEntryReferenceEditor;
|
|
3832
4276
|
exports.SingleMediaEditor = SingleMediaEditor;
|
|
4277
|
+
exports.SingleResourceReferenceEditor = SingleResourceReferenceEditor;
|
|
3833
4278
|
exports.SortableLinkList = SortableLinkList;
|
|
3834
4279
|
exports.WrappedAssetCard = WrappedAssetCard;
|
|
3835
4280
|
exports.WrappedEntryCard = WrappedEntryCard;
|