@contentful/field-editor-reference 5.8.6 → 5.10.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.
- package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/assets/MultipleMediaEditor.js +86 -0
- package/dist/cjs/assets/SingleMediaEditor.js +69 -0
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +125 -0
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +171 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +159 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +130 -0
- package/dist/cjs/assets/index.js +24 -0
- package/dist/cjs/common/EntityStore.js +420 -0
- package/dist/cjs/common/MultipleReferenceEditor.js +164 -0
- package/dist/cjs/common/ReferenceEditor.js +74 -0
- package/dist/cjs/common/SingleReferenceEditor.js +118 -0
- package/dist/cjs/common/SortableLinkList.js +95 -0
- package/dist/cjs/common/customCardTypes.js +44 -0
- package/dist/cjs/common/useAccessApi.js +19 -0
- package/dist/cjs/common/useContentTypePermissions.js +54 -0
- package/dist/cjs/common/useEditorPermissions.js +77 -0
- package/dist/cjs/common/useEditorPermissions.spec.js +205 -0
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +62 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +102 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +254 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +199 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +190 -0
- package/dist/cjs/components/CreateEntryLinkButton/useGlobalMouseUp.js +19 -0
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +167 -0
- package/dist/cjs/components/LinkActions/LinkActions.js +123 -0
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +186 -0
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +54 -0
- package/dist/cjs/components/LinkActions/helpers.js +78 -0
- package/dist/cjs/components/LinkActions/redesignStyles.js +44 -0
- package/dist/cjs/components/LinkActions/styles.js +33 -0
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +75 -0
- package/dist/cjs/components/MissingEntityCard/styles.js +29 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +75 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +81 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +45 -0
- package/dist/cjs/components/SpaceName/SpaceName.js +91 -0
- package/dist/cjs/components/index.js +44 -0
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +86 -0
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +74 -0
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +189 -0
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +181 -0
- package/dist/cjs/entries/index.js +24 -0
- package/dist/cjs/index.js +92 -0
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +87 -0
- package/dist/cjs/resources/Cards/ResourceCard.js +111 -0
- package/dist/cjs/resources/Cards/UnsupportedEntityCard.js +64 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +157 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +297 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +87 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +161 -0
- package/dist/cjs/resources/index.js +19 -0
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +121 -0
- package/dist/cjs/resources/useResourceLinkActions.js +88 -0
- package/dist/cjs/types.js +22 -0
- package/dist/cjs/utils/fromFieldValidations.js +54 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/assets/MultipleMediaEditor.js +37 -0
- package/dist/esm/assets/SingleMediaEditor.js +20 -0
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +63 -0
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +122 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +105 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +76 -0
- package/dist/esm/assets/index.js +3 -0
- package/dist/esm/common/EntityStore.js +347 -0
- package/dist/esm/common/MultipleReferenceEditor.js +111 -0
- package/dist/esm/common/ReferenceEditor.js +20 -0
- package/dist/esm/common/SingleReferenceEditor.js +70 -0
- package/dist/esm/common/SortableLinkList.js +41 -0
- package/dist/esm/common/customCardTypes.js +1 -0
- package/dist/esm/common/useAccessApi.js +9 -0
- package/dist/esm/common/useContentTypePermissions.js +44 -0
- package/dist/esm/common/useEditorPermissions.js +67 -0
- package/dist/esm/common/useEditorPermissions.spec.js +201 -0
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +13 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +48 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +206 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +145 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +142 -0
- package/dist/esm/components/CreateEntryLinkButton/useGlobalMouseUp.js +9 -0
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +118 -0
- package/dist/esm/components/LinkActions/LinkActions.js +66 -0
- package/dist/esm/components/LinkActions/LinkEntityActions.js +127 -0
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +5 -0
- package/dist/esm/components/LinkActions/helpers.js +57 -0
- package/dist/esm/components/LinkActions/redesignStyles.js +18 -0
- package/dist/esm/components/LinkActions/styles.js +10 -0
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +26 -0
- package/dist/esm/components/MissingEntityCard/styles.js +11 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +18 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +32 -0
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +19 -0
- package/dist/esm/components/SpaceName/SpaceName.js +37 -0
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +37 -0
- package/dist/esm/entries/SingleEntryReferenceEditor.js +25 -0
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +135 -0
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +127 -0
- package/dist/esm/entries/index.js +3 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +38 -0
- package/dist/esm/resources/Cards/ResourceCard.js +62 -0
- package/dist/esm/resources/Cards/UnsupportedEntityCard.js +15 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +104 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +254 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.js +33 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +118 -0
- package/dist/esm/resources/index.js +2 -0
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +103 -0
- package/dist/esm/resources/useResourceLinkActions.js +78 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/fromFieldValidations.js +39 -0
- package/dist/{__fixtures__ → types/__fixtures__}/FakeSdk.d.ts +8 -8
- package/dist/{__fixtures__ → types/__fixtures__}/asset/index.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/content-type/index.d.ts +2 -2
- package/dist/{__fixtures__ → types/__fixtures__}/entry/index.d.ts +5 -5
- package/dist/{__fixtures__ → types/__fixtures__}/fixtures.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/locale/index.d.ts +42 -42
- package/dist/{__fixtures__ → types/__fixtures__}/space/index.d.ts +2 -2
- package/dist/{assets → types/assets}/MultipleMediaEditor.d.ts +10 -10
- package/dist/types/assets/SingleMediaEditor.d.ts +10 -0
- package/dist/{assets → types/assets}/WrappedAssetCard/AssetCardActions.d.ts +11 -11
- package/dist/{assets → types/assets}/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +17 -17
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetCard.d.ts +24 -24
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetLink.d.ts +16 -16
- package/dist/{assets → types/assets}/index.d.ts +3 -3
- package/dist/{common → types/common}/EntityStore.d.ts +62 -62
- package/dist/{common → types/common}/MultipleReferenceEditor.d.ts +25 -25
- package/dist/{common → types/common}/ReferenceEditor.d.ts +46 -46
- package/dist/{common → types/common}/SingleReferenceEditor.d.ts +24 -24
- package/dist/{common → types/common}/SortableLinkList.d.ts +19 -19
- package/dist/{common → types/common}/customCardTypes.d.ts +29 -29
- package/dist/types/common/useAccessApi.d.ts +16 -0
- package/dist/{common → types/common}/useContentTypePermissions.d.ts +17 -17
- package/dist/{common → types/common}/useEditorPermissions.d.ts +17 -17
- package/dist/types/common/useEditorPermissions.spec.d.ts +1 -0
- package/dist/{components → types/components}/AssetThumbnail/AssetThumbnail.d.ts +7 -7
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +19 -19
- package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +31 -31
- package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/useGlobalMouseUp.d.ts +1 -1
- package/dist/{components → types/components}/LinkActions/CombinedLinkActions.d.ts +10 -10
- package/dist/{components → types/components}/LinkActions/LinkActions.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/LinkEntityActions.d.ts +24 -24
- package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -0
- package/dist/{components → types/components}/LinkActions/helpers.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/redesignStyles.d.ts +3 -3
- package/dist/{components → types/components}/LinkActions/styles.d.ts +2 -2
- package/dist/{components → types/components}/MissingEntityCard/MissingEntityCard.d.ts +8 -8
- package/dist/{components → types/components}/MissingEntityCard/styles.d.ts +2 -2
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +11 -11
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +10 -10
- package/dist/{components → types/components}/ScheduledIconWithTooltip/formatDateAndTime.d.ts +15 -15
- package/dist/types/components/SpaceName/SpaceName.d.ts +6 -0
- package/dist/{components → types/components}/index.d.ts +9 -9
- package/dist/{entries → types/entries}/MultipleEntryReferenceEditor.d.ts +3 -3
- package/dist/{entries → types/entries}/SingleEntryReferenceEditor.d.ts +8 -8
- package/dist/{entries → types/entries}/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +18 -18
- package/dist/{entries → types/entries}/WrappedEntryCard/WrappedEntryCard.d.ts +35 -35
- package/dist/{entries → types/entries}/index.d.ts +3 -3
- package/dist/{index.d.ts → types/index.d.ts} +9 -8
- package/dist/{resources → types/resources}/Cards/ContentfulEntryCard.d.ts +21 -21
- package/dist/{resources → types/resources}/Cards/ResourceCard.d.ts +12 -12
- package/dist/{resources → types/resources}/Cards/UnsupportedEntityCard.d.ts +4 -4
- package/dist/{resources → types/resources}/MultipleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/MultipleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/SingleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/SingleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/index.d.ts +2 -2
- package/dist/{resources → types/resources}/testHelpers/resourceEditorHelpers.d.ts +50 -50
- package/dist/{resources → types/resources}/useResourceLinkActions.d.ts +7 -7
- package/dist/{types.d.ts → types/types.d.ts} +104 -104
- package/dist/{utils → types/utils}/fromFieldValidations.d.ts +21 -21
- package/package.json +25 -11
- package/CHANGELOG.md +0 -854
- package/dist/assets/SingleMediaEditor.d.ts +0 -10
- package/dist/common/useAccessApi.d.ts +0 -16
- package/dist/components/LinkActions/NoLinkPermissionsInfo.d.ts +0 -2
- package/dist/components/SpaceName/SpaceName.d.ts +0 -6
- package/dist/field-editor-reference.cjs.development.js +0 -4395
- package/dist/field-editor-reference.cjs.development.js.map +0 -1
- package/dist/field-editor-reference.cjs.production.min.js +0 -2
- package/dist/field-editor-reference.cjs.production.min.js.map +0 -1
- package/dist/field-editor-reference.esm.js +0 -4369
- package/dist/field-editor-reference.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -1,4369 +0,0 @@
|
|
|
1
|
-
import React__default, { useState, useRef, useEffect, createElement, Fragment, useMemo, useCallback } from 'react';
|
|
2
|
-
import { css, cx } from 'emotion';
|
|
3
|
-
import tokens from '@contentful/f36-tokens';
|
|
4
|
-
import { Menu, TextInput, Button, Paragraph, Card, Flex, SectionHeading, IconButton, Tooltip, Text, EntryCard, MenuItem, MenuDivider, AssetCard } from '@contentful/f36-components';
|
|
5
|
-
import { SearchIcon, PlusIcon, ChevronDownIcon, LinkIcon, CloseIcon, FolderOpenTrimmedIcon, ClockIcon } from '@contentful/f36-icons';
|
|
6
|
-
import get from 'lodash-es/get';
|
|
7
|
-
import moment from 'moment';
|
|
8
|
-
import { FieldConnector, isValidImage, entityHelpers, shortenStorageUnit } from '@contentful/field-editor-shared';
|
|
9
|
-
import deepEqual from 'deep-equal';
|
|
10
|
-
import { useQuery, QueryCache, QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query';
|
|
11
|
-
import constate from 'constate';
|
|
12
|
-
import { createClient } from 'contentful-management';
|
|
13
|
-
import PQueue from 'p-queue';
|
|
14
|
-
import isNumber from 'lodash-es/isNumber';
|
|
15
|
-
import arrayMove from 'array-move';
|
|
16
|
-
import { SortableContainer, SortableHandle, SortableElement } from 'react-sortable-hoc';
|
|
17
|
-
import mimetype from '@contentful/mimetype';
|
|
18
|
-
import { useInView } from 'react-intersection-observer';
|
|
19
|
-
|
|
20
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
21
|
-
try {
|
|
22
|
-
var info = gen[key](arg);
|
|
23
|
-
var value = info.value;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
reject(error);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (info.done) {
|
|
30
|
-
resolve(value);
|
|
31
|
-
} else {
|
|
32
|
-
Promise.resolve(value).then(_next, _throw);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function _asyncToGenerator(fn) {
|
|
37
|
-
return function () {
|
|
38
|
-
var self = this,
|
|
39
|
-
args = arguments;
|
|
40
|
-
return new Promise(function (resolve, reject) {
|
|
41
|
-
var gen = fn.apply(self, args);
|
|
42
|
-
|
|
43
|
-
function _next(value) {
|
|
44
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function _throw(err) {
|
|
48
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_next(undefined);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function _extends() {
|
|
57
|
-
_extends = Object.assign || function (target) {
|
|
58
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
59
|
-
var source = arguments[i];
|
|
60
|
-
|
|
61
|
-
for (var key in source) {
|
|
62
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
63
|
-
target[key] = source[key];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return target;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return _extends.apply(this, arguments);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function _inheritsLoose(subClass, superClass) {
|
|
75
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
76
|
-
subClass.prototype.constructor = subClass;
|
|
77
|
-
|
|
78
|
-
_setPrototypeOf(subClass, superClass);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function _getPrototypeOf(o) {
|
|
82
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
83
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
84
|
-
};
|
|
85
|
-
return _getPrototypeOf(o);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function _setPrototypeOf(o, p) {
|
|
89
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
90
|
-
o.__proto__ = p;
|
|
91
|
-
return o;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return _setPrototypeOf(o, p);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function _isNativeReflectConstruct() {
|
|
98
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
99
|
-
if (Reflect.construct.sham) return false;
|
|
100
|
-
if (typeof Proxy === "function") return true;
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
104
|
-
return true;
|
|
105
|
-
} catch (e) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function _construct(Parent, args, Class) {
|
|
111
|
-
if (_isNativeReflectConstruct()) {
|
|
112
|
-
_construct = Reflect.construct;
|
|
113
|
-
} else {
|
|
114
|
-
_construct = function _construct(Parent, args, Class) {
|
|
115
|
-
var a = [null];
|
|
116
|
-
a.push.apply(a, args);
|
|
117
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
118
|
-
var instance = new Constructor();
|
|
119
|
-
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
120
|
-
return instance;
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return _construct.apply(null, arguments);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function _isNativeFunction(fn) {
|
|
128
|
-
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function _wrapNativeSuper(Class) {
|
|
132
|
-
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
133
|
-
|
|
134
|
-
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
135
|
-
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
136
|
-
|
|
137
|
-
if (typeof Class !== "function") {
|
|
138
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (typeof _cache !== "undefined") {
|
|
142
|
-
if (_cache.has(Class)) return _cache.get(Class);
|
|
143
|
-
|
|
144
|
-
_cache.set(Class, Wrapper);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function Wrapper() {
|
|
148
|
-
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
Wrapper.prototype = Object.create(Class.prototype, {
|
|
152
|
-
constructor: {
|
|
153
|
-
value: Wrapper,
|
|
154
|
-
enumerable: false,
|
|
155
|
-
writable: true,
|
|
156
|
-
configurable: true
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return _setPrototypeOf(Wrapper, Class);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
return _wrapNativeSuper(Class);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
166
|
-
if (source == null) return {};
|
|
167
|
-
var target = {};
|
|
168
|
-
var sourceKeys = Object.keys(source);
|
|
169
|
-
var key, i;
|
|
170
|
-
|
|
171
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
172
|
-
key = sourceKeys[i];
|
|
173
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
174
|
-
target[key] = source[key];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return target;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
var container = /*#__PURE__*/css({
|
|
181
|
-
display: 'flex',
|
|
182
|
-
border: "1px dashed " + tokens.gray500,
|
|
183
|
-
borderRadius: tokens.borderRadiusMedium,
|
|
184
|
-
justifyContent: 'center',
|
|
185
|
-
padding: tokens.spacingXl
|
|
186
|
-
});
|
|
187
|
-
var action = /*#__PURE__*/css({
|
|
188
|
-
textDecoration: 'none',
|
|
189
|
-
fontWeight: 'bold'
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
193
|
-
var MAX_ITEMS_WITHOUT_SEARCH = 5;
|
|
194
|
-
var menuPlacementMap = {
|
|
195
|
-
'bottom-left': 'bottom-start',
|
|
196
|
-
'bottom-right': 'bottom-end'
|
|
197
|
-
};
|
|
198
|
-
var styles = {
|
|
199
|
-
wrapper: /*#__PURE__*/css({
|
|
200
|
-
position: 'relative'
|
|
201
|
-
}),
|
|
202
|
-
inputWrapper: /*#__PURE__*/css({
|
|
203
|
-
position: 'relative',
|
|
204
|
-
padding: "0 " + tokens.spacing2Xs
|
|
205
|
-
}),
|
|
206
|
-
searchInput: /*#__PURE__*/css({
|
|
207
|
-
paddingRight: tokens.spacingXl,
|
|
208
|
-
textOverflow: 'ellipsis'
|
|
209
|
-
}),
|
|
210
|
-
searchIcon: /*#__PURE__*/css({
|
|
211
|
-
position: 'absolute',
|
|
212
|
-
right: tokens.spacingM,
|
|
213
|
-
top: tokens.spacingS,
|
|
214
|
-
zIndex: /*#__PURE__*/Number(tokens.zIndexDefault),
|
|
215
|
-
fill: tokens.gray600
|
|
216
|
-
}),
|
|
217
|
-
separator: /*#__PURE__*/css({
|
|
218
|
-
background: tokens.gray200,
|
|
219
|
-
margin: '10px 0'
|
|
220
|
-
}),
|
|
221
|
-
dropdownList: /*#__PURE__*/css({
|
|
222
|
-
borderColor: tokens.gray200
|
|
223
|
-
})
|
|
224
|
-
};
|
|
225
|
-
var CreateEntryMenuTrigger = function CreateEntryMenuTrigger(_ref) {
|
|
226
|
-
var contentTypes = _ref.contentTypes,
|
|
227
|
-
suggestedContentTypeId = _ref.suggestedContentTypeId,
|
|
228
|
-
contentTypesLabel = _ref.contentTypesLabel,
|
|
229
|
-
onSelect = _ref.onSelect,
|
|
230
|
-
testId = _ref.testId,
|
|
231
|
-
_ref$dropdownSettings = _ref.dropdownSettings,
|
|
232
|
-
dropdownSettings = _ref$dropdownSettings === void 0 ? {
|
|
233
|
-
position: 'bottom-left'
|
|
234
|
-
} : _ref$dropdownSettings,
|
|
235
|
-
customDropdownItems = _ref.customDropdownItems,
|
|
236
|
-
children = _ref.children;
|
|
237
|
-
|
|
238
|
-
var _useState = useState(false),
|
|
239
|
-
isOpen = _useState[0],
|
|
240
|
-
setOpen = _useState[1];
|
|
241
|
-
|
|
242
|
-
var _useState2 = useState(false),
|
|
243
|
-
isSelecting = _useState2[0],
|
|
244
|
-
setSelecting = _useState2[1];
|
|
245
|
-
|
|
246
|
-
var _useState3 = useState(''),
|
|
247
|
-
searchInput = _useState3[0],
|
|
248
|
-
setSearchInput = _useState3[1];
|
|
249
|
-
|
|
250
|
-
var wrapper = useRef(null);
|
|
251
|
-
var textField = useRef(null);
|
|
252
|
-
var menuListRef = useRef(null);
|
|
253
|
-
/*
|
|
254
|
-
By default, dropdown wraps it's content, so it's width = the width of the widest item
|
|
255
|
-
During search, menu items change, and so the widest menu item can change
|
|
256
|
-
This leads to menu always changing it's width
|
|
257
|
-
To prevent this, we get the width of the menu item after the first mount of a dropdown (when all the content is displayed)
|
|
258
|
-
And hardcode it through the class name. This way we ensure that even during search the menu will keep that max width
|
|
259
|
-
That it had on initial mount and that fits any menu item in has
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
|
-
var _useState4 = useState(),
|
|
263
|
-
dropdownWidth = _useState4[0],
|
|
264
|
-
setDropdownWidth = _useState4[1];
|
|
265
|
-
|
|
266
|
-
var hasDropdown = contentTypes.length > 1 || !!customDropdownItems;
|
|
267
|
-
|
|
268
|
-
var closeMenu = function closeMenu() {
|
|
269
|
-
return setOpen(false);
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
useEffect(function () {
|
|
273
|
-
if (isOpen) {
|
|
274
|
-
setTimeout(function () {
|
|
275
|
-
var _textField$current, _textField$current$qu;
|
|
276
|
-
|
|
277
|
-
(_textField$current = textField.current) == null ? void 0 : (_textField$current$qu = _textField$current.querySelector('input')) == null ? void 0 : _textField$current$qu.focus({
|
|
278
|
-
preventScroll: true
|
|
279
|
-
});
|
|
280
|
-
}, 200);
|
|
281
|
-
}
|
|
282
|
-
}, [isOpen]);
|
|
283
|
-
useEffect(function () {
|
|
284
|
-
if (isOpen && !dropdownWidth) {
|
|
285
|
-
var _menuListRef$current;
|
|
286
|
-
|
|
287
|
-
setDropdownWidth((_menuListRef$current = menuListRef.current) == null ? void 0 : _menuListRef$current.clientWidth);
|
|
288
|
-
}
|
|
289
|
-
}, [isOpen, dropdownWidth]);
|
|
290
|
-
|
|
291
|
-
var handleSelect = function handleSelect(item) {
|
|
292
|
-
closeMenu();
|
|
293
|
-
var res = onSelect(item.sys.id); // TODO: Convert to controllable component.
|
|
294
|
-
|
|
295
|
-
if (res && typeof res.then === 'function') {
|
|
296
|
-
setSelecting(true);
|
|
297
|
-
res.then(function () {
|
|
298
|
-
return setSelecting(false);
|
|
299
|
-
}, function () {
|
|
300
|
-
return setSelecting(false);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
var handleMenuOpen = function handleMenuOpen() {
|
|
306
|
-
if (hasDropdown) {
|
|
307
|
-
setOpen(true);
|
|
308
|
-
} else {
|
|
309
|
-
handleSelect(contentTypes[0]);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
useEffect(function () {
|
|
314
|
-
if (!isOpen) {
|
|
315
|
-
setSearchInput('');
|
|
316
|
-
}
|
|
317
|
-
}, [isOpen]);
|
|
318
|
-
|
|
319
|
-
var renderSearchResultsCount = function renderSearchResultsCount(resultsLength) {
|
|
320
|
-
return resultsLength ? React__default.createElement(Menu.SectionTitle, {
|
|
321
|
-
testId: "add-entru-menu-search-results"
|
|
322
|
-
}, resultsLength, " result", resultsLength > 1 ? 's' : '') : null;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
var isSearchable = contentTypes.length > MAX_ITEMS_WITHOUT_SEARCH;
|
|
326
|
-
var maxDropdownHeight = suggestedContentTypeId ? 300 : 250;
|
|
327
|
-
var suggestedContentType = contentTypes.find(function (ct) {
|
|
328
|
-
return ct.sys.id === suggestedContentTypeId;
|
|
329
|
-
});
|
|
330
|
-
var filteredContentTypes = contentTypes.filter(function (ct) {
|
|
331
|
-
return !searchInput || get(ct, 'name', 'Untitled').toLowerCase().includes(searchInput.toLowerCase());
|
|
332
|
-
});
|
|
333
|
-
return React__default.createElement("span", {
|
|
334
|
-
className: styles.wrapper,
|
|
335
|
-
ref: wrapper,
|
|
336
|
-
"data-test-id": testId
|
|
337
|
-
}, React__default.createElement(Menu, {
|
|
338
|
-
placement: menuPlacementMap[dropdownSettings.position],
|
|
339
|
-
isAutoalignmentEnabled: dropdownSettings.isAutoalignmentEnabled,
|
|
340
|
-
isOpen: isOpen,
|
|
341
|
-
onClose: closeMenu,
|
|
342
|
-
onOpen: handleMenuOpen
|
|
343
|
-
}, React__default.createElement(Menu.Trigger, null, children({
|
|
344
|
-
isOpen: isOpen,
|
|
345
|
-
isSelecting: isSelecting
|
|
346
|
-
})), isOpen && React__default.createElement(Menu.List, {
|
|
347
|
-
className: styles.dropdownList,
|
|
348
|
-
style: {
|
|
349
|
-
width: dropdownWidth != undefined ? dropdownWidth + "px" : undefined,
|
|
350
|
-
maxHeight: maxDropdownHeight + "px"
|
|
351
|
-
},
|
|
352
|
-
ref: menuListRef,
|
|
353
|
-
testId: "add-entry-menu"
|
|
354
|
-
}, Boolean(customDropdownItems) && React__default.createElement(React__default.Fragment, null, customDropdownItems, React__default.createElement(Menu.Divider, null)), isSearchable && React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
|
|
355
|
-
ref: textField,
|
|
356
|
-
className: styles.inputWrapper
|
|
357
|
-
}, React__default.createElement(TextInput, {
|
|
358
|
-
className: styles.searchInput,
|
|
359
|
-
placeholder: "Search all content types",
|
|
360
|
-
testId: "add-entry-menu-search",
|
|
361
|
-
value: searchInput,
|
|
362
|
-
onChange: function onChange(e) {
|
|
363
|
-
return setSearchInput(e.target.value);
|
|
364
|
-
}
|
|
365
|
-
}), React__default.createElement(SearchIcon, {
|
|
366
|
-
className: styles.searchIcon
|
|
367
|
-
})), React__default.createElement(Menu.Divider, null)), searchInput && renderSearchResultsCount(filteredContentTypes.length), suggestedContentType && !searchInput && React__default.createElement(React__default.Fragment, null, React__default.createElement(Menu.SectionTitle, null, "Suggested Content Type"), React__default.createElement(Menu.Item, {
|
|
368
|
-
testId: "suggested",
|
|
369
|
-
onClick: function onClick() {
|
|
370
|
-
return handleSelect(suggestedContentType);
|
|
371
|
-
}
|
|
372
|
-
}, get(suggestedContentType, 'name')), React__default.createElement(Menu.Divider, null)), !searchInput && React__default.createElement(Menu.SectionTitle, null, contentTypesLabel), filteredContentTypes.length ? filteredContentTypes.map(function (contentType, i) {
|
|
373
|
-
return React__default.createElement(Menu.Item, {
|
|
374
|
-
testId: "contentType",
|
|
375
|
-
key: get(contentType, 'name') + "-" + i,
|
|
376
|
-
onClick: function onClick() {
|
|
377
|
-
return handleSelect(contentType);
|
|
378
|
-
}
|
|
379
|
-
}, get(contentType, 'name', 'Untitled'));
|
|
380
|
-
}) : React__default.createElement(Menu.Item, {
|
|
381
|
-
testId: "add-entru-menu-search-results"
|
|
382
|
-
}, "No results found"))));
|
|
383
|
-
};
|
|
384
|
-
CreateEntryMenuTrigger.defaultProps = {
|
|
385
|
-
testId: 'create-entry-button-menu-trigger',
|
|
386
|
-
contentTypesLabel: 'All Content Types'
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
var standardStyles = {
|
|
390
|
-
spinnerMargin: /*#__PURE__*/css({
|
|
391
|
-
marginRight: tokens.spacingXs
|
|
392
|
-
}),
|
|
393
|
-
action: undefined
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
var redesignStyles = /*#__PURE__*/_extends({}, standardStyles, {
|
|
397
|
-
action: /*#__PURE__*/css({
|
|
398
|
-
textDecoration: 'none',
|
|
399
|
-
fontWeight: 'bold',
|
|
400
|
-
maxWidth: '300px'
|
|
401
|
-
})
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
var CreateEntryLinkButton = function CreateEntryLinkButton(_ref) {
|
|
405
|
-
var contentTypes = _ref.contentTypes,
|
|
406
|
-
onSelect = _ref.onSelect,
|
|
407
|
-
customDropdownItems = _ref.customDropdownItems,
|
|
408
|
-
text = _ref.text,
|
|
409
|
-
testId = _ref.testId,
|
|
410
|
-
_ref$hasPlusIcon = _ref.hasPlusIcon,
|
|
411
|
-
hasPlusIcon = _ref$hasPlusIcon === void 0 ? false : _ref$hasPlusIcon,
|
|
412
|
-
useExperimentalStyles = _ref.useExperimentalStyles,
|
|
413
|
-
suggestedContentTypeId = _ref.suggestedContentTypeId,
|
|
414
|
-
dropdownSettings = _ref.dropdownSettings,
|
|
415
|
-
_ref$disabled = _ref.disabled,
|
|
416
|
-
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
417
|
-
contentTypes = contentTypes.sort(function (a, b) {
|
|
418
|
-
return a.name.localeCompare(b.name);
|
|
419
|
-
});
|
|
420
|
-
var suggestedContentType = contentTypes.find(function (ct) {
|
|
421
|
-
return ct.sys.id === suggestedContentTypeId;
|
|
422
|
-
});
|
|
423
|
-
var buttonText = text || "Add " + get(suggestedContentType || (contentTypes.length === 1 ? contentTypes[0] : {}), 'name', 'entry');
|
|
424
|
-
var hasDropdown = contentTypes.length > 1 || customDropdownItems; // TODO: Introduce `icon: string` and remove `hasPlusIcon` or remove "Plus" if we keep new layout.
|
|
425
|
-
|
|
426
|
-
var plusIcon = hasPlusIcon ? React__default.createElement(PlusIcon, null) : undefined; // TODO: Always use "New content" here if we fully switch to new layout.
|
|
427
|
-
|
|
428
|
-
var contentTypesLabel = useExperimentalStyles ? 'New content' : undefined;
|
|
429
|
-
var styles = useExperimentalStyles ? redesignStyles : standardStyles;
|
|
430
|
-
return React__default.createElement(CreateEntryMenuTrigger, {
|
|
431
|
-
contentTypes: contentTypes,
|
|
432
|
-
suggestedContentTypeId: suggestedContentTypeId,
|
|
433
|
-
contentTypesLabel: contentTypesLabel,
|
|
434
|
-
onSelect: onSelect,
|
|
435
|
-
testId: testId,
|
|
436
|
-
dropdownSettings: dropdownSettings,
|
|
437
|
-
customDropdownItems: customDropdownItems
|
|
438
|
-
}, function (_ref2) {
|
|
439
|
-
var isSelecting = _ref2.isSelecting;
|
|
440
|
-
return React__default.createElement(Button, {
|
|
441
|
-
endIcon: hasDropdown ? React__default.createElement(ChevronDownIcon, null) : undefined,
|
|
442
|
-
variant: "secondary",
|
|
443
|
-
className: styles.action,
|
|
444
|
-
isDisabled: disabled || isSelecting,
|
|
445
|
-
startIcon: isSelecting ? undefined : plusIcon,
|
|
446
|
-
size: "small",
|
|
447
|
-
testId: "create-entry-link-button",
|
|
448
|
-
isLoading: isSelecting
|
|
449
|
-
}, buttonText);
|
|
450
|
-
});
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
function NoLinkPermissionsInfo() {
|
|
454
|
-
return React__default.createElement(Paragraph, null, "You don't have permission to view this content or this field is not correctly configured. Contact your administrator for help.");
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
var container$1 = /*#__PURE__*/css({
|
|
458
|
-
display: 'flex',
|
|
459
|
-
width: '100%',
|
|
460
|
-
marginTop: tokens.spacingS
|
|
461
|
-
});
|
|
462
|
-
var separator = /*#__PURE__*/css({
|
|
463
|
-
marginRight: tokens.spacingXl
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
var defaultEntryLabels = {
|
|
467
|
-
createNew: function createNew(props) {
|
|
468
|
-
return props != null && props.contentType ? "Create new " + props.contentType + " and link" : 'Create new entry and link';
|
|
469
|
-
},
|
|
470
|
-
linkExisting: function linkExisting(props) {
|
|
471
|
-
return props != null && props.canLinkMultiple ? 'Link existing entries' : 'Link existing entry';
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
var defaultAssetLabels = {
|
|
475
|
-
createNew: function createNew() {
|
|
476
|
-
return "Create new asset and link";
|
|
477
|
-
},
|
|
478
|
-
linkExisting: function linkExisting(props) {
|
|
479
|
-
return props != null && props.canLinkMultiple ? 'Link existing assets' : 'Link existing asset';
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
var testIds = {
|
|
483
|
-
dropdown: 'linkEditor.dropdown',
|
|
484
|
-
createAndLink: 'linkEditor.createAndLink',
|
|
485
|
-
createAndLinkWrapper: 'create-entry-button-menu-trigger',
|
|
486
|
-
linkExisting: 'linkEditor.linkExisting'
|
|
487
|
-
};
|
|
488
|
-
function LinkActions(props) {
|
|
489
|
-
if (props.isFull) {
|
|
490
|
-
return null; // Don't render link actions if we reached max allowed links.
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
var defaultLabels = props.entityType === 'Entry' ? defaultEntryLabels : defaultAssetLabels;
|
|
494
|
-
|
|
495
|
-
var labels = _extends({}, defaultLabels, props.actionLabels);
|
|
496
|
-
|
|
497
|
-
return createElement("div", {
|
|
498
|
-
className: container$1
|
|
499
|
-
}, props.canCreateEntity && createElement(Fragment, null, props.entityType === 'Entry' && createElement(CreateEntryLinkButton, {
|
|
500
|
-
testId: testIds.createAndLink,
|
|
501
|
-
disabled: props.isDisabled,
|
|
502
|
-
text: labels.createNew({
|
|
503
|
-
contentType: props.contentTypes.length === 1 ? props.contentTypes[0].name : undefined
|
|
504
|
-
}),
|
|
505
|
-
contentTypes: props.contentTypes,
|
|
506
|
-
hasPlusIcon: true,
|
|
507
|
-
onSelect: function onSelect(contentTypeId) {
|
|
508
|
-
return contentTypeId ? props.onCreate(contentTypeId, props.itemsLength) : Promise.resolve();
|
|
509
|
-
}
|
|
510
|
-
}), props.entityType === 'Asset' && createElement(Button, {
|
|
511
|
-
isDisabled: props.isDisabled,
|
|
512
|
-
testId: testIds.createAndLink,
|
|
513
|
-
onClick: function onClick() {
|
|
514
|
-
props.onCreate(undefined, props.itemsLength);
|
|
515
|
-
},
|
|
516
|
-
variant: "secondary",
|
|
517
|
-
startIcon: createElement(PlusIcon, null),
|
|
518
|
-
size: "small"
|
|
519
|
-
}, labels.createNew()), createElement("span", {
|
|
520
|
-
className: separator
|
|
521
|
-
})), props.canLinkEntity && createElement(Button, {
|
|
522
|
-
isDisabled: props.isDisabled,
|
|
523
|
-
testId: testIds.linkExisting,
|
|
524
|
-
onClick: function onClick() {
|
|
525
|
-
props.onLinkExisting();
|
|
526
|
-
},
|
|
527
|
-
variant: "secondary",
|
|
528
|
-
startIcon: createElement(LinkIcon, null),
|
|
529
|
-
size: "small"
|
|
530
|
-
}, labels.linkExisting({
|
|
531
|
-
canLinkMultiple: props.canLinkMultiple
|
|
532
|
-
})), !props.canCreateEntity && !props.canLinkEntity && createElement(NoLinkPermissionsInfo, null));
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
var testIds$1 = /*#__PURE__*/_extends({}, testIds, {
|
|
536
|
-
actionsWrapper: 'link-actions-menu-trigger'
|
|
537
|
-
});
|
|
538
|
-
/**
|
|
539
|
-
* Alternative, experimental alternative to <LinkActions /> that is planned to
|
|
540
|
-
* replace the current default LinkActions in reference and media editors.
|
|
541
|
-
*
|
|
542
|
-
* Places both actions to create and link new, as well as link existing, behind
|
|
543
|
-
* one action dropdown and introduces new copy for action labels.
|
|
544
|
-
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
function CombinedLinkActions(props) {
|
|
548
|
-
if (props.isFull) {
|
|
549
|
-
return null; // Don't render link actions if we reached max allowed links.
|
|
550
|
-
} // We don't want to render a spacious container in case there are are already
|
|
551
|
-
// assets linked (in case of entries, always show it) as the border wouldn't be
|
|
552
|
-
// nicely aligned with asset cards.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
var hideEmptyCard = props.entityType === 'Asset' && !props.isEmpty;
|
|
556
|
-
return createElement("div", {
|
|
557
|
-
className: hideEmptyCard ? '' : container
|
|
558
|
-
}, !props.canCreateEntity && !props.canLinkEntity && createElement(NoLinkPermissionsInfo, null), props.entityType === 'Entry' && createElement(CombinedEntryLinkActions, _extends({}, props)), props.entityType === 'Asset' && createElement(CombinedAssetLinkActions, _extends({}, props)));
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function CombinedEntryLinkActions(props) {
|
|
562
|
-
if (props.canCreateEntity) {
|
|
563
|
-
return createElement(CreateEntryLinkButton, {
|
|
564
|
-
testId: testIds$1.actionsWrapper,
|
|
565
|
-
disabled: props.isDisabled,
|
|
566
|
-
text: props.combinedActionsLabel || 'Add content',
|
|
567
|
-
contentTypes: props.contentTypes,
|
|
568
|
-
hasPlusIcon: true,
|
|
569
|
-
useExperimentalStyles: true,
|
|
570
|
-
dropdownSettings: {
|
|
571
|
-
position: 'bottom-left'
|
|
572
|
-
},
|
|
573
|
-
onSelect: function onSelect(contentTypeId) {
|
|
574
|
-
return contentTypeId ? props.onCreate(contentTypeId) : Promise.resolve();
|
|
575
|
-
},
|
|
576
|
-
customDropdownItems: props.canLinkEntity ? createElement(Menu.Item, {
|
|
577
|
-
testId: testIds$1.linkExisting,
|
|
578
|
-
onClick: function onClick() {
|
|
579
|
-
props.onLinkExisting();
|
|
580
|
-
}
|
|
581
|
-
}, "Add existing content") : undefined
|
|
582
|
-
});
|
|
583
|
-
} else if (props.canLinkEntity) {
|
|
584
|
-
return createElement(Button, {
|
|
585
|
-
isDisabled: props.isDisabled,
|
|
586
|
-
testId: testIds$1.linkExisting,
|
|
587
|
-
className: action,
|
|
588
|
-
onClick: function onClick() {
|
|
589
|
-
props.onLinkExisting();
|
|
590
|
-
},
|
|
591
|
-
variant: "secondary",
|
|
592
|
-
startIcon: createElement(LinkIcon, null),
|
|
593
|
-
size: "small"
|
|
594
|
-
}, "Add existing content");
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
return null;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
function CombinedAssetLinkActions(props) {
|
|
601
|
-
var _React$useState = useState(false),
|
|
602
|
-
isOpen = _React$useState[0],
|
|
603
|
-
setOpen = _React$useState[1];
|
|
604
|
-
|
|
605
|
-
if (!props.canLinkEntity || !props.canCreateEntity) {
|
|
606
|
-
if (props.canLinkEntity) {
|
|
607
|
-
return createElement(Button, {
|
|
608
|
-
isDisabled: props.isDisabled,
|
|
609
|
-
testId: testIds$1.linkExisting,
|
|
610
|
-
className: action,
|
|
611
|
-
onClick: function onClick() {
|
|
612
|
-
props.onLinkExisting();
|
|
613
|
-
},
|
|
614
|
-
variant: "secondary",
|
|
615
|
-
startIcon: createElement(PlusIcon, null),
|
|
616
|
-
size: "small"
|
|
617
|
-
}, "Add existing media");
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
if (props.canCreateEntity) {
|
|
621
|
-
return createElement(Button, {
|
|
622
|
-
isDisabled: props.isDisabled,
|
|
623
|
-
testId: testIds$1.createAndLink,
|
|
624
|
-
className: action,
|
|
625
|
-
onClick: function onClick() {
|
|
626
|
-
props.onCreate();
|
|
627
|
-
},
|
|
628
|
-
variant: "secondary",
|
|
629
|
-
startIcon: createElement(PlusIcon, null),
|
|
630
|
-
size: "small"
|
|
631
|
-
}, "Add media");
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
return null;
|
|
635
|
-
} // TODO: If we fully switch to this new layout, make a more generic `CreateEntityLinkButton`
|
|
636
|
-
// that works without content types to cover asset use-case.
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
return createElement(Menu, {
|
|
640
|
-
isOpen: isOpen,
|
|
641
|
-
onClose: function onClose() {
|
|
642
|
-
setOpen(false);
|
|
643
|
-
},
|
|
644
|
-
onOpen: function onOpen() {
|
|
645
|
-
setOpen(true);
|
|
646
|
-
}
|
|
647
|
-
}, createElement(Menu.Trigger, null, createElement(Button, {
|
|
648
|
-
endIcon: createElement(ChevronDownIcon, null),
|
|
649
|
-
isDisabled: props.isDisabled,
|
|
650
|
-
testId: testIds$1.actionsWrapper,
|
|
651
|
-
className: action,
|
|
652
|
-
variant: "secondary",
|
|
653
|
-
startIcon: createElement(PlusIcon, null),
|
|
654
|
-
size: "small"
|
|
655
|
-
}, "Add media")), isOpen && createElement(Menu.List, {
|
|
656
|
-
testId: testIds$1.dropdown
|
|
657
|
-
}, createElement(Menu.Item, {
|
|
658
|
-
testId: testIds$1.linkExisting,
|
|
659
|
-
onClick: function onClick() {
|
|
660
|
-
props.onLinkExisting();
|
|
661
|
-
}
|
|
662
|
-
}, "Add existing media"), createElement(Menu.Item, {
|
|
663
|
-
testId: testIds$1.createAndLink,
|
|
664
|
-
onClick: function onClick() {
|
|
665
|
-
props.onCreate();
|
|
666
|
-
}
|
|
667
|
-
}, "Add new media")));
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
var card = /*#__PURE__*/css({
|
|
671
|
-
position: 'relative'
|
|
672
|
-
});
|
|
673
|
-
var squareCard = /*#__PURE__*/css({
|
|
674
|
-
display: 'flex',
|
|
675
|
-
alignItems: 'center',
|
|
676
|
-
width: '135px',
|
|
677
|
-
height: '160px',
|
|
678
|
-
textAlign: 'center'
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
function MissingEntityCard(props) {
|
|
682
|
-
return React__default.createElement(Card, {
|
|
683
|
-
className: card,
|
|
684
|
-
testId: "cf-ui-missing-entry-card"
|
|
685
|
-
}, React__default.createElement(Flex, {
|
|
686
|
-
alignItems: "center",
|
|
687
|
-
justifyContent: "space-between"
|
|
688
|
-
}, React__default.createElement("div", {
|
|
689
|
-
className: props.asSquare ? squareCard : ''
|
|
690
|
-
}, React__default.createElement(SectionHeading, {
|
|
691
|
-
marginBottom: "none"
|
|
692
|
-
}, props.entityType, " is missing or inaccessible")), !props.isDisabled && props.onRemove && React__default.createElement(IconButton, {
|
|
693
|
-
variant: "transparent",
|
|
694
|
-
icon: React__default.createElement(CloseIcon, {
|
|
695
|
-
variant: "muted"
|
|
696
|
-
}),
|
|
697
|
-
"aria-label": "Delete",
|
|
698
|
-
onClick: function onClick() {
|
|
699
|
-
props.onRemove && props.onRemove();
|
|
700
|
-
}
|
|
701
|
-
})));
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function createCommonjsModule(fn, module) {
|
|
705
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
|
|
709
|
-
/**
|
|
710
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
711
|
-
*
|
|
712
|
-
* This source code is licensed under the MIT license found in the
|
|
713
|
-
* LICENSE file in the root directory of this source tree.
|
|
714
|
-
*/
|
|
715
|
-
var runtime = function (exports) {
|
|
716
|
-
|
|
717
|
-
var Op = Object.prototype;
|
|
718
|
-
var hasOwn = Op.hasOwnProperty;
|
|
719
|
-
var undefined$1; // More compressible than void 0.
|
|
720
|
-
|
|
721
|
-
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
722
|
-
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
723
|
-
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
724
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
725
|
-
|
|
726
|
-
function define(obj, key, value) {
|
|
727
|
-
Object.defineProperty(obj, key, {
|
|
728
|
-
value: value,
|
|
729
|
-
enumerable: true,
|
|
730
|
-
configurable: true,
|
|
731
|
-
writable: true
|
|
732
|
-
});
|
|
733
|
-
return obj[key];
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
try {
|
|
737
|
-
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
738
|
-
define({}, "");
|
|
739
|
-
} catch (err) {
|
|
740
|
-
define = function define(obj, key, value) {
|
|
741
|
-
return obj[key] = value;
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
746
|
-
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
747
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
748
|
-
var generator = Object.create(protoGenerator.prototype);
|
|
749
|
-
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
|
|
750
|
-
// .throw, and .return methods.
|
|
751
|
-
|
|
752
|
-
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
753
|
-
return generator;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
|
|
757
|
-
// record like context.tryEntries[i].completion. This interface could
|
|
758
|
-
// have been (and was previously) designed to take a closure to be
|
|
759
|
-
// invoked without arguments, but in all the cases we care about we
|
|
760
|
-
// already have an existing method we want to call, so there's no need
|
|
761
|
-
// to create a new function object. We can even get away with assuming
|
|
762
|
-
// the method takes exactly one argument, since that happens to be true
|
|
763
|
-
// in every case, so we don't have to touch the arguments object. The
|
|
764
|
-
// only additional allocation required is the completion record, which
|
|
765
|
-
// has a stable shape and so hopefully should be cheap to allocate.
|
|
766
|
-
|
|
767
|
-
function tryCatch(fn, obj, arg) {
|
|
768
|
-
try {
|
|
769
|
-
return {
|
|
770
|
-
type: "normal",
|
|
771
|
-
arg: fn.call(obj, arg)
|
|
772
|
-
};
|
|
773
|
-
} catch (err) {
|
|
774
|
-
return {
|
|
775
|
-
type: "throw",
|
|
776
|
-
arg: err
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
var GenStateSuspendedStart = "suspendedStart";
|
|
782
|
-
var GenStateSuspendedYield = "suspendedYield";
|
|
783
|
-
var GenStateExecuting = "executing";
|
|
784
|
-
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
|
|
785
|
-
// breaking out of the dispatch switch statement.
|
|
786
|
-
|
|
787
|
-
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
|
|
788
|
-
// .constructor.prototype properties for functions that return Generator
|
|
789
|
-
// objects. For full spec compliance, you may wish to configure your
|
|
790
|
-
// minifier not to mangle the names of these two functions.
|
|
791
|
-
|
|
792
|
-
function Generator() {}
|
|
793
|
-
|
|
794
|
-
function GeneratorFunction() {}
|
|
795
|
-
|
|
796
|
-
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
|
|
797
|
-
// don't natively support it.
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
var IteratorPrototype = {};
|
|
801
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
802
|
-
return this;
|
|
803
|
-
});
|
|
804
|
-
var getProto = Object.getPrototypeOf;
|
|
805
|
-
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
806
|
-
|
|
807
|
-
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
808
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
809
|
-
// of the polyfill.
|
|
810
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
814
|
-
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
815
|
-
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
816
|
-
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
817
|
-
GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
|
|
818
|
-
// Iterator interface in terms of a single ._invoke method.
|
|
819
|
-
|
|
820
|
-
function defineIteratorMethods(prototype) {
|
|
821
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
822
|
-
define(prototype, method, function (arg) {
|
|
823
|
-
return this._invoke(method, arg);
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
exports.isGeneratorFunction = function (genFun) {
|
|
829
|
-
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
830
|
-
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
|
|
831
|
-
// do is to check its .name property.
|
|
832
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction" : false;
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
exports.mark = function (genFun) {
|
|
836
|
-
if (Object.setPrototypeOf) {
|
|
837
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
838
|
-
} else {
|
|
839
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
840
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
genFun.prototype = Object.create(Gp);
|
|
844
|
-
return genFun;
|
|
845
|
-
}; // Within the body of any async function, `await x` is transformed to
|
|
846
|
-
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
847
|
-
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
848
|
-
// meant to be awaited.
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
exports.awrap = function (arg) {
|
|
852
|
-
return {
|
|
853
|
-
__await: arg
|
|
854
|
-
};
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
858
|
-
function invoke(method, arg, resolve, reject) {
|
|
859
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
860
|
-
|
|
861
|
-
if (record.type === "throw") {
|
|
862
|
-
reject(record.arg);
|
|
863
|
-
} else {
|
|
864
|
-
var result = record.arg;
|
|
865
|
-
var value = result.value;
|
|
866
|
-
|
|
867
|
-
if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
|
|
868
|
-
return PromiseImpl.resolve(value.__await).then(function (value) {
|
|
869
|
-
invoke("next", value, resolve, reject);
|
|
870
|
-
}, function (err) {
|
|
871
|
-
invoke("throw", err, resolve, reject);
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
return PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
876
|
-
// When a yielded Promise is resolved, its final value becomes
|
|
877
|
-
// the .value of the Promise<{value,done}> result for the
|
|
878
|
-
// current iteration.
|
|
879
|
-
result.value = unwrapped;
|
|
880
|
-
resolve(result);
|
|
881
|
-
}, function (error) {
|
|
882
|
-
// If a rejected Promise was yielded, throw the rejection back
|
|
883
|
-
// into the async generator function so it can be handled there.
|
|
884
|
-
return invoke("throw", error, resolve, reject);
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
var previousPromise;
|
|
890
|
-
|
|
891
|
-
function enqueue(method, arg) {
|
|
892
|
-
function callInvokeWithMethodAndArg() {
|
|
893
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
894
|
-
invoke(method, arg, resolve, reject);
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
return previousPromise = // If enqueue has been called before, then we want to wait until
|
|
899
|
-
// all previous Promises have been resolved before calling invoke,
|
|
900
|
-
// so that results are always delivered in the correct order. If
|
|
901
|
-
// enqueue has not been called before, then it is important to
|
|
902
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
903
|
-
// so that the async generator function has the opportunity to do
|
|
904
|
-
// any necessary setup in a predictable way. This predictability
|
|
905
|
-
// is why the Promise constructor synchronously invokes its
|
|
906
|
-
// executor callback, and why async functions synchronously
|
|
907
|
-
// execute code before the first await. Since we implement simple
|
|
908
|
-
// async functions in terms of async generators, it is especially
|
|
909
|
-
// important to get this right, even though it requires care.
|
|
910
|
-
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
|
|
911
|
-
// invocations of the iterator.
|
|
912
|
-
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
913
|
-
} // Define the unified helper method that is used to implement .next,
|
|
914
|
-
// .throw, and .return (see defineIteratorMethods).
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
this._invoke = enqueue;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
defineIteratorMethods(AsyncIterator.prototype);
|
|
921
|
-
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
922
|
-
return this;
|
|
923
|
-
});
|
|
924
|
-
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
|
|
925
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
926
|
-
// the final result produced by the iterator.
|
|
927
|
-
|
|
928
|
-
exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
929
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
930
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
931
|
-
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
|
|
932
|
-
: iter.next().then(function (result) {
|
|
933
|
-
return result.done ? result.value : iter.next();
|
|
934
|
-
});
|
|
935
|
-
};
|
|
936
|
-
|
|
937
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
938
|
-
var state = GenStateSuspendedStart;
|
|
939
|
-
return function invoke(method, arg) {
|
|
940
|
-
if (state === GenStateExecuting) {
|
|
941
|
-
throw new Error("Generator is already running");
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
if (state === GenStateCompleted) {
|
|
945
|
-
if (method === "throw") {
|
|
946
|
-
throw arg;
|
|
947
|
-
} // Be forgiving, per 25.3.3.3.3 of the spec:
|
|
948
|
-
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
return doneResult();
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
context.method = method;
|
|
955
|
-
context.arg = arg;
|
|
956
|
-
|
|
957
|
-
while (true) {
|
|
958
|
-
var delegate = context.delegate;
|
|
959
|
-
|
|
960
|
-
if (delegate) {
|
|
961
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
962
|
-
|
|
963
|
-
if (delegateResult) {
|
|
964
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
965
|
-
return delegateResult;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
if (context.method === "next") {
|
|
970
|
-
// Setting context._sent for legacy support of Babel's
|
|
971
|
-
// function.sent implementation.
|
|
972
|
-
context.sent = context._sent = context.arg;
|
|
973
|
-
} else if (context.method === "throw") {
|
|
974
|
-
if (state === GenStateSuspendedStart) {
|
|
975
|
-
state = GenStateCompleted;
|
|
976
|
-
throw context.arg;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
context.dispatchException(context.arg);
|
|
980
|
-
} else if (context.method === "return") {
|
|
981
|
-
context.abrupt("return", context.arg);
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
state = GenStateExecuting;
|
|
985
|
-
var record = tryCatch(innerFn, self, context);
|
|
986
|
-
|
|
987
|
-
if (record.type === "normal") {
|
|
988
|
-
// If an exception is thrown from innerFn, we leave state ===
|
|
989
|
-
// GenStateExecuting and loop back for another invocation.
|
|
990
|
-
state = context.done ? GenStateCompleted : GenStateSuspendedYield;
|
|
991
|
-
|
|
992
|
-
if (record.arg === ContinueSentinel) {
|
|
993
|
-
continue;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
return {
|
|
997
|
-
value: record.arg,
|
|
998
|
-
done: context.done
|
|
999
|
-
};
|
|
1000
|
-
} else if (record.type === "throw") {
|
|
1001
|
-
state = GenStateCompleted; // Dispatch the exception by looping back around to the
|
|
1002
|
-
// context.dispatchException(context.arg) call above.
|
|
1003
|
-
|
|
1004
|
-
context.method = "throw";
|
|
1005
|
-
context.arg = record.arg;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
} // Call delegate.iterator[context.method](context.arg) and handle the
|
|
1010
|
-
// result, either by returning a { value, done } result from the
|
|
1011
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
1012
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
1016
|
-
var method = delegate.iterator[context.method];
|
|
1017
|
-
|
|
1018
|
-
if (method === undefined$1) {
|
|
1019
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
1020
|
-
// method always terminates the yield* loop.
|
|
1021
|
-
context.delegate = null;
|
|
1022
|
-
|
|
1023
|
-
if (context.method === "throw") {
|
|
1024
|
-
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
1025
|
-
if (delegate.iterator["return"]) {
|
|
1026
|
-
// If the delegate iterator has a return method, give it a
|
|
1027
|
-
// chance to clean up.
|
|
1028
|
-
context.method = "return";
|
|
1029
|
-
context.arg = undefined$1;
|
|
1030
|
-
maybeInvokeDelegate(delegate, context);
|
|
1031
|
-
|
|
1032
|
-
if (context.method === "throw") {
|
|
1033
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
1034
|
-
// "return" to "throw", let that override the TypeError below.
|
|
1035
|
-
return ContinueSentinel;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
context.method = "throw";
|
|
1040
|
-
context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
return ContinueSentinel;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
1047
|
-
|
|
1048
|
-
if (record.type === "throw") {
|
|
1049
|
-
context.method = "throw";
|
|
1050
|
-
context.arg = record.arg;
|
|
1051
|
-
context.delegate = null;
|
|
1052
|
-
return ContinueSentinel;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
var info = record.arg;
|
|
1056
|
-
|
|
1057
|
-
if (!info) {
|
|
1058
|
-
context.method = "throw";
|
|
1059
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
1060
|
-
context.delegate = null;
|
|
1061
|
-
return ContinueSentinel;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
if (info.done) {
|
|
1065
|
-
// Assign the result of the finished delegate to the temporary
|
|
1066
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
1067
|
-
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
|
|
1068
|
-
|
|
1069
|
-
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
|
|
1070
|
-
// exception, let the outer generator proceed normally. If
|
|
1071
|
-
// context.method was "next", forget context.arg since it has been
|
|
1072
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
1073
|
-
// "return", allow the original .return call to continue in the
|
|
1074
|
-
// outer generator.
|
|
1075
|
-
|
|
1076
|
-
if (context.method !== "return") {
|
|
1077
|
-
context.method = "next";
|
|
1078
|
-
context.arg = undefined$1;
|
|
1079
|
-
}
|
|
1080
|
-
} else {
|
|
1081
|
-
// Re-yield the result returned by the delegate method.
|
|
1082
|
-
return info;
|
|
1083
|
-
} // The delegate iterator is finished, so forget it and continue with
|
|
1084
|
-
// the outer generator.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
context.delegate = null;
|
|
1088
|
-
return ContinueSentinel;
|
|
1089
|
-
} // Define Generator.prototype.{next,throw,return} in terms of the
|
|
1090
|
-
// unified ._invoke helper method.
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
defineIteratorMethods(Gp);
|
|
1094
|
-
define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
|
|
1095
|
-
// @@iterator function is called on it. Some browsers' implementations of the
|
|
1096
|
-
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
1097
|
-
// object to not be returned from this call. This ensures that doesn't happen.
|
|
1098
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
1099
|
-
|
|
1100
|
-
define(Gp, iteratorSymbol, function () {
|
|
1101
|
-
return this;
|
|
1102
|
-
});
|
|
1103
|
-
define(Gp, "toString", function () {
|
|
1104
|
-
return "[object Generator]";
|
|
1105
|
-
});
|
|
1106
|
-
|
|
1107
|
-
function pushTryEntry(locs) {
|
|
1108
|
-
var entry = {
|
|
1109
|
-
tryLoc: locs[0]
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
if (1 in locs) {
|
|
1113
|
-
entry.catchLoc = locs[1];
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
if (2 in locs) {
|
|
1117
|
-
entry.finallyLoc = locs[2];
|
|
1118
|
-
entry.afterLoc = locs[3];
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
this.tryEntries.push(entry);
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
function resetTryEntry(entry) {
|
|
1125
|
-
var record = entry.completion || {};
|
|
1126
|
-
record.type = "normal";
|
|
1127
|
-
delete record.arg;
|
|
1128
|
-
entry.completion = record;
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
function Context(tryLocsList) {
|
|
1132
|
-
// The root entry object (effectively a try statement without a catch
|
|
1133
|
-
// or a finally block) gives us a place to store values thrown from
|
|
1134
|
-
// locations where there is no enclosing try statement.
|
|
1135
|
-
this.tryEntries = [{
|
|
1136
|
-
tryLoc: "root"
|
|
1137
|
-
}];
|
|
1138
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
1139
|
-
this.reset(true);
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
exports.keys = function (object) {
|
|
1143
|
-
var keys = [];
|
|
1144
|
-
|
|
1145
|
-
for (var key in object) {
|
|
1146
|
-
keys.push(key);
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
keys.reverse(); // Rather than returning an object with a next method, we keep
|
|
1150
|
-
// things simple and return the next function itself.
|
|
1151
|
-
|
|
1152
|
-
return function next() {
|
|
1153
|
-
while (keys.length) {
|
|
1154
|
-
var key = keys.pop();
|
|
1155
|
-
|
|
1156
|
-
if (key in object) {
|
|
1157
|
-
next.value = key;
|
|
1158
|
-
next.done = false;
|
|
1159
|
-
return next;
|
|
1160
|
-
}
|
|
1161
|
-
} // To avoid creating an additional object, we just hang the .value
|
|
1162
|
-
// and .done properties off the next function object itself. This
|
|
1163
|
-
// also ensures that the minifier will not anonymize the function.
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
next.done = true;
|
|
1167
|
-
return next;
|
|
1168
|
-
};
|
|
1169
|
-
};
|
|
1170
|
-
|
|
1171
|
-
function values(iterable) {
|
|
1172
|
-
if (iterable) {
|
|
1173
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
1174
|
-
|
|
1175
|
-
if (iteratorMethod) {
|
|
1176
|
-
return iteratorMethod.call(iterable);
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
if (typeof iterable.next === "function") {
|
|
1180
|
-
return iterable;
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
if (!isNaN(iterable.length)) {
|
|
1184
|
-
var i = -1,
|
|
1185
|
-
next = function next() {
|
|
1186
|
-
while (++i < iterable.length) {
|
|
1187
|
-
if (hasOwn.call(iterable, i)) {
|
|
1188
|
-
next.value = iterable[i];
|
|
1189
|
-
next.done = false;
|
|
1190
|
-
return next;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
next.value = undefined$1;
|
|
1195
|
-
next.done = true;
|
|
1196
|
-
return next;
|
|
1197
|
-
};
|
|
1198
|
-
|
|
1199
|
-
return next.next = next;
|
|
1200
|
-
}
|
|
1201
|
-
} // Return an iterator with no values.
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
return {
|
|
1205
|
-
next: doneResult
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
exports.values = values;
|
|
1210
|
-
|
|
1211
|
-
function doneResult() {
|
|
1212
|
-
return {
|
|
1213
|
-
value: undefined$1,
|
|
1214
|
-
done: true
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
Context.prototype = {
|
|
1219
|
-
constructor: Context,
|
|
1220
|
-
reset: function reset(skipTempReset) {
|
|
1221
|
-
this.prev = 0;
|
|
1222
|
-
this.next = 0; // Resetting context._sent for legacy support of Babel's
|
|
1223
|
-
// function.sent implementation.
|
|
1224
|
-
|
|
1225
|
-
this.sent = this._sent = undefined$1;
|
|
1226
|
-
this.done = false;
|
|
1227
|
-
this.delegate = null;
|
|
1228
|
-
this.method = "next";
|
|
1229
|
-
this.arg = undefined$1;
|
|
1230
|
-
this.tryEntries.forEach(resetTryEntry);
|
|
1231
|
-
|
|
1232
|
-
if (!skipTempReset) {
|
|
1233
|
-
for (var name in this) {
|
|
1234
|
-
// Not sure about the optimal order of these conditions:
|
|
1235
|
-
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
|
|
1236
|
-
this[name] = undefined$1;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
},
|
|
1241
|
-
stop: function stop() {
|
|
1242
|
-
this.done = true;
|
|
1243
|
-
var rootEntry = this.tryEntries[0];
|
|
1244
|
-
var rootRecord = rootEntry.completion;
|
|
1245
|
-
|
|
1246
|
-
if (rootRecord.type === "throw") {
|
|
1247
|
-
throw rootRecord.arg;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
return this.rval;
|
|
1251
|
-
},
|
|
1252
|
-
dispatchException: function dispatchException(exception) {
|
|
1253
|
-
if (this.done) {
|
|
1254
|
-
throw exception;
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
var context = this;
|
|
1258
|
-
|
|
1259
|
-
function handle(loc, caught) {
|
|
1260
|
-
record.type = "throw";
|
|
1261
|
-
record.arg = exception;
|
|
1262
|
-
context.next = loc;
|
|
1263
|
-
|
|
1264
|
-
if (caught) {
|
|
1265
|
-
// If the dispatched exception was caught by a catch block,
|
|
1266
|
-
// then let that catch block handle the exception normally.
|
|
1267
|
-
context.method = "next";
|
|
1268
|
-
context.arg = undefined$1;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
return !!caught;
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1275
|
-
var entry = this.tryEntries[i];
|
|
1276
|
-
var record = entry.completion;
|
|
1277
|
-
|
|
1278
|
-
if (entry.tryLoc === "root") {
|
|
1279
|
-
// Exception thrown outside of any try block that could handle
|
|
1280
|
-
// it, so set the completion value of the entire function to
|
|
1281
|
-
// throw the exception.
|
|
1282
|
-
return handle("end");
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
if (entry.tryLoc <= this.prev) {
|
|
1286
|
-
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
1287
|
-
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
1288
|
-
|
|
1289
|
-
if (hasCatch && hasFinally) {
|
|
1290
|
-
if (this.prev < entry.catchLoc) {
|
|
1291
|
-
return handle(entry.catchLoc, true);
|
|
1292
|
-
} else if (this.prev < entry.finallyLoc) {
|
|
1293
|
-
return handle(entry.finallyLoc);
|
|
1294
|
-
}
|
|
1295
|
-
} else if (hasCatch) {
|
|
1296
|
-
if (this.prev < entry.catchLoc) {
|
|
1297
|
-
return handle(entry.catchLoc, true);
|
|
1298
|
-
}
|
|
1299
|
-
} else if (hasFinally) {
|
|
1300
|
-
if (this.prev < entry.finallyLoc) {
|
|
1301
|
-
return handle(entry.finallyLoc);
|
|
1302
|
-
}
|
|
1303
|
-
} else {
|
|
1304
|
-
throw new Error("try statement without catch or finally");
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
},
|
|
1309
|
-
abrupt: function abrupt(type, arg) {
|
|
1310
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1311
|
-
var entry = this.tryEntries[i];
|
|
1312
|
-
|
|
1313
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
1314
|
-
var finallyEntry = entry;
|
|
1315
|
-
break;
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
|
|
1320
|
-
// Ignore the finally entry if control is not jumping to a
|
|
1321
|
-
// location outside the try/catch block.
|
|
1322
|
-
finallyEntry = null;
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
1326
|
-
record.type = type;
|
|
1327
|
-
record.arg = arg;
|
|
1328
|
-
|
|
1329
|
-
if (finallyEntry) {
|
|
1330
|
-
this.method = "next";
|
|
1331
|
-
this.next = finallyEntry.finallyLoc;
|
|
1332
|
-
return ContinueSentinel;
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
return this.complete(record);
|
|
1336
|
-
},
|
|
1337
|
-
complete: function complete(record, afterLoc) {
|
|
1338
|
-
if (record.type === "throw") {
|
|
1339
|
-
throw record.arg;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
if (record.type === "break" || record.type === "continue") {
|
|
1343
|
-
this.next = record.arg;
|
|
1344
|
-
} else if (record.type === "return") {
|
|
1345
|
-
this.rval = this.arg = record.arg;
|
|
1346
|
-
this.method = "return";
|
|
1347
|
-
this.next = "end";
|
|
1348
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
1349
|
-
this.next = afterLoc;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
return ContinueSentinel;
|
|
1353
|
-
},
|
|
1354
|
-
finish: function finish(finallyLoc) {
|
|
1355
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1356
|
-
var entry = this.tryEntries[i];
|
|
1357
|
-
|
|
1358
|
-
if (entry.finallyLoc === finallyLoc) {
|
|
1359
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
1360
|
-
resetTryEntry(entry);
|
|
1361
|
-
return ContinueSentinel;
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
},
|
|
1365
|
-
"catch": function _catch(tryLoc) {
|
|
1366
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
1367
|
-
var entry = this.tryEntries[i];
|
|
1368
|
-
|
|
1369
|
-
if (entry.tryLoc === tryLoc) {
|
|
1370
|
-
var record = entry.completion;
|
|
1371
|
-
|
|
1372
|
-
if (record.type === "throw") {
|
|
1373
|
-
var thrown = record.arg;
|
|
1374
|
-
resetTryEntry(entry);
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
return thrown;
|
|
1378
|
-
}
|
|
1379
|
-
} // The context.catch method must only be called with a location
|
|
1380
|
-
// argument that corresponds to a known catch block.
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
throw new Error("illegal catch attempt");
|
|
1384
|
-
},
|
|
1385
|
-
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
1386
|
-
this.delegate = {
|
|
1387
|
-
iterator: values(iterable),
|
|
1388
|
-
resultName: resultName,
|
|
1389
|
-
nextLoc: nextLoc
|
|
1390
|
-
};
|
|
1391
|
-
|
|
1392
|
-
if (this.method === "next") {
|
|
1393
|
-
// Deliberately forget the last sent value so that we don't
|
|
1394
|
-
// accidentally pass it on to the delegate.
|
|
1395
|
-
this.arg = undefined$1;
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
return ContinueSentinel;
|
|
1399
|
-
}
|
|
1400
|
-
}; // Regardless of whether this script is executing as a CommonJS module
|
|
1401
|
-
// or not, return the runtime object so that we can declare the variable
|
|
1402
|
-
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
1403
|
-
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
1404
|
-
|
|
1405
|
-
return exports;
|
|
1406
|
-
}( // If this script is executing as a CommonJS module, use module.exports
|
|
1407
|
-
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
1408
|
-
// object. Either way, the resulting object will be used to initialize
|
|
1409
|
-
// the regeneratorRuntime variable at the top of this file.
|
|
1410
|
-
module.exports );
|
|
1411
|
-
|
|
1412
|
-
try {
|
|
1413
|
-
regeneratorRuntime = runtime;
|
|
1414
|
-
} catch (accidentalStrictMode) {
|
|
1415
|
-
// This module should not be running in strict mode, so the above
|
|
1416
|
-
// assignment should always work unless something is misconfigured. Just
|
|
1417
|
-
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
1418
|
-
// we can explicitly access globalThis. In older engines we can escape
|
|
1419
|
-
// strict mode using a global Function call. This could conceivably fail
|
|
1420
|
-
// if a Content Security Policy forbids using Function, but in that case
|
|
1421
|
-
// the proper solution is to fix the accidental strict mode problem. If
|
|
1422
|
-
// you've misconfigured your bundler to force strict mode and applied a
|
|
1423
|
-
// CSP to forbid Function, and you're not willing to fix either of those
|
|
1424
|
-
// problems, please detail your unique predicament in a GitHub issue.
|
|
1425
|
-
if (typeof globalThis === "object") {
|
|
1426
|
-
globalThis.regeneratorRuntime = runtime;
|
|
1427
|
-
} else {
|
|
1428
|
-
Function("r", "regeneratorRuntime = r")(runtime);
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
|
|
1433
|
-
var getContentTypeIds = function getContentTypeIds(contentTypes) {
|
|
1434
|
-
return contentTypes.map(function (ct) {
|
|
1435
|
-
return ct.sys.id;
|
|
1436
|
-
});
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
function createEntity(_x) {
|
|
1440
|
-
return _createEntity.apply(this, arguments);
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
function _createEntity() {
|
|
1444
|
-
_createEntity = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(props) {
|
|
1445
|
-
var _yield$props$sdk$navi, entity, slide, _yield$props$sdk$navi2, _entity, _slide;
|
|
1446
|
-
|
|
1447
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1448
|
-
while (1) {
|
|
1449
|
-
switch (_context.prev = _context.next) {
|
|
1450
|
-
case 0:
|
|
1451
|
-
if (!(props.entityType === 'Entry')) {
|
|
1452
|
-
_context.next = 11;
|
|
1453
|
-
break;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
if (props.contentTypeId) {
|
|
1457
|
-
_context.next = 3;
|
|
1458
|
-
break;
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
return _context.abrupt("return", {});
|
|
1462
|
-
|
|
1463
|
-
case 3:
|
|
1464
|
-
_context.next = 5;
|
|
1465
|
-
return props.sdk.navigator.openNewEntry(props.contentTypeId, {
|
|
1466
|
-
slideIn: true
|
|
1467
|
-
});
|
|
1468
|
-
|
|
1469
|
-
case 5:
|
|
1470
|
-
_yield$props$sdk$navi = _context.sent;
|
|
1471
|
-
entity = _yield$props$sdk$navi.entity;
|
|
1472
|
-
slide = _yield$props$sdk$navi.slide;
|
|
1473
|
-
return _context.abrupt("return", {
|
|
1474
|
-
entity: entity,
|
|
1475
|
-
slide: slide
|
|
1476
|
-
});
|
|
1477
|
-
|
|
1478
|
-
case 11:
|
|
1479
|
-
_context.next = 13;
|
|
1480
|
-
return props.sdk.navigator.openNewAsset({
|
|
1481
|
-
slideIn: true
|
|
1482
|
-
});
|
|
1483
|
-
|
|
1484
|
-
case 13:
|
|
1485
|
-
_yield$props$sdk$navi2 = _context.sent;
|
|
1486
|
-
_entity = _yield$props$sdk$navi2.entity;
|
|
1487
|
-
_slide = _yield$props$sdk$navi2.slide;
|
|
1488
|
-
return _context.abrupt("return", {
|
|
1489
|
-
entity: _entity,
|
|
1490
|
-
slide: _slide
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
case 17:
|
|
1494
|
-
case "end":
|
|
1495
|
-
return _context.stop();
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
}, _callee);
|
|
1499
|
-
}));
|
|
1500
|
-
return _createEntity.apply(this, arguments);
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
function selectSingleEntity(_x2) {
|
|
1504
|
-
return _selectSingleEntity.apply(this, arguments);
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
function _selectSingleEntity() {
|
|
1508
|
-
_selectSingleEntity = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(props) {
|
|
1509
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1510
|
-
while (1) {
|
|
1511
|
-
switch (_context2.prev = _context2.next) {
|
|
1512
|
-
case 0:
|
|
1513
|
-
if (!(props.entityType === 'Entry')) {
|
|
1514
|
-
_context2.next = 6;
|
|
1515
|
-
break;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
_context2.next = 3;
|
|
1519
|
-
return props.sdk.dialogs.selectSingleEntry({
|
|
1520
|
-
locale: props.sdk.field.locale,
|
|
1521
|
-
contentTypes: getContentTypeIds(props.editorPermissions.readableContentTypes)
|
|
1522
|
-
});
|
|
1523
|
-
|
|
1524
|
-
case 3:
|
|
1525
|
-
return _context2.abrupt("return", _context2.sent);
|
|
1526
|
-
|
|
1527
|
-
case 6:
|
|
1528
|
-
return _context2.abrupt("return", props.sdk.dialogs.selectSingleAsset({
|
|
1529
|
-
locale: props.sdk.field.locale,
|
|
1530
|
-
mimetypeGroups: props.editorPermissions.validations.mimetypeGroups
|
|
1531
|
-
}));
|
|
1532
|
-
|
|
1533
|
-
case 7:
|
|
1534
|
-
case "end":
|
|
1535
|
-
return _context2.stop();
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
}, _callee2);
|
|
1539
|
-
}));
|
|
1540
|
-
return _selectSingleEntity.apply(this, arguments);
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
function selectMultipleEntities(_x3) {
|
|
1544
|
-
return _selectMultipleEntities.apply(this, arguments);
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
function _selectMultipleEntities() {
|
|
1548
|
-
_selectMultipleEntities = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(props) {
|
|
1549
|
-
var _props$editorPermissi, _props$editorPermissi2;
|
|
1550
|
-
|
|
1551
|
-
var value, linkCount, min, max;
|
|
1552
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1553
|
-
while (1) {
|
|
1554
|
-
switch (_context3.prev = _context3.next) {
|
|
1555
|
-
case 0:
|
|
1556
|
-
value = props.sdk.field.getValue();
|
|
1557
|
-
linkCount = Array.isArray(value) ? value.length : value ? 1 : 0; // TODO: Why not always set `min: 1` by default? Does it make sense to enforce
|
|
1558
|
-
// user to select as many entities as the field's "min" requires? What if e.g.
|
|
1559
|
-
// "min" is 4 and the user wants to insert 2 entities first, then create 2 new ones?
|
|
1560
|
-
|
|
1561
|
-
min = Math.max((((_props$editorPermissi = props.editorPermissions.validations.numberOfLinks) == null ? void 0 : _props$editorPermissi.min) || 1) - linkCount, 1); // TODO: Consider same for max. If e.g. "max" is 4, we disable the button if the
|
|
1562
|
-
// user wants to select 5 but we show no information why the button is disabled.
|
|
1563
|
-
|
|
1564
|
-
max = (((_props$editorPermissi2 = props.editorPermissions.validations.numberOfLinks) == null ? void 0 : _props$editorPermissi2.max) || +Infinity) - linkCount;
|
|
1565
|
-
|
|
1566
|
-
if (!(props.entityType === 'Entry')) {
|
|
1567
|
-
_context3.next = 10;
|
|
1568
|
-
break;
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
_context3.next = 7;
|
|
1572
|
-
return props.sdk.dialogs.selectMultipleEntries({
|
|
1573
|
-
locale: props.sdk.field.locale,
|
|
1574
|
-
contentTypes: getContentTypeIds(props.editorPermissions.readableContentTypes),
|
|
1575
|
-
min: min,
|
|
1576
|
-
max: max
|
|
1577
|
-
});
|
|
1578
|
-
|
|
1579
|
-
case 7:
|
|
1580
|
-
return _context3.abrupt("return", _context3.sent);
|
|
1581
|
-
|
|
1582
|
-
case 10:
|
|
1583
|
-
return _context3.abrupt("return", props.sdk.dialogs.selectMultipleAssets({
|
|
1584
|
-
locale: props.sdk.field.locale,
|
|
1585
|
-
mimetypeGroups: props.editorPermissions.validations.mimetypeGroups,
|
|
1586
|
-
min: min,
|
|
1587
|
-
max: max
|
|
1588
|
-
}));
|
|
1589
|
-
|
|
1590
|
-
case 11:
|
|
1591
|
-
case "end":
|
|
1592
|
-
return _context3.stop();
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
}, _callee3);
|
|
1596
|
-
}));
|
|
1597
|
-
return _selectMultipleEntities.apply(this, arguments);
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
var _excluded = ["renderCustomActions"],
|
|
1601
|
-
_excluded2 = ["renderCustomActions"];
|
|
1602
|
-
function useLinkActionsProps(props) {
|
|
1603
|
-
var _editorPermissions$va;
|
|
1604
|
-
|
|
1605
|
-
var sdk = props.sdk,
|
|
1606
|
-
editorPermissions = props.editorPermissions,
|
|
1607
|
-
entityType = props.entityType,
|
|
1608
|
-
canLinkMultiple = props.canLinkMultiple,
|
|
1609
|
-
isDisabled = props.isDisabled,
|
|
1610
|
-
actionLabels = props.actionLabels,
|
|
1611
|
-
itemsLength = props.itemsLength;
|
|
1612
|
-
var maxLinksCount = (_editorPermissions$va = editorPermissions.validations.numberOfLinks) == null ? void 0 : _editorPermissions$va.max;
|
|
1613
|
-
var value = sdk.field.getValue();
|
|
1614
|
-
var linkCount = Array.isArray(value) ? value.length : value ? 1 : 0;
|
|
1615
|
-
var isFull = !!maxLinksCount && maxLinksCount <= linkCount;
|
|
1616
|
-
var isEmpty = linkCount === 0;
|
|
1617
|
-
var onCreated = useCallback(function (entity, index, slide) {
|
|
1618
|
-
if (index === void 0) {
|
|
1619
|
-
index = itemsLength;
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
props.onCreate(entity.sys.id, index);
|
|
1623
|
-
props.onAction && props.onAction({
|
|
1624
|
-
type: 'create_and_link',
|
|
1625
|
-
entity: entityType,
|
|
1626
|
-
entityData: entity,
|
|
1627
|
-
slide: slide,
|
|
1628
|
-
index: index
|
|
1629
|
-
});
|
|
1630
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1631
|
-
[entityType, props.onCreate, props.onAction]);
|
|
1632
|
-
var onLinkedExisting = useCallback(function (entities, index) {
|
|
1633
|
-
if (index === void 0) {
|
|
1634
|
-
index = itemsLength;
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
props.onLink(entities.map(function (item) {
|
|
1638
|
-
return item.sys.id;
|
|
1639
|
-
}), index);
|
|
1640
|
-
entities.forEach(function (entity, i) {
|
|
1641
|
-
props.onAction && props.onAction({
|
|
1642
|
-
type: 'select_and_link',
|
|
1643
|
-
entity: entityType,
|
|
1644
|
-
entityData: entity,
|
|
1645
|
-
index: index === undefined ? undefined : index + i
|
|
1646
|
-
});
|
|
1647
|
-
});
|
|
1648
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1649
|
-
[entityType, props.onLink, props.onAction]);
|
|
1650
|
-
var onCreate = useCallback( /*#__PURE__*/function () {
|
|
1651
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(contentTypeId, index) {
|
|
1652
|
-
var _yield$createEntity, entity, slide;
|
|
1653
|
-
|
|
1654
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1655
|
-
while (1) {
|
|
1656
|
-
switch (_context.prev = _context.next) {
|
|
1657
|
-
case 0:
|
|
1658
|
-
_context.next = 2;
|
|
1659
|
-
return createEntity({
|
|
1660
|
-
sdk: sdk,
|
|
1661
|
-
entityType: entityType,
|
|
1662
|
-
contentTypeId: contentTypeId
|
|
1663
|
-
});
|
|
1664
|
-
|
|
1665
|
-
case 2:
|
|
1666
|
-
_yield$createEntity = _context.sent;
|
|
1667
|
-
entity = _yield$createEntity.entity;
|
|
1668
|
-
slide = _yield$createEntity.slide;
|
|
1669
|
-
|
|
1670
|
-
if (entity) {
|
|
1671
|
-
_context.next = 7;
|
|
1672
|
-
break;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
return _context.abrupt("return");
|
|
1676
|
-
|
|
1677
|
-
case 7:
|
|
1678
|
-
onCreated(entity, index, slide);
|
|
1679
|
-
|
|
1680
|
-
case 8:
|
|
1681
|
-
case "end":
|
|
1682
|
-
return _context.stop();
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
}, _callee);
|
|
1686
|
-
}));
|
|
1687
|
-
|
|
1688
|
-
return function (_x, _x2) {
|
|
1689
|
-
return _ref.apply(this, arguments);
|
|
1690
|
-
};
|
|
1691
|
-
}(), [sdk, entityType, onCreated]);
|
|
1692
|
-
var onLinkExisting = useCallback( /*#__PURE__*/function () {
|
|
1693
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(index) {
|
|
1694
|
-
var entity;
|
|
1695
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1696
|
-
while (1) {
|
|
1697
|
-
switch (_context2.prev = _context2.next) {
|
|
1698
|
-
case 0:
|
|
1699
|
-
_context2.next = 2;
|
|
1700
|
-
return selectSingleEntity({
|
|
1701
|
-
sdk: sdk,
|
|
1702
|
-
entityType: entityType,
|
|
1703
|
-
editorPermissions: editorPermissions
|
|
1704
|
-
});
|
|
1705
|
-
|
|
1706
|
-
case 2:
|
|
1707
|
-
entity = _context2.sent;
|
|
1708
|
-
|
|
1709
|
-
if (entity) {
|
|
1710
|
-
_context2.next = 5;
|
|
1711
|
-
break;
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
return _context2.abrupt("return");
|
|
1715
|
-
|
|
1716
|
-
case 5:
|
|
1717
|
-
onLinkedExisting([entity], index);
|
|
1718
|
-
|
|
1719
|
-
case 6:
|
|
1720
|
-
case "end":
|
|
1721
|
-
return _context2.stop();
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
}, _callee2);
|
|
1725
|
-
}));
|
|
1726
|
-
|
|
1727
|
-
return function (_x3) {
|
|
1728
|
-
return _ref2.apply(this, arguments);
|
|
1729
|
-
};
|
|
1730
|
-
}(), // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1731
|
-
[sdk, entityType, onLinkedExisting]);
|
|
1732
|
-
var onLinkSeveralExisting = useCallback( /*#__PURE__*/function () {
|
|
1733
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(index) {
|
|
1734
|
-
var entities;
|
|
1735
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1736
|
-
while (1) {
|
|
1737
|
-
switch (_context3.prev = _context3.next) {
|
|
1738
|
-
case 0:
|
|
1739
|
-
_context3.next = 2;
|
|
1740
|
-
return selectMultipleEntities({
|
|
1741
|
-
sdk: sdk,
|
|
1742
|
-
entityType: entityType,
|
|
1743
|
-
editorPermissions: editorPermissions
|
|
1744
|
-
});
|
|
1745
|
-
|
|
1746
|
-
case 2:
|
|
1747
|
-
entities = _context3.sent;
|
|
1748
|
-
|
|
1749
|
-
if (!(!entities || entities.length === 0)) {
|
|
1750
|
-
_context3.next = 5;
|
|
1751
|
-
break;
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
return _context3.abrupt("return");
|
|
1755
|
-
|
|
1756
|
-
case 5:
|
|
1757
|
-
onLinkedExisting(entities, index);
|
|
1758
|
-
|
|
1759
|
-
case 6:
|
|
1760
|
-
case "end":
|
|
1761
|
-
return _context3.stop();
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
}, _callee3);
|
|
1765
|
-
}));
|
|
1766
|
-
|
|
1767
|
-
return function (_x4) {
|
|
1768
|
-
return _ref3.apply(this, arguments);
|
|
1769
|
-
};
|
|
1770
|
-
}(), // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1771
|
-
[sdk, entityType, onLinkedExisting]); // FIXME: The memoization might rerun every time due to the always changing callback identities above
|
|
1772
|
-
|
|
1773
|
-
return useMemo(function () {
|
|
1774
|
-
return {
|
|
1775
|
-
entityType: entityType,
|
|
1776
|
-
canLinkMultiple: canLinkMultiple,
|
|
1777
|
-
isDisabled: isDisabled,
|
|
1778
|
-
isEmpty: isEmpty,
|
|
1779
|
-
isFull: isFull,
|
|
1780
|
-
canCreateEntity: editorPermissions.canCreateEntity,
|
|
1781
|
-
canLinkEntity: editorPermissions.canLinkEntity,
|
|
1782
|
-
contentTypes: editorPermissions.creatableContentTypes,
|
|
1783
|
-
onCreate: onCreate,
|
|
1784
|
-
onLinkExisting: canLinkMultiple ? onLinkSeveralExisting : onLinkExisting,
|
|
1785
|
-
actionLabels: actionLabels,
|
|
1786
|
-
onCreated: onCreated,
|
|
1787
|
-
onLinkedExisting: onLinkedExisting,
|
|
1788
|
-
itemsLength: itemsLength
|
|
1789
|
-
};
|
|
1790
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1791
|
-
[entityType, canLinkMultiple, isDisabled, isEmpty, isFull, editorPermissions.canCreateEntity, editorPermissions.canLinkEntity, actionLabels, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
1792
|
-
editorPermissions.creatableContentTypes.map(function (ct) {
|
|
1793
|
-
return ct.sys.id;
|
|
1794
|
-
}).join(':'), onCreate, onLinkExisting, onLinkSeveralExisting, onCreated, onLinkedExisting, itemsLength]);
|
|
1795
|
-
}
|
|
1796
|
-
function LinkEntityActions(_ref4) {
|
|
1797
|
-
var renderCustomActions = _ref4.renderCustomActions,
|
|
1798
|
-
props = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
1799
|
-
|
|
1800
|
-
return renderCustomActions ? renderCustomActions(props) : createElement(LinkActions, _extends({}, props));
|
|
1801
|
-
}
|
|
1802
|
-
function CombinedLinkEntityActions(_ref5) {
|
|
1803
|
-
var renderCustomActions = _ref5.renderCustomActions,
|
|
1804
|
-
props = _objectWithoutPropertiesLoose(_ref5, _excluded2);
|
|
1805
|
-
|
|
1806
|
-
return renderCustomActions ? renderCustomActions(props) : createElement(CombinedLinkActions, _extends({}, props));
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
// eslint-disable-next-line -- TODO: describe this disable no-restricted-imports
|
|
1810
|
-
/**
|
|
1811
|
-
* @param {Date|string} date A valid constructor argument for moment()
|
|
1812
|
-
* @param {boolean=} short Render only Today/Tomorrow/Yesterday if valid. Defaults to false
|
|
1813
|
-
*/
|
|
1814
|
-
|
|
1815
|
-
var formatDate = function formatDate(date, _short) {
|
|
1816
|
-
switch (moment().startOf('day').diff(moment(date).startOf('day'), 'days')) {
|
|
1817
|
-
case 0:
|
|
1818
|
-
return _short ? 'Today' : "Today, " + moment(date).format('DD MMM YYYY');
|
|
1819
|
-
|
|
1820
|
-
case -1:
|
|
1821
|
-
return _short ? 'Tomorrow' : "Tomorrow, " + moment(date).format('DD MMM YYYY');
|
|
1822
|
-
|
|
1823
|
-
case 1:
|
|
1824
|
-
return _short ? 'Yesterday' : "Yesterday, " + moment(date).format('DD MMM YYYY');
|
|
1825
|
-
|
|
1826
|
-
default:
|
|
1827
|
-
return moment(date).format('ddd, DD MMM YYYY');
|
|
1828
|
-
}
|
|
1829
|
-
};
|
|
1830
|
-
/**
|
|
1831
|
-
* Returns the time portion of a date in the local time in the format H:MM AM/PM
|
|
1832
|
-
*
|
|
1833
|
-
* == Examples
|
|
1834
|
-
* * `T15:36:45.000Z` => 3:36 PM (if in +0:00 offset)
|
|
1835
|
-
*/
|
|
1836
|
-
|
|
1837
|
-
var formatTime = function formatTime(date) {
|
|
1838
|
-
return moment.utc(date).local().format('h:mm A');
|
|
1839
|
-
};
|
|
1840
|
-
var formatDateAndTime = function formatDateAndTime(date, _short2) {
|
|
1841
|
-
return formatDate(date, _short2) + " at " + formatTime(date);
|
|
1842
|
-
};
|
|
1843
|
-
|
|
1844
|
-
var getScheduleTooltipContent = function getScheduleTooltipContent(_ref) {
|
|
1845
|
-
var job = _ref.job,
|
|
1846
|
-
jobsCount = _ref.jobsCount;
|
|
1847
|
-
return "Will " + job.action.toLowerCase() + " " + formatDateAndTime(job.scheduledFor.datetime).toLowerCase() + "\n " + (jobsCount > 1 ? "+ " + (jobsCount - 1) + " more" : '');
|
|
1848
|
-
};
|
|
1849
|
-
var ScheduleTooltip = function ScheduleTooltip(_ref2) {
|
|
1850
|
-
var job = _ref2.job,
|
|
1851
|
-
jobsCount = _ref2.jobsCount,
|
|
1852
|
-
children = _ref2.children;
|
|
1853
|
-
return React__default.createElement(Tooltip, {
|
|
1854
|
-
placement: "top",
|
|
1855
|
-
testId: job.sys.id,
|
|
1856
|
-
as: "div",
|
|
1857
|
-
content: getScheduleTooltipContent({
|
|
1858
|
-
job: job,
|
|
1859
|
-
jobsCount: jobsCount
|
|
1860
|
-
})
|
|
1861
|
-
}, children);
|
|
1862
|
-
};
|
|
1863
|
-
|
|
1864
|
-
var ScheduledIconWithTooltip = function ScheduledIconWithTooltip(_ref) {
|
|
1865
|
-
var _status$jobs;
|
|
1866
|
-
|
|
1867
|
-
var entityType = _ref.entityType,
|
|
1868
|
-
entityId = _ref.entityId,
|
|
1869
|
-
getEntityScheduledActions = _ref.getEntityScheduledActions,
|
|
1870
|
-
children = _ref.children;
|
|
1871
|
-
|
|
1872
|
-
var _React$useState = React__default.useState({
|
|
1873
|
-
type: 'loading'
|
|
1874
|
-
}),
|
|
1875
|
-
status = _React$useState[0],
|
|
1876
|
-
setStatus = _React$useState[1];
|
|
1877
|
-
|
|
1878
|
-
React__default.useEffect(function () {
|
|
1879
|
-
getEntityScheduledActions(entityType, entityId).then(function (data) {
|
|
1880
|
-
setStatus({
|
|
1881
|
-
type: 'loaded',
|
|
1882
|
-
jobs: data
|
|
1883
|
-
});
|
|
1884
|
-
})["catch"](function (e) {
|
|
1885
|
-
setStatus({
|
|
1886
|
-
type: 'error',
|
|
1887
|
-
error: e
|
|
1888
|
-
});
|
|
1889
|
-
}); // This should only be ever called once. Following the eslint hint to add used
|
|
1890
|
-
// dependencies will cause page freeze (infinite loop)
|
|
1891
|
-
// eslint-disable-next-line -- TODO: describe this disable
|
|
1892
|
-
}, []);
|
|
1893
|
-
|
|
1894
|
-
if (status.type === 'loading' || status.type === 'error') {
|
|
1895
|
-
return null;
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
var jobs = (_status$jobs = status.jobs) != null ? _status$jobs : [];
|
|
1899
|
-
|
|
1900
|
-
if (jobs.length === 0) {
|
|
1901
|
-
return null;
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
var mostRelevantJob = jobs[0];
|
|
1905
|
-
return React__default.createElement(ScheduleTooltip, {
|
|
1906
|
-
job: mostRelevantJob,
|
|
1907
|
-
jobsCount: jobs.length
|
|
1908
|
-
}, children);
|
|
1909
|
-
};
|
|
1910
|
-
|
|
1911
|
-
var dimensions = {
|
|
1912
|
-
width: 70,
|
|
1913
|
-
height: 70
|
|
1914
|
-
};
|
|
1915
|
-
function AssetThumbnail(props) {
|
|
1916
|
-
return React__default.createElement("img", {
|
|
1917
|
-
alt: props.file.fileName,
|
|
1918
|
-
src: props.file.url + "?w=" + dimensions.width + "&h=" + dimensions.height + "&fit=thumb",
|
|
1919
|
-
height: dimensions.height,
|
|
1920
|
-
width: dimensions.width
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
|
-
var _excluded$1 = ["priority"],
|
|
1925
|
-
_excluded2$1 = ["children"];
|
|
1926
|
-
|
|
1927
|
-
var globalQueue = /*#__PURE__*/new PQueue({
|
|
1928
|
-
concurrency: 50
|
|
1929
|
-
});
|
|
1930
|
-
var UnsupportedError = /*#__PURE__*/function (_Error) {
|
|
1931
|
-
_inheritsLoose(UnsupportedError, _Error);
|
|
1932
|
-
|
|
1933
|
-
function UnsupportedError(message) {
|
|
1934
|
-
var _this;
|
|
1935
|
-
|
|
1936
|
-
_this = _Error.call(this, message) || this;
|
|
1937
|
-
_this.isUnsupportedError = void 0;
|
|
1938
|
-
_this.isUnsupportedError = true;
|
|
1939
|
-
return _this;
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
return UnsupportedError;
|
|
1943
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1944
|
-
function isUnsupportedError(value) {
|
|
1945
|
-
return typeof value === 'object' && (value == null ? void 0 : value.isUnsupportedError) === true;
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
var isEntityQueryKey = function isEntityQueryKey(queryKey) {
|
|
1949
|
-
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
1950
|
-
};
|
|
1951
|
-
|
|
1952
|
-
function fetchContentfulEntry(_x) {
|
|
1953
|
-
return _fetchContentfulEntry.apply(this, arguments);
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
function _fetchContentfulEntry() {
|
|
1957
|
-
_fetchContentfulEntry = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(params) {
|
|
1958
|
-
var urn, fetch, options, resourceId, _resourceId$split, spaceId, entryId, environmentId, _yield$Promise$all, space, entry, contentTypeId, _yield$Promise$all2, contentType, defaultLocaleCode;
|
|
1959
|
-
|
|
1960
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1961
|
-
while (1) {
|
|
1962
|
-
switch (_context3.prev = _context3.next) {
|
|
1963
|
-
case 0:
|
|
1964
|
-
urn = params.urn, fetch = params.fetch, options = params.options;
|
|
1965
|
-
resourceId = urn.split(':', 6)[5];
|
|
1966
|
-
_resourceId$split = resourceId.split('/'), spaceId = _resourceId$split[1], entryId = _resourceId$split[3];
|
|
1967
|
-
environmentId = 'master';
|
|
1968
|
-
_context3.next = 6;
|
|
1969
|
-
return Promise.all([fetch(['space', spaceId], function (_ref10) {
|
|
1970
|
-
var cmaClient = _ref10.cmaClient;
|
|
1971
|
-
return cmaClient.space.get({
|
|
1972
|
-
spaceId: spaceId
|
|
1973
|
-
});
|
|
1974
|
-
}, options), fetch(['entry', spaceId, environmentId, entryId], function (_ref11) {
|
|
1975
|
-
var cmaClient = _ref11.cmaClient;
|
|
1976
|
-
return cmaClient.entry.get({
|
|
1977
|
-
spaceId: spaceId,
|
|
1978
|
-
environmentId: environmentId,
|
|
1979
|
-
entryId: entryId
|
|
1980
|
-
});
|
|
1981
|
-
}, options)]);
|
|
1982
|
-
|
|
1983
|
-
case 6:
|
|
1984
|
-
_yield$Promise$all = _context3.sent;
|
|
1985
|
-
space = _yield$Promise$all[0];
|
|
1986
|
-
entry = _yield$Promise$all[1];
|
|
1987
|
-
contentTypeId = entry.sys.contentType.sys.id;
|
|
1988
|
-
_context3.next = 12;
|
|
1989
|
-
return Promise.all([fetch(['contentType', spaceId, environmentId, contentTypeId], function (_ref12) {
|
|
1990
|
-
var cmaClient = _ref12.cmaClient;
|
|
1991
|
-
return cmaClient.contentType.get({
|
|
1992
|
-
contentTypeId: contentTypeId,
|
|
1993
|
-
spaceId: spaceId,
|
|
1994
|
-
environmentId: environmentId
|
|
1995
|
-
});
|
|
1996
|
-
}, options), fetch(['defaultLocale', spaceId, environmentId], /*#__PURE__*/function () {
|
|
1997
|
-
var _ref14 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref13) {
|
|
1998
|
-
var _locales$items$find;
|
|
1999
|
-
|
|
2000
|
-
var cmaClient, locales, defaultLocaleCode;
|
|
2001
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2002
|
-
while (1) {
|
|
2003
|
-
switch (_context2.prev = _context2.next) {
|
|
2004
|
-
case 0:
|
|
2005
|
-
cmaClient = _ref13.cmaClient;
|
|
2006
|
-
_context2.next = 3;
|
|
2007
|
-
return cmaClient.locale.getMany({
|
|
2008
|
-
spaceId: spaceId,
|
|
2009
|
-
environmentId: environmentId,
|
|
2010
|
-
query: {
|
|
2011
|
-
limit: 100
|
|
2012
|
-
}
|
|
2013
|
-
});
|
|
2014
|
-
|
|
2015
|
-
case 3:
|
|
2016
|
-
locales = _context2.sent;
|
|
2017
|
-
defaultLocaleCode = (_locales$items$find = locales.items.find(function (locale) {
|
|
2018
|
-
return locale["default"];
|
|
2019
|
-
})) == null ? void 0 : _locales$items$find.code;
|
|
2020
|
-
return _context2.abrupt("return", defaultLocaleCode);
|
|
2021
|
-
|
|
2022
|
-
case 6:
|
|
2023
|
-
case "end":
|
|
2024
|
-
return _context2.stop();
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
}, _callee2);
|
|
2028
|
-
}));
|
|
2029
|
-
|
|
2030
|
-
return function (_x3) {
|
|
2031
|
-
return _ref14.apply(this, arguments);
|
|
2032
|
-
};
|
|
2033
|
-
}(), options)]);
|
|
2034
|
-
|
|
2035
|
-
case 12:
|
|
2036
|
-
_yield$Promise$all2 = _context3.sent;
|
|
2037
|
-
contentType = _yield$Promise$all2[0];
|
|
2038
|
-
defaultLocaleCode = _yield$Promise$all2[1];
|
|
2039
|
-
return _context3.abrupt("return", {
|
|
2040
|
-
defaultLocaleCode: defaultLocaleCode,
|
|
2041
|
-
resource: entry,
|
|
2042
|
-
space: space,
|
|
2043
|
-
contentType: contentType
|
|
2044
|
-
});
|
|
2045
|
-
|
|
2046
|
-
case 16:
|
|
2047
|
-
case "end":
|
|
2048
|
-
return _context3.stop();
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
}, _callee3);
|
|
2052
|
-
}));
|
|
2053
|
-
return _fetchContentfulEntry.apply(this, arguments);
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
var _constate = /*#__PURE__*/constate(function useInitServices(props) {
|
|
2057
|
-
var _props$sdk$ids$enviro;
|
|
2058
|
-
|
|
2059
|
-
var currentSpaceId = props.sdk.ids.space;
|
|
2060
|
-
var currentEnvironmentId = (_props$sdk$ids$enviro = props.sdk.ids.environmentAlias) != null ? _props$sdk$ids$enviro : props.sdk.ids.environment;
|
|
2061
|
-
var environmentIds = useMemo(function () {
|
|
2062
|
-
return [props.sdk.ids.environmentAlias, props.sdk.ids.environment];
|
|
2063
|
-
}, [props.sdk.ids.environmentAlias, props.sdk.ids.environment]);
|
|
2064
|
-
var queryClient = useQueryClient();
|
|
2065
|
-
var queryCache = queryClient.getQueryCache();
|
|
2066
|
-
var entityChangeUnsubscribers = useRef({});
|
|
2067
|
-
var cmaClient = useMemo(function () {
|
|
2068
|
-
return createClient({
|
|
2069
|
-
apiAdapter: props.sdk.cmaAdapter
|
|
2070
|
-
}, {
|
|
2071
|
-
type: 'plain'
|
|
2072
|
-
});
|
|
2073
|
-
}, [props.sdk.cmaAdapter]);
|
|
2074
|
-
var queryQueue = useMemo(function () {
|
|
2075
|
-
if (props.queryConcurrency) {
|
|
2076
|
-
return new PQueue({
|
|
2077
|
-
concurrency: props.queryConcurrency
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
return globalQueue;
|
|
2082
|
-
}, [props.queryConcurrency]);
|
|
2083
|
-
var fetch = useCallback(function fetch(queryKey, fn, options) {
|
|
2084
|
-
if (options === void 0) {
|
|
2085
|
-
options = {};
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
var _options = options,
|
|
2089
|
-
priority = _options.priority,
|
|
2090
|
-
queryOptions = _objectWithoutPropertiesLoose(_options, _excluded$1);
|
|
2091
|
-
|
|
2092
|
-
return queryClient.fetchQuery(queryKey, function () {
|
|
2093
|
-
return queryQueue.add(function () {
|
|
2094
|
-
return fn({
|
|
2095
|
-
cmaClient: cmaClient
|
|
2096
|
-
});
|
|
2097
|
-
}, {
|
|
2098
|
-
priority: priority
|
|
2099
|
-
});
|
|
2100
|
-
}, queryOptions);
|
|
2101
|
-
}, [queryClient, queryQueue, cmaClient]);
|
|
2102
|
-
var getEntity = useCallback(function getEntity(entityType, entityId, options) {
|
|
2103
|
-
var _options$spaceId, _options$environmentI;
|
|
2104
|
-
|
|
2105
|
-
var spaceId = (_options$spaceId = options == null ? void 0 : options.spaceId) != null ? _options$spaceId : currentSpaceId;
|
|
2106
|
-
var environmentId = (_options$environmentI = options == null ? void 0 : options.environmentId) != null ? _options$environmentI : currentEnvironmentId;
|
|
2107
|
-
var queryKey = [entityType, entityId, spaceId, environmentId];
|
|
2108
|
-
return fetch(queryKey, function (_ref) {
|
|
2109
|
-
var cmaClient = _ref.cmaClient;
|
|
2110
|
-
|
|
2111
|
-
if (entityType === 'Entry') {
|
|
2112
|
-
return cmaClient.entry.get({
|
|
2113
|
-
entryId: entityId,
|
|
2114
|
-
spaceId: spaceId,
|
|
2115
|
-
environmentId: environmentId
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
if (entityType === 'Asset') {
|
|
2120
|
-
return cmaClient.asset.get({
|
|
2121
|
-
assetId: entityId,
|
|
2122
|
-
spaceId: spaceId,
|
|
2123
|
-
environmentId: environmentId
|
|
2124
|
-
});
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
throw new UnsupportedError('Unsupported entity type');
|
|
2128
|
-
}, options);
|
|
2129
|
-
}, [fetch, currentSpaceId, currentEnvironmentId]);
|
|
2130
|
-
/**
|
|
2131
|
-
* Fetch all scheduled actions for a given entity.
|
|
2132
|
-
* This function fetches all schedules for all entries and then returns
|
|
2133
|
-
* a filtered result based on the entityID provided.
|
|
2134
|
-
*
|
|
2135
|
-
* The result is then reused/cached for subsequent calls to this function.
|
|
2136
|
-
*/
|
|
2137
|
-
|
|
2138
|
-
/**
|
|
2139
|
-
* Fetch all scheduled actions for a given entity.
|
|
2140
|
-
* This function fetches all schedules for all entries and then returns
|
|
2141
|
-
* a filtered result based on the entityID provided.
|
|
2142
|
-
*
|
|
2143
|
-
* The result is then reused/cached for subsequent calls to this function.
|
|
2144
|
-
*/
|
|
2145
|
-
var getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
|
|
2146
|
-
var _options$spaceId2, _options$environmentI2;
|
|
2147
|
-
|
|
2148
|
-
// This is fixed to force the cache to reuse previous results
|
|
2149
|
-
var fixedEntityCacheId = 'scheduledActionEntityId'; // A space+environment combo can only have up to 500 scheduled actions
|
|
2150
|
-
// With this request we fetch all schedules and can reuse the results.
|
|
2151
|
-
// See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
|
|
2152
|
-
|
|
2153
|
-
// A space+environment combo can only have up to 500 scheduled actions
|
|
2154
|
-
// With this request we fetch all schedules and can reuse the results.
|
|
2155
|
-
// See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
|
|
2156
|
-
var maxScheduledActions = 500;
|
|
2157
|
-
var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
|
|
2158
|
-
var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
|
|
2159
|
-
var queryKey = ['scheduled-actions', entityType, fixedEntityCacheId, spaceId, environmentId]; // Fetch + Filter by entity ID in the end
|
|
2160
|
-
|
|
2161
|
-
// Fetch + Filter by entity ID in the end
|
|
2162
|
-
return fetch(queryKey, /*#__PURE__*/function () {
|
|
2163
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
|
|
2164
|
-
var cmaClient, response;
|
|
2165
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
2166
|
-
while (1) {
|
|
2167
|
-
switch (_context.prev = _context.next) {
|
|
2168
|
-
case 0:
|
|
2169
|
-
cmaClient = _ref2.cmaClient;
|
|
2170
|
-
_context.next = 3;
|
|
2171
|
-
return cmaClient.scheduledActions.getMany({
|
|
2172
|
-
spaceId: spaceId,
|
|
2173
|
-
query: {
|
|
2174
|
-
'environment.sys.id': environmentId,
|
|
2175
|
-
'sys.status[in]': 'scheduled',
|
|
2176
|
-
order: 'scheduledFor.datetime',
|
|
2177
|
-
limit: maxScheduledActions
|
|
2178
|
-
}
|
|
2179
|
-
});
|
|
2180
|
-
|
|
2181
|
-
case 3:
|
|
2182
|
-
response = _context.sent;
|
|
2183
|
-
return _context.abrupt("return", response.items);
|
|
2184
|
-
|
|
2185
|
-
case 5:
|
|
2186
|
-
case "end":
|
|
2187
|
-
return _context.stop();
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
}, _callee);
|
|
2191
|
-
}));
|
|
2192
|
-
|
|
2193
|
-
return function (_x2) {
|
|
2194
|
-
return _ref3.apply(this, arguments);
|
|
2195
|
-
};
|
|
2196
|
-
}(), options).then(function (items) {
|
|
2197
|
-
return items.filter(function (action) {
|
|
2198
|
-
return action.entity.sys.id === entityId;
|
|
2199
|
-
});
|
|
2200
|
-
});
|
|
2201
|
-
}, [fetch, currentSpaceId, currentEnvironmentId]);
|
|
2202
|
-
var getResource = useCallback(function getResource(resourceType, urn, options) {
|
|
2203
|
-
var queryKey = ['Resource', resourceType, urn];
|
|
2204
|
-
return fetch(queryKey, function () {
|
|
2205
|
-
if (resourceType === 'Contentful:Entry') {
|
|
2206
|
-
return fetchContentfulEntry({
|
|
2207
|
-
fetch: fetch,
|
|
2208
|
-
urn: urn,
|
|
2209
|
-
options: options
|
|
2210
|
-
});
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
throw new UnsupportedError('Unsupported resource type');
|
|
2214
|
-
}, options);
|
|
2215
|
-
}, [fetch]);
|
|
2216
|
-
var isSameSpaceEntityQueryKey = useCallback(function (queryKey) {
|
|
2217
|
-
var isEntityKey = isEntityQueryKey(queryKey);
|
|
2218
|
-
var isSameSpaceEntityKey = isEntityKey && queryKey[2] === currentSpaceId && environmentIds.includes(queryKey[3]);
|
|
2219
|
-
return isSameSpaceEntityKey;
|
|
2220
|
-
}, [currentSpaceId, environmentIds]); // @ts-expect-error ...
|
|
2221
|
-
|
|
2222
|
-
// @ts-expect-error ...
|
|
2223
|
-
var onEntityChanged = props.sdk.space.onEntityChanged;
|
|
2224
|
-
var onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
|
|
2225
|
-
useEffect(function () {
|
|
2226
|
-
function findSameSpaceQueries() {
|
|
2227
|
-
return queryCache.findAll({
|
|
2228
|
-
type: 'active',
|
|
2229
|
-
predicate: function predicate(query) {
|
|
2230
|
-
return isSameSpaceEntityQueryKey(query.queryKey);
|
|
2231
|
-
}
|
|
2232
|
-
});
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
|
-
if (typeof onEntityChanged !== 'function') {
|
|
2236
|
-
return onSlideInNavigation(function (_ref4) {
|
|
2237
|
-
var oldSlideLevel = _ref4.oldSlideLevel,
|
|
2238
|
-
newSlideLevel = _ref4.newSlideLevel;
|
|
2239
|
-
|
|
2240
|
-
if (oldSlideLevel > newSlideLevel) {
|
|
2241
|
-
findSameSpaceQueries().forEach(function (query) {
|
|
2242
|
-
// automatically refetches the query
|
|
2243
|
-
void queryClient.invalidateQueries(query.queryKey);
|
|
2244
|
-
});
|
|
2245
|
-
}
|
|
2246
|
-
});
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
var subscribeQuery = function subscribeQuery(_ref5) {
|
|
2250
|
-
var queryKey = _ref5.queryKey,
|
|
2251
|
-
queryHash = _ref5.queryHash;
|
|
2252
|
-
var entityType = queryKey[0],
|
|
2253
|
-
entityId = queryKey[1];
|
|
2254
|
-
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, function (data) {
|
|
2255
|
-
queryClient.setQueryData(queryKey, data);
|
|
2256
|
-
});
|
|
2257
|
-
};
|
|
2258
|
-
|
|
2259
|
-
findSameSpaceQueries().forEach(subscribeQuery);
|
|
2260
|
-
var unsubscribe = queryCache.subscribe(function (event) {
|
|
2261
|
-
if (!event) {
|
|
2262
|
-
return;
|
|
2263
|
-
}
|
|
2264
|
-
|
|
2265
|
-
var type = event.type,
|
|
2266
|
-
query = event.query;
|
|
2267
|
-
var queryKey = query.queryKey,
|
|
2268
|
-
queryHash = query.queryHash;
|
|
2269
|
-
|
|
2270
|
-
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
2271
|
-
return;
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
if (type === 'added') {
|
|
2275
|
-
subscribeQuery(query);
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
if (type === 'removed') {
|
|
2279
|
-
var _entityChangeUnsubscr, _entityChangeUnsubscr2;
|
|
2280
|
-
|
|
2281
|
-
// calling unsubscribe
|
|
2282
|
-
(_entityChangeUnsubscr = (_entityChangeUnsubscr2 = entityChangeUnsubscribers.current)[queryHash]) == null ? void 0 : _entityChangeUnsubscr.call(_entityChangeUnsubscr2);
|
|
2283
|
-
}
|
|
2284
|
-
});
|
|
2285
|
-
return function () {
|
|
2286
|
-
unsubscribe();
|
|
2287
|
-
Object.values(entityChangeUnsubscribers.current).forEach(function (off) {
|
|
2288
|
-
return off();
|
|
2289
|
-
});
|
|
2290
|
-
entityChangeUnsubscribers.current = {};
|
|
2291
|
-
};
|
|
2292
|
-
}, [onEntityChanged, queryCache, isSameSpaceEntityQueryKey, queryClient, getEntity, onSlideInNavigation]);
|
|
2293
|
-
return {
|
|
2294
|
-
ids: props.sdk.ids,
|
|
2295
|
-
cmaClient: cmaClient,
|
|
2296
|
-
fetch: fetch,
|
|
2297
|
-
getResource: getResource,
|
|
2298
|
-
getEntity: getEntity,
|
|
2299
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
2300
|
-
};
|
|
2301
|
-
}, function (_ref6) {
|
|
2302
|
-
var fetch = _ref6.fetch;
|
|
2303
|
-
return fetch;
|
|
2304
|
-
}, function (_ref7) {
|
|
2305
|
-
var getResource = _ref7.getResource,
|
|
2306
|
-
getEntity = _ref7.getEntity,
|
|
2307
|
-
getEntityScheduledActions = _ref7.getEntityScheduledActions;
|
|
2308
|
-
return {
|
|
2309
|
-
getResource: getResource,
|
|
2310
|
-
getEntity: getEntity,
|
|
2311
|
-
getEntityScheduledActions: getEntityScheduledActions
|
|
2312
|
-
};
|
|
2313
|
-
}, function (_ref8) {
|
|
2314
|
-
var _ids$environmentAlias;
|
|
2315
|
-
|
|
2316
|
-
var ids = _ref8.ids;
|
|
2317
|
-
return {
|
|
2318
|
-
environment: (_ids$environmentAlias = ids.environmentAlias) != null ? _ids$environmentAlias : ids.environment,
|
|
2319
|
-
space: ids.space
|
|
2320
|
-
};
|
|
2321
|
-
}),
|
|
2322
|
-
InternalServiceProvider = _constate[0],
|
|
2323
|
-
useEntityLoader = _constate[2],
|
|
2324
|
-
useCurrentIds = _constate[3];
|
|
2325
|
-
|
|
2326
|
-
function useEntity(entityType, entityId, options) {
|
|
2327
|
-
var _options$spaceId3, _options$environmentI3;
|
|
2328
|
-
|
|
2329
|
-
var _useCurrentIds = useCurrentIds(),
|
|
2330
|
-
space = _useCurrentIds.space,
|
|
2331
|
-
environment = _useCurrentIds.environment;
|
|
2332
|
-
|
|
2333
|
-
var _useEntityLoader = useEntityLoader(),
|
|
2334
|
-
getEntity = _useEntityLoader.getEntity;
|
|
2335
|
-
|
|
2336
|
-
var queryKey = [entityType, entityId, (_options$spaceId3 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId3 : space, (_options$environmentI3 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI3 : environment];
|
|
2337
|
-
|
|
2338
|
-
var _useQuery = useQuery(queryKey, function () {
|
|
2339
|
-
return getEntity(entityType, entityId, options);
|
|
2340
|
-
}, {
|
|
2341
|
-
enabled: options == null ? void 0 : options.enabled
|
|
2342
|
-
}),
|
|
2343
|
-
status = _useQuery.status,
|
|
2344
|
-
data = _useQuery.data;
|
|
2345
|
-
|
|
2346
|
-
return {
|
|
2347
|
-
status: status,
|
|
2348
|
-
data: data
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
function useResource(resourceType, urn, options) {
|
|
2352
|
-
var queryKey = ['Resource', resourceType, urn];
|
|
2353
|
-
|
|
2354
|
-
var _useEntityLoader2 = useEntityLoader(),
|
|
2355
|
-
getResource = _useEntityLoader2.getResource;
|
|
2356
|
-
|
|
2357
|
-
var _useQuery2 = useQuery(queryKey, function () {
|
|
2358
|
-
return getResource(resourceType, urn, options);
|
|
2359
|
-
}, {
|
|
2360
|
-
enabled: options == null ? void 0 : options.enabled
|
|
2361
|
-
}),
|
|
2362
|
-
status = _useQuery2.status,
|
|
2363
|
-
data = _useQuery2.data,
|
|
2364
|
-
error = _useQuery2.error;
|
|
2365
|
-
|
|
2366
|
-
return {
|
|
2367
|
-
status: status,
|
|
2368
|
-
data: data,
|
|
2369
|
-
error: error
|
|
2370
|
-
};
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
function EntityProvider(_ref9) {
|
|
2374
|
-
var children = _ref9.children,
|
|
2375
|
-
props = _objectWithoutPropertiesLoose(_ref9, _excluded2$1);
|
|
2376
|
-
|
|
2377
|
-
var reactQueryClient = useMemo(function () {
|
|
2378
|
-
var queryCache = new QueryCache();
|
|
2379
|
-
var queryClient = new QueryClient({
|
|
2380
|
-
queryCache: queryCache,
|
|
2381
|
-
defaultOptions: {
|
|
2382
|
-
queries: {
|
|
2383
|
-
useErrorBoundary: false,
|
|
2384
|
-
refetchOnWindowFocus: false,
|
|
2385
|
-
refetchOnReconnect: true,
|
|
2386
|
-
refetchOnMount: false,
|
|
2387
|
-
staleTime: Infinity,
|
|
2388
|
-
retry: false
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
});
|
|
2392
|
-
return queryClient;
|
|
2393
|
-
}, []);
|
|
2394
|
-
return React__default.createElement(QueryClientProvider, {
|
|
2395
|
-
client: reactQueryClient
|
|
2396
|
-
}, React__default.createElement(InternalServiceProvider, _extends({}, props), children));
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
function ReferenceEditor(props) {
|
|
2400
|
-
return createElement(EntityProvider, {
|
|
2401
|
-
sdk: props.sdk
|
|
2402
|
-
}, createElement(FieldConnector, {
|
|
2403
|
-
throttle: 0,
|
|
2404
|
-
field: props.sdk.field,
|
|
2405
|
-
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
2406
|
-
isEqualValues: function isEqualValues(value1, value2) {
|
|
2407
|
-
return deepEqual(value1, value2);
|
|
2408
|
-
}
|
|
2409
|
-
}, props.children));
|
|
2410
|
-
}
|
|
2411
|
-
ReferenceEditor.defaultProps = {
|
|
2412
|
-
isInitiallyDisabled: true,
|
|
2413
|
-
hasCardEditActions: true
|
|
2414
|
-
};
|
|
2415
|
-
|
|
2416
|
-
var AllowActionsOnContentType = function AllowActionsOnContentType() {
|
|
2417
|
-
return Promise.resolve(true);
|
|
2418
|
-
};
|
|
2419
|
-
|
|
2420
|
-
function useAccessApi(accessApi) {
|
|
2421
|
-
var _accessApi$canPerform;
|
|
2422
|
-
|
|
2423
|
-
var canPerformAction = accessApi.can;
|
|
2424
|
-
var canPerformActionOnEntryOfType = (_accessApi$canPerform = accessApi.canPerformActionOnEntryOfType) != null ? _accessApi$canPerform : AllowActionsOnContentType;
|
|
2425
|
-
return {
|
|
2426
|
-
canPerformAction: canPerformAction,
|
|
2427
|
-
canPerformActionOnEntryOfType: canPerformActionOnEntryOfType
|
|
2428
|
-
};
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
function filter(_x, _x2) {
|
|
2432
|
-
return _filter.apply(this, arguments);
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
function _filter() {
|
|
2436
|
-
_filter = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(arr, predicate) {
|
|
2437
|
-
var fail, results;
|
|
2438
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
2439
|
-
while (1) {
|
|
2440
|
-
switch (_context3.prev = _context3.next) {
|
|
2441
|
-
case 0:
|
|
2442
|
-
// intentionally parallel as we assume it's cached in the implementation of the access api
|
|
2443
|
-
fail = Symbol();
|
|
2444
|
-
_context3.next = 3;
|
|
2445
|
-
return Promise.all(arr.map( /*#__PURE__*/function () {
|
|
2446
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(item) {
|
|
2447
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2448
|
-
while (1) {
|
|
2449
|
-
switch (_context2.prev = _context2.next) {
|
|
2450
|
-
case 0:
|
|
2451
|
-
_context2.next = 2;
|
|
2452
|
-
return predicate(item);
|
|
2453
|
-
|
|
2454
|
-
case 2:
|
|
2455
|
-
if (!_context2.sent) {
|
|
2456
|
-
_context2.next = 6;
|
|
2457
|
-
break;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
_context2.t0 = item;
|
|
2461
|
-
_context2.next = 7;
|
|
2462
|
-
break;
|
|
2463
|
-
|
|
2464
|
-
case 6:
|
|
2465
|
-
_context2.t0 = fail;
|
|
2466
|
-
|
|
2467
|
-
case 7:
|
|
2468
|
-
return _context2.abrupt("return", _context2.t0);
|
|
2469
|
-
|
|
2470
|
-
case 8:
|
|
2471
|
-
case "end":
|
|
2472
|
-
return _context2.stop();
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
}, _callee2);
|
|
2476
|
-
}));
|
|
2477
|
-
|
|
2478
|
-
return function (_x3) {
|
|
2479
|
-
return _ref.apply(this, arguments);
|
|
2480
|
-
};
|
|
2481
|
-
}()));
|
|
2482
|
-
|
|
2483
|
-
case 3:
|
|
2484
|
-
results = _context3.sent;
|
|
2485
|
-
return _context3.abrupt("return", results.filter(function (x) {
|
|
2486
|
-
return x !== fail;
|
|
2487
|
-
}));
|
|
2488
|
-
|
|
2489
|
-
case 5:
|
|
2490
|
-
case "end":
|
|
2491
|
-
return _context3.stop();
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
}, _callee3);
|
|
2495
|
-
}));
|
|
2496
|
-
return _filter.apply(this, arguments);
|
|
2497
|
-
}
|
|
2498
|
-
|
|
2499
|
-
function useContentTypePermissions(props) {
|
|
2500
|
-
var availableContentTypes = useMemo(function () {
|
|
2501
|
-
if (props.entityType === 'Asset') {
|
|
2502
|
-
return [];
|
|
2503
|
-
}
|
|
2504
|
-
|
|
2505
|
-
if (props.validations.contentTypes) {
|
|
2506
|
-
return props.allContentTypes.filter(function (ct) {
|
|
2507
|
-
var _props$validations$co;
|
|
2508
|
-
|
|
2509
|
-
return (_props$validations$co = props.validations.contentTypes) == null ? void 0 : _props$validations$co.includes(ct.sys.id);
|
|
2510
|
-
});
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
return props.allContentTypes;
|
|
2514
|
-
}, [props.allContentTypes, props.validations.contentTypes, props.entityType]);
|
|
2515
|
-
|
|
2516
|
-
var _useState = useState(availableContentTypes),
|
|
2517
|
-
creatableContentTypes = _useState[0],
|
|
2518
|
-
setCreatableContentTypes = _useState[1];
|
|
2519
|
-
|
|
2520
|
-
var _useState2 = useState(availableContentTypes),
|
|
2521
|
-
readableContentTypes = _useState2[0],
|
|
2522
|
-
setReadableContentTypes = _useState2[1];
|
|
2523
|
-
|
|
2524
|
-
var _useAccessApi = useAccessApi(props.sdk.access),
|
|
2525
|
-
canPerformActionOnEntryOfType = _useAccessApi.canPerformActionOnEntryOfType;
|
|
2526
|
-
|
|
2527
|
-
useEffect(function () {
|
|
2528
|
-
function getContentTypes(action) {
|
|
2529
|
-
return filter(availableContentTypes, function (ct) {
|
|
2530
|
-
return canPerformActionOnEntryOfType(action, ct.sys.id);
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
|
-
|
|
2534
|
-
function checkContentTypeAccess() {
|
|
2535
|
-
return _checkContentTypeAccess.apply(this, arguments);
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
function _checkContentTypeAccess() {
|
|
2539
|
-
_checkContentTypeAccess = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
2540
|
-
var creatable, readable;
|
|
2541
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
2542
|
-
while (1) {
|
|
2543
|
-
switch (_context.prev = _context.next) {
|
|
2544
|
-
case 0:
|
|
2545
|
-
_context.next = 2;
|
|
2546
|
-
return getContentTypes('create');
|
|
2547
|
-
|
|
2548
|
-
case 2:
|
|
2549
|
-
creatable = _context.sent;
|
|
2550
|
-
_context.next = 5;
|
|
2551
|
-
return getContentTypes('read');
|
|
2552
|
-
|
|
2553
|
-
case 5:
|
|
2554
|
-
readable = _context.sent;
|
|
2555
|
-
setCreatableContentTypes(creatable);
|
|
2556
|
-
setReadableContentTypes(readable);
|
|
2557
|
-
|
|
2558
|
-
case 8:
|
|
2559
|
-
case "end":
|
|
2560
|
-
return _context.stop();
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
}, _callee);
|
|
2564
|
-
}));
|
|
2565
|
-
return _checkContentTypeAccess.apply(this, arguments);
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
void checkContentTypeAccess(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
2569
|
-
}, [availableContentTypes]);
|
|
2570
|
-
return {
|
|
2571
|
-
creatableContentTypes: creatableContentTypes,
|
|
2572
|
-
readableContentTypes: readableContentTypes,
|
|
2573
|
-
availableContentTypes: availableContentTypes
|
|
2574
|
-
};
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
|
-
function fromFieldValidations(field) {
|
|
2578
|
-
var _field$items$validati, _field$items, _linkContentTypeValid, _linkMimetypeGroupVal;
|
|
2579
|
-
|
|
2580
|
-
// eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
|
|
2581
|
-
var validations = [].concat(field.validations, (_field$items$validati = (_field$items = field.items) == null ? void 0 : _field$items.validations) != null ? _field$items$validati : []);
|
|
2582
|
-
var linkContentTypeValidations = validations.find(function (v) {
|
|
2583
|
-
return 'linkContentType' in v;
|
|
2584
|
-
});
|
|
2585
|
-
var linkMimetypeGroupValidations = validations.find(function (v) {
|
|
2586
|
-
return 'linkMimetypeGroup' in v;
|
|
2587
|
-
});
|
|
2588
|
-
var sizeValidations = validations.find(function (v) {
|
|
2589
|
-
return 'size' in v;
|
|
2590
|
-
});
|
|
2591
|
-
var size = sizeValidations && sizeValidations.size || {};
|
|
2592
|
-
var min = size.min;
|
|
2593
|
-
var max = size.max;
|
|
2594
|
-
var numberOfLinks = undefined;
|
|
2595
|
-
|
|
2596
|
-
if (isNumber(min) && isNumber(max)) {
|
|
2597
|
-
numberOfLinks = {
|
|
2598
|
-
type: 'min-max',
|
|
2599
|
-
min: min,
|
|
2600
|
-
max: max
|
|
2601
|
-
};
|
|
2602
|
-
} else if (isNumber(min)) {
|
|
2603
|
-
numberOfLinks = {
|
|
2604
|
-
type: 'min',
|
|
2605
|
-
min: min,
|
|
2606
|
-
max: undefined
|
|
2607
|
-
};
|
|
2608
|
-
} else if (isNumber(max)) {
|
|
2609
|
-
numberOfLinks = {
|
|
2610
|
-
type: 'max',
|
|
2611
|
-
max: max,
|
|
2612
|
-
min: undefined
|
|
2613
|
-
};
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
var result = {
|
|
2617
|
-
contentTypes: (_linkContentTypeValid = linkContentTypeValidations == null ? void 0 : linkContentTypeValidations.linkContentType) != null ? _linkContentTypeValid : undefined,
|
|
2618
|
-
mimetypeGroups: (_linkMimetypeGroupVal = linkMimetypeGroupValidations == null ? void 0 : linkMimetypeGroupValidations.linkMimetypeGroup) != null ? _linkMimetypeGroupVal : undefined,
|
|
2619
|
-
numberOfLinks: numberOfLinks // todo: there are multiple BE problems that need to be solved first, for now we don't want to apply size constraints
|
|
2620
|
-
// linkedFileSize: findValidation(field, 'assetFileSize', {}),
|
|
2621
|
-
// linkedImageDimensions: findValidation(field, 'assetImageDimensions', {})
|
|
2622
|
-
|
|
2623
|
-
};
|
|
2624
|
-
return result;
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
function useEditorPermissions(props) {
|
|
2628
|
-
var sdk = props.sdk,
|
|
2629
|
-
entityType = props.entityType,
|
|
2630
|
-
parameters = props.parameters;
|
|
2631
|
-
var validations = useMemo(function () {
|
|
2632
|
-
return fromFieldValidations(props.sdk.field);
|
|
2633
|
-
}, [props.sdk.field]);
|
|
2634
|
-
|
|
2635
|
-
var _useState = useState(true),
|
|
2636
|
-
canCreateEntity = _useState[0],
|
|
2637
|
-
setCanCreateEntity = _useState[1];
|
|
2638
|
-
|
|
2639
|
-
var _useState2 = useState(true),
|
|
2640
|
-
canLinkEntity = _useState2[0],
|
|
2641
|
-
setCanLinkEntity = _useState2[1];
|
|
2642
|
-
|
|
2643
|
-
var _useContentTypePermis = useContentTypePermissions(_extends({}, props, {
|
|
2644
|
-
validations: validations
|
|
2645
|
-
})),
|
|
2646
|
-
creatableContentTypes = _useContentTypePermis.creatableContentTypes,
|
|
2647
|
-
readableContentTypes = _useContentTypePermis.readableContentTypes,
|
|
2648
|
-
availableContentTypes = _useContentTypePermis.availableContentTypes;
|
|
2649
|
-
|
|
2650
|
-
var _useAccessApi = useAccessApi(sdk.access),
|
|
2651
|
-
canPerformAction = _useAccessApi.canPerformAction;
|
|
2652
|
-
|
|
2653
|
-
useEffect(function () {
|
|
2654
|
-
if (parameters.instance.showCreateEntityAction === false) {
|
|
2655
|
-
setCanCreateEntity(false);
|
|
2656
|
-
return;
|
|
2657
|
-
}
|
|
2658
|
-
|
|
2659
|
-
function checkCreateAccess() {
|
|
2660
|
-
return _checkCreateAccess.apply(this, arguments);
|
|
2661
|
-
}
|
|
2662
|
-
|
|
2663
|
-
function _checkCreateAccess() {
|
|
2664
|
-
_checkCreateAccess = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
2665
|
-
var canCreate, _canCreate;
|
|
2666
|
-
|
|
2667
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
2668
|
-
while (1) {
|
|
2669
|
-
switch (_context.prev = _context.next) {
|
|
2670
|
-
case 0:
|
|
2671
|
-
if (!(entityType === 'Asset')) {
|
|
2672
|
-
_context.next = 8;
|
|
2673
|
-
break;
|
|
2674
|
-
}
|
|
2675
|
-
|
|
2676
|
-
_context.next = 3;
|
|
2677
|
-
return canPerformAction('create', 'Asset');
|
|
2678
|
-
|
|
2679
|
-
case 3:
|
|
2680
|
-
_context.t0 = _context.sent;
|
|
2681
|
-
|
|
2682
|
-
if (_context.t0) {
|
|
2683
|
-
_context.next = 6;
|
|
2684
|
-
break;
|
|
2685
|
-
}
|
|
2686
|
-
|
|
2687
|
-
_context.t0 = true;
|
|
2688
|
-
|
|
2689
|
-
case 6:
|
|
2690
|
-
canCreate = _context.t0;
|
|
2691
|
-
setCanCreateEntity(canCreate);
|
|
2692
|
-
|
|
2693
|
-
case 8:
|
|
2694
|
-
if (entityType === 'Entry') {
|
|
2695
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
2696
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
2697
|
-
_canCreate = creatableContentTypes.length > 0 || true;
|
|
2698
|
-
setCanCreateEntity(_canCreate);
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
|
-
case 9:
|
|
2702
|
-
case "end":
|
|
2703
|
-
return _context.stop();
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
}, _callee);
|
|
2707
|
-
}));
|
|
2708
|
-
return _checkCreateAccess.apply(this, arguments);
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
void checkCreateAccess(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
2712
|
-
}, [entityType, parameters.instance, creatableContentTypes]);
|
|
2713
|
-
useEffect(function () {
|
|
2714
|
-
if (parameters.instance.showLinkEntityAction === false) {
|
|
2715
|
-
setCanLinkEntity(false);
|
|
2716
|
-
return;
|
|
2717
|
-
}
|
|
2718
|
-
|
|
2719
|
-
function checkLinkAccess() {
|
|
2720
|
-
return _checkLinkAccess.apply(this, arguments);
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
function _checkLinkAccess() {
|
|
2724
|
-
_checkLinkAccess = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
2725
|
-
var canRead, _canRead;
|
|
2726
|
-
|
|
2727
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2728
|
-
while (1) {
|
|
2729
|
-
switch (_context2.prev = _context2.next) {
|
|
2730
|
-
case 0:
|
|
2731
|
-
if (!(entityType === 'Asset')) {
|
|
2732
|
-
_context2.next = 8;
|
|
2733
|
-
break;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
_context2.next = 3;
|
|
2737
|
-
return canPerformAction('read', 'Asset');
|
|
2738
|
-
|
|
2739
|
-
case 3:
|
|
2740
|
-
_context2.t0 = _context2.sent;
|
|
2741
|
-
|
|
2742
|
-
if (_context2.t0) {
|
|
2743
|
-
_context2.next = 6;
|
|
2744
|
-
break;
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
_context2.t0 = true;
|
|
2748
|
-
|
|
2749
|
-
case 6:
|
|
2750
|
-
canRead = _context2.t0;
|
|
2751
|
-
setCanLinkEntity(canRead);
|
|
2752
|
-
|
|
2753
|
-
case 8:
|
|
2754
|
-
if (entityType === 'Entry') {
|
|
2755
|
-
// Hardcoded `true` value following https://contentful.atlassian.net/browse/DANTE-486
|
|
2756
|
-
// TODO: refine permissions check in order to account for tags in rules
|
|
2757
|
-
// TODO: always show every content type (it's just a filter) to avoid people not seeing
|
|
2758
|
-
// their (partly limited) content types
|
|
2759
|
-
_canRead = true;
|
|
2760
|
-
setCanLinkEntity(_canRead);
|
|
2761
|
-
}
|
|
2762
|
-
|
|
2763
|
-
case 9:
|
|
2764
|
-
case "end":
|
|
2765
|
-
return _context2.stop();
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
|
-
}, _callee2);
|
|
2769
|
-
}));
|
|
2770
|
-
return _checkLinkAccess.apply(this, arguments);
|
|
2771
|
-
}
|
|
2772
|
-
|
|
2773
|
-
void checkLinkAccess(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
2774
|
-
}, [entityType, parameters.instance, readableContentTypes]);
|
|
2775
|
-
return {
|
|
2776
|
-
canCreateEntity: canCreateEntity,
|
|
2777
|
-
canLinkEntity: canLinkEntity,
|
|
2778
|
-
creatableContentTypes: creatableContentTypes,
|
|
2779
|
-
readableContentTypes: readableContentTypes,
|
|
2780
|
-
availableContentTypes: availableContentTypes,
|
|
2781
|
-
validations: validations
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
function Editor(props) {
|
|
2786
|
-
var setValue = props.setValue,
|
|
2787
|
-
entityType = props.entityType;
|
|
2788
|
-
var editorPermissions = useEditorPermissions(props);
|
|
2789
|
-
var onCreate = useCallback(function (id) {
|
|
2790
|
-
return void setValue({
|
|
2791
|
-
sys: {
|
|
2792
|
-
type: 'Link',
|
|
2793
|
-
linkType: entityType,
|
|
2794
|
-
id: id
|
|
2795
|
-
}
|
|
2796
|
-
});
|
|
2797
|
-
}, [setValue, entityType]);
|
|
2798
|
-
var onLink = useCallback(function (ids) {
|
|
2799
|
-
var id = ids[0];
|
|
2800
|
-
setValue({
|
|
2801
|
-
sys: {
|
|
2802
|
-
type: 'Link',
|
|
2803
|
-
linkType: entityType,
|
|
2804
|
-
id: id
|
|
2805
|
-
}
|
|
2806
|
-
});
|
|
2807
|
-
}, [setValue, entityType]);
|
|
2808
|
-
var linkActionsProps = useLinkActionsProps(_extends({}, props, {
|
|
2809
|
-
canLinkMultiple: false,
|
|
2810
|
-
editorPermissions: editorPermissions,
|
|
2811
|
-
onCreate: onCreate,
|
|
2812
|
-
onLink: onLink
|
|
2813
|
-
})); // Inject card actions props into the given custom card renderer
|
|
2814
|
-
|
|
2815
|
-
var customCardRenderer = useCallback(function (cardProps, _, renderDefaultCard) {
|
|
2816
|
-
return props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false;
|
|
2817
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
2818
|
-
[linkActionsProps]);
|
|
2819
|
-
|
|
2820
|
-
if (!props.entityId) {
|
|
2821
|
-
return createElement(LinkEntityActions, _extends({
|
|
2822
|
-
renderCustomActions: props.renderCustomActions
|
|
2823
|
-
}, linkActionsProps));
|
|
2824
|
-
}
|
|
2825
|
-
|
|
2826
|
-
return props.children(_extends({}, props, {
|
|
2827
|
-
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
2828
|
-
}));
|
|
2829
|
-
}
|
|
2830
|
-
|
|
2831
|
-
function SingleReferenceEditor(props) {
|
|
2832
|
-
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
2833
|
-
return createElement(ReferenceEditor, _extends({}, props), function (_ref) {
|
|
2834
|
-
var value = _ref.value,
|
|
2835
|
-
setValue = _ref.setValue,
|
|
2836
|
-
disabled = _ref.disabled,
|
|
2837
|
-
externalReset = _ref.externalReset;
|
|
2838
|
-
return createElement(Editor, _extends({}, props, {
|
|
2839
|
-
key: externalReset + "-reference",
|
|
2840
|
-
entityId: value ? value.sys.id : '',
|
|
2841
|
-
isDisabled: disabled,
|
|
2842
|
-
setValue: setValue,
|
|
2843
|
-
allContentTypes: allContentTypes
|
|
2844
|
-
}));
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
SingleReferenceEditor.defaultProps = {
|
|
2848
|
-
hasCardEditActions: true,
|
|
2849
|
-
hasCardRemoveActions: true
|
|
2850
|
-
};
|
|
2851
|
-
|
|
2852
|
-
var styles$1 = {
|
|
2853
|
-
spaceIcon: /*#__PURE__*/css({
|
|
2854
|
-
flexShrink: 0,
|
|
2855
|
-
fill: tokens.purple600
|
|
2856
|
-
}),
|
|
2857
|
-
spaceName: /*#__PURE__*/css({
|
|
2858
|
-
color: tokens.gray700,
|
|
2859
|
-
fontSize: tokens.fontSizeS,
|
|
2860
|
-
fontWeight: tokens.fontWeightDemiBold,
|
|
2861
|
-
maxWidth: '80px',
|
|
2862
|
-
textOverflow: 'ellipsis',
|
|
2863
|
-
overflow: 'hidden',
|
|
2864
|
-
whiteSpace: 'nowrap'
|
|
2865
|
-
})
|
|
2866
|
-
};
|
|
2867
|
-
function SpaceName(props) {
|
|
2868
|
-
return createElement(Tooltip, {
|
|
2869
|
-
placement: "top",
|
|
2870
|
-
as: "div",
|
|
2871
|
-
content: "Space: " + props.spaceName
|
|
2872
|
-
}, createElement(Flex, {
|
|
2873
|
-
alignItems: "center",
|
|
2874
|
-
gap: "spacingXs",
|
|
2875
|
-
marginRight: "spacingS"
|
|
2876
|
-
}, createElement(FolderOpenTrimmedIcon, {
|
|
2877
|
-
className: styles$1.spaceIcon,
|
|
2878
|
-
size: "tiny",
|
|
2879
|
-
"aria-label": "Source space"
|
|
2880
|
-
}), createElement(Text, {
|
|
2881
|
-
className: styles$1.spaceName
|
|
2882
|
-
}, props.spaceName)));
|
|
2883
|
-
}
|
|
2884
|
-
|
|
2885
|
-
var getEntryTitle = entityHelpers.getEntryTitle,
|
|
2886
|
-
getEntityDescription = entityHelpers.getEntityDescription,
|
|
2887
|
-
getEntryStatus = entityHelpers.getEntryStatus,
|
|
2888
|
-
getEntryImage = entityHelpers.getEntryImage;
|
|
2889
|
-
var styles$2 = {
|
|
2890
|
-
scheduleIcon: /*#__PURE__*/css({
|
|
2891
|
-
marginRight: tokens.spacing2Xs
|
|
2892
|
-
})
|
|
2893
|
-
};
|
|
2894
|
-
var defaultProps = {
|
|
2895
|
-
isClickable: true,
|
|
2896
|
-
hasCardEditActions: true,
|
|
2897
|
-
hasCardMoveActions: true,
|
|
2898
|
-
hasCardRemoveActions: true
|
|
2899
|
-
};
|
|
2900
|
-
function WrappedEntryCard(props) {
|
|
2901
|
-
var _props$entry;
|
|
2902
|
-
|
|
2903
|
-
var _React$useState = useState(null),
|
|
2904
|
-
file = _React$useState[0],
|
|
2905
|
-
setFile = _React$useState[1];
|
|
2906
|
-
|
|
2907
|
-
var contentType = props.contentType;
|
|
2908
|
-
useEffect(function () {
|
|
2909
|
-
if (props.entry) {
|
|
2910
|
-
getEntryImage({
|
|
2911
|
-
entry: props.entry,
|
|
2912
|
-
contentType: contentType,
|
|
2913
|
-
localeCode: props.localeCode,
|
|
2914
|
-
defaultLocaleCode: props.defaultLocaleCode
|
|
2915
|
-
}, props.getAsset).then(function (file) {
|
|
2916
|
-
setFile(file);
|
|
2917
|
-
})["catch"](function () {
|
|
2918
|
-
setFile(null);
|
|
2919
|
-
});
|
|
2920
|
-
}
|
|
2921
|
-
}, [props.entry, props.getAsset, contentType, props.localeCode, props.defaultLocaleCode]);
|
|
2922
|
-
var status = getEntryStatus((_props$entry = props.entry) == null ? void 0 : _props$entry.sys);
|
|
2923
|
-
|
|
2924
|
-
if (status === 'deleted') {
|
|
2925
|
-
return createElement(MissingEntityCard, {
|
|
2926
|
-
entityType: "Entry",
|
|
2927
|
-
isDisabled: props.isDisabled,
|
|
2928
|
-
onRemove: props.onRemove
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
|
|
2932
|
-
var title = getEntryTitle({
|
|
2933
|
-
entry: props.entry,
|
|
2934
|
-
contentType: contentType,
|
|
2935
|
-
localeCode: props.localeCode,
|
|
2936
|
-
defaultLocaleCode: props.defaultLocaleCode,
|
|
2937
|
-
defaultTitle: 'Untitled'
|
|
2938
|
-
});
|
|
2939
|
-
var description = getEntityDescription({
|
|
2940
|
-
entity: props.entry,
|
|
2941
|
-
contentType: contentType,
|
|
2942
|
-
localeCode: props.localeCode,
|
|
2943
|
-
defaultLocaleCode: props.defaultLocaleCode
|
|
2944
|
-
});
|
|
2945
|
-
return createElement(EntryCard, {
|
|
2946
|
-
as: props.entryUrl ? 'a' : 'article',
|
|
2947
|
-
href: props.entryUrl,
|
|
2948
|
-
title: title,
|
|
2949
|
-
description: description,
|
|
2950
|
-
contentType: contentType == null ? void 0 : contentType.name,
|
|
2951
|
-
size: props.size,
|
|
2952
|
-
isSelected: props.isSelected,
|
|
2953
|
-
status: status,
|
|
2954
|
-
icon: props.spaceName ? createElement(SpaceName, {
|
|
2955
|
-
spaceName: props.spaceName
|
|
2956
|
-
}) : createElement(ScheduledIconWithTooltip, {
|
|
2957
|
-
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
2958
|
-
entityType: "Entry",
|
|
2959
|
-
entityId: props.entry.sys.id
|
|
2960
|
-
}, createElement(ClockIcon, {
|
|
2961
|
-
className: styles$2.scheduleIcon,
|
|
2962
|
-
size: "small",
|
|
2963
|
-
variant: "muted",
|
|
2964
|
-
testId: "schedule-icon"
|
|
2965
|
-
})),
|
|
2966
|
-
thumbnailElement: file && isValidImage(file) ? createElement(AssetThumbnail, {
|
|
2967
|
-
file: file
|
|
2968
|
-
}) : undefined,
|
|
2969
|
-
dragHandleRender: props.renderDragHandle,
|
|
2970
|
-
withDragHandle: !!props.renderDragHandle,
|
|
2971
|
-
actions: props.onEdit || props.onRemove ? [props.hasCardEditActions && props.onEdit ? createElement(MenuItem, {
|
|
2972
|
-
key: "edit",
|
|
2973
|
-
testId: "edit",
|
|
2974
|
-
onClick: function onClick() {
|
|
2975
|
-
props.onEdit && props.onEdit();
|
|
2976
|
-
}
|
|
2977
|
-
}, "Edit") : null, props.hasCardRemoveActions && props.onRemove ? createElement(MenuItem, {
|
|
2978
|
-
key: "delete",
|
|
2979
|
-
testId: "delete",
|
|
2980
|
-
onClick: function onClick() {
|
|
2981
|
-
props.onRemove && props.onRemove();
|
|
2982
|
-
}
|
|
2983
|
-
}, "Remove") : null, props.hasCardMoveActions && (props.onMoveTop || props.onMoveBottom) ? createElement(MenuDivider, {
|
|
2984
|
-
key: "divider"
|
|
2985
|
-
}) : null, props.hasCardMoveActions && props.onMoveTop ? createElement(MenuItem, {
|
|
2986
|
-
key: "move-top",
|
|
2987
|
-
onClick: function onClick() {
|
|
2988
|
-
return props.onMoveTop && props.onMoveTop();
|
|
2989
|
-
},
|
|
2990
|
-
testId: "move-top"
|
|
2991
|
-
}, "Move to top") : null, props.hasCardMoveActions && props.onMoveBottom ? createElement(MenuItem, {
|
|
2992
|
-
key: "move-bottom",
|
|
2993
|
-
onClick: function onClick() {
|
|
2994
|
-
return props.onMoveBottom && props.onMoveBottom();
|
|
2995
|
-
},
|
|
2996
|
-
testId: "move-bottom"
|
|
2997
|
-
}, "Move to bottom") : null].filter(function (item) {
|
|
2998
|
-
return item;
|
|
2999
|
-
}) : [],
|
|
3000
|
-
onClick: // Providing an onClick handler messes up with some rich text
|
|
3001
|
-
// features e.g. pressing ENTER on a card to add a new paragraph
|
|
3002
|
-
// underneath. It's crucial not to pass a custom handler when
|
|
3003
|
-
// isClickable is disabled which in the case of RT it's.
|
|
3004
|
-
props.isClickable ? function (e) {
|
|
3005
|
-
e.preventDefault();
|
|
3006
|
-
if (props.onClick) return props.onClick(e);
|
|
3007
|
-
props.onEdit && props.onEdit();
|
|
3008
|
-
} : undefined
|
|
3009
|
-
});
|
|
3010
|
-
}
|
|
3011
|
-
WrappedEntryCard.defaultProps = defaultProps;
|
|
3012
|
-
|
|
3013
|
-
function openEntry(_x, _x2, _x3) {
|
|
3014
|
-
return _openEntry.apply(this, arguments);
|
|
3015
|
-
}
|
|
3016
|
-
|
|
3017
|
-
function _openEntry() {
|
|
3018
|
-
_openEntry = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(sdk, entryId, options) {
|
|
3019
|
-
var slide, _options$index, _result, result;
|
|
3020
|
-
|
|
3021
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
3022
|
-
while (1) {
|
|
3023
|
-
switch (_context2.prev = _context2.next) {
|
|
3024
|
-
case 0:
|
|
3025
|
-
if (!options.bulkEditing) {
|
|
3026
|
-
_context2.next = 11;
|
|
3027
|
-
break;
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
_context2.prev = 1;
|
|
3031
|
-
_context2.next = 4;
|
|
3032
|
-
return sdk.navigator.openBulkEditor(sdk.entry.getSys().id, {
|
|
3033
|
-
fieldId: sdk.field.id,
|
|
3034
|
-
locale: sdk.field.locale,
|
|
3035
|
-
index: (_options$index = options.index) != null ? _options$index : 0
|
|
3036
|
-
});
|
|
3037
|
-
|
|
3038
|
-
case 4:
|
|
3039
|
-
_result = _context2.sent;
|
|
3040
|
-
slide = _result.slide;
|
|
3041
|
-
return _context2.abrupt("return", slide);
|
|
3042
|
-
|
|
3043
|
-
case 9:
|
|
3044
|
-
_context2.prev = 9;
|
|
3045
|
-
_context2.t0 = _context2["catch"](1);
|
|
3046
|
-
|
|
3047
|
-
case 11:
|
|
3048
|
-
_context2.next = 13;
|
|
3049
|
-
return sdk.navigator.openEntry(entryId, {
|
|
3050
|
-
slideIn: true
|
|
3051
|
-
});
|
|
3052
|
-
|
|
3053
|
-
case 13:
|
|
3054
|
-
result = _context2.sent;
|
|
3055
|
-
slide = result.slide;
|
|
3056
|
-
return _context2.abrupt("return", slide);
|
|
3057
|
-
|
|
3058
|
-
case 16:
|
|
3059
|
-
case "end":
|
|
3060
|
-
return _context2.stop();
|
|
3061
|
-
}
|
|
3062
|
-
}
|
|
3063
|
-
}, _callee2, null, [[1, 9]]);
|
|
3064
|
-
}));
|
|
3065
|
-
return _openEntry.apply(this, arguments);
|
|
3066
|
-
}
|
|
3067
|
-
|
|
3068
|
-
function FetchingWrappedEntryCard(props) {
|
|
3069
|
-
var _useEntity = useEntity('Entry', props.entryId),
|
|
3070
|
-
entry = _useEntity.data,
|
|
3071
|
-
status = _useEntity.status;
|
|
3072
|
-
|
|
3073
|
-
var _useEntityLoader = useEntityLoader(),
|
|
3074
|
-
getEntityScheduledActions = _useEntityLoader.getEntityScheduledActions;
|
|
3075
|
-
|
|
3076
|
-
var loadEntityScheduledActions = useCallback(function () {
|
|
3077
|
-
return getEntityScheduledActions('Entry', props.entryId);
|
|
3078
|
-
}, [getEntityScheduledActions, props.entryId]);
|
|
3079
|
-
var size = props.viewType === 'link' ? 'small' : 'default';
|
|
3080
|
-
|
|
3081
|
-
var _useEntityLoader2 = useEntityLoader(),
|
|
3082
|
-
getEntity = _useEntityLoader2.getEntity;
|
|
3083
|
-
|
|
3084
|
-
var getAsset = function getAsset(assetId) {
|
|
3085
|
-
return getEntity('Asset', assetId);
|
|
3086
|
-
};
|
|
3087
|
-
|
|
3088
|
-
var onEdit = /*#__PURE__*/function () {
|
|
3089
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
3090
|
-
var slide;
|
|
3091
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
3092
|
-
while (1) {
|
|
3093
|
-
switch (_context.prev = _context.next) {
|
|
3094
|
-
case 0:
|
|
3095
|
-
_context.next = 2;
|
|
3096
|
-
return openEntry(props.sdk, props.entryId, {
|
|
3097
|
-
bulkEditing: props.parameters.instance.bulkEditing,
|
|
3098
|
-
index: props.index
|
|
3099
|
-
});
|
|
3100
|
-
|
|
3101
|
-
case 2:
|
|
3102
|
-
slide = _context.sent;
|
|
3103
|
-
props.onAction && props.onAction({
|
|
3104
|
-
entity: 'Entry',
|
|
3105
|
-
type: 'edit',
|
|
3106
|
-
id: props.entryId,
|
|
3107
|
-
contentTypeId: get(entry, 'sys.contentType.sys.id'),
|
|
3108
|
-
slide: slide
|
|
3109
|
-
});
|
|
3110
|
-
|
|
3111
|
-
case 4:
|
|
3112
|
-
case "end":
|
|
3113
|
-
return _context.stop();
|
|
3114
|
-
}
|
|
3115
|
-
}
|
|
3116
|
-
}, _callee);
|
|
3117
|
-
}));
|
|
3118
|
-
|
|
3119
|
-
return function onEdit() {
|
|
3120
|
-
return _ref.apply(this, arguments);
|
|
3121
|
-
};
|
|
3122
|
-
}();
|
|
3123
|
-
|
|
3124
|
-
var onRemoveEntry = function onRemoveEntry() {
|
|
3125
|
-
props.onRemove();
|
|
3126
|
-
props.onAction && props.onAction({
|
|
3127
|
-
entity: 'Entry',
|
|
3128
|
-
type: 'delete',
|
|
3129
|
-
id: props.entryId,
|
|
3130
|
-
contentTypeId: get(entry, 'sys.contentType.sys.id')
|
|
3131
|
-
});
|
|
3132
|
-
};
|
|
3133
|
-
|
|
3134
|
-
useEffect(function () {
|
|
3135
|
-
if (entry) {
|
|
3136
|
-
props.onAction && props.onAction({
|
|
3137
|
-
type: 'rendered',
|
|
3138
|
-
entity: 'Entry'
|
|
3139
|
-
});
|
|
3140
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3141
|
-
|
|
3142
|
-
}, [entry]);
|
|
3143
|
-
return useMemo(function () {
|
|
3144
|
-
if (status === 'error') {
|
|
3145
|
-
var card = createElement(MissingEntityCard, {
|
|
3146
|
-
entityType: "Entry",
|
|
3147
|
-
isDisabled: props.isDisabled,
|
|
3148
|
-
onRemove: onRemoveEntry
|
|
3149
|
-
});
|
|
3150
|
-
|
|
3151
|
-
if (props.renderCustomMissingEntityCard) {
|
|
3152
|
-
return props.renderCustomMissingEntityCard({
|
|
3153
|
-
defaultCard: card,
|
|
3154
|
-
entity: {
|
|
3155
|
-
id: props.entryId,
|
|
3156
|
-
type: 'Entry'
|
|
3157
|
-
}
|
|
3158
|
-
});
|
|
3159
|
-
}
|
|
3160
|
-
|
|
3161
|
-
return card;
|
|
3162
|
-
}
|
|
3163
|
-
|
|
3164
|
-
if (status === 'loading') {
|
|
3165
|
-
return createElement(EntryCard, {
|
|
3166
|
-
size: size,
|
|
3167
|
-
isLoading: true
|
|
3168
|
-
});
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3171
|
-
var sharedCardProps = {
|
|
3172
|
-
index: props.index,
|
|
3173
|
-
entity: entry,
|
|
3174
|
-
entityUrl: props.getEntityUrl && props.getEntityUrl(entry.sys.id),
|
|
3175
|
-
contentType: props.allContentTypes.find(function (contentType) {
|
|
3176
|
-
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
3177
|
-
}),
|
|
3178
|
-
isDisabled: props.isDisabled,
|
|
3179
|
-
size: size,
|
|
3180
|
-
localeCode: props.sdk.field.locale,
|
|
3181
|
-
defaultLocaleCode: props.sdk.locales["default"],
|
|
3182
|
-
renderDragHandle: props.renderDragHandle,
|
|
3183
|
-
onEdit: onEdit,
|
|
3184
|
-
onRemove: onRemoveEntry,
|
|
3185
|
-
onMoveTop: props.onMoveTop,
|
|
3186
|
-
onMoveBottom: props.onMoveBottom,
|
|
3187
|
-
isBeingDragged: props.isBeingDragged
|
|
3188
|
-
};
|
|
3189
|
-
var hasCardEditActions = props.hasCardEditActions,
|
|
3190
|
-
hasCardMoveActions = props.hasCardMoveActions,
|
|
3191
|
-
hasCardRemoveActions = props.hasCardRemoveActions;
|
|
3192
|
-
|
|
3193
|
-
function renderDefaultCard(props) {
|
|
3194
|
-
var builtinCardProps = _extends({}, sharedCardProps, props, {
|
|
3195
|
-
hasCardEditActions: hasCardEditActions,
|
|
3196
|
-
hasCardMoveActions: hasCardMoveActions,
|
|
3197
|
-
hasCardRemoveActions: hasCardRemoveActions,
|
|
3198
|
-
getAsset: getAsset,
|
|
3199
|
-
getEntityScheduledActions: loadEntityScheduledActions,
|
|
3200
|
-
entry: (props == null ? void 0 : props.entity) || sharedCardProps.entity,
|
|
3201
|
-
entryUrl: (props == null ? void 0 : props.entityUrl) || sharedCardProps.entityUrl
|
|
3202
|
-
});
|
|
3203
|
-
|
|
3204
|
-
return createElement(WrappedEntryCard, _extends({}, builtinCardProps));
|
|
3205
|
-
}
|
|
3206
|
-
|
|
3207
|
-
if (props.renderCustomCard) {
|
|
3208
|
-
// LinkActionsProps are injected higher SingleReferenceEditor/MultipleReferenceEditor
|
|
3209
|
-
var renderedCustomCard = props.renderCustomCard(sharedCardProps, {}, renderDefaultCard); // Only `false` indicates to render the original card. E.g. `null` would result in no card.
|
|
3210
|
-
|
|
3211
|
-
if (renderedCustomCard !== false) {
|
|
3212
|
-
return renderedCustomCard;
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
|
|
3216
|
-
return renderDefaultCard(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3217
|
-
}, [props, status, entry]);
|
|
3218
|
-
}
|
|
3219
|
-
|
|
3220
|
-
function SingleEntryReferenceEditor(props) {
|
|
3221
|
-
return createElement(SingleReferenceEditor, _extends({}, props, {
|
|
3222
|
-
entityType: "Entry"
|
|
3223
|
-
}), function (_ref) {
|
|
3224
|
-
var allContentTypes = _ref.allContentTypes,
|
|
3225
|
-
isDisabled = _ref.isDisabled,
|
|
3226
|
-
entityId = _ref.entityId,
|
|
3227
|
-
setValue = _ref.setValue,
|
|
3228
|
-
renderCustomCard = _ref.renderCustomCard,
|
|
3229
|
-
hasCardRemoveActions = _ref.hasCardRemoveActions,
|
|
3230
|
-
hasCardEditActions = _ref.hasCardEditActions;
|
|
3231
|
-
return createElement(FetchingWrappedEntryCard, _extends({}, props, {
|
|
3232
|
-
allContentTypes: allContentTypes,
|
|
3233
|
-
isDisabled: isDisabled,
|
|
3234
|
-
entryId: entityId,
|
|
3235
|
-
renderCustomCard: renderCustomCard,
|
|
3236
|
-
hasCardEditActions: hasCardEditActions,
|
|
3237
|
-
hasCardRemoveActions: hasCardRemoveActions,
|
|
3238
|
-
onRemove: function onRemove() {
|
|
3239
|
-
setValue(null);
|
|
3240
|
-
}
|
|
3241
|
-
}));
|
|
3242
|
-
});
|
|
3243
|
-
}
|
|
3244
|
-
SingleEntryReferenceEditor.defaultProps = {
|
|
3245
|
-
isInitiallyDisabled: true
|
|
3246
|
-
};
|
|
3247
|
-
|
|
3248
|
-
function onLinkOrCreate(setValue, entityType, items, ids, index) {
|
|
3249
|
-
if (index === void 0) {
|
|
3250
|
-
index = items.length;
|
|
3251
|
-
}
|
|
3252
|
-
|
|
3253
|
-
var links = ids.map(function (id) {
|
|
3254
|
-
return {
|
|
3255
|
-
sys: {
|
|
3256
|
-
type: 'Link',
|
|
3257
|
-
linkType: entityType,
|
|
3258
|
-
id: id
|
|
3259
|
-
}
|
|
3260
|
-
};
|
|
3261
|
-
});
|
|
3262
|
-
var newItems = Array.from(items);
|
|
3263
|
-
newItems.splice.apply(newItems, [index, 0].concat(links));
|
|
3264
|
-
setValue(newItems);
|
|
3265
|
-
}
|
|
3266
|
-
|
|
3267
|
-
var emptyArray = [];
|
|
3268
|
-
var nullableValue = {
|
|
3269
|
-
sys: {
|
|
3270
|
-
id: 'null-value'
|
|
3271
|
-
}
|
|
3272
|
-
};
|
|
3273
|
-
|
|
3274
|
-
function Editor$1(props) {
|
|
3275
|
-
var setValue = props.setValue,
|
|
3276
|
-
entityType = props.entityType,
|
|
3277
|
-
setIndexToUpdate = props.setIndexToUpdate;
|
|
3278
|
-
var editorPermissions = useEditorPermissions(props);
|
|
3279
|
-
var items = useMemo(function () {
|
|
3280
|
-
return (props.items || []). // If null values have found their way into the persisted
|
|
3281
|
-
// value for the multiref field, replace them with an object
|
|
3282
|
-
// that has the shape of a Link to make the missing entry/asset
|
|
3283
|
-
// card render
|
|
3284
|
-
map(function (link) {
|
|
3285
|
-
return link || nullableValue;
|
|
3286
|
-
});
|
|
3287
|
-
}, [props.items]);
|
|
3288
|
-
var onSortStart = useCallback(function (_, event) {
|
|
3289
|
-
if (event instanceof MouseEvent) {
|
|
3290
|
-
document.body.classList.add('grabbing');
|
|
3291
|
-
}
|
|
3292
|
-
|
|
3293
|
-
event.preventDefault();
|
|
3294
|
-
}, []);
|
|
3295
|
-
var onSortEnd = useCallback(function (_ref) {
|
|
3296
|
-
var oldIndex = _ref.oldIndex,
|
|
3297
|
-
newIndex = _ref.newIndex;
|
|
3298
|
-
// custom callback that is invoked *before* we sort the array
|
|
3299
|
-
// e.g. in Compose we want to sort the references in the referenceMap before re-rendering drag and drop
|
|
3300
|
-
props.onSortingEnd && props.onSortingEnd({
|
|
3301
|
-
oldIndex: oldIndex,
|
|
3302
|
-
newIndex: newIndex
|
|
3303
|
-
});
|
|
3304
|
-
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
3305
|
-
setValue(newItems);
|
|
3306
|
-
setIndexToUpdate && setIndexToUpdate(undefined);
|
|
3307
|
-
document.body.classList.remove('grabbing');
|
|
3308
|
-
}, [items, props, setIndexToUpdate, setValue]);
|
|
3309
|
-
var onMove = useCallback(function (oldIndex, newIndex) {
|
|
3310
|
-
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
3311
|
-
setValue(newItems);
|
|
3312
|
-
}, [items, setValue]);
|
|
3313
|
-
var onCreate = useCallback(function (id, index) {
|
|
3314
|
-
return onLinkOrCreate(setValue, entityType, items, [id], index);
|
|
3315
|
-
}, [setValue, items, entityType]);
|
|
3316
|
-
var onLink = useCallback(function (ids, index) {
|
|
3317
|
-
return onLinkOrCreate(setValue, entityType, items, ids, index);
|
|
3318
|
-
}, [setValue, items, entityType]);
|
|
3319
|
-
var linkActionsProps = useLinkActionsProps(_extends({}, props, {
|
|
3320
|
-
canLinkMultiple: true,
|
|
3321
|
-
editorPermissions: editorPermissions,
|
|
3322
|
-
onCreate: onCreate,
|
|
3323
|
-
onLink: onLink,
|
|
3324
|
-
itemsLength: items.length
|
|
3325
|
-
}));
|
|
3326
|
-
var customCardRenderer = useCallback(function (cardProps, _, renderDefaultCard) {
|
|
3327
|
-
return props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false;
|
|
3328
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3329
|
-
[linkActionsProps]);
|
|
3330
|
-
return createElement(Fragment, null, props.children(_extends({}, props, {
|
|
3331
|
-
onSortStart: onSortStart,
|
|
3332
|
-
onSortEnd: onSortEnd,
|
|
3333
|
-
onMove: onMove,
|
|
3334
|
-
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
3335
|
-
})), createElement(LinkEntityActions, _extends({
|
|
3336
|
-
renderCustomActions: props.renderCustomActions
|
|
3337
|
-
}, linkActionsProps)));
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3340
|
-
function MultipleReferenceEditor(props) {
|
|
3341
|
-
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
3342
|
-
return createElement(ReferenceEditor, _extends({}, props), function (_ref2) {
|
|
3343
|
-
var value = _ref2.value,
|
|
3344
|
-
disabled = _ref2.disabled,
|
|
3345
|
-
setValue = _ref2.setValue,
|
|
3346
|
-
externalReset = _ref2.externalReset;
|
|
3347
|
-
return createElement(Editor$1, _extends({}, props, {
|
|
3348
|
-
items: value || emptyArray,
|
|
3349
|
-
isDisabled: disabled,
|
|
3350
|
-
setValue: setValue,
|
|
3351
|
-
key: externalReset + "-list",
|
|
3352
|
-
allContentTypes: allContentTypes
|
|
3353
|
-
}));
|
|
3354
|
-
});
|
|
3355
|
-
}
|
|
3356
|
-
MultipleReferenceEditor.defaultProps = {
|
|
3357
|
-
hasCardEditActions: true
|
|
3358
|
-
};
|
|
3359
|
-
|
|
3360
|
-
var styles$3 = {
|
|
3361
|
-
container: /*#__PURE__*/css({
|
|
3362
|
-
position: 'relative'
|
|
3363
|
-
}),
|
|
3364
|
-
item: /*#__PURE__*/css({
|
|
3365
|
-
marginBottom: tokens.spacingM,
|
|
3366
|
-
zIndex: tokens.zIndexModal // setting this to an index above 99 fixes dragged item disappearing issue. Should not be higher than 100 so it does not overlap the asset modal.
|
|
3367
|
-
|
|
3368
|
-
})
|
|
3369
|
-
};
|
|
3370
|
-
|
|
3371
|
-
var DragHandle = function DragHandle(props) {
|
|
3372
|
-
var SortableDragHandle = SortableHandle(function () {
|
|
3373
|
-
return props.drag;
|
|
3374
|
-
});
|
|
3375
|
-
return React__default.createElement(SortableDragHandle, null);
|
|
3376
|
-
};
|
|
3377
|
-
|
|
3378
|
-
var SortableLink = /*#__PURE__*/SortableElement(function (props) {
|
|
3379
|
-
return React__default.createElement("div", {
|
|
3380
|
-
className: styles$3.item
|
|
3381
|
-
}, props.children);
|
|
3382
|
-
});
|
|
3383
|
-
var SortableLinkListInternal = /*#__PURE__*/SortableContainer(function (props) {
|
|
3384
|
-
return React__default.createElement("div", {
|
|
3385
|
-
className: cx(styles$3.container, props.className)
|
|
3386
|
-
}, props.items.map(function (item, index) {
|
|
3387
|
-
var _item$sys$urn;
|
|
3388
|
-
|
|
3389
|
-
return React__default.createElement(SortableLink, {
|
|
3390
|
-
disabled: props.isDisabled,
|
|
3391
|
-
key: ((_item$sys$urn = item.sys.urn) != null ? _item$sys$urn : item.sys.id) + "-" + index,
|
|
3392
|
-
index: index
|
|
3393
|
-
}, props.children({
|
|
3394
|
-
items: props.items,
|
|
3395
|
-
isDisabled: props.isDisabled,
|
|
3396
|
-
item: item,
|
|
3397
|
-
index: index,
|
|
3398
|
-
DragHandle: props.isDisabled ? undefined : DragHandle
|
|
3399
|
-
}));
|
|
3400
|
-
}));
|
|
3401
|
-
}); // HOC does not support generics, so we mimic it via additional component
|
|
3402
|
-
|
|
3403
|
-
function SortableLinkList(props) {
|
|
3404
|
-
// with the default distance of 0 the drag start event is "confused" with the click event,
|
|
3405
|
-
// so the latter one isn't fired and click handlers on child elements don't work
|
|
3406
|
-
return React__default.createElement(SortableLinkListInternal, _extends({
|
|
3407
|
-
distance: 1
|
|
3408
|
-
}, props), props.children);
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
function MultipleEntryReferenceEditor(props) {
|
|
3412
|
-
var _React$useState = useState(undefined),
|
|
3413
|
-
indexToUpdate = _React$useState[0],
|
|
3414
|
-
setIndexToUpdate = _React$useState[1];
|
|
3415
|
-
|
|
3416
|
-
var updateBeforeSortStart = function updateBeforeSortStart(_ref) {
|
|
3417
|
-
var index = _ref.index;
|
|
3418
|
-
setIndexToUpdate(index);
|
|
3419
|
-
};
|
|
3420
|
-
|
|
3421
|
-
return createElement(MultipleReferenceEditor, _extends({}, props, {
|
|
3422
|
-
entityType: "Entry",
|
|
3423
|
-
setIndexToUpdate: setIndexToUpdate
|
|
3424
|
-
}), function (childrenProps) {
|
|
3425
|
-
return createElement(SortableLinkList, _extends({}, childrenProps, {
|
|
3426
|
-
axis: "y",
|
|
3427
|
-
useDragHandle: true,
|
|
3428
|
-
updateBeforeSortStart: updateBeforeSortStart
|
|
3429
|
-
}), function (_ref2) {
|
|
3430
|
-
var items = _ref2.items,
|
|
3431
|
-
item = _ref2.item,
|
|
3432
|
-
index = _ref2.index,
|
|
3433
|
-
isDisabled = _ref2.isDisabled,
|
|
3434
|
-
DragHandle = _ref2.DragHandle;
|
|
3435
|
-
var lastIndex = items.length - 1;
|
|
3436
|
-
return createElement(FetchingWrappedEntryCard, _extends({}, childrenProps, {
|
|
3437
|
-
key: item.sys.id + "-" + index,
|
|
3438
|
-
index: index,
|
|
3439
|
-
allContentTypes: childrenProps.allContentTypes,
|
|
3440
|
-
isDisabled: isDisabled,
|
|
3441
|
-
entryId: item.sys.id,
|
|
3442
|
-
onRemove: function onRemove() {
|
|
3443
|
-
childrenProps.setValue(items.filter(function (_value, i) {
|
|
3444
|
-
return i !== index;
|
|
3445
|
-
}));
|
|
3446
|
-
},
|
|
3447
|
-
onMoveTop: index !== 0 ? function () {
|
|
3448
|
-
return childrenProps.onMove(index, 0);
|
|
3449
|
-
} : undefined,
|
|
3450
|
-
onMoveBottom: index !== lastIndex ? function () {
|
|
3451
|
-
return childrenProps.onMove(index, lastIndex);
|
|
3452
|
-
} : undefined,
|
|
3453
|
-
renderDragHandle: DragHandle,
|
|
3454
|
-
isBeingDragged: index === indexToUpdate
|
|
3455
|
-
}));
|
|
3456
|
-
});
|
|
3457
|
-
});
|
|
3458
|
-
}
|
|
3459
|
-
|
|
3460
|
-
function downloadAsset(url) {
|
|
3461
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
3462
|
-
}
|
|
3463
|
-
|
|
3464
|
-
function renderAssetInfo(props) {
|
|
3465
|
-
var entityFile = props.entityFile;
|
|
3466
|
-
var fileName = get(entityFile, 'fileName');
|
|
3467
|
-
var mimeType = get(entityFile, 'contentType');
|
|
3468
|
-
var fileSize = get(entityFile, 'details.size');
|
|
3469
|
-
var image = get(entityFile, 'details.image');
|
|
3470
|
-
return [React__default.createElement(Menu.SectionTitle, {
|
|
3471
|
-
key: "file-section"
|
|
3472
|
-
}, "File info"), fileName && React__default.createElement(Menu.Item, {
|
|
3473
|
-
key: "file-name"
|
|
3474
|
-
}, React__default.createElement(Text, {
|
|
3475
|
-
isTruncated: true
|
|
3476
|
-
}, fileName)), mimeType && React__default.createElement(Menu.Item, {
|
|
3477
|
-
key: "file-type"
|
|
3478
|
-
}, React__default.createElement(Text, {
|
|
3479
|
-
isTruncated: true
|
|
3480
|
-
}, mimeType)), fileSize && React__default.createElement(Menu.Item, {
|
|
3481
|
-
key: "file-size"
|
|
3482
|
-
}, shortenStorageUnit(fileSize, 'B')), image && React__default.createElement(Menu.Item, {
|
|
3483
|
-
key: "file-dimentions"
|
|
3484
|
-
}, image.width + " \xD7 " + image.height)].filter(function (item) {
|
|
3485
|
-
return item;
|
|
3486
|
-
});
|
|
3487
|
-
}
|
|
3488
|
-
function renderActions(props) {
|
|
3489
|
-
var entityFile = props.entityFile,
|
|
3490
|
-
isDisabled = props.isDisabled,
|
|
3491
|
-
onEdit = props.onEdit,
|
|
3492
|
-
onRemove = props.onRemove;
|
|
3493
|
-
return [React__default.createElement(Menu.SectionTitle, {
|
|
3494
|
-
key: "section-title"
|
|
3495
|
-
}, "Actions"), onEdit ? React__default.createElement(Menu.Item, {
|
|
3496
|
-
key: "edit",
|
|
3497
|
-
onClick: onEdit,
|
|
3498
|
-
testId: "card-action-edit"
|
|
3499
|
-
}, "Edit") : null, entityFile ? React__default.createElement(Menu.Item, {
|
|
3500
|
-
key: "download",
|
|
3501
|
-
onClick: function onClick() {
|
|
3502
|
-
if (typeof entityFile.url === 'string') {
|
|
3503
|
-
downloadAsset(entityFile.url);
|
|
3504
|
-
}
|
|
3505
|
-
},
|
|
3506
|
-
testId: "card-action-download"
|
|
3507
|
-
}, "Download") : null, onRemove ? React__default.createElement(Menu.Item, {
|
|
3508
|
-
key: "remove",
|
|
3509
|
-
disabled: isDisabled,
|
|
3510
|
-
onClick: onRemove,
|
|
3511
|
-
testId: "card-action-remove"
|
|
3512
|
-
}, "Remove") : null].filter(function (item) {
|
|
3513
|
-
return item;
|
|
3514
|
-
});
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
var groupToIconMap = {
|
|
3518
|
-
image: 'image',
|
|
3519
|
-
video: 'video',
|
|
3520
|
-
audio: 'audio',
|
|
3521
|
-
richtext: 'richtext',
|
|
3522
|
-
presentation: 'presentation',
|
|
3523
|
-
spreadsheet: 'spreadsheet',
|
|
3524
|
-
pdfdocument: 'pdf',
|
|
3525
|
-
archive: 'archive',
|
|
3526
|
-
plaintext: 'plaintext',
|
|
3527
|
-
code: 'code',
|
|
3528
|
-
markup: 'markup'
|
|
3529
|
-
};
|
|
3530
|
-
var styles$4 = {
|
|
3531
|
-
scheduleIcon: /*#__PURE__*/css({
|
|
3532
|
-
marginRight: tokens.spacing2Xs
|
|
3533
|
-
})
|
|
3534
|
-
};
|
|
3535
|
-
var defaultProps$1 = {
|
|
3536
|
-
isClickable: true
|
|
3537
|
-
}; // eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
|
|
3538
|
-
|
|
3539
|
-
function getFileType(file) {
|
|
3540
|
-
if (!file) {
|
|
3541
|
-
return 'archive';
|
|
3542
|
-
}
|
|
3543
|
-
|
|
3544
|
-
var groupName = mimetype.getGroupLabel({
|
|
3545
|
-
type: file.contentType,
|
|
3546
|
-
fallbackFileName: file.fileName
|
|
3547
|
-
});
|
|
3548
|
-
return groupToIconMap[groupName] || 'archive';
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3551
|
-
var WrappedAssetCard = function WrappedAssetCard(props) {
|
|
3552
|
-
var className = props.className,
|
|
3553
|
-
onEdit = props.onEdit,
|
|
3554
|
-
getAssetUrl = props.getAssetUrl,
|
|
3555
|
-
onRemove = props.onRemove,
|
|
3556
|
-
size = props.size,
|
|
3557
|
-
isDisabled = props.isDisabled,
|
|
3558
|
-
isSelected = props.isSelected,
|
|
3559
|
-
isClickable = props.isClickable;
|
|
3560
|
-
var status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
3561
|
-
|
|
3562
|
-
if (status === 'deleted') {
|
|
3563
|
-
return React__default.createElement(MissingEntityCard, {
|
|
3564
|
-
entityType: "Asset",
|
|
3565
|
-
asSquare: true,
|
|
3566
|
-
isDisabled: props.isDisabled,
|
|
3567
|
-
onRemove: props.onRemove
|
|
3568
|
-
});
|
|
3569
|
-
}
|
|
3570
|
-
|
|
3571
|
-
var entityTitle = entityHelpers.getAssetTitle({
|
|
3572
|
-
asset: props.asset,
|
|
3573
|
-
localeCode: props.localeCode,
|
|
3574
|
-
defaultLocaleCode: props.defaultLocaleCode,
|
|
3575
|
-
defaultTitle: 'Untitled'
|
|
3576
|
-
});
|
|
3577
|
-
var entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
3578
|
-
var href = getAssetUrl ? getAssetUrl(props.asset.sys.id) : undefined;
|
|
3579
|
-
return React__default.createElement(AssetCard, {
|
|
3580
|
-
as: href ? 'a' : 'article',
|
|
3581
|
-
type: getFileType(entityFile),
|
|
3582
|
-
title: entityTitle,
|
|
3583
|
-
className: className,
|
|
3584
|
-
isSelected: isSelected,
|
|
3585
|
-
href: href,
|
|
3586
|
-
status: status,
|
|
3587
|
-
icon: React__default.createElement(ScheduledIconWithTooltip, {
|
|
3588
|
-
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
3589
|
-
entityType: "Asset",
|
|
3590
|
-
entityId: props.asset.sys.id
|
|
3591
|
-
}, React__default.createElement(ClockIcon, {
|
|
3592
|
-
className: styles$4.scheduleIcon,
|
|
3593
|
-
size: "small",
|
|
3594
|
-
variant: "muted",
|
|
3595
|
-
testId: "schedule-icon"
|
|
3596
|
-
})),
|
|
3597
|
-
src: entityFile && entityFile.url ? size === 'small' ? entityFile.url + "?w=150&h=150&fit=thumb" : entityFile.url + "?h=300" : '',
|
|
3598
|
-
onClick: // Providing an onClick handler messes up with some rich text
|
|
3599
|
-
// features e.g. pressing ENTER on a card to add a new paragraph
|
|
3600
|
-
// underneath. It's crucial not to pass a custom handler when
|
|
3601
|
-
// isClickable is disabled which in the case of RT it's.
|
|
3602
|
-
isClickable ? function (e) {
|
|
3603
|
-
e.preventDefault();
|
|
3604
|
-
onEdit && onEdit();
|
|
3605
|
-
} : undefined,
|
|
3606
|
-
|
|
3607
|
-
/* todo - remove this when onKeyDown is allowed as a prop for BaseCard in forma 36
|
|
3608
|
-
// @ts-expect-error */
|
|
3609
|
-
onKeyDown: isClickable ? function (e) {
|
|
3610
|
-
if (e.key === 'Enter' && onEdit) {
|
|
3611
|
-
e.preventDefault();
|
|
3612
|
-
onEdit();
|
|
3613
|
-
}
|
|
3614
|
-
} : undefined,
|
|
3615
|
-
dragHandleRender: props.renderDragHandle,
|
|
3616
|
-
withDragHandle: !!props.renderDragHandle,
|
|
3617
|
-
actions: [].concat(renderActions({
|
|
3618
|
-
entityFile: entityFile,
|
|
3619
|
-
isDisabled: isDisabled,
|
|
3620
|
-
onEdit: onEdit,
|
|
3621
|
-
onRemove: onRemove
|
|
3622
|
-
}), entityFile ? renderAssetInfo({
|
|
3623
|
-
entityFile: entityFile
|
|
3624
|
-
}) : []).filter(function (item) {
|
|
3625
|
-
return item;
|
|
3626
|
-
}),
|
|
3627
|
-
size: size
|
|
3628
|
-
});
|
|
3629
|
-
};
|
|
3630
|
-
WrappedAssetCard.defaultProps = defaultProps$1;
|
|
3631
|
-
|
|
3632
|
-
var styles$5 = {
|
|
3633
|
-
scheduleIcon: /*#__PURE__*/css({
|
|
3634
|
-
marginRight: tokens.spacing2Xs
|
|
3635
|
-
})
|
|
3636
|
-
};
|
|
3637
|
-
var WrappedAssetLink = function WrappedAssetLink(props) {
|
|
3638
|
-
var className = props.className,
|
|
3639
|
-
href = props.href,
|
|
3640
|
-
onEdit = props.onEdit,
|
|
3641
|
-
onRemove = props.onRemove,
|
|
3642
|
-
isDisabled = props.isDisabled;
|
|
3643
|
-
var status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
3644
|
-
|
|
3645
|
-
if (status === 'deleted') {
|
|
3646
|
-
return React__default.createElement(MissingEntityCard, {
|
|
3647
|
-
entityType: "Asset",
|
|
3648
|
-
isDisabled: props.isDisabled,
|
|
3649
|
-
onRemove: props.onRemove
|
|
3650
|
-
});
|
|
3651
|
-
}
|
|
3652
|
-
|
|
3653
|
-
var entityTitle = entityHelpers.getAssetTitle({
|
|
3654
|
-
asset: props.asset,
|
|
3655
|
-
localeCode: props.localeCode,
|
|
3656
|
-
defaultLocaleCode: props.defaultLocaleCode,
|
|
3657
|
-
defaultTitle: 'Untitled'
|
|
3658
|
-
});
|
|
3659
|
-
var entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
3660
|
-
return React__default.createElement(EntryCard, {
|
|
3661
|
-
as: href ? 'a' : 'article',
|
|
3662
|
-
contentType: "Asset",
|
|
3663
|
-
title: entityTitle,
|
|
3664
|
-
className: className,
|
|
3665
|
-
href: href,
|
|
3666
|
-
size: "small",
|
|
3667
|
-
status: status,
|
|
3668
|
-
thumbnailElement: entityFile && isValidImage(entityFile) ? React__default.createElement(AssetThumbnail, {
|
|
3669
|
-
file: entityFile
|
|
3670
|
-
}) : undefined,
|
|
3671
|
-
icon: React__default.createElement(ScheduledIconWithTooltip, {
|
|
3672
|
-
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
3673
|
-
entityType: "Asset",
|
|
3674
|
-
entityId: props.asset.sys.id
|
|
3675
|
-
}, React__default.createElement(ClockIcon, {
|
|
3676
|
-
className: styles$5.scheduleIcon,
|
|
3677
|
-
size: "small",
|
|
3678
|
-
variant: "muted",
|
|
3679
|
-
testId: "schedule-icon"
|
|
3680
|
-
})),
|
|
3681
|
-
onClick: function onClick(e) {
|
|
3682
|
-
e.preventDefault();
|
|
3683
|
-
onEdit();
|
|
3684
|
-
},
|
|
3685
|
-
onKeyDown: function onKeyDown(e) {
|
|
3686
|
-
if (e.key === 'Enter' && onEdit) {
|
|
3687
|
-
e.preventDefault();
|
|
3688
|
-
onEdit();
|
|
3689
|
-
}
|
|
3690
|
-
},
|
|
3691
|
-
dragHandleRender: props.renderDragHandle,
|
|
3692
|
-
withDragHandle: !!props.renderDragHandle,
|
|
3693
|
-
actions: [renderActions({
|
|
3694
|
-
entityFile: entityFile,
|
|
3695
|
-
isDisabled: isDisabled,
|
|
3696
|
-
onEdit: onEdit,
|
|
3697
|
-
onRemove: onRemove
|
|
3698
|
-
}), entityFile ? renderAssetInfo({
|
|
3699
|
-
entityFile: entityFile
|
|
3700
|
-
}) : null].filter(function (item) {
|
|
3701
|
-
return item;
|
|
3702
|
-
})
|
|
3703
|
-
});
|
|
3704
|
-
};
|
|
3705
|
-
|
|
3706
|
-
function FetchingWrappedAssetCard(props) {
|
|
3707
|
-
var _useEntity = useEntity('Asset', props.assetId),
|
|
3708
|
-
asset = _useEntity.data,
|
|
3709
|
-
status = _useEntity.status;
|
|
3710
|
-
|
|
3711
|
-
var _useEntityLoader = useEntityLoader(),
|
|
3712
|
-
getEntityScheduledActions = _useEntityLoader.getEntityScheduledActions;
|
|
3713
|
-
|
|
3714
|
-
var loadEntityScheduledActions = useCallback(function () {
|
|
3715
|
-
return getEntityScheduledActions('Asset', props.assetId);
|
|
3716
|
-
}, [getEntityScheduledActions, props.assetId]);
|
|
3717
|
-
useEffect(function () {
|
|
3718
|
-
if (asset) {
|
|
3719
|
-
props.onAction && props.onAction({
|
|
3720
|
-
type: 'rendered',
|
|
3721
|
-
entity: 'Asset'
|
|
3722
|
-
});
|
|
3723
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3724
|
-
|
|
3725
|
-
}, [asset]);
|
|
3726
|
-
|
|
3727
|
-
var onEdit = /*#__PURE__*/function () {
|
|
3728
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
3729
|
-
var _yield$props$sdk$navi, slide;
|
|
3730
|
-
|
|
3731
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
3732
|
-
while (1) {
|
|
3733
|
-
switch (_context.prev = _context.next) {
|
|
3734
|
-
case 0:
|
|
3735
|
-
_context.next = 2;
|
|
3736
|
-
return props.sdk.navigator.openAsset(props.assetId, {
|
|
3737
|
-
slideIn: true
|
|
3738
|
-
});
|
|
3739
|
-
|
|
3740
|
-
case 2:
|
|
3741
|
-
_yield$props$sdk$navi = _context.sent;
|
|
3742
|
-
slide = _yield$props$sdk$navi.slide;
|
|
3743
|
-
props.onAction && props.onAction({
|
|
3744
|
-
entity: 'Asset',
|
|
3745
|
-
type: 'edit',
|
|
3746
|
-
id: props.assetId,
|
|
3747
|
-
contentTypeId: '',
|
|
3748
|
-
slide: slide
|
|
3749
|
-
});
|
|
3750
|
-
|
|
3751
|
-
case 5:
|
|
3752
|
-
case "end":
|
|
3753
|
-
return _context.stop();
|
|
3754
|
-
}
|
|
3755
|
-
}
|
|
3756
|
-
}, _callee);
|
|
3757
|
-
}));
|
|
3758
|
-
|
|
3759
|
-
return function onEdit() {
|
|
3760
|
-
return _ref.apply(this, arguments);
|
|
3761
|
-
};
|
|
3762
|
-
}();
|
|
3763
|
-
|
|
3764
|
-
var onRemove = function onRemove() {
|
|
3765
|
-
props.onRemove();
|
|
3766
|
-
props.onAction && props.onAction({
|
|
3767
|
-
entity: 'Asset',
|
|
3768
|
-
type: 'delete',
|
|
3769
|
-
id: props.assetId,
|
|
3770
|
-
contentTypeId: ''
|
|
3771
|
-
});
|
|
3772
|
-
};
|
|
3773
|
-
|
|
3774
|
-
return useMemo(function () {
|
|
3775
|
-
if (status === 'error') {
|
|
3776
|
-
var card = createElement(MissingEntityCard, {
|
|
3777
|
-
entityType: "Asset",
|
|
3778
|
-
asSquare: props.viewType !== 'link',
|
|
3779
|
-
isDisabled: props.isDisabled,
|
|
3780
|
-
onRemove: onRemove
|
|
3781
|
-
});
|
|
3782
|
-
|
|
3783
|
-
if (props.renderCustomMissingEntityCard) {
|
|
3784
|
-
return props.renderCustomMissingEntityCard({
|
|
3785
|
-
defaultCard: card,
|
|
3786
|
-
entity: {
|
|
3787
|
-
id: props.assetId,
|
|
3788
|
-
type: 'Asset'
|
|
3789
|
-
}
|
|
3790
|
-
});
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
return card;
|
|
3794
|
-
}
|
|
3795
|
-
|
|
3796
|
-
var getEntityUrl = props.getEntityUrl;
|
|
3797
|
-
var size = props.viewType === 'big_card' ? 'default' : 'small';
|
|
3798
|
-
var commonProps = {
|
|
3799
|
-
asset: asset,
|
|
3800
|
-
entityUrl: getEntityUrl && getEntityUrl(props.assetId),
|
|
3801
|
-
size: size,
|
|
3802
|
-
isDisabled: props.isDisabled,
|
|
3803
|
-
localeCode: props.sdk.field.locale,
|
|
3804
|
-
defaultLocaleCode: props.sdk.locales["default"],
|
|
3805
|
-
renderDragHandle: props.renderDragHandle,
|
|
3806
|
-
onEdit: onEdit,
|
|
3807
|
-
onRemove: onRemove
|
|
3808
|
-
};
|
|
3809
|
-
|
|
3810
|
-
if (props.viewType === 'link') {
|
|
3811
|
-
if (status === 'loading') {
|
|
3812
|
-
return createElement(EntryCard, {
|
|
3813
|
-
size: "small",
|
|
3814
|
-
isLoading: true
|
|
3815
|
-
});
|
|
3816
|
-
}
|
|
3817
|
-
|
|
3818
|
-
return createElement(WrappedAssetLink, _extends({}, commonProps, {
|
|
3819
|
-
href: commonProps.entityUrl,
|
|
3820
|
-
getEntityScheduledActions: loadEntityScheduledActions
|
|
3821
|
-
}));
|
|
3822
|
-
}
|
|
3823
|
-
|
|
3824
|
-
if (status === 'loading') {
|
|
3825
|
-
return createElement(AssetCard, {
|
|
3826
|
-
size: size,
|
|
3827
|
-
isLoading: true
|
|
3828
|
-
});
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
function renderDefaultCard(props) {
|
|
3832
|
-
// isClickable has a default value, so omit it from the props
|
|
3833
|
-
var builtinCardProps = _extends({}, commonProps, props, {
|
|
3834
|
-
getEntityScheduledActions: loadEntityScheduledActions,
|
|
3835
|
-
asset: (props == null ? void 0 : props.entity) || commonProps.asset,
|
|
3836
|
-
getAssetUrl: getEntityUrl
|
|
3837
|
-
});
|
|
3838
|
-
|
|
3839
|
-
return createElement(WrappedAssetCard, _extends({}, builtinCardProps));
|
|
3840
|
-
}
|
|
3841
|
-
|
|
3842
|
-
if (props.renderCustomCard) {
|
|
3843
|
-
var customProps = _extends({}, commonProps, {
|
|
3844
|
-
entity: commonProps.asset
|
|
3845
|
-
}); // LinkActionsProps are injected higher SingleReferenceEditor/MultipleReferenceEditor
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
var renderedCustomCard = props.renderCustomCard(customProps, {}, renderDefaultCard); // Only `false` indicates to render the original card. E.g. `null` would result in no card.
|
|
3849
|
-
|
|
3850
|
-
if (renderedCustomCard !== false) {
|
|
3851
|
-
return renderedCustomCard;
|
|
3852
|
-
}
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
return renderDefaultCard(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3856
|
-
}, [props, status, asset]);
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
function SingleMediaEditor(props) {
|
|
3860
|
-
return createElement(SingleReferenceEditor, _extends({}, props, {
|
|
3861
|
-
entityType: "Asset"
|
|
3862
|
-
}), function (_ref) {
|
|
3863
|
-
var entityId = _ref.entityId,
|
|
3864
|
-
isDisabled = _ref.isDisabled,
|
|
3865
|
-
setValue = _ref.setValue;
|
|
3866
|
-
return createElement(FetchingWrappedAssetCard, _extends({}, props, {
|
|
3867
|
-
viewType: "big_card",
|
|
3868
|
-
assetId: entityId,
|
|
3869
|
-
isDisabled: isDisabled,
|
|
3870
|
-
onRemove: function onRemove() {
|
|
3871
|
-
setValue(null);
|
|
3872
|
-
}
|
|
3873
|
-
}));
|
|
3874
|
-
});
|
|
3875
|
-
}
|
|
3876
|
-
SingleMediaEditor.defaultProps = {
|
|
3877
|
-
isInitiallyDisabled: true
|
|
3878
|
-
};
|
|
3879
|
-
|
|
3880
|
-
var styles$6 = {
|
|
3881
|
-
gridContainer: /*#__PURE__*/css({
|
|
3882
|
-
position: 'relative',
|
|
3883
|
-
display: 'flex',
|
|
3884
|
-
flexWrap: 'wrap'
|
|
3885
|
-
})
|
|
3886
|
-
};
|
|
3887
|
-
function MultipleMediaEditor(props) {
|
|
3888
|
-
return createElement(MultipleReferenceEditor, _extends({}, props, {
|
|
3889
|
-
entityType: "Asset"
|
|
3890
|
-
}), function (childrenProps) {
|
|
3891
|
-
var _cx;
|
|
3892
|
-
|
|
3893
|
-
return createElement(SortableLinkList, _extends({}, childrenProps, {
|
|
3894
|
-
className: cx((_cx = {}, _cx[styles$6.gridContainer] = childrenProps.viewType === 'card', _cx)),
|
|
3895
|
-
axis: childrenProps.viewType === 'card' ? 'xy' : 'y',
|
|
3896
|
-
useDragHandle: true
|
|
3897
|
-
}), function (_ref) {
|
|
3898
|
-
var items = _ref.items,
|
|
3899
|
-
item = _ref.item,
|
|
3900
|
-
index = _ref.index,
|
|
3901
|
-
isDisabled = _ref.isDisabled,
|
|
3902
|
-
DragHandle = _ref.DragHandle;
|
|
3903
|
-
return createElement(FetchingWrappedAssetCard, _extends({}, childrenProps, {
|
|
3904
|
-
isDisabled: isDisabled,
|
|
3905
|
-
key: item.sys.id + "-" + index,
|
|
3906
|
-
assetId: item.sys.id,
|
|
3907
|
-
onRemove: function onRemove() {
|
|
3908
|
-
childrenProps.setValue(items.filter(function (_value, i) {
|
|
3909
|
-
return i !== index;
|
|
3910
|
-
}));
|
|
3911
|
-
},
|
|
3912
|
-
renderDragHandle: DragHandle
|
|
3913
|
-
}));
|
|
3914
|
-
});
|
|
3915
|
-
});
|
|
3916
|
-
}
|
|
3917
|
-
MultipleMediaEditor.defaultProps = {
|
|
3918
|
-
isInitiallyDisabled: true
|
|
3919
|
-
};
|
|
3920
|
-
|
|
3921
|
-
var resolveAsset = function resolveAsset() {
|
|
3922
|
-
return Promise.resolve();
|
|
3923
|
-
}; // we don't want to show scheduled actions for resources
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
var resolveScheduledActions = function resolveScheduledActions() {
|
|
3927
|
-
return Promise.resolve([]);
|
|
3928
|
-
};
|
|
3929
|
-
|
|
3930
|
-
function ContentfulEntryCard(_ref) {
|
|
3931
|
-
var info = _ref.info,
|
|
3932
|
-
isDisabled = _ref.isDisabled,
|
|
3933
|
-
renderDragHandle = _ref.renderDragHandle,
|
|
3934
|
-
onRemove = _ref.onRemove,
|
|
3935
|
-
onMoveTop = _ref.onMoveTop,
|
|
3936
|
-
onMoveBottom = _ref.onMoveBottom,
|
|
3937
|
-
getEntryRouteHref = _ref.getEntryRouteHref;
|
|
3938
|
-
var resourceSys = info.resource.sys;
|
|
3939
|
-
var spaceId = resourceSys.space.sys.id;
|
|
3940
|
-
var environmentId = resourceSys.environment.sys.id;
|
|
3941
|
-
var entryId = resourceSys.id;
|
|
3942
|
-
var resourceHref = getEntryRouteHref({
|
|
3943
|
-
spaceId: spaceId,
|
|
3944
|
-
environmentId: environmentId,
|
|
3945
|
-
entryId: entryId
|
|
3946
|
-
}); // TODO: move this into `sdk.navigator.openEntry()`, note that it's signature only include the entry id (not a space or environment)
|
|
3947
|
-
|
|
3948
|
-
var openEntryDetail = function openEntryDetail() {
|
|
3949
|
-
window.open(resourceHref, '_blank', 'noopener,noreferrer');
|
|
3950
|
-
};
|
|
3951
|
-
|
|
3952
|
-
return createElement(WrappedEntryCard, {
|
|
3953
|
-
entry: info.resource,
|
|
3954
|
-
isDisabled: isDisabled,
|
|
3955
|
-
hasCardEditActions: false,
|
|
3956
|
-
contentType: info.contentType,
|
|
3957
|
-
// we use the default locale from the space the entry belongs to
|
|
3958
|
-
// as we assume this gives a more consistent behaviour.
|
|
3959
|
-
// locales will inevitably differ from space to space, so it's likely
|
|
3960
|
-
// that the current locale does not exist in the "remote" space
|
|
3961
|
-
localeCode: info.defaultLocaleCode,
|
|
3962
|
-
defaultLocaleCode: info.defaultLocaleCode,
|
|
3963
|
-
size: "small",
|
|
3964
|
-
getAsset: resolveAsset,
|
|
3965
|
-
getEntityScheduledActions: resolveScheduledActions,
|
|
3966
|
-
spaceName: info.space.name,
|
|
3967
|
-
renderDragHandle: renderDragHandle,
|
|
3968
|
-
isClickable: true,
|
|
3969
|
-
onEdit: openEntryDetail,
|
|
3970
|
-
hasCardRemoveActions: Boolean(onRemove),
|
|
3971
|
-
onRemove: onRemove,
|
|
3972
|
-
onMoveBottom: onMoveBottom,
|
|
3973
|
-
onMoveTop: onMoveTop,
|
|
3974
|
-
entryUrl: resourceHref
|
|
3975
|
-
});
|
|
3976
|
-
}
|
|
3977
|
-
|
|
3978
|
-
var styles$7 = {
|
|
3979
|
-
card: /*#__PURE__*/css({
|
|
3980
|
-
position: 'relative'
|
|
3981
|
-
})
|
|
3982
|
-
};
|
|
3983
|
-
function UnsupportedEntityCard(props) {
|
|
3984
|
-
return React__default.createElement(Card, {
|
|
3985
|
-
className: styles$7.card
|
|
3986
|
-
}, React__default.createElement(SectionHeading, {
|
|
3987
|
-
marginBottom: "none"
|
|
3988
|
-
}, "Resource type ", props.entityType, " is currently not supported"));
|
|
3989
|
-
}
|
|
3990
|
-
|
|
3991
|
-
function ResourceCardSkeleton() {
|
|
3992
|
-
return createElement(EntryCard, {
|
|
3993
|
-
size: "small",
|
|
3994
|
-
isLoading: true
|
|
3995
|
-
});
|
|
3996
|
-
}
|
|
3997
|
-
|
|
3998
|
-
function ExistingResourceCard(props) {
|
|
3999
|
-
var resourceLink = props.resourceLink,
|
|
4000
|
-
inView = props.inView,
|
|
4001
|
-
_props$index = props.index,
|
|
4002
|
-
index = _props$index === void 0 ? 0 : _props$index;
|
|
4003
|
-
var resourceOptions = {
|
|
4004
|
-
priority: index * -1,
|
|
4005
|
-
enabled: inView
|
|
4006
|
-
};
|
|
4007
|
-
|
|
4008
|
-
var _useResource = useResource(resourceLink.sys.linkType, resourceLink.sys.urn, resourceOptions),
|
|
4009
|
-
data = _useResource.data,
|
|
4010
|
-
error = _useResource.error;
|
|
4011
|
-
|
|
4012
|
-
if (!data && !error) {
|
|
4013
|
-
return createElement(ResourceCardSkeleton, null);
|
|
4014
|
-
}
|
|
4015
|
-
|
|
4016
|
-
if (data) {
|
|
4017
|
-
return createElement(ContentfulEntryCard, _extends({
|
|
4018
|
-
info: data
|
|
4019
|
-
}, props));
|
|
4020
|
-
}
|
|
4021
|
-
|
|
4022
|
-
if (isUnsupportedError(error)) {
|
|
4023
|
-
return createElement(UnsupportedEntityCard, {
|
|
4024
|
-
entityType: resourceLink.sys.linkType
|
|
4025
|
-
});
|
|
4026
|
-
}
|
|
4027
|
-
|
|
4028
|
-
return createElement(MissingEntityCard, {
|
|
4029
|
-
entityType: "Entry",
|
|
4030
|
-
isDisabled: props.isDisabled,
|
|
4031
|
-
onRemove: props.onRemove
|
|
4032
|
-
});
|
|
4033
|
-
}
|
|
4034
|
-
|
|
4035
|
-
function ResourceCardWrapper(props) {
|
|
4036
|
-
if (!props.resourceLink) {
|
|
4037
|
-
return null;
|
|
4038
|
-
}
|
|
4039
|
-
|
|
4040
|
-
return createElement(ExistingResourceCard, _extends({}, props, {
|
|
4041
|
-
resourceLink: props.resourceLink,
|
|
4042
|
-
getEntryRouteHref: props.getEntryRouteHref
|
|
4043
|
-
}));
|
|
4044
|
-
}
|
|
4045
|
-
|
|
4046
|
-
function ResourceCard(props) {
|
|
4047
|
-
var _useInView = useInView({
|
|
4048
|
-
triggerOnce: true,
|
|
4049
|
-
rootMargin: '300px 0px 0px 300px'
|
|
4050
|
-
}),
|
|
4051
|
-
ref = _useInView.ref,
|
|
4052
|
-
inView = _useInView.inView; // Forma does not offer us to pass refs, so we need an additional wrapper here
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
return createElement("div", {
|
|
4056
|
-
ref: ref
|
|
4057
|
-
}, createElement(ResourceCardWrapper, _extends({}, props, {
|
|
4058
|
-
inView: inView
|
|
4059
|
-
})));
|
|
4060
|
-
}
|
|
4061
|
-
|
|
4062
|
-
var toLinkItem = function toLinkItem(entry, apiUrl) {
|
|
4063
|
-
var _entry$sys$urn;
|
|
4064
|
-
|
|
4065
|
-
return {
|
|
4066
|
-
sys: {
|
|
4067
|
-
type: 'ResourceLink',
|
|
4068
|
-
linkType: 'Contentful:Entry',
|
|
4069
|
-
urn: (_entry$sys$urn = entry.sys.urn) != null ? _entry$sys$urn : "crn:" + apiUrl + ":::content:spaces/" + entry.sys.space.sys.id + "/entries/" + entry.sys.id
|
|
4070
|
-
}
|
|
4071
|
-
};
|
|
4072
|
-
};
|
|
4073
|
-
|
|
4074
|
-
var getUpdatedValue = function getUpdatedValue(field, entries, apiUrl) {
|
|
4075
|
-
var multiple = field.type === 'Array';
|
|
4076
|
-
|
|
4077
|
-
if (multiple) {
|
|
4078
|
-
var linkItems = entries.map(function (entry) {
|
|
4079
|
-
return toLinkItem(entry, apiUrl);
|
|
4080
|
-
});
|
|
4081
|
-
var prevValue = field.getValue() || [];
|
|
4082
|
-
return [].concat(prevValue, linkItems);
|
|
4083
|
-
} else {
|
|
4084
|
-
return toLinkItem(entries[0], apiUrl);
|
|
4085
|
-
}
|
|
4086
|
-
};
|
|
4087
|
-
|
|
4088
|
-
function useResourceLinkActions(_ref) {
|
|
4089
|
-
var dialogs = _ref.dialogs,
|
|
4090
|
-
field = _ref.field,
|
|
4091
|
-
onAfterLink = _ref.onAfterLink,
|
|
4092
|
-
apiUrl = _ref.apiUrl;
|
|
4093
|
-
var handleAfterLink = useCallback(function (entries) {
|
|
4094
|
-
if (!onAfterLink) {
|
|
4095
|
-
return;
|
|
4096
|
-
}
|
|
4097
|
-
|
|
4098
|
-
entries.forEach(onAfterLink);
|
|
4099
|
-
}, [onAfterLink]);
|
|
4100
|
-
var onLinkedExisting = useMemo(function () {
|
|
4101
|
-
return function (entries) {
|
|
4102
|
-
var updatedValue = getUpdatedValue(field, entries, apiUrl);
|
|
4103
|
-
field.setValue(updatedValue);
|
|
4104
|
-
handleAfterLink(entries);
|
|
4105
|
-
};
|
|
4106
|
-
}, [field, handleAfterLink, apiUrl]);
|
|
4107
|
-
var multiple = field.type === 'Array';
|
|
4108
|
-
var onLinkExisting = useMemo(function () {
|
|
4109
|
-
var promptSelection = multiple ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
4110
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
4111
|
-
while (1) {
|
|
4112
|
-
switch (_context.prev = _context.next) {
|
|
4113
|
-
case 0:
|
|
4114
|
-
_context.next = 2;
|
|
4115
|
-
return dialogs.selectMultipleResourceEntries({
|
|
4116
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
4117
|
-
allowedResources: field.allowedResources
|
|
4118
|
-
});
|
|
4119
|
-
|
|
4120
|
-
case 2:
|
|
4121
|
-
return _context.abrupt("return", _context.sent);
|
|
4122
|
-
|
|
4123
|
-
case 3:
|
|
4124
|
-
case "end":
|
|
4125
|
-
return _context.stop();
|
|
4126
|
-
}
|
|
4127
|
-
}
|
|
4128
|
-
}, _callee);
|
|
4129
|
-
})) : /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
4130
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
4131
|
-
while (1) {
|
|
4132
|
-
switch (_context2.prev = _context2.next) {
|
|
4133
|
-
case 0:
|
|
4134
|
-
_context2.next = 2;
|
|
4135
|
-
return dialogs.selectSingleResourceEntry({
|
|
4136
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
4137
|
-
allowedResources: field.allowedResources
|
|
4138
|
-
});
|
|
4139
|
-
|
|
4140
|
-
case 2:
|
|
4141
|
-
_context2.t0 = _context2.sent;
|
|
4142
|
-
return _context2.abrupt("return", [_context2.t0]);
|
|
4143
|
-
|
|
4144
|
-
case 4:
|
|
4145
|
-
case "end":
|
|
4146
|
-
return _context2.stop();
|
|
4147
|
-
}
|
|
4148
|
-
}
|
|
4149
|
-
}, _callee2);
|
|
4150
|
-
}));
|
|
4151
|
-
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
4152
|
-
var res;
|
|
4153
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
4154
|
-
while (1) {
|
|
4155
|
-
switch (_context3.prev = _context3.next) {
|
|
4156
|
-
case 0:
|
|
4157
|
-
_context3.next = 2;
|
|
4158
|
-
return promptSelection();
|
|
4159
|
-
|
|
4160
|
-
case 2:
|
|
4161
|
-
res = _context3.sent;
|
|
4162
|
-
|
|
4163
|
-
if (res) {
|
|
4164
|
-
_context3.next = 5;
|
|
4165
|
-
break;
|
|
4166
|
-
}
|
|
4167
|
-
|
|
4168
|
-
return _context3.abrupt("return");
|
|
4169
|
-
|
|
4170
|
-
case 5:
|
|
4171
|
-
onLinkedExisting(res);
|
|
4172
|
-
|
|
4173
|
-
case 6:
|
|
4174
|
-
case "end":
|
|
4175
|
-
return _context3.stop();
|
|
4176
|
-
}
|
|
4177
|
-
}
|
|
4178
|
-
}, _callee3);
|
|
4179
|
-
})); // @ts-expect-error wait for update of app-sdk version
|
|
4180
|
-
}, [dialogs, field.allowedResources, multiple, onLinkedExisting]);
|
|
4181
|
-
return {
|
|
4182
|
-
onLinkExisting: onLinkExisting,
|
|
4183
|
-
onLinkedExisting: onLinkedExisting,
|
|
4184
|
-
// hardcoded values to match interface for standard reference field actions
|
|
4185
|
-
entityType: 'Entry',
|
|
4186
|
-
contentTypes: [],
|
|
4187
|
-
canCreateEntity: false,
|
|
4188
|
-
canLinkMultiple: multiple,
|
|
4189
|
-
canLinkEntity: true,
|
|
4190
|
-
isDisabled: false,
|
|
4191
|
-
isEmpty: false,
|
|
4192
|
-
isFull: false,
|
|
4193
|
-
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4194
|
-
onCreate: function () {
|
|
4195
|
-
var _onCreate = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
4196
|
-
return runtime_1.wrap(function _callee4$(_context4) {
|
|
4197
|
-
while (1) {
|
|
4198
|
-
switch (_context4.prev = _context4.next) {
|
|
4199
|
-
case 0:
|
|
4200
|
-
case "end":
|
|
4201
|
-
return _context4.stop();
|
|
4202
|
-
}
|
|
4203
|
-
}
|
|
4204
|
-
}, _callee4);
|
|
4205
|
-
}));
|
|
4206
|
-
|
|
4207
|
-
function onCreate() {
|
|
4208
|
-
return _onCreate.apply(this, arguments);
|
|
4209
|
-
}
|
|
4210
|
-
|
|
4211
|
-
return onCreate;
|
|
4212
|
-
}(),
|
|
4213
|
-
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4214
|
-
onCreated: function onCreated() {}
|
|
4215
|
-
};
|
|
4216
|
-
}
|
|
4217
|
-
|
|
4218
|
-
function ResourceEditor(props) {
|
|
4219
|
-
var setValue = props.setValue,
|
|
4220
|
-
items = props.items,
|
|
4221
|
-
apiUrl = props.apiUrl;
|
|
4222
|
-
var onSortStart = useCallback(function (_, event) {
|
|
4223
|
-
return event.preventDefault();
|
|
4224
|
-
}, []);
|
|
4225
|
-
var onSortEnd = useCallback(function (_ref) {
|
|
4226
|
-
var oldIndex = _ref.oldIndex,
|
|
4227
|
-
newIndex = _ref.newIndex;
|
|
4228
|
-
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4229
|
-
setValue(newItems);
|
|
4230
|
-
}, [items, setValue]);
|
|
4231
|
-
var onMove = useCallback(function (oldIndex, newIndex) {
|
|
4232
|
-
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4233
|
-
setValue(newItems);
|
|
4234
|
-
}, [items, setValue]);
|
|
4235
|
-
var onRemoteItemAtIndex = useCallback(function (index) {
|
|
4236
|
-
setValue(items.filter(function (_v, i) {
|
|
4237
|
-
return i !== index;
|
|
4238
|
-
}));
|
|
4239
|
-
}, [items, setValue]);
|
|
4240
|
-
var _props$sdk = props.sdk,
|
|
4241
|
-
dialogs = _props$sdk.dialogs,
|
|
4242
|
-
field = _props$sdk.field;
|
|
4243
|
-
var linkActionsProps = useResourceLinkActions({
|
|
4244
|
-
dialogs: dialogs,
|
|
4245
|
-
field: field,
|
|
4246
|
-
apiUrl: apiUrl
|
|
4247
|
-
});
|
|
4248
|
-
return createElement(Fragment, null, props.children(_extends({}, props, {
|
|
4249
|
-
onSortStart: onSortStart,
|
|
4250
|
-
onSortEnd: onSortEnd,
|
|
4251
|
-
onMove: onMove,
|
|
4252
|
-
onRemoteItemAtIndex: onRemoteItemAtIndex
|
|
4253
|
-
})), createElement(CombinedLinkEntityActions, _extends({}, linkActionsProps, {
|
|
4254
|
-
renderCustomActions: props.renderCustomActions
|
|
4255
|
-
})));
|
|
4256
|
-
} // provides memoized callbacks bound to a given item
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
function WithPerItemCallbacks(_ref2) {
|
|
4260
|
-
var listLength = _ref2.listLength,
|
|
4261
|
-
index = _ref2.index,
|
|
4262
|
-
onMove = _ref2.onMove,
|
|
4263
|
-
onRemoteItemAtIndex = _ref2.onRemoteItemAtIndex,
|
|
4264
|
-
children = _ref2.children;
|
|
4265
|
-
var handleMoveTop = useMemo(function () {
|
|
4266
|
-
return index > 0 ? function () {
|
|
4267
|
-
return onMove(index, 0);
|
|
4268
|
-
} : undefined;
|
|
4269
|
-
}, [index, onMove]);
|
|
4270
|
-
var handleMoveBottom = useMemo(function () {
|
|
4271
|
-
return index < listLength - 1 ? function () {
|
|
4272
|
-
return onMove(index, listLength - 1);
|
|
4273
|
-
} : undefined;
|
|
4274
|
-
}, [index, onMove, listLength]);
|
|
4275
|
-
var handleRemove = useCallback(function () {
|
|
4276
|
-
return onRemoteItemAtIndex(index);
|
|
4277
|
-
}, [index, onRemoteItemAtIndex]);
|
|
4278
|
-
return createElement(Fragment, null, children({
|
|
4279
|
-
onMoveBottom: handleMoveBottom,
|
|
4280
|
-
onMoveTop: handleMoveTop,
|
|
4281
|
-
onRemove: handleRemove
|
|
4282
|
-
}));
|
|
4283
|
-
}
|
|
4284
|
-
|
|
4285
|
-
var EMPTY_ARRAY = [];
|
|
4286
|
-
function MultipleResourceReferenceEditor(props) {
|
|
4287
|
-
return createElement(EntityProvider, {
|
|
4288
|
-
sdk: props.sdk
|
|
4289
|
-
}, createElement(FieldConnector, {
|
|
4290
|
-
throttle: 0,
|
|
4291
|
-
field: props.sdk.field,
|
|
4292
|
-
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4293
|
-
isEqualValues: deepEqual
|
|
4294
|
-
}, function (_ref3) {
|
|
4295
|
-
var value = _ref3.value,
|
|
4296
|
-
disabled = _ref3.disabled,
|
|
4297
|
-
setValue = _ref3.setValue,
|
|
4298
|
-
externalReset = _ref3.externalReset;
|
|
4299
|
-
return createElement(ResourceEditor, _extends({}, props, {
|
|
4300
|
-
items: value || EMPTY_ARRAY,
|
|
4301
|
-
isDisabled: disabled,
|
|
4302
|
-
setValue: setValue,
|
|
4303
|
-
renderCustomActions: props.renderCustomActions,
|
|
4304
|
-
key: externalReset + "-list"
|
|
4305
|
-
}), function (editorProps) {
|
|
4306
|
-
return createElement(SortableLinkList, _extends({}, editorProps), function (_ref4) {
|
|
4307
|
-
var item = _ref4.item,
|
|
4308
|
-
isDisabled = _ref4.isDisabled,
|
|
4309
|
-
DragHandle = _ref4.DragHandle,
|
|
4310
|
-
index = _ref4.index;
|
|
4311
|
-
return createElement(WithPerItemCallbacks, {
|
|
4312
|
-
index: index,
|
|
4313
|
-
onMove: editorProps.onMove,
|
|
4314
|
-
onRemoteItemAtIndex: editorProps.onRemoteItemAtIndex,
|
|
4315
|
-
listLength: (value == null ? void 0 : value.length) || 0
|
|
4316
|
-
}, function (_ref5) {
|
|
4317
|
-
var onMoveBottom = _ref5.onMoveBottom,
|
|
4318
|
-
onMoveTop = _ref5.onMoveTop,
|
|
4319
|
-
onRemove = _ref5.onRemove;
|
|
4320
|
-
return createElement(ResourceCard, {
|
|
4321
|
-
index: index,
|
|
4322
|
-
resourceLink: item,
|
|
4323
|
-
isDisabled: isDisabled,
|
|
4324
|
-
renderDragHandle: DragHandle,
|
|
4325
|
-
onMoveTop: onMoveTop,
|
|
4326
|
-
onMoveBottom: onMoveBottom,
|
|
4327
|
-
onRemove: onRemove,
|
|
4328
|
-
getEntryRouteHref: props.getEntryRouteHref
|
|
4329
|
-
});
|
|
4330
|
-
});
|
|
4331
|
-
});
|
|
4332
|
-
});
|
|
4333
|
-
}));
|
|
4334
|
-
}
|
|
4335
|
-
|
|
4336
|
-
function SingleResourceReferenceEditor(props) {
|
|
4337
|
-
var _props$sdk = props.sdk,
|
|
4338
|
-
dialogs = _props$sdk.dialogs,
|
|
4339
|
-
field = _props$sdk.field;
|
|
4340
|
-
var linkActionsProps = useResourceLinkActions({
|
|
4341
|
-
dialogs: dialogs,
|
|
4342
|
-
field: field,
|
|
4343
|
-
apiUrl: props.apiUrl
|
|
4344
|
-
});
|
|
4345
|
-
return createElement(EntityProvider, {
|
|
4346
|
-
sdk: props.sdk
|
|
4347
|
-
}, createElement(FieldConnector, {
|
|
4348
|
-
throttle: 0,
|
|
4349
|
-
field: props.sdk.field,
|
|
4350
|
-
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4351
|
-
isEqualValues: deepEqual
|
|
4352
|
-
}, function (_ref) {
|
|
4353
|
-
var value = _ref.value,
|
|
4354
|
-
disabled = _ref.disabled;
|
|
4355
|
-
return value ? createElement(ResourceCard, {
|
|
4356
|
-
onRemove: function onRemove() {
|
|
4357
|
-
return props.sdk.field.removeValue();
|
|
4358
|
-
},
|
|
4359
|
-
resourceLink: value,
|
|
4360
|
-
isDisabled: disabled,
|
|
4361
|
-
getEntryRouteHref: props.getEntryRouteHref
|
|
4362
|
-
}) : createElement(CombinedLinkEntityActions, _extends({}, linkActionsProps, {
|
|
4363
|
-
renderCustomActions: props.renderCustomActions
|
|
4364
|
-
}));
|
|
4365
|
-
}));
|
|
4366
|
-
}
|
|
4367
|
-
|
|
4368
|
-
export { AssetThumbnail, CombinedLinkActions, CreateEntryLinkButton, CreateEntryMenuTrigger, EntityProvider, MissingEntityCard, MultipleEntryReferenceEditor, MultipleMediaEditor, MultipleResourceReferenceEditor, ScheduledIconWithTooltip, SingleEntryReferenceEditor, SingleMediaEditor, SingleResourceReferenceEditor, SortableLinkList, WrappedAssetCard, WrappedEntryCard, getScheduleTooltipContent, useEntity, useEntityLoader, useResource };
|
|
4369
|
-
//# sourceMappingURL=field-editor-reference.esm.js.map
|