@contentful/field-editor-reference 4.6.10 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/assets/WrappedAssetCard/AssetCardActions.d.ts +1 -1
- package/dist/common/EntityStore.d.ts +55 -5
- package/dist/common/ReferenceEditor.d.ts +1 -1
- package/dist/common/useAccessApi.d.ts +1 -1
- package/dist/components/LinkActions/helpers.d.ts +3 -3
- package/dist/field-editor-reference.cjs.development.js +972 -540
- package/dist/field-editor-reference.cjs.development.js.map +1 -1
- package/dist/field-editor-reference.cjs.production.min.js +1 -1
- package/dist/field-editor-reference.cjs.production.min.js.map +1 -1
- package/dist/field-editor-reference.esm.js +969 -541
- package/dist/field-editor-reference.esm.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/resources/Cards/ContentfulEntryCard.d.ts +21 -0
- package/dist/resources/Cards/ResourceCard.d.ts +12 -0
- package/dist/resources/Cards/UnsupportedEntityCard.d.ts +4 -0
- package/dist/resources/MultipleResourceReferenceEditor.d.ts +7 -0
- package/dist/resources/SingleResourceReferenceEditor.d.ts +7 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/testHelpers/resourceEditorHelpers.d.ts +50 -0
- package/dist/resources/useResourceLinkActions.d.ts +7 -0
- package/dist/types.d.ts +10 -0
- package/package.json +7 -3
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import React__default, { useState, useRef, useEffect, createElement, Fragment, useMemo, useCallback
|
|
1
|
+
import React__default, { useState, useRef, useEffect, createElement, Fragment, useMemo, useCallback } from 'react';
|
|
2
2
|
import { css, cx } from 'emotion';
|
|
3
3
|
import tokens from '@contentful/f36-tokens';
|
|
4
4
|
import get from 'lodash-es/get';
|
|
5
5
|
import { Menu, TextInput, Button, Paragraph, Card, Flex, SectionHeading, IconButton, Tooltip, Text, EntryCard, MenuItem, MenuDivider, AssetCard } from '@contentful/f36-components';
|
|
6
6
|
import { SearchIcon, PlusIcon, ChevronDownIcon, LinkIcon, CloseIcon, FolderOpenTrimmedIcon, ClockIcon } from '@contentful/f36-icons';
|
|
7
7
|
import moment from 'moment';
|
|
8
|
-
import deepEqual from 'deep-equal';
|
|
9
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';
|
|
10
11
|
import constate from 'constate';
|
|
11
12
|
import { createClient } from 'contentful-management';
|
|
13
|
+
import PQueue from 'p-queue';
|
|
12
14
|
import isNumber from 'lodash-es/isNumber';
|
|
13
15
|
import arrayMove from 'array-move';
|
|
14
16
|
import { SortableContainer, SortableHandle, SortableElement } from 'react-sortable-hoc';
|
|
15
17
|
import mimetype from '@contentful/mimetype';
|
|
18
|
+
import { useInView } from 'react-intersection-observer';
|
|
16
19
|
|
|
17
20
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
18
21
|
try {
|
|
@@ -68,57 +71,110 @@ function _extends() {
|
|
|
68
71
|
return _extends.apply(this, arguments);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var sourceKeys = Object.keys(source);
|
|
75
|
-
var key, i;
|
|
74
|
+
function _inheritsLoose(subClass, superClass) {
|
|
75
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
76
|
+
subClass.prototype.constructor = subClass;
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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;
|
|
81
107
|
}
|
|
108
|
+
}
|
|
82
109
|
|
|
83
|
-
|
|
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);
|
|
84
125
|
}
|
|
85
126
|
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
89
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
90
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
91
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
92
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
127
|
+
function _isNativeFunction(fn) {
|
|
128
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
93
129
|
}
|
|
94
130
|
|
|
95
|
-
function
|
|
96
|
-
|
|
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);
|
|
97
143
|
|
|
98
|
-
|
|
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
|
+
};
|
|
99
161
|
|
|
100
|
-
return
|
|
162
|
+
return _wrapNativeSuper(Class);
|
|
101
163
|
}
|
|
102
164
|
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
165
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
166
|
+
if (source == null) return {};
|
|
167
|
+
var target = {};
|
|
168
|
+
var sourceKeys = Object.keys(source);
|
|
169
|
+
var key, i;
|
|
106
170
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (i >= o.length) return {
|
|
112
|
-
done: true
|
|
113
|
-
};
|
|
114
|
-
return {
|
|
115
|
-
done: false,
|
|
116
|
-
value: o[i++]
|
|
117
|
-
};
|
|
118
|
-
};
|
|
171
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
172
|
+
key = sourceKeys[i];
|
|
173
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
174
|
+
target[key] = source[key];
|
|
119
175
|
}
|
|
120
176
|
|
|
121
|
-
|
|
177
|
+
return target;
|
|
122
178
|
}
|
|
123
179
|
|
|
124
180
|
var container = /*#__PURE__*/css({
|
|
@@ -498,7 +554,7 @@ function CombinedLinkActions(props) {
|
|
|
498
554
|
var hideEmptyCard = props.entityType === 'Asset' && !props.isEmpty;
|
|
499
555
|
return createElement("div", {
|
|
500
556
|
className: hideEmptyCard ? '' : container
|
|
501
|
-
}, !props.canCreateEntity && !props.canLinkEntity && createElement(NoLinkPermissionsInfo, null), props.entityType === 'Entry' && createElement(CombinedEntryLinkActions,
|
|
557
|
+
}, !props.canCreateEntity && !props.canLinkEntity && createElement(NoLinkPermissionsInfo, null), props.entityType === 'Entry' && createElement(CombinedEntryLinkActions, _extends({}, props)), props.entityType === 'Asset' && createElement(CombinedAssetLinkActions, _extends({}, props)));
|
|
502
558
|
}
|
|
503
559
|
|
|
504
560
|
function CombinedEntryLinkActions(props) {
|
|
@@ -1738,7 +1794,7 @@ function LinkEntityActions(_ref4) {
|
|
|
1738
1794
|
props = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
1739
1795
|
|
|
1740
1796
|
var renderLinkActions = renderCustomActions ? renderCustomActions : function (props) {
|
|
1741
|
-
return createElement(LinkActions,
|
|
1797
|
+
return createElement(LinkActions, _extends({}, props));
|
|
1742
1798
|
};
|
|
1743
1799
|
return renderLinkActions(props);
|
|
1744
1800
|
}
|
|
@@ -1799,6 +1855,8 @@ var ScheduleTooltip = function ScheduleTooltip(_ref2) {
|
|
|
1799
1855
|
};
|
|
1800
1856
|
|
|
1801
1857
|
var ScheduledIconWithTooltip = function ScheduledIconWithTooltip(_ref) {
|
|
1858
|
+
var _status$jobs;
|
|
1859
|
+
|
|
1802
1860
|
var entityType = _ref.entityType,
|
|
1803
1861
|
entityId = _ref.entityId,
|
|
1804
1862
|
getEntityScheduledActions = _ref.getEntityScheduledActions,
|
|
@@ -1830,7 +1888,7 @@ var ScheduledIconWithTooltip = function ScheduledIconWithTooltip(_ref) {
|
|
|
1830
1888
|
return null;
|
|
1831
1889
|
}
|
|
1832
1890
|
|
|
1833
|
-
var jobs = status.jobs ?
|
|
1891
|
+
var jobs = (_status$jobs = status.jobs) != null ? _status$jobs : [];
|
|
1834
1892
|
|
|
1835
1893
|
if (jobs.length === 0) {
|
|
1836
1894
|
return null;
|
|
@@ -1856,502 +1914,426 @@ function AssetThumbnail(props) {
|
|
|
1856
1914
|
});
|
|
1857
1915
|
}
|
|
1858
1916
|
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
switch (action.type) {
|
|
1863
|
-
case 'set_entry':
|
|
1864
|
-
return _extends({}, state, {
|
|
1865
|
-
entries: _extends({}, state.entries, (_extends2 = {}, _extends2[action.id] = action.entry, _extends2))
|
|
1866
|
-
});
|
|
1867
|
-
|
|
1868
|
-
case 'set_entry_failed':
|
|
1869
|
-
return _extends({}, state, {
|
|
1870
|
-
entries: _extends({}, state.entries, (_extends3 = {}, _extends3[action.id] = 'failed', _extends3))
|
|
1871
|
-
});
|
|
1872
|
-
|
|
1873
|
-
case 'set_asset':
|
|
1874
|
-
return _extends({}, state, {
|
|
1875
|
-
assets: _extends({}, state.assets, (_extends4 = {}, _extends4[action.id] = action.asset, _extends4))
|
|
1876
|
-
});
|
|
1877
|
-
|
|
1878
|
-
case 'set_asset_failed':
|
|
1879
|
-
return _extends({}, state, {
|
|
1880
|
-
assets: _extends({}, state.assets, (_extends5 = {}, _extends5[action.id] = 'failed', _extends5))
|
|
1881
|
-
});
|
|
1917
|
+
var _excluded$1 = ["priority"],
|
|
1918
|
+
_excluded2 = ["children"];
|
|
1882
1919
|
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
case 'set_resource':
|
|
1889
|
-
return _extends({}, state, {
|
|
1890
|
-
resources: _extends({}, state.resources, (_extends7 = {}, _extends7[action.resourceType + "." + action.urn] = action.resourceInfo, _extends7))
|
|
1891
|
-
});
|
|
1920
|
+
var globalQueue = /*#__PURE__*/new PQueue({
|
|
1921
|
+
concurrency: 20
|
|
1922
|
+
});
|
|
1923
|
+
var UnsupportedError = /*#__PURE__*/function (_Error) {
|
|
1924
|
+
_inheritsLoose(UnsupportedError, _Error);
|
|
1892
1925
|
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
resources: _extends({}, state.resources, (_extends8 = {}, _extends8[action.resourceType + "." + action.urn] = 'failed', _extends8))
|
|
1896
|
-
});
|
|
1926
|
+
function UnsupportedError(message) {
|
|
1927
|
+
var _this;
|
|
1897
1928
|
|
|
1898
|
-
|
|
1899
|
-
|
|
1929
|
+
_this = _Error.call(this, message) || this;
|
|
1930
|
+
_this.isUnsupportedError = void 0;
|
|
1931
|
+
_this.isUnsupportedError = true;
|
|
1932
|
+
return _this;
|
|
1900
1933
|
}
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
var initialState = {
|
|
1904
|
-
entries: {},
|
|
1905
|
-
assets: {},
|
|
1906
|
-
scheduledActions: {},
|
|
1907
|
-
resources: {}
|
|
1908
|
-
};
|
|
1909
1934
|
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1935
|
+
return UnsupportedError;
|
|
1936
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1937
|
+
function isUnsupportedError(value) {
|
|
1938
|
+
return typeof value === 'object' && (value == null ? void 0 : value.isUnsupportedError) === true;
|
|
1939
|
+
}
|
|
1913
1940
|
|
|
1914
|
-
var
|
|
1915
|
-
return
|
|
1916
|
-
var value = _ref[1];
|
|
1917
|
-
return isNotNil(value);
|
|
1918
|
-
});
|
|
1941
|
+
var isEntityQueryKey = function isEntityQueryKey(queryKey) {
|
|
1942
|
+
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
1919
1943
|
};
|
|
1920
1944
|
|
|
1921
|
-
function
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
var _React$useState = useState(function () {
|
|
1926
|
-
return createClient({
|
|
1927
|
-
apiAdapter: props.sdk.cmaAdapter
|
|
1928
|
-
}, {
|
|
1929
|
-
type: 'plain'
|
|
1930
|
-
});
|
|
1931
|
-
}),
|
|
1932
|
-
cmaClient = _React$useState[0];
|
|
1933
|
-
|
|
1934
|
-
var _React$useReducer = useReducer(reducer, initialState),
|
|
1935
|
-
state = _React$useReducer[0],
|
|
1936
|
-
dispatch = _React$useReducer[1];
|
|
1937
|
-
|
|
1938
|
-
var loadEntityScheduledActions = useCallback(function (entityType, id) {
|
|
1939
|
-
var key = entityType + ":" + id;
|
|
1940
|
-
|
|
1941
|
-
if (state.scheduledActions[key]) {
|
|
1942
|
-
return Promise.resolve(state.scheduledActions[key]);
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
return props.sdk.space.getEntityScheduledActions(entityType, id).then(function (data) {
|
|
1946
|
-
dispatch({
|
|
1947
|
-
type: 'set_scheduled_actions',
|
|
1948
|
-
key: key,
|
|
1949
|
-
actions: data
|
|
1950
|
-
});
|
|
1951
|
-
return data;
|
|
1952
|
-
})["catch"](function () {
|
|
1953
|
-
dispatch({
|
|
1954
|
-
type: 'set_scheduled_actions',
|
|
1955
|
-
key: key,
|
|
1956
|
-
actions: undefined
|
|
1957
|
-
});
|
|
1958
|
-
return [];
|
|
1959
|
-
});
|
|
1960
|
-
}, [props.sdk.space, state.scheduledActions]);
|
|
1961
|
-
var loadEntry = useCallback( /*#__PURE__*/function () {
|
|
1962
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(entryId) {
|
|
1963
|
-
var entry;
|
|
1964
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1965
|
-
while (1) {
|
|
1966
|
-
switch (_context.prev = _context.next) {
|
|
1967
|
-
case 0:
|
|
1968
|
-
_context.prev = 0;
|
|
1969
|
-
_context.next = 3;
|
|
1970
|
-
return cmaClient.entry.get({
|
|
1971
|
-
spaceId: spaceId,
|
|
1972
|
-
environmentId: environmentId,
|
|
1973
|
-
entryId: entryId
|
|
1974
|
-
});
|
|
1975
|
-
|
|
1976
|
-
case 3:
|
|
1977
|
-
entry = _context.sent;
|
|
1978
|
-
dispatch({
|
|
1979
|
-
type: 'set_entry',
|
|
1980
|
-
id: entryId,
|
|
1981
|
-
entry: entry
|
|
1982
|
-
});
|
|
1983
|
-
return _context.abrupt("return", entry);
|
|
1984
|
-
|
|
1985
|
-
case 8:
|
|
1986
|
-
_context.prev = 8;
|
|
1987
|
-
_context.t0 = _context["catch"](0);
|
|
1988
|
-
dispatch({
|
|
1989
|
-
type: 'set_entry_failed',
|
|
1990
|
-
id: entryId
|
|
1991
|
-
});
|
|
1992
|
-
return _context.abrupt("return");
|
|
1993
|
-
|
|
1994
|
-
case 12:
|
|
1995
|
-
case "end":
|
|
1996
|
-
return _context.stop();
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
}, _callee, null, [[0, 8]]);
|
|
2000
|
-
}));
|
|
2001
|
-
|
|
2002
|
-
return function (_x) {
|
|
2003
|
-
return _ref2.apply(this, arguments);
|
|
2004
|
-
};
|
|
2005
|
-
}(), [cmaClient, spaceId, environmentId]);
|
|
2006
|
-
var getEntry = useCallback( /*#__PURE__*/function () {
|
|
2007
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(entryId) {
|
|
2008
|
-
var cachedEntry;
|
|
2009
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2010
|
-
while (1) {
|
|
2011
|
-
switch (_context2.prev = _context2.next) {
|
|
2012
|
-
case 0:
|
|
2013
|
-
cachedEntry = state.entries[entryId];
|
|
2014
|
-
|
|
2015
|
-
if (!isNotNil(cachedEntry)) {
|
|
2016
|
-
_context2.next = 3;
|
|
2017
|
-
break;
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
return _context2.abrupt("return", cachedEntry);
|
|
2021
|
-
|
|
2022
|
-
case 3:
|
|
2023
|
-
return _context2.abrupt("return", loadEntry(entryId));
|
|
2024
|
-
|
|
2025
|
-
case 4:
|
|
2026
|
-
case "end":
|
|
2027
|
-
return _context2.stop();
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
}, _callee2);
|
|
2031
|
-
}));
|
|
2032
|
-
|
|
2033
|
-
return function (_x2) {
|
|
2034
|
-
return _ref3.apply(this, arguments);
|
|
2035
|
-
};
|
|
2036
|
-
}(), [loadEntry, state.entries]);
|
|
2037
|
-
var loadAsset = useCallback( /*#__PURE__*/function () {
|
|
2038
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(assetId) {
|
|
2039
|
-
var asset;
|
|
2040
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
2041
|
-
while (1) {
|
|
2042
|
-
switch (_context3.prev = _context3.next) {
|
|
2043
|
-
case 0:
|
|
2044
|
-
_context3.prev = 0;
|
|
2045
|
-
_context3.next = 3;
|
|
2046
|
-
return cmaClient.asset.get({
|
|
2047
|
-
spaceId: spaceId,
|
|
2048
|
-
environmentId: environmentId,
|
|
2049
|
-
assetId: assetId
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
case 3:
|
|
2053
|
-
asset = _context3.sent;
|
|
2054
|
-
dispatch({
|
|
2055
|
-
type: 'set_asset',
|
|
2056
|
-
id: assetId,
|
|
2057
|
-
asset: asset
|
|
2058
|
-
});
|
|
2059
|
-
return _context3.abrupt("return", asset);
|
|
2060
|
-
|
|
2061
|
-
case 8:
|
|
2062
|
-
_context3.prev = 8;
|
|
2063
|
-
_context3.t0 = _context3["catch"](0);
|
|
2064
|
-
dispatch({
|
|
2065
|
-
type: 'set_asset_failed',
|
|
2066
|
-
id: assetId
|
|
2067
|
-
});
|
|
2068
|
-
return _context3.abrupt("return");
|
|
2069
|
-
|
|
2070
|
-
case 12:
|
|
2071
|
-
case "end":
|
|
2072
|
-
return _context3.stop();
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
}, _callee3, null, [[0, 8]]);
|
|
2076
|
-
}));
|
|
2077
|
-
|
|
2078
|
-
return function (_x3) {
|
|
2079
|
-
return _ref4.apply(this, arguments);
|
|
2080
|
-
};
|
|
2081
|
-
}(), [cmaClient, spaceId, environmentId]);
|
|
2082
|
-
var getAsset = useCallback( /*#__PURE__*/function () {
|
|
2083
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(assetId) {
|
|
2084
|
-
var cachedAsset;
|
|
2085
|
-
return runtime_1.wrap(function _callee4$(_context4) {
|
|
2086
|
-
while (1) {
|
|
2087
|
-
switch (_context4.prev = _context4.next) {
|
|
2088
|
-
case 0:
|
|
2089
|
-
cachedAsset = state.assets[assetId];
|
|
2090
|
-
|
|
2091
|
-
if (!isNotNil(cachedAsset)) {
|
|
2092
|
-
_context4.next = 3;
|
|
2093
|
-
break;
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
return _context4.abrupt("return", cachedAsset);
|
|
2097
|
-
|
|
2098
|
-
case 3:
|
|
2099
|
-
return _context4.abrupt("return", loadAsset(assetId));
|
|
2100
|
-
|
|
2101
|
-
case 4:
|
|
2102
|
-
case "end":
|
|
2103
|
-
return _context4.stop();
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
}, _callee4);
|
|
2107
|
-
}));
|
|
2108
|
-
|
|
2109
|
-
return function (_x4) {
|
|
2110
|
-
return _ref5.apply(this, arguments);
|
|
2111
|
-
};
|
|
2112
|
-
}(), [loadAsset, state.assets]);
|
|
2113
|
-
var loadContentfulEntry = useCallback( /*#__PURE__*/function () {
|
|
2114
|
-
var _ref6 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(urn) {
|
|
2115
|
-
var _locales$items$find;
|
|
1945
|
+
function fetchContentfulEntry(_x) {
|
|
1946
|
+
return _fetchContentfulEntry.apply(this, arguments);
|
|
1947
|
+
}
|
|
2116
1948
|
|
|
2117
|
-
|
|
1949
|
+
function _fetchContentfulEntry() {
|
|
1950
|
+
_fetchContentfulEntry = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(params) {
|
|
1951
|
+
var urn, fetch, options, resourceId, _resourceId$split, spaceId, entryId, environmentId, _yield$Promise$all, space, entry, contentTypeId, _yield$Promise$all2, contentType, defaultLocaleCode;
|
|
2118
1952
|
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
1953
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1954
|
+
while (1) {
|
|
1955
|
+
switch (_context3.prev = _context3.next) {
|
|
1956
|
+
case 0:
|
|
1957
|
+
urn = params.urn, fetch = params.fetch, options = params.options;
|
|
1958
|
+
resourceId = urn.split(':', 6)[5];
|
|
1959
|
+
_resourceId$split = resourceId.split('/'), spaceId = _resourceId$split[1], entryId = _resourceId$split[3];
|
|
1960
|
+
environmentId = 'master';
|
|
1961
|
+
_context3.next = 6;
|
|
1962
|
+
return Promise.all([fetch(['space', spaceId], function (_ref9) {
|
|
1963
|
+
var cmaClient = _ref9.cmaClient;
|
|
2128
1964
|
return cmaClient.space.get({
|
|
2129
1965
|
spaceId: spaceId
|
|
2130
1966
|
});
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
_context5.t1 = _context5.sent;
|
|
2134
|
-
_context5.next = 9;
|
|
1967
|
+
}, options), fetch(['entry', spaceId, environmentId, entryId], function (_ref10) {
|
|
1968
|
+
var cmaClient = _ref10.cmaClient;
|
|
2135
1969
|
return cmaClient.entry.get({
|
|
2136
1970
|
spaceId: spaceId,
|
|
2137
1971
|
environmentId: environmentId,
|
|
2138
1972
|
entryId: entryId
|
|
2139
1973
|
});
|
|
1974
|
+
}, options)]);
|
|
2140
1975
|
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
space = _yield$Promise$all[0];
|
|
2150
|
-
entry = _yield$Promise$all[1];
|
|
2151
|
-
contentTypeId = entry.sys.contentType.sys.id;
|
|
2152
|
-
_context5.t4 = Promise;
|
|
2153
|
-
_context5.next = 20;
|
|
1976
|
+
case 6:
|
|
1977
|
+
_yield$Promise$all = _context3.sent;
|
|
1978
|
+
space = _yield$Promise$all[0];
|
|
1979
|
+
entry = _yield$Promise$all[1];
|
|
1980
|
+
contentTypeId = entry.sys.contentType.sys.id;
|
|
1981
|
+
_context3.next = 12;
|
|
1982
|
+
return Promise.all([fetch(['contentType', spaceId, environmentId, contentTypeId], function (_ref11) {
|
|
1983
|
+
var cmaClient = _ref11.cmaClient;
|
|
2154
1984
|
return cmaClient.contentType.get({
|
|
2155
1985
|
contentTypeId: contentTypeId,
|
|
2156
1986
|
spaceId: spaceId,
|
|
2157
1987
|
environmentId: environmentId
|
|
2158
1988
|
});
|
|
1989
|
+
}, options), fetch(['defaultLocale', spaceId, environmentId], /*#__PURE__*/function () {
|
|
1990
|
+
var _ref13 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref12) {
|
|
1991
|
+
var _locales$items$find;
|
|
2159
1992
|
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
1993
|
+
var cmaClient, locales, defaultLocaleCode;
|
|
1994
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1995
|
+
while (1) {
|
|
1996
|
+
switch (_context2.prev = _context2.next) {
|
|
1997
|
+
case 0:
|
|
1998
|
+
cmaClient = _ref12.cmaClient;
|
|
1999
|
+
_context2.next = 3;
|
|
2000
|
+
return cmaClient.locale.getMany({
|
|
2001
|
+
spaceId: spaceId,
|
|
2002
|
+
environmentId: environmentId,
|
|
2003
|
+
query: {
|
|
2004
|
+
limit: 100
|
|
2005
|
+
}
|
|
2006
|
+
});
|
|
2007
|
+
|
|
2008
|
+
case 3:
|
|
2009
|
+
locales = _context2.sent;
|
|
2010
|
+
defaultLocaleCode = (_locales$items$find = locales.items.find(function (locale) {
|
|
2011
|
+
return locale["default"];
|
|
2012
|
+
})) == null ? void 0 : _locales$items$find.code;
|
|
2013
|
+
return _context2.abrupt("return", defaultLocaleCode);
|
|
2170
2014
|
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
_yield$Promise$all2 = _context5.sent;
|
|
2179
|
-
contentType = _yield$Promise$all2[0];
|
|
2180
|
-
locales = _yield$Promise$all2[1];
|
|
2181
|
-
defaultLocaleCode = (_locales$items$find = locales.items.find(function (locale) {
|
|
2182
|
-
return locale["default"];
|
|
2183
|
-
})) == null ? void 0 : _locales$items$find.code;
|
|
2184
|
-
return _context5.abrupt("return", {
|
|
2185
|
-
resource: entry,
|
|
2186
|
-
defaultLocaleCode: defaultLocaleCode,
|
|
2187
|
-
space: space,
|
|
2188
|
-
contentType: contentType
|
|
2189
|
-
});
|
|
2015
|
+
case 6:
|
|
2016
|
+
case "end":
|
|
2017
|
+
return _context2.stop();
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}, _callee2);
|
|
2021
|
+
}));
|
|
2190
2022
|
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2023
|
+
return function (_x3) {
|
|
2024
|
+
return _ref13.apply(this, arguments);
|
|
2025
|
+
};
|
|
2026
|
+
}(), options)]);
|
|
2027
|
+
|
|
2028
|
+
case 12:
|
|
2029
|
+
_yield$Promise$all2 = _context3.sent;
|
|
2030
|
+
contentType = _yield$Promise$all2[0];
|
|
2031
|
+
defaultLocaleCode = _yield$Promise$all2[1];
|
|
2032
|
+
return _context3.abrupt("return", {
|
|
2033
|
+
defaultLocaleCode: defaultLocaleCode,
|
|
2034
|
+
resource: entry,
|
|
2035
|
+
space: space,
|
|
2036
|
+
contentType: contentType
|
|
2037
|
+
});
|
|
2198
2038
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
switch (_context6.prev = _context6.next) {
|
|
2209
|
-
case 0:
|
|
2210
|
-
cachedResource = state.resources[resourceType + "." + urn];
|
|
2039
|
+
case 16:
|
|
2040
|
+
case "end":
|
|
2041
|
+
return _context3.stop();
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
}, _callee3);
|
|
2045
|
+
}));
|
|
2046
|
+
return _fetchContentfulEntry.apply(this, arguments);
|
|
2047
|
+
}
|
|
2211
2048
|
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2049
|
+
var _constate = /*#__PURE__*/constate(function useInitServices(props) {
|
|
2050
|
+
var currentSpaceId = props.sdk.ids.space;
|
|
2051
|
+
var currentEnvironmentId = props.sdk.ids.environment;
|
|
2052
|
+
var queryClient = useQueryClient();
|
|
2053
|
+
var queryCache = queryClient.getQueryCache();
|
|
2054
|
+
var entityChangeUnsubscribers = useRef({});
|
|
2055
|
+
var cmaClient = useMemo(function () {
|
|
2056
|
+
return createClient({
|
|
2057
|
+
apiAdapter: props.sdk.cmaAdapter
|
|
2058
|
+
}, {
|
|
2059
|
+
type: 'plain'
|
|
2060
|
+
});
|
|
2061
|
+
}, [props.sdk.cmaAdapter]);
|
|
2062
|
+
var queryQueue = useMemo(function () {
|
|
2063
|
+
if (props.queryConcurrency) {
|
|
2064
|
+
return new PQueue({
|
|
2065
|
+
concurrency: props.queryConcurrency
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2216
2068
|
|
|
2217
|
-
|
|
2069
|
+
return globalQueue;
|
|
2070
|
+
}, [props.queryConcurrency]);
|
|
2071
|
+
var fetch = useCallback(function fetch(queryKey, fn, options) {
|
|
2072
|
+
if (options === void 0) {
|
|
2073
|
+
options = {};
|
|
2074
|
+
}
|
|
2218
2075
|
|
|
2219
|
-
|
|
2220
|
-
|
|
2076
|
+
var _options = options,
|
|
2077
|
+
priority = _options.priority,
|
|
2078
|
+
queryOptions = _objectWithoutPropertiesLoose(_options, _excluded$1);
|
|
2221
2079
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2080
|
+
return queryClient.fetchQuery(queryKey, function () {
|
|
2081
|
+
return queryQueue.add(function () {
|
|
2082
|
+
return fn({
|
|
2083
|
+
cmaClient: cmaClient
|
|
2084
|
+
});
|
|
2085
|
+
}, {
|
|
2086
|
+
priority: priority
|
|
2087
|
+
});
|
|
2088
|
+
}, queryOptions);
|
|
2089
|
+
}, [queryClient, queryQueue, cmaClient]);
|
|
2090
|
+
var getEntity = useCallback(function getEntity(entityType, entityId, options) {
|
|
2091
|
+
var _options$spaceId, _options$environmentI;
|
|
2092
|
+
|
|
2093
|
+
var spaceId = (_options$spaceId = options == null ? void 0 : options.spaceId) != null ? _options$spaceId : currentSpaceId;
|
|
2094
|
+
var environmentId = (_options$environmentI = options == null ? void 0 : options.environmentId) != null ? _options$environmentI : currentEnvironmentId;
|
|
2095
|
+
var queryKey = [entityType, entityId, spaceId, environmentId];
|
|
2096
|
+
return fetch(queryKey, function (_ref) {
|
|
2097
|
+
var cmaClient = _ref.cmaClient;
|
|
2098
|
+
|
|
2099
|
+
if (entityType === 'Entry') {
|
|
2100
|
+
return cmaClient.entry.get({
|
|
2101
|
+
entryId: entityId,
|
|
2102
|
+
spaceId: spaceId,
|
|
2103
|
+
environmentId: environmentId
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2226
2106
|
|
|
2227
|
-
|
|
2228
|
-
|
|
2107
|
+
if (entityType === 'Asset') {
|
|
2108
|
+
return cmaClient.asset.get({
|
|
2109
|
+
assetId: entityId,
|
|
2110
|
+
spaceId: spaceId,
|
|
2111
|
+
environmentId: environmentId
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2229
2114
|
|
|
2230
|
-
|
|
2231
|
-
|
|
2115
|
+
throw new UnsupportedError('Unsupported entity type');
|
|
2116
|
+
}, options);
|
|
2117
|
+
}, [fetch, currentSpaceId, currentEnvironmentId]);
|
|
2118
|
+
var getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
|
|
2119
|
+
var _options$spaceId2, _options$environmentI2;
|
|
2120
|
+
|
|
2121
|
+
var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
|
|
2122
|
+
var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
|
|
2123
|
+
var queryKey = ['scheduled-actions', entityType, entityId, spaceId, environmentId];
|
|
2124
|
+
return fetch(queryKey, /*#__PURE__*/function () {
|
|
2125
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
|
|
2126
|
+
var cmaClient, response;
|
|
2127
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
2128
|
+
while (1) {
|
|
2129
|
+
switch (_context.prev = _context.next) {
|
|
2130
|
+
case 0:
|
|
2131
|
+
cmaClient = _ref2.cmaClient;
|
|
2132
|
+
_context.next = 3;
|
|
2133
|
+
return cmaClient.scheduledActions.getMany({
|
|
2134
|
+
spaceId: spaceId,
|
|
2135
|
+
query: {
|
|
2136
|
+
'environment.sys.id': environmentId,
|
|
2137
|
+
'entity.sys.id': entityId,
|
|
2138
|
+
'sys.status[in]': 'scheduled',
|
|
2139
|
+
order: 'scheduledFor.datetime'
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2232
2142
|
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
resourceType: resourceType,
|
|
2237
|
-
urn: urn,
|
|
2238
|
-
resourceInfo: resourceInfo
|
|
2239
|
-
});
|
|
2240
|
-
return _context6.abrupt("return", resourceInfo);
|
|
2241
|
-
|
|
2242
|
-
case 12:
|
|
2243
|
-
_context6.prev = 12;
|
|
2244
|
-
_context6.t0 = _context6["catch"](3);
|
|
2245
|
-
dispatch({
|
|
2246
|
-
type: 'set_resource_failed',
|
|
2247
|
-
resourceType: resourceType,
|
|
2248
|
-
urn: urn
|
|
2249
|
-
});
|
|
2250
|
-
return _context6.abrupt("return");
|
|
2143
|
+
case 3:
|
|
2144
|
+
response = _context.sent;
|
|
2145
|
+
return _context.abrupt("return", response.items);
|
|
2251
2146
|
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2147
|
+
case 5:
|
|
2148
|
+
case "end":
|
|
2149
|
+
return _context.stop();
|
|
2150
|
+
}
|
|
2255
2151
|
}
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
}));
|
|
2152
|
+
}, _callee);
|
|
2153
|
+
}));
|
|
2259
2154
|
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
};
|
|
2263
|
-
}(), [loadContentfulEntry, state.resources]);
|
|
2264
|
-
useEffect(function () {
|
|
2265
|
-
// @ts-expect-error
|
|
2266
|
-
if (typeof props.sdk.space.onEntityChanged !== 'undefined') {
|
|
2267
|
-
// @ts-expect-error
|
|
2268
|
-
var onEntityChanged = props.sdk.space.onEntityChanged;
|
|
2269
|
-
var listeners = [];
|
|
2270
|
-
|
|
2271
|
-
var _loop = function _loop() {
|
|
2272
|
-
var _step$value = _step.value,
|
|
2273
|
-
id = _step$value[0];
|
|
2274
|
-
listeners.push(onEntityChanged('Entry', id, function (entry) {
|
|
2275
|
-
return dispatch({
|
|
2276
|
-
type: 'set_entry',
|
|
2277
|
-
id: id,
|
|
2278
|
-
entry: entry
|
|
2279
|
-
});
|
|
2280
|
-
}));
|
|
2155
|
+
return function (_x2) {
|
|
2156
|
+
return _ref3.apply(this, arguments);
|
|
2281
2157
|
};
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2158
|
+
}(), options);
|
|
2159
|
+
}, [fetch, currentSpaceId, currentEnvironmentId]);
|
|
2160
|
+
var getResource = useCallback(function getResource(resourceType, urn, options) {
|
|
2161
|
+
var queryKey = ['Resource', resourceType, urn];
|
|
2162
|
+
return fetch(queryKey, function () {
|
|
2163
|
+
if (resourceType === 'Contentful:Entry') {
|
|
2164
|
+
return fetchContentfulEntry({
|
|
2165
|
+
fetch: fetch,
|
|
2166
|
+
urn: urn,
|
|
2167
|
+
options: options
|
|
2168
|
+
});
|
|
2285
2169
|
}
|
|
2286
2170
|
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2171
|
+
throw new UnsupportedError('Unsupported resource type');
|
|
2172
|
+
}, options);
|
|
2173
|
+
}, [fetch]);
|
|
2174
|
+
var isSameSpaceEntityQueryKey = useCallback(function (queryKey) {
|
|
2175
|
+
var isEntityKey = isEntityQueryKey(queryKey);
|
|
2176
|
+
var isSameSpaceEntityKey = isEntityKey && queryKey[2] === currentSpaceId && queryKey[3] === currentEnvironmentId;
|
|
2177
|
+
return isSameSpaceEntityKey;
|
|
2178
|
+
}, [currentSpaceId, currentEnvironmentId]); // @ts-expect-error ...
|
|
2179
|
+
|
|
2180
|
+
// @ts-expect-error ...
|
|
2181
|
+
var onEntityChanged = props.sdk.space.onEntityChanged;
|
|
2182
|
+
useEffect(function () {
|
|
2183
|
+
if (typeof onEntityChanged !== 'function') {
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
var subscribeQuery = function subscribeQuery(_ref4) {
|
|
2188
|
+
var queryKey = _ref4.queryKey,
|
|
2189
|
+
queryHash = _ref4.queryHash;
|
|
2190
|
+
var entityType = queryKey[0],
|
|
2191
|
+
entityId = queryKey[1];
|
|
2192
|
+
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, function (data) {
|
|
2193
|
+
queryClient.setQueryData(queryKey, data);
|
|
2194
|
+
});
|
|
2195
|
+
};
|
|
2298
2196
|
|
|
2299
|
-
|
|
2300
|
-
|
|
2197
|
+
var queries = queryCache.findAll({
|
|
2198
|
+
type: 'active',
|
|
2199
|
+
predicate: function predicate(query) {
|
|
2200
|
+
return isSameSpaceEntityQueryKey(query.queryKey);
|
|
2201
|
+
}
|
|
2202
|
+
});
|
|
2203
|
+
queries.forEach(subscribeQuery);
|
|
2204
|
+
var unsubscribe = queryCache.subscribe(function (event) {
|
|
2205
|
+
if (!event) {
|
|
2206
|
+
return;
|
|
2301
2207
|
}
|
|
2302
2208
|
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2209
|
+
var type = event.type,
|
|
2210
|
+
query = event.query;
|
|
2211
|
+
var queryKey = query.queryKey,
|
|
2212
|
+
queryHash = query.queryHash;
|
|
2213
|
+
|
|
2214
|
+
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
2215
|
+
return;
|
|
2216
|
+
}
|
|
2309
2217
|
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2218
|
+
if (type === 'added') {
|
|
2219
|
+
subscribeQuery(query);
|
|
2220
|
+
}
|
|
2313
2221
|
|
|
2314
|
-
if (
|
|
2315
|
-
|
|
2316
|
-
var _step3$value = _step3.value,
|
|
2317
|
-
id = _step3$value[0];
|
|
2318
|
-
loadEntry(id);
|
|
2319
|
-
}
|
|
2222
|
+
if (type === 'removed') {
|
|
2223
|
+
var _entityChangeUnsubscr, _entityChangeUnsubscr2;
|
|
2320
2224
|
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
_id = _step4$value[0];
|
|
2324
|
-
loadAsset(_id);
|
|
2325
|
-
}
|
|
2225
|
+
// calling unsubscribe
|
|
2226
|
+
(_entityChangeUnsubscr = (_entityChangeUnsubscr2 = entityChangeUnsubscribers.current)[queryHash]) == null ? void 0 : _entityChangeUnsubscr.call(_entityChangeUnsubscr2);
|
|
2326
2227
|
}
|
|
2327
|
-
});
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
getOrLoadEntry: getEntry,
|
|
2335
|
-
|
|
2336
|
-
/**
|
|
2337
|
-
* @deprecated use `getAsset` instead
|
|
2338
|
-
*/
|
|
2339
|
-
getOrLoadAsset: getAsset,
|
|
2340
|
-
getResource: getResource,
|
|
2341
|
-
getEntry: getEntry,
|
|
2342
|
-
getAsset: getAsset,
|
|
2343
|
-
loadEntityScheduledActions: loadEntityScheduledActions,
|
|
2344
|
-
entries: state.entries,
|
|
2345
|
-
assets: state.assets,
|
|
2346
|
-
scheduledActions: state.scheduledActions,
|
|
2347
|
-
resources: state.resources
|
|
2228
|
+
});
|
|
2229
|
+
return function () {
|
|
2230
|
+
unsubscribe();
|
|
2231
|
+
Object.values(entityChangeUnsubscribers.current).forEach(function (off) {
|
|
2232
|
+
return off();
|
|
2233
|
+
});
|
|
2234
|
+
entityChangeUnsubscribers.current = {};
|
|
2348
2235
|
};
|
|
2349
|
-
}, [
|
|
2236
|
+
}, [onEntityChanged, queryCache, isSameSpaceEntityQueryKey, queryClient]);
|
|
2237
|
+
return {
|
|
2238
|
+
cmaClient: cmaClient,
|
|
2239
|
+
fetch: fetch,
|
|
2240
|
+
getResource: getResource,
|
|
2241
|
+
getEntity: getEntity,
|
|
2242
|
+
ids: props.sdk.ids,
|
|
2243
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
2244
|
+
};
|
|
2245
|
+
}, function (_ref5) {
|
|
2246
|
+
var fetch = _ref5.fetch;
|
|
2247
|
+
return fetch;
|
|
2248
|
+
}, function (_ref6) {
|
|
2249
|
+
var getResource = _ref6.getResource,
|
|
2250
|
+
getEntity = _ref6.getEntity,
|
|
2251
|
+
getEntityScheduledActions = _ref6.getEntityScheduledActions;
|
|
2252
|
+
return {
|
|
2253
|
+
getResource: getResource,
|
|
2254
|
+
getEntity: getEntity,
|
|
2255
|
+
getEntityScheduledActions: getEntityScheduledActions
|
|
2256
|
+
};
|
|
2257
|
+
}, function (_ref7) {
|
|
2258
|
+
var ids = _ref7.ids;
|
|
2259
|
+
return ids;
|
|
2260
|
+
}),
|
|
2261
|
+
InternalServiceProvider = _constate[0],
|
|
2262
|
+
useEntityLoader = _constate[2],
|
|
2263
|
+
useCurrentIds = _constate[3];
|
|
2264
|
+
|
|
2265
|
+
function useEntity(entityType, entityId, options) {
|
|
2266
|
+
var _options$spaceId3, _options$environmentI3;
|
|
2267
|
+
|
|
2268
|
+
var _useCurrentIds = useCurrentIds(),
|
|
2269
|
+
space = _useCurrentIds.space,
|
|
2270
|
+
environment = _useCurrentIds.environment;
|
|
2271
|
+
|
|
2272
|
+
var _useEntityLoader = useEntityLoader(),
|
|
2273
|
+
getEntity = _useEntityLoader.getEntity;
|
|
2274
|
+
|
|
2275
|
+
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];
|
|
2276
|
+
|
|
2277
|
+
var _useQuery = useQuery(queryKey, function () {
|
|
2278
|
+
return getEntity(entityType, entityId, options);
|
|
2279
|
+
}, {
|
|
2280
|
+
enabled: options == null ? void 0 : options.enabled
|
|
2281
|
+
}),
|
|
2282
|
+
status = _useQuery.status,
|
|
2283
|
+
data = _useQuery.data;
|
|
2284
|
+
|
|
2285
|
+
return {
|
|
2286
|
+
status: status,
|
|
2287
|
+
data: data
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
function useResource(resourceType, urn, options) {
|
|
2291
|
+
var queryKey = ['Resource', resourceType, urn];
|
|
2292
|
+
|
|
2293
|
+
var _useEntityLoader2 = useEntityLoader(),
|
|
2294
|
+
getResource = _useEntityLoader2.getResource;
|
|
2295
|
+
|
|
2296
|
+
var _useQuery2 = useQuery(queryKey, function () {
|
|
2297
|
+
return getResource(resourceType, urn, options);
|
|
2298
|
+
}, {
|
|
2299
|
+
enabled: options == null ? void 0 : options.enabled
|
|
2300
|
+
}),
|
|
2301
|
+
status = _useQuery2.status,
|
|
2302
|
+
data = _useQuery2.data,
|
|
2303
|
+
error = _useQuery2.error;
|
|
2304
|
+
|
|
2305
|
+
return {
|
|
2306
|
+
status: status,
|
|
2307
|
+
data: data,
|
|
2308
|
+
error: error
|
|
2309
|
+
};
|
|
2350
2310
|
}
|
|
2351
2311
|
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2312
|
+
function EntityProvider(_ref8) {
|
|
2313
|
+
var children = _ref8.children,
|
|
2314
|
+
props = _objectWithoutPropertiesLoose(_ref8, _excluded2);
|
|
2315
|
+
|
|
2316
|
+
var reactQueryClient = useMemo(function () {
|
|
2317
|
+
var queryCache = new QueryCache();
|
|
2318
|
+
var queryClient = new QueryClient({
|
|
2319
|
+
queryCache: queryCache,
|
|
2320
|
+
defaultOptions: {
|
|
2321
|
+
queries: {
|
|
2322
|
+
useErrorBoundary: false,
|
|
2323
|
+
refetchOnWindowFocus: false,
|
|
2324
|
+
refetchOnReconnect: true,
|
|
2325
|
+
refetchOnMount: false,
|
|
2326
|
+
staleTime: Infinity,
|
|
2327
|
+
retry: false
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
});
|
|
2331
|
+
return queryClient;
|
|
2332
|
+
}, []);
|
|
2333
|
+
return React__default.createElement(QueryClientProvider, {
|
|
2334
|
+
client: reactQueryClient
|
|
2335
|
+
}, React__default.createElement(InternalServiceProvider, _extends({}, props), children));
|
|
2336
|
+
}
|
|
2355
2337
|
|
|
2356
2338
|
function ReferenceEditor(props) {
|
|
2357
2339
|
return createElement(EntityProvider, {
|
|
@@ -2573,7 +2555,10 @@ function fromFieldValidations(field) {
|
|
|
2573
2555
|
var result = {
|
|
2574
2556
|
contentTypes: (_linkContentTypeValid = linkContentTypeValidations == null ? void 0 : linkContentTypeValidations.linkContentType) != null ? _linkContentTypeValid : undefined,
|
|
2575
2557
|
mimetypeGroups: (_linkMimetypeGroupVal = linkMimetypeGroupValidations == null ? void 0 : linkMimetypeGroupValidations.linkMimetypeGroup) != null ? _linkMimetypeGroupVal : undefined,
|
|
2576
|
-
numberOfLinks: numberOfLinks
|
|
2558
|
+
numberOfLinks: numberOfLinks // todo: there are multiple BE problems that need to be solved first, for now we don't want to apply size constraints
|
|
2559
|
+
// linkedFileSize: findValidation(field, 'assetFileSize', {}),
|
|
2560
|
+
// linkedImageDimensions: findValidation(field, 'assetImageDimensions', {})
|
|
2561
|
+
|
|
2577
2562
|
};
|
|
2578
2563
|
return result;
|
|
2579
2564
|
}
|
|
@@ -2772,7 +2757,7 @@ function Editor(props) {
|
|
|
2772
2757
|
[linkActionsProps]);
|
|
2773
2758
|
|
|
2774
2759
|
if (!props.entityId) {
|
|
2775
|
-
return createElement(LinkEntityActions,
|
|
2760
|
+
return createElement(LinkEntityActions, _extends({
|
|
2776
2761
|
renderCustomActions: props.renderCustomActions
|
|
2777
2762
|
}, linkActionsProps));
|
|
2778
2763
|
}
|
|
@@ -2784,12 +2769,12 @@ function Editor(props) {
|
|
|
2784
2769
|
|
|
2785
2770
|
function SingleReferenceEditor(props) {
|
|
2786
2771
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
2787
|
-
return createElement(ReferenceEditor,
|
|
2772
|
+
return createElement(ReferenceEditor, _extends({}, props), function (_ref) {
|
|
2788
2773
|
var value = _ref.value,
|
|
2789
2774
|
setValue = _ref.setValue,
|
|
2790
2775
|
disabled = _ref.disabled,
|
|
2791
2776
|
externalReset = _ref.externalReset;
|
|
2792
|
-
return createElement(Editor,
|
|
2777
|
+
return createElement(Editor, _extends({}, props, {
|
|
2793
2778
|
key: externalReset + "-reference",
|
|
2794
2779
|
entityId: value ? value.sys.id : '',
|
|
2795
2780
|
isDisabled: disabled,
|
|
@@ -3019,18 +3004,24 @@ function _openEntry() {
|
|
|
3019
3004
|
}
|
|
3020
3005
|
|
|
3021
3006
|
function FetchingWrappedEntryCard(props) {
|
|
3022
|
-
var
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions,
|
|
3026
|
-
entries = _useEntities.entries;
|
|
3007
|
+
var _useEntity = useEntity('Entry', props.entryId),
|
|
3008
|
+
entry = _useEntity.data,
|
|
3009
|
+
status = _useEntity.status;
|
|
3027
3010
|
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3011
|
+
var _useEntityLoader = useEntityLoader(),
|
|
3012
|
+
getEntityScheduledActions = _useEntityLoader.getEntityScheduledActions;
|
|
3013
|
+
|
|
3014
|
+
var loadEntityScheduledActions = useCallback(function () {
|
|
3015
|
+
return getEntityScheduledActions('Entry', props.entryId);
|
|
3016
|
+
}, [getEntityScheduledActions, props.entryId]);
|
|
3031
3017
|
var size = props.viewType === 'link' ? 'small' : 'default';
|
|
3032
|
-
|
|
3033
|
-
var
|
|
3018
|
+
|
|
3019
|
+
var _useEntityLoader2 = useEntityLoader(),
|
|
3020
|
+
getEntity = _useEntityLoader2.getEntity;
|
|
3021
|
+
|
|
3022
|
+
var getAsset = function getAsset(assetId) {
|
|
3023
|
+
return getEntity('Asset', assetId);
|
|
3024
|
+
};
|
|
3034
3025
|
|
|
3035
3026
|
var onEdit = /*#__PURE__*/function () {
|
|
3036
3027
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
@@ -3088,7 +3079,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
3088
3079
|
|
|
3089
3080
|
}, [entry]);
|
|
3090
3081
|
return useMemo(function () {
|
|
3091
|
-
if (
|
|
3082
|
+
if (status === 'error') {
|
|
3092
3083
|
var card = createElement(MissingEntityCard, {
|
|
3093
3084
|
entityType: "Entry",
|
|
3094
3085
|
isDisabled: props.isDisabled,
|
|
@@ -3108,7 +3099,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
3108
3099
|
return card;
|
|
3109
3100
|
}
|
|
3110
3101
|
|
|
3111
|
-
if (
|
|
3102
|
+
if (status === 'loading') {
|
|
3112
3103
|
return createElement(EntryCard, {
|
|
3113
3104
|
size: size,
|
|
3114
3105
|
isLoading: true
|
|
@@ -3147,7 +3138,7 @@ function FetchingWrappedEntryCard(props) {
|
|
|
3147
3138
|
entryUrl: (props == null ? void 0 : props.entityUrl) || sharedCardProps.entityUrl
|
|
3148
3139
|
});
|
|
3149
3140
|
|
|
3150
|
-
return createElement(WrappedEntryCard,
|
|
3141
|
+
return createElement(WrappedEntryCard, _extends({}, builtinCardProps));
|
|
3151
3142
|
}
|
|
3152
3143
|
|
|
3153
3144
|
if (props.renderCustomCard) {
|
|
@@ -3160,11 +3151,11 @@ function FetchingWrappedEntryCard(props) {
|
|
|
3160
3151
|
}
|
|
3161
3152
|
|
|
3162
3153
|
return renderDefaultCard(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3163
|
-
}, [props,
|
|
3154
|
+
}, [props, status, entry]);
|
|
3164
3155
|
}
|
|
3165
3156
|
|
|
3166
3157
|
function SingleEntryReferenceEditor(props) {
|
|
3167
|
-
return createElement(SingleReferenceEditor,
|
|
3158
|
+
return createElement(SingleReferenceEditor, _extends({}, props, {
|
|
3168
3159
|
entityType: "Entry"
|
|
3169
3160
|
}), function (_ref) {
|
|
3170
3161
|
var allContentTypes = _ref.allContentTypes,
|
|
@@ -3174,7 +3165,7 @@ function SingleEntryReferenceEditor(props) {
|
|
|
3174
3165
|
renderCustomCard = _ref.renderCustomCard,
|
|
3175
3166
|
hasCardRemoveActions = _ref.hasCardRemoveActions,
|
|
3176
3167
|
hasCardEditActions = _ref.hasCardEditActions;
|
|
3177
|
-
return createElement(FetchingWrappedEntryCard,
|
|
3168
|
+
return createElement(FetchingWrappedEntryCard, _extends({}, props, {
|
|
3178
3169
|
allContentTypes: allContentTypes,
|
|
3179
3170
|
isDisabled: isDisabled,
|
|
3180
3171
|
entryId: entityId,
|
|
@@ -3265,19 +3256,19 @@ function Editor$1(props) {
|
|
|
3265
3256
|
onSortEnd: onSortEnd,
|
|
3266
3257
|
onMove: onMove,
|
|
3267
3258
|
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
3268
|
-
})), createElement(LinkEntityActions,
|
|
3259
|
+
})), createElement(LinkEntityActions, _extends({
|
|
3269
3260
|
renderCustomActions: props.renderCustomActions
|
|
3270
3261
|
}, linkActionsProps)));
|
|
3271
3262
|
}
|
|
3272
3263
|
|
|
3273
3264
|
function MultipleReferenceEditor(props) {
|
|
3274
3265
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
3275
|
-
return createElement(ReferenceEditor,
|
|
3266
|
+
return createElement(ReferenceEditor, _extends({}, props), function (_ref2) {
|
|
3276
3267
|
var value = _ref2.value,
|
|
3277
3268
|
disabled = _ref2.disabled,
|
|
3278
3269
|
setValue = _ref2.setValue,
|
|
3279
3270
|
externalReset = _ref2.externalReset;
|
|
3280
|
-
return createElement(Editor$1,
|
|
3271
|
+
return createElement(Editor$1, _extends({}, props, {
|
|
3281
3272
|
items: value || emptyArray,
|
|
3282
3273
|
isDisabled: disabled,
|
|
3283
3274
|
setValue: setValue,
|
|
@@ -3334,16 +3325,16 @@ var SortableLinkListInternal = /*#__PURE__*/SortableContainer(function (props) {
|
|
|
3334
3325
|
function SortableLinkList(props) {
|
|
3335
3326
|
// with the default distance of 0 the drag start event is "confused" with the click event,
|
|
3336
3327
|
// so the latter one isn't fired and click handlers on child elements don't work
|
|
3337
|
-
return React__default.createElement(SortableLinkListInternal,
|
|
3328
|
+
return React__default.createElement(SortableLinkListInternal, _extends({
|
|
3338
3329
|
distance: 1
|
|
3339
3330
|
}, props), props.children);
|
|
3340
3331
|
}
|
|
3341
3332
|
|
|
3342
3333
|
function MultipleEntryReferenceEditor(props) {
|
|
3343
|
-
return createElement(MultipleReferenceEditor,
|
|
3334
|
+
return createElement(MultipleReferenceEditor, _extends({}, props, {
|
|
3344
3335
|
entityType: "Entry"
|
|
3345
3336
|
}), function (childrenProps) {
|
|
3346
|
-
return createElement(SortableLinkList,
|
|
3337
|
+
return createElement(SortableLinkList, _extends({}, childrenProps, {
|
|
3347
3338
|
axis: "y",
|
|
3348
3339
|
useDragHandle: true
|
|
3349
3340
|
}), function (_ref) {
|
|
@@ -3353,7 +3344,7 @@ function MultipleEntryReferenceEditor(props) {
|
|
|
3353
3344
|
isDisabled = _ref.isDisabled,
|
|
3354
3345
|
DragHandle = _ref.DragHandle;
|
|
3355
3346
|
var lastIndex = items.length - 1;
|
|
3356
|
-
return createElement(FetchingWrappedEntryCard,
|
|
3347
|
+
return createElement(FetchingWrappedEntryCard, _extends({}, childrenProps, {
|
|
3357
3348
|
key: item.sys.id + "-" + index,
|
|
3358
3349
|
index: index,
|
|
3359
3350
|
allContentTypes: childrenProps.allContentTypes,
|
|
@@ -3608,20 +3599,16 @@ var WrappedAssetLink = function WrappedAssetLink(props) {
|
|
|
3608
3599
|
};
|
|
3609
3600
|
|
|
3610
3601
|
function FetchingWrappedAssetCard(props) {
|
|
3611
|
-
var
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
assets = _useEntities.assets;
|
|
3602
|
+
var _useEntity = useEntity('Asset', props.assetId),
|
|
3603
|
+
asset = _useEntity.data,
|
|
3604
|
+
status = _useEntity.status;
|
|
3615
3605
|
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
return;
|
|
3619
|
-
}
|
|
3606
|
+
var _useEntityLoader = useEntityLoader(),
|
|
3607
|
+
getEntityScheduledActions = _useEntityLoader.getEntityScheduledActions;
|
|
3620
3608
|
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
var entityKey = asset === 'failed' ? 'failed' : asset === undefined ? 'undefined' : ":" + asset.sys.id + ":" + asset.sys.version;
|
|
3609
|
+
var loadEntityScheduledActions = useCallback(function () {
|
|
3610
|
+
return getEntityScheduledActions('Asset', props.assetId);
|
|
3611
|
+
}, [getEntityScheduledActions, props.assetId]);
|
|
3625
3612
|
useEffect(function () {
|
|
3626
3613
|
if (asset) {
|
|
3627
3614
|
props.onAction && props.onAction({
|
|
@@ -3680,7 +3667,7 @@ function FetchingWrappedAssetCard(props) {
|
|
|
3680
3667
|
};
|
|
3681
3668
|
|
|
3682
3669
|
return useMemo(function () {
|
|
3683
|
-
if (
|
|
3670
|
+
if (status === 'error') {
|
|
3684
3671
|
var card = createElement(MissingEntityCard, {
|
|
3685
3672
|
entityType: "Asset",
|
|
3686
3673
|
asSquare: props.viewType !== 'link',
|
|
@@ -3701,8 +3688,7 @@ function FetchingWrappedAssetCard(props) {
|
|
|
3701
3688
|
return card;
|
|
3702
3689
|
}
|
|
3703
3690
|
|
|
3704
|
-
var getEntityUrl = props.getEntityUrl
|
|
3705
|
-
sdk = props.sdk;
|
|
3691
|
+
var getEntityUrl = props.getEntityUrl;
|
|
3706
3692
|
var size = props.viewType === 'big_card' ? 'default' : 'small';
|
|
3707
3693
|
var commonProps = {
|
|
3708
3694
|
asset: asset,
|
|
@@ -3717,20 +3703,20 @@ function FetchingWrappedAssetCard(props) {
|
|
|
3717
3703
|
};
|
|
3718
3704
|
|
|
3719
3705
|
if (props.viewType === 'link') {
|
|
3720
|
-
if (
|
|
3706
|
+
if (status === 'loading') {
|
|
3721
3707
|
return createElement(EntryCard, {
|
|
3722
3708
|
size: "small",
|
|
3723
3709
|
isLoading: true
|
|
3724
3710
|
});
|
|
3725
3711
|
}
|
|
3726
3712
|
|
|
3727
|
-
return createElement(WrappedAssetLink,
|
|
3713
|
+
return createElement(WrappedAssetLink, _extends({}, commonProps, {
|
|
3728
3714
|
href: commonProps.entityUrl,
|
|
3729
|
-
getEntityScheduledActions:
|
|
3715
|
+
getEntityScheduledActions: loadEntityScheduledActions
|
|
3730
3716
|
}));
|
|
3731
3717
|
}
|
|
3732
3718
|
|
|
3733
|
-
if (
|
|
3719
|
+
if (status === 'loading') {
|
|
3734
3720
|
return createElement(AssetCard, {
|
|
3735
3721
|
size: size,
|
|
3736
3722
|
isLoading: true
|
|
@@ -3745,7 +3731,7 @@ function FetchingWrappedAssetCard(props) {
|
|
|
3745
3731
|
getAssetUrl: getEntityUrl
|
|
3746
3732
|
});
|
|
3747
3733
|
|
|
3748
|
-
return createElement(WrappedAssetCard,
|
|
3734
|
+
return createElement(WrappedAssetCard, _extends({}, builtinCardProps));
|
|
3749
3735
|
}
|
|
3750
3736
|
|
|
3751
3737
|
if (props.renderCustomCard) {
|
|
@@ -3762,17 +3748,17 @@ function FetchingWrappedAssetCard(props) {
|
|
|
3762
3748
|
}
|
|
3763
3749
|
|
|
3764
3750
|
return renderDefaultCard(); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
3765
|
-
}, [props,
|
|
3751
|
+
}, [props, status, asset]);
|
|
3766
3752
|
}
|
|
3767
3753
|
|
|
3768
3754
|
function SingleMediaEditor(props) {
|
|
3769
|
-
return createElement(SingleReferenceEditor,
|
|
3755
|
+
return createElement(SingleReferenceEditor, _extends({}, props, {
|
|
3770
3756
|
entityType: "Asset"
|
|
3771
3757
|
}), function (_ref) {
|
|
3772
3758
|
var entityId = _ref.entityId,
|
|
3773
3759
|
isDisabled = _ref.isDisabled,
|
|
3774
3760
|
setValue = _ref.setValue;
|
|
3775
|
-
return createElement(FetchingWrappedAssetCard,
|
|
3761
|
+
return createElement(FetchingWrappedAssetCard, _extends({}, props, {
|
|
3776
3762
|
viewType: "big_card",
|
|
3777
3763
|
assetId: entityId,
|
|
3778
3764
|
isDisabled: isDisabled,
|
|
@@ -3794,12 +3780,12 @@ var styles$6 = {
|
|
|
3794
3780
|
})
|
|
3795
3781
|
};
|
|
3796
3782
|
function MultipleMediaEditor(props) {
|
|
3797
|
-
return createElement(MultipleReferenceEditor,
|
|
3783
|
+
return createElement(MultipleReferenceEditor, _extends({}, props, {
|
|
3798
3784
|
entityType: "Asset"
|
|
3799
3785
|
}), function (childrenProps) {
|
|
3800
3786
|
var _cx;
|
|
3801
3787
|
|
|
3802
|
-
return createElement(SortableLinkList,
|
|
3788
|
+
return createElement(SortableLinkList, _extends({}, childrenProps, {
|
|
3803
3789
|
className: cx((_cx = {}, _cx[styles$6.gridContainer] = childrenProps.viewType === 'card', _cx)),
|
|
3804
3790
|
axis: childrenProps.viewType === 'card' ? 'xy' : 'y',
|
|
3805
3791
|
useDragHandle: true
|
|
@@ -3809,7 +3795,7 @@ function MultipleMediaEditor(props) {
|
|
|
3809
3795
|
index = _ref.index,
|
|
3810
3796
|
isDisabled = _ref.isDisabled,
|
|
3811
3797
|
DragHandle = _ref.DragHandle;
|
|
3812
|
-
return createElement(FetchingWrappedAssetCard,
|
|
3798
|
+
return createElement(FetchingWrappedAssetCard, _extends({}, childrenProps, {
|
|
3813
3799
|
isDisabled: isDisabled,
|
|
3814
3800
|
key: item.sys.id + "-" + index,
|
|
3815
3801
|
assetId: item.sys.id,
|
|
@@ -3827,5 +3813,447 @@ MultipleMediaEditor.defaultProps = {
|
|
|
3827
3813
|
isInitiallyDisabled: true
|
|
3828
3814
|
};
|
|
3829
3815
|
|
|
3830
|
-
|
|
3816
|
+
var resolveAsset = function resolveAsset() {
|
|
3817
|
+
return Promise.resolve();
|
|
3818
|
+
}; // we don't want to show scheduled actions for resources
|
|
3819
|
+
|
|
3820
|
+
|
|
3821
|
+
var resolveScheduledActions = function resolveScheduledActions() {
|
|
3822
|
+
return Promise.resolve([]);
|
|
3823
|
+
};
|
|
3824
|
+
|
|
3825
|
+
function ContentfulEntryCard(_ref) {
|
|
3826
|
+
var info = _ref.info,
|
|
3827
|
+
isDisabled = _ref.isDisabled,
|
|
3828
|
+
renderDragHandle = _ref.renderDragHandle,
|
|
3829
|
+
onRemove = _ref.onRemove,
|
|
3830
|
+
onMoveTop = _ref.onMoveTop,
|
|
3831
|
+
onMoveBottom = _ref.onMoveBottom,
|
|
3832
|
+
getEntryRouteHref = _ref.getEntryRouteHref;
|
|
3833
|
+
var resourceSys = info.resource.sys;
|
|
3834
|
+
var spaceId = resourceSys.space.sys.id;
|
|
3835
|
+
var environmentId = resourceSys.environment.sys.id;
|
|
3836
|
+
var entryId = resourceSys.id;
|
|
3837
|
+
var resourceHref = getEntryRouteHref({
|
|
3838
|
+
spaceId: spaceId,
|
|
3839
|
+
environmentId: environmentId,
|
|
3840
|
+
entryId: entryId
|
|
3841
|
+
}); // TODO: move this into `sdk.navigator.openEntry()`, note that it's signature only include the entry id (not a space or environment)
|
|
3842
|
+
|
|
3843
|
+
var openEntryDetail = function openEntryDetail() {
|
|
3844
|
+
window.open(resourceHref, '_blank', 'noopener,noreferrer');
|
|
3845
|
+
};
|
|
3846
|
+
|
|
3847
|
+
return createElement(WrappedEntryCard, {
|
|
3848
|
+
entry: info.resource,
|
|
3849
|
+
isDisabled: isDisabled,
|
|
3850
|
+
hasCardEditActions: false,
|
|
3851
|
+
contentType: info.contentType,
|
|
3852
|
+
// we use the default locale from the space the entry belongs to
|
|
3853
|
+
// as we assume this gives a more consistent behaviour.
|
|
3854
|
+
// locales will inevitably differ from space to space, so it's likely
|
|
3855
|
+
// that the current locale does not exist in the "remote" space
|
|
3856
|
+
localeCode: info.defaultLocaleCode,
|
|
3857
|
+
defaultLocaleCode: info.defaultLocaleCode,
|
|
3858
|
+
size: "small",
|
|
3859
|
+
getAsset: resolveAsset,
|
|
3860
|
+
getEntityScheduledActions: resolveScheduledActions,
|
|
3861
|
+
spaceName: info.space.name,
|
|
3862
|
+
renderDragHandle: renderDragHandle,
|
|
3863
|
+
isClickable: true,
|
|
3864
|
+
onEdit: openEntryDetail,
|
|
3865
|
+
hasCardRemoveActions: Boolean(onRemove),
|
|
3866
|
+
onRemove: onRemove,
|
|
3867
|
+
onMoveBottom: onMoveBottom,
|
|
3868
|
+
onMoveTop: onMoveTop,
|
|
3869
|
+
entryUrl: resourceHref
|
|
3870
|
+
});
|
|
3871
|
+
}
|
|
3872
|
+
|
|
3873
|
+
var styles$7 = {
|
|
3874
|
+
card: /*#__PURE__*/css({
|
|
3875
|
+
position: 'relative'
|
|
3876
|
+
})
|
|
3877
|
+
};
|
|
3878
|
+
function UnsupportedEntityCard(props) {
|
|
3879
|
+
return React__default.createElement(Card, {
|
|
3880
|
+
className: styles$7.card
|
|
3881
|
+
}, React__default.createElement(SectionHeading, {
|
|
3882
|
+
marginBottom: "none"
|
|
3883
|
+
}, "Resource type ", props.entityType, " is currently not supported"));
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
function ResourceCardSkeleton() {
|
|
3887
|
+
return createElement(EntryCard, {
|
|
3888
|
+
size: "small",
|
|
3889
|
+
isLoading: true
|
|
3890
|
+
});
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
function ExistingResourceCard(props) {
|
|
3894
|
+
var resourceLink = props.resourceLink,
|
|
3895
|
+
inView = props.inView,
|
|
3896
|
+
_props$index = props.index,
|
|
3897
|
+
index = _props$index === void 0 ? 0 : _props$index;
|
|
3898
|
+
var resourceOptions = {
|
|
3899
|
+
priority: index * -1,
|
|
3900
|
+
enabled: inView
|
|
3901
|
+
};
|
|
3902
|
+
|
|
3903
|
+
var _useResource = useResource(resourceLink.sys.linkType, resourceLink.sys.urn, resourceOptions),
|
|
3904
|
+
data = _useResource.data,
|
|
3905
|
+
error = _useResource.error;
|
|
3906
|
+
|
|
3907
|
+
if (!data && !error) {
|
|
3908
|
+
return createElement(ResourceCardSkeleton, null);
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
if (data) {
|
|
3912
|
+
return createElement(ContentfulEntryCard, _extends({
|
|
3913
|
+
info: data
|
|
3914
|
+
}, props));
|
|
3915
|
+
}
|
|
3916
|
+
|
|
3917
|
+
if (isUnsupportedError(error)) {
|
|
3918
|
+
return createElement(UnsupportedEntityCard, {
|
|
3919
|
+
entityType: resourceLink.sys.linkType
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
|
|
3923
|
+
return createElement(MissingEntityCard, {
|
|
3924
|
+
entityType: "Entry",
|
|
3925
|
+
isDisabled: props.isDisabled,
|
|
3926
|
+
onRemove: props.onRemove
|
|
3927
|
+
});
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
function ResourceCardWrapper(props) {
|
|
3931
|
+
if (!props.resourceLink) {
|
|
3932
|
+
return null;
|
|
3933
|
+
}
|
|
3934
|
+
|
|
3935
|
+
return createElement(ExistingResourceCard, _extends({}, props, {
|
|
3936
|
+
resourceLink: props.resourceLink,
|
|
3937
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
3938
|
+
}));
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3941
|
+
function ResourceCard(props) {
|
|
3942
|
+
var _useInView = useInView({
|
|
3943
|
+
triggerOnce: true,
|
|
3944
|
+
rootMargin: '300px 0px 0px 300px'
|
|
3945
|
+
}),
|
|
3946
|
+
ref = _useInView.ref,
|
|
3947
|
+
inView = _useInView.inView; // Forma does not offer us to pass refs, so we need an additional wrapper here
|
|
3948
|
+
|
|
3949
|
+
|
|
3950
|
+
return createElement("div", {
|
|
3951
|
+
ref: ref
|
|
3952
|
+
}, createElement(ResourceCardWrapper, _extends({}, props, {
|
|
3953
|
+
inView: inView
|
|
3954
|
+
})));
|
|
3955
|
+
}
|
|
3956
|
+
|
|
3957
|
+
function useResourceLinkActions(_ref) {
|
|
3958
|
+
var apiUrl = _ref.apiUrl,
|
|
3959
|
+
dialogs = _ref.dialogs,
|
|
3960
|
+
field = _ref.field,
|
|
3961
|
+
onAfterLink = _ref.onAfterLink;
|
|
3962
|
+
var handleAfterLink = useCallback(function (entries) {
|
|
3963
|
+
if (!onAfterLink) {
|
|
3964
|
+
return;
|
|
3965
|
+
}
|
|
3966
|
+
|
|
3967
|
+
entries.forEach(onAfterLink);
|
|
3968
|
+
}, [onAfterLink]);
|
|
3969
|
+
var multiple = field.type === 'Array';
|
|
3970
|
+
var toLinkItem = useMemo(function () {
|
|
3971
|
+
function toUrn(entry) {
|
|
3972
|
+
return "crn:" + apiUrl + ":::content:spaces/" + entry.sys.space.sys.id + "/entries/" + entry.sys.id;
|
|
3973
|
+
}
|
|
3974
|
+
|
|
3975
|
+
return function (entry) {
|
|
3976
|
+
return {
|
|
3977
|
+
sys: {
|
|
3978
|
+
type: 'ResourceLink',
|
|
3979
|
+
linkType: 'Contentful:Entry',
|
|
3980
|
+
urn: toUrn(entry)
|
|
3981
|
+
}
|
|
3982
|
+
};
|
|
3983
|
+
};
|
|
3984
|
+
}, [apiUrl]);
|
|
3985
|
+
var onLinkedExisting = useMemo(function () {
|
|
3986
|
+
if (multiple) {
|
|
3987
|
+
return function (entries) {
|
|
3988
|
+
var linkItems = entries.map(toLinkItem);
|
|
3989
|
+
var prevValue = field.getValue() || [];
|
|
3990
|
+
var updatedValue = [].concat(prevValue, linkItems);
|
|
3991
|
+
field.setValue(updatedValue);
|
|
3992
|
+
handleAfterLink(entries);
|
|
3993
|
+
};
|
|
3994
|
+
} else {
|
|
3995
|
+
return function (entries) {
|
|
3996
|
+
var entry = entries[0];
|
|
3997
|
+
field.setValue(toLinkItem(entry));
|
|
3998
|
+
handleAfterLink([entry]);
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
}, [field, handleAfterLink, multiple, toLinkItem]);
|
|
4002
|
+
var onLinkExisting = useMemo(function () {
|
|
4003
|
+
var promptSelection = multiple ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
4004
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
4005
|
+
while (1) {
|
|
4006
|
+
switch (_context.prev = _context.next) {
|
|
4007
|
+
case 0:
|
|
4008
|
+
_context.next = 2;
|
|
4009
|
+
return dialogs.selectMultipleResourceEntries({
|
|
4010
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
4011
|
+
allowedResources: field.allowedResources
|
|
4012
|
+
});
|
|
4013
|
+
|
|
4014
|
+
case 2:
|
|
4015
|
+
return _context.abrupt("return", _context.sent);
|
|
4016
|
+
|
|
4017
|
+
case 3:
|
|
4018
|
+
case "end":
|
|
4019
|
+
return _context.stop();
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
}, _callee);
|
|
4023
|
+
})) : /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
4024
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
4025
|
+
while (1) {
|
|
4026
|
+
switch (_context2.prev = _context2.next) {
|
|
4027
|
+
case 0:
|
|
4028
|
+
_context2.next = 2;
|
|
4029
|
+
return dialogs.selectSingleResourceEntry({
|
|
4030
|
+
// @ts-expect-error wait for update of app-sdk version
|
|
4031
|
+
allowedResources: field.allowedResources
|
|
4032
|
+
});
|
|
4033
|
+
|
|
4034
|
+
case 2:
|
|
4035
|
+
_context2.t0 = _context2.sent;
|
|
4036
|
+
return _context2.abrupt("return", [_context2.t0]);
|
|
4037
|
+
|
|
4038
|
+
case 4:
|
|
4039
|
+
case "end":
|
|
4040
|
+
return _context2.stop();
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
}, _callee2);
|
|
4044
|
+
}));
|
|
4045
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
4046
|
+
var res;
|
|
4047
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
4048
|
+
while (1) {
|
|
4049
|
+
switch (_context3.prev = _context3.next) {
|
|
4050
|
+
case 0:
|
|
4051
|
+
_context3.next = 2;
|
|
4052
|
+
return promptSelection();
|
|
4053
|
+
|
|
4054
|
+
case 2:
|
|
4055
|
+
res = _context3.sent;
|
|
4056
|
+
|
|
4057
|
+
if (res) {
|
|
4058
|
+
_context3.next = 5;
|
|
4059
|
+
break;
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
return _context3.abrupt("return");
|
|
4063
|
+
|
|
4064
|
+
case 5:
|
|
4065
|
+
onLinkedExisting(res);
|
|
4066
|
+
|
|
4067
|
+
case 6:
|
|
4068
|
+
case "end":
|
|
4069
|
+
return _context3.stop();
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
}, _callee3);
|
|
4073
|
+
})); // @ts-expect-error wait for update of app-sdk version
|
|
4074
|
+
}, [dialogs, field.allowedResources, multiple, onLinkedExisting]);
|
|
4075
|
+
return {
|
|
4076
|
+
onLinkExisting: onLinkExisting,
|
|
4077
|
+
onLinkedExisting: onLinkedExisting,
|
|
4078
|
+
// hardcoded values to match interface for standard reference field actions
|
|
4079
|
+
entityType: 'Entry',
|
|
4080
|
+
contentTypes: [],
|
|
4081
|
+
canCreateEntity: false,
|
|
4082
|
+
canLinkMultiple: multiple,
|
|
4083
|
+
canLinkEntity: true,
|
|
4084
|
+
isDisabled: false,
|
|
4085
|
+
isEmpty: false,
|
|
4086
|
+
isFull: false,
|
|
4087
|
+
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4088
|
+
onCreate: function () {
|
|
4089
|
+
var _onCreate = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
4090
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
4091
|
+
while (1) {
|
|
4092
|
+
switch (_context4.prev = _context4.next) {
|
|
4093
|
+
case 0:
|
|
4094
|
+
case "end":
|
|
4095
|
+
return _context4.stop();
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
}, _callee4);
|
|
4099
|
+
}));
|
|
4100
|
+
|
|
4101
|
+
function onCreate() {
|
|
4102
|
+
return _onCreate.apply(this, arguments);
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
return onCreate;
|
|
4106
|
+
}(),
|
|
4107
|
+
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
4108
|
+
onCreated: function onCreated() {}
|
|
4109
|
+
};
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4112
|
+
function ResourceEditor(props) {
|
|
4113
|
+
var setValue = props.setValue,
|
|
4114
|
+
items = props.items,
|
|
4115
|
+
apiUrl = props.apiUrl;
|
|
4116
|
+
var onSortStart = useCallback(function (_, event) {
|
|
4117
|
+
return event.preventDefault();
|
|
4118
|
+
}, []);
|
|
4119
|
+
var onSortEnd = useCallback(function (_ref) {
|
|
4120
|
+
var oldIndex = _ref.oldIndex,
|
|
4121
|
+
newIndex = _ref.newIndex;
|
|
4122
|
+
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4123
|
+
setValue(newItems);
|
|
4124
|
+
}, [items, setValue]);
|
|
4125
|
+
var onMove = useCallback(function (oldIndex, newIndex) {
|
|
4126
|
+
var newItems = arrayMove(items, oldIndex, newIndex);
|
|
4127
|
+
setValue(newItems);
|
|
4128
|
+
}, [items, setValue]);
|
|
4129
|
+
var onRemoteItemAtIndex = useCallback(function (index) {
|
|
4130
|
+
setValue(items.filter(function (_v, i) {
|
|
4131
|
+
return i !== index;
|
|
4132
|
+
}));
|
|
4133
|
+
}, [items, setValue]);
|
|
4134
|
+
var _props$sdk = props.sdk,
|
|
4135
|
+
dialogs = _props$sdk.dialogs,
|
|
4136
|
+
field = _props$sdk.field;
|
|
4137
|
+
var linkActionsProps = useResourceLinkActions({
|
|
4138
|
+
dialogs: dialogs,
|
|
4139
|
+
field: field,
|
|
4140
|
+
apiUrl: apiUrl
|
|
4141
|
+
});
|
|
4142
|
+
return createElement(Fragment, null, props.children(_extends({}, props, {
|
|
4143
|
+
onSortStart: onSortStart,
|
|
4144
|
+
onSortEnd: onSortEnd,
|
|
4145
|
+
onMove: onMove,
|
|
4146
|
+
onRemoteItemAtIndex: onRemoteItemAtIndex
|
|
4147
|
+
})), createElement(CombinedLinkActions, _extends({}, linkActionsProps)));
|
|
4148
|
+
} // provides memoized callbacks bound to a given item
|
|
4149
|
+
|
|
4150
|
+
|
|
4151
|
+
function WithPerItemCallbacks(_ref2) {
|
|
4152
|
+
var listLength = _ref2.listLength,
|
|
4153
|
+
index = _ref2.index,
|
|
4154
|
+
onMove = _ref2.onMove,
|
|
4155
|
+
onRemoteItemAtIndex = _ref2.onRemoteItemAtIndex,
|
|
4156
|
+
children = _ref2.children;
|
|
4157
|
+
var handleMoveTop = useMemo(function () {
|
|
4158
|
+
return index > 0 ? function () {
|
|
4159
|
+
return onMove(index, 0);
|
|
4160
|
+
} : undefined;
|
|
4161
|
+
}, [index, onMove]);
|
|
4162
|
+
var handleMoveBottom = useMemo(function () {
|
|
4163
|
+
return index < listLength - 1 ? function () {
|
|
4164
|
+
return onMove(index, listLength - 1);
|
|
4165
|
+
} : undefined;
|
|
4166
|
+
}, [index, onMove, listLength]);
|
|
4167
|
+
var handleRemove = useCallback(function () {
|
|
4168
|
+
return onRemoteItemAtIndex(index);
|
|
4169
|
+
}, [index, onRemoteItemAtIndex]);
|
|
4170
|
+
return createElement(Fragment, null, children({
|
|
4171
|
+
onMoveBottom: handleMoveBottom,
|
|
4172
|
+
onMoveTop: handleMoveTop,
|
|
4173
|
+
onRemove: handleRemove
|
|
4174
|
+
}));
|
|
4175
|
+
}
|
|
4176
|
+
|
|
4177
|
+
var EMPTY_ARRAY = [];
|
|
4178
|
+
function MultipleResourceReferenceEditor(props) {
|
|
4179
|
+
return createElement(EntityProvider, {
|
|
4180
|
+
sdk: props.sdk
|
|
4181
|
+
}, createElement(FieldConnector, {
|
|
4182
|
+
throttle: 0,
|
|
4183
|
+
field: props.sdk.field,
|
|
4184
|
+
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4185
|
+
isEqualValues: deepEqual
|
|
4186
|
+
}, function (_ref3) {
|
|
4187
|
+
var value = _ref3.value,
|
|
4188
|
+
disabled = _ref3.disabled,
|
|
4189
|
+
setValue = _ref3.setValue,
|
|
4190
|
+
externalReset = _ref3.externalReset;
|
|
4191
|
+
return createElement(ResourceEditor, _extends({}, props, {
|
|
4192
|
+
items: value || EMPTY_ARRAY,
|
|
4193
|
+
isDisabled: disabled,
|
|
4194
|
+
setValue: setValue,
|
|
4195
|
+
key: externalReset + "-list"
|
|
4196
|
+
}), function (editorProps) {
|
|
4197
|
+
return createElement(SortableLinkList, _extends({}, editorProps), function (_ref4) {
|
|
4198
|
+
var item = _ref4.item,
|
|
4199
|
+
isDisabled = _ref4.isDisabled,
|
|
4200
|
+
DragHandle = _ref4.DragHandle,
|
|
4201
|
+
index = _ref4.index;
|
|
4202
|
+
return createElement(WithPerItemCallbacks, {
|
|
4203
|
+
index: index,
|
|
4204
|
+
onMove: editorProps.onMove,
|
|
4205
|
+
onRemoteItemAtIndex: editorProps.onRemoteItemAtIndex,
|
|
4206
|
+
listLength: (value == null ? void 0 : value.length) || 0
|
|
4207
|
+
}, function (_ref5) {
|
|
4208
|
+
var onMoveBottom = _ref5.onMoveBottom,
|
|
4209
|
+
onMoveTop = _ref5.onMoveTop,
|
|
4210
|
+
onRemove = _ref5.onRemove;
|
|
4211
|
+
return createElement(ResourceCard, {
|
|
4212
|
+
index: index,
|
|
4213
|
+
resourceLink: item,
|
|
4214
|
+
isDisabled: isDisabled,
|
|
4215
|
+
renderDragHandle: DragHandle,
|
|
4216
|
+
onMoveTop: onMoveTop,
|
|
4217
|
+
onMoveBottom: onMoveBottom,
|
|
4218
|
+
onRemove: onRemove,
|
|
4219
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
4220
|
+
});
|
|
4221
|
+
});
|
|
4222
|
+
});
|
|
4223
|
+
});
|
|
4224
|
+
}));
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
function SingleResourceReferenceEditor(props) {
|
|
4228
|
+
var _props$sdk = props.sdk,
|
|
4229
|
+
dialogs = _props$sdk.dialogs,
|
|
4230
|
+
field = _props$sdk.field;
|
|
4231
|
+
var linkActionsProps = useResourceLinkActions({
|
|
4232
|
+
dialogs: dialogs,
|
|
4233
|
+
field: field,
|
|
4234
|
+
apiUrl: props.apiUrl
|
|
4235
|
+
});
|
|
4236
|
+
return createElement(EntityProvider, {
|
|
4237
|
+
sdk: props.sdk
|
|
4238
|
+
}, createElement(FieldConnector, {
|
|
4239
|
+
throttle: 0,
|
|
4240
|
+
field: props.sdk.field,
|
|
4241
|
+
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
4242
|
+
isEqualValues: deepEqual
|
|
4243
|
+
}, function (_ref) {
|
|
4244
|
+
var value = _ref.value,
|
|
4245
|
+
disabled = _ref.disabled;
|
|
4246
|
+
return value ? createElement(ResourceCard, {
|
|
4247
|
+
onRemove: function onRemove() {
|
|
4248
|
+
return props.sdk.field.removeValue();
|
|
4249
|
+
},
|
|
4250
|
+
resourceLink: value,
|
|
4251
|
+
isDisabled: disabled,
|
|
4252
|
+
getEntryRouteHref: props.getEntryRouteHref
|
|
4253
|
+
}) : // TODO: support custom actions once publicly available
|
|
4254
|
+
createElement(CombinedLinkActions, _extends({}, linkActionsProps));
|
|
4255
|
+
}));
|
|
4256
|
+
}
|
|
4257
|
+
|
|
4258
|
+
export { AssetThumbnail, CombinedLinkActions, CreateEntryLinkButton, CreateEntryMenuTrigger, EntityProvider, MissingEntityCard, MultipleEntryReferenceEditor, MultipleMediaEditor, MultipleResourceReferenceEditor, ScheduledIconWithTooltip, SingleEntryReferenceEditor, SingleMediaEditor, SingleResourceReferenceEditor, SortableLinkList, WrappedAssetCard, WrappedEntryCard, getScheduleTooltipContent, useEntity, useEntityLoader, useResource };
|
|
3831
4259
|
//# sourceMappingURL=field-editor-reference.esm.js.map
|