@commercetools-frontend/application-shell-connectors 21.23.10 → 21.24.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/dist/commercetools-frontend-application-shell-connectors.cjs.dev.js +126 -131
- package/dist/commercetools-frontend-application-shell-connectors.cjs.prod.js +126 -131
- package/dist/commercetools-frontend-application-shell-connectors.esm.js +126 -131
- package/dist/declarations/src/components/application-context/application-context.d.ts +1 -9
- package/dist/declarations/src/components/project-extension-image-regex/project-extension-image-regex.d.ts +1 -1
- package/dist/declarations/src/types/generated/mc.d.ts +3 -3
- package/package.json +5 -5
- package/test-utils/dist/commercetools-frontend-application-shell-connectors-test-utils.cjs.dev.js +4 -4
- package/test-utils/dist/commercetools-frontend-application-shell-connectors-test-utils.cjs.prod.js +4 -4
- package/test-utils/dist/commercetools-frontend-application-shell-connectors-test-utils.esm.js +4 -4
|
@@ -18,13 +18,12 @@ var react = require('react');
|
|
|
18
18
|
var moment = require('moment-timezone');
|
|
19
19
|
var sentry = require('@commercetools-frontend/sentry');
|
|
20
20
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
21
|
-
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
22
21
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
23
22
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
24
23
|
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
|
|
25
24
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
26
|
-
var warning = require('tiny-warning');
|
|
27
25
|
var react$1 = require('@apollo/client/react');
|
|
26
|
+
var warning = require('tiny-warning');
|
|
28
27
|
var constants = require('@commercetools-frontend/constants');
|
|
29
28
|
|
|
30
29
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -47,12 +46,12 @@ var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInsta
|
|
|
47
46
|
var warning__default = /*#__PURE__*/_interopDefault(warning);
|
|
48
47
|
|
|
49
48
|
// NOTE: This string will be replaced on build time with the package version.
|
|
50
|
-
var version = "21.
|
|
49
|
+
var version = "21.24.1";
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
52
|
+
const mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
const getMcOriginTld = host => {
|
|
56
55
|
if (host.match(mcPreviewHostnameRegex)) {
|
|
57
56
|
return host.replace(mcPreviewHostnameRegex, '$1');
|
|
58
57
|
}
|
|
@@ -60,22 +59,20 @@ var getMcOriginTld = function getMcOriginTld(host) {
|
|
|
60
59
|
return host.replace(mcHostnameRegex, '$3');
|
|
61
60
|
};
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
const getMcApiUrlFromOrigin = origin => {
|
|
64
63
|
var _context;
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const url = new _URL__default["default"](origin);
|
|
66
|
+
const originTld = getMcOriginTld(url.host);
|
|
68
67
|
return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
return value === true || value === 'true';
|
|
73
|
-
};
|
|
70
|
+
const parseAsBoolean = value => value === true || value === 'true';
|
|
74
71
|
|
|
75
72
|
function getMcApiUrl() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
let environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app;
|
|
74
|
+
let origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.origin;
|
|
75
|
+
const isServedByProxy = parseAsBoolean(environment.servedByProxy);
|
|
79
76
|
/**
|
|
80
77
|
* Prefer using the origin URL for the MC API based on the origin value
|
|
81
78
|
* of the browser's `window.location`.
|
|
@@ -91,7 +88,7 @@ function getMcApiUrl() {
|
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
94
|
-
|
|
91
|
+
const getDisplayName = Component => {
|
|
95
92
|
if (typeof Component === 'string') {
|
|
96
93
|
return Component;
|
|
97
94
|
}
|
|
@@ -105,7 +102,7 @@ var getDisplayName = function getDisplayName(Component) {
|
|
|
105
102
|
|
|
106
103
|
function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
107
104
|
|
|
108
|
-
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
105
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
109
106
|
// Menu visibilities
|
|
110
107
|
// Permissions
|
|
111
108
|
// Action rights
|
|
@@ -129,66 +126,76 @@ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) {
|
|
|
129
126
|
* the fetching logic. Given this mapping needs to be used elsewere feel free
|
|
130
127
|
* to move this over to `permissions` and export it there.
|
|
131
128
|
*/
|
|
132
|
-
|
|
129
|
+
const normalizeAllAppliedPermissions = allAppliedPermissions => {
|
|
133
130
|
if (!allAppliedPermissions || allAppliedPermissions.length === 0) {
|
|
134
131
|
return null;
|
|
135
132
|
}
|
|
136
133
|
|
|
137
|
-
return _reduceInstanceProperty__default["default"](allAppliedPermissions).call(allAppliedPermissions,
|
|
134
|
+
return _reduceInstanceProperty__default["default"](allAppliedPermissions).call(allAppliedPermissions, (transformedAllApplied, allApplied) => {
|
|
138
135
|
if (!allApplied) return transformedAllApplied;
|
|
139
|
-
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {},
|
|
136
|
+
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {}, {
|
|
137
|
+
[allApplied.name]: allApplied.value
|
|
138
|
+
});
|
|
140
139
|
}, {});
|
|
141
140
|
};
|
|
142
|
-
|
|
141
|
+
const normalizeAllAppliedMenuVisibilities = allAppliedMenuVisibilities => {
|
|
143
142
|
if (!allAppliedMenuVisibilities || allAppliedMenuVisibilities.length === 0) {
|
|
144
143
|
return null;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
return _reduceInstanceProperty__default["default"](allAppliedMenuVisibilities).call(allAppliedMenuVisibilities,
|
|
146
|
+
return _reduceInstanceProperty__default["default"](allAppliedMenuVisibilities).call(allAppliedMenuVisibilities, (transformedAllApplied, allApplied) => {
|
|
148
147
|
if (!allApplied) return transformedAllApplied;
|
|
149
|
-
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {},
|
|
148
|
+
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {}, {
|
|
149
|
+
[allApplied.name]: allApplied.value
|
|
150
|
+
});
|
|
150
151
|
}, {});
|
|
151
152
|
};
|
|
152
|
-
|
|
153
|
+
const normalizeAllAppliedActionRights = allAppliedActionRights => {
|
|
153
154
|
if (!allAppliedActionRights || allAppliedActionRights.length === 0) {
|
|
154
155
|
return null;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
return _reduceInstanceProperty__default["default"](allAppliedActionRights).call(allAppliedActionRights,
|
|
158
|
+
return _reduceInstanceProperty__default["default"](allAppliedActionRights).call(allAppliedActionRights, (transformedAllApplied, allApplied) => {
|
|
158
159
|
if (!allApplied) return transformedAllApplied;
|
|
159
|
-
|
|
160
|
-
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {},
|
|
160
|
+
const previousAllAppliedGroup = transformedAllApplied[allApplied.group];
|
|
161
|
+
return _objectSpread$2(_objectSpread$2({}, transformedAllApplied), {}, {
|
|
162
|
+
[allApplied.group]: _objectSpread$2(_objectSpread$2({}, previousAllAppliedGroup), {}, {
|
|
163
|
+
[allApplied.name]: allApplied.value
|
|
164
|
+
})
|
|
165
|
+
});
|
|
161
166
|
}, {});
|
|
162
167
|
};
|
|
163
168
|
|
|
164
|
-
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
var groupedByResourceType = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, function (previousGroupsOfSameType, appliedDataFence) {
|
|
168
|
-
var _context;
|
|
169
|
+
const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
|
|
170
|
+
var _context;
|
|
169
171
|
|
|
172
|
+
const groupedByResourceType = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, (previousGroupsOfSameType, appliedDataFence) => {
|
|
170
173
|
if (!appliedDataFence) return previousGroupsOfSameType;
|
|
171
|
-
|
|
172
|
-
return _objectSpread$2(_objectSpread$2({}, previousGroupsOfSameType), {},
|
|
174
|
+
const previousGroup = previousGroupsOfSameType[appliedDataFence.group];
|
|
175
|
+
return _objectSpread$2(_objectSpread$2({}, previousGroupsOfSameType), {}, {
|
|
176
|
+
[appliedDataFence.group]: [...(previousGroup || []), appliedDataFence]
|
|
177
|
+
});
|
|
173
178
|
}, {});
|
|
174
179
|
|
|
175
|
-
return _reduceInstanceProperty__default["default"](
|
|
176
|
-
|
|
180
|
+
return _reduceInstanceProperty__default["default"](_context = _Object$entries__default["default"](groupedByResourceType)).call(_context, (previousGroupedByResourceType, _ref) => {
|
|
181
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
177
182
|
resourceType = _ref2[0],
|
|
178
183
|
dataFences = _ref2[1];
|
|
179
184
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var dataFenceByName = nextDataFenceValues[dataFence.name] || {
|
|
185
|
+
const groupByDataFenceName = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, (nextDataFenceValues, dataFence) => {
|
|
186
|
+
const dataFenceByName = nextDataFenceValues[dataFence.name] || {
|
|
184
187
|
values: []
|
|
185
188
|
};
|
|
186
|
-
return _objectSpread$2(_objectSpread$2({}, nextDataFenceValues), {},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
return _objectSpread$2(_objectSpread$2({}, nextDataFenceValues), {}, {
|
|
190
|
+
[dataFence.name]: _objectSpread$2(_objectSpread$2({}, dataFenceByName), {}, {
|
|
191
|
+
values: [..._valuesInstanceProperty__default["default"](dataFenceByName), dataFence.value]
|
|
192
|
+
})
|
|
193
|
+
});
|
|
189
194
|
}, {});
|
|
190
195
|
|
|
191
|
-
return _objectSpread$2(_objectSpread$2({}, previousGroupedByResourceType), {},
|
|
196
|
+
return _objectSpread$2(_objectSpread$2({}, previousGroupedByResourceType), {}, {
|
|
197
|
+
[resourceType]: groupByDataFenceName
|
|
198
|
+
});
|
|
192
199
|
}, {});
|
|
193
200
|
}; // input:
|
|
194
201
|
// [
|
|
@@ -222,20 +229,20 @@ var normalizeAppliedDataFencesForStoresByResourceType = function normalizeApplie
|
|
|
222
229
|
// }
|
|
223
230
|
|
|
224
231
|
|
|
225
|
-
|
|
232
|
+
const normalizeAllAppliedDataFences = allAppliedDataFences => {
|
|
226
233
|
if (!allAppliedDataFences || allAppliedDataFences.length === 0) {
|
|
227
234
|
return null;
|
|
228
235
|
}
|
|
229
236
|
|
|
230
|
-
|
|
231
|
-
var _context4;
|
|
232
|
-
|
|
237
|
+
const groupedByType = _reduceInstanceProperty__default["default"](allAppliedDataFences).call(allAppliedDataFences, (previousGroupsOfSameType, appliedDataFence) => {
|
|
233
238
|
if (!appliedDataFence) return previousGroupsOfSameType;
|
|
234
|
-
|
|
235
|
-
return _objectSpread$2(_objectSpread$2({}, previousGroupsOfSameType), {},
|
|
239
|
+
const previousGroup = previousGroupsOfSameType[appliedDataFence.type];
|
|
240
|
+
return _objectSpread$2(_objectSpread$2({}, previousGroupsOfSameType), {}, {
|
|
241
|
+
[appliedDataFence.type]: [...(previousGroup || []), appliedDataFence]
|
|
242
|
+
});
|
|
236
243
|
}, {});
|
|
237
244
|
|
|
238
|
-
|
|
245
|
+
const normalizedDataFences = _objectSpread$2({}, 'store' in groupedByType ? {
|
|
239
246
|
store: normalizeAppliedDataFencesForStoresByResourceType(groupedByType.store)
|
|
240
247
|
} : {});
|
|
241
248
|
|
|
@@ -246,13 +253,13 @@ var normalizeAllAppliedDataFences = function normalizeAllAppliedDataFences(allAp
|
|
|
246
253
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
247
254
|
|
|
248
255
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
249
|
-
|
|
250
|
-
|
|
256
|
+
const Context$1 = /*#__PURE__*/react.createContext({});
|
|
257
|
+
const defaultTimeZone = moment__default["default"].tz.guess() || 'Etc/UTC'; // Expose only certain fields as some of them are only meant to
|
|
251
258
|
// be used internally in the AppShell
|
|
252
259
|
|
|
253
|
-
|
|
260
|
+
const mapUserToApplicationContextUser = user => {
|
|
254
261
|
if (!user) return null;
|
|
255
|
-
|
|
262
|
+
let applicationContextUser = {
|
|
256
263
|
id: user.id,
|
|
257
264
|
email: user.email,
|
|
258
265
|
createdAt: user.createdAt,
|
|
@@ -267,7 +274,7 @@ var mapUserToApplicationContextUser = function mapUserToApplicationContextUser(u
|
|
|
267
274
|
}; // This property will only be populated when user has logged in using SSO
|
|
268
275
|
|
|
269
276
|
if (user.idTokenUserInfo) {
|
|
270
|
-
|
|
277
|
+
let additionalClaims = {};
|
|
271
278
|
|
|
272
279
|
try {
|
|
273
280
|
additionalClaims = JSON.parse(user.idTokenUserInfo.additionalClaims || '{}');
|
|
@@ -280,22 +287,20 @@ var mapUserToApplicationContextUser = function mapUserToApplicationContextUser(u
|
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
applicationContextUser.idTokenUserInfo = _objectSpread$1(_objectSpread$1({}, user.idTokenUserInfo), {}, {
|
|
283
|
-
additionalClaims
|
|
290
|
+
additionalClaims
|
|
284
291
|
});
|
|
285
292
|
}
|
|
286
293
|
|
|
287
294
|
return applicationContextUser;
|
|
288
295
|
}; // Adjust certain fields which depend e.g. on the origin
|
|
289
296
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
});
|
|
295
|
-
}; // Expose only certain fields as some of them are only meant to
|
|
297
|
+
const mapEnvironmentToApplicationContextEnvironment = (environment, origin) => _objectSpread$1(_objectSpread$1({}, environment), {}, {
|
|
298
|
+
// NOTE: The `mcApiUrl` depends on `servedByProxy`
|
|
299
|
+
mcApiUrl: getMcApiUrl(environment, origin)
|
|
300
|
+
}); // Expose only certain fields as some of them are only meant to
|
|
296
301
|
// be used internally in the AppShell
|
|
297
302
|
|
|
298
|
-
|
|
303
|
+
const mapProjectToApplicationContextProject = project => {
|
|
299
304
|
if (!project) return null;
|
|
300
305
|
return {
|
|
301
306
|
key: project.key,
|
|
@@ -309,24 +314,20 @@ var mapProjectToApplicationContextProject = function mapProjectToApplicationCont
|
|
|
309
314
|
};
|
|
310
315
|
};
|
|
311
316
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
};
|
|
322
|
-
};
|
|
317
|
+
const createApplicationContext = (environment, user, project, projectDataLocale) => ({
|
|
318
|
+
environment: mapEnvironmentToApplicationContextEnvironment(environment),
|
|
319
|
+
user: mapUserToApplicationContextUser(user),
|
|
320
|
+
project: mapProjectToApplicationContextProject(project),
|
|
321
|
+
permissions: normalizeAllAppliedPermissions(project === null || project === void 0 ? void 0 : project.allAppliedPermissions),
|
|
322
|
+
actionRights: normalizeAllAppliedActionRights(project === null || project === void 0 ? void 0 : project.allAppliedActionRights),
|
|
323
|
+
dataFences: normalizeAllAppliedDataFences(project === null || project === void 0 ? void 0 : project.allAppliedDataFences),
|
|
324
|
+
dataLocale: projectDataLocale || null
|
|
325
|
+
});
|
|
323
326
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
});
|
|
329
|
-
};
|
|
327
|
+
const ApplicationContextProvider = props => jsxRuntime.jsx(Context$1.Provider, {
|
|
328
|
+
value: createApplicationContext(props.environment, props.user, props.project, props.projectDataLocale),
|
|
329
|
+
children: props.children
|
|
330
|
+
});
|
|
330
331
|
|
|
331
332
|
ApplicationContextProvider.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
332
333
|
projectDataLocale: _pt__default["default"].string,
|
|
@@ -334,18 +335,16 @@ ApplicationContextProvider.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
334
335
|
} : {};
|
|
335
336
|
ApplicationContextProvider.displayName = 'ApplicationContextProvider';
|
|
336
337
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
});
|
|
348
|
-
};
|
|
338
|
+
const ApplicationContext = props => jsxRuntime.jsx(Context$1.Consumer, {
|
|
339
|
+
children: context => {
|
|
340
|
+
// Because of the way the ApplicationShell configures the Context.Provider,
|
|
341
|
+
// we ensure that, when we read from the context, we always get actual
|
|
342
|
+
// context object and not the initial value.
|
|
343
|
+
// Therefore, we can safely cast the value to be out `TApplicationContext` type.
|
|
344
|
+
const applicationContext = context;
|
|
345
|
+
return props.render(applicationContext);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
349
348
|
|
|
350
349
|
ApplicationContext.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
351
350
|
render: _pt__default["default"].func.isRequired
|
|
@@ -353,17 +352,15 @@ ApplicationContext.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
353
352
|
ApplicationContext.displayName = 'ApplicationContext';
|
|
354
353
|
|
|
355
354
|
function withApplicationContext(mapApplicationContextToProps) {
|
|
356
|
-
return
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
});
|
|
366
|
-
};
|
|
355
|
+
return Component => {
|
|
356
|
+
const WrappedComponent = props => jsxRuntime.jsx(ApplicationContext, {
|
|
357
|
+
render: applicationContext => {
|
|
358
|
+
const mappedProps = mapApplicationContextToProps ? mapApplicationContextToProps(applicationContext) : {
|
|
359
|
+
applicationContext
|
|
360
|
+
};
|
|
361
|
+
return jsxRuntime.jsx(Component, _objectSpread$1(_objectSpread$1({}, props), mappedProps));
|
|
362
|
+
}
|
|
363
|
+
});
|
|
367
364
|
|
|
368
365
|
WrappedComponent.displayName = "withApplicationContext(".concat(getDisplayName(Component), ")");
|
|
369
366
|
return WrappedComponent;
|
|
@@ -375,56 +372,56 @@ function withApplicationContext(mapApplicationContextToProps) {
|
|
|
375
372
|
// Then implement the function. Typescript will pick the appropriate signature
|
|
376
373
|
// based on the function arguments.
|
|
377
374
|
function useApplicationContextHook(selector) {
|
|
378
|
-
|
|
375
|
+
const context = react.useContext(Context$1); // Because of the way the ApplicationShell configures the Context.Provider,
|
|
379
376
|
// we ensure that, when we read from the context, we always get actual
|
|
380
377
|
// context object and not the initial value.
|
|
381
378
|
// Therefore, we can safely cast the value to be out `TApplicationContext` type.
|
|
382
379
|
|
|
383
|
-
|
|
380
|
+
const applicationContext = context;
|
|
384
381
|
return selector ? selector(applicationContext) : applicationContext;
|
|
385
382
|
} // This is a workaround to trick babel/rollup to correctly export the function.
|
|
386
383
|
// Most likely the problem arises with the use of overloading.
|
|
387
384
|
// See related issue: https://github.com/babel/babel/issues/8361
|
|
388
385
|
|
|
389
386
|
|
|
390
|
-
|
|
387
|
+
const useApplicationContext = useApplicationContextHook; // Exports
|
|
391
388
|
|
|
392
389
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
393
390
|
|
|
394
391
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
395
392
|
var FetchProjectExtensionImageRegex = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchProjectExtensionImageRegex" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "projectExtension" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "imageRegex" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "thumb" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "small" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }] } }] } }] } }, { kind: "FragmentDefinition", name: { kind: "Name", value: "ImageRegex" }, typeCondition: { kind: "NamedType", name: { kind: "Name", value: "ImageRegexOptions" } }, directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "flag" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "search" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "replace" }, arguments: [], directives: [] }] } }], loc: { start: 0, end: 256, source: { body: "query FetchProjectExtensionImageRegex {\n projectExtension {\n id\n imageRegex {\n thumb {\n ...ImageRegex\n }\n small {\n ...ImageRegex\n }\n }\n }\n}\nfragment ImageRegex on ImageRegexOptions {\n flag\n search\n replace\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
396
393
|
|
|
397
|
-
|
|
398
|
-
react.useEffect(
|
|
394
|
+
const useWarning = (condition, message) => {
|
|
395
|
+
react.useEffect(() => {
|
|
399
396
|
process.env.NODE_ENV !== "production" ? warning__default["default"](condition, message) : void 0; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
400
397
|
}, []);
|
|
401
398
|
};
|
|
402
399
|
|
|
403
|
-
|
|
400
|
+
const Context = /*#__PURE__*/react.createContext({
|
|
404
401
|
isLoading: false
|
|
405
402
|
});
|
|
406
403
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
404
|
+
const useProjectExtensionImageRegex = () => {
|
|
405
|
+
const _useContext = react.useContext(Context),
|
|
406
|
+
isLoading = _useContext.isLoading,
|
|
407
|
+
imageRegex = _useContext.imageRegex;
|
|
411
408
|
|
|
412
409
|
return {
|
|
413
|
-
isLoading
|
|
414
|
-
imageRegex
|
|
410
|
+
isLoading,
|
|
411
|
+
imageRegex
|
|
415
412
|
};
|
|
416
413
|
};
|
|
417
414
|
|
|
418
|
-
|
|
419
|
-
|
|
415
|
+
const ProjectExtensionProviderForImageRegex = props => {
|
|
416
|
+
const _useQuery = react$1.useQuery(FetchProjectExtensionImageRegex, {
|
|
420
417
|
skip: props.skip,
|
|
421
418
|
onError: sentry.reportErrorToSentry,
|
|
422
419
|
context: {
|
|
423
420
|
target: constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
|
|
424
421
|
}
|
|
425
422
|
}),
|
|
426
|
-
|
|
427
|
-
|
|
423
|
+
loading = _useQuery.loading,
|
|
424
|
+
data = _useQuery.data;
|
|
428
425
|
|
|
429
426
|
return jsxRuntime.jsx(Context.Provider, {
|
|
430
427
|
value: {
|
|
@@ -441,12 +438,10 @@ ProjectExtensionProviderForImageRegex.propTypes = process.env.NODE_ENV !== "prod
|
|
|
441
438
|
} : {};
|
|
442
439
|
ProjectExtensionProviderForImageRegex.displayName = 'ProjectExtensionProviderForImageRegex';
|
|
443
440
|
|
|
444
|
-
|
|
441
|
+
const GetProjectExtensionImageRegex = props => {
|
|
445
442
|
useWarning(false, "@commercetools-frontend/application-shell-connectors: It is not recommended to use the 'GetProjectExtensionImageRegex' anymore. Please use the 'useProjectExtensionImageRegex' hook instead.");
|
|
446
443
|
return jsxRuntime.jsx(Context.Consumer, {
|
|
447
|
-
children:
|
|
448
|
-
return props.render(imageRegexContext);
|
|
449
|
-
}
|
|
444
|
+
children: imageRegexContext => props.render(imageRegexContext)
|
|
450
445
|
});
|
|
451
446
|
};
|
|
452
447
|
|
|
@@ -456,15 +451,15 @@ GetProjectExtensionImageRegex.propTypes = process.env.NODE_ENV !== "production"
|
|
|
456
451
|
GetProjectExtensionImageRegex.displayName = 'GetProjectExtensionImageRegex';
|
|
457
452
|
|
|
458
453
|
function withProjectExtensionImageRegex() {
|
|
459
|
-
|
|
460
|
-
return
|
|
461
|
-
|
|
454
|
+
let propKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'imageRegexData';
|
|
455
|
+
return Component => {
|
|
456
|
+
const WrappedComponent = props => {
|
|
462
457
|
useWarning(false, "@commercetools-frontend/application-shell-connectors: It is not recommended to use the 'withProjectExtensionImageRegex' high order component anymore. Please use the 'useProjectExtensionImageRegex' hook instead.");
|
|
463
|
-
|
|
458
|
+
const imageregexContext = useProjectExtensionImageRegex();
|
|
464
459
|
return jsxRuntime.jsx(GetProjectExtensionImageRegex, {
|
|
465
|
-
render:
|
|
466
|
-
|
|
467
|
-
}
|
|
460
|
+
render: () => jsxRuntime.jsx(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
461
|
+
[propKey]: imageregexContext
|
|
462
|
+
}))
|
|
468
463
|
});
|
|
469
464
|
};
|
|
470
465
|
|