@builder.io/plugin-sfcc-commerce-api 0.0.4 → 0.0.5
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/plugin.system.js +817 -409
- package/dist/plugin.system.js.map +1 -1
- package/package.json +2 -2
package/dist/plugin.system.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'react', 'mobx', 'mobx-react', '@builder.io/app-context'], function () {
|
|
2
2
|
'use strict';
|
|
3
|
-
var Builder, jsx, CircularProgress, Paper, IconButton, Button, ListItem, ListItemAvatar, Avatar, ListItemText,
|
|
3
|
+
var Builder, jsx, CircularProgress, Paper, IconButton, Button, ListItem, ListItemAvatar, Avatar, ListItemText, Typography, Tooltip, TextField, InputAdornment, React, createElement, Component, useEffect, action, runInAction, useLocalStore, useObserver, appState;
|
|
4
4
|
return {
|
|
5
5
|
setters: [function (module) {
|
|
6
6
|
Builder = module.Builder;
|
|
@@ -15,10 +15,10 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
15
15
|
ListItemAvatar = module.ListItemAvatar;
|
|
16
16
|
Avatar = module.Avatar;
|
|
17
17
|
ListItemText = module.ListItemText;
|
|
18
|
-
TextField = module.TextField;
|
|
19
|
-
InputAdornment = module.InputAdornment;
|
|
20
18
|
Typography = module.Typography;
|
|
21
19
|
Tooltip = module.Tooltip;
|
|
20
|
+
TextField = module.TextField;
|
|
21
|
+
InputAdornment = module.InputAdornment;
|
|
22
22
|
}, function (module) {
|
|
23
23
|
React = module.default;
|
|
24
24
|
createElement = module.createElement;
|
|
@@ -35,7 +35,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
35
35
|
}],
|
|
36
36
|
execute: function () {
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
/******************************************************************************
|
|
39
39
|
Copyright (c) Microsoft Corporation.
|
|
40
40
|
|
|
41
41
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -30331,225 +30331,37 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
30331
30331
|
});
|
|
30332
30332
|
});
|
|
30333
30333
|
|
|
30334
|
-
|
|
30335
|
-
|
|
30336
|
-
|
|
30337
|
-
|
|
30338
|
-
|
|
30339
|
-
|
|
30340
|
-
|
|
30341
|
-
|
|
30342
|
-
|
|
30343
|
-
|
|
30344
|
-
|
|
30345
|
-
|
|
30346
|
-
|
|
30347
|
-
|
|
30348
|
-
|
|
30349
|
-
|
|
30350
|
-
|
|
30351
|
-
|
|
30352
|
-
|
|
30353
|
-
|
|
30354
|
-
|
|
30355
|
-
|
|
30356
|
-
|
|
30357
|
-
|
|
30358
|
-
|
|
30359
|
-
|
|
30360
|
-
|
|
30361
|
-
|
|
30362
|
-
|
|
30363
|
-
|
|
30364
|
-
|
|
30365
|
-
case 1:
|
|
30366
|
-
resourcesResponse = _a.sent();
|
|
30367
|
-
runInAction(function () {
|
|
30368
|
-
if (Array.isArray(resourcesResponse)) {
|
|
30369
|
-
_this.resources = resourcesResponse.filter(function (resource) { return !(props.omitIds || []).includes(String(resource.id)); });
|
|
30370
|
-
}
|
|
30371
|
-
_this.loading = false;
|
|
30372
|
-
});
|
|
30373
|
-
return [2 /*return*/];
|
|
30374
|
-
}
|
|
30375
|
-
});
|
|
30376
|
-
});
|
|
30377
|
-
},
|
|
30378
|
-
}); });
|
|
30379
|
-
useEffect(function () {
|
|
30380
|
-
store.search();
|
|
30381
|
-
}, [store.searchInputText]);
|
|
30382
|
-
return useObserver(function () { return (jsx("div", { css: { display: 'flex', flexDirection: 'column', minWidth: 500 } },
|
|
30383
|
-
jsx(TextField, { css: { margin: 15 }, value: store.searchInputText, placeholder: props.title || "Search " + pluralize.plural(props.resourceName) + "...", InputProps: {
|
|
30384
|
-
startAdornment: (jsx(InputAdornment, { position: "start" },
|
|
30385
|
-
jsx(Search$1, { css: { color: '#999', marginRight: -2, fontSize: 20 } }))),
|
|
30386
|
-
}, onChange: action(function (e) { return (store.searchInputText = e.target.value); }) }),
|
|
30387
|
-
store.loading && jsx(CircularProgress, { disableShrink: true, css: { margin: '50px auto' } }),
|
|
30388
|
-
jsx("div", { css: { maxHeight: '80vh', overflow: 'auto' } }, !store.loading &&
|
|
30389
|
-
(store.resources.length ? (store.resources.map(function (item) {
|
|
30390
|
-
var _a;
|
|
30391
|
-
return (jsx("div", { key: item.id, onClick: function (e) {
|
|
30392
|
-
props.onChange(item);
|
|
30393
|
-
} },
|
|
30394
|
-
jsx(ResourcePreviewCell, { selected: String(item.id) === String((_a = props.value) === null || _a === void 0 ? void 0 : _a.id), button: true, resource: item, key: item.id })));
|
|
30395
|
-
})) : (jsx("div", null,
|
|
30396
|
-
jsx(Typography, { css: {
|
|
30397
|
-
margin: '40px 20px',
|
|
30398
|
-
textAlign: 'center',
|
|
30399
|
-
fontSize: 17,
|
|
30400
|
-
}, variant: "caption" },
|
|
30401
|
-
"No ",
|
|
30402
|
-
pluralize.plural(props.resourceName),
|
|
30403
|
-
" found"))))))); });
|
|
30404
|
-
};
|
|
30405
|
-
var ResourcesPickerButton = function (props) {
|
|
30406
|
-
var store = useLocalStore(function () {
|
|
30407
|
-
var _a, _b;
|
|
30408
|
-
return ({
|
|
30409
|
-
loading: false,
|
|
30410
|
-
error: null,
|
|
30411
|
-
resourceInfo: null,
|
|
30412
|
-
resourceHandle: props.handleOnly && typeof props.value === 'string' ? props.value : undefined,
|
|
30413
|
-
resourceId: props.handleOnly
|
|
30414
|
-
? undefined
|
|
30415
|
-
: typeof props.value === 'string'
|
|
30416
|
-
? props.value
|
|
30417
|
-
: (_b = (_a = props.value) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.get(props.resourceName),
|
|
30418
|
-
getResource: function () {
|
|
30419
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
30420
|
-
var resourceService, value, _a, _b, _c, e_1;
|
|
30421
|
-
return __generator(this, function (_d) {
|
|
30422
|
-
switch (_d.label) {
|
|
30423
|
-
case 0:
|
|
30424
|
-
this.error = null;
|
|
30425
|
-
this.loading = true;
|
|
30426
|
-
_d.label = 1;
|
|
30427
|
-
case 1:
|
|
30428
|
-
_d.trys.push([1, 7, , 8]);
|
|
30429
|
-
resourceService = props.api[props.resourceName];
|
|
30430
|
-
_b = this.resourceId;
|
|
30431
|
-
if (!_b) return [3 /*break*/, 3];
|
|
30432
|
-
return [4 /*yield*/, resourceService.findById(this.resourceId)];
|
|
30433
|
-
case 2:
|
|
30434
|
-
_b = (_d.sent());
|
|
30435
|
-
_d.label = 3;
|
|
30436
|
-
case 3:
|
|
30437
|
-
_a = (_b);
|
|
30438
|
-
if (_a) return [3 /*break*/, 6];
|
|
30439
|
-
_c = this.resourceHandle &&
|
|
30440
|
-
resourceService.findByHandle;
|
|
30441
|
-
if (!_c) return [3 /*break*/, 5];
|
|
30442
|
-
return [4 /*yield*/, resourceService.findByHandle(this.resourceHandle)];
|
|
30443
|
-
case 4:
|
|
30444
|
-
_c = (_d.sent());
|
|
30445
|
-
_d.label = 5;
|
|
30446
|
-
case 5:
|
|
30447
|
-
_a = (_c);
|
|
30448
|
-
_d.label = 6;
|
|
30449
|
-
case 6:
|
|
30450
|
-
value = _a;
|
|
30451
|
-
this.resourceInfo = value || null;
|
|
30452
|
-
return [3 /*break*/, 8];
|
|
30453
|
-
case 7:
|
|
30454
|
-
e_1 = _d.sent();
|
|
30455
|
-
console.error(e_1);
|
|
30456
|
-
this.error = e_1;
|
|
30457
|
-
props.context.snackBar.show("Oh no! There was an error fetching " + pluralize.plural(props.resourceName));
|
|
30458
|
-
return [3 /*break*/, 8];
|
|
30459
|
-
case 8:
|
|
30460
|
-
this.loading = false;
|
|
30461
|
-
return [2 /*return*/];
|
|
30462
|
-
}
|
|
30463
|
-
});
|
|
30464
|
-
});
|
|
30465
|
-
},
|
|
30466
|
-
showPickResouceModal: function (title) {
|
|
30467
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
30468
|
-
var close;
|
|
30469
|
-
var _this = this;
|
|
30470
|
-
return __generator(this, function (_a) {
|
|
30471
|
-
switch (_a.label) {
|
|
30472
|
-
case 0: return [4 /*yield*/, props.context.globalState.openDialog(jsx(ResourcePicker, __assign({ resourceName: props.resourceName, api: props.api, context: props.context }, (this.resourceInfo && { value: this.resourceInfo }), { title: title, onChange: action(function (value) {
|
|
30473
|
-
var _a;
|
|
30474
|
-
if (value) {
|
|
30475
|
-
_this.resourceHandle = value.handle;
|
|
30476
|
-
_this.resourceId = String(value.id);
|
|
30477
|
-
_this.getResource();
|
|
30478
|
-
if (props.handleOnly) {
|
|
30479
|
-
props.onChange(_this.resourceHandle);
|
|
30480
|
-
}
|
|
30481
|
-
else {
|
|
30482
|
-
if ((_a = props.field) === null || _a === void 0 ? void 0 : _a.isTargeting) {
|
|
30483
|
-
props.onChange(_this.resourceId);
|
|
30484
|
-
}
|
|
30485
|
-
else {
|
|
30486
|
-
props.onChange(props.api[props.resourceName].getRequestObject(_this.resourceId, value));
|
|
30487
|
-
}
|
|
30488
|
-
}
|
|
30489
|
-
}
|
|
30490
|
-
close();
|
|
30491
|
-
}) })), true, {
|
|
30492
|
-
PaperProps: {
|
|
30493
|
-
// Align modal to top so doesn't jump around centering itself when
|
|
30494
|
-
// grows and shrinks to show more/less resources or loading
|
|
30495
|
-
style: {
|
|
30496
|
-
alignSelf: 'flex-start',
|
|
30497
|
-
},
|
|
30498
|
-
},
|
|
30499
|
-
})];
|
|
30500
|
-
case 1:
|
|
30501
|
-
close = _a.sent();
|
|
30502
|
-
return [2 /*return*/];
|
|
30503
|
-
}
|
|
30504
|
-
});
|
|
30505
|
-
});
|
|
30506
|
-
},
|
|
30507
|
-
});
|
|
30508
|
-
});
|
|
30509
|
-
useEffect(function () {
|
|
30510
|
-
store.getResource();
|
|
30511
|
-
}, []);
|
|
30512
|
-
useEffect(function () {
|
|
30513
|
-
var _a, _b;
|
|
30514
|
-
var hasPreviewFields = Boolean((_a = props.context.designerState.editingModel) === null || _a === void 0 ? void 0 : _a.fields.find(function (field) { return field.type === props.previewType; }));
|
|
30515
|
-
if (hasPreviewFields &&
|
|
30516
|
-
props.context.globalState.globalDialogs.length === 0 && ((_b = props.context.designerState) === null || _b === void 0 ? void 0 : _b.editingContentModel) &&
|
|
30517
|
-
props.isPreview &&
|
|
30518
|
-
(!props.value || store.error)) {
|
|
30519
|
-
setTimeout(function () { return store.showPickResouceModal("Pick a " + props.resourceName + " to preview"); });
|
|
30520
|
-
}
|
|
30521
|
-
}, [store.error]);
|
|
30522
|
-
return useObserver(function () {
|
|
30523
|
-
var pluginSettings = props.context.user.organization.value.settings.plugins.get(props.pluginId);
|
|
30524
|
-
if (!pluginSettings.get('hasConnected')) {
|
|
30525
|
-
return jsx(SetEcomKeysMessage, { pluginId: props.pluginId, pluginName: props.pluginName });
|
|
30526
|
-
}
|
|
30527
|
-
return (jsx("div", { css: { display: 'flex', flexDirection: 'column', padding: '10px 0' } },
|
|
30528
|
-
store.loading && (jsx(CircularProgress, { size: 20, disableShrink: true, css: { margin: '30px auto' } })),
|
|
30529
|
-
store.resourceInfo && (jsx(Paper, { css: {
|
|
30530
|
-
marginBottom: 15,
|
|
30531
|
-
position: 'relative',
|
|
30532
|
-
} },
|
|
30533
|
-
jsx(ResourcePreviewCell, { button: true, css: { paddingRight: 30 }, resource: store.resourceInfo }),
|
|
30534
|
-
jsx(IconButton, { css: {
|
|
30535
|
-
position: 'absolute',
|
|
30536
|
-
right: 2,
|
|
30537
|
-
top: 0,
|
|
30538
|
-
bottom: 0,
|
|
30539
|
-
height: 50,
|
|
30540
|
-
marginTop: 'auto',
|
|
30541
|
-
marginBottom: 'auto',
|
|
30542
|
-
}, onClick: function () {
|
|
30543
|
-
store.showPickResouceModal();
|
|
30544
|
-
} },
|
|
30545
|
-
jsx(Create$1, { css: { color: '#888' } })))),
|
|
30546
|
-
!store.resourceInfo && !store.loading && (jsx(Button, { color: "primary", variant: "contained", onClick: function () {
|
|
30547
|
-
store.showPickResouceModal();
|
|
30548
|
-
} },
|
|
30549
|
-
"Choose ",
|
|
30550
|
-
props.resourceName))));
|
|
30551
|
-
});
|
|
30552
|
-
};
|
|
30334
|
+
/**
|
|
30335
|
+
* Checks if `value` is the
|
|
30336
|
+
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
30337
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
30338
|
+
*
|
|
30339
|
+
* @static
|
|
30340
|
+
* @memberOf _
|
|
30341
|
+
* @since 0.1.0
|
|
30342
|
+
* @category Lang
|
|
30343
|
+
* @param {*} value The value to check.
|
|
30344
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
30345
|
+
* @example
|
|
30346
|
+
*
|
|
30347
|
+
* _.isObject({});
|
|
30348
|
+
* // => true
|
|
30349
|
+
*
|
|
30350
|
+
* _.isObject([1, 2, 3]);
|
|
30351
|
+
* // => true
|
|
30352
|
+
*
|
|
30353
|
+
* _.isObject(_.noop);
|
|
30354
|
+
* // => true
|
|
30355
|
+
*
|
|
30356
|
+
* _.isObject(null);
|
|
30357
|
+
* // => false
|
|
30358
|
+
*/
|
|
30359
|
+
function isObject(value) {
|
|
30360
|
+
var type = typeof value;
|
|
30361
|
+
return value != null && (type == 'object' || type == 'function');
|
|
30362
|
+
}
|
|
30363
|
+
|
|
30364
|
+
var isObject_1 = isObject;
|
|
30553
30365
|
|
|
30554
30366
|
/** Detect free variable `global` from Node.js. */
|
|
30555
30367
|
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
@@ -30564,59 +30376,70 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
30564
30376
|
|
|
30565
30377
|
var _root = root;
|
|
30566
30378
|
|
|
30567
|
-
/**
|
|
30568
|
-
|
|
30379
|
+
/**
|
|
30380
|
+
* Gets the timestamp of the number of milliseconds that have elapsed since
|
|
30381
|
+
* the Unix epoch (1 January 1970 00:00:00 UTC).
|
|
30382
|
+
*
|
|
30383
|
+
* @static
|
|
30384
|
+
* @memberOf _
|
|
30385
|
+
* @since 2.4.0
|
|
30386
|
+
* @category Date
|
|
30387
|
+
* @returns {number} Returns the timestamp.
|
|
30388
|
+
* @example
|
|
30389
|
+
*
|
|
30390
|
+
* _.defer(function(stamp) {
|
|
30391
|
+
* console.log(_.now() - stamp);
|
|
30392
|
+
* }, _.now());
|
|
30393
|
+
* // => Logs the number of milliseconds it took for the deferred invocation.
|
|
30394
|
+
*/
|
|
30395
|
+
var now = function() {
|
|
30396
|
+
return _root.Date.now();
|
|
30397
|
+
};
|
|
30569
30398
|
|
|
30570
|
-
var
|
|
30399
|
+
var now_1 = now;
|
|
30400
|
+
|
|
30401
|
+
/** Used to match a single whitespace character. */
|
|
30402
|
+
var reWhitespace = /\s/;
|
|
30571
30403
|
|
|
30572
30404
|
/**
|
|
30573
|
-
*
|
|
30574
|
-
*
|
|
30405
|
+
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
|
|
30406
|
+
* character of `string`.
|
|
30575
30407
|
*
|
|
30576
30408
|
* @private
|
|
30577
|
-
* @param {
|
|
30578
|
-
* @
|
|
30579
|
-
* @returns {Array} Returns the new mapped array.
|
|
30409
|
+
* @param {string} string The string to inspect.
|
|
30410
|
+
* @returns {number} Returns the index of the last non-whitespace character.
|
|
30580
30411
|
*/
|
|
30581
|
-
function
|
|
30582
|
-
var index =
|
|
30583
|
-
length = array == null ? 0 : array.length,
|
|
30584
|
-
result = Array(length);
|
|
30412
|
+
function trimmedEndIndex(string) {
|
|
30413
|
+
var index = string.length;
|
|
30585
30414
|
|
|
30586
|
-
while (
|
|
30587
|
-
|
|
30588
|
-
}
|
|
30589
|
-
return result;
|
|
30415
|
+
while (index-- && reWhitespace.test(string.charAt(index))) {}
|
|
30416
|
+
return index;
|
|
30590
30417
|
}
|
|
30591
30418
|
|
|
30592
|
-
var
|
|
30419
|
+
var _trimmedEndIndex = trimmedEndIndex;
|
|
30420
|
+
|
|
30421
|
+
/** Used to match leading whitespace. */
|
|
30422
|
+
var reTrimStart = /^\s+/;
|
|
30593
30423
|
|
|
30594
30424
|
/**
|
|
30595
|
-
*
|
|
30596
|
-
*
|
|
30597
|
-
* @static
|
|
30598
|
-
* @memberOf _
|
|
30599
|
-
* @since 0.1.0
|
|
30600
|
-
* @category Lang
|
|
30601
|
-
* @param {*} value The value to check.
|
|
30602
|
-
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
30603
|
-
* @example
|
|
30604
|
-
*
|
|
30605
|
-
* _.isArray([1, 2, 3]);
|
|
30606
|
-
* // => true
|
|
30607
|
-
*
|
|
30608
|
-
* _.isArray(document.body.children);
|
|
30609
|
-
* // => false
|
|
30610
|
-
*
|
|
30611
|
-
* _.isArray('abc');
|
|
30612
|
-
* // => false
|
|
30425
|
+
* The base implementation of `_.trim`.
|
|
30613
30426
|
*
|
|
30614
|
-
*
|
|
30615
|
-
*
|
|
30427
|
+
* @private
|
|
30428
|
+
* @param {string} string The string to trim.
|
|
30429
|
+
* @returns {string} Returns the trimmed string.
|
|
30616
30430
|
*/
|
|
30617
|
-
|
|
30431
|
+
function baseTrim(string) {
|
|
30432
|
+
return string
|
|
30433
|
+
? string.slice(0, _trimmedEndIndex(string) + 1).replace(reTrimStart, '')
|
|
30434
|
+
: string;
|
|
30435
|
+
}
|
|
30618
30436
|
|
|
30619
|
-
var
|
|
30437
|
+
var _baseTrim = baseTrim;
|
|
30438
|
+
|
|
30439
|
+
/** Built-in value references. */
|
|
30440
|
+
var Symbol$1 = _root.Symbol;
|
|
30441
|
+
|
|
30442
|
+
var _Symbol = Symbol$1;
|
|
30620
30443
|
|
|
30621
30444
|
/** Used for built-in method references. */
|
|
30622
30445
|
var objectProto$b = Object.prototype;
|
|
@@ -30768,6 +30591,591 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
30768
30591
|
|
|
30769
30592
|
var isSymbol_1 = isSymbol;
|
|
30770
30593
|
|
|
30594
|
+
/** Used as references for various `Number` constants. */
|
|
30595
|
+
var NAN = 0 / 0;
|
|
30596
|
+
|
|
30597
|
+
/** Used to detect bad signed hexadecimal string values. */
|
|
30598
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
30599
|
+
|
|
30600
|
+
/** Used to detect binary string values. */
|
|
30601
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
30602
|
+
|
|
30603
|
+
/** Used to detect octal string values. */
|
|
30604
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
30605
|
+
|
|
30606
|
+
/** Built-in method references without a dependency on `root`. */
|
|
30607
|
+
var freeParseInt = parseInt;
|
|
30608
|
+
|
|
30609
|
+
/**
|
|
30610
|
+
* Converts `value` to a number.
|
|
30611
|
+
*
|
|
30612
|
+
* @static
|
|
30613
|
+
* @memberOf _
|
|
30614
|
+
* @since 4.0.0
|
|
30615
|
+
* @category Lang
|
|
30616
|
+
* @param {*} value The value to process.
|
|
30617
|
+
* @returns {number} Returns the number.
|
|
30618
|
+
* @example
|
|
30619
|
+
*
|
|
30620
|
+
* _.toNumber(3.2);
|
|
30621
|
+
* // => 3.2
|
|
30622
|
+
*
|
|
30623
|
+
* _.toNumber(Number.MIN_VALUE);
|
|
30624
|
+
* // => 5e-324
|
|
30625
|
+
*
|
|
30626
|
+
* _.toNumber(Infinity);
|
|
30627
|
+
* // => Infinity
|
|
30628
|
+
*
|
|
30629
|
+
* _.toNumber('3.2');
|
|
30630
|
+
* // => 3.2
|
|
30631
|
+
*/
|
|
30632
|
+
function toNumber(value) {
|
|
30633
|
+
if (typeof value == 'number') {
|
|
30634
|
+
return value;
|
|
30635
|
+
}
|
|
30636
|
+
if (isSymbol_1(value)) {
|
|
30637
|
+
return NAN;
|
|
30638
|
+
}
|
|
30639
|
+
if (isObject_1(value)) {
|
|
30640
|
+
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
|
30641
|
+
value = isObject_1(other) ? (other + '') : other;
|
|
30642
|
+
}
|
|
30643
|
+
if (typeof value != 'string') {
|
|
30644
|
+
return value === 0 ? value : +value;
|
|
30645
|
+
}
|
|
30646
|
+
value = _baseTrim(value);
|
|
30647
|
+
var isBinary = reIsBinary.test(value);
|
|
30648
|
+
return (isBinary || reIsOctal.test(value))
|
|
30649
|
+
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
|
30650
|
+
: (reIsBadHex.test(value) ? NAN : +value);
|
|
30651
|
+
}
|
|
30652
|
+
|
|
30653
|
+
var toNumber_1 = toNumber;
|
|
30654
|
+
|
|
30655
|
+
/** Error message constants. */
|
|
30656
|
+
var FUNC_ERROR_TEXT$1 = 'Expected a function';
|
|
30657
|
+
|
|
30658
|
+
/* Built-in method references for those with the same name as other `lodash` methods. */
|
|
30659
|
+
var nativeMax$1 = Math.max,
|
|
30660
|
+
nativeMin = Math.min;
|
|
30661
|
+
|
|
30662
|
+
/**
|
|
30663
|
+
* Creates a debounced function that delays invoking `func` until after `wait`
|
|
30664
|
+
* milliseconds have elapsed since the last time the debounced function was
|
|
30665
|
+
* invoked. The debounced function comes with a `cancel` method to cancel
|
|
30666
|
+
* delayed `func` invocations and a `flush` method to immediately invoke them.
|
|
30667
|
+
* Provide `options` to indicate whether `func` should be invoked on the
|
|
30668
|
+
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
|
|
30669
|
+
* with the last arguments provided to the debounced function. Subsequent
|
|
30670
|
+
* calls to the debounced function return the result of the last `func`
|
|
30671
|
+
* invocation.
|
|
30672
|
+
*
|
|
30673
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
30674
|
+
* invoked on the trailing edge of the timeout only if the debounced function
|
|
30675
|
+
* is invoked more than once during the `wait` timeout.
|
|
30676
|
+
*
|
|
30677
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
30678
|
+
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
30679
|
+
*
|
|
30680
|
+
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
30681
|
+
* for details over the differences between `_.debounce` and `_.throttle`.
|
|
30682
|
+
*
|
|
30683
|
+
* @static
|
|
30684
|
+
* @memberOf _
|
|
30685
|
+
* @since 0.1.0
|
|
30686
|
+
* @category Function
|
|
30687
|
+
* @param {Function} func The function to debounce.
|
|
30688
|
+
* @param {number} [wait=0] The number of milliseconds to delay.
|
|
30689
|
+
* @param {Object} [options={}] The options object.
|
|
30690
|
+
* @param {boolean} [options.leading=false]
|
|
30691
|
+
* Specify invoking on the leading edge of the timeout.
|
|
30692
|
+
* @param {number} [options.maxWait]
|
|
30693
|
+
* The maximum time `func` is allowed to be delayed before it's invoked.
|
|
30694
|
+
* @param {boolean} [options.trailing=true]
|
|
30695
|
+
* Specify invoking on the trailing edge of the timeout.
|
|
30696
|
+
* @returns {Function} Returns the new debounced function.
|
|
30697
|
+
* @example
|
|
30698
|
+
*
|
|
30699
|
+
* // Avoid costly calculations while the window size is in flux.
|
|
30700
|
+
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
|
30701
|
+
*
|
|
30702
|
+
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
|
|
30703
|
+
* jQuery(element).on('click', _.debounce(sendMail, 300, {
|
|
30704
|
+
* 'leading': true,
|
|
30705
|
+
* 'trailing': false
|
|
30706
|
+
* }));
|
|
30707
|
+
*
|
|
30708
|
+
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
|
|
30709
|
+
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
|
|
30710
|
+
* var source = new EventSource('/stream');
|
|
30711
|
+
* jQuery(source).on('message', debounced);
|
|
30712
|
+
*
|
|
30713
|
+
* // Cancel the trailing debounced invocation.
|
|
30714
|
+
* jQuery(window).on('popstate', debounced.cancel);
|
|
30715
|
+
*/
|
|
30716
|
+
function debounce(func, wait, options) {
|
|
30717
|
+
var lastArgs,
|
|
30718
|
+
lastThis,
|
|
30719
|
+
maxWait,
|
|
30720
|
+
result,
|
|
30721
|
+
timerId,
|
|
30722
|
+
lastCallTime,
|
|
30723
|
+
lastInvokeTime = 0,
|
|
30724
|
+
leading = false,
|
|
30725
|
+
maxing = false,
|
|
30726
|
+
trailing = true;
|
|
30727
|
+
|
|
30728
|
+
if (typeof func != 'function') {
|
|
30729
|
+
throw new TypeError(FUNC_ERROR_TEXT$1);
|
|
30730
|
+
}
|
|
30731
|
+
wait = toNumber_1(wait) || 0;
|
|
30732
|
+
if (isObject_1(options)) {
|
|
30733
|
+
leading = !!options.leading;
|
|
30734
|
+
maxing = 'maxWait' in options;
|
|
30735
|
+
maxWait = maxing ? nativeMax$1(toNumber_1(options.maxWait) || 0, wait) : maxWait;
|
|
30736
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
30737
|
+
}
|
|
30738
|
+
|
|
30739
|
+
function invokeFunc(time) {
|
|
30740
|
+
var args = lastArgs,
|
|
30741
|
+
thisArg = lastThis;
|
|
30742
|
+
|
|
30743
|
+
lastArgs = lastThis = undefined;
|
|
30744
|
+
lastInvokeTime = time;
|
|
30745
|
+
result = func.apply(thisArg, args);
|
|
30746
|
+
return result;
|
|
30747
|
+
}
|
|
30748
|
+
|
|
30749
|
+
function leadingEdge(time) {
|
|
30750
|
+
// Reset any `maxWait` timer.
|
|
30751
|
+
lastInvokeTime = time;
|
|
30752
|
+
// Start the timer for the trailing edge.
|
|
30753
|
+
timerId = setTimeout(timerExpired, wait);
|
|
30754
|
+
// Invoke the leading edge.
|
|
30755
|
+
return leading ? invokeFunc(time) : result;
|
|
30756
|
+
}
|
|
30757
|
+
|
|
30758
|
+
function remainingWait(time) {
|
|
30759
|
+
var timeSinceLastCall = time - lastCallTime,
|
|
30760
|
+
timeSinceLastInvoke = time - lastInvokeTime,
|
|
30761
|
+
timeWaiting = wait - timeSinceLastCall;
|
|
30762
|
+
|
|
30763
|
+
return maxing
|
|
30764
|
+
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
|
|
30765
|
+
: timeWaiting;
|
|
30766
|
+
}
|
|
30767
|
+
|
|
30768
|
+
function shouldInvoke(time) {
|
|
30769
|
+
var timeSinceLastCall = time - lastCallTime,
|
|
30770
|
+
timeSinceLastInvoke = time - lastInvokeTime;
|
|
30771
|
+
|
|
30772
|
+
// Either this is the first call, activity has stopped and we're at the
|
|
30773
|
+
// trailing edge, the system time has gone backwards and we're treating
|
|
30774
|
+
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
30775
|
+
return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
|
|
30776
|
+
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
|
|
30777
|
+
}
|
|
30778
|
+
|
|
30779
|
+
function timerExpired() {
|
|
30780
|
+
var time = now_1();
|
|
30781
|
+
if (shouldInvoke(time)) {
|
|
30782
|
+
return trailingEdge(time);
|
|
30783
|
+
}
|
|
30784
|
+
// Restart the timer.
|
|
30785
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
30786
|
+
}
|
|
30787
|
+
|
|
30788
|
+
function trailingEdge(time) {
|
|
30789
|
+
timerId = undefined;
|
|
30790
|
+
|
|
30791
|
+
// Only invoke if we have `lastArgs` which means `func` has been
|
|
30792
|
+
// debounced at least once.
|
|
30793
|
+
if (trailing && lastArgs) {
|
|
30794
|
+
return invokeFunc(time);
|
|
30795
|
+
}
|
|
30796
|
+
lastArgs = lastThis = undefined;
|
|
30797
|
+
return result;
|
|
30798
|
+
}
|
|
30799
|
+
|
|
30800
|
+
function cancel() {
|
|
30801
|
+
if (timerId !== undefined) {
|
|
30802
|
+
clearTimeout(timerId);
|
|
30803
|
+
}
|
|
30804
|
+
lastInvokeTime = 0;
|
|
30805
|
+
lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|
30806
|
+
}
|
|
30807
|
+
|
|
30808
|
+
function flush() {
|
|
30809
|
+
return timerId === undefined ? result : trailingEdge(now_1());
|
|
30810
|
+
}
|
|
30811
|
+
|
|
30812
|
+
function debounced() {
|
|
30813
|
+
var time = now_1(),
|
|
30814
|
+
isInvoking = shouldInvoke(time);
|
|
30815
|
+
|
|
30816
|
+
lastArgs = arguments;
|
|
30817
|
+
lastThis = this;
|
|
30818
|
+
lastCallTime = time;
|
|
30819
|
+
|
|
30820
|
+
if (isInvoking) {
|
|
30821
|
+
if (timerId === undefined) {
|
|
30822
|
+
return leadingEdge(lastCallTime);
|
|
30823
|
+
}
|
|
30824
|
+
if (maxing) {
|
|
30825
|
+
// Handle invocations in a tight loop.
|
|
30826
|
+
clearTimeout(timerId);
|
|
30827
|
+
timerId = setTimeout(timerExpired, wait);
|
|
30828
|
+
return invokeFunc(lastCallTime);
|
|
30829
|
+
}
|
|
30830
|
+
}
|
|
30831
|
+
if (timerId === undefined) {
|
|
30832
|
+
timerId = setTimeout(timerExpired, wait);
|
|
30833
|
+
}
|
|
30834
|
+
return result;
|
|
30835
|
+
}
|
|
30836
|
+
debounced.cancel = cancel;
|
|
30837
|
+
debounced.flush = flush;
|
|
30838
|
+
return debounced;
|
|
30839
|
+
}
|
|
30840
|
+
|
|
30841
|
+
var debounce_1 = debounce;
|
|
30842
|
+
|
|
30843
|
+
/** Error message constants. */
|
|
30844
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
30845
|
+
|
|
30846
|
+
/**
|
|
30847
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
30848
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
30849
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
30850
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
30851
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
30852
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
30853
|
+
* throttled function. Subsequent calls to the throttled function return the
|
|
30854
|
+
* result of the last `func` invocation.
|
|
30855
|
+
*
|
|
30856
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
30857
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
30858
|
+
* is invoked more than once during the `wait` timeout.
|
|
30859
|
+
*
|
|
30860
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
30861
|
+
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
30862
|
+
*
|
|
30863
|
+
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
30864
|
+
* for details over the differences between `_.throttle` and `_.debounce`.
|
|
30865
|
+
*
|
|
30866
|
+
* @static
|
|
30867
|
+
* @memberOf _
|
|
30868
|
+
* @since 0.1.0
|
|
30869
|
+
* @category Function
|
|
30870
|
+
* @param {Function} func The function to throttle.
|
|
30871
|
+
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|
30872
|
+
* @param {Object} [options={}] The options object.
|
|
30873
|
+
* @param {boolean} [options.leading=true]
|
|
30874
|
+
* Specify invoking on the leading edge of the timeout.
|
|
30875
|
+
* @param {boolean} [options.trailing=true]
|
|
30876
|
+
* Specify invoking on the trailing edge of the timeout.
|
|
30877
|
+
* @returns {Function} Returns the new throttled function.
|
|
30878
|
+
* @example
|
|
30879
|
+
*
|
|
30880
|
+
* // Avoid excessively updating the position while scrolling.
|
|
30881
|
+
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
30882
|
+
*
|
|
30883
|
+
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|
30884
|
+
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|
30885
|
+
* jQuery(element).on('click', throttled);
|
|
30886
|
+
*
|
|
30887
|
+
* // Cancel the trailing throttled invocation.
|
|
30888
|
+
* jQuery(window).on('popstate', throttled.cancel);
|
|
30889
|
+
*/
|
|
30890
|
+
function throttle(func, wait, options) {
|
|
30891
|
+
var leading = true,
|
|
30892
|
+
trailing = true;
|
|
30893
|
+
|
|
30894
|
+
if (typeof func != 'function') {
|
|
30895
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
30896
|
+
}
|
|
30897
|
+
if (isObject_1(options)) {
|
|
30898
|
+
leading = 'leading' in options ? !!options.leading : leading;
|
|
30899
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
30900
|
+
}
|
|
30901
|
+
return debounce_1(func, wait, {
|
|
30902
|
+
'leading': leading,
|
|
30903
|
+
'maxWait': wait,
|
|
30904
|
+
'trailing': trailing
|
|
30905
|
+
});
|
|
30906
|
+
}
|
|
30907
|
+
|
|
30908
|
+
var throttle_1 = throttle;
|
|
30909
|
+
|
|
30910
|
+
var ResourcePreviewCell = function (props) {
|
|
30911
|
+
return useObserver(function () { return (jsx(ListItem, { className: props.className, button: props.button, selected: props.selected },
|
|
30912
|
+
props.resource.image && (jsx(ListItemAvatar, null,
|
|
30913
|
+
jsx(Avatar, { css: { borderRadius: 4 }, src: props.resource.image.src }))),
|
|
30914
|
+
jsx(ListItemText, { primary: jsx("div", { css: {
|
|
30915
|
+
maxWidth: 400,
|
|
30916
|
+
overflow: 'hidden',
|
|
30917
|
+
textOverflow: 'ellipsis',
|
|
30918
|
+
whiteSpace: 'nowrap',
|
|
30919
|
+
} }, props.resource.title) }))); });
|
|
30920
|
+
};
|
|
30921
|
+
var ResourcePicker = function (props) {
|
|
30922
|
+
var store = useLocalStore(function () { return ({
|
|
30923
|
+
searchInputText: '',
|
|
30924
|
+
loading: false,
|
|
30925
|
+
resources: [],
|
|
30926
|
+
search: throttle_1(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
30927
|
+
var catchError, resourcesResponse;
|
|
30928
|
+
return __generator(this, function (_a) {
|
|
30929
|
+
switch (_a.label) {
|
|
30930
|
+
case 0:
|
|
30931
|
+
store.loading = true;
|
|
30932
|
+
catchError = function (err) {
|
|
30933
|
+
console.error('search error:', err);
|
|
30934
|
+
props.context.snackBar.show('Oh no! There was an error searching for resources');
|
|
30935
|
+
};
|
|
30936
|
+
return [4 /*yield*/, props.api[props.resourceName]
|
|
30937
|
+
.search(store.searchInputText)
|
|
30938
|
+
.catch(catchError)];
|
|
30939
|
+
case 1:
|
|
30940
|
+
resourcesResponse = _a.sent();
|
|
30941
|
+
runInAction(function () {
|
|
30942
|
+
if (Array.isArray(resourcesResponse)) {
|
|
30943
|
+
store.resources = resourcesResponse.filter(function (resource) { return !(props.omitIds || []).includes(String(resource.id)); });
|
|
30944
|
+
}
|
|
30945
|
+
store.loading = false;
|
|
30946
|
+
});
|
|
30947
|
+
return [2 /*return*/];
|
|
30948
|
+
}
|
|
30949
|
+
});
|
|
30950
|
+
}); }, 400),
|
|
30951
|
+
}); });
|
|
30952
|
+
useEffect(function () {
|
|
30953
|
+
store.search();
|
|
30954
|
+
}, [store.searchInputText]);
|
|
30955
|
+
return useObserver(function () { return (jsx("div", { css: { display: 'flex', flexDirection: 'column', minWidth: 500 } },
|
|
30956
|
+
jsx(TextField, { css: { margin: 15 }, value: store.searchInputText, placeholder: props.title || "Search " + pluralize.plural(props.resourceName) + "...", InputProps: {
|
|
30957
|
+
startAdornment: (jsx(InputAdornment, { position: "start" },
|
|
30958
|
+
jsx(Search$1, { css: { color: '#999', marginRight: -2, fontSize: 20 } }))),
|
|
30959
|
+
}, onChange: action(function (e) { return (store.searchInputText = e.target.value); }) }),
|
|
30960
|
+
store.loading && jsx(CircularProgress, { disableShrink: true, css: { margin: '50px auto' } }),
|
|
30961
|
+
jsx("div", { css: { maxHeight: '80vh', overflow: 'auto' } }, !store.loading &&
|
|
30962
|
+
(store.resources.length ? (store.resources.map(function (item) {
|
|
30963
|
+
var _a;
|
|
30964
|
+
return (jsx("div", { key: item.id, onClick: function (e) {
|
|
30965
|
+
props.onChange(item);
|
|
30966
|
+
} },
|
|
30967
|
+
jsx(ResourcePreviewCell, { selected: String(item.id) === String((_a = props.value) === null || _a === void 0 ? void 0 : _a.id), button: true, resource: item, key: item.id })));
|
|
30968
|
+
})) : (jsx("div", null,
|
|
30969
|
+
jsx(Typography, { css: {
|
|
30970
|
+
margin: '40px 20px',
|
|
30971
|
+
textAlign: 'center',
|
|
30972
|
+
fontSize: 17,
|
|
30973
|
+
}, variant: "caption" },
|
|
30974
|
+
"No ",
|
|
30975
|
+
pluralize.plural(props.resourceName),
|
|
30976
|
+
" found"))))))); });
|
|
30977
|
+
};
|
|
30978
|
+
var ResourcesPickerButton = function (props) {
|
|
30979
|
+
var store = useLocalStore(function () {
|
|
30980
|
+
var _a, _b;
|
|
30981
|
+
return ({
|
|
30982
|
+
loading: false,
|
|
30983
|
+
error: null,
|
|
30984
|
+
resourceInfo: null,
|
|
30985
|
+
resourceHandle: props.handleOnly && typeof props.value === 'string' ? props.value : undefined,
|
|
30986
|
+
resourceId: props.handleOnly
|
|
30987
|
+
? undefined
|
|
30988
|
+
: typeof props.value === 'string'
|
|
30989
|
+
? props.value
|
|
30990
|
+
: (_b = (_a = props.value) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.get(props.resourceName),
|
|
30991
|
+
getResource: function () {
|
|
30992
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
30993
|
+
var resourceService, value, _a, _b, _c, e_1;
|
|
30994
|
+
return __generator(this, function (_d) {
|
|
30995
|
+
switch (_d.label) {
|
|
30996
|
+
case 0:
|
|
30997
|
+
this.error = null;
|
|
30998
|
+
this.loading = true;
|
|
30999
|
+
_d.label = 1;
|
|
31000
|
+
case 1:
|
|
31001
|
+
_d.trys.push([1, 7, , 8]);
|
|
31002
|
+
resourceService = props.api[props.resourceName];
|
|
31003
|
+
_b = this.resourceId;
|
|
31004
|
+
if (!_b) return [3 /*break*/, 3];
|
|
31005
|
+
return [4 /*yield*/, resourceService.findById(this.resourceId)];
|
|
31006
|
+
case 2:
|
|
31007
|
+
_b = (_d.sent());
|
|
31008
|
+
_d.label = 3;
|
|
31009
|
+
case 3:
|
|
31010
|
+
_a = (_b);
|
|
31011
|
+
if (_a) return [3 /*break*/, 6];
|
|
31012
|
+
_c = this.resourceHandle &&
|
|
31013
|
+
resourceService.findByHandle;
|
|
31014
|
+
if (!_c) return [3 /*break*/, 5];
|
|
31015
|
+
return [4 /*yield*/, resourceService.findByHandle(this.resourceHandle)];
|
|
31016
|
+
case 4:
|
|
31017
|
+
_c = (_d.sent());
|
|
31018
|
+
_d.label = 5;
|
|
31019
|
+
case 5:
|
|
31020
|
+
_a = (_c);
|
|
31021
|
+
_d.label = 6;
|
|
31022
|
+
case 6:
|
|
31023
|
+
value = _a;
|
|
31024
|
+
this.resourceInfo = value || null;
|
|
31025
|
+
return [3 /*break*/, 8];
|
|
31026
|
+
case 7:
|
|
31027
|
+
e_1 = _d.sent();
|
|
31028
|
+
console.error(e_1);
|
|
31029
|
+
this.error = e_1;
|
|
31030
|
+
props.context.snackBar.show("Oh no! There was an error fetching " + pluralize.plural(props.resourceName));
|
|
31031
|
+
return [3 /*break*/, 8];
|
|
31032
|
+
case 8:
|
|
31033
|
+
this.loading = false;
|
|
31034
|
+
return [2 /*return*/];
|
|
31035
|
+
}
|
|
31036
|
+
});
|
|
31037
|
+
});
|
|
31038
|
+
},
|
|
31039
|
+
showPickResouceModal: function (title) {
|
|
31040
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
31041
|
+
var resourcePicker, rest, PickerCompnent, close;
|
|
31042
|
+
var _this = this;
|
|
31043
|
+
return __generator(this, function (_a) {
|
|
31044
|
+
switch (_a.label) {
|
|
31045
|
+
case 0:
|
|
31046
|
+
props.value, resourcePicker = props.resourcePicker, rest = __rest(props, ["value", "resourcePicker"]);
|
|
31047
|
+
PickerCompnent = resourcePicker || ResourcePicker;
|
|
31048
|
+
return [4 /*yield*/, props.context.globalState.openDialog(jsx(PickerCompnent, __assign({}, rest, { resourceName: props.resourceName }, (this.resourceInfo && { value: this.resourceInfo }), { title: title, onChange: action(function (value) {
|
|
31049
|
+
var _a;
|
|
31050
|
+
if (value) {
|
|
31051
|
+
_this.resourceHandle = value.handle;
|
|
31052
|
+
_this.resourceId = String(value.id);
|
|
31053
|
+
_this.getResource();
|
|
31054
|
+
if (props.handleOnly) {
|
|
31055
|
+
props.onChange(_this.resourceHandle);
|
|
31056
|
+
}
|
|
31057
|
+
else {
|
|
31058
|
+
if ((_a = props.field) === null || _a === void 0 ? void 0 : _a.isTargeting) {
|
|
31059
|
+
props.onChange(_this.resourceId);
|
|
31060
|
+
}
|
|
31061
|
+
else {
|
|
31062
|
+
props.onChange(props.api[props.resourceName].getRequestObject(_this.resourceId, value));
|
|
31063
|
+
}
|
|
31064
|
+
}
|
|
31065
|
+
}
|
|
31066
|
+
close();
|
|
31067
|
+
}) })), true, {
|
|
31068
|
+
PaperProps: {
|
|
31069
|
+
// Align modal to top so doesn't jump around centering itself when
|
|
31070
|
+
// grows and shrinks to show more/less resources or loading
|
|
31071
|
+
style: {
|
|
31072
|
+
alignSelf: 'flex-start',
|
|
31073
|
+
},
|
|
31074
|
+
},
|
|
31075
|
+
})];
|
|
31076
|
+
case 1:
|
|
31077
|
+
close = _a.sent();
|
|
31078
|
+
return [2 /*return*/];
|
|
31079
|
+
}
|
|
31080
|
+
});
|
|
31081
|
+
});
|
|
31082
|
+
},
|
|
31083
|
+
});
|
|
31084
|
+
});
|
|
31085
|
+
useEffect(function () {
|
|
31086
|
+
store.getResource();
|
|
31087
|
+
}, []);
|
|
31088
|
+
useEffect(function () {
|
|
31089
|
+
var _a, _b;
|
|
31090
|
+
var hasPreviewFields = Boolean((_a = props.context.designerState.editingModel) === null || _a === void 0 ? void 0 : _a.fields.find(function (field) { return field.type === props.previewType; }));
|
|
31091
|
+
if (hasPreviewFields &&
|
|
31092
|
+
props.context.globalState.globalDialogs.length === 0 && ((_b = props.context.designerState) === null || _b === void 0 ? void 0 : _b.editingContentModel) &&
|
|
31093
|
+
props.isPreview &&
|
|
31094
|
+
(!props.value || store.error)) {
|
|
31095
|
+
setTimeout(function () { return store.showPickResouceModal("Pick a " + props.resourceName + " to preview"); });
|
|
31096
|
+
}
|
|
31097
|
+
}, [store.error]);
|
|
31098
|
+
return useObserver(function () {
|
|
31099
|
+
var pluginSettings = props.context.user.organization.value.settings.plugins.get(props.pluginId);
|
|
31100
|
+
if (!pluginSettings.get('hasConnected')) {
|
|
31101
|
+
return jsx(SetEcomKeysMessage, { pluginId: props.pluginId, pluginName: props.pluginName });
|
|
31102
|
+
}
|
|
31103
|
+
return (jsx("div", { css: { display: 'flex', flexDirection: 'column', padding: '10px 0' } },
|
|
31104
|
+
store.loading && (jsx(CircularProgress, { size: 20, disableShrink: true, css: { margin: '30px auto' } })),
|
|
31105
|
+
store.resourceInfo && (jsx(Paper, { css: {
|
|
31106
|
+
marginBottom: 15,
|
|
31107
|
+
position: 'relative',
|
|
31108
|
+
} },
|
|
31109
|
+
jsx(ResourcePreviewCell, { button: true, css: { paddingRight: 30 }, resource: store.resourceInfo }),
|
|
31110
|
+
jsx(IconButton, { css: {
|
|
31111
|
+
position: 'absolute',
|
|
31112
|
+
right: 2,
|
|
31113
|
+
top: 0,
|
|
31114
|
+
bottom: 0,
|
|
31115
|
+
height: 50,
|
|
31116
|
+
marginTop: 'auto',
|
|
31117
|
+
marginBottom: 'auto',
|
|
31118
|
+
}, onClick: function () {
|
|
31119
|
+
store.showPickResouceModal();
|
|
31120
|
+
} },
|
|
31121
|
+
jsx(Create$1, { css: { color: '#888' } })))),
|
|
31122
|
+
!store.resourceInfo && !store.loading && (jsx(Button, { color: "primary", variant: "contained", onClick: function () {
|
|
31123
|
+
store.showPickResouceModal();
|
|
31124
|
+
} },
|
|
31125
|
+
"Choose ",
|
|
31126
|
+
props.resourceName))));
|
|
31127
|
+
});
|
|
31128
|
+
};
|
|
31129
|
+
|
|
31130
|
+
/**
|
|
31131
|
+
* A specialized version of `_.map` for arrays without support for iteratee
|
|
31132
|
+
* shorthands.
|
|
31133
|
+
*
|
|
31134
|
+
* @private
|
|
31135
|
+
* @param {Array} [array] The array to iterate over.
|
|
31136
|
+
* @param {Function} iteratee The function invoked per iteration.
|
|
31137
|
+
* @returns {Array} Returns the new mapped array.
|
|
31138
|
+
*/
|
|
31139
|
+
function arrayMap(array, iteratee) {
|
|
31140
|
+
var index = -1,
|
|
31141
|
+
length = array == null ? 0 : array.length,
|
|
31142
|
+
result = Array(length);
|
|
31143
|
+
|
|
31144
|
+
while (++index < length) {
|
|
31145
|
+
result[index] = iteratee(array[index], index, array);
|
|
31146
|
+
}
|
|
31147
|
+
return result;
|
|
31148
|
+
}
|
|
31149
|
+
|
|
31150
|
+
var _arrayMap = arrayMap;
|
|
31151
|
+
|
|
31152
|
+
/**
|
|
31153
|
+
* Checks if `value` is classified as an `Array` object.
|
|
31154
|
+
*
|
|
31155
|
+
* @static
|
|
31156
|
+
* @memberOf _
|
|
31157
|
+
* @since 0.1.0
|
|
31158
|
+
* @category Lang
|
|
31159
|
+
* @param {*} value The value to check.
|
|
31160
|
+
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
|
31161
|
+
* @example
|
|
31162
|
+
*
|
|
31163
|
+
* _.isArray([1, 2, 3]);
|
|
31164
|
+
* // => true
|
|
31165
|
+
*
|
|
31166
|
+
* _.isArray(document.body.children);
|
|
31167
|
+
* // => false
|
|
31168
|
+
*
|
|
31169
|
+
* _.isArray('abc');
|
|
31170
|
+
* // => false
|
|
31171
|
+
*
|
|
31172
|
+
* _.isArray(_.noop);
|
|
31173
|
+
* // => false
|
|
31174
|
+
*/
|
|
31175
|
+
var isArray = Array.isArray;
|
|
31176
|
+
|
|
31177
|
+
var isArray_1 = isArray;
|
|
31178
|
+
|
|
30771
31179
|
/** Used as references for various `Number` constants. */
|
|
30772
31180
|
var INFINITY = 1 / 0;
|
|
30773
31181
|
|
|
@@ -31115,17 +31523,19 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
31115
31523
|
marginLeft: 'auto',
|
|
31116
31524
|
alignSelf: 'center',
|
|
31117
31525
|
}, onClick: function () {
|
|
31118
|
-
var res = __spreadArrays(props.value).
|
|
31526
|
+
var res = __spreadArrays(props.value.slice(0, props.value.indexOf(item)), props.value.slice(props.value.indexOf(item) + 1));
|
|
31119
31527
|
props.onChange(res);
|
|
31120
31528
|
} },
|
|
31121
31529
|
jsx(Close$1, null))))); })),
|
|
31122
31530
|
jsx(Button, { color: "primary", variant: "outlined", fullWidth: true, css: { marginTop: 10 }, onClick: function () {
|
|
31123
|
-
var
|
|
31531
|
+
props.value; var resourcePicker = props.resourcePicker, rest = __rest(props, ["value", "resourcePicker"]);
|
|
31532
|
+
var PickerCompnent = resourcePicker || ResourcePicker;
|
|
31533
|
+
var close = appState.globalState.openDialog(jsx(PickerCompnent, __assign({}, rest, { context: appState, omitIds: store.value, onChange: action(function (resource) {
|
|
31124
31534
|
if (resource) {
|
|
31125
31535
|
props.onChange(__spreadArrays((store.value || []), [String(resource.id)]));
|
|
31126
31536
|
}
|
|
31127
31537
|
close();
|
|
31128
|
-
}) }));
|
|
31538
|
+
}) })));
|
|
31129
31539
|
} },
|
|
31130
31540
|
"+ ",
|
|
31131
31541
|
capitalize_1(props.resourceName)),
|
|
@@ -31156,38 +31566,6 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
31156
31566
|
});
|
|
31157
31567
|
}
|
|
31158
31568
|
|
|
31159
|
-
/**
|
|
31160
|
-
* Checks if `value` is the
|
|
31161
|
-
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
31162
|
-
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
31163
|
-
*
|
|
31164
|
-
* @static
|
|
31165
|
-
* @memberOf _
|
|
31166
|
-
* @since 0.1.0
|
|
31167
|
-
* @category Lang
|
|
31168
|
-
* @param {*} value The value to check.
|
|
31169
|
-
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
31170
|
-
* @example
|
|
31171
|
-
*
|
|
31172
|
-
* _.isObject({});
|
|
31173
|
-
* // => true
|
|
31174
|
-
*
|
|
31175
|
-
* _.isObject([1, 2, 3]);
|
|
31176
|
-
* // => true
|
|
31177
|
-
*
|
|
31178
|
-
* _.isObject(_.noop);
|
|
31179
|
-
* // => true
|
|
31180
|
-
*
|
|
31181
|
-
* _.isObject(null);
|
|
31182
|
-
* // => false
|
|
31183
|
-
*/
|
|
31184
|
-
function isObject(value) {
|
|
31185
|
-
var type = typeof value;
|
|
31186
|
-
return value != null && (type == 'object' || type == 'function');
|
|
31187
|
-
}
|
|
31188
|
-
|
|
31189
|
-
var isObject_1 = isObject;
|
|
31190
|
-
|
|
31191
31569
|
/** `Object#toString` result references. */
|
|
31192
31570
|
var asyncTag = '[object AsyncFunction]',
|
|
31193
31571
|
funcTag$1 = '[object Function]',
|
|
@@ -32953,72 +33331,77 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
32953
33331
|
|
|
32954
33332
|
var template_1 = template;
|
|
32955
33333
|
|
|
32956
|
-
var onEditorLoad = function (config, apiOperations, resourceName) {
|
|
32957
|
-
|
|
32958
|
-
|
|
32959
|
-
|
|
32960
|
-
|
|
32961
|
-
|
|
32962
|
-
|
|
32963
|
-
|
|
32964
|
-
|
|
32965
|
-
var previewField = (_c = (_b = appState.designerState.editingModel) === null || _b === void 0 ? void 0 : _b.fields.find(function (field) {
|
|
32966
|
-
return field.type === "" + config.name + capitalize_1(resourceName) + "Preview";
|
|
32967
|
-
})) === null || _c === void 0 ? void 0 : _c.name;
|
|
32968
|
-
if (previewField && appState.designerState.editingContentModel) {
|
|
32969
|
-
var resourceId = (_d = appState.designerState.editingContentModel.data
|
|
32970
|
-
.get(previewField)) === null || _d === void 0 ? void 0 : _d.options.get(resourceName);
|
|
32971
|
-
return apiOperations[resourceName].findById(resourceId);
|
|
32972
|
-
}
|
|
32973
|
-
var pluginSettings = appState.user.organization.value.settings.plugins.get(config.id);
|
|
32974
|
-
var shouldSync = pluginSettings.get('syncPreviewUrlWithTargeting');
|
|
32975
|
-
var query = (_f = (_e = appState.designerState.editingContentModel) === null || _e === void 0 ? void 0 : _e.query) === null || _f === void 0 ? void 0 : _f.toJSON();
|
|
32976
|
-
var customAttributes = (_g = appState.user.organization.value.customTargetingAttributes) === null || _g === void 0 ? void 0 : _g.toJSON();
|
|
32977
|
-
if (shouldSync && customAttributes && query) {
|
|
32978
|
-
var apiService = apiOperations[resourceName];
|
|
32979
|
-
var _loop_1 = function (key, value) {
|
|
32980
|
-
var targetingValue = (_h = query.find(function (q) { return q.property === key; })) === null || _h === void 0 ? void 0 : _h.value;
|
|
32981
|
-
if (targetingValue && value.type === "" + config.name + capitalize_1(resourceName)) {
|
|
32982
|
-
return { value: apiService.findById(targetingValue) };
|
|
32983
|
-
}
|
|
32984
|
-
if (apiService.findByHandle &&
|
|
32985
|
-
targetingValue &&
|
|
32986
|
-
value.type === "" + config.name + capitalize_1(resourceName) + "Handle") {
|
|
32987
|
-
return { value: apiService.findByHandle(targetingValue) };
|
|
32988
|
-
}
|
|
32989
|
-
};
|
|
32990
|
-
for (var _i = 0, _j = Object.entries(customAttributes); _i < _j.length; _i++) {
|
|
32991
|
-
var _k = _j[_i], key = _k[0], value = _k[1];
|
|
32992
|
-
var state_1 = _loop_1(key, value);
|
|
32993
|
-
if (typeof state_1 === "object")
|
|
32994
|
-
return state_1.value;
|
|
33334
|
+
var onEditorLoad = function (config, apiOperations, resourceName) {
|
|
33335
|
+
return function (_a) {
|
|
33336
|
+
var safeReaction = _a.safeReaction, updatePreviewUrl = _a.updatePreviewUrl;
|
|
33337
|
+
// compile previewResource if any, to allow user to have templated editing urls for their models (e.g in cases of product page template)
|
|
33338
|
+
safeReaction(function () {
|
|
33339
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
33340
|
+
var modelUrl = (_a = appState.designerState.editingModel) === null || _a === void 0 ? void 0 : _a.examplePageUrl;
|
|
33341
|
+
if (!modelUrl) {
|
|
33342
|
+
return;
|
|
32995
33343
|
}
|
|
32996
|
-
|
|
32997
|
-
|
|
32998
|
-
|
|
32999
|
-
|
|
33000
|
-
|
|
33001
|
-
|
|
33002
|
-
|
|
33003
|
-
|
|
33004
|
-
|
|
33005
|
-
|
|
33006
|
-
|
|
33007
|
-
|
|
33008
|
-
|
|
33009
|
-
|
|
33010
|
-
|
|
33011
|
-
}));
|
|
33012
|
-
if (
|
|
33013
|
-
|
|
33014
|
-
|
|
33344
|
+
var previewField = (_c = (_b = appState.designerState.editingModel) === null || _b === void 0 ? void 0 : _b.fields.find(function (field) {
|
|
33345
|
+
return field.type === "" + config.name + capitalize_1(resourceName) + "Preview";
|
|
33346
|
+
})) === null || _c === void 0 ? void 0 : _c.name;
|
|
33347
|
+
if (previewField && appState.designerState.editingContentModel) {
|
|
33348
|
+
var resourceId = (_d = appState.designerState.editingContentModel.data
|
|
33349
|
+
.get(previewField)) === null || _d === void 0 ? void 0 : _d.options.get(resourceName);
|
|
33350
|
+
return apiOperations[resourceName].findById(resourceId);
|
|
33351
|
+
}
|
|
33352
|
+
var pluginSettings = appState.user.organization.value.settings.plugins.get(config.id);
|
|
33353
|
+
var shouldSync = pluginSettings.get('syncPreviewUrlWithTargeting');
|
|
33354
|
+
var query = (_f = (_e = appState.designerState.editingContentModel) === null || _e === void 0 ? void 0 : _e.query) === null || _f === void 0 ? void 0 : _f.toJSON();
|
|
33355
|
+
var customAttributes = (_g = appState.user.organization.value.customTargetingAttributes) === null || _g === void 0 ? void 0 : _g.toJSON();
|
|
33356
|
+
if (shouldSync && customAttributes && query) {
|
|
33357
|
+
var apiService = apiOperations[resourceName];
|
|
33358
|
+
var _loop_1 = function (key, value) {
|
|
33359
|
+
var targetingValue = (_h = query.find(function (q) { return q.property === key; })) === null || _h === void 0 ? void 0 : _h.value;
|
|
33360
|
+
if (targetingValue && value.type === "" + config.name + capitalize_1(resourceName)) {
|
|
33361
|
+
return { value: apiService.findById(targetingValue) };
|
|
33362
|
+
}
|
|
33363
|
+
if (apiService.findByHandle &&
|
|
33364
|
+
targetingValue &&
|
|
33365
|
+
value.type === "" + config.name + capitalize_1(resourceName) + "Handle") {
|
|
33366
|
+
return { value: apiService.findByHandle(targetingValue) };
|
|
33015
33367
|
}
|
|
33016
|
-
|
|
33017
|
-
|
|
33368
|
+
};
|
|
33369
|
+
for (var _i = 0, _j = Object.entries(customAttributes); _i < _j.length; _i++) {
|
|
33370
|
+
var _k = _j[_i], key = _k[0], value = _k[1];
|
|
33371
|
+
var state_1 = _loop_1(key, value);
|
|
33372
|
+
if (typeof state_1 === "object")
|
|
33373
|
+
return state_1.value;
|
|
33374
|
+
}
|
|
33018
33375
|
}
|
|
33019
|
-
})
|
|
33020
|
-
|
|
33021
|
-
|
|
33376
|
+
}, function (resourcePromise) { return __awaiter(void 0, void 0, void 0, function () {
|
|
33377
|
+
var modelUrl, previewResource, compiled, previewUrl;
|
|
33378
|
+
var _a;
|
|
33379
|
+
var _b;
|
|
33380
|
+
return __generator(this, function (_c) {
|
|
33381
|
+
switch (_c.label) {
|
|
33382
|
+
case 0:
|
|
33383
|
+
modelUrl = (_b = appState.designerState.editingModel) === null || _b === void 0 ? void 0 : _b.examplePageUrl;
|
|
33384
|
+
if (!(resourcePromise && modelUrl)) return [3 /*break*/, 2];
|
|
33385
|
+
return [4 /*yield*/, resourcePromise];
|
|
33386
|
+
case 1:
|
|
33387
|
+
previewResource = _c.sent();
|
|
33388
|
+
compiled = template_1(modelUrl);
|
|
33389
|
+
previewUrl = compiled(withDefaults((_a = {
|
|
33390
|
+
previewResource: previewResource
|
|
33391
|
+
},
|
|
33392
|
+
_a["preview" + capitalize_1(resourceName)] = previewResource,
|
|
33393
|
+
_a)));
|
|
33394
|
+
if (modelUrl !== previewUrl) {
|
|
33395
|
+
updatePreviewUrl(previewUrl);
|
|
33396
|
+
appState.snackBar.show("Previewing " + previewUrl);
|
|
33397
|
+
}
|
|
33398
|
+
_c.label = 2;
|
|
33399
|
+
case 2: return [2 /*return*/];
|
|
33400
|
+
}
|
|
33401
|
+
});
|
|
33402
|
+
}); });
|
|
33403
|
+
};
|
|
33404
|
+
};
|
|
33022
33405
|
var withDefaults = function (obj) {
|
|
33023
33406
|
var _a;
|
|
33024
33407
|
return (__assign(__assign({}, obj), { space: {
|
|
@@ -33095,27 +33478,33 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33095
33478
|
api: apiOperations,
|
|
33096
33479
|
};
|
|
33097
33480
|
Builder.register('editor.onLoad', onEditorLoad(config, apiOperations, resourceName));
|
|
33481
|
+
var resourcePicker = apiOperations[resourceName].resourcePicker;
|
|
33098
33482
|
Builder.registerEditor({
|
|
33099
33483
|
name: "" + config.name + capitalize_1(resourceName),
|
|
33484
|
+
isDataResource: true,
|
|
33485
|
+
pluginId: config.id,
|
|
33100
33486
|
component: function (props) { return (React.createElement(ErrorBoundary, null,
|
|
33101
|
-
React.createElement(ResourcesPickerButton, __assign({}, props, contextProps)))); },
|
|
33102
|
-
});
|
|
33103
|
-
Builder.registerEditor({
|
|
33104
|
-
name: "" + config.name + capitalize_1(resourceName) + "Preview",
|
|
33105
|
-
component: function (props) { return (React.createElement(ErrorBoundary, null,
|
|
33106
|
-
React.createElement(ResourcesPickerButton, __assign({}, props, contextProps, { previewType: "" + config.name + capitalize_1(resourceName) + "Preview", isPreview: true })))); },
|
|
33487
|
+
React.createElement(ResourcesPickerButton, __assign({ resourcePicker: resourcePicker }, props, contextProps)))); },
|
|
33107
33488
|
});
|
|
33489
|
+
if (!config.noPreviewTypes) {
|
|
33490
|
+
Builder.registerEditor({
|
|
33491
|
+
name: "" + config.name + capitalize_1(resourceName) + "Preview",
|
|
33492
|
+
component: function (props) { return (React.createElement(ErrorBoundary, null,
|
|
33493
|
+
React.createElement(ResourcesPickerButton, __assign({ resourcePicker: resourcePicker }, props, contextProps, { previewType: "" + config.name + capitalize_1(resourceName) + "Preview", isPreview: true })))); },
|
|
33494
|
+
});
|
|
33495
|
+
}
|
|
33108
33496
|
if (apiOperations[resourceName].findByHandle) {
|
|
33109
33497
|
Builder.registerEditor({
|
|
33110
33498
|
name: "" + config.name + capitalize_1(resourceName) + "Handle",
|
|
33111
33499
|
component: function (props) { return (React.createElement(ErrorBoundary, null,
|
|
33112
|
-
React.createElement(ResourcesPickerButton, __assign({}, props, contextProps, { handleOnly: true })))); },
|
|
33500
|
+
React.createElement(ResourcesPickerButton, __assign({ resourcePicker: resourcePicker }, props, contextProps, { handleOnly: true })))); },
|
|
33113
33501
|
});
|
|
33114
33502
|
}
|
|
33115
33503
|
Builder.registerEditor({
|
|
33116
33504
|
name: "" + config.name + capitalize_1(pluralize.plural(resourceName)) + "List",
|
|
33505
|
+
enum: true,
|
|
33117
33506
|
component: function (props) { return (React.createElement(ErrorBoundary, null,
|
|
33118
|
-
React.createElement(PickResourcesListButton, __assign({}, props, contextProps)))); },
|
|
33507
|
+
React.createElement(PickResourcesListButton, __assign({ resourcePicker: resourcePicker }, props, contextProps)))); },
|
|
33119
33508
|
});
|
|
33120
33509
|
});
|
|
33121
33510
|
return [2 /*return*/];
|
|
@@ -33174,7 +33563,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33174
33563
|
}); };
|
|
33175
33564
|
|
|
33176
33565
|
var name = "@builder.io/plugin-sfcc-commerce-api";
|
|
33177
|
-
var version = "0.0.
|
|
33566
|
+
var version = "0.0.4";
|
|
33178
33567
|
var description = "";
|
|
33179
33568
|
var keywords = [
|
|
33180
33569
|
];
|
|
@@ -33290,7 +33679,7 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33290
33679
|
typescript: "^3.0.3"
|
|
33291
33680
|
};
|
|
33292
33681
|
var dependencies = {
|
|
33293
|
-
"@builder.io/commerce-plugin-tools": "^0.
|
|
33682
|
+
"@builder.io/commerce-plugin-tools": "^0.3.1-1",
|
|
33294
33683
|
"commerce-sdk-isomorphic": "^1.7.0"
|
|
33295
33684
|
};
|
|
33296
33685
|
var pkg = {
|
|
@@ -33319,6 +33708,32 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33319
33708
|
dependencies: dependencies
|
|
33320
33709
|
};
|
|
33321
33710
|
|
|
33711
|
+
const basicCache = new Map();
|
|
33712
|
+
const transformProduct = (resource) => ({
|
|
33713
|
+
...resource,
|
|
33714
|
+
id: resource.id,
|
|
33715
|
+
title: resource.name || "untitled",
|
|
33716
|
+
handle: resource.id,
|
|
33717
|
+
image: {
|
|
33718
|
+
src: resource.imageGroups?.[0].images?.[0].link || "https://unpkg.com/css.gg@2.0.0/icons/svg/toolbox.svg"
|
|
33719
|
+
}
|
|
33720
|
+
});
|
|
33721
|
+
const transformHit = (hit) => ({
|
|
33722
|
+
id: hit.productId,
|
|
33723
|
+
title: hit.productName || "untitled",
|
|
33724
|
+
handle: hit.productId,
|
|
33725
|
+
image: {
|
|
33726
|
+
src: hit.image?.link || "https://unpkg.com/css.gg@2.0.0/icons/svg/toolbox.svg"
|
|
33727
|
+
}
|
|
33728
|
+
});
|
|
33729
|
+
const transformCategory = (cat) => ({
|
|
33730
|
+
id: cat.id,
|
|
33731
|
+
title: cat.name,
|
|
33732
|
+
handle: cat.id,
|
|
33733
|
+
image: {
|
|
33734
|
+
src: cat.image || "https://unpkg.com/css.gg@2.0.0/icons/svg/box.svg"
|
|
33735
|
+
}
|
|
33736
|
+
});
|
|
33322
33737
|
class Api {
|
|
33323
33738
|
constructor(apiKey, pluginId) {
|
|
33324
33739
|
this.apiKey = apiKey;
|
|
@@ -33344,16 +33759,38 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33344
33759
|
}).then((res) => res.json());
|
|
33345
33760
|
}
|
|
33346
33761
|
getProduct(id) {
|
|
33347
|
-
|
|
33762
|
+
if (basicCache.get(id)) {
|
|
33763
|
+
return Promise.resolve(basicCache.get(id));
|
|
33764
|
+
}
|
|
33765
|
+
return this.request(`products/${id}`).then((product) => {
|
|
33766
|
+
const resource = transformProduct(product);
|
|
33767
|
+
basicCache.set(resource.id, resource);
|
|
33768
|
+
return resource;
|
|
33769
|
+
});
|
|
33348
33770
|
}
|
|
33349
|
-
search(search
|
|
33350
|
-
return this.request("products-search", { method: "GET" }, { q: search })
|
|
33771
|
+
search(search) {
|
|
33772
|
+
return this.request("products-search", { method: "GET" }, { q: search }).then((search2) => {
|
|
33773
|
+
const resources = search2.hits?.map(transformHit) || [];
|
|
33774
|
+
resources.forEach((r) => basicCache.set(r.id, r));
|
|
33775
|
+
return resources;
|
|
33776
|
+
});
|
|
33351
33777
|
}
|
|
33352
33778
|
getCategory(id) {
|
|
33353
|
-
|
|
33779
|
+
if (basicCache.get(id)) {
|
|
33780
|
+
return Promise.resolve(basicCache.get(id));
|
|
33781
|
+
}
|
|
33782
|
+
return this.request(`categories/${id}`).then((cat) => {
|
|
33783
|
+
const resource = transformProduct(cat);
|
|
33784
|
+
basicCache.set(resource.id, resource);
|
|
33785
|
+
return resource;
|
|
33786
|
+
});
|
|
33354
33787
|
}
|
|
33355
33788
|
searchCategories(search) {
|
|
33356
|
-
return this.request("categories-search", { method: "GET" }, { q: search })
|
|
33789
|
+
return this.request("categories-search", { method: "GET" }, { q: search }).then((categories) => {
|
|
33790
|
+
const resources = categories?.map(transformCategory) || [];
|
|
33791
|
+
resources.forEach((r) => basicCache.set(r.id, r));
|
|
33792
|
+
return resources;
|
|
33793
|
+
});
|
|
33357
33794
|
}
|
|
33358
33795
|
}
|
|
33359
33796
|
|
|
@@ -33390,39 +33827,13 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33390
33827
|
ctaText: `Connect your Salesforce Commerce API`
|
|
33391
33828
|
}, async () => {
|
|
33392
33829
|
const api = new Api(appState.user.apiKey, pkg.name);
|
|
33393
|
-
|
|
33394
|
-
...resource,
|
|
33395
|
-
id: resource.id,
|
|
33396
|
-
title: resource.name || "untitled",
|
|
33397
|
-
handle: resource.id,
|
|
33398
|
-
image: {
|
|
33399
|
-
src: resource.imageGroups?.[0].images?.[0].link || "https://cdn.builder.io/api/v1/image/assets%2F979b06c19c1f41b0825d33993be6cdd4%2F478d9c03b7c24eaabbdb6346e67d5ed2"
|
|
33400
|
-
}
|
|
33401
|
-
});
|
|
33402
|
-
const transformCat = (cat) => ({
|
|
33403
|
-
id: cat.id,
|
|
33404
|
-
title: cat.name,
|
|
33405
|
-
handle: cat.id,
|
|
33406
|
-
image: {
|
|
33407
|
-
src: cat.image || "https://unpkg.com/css.gg@2.0.0/icons/svg/box.svg"
|
|
33408
|
-
}
|
|
33409
|
-
});
|
|
33410
|
-
const service = {
|
|
33830
|
+
return {
|
|
33411
33831
|
product: {
|
|
33412
33832
|
async findById(id) {
|
|
33413
|
-
|
|
33414
|
-
return transform(product);
|
|
33833
|
+
return await api.getProduct(id);
|
|
33415
33834
|
},
|
|
33416
33835
|
async search(search) {
|
|
33417
|
-
|
|
33418
|
-
return searchResult.hits?.map((hit) => ({
|
|
33419
|
-
id: hit.productId,
|
|
33420
|
-
title: hit.productName || "untitled",
|
|
33421
|
-
handle: hit.productId,
|
|
33422
|
-
image: {
|
|
33423
|
-
src: hit.image?.link || "https://unpkg.com/css.gg@2.0.0/icons/svg/toolbox.svg"
|
|
33424
|
-
}
|
|
33425
|
-
})) || [];
|
|
33836
|
+
return await api.search(search || "womens");
|
|
33426
33837
|
},
|
|
33427
33838
|
getRequestObject(id) {
|
|
33428
33839
|
return {
|
|
@@ -33438,12 +33849,10 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33438
33849
|
},
|
|
33439
33850
|
category: {
|
|
33440
33851
|
async findById(id) {
|
|
33441
|
-
|
|
33442
|
-
return transformCat(cat);
|
|
33852
|
+
return await api.getCategory(id);
|
|
33443
33853
|
},
|
|
33444
33854
|
async search(search) {
|
|
33445
|
-
|
|
33446
|
-
return categories.map(transformCat);
|
|
33855
|
+
return await api.searchCategories(search || "");
|
|
33447
33856
|
},
|
|
33448
33857
|
getRequestObject(id) {
|
|
33449
33858
|
return {
|
|
@@ -33458,7 +33867,6 @@ System.register(['@builder.io/react', '@emotion/core', '@material-ui/core', 'rea
|
|
|
33458
33867
|
}
|
|
33459
33868
|
}
|
|
33460
33869
|
};
|
|
33461
|
-
return service;
|
|
33462
33870
|
});
|
|
33463
33871
|
|
|
33464
33872
|
}
|