@threekit-tools/treble 0.0.57 → 0.0.60-next.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/Treble/Snapshots.js +32 -63
- package/dist/Treble/Treble.d.ts +9 -7
- package/dist/Treble/Treble.js +26 -6
- package/dist/Treble/Wishlist.d.ts +3 -3
- package/dist/Treble/Wishlist.js +1 -0
- package/dist/api/configurations.d.ts +2 -3
- package/dist/api/configurations.js +28 -22
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/server.d.ts +2 -0
- package/dist/api/server.js +11 -0
- package/dist/components/Cards/index.js +3 -4
- package/dist/components/Dropdown/index.js +6 -10
- package/dist/components/Strips/index.js +3 -4
- package/dist/components/Swatch/index.js +3 -4
- package/dist/components/TextInput/index.d.ts +1 -0
- package/dist/components/TextInput/index.js +2 -2
- package/dist/components/TextInput/textInput.styles.js +1 -1
- package/dist/components/ThreekitProvider/index.d.ts +1 -0
- package/dist/components/ThreekitProvider/index.js +10 -3
- package/dist/components/Tiles/index.js +3 -4
- package/dist/components/TilesGroup/index.js +3 -4
- package/dist/components/TrebleApp/index.d.ts +1 -0
- package/dist/components/TrebleApp/index.js +16 -6
- package/dist/components/Wishlist/index.js +6 -11
- package/dist/components/containers/formInputContainer.d.ts +9 -5
- package/dist/components/containers/formInputContainer.js +14 -19
- package/dist/connection.d.ts +4 -1
- package/dist/connection.js +4 -0
- package/dist/hooks/useAttribute/index.d.ts +2 -2
- package/dist/hooks/useAttribute/index.js +6 -5
- package/dist/hooks/useConfigurator/index.d.ts +2 -2
- package/dist/hooks/useConfigurator/index.js +7 -3
- package/dist/hooks/useNestedConfigurator/index.d.ts +8 -0
- package/dist/hooks/useNestedConfigurator/index.js +93 -0
- package/dist/hooks/useProductCache/index.d.ts +22 -0
- package/dist/hooks/useProductCache/index.js +28 -0
- package/dist/hooks/useSingleAnimation/index.d.ts +17 -0
- package/dist/hooks/useSingleAnimation/index.js +264 -0
- package/dist/hooks/useWishlist/index.d.ts +10 -7
- package/dist/hooks/useWishlist/index.js +17 -25
- package/dist/http/configurations.d.ts +1 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +2 -0
- package/dist/http/server.d.ts +14 -0
- package/dist/http/server.js +17 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/store/attributes.d.ts +14 -1
- package/dist/store/attributes.js +6 -45
- package/dist/store/price.js +2 -2
- package/dist/store/product.d.ts +47 -2
- package/dist/store/product.js +267 -12
- package/dist/store/translations.d.ts +4 -2
- package/dist/store/translations.js +4 -12
- package/dist/store/treble.d.ts +36 -2
- package/dist/store/treble.js +214 -52
- package/dist/store/wishlist.d.ts +3 -2
- package/dist/threekit.d.ts +20 -2
- package/dist/utils.d.ts +9 -11
- package/dist/utils.js +83 -27
- package/package.json +17 -2
- package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
- package/dist/hooks/useArrayAttribute/index.js +0 -184
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
39
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
40
|
if (ar || !(i in from)) {
|
|
@@ -9,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
9
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
46
|
};
|
|
11
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.
|
|
48
|
+
exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.hydrateAttribute = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.downloadSnapshot = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.isJsonString = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
|
|
13
49
|
var constants_1 = require("./constants");
|
|
14
50
|
var generateClassName = function (baseClass) {
|
|
15
51
|
return function (component, customClassName, title) {
|
|
@@ -29,7 +65,7 @@ exports.generateLayoutClassName = (0, exports.generateClassName)(constants_1.LAY
|
|
|
29
65
|
exports.generateToolClassName = (0, exports.generateClassName)(constants_1.TOOL_CLASS_NAME);
|
|
30
66
|
exports.generateDisplayClassName = (0, exports.generateClassName)(constants_1.DISPLAY_CLASS_NAME);
|
|
31
67
|
exports.generateFormClassName = (0, exports.generateClassName)(constants_1.FORM_CLASS_NAME);
|
|
32
|
-
var
|
|
68
|
+
var isJsonString = function (str) {
|
|
33
69
|
try {
|
|
34
70
|
JSON.parse(str);
|
|
35
71
|
}
|
|
@@ -38,7 +74,7 @@ var IsJsonString = function (str) {
|
|
|
38
74
|
}
|
|
39
75
|
return true;
|
|
40
76
|
};
|
|
41
|
-
exports.
|
|
77
|
+
exports.isJsonString = isJsonString;
|
|
42
78
|
var isObject = function (object) {
|
|
43
79
|
return object != null && typeof object === 'object';
|
|
44
80
|
};
|
|
@@ -50,7 +86,7 @@ var objectToQueryStr = function (obj) {
|
|
|
50
86
|
if (i)
|
|
51
87
|
output += '&';
|
|
52
88
|
if (val !== undefined)
|
|
53
|
-
output += "".concat(key, "=").concat((0, exports.
|
|
89
|
+
output += "".concat(key, "=").concat((0, exports.isJsonString)(val) ? JSON.stringify(val) : val);
|
|
54
90
|
return output;
|
|
55
91
|
}, '?');
|
|
56
92
|
};
|
|
@@ -62,7 +98,7 @@ var getParams = function () {
|
|
|
62
98
|
if (!(key === null || key === void 0 ? void 0 : key.length))
|
|
63
99
|
return output;
|
|
64
100
|
var preppedValue = decodeURIComponent(value);
|
|
65
|
-
output[decodeURIComponent(key)] = (0, exports.
|
|
101
|
+
output[decodeURIComponent(key)] = (0, exports.isJsonString)(preppedValue)
|
|
66
102
|
? JSON.parse(preppedValue)
|
|
67
103
|
: preppedValue;
|
|
68
104
|
return output;
|
|
@@ -225,6 +261,27 @@ var dataURItoFile = function (dataURI, filename) {
|
|
|
225
261
|
return new File([u8arr], filename, { type: mime });
|
|
226
262
|
};
|
|
227
263
|
exports.dataURItoFile = dataURItoFile;
|
|
264
|
+
var downloadSnapshot = function (snapshot, filename) { return __awaiter(void 0, void 0, void 0, function () {
|
|
265
|
+
var blob, blobUrl, link, clickHandler;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
blob = (0, exports.dataURItoBlob)(snapshot);
|
|
268
|
+
blobUrl = URL.createObjectURL(blob);
|
|
269
|
+
link = document.createElement('a');
|
|
270
|
+
link.href = blobUrl;
|
|
271
|
+
link.download = filename;
|
|
272
|
+
clickHandler = function () {
|
|
273
|
+
setTimeout(function () {
|
|
274
|
+
URL.revokeObjectURL(blobUrl);
|
|
275
|
+
link.removeEventListener('click', clickHandler);
|
|
276
|
+
}, 150);
|
|
277
|
+
};
|
|
278
|
+
link.addEventListener('click', clickHandler);
|
|
279
|
+
document.body.appendChild(link);
|
|
280
|
+
link.click();
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
});
|
|
283
|
+
}); };
|
|
284
|
+
exports.downloadSnapshot = downloadSnapshot;
|
|
228
285
|
var copyToClipboard = function (data) {
|
|
229
286
|
if (!data)
|
|
230
287
|
return;
|
|
@@ -252,25 +309,10 @@ var metadataValueToObject = function (data) {
|
|
|
252
309
|
}, {});
|
|
253
310
|
};
|
|
254
311
|
exports.metadataValueToObject = metadataValueToObject;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
*
|
|
258
|
-
* @param threekitDomain The threekit environement to use. i.e. preview.threekit.com
|
|
259
|
-
* @returns
|
|
260
|
-
*/
|
|
261
|
-
var createThreekitScriptEl = function (threekitDomain) {
|
|
262
|
-
return new Promise(function (resolve) {
|
|
263
|
-
var script = document.createElement('script');
|
|
264
|
-
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
265
|
-
script.id = 'threekit-player-bundle';
|
|
266
|
-
script.onload = function () { return resolve(); };
|
|
267
|
-
document.head.appendChild(script);
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
exports.createThreekitScriptEl = createThreekitScriptEl;
|
|
271
|
-
var translateAttribute = function (attributes, translations, language) {
|
|
312
|
+
var hydrateAttribute = function (data, optionSelectionHandler) {
|
|
313
|
+
var attributes = data[0], translations = data[1], language = data[2];
|
|
272
314
|
var hasTranslation = !!language && !!translations;
|
|
273
|
-
return attributes.reduce(function (output, attribute) {
|
|
315
|
+
return Object.values(attributes).reduce(function (output, attribute) {
|
|
274
316
|
var _a;
|
|
275
317
|
var _b;
|
|
276
318
|
return Object.assign(output, (_a = {},
|
|
@@ -285,7 +327,14 @@ var translateAttribute = function (attributes, translations, language) {
|
|
|
285
327
|
return Object.assign({}, el, {
|
|
286
328
|
label: hasTranslation
|
|
287
329
|
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
|
|
288
|
-
:
|
|
330
|
+
: el.label,
|
|
331
|
+
handleSelect: function () {
|
|
332
|
+
var _a;
|
|
333
|
+
return optionSelectionHandler((_a = {},
|
|
334
|
+
_a[attribute.name] = el.value,
|
|
335
|
+
_a));
|
|
336
|
+
},
|
|
337
|
+
selected: attribute.value === el.value,
|
|
289
338
|
});
|
|
290
339
|
}),
|
|
291
340
|
}
|
|
@@ -296,15 +345,22 @@ var translateAttribute = function (attributes, translations, language) {
|
|
|
296
345
|
return Object.assign({}, el, {
|
|
297
346
|
label: hasTranslation
|
|
298
347
|
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
|
|
299
|
-
:
|
|
348
|
+
: el.name,
|
|
349
|
+
handleSelect: function () {
|
|
350
|
+
var _a;
|
|
351
|
+
return optionSelectionHandler((_a = {},
|
|
352
|
+
_a[attribute.name] = { assetId: el.assetId },
|
|
353
|
+
_a));
|
|
354
|
+
},
|
|
355
|
+
selected: attribute.value.assetId === el.assetId,
|
|
300
356
|
});
|
|
301
357
|
}),
|
|
302
358
|
}
|
|
303
359
|
: undefined),
|
|
304
360
|
_a));
|
|
305
|
-
});
|
|
361
|
+
}, {});
|
|
306
362
|
};
|
|
307
|
-
exports.
|
|
363
|
+
exports.hydrateAttribute = hydrateAttribute;
|
|
308
364
|
var selectionToConfiguration = function (value, attributeType) {
|
|
309
365
|
switch (attributeType) {
|
|
310
366
|
case constants_1.ATTRIBUTE_TYPES.number:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threekit-tools/treble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60-next.1",
|
|
4
4
|
"author": "Amaan Saeed",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"directory": "dist"
|
|
15
15
|
},
|
|
16
|
+
"jest": {
|
|
17
|
+
"verbose": true,
|
|
18
|
+
"globals": {
|
|
19
|
+
"ts-jest": {
|
|
20
|
+
"tsConfig": "tsconfig.json"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
16
24
|
"scripts": {
|
|
17
25
|
"start": "tsc --watch",
|
|
18
26
|
"build": "tsc",
|
|
@@ -21,7 +29,8 @@
|
|
|
21
29
|
"build-storybook": "build-storybook -o build",
|
|
22
30
|
"lint": "eslint ./src",
|
|
23
31
|
"check-format": "prettier -c ./src",
|
|
24
|
-
"format": "prettier --write ./src"
|
|
32
|
+
"format": "prettier --write ./src",
|
|
33
|
+
"test": "jest"
|
|
25
34
|
},
|
|
26
35
|
"dependencies": {
|
|
27
36
|
"@reduxjs/toolkit": "^1.6.2",
|
|
@@ -40,18 +49,24 @@
|
|
|
40
49
|
"@storybook/addon-links": "^6.3.12",
|
|
41
50
|
"@storybook/addon-storysource": "^6.3.12",
|
|
42
51
|
"@storybook/react": "^6.3.12",
|
|
52
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
53
|
+
"@testing-library/react": "^12.1.3",
|
|
54
|
+
"@types/jest": "^27.4.1",
|
|
43
55
|
"@types/node": "^16.10.3",
|
|
44
56
|
"@types/react": ">=17.0.27",
|
|
45
57
|
"@types/react-dom": ">=17.0.9",
|
|
46
58
|
"@types/redux-logger": "^3.0.9",
|
|
47
59
|
"@types/styled-components": "^5.1.15",
|
|
48
60
|
"@types/webpack-env": "^1.16.3",
|
|
61
|
+
"babel-jest": "^27.5.1",
|
|
49
62
|
"babel-loader": "^8.2.2",
|
|
63
|
+
"jest": "^27.5.1",
|
|
50
64
|
"react": ">=17.0.2",
|
|
51
65
|
"react-dom": ">=17.0.2",
|
|
52
66
|
"rimraf": "^3.0.2",
|
|
53
67
|
"serve": "^12.0.1",
|
|
54
68
|
"storybook-addon-styled-component-theme": "^2.0.0",
|
|
69
|
+
"ts-jest": "^27.1.3",
|
|
55
70
|
"typescript": ">=4.4.4"
|
|
56
71
|
},
|
|
57
72
|
"gitHead": "2e16bcf98f81e16bb1768072fdb3968122e7966f"
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import { useThreekitSelector, useThreekitDispatch } from '../../store';
|
|
3
|
-
// import { getAttributes, setConfiguration } from '../../store/attributes';
|
|
4
|
-
// import { selectionToConfiguration } from '../../utils';
|
|
5
|
-
// import {
|
|
6
|
-
// IConfigurationColor,
|
|
7
|
-
// ISetConfiguration,
|
|
8
|
-
// IThreekitDisplayAttribute,
|
|
9
|
-
// } from '../../threekit';
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.useArrayAttribute = void 0;
|
|
12
|
-
// export type AttributeValue = string | number | boolean | IConfigurationColor;
|
|
13
|
-
// type UseAttributeError = [undefined, undefined];
|
|
14
|
-
// type UseAttributeSuccess = [
|
|
15
|
-
// IThreekitDisplayAttribute,
|
|
16
|
-
// (val: AttributeValue) => void
|
|
17
|
-
// ];
|
|
18
|
-
var useArrayAttribute = function (attributeIdentifier) {
|
|
19
|
-
if (!attributeIdentifier)
|
|
20
|
-
return [];
|
|
21
|
-
return attributeIdentifier;
|
|
22
|
-
};
|
|
23
|
-
exports.useArrayAttribute = useArrayAttribute;
|
|
24
|
-
// Ordinal Configurator (Psuedo-Array type attribute)
|
|
25
|
-
// export const addItemToArray = (arrayLabel) => (
|
|
26
|
-
// assetId,
|
|
27
|
-
// addToIdx = undefined
|
|
28
|
-
// ) => async (dispatch, getState) => {
|
|
29
|
-
// if (!assetId?.length) return;
|
|
30
|
-
// const { threekit } = getState();
|
|
31
|
-
// const attributesRegExp = new RegExp(`${arrayLabel} [0-9]`);
|
|
32
|
-
// const arrayAttributes = filterAttributesArray(
|
|
33
|
-
// attributesRegExp,
|
|
34
|
-
// threekit.attributes
|
|
35
|
-
// );
|
|
36
|
-
// let updateAttrIdx = addToIdx;
|
|
37
|
-
// let attributeToUpdate;
|
|
38
|
-
// if (isNaN(updateAttrIdx))
|
|
39
|
-
// attributeToUpdate = Object.values(arrayAttributes).find((el, idx) => {
|
|
40
|
-
// if (!el.value.assetId?.length) {
|
|
41
|
-
// updateAttrIdx = idx;
|
|
42
|
-
// return true;
|
|
43
|
-
// }
|
|
44
|
-
// });
|
|
45
|
-
// else attributeToUpdate = arrayAttributes[updateAttrIdx];
|
|
46
|
-
// if (!attributeToUpdate) return message.info('Max items reached');
|
|
47
|
-
// let error;
|
|
48
|
-
// const options = Object.values(arrayAttributes)[0].values.reduce(
|
|
49
|
-
// (output, item) => Object.assign(output, { [item.assetId]: item }),
|
|
50
|
-
// {}
|
|
51
|
-
// );
|
|
52
|
-
// const updatedArray = Object.values(arrayAttributes).reduce(
|
|
53
|
-
// (output, attr, i) => {
|
|
54
|
-
// if (i !== updateAttrIdx) output.push(attr);
|
|
55
|
-
// else output.push({ ...attr, value: { assetId } });
|
|
56
|
-
// return output;
|
|
57
|
-
// },
|
|
58
|
-
// []
|
|
59
|
-
// );
|
|
60
|
-
// // Default Validator
|
|
61
|
-
// error = arrayValidator(options, updatedArray);
|
|
62
|
-
// if (error) return message.info(error);
|
|
63
|
-
// // Custom Validator
|
|
64
|
-
// if (MIDDLEWARE.arrayValidation?.[arrayLabel])
|
|
65
|
-
// error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
|
|
66
|
-
// if (error) return message.info(error);
|
|
67
|
-
// dispatch(setConfiguration({ [attributeToUpdate.name]: { assetId } }));
|
|
68
|
-
// };
|
|
69
|
-
// export const deleteItemFromArray = (arrayLabel) => (idx) => async (
|
|
70
|
-
// dispatch,
|
|
71
|
-
// getState
|
|
72
|
-
// ) => {
|
|
73
|
-
// if (isNaN(idx)) return;
|
|
74
|
-
// const { threekit } = getState();
|
|
75
|
-
// const attributesRegExp = new RegExp(`${arrayLabel} [0-9]`);
|
|
76
|
-
// const arrayAttributes = filterAttributesArray(
|
|
77
|
-
// attributesRegExp,
|
|
78
|
-
// threekit.attributes
|
|
79
|
-
// );
|
|
80
|
-
// let error;
|
|
81
|
-
// const options = Object.values(arrayAttributes)[0].values.reduce(
|
|
82
|
-
// (output, item) => Object.assign(output, { [item.assetId]: item }),
|
|
83
|
-
// {}
|
|
84
|
-
// );
|
|
85
|
-
// const updatedArray = Object.values(arrayAttributes).filter(
|
|
86
|
-
// (_, i) => i !== idx
|
|
87
|
-
// );
|
|
88
|
-
// // Default Validator
|
|
89
|
-
// error = arrayValidator(options, updatedArray);
|
|
90
|
-
// if (error) return message.info(error);
|
|
91
|
-
// // Custom Validator
|
|
92
|
-
// if (MIDDLEWARE.arrayValidation?.[arrayLabel])
|
|
93
|
-
// error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
|
|
94
|
-
// if (error) return message.info(error);
|
|
95
|
-
// const arrayConfigurationObj = filterAttributesArray(
|
|
96
|
-
// attributesRegExp,
|
|
97
|
-
// window.threekit.configurator.getConfiguration()
|
|
98
|
-
// );
|
|
99
|
-
// const arrayConfiguration = Object.entries(arrayConfigurationObj);
|
|
100
|
-
// const updatedConfiguration = arrayConfiguration.reduce(
|
|
101
|
-
// (output, [attributeName], i) => {
|
|
102
|
-
// if (i < idx) return output;
|
|
103
|
-
// if (!arrayConfiguration[i + 1])
|
|
104
|
-
// return Object.assign(output, { [attributeName]: { assetId: '' } });
|
|
105
|
-
// return Object.assign(output, {
|
|
106
|
-
// [attributeName]: arrayConfiguration[i + 1][1],
|
|
107
|
-
// });
|
|
108
|
-
// },
|
|
109
|
-
// {}
|
|
110
|
-
// );
|
|
111
|
-
// dispatch(setConfiguration(updatedConfiguration));
|
|
112
|
-
// };
|
|
113
|
-
// export const moveItemWithinArray = (arrayLabel) => (
|
|
114
|
-
// fromIdx,
|
|
115
|
-
// toIdx,
|
|
116
|
-
// config
|
|
117
|
-
// ) => async (dispatch, getState) => {
|
|
118
|
-
// if (isNaN(fromIdx) || isNaN(fromIdx)) return;
|
|
119
|
-
// const { threekit } = getState();
|
|
120
|
-
// const { method } = Object.assign({ method: 'move' }, config);
|
|
121
|
-
// const attributesRegExp =
|
|
122
|
-
// typeof arrayLabel === 'string'
|
|
123
|
-
// ? new RegExp(`${arrayLabel} [0-9]`)
|
|
124
|
-
// : arrayLabel;
|
|
125
|
-
// const arrayAttributes = filterAttributesArray(
|
|
126
|
-
// attributesRegExp,
|
|
127
|
-
// threekit.attributes
|
|
128
|
-
// );
|
|
129
|
-
// let error;
|
|
130
|
-
// const options = Object.values(arrayAttributes)[0].values.reduce(
|
|
131
|
-
// (output, item) => Object.assign(output, { [item.assetId]: item }),
|
|
132
|
-
// {}
|
|
133
|
-
// );
|
|
134
|
-
// let updatedArray;
|
|
135
|
-
// switch (method) {
|
|
136
|
-
// case 'move':
|
|
137
|
-
// updatedArray = Object.values(arrayAttributes).reduce(
|
|
138
|
-
// (output, attr, idx, srcArray) => {
|
|
139
|
-
// if (idx === fromIdx) return output;
|
|
140
|
-
// output.push(attr);
|
|
141
|
-
// if (idx === toIdx) output.push(srcArray[fromIdx]);
|
|
142
|
-
// return output;
|
|
143
|
-
// },
|
|
144
|
-
// []
|
|
145
|
-
// );
|
|
146
|
-
// break;
|
|
147
|
-
// default:
|
|
148
|
-
// break;
|
|
149
|
-
// }
|
|
150
|
-
// // Default Validator
|
|
151
|
-
// error = arrayValidator(options, updatedArray);
|
|
152
|
-
// if (error) return message.info(error);
|
|
153
|
-
// // Custom Validator
|
|
154
|
-
// if (MIDDLEWARE.arrayValidation?.[arrayLabel])
|
|
155
|
-
// error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
|
|
156
|
-
// if (error) return message.info(error);
|
|
157
|
-
// const arrayConfigurationObj = filterAttributesArray(
|
|
158
|
-
// attributesRegExp,
|
|
159
|
-
// window.threekit.configurator.getConfiguration()
|
|
160
|
-
// );
|
|
161
|
-
// const attributeKeys = Object.keys(arrayConfigurationObj);
|
|
162
|
-
// const arrayConfiguration = Object.values(arrayConfigurationObj);
|
|
163
|
-
// let updatedConfiguration;
|
|
164
|
-
// switch (method) {
|
|
165
|
-
// case 'move':
|
|
166
|
-
// updatedConfiguration = arrayConfiguration.reduce(
|
|
167
|
-
// (output, configuration, idx, srcArray) => {
|
|
168
|
-
// if (idx === fromIdx) return output;
|
|
169
|
-
// output = Object.assign(output, {
|
|
170
|
-
// [attributeKeys.shift()]: configuration,
|
|
171
|
-
// });
|
|
172
|
-
// if (idx === toIdx)
|
|
173
|
-
// output = Object.assign(output, {
|
|
174
|
-
// [attributeKeys.shift()]: srcArray[fromIdx],
|
|
175
|
-
// });
|
|
176
|
-
// return output;
|
|
177
|
-
// },
|
|
178
|
-
// {}
|
|
179
|
-
// );
|
|
180
|
-
// break;
|
|
181
|
-
// default:
|
|
182
|
-
// break;
|
|
183
|
-
// }
|
|
184
|
-
// dispatch(setConfiguration(updatedConfiguration));
|