@threekit-tools/treble 0.0.60 → 0.0.61
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/Treble.d.ts +2 -2
- package/dist/Treble/Treble.js +7 -2
- package/dist/components/ThreekitProvider/index.d.ts +1 -0
- package/dist/components/ThreekitProvider/index.js +10 -3
- 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 +2 -2
- package/dist/components/containers/formInputContainer.js +4 -4
- package/dist/hooks/useAttribute/index.js +5 -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 +13 -5
- package/dist/hooks/useProductCache/index.js +16 -23
- package/dist/hooks/useWishlist/index.d.ts +8 -6
- package/dist/hooks/useWishlist/index.js +16 -22
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -2
- package/dist/store/attributes.d.ts +3 -3
- package/dist/store/attributes.js +3 -50
- package/dist/store/product.d.ts +22 -13
- package/dist/store/product.js +98 -54
- package/dist/store/translations.d.ts +4 -3
- package/dist/store/translations.js +4 -14
- package/dist/store/treble.d.ts +4 -0
- package/dist/store/treble.js +69 -30
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +53 -1
- package/package.json +1 -1
package/dist/store/treble.js
CHANGED
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.reloadPlayer = exports.unloadPlayer = exports.launch = exports.initPlayer = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = exports.reloadTreble = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = void 0;
|
|
53
|
+
exports.reloadPlayer = exports.unloadPlayer = exports.launch = exports.initPlayer = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = exports.getThreekitEnv = exports.reloadTreble = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = exports.setThreekitEnv = void 0;
|
|
54
54
|
var connection_1 = __importDefault(require("../connection"));
|
|
55
55
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
56
56
|
var api_1 = __importDefault(require("../api"));
|
|
@@ -98,6 +98,7 @@ var EVENTS = {};
|
|
|
98
98
|
* State
|
|
99
99
|
****************************************************/
|
|
100
100
|
var initialState = {
|
|
101
|
+
threekitEnv: 'preview',
|
|
101
102
|
isThreekitInitialized: false,
|
|
102
103
|
isPlayerLoading: false,
|
|
103
104
|
playerElId: undefined,
|
|
@@ -106,6 +107,7 @@ var initialState = {
|
|
|
106
107
|
/*****************************************************
|
|
107
108
|
* Actions
|
|
108
109
|
****************************************************/
|
|
110
|
+
exports.setThreekitEnv = (0, toolkit_1.createAction)('treble/set-threekit-env');
|
|
109
111
|
exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
|
|
110
112
|
exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
|
|
111
113
|
exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
|
|
@@ -118,6 +120,10 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
118
120
|
initialState: initialState,
|
|
119
121
|
reducers: {},
|
|
120
122
|
extraReducers: function (builder) {
|
|
123
|
+
builder.addCase(exports.setThreekitEnv, function (state, action) {
|
|
124
|
+
state.threekitEnv = action.payload;
|
|
125
|
+
return state;
|
|
126
|
+
});
|
|
121
127
|
builder.addCase(exports.setThreekitInitialized, function (state, action) {
|
|
122
128
|
state.isThreekitInitialized = action.payload;
|
|
123
129
|
return state;
|
|
@@ -139,6 +145,11 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
139
145
|
* Standard Selectors
|
|
140
146
|
****************************************************/
|
|
141
147
|
// Loading Trackers
|
|
148
|
+
var getThreekitEnv = function (state) {
|
|
149
|
+
return state.treble.threekitEnv;
|
|
150
|
+
};
|
|
151
|
+
exports.getThreekitEnv = getThreekitEnv;
|
|
152
|
+
// Loading Trackers
|
|
142
153
|
var isThreekitInitialized = function (state) {
|
|
143
154
|
return state.treble.isThreekitInitialized;
|
|
144
155
|
};
|
|
@@ -197,41 +208,67 @@ var initPlayer = function (config) { return function (dispatch) { return __await
|
|
|
197
208
|
exports.initPlayer = initPlayer;
|
|
198
209
|
var launch = function (launchConfig) {
|
|
199
210
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
-
var config, credentials, products, threekitEnv, serverUrl, playerConfig, envCredentials,
|
|
201
|
-
var
|
|
202
|
-
return __generator(this, function (
|
|
203
|
-
switch (
|
|
211
|
+
var config, productId, credentials, productsRaw, products, threekitEnv, serverUrl, playerConfig, envCredentials, _a, assetId, stageId, configurationId, initialConfigurationRaw, threekitDomainRaw, orgId, authToken, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
212
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
213
|
+
return __generator(this, function (_j) {
|
|
214
|
+
switch (_j.label) {
|
|
204
215
|
case 0:
|
|
205
216
|
if (window.threekit)
|
|
206
217
|
return [2 /*return*/];
|
|
207
218
|
config = (0, utils_1.loadTrebleConfig)();
|
|
208
|
-
credentials =
|
|
209
|
-
|
|
219
|
+
credentials = ((_b = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _b === void 0 ? void 0 : _b.credentials) || ((_c = config.project) === null || _c === void 0 ? void 0 : _c.credentials) || {};
|
|
220
|
+
productsRaw = ((_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _d === void 0 ? void 0 : _d.products) || ((_e = config.project) === null || _e === void 0 ? void 0 : _e.products) || {};
|
|
221
|
+
if (!((_f = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.productId) === null || _f === void 0 ? void 0 : _f.length)) {
|
|
222
|
+
productsRaw = { default: productsRaw };
|
|
223
|
+
productId = 'default';
|
|
224
|
+
}
|
|
225
|
+
else
|
|
226
|
+
productId = launchConfig.productId;
|
|
227
|
+
products = Object.entries(productsRaw).reduce(function (output, _a) {
|
|
228
|
+
var _b;
|
|
229
|
+
var prodId = _a[0], envs = _a[1];
|
|
230
|
+
var updatedEnvs = Object.entries(envs).reduce(function (result, _a) {
|
|
231
|
+
var _b;
|
|
232
|
+
var env = _a[0], conf = _a[1];
|
|
233
|
+
var initialConfiguration;
|
|
234
|
+
var assetId;
|
|
235
|
+
var stageId;
|
|
236
|
+
var configurationId;
|
|
237
|
+
if (typeof conf === 'string') {
|
|
238
|
+
if ((0, utils_1.isUuid)(conf))
|
|
239
|
+
assetId = conf;
|
|
240
|
+
else
|
|
241
|
+
configurationId = conf;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
stageId = conf.stageId;
|
|
245
|
+
if (conf.configurationId)
|
|
246
|
+
configurationId = conf.configurationId;
|
|
247
|
+
else if ((0, utils_1.isUuid)(conf.assetId))
|
|
248
|
+
assetId = conf.assetId;
|
|
249
|
+
else
|
|
250
|
+
configurationId = conf.assetId;
|
|
251
|
+
}
|
|
252
|
+
return Object.assign(result, (_b = {},
|
|
253
|
+
_b[env] = {
|
|
254
|
+
assetId: assetId,
|
|
255
|
+
stageId: stageId,
|
|
256
|
+
configurationId: configurationId,
|
|
257
|
+
initialConfiguration: initialConfiguration,
|
|
258
|
+
},
|
|
259
|
+
_b));
|
|
260
|
+
}, {});
|
|
261
|
+
return Object.assign(output, (_b = {}, _b[prodId] = updatedEnvs, _b));
|
|
262
|
+
}, {});
|
|
210
263
|
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
211
264
|
return [2 /*return*/, console.error('Missing credentials')];
|
|
212
265
|
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
213
|
-
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((
|
|
214
|
-
(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
266
|
+
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((_g = config === null || config === void 0 ? void 0 : config.project) === null || _g === void 0 ? void 0 : _g.serverUrl);
|
|
215
267
|
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
216
268
|
envCredentials = credentials[threekitEnv];
|
|
217
|
-
|
|
269
|
+
_a = products[productId][threekitEnv], assetId = _a.assetId, stageId = _a.stageId, configurationId = _a.configurationId, initialConfigurationRaw = _a.initialConfiguration;
|
|
218
270
|
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
219
271
|
orgId = envCredentials.orgId, authToken = envCredentials.publicToken;
|
|
220
|
-
if (typeof product === 'string') {
|
|
221
|
-
if ((0, utils_1.isUuid)(product))
|
|
222
|
-
assetId = product;
|
|
223
|
-
else
|
|
224
|
-
configurationId = product;
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
stageId = product.stageId;
|
|
228
|
-
if (product.configurationId)
|
|
229
|
-
configurationId = product.configurationId;
|
|
230
|
-
else if ((0, utils_1.isUuid)(product.assetId))
|
|
231
|
-
assetId = product.assetId;
|
|
232
|
-
else
|
|
233
|
-
configurationId = product.assetId;
|
|
234
|
-
}
|
|
235
272
|
if (playerConfig.elementId) {
|
|
236
273
|
el = document.getElementById(playerConfig.elementId);
|
|
237
274
|
if (el)
|
|
@@ -253,19 +290,19 @@ var launch = function (launchConfig) {
|
|
|
253
290
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
254
291
|
updatedAssetId = assetId;
|
|
255
292
|
params = (0, utils_1.getParams)();
|
|
256
|
-
configId = ((
|
|
293
|
+
configId = ((_h = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _h === void 0 ? void 0 : _h.length)
|
|
257
294
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
258
295
|
: configurationId;
|
|
259
296
|
if (!configId) return [3 /*break*/, 2];
|
|
260
297
|
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
261
298
|
case 1:
|
|
262
|
-
configuration =
|
|
299
|
+
configuration = _j.sent();
|
|
263
300
|
if (configuration) {
|
|
264
301
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
265
302
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
266
303
|
updatedAssetId = configuration.data.productId;
|
|
267
304
|
}
|
|
268
|
-
|
|
305
|
+
_j.label = 2;
|
|
269
306
|
case 2:
|
|
270
307
|
if (!updatedAssetId)
|
|
271
308
|
return [2 /*return*/, console.error('missing assetId')];
|
|
@@ -279,7 +316,7 @@ var launch = function (launchConfig) {
|
|
|
279
316
|
})];
|
|
280
317
|
case 3:
|
|
281
318
|
// We create the threekit script
|
|
282
|
-
|
|
319
|
+
_j.sent();
|
|
283
320
|
return [4 /*yield*/, dispatch((0, exports.initPlayer)({
|
|
284
321
|
el: el,
|
|
285
322
|
orgId: orgId,
|
|
@@ -290,15 +327,17 @@ var launch = function (launchConfig) {
|
|
|
290
327
|
initialConfiguration: initialConfiguration,
|
|
291
328
|
}))];
|
|
292
329
|
case 4:
|
|
293
|
-
|
|
330
|
+
_j.sent();
|
|
294
331
|
document.addEventListener('treble:notification', function (e) {
|
|
295
332
|
message_1.default.info(e.detail.message);
|
|
296
333
|
});
|
|
297
334
|
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
335
|
+
dispatch((0, exports.setThreekitEnv)(threekitEnv));
|
|
298
336
|
dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
|
|
299
337
|
dispatch((0, price_1.initPrice)());
|
|
300
338
|
dispatch((0, price_1.updatePrice)());
|
|
301
339
|
dispatch((0, product_1.initProduct)(products));
|
|
340
|
+
dispatch((0, product_1.setProductId)(productId));
|
|
302
341
|
dispatch((0, wishlist_1.refreshWishlist)());
|
|
303
342
|
return [2 /*return*/];
|
|
304
343
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute } from './threekit';
|
|
1
|
+
import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute, ISetConfiguration, IHydratedAttribute } from './threekit';
|
|
2
2
|
import { ITrebleConfig, IAttributeTypes } from './threekit';
|
|
3
3
|
import { RawAttributeValue } from './hooks/useAttribute';
|
|
4
|
+
import { ITranslationMap } from './api/products';
|
|
4
5
|
interface ICameraPosition {
|
|
5
6
|
position: ICoordinates;
|
|
6
7
|
quaternion: IQuaternion;
|
|
@@ -46,6 +47,11 @@ export declare const downloadSnapshot: (snapshot: string, filename: string) => P
|
|
|
46
47
|
export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
|
|
47
48
|
export declare const easeInOutCubic: (val: number) => number;
|
|
48
49
|
export declare const metadataValueToObject: (data: string) => Record<string, string | number>;
|
|
50
|
+
export declare const hydrateAttribute: (data: [
|
|
51
|
+
Record<string, IThreekitDisplayAttribute>,
|
|
52
|
+
undefined | ITranslationMap,
|
|
53
|
+
undefined | string
|
|
54
|
+
], optionSelectionHandler: (config: ISetConfiguration) => Promise<void>) => Record<string, IHydratedAttribute>;
|
|
49
55
|
export declare const selectionToConfiguration: (value: RawAttributeValue, attributeType: IAttributeTypes) => string | number | boolean | File | IConfigurationColor | {
|
|
50
56
|
assetId: RawAttributeValue;
|
|
51
57
|
} | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -45,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.loadTrebleConfig = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = 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;
|
|
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;
|
|
49
49
|
var constants_1 = require("./constants");
|
|
50
50
|
var generateClassName = function (baseClass) {
|
|
51
51
|
return function (component, customClassName, title) {
|
|
@@ -309,6 +309,58 @@ var metadataValueToObject = function (data) {
|
|
|
309
309
|
}, {});
|
|
310
310
|
};
|
|
311
311
|
exports.metadataValueToObject = metadataValueToObject;
|
|
312
|
+
var hydrateAttribute = function (data, optionSelectionHandler) {
|
|
313
|
+
var attributes = data[0], translations = data[1], language = data[2];
|
|
314
|
+
var hasTranslation = !!language && !!translations;
|
|
315
|
+
return Object.values(attributes).reduce(function (output, attribute) {
|
|
316
|
+
var _a;
|
|
317
|
+
var _b;
|
|
318
|
+
return Object.assign(output, (_a = {},
|
|
319
|
+
_a[attribute.name] = Object.assign({}, attribute, {
|
|
320
|
+
label: hasTranslation
|
|
321
|
+
? ((_b = translations === null || translations === void 0 ? void 0 : translations[attribute.name]) === null || _b === void 0 ? void 0 : _b[language]) || attribute.name
|
|
322
|
+
: attribute.name,
|
|
323
|
+
}, attribute.type === 'String'
|
|
324
|
+
? {
|
|
325
|
+
values: attribute.values.map(function (el) {
|
|
326
|
+
var _a;
|
|
327
|
+
return Object.assign({}, el, {
|
|
328
|
+
label: hasTranslation
|
|
329
|
+
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
|
|
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,
|
|
338
|
+
});
|
|
339
|
+
}),
|
|
340
|
+
}
|
|
341
|
+
: attribute.type === 'Asset'
|
|
342
|
+
? {
|
|
343
|
+
values: attribute.values.map(function (el) {
|
|
344
|
+
var _a;
|
|
345
|
+
return Object.assign({}, el, {
|
|
346
|
+
label: hasTranslation
|
|
347
|
+
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
|
|
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,
|
|
356
|
+
});
|
|
357
|
+
}),
|
|
358
|
+
}
|
|
359
|
+
: undefined),
|
|
360
|
+
_a));
|
|
361
|
+
}, {});
|
|
362
|
+
};
|
|
363
|
+
exports.hydrateAttribute = hydrateAttribute;
|
|
312
364
|
var selectionToConfiguration = function (value, attributeType) {
|
|
313
365
|
switch (attributeType) {
|
|
314
366
|
case constants_1.ATTRIBUTE_TYPES.number:
|