@threekit-tools/treble 0.0.58 → 0.0.60-next.2
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 +8 -2
- package/dist/Treble/Treble.js +23 -2
- 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/useWishlist/index.d.ts +8 -6
- package/dist/hooks/useWishlist/index.js +16 -22
- 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 +5 -1
- package/dist/store/attributes.d.ts +14 -1
- package/dist/store/attributes.js +6 -45
- 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/threekit.d.ts +16 -1
- package/dist/utils.d.ts +7 -10
- package/dist/utils.js +22 -23
- package/package.json +1 -1
- package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
- package/dist/hooks/useArrayAttribute/index.js +0 -184
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.launch = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = 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"));
|
|
@@ -62,6 +62,7 @@ var price_1 = require("./price");
|
|
|
62
62
|
var wishlist_1 = require("./wishlist");
|
|
63
63
|
var translations_1 = require("./translations");
|
|
64
64
|
var product_1 = require("./product");
|
|
65
|
+
var message_1 = __importDefault(require("../components/message"));
|
|
65
66
|
/*****************************************************
|
|
66
67
|
* Helper Functions
|
|
67
68
|
****************************************************/
|
|
@@ -97,16 +98,20 @@ var EVENTS = {};
|
|
|
97
98
|
* State
|
|
98
99
|
****************************************************/
|
|
99
100
|
var initialState = {
|
|
101
|
+
threekitEnv: 'preview',
|
|
100
102
|
isThreekitInitialized: false,
|
|
101
103
|
isPlayerLoading: false,
|
|
102
104
|
playerElId: undefined,
|
|
105
|
+
notifications: true,
|
|
103
106
|
};
|
|
104
107
|
/*****************************************************
|
|
105
108
|
* Actions
|
|
106
109
|
****************************************************/
|
|
110
|
+
exports.setThreekitEnv = (0, toolkit_1.createAction)('treble/set-threekit-env');
|
|
107
111
|
exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
|
|
108
112
|
exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
|
|
109
113
|
exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
|
|
114
|
+
exports.reloadTreble = (0, toolkit_1.createAction)('treble/reload');
|
|
110
115
|
/*****************************************************
|
|
111
116
|
* Slice
|
|
112
117
|
****************************************************/
|
|
@@ -115,14 +120,24 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
115
120
|
initialState: initialState,
|
|
116
121
|
reducers: {},
|
|
117
122
|
extraReducers: function (builder) {
|
|
118
|
-
builder.addCase(exports.
|
|
119
|
-
state.
|
|
123
|
+
builder.addCase(exports.setThreekitEnv, function (state, action) {
|
|
124
|
+
state.threekitEnv = action.payload;
|
|
125
|
+
return state;
|
|
126
|
+
});
|
|
127
|
+
builder.addCase(exports.setThreekitInitialized, function (state, action) {
|
|
128
|
+
state.isThreekitInitialized = action.payload;
|
|
129
|
+
return state;
|
|
120
130
|
});
|
|
121
131
|
builder.addCase(exports.setPlayerLoading, function (state, action) {
|
|
122
132
|
state.isPlayerLoading = action.payload;
|
|
133
|
+
return state;
|
|
123
134
|
});
|
|
124
135
|
builder.addCase(exports.setPlayerElement, function (state, action) {
|
|
125
136
|
state.playerElId = action.payload;
|
|
137
|
+
return state;
|
|
138
|
+
});
|
|
139
|
+
builder.addCase(exports.reloadTreble, function (state, action) {
|
|
140
|
+
return __assign(__assign({}, state), action.payload);
|
|
126
141
|
});
|
|
127
142
|
},
|
|
128
143
|
}).reducer;
|
|
@@ -130,6 +145,11 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
130
145
|
* Standard Selectors
|
|
131
146
|
****************************************************/
|
|
132
147
|
// Loading Trackers
|
|
148
|
+
var getThreekitEnv = function (state) {
|
|
149
|
+
return state.treble.threekitEnv;
|
|
150
|
+
};
|
|
151
|
+
exports.getThreekitEnv = getThreekitEnv;
|
|
152
|
+
// Loading Trackers
|
|
133
153
|
var isThreekitInitialized = function (state) {
|
|
134
154
|
return state.treble.isThreekitInitialized;
|
|
135
155
|
};
|
|
@@ -146,41 +166,109 @@ exports.getPlayerElementId = getPlayerElementId;
|
|
|
146
166
|
/*****************************************************
|
|
147
167
|
* Complex Actions
|
|
148
168
|
****************************************************/
|
|
169
|
+
var initPlayer = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
|
+
var el, authToken, assetId, stageId, orgId, playerConfig, initialConfiguration, player, configurator;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
el = config.el, authToken = config.authToken, assetId = config.assetId, stageId = config.stageId, orgId = config.orgId, playerConfig = config.playerConfig, initialConfiguration = config.initialConfiguration;
|
|
175
|
+
return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
|
|
176
|
+
// Variables to sort out
|
|
177
|
+
authToken: authToken, stageId: stageId, assetId: assetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
178
|
+
case 1:
|
|
179
|
+
player = _a.sent();
|
|
180
|
+
return [4 /*yield*/, player.getConfigurator()];
|
|
181
|
+
case 2:
|
|
182
|
+
configurator = _a.sent();
|
|
183
|
+
if (window.threekit) {
|
|
184
|
+
window.threekit = Object.assign(window.threekit, {
|
|
185
|
+
player: player,
|
|
186
|
+
configurator: configurator,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
window.threekit = {
|
|
191
|
+
player: player,
|
|
192
|
+
configurator: configurator,
|
|
193
|
+
treble: new Treble_1.default({
|
|
194
|
+
player: player,
|
|
195
|
+
orgId: orgId,
|
|
196
|
+
initialConfiguration: configurator.getConfiguration(),
|
|
197
|
+
}),
|
|
198
|
+
};
|
|
199
|
+
dispatch((0, exports.setThreekitInitialized)(true));
|
|
200
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
201
|
+
window.threekit.player.on('setConfiguration', function () {
|
|
202
|
+
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
203
|
+
});
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}); }; };
|
|
208
|
+
exports.initPlayer = initPlayer;
|
|
149
209
|
var launch = function (launchConfig) {
|
|
150
210
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
-
var config, credentials, products, threekitEnv, playerConfig, envCredentials,
|
|
152
|
-
var
|
|
153
|
-
return __generator(this, function (
|
|
154
|
-
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) {
|
|
155
215
|
case 0:
|
|
156
216
|
if (window.threekit)
|
|
157
217
|
return [2 /*return*/];
|
|
158
218
|
config = (0, utils_1.loadTrebleConfig)();
|
|
159
|
-
credentials =
|
|
160
|
-
|
|
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
|
+
}, {});
|
|
161
263
|
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
162
264
|
return [2 /*return*/, console.error('Missing credentials')];
|
|
163
265
|
threekitEnv = (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);
|
|
164
267
|
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
165
268
|
envCredentials = credentials[threekitEnv];
|
|
166
|
-
|
|
269
|
+
_a = products[productId][threekitEnv], assetId = _a.assetId, stageId = _a.stageId, configurationId = _a.configurationId, initialConfigurationRaw = _a.initialConfiguration;
|
|
167
270
|
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
168
271
|
orgId = envCredentials.orgId, authToken = envCredentials.publicToken;
|
|
169
|
-
if (typeof product === 'string') {
|
|
170
|
-
if ((0, utils_1.isUuid)(product))
|
|
171
|
-
assetId = product;
|
|
172
|
-
else
|
|
173
|
-
configurationId = product;
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
stageId = product.stageId;
|
|
177
|
-
if (product.configurationId)
|
|
178
|
-
configurationId = product.configurationId;
|
|
179
|
-
else if ((0, utils_1.isUuid)(product.assetId))
|
|
180
|
-
assetId = product.assetId;
|
|
181
|
-
else
|
|
182
|
-
configurationId = product.assetId;
|
|
183
|
-
}
|
|
184
272
|
if (playerConfig.elementId) {
|
|
185
273
|
el = document.getElementById(playerConfig.elementId);
|
|
186
274
|
if (el)
|
|
@@ -196,59 +284,60 @@ var launch = function (launchConfig) {
|
|
|
196
284
|
orgId: orgId,
|
|
197
285
|
assetId: assetId,
|
|
198
286
|
threekitDomain: threekitDomainRaw,
|
|
287
|
+
serverUrl: serverUrl,
|
|
199
288
|
});
|
|
200
289
|
threekitDomain = connection_1.default.getConnection().threekitDomain;
|
|
201
290
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
202
291
|
updatedAssetId = assetId;
|
|
203
292
|
params = (0, utils_1.getParams)();
|
|
204
|
-
configId = ((
|
|
293
|
+
configId = ((_h = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _h === void 0 ? void 0 : _h.length)
|
|
205
294
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
206
295
|
: configurationId;
|
|
207
296
|
if (!configId) return [3 /*break*/, 2];
|
|
208
297
|
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
209
298
|
case 1:
|
|
210
|
-
configuration =
|
|
299
|
+
configuration = _j.sent();
|
|
211
300
|
if (configuration) {
|
|
212
301
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
213
302
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
214
303
|
updatedAssetId = configuration.data.productId;
|
|
215
304
|
}
|
|
216
|
-
|
|
305
|
+
_j.label = 2;
|
|
217
306
|
case 2:
|
|
218
307
|
if (!updatedAssetId)
|
|
219
308
|
return [2 /*return*/, console.error('missing assetId')];
|
|
220
309
|
// We create the threekit script
|
|
221
|
-
return [4 /*yield*/, (
|
|
310
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
311
|
+
var script = document.createElement('script');
|
|
312
|
+
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
313
|
+
script.id = 'threekit-player-bundle';
|
|
314
|
+
script.onload = function () { return resolve(); };
|
|
315
|
+
document.head.appendChild(script);
|
|
316
|
+
})];
|
|
222
317
|
case 3:
|
|
223
318
|
// We create the threekit script
|
|
224
|
-
|
|
225
|
-
return [4 /*yield*/,
|
|
226
|
-
|
|
227
|
-
authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
228
|
-
case 4:
|
|
229
|
-
player = _f.sent();
|
|
230
|
-
return [4 /*yield*/, player.getConfigurator()];
|
|
231
|
-
case 5:
|
|
232
|
-
configurator = _f.sent();
|
|
233
|
-
window.threekit = {
|
|
234
|
-
player: player,
|
|
235
|
-
configurator: configurator,
|
|
236
|
-
treble: new Treble_1.default({
|
|
237
|
-
player: player,
|
|
319
|
+
_j.sent();
|
|
320
|
+
return [4 /*yield*/, dispatch((0, exports.initPlayer)({
|
|
321
|
+
el: el,
|
|
238
322
|
orgId: orgId,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
323
|
+
authToken: authToken,
|
|
324
|
+
stageId: stageId,
|
|
325
|
+
assetId: updatedAssetId,
|
|
326
|
+
playerConfig: playerConfig,
|
|
327
|
+
initialConfiguration: initialConfiguration,
|
|
328
|
+
}))];
|
|
329
|
+
case 4:
|
|
330
|
+
_j.sent();
|
|
331
|
+
document.addEventListener('treble:notification', function (e) {
|
|
332
|
+
message_1.default.info(e.detail.message);
|
|
247
333
|
});
|
|
248
334
|
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
335
|
+
dispatch((0, exports.setThreekitEnv)(threekitEnv));
|
|
249
336
|
dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
|
|
250
337
|
dispatch((0, price_1.initPrice)());
|
|
251
|
-
dispatch((0,
|
|
338
|
+
dispatch((0, price_1.updatePrice)());
|
|
339
|
+
dispatch((0, product_1.initProduct)(products));
|
|
340
|
+
dispatch((0, product_1.setProductId)(productId));
|
|
252
341
|
dispatch((0, wishlist_1.refreshWishlist)());
|
|
253
342
|
return [2 /*return*/];
|
|
254
343
|
}
|
|
@@ -256,4 +345,77 @@ var launch = function (launchConfig) {
|
|
|
256
345
|
}); };
|
|
257
346
|
};
|
|
258
347
|
exports.launch = launch;
|
|
348
|
+
var unloadPlayer = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
349
|
+
return __generator(this, function (_a) {
|
|
350
|
+
switch (_a.label) {
|
|
351
|
+
case 0:
|
|
352
|
+
dispatch((0, exports.setThreekitInitialized)(true));
|
|
353
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
354
|
+
dispatch((0, attributes_1.setAttributes)([]));
|
|
355
|
+
dispatch((0, product_1.setName)(''));
|
|
356
|
+
dispatch((0, product_1.setMetadata)({}));
|
|
357
|
+
return [4 /*yield*/, window.threekit.player.unload()];
|
|
358
|
+
case 1:
|
|
359
|
+
_a.sent();
|
|
360
|
+
return [2 /*return*/];
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}); }; };
|
|
364
|
+
exports.unloadPlayer = unloadPlayer;
|
|
365
|
+
var reloadPlayer = function (config) {
|
|
366
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
367
|
+
var connectionObj, assetId, stageId, initialConfiguration, configuration, state, trebleConfig, playerConfig, el;
|
|
368
|
+
return __generator(this, function (_a) {
|
|
369
|
+
switch (_a.label) {
|
|
370
|
+
case 0:
|
|
371
|
+
connectionObj = connection_1.default.getConnection();
|
|
372
|
+
if (!(config === undefined)) return [3 /*break*/, 1];
|
|
373
|
+
assetId = connectionObj.assetId;
|
|
374
|
+
return [3 /*break*/, 4];
|
|
375
|
+
case 1:
|
|
376
|
+
if (!(typeof config === 'string')) return [3 /*break*/, 2];
|
|
377
|
+
assetId = config;
|
|
378
|
+
return [3 /*break*/, 4];
|
|
379
|
+
case 2:
|
|
380
|
+
assetId = (config === null || config === void 0 ? void 0 : config.assetId) || connectionObj.assetId;
|
|
381
|
+
stageId = config === null || config === void 0 ? void 0 : config.stageId;
|
|
382
|
+
initialConfiguration = (config === null || config === void 0 ? void 0 : config.configuration) || {};
|
|
383
|
+
if (!(config === null || config === void 0 ? void 0 : config.configurationId)) return [3 /*break*/, 4];
|
|
384
|
+
return [4 /*yield*/, api_1.default.configurations.fetch(config === null || config === void 0 ? void 0 : config.configurationId)];
|
|
385
|
+
case 3:
|
|
386
|
+
configuration = _a.sent();
|
|
387
|
+
if (configuration) {
|
|
388
|
+
initialConfiguration = Object.assign({}, initialConfiguration, configuration.data.variant);
|
|
389
|
+
assetId = configuration.data.productId;
|
|
390
|
+
}
|
|
391
|
+
_a.label = 4;
|
|
392
|
+
case 4:
|
|
393
|
+
// Update connection
|
|
394
|
+
if (assetId !== connectionObj.assetId)
|
|
395
|
+
connection_1.default.connect({ assetId: assetId });
|
|
396
|
+
state = getState();
|
|
397
|
+
trebleConfig = (0, utils_1.loadTrebleConfig)();
|
|
398
|
+
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, trebleConfig.player);
|
|
399
|
+
el = document.getElementById(state.treble.playerElId);
|
|
400
|
+
if (state.treble.isThreekitInitialized)
|
|
401
|
+
dispatch((0, exports.unloadPlayer)());
|
|
402
|
+
return [4 /*yield*/, dispatch((0, exports.initPlayer)({
|
|
403
|
+
el: el,
|
|
404
|
+
orgId: connectionObj.orgId,
|
|
405
|
+
authToken: connectionObj.authToken,
|
|
406
|
+
stageId: stageId,
|
|
407
|
+
assetId: assetId,
|
|
408
|
+
playerConfig: playerConfig,
|
|
409
|
+
initialConfiguration: initialConfiguration,
|
|
410
|
+
}))];
|
|
411
|
+
case 5:
|
|
412
|
+
_a.sent();
|
|
413
|
+
dispatch((0, price_1.updatePrice)());
|
|
414
|
+
dispatch((0, product_1.initProduct)());
|
|
415
|
+
return [2 /*return*/];
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}); };
|
|
419
|
+
};
|
|
420
|
+
exports.reloadPlayer = reloadPlayer;
|
|
259
421
|
exports.default = reducer;
|
package/dist/threekit.d.ts
CHANGED
|
@@ -84,6 +84,11 @@ export interface IDisplayAttributeAssetValue extends IConfigurationAssetValue {
|
|
|
84
84
|
tags: Array<string>;
|
|
85
85
|
label: string;
|
|
86
86
|
}
|
|
87
|
+
export interface IHydratedAttributeAssetValue extends IDisplayAttributeAssetValue {
|
|
88
|
+
label: string;
|
|
89
|
+
handleSelect: () => Promise<void>;
|
|
90
|
+
selected: boolean;
|
|
91
|
+
}
|
|
87
92
|
export interface IAttributeAssetBase<V> extends IAttributeBase<'Asset', IConfigurationAsset> {
|
|
88
93
|
assetType: AssetType;
|
|
89
94
|
blacklist: [];
|
|
@@ -93,12 +98,17 @@ export interface IAttributeAssetBase<V> extends IAttributeBase<'Asset', IConfigu
|
|
|
93
98
|
values: Array<V>;
|
|
94
99
|
}
|
|
95
100
|
export declare type IDisplayAttributeAsset = IAttributeAssetBase<IDisplayAttributeAssetValue>;
|
|
101
|
+
export declare type IHydratedAttributeAsset = IAttributeAssetBase<IHydratedAttributeAssetValue>;
|
|
96
102
|
export declare type IAttributeAsset = IAttributeAssetBase<IConfigurationAssetValue>;
|
|
97
103
|
/****** String TYPE ATTRIBUTE *******/
|
|
98
104
|
export interface IDisplayAttributeStringValue {
|
|
99
105
|
label: string;
|
|
100
106
|
value: string;
|
|
101
107
|
}
|
|
108
|
+
export interface IHydratedAttributeStringValue extends IDisplayAttributeStringValue {
|
|
109
|
+
handleSelect: () => Promise<void>;
|
|
110
|
+
selected: boolean;
|
|
111
|
+
}
|
|
102
112
|
export interface IAttributeStringBase<V> extends IAttributeBase<'String', string> {
|
|
103
113
|
blacklist: [];
|
|
104
114
|
defaultValue: string;
|
|
@@ -107,6 +117,7 @@ export interface IAttributeStringBase<V> extends IAttributeBase<'String', string
|
|
|
107
117
|
values: Array<V>;
|
|
108
118
|
}
|
|
109
119
|
export declare type IDisplayAttributeString = IAttributeStringBase<IDisplayAttributeStringValue>;
|
|
120
|
+
export declare type IHydratedAttributeString = IAttributeStringBase<IHydratedAttributeStringValue>;
|
|
110
121
|
export declare type IAttributeString = IAttributeStringBase<string>;
|
|
111
122
|
/****** STRING TYPE ATTRIBUTE *******/
|
|
112
123
|
export interface IAttributeColor extends IAttributeBase<'Color', IConfigurationColor> {
|
|
@@ -123,7 +134,9 @@ export interface IAttributeNumber extends IAttributeBase<'Number', number> {
|
|
|
123
134
|
/****** getAttributes() *******/
|
|
124
135
|
export declare type IThreekitAttribute = IAttributeAsset | IAttributeColor | IAttributeString | IAttributeNumber;
|
|
125
136
|
/****** getDisplayAttributes() *******/
|
|
126
|
-
export declare type IThreekitDisplayAttribute = IDisplayAttributeAsset |
|
|
137
|
+
export declare type IThreekitDisplayAttribute = IDisplayAttributeAsset | IDisplayAttributeString | IAttributeColor | IAttributeNumber;
|
|
138
|
+
/****** Treble Hydrated Values *******/
|
|
139
|
+
export declare type IHydratedAttribute = IHydratedAttributeAsset | IHydratedAttributeString | IAttributeColor | IAttributeNumber;
|
|
127
140
|
/***************************************************
|
|
128
141
|
* Camera
|
|
129
142
|
**************************************************/
|
|
@@ -195,6 +208,7 @@ export interface IThreekitPlayer {
|
|
|
195
208
|
getConfigurator: () => Promise<IThreekitConfigurator>;
|
|
196
209
|
enableApi: (api: PRIVATE_APIS) => any;
|
|
197
210
|
snapshotAsync: (snapshotConfig: ISnapshotConfig) => Promise<string>;
|
|
211
|
+
unload: () => Promise<string>;
|
|
198
212
|
}
|
|
199
213
|
export interface IThreekitPrivateConfigurator extends IThreekitConfigurator {
|
|
200
214
|
getAppliedConfiguration: (attributeName: string) => string;
|
|
@@ -262,6 +276,7 @@ export interface IProducts extends Record<string, string | Partial<IProduct>> {
|
|
|
262
276
|
export interface IProject {
|
|
263
277
|
credentials: ICredentials;
|
|
264
278
|
products: IProducts;
|
|
279
|
+
serverUrl?: string;
|
|
265
280
|
}
|
|
266
281
|
export interface ITrebleConfig {
|
|
267
282
|
project: IProject;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute } from './threekit';
|
|
1
|
+
import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute, ISetConfiguration, IHydratedAttribute } from './threekit';
|
|
3
2
|
import { ITrebleConfig, IAttributeTypes } from './threekit';
|
|
4
3
|
import { RawAttributeValue } from './hooks/useAttribute';
|
|
4
|
+
import { ITranslationMap } from './api/products';
|
|
5
5
|
interface ICameraPosition {
|
|
6
6
|
position: ICoordinates;
|
|
7
7
|
quaternion: IQuaternion;
|
|
@@ -47,14 +47,11 @@ export declare const downloadSnapshot: (snapshot: string, filename: string) => P
|
|
|
47
47
|
export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
|
|
48
48
|
export declare const easeInOutCubic: (val: number) => number;
|
|
49
49
|
export declare const metadataValueToObject: (data: string) => Record<string, string | number>;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*/
|
|
56
|
-
export declare const createThreekitScriptEl: (threekitDomain: string) => Promise<void>;
|
|
57
|
-
export declare const translateAttribute: (attributes: Array<IThreekitDisplayAttribute>, translations?: ITranslationMap | undefined, language?: string | undefined) => IThreekitDisplayAttribute;
|
|
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>;
|
|
58
55
|
export declare const selectionToConfiguration: (value: RawAttributeValue, attributeType: IAttributeTypes) => string | number | boolean | File | IConfigurationColor | {
|
|
59
56
|
assetId: RawAttributeValue;
|
|
60
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.
|
|
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,25 +309,10 @@ var metadataValueToObject = function (data) {
|
|
|
309
309
|
}, {});
|
|
310
310
|
};
|
|
311
311
|
exports.metadataValueToObject = metadataValueToObject;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
*
|
|
315
|
-
* @param threekitDomain The threekit environement to use. i.e. preview.threekit.com
|
|
316
|
-
* @returns
|
|
317
|
-
*/
|
|
318
|
-
var createThreekitScriptEl = function (threekitDomain) {
|
|
319
|
-
return new Promise(function (resolve) {
|
|
320
|
-
var script = document.createElement('script');
|
|
321
|
-
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
322
|
-
script.id = 'threekit-player-bundle';
|
|
323
|
-
script.onload = function () { return resolve(); };
|
|
324
|
-
document.head.appendChild(script);
|
|
325
|
-
});
|
|
326
|
-
};
|
|
327
|
-
exports.createThreekitScriptEl = createThreekitScriptEl;
|
|
328
|
-
var translateAttribute = function (attributes, translations, language) {
|
|
312
|
+
var hydrateAttribute = function (data, optionSelectionHandler) {
|
|
313
|
+
var attributes = data[0], translations = data[1], language = data[2];
|
|
329
314
|
var hasTranslation = !!language && !!translations;
|
|
330
|
-
return attributes.reduce(function (output, attribute) {
|
|
315
|
+
return Object.values(attributes).reduce(function (output, attribute) {
|
|
331
316
|
var _a;
|
|
332
317
|
var _b;
|
|
333
318
|
return Object.assign(output, (_a = {},
|
|
@@ -342,7 +327,14 @@ var translateAttribute = function (attributes, translations, language) {
|
|
|
342
327
|
return Object.assign({}, el, {
|
|
343
328
|
label: hasTranslation
|
|
344
329
|
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
|
|
345
|
-
:
|
|
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,
|
|
346
338
|
});
|
|
347
339
|
}),
|
|
348
340
|
}
|
|
@@ -353,15 +345,22 @@ var translateAttribute = function (attributes, translations, language) {
|
|
|
353
345
|
return Object.assign({}, el, {
|
|
354
346
|
label: hasTranslation
|
|
355
347
|
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
|
|
356
|
-
:
|
|
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,
|
|
357
356
|
});
|
|
358
357
|
}),
|
|
359
358
|
}
|
|
360
359
|
: undefined),
|
|
361
360
|
_a));
|
|
362
|
-
});
|
|
361
|
+
}, {});
|
|
363
362
|
};
|
|
364
|
-
exports.
|
|
363
|
+
exports.hydrateAttribute = hydrateAttribute;
|
|
365
364
|
var selectionToConfiguration = function (value, attributeType) {
|
|
366
365
|
switch (attributeType) {
|
|
367
366
|
case constants_1.ATTRIBUTE_TYPES.number:
|
package/package.json
CHANGED