@threekit-tools/treble 0.0.96 → 0.0.97
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.
|
@@ -50,21 +50,18 @@ var App = function (props) {
|
|
|
50
50
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
51
51
|
var playerConfig = props.playerConfig, assetId = props.assetId, customId = props.customId, productId = props.productId, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv, eventHandlers = props.eventHandlers;
|
|
52
52
|
(0, react_1.useEffect)(function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}));
|
|
64
|
-
};
|
|
65
|
-
init();
|
|
53
|
+
dispatch((0, treble_1.launch)({
|
|
54
|
+
playerConfig: playerConfig,
|
|
55
|
+
productId: productId,
|
|
56
|
+
assetId: assetId,
|
|
57
|
+
customId: customId,
|
|
58
|
+
project: project,
|
|
59
|
+
locale: locale,
|
|
60
|
+
threekitEnv: threekitEnv,
|
|
61
|
+
eventHandlers: eventHandlers,
|
|
62
|
+
}));
|
|
66
63
|
return;
|
|
67
|
-
}, [props.project, props.threekitEnv, props.playerConfig]);
|
|
64
|
+
}, [assetId, props.project, props.threekitEnv, props.playerConfig]);
|
|
68
65
|
return react_1.default.createElement(react_1.default.Fragment, null, props.children);
|
|
69
66
|
};
|
|
70
67
|
var ThreekitProvider = function (props) {
|
package/dist/store/product.js
CHANGED
|
@@ -81,10 +81,7 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
81
81
|
return __assign(__assign({}, state), { id: action.payload });
|
|
82
82
|
});
|
|
83
83
|
builder.addCase(exports.setName, function (state, action) {
|
|
84
|
-
|
|
85
|
-
id: window.threekit.player.assetId,
|
|
86
|
-
}).name;
|
|
87
|
-
return __assign(__assign({}, state), { name: action.payload || name });
|
|
84
|
+
return __assign(__assign({}, state), { name: action.payload });
|
|
88
85
|
});
|
|
89
86
|
builder.addCase(exports.setMetadata, function (state, action) {
|
|
90
87
|
return __assign(__assign({}, state), { metadata: action.payload || window.threekit.configurator.getMetadata() });
|
package/dist/store/treble.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare const getPlayerElementId: (state: RootState) => undefined | strin
|
|
|
65
65
|
export declare const getLoadingProgress: (state: RootState) => undefined | number;
|
|
66
66
|
export declare const getPlayerInteraction: (state: RootState) => undefined | boolean;
|
|
67
67
|
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
68
|
-
export declare const launch: (launchConfig
|
|
69
|
-
export declare const unloadPlayer: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
68
|
+
export declare const launch: (launchConfig: Partial<ILaunchConfig>) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
69
|
+
export declare const unloadPlayer: (playerEl?: HTMLElement) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
70
70
|
export declare const reloadPlayer: (config: undefined | string | Pick<IReloadConfig, 'assetId' | 'stageId' | 'configurationId' | 'configuration'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
71
71
|
export default reducer;
|
package/dist/store/treble.js
CHANGED
|
@@ -175,6 +175,8 @@ var initPlayer = function (config) {
|
|
|
175
175
|
dispatch((0, exports.updateLoadingProgress)(0));
|
|
176
176
|
return [4, window.threekitPlayer(__assign(__assign({ el: el, authToken: authToken, stageId: stageId, assetId: assetId, customId: customId }, playerConfig), { initialConfiguration: initialConfiguration, onLoadingProgress: function (progress) {
|
|
177
177
|
var _a;
|
|
178
|
+
if (progress > 0)
|
|
179
|
+
el.style.visibility = 'visible';
|
|
178
180
|
dispatch((0, exports.updateLoadingProgress)(progress));
|
|
179
181
|
(_a = playerConfig === null || playerConfig === void 0 ? void 0 : playerConfig.onLoadingProgress) === null || _a === void 0 ? void 0 : _a.call(playerConfig, progress);
|
|
180
182
|
} }))];
|
|
@@ -263,17 +265,24 @@ var initPlayer = function (config) {
|
|
|
263
265
|
exports.initPlayer = initPlayer;
|
|
264
266
|
var launch = function (launchConfig) {
|
|
265
267
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
-
var config, productId, credentials, productsRaw, products, threekitEnv, serverUrl, playerConfig, envCredentials, _a, assetIdRaw, customIdRaw, stageId, configurationId, initialConfigurationRaw, customId, assetId, threekitDomainRaw, authToken, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
267
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
268
|
-
return __generator(this, function (
|
|
269
|
-
switch (
|
|
268
|
+
var config, playerElId, productId, credentials, productsRaw, products, threekitEnv, serverUrl, playerConfig, envCredentials, _a, assetIdRaw, customIdRaw, stageId, configurationId, initialConfigurationRaw, customId, assetId, threekitDomainRaw, authToken, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
269
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
270
|
+
return __generator(this, function (_q) {
|
|
271
|
+
switch (_q.label) {
|
|
270
272
|
case 0:
|
|
271
|
-
if (window.threekit)
|
|
272
|
-
return [2];
|
|
273
273
|
config = (0, utils_1.loadTrebleConfig)();
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
if (!window.threekit) return [3, 2];
|
|
275
|
+
if (launchConfig.assetId === window.threekit.player.assetId)
|
|
276
|
+
return [2];
|
|
277
|
+
playerElId = (_e = (_c = (_b = config === null || config === void 0 ? void 0 : config.player) === null || _b === void 0 ? void 0 : _b.elementId) !== null && _c !== void 0 ? _c : (_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig) === null || _d === void 0 ? void 0 : _d.elementId) !== null && _e !== void 0 ? _e : constants_1.TK_PLAYER_ROOT_DIV;
|
|
278
|
+
return [4, dispatch((0, exports.unloadPlayer)((_f = document.getElementById(playerElId)) !== null && _f !== void 0 ? _f : undefined))];
|
|
279
|
+
case 1:
|
|
280
|
+
_q.sent();
|
|
281
|
+
_q.label = 2;
|
|
282
|
+
case 2:
|
|
283
|
+
credentials = ((_g = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _g === void 0 ? void 0 : _g.credentials) || ((_h = config.project) === null || _h === void 0 ? void 0 : _h.credentials) || {};
|
|
284
|
+
productsRaw = ((_j = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _j === void 0 ? void 0 : _j.products) || ((_k = config.project) === null || _k === void 0 ? void 0 : _k.products) || {};
|
|
285
|
+
if (!((_l = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.productId) === null || _l === void 0 ? void 0 : _l.length)) {
|
|
277
286
|
productsRaw = { default: productsRaw };
|
|
278
287
|
productId = 'default';
|
|
279
288
|
}
|
|
@@ -325,12 +334,12 @@ var launch = function (launchConfig) {
|
|
|
325
334
|
(0, product_1.setProducts)(products);
|
|
326
335
|
dispatch((0, product_1.setProductId)(productId));
|
|
327
336
|
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
328
|
-
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((
|
|
337
|
+
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((_m = config === null || config === void 0 ? void 0 : config.project) === null || _m === void 0 ? void 0 : _m.serverUrl);
|
|
329
338
|
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
330
339
|
envCredentials = credentials[threekitEnv];
|
|
331
340
|
_a = products[productId][threekitEnv] || {}, assetIdRaw = _a.assetId, customIdRaw = _a.customId, stageId = _a.stageId, configurationId = _a.configurationId, initialConfigurationRaw = _a.initialConfiguration;
|
|
332
341
|
customId = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.customId) || customIdRaw;
|
|
333
|
-
assetId = ((
|
|
342
|
+
assetId = ((_o = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.customId) === null || _o === void 0 ? void 0 : _o.length)
|
|
334
343
|
? undefined
|
|
335
344
|
: (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.assetId) || assetIdRaw;
|
|
336
345
|
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
@@ -355,22 +364,23 @@ var launch = function (launchConfig) {
|
|
|
355
364
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
356
365
|
updatedAssetId = assetId;
|
|
357
366
|
params = (0, utils_1.getParams)();
|
|
358
|
-
configId = ((
|
|
367
|
+
configId = ((_p = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _p === void 0 ? void 0 : _p.length)
|
|
359
368
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
360
369
|
: configurationId;
|
|
361
|
-
if (!configId) return [3,
|
|
370
|
+
if (!configId) return [3, 4];
|
|
362
371
|
return [4, api_1.default.configurations.fetch(configId)];
|
|
363
|
-
case
|
|
364
|
-
configuration =
|
|
372
|
+
case 3:
|
|
373
|
+
configuration = _q.sent();
|
|
365
374
|
if (configuration) {
|
|
366
375
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
367
376
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
368
377
|
updatedAssetId = configuration.data.productId;
|
|
369
378
|
}
|
|
370
|
-
|
|
371
|
-
case
|
|
379
|
+
_q.label = 4;
|
|
380
|
+
case 4:
|
|
372
381
|
if (!updatedAssetId && !customId)
|
|
373
382
|
throw new Error('missing assetId and customId');
|
|
383
|
+
if (!!window.threekitPlayer) return [3, 6];
|
|
374
384
|
return [4, new Promise(function (resolve) {
|
|
375
385
|
var script = document.createElement('script');
|
|
376
386
|
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
@@ -378,24 +388,27 @@ var launch = function (launchConfig) {
|
|
|
378
388
|
script.onload = function () { return resolve(); };
|
|
379
389
|
document.head.appendChild(script);
|
|
380
390
|
})];
|
|
381
|
-
case
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
case 5:
|
|
392
|
+
_q.sent();
|
|
393
|
+
_q.label = 6;
|
|
394
|
+
case 6: return [4, dispatch((0, exports.initPlayer)({
|
|
395
|
+
el: el,
|
|
396
|
+
authToken: authToken,
|
|
397
|
+
stageId: stageId,
|
|
398
|
+
assetId: updatedAssetId,
|
|
399
|
+
customId: customId,
|
|
400
|
+
playerConfig: playerConfig,
|
|
401
|
+
initialConfiguration: initialConfiguration,
|
|
402
|
+
}))];
|
|
403
|
+
case 7:
|
|
404
|
+
_q.sent();
|
|
394
405
|
document.addEventListener('treble:notification', function (e) {
|
|
395
406
|
message_1.default.info(e.detail.message);
|
|
396
407
|
});
|
|
397
408
|
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
398
|
-
dispatch((0, product_1.setName)(
|
|
409
|
+
dispatch((0, product_1.setName)(window.threekit.player.scene.get({
|
|
410
|
+
id: window.threekit.player.assetId,
|
|
411
|
+
}).name));
|
|
399
412
|
dispatch((0, product_1.setMetadata)());
|
|
400
413
|
dispatch((0, product_1.initProduct)());
|
|
401
414
|
dispatch((0, exports.setThreekitEnv)(threekitEnv));
|
|
@@ -409,7 +422,7 @@ var launch = function (launchConfig) {
|
|
|
409
422
|
}); };
|
|
410
423
|
};
|
|
411
424
|
exports.launch = launch;
|
|
412
|
-
var unloadPlayer = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
425
|
+
var unloadPlayer = function (playerEl) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
413
426
|
return __generator(this, function (_a) {
|
|
414
427
|
switch (_a.label) {
|
|
415
428
|
case 0:
|
|
@@ -421,6 +434,8 @@ var unloadPlayer = function () { return function (dispatch) { return __awaiter(v
|
|
|
421
434
|
return [4, window.threekit.player.unload()];
|
|
422
435
|
case 1:
|
|
423
436
|
_a.sent();
|
|
437
|
+
if (playerEl)
|
|
438
|
+
playerEl.style.visibility = 'hidden';
|
|
424
439
|
return [2];
|
|
425
440
|
}
|
|
426
441
|
});
|