@threekit-tools/treble 0.0.60 → 0.0.63

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.
Files changed (39) hide show
  1. package/dist/Treble/Treble.d.ts +2 -2
  2. package/dist/Treble/Treble.js +7 -2
  3. package/dist/components/Switch/index.d.ts +66 -0
  4. package/dist/components/Switch/index.js +86 -0
  5. package/dist/components/Switch/switch.styles.d.ts +4 -0
  6. package/dist/components/Switch/switch.styles.js +16 -0
  7. package/dist/components/TextInput/index.js +2 -0
  8. package/dist/components/ThreekitProvider/index.d.ts +1 -0
  9. package/dist/components/ThreekitProvider/index.js +10 -3
  10. package/dist/components/TrebleApp/index.d.ts +1 -0
  11. package/dist/components/TrebleApp/index.js +16 -6
  12. package/dist/components/Upload/index.js +5 -4
  13. package/dist/components/UploadArea/index.js +4 -3
  14. package/dist/components/Wishlist/index.js +6 -11
  15. package/dist/components/containers/formInputContainer.d.ts +4 -4
  16. package/dist/components/containers/formInputContainer.js +4 -4
  17. package/dist/components/formComponents.js +5 -1
  18. package/dist/hooks/useAttribute/index.js +5 -2
  19. package/dist/hooks/useConfigurator/index.js +7 -3
  20. package/dist/hooks/useNestedConfigurator/index.d.ts +8 -0
  21. package/dist/hooks/useNestedConfigurator/index.js +93 -0
  22. package/dist/hooks/useProductCache/index.d.ts +13 -5
  23. package/dist/hooks/useProductCache/index.js +16 -23
  24. package/dist/hooks/useWishlist/index.d.ts +8 -6
  25. package/dist/hooks/useWishlist/index.js +16 -22
  26. package/dist/index.d.ts +4 -1
  27. package/dist/index.js +7 -2
  28. package/dist/store/attributes.d.ts +3 -3
  29. package/dist/store/attributes.js +3 -50
  30. package/dist/store/product.d.ts +22 -13
  31. package/dist/store/product.js +98 -54
  32. package/dist/store/translations.d.ts +4 -3
  33. package/dist/store/translations.js +4 -14
  34. package/dist/store/treble.d.ts +4 -0
  35. package/dist/store/treble.js +69 -30
  36. package/dist/threekit.d.ts +9 -5
  37. package/dist/utils.d.ts +7 -1
  38. package/dist/utils.js +53 -1
  39. package/package.json +1 -1
@@ -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.removeProductIdx = exports.changeActiveProductIdx = exports.loadNewProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveProductIdx = exports.getMetadata = exports.getName = exports.decrementActiveProductIdx = exports.incrementActiveProductIdx = exports.setActiveProductIdx = exports.removeProductFromCache = exports.updateActiveProductCache = exports.addProductToCache = exports.setMetadata = exports.setName = exports.PRODUCTS = void 0;
53
+ exports.removeProductIdx = exports.changeActiveCacheIdx = exports.loadNewProduct = exports.loadProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveCacheIdx = exports.getMetadata = exports.getName = exports.getProductId = exports.decrementActiveCacheIdx = exports.incrementActiveCacheIdx = exports.setActiveCacheIdx = exports.removeFromCache = exports.updateActiveProductCache = exports.appendToCache = exports.setMetadata = exports.setName = exports.setProductId = exports.PRODUCTS = void 0;
54
54
  var toolkit_1 = require("@reduxjs/toolkit");
55
55
  var connection_1 = __importDefault(require("../connection"));
56
56
  var treble_1 = require("./treble");
@@ -58,62 +58,68 @@ var treble_1 = require("./treble");
58
58
  * Actions
59
59
  ****************************************************/
60
60
  // Actions to be used only internally
61
- exports.setName = (0, toolkit_1.createAction)('treble/product/set-name');
62
- exports.setMetadata = (0, toolkit_1.createAction)('treble/product/set-metadata');
63
- exports.addProductToCache = (0, toolkit_1.createAction)('treble/add-product-to-cache');
61
+ exports.setProductId = (0, toolkit_1.createAction)('treble/set-product-id');
62
+ exports.setName = (0, toolkit_1.createAction)('treble/set-product-name');
63
+ exports.setMetadata = (0, toolkit_1.createAction)('treble/set-metadata');
64
+ exports.appendToCache = (0, toolkit_1.createAction)('treble/append-to-cache');
64
65
  exports.updateActiveProductCache = (0, toolkit_1.createAction)('treble/update-active-product-cache');
65
- exports.removeProductFromCache = (0, toolkit_1.createAction)('treble/remove-product-from-cache');
66
- exports.setActiveProductIdx = (0, toolkit_1.createAction)('treble/set-active-product-idx');
67
- exports.incrementActiveProductIdx = (0, toolkit_1.createAction)('treble/increment-active-product-idx');
68
- exports.decrementActiveProductIdx = (0, toolkit_1.createAction)('treble/decrement-active-product-idx');
66
+ exports.removeFromCache = (0, toolkit_1.createAction)('treble/remove-from-cache');
67
+ exports.setActiveCacheIdx = (0, toolkit_1.createAction)('treble/set-active-cache-idx');
68
+ exports.incrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/increment-active-cache-idx');
69
+ exports.decrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/decrement-active-cache-idx');
69
70
  /*****************************************************
70
71
  * State
71
72
  ****************************************************/
72
73
  var initialState = {
74
+ // ID of initialized item
75
+ id: undefined,
73
76
  // Name of the Initialized Item
74
77
  name: undefined,
75
78
  // Initialized item's metadata
76
79
  metadata: undefined,
77
80
  // cached products. Does not include the active product
78
- cachedProducts: [],
79
- activeProductIdx: 0,
81
+ cache: [],
82
+ activeCacheIdx: 0,
80
83
  };
81
84
  var reducer = (0, toolkit_1.createSlice)({
82
85
  name: 'product',
83
86
  initialState: initialState,
84
87
  extraReducers: function (builder) {
88
+ builder.addCase(exports.setProductId, function (state, action) {
89
+ return __assign(__assign({}, state), { id: action.payload });
90
+ });
85
91
  builder.addCase(exports.setName, function (state, action) {
86
92
  return __assign(__assign({}, state), { name: action.payload });
87
93
  });
88
94
  builder.addCase(exports.setMetadata, function (state, action) {
89
95
  return __assign(__assign({}, state), { metadata: action.payload });
90
96
  });
91
- builder.addCase(exports.addProductToCache, function (state, action) {
92
- state.cachedProducts.push(action.payload);
97
+ builder.addCase(exports.appendToCache, function (state, action) {
98
+ state.cache.push(action.payload);
93
99
  return state;
94
100
  });
95
- builder.addCase(exports.removeProductFromCache, function (state, action) {
96
- state.cachedProducts.splice(action.payload, 1);
101
+ builder.addCase(exports.removeFromCache, function (state, action) {
102
+ state.cache.splice(action.payload, 1);
97
103
  return state;
98
104
  });
99
105
  builder.addCase(exports.updateActiveProductCache, function (state, action) {
100
- state.cachedProducts[state.activeProductIdx] = Object.assign({}, state.cachedProducts[state.activeProductIdx], action.payload);
106
+ state.cache[state.activeCacheIdx] = Object.assign({}, state.cache[state.activeCacheIdx], action.payload);
101
107
  return state;
102
108
  });
103
- builder.addCase(exports.setActiveProductIdx, function (state, action) {
104
- state.activeProductIdx = action.payload;
109
+ builder.addCase(exports.setActiveCacheIdx, function (state, action) {
110
+ state.activeCacheIdx = action.payload;
105
111
  return state;
106
112
  });
107
- builder.addCase(exports.incrementActiveProductIdx, function (state) {
108
- state.activeProductIdx =
109
- state.activeProductIdx >= state.cachedProducts.length
110
- ? state.activeProductIdx
111
- : state.activeProductIdx + 1;
113
+ builder.addCase(exports.incrementActiveCacheIdx, function (state) {
114
+ state.activeCacheIdx =
115
+ state.activeCacheIdx >= state.cache.length
116
+ ? state.activeCacheIdx
117
+ : state.activeCacheIdx + 1;
112
118
  return state;
113
119
  });
114
- builder.addCase(exports.decrementActiveProductIdx, function (state) {
115
- state.activeProductIdx =
116
- state.activeProductIdx === 0 ? 0 : state.activeProductIdx - 1;
120
+ builder.addCase(exports.decrementActiveCacheIdx, function (state) {
121
+ state.activeCacheIdx =
122
+ state.activeCacheIdx === 0 ? 0 : state.activeCacheIdx - 1;
117
123
  return state;
118
124
  });
119
125
  },
@@ -122,6 +128,10 @@ var reducer = (0, toolkit_1.createSlice)({
122
128
  /*****************************************************
123
129
  * Standard Selectors
124
130
  ****************************************************/
131
+ var getProductId = function (state) {
132
+ return state.product.id;
133
+ };
134
+ exports.getProductId = getProductId;
125
135
  var getName = function (state) {
126
136
  return state.product.name;
127
137
  };
@@ -132,12 +142,12 @@ var getMetadata = function (state) {
132
142
  };
133
143
  exports.getMetadata = getMetadata;
134
144
  // Product Cache
135
- var getActiveProductIdx = function (state) {
136
- return state.product.activeProductIdx;
145
+ var getActiveCacheIdx = function (state) {
146
+ return state.product.activeCacheIdx;
137
147
  };
138
- exports.getActiveProductIdx = getActiveProductIdx;
148
+ exports.getActiveCacheIdx = getActiveCacheIdx;
139
149
  var getProductCache = function (state) {
140
- return state.product.cachedProducts.map(function (prod) {
150
+ return state.product.cache.map(function (prod) {
141
151
  return Object.assign({
142
152
  name: prod.name,
143
153
  }, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
@@ -158,8 +168,8 @@ var initProduct = function (prods) {
158
168
  var metadata = window.threekit.configurator.getMetadata();
159
169
  dispatch((0, exports.setName)(name));
160
170
  dispatch((0, exports.setMetadata)(metadata));
161
- if (!state.product.cachedProducts.length) {
162
- dispatch((0, exports.setActiveProductIdx)(0));
171
+ if (!state.product.cache.length) {
172
+ dispatch((0, exports.setActiveCacheIdx)(0));
163
173
  dispatch((0, exports.cacheActiveProduct)());
164
174
  }
165
175
  };
@@ -174,11 +184,43 @@ var cacheActiveProduct = function (config) {
174
184
  delete connectionObj.threekitDomain;
175
185
  var configuration = window.threekit.configurator.getConfiguration();
176
186
  var data = { connection: connectionObj, configuration: configuration };
177
- var product = Object.assign({ name: state.product.name, data: JSON.stringify(data) }, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
187
+ var product = Object.assign({
188
+ id: state.product.id,
189
+ name: state.product.name,
190
+ data: JSON.stringify(data),
191
+ }, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
178
192
  return dispatch((0, exports.updateActiveProductCache)(product));
179
193
  };
180
194
  };
181
195
  exports.cacheActiveProduct = cacheActiveProduct;
196
+ var loadProduct = function (id) {
197
+ return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
198
+ var state, productsList, shouldCacheProduct, productConfig;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ state = getState();
203
+ productsList = Object.keys(exports.PRODUCTS);
204
+ shouldCacheProduct = true;
205
+ if (!productsList.includes(id))
206
+ return [2 /*return*/];
207
+ productConfig = exports.PRODUCTS[id][state.treble.threekitEnv];
208
+ dispatch((0, exports.setProductId)(id));
209
+ if (shouldCacheProduct)
210
+ dispatch((0, exports.cacheActiveProduct)());
211
+ return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(productConfig))];
212
+ case 1:
213
+ _a.sent();
214
+ if (shouldCacheProduct) {
215
+ dispatch((0, exports.incrementActiveCacheIdx)());
216
+ dispatch((0, exports.cacheActiveProduct)());
217
+ }
218
+ return [2 /*return*/];
219
+ }
220
+ });
221
+ }); };
222
+ };
223
+ exports.loadProduct = loadProduct;
182
224
  var loadNewProduct = function (config) {
183
225
  return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
184
226
  var label, thumbnail, shouldCacheProduct;
@@ -194,11 +236,12 @@ var loadNewProduct = function (config) {
194
236
  }
195
237
  if (shouldCacheProduct)
196
238
  dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
239
+ dispatch((0, exports.setProductId)(undefined));
197
240
  return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(config))];
198
241
  case 1:
199
242
  _a.sent();
200
243
  if (shouldCacheProduct) {
201
- dispatch((0, exports.incrementActiveProductIdx)());
244
+ dispatch((0, exports.incrementActiveCacheIdx)());
202
245
  dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
203
246
  }
204
247
  return [2 /*return*/];
@@ -207,21 +250,22 @@ var loadNewProduct = function (config) {
207
250
  }); };
208
251
  };
209
252
  exports.loadNewProduct = loadNewProduct;
210
- var changeActiveProductIdx = function (idx) {
253
+ var changeActiveCacheIdx = function (idx) {
211
254
  return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
212
- var state, cachedProducts, cachedProduct, data;
255
+ var state, cache, cachedProduct, data;
213
256
  return __generator(this, function (_a) {
214
257
  switch (_a.label) {
215
258
  case 0:
216
259
  state = getState();
217
- cachedProducts = state.product.cachedProducts;
218
- if (idx >= cachedProducts.length)
260
+ cache = state.product.cache;
261
+ if (idx >= cache.length)
219
262
  return [2 /*return*/, Promise.resolve()];
220
263
  dispatch((0, exports.cacheActiveProduct)());
221
- cachedProduct = __assign({}, state.product.cachedProducts[idx]);
264
+ cachedProduct = __assign({}, state.product.cache[idx]);
222
265
  data = JSON.parse(cachedProduct.data);
223
266
  connection_1.default.connect(data.connection);
224
- dispatch((0, exports.setActiveProductIdx)(idx));
267
+ dispatch((0, exports.setActiveCacheIdx)(idx));
268
+ dispatch((0, exports.setProductId)(cachedProduct.id));
225
269
  return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)({
226
270
  assetId: data.connection.assetId,
227
271
  configuration: data.configuration,
@@ -233,38 +277,38 @@ var changeActiveProductIdx = function (idx) {
233
277
  });
234
278
  }); };
235
279
  };
236
- exports.changeActiveProductIdx = changeActiveProductIdx;
280
+ exports.changeActiveCacheIdx = changeActiveCacheIdx;
237
281
  var removeProductIdx = function (idx) {
238
282
  return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
239
- var state, _a, cachedProducts, activeProductIdx;
283
+ var state, _a, cache, activeCacheIdx;
240
284
  return __generator(this, function (_b) {
241
285
  switch (_b.label) {
242
286
  case 0:
243
287
  state = getState();
244
- _a = state.product, cachedProducts = _a.cachedProducts, activeProductIdx = _a.activeProductIdx;
245
- if (cachedProducts.length <= 1)
288
+ _a = state.product, cache = _a.cache, activeCacheIdx = _a.activeCacheIdx;
289
+ if (cache.length <= 1)
246
290
  return [2 /*return*/, Promise.resolve()];
247
- if (!(!idx || idx === activeProductIdx)) return [3 /*break*/, 5];
248
- if (!(activeProductIdx === state.product.cachedProducts.length - 1)) return [3 /*break*/, 2];
249
- return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx - 1))];
291
+ if (!(!idx || idx === activeCacheIdx)) return [3 /*break*/, 5];
292
+ if (!(activeCacheIdx === state.product.cache.length - 1)) return [3 /*break*/, 2];
293
+ return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx - 1))];
250
294
  case 1:
251
295
  _b.sent();
252
- dispatch((0, exports.removeProductFromCache)(activeProductIdx));
296
+ dispatch((0, exports.removeFromCache)(activeCacheIdx));
253
297
  return [3 /*break*/, 4];
254
298
  case 2:
255
- dispatch((0, exports.removeProductFromCache)(activeProductIdx));
256
- return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx))];
299
+ dispatch((0, exports.removeFromCache)(activeCacheIdx));
300
+ return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx))];
257
301
  case 3:
258
302
  _b.sent();
259
303
  _b.label = 4;
260
304
  case 4: return [3 /*break*/, 6];
261
305
  case 5:
262
- if (idx >= activeProductIdx) {
263
- dispatch((0, exports.removeProductFromCache)(idx));
306
+ if (idx >= activeCacheIdx) {
307
+ dispatch((0, exports.removeFromCache)(idx));
264
308
  }
265
- else if (idx <= activeProductIdx) {
266
- dispatch((0, exports.decrementActiveProductIdx)());
267
- dispatch((0, exports.removeProductFromCache)(idx));
309
+ else if (idx <= activeCacheIdx) {
310
+ dispatch((0, exports.decrementActiveCacheIdx)());
311
+ dispatch((0, exports.removeFromCache)(idx));
268
312
  }
269
313
  _b.label = 6;
270
314
  case 6: return [2 /*return*/, Promise.resolve()];
@@ -4,13 +4,15 @@ import { ITranslationMap } from '../api/products';
4
4
  * Types and Interfaces
5
5
  ****************************************************/
6
6
  export interface TranslationsState {
7
- translations: undefined | ITranslationMap;
8
7
  language: string | undefined;
9
8
  }
9
+ /*****************************************************
10
+ * Constants
11
+ ****************************************************/
12
+ export declare let TRANSLATIONS: undefined | ITranslationMap;
10
13
  /*****************************************************
11
14
  * Actions
12
15
  ****************************************************/
13
- export declare const setTranslations: import("@reduxjs/toolkit").ActionCreatorWithPayload<ITranslationMap, string>;
14
16
  export declare const setLanguage: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
15
17
  export declare const initTranslations: (language?: string | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
16
18
  declare const reducer: import("redux").Reducer<TranslationsState, import("redux").AnyAction>;
@@ -18,6 +20,5 @@ declare const reducer: import("redux").Reducer<TranslationsState, import("redux"
18
20
  * Standard Selectors
19
21
  ****************************************************/
20
22
  export declare const getLanguage: (state: RootState) => undefined | string;
21
- export declare const getTranslations: (state: RootState) => undefined | ITranslationMap;
22
23
  export declare const getLanguageOptions: (state: RootState) => Array<string>;
23
24
  export default reducer;
@@ -39,23 +39,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getLanguageOptions = exports.getTranslations = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
42
+ exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.TRANSLATIONS = void 0;
43
43
  var toolkit_1 = require("@reduxjs/toolkit");
44
44
  var api_1 = __importDefault(require("../api"));
45
45
  /*****************************************************
46
46
  * Actions
47
47
  ****************************************************/
48
- // Actions to be used only internally
49
- exports.setTranslations = (0, toolkit_1.createAction)('treble/translations/set-translations');
50
48
  exports.setLanguage = (0, toolkit_1.createAction)('treble/translations/set-language');
51
49
  var initTranslations = function (language) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
52
- var translations;
53
50
  return __generator(this, function (_a) {
54
51
  switch (_a.label) {
55
52
  case 0: return [4 /*yield*/, api_1.default.products.fetchTranslations()];
56
53
  case 1:
57
- translations = _a.sent();
58
- dispatch((0, exports.setTranslations)(translations));
54
+ exports.TRANSLATIONS = _a.sent();
59
55
  if (language)
60
56
  dispatch((0, exports.setLanguage)(language));
61
57
  return [2 /*return*/];
@@ -68,16 +64,12 @@ exports.initTranslations = initTranslations;
68
64
  ****************************************************/
69
65
  var initialState = {
70
66
  // Selected language
71
- translations: undefined,
72
67
  language: undefined,
73
68
  };
74
69
  var reducer = (0, toolkit_1.createSlice)({
75
70
  name: 'translations',
76
71
  initialState: initialState,
77
72
  extraReducers: function (builder) {
78
- builder.addCase(exports.setTranslations, function (state, action) {
79
- state.translations = action.payload;
80
- });
81
73
  builder.addCase(exports.setLanguage, function (state, action) {
82
74
  state.language = action.payload;
83
75
  });
@@ -91,12 +83,10 @@ var getLanguage = function (state) {
91
83
  return state.translations.language;
92
84
  };
93
85
  exports.getLanguage = getLanguage;
94
- var getTranslations = function (state) { return state.translations.translations; };
95
- exports.getTranslations = getTranslations;
96
86
  var getLanguageOptions = function (state) {
97
- if (!state.treble.isThreekitInitialized || !state.translations.translations)
87
+ if (!state.treble.isThreekitInitialized || !exports.TRANSLATIONS)
98
88
  return [];
99
- return Object.keys(Object.values(state.translations.translations)[0]);
89
+ return Object.keys(Object.values(exports.TRANSLATIONS)[0]);
100
90
  };
101
91
  exports.getLanguageOptions = getLanguageOptions;
102
92
  exports.default = reducer;
@@ -13,6 +13,7 @@ export interface IPlayerInit {
13
13
  initialConfiguration?: IConfiguration;
14
14
  }
15
15
  export interface ILaunchConfig {
16
+ productId: string;
16
17
  threekitEnv: string;
17
18
  serverUrl: string;
18
19
  locale: string;
@@ -30,6 +31,7 @@ export interface IReloadConfig {
30
31
  cacheProduct?: boolean;
31
32
  }
32
33
  export interface TrebleState {
34
+ threekitEnv: string;
33
35
  isPlayerLoading: boolean;
34
36
  isThreekitInitialized: boolean;
35
37
  playerElId: undefined | string;
@@ -47,6 +49,7 @@ interface EventHandlers {
47
49
  /*****************************************************
48
50
  * Actions
49
51
  ****************************************************/
52
+ export declare const setThreekitEnv: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
50
53
  export declare const setThreekitInitialized: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
51
54
  export declare const setPlayerLoading: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
52
55
  export declare const setPlayerElement: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
@@ -58,6 +61,7 @@ declare const reducer: import("redux").Reducer<TrebleState, import("redux").AnyA
58
61
  /*****************************************************
59
62
  * Standard Selectors
60
63
  ****************************************************/
64
+ export declare const getThreekitEnv: (state: RootState) => string;
61
65
  export declare const isThreekitInitialized: (state: RootState) => boolean;
62
66
  export declare const isPlayerLoading: (state: RootState) => boolean;
63
67
  export declare const getPlayerElementId: (state: RootState) => undefined | string;
@@ -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, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
201
- var _a, _b, _c, _d, _e, _f;
202
- return __generator(this, function (_g) {
203
- switch (_g.label) {
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 = Object.assign({}, ((_a = config.project) === null || _a === void 0 ? void 0 : _a.credentials) || {}, ((_b = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _b === void 0 ? void 0 : _b.credentials) || {});
209
- products = Object.assign({}, ((_c = config.project) === null || _c === void 0 ? void 0 : _c.products) || {}, ((_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _d === void 0 ? void 0 : _d.products) || {});
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) || ((_e = config === null || config === void 0 ? void 0 : config.project) === null || _e === void 0 ? void 0 : _e.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
- product = products[threekitEnv];
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 = ((_f = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _f === void 0 ? void 0 : _f.length)
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 = _g.sent();
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
- _g.label = 2;
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
- _g.sent();
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
- _g.sent();
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
  }
@@ -3,7 +3,7 @@ import Treble from './Treble';
3
3
  declare type SCENE_PHASES = 'LOADED' | 'PRELOADED' | 'RENDERED';
4
4
  declare type PRIVATE_APIS = 'scene' | 'player';
5
5
  export declare type DISPLAY_OPTIONS = 'webgl' | 'image';
6
- export declare type IAttributeTypes = 'String' | 'Asset' | 'Color' | 'Number';
6
+ export declare type IAttributeTypes = 'String' | 'Asset' | 'Color' | 'Number' | 'Boolean';
7
7
  export declare type AssetType = 'upload' | 'item';
8
8
  export declare type IMetadata = Record<string, string | number | null>;
9
9
  /***************************************************
@@ -53,7 +53,7 @@ export interface IConfigurationColor {
53
53
  g: number;
54
54
  b: number;
55
55
  }
56
- export declare type IConfigurationAttribute = IConfigurationAsset | IConfigurationColor | string | number | undefined;
56
+ export declare type IConfigurationAttribute = IConfigurationAsset | IConfigurationColor | string | number | boolean | undefined;
57
57
  export declare type IConfiguration = Record<string, IConfigurationAttribute>;
58
58
  export declare type ISetConfiguration = Record<string, IConfigurationAttribute>;
59
59
  /***************************************************
@@ -131,12 +131,16 @@ export interface IAttributeNumber extends IAttributeBase<'Number', number> {
131
131
  min?: number;
132
132
  step: number;
133
133
  }
134
+ /****** NUMBER TYPE ATTRIBUTE *******/
135
+ export interface IAttributeBoolean extends IAttributeBase<'Boolean', boolean> {
136
+ defaultValue: boolean;
137
+ }
134
138
  /****** getAttributes() *******/
135
- export declare type IThreekitAttribute = IAttributeAsset | IAttributeColor | IAttributeString | IAttributeNumber;
139
+ export declare type IThreekitAttribute = IAttributeAsset | IAttributeColor | IAttributeString | IAttributeNumber | IAttributeBoolean;
136
140
  /****** getDisplayAttributes() *******/
137
- export declare type IThreekitDisplayAttribute = IDisplayAttributeAsset | IDisplayAttributeString | IAttributeColor | IAttributeNumber;
141
+ export declare type IThreekitDisplayAttribute = IDisplayAttributeAsset | IDisplayAttributeString | IAttributeColor | IAttributeNumber | IAttributeBoolean;
138
142
  /****** Treble Hydrated Values *******/
139
- export declare type IHydratedAttribute = IHydratedAttributeAsset | IHydratedAttributeString | IAttributeColor | IAttributeNumber;
143
+ export declare type IHydratedAttribute = IHydratedAttributeAsset | IHydratedAttributeString | IAttributeColor | IAttributeNumber | IAttributeBoolean;
140
144
  /***************************************************
141
145
  * Camera
142
146
  **************************************************/