@threekit-tools/treble 0.0.58 → 0.0.59

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 (45) hide show
  1. package/dist/Treble/Treble.d.ts +6 -0
  2. package/dist/Treble/Treble.js +16 -0
  3. package/dist/api/index.d.ts +2 -0
  4. package/dist/api/index.js +2 -0
  5. package/dist/api/server.d.ts +2 -0
  6. package/dist/api/server.js +11 -0
  7. package/dist/components/Cards/index.js +3 -4
  8. package/dist/components/Dropdown/index.js +6 -10
  9. package/dist/components/Strips/index.js +3 -4
  10. package/dist/components/Swatch/index.js +3 -4
  11. package/dist/components/TextInput/index.d.ts +1 -0
  12. package/dist/components/TextInput/index.js +2 -2
  13. package/dist/components/TextInput/textInput.styles.js +1 -1
  14. package/dist/components/Tiles/index.js +3 -4
  15. package/dist/components/TilesGroup/index.js +3 -4
  16. package/dist/components/containers/formInputContainer.d.ts +8 -4
  17. package/dist/components/containers/formInputContainer.js +10 -15
  18. package/dist/connection.d.ts +4 -1
  19. package/dist/connection.js +4 -0
  20. package/dist/hooks/useAttribute/index.d.ts +2 -2
  21. package/dist/hooks/useAttribute/index.js +2 -4
  22. package/dist/hooks/useConfigurator/index.d.ts +2 -2
  23. package/dist/hooks/useConfigurator/index.js +1 -1
  24. package/dist/hooks/useProductCache/index.d.ts +14 -0
  25. package/dist/hooks/useProductCache/index.js +35 -0
  26. package/dist/http/index.d.ts +2 -0
  27. package/dist/http/index.js +2 -0
  28. package/dist/http/server.d.ts +14 -0
  29. package/dist/http/server.js +17 -0
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.js +3 -1
  32. package/dist/store/attributes.d.ts +15 -2
  33. package/dist/store/attributes.js +20 -12
  34. package/dist/store/product.d.ts +38 -2
  35. package/dist/store/product.js +221 -10
  36. package/dist/store/translations.d.ts +1 -0
  37. package/dist/store/translations.js +3 -1
  38. package/dist/store/treble.d.ts +32 -2
  39. package/dist/store/treble.js +157 -34
  40. package/dist/threekit.d.ts +16 -1
  41. package/dist/utils.d.ts +0 -9
  42. package/dist/utils.js +1 -54
  43. package/package.json +1 -1
  44. package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
  45. package/dist/hooks/useArrayAttribute/index.js +0 -184
@@ -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.reloadTreble = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = 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
  ****************************************************/
@@ -100,6 +101,7 @@ var initialState = {
100
101
  isThreekitInitialized: false,
101
102
  isPlayerLoading: false,
102
103
  playerElId: undefined,
104
+ notifications: true,
103
105
  };
104
106
  /*****************************************************
105
107
  * Actions
@@ -107,6 +109,7 @@ var initialState = {
107
109
  exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
108
110
  exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
109
111
  exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
112
+ exports.reloadTreble = (0, toolkit_1.createAction)('treble/reload');
110
113
  /*****************************************************
111
114
  * Slice
112
115
  ****************************************************/
@@ -115,14 +118,20 @@ var reducer = (0, toolkit_1.createSlice)({
115
118
  initialState: initialState,
116
119
  reducers: {},
117
120
  extraReducers: function (builder) {
118
- builder.addCase(exports.setThreekitInitialized, function (state, _) {
119
- state.isThreekitInitialized = true;
121
+ builder.addCase(exports.setThreekitInitialized, function (state, action) {
122
+ state.isThreekitInitialized = action.payload;
123
+ return state;
120
124
  });
121
125
  builder.addCase(exports.setPlayerLoading, function (state, action) {
122
126
  state.isPlayerLoading = action.payload;
127
+ return state;
123
128
  });
124
129
  builder.addCase(exports.setPlayerElement, function (state, action) {
125
130
  state.playerElId = action.payload;
131
+ return state;
132
+ });
133
+ builder.addCase(exports.reloadTreble, function (state, action) {
134
+ return __assign(__assign({}, state), action.payload);
126
135
  });
127
136
  },
128
137
  }).reducer;
@@ -146,12 +155,52 @@ exports.getPlayerElementId = getPlayerElementId;
146
155
  /*****************************************************
147
156
  * Complex Actions
148
157
  ****************************************************/
158
+ var initPlayer = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
159
+ var el, authToken, assetId, stageId, orgId, playerConfig, initialConfiguration, player, configurator;
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0:
163
+ el = config.el, authToken = config.authToken, assetId = config.assetId, stageId = config.stageId, orgId = config.orgId, playerConfig = config.playerConfig, initialConfiguration = config.initialConfiguration;
164
+ return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
165
+ // Variables to sort out
166
+ authToken: authToken, stageId: stageId, assetId: assetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
167
+ case 1:
168
+ player = _a.sent();
169
+ return [4 /*yield*/, player.getConfigurator()];
170
+ case 2:
171
+ configurator = _a.sent();
172
+ if (window.threekit) {
173
+ window.threekit = Object.assign(window.threekit, {
174
+ player: player,
175
+ configurator: configurator,
176
+ });
177
+ }
178
+ else
179
+ window.threekit = {
180
+ player: player,
181
+ configurator: configurator,
182
+ treble: new Treble_1.default({
183
+ player: player,
184
+ orgId: orgId,
185
+ initialConfiguration: configurator.getConfiguration(),
186
+ }),
187
+ };
188
+ dispatch((0, exports.setThreekitInitialized)(true));
189
+ dispatch((0, exports.setPlayerLoading)(false));
190
+ window.threekit.player.on('setConfiguration', function () {
191
+ dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
192
+ });
193
+ return [2 /*return*/];
194
+ }
195
+ });
196
+ }); }; };
197
+ exports.initPlayer = initPlayer;
149
198
  var launch = function (launchConfig) {
150
199
  return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
151
- var config, credentials, products, threekitEnv, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration, player, configurator;
152
- var _a, _b, _c, _d, _e;
153
- return __generator(this, function (_f) {
154
- switch (_f.label) {
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) {
155
204
  case 0:
156
205
  if (window.threekit)
157
206
  return [2 /*return*/];
@@ -161,6 +210,8 @@ var launch = function (launchConfig) {
161
210
  if (!Object.keys(credentials).length || !Object.keys(products).length)
162
211
  return [2 /*return*/, console.error('Missing credentials')];
163
212
  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';
164
215
  playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
165
216
  envCredentials = credentials[threekitEnv];
166
217
  product = products[threekitEnv];
@@ -196,59 +247,58 @@ var launch = function (launchConfig) {
196
247
  orgId: orgId,
197
248
  assetId: assetId,
198
249
  threekitDomain: threekitDomainRaw,
250
+ serverUrl: serverUrl,
199
251
  });
200
252
  threekitDomain = connection_1.default.getConnection().threekitDomain;
201
253
  initialConfiguration = __assign({}, initialConfigurationRaw);
202
254
  updatedAssetId = assetId;
203
255
  params = (0, utils_1.getParams)();
204
- configId = ((_e = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _e === void 0 ? void 0 : _e.length)
256
+ configId = ((_f = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _f === void 0 ? void 0 : _f.length)
205
257
  ? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
206
258
  : configurationId;
207
259
  if (!configId) return [3 /*break*/, 2];
208
260
  return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
209
261
  case 1:
210
- configuration = _f.sent();
262
+ configuration = _g.sent();
211
263
  if (configuration) {
212
264
  initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
213
265
  connection_1.default.connect({ assetId: configuration.data.productId });
214
266
  updatedAssetId = configuration.data.productId;
215
267
  }
216
- _f.label = 2;
268
+ _g.label = 2;
217
269
  case 2:
218
270
  if (!updatedAssetId)
219
271
  return [2 /*return*/, console.error('missing assetId')];
220
272
  // We create the threekit script
221
- return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
273
+ return [4 /*yield*/, new Promise(function (resolve) {
274
+ var script = document.createElement('script');
275
+ script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
276
+ script.id = 'threekit-player-bundle';
277
+ script.onload = function () { return resolve(); };
278
+ document.head.appendChild(script);
279
+ })];
222
280
  case 3:
223
281
  // We create the threekit script
224
- _f.sent();
225
- return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
226
- // Variables to sort out
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,
282
+ _g.sent();
283
+ return [4 /*yield*/, dispatch((0, exports.initPlayer)({
284
+ el: el,
238
285
  orgId: orgId,
239
- initialConfiguration: configurator.getConfiguration(),
240
- }),
241
- };
242
- dispatch((0, exports.setThreekitInitialized)());
243
- dispatch((0, exports.setPlayerLoading)(false));
244
- window.threekit.player.on('setConfiguration', function () {
245
- dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
246
- dispatch((0, price_1.updatePrice)());
286
+ authToken: authToken,
287
+ stageId: stageId,
288
+ assetId: updatedAssetId,
289
+ playerConfig: playerConfig,
290
+ initialConfiguration: initialConfiguration,
291
+ }))];
292
+ case 4:
293
+ _g.sent();
294
+ document.addEventListener('treble:notification', function (e) {
295
+ message_1.default.info(e.detail.message);
247
296
  });
248
297
  EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
249
298
  dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
250
299
  dispatch((0, price_1.initPrice)());
251
- dispatch((0, product_1.initProduct)());
300
+ dispatch((0, price_1.updatePrice)());
301
+ dispatch((0, product_1.initProduct)(products));
252
302
  dispatch((0, wishlist_1.refreshWishlist)());
253
303
  return [2 /*return*/];
254
304
  }
@@ -256,4 +306,77 @@ var launch = function (launchConfig) {
256
306
  }); };
257
307
  };
258
308
  exports.launch = launch;
309
+ var unloadPlayer = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
310
+ return __generator(this, function (_a) {
311
+ switch (_a.label) {
312
+ case 0:
313
+ dispatch((0, exports.setThreekitInitialized)(true));
314
+ dispatch((0, exports.setPlayerLoading)(false));
315
+ dispatch((0, attributes_1.setAttributes)([]));
316
+ dispatch((0, product_1.setName)(''));
317
+ dispatch((0, product_1.setMetadata)({}));
318
+ return [4 /*yield*/, window.threekit.player.unload()];
319
+ case 1:
320
+ _a.sent();
321
+ return [2 /*return*/];
322
+ }
323
+ });
324
+ }); }; };
325
+ exports.unloadPlayer = unloadPlayer;
326
+ var reloadPlayer = function (config) {
327
+ return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
328
+ var connectionObj, assetId, stageId, initialConfiguration, configuration, state, trebleConfig, playerConfig, el;
329
+ return __generator(this, function (_a) {
330
+ switch (_a.label) {
331
+ case 0:
332
+ connectionObj = connection_1.default.getConnection();
333
+ if (!(config === undefined)) return [3 /*break*/, 1];
334
+ assetId = connectionObj.assetId;
335
+ return [3 /*break*/, 4];
336
+ case 1:
337
+ if (!(typeof config === 'string')) return [3 /*break*/, 2];
338
+ assetId = config;
339
+ return [3 /*break*/, 4];
340
+ case 2:
341
+ assetId = (config === null || config === void 0 ? void 0 : config.assetId) || connectionObj.assetId;
342
+ stageId = config === null || config === void 0 ? void 0 : config.stageId;
343
+ initialConfiguration = (config === null || config === void 0 ? void 0 : config.configuration) || {};
344
+ if (!(config === null || config === void 0 ? void 0 : config.configurationId)) return [3 /*break*/, 4];
345
+ return [4 /*yield*/, api_1.default.configurations.fetch(config === null || config === void 0 ? void 0 : config.configurationId)];
346
+ case 3:
347
+ configuration = _a.sent();
348
+ if (configuration) {
349
+ initialConfiguration = Object.assign({}, initialConfiguration, configuration.data.variant);
350
+ assetId = configuration.data.productId;
351
+ }
352
+ _a.label = 4;
353
+ case 4:
354
+ // Update connection
355
+ if (assetId !== connectionObj.assetId)
356
+ connection_1.default.connect({ assetId: assetId });
357
+ state = getState();
358
+ trebleConfig = (0, utils_1.loadTrebleConfig)();
359
+ playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, trebleConfig.player);
360
+ el = document.getElementById(state.treble.playerElId);
361
+ if (state.treble.isThreekitInitialized)
362
+ dispatch((0, exports.unloadPlayer)());
363
+ return [4 /*yield*/, dispatch((0, exports.initPlayer)({
364
+ el: el,
365
+ orgId: connectionObj.orgId,
366
+ authToken: connectionObj.authToken,
367
+ stageId: stageId,
368
+ assetId: assetId,
369
+ playerConfig: playerConfig,
370
+ initialConfiguration: initialConfiguration,
371
+ }))];
372
+ case 5:
373
+ _a.sent();
374
+ dispatch((0, price_1.updatePrice)());
375
+ dispatch((0, product_1.initProduct)());
376
+ return [2 /*return*/];
377
+ }
378
+ });
379
+ }); };
380
+ };
381
+ exports.reloadPlayer = reloadPlayer;
259
382
  exports.default = reducer;
@@ -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 | IAttributeColor | IDisplayAttributeString | IAttributeNumber;
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,4 +1,3 @@
1
- import { ITranslationMap } from './api/products';
2
1
  import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute } from './threekit';
3
2
  import { ITrebleConfig, IAttributeTypes } from './threekit';
4
3
  import { RawAttributeValue } from './hooks/useAttribute';
@@ -47,14 +46,6 @@ export declare const downloadSnapshot: (snapshot: string, filename: string) => P
47
46
  export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
48
47
  export declare const easeInOutCubic: (val: number) => number;
49
48
  export declare const metadataValueToObject: (data: string) => Record<string, string | number>;
50
- /**
51
- * A function to load the Threekit JS Player API script
52
- *
53
- * @param threekitDomain The threekit environement to use. i.e. preview.threekit.com
54
- * @returns
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;
58
49
  export declare const selectionToConfiguration: (value: RawAttributeValue, attributeType: IAttributeTypes) => string | number | boolean | File | IConfigurationColor | {
59
50
  assetId: RawAttributeValue;
60
51
  } | 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.translateAttribute = exports.createThreekitScriptEl = 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.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,59 +309,6 @@ var metadataValueToObject = function (data) {
309
309
  }, {});
310
310
  };
311
311
  exports.metadataValueToObject = metadataValueToObject;
312
- /**
313
- * A function to load the Threekit JS Player API script
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) {
329
- var hasTranslation = !!language && !!translations;
330
- return attributes.reduce(function (output, attribute) {
331
- var _a;
332
- var _b;
333
- return Object.assign(output, (_a = {},
334
- _a[attribute.name] = Object.assign({}, attribute, {
335
- label: hasTranslation
336
- ? ((_b = translations === null || translations === void 0 ? void 0 : translations[attribute.name]) === null || _b === void 0 ? void 0 : _b[language]) || attribute.name
337
- : attribute.name,
338
- }, attribute.type === 'String'
339
- ? {
340
- values: attribute.values.map(function (el) {
341
- var _a;
342
- return Object.assign({}, el, {
343
- label: hasTranslation
344
- ? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
345
- : attribute.name,
346
- });
347
- }),
348
- }
349
- : attribute.type === 'Asset'
350
- ? {
351
- values: attribute.values.map(function (el) {
352
- var _a;
353
- return Object.assign({}, el, {
354
- label: hasTranslation
355
- ? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
356
- : attribute.name,
357
- });
358
- }),
359
- }
360
- : undefined),
361
- _a));
362
- });
363
- };
364
- exports.translateAttribute = translateAttribute;
365
312
  var selectionToConfiguration = function (value, attributeType) {
366
313
  switch (attributeType) {
367
314
  case constants_1.ATTRIBUTE_TYPES.number:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1,2 +0,0 @@
1
- export declare type AttributeIdentifier = string | RegExp;
2
- export declare const useArrayAttribute: (attributeIdentifier: AttributeIdentifier) => string | RegExp | never[];
@@ -1,184 +0,0 @@
1
- "use strict";
2
- // import { useThreekitSelector, useThreekitDispatch } from '../../store';
3
- // import { getAttributes, setConfiguration } from '../../store/attributes';
4
- // import { selectionToConfiguration } from '../../utils';
5
- // import {
6
- // IConfigurationColor,
7
- // ISetConfiguration,
8
- // IThreekitDisplayAttribute,
9
- // } from '../../threekit';
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.useArrayAttribute = void 0;
12
- // export type AttributeValue = string | number | boolean | IConfigurationColor;
13
- // type UseAttributeError = [undefined, undefined];
14
- // type UseAttributeSuccess = [
15
- // IThreekitDisplayAttribute,
16
- // (val: AttributeValue) => void
17
- // ];
18
- var useArrayAttribute = function (attributeIdentifier) {
19
- if (!attributeIdentifier)
20
- return [];
21
- return attributeIdentifier;
22
- };
23
- exports.useArrayAttribute = useArrayAttribute;
24
- // Ordinal Configurator (Psuedo-Array type attribute)
25
- // export const addItemToArray = (arrayLabel) => (
26
- // assetId,
27
- // addToIdx = undefined
28
- // ) => async (dispatch, getState) => {
29
- // if (!assetId?.length) return;
30
- // const { threekit } = getState();
31
- // const attributesRegExp = new RegExp(`${arrayLabel} [0-9]`);
32
- // const arrayAttributes = filterAttributesArray(
33
- // attributesRegExp,
34
- // threekit.attributes
35
- // );
36
- // let updateAttrIdx = addToIdx;
37
- // let attributeToUpdate;
38
- // if (isNaN(updateAttrIdx))
39
- // attributeToUpdate = Object.values(arrayAttributes).find((el, idx) => {
40
- // if (!el.value.assetId?.length) {
41
- // updateAttrIdx = idx;
42
- // return true;
43
- // }
44
- // });
45
- // else attributeToUpdate = arrayAttributes[updateAttrIdx];
46
- // if (!attributeToUpdate) return message.info('Max items reached');
47
- // let error;
48
- // const options = Object.values(arrayAttributes)[0].values.reduce(
49
- // (output, item) => Object.assign(output, { [item.assetId]: item }),
50
- // {}
51
- // );
52
- // const updatedArray = Object.values(arrayAttributes).reduce(
53
- // (output, attr, i) => {
54
- // if (i !== updateAttrIdx) output.push(attr);
55
- // else output.push({ ...attr, value: { assetId } });
56
- // return output;
57
- // },
58
- // []
59
- // );
60
- // // Default Validator
61
- // error = arrayValidator(options, updatedArray);
62
- // if (error) return message.info(error);
63
- // // Custom Validator
64
- // if (MIDDLEWARE.arrayValidation?.[arrayLabel])
65
- // error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
66
- // if (error) return message.info(error);
67
- // dispatch(setConfiguration({ [attributeToUpdate.name]: { assetId } }));
68
- // };
69
- // export const deleteItemFromArray = (arrayLabel) => (idx) => async (
70
- // dispatch,
71
- // getState
72
- // ) => {
73
- // if (isNaN(idx)) return;
74
- // const { threekit } = getState();
75
- // const attributesRegExp = new RegExp(`${arrayLabel} [0-9]`);
76
- // const arrayAttributes = filterAttributesArray(
77
- // attributesRegExp,
78
- // threekit.attributes
79
- // );
80
- // let error;
81
- // const options = Object.values(arrayAttributes)[0].values.reduce(
82
- // (output, item) => Object.assign(output, { [item.assetId]: item }),
83
- // {}
84
- // );
85
- // const updatedArray = Object.values(arrayAttributes).filter(
86
- // (_, i) => i !== idx
87
- // );
88
- // // Default Validator
89
- // error = arrayValidator(options, updatedArray);
90
- // if (error) return message.info(error);
91
- // // Custom Validator
92
- // if (MIDDLEWARE.arrayValidation?.[arrayLabel])
93
- // error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
94
- // if (error) return message.info(error);
95
- // const arrayConfigurationObj = filterAttributesArray(
96
- // attributesRegExp,
97
- // window.threekit.configurator.getConfiguration()
98
- // );
99
- // const arrayConfiguration = Object.entries(arrayConfigurationObj);
100
- // const updatedConfiguration = arrayConfiguration.reduce(
101
- // (output, [attributeName], i) => {
102
- // if (i < idx) return output;
103
- // if (!arrayConfiguration[i + 1])
104
- // return Object.assign(output, { [attributeName]: { assetId: '' } });
105
- // return Object.assign(output, {
106
- // [attributeName]: arrayConfiguration[i + 1][1],
107
- // });
108
- // },
109
- // {}
110
- // );
111
- // dispatch(setConfiguration(updatedConfiguration));
112
- // };
113
- // export const moveItemWithinArray = (arrayLabel) => (
114
- // fromIdx,
115
- // toIdx,
116
- // config
117
- // ) => async (dispatch, getState) => {
118
- // if (isNaN(fromIdx) || isNaN(fromIdx)) return;
119
- // const { threekit } = getState();
120
- // const { method } = Object.assign({ method: 'move' }, config);
121
- // const attributesRegExp =
122
- // typeof arrayLabel === 'string'
123
- // ? new RegExp(`${arrayLabel} [0-9]`)
124
- // : arrayLabel;
125
- // const arrayAttributes = filterAttributesArray(
126
- // attributesRegExp,
127
- // threekit.attributes
128
- // );
129
- // let error;
130
- // const options = Object.values(arrayAttributes)[0].values.reduce(
131
- // (output, item) => Object.assign(output, { [item.assetId]: item }),
132
- // {}
133
- // );
134
- // let updatedArray;
135
- // switch (method) {
136
- // case 'move':
137
- // updatedArray = Object.values(arrayAttributes).reduce(
138
- // (output, attr, idx, srcArray) => {
139
- // if (idx === fromIdx) return output;
140
- // output.push(attr);
141
- // if (idx === toIdx) output.push(srcArray[fromIdx]);
142
- // return output;
143
- // },
144
- // []
145
- // );
146
- // break;
147
- // default:
148
- // break;
149
- // }
150
- // // Default Validator
151
- // error = arrayValidator(options, updatedArray);
152
- // if (error) return message.info(error);
153
- // // Custom Validator
154
- // if (MIDDLEWARE.arrayValidation?.[arrayLabel])
155
- // error = MIDDLEWARE.arrayValidation?.[arrayLabel](options, updatedArray);
156
- // if (error) return message.info(error);
157
- // const arrayConfigurationObj = filterAttributesArray(
158
- // attributesRegExp,
159
- // window.threekit.configurator.getConfiguration()
160
- // );
161
- // const attributeKeys = Object.keys(arrayConfigurationObj);
162
- // const arrayConfiguration = Object.values(arrayConfigurationObj);
163
- // let updatedConfiguration;
164
- // switch (method) {
165
- // case 'move':
166
- // updatedConfiguration = arrayConfiguration.reduce(
167
- // (output, configuration, idx, srcArray) => {
168
- // if (idx === fromIdx) return output;
169
- // output = Object.assign(output, {
170
- // [attributeKeys.shift()]: configuration,
171
- // });
172
- // if (idx === toIdx)
173
- // output = Object.assign(output, {
174
- // [attributeKeys.shift()]: srcArray[fromIdx],
175
- // });
176
- // return output;
177
- // },
178
- // {}
179
- // );
180
- // break;
181
- // default:
182
- // break;
183
- // }
184
- // dispatch(setConfiguration(updatedConfiguration));