@threekit-tools/treble 0.0.50 → 0.0.54

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 -2
  2. package/dist/Treble/Treble.js +19 -2
  3. package/dist/api/catalog.d.ts +1 -0
  4. package/dist/api/catalog.js +86 -0
  5. package/dist/api/index.d.ts +2 -0
  6. package/dist/api/index.js +2 -0
  7. package/dist/components/FlatForm/index.js +9 -3
  8. package/dist/components/Upload/index.d.ts +12 -0
  9. package/dist/components/Upload/index.js +137 -0
  10. package/dist/components/Upload/upload.styles.d.ts +7 -0
  11. package/dist/components/Upload/upload.styles.js +16 -0
  12. package/dist/components/containers/formInputContainer.d.ts +7 -15
  13. package/dist/components/formComponents.d.ts +2 -0
  14. package/dist/components/formComponents.js +5 -1
  15. package/dist/constants.d.ts +4 -0
  16. package/dist/constants.js +5 -1
  17. package/dist/hooks/useArrayAttribute/index.d.ts +2 -0
  18. package/dist/hooks/useArrayAttribute/index.js +184 -0
  19. package/dist/hooks/useAttribute/index.d.ts +3 -3
  20. package/dist/hooks/useAttribute/index.js +65 -6
  21. package/dist/hooks/useWishlist/index.d.ts +1 -1
  22. package/dist/http/catalog.d.ts +53 -2
  23. package/dist/http/catalog.js +3 -3
  24. package/dist/http/index.d.ts +2 -0
  25. package/dist/http/index.js +2 -0
  26. package/dist/icons/Spinner.d.ts +9 -0
  27. package/dist/icons/Spinner.js +38 -0
  28. package/dist/icons/index.d.ts +3 -2
  29. package/dist/icons/index.js +4 -1
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.js +3 -1
  32. package/dist/store/attributes.d.ts +1 -1
  33. package/dist/store/attributes.js +13 -9
  34. package/dist/store/price.d.ts +1 -0
  35. package/dist/store/price.js +64 -4
  36. package/dist/store/product.d.ts +2 -1
  37. package/dist/store/product.js +25 -6
  38. package/dist/store/translations.d.ts +2 -1
  39. package/dist/store/translations.js +58 -4
  40. package/dist/store/treble.js +35 -55
  41. package/dist/store/wishlist.d.ts +5 -6
  42. package/dist/store/wishlist.js +44 -31
  43. package/dist/threekit.d.ts +18 -3
  44. package/dist/utils.d.ts +4 -3
  45. package/package.json +1 -1
@@ -1,13 +1,72 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
2
41
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updatePrice = exports.getPrice = exports.setPrice = exports.setPriceConfig = void 0;
42
+ exports.updatePrice = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
4
43
  var toolkit_1 = require("@reduxjs/toolkit");
44
+ var api_1 = __importDefault(require("../api"));
5
45
  /*****************************************************
6
46
  * Actions
7
47
  ****************************************************/
8
48
  // Actions to be used only internally
9
- exports.setPriceConfig = (0, toolkit_1.createAction)('setPriceConfig');
10
- exports.setPrice = (0, toolkit_1.createAction)('setPrice');
49
+ exports.setPriceConfig = (0, toolkit_1.createAction)('treble/price/set-price-config');
50
+ exports.setPrice = (0, toolkit_1.createAction)('treble/price/set-price');
51
+ var initPrice = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var pricebook, id, currency, price;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0: return [4 /*yield*/, api_1.default.price.getPricebooksList()];
56
+ case 1:
57
+ pricebook = _a.sent();
58
+ id = pricebook[0].id;
59
+ currency = pricebook[0].currencies[0];
60
+ if (pricebook.length) {
61
+ dispatch((0, exports.setPriceConfig)({ id: id, currency: currency }));
62
+ price = window.threekit.configurator.getPrice(id, currency);
63
+ dispatch((0, exports.setPrice)(price));
64
+ }
65
+ return [2 /*return*/];
66
+ }
67
+ });
68
+ }); }; };
69
+ exports.initPrice = initPrice;
11
70
  /*****************************************************
12
71
  * State
13
72
  ****************************************************/
@@ -25,10 +84,11 @@ var reducer = (0, toolkit_1.createSlice)({
25
84
  var _a = action.payload, id = _a.id, currency = _a.currency;
26
85
  state.id = id;
27
86
  state.currency = currency;
28
- state.price = window.threekit.configurator.getPrice(id, currency);
87
+ return state;
29
88
  });
30
89
  builder.addCase(exports.setPrice, function (state, action) {
31
90
  state.price = action.payload;
91
+ return state;
32
92
  });
33
93
  },
34
94
  reducers: {},
@@ -1,4 +1,4 @@
1
- import { RootState } from './index';
1
+ import { RootState, ThreekitDispatch } from './index';
2
2
  import { IMetadata } from '../threekit';
3
3
  /*****************************************************
4
4
  * Types and Interfaces
@@ -12,6 +12,7 @@ export interface ProductState {
12
12
  ****************************************************/
13
13
  export declare const setName: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
14
14
  export declare const setMetadata: import("@reduxjs/toolkit").ActionCreatorWithPayload<IMetadata, string>;
15
+ export declare const initProduct: () => (dispatch: ThreekitDispatch) => void;
15
16
  declare const reducer: import("redux").Reducer<ProductState, import("redux").AnyAction>;
16
17
  /*****************************************************
17
18
  * Standard Selectors
@@ -1,13 +1,33 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMetadata = exports.getName = exports.setMetadata = exports.setName = void 0;
14
+ exports.getMetadata = exports.getName = exports.initProduct = exports.setMetadata = exports.setName = void 0;
4
15
  var toolkit_1 = require("@reduxjs/toolkit");
5
16
  /*****************************************************
6
17
  * Actions
7
18
  ****************************************************/
8
19
  // Actions to be used only internally
9
- exports.setName = (0, toolkit_1.createAction)('setName');
10
- exports.setMetadata = (0, toolkit_1.createAction)('setMetadata');
20
+ exports.setName = (0, toolkit_1.createAction)('treble/product/set-name');
21
+ exports.setMetadata = (0, toolkit_1.createAction)('treble/product/set-metadata');
22
+ var initProduct = function () { return function (dispatch) {
23
+ var name = window.threekit.player.scene.get({
24
+ id: window.threekit.player.assetId,
25
+ }).name;
26
+ var metadata = window.threekit.configurator.getMetadata();
27
+ dispatch((0, exports.setName)(name));
28
+ dispatch((0, exports.setMetadata)(metadata));
29
+ }; };
30
+ exports.initProduct = initProduct;
11
31
  /*****************************************************
12
32
  * State
13
33
  ****************************************************/
@@ -21,12 +41,11 @@ var reducer = (0, toolkit_1.createSlice)({
21
41
  name: 'product',
22
42
  initialState: initialState,
23
43
  extraReducers: function (builder) {
24
- // Language
25
44
  builder.addCase(exports.setName, function (state, action) {
26
- state.name = action.payload;
45
+ return __assign(__assign({}, state), { name: action.payload });
27
46
  });
28
47
  builder.addCase(exports.setMetadata, function (state, action) {
29
- state.metadata = action.payload;
48
+ return __assign(__assign({}, state), { metadata: action.payload });
30
49
  });
31
50
  },
32
51
  reducers: {},
@@ -1,4 +1,4 @@
1
- import { RootState } from './index';
1
+ import { RootState, ThreekitDispatch } from './index';
2
2
  import { ITranslationMap } from '../api/products';
3
3
  /*****************************************************
4
4
  * Types and Interfaces
@@ -12,6 +12,7 @@ export interface TranslationsState {
12
12
  ****************************************************/
13
13
  export declare const setTranslations: import("@reduxjs/toolkit").ActionCreatorWithPayload<ITranslationMap, string>;
14
14
  export declare const setLanguage: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
15
+ export declare const initTranslations: (language?: string | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
15
16
  declare const reducer: import("redux").Reducer<TranslationsState, import("redux").AnyAction>;
16
17
  /*****************************************************
17
18
  * Standard Selectors
@@ -1,13 +1,68 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
2
41
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLanguageOptions = exports.getLanguage = exports.setLanguage = exports.setTranslations = void 0;
42
+ exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
4
43
  var toolkit_1 = require("@reduxjs/toolkit");
44
+ var api_1 = __importDefault(require("../api"));
5
45
  /*****************************************************
6
46
  * Actions
7
47
  ****************************************************/
8
48
  // Actions to be used only internally
9
- exports.setTranslations = (0, toolkit_1.createAction)('setTranslations');
10
- exports.setLanguage = (0, toolkit_1.createAction)('setLanguage');
49
+ exports.setTranslations = (0, toolkit_1.createAction)('treble/translations/set-translations');
50
+ exports.setLanguage = (0, toolkit_1.createAction)('treble/translations/set-language');
51
+ var initTranslations = function (language) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
52
+ var translations;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0: return [4 /*yield*/, api_1.default.products.fetchTranslations()];
56
+ case 1:
57
+ translations = _a.sent();
58
+ dispatch((0, exports.setTranslations)(translations));
59
+ if (language)
60
+ dispatch((0, exports.setLanguage)(language));
61
+ return [2 /*return*/];
62
+ }
63
+ });
64
+ }); }; };
65
+ exports.initTranslations = initTranslations;
11
66
  /*****************************************************
12
67
  * State
13
68
  ****************************************************/
@@ -20,7 +75,6 @@ var reducer = (0, toolkit_1.createSlice)({
20
75
  name: 'translations',
21
76
  initialState: initialState,
22
77
  extraReducers: function (builder) {
23
- // Language
24
78
  builder.addCase(exports.setTranslations, function (state, action) {
25
79
  state.translations = action.payload;
26
80
  });
@@ -57,10 +57,10 @@ var api_1 = __importDefault(require("../api"));
57
57
  var utils_1 = require("../utils");
58
58
  var constants_1 = require("../constants");
59
59
  var Treble_1 = __importDefault(require("../Treble"));
60
- var translations_1 = require("./translations");
61
60
  var attributes_1 = require("./attributes");
62
61
  var price_1 = require("./price");
63
62
  var wishlist_1 = require("./wishlist");
63
+ var translations_1 = require("./translations");
64
64
  var product_1 = require("./product");
65
65
  /*****************************************************
66
66
  * Helper Functions
@@ -104,9 +104,9 @@ var initialState = {
104
104
  /*****************************************************
105
105
  * Actions
106
106
  ****************************************************/
107
- exports.setThreekitInitialized = (0, toolkit_1.createAction)('setThreekitInitialized');
108
- exports.setPlayerLoading = (0, toolkit_1.createAction)('setPlayerLoading');
109
- exports.setPlayerElement = (0, toolkit_1.createAction)('setPlayerElement');
107
+ exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
108
+ exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
109
+ exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
110
110
  /*****************************************************
111
111
  * Slice
112
112
  ****************************************************/
@@ -148,17 +148,16 @@ exports.getPlayerElementId = getPlayerElementId;
148
148
  ****************************************************/
149
149
  var launch = function (launchConfig) {
150
150
  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, _a, player, translations, pricebook, _b, priceConfig, productName, wishlistData;
152
- var _c;
153
- var _d, _e, _f, _g, _h;
154
- return __generator(this, function (_j) {
155
- switch (_j.label) {
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) {
156
155
  case 0:
157
156
  if (window.threekit)
158
157
  return [2 /*return*/];
159
158
  config = (0, utils_1.loadTrebleConfig)();
160
- credentials = Object.assign({}, ((_d = config.project) === null || _d === void 0 ? void 0 : _d.credentials) || {}, ((_e = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _e === void 0 ? void 0 : _e.credentials) || {});
161
- products = Object.assign({}, ((_f = config.project) === null || _f === void 0 ? void 0 : _f.products) || {}, ((_g = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _g === void 0 ? void 0 : _g.products) || {});
159
+ 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) || {});
160
+ 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) || {});
162
161
  if (!Object.keys(credentials).length || !Object.keys(products).length)
163
162
  return [2 /*return*/, console.error('Missing credentials')];
164
163
  threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
@@ -202,19 +201,19 @@ var launch = function (launchConfig) {
202
201
  initialConfiguration = __assign({}, initialConfigurationRaw);
203
202
  updatedAssetId = assetId;
204
203
  params = (0, utils_1.getParams)();
205
- configId = ((_h = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _h === void 0 ? void 0 : _h.length)
204
+ configId = ((_e = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _e === void 0 ? void 0 : _e.length)
206
205
  ? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
207
206
  : configurationId;
208
207
  if (!configId) return [3 /*break*/, 2];
209
208
  return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
210
209
  case 1:
211
- configuration = _j.sent();
210
+ configuration = _f.sent();
212
211
  if (configuration) {
213
212
  initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
214
213
  connection_1.default.connect({ assetId: configuration.data.productId });
215
214
  updatedAssetId = configuration.data.productId;
216
215
  }
217
- _j.label = 2;
216
+ _f.label = 2;
218
217
  case 2:
219
218
  if (!updatedAssetId)
220
219
  return [2 /*return*/, console.error('missing assetId')];
@@ -222,54 +221,35 @@ var launch = function (launchConfig) {
222
221
  return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
223
222
  case 3:
224
223
  // We create the threekit script
225
- _j.sent();
226
- return [4 /*yield*/, Promise.all([
227
- window.threekitPlayer(__assign(__assign({ el: el,
228
- // Variables to sort out
229
- authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration })),
230
- api_1.default.products.fetchTranslations(),
231
- api_1.default.price.getPricebooksList(),
232
- ])];
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 }))];
233
228
  case 4:
234
- _a = _j.sent(), player = _a[0], translations = _a[1], pricebook = _a[2];
235
- _b = window;
236
- _c = {
237
- player: player
238
- };
229
+ player = _f.sent();
239
230
  return [4 /*yield*/, player.getConfigurator()];
240
231
  case 5:
241
- _b.threekit = (_c.configurator = _j.sent(),
242
- _c.treble = new Treble_1.default({ player: player, orgId: orgId }),
243
- _c);
244
- dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
232
+ configurator = _f.sent();
233
+ window.threekit = {
234
+ player: player,
235
+ configurator: configurator,
236
+ treble: new Treble_1.default({
237
+ player: player,
238
+ orgId: orgId,
239
+ initialConfiguration: configurator.getConfiguration(),
240
+ }),
241
+ };
242
+ dispatch((0, exports.setThreekitInitialized)());
243
+ dispatch((0, exports.setPlayerLoading)(false));
245
244
  window.threekit.player.on('setConfiguration', function () {
246
245
  dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
247
246
  dispatch((0, price_1.updatePrice)());
248
247
  });
249
- if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale) {
250
- dispatch((0, translations_1.setLanguage)(launchConfig.locale));
251
- dispatch((0, translations_1.setTranslations)(translations));
252
- }
253
- if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers)
254
- EVENTS = Object.assign(EVENTS, launchConfig.eventHandlers);
255
- if (pricebook.length) {
256
- priceConfig = {
257
- id: pricebook[0].id,
258
- currency: pricebook[0].currencies[0],
259
- };
260
- dispatch((0, price_1.setPriceConfig)(priceConfig));
261
- }
262
- productName = window.threekit.player.scene.get({
263
- id: window.threekit.player.assetId,
264
- }).name;
265
- dispatch((0, product_1.setName)(productName));
266
- dispatch((0, product_1.setMetadata)(window.threekit.configurator.getMetadata()));
267
- dispatch((0, exports.setThreekitInitialized)());
268
- dispatch((0, exports.setPlayerLoading)(false));
269
- return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
270
- case 6:
271
- wishlistData = _j.sent();
272
- dispatch((0, wishlist_1.setWishlist)(wishlistData));
248
+ EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
249
+ dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
250
+ dispatch((0, price_1.initPrice)());
251
+ dispatch((0, product_1.initProduct)());
252
+ dispatch((0, wishlist_1.refreshWishlist)());
273
253
  return [2 /*return*/];
274
254
  }
275
255
  });
@@ -1,6 +1,5 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
2
  import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
3
- import { IConfigurationResponse } from '../http/configurations';
4
3
  /*****************************************************
5
4
  * Types and Interfaces
6
5
  ****************************************************/
@@ -8,7 +7,10 @@ export declare type WishlistState = WishlistArray;
8
7
  /*****************************************************
9
8
  * Standard Selectors
10
9
  ****************************************************/
11
- export declare const setWishlist: import("@reduxjs/toolkit").ActionCreatorWithPayload<IConfigurationResponse[], string>;
10
+ export declare const refreshWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], void, {}>;
11
+ export declare const addToWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], ISaveConfigurationConfig, {}>;
12
+ export declare const clearWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/clear", never, never>;
13
+ export declare const removeFromWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[idx: number], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/remove-item", never, never>;
12
14
  /*****************************************************
13
15
  * Slice
14
16
  ****************************************************/
@@ -17,8 +19,5 @@ declare const reducer: import("redux").Reducer<WishlistArray, import("redux").An
17
19
  * Standard Selectors
18
20
  ****************************************************/
19
21
  export declare const getWishlist: (state: RootState) => WishlistArray;
20
- export declare const addToWishlist: (config: ISaveConfigurationConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
21
- export declare const removeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch) => void;
22
- export declare const resumeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
23
- export declare const clearWishlist: () => (dispatch: ThreekitDispatch) => void;
22
+ export declare const resumeFromWishlist: (idx: number) => (_: ThreekitDispatch, getState: () => RootState) => void;
24
23
  export default reducer;
@@ -36,9 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.clearWishlist = exports.resumeFromWishlist = exports.removeFromWishlist = exports.addToWishlist = exports.getWishlist = exports.setWishlist = void 0;
39
+ exports.resumeFromWishlist = exports.getWishlist = exports.removeFromWishlist = exports.clearWishlist = exports.addToWishlist = exports.refreshWishlist = void 0;
40
40
  var toolkit_1 = require("@reduxjs/toolkit");
41
- var attributes_1 = require("./attributes");
42
41
  /*****************************************************
43
42
  * State
44
43
  ****************************************************/
@@ -46,7 +45,36 @@ var initialState = [];
46
45
  /*****************************************************
47
46
  * Standard Selectors
48
47
  ****************************************************/
49
- exports.setWishlist = (0, toolkit_1.createAction)('setWishlist');
48
+ exports.refreshWishlist = (0, toolkit_1.createAsyncThunk)('treble/wishlist/refresh-data', function () { return __awaiter(void 0, void 0, void 0, function () {
49
+ var wishlistData;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0: return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
53
+ case 1:
54
+ wishlistData = _a.sent();
55
+ return [2 /*return*/, wishlistData];
56
+ }
57
+ });
58
+ }); });
59
+ exports.addToWishlist = (0, toolkit_1.createAsyncThunk)('treble/wishlist/add-item', function (config) { return __awaiter(void 0, void 0, void 0, function () {
60
+ var wishlistData;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
64
+ case 1:
65
+ wishlistData = _a.sent();
66
+ return [2 /*return*/, wishlistData];
67
+ }
68
+ });
69
+ }); });
70
+ exports.clearWishlist = (0, toolkit_1.createAction)('treble/wishlist/clear', function () {
71
+ var wishlistData = window.threekit.treble.wishlist.clearWishlist();
72
+ return { payload: wishlistData };
73
+ });
74
+ exports.removeFromWishlist = (0, toolkit_1.createAction)('treble/wishlist/remove-item', function (idx) {
75
+ var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
76
+ return { payload: wishlistData };
77
+ });
50
78
  /*****************************************************
51
79
  * Slice
52
80
  ****************************************************/
@@ -55,9 +83,17 @@ var reducer = (0, toolkit_1.createSlice)({
55
83
  initialState: initialState,
56
84
  reducers: {},
57
85
  extraReducers: function (builder) {
58
- builder.addCase(exports.setWishlist, function (state, action) {
59
- state = action.payload;
60
- return state;
86
+ builder.addCase(exports.refreshWishlist.fulfilled, function (_, action) {
87
+ return action.payload;
88
+ });
89
+ builder.addCase(exports.addToWishlist.fulfilled, function (_, action) {
90
+ return action.payload;
91
+ });
92
+ builder.addCase(exports.removeFromWishlist, function (_, action) {
93
+ return action.payload;
94
+ });
95
+ builder.addCase(exports.clearWishlist, function (_, action) {
96
+ return action.payload;
61
97
  });
62
98
  },
63
99
  }).reducer;
@@ -67,35 +103,12 @@ var reducer = (0, toolkit_1.createSlice)({
67
103
  // Wishlist
68
104
  var getWishlist = function (state) { return state.wishlist; };
69
105
  exports.getWishlist = getWishlist;
70
- var addToWishlist = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
71
- var wishlistData;
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
75
- case 1:
76
- wishlistData = _a.sent();
77
- dispatch((0, exports.setWishlist)(wishlistData));
78
- return [2 /*return*/];
79
- }
80
- });
81
- }); }; };
82
- exports.addToWishlist = addToWishlist;
83
- var removeFromWishlist = function (idx) { return function (dispatch) {
84
- var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
85
- dispatch((0, exports.setWishlist)(wishlistData));
86
- }; };
87
- exports.removeFromWishlist = removeFromWishlist;
88
- var resumeFromWishlist = function (idx) { return function (dispatch, getState) {
106
+ var resumeFromWishlist = function (idx) { return function (_, getState) {
89
107
  var wishlist = getState().wishlist;
90
108
  var savedConfiguration = wishlist[idx];
91
109
  if (!savedConfiguration)
92
110
  return;
93
- dispatch((0, attributes_1.setConfiguration)(savedConfiguration.variant));
111
+ window.threekit.configurator.setConfiguration(savedConfiguration.variant);
94
112
  }; };
95
113
  exports.resumeFromWishlist = resumeFromWishlist;
96
- var clearWishlist = function () { return function (dispatch) {
97
- var wishlistData = window.threekit.treble.wishlist.clearWishlist();
98
- dispatch((0, exports.setWishlist)(wishlistData));
99
- }; };
100
- exports.clearWishlist = clearWishlist;
101
114
  exports.default = reducer;
@@ -3,7 +3,8 @@ 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
- declare type IAttributeTypes = 'String' | 'Asset' | 'Color' | 'Number';
6
+ export declare type IAttributeTypes = 'String' | 'Asset' | 'Color' | 'Number';
7
+ export declare type AssetType = 'upload' | 'item';
7
8
  export declare type IMetadata = Record<string, string | number | null>;
8
9
  /***************************************************
9
10
  * Scene
@@ -83,7 +84,7 @@ export interface IDisplayAttributeAssetValue extends IConfigurationAssetValue {
83
84
  label: string;
84
85
  }
85
86
  export interface IAttributeAssetBase<V> extends IAttributeBase<'Asset', IConfigurationAsset> {
86
- assetType: string;
87
+ assetType: AssetType;
87
88
  blacklist: [];
88
89
  defaultValue: IConfigurationAsset;
89
90
  hiddenValues?: Array<string>;
@@ -213,11 +214,25 @@ export interface ThreekitInitConfig {
213
214
  showShare?: boolean;
214
215
  showLoadingThumbnail?: boolean;
215
216
  showLoadingProgress?: boolean;
216
- onLoadingProgress?: boolean;
217
+ onLoadingProgress?: (progress: number) => void;
217
218
  locale?: string;
218
219
  allowMobileVerticalOrbit?: boolean;
219
220
  publishStage?: string;
220
221
  display?: DISPLAY_OPTIONS;
222
+ classnames?: {
223
+ loading?: string;
224
+ mobile?: string;
225
+ share?: string | {
226
+ button: string;
227
+ popup: string;
228
+ };
229
+ fullscreen?: string;
230
+ ar?: string | {
231
+ button: string;
232
+ popup: string;
233
+ };
234
+ help?: string;
235
+ };
221
236
  }
222
237
  /***************************************************
223
238
  * Treble Declarations
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { ITranslationMap } from './api/products';
2
2
  import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute } from './threekit';
3
- import { ITrebleConfig } from './threekit';
3
+ import { ITrebleConfig, IAttributeTypes } from './threekit';
4
+ import { RawAttributeValue } from './hooks/useAttribute';
4
5
  interface ICameraPosition {
5
6
  position: ICoordinates;
6
7
  quaternion: IQuaternion;
@@ -53,8 +54,8 @@ export declare const metadataValueToObject: (data: string) => Record<string, str
53
54
  */
54
55
  export declare const createThreekitScriptEl: (threekitDomain: string) => Promise<void>;
55
56
  export declare const translateAttribute: (attributes: Array<IThreekitDisplayAttribute>, translations?: ITranslationMap | undefined, language?: string | undefined) => IThreekitDisplayAttribute;
56
- export declare const selectionToConfiguration: (value: string | number | boolean | IConfigurationColor, attributeType: string) => string | number | boolean | IConfigurationColor | {
57
- assetId: string | number | boolean | IConfigurationColor;
57
+ export declare const selectionToConfiguration: (value: RawAttributeValue, attributeType: IAttributeTypes) => string | number | boolean | File | IConfigurationColor | {
58
+ assetId: RawAttributeValue;
58
59
  };
59
60
  export declare const filterFormAttributes: (attributes: Record<string, IThreekitDisplayAttribute>, attributeComponentProps: IAttributesComponentProps, includeReservedAttributes: boolean) => IThreekitDisplayAttribute[];
60
61
  export declare const isUuid: (str?: string | undefined) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.50",
3
+ "version": "0.0.54",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [