@threekit-tools/treble 0.0.48 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Treble/Snapshots.js +0 -26
- package/dist/Treble/Treble.d.ts +3 -1
- package/dist/Treble/Treble.js +14 -3
- package/dist/Treble/Wishlist.d.ts +3 -2
- package/dist/Treble/Wishlist.js +12 -12
- package/dist/api/catalog.d.ts +1 -0
- package/dist/api/catalog.js +86 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/components/Accordion/index.d.ts +1 -1
- package/dist/components/FlatForm/index.js +9 -3
- package/dist/components/Player/index.js +5 -3
- package/dist/components/ThreekitProvider/index.d.ts +3 -1
- package/dist/components/ThreekitProvider/index.js +3 -3
- package/dist/components/Upload/index.d.ts +12 -0
- package/dist/components/Upload/index.js +114 -0
- package/dist/components/Upload/upload.styles.d.ts +6 -0
- package/dist/components/Upload/upload.styles.js +15 -0
- package/dist/components/containers/formInputContainer.d.ts +8 -16
- package/dist/components/formComponents.d.ts +2 -0
- package/dist/components/formComponents.js +5 -1
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -1
- package/dist/hooks/useArrayAttribute/index.d.ts +2 -0
- package/dist/hooks/useArrayAttribute/index.js +184 -0
- package/dist/hooks/useAttribute/index.d.ts +3 -3
- package/dist/hooks/useAttribute/index.js +67 -8
- package/dist/hooks/useConfigurator/index.js +3 -3
- package/dist/hooks/useMetadata/index.js +2 -2
- package/dist/hooks/useName/index.js +2 -2
- package/dist/hooks/usePlayerLoadingStatus/index.js +2 -2
- package/dist/hooks/usePlayerPortal/index.js +2 -3
- package/dist/hooks/usePrice/index.d.ts +1 -1
- package/dist/hooks/usePrice/index.js +2 -2
- package/dist/hooks/useShare/index.js +2 -2
- package/dist/hooks/useSnapshot/index.js +2 -2
- package/dist/hooks/useThreekitInitStatus/index.js +2 -2
- package/dist/hooks/useWishlist/index.d.ts +1 -1
- package/dist/hooks/useWishlist/index.js +8 -7
- package/dist/http/catalog.d.ts +53 -2
- package/dist/http/catalog.js +3 -3
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/store/attributes.d.ts +20 -0
- package/dist/store/attributes.js +139 -0
- package/dist/store/index.d.ts +67 -7
- package/dist/store/index.js +36 -4
- package/dist/store/price.d.ts +33 -0
- package/dist/store/price.js +116 -0
- package/dist/store/product.d.ts +22 -0
- package/dist/store/product.js +65 -0
- package/dist/store/translations.d.ts +22 -0
- package/dist/store/translations.js +100 -0
- package/dist/store/treble.d.ts +41 -0
- package/dist/store/treble.js +257 -0
- package/dist/store/wishlist.d.ts +23 -0
- package/dist/store/wishlist.js +114 -0
- package/dist/threekit.d.ts +3 -2
- package/dist/utils.d.ts +4 -3
- package/package.json +1 -1
- package/dist/store/threekit.d.ts +0 -68
- package/dist/store/threekit.js +0 -453
package/dist/store/threekit.js
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
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
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.clearWishlist = exports.resumeFromWishlist = exports.removeFromWishlist = exports.addToWishlist = exports.setConfiguration = exports.launch = exports.getWishlist = exports.getAttributes = exports.getLanguageOptions = exports.getLanguage = exports.getMetadata = exports.getPrice = exports.getName = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitLoaded = exports.setThreekitLoaded = void 0;
|
|
54
|
-
var connection_1 = __importDefault(require("../connection"));
|
|
55
|
-
var toolkit_1 = require("@reduxjs/toolkit");
|
|
56
|
-
var api_1 = __importDefault(require("../api"));
|
|
57
|
-
var utils_1 = require("../utils");
|
|
58
|
-
var constants_1 = require("../constants");
|
|
59
|
-
var Treble_1 = __importDefault(require("../Treble"));
|
|
60
|
-
/*****************************************************
|
|
61
|
-
* Helper Functions
|
|
62
|
-
****************************************************/
|
|
63
|
-
var createPlayerLoaderEl = function (elementId) {
|
|
64
|
-
/**
|
|
65
|
-
* By default the player is loaded into a player-loader div that
|
|
66
|
-
* is placed outside the user's view. This is done because in
|
|
67
|
-
* React the Threekit Initialization may happen before the
|
|
68
|
-
* component with the player HTML element has loaded which would
|
|
69
|
-
* otherwise throw an error.
|
|
70
|
-
*/
|
|
71
|
-
var playerElement = document.getElementById(elementId);
|
|
72
|
-
if (playerElement)
|
|
73
|
-
return playerElement;
|
|
74
|
-
playerElement = document.createElement('div');
|
|
75
|
-
playerElement.setAttribute('id', elementId);
|
|
76
|
-
playerElement.style.height = '100%';
|
|
77
|
-
var playerLoader = document.createElement('div');
|
|
78
|
-
playerLoader.setAttribute('id', constants_1.TK_PLAYER_LOADER_DIV);
|
|
79
|
-
playerLoader.appendChild(playerElement);
|
|
80
|
-
playerLoader.style.opacity = '0';
|
|
81
|
-
playerLoader.style.height = '1px';
|
|
82
|
-
playerLoader.style.position = 'fixed';
|
|
83
|
-
playerLoader.style.top = '-100%';
|
|
84
|
-
document.body.appendChild(playerLoader);
|
|
85
|
-
return playerElement;
|
|
86
|
-
};
|
|
87
|
-
/*****************************************************
|
|
88
|
-
* Constants and Event Handlers
|
|
89
|
-
****************************************************/
|
|
90
|
-
var EVENTS = {};
|
|
91
|
-
var initialState = {
|
|
92
|
-
// Player HTML element
|
|
93
|
-
playerElId: undefined,
|
|
94
|
-
// Name of the Initialized Item
|
|
95
|
-
name: undefined,
|
|
96
|
-
// Initialized item's metadata
|
|
97
|
-
metadata: undefined,
|
|
98
|
-
// Selected language
|
|
99
|
-
translations: undefined,
|
|
100
|
-
language: undefined,
|
|
101
|
-
// Price
|
|
102
|
-
priceConfig: null,
|
|
103
|
-
// Tracks Threekit API initialization status
|
|
104
|
-
isThreekitLoaded: false,
|
|
105
|
-
// Tracks configuration update
|
|
106
|
-
isPlayerLoading: false,
|
|
107
|
-
// Attributes State
|
|
108
|
-
attributes: undefined,
|
|
109
|
-
wishlist: [],
|
|
110
|
-
};
|
|
111
|
-
var _a = (0, toolkit_1.createSlice)({
|
|
112
|
-
name: 'threekit',
|
|
113
|
-
initialState: initialState,
|
|
114
|
-
reducers: {
|
|
115
|
-
// Loading Trackers
|
|
116
|
-
setThreekitLoaded: function (state, _) {
|
|
117
|
-
state.isThreekitLoaded = true;
|
|
118
|
-
},
|
|
119
|
-
setPlayerLoading: function (state, action) {
|
|
120
|
-
state.isPlayerLoading = action.payload;
|
|
121
|
-
},
|
|
122
|
-
// Initialized Item's Name
|
|
123
|
-
setPlayerElement: function (state, action) {
|
|
124
|
-
state.playerElId = action.payload;
|
|
125
|
-
},
|
|
126
|
-
// Initialized Item's Name
|
|
127
|
-
setName: function (state, action) {
|
|
128
|
-
state.name = action.payload;
|
|
129
|
-
},
|
|
130
|
-
// Initialized Item's Metadata
|
|
131
|
-
setMetadata: function (state, action) {
|
|
132
|
-
state.metadata = action.payload;
|
|
133
|
-
},
|
|
134
|
-
// Language
|
|
135
|
-
setTranslations: function (state, action) {
|
|
136
|
-
state.translations = action.payload;
|
|
137
|
-
},
|
|
138
|
-
setLanguage: function (state, action) {
|
|
139
|
-
state.language = action.payload;
|
|
140
|
-
},
|
|
141
|
-
// Price
|
|
142
|
-
setPriceConfig: function (state, action) {
|
|
143
|
-
state.priceConfig = action.payload;
|
|
144
|
-
},
|
|
145
|
-
// Attributes
|
|
146
|
-
setAttributes: function (state, action) {
|
|
147
|
-
state.attributes = action.payload;
|
|
148
|
-
},
|
|
149
|
-
// Wishlist
|
|
150
|
-
setWishlist: function (state, action) {
|
|
151
|
-
state.wishlist = action.payload;
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
}), actions = _a.actions, reducer = _a.reducer;
|
|
155
|
-
/*****************************************************
|
|
156
|
-
* Actions
|
|
157
|
-
****************************************************/
|
|
158
|
-
// Actions to be used only internally
|
|
159
|
-
var setPlayerLoading = actions.setPlayerLoading, setName = actions.setName, setMetadata = actions.setMetadata, setPriceConfig = actions.setPriceConfig, setAttributes = actions.setAttributes, setLanguage = actions.setLanguage, setTranslations = actions.setTranslations, setPlayerElement = actions.setPlayerElement, setWishlist = actions.setWishlist;
|
|
160
|
-
// Actions to be used only internally and externally
|
|
161
|
-
exports.setThreekitLoaded = actions.setThreekitLoaded;
|
|
162
|
-
/*****************************************************
|
|
163
|
-
* Standard Selectors
|
|
164
|
-
****************************************************/
|
|
165
|
-
// Loading Trackers
|
|
166
|
-
var isThreekitLoaded = function (state) {
|
|
167
|
-
return state.threekit.isThreekitLoaded;
|
|
168
|
-
};
|
|
169
|
-
exports.isThreekitLoaded = isThreekitLoaded;
|
|
170
|
-
var isPlayerLoading = function (state) {
|
|
171
|
-
return state.threekit.isPlayerLoading;
|
|
172
|
-
};
|
|
173
|
-
exports.isPlayerLoading = isPlayerLoading;
|
|
174
|
-
// Player's HTML element
|
|
175
|
-
var getPlayerElementId = function (state) {
|
|
176
|
-
return state.threekit.playerElId;
|
|
177
|
-
};
|
|
178
|
-
exports.getPlayerElementId = getPlayerElementId;
|
|
179
|
-
// Initialized item's name
|
|
180
|
-
var getName = function (state) {
|
|
181
|
-
return state.threekit.name;
|
|
182
|
-
};
|
|
183
|
-
exports.getName = getName;
|
|
184
|
-
// Price
|
|
185
|
-
var getPrice = function (state) {
|
|
186
|
-
var priceConfig = state.threekit.priceConfig;
|
|
187
|
-
if (!priceConfig)
|
|
188
|
-
return undefined;
|
|
189
|
-
var price = window.threekit.configurator.getPrice(priceConfig.id, priceConfig.currency);
|
|
190
|
-
return { price: price, currency: priceConfig.currency };
|
|
191
|
-
};
|
|
192
|
-
exports.getPrice = getPrice;
|
|
193
|
-
// Metadata
|
|
194
|
-
var getMetadata = function (state) {
|
|
195
|
-
return state.threekit.metadata;
|
|
196
|
-
};
|
|
197
|
-
exports.getMetadata = getMetadata;
|
|
198
|
-
// Languages and Translations
|
|
199
|
-
var getLanguage = function (state) {
|
|
200
|
-
return state.threekit.language;
|
|
201
|
-
};
|
|
202
|
-
exports.getLanguage = getLanguage;
|
|
203
|
-
var getLanguageOptions = function (state) {
|
|
204
|
-
if (!state.threekit.isThreekitLoaded || !state.threekit.translations)
|
|
205
|
-
return [];
|
|
206
|
-
return Object.keys(Object.values(state.threekit.translations)[0]);
|
|
207
|
-
};
|
|
208
|
-
exports.getLanguageOptions = getLanguageOptions;
|
|
209
|
-
// Attributes
|
|
210
|
-
var getAttributes = function (state) {
|
|
211
|
-
var _a = state.threekit, isThreekitLoaded = _a.isThreekitLoaded, attributes = _a.attributes, language = _a.language, translations = _a.translations;
|
|
212
|
-
if (!isThreekitLoaded)
|
|
213
|
-
return undefined;
|
|
214
|
-
if (!attributes)
|
|
215
|
-
return undefined;
|
|
216
|
-
var hasTranslation = !!language && !!translations;
|
|
217
|
-
return attributes.reduce(function (output, attribute) {
|
|
218
|
-
var _a;
|
|
219
|
-
var _b;
|
|
220
|
-
return Object.assign(output, (_a = {},
|
|
221
|
-
_a[attribute.name] = Object.assign({}, attribute, {
|
|
222
|
-
label: hasTranslation
|
|
223
|
-
? ((_b = translations === null || translations === void 0 ? void 0 : translations[attribute.name]) === null || _b === void 0 ? void 0 : _b[language]) || attribute.name
|
|
224
|
-
: attribute.name,
|
|
225
|
-
}, attribute.type === 'String'
|
|
226
|
-
? {
|
|
227
|
-
values: attribute.values.map(function (el) {
|
|
228
|
-
var _a;
|
|
229
|
-
return Object.assign({}, el, {
|
|
230
|
-
label: hasTranslation
|
|
231
|
-
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
|
|
232
|
-
: el.label,
|
|
233
|
-
});
|
|
234
|
-
}),
|
|
235
|
-
}
|
|
236
|
-
: attribute.type === 'Asset'
|
|
237
|
-
? {
|
|
238
|
-
values: attribute.values.map(function (el) {
|
|
239
|
-
var _a;
|
|
240
|
-
return Object.assign({}, el, {
|
|
241
|
-
label: hasTranslation
|
|
242
|
-
? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
|
|
243
|
-
: el.name,
|
|
244
|
-
});
|
|
245
|
-
}),
|
|
246
|
-
}
|
|
247
|
-
: undefined),
|
|
248
|
-
_a));
|
|
249
|
-
}, {});
|
|
250
|
-
};
|
|
251
|
-
exports.getAttributes = getAttributes;
|
|
252
|
-
// Wishlist
|
|
253
|
-
var getWishlist = function (state) { return state.threekit.wishlist; };
|
|
254
|
-
exports.getWishlist = getWishlist;
|
|
255
|
-
/*****************************************************
|
|
256
|
-
* Complex Selectors
|
|
257
|
-
****************************************************/
|
|
258
|
-
// Attributes
|
|
259
|
-
// export const getAttribute = (attribute: string) =>
|
|
260
|
-
// createSelector(
|
|
261
|
-
// getAttributes,
|
|
262
|
-
// (attributes) => attributes?.[attribute] || undefined
|
|
263
|
-
// )
|
|
264
|
-
/*****************************************************
|
|
265
|
-
* Complex Actions
|
|
266
|
-
****************************************************/
|
|
267
|
-
var launch = function (launchConfig) {
|
|
268
|
-
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
|
-
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;
|
|
270
|
-
var _c;
|
|
271
|
-
var _d, _e, _f, _g, _h;
|
|
272
|
-
return __generator(this, function (_j) {
|
|
273
|
-
switch (_j.label) {
|
|
274
|
-
case 0:
|
|
275
|
-
if (window.threekit)
|
|
276
|
-
return [2 /*return*/];
|
|
277
|
-
config = (0, utils_1.loadTrebleConfig)();
|
|
278
|
-
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) || {});
|
|
279
|
-
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) || {});
|
|
280
|
-
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
281
|
-
return [2 /*return*/, console.error('Missing credentials')];
|
|
282
|
-
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
283
|
-
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
284
|
-
envCredentials = credentials[threekitEnv];
|
|
285
|
-
product = products[threekitEnv];
|
|
286
|
-
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
287
|
-
orgId = envCredentials.orgId, authToken = envCredentials.publicToken;
|
|
288
|
-
if (typeof product === 'string') {
|
|
289
|
-
if ((0, utils_1.isUuid)(product))
|
|
290
|
-
assetId = product;
|
|
291
|
-
else
|
|
292
|
-
configurationId = product;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
stageId = product.stageId;
|
|
296
|
-
if (product.configurationId)
|
|
297
|
-
configurationId = product.configurationId;
|
|
298
|
-
else if ((0, utils_1.isUuid)(product.assetId))
|
|
299
|
-
assetId = product.assetId;
|
|
300
|
-
else
|
|
301
|
-
configurationId = product.assetId;
|
|
302
|
-
}
|
|
303
|
-
if (playerConfig.elementId) {
|
|
304
|
-
el = document.getElementById(playerConfig.elementId);
|
|
305
|
-
if (el)
|
|
306
|
-
dispatch(setPlayerElement(playerConfig.elementId));
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
el = createPlayerLoaderEl(constants_1.TK_PLAYER_ROOT_DIV);
|
|
310
|
-
dispatch(setPlayerElement(constants_1.TK_PLAYER_ROOT_DIV));
|
|
311
|
-
}
|
|
312
|
-
// Connection
|
|
313
|
-
connection_1.default.connect({
|
|
314
|
-
authToken: authToken,
|
|
315
|
-
orgId: orgId,
|
|
316
|
-
assetId: assetId,
|
|
317
|
-
threekitDomain: threekitDomainRaw,
|
|
318
|
-
});
|
|
319
|
-
threekitDomain = connection_1.default.getConnection().threekitDomain;
|
|
320
|
-
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
321
|
-
updatedAssetId = assetId;
|
|
322
|
-
params = (0, utils_1.getParams)();
|
|
323
|
-
configId = ((_h = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _h === void 0 ? void 0 : _h.length)
|
|
324
|
-
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
325
|
-
: configurationId;
|
|
326
|
-
if (!configId) return [3 /*break*/, 2];
|
|
327
|
-
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
328
|
-
case 1:
|
|
329
|
-
configuration = _j.sent();
|
|
330
|
-
if (configuration) {
|
|
331
|
-
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
332
|
-
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
333
|
-
updatedAssetId = configuration.data.productId;
|
|
334
|
-
}
|
|
335
|
-
_j.label = 2;
|
|
336
|
-
case 2:
|
|
337
|
-
if (!updatedAssetId)
|
|
338
|
-
return [2 /*return*/, console.error('missing assetId')];
|
|
339
|
-
// We create the threekit script
|
|
340
|
-
return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
|
|
341
|
-
case 3:
|
|
342
|
-
// We create the threekit script
|
|
343
|
-
_j.sent();
|
|
344
|
-
return [4 /*yield*/, Promise.all([
|
|
345
|
-
window.threekitPlayer(__assign(__assign({ el: el,
|
|
346
|
-
// Variables to sort out
|
|
347
|
-
authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration })),
|
|
348
|
-
api_1.default.products.fetchTranslations(),
|
|
349
|
-
api_1.default.price.getPricebooksList(),
|
|
350
|
-
])];
|
|
351
|
-
case 4:
|
|
352
|
-
_a = _j.sent(), player = _a[0], translations = _a[1], pricebook = _a[2];
|
|
353
|
-
_b = window;
|
|
354
|
-
_c = {
|
|
355
|
-
player: player
|
|
356
|
-
};
|
|
357
|
-
return [4 /*yield*/, player.getConfigurator()];
|
|
358
|
-
case 5:
|
|
359
|
-
_b.threekit = (_c.configurator = _j.sent(),
|
|
360
|
-
_c.treble = new Treble_1.default({ player: player }),
|
|
361
|
-
_c);
|
|
362
|
-
window.threekit.player.on('setConfiguration', function () {
|
|
363
|
-
dispatch(setAttributes(window.threekit.configurator.getDisplayAttributes()));
|
|
364
|
-
});
|
|
365
|
-
if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale) {
|
|
366
|
-
dispatch(setLanguage(launchConfig.locale));
|
|
367
|
-
dispatch(setTranslations(translations));
|
|
368
|
-
}
|
|
369
|
-
if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers)
|
|
370
|
-
EVENTS = Object.assign(EVENTS, launchConfig.eventHandlers);
|
|
371
|
-
if (pricebook.length) {
|
|
372
|
-
priceConfig = {
|
|
373
|
-
id: pricebook[0].id,
|
|
374
|
-
currency: pricebook[0].currencies[0],
|
|
375
|
-
};
|
|
376
|
-
dispatch(setPriceConfig(priceConfig));
|
|
377
|
-
}
|
|
378
|
-
productName = window.threekit.player.scene.get({
|
|
379
|
-
id: window.threekit.player.assetId,
|
|
380
|
-
}).name;
|
|
381
|
-
dispatch(setName(productName));
|
|
382
|
-
dispatch(setMetadata(window.threekit.configurator.getMetadata()));
|
|
383
|
-
dispatch(setAttributes(window.threekit.configurator.getDisplayAttributes()));
|
|
384
|
-
dispatch((0, exports.setThreekitLoaded)(true));
|
|
385
|
-
dispatch(setPlayerLoading(false));
|
|
386
|
-
return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
|
|
387
|
-
case 6:
|
|
388
|
-
wishlistData = _j.sent();
|
|
389
|
-
dispatch(setWishlist(wishlistData));
|
|
390
|
-
return [2 /*return*/];
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}); };
|
|
394
|
-
};
|
|
395
|
-
exports.launch = launch;
|
|
396
|
-
// Configurator
|
|
397
|
-
var setConfiguration = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
398
|
-
var previousConfiguration, updatedAttributes;
|
|
399
|
-
return __generator(this, function (_a) {
|
|
400
|
-
switch (_a.label) {
|
|
401
|
-
case 0:
|
|
402
|
-
previousConfiguration = window.threekit.configurator.getDisplayAttributes();
|
|
403
|
-
dispatch(setPlayerLoading(true));
|
|
404
|
-
return [4 /*yield*/, window.threekit.configurator.setConfiguration(config)];
|
|
405
|
-
case 1:
|
|
406
|
-
_a.sent();
|
|
407
|
-
updatedAttributes = window.threekit.configurator.getDisplayAttributes();
|
|
408
|
-
if (!EVENTS.postConfigurationChange) return [3 /*break*/, 3];
|
|
409
|
-
return [4 /*yield*/, EVENTS.postConfigurationChange(updatedAttributes, config, previousConfiguration)];
|
|
410
|
-
case 2:
|
|
411
|
-
_a.sent();
|
|
412
|
-
_a.label = 3;
|
|
413
|
-
case 3:
|
|
414
|
-
dispatch(setAttributes(updatedAttributes));
|
|
415
|
-
dispatch(setPlayerLoading(false));
|
|
416
|
-
return [2 /*return*/];
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}); }; };
|
|
420
|
-
exports.setConfiguration = setConfiguration;
|
|
421
|
-
// Wishlst
|
|
422
|
-
var addToWishlist = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
423
|
-
var wishlistData;
|
|
424
|
-
return __generator(this, function (_a) {
|
|
425
|
-
switch (_a.label) {
|
|
426
|
-
case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
|
|
427
|
-
case 1:
|
|
428
|
-
wishlistData = _a.sent();
|
|
429
|
-
dispatch(setWishlist(wishlistData));
|
|
430
|
-
return [2 /*return*/];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
}); }; };
|
|
434
|
-
exports.addToWishlist = addToWishlist;
|
|
435
|
-
var removeFromWishlist = function (idx) { return function (dispatch) {
|
|
436
|
-
var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
|
|
437
|
-
dispatch(setWishlist(wishlistData));
|
|
438
|
-
}; };
|
|
439
|
-
exports.removeFromWishlist = removeFromWishlist;
|
|
440
|
-
var resumeFromWishlist = function (idx) { return function (dispatch, getState) {
|
|
441
|
-
var threekit = getState().threekit;
|
|
442
|
-
var savedConfiguration = threekit.wishlist[idx];
|
|
443
|
-
if (!savedConfiguration)
|
|
444
|
-
return;
|
|
445
|
-
dispatch((0, exports.setConfiguration)(savedConfiguration.variant));
|
|
446
|
-
}; };
|
|
447
|
-
exports.resumeFromWishlist = resumeFromWishlist;
|
|
448
|
-
var clearWishlist = function () { return function (dispatch) {
|
|
449
|
-
var wishlistData = window.threekit.treble.wishlist.clearWishlist();
|
|
450
|
-
dispatch(setWishlist(wishlistData));
|
|
451
|
-
}; };
|
|
452
|
-
exports.clearWishlist = clearWishlist;
|
|
453
|
-
exports.default = reducer;
|