@threekit-tools/treble 0.0.46 → 0.0.50
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 +2 -1
- package/dist/Treble/Treble.js +2 -2
- package/dist/Treble/Wishlist.d.ts +3 -2
- package/dist/Treble/Wishlist.js +12 -12
- package/dist/components/Accordion/index.d.ts +1 -1
- package/dist/components/Player/index.js +5 -3
- package/dist/components/Tabs/index.d.ts +4 -7
- package/dist/components/ThreekitProvider/index.d.ts +3 -1
- package/dist/components/ThreekitProvider/index.js +3 -3
- package/dist/components/TrebleApp/index.js +2 -2
- package/dist/components/containers/formInputContainer.d.ts +1 -1
- package/dist/hooks/useAttribute/index.js +3 -3
- 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.js +8 -7
- package/dist/store/attributes.d.ts +20 -0
- package/dist/store/attributes.js +135 -0
- package/dist/store/index.d.ts +67 -7
- package/dist/store/index.js +36 -4
- package/dist/store/price.d.ts +32 -0
- package/dist/store/price.js +56 -0
- package/dist/store/product.d.ts +21 -0
- package/dist/store/product.js +46 -0
- package/dist/store/translations.d.ts +21 -0
- package/dist/store/translations.js +46 -0
- package/dist/store/treble.d.ts +41 -0
- package/dist/store/{threekit.js → treble.js} +53 -224
- package/dist/store/wishlist.d.ts +24 -0
- package/dist/store/wishlist.js +101 -0
- package/dist/threekit.d.ts +1 -1
- package/package.json +1 -1
- package/dist/store/threekit.d.ts +0 -68
|
@@ -50,13 +50,18 @@ 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.
|
|
53
|
+
exports.launch = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = 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"));
|
|
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
|
+
var attributes_1 = require("./attributes");
|
|
62
|
+
var price_1 = require("./price");
|
|
63
|
+
var wishlist_1 = require("./wishlist");
|
|
64
|
+
var product_1 = require("./product");
|
|
60
65
|
/*****************************************************
|
|
61
66
|
* Helper Functions
|
|
62
67
|
****************************************************/
|
|
@@ -88,179 +93,56 @@ var createPlayerLoaderEl = function (elementId) {
|
|
|
88
93
|
* Constants and Event Handlers
|
|
89
94
|
****************************************************/
|
|
90
95
|
var EVENTS = {};
|
|
96
|
+
/*****************************************************
|
|
97
|
+
* State
|
|
98
|
+
****************************************************/
|
|
91
99
|
var initialState = {
|
|
92
|
-
|
|
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
|
|
100
|
+
isThreekitInitialized: false,
|
|
106
101
|
isPlayerLoading: false,
|
|
107
|
-
|
|
108
|
-
attributes: undefined,
|
|
109
|
-
wishlist: [],
|
|
102
|
+
playerElId: undefined,
|
|
110
103
|
};
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
/*****************************************************
|
|
105
|
+
* Actions
|
|
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');
|
|
110
|
+
/*****************************************************
|
|
111
|
+
* Slice
|
|
112
|
+
****************************************************/
|
|
113
|
+
var reducer = (0, toolkit_1.createSlice)({
|
|
114
|
+
name: 'treble',
|
|
113
115
|
initialState: initialState,
|
|
114
|
-
reducers: {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
state.
|
|
118
|
-
}
|
|
119
|
-
setPlayerLoading
|
|
116
|
+
reducers: {},
|
|
117
|
+
extraReducers: function (builder) {
|
|
118
|
+
builder.addCase(exports.setThreekitInitialized, function (state, _) {
|
|
119
|
+
state.isThreekitInitialized = true;
|
|
120
|
+
});
|
|
121
|
+
builder.addCase(exports.setPlayerLoading, function (state, action) {
|
|
120
122
|
state.isPlayerLoading = action.payload;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setPlayerElement: function (state, action) {
|
|
123
|
+
});
|
|
124
|
+
builder.addCase(exports.setPlayerElement, function (state, action) {
|
|
124
125
|
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
|
-
},
|
|
126
|
+
});
|
|
153
127
|
},
|
|
154
|
-
})
|
|
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;
|
|
128
|
+
}).reducer;
|
|
162
129
|
/*****************************************************
|
|
163
130
|
* Standard Selectors
|
|
164
131
|
****************************************************/
|
|
165
132
|
// Loading Trackers
|
|
166
|
-
var
|
|
167
|
-
return state.
|
|
133
|
+
var isThreekitInitialized = function (state) {
|
|
134
|
+
return state.treble.isThreekitInitialized;
|
|
168
135
|
};
|
|
169
|
-
exports.
|
|
136
|
+
exports.isThreekitInitialized = isThreekitInitialized;
|
|
170
137
|
var isPlayerLoading = function (state) {
|
|
171
|
-
return state.
|
|
138
|
+
return state.treble.isPlayerLoading;
|
|
172
139
|
};
|
|
173
140
|
exports.isPlayerLoading = isPlayerLoading;
|
|
174
141
|
// Player's HTML element
|
|
175
142
|
var getPlayerElementId = function (state) {
|
|
176
|
-
return state.
|
|
143
|
+
return state.treble.playerElId;
|
|
177
144
|
};
|
|
178
145
|
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
146
|
/*****************************************************
|
|
265
147
|
* Complex Actions
|
|
266
148
|
****************************************************/
|
|
@@ -303,11 +185,11 @@ var launch = function (launchConfig) {
|
|
|
303
185
|
if (playerConfig.elementId) {
|
|
304
186
|
el = document.getElementById(playerConfig.elementId);
|
|
305
187
|
if (el)
|
|
306
|
-
dispatch(setPlayerElement(playerConfig.elementId));
|
|
188
|
+
dispatch((0, exports.setPlayerElement)(playerConfig.elementId));
|
|
307
189
|
}
|
|
308
190
|
else {
|
|
309
191
|
el = createPlayerLoaderEl(constants_1.TK_PLAYER_ROOT_DIV);
|
|
310
|
-
dispatch(setPlayerElement(constants_1.TK_PLAYER_ROOT_DIV));
|
|
192
|
+
dispatch((0, exports.setPlayerElement)(constants_1.TK_PLAYER_ROOT_DIV));
|
|
311
193
|
}
|
|
312
194
|
// Connection
|
|
313
195
|
connection_1.default.connect({
|
|
@@ -357,11 +239,16 @@ var launch = function (launchConfig) {
|
|
|
357
239
|
return [4 /*yield*/, player.getConfigurator()];
|
|
358
240
|
case 5:
|
|
359
241
|
_b.threekit = (_c.configurator = _j.sent(),
|
|
360
|
-
_c.treble = new Treble_1.default({ player: player }),
|
|
242
|
+
_c.treble = new Treble_1.default({ player: player, orgId: orgId }),
|
|
361
243
|
_c);
|
|
244
|
+
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
245
|
+
window.threekit.player.on('setConfiguration', function () {
|
|
246
|
+
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
247
|
+
dispatch((0, price_1.updatePrice)());
|
|
248
|
+
});
|
|
362
249
|
if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale) {
|
|
363
|
-
dispatch(setLanguage(launchConfig.locale));
|
|
364
|
-
dispatch(setTranslations(translations));
|
|
250
|
+
dispatch((0, translations_1.setLanguage)(launchConfig.locale));
|
|
251
|
+
dispatch((0, translations_1.setTranslations)(translations));
|
|
365
252
|
}
|
|
366
253
|
if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers)
|
|
367
254
|
EVENTS = Object.assign(EVENTS, launchConfig.eventHandlers);
|
|
@@ -370,81 +257,23 @@ var launch = function (launchConfig) {
|
|
|
370
257
|
id: pricebook[0].id,
|
|
371
258
|
currency: pricebook[0].currencies[0],
|
|
372
259
|
};
|
|
373
|
-
dispatch(setPriceConfig(priceConfig));
|
|
260
|
+
dispatch((0, price_1.setPriceConfig)(priceConfig));
|
|
374
261
|
}
|
|
375
262
|
productName = window.threekit.player.scene.get({
|
|
376
263
|
id: window.threekit.player.assetId,
|
|
377
264
|
}).name;
|
|
378
|
-
dispatch(setName(productName));
|
|
379
|
-
dispatch(setMetadata(window.threekit.configurator.getMetadata()));
|
|
380
|
-
dispatch(
|
|
381
|
-
dispatch((0, exports.
|
|
382
|
-
dispatch(setPlayerLoading(false));
|
|
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));
|
|
383
269
|
return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
|
|
384
270
|
case 6:
|
|
385
271
|
wishlistData = _j.sent();
|
|
386
|
-
dispatch(setWishlist(wishlistData));
|
|
272
|
+
dispatch((0, wishlist_1.setWishlist)(wishlistData));
|
|
387
273
|
return [2 /*return*/];
|
|
388
274
|
}
|
|
389
275
|
});
|
|
390
276
|
}); };
|
|
391
277
|
};
|
|
392
278
|
exports.launch = launch;
|
|
393
|
-
// Configurator
|
|
394
|
-
var setConfiguration = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
395
|
-
var previousConfiguration, updatedAttributes;
|
|
396
|
-
return __generator(this, function (_a) {
|
|
397
|
-
switch (_a.label) {
|
|
398
|
-
case 0:
|
|
399
|
-
previousConfiguration = window.threekit.configurator.getDisplayAttributes();
|
|
400
|
-
dispatch(setPlayerLoading(true));
|
|
401
|
-
return [4 /*yield*/, window.threekit.configurator.setConfiguration(config)];
|
|
402
|
-
case 1:
|
|
403
|
-
_a.sent();
|
|
404
|
-
updatedAttributes = window.threekit.configurator.getDisplayAttributes();
|
|
405
|
-
if (!EVENTS.postConfigurationChange) return [3 /*break*/, 3];
|
|
406
|
-
return [4 /*yield*/, EVENTS.postConfigurationChange(updatedAttributes, config, previousConfiguration)];
|
|
407
|
-
case 2:
|
|
408
|
-
_a.sent();
|
|
409
|
-
_a.label = 3;
|
|
410
|
-
case 3:
|
|
411
|
-
dispatch(setAttributes(updatedAttributes));
|
|
412
|
-
dispatch(setPlayerLoading(false));
|
|
413
|
-
return [2 /*return*/];
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
}); }; };
|
|
417
|
-
exports.setConfiguration = setConfiguration;
|
|
418
|
-
// Wishlst
|
|
419
|
-
var addToWishlist = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
420
|
-
var wishlistData;
|
|
421
|
-
return __generator(this, function (_a) {
|
|
422
|
-
switch (_a.label) {
|
|
423
|
-
case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
|
|
424
|
-
case 1:
|
|
425
|
-
wishlistData = _a.sent();
|
|
426
|
-
dispatch(setWishlist(wishlistData));
|
|
427
|
-
return [2 /*return*/];
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}); }; };
|
|
431
|
-
exports.addToWishlist = addToWishlist;
|
|
432
|
-
var removeFromWishlist = function (idx) { return function (dispatch) {
|
|
433
|
-
var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
|
|
434
|
-
dispatch(setWishlist(wishlistData));
|
|
435
|
-
}; };
|
|
436
|
-
exports.removeFromWishlist = removeFromWishlist;
|
|
437
|
-
var resumeFromWishlist = function (idx) { return function (dispatch, getState) {
|
|
438
|
-
var threekit = getState().threekit;
|
|
439
|
-
var savedConfiguration = threekit.wishlist[idx];
|
|
440
|
-
if (!savedConfiguration)
|
|
441
|
-
return;
|
|
442
|
-
dispatch((0, exports.setConfiguration)(savedConfiguration.variant));
|
|
443
|
-
}; };
|
|
444
|
-
exports.resumeFromWishlist = resumeFromWishlist;
|
|
445
|
-
var clearWishlist = function () { return function (dispatch) {
|
|
446
|
-
var wishlistData = window.threekit.treble.wishlist.clearWishlist();
|
|
447
|
-
dispatch(setWishlist(wishlistData));
|
|
448
|
-
}; };
|
|
449
|
-
exports.clearWishlist = clearWishlist;
|
|
450
279
|
exports.default = reducer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
+
import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
|
|
3
|
+
import { IConfigurationResponse } from '../http/configurations';
|
|
4
|
+
/*****************************************************
|
|
5
|
+
* Types and Interfaces
|
|
6
|
+
****************************************************/
|
|
7
|
+
export declare type WishlistState = WishlistArray;
|
|
8
|
+
/*****************************************************
|
|
9
|
+
* Standard Selectors
|
|
10
|
+
****************************************************/
|
|
11
|
+
export declare const setWishlist: import("@reduxjs/toolkit").ActionCreatorWithPayload<IConfigurationResponse[], string>;
|
|
12
|
+
/*****************************************************
|
|
13
|
+
* Slice
|
|
14
|
+
****************************************************/
|
|
15
|
+
declare const reducer: import("redux").Reducer<WishlistArray, import("redux").AnyAction>;
|
|
16
|
+
/*****************************************************
|
|
17
|
+
* Standard Selectors
|
|
18
|
+
****************************************************/
|
|
19
|
+
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;
|
|
24
|
+
export default reducer;
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.clearWishlist = exports.resumeFromWishlist = exports.removeFromWishlist = exports.addToWishlist = exports.getWishlist = exports.setWishlist = void 0;
|
|
40
|
+
var toolkit_1 = require("@reduxjs/toolkit");
|
|
41
|
+
var attributes_1 = require("./attributes");
|
|
42
|
+
/*****************************************************
|
|
43
|
+
* State
|
|
44
|
+
****************************************************/
|
|
45
|
+
var initialState = [];
|
|
46
|
+
/*****************************************************
|
|
47
|
+
* Standard Selectors
|
|
48
|
+
****************************************************/
|
|
49
|
+
exports.setWishlist = (0, toolkit_1.createAction)('setWishlist');
|
|
50
|
+
/*****************************************************
|
|
51
|
+
* Slice
|
|
52
|
+
****************************************************/
|
|
53
|
+
var reducer = (0, toolkit_1.createSlice)({
|
|
54
|
+
name: 'wishlist',
|
|
55
|
+
initialState: initialState,
|
|
56
|
+
reducers: {},
|
|
57
|
+
extraReducers: function (builder) {
|
|
58
|
+
builder.addCase(exports.setWishlist, function (state, action) {
|
|
59
|
+
state = action.payload;
|
|
60
|
+
return state;
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
}).reducer;
|
|
64
|
+
/*****************************************************
|
|
65
|
+
* Standard Selectors
|
|
66
|
+
****************************************************/
|
|
67
|
+
// Wishlist
|
|
68
|
+
var getWishlist = function (state) { return state.wishlist; };
|
|
69
|
+
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) {
|
|
89
|
+
var wishlist = getState().wishlist;
|
|
90
|
+
var savedConfiguration = wishlist[idx];
|
|
91
|
+
if (!savedConfiguration)
|
|
92
|
+
return;
|
|
93
|
+
dispatch((0, attributes_1.setConfiguration)(savedConfiguration.variant));
|
|
94
|
+
}; };
|
|
95
|
+
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
|
+
exports.default = reducer;
|
package/dist/threekit.d.ts
CHANGED
|
@@ -187,7 +187,7 @@ export interface IThreekitPlayer {
|
|
|
187
187
|
tools: IThreekitTools;
|
|
188
188
|
camera: IThreekitCamera;
|
|
189
189
|
setActiveCamera: () => void;
|
|
190
|
-
on: (phase: SCENE_PHASES) => void;
|
|
190
|
+
on: (phase: SCENE_PHASES | string, callback: (args: any) => void) => void;
|
|
191
191
|
getConfigurator: () => Promise<IThreekitConfigurator>;
|
|
192
192
|
enableApi: (api: PRIVATE_APIS) => any;
|
|
193
193
|
snapshotAsync: (snapshotConfig: ISnapshotConfig) => Promise<string>;
|
package/package.json
CHANGED
package/dist/store/threekit.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
-
import { ISetConfiguration, IThreekitDisplayAttribute, IMetadata, IProject, IPlayerConfig } from '../threekit';
|
|
3
|
-
import { ITranslationMap } from '../api/products';
|
|
4
|
-
import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
|
|
5
|
-
/*****************************************************
|
|
6
|
-
* Types and Interfaces
|
|
7
|
-
****************************************************/
|
|
8
|
-
interface EventHandlers {
|
|
9
|
-
postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export interface ILaunchConfig {
|
|
12
|
-
threekitEnv: string;
|
|
13
|
-
locale: string;
|
|
14
|
-
project: IProject;
|
|
15
|
-
playerConfig: IPlayerConfig;
|
|
16
|
-
eventHandlers: EventHandlers;
|
|
17
|
-
}
|
|
18
|
-
interface IPriceConfig {
|
|
19
|
-
id: string;
|
|
20
|
-
currency: string;
|
|
21
|
-
}
|
|
22
|
-
export interface IPrice {
|
|
23
|
-
price: number;
|
|
24
|
-
currency: string;
|
|
25
|
-
}
|
|
26
|
-
/*****************************************************
|
|
27
|
-
* State
|
|
28
|
-
****************************************************/
|
|
29
|
-
export interface ThreekitState {
|
|
30
|
-
playerElId: undefined | string;
|
|
31
|
-
name: undefined | string;
|
|
32
|
-
metadata: undefined | IMetadata;
|
|
33
|
-
translations: undefined | ITranslationMap;
|
|
34
|
-
language: string | undefined;
|
|
35
|
-
priceConfig: IPriceConfig | null;
|
|
36
|
-
isPlayerLoading: boolean;
|
|
37
|
-
isThreekitLoaded: boolean;
|
|
38
|
-
attributes: undefined | Array<IThreekitDisplayAttribute>;
|
|
39
|
-
wishlist: WishlistArray;
|
|
40
|
-
}
|
|
41
|
-
declare const reducer: import("redux").Reducer<ThreekitState, import("redux").AnyAction>;
|
|
42
|
-
export declare const setThreekitLoaded: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
43
|
-
/*****************************************************
|
|
44
|
-
* Standard Selectors
|
|
45
|
-
****************************************************/
|
|
46
|
-
export declare const isThreekitLoaded: (state: RootState) => boolean;
|
|
47
|
-
export declare const isPlayerLoading: (state: RootState) => boolean;
|
|
48
|
-
export declare const getPlayerElementId: (state: RootState) => undefined | string;
|
|
49
|
-
export declare const getName: (state: RootState) => undefined | string;
|
|
50
|
-
export declare const getPrice: (state: RootState) => undefined | IPrice;
|
|
51
|
-
export declare const getMetadata: (state: RootState) => undefined | IMetadata;
|
|
52
|
-
export declare const getLanguage: (state: RootState) => undefined | string;
|
|
53
|
-
export declare const getLanguageOptions: (state: RootState) => Array<string>;
|
|
54
|
-
export declare const getAttributes: (state: RootState) => undefined | Record<string, IThreekitDisplayAttribute>;
|
|
55
|
-
export declare const getWishlist: (state: RootState) => WishlistArray;
|
|
56
|
-
/*****************************************************
|
|
57
|
-
* Complex Selectors
|
|
58
|
-
****************************************************/
|
|
59
|
-
/*****************************************************
|
|
60
|
-
* Complex Actions
|
|
61
|
-
****************************************************/
|
|
62
|
-
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
63
|
-
export declare const setConfiguration: (config: ISetConfiguration) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
64
|
-
export declare const addToWishlist: (config: ISaveConfigurationConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
65
|
-
export declare const removeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch) => void;
|
|
66
|
-
export declare const resumeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
|
|
67
|
-
export declare const clearWishlist: () => (dispatch: ThreekitDispatch) => void;
|
|
68
|
-
export default reducer;
|