@threekit-tools/treble 0.0.57-animation → 0.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Treble/Snapshots.js +32 -63
- package/dist/Treble/Treble.d.ts +8 -6
- package/dist/Treble/Treble.js +19 -4
- package/dist/Treble/Wishlist.d.ts +3 -3
- package/dist/Treble/Wishlist.js +1 -0
- package/dist/api/configurations.d.ts +2 -3
- package/dist/api/configurations.js +28 -22
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/server.d.ts +2 -0
- package/dist/api/server.js +11 -0
- package/dist/components/Cards/index.js +3 -4
- package/dist/components/Dropdown/index.js +6 -10
- package/dist/components/Strips/index.js +3 -4
- package/dist/components/Swatch/index.js +3 -4
- package/dist/components/TextInput/index.d.ts +1 -0
- package/dist/components/TextInput/index.js +2 -2
- package/dist/components/TextInput/textInput.styles.js +1 -1
- package/dist/components/Tiles/index.js +3 -4
- package/dist/components/TilesGroup/index.js +3 -4
- package/dist/components/containers/formInputContainer.d.ts +8 -4
- package/dist/components/containers/formInputContainer.js +10 -15
- package/dist/connection.d.ts +4 -1
- package/dist/connection.js +4 -0
- package/dist/hooks/useAttribute/index.d.ts +2 -2
- package/dist/hooks/useAttribute/index.js +2 -4
- package/dist/hooks/useConfigurator/index.d.ts +2 -2
- package/dist/hooks/useConfigurator/index.js +1 -1
- package/dist/hooks/useProductCache/index.d.ts +14 -0
- package/dist/hooks/useProductCache/index.js +35 -0
- package/dist/hooks/useWishlist/index.d.ts +3 -2
- package/dist/hooks/useWishlist/index.js +1 -3
- package/dist/http/configurations.d.ts +1 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +2 -0
- package/dist/http/server.d.ts +14 -0
- package/dist/http/server.js +17 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/store/attributes.d.ts +15 -2
- package/dist/store/attributes.js +20 -12
- package/dist/store/price.js +2 -2
- package/dist/store/product.d.ts +38 -2
- package/dist/store/product.js +221 -10
- package/dist/store/translations.d.ts +1 -0
- package/dist/store/translations.js +3 -1
- package/dist/store/treble.d.ts +32 -2
- package/dist/store/treble.js +157 -34
- package/dist/store/wishlist.d.ts +3 -2
- package/dist/threekit.d.ts +16 -1
- package/dist/utils.d.ts +1 -9
- package/dist/utils.js +58 -54
- package/package.json +1 -1
- package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
- package/dist/hooks/useArrayAttribute/index.js +0 -184
package/dist/store/product.js
CHANGED
|
@@ -10,24 +10,62 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
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
|
+
};
|
|
13
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.getMetadata = exports.getName = exports.
|
|
53
|
+
exports.removeProductIdx = exports.changeActiveProductIdx = exports.loadNewProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveProductIdx = exports.getMetadata = exports.getName = exports.decrementActiveProductIdx = exports.incrementActiveProductIdx = exports.setActiveProductIdx = exports.removeProductFromCache = exports.updateActiveProductCache = exports.addProductToCache = exports.setMetadata = exports.setName = exports.PRODUCTS = void 0;
|
|
15
54
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
55
|
+
var connection_1 = __importDefault(require("../connection"));
|
|
56
|
+
var treble_1 = require("./treble");
|
|
16
57
|
/*****************************************************
|
|
17
58
|
* Actions
|
|
18
59
|
****************************************************/
|
|
19
60
|
// Actions to be used only internally
|
|
20
61
|
exports.setName = (0, toolkit_1.createAction)('treble/product/set-name');
|
|
21
62
|
exports.setMetadata = (0, toolkit_1.createAction)('treble/product/set-metadata');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
dispatch((0, exports.setMetadata)(metadata));
|
|
29
|
-
}; };
|
|
30
|
-
exports.initProduct = initProduct;
|
|
63
|
+
exports.addProductToCache = (0, toolkit_1.createAction)('treble/add-product-to-cache');
|
|
64
|
+
exports.updateActiveProductCache = (0, toolkit_1.createAction)('treble/update-active-product-cache');
|
|
65
|
+
exports.removeProductFromCache = (0, toolkit_1.createAction)('treble/remove-product-from-cache');
|
|
66
|
+
exports.setActiveProductIdx = (0, toolkit_1.createAction)('treble/set-active-product-idx');
|
|
67
|
+
exports.incrementActiveProductIdx = (0, toolkit_1.createAction)('treble/increment-active-product-idx');
|
|
68
|
+
exports.decrementActiveProductIdx = (0, toolkit_1.createAction)('treble/decrement-active-product-idx');
|
|
31
69
|
/*****************************************************
|
|
32
70
|
* State
|
|
33
71
|
****************************************************/
|
|
@@ -36,6 +74,9 @@ var initialState = {
|
|
|
36
74
|
name: undefined,
|
|
37
75
|
// Initialized item's metadata
|
|
38
76
|
metadata: undefined,
|
|
77
|
+
// cached products. Does not include the active product
|
|
78
|
+
cachedProducts: [],
|
|
79
|
+
activeProductIdx: 0,
|
|
39
80
|
};
|
|
40
81
|
var reducer = (0, toolkit_1.createSlice)({
|
|
41
82
|
name: 'product',
|
|
@@ -47,6 +88,34 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
47
88
|
builder.addCase(exports.setMetadata, function (state, action) {
|
|
48
89
|
return __assign(__assign({}, state), { metadata: action.payload });
|
|
49
90
|
});
|
|
91
|
+
builder.addCase(exports.addProductToCache, function (state, action) {
|
|
92
|
+
state.cachedProducts.push(action.payload);
|
|
93
|
+
return state;
|
|
94
|
+
});
|
|
95
|
+
builder.addCase(exports.removeProductFromCache, function (state, action) {
|
|
96
|
+
state.cachedProducts.splice(action.payload, 1);
|
|
97
|
+
return state;
|
|
98
|
+
});
|
|
99
|
+
builder.addCase(exports.updateActiveProductCache, function (state, action) {
|
|
100
|
+
state.cachedProducts[state.activeProductIdx] = Object.assign({}, state.cachedProducts[state.activeProductIdx], action.payload);
|
|
101
|
+
return state;
|
|
102
|
+
});
|
|
103
|
+
builder.addCase(exports.setActiveProductIdx, function (state, action) {
|
|
104
|
+
state.activeProductIdx = action.payload;
|
|
105
|
+
return state;
|
|
106
|
+
});
|
|
107
|
+
builder.addCase(exports.incrementActiveProductIdx, function (state) {
|
|
108
|
+
state.activeProductIdx =
|
|
109
|
+
state.activeProductIdx >= state.cachedProducts.length
|
|
110
|
+
? state.activeProductIdx
|
|
111
|
+
: state.activeProductIdx + 1;
|
|
112
|
+
return state;
|
|
113
|
+
});
|
|
114
|
+
builder.addCase(exports.decrementActiveProductIdx, function (state) {
|
|
115
|
+
state.activeProductIdx =
|
|
116
|
+
state.activeProductIdx === 0 ? 0 : state.activeProductIdx - 1;
|
|
117
|
+
return state;
|
|
118
|
+
});
|
|
50
119
|
},
|
|
51
120
|
reducers: {},
|
|
52
121
|
}).reducer;
|
|
@@ -62,4 +131,146 @@ var getMetadata = function (state) {
|
|
|
62
131
|
return state.product.metadata;
|
|
63
132
|
};
|
|
64
133
|
exports.getMetadata = getMetadata;
|
|
134
|
+
// Product Cache
|
|
135
|
+
var getActiveProductIdx = function (state) {
|
|
136
|
+
return state.product.activeProductIdx;
|
|
137
|
+
};
|
|
138
|
+
exports.getActiveProductIdx = getActiveProductIdx;
|
|
139
|
+
var getProductCache = function (state) {
|
|
140
|
+
return state.product.cachedProducts.map(function (prod) {
|
|
141
|
+
return Object.assign({
|
|
142
|
+
name: prod.name,
|
|
143
|
+
}, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
exports.getProductCache = getProductCache;
|
|
147
|
+
/*****************************************************
|
|
148
|
+
* Complex Actions
|
|
149
|
+
****************************************************/
|
|
150
|
+
var initProduct = function (prods) {
|
|
151
|
+
return function (dispatch, getState) {
|
|
152
|
+
if (prods)
|
|
153
|
+
exports.PRODUCTS = prods;
|
|
154
|
+
var state = getState();
|
|
155
|
+
var name = window.threekit.player.scene.get({
|
|
156
|
+
id: window.threekit.player.assetId,
|
|
157
|
+
}).name;
|
|
158
|
+
var metadata = window.threekit.configurator.getMetadata();
|
|
159
|
+
dispatch((0, exports.setName)(name));
|
|
160
|
+
dispatch((0, exports.setMetadata)(metadata));
|
|
161
|
+
if (!state.product.cachedProducts.length) {
|
|
162
|
+
dispatch((0, exports.setActiveProductIdx)(0));
|
|
163
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
exports.initProduct = initProduct;
|
|
168
|
+
var cacheActiveProduct = function (config) {
|
|
169
|
+
return function (dispatch, getState) {
|
|
170
|
+
var state = getState();
|
|
171
|
+
var label = config === null || config === void 0 ? void 0 : config.label;
|
|
172
|
+
var thumbnail = config === null || config === void 0 ? void 0 : config.thumbnail;
|
|
173
|
+
var connectionObj = connection_1.default.getConnection();
|
|
174
|
+
delete connectionObj.threekitDomain;
|
|
175
|
+
var configuration = window.threekit.configurator.getConfiguration();
|
|
176
|
+
var data = { connection: connectionObj, configuration: configuration };
|
|
177
|
+
var product = Object.assign({ name: state.product.name, data: JSON.stringify(data) }, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
|
|
178
|
+
return dispatch((0, exports.updateActiveProductCache)(product));
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
exports.cacheActiveProduct = cacheActiveProduct;
|
|
182
|
+
var loadNewProduct = function (config) {
|
|
183
|
+
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
184
|
+
var label, thumbnail, shouldCacheProduct;
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
switch (_a.label) {
|
|
187
|
+
case 0:
|
|
188
|
+
shouldCacheProduct = true;
|
|
189
|
+
if (typeof config === 'object') {
|
|
190
|
+
label = config.label;
|
|
191
|
+
thumbnail = config.thumbnail;
|
|
192
|
+
if (config.cacheProduct === false)
|
|
193
|
+
shouldCacheProduct = false;
|
|
194
|
+
}
|
|
195
|
+
if (shouldCacheProduct)
|
|
196
|
+
dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
|
|
197
|
+
return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(config))];
|
|
198
|
+
case 1:
|
|
199
|
+
_a.sent();
|
|
200
|
+
if (shouldCacheProduct) {
|
|
201
|
+
dispatch((0, exports.incrementActiveProductIdx)());
|
|
202
|
+
dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
|
|
203
|
+
}
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}); };
|
|
208
|
+
};
|
|
209
|
+
exports.loadNewProduct = loadNewProduct;
|
|
210
|
+
var changeActiveProductIdx = function (idx) {
|
|
211
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
212
|
+
var state, cachedProducts, cachedProduct, data;
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
state = getState();
|
|
217
|
+
cachedProducts = state.product.cachedProducts;
|
|
218
|
+
if (idx >= cachedProducts.length)
|
|
219
|
+
return [2 /*return*/, Promise.resolve()];
|
|
220
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
221
|
+
cachedProduct = __assign({}, state.product.cachedProducts[idx]);
|
|
222
|
+
data = JSON.parse(cachedProduct.data);
|
|
223
|
+
connection_1.default.connect(data.connection);
|
|
224
|
+
dispatch((0, exports.setActiveProductIdx)(idx));
|
|
225
|
+
return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)({
|
|
226
|
+
assetId: data.connection.assetId,
|
|
227
|
+
configuration: data.configuration,
|
|
228
|
+
}))];
|
|
229
|
+
case 1:
|
|
230
|
+
_a.sent();
|
|
231
|
+
return [2 /*return*/];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}); };
|
|
235
|
+
};
|
|
236
|
+
exports.changeActiveProductIdx = changeActiveProductIdx;
|
|
237
|
+
var removeProductIdx = function (idx) {
|
|
238
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
239
|
+
var state, _a, cachedProducts, activeProductIdx;
|
|
240
|
+
return __generator(this, function (_b) {
|
|
241
|
+
switch (_b.label) {
|
|
242
|
+
case 0:
|
|
243
|
+
state = getState();
|
|
244
|
+
_a = state.product, cachedProducts = _a.cachedProducts, activeProductIdx = _a.activeProductIdx;
|
|
245
|
+
if (cachedProducts.length <= 1)
|
|
246
|
+
return [2 /*return*/, Promise.resolve()];
|
|
247
|
+
if (!(!idx || idx === activeProductIdx)) return [3 /*break*/, 5];
|
|
248
|
+
if (!(activeProductIdx === state.product.cachedProducts.length - 1)) return [3 /*break*/, 2];
|
|
249
|
+
return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx - 1))];
|
|
250
|
+
case 1:
|
|
251
|
+
_b.sent();
|
|
252
|
+
dispatch((0, exports.removeProductFromCache)(activeProductIdx));
|
|
253
|
+
return [3 /*break*/, 4];
|
|
254
|
+
case 2:
|
|
255
|
+
dispatch((0, exports.removeProductFromCache)(activeProductIdx));
|
|
256
|
+
return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx))];
|
|
257
|
+
case 3:
|
|
258
|
+
_b.sent();
|
|
259
|
+
_b.label = 4;
|
|
260
|
+
case 4: return [3 /*break*/, 6];
|
|
261
|
+
case 5:
|
|
262
|
+
if (idx >= activeProductIdx) {
|
|
263
|
+
dispatch((0, exports.removeProductFromCache)(idx));
|
|
264
|
+
}
|
|
265
|
+
else if (idx <= activeProductIdx) {
|
|
266
|
+
dispatch((0, exports.decrementActiveProductIdx)());
|
|
267
|
+
dispatch((0, exports.removeProductFromCache)(idx));
|
|
268
|
+
}
|
|
269
|
+
_b.label = 6;
|
|
270
|
+
case 6: return [2 /*return*/, Promise.resolve()];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}); };
|
|
274
|
+
};
|
|
275
|
+
exports.removeProductIdx = removeProductIdx;
|
|
65
276
|
exports.default = reducer;
|
|
@@ -18,5 +18,6 @@ declare const reducer: import("redux").Reducer<TranslationsState, import("redux"
|
|
|
18
18
|
* Standard Selectors
|
|
19
19
|
****************************************************/
|
|
20
20
|
export declare const getLanguage: (state: RootState) => undefined | string;
|
|
21
|
+
export declare const getTranslations: (state: RootState) => undefined | ITranslationMap;
|
|
21
22
|
export declare const getLanguageOptions: (state: RootState) => Array<string>;
|
|
22
23
|
export default reducer;
|
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
|
|
42
|
+
exports.getLanguageOptions = exports.getTranslations = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
|
|
43
43
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
44
44
|
var api_1 = __importDefault(require("../api"));
|
|
45
45
|
/*****************************************************
|
|
@@ -91,6 +91,8 @@ var getLanguage = function (state) {
|
|
|
91
91
|
return state.translations.language;
|
|
92
92
|
};
|
|
93
93
|
exports.getLanguage = getLanguage;
|
|
94
|
+
var getTranslations = function (state) { return state.translations.translations; };
|
|
95
|
+
exports.getTranslations = getTranslations;
|
|
94
96
|
var getLanguageOptions = function (state) {
|
|
95
97
|
if (!state.treble.isThreekitInitialized || !state.translations.translations)
|
|
96
98
|
return [];
|
package/dist/store/treble.d.ts
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
-
import { IProject, IPlayerConfig, IThreekitDisplayAttribute, ISetConfiguration } from '../threekit';
|
|
2
|
+
import { IProject, IPlayerConfig, IThreekitDisplayAttribute, ISetConfiguration, IConfiguration } from '../threekit';
|
|
3
3
|
/*****************************************************
|
|
4
4
|
* Types and Interfaces
|
|
5
5
|
****************************************************/
|
|
6
|
+
export interface IPlayerInit {
|
|
7
|
+
el: HTMLElement;
|
|
8
|
+
authToken: string;
|
|
9
|
+
assetId: string;
|
|
10
|
+
stageId?: string;
|
|
11
|
+
orgId: string;
|
|
12
|
+
playerConfig: IPlayerConfig;
|
|
13
|
+
initialConfiguration?: IConfiguration;
|
|
14
|
+
}
|
|
6
15
|
export interface ILaunchConfig {
|
|
7
16
|
threekitEnv: string;
|
|
17
|
+
serverUrl: string;
|
|
8
18
|
locale: string;
|
|
9
19
|
project: IProject;
|
|
10
20
|
playerConfig: IPlayerConfig;
|
|
11
21
|
eventHandlers: EventHandlers;
|
|
12
22
|
}
|
|
23
|
+
export interface IReloadConfig {
|
|
24
|
+
label?: string;
|
|
25
|
+
thumbnail?: string;
|
|
26
|
+
configuration?: IConfiguration;
|
|
27
|
+
assetId?: string;
|
|
28
|
+
stageId?: string;
|
|
29
|
+
configurationId?: string;
|
|
30
|
+
cacheProduct?: boolean;
|
|
31
|
+
}
|
|
13
32
|
export interface TrebleState {
|
|
14
33
|
isPlayerLoading: boolean;
|
|
15
34
|
isThreekitInitialized: boolean;
|
|
16
35
|
playerElId: undefined | string;
|
|
36
|
+
notifications: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface NotificationEvent extends Event {
|
|
39
|
+
detail: {
|
|
40
|
+
message: string;
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
17
43
|
}
|
|
18
44
|
interface EventHandlers {
|
|
19
45
|
postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
|
|
@@ -21,9 +47,10 @@ interface EventHandlers {
|
|
|
21
47
|
/*****************************************************
|
|
22
48
|
* Actions
|
|
23
49
|
****************************************************/
|
|
24
|
-
export declare const setThreekitInitialized: import("@reduxjs/toolkit").
|
|
50
|
+
export declare const setThreekitInitialized: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
25
51
|
export declare const setPlayerLoading: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
26
52
|
export declare const setPlayerElement: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
53
|
+
export declare const reloadTreble: import("@reduxjs/toolkit").ActionCreatorWithPayload<Partial<TrebleState>, string>;
|
|
27
54
|
/*****************************************************
|
|
28
55
|
* Slice
|
|
29
56
|
****************************************************/
|
|
@@ -37,5 +64,8 @@ export declare const getPlayerElementId: (state: RootState) => undefined | strin
|
|
|
37
64
|
/*****************************************************
|
|
38
65
|
* Complex Actions
|
|
39
66
|
****************************************************/
|
|
67
|
+
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
40
68
|
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
69
|
+
export declare const unloadPlayer: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
70
|
+
export declare const reloadPlayer: (config: undefined | string | Pick<IReloadConfig, 'assetId' | 'stageId' | 'configurationId' | 'configuration'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
41
71
|
export default reducer;
|
package/dist/store/treble.js
CHANGED
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.launch = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = void 0;
|
|
53
|
+
exports.reloadPlayer = exports.unloadPlayer = exports.launch = exports.initPlayer = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = exports.reloadTreble = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = void 0;
|
|
54
54
|
var connection_1 = __importDefault(require("../connection"));
|
|
55
55
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
56
56
|
var api_1 = __importDefault(require("../api"));
|
|
@@ -62,6 +62,7 @@ var price_1 = require("./price");
|
|
|
62
62
|
var wishlist_1 = require("./wishlist");
|
|
63
63
|
var translations_1 = require("./translations");
|
|
64
64
|
var product_1 = require("./product");
|
|
65
|
+
var message_1 = __importDefault(require("../components/message"));
|
|
65
66
|
/*****************************************************
|
|
66
67
|
* Helper Functions
|
|
67
68
|
****************************************************/
|
|
@@ -100,6 +101,7 @@ var initialState = {
|
|
|
100
101
|
isThreekitInitialized: false,
|
|
101
102
|
isPlayerLoading: false,
|
|
102
103
|
playerElId: undefined,
|
|
104
|
+
notifications: true,
|
|
103
105
|
};
|
|
104
106
|
/*****************************************************
|
|
105
107
|
* Actions
|
|
@@ -107,6 +109,7 @@ var initialState = {
|
|
|
107
109
|
exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
|
|
108
110
|
exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
|
|
109
111
|
exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
|
|
112
|
+
exports.reloadTreble = (0, toolkit_1.createAction)('treble/reload');
|
|
110
113
|
/*****************************************************
|
|
111
114
|
* Slice
|
|
112
115
|
****************************************************/
|
|
@@ -115,14 +118,20 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
115
118
|
initialState: initialState,
|
|
116
119
|
reducers: {},
|
|
117
120
|
extraReducers: function (builder) {
|
|
118
|
-
builder.addCase(exports.setThreekitInitialized, function (state,
|
|
119
|
-
state.isThreekitInitialized =
|
|
121
|
+
builder.addCase(exports.setThreekitInitialized, function (state, action) {
|
|
122
|
+
state.isThreekitInitialized = action.payload;
|
|
123
|
+
return state;
|
|
120
124
|
});
|
|
121
125
|
builder.addCase(exports.setPlayerLoading, function (state, action) {
|
|
122
126
|
state.isPlayerLoading = action.payload;
|
|
127
|
+
return state;
|
|
123
128
|
});
|
|
124
129
|
builder.addCase(exports.setPlayerElement, function (state, action) {
|
|
125
130
|
state.playerElId = action.payload;
|
|
131
|
+
return state;
|
|
132
|
+
});
|
|
133
|
+
builder.addCase(exports.reloadTreble, function (state, action) {
|
|
134
|
+
return __assign(__assign({}, state), action.payload);
|
|
126
135
|
});
|
|
127
136
|
},
|
|
128
137
|
}).reducer;
|
|
@@ -146,12 +155,52 @@ exports.getPlayerElementId = getPlayerElementId;
|
|
|
146
155
|
/*****************************************************
|
|
147
156
|
* Complex Actions
|
|
148
157
|
****************************************************/
|
|
158
|
+
var initPlayer = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
159
|
+
var el, authToken, assetId, stageId, orgId, playerConfig, initialConfiguration, player, configurator;
|
|
160
|
+
return __generator(this, function (_a) {
|
|
161
|
+
switch (_a.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
el = config.el, authToken = config.authToken, assetId = config.assetId, stageId = config.stageId, orgId = config.orgId, playerConfig = config.playerConfig, initialConfiguration = config.initialConfiguration;
|
|
164
|
+
return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
|
|
165
|
+
// Variables to sort out
|
|
166
|
+
authToken: authToken, stageId: stageId, assetId: assetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
167
|
+
case 1:
|
|
168
|
+
player = _a.sent();
|
|
169
|
+
return [4 /*yield*/, player.getConfigurator()];
|
|
170
|
+
case 2:
|
|
171
|
+
configurator = _a.sent();
|
|
172
|
+
if (window.threekit) {
|
|
173
|
+
window.threekit = Object.assign(window.threekit, {
|
|
174
|
+
player: player,
|
|
175
|
+
configurator: configurator,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
window.threekit = {
|
|
180
|
+
player: player,
|
|
181
|
+
configurator: configurator,
|
|
182
|
+
treble: new Treble_1.default({
|
|
183
|
+
player: player,
|
|
184
|
+
orgId: orgId,
|
|
185
|
+
initialConfiguration: configurator.getConfiguration(),
|
|
186
|
+
}),
|
|
187
|
+
};
|
|
188
|
+
dispatch((0, exports.setThreekitInitialized)(true));
|
|
189
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
190
|
+
window.threekit.player.on('setConfiguration', function () {
|
|
191
|
+
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
192
|
+
});
|
|
193
|
+
return [2 /*return*/];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}); }; };
|
|
197
|
+
exports.initPlayer = initPlayer;
|
|
149
198
|
var launch = function (launchConfig) {
|
|
150
199
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
-
var config, credentials, products, threekitEnv, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration
|
|
152
|
-
var _a, _b, _c, _d, _e;
|
|
153
|
-
return __generator(this, function (
|
|
154
|
-
switch (
|
|
200
|
+
var config, credentials, products, threekitEnv, serverUrl, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
201
|
+
var _a, _b, _c, _d, _e, _f;
|
|
202
|
+
return __generator(this, function (_g) {
|
|
203
|
+
switch (_g.label) {
|
|
155
204
|
case 0:
|
|
156
205
|
if (window.threekit)
|
|
157
206
|
return [2 /*return*/];
|
|
@@ -161,6 +210,8 @@ var launch = function (launchConfig) {
|
|
|
161
210
|
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
162
211
|
return [2 /*return*/, console.error('Missing credentials')];
|
|
163
212
|
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
213
|
+
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((_e = config === null || config === void 0 ? void 0 : config.project) === null || _e === void 0 ? void 0 : _e.serverUrl);
|
|
214
|
+
(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
164
215
|
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
165
216
|
envCredentials = credentials[threekitEnv];
|
|
166
217
|
product = products[threekitEnv];
|
|
@@ -196,59 +247,58 @@ var launch = function (launchConfig) {
|
|
|
196
247
|
orgId: orgId,
|
|
197
248
|
assetId: assetId,
|
|
198
249
|
threekitDomain: threekitDomainRaw,
|
|
250
|
+
serverUrl: serverUrl,
|
|
199
251
|
});
|
|
200
252
|
threekitDomain = connection_1.default.getConnection().threekitDomain;
|
|
201
253
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
202
254
|
updatedAssetId = assetId;
|
|
203
255
|
params = (0, utils_1.getParams)();
|
|
204
|
-
configId = ((
|
|
256
|
+
configId = ((_f = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _f === void 0 ? void 0 : _f.length)
|
|
205
257
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
206
258
|
: configurationId;
|
|
207
259
|
if (!configId) return [3 /*break*/, 2];
|
|
208
260
|
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
209
261
|
case 1:
|
|
210
|
-
configuration =
|
|
262
|
+
configuration = _g.sent();
|
|
211
263
|
if (configuration) {
|
|
212
264
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
213
265
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
214
266
|
updatedAssetId = configuration.data.productId;
|
|
215
267
|
}
|
|
216
|
-
|
|
268
|
+
_g.label = 2;
|
|
217
269
|
case 2:
|
|
218
270
|
if (!updatedAssetId)
|
|
219
271
|
return [2 /*return*/, console.error('missing assetId')];
|
|
220
272
|
// We create the threekit script
|
|
221
|
-
return [4 /*yield*/, (
|
|
273
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
274
|
+
var script = document.createElement('script');
|
|
275
|
+
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
276
|
+
script.id = 'threekit-player-bundle';
|
|
277
|
+
script.onload = function () { return resolve(); };
|
|
278
|
+
document.head.appendChild(script);
|
|
279
|
+
})];
|
|
222
280
|
case 3:
|
|
223
281
|
// We create the threekit script
|
|
224
|
-
|
|
225
|
-
return [4 /*yield*/,
|
|
226
|
-
|
|
227
|
-
authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
228
|
-
case 4:
|
|
229
|
-
player = _f.sent();
|
|
230
|
-
return [4 /*yield*/, player.getConfigurator()];
|
|
231
|
-
case 5:
|
|
232
|
-
configurator = _f.sent();
|
|
233
|
-
window.threekit = {
|
|
234
|
-
player: player,
|
|
235
|
-
configurator: configurator,
|
|
236
|
-
treble: new Treble_1.default({
|
|
237
|
-
player: player,
|
|
282
|
+
_g.sent();
|
|
283
|
+
return [4 /*yield*/, dispatch((0, exports.initPlayer)({
|
|
284
|
+
el: el,
|
|
238
285
|
orgId: orgId,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
286
|
+
authToken: authToken,
|
|
287
|
+
stageId: stageId,
|
|
288
|
+
assetId: updatedAssetId,
|
|
289
|
+
playerConfig: playerConfig,
|
|
290
|
+
initialConfiguration: initialConfiguration,
|
|
291
|
+
}))];
|
|
292
|
+
case 4:
|
|
293
|
+
_g.sent();
|
|
294
|
+
document.addEventListener('treble:notification', function (e) {
|
|
295
|
+
message_1.default.info(e.detail.message);
|
|
247
296
|
});
|
|
248
297
|
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
249
298
|
dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
|
|
250
299
|
dispatch((0, price_1.initPrice)());
|
|
251
|
-
dispatch((0,
|
|
300
|
+
dispatch((0, price_1.updatePrice)());
|
|
301
|
+
dispatch((0, product_1.initProduct)(products));
|
|
252
302
|
dispatch((0, wishlist_1.refreshWishlist)());
|
|
253
303
|
return [2 /*return*/];
|
|
254
304
|
}
|
|
@@ -256,4 +306,77 @@ var launch = function (launchConfig) {
|
|
|
256
306
|
}); };
|
|
257
307
|
};
|
|
258
308
|
exports.launch = launch;
|
|
309
|
+
var unloadPlayer = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
310
|
+
return __generator(this, function (_a) {
|
|
311
|
+
switch (_a.label) {
|
|
312
|
+
case 0:
|
|
313
|
+
dispatch((0, exports.setThreekitInitialized)(true));
|
|
314
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
315
|
+
dispatch((0, attributes_1.setAttributes)([]));
|
|
316
|
+
dispatch((0, product_1.setName)(''));
|
|
317
|
+
dispatch((0, product_1.setMetadata)({}));
|
|
318
|
+
return [4 /*yield*/, window.threekit.player.unload()];
|
|
319
|
+
case 1:
|
|
320
|
+
_a.sent();
|
|
321
|
+
return [2 /*return*/];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}); }; };
|
|
325
|
+
exports.unloadPlayer = unloadPlayer;
|
|
326
|
+
var reloadPlayer = function (config) {
|
|
327
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
328
|
+
var connectionObj, assetId, stageId, initialConfiguration, configuration, state, trebleConfig, playerConfig, el;
|
|
329
|
+
return __generator(this, function (_a) {
|
|
330
|
+
switch (_a.label) {
|
|
331
|
+
case 0:
|
|
332
|
+
connectionObj = connection_1.default.getConnection();
|
|
333
|
+
if (!(config === undefined)) return [3 /*break*/, 1];
|
|
334
|
+
assetId = connectionObj.assetId;
|
|
335
|
+
return [3 /*break*/, 4];
|
|
336
|
+
case 1:
|
|
337
|
+
if (!(typeof config === 'string')) return [3 /*break*/, 2];
|
|
338
|
+
assetId = config;
|
|
339
|
+
return [3 /*break*/, 4];
|
|
340
|
+
case 2:
|
|
341
|
+
assetId = (config === null || config === void 0 ? void 0 : config.assetId) || connectionObj.assetId;
|
|
342
|
+
stageId = config === null || config === void 0 ? void 0 : config.stageId;
|
|
343
|
+
initialConfiguration = (config === null || config === void 0 ? void 0 : config.configuration) || {};
|
|
344
|
+
if (!(config === null || config === void 0 ? void 0 : config.configurationId)) return [3 /*break*/, 4];
|
|
345
|
+
return [4 /*yield*/, api_1.default.configurations.fetch(config === null || config === void 0 ? void 0 : config.configurationId)];
|
|
346
|
+
case 3:
|
|
347
|
+
configuration = _a.sent();
|
|
348
|
+
if (configuration) {
|
|
349
|
+
initialConfiguration = Object.assign({}, initialConfiguration, configuration.data.variant);
|
|
350
|
+
assetId = configuration.data.productId;
|
|
351
|
+
}
|
|
352
|
+
_a.label = 4;
|
|
353
|
+
case 4:
|
|
354
|
+
// Update connection
|
|
355
|
+
if (assetId !== connectionObj.assetId)
|
|
356
|
+
connection_1.default.connect({ assetId: assetId });
|
|
357
|
+
state = getState();
|
|
358
|
+
trebleConfig = (0, utils_1.loadTrebleConfig)();
|
|
359
|
+
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, trebleConfig.player);
|
|
360
|
+
el = document.getElementById(state.treble.playerElId);
|
|
361
|
+
if (state.treble.isThreekitInitialized)
|
|
362
|
+
dispatch((0, exports.unloadPlayer)());
|
|
363
|
+
return [4 /*yield*/, dispatch((0, exports.initPlayer)({
|
|
364
|
+
el: el,
|
|
365
|
+
orgId: connectionObj.orgId,
|
|
366
|
+
authToken: connectionObj.authToken,
|
|
367
|
+
stageId: stageId,
|
|
368
|
+
assetId: assetId,
|
|
369
|
+
playerConfig: playerConfig,
|
|
370
|
+
initialConfiguration: initialConfiguration,
|
|
371
|
+
}))];
|
|
372
|
+
case 5:
|
|
373
|
+
_a.sent();
|
|
374
|
+
dispatch((0, price_1.updatePrice)());
|
|
375
|
+
dispatch((0, product_1.initProduct)());
|
|
376
|
+
return [2 /*return*/];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}); };
|
|
380
|
+
};
|
|
381
|
+
exports.reloadPlayer = reloadPlayer;
|
|
259
382
|
exports.default = reducer;
|
package/dist/store/wishlist.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
-
import {
|
|
2
|
+
import { WishlistArray } from '../Treble';
|
|
3
|
+
import { ISaveConfiguration } from '../api/configurations';
|
|
3
4
|
/*****************************************************
|
|
4
5
|
* Types and Interfaces
|
|
5
6
|
****************************************************/
|
|
@@ -8,7 +9,7 @@ export declare type WishlistState = WishlistArray;
|
|
|
8
9
|
* Standard Selectors
|
|
9
10
|
****************************************************/
|
|
10
11
|
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[],
|
|
12
|
+
export declare const addToWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], Omit<ISaveConfiguration, "configurator">, {}>;
|
|
12
13
|
export declare const clearWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/clear", never, never>;
|
|
13
14
|
export declare const removeFromWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[idx: number], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/remove-item", never, never>;
|
|
14
15
|
/*****************************************************
|