@threekit-tools/treble 0.0.58 → 0.0.60-next.2
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/Treble.d.ts +8 -2
- package/dist/Treble/Treble.js +23 -2
- 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/ThreekitProvider/index.d.ts +1 -0
- package/dist/components/ThreekitProvider/index.js +10 -3
- package/dist/components/Tiles/index.js +3 -4
- package/dist/components/TilesGroup/index.js +3 -4
- package/dist/components/TrebleApp/index.d.ts +1 -0
- package/dist/components/TrebleApp/index.js +16 -6
- package/dist/components/Wishlist/index.js +6 -11
- package/dist/components/containers/formInputContainer.d.ts +9 -5
- package/dist/components/containers/formInputContainer.js +14 -19
- 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 +6 -5
- package/dist/hooks/useConfigurator/index.d.ts +2 -2
- package/dist/hooks/useConfigurator/index.js +7 -3
- package/dist/hooks/useNestedConfigurator/index.d.ts +8 -0
- package/dist/hooks/useNestedConfigurator/index.js +93 -0
- package/dist/hooks/useProductCache/index.d.ts +22 -0
- package/dist/hooks/useProductCache/index.js +28 -0
- package/dist/hooks/useWishlist/index.d.ts +8 -6
- package/dist/hooks/useWishlist/index.js +16 -22
- 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 +3 -1
- package/dist/index.js +5 -1
- package/dist/store/attributes.d.ts +14 -1
- package/dist/store/attributes.js +6 -45
- package/dist/store/product.d.ts +47 -2
- package/dist/store/product.js +267 -12
- package/dist/store/translations.d.ts +4 -2
- package/dist/store/translations.js +4 -12
- package/dist/store/treble.d.ts +36 -2
- package/dist/store/treble.js +214 -52
- package/dist/threekit.d.ts +16 -1
- package/dist/utils.d.ts +7 -10
- package/dist/utils.js +22 -23
- 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,49 +10,128 @@ 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.changeActiveCacheIdx = exports.loadNewProduct = exports.loadProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveCacheIdx = exports.getMetadata = exports.getName = exports.getProductId = exports.decrementActiveCacheIdx = exports.incrementActiveCacheIdx = exports.setActiveCacheIdx = exports.removeFromCache = exports.updateActiveProductCache = exports.appendToCache = exports.setMetadata = exports.setName = exports.setProductId = 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
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}; };
|
|
30
|
-
exports.initProduct = initProduct;
|
|
61
|
+
exports.setProductId = (0, toolkit_1.createAction)('treble/set-product-id');
|
|
62
|
+
exports.setName = (0, toolkit_1.createAction)('treble/set-product-name');
|
|
63
|
+
exports.setMetadata = (0, toolkit_1.createAction)('treble/set-metadata');
|
|
64
|
+
exports.appendToCache = (0, toolkit_1.createAction)('treble/append-to-cache');
|
|
65
|
+
exports.updateActiveProductCache = (0, toolkit_1.createAction)('treble/update-active-product-cache');
|
|
66
|
+
exports.removeFromCache = (0, toolkit_1.createAction)('treble/remove-from-cache');
|
|
67
|
+
exports.setActiveCacheIdx = (0, toolkit_1.createAction)('treble/set-active-cache-idx');
|
|
68
|
+
exports.incrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/increment-active-cache-idx');
|
|
69
|
+
exports.decrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/decrement-active-cache-idx');
|
|
31
70
|
/*****************************************************
|
|
32
71
|
* State
|
|
33
72
|
****************************************************/
|
|
34
73
|
var initialState = {
|
|
74
|
+
// ID of initialized item
|
|
75
|
+
id: undefined,
|
|
35
76
|
// Name of the Initialized Item
|
|
36
77
|
name: undefined,
|
|
37
78
|
// Initialized item's metadata
|
|
38
79
|
metadata: undefined,
|
|
80
|
+
// cached products. Does not include the active product
|
|
81
|
+
cache: [],
|
|
82
|
+
activeCacheIdx: 0,
|
|
39
83
|
};
|
|
40
84
|
var reducer = (0, toolkit_1.createSlice)({
|
|
41
85
|
name: 'product',
|
|
42
86
|
initialState: initialState,
|
|
43
87
|
extraReducers: function (builder) {
|
|
88
|
+
builder.addCase(exports.setProductId, function (state, action) {
|
|
89
|
+
return __assign(__assign({}, state), { id: action.payload });
|
|
90
|
+
});
|
|
44
91
|
builder.addCase(exports.setName, function (state, action) {
|
|
45
92
|
return __assign(__assign({}, state), { name: action.payload });
|
|
46
93
|
});
|
|
47
94
|
builder.addCase(exports.setMetadata, function (state, action) {
|
|
48
95
|
return __assign(__assign({}, state), { metadata: action.payload });
|
|
49
96
|
});
|
|
97
|
+
builder.addCase(exports.appendToCache, function (state, action) {
|
|
98
|
+
state.cache.push(action.payload);
|
|
99
|
+
return state;
|
|
100
|
+
});
|
|
101
|
+
builder.addCase(exports.removeFromCache, function (state, action) {
|
|
102
|
+
state.cache.splice(action.payload, 1);
|
|
103
|
+
return state;
|
|
104
|
+
});
|
|
105
|
+
builder.addCase(exports.updateActiveProductCache, function (state, action) {
|
|
106
|
+
state.cache[state.activeCacheIdx] = Object.assign({}, state.cache[state.activeCacheIdx], action.payload);
|
|
107
|
+
return state;
|
|
108
|
+
});
|
|
109
|
+
builder.addCase(exports.setActiveCacheIdx, function (state, action) {
|
|
110
|
+
state.activeCacheIdx = action.payload;
|
|
111
|
+
return state;
|
|
112
|
+
});
|
|
113
|
+
builder.addCase(exports.incrementActiveCacheIdx, function (state) {
|
|
114
|
+
state.activeCacheIdx =
|
|
115
|
+
state.activeCacheIdx >= state.cache.length
|
|
116
|
+
? state.activeCacheIdx
|
|
117
|
+
: state.activeCacheIdx + 1;
|
|
118
|
+
return state;
|
|
119
|
+
});
|
|
120
|
+
builder.addCase(exports.decrementActiveCacheIdx, function (state) {
|
|
121
|
+
state.activeCacheIdx =
|
|
122
|
+
state.activeCacheIdx === 0 ? 0 : state.activeCacheIdx - 1;
|
|
123
|
+
return state;
|
|
124
|
+
});
|
|
50
125
|
},
|
|
51
126
|
reducers: {},
|
|
52
127
|
}).reducer;
|
|
53
128
|
/*****************************************************
|
|
54
129
|
* Standard Selectors
|
|
55
130
|
****************************************************/
|
|
131
|
+
var getProductId = function (state) {
|
|
132
|
+
return state.product.id;
|
|
133
|
+
};
|
|
134
|
+
exports.getProductId = getProductId;
|
|
56
135
|
var getName = function (state) {
|
|
57
136
|
return state.product.name;
|
|
58
137
|
};
|
|
@@ -62,4 +141,180 @@ var getMetadata = function (state) {
|
|
|
62
141
|
return state.product.metadata;
|
|
63
142
|
};
|
|
64
143
|
exports.getMetadata = getMetadata;
|
|
144
|
+
// Product Cache
|
|
145
|
+
var getActiveCacheIdx = function (state) {
|
|
146
|
+
return state.product.activeCacheIdx;
|
|
147
|
+
};
|
|
148
|
+
exports.getActiveCacheIdx = getActiveCacheIdx;
|
|
149
|
+
var getProductCache = function (state) {
|
|
150
|
+
return state.product.cache.map(function (prod) {
|
|
151
|
+
return Object.assign({
|
|
152
|
+
name: prod.name,
|
|
153
|
+
}, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
exports.getProductCache = getProductCache;
|
|
157
|
+
/*****************************************************
|
|
158
|
+
* Complex Actions
|
|
159
|
+
****************************************************/
|
|
160
|
+
var initProduct = function (prods) {
|
|
161
|
+
return function (dispatch, getState) {
|
|
162
|
+
if (prods)
|
|
163
|
+
exports.PRODUCTS = prods;
|
|
164
|
+
var state = getState();
|
|
165
|
+
var name = window.threekit.player.scene.get({
|
|
166
|
+
id: window.threekit.player.assetId,
|
|
167
|
+
}).name;
|
|
168
|
+
var metadata = window.threekit.configurator.getMetadata();
|
|
169
|
+
dispatch((0, exports.setName)(name));
|
|
170
|
+
dispatch((0, exports.setMetadata)(metadata));
|
|
171
|
+
if (!state.product.cache.length) {
|
|
172
|
+
dispatch((0, exports.setActiveCacheIdx)(0));
|
|
173
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
exports.initProduct = initProduct;
|
|
178
|
+
var cacheActiveProduct = function (config) {
|
|
179
|
+
return function (dispatch, getState) {
|
|
180
|
+
var state = getState();
|
|
181
|
+
var label = config === null || config === void 0 ? void 0 : config.label;
|
|
182
|
+
var thumbnail = config === null || config === void 0 ? void 0 : config.thumbnail;
|
|
183
|
+
var connectionObj = connection_1.default.getConnection();
|
|
184
|
+
delete connectionObj.threekitDomain;
|
|
185
|
+
var configuration = window.threekit.configurator.getConfiguration();
|
|
186
|
+
var data = { connection: connectionObj, configuration: configuration };
|
|
187
|
+
var product = Object.assign({
|
|
188
|
+
id: state.product.id,
|
|
189
|
+
name: state.product.name,
|
|
190
|
+
data: JSON.stringify(data),
|
|
191
|
+
}, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
|
|
192
|
+
return dispatch((0, exports.updateActiveProductCache)(product));
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
exports.cacheActiveProduct = cacheActiveProduct;
|
|
196
|
+
var loadProduct = function (id) {
|
|
197
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
198
|
+
var state, productsList, shouldCacheProduct, productConfig;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0:
|
|
202
|
+
state = getState();
|
|
203
|
+
productsList = Object.keys(exports.PRODUCTS);
|
|
204
|
+
shouldCacheProduct = true;
|
|
205
|
+
if (!productsList.includes(id))
|
|
206
|
+
return [2 /*return*/];
|
|
207
|
+
productConfig = exports.PRODUCTS[id][state.treble.threekitEnv];
|
|
208
|
+
dispatch((0, exports.setProductId)(id));
|
|
209
|
+
if (shouldCacheProduct)
|
|
210
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
211
|
+
return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(productConfig))];
|
|
212
|
+
case 1:
|
|
213
|
+
_a.sent();
|
|
214
|
+
if (shouldCacheProduct) {
|
|
215
|
+
dispatch((0, exports.incrementActiveCacheIdx)());
|
|
216
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
217
|
+
}
|
|
218
|
+
return [2 /*return*/];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}); };
|
|
222
|
+
};
|
|
223
|
+
exports.loadProduct = loadProduct;
|
|
224
|
+
var loadNewProduct = function (config) {
|
|
225
|
+
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
226
|
+
var label, thumbnail, shouldCacheProduct;
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
switch (_a.label) {
|
|
229
|
+
case 0:
|
|
230
|
+
shouldCacheProduct = true;
|
|
231
|
+
if (typeof config === 'object') {
|
|
232
|
+
label = config.label;
|
|
233
|
+
thumbnail = config.thumbnail;
|
|
234
|
+
if (config.cacheProduct === false)
|
|
235
|
+
shouldCacheProduct = false;
|
|
236
|
+
}
|
|
237
|
+
if (shouldCacheProduct)
|
|
238
|
+
dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
|
|
239
|
+
dispatch((0, exports.setProductId)(undefined));
|
|
240
|
+
return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(config))];
|
|
241
|
+
case 1:
|
|
242
|
+
_a.sent();
|
|
243
|
+
if (shouldCacheProduct) {
|
|
244
|
+
dispatch((0, exports.incrementActiveCacheIdx)());
|
|
245
|
+
dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
|
|
246
|
+
}
|
|
247
|
+
return [2 /*return*/];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}); };
|
|
251
|
+
};
|
|
252
|
+
exports.loadNewProduct = loadNewProduct;
|
|
253
|
+
var changeActiveCacheIdx = function (idx) {
|
|
254
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
255
|
+
var state, cache, cachedProduct, data;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
state = getState();
|
|
260
|
+
cache = state.product.cache;
|
|
261
|
+
if (idx >= cache.length)
|
|
262
|
+
return [2 /*return*/, Promise.resolve()];
|
|
263
|
+
dispatch((0, exports.cacheActiveProduct)());
|
|
264
|
+
cachedProduct = __assign({}, state.product.cache[idx]);
|
|
265
|
+
data = JSON.parse(cachedProduct.data);
|
|
266
|
+
connection_1.default.connect(data.connection);
|
|
267
|
+
dispatch((0, exports.setActiveCacheIdx)(idx));
|
|
268
|
+
dispatch((0, exports.setProductId)(cachedProduct.id));
|
|
269
|
+
return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)({
|
|
270
|
+
assetId: data.connection.assetId,
|
|
271
|
+
configuration: data.configuration,
|
|
272
|
+
}))];
|
|
273
|
+
case 1:
|
|
274
|
+
_a.sent();
|
|
275
|
+
return [2 /*return*/];
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}); };
|
|
279
|
+
};
|
|
280
|
+
exports.changeActiveCacheIdx = changeActiveCacheIdx;
|
|
281
|
+
var removeProductIdx = function (idx) {
|
|
282
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
283
|
+
var state, _a, cache, activeCacheIdx;
|
|
284
|
+
return __generator(this, function (_b) {
|
|
285
|
+
switch (_b.label) {
|
|
286
|
+
case 0:
|
|
287
|
+
state = getState();
|
|
288
|
+
_a = state.product, cache = _a.cache, activeCacheIdx = _a.activeCacheIdx;
|
|
289
|
+
if (cache.length <= 1)
|
|
290
|
+
return [2 /*return*/, Promise.resolve()];
|
|
291
|
+
if (!(!idx || idx === activeCacheIdx)) return [3 /*break*/, 5];
|
|
292
|
+
if (!(activeCacheIdx === state.product.cache.length - 1)) return [3 /*break*/, 2];
|
|
293
|
+
return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx - 1))];
|
|
294
|
+
case 1:
|
|
295
|
+
_b.sent();
|
|
296
|
+
dispatch((0, exports.removeFromCache)(activeCacheIdx));
|
|
297
|
+
return [3 /*break*/, 4];
|
|
298
|
+
case 2:
|
|
299
|
+
dispatch((0, exports.removeFromCache)(activeCacheIdx));
|
|
300
|
+
return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx))];
|
|
301
|
+
case 3:
|
|
302
|
+
_b.sent();
|
|
303
|
+
_b.label = 4;
|
|
304
|
+
case 4: return [3 /*break*/, 6];
|
|
305
|
+
case 5:
|
|
306
|
+
if (idx >= activeCacheIdx) {
|
|
307
|
+
dispatch((0, exports.removeFromCache)(idx));
|
|
308
|
+
}
|
|
309
|
+
else if (idx <= activeCacheIdx) {
|
|
310
|
+
dispatch((0, exports.decrementActiveCacheIdx)());
|
|
311
|
+
dispatch((0, exports.removeFromCache)(idx));
|
|
312
|
+
}
|
|
313
|
+
_b.label = 6;
|
|
314
|
+
case 6: return [2 /*return*/, Promise.resolve()];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}); };
|
|
318
|
+
};
|
|
319
|
+
exports.removeProductIdx = removeProductIdx;
|
|
65
320
|
exports.default = reducer;
|
|
@@ -4,13 +4,15 @@ import { ITranslationMap } from '../api/products';
|
|
|
4
4
|
* Types and Interfaces
|
|
5
5
|
****************************************************/
|
|
6
6
|
export interface TranslationsState {
|
|
7
|
-
translations: undefined | ITranslationMap;
|
|
8
7
|
language: string | undefined;
|
|
9
8
|
}
|
|
9
|
+
/*****************************************************
|
|
10
|
+
* Constants
|
|
11
|
+
****************************************************/
|
|
12
|
+
export declare let TRANSLATIONS: undefined | ITranslationMap;
|
|
10
13
|
/*****************************************************
|
|
11
14
|
* Actions
|
|
12
15
|
****************************************************/
|
|
13
|
-
export declare const setTranslations: import("@reduxjs/toolkit").ActionCreatorWithPayload<ITranslationMap, string>;
|
|
14
16
|
export declare const setLanguage: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
15
17
|
export declare const initTranslations: (language?: string | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
16
18
|
declare const reducer: import("redux").Reducer<TranslationsState, import("redux").AnyAction>;
|
|
@@ -39,23 +39,19 @@ 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.
|
|
42
|
+
exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.TRANSLATIONS = void 0;
|
|
43
43
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
44
44
|
var api_1 = __importDefault(require("../api"));
|
|
45
45
|
/*****************************************************
|
|
46
46
|
* Actions
|
|
47
47
|
****************************************************/
|
|
48
|
-
// Actions to be used only internally
|
|
49
|
-
exports.setTranslations = (0, toolkit_1.createAction)('treble/translations/set-translations');
|
|
50
48
|
exports.setLanguage = (0, toolkit_1.createAction)('treble/translations/set-language');
|
|
51
49
|
var initTranslations = function (language) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
-
var translations;
|
|
53
50
|
return __generator(this, function (_a) {
|
|
54
51
|
switch (_a.label) {
|
|
55
52
|
case 0: return [4 /*yield*/, api_1.default.products.fetchTranslations()];
|
|
56
53
|
case 1:
|
|
57
|
-
|
|
58
|
-
dispatch((0, exports.setTranslations)(translations));
|
|
54
|
+
exports.TRANSLATIONS = _a.sent();
|
|
59
55
|
if (language)
|
|
60
56
|
dispatch((0, exports.setLanguage)(language));
|
|
61
57
|
return [2 /*return*/];
|
|
@@ -68,16 +64,12 @@ exports.initTranslations = initTranslations;
|
|
|
68
64
|
****************************************************/
|
|
69
65
|
var initialState = {
|
|
70
66
|
// Selected language
|
|
71
|
-
translations: undefined,
|
|
72
67
|
language: undefined,
|
|
73
68
|
};
|
|
74
69
|
var reducer = (0, toolkit_1.createSlice)({
|
|
75
70
|
name: 'translations',
|
|
76
71
|
initialState: initialState,
|
|
77
72
|
extraReducers: function (builder) {
|
|
78
|
-
builder.addCase(exports.setTranslations, function (state, action) {
|
|
79
|
-
state.translations = action.payload;
|
|
80
|
-
});
|
|
81
73
|
builder.addCase(exports.setLanguage, function (state, action) {
|
|
82
74
|
state.language = action.payload;
|
|
83
75
|
});
|
|
@@ -92,9 +84,9 @@ var getLanguage = function (state) {
|
|
|
92
84
|
};
|
|
93
85
|
exports.getLanguage = getLanguage;
|
|
94
86
|
var getLanguageOptions = function (state) {
|
|
95
|
-
if (!state.treble.isThreekitInitialized || !
|
|
87
|
+
if (!state.treble.isThreekitInitialized || !exports.TRANSLATIONS)
|
|
96
88
|
return [];
|
|
97
|
-
return Object.keys(Object.values(
|
|
89
|
+
return Object.keys(Object.values(exports.TRANSLATIONS)[0]);
|
|
98
90
|
};
|
|
99
91
|
exports.getLanguageOptions = getLanguageOptions;
|
|
100
92
|
exports.default = reducer;
|
package/dist/store/treble.d.ts
CHANGED
|
@@ -1,19 +1,47 @@
|
|
|
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 {
|
|
16
|
+
productId: string;
|
|
7
17
|
threekitEnv: string;
|
|
18
|
+
serverUrl: string;
|
|
8
19
|
locale: string;
|
|
9
20
|
project: IProject;
|
|
10
21
|
playerConfig: IPlayerConfig;
|
|
11
22
|
eventHandlers: EventHandlers;
|
|
12
23
|
}
|
|
24
|
+
export interface IReloadConfig {
|
|
25
|
+
label?: string;
|
|
26
|
+
thumbnail?: string;
|
|
27
|
+
configuration?: IConfiguration;
|
|
28
|
+
assetId?: string;
|
|
29
|
+
stageId?: string;
|
|
30
|
+
configurationId?: string;
|
|
31
|
+
cacheProduct?: boolean;
|
|
32
|
+
}
|
|
13
33
|
export interface TrebleState {
|
|
34
|
+
threekitEnv: string;
|
|
14
35
|
isPlayerLoading: boolean;
|
|
15
36
|
isThreekitInitialized: boolean;
|
|
16
37
|
playerElId: undefined | string;
|
|
38
|
+
notifications: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface NotificationEvent extends Event {
|
|
41
|
+
detail: {
|
|
42
|
+
message: string;
|
|
43
|
+
type: string;
|
|
44
|
+
};
|
|
17
45
|
}
|
|
18
46
|
interface EventHandlers {
|
|
19
47
|
postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
|
|
@@ -21,9 +49,11 @@ interface EventHandlers {
|
|
|
21
49
|
/*****************************************************
|
|
22
50
|
* Actions
|
|
23
51
|
****************************************************/
|
|
24
|
-
export declare const
|
|
52
|
+
export declare const setThreekitEnv: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
53
|
+
export declare const setThreekitInitialized: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
25
54
|
export declare const setPlayerLoading: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
26
55
|
export declare const setPlayerElement: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
56
|
+
export declare const reloadTreble: import("@reduxjs/toolkit").ActionCreatorWithPayload<Partial<TrebleState>, string>;
|
|
27
57
|
/*****************************************************
|
|
28
58
|
* Slice
|
|
29
59
|
****************************************************/
|
|
@@ -31,11 +61,15 @@ declare const reducer: import("redux").Reducer<TrebleState, import("redux").AnyA
|
|
|
31
61
|
/*****************************************************
|
|
32
62
|
* Standard Selectors
|
|
33
63
|
****************************************************/
|
|
64
|
+
export declare const getThreekitEnv: (state: RootState) => string;
|
|
34
65
|
export declare const isThreekitInitialized: (state: RootState) => boolean;
|
|
35
66
|
export declare const isPlayerLoading: (state: RootState) => boolean;
|
|
36
67
|
export declare const getPlayerElementId: (state: RootState) => undefined | string;
|
|
37
68
|
/*****************************************************
|
|
38
69
|
* Complex Actions
|
|
39
70
|
****************************************************/
|
|
71
|
+
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
40
72
|
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
73
|
+
export declare const unloadPlayer: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
74
|
+
export declare const reloadPlayer: (config: undefined | string | Pick<IReloadConfig, 'assetId' | 'stageId' | 'configurationId' | 'configuration'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
41
75
|
export default reducer;
|