@threekit-tools/treble 0.0.10-alpha.13 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +163 -156
  2. package/dist/Treble/Snapshots.d.ts +28 -0
  3. package/dist/Treble/Snapshots.js +280 -0
  4. package/dist/Treble/Treble.d.ts +9 -27
  5. package/dist/Treble/Treble.js +34 -350
  6. package/dist/Treble/Wishlist.d.ts +18 -0
  7. package/dist/Treble/Wishlist.js +137 -0
  8. package/dist/Treble/index.d.ts +2 -0
  9. package/dist/Treble/index.js +2 -0
  10. package/dist/components/Accordion/accordion.styles.d.ts +5 -0
  11. package/dist/components/Accordion/accordion.styles.js +13 -0
  12. package/dist/components/Accordion/index.d.ts +14 -0
  13. package/dist/components/Accordion/index.js +63 -0
  14. package/dist/components/Cards/index.d.ts +2 -2
  15. package/dist/components/Drawer/index.js +0 -1
  16. package/dist/components/Dropdown/dropdown.styles.js +1 -3
  17. package/dist/components/Dropdown/index.d.ts +2 -2
  18. package/dist/components/FormComponentDescription/index.js +1 -1
  19. package/dist/components/Modal/index.js +3 -1
  20. package/dist/components/Share/index.d.ts +37 -0
  21. package/dist/components/Share/index.js +51 -0
  22. package/dist/components/Strips/index.d.ts +2 -2
  23. package/dist/components/Strips/index.js +1 -1
  24. package/dist/components/Swatch/index.d.ts +2 -2
  25. package/dist/components/Tabs/index.d.ts +14 -0
  26. package/dist/components/Tabs/index.js +53 -0
  27. package/dist/components/Tabs/tabs.styles.d.ts +8 -0
  28. package/dist/components/Tabs/tabs.styles.js +20 -0
  29. package/dist/components/ThreekitProvider/index.d.ts +11 -2
  30. package/dist/components/ThreekitProvider/index.js +3 -3
  31. package/dist/components/Tiles/index.d.ts +2 -2
  32. package/dist/components/TilesGroup/index.d.ts +2 -2
  33. package/dist/components/containers/formInputContainer.d.ts +1 -1
  34. package/dist/hooks/useShare/index.d.ts +3 -0
  35. package/dist/hooks/useShare/index.js +71 -0
  36. package/dist/hooks/useWishlist/index.d.ts +2 -3
  37. package/dist/index.d.ts +5 -1
  38. package/dist/index.js +9 -1
  39. package/dist/store/threekit.d.ts +5 -5
  40. package/dist/store/threekit.js +7 -6
  41. package/dist/threekit.d.ts +2 -0
  42. package/package.json +7 -5
@@ -35,15 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
40
  };
@@ -52,361 +43,54 @@ var api_1 = __importDefault(require("../api"));
52
43
  var connection_1 = __importDefault(require("../connection"));
53
44
  var constants_1 = require("../constants");
54
45
  var utils_1 = require("../utils");
55
- var DEFAULT_CAMERA_CONFIG = {
56
- filename: "snapshot",
57
- size: { width: 1920, height: 1080 },
58
- format: constants_1.SNAPSHOT_FORMATS.png,
59
- attributeName: constants_1.ATTRIBUTES_RESERVED.camera,
60
- output: constants_1.SNAPSHOT_OUTPUTS.blob,
61
- };
46
+ var Wishlist_1 = __importDefault(require("./Wishlist"));
47
+ var Snapshots_1 = __importDefault(require("./Snapshots"));
62
48
  var Treble = /** @class */ (function () {
63
49
  function Treble(_a) {
64
- var player = _a.player;
65
- // Threekit API
66
- this._api = api_1.default;
67
- this._player = player;
68
- // this._player = player.enableApi('player')
69
- }
70
- Treble.prototype._getCameraValue = function (cameraAttrName) {
71
- var attribute = window.threekit.configurator
72
- .getDisplayAttributes()
73
- .find(function (el) { return el.name === cameraAttrName; });
74
- if (!attribute)
75
- return undefined;
76
- return attribute.value;
77
- };
78
- Treble.prototype._getCamerasMap = function (cameraAttrName) {
79
50
  var _this = this;
80
- if (this._cameraValues)
81
- return this._cameraValues;
82
- var attribute = window.threekit.configurator
83
- .getDisplayAttributes()
84
- .find(function (el) { return el.name === cameraAttrName; });
85
- if (!attribute) {
86
- this._cameraValues = {};
87
- return this._cameraValues;
88
- }
89
- var cameraAttribute = attribute;
90
- cameraAttribute.values.forEach(function (el) {
91
- var _a;
92
- var value = cameraAttribute.type === constants_1.ATTRIBUTE_TYPES.asset
93
- ? { assetId: el.assetId }
94
- : el.value;
95
- _this._cameraValues = Object.assign(_this._cameraValues || {}, (_a = {},
96
- _a[el.label] = value,
97
- _a));
98
- }, {});
99
- return this._cameraValues;
100
- };
101
- Treble.prototype.takeSnapshots = function (cameras, config) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- function getSnapshot() {
104
- return window.threekit.player.snapshotAsync({
105
- size: size,
106
- mimeType: "image/".concat(constants_1.SNAPSHOT_FORMATS[format]),
107
- });
108
- }
109
- function getSnapshots(cameras, camerasMap) {
110
- var _this = this;
111
- var snapshots = [];
112
- return cameras.reduce(function (snapshotPromise, camera) {
113
- return snapshotPromise.then(function () {
114
- return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
115
- var snapshotStr;
116
- var _a;
117
- return __generator(this, function (_b) {
118
- switch (_b.label) {
119
- case 0:
120
- if (!camera) return [3 /*break*/, 2];
121
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_a = {},
122
- _a[attributeName] = camerasMap[camera],
123
- _a))];
124
- case 1:
125
- _b.sent();
126
- _b.label = 2;
127
- case 2: return [4 /*yield*/, getSnapshot()];
128
- case 3:
129
- snapshotStr = _b.sent();
130
- snapshots.push(snapshotStr);
131
- resolve(snapshots);
132
- return [2 /*return*/];
133
- }
134
- });
135
- }); });
136
- });
137
- }, Promise.resolve(snapshots));
138
- }
139
- function saveSnapshotToPlatform(snapshot, filename) {
140
- return __awaiter(this, void 0, void 0, function () {
141
- var files, response;
142
- return __generator(this, function (_a) {
143
- switch (_a.label) {
144
- case 0:
145
- files = (0, utils_1.dataURItoFile)(snapshot, filename);
146
- return [4 /*yield*/, api_1.default.configurations.save({
147
- assetId: window.threekit.player.assetId,
148
- configuration: window.threekit.configurator.getConfiguration(),
149
- files: files,
150
- })];
151
- case 1:
152
- response = _a.sent();
153
- return [2 /*return*/, "".concat(threekitDomain, "/api/files/hash/").concat(response.data.thumbnail)];
154
- }
155
- });
156
- });
157
- }
158
- function downloadSnapshot(snapshot, filename) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- var blob, blobUrl, link, clickHandler;
161
- return __generator(this, function (_a) {
162
- blob = (0, utils_1.dataURItoBlob)(snapshot);
163
- blobUrl = URL.createObjectURL(blob);
164
- link = document.createElement('a') // Or maybe get it from the current document
165
- ;
166
- link.href = blobUrl;
167
- link.download = filename;
168
- clickHandler = function () {
169
- setTimeout(function () {
170
- URL.revokeObjectURL(blobUrl);
171
- link.removeEventListener('click', clickHandler);
172
- }, 150);
173
- };
174
- link.addEventListener('click', clickHandler);
175
- document.body.appendChild(link);
176
- link.click();
177
- return [2 /*return*/];
178
- });
179
- });
180
- }
181
- var threekitDomain, filename, size, format, attributeName, output, camerasList, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _a, savedSnapshots, snapshotBlobs, snapshotFiles;
51
+ var player = _a.player;
52
+ this.saveConfiguration = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
+ var threekitDomain, _a, customerId, metadata, productVersion, files, response, params, url;
182
54
  var _b;
183
- return __generator(this, function (_c) {
184
- switch (_c.label) {
185
- case 0:
186
- threekitDomain = connection_1.default.getConnection().threekitDomain;
187
- filename = config.filename || DEFAULT_CAMERA_CONFIG.filename;
188
- size = config.size || DEFAULT_CAMERA_CONFIG.size;
189
- format = config.format || DEFAULT_CAMERA_CONFIG.format;
190
- attributeName = config.attributeName || DEFAULT_CAMERA_CONFIG.attributeName;
191
- output = config.output || DEFAULT_CAMERA_CONFIG.output;
192
- camerasList = Array.isArray(cameras) ? cameras : [cameras];
193
- if (!(camerasList.length === 1 && camerasList[0] === undefined)) return [3 /*break*/, 2];
194
- return [4 /*yield*/, getSnapshot()];
195
- case 1:
196
- snapshotData = _c.sent();
197
- snapshotsRaw = [snapshotData];
198
- return [3 /*break*/, 5];
199
- case 2:
200
- camerasMap_1 = this._getCamerasMap(attributeName);
201
- if (!camerasMap_1)
202
- return [2 /*return*/, null];
203
- camerasList = camerasList.filter(function (el) { return el === undefined || Object.keys(camerasMap_1).includes(el); });
204
- currentCamera = this._getCameraValue(attributeName);
205
- cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
206
- return [4 /*yield*/, getSnapshots(camerasList, camerasMap_1)];
207
- case 3:
208
- snapshotsRaw = _c.sent();
209
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_b = {},
210
- _b[attributeName] = currentCamera,
211
- _b))];
212
- case 4:
213
- _c.sent();
214
- (0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
215
- _c.label = 5;
216
- case 5:
217
- _a = output;
218
- switch (_a) {
219
- case constants_1.SNAPSHOT_OUTPUTS.url: return [3 /*break*/, 6];
220
- case constants_1.SNAPSHOT_OUTPUTS.download: return [3 /*break*/, 8];
221
- case constants_1.SNAPSHOT_OUTPUTS.blob: return [3 /*break*/, 9];
222
- case constants_1.SNAPSHOT_OUTPUTS.file: return [3 /*break*/, 10];
223
- case constants_1.SNAPSHOT_OUTPUTS.dataUrl: return [3 /*break*/, 11];
224
- }
225
- return [3 /*break*/, 11];
226
- case 6: return [4 /*yield*/, Promise.all(snapshotsRaw.map(function (snapshotBlob, idx) {
227
- var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
228
- ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
229
- : '';
230
- return saveSnapshotToPlatform(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
231
- }))];
232
- case 7:
233
- savedSnapshots = _c.sent();
234
- return [2 /*return*/, Promise.resolve(savedSnapshots)];
235
- case 8:
236
- snapshotsRaw.forEach(function (snapshotBlob, idx) {
237
- var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
238
- ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
239
- : '';
240
- downloadSnapshot(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
241
- });
242
- return [2 /*return*/, Promise.resolve()];
243
- case 9:
244
- snapshotBlobs = snapshotsRaw.map(function (el) { return (0, utils_1.dataURItoBlob)(el); });
245
- return [2 /*return*/, Promise.resolve(snapshotBlobs)];
246
- case 10:
247
- snapshotFiles = snapshotsRaw.map(function (el, idx) {
248
- var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
249
- ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
250
- : '';
251
- return (0, utils_1.dataURItoFile)(el, "".concat(filename).concat(cameraName, ".").concat(format));
252
- });
253
- return [2 /*return*/, Promise.resolve(snapshotFiles)];
254
- case 11: return [2 /*return*/, Promise.resolve(snapshotsRaw)];
255
- case 12: return [2 /*return*/];
256
- }
257
- });
258
- });
259
- };
260
- Treble.prototype.saveConfiguration = function (config) {
261
- var _a, _b, _c, _d;
262
- return __awaiter(this, void 0, void 0, function () {
263
- var threekitDomain, _e, customerId, metadata, productVersion, snapshot, files, filename, size, format, attributeName, snapshotRaw, camerasMap, currentCamera, cameraPosition, response;
264
- var _f, _g;
265
- return __generator(this, function (_h) {
266
- switch (_h.label) {
55
+ var _c;
56
+ return __generator(this, function (_d) {
57
+ switch (_d.label) {
267
58
  case 0:
268
59
  threekitDomain = connection_1.default.getConnection().threekitDomain;
269
- _e = Object.assign({}, config), customerId = _e.customerId, metadata = _e.metadata, productVersion = _e.productVersion, snapshot = _e.snapshot;
60
+ _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion;
270
61
  files = undefined;
271
- if (!snapshot) return [3 /*break*/, 9];
272
- filename = DEFAULT_CAMERA_CONFIG.filename, size = DEFAULT_CAMERA_CONFIG.size, format = DEFAULT_CAMERA_CONFIG.format, attributeName = DEFAULT_CAMERA_CONFIG.attributeName;
273
- snapshotRaw = void 0;
274
- if (!(snapshot === true || !snapshot.camera)) return [3 /*break*/, 3];
275
- return [4 /*yield*/, window.threekit.player.snapshotAsync({
276
- size: size,
277
- mimeType: "image/".concat(constants_1.SNAPSHOT_FORMATS[format]),
278
- })];
279
- case 1: return [4 /*yield*/, _h.sent()];
280
- case 2:
281
- snapshotRaw = _h.sent();
282
- return [3 /*break*/, 8];
283
- case 3:
284
- filename = "".concat(filename).concat(snapshot.camera || '');
285
- size = ((_a = snapshot.config) === null || _a === void 0 ? void 0 : _a.size) || DEFAULT_CAMERA_CONFIG.size;
286
- format = ((_b = snapshot.config) === null || _b === void 0 ? void 0 : _b.format) || DEFAULT_CAMERA_CONFIG.format;
287
- attributeName =
288
- ((_c = snapshot.config) === null || _c === void 0 ? void 0 : _c.attributeName) || DEFAULT_CAMERA_CONFIG.attributeName;
289
- camerasMap = this._getCamerasMap(attributeName);
290
- if (!camerasMap)
291
- return [2 /*return*/, null];
292
- currentCamera = this._getCameraValue(attributeName);
293
- cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
294
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_f = {},
295
- _f[attributeName] = camerasMap[snapshot.camera],
296
- _f))];
297
- case 4:
298
- _h.sent();
299
- return [4 /*yield*/, window.threekit.player.snapshotAsync({
300
- size: size,
301
- mimeType: "image/".concat(constants_1.SNAPSHOT_FORMATS[format]),
62
+ return [4 /*yield*/, api_1.default.configurations.save({
63
+ assetId: window.threekit.player.assetId,
64
+ configuration: window.threekit.configurator.getConfiguration(),
65
+ customerId: customerId,
66
+ metadata: metadata,
67
+ productVersion: productVersion,
68
+ files: files,
302
69
  })];
303
- case 5: return [4 /*yield*/, _h.sent()];
304
- case 6:
305
- snapshotRaw = _h.sent();
306
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_g = {},
307
- _g[attributeName] = currentCamera,
308
- _g))];
309
- case 7:
310
- _h.sent();
311
- (0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
312
- _h.label = 8;
313
- case 8:
314
- files = (0, utils_1.dataURItoFile)(snapshotRaw, "".concat(filename, ".").concat(format));
315
- _h.label = 9;
316
- case 9: return [4 /*yield*/, api_1.default.configurations.save({
317
- assetId: window.threekit.player.assetId,
318
- configuration: window.threekit.configurator.getConfiguration(),
319
- customerId: customerId,
320
- metadata: metadata,
321
- productVersion: productVersion,
322
- files: files,
323
- })];
324
- case 10:
325
- response = _h.sent();
326
- return [2 /*return*/, Object.assign({}, response.data, ((_d = response.data.thumbnail) === null || _d === void 0 ? void 0 : _d.length)
70
+ case 1:
71
+ response = _d.sent();
72
+ params = Object.assign((0, utils_1.getParams)(), (_b = {},
73
+ _b[constants_1.TK_SAVED_CONFIG_PARAM_KEY] = response.data.shortId,
74
+ _b));
75
+ url = window.location.href.replace(window.location.search, '');
76
+ return [2 /*return*/, Object.assign({
77
+ resumableUrl: "".concat(url).concat((0, utils_1.objectToQueryStr)(params)),
78
+ }, response.data, ((_c = response.data.thumbnail) === null || _c === void 0 ? void 0 : _c.length)
327
79
  ? {
328
80
  thumbnail: "".concat(threekitDomain, "/api/files/hash/").concat(response.data.thumbnail),
329
81
  }
330
82
  : undefined)];
331
83
  }
332
84
  });
333
- });
334
- };
335
- Treble.prototype.getWishlist = function () {
336
- return __awaiter(this, void 0, void 0, function () {
337
- var threekitDomain, wishlistListStr, wishlistList, wishlistData;
338
- return __generator(this, function (_a) {
339
- switch (_a.label) {
340
- case 0:
341
- if (this._wishlist)
342
- return [2 /*return*/, this._wishlist];
343
- threekitDomain = connection_1.default.getConnection().threekitDomain;
344
- wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
345
- wishlistList = JSON.parse(wishlistListStr || '[]');
346
- return [4 /*yield*/, Promise.all(wishlistList.map(function (el) { return api_1.default.configurations.fetch(el); }))];
347
- case 1:
348
- wishlistData = _a.sent();
349
- this._wishlist = wishlistData.map(function (el) {
350
- var _a;
351
- return Object.assign({}, el.data, ((_a = el.data.thumbnail) === null || _a === void 0 ? void 0 : _a.length)
352
- ? {
353
- thumbnail: "".concat(threekitDomain, "/api/files/hash/").concat(el.data.thumbnail),
354
- }
355
- : undefined);
356
- });
357
- return [2 /*return*/, this._wishlist];
358
- }
359
- });
360
- });
361
- };
362
- Treble.prototype.addToWishlist = function (config) {
363
- return __awaiter(this, void 0, void 0, function () {
364
- var configPrepped, savedConfiguration, wishlistListStr, wishlistList;
365
- return __generator(this, function (_a) {
366
- switch (_a.label) {
367
- case 0:
368
- if (!this._wishlist) {
369
- this._wishlist = [];
370
- localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
371
- }
372
- configPrepped = Object.assign({ snapshot: true }, config);
373
- return [4 /*yield*/, this.saveConfiguration(configPrepped)];
374
- case 1:
375
- savedConfiguration = _a.sent();
376
- if (!savedConfiguration)
377
- return [2 /*return*/, this._wishlist];
378
- this._wishlist = __spreadArray(__spreadArray([], this._wishlist, true), [savedConfiguration], false);
379
- wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
380
- wishlistList = JSON.parse(wishlistListStr || '[]');
381
- wishlistList.push(savedConfiguration.shortId);
382
- localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify(wishlistList));
383
- return [2 /*return*/, this.getWishlist()];
384
- }
385
- });
386
- });
387
- };
388
- Treble.prototype.removeFromWishlist = function (idx) {
389
- if (!this._wishlist) {
390
- this._wishlist = [];
391
- localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
392
- return this._wishlist;
393
- }
394
- if (idx > this._wishlist.length - 1)
395
- return this._wishlist;
396
- var updatedWishlist = __spreadArray([], this._wishlist, true);
397
- updatedWishlist.splice(idx, 1);
398
- this._wishlist = updatedWishlist;
399
- var wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
400
- var wishlistList = JSON.parse(wishlistListStr || '[]');
401
- wishlistList.splice(idx, 1);
402
- localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify(wishlistList));
403
- return this._wishlist;
404
- };
405
- Treble.prototype.clearWishlist = function () {
406
- this._wishlist = [];
407
- localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
408
- return this._wishlist;
409
- };
85
+ }); };
86
+ // Threekit API
87
+ this._api = api_1.default;
88
+ this._player = player;
89
+ this.wishlist = (0, Wishlist_1.default)();
90
+ this._snapshots = new Snapshots_1.default();
91
+ this.takeSnapshots = this._snapshots.takeSnapshots;
92
+ // this._player = player.enableApi('player')
93
+ }
410
94
  return Treble;
411
95
  }());
412
96
  exports.default = Treble;
@@ -0,0 +1,18 @@
1
+ import { IConfigurationResponse } from '../http/configurations';
2
+ import { ISaveConfigurationConfig } from './Treble';
3
+ export declare type WishlistArray = Array<IConfigurationResponse>;
4
+ export interface IWishlist {
5
+ getWishlist(): Promise<Array<IConfigurationResponse>>;
6
+ addItem(config?: ISaveConfigurationConfig): Promise<Array<IConfigurationResponse>>;
7
+ removeItemByIdx(idx: number): Array<IConfigurationResponse>;
8
+ clearWishlist(): Array<IConfigurationResponse>;
9
+ }
10
+ declare class Wishlist implements IWishlist {
11
+ constructor();
12
+ getWishlist: () => Promise<WishlistArray>;
13
+ addItem: (config?: ISaveConfigurationConfig | undefined) => Promise<WishlistArray>;
14
+ removeItemByIdx: (idx: number) => WishlistArray;
15
+ clearWishlist: () => WishlistArray;
16
+ }
17
+ export default function createWishlist(): Wishlist;
18
+ export {};
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ var api_1 = __importDefault(require("../api"));
52
+ var connection_1 = __importDefault(require("../connection"));
53
+ var constants_1 = require("../constants");
54
+ var wishlistData;
55
+ var Wishlist = /** @class */ (function () {
56
+ function Wishlist() {
57
+ var _this = this;
58
+ this.getWishlist = function () { return __awaiter(_this, void 0, void 0, function () {
59
+ var threekitDomain, wishlistListStr, wishlistList, wishlistDataRaw;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ if (wishlistData)
64
+ return [2 /*return*/, wishlistData];
65
+ threekitDomain = connection_1.default.getConnection().threekitDomain;
66
+ wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
67
+ wishlistList = JSON.parse(wishlistListStr || '[]');
68
+ return [4 /*yield*/, Promise.all(wishlistList.map(function (el) { return api_1.default.configurations.fetch(el); }))];
69
+ case 1:
70
+ wishlistDataRaw = _a.sent();
71
+ wishlistData = wishlistDataRaw.map(function (el) {
72
+ var _a;
73
+ return Object.assign({}, el.data, ((_a = el.data.thumbnail) === null || _a === void 0 ? void 0 : _a.length)
74
+ ? {
75
+ thumbnail: "".concat(threekitDomain, "/api/files/hash/").concat(el.data.thumbnail),
76
+ }
77
+ : undefined);
78
+ });
79
+ return [2 /*return*/, wishlistData];
80
+ }
81
+ });
82
+ }); };
83
+ this.addItem = function (config) { return __awaiter(_this, void 0, void 0, function () {
84
+ var configPrepped, savedConfiguration, wishlistListStr, wishlistList;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ if (!wishlistData) {
89
+ wishlistData = [];
90
+ localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
91
+ }
92
+ configPrepped = Object.assign({ snapshot: true }, config);
93
+ return [4 /*yield*/, window.threekit.treble.saveConfiguration(configPrepped)];
94
+ case 1:
95
+ savedConfiguration = _a.sent();
96
+ // const savedConfiguration = await this.saveConfiguration(configPrepped)
97
+ if (!savedConfiguration)
98
+ return [2 /*return*/, wishlistData];
99
+ wishlistData = __spreadArray(__spreadArray([], wishlistData, true), [savedConfiguration], false);
100
+ wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
101
+ wishlistList = JSON.parse(wishlistListStr || '[]');
102
+ wishlistList.push(savedConfiguration.shortId);
103
+ localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify(wishlistList));
104
+ return [2 /*return*/, this.getWishlist()];
105
+ }
106
+ });
107
+ }); };
108
+ this.removeItemByIdx = function (idx) {
109
+ if (!(wishlistData === null || wishlistData === void 0 ? void 0 : wishlistData.length)) {
110
+ wishlistData = [];
111
+ localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
112
+ return wishlistData;
113
+ }
114
+ if (idx > (wishlistData === null || wishlistData === void 0 ? void 0 : wishlistData.length) - 1)
115
+ return wishlistData;
116
+ var updatedWishlist = __spreadArray([], wishlistData, true);
117
+ updatedWishlist.splice(idx, 1);
118
+ wishlistData = updatedWishlist;
119
+ var wishlistListStr = localStorage.getItem(constants_1.WISHLIST_LOCALSTORAGE_KEY);
120
+ var wishlistList = JSON.parse(wishlistListStr || '[]');
121
+ wishlistList.splice(idx, 1);
122
+ localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify(wishlistList));
123
+ return wishlistData;
124
+ };
125
+ this.clearWishlist = function () {
126
+ wishlistData = [];
127
+ localStorage.setItem(constants_1.WISHLIST_LOCALSTORAGE_KEY, JSON.stringify([]));
128
+ return wishlistData;
129
+ };
130
+ this.getWishlist();
131
+ }
132
+ return Wishlist;
133
+ }());
134
+ function createWishlist() {
135
+ return new Wishlist();
136
+ }
137
+ exports.default = createWishlist;
@@ -1,3 +1,5 @@
1
1
  import Treble from './Treble';
2
2
  export * from './Treble';
3
+ export * from './Snapshots';
4
+ export * from './Wishlist';
3
5
  export default Treble;
@@ -15,4 +15,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  var Treble_1 = __importDefault(require("./Treble"));
17
17
  __exportStar(require("./Treble"), exports);
18
+ __exportStar(require("./Snapshots"), exports);
19
+ __exportStar(require("./Wishlist"), exports);
18
20
  exports.default = Treble_1.default;
@@ -0,0 +1,5 @@
1
+ interface AccordionWrapper {
2
+ selected?: boolean;
3
+ }
4
+ export declare const Wrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, AccordionWrapper, never>;
5
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Wrapper = void 0;
11
+ var styled_components_1 = __importDefault(require("styled-components"));
12
+ exports.Wrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: max-content;\n border: 1px solid #d3d4d3;\n /* border-radius: 3px; */\n width: 100%;\n margin-bottom: 2px;\n background: #fafafa;\n\n & > div:nth-child(1) {\n height: 45px;\n padding: 0 15px;\n /* border-radius: 3px; */\n cursor: pointer;\n\n display: grid;\n grid-template-columns: auto max-content max-content;\n grid-gap: 10px;\n\n & > div {\n height: max-content;\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n }\n\n & > div:nth-child(1) {\n text-transform: uppercase;\n letter-spacing: 0.2em;\n font-size: 14px;\n font-family: ", ";\n }\n\n & > div:nth-child(2) {\n color: #888888;\n padding-right: 8px;\n font-size: 13px;\n letter-spacing: 0.1em;\n font-family: ", ";\n }\n }\n\n & > div:nth-child(2) {\n max-height: ", ";\n transition: all 0.3s;\n overflow-y: scroll;\n\n & > div {\n padding: 0 30px;\n padding-bottom: 20px;\n\n & > div:nth-child(1) {\n padding-top: 20px;\n }\n }\n }\n"], ["\n height: max-content;\n border: 1px solid #d3d4d3;\n /* border-radius: 3px; */\n width: 100%;\n margin-bottom: 2px;\n background: #fafafa;\n\n & > div:nth-child(1) {\n height: 45px;\n padding: 0 15px;\n /* border-radius: 3px; */\n cursor: pointer;\n\n display: grid;\n grid-template-columns: auto max-content max-content;\n grid-gap: 10px;\n\n & > div {\n height: max-content;\n position: relative;\n top: 50%;\n transform: translateY(-50%);\n }\n\n & > div:nth-child(1) {\n text-transform: uppercase;\n letter-spacing: 0.2em;\n font-size: 14px;\n font-family: ", ";\n }\n\n & > div:nth-child(2) {\n color: #888888;\n padding-right: 8px;\n font-size: 13px;\n letter-spacing: 0.1em;\n font-family: ", ";\n }\n }\n\n & > div:nth-child(2) {\n max-height: ", ";\n transition: all 0.3s;\n overflow-y: scroll;\n\n & > div {\n padding: 0 30px;\n padding-bottom: 20px;\n\n & > div:nth-child(1) {\n padding-top: 20px;\n }\n }\n }\n"])), function (props) { return props.theme.fontFamily; }, function (props) { return props.theme.fontFamily; }, function (props) { return (props.selected ? '330px' : 0); });
13
+ var templateObject_1;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ interface AccordionItemProps extends React.FC {
3
+ selected: boolean;
4
+ label: string;
5
+ handleClick: () => void;
6
+ }
7
+ interface AccordionProps<T> {
8
+ children: React.FunctionComponentElement<T>;
9
+ }
10
+ export declare const Accordion: {
11
+ (props: AccordionProps<AccordionItemProps>): React.FunctionComponentElement<AccordionItemProps>[] | null;
12
+ AccordionItem: React.FC<AccordionItemProps>;
13
+ };
14
+ export default Accordion;