@threekit-tools/treble 0.0.83 → 0.0.84

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 (46) hide show
  1. package/dist/Treble/Treble.d.ts +9 -3
  2. package/dist/Treble/Treble.js +37 -7
  3. package/dist/Treble/index.d.ts +2 -2
  4. package/dist/Treble/index.js +2 -2
  5. package/dist/Treble/{Snapshots.d.ts → snapshots.d.ts} +4 -9
  6. package/dist/Treble/snapshots.js +247 -0
  7. package/dist/Treble/{Wishlist.d.ts → wishlist.d.ts} +2 -6
  8. package/dist/Treble/wishlist.js +135 -0
  9. package/dist/api/orders.d.ts +5 -7
  10. package/dist/components/AttributeValue/index.js +2 -2
  11. package/dist/components/Cards/index.d.ts +2 -1
  12. package/dist/components/Cards/index.js +3 -3
  13. package/dist/components/Dropdown/index.d.ts +2 -1
  14. package/dist/components/Dropdown/index.js +3 -3
  15. package/dist/components/FlatForm/index.js +5 -3
  16. package/dist/components/Player/index.d.ts +1 -1
  17. package/dist/components/Strips/index.d.ts +2 -1
  18. package/dist/components/Strips/index.js +3 -3
  19. package/dist/components/Swatch/index.d.ts +2 -1
  20. package/dist/components/Swatch/index.js +3 -3
  21. package/dist/components/Switch/index.d.ts +2 -1
  22. package/dist/components/Switch/index.js +2 -2
  23. package/dist/components/TextInput/index.d.ts +2 -1
  24. package/dist/components/TextInput/index.js +2 -2
  25. package/dist/components/Tiles/index.d.ts +2 -1
  26. package/dist/components/Tiles/index.js +3 -3
  27. package/dist/components/TilesGroup/index.d.ts +2 -1
  28. package/dist/components/TilesGroup/index.js +3 -3
  29. package/dist/components/Upload/index.d.ts +2 -1
  30. package/dist/components/Upload/index.js +2 -2
  31. package/dist/components/UploadArea/index.d.ts +2 -1
  32. package/dist/components/UploadArea/index.js +2 -2
  33. package/dist/components/formComponents.d.ts +12 -0
  34. package/dist/components/formComponents.js +5 -5
  35. package/dist/constants.d.ts +0 -22
  36. package/dist/constants.js +1 -23
  37. package/dist/hooks/useSingleAnimation/index.js +15 -14
  38. package/dist/http/orders.d.ts +6 -8
  39. package/dist/store/product.js +3 -1
  40. package/dist/types.d.ts +71 -24
  41. package/dist/types.js +54 -0
  42. package/dist/utils.d.ts +2 -2
  43. package/dist/utils.js +5 -4
  44. package/package.json +1 -1
  45. package/dist/Treble/Snapshots.js +0 -250
  46. package/dist/Treble/Wishlist.js +0 -136
@@ -1,8 +1,10 @@
1
1
  import threekitAPI from '../api';
2
2
  import { IThreekitPlayer, IThreekitPrivatePlayer, IConfiguration, ISetConfiguration, IThreekitPrivateConfigurator } from '../types';
3
- import { IWishlist } from './Wishlist';
4
- import Snapshots from './Snapshots';
3
+ import { IWishlist } from './wishlist';
4
+ import snapshots from './snapshots';
5
5
  import { ISaveConfiguration } from '../api/configurations';
6
+ import { ICreateOrder } from '../api/orders';
7
+ import { ICartItem } from '../http/orders';
6
8
  interface ITreble {
7
9
  player: IThreekitPlayer;
8
10
  orgId: string;
@@ -13,15 +15,19 @@ interface IEmailShareCredentials {
13
15
  from: string;
14
16
  templateId: string;
15
17
  }
18
+ interface IOrder extends Omit<ICreateOrder, 'cart'> {
19
+ cart?: Array<ICartItem>;
20
+ }
16
21
  declare class Treble {
17
22
  _api: typeof threekitAPI;
18
23
  _player: IThreekitPrivatePlayer;
19
24
  wishlist: IWishlist;
20
25
  private _initialConfiguration;
21
26
  private _snapshots;
22
- takeSnapshots: Snapshots['takeSnapshots'];
27
+ takeSnapshots: typeof snapshots['takeSnapshots'];
23
28
  _debugMode: boolean;
24
29
  constructor({ player, orgId, initialConfiguration }: ITreble);
30
+ createOrder: (order?: IOrder) => Promise<import("../http/orders").IOrderResponse>;
25
31
  saveConfiguration: (config?: Partial<Omit<ISaveConfiguration, 'configuration'>>) => Promise<{
26
32
  resumableUrl: string;
27
33
  } & import("../http/configurations").IConfigurationResponse & {
@@ -41,14 +41,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var api_1 = __importDefault(require("../api"));
43
43
  var connection_1 = __importDefault(require("../connection"));
44
+ var types_1 = require("../types");
44
45
  var constants_1 = require("../constants");
45
46
  var utils_1 = require("../utils");
46
- var Wishlist_1 = __importDefault(require("./Wishlist"));
47
- var Snapshots_1 = __importDefault(require("./Snapshots"));
47
+ var wishlist_1 = __importDefault(require("./wishlist"));
48
+ var snapshots_1 = __importDefault(require("./snapshots"));
48
49
  var Treble = (function () {
49
50
  function Treble(_a) {
50
51
  var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
51
52
  var _this = this;
53
+ this.createOrder = function (order) { return __awaiter(_this, void 0, void 0, function () {
54
+ var updatedOrder, configuration, response;
55
+ var _a;
56
+ return __generator(this, function (_b) {
57
+ switch (_b.label) {
58
+ case 0:
59
+ updatedOrder = Object.assign({}, order, (order === null || order === void 0 ? void 0 : order.cart) ? { cart: order.cart } : { cart: [] });
60
+ if (!!(order === null || order === void 0 ? void 0 : order.cart)) return [3, 2];
61
+ return [4, this.saveConfiguration()];
62
+ case 1:
63
+ configuration = _b.sent();
64
+ updatedOrder = Object.assign({}, order, ((_a = order === null || order === void 0 ? void 0 : order.cart) === null || _a === void 0 ? void 0 : _a.length)
65
+ ? { cart: order.cart }
66
+ : {
67
+ cart: [
68
+ {
69
+ count: 1,
70
+ configurationId: configuration.id,
71
+ },
72
+ ],
73
+ });
74
+ _b.label = 2;
75
+ case 2: return [4, api_1.default.orders.createOrder(updatedOrder)];
76
+ case 3:
77
+ response = _b.sent();
78
+ return [2, response];
79
+ }
80
+ });
81
+ }); };
52
82
  this.saveConfiguration = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
83
  var threekitDomain, _a, customerId, metadata, productVersion, attachments, player, response, params, url;
54
84
  var _b;
@@ -58,7 +88,7 @@ var Treble = (function () {
58
88
  case 0:
59
89
  threekitDomain = connection_1.default.getConnection().threekitDomain;
60
90
  _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion, attachments = _a.attachments;
61
- player = window.threekit.player.enableApi('player');
91
+ player = window.threekit.player.enableApi(types_1.PRIVATE_APIS.PLAYER);
62
92
  return [4, api_1.default.configurations.save({
63
93
  assetId: window.threekit.player.assetId,
64
94
  configuration: player.getConfigurator().getFullConfiguration(),
@@ -86,7 +116,7 @@ var Treble = (function () {
86
116
  this.getNestedConfigurator = function (address) {
87
117
  if (!address)
88
118
  return undefined;
89
- var player = window.threekit.player.enableApi('player');
119
+ var player = window.threekit.player.enableApi(types_1.PRIVATE_APIS.PLAYER);
90
120
  var addressArr = Array.isArray(address) ? address : [address];
91
121
  return addressArr.reduce(function (configurator, attributeName) {
92
122
  var _a;
@@ -121,10 +151,10 @@ var Treble = (function () {
121
151
  return api_1.default.server.sendEmail(data);
122
152
  };
123
153
  this._api = api_1.default;
124
- this.wishlist = (0, Wishlist_1.default)(orgId);
125
- this._snapshots = new Snapshots_1.default();
154
+ this.wishlist = (0, wishlist_1.default)(orgId);
155
+ this._snapshots = snapshots_1.default;
126
156
  this.takeSnapshots = this._snapshots.takeSnapshots;
127
- this._player = player.enableApi('player');
157
+ this._player = player.enableApi(types_1.PRIVATE_APIS.PLAYER);
128
158
  this._initialConfiguration = JSON.stringify(initialConfiguration);
129
159
  this._debugMode = constants_1.TREBLE_DEBUG;
130
160
  }
@@ -1,5 +1,5 @@
1
1
  import Treble from './Treble';
2
2
  export * from './Treble';
3
- export * from './Snapshots';
4
- export * from './Wishlist';
3
+ export * from './snapshots';
4
+ export * from './wishlist';
5
5
  export default Treble;
@@ -19,6 +19,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  var Treble_1 = __importDefault(require("./Treble"));
21
21
  __exportStar(require("./Treble"), exports);
22
- __exportStar(require("./Snapshots"), exports);
23
- __exportStar(require("./Wishlist"), exports);
22
+ __exportStar(require("./snapshots"), exports);
23
+ __exportStar(require("./wishlist"), exports);
24
24
  exports.default = Treble_1.default;
@@ -15,13 +15,8 @@ interface IGetSnapshot {
15
15
  size: SnapshotSize;
16
16
  format: string;
17
17
  }
18
- interface ISnapshots {
19
- getSnapshot(snapshotConfig: IGetSnapshot): Promise<string>;
20
- takeSnapshots(cameras: ISnapshotsCameras, config: ITakeSnapshotsConfig): Promise<void | string[] | Blob[] | File[] | null>;
21
- }
22
- declare class Snapshots implements ISnapshots {
23
- constructor();
18
+ declare const _default: {
24
19
  getSnapshot: ({ size, format }: IGetSnapshot) => Promise<string>;
25
- takeSnapshots: (camerasList: ISnapshotsCameras, snapshotsConfig: ITakeSnapshotsConfig) => Promise<void | string[] | Blob[] | File[] | null>;
26
- }
27
- export default Snapshots;
20
+ takeSnapshots: (camerasList: ISnapshotsCameras, snapshotsConfig: ITakeSnapshotsConfig) => Promise<void | string[] | File[] | Blob[] | null>;
21
+ };
22
+ export default _default;
@@ -0,0 +1,247 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var api_1 = __importDefault(require("../api"));
43
+ var constants_1 = require("../constants");
44
+ var types_1 = require("../types");
45
+ var utils_1 = require("../utils");
46
+ var DEFAULT_CAMERA_CONFIG = {
47
+ filename: "snapshot",
48
+ size: { width: 1920, height: 1080 },
49
+ format: types_1.SNAPSHOT_FORMATS.PNG,
50
+ attributeName: constants_1.ATTRIBUTES_RESERVED.camera,
51
+ output: types_1.SNAPSHOT_OUTPUTS.BLOB,
52
+ useStage: false,
53
+ };
54
+ var cameraValues;
55
+ var getCameraValue = function (configurator, cameraAttrName) {
56
+ if (cameraAttrName === void 0) { cameraAttrName = constants_1.ATTRIBUTES_RESERVED.camera; }
57
+ var attribute = configurator
58
+ .getDisplayAttributes()
59
+ .find(function (el) { return el.name === cameraAttrName; });
60
+ if (!attribute)
61
+ return undefined;
62
+ return attribute.value;
63
+ };
64
+ var getCamerasMap = function (configurator, cameraAttrName) {
65
+ if (cameraAttrName === void 0) { cameraAttrName = constants_1.ATTRIBUTES_RESERVED.camera; }
66
+ if (cameraValues)
67
+ return cameraValues;
68
+ var attribute = configurator
69
+ .getDisplayAttributes()
70
+ .find(function (el) { return el.name === cameraAttrName; });
71
+ if (!attribute) {
72
+ cameraValues = {};
73
+ return cameraValues;
74
+ }
75
+ var cameraAttribute = attribute;
76
+ cameraAttribute.values.forEach(function (el) {
77
+ var _a;
78
+ var value = cameraAttribute.type === types_1.ATTRIBUTE_TYPES.ASSET
79
+ ? { assetId: el.assetId }
80
+ : el.value;
81
+ cameraValues = Object.assign(cameraValues || {}, (_a = {},
82
+ _a[el.label] = value,
83
+ _a));
84
+ }, {});
85
+ return cameraValues;
86
+ };
87
+ var getSnapshot = function (_a) {
88
+ var size = _a.size, format = _a.format;
89
+ return window.threekit.player.snapshotAsync({
90
+ size: size,
91
+ mimeType: "image/".concat(types_1.SNAPSHOT_FORMATS[format]),
92
+ });
93
+ };
94
+ var getSnapshots = function (cameras, snapshotConfig) { return __awaiter(void 0, void 0, void 0, function () {
95
+ var attributeName, size, format, configurator, _a, camerasMap, snapshots;
96
+ return __generator(this, function (_b) {
97
+ switch (_b.label) {
98
+ case 0:
99
+ attributeName = snapshotConfig.attributeName || DEFAULT_CAMERA_CONFIG.attributeName;
100
+ size = snapshotConfig.size || DEFAULT_CAMERA_CONFIG.size;
101
+ format = snapshotConfig.format || DEFAULT_CAMERA_CONFIG.format;
102
+ if (!(snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.useStage)) return [3, 2];
103
+ return [4, window.threekit.player.getStageConfigurator()];
104
+ case 1:
105
+ _a = _b.sent();
106
+ return [3, 3];
107
+ case 2:
108
+ _a = window.threekit.configurator;
109
+ _b.label = 3;
110
+ case 3:
111
+ configurator = _a;
112
+ camerasMap = getCamerasMap(configurator, attributeName);
113
+ if (!camerasMap)
114
+ return [2, Promise.resolve([])];
115
+ snapshots = [];
116
+ return [2, cameras.reduce(function (snapshotPromise, camera) {
117
+ return snapshotPromise.then(function () {
118
+ return new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
119
+ var snapshotStr;
120
+ var _a;
121
+ return __generator(this, function (_b) {
122
+ switch (_b.label) {
123
+ case 0:
124
+ if (!camera) return [3, 2];
125
+ return [4, configurator.setConfiguration((_a = {},
126
+ _a[attributeName] = camerasMap[camera],
127
+ _a))];
128
+ case 1:
129
+ _b.sent();
130
+ _b.label = 2;
131
+ case 2: return [4, getSnapshot({ size: size, format: format })];
132
+ case 3:
133
+ snapshotStr = _b.sent();
134
+ snapshots.push(snapshotStr);
135
+ resolve(snapshots);
136
+ return [2];
137
+ }
138
+ });
139
+ }); });
140
+ });
141
+ }, Promise.resolve(snapshots))];
142
+ }
143
+ });
144
+ }); };
145
+ var takeSnapshots = function (camerasList, snapshotsConfig) { return __awaiter(void 0, void 0, void 0, function () {
146
+ var filename, size, format, attributeName, output, configurator, _a, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _b, attachments, response, urlsArray, snapshotBlobs, snapshotFiles;
147
+ var _c;
148
+ return __generator(this, function (_d) {
149
+ switch (_d.label) {
150
+ case 0:
151
+ filename = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.filename) || DEFAULT_CAMERA_CONFIG.filename;
152
+ size = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.size) || DEFAULT_CAMERA_CONFIG.size;
153
+ format = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.format) || DEFAULT_CAMERA_CONFIG.format;
154
+ attributeName = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.attributeName) || DEFAULT_CAMERA_CONFIG.attributeName;
155
+ output = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.output) || DEFAULT_CAMERA_CONFIG.output;
156
+ if (!(snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.useStage)) return [3, 2];
157
+ return [4, window.threekit.player.getStageConfigurator()];
158
+ case 1:
159
+ _a = _d.sent();
160
+ return [3, 3];
161
+ case 2:
162
+ _a = window.threekit.configurator;
163
+ _d.label = 3;
164
+ case 3:
165
+ configurator = _a;
166
+ cameras = Array.isArray(camerasList) ? camerasList : [camerasList];
167
+ if (!(cameras.length === 1 && cameras[0] === undefined)) return [3, 5];
168
+ return [4, getSnapshot({ size: size, format: format })];
169
+ case 4:
170
+ snapshotData = _d.sent();
171
+ snapshotsRaw = [snapshotData];
172
+ return [3, 8];
173
+ case 5:
174
+ camerasMap_1 = getCamerasMap(configurator, attributeName);
175
+ if (!camerasMap_1)
176
+ return [2, null];
177
+ cameras = cameras.filter(function (el) { return el === undefined || Object.keys(camerasMap_1).includes(el); });
178
+ currentCamera = getCameraValue(configurator, attributeName);
179
+ cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
180
+ return [4, getSnapshots(cameras, snapshotsConfig)];
181
+ case 6:
182
+ snapshotsRaw = _d.sent();
183
+ return [4, configurator.setConfiguration((_c = {},
184
+ _c[attributeName] = currentCamera,
185
+ _c))];
186
+ case 7:
187
+ _d.sent();
188
+ (0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
189
+ _d.label = 8;
190
+ case 8:
191
+ _b = output;
192
+ switch (_b) {
193
+ case types_1.SNAPSHOT_OUTPUTS.URL: return [3, 9];
194
+ case types_1.SNAPSHOT_OUTPUTS.DOWNLOAD: return [3, 11];
195
+ case types_1.SNAPSHOT_OUTPUTS.BLOB: return [3, 12];
196
+ case types_1.SNAPSHOT_OUTPUTS.FILE: return [3, 13];
197
+ case types_1.SNAPSHOT_OUTPUTS.DATA_URL: return [3, 14];
198
+ }
199
+ return [3, 14];
200
+ case 9:
201
+ attachments = snapshotsRaw.reduce(function (output, el, idx) {
202
+ var _a;
203
+ var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
204
+ ? (0, utils_1.regularToKebabCase)(camerasList[idx] || 'default')
205
+ : filename;
206
+ var preppedFilename = cameraName === filename
207
+ ? "".concat(filename, ".").concat(format)
208
+ : "".concat(filename, "-").concat(cameraName, ".").concat(format);
209
+ var file = (0, utils_1.dataURItoFile)(el, preppedFilename);
210
+ return Object.assign(output, (_a = {}, _a[cameraName] = file, _a));
211
+ }, {});
212
+ return [4, api_1.default.configurations.save({
213
+ assetId: window.threekit.player.assetId,
214
+ configuration: window.threekit.configurator.getConfiguration(),
215
+ attachments: attachments,
216
+ })];
217
+ case 10:
218
+ response = _d.sent();
219
+ urlsArray = Object.values(response.data.attachments);
220
+ return [2, Promise.resolve(urlsArray)];
221
+ case 11:
222
+ snapshotsRaw.forEach(function (snapshotBlob, idx) {
223
+ var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
224
+ ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
225
+ : '';
226
+ (0, utils_1.downloadSnapshot)(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
227
+ });
228
+ return [2, Promise.resolve()];
229
+ case 12:
230
+ snapshotBlobs = snapshotsRaw.map(function (el) { return (0, utils_1.dataURItoBlob)(el); });
231
+ return [2, Promise.resolve(snapshotBlobs)];
232
+ case 13:
233
+ snapshotFiles = snapshotsRaw.map(function (el, idx) {
234
+ var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
235
+ ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
236
+ : '';
237
+ return (0, utils_1.dataURItoFile)(el, "".concat(filename).concat(cameraName, ".").concat(format));
238
+ });
239
+ return [2, Promise.resolve(snapshotFiles)];
240
+ case 14: return [2, Promise.resolve(snapshotsRaw)];
241
+ }
242
+ });
243
+ }); };
244
+ exports.default = {
245
+ getSnapshot: getSnapshot,
246
+ takeSnapshots: takeSnapshots,
247
+ };
@@ -7,13 +7,9 @@ export interface IWishlist {
7
7
  removeItemByIdx(idx: number): Array<IConfigurationResponse>;
8
8
  clearWishlist(): Array<IConfigurationResponse>;
9
9
  }
10
- declare class Wishlist implements IWishlist {
11
- _wishlistKey: string;
12
- constructor(orgId: string);
10
+ export default function createWishlist(orgId: string): {
13
11
  getWishlist: () => Promise<WishlistArray>;
14
12
  addItem: () => Promise<WishlistArray>;
15
13
  removeItemByIdx: (idx: number) => WishlistArray;
16
14
  clearWishlist: () => WishlistArray;
17
- }
18
- export default function createWishlist(orgId: string): Wishlist;
19
- export {};
15
+ };
@@ -0,0 +1,135 @@
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 constants_1 = require("../constants");
53
+ var wishlistData;
54
+ var wishlistKey;
55
+ var getWishlist = function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var wishlistListStr, wishlistList, wishlistDataRaw;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ if (wishlistData)
61
+ return [2, wishlistData];
62
+ wishlistListStr = localStorage.getItem(wishlistKey);
63
+ wishlistList = JSON.parse(wishlistListStr || '[]');
64
+ return [4, Promise.all(wishlistList.map(function (el) { return api_1.default.configurations.fetch(el); }))];
65
+ case 1:
66
+ wishlistDataRaw = _a.sent();
67
+ wishlistData = wishlistDataRaw.map(function (el) { return el.data; });
68
+ return [2, wishlistData];
69
+ }
70
+ });
71
+ }); };
72
+ var addItem = function () { return __awaiter(void 0, void 0, void 0, function () {
73
+ var thumbnails, savedConfiguration, wishlistListStr, wishlistList;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ if (!wishlistData) {
78
+ wishlistData = [];
79
+ localStorage.setItem(wishlistKey, JSON.stringify([]));
80
+ }
81
+ return [4, window.threekit.treble.takeSnapshots(undefined, {
82
+ output: 'file',
83
+ filename: 'thumbnail',
84
+ })];
85
+ case 1:
86
+ thumbnails = (_a.sent());
87
+ return [4, window.threekit.treble.saveConfiguration({
88
+ attachments: { thumbnail: thumbnails[0] },
89
+ })];
90
+ case 2:
91
+ savedConfiguration = _a.sent();
92
+ if (!savedConfiguration)
93
+ return [2, wishlistData];
94
+ wishlistData = __spreadArray(__spreadArray([], wishlistData, true), [savedConfiguration], false);
95
+ wishlistListStr = localStorage.getItem(wishlistKey);
96
+ wishlistList = JSON.parse(wishlistListStr || '[]');
97
+ wishlistList.push(savedConfiguration.shortId);
98
+ localStorage.setItem(wishlistKey, JSON.stringify(wishlistList));
99
+ return [2, getWishlist()];
100
+ }
101
+ });
102
+ }); };
103
+ var removeItemByIdx = function (idx) {
104
+ if (!(wishlistData === null || wishlistData === void 0 ? void 0 : wishlistData.length)) {
105
+ wishlistData = [];
106
+ localStorage.setItem(wishlistKey, JSON.stringify([]));
107
+ return wishlistData;
108
+ }
109
+ if (idx > (wishlistData === null || wishlistData === void 0 ? void 0 : wishlistData.length) - 1)
110
+ return wishlistData;
111
+ var updatedWishlist = __spreadArray([], wishlistData, true);
112
+ updatedWishlist.splice(idx, 1);
113
+ wishlistData = updatedWishlist;
114
+ var wishlistListStr = localStorage.getItem(wishlistKey);
115
+ var wishlistList = JSON.parse(wishlistListStr || '[]');
116
+ wishlistList.splice(idx, 1);
117
+ localStorage.setItem(wishlistKey, JSON.stringify(wishlistList));
118
+ return wishlistData;
119
+ };
120
+ var clearWishlist = function () {
121
+ wishlistData = [];
122
+ localStorage.setItem(wishlistKey, JSON.stringify([]));
123
+ return wishlistData;
124
+ };
125
+ function createWishlist(orgId) {
126
+ wishlistKey = "".concat(constants_1.WISHLIST_LOCALSTORAGE_KEY, "_").concat(orgId);
127
+ getWishlist();
128
+ return {
129
+ getWishlist: getWishlist,
130
+ addItem: addItem,
131
+ removeItemByIdx: removeItemByIdx,
132
+ clearWishlist: clearWishlist,
133
+ };
134
+ }
135
+ exports.default = createWishlist;
@@ -1,14 +1,12 @@
1
- import { ICart, STATUSES, IOrderResponse } from '../http/orders';
2
- interface IEditOrder extends ICart {
3
- }
4
- interface ICreateOrder extends ICart {
5
- name: string;
1
+ import { ICartItem, STATUSES, IOrderResponse } from '../http/orders';
2
+ export interface ICreateOrder {
3
+ name?: string;
6
4
  metadata?: Record<string, string>;
7
5
  platform?: Record<string, string>;
8
6
  status?: STATUSES;
7
+ cart: Array<ICartItem>;
9
8
  }
10
9
  export declare const getOrder: (orderId: string) => Promise<IOrderResponse>;
11
10
  export declare const fetchOrders: (metadataQuery: Record<string, string>) => Promise<IOrderResponse[]>;
12
11
  export declare const createOrder: (order: ICreateOrder) => Promise<IOrderResponse>;
13
- export declare const editOrder: (orderId: string, data: IEditOrder) => Promise<IOrderResponse>;
14
- export {};
12
+ export declare const editOrder: (orderId: string, data: Array<ICartItem>) => Promise<IOrderResponse>;
@@ -8,7 +8,7 @@ var react_1 = __importDefault(require("react"));
8
8
  var prop_types_1 = __importDefault(require("prop-types"));
9
9
  var attributeValue_styles_1 = require("./attributeValue.styles");
10
10
  var useAttribute_1 = __importDefault(require("../../hooks/useAttribute"));
11
- var constants_1 = require("../../constants");
11
+ var types_1 = require("../../types");
12
12
  var utils_1 = require("../../utils");
13
13
  var AttributeValue = function (props) {
14
14
  var _a, _b;
@@ -17,7 +17,7 @@ var AttributeValue = function (props) {
17
17
  if (!attributeData)
18
18
  return null;
19
19
  var value;
20
- if (attributeData.type === constants_1.ATTRIBUTE_TYPES.asset) {
20
+ if (attributeData.type === types_1.ATTRIBUTE_TYPES.ASSET) {
21
21
  var assetAttribute_1 = attributeData;
22
22
  if (!((_a = assetAttribute_1.value) === null || _a === void 0 ? void 0 : _a.assetId))
23
23
  return null;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import PropTypes from 'prop-types';
3
+ import { ATTRIBUTE_TYPES } from '../../types';
3
4
  import { IFormComponentProps, IOption } from '../containers/formInputContainer';
4
5
  export interface ICards extends IFormComponentProps<IOption> {
5
6
  showThumbnail?: boolean;
@@ -47,7 +48,7 @@ export declare const Cards: {
47
48
  onClick: undefined;
48
49
  };
49
50
  componentName: string;
50
- compatibleAttributes: Set<string>;
51
+ compatibleAttributes: Set<ATTRIBUTE_TYPES>;
51
52
  };
52
53
  declare const _default: (props: ICards) => JSX.Element | null;
53
54
  export default _default;
@@ -11,7 +11,7 @@ var FormComponentDescription_1 = __importDefault(require("../FormComponentDescri
11
11
  var shared_styles_1 = require("../shared.styles");
12
12
  var cards_styles_1 = require("./cards.styles");
13
13
  var utils_1 = require("../../utils");
14
- var constants_1 = require("../../constants");
14
+ var types_1 = require("../../types");
15
15
  var formInputContainer_1 = __importDefault(require("../containers/formInputContainer"));
16
16
  var Thumbnail = function (props) {
17
17
  var imageUrl = props.imageUrl, color = props.color, name = props.name, className = props.className;
@@ -101,7 +101,7 @@ exports.Cards.defaultProps = {
101
101
  };
102
102
  exports.Cards.componentName = 'cards';
103
103
  exports.Cards.compatibleAttributes = new Set([
104
- constants_1.ATTRIBUTE_TYPES.asset,
105
- constants_1.ATTRIBUTE_TYPES.string,
104
+ types_1.ATTRIBUTE_TYPES.ASSET,
105
+ types_1.ATTRIBUTE_TYPES.STRING,
106
106
  ]);
107
107
  exports.default = (0, formInputContainer_1.default)(exports.Cards);
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import PropTypes from 'prop-types';
3
+ import { ATTRIBUTE_TYPES } from '../../types';
3
4
  import { IFormComponentProps, IOption } from '../containers/formInputContainer';
4
5
  export interface IDropdown extends IFormComponentProps<IOption> {
5
6
  showThumbnail?: boolean;
@@ -49,7 +50,7 @@ export declare const Dropdown: {
49
50
  dropdownMaxHeight: string;
50
51
  };
51
52
  componentName: string;
52
- compatibleAttributes: Set<string>;
53
+ compatibleAttributes: Set<ATTRIBUTE_TYPES>;
53
54
  };
54
55
  declare const _default: (props: IDropdown) => JSX.Element | null;
55
56
  export default _default;