@threekit-tools/treble 0.0.81 → 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 (110) hide show
  1. package/dist/Treble/Treble.d.ts +11 -5
  2. package/dist/Treble/Treble.js +41 -12
  3. package/dist/Treble/index.d.ts +2 -2
  4. package/dist/Treble/index.js +7 -3
  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/catalog.js +6 -6
  10. package/dist/api/configurations.js +3 -3
  11. package/dist/api/datatables.js +5 -5
  12. package/dist/api/index.js +5 -1
  13. package/dist/api/orders.d.ts +5 -7
  14. package/dist/api/orders.js +12 -12
  15. package/dist/api/price.js +2 -2
  16. package/dist/api/products.js +2 -2
  17. package/dist/components/Accordion/index.js +6 -7
  18. package/dist/components/AttributeTitle/index.d.ts +0 -9
  19. package/dist/components/AttributeTitle/index.js +0 -9
  20. package/dist/components/AttributeValue/index.d.ts +0 -6
  21. package/dist/components/AttributeValue/index.js +2 -8
  22. package/dist/components/Button/index.d.ts +0 -27
  23. package/dist/components/Button/index.js +0 -27
  24. package/dist/components/Cards/index.d.ts +2 -55
  25. package/dist/components/Cards/index.js +3 -60
  26. package/dist/components/Drawer/index.js +7 -16
  27. package/dist/components/Dropdown/index.d.ts +2 -59
  28. package/dist/components/Dropdown/index.js +11 -72
  29. package/dist/components/FlatForm/index.d.ts +0 -21
  30. package/dist/components/FlatForm/index.js +10 -25
  31. package/dist/components/Modal/index.js +2 -15
  32. package/dist/components/Player/index.d.ts +1 -1
  33. package/dist/components/PortalToArOverlay/index.js +5 -1
  34. package/dist/components/PortalToElement/index.js +0 -8
  35. package/dist/components/ProductDescription/index.d.ts +0 -6
  36. package/dist/components/ProductDescription/index.js +0 -6
  37. package/dist/components/ProductName/index.d.ts +0 -9
  38. package/dist/components/ProductName/index.js +0 -9
  39. package/dist/components/Share/index.d.ts +0 -12
  40. package/dist/components/Share/index.js +2 -14
  41. package/dist/components/Snapshots/index.d.ts +0 -8
  42. package/dist/components/Snapshots/index.js +2 -10
  43. package/dist/components/Strips/index.d.ts +2 -55
  44. package/dist/components/Strips/index.js +3 -60
  45. package/dist/components/Swatch/index.d.ts +2 -64
  46. package/dist/components/Swatch/index.js +3 -69
  47. package/dist/components/Switch/index.d.ts +2 -34
  48. package/dist/components/Switch/index.js +2 -38
  49. package/dist/components/Tabs/index.js +5 -1
  50. package/dist/components/TextInput/index.d.ts +2 -1
  51. package/dist/components/TextInput/index.js +2 -3
  52. package/dist/components/ThreekitProvider/index.js +5 -1
  53. package/dist/components/Tiles/index.d.ts +2 -29
  54. package/dist/components/Tiles/index.js +3 -33
  55. package/dist/components/TilesGroup/index.d.ts +2 -26
  56. package/dist/components/TilesGroup/index.js +3 -30
  57. package/dist/components/TotalPrice/index.d.ts +0 -6
  58. package/dist/components/TotalPrice/index.js +0 -6
  59. package/dist/components/TrebleApp/index.js +5 -1
  60. package/dist/components/Upload/index.d.ts +2 -1
  61. package/dist/components/Upload/index.js +21 -17
  62. package/dist/components/UploadArea/index.d.ts +2 -1
  63. package/dist/components/UploadArea/index.js +18 -15
  64. package/dist/components/Wishlist/index.d.ts +0 -3
  65. package/dist/components/Wishlist/index.js +12 -10
  66. package/dist/components/Zoom/index.d.ts +0 -17
  67. package/dist/components/Zoom/index.js +5 -21
  68. package/dist/components/formComponents.d.ts +12 -0
  69. package/dist/components/formComponents.js +10 -8
  70. package/dist/components/message/index.d.ts +0 -9
  71. package/dist/components/message/index.js +4 -31
  72. package/dist/connection.js +2 -2
  73. package/dist/constants.d.ts +0 -49
  74. package/dist/constants.js +1 -59
  75. package/dist/hooks/useAttribute/index.d.ts +1 -1
  76. package/dist/hooks/useAttribute/index.js +6 -6
  77. package/dist/hooks/useConfigurationLoader/index.js +5 -5
  78. package/dist/hooks/useNestedConfigurator/index.js +2 -2
  79. package/dist/hooks/useShare/index.js +3 -3
  80. package/dist/hooks/useSingleAnimation/index.js +20 -25
  81. package/dist/http/datatables.js +0 -1
  82. package/dist/http/index.js +5 -1
  83. package/dist/http/orders.d.ts +6 -8
  84. package/dist/icons/Spinner.js +5 -1
  85. package/dist/icons/index.d.ts +0 -41
  86. package/dist/icons/index.js +0 -42
  87. package/dist/index.d.ts +42 -3
  88. package/dist/index.js +84 -26
  89. package/dist/store/attributes.d.ts +0 -12
  90. package/dist/store/attributes.js +2 -15
  91. package/dist/store/index.d.ts +1 -1
  92. package/dist/store/price.d.ts +0 -12
  93. package/dist/store/price.js +2 -16
  94. package/dist/store/product.d.ts +6 -21
  95. package/dist/store/product.js +26 -38
  96. package/dist/store/translations.d.ts +1 -13
  97. package/dist/store/translations.js +2 -12
  98. package/dist/store/treble.d.ts +1 -16
  99. package/dist/store/treble.js +31 -66
  100. package/dist/store/wishlist.d.ts +0 -12
  101. package/dist/store/wishlist.js +4 -17
  102. package/dist/types.d.ts +118 -65
  103. package/dist/types.js +54 -0
  104. package/dist/utils.d.ts +10 -10
  105. package/dist/utils.js +8 -16
  106. package/package.json +16 -4
  107. package/dist/Treble/Snapshots.js +0 -251
  108. package/dist/Treble/Wishlist.js +0 -136
  109. package/dist/hooks/useImageEditor/index.d.ts +0 -14
  110. package/dist/hooks/useImageEditor/index.js +0 -320
@@ -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,22 +15,26 @@ 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);
25
- saveConfiguration: (config?: Partial<Omit<ISaveConfiguration, "configuration">> | undefined) => Promise<{
30
+ createOrder: (order?: IOrder) => Promise<import("../http/orders").IOrderResponse>;
31
+ saveConfiguration: (config?: Partial<Omit<ISaveConfiguration, 'configuration'>>) => Promise<{
26
32
  resumableUrl: string;
27
33
  } & import("../http/configurations").IConfigurationResponse & {
28
34
  thumbnail: string;
29
35
  }>;
30
36
  getNestedConfigurator: (address: string | Array<string>) => undefined | IThreekitPrivateConfigurator;
31
- resetConfiguration: (configuration?: ISetConfiguration | undefined) => void;
37
+ resetConfiguration: (configuration?: ISetConfiguration) => void;
32
38
  sendEmail: (credentials: IEmailShareCredentials, templateData: Record<string, any>) => Promise<import("../http/server").IPostEmailResponse>;
33
39
  }
34
40
  export default Treble;
@@ -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"));
48
- var Treble = /** @class */ (function () {
47
+ var wishlist_1 = __importDefault(require("./wishlist"));
48
+ var snapshots_1 = __importDefault(require("./snapshots"));
49
+ var Treble = (function () {
49
50
  function Treble(_a) {
50
- var _this = this;
51
51
  var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
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,8 +88,8 @@ var Treble = /** @class */ (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');
62
- return [4 /*yield*/, api_1.default.configurations.save({
91
+ player = window.threekit.player.enableApi(types_1.PRIVATE_APIS.PLAYER);
92
+ return [4, api_1.default.configurations.save({
63
93
  assetId: window.threekit.player.assetId,
64
94
  configuration: player.getConfigurator().getFullConfiguration(),
65
95
  customerId: customerId,
@@ -73,7 +103,7 @@ var Treble = /** @class */ (function () {
73
103
  _b[constants_1.TK_SAVED_CONFIG_PARAM_KEY] = response.data.shortId,
74
104
  _b));
75
105
  url = window.location.href.replace(window.location.search, '');
76
- return [2 /*return*/, Object.assign({
106
+ return [2, Object.assign({
77
107
  resumableUrl: "".concat(url).concat((0, utils_1.objectToQueryStr)(params)),
78
108
  }, response.data, ((_c = response.data.thumbnail) === null || _c === void 0 ? void 0 : _c.length)
79
109
  ? {
@@ -86,7 +116,7 @@ var Treble = /** @class */ (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;
@@ -120,12 +150,11 @@ var Treble = /** @class */ (function () {
120
150
  }, { TemplateModel: templateData });
121
151
  return api_1.default.server.sendEmail(data);
122
152
  };
123
- // Threekit API
124
153
  this._api = api_1.default;
125
- this.wishlist = (0, Wishlist_1.default)(orgId);
126
- this._snapshots = new Snapshots_1.default();
154
+ this.wishlist = (0, wishlist_1.default)(orgId);
155
+ this._snapshots = snapshots_1.default;
127
156
  this.takeSnapshots = this._snapshots.takeSnapshots;
128
- this._player = player.enableApi('player');
157
+ this._player = player.enableApi(types_1.PRIVATE_APIS.PLAYER);
129
158
  this._initialConfiguration = JSON.stringify(initialConfiguration);
130
159
  this._debugMode = constants_1.TREBLE_DEBUG;
131
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;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -15,6 +19,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
19
  Object.defineProperty(exports, "__esModule", { value: true });
16
20
  var Treble_1 = __importDefault(require("./Treble"));
17
21
  __exportStar(require("./Treble"), exports);
18
- __exportStar(require("./Snapshots"), exports);
19
- __exportStar(require("./Wishlist"), exports);
22
+ __exportStar(require("./snapshots"), exports);
23
+ __exportStar(require("./wishlist"), exports);
20
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;
@@ -52,20 +52,20 @@ var uploadAsset = function (file) { return __awaiter(void 0, void 0, void 0, fun
52
52
  throw new Error(error);
53
53
  formData = new FormData();
54
54
  formData.append('files', file, file.name);
55
- return [4 /*yield*/, http_1.default.catalog.uploadAsset(formData)];
55
+ return [4, http_1.default.catalog.uploadAsset(formData)];
56
56
  case 1:
57
57
  uploadResponse = _a.sent();
58
58
  jobId = uploadResponse.data[0].jobId;
59
59
  count = 30;
60
60
  _a.label = 2;
61
61
  case 2:
62
- if (!(count > 1 && !assetId)) return [3 /*break*/, 5];
63
- return [4 /*yield*/, new Promise(function (resolve) {
62
+ if (!(count > 1 && !assetId)) return [3, 5];
63
+ return [4, new Promise(function (resolve) {
64
64
  return setTimeout(function () { return resolve(undefined); }, 0.5 * 1000);
65
65
  })];
66
66
  case 3:
67
67
  _a.sent();
68
- return [4 /*yield*/, http_1.default.catalog.getJobStatus(jobId)];
68
+ return [4, http_1.default.catalog.getJobStatus(jobId)];
69
69
  case 4:
70
70
  checkRes = _a.sent();
71
71
  ++count;
@@ -78,8 +78,8 @@ var uploadAsset = function (file) { return __awaiter(void 0, void 0, void 0, fun
78
78
  assetId = output.vector[0].assetId;
79
79
  }
80
80
  }
81
- return [3 /*break*/, 2];
82
- case 5: return [2 /*return*/, assetId];
81
+ return [3, 2];
82
+ case 5: return [2, assetId];
83
83
  }
84
84
  });
85
85
  }); };
@@ -71,7 +71,7 @@ var save = function (saveConfig) { return __awaiter(void 0, void 0, void 0, func
71
71
  });
72
72
  fd.append('attachments', JSON.stringify(attachmentsPrepped_1));
73
73
  }
74
- return [2 /*return*/, http_1.default.configurations.postConfiguration(fd)];
74
+ return [2, http_1.default.configurations.postConfiguration(fd)];
75
75
  });
76
76
  }); };
77
77
  exports.save = save;
@@ -89,11 +89,11 @@ var fetchAll = function () {
89
89
  var configurations;
90
90
  return __generator(this, function (_a) {
91
91
  switch (_a.label) {
92
- case 0: return [4 /*yield*/, http_1.default.configurations.getConfigurations()];
92
+ case 0: return [4, http_1.default.configurations.getConfigurations()];
93
93
  case 1:
94
94
  configurations = _a.sent();
95
95
  resolve(configurations.data.configurations);
96
- return [2 /*return*/];
96
+ return [2];
97
97
  }
98
98
  });
99
99
  }); });