@threekit-tools/treble 0.0.57-animation → 0.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/Treble/Snapshots.js +32 -63
  2. package/dist/Treble/Treble.d.ts +8 -6
  3. package/dist/Treble/Treble.js +19 -4
  4. package/dist/Treble/Wishlist.d.ts +3 -3
  5. package/dist/Treble/Wishlist.js +1 -0
  6. package/dist/api/configurations.d.ts +2 -3
  7. package/dist/api/configurations.js +28 -22
  8. package/dist/api/index.d.ts +2 -0
  9. package/dist/api/index.js +2 -0
  10. package/dist/api/server.d.ts +2 -0
  11. package/dist/api/server.js +11 -0
  12. package/dist/components/Cards/index.js +3 -4
  13. package/dist/components/Dropdown/index.js +6 -10
  14. package/dist/components/Strips/index.js +3 -4
  15. package/dist/components/Swatch/index.js +3 -4
  16. package/dist/components/TextInput/index.d.ts +1 -0
  17. package/dist/components/TextInput/index.js +2 -2
  18. package/dist/components/TextInput/textInput.styles.js +1 -1
  19. package/dist/components/Tiles/index.js +3 -4
  20. package/dist/components/TilesGroup/index.js +3 -4
  21. package/dist/components/containers/formInputContainer.d.ts +8 -4
  22. package/dist/components/containers/formInputContainer.js +10 -15
  23. package/dist/connection.d.ts +4 -1
  24. package/dist/connection.js +4 -0
  25. package/dist/hooks/useAttribute/index.d.ts +2 -2
  26. package/dist/hooks/useAttribute/index.js +2 -4
  27. package/dist/hooks/useConfigurator/index.d.ts +2 -2
  28. package/dist/hooks/useConfigurator/index.js +1 -1
  29. package/dist/hooks/useProductCache/index.d.ts +14 -0
  30. package/dist/hooks/useProductCache/index.js +35 -0
  31. package/dist/hooks/useWishlist/index.d.ts +3 -2
  32. package/dist/hooks/useWishlist/index.js +1 -3
  33. package/dist/http/configurations.d.ts +1 -0
  34. package/dist/http/index.d.ts +2 -0
  35. package/dist/http/index.js +2 -0
  36. package/dist/http/server.d.ts +14 -0
  37. package/dist/http/server.js +17 -0
  38. package/dist/index.d.ts +2 -1
  39. package/dist/index.js +4 -1
  40. package/dist/store/attributes.d.ts +15 -2
  41. package/dist/store/attributes.js +20 -12
  42. package/dist/store/price.js +2 -2
  43. package/dist/store/product.d.ts +38 -2
  44. package/dist/store/product.js +221 -10
  45. package/dist/store/translations.d.ts +1 -0
  46. package/dist/store/translations.js +3 -1
  47. package/dist/store/treble.d.ts +32 -2
  48. package/dist/store/treble.js +157 -34
  49. package/dist/store/wishlist.d.ts +3 -2
  50. package/dist/threekit.d.ts +16 -1
  51. package/dist/utils.d.ts +1 -9
  52. package/dist/utils.js +58 -54
  53. package/package.json +1 -1
  54. package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
  55. package/dist/hooks/useArrayAttribute/index.js +0 -184
@@ -129,53 +129,12 @@ var Snapshots = /** @class */ (function () {
129
129
  }, Promise.resolve(snapshots));
130
130
  };
131
131
  this.takeSnapshots = function (camerasList, snapshotsConfig) { return __awaiter(_this, void 0, void 0, function () {
132
- function saveSnapshotToPlatform(snapshot, filename) {
133
- return __awaiter(this, void 0, void 0, function () {
134
- var files, response;
135
- return __generator(this, function (_a) {
136
- switch (_a.label) {
137
- case 0:
138
- files = (0, utils_1.dataURItoFile)(snapshot, filename);
139
- return [4 /*yield*/, api_1.default.configurations.save({
140
- assetId: window.threekit.player.assetId,
141
- configuration: window.threekit.configurator.getConfiguration(),
142
- files: files,
143
- })];
144
- case 1:
145
- response = _a.sent();
146
- return [2 /*return*/, "".concat(threekitDomain, "/api/files/hash/").concat(response.data.thumbnail)];
147
- }
148
- });
149
- });
150
- }
151
- function downloadSnapshot(snapshot, filename) {
152
- return __awaiter(this, void 0, void 0, function () {
153
- var blob, blobUrl, link, clickHandler;
154
- return __generator(this, function (_a) {
155
- blob = (0, utils_1.dataURItoBlob)(snapshot);
156
- blobUrl = URL.createObjectURL(blob);
157
- link = document.createElement('a');
158
- link.href = blobUrl;
159
- link.download = filename;
160
- clickHandler = function () {
161
- setTimeout(function () {
162
- URL.revokeObjectURL(blobUrl);
163
- link.removeEventListener('click', clickHandler);
164
- }, 150);
165
- };
166
- link.addEventListener('click', clickHandler);
167
- document.body.appendChild(link);
168
- link.click();
169
- return [2 /*return*/];
170
- });
171
- });
172
- }
173
- var threekitDomain, filename, size, format, attributeName, output, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _a, savedSnapshots, snapshotBlobs, snapshotFiles;
174
- var _b;
175
- return __generator(this, function (_c) {
176
- switch (_c.label) {
132
+ var _a, threekitDomain, orgId, filename, size, format, attributeName, output, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _b, attachments, response_1, urlsArray, snapshotBlobs, snapshotFiles;
133
+ var _c;
134
+ return __generator(this, function (_d) {
135
+ switch (_d.label) {
177
136
  case 0:
178
- threekitDomain = connection_1.default.getConnection().threekitDomain;
137
+ _a = connection_1.default.getConnection(), threekitDomain = _a.threekitDomain, orgId = _a.orgId;
179
138
  filename = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.filename) || DEFAULT_CAMERA_CONFIG.filename;
180
139
  size = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.size) || DEFAULT_CAMERA_CONFIG.size;
181
140
  format = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.format) || DEFAULT_CAMERA_CONFIG.format;
@@ -185,7 +144,7 @@ var Snapshots = /** @class */ (function () {
185
144
  if (!(cameras.length === 1 && cameras[0] === undefined)) return [3 /*break*/, 2];
186
145
  return [4 /*yield*/, this.getSnapshot({ size: size, format: format })];
187
146
  case 1:
188
- snapshotData = _c.sent();
147
+ snapshotData = _d.sent();
189
148
  snapshotsRaw = [snapshotData];
190
149
  return [3 /*break*/, 5];
191
150
  case 2:
@@ -197,17 +156,17 @@ var Snapshots = /** @class */ (function () {
197
156
  cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
198
157
  return [4 /*yield*/, this.getSnapshots(cameras, camerasMap_1)];
199
158
  case 3:
200
- snapshotsRaw = _c.sent();
201
- return [4 /*yield*/, window.threekit.configurator.setConfiguration((_b = {},
202
- _b[attributeName] = currentCamera,
203
- _b))];
159
+ snapshotsRaw = _d.sent();
160
+ return [4 /*yield*/, window.threekit.configurator.setConfiguration((_c = {},
161
+ _c[attributeName] = currentCamera,
162
+ _c))];
204
163
  case 4:
205
- _c.sent();
164
+ _d.sent();
206
165
  (0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
207
- _c.label = 5;
166
+ _d.label = 5;
208
167
  case 5:
209
- _a = output;
210
- switch (_a) {
168
+ _b = output;
169
+ switch (_b) {
211
170
  case constants_1.SNAPSHOT_OUTPUTS.url: return [3 /*break*/, 6];
212
171
  case constants_1.SNAPSHOT_OUTPUTS.download: return [3 /*break*/, 8];
213
172
  case constants_1.SNAPSHOT_OUTPUTS.blob: return [3 /*break*/, 9];
@@ -215,21 +174,32 @@ var Snapshots = /** @class */ (function () {
215
174
  case constants_1.SNAPSHOT_OUTPUTS.dataUrl: return [3 /*break*/, 11];
216
175
  }
217
176
  return [3 /*break*/, 11];
218
- case 6: return [4 /*yield*/, Promise.all(snapshotsRaw.map(function (snapshotBlob, idx) {
177
+ case 6:
178
+ attachments = snapshotsRaw.reduce(function (output, el, idx) {
179
+ var _a;
219
180
  var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
220
- ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
181
+ ? (0, utils_1.regularToKebabCase)(camerasList[idx] || 'default')
221
182
  : '';
222
- return saveSnapshotToPlatform(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
223
- }))];
183
+ var file = (0, utils_1.dataURItoFile)(el, "".concat(filename, "-").concat(cameraName, ".").concat(format));
184
+ return Object.assign(output, (_a = {}, _a[cameraName] = file, _a));
185
+ }, {});
186
+ return [4 /*yield*/, api_1.default.configurations.save({
187
+ assetId: window.threekit.player.assetId,
188
+ configuration: window.threekit.configurator.getConfiguration(),
189
+ attachments: attachments,
190
+ })];
224
191
  case 7:
225
- savedSnapshots = _c.sent();
226
- return [2 /*return*/, Promise.resolve(savedSnapshots)];
192
+ response_1 = _d.sent();
193
+ urlsArray = Object.keys(response_1.data.attachments).map(function (key) {
194
+ return "".concat(threekitDomain, "/api/configurations/").concat(response_1.data.shortId, "/files/").concat(key, "?orgId=").concat(orgId);
195
+ });
196
+ return [2 /*return*/, Promise.resolve(urlsArray)];
227
197
  case 8:
228
198
  snapshotsRaw.forEach(function (snapshotBlob, idx) {
229
199
  var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
230
200
  ? "-".concat((0, utils_1.regularToKebabCase)(camerasList[idx] || 'default'))
231
201
  : '';
232
- downloadSnapshot(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
202
+ (0, utils_1.downloadSnapshot)(snapshotBlob, "".concat(filename).concat(cameraName, ".").concat(format));
233
203
  });
234
204
  return [2 /*return*/, Promise.resolve()];
235
205
  case 9:
@@ -244,7 +214,6 @@ var Snapshots = /** @class */ (function () {
244
214
  });
245
215
  return [2 /*return*/, Promise.resolve(snapshotFiles)];
246
216
  case 11: return [2 /*return*/, Promise.resolve(snapshotsRaw)];
247
- case 12: return [2 /*return*/];
248
217
  }
249
218
  });
250
219
  }); };
@@ -1,16 +1,17 @@
1
1
  import threekitAPI from '../api';
2
- import { IThreekitPlayer, IMetadata, IConfiguration, ISetConfiguration } from '../threekit';
2
+ import { IThreekitPlayer, IConfiguration, ISetConfiguration } from '../threekit';
3
3
  import { IWishlist } from './Wishlist';
4
4
  import Snapshots from './Snapshots';
5
+ import { ISaveConfiguration } from '../api/configurations';
5
6
  interface ITreble {
6
7
  player: IThreekitPlayer;
7
8
  orgId: string;
8
9
  initialConfiguration: IConfiguration;
9
10
  }
10
- export interface ISaveConfigurationConfig {
11
- customerId?: string;
12
- metadata?: IMetadata;
13
- productVersion?: string;
11
+ interface IEmailShareCredentials {
12
+ to: string;
13
+ from: string;
14
+ templateId: string;
14
15
  }
15
16
  declare class Treble {
16
17
  _api: typeof threekitAPI;
@@ -20,12 +21,13 @@ declare class Treble {
20
21
  private _snapshots;
21
22
  takeSnapshots: Snapshots['takeSnapshots'];
22
23
  constructor({ player, orgId, initialConfiguration }: ITreble);
23
- saveConfiguration: (config?: ISaveConfigurationConfig | undefined) => Promise<{
24
+ saveConfiguration: (config?: Omit<ISaveConfiguration, "configuration"> | undefined) => Promise<{
24
25
  resumableUrl: string;
25
26
  } & import("../http/configurations").IConfigurationResponse & {
26
27
  thumbnail: string;
27
28
  }>;
28
29
  getNestedConfigurator: (address: string | Array<string>) => any;
29
30
  resetConfiguration: (configuration?: ISetConfiguration | undefined) => void;
31
+ sendEmail: (credentials: IEmailShareCredentials, templateData: Record<string, any>) => Promise<import("../http/server").IPostEmailResponse>;
30
32
  }
31
33
  export default Treble;
@@ -50,22 +50,21 @@ var Treble = /** @class */ (function () {
50
50
  var _this = this;
51
51
  var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
52
52
  this.saveConfiguration = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
- var threekitDomain, _a, customerId, metadata, productVersion, files, response, params, url;
53
+ var threekitDomain, _a, customerId, metadata, productVersion, attachments, response, params, url;
54
54
  var _b;
55
55
  var _c;
56
56
  return __generator(this, function (_d) {
57
57
  switch (_d.label) {
58
58
  case 0:
59
59
  threekitDomain = connection_1.default.getConnection().threekitDomain;
60
- _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion;
61
- files = undefined;
60
+ _a = Object.assign({}, config), customerId = _a.customerId, metadata = _a.metadata, productVersion = _a.productVersion, attachments = _a.attachments;
62
61
  return [4 /*yield*/, api_1.default.configurations.save({
63
62
  assetId: window.threekit.player.assetId,
64
63
  configuration: window.threekit.configurator.getConfiguration(),
65
64
  customerId: customerId,
66
65
  metadata: metadata,
67
66
  productVersion: productVersion,
68
- files: files,
67
+ attachments: attachments,
69
68
  })];
70
69
  case 1:
71
70
  response = _d.sent();
@@ -99,6 +98,22 @@ var Treble = /** @class */ (function () {
99
98
  var updateConfiguration = Object.assign(initialConfiguration, configuration);
100
99
  window.threekit.configurator.setConfiguration(updateConfiguration);
101
100
  };
101
+ this.sendEmail = function (credentials, templateData) {
102
+ if (!credentials)
103
+ throw new Error('sendEmail is missing credentials object');
104
+ if (!credentials.from.length)
105
+ throw new Error('sendEmail is missing sender email - "From"');
106
+ if (!credentials.to.length)
107
+ throw new Error('sendEmail is missing receivers email - "To"');
108
+ if (!credentials.templateId.length)
109
+ throw new Error('sendEmail is missing the templateId to use - "TemplateId"');
110
+ var data = Object.assign({
111
+ To: credentials.to,
112
+ From: credentials.from,
113
+ TemplateId: credentials.templateId,
114
+ }, { TemplateModel: templateData });
115
+ return api_1.default.server.sendEmail(data);
116
+ };
102
117
  // Threekit API
103
118
  this._api = api_1.default;
104
119
  this._player = player;
@@ -1,9 +1,9 @@
1
1
  import { IConfigurationResponse } from '../http/configurations';
2
- import { ISaveConfigurationConfig } from './Treble';
2
+ import { ISaveConfiguration } from '../api/configurations';
3
3
  export declare type WishlistArray = Array<IConfigurationResponse>;
4
4
  export interface IWishlist {
5
5
  getWishlist(): Promise<Array<IConfigurationResponse>>;
6
- addItem(config?: ISaveConfigurationConfig): Promise<Array<IConfigurationResponse>>;
6
+ addItem(config?: Omit<ISaveConfiguration, 'configurator'>): Promise<Array<IConfigurationResponse>>;
7
7
  removeItemByIdx(idx: number): Array<IConfigurationResponse>;
8
8
  clearWishlist(): Array<IConfigurationResponse>;
9
9
  }
@@ -11,7 +11,7 @@ declare class Wishlist implements IWishlist {
11
11
  _wishlistKey: string;
12
12
  constructor(orgId: string);
13
13
  getWishlist: () => Promise<WishlistArray>;
14
- addItem: (config?: ISaveConfigurationConfig | undefined) => Promise<WishlistArray>;
14
+ addItem: (config?: Omit<ISaveConfiguration, "configurator"> | undefined) => Promise<WishlistArray>;
15
15
  removeItemByIdx: (idx: number) => WishlistArray;
16
16
  clearWishlist: () => WishlistArray;
17
17
  }
@@ -128,6 +128,7 @@ var Wishlist = /** @class */ (function () {
128
128
  };
129
129
  this._wishlistKey = "".concat(constants_1.WISHLIST_LOCALSTORAGE_KEY, "_").concat(orgId);
130
130
  this.getWishlist();
131
+ return this;
131
132
  }
132
133
  return Wishlist;
133
134
  }());
@@ -1,14 +1,13 @@
1
1
  import { IConfigurationResponse } from '../http/configurations';
2
2
  import { IConfiguration, IMetadata } from '../threekit';
3
- interface ISaveConfiguration {
3
+ export interface ISaveConfiguration {
4
4
  assetId: string;
5
5
  customerId?: string;
6
6
  configuration: IConfiguration;
7
7
  metadata?: IMetadata;
8
8
  productVersion?: string;
9
- files?: File;
9
+ attachments?: Record<string, File>;
10
10
  }
11
11
  export declare const save: (saveConfig: ISaveConfiguration) => Promise<import("axios").AxiosResponse<IConfigurationResponse>>;
12
12
  export declare const fetch: (configurationId: string) => Promise<import("axios").AxiosResponse<IConfigurationResponse>>;
13
13
  export declare const fetchAll: () => Promise<IConfigurationResponse[]>;
14
- export {};
@@ -42,30 +42,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.fetchAll = exports.fetch = exports.save = void 0;
43
43
  var http_1 = __importDefault(require("../http"));
44
44
  var save = function (saveConfig) { return __awaiter(void 0, void 0, void 0, function () {
45
- var assetId, customerId, configuration, metadata, productVersion, files, error, fd;
45
+ var assetId, customerId, configuration, metadata, productVersion, attachments, error, fd, attachmentsPrepped_1;
46
46
  return __generator(this, function (_a) {
47
- switch (_a.label) {
48
- case 0:
49
- assetId = saveConfig.assetId, customerId = saveConfig.customerId, configuration = saveConfig.configuration, metadata = saveConfig.metadata, productVersion = saveConfig.productVersion, files = saveConfig.files;
50
- if (!assetId)
51
- error = 'Requires Asset Id';
52
- if (!configuration)
53
- error = 'Requires a configuration';
54
- if (error)
55
- throw new Error(error);
56
- fd = new FormData();
57
- fd.append('productId', assetId);
58
- fd.append('variant', JSON.stringify(configuration));
59
- fd.append('productVersion', productVersion || 'v1');
60
- if (metadata && Object.keys(metadata))
61
- fd.append('metadata', JSON.stringify(metadata));
62
- if (customerId)
63
- fd.append('customerId', customerId);
64
- if (files)
65
- fd.append('files', files);
66
- return [4 /*yield*/, http_1.default.configurations.postConfiguration(fd)];
67
- case 1: return [2 /*return*/, _a.sent()];
47
+ assetId = saveConfig.assetId, customerId = saveConfig.customerId, configuration = saveConfig.configuration, metadata = saveConfig.metadata, productVersion = saveConfig.productVersion, attachments = saveConfig.attachments;
48
+ if (!assetId)
49
+ error = 'Requires Asset Id';
50
+ if (!configuration)
51
+ error = 'Requires a configuration';
52
+ if (error)
53
+ throw new Error(error);
54
+ fd = new FormData();
55
+ fd.append('productId', assetId);
56
+ fd.append('variant', JSON.stringify(configuration));
57
+ fd.append('productVersion', productVersion || 'v1');
58
+ if (metadata && Object.keys(metadata))
59
+ fd.append('metadata', JSON.stringify(metadata));
60
+ if (customerId)
61
+ fd.append('customerId', customerId);
62
+ if (attachments && Object.keys(attachments).length) {
63
+ attachmentsPrepped_1 = {};
64
+ Object.entries(attachments).forEach(function (_a) {
65
+ var _b;
66
+ var key = _a[0], file = _a[1];
67
+ fd.append('files', file);
68
+ attachmentsPrepped_1 = Object.assign({}, attachmentsPrepped_1, (_b = {},
69
+ _b[key] = file.name,
70
+ _b));
71
+ });
72
+ fd.append('attachments', JSON.stringify(attachmentsPrepped_1));
68
73
  }
74
+ return [2 /*return*/, http_1.default.configurations.postConfiguration(fd)];
69
75
  });
70
76
  }); };
71
77
  exports.save = save;
@@ -3,11 +3,13 @@ import * as configurations from './configurations';
3
3
  import * as price from './price';
4
4
  import * as orders from './orders';
5
5
  import * as catalog from './catalog';
6
+ import * as server from './server';
6
7
  declare const _default: {
7
8
  products: typeof products;
8
9
  configurations: typeof configurations;
9
10
  price: typeof price;
10
11
  orders: typeof orders;
11
12
  catalog: typeof catalog;
13
+ server: typeof server;
12
14
  };
13
15
  export default _default;
package/dist/api/index.js CHANGED
@@ -24,10 +24,12 @@ var configurations = __importStar(require("./configurations"));
24
24
  var price = __importStar(require("./price"));
25
25
  var orders = __importStar(require("./orders"));
26
26
  var catalog = __importStar(require("./catalog"));
27
+ var server = __importStar(require("./server"));
27
28
  exports.default = {
28
29
  products: products,
29
30
  configurations: configurations,
30
31
  price: price,
31
32
  orders: orders,
32
33
  catalog: catalog,
34
+ server: server,
33
35
  };
@@ -0,0 +1,2 @@
1
+ import { IPostEmailRequest } from '../http/server';
2
+ export declare const sendEmail: (data: IPostEmailRequest) => Promise<import("../http/server").IPostEmailResponse>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sendEmail = void 0;
7
+ var http_1 = __importDefault(require("../http"));
8
+ var sendEmail = function (data) {
9
+ return http_1.default.server.postEmail(data);
10
+ };
11
+ exports.sendEmail = sendEmail;
@@ -38,7 +38,7 @@ var Price = function (props) {
38
38
  return react_1.default.createElement(cards_styles_1.CardPrice, { className: "".concat(className, " option-price") }, price);
39
39
  };
40
40
  var Cards = function (props) {
41
- var title = props.title, description = props.description, options = props.options, value = props.value, onClick = props.onClick, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription;
41
+ var title = props.title, description = props.description, options = props.options, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription;
42
42
  var cls = (0, utils_1.generateInputClassName)('cards', customClassName, title);
43
43
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
44
44
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
@@ -50,10 +50,9 @@ var Cards = function (props) {
50
50
  imageUrl: !showThumbnail ? undefined : el.imageUrl,
51
51
  price: !showPrice ? undefined : el.price,
52
52
  description: !showDescription ? undefined : el.description,
53
- }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue;
54
- var selected = value === optionValue;
53
+ }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue, selected = _a.selected, handleSelect = _a.handleSelect;
55
54
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
56
- return (react_1.default.createElement(cards_styles_1.CardWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt },
55
+ return (react_1.default.createElement(cards_styles_1.CardWrapper, { key: i, onClick: handleSelect, selected: selected, className: clsOpt },
57
56
  react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, name: name, className: clsOpt }),
58
57
  react_1.default.createElement("div", null,
59
58
  react_1.default.createElement(Title, { name: name, className: clsOpt }),
@@ -57,7 +57,7 @@ var Price = function (props) {
57
57
  return (react_1.default.createElement(dropdown_styles_1.OptionPrice, { className: "".concat(className, " option-price") }, price));
58
58
  };
59
59
  var Dropdown = function (props) {
60
- var title = props.title, description = props.description, options = props.options, value = props.value, onClick = props.onClick, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription, dropdownMaxHeight = props.dropdownMaxHeight;
60
+ var title = props.title, description = props.description, options = props.options, value = props.value, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription, dropdownMaxHeight = props.dropdownMaxHeight;
61
61
  var _a = (0, react_1.useState)(true), hide = _a[0], setHide = _a[1];
62
62
  var ref = (0, react_1.useRef)(null);
63
63
  (0, react_1.useEffect)(function () {
@@ -73,12 +73,6 @@ var Dropdown = function (props) {
73
73
  document.removeEventListener('mousedown', handleClickOutside);
74
74
  };
75
75
  }, [hide, ref]);
76
- var handleClick = function (value) {
77
- if (!onClick)
78
- return;
79
- onClick(value);
80
- setHide(true);
81
- };
82
76
  var cls = (0, utils_1.generateInputClassName)('dropdown', customClassName, title);
83
77
  var selectedOpt = options === null || options === void 0 ? void 0 : options.find(function (el) { return el.value === value; });
84
78
  return (react_1.default.createElement("div", { className: cls },
@@ -105,10 +99,12 @@ var Dropdown = function (props) {
105
99
  imageUrl: !showThumbnail ? undefined : el.imageUrl,
106
100
  price: !showPrice ? undefined : el.price,
107
101
  description: !showDescription ? undefined : el.description,
108
- }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue;
109
- var selected = value === optionValue;
102
+ }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue, selected = _a.selected, handleSelect = _a.handleSelect;
110
103
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue);
111
- return (react_1.default.createElement(dropdown_styles_1.OptionWrapper, { key: i, onClick: function () { return handleClick(optionValue); }, className: clsOpt, selected: selected },
104
+ return (react_1.default.createElement(dropdown_styles_1.OptionWrapper, { key: i, onClick: function () {
105
+ handleSelect();
106
+ setHide(true);
107
+ }, className: clsOpt, selected: selected },
112
108
  react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, name: name, className: clsOpt }),
113
109
  react_1.default.createElement("div", null,
114
110
  react_1.default.createElement(Title, { name: name, className: clsOpt }),
@@ -38,7 +38,7 @@ var Price = function (props) {
38
38
  return (react_1.default.createElement(strips_styles_1.StripPrice, { className: "".concat(className, " option-price") }, price));
39
39
  };
40
40
  var Strips = function (props) {
41
- var title = props.title, description = props.description, options = props.options, value = props.value, onClick = props.onClick, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription;
41
+ var title = props.title, description = props.description, options = props.options, customClassName = props.className, showThumbnail = props.showThumbnail, showPrice = props.showPrice, showDescription = props.showDescription;
42
42
  var cls = (0, utils_1.generateInputClassName)('strips', customClassName, title);
43
43
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
44
44
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
@@ -50,10 +50,9 @@ var Strips = function (props) {
50
50
  imageUrl: !showThumbnail ? undefined : el.imageUrl,
51
51
  price: !showPrice ? undefined : el.price,
52
52
  description: !showDescription ? undefined : el.description,
53
- }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue;
54
- var selected = value === optionValue;
53
+ }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue, selected = _a.selected, handleSelect = _a.handleSelect;
55
54
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
56
- return (react_1.default.createElement(strips_styles_1.StripWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt },
55
+ return (react_1.default.createElement(strips_styles_1.StripWrapper, { key: i, onClick: handleSelect, selected: selected, className: clsOpt },
57
56
  react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, name: name, className: clsOpt }),
58
57
  react_1.default.createElement("div", null,
59
58
  react_1.default.createElement(Title, { name: name, className: clsOpt }),
@@ -30,7 +30,7 @@ var Thumbnail = function (props) {
30
30
  return (react_1.default.createElement(swatch_styles_1.OptionThumbnail, { className: "".concat(className, " option-thumbnail"), color: color, shape: shape, size: size }, imageUrl ? react_1.default.createElement("img", { src: imageUrl, alt: name || '' }) : react_1.default.createElement("span", null)));
31
31
  };
32
32
  var Swatch = function (props) {
33
- var _a = Object.assign({ shape: 'round', size: '60px' }, props), title = _a.title, shape = _a.shape, description = _a.description, options = _a.options, value = _a.value, onClick = _a.onClick, customClassName = _a.className, showThumbnail = _a.showThumbnail, showPrice = _a.showPrice, showDescription = _a.showDescription, size = _a.size;
33
+ var _a = Object.assign({ shape: 'round', size: '60px' }, props), title = _a.title, shape = _a.shape, description = _a.description, options = _a.options, customClassName = _a.className, showThumbnail = _a.showThumbnail, showPrice = _a.showPrice, showDescription = _a.showDescription, size = _a.size;
34
34
  var cls = (0, utils_1.generateInputClassName)('swatch', customClassName, title);
35
35
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
36
36
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
@@ -42,10 +42,9 @@ var Swatch = function (props) {
42
42
  imageUrl: !showThumbnail ? undefined : el.imageUrl,
43
43
  price: !showPrice ? undefined : el.price,
44
44
  description: !showDescription ? undefined : el.description,
45
- }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue;
46
- var selected = value === optionValue;
45
+ }), imageUrl = _a.imageUrl, color = _a.color, name = _a.name, description = _a.description, price = _a.price, optionValue = _a.optionValue, selected = _a.selected, handleSelect = _a.handleSelect;
47
46
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
48
- return (react_1.default.createElement(swatch_styles_1.OptionWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt, shape: shape, size: size },
47
+ return (react_1.default.createElement(swatch_styles_1.OptionWrapper, { key: i, onClick: handleSelect, selected: selected, className: clsOpt, shape: shape, size: size },
49
48
  react_1.default.createElement("div", null,
50
49
  react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, shape: shape, className: clsOpt, size: size })),
51
50
  react_1.default.createElement(SwatchInfo, { title: name, price: price, description: description })));
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { IFormComponentProps } from '../containers/formInputContainer';
3
3
  export interface ITextInput extends IFormComponentProps<undefined> {
4
+ maxLength?: number;
4
5
  }
5
6
  export declare const TextInput: {
6
7
  (props: ITextInput): JSX.Element;
@@ -14,12 +14,12 @@ var utils_1 = require("../../utils");
14
14
  var constants_1 = require("../../constants");
15
15
  var formInputContainer_1 = __importDefault(require("../containers/formInputContainer"));
16
16
  var TextInput = function (props) {
17
- var title = props.title, description = props.description, value = props.value, onChange = props.onChange, customClassName = props.className;
17
+ var title = props.title, description = props.description, value = props.value, onChange = props.onChange, maxLength = props.maxLength, customClassName = props.className;
18
18
  var cls = (0, utils_1.generateInputClassName)('text-input', customClassName, title);
19
19
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
20
20
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
21
21
  react_1.default.createElement(FormComponentDescription_1.default, { description: description, className: cls }),
22
- react_1.default.createElement(textInput_styles_1.Input, { type: "text", value: value, onChange: function (e) { return onChange && onChange(e.target.value); }, className: cls })));
22
+ react_1.default.createElement(textInput_styles_1.Input, { type: "text", maxLength: maxLength, value: value, onChange: function (e) { return onChange && onChange(e.target.value); }, className: cls })));
23
23
  };
24
24
  exports.TextInput = TextInput;
25
25
  exports.TextInput.componentName = 'text-input';
@@ -9,5 +9,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.Input = void 0;
11
11
  var styled_components_1 = __importDefault(require("styled-components"));
12
- exports.Input = styled_components_1.default.input(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n margin: 0;\n padding: 10px 6px;\n background: #fff;\n border: 1px solid #d9d9d9;\n color: ", ";\n outline: none;\n border-radius: 2px;\n font-size: 14px;\n transition: all 0.3s;\n font-family: ", ";\n\n &:hover {\n border-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n box-shadow: 0 0 0 2px ", ";\n }\n"], ["\n width: 100%;\n margin: 0;\n padding: 10px 6px;\n background: #fff;\n border: 1px solid #d9d9d9;\n color: ", ";\n outline: none;\n border-radius: 2px;\n font-size: 14px;\n transition: all 0.3s;\n font-family: ", ";\n\n &:hover {\n border-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n box-shadow: 0 0 0 2px ", ";\n }\n"])), function (props) { return props.theme.textColor; }, function (props) { return props.theme.fontFamily; }, function (props) { return props.theme.primaryColor; }, function (props) { return props.theme.primaryColor; }, function (props) { return "".concat(props.theme.primaryColor, "33"); });
12
+ exports.Input = styled_components_1.default.input(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n margin: 0;\n padding: 8px 7px;\n background: #fff;\n border: 1px solid #d9d9d9;\n color: ", ";\n outline: none;\n border-radius: 2px;\n font-size: 14px;\n transition: all 0.3s;\n font-family: ", ";\n\n &:hover {\n border-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n box-shadow: 0 0 0 2px ", ";\n }\n"], ["\n width: 100%;\n margin: 0;\n padding: 8px 7px;\n background: #fff;\n border: 1px solid #d9d9d9;\n color: ", ";\n outline: none;\n border-radius: 2px;\n font-size: 14px;\n transition: all 0.3s;\n font-family: ", ";\n\n &:hover {\n border-color: ", ";\n }\n\n &:focus {\n border-color: ", ";\n box-shadow: 0 0 0 2px ", ";\n }\n"])), function (props) { return props.theme.textColor; }, function (props) { return props.theme.fontFamily; }, function (props) { return props.theme.primaryColor; }, function (props) { return props.theme.primaryColor; }, function (props) { return "".concat(props.theme.primaryColor, "33"); });
13
13
  var templateObject_1;
@@ -14,16 +14,15 @@ var utils_1 = require("../../utils");
14
14
  var constants_1 = require("../../constants");
15
15
  var formInputContainer_1 = __importDefault(require("../containers/formInputContainer"));
16
16
  var Tiles = function (props) {
17
- var _a = Object.assign({ columns: 2 }, props), title = _a.title, description = _a.description, options = _a.options, value = _a.value, onClick = _a.onClick, customClassName = _a.className, columns = _a.columns;
17
+ var _a = Object.assign({ columns: 2 }, props), title = _a.title, description = _a.description, options = _a.options, customClassName = _a.className, columns = _a.columns;
18
18
  var cls = (0, utils_1.generateInputClassName)('tiles', customClassName, title);
19
19
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
20
20
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
21
21
  react_1.default.createElement(FormComponentDescription_1.default, { description: description, className: cls }),
22
22
  react_1.default.createElement(tiles_styles_1.TilesWrapper, { columns: columns }, options === null || options === void 0 ? void 0 : options.map(function (el, i) {
23
- var name = el.name, optionValue = el.value;
24
- var selected = value === optionValue;
23
+ var name = el.name, optionValue = el.value, selected = el.selected, handleSelect = el.handleSelect;
25
24
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
26
- return (react_1.default.createElement(tiles_styles_1.TileWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt },
25
+ return (react_1.default.createElement(tiles_styles_1.TileWrapper, { key: i, onClick: handleSelect, selected: selected, className: clsOpt },
27
26
  react_1.default.createElement("div", null, name)));
28
27
  }))));
29
28
  };
@@ -14,16 +14,15 @@ var utils_1 = require("../../utils");
14
14
  var constants_1 = require("../../constants");
15
15
  var formInputContainer_1 = __importDefault(require("../containers/formInputContainer"));
16
16
  var TilesGroup = function (props) {
17
- var _a = Object.assign({ stretch: true }, props), stretch = _a.stretch, title = _a.title, description = _a.description, options = _a.options, value = _a.value, onClick = _a.onClick, customClassName = _a.className;
17
+ var _a = Object.assign({ stretch: true }, props), stretch = _a.stretch, title = _a.title, description = _a.description, options = _a.options, customClassName = _a.className;
18
18
  var cls = (0, utils_1.generateInputClassName)('tiles-group', customClassName, title);
19
19
  return (react_1.default.createElement(shared_styles_1.FormComponentWrapper, { className: cls },
20
20
  react_1.default.createElement(FormComponentTitle_1.default, { title: title, className: cls }),
21
21
  react_1.default.createElement(FormComponentDescription_1.default, { description: description, className: cls }),
22
22
  react_1.default.createElement(tilesGroup_styles_1.TilesGroupWrapper, { stretch: stretch }, options === null || options === void 0 ? void 0 : options.map(function (el, i) {
23
- var name = el.name, optionValue = el.value;
24
- var selected = value === optionValue;
23
+ var name = el.name, optionValue = el.value, selected = el.selected, handleSelect = el.handleSelect;
25
24
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
26
- return (react_1.default.createElement(tilesGroup_styles_1.TileWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt },
25
+ return (react_1.default.createElement(tilesGroup_styles_1.TileWrapper, { key: i, onClick: handleSelect, selected: selected, className: clsOpt },
27
26
  react_1.default.createElement("div", null, name)));
28
27
  }))));
29
28
  };
@@ -1,9 +1,11 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { RawAttributeValue } from '../../hooks/useAttribute';
3
- import { IDisplayAttributeAssetValue, IThreekitDisplayAttribute } from '../../threekit';
3
+ import { IHydratedAttribute, IHydratedAttributeAssetValue } from '../../threekit';
4
4
  export interface IOptionShared {
5
5
  name: string;
6
6
  value: string;
7
+ handleSelect: () => Promise<void>;
8
+ selected: boolean;
7
9
  }
8
10
  export interface IOption extends IOptionShared {
9
11
  description?: string;
@@ -38,13 +40,15 @@ interface IPrepAttributeConfig {
38
40
  metadataKeys: MetadataKeys;
39
41
  sort?: string;
40
42
  }
41
- export declare const prepAttributeForComponent: (attribute: IThreekitDisplayAttribute, config: IPrepAttributeConfig) => {
43
+ export declare const prepAttributeForComponent: (attribute: IHydratedAttribute, config: IPrepAttributeConfig) => {
42
44
  selected: string | number | import("../../threekit").IConfigurationAsset | import("../../threekit").IConfigurationColor;
43
- options: IDisplayAttributeAssetValue[] | {
45
+ options: {
44
46
  name: string;
47
+ handleSelect: () => Promise<void>;
48
+ selected: boolean;
45
49
  label: string;
46
50
  value: string;
47
- }[] | undefined;
51
+ }[] | IHydratedAttributeAssetValue[] | undefined;
48
52
  };
49
53
  declare function formComponentContainer<P extends IFormContainerProps>(FormComponent: IFormComponent<Omit<P, 'options'>>): (props: P) => JSX.Element | null;
50
54
  export default formComponentContainer;