@threekit-tools/treble 0.0.57 → 0.0.60-next.1

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 (64) hide show
  1. package/dist/Treble/Snapshots.js +32 -63
  2. package/dist/Treble/Treble.d.ts +9 -7
  3. package/dist/Treble/Treble.js +26 -6
  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/ThreekitProvider/index.d.ts +1 -0
  20. package/dist/components/ThreekitProvider/index.js +10 -3
  21. package/dist/components/Tiles/index.js +3 -4
  22. package/dist/components/TilesGroup/index.js +3 -4
  23. package/dist/components/TrebleApp/index.d.ts +1 -0
  24. package/dist/components/TrebleApp/index.js +16 -6
  25. package/dist/components/Wishlist/index.js +6 -11
  26. package/dist/components/containers/formInputContainer.d.ts +9 -5
  27. package/dist/components/containers/formInputContainer.js +14 -19
  28. package/dist/connection.d.ts +4 -1
  29. package/dist/connection.js +4 -0
  30. package/dist/hooks/useAttribute/index.d.ts +2 -2
  31. package/dist/hooks/useAttribute/index.js +6 -5
  32. package/dist/hooks/useConfigurator/index.d.ts +2 -2
  33. package/dist/hooks/useConfigurator/index.js +7 -3
  34. package/dist/hooks/useNestedConfigurator/index.d.ts +8 -0
  35. package/dist/hooks/useNestedConfigurator/index.js +93 -0
  36. package/dist/hooks/useProductCache/index.d.ts +22 -0
  37. package/dist/hooks/useProductCache/index.js +28 -0
  38. package/dist/hooks/useSingleAnimation/index.d.ts +17 -0
  39. package/dist/hooks/useSingleAnimation/index.js +264 -0
  40. package/dist/hooks/useWishlist/index.d.ts +10 -7
  41. package/dist/hooks/useWishlist/index.js +17 -25
  42. package/dist/http/configurations.d.ts +1 -0
  43. package/dist/http/index.d.ts +2 -0
  44. package/dist/http/index.js +2 -0
  45. package/dist/http/server.d.ts +14 -0
  46. package/dist/http/server.js +17 -0
  47. package/dist/index.d.ts +3 -1
  48. package/dist/index.js +6 -1
  49. package/dist/store/attributes.d.ts +14 -1
  50. package/dist/store/attributes.js +6 -45
  51. package/dist/store/price.js +2 -2
  52. package/dist/store/product.d.ts +47 -2
  53. package/dist/store/product.js +267 -12
  54. package/dist/store/translations.d.ts +4 -2
  55. package/dist/store/translations.js +4 -12
  56. package/dist/store/treble.d.ts +36 -2
  57. package/dist/store/treble.js +214 -52
  58. package/dist/store/wishlist.d.ts +3 -2
  59. package/dist/threekit.d.ts +20 -2
  60. package/dist/utils.d.ts +9 -11
  61. package/dist/utils.js +83 -27
  62. package/package.json +17 -2
  63. package/dist/hooks/useArrayAttribute/index.d.ts +0 -2
  64. package/dist/hooks/useArrayAttribute/index.js +0 -184
@@ -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
  };
@@ -3,5 +3,6 @@ import { ThreekitProviderProps } from '../ThreekitProvider';
3
3
  interface TrebleAppProps extends Omit<ThreekitProviderProps, 'children'> {
4
4
  productId?: string;
5
5
  }
6
+ export declare const Products: () => JSX.Element | null;
6
7
  export default function TrebleApp(props: TrebleAppProps): JSX.Element | null;
7
8
  export {};
@@ -22,13 +22,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Products = void 0;
25
26
  var react_1 = __importStar(require("react"));
27
+ var store_1 = require("../../store");
26
28
  var ThreekitProvider_1 = __importDefault(require("../ThreekitProvider"));
27
29
  var utils_1 = require("../../utils");
28
30
  var constants_1 = require("../../constants");
31
+ var product_1 = require("../../store/product");
29
32
  var productsMap = {};
30
33
  var productComponents = [];
31
34
  var productToComponentMap = {};
35
+ var Products = function () {
36
+ var productId = (0, store_1.useThreekitSelector)(product_1.getProductId);
37
+ if (!productId)
38
+ return null;
39
+ var Product = productComponents[productToComponentMap[productId]];
40
+ if (!Product)
41
+ return null;
42
+ return react_1.default.createElement(Product, null);
43
+ };
44
+ exports.Products = Products;
32
45
  function TrebleApp(props) {
33
46
  var _a;
34
47
  var project = props.project, productId = props.productId, playerConfig = props.playerConfig, threekitEnv = props.threekitEnv, locale = props.locale, theme = props.theme, eventHandlers = props.eventHandlers;
@@ -69,13 +82,10 @@ function TrebleApp(props) {
69
82
  }
70
83
  if (!id)
71
84
  return null;
72
- var Product = productComponents[productToComponentMap[id]];
73
- if (!Product)
74
- return null;
75
85
  var preppedProject = Object.assign({}, project, {
76
- products: productsMap[id],
86
+ products: productsMap,
77
87
  });
78
- return (react_1.default.createElement(ThreekitProvider_1.default, { project: preppedProject, locale: locale, playerConfig: playerConfig, theme: theme, threekitEnv: threekitEnv, eventHandlers: eventHandlers },
79
- react_1.default.createElement(Product, null)));
88
+ return (react_1.default.createElement(ThreekitProvider_1.default, { productId: id, project: preppedProject, locale: locale, playerConfig: playerConfig, theme: theme, threekitEnv: threekitEnv, eventHandlers: eventHandlers },
89
+ react_1.default.createElement(exports.Products, null)));
80
90
  }
81
91
  exports.default = TrebleApp;
@@ -81,16 +81,12 @@ var WishlistButton = function (props) {
81
81
  exports.WishlistButton = WishlistButton;
82
82
  var Wishlist = function (props) {
83
83
  var _a = (0, react_1.useState)(false), showWishlist = _a[0], setShowWishlist = _a[1];
84
- var _b = (0, useWishlist_1.default)(), wishlist = _b[0], addToWishlist = _b[1], removeFromWishlist = _b[2], resumeWishlistItem = _b[3], shareWishlistItem = _b[4];
84
+ var _b = (0, useWishlist_1.default)(), wishlist = _b[0], addToWishlist = _b[1];
85
85
  var className = props.className, showLabel = props.showLabel;
86
86
  var shape = props.shape || 'round';
87
87
  var type = props.type || 'threekit';
88
88
  var cls = (0, utils_1.generateWidgetClassName)('wishlist', className);
89
- if (!wishlist ||
90
- !addToWishlist ||
91
- !resumeWishlistItem ||
92
- !removeFromWishlist ||
93
- !shareWishlistItem)
89
+ if (!wishlist || !addToWishlist)
94
90
  return null;
95
91
  var handleAddToWishlist = function () { return __awaiter(void 0, void 0, void 0, function () {
96
92
  return __generator(this, function (_a) {
@@ -103,16 +99,15 @@ var Wishlist = function (props) {
103
99
  }
104
100
  });
105
101
  }); };
106
- var handleClickResume = function (idx) {
107
- resumeWishlistItem(idx);
108
- setShowWishlist(false);
109
- };
110
102
  return (react_1.default.createElement(react_1.default.Fragment, null,
111
103
  react_1.default.createElement(shared_styles_1.TwinButtonWrapper, null,
112
104
  react_1.default.createElement(exports.AddWishlistButton, { title: showLabel ? 'Add to Wishlist' : undefined, className: cls, onClick: handleAddToWishlist, type: type, shape: shape }),
113
105
  react_1.default.createElement(exports.WishlistButton, { title: showLabel ? 'Open Wishlist' : undefined, className: cls, onClick: function () { return setShowWishlist(true); }, type: type, shape: shape })),
114
106
  react_1.default.createElement(Drawer_1.default, { title: "Wishlist", show: showWishlist, handleClose: function () { return setShowWishlist(false); } },
115
- react_1.default.createElement(wishlist_styles_1.WishlistWrapper, null, wishlist.map(function (el, i) { return (react_1.default.createElement(WishlistItem_1.default, { key: i, thumbnail: el.thumbnail || undefined, metadata: el.metadata || undefined, onDelete: function () { return removeFromWishlist(i); }, onResume: function () { return handleClickResume(i); }, onShare: function () { return shareWishlistItem(i); } })); })))));
107
+ react_1.default.createElement(wishlist_styles_1.WishlistWrapper, null, wishlist.map(function (el, i) { return (react_1.default.createElement(WishlistItem_1.default, { key: i, thumbnail: el.thumbnail || undefined, metadata: el.metadata || undefined, onDelete: el.handleRemove, onResume: function () {
108
+ el.handleSelect();
109
+ setShowWishlist(false);
110
+ }, onShare: el.handleShare })); })))));
116
111
  };
117
112
  exports.Wishlist = Wishlist;
118
113
  exports.Wishlist.propTypes = {
@@ -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;
@@ -34,17 +36,19 @@ export interface IFormComponentProps<T extends IOptionShared | undefined> extend
34
36
  export interface IFormComponent<P> extends FunctionComponent<P> {
35
37
  compatibleAttributes: Set<string>;
36
38
  }
37
- interface IPrepAttributeConfig {
39
+ interface IhydrateAttributeConfig {
38
40
  metadataKeys: MetadataKeys;
39
41
  sort?: string;
40
42
  }
41
- export declare const prepAttributeForComponent: (attribute: IThreekitDisplayAttribute, config: IPrepAttributeConfig) => {
43
+ export declare const hydrateAttributeForComponent: (attribute: IHydratedAttribute, config: IhydrateAttributeConfig) => {
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;
@@ -14,13 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.prepAttributeForComponent = void 0;
17
+ exports.hydrateAttributeForComponent = void 0;
18
18
  var react_1 = __importDefault(require("react"));
19
19
  var useAttribute_1 = __importDefault(require("../../hooks/useAttribute"));
20
20
  var usePlayerLoadingStatus_1 = __importDefault(require("../../hooks/usePlayerLoadingStatus"));
21
21
  var utils_1 = require("../../utils");
22
22
  var constants_1 = require("../../constants");
23
- var prepAttributeForComponent = function (attribute, config) {
23
+ var hydrateAttributeForComponent = function (attribute, config) {
24
24
  var _a;
25
25
  var _b = config.metadataKeys, metadataKeyThumbnail = _b.metadataKeyThumbnail, metadataKeyPrice = _b.metadataKeyPrice, metadataKeyDescription = _b.metadataKeyDescription;
26
26
  var sort = config.sort;
@@ -29,15 +29,13 @@ var prepAttributeForComponent = function (attribute, config) {
29
29
  var descriptionKey = metadataKeyDescription || constants_1.METADATA_RESERVED.description;
30
30
  var options;
31
31
  var selected = attribute.value;
32
- if (attribute.type === constants_1.ATTRIBUTE_TYPES.string) {
33
- var stringAttribute = attribute;
34
- options = stringAttribute.values.map(function (el) { return (__assign(__assign({}, el), { name: el.label })); });
32
+ if (attribute.type === 'String') {
33
+ options = attribute.values.map(function (el) { return (__assign(__assign({}, el), { name: el.label })); });
35
34
  }
36
- else if (attribute.type === constants_1.ATTRIBUTE_TYPES.asset) {
37
- var assetAttribute = attribute;
38
- selected = (_a = assetAttribute.value) === null || _a === void 0 ? void 0 : _a.assetId;
39
- options = assetAttribute.values
40
- ? assetAttribute.values
35
+ else if (attribute.type === 'Asset') {
36
+ selected = (_a = attribute.value) === null || _a === void 0 ? void 0 : _a.assetId;
37
+ options = attribute.values
38
+ ? attribute.values
41
39
  .map(function (el) { return prepCatalogItem(el); })
42
40
  .sort(function (a, b) {
43
41
  if (!sort || !Object.keys(constants_1.SORT_OPTIONS).includes(sort))
@@ -50,9 +48,8 @@ var prepAttributeForComponent = function (attribute, config) {
50
48
  })
51
49
  : [];
52
50
  }
53
- else if (attribute.type === constants_1.ATTRIBUTE_TYPES.color) {
54
- var colorAttribute = attribute;
55
- selected = (0, utils_1.inflateRgb)(colorAttribute.value);
51
+ else if (attribute.type === 'Color') {
52
+ selected = (0, utils_1.inflateRgb)(attribute.value);
56
53
  }
57
54
  function prepCatalogItem(item) {
58
55
  var _a, _b;
@@ -79,10 +76,8 @@ var prepAttributeForComponent = function (attribute, config) {
79
76
  }
80
77
  return { selected: selected, options: options };
81
78
  };
82
- exports.prepAttributeForComponent = prepAttributeForComponent;
83
- function formComponentContainer(FormComponent
84
- // FormComponent: IFormComponent<P>
85
- ) {
79
+ exports.hydrateAttributeForComponent = hydrateAttributeForComponent;
80
+ function formComponentContainer(FormComponent) {
86
81
  return function (props) {
87
82
  var attribute = props.attribute, metadataKeyThumbnail = props.metadataKeyThumbnail, metadataKeyDescription = props.metadataKeyDescription, metadataKeyPrice = props.metadataKeyPrice, hideAttributeTitle = props.hideAttributeTitle, sort = props.sort;
88
83
  var isLoading = (0, usePlayerLoadingStatus_1.default)();
@@ -95,7 +90,7 @@ function formComponentContainer(FormComponent
95
90
  console.log('Incompatible attribute type for this component');
96
91
  return null;
97
92
  }
98
- var _b = (0, exports.prepAttributeForComponent)(attributeData, {
93
+ var _b = (0, exports.hydrateAttributeForComponent)(attributeData, {
99
94
  metadataKeys: {
100
95
  metadataKeyThumbnail: metadataKeyThumbnail,
101
96
  metadataKeyDescription: metadataKeyDescription,
@@ -104,7 +99,7 @@ function formComponentContainer(FormComponent
104
99
  sort: sort,
105
100
  }), selected = _b.selected, options = _b.options;
106
101
  var handleSetAttribute = function (value) {
107
- return setAttribute && setAttribute(value);
102
+ return setAttribute === null || setAttribute === void 0 ? void 0 : setAttribute(value);
108
103
  };
109
104
  var preppedProps = __assign({}, props);
110
105
  if (!hideAttributeTitle && !preppedProps.title)
@@ -1,14 +1,16 @@
1
- interface IConnectionConfig {
1
+ export interface IConnectionConfig {
2
2
  authToken?: string;
3
3
  orgId?: string;
4
4
  assetId?: string;
5
5
  threekitDomain?: string;
6
+ serverUrl?: string;
6
7
  }
7
8
  export declare class ThreekitConnection {
8
9
  _authToken: string;
9
10
  _orgId: string;
10
11
  _assetId: string;
11
12
  _threekitDomain: string;
13
+ _serverUrl: string;
12
14
  constructor();
13
15
  connect(config: IConnectionConfig): Promise<void>;
14
16
  getConnection(): {
@@ -16,6 +18,7 @@ export declare class ThreekitConnection {
16
18
  orgId: string;
17
19
  assetId: string;
18
20
  threekitDomain: string;
21
+ serverUrl: string;
19
22
  };
20
23
  }
21
24
  declare const _default: ThreekitConnection;
@@ -42,6 +42,7 @@ var ThreekitConnection = /** @class */ (function () {
42
42
  this._authToken = '';
43
43
  this._orgId = '';
44
44
  this._assetId = '';
45
+ this._serverUrl = '';
45
46
  this._threekitDomain = 'https://admin-fts.threekit.com';
46
47
  }
47
48
  ThreekitConnection.prototype.connect = function (config) {
@@ -53,6 +54,8 @@ var ThreekitConnection = /** @class */ (function () {
53
54
  this._orgId = config.orgId;
54
55
  if (config.assetId)
55
56
  this._assetId = config.assetId;
57
+ if (config.serverUrl)
58
+ this._serverUrl = config.serverUrl;
56
59
  if (config.threekitDomain)
57
60
  this._threekitDomain = "https://".concat(config.threekitDomain);
58
61
  return [2 /*return*/];
@@ -68,6 +71,7 @@ var ThreekitConnection = /** @class */ (function () {
68
71
  orgId: this._orgId,
69
72
  assetId: this._assetId,
70
73
  threekitDomain: this._threekitDomain,
74
+ serverUrl: this._serverUrl,
71
75
  };
72
76
  };
73
77
  return ThreekitConnection;
@@ -1,8 +1,8 @@
1
- import { IThreekitDisplayAttribute, IConfigurationColor } from '../../threekit';
1
+ import { IHydratedAttribute, IConfigurationColor } from '../../threekit';
2
2
  export declare type RawAttributeValue = string | number | boolean | IConfigurationColor | File | undefined;
3
3
  declare type UseAttributeError = [undefined, undefined];
4
4
  declare type UseAttributeSuccess = [
5
- IThreekitDisplayAttribute,
5
+ IHydratedAttribute,
6
6
  (val: RawAttributeValue) => Promise<void>
7
7
  ];
8
8
  declare type UseAttributeHook = UseAttributeError | UseAttributeSuccess;
@@ -42,26 +42,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var store_1 = require("../../store");
43
43
  var attributes_1 = require("../../store/attributes");
44
44
  var utils_1 = require("../../utils");
45
- var constants_1 = require("../../constants");
46
45
  var api_1 = __importDefault(require("../../api"));
46
+ var utils_2 = require("../../utils");
47
47
  var useAttribute = function (attributeName) {
48
+ var _a;
48
49
  if (!attributeName)
49
50
  return [undefined, undefined];
50
51
  var dispatch = (0, store_1.useThreekitDispatch)();
51
- var attributes = (0, store_1.useThreekitSelector)(attributes_1.getAttributes);
52
+ var _b = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), attributes = _b[0], translations = _b[1], language = _b[2];
52
53
  if (!attributeName || !attributes)
53
54
  return [undefined, undefined];
54
55
  var attribute = attributes[attributeName];
55
56
  if (!attribute)
56
57
  return [undefined, undefined];
58
+ var preppedAttributes = (0, utils_2.hydrateAttribute)([(_a = {}, _a[attributeName] = attribute, _a), translations, language], function (config) { return dispatch((0, attributes_1.setConfiguration)(config)); });
57
59
  var handleChange = function (value) { return __awaiter(void 0, void 0, void 0, function () {
58
60
  var preppedValue, assetId;
59
61
  var _a;
60
62
  return __generator(this, function (_b) {
61
63
  switch (_b.label) {
62
64
  case 0:
63
- if (!(attribute.type === 'Asset' &&
64
- attribute.assetType === constants_1.ASSET_TYPES.upload)) return [3 /*break*/, 4];
65
+ if (!(attribute.type === 'Asset' && attribute.assetType === 'upload')) return [3 /*break*/, 4];
65
66
  if (!!value) return [3 /*break*/, 1];
66
67
  preppedValue = (0, utils_1.selectionToConfiguration)('', attribute.type);
67
68
  return [3 /*break*/, 3];
@@ -83,6 +84,6 @@ var useAttribute = function (attributeName) {
83
84
  }
84
85
  });
85
86
  }); };
86
- return [attribute, handleChange];
87
+ return [preppedAttributes[attributeName], handleChange];
87
88
  };
88
89
  exports.default = useAttribute;
@@ -1,7 +1,7 @@
1
- import { ISetConfiguration, IThreekitDisplayAttribute } from '../../threekit';
1
+ import { ISetConfiguration, IHydratedAttribute } from '../../threekit';
2
2
  declare type UseConfiguratorError = [undefined, undefined];
3
3
  declare type UseConfiguratorSuccess = [
4
- Record<string, IThreekitDisplayAttribute>,
4
+ Record<string, IHydratedAttribute>,
5
5
  (configuration: ISetConfiguration) => void
6
6
  ];
7
7
  declare type UseConfiguratorHook = UseConfiguratorError | UseConfiguratorSuccess;
@@ -2,14 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var attributes_1 = require("../../store/attributes");
4
4
  var store_1 = require("../../store");
5
+ var utils_1 = require("../../utils");
5
6
  var useConfigurator = function () {
6
7
  var dispatch = (0, store_1.useThreekitDispatch)();
7
- var attributes = (0, store_1.useThreekitSelector)(attributes_1.getAttributes);
8
- if (!attributes)
8
+ var hydrationData = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData);
9
+ if (!hydrationData)
9
10
  return [undefined, undefined];
11
+ var preppedAttributes = (0, utils_1.hydrateAttribute)(hydrationData, function (config) {
12
+ return dispatch((0, attributes_1.setConfiguration)(config));
13
+ });
10
14
  var handleChange = function (configuration) {
11
15
  return dispatch((0, attributes_1.setConfiguration)(configuration));
12
16
  };
13
- return [attributes, handleChange];
17
+ return [preppedAttributes, handleChange];
14
18
  };
15
19
  exports.default = useConfigurator;
@@ -0,0 +1,8 @@
1
+ import { IHydratedAttribute, ISetConfiguration } from '../../threekit';
2
+ declare type UseNestedConfiguratorError = [undefined, undefined];
3
+ declare type UseNestedConfiguratorSuccess = [
4
+ Record<string, IHydratedAttribute>,
5
+ (val: ISetConfiguration) => Promise<void>
6
+ ];
7
+ declare const useNestedConfigurator: (address: string | Array<string>) => UseNestedConfiguratorError | UseNestedConfiguratorSuccess;
8
+ export default useNestedConfigurator;
@@ -0,0 +1,93 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var react_1 = require("react");
40
+ var store_1 = require("../../store");
41
+ var treble_1 = require("../../store/treble");
42
+ var utils_1 = require("../../utils");
43
+ var attributes_1 = require("../../store/attributes");
44
+ var useNestedConfigurator = function (address) {
45
+ var dispatch = (0, store_1.useThreekitDispatch)();
46
+ var hasInitialized = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
47
+ var playerLoading = (0, store_1.useThreekitSelector)(treble_1.isPlayerLoading);
48
+ var _a = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), _ = _a[0], translations = _a[1], language = _a[2];
49
+ var _b = (0, react_1.useState)(), attributes = _b[0], setAttributes = _b[1];
50
+ var configurator = (0, react_1.useRef)();
51
+ (0, react_1.useEffect)(function () {
52
+ (function () {
53
+ var _a;
54
+ if (!hasInitialized)
55
+ return;
56
+ if (playerLoading)
57
+ return;
58
+ configurator.current =
59
+ window.threekit.treble.getNestedConfigurator(address);
60
+ if (!configurator.current)
61
+ return;
62
+ var updatedAttrs = (_a = configurator.current) === null || _a === void 0 ? void 0 : _a.getDisplayAttributes();
63
+ setAttributes(updatedAttrs);
64
+ })();
65
+ }, [hasInitialized, address, playerLoading]);
66
+ if (!hasInitialized || !attributes)
67
+ return [undefined, undefined];
68
+ var handleSelect = function (config) { return __awaiter(void 0, void 0, void 0, function () {
69
+ var updatedAttrs;
70
+ var _a, _b;
71
+ return __generator(this, function (_c) {
72
+ switch (_c.label) {
73
+ case 0:
74
+ dispatch((0, treble_1.setPlayerLoading)(true));
75
+ return [4 /*yield*/, ((_a = configurator.current) === null || _a === void 0 ? void 0 : _a.setConfiguration(config))];
76
+ case 1:
77
+ _c.sent();
78
+ dispatch((0, treble_1.setPlayerLoading)(false));
79
+ updatedAttrs = (_b = configurator.current) === null || _b === void 0 ? void 0 : _b.getDisplayAttributes();
80
+ if (updatedAttrs)
81
+ setAttributes(updatedAttrs);
82
+ return [2 /*return*/];
83
+ }
84
+ });
85
+ }); };
86
+ var attributeObj = attributes.reduce(function (output, attr) {
87
+ var _a;
88
+ return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
89
+ }, {});
90
+ var preppedAttributes = (0, utils_1.hydrateAttribute)([attributeObj, translations, language], handleSelect);
91
+ return [preppedAttributes, handleSelect];
92
+ };
93
+ exports.default = useNestedConfigurator;
@@ -0,0 +1,22 @@
1
+ import { CachedProduct } from '../../store/product';
2
+ import { IReloadConfig } from '../../store/treble';
3
+ interface HydratedCacheProduct extends Pick<CachedProduct, 'name' | 'label' | 'thumbnail'> {
4
+ selected: boolean;
5
+ handleSelect: () => Promise<void>;
6
+ handleRemove: () => Promise<void>;
7
+ }
8
+ interface ISelectableProduct {
9
+ id: string;
10
+ label: string;
11
+ handleSelect: () => void;
12
+ }
13
+ interface CacheData {
14
+ cache: Array<HydratedCacheProduct>;
15
+ products: Array<ISelectableProduct>;
16
+ }
17
+ declare type UseProductCache = [
18
+ CacheData,
19
+ (config?: string | IReloadConfig) => Promise<void>
20
+ ];
21
+ declare const useProductCache: () => UseProductCache;
22
+ export default useProductCache;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var product_1 = require("../../store/product");
4
+ var store_1 = require("../../store");
5
+ var useProductCache = function () {
6
+ var dispatch = (0, store_1.useThreekitDispatch)();
7
+ var cache = (0, store_1.useThreekitSelector)(product_1.getProductCache);
8
+ var activeProductIdx = (0, store_1.useThreekitSelector)(product_1.getActiveCacheIdx);
9
+ var handleLoadNewProduct = function (config) {
10
+ return dispatch((0, product_1.loadNewProduct)(config));
11
+ };
12
+ var hydratedCache = cache.map(function (el, i) {
13
+ return Object.assign({}, el, {
14
+ selected: activeProductIdx === i,
15
+ handleRemove: function () { return dispatch((0, product_1.removeProductIdx)(i)); },
16
+ handleSelect: activeProductIdx === i
17
+ ? function () { return Promise.resolve(); }
18
+ : function () { return dispatch((0, product_1.changeActiveCacheIdx)(i)); },
19
+ });
20
+ });
21
+ var products = Object.keys(product_1.PRODUCTS).map(function (prod) { return ({
22
+ id: prod,
23
+ label: prod,
24
+ handleSelect: function () { return dispatch((0, product_1.loadProduct)(prod)); },
25
+ }); });
26
+ return [{ cache: hydratedCache, products: products }, handleLoadNewProduct];
27
+ };
28
+ exports.default = useProductCache;
@@ -0,0 +1,17 @@
1
+ import { ICoordinates } from '../../threekit';
2
+ interface NodeConfig {
3
+ nodeId: string;
4
+ paddingStart: number;
5
+ paddingEnd: number;
6
+ delay: number;
7
+ duration: number;
8
+ translation: ICoordinates;
9
+ rotation: ICoordinates;
10
+ scale: ICoordinates;
11
+ }
12
+ interface AnimationConfig {
13
+ duration: number;
14
+ nodes: Array<NodeConfig>;
15
+ }
16
+ declare const useAnimation: (animationConfig: AnimationConfig) => undefined[] | (boolean | (() => Promise<void>))[];
17
+ export default useAnimation;