@threekit-tools/treble 0.0.59 → 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.
- package/dist/Treble/Treble.d.ts +2 -2
- package/dist/Treble/Treble.js +7 -2
- package/dist/components/ThreekitProvider/index.d.ts +1 -0
- package/dist/components/ThreekitProvider/index.js +10 -3
- package/dist/components/TrebleApp/index.d.ts +1 -0
- package/dist/components/TrebleApp/index.js +16 -6
- package/dist/components/Wishlist/index.js +6 -11
- package/dist/components/containers/formInputContainer.d.ts +2 -2
- package/dist/components/containers/formInputContainer.js +4 -4
- package/dist/hooks/useAttribute/index.js +5 -2
- package/dist/hooks/useConfigurator/index.js +7 -3
- package/dist/hooks/useNestedConfigurator/index.d.ts +8 -0
- package/dist/hooks/useNestedConfigurator/index.js +93 -0
- package/dist/hooks/useProductCache/index.d.ts +13 -5
- package/dist/hooks/useProductCache/index.js +16 -23
- package/dist/hooks/useWishlist/index.d.ts +8 -6
- package/dist/hooks/useWishlist/index.js +16 -22
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/store/attributes.d.ts +3 -3
- package/dist/store/attributes.js +3 -50
- package/dist/store/product.d.ts +22 -13
- package/dist/store/product.js +98 -54
- package/dist/store/translations.d.ts +4 -3
- package/dist/store/translations.js +4 -14
- package/dist/store/treble.d.ts +4 -0
- package/dist/store/treble.js +69 -30
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +53 -1
- package/package.json +1 -1
package/dist/Treble/Treble.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import threekitAPI from '../api';
|
|
2
|
-
import { IThreekitPlayer, IConfiguration, ISetConfiguration } from '../threekit';
|
|
2
|
+
import { IThreekitPlayer, IConfiguration, ISetConfiguration, IThreekitPrivateConfigurator } from '../threekit';
|
|
3
3
|
import { IWishlist } from './Wishlist';
|
|
4
4
|
import Snapshots from './Snapshots';
|
|
5
5
|
import { ISaveConfiguration } from '../api/configurations';
|
|
@@ -26,7 +26,7 @@ declare class Treble {
|
|
|
26
26
|
} & import("../http/configurations").IConfigurationResponse & {
|
|
27
27
|
thumbnail: string;
|
|
28
28
|
}>;
|
|
29
|
-
getNestedConfigurator: (address: string | Array<string>) =>
|
|
29
|
+
getNestedConfigurator: (address: string | Array<string>) => undefined | IThreekitPrivateConfigurator;
|
|
30
30
|
resetConfiguration: (configuration?: ISetConfiguration | undefined) => void;
|
|
31
31
|
sendEmail: (credentials: IEmailShareCredentials, templateData: Record<string, any>) => Promise<import("../http/server").IPostEmailResponse>;
|
|
32
32
|
}
|
package/dist/Treble/Treble.js
CHANGED
|
@@ -83,14 +83,19 @@ var Treble = /** @class */ (function () {
|
|
|
83
83
|
});
|
|
84
84
|
}); };
|
|
85
85
|
this.getNestedConfigurator = function (address) {
|
|
86
|
+
if (!address)
|
|
87
|
+
return undefined;
|
|
86
88
|
var player = window.threekit.player.enableApi('player');
|
|
87
89
|
var addressArr = Array.isArray(address) ? address : [address];
|
|
88
90
|
return addressArr.reduce(function (configurator, attributeName) {
|
|
91
|
+
var _a;
|
|
92
|
+
if (!configurator)
|
|
93
|
+
return undefined;
|
|
89
94
|
var itemId = configurator.getAppliedConfiguration(attributeName);
|
|
90
|
-
return window.threekit.player.scene.get({
|
|
95
|
+
return (_a = window.threekit.player.scene.get({
|
|
91
96
|
id: itemId,
|
|
92
97
|
evalNode: true,
|
|
93
|
-
}).configurator;
|
|
98
|
+
})) === null || _a === void 0 ? void 0 : _a.configurator;
|
|
94
99
|
}, player.getConfigurator());
|
|
95
100
|
};
|
|
96
101
|
this.resetConfiguration = function (configuration) {
|
|
@@ -31,10 +31,17 @@ var theme_1 = __importDefault(require("../../theme"));
|
|
|
31
31
|
var GlobalStyles_styles_1 = __importDefault(require("./GlobalStyles.styles"));
|
|
32
32
|
var App = function (props) {
|
|
33
33
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
34
|
+
var playerConfig = props.playerConfig, productId = props.productId, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv, eventHandlers = props.eventHandlers;
|
|
34
35
|
(0, react_1.useEffect)(function () {
|
|
35
36
|
var init = function () {
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
dispatch((0, treble_1.launch)({
|
|
38
|
+
playerConfig: playerConfig,
|
|
39
|
+
productId: productId,
|
|
40
|
+
project: project,
|
|
41
|
+
locale: locale,
|
|
42
|
+
threekitEnv: threekitEnv,
|
|
43
|
+
eventHandlers: eventHandlers,
|
|
44
|
+
}));
|
|
38
45
|
};
|
|
39
46
|
init();
|
|
40
47
|
return;
|
|
@@ -45,6 +52,6 @@ var ThreekitProvider = function (props) {
|
|
|
45
52
|
return (react_1.default.createElement(react_redux_1.Provider, { store: (0, store_1.default)(props.reducer) },
|
|
46
53
|
react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme_1.default },
|
|
47
54
|
react_1.default.createElement(GlobalStyles_styles_1.default, null),
|
|
48
|
-
react_1.default.createElement(App, { locale: props.locale, project: props.project, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv, eventHandlers: props.eventHandlers }, props.children))));
|
|
55
|
+
react_1.default.createElement(App, { locale: props.locale, productId: props.productId, project: props.project, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv, eventHandlers: props.eventHandlers }, props.children))));
|
|
49
56
|
};
|
|
50
57
|
exports.default = ThreekitProvider;
|
|
@@ -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
|
|
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(
|
|
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]
|
|
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:
|
|
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 = {
|
|
@@ -36,11 +36,11 @@ export interface IFormComponentProps<T extends IOptionShared | undefined> extend
|
|
|
36
36
|
export interface IFormComponent<P> extends FunctionComponent<P> {
|
|
37
37
|
compatibleAttributes: Set<string>;
|
|
38
38
|
}
|
|
39
|
-
interface
|
|
39
|
+
interface IhydrateAttributeConfig {
|
|
40
40
|
metadataKeys: MetadataKeys;
|
|
41
41
|
sort?: string;
|
|
42
42
|
}
|
|
43
|
-
export declare const
|
|
43
|
+
export declare const hydrateAttributeForComponent: (attribute: IHydratedAttribute, config: IhydrateAttributeConfig) => {
|
|
44
44
|
selected: string | number | import("../../threekit").IConfigurationAsset | import("../../threekit").IConfigurationColor;
|
|
45
45
|
options: {
|
|
46
46
|
name: string;
|
|
@@ -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.
|
|
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
|
|
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;
|
|
@@ -76,7 +76,7 @@ var prepAttributeForComponent = function (attribute, config) {
|
|
|
76
76
|
}
|
|
77
77
|
return { selected: selected, options: options };
|
|
78
78
|
};
|
|
79
|
-
exports.
|
|
79
|
+
exports.hydrateAttributeForComponent = hydrateAttributeForComponent;
|
|
80
80
|
function formComponentContainer(FormComponent) {
|
|
81
81
|
return function (props) {
|
|
82
82
|
var attribute = props.attribute, metadataKeyThumbnail = props.metadataKeyThumbnail, metadataKeyDescription = props.metadataKeyDescription, metadataKeyPrice = props.metadataKeyPrice, hideAttributeTitle = props.hideAttributeTitle, sort = props.sort;
|
|
@@ -90,7 +90,7 @@ function formComponentContainer(FormComponent) {
|
|
|
90
90
|
console.log('Incompatible attribute type for this component');
|
|
91
91
|
return null;
|
|
92
92
|
}
|
|
93
|
-
var _b = (0, exports.
|
|
93
|
+
var _b = (0, exports.hydrateAttributeForComponent)(attributeData, {
|
|
94
94
|
metadataKeys: {
|
|
95
95
|
metadataKeyThumbnail: metadataKeyThumbnail,
|
|
96
96
|
metadataKeyDescription: metadataKeyDescription,
|
|
@@ -43,16 +43,19 @@ var store_1 = require("../../store");
|
|
|
43
43
|
var attributes_1 = require("../../store/attributes");
|
|
44
44
|
var utils_1 = require("../../utils");
|
|
45
45
|
var api_1 = __importDefault(require("../../api"));
|
|
46
|
+
var utils_2 = require("../../utils");
|
|
46
47
|
var useAttribute = function (attributeName) {
|
|
48
|
+
var _a;
|
|
47
49
|
if (!attributeName)
|
|
48
50
|
return [undefined, undefined];
|
|
49
51
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
50
|
-
var
|
|
52
|
+
var _b = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), attributes = _b[0], translations = _b[1], language = _b[2];
|
|
51
53
|
if (!attributeName || !attributes)
|
|
52
54
|
return [undefined, undefined];
|
|
53
55
|
var attribute = attributes[attributeName];
|
|
54
56
|
if (!attribute)
|
|
55
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)); });
|
|
56
59
|
var handleChange = function (value) { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
60
|
var preppedValue, assetId;
|
|
58
61
|
var _a;
|
|
@@ -81,6 +84,6 @@ var useAttribute = function (attributeName) {
|
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
}); };
|
|
84
|
-
return [
|
|
87
|
+
return [preppedAttributes[attributeName], handleChange];
|
|
85
88
|
};
|
|
86
89
|
exports.default = useAttribute;
|
|
@@ -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
|
|
8
|
-
if (!
|
|
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 [
|
|
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;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { CachedProduct } from '../../store/product';
|
|
2
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
|
+
}
|
|
3
13
|
interface CacheData {
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
cache: Array<HydratedCacheProduct>;
|
|
15
|
+
products: Array<ISelectableProduct>;
|
|
6
16
|
}
|
|
7
17
|
declare type UseProductCache = [
|
|
8
18
|
CacheData,
|
|
9
|
-
(config?: string | IReloadConfig) => Promise<void
|
|
10
|
-
(idx: number) => Promise<void>,
|
|
11
|
-
(idx: number) => Promise<void>
|
|
19
|
+
(config?: string | IReloadConfig) => Promise<void>
|
|
12
20
|
];
|
|
13
21
|
declare const useProductCache: () => UseProductCache;
|
|
14
22
|
export default useProductCache;
|
|
@@ -5,31 +5,24 @@ var store_1 = require("../../store");
|
|
|
5
5
|
var useProductCache = function () {
|
|
6
6
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
7
7
|
var cache = (0, store_1.useThreekitSelector)(product_1.getProductCache);
|
|
8
|
-
var activeProductIdx = (0, store_1.useThreekitSelector)(product_1.
|
|
9
|
-
var data = {
|
|
10
|
-
cache: cache,
|
|
11
|
-
activeProductIdx: activeProductIdx,
|
|
12
|
-
};
|
|
13
|
-
var handleChangeActiveProduct = function (idx) {
|
|
14
|
-
if (idx === undefined)
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
if (idx === activeProductIdx)
|
|
17
|
-
return Promise.resolve();
|
|
18
|
-
if (!cache || idx >= (cache === null || cache === void 0 ? void 0 : cache.length))
|
|
19
|
-
return Promise.resolve();
|
|
20
|
-
return dispatch((0, product_1.changeActiveProductIdx)(idx));
|
|
21
|
-
};
|
|
8
|
+
var activeProductIdx = (0, store_1.useThreekitSelector)(product_1.getActiveCacheIdx);
|
|
22
9
|
var handleLoadNewProduct = function (config) {
|
|
23
10
|
return dispatch((0, product_1.loadNewProduct)(config));
|
|
24
11
|
};
|
|
25
|
-
var
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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];
|
|
34
27
|
};
|
|
35
28
|
exports.default = useProductCache;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IConfigurationResponse } from '../../http/configurations';
|
|
2
2
|
import { ISaveConfiguration } from '../../api/configurations';
|
|
3
|
+
interface HydratedWishlistItem extends IConfigurationResponse {
|
|
4
|
+
handleSelect: () => void;
|
|
5
|
+
handleRemove: () => void;
|
|
6
|
+
handleShare: () => void;
|
|
7
|
+
}
|
|
3
8
|
declare type UseWishlistHook = [
|
|
4
|
-
|
|
9
|
+
Array<HydratedWishlistItem>,
|
|
5
10
|
(config?: Omit<ISaveConfiguration, 'configurator'>) => void,
|
|
6
|
-
(idx: number) => void,
|
|
7
|
-
(idx: number) => void,
|
|
8
|
-
(idx: number) => void,
|
|
9
11
|
() => void
|
|
10
|
-
] | [undefined, undefined, undefined
|
|
12
|
+
] | [undefined, undefined, undefined];
|
|
11
13
|
declare const useWishlist: () => UseWishlistHook;
|
|
12
14
|
export default useWishlist;
|
|
@@ -11,32 +11,26 @@ var message_1 = __importDefault(require("../../components/message"));
|
|
|
11
11
|
var useWishlist = function () {
|
|
12
12
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
13
13
|
var isLoaded = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
|
|
14
|
-
var
|
|
14
|
+
var wishlistData = (0, store_1.useThreekitSelector)(wishlist_1.getWishlist);
|
|
15
15
|
if (!isLoaded)
|
|
16
|
-
return [undefined, undefined, undefined
|
|
16
|
+
return [undefined, undefined, undefined];
|
|
17
17
|
var handleAddToWishlist = function (config) { return dispatch((0, wishlist_1.addToWishlist)(config)); };
|
|
18
|
-
var handleRemoveFromWishlist = function (idx) {
|
|
19
|
-
dispatch((0, wishlist_1.removeFromWishlist)(idx));
|
|
20
|
-
message_1.default.info('Item removed from wishlist');
|
|
21
|
-
};
|
|
22
|
-
var handleResumeItem = function (idx) {
|
|
23
|
-
dispatch((0, wishlist_1.resumeFromWishlist)(idx));
|
|
24
|
-
};
|
|
25
|
-
var handleShareItem = function (idx) {
|
|
26
|
-
var url = (0, utils_1.getResumableUrl)(wishlist[idx].shortId);
|
|
27
|
-
(0, utils_1.copyToClipboard)(url);
|
|
28
|
-
message_1.default.info('Link copied!');
|
|
29
|
-
};
|
|
30
18
|
var handleClearWishlist = function () {
|
|
31
19
|
dispatch(wishlist_1.clearWishlist);
|
|
32
20
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
var wishlist = wishlistData.map(function (el, i) {
|
|
22
|
+
return Object.assign({}, el, {
|
|
23
|
+
handleSelect: function () { return dispatch((0, wishlist_1.resumeFromWishlist)(i)); },
|
|
24
|
+
handleRemove: function () {
|
|
25
|
+
dispatch((0, wishlist_1.removeFromWishlist)(i));
|
|
26
|
+
message_1.default.info('Item removed from wishlist');
|
|
27
|
+
},
|
|
28
|
+
handleShare: function () {
|
|
29
|
+
(0, utils_1.copyToClipboard)((0, utils_1.getResumableUrl)(el.shortId));
|
|
30
|
+
message_1.default.info('Link copied!');
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return [wishlist, handleAddToWishlist, handleClearWishlist];
|
|
41
35
|
};
|
|
42
36
|
exports.default = useWishlist;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import useWishlist from './hooks/useWishlist';
|
|
|
11
11
|
import useShare from './hooks/useShare';
|
|
12
12
|
import usePlayerPortal from './hooks/usePlayerPortal';
|
|
13
13
|
import useProductCache from './hooks/useProductCache';
|
|
14
|
+
import useNestedConfigurator from './hooks/useNestedConfigurator';
|
|
14
15
|
import ThreekitProvider from './components/ThreekitProvider';
|
|
15
16
|
import Player from './components/Player';
|
|
16
17
|
import Button from './components/Button';
|
|
@@ -42,4 +43,4 @@ import icons from './icons';
|
|
|
42
43
|
export * from './icons';
|
|
43
44
|
import TrebleApp from './components/TrebleApp';
|
|
44
45
|
import ProductLayout from './components/ProductLayout';
|
|
45
|
-
export { useAttribute, useConfigurator, useMetadata, useName, usePlayerLoadingStatus, usePrice, useThreekitInitStatus, useZoom, useSnapshot, useWishlist, useShare, usePlayerPortal, useProductCache, ThreekitProvider, Player, Button, Cards, Dropdown, Strips, Swatch, Tiles, TilesGroup, Upload, ProductName, ProductDescription, AttributeTitle, AttributeValue, TotalPrice, message, Modal, Drawer, Accordion, Tabs, PortalToElement, AwaitThreekitLoad, FlatForm, Zoom, Snapshots, Wishlist, Share, icons, TrebleApp, ProductLayout, };
|
|
46
|
+
export { useAttribute, useConfigurator, useMetadata, useName, usePlayerLoadingStatus, usePrice, useThreekitInitStatus, useZoom, useSnapshot, useWishlist, useShare, usePlayerPortal, useProductCache, useNestedConfigurator, ThreekitProvider, Player, Button, Cards, Dropdown, Strips, Swatch, Tiles, TilesGroup, Upload, ProductName, ProductDescription, AttributeTitle, AttributeValue, TotalPrice, message, Modal, Drawer, Accordion, Tabs, PortalToElement, AwaitThreekitLoad, FlatForm, Zoom, Snapshots, Wishlist, Share, icons, TrebleApp, ProductLayout, };
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ProductLayout = exports.TrebleApp = exports.icons = exports.Share = exports.Wishlist = exports.Snapshots = exports.Zoom = exports.FlatForm = exports.AwaitThreekitLoad = exports.PortalToElement = exports.Tabs = exports.Accordion = exports.Drawer = exports.Modal = exports.message = exports.TotalPrice = exports.AttributeValue = exports.AttributeTitle = exports.ProductDescription = exports.ProductName = exports.Upload = exports.TilesGroup = exports.Tiles = exports.Swatch = exports.Strips = exports.Dropdown = exports.Cards = exports.Button = exports.Player = exports.ThreekitProvider = exports.useProductCache = exports.usePlayerPortal = exports.useShare = exports.useWishlist = exports.useSnapshot = exports.useZoom = exports.useThreekitInitStatus = exports.usePrice = exports.usePlayerLoadingStatus = exports.useName = exports.useMetadata = exports.useConfigurator = exports.useAttribute = void 0;
|
|
16
|
+
exports.ProductLayout = exports.TrebleApp = exports.icons = exports.Share = exports.Wishlist = exports.Snapshots = exports.Zoom = exports.FlatForm = exports.AwaitThreekitLoad = exports.PortalToElement = exports.Tabs = exports.Accordion = exports.Drawer = exports.Modal = exports.message = exports.TotalPrice = exports.AttributeValue = exports.AttributeTitle = exports.ProductDescription = exports.ProductName = exports.Upload = exports.TilesGroup = exports.Tiles = exports.Swatch = exports.Strips = exports.Dropdown = exports.Cards = exports.Button = exports.Player = exports.ThreekitProvider = exports.useNestedConfigurator = exports.useProductCache = exports.usePlayerPortal = exports.useShare = exports.useWishlist = exports.useSnapshot = exports.useZoom = exports.useThreekitInitStatus = exports.usePrice = exports.usePlayerLoadingStatus = exports.useName = exports.useMetadata = exports.useConfigurator = exports.useAttribute = void 0;
|
|
17
17
|
// Hooks
|
|
18
18
|
var useAttribute_1 = __importDefault(require("./hooks/useAttribute"));
|
|
19
19
|
exports.useAttribute = useAttribute_1.default;
|
|
@@ -42,6 +42,8 @@ exports.usePlayerPortal = usePlayerPortal_1.default;
|
|
|
42
42
|
// import useSingleAnimation from './hooks/useSingleAnimation';
|
|
43
43
|
var useProductCache_1 = __importDefault(require("./hooks/useProductCache"));
|
|
44
44
|
exports.useProductCache = useProductCache_1.default;
|
|
45
|
+
var useNestedConfigurator_1 = __importDefault(require("./hooks/useNestedConfigurator"));
|
|
46
|
+
exports.useNestedConfigurator = useNestedConfigurator_1.default;
|
|
45
47
|
// Components
|
|
46
48
|
var ThreekitProvider_1 = __importDefault(require("./components/ThreekitProvider"));
|
|
47
49
|
exports.ThreekitProvider = ThreekitProvider_1.default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
-
import { ISetConfiguration, IThreekitDisplayAttribute
|
|
2
|
+
import { ISetConfiguration, IThreekitDisplayAttribute } from '../threekit';
|
|
3
3
|
import { ITranslationMap } from '../api/products';
|
|
4
4
|
/*****************************************************
|
|
5
5
|
* Types and Interfaces
|
|
@@ -17,14 +17,14 @@ declare const reducer: import("redux").Reducer<AttributesState, import("redux").
|
|
|
17
17
|
* Standard Selectors
|
|
18
18
|
****************************************************/
|
|
19
19
|
export declare const getAttributes: (state: RootState) => AttributesState;
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const getHydrationData: ((state: {
|
|
21
21
|
treble: import("./treble").TrebleState;
|
|
22
22
|
product: import("./product").ProductState;
|
|
23
23
|
attributes: AttributesState;
|
|
24
24
|
translations: import("./translations").TranslationsState;
|
|
25
25
|
wishlist: import("../Treble").WishlistArray;
|
|
26
26
|
price: import("./price").PriceState;
|
|
27
|
-
}) => Record<string,
|
|
27
|
+
}) => [Record<string, IThreekitDisplayAttribute>, ITranslationMap | undefined, string | undefined]) & import("reselect").OutputSelectorFields<(args_0: AttributesState, args_1: string | undefined) => [Record<string, IThreekitDisplayAttribute>, ITranslationMap | undefined, string | undefined] & {
|
|
28
28
|
clearCache: () => void;
|
|
29
29
|
}> & {
|
|
30
30
|
clearCache: () => void;
|