@threekit-tools/treble 0.0.67 → 0.0.70
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/Snapshots.js +21 -21
- package/dist/components/DevTools/devTools.styles.d.ts +2 -0
- package/dist/components/DevTools/devTools.styles.js +14 -0
- package/dist/components/DevTools/index.d.ts +3 -0
- package/dist/components/DevTools/index.js +18 -0
- package/dist/components/ProductDescription/index.d.ts +3 -2
- package/dist/components/ProductDescription/index.js +17 -11
- package/dist/components/ProductDescription/{description.styles.d.ts → productDescription.styles.d.ts} +0 -0
- package/dist/components/ProductDescription/{description.styles.js → productDescription.styles.js} +0 -0
- package/dist/components/ProductName/index.d.ts +3 -2
- package/dist/components/ProductName/index.js +11 -6
- package/dist/components/ThreekitProvider/index.js +3 -1
- package/dist/components/TotalPrice/index.d.ts +3 -2
- package/dist/components/TotalPrice/index.js +11 -6
- package/dist/components/TrebleApp/index.js +2 -2
- package/dist/hooks/useDevTools/index.d.ts +3 -0
- package/dist/hooks/useDevTools/index.js +43 -0
- package/dist/hooks/useNestedConfigurator/index.d.ts +3 -2
- package/dist/hooks/useNestedConfigurator/index.js +8 -3
- package/dist/store/price.d.ts +6 -5
- package/dist/store/price.js +8 -1
- package/dist/store/treble.d.ts +1 -1
- package/dist/store/treble.js +55 -39
- package/dist/types.d.ts +7 -0
- package/package.json +3 -2
package/dist/Treble/Snapshots.js
CHANGED
|
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
var api_1 = __importDefault(require("../api"));
|
|
43
|
-
|
|
43
|
+
// import connection from '../connection';
|
|
44
44
|
var constants_1 = require("../constants");
|
|
45
45
|
var utils_1 = require("../utils");
|
|
46
46
|
var DEFAULT_CAMERA_CONFIG = {
|
|
@@ -129,12 +129,11 @@ 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
|
-
var
|
|
133
|
-
var
|
|
134
|
-
return __generator(this, function (
|
|
135
|
-
switch (
|
|
132
|
+
var filename, size, format, attributeName, output, cameras, snapshotsRaw, snapshotData, camerasMap_1, currentCamera, cameraPosition, _a, attachments, response, urlsArray, snapshotBlobs, snapshotFiles;
|
|
133
|
+
var _b;
|
|
134
|
+
return __generator(this, function (_c) {
|
|
135
|
+
switch (_c.label) {
|
|
136
136
|
case 0:
|
|
137
|
-
_a = connection_1.default.getConnection(), threekitDomain = _a.threekitDomain, orgId = _a.orgId;
|
|
138
137
|
filename = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.filename) || DEFAULT_CAMERA_CONFIG.filename;
|
|
139
138
|
size = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.size) || DEFAULT_CAMERA_CONFIG.size;
|
|
140
139
|
format = (snapshotsConfig === null || snapshotsConfig === void 0 ? void 0 : snapshotsConfig.format) || DEFAULT_CAMERA_CONFIG.format;
|
|
@@ -144,7 +143,7 @@ var Snapshots = /** @class */ (function () {
|
|
|
144
143
|
if (!(cameras.length === 1 && cameras[0] === undefined)) return [3 /*break*/, 2];
|
|
145
144
|
return [4 /*yield*/, this.getSnapshot({ size: size, format: format })];
|
|
146
145
|
case 1:
|
|
147
|
-
snapshotData =
|
|
146
|
+
snapshotData = _c.sent();
|
|
148
147
|
snapshotsRaw = [snapshotData];
|
|
149
148
|
return [3 /*break*/, 5];
|
|
150
149
|
case 2:
|
|
@@ -156,17 +155,17 @@ var Snapshots = /** @class */ (function () {
|
|
|
156
155
|
cameraPosition = (0, utils_1.getCameraPosition)(window.threekit.player.camera);
|
|
157
156
|
return [4 /*yield*/, this.getSnapshots(cameras, camerasMap_1)];
|
|
158
157
|
case 3:
|
|
159
|
-
snapshotsRaw =
|
|
160
|
-
return [4 /*yield*/, window.threekit.configurator.setConfiguration((
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
snapshotsRaw = _c.sent();
|
|
159
|
+
return [4 /*yield*/, window.threekit.configurator.setConfiguration((_b = {},
|
|
160
|
+
_b[attributeName] = currentCamera,
|
|
161
|
+
_b))];
|
|
163
162
|
case 4:
|
|
164
|
-
|
|
163
|
+
_c.sent();
|
|
165
164
|
(0, utils_1.setCameraPosition)(window.threekit.player.camera, cameraPosition);
|
|
166
|
-
|
|
165
|
+
_c.label = 5;
|
|
167
166
|
case 5:
|
|
168
|
-
|
|
169
|
-
switch (
|
|
167
|
+
_a = output;
|
|
168
|
+
switch (_a) {
|
|
170
169
|
case constants_1.SNAPSHOT_OUTPUTS.url: return [3 /*break*/, 6];
|
|
171
170
|
case constants_1.SNAPSHOT_OUTPUTS.download: return [3 /*break*/, 8];
|
|
172
171
|
case constants_1.SNAPSHOT_OUTPUTS.blob: return [3 /*break*/, 9];
|
|
@@ -179,8 +178,11 @@ var Snapshots = /** @class */ (function () {
|
|
|
179
178
|
var _a;
|
|
180
179
|
var cameraName = (camerasList === null || camerasList === void 0 ? void 0 : camerasList[idx])
|
|
181
180
|
? (0, utils_1.regularToKebabCase)(camerasList[idx] || 'default')
|
|
182
|
-
:
|
|
183
|
-
var
|
|
181
|
+
: filename;
|
|
182
|
+
var preppedFilename = cameraName === filename
|
|
183
|
+
? "".concat(filename, ".").concat(format)
|
|
184
|
+
: "".concat(filename, "-").concat(cameraName, ".").concat(format);
|
|
185
|
+
var file = (0, utils_1.dataURItoFile)(el, preppedFilename);
|
|
184
186
|
return Object.assign(output, (_a = {}, _a[cameraName] = file, _a));
|
|
185
187
|
}, {});
|
|
186
188
|
return [4 /*yield*/, api_1.default.configurations.save({
|
|
@@ -189,10 +191,8 @@ var Snapshots = /** @class */ (function () {
|
|
|
189
191
|
attachments: attachments,
|
|
190
192
|
})];
|
|
191
193
|
case 7:
|
|
192
|
-
|
|
193
|
-
urlsArray = Object.
|
|
194
|
-
return "".concat(threekitDomain, "/api/configurations/").concat(response_1.data.shortId, "/files/").concat(key, "?orgId=").concat(orgId);
|
|
195
|
-
});
|
|
194
|
+
response = _c.sent();
|
|
195
|
+
urlsArray = Object.values(response.data.attachments);
|
|
196
196
|
return [2 /*return*/, Promise.resolve(urlsArray)];
|
|
197
197
|
case 8:
|
|
198
198
|
snapshotsRaw.forEach(function (snapshotBlob, idx) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Header = exports.Wrapper = void 0;
|
|
11
|
+
var styled_components_1 = __importDefault(require("styled-components"));
|
|
12
|
+
exports.Wrapper = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: 10px 15px;\n"], ["\n padding: 10px 15px;\n"])));
|
|
13
|
+
exports.Header = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n font-size: 18px;\n font-weight: 400;\n text-align: center;\n"], ["\n font-size: 18px;\n font-weight: 400;\n text-align: center;\n"])));
|
|
14
|
+
var templateObject_1, templateObject_2;
|
|
@@ -0,0 +1,18 @@
|
|
|
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.DevTools = void 0;
|
|
7
|
+
var react_1 = __importDefault(require("react"));
|
|
8
|
+
var useDevTools_1 = __importDefault(require("../../hooks/useDevTools"));
|
|
9
|
+
var Drawer_1 = __importDefault(require("../Drawer"));
|
|
10
|
+
var devTools_styles_1 = require("./devTools.styles");
|
|
11
|
+
var DevTools = function () {
|
|
12
|
+
var _a = (0, useDevTools_1.default)(), showDevTools = _a[0], setShowDevTools = _a[1];
|
|
13
|
+
return (react_1.default.createElement(Drawer_1.default, { showHeader: false, show: showDevTools, handleClose: function () { return setShowDevTools(false); } },
|
|
14
|
+
react_1.default.createElement(devTools_styles_1.Wrapper, null,
|
|
15
|
+
react_1.default.createElement(devTools_styles_1.Header, null, "Treble - Dev Tools"))));
|
|
16
|
+
};
|
|
17
|
+
exports.DevTools = DevTools;
|
|
18
|
+
exports.default = exports.DevTools;
|
|
@@ -4,8 +4,8 @@ interface IProductDescription {
|
|
|
4
4
|
description?: string;
|
|
5
5
|
className?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
8
|
-
(props: IProductDescription): JSX.Element
|
|
7
|
+
export declare const ProductDescriptionComponent: {
|
|
8
|
+
(props: IProductDescription): JSX.Element;
|
|
9
9
|
propTypes: {
|
|
10
10
|
/**
|
|
11
11
|
* The description displayed to the user
|
|
@@ -21,4 +21,5 @@ export declare const ProductDescription: {
|
|
|
21
21
|
className: string;
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
declare const ProductDescription: (props: IProductDescription) => JSX.Element | null;
|
|
24
25
|
export default ProductDescription;
|
|
@@ -3,25 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.ProductDescriptionComponent = void 0;
|
|
7
7
|
var react_1 = __importDefault(require("react"));
|
|
8
8
|
var prop_types_1 = __importDefault(require("prop-types"));
|
|
9
|
-
var
|
|
9
|
+
var productDescription_styles_1 = require("./productDescription.styles");
|
|
10
10
|
var useMetadata_1 = __importDefault(require("../../hooks/useMetadata"));
|
|
11
11
|
var utils_1 = require("../../utils");
|
|
12
|
+
var ProductDescriptionComponent = function (props) {
|
|
13
|
+
var _a = Object.assign({ className: '' }, props), description = _a.description, customClassName = _a.className;
|
|
14
|
+
var cls = (0, utils_1.generateDisplayClassName)('description', customClassName);
|
|
15
|
+
return react_1.default.createElement(productDescription_styles_1.Wrapper, { className: cls }, description);
|
|
16
|
+
};
|
|
17
|
+
exports.ProductDescriptionComponent = ProductDescriptionComponent;
|
|
12
18
|
var ProductDescription = function (props) {
|
|
13
|
-
var _a
|
|
19
|
+
var _a;
|
|
20
|
+
var _b = Object.assign({
|
|
14
21
|
description: undefined,
|
|
15
|
-
|
|
16
|
-
}, props), description = _a.description, customClassName = _a.className;
|
|
22
|
+
}, props), description = _b.description, className = _b.className;
|
|
17
23
|
var metadata = (0, useMetadata_1.default)();
|
|
18
24
|
if (!description && !(metadata === null || metadata === void 0 ? void 0 : metadata._description))
|
|
19
25
|
return null;
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
if (!description)
|
|
27
|
+
return null;
|
|
28
|
+
return (react_1.default.createElement(exports.ProductDescriptionComponent, { className: className, description: ((_a = metadata === null || metadata === void 0 ? void 0 : metadata._description) === null || _a === void 0 ? void 0 : _a.toString()) || description }));
|
|
22
29
|
};
|
|
23
|
-
exports.
|
|
24
|
-
exports.ProductDescription.propTypes = {
|
|
30
|
+
exports.ProductDescriptionComponent.propTypes = {
|
|
25
31
|
/**
|
|
26
32
|
* The description displayed to the user
|
|
27
33
|
*/
|
|
@@ -31,8 +37,8 @@ exports.ProductDescription.propTypes = {
|
|
|
31
37
|
*/
|
|
32
38
|
className: prop_types_1.default.string,
|
|
33
39
|
};
|
|
34
|
-
exports.
|
|
40
|
+
exports.ProductDescriptionComponent.defaultProps = {
|
|
35
41
|
description: undefined,
|
|
36
42
|
className: '',
|
|
37
43
|
};
|
|
38
|
-
exports.default =
|
|
44
|
+
exports.default = ProductDescription;
|
|
File without changes
|
package/dist/components/ProductDescription/{description.styles.js → productDescription.styles.js}
RENAMED
|
File without changes
|
|
@@ -5,8 +5,8 @@ interface ITitle {
|
|
|
5
5
|
className?: string;
|
|
6
6
|
align?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const
|
|
9
|
-
(props: ITitle): JSX.Element
|
|
8
|
+
export declare const ProductNameComponent: {
|
|
9
|
+
(props: ITitle): JSX.Element;
|
|
10
10
|
propTypes: {
|
|
11
11
|
/**
|
|
12
12
|
* The title displayed to the user
|
|
@@ -26,4 +26,5 @@ export declare const ProductName: {
|
|
|
26
26
|
align: string;
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
export declare const ProductName: (props: ITitle) => JSX.Element | null;
|
|
29
30
|
export default ProductName;
|
|
@@ -3,22 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ProductName = void 0;
|
|
6
|
+
exports.ProductName = exports.ProductNameComponent = void 0;
|
|
7
7
|
var react_1 = __importDefault(require("react"));
|
|
8
8
|
var prop_types_1 = __importDefault(require("prop-types"));
|
|
9
9
|
var productName_styles_1 = require("./productName.styles");
|
|
10
10
|
var useName_1 = __importDefault(require("../../hooks/useName"));
|
|
11
11
|
var utils_1 = require("../../utils");
|
|
12
|
-
var
|
|
12
|
+
var ProductNameComponent = function (props) {
|
|
13
13
|
var _a = Object.assign({ className: '', align: 'left' }, props), title = _a.title, customClassName = _a.className, align = _a.align;
|
|
14
|
+
var cls = (0, utils_1.generateDisplayClassName)('title', customClassName);
|
|
15
|
+
return (react_1.default.createElement(productName_styles_1.Wrapper, { align: align, className: cls }, title));
|
|
16
|
+
};
|
|
17
|
+
exports.ProductNameComponent = ProductNameComponent;
|
|
18
|
+
var ProductName = function (props) {
|
|
19
|
+
var title = props.title, className = props.className, align = props.align;
|
|
14
20
|
var name = (0, useName_1.default)();
|
|
15
21
|
if (!(title === null || title === void 0 ? void 0 : title.length) && !name)
|
|
16
22
|
return null;
|
|
17
|
-
|
|
18
|
-
return (react_1.default.createElement(productName_styles_1.Wrapper, { align: align, className: cls }, title || name));
|
|
23
|
+
return (react_1.default.createElement(exports.ProductNameComponent, { align: align, className: className, title: title || name }));
|
|
19
24
|
};
|
|
20
25
|
exports.ProductName = ProductName;
|
|
21
|
-
exports.
|
|
26
|
+
exports.ProductNameComponent.propTypes = {
|
|
22
27
|
/**
|
|
23
28
|
* The title displayed to the user
|
|
24
29
|
*/
|
|
@@ -32,7 +37,7 @@ exports.ProductName.propTypes = {
|
|
|
32
37
|
*/
|
|
33
38
|
align: prop_types_1.default.string,
|
|
34
39
|
};
|
|
35
|
-
exports.
|
|
40
|
+
exports.ProductNameComponent.defaultProps = {
|
|
36
41
|
className: '',
|
|
37
42
|
align: 'left',
|
|
38
43
|
};
|
|
@@ -29,6 +29,7 @@ var react_redux_1 = require("react-redux");
|
|
|
29
29
|
var styled_components_1 = require("styled-components");
|
|
30
30
|
var theme_1 = __importDefault(require("../../theme"));
|
|
31
31
|
var GlobalStyles_styles_1 = __importDefault(require("./GlobalStyles.styles"));
|
|
32
|
+
var DevTools_1 = __importDefault(require("../DevTools"));
|
|
32
33
|
var App = function (props) {
|
|
33
34
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
34
35
|
var playerConfig = props.playerConfig, productId = props.productId, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv, eventHandlers = props.eventHandlers;
|
|
@@ -52,6 +53,7 @@ var ThreekitProvider = function (props) {
|
|
|
52
53
|
return (react_1.default.createElement(react_redux_1.Provider, { store: (0, store_1.default)(props.reducer) },
|
|
53
54
|
react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme_1.default },
|
|
54
55
|
react_1.default.createElement(GlobalStyles_styles_1.default, null),
|
|
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)
|
|
56
|
+
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),
|
|
57
|
+
react_1.default.createElement(DevTools_1.default, null))));
|
|
56
58
|
};
|
|
57
59
|
exports.default = ThreekitProvider;
|
|
@@ -4,8 +4,8 @@ interface IPrice {
|
|
|
4
4
|
price?: string;
|
|
5
5
|
className?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const
|
|
8
|
-
(props: IPrice): JSX.Element
|
|
7
|
+
export declare const TotalPriceComponent: {
|
|
8
|
+
(props: IPrice): JSX.Element;
|
|
9
9
|
propTypes: {
|
|
10
10
|
/**
|
|
11
11
|
* The price displayed to the user
|
|
@@ -21,4 +21,5 @@ export declare const TotalPrice: {
|
|
|
21
21
|
className: string;
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
export declare const TotalPrice: (props: IPrice) => JSX.Element | null;
|
|
24
25
|
export default TotalPrice;
|
|
@@ -3,25 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TotalPrice = void 0;
|
|
6
|
+
exports.TotalPrice = exports.TotalPriceComponent = void 0;
|
|
7
7
|
var react_1 = __importDefault(require("react"));
|
|
8
8
|
var prop_types_1 = __importDefault(require("prop-types"));
|
|
9
9
|
var totalPrice_styles_1 = require("./totalPrice.styles");
|
|
10
10
|
var usePrice_1 = __importDefault(require("../../hooks/usePrice"));
|
|
11
11
|
var utils_1 = require("../../utils");
|
|
12
|
-
var
|
|
12
|
+
var TotalPriceComponent = function (props) {
|
|
13
13
|
var price = props.price, customClassName = props.className;
|
|
14
|
-
var priceData = (0, usePrice_1.default)();
|
|
15
14
|
var cls = (0, utils_1.generateDisplayClassName)('price', customClassName);
|
|
15
|
+
return react_1.default.createElement(totalPrice_styles_1.Wrapper, { className: cls }, price);
|
|
16
|
+
};
|
|
17
|
+
exports.TotalPriceComponent = TotalPriceComponent;
|
|
18
|
+
var TotalPrice = function (props) {
|
|
19
|
+
var price = props.price, className = props.className;
|
|
20
|
+
var priceData = (0, usePrice_1.default)();
|
|
16
21
|
var preppedPrice = props.price;
|
|
17
22
|
if (priceData)
|
|
18
23
|
preppedPrice = "".concat(priceData.price, " ").concat(priceData.currency);
|
|
19
24
|
if (!price && !priceData)
|
|
20
25
|
return null;
|
|
21
|
-
return react_1.default.createElement(
|
|
26
|
+
return react_1.default.createElement(exports.TotalPriceComponent, { className: className, price: preppedPrice });
|
|
22
27
|
};
|
|
23
28
|
exports.TotalPrice = TotalPrice;
|
|
24
|
-
exports.
|
|
29
|
+
exports.TotalPriceComponent.propTypes = {
|
|
25
30
|
/**
|
|
26
31
|
* The price displayed to the user
|
|
27
32
|
*/
|
|
@@ -31,7 +36,7 @@ exports.TotalPrice.propTypes = {
|
|
|
31
36
|
*/
|
|
32
37
|
className: prop_types_1.default.string,
|
|
33
38
|
};
|
|
34
|
-
exports.
|
|
39
|
+
exports.TotalPriceComponent.defaultProps = {
|
|
35
40
|
price: undefined,
|
|
36
41
|
className: '',
|
|
37
42
|
};
|
|
@@ -44,7 +44,7 @@ var Products = function () {
|
|
|
44
44
|
exports.Products = Products;
|
|
45
45
|
function TrebleApp(props) {
|
|
46
46
|
var _a;
|
|
47
|
-
var project = props.project, productId = props.productId, playerConfig = props.playerConfig, threekitEnv = props.threekitEnv, locale = props.locale, theme = props.theme, eventHandlers = props.eventHandlers;
|
|
47
|
+
var project = props.project, productId = props.productId, playerConfig = props.playerConfig, threekitEnv = props.threekitEnv, locale = props.locale, theme = props.theme, eventHandlers = props.eventHandlers, reducer = props.reducer;
|
|
48
48
|
var config = constants_1.IS_TREBLE_SCRIPTS ? (0, utils_1.loadTrebleConfig)() : {};
|
|
49
49
|
if (!((_a = config.treble) === null || _a === void 0 ? void 0 : _a.productsCtx)) {
|
|
50
50
|
console.error('Treble Config is not setup correctly');
|
|
@@ -85,7 +85,7 @@ function TrebleApp(props) {
|
|
|
85
85
|
var preppedProject = Object.assign({}, project, {
|
|
86
86
|
products: productsMap,
|
|
87
87
|
});
|
|
88
|
-
return (react_1.default.createElement(ThreekitProvider_1.default, { productId: id, project: preppedProject, locale: locale, playerConfig: playerConfig, theme: theme, threekitEnv: threekitEnv, eventHandlers: eventHandlers },
|
|
88
|
+
return (react_1.default.createElement(ThreekitProvider_1.default, { productId: id, project: preppedProject, locale: locale, playerConfig: playerConfig, theme: theme, threekitEnv: threekitEnv, eventHandlers: eventHandlers, reducer: reducer },
|
|
89
89
|
react_1.default.createElement(exports.Products, null)));
|
|
90
90
|
}
|
|
91
91
|
exports.default = TrebleApp;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDevTools = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var useDevTools = function () {
|
|
6
|
+
var _a = (0, react_1.useState)(false), showDevTools = _a[0], setShowDevTools = _a[1];
|
|
7
|
+
var pressedKeysRef = (0, react_1.useRef)({
|
|
8
|
+
t: false,
|
|
9
|
+
k: false,
|
|
10
|
+
});
|
|
11
|
+
var keydownListener = function (event) {
|
|
12
|
+
if (event.altKey && event.code === 'KeyT')
|
|
13
|
+
pressedKeysRef.current.t = true;
|
|
14
|
+
else if (event.altKey && event.code === 'KeyK')
|
|
15
|
+
pressedKeysRef.current.k = true;
|
|
16
|
+
var allPressed = Object.values(pressedKeysRef.current).reduce(function (result, bool) {
|
|
17
|
+
if (!result || !bool)
|
|
18
|
+
return false;
|
|
19
|
+
return bool;
|
|
20
|
+
}, true);
|
|
21
|
+
if (allPressed)
|
|
22
|
+
setShowDevTools(true);
|
|
23
|
+
};
|
|
24
|
+
var keyupListener = function (event) {
|
|
25
|
+
if (event.code === 'KeyT')
|
|
26
|
+
pressedKeysRef.current.t = false;
|
|
27
|
+
else if (event.code === 'KeyK')
|
|
28
|
+
pressedKeysRef.current.k = false;
|
|
29
|
+
};
|
|
30
|
+
(0, react_1.useEffect)(function () {
|
|
31
|
+
(function () {
|
|
32
|
+
document.addEventListener('keydown', keydownListener);
|
|
33
|
+
document.addEventListener('keyup', keyupListener);
|
|
34
|
+
})();
|
|
35
|
+
return function () {
|
|
36
|
+
document.removeEventListener('keydown', keydownListener);
|
|
37
|
+
document.removeEventListener('keyup', keyupListener);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
return [showDevTools, function (val) { return setShowDevTools(val); }];
|
|
41
|
+
};
|
|
42
|
+
exports.useDevTools = useDevTools;
|
|
43
|
+
exports.default = exports.useDevTools;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IHydratedAttribute, IMetadata, ISetConfiguration } from '../../types';
|
|
2
|
-
declare type UseNestedConfiguratorError = [undefined, undefined, undefined];
|
|
2
|
+
declare type UseNestedConfiguratorError = [undefined, undefined, undefined, undefined];
|
|
3
3
|
declare type UseNestedConfiguratorSuccess = [
|
|
4
4
|
Record<string, IHydratedAttribute>,
|
|
5
5
|
(val: ISetConfiguration) => Promise<void>,
|
|
6
|
-
IMetadata
|
|
6
|
+
IMetadata,
|
|
7
|
+
number | undefined
|
|
7
8
|
];
|
|
8
9
|
declare const useNestedConfigurator: (address: string | Array<string>) => UseNestedConfiguratorError | UseNestedConfiguratorSuccess;
|
|
9
10
|
export default useNestedConfigurator;
|
|
@@ -41,10 +41,12 @@ var store_1 = require("../../store");
|
|
|
41
41
|
var treble_1 = require("../../store/treble");
|
|
42
42
|
var utils_1 = require("../../utils");
|
|
43
43
|
var attributes_1 = require("../../store/attributes");
|
|
44
|
+
var price_1 = require("../../store/price");
|
|
44
45
|
var useNestedConfigurator = function (address) {
|
|
45
46
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
46
47
|
var hasInitialized = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
|
|
47
48
|
var playerLoading = (0, store_1.useThreekitSelector)(treble_1.isPlayerLoading);
|
|
49
|
+
var priceConfig = (0, store_1.useThreekitSelector)(price_1.getPriceConfig);
|
|
48
50
|
var _a = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), _ = _a[0], translations = _a[1], language = _a[2];
|
|
49
51
|
var _b = (0, react_1.useState)(), attributes = _b[0], setAttributes = _b[1];
|
|
50
52
|
var metadataRef = (0, react_1.useRef)({});
|
|
@@ -63,9 +65,9 @@ var useNestedConfigurator = function (address) {
|
|
|
63
65
|
setAttributes(updatedAttrs);
|
|
64
66
|
metadataRef.current = configurator.current.getMetadata();
|
|
65
67
|
})();
|
|
66
|
-
}, [hasInitialized,
|
|
68
|
+
}, [hasInitialized, playerLoading]);
|
|
67
69
|
if (!hasInitialized || !configurator.current || !attributes)
|
|
68
|
-
return [undefined, undefined, undefined];
|
|
70
|
+
return [undefined, undefined, undefined, undefined];
|
|
69
71
|
var handleSelect = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
72
|
var updatedAttrs;
|
|
71
73
|
var _a, _b;
|
|
@@ -89,6 +91,9 @@ var useNestedConfigurator = function (address) {
|
|
|
89
91
|
return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
|
|
90
92
|
}, {});
|
|
91
93
|
var preppedAttributes = (0, utils_1.hydrateAttribute)([attributeObj, translations, language], handleSelect);
|
|
92
|
-
|
|
94
|
+
var price = priceConfig
|
|
95
|
+
? configurator.current.getPrice(priceConfig.id, priceConfig.currency)
|
|
96
|
+
: undefined;
|
|
97
|
+
return [preppedAttributes, handleSelect, metadataRef.current, price];
|
|
93
98
|
};
|
|
94
99
|
exports.default = useNestedConfigurator;
|
package/dist/store/price.d.ts
CHANGED
|
@@ -2,11 +2,6 @@ import { RootState, ThreekitDispatch } from './index';
|
|
|
2
2
|
/*****************************************************
|
|
3
3
|
* Types and Interfaces
|
|
4
4
|
****************************************************/
|
|
5
|
-
export interface PriceState {
|
|
6
|
-
id: undefined | string;
|
|
7
|
-
currency: undefined | string;
|
|
8
|
-
price: undefined | number;
|
|
9
|
-
}
|
|
10
5
|
export interface IPriceConfig {
|
|
11
6
|
id: string;
|
|
12
7
|
currency: string;
|
|
@@ -15,6 +10,11 @@ export interface IPrice {
|
|
|
15
10
|
currency: string;
|
|
16
11
|
price: number;
|
|
17
12
|
}
|
|
13
|
+
export interface PriceState {
|
|
14
|
+
id: undefined | string;
|
|
15
|
+
currency: undefined | string;
|
|
16
|
+
price: undefined | number;
|
|
17
|
+
}
|
|
18
18
|
/*****************************************************
|
|
19
19
|
* Actions
|
|
20
20
|
****************************************************/
|
|
@@ -26,6 +26,7 @@ declare const reducer: import("redux").Reducer<PriceState, import("redux").AnyAc
|
|
|
26
26
|
* Standard Selectors
|
|
27
27
|
****************************************************/
|
|
28
28
|
export declare const getPrice: (state: RootState) => undefined | IPrice;
|
|
29
|
+
export declare const getPriceConfig: (state: RootState) => undefined | IPriceConfig;
|
|
29
30
|
/*****************************************************
|
|
30
31
|
* Complex Actions
|
|
31
32
|
****************************************************/
|
package/dist/store/price.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.updatePrice = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
|
|
42
|
+
exports.updatePrice = exports.getPriceConfig = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
|
|
43
43
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
44
44
|
var api_1 = __importDefault(require("../api"));
|
|
45
45
|
/*****************************************************
|
|
@@ -103,6 +103,13 @@ var getPrice = function (state) {
|
|
|
103
103
|
return { price: price, currency: currency };
|
|
104
104
|
};
|
|
105
105
|
exports.getPrice = getPrice;
|
|
106
|
+
var getPriceConfig = function (state) {
|
|
107
|
+
var _a = state.price, id = _a.id, currency = _a.currency;
|
|
108
|
+
if (!id || !currency)
|
|
109
|
+
return undefined;
|
|
110
|
+
return { id: id, currency: currency };
|
|
111
|
+
};
|
|
112
|
+
exports.getPriceConfig = getPriceConfig;
|
|
106
113
|
/*****************************************************
|
|
107
114
|
* Complex Actions
|
|
108
115
|
****************************************************/
|
package/dist/store/treble.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export declare const getPlayerElementId: (state: RootState) => undefined | strin
|
|
|
68
68
|
/*****************************************************
|
|
69
69
|
* Complex Actions
|
|
70
70
|
****************************************************/
|
|
71
|
-
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
71
|
+
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
72
72
|
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
73
73
|
export declare const unloadPlayer: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
74
74
|
export declare const reloadPlayer: (config: undefined | string | Pick<IReloadConfig, 'assetId' | 'stageId' | 'configurationId' | 'configuration'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
package/dist/store/treble.js
CHANGED
|
@@ -166,46 +166,62 @@ exports.getPlayerElementId = getPlayerElementId;
|
|
|
166
166
|
/*****************************************************
|
|
167
167
|
* Complex Actions
|
|
168
168
|
****************************************************/
|
|
169
|
-
var initPlayer = function (config) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
configurator: configurator,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
else
|
|
190
|
-
window.threekit = {
|
|
191
|
-
player: player,
|
|
192
|
-
configurator: configurator,
|
|
193
|
-
services: api_1.default,
|
|
194
|
-
treble: new Treble_1.default({
|
|
169
|
+
var initPlayer = function (config) {
|
|
170
|
+
return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
|
|
171
|
+
var el, authToken, assetId, stageId, orgId, playerConfig, initialConfiguration, player, configurator;
|
|
172
|
+
return __generator(this, function (_a) {
|
|
173
|
+
switch (_a.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
el = config.el, authToken = config.authToken, assetId = config.assetId, stageId = config.stageId, orgId = config.orgId, playerConfig = config.playerConfig, initialConfiguration = config.initialConfiguration;
|
|
176
|
+
return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
|
|
177
|
+
// Variables to sort out
|
|
178
|
+
authToken: authToken, stageId: stageId, assetId: assetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
179
|
+
case 1:
|
|
180
|
+
player = _a.sent();
|
|
181
|
+
return [4 /*yield*/, player.getConfigurator()];
|
|
182
|
+
case 2:
|
|
183
|
+
configurator = _a.sent();
|
|
184
|
+
if (window.threekit) {
|
|
185
|
+
window.threekit = Object.assign(window.threekit, {
|
|
195
186
|
player: player,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
})
|
|
187
|
+
configurator: configurator,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else
|
|
191
|
+
window.threekit = {
|
|
192
|
+
player: player,
|
|
193
|
+
configurator: configurator,
|
|
194
|
+
services: api_1.default,
|
|
195
|
+
treble: new Treble_1.default({
|
|
196
|
+
player: player,
|
|
197
|
+
orgId: orgId,
|
|
198
|
+
initialConfiguration: configurator.getConfiguration(),
|
|
199
|
+
}),
|
|
200
|
+
};
|
|
201
|
+
dispatch((0, exports.setThreekitInitialized)(true));
|
|
202
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
203
|
+
window.threekit.player.on('setConfiguration', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
204
|
+
var attributes, previousAttributes, updatedAttributes;
|
|
205
|
+
var _a;
|
|
206
|
+
return __generator(this, function (_b) {
|
|
207
|
+
switch (_b.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
attributes = getState().attributes;
|
|
210
|
+
previousAttributes = Object.values(attributes);
|
|
211
|
+
updatedAttributes = window.threekit.configurator.getDisplayAttributes();
|
|
212
|
+
dispatch((0, attributes_1.setAttributes)(updatedAttributes));
|
|
213
|
+
return [4 /*yield*/, ((_a = EVENTS.postConfigurationChange) === null || _a === void 0 ? void 0 : _a.call(EVENTS, updatedAttributes, {}, previousAttributes))];
|
|
214
|
+
case 1:
|
|
215
|
+
_b.sent();
|
|
216
|
+
return [2 /*return*/];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}); });
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}); };
|
|
224
|
+
};
|
|
209
225
|
exports.initPlayer = initPlayer;
|
|
210
226
|
var launch = function (launchConfig) {
|
|
211
227
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
package/dist/types.d.ts
CHANGED
|
@@ -164,6 +164,13 @@ export declare type SNAPSHOT_FORMAT_TYPES = 'jpg' | 'png';
|
|
|
164
164
|
/***************************************************
|
|
165
165
|
* Threekit Api
|
|
166
166
|
**************************************************/
|
|
167
|
+
export interface IConfigurationChangeEvent {
|
|
168
|
+
name: string;
|
|
169
|
+
appliedConfiguration: Record<string, string>;
|
|
170
|
+
previousConfiguration: IConfiguration;
|
|
171
|
+
configuration: IConfiguration;
|
|
172
|
+
metadata: Record<string, string>;
|
|
173
|
+
}
|
|
167
174
|
export interface IThreekitConfigurator {
|
|
168
175
|
getMetadata: () => IMetadata;
|
|
169
176
|
getAttributes: () => Array<IThreekitAttribute>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threekit-tools/treble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.70",
|
|
4
4
|
"author": "Amaan Saeed",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -60,12 +60,13 @@
|
|
|
60
60
|
"@types/webpack-env": "^1.16.3",
|
|
61
61
|
"babel-jest": "^27.5.1",
|
|
62
62
|
"babel-loader": "^8.2.2",
|
|
63
|
+
"chromatic": "^6.5.3",
|
|
63
64
|
"jest": "^27.5.1",
|
|
64
65
|
"react": ">=17.0.2",
|
|
65
66
|
"react-dom": ">=17.0.2",
|
|
66
67
|
"rimraf": "^3.0.2",
|
|
67
68
|
"serve": "^12.0.1",
|
|
68
|
-
"storybook
|
|
69
|
+
"themeprovider-storybook": "^1.8.0",
|
|
69
70
|
"ts-jest": "^27.1.3",
|
|
70
71
|
"typescript": ">=4.4.4"
|
|
71
72
|
},
|