@threekit-tools/treble 0.0.96 → 0.0.97-beta-01
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 +1 -1
- package/dist/components/Share/index.js +13 -21
- package/dist/components/ThreekitProvider/index.js +11 -14
- package/dist/hooks/useAnalyticsSession/index.d.ts +6 -0
- package/dist/hooks/useAnalyticsSession/index.js +17 -0
- package/dist/hooks/useAttribute/index.js +34 -6
- package/dist/hooks/useShare/index.js +15 -0
- package/dist/store/attributes.js +26 -2
- package/dist/store/product.js +1 -4
- package/dist/store/treble.d.ts +2 -2
- package/dist/store/treble.js +53 -36
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +65 -3
- package/package.json +3 -1
package/dist/Treble/Treble.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare class Treble {
|
|
|
22
22
|
_player: IThreekitPrivatePlayer;
|
|
23
23
|
wishlist: IWishlist;
|
|
24
24
|
private _snapshots;
|
|
25
|
-
takeSnapshots:
|
|
25
|
+
takeSnapshots: typeof snapshots['takeSnapshots'];
|
|
26
26
|
_debugMode: boolean;
|
|
27
27
|
constructor({ player, orgId }: ITreble);
|
|
28
28
|
createOrder: (order?: IOrder) => Promise<import("../http/orders").IOrderResponse>;
|
|
@@ -71,6 +71,7 @@ var Share_1 = __importDefault(require("../../icons/Share"));
|
|
|
71
71
|
var useThreekitInitStatus_1 = __importDefault(require("../../hooks/useThreekitInitStatus"));
|
|
72
72
|
var utils_1 = require("../../utils");
|
|
73
73
|
var share_styles_1 = require("./share.styles");
|
|
74
|
+
var useShare_1 = __importDefault(require("../../hooks/useShare"));
|
|
74
75
|
var Share = function (props) {
|
|
75
76
|
var _a = Object.assign({
|
|
76
77
|
type: 'threekit',
|
|
@@ -80,7 +81,8 @@ var Share = function (props) {
|
|
|
80
81
|
}, props), shape = _a.shape, type = _a.type, className = _a.className, msg = _a.message, position = _a.position;
|
|
81
82
|
var hasLoaded = (0, useThreekitInitStatus_1.default)();
|
|
82
83
|
var _b = (0, react_1.useState)(false), show = _b[0], setShow = _b[1];
|
|
83
|
-
var _c = (0, react_1.useState)(
|
|
84
|
+
var _c = (0, react_1.useState)(undefined), resumeUrl = _c[0], setResumeUrl = _c[1];
|
|
85
|
+
var handleShare = (0, useShare_1.default)();
|
|
84
86
|
var resumeUrlElRef = (0, react_1.useRef)(null);
|
|
85
87
|
var shareButtonRef = (0, react_1.useRef)(null);
|
|
86
88
|
var shareContentRef = (0, react_1.useRef)(null);
|
|
@@ -100,37 +102,27 @@ var Share = function (props) {
|
|
|
100
102
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
101
103
|
};
|
|
102
104
|
}, [show, shareButtonRef, shareContentRef]);
|
|
103
|
-
if (!hasLoaded)
|
|
105
|
+
if (!hasLoaded || !handleShare)
|
|
104
106
|
return null;
|
|
105
107
|
var cls = (0, utils_1.generateWidgetClassName)('share', className);
|
|
106
108
|
var handleClick = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var
|
|
109
|
+
var resumableUrl;
|
|
108
110
|
return __generator(this, function (_a) {
|
|
109
111
|
switch (_a.label) {
|
|
110
112
|
case 0:
|
|
111
113
|
if (show) {
|
|
112
|
-
setResumeUrl(
|
|
114
|
+
setResumeUrl(undefined);
|
|
113
115
|
setShow(!show);
|
|
114
116
|
return [2];
|
|
115
117
|
}
|
|
116
|
-
return [4,
|
|
118
|
+
return [4, handleShare(msg)];
|
|
117
119
|
case 1:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
_a.sent();
|
|
125
|
-
if (msg === null || msg === void 0 ? void 0 : msg.length)
|
|
126
|
-
message_1.default.info(msg);
|
|
127
|
-
return [3, 5];
|
|
128
|
-
case 4:
|
|
129
|
-
e_1 = _a.sent();
|
|
130
|
-
setResumeUrl(configuration.resumableUrl);
|
|
131
|
-
setShow(!show);
|
|
132
|
-
return [3, 5];
|
|
133
|
-
case 5: return [2];
|
|
120
|
+
resumableUrl = _a.sent();
|
|
121
|
+
if (resumableUrl !== undefined) {
|
|
122
|
+
setResumeUrl(resumableUrl);
|
|
123
|
+
setShow(!show);
|
|
124
|
+
}
|
|
125
|
+
return [2];
|
|
134
126
|
}
|
|
135
127
|
});
|
|
136
128
|
}); };
|
|
@@ -50,21 +50,18 @@ var App = function (props) {
|
|
|
50
50
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
51
51
|
var playerConfig = props.playerConfig, assetId = props.assetId, customId = props.customId, productId = props.productId, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv, eventHandlers = props.eventHandlers;
|
|
52
52
|
(0, react_1.useEffect)(function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}));
|
|
64
|
-
};
|
|
65
|
-
init();
|
|
53
|
+
dispatch((0, treble_1.launch)({
|
|
54
|
+
playerConfig: playerConfig,
|
|
55
|
+
productId: productId,
|
|
56
|
+
assetId: assetId,
|
|
57
|
+
customId: customId,
|
|
58
|
+
project: project,
|
|
59
|
+
locale: locale,
|
|
60
|
+
threekitEnv: threekitEnv,
|
|
61
|
+
eventHandlers: eventHandlers,
|
|
62
|
+
}));
|
|
66
63
|
return;
|
|
67
|
-
}, [props.project, props.threekitEnv, props.playerConfig]);
|
|
64
|
+
}, [assetId, props.project, props.threekitEnv, props.playerConfig]);
|
|
68
65
|
return react_1.default.createElement(react_1.default.Fragment, null, props.children);
|
|
69
66
|
};
|
|
70
67
|
var ThreekitProvider = function (props) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Session } from '@threekit/analytics';
|
|
2
|
+
declare type UseAnalyticsSessionSuccess = Session;
|
|
3
|
+
declare type UseAnalyticsSessionError = undefined;
|
|
4
|
+
declare type UseAnalyticsSession = UseAnalyticsSessionSuccess | UseAnalyticsSessionError;
|
|
5
|
+
declare const useAnalyticsSession: () => UseAnalyticsSession;
|
|
6
|
+
export default useAnalyticsSession;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var analytics_1 = require("@threekit/analytics");
|
|
4
|
+
var connection_1 = require("../../connection");
|
|
5
|
+
var useAnalyticsSession = function () {
|
|
6
|
+
var connection = new connection_1.ThreekitConnection();
|
|
7
|
+
var auth = {
|
|
8
|
+
orgId: connection._orgId,
|
|
9
|
+
host: connection._threekitDomain,
|
|
10
|
+
publicToken: connection._authToken,
|
|
11
|
+
};
|
|
12
|
+
var analyticsSession = (0, analytics_1.getSession)({ auth: auth });
|
|
13
|
+
if (!analyticsSession)
|
|
14
|
+
return undefined;
|
|
15
|
+
return analyticsSession;
|
|
16
|
+
};
|
|
17
|
+
exports.default = useAnalyticsSession;
|
|
@@ -35,17 +35,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
38
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
42
|
var store_1 = require("../../store");
|
|
40
43
|
var attributes_1 = require("../../store/attributes");
|
|
41
44
|
var utils_1 = require("../../utils");
|
|
42
45
|
var utils_2 = require("../../utils");
|
|
46
|
+
var useAnalyticsSession_1 = __importDefault(require("../useAnalyticsSession"));
|
|
47
|
+
var rest_api_1 = require("@threekit/rest-api");
|
|
43
48
|
var useAttribute = function (attributeName) {
|
|
44
49
|
var _a;
|
|
45
50
|
if (!attributeName)
|
|
46
51
|
return [undefined, undefined];
|
|
47
52
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
48
53
|
var _b = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), attributes = _b[0], translations = _b[1];
|
|
54
|
+
var analyticsSession = (0, useAnalyticsSession_1.default)();
|
|
49
55
|
if (!attributeName || !attributes)
|
|
50
56
|
return [undefined, undefined];
|
|
51
57
|
var attribute = attributes[attributeName];
|
|
@@ -53,20 +59,31 @@ var useAttribute = function (attributeName) {
|
|
|
53
59
|
return [undefined, undefined];
|
|
54
60
|
var preppedAttributes = (0, utils_2.hydrateAttribute)([(_a = {}, _a[attributeName] = attribute, _a), translations], function (config) { return dispatch((0, attributes_1.setConfiguration)(config)); });
|
|
55
61
|
var handleChange = function (value) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
-
var preppedValue,
|
|
62
|
+
var preppedValue, uploadId;
|
|
57
63
|
var _a;
|
|
58
64
|
return __generator(this, function (_b) {
|
|
59
65
|
switch (_b.label) {
|
|
60
66
|
case 0:
|
|
61
67
|
if (!(attribute.type === 'Asset' && attribute.assetType === 'upload')) return [3, 4];
|
|
62
|
-
if (!!value) return [3, 1];
|
|
63
|
-
preppedValue = (0, utils_1.selectionToConfiguration)('', attribute.type);
|
|
68
|
+
if (!!(value instanceof File)) return [3, 1];
|
|
69
|
+
preppedValue = (0, utils_1.selectionToConfiguration)(value !== null && value !== void 0 ? value : '', attribute.type);
|
|
64
70
|
return [3, 3];
|
|
65
71
|
case 1: return [4, window.threekit.player.uploadImage(value)];
|
|
66
72
|
case 2:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
uploadId = _b.sent();
|
|
74
|
+
try {
|
|
75
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.imageUpload({
|
|
76
|
+
assetId: window.threekit.player.assetId,
|
|
77
|
+
imageUploadId: attributeName,
|
|
78
|
+
imageUploadFileId: uploadId,
|
|
79
|
+
configuration: window.threekit.configurator.getFullConfiguration(),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
console.log('v2Analytics: Error reporting imageUpload event:', e);
|
|
84
|
+
}
|
|
85
|
+
if (uploadId)
|
|
86
|
+
preppedValue = (0, utils_1.selectionToConfiguration)(uploadId, attribute.type);
|
|
70
87
|
_b.label = 3;
|
|
71
88
|
case 3: return [3, 5];
|
|
72
89
|
case 4:
|
|
@@ -76,6 +93,17 @@ var useAttribute = function (attributeName) {
|
|
|
76
93
|
dispatch((0, attributes_1.setConfiguration)((_a = {},
|
|
77
94
|
_a[attributeName] = preppedValue,
|
|
78
95
|
_a)));
|
|
96
|
+
try {
|
|
97
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.optionInteraction({
|
|
98
|
+
optionsSetId: attribute.id,
|
|
99
|
+
optionId: attribute.name,
|
|
100
|
+
interactionType: rest_api_1.OptionInteractionType.Select,
|
|
101
|
+
configuration: window.threekit.configurator.getFullConfiguration(),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
console.log('v2Analytics: Error reporting optionInteraction event:', e);
|
|
106
|
+
}
|
|
79
107
|
return [2];
|
|
80
108
|
}
|
|
81
109
|
});
|
|
@@ -43,10 +43,13 @@ var store_1 = require("../../store");
|
|
|
43
43
|
var treble_1 = require("../../store/treble");
|
|
44
44
|
var message_1 = __importDefault(require("../../components/message"));
|
|
45
45
|
var utils_1 = require("../../utils");
|
|
46
|
+
var useAnalyticsSession_1 = __importDefault(require("../useAnalyticsSession"));
|
|
47
|
+
var rest_api_1 = require("@threekit/rest-api");
|
|
46
48
|
var useShare = function () {
|
|
47
49
|
var isLoaded = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
|
|
48
50
|
if (!isLoaded)
|
|
49
51
|
return undefined;
|
|
52
|
+
var analyticsSession = (0, useAnalyticsSession_1.default)();
|
|
50
53
|
var handleShare = function (msg) {
|
|
51
54
|
if (msg === void 0) { msg = 'Link copied'; }
|
|
52
55
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -63,6 +66,18 @@ var useShare = function () {
|
|
|
63
66
|
(0, utils_1.copyToClipboard)(configuration.resumableUrl);
|
|
64
67
|
if (msg === null || msg === void 0 ? void 0 : msg.length)
|
|
65
68
|
message_1.default.info(msg);
|
|
69
|
+
try {
|
|
70
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.share({
|
|
71
|
+
shareLink: configuration.resumableUrl,
|
|
72
|
+
shareType: rest_api_1.ShareType.Share,
|
|
73
|
+
assetId: window.threekit.player.assetId,
|
|
74
|
+
configurationId: configuration.id,
|
|
75
|
+
configuration: window.threekit.configurator.getFullConfiguration(),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.log('v2Analytics: Error reporting share event.');
|
|
80
|
+
}
|
|
66
81
|
return [2, Promise.resolve((configuration === null || configuration === void 0 ? void 0 : configuration.resumableUrl) || undefined)];
|
|
67
82
|
}
|
|
68
83
|
});
|
package/dist/store/attributes.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -56,8 +67,21 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
56
67
|
builder.addCase(treble_1.setThreekitInitialized, function () {
|
|
57
68
|
var attributes = window.threekit.configurator.getDisplayAttributes();
|
|
58
69
|
return attributes.reduce(function (output, attr) {
|
|
59
|
-
var _a;
|
|
60
|
-
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (attr.type === 'Color') {
|
|
72
|
+
return Object.assign(output, (_a = {},
|
|
73
|
+
_a[attr.name] = __assign(__assign({}, attr), { defaultValue: {
|
|
74
|
+
r: attr.defaultValue.r,
|
|
75
|
+
g: attr.defaultValue.g,
|
|
76
|
+
b: attr.defaultValue.b,
|
|
77
|
+
}, value: {
|
|
78
|
+
r: attr.value.r,
|
|
79
|
+
g: attr.value.g,
|
|
80
|
+
b: attr.value.b,
|
|
81
|
+
} }),
|
|
82
|
+
_a));
|
|
83
|
+
}
|
|
84
|
+
return Object.assign(output, (_b = {}, _b[attr.name] = attr, _b));
|
|
61
85
|
}, {});
|
|
62
86
|
});
|
|
63
87
|
builder.addCase(exports.setAttributes, function (_, action) {
|
package/dist/store/product.js
CHANGED
|
@@ -81,10 +81,7 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
81
81
|
return __assign(__assign({}, state), { id: action.payload });
|
|
82
82
|
});
|
|
83
83
|
builder.addCase(exports.setName, function (state, action) {
|
|
84
|
-
|
|
85
|
-
id: window.threekit.player.assetId,
|
|
86
|
-
}).name;
|
|
87
|
-
return __assign(__assign({}, state), { name: action.payload || name });
|
|
84
|
+
return __assign(__assign({}, state), { name: action.payload });
|
|
88
85
|
});
|
|
89
86
|
builder.addCase(exports.setMetadata, function (state, action) {
|
|
90
87
|
return __assign(__assign({}, state), { metadata: action.payload || window.threekit.configurator.getMetadata() });
|
package/dist/store/treble.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare const getPlayerElementId: (state: RootState) => undefined | strin
|
|
|
65
65
|
export declare const getLoadingProgress: (state: RootState) => undefined | number;
|
|
66
66
|
export declare const getPlayerInteraction: (state: RootState) => undefined | boolean;
|
|
67
67
|
export declare const initPlayer: (config: IPlayerInit) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
68
|
-
export declare const launch: (launchConfig
|
|
69
|
-
export declare const unloadPlayer: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
68
|
+
export declare const launch: (launchConfig: Partial<ILaunchConfig>) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
69
|
+
export declare const unloadPlayer: (playerEl?: HTMLElement) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
70
70
|
export declare const reloadPlayer: (config: undefined | string | Pick<IReloadConfig, 'assetId' | 'stageId' | 'configurationId' | 'configuration'>) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
|
|
71
71
|
export default reducer;
|
package/dist/store/treble.js
CHANGED
|
@@ -173,8 +173,10 @@ var initPlayer = function (config) {
|
|
|
173
173
|
case 0:
|
|
174
174
|
el = config.el, authToken = config.authToken, assetId = config.assetId, customId = config.customId, stageId = config.stageId, playerConfig = config.playerConfig, initialConfiguration = config.initialConfiguration;
|
|
175
175
|
dispatch((0, exports.updateLoadingProgress)(0));
|
|
176
|
-
return [4, window.threekitPlayer(__assign(__assign({ el: el, authToken: authToken, stageId: stageId, assetId: assetId, customId: customId }, playerConfig), { initialConfiguration: initialConfiguration, onLoadingProgress: function (progress) {
|
|
176
|
+
return [4, window.threekitPlayer(__assign(__assign({ el: el, authToken: authToken, stageId: stageId, assetId: assetId, customId: customId }, playerConfig), { pricing: false, initialConfiguration: initialConfiguration, onLoadingProgress: function (progress) {
|
|
177
177
|
var _a;
|
|
178
|
+
if (progress > 0)
|
|
179
|
+
el.style.visibility = 'visible';
|
|
178
180
|
dispatch((0, exports.updateLoadingProgress)(progress));
|
|
179
181
|
(_a = playerConfig === null || playerConfig === void 0 ? void 0 : playerConfig.onLoadingProgress) === null || _a === void 0 ? void 0 : _a.call(playerConfig, progress);
|
|
180
182
|
} }))];
|
|
@@ -263,17 +265,24 @@ var initPlayer = function (config) {
|
|
|
263
265
|
exports.initPlayer = initPlayer;
|
|
264
266
|
var launch = function (launchConfig) {
|
|
265
267
|
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
-
var config, productId, credentials, productsRaw, products, threekitEnv, serverUrl, playerConfig, envCredentials, _a, assetIdRaw, customIdRaw, stageId, configurationId, initialConfigurationRaw, customId, assetId, threekitDomainRaw, authToken, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
267
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
268
|
-
return __generator(this, function (
|
|
269
|
-
switch (
|
|
268
|
+
var config, playerElId, productId, credentials, productsRaw, products, threekitEnv, serverUrl, playerConfig, envCredentials, _a, assetIdRaw, customIdRaw, stageId, configurationId, initialConfigurationRaw, customId, assetId, threekitDomainRaw, authToken, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration;
|
|
269
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
270
|
+
return __generator(this, function (_q) {
|
|
271
|
+
switch (_q.label) {
|
|
270
272
|
case 0:
|
|
271
|
-
if (window.threekit)
|
|
272
|
-
return [2];
|
|
273
273
|
config = (0, utils_1.loadTrebleConfig)();
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
if (!window.threekit) return [3, 2];
|
|
275
|
+
if (launchConfig.assetId === window.threekit.player.assetId)
|
|
276
|
+
return [2];
|
|
277
|
+
playerElId = (_e = (_c = (_b = config === null || config === void 0 ? void 0 : config.player) === null || _b === void 0 ? void 0 : _b.elementId) !== null && _c !== void 0 ? _c : (_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig) === null || _d === void 0 ? void 0 : _d.elementId) !== null && _e !== void 0 ? _e : constants_1.TK_PLAYER_ROOT_DIV;
|
|
278
|
+
return [4, dispatch((0, exports.unloadPlayer)((_f = document.getElementById(playerElId)) !== null && _f !== void 0 ? _f : undefined))];
|
|
279
|
+
case 1:
|
|
280
|
+
_q.sent();
|
|
281
|
+
_q.label = 2;
|
|
282
|
+
case 2:
|
|
283
|
+
credentials = ((_g = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _g === void 0 ? void 0 : _g.credentials) || ((_h = config.project) === null || _h === void 0 ? void 0 : _h.credentials) || {};
|
|
284
|
+
productsRaw = ((_j = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _j === void 0 ? void 0 : _j.products) || ((_k = config.project) === null || _k === void 0 ? void 0 : _k.products) || {};
|
|
285
|
+
if (!((_l = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.productId) === null || _l === void 0 ? void 0 : _l.length)) {
|
|
277
286
|
productsRaw = { default: productsRaw };
|
|
278
287
|
productId = 'default';
|
|
279
288
|
}
|
|
@@ -325,12 +334,12 @@ var launch = function (launchConfig) {
|
|
|
325
334
|
(0, product_1.setProducts)(products);
|
|
326
335
|
dispatch((0, product_1.setProductId)(productId));
|
|
327
336
|
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
328
|
-
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((
|
|
337
|
+
serverUrl = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.serverUrl) || ((_m = config === null || config === void 0 ? void 0 : config.project) === null || _m === void 0 ? void 0 : _m.serverUrl);
|
|
329
338
|
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
330
339
|
envCredentials = credentials[threekitEnv];
|
|
331
340
|
_a = products[productId][threekitEnv] || {}, assetIdRaw = _a.assetId, customIdRaw = _a.customId, stageId = _a.stageId, configurationId = _a.configurationId, initialConfigurationRaw = _a.initialConfiguration;
|
|
332
341
|
customId = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.customId) || customIdRaw;
|
|
333
|
-
assetId = ((
|
|
342
|
+
assetId = ((_o = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.customId) === null || _o === void 0 ? void 0 : _o.length)
|
|
334
343
|
? undefined
|
|
335
344
|
: (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.assetId) || assetIdRaw;
|
|
336
345
|
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
@@ -355,22 +364,23 @@ var launch = function (launchConfig) {
|
|
|
355
364
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
356
365
|
updatedAssetId = assetId;
|
|
357
366
|
params = (0, utils_1.getParams)();
|
|
358
|
-
configId = ((
|
|
367
|
+
configId = ((_p = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _p === void 0 ? void 0 : _p.length)
|
|
359
368
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
360
369
|
: configurationId;
|
|
361
|
-
if (!configId) return [3,
|
|
370
|
+
if (!configId) return [3, 4];
|
|
362
371
|
return [4, api_1.default.configurations.fetch(configId)];
|
|
363
|
-
case
|
|
364
|
-
configuration =
|
|
372
|
+
case 3:
|
|
373
|
+
configuration = _q.sent();
|
|
365
374
|
if (configuration) {
|
|
366
375
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
367
376
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
368
377
|
updatedAssetId = configuration.data.productId;
|
|
369
378
|
}
|
|
370
|
-
|
|
371
|
-
case
|
|
379
|
+
_q.label = 4;
|
|
380
|
+
case 4:
|
|
372
381
|
if (!updatedAssetId && !customId)
|
|
373
382
|
throw new Error('missing assetId and customId');
|
|
383
|
+
if (!!window.threekitPlayer) return [3, 6];
|
|
374
384
|
return [4, new Promise(function (resolve) {
|
|
375
385
|
var script = document.createElement('script');
|
|
376
386
|
script.src = "".concat(threekitDomain, "/app/js/threekit-player-bundle.js");
|
|
@@ -378,30 +388,35 @@ var launch = function (launchConfig) {
|
|
|
378
388
|
script.onload = function () { return resolve(); };
|
|
379
389
|
document.head.appendChild(script);
|
|
380
390
|
})];
|
|
381
|
-
case
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
case 5:
|
|
392
|
+
_q.sent();
|
|
393
|
+
_q.label = 6;
|
|
394
|
+
case 6: return [4, dispatch((0, exports.initPlayer)({
|
|
395
|
+
el: el,
|
|
396
|
+
authToken: authToken,
|
|
397
|
+
stageId: stageId,
|
|
398
|
+
assetId: updatedAssetId,
|
|
399
|
+
customId: customId,
|
|
400
|
+
playerConfig: playerConfig,
|
|
401
|
+
initialConfiguration: initialConfiguration,
|
|
402
|
+
}))];
|
|
403
|
+
case 7:
|
|
404
|
+
_q.sent();
|
|
394
405
|
document.addEventListener('treble:notification', function (e) {
|
|
395
406
|
message_1.default.info(e.detail.message);
|
|
396
407
|
});
|
|
397
408
|
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
398
|
-
dispatch((0, product_1.setName)(
|
|
409
|
+
dispatch((0, product_1.setName)(window.threekit.player.scene.get({
|
|
410
|
+
id: window.threekit.player.assetId,
|
|
411
|
+
}).name));
|
|
399
412
|
dispatch((0, product_1.setMetadata)());
|
|
400
413
|
dispatch((0, product_1.initProduct)());
|
|
401
414
|
dispatch((0, exports.setThreekitEnv)(threekitEnv));
|
|
402
415
|
dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
|
|
403
|
-
|
|
404
|
-
|
|
416
|
+
if (playerConfig.pricing) {
|
|
417
|
+
dispatch((0, price_1.initPrice)());
|
|
418
|
+
dispatch((0, price_1.updatePrice)());
|
|
419
|
+
}
|
|
405
420
|
dispatch((0, wishlist_1.refreshWishlist)());
|
|
406
421
|
return [2];
|
|
407
422
|
}
|
|
@@ -409,18 +424,20 @@ var launch = function (launchConfig) {
|
|
|
409
424
|
}); };
|
|
410
425
|
};
|
|
411
426
|
exports.launch = launch;
|
|
412
|
-
var unloadPlayer = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
427
|
+
var unloadPlayer = function (playerEl) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
413
428
|
return __generator(this, function (_a) {
|
|
414
429
|
switch (_a.label) {
|
|
415
430
|
case 0:
|
|
416
431
|
dispatch((0, exports.setThreekitInitialized)(false));
|
|
417
432
|
dispatch((0, exports.setPlayerLoading)(true));
|
|
418
433
|
dispatch((0, attributes_1.setAttributes)([]));
|
|
419
|
-
dispatch((0, product_1.setName)(
|
|
434
|
+
dispatch((0, product_1.setName)());
|
|
420
435
|
dispatch((0, product_1.setMetadata)({}));
|
|
421
436
|
return [4, window.threekit.player.unload()];
|
|
422
437
|
case 1:
|
|
423
438
|
_a.sent();
|
|
439
|
+
if (playerEl)
|
|
440
|
+
playerEl.style.visibility = 'hidden';
|
|
424
441
|
return [2];
|
|
425
442
|
}
|
|
426
443
|
});
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export declare const downloadSnapshot: (snapshot: string, filename: string) => P
|
|
|
48
48
|
export declare const copyToClipboard: (data: string | Record<string, string | number | boolean>) => void;
|
|
49
49
|
export declare const easeInOutCubic: (val: number) => number;
|
|
50
50
|
export declare const metadataValueToObject: (data: string) => Record<string, string | number>;
|
|
51
|
+
export declare const recordOptionsShowAnalytics: (attributes: Record<string, IThreekitDisplayAttribute>) => void;
|
|
52
|
+
export declare const recordOptionInteractionAnalytics: (attribute: IThreekitDisplayAttribute, chosenAttribute: string, configuration?: IConfiguration) => void;
|
|
51
53
|
export declare const hydrateAttribute: (data: [Record<string, IThreekitDisplayAttribute>, ITranslationsMap], optionSelectionHandler: (config: ISetConfiguration) => Promise<void>, configuration?: IConfiguration) => Record<string, IHydratedAttribute>;
|
|
52
54
|
export declare const selectionToConfiguration: (value: RawAttributeValue, attributeType: ATTRIBUTE_TYPES) => string | number | boolean | File | IConfigurationColor | {
|
|
53
55
|
assetId: RawAttributeValue;
|
package/dist/utils.js
CHANGED
|
@@ -44,10 +44,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
44
|
}
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
47
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.loadTrebleConfig = exports.runDebugger = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.hydrateAttribute = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.downloadSnapshot = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.isJsonString = exports.isIOS = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
|
|
51
|
+
exports.loadTrebleConfig = exports.runDebugger = exports.isUuid = exports.filterFormAttributes = exports.selectionToConfiguration = exports.hydrateAttribute = exports.recordOptionInteractionAnalytics = exports.recordOptionsShowAnalytics = exports.metadataValueToObject = exports.easeInOutCubic = exports.copyToClipboard = exports.downloadSnapshot = exports.dataURItoFile = exports.dataURItoBlob = exports.setCameraPosition = exports.getCameraPosition = exports.findHitNode = exports.deflateRgb = exports.inflateRgb = exports.rgbToHex = exports.hexToRgb = exports.regularToKebabCase = exports.deepCompare = exports.shallowCompare = exports.getResumableUrl = exports.getParams = exports.objectToQueryStr = exports.isJsonString = exports.isIOS = exports.generateFormClassName = exports.generateDisplayClassName = exports.generateToolClassName = exports.generateLayoutClassName = exports.generateWidgetClassName = exports.generateInputClassName = exports.generateClassName = void 0;
|
|
49
52
|
var constants_1 = require("./constants");
|
|
50
53
|
var types_1 = require("./types");
|
|
54
|
+
var useAnalyticsSession_1 = __importDefault(require("./hooks/useAnalyticsSession"));
|
|
55
|
+
var rest_api_1 = require("@threekit/rest-api");
|
|
51
56
|
var generateClassName = function (baseClass) {
|
|
52
57
|
return function (component, customClassName, title) {
|
|
53
58
|
var result = "".concat(baseClass, "-").concat(component);
|
|
@@ -303,10 +308,65 @@ var metadataValueToObject = function (data) {
|
|
|
303
308
|
}, {});
|
|
304
309
|
};
|
|
305
310
|
exports.metadataValueToObject = metadataValueToObject;
|
|
311
|
+
var recordOptionsShowAnalytics = function (attributes) {
|
|
312
|
+
var analyticsSession = (0, useAnalyticsSession_1.default)();
|
|
313
|
+
Object.values(attributes).forEach(function (attribute) {
|
|
314
|
+
if ((attribute.type === 'String' || attribute.type === 'Asset') &&
|
|
315
|
+
attribute.values.length) {
|
|
316
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.optionsShow({
|
|
317
|
+
optionsSetId: attribute.id,
|
|
318
|
+
optionsSetName: attribute.name,
|
|
319
|
+
options: attribute.values,
|
|
320
|
+
optionsType: attribute.type === 'Asset' ? rest_api_1.OptionsType.Asset : rest_api_1.OptionsType.Value,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
exports.recordOptionsShowAnalytics = recordOptionsShowAnalytics;
|
|
326
|
+
var recordOptionInteractionAnalytics = function (attribute, chosenAttribute, configuration) {
|
|
327
|
+
var analyticsSession = (0, useAnalyticsSession_1.default)();
|
|
328
|
+
var castedConfiguration = configuration;
|
|
329
|
+
var id = attribute.type === 'Asset' ? attribute.value.assetId : attribute.id;
|
|
330
|
+
if (attribute.type === 'String') {
|
|
331
|
+
if (attribute.values.length > 0) {
|
|
332
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.optionInteraction({
|
|
333
|
+
optionsSetId: id,
|
|
334
|
+
optionId: chosenAttribute,
|
|
335
|
+
interactionType: rest_api_1.OptionInteractionType.Select,
|
|
336
|
+
configuration: castedConfiguration,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.personalizeText({
|
|
341
|
+
assetId: id,
|
|
342
|
+
configuration: castedConfiguration,
|
|
343
|
+
personalizeId: attribute.id,
|
|
344
|
+
personalizedText: attribute.value,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (attribute.type === 'Asset' || attribute.type === 'Color') {
|
|
349
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.optionInteraction({
|
|
350
|
+
optionsSetId: id,
|
|
351
|
+
optionId: chosenAttribute,
|
|
352
|
+
interactionType: rest_api_1.OptionInteractionType.Select,
|
|
353
|
+
configuration: castedConfiguration,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (attribute.type === 'Number') {
|
|
357
|
+
analyticsSession === null || analyticsSession === void 0 ? void 0 : analyticsSession.parametricValue({
|
|
358
|
+
parametricId: id,
|
|
359
|
+
parametricValue: attribute.value,
|
|
360
|
+
configuration: castedConfiguration,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
exports.recordOptionInteractionAnalytics = recordOptionInteractionAnalytics;
|
|
306
365
|
var hydrateAttribute = function (data, optionSelectionHandler, configuration) {
|
|
307
366
|
var _a, _b;
|
|
308
367
|
var attributes = data[0], translations = data[1];
|
|
309
368
|
var resolvedConfig = configuration !== null && configuration !== void 0 ? configuration : (_b = (_a = window.threekit) === null || _a === void 0 ? void 0 : _a.configurator) === null || _b === void 0 ? void 0 : _b.getResolvedConfiguration();
|
|
369
|
+
(0, exports.recordOptionsShowAnalytics)(attributes);
|
|
310
370
|
return Object.values(attributes).reduce(function (output, attribute) {
|
|
311
371
|
var _a;
|
|
312
372
|
var _b;
|
|
@@ -321,7 +381,8 @@ var hydrateAttribute = function (data, optionSelectionHandler, configuration) {
|
|
|
321
381
|
label: (_a = translations[el.label]) !== null && _a !== void 0 ? _a : el.label,
|
|
322
382
|
handleSelect: function () {
|
|
323
383
|
var _a;
|
|
324
|
-
|
|
384
|
+
(0, exports.recordOptionInteractionAnalytics)(attribute, attribute.value, configuration);
|
|
385
|
+
optionSelectionHandler((_a = {},
|
|
325
386
|
_a[attribute.name] = el.value,
|
|
326
387
|
_a));
|
|
327
388
|
},
|
|
@@ -337,7 +398,8 @@ var hydrateAttribute = function (data, optionSelectionHandler, configuration) {
|
|
|
337
398
|
label: (_a = translations[el.name]) !== null && _a !== void 0 ? _a : el.name,
|
|
338
399
|
handleSelect: function () {
|
|
339
400
|
var _a;
|
|
340
|
-
|
|
401
|
+
(0, exports.recordOptionInteractionAnalytics)(attribute, attribute.label, configuration);
|
|
402
|
+
optionSelectionHandler((_a = {},
|
|
341
403
|
_a[attribute.name] = { assetId: el.assetId },
|
|
342
404
|
_a));
|
|
343
405
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threekit-tools/treble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.97-beta-01",
|
|
4
4
|
"author": "Amaan Saeed",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -82,6 +82,8 @@
|
|
|
82
82
|
"typescript": ">=4.4.4"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
+
"@threekit/analytics": "0.2.13",
|
|
86
|
+
"@threekit/rest-api": ">=0.2.2",
|
|
85
87
|
"react": ">=17.0.2",
|
|
86
88
|
"react-dom": ">=17.0.2"
|
|
87
89
|
},
|