@threekit-tools/treble 0.0.47 → 0.0.51
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 +0 -26
- package/dist/Treble/Treble.d.ts +3 -1
- package/dist/Treble/Treble.js +14 -3
- package/dist/Treble/Wishlist.d.ts +3 -2
- package/dist/Treble/Wishlist.js +12 -12
- package/dist/components/Accordion/index.d.ts +1 -1
- package/dist/components/Player/index.js +5 -3
- package/dist/components/ThreekitProvider/index.d.ts +3 -1
- package/dist/components/ThreekitProvider/index.js +3 -3
- package/dist/components/containers/formInputContainer.d.ts +1 -1
- package/dist/hooks/useAttribute/index.js +3 -3
- package/dist/hooks/useConfigurator/index.js +3 -3
- package/dist/hooks/useMetadata/index.js +2 -2
- package/dist/hooks/useName/index.js +2 -2
- package/dist/hooks/usePlayerLoadingStatus/index.js +2 -2
- package/dist/hooks/usePlayerPortal/index.js +2 -3
- package/dist/hooks/usePrice/index.d.ts +1 -1
- package/dist/hooks/usePrice/index.js +2 -2
- package/dist/hooks/useShare/index.js +2 -2
- package/dist/hooks/useSnapshot/index.js +2 -2
- package/dist/hooks/useThreekitInitStatus/index.js +2 -2
- package/dist/hooks/useWishlist/index.d.ts +1 -1
- package/dist/hooks/useWishlist/index.js +8 -7
- package/dist/store/attributes.d.ts +20 -0
- package/dist/store/attributes.js +139 -0
- package/dist/store/index.d.ts +67 -7
- package/dist/store/index.js +36 -4
- package/dist/store/price.d.ts +33 -0
- package/dist/store/price.js +116 -0
- package/dist/store/product.d.ts +22 -0
- package/dist/store/product.js +65 -0
- package/dist/store/translations.d.ts +22 -0
- package/dist/store/translations.js +100 -0
- package/dist/store/treble.d.ts +41 -0
- package/dist/store/treble.js +257 -0
- package/dist/store/wishlist.d.ts +23 -0
- package/dist/store/wishlist.js +114 -0
- package/dist/threekit.d.ts +1 -1
- package/package.json +1 -1
- package/dist/store/threekit.d.ts +0 -68
- package/dist/store/threekit.js +0 -450
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
+
import { IProject, IPlayerConfig, IThreekitDisplayAttribute, ISetConfiguration } from '../threekit';
|
|
3
|
+
/*****************************************************
|
|
4
|
+
* Types and Interfaces
|
|
5
|
+
****************************************************/
|
|
6
|
+
export interface ILaunchConfig {
|
|
7
|
+
threekitEnv: string;
|
|
8
|
+
locale: string;
|
|
9
|
+
project: IProject;
|
|
10
|
+
playerConfig: IPlayerConfig;
|
|
11
|
+
eventHandlers: EventHandlers;
|
|
12
|
+
}
|
|
13
|
+
export interface TrebleState {
|
|
14
|
+
isPlayerLoading: boolean;
|
|
15
|
+
isThreekitInitialized: boolean;
|
|
16
|
+
playerElId: undefined | string;
|
|
17
|
+
}
|
|
18
|
+
interface EventHandlers {
|
|
19
|
+
postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/*****************************************************
|
|
22
|
+
* Actions
|
|
23
|
+
****************************************************/
|
|
24
|
+
export declare const setThreekitInitialized: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<undefined, string>;
|
|
25
|
+
export declare const setPlayerLoading: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
|
|
26
|
+
export declare const setPlayerElement: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
27
|
+
/*****************************************************
|
|
28
|
+
* Slice
|
|
29
|
+
****************************************************/
|
|
30
|
+
declare const reducer: import("redux").Reducer<TrebleState, import("redux").AnyAction>;
|
|
31
|
+
/*****************************************************
|
|
32
|
+
* Standard Selectors
|
|
33
|
+
****************************************************/
|
|
34
|
+
export declare const isThreekitInitialized: (state: RootState) => boolean;
|
|
35
|
+
export declare const isPlayerLoading: (state: RootState) => boolean;
|
|
36
|
+
export declare const getPlayerElementId: (state: RootState) => undefined | string;
|
|
37
|
+
/*****************************************************
|
|
38
|
+
* Complex Actions
|
|
39
|
+
****************************************************/
|
|
40
|
+
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
41
|
+
export default reducer;
|
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.launch = exports.getPlayerElementId = exports.isPlayerLoading = exports.isThreekitInitialized = exports.setPlayerElement = exports.setPlayerLoading = exports.setThreekitInitialized = void 0;
|
|
54
|
+
var connection_1 = __importDefault(require("../connection"));
|
|
55
|
+
var toolkit_1 = require("@reduxjs/toolkit");
|
|
56
|
+
var api_1 = __importDefault(require("../api"));
|
|
57
|
+
var utils_1 = require("../utils");
|
|
58
|
+
var constants_1 = require("../constants");
|
|
59
|
+
var Treble_1 = __importDefault(require("../Treble"));
|
|
60
|
+
var attributes_1 = require("./attributes");
|
|
61
|
+
var price_1 = require("./price");
|
|
62
|
+
var wishlist_1 = require("./wishlist");
|
|
63
|
+
var translations_1 = require("./translations");
|
|
64
|
+
var product_1 = require("./product");
|
|
65
|
+
/*****************************************************
|
|
66
|
+
* Helper Functions
|
|
67
|
+
****************************************************/
|
|
68
|
+
var createPlayerLoaderEl = function (elementId) {
|
|
69
|
+
/**
|
|
70
|
+
* By default the player is loaded into a player-loader div that
|
|
71
|
+
* is placed outside the user's view. This is done because in
|
|
72
|
+
* React the Threekit Initialization may happen before the
|
|
73
|
+
* component with the player HTML element has loaded which would
|
|
74
|
+
* otherwise throw an error.
|
|
75
|
+
*/
|
|
76
|
+
var playerElement = document.getElementById(elementId);
|
|
77
|
+
if (playerElement)
|
|
78
|
+
return playerElement;
|
|
79
|
+
playerElement = document.createElement('div');
|
|
80
|
+
playerElement.setAttribute('id', elementId);
|
|
81
|
+
playerElement.style.height = '100%';
|
|
82
|
+
var playerLoader = document.createElement('div');
|
|
83
|
+
playerLoader.setAttribute('id', constants_1.TK_PLAYER_LOADER_DIV);
|
|
84
|
+
playerLoader.appendChild(playerElement);
|
|
85
|
+
playerLoader.style.opacity = '0';
|
|
86
|
+
playerLoader.style.height = '1px';
|
|
87
|
+
playerLoader.style.position = 'fixed';
|
|
88
|
+
playerLoader.style.top = '-100%';
|
|
89
|
+
document.body.appendChild(playerLoader);
|
|
90
|
+
return playerElement;
|
|
91
|
+
};
|
|
92
|
+
/*****************************************************
|
|
93
|
+
* Constants and Event Handlers
|
|
94
|
+
****************************************************/
|
|
95
|
+
var EVENTS = {};
|
|
96
|
+
/*****************************************************
|
|
97
|
+
* State
|
|
98
|
+
****************************************************/
|
|
99
|
+
var initialState = {
|
|
100
|
+
isThreekitInitialized: false,
|
|
101
|
+
isPlayerLoading: false,
|
|
102
|
+
playerElId: undefined,
|
|
103
|
+
};
|
|
104
|
+
/*****************************************************
|
|
105
|
+
* Actions
|
|
106
|
+
****************************************************/
|
|
107
|
+
exports.setThreekitInitialized = (0, toolkit_1.createAction)('treble/set-threekit-initialized');
|
|
108
|
+
exports.setPlayerLoading = (0, toolkit_1.createAction)('treble/set-player-loading');
|
|
109
|
+
exports.setPlayerElement = (0, toolkit_1.createAction)('treble/set-player-element');
|
|
110
|
+
/*****************************************************
|
|
111
|
+
* Slice
|
|
112
|
+
****************************************************/
|
|
113
|
+
var reducer = (0, toolkit_1.createSlice)({
|
|
114
|
+
name: 'treble',
|
|
115
|
+
initialState: initialState,
|
|
116
|
+
reducers: {},
|
|
117
|
+
extraReducers: function (builder) {
|
|
118
|
+
builder.addCase(exports.setThreekitInitialized, function (state, _) {
|
|
119
|
+
state.isThreekitInitialized = true;
|
|
120
|
+
});
|
|
121
|
+
builder.addCase(exports.setPlayerLoading, function (state, action) {
|
|
122
|
+
state.isPlayerLoading = action.payload;
|
|
123
|
+
});
|
|
124
|
+
builder.addCase(exports.setPlayerElement, function (state, action) {
|
|
125
|
+
state.playerElId = action.payload;
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
}).reducer;
|
|
129
|
+
/*****************************************************
|
|
130
|
+
* Standard Selectors
|
|
131
|
+
****************************************************/
|
|
132
|
+
// Loading Trackers
|
|
133
|
+
var isThreekitInitialized = function (state) {
|
|
134
|
+
return state.treble.isThreekitInitialized;
|
|
135
|
+
};
|
|
136
|
+
exports.isThreekitInitialized = isThreekitInitialized;
|
|
137
|
+
var isPlayerLoading = function (state) {
|
|
138
|
+
return state.treble.isPlayerLoading;
|
|
139
|
+
};
|
|
140
|
+
exports.isPlayerLoading = isPlayerLoading;
|
|
141
|
+
// Player's HTML element
|
|
142
|
+
var getPlayerElementId = function (state) {
|
|
143
|
+
return state.treble.playerElId;
|
|
144
|
+
};
|
|
145
|
+
exports.getPlayerElementId = getPlayerElementId;
|
|
146
|
+
/*****************************************************
|
|
147
|
+
* Complex Actions
|
|
148
|
+
****************************************************/
|
|
149
|
+
var launch = function (launchConfig) {
|
|
150
|
+
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var config, credentials, products, threekitEnv, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration, player, _a;
|
|
152
|
+
var _b;
|
|
153
|
+
var _c, _d, _e, _f, _g;
|
|
154
|
+
return __generator(this, function (_h) {
|
|
155
|
+
switch (_h.label) {
|
|
156
|
+
case 0:
|
|
157
|
+
if (window.threekit)
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
config = (0, utils_1.loadTrebleConfig)();
|
|
160
|
+
credentials = Object.assign({}, ((_c = config.project) === null || _c === void 0 ? void 0 : _c.credentials) || {}, ((_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _d === void 0 ? void 0 : _d.credentials) || {});
|
|
161
|
+
products = Object.assign({}, ((_e = config.project) === null || _e === void 0 ? void 0 : _e.products) || {}, ((_f = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _f === void 0 ? void 0 : _f.products) || {});
|
|
162
|
+
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
163
|
+
return [2 /*return*/, console.error('Missing credentials')];
|
|
164
|
+
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
165
|
+
playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, config.player, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.playerConfig);
|
|
166
|
+
envCredentials = credentials[threekitEnv];
|
|
167
|
+
product = products[threekitEnv];
|
|
168
|
+
threekitDomainRaw = envCredentials.threekitDomain || "".concat(threekitEnv, ".threekit.com");
|
|
169
|
+
orgId = envCredentials.orgId, authToken = envCredentials.publicToken;
|
|
170
|
+
if (typeof product === 'string') {
|
|
171
|
+
if ((0, utils_1.isUuid)(product))
|
|
172
|
+
assetId = product;
|
|
173
|
+
else
|
|
174
|
+
configurationId = product;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
stageId = product.stageId;
|
|
178
|
+
if (product.configurationId)
|
|
179
|
+
configurationId = product.configurationId;
|
|
180
|
+
else if ((0, utils_1.isUuid)(product.assetId))
|
|
181
|
+
assetId = product.assetId;
|
|
182
|
+
else
|
|
183
|
+
configurationId = product.assetId;
|
|
184
|
+
}
|
|
185
|
+
if (playerConfig.elementId) {
|
|
186
|
+
el = document.getElementById(playerConfig.elementId);
|
|
187
|
+
if (el)
|
|
188
|
+
dispatch((0, exports.setPlayerElement)(playerConfig.elementId));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
el = createPlayerLoaderEl(constants_1.TK_PLAYER_ROOT_DIV);
|
|
192
|
+
dispatch((0, exports.setPlayerElement)(constants_1.TK_PLAYER_ROOT_DIV));
|
|
193
|
+
}
|
|
194
|
+
// Connection
|
|
195
|
+
connection_1.default.connect({
|
|
196
|
+
authToken: authToken,
|
|
197
|
+
orgId: orgId,
|
|
198
|
+
assetId: assetId,
|
|
199
|
+
threekitDomain: threekitDomainRaw,
|
|
200
|
+
});
|
|
201
|
+
threekitDomain = connection_1.default.getConnection().threekitDomain;
|
|
202
|
+
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
203
|
+
updatedAssetId = assetId;
|
|
204
|
+
params = (0, utils_1.getParams)();
|
|
205
|
+
configId = ((_g = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _g === void 0 ? void 0 : _g.length)
|
|
206
|
+
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
207
|
+
: configurationId;
|
|
208
|
+
if (!configId) return [3 /*break*/, 2];
|
|
209
|
+
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
210
|
+
case 1:
|
|
211
|
+
configuration = _h.sent();
|
|
212
|
+
if (configuration) {
|
|
213
|
+
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
214
|
+
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
215
|
+
updatedAssetId = configuration.data.productId;
|
|
216
|
+
}
|
|
217
|
+
_h.label = 2;
|
|
218
|
+
case 2:
|
|
219
|
+
if (!updatedAssetId)
|
|
220
|
+
return [2 /*return*/, console.error('missing assetId')];
|
|
221
|
+
// We create the threekit script
|
|
222
|
+
return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
|
|
223
|
+
case 3:
|
|
224
|
+
// We create the threekit script
|
|
225
|
+
_h.sent();
|
|
226
|
+
return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
|
|
227
|
+
// Variables to sort out
|
|
228
|
+
authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
|
|
229
|
+
case 4:
|
|
230
|
+
player = _h.sent();
|
|
231
|
+
_a = window;
|
|
232
|
+
_b = {
|
|
233
|
+
player: player
|
|
234
|
+
};
|
|
235
|
+
return [4 /*yield*/, player.getConfigurator()];
|
|
236
|
+
case 5:
|
|
237
|
+
_a.threekit = (_b.configurator = _h.sent(),
|
|
238
|
+
_b.treble = new Treble_1.default({ player: player, orgId: orgId }),
|
|
239
|
+
_b);
|
|
240
|
+
dispatch((0, exports.setThreekitInitialized)());
|
|
241
|
+
dispatch((0, exports.setPlayerLoading)(false));
|
|
242
|
+
window.threekit.player.on('setConfiguration', function () {
|
|
243
|
+
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
244
|
+
dispatch((0, price_1.updatePrice)());
|
|
245
|
+
});
|
|
246
|
+
EVENTS = Object.assign(EVENTS, launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers);
|
|
247
|
+
dispatch((0, translations_1.initTranslations)(launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.locale));
|
|
248
|
+
dispatch((0, price_1.initPrice)());
|
|
249
|
+
dispatch((0, product_1.initProduct)());
|
|
250
|
+
dispatch((0, wishlist_1.refreshWishlist)());
|
|
251
|
+
return [2 /*return*/];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}); };
|
|
255
|
+
};
|
|
256
|
+
exports.launch = launch;
|
|
257
|
+
exports.default = reducer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
+
import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
|
|
3
|
+
/*****************************************************
|
|
4
|
+
* Types and Interfaces
|
|
5
|
+
****************************************************/
|
|
6
|
+
export declare type WishlistState = WishlistArray;
|
|
7
|
+
/*****************************************************
|
|
8
|
+
* Standard Selectors
|
|
9
|
+
****************************************************/
|
|
10
|
+
export declare const refreshWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], void, {}>;
|
|
11
|
+
export declare const addToWishlist: import("@reduxjs/toolkit").AsyncThunk<import("../http/configurations").IConfigurationResponse[], ISaveConfigurationConfig, {}>;
|
|
12
|
+
export declare const clearWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/clear", never, never>;
|
|
13
|
+
export declare const removeFromWishlist: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[idx: number], import("../http/configurations").IConfigurationResponse[], "treble/wishlist/remove-item", never, never>;
|
|
14
|
+
/*****************************************************
|
|
15
|
+
* Slice
|
|
16
|
+
****************************************************/
|
|
17
|
+
declare const reducer: import("redux").Reducer<WishlistArray, import("redux").AnyAction>;
|
|
18
|
+
/*****************************************************
|
|
19
|
+
* Standard Selectors
|
|
20
|
+
****************************************************/
|
|
21
|
+
export declare const getWishlist: (state: RootState) => WishlistArray;
|
|
22
|
+
export declare const resumeFromWishlist: (idx: number) => (_: ThreekitDispatch, getState: () => RootState) => void;
|
|
23
|
+
export default reducer;
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
exports.resumeFromWishlist = exports.getWishlist = exports.removeFromWishlist = exports.clearWishlist = exports.addToWishlist = exports.refreshWishlist = void 0;
|
|
40
|
+
var toolkit_1 = require("@reduxjs/toolkit");
|
|
41
|
+
/*****************************************************
|
|
42
|
+
* State
|
|
43
|
+
****************************************************/
|
|
44
|
+
var initialState = [];
|
|
45
|
+
/*****************************************************
|
|
46
|
+
* Standard Selectors
|
|
47
|
+
****************************************************/
|
|
48
|
+
exports.refreshWishlist = (0, toolkit_1.createAsyncThunk)('treble/wishlist/refresh-data', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var wishlistData;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
|
|
53
|
+
case 1:
|
|
54
|
+
wishlistData = _a.sent();
|
|
55
|
+
return [2 /*return*/, wishlistData];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); });
|
|
59
|
+
exports.addToWishlist = (0, toolkit_1.createAsyncThunk)('treble/wishlist/add-item', function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var wishlistData;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
|
|
64
|
+
case 1:
|
|
65
|
+
wishlistData = _a.sent();
|
|
66
|
+
return [2 /*return*/, wishlistData];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}); });
|
|
70
|
+
exports.clearWishlist = (0, toolkit_1.createAction)('treble/wishlist/clear', function () {
|
|
71
|
+
var wishlistData = window.threekit.treble.wishlist.clearWishlist();
|
|
72
|
+
return { payload: wishlistData };
|
|
73
|
+
});
|
|
74
|
+
exports.removeFromWishlist = (0, toolkit_1.createAction)('treble/wishlist/remove-item', function (idx) {
|
|
75
|
+
var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
|
|
76
|
+
return { payload: wishlistData };
|
|
77
|
+
});
|
|
78
|
+
/*****************************************************
|
|
79
|
+
* Slice
|
|
80
|
+
****************************************************/
|
|
81
|
+
var reducer = (0, toolkit_1.createSlice)({
|
|
82
|
+
name: 'wishlist',
|
|
83
|
+
initialState: initialState,
|
|
84
|
+
reducers: {},
|
|
85
|
+
extraReducers: function (builder) {
|
|
86
|
+
builder.addCase(exports.refreshWishlist.fulfilled, function (_, action) {
|
|
87
|
+
return action.payload;
|
|
88
|
+
});
|
|
89
|
+
builder.addCase(exports.addToWishlist.fulfilled, function (_, action) {
|
|
90
|
+
return action.payload;
|
|
91
|
+
});
|
|
92
|
+
builder.addCase(exports.removeFromWishlist, function (_, action) {
|
|
93
|
+
return action.payload;
|
|
94
|
+
});
|
|
95
|
+
builder.addCase(exports.clearWishlist, function (_, action) {
|
|
96
|
+
return action.payload;
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
}).reducer;
|
|
100
|
+
/*****************************************************
|
|
101
|
+
* Standard Selectors
|
|
102
|
+
****************************************************/
|
|
103
|
+
// Wishlist
|
|
104
|
+
var getWishlist = function (state) { return state.wishlist; };
|
|
105
|
+
exports.getWishlist = getWishlist;
|
|
106
|
+
var resumeFromWishlist = function (idx) { return function (_, getState) {
|
|
107
|
+
var wishlist = getState().wishlist;
|
|
108
|
+
var savedConfiguration = wishlist[idx];
|
|
109
|
+
if (!savedConfiguration)
|
|
110
|
+
return;
|
|
111
|
+
window.threekit.configurator.setConfiguration(savedConfiguration.variant);
|
|
112
|
+
}; };
|
|
113
|
+
exports.resumeFromWishlist = resumeFromWishlist;
|
|
114
|
+
exports.default = reducer;
|
package/dist/threekit.d.ts
CHANGED
|
@@ -187,7 +187,7 @@ export interface IThreekitPlayer {
|
|
|
187
187
|
tools: IThreekitTools;
|
|
188
188
|
camera: IThreekitCamera;
|
|
189
189
|
setActiveCamera: () => void;
|
|
190
|
-
on: (phase: SCENE_PHASES) => void;
|
|
190
|
+
on: (phase: SCENE_PHASES | string, callback: (args: any) => void) => void;
|
|
191
191
|
getConfigurator: () => Promise<IThreekitConfigurator>;
|
|
192
192
|
enableApi: (api: PRIVATE_APIS) => any;
|
|
193
193
|
snapshotAsync: (snapshotConfig: ISnapshotConfig) => Promise<string>;
|
package/package.json
CHANGED
package/dist/store/threekit.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { RootState, ThreekitDispatch } from './index';
|
|
2
|
-
import { ISetConfiguration, IThreekitDisplayAttribute, IMetadata, IProject, IPlayerConfig } from '../threekit';
|
|
3
|
-
import { ITranslationMap } from '../api/products';
|
|
4
|
-
import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
|
|
5
|
-
/*****************************************************
|
|
6
|
-
* Types and Interfaces
|
|
7
|
-
****************************************************/
|
|
8
|
-
interface EventHandlers {
|
|
9
|
-
postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export interface ILaunchConfig {
|
|
12
|
-
threekitEnv: string;
|
|
13
|
-
locale: string;
|
|
14
|
-
project: IProject;
|
|
15
|
-
playerConfig: IPlayerConfig;
|
|
16
|
-
eventHandlers: EventHandlers;
|
|
17
|
-
}
|
|
18
|
-
interface IPriceConfig {
|
|
19
|
-
id: string;
|
|
20
|
-
currency: string;
|
|
21
|
-
}
|
|
22
|
-
export interface IPrice {
|
|
23
|
-
price: number;
|
|
24
|
-
currency: string;
|
|
25
|
-
}
|
|
26
|
-
/*****************************************************
|
|
27
|
-
* State
|
|
28
|
-
****************************************************/
|
|
29
|
-
export interface ThreekitState {
|
|
30
|
-
playerElId: undefined | string;
|
|
31
|
-
name: undefined | string;
|
|
32
|
-
metadata: undefined | IMetadata;
|
|
33
|
-
translations: undefined | ITranslationMap;
|
|
34
|
-
language: string | undefined;
|
|
35
|
-
priceConfig: IPriceConfig | null;
|
|
36
|
-
isPlayerLoading: boolean;
|
|
37
|
-
isThreekitLoaded: boolean;
|
|
38
|
-
attributes: undefined | Array<IThreekitDisplayAttribute>;
|
|
39
|
-
wishlist: WishlistArray;
|
|
40
|
-
}
|
|
41
|
-
declare const reducer: import("redux").Reducer<ThreekitState, import("redux").AnyAction>;
|
|
42
|
-
export declare const setThreekitLoaded: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
43
|
-
/*****************************************************
|
|
44
|
-
* Standard Selectors
|
|
45
|
-
****************************************************/
|
|
46
|
-
export declare const isThreekitLoaded: (state: RootState) => boolean;
|
|
47
|
-
export declare const isPlayerLoading: (state: RootState) => boolean;
|
|
48
|
-
export declare const getPlayerElementId: (state: RootState) => undefined | string;
|
|
49
|
-
export declare const getName: (state: RootState) => undefined | string;
|
|
50
|
-
export declare const getPrice: (state: RootState) => undefined | IPrice;
|
|
51
|
-
export declare const getMetadata: (state: RootState) => undefined | IMetadata;
|
|
52
|
-
export declare const getLanguage: (state: RootState) => undefined | string;
|
|
53
|
-
export declare const getLanguageOptions: (state: RootState) => Array<string>;
|
|
54
|
-
export declare const getAttributes: (state: RootState) => undefined | Record<string, IThreekitDisplayAttribute>;
|
|
55
|
-
export declare const getWishlist: (state: RootState) => WishlistArray;
|
|
56
|
-
/*****************************************************
|
|
57
|
-
* Complex Selectors
|
|
58
|
-
****************************************************/
|
|
59
|
-
/*****************************************************
|
|
60
|
-
* Complex Actions
|
|
61
|
-
****************************************************/
|
|
62
|
-
export declare const launch: (launchConfig?: Partial<ILaunchConfig> | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
63
|
-
export declare const setConfiguration: (config: ISetConfiguration) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
64
|
-
export declare const addToWishlist: (config: ISaveConfigurationConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
65
|
-
export declare const removeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch) => void;
|
|
66
|
-
export declare const resumeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
|
|
67
|
-
export declare const clearWishlist: () => (dispatch: ThreekitDispatch) => void;
|
|
68
|
-
export default reducer;
|