@threekit-tools/treble 0.0.50 → 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/Treble.d.ts +1 -0
- package/dist/Treble/Treble.js +12 -1
- package/dist/hooks/useWishlist/index.d.ts +1 -1
- package/dist/store/attributes.d.ts +1 -1
- package/dist/store/attributes.js +13 -9
- package/dist/store/price.d.ts +1 -0
- package/dist/store/price.js +64 -4
- package/dist/store/product.d.ts +2 -1
- package/dist/store/product.js +25 -6
- package/dist/store/translations.d.ts +2 -1
- package/dist/store/translations.js +58 -4
- package/dist/store/treble.js +31 -53
- package/dist/store/wishlist.d.ts +5 -6
- package/dist/store/wishlist.js +44 -31
- package/package.json +1 -1
package/dist/Treble/Treble.d.ts
CHANGED
package/dist/Treble/Treble.js
CHANGED
|
@@ -83,13 +83,24 @@ var Treble = /** @class */ (function () {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
}); };
|
|
86
|
+
this.getNestedConfigurator = function (address) {
|
|
87
|
+
var player = window.threekit.player.enableApi('player');
|
|
88
|
+
var addressArr = Array.isArray(address) ? address : [address];
|
|
89
|
+
return addressArr.reduce(function (configurator, attributeName) {
|
|
90
|
+
var itemId = configurator.getAppliedConfiguration(attributeName);
|
|
91
|
+
return window.threekit.player.scene.get({
|
|
92
|
+
id: itemId,
|
|
93
|
+
evalNode: true,
|
|
94
|
+
}).configurator;
|
|
95
|
+
}, player.getConfigurator());
|
|
96
|
+
};
|
|
86
97
|
// Threekit API
|
|
87
98
|
this._api = api_1.default;
|
|
88
99
|
this._player = player;
|
|
89
100
|
this.wishlist = (0, Wishlist_1.default)(orgId);
|
|
90
101
|
this._snapshots = new Snapshots_1.default();
|
|
91
102
|
this.takeSnapshots = this._snapshots.takeSnapshots;
|
|
92
|
-
// this._player = player.enableApi('player')
|
|
103
|
+
// this._player = player.enableApi('player');
|
|
93
104
|
}
|
|
94
105
|
return Treble;
|
|
95
106
|
}());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISaveConfigurationConfig, WishlistArray } from '../../Treble';
|
|
2
2
|
declare type UseWishlistHook = [
|
|
3
3
|
WishlistArray,
|
|
4
|
-
(config?: ISaveConfigurationConfig) =>
|
|
4
|
+
(config?: ISaveConfigurationConfig) => void,
|
|
5
5
|
(idx: number) => void,
|
|
6
6
|
(idx: number) => void,
|
|
7
7
|
(idx: number) => void,
|
|
@@ -7,7 +7,7 @@ export declare type AttributesState = Record<string, IThreekitDisplayAttribute>;
|
|
|
7
7
|
/*****************************************************
|
|
8
8
|
* Actions
|
|
9
9
|
****************************************************/
|
|
10
|
-
export declare const setAttributes: import("@reduxjs/toolkit").
|
|
10
|
+
export declare const setAttributes: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[attributes: IThreekitDisplayAttribute[]], Record<string, IThreekitDisplayAttribute>, "treble/attributes/set-attributes", never, never>;
|
|
11
11
|
/*****************************************************
|
|
12
12
|
* Slice
|
|
13
13
|
****************************************************/
|
package/dist/store/attributes.js
CHANGED
|
@@ -39,13 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.setConfiguration = exports.getAttributes = exports.setAttributes = void 0;
|
|
40
40
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
41
41
|
var treble_1 = require("./treble");
|
|
42
|
-
// export interface AttributesState {
|
|
43
|
-
// attributes: Record<string, IThreekitDisplayAttribute>;
|
|
44
|
-
// }
|
|
45
42
|
/*****************************************************
|
|
46
43
|
* Actions
|
|
47
44
|
****************************************************/
|
|
48
|
-
exports.setAttributes = (0, toolkit_1.createAction)('
|
|
45
|
+
exports.setAttributes = (0, toolkit_1.createAction)('treble/attributes/set-attributes', function (attributes) {
|
|
46
|
+
var payload = attributes.reduce(function (output, attr) {
|
|
47
|
+
var _a;
|
|
48
|
+
return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
|
|
49
|
+
}, {});
|
|
50
|
+
return { payload: payload };
|
|
51
|
+
});
|
|
49
52
|
/*****************************************************
|
|
50
53
|
* State and Data
|
|
51
54
|
****************************************************/
|
|
@@ -58,12 +61,15 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
58
61
|
initialState: initialState,
|
|
59
62
|
reducers: {},
|
|
60
63
|
extraReducers: function (builder) {
|
|
61
|
-
builder.addCase(
|
|
62
|
-
|
|
64
|
+
builder.addCase(treble_1.setThreekitInitialized, function () {
|
|
65
|
+
var attributes = window.threekit.configurator.getDisplayAttributes();
|
|
66
|
+
return attributes.reduce(function (output, attr) {
|
|
63
67
|
var _a;
|
|
64
68
|
return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
|
|
65
69
|
}, {});
|
|
66
|
-
|
|
70
|
+
});
|
|
71
|
+
builder.addCase(exports.setAttributes, function (_, action) {
|
|
72
|
+
return action.payload;
|
|
67
73
|
});
|
|
68
74
|
},
|
|
69
75
|
}).reducer;
|
|
@@ -72,8 +78,6 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
72
78
|
****************************************************/
|
|
73
79
|
// Attributes
|
|
74
80
|
var getAttributes = function (state) {
|
|
75
|
-
// const { isThreekitLoaded, attributes, language, translations } =
|
|
76
|
-
// state.threekit;
|
|
77
81
|
var attributes = state.attributes;
|
|
78
82
|
var isThreekitInitialized = state.treble.isThreekitInitialized;
|
|
79
83
|
var _a = state.translations, language = _a.language, translations = _a.translations;
|
package/dist/store/price.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface IPrice {
|
|
|
20
20
|
****************************************************/
|
|
21
21
|
export declare const setPriceConfig: import("@reduxjs/toolkit").ActionCreatorWithPayload<IPriceConfig, string>;
|
|
22
22
|
export declare const setPrice: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, string>;
|
|
23
|
+
export declare const initPrice: () => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
23
24
|
declare const reducer: import("redux").Reducer<PriceState, import("redux").AnyAction>;
|
|
24
25
|
/*****************************************************
|
|
25
26
|
* Standard Selectors
|
package/dist/store/price.js
CHANGED
|
@@ -1,13 +1,72 @@
|
|
|
1
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
2
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updatePrice = exports.getPrice = exports.setPrice = exports.setPriceConfig = void 0;
|
|
42
|
+
exports.updatePrice = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
|
|
4
43
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
44
|
+
var api_1 = __importDefault(require("../api"));
|
|
5
45
|
/*****************************************************
|
|
6
46
|
* Actions
|
|
7
47
|
****************************************************/
|
|
8
48
|
// Actions to be used only internally
|
|
9
|
-
exports.setPriceConfig = (0, toolkit_1.createAction)('
|
|
10
|
-
exports.setPrice = (0, toolkit_1.createAction)('
|
|
49
|
+
exports.setPriceConfig = (0, toolkit_1.createAction)('treble/price/set-price-config');
|
|
50
|
+
exports.setPrice = (0, toolkit_1.createAction)('treble/price/set-price');
|
|
51
|
+
var initPrice = function () { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
var pricebook, id, currency, price;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, api_1.default.price.getPricebooksList()];
|
|
56
|
+
case 1:
|
|
57
|
+
pricebook = _a.sent();
|
|
58
|
+
id = pricebook[0].id;
|
|
59
|
+
currency = pricebook[0].currencies[0];
|
|
60
|
+
if (pricebook.length) {
|
|
61
|
+
dispatch((0, exports.setPriceConfig)({ id: id, currency: currency }));
|
|
62
|
+
price = window.threekit.configurator.getPrice(id, currency);
|
|
63
|
+
dispatch((0, exports.setPrice)(price));
|
|
64
|
+
}
|
|
65
|
+
return [2 /*return*/];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}); }; };
|
|
69
|
+
exports.initPrice = initPrice;
|
|
11
70
|
/*****************************************************
|
|
12
71
|
* State
|
|
13
72
|
****************************************************/
|
|
@@ -25,10 +84,11 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
25
84
|
var _a = action.payload, id = _a.id, currency = _a.currency;
|
|
26
85
|
state.id = id;
|
|
27
86
|
state.currency = currency;
|
|
28
|
-
state
|
|
87
|
+
return state;
|
|
29
88
|
});
|
|
30
89
|
builder.addCase(exports.setPrice, function (state, action) {
|
|
31
90
|
state.price = action.payload;
|
|
91
|
+
return state;
|
|
32
92
|
});
|
|
33
93
|
},
|
|
34
94
|
reducers: {},
|
package/dist/store/product.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RootState } from './index';
|
|
1
|
+
import { RootState, ThreekitDispatch } from './index';
|
|
2
2
|
import { IMetadata } from '../threekit';
|
|
3
3
|
/*****************************************************
|
|
4
4
|
* Types and Interfaces
|
|
@@ -12,6 +12,7 @@ export interface ProductState {
|
|
|
12
12
|
****************************************************/
|
|
13
13
|
export declare const setName: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
14
14
|
export declare const setMetadata: import("@reduxjs/toolkit").ActionCreatorWithPayload<IMetadata, string>;
|
|
15
|
+
export declare const initProduct: () => (dispatch: ThreekitDispatch) => void;
|
|
15
16
|
declare const reducer: import("redux").Reducer<ProductState, import("redux").AnyAction>;
|
|
16
17
|
/*****************************************************
|
|
17
18
|
* Standard Selectors
|
package/dist/store/product.js
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMetadata = exports.getName = exports.setMetadata = exports.setName = void 0;
|
|
14
|
+
exports.getMetadata = exports.getName = exports.initProduct = exports.setMetadata = exports.setName = void 0;
|
|
4
15
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
5
16
|
/*****************************************************
|
|
6
17
|
* Actions
|
|
7
18
|
****************************************************/
|
|
8
19
|
// Actions to be used only internally
|
|
9
|
-
exports.setName = (0, toolkit_1.createAction)('
|
|
10
|
-
exports.setMetadata = (0, toolkit_1.createAction)('
|
|
20
|
+
exports.setName = (0, toolkit_1.createAction)('treble/product/set-name');
|
|
21
|
+
exports.setMetadata = (0, toolkit_1.createAction)('treble/product/set-metadata');
|
|
22
|
+
var initProduct = function () { return function (dispatch) {
|
|
23
|
+
var name = window.threekit.player.scene.get({
|
|
24
|
+
id: window.threekit.player.assetId,
|
|
25
|
+
}).name;
|
|
26
|
+
var metadata = window.threekit.configurator.getMetadata();
|
|
27
|
+
dispatch((0, exports.setName)(name));
|
|
28
|
+
dispatch((0, exports.setMetadata)(metadata));
|
|
29
|
+
}; };
|
|
30
|
+
exports.initProduct = initProduct;
|
|
11
31
|
/*****************************************************
|
|
12
32
|
* State
|
|
13
33
|
****************************************************/
|
|
@@ -21,12 +41,11 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
21
41
|
name: 'product',
|
|
22
42
|
initialState: initialState,
|
|
23
43
|
extraReducers: function (builder) {
|
|
24
|
-
// Language
|
|
25
44
|
builder.addCase(exports.setName, function (state, action) {
|
|
26
|
-
state
|
|
45
|
+
return __assign(__assign({}, state), { name: action.payload });
|
|
27
46
|
});
|
|
28
47
|
builder.addCase(exports.setMetadata, function (state, action) {
|
|
29
|
-
state
|
|
48
|
+
return __assign(__assign({}, state), { metadata: action.payload });
|
|
30
49
|
});
|
|
31
50
|
},
|
|
32
51
|
reducers: {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RootState } from './index';
|
|
1
|
+
import { RootState, ThreekitDispatch } from './index';
|
|
2
2
|
import { ITranslationMap } from '../api/products';
|
|
3
3
|
/*****************************************************
|
|
4
4
|
* Types and Interfaces
|
|
@@ -12,6 +12,7 @@ export interface TranslationsState {
|
|
|
12
12
|
****************************************************/
|
|
13
13
|
export declare const setTranslations: import("@reduxjs/toolkit").ActionCreatorWithPayload<ITranslationMap, string>;
|
|
14
14
|
export declare const setLanguage: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
|
|
15
|
+
export declare const initTranslations: (language?: string | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
|
|
15
16
|
declare const reducer: import("redux").Reducer<TranslationsState, import("redux").AnyAction>;
|
|
16
17
|
/*****************************************************
|
|
17
18
|
* Standard Selectors
|
|
@@ -1,13 +1,68 @@
|
|
|
1
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
2
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLanguageOptions = exports.getLanguage = exports.setLanguage = exports.setTranslations = void 0;
|
|
42
|
+
exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
|
|
4
43
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
44
|
+
var api_1 = __importDefault(require("../api"));
|
|
5
45
|
/*****************************************************
|
|
6
46
|
* Actions
|
|
7
47
|
****************************************************/
|
|
8
48
|
// Actions to be used only internally
|
|
9
|
-
exports.setTranslations = (0, toolkit_1.createAction)('
|
|
10
|
-
exports.setLanguage = (0, toolkit_1.createAction)('
|
|
49
|
+
exports.setTranslations = (0, toolkit_1.createAction)('treble/translations/set-translations');
|
|
50
|
+
exports.setLanguage = (0, toolkit_1.createAction)('treble/translations/set-language');
|
|
51
|
+
var initTranslations = function (language) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
var translations;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, api_1.default.products.fetchTranslations()];
|
|
56
|
+
case 1:
|
|
57
|
+
translations = _a.sent();
|
|
58
|
+
dispatch((0, exports.setTranslations)(translations));
|
|
59
|
+
if (language)
|
|
60
|
+
dispatch((0, exports.setLanguage)(language));
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); }; };
|
|
65
|
+
exports.initTranslations = initTranslations;
|
|
11
66
|
/*****************************************************
|
|
12
67
|
* State
|
|
13
68
|
****************************************************/
|
|
@@ -20,7 +75,6 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
20
75
|
name: 'translations',
|
|
21
76
|
initialState: initialState,
|
|
22
77
|
extraReducers: function (builder) {
|
|
23
|
-
// Language
|
|
24
78
|
builder.addCase(exports.setTranslations, function (state, action) {
|
|
25
79
|
state.translations = action.payload;
|
|
26
80
|
});
|
package/dist/store/treble.js
CHANGED
|
@@ -57,10 +57,10 @@ var api_1 = __importDefault(require("../api"));
|
|
|
57
57
|
var utils_1 = require("../utils");
|
|
58
58
|
var constants_1 = require("../constants");
|
|
59
59
|
var Treble_1 = __importDefault(require("../Treble"));
|
|
60
|
-
var translations_1 = require("./translations");
|
|
61
60
|
var attributes_1 = require("./attributes");
|
|
62
61
|
var price_1 = require("./price");
|
|
63
62
|
var wishlist_1 = require("./wishlist");
|
|
63
|
+
var translations_1 = require("./translations");
|
|
64
64
|
var product_1 = require("./product");
|
|
65
65
|
/*****************************************************
|
|
66
66
|
* Helper Functions
|
|
@@ -104,9 +104,9 @@ var initialState = {
|
|
|
104
104
|
/*****************************************************
|
|
105
105
|
* Actions
|
|
106
106
|
****************************************************/
|
|
107
|
-
exports.setThreekitInitialized = (0, toolkit_1.createAction)('
|
|
108
|
-
exports.setPlayerLoading = (0, toolkit_1.createAction)('
|
|
109
|
-
exports.setPlayerElement = (0, toolkit_1.createAction)('
|
|
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
110
|
/*****************************************************
|
|
111
111
|
* Slice
|
|
112
112
|
****************************************************/
|
|
@@ -148,17 +148,17 @@ exports.getPlayerElementId = getPlayerElementId;
|
|
|
148
148
|
****************************************************/
|
|
149
149
|
var launch = function (launchConfig) {
|
|
150
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,
|
|
152
|
-
var
|
|
153
|
-
var _d, _e, _f, _g
|
|
154
|
-
return __generator(this, function (
|
|
155
|
-
switch (
|
|
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
156
|
case 0:
|
|
157
157
|
if (window.threekit)
|
|
158
158
|
return [2 /*return*/];
|
|
159
159
|
config = (0, utils_1.loadTrebleConfig)();
|
|
160
|
-
credentials = Object.assign({}, ((
|
|
161
|
-
products = Object.assign({}, ((
|
|
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
162
|
if (!Object.keys(credentials).length || !Object.keys(products).length)
|
|
163
163
|
return [2 /*return*/, console.error('Missing credentials')];
|
|
164
164
|
threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
|
|
@@ -202,19 +202,19 @@ var launch = function (launchConfig) {
|
|
|
202
202
|
initialConfiguration = __assign({}, initialConfigurationRaw);
|
|
203
203
|
updatedAssetId = assetId;
|
|
204
204
|
params = (0, utils_1.getParams)();
|
|
205
|
-
configId = ((
|
|
205
|
+
configId = ((_g = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _g === void 0 ? void 0 : _g.length)
|
|
206
206
|
? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
|
|
207
207
|
: configurationId;
|
|
208
208
|
if (!configId) return [3 /*break*/, 2];
|
|
209
209
|
return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
|
|
210
210
|
case 1:
|
|
211
|
-
configuration =
|
|
211
|
+
configuration = _h.sent();
|
|
212
212
|
if (configuration) {
|
|
213
213
|
initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
|
|
214
214
|
connection_1.default.connect({ assetId: configuration.data.productId });
|
|
215
215
|
updatedAssetId = configuration.data.productId;
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
_h.label = 2;
|
|
218
218
|
case 2:
|
|
219
219
|
if (!updatedAssetId)
|
|
220
220
|
return [2 /*return*/, console.error('missing assetId')];
|
|
@@ -222,54 +222,32 @@ var launch = function (launchConfig) {
|
|
|
222
222
|
return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
|
|
223
223
|
case 3:
|
|
224
224
|
// We create the threekit script
|
|
225
|
-
|
|
226
|
-
return [4 /*yield*/,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration })),
|
|
230
|
-
api_1.default.products.fetchTranslations(),
|
|
231
|
-
api_1.default.price.getPricebooksList(),
|
|
232
|
-
])];
|
|
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 }))];
|
|
233
229
|
case 4:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
230
|
+
player = _h.sent();
|
|
231
|
+
_a = window;
|
|
232
|
+
_b = {
|
|
237
233
|
player: player
|
|
238
234
|
};
|
|
239
235
|
return [4 /*yield*/, player.getConfigurator()];
|
|
240
236
|
case 5:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
dispatch((0,
|
|
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));
|
|
245
242
|
window.threekit.player.on('setConfiguration', function () {
|
|
246
243
|
dispatch((0, attributes_1.setAttributes)(window.threekit.configurator.getDisplayAttributes()));
|
|
247
244
|
dispatch((0, price_1.updatePrice)());
|
|
248
245
|
});
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
EVENTS = Object.assign(EVENTS, launchConfig.eventHandlers);
|
|
255
|
-
if (pricebook.length) {
|
|
256
|
-
priceConfig = {
|
|
257
|
-
id: pricebook[0].id,
|
|
258
|
-
currency: pricebook[0].currencies[0],
|
|
259
|
-
};
|
|
260
|
-
dispatch((0, price_1.setPriceConfig)(priceConfig));
|
|
261
|
-
}
|
|
262
|
-
productName = window.threekit.player.scene.get({
|
|
263
|
-
id: window.threekit.player.assetId,
|
|
264
|
-
}).name;
|
|
265
|
-
dispatch((0, product_1.setName)(productName));
|
|
266
|
-
dispatch((0, product_1.setMetadata)(window.threekit.configurator.getMetadata()));
|
|
267
|
-
dispatch((0, exports.setThreekitInitialized)());
|
|
268
|
-
dispatch((0, exports.setPlayerLoading)(false));
|
|
269
|
-
return [4 /*yield*/, window.threekit.treble.wishlist.getWishlist()];
|
|
270
|
-
case 6:
|
|
271
|
-
wishlistData = _j.sent();
|
|
272
|
-
dispatch((0, wishlist_1.setWishlist)(wishlistData));
|
|
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)());
|
|
273
251
|
return [2 /*return*/];
|
|
274
252
|
}
|
|
275
253
|
});
|
package/dist/store/wishlist.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RootState, ThreekitDispatch } from './index';
|
|
2
2
|
import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
|
|
3
|
-
import { IConfigurationResponse } from '../http/configurations';
|
|
4
3
|
/*****************************************************
|
|
5
4
|
* Types and Interfaces
|
|
6
5
|
****************************************************/
|
|
@@ -8,7 +7,10 @@ export declare type WishlistState = WishlistArray;
|
|
|
8
7
|
/*****************************************************
|
|
9
8
|
* Standard Selectors
|
|
10
9
|
****************************************************/
|
|
11
|
-
export declare const
|
|
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>;
|
|
12
14
|
/*****************************************************
|
|
13
15
|
* Slice
|
|
14
16
|
****************************************************/
|
|
@@ -17,8 +19,5 @@ declare const reducer: import("redux").Reducer<WishlistArray, import("redux").An
|
|
|
17
19
|
* Standard Selectors
|
|
18
20
|
****************************************************/
|
|
19
21
|
export declare const getWishlist: (state: RootState) => WishlistArray;
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const removeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch) => void;
|
|
22
|
-
export declare const resumeFromWishlist: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
|
|
23
|
-
export declare const clearWishlist: () => (dispatch: ThreekitDispatch) => void;
|
|
22
|
+
export declare const resumeFromWishlist: (idx: number) => (_: ThreekitDispatch, getState: () => RootState) => void;
|
|
24
23
|
export default reducer;
|
package/dist/store/wishlist.js
CHANGED
|
@@ -36,9 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.resumeFromWishlist = exports.getWishlist = exports.removeFromWishlist = exports.clearWishlist = exports.addToWishlist = exports.refreshWishlist = void 0;
|
|
40
40
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
41
|
-
var attributes_1 = require("./attributes");
|
|
42
41
|
/*****************************************************
|
|
43
42
|
* State
|
|
44
43
|
****************************************************/
|
|
@@ -46,7 +45,36 @@ var initialState = [];
|
|
|
46
45
|
/*****************************************************
|
|
47
46
|
* Standard Selectors
|
|
48
47
|
****************************************************/
|
|
49
|
-
exports.
|
|
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
|
+
});
|
|
50
78
|
/*****************************************************
|
|
51
79
|
* Slice
|
|
52
80
|
****************************************************/
|
|
@@ -55,9 +83,17 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
55
83
|
initialState: initialState,
|
|
56
84
|
reducers: {},
|
|
57
85
|
extraReducers: function (builder) {
|
|
58
|
-
builder.addCase(exports.
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
61
97
|
});
|
|
62
98
|
},
|
|
63
99
|
}).reducer;
|
|
@@ -67,35 +103,12 @@ var reducer = (0, toolkit_1.createSlice)({
|
|
|
67
103
|
// Wishlist
|
|
68
104
|
var getWishlist = function (state) { return state.wishlist; };
|
|
69
105
|
exports.getWishlist = getWishlist;
|
|
70
|
-
var
|
|
71
|
-
var wishlistData;
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
switch (_a.label) {
|
|
74
|
-
case 0: return [4 /*yield*/, window.threekit.treble.wishlist.addItem(config)];
|
|
75
|
-
case 1:
|
|
76
|
-
wishlistData = _a.sent();
|
|
77
|
-
dispatch((0, exports.setWishlist)(wishlistData));
|
|
78
|
-
return [2 /*return*/];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}); }; };
|
|
82
|
-
exports.addToWishlist = addToWishlist;
|
|
83
|
-
var removeFromWishlist = function (idx) { return function (dispatch) {
|
|
84
|
-
var wishlistData = window.threekit.treble.wishlist.removeItemByIdx(idx);
|
|
85
|
-
dispatch((0, exports.setWishlist)(wishlistData));
|
|
86
|
-
}; };
|
|
87
|
-
exports.removeFromWishlist = removeFromWishlist;
|
|
88
|
-
var resumeFromWishlist = function (idx) { return function (dispatch, getState) {
|
|
106
|
+
var resumeFromWishlist = function (idx) { return function (_, getState) {
|
|
89
107
|
var wishlist = getState().wishlist;
|
|
90
108
|
var savedConfiguration = wishlist[idx];
|
|
91
109
|
if (!savedConfiguration)
|
|
92
110
|
return;
|
|
93
|
-
|
|
111
|
+
window.threekit.configurator.setConfiguration(savedConfiguration.variant);
|
|
94
112
|
}; };
|
|
95
113
|
exports.resumeFromWishlist = resumeFromWishlist;
|
|
96
|
-
var clearWishlist = function () { return function (dispatch) {
|
|
97
|
-
var wishlistData = window.threekit.treble.wishlist.clearWishlist();
|
|
98
|
-
dispatch((0, exports.setWishlist)(wishlistData));
|
|
99
|
-
}; };
|
|
100
|
-
exports.clearWishlist = clearWishlist;
|
|
101
114
|
exports.default = reducer;
|