@threekit-tools/treble 0.0.52 → 0.0.53

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.
@@ -1,10 +1,11 @@
1
1
  import threekitAPI from '../api';
2
- import { IThreekitPlayer, IMetadata } from '../threekit';
2
+ import { IThreekitPlayer, IMetadata, IConfiguration, ISetConfiguration } from '../threekit';
3
3
  import { IWishlist } from './Wishlist';
4
4
  import Snapshots from './Snapshots';
5
5
  interface ITreble {
6
6
  player: IThreekitPlayer;
7
7
  orgId: string;
8
+ initialConfiguration: IConfiguration;
8
9
  }
9
10
  export interface ISaveConfigurationConfig {
10
11
  customerId?: string;
@@ -15,14 +16,16 @@ declare class Treble {
15
16
  _api: typeof threekitAPI;
16
17
  _player: IThreekitPlayer;
17
18
  wishlist: IWishlist;
19
+ private _initialConfiguration;
18
20
  private _snapshots;
19
21
  takeSnapshots: Snapshots['takeSnapshots'];
20
- constructor({ player, orgId }: ITreble);
22
+ constructor({ player, orgId, initialConfiguration }: ITreble);
21
23
  saveConfiguration: (config?: ISaveConfigurationConfig | undefined) => Promise<{
22
24
  resumableUrl: string;
23
25
  } & import("../http/configurations").IConfigurationResponse & {
24
26
  thumbnail: string;
25
27
  }>;
26
28
  getNestedConfigurator: (address: string | Array<string>) => any;
29
+ resetConfiguration: (configuration?: ISetConfiguration | undefined) => void;
27
30
  }
28
31
  export default Treble;
@@ -48,7 +48,7 @@ var Snapshots_1 = __importDefault(require("./Snapshots"));
48
48
  var Treble = /** @class */ (function () {
49
49
  function Treble(_a) {
50
50
  var _this = this;
51
- var player = _a.player, orgId = _a.orgId;
51
+ var player = _a.player, orgId = _a.orgId, initialConfiguration = _a.initialConfiguration;
52
52
  this.saveConfiguration = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
53
  var threekitDomain, _a, customerId, metadata, productVersion, files, response, params, url;
54
54
  var _b;
@@ -94,6 +94,11 @@ var Treble = /** @class */ (function () {
94
94
  }).configurator;
95
95
  }, player.getConfigurator());
96
96
  };
97
+ this.resetConfiguration = function (configuration) {
98
+ var initialConfiguration = JSON.parse(_this._initialConfiguration);
99
+ var updateConfiguration = Object.assign(initialConfiguration, configuration);
100
+ window.threekit.configurator.setConfiguration(updateConfiguration);
101
+ };
97
102
  // Threekit API
98
103
  this._api = api_1.default;
99
104
  this._player = player;
@@ -101,6 +106,7 @@ var Treble = /** @class */ (function () {
101
106
  this._snapshots = new Snapshots_1.default();
102
107
  this.takeSnapshots = this._snapshots.takeSnapshots;
103
108
  // this._player = player.enableApi('player');
109
+ this._initialConfiguration = JSON.stringify(initialConfiguration);
104
110
  }
105
111
  return Treble;
106
112
  }());
@@ -148,17 +148,16 @@ 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, player, _a;
152
- var _b;
153
- var _c, _d, _e, _f, _g;
154
- return __generator(this, function (_h) {
155
- switch (_h.label) {
151
+ var config, credentials, products, threekitEnv, playerConfig, envCredentials, product, threekitDomainRaw, orgId, authToken, initialConfigurationRaw, assetId, stageId, configurationId, el, threekitDomain, initialConfiguration, updatedAssetId, params, configId, configuration, player, configurator;
152
+ var _a, _b, _c, _d, _e;
153
+ return __generator(this, function (_f) {
154
+ switch (_f.label) {
156
155
  case 0:
157
156
  if (window.threekit)
158
157
  return [2 /*return*/];
159
158
  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) || {});
159
+ credentials = Object.assign({}, ((_a = config.project) === null || _a === void 0 ? void 0 : _a.credentials) || {}, ((_b = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _b === void 0 ? void 0 : _b.credentials) || {});
160
+ products = Object.assign({}, ((_c = config.project) === null || _c === void 0 ? void 0 : _c.products) || {}, ((_d = launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.project) === null || _d === void 0 ? void 0 : _d.products) || {});
162
161
  if (!Object.keys(credentials).length || !Object.keys(products).length)
163
162
  return [2 /*return*/, console.error('Missing credentials')];
164
163
  threekitEnv = (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.threekitEnv) || process.env.THREEKIT_ENV || 'preview';
@@ -202,19 +201,19 @@ var launch = function (launchConfig) {
202
201
  initialConfiguration = __assign({}, initialConfigurationRaw);
203
202
  updatedAssetId = assetId;
204
203
  params = (0, utils_1.getParams)();
205
- configId = ((_g = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _g === void 0 ? void 0 : _g.length)
204
+ configId = ((_e = params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]) === null || _e === void 0 ? void 0 : _e.length)
206
205
  ? params[constants_1.TK_SAVED_CONFIG_PARAM_KEY]
207
206
  : configurationId;
208
207
  if (!configId) return [3 /*break*/, 2];
209
208
  return [4 /*yield*/, api_1.default.configurations.fetch(configId)];
210
209
  case 1:
211
- configuration = _h.sent();
210
+ configuration = _f.sent();
212
211
  if (configuration) {
213
212
  initialConfiguration = Object.assign({}, initialConfigurationRaw, configuration.data.variant);
214
213
  connection_1.default.connect({ assetId: configuration.data.productId });
215
214
  updatedAssetId = configuration.data.productId;
216
215
  }
217
- _h.label = 2;
216
+ _f.label = 2;
218
217
  case 2:
219
218
  if (!updatedAssetId)
220
219
  return [2 /*return*/, console.error('missing assetId')];
@@ -222,21 +221,24 @@ var launch = function (launchConfig) {
222
221
  return [4 /*yield*/, (0, utils_1.createThreekitScriptEl)(threekitDomain)];
223
222
  case 3:
224
223
  // We create the threekit script
225
- _h.sent();
224
+ _f.sent();
226
225
  return [4 /*yield*/, window.threekitPlayer(__assign(__assign({ el: el,
227
226
  // Variables to sort out
228
227
  authToken: authToken, stageId: stageId, assetId: updatedAssetId }, playerConfig), { initialConfiguration: initialConfiguration }))];
229
228
  case 4:
230
- player = _h.sent();
231
- _a = window;
232
- _b = {
233
- player: player
234
- };
229
+ player = _f.sent();
235
230
  return [4 /*yield*/, player.getConfigurator()];
236
231
  case 5:
237
- _a.threekit = (_b.configurator = _h.sent(),
238
- _b.treble = new Treble_1.default({ player: player, orgId: orgId }),
239
- _b);
232
+ configurator = _f.sent();
233
+ window.threekit = {
234
+ player: player,
235
+ configurator: configurator,
236
+ treble: new Treble_1.default({
237
+ player: player,
238
+ orgId: orgId,
239
+ initialConfiguration: configurator.getConfiguration(),
240
+ }),
241
+ };
240
242
  dispatch((0, exports.setThreekitInitialized)());
241
243
  dispatch((0, exports.setPlayerLoading)(false));
242
244
  window.threekit.player.on('setConfiguration', function () {
@@ -214,11 +214,25 @@ export interface ThreekitInitConfig {
214
214
  showShare?: boolean;
215
215
  showLoadingThumbnail?: boolean;
216
216
  showLoadingProgress?: boolean;
217
- onLoadingProgress?: boolean;
217
+ onLoadingProgress?: (progress: number) => void;
218
218
  locale?: string;
219
219
  allowMobileVerticalOrbit?: boolean;
220
220
  publishStage?: string;
221
221
  display?: DISPLAY_OPTIONS;
222
+ classnames?: {
223
+ loading?: string;
224
+ mobile?: string;
225
+ share?: string | {
226
+ button: string;
227
+ popup: string;
228
+ };
229
+ fullscreen?: string;
230
+ ar?: string | {
231
+ button: string;
232
+ popup: string;
233
+ };
234
+ help?: string;
235
+ };
222
236
  }
223
237
  /***************************************************
224
238
  * Treble Declarations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [