zakeke-configurator-react 0.0.111 → 0.0.112

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.
@@ -40,6 +40,8 @@ export declare class ZakekeEnvironment {
40
40
  private enableShareCompositionUrl;
41
41
  private sharedCompositionDocId;
42
42
  private savedCompositions;
43
+ private initialSelection;
44
+ currentAttributesSelection: Object | null;
43
45
  sellerSettings: SellerSettings | null;
44
46
  get internalProduct(): MPlaza.Model | null;
45
47
  get internalScene(): Zakeke.Scene | null;
@@ -86,6 +88,7 @@ export declare class ZakekeEnvironment {
86
88
  }) => void;
87
89
  renderDesign: _.DebouncedFunc<() => Promise<void>>;
88
90
  resize: () => void;
91
+ private buildRecapProps;
89
92
  updateRecapAndExtensionField: () => void;
90
93
  private getCurrentExtensionFields;
91
94
  private handleSceneLoaded;
@@ -94,6 +97,8 @@ export declare class ZakekeEnvironment {
94
97
  private internalLoadDesign;
95
98
  loadComposition: (id: string | null) => Promise<void>;
96
99
  private internalLoadComposition;
100
+ cloneSelection: (selection: any) => Zakeke.ComposerSelection;
101
+ reset: () => Promise<void>;
97
102
  private handleAttributeSelectionChanged;
98
103
  private handleAttributeEnabled;
99
104
  private handleAttributeDisabled;
@@ -43,7 +43,13 @@ export interface ProviderValue {
43
43
  eventMessages: EventMessage[] | null;
44
44
  isAssetsLoading: boolean;
45
45
  themeCompositions: ThemeCompositions[] | null;
46
- extensionFields: object | null;
46
+ extensionFields: {
47
+ name: string;
48
+ value: number;
49
+ label: string;
50
+ formatString: string;
51
+ }[] | null;
52
+ currentAttributesSelection: object | null;
47
53
  selectOption: (optionId: number) => void;
48
54
  internalAppendViewer: (container: HTMLElement) => void;
49
55
  designUpdate: () => void;
@@ -116,6 +122,7 @@ export interface ProviderValue {
116
122
  saveDraftsComposition: (name: string, tags: string[], isCopy?: boolean) => Promise<void>;
117
123
  loadSavedComposition: (docID: string) => Promise<void>;
118
124
  deleteSavedComposition: (docId: string) => Promise<void>;
125
+ reset: () => Promise<void>;
119
126
  }
120
127
  export declare const createProviderValue: (state: AppState, dispatch: React.Dispatch<any>) => ProviderValue;
121
128
  export {};
package/dist/index.js CHANGED
@@ -3921,18 +3921,27 @@ __webpack_require__.r(__webpack_exports__);
3921
3921
 
3922
3922
 
3923
3923
  class EnvironmentManager {
3924
- constructor(zkScene, scene) {
3924
+ constructor(zkScene, scene, isHologram = false) {
3925
3925
  this._originalSceneClearColor = null;
3926
3926
  this._originalCameraAutoRotate = null;
3927
3927
  this._environmentHelper = null;
3928
3928
  this._shadowLight = null;
3929
+ this._isHologram = false;
3929
3930
  this._zkScene = zkScene;
3930
3931
  this._scene = scene;
3931
3932
  this._sceneHelper = new _SceneHelper__WEBPACK_IMPORTED_MODULE_0__.SceneHelper(this._scene);
3933
+ this._isHologram = isHologram;
3932
3934
  }
3933
3935
  get scene() {
3934
3936
  return this._scene;
3935
3937
  }
3938
+ get isHologram() {
3939
+ return this._isHologram;
3940
+ }
3941
+ set isHologram(value) {
3942
+ this._isHologram = value;
3943
+ this.update();
3944
+ }
3936
3945
  dispose() {
3937
3946
  if (this._shadowLight)
3938
3947
  this._shadowLight.dispose();
@@ -3950,7 +3959,8 @@ class EnvironmentManager {
3950
3959
  }
3951
3960
  configureSkybox() {
3952
3961
  this.removeOldSkybox();
3953
- this.createSkybox();
3962
+ if (this._isHologram)
3963
+ this.createSkybox();
3954
3964
  }
3955
3965
  removeOldSkybox() {
3956
3966
  const mesh = this.getSkyboxMesh();
@@ -4055,6 +4065,11 @@ class EnvironmentManager {
4055
4065
  configureScene() {
4056
4066
  if (!this._scene)
4057
4067
  return;
4068
+ this._originalSceneClearColor = this._scene.clearColor.clone();
4069
+ if (this._isHologram) {
4070
+ this._scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
4071
+ return;
4072
+ }
4058
4073
  var generalConfig = this.getGeneralConfig();
4059
4074
  if (generalConfig) {
4060
4075
  let alpha = null;
@@ -21811,6 +21826,7 @@ SceneEditor.EmptyGroupName = "_dummy_";
21811
21826
  "use strict";
21812
21827
  __webpack_require__.r(__webpack_exports__);
21813
21828
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
21829
+ /* harmony export */ "BroadcastChannelEventType": () => (/* binding */ BroadcastChannelEventType),
21814
21830
  /* harmony export */ "SceneViewer": () => (/* binding */ SceneViewer)
21815
21831
  /* harmony export */ });
21816
21832
  /* harmony import */ var _Components_ActionExecutor_SceneActionExecutor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Components/ActionExecutor/SceneActionExecutor */ "../../3D/src/Components/ActionExecutor/SceneActionExecutor.ts");
@@ -21850,6 +21866,12 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
21850
21866
 
21851
21867
 
21852
21868
 
21869
+ var BroadcastChannelEventType;
21870
+ (function (BroadcastChannelEventType) {
21871
+ BroadcastChannelEventType["CameraMovement"] = "camera-movement";
21872
+ BroadcastChannelEventType["ScriptExecution"] = "script-execution";
21873
+ BroadcastChannelEventType["DesignChanged"] = "design-changed";
21874
+ })(BroadcastChannelEventType || (BroadcastChannelEventType = {}));
21853
21875
  class SceneViewer {
21854
21876
  constructor(options) {
21855
21877
  // Zakeke Scene Model
@@ -21914,6 +21936,9 @@ class SceneViewer {
21914
21936
  this._infoPointsManagerStyle = null;
21915
21937
  this._canShowInfoPoints = true;
21916
21938
  this._canShowInfoPointsContent = true;
21939
+ this._broadcastChannel = null;
21940
+ this._isHologramSource = false;
21941
+ this._isHologram = false;
21917
21942
  this.setCameraLocked = (isBlocked) => {
21918
21943
  if (this._zkScene && this._sceneHelper && this._scene) {
21919
21944
  this._sceneHelper.setupCamera();
@@ -21972,6 +21997,30 @@ class SceneViewer {
21972
21997
  set antialias(value) {
21973
21998
  this._antialias = value;
21974
21999
  }
22000
+ get isHologramSource() {
22001
+ return this.isHologramSource;
22002
+ }
22003
+ set isHologramSource(value) {
22004
+ this._isHologramSource = value;
22005
+ if (value) {
22006
+ this._isHologram = false;
22007
+ this.detachBroadcastChannelEventHandlers();
22008
+ }
22009
+ }
22010
+ get isHologram() {
22011
+ return this._isHologram;
22012
+ }
22013
+ set isHologram(value) {
22014
+ this._isHologram = value;
22015
+ if (value) {
22016
+ this._isHologramSource = false;
22017
+ this.attachBroadcastChannelEventHandlers();
22018
+ }
22019
+ else {
22020
+ this.detachBroadcastChannelEventHandlers();
22021
+ }
22022
+ this.refreshEnvironment();
22023
+ }
21975
22024
  getAntialiasEnabled() {
21976
22025
  let def = true;
21977
22026
  if (this._zkScene) {
@@ -22149,6 +22198,7 @@ class SceneViewer {
22149
22198
  });
22150
22199
  }
22151
22200
  dispose() {
22201
+ this.closeBroadcastChannel();
22152
22202
  this.removeCanvas();
22153
22203
  this.removeDomElement();
22154
22204
  this.deleteScene();
@@ -22267,6 +22317,21 @@ class SceneViewer {
22267
22317
  yield this.init3DEngineAsync();
22268
22318
  });
22269
22319
  }
22320
+ closeBroadcastChannel() {
22321
+ if (this._broadcastChannel) {
22322
+ this._broadcastChannel.close();
22323
+ this._broadcastChannel = null;
22324
+ }
22325
+ }
22326
+ openBroadcastChannel() {
22327
+ if (!this._broadcastChannel) {
22328
+ this._broadcastChannel = new BroadcastChannel("zakeke-broadcast-channel");
22329
+ }
22330
+ }
22331
+ getOrCreateBroadcastChannel() {
22332
+ this.openBroadcastChannel();
22333
+ return this._broadcastChannel;
22334
+ }
22270
22335
  createEngine() {
22271
22336
  this.deleteScene();
22272
22337
  this.deleteEngine();
@@ -22329,6 +22394,9 @@ class SceneViewer {
22329
22394
  this._sceneHelper.setMaxZoomPerc(null);
22330
22395
  this._sceneHelper.setCameraAlphaLimits(lowerAlphaLimit, upperAlphaLimit);
22331
22396
  this._sceneHelper.setCameraBetaLimits(lowerBetaLimit, upperBetaLimit);
22397
+ this._camera.onViewMatrixChangedObservable.add(() => {
22398
+ this.notifyCameraMovement();
22399
+ });
22332
22400
  this._camera.onRestoreStateObservable.add(() => {
22333
22401
  this.setupShaderMaterialsCameraPosition();
22334
22402
  this.setRenderingNeeded();
@@ -23117,6 +23185,7 @@ class SceneViewer {
23117
23185
  return __awaiter(this, void 0, void 0, function* () {
23118
23186
  if (this._sceneActionsExecutor) {
23119
23187
  yield this._sceneActionsExecutor.executeScriptAsync(script);
23188
+ this.notifyScriptExecution(script);
23120
23189
  this.setupShaderMaterialsCameraPosition();
23121
23190
  this.refreshInfoPoints();
23122
23191
  this.setLongRenderingNeeded();
@@ -23127,6 +23196,7 @@ class SceneViewer {
23127
23196
  return __awaiter(this, void 0, void 0, function* () {
23128
23197
  if (this._sceneActionsExecutor) {
23129
23198
  yield this._sceneActionsExecutor.executeActionsAsync(attributeID, selectedValue, actions);
23199
+ this.notifyActionExecution(attributeID, selectedValue, actions);
23130
23200
  this.setupShaderMaterialsCameraPosition();
23131
23201
  this.refreshInfoPoints();
23132
23202
  this.setLongRenderingNeeded();
@@ -23147,8 +23217,8 @@ class SceneViewer {
23147
23217
  }
23148
23218
  refreshEnvironment() {
23149
23219
  if (this._zkScene && this._scene) {
23150
- if (!this._environmentManager || this._environmentManager.scene != this._scene)
23151
- this._environmentManager = new _Components_Environment_EnvironmentManager__WEBPACK_IMPORTED_MODULE_4__.EnvironmentManager(this._zkScene, this._scene);
23220
+ if (!this._environmentManager || this._environmentManager.scene != this._scene || this._environmentManager.isHologram != this._isHologram)
23221
+ this._environmentManager = new _Components_Environment_EnvironmentManager__WEBPACK_IMPORTED_MODULE_4__.EnvironmentManager(this._zkScene, this._scene, this._isHologram);
23152
23222
  this._environmentManager.update();
23153
23223
  this.setLongRenderingNeeded();
23154
23224
  if (this._camera && this._camera instanceof BABYLON.ArcRotateCamera)
@@ -23440,7 +23510,6 @@ class SceneViewer {
23440
23510
  let dataUrl = '';
23441
23511
  if (legacyScreenshot) {
23442
23512
  dataUrl = yield this._sceneHelper.takeContentScreenshotAsync(width, height);
23443
- console.log({ dataUrlLegacy: dataUrl });
23444
23513
  }
23445
23514
  else {
23446
23515
  const result = yield _Components_ScenePreview_ScenePreview__WEBPACK_IMPORTED_MODULE_9__.ScenesPreview.getPreviewsAsync(this.scene, this._zkScene.get("rootUrl"), {
@@ -23456,7 +23525,6 @@ class SceneViewer {
23456
23525
  meshesWithCustomizationIds: canvasMeshesOriginalMeshesIds,
23457
23526
  });
23458
23527
  dataUrl = result.previewFile;
23459
- console.log({ dataUrl });
23460
23528
  }
23461
23529
  // Trim image
23462
23530
  let image = yield _Helpers_utils__WEBPACK_IMPORTED_MODULE_11__.Utils.trimImageAsync(dataUrl);
@@ -23532,7 +23600,10 @@ class SceneViewer {
23532
23600
  this._sceneDesignManager = null;
23533
23601
  }
23534
23602
  this._sceneDesignManager = new _Components_DesignManagers_SceneDesignManager__WEBPACK_IMPORTED_MODULE_2__.SceneDesignManager(this._scene, this._zkScene, this._zkModel, zkDesign, showDesign);
23535
- this._sceneDesignManager.addRenderingNeededListener(() => this.setLongRenderingNeeded());
23603
+ this._sceneDesignManager.addRenderingNeededListener(() => {
23604
+ this.setLongRenderingNeeded();
23605
+ this.notifyDesignChanged(zkDesign);
23606
+ });
23536
23607
  this._sceneDesignManager.setCustomizerGrids(this._grids);
23537
23608
  this._sceneDesignManager.setEventMessages(this._designEventMessages);
23538
23609
  for (const listener of this._designNotifyMessageListeners)
@@ -24168,6 +24239,109 @@ class SceneViewer {
24168
24239
  materialHasLoadingErrorTextues(material) {
24169
24240
  return this._sceneHelper ? this._sceneHelper.materialHasLoadingErrorTextues(material) : false;
24170
24241
  }
24242
+ notifyCameraMovement() {
24243
+ if (this._isHologramSource && this._camera && this._camera instanceof BABYLON.ArcRotateCamera) {
24244
+ let bc = this.getOrCreateBroadcastChannel();
24245
+ bc.postMessage({
24246
+ type: BroadcastChannelEventType.CameraMovement,
24247
+ target: { x: this._camera.target.x, y: this._camera.target.y, z: this._camera.target.z },
24248
+ alpha: this._camera.alpha,
24249
+ beta: this._camera.beta,
24250
+ radius: this._camera.radius
24251
+ });
24252
+ }
24253
+ }
24254
+ notifyScriptExecution(script) {
24255
+ if (this._isHologramSource) {
24256
+ const scriptJson = script.map(s => ({
24257
+ attributeID: s.attributeID,
24258
+ selectedValue: s.selectedValue,
24259
+ actions: s.actions.map(a => a.toJSON())
24260
+ /*
24261
+ actions: s.actions.map(a => ({
24262
+ attributeGuid: a.get("actionGuid"),
24263
+ name: a.get("name"),
24264
+ actionTypeID: a.get("actionTypeID"),
24265
+ sceneElementTypeID: a.get("sceneElementTypeID"),
24266
+ selector: a.get("selector"),
24267
+ propertyName: a.get("propertyName"),
24268
+ value: a.get("value"),
24269
+ execOrder: a.get("execOrder"),
24270
+ deviceTypes: a.get("deviceTypes")
24271
+ }))
24272
+ */
24273
+ }));
24274
+ let bc = this.getOrCreateBroadcastChannel();
24275
+ bc.postMessage({
24276
+ type: BroadcastChannelEventType.ScriptExecution,
24277
+ script: scriptJson
24278
+ });
24279
+ }
24280
+ }
24281
+ notifyDesignChanged(zkDesign) {
24282
+ if (this._isHologramSource) {
24283
+ let bc = this.getOrCreateBroadcastChannel();
24284
+ bc.postMessage({
24285
+ type: BroadcastChannelEventType.DesignChanged,
24286
+ design: zkDesign.toJSON()
24287
+ });
24288
+ }
24289
+ }
24290
+ notifyActionExecution(attributeID, selectedValue, actions) {
24291
+ this.notifyScriptExecution([{
24292
+ attributeID,
24293
+ selectedValue,
24294
+ actions
24295
+ }]);
24296
+ }
24297
+ attachBroadcastChannelEventHandlers() {
24298
+ if (this._isHologram && !this._isHologramSource) {
24299
+ var bc = this.getOrCreateBroadcastChannel();
24300
+ bc.onmessage = (event) => this.onBroadcastMessageReceived(event);
24301
+ }
24302
+ }
24303
+ detachBroadcastChannelEventHandlers() {
24304
+ if (this._broadcastChannel)
24305
+ this._broadcastChannel.onmessage = null;
24306
+ }
24307
+ onBroadcastMessageReceived(event) {
24308
+ if (this._isHologram && event && event.data && event.data.type) {
24309
+ if (event.data.type === BroadcastChannelEventType.CameraMovement) {
24310
+ this.processCameraMovementEvent(event);
24311
+ }
24312
+ else if (event.data.type === BroadcastChannelEventType.ScriptExecution) {
24313
+ this.processScriptExecution(event);
24314
+ }
24315
+ else if (event.data.type === BroadcastChannelEventType.DesignChanged) {
24316
+ this.processDesignChanged(event);
24317
+ }
24318
+ }
24319
+ }
24320
+ processCameraMovementEvent(event) {
24321
+ if (this._camera && this._camera instanceof BABYLON.ArcRotateCamera && event && event.data) {
24322
+ this._camera.target = new BABYLON.Vector3(event.data.target.x, event.data.target.y, event.data.target.z);
24323
+ this._camera.alpha = event.data.alpha;
24324
+ this._camera.beta = event.data.beta;
24325
+ this._camera.radius = event.data.radius;
24326
+ this.setRenderingNeeded();
24327
+ }
24328
+ }
24329
+ processScriptExecution(event) {
24330
+ if (event && event.data && event.data.script && Object.prototype.toString.call(event.data.script) === '[object Array]') {
24331
+ var composerScript = event.data.script.map(s => ({
24332
+ attributeID: s.attributeID,
24333
+ selectedValue: s.selectedValue,
24334
+ actions: s.actions.map(a => new MPlaza.AttributeSceneAction(a))
24335
+ }));
24336
+ this.executeScriptAsync(composerScript);
24337
+ }
24338
+ }
24339
+ processDesignChanged(event) {
24340
+ if (event && event.data && event.data.design) {
24341
+ let zkDesign = new MPlaza.Design(event.data.design);
24342
+ this.renderDesignAsync(zkDesign);
24343
+ }
24344
+ }
24171
24345
  }
24172
24346
 
24173
24347
 
@@ -24187,6 +24361,7 @@ __webpack_require__.r(__webpack_exports__);
24187
24361
  /* harmony export */ "BlendProceduralTexture": () => (/* reexport safe */ _Components_ProceduralTextures_BlendProceduralTexture__WEBPACK_IMPORTED_MODULE_14__.BlendProceduralTexture),
24188
24362
  /* harmony export */ "BlurXProceduralTexture": () => (/* reexport safe */ _Components_ProceduralTextures_BlurXProceduralTexture__WEBPACK_IMPORTED_MODULE_6__.BlurXProceduralTexture),
24189
24363
  /* harmony export */ "BlurYProceduralTexture": () => (/* reexport safe */ _Components_ProceduralTextures_BlurYProceduralTexture__WEBPACK_IMPORTED_MODULE_7__.BlurYProceduralTexture),
24364
+ /* harmony export */ "BroadcastChannelEventType": () => (/* reexport safe */ _Viewers_SceneViewer__WEBPACK_IMPORTED_MODULE_48__.BroadcastChannelEventType),
24190
24365
  /* harmony export */ "Database": () => (/* reexport safe */ _Misc_Database__WEBPACK_IMPORTED_MODULE_47__.Database),
24191
24366
  /* harmony export */ "DefaultAssetUrls": () => (/* reexport safe */ _Misc_DefaultAssetUrls__WEBPACK_IMPORTED_MODULE_43__.DefaultAssetUrls),
24192
24367
  /* harmony export */ "DracoCompression": () => (/* reexport safe */ _Components_Draco_DracoCompression__WEBPACK_IMPORTED_MODULE_27__.DracoCompression),
@@ -24759,6 +24934,7 @@ class ZakekeEnvironment {
24759
24934
  this.enableShareCompositionUrl = false;
24760
24935
  this.sharedCompositionDocId = null;
24761
24936
  this.savedCompositions = null;
24937
+ this.currentAttributesSelection = null;
24762
24938
  this.sellerSettings = null;
24763
24939
  this.themeCompositions = null;
24764
24940
  this.currency = 'EUR';
@@ -25110,6 +25286,57 @@ class ZakekeEnvironment {
25110
25286
  this.viewer.adjustCamera(false);
25111
25287
  }
25112
25288
  };
25289
+ this.buildRecapProps = lodash__WEBPACK_IMPORTED_MODULE_0___default().debounce((selectedOptions) => {
25290
+ if (!this.sellerSettings || !this.sellerSettings.isCompositionRecapEnabled)
25291
+ return;
25292
+ const storeAttr = this.zkProduct.get("attributes");
25293
+ const storeGroups = this.zkProduct.get("attributeGroups");
25294
+ const storeSteps = this.zkProduct.get("attributeSteps");
25295
+ const recapProps = {};
25296
+ selectedOptions.forEach((item) => {
25297
+ const currentAttr = storeAttr.find(attr => attr.get("attributeID") == item.attributeID);
25298
+ const currentOption = currentAttr.get("options").find(opt => opt.get("optionID") == item.optionID);
25299
+ const currentGroup = storeGroups.find(group => group.get("groupID") == currentAttr.get('groupID'));
25300
+ const currentStep = storeSteps.find(step => step.get("stepID") == currentAttr.get('stepID'));
25301
+ let groupName = "";
25302
+ let isOptionEnabled = false;
25303
+ this.selection.get("groups").each(group => {
25304
+ group.get("attributes").each(attr => {
25305
+ var _a, _b, _c, _d, _e, _f, _g, _h;
25306
+ const option = attr.get("options").find(x => x.get('optionID') == currentOption.get("optionID"));
25307
+ if (option && attr.get("enabled")) {
25308
+ isOptionEnabled = this.isOptionEnabled(currentOption.get("optionID"));
25309
+ groupName = group.get("name");
25310
+ if (isOptionEnabled) {
25311
+ if (!recapProps[(currentAttr.get("name"))]) {
25312
+ recapProps[(currentAttr.get("name"))] = {
25313
+ groupDisplayOrder: (_a = currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.get('displayOrder')) !== null && _a !== void 0 ? _a : 0,
25314
+ stepDisplayOrder: (_b = currentStep === null || currentStep === void 0 ? void 0 : currentStep.get('displayOrder')) !== null && _b !== void 0 ? _b : 0,
25315
+ attributeDisplayOrder: (_c = currentAttr === null || currentAttr === void 0 ? void 0 : currentAttr.get('displayOrder')) !== null && _c !== void 0 ? _c : 0,
25316
+ optionDisplayOrder: (_d = currentOption === null || currentOption === void 0 ? void 0 : currentOption.get('displayOrder')) !== null && _d !== void 0 ? _d : 0,
25317
+ value: currentOption.get("name"),
25318
+ groupName,
25319
+ showGroup: false,
25320
+ };
25321
+ }
25322
+ else {
25323
+ recapProps[(currentAttr.get("name"))].showGroup = true;
25324
+ recapProps[`${groupName} ${currentAttr.get("name")}`] = {
25325
+ groupDisplayOrder: (_e = currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.get('displayOrder')) !== null && _e !== void 0 ? _e : 0,
25326
+ stepDisplayOrder: (_f = currentStep === null || currentStep === void 0 ? void 0 : currentStep.get('displayOrder')) !== null && _f !== void 0 ? _f : 0,
25327
+ attributeDisplayOrder: (_g = currentAttr === null || currentAttr === void 0 ? void 0 : currentAttr.get('displayOrder')) !== null && _g !== void 0 ? _g : 0,
25328
+ optionDisplayOrder: (_h = currentOption === null || currentOption === void 0 ? void 0 : currentOption.get('displayOrder')) !== null && _h !== void 0 ? _h : 0,
25329
+ value: currentOption.get("name"),
25330
+ showGroup: false,
25331
+ };
25332
+ }
25333
+ }
25334
+ }
25335
+ });
25336
+ });
25337
+ });
25338
+ this.currentAttributesSelection = recapProps;
25339
+ }, 200);
25113
25340
  this.updateRecapAndExtensionField = () => {
25114
25341
  const selectedOptions = [];
25115
25342
  this.selection.getAllAttributeSelections().forEach(attribute => {
@@ -25123,7 +25350,7 @@ class ZakekeEnvironment {
25123
25350
  });
25124
25351
  });
25125
25352
  this.getCurrentExtensionFields(selectedOptions);
25126
- //this.buildRecapProps(selectedOptions);
25353
+ this.buildRecapProps(selectedOptions);
25127
25354
  };
25128
25355
  this.getCurrentExtensionFields = (options) => {
25129
25356
  const propsValues = [];
@@ -25164,6 +25391,9 @@ class ZakekeEnvironment {
25164
25391
  console.log("Scene loaded");
25165
25392
  this.selection = Zakeke.ComposerSelection.CreateComposerSelection(this.zkProduct);
25166
25393
  let currentCompositionId = this.compositionId || this.sharedCompositionDocId;
25394
+ if (this.initialSelection == undefined) {
25395
+ this.initialSelection = this.cloneSelection(this.selection);
25396
+ }
25167
25397
  yield this.internalLoadComposition(currentCompositionId);
25168
25398
  this.trigger("change");
25169
25399
  this.buildStructure();
@@ -25309,6 +25539,75 @@ class ZakekeEnvironment {
25309
25539
  });
25310
25540
  this.updateComposition();
25311
25541
  });
25542
+ this.cloneSelection = (selection) => {
25543
+ const clone = new Zakeke.ComposerSelection();
25544
+ clone.set('zkModel', this.zkProduct);
25545
+ clone.set('attributeDependencies', selection.get('attributeDependencies'));
25546
+ clone.set('optionDependencies', selection.get('optionDependencies'));
25547
+ clone.get('groups').reset();
25548
+ selection.get('groups').each(group => {
25549
+ var cloneGroup = new Zakeke.AttributeGroupSelection();
25550
+ for (const key in group.attributes) {
25551
+ cloneGroup.set(key, group.attributes[key]);
25552
+ }
25553
+ clone.get('groups').add(cloneGroup);
25554
+ });
25555
+ let idx = 0;
25556
+ clone.get("groups").each((group) => {
25557
+ group.set("attributes", selection.get("groups").at(idx).get("attributes").clone());
25558
+ group.get('attributes').reset();
25559
+ selection.get("groups").at(idx).get("attributes").each(attribute => {
25560
+ var cloneAttribute = new Zakeke.AttributeSelection();
25561
+ for (const key in attribute.attributes) {
25562
+ cloneAttribute.set(key, attribute.attributes[key]);
25563
+ }
25564
+ group.get('attributes').add(cloneAttribute);
25565
+ });
25566
+ let idx2 = 0;
25567
+ group.get("attributes").each((attribute) => {
25568
+ attribute.set("options", selection.get("groups").at(idx).get("attributes").at(idx2).get("options").clone());
25569
+ attribute.get('options').reset();
25570
+ selection.get("groups").at(idx).get("attributes").at(idx2).get("options").each(option => {
25571
+ var cloneOption = new Zakeke.OptionSelection();
25572
+ for (const key in option.attributes) {
25573
+ cloneOption.set(key, option.attributes[key]);
25574
+ }
25575
+ attribute.get('options').add(cloneOption);
25576
+ });
25577
+ idx2++;
25578
+ });
25579
+ idx++;
25580
+ });
25581
+ return clone;
25582
+ };
25583
+ this.reset = () => __awaiter(this, void 0, void 0, function* () {
25584
+ if (!this.initialSelection)
25585
+ return;
25586
+ // this.undoStack = [];
25587
+ // this.redoStack = [];
25588
+ this.selection = this.cloneSelection(this.initialSelection);
25589
+ this.selection.attachEvents();
25590
+ this.selection.on("attributeSelectionChanged", (e) => {
25591
+ this.handleAttributeSelectionChanged(e);
25592
+ });
25593
+ this.selection.on("attributeEnabled", (e) => {
25594
+ this.handleAttributeEnabled(e.attributeID);
25595
+ });
25596
+ this.selection.on("attributeDisabled", (e) => {
25597
+ this.handleAttributeDisabled(e.attributeID);
25598
+ });
25599
+ this.selection.on("attributeOptionEnabled", (e) => {
25600
+ this.handleAttributeOptionEnabled(e.attributeID, e.optionID);
25601
+ });
25602
+ this.selection.on("attributeOptionDisabled", (e) => {
25603
+ this.handleAttributeOptionDisabled(e.attributeID, e.optionID);
25604
+ });
25605
+ let script = this.selection.getAllAttributeTransformationScript();
25606
+ yield this.viewer.executeScriptAsync(script);
25607
+ this.buildStructure();
25608
+ this.updateComposition();
25609
+ this.updateRecapAndExtensionField();
25610
+ });
25312
25611
  this.handleAttributeSelectionChanged = (e) => __awaiter(this, void 0, void 0, function* () {
25313
25612
  yield this.viewer.executeActionsAsync(e.attributeID, e.selectedValue, e.actions);
25314
25613
  this.updateComposition();
@@ -25384,6 +25683,7 @@ class ZakekeEnvironment {
25384
25683
  }
25385
25684
  }
25386
25685
  }
25686
+ this.updateRecapAndExtensionField();
25387
25687
  };
25388
25688
  this.isOptionEnabled = (optionId) => {
25389
25689
  let enabled = false;
@@ -27865,6 +28165,7 @@ const createProviderValue = (state, dispatch) => {
27865
28165
  internalScene: state.environment.internalScene,
27866
28166
  internalCurrentTemplate: state.environment.internalCurrentTemplate,
27867
28167
  themeCompositions: state.environment.themeCompositions,
28168
+ currentAttributesSelection: state.environment.currentAttributesSelection,
27868
28169
  isSceneLoading: state.isSceneLoading,
27869
28170
  isAddToCartLoading: state.isAddToCartLoading,
27870
28171
  fonts: state.environment.fonts,
@@ -27888,6 +28189,7 @@ const createProviderValue = (state, dispatch) => {
27888
28189
  loadComposition: state.environment.loadComposition,
27889
28190
  getPDF: state.environment.getPDF.bind(state.environment),
27890
28191
  getOnlineScreenshot: state.environment.getOnlineScreenshot.bind(state.environment),
28192
+ reset: state.environment.reset.bind(state.environment),
27891
28193
  setCamera: state.environment.setCamera.bind(state.environment),
27892
28194
  setCameraByName: state.environment.setCameraByName.bind(state.environment),
27893
28195
  setCameraZoomEnabled: state.environment.setCameraZoomEnabled.bind(state.environment),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zakeke-configurator-react",
3
- "version": "0.0.111",
3
+ "version": "0.0.112",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/declarations/composer/Module/src/index.d.ts",