@babylonjs/gui-editor 5.51.0 → 5.53.0

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.
@@ -42086,6 +42086,20 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
42086
42086
  this._constraintDirection = ConstraintDirection.NONE;
42087
42087
  this.props.globalState.onPointerUpObservable.notifyObservers(null);
42088
42088
  };
42089
+ this._controlToLinkedMeshMap = new Map();
42090
+ this._observersMap = {
42091
+ onPointerDownObservable: new Map(),
42092
+ onPointerUpObservable: new Map(),
42093
+ onPointerMoveObservable: new Map(),
42094
+ onPointerEnterObservable: new Map(),
42095
+ onPointerOutObservable: new Map(),
42096
+ onPointerClickObservable: new Map(),
42097
+ onDisposeObservable: new Map(),
42098
+ onIsVisibleChangedObservable: new Map(),
42099
+ onBeforeDrawObservable: new Map(),
42100
+ onAfterDrawObservable: new Map(),
42101
+ onWheelObservable: new Map(),
42102
+ };
42089
42103
  const { globalState } = props;
42090
42104
  this._rootContainer = react__WEBPACK_IMPORTED_MODULE_1__.createRef();
42091
42105
  globalState.onSelectionChangedObservable.add(() => this.updateNodeOutlines());
@@ -42433,16 +42447,44 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
42433
42447
  _canClone() {
42434
42448
  return this.props.globalState.liveGuiTexture && this.props.globalState.guiTexture && this.trueRootContainer;
42435
42449
  }
42450
+ _saveObservables(root) {
42451
+ root.getDescendants().forEach((control) => {
42452
+ if (control.linkedMesh) {
42453
+ this._controlToLinkedMeshMap.set(control.metadata.editorUniqueId, control.linkedMesh);
42454
+ }
42455
+ Object.keys(this._observersMap).forEach((key) => {
42456
+ const observable = control[key];
42457
+ if (observable.hasObservers()) {
42458
+ this._observersMap[key].set(control.metadata.editorUniqueId, observable);
42459
+ }
42460
+ });
42461
+ });
42462
+ }
42463
+ _restoreObservables(root) {
42464
+ root.getDescendants().forEach((control) => {
42465
+ if (this._controlToLinkedMeshMap.has(control.metadata?.editorUniqueId)) {
42466
+ const linkedMesh = this._controlToLinkedMeshMap.get(control.metadata.editorUniqueId);
42467
+ if (linkedMesh) {
42468
+ control.linkWithMesh(linkedMesh);
42469
+ }
42470
+ }
42471
+ Object.keys(this._observersMap).forEach((key) => {
42472
+ const savedObservable = this._observersMap[key].get(control.metadata?.editorUniqueId);
42473
+ if (savedObservable) {
42474
+ control[key] = savedObservable;
42475
+ }
42476
+ });
42477
+ });
42478
+ this._controlToLinkedMeshMap.clear();
42479
+ Object.keys(this._observersMap).forEach((key) => {
42480
+ this._observersMap[key].clear();
42481
+ });
42482
+ }
42436
42483
  _copyEditorGUIToLiveGUI() {
42437
42484
  if (this._canClone()) {
42438
42485
  // Before cloning, save all of the live GUI controls that have a linked mesh
42439
- const controlToLinkedMesh = new Map();
42440
42486
  const liveRoot = this.props.globalState.liveGuiTexture.rootContainer;
42441
- liveRoot.getDescendants().forEach((control) => {
42442
- if (control.linkedMesh) {
42443
- controlToLinkedMesh.set(control.metadata.editorUniqueId, control.linkedMesh);
42444
- }
42445
- });
42487
+ this._saveObservables(liveRoot);
42446
42488
  liveRoot.clearControls();
42447
42489
  const originalToCloneMap = new Map();
42448
42490
  const updatedRootChildren = this.trueRootContainer.children.slice(0);
@@ -42452,14 +42494,7 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
42452
42494
  liveRoot.addControl(clone);
42453
42495
  }
42454
42496
  // Relink all meshes
42455
- liveRoot.getDescendants().forEach((control) => {
42456
- if (control.metadata && controlToLinkedMesh.has(control.metadata.editorUniqueId)) {
42457
- const linkedMesh = controlToLinkedMesh.get(control.metadata.editorUniqueId);
42458
- if (linkedMesh) {
42459
- control.linkWithMesh(linkedMesh);
42460
- }
42461
- }
42462
- });
42497
+ this._restoreObservables(liveRoot);
42463
42498
  this._syncConnectedLines(updatedRootChildren, originalToCloneMap);
42464
42499
  }
42465
42500
  }