@babylonjs/gui-editor 5.19.0 → 5.20.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.
@@ -51344,13 +51344,17 @@ class CommandBarComponent extends react__WEBPACK_IMPORTED_MODULE_2__.Component {
51344
51344
  props.globalState.onSelectionChangedObservable.add(() => {
51345
51345
  this.forceUpdate();
51346
51346
  });
51347
+ props.globalState.onWindowResizeObservable.add(() => {
51348
+ this.forceUpdate();
51349
+ });
51347
51350
  }
51348
51351
  render() {
51349
- const isPasteDisabled = this.props.globalState.workbench && this.props.globalState.selectedControls.length > 0 ? this.props.globalState.workbench.pasteDisabled : true;
51352
+ const isPasteDisabled = this.props.globalState.workbench ? this.props.globalState.workbench.pasteDisabled : true;
51350
51353
  const size = this.props.globalState.workbench ? Object.assign({}, this.props.globalState.workbench.guiSize) : { width: 0, height: 0 };
51351
51354
  const copyyIcon = this.props.globalState.selectedControls.length === 0 ? _imgs_buttonbar_copyIcon_disabled_svg__WEBPACK_IMPORTED_MODULE_22__ : _imgs_buttonbar_copyIcon_svg__WEBPACK_IMPORTED_MODULE_19__;
51352
51355
  const deleteeIcon = this.props.globalState.selectedControls.length === 0 ? _imgs_buttonBar_deleteIcon_disabled_svg__WEBPACK_IMPORTED_MODULE_24__ : _imgs_buttonBar_deleteIcon_svg__WEBPACK_IMPORTED_MODULE_21__;
51353
51356
  const pasteeIcon = isPasteDisabled ? _imgs_buttonbar_pasteIcon_disabled_svg__WEBPACK_IMPORTED_MODULE_23__ : _imgs_buttonbar_pasteIcon_svg__WEBPACK_IMPORTED_MODULE_20__;
51357
+ const responsiveUI = this.props.globalState.fromPG ? core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.ReadBoolean("responsiveUI", true) : core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.ReadBoolean("Responsive", true);
51354
51358
  this._sizeOption = _sizeValues.findIndex((value) => value.width == size.width && value.height == size.height);
51355
51359
  if (this._sizeOption < 0) {
51356
51360
  this.props.globalState.onResponsiveChangeObservable.notifyObservers(false);
@@ -51417,37 +51421,46 @@ class CommandBarComponent extends react__WEBPACK_IMPORTED_MODULE_2__.Component {
51417
51421
  } }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_commandButtonComponent__WEBPACK_IMPORTED_MODULE_7__.CommandButtonComponent, { tooltip: "Toggle Guides", shortcut: "G", icon: _imgs_guidesIcon_svg__WEBPACK_IMPORTED_MODULE_15__, isActive: this.props.globalState.outlines, onClick: () => (this.props.globalState.outlines = !this.props.globalState.outlines) })] })), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", Object.assign({ className: "divider padded" }, { children: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_colorLineComponent__WEBPACK_IMPORTED_MODULE_9__.ColorLineComponent, { lockObject: this._lockObject, label: "Artboard:", target: this.props.globalState, propertyName: "backgroundColor", disableAlpha: true }) })), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", Object.assign({ className: "divider padded" }, { children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_checkBoxLineComponent__WEBPACK_IMPORTED_MODULE_5__.CheckBoxLineComponent, { label: "Responsive:", iconLabel: "Responsive GUIs will resize the UI layout and reflow controls to accommodate different device screen sizes", isSelected: () => core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.ReadBoolean("Responsive", true), onSelect: (value) => {
51418
51422
  this.props.globalState.onResponsiveChangeObservable.notifyObservers(value);
51419
51423
  core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteBoolean("Responsive", value);
51424
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteBoolean("responsiveUI", value);
51420
51425
  this._sizeOption = _sizeOptions.length;
51421
51426
  if (value) {
51422
51427
  this._sizeOption = 0;
51423
51428
  this.props.globalState.workbench.guiSize = _sizeValues[this._sizeOption];
51429
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("width", this.props.globalState.workbench.guiSize.width);
51430
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("height", this.props.globalState.workbench.guiSize.height);
51424
51431
  }
51425
51432
  this.forceUpdate();
51426
- }, large: true }), core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.ReadBoolean("Responsive", true) && ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_optionsLineComponent__WEBPACK_IMPORTED_MODULE_6__.OptionsLineComponent, { label: "", iconLabel: "Size", options: _sizeOptions, target: this, propertyName: "_sizeOption", noDirectUpdate: true, onSelect: (value) => {
51433
+ }, large: true }), responsiveUI && ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_optionsLineComponent__WEBPACK_IMPORTED_MODULE_6__.OptionsLineComponent, { label: "", iconLabel: "Size", options: _sizeOptions, target: this, propertyName: "_sizeOption", noDirectUpdate: true, onSelect: (value) => {
51427
51434
  this._sizeOption = value;
51428
51435
  if (this._sizeOption !== _sizeOptions.length) {
51429
51436
  const newSize = _sizeValues[this._sizeOption];
51430
51437
  this.props.globalState.workbench.guiSize = newSize;
51438
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("width", this.props.globalState.workbench.guiSize.width);
51439
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("height", this.props.globalState.workbench.guiSize.height);
51431
51440
  }
51432
51441
  this.forceUpdate();
51433
- } })), !core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.ReadBoolean("Responsive", true) && ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, { children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_floatLineComponent__WEBPACK_IMPORTED_MODULE_4__.FloatLineComponent, { lockObject: this._lockObject, label: "W", target: size, propertyName: "width", min: 1, max: MAX_TEXTURE_SIZE, onChange: (newValue) => {
51442
+ } })), !responsiveUI && ((0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, { children: [(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_floatLineComponent__WEBPACK_IMPORTED_MODULE_4__.FloatLineComponent, { lockObject: this._lockObject, label: "W", target: size, propertyName: "width", min: 1, max: MAX_TEXTURE_SIZE, onChange: (newValue) => {
51434
51443
  if (!this._stopUpdating) {
51435
51444
  this.props.globalState.workbench.guiSize = { width: newValue, height: size.height };
51445
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("width", this.props.globalState.workbench.guiSize.width);
51436
51446
  }
51437
51447
  }, onDragStart: () => {
51438
51448
  this._stopUpdating = true;
51439
51449
  }, onDragStop: (newValue) => {
51440
51450
  this._stopUpdating = false;
51441
51451
  this.props.globalState.workbench.guiSize = { width: newValue, height: size.height };
51452
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("width", this.props.globalState.workbench.guiSize.width);
51442
51453
  }, arrows: true, isInteger: true }), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(shared_ui_components_lines_floatLineComponent__WEBPACK_IMPORTED_MODULE_4__.FloatLineComponent, { lockObject: this._lockObject, label: "H", target: size, propertyName: "height", min: 1, max: MAX_TEXTURE_SIZE, onChange: (newValue) => {
51443
51454
  if (!this._stopUpdating) {
51444
51455
  this.props.globalState.workbench.guiSize = { width: size.width, height: newValue };
51456
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("height", this.props.globalState.workbench.guiSize.width);
51445
51457
  }
51446
51458
  }, onDragStart: () => {
51447
51459
  this._stopUpdating = true;
51448
51460
  }, onDragStop: (newValue) => {
51449
51461
  this._stopUpdating = false;
51450
51462
  this.props.globalState.workbench.guiSize = { width: size.width, height: newValue };
51463
+ core_Misc_dataStorage__WEBPACK_IMPORTED_MODULE_1__.DataStorage.WriteNumber("height", this.props.globalState.workbench.guiSize.width);
51451
51464
  }, arrows: true, isInteger: true })] }))] }))] })), (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", Object.assign({ className: "commands-right" }, { children: (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("img", { src: _imgs_betaFlag_svg__WEBPACK_IMPORTED_MODULE_18__, className: "beta-flag", draggable: false }) }))] })));
51452
51465
  }
51453
51466
  }
@@ -55560,7 +55573,7 @@ __webpack_require__.r(__webpack_exports__);
55560
55573
  /* harmony import */ var _globalState__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../globalState */ "../../../tools/guiEditor/dist/globalState.js");
55561
55574
  /* harmony import */ var gui_2D_controls_control__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! gui/2D/valueAndUnit */ "gui/2D/controls/container");
55562
55575
  /* harmony import */ var gui_2D_controls_control__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(gui_2D_controls_control__WEBPACK_IMPORTED_MODULE_3__);
55563
- /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core/Misc/logger */ "core/Misc/observable");
55576
+ /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core/Misc/dataStorage */ "core/Misc/observable");
55564
55577
  /* harmony import */ var core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__);
55565
55578
  /* harmony import */ var _tools__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../tools */ "../../../tools/guiEditor/dist/tools.js");
55566
55579
  /* harmony import */ var _coordinateHelper__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./coordinateHelper */ "../../../tools/guiEditor/dist/diagram/coordinateHelper.js");
@@ -55586,6 +55599,7 @@ __webpack_require__.r(__webpack_exports__);
55586
55599
 
55587
55600
 
55588
55601
 
55602
+
55589
55603
 
55590
55604
  var ConstraintDirection;
55591
55605
  (function (ConstraintDirection) {
@@ -55596,6 +55610,7 @@ var ConstraintDirection;
55596
55610
  const ARROW_KEY_MOVEMENT_SMALL = 1; // px
55597
55611
  const ARROW_KEY_MOVEMENT_LARGE = 5; // px
55598
55612
  const MAX_POINTER_TRAVEL_DISTANCE = 5; //px^2. determines how far the pointer can move to be treated as a drag vs. a click
55613
+ const CONTROL_OFFSET = 10; //offset in pixels for when a control is added to editor
55599
55614
  class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
55600
55615
  constructor(props) {
55601
55616
  super(props);
@@ -55608,6 +55623,8 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
55608
55623
  this._controlsHit = [];
55609
55624
  this._pointerTravelDistance = 0;
55610
55625
  this._processSelectionOnUp = false;
55626
+ this._currLeft = 0;
55627
+ this._currTop = 0;
55611
55628
  this._nextLiveGuiRender = -1;
55612
55629
  this._liveGuiRerenderDelay = 30;
55613
55630
  this._defaultGUISize = { width: 1024, height: 1024 };
@@ -55799,6 +55816,8 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
55799
55816
  const obj = {};
55800
55817
  control.serialize(obj);
55801
55818
  controlList.push(obj);
55819
+ this._currLeft = control.leftInPixels;
55820
+ this._currTop = control.topInPixels;
55802
55821
  }
55803
55822
  copyFn(JSON.stringify({
55804
55823
  GUIClipboard: true,
@@ -55818,8 +55837,14 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
55818
55837
  for (const control of parsed.controls) {
55819
55838
  newSelection.push(gui_2D_controls_control__WEBPACK_IMPORTED_MODULE_3__.Control.Parse(control, this.props.globalState.guiTexture));
55820
55839
  }
55821
- (_a = this.props.globalState.selectedControls[0].parent) === null || _a === void 0 ? void 0 : _a.addControl(newSelection[0]);
55822
- this.props.globalState.setSelection(newSelection);
55840
+ if (((_a = newSelection[0].parent) === null || _a === void 0 ? void 0 : _a.typeName) != "StackPanel") {
55841
+ this._currLeft += CONTROL_OFFSET;
55842
+ this._currTop += CONTROL_OFFSET;
55843
+ }
55844
+ newSelection[0].leftInPixels = this._currLeft;
55845
+ newSelection[0].topInPixels = this._currTop;
55846
+ const newGuiNode = this.props.globalState.workbench.appendBlock(newSelection[0]);
55847
+ this.props.globalState.setSelection([newGuiNode]);
55823
55848
  return true;
55824
55849
  }
55825
55850
  }
@@ -56016,12 +56041,18 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
56016
56041
  }
56017
56042
  }
56018
56043
  appendBlock(guiElement) {
56044
+ var _a;
56019
56045
  if (this.props.globalState.liveGuiTexture) {
56020
56046
  this.props.globalState.liveGuiTexture.addControl(guiElement);
56021
56047
  }
56022
56048
  this.addEditorBehavior(guiElement);
56023
56049
  guiElement.getDescendants(true).forEach((desc) => this.addEditorBehavior(desc));
56024
- this.trueRootContainer.addControl(guiElement);
56050
+ if (this.props.globalState.selectedControls.length != 0) {
56051
+ (_a = this.props.globalState.selectedControls[0].parent) === null || _a === void 0 ? void 0 : _a.addControl(guiElement);
56052
+ }
56053
+ else {
56054
+ this.trueRootContainer.addControl(guiElement);
56055
+ }
56025
56056
  return guiElement;
56026
56057
  }
56027
56058
  parent(dropLocationControl) {
@@ -56289,7 +56320,7 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
56289
56320
  this._processSelectionOnUp = false;
56290
56321
  }
56291
56322
  }
56292
- createGUICanvas() {
56323
+ createGUICanvas(embed) {
56293
56324
  // Get the canvas element from the DOM.
56294
56325
  const canvas = this._rootContainer.current;
56295
56326
  // Associate a Babylon Engine to it.
@@ -56299,7 +56330,11 @@ class WorkbenchComponent extends react__WEBPACK_IMPORTED_MODULE_1__.Component {
56299
56330
  this._scene.clearColor = new core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__.Color4(0, 0, 0, 0);
56300
56331
  const light = new core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__.HemisphericLight("light1", core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__.Axis.Y, this._scene);
56301
56332
  light.intensity = 0.9;
56302
- this._guiSize = this._defaultGUISize;
56333
+ if (embed) {
56334
+ this.props.globalState.fromPG = true;
56335
+ this._guiSize.width = core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__.DataStorage.ReadNumber("width", 1024);
56336
+ this._guiSize.height = core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_4__.DataStorage.ReadNumber("height", 1024);
56337
+ }
56303
56338
  this._panAndZoomContainer = new gui_2D_controls_control__WEBPACK_IMPORTED_MODULE_3__.Container("panAndZoom");
56304
56339
  this._panAndZoomContainer.clipContent = false;
56305
56340
  this._panAndZoomContainer.clipChildren = false;
@@ -56656,6 +56691,12 @@ class GlobalState {
56656
56691
  get backgroundColor() {
56657
56692
  return this._backgroundColor;
56658
56693
  }
56694
+ get fromPG() {
56695
+ return this._fromPG;
56696
+ }
56697
+ set fromPG(value) {
56698
+ this._fromPG = value;
56699
+ }
56659
56700
  set backgroundColor(value) {
56660
56701
  this._backgroundColor = value;
56661
56702
  this.onBackgroundColorChangeObservable.notifyObservers();
@@ -56765,8 +56806,9 @@ class GUIEditor {
56765
56806
  /**
56766
56807
  * Show the gui editor
56767
56808
  * @param options defines the options to use to configure the gui editor
56809
+ * @param embed defines whether editor is being opened from the Playground
56768
56810
  */
56769
- static async Show(options) {
56811
+ static async Show(options, embed) {
56770
56812
  let hostElement = options.hostElement;
56771
56813
  // if we are in a standalone window and we have some current state, just load the GUI from the snippet server, don't do anything else
56772
56814
  if (this._CurrentState && hostElement) {
@@ -56803,7 +56845,7 @@ class GUIEditor {
56803
56845
  react_dom__WEBPACK_IMPORTED_MODULE_1__.render(graphEditor, hostElement);
56804
56846
  // create the middle workbench canvas
56805
56847
  if (!globalState.guiTexture) {
56806
- globalState.workbench.createGUICanvas();
56848
+ globalState.workbench.createGUICanvas(embed);
56807
56849
  if (options.currentSnippetToken) {
56808
56850
  try {
56809
56851
  await globalState.workbench.loadFromSnippet(options.currentSnippetToken);