x4js 1.5.29 → 1.5.31

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/lib/esm/index.mjs CHANGED
@@ -1976,6 +1976,17 @@ var _Component = class extends BaseComponent {
1976
1976
  append(content);
1977
1977
  }
1978
1978
  }
1979
+ removeChild(item) {
1980
+ if (this.m_props.content) {
1981
+ if (!isArray(this.m_props.content)) {
1982
+ this.m_props.content = [this.m_props.content];
1983
+ }
1984
+ this.m_props.content = this.m_props.content.filter((x) => x !== item);
1985
+ }
1986
+ if (this.dom && item.dom) {
1987
+ this.dom.removeChild(item.dom);
1988
+ }
1989
+ }
1979
1990
  /**
1980
1991
  *
1981
1992
  */
@@ -3542,7 +3553,7 @@ var Router = class extends EventSource {
3542
3553
  _getLocation() {
3543
3554
  return this.m_useHash ? "/" + x4document.location.hash.substring(1) : x4document.location.pathname;
3544
3555
  }
3545
- navigate(uri, notify = true) {
3556
+ navigate(uri, notify = true, replace = false) {
3546
3557
  if (!uri.startsWith("/")) {
3547
3558
  uri = "/" + uri;
3548
3559
  }
@@ -3553,10 +3564,13 @@ var Router = class extends EventSource {
3553
3564
  return;
3554
3565
  }
3555
3566
  if (this.m_useHash) {
3556
- while (uri.startsWith("/")) {
3567
+ while (uri.at(0) == "/") {
3557
3568
  uri = uri.substring(1);
3558
3569
  }
3559
- window.history.pushState({}, "", "#" + uri);
3570
+ uri = "#" + uri;
3571
+ }
3572
+ if (replace) {
3573
+ window.history.replaceState({}, "", uri);
3560
3574
  } else {
3561
3575
  window.history.pushState({}, "", uri);
3562
3576
  }
@@ -5316,11 +5330,138 @@ var PopupListView = class extends Popup {
5316
5330
  };
5317
5331
  __name(PopupListView, "PopupListView");
5318
5332
 
5333
+ // src/tooltips.ts
5334
+ var tipTmo;
5335
+ var tooltip;
5336
+ var Tooltip = class extends Component {
5337
+ m_text;
5338
+ set text(text) {
5339
+ this.m_text.text = text;
5340
+ }
5341
+ /** @ignore */
5342
+ render() {
5343
+ this.setClass("@non-maskable", true);
5344
+ this.setContent([
5345
+ new Icon({ icon: "var( --x4-icon-tip )" }),
5346
+ this.m_text = new Label({ text: "help" })
5347
+ ]);
5348
+ }
5349
+ /**
5350
+ * display the menu at a specific position
5351
+ * @param x
5352
+ * @param y
5353
+ */
5354
+ displayAt(x, y, align = "top left") {
5355
+ this.show();
5356
+ let halign = "l", valign = "t";
5357
+ if (align.indexOf("right") >= 0) {
5358
+ halign = "r";
5359
+ }
5360
+ if (align.indexOf("bottom") >= 0) {
5361
+ valign = "b";
5362
+ }
5363
+ let rc = x4document.body.getBoundingClientRect(), rm = this.getBoundingRect();
5364
+ if (halign == "r") {
5365
+ x -= rm.width;
5366
+ }
5367
+ if (valign == "b") {
5368
+ y -= rm.height;
5369
+ }
5370
+ if (x + rm.width > rc.right) {
5371
+ x = rc.right - rm.width;
5372
+ }
5373
+ if (y + rm.height > rc.bottom) {
5374
+ y = rc.bottom - rm.height - 17;
5375
+ }
5376
+ this.setStyle({ left: x, top: y });
5377
+ }
5378
+ };
5379
+ __name(Tooltip, "Tooltip");
5380
+ function initTooltips(cb) {
5381
+ if (isTouchDevice()) {
5382
+ return;
5383
+ }
5384
+ let tipTarget = {
5385
+ target: null,
5386
+ x: 0,
5387
+ y: 0
5388
+ };
5389
+ function handle_mpos(event) {
5390
+ tipTarget.x = event.pageX;
5391
+ tipTarget.y = event.pageY;
5392
+ }
5393
+ __name(handle_mpos, "handle_mpos");
5394
+ function handle_mouse(event) {
5395
+ let target = event.target;
5396
+ let tip = null;
5397
+ tipTarget.x = event.pageX + 10;
5398
+ tipTarget.y = event.pageY + 15;
5399
+ while (target) {
5400
+ tip = target.getAttribute("tip");
5401
+ if (tip) {
5402
+ break;
5403
+ }
5404
+ target = target.parentElement;
5405
+ }
5406
+ if (target == tipTarget.target || tooltip && target == tooltip.dom) {
5407
+ return;
5408
+ }
5409
+ if (!target || !tip) {
5410
+ tipTarget.target = null;
5411
+ if (cb) {
5412
+ cb(null);
5413
+ } else {
5414
+ _hideTip();
5415
+ }
5416
+ return;
5417
+ }
5418
+ tipTarget.target = target;
5419
+ if (cb) {
5420
+ cb(null);
5421
+ } else {
5422
+ _hideTip();
5423
+ }
5424
+ if (cb) {
5425
+ cb(tip);
5426
+ } else {
5427
+ tipTmo = setTimeout(() => {
5428
+ if (tooltip === void 0) {
5429
+ tooltip = new Tooltip({});
5430
+ x4document.body.appendChild(tooltip._build());
5431
+ }
5432
+ tooltip.text = tip;
5433
+ tooltip.displayAt(tipTarget.x + 17, tipTarget.y + 17, "top left");
5434
+ }, 700);
5435
+ }
5436
+ }
5437
+ __name(handle_mouse, "handle_mouse");
5438
+ function _hideTip() {
5439
+ if (tipTmo) {
5440
+ clearTimeout(tipTmo);
5441
+ }
5442
+ if (tooltip) {
5443
+ tooltip.hide();
5444
+ }
5445
+ }
5446
+ __name(_hideTip, "_hideTip");
5447
+ x4document.body.addEventListener("mouseover", handle_mouse);
5448
+ x4document.body.addEventListener("mouseout", handle_mouse);
5449
+ x4document.body.addEventListener("mousemove", handle_mpos);
5450
+ }
5451
+ __name(initTooltips, "initTooltips");
5452
+
5319
5453
  // src/input.ts
5320
5454
  var Input = class extends Component {
5455
+ m_error_tip;
5321
5456
  constructor(props) {
5322
5457
  super(props);
5323
5458
  }
5459
+ componentDisposed() {
5460
+ if (this.m_error_tip) {
5461
+ this.m_error_tip.dispose();
5462
+ }
5463
+ super.componentDisposed();
5464
+ }
5324
5465
  /** @ignore */
5325
5466
  render(props) {
5326
5467
  this.setTag("input");
@@ -5350,6 +5491,22 @@ var Input = class extends Component {
5350
5491
  });
5351
5492
  }
5352
5493
  }
5494
+ showError(text) {
5495
+ if (!this.m_error_tip) {
5496
+ this.m_error_tip = new Tooltip({ cls: "error" });
5497
+ x4document.body.appendChild(this.m_error_tip._build());
5498
+ }
5499
+ let rc = this.getBoundingRect();
5500
+ this.m_error_tip.text = text;
5501
+ this.m_error_tip.displayAt(rc.right, rc.top - 8, "top right");
5502
+ this.addClass("@error");
5503
+ }
5504
+ clearError() {
5505
+ if (this.m_error_tip) {
5506
+ this.m_error_tip.hide();
5507
+ this.removeClass("@error");
5508
+ }
5509
+ }
5353
5510
  getType() {
5354
5511
  return this.m_props.type;
5355
5512
  }
@@ -5357,6 +5514,9 @@ var Input = class extends Component {
5357
5514
  * return the current editor value
5358
5515
  */
5359
5516
  get value() {
5517
+ return this.getValue();
5518
+ }
5519
+ getValue() {
5360
5520
  if (this.dom) {
5361
5521
  this.m_props.value = this.dom.value;
5362
5522
  }
@@ -5374,6 +5534,9 @@ var Input = class extends Component {
5374
5534
  * @param value - new value to set
5375
5535
  */
5376
5536
  set value(value) {
5537
+ this.setValue(value);
5538
+ }
5539
+ setValue(value) {
5377
5540
  this.m_props.value = value;
5378
5541
  if (this.dom) {
5379
5542
  this.dom.value = value;
@@ -5413,6 +5576,7 @@ var Input = class extends Component {
5413
5576
  }
5414
5577
  }
5415
5578
  setStoreValue(v) {
5579
+ this.clearError();
5416
5580
  if (this.m_props.value_hook) {
5417
5581
  return this.m_props.value_hook.set(v);
5418
5582
  } else {
@@ -5879,132 +6043,11 @@ var PopupCalendar = class extends Popup {
5879
6043
  };
5880
6044
  __name(PopupCalendar, "PopupCalendar");
5881
6045
 
5882
- // src/tooltips.ts
5883
- var tipTmo;
5884
- var tooltip;
5885
- var Tooltip = class extends Component {
5886
- m_text;
5887
- set text(text) {
5888
- this.m_text.text = text;
5889
- }
5890
- /** @ignore */
5891
- render() {
5892
- this.setClass("@non-maskable", true);
5893
- this.setContent([
5894
- new Icon({ icon: "var( --x4-icon-tip )" }),
5895
- this.m_text = new Label({ text: "help" })
5896
- ]);
5897
- }
5898
- /**
5899
- * display the menu at a specific position
5900
- * @param x
5901
- * @param y
5902
- */
5903
- displayAt(x, y, align = "top left") {
5904
- this.show();
5905
- let halign = "l", valign = "t";
5906
- if (align.indexOf("right") >= 0) {
5907
- halign = "r";
5908
- }
5909
- if (align.indexOf("bottom") >= 0) {
5910
- valign = "b";
5911
- }
5912
- let rc = x4document.body.getBoundingClientRect(), rm = this.getBoundingRect();
5913
- if (halign == "r") {
5914
- x -= rm.width;
5915
- }
5916
- if (valign == "b") {
5917
- y -= rm.height;
5918
- }
5919
- if (x + rm.width > rc.right) {
5920
- x = rc.right - rm.width;
5921
- }
5922
- if (y + rm.height > rc.bottom) {
5923
- y = rc.bottom - rm.height - 17;
5924
- }
5925
- this.setStyle({ left: x, top: y });
5926
- }
5927
- };
5928
- __name(Tooltip, "Tooltip");
5929
- function initTooltips(cb) {
5930
- if (isTouchDevice()) {
5931
- return;
5932
- }
5933
- let tipTarget = {
5934
- target: null,
5935
- x: 0,
5936
- y: 0
5937
- };
5938
- function handle_mpos(event) {
5939
- tipTarget.x = event.pageX;
5940
- tipTarget.y = event.pageY;
5941
- }
5942
- __name(handle_mpos, "handle_mpos");
5943
- function handle_mouse(event) {
5944
- let target = event.target;
5945
- let tip = null;
5946
- tipTarget.x = event.pageX + 10;
5947
- tipTarget.y = event.pageY + 15;
5948
- while (target) {
5949
- tip = target.getAttribute("tip");
5950
- if (tip) {
5951
- break;
5952
- }
5953
- target = target.parentElement;
5954
- }
5955
- if (target == tipTarget.target || tooltip && target == tooltip.dom) {
5956
- return;
5957
- }
5958
- if (!target || !tip) {
5959
- tipTarget.target = null;
5960
- if (cb) {
5961
- cb(null);
5962
- } else {
5963
- _hideTip();
5964
- }
5965
- return;
5966
- }
5967
- tipTarget.target = target;
5968
- if (cb) {
5969
- cb(null);
5970
- } else {
5971
- _hideTip();
5972
- }
5973
- if (cb) {
5974
- cb(tip);
5975
- } else {
5976
- tipTmo = setTimeout(() => {
5977
- if (tooltip === void 0) {
5978
- tooltip = new Tooltip({});
5979
- x4document.body.appendChild(tooltip._build());
5980
- }
5981
- tooltip.text = tip;
5982
- tooltip.displayAt(tipTarget.x + 17, tipTarget.y + 17, "top left");
5983
- }, 700);
5984
- }
5985
- }
5986
- __name(handle_mouse, "handle_mouse");
5987
- function _hideTip() {
5988
- if (tipTmo) {
5989
- clearTimeout(tipTmo);
5990
- }
5991
- if (tooltip) {
5992
- tooltip.hide();
5993
- }
5994
- }
5995
- __name(_hideTip, "_hideTip");
5996
- x4document.body.addEventListener("mouseover", handle_mouse);
5997
- x4document.body.addEventListener("mouseout", handle_mouse);
5998
- x4document.body.addEventListener("mousemove", handle_mpos);
5999
- }
6000
- __name(initTooltips, "initTooltips");
6001
-
6002
6046
  // src/textedit.ts
6003
6047
  var reEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
6004
6048
  var TextEdit = class extends Component {
6005
6049
  m_cal_popup;
6006
6050
  m_ui_input;
6007
- m_error_tip;
6008
6051
  constructor(props) {
6009
6052
  super(props);
6010
6053
  this.addClass("@hlayout");
@@ -6016,12 +6059,6 @@ var TextEdit = class extends Component {
6016
6059
  this.focus();
6017
6060
  }
6018
6061
  }
6019
- componentDisposed() {
6020
- if (this.m_error_tip) {
6021
- this.m_error_tip.dispose();
6022
- }
6023
- super.componentDisposed();
6024
- }
6025
6062
  focus() {
6026
6063
  this.m_ui_input.focus();
6027
6064
  }
@@ -6173,29 +6210,28 @@ var TextEdit = class extends Component {
6173
6210
  }
6174
6211
  }
6175
6212
  showError(text) {
6176
- if (!this.m_error_tip) {
6177
- this.m_error_tip = new Tooltip({ cls: "error" });
6178
- x4document.body.appendChild(this.m_error_tip._build());
6179
- }
6180
- let rc = this.m_ui_input.getBoundingRect();
6181
- this.m_error_tip.text = text;
6182
- this.m_error_tip.displayAt(rc.right, rc.top - 8, "top right");
6183
- this.addClass("@error");
6213
+ this.m_ui_input.showError(text);
6184
6214
  }
6185
6215
  clearError() {
6186
- if (this.m_error_tip) {
6187
- this.m_error_tip.hide();
6188
- this.removeClass("@error");
6189
- }
6216
+ this.m_ui_input.clearError();
6190
6217
  }
6191
6218
  get value() {
6219
+ return this.getValue();
6220
+ }
6221
+ getValue() {
6192
6222
  if (this.m_ui_input) {
6193
6223
  return this.m_ui_input.value;
6194
6224
  } else {
6195
6225
  return this.m_props.value;
6196
6226
  }
6197
6227
  }
6228
+ /**
6229
+ *
6230
+ */
6198
6231
  set value(value) {
6232
+ this.setValue(value);
6233
+ }
6234
+ setValue(value) {
6199
6235
  if (this.m_ui_input) {
6200
6236
  this.m_ui_input.value = value;
6201
6237
  } else {
@@ -6411,8 +6447,12 @@ var AutoComplete = class extends TextEdit {
6411
6447
  }
6412
6448
  super.componentDisposed();
6413
6449
  }
6414
- showPopup() {
6415
- this._onChange();
6450
+ showPopup(show = true) {
6451
+ if (show) {
6452
+ this._onChange();
6453
+ } else {
6454
+ this._hidePopup();
6455
+ }
6416
6456
  }
6417
6457
  /**
6418
6458
  * display the popup
@@ -6445,7 +6485,8 @@ var AutoComplete = class extends TextEdit {
6445
6485
  style: {
6446
6486
  fontFamily,
6447
6487
  fontSize
6448
- }
6488
+ },
6489
+ renderItem: props.renderItem
6449
6490
  });
6450
6491
  }
6451
6492
  if (items) {
@@ -6490,6 +6531,9 @@ var AutoComplete = class extends TextEdit {
6490
6531
  }
6491
6532
  this.m_needval = true;
6492
6533
  }
6534
+ isPopupVisible() {
6535
+ return this.m_popvis;
6536
+ }
6493
6537
  };
6494
6538
  __name(AutoComplete, "AutoComplete");
6495
6539
 
@@ -7822,7 +7866,7 @@ var data;
7822
7866
  data2.calc = calc;
7823
7867
  __name(calc, "calc");
7824
7868
  function array(ctor, props) {
7825
- return data2.field({ ...props, type: "array", model: new ctor() });
7869
+ return data2.field({ ...props, type: "array", model: ctor ? new ctor() : null });
7826
7870
  }
7827
7871
  data2.array = array;
7828
7872
  __name(array, "array");
@@ -8599,7 +8643,6 @@ var ComboBox = class extends HLayout {
8599
8643
  m_lockchg;
8600
8644
  m_popvis;
8601
8645
  m_selection;
8602
- m_error_tip;
8603
8646
  constructor(props) {
8604
8647
  super(props);
8605
8648
  if (!props.editable) {
@@ -8725,9 +8768,6 @@ var ComboBox = class extends HLayout {
8725
8768
  }
8726
8769
  }
8727
8770
  componentDisposed() {
8728
- if (this.m_error_tip) {
8729
- this.m_error_tip.dispose();
8730
- }
8731
8771
  if (this.m_popup) {
8732
8772
  this.m_popup.close();
8733
8773
  }
@@ -8795,20 +8835,10 @@ var ComboBox = class extends HLayout {
8795
8835
  return true;
8796
8836
  }
8797
8837
  showError(text) {
8798
- if (!this.m_error_tip) {
8799
- this.m_error_tip = new Tooltip({ cls: "error" });
8800
- x4document.body.appendChild(this.m_error_tip._build());
8801
- }
8802
- let rc = this.m_ui_input.getBoundingRect();
8803
- this.m_error_tip.text = text;
8804
- this.m_error_tip.displayAt(rc.right, rc.top - 8, "top right");
8805
- this.addClass("@error");
8838
+ this.m_ui_input.showError(text);
8806
8839
  }
8807
8840
  clearError() {
8808
- if (this.m_error_tip) {
8809
- this.m_error_tip.hide();
8810
- this.removeClass("@error");
8811
- }
8841
+ this.m_ui_input.clearError();
8812
8842
  }
8813
8843
  /** @ignore
8814
8844
  */
@@ -15658,7 +15688,7 @@ function setupWSMessaging(closeCB) {
15658
15688
  __name(setupWSMessaging, "setupWSMessaging");
15659
15689
 
15660
15690
  // src/version.ts
15661
- var x4js_version = "1.5.29";
15691
+ var x4js_version = "1.5.31";
15662
15692
  export {
15663
15693
  AbsLayout,
15664
15694
  Application,