@zeedhi/common 1.48.0 → 1.50.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.
@@ -1794,16 +1794,17 @@ class Input extends ComponentRender {
1794
1794
  set displayValue(value) {
1795
1795
  if (this.internalDisplayValue !== value) {
1796
1796
  this.internalValue = this.parser(value);
1797
+ this.value = this.internalValue; // forces value accessor to be called if necessary
1797
1798
  let { mask } = this;
1798
1799
  if (mask) {
1799
1800
  if (typeof mask === 'function') {
1800
1801
  mask = mask(this.internalValue);
1801
1802
  }
1802
- this.internalDisplayValue = Mask.convertAll(mask, value);
1803
+ this.internalDisplayValue = Mask.convertAll(mask, this.internalValue);
1803
1804
  this.internalValue = this.parser(this.internalDisplayValue);
1804
1805
  }
1805
1806
  else {
1806
- this.internalDisplayValue = value;
1807
+ this.internalDisplayValue = this.internalValue;
1807
1808
  }
1808
1809
  }
1809
1810
  }
@@ -2812,6 +2813,16 @@ class ModalService {
2812
2813
  return this.create(modal);
2813
2814
  });
2814
2815
  }
2816
+ /**
2817
+ * Creates a new modal instance from JSON
2818
+ * @param modal modal structure
2819
+ */
2820
+ static createFromJsonPost(modalPath, params) {
2821
+ return __awaiter(this, void 0, void 0, function* () {
2822
+ const modal = yield Metadata.post(modalPath, params);
2823
+ return this.create(modal);
2824
+ });
2825
+ }
2815
2826
  /**
2816
2827
  * Deletes modal
2817
2828
  * @param modal modal instance
@@ -3102,7 +3113,7 @@ class Dashboard extends ComponentRender {
3102
3113
  ];
3103
3114
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3104
3115
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3105
- this.cards = props.cards || this.cards;
3116
+ this.cards = this.getInitValue('cards', props.cards, this.cards);
3106
3117
  this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3107
3118
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3108
3119
  this.height = this.getInitValue('height', props.height, this.height);
@@ -3130,13 +3141,7 @@ class Dashboard extends ComponentRender {
3130
3141
  addCard() {
3131
3142
  const addCardForm = Metadata.getInstance('addCardForm');
3132
3143
  if (addCardForm.validate()) {
3133
- const newCard = {
3134
- cardId: this.getCardId(),
3135
- path: addCardForm.value.inputPath,
3136
- local: addCardForm.value.inputLocal,
3137
- height: addCardForm.value.inputHeight,
3138
- width: addCardForm.value.inputWidth,
3139
- };
3144
+ const newCard = Object.assign({ cardId: this.getCardId(), path: addCardForm.value.inputPath, local: addCardForm.value.inputLocal, height: addCardForm.value.inputHeight, width: addCardForm.value.inputWidth }, addCardForm.value);
3140
3145
  this.cards.push(newCard);
3141
3146
  this.modalCancelClick();
3142
3147
  }
@@ -3428,6 +3433,7 @@ class Date$1 extends TextInput {
3428
3433
  this.dateError = false;
3429
3434
  this.internalDisplayValue = newValue;
3430
3435
  this.internalValue = this.parser(newValue);
3436
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3431
3437
  }
3432
3438
  /**
3433
3439
  * Assign the updated mask to mask property
@@ -3467,6 +3473,7 @@ class Date$1 extends TextInput {
3467
3473
  }
3468
3474
  this.dateError = !!displayValue;
3469
3475
  }
3476
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3470
3477
  }
3471
3478
  isValidDate(value, format, strict = true) {
3472
3479
  return dayjs(value, format, strict).isValid();
@@ -3773,6 +3780,7 @@ class DateRange extends TextInput {
3773
3780
  this.internalValue = this.parser(newValue);
3774
3781
  else
3775
3782
  this.internalValue = [];
3783
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3776
3784
  }
3777
3785
  /**
3778
3786
  * Assign the updated mask to mask property
@@ -3813,6 +3821,7 @@ class DateRange extends TextInput {
3813
3821
  }
3814
3822
  this.dateError = !!displayValue;
3815
3823
  }
3824
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3816
3825
  }
3817
3826
  isValidDateArray(format, values) {
3818
3827
  if (!values || values.length === 0)
@@ -4412,14 +4421,17 @@ class Frame extends ComponentRender {
4412
4421
  this.local = false;
4413
4422
  this.metadata = {};
4414
4423
  this.override = {};
4424
+ this.params = {};
4415
4425
  this.overrideNamedProps = {};
4426
+ this.path = '';
4416
4427
  this.cache = false;
4417
4428
  this.cacheDuration = 2 * 60 * 60 * 1000;
4418
4429
  this.height = 'auto';
4419
4430
  this.maxHeight = 'none';
4420
4431
  this.minHeight = 'none';
4432
+ this.type = 'get';
4421
4433
  this.headerName = 'sw-fetched-on';
4422
- this.path = props.path;
4434
+ this.path = this.getInitValue('path', props.path, this.path);
4423
4435
  this.local = props.local === true;
4424
4436
  this.override = props.override || this.override;
4425
4437
  this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
@@ -4428,6 +4440,8 @@ class Frame extends ComponentRender {
4428
4440
  this.height = this.getInitValue('height', props.height, this.height);
4429
4441
  this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
4430
4442
  this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
4443
+ this.type = this.getInitValue('type', props.type, this.type);
4444
+ this.params = this.getInitValue('params', props.params, this.params);
4431
4445
  this.createAccessors();
4432
4446
  this.getMetadata();
4433
4447
  }
@@ -4468,6 +4482,9 @@ class Frame extends ComponentRender {
4468
4482
  requestPage() {
4469
4483
  return __awaiter(this, void 0, void 0, function* () {
4470
4484
  if (!this.cache) {
4485
+ if (this.type === 'post') {
4486
+ return Metadata.post(this.path, this.params);
4487
+ }
4471
4488
  return Metadata.get(this.path, this.local);
4472
4489
  }
4473
4490
  const url = Metadata.getMetadataUrl(this.path, this.local);
@@ -9047,7 +9064,9 @@ class TreeDataStructure {
9047
9064
  originalData.splice(index + 1, 0, ...data);
9048
9065
  this.originalDatasource.data = originalData;
9049
9066
  this.originalDatasource.currentRow = this.clearRow(row);
9067
+ return data;
9050
9068
  }
9069
+ return undefined;
9051
9070
  });
9052
9071
  }
9053
9072
  /**
@@ -9235,6 +9254,10 @@ class SelectTree extends TextInput {
9235
9254
  */
9236
9255
  this.lazyLoad = true;
9237
9256
  this.selectValue = null;
9257
+ /**
9258
+ * Uses delayed loading to load tree branches
9259
+ */
9260
+ this.fetchOnDemand = false;
9238
9261
  this.nodes = this.getInitValue('nodes', props.nodes, this.nodes);
9239
9262
  this.alwaysOpen = this.getInitValue('alwaysOpen', props.alwaysOpen, this.alwaysOpen);
9240
9263
  this.flattenSearchResults = this.getInitValue('flattenSearchResults', props.flattenSearchResults, this.flattenSearchResults);
@@ -9253,6 +9276,7 @@ class SelectTree extends TextInput {
9253
9276
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
9254
9277
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
9255
9278
  this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
9279
+ this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
9256
9280
  if (props.datasource && Object.keys(props.datasource).length) {
9257
9281
  this.lazyLoad = props.datasource.lazyLoad !== false;
9258
9282
  const searchFields = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
@@ -9289,7 +9313,7 @@ class SelectTree extends TextInput {
9289
9313
  datasource: this.datasource,
9290
9314
  parentField: this.parentField,
9291
9315
  openLevelOnLoad: false,
9292
- fetchOnDemand: false,
9316
+ fetchOnDemand: this.fetchOnDemand,
9293
9317
  });
9294
9318
  if (!this.lazyLoad) {
9295
9319
  this.datasource.get().then(() => { this.createNodesFromDatasource(false); });
@@ -9309,7 +9333,16 @@ class SelectTree extends TextInput {
9309
9333
  }
9310
9334
  }
9311
9335
  createNodeFromRow(row) {
9312
- const children = this.createChildrenNodes(row.tree__children);
9336
+ let children;
9337
+ if (this.fetchOnDemand) {
9338
+ children = null;
9339
+ }
9340
+ else {
9341
+ children = this.createChildrenNodes(row.tree__children);
9342
+ if (!children.length) {
9343
+ children = undefined;
9344
+ }
9345
+ }
9313
9346
  const dataTextArr = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
9314
9347
  const dataTextNames = [];
9315
9348
  const masks = [];
@@ -9344,15 +9377,18 @@ class SelectTree extends TextInput {
9344
9377
  return {
9345
9378
  id: row[this.dataValue],
9346
9379
  label: dataText,
9347
- children: children.length ? children : undefined,
9380
+ children,
9348
9381
  row,
9349
9382
  };
9350
9383
  }
9351
9384
  createChildrenNodes(rows) {
9352
9385
  const newNodes = [];
9353
9386
  rows.forEach((row) => {
9354
- const newNode = this.createNodeFromRow(row);
9355
- newNodes.push(newNode);
9387
+ if (Object.keys(row).length > 0) {
9388
+ const newNode = this.createNodeFromRow(row);
9389
+ row.tree__node = newNode;
9390
+ newNodes.push(newNode);
9391
+ }
9356
9392
  });
9357
9393
  return newNodes;
9358
9394
  }
@@ -9388,7 +9424,7 @@ class SelectTree extends TextInput {
9388
9424
  return this.disabledItems.indexOf(node.id) !== -1;
9389
9425
  }
9390
9426
  getDisabledNodes(nodes) {
9391
- return nodes.map((node) => (Object.assign(Object.assign({}, node), { isDisabled: this.isDisable(node), children: node.children ? this.getDisabledNodes(node.children) : undefined })));
9427
+ return nodes.map((node) => (Object.assign(Object.assign({}, node), { isDisabled: this.isDisable(node), children: node.children ? this.getDisabledNodes(node.children) : node.children })));
9392
9428
  }
9393
9429
  getNodes() {
9394
9430
  return this.getDisabledNodes(this.nodes);
@@ -9455,6 +9491,22 @@ class SelectTree extends TextInput {
9455
9491
  }
9456
9492
  this.selectValue = val;
9457
9493
  }
9494
+ loadChildren(parentNode) {
9495
+ return __awaiter(this, void 0, void 0, function* () {
9496
+ return this.treeDataStructure.toggleExpand(parentNode.row).then((data) => {
9497
+ const node = parentNode.row.tree__node;
9498
+ if (node) {
9499
+ if (!data || data.length === 0) {
9500
+ node.children = undefined;
9501
+ }
9502
+ else {
9503
+ const nodes = this.createChildrenNodes(data);
9504
+ node.children = nodes;
9505
+ }
9506
+ }
9507
+ });
9508
+ });
9509
+ }
9458
9510
  }
9459
9511
 
9460
9512
  /**
@@ -10527,6 +10579,10 @@ class Tree extends ComponentRender {
10527
10579
  children: [],
10528
10580
  };
10529
10581
  newNode = merge(newNode, node, override);
10582
+ if (typeof node.isLeaf === 'undefined') {
10583
+ const hasChildren = newNode.children.length > 0;
10584
+ newNode.isLeaf = !hasChildren;
10585
+ }
10530
10586
  newNode.children = this.initNodes(node.children || [], override);
10531
10587
  return newNode;
10532
10588
  });
@@ -10601,6 +10657,7 @@ class Tree extends ComponentRender {
10601
10657
  insertNode(newNode) {
10602
10658
  const initNode = this.initNodes([newNode])[0];
10603
10659
  if (this.selectedNodes.length) {
10660
+ this.updateNodeData(this.selectedNodes[0], { isLeaf: false });
10604
10661
  const cursorPosition = {
10605
10662
  node: this.selectedNodes[0],
10606
10663
  placement: 'inside',
@@ -10611,31 +10668,44 @@ class Tree extends ComponentRender {
10611
10668
  this.nodes.push(initNode);
10612
10669
  }
10613
10670
  }
10671
+ /** Import multiples nodes by the current cursor position */
10614
10672
  importNodes(nodes) {
10615
10673
  if (this.selectedNodes.length) {
10616
- const cursorPosition = {
10617
- node: this.selectedNodes[0],
10618
- placement: 'inside',
10619
- };
10620
10674
  nodes.reverse().forEach((node) => {
10621
- this.tree.insert(cursorPosition, node);
10675
+ this.insertNode(node);
10622
10676
  });
10623
10677
  }
10624
10678
  else {
10625
10679
  nodes.forEach((node) => {
10626
- this.nodes.push(node);
10680
+ this.insertNode(node);
10627
10681
  });
10628
10682
  }
10629
10683
  }
10630
10684
  /** Remove selected node */
10631
10685
  removeSelected() {
10686
+ const parentNodesPath = [];
10632
10687
  if (this.selectedNodes.length) {
10633
- const selectedPaths = this.selectedNodes.map((item) => item.path);
10688
+ const selectedPaths = this.selectedNodes.map((item) => {
10689
+ const parent = this.getParentNode(item);
10690
+ if (parent) {
10691
+ parentNodesPath.push(parent.path);
10692
+ }
10693
+ return item.path;
10694
+ });
10634
10695
  this.tree.remove(selectedPaths);
10696
+ parentNodesPath.forEach((path) => {
10697
+ const parent = this.getNode(path);
10698
+ if (parent && parent.children && parent.children.length === 0) {
10699
+ this.tree.updateNode(path, { isLeaf: true });
10700
+ }
10701
+ });
10635
10702
  }
10636
10703
  }
10637
10704
  /** Update selected node */
10638
10705
  updateNodeData(node, value) {
10706
+ if (node.children && node.children.length === 0) {
10707
+ this.tree.updateNode(node.path, { isLeaf: true });
10708
+ }
10639
10709
  this.tree.updateNode(node.path, value);
10640
10710
  }
10641
10711
  setTree(tree) {
@@ -10768,8 +10838,11 @@ class Tree extends ComponentRender {
10768
10838
  return this.searchPath(this.nodes, path);
10769
10839
  }
10770
10840
  getParentNode(node) {
10771
- var _a;
10772
- return this.tree.getNode(((_a = node.path) === null || _a === void 0 ? void 0 : _a.slice(0, -1)) || []);
10841
+ const hasParent = Array.isArray(node.path) && node.path.length > 1;
10842
+ if (hasParent) {
10843
+ return this.tree.getNode(node.path.slice(0, -1));
10844
+ }
10845
+ return undefined;
10773
10846
  }
10774
10847
  searchPath(nodes, path) {
10775
10848
  const currentNode = (path[0] > -1 && path[0] < nodes.length) ? nodes[path[0]] : undefined;
@@ -1801,16 +1801,17 @@
1801
1801
  set displayValue(value) {
1802
1802
  if (this.internalDisplayValue !== value) {
1803
1803
  this.internalValue = this.parser(value);
1804
+ this.value = this.internalValue; // forces value accessor to be called if necessary
1804
1805
  let { mask } = this;
1805
1806
  if (mask) {
1806
1807
  if (typeof mask === 'function') {
1807
1808
  mask = mask(this.internalValue);
1808
1809
  }
1809
- this.internalDisplayValue = core.Mask.convertAll(mask, value);
1810
+ this.internalDisplayValue = core.Mask.convertAll(mask, this.internalValue);
1810
1811
  this.internalValue = this.parser(this.internalDisplayValue);
1811
1812
  }
1812
1813
  else {
1813
- this.internalDisplayValue = value;
1814
+ this.internalDisplayValue = this.internalValue;
1814
1815
  }
1815
1816
  }
1816
1817
  }
@@ -2819,6 +2820,16 @@
2819
2820
  return this.create(modal);
2820
2821
  });
2821
2822
  }
2823
+ /**
2824
+ * Creates a new modal instance from JSON
2825
+ * @param modal modal structure
2826
+ */
2827
+ static createFromJsonPost(modalPath, params) {
2828
+ return __awaiter(this, void 0, void 0, function* () {
2829
+ const modal = yield core.Metadata.post(modalPath, params);
2830
+ return this.create(modal);
2831
+ });
2832
+ }
2822
2833
  /**
2823
2834
  * Deletes modal
2824
2835
  * @param modal modal instance
@@ -3109,7 +3120,7 @@
3109
3120
  ];
3110
3121
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3111
3122
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3112
- this.cards = props.cards || this.cards;
3123
+ this.cards = this.getInitValue('cards', props.cards, this.cards);
3113
3124
  this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3114
3125
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3115
3126
  this.height = this.getInitValue('height', props.height, this.height);
@@ -3137,13 +3148,7 @@
3137
3148
  addCard() {
3138
3149
  const addCardForm = core.Metadata.getInstance('addCardForm');
3139
3150
  if (addCardForm.validate()) {
3140
- const newCard = {
3141
- cardId: this.getCardId(),
3142
- path: addCardForm.value.inputPath,
3143
- local: addCardForm.value.inputLocal,
3144
- height: addCardForm.value.inputHeight,
3145
- width: addCardForm.value.inputWidth,
3146
- };
3151
+ const newCard = Object.assign({ cardId: this.getCardId(), path: addCardForm.value.inputPath, local: addCardForm.value.inputLocal, height: addCardForm.value.inputHeight, width: addCardForm.value.inputWidth }, addCardForm.value);
3147
3152
  this.cards.push(newCard);
3148
3153
  this.modalCancelClick();
3149
3154
  }
@@ -3435,6 +3440,7 @@
3435
3440
  this.dateError = false;
3436
3441
  this.internalDisplayValue = newValue;
3437
3442
  this.internalValue = this.parser(newValue);
3443
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3438
3444
  }
3439
3445
  /**
3440
3446
  * Assign the updated mask to mask property
@@ -3474,6 +3480,7 @@
3474
3480
  }
3475
3481
  this.dateError = !!displayValue;
3476
3482
  }
3483
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3477
3484
  }
3478
3485
  isValidDate(value, format, strict = true) {
3479
3486
  return core.dayjs(value, format, strict).isValid();
@@ -3780,6 +3787,7 @@
3780
3787
  this.internalValue = this.parser(newValue);
3781
3788
  else
3782
3789
  this.internalValue = [];
3790
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3783
3791
  }
3784
3792
  /**
3785
3793
  * Assign the updated mask to mask property
@@ -3820,6 +3828,7 @@
3820
3828
  }
3821
3829
  this.dateError = !!displayValue;
3822
3830
  }
3831
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3823
3832
  }
3824
3833
  isValidDateArray(format, values) {
3825
3834
  if (!values || values.length === 0)
@@ -4419,14 +4428,17 @@
4419
4428
  this.local = false;
4420
4429
  this.metadata = {};
4421
4430
  this.override = {};
4431
+ this.params = {};
4422
4432
  this.overrideNamedProps = {};
4433
+ this.path = '';
4423
4434
  this.cache = false;
4424
4435
  this.cacheDuration = 2 * 60 * 60 * 1000;
4425
4436
  this.height = 'auto';
4426
4437
  this.maxHeight = 'none';
4427
4438
  this.minHeight = 'none';
4439
+ this.type = 'get';
4428
4440
  this.headerName = 'sw-fetched-on';
4429
- this.path = props.path;
4441
+ this.path = this.getInitValue('path', props.path, this.path);
4430
4442
  this.local = props.local === true;
4431
4443
  this.override = props.override || this.override;
4432
4444
  this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
@@ -4435,6 +4447,8 @@
4435
4447
  this.height = this.getInitValue('height', props.height, this.height);
4436
4448
  this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
4437
4449
  this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
4450
+ this.type = this.getInitValue('type', props.type, this.type);
4451
+ this.params = this.getInitValue('params', props.params, this.params);
4438
4452
  this.createAccessors();
4439
4453
  this.getMetadata();
4440
4454
  }
@@ -4475,6 +4489,9 @@
4475
4489
  requestPage() {
4476
4490
  return __awaiter(this, void 0, void 0, function* () {
4477
4491
  if (!this.cache) {
4492
+ if (this.type === 'post') {
4493
+ return core.Metadata.post(this.path, this.params);
4494
+ }
4478
4495
  return core.Metadata.get(this.path, this.local);
4479
4496
  }
4480
4497
  const url = core.Metadata.getMetadataUrl(this.path, this.local);
@@ -9054,7 +9071,9 @@
9054
9071
  originalData.splice(index + 1, 0, ...data);
9055
9072
  this.originalDatasource.data = originalData;
9056
9073
  this.originalDatasource.currentRow = this.clearRow(row);
9074
+ return data;
9057
9075
  }
9076
+ return undefined;
9058
9077
  });
9059
9078
  }
9060
9079
  /**
@@ -9242,6 +9261,10 @@
9242
9261
  */
9243
9262
  this.lazyLoad = true;
9244
9263
  this.selectValue = null;
9264
+ /**
9265
+ * Uses delayed loading to load tree branches
9266
+ */
9267
+ this.fetchOnDemand = false;
9245
9268
  this.nodes = this.getInitValue('nodes', props.nodes, this.nodes);
9246
9269
  this.alwaysOpen = this.getInitValue('alwaysOpen', props.alwaysOpen, this.alwaysOpen);
9247
9270
  this.flattenSearchResults = this.getInitValue('flattenSearchResults', props.flattenSearchResults, this.flattenSearchResults);
@@ -9260,6 +9283,7 @@
9260
9283
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
9261
9284
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
9262
9285
  this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
9286
+ this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
9263
9287
  if (props.datasource && Object.keys(props.datasource).length) {
9264
9288
  this.lazyLoad = props.datasource.lazyLoad !== false;
9265
9289
  const searchFields = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
@@ -9296,7 +9320,7 @@
9296
9320
  datasource: this.datasource,
9297
9321
  parentField: this.parentField,
9298
9322
  openLevelOnLoad: false,
9299
- fetchOnDemand: false,
9323
+ fetchOnDemand: this.fetchOnDemand,
9300
9324
  });
9301
9325
  if (!this.lazyLoad) {
9302
9326
  this.datasource.get().then(() => { this.createNodesFromDatasource(false); });
@@ -9316,7 +9340,16 @@
9316
9340
  }
9317
9341
  }
9318
9342
  createNodeFromRow(row) {
9319
- const children = this.createChildrenNodes(row.tree__children);
9343
+ let children;
9344
+ if (this.fetchOnDemand) {
9345
+ children = null;
9346
+ }
9347
+ else {
9348
+ children = this.createChildrenNodes(row.tree__children);
9349
+ if (!children.length) {
9350
+ children = undefined;
9351
+ }
9352
+ }
9320
9353
  const dataTextArr = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
9321
9354
  const dataTextNames = [];
9322
9355
  const masks = [];
@@ -9351,15 +9384,18 @@
9351
9384
  return {
9352
9385
  id: row[this.dataValue],
9353
9386
  label: dataText,
9354
- children: children.length ? children : undefined,
9387
+ children,
9355
9388
  row,
9356
9389
  };
9357
9390
  }
9358
9391
  createChildrenNodes(rows) {
9359
9392
  const newNodes = [];
9360
9393
  rows.forEach((row) => {
9361
- const newNode = this.createNodeFromRow(row);
9362
- newNodes.push(newNode);
9394
+ if (Object.keys(row).length > 0) {
9395
+ const newNode = this.createNodeFromRow(row);
9396
+ row.tree__node = newNode;
9397
+ newNodes.push(newNode);
9398
+ }
9363
9399
  });
9364
9400
  return newNodes;
9365
9401
  }
@@ -9395,7 +9431,7 @@
9395
9431
  return this.disabledItems.indexOf(node.id) !== -1;
9396
9432
  }
9397
9433
  getDisabledNodes(nodes) {
9398
- return nodes.map((node) => (Object.assign(Object.assign({}, node), { isDisabled: this.isDisable(node), children: node.children ? this.getDisabledNodes(node.children) : undefined })));
9434
+ return nodes.map((node) => (Object.assign(Object.assign({}, node), { isDisabled: this.isDisable(node), children: node.children ? this.getDisabledNodes(node.children) : node.children })));
9399
9435
  }
9400
9436
  getNodes() {
9401
9437
  return this.getDisabledNodes(this.nodes);
@@ -9462,6 +9498,22 @@
9462
9498
  }
9463
9499
  this.selectValue = val;
9464
9500
  }
9501
+ loadChildren(parentNode) {
9502
+ return __awaiter(this, void 0, void 0, function* () {
9503
+ return this.treeDataStructure.toggleExpand(parentNode.row).then((data) => {
9504
+ const node = parentNode.row.tree__node;
9505
+ if (node) {
9506
+ if (!data || data.length === 0) {
9507
+ node.children = undefined;
9508
+ }
9509
+ else {
9510
+ const nodes = this.createChildrenNodes(data);
9511
+ node.children = nodes;
9512
+ }
9513
+ }
9514
+ });
9515
+ });
9516
+ }
9465
9517
  }
9466
9518
 
9467
9519
  /**
@@ -10534,6 +10586,10 @@
10534
10586
  children: [],
10535
10587
  };
10536
10588
  newNode = merge__default["default"](newNode, node, override);
10589
+ if (typeof node.isLeaf === 'undefined') {
10590
+ const hasChildren = newNode.children.length > 0;
10591
+ newNode.isLeaf = !hasChildren;
10592
+ }
10537
10593
  newNode.children = this.initNodes(node.children || [], override);
10538
10594
  return newNode;
10539
10595
  });
@@ -10608,6 +10664,7 @@
10608
10664
  insertNode(newNode) {
10609
10665
  const initNode = this.initNodes([newNode])[0];
10610
10666
  if (this.selectedNodes.length) {
10667
+ this.updateNodeData(this.selectedNodes[0], { isLeaf: false });
10611
10668
  const cursorPosition = {
10612
10669
  node: this.selectedNodes[0],
10613
10670
  placement: 'inside',
@@ -10618,31 +10675,44 @@
10618
10675
  this.nodes.push(initNode);
10619
10676
  }
10620
10677
  }
10678
+ /** Import multiples nodes by the current cursor position */
10621
10679
  importNodes(nodes) {
10622
10680
  if (this.selectedNodes.length) {
10623
- const cursorPosition = {
10624
- node: this.selectedNodes[0],
10625
- placement: 'inside',
10626
- };
10627
10681
  nodes.reverse().forEach((node) => {
10628
- this.tree.insert(cursorPosition, node);
10682
+ this.insertNode(node);
10629
10683
  });
10630
10684
  }
10631
10685
  else {
10632
10686
  nodes.forEach((node) => {
10633
- this.nodes.push(node);
10687
+ this.insertNode(node);
10634
10688
  });
10635
10689
  }
10636
10690
  }
10637
10691
  /** Remove selected node */
10638
10692
  removeSelected() {
10693
+ const parentNodesPath = [];
10639
10694
  if (this.selectedNodes.length) {
10640
- const selectedPaths = this.selectedNodes.map((item) => item.path);
10695
+ const selectedPaths = this.selectedNodes.map((item) => {
10696
+ const parent = this.getParentNode(item);
10697
+ if (parent) {
10698
+ parentNodesPath.push(parent.path);
10699
+ }
10700
+ return item.path;
10701
+ });
10641
10702
  this.tree.remove(selectedPaths);
10703
+ parentNodesPath.forEach((path) => {
10704
+ const parent = this.getNode(path);
10705
+ if (parent && parent.children && parent.children.length === 0) {
10706
+ this.tree.updateNode(path, { isLeaf: true });
10707
+ }
10708
+ });
10642
10709
  }
10643
10710
  }
10644
10711
  /** Update selected node */
10645
10712
  updateNodeData(node, value) {
10713
+ if (node.children && node.children.length === 0) {
10714
+ this.tree.updateNode(node.path, { isLeaf: true });
10715
+ }
10646
10716
  this.tree.updateNode(node.path, value);
10647
10717
  }
10648
10718
  setTree(tree) {
@@ -10775,8 +10845,11 @@
10775
10845
  return this.searchPath(this.nodes, path);
10776
10846
  }
10777
10847
  getParentNode(node) {
10778
- var _a;
10779
- return this.tree.getNode(((_a = node.path) === null || _a === void 0 ? void 0 : _a.slice(0, -1)) || []);
10848
+ const hasParent = Array.isArray(node.path) && node.path.length > 1;
10849
+ if (hasParent) {
10850
+ return this.tree.getNode(node.path.slice(0, -1));
10851
+ }
10852
+ return undefined;
10780
10853
  }
10781
10854
  searchPath(nodes, path) {
10782
10855
  const currentNode = (path[0] > -1 && path[0] < nodes.length) ? nodes[path[0]] : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.48.0",
3
+ "version": "1.50.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -37,5 +37,5 @@
37
37
  "lodash.times": "^4.3.2",
38
38
  "mockdate": "^3.0.2"
39
39
  },
40
- "gitHead": "8f588b928efe593c47681477f44ac419b28fbabc"
40
+ "gitHead": "47f7e1870055d3ad9bba54c0f96b1e34176b70b6"
41
41
  }
@@ -2,7 +2,7 @@ import { IEventParam } from '@zeedhi/core';
2
2
  import { Dashboard } from './dashboard';
3
3
  import { IComponentRender, IComponentEvents } from '../zd-component/interfaces';
4
4
  import { IButton } from '../zd-button/interfaces';
5
- import { ICardEvents } from '../zd-card/interfaces';
5
+ import { ICard } from '../zd-card/interfaces';
6
6
  export declare type IDashboardEventParam = IEventParam<Dashboard>;
7
7
  export declare type IDashboardLoadEvent<T> = (event: T) => Promise<any>;
8
8
  export interface IDashboardEvents<T = IEventParam<any>> extends IComponentEvents<T> {
@@ -19,13 +19,11 @@ export interface IDashboard extends IComponentRender {
19
19
  height?: string | number;
20
20
  heightAdjust?: string | number;
21
21
  }
22
- export interface IDashboardCard {
22
+ export interface IDashboardCard extends Omit<ICard, 'name' | 'component'> {
23
23
  cardId: string;
24
24
  path: string;
25
25
  local: boolean;
26
26
  height: number | string;
27
- width: number;
28
- flat?: boolean;
29
- events?: ICardEvents;
27
+ width: number | string;
30
28
  overrideNamedProps?: any;
31
29
  }
@@ -8,6 +8,7 @@ export declare class Frame extends ComponentRender implements IFrame {
8
8
  local: boolean;
9
9
  metadata: Object;
10
10
  override: Object;
11
+ params: any;
11
12
  overrideNamedProps: any;
12
13
  path: string;
13
14
  cache: boolean;
@@ -16,6 +17,7 @@ export declare class Frame extends ComponentRender implements IFrame {
16
17
  height: number | string;
17
18
  maxHeight: number | string;
18
19
  minHeight: number | string;
20
+ type: string;
19
21
  private readonly headerName;
20
22
  private static readonly cacheName;
21
23
  /**
@@ -6,13 +6,15 @@ export interface IFrameEvents<T = IFrameEvent> extends IComponentEvents<T> {
6
6
  onAfterLoad?: IEvent<T> | string;
7
7
  }
8
8
  export interface IFrame extends IComponentRender {
9
- path: string;
9
+ path?: string;
10
10
  local?: boolean;
11
11
  override?: Object;
12
+ params?: any;
12
13
  overrideNamedProps?: any;
13
14
  cache?: boolean;
14
15
  cacheDuration?: number;
15
16
  height?: number | string;
16
17
  maxHeight?: number | string;
17
18
  minHeight?: number | string;
19
+ type?: string;
18
20
  }
@@ -6,7 +6,8 @@ export interface ISelectTreeNode<T> {
6
6
  label: string;
7
7
  isDisabled?: boolean;
8
8
  isDefaultExpanded?: boolean;
9
- children?: ISelectTreeNode<T>[];
9
+ children?: ISelectTreeNode<T>[] | null;
10
+ row?: IDictionary<any>;
10
11
  }
11
12
  export interface ISelectTree extends IComponentRender {
12
13
  nodes?: ISelectTreeNode<IDictionary>[];
@@ -28,6 +29,7 @@ export interface ISelectTree extends IComponentRender {
28
29
  dataText?: string | any[];
29
30
  dataDisabled?: string;
30
31
  disabledItems?: any[];
32
+ fetchOnDemand?: boolean;
31
33
  }
32
34
  export interface ISelectTreeCloseEvent extends IEventParam<SelectTree> {
33
35
  selectedNodes: ISelectTreeNode<IDictionary>[];
@@ -89,6 +89,10 @@ export declare class SelectTree extends TextInput implements ISelectTree {
89
89
  */
90
90
  private lazyLoad;
91
91
  selectValue: any;
92
+ /**
93
+ * Uses delayed loading to load tree branches
94
+ */
95
+ fetchOnDemand: boolean;
92
96
  /**
93
97
  * Creates a new instance of SelectTree
94
98
  * @param props
@@ -135,4 +139,5 @@ export declare class SelectTree extends TextInput implements ISelectTree {
135
139
  get value(): any;
136
140
  set value(value: any);
137
141
  setValue(value: any): void;
142
+ loadChildren(parentNode: ISelectTreeNode<IDictionary>): Promise<void>;
138
143
  }
@@ -68,7 +68,7 @@ export declare class Tree extends ComponentRender implements ITree {
68
68
  /**
69
69
  * Initialize all the properties of the declared nodes (reactivity)
70
70
  */
71
- protected initNodes(nodes: ITreeNodeModel<IDictionary>[], override?: IDictionary): ITreeNodeModel<IDictionary>[];
71
+ initNodes(nodes: ITreeNodeModel<IDictionary>[], override?: IDictionary): ITreeNodeModel<IDictionary>[];
72
72
  /** Nodes */
73
73
  get nodes(): ITreeNodeModel<IDictionary>[];
74
74
  set nodes(value: ITreeNodeModel<IDictionary>[]);
@@ -82,6 +82,7 @@ export declare class Tree extends ComponentRender implements ITree {
82
82
  private createChildrenNodes;
83
83
  /** Insert nodes by the current cursor position */
84
84
  insertNode(newNode: ITreeNodeModel<IDictionary>): void;
85
+ /** Import multiples nodes by the current cursor position */
85
86
  importNodes(nodes: ITreeNodeModel<IDictionary>[]): void;
86
87
  /** Remove selected node */
87
88
  removeSelected(): void;
@@ -17,6 +17,11 @@ export declare class ModalService {
17
17
  * @param modal modal structure
18
18
  */
19
19
  static createFromJson(modalPath: string, local?: boolean): Promise<Modal>;
20
+ /**
21
+ * Creates a new modal instance from JSON
22
+ * @param modal modal structure
23
+ */
24
+ static createFromJsonPost(modalPath: string, params?: object): Promise<Modal>;
20
25
  /**
21
26
  * Deletes modal
22
27
  * @param modal modal instance
@@ -105,7 +105,7 @@ export declare class TreeDataStructure {
105
105
  * @param row Row object
106
106
  * @param rowIndex Row index
107
107
  */
108
- toggleExpand(row: IDictionary<any>, rowIndex?: number): Promise<void>;
108
+ toggleExpand(row: IDictionary<any>, rowIndex?: number): Promise<IDictionary<any>[] | undefined>;
109
109
  /**
110
110
  * Return row with tree data
111
111
  * @param row datasource row