@zeedhi/common 1.47.0 → 1.49.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.
@@ -1,4 +1,4 @@
1
- import { AccessorManager, Event, KeyMap, Metadata, FormatterParserProvider, Validation, Accessor, DatasourceFactory, I18n, MethodNotAssignedError, Loader, Mask, Config, dayjs, DateHelper, Utils, Router, InstanceNotFoundError, Http, Cookie, URL as URL$1 } from '@zeedhi/core';
1
+ import { AccessorManager, Event, KeyMap, Metadata, FormatterParserProvider, Validation, Mask, Accessor, DatasourceFactory, I18n, MethodNotAssignedError, Loader, Config, dayjs, DateHelper, Utils, Router, InstanceNotFoundError, Http, Cookie, URL as URL$1 } from '@zeedhi/core';
2
2
  import merge from 'lodash.merge';
3
3
  import debounce from 'lodash.debounce';
4
4
  import isUndefined from 'lodash.isundefined';
@@ -40,6 +40,10 @@ class Component {
40
40
  * Set css in line with cssStyle.
41
41
  */
42
42
  this.cssStyle = '';
43
+ /**
44
+ * Directives registered to the component.
45
+ */
46
+ this.directives = {};
43
47
  /**
44
48
  * Events registered to the component.
45
49
  */
@@ -70,12 +74,16 @@ class Component {
70
74
  this.events = Event.factory(props.events || this.events);
71
75
  this.cssClass = this.getInitValue('cssClass', props.cssClass, this.cssClass);
72
76
  this.cssStyle = this.getInitValue('cssStyle', props.cssStyle, this.cssStyle);
77
+ this.directives = this.getInitValue('directives', props.directives, this.directives);
73
78
  this.isVisible = this.getInitValue('isVisible', props.isVisible, this.isVisible);
74
79
  this.dark = this.getInitValue('dark', props.dark, this.dark);
75
80
  this.light = this.getInitValue('light', props.light, this.light);
76
81
  this.children = Array.isArray(props.children) ? props.children : this.children;
77
82
  this.keyMap = KeyMap.factory(props.keyMap || this.keyMap);
78
83
  this.createAccessors();
84
+ Object.keys(this.directives).forEach((key) => {
85
+ this.directives[key] = Event.factory(this.directives[key]);
86
+ });
79
87
  }
80
88
  setViewFocus(viewFocus) {
81
89
  this.viewFocus = viewFocus;
@@ -1649,10 +1657,6 @@ class Input extends ComponentRender {
1649
1657
  * Used to watch a value from store.
1650
1658
  */
1651
1659
  this.storePath = '';
1652
- /**
1653
- * Internal input value.
1654
- */
1655
- this.value = null;
1656
1660
  /**
1657
1661
  * Input validations.
1658
1662
  */
@@ -1663,6 +1667,8 @@ class Input extends ComponentRender {
1663
1667
  this.parsedValidations = {};
1664
1668
  this.formatterFn = FormatterParserProvider.getFormatter('ZdInput');
1665
1669
  this.parserFn = FormatterParserProvider.getParser('ZdInput');
1670
+ this.internalDisplayValue = '';
1671
+ this.internalValue = null;
1666
1672
  this.lastInputValue = undefined;
1667
1673
  this.callInputEvent = debounce(({ event, element, component }) => {
1668
1674
  this.callEvent('input', { event, element, component });
@@ -1767,14 +1773,40 @@ class Input extends ComponentRender {
1767
1773
  this.rules = Object.values(this.parsedValidations)
1768
1774
  .map((validation) => () => validation(this.value));
1769
1775
  }
1776
+ /**
1777
+ * Input value.
1778
+ */
1779
+ get value() {
1780
+ return this.internalValue;
1781
+ }
1782
+ set value(value) {
1783
+ if (this.internalValue !== value) {
1784
+ this.internalDisplayValue = this.formatter(value);
1785
+ this.internalValue = value;
1786
+ }
1787
+ }
1770
1788
  /**
1771
1789
  * Input displayed value.
1772
1790
  */
1773
1791
  get displayValue() {
1774
- return this.formatter(this.value);
1792
+ return this.internalDisplayValue;
1775
1793
  }
1776
1794
  set displayValue(value) {
1777
- this.value = this.parser(value);
1795
+ if (this.internalDisplayValue !== value) {
1796
+ this.internalValue = this.parser(value);
1797
+ this.value = this.internalValue; // forces value accessor to be called if necessary
1798
+ let { mask } = this;
1799
+ if (mask) {
1800
+ if (typeof mask === 'function') {
1801
+ mask = mask(this.internalValue);
1802
+ }
1803
+ this.internalDisplayValue = Mask.convertAll(mask, this.internalValue);
1804
+ this.internalValue = this.parser(this.internalDisplayValue);
1805
+ }
1806
+ else {
1807
+ this.internalDisplayValue = this.internalValue;
1808
+ }
1809
+ }
1778
1810
  }
1779
1811
  /**
1780
1812
  * Retrieves a formatted value.
@@ -2863,6 +2895,7 @@ class Dashboard extends ComponentRender {
2863
2895
  this.cards = [];
2864
2896
  /* Card ID to be deleted */
2865
2897
  this.deleteCardId = '';
2898
+ this.overrideNamedProps = {};
2866
2899
  /* Remove the paddings of the dashboard */
2867
2900
  this.removePadding = false;
2868
2901
  /* Height of the dashboard */
@@ -3071,6 +3104,7 @@ class Dashboard extends ComponentRender {
3071
3104
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3072
3105
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3073
3106
  this.cards = props.cards || this.cards;
3107
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3074
3108
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3075
3109
  this.height = this.getInitValue('height', props.height, this.height);
3076
3110
  this.heightAdjust = this.getInitValue('heightAdjust', props.heightAdjust, this.heightAdjust);
@@ -3208,6 +3242,7 @@ class Dashboard extends ComponentRender {
3208
3242
  component: 'ZdFrame',
3209
3243
  path: card.path,
3210
3244
  local: card.local,
3245
+ overrideNamedProps: card.overrideNamedProps,
3211
3246
  };
3212
3247
  }
3213
3248
  /* Return footer rightSlot props for view layer */
@@ -3388,12 +3423,13 @@ class Date$1 extends TextInput {
3388
3423
  }
3389
3424
  }
3390
3425
  get displayValue() {
3391
- return this.formatter(this.value);
3426
+ return this.internalDisplayValue;
3392
3427
  }
3393
3428
  set displayValue(newValue) {
3394
3429
  this.dateError = false;
3395
- const dateValue = newValue;
3396
- this.value = this.parser(dateValue);
3430
+ this.internalDisplayValue = newValue;
3431
+ this.internalValue = this.parser(newValue);
3432
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3397
3433
  }
3398
3434
  /**
3399
3435
  * Assign the updated mask to mask property
@@ -3418,19 +3454,22 @@ class Date$1 extends TextInput {
3418
3454
  setDateValue(displayValue) {
3419
3455
  const lastValue = this.displayValue;
3420
3456
  if (this.isValidDate(displayValue, this.displayFormat)) {
3421
- this.displayValue = displayValue;
3457
+ this.internalDisplayValue = displayValue;
3458
+ this.internalValue = this.parser(displayValue);
3422
3459
  this.dateError = false;
3423
3460
  if (lastValue !== this.displayValue)
3424
3461
  this.change(this.value);
3425
3462
  }
3426
3463
  else {
3427
3464
  if (!displayValue) {
3428
- this.displayValue = displayValue;
3465
+ this.internalDisplayValue = displayValue;
3466
+ this.internalValue = null;
3429
3467
  if (lastValue !== this.displayValue)
3430
3468
  this.change(this.value);
3431
3469
  }
3432
3470
  this.dateError = !!displayValue;
3433
3471
  }
3472
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3434
3473
  }
3435
3474
  isValidDate(value, format, strict = true) {
3436
3475
  return dayjs(value, format, strict).isValid();
@@ -3469,7 +3508,7 @@ class Date$1 extends TextInput {
3469
3508
  }
3470
3509
  blur(event, element) {
3471
3510
  this.removeDateMask();
3472
- this.setDateValue(this.displayValue);
3511
+ this.setDateValue(this.formatter(this.value));
3473
3512
  super.blur(event, element);
3474
3513
  this.showDatePicker = false;
3475
3514
  }
@@ -3485,6 +3524,7 @@ class Date$1 extends TextInput {
3485
3524
  return;
3486
3525
  setTimeout(() => {
3487
3526
  this.mask = this.initialMask;
3527
+ this.internalDisplayValue = dayjs(this.value, this.dateFormat).format(this.inputFormat || this.displayFormat);
3488
3528
  });
3489
3529
  }
3490
3530
  /**
@@ -3727,15 +3767,16 @@ class DateRange extends TextInput {
3727
3767
  formatter(value) { return this.formatterFn(value, this); }
3728
3768
  parser(value) { return this.parserFn(value, this); }
3729
3769
  get displayValue() {
3730
- return this.formatter(this.value);
3770
+ return this.internalDisplayValue;
3731
3771
  }
3732
3772
  set displayValue(newValue) {
3733
3773
  this.dateError = false;
3734
- const dateValue = newValue;
3735
- if (dateValue)
3736
- this.value = this.parser(dateValue);
3774
+ this.internalDisplayValue = newValue;
3775
+ if (newValue)
3776
+ this.internalValue = this.parser(newValue);
3737
3777
  else
3738
- this.value = [];
3778
+ this.internalValue = [];
3779
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3739
3780
  }
3740
3781
  /**
3741
3782
  * Assign the updated mask to mask property
@@ -3761,19 +3802,22 @@ class DateRange extends TextInput {
3761
3802
  const lastValue = this.displayValue;
3762
3803
  const values = this.splitValues(displayValue);
3763
3804
  if (this.isValidDateArray(this.displayFormat, values)) {
3764
- this.displayValue = displayValue;
3805
+ this.internalDisplayValue = displayValue;
3806
+ this.internalValue = this.parser(displayValue);
3765
3807
  this.dateError = false;
3766
3808
  if (lastValue !== this.displayValue)
3767
3809
  this.change(this.value);
3768
3810
  }
3769
3811
  else {
3770
3812
  if (!displayValue) {
3771
- this.displayValue = displayValue;
3813
+ this.internalDisplayValue = displayValue;
3814
+ this.internalValue = [];
3772
3815
  if (lastValue !== this.displayValue)
3773
3816
  this.change(this.value);
3774
3817
  }
3775
3818
  this.dateError = !!displayValue;
3776
3819
  }
3820
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3777
3821
  }
3778
3822
  isValidDateArray(format, values) {
3779
3823
  if (!values || values.length === 0)
@@ -3844,11 +3888,13 @@ class DateRange extends TextInput {
3844
3888
  }
3845
3889
  }
3846
3890
  blur(event, element) {
3847
- this.value = this.sortDates(this.value);
3848
- this.removeDateMask();
3849
- this.setDateValue(this.displayValue);
3850
- super.blur(event, element);
3851
- this.showDatePicker = false;
3891
+ if (this.value) {
3892
+ this.value = this.sortDates(this.value);
3893
+ this.removeDateMask();
3894
+ this.setDateValue(this.formatter(this.value));
3895
+ super.blur(event, element);
3896
+ this.showDatePicker = false;
3897
+ }
3852
3898
  }
3853
3899
  focus(event, element) {
3854
3900
  this.addDateMask();
@@ -3862,6 +3908,13 @@ class DateRange extends TextInput {
3862
3908
  return;
3863
3909
  setTimeout(() => {
3864
3910
  this.mask = this.initialMask;
3911
+ const firstDate = this.value[0]
3912
+ ? dayjs(this.value[0], this.dateFormat).format(this.inputFormat || this.displayFormat)
3913
+ : '';
3914
+ const lastDate = this.value[1]
3915
+ ? dayjs(this.value[1], this.dateFormat).format(this.inputFormat || this.displayFormat)
3916
+ : '';
3917
+ this.internalDisplayValue = `${firstDate}${lastDate ? this.splitter : ''}${lastDate}`;
3865
3918
  });
3866
3919
  }
3867
3920
  /**
@@ -4364,20 +4417,27 @@ class Frame extends ComponentRender {
4364
4417
  this.local = false;
4365
4418
  this.metadata = {};
4366
4419
  this.override = {};
4420
+ this.params = {};
4421
+ this.overrideNamedProps = {};
4422
+ this.path = '';
4367
4423
  this.cache = false;
4368
4424
  this.cacheDuration = 2 * 60 * 60 * 1000;
4369
4425
  this.height = 'auto';
4370
4426
  this.maxHeight = 'none';
4371
4427
  this.minHeight = 'none';
4428
+ this.type = 'get';
4372
4429
  this.headerName = 'sw-fetched-on';
4373
- this.path = props.path;
4430
+ this.path = this.getInitValue('path', props.path, this.path);
4374
4431
  this.local = props.local === true;
4375
4432
  this.override = props.override || this.override;
4433
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
4376
4434
  this.cache = props.cache || this.cache;
4377
4435
  this.cacheDuration = this.getInitValue('cacheDuration', props.cacheDuration, this.cacheDuration);
4378
4436
  this.height = this.getInitValue('height', props.height, this.height);
4379
4437
  this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
4380
4438
  this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
4439
+ this.type = this.getInitValue('type', props.type, this.type);
4440
+ this.params = this.getInitValue('params', props.params, this.params);
4381
4441
  this.createAccessors();
4382
4442
  this.getMetadata();
4383
4443
  }
@@ -4388,6 +4448,9 @@ class Frame extends ComponentRender {
4388
4448
  if (typeof page !== 'object')
4389
4449
  throw new Error();
4390
4450
  this.metadata = merge(page, this.override);
4451
+ if (Object.keys(this.overrideNamedProps).length !== 0) {
4452
+ this.metadata = this.overrideNamedPropsFunc(this.metadata);
4453
+ }
4391
4454
  }
4392
4455
  catch (_a) {
4393
4456
  this.notFoundError();
@@ -4398,6 +4461,13 @@ class Frame extends ComponentRender {
4398
4461
  }
4399
4462
  });
4400
4463
  }
4464
+ overrideNamedPropsFunc(metadata) {
4465
+ let strMatadata = JSON.stringify(metadata);
4466
+ Object.keys(this.overrideNamedProps).forEach((key) => {
4467
+ strMatadata = strMatadata.replace(RegExp(`<<${key}>>`, 'g'), this.overrideNamedProps[key]);
4468
+ });
4469
+ return JSON.parse(strMatadata);
4470
+ }
4401
4471
  reload() {
4402
4472
  return __awaiter(this, void 0, void 0, function* () {
4403
4473
  this.loading = true;
@@ -4408,6 +4478,9 @@ class Frame extends ComponentRender {
4408
4478
  requestPage() {
4409
4479
  return __awaiter(this, void 0, void 0, function* () {
4410
4480
  if (!this.cache) {
4481
+ if (this.type === 'post') {
4482
+ return Metadata.post(this.path, this.params);
4483
+ }
4411
4484
  return Metadata.get(this.path, this.local);
4412
4485
  }
4413
4486
  const url = Metadata.getMetadataUrl(this.path, this.local);
@@ -6268,6 +6341,10 @@ class Select extends TextInput {
6268
6341
  * Maximum height of select menu
6269
6342
  */
6270
6343
  this.menuMaxHeight = 304;
6344
+ /**
6345
+ * Maximum width of select menu
6346
+ */
6347
+ this.menuMaxWidth = 'auto';
6271
6348
  /**
6272
6349
  * Input select value
6273
6350
  */
@@ -6327,6 +6404,7 @@ class Select extends TextInput {
6327
6404
  this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
6328
6405
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
6329
6406
  this.menuMaxHeight = this.getInitValue('menuMaxHeight', props.menuMaxHeight, this.menuMaxHeight);
6407
+ this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
6330
6408
  this.returnObject = this.getInitValue('returnObject', props.returnObject, this.returnObject);
6331
6409
  this.autocomplete = this.getInitValue('autocomplete', props.autocomplete, this.autocomplete);
6332
6410
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
@@ -6422,8 +6500,10 @@ class Select extends TextInput {
6422
6500
  getItemsBySearchValue(value, searchIn) {
6423
6501
  return __awaiter(this, void 0, void 0, function* () {
6424
6502
  const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true });
6503
+ this.datasource.loading = true;
6425
6504
  const datasource = DatasourceFactory.factory(config);
6426
6505
  const items = yield datasource.get();
6506
+ this.datasource.loading = false;
6427
6507
  datasource.destroy();
6428
6508
  return items.find(this.getCondition(value));
6429
6509
  });
@@ -9372,23 +9452,21 @@ class SelectTree extends TextInput {
9372
9452
  return this.selectValue;
9373
9453
  }
9374
9454
  set value(value) {
9375
- this.selectValue = value;
9455
+ this.setValue(value);
9376
9456
  }
9377
9457
  setValue(value) {
9378
- if (this.returnObject) {
9379
- if (typeof value !== 'object') {
9380
- this.value = { id: value };
9381
- }
9382
- else {
9383
- this.value = { id: value[this.dataValue] };
9384
- }
9458
+ let val = value;
9459
+ if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9460
+ val = value[this.dataValue];
9385
9461
  }
9386
- else if (typeof value === 'object') {
9387
- this.value = value[this.dataValue];
9462
+ else if (!value && value !== 0) {
9463
+ val = null;
9388
9464
  }
9389
- else {
9390
- this.value = value;
9465
+ if (this.returnObject) {
9466
+ this.selectValue = val ? { id: val } : null;
9467
+ return;
9391
9468
  }
9469
+ this.selectValue = val;
9392
9470
  }
9393
9471
  }
9394
9472
 
@@ -9811,6 +9889,7 @@ class Tab extends Component {
9811
9889
  this.tabTitle = '';
9812
9890
  this.tabTitle = this.getInitValue('tabTitle', props.tabTitle, this.tabTitle);
9813
9891
  this.disabled = this.getInitValue('disabled', props.disabled, this.disabled);
9892
+ this.flex = this.getInitValue('flex', props.flex, this.flex);
9814
9893
  this.createAccessors();
9815
9894
  }
9816
9895
  }
@@ -10702,8 +10781,11 @@ class Tree extends ComponentRender {
10702
10781
  return this.searchPath(this.nodes, path);
10703
10782
  }
10704
10783
  getParentNode(node) {
10705
- var _a;
10706
- return this.tree.getNode(((_a = node.path) === null || _a === void 0 ? void 0 : _a.slice(0, -1)) || []);
10784
+ const hasParent = Array.isArray(node.path) && node.path.length > 1;
10785
+ if (node.path && hasParent) {
10786
+ return this.tree.getNode(node.path.slice(0, -1));
10787
+ }
10788
+ return undefined;
10707
10789
  }
10708
10790
  searchPath(nodes, path) {
10709
10791
  const currentNode = (path[0] > -1 && path[0] < nodes.length) ? nodes[path[0]] : undefined;
@@ -47,6 +47,10 @@
47
47
  * Set css in line with cssStyle.
48
48
  */
49
49
  this.cssStyle = '';
50
+ /**
51
+ * Directives registered to the component.
52
+ */
53
+ this.directives = {};
50
54
  /**
51
55
  * Events registered to the component.
52
56
  */
@@ -77,12 +81,16 @@
77
81
  this.events = core.Event.factory(props.events || this.events);
78
82
  this.cssClass = this.getInitValue('cssClass', props.cssClass, this.cssClass);
79
83
  this.cssStyle = this.getInitValue('cssStyle', props.cssStyle, this.cssStyle);
84
+ this.directives = this.getInitValue('directives', props.directives, this.directives);
80
85
  this.isVisible = this.getInitValue('isVisible', props.isVisible, this.isVisible);
81
86
  this.dark = this.getInitValue('dark', props.dark, this.dark);
82
87
  this.light = this.getInitValue('light', props.light, this.light);
83
88
  this.children = Array.isArray(props.children) ? props.children : this.children;
84
89
  this.keyMap = core.KeyMap.factory(props.keyMap || this.keyMap);
85
90
  this.createAccessors();
91
+ Object.keys(this.directives).forEach((key) => {
92
+ this.directives[key] = core.Event.factory(this.directives[key]);
93
+ });
86
94
  }
87
95
  setViewFocus(viewFocus) {
88
96
  this.viewFocus = viewFocus;
@@ -1656,10 +1664,6 @@
1656
1664
  * Used to watch a value from store.
1657
1665
  */
1658
1666
  this.storePath = '';
1659
- /**
1660
- * Internal input value.
1661
- */
1662
- this.value = null;
1663
1667
  /**
1664
1668
  * Input validations.
1665
1669
  */
@@ -1670,6 +1674,8 @@
1670
1674
  this.parsedValidations = {};
1671
1675
  this.formatterFn = core.FormatterParserProvider.getFormatter('ZdInput');
1672
1676
  this.parserFn = core.FormatterParserProvider.getParser('ZdInput');
1677
+ this.internalDisplayValue = '';
1678
+ this.internalValue = null;
1673
1679
  this.lastInputValue = undefined;
1674
1680
  this.callInputEvent = debounce__default["default"](({ event, element, component }) => {
1675
1681
  this.callEvent('input', { event, element, component });
@@ -1774,14 +1780,40 @@
1774
1780
  this.rules = Object.values(this.parsedValidations)
1775
1781
  .map((validation) => () => validation(this.value));
1776
1782
  }
1783
+ /**
1784
+ * Input value.
1785
+ */
1786
+ get value() {
1787
+ return this.internalValue;
1788
+ }
1789
+ set value(value) {
1790
+ if (this.internalValue !== value) {
1791
+ this.internalDisplayValue = this.formatter(value);
1792
+ this.internalValue = value;
1793
+ }
1794
+ }
1777
1795
  /**
1778
1796
  * Input displayed value.
1779
1797
  */
1780
1798
  get displayValue() {
1781
- return this.formatter(this.value);
1799
+ return this.internalDisplayValue;
1782
1800
  }
1783
1801
  set displayValue(value) {
1784
- this.value = this.parser(value);
1802
+ if (this.internalDisplayValue !== value) {
1803
+ this.internalValue = this.parser(value);
1804
+ this.value = this.internalValue; // forces value accessor to be called if necessary
1805
+ let { mask } = this;
1806
+ if (mask) {
1807
+ if (typeof mask === 'function') {
1808
+ mask = mask(this.internalValue);
1809
+ }
1810
+ this.internalDisplayValue = core.Mask.convertAll(mask, this.internalValue);
1811
+ this.internalValue = this.parser(this.internalDisplayValue);
1812
+ }
1813
+ else {
1814
+ this.internalDisplayValue = this.internalValue;
1815
+ }
1816
+ }
1785
1817
  }
1786
1818
  /**
1787
1819
  * Retrieves a formatted value.
@@ -2870,6 +2902,7 @@
2870
2902
  this.cards = [];
2871
2903
  /* Card ID to be deleted */
2872
2904
  this.deleteCardId = '';
2905
+ this.overrideNamedProps = {};
2873
2906
  /* Remove the paddings of the dashboard */
2874
2907
  this.removePadding = false;
2875
2908
  /* Height of the dashboard */
@@ -3078,6 +3111,7 @@
3078
3111
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3079
3112
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3080
3113
  this.cards = props.cards || this.cards;
3114
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3081
3115
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3082
3116
  this.height = this.getInitValue('height', props.height, this.height);
3083
3117
  this.heightAdjust = this.getInitValue('heightAdjust', props.heightAdjust, this.heightAdjust);
@@ -3215,6 +3249,7 @@
3215
3249
  component: 'ZdFrame',
3216
3250
  path: card.path,
3217
3251
  local: card.local,
3252
+ overrideNamedProps: card.overrideNamedProps,
3218
3253
  };
3219
3254
  }
3220
3255
  /* Return footer rightSlot props for view layer */
@@ -3395,12 +3430,13 @@
3395
3430
  }
3396
3431
  }
3397
3432
  get displayValue() {
3398
- return this.formatter(this.value);
3433
+ return this.internalDisplayValue;
3399
3434
  }
3400
3435
  set displayValue(newValue) {
3401
3436
  this.dateError = false;
3402
- const dateValue = newValue;
3403
- this.value = this.parser(dateValue);
3437
+ this.internalDisplayValue = newValue;
3438
+ this.internalValue = this.parser(newValue);
3439
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3404
3440
  }
3405
3441
  /**
3406
3442
  * Assign the updated mask to mask property
@@ -3425,19 +3461,22 @@
3425
3461
  setDateValue(displayValue) {
3426
3462
  const lastValue = this.displayValue;
3427
3463
  if (this.isValidDate(displayValue, this.displayFormat)) {
3428
- this.displayValue = displayValue;
3464
+ this.internalDisplayValue = displayValue;
3465
+ this.internalValue = this.parser(displayValue);
3429
3466
  this.dateError = false;
3430
3467
  if (lastValue !== this.displayValue)
3431
3468
  this.change(this.value);
3432
3469
  }
3433
3470
  else {
3434
3471
  if (!displayValue) {
3435
- this.displayValue = displayValue;
3472
+ this.internalDisplayValue = displayValue;
3473
+ this.internalValue = null;
3436
3474
  if (lastValue !== this.displayValue)
3437
3475
  this.change(this.value);
3438
3476
  }
3439
3477
  this.dateError = !!displayValue;
3440
3478
  }
3479
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3441
3480
  }
3442
3481
  isValidDate(value, format, strict = true) {
3443
3482
  return core.dayjs(value, format, strict).isValid();
@@ -3476,7 +3515,7 @@
3476
3515
  }
3477
3516
  blur(event, element) {
3478
3517
  this.removeDateMask();
3479
- this.setDateValue(this.displayValue);
3518
+ this.setDateValue(this.formatter(this.value));
3480
3519
  super.blur(event, element);
3481
3520
  this.showDatePicker = false;
3482
3521
  }
@@ -3492,6 +3531,7 @@
3492
3531
  return;
3493
3532
  setTimeout(() => {
3494
3533
  this.mask = this.initialMask;
3534
+ this.internalDisplayValue = core.dayjs(this.value, this.dateFormat).format(this.inputFormat || this.displayFormat);
3495
3535
  });
3496
3536
  }
3497
3537
  /**
@@ -3734,15 +3774,16 @@
3734
3774
  formatter(value) { return this.formatterFn(value, this); }
3735
3775
  parser(value) { return this.parserFn(value, this); }
3736
3776
  get displayValue() {
3737
- return this.formatter(this.value);
3777
+ return this.internalDisplayValue;
3738
3778
  }
3739
3779
  set displayValue(newValue) {
3740
3780
  this.dateError = false;
3741
- const dateValue = newValue;
3742
- if (dateValue)
3743
- this.value = this.parser(dateValue);
3781
+ this.internalDisplayValue = newValue;
3782
+ if (newValue)
3783
+ this.internalValue = this.parser(newValue);
3744
3784
  else
3745
- this.value = [];
3785
+ this.internalValue = [];
3786
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3746
3787
  }
3747
3788
  /**
3748
3789
  * Assign the updated mask to mask property
@@ -3768,19 +3809,22 @@
3768
3809
  const lastValue = this.displayValue;
3769
3810
  const values = this.splitValues(displayValue);
3770
3811
  if (this.isValidDateArray(this.displayFormat, values)) {
3771
- this.displayValue = displayValue;
3812
+ this.internalDisplayValue = displayValue;
3813
+ this.internalValue = this.parser(displayValue);
3772
3814
  this.dateError = false;
3773
3815
  if (lastValue !== this.displayValue)
3774
3816
  this.change(this.value);
3775
3817
  }
3776
3818
  else {
3777
3819
  if (!displayValue) {
3778
- this.displayValue = displayValue;
3820
+ this.internalDisplayValue = displayValue;
3821
+ this.internalValue = [];
3779
3822
  if (lastValue !== this.displayValue)
3780
3823
  this.change(this.value);
3781
3824
  }
3782
3825
  this.dateError = !!displayValue;
3783
3826
  }
3827
+ this.value = this.internalValue; // forces value accessor to be called if necessary
3784
3828
  }
3785
3829
  isValidDateArray(format, values) {
3786
3830
  if (!values || values.length === 0)
@@ -3851,11 +3895,13 @@
3851
3895
  }
3852
3896
  }
3853
3897
  blur(event, element) {
3854
- this.value = this.sortDates(this.value);
3855
- this.removeDateMask();
3856
- this.setDateValue(this.displayValue);
3857
- super.blur(event, element);
3858
- this.showDatePicker = false;
3898
+ if (this.value) {
3899
+ this.value = this.sortDates(this.value);
3900
+ this.removeDateMask();
3901
+ this.setDateValue(this.formatter(this.value));
3902
+ super.blur(event, element);
3903
+ this.showDatePicker = false;
3904
+ }
3859
3905
  }
3860
3906
  focus(event, element) {
3861
3907
  this.addDateMask();
@@ -3869,6 +3915,13 @@
3869
3915
  return;
3870
3916
  setTimeout(() => {
3871
3917
  this.mask = this.initialMask;
3918
+ const firstDate = this.value[0]
3919
+ ? core.dayjs(this.value[0], this.dateFormat).format(this.inputFormat || this.displayFormat)
3920
+ : '';
3921
+ const lastDate = this.value[1]
3922
+ ? core.dayjs(this.value[1], this.dateFormat).format(this.inputFormat || this.displayFormat)
3923
+ : '';
3924
+ this.internalDisplayValue = `${firstDate}${lastDate ? this.splitter : ''}${lastDate}`;
3872
3925
  });
3873
3926
  }
3874
3927
  /**
@@ -4371,20 +4424,27 @@
4371
4424
  this.local = false;
4372
4425
  this.metadata = {};
4373
4426
  this.override = {};
4427
+ this.params = {};
4428
+ this.overrideNamedProps = {};
4429
+ this.path = '';
4374
4430
  this.cache = false;
4375
4431
  this.cacheDuration = 2 * 60 * 60 * 1000;
4376
4432
  this.height = 'auto';
4377
4433
  this.maxHeight = 'none';
4378
4434
  this.minHeight = 'none';
4435
+ this.type = 'get';
4379
4436
  this.headerName = 'sw-fetched-on';
4380
- this.path = props.path;
4437
+ this.path = this.getInitValue('path', props.path, this.path);
4381
4438
  this.local = props.local === true;
4382
4439
  this.override = props.override || this.override;
4440
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
4383
4441
  this.cache = props.cache || this.cache;
4384
4442
  this.cacheDuration = this.getInitValue('cacheDuration', props.cacheDuration, this.cacheDuration);
4385
4443
  this.height = this.getInitValue('height', props.height, this.height);
4386
4444
  this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
4387
4445
  this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
4446
+ this.type = this.getInitValue('type', props.type, this.type);
4447
+ this.params = this.getInitValue('params', props.params, this.params);
4388
4448
  this.createAccessors();
4389
4449
  this.getMetadata();
4390
4450
  }
@@ -4395,6 +4455,9 @@
4395
4455
  if (typeof page !== 'object')
4396
4456
  throw new Error();
4397
4457
  this.metadata = merge__default["default"](page, this.override);
4458
+ if (Object.keys(this.overrideNamedProps).length !== 0) {
4459
+ this.metadata = this.overrideNamedPropsFunc(this.metadata);
4460
+ }
4398
4461
  }
4399
4462
  catch (_a) {
4400
4463
  this.notFoundError();
@@ -4405,6 +4468,13 @@
4405
4468
  }
4406
4469
  });
4407
4470
  }
4471
+ overrideNamedPropsFunc(metadata) {
4472
+ let strMatadata = JSON.stringify(metadata);
4473
+ Object.keys(this.overrideNamedProps).forEach((key) => {
4474
+ strMatadata = strMatadata.replace(RegExp(`<<${key}>>`, 'g'), this.overrideNamedProps[key]);
4475
+ });
4476
+ return JSON.parse(strMatadata);
4477
+ }
4408
4478
  reload() {
4409
4479
  return __awaiter(this, void 0, void 0, function* () {
4410
4480
  this.loading = true;
@@ -4415,6 +4485,9 @@
4415
4485
  requestPage() {
4416
4486
  return __awaiter(this, void 0, void 0, function* () {
4417
4487
  if (!this.cache) {
4488
+ if (this.type === 'post') {
4489
+ return core.Metadata.post(this.path, this.params);
4490
+ }
4418
4491
  return core.Metadata.get(this.path, this.local);
4419
4492
  }
4420
4493
  const url = core.Metadata.getMetadataUrl(this.path, this.local);
@@ -6275,6 +6348,10 @@
6275
6348
  * Maximum height of select menu
6276
6349
  */
6277
6350
  this.menuMaxHeight = 304;
6351
+ /**
6352
+ * Maximum width of select menu
6353
+ */
6354
+ this.menuMaxWidth = 'auto';
6278
6355
  /**
6279
6356
  * Input select value
6280
6357
  */
@@ -6334,6 +6411,7 @@
6334
6411
  this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
6335
6412
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
6336
6413
  this.menuMaxHeight = this.getInitValue('menuMaxHeight', props.menuMaxHeight, this.menuMaxHeight);
6414
+ this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
6337
6415
  this.returnObject = this.getInitValue('returnObject', props.returnObject, this.returnObject);
6338
6416
  this.autocomplete = this.getInitValue('autocomplete', props.autocomplete, this.autocomplete);
6339
6417
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
@@ -6429,8 +6507,10 @@
6429
6507
  getItemsBySearchValue(value, searchIn) {
6430
6508
  return __awaiter(this, void 0, void 0, function* () {
6431
6509
  const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true });
6510
+ this.datasource.loading = true;
6432
6511
  const datasource = core.DatasourceFactory.factory(config);
6433
6512
  const items = yield datasource.get();
6513
+ this.datasource.loading = false;
6434
6514
  datasource.destroy();
6435
6515
  return items.find(this.getCondition(value));
6436
6516
  });
@@ -9379,23 +9459,21 @@
9379
9459
  return this.selectValue;
9380
9460
  }
9381
9461
  set value(value) {
9382
- this.selectValue = value;
9462
+ this.setValue(value);
9383
9463
  }
9384
9464
  setValue(value) {
9385
- if (this.returnObject) {
9386
- if (typeof value !== 'object') {
9387
- this.value = { id: value };
9388
- }
9389
- else {
9390
- this.value = { id: value[this.dataValue] };
9391
- }
9465
+ let val = value;
9466
+ if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9467
+ val = value[this.dataValue];
9392
9468
  }
9393
- else if (typeof value === 'object') {
9394
- this.value = value[this.dataValue];
9469
+ else if (!value && value !== 0) {
9470
+ val = null;
9395
9471
  }
9396
- else {
9397
- this.value = value;
9472
+ if (this.returnObject) {
9473
+ this.selectValue = val ? { id: val } : null;
9474
+ return;
9398
9475
  }
9476
+ this.selectValue = val;
9399
9477
  }
9400
9478
  }
9401
9479
 
@@ -9818,6 +9896,7 @@
9818
9896
  this.tabTitle = '';
9819
9897
  this.tabTitle = this.getInitValue('tabTitle', props.tabTitle, this.tabTitle);
9820
9898
  this.disabled = this.getInitValue('disabled', props.disabled, this.disabled);
9899
+ this.flex = this.getInitValue('flex', props.flex, this.flex);
9821
9900
  this.createAccessors();
9822
9901
  }
9823
9902
  }
@@ -10709,8 +10788,11 @@
10709
10788
  return this.searchPath(this.nodes, path);
10710
10789
  }
10711
10790
  getParentNode(node) {
10712
- var _a;
10713
- return this.tree.getNode(((_a = node.path) === null || _a === void 0 ? void 0 : _a.slice(0, -1)) || []);
10791
+ const hasParent = Array.isArray(node.path) && node.path.length > 1;
10792
+ if (node.path && hasParent) {
10793
+ return this.tree.getNode(node.path.slice(0, -1));
10794
+ }
10795
+ return undefined;
10714
10796
  }
10715
10797
  searchPath(nodes, path) {
10716
10798
  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.47.0",
3
+ "version": "1.49.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": "69b4f8f97adbd991270b536b5fa59fa8fa138aa7"
40
+ "gitHead": "c470a0a057bc8e1c5b97197258b551b9b158b744"
41
41
  }
@@ -1,5 +1,5 @@
1
1
  import { IKeyMap } from '@zeedhi/core';
2
- import { IComponent, IComponentEvents } from './interfaces';
2
+ import { IComponent, IComponentDirectives, IComponentEvents } from './interfaces';
3
3
  /**
4
4
  * Base class for all Zeedhi components.
5
5
  */
@@ -22,6 +22,10 @@ export declare class Component implements IComponent {
22
22
  * Set css in line with cssStyle.
23
23
  */
24
24
  cssStyle: string | object;
25
+ /**
26
+ * Directives registered to the component.
27
+ */
28
+ directives: IComponentDirectives;
25
29
  /**
26
30
  * Events registered to the component.
27
31
  */
@@ -12,6 +12,7 @@ export interface IComponent {
12
12
  cssClass?: string;
13
13
  cssStyle?: string | object;
14
14
  events?: IComponentEvents;
15
+ directives?: IComponentDirectives;
15
16
  isVisible?: boolean | string;
16
17
  dark?: boolean;
17
18
  light?: boolean;
@@ -34,3 +35,7 @@ export interface IComponentEvents<T = IEventParam<any>> extends IEvents<T> {
34
35
  onBeforeDestroy?: IEvent<T> | string;
35
36
  onDestroyed?: IEvent<T> | string;
36
37
  }
38
+ export interface IComponentDirectives {
39
+ touch?: IComponentEvents;
40
+ [key: string]: IComponentEvents | undefined;
41
+ }
@@ -14,6 +14,7 @@ export declare class Dashboard extends ComponentRender implements IDashboard {
14
14
  addModal?: Modal;
15
15
  editModal?: Modal;
16
16
  deleteCardId: string;
17
+ overrideNamedProps: any;
17
18
  removePadding: boolean;
18
19
  height: string | number;
19
20
  heightAdjust: string | number;
@@ -41,11 +42,13 @@ export declare class Dashboard extends ComponentRender implements IDashboard {
41
42
  component?: undefined;
42
43
  path?: undefined;
43
44
  local?: undefined;
45
+ overrideNamedProps?: undefined;
44
46
  } | {
45
47
  name: string;
46
48
  component: string;
47
49
  path: string;
48
50
  local: boolean;
51
+ overrideNamedProps: any;
49
52
  };
50
53
  getFooterRightSlot(cardId: string): ({
51
54
  name: string;
@@ -27,4 +27,5 @@ export interface IDashboardCard {
27
27
  width: number;
28
28
  flat?: boolean;
29
29
  events?: ICardEvents;
30
+ overrideNamedProps?: any;
30
31
  }
@@ -63,7 +63,7 @@ export declare class FileInput extends TextInput implements IFileInput {
63
63
  /**
64
64
  * Field value.
65
65
  */
66
- private internalValue;
66
+ protected internalValue: any;
67
67
  selectFileButton: IButton;
68
68
  /**
69
69
  * Create a new FileInput
@@ -66,22 +66,16 @@ export declare class Form extends ComponentRender implements IForm {
66
66
  get childrenProps(): {
67
67
  [key: string]: any;
68
68
  children?: import("..").IComponentRender[] | undefined;
69
- component: string; /**
70
- * Applies the justify-content css property.
71
- * Available options are start, center, end, space-between and space-around.
72
- */
69
+ component: string;
73
70
  componentId?: number | undefined;
74
71
  cssClass?: string | undefined;
75
72
  cssStyle?: string | object | undefined;
76
73
  events?: import("..").IComponentEvents<import("@zeedhi/core").IEventParam<any>> | undefined;
74
+ directives?: import("..").IComponentDirectives | undefined;
77
75
  isVisible?: string | boolean | undefined;
78
76
  dark?: boolean | undefined;
79
77
  light?: boolean | undefined;
80
78
  keyMap?: import("@zeedhi/core").IKeyMap<import("@zeedhi/core").IEventParam<any>> | undefined;
81
- /**
82
- * Applies the align-items css property.
83
- * Available options are start, center, end, space-between, space-around and stretch.
84
- */
85
79
  name: string;
86
80
  parent?: import("..").Component | undefined;
87
81
  }[];
@@ -8,6 +8,8 @@ export declare class Frame extends ComponentRender implements IFrame {
8
8
  local: boolean;
9
9
  metadata: Object;
10
10
  override: Object;
11
+ params: any;
12
+ overrideNamedProps: any;
11
13
  path: string;
12
14
  cache: boolean;
13
15
  events: IFrameEvents;
@@ -15,6 +17,7 @@ export declare class Frame extends ComponentRender implements IFrame {
15
17
  height: number | string;
16
18
  maxHeight: number | string;
17
19
  minHeight: number | string;
20
+ type: string;
18
21
  private readonly headerName;
19
22
  private static readonly cacheName;
20
23
  /**
@@ -23,6 +26,7 @@ export declare class Frame extends ComponentRender implements IFrame {
23
26
  */
24
27
  constructor(props: IFrame);
25
28
  private getMetadata;
29
+ overrideNamedPropsFunc(metadata: object): any;
26
30
  reload(): Promise<void>;
27
31
  protected notFoundError(): void;
28
32
  private requestPage;
@@ -6,12 +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;
13
+ overrideNamedProps?: any;
12
14
  cache?: boolean;
13
15
  cacheDuration?: number;
14
16
  height?: number | string;
15
17
  maxHeight?: number | string;
16
18
  minHeight?: number | string;
19
+ type?: string;
17
20
  }
@@ -22,11 +22,15 @@ export declare class GridColumn extends Column implements IGridColumn {
22
22
  cssClass?: string | undefined;
23
23
  cssStyle?: string | object | undefined;
24
24
  events?: import("..").IComponentEvents<import("@zeedhi/core").IEventParam<any>> | undefined;
25
+ directives?: import("..").IComponentDirectives | undefined;
25
26
  isVisible?: string | boolean | undefined;
26
27
  dark?: boolean | undefined;
27
28
  light?: boolean | undefined;
28
29
  keyMap?: import("@zeedhi/core").IKeyMap<import("@zeedhi/core").IEventParam<any>> | undefined;
29
- name: string;
30
+ name: string; /**
31
+ * Creates a new Grid Column.
32
+ * @param props Grid column properties
33
+ */
30
34
  parent?: import("..").Component | undefined;
31
35
  }[];
32
36
  /**
@@ -98,10 +98,6 @@ export declare class Input extends ComponentRender implements IInput {
98
98
  * Used to watch a value from store.
99
99
  */
100
100
  storePath: string;
101
- /**
102
- * Internal input value.
103
- */
104
- value: any;
105
101
  /**
106
102
  * Input validations.
107
103
  */
@@ -120,6 +116,8 @@ export declare class Input extends ComponentRender implements IInput {
120
116
  private parsedValidations;
121
117
  protected formatterFn: Function;
122
118
  protected parserFn: Function;
119
+ protected internalDisplayValue: string;
120
+ protected internalValue: any;
123
121
  /**
124
122
  * Creates a new Input.
125
123
  * @param props Input properties
@@ -166,6 +164,11 @@ export declare class Input extends ComponentRender implements IInput {
166
164
  * Updates input rules.
167
165
  */
168
166
  private updateRules;
167
+ /**
168
+ * Input value.
169
+ */
170
+ get value(): any;
171
+ set value(value: any);
169
172
  /**
170
173
  * Input displayed value.
171
174
  */
@@ -9,6 +9,7 @@ export interface ISelect extends ITextInput {
9
9
  dataValue?: string;
10
10
  dataDisabled?: string;
11
11
  menuMaxHeight?: string | number;
12
+ menuMaxWidth?: string | number;
12
13
  preventLoadOnFocus?: boolean;
13
14
  returnObject?: boolean;
14
15
  itemBeforeSlot?: IComponentRender[];
@@ -42,6 +42,10 @@ export declare class Select extends TextInput implements ISelect {
42
42
  * Maximum height of select menu
43
43
  */
44
44
  menuMaxHeight: string | number;
45
+ /**
46
+ * Maximum width of select menu
47
+ */
48
+ menuMaxWidth: string | number;
45
49
  /**
46
50
  * Input select value
47
51
  */
@@ -13,6 +13,7 @@ export interface ITabsEvents<T = ITabsEventParam | ITabsBeforeChangeEventParam |
13
13
  export interface ITab extends IComponent {
14
14
  tabTitle: string;
15
15
  disabled?: boolean;
16
+ flex?: boolean;
16
17
  }
17
18
  export interface ITabs extends IComponentRender {
18
19
  activeTab?: number;
@@ -6,6 +6,10 @@ import { Component } from '../zd-component/component';
6
6
  export declare class Tab extends Component implements ITab {
7
7
  disabled: boolean;
8
8
  tabTitle: string;
9
+ /**
10
+ * Defines if is flex mode.
11
+ */
12
+ flex?: boolean;
9
13
  /**
10
14
  * Create a new Tab.
11
15
  * @param props Tab properties