@zeedhi/common 1.47.0 → 1.48.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,39 @@ 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
+ let { mask } = this;
1798
+ if (mask) {
1799
+ if (typeof mask === 'function') {
1800
+ mask = mask(this.internalValue);
1801
+ }
1802
+ this.internalDisplayValue = Mask.convertAll(mask, value);
1803
+ this.internalValue = this.parser(this.internalDisplayValue);
1804
+ }
1805
+ else {
1806
+ this.internalDisplayValue = value;
1807
+ }
1808
+ }
1778
1809
  }
1779
1810
  /**
1780
1811
  * Retrieves a formatted value.
@@ -2863,6 +2894,7 @@ class Dashboard extends ComponentRender {
2863
2894
  this.cards = [];
2864
2895
  /* Card ID to be deleted */
2865
2896
  this.deleteCardId = '';
2897
+ this.overrideNamedProps = {};
2866
2898
  /* Remove the paddings of the dashboard */
2867
2899
  this.removePadding = false;
2868
2900
  /* Height of the dashboard */
@@ -3071,6 +3103,7 @@ class Dashboard extends ComponentRender {
3071
3103
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3072
3104
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3073
3105
  this.cards = props.cards || this.cards;
3106
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3074
3107
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3075
3108
  this.height = this.getInitValue('height', props.height, this.height);
3076
3109
  this.heightAdjust = this.getInitValue('heightAdjust', props.heightAdjust, this.heightAdjust);
@@ -3208,6 +3241,7 @@ class Dashboard extends ComponentRender {
3208
3241
  component: 'ZdFrame',
3209
3242
  path: card.path,
3210
3243
  local: card.local,
3244
+ overrideNamedProps: card.overrideNamedProps,
3211
3245
  };
3212
3246
  }
3213
3247
  /* Return footer rightSlot props for view layer */
@@ -3388,12 +3422,12 @@ class Date$1 extends TextInput {
3388
3422
  }
3389
3423
  }
3390
3424
  get displayValue() {
3391
- return this.formatter(this.value);
3425
+ return this.internalDisplayValue;
3392
3426
  }
3393
3427
  set displayValue(newValue) {
3394
3428
  this.dateError = false;
3395
- const dateValue = newValue;
3396
- this.value = this.parser(dateValue);
3429
+ this.internalDisplayValue = newValue;
3430
+ this.internalValue = this.parser(newValue);
3397
3431
  }
3398
3432
  /**
3399
3433
  * Assign the updated mask to mask property
@@ -3418,14 +3452,16 @@ class Date$1 extends TextInput {
3418
3452
  setDateValue(displayValue) {
3419
3453
  const lastValue = this.displayValue;
3420
3454
  if (this.isValidDate(displayValue, this.displayFormat)) {
3421
- this.displayValue = displayValue;
3455
+ this.internalDisplayValue = displayValue;
3456
+ this.internalValue = this.parser(displayValue);
3422
3457
  this.dateError = false;
3423
3458
  if (lastValue !== this.displayValue)
3424
3459
  this.change(this.value);
3425
3460
  }
3426
3461
  else {
3427
3462
  if (!displayValue) {
3428
- this.displayValue = displayValue;
3463
+ this.internalDisplayValue = displayValue;
3464
+ this.internalValue = null;
3429
3465
  if (lastValue !== this.displayValue)
3430
3466
  this.change(this.value);
3431
3467
  }
@@ -3469,7 +3505,7 @@ class Date$1 extends TextInput {
3469
3505
  }
3470
3506
  blur(event, element) {
3471
3507
  this.removeDateMask();
3472
- this.setDateValue(this.displayValue);
3508
+ this.setDateValue(this.formatter(this.value));
3473
3509
  super.blur(event, element);
3474
3510
  this.showDatePicker = false;
3475
3511
  }
@@ -3485,6 +3521,7 @@ class Date$1 extends TextInput {
3485
3521
  return;
3486
3522
  setTimeout(() => {
3487
3523
  this.mask = this.initialMask;
3524
+ this.internalDisplayValue = dayjs(this.value, this.dateFormat).format(this.inputFormat || this.displayFormat);
3488
3525
  });
3489
3526
  }
3490
3527
  /**
@@ -3727,15 +3764,15 @@ class DateRange extends TextInput {
3727
3764
  formatter(value) { return this.formatterFn(value, this); }
3728
3765
  parser(value) { return this.parserFn(value, this); }
3729
3766
  get displayValue() {
3730
- return this.formatter(this.value);
3767
+ return this.internalDisplayValue;
3731
3768
  }
3732
3769
  set displayValue(newValue) {
3733
3770
  this.dateError = false;
3734
- const dateValue = newValue;
3735
- if (dateValue)
3736
- this.value = this.parser(dateValue);
3771
+ this.internalDisplayValue = newValue;
3772
+ if (newValue)
3773
+ this.internalValue = this.parser(newValue);
3737
3774
  else
3738
- this.value = [];
3775
+ this.internalValue = [];
3739
3776
  }
3740
3777
  /**
3741
3778
  * Assign the updated mask to mask property
@@ -3761,14 +3798,16 @@ class DateRange extends TextInput {
3761
3798
  const lastValue = this.displayValue;
3762
3799
  const values = this.splitValues(displayValue);
3763
3800
  if (this.isValidDateArray(this.displayFormat, values)) {
3764
- this.displayValue = displayValue;
3801
+ this.internalDisplayValue = displayValue;
3802
+ this.internalValue = this.parser(displayValue);
3765
3803
  this.dateError = false;
3766
3804
  if (lastValue !== this.displayValue)
3767
3805
  this.change(this.value);
3768
3806
  }
3769
3807
  else {
3770
3808
  if (!displayValue) {
3771
- this.displayValue = displayValue;
3809
+ this.internalDisplayValue = displayValue;
3810
+ this.internalValue = [];
3772
3811
  if (lastValue !== this.displayValue)
3773
3812
  this.change(this.value);
3774
3813
  }
@@ -3844,11 +3883,13 @@ class DateRange extends TextInput {
3844
3883
  }
3845
3884
  }
3846
3885
  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;
3886
+ if (this.value) {
3887
+ this.value = this.sortDates(this.value);
3888
+ this.removeDateMask();
3889
+ this.setDateValue(this.formatter(this.value));
3890
+ super.blur(event, element);
3891
+ this.showDatePicker = false;
3892
+ }
3852
3893
  }
3853
3894
  focus(event, element) {
3854
3895
  this.addDateMask();
@@ -3862,6 +3903,13 @@ class DateRange extends TextInput {
3862
3903
  return;
3863
3904
  setTimeout(() => {
3864
3905
  this.mask = this.initialMask;
3906
+ const firstDate = this.value[0]
3907
+ ? dayjs(this.value[0], this.dateFormat).format(this.inputFormat || this.displayFormat)
3908
+ : '';
3909
+ const lastDate = this.value[1]
3910
+ ? dayjs(this.value[1], this.dateFormat).format(this.inputFormat || this.displayFormat)
3911
+ : '';
3912
+ this.internalDisplayValue = `${firstDate}${lastDate ? this.splitter : ''}${lastDate}`;
3865
3913
  });
3866
3914
  }
3867
3915
  /**
@@ -4364,6 +4412,7 @@ class Frame extends ComponentRender {
4364
4412
  this.local = false;
4365
4413
  this.metadata = {};
4366
4414
  this.override = {};
4415
+ this.overrideNamedProps = {};
4367
4416
  this.cache = false;
4368
4417
  this.cacheDuration = 2 * 60 * 60 * 1000;
4369
4418
  this.height = 'auto';
@@ -4373,6 +4422,7 @@ class Frame extends ComponentRender {
4373
4422
  this.path = props.path;
4374
4423
  this.local = props.local === true;
4375
4424
  this.override = props.override || this.override;
4425
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
4376
4426
  this.cache = props.cache || this.cache;
4377
4427
  this.cacheDuration = this.getInitValue('cacheDuration', props.cacheDuration, this.cacheDuration);
4378
4428
  this.height = this.getInitValue('height', props.height, this.height);
@@ -4388,6 +4438,9 @@ class Frame extends ComponentRender {
4388
4438
  if (typeof page !== 'object')
4389
4439
  throw new Error();
4390
4440
  this.metadata = merge(page, this.override);
4441
+ if (Object.keys(this.overrideNamedProps).length !== 0) {
4442
+ this.metadata = this.overrideNamedPropsFunc(this.metadata);
4443
+ }
4391
4444
  }
4392
4445
  catch (_a) {
4393
4446
  this.notFoundError();
@@ -4398,6 +4451,13 @@ class Frame extends ComponentRender {
4398
4451
  }
4399
4452
  });
4400
4453
  }
4454
+ overrideNamedPropsFunc(metadata) {
4455
+ let strMatadata = JSON.stringify(metadata);
4456
+ Object.keys(this.overrideNamedProps).forEach((key) => {
4457
+ strMatadata = strMatadata.replace(RegExp(`<<${key}>>`, 'g'), this.overrideNamedProps[key]);
4458
+ });
4459
+ return JSON.parse(strMatadata);
4460
+ }
4401
4461
  reload() {
4402
4462
  return __awaiter(this, void 0, void 0, function* () {
4403
4463
  this.loading = true;
@@ -6268,6 +6328,10 @@ class Select extends TextInput {
6268
6328
  * Maximum height of select menu
6269
6329
  */
6270
6330
  this.menuMaxHeight = 304;
6331
+ /**
6332
+ * Maximum width of select menu
6333
+ */
6334
+ this.menuMaxWidth = 'auto';
6271
6335
  /**
6272
6336
  * Input select value
6273
6337
  */
@@ -6327,6 +6391,7 @@ class Select extends TextInput {
6327
6391
  this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
6328
6392
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
6329
6393
  this.menuMaxHeight = this.getInitValue('menuMaxHeight', props.menuMaxHeight, this.menuMaxHeight);
6394
+ this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
6330
6395
  this.returnObject = this.getInitValue('returnObject', props.returnObject, this.returnObject);
6331
6396
  this.autocomplete = this.getInitValue('autocomplete', props.autocomplete, this.autocomplete);
6332
6397
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
@@ -6422,8 +6487,10 @@ class Select extends TextInput {
6422
6487
  getItemsBySearchValue(value, searchIn) {
6423
6488
  return __awaiter(this, void 0, void 0, function* () {
6424
6489
  const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true });
6490
+ this.datasource.loading = true;
6425
6491
  const datasource = DatasourceFactory.factory(config);
6426
6492
  const items = yield datasource.get();
6493
+ this.datasource.loading = false;
6427
6494
  datasource.destroy();
6428
6495
  return items.find(this.getCondition(value));
6429
6496
  });
@@ -9372,23 +9439,21 @@ class SelectTree extends TextInput {
9372
9439
  return this.selectValue;
9373
9440
  }
9374
9441
  set value(value) {
9375
- this.selectValue = value;
9442
+ this.setValue(value);
9376
9443
  }
9377
9444
  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
- }
9445
+ let val = value;
9446
+ if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9447
+ val = value[this.dataValue];
9385
9448
  }
9386
- else if (typeof value === 'object') {
9387
- this.value = value[this.dataValue];
9449
+ else if (!value && value !== 0) {
9450
+ val = null;
9388
9451
  }
9389
- else {
9390
- this.value = value;
9452
+ if (this.returnObject) {
9453
+ this.selectValue = val ? { id: val } : null;
9454
+ return;
9391
9455
  }
9456
+ this.selectValue = val;
9392
9457
  }
9393
9458
  }
9394
9459
 
@@ -9811,6 +9876,7 @@ class Tab extends Component {
9811
9876
  this.tabTitle = '';
9812
9877
  this.tabTitle = this.getInitValue('tabTitle', props.tabTitle, this.tabTitle);
9813
9878
  this.disabled = this.getInitValue('disabled', props.disabled, this.disabled);
9879
+ this.flex = this.getInitValue('flex', props.flex, this.flex);
9814
9880
  this.createAccessors();
9815
9881
  }
9816
9882
  }
@@ -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,39 @@
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
+ let { mask } = this;
1805
+ if (mask) {
1806
+ if (typeof mask === 'function') {
1807
+ mask = mask(this.internalValue);
1808
+ }
1809
+ this.internalDisplayValue = core.Mask.convertAll(mask, value);
1810
+ this.internalValue = this.parser(this.internalDisplayValue);
1811
+ }
1812
+ else {
1813
+ this.internalDisplayValue = value;
1814
+ }
1815
+ }
1785
1816
  }
1786
1817
  /**
1787
1818
  * Retrieves a formatted value.
@@ -2870,6 +2901,7 @@
2870
2901
  this.cards = [];
2871
2902
  /* Card ID to be deleted */
2872
2903
  this.deleteCardId = '';
2904
+ this.overrideNamedProps = {};
2873
2905
  /* Remove the paddings of the dashboard */
2874
2906
  this.removePadding = false;
2875
2907
  /* Height of the dashboard */
@@ -3078,6 +3110,7 @@
3078
3110
  this.editingMode = this.getInitValue('editingMode', props.editingMode, this.editingMode);
3079
3111
  this.moveMode = this.getInitValue('moveMode', props.moveMode, this.moveMode);
3080
3112
  this.cards = props.cards || this.cards;
3113
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
3081
3114
  this.removePadding = this.getInitValue('removePadding', props.removePadding, this.removePadding);
3082
3115
  this.height = this.getInitValue('height', props.height, this.height);
3083
3116
  this.heightAdjust = this.getInitValue('heightAdjust', props.heightAdjust, this.heightAdjust);
@@ -3215,6 +3248,7 @@
3215
3248
  component: 'ZdFrame',
3216
3249
  path: card.path,
3217
3250
  local: card.local,
3251
+ overrideNamedProps: card.overrideNamedProps,
3218
3252
  };
3219
3253
  }
3220
3254
  /* Return footer rightSlot props for view layer */
@@ -3395,12 +3429,12 @@
3395
3429
  }
3396
3430
  }
3397
3431
  get displayValue() {
3398
- return this.formatter(this.value);
3432
+ return this.internalDisplayValue;
3399
3433
  }
3400
3434
  set displayValue(newValue) {
3401
3435
  this.dateError = false;
3402
- const dateValue = newValue;
3403
- this.value = this.parser(dateValue);
3436
+ this.internalDisplayValue = newValue;
3437
+ this.internalValue = this.parser(newValue);
3404
3438
  }
3405
3439
  /**
3406
3440
  * Assign the updated mask to mask property
@@ -3425,14 +3459,16 @@
3425
3459
  setDateValue(displayValue) {
3426
3460
  const lastValue = this.displayValue;
3427
3461
  if (this.isValidDate(displayValue, this.displayFormat)) {
3428
- this.displayValue = displayValue;
3462
+ this.internalDisplayValue = displayValue;
3463
+ this.internalValue = this.parser(displayValue);
3429
3464
  this.dateError = false;
3430
3465
  if (lastValue !== this.displayValue)
3431
3466
  this.change(this.value);
3432
3467
  }
3433
3468
  else {
3434
3469
  if (!displayValue) {
3435
- this.displayValue = displayValue;
3470
+ this.internalDisplayValue = displayValue;
3471
+ this.internalValue = null;
3436
3472
  if (lastValue !== this.displayValue)
3437
3473
  this.change(this.value);
3438
3474
  }
@@ -3476,7 +3512,7 @@
3476
3512
  }
3477
3513
  blur(event, element) {
3478
3514
  this.removeDateMask();
3479
- this.setDateValue(this.displayValue);
3515
+ this.setDateValue(this.formatter(this.value));
3480
3516
  super.blur(event, element);
3481
3517
  this.showDatePicker = false;
3482
3518
  }
@@ -3492,6 +3528,7 @@
3492
3528
  return;
3493
3529
  setTimeout(() => {
3494
3530
  this.mask = this.initialMask;
3531
+ this.internalDisplayValue = core.dayjs(this.value, this.dateFormat).format(this.inputFormat || this.displayFormat);
3495
3532
  });
3496
3533
  }
3497
3534
  /**
@@ -3734,15 +3771,15 @@
3734
3771
  formatter(value) { return this.formatterFn(value, this); }
3735
3772
  parser(value) { return this.parserFn(value, this); }
3736
3773
  get displayValue() {
3737
- return this.formatter(this.value);
3774
+ return this.internalDisplayValue;
3738
3775
  }
3739
3776
  set displayValue(newValue) {
3740
3777
  this.dateError = false;
3741
- const dateValue = newValue;
3742
- if (dateValue)
3743
- this.value = this.parser(dateValue);
3778
+ this.internalDisplayValue = newValue;
3779
+ if (newValue)
3780
+ this.internalValue = this.parser(newValue);
3744
3781
  else
3745
- this.value = [];
3782
+ this.internalValue = [];
3746
3783
  }
3747
3784
  /**
3748
3785
  * Assign the updated mask to mask property
@@ -3768,14 +3805,16 @@
3768
3805
  const lastValue = this.displayValue;
3769
3806
  const values = this.splitValues(displayValue);
3770
3807
  if (this.isValidDateArray(this.displayFormat, values)) {
3771
- this.displayValue = displayValue;
3808
+ this.internalDisplayValue = displayValue;
3809
+ this.internalValue = this.parser(displayValue);
3772
3810
  this.dateError = false;
3773
3811
  if (lastValue !== this.displayValue)
3774
3812
  this.change(this.value);
3775
3813
  }
3776
3814
  else {
3777
3815
  if (!displayValue) {
3778
- this.displayValue = displayValue;
3816
+ this.internalDisplayValue = displayValue;
3817
+ this.internalValue = [];
3779
3818
  if (lastValue !== this.displayValue)
3780
3819
  this.change(this.value);
3781
3820
  }
@@ -3851,11 +3890,13 @@
3851
3890
  }
3852
3891
  }
3853
3892
  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;
3893
+ if (this.value) {
3894
+ this.value = this.sortDates(this.value);
3895
+ this.removeDateMask();
3896
+ this.setDateValue(this.formatter(this.value));
3897
+ super.blur(event, element);
3898
+ this.showDatePicker = false;
3899
+ }
3859
3900
  }
3860
3901
  focus(event, element) {
3861
3902
  this.addDateMask();
@@ -3869,6 +3910,13 @@
3869
3910
  return;
3870
3911
  setTimeout(() => {
3871
3912
  this.mask = this.initialMask;
3913
+ const firstDate = this.value[0]
3914
+ ? core.dayjs(this.value[0], this.dateFormat).format(this.inputFormat || this.displayFormat)
3915
+ : '';
3916
+ const lastDate = this.value[1]
3917
+ ? core.dayjs(this.value[1], this.dateFormat).format(this.inputFormat || this.displayFormat)
3918
+ : '';
3919
+ this.internalDisplayValue = `${firstDate}${lastDate ? this.splitter : ''}${lastDate}`;
3872
3920
  });
3873
3921
  }
3874
3922
  /**
@@ -4371,6 +4419,7 @@
4371
4419
  this.local = false;
4372
4420
  this.metadata = {};
4373
4421
  this.override = {};
4422
+ this.overrideNamedProps = {};
4374
4423
  this.cache = false;
4375
4424
  this.cacheDuration = 2 * 60 * 60 * 1000;
4376
4425
  this.height = 'auto';
@@ -4380,6 +4429,7 @@
4380
4429
  this.path = props.path;
4381
4430
  this.local = props.local === true;
4382
4431
  this.override = props.override || this.override;
4432
+ this.overrideNamedProps = props.overrideNamedProps || this.overrideNamedProps;
4383
4433
  this.cache = props.cache || this.cache;
4384
4434
  this.cacheDuration = this.getInitValue('cacheDuration', props.cacheDuration, this.cacheDuration);
4385
4435
  this.height = this.getInitValue('height', props.height, this.height);
@@ -4395,6 +4445,9 @@
4395
4445
  if (typeof page !== 'object')
4396
4446
  throw new Error();
4397
4447
  this.metadata = merge__default["default"](page, this.override);
4448
+ if (Object.keys(this.overrideNamedProps).length !== 0) {
4449
+ this.metadata = this.overrideNamedPropsFunc(this.metadata);
4450
+ }
4398
4451
  }
4399
4452
  catch (_a) {
4400
4453
  this.notFoundError();
@@ -4405,6 +4458,13 @@
4405
4458
  }
4406
4459
  });
4407
4460
  }
4461
+ overrideNamedPropsFunc(metadata) {
4462
+ let strMatadata = JSON.stringify(metadata);
4463
+ Object.keys(this.overrideNamedProps).forEach((key) => {
4464
+ strMatadata = strMatadata.replace(RegExp(`<<${key}>>`, 'g'), this.overrideNamedProps[key]);
4465
+ });
4466
+ return JSON.parse(strMatadata);
4467
+ }
4408
4468
  reload() {
4409
4469
  return __awaiter(this, void 0, void 0, function* () {
4410
4470
  this.loading = true;
@@ -6275,6 +6335,10 @@
6275
6335
  * Maximum height of select menu
6276
6336
  */
6277
6337
  this.menuMaxHeight = 304;
6338
+ /**
6339
+ * Maximum width of select menu
6340
+ */
6341
+ this.menuMaxWidth = 'auto';
6278
6342
  /**
6279
6343
  * Input select value
6280
6344
  */
@@ -6334,6 +6398,7 @@
6334
6398
  this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
6335
6399
  this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
6336
6400
  this.menuMaxHeight = this.getInitValue('menuMaxHeight', props.menuMaxHeight, this.menuMaxHeight);
6401
+ this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
6337
6402
  this.returnObject = this.getInitValue('returnObject', props.returnObject, this.returnObject);
6338
6403
  this.autocomplete = this.getInitValue('autocomplete', props.autocomplete, this.autocomplete);
6339
6404
  this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
@@ -6429,8 +6494,10 @@
6429
6494
  getItemsBySearchValue(value, searchIn) {
6430
6495
  return __awaiter(this, void 0, void 0, function* () {
6431
6496
  const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true });
6497
+ this.datasource.loading = true;
6432
6498
  const datasource = core.DatasourceFactory.factory(config);
6433
6499
  const items = yield datasource.get();
6500
+ this.datasource.loading = false;
6434
6501
  datasource.destroy();
6435
6502
  return items.find(this.getCondition(value));
6436
6503
  });
@@ -9379,23 +9446,21 @@
9379
9446
  return this.selectValue;
9380
9447
  }
9381
9448
  set value(value) {
9382
- this.selectValue = value;
9449
+ this.setValue(value);
9383
9450
  }
9384
9451
  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
- }
9452
+ let val = value;
9453
+ if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9454
+ val = value[this.dataValue];
9392
9455
  }
9393
- else if (typeof value === 'object') {
9394
- this.value = value[this.dataValue];
9456
+ else if (!value && value !== 0) {
9457
+ val = null;
9395
9458
  }
9396
- else {
9397
- this.value = value;
9459
+ if (this.returnObject) {
9460
+ this.selectValue = val ? { id: val } : null;
9461
+ return;
9398
9462
  }
9463
+ this.selectValue = val;
9399
9464
  }
9400
9465
  }
9401
9466
 
@@ -9818,6 +9883,7 @@
9818
9883
  this.tabTitle = '';
9819
9884
  this.tabTitle = this.getInitValue('tabTitle', props.tabTitle, this.tabTitle);
9820
9885
  this.disabled = this.getInitValue('disabled', props.disabled, this.disabled);
9886
+ this.flex = this.getInitValue('flex', props.flex, this.flex);
9821
9887
  this.createAccessors();
9822
9888
  }
9823
9889
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.47.0",
3
+ "version": "1.48.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": "8f588b928efe593c47681477f44ac419b28fbabc"
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,7 @@ export declare class Frame extends ComponentRender implements IFrame {
8
8
  local: boolean;
9
9
  metadata: Object;
10
10
  override: Object;
11
+ overrideNamedProps: any;
11
12
  path: string;
12
13
  cache: boolean;
13
14
  events: IFrameEvents;
@@ -23,6 +24,7 @@ export declare class Frame extends ComponentRender implements IFrame {
23
24
  */
24
25
  constructor(props: IFrame);
25
26
  private getMetadata;
27
+ overrideNamedPropsFunc(metadata: object): any;
26
28
  reload(): Promise<void>;
27
29
  protected notFoundError(): void;
28
30
  private requestPage;
@@ -9,6 +9,7 @@ export interface IFrame extends IComponentRender {
9
9
  path: string;
10
10
  local?: boolean;
11
11
  override?: Object;
12
+ overrideNamedProps?: any;
12
13
  cache?: boolean;
13
14
  cacheDuration?: number;
14
15
  height?: number | string;
@@ -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