@zeedhi/common 1.44.0 → 1.45.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.
Files changed (41) hide show
  1. package/dist/zd-common.esm.js +233 -70
  2. package/dist/zd-common.umd.js +233 -70
  3. package/package.json +2 -2
  4. package/types/components/zd-button-group/button-group.d.ts +1 -1
  5. package/types/components/zd-carousel/carousel.d.ts +2 -2
  6. package/types/components/zd-carousel/interfaces.d.ts +1 -1
  7. package/types/components/zd-collapse-card/collapse-card.d.ts +1 -1
  8. package/types/components/zd-component/component.d.ts +5 -4
  9. package/types/components/zd-dashboard/dashboard.d.ts +1 -1
  10. package/types/components/zd-date/date-range.d.ts +4 -4
  11. package/types/components/zd-date/date.d.ts +5 -5
  12. package/types/components/zd-file-input/file-input.d.ts +3 -3
  13. package/types/components/zd-form/form.d.ts +2 -2
  14. package/types/components/zd-frame/frame.d.ts +1 -1
  15. package/types/components/zd-grid/grid-editable.d.ts +6 -6
  16. package/types/components/zd-grid/grid.d.ts +5 -5
  17. package/types/components/zd-increment/increment.d.ts +2 -2
  18. package/types/components/zd-input/input.d.ts +6 -6
  19. package/types/components/zd-iterable/iterable-page-component.d.ts +1 -1
  20. package/types/components/zd-iterable/iterable-page-size.d.ts +2 -2
  21. package/types/components/zd-iterable/iterable.d.ts +1 -1
  22. package/types/components/zd-login/login-button.d.ts +1 -1
  23. package/types/components/zd-master-detail/master-detail.d.ts +1 -1
  24. package/types/components/zd-menu/menu-group.d.ts +1 -1
  25. package/types/components/zd-menu/menu-link.d.ts +1 -1
  26. package/types/components/zd-menu/menu.d.ts +1 -1
  27. package/types/components/zd-select/select.d.ts +5 -5
  28. package/types/components/zd-select-multiple/select-multiple.d.ts +2 -2
  29. package/types/components/zd-select-tree/select-tree.d.ts +6 -6
  30. package/types/components/zd-select-tree-multiple/select-tree-multiple.d.ts +2 -2
  31. package/types/components/zd-selectable-list/selectable-list.d.ts +1 -1
  32. package/types/components/zd-svg-map/svg-map.d.ts +1 -1
  33. package/types/components/zd-tabs/tabs.d.ts +2 -2
  34. package/types/components/zd-text-input/text-input.d.ts +4 -4
  35. package/types/components/zd-time/time.d.ts +1 -1
  36. package/types/components/zd-tree/interfaces.d.ts +4 -0
  37. package/types/components/zd-tree/tree.d.ts +39 -11
  38. package/types/components/zd-tree-grid/tree-grid-editable.d.ts +6 -6
  39. package/types/components/zd-tree-grid/tree-grid.d.ts +2 -2
  40. package/types/services/zd-loading/loading-service.d.ts +7 -1
  41. package/types/utils/themes/themes.d.ts +8 -2
@@ -192,6 +192,7 @@ class Component {
192
192
  * @param element Element mounted reference
193
193
  */
194
194
  onMounted(element) {
195
+ this.element = element;
195
196
  if (Object.keys(this.keyMap).length) {
196
197
  KeyMap.bind(this.keyMap, this, element);
197
198
  }
@@ -219,7 +220,11 @@ class Component {
219
220
  * @param element Element clicked
220
221
  */
221
222
  click(event, element) {
222
- this.callEvent('click', { event, element, component: this });
223
+ this.callEvent('click', {
224
+ event: (event || new MouseEvent('click')),
225
+ element: (element || this.element),
226
+ component: this,
227
+ });
223
228
  }
224
229
  /**
225
230
  * Triggered when the component is focused.
@@ -552,7 +557,10 @@ class ApexChart extends ComponentRender {
552
557
  */
553
558
  clickEvent(event, chartContext, config) {
554
559
  this.callEvent('chartClick', {
555
- event, component: this, chartContext, config,
560
+ event: (event || new MouseEvent('click')),
561
+ component: this,
562
+ chartContext,
563
+ config,
556
564
  });
557
565
  }
558
566
  /**
@@ -1642,9 +1650,9 @@ class Input extends ComponentRender {
1642
1650
  */
1643
1651
  this.storePath = '';
1644
1652
  /**
1645
- * Input value.
1646
- */
1647
- this.value = undefined;
1653
+ * Internal input value.
1654
+ */
1655
+ this.value = null;
1648
1656
  /**
1649
1657
  * Input validations.
1650
1658
  */
@@ -1792,6 +1800,8 @@ class Input extends ComponentRender {
1792
1800
  * @param element Element clicked
1793
1801
  */
1794
1802
  change(event, element) {
1803
+ if (this.value === '')
1804
+ this.value = null;
1795
1805
  if (this.events.change && typeof this.events.change === 'function') {
1796
1806
  this.events.change({ event, element, component: this });
1797
1807
  }
@@ -2804,61 +2814,34 @@ class ModalService {
2804
2814
  */
2805
2815
  ModalService.modals = [];
2806
2816
 
2807
- class Loading extends Component {
2808
- /*
2809
- * Creates a new Loading Overlay
2810
- * @param props Modal structure
2811
- */
2812
- constructor(props) {
2813
- super(props);
2814
- /**
2815
- * text to show in Loader Overlay
2816
- */
2817
- this.text = 'Loading';
2818
- this.isVisible = false;
2819
- this.zIndex = 999;
2820
- this.text = this.getInitValue('text', props.text, this.text);
2821
- this.zIndex = this.getInitValue('zIndex', props.zIndex, this.zIndex);
2822
- this.defaultText = this.text;
2823
- }
2824
- /**
2825
- * Displays overlay
2826
- */
2827
- show(text) {
2828
- if (text)
2829
- this.text = text;
2830
- else
2831
- this.text = this.defaultText;
2832
- this.isVisible = true;
2833
- }
2834
- /**
2835
- * Close overlay
2836
- */
2837
- hide() {
2838
- this.isVisible = false;
2839
- }
2840
- }
2841
-
2842
2817
  /**
2843
2818
  * Loading Service Class
2844
2819
  */
2845
2820
  class LoadingService {
2821
+ /**
2822
+ * Creates a new loading instance
2823
+ * @param loading loading structure
2824
+ */
2825
+ static create(CreateLoading, props) {
2826
+ const instance = new CreateLoading(props);
2827
+ this.loading = instance;
2828
+ return instance;
2829
+ }
2846
2830
  /**
2847
2831
  * Displays a Loading.
2848
2832
  * If has an opened Loading it will be closed.
2849
2833
  * @param Loading loading structure
2850
2834
  */
2851
2835
  static show(text) {
2852
- this.instance.show(text);
2836
+ this.loading.show(text);
2853
2837
  }
2854
2838
  /**
2855
2839
  * Hides current Loading
2856
2840
  */
2857
2841
  static hide() {
2858
- this.instance.hide();
2842
+ this.loading.hide();
2859
2843
  }
2860
- }
2861
- LoadingService.instance = new Loading({ name: 'loading-instance' });
2844
+ }
2862
2845
 
2863
2846
  /**
2864
2847
  * Base class for Dashboard component.
@@ -3465,8 +3448,9 @@ class Date$1 extends TextInput {
3465
3448
  return !this.dateError || I18n.translate('VALIDATION_INVALID_DATE');
3466
3449
  }
3467
3450
  click(event, element) {
3468
- super.click(event, element);
3469
- if (!event.defaultPrevented) {
3451
+ const clickEvent = event || new MouseEvent('click');
3452
+ super.click(clickEvent, element);
3453
+ if (!clickEvent.defaultPrevented) {
3470
3454
  this.showDatePicker = !this.showDatePicker;
3471
3455
  }
3472
3456
  }
@@ -3814,8 +3798,9 @@ class DateRange extends TextInput {
3814
3798
  return !this.dateError || I18n.translate('VALIDATION_INVALID_DATE');
3815
3799
  }
3816
3800
  click(event, element) {
3817
- super.click(event, element);
3818
- if (!event.defaultPrevented) {
3801
+ const clickEvent = event || new MouseEvent('click');
3802
+ super.click(clickEvent, element);
3803
+ if (!clickEvent.defaultPrevented) {
3819
3804
  this.showDatePicker = !this.showDatePicker;
3820
3805
  }
3821
3806
  }
@@ -4188,7 +4173,7 @@ class FileInput extends TextInput {
4188
4173
  * Triggered when a removable chip is clicked
4189
4174
  * @param event DOM event
4190
4175
  * @param index Chip index
4191
- * @param element HTMLElement
4176
+ * @param element any
4192
4177
  */
4193
4178
  chipClick(event, index, element) {
4194
4179
  event.stopImmediatePropagation();
@@ -7039,6 +7024,41 @@ class ListGroup extends ListItem {
7039
7024
  }
7040
7025
  }
7041
7026
 
7027
+ class Loading extends Component {
7028
+ /*
7029
+ * Creates a new Loading Overlay
7030
+ * @param props Modal structure
7031
+ */
7032
+ constructor(props) {
7033
+ super(props);
7034
+ /**
7035
+ * text to show in Loader Overlay
7036
+ */
7037
+ this.text = 'Loading';
7038
+ this.isVisible = false;
7039
+ this.zIndex = 999;
7040
+ this.text = this.getInitValue('text', props.text, this.text);
7041
+ this.zIndex = this.getInitValue('zIndex', props.zIndex, this.zIndex);
7042
+ this.defaultText = this.text;
7043
+ }
7044
+ /**
7045
+ * Displays overlay
7046
+ */
7047
+ show(text) {
7048
+ if (text)
7049
+ this.text = text;
7050
+ else
7051
+ this.text = this.defaultText;
7052
+ this.isVisible = true;
7053
+ }
7054
+ /**
7055
+ * Close overlay
7056
+ */
7057
+ hide() {
7058
+ this.isVisible = false;
7059
+ }
7060
+ }
7061
+
7042
7062
  /**
7043
7063
  * Base class for Login component.
7044
7064
  */
@@ -7672,9 +7692,12 @@ class MenuLink extends ComponentRender {
7672
7692
  */
7673
7693
  click(event) {
7674
7694
  let preventDefault = false;
7675
- preventDefault = this.callEvent('click', { event, component: this });
7695
+ preventDefault = this.callEvent('click', {
7696
+ event: (event || new MouseEvent('click')),
7697
+ component: this,
7698
+ });
7676
7699
  if (preventDefault) {
7677
- event.preventDefault();
7700
+ event === null || event === void 0 ? void 0 : event.preventDefault();
7678
7701
  }
7679
7702
  this.setFocus();
7680
7703
  }
@@ -7757,9 +7780,12 @@ class MenuGroup extends ComponentRender {
7757
7780
  */
7758
7781
  click(event) {
7759
7782
  let preventDefault = false;
7760
- preventDefault = this.callEvent('click', { event, component: this });
7783
+ preventDefault = this.callEvent('click', {
7784
+ event: (event || new MouseEvent('click')),
7785
+ component: this,
7786
+ });
7761
7787
  if (preventDefault) {
7762
- event.preventDefault();
7788
+ event === null || event === void 0 ? void 0 : event.preventDefault();
7763
7789
  }
7764
7790
  this.setFocus();
7765
7791
  }
@@ -10130,8 +10156,11 @@ class Time extends TextInput {
10130
10156
  || I18n.translate('VALIDATION_TIME_NOT_ALLOWED');
10131
10157
  }
10132
10158
  click(event) {
10133
- this.callEvent('click', { event, component: this });
10134
- if (!event.defaultPrevented) {
10159
+ this.callEvent('click', {
10160
+ event: (event || new MouseEvent('click')),
10161
+ component: this,
10162
+ });
10163
+ if (!(event === null || event === void 0 ? void 0 : event.defaultPrevented)) {
10135
10164
  this.showTimePicker = !this.showTimePicker;
10136
10165
  }
10137
10166
  }
@@ -10257,6 +10286,10 @@ class Tree extends ComponentRender {
10257
10286
  * Components that will be rendered on toolbar slot
10258
10287
  */
10259
10288
  this.toolbarSlot = [];
10289
+ /**
10290
+ * Components that will be rendered on title slot
10291
+ */
10292
+ this.titleSlot = [];
10260
10293
  /** Datasource parent field */
10261
10294
  this.parentField = '';
10262
10295
  /** Datasource title field */
@@ -10267,11 +10300,21 @@ class Tree extends ComponentRender {
10267
10300
  * Defines if the tree will be opened or not (true/false) or if it should open only until a specific level
10268
10301
  */
10269
10302
  this.openLevelOnLoad = false;
10303
+ /**
10304
+ * Allow row check
10305
+ */
10306
+ this.checkbox = false;
10270
10307
  /**
10271
10308
  * Defines if should wait and not execute GET method when Datasource is created
10272
10309
  */
10273
10310
  this.lazyLoad = true;
10274
- this.nodes = props.nodes || this.nodes;
10311
+ /**
10312
+ * Dictionary of nodePath ponting to Dictionary of path pointing to the condition (applied) return value
10313
+ */
10314
+ this.appliedConditions = {};
10315
+ /* Conditions of tree */
10316
+ this.factoredConditions = {};
10317
+ this.nodes = this.initNodes(props.nodes || this.nodes);
10275
10318
  this.itemIconName = this.getInitValue('itemIconName', props.itemIconName, this.itemIconName);
10276
10319
  this.groupIconName = this.getInitValue('groupIconName', props.groupIconName, this.groupIconName);
10277
10320
  this.openedIconName = this.getInitValue('openedIconName', props.openedIconName, this.openedIconName);
@@ -10282,8 +10325,16 @@ class Tree extends ComponentRender {
10282
10325
  this.titleField = this.getInitValue('titleField', props.titleField, this.titleField);
10283
10326
  this.dataField = this.getInitValue('dataField', props.dataField, this.dataField);
10284
10327
  this.openLevelOnLoad = this.getInitValue('openLevelOnLoad', props.openLevelOnLoad, this.openLevelOnLoad);
10328
+ this.checkbox = this.getInitValue('checkbox', props.checkbox, this.checkbox);
10285
10329
  this.afterTitleSlot = props.afterTitleSlot || this.afterTitleSlot;
10286
10330
  this.toolbarSlot = props.toolbarSlot || this.toolbarSlot;
10331
+ this.titleSlot = props.titleSlot || this.titleSlot;
10332
+ if (props.afterTitleSlot) {
10333
+ this.createConditions([props.afterTitleSlot]);
10334
+ }
10335
+ if (props.titleSlot) {
10336
+ this.createConditions(props.titleSlot);
10337
+ }
10287
10338
  if (props.datasource && Object.keys(props.datasource).length) {
10288
10339
  this.lazyLoad = props.datasource.lazyLoad !== false;
10289
10340
  this.datasource = DatasourceFactory.factory(Object.assign(Object.assign({}, props.datasource), { searchIn: props.datasource.searchIn || [this.titleField, this.dataField].filter(Boolean), lazyLoad: true, loadAll: true }));
@@ -10291,6 +10342,12 @@ class Tree extends ComponentRender {
10291
10342
  }
10292
10343
  this.createAccessors();
10293
10344
  }
10345
+ /**
10346
+ * Initialize all the properties of the declared nodes (reactivity)
10347
+ */
10348
+ initNodes(nodes) {
10349
+ return nodes.map((node) => (Object.assign(Object.assign({ isLeaf: false, isExpanded: true, isSelected: false, isDraggable: true, isSelectable: true, isChecked: false }, node), { children: this.initNodes(node.children || []) })));
10350
+ }
10294
10351
  /** Nodes */
10295
10352
  get nodes() {
10296
10353
  return this.nodesValue;
@@ -10301,6 +10358,16 @@ class Tree extends ComponentRender {
10301
10358
  }
10302
10359
  this.nodesValue = value;
10303
10360
  }
10361
+ getCheckedNodes() {
10362
+ const selectedNodes = [];
10363
+ this.tree.traverse((node) => {
10364
+ const instanceNode = this.getNode(node.path || []);
10365
+ if (instanceNode === null || instanceNode === void 0 ? void 0 : instanceNode.isChecked) {
10366
+ selectedNodes.push(instanceNode);
10367
+ }
10368
+ });
10369
+ return selectedNodes;
10370
+ }
10304
10371
  /** Returns the selected nodes */
10305
10372
  get selectedNodes() {
10306
10373
  var _a;
@@ -10399,16 +10466,87 @@ class Tree extends ComponentRender {
10399
10466
  setTree(tree) {
10400
10467
  this.tree = tree;
10401
10468
  }
10402
- /** Get the conditions function to be applied to each column depending on the node */
10403
- getConditions(conditions) {
10404
- const cond = Event.factory(conditions);
10405
- return (node) => {
10406
- const appliedConditions = {};
10407
- Object.keys(conditions).forEach((condition) => {
10408
- appliedConditions[condition] = cond[condition](node);
10409
- });
10410
- return appliedConditions;
10411
- };
10469
+ /**
10470
+ * Return plain conditions object
10471
+ * @param conditions Conditions object
10472
+ * @param parentPath Path to parent property
10473
+ */
10474
+ getPlainConditions(conditions, parentPath = '') {
10475
+ let plainData = {};
10476
+ Object.keys(conditions).forEach((key) => {
10477
+ const fullKey = parentPath ? [parentPath, key].join('.') : key;
10478
+ if (typeof conditions[key] === 'object') {
10479
+ plainData = Object.assign(Object.assign({}, plainData), this.getPlainConditions(conditions[key], fullKey));
10480
+ }
10481
+ else {
10482
+ plainData[fullKey] = conditions[key];
10483
+ }
10484
+ });
10485
+ return plainData;
10486
+ }
10487
+ createConditions(children, parentPath = '') {
10488
+ children.forEach((child) => {
10489
+ const path = parentPath ? `${parentPath}.${child.name}` : child.name;
10490
+ if (child.conditions) {
10491
+ const plainConditions = this.getPlainConditions(child.conditions);
10492
+ this.factoredConditions[path] = Event.factory(plainConditions);
10493
+ }
10494
+ if (child.children) {
10495
+ this.createConditions(child.children, path);
10496
+ }
10497
+ });
10498
+ }
10499
+ applyCondition(node, factoredConditions) {
10500
+ const appliedConditions = {};
10501
+ Object.keys(factoredConditions).forEach((condition) => {
10502
+ const conditionFunction = factoredConditions[condition];
10503
+ set(appliedConditions, condition, conditionFunction(node));
10504
+ });
10505
+ return appliedConditions;
10506
+ }
10507
+ applyChildCondition(node, factoredConditions = this.factoredConditions) {
10508
+ const appliedConditions = {};
10509
+ Object.keys(factoredConditions).forEach((comp) => {
10510
+ const conditions = this.factoredConditions[comp];
10511
+ appliedConditions[comp] = Object.assign({}, this.applyCondition(node, conditions));
10512
+ });
10513
+ return appliedConditions;
10514
+ }
10515
+ reapplyConditions(node) {
10516
+ const nodePath = node.pathStr;
10517
+ if (!nodePath)
10518
+ return {};
10519
+ const appliedConditions = Object.assign({}, this.appliedConditions);
10520
+ appliedConditions[nodePath] = this.applyChildCondition(node);
10521
+ this.appliedConditions = appliedConditions;
10522
+ return this.appliedConditions[nodePath];
10523
+ }
10524
+ getSlotComponent(slot, node, parentPath = '') {
10525
+ const slotArr = Array.isArray(slot) ? slot : [slot];
10526
+ const newComponents = [];
10527
+ slotArr.forEach((component) => {
10528
+ var _a;
10529
+ if (!component)
10530
+ return;
10531
+ const nodePath = node.pathStr;
10532
+ if (!nodePath)
10533
+ return;
10534
+ const compName = component.name;
10535
+ const instanceName = `${compName}_${nodePath}`;
10536
+ const path = parentPath ? `${parentPath}.${compName}` : compName;
10537
+ const newComponent = merge({}, component, (_a = this.appliedConditions[nodePath]) === null || _a === void 0 ? void 0 : _a[path]);
10538
+ const newChildren = this.getSlotComponent(newComponent.children || [], node, path);
10539
+ newComponent.name = instanceName;
10540
+ newComponent.children = newChildren;
10541
+ try {
10542
+ Metadata.updateInstance(instanceName, newComponent);
10543
+ }
10544
+ catch (e) {
10545
+ // do nothing
10546
+ }
10547
+ newComponents.push(newComponent);
10548
+ });
10549
+ return newComponents;
10412
10550
  }
10413
10551
  /** Triggers when dragging nodes have been dropped */
10414
10552
  nodeDrop(nodes, position, event, element) {
@@ -10436,6 +10574,12 @@ class Tree extends ComponentRender {
10436
10574
  event, element, component: this, node,
10437
10575
  });
10438
10576
  }
10577
+ /** Triggers when a node has been checked/unchecked */
10578
+ nodeCheck(node, event, element) {
10579
+ this.callEvent('onNodeCheck', {
10580
+ event, element, component: this, node,
10581
+ });
10582
+ }
10439
10583
  clearSelection(nodes) {
10440
10584
  const nodesArray = nodes || this.nodes;
10441
10585
  nodesArray.forEach((node) => {
@@ -10445,6 +10589,19 @@ class Tree extends ComponentRender {
10445
10589
  }
10446
10590
  });
10447
10591
  }
10592
+ getNode(path) {
10593
+ return this.searchPath(this.nodes, path);
10594
+ }
10595
+ getParentNode(node) {
10596
+ var _a;
10597
+ return this.getNode(((_a = node.path) === null || _a === void 0 ? void 0 : _a.slice(0, -1)) || []);
10598
+ }
10599
+ searchPath(nodes, path) {
10600
+ const currentNode = (path[0] > -1 && path[0] < nodes.length) ? nodes[path[0]] : undefined;
10601
+ if (currentNode && path.length > 1)
10602
+ return this.searchPath(currentNode.children || [], path.slice(1));
10603
+ return currentNode;
10604
+ }
10448
10605
  }
10449
10606
 
10450
10607
  /**
@@ -11182,15 +11339,23 @@ const defaultTheme = {
11182
11339
  zeedhi: {
11183
11340
  light: {
11184
11341
  'font-color': 'var(--v-grey-darken2)',
11185
- 'background-base': '#F6F6F6',
11342
+ 'background-base': '#FDFDFD',
11343
+ 'background-base-2': '#F6F6F6',
11344
+ 'background-base-3': '#EEE',
11186
11345
  'scrollbar-track': 'var(--v-grey-lighten5)',
11187
11346
  'scrollbar-thumb': 'var(--v-grey-lighten4)',
11347
+ 'badge-background-color': '#f44336',
11348
+ 'badge-text-color': '#fff',
11188
11349
  },
11189
11350
  dark: {
11190
11351
  'font-color': 'var(--v-grey-lighten3)',
11191
- 'background-base': '#121212',
11352
+ 'background-base': '#1E1E1E',
11353
+ 'background-base-2': 'var(--v-grey-darken2)',
11354
+ 'background-base-3': 'var(--v-grey-darken4)',
11192
11355
  'scrollbar-track': 'var(--v-grey-darken3)',
11193
11356
  'scrollbar-thumb': 'var(--v-grey-base)',
11357
+ 'badge-background-color': '#f44336',
11358
+ 'badge-text-color': '#fff',
11194
11359
  },
11195
11360
  variables: {
11196
11361
  'default-padding': '16px',
@@ -11208,8 +11373,6 @@ const defaultTheme = {
11208
11373
  'font-body4-weight': '500',
11209
11374
  'font-caption-size': '11px',
11210
11375
  'font-caption-weight': '400',
11211
- 'badge-background-color': '#f44336',
11212
- 'badge-text-color': '#fff',
11213
11376
  },
11214
11377
  },
11215
11378
  };