@zeedhi/common 1.84.1 → 1.85.1

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.
@@ -5540,13 +5540,7 @@ class Iterable extends ComponentRender {
5540
5540
  * Get pagination length
5541
5541
  */
5542
5542
  get paginationLength() {
5543
- let { limit, total } = this.datasource;
5544
- limit = Number(limit);
5545
- total = Number(total);
5546
- if (!limit || Number.isNaN(total) || Number.isNaN(limit)) {
5547
- return 0;
5548
- }
5549
- return Math.ceil(total / limit);
5543
+ return this.datasource.getPaginationLength();
5550
5544
  }
5551
5545
  /**
5552
5546
  * Return cells with conditions applied for each row
@@ -5610,6 +5604,17 @@ class Iterable extends ComponentRender {
5610
5604
  }
5611
5605
  }
5612
5606
 
5607
+ /**
5608
+ * Delete rows error
5609
+ */
5610
+ class DeleteRowsError extends Error {
5611
+ constructor() {
5612
+ super('Grid can\'t automatically delete rows when selectAllPages property is true.'
5613
+ + ' You should delete them manually');
5614
+ this.name = 'DeleteRowsError';
5615
+ }
5616
+ }
5617
+
5613
5618
  /**
5614
5619
  * Base class for Grid column
5615
5620
  */
@@ -5772,17 +5777,6 @@ const toggleableFormatter = ({ value, componentProps }) => {
5772
5777
  FormatterParserProvider.registerFormatter('column_ZdCheckbox', toggleableFormatter);
5773
5778
  FormatterParserProvider.registerFormatter('column_ZdSwitch', toggleableFormatter);
5774
5779
 
5775
- /**
5776
- * Delete rows error
5777
- */
5778
- class DeleteRowsError extends Error {
5779
- constructor() {
5780
- super('Grid can\'t automatically delete rows when selectAllPages property is true.'
5781
- + ' You should delete them manually');
5782
- this.name = 'DeleteRowsError';
5783
- }
5784
- }
5785
-
5786
5780
  /**
5787
5781
  * Base class for Grid component
5788
5782
  */
@@ -6224,16 +6218,9 @@ class Grid extends Iterable {
6224
6218
  const compName = actionComponent.name;
6225
6219
  const instanceName = `${compName}_${rowKey}`;
6226
6220
  const path = parentPath ? `${parentPath}.${compName}` : compName;
6227
- const props = merge({}, actionComponent, (_b = (_a = this.actionsApplied[rowKey]) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b[path]);
6228
- let newClickEvt;
6229
- if ((_c = props.events) === null || _c === void 0 ? void 0 : _c.click) {
6230
- const compEvents = Event.factory(props.events);
6231
- if (typeof compEvents.click === 'function') {
6232
- newClickEvt = ({ component, event, element }) => compEvents.click({
6233
- component, event, element, row, column,
6234
- });
6235
- }
6236
- }
6221
+ const compActivator = (_a = actionComponent.activator) !== null && _a !== void 0 ? _a : undefined;
6222
+ const props = merge({}, actionComponent, (_c = (_b = this.actionsApplied[rowKey]) === null || _b === void 0 ? void 0 : _b[column.name]) === null || _c === void 0 ? void 0 : _c[path]);
6223
+ const newClickEvt = this.setGridRowsInEvents(props, column, row);
6237
6224
  const children = props.children || [];
6238
6225
  const newChildren = children.map((child) => this.getActionProps(child, column, row, path).props);
6239
6226
  props.children = newChildren;
@@ -6253,6 +6240,12 @@ class Grid extends Iterable {
6253
6240
  }
6254
6241
  if (newClickEvt)
6255
6242
  props.events.click = newClickEvt;
6243
+ if (compActivator) {
6244
+ const newActivatorClickEvt = this.setGridRowsInEvents(compActivator, column, row);
6245
+ if (newActivatorClickEvt) {
6246
+ props.activator.events.click = newActivatorClickEvt;
6247
+ }
6248
+ }
6256
6249
  return { props, instance };
6257
6250
  }
6258
6251
  updateActionInstance(instanceName, newComponent) {
@@ -6284,6 +6277,18 @@ class Grid extends Iterable {
6284
6277
  }
6285
6278
  return {};
6286
6279
  }
6280
+ setGridRowsInEvents(comp, column, row) {
6281
+ var _a;
6282
+ if ((_a = comp.events) === null || _a === void 0 ? void 0 : _a.click) {
6283
+ const compEvents = Event.factory(comp.events);
6284
+ if (typeof compEvents.click === 'function') {
6285
+ return ({ component, event, element }) => compEvents.click({
6286
+ component, event, element, row, column,
6287
+ });
6288
+ }
6289
+ }
6290
+ return undefined;
6291
+ }
6287
6292
  }
6288
6293
 
6289
6294
  /**
@@ -7956,6 +7961,7 @@ class Search extends TextInput {
7956
7961
  */
7957
7962
  constructor(props) {
7958
7963
  super(props);
7964
+ this.lazyAttach = false;
7959
7965
  this.debounceSetSearch = debounce(this.setSearch, 500);
7960
7966
  this.iterableComponentName = this.getInitValue('iterableComponentName', props.iterableComponentName, this.iterableComponent);
7961
7967
  this.showHelper = this.getInitValue('showHelper', props.showHelper, false);
@@ -7963,10 +7969,13 @@ class Search extends TextInput {
7963
7969
  this.appendIcon = this.getInitValue('appendIcon', props.appendIcon, 'magnify');
7964
7970
  this.placeholder = this.getInitValue('placeholder', props.placeholder, 'SEARCH');
7965
7971
  this.cssClass = this.getInitValue('cssClass', props.cssClass, 'zd-float-right');
7966
- this.setIterableComponent();
7972
+ this.lazyAttach = this.getInitValue('lazyAttach', props.lazyAttach, this.lazyAttach);
7973
+ if (!this.lazyAttach)
7974
+ this.setIterableComponent();
7967
7975
  this.createAccessors();
7968
7976
  }
7969
- setIterableComponent() {
7977
+ setIterableComponent(name) {
7978
+ this.iterableComponentName = name || this.iterableComponentName;
7970
7979
  if (this.iterableComponentName && Metadata.getInstances(this.iterableComponentName).length > 0) {
7971
7980
  this.iterableComponent = Metadata.getInstance(this.iterableComponentName);
7972
7981
  }
@@ -5547,13 +5547,7 @@
5547
5547
  * Get pagination length
5548
5548
  */
5549
5549
  get paginationLength() {
5550
- let { limit, total } = this.datasource;
5551
- limit = Number(limit);
5552
- total = Number(total);
5553
- if (!limit || Number.isNaN(total) || Number.isNaN(limit)) {
5554
- return 0;
5555
- }
5556
- return Math.ceil(total / limit);
5550
+ return this.datasource.getPaginationLength();
5557
5551
  }
5558
5552
  /**
5559
5553
  * Return cells with conditions applied for each row
@@ -5617,6 +5611,17 @@
5617
5611
  }
5618
5612
  }
5619
5613
 
5614
+ /**
5615
+ * Delete rows error
5616
+ */
5617
+ class DeleteRowsError extends Error {
5618
+ constructor() {
5619
+ super('Grid can\'t automatically delete rows when selectAllPages property is true.'
5620
+ + ' You should delete them manually');
5621
+ this.name = 'DeleteRowsError';
5622
+ }
5623
+ }
5624
+
5620
5625
  /**
5621
5626
  * Base class for Grid column
5622
5627
  */
@@ -5779,17 +5784,6 @@
5779
5784
  core.FormatterParserProvider.registerFormatter('column_ZdCheckbox', toggleableFormatter);
5780
5785
  core.FormatterParserProvider.registerFormatter('column_ZdSwitch', toggleableFormatter);
5781
5786
 
5782
- /**
5783
- * Delete rows error
5784
- */
5785
- class DeleteRowsError extends Error {
5786
- constructor() {
5787
- super('Grid can\'t automatically delete rows when selectAllPages property is true.'
5788
- + ' You should delete them manually');
5789
- this.name = 'DeleteRowsError';
5790
- }
5791
- }
5792
-
5793
5787
  /**
5794
5788
  * Base class for Grid component
5795
5789
  */
@@ -6231,16 +6225,9 @@
6231
6225
  const compName = actionComponent.name;
6232
6226
  const instanceName = `${compName}_${rowKey}`;
6233
6227
  const path = parentPath ? `${parentPath}.${compName}` : compName;
6234
- const props = merge__default["default"]({}, actionComponent, (_b = (_a = this.actionsApplied[rowKey]) === null || _a === void 0 ? void 0 : _a[column.name]) === null || _b === void 0 ? void 0 : _b[path]);
6235
- let newClickEvt;
6236
- if ((_c = props.events) === null || _c === void 0 ? void 0 : _c.click) {
6237
- const compEvents = core.Event.factory(props.events);
6238
- if (typeof compEvents.click === 'function') {
6239
- newClickEvt = ({ component, event, element }) => compEvents.click({
6240
- component, event, element, row, column,
6241
- });
6242
- }
6243
- }
6228
+ const compActivator = (_a = actionComponent.activator) !== null && _a !== void 0 ? _a : undefined;
6229
+ const props = merge__default["default"]({}, actionComponent, (_c = (_b = this.actionsApplied[rowKey]) === null || _b === void 0 ? void 0 : _b[column.name]) === null || _c === void 0 ? void 0 : _c[path]);
6230
+ const newClickEvt = this.setGridRowsInEvents(props, column, row);
6244
6231
  const children = props.children || [];
6245
6232
  const newChildren = children.map((child) => this.getActionProps(child, column, row, path).props);
6246
6233
  props.children = newChildren;
@@ -6260,6 +6247,12 @@
6260
6247
  }
6261
6248
  if (newClickEvt)
6262
6249
  props.events.click = newClickEvt;
6250
+ if (compActivator) {
6251
+ const newActivatorClickEvt = this.setGridRowsInEvents(compActivator, column, row);
6252
+ if (newActivatorClickEvt) {
6253
+ props.activator.events.click = newActivatorClickEvt;
6254
+ }
6255
+ }
6263
6256
  return { props, instance };
6264
6257
  }
6265
6258
  updateActionInstance(instanceName, newComponent) {
@@ -6291,6 +6284,18 @@
6291
6284
  }
6292
6285
  return {};
6293
6286
  }
6287
+ setGridRowsInEvents(comp, column, row) {
6288
+ var _a;
6289
+ if ((_a = comp.events) === null || _a === void 0 ? void 0 : _a.click) {
6290
+ const compEvents = core.Event.factory(comp.events);
6291
+ if (typeof compEvents.click === 'function') {
6292
+ return ({ component, event, element }) => compEvents.click({
6293
+ component, event, element, row, column,
6294
+ });
6295
+ }
6296
+ }
6297
+ return undefined;
6298
+ }
6294
6299
  }
6295
6300
 
6296
6301
  /**
@@ -7963,6 +7968,7 @@
7963
7968
  */
7964
7969
  constructor(props) {
7965
7970
  super(props);
7971
+ this.lazyAttach = false;
7966
7972
  this.debounceSetSearch = debounce__default["default"](this.setSearch, 500);
7967
7973
  this.iterableComponentName = this.getInitValue('iterableComponentName', props.iterableComponentName, this.iterableComponent);
7968
7974
  this.showHelper = this.getInitValue('showHelper', props.showHelper, false);
@@ -7970,10 +7976,13 @@
7970
7976
  this.appendIcon = this.getInitValue('appendIcon', props.appendIcon, 'magnify');
7971
7977
  this.placeholder = this.getInitValue('placeholder', props.placeholder, 'SEARCH');
7972
7978
  this.cssClass = this.getInitValue('cssClass', props.cssClass, 'zd-float-right');
7973
- this.setIterableComponent();
7979
+ this.lazyAttach = this.getInitValue('lazyAttach', props.lazyAttach, this.lazyAttach);
7980
+ if (!this.lazyAttach)
7981
+ this.setIterableComponent();
7974
7982
  this.createAccessors();
7975
7983
  }
7976
- setIterableComponent() {
7984
+ setIterableComponent(name) {
7985
+ this.iterableComponentName = name || this.iterableComponentName;
7977
7986
  if (this.iterableComponentName && core.Metadata.getInstances(this.iterableComponentName).length > 0) {
7978
7987
  this.iterableComponent = core.Metadata.getInstance(this.iterableComponentName);
7979
7988
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.84.1",
3
+ "version": "1.85.1",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -43,5 +43,5 @@
43
43
  "lodash.times": "4.3.*",
44
44
  "mockdate": "3.0.*"
45
45
  },
46
- "gitHead": "0b18124932a37bd921c9938b86371a7222e90f59"
46
+ "gitHead": "13bfb6936e5027a14c02d4ecde838100992a57d0"
47
47
  }
@@ -1,9 +1,9 @@
1
1
  import { IDictionary } from '@zeedhi/core';
2
- import { IGrid, IGridColumn, IGridEvents } from './interfaces';
3
- import { Iterable } from '../zd-iterable/iterable';
2
+ import { Component } from '../zd-component/component';
4
3
  import { IComponent, IComponentRender } from '../zd-component/interfaces';
4
+ import { Iterable } from '../zd-iterable/iterable';
5
5
  import { GridColumn } from './grid-column';
6
- import { Component } from '../zd-component/component';
6
+ import { IGrid, IGridColumn, IGridEvents } from './interfaces';
7
7
  /**
8
8
  * Base class for Grid component
9
9
  */
@@ -212,4 +212,5 @@ export declare class Grid extends Iterable implements IGrid {
212
212
  protected changeDefaultSlotNames(slot: IComponentRender[]): any;
213
213
  callDisableSelection(row: IDictionary<any>): boolean;
214
214
  getRowStyleConditions(row: IDictionary<any>): IDictionary<any>;
215
+ private setGridRowsInEvents;
215
216
  }
@@ -61,6 +61,7 @@ export interface ISearch extends ITextInput {
61
61
  showLabel?: boolean;
62
62
  showHelper?: boolean;
63
63
  appendIcon?: string;
64
+ lazyAttach?: boolean;
64
65
  }
65
66
  export interface IIterableColumnsButton extends IButton {
66
67
  iterableComponentName?: string;
@@ -13,12 +13,13 @@ export declare class Search extends TextInput implements ISearch {
13
13
  * Iterable component name
14
14
  */
15
15
  iterableComponent: Iterable;
16
+ lazyAttach: boolean;
16
17
  /**
17
18
  * Creates a new Iterable Page component.
18
19
  * @param props Iterable page component properties
19
20
  */
20
21
  constructor(props: ISearch);
21
- private setIterableComponent;
22
+ setIterableComponent(name?: string): void;
22
23
  protected setSearch(search: string): Promise<void>;
23
24
  debounceSetSearch: (search: string) => void;
24
25
  }