aio-class 2.0.5 → 2.1.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.
Files changed (3) hide show
  1. package/index.d.ts +43 -25
  2. package/index.js +43 -12
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -78,7 +78,7 @@ export declare const ArrayToObject: <T>(keys: T[], fn: (key: T) => any) => any;
78
78
  export declare const TextFilter: (p: {
79
79
  value: string | number;
80
80
  chars?: {
81
- [key: string]: boolean;
81
+ [key: string]: boolean | undefined;
82
82
  };
83
83
  number?: boolean;
84
84
  symbol?: boolean;
@@ -210,32 +210,48 @@ export declare class EntityClass<T> {
210
210
  private setChilds;
211
211
  private getRowDetailsByIds;
212
212
  private getRowDetailByRowAndParents;
213
- getRowByAddChild: (parentRow: T, row: T, index?: number) => T;
214
- removeChildOfParent: (parentRow: T, rowId: I_id) => T;
215
- getRowDetailById: (data: T[], rowId: I_id) => false | I_rowResult<T>;
216
- getFilteredTree: (data: T[], filter: (row: T, detail: I_rowResult<T>) => boolean | undefined) => T[];
217
- sortData: (rows: T[], sorts: I_sort<T>[]) => T[];
218
- addRow: (data: T[], row: T, p: {
219
- parentId?: I_id;
220
- index?: number;
221
- }) => {
222
- rows: T[];
223
- row: T;
224
- };
225
- editRow: (data: T[], newRow: T) => T[];
226
- editById: (data: T[], rowId: I_id, change: Partial<T>) => T[];
227
- removeRow: (data: T[], rowId: I_id) => T[];
228
- removeByRowIds: (data: T[], rowIds: I_id[]) => T[];
229
- reOrder: (data: T[], fromId: I_id, toId: I_id, pos?: 'before' | 'after') => T[];
230
- reOrderByDir: (data: T[], rowId: I_id, dir: 1 | -1) => T[];
231
- moveTo: (data: T[], fromIds: I_id[], toId: I_id) => T[];
232
- editByTraverse: (rows: T[], callback: (row: T) => T | false) => T[];
233
- traverse: (rows: T[], callback: (row: T, detail: I_rowResult<T>) => false | undefined) => T[];
234
- _dataMethods: {
235
- getChilds: (row: T) => T[];
213
+ private removeChildOfParent;
214
+ private getRowByAddChild;
215
+ private getRowDetailById;
216
+ private getFilteredTree;
217
+ private getSortedTree;
218
+ private addRow;
219
+ private editRow;
220
+ private editById;
221
+ private removeRow;
222
+ private removeByRowIds;
223
+ private reOrder;
224
+ private reOrderByDir;
225
+ private moveTo;
226
+ private editByTraverse;
227
+ private traverse;
228
+ actions: {
236
229
  getId: (row: T) => I_id;
237
- traverse: (rows: T[], callback: (row: T, detail: I_rowResult<T>) => false | undefined) => T[];
230
+ setId: (row: T) => T;
231
+ getChilds: (row: T) => T[];
232
+ setChilds: (row: T, childs: T[] | undefined) => T;
238
233
  getRowDetailById: (data: T[], rowId: I_id) => false | I_rowResult<T>;
234
+ getFilteredTree: (data: T[], filter: (row: T, detail: I_rowResult<T>) => boolean | undefined) => T[];
235
+ getSortedTree: (rows: T[], sorts: I_sort<T>[]) => T[];
236
+ addRow: (data: T[], row: T, p: {
237
+ parentId?: I_id;
238
+ index?: number;
239
+ }) => {
240
+ rows: T[];
241
+ row: T;
242
+ };
243
+ editRow: (data: T[], newRow: T) => T[];
244
+ editById: (data: T[], rowId: I_id, change: Partial<T>) => T[];
245
+ removeRow: (data: T[], rowId: I_id) => T[];
246
+ removeByRowIds: (data: T[], rowIds: I_id[]) => T[];
247
+ reOrder: (data: T[], fromId: I_id, toId: I_id, pos?: 'before' | 'after') => T[];
248
+ reOrderByDir: (data: T[], rowId: I_id, dir: 1 | -1) => T[];
249
+ moveTo: (data: T[], fromIds: I_id[], toId: I_id) => T[];
250
+ editByTraverse: (rows: T[], callback: (row: T) => T | false) => T[];
251
+ traverse: (rows: T[], callback: (row: T, detail: I_rowResult<T>) => false | undefined) => T[];
252
+ };
253
+ dataActions: {
254
+ getRowDetailById: (rowId: any) => false | I_rowResult<T>;
239
255
  addRow: (row: T, p: {
240
256
  parentId?: I_id;
241
257
  index?: number;
@@ -251,6 +267,8 @@ export declare class EntityClass<T> {
251
267
  reOrderByDir: (rowId: I_id, dir: 1 | -1) => T[];
252
268
  moveTo: (fromIds: I_id[], toId: I_id) => T[];
253
269
  editByTraverse: (callback: (row: T) => T | false) => T[];
270
+ getSortedTree: (sorts: I_sort<T>[]) => T[];
271
+ getFilteredTree: (filter: (row: T, detail: I_rowResult<T>) => boolean | undefined) => T[];
254
272
  };
255
273
  }
256
274
  type I_color = any;
package/index.js CHANGED
@@ -242,7 +242,7 @@ export const EventHandler = (selector, event, action, type = 'bind') => {
242
242
  element.addEventListener(fixedEvent, action);
243
243
  }
244
244
  };
245
- export const Stall = (stallTime = 3000) => __awaiter(void 0, void 0, void 0, function* () { return yield new Promise(resolve => setTimeout(resolve, stallTime)); });
245
+ export const Stall = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (stallTime = 3000) { return yield new Promise(resolve => setTimeout(resolve, stallTime)); });
246
246
  export const DetectOS = () => {
247
247
  const userAgent = window.navigator.userAgent;
248
248
  const platform = window.navigator.platform;
@@ -1548,12 +1548,6 @@ export class EntityClass {
1548
1548
  }
1549
1549
  return { row, parentRows, rowId, childsLength, parentId, isLeaf, parentRow, index, beforeSibling, afterSibling, isFirstChild, isLastChild };
1550
1550
  };
1551
- this.getRowByAddChild = (parentRow, row, index) => {
1552
- const childs = this.getChilds(parentRow) || [];
1553
- const newChilds = [...childs];
1554
- newChilds.splice(index === undefined ? newChilds.length : index, 0, row);
1555
- return this.setChilds(parentRow, newChilds);
1556
- };
1557
1551
  this.removeChildOfParent = (parentRow, rowId) => {
1558
1552
  let childs = this.getChilds(parentRow);
1559
1553
  if (!childs || !childs.length) {
@@ -1562,6 +1556,12 @@ export class EntityClass {
1562
1556
  childs = childs.filter((o) => this.getId(o).toString() !== rowId.toString());
1563
1557
  return this.setChilds(parentRow, childs);
1564
1558
  };
1559
+ this.getRowByAddChild = (parentRow, row, index) => {
1560
+ const childs = this.getChilds(parentRow) || [];
1561
+ const newChilds = [...childs];
1562
+ newChilds.splice(index === undefined ? newChilds.length : index, 0, row);
1563
+ return this.setChilds(parentRow, newChilds);
1564
+ };
1565
1565
  this.getRowDetailById = (data, rowId) => {
1566
1566
  const fn = (data, rowId, parents, temp) => {
1567
1567
  if (temp.res) {
@@ -1626,14 +1626,14 @@ export class EntityClass {
1626
1626
  const nodesDic = getNodesDic(data, filter);
1627
1627
  return fn(data, []);
1628
1628
  };
1629
- this.sortData = (rows, sorts) => {
1629
+ this.getSortedTree = (rows, sorts) => {
1630
1630
  let sortedRows = SortArray(rows, sorts);
1631
1631
  return sortedRows.map((o) => {
1632
1632
  const childs = this.getChilds(o);
1633
1633
  if (!childs || !childs.length) {
1634
1634
  return o;
1635
1635
  }
1636
- const newChilds = this.sortData(childs, sorts);
1636
+ const newChilds = this.getSortedTree(childs, sorts);
1637
1637
  return this.setChilds(Object.assign({}, o), newChilds);
1638
1638
  });
1639
1639
  };
@@ -1828,11 +1828,30 @@ export class EntityClass {
1828
1828
  fn(rows, []);
1829
1829
  return rows;
1830
1830
  };
1831
- this._dataMethods = {
1832
- getChilds: this.getChilds,
1831
+ this.actions = {
1833
1832
  getId: this.getId,
1834
- traverse: this.traverse,
1833
+ setId: this.setId,
1834
+ getChilds: this.getChilds,
1835
+ setChilds: this.setChilds,
1835
1836
  getRowDetailById: this.getRowDetailById,
1837
+ getFilteredTree: this.getFilteredTree,
1838
+ getSortedTree: this.getSortedTree,
1839
+ addRow: this.addRow,
1840
+ editRow: this.editRow,
1841
+ editById: this.editById,
1842
+ removeRow: this.removeRow,
1843
+ removeByRowIds: this.removeByRowIds,
1844
+ reOrder: this.reOrder,
1845
+ reOrderByDir: this.reOrderByDir,
1846
+ moveTo: this.moveTo,
1847
+ editByTraverse: this.editByTraverse,
1848
+ traverse: this.traverse
1849
+ };
1850
+ this.dataActions = {
1851
+ getRowDetailById: (rowId) => {
1852
+ const data = this.getData();
1853
+ return this.getRowDetailById(data, rowId);
1854
+ },
1836
1855
  addRow: (row, p) => {
1837
1856
  const data = this.getData();
1838
1857
  const res = this.addRow(data, row, p);
@@ -1886,6 +1905,18 @@ export class EntityClass {
1886
1905
  const res = this.editByTraverse(data, callback);
1887
1906
  this.setData(res);
1888
1907
  return res;
1908
+ },
1909
+ getSortedTree: (sorts) => {
1910
+ const data = this.getData();
1911
+ const res = this.getSortedTree(data, sorts);
1912
+ this.setData(res);
1913
+ return res;
1914
+ },
1915
+ getFilteredTree: (filter) => {
1916
+ const data = this.getData();
1917
+ const res = this.getFilteredTree(data, filter);
1918
+ this.setData(res);
1919
+ return res;
1889
1920
  }
1890
1921
  };
1891
1922
  this.params = p;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.0.5",
3
+ "version": "2.1.1",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {