aio-class 2.2.1 → 2.2.2

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 +8 -7
  2. package/index.js +18 -14
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -209,15 +209,15 @@ export declare class EntityClass<T> {
209
209
  setData?: (v: T[]) => void;
210
210
  sorts?: I_sort<T>[];
211
211
  });
212
- private getId;
213
- private setId;
214
- private getChilds;
215
- private setChilds;
212
+ getId: (row: T) => I_id;
213
+ setId: (row: T) => T;
214
+ getChilds: (row: T) => T[];
215
+ setChilds: (row: T, childs: T[] | undefined) => T;
216
216
  private getRowDetailsByIds;
217
217
  private getRowDetailByRowAndParents;
218
218
  private removeChildOfParent;
219
219
  private getRowByAddChild;
220
- private _getRowDetailById;
220
+ private _getRowDetail;
221
221
  private _getFilteredTree;
222
222
  private _getSortedTree;
223
223
  private _addRow;
@@ -230,8 +230,9 @@ export declare class EntityClass<T> {
230
230
  private _moveTo;
231
231
  private _editByTraverse;
232
232
  private _traverse;
233
- getRowDetailById: (p: {
234
- rowId: I_id;
233
+ getRowDetail: (p: {
234
+ rowId?: I_id;
235
+ row?: T;
235
236
  rows?: T[];
236
237
  }) => false | I_EntityRowDetail<T>;
237
238
  getFilteredTree: (p: {
package/index.js CHANGED
@@ -1572,15 +1572,15 @@ export class EntityClass {
1572
1572
  newChilds.splice(index === undefined ? newChilds.length : index, 0, row);
1573
1573
  return this.setChilds(parentRow, newChilds);
1574
1574
  };
1575
- this._getRowDetailById = (data, rowId) => {
1576
- const fn = (data, rowId, parents, level, temp) => {
1575
+ this._getRowDetail = (p) => {
1576
+ const fn = (rows, rowId, parents, level, temp) => {
1577
1577
  if (temp.res) {
1578
1578
  return;
1579
1579
  }
1580
- for (let i = 0; i < data.length; i++) {
1580
+ for (let i = 0; i < rows.length; i++) {
1581
1581
  const isFirstChild = i === 0;
1582
- const isLastChild = i === data.length - 1;
1583
- const row = data[i];
1582
+ const isLastChild = i === rows.length - 1;
1583
+ const row = rows[i];
1584
1584
  const childs = this.getChilds(row);
1585
1585
  if (this.getId(row).toString() === rowId.toString()) {
1586
1586
  temp.res = this.getRowDetailByRowAndParents(row, i, parents, isFirstChild, isLastChild, level);
@@ -1594,7 +1594,11 @@ export class EntityClass {
1594
1594
  }
1595
1595
  };
1596
1596
  let temp = { res: false };
1597
- fn(data, rowId, [], 0, temp);
1597
+ if (p.rowId === undefined && p.row === undefined) {
1598
+ return false;
1599
+ }
1600
+ const rowId = p.rowId === undefined ? this.getId(p.row) : p.rowId;
1601
+ fn(p.rows, rowId, [], 0, temp);
1598
1602
  return temp.res ? temp.res : false;
1599
1603
  };
1600
1604
  this._getFilteredTree = (data, filter) => {
@@ -1651,7 +1655,7 @@ export class EntityClass {
1651
1655
  const { parentId, index } = p;
1652
1656
  const newRow = this.setId(row);
1653
1657
  if (parentId !== undefined) {
1654
- const detail = this._getRowDetailById(data, parentId);
1658
+ const detail = this._getRowDetail({ rows: data, rowId: parentId });
1655
1659
  if (!detail) {
1656
1660
  return { rows: data, row };
1657
1661
  }
@@ -1667,7 +1671,7 @@ export class EntityClass {
1667
1671
  };
1668
1672
  this._editRow = (data, newRow) => {
1669
1673
  const rowId = this.getId(newRow);
1670
- const detail = this._getRowDetailById(data, rowId);
1674
+ const detail = this._getRowDetail({ rows: data, rowId });
1671
1675
  const parentRow = detail.parentRow;
1672
1676
  if (parentRow) {
1673
1677
  const childs = this.getChilds(parentRow);
@@ -1680,7 +1684,7 @@ export class EntityClass {
1680
1684
  }
1681
1685
  };
1682
1686
  this._editById = (data, rowId, change) => {
1683
- const detail = this._getRowDetailById(data, rowId);
1687
+ const detail = this._getRowDetail({ rows: data, rowId });
1684
1688
  if (!detail) {
1685
1689
  return data;
1686
1690
  }
@@ -1688,7 +1692,7 @@ export class EntityClass {
1688
1692
  return this._editRow(data, newRow);
1689
1693
  };
1690
1694
  this._removeRow = (data, rowId) => {
1691
- let detail = this._getRowDetailById(data, rowId);
1695
+ let detail = this._getRowDetail({ rows: data, rowId });
1692
1696
  if (!detail) {
1693
1697
  return data;
1694
1698
  }
@@ -1752,7 +1756,7 @@ export class EntityClass {
1752
1756
  }
1753
1757
  };
1754
1758
  this._reOrderByDir = (data, rowId, dir) => {
1755
- const from = this._getRowDetailById(data, rowId);
1759
+ const from = this._getRowDetail({ rows: data, rowId });
1756
1760
  if (!from) {
1757
1761
  return data;
1758
1762
  }
@@ -1781,7 +1785,7 @@ export class EntityClass {
1781
1785
  }
1782
1786
  const newData = this._removeRow(data, fromId);
1783
1787
  //اگر بروز نشه مشکل بوجود میاد
1784
- toDetail = this._getRowDetailById(newData, toId);
1788
+ toDetail = this._getRowDetail({ rows: newData, rowId: toId });
1785
1789
  if (!toDetail) {
1786
1790
  return data;
1787
1791
  }
@@ -1837,9 +1841,9 @@ export class EntityClass {
1837
1841
  };
1838
1842
  fn(rows, [], 0);
1839
1843
  };
1840
- this.getRowDetailById = (p) => {
1844
+ this.getRowDetail = (p) => {
1841
1845
  const rows = p.rows || this.getData();
1842
- return this._getRowDetailById(rows, p.rowId);
1846
+ return this._getRowDetail({ rows, rowId: p.rowId, row: p.row });
1843
1847
  };
1844
1848
  this.getFilteredTree = (p) => {
1845
1849
  const rows = p.rows || this.getData();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {