aio-class 2.2.0 → 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 +79 -85
  2. package/index.js +115 -117
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="emscripten" />
2
1
  /// <reference types="jquery" />
3
2
  /// <reference types="jquery" />
4
3
  import { AIOGeo } from 'aio-geo';
@@ -79,7 +78,7 @@ export declare const ArrayToObject: <T>(keys: T[], fn: (key: T) => any) => any;
79
78
  export declare const TextFilter: (p: {
80
79
  value: string | number;
81
80
  chars?: {
82
- [key: string]: boolean;
81
+ [key: string]: boolean | undefined;
83
82
  };
84
83
  number?: boolean;
85
84
  symbol?: boolean;
@@ -210,94 +209,89 @@ export declare class EntityClass<T> {
210
209
  setData?: (v: T[]) => void;
211
210
  sorts?: I_sort<T>[];
212
211
  });
213
- private getId;
214
- private setId;
215
- private getChilds;
216
- 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;
217
216
  private getRowDetailsByIds;
218
217
  private getRowDetailByRowAndParents;
219
218
  private removeChildOfParent;
220
219
  private getRowByAddChild;
221
- private getRowDetailById;
222
- private getFilteredTree;
223
- private getSortedTree;
224
- private addRow;
225
- private editRow;
226
- private editById;
227
- private removeRow;
228
- private removeByRowIds;
229
- private reOrder;
230
- private reOrderByDir;
231
- private moveTo;
232
- private editByTraverse;
233
- private traverse;
234
- actions: {
235
- getId: (row: T) => I_id;
236
- setId: (row: T) => T;
237
- getChilds: (row: T) => T[];
238
- setChilds: (row: T, childs: T[] | undefined) => T;
239
- getRowDetailById: (p: {
240
- rowId: I_id;
241
- rows?: T[];
242
- }) => false | I_EntityRowDetail<T>;
243
- getFilteredTree: (p: {
244
- filter: (row: T, detail: I_EntityRowDetail<T>) => boolean | undefined;
245
- rows?: T[];
246
- }) => T[];
247
- getSortedTree: (p: {
248
- sorts: I_sort<T>[];
249
- rows?: T[];
250
- }) => T[];
251
- addRow: (p: {
252
- row: T;
253
- parentId?: I_id;
254
- index?: number;
255
- rows?: T[];
256
- }) => {
257
- rows: T[];
258
- row: T;
259
- };
260
- editRow: (p: {
261
- row: T;
262
- rows?: T[];
263
- }) => T[];
264
- editById: (p: {
265
- rowId: I_id;
266
- change: Partial<T>;
267
- rows?: T[];
268
- }) => T[];
269
- removeRow: (p: {
270
- rowId: I_id;
271
- rows?: T[];
272
- }) => T[];
273
- removeByRowIds: (p: {
274
- rowIds: I_id[];
275
- rows?: T[];
276
- }) => T[];
277
- reOrder: (p: {
278
- fromId: I_id;
279
- toId: I_id;
280
- rows?: T[];
281
- }) => T[];
282
- reOrderByDir: (p: {
283
- rowId: I_id;
284
- dir: 1 | -1;
285
- rows?: T[];
286
- }) => T[];
287
- moveTo: (p: {
288
- fromIds: I_id[];
289
- toId: I_id;
290
- rows?: T[];
291
- }) => T[];
292
- editByTraverse: (p: {
293
- callback: (row: T) => T | false;
294
- rows?: T[];
295
- }) => T[];
296
- traverse: (p: {
297
- callback: (row: T, detail: I_EntityRowDetail<T>) => false | undefined;
298
- rows?: T[];
299
- }) => void;
220
+ private _getRowDetail;
221
+ private _getFilteredTree;
222
+ private _getSortedTree;
223
+ private _addRow;
224
+ private _editRow;
225
+ private _editById;
226
+ private _removeRow;
227
+ private _removeByRowIds;
228
+ private _reOrder;
229
+ private _reOrderByDir;
230
+ private _moveTo;
231
+ private _editByTraverse;
232
+ private _traverse;
233
+ getRowDetail: (p: {
234
+ rowId?: I_id;
235
+ row?: T;
236
+ rows?: T[];
237
+ }) => false | I_EntityRowDetail<T>;
238
+ getFilteredTree: (p: {
239
+ filter: (row: T, detail: I_EntityRowDetail<T>) => boolean | undefined;
240
+ rows?: T[];
241
+ }) => T[];
242
+ getSortedTree: (p: {
243
+ sorts: I_sort<T>[];
244
+ rows?: T[];
245
+ }) => T[];
246
+ addRow: (p: {
247
+ row: T;
248
+ parentId?: I_id;
249
+ index?: number;
250
+ rows?: T[];
251
+ }) => {
252
+ rows: T[];
253
+ row: T;
300
254
  };
255
+ editRow: (p: {
256
+ row: T;
257
+ rows?: T[];
258
+ }) => T[];
259
+ editById: (p: {
260
+ rowId: I_id;
261
+ change: Partial<T>;
262
+ rows?: T[];
263
+ }) => T[];
264
+ removeRow: (p: {
265
+ rowId: I_id;
266
+ rows?: T[];
267
+ }) => T[];
268
+ removeByRowIds: (p: {
269
+ rowIds: I_id[];
270
+ rows?: T[];
271
+ }) => T[];
272
+ reOrder: (p: {
273
+ fromId: I_id;
274
+ toId: I_id;
275
+ rows?: T[];
276
+ }) => T[];
277
+ reOrderByDir: (p: {
278
+ rowId: I_id;
279
+ dir: 1 | -1;
280
+ rows?: T[];
281
+ }) => T[];
282
+ moveTo: (p: {
283
+ fromIds: I_id[];
284
+ toId: I_id;
285
+ rows?: T[];
286
+ }) => T[];
287
+ editByTraverse: (p: {
288
+ callback: (row: T) => T | false;
289
+ rows?: T[];
290
+ }) => T[];
291
+ traverse: (p: {
292
+ callback: (row: T, detail: I_EntityRowDetail<T>) => false | undefined;
293
+ rows?: T[];
294
+ }) => void;
301
295
  }
302
296
  type I_color = any;
303
297
  type I_color_type = 'rgb' | 'hex' | 'array';
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;
@@ -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,13 +1594,17 @@ 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
- this.getFilteredTree = (data, filter) => {
1604
+ this._getFilteredTree = (data, filter) => {
1601
1605
  const getNodesDic = (data, filter) => {
1602
1606
  const detailDic = {};
1603
- this.traverse(data, (row, detail) => {
1607
+ this._traverse(data, (row, detail) => {
1604
1608
  const res = filter(row, detail);
1605
1609
  if (res === false) {
1606
1610
  return false;
@@ -1636,27 +1640,27 @@ export class EntityClass {
1636
1640
  const nodesDic = getNodesDic(data, filter);
1637
1641
  return fn(data, [], 0);
1638
1642
  };
1639
- this.getSortedTree = (rows, sorts) => {
1643
+ this._getSortedTree = (rows, sorts) => {
1640
1644
  let sortedRows = SortArray(rows, sorts);
1641
1645
  return sortedRows.map((o) => {
1642
1646
  const childs = this.getChilds(o);
1643
1647
  if (!childs || !childs.length) {
1644
1648
  return o;
1645
1649
  }
1646
- const newChilds = this.getSortedTree(childs, sorts);
1650
+ const newChilds = this._getSortedTree(childs, sorts);
1647
1651
  return this.setChilds(Object.assign({}, o), newChilds);
1648
1652
  });
1649
1653
  };
1650
- this.addRow = (data, row, p) => {
1654
+ this._addRow = (data, row, p) => {
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
  }
1658
1662
  const parent = this.getRowByAddChild(detail.row, newRow);
1659
- const newData = this.editRow(data, parent);
1663
+ const newData = this._editRow(data, parent);
1660
1664
  return { rows: newData, row: newRow };
1661
1665
  }
1662
1666
  else {
@@ -1665,50 +1669,50 @@ export class EntityClass {
1665
1669
  return { rows: newData, row: newRow };
1666
1670
  }
1667
1671
  };
1668
- this.editRow = (data, newRow) => {
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);
1674
1678
  const newChilds = childs.map((o) => this.getId(o).toString() === rowId.toString() ? newRow : o);
1675
1679
  const newParentRow = this.setChilds(parentRow, newChilds);
1676
- return this.editRow(data, newParentRow);
1680
+ return this._editRow(data, newParentRow);
1677
1681
  }
1678
1682
  else {
1679
1683
  return data.map((o) => this.getId(o).toString() === this.getId(newRow).toString() ? newRow : o);
1680
1684
  }
1681
1685
  };
1682
- this.editById = (data, rowId, change) => {
1683
- const detail = this.getRowDetailById(data, rowId);
1686
+ this._editById = (data, rowId, change) => {
1687
+ const detail = this._getRowDetail({ rows: data, rowId });
1684
1688
  if (!detail) {
1685
1689
  return data;
1686
1690
  }
1687
1691
  const newRow = Object.assign(Object.assign({}, detail.row), change);
1688
- return this.editRow(data, newRow);
1692
+ return this._editRow(data, newRow);
1689
1693
  };
1690
- this.removeRow = (data, rowId) => {
1691
- let detail = this.getRowDetailById(data, rowId);
1694
+ this._removeRow = (data, rowId) => {
1695
+ let detail = this._getRowDetail({ rows: data, rowId });
1692
1696
  if (!detail) {
1693
1697
  return data;
1694
1698
  }
1695
1699
  let parentRow = detail.parentRow;
1696
1700
  if (parentRow) {
1697
1701
  parentRow = this.removeChildOfParent(parentRow, rowId);
1698
- return this.editRow(data, parentRow);
1702
+ return this._editRow(data, parentRow);
1699
1703
  }
1700
1704
  else {
1701
1705
  return data.filter((o) => this.getId(o).toString() !== rowId.toString());
1702
1706
  }
1703
1707
  };
1704
- this.removeByRowIds = (data, rowIds) => {
1708
+ this._removeByRowIds = (data, rowIds) => {
1705
1709
  let tempRows = [...data];
1706
1710
  for (let i = 0; i < rowIds.length; i++) {
1707
- tempRows = this.removeRow(tempRows, rowIds[i]);
1711
+ tempRows = this._removeRow(tempRows, rowIds[i]);
1708
1712
  }
1709
1713
  return tempRows;
1710
1714
  };
1711
- this.reOrder = (data, fromId, toId, pos) => {
1715
+ this._reOrder = (data, fromId, toId, pos) => {
1712
1716
  if (fromId.toString() === toId.toString()) {
1713
1717
  return data;
1714
1718
  }
@@ -1739,20 +1743,20 @@ export class EntityClass {
1739
1743
  //مبدا رو با آی دی جدید به پرنت مقصد در ایندکس ردیف مقصد اضافه کن
1740
1744
  const newToParent = this.getRowByAddChild(toParent, fromRow, toIndex);
1741
1745
  //دیتا رو با این ردیف جدید ویرایش کن
1742
- let newData = this.editRow(data, newToParent);
1746
+ let newData = this._editRow(data, newToParent);
1743
1747
  //مبدا رو از دیتای جدید حذف کن
1744
- return this.removeRow(newData, fromDetail.rowId);
1748
+ return this._removeRow(newData, fromDetail.rowId);
1745
1749
  }
1746
1750
  //اگر پرنت نداشت
1747
1751
  else {
1748
1752
  //مبدا رو با آی دی جدید به پرنت مقصد در ایندکس ردیف مقصد اضافه کن
1749
- let newData = this.addRow(data, fromRow, { index: toIndex });
1753
+ let newData = this._addRow(data, fromRow, { index: toIndex });
1750
1754
  //مبدا رو از دیتای جدید حذف کن
1751
- return this.removeRow(newData.rows, fromDetail.rowId);
1755
+ return this._removeRow(newData.rows, fromDetail.rowId);
1752
1756
  }
1753
1757
  };
1754
- this.reOrderByDir = (data, rowId, dir) => {
1755
- const from = this.getRowDetailById(data, rowId);
1758
+ this._reOrderByDir = (data, rowId, dir) => {
1759
+ const from = this._getRowDetail({ rows: data, rowId });
1756
1760
  if (!from) {
1757
1761
  return data;
1758
1762
  }
@@ -1762,9 +1766,9 @@ export class EntityClass {
1762
1766
  }
1763
1767
  const fromId = rowId;
1764
1768
  const toId = this.getId(sibling);
1765
- return this.reOrder(data, fromId, toId, dir === 1 ? 'after' : 'before') || data;
1769
+ return this._reOrder(data, fromId, toId, dir === 1 ? 'after' : 'before') || data;
1766
1770
  };
1767
- this.moveTo = (data, fromIds, toId) => {
1771
+ this._moveTo = (data, fromIds, toId) => {
1768
1772
  const fn = (data, fromId, toId) => {
1769
1773
  const details = this.getRowDetailsByIds(data, [fromId, toId]);
1770
1774
  let toDetail = details[toId];
@@ -1779,14 +1783,14 @@ export class EntityClass {
1779
1783
  if (isToChildOfFrom) {
1780
1784
  return data;
1781
1785
  }
1782
- const newData = this.removeRow(data, fromId);
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
  }
1788
1792
  const newToRow = this.getRowByAddChild(toDetail.row, fromDetail.row);
1789
- return this.editRow(newData, newToRow);
1793
+ return this._editRow(newData, newToRow);
1790
1794
  };
1791
1795
  let rows = data;
1792
1796
  for (let i = 0; i < fromIds.length; i++) {
@@ -1794,7 +1798,7 @@ export class EntityClass {
1794
1798
  }
1795
1799
  return rows;
1796
1800
  };
1797
- this.editByTraverse = (rows, callback) => {
1801
+ this._editByTraverse = (rows, callback) => {
1798
1802
  const fn = (data, parentRow) => {
1799
1803
  for (let i = 0; i < data.length; i++) {
1800
1804
  let row = data[i];
@@ -1820,7 +1824,7 @@ export class EntityClass {
1820
1824
  fn(rows);
1821
1825
  return rows;
1822
1826
  };
1823
- this.traverse = (rows, callback) => {
1827
+ this._traverse = (rows, callback) => {
1824
1828
  const fn = (data, parentRows, level) => {
1825
1829
  for (let i = 0; i < data.length; i++) {
1826
1830
  let row = data[i];
@@ -1837,83 +1841,77 @@ export class EntityClass {
1837
1841
  };
1838
1842
  fn(rows, [], 0);
1839
1843
  };
1840
- this.actions = {
1841
- getId: this.getId,
1842
- setId: this.setId,
1843
- getChilds: this.getChilds,
1844
- setChilds: this.setChilds,
1845
- getRowDetailById: (p) => {
1846
- const rows = p.rows || this.getData();
1847
- return this.getRowDetailById(rows, p.rowId);
1848
- },
1849
- getFilteredTree: (p) => {
1850
- const rows = p.rows || this.getData();
1851
- return this.getFilteredTree(rows, p.filter);
1852
- },
1853
- getSortedTree: (p) => {
1854
- const rows = p.rows || this.getData();
1855
- const res = this.getSortedTree(rows, p.sorts);
1856
- this.setData(res);
1857
- return res;
1858
- },
1859
- addRow: (p) => {
1860
- const rows = p.rows || this.getData();
1861
- const res = this.addRow(rows, p.row, p);
1862
- this.setData(res.rows);
1863
- return res;
1864
- },
1865
- editRow: (p) => {
1866
- const rows = p.rows || this.getData();
1867
- const res = this.editRow(rows, p.row);
1868
- this.setData(res);
1869
- return res;
1870
- },
1871
- editById: (p) => {
1872
- const rows = p.rows || this.getData();
1873
- const res = this.editById(rows, p.rowId, p.change);
1874
- this.setData(res);
1875
- return res;
1876
- },
1877
- removeRow: (p) => {
1878
- const rows = p.rows || this.getData();
1879
- const res = this.removeRow(rows, p.rowId);
1880
- this.setData(res);
1881
- return res;
1882
- },
1883
- removeByRowIds: (p) => {
1884
- const rows = p.rows || this.getData();
1885
- const res = this.removeByRowIds(rows, p.rowIds);
1886
- this.setData(res);
1887
- return res;
1888
- },
1889
- reOrder: (p) => {
1890
- const rows = p.rows || this.getData();
1891
- const res = this.reOrder(rows, p.fromId, p.toId);
1892
- this.setData(res);
1893
- return res;
1894
- },
1895
- reOrderByDir: (p) => {
1896
- const rows = p.rows || this.getData();
1897
- const res = this.reOrderByDir(rows, p.rowId, p.dir);
1898
- this.setData(res);
1899
- return res;
1900
- },
1901
- moveTo: (p) => {
1902
- const rows = p.rows || this.getData();
1903
- const res = this.moveTo(rows, p.fromIds, p.toId);
1904
- this.setData(res);
1905
- return res;
1906
- },
1907
- editByTraverse: (p) => {
1908
- const rows = p.rows || this.getData();
1909
- const res = this.editByTraverse(rows, p.callback);
1910
- this.setData(res);
1911
- return res;
1912
- },
1913
- traverse: (p) => {
1914
- const rows = p.rows || this.getData();
1915
- this.traverse(rows, p.callback);
1916
- }
1844
+ this.getRowDetail = (p) => {
1845
+ const rows = p.rows || this.getData();
1846
+ return this._getRowDetail({ rows, rowId: p.rowId, row: p.row });
1847
+ };
1848
+ this.getFilteredTree = (p) => {
1849
+ const rows = p.rows || this.getData();
1850
+ return this._getFilteredTree(rows, p.filter);
1851
+ };
1852
+ this.getSortedTree = (p) => {
1853
+ const rows = p.rows || this.getData();
1854
+ const res = this._getSortedTree(rows, p.sorts);
1855
+ this.setData(res);
1856
+ return res;
1857
+ };
1858
+ this.addRow = (p) => {
1859
+ const rows = p.rows || this.getData();
1860
+ const res = this._addRow(rows, p.row, p);
1861
+ this.setData(res.rows);
1862
+ return res;
1863
+ };
1864
+ this.editRow = (p) => {
1865
+ const rows = p.rows || this.getData();
1866
+ const res = this._editRow(rows, p.row);
1867
+ this.setData(res);
1868
+ return res;
1869
+ };
1870
+ this.editById = (p) => {
1871
+ const rows = p.rows || this.getData();
1872
+ const res = this._editById(rows, p.rowId, p.change);
1873
+ this.setData(res);
1874
+ return res;
1875
+ };
1876
+ this.removeRow = (p) => {
1877
+ const rows = p.rows || this.getData();
1878
+ const res = this._removeRow(rows, p.rowId);
1879
+ this.setData(res);
1880
+ return res;
1881
+ };
1882
+ this.removeByRowIds = (p) => {
1883
+ const rows = p.rows || this.getData();
1884
+ const res = this._removeByRowIds(rows, p.rowIds);
1885
+ this.setData(res);
1886
+ return res;
1887
+ };
1888
+ this.reOrder = (p) => {
1889
+ const rows = p.rows || this.getData();
1890
+ const res = this._reOrder(rows, p.fromId, p.toId);
1891
+ this.setData(res);
1892
+ return res;
1893
+ };
1894
+ this.reOrderByDir = (p) => {
1895
+ const rows = p.rows || this.getData();
1896
+ const res = this._reOrderByDir(rows, p.rowId, p.dir);
1897
+ this.setData(res);
1898
+ return res;
1899
+ };
1900
+ this.moveTo = (p) => {
1901
+ const rows = p.rows || this.getData();
1902
+ const res = this._moveTo(rows, p.fromIds, p.toId);
1903
+ this.setData(res);
1904
+ return res;
1905
+ };
1906
+ this.editByTraverse = (p) => {
1907
+ const rows = p.rows || this.getData();
1908
+ const res = this._editByTraverse(rows, p.callback);
1909
+ this.setData(res);
1910
+ return res;
1911
+ };
1912
+ this.traverse = (p) => {
1913
+ const rows = p.rows || this.getData();
1914
+ this._traverse(rows, p.callback);
1917
1915
  };
1918
1916
  this.map = p.map;
1919
1917
  if (p.getData) {
@@ -1923,7 +1921,7 @@ export class EntityClass {
1923
1921
  if (p.setData) {
1924
1922
  let newData = v;
1925
1923
  if (p.sorts && p.sorts.length) {
1926
- newData = this.getSortedTree(newData, p.sorts);
1924
+ newData = this._getSortedTree(newData, p.sorts);
1927
1925
  }
1928
1926
  p.setData(newData);
1929
1927
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {