aio-class 2.0.4 → 2.1.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 (3) hide show
  1. package/index.d.ts +41 -24
  2. package/index.js +42 -13
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -210,32 +210,47 @@ 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: {
239
254
  addRow: (row: T, p: {
240
255
  parentId?: I_id;
241
256
  index?: number;
@@ -251,6 +266,8 @@ export declare class EntityClass<T> {
251
266
  reOrderByDir: (rowId: I_id, dir: 1 | -1) => T[];
252
267
  moveTo: (fromIds: I_id[], toId: I_id) => T[];
253
268
  editByTraverse: (callback: (row: T) => T | false) => T[];
269
+ getSortedTree: (sorts: I_sort<T>[]) => T[];
270
+ getFilteredTree: (filter: (row: T, detail: I_rowResult<T>) => boolean | undefined) => T[];
254
271
  };
255
272
  }
256
273
  type I_color = any;
package/index.js CHANGED
@@ -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,26 @@ 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 = {
1836
1851
  addRow: (row, p) => {
1837
1852
  const data = this.getData();
1838
1853
  const res = this.addRow(data, row, p);
@@ -1886,6 +1901,18 @@ export class EntityClass {
1886
1901
  const res = this.editByTraverse(data, callback);
1887
1902
  this.setData(res);
1888
1903
  return res;
1904
+ },
1905
+ getSortedTree: (sorts) => {
1906
+ const data = this.getData();
1907
+ const res = this.getSortedTree(data, sorts);
1908
+ this.setData(res);
1909
+ return res;
1910
+ },
1911
+ getFilteredTree: (filter) => {
1912
+ const data = this.getData();
1913
+ const res = this.getFilteredTree(data, filter);
1914
+ this.setData(res);
1915
+ return res;
1889
1916
  }
1890
1917
  };
1891
1918
  this.params = p;
@@ -2114,13 +2141,15 @@ export class Swip {
2114
2141
  this.bind = (dom) => {
2115
2142
  this.unbind();
2116
2143
  this.dom = dom;
2117
- dom.addEventListener('mousedown', this.mouseDown);
2144
+ const touch = IsTouch();
2145
+ dom.addEventListener(touch ? 'touchstart' : 'mousedown', this.mouseDown);
2118
2146
  };
2119
2147
  this.unbind = () => {
2120
2148
  if (!this.dom) {
2121
2149
  return;
2122
2150
  }
2123
- this.dom.removeEventListener('mousedown', this.mouseDown);
2151
+ const touch = IsTouch();
2152
+ this.dom.removeEventListener(touch ? 'touchstart' : 'mousedown', this.mouseDown);
2124
2153
  this.dom = undefined;
2125
2154
  };
2126
2155
  this.init = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {