aio-class 2.2.1 → 2.2.3

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 +39 -12
  2. package/index.js +93 -25
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference types="jquery" />
2
- /// <reference types="jquery" />
1
+ /// <reference types="emscripten" />
3
2
  import { AIOGeo } from 'aio-geo';
4
3
  import AIODate from 'aio-date';
5
4
  export { AIOGeo, AIODate };
@@ -78,7 +77,7 @@ export declare const ArrayToObject: <T>(keys: T[], fn: (key: T) => any) => any;
78
77
  export declare const TextFilter: (p: {
79
78
  value: string | number;
80
79
  chars?: {
81
- [key: string]: boolean | undefined;
80
+ [key: string]: boolean;
82
81
  };
83
82
  number?: boolean;
84
83
  symbol?: boolean;
@@ -188,7 +187,7 @@ export type I_EntityRowDetail<T> = {
188
187
  parentRow: T | false;
189
188
  parentChilds?: T[] | false;
190
189
  rowId: I_id;
191
- parentId?: I_id | false;
190
+ parentId: I_id | false;
192
191
  index: number;
193
192
  beforeSibling: false | T;
194
193
  afterSibling: false | T;
@@ -209,15 +208,15 @@ export declare class EntityClass<T> {
209
208
  setData?: (v: T[]) => void;
210
209
  sorts?: I_sort<T>[];
211
210
  });
212
- private getId;
213
- private setId;
214
- private getChilds;
215
- private setChilds;
211
+ getId: (row: T) => I_id;
212
+ setId: (row: T) => T;
213
+ getChilds: (row: T) => T[];
214
+ setChilds: (row: T, childs: T[] | undefined) => T;
216
215
  private getRowDetailsByIds;
217
216
  private getRowDetailByRowAndParents;
218
217
  private removeChildOfParent;
219
218
  private getRowByAddChild;
220
- private _getRowDetailById;
219
+ private _getRowDetail;
221
220
  private _getFilteredTree;
222
221
  private _getSortedTree;
223
222
  private _addRow;
@@ -230,8 +229,9 @@ export declare class EntityClass<T> {
230
229
  private _moveTo;
231
230
  private _editByTraverse;
232
231
  private _traverse;
233
- getRowDetailById: (p: {
234
- rowId: I_id;
232
+ getRowDetail: (p: {
233
+ rowId?: I_id;
234
+ row?: T;
235
235
  rows?: T[];
236
236
  }) => false | I_EntityRowDetail<T>;
237
237
  getFilteredTree: (p: {
@@ -400,7 +400,7 @@ export type I_Swip_tempSelectRect = {
400
400
  left: number;
401
401
  top: number;
402
402
  };
403
- type I_Swip_dom = HTMLElement | JQuery | {
403
+ type I_Swip_dom = HTMLElement | any | {
404
404
  current: HTMLElement | null;
405
405
  } | string;
406
406
  export declare class Swip {
@@ -464,3 +464,30 @@ export declare class Swip {
464
464
  setSelectRect: (width: number, height: number) => void;
465
465
  removeSelectRect: () => void;
466
466
  }
467
+ export type I_logItem = {
468
+ tags: string[];
469
+ id: string;
470
+ repeat?: {
471
+ id: string;
472
+ count: number;
473
+ };
474
+ message: string;
475
+ status: 'error' | 'success' | 'warning' | 'info';
476
+ data?: any;
477
+ date: number;
478
+ expiredInMiliseconds: number;
479
+ };
480
+ export declare class LogsClass {
481
+ logs: I_logItem[];
482
+ load: () => Promise<I_logItem[]>;
483
+ save: (logs: I_logItem[]) => Promise<void>;
484
+ constructor(p: {
485
+ load: () => Promise<I_logItem[]>;
486
+ save: (logs: I_logItem[]) => Promise<void>;
487
+ });
488
+ init: () => Promise<void>;
489
+ changeLogs: (logs: I_logItem[]) => void;
490
+ add: (logItem: Partial<I_logItem>) => void;
491
+ remove: (logItem: I_logItem) => void;
492
+ clear: () => void;
493
+ }
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 = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (stallTime = 3000) { return yield new Promise(resolve => setTimeout(resolve, stallTime)); });
245
+ export const Stall = (stallTime = 3000) => __awaiter(void 0, void 0, void 0, function* () { 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,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();
@@ -1848,61 +1852,71 @@ export class EntityClass {
1848
1852
  this.getSortedTree = (p) => {
1849
1853
  const rows = p.rows || this.getData();
1850
1854
  const res = this._getSortedTree(rows, p.sorts);
1851
- this.setData(res);
1855
+ if (!p.rows)
1856
+ this.setData(res);
1852
1857
  return res;
1853
1858
  };
1854
1859
  this.addRow = (p) => {
1855
1860
  const rows = p.rows || this.getData();
1856
1861
  const res = this._addRow(rows, p.row, p);
1857
- this.setData(res.rows);
1862
+ if (!p.rows)
1863
+ this.setData(res.rows);
1858
1864
  return res;
1859
1865
  };
1860
1866
  this.editRow = (p) => {
1861
1867
  const rows = p.rows || this.getData();
1862
1868
  const res = this._editRow(rows, p.row);
1863
- this.setData(res);
1869
+ if (!p.rows)
1870
+ this.setData(res);
1864
1871
  return res;
1865
1872
  };
1866
1873
  this.editById = (p) => {
1867
1874
  const rows = p.rows || this.getData();
1868
1875
  const res = this._editById(rows, p.rowId, p.change);
1869
- this.setData(res);
1876
+ if (!p.rows)
1877
+ this.setData(res);
1870
1878
  return res;
1871
1879
  };
1872
1880
  this.removeRow = (p) => {
1873
1881
  const rows = p.rows || this.getData();
1874
1882
  const res = this._removeRow(rows, p.rowId);
1875
- this.setData(res);
1883
+ if (!p.rows)
1884
+ this.setData(res);
1876
1885
  return res;
1877
1886
  };
1878
1887
  this.removeByRowIds = (p) => {
1879
1888
  const rows = p.rows || this.getData();
1880
1889
  const res = this._removeByRowIds(rows, p.rowIds);
1881
- this.setData(res);
1890
+ if (!p.rows)
1891
+ this.setData(res);
1882
1892
  return res;
1883
1893
  };
1884
1894
  this.reOrder = (p) => {
1885
1895
  const rows = p.rows || this.getData();
1886
1896
  const res = this._reOrder(rows, p.fromId, p.toId);
1887
- this.setData(res);
1897
+ if (!p.rows)
1898
+ this.setData(res);
1888
1899
  return res;
1889
1900
  };
1890
1901
  this.reOrderByDir = (p) => {
1891
1902
  const rows = p.rows || this.getData();
1892
1903
  const res = this._reOrderByDir(rows, p.rowId, p.dir);
1893
- this.setData(res);
1904
+ if (!p.rows)
1905
+ this.setData(res);
1894
1906
  return res;
1895
1907
  };
1896
1908
  this.moveTo = (p) => {
1897
1909
  const rows = p.rows || this.getData();
1898
1910
  const res = this._moveTo(rows, p.fromIds, p.toId);
1899
- this.setData(res);
1911
+ if (!p.rows)
1912
+ this.setData(res);
1900
1913
  return res;
1901
1914
  };
1902
1915
  this.editByTraverse = (p) => {
1903
1916
  const rows = p.rows || this.getData();
1904
1917
  const res = this._editByTraverse(rows, p.callback);
1905
- this.setData(res);
1918
+ if (!p.rows)
1919
+ this.setData(res);
1906
1920
  return res;
1907
1921
  };
1908
1922
  this.traverse = (p) => {
@@ -2494,3 +2508,57 @@ export class Swip {
2494
2508
  this.init();
2495
2509
  }
2496
2510
  }
2511
+ export class LogsClass {
2512
+ constructor(p) {
2513
+ this.logs = [];
2514
+ this.init = () => __awaiter(this, void 0, void 0, function* () {
2515
+ let logs = yield this.load();
2516
+ this.changeLogs(logs);
2517
+ });
2518
+ this.changeLogs = (logs) => {
2519
+ const nowM = Date.now();
2520
+ logs = logs.filter((o) => nowM < o.expiredInMiliseconds + o.date);
2521
+ this.save(logs);
2522
+ this.logs = logs;
2523
+ };
2524
+ this.add = (logItem) => {
2525
+ const getMessage = (message) => {
2526
+ if (message.length > 100) {
2527
+ const start = message.slice(0, 50);
2528
+ const end = message.slice(51, 100);
2529
+ return `${start} ... ${end}`;
2530
+ }
2531
+ return message;
2532
+ };
2533
+ const now = Date.now();
2534
+ logItem.id = GenerateId('string');
2535
+ logItem.message = getMessage(logItem.message || 'no message');
2536
+ logItem.date = now;
2537
+ logItem.status = logItem.status || 'info';
2538
+ logItem.expiredInMiliseconds = logItem.expiredInMiliseconds || 1 * 60 * 60 * 1000;
2539
+ let newLogs = [...this.logs, logItem];
2540
+ if (logItem.repeat) {
2541
+ const res = [];
2542
+ let count = 0;
2543
+ const rev = newLogs.reverse();
2544
+ for (let i = 0; i < rev.length; i++) {
2545
+ const o = rev[i];
2546
+ if (o.repeat && o.repeat.id === logItem.repeat.id) {
2547
+ if (count >= logItem.repeat.count) {
2548
+ continue;
2549
+ }
2550
+ count++;
2551
+ }
2552
+ res.push(o);
2553
+ }
2554
+ newLogs = res.reverse();
2555
+ }
2556
+ this.changeLogs(newLogs);
2557
+ };
2558
+ this.remove = (logItem) => this.changeLogs(this.logs.filter((o) => o.id !== logItem.id));
2559
+ this.clear = () => this.changeLogs([]);
2560
+ this.save = p.save;
2561
+ this.load = p.load;
2562
+ this.init();
2563
+ }
2564
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-class",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {