aio-class 2.2.2 → 2.2.4

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 +29 -4
  2. package/index.js +74 -10
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="jquery" />
2
- /// <reference types="jquery" />
3
1
  import { AIOGeo } from 'aio-geo';
4
2
  import AIODate from 'aio-date';
5
3
  export { AIOGeo, AIODate };
@@ -188,7 +186,7 @@ export type I_EntityRowDetail<T> = {
188
186
  parentRow: T | false;
189
187
  parentChilds?: T[] | false;
190
188
  rowId: I_id;
191
- parentId?: I_id | false;
189
+ parentId: I_id | false;
192
190
  index: number;
193
191
  beforeSibling: false | T;
194
192
  afterSibling: false | T;
@@ -401,7 +399,7 @@ export type I_Swip_tempSelectRect = {
401
399
  left: number;
402
400
  top: number;
403
401
  };
404
- type I_Swip_dom = HTMLElement | JQuery | {
402
+ type I_Swip_dom = HTMLElement | any | {
405
403
  current: HTMLElement | null;
406
404
  } | string;
407
405
  export declare class Swip {
@@ -465,3 +463,30 @@ export declare class Swip {
465
463
  setSelectRect: (width: number, height: number) => void;
466
464
  removeSelectRect: () => void;
467
465
  }
466
+ export type I_logItem = {
467
+ tags: string[];
468
+ id: string;
469
+ repeat?: {
470
+ id: string;
471
+ count: number;
472
+ };
473
+ message: string;
474
+ status: 'error' | 'success' | 'warning' | 'info';
475
+ data?: any;
476
+ date: number;
477
+ expiredInMiliseconds: number;
478
+ };
479
+ export declare class LogsClass {
480
+ logs: I_logItem[];
481
+ load: () => Promise<I_logItem[]>;
482
+ save: (logs: I_logItem[]) => Promise<void>;
483
+ constructor(p: {
484
+ load: () => Promise<I_logItem[]>;
485
+ save: (logs: I_logItem[]) => Promise<void>;
486
+ });
487
+ init: () => Promise<void>;
488
+ changeLogs: (logs: I_logItem[]) => void;
489
+ add: (logItem: Partial<I_logItem>) => void;
490
+ remove: (logItem: I_logItem) => void;
491
+ clear: () => void;
492
+ }
package/index.js CHANGED
@@ -1852,61 +1852,71 @@ export class EntityClass {
1852
1852
  this.getSortedTree = (p) => {
1853
1853
  const rows = p.rows || this.getData();
1854
1854
  const res = this._getSortedTree(rows, p.sorts);
1855
- this.setData(res);
1855
+ if (!p.rows)
1856
+ this.setData(res);
1856
1857
  return res;
1857
1858
  };
1858
1859
  this.addRow = (p) => {
1859
1860
  const rows = p.rows || this.getData();
1860
1861
  const res = this._addRow(rows, p.row, p);
1861
- this.setData(res.rows);
1862
+ if (!p.rows)
1863
+ this.setData(res.rows);
1862
1864
  return res;
1863
1865
  };
1864
1866
  this.editRow = (p) => {
1865
1867
  const rows = p.rows || this.getData();
1866
1868
  const res = this._editRow(rows, p.row);
1867
- this.setData(res);
1869
+ if (!p.rows)
1870
+ this.setData(res);
1868
1871
  return res;
1869
1872
  };
1870
1873
  this.editById = (p) => {
1871
1874
  const rows = p.rows || this.getData();
1872
1875
  const res = this._editById(rows, p.rowId, p.change);
1873
- this.setData(res);
1876
+ if (!p.rows)
1877
+ this.setData(res);
1874
1878
  return res;
1875
1879
  };
1876
1880
  this.removeRow = (p) => {
1877
1881
  const rows = p.rows || this.getData();
1878
1882
  const res = this._removeRow(rows, p.rowId);
1879
- this.setData(res);
1883
+ if (!p.rows)
1884
+ this.setData(res);
1880
1885
  return res;
1881
1886
  };
1882
1887
  this.removeByRowIds = (p) => {
1883
1888
  const rows = p.rows || this.getData();
1884
1889
  const res = this._removeByRowIds(rows, p.rowIds);
1885
- this.setData(res);
1890
+ if (!p.rows)
1891
+ this.setData(res);
1886
1892
  return res;
1887
1893
  };
1888
1894
  this.reOrder = (p) => {
1889
1895
  const rows = p.rows || this.getData();
1890
1896
  const res = this._reOrder(rows, p.fromId, p.toId);
1891
- this.setData(res);
1897
+ if (!p.rows)
1898
+ this.setData(res);
1892
1899
  return res;
1893
1900
  };
1894
1901
  this.reOrderByDir = (p) => {
1895
1902
  const rows = p.rows || this.getData();
1896
1903
  const res = this._reOrderByDir(rows, p.rowId, p.dir);
1897
- this.setData(res);
1904
+ if (!p.rows)
1905
+ this.setData(res);
1898
1906
  return res;
1899
1907
  };
1900
1908
  this.moveTo = (p) => {
1901
1909
  const rows = p.rows || this.getData();
1902
1910
  const res = this._moveTo(rows, p.fromIds, p.toId);
1903
- this.setData(res);
1911
+ if (!p.rows)
1912
+ this.setData(res);
1904
1913
  return res;
1905
1914
  };
1906
1915
  this.editByTraverse = (p) => {
1907
1916
  const rows = p.rows || this.getData();
1908
1917
  const res = this._editByTraverse(rows, p.callback);
1909
- this.setData(res);
1918
+ if (!p.rows)
1919
+ this.setData(res);
1910
1920
  return res;
1911
1921
  };
1912
1922
  this.traverse = (p) => {
@@ -2498,3 +2508,57 @@ export class Swip {
2498
2508
  this.init();
2499
2509
  }
2500
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.2",
3
+ "version": "2.2.4",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/mohammadFeiz/aio-class#readme",
6
6
  "bugs": {