aio-class 2.1.5 → 2.2.1
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.
- package/index.d.ts +77 -59
- package/index.js +144 -151
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -118,13 +118,13 @@ export declare class FileClass {
|
|
|
118
118
|
duration: null | number;
|
|
119
119
|
}>;
|
|
120
120
|
fetchBlob: (url: string) => Promise<FileResult<Blob>>;
|
|
121
|
-
fetchBlob2: () => Promise<void>;
|
|
122
121
|
base64ToBlob: (base64: string) => FileResult<Blob>;
|
|
123
122
|
handleFileName: (selectedName?: string) => string;
|
|
124
123
|
generateFileName: (mimeType?: string) => string;
|
|
125
124
|
private saveWeb;
|
|
126
125
|
dataUrlToBase64: (dataUrl: string) => FileResult<string>;
|
|
127
126
|
toBlob: (input: File | Blob | string | ArrayBuffer | Uint8Array | any) => Promise<FileResult<Blob>>;
|
|
127
|
+
dataUrlToFile(dataUrl: string, fileName?: string): File;
|
|
128
128
|
saveText: (text: string, path: string) => Promise<{
|
|
129
129
|
success: boolean;
|
|
130
130
|
message: string;
|
|
@@ -196,6 +196,8 @@ export type I_EntityRowDetail<T> = {
|
|
|
196
196
|
isLeaf: boolean;
|
|
197
197
|
isFirstChild: boolean;
|
|
198
198
|
isLastChild: boolean;
|
|
199
|
+
level: number;
|
|
200
|
+
isRoot: boolean;
|
|
199
201
|
};
|
|
200
202
|
export declare class EntityClass<T> {
|
|
201
203
|
map: I_EntityMap<T>;
|
|
@@ -205,6 +207,7 @@ export declare class EntityClass<T> {
|
|
|
205
207
|
map: I_EntityMap<T>;
|
|
206
208
|
getData?: () => T[];
|
|
207
209
|
setData?: (v: T[]) => void;
|
|
210
|
+
sorts?: I_sort<T>[];
|
|
208
211
|
});
|
|
209
212
|
private getId;
|
|
210
213
|
private setId;
|
|
@@ -214,65 +217,80 @@ export declare class EntityClass<T> {
|
|
|
214
217
|
private getRowDetailByRowAndParents;
|
|
215
218
|
private removeChildOfParent;
|
|
216
219
|
private getRowByAddChild;
|
|
217
|
-
private
|
|
218
|
-
private
|
|
219
|
-
private
|
|
220
|
-
private
|
|
221
|
-
private
|
|
222
|
-
private
|
|
223
|
-
private
|
|
224
|
-
private
|
|
225
|
-
private
|
|
226
|
-
private
|
|
227
|
-
private
|
|
228
|
-
private
|
|
229
|
-
private
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
reOrderByDir: (data: T[], rowId: I_id, dir: 1 | -1) => T[];
|
|
251
|
-
moveTo: (data: T[], fromIds: I_id[], toId: I_id) => T[];
|
|
252
|
-
editByTraverse: (rows: T[], callback: (row: T) => T | false) => T[];
|
|
253
|
-
traverse: (rows: T[], callback: (row: T, detail: I_EntityRowDetail<T>) => false | undefined) => void;
|
|
254
|
-
};
|
|
255
|
-
dataActions: {
|
|
256
|
-
getRowDetailById: (rowId: any) => false | I_EntityRowDetail<T>;
|
|
257
|
-
addRow: (row: T, p: {
|
|
258
|
-
parentId?: I_id;
|
|
259
|
-
index?: number;
|
|
260
|
-
}) => {
|
|
261
|
-
rows: T[];
|
|
262
|
-
row: T;
|
|
263
|
-
};
|
|
264
|
-
editRow: (newRow: T) => T[];
|
|
265
|
-
editById: (rowId: I_id, change: Partial<T>) => T[];
|
|
266
|
-
removeRow: (rowId: I_id) => T[];
|
|
267
|
-
removeByRowIds: (rowIds: I_id[]) => T[];
|
|
268
|
-
reOrder: (fromId: I_id, toId: I_id) => T[];
|
|
269
|
-
reOrderByDir: (rowId: I_id, dir: 1 | -1) => T[];
|
|
270
|
-
moveTo: (fromIds: I_id[], toId: I_id) => T[];
|
|
271
|
-
editByTraverse: (callback: (row: T) => T | false) => T[];
|
|
272
|
-
getSortedTree: (sorts: I_sort<T>[]) => T[];
|
|
273
|
-
getFilteredTree: (filter: (row: T, detail: I_EntityRowDetail<T>) => boolean | undefined) => T[];
|
|
274
|
-
traverse: (callback: (row: T, detail: I_EntityRowDetail<T>) => false | undefined) => void;
|
|
220
|
+
private _getRowDetailById;
|
|
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
|
+
getRowDetailById: (p: {
|
|
234
|
+
rowId: I_id;
|
|
235
|
+
rows?: T[];
|
|
236
|
+
}) => false | I_EntityRowDetail<T>;
|
|
237
|
+
getFilteredTree: (p: {
|
|
238
|
+
filter: (row: T, detail: I_EntityRowDetail<T>) => boolean | undefined;
|
|
239
|
+
rows?: T[];
|
|
240
|
+
}) => T[];
|
|
241
|
+
getSortedTree: (p: {
|
|
242
|
+
sorts: I_sort<T>[];
|
|
243
|
+
rows?: T[];
|
|
244
|
+
}) => T[];
|
|
245
|
+
addRow: (p: {
|
|
246
|
+
row: T;
|
|
247
|
+
parentId?: I_id;
|
|
248
|
+
index?: number;
|
|
249
|
+
rows?: T[];
|
|
250
|
+
}) => {
|
|
251
|
+
rows: T[];
|
|
252
|
+
row: T;
|
|
275
253
|
};
|
|
254
|
+
editRow: (p: {
|
|
255
|
+
row: T;
|
|
256
|
+
rows?: T[];
|
|
257
|
+
}) => T[];
|
|
258
|
+
editById: (p: {
|
|
259
|
+
rowId: I_id;
|
|
260
|
+
change: Partial<T>;
|
|
261
|
+
rows?: T[];
|
|
262
|
+
}) => T[];
|
|
263
|
+
removeRow: (p: {
|
|
264
|
+
rowId: I_id;
|
|
265
|
+
rows?: T[];
|
|
266
|
+
}) => T[];
|
|
267
|
+
removeByRowIds: (p: {
|
|
268
|
+
rowIds: I_id[];
|
|
269
|
+
rows?: T[];
|
|
270
|
+
}) => T[];
|
|
271
|
+
reOrder: (p: {
|
|
272
|
+
fromId: I_id;
|
|
273
|
+
toId: I_id;
|
|
274
|
+
rows?: T[];
|
|
275
|
+
}) => T[];
|
|
276
|
+
reOrderByDir: (p: {
|
|
277
|
+
rowId: I_id;
|
|
278
|
+
dir: 1 | -1;
|
|
279
|
+
rows?: T[];
|
|
280
|
+
}) => T[];
|
|
281
|
+
moveTo: (p: {
|
|
282
|
+
fromIds: I_id[];
|
|
283
|
+
toId: I_id;
|
|
284
|
+
rows?: T[];
|
|
285
|
+
}) => T[];
|
|
286
|
+
editByTraverse: (p: {
|
|
287
|
+
callback: (row: T) => T | false;
|
|
288
|
+
rows?: T[];
|
|
289
|
+
}) => T[];
|
|
290
|
+
traverse: (p: {
|
|
291
|
+
callback: (row: T, detail: I_EntityRowDetail<T>) => false | undefined;
|
|
292
|
+
rows?: T[];
|
|
293
|
+
}) => void;
|
|
276
294
|
}
|
|
277
295
|
type I_color = any;
|
|
278
296
|
type I_color_type = 'rgb' | 'hex' | 'array';
|
package/index.js
CHANGED
|
@@ -803,8 +803,6 @@ export class FileClass {
|
|
|
803
803
|
return { success: false, result: null, message: (e === null || e === void 0 ? void 0 : e.message) || "Fetch failed" };
|
|
804
804
|
}
|
|
805
805
|
});
|
|
806
|
-
this.fetchBlob2 = () => __awaiter(this, void 0, void 0, function* () {
|
|
807
|
-
});
|
|
808
806
|
this.base64ToBlob = (base64) => {
|
|
809
807
|
try {
|
|
810
808
|
const byteCharacters = atob(base64);
|
|
@@ -930,6 +928,18 @@ export class FileClass {
|
|
|
930
928
|
return size + " byte";
|
|
931
929
|
};
|
|
932
930
|
}
|
|
931
|
+
dataUrlToFile(dataUrl, fileName = 'upload.bin') {
|
|
932
|
+
var _a, _b;
|
|
933
|
+
const arr = dataUrl.split(',');
|
|
934
|
+
const mime = ((_b = (_a = arr[0]) === null || _a === void 0 ? void 0 : _a.match(/:(.*?);/)) === null || _b === void 0 ? void 0 : _b[1]) || 'application/octet-stream';
|
|
935
|
+
const bstr = atob(arr[1] || arr[0]); // اگه header نداشت، کل base64 رو بگیر
|
|
936
|
+
const n = bstr.length;
|
|
937
|
+
const u8arr = new Uint8Array(n);
|
|
938
|
+
for (let i = 0; i < n; i++) {
|
|
939
|
+
u8arr[i] = bstr.charCodeAt(i);
|
|
940
|
+
}
|
|
941
|
+
return new File([u8arr], fileName, { type: mime });
|
|
942
|
+
}
|
|
933
943
|
}
|
|
934
944
|
export class StorageClass {
|
|
935
945
|
constructor(id, context) {
|
|
@@ -1506,7 +1516,7 @@ export class EntityClass {
|
|
|
1506
1516
|
this.getChilds = (row) => this.map.getChilds(row);
|
|
1507
1517
|
this.setChilds = (row, childs) => this.map.setChilds(row, childs);
|
|
1508
1518
|
this.getRowDetailsByIds = (data, rowIds) => {
|
|
1509
|
-
const fn = (data, parents, temp) => {
|
|
1519
|
+
const fn = (data, parents, level, temp) => {
|
|
1510
1520
|
const isFoundAll = () => Object.keys(temp).filter((rowId) => temp[rowId] === false).length === 0;
|
|
1511
1521
|
for (let i = 0; i < data.length; i++) {
|
|
1512
1522
|
if (isFoundAll()) {
|
|
@@ -1517,11 +1527,11 @@ export class EntityClass {
|
|
|
1517
1527
|
const row = data[i];
|
|
1518
1528
|
const rowId = this.getId(row);
|
|
1519
1529
|
if (temp[rowId.toString()] === false) {
|
|
1520
|
-
temp[rowId.toString()] = this.getRowDetailByRowAndParents(row, i, parents, isFirstChild, isLastChild);
|
|
1530
|
+
temp[rowId.toString()] = this.getRowDetailByRowAndParents(row, i, parents, isFirstChild, isLastChild, level);
|
|
1521
1531
|
}
|
|
1522
1532
|
const childs = this.getChilds(row);
|
|
1523
1533
|
if (childs && childs.length) {
|
|
1524
|
-
fn(childs, [...parents, row], temp);
|
|
1534
|
+
fn(childs, [...parents, row], level + 1, temp);
|
|
1525
1535
|
}
|
|
1526
1536
|
}
|
|
1527
1537
|
};
|
|
@@ -1529,10 +1539,10 @@ export class EntityClass {
|
|
|
1529
1539
|
for (let i = 0; i < rowIds.length; i++) {
|
|
1530
1540
|
temp[rowIds[i].toString()] = false;
|
|
1531
1541
|
}
|
|
1532
|
-
fn(data, [], temp);
|
|
1542
|
+
fn(data, [], 0, temp);
|
|
1533
1543
|
return temp;
|
|
1534
1544
|
};
|
|
1535
|
-
this.getRowDetailByRowAndParents = (row, index, parentRows, isFirstChild, isLastChild) => {
|
|
1545
|
+
this.getRowDetailByRowAndParents = (row, index, parentRows, isFirstChild, isLastChild, level) => {
|
|
1536
1546
|
const rowId = this.getId(row);
|
|
1537
1547
|
const childs = this.getChilds(row);
|
|
1538
1548
|
const childsLength = childs ? childs.length : 0;
|
|
@@ -1546,7 +1556,7 @@ export class EntityClass {
|
|
|
1546
1556
|
beforeSibling = parentChilds[index - 1] || false;
|
|
1547
1557
|
afterSibling = parentChilds[index + 1] || false;
|
|
1548
1558
|
}
|
|
1549
|
-
return { row, parentRows, rowId, childsLength, parentId, isLeaf, parentRow, index, beforeSibling, afterSibling, isFirstChild, isLastChild };
|
|
1559
|
+
return { row, parentRows, rowId, childsLength, parentId, isLeaf, parentRow, index, beforeSibling, afterSibling, isFirstChild, isLastChild, level, isRoot: level === 0 };
|
|
1550
1560
|
};
|
|
1551
1561
|
this.removeChildOfParent = (parentRow, rowId) => {
|
|
1552
1562
|
let childs = this.getChilds(parentRow);
|
|
@@ -1562,8 +1572,8 @@ export class EntityClass {
|
|
|
1562
1572
|
newChilds.splice(index === undefined ? newChilds.length : index, 0, row);
|
|
1563
1573
|
return this.setChilds(parentRow, newChilds);
|
|
1564
1574
|
};
|
|
1565
|
-
this.
|
|
1566
|
-
const fn = (data, rowId, parents, temp) => {
|
|
1575
|
+
this._getRowDetailById = (data, rowId) => {
|
|
1576
|
+
const fn = (data, rowId, parents, level, temp) => {
|
|
1567
1577
|
if (temp.res) {
|
|
1568
1578
|
return;
|
|
1569
1579
|
}
|
|
@@ -1573,24 +1583,24 @@ export class EntityClass {
|
|
|
1573
1583
|
const row = data[i];
|
|
1574
1584
|
const childs = this.getChilds(row);
|
|
1575
1585
|
if (this.getId(row).toString() === rowId.toString()) {
|
|
1576
|
-
temp.res = this.getRowDetailByRowAndParents(row, i, parents, isFirstChild, isLastChild);
|
|
1586
|
+
temp.res = this.getRowDetailByRowAndParents(row, i, parents, isFirstChild, isLastChild, level);
|
|
1577
1587
|
break;
|
|
1578
1588
|
}
|
|
1579
1589
|
else {
|
|
1580
1590
|
if (childs && childs.length) {
|
|
1581
|
-
fn(childs, rowId, [...parents, row], temp);
|
|
1591
|
+
fn(childs, rowId, [...parents, row], level + 1, temp);
|
|
1582
1592
|
}
|
|
1583
1593
|
}
|
|
1584
1594
|
}
|
|
1585
1595
|
};
|
|
1586
1596
|
let temp = { res: false };
|
|
1587
|
-
fn(data, rowId, [], temp);
|
|
1597
|
+
fn(data, rowId, [], 0, temp);
|
|
1588
1598
|
return temp.res ? temp.res : false;
|
|
1589
1599
|
};
|
|
1590
|
-
this.
|
|
1600
|
+
this._getFilteredTree = (data, filter) => {
|
|
1591
1601
|
const getNodesDic = (data, filter) => {
|
|
1592
1602
|
const detailDic = {};
|
|
1593
|
-
this.
|
|
1603
|
+
this._traverse(data, (row, detail) => {
|
|
1594
1604
|
const res = filter(row, detail);
|
|
1595
1605
|
if (res === false) {
|
|
1596
1606
|
return false;
|
|
@@ -1605,17 +1615,17 @@ export class EntityClass {
|
|
|
1605
1615
|
});
|
|
1606
1616
|
return detailDic;
|
|
1607
1617
|
};
|
|
1608
|
-
const fn = (data, parentRows) => {
|
|
1618
|
+
const fn = (data, parentRows, level) => {
|
|
1609
1619
|
const res = data.filter((row, i) => {
|
|
1610
1620
|
const isFirstChild = i === 0;
|
|
1611
1621
|
const isLastChild = i === data.length - 1;
|
|
1612
|
-
const detail = this.getRowDetailByRowAndParents(row, i, parentRows, isFirstChild, isLastChild);
|
|
1622
|
+
const detail = this.getRowDetailByRowAndParents(row, i, parentRows, isFirstChild, isLastChild, level);
|
|
1613
1623
|
return !!nodesDic[detail.rowId.toString()];
|
|
1614
1624
|
});
|
|
1615
1625
|
return res.map((row) => {
|
|
1616
1626
|
const childs = this.getChilds(row);
|
|
1617
1627
|
if (childs) {
|
|
1618
|
-
const newChilds = fn(childs, (parentRows || []).concat(row));
|
|
1628
|
+
const newChilds = fn(childs, (parentRows || []).concat(row), level + 1);
|
|
1619
1629
|
return this.setChilds(row, newChilds);
|
|
1620
1630
|
}
|
|
1621
1631
|
else {
|
|
@@ -1624,29 +1634,29 @@ export class EntityClass {
|
|
|
1624
1634
|
});
|
|
1625
1635
|
};
|
|
1626
1636
|
const nodesDic = getNodesDic(data, filter);
|
|
1627
|
-
return fn(data, []);
|
|
1637
|
+
return fn(data, [], 0);
|
|
1628
1638
|
};
|
|
1629
|
-
this.
|
|
1639
|
+
this._getSortedTree = (rows, sorts) => {
|
|
1630
1640
|
let sortedRows = SortArray(rows, sorts);
|
|
1631
1641
|
return sortedRows.map((o) => {
|
|
1632
1642
|
const childs = this.getChilds(o);
|
|
1633
1643
|
if (!childs || !childs.length) {
|
|
1634
1644
|
return o;
|
|
1635
1645
|
}
|
|
1636
|
-
const newChilds = this.
|
|
1646
|
+
const newChilds = this._getSortedTree(childs, sorts);
|
|
1637
1647
|
return this.setChilds(Object.assign({}, o), newChilds);
|
|
1638
1648
|
});
|
|
1639
1649
|
};
|
|
1640
|
-
this.
|
|
1650
|
+
this._addRow = (data, row, p) => {
|
|
1641
1651
|
const { parentId, index } = p;
|
|
1642
1652
|
const newRow = this.setId(row);
|
|
1643
1653
|
if (parentId !== undefined) {
|
|
1644
|
-
const detail = this.
|
|
1654
|
+
const detail = this._getRowDetailById(data, parentId);
|
|
1645
1655
|
if (!detail) {
|
|
1646
1656
|
return { rows: data, row };
|
|
1647
1657
|
}
|
|
1648
1658
|
const parent = this.getRowByAddChild(detail.row, newRow);
|
|
1649
|
-
const newData = this.
|
|
1659
|
+
const newData = this._editRow(data, parent);
|
|
1650
1660
|
return { rows: newData, row: newRow };
|
|
1651
1661
|
}
|
|
1652
1662
|
else {
|
|
@@ -1655,50 +1665,50 @@ export class EntityClass {
|
|
|
1655
1665
|
return { rows: newData, row: newRow };
|
|
1656
1666
|
}
|
|
1657
1667
|
};
|
|
1658
|
-
this.
|
|
1668
|
+
this._editRow = (data, newRow) => {
|
|
1659
1669
|
const rowId = this.getId(newRow);
|
|
1660
|
-
const detail = this.
|
|
1670
|
+
const detail = this._getRowDetailById(data, rowId);
|
|
1661
1671
|
const parentRow = detail.parentRow;
|
|
1662
1672
|
if (parentRow) {
|
|
1663
1673
|
const childs = this.getChilds(parentRow);
|
|
1664
1674
|
const newChilds = childs.map((o) => this.getId(o).toString() === rowId.toString() ? newRow : o);
|
|
1665
1675
|
const newParentRow = this.setChilds(parentRow, newChilds);
|
|
1666
|
-
return this.
|
|
1676
|
+
return this._editRow(data, newParentRow);
|
|
1667
1677
|
}
|
|
1668
1678
|
else {
|
|
1669
1679
|
return data.map((o) => this.getId(o).toString() === this.getId(newRow).toString() ? newRow : o);
|
|
1670
1680
|
}
|
|
1671
1681
|
};
|
|
1672
|
-
this.
|
|
1673
|
-
const detail = this.
|
|
1682
|
+
this._editById = (data, rowId, change) => {
|
|
1683
|
+
const detail = this._getRowDetailById(data, rowId);
|
|
1674
1684
|
if (!detail) {
|
|
1675
1685
|
return data;
|
|
1676
1686
|
}
|
|
1677
1687
|
const newRow = Object.assign(Object.assign({}, detail.row), change);
|
|
1678
|
-
return this.
|
|
1688
|
+
return this._editRow(data, newRow);
|
|
1679
1689
|
};
|
|
1680
|
-
this.
|
|
1681
|
-
let detail = this.
|
|
1690
|
+
this._removeRow = (data, rowId) => {
|
|
1691
|
+
let detail = this._getRowDetailById(data, rowId);
|
|
1682
1692
|
if (!detail) {
|
|
1683
1693
|
return data;
|
|
1684
1694
|
}
|
|
1685
1695
|
let parentRow = detail.parentRow;
|
|
1686
1696
|
if (parentRow) {
|
|
1687
1697
|
parentRow = this.removeChildOfParent(parentRow, rowId);
|
|
1688
|
-
return this.
|
|
1698
|
+
return this._editRow(data, parentRow);
|
|
1689
1699
|
}
|
|
1690
1700
|
else {
|
|
1691
1701
|
return data.filter((o) => this.getId(o).toString() !== rowId.toString());
|
|
1692
1702
|
}
|
|
1693
1703
|
};
|
|
1694
|
-
this.
|
|
1704
|
+
this._removeByRowIds = (data, rowIds) => {
|
|
1695
1705
|
let tempRows = [...data];
|
|
1696
1706
|
for (let i = 0; i < rowIds.length; i++) {
|
|
1697
|
-
tempRows = this.
|
|
1707
|
+
tempRows = this._removeRow(tempRows, rowIds[i]);
|
|
1698
1708
|
}
|
|
1699
1709
|
return tempRows;
|
|
1700
1710
|
};
|
|
1701
|
-
this.
|
|
1711
|
+
this._reOrder = (data, fromId, toId, pos) => {
|
|
1702
1712
|
if (fromId.toString() === toId.toString()) {
|
|
1703
1713
|
return data;
|
|
1704
1714
|
}
|
|
@@ -1729,20 +1739,20 @@ export class EntityClass {
|
|
|
1729
1739
|
//مبدا رو با آی دی جدید به پرنت مقصد در ایندکس ردیف مقصد اضافه کن
|
|
1730
1740
|
const newToParent = this.getRowByAddChild(toParent, fromRow, toIndex);
|
|
1731
1741
|
//دیتا رو با این ردیف جدید ویرایش کن
|
|
1732
|
-
let newData = this.
|
|
1742
|
+
let newData = this._editRow(data, newToParent);
|
|
1733
1743
|
//مبدا رو از دیتای جدید حذف کن
|
|
1734
|
-
return this.
|
|
1744
|
+
return this._removeRow(newData, fromDetail.rowId);
|
|
1735
1745
|
}
|
|
1736
1746
|
//اگر پرنت نداشت
|
|
1737
1747
|
else {
|
|
1738
1748
|
//مبدا رو با آی دی جدید به پرنت مقصد در ایندکس ردیف مقصد اضافه کن
|
|
1739
|
-
let newData = this.
|
|
1749
|
+
let newData = this._addRow(data, fromRow, { index: toIndex });
|
|
1740
1750
|
//مبدا رو از دیتای جدید حذف کن
|
|
1741
|
-
return this.
|
|
1751
|
+
return this._removeRow(newData.rows, fromDetail.rowId);
|
|
1742
1752
|
}
|
|
1743
1753
|
};
|
|
1744
|
-
this.
|
|
1745
|
-
const from = this.
|
|
1754
|
+
this._reOrderByDir = (data, rowId, dir) => {
|
|
1755
|
+
const from = this._getRowDetailById(data, rowId);
|
|
1746
1756
|
if (!from) {
|
|
1747
1757
|
return data;
|
|
1748
1758
|
}
|
|
@@ -1752,9 +1762,9 @@ export class EntityClass {
|
|
|
1752
1762
|
}
|
|
1753
1763
|
const fromId = rowId;
|
|
1754
1764
|
const toId = this.getId(sibling);
|
|
1755
|
-
return this.
|
|
1765
|
+
return this._reOrder(data, fromId, toId, dir === 1 ? 'after' : 'before') || data;
|
|
1756
1766
|
};
|
|
1757
|
-
this.
|
|
1767
|
+
this._moveTo = (data, fromIds, toId) => {
|
|
1758
1768
|
const fn = (data, fromId, toId) => {
|
|
1759
1769
|
const details = this.getRowDetailsByIds(data, [fromId, toId]);
|
|
1760
1770
|
let toDetail = details[toId];
|
|
@@ -1769,14 +1779,14 @@ export class EntityClass {
|
|
|
1769
1779
|
if (isToChildOfFrom) {
|
|
1770
1780
|
return data;
|
|
1771
1781
|
}
|
|
1772
|
-
const newData = this.
|
|
1782
|
+
const newData = this._removeRow(data, fromId);
|
|
1773
1783
|
//اگر بروز نشه مشکل بوجود میاد
|
|
1774
|
-
toDetail = this.
|
|
1784
|
+
toDetail = this._getRowDetailById(newData, toId);
|
|
1775
1785
|
if (!toDetail) {
|
|
1776
1786
|
return data;
|
|
1777
1787
|
}
|
|
1778
1788
|
const newToRow = this.getRowByAddChild(toDetail.row, fromDetail.row);
|
|
1779
|
-
return this.
|
|
1789
|
+
return this._editRow(newData, newToRow);
|
|
1780
1790
|
};
|
|
1781
1791
|
let rows = data;
|
|
1782
1792
|
for (let i = 0; i < fromIds.length; i++) {
|
|
@@ -1784,7 +1794,7 @@ export class EntityClass {
|
|
|
1784
1794
|
}
|
|
1785
1795
|
return rows;
|
|
1786
1796
|
};
|
|
1787
|
-
this.
|
|
1797
|
+
this._editByTraverse = (rows, callback) => {
|
|
1788
1798
|
const fn = (data, parentRow) => {
|
|
1789
1799
|
for (let i = 0; i < data.length; i++) {
|
|
1790
1800
|
let row = data[i];
|
|
@@ -1810,125 +1820,108 @@ export class EntityClass {
|
|
|
1810
1820
|
fn(rows);
|
|
1811
1821
|
return rows;
|
|
1812
1822
|
};
|
|
1813
|
-
this.
|
|
1814
|
-
const fn = (data, parentRows) => {
|
|
1823
|
+
this._traverse = (rows, callback) => {
|
|
1824
|
+
const fn = (data, parentRows, level) => {
|
|
1815
1825
|
for (let i = 0; i < data.length; i++) {
|
|
1816
1826
|
let row = data[i];
|
|
1817
1827
|
const isFirstChild = i === 0;
|
|
1818
1828
|
const isLastChild = i === data.length - 1;
|
|
1819
|
-
const detail = this.getRowDetailByRowAndParents(row, i, parentRows, isFirstChild, isLastChild);
|
|
1829
|
+
const detail = this.getRowDetailByRowAndParents(row, i, parentRows, isFirstChild, isLastChild, level);
|
|
1820
1830
|
const res = callback(row, detail);
|
|
1821
1831
|
if (res === false || !detail.childsLength) {
|
|
1822
1832
|
continue;
|
|
1823
1833
|
}
|
|
1824
1834
|
const childs = this.getChilds(row);
|
|
1825
|
-
fn(childs, [...parentRows, row]);
|
|
1835
|
+
fn(childs, [...parentRows, row], level + 1);
|
|
1826
1836
|
}
|
|
1827
1837
|
};
|
|
1828
|
-
fn(rows, []);
|
|
1829
|
-
};
|
|
1830
|
-
this.
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
},
|
|
1902
|
-
editByTraverse: (callback) => {
|
|
1903
|
-
const data = this.getData();
|
|
1904
|
-
const res = this.editByTraverse(data, callback);
|
|
1905
|
-
this.setData(res);
|
|
1906
|
-
return res;
|
|
1907
|
-
},
|
|
1908
|
-
getSortedTree: (sorts) => {
|
|
1909
|
-
const data = this.getData();
|
|
1910
|
-
const res = this.getSortedTree(data, sorts);
|
|
1911
|
-
this.setData(res);
|
|
1912
|
-
return res;
|
|
1913
|
-
},
|
|
1914
|
-
getFilteredTree: (filter) => {
|
|
1915
|
-
const data = this.getData();
|
|
1916
|
-
const res = this.getFilteredTree(data, filter);
|
|
1917
|
-
this.setData(res);
|
|
1918
|
-
return res;
|
|
1919
|
-
},
|
|
1920
|
-
traverse: (callback) => {
|
|
1921
|
-
const data = this.getData();
|
|
1922
|
-
this.traverse(data, callback);
|
|
1923
|
-
}
|
|
1838
|
+
fn(rows, [], 0);
|
|
1839
|
+
};
|
|
1840
|
+
this.getRowDetailById = (p) => {
|
|
1841
|
+
const rows = p.rows || this.getData();
|
|
1842
|
+
return this._getRowDetailById(rows, p.rowId);
|
|
1843
|
+
};
|
|
1844
|
+
this.getFilteredTree = (p) => {
|
|
1845
|
+
const rows = p.rows || this.getData();
|
|
1846
|
+
return this._getFilteredTree(rows, p.filter);
|
|
1847
|
+
};
|
|
1848
|
+
this.getSortedTree = (p) => {
|
|
1849
|
+
const rows = p.rows || this.getData();
|
|
1850
|
+
const res = this._getSortedTree(rows, p.sorts);
|
|
1851
|
+
this.setData(res);
|
|
1852
|
+
return res;
|
|
1853
|
+
};
|
|
1854
|
+
this.addRow = (p) => {
|
|
1855
|
+
const rows = p.rows || this.getData();
|
|
1856
|
+
const res = this._addRow(rows, p.row, p);
|
|
1857
|
+
this.setData(res.rows);
|
|
1858
|
+
return res;
|
|
1859
|
+
};
|
|
1860
|
+
this.editRow = (p) => {
|
|
1861
|
+
const rows = p.rows || this.getData();
|
|
1862
|
+
const res = this._editRow(rows, p.row);
|
|
1863
|
+
this.setData(res);
|
|
1864
|
+
return res;
|
|
1865
|
+
};
|
|
1866
|
+
this.editById = (p) => {
|
|
1867
|
+
const rows = p.rows || this.getData();
|
|
1868
|
+
const res = this._editById(rows, p.rowId, p.change);
|
|
1869
|
+
this.setData(res);
|
|
1870
|
+
return res;
|
|
1871
|
+
};
|
|
1872
|
+
this.removeRow = (p) => {
|
|
1873
|
+
const rows = p.rows || this.getData();
|
|
1874
|
+
const res = this._removeRow(rows, p.rowId);
|
|
1875
|
+
this.setData(res);
|
|
1876
|
+
return res;
|
|
1877
|
+
};
|
|
1878
|
+
this.removeByRowIds = (p) => {
|
|
1879
|
+
const rows = p.rows || this.getData();
|
|
1880
|
+
const res = this._removeByRowIds(rows, p.rowIds);
|
|
1881
|
+
this.setData(res);
|
|
1882
|
+
return res;
|
|
1883
|
+
};
|
|
1884
|
+
this.reOrder = (p) => {
|
|
1885
|
+
const rows = p.rows || this.getData();
|
|
1886
|
+
const res = this._reOrder(rows, p.fromId, p.toId);
|
|
1887
|
+
this.setData(res);
|
|
1888
|
+
return res;
|
|
1889
|
+
};
|
|
1890
|
+
this.reOrderByDir = (p) => {
|
|
1891
|
+
const rows = p.rows || this.getData();
|
|
1892
|
+
const res = this._reOrderByDir(rows, p.rowId, p.dir);
|
|
1893
|
+
this.setData(res);
|
|
1894
|
+
return res;
|
|
1895
|
+
};
|
|
1896
|
+
this.moveTo = (p) => {
|
|
1897
|
+
const rows = p.rows || this.getData();
|
|
1898
|
+
const res = this._moveTo(rows, p.fromIds, p.toId);
|
|
1899
|
+
this.setData(res);
|
|
1900
|
+
return res;
|
|
1901
|
+
};
|
|
1902
|
+
this.editByTraverse = (p) => {
|
|
1903
|
+
const rows = p.rows || this.getData();
|
|
1904
|
+
const res = this._editByTraverse(rows, p.callback);
|
|
1905
|
+
this.setData(res);
|
|
1906
|
+
return res;
|
|
1907
|
+
};
|
|
1908
|
+
this.traverse = (p) => {
|
|
1909
|
+
const rows = p.rows || this.getData();
|
|
1910
|
+
this._traverse(rows, p.callback);
|
|
1924
1911
|
};
|
|
1925
1912
|
this.map = p.map;
|
|
1926
1913
|
if (p.getData) {
|
|
1927
1914
|
this.getData = p.getData;
|
|
1928
1915
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1916
|
+
this.setData = (v) => {
|
|
1917
|
+
if (p.setData) {
|
|
1918
|
+
let newData = v;
|
|
1919
|
+
if (p.sorts && p.sorts.length) {
|
|
1920
|
+
newData = this._getSortedTree(newData, p.sorts);
|
|
1921
|
+
}
|
|
1922
|
+
p.setData(newData);
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1932
1925
|
}
|
|
1933
1926
|
}
|
|
1934
1927
|
export class AIOColors {
|