@rugal.tu/vuemodel3 1.5.7 → 1.5.9
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/package.json +1 -1
- package/src/VueModel.d.ts +17 -6
- package/src/VueModel.ts +124 -19
- package/dist/VueModel.esm.js +0 -1889
- package/dist/VueModel.umd.js +0 -1910
- package/src/esm/VueModel.js +0 -1889
- package/src/esm/VueModel.js.map +0 -1
- package/src/umd/VueModel.js +0 -1910
- package/src/umd/VueModel.js.map +0 -1
package/package.json
CHANGED
package/src/VueModel.d.ts
CHANGED
|
@@ -92,6 +92,9 @@ type FileItemStore = {
|
|
|
92
92
|
Base64?: string;
|
|
93
93
|
Buffer?: ArrayBuffer;
|
|
94
94
|
ConvertType?: FileConvertType | FileConvertType[];
|
|
95
|
+
IsLoaded?: boolean;
|
|
96
|
+
IsLoading?: boolean;
|
|
97
|
+
Error?: any;
|
|
95
98
|
};
|
|
96
99
|
export declare class FileItem {
|
|
97
100
|
OnChangeBase64: Function;
|
|
@@ -109,8 +112,12 @@ export declare class FileItem {
|
|
|
109
112
|
get Buffer(): ArrayBuffer;
|
|
110
113
|
set Buffer(Value: ArrayBuffer);
|
|
111
114
|
get InnerStore(): FileItemStore;
|
|
115
|
+
get IsLoaded(): boolean;
|
|
116
|
+
get IsLoading(): boolean;
|
|
117
|
+
get Error(): any;
|
|
112
118
|
Clear(): void;
|
|
113
119
|
From(Item: FileItem): void;
|
|
120
|
+
CheckLoadAsync(): Promise<boolean>;
|
|
114
121
|
protected $ConvertFile(): void;
|
|
115
122
|
protected $ConvertBase64(IsForce?: boolean): this;
|
|
116
123
|
protected $ConvertBuffer(): void;
|
|
@@ -290,14 +297,13 @@ type CommandOption = {
|
|
|
290
297
|
FuncAction?: boolean;
|
|
291
298
|
FuncArgs?: PathType;
|
|
292
299
|
};
|
|
293
|
-
type
|
|
294
|
-
CallBack: WatchCallback;
|
|
295
|
-
Option?: WatchOptions;
|
|
296
|
-
};
|
|
300
|
+
type AddCommandOption = PathType | Function | CommandOption;
|
|
297
301
|
export type TreeSetType = {
|
|
298
302
|
'using'?: UsingFunctionType;
|
|
299
303
|
'store'?: any;
|
|
300
304
|
[DomName: `:${string}`]: UsingFunctionType | TreeSetType;
|
|
305
|
+
[TagName: `@${string}`]: UsingFunctionType | TreeSetType;
|
|
306
|
+
[TagName: `tag:${string}`]: UsingFunctionType | TreeSetType;
|
|
301
307
|
'watch'?: WatchCallback | TreeWatchOption;
|
|
302
308
|
[WatchTargetCmd: `watch:${string}`]: WatchCallback | TreeWatchOption;
|
|
303
309
|
'func'?: Function;
|
|
@@ -340,7 +346,6 @@ type TreeSetFuncOption = {
|
|
|
340
346
|
TargetFunc: PathType | Function;
|
|
341
347
|
Args?: PathType;
|
|
342
348
|
};
|
|
343
|
-
type AddCommandOption = PathType | Function | CommandOption;
|
|
344
349
|
type TreeSetInfo = {
|
|
345
350
|
Nodes?: QueryNode[];
|
|
346
351
|
TreePaths: string[];
|
|
@@ -356,6 +361,10 @@ type TreeSetInfoOption = {
|
|
|
356
361
|
TargetDom: PathType | QueryNode[];
|
|
357
362
|
TargetValue: PathType | Function | CommandOption;
|
|
358
363
|
};
|
|
364
|
+
type TreeWatchOption = {
|
|
365
|
+
CallBack: WatchCallback;
|
|
366
|
+
Option?: WatchOptions;
|
|
367
|
+
};
|
|
359
368
|
type AddV_ModelOption = {
|
|
360
369
|
ModelValue?: string;
|
|
361
370
|
DefaultValue?: any;
|
|
@@ -365,6 +374,8 @@ type AddV_FilePickerOption = string | {
|
|
|
365
374
|
Accept?: string | string[];
|
|
366
375
|
Multiple?: boolean;
|
|
367
376
|
ConvertType?: FileConvertType | FileConvertType[];
|
|
377
|
+
OnSuccess?: (files: FileItem[]) => void;
|
|
378
|
+
OnError?: (file: FileItem) => void;
|
|
368
379
|
};
|
|
369
380
|
type AddV_TreeOption = {
|
|
370
381
|
UseDeepQuery?: boolean;
|
|
@@ -405,7 +416,7 @@ export declare class VueCommand extends VueStore {
|
|
|
405
416
|
protected $AddCommand(DomName: PathType | QueryNode[], Command: string, Option: CommandOption): void;
|
|
406
417
|
protected $SetAttribute(Dom: HTMLElement, AttrName: string, AttrValue: string): void;
|
|
407
418
|
protected $RandomFuncName(BaseFuncName: string): string;
|
|
408
|
-
protected $GenerateEventFunction(
|
|
419
|
+
protected $GenerateEventFunction(domName: PathType, eventFunc: Function, command: string): string;
|
|
409
420
|
}
|
|
410
421
|
export declare class VueModel extends VueCommand {
|
|
411
422
|
$NativeWarn: (...Message: any[]) => void;
|
package/src/VueModel.ts
CHANGED
|
@@ -257,6 +257,7 @@ export class QueryNode extends FuncBase {
|
|
|
257
257
|
DomName: string = null;
|
|
258
258
|
Parent: QueryNode = null;
|
|
259
259
|
Children: QueryNode[] = [];
|
|
260
|
+
//DomChildren:
|
|
260
261
|
ElementDeep: number = 0;
|
|
261
262
|
NodeDeep: number = 0;
|
|
262
263
|
constructor(Dom: HTMLElement) {
|
|
@@ -266,9 +267,11 @@ export class QueryNode extends FuncBase {
|
|
|
266
267
|
}
|
|
267
268
|
|
|
268
269
|
public Query(DomName: PathType, Option?: QueryOption): QueryNode[] {
|
|
270
|
+
Option ??= { Mode: 'Multi' };
|
|
269
271
|
return this.$RCS_QueryChildrens(this, DomName, Option);
|
|
270
272
|
}
|
|
271
273
|
public QueryCss(Selector: string, Option?: QueryOption): QueryNode[] {
|
|
274
|
+
Option ??= { Mode: 'Multi' };
|
|
272
275
|
return this.$RCS_QueryCssChildrens(this, Selector, Option);
|
|
273
276
|
}
|
|
274
277
|
public Selector(Selector: string) {
|
|
@@ -289,7 +292,22 @@ export class QueryNode extends FuncBase {
|
|
|
289
292
|
for (let NodeItem of TargetNode.Children) {
|
|
290
293
|
if (Array.isArray(DomName)) {
|
|
291
294
|
let Names: PathType = [...DomName];
|
|
292
|
-
let FirstName = Names.shift();
|
|
295
|
+
let FirstName = Names.shift() as string;
|
|
296
|
+
|
|
297
|
+
const pathRegex = FirstName.match(/^(?<key>[^:]+):(?<name>.+)$/);
|
|
298
|
+
if (pathRegex) {
|
|
299
|
+
const key = pathRegex.groups.key;
|
|
300
|
+
const name = pathRegex.groups.name;
|
|
301
|
+
switch (key) {
|
|
302
|
+
case 'tag':
|
|
303
|
+
//TargetNode.Dom.
|
|
304
|
+
//Todo:
|
|
305
|
+
break;
|
|
306
|
+
default:
|
|
307
|
+
FirstName = name;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
293
311
|
if (NodeItem.DomName == FirstName) {
|
|
294
312
|
if (Names.length == 1)
|
|
295
313
|
Names = Names[0];
|
|
@@ -484,6 +502,9 @@ type FileItemStore = {
|
|
|
484
502
|
Base64?: string;
|
|
485
503
|
Buffer?: ArrayBuffer;
|
|
486
504
|
ConvertType?: FileConvertType | FileConvertType[];
|
|
505
|
+
IsLoaded?: boolean,
|
|
506
|
+
IsLoading?: boolean,
|
|
507
|
+
Error?: any
|
|
487
508
|
}
|
|
488
509
|
export class FileItem {
|
|
489
510
|
|
|
@@ -501,6 +522,9 @@ export class FileItem {
|
|
|
501
522
|
ConvertType: ConvertType,
|
|
502
523
|
Base64: null,
|
|
503
524
|
Buffer: null,
|
|
525
|
+
IsLoaded: false,
|
|
526
|
+
IsLoading: true,
|
|
527
|
+
Error: null,
|
|
504
528
|
});
|
|
505
529
|
this.$ConvertFile();
|
|
506
530
|
}
|
|
@@ -540,6 +564,16 @@ export class FileItem {
|
|
|
540
564
|
get InnerStore() {
|
|
541
565
|
return this.$Store;
|
|
542
566
|
}
|
|
567
|
+
get IsLoaded() {
|
|
568
|
+
return this.$Store.IsLoaded;
|
|
569
|
+
}
|
|
570
|
+
get IsLoading() {
|
|
571
|
+
return this.$Store.IsLoading;
|
|
572
|
+
}
|
|
573
|
+
get Error() {
|
|
574
|
+
return this.$Store.Error;
|
|
575
|
+
}
|
|
576
|
+
|
|
543
577
|
|
|
544
578
|
public Clear() {
|
|
545
579
|
this.$Store.Base64 = null;
|
|
@@ -549,6 +583,34 @@ export class FileItem {
|
|
|
549
583
|
public From(Item: FileItem) {
|
|
550
584
|
this.$Store = Item.InnerStore;
|
|
551
585
|
}
|
|
586
|
+
public CheckLoadAsync(): Promise<boolean> {
|
|
587
|
+
return new Promise((resolve, reject) => {
|
|
588
|
+
try {
|
|
589
|
+
if (this.$Store.IsLoaded || !this.$Store.IsLoading)
|
|
590
|
+
return resolve(this.$Store.IsLoaded);
|
|
591
|
+
|
|
592
|
+
const timeout = setTimeout(() => {
|
|
593
|
+
if (timer)
|
|
594
|
+
clearInterval(timer);
|
|
595
|
+
|
|
596
|
+
this.$Store.Error = 'timeout';
|
|
597
|
+
console.error("WaitLoadAsync: timeout");
|
|
598
|
+
reject(false);
|
|
599
|
+
}, 60000);
|
|
600
|
+
const timer = setInterval(() => {
|
|
601
|
+
if (this.$Store.IsLoaded || !this.$Store.IsLoading) {
|
|
602
|
+
clearInterval(timer);
|
|
603
|
+
clearTimeout(timeout);
|
|
604
|
+
resolve(this.$Store.IsLoaded);
|
|
605
|
+
}
|
|
606
|
+
}, 100);
|
|
607
|
+
} catch (e) {
|
|
608
|
+
this.$Store.Error = e;
|
|
609
|
+
console.error(e);
|
|
610
|
+
reject(false);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
552
614
|
|
|
553
615
|
protected $ConvertFile() {
|
|
554
616
|
if (this.ConvertType == null)
|
|
@@ -564,12 +626,15 @@ export class FileItem {
|
|
|
564
626
|
let TypeItem = GetConvertType[i];
|
|
565
627
|
switch (TypeItem) {
|
|
566
628
|
case 'base64':
|
|
629
|
+
this.$Store.IsLoading = true;
|
|
567
630
|
this.$ConvertBase64();
|
|
568
631
|
break;
|
|
569
632
|
case 'buffer':
|
|
633
|
+
this.$Store.IsLoading = true;
|
|
570
634
|
this.$ConvertBuffer();
|
|
571
635
|
break;
|
|
572
636
|
default:
|
|
637
|
+
this.$Store.IsLoaded = true;
|
|
573
638
|
break;
|
|
574
639
|
}
|
|
575
640
|
}
|
|
@@ -583,13 +648,21 @@ export class FileItem {
|
|
|
583
648
|
|
|
584
649
|
let Reader = new FileReader();
|
|
585
650
|
Reader.readAsDataURL(this.File);
|
|
586
|
-
Reader.onload = () =>
|
|
651
|
+
Reader.onload = () => {
|
|
652
|
+
this.Base64 = Reader.result as string;
|
|
653
|
+
this.$Store.IsLoaded = true;
|
|
654
|
+
this.$Store.IsLoading = false;
|
|
655
|
+
}
|
|
587
656
|
return this;
|
|
588
657
|
}
|
|
589
658
|
protected $ConvertBuffer() {
|
|
590
659
|
let Reader = new FileReader();
|
|
591
660
|
Reader.readAsArrayBuffer(this.File);
|
|
592
|
-
Reader.onload = () =>
|
|
661
|
+
Reader.onload = () => {
|
|
662
|
+
this.Buffer = Reader.result as ArrayBuffer;
|
|
663
|
+
this.$Store.IsLoaded = true;
|
|
664
|
+
this.$Store.IsLoading = false;
|
|
665
|
+
}
|
|
593
666
|
}
|
|
594
667
|
}
|
|
595
668
|
type FileConvertType = 'none' | 'base64' | 'buffer';
|
|
@@ -1491,14 +1564,13 @@ type CommandOption = {
|
|
|
1491
1564
|
FuncAction?: boolean;
|
|
1492
1565
|
FuncArgs?: PathType,
|
|
1493
1566
|
};
|
|
1494
|
-
type
|
|
1495
|
-
CallBack: WatchCallback,
|
|
1496
|
-
Option?: WatchOptions,
|
|
1497
|
-
}
|
|
1567
|
+
type AddCommandOption = PathType | Function | CommandOption;
|
|
1498
1568
|
export type TreeSetType = {
|
|
1499
1569
|
'using'?: UsingFunctionType,
|
|
1500
1570
|
'store'?: any,
|
|
1501
1571
|
[DomName: `:${string}`]: UsingFunctionType | TreeSetType,
|
|
1572
|
+
[TagName: `@${string}`]: UsingFunctionType | TreeSetType,
|
|
1573
|
+
[TagName: `tag:${string}`]: UsingFunctionType | TreeSetType,
|
|
1502
1574
|
|
|
1503
1575
|
'watch'?: WatchCallback | TreeWatchOption,
|
|
1504
1576
|
[WatchTargetCmd: `watch:${string}`]: WatchCallback | TreeWatchOption,
|
|
@@ -1554,8 +1626,6 @@ type TreeSetFuncOption = {
|
|
|
1554
1626
|
TargetFunc: PathType | Function,
|
|
1555
1627
|
Args?: PathType,
|
|
1556
1628
|
};
|
|
1557
|
-
type AddCommandOption = PathType | Function | CommandOption;
|
|
1558
|
-
|
|
1559
1629
|
type TreeSetInfo = {
|
|
1560
1630
|
Nodes?: QueryNode[],
|
|
1561
1631
|
TreePaths: string[],
|
|
@@ -1571,6 +1641,10 @@ type TreeSetInfoOption = {
|
|
|
1571
1641
|
TargetDom: PathType | QueryNode[],
|
|
1572
1642
|
TargetValue: PathType | Function | CommandOption,
|
|
1573
1643
|
};
|
|
1644
|
+
type TreeWatchOption = {
|
|
1645
|
+
CallBack: WatchCallback,
|
|
1646
|
+
Option?: WatchOptions,
|
|
1647
|
+
};
|
|
1574
1648
|
type AddV_ModelOption = {
|
|
1575
1649
|
ModelValue?: string,
|
|
1576
1650
|
DefaultValue?: any,
|
|
@@ -1580,6 +1654,8 @@ type AddV_FilePickerOption = string | {
|
|
|
1580
1654
|
Accept?: string | string[],
|
|
1581
1655
|
Multiple?: boolean;
|
|
1582
1656
|
ConvertType?: FileConvertType | FileConvertType[];
|
|
1657
|
+
OnSuccess?: (files: FileItem[]) => void,
|
|
1658
|
+
OnError?: (file: FileItem) => void,
|
|
1583
1659
|
};
|
|
1584
1660
|
type AddV_TreeOption = {
|
|
1585
1661
|
UseDeepQuery?: boolean,
|
|
@@ -1737,6 +1813,8 @@ export class VueCommand extends VueStore {
|
|
|
1737
1813
|
let Accept: string = null;
|
|
1738
1814
|
let ConvertType: FileConvertType | FileConvertType[] = 'none';
|
|
1739
1815
|
let Multi: boolean = false;
|
|
1816
|
+
let OnSuccess: (files: FileItem[]) => void;
|
|
1817
|
+
let OnError: (file: FileItem) => void;
|
|
1740
1818
|
|
|
1741
1819
|
if (typeof (Option) == 'string')
|
|
1742
1820
|
FileStorePath = Option;
|
|
@@ -1744,12 +1822,14 @@ export class VueCommand extends VueStore {
|
|
|
1744
1822
|
FileStorePath = Option.Store;
|
|
1745
1823
|
ConvertType = Option.ConvertType;
|
|
1746
1824
|
Multi = Option.Multiple;
|
|
1825
|
+
OnSuccess = Option.OnSuccess;
|
|
1747
1826
|
|
|
1748
1827
|
if (Array.isArray(Option.Accept))
|
|
1749
1828
|
Accept = Option.Accept.join(' ');
|
|
1750
1829
|
else
|
|
1751
1830
|
Accept = Option.Accept;
|
|
1752
1831
|
}
|
|
1832
|
+
|
|
1753
1833
|
this.AddFileStore(FileStorePath, {
|
|
1754
1834
|
Multi: Multi,
|
|
1755
1835
|
});
|
|
@@ -1761,14 +1841,37 @@ export class VueCommand extends VueStore {
|
|
|
1761
1841
|
if (Multi != null)
|
|
1762
1842
|
TempInput.multiple = Multi;
|
|
1763
1843
|
|
|
1764
|
-
TempInput.onchange = (Event) => {
|
|
1844
|
+
TempInput.onchange = async (Event) => {
|
|
1765
1845
|
if (TempInput.files == null || TempInput.files.length == 0)
|
|
1766
1846
|
return;
|
|
1767
1847
|
|
|
1768
|
-
|
|
1848
|
+
const Files = TempInput.files;
|
|
1849
|
+
const FileItems: FileItem[] = [];
|
|
1769
1850
|
for (let i = 0; i < Files.length; i++) {
|
|
1770
1851
|
let PickFile = Files[i];
|
|
1771
1852
|
this.AddFile(FileStorePath, PickFile, ConvertType);
|
|
1853
|
+
|
|
1854
|
+
let fileData = Model.FileStore[FileStorePath];
|
|
1855
|
+
if (!Array.isArray(fileData)) {
|
|
1856
|
+
fileData = [fileData];
|
|
1857
|
+
}
|
|
1858
|
+
FileItems.push(...fileData);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
if (OnSuccess) {
|
|
1862
|
+
let isChecked = true;
|
|
1863
|
+
for (const item of FileItems) {
|
|
1864
|
+
if (item instanceof FileItem) {
|
|
1865
|
+
if (!await item.CheckLoadAsync()) {
|
|
1866
|
+
if (OnError)
|
|
1867
|
+
OnError(item);
|
|
1868
|
+
isChecked = false;
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
if (isChecked)
|
|
1874
|
+
OnSuccess(FileItems)
|
|
1772
1875
|
}
|
|
1773
1876
|
};
|
|
1774
1877
|
TempInput.click();
|
|
@@ -2107,14 +2210,14 @@ export class VueCommand extends VueStore {
|
|
|
2107
2210
|
if (Option.get)
|
|
2108
2211
|
return Option.get();
|
|
2109
2212
|
|
|
2110
|
-
return this.$get(PropertyKey);
|
|
2213
|
+
return (this as any).$get(PropertyKey);
|
|
2111
2214
|
},
|
|
2112
2215
|
set(Value) {
|
|
2113
2216
|
if (Option.set) {
|
|
2114
2217
|
Option.set(Value);
|
|
2115
2218
|
return;
|
|
2116
2219
|
}
|
|
2117
|
-
this.$set(PropertyKey, Value);
|
|
2220
|
+
(this as any).$set(PropertyKey, Value);
|
|
2118
2221
|
}
|
|
2119
2222
|
};
|
|
2120
2223
|
|
|
@@ -2244,12 +2347,14 @@ export class VueCommand extends VueStore {
|
|
|
2244
2347
|
protected $RandomFuncName(BaseFuncName: string) {
|
|
2245
2348
|
return `${BaseFuncName}${this.GenerateIdReplace('')}`.replace(/[-:.]/g, '_');
|
|
2246
2349
|
}
|
|
2247
|
-
protected $GenerateEventFunction(
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2350
|
+
protected $GenerateEventFunction(domName: PathType, eventFunc: Function, command: string) {
|
|
2351
|
+
const funcName = this.$RandomFuncName(`${command}_`);
|
|
2352
|
+
domName = this.Paths(domName);
|
|
2353
|
+
const fullFuncPath = ['event', ...domName, funcName]
|
|
2354
|
+
.filter(item => item != null && item != '');
|
|
2355
|
+
|
|
2356
|
+
this.AddV_Function(fullFuncPath, eventFunc);
|
|
2357
|
+
return this.ToJoin(fullFuncPath);
|
|
2253
2358
|
}
|
|
2254
2359
|
//#endregion
|
|
2255
2360
|
|