phecda-vue 1.2.9 → 1.3.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.
- package/dist/index.d.ts +3 -5
- package/dist/index.js +51 -39
- package/dist/index.mjs +51 -37
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -48,9 +48,7 @@ declare function usePatch<T extends new (...args: any) => any>(Model: T, Data: _
|
|
|
48
48
|
declare function useR<T extends new (...args: any) => any>(Model: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
49
49
|
declare function useV<T extends new (...args: any) => any>(Model: T): PublicOnly<ReplaceInstanceValues<InstanceType<T>>>;
|
|
50
50
|
declare function useEvent<Key extends keyof PhecdaEvents>(eventName: Key, cb: Handler<PhecdaEvents[Key]>): () => void;
|
|
51
|
-
declare function
|
|
52
|
-
declare function clearStorage<M extends new (...args: any) => any>(Model: M, isForceUpdate?: boolean): void;
|
|
53
|
-
declare function deleteStorage(tag: string): void;
|
|
51
|
+
declare function initialize<M extends new (...args: any) => any>(Model: M): InstanceType<M> | void;
|
|
54
52
|
|
|
55
53
|
declare const EXPRESS_RE: RegExp;
|
|
56
54
|
declare const FN_RE: RegExp;
|
|
@@ -77,7 +75,7 @@ declare function createForm<P extends {
|
|
|
77
75
|
$props: any;
|
|
78
76
|
}>(compSet: Record<string, Component> | any, form: Component<P>, formItem: Component | false, options?: {
|
|
79
77
|
modelKey?: string;
|
|
80
|
-
onUpdate?: (key: string) => void;
|
|
78
|
+
onUpdate?: (key: string, v: any) => void;
|
|
81
79
|
}): DefineComponent<{
|
|
82
80
|
config: Object;
|
|
83
81
|
data: Object;
|
|
@@ -129,4 +127,4 @@ declare class PV {
|
|
|
129
127
|
off<Key extends keyof PhecdaEvents>(type: Key, handler?: (arg: PhecdaEvents[Key]) => void): void;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
export { EXPRESS_RE, FN_RE, GetDevUIRules, PV, PhecdaEmitter, PublicOnly, ReplaceInstanceValues, SchemaToObj,
|
|
130
|
+
export { EXPRESS_RE, FN_RE, GetDevUIRules, PV, PhecdaEmitter, PublicOnly, ReplaceInstanceValues, SchemaToObj, createFilter, createForm, createFormData, createModal, createPhecda, createPipe, createTable, emitter, getActivePhecda, getAntDRules, getElementPlusRules, getNaiveUIRules, getNutUIRules, getReactiveMap, getVantRules, initialize, phecdaSymbol, setActivePhecda, useEvent, useO, usePatch, useR, useV };
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(src_exports, {
|
|
|
32
32
|
FN_RE: () => FN_RE,
|
|
33
33
|
GetDevUIRules: () => GetDevUIRules,
|
|
34
34
|
PV: () => PV,
|
|
35
|
-
clearStorage: () => clearStorage,
|
|
36
35
|
createFilter: () => createFilter,
|
|
37
36
|
createForm: () => createForm,
|
|
38
37
|
createFormData: () => createFormData,
|
|
@@ -40,7 +39,6 @@ __export(src_exports, {
|
|
|
40
39
|
createPhecda: () => createPhecda,
|
|
41
40
|
createPipe: () => createPipe,
|
|
42
41
|
createTable: () => createTable,
|
|
43
|
-
deleteStorage: () => deleteStorage,
|
|
44
42
|
emitter: () => emitter,
|
|
45
43
|
getActivePhecda: () => getActivePhecda,
|
|
46
44
|
getAntDRules: () => getAntDRules,
|
|
@@ -49,7 +47,7 @@ __export(src_exports, {
|
|
|
49
47
|
getNutUIRules: () => getNutUIRules,
|
|
50
48
|
getReactiveMap: () => getReactiveMap,
|
|
51
49
|
getVantRules: () => getVantRules,
|
|
52
|
-
|
|
50
|
+
initialize: () => initialize,
|
|
53
51
|
phecdaSymbol: () => phecdaSymbol,
|
|
54
52
|
setActivePhecda: () => setActivePhecda,
|
|
55
53
|
useEvent: () => useEvent,
|
|
@@ -91,26 +89,49 @@ function createPhecda(symbol) {
|
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
91
|
let eventRecord = [];
|
|
94
|
-
(0, import_phecda_core.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
92
|
+
if (!(0, import_phecda_core.getProperty)("watcher")) {
|
|
93
|
+
(0, import_phecda_core.injectProperty)("watcher", ({ eventName, instance, key, options }) => {
|
|
94
|
+
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
95
|
+
if (options?.once) {
|
|
96
|
+
const handler = /* @__PURE__ */ __name((...args) => {
|
|
97
|
+
fn(...args);
|
|
98
|
+
emitter.off(eventName, handler);
|
|
99
|
+
}, "handler");
|
|
100
|
+
emitter.on(eventName, handler);
|
|
101
|
+
eventRecord.push([
|
|
102
|
+
eventName,
|
|
103
|
+
handler
|
|
104
|
+
]);
|
|
105
|
+
} else {
|
|
106
|
+
eventRecord.push([
|
|
107
|
+
eventName,
|
|
108
|
+
fn
|
|
109
|
+
]);
|
|
110
|
+
emitter.on(eventName, fn);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!(0, import_phecda_core.getProperty)("storage")) {
|
|
115
|
+
(0, import_phecda_core.injectProperty)("storage", ({ tag, key, instance }) => {
|
|
116
|
+
if (!tag)
|
|
117
|
+
return;
|
|
118
|
+
const initstr = localStorage.getItem(tag);
|
|
119
|
+
if (initstr) {
|
|
120
|
+
const data = JSON.parse(initstr);
|
|
121
|
+
if (key) {
|
|
122
|
+
instance[key] = data;
|
|
123
|
+
} else {
|
|
124
|
+
for (const i in data) {
|
|
125
|
+
if (i)
|
|
126
|
+
instance[i] = data[i];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
globalThis.addEventListener("beforeunload", () => {
|
|
131
|
+
localStorage.setItem(tag, JSON.stringify(key ? instance[key] : instance));
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
114
135
|
const originUnmount = app.unmount.bind(app);
|
|
115
136
|
app.unmount = () => {
|
|
116
137
|
eventRecord.forEach(([eventName, handler]) => emitter.off(eventName, handler));
|
|
@@ -314,23 +335,14 @@ function useEvent(eventName, cb) {
|
|
|
314
335
|
return () => emitter.off(eventName, cb);
|
|
315
336
|
}
|
|
316
337
|
__name(useEvent, "useEvent");
|
|
317
|
-
function
|
|
338
|
+
function initialize(Model) {
|
|
318
339
|
const instance = useO(Model);
|
|
319
340
|
if (instance) {
|
|
320
341
|
Object.assign(instance, new Model());
|
|
321
342
|
return instance;
|
|
322
343
|
}
|
|
323
344
|
}
|
|
324
|
-
__name(
|
|
325
|
-
function clearStorage(Model, isForceUpdate = true) {
|
|
326
|
-
localStorage.removeItem(`_phecda_${useO(Model)._symbol}`);
|
|
327
|
-
isForceUpdate && initalize(Model);
|
|
328
|
-
}
|
|
329
|
-
__name(clearStorage, "clearStorage");
|
|
330
|
-
function deleteStorage(tag) {
|
|
331
|
-
localStorage.removeItem(`_phecda_${tag}`);
|
|
332
|
-
}
|
|
333
|
-
__name(deleteStorage, "deleteStorage");
|
|
345
|
+
__name(initialize, "initialize");
|
|
334
346
|
|
|
335
347
|
// src/filter.ts
|
|
336
348
|
var import_vue4 = require("vue");
|
|
@@ -439,8 +451,10 @@ function createForm(compSet, form, formItem, options = {}) {
|
|
|
439
451
|
...props.config[property],
|
|
440
452
|
[`${modelKey}`]: props.data[property],
|
|
441
453
|
[`onUpdate:${modelKey}`]: (v) => {
|
|
442
|
-
onUpdate
|
|
443
|
-
|
|
454
|
+
if (onUpdate)
|
|
455
|
+
onUpdate(property, v);
|
|
456
|
+
else
|
|
457
|
+
props.data[property] = v;
|
|
444
458
|
}
|
|
445
459
|
}, {
|
|
446
460
|
default: () => generateChildVNode(props.config[props.property])
|
|
@@ -780,7 +794,6 @@ __name(PV, "PV");
|
|
|
780
794
|
FN_RE,
|
|
781
795
|
GetDevUIRules,
|
|
782
796
|
PV,
|
|
783
|
-
clearStorage,
|
|
784
797
|
createFilter,
|
|
785
798
|
createForm,
|
|
786
799
|
createFormData,
|
|
@@ -788,7 +801,6 @@ __name(PV, "PV");
|
|
|
788
801
|
createPhecda,
|
|
789
802
|
createPipe,
|
|
790
803
|
createTable,
|
|
791
|
-
deleteStorage,
|
|
792
804
|
emitter,
|
|
793
805
|
getActivePhecda,
|
|
794
806
|
getAntDRules,
|
|
@@ -797,7 +809,7 @@ __name(PV, "PV");
|
|
|
797
809
|
getNutUIRules,
|
|
798
810
|
getReactiveMap,
|
|
799
811
|
getVantRules,
|
|
800
|
-
|
|
812
|
+
initialize,
|
|
801
813
|
phecdaSymbol,
|
|
802
814
|
setActivePhecda,
|
|
803
815
|
useEvent,
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var emitter = mitt();
|
|
|
7
7
|
|
|
8
8
|
// src/vue/phecda.ts
|
|
9
9
|
import { markRaw } from "vue";
|
|
10
|
-
import { getTag, injectProperty } from "phecda-core";
|
|
10
|
+
import { getProperty, getTag, injectProperty } from "phecda-core";
|
|
11
11
|
var phecdaSymbol = Symbol("phecda");
|
|
12
12
|
function createPhecda(symbol) {
|
|
13
13
|
const phecda = markRaw({
|
|
@@ -32,26 +32,49 @@ function createPhecda(symbol) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
let eventRecord = [];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
if (!getProperty("watcher")) {
|
|
36
|
+
injectProperty("watcher", ({ eventName, instance, key, options }) => {
|
|
37
|
+
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
38
|
+
if (options?.once) {
|
|
39
|
+
const handler = /* @__PURE__ */ __name((...args) => {
|
|
40
|
+
fn(...args);
|
|
41
|
+
emitter.off(eventName, handler);
|
|
42
|
+
}, "handler");
|
|
43
|
+
emitter.on(eventName, handler);
|
|
44
|
+
eventRecord.push([
|
|
45
|
+
eventName,
|
|
46
|
+
handler
|
|
47
|
+
]);
|
|
48
|
+
} else {
|
|
49
|
+
eventRecord.push([
|
|
50
|
+
eventName,
|
|
51
|
+
fn
|
|
52
|
+
]);
|
|
53
|
+
emitter.on(eventName, fn);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!getProperty("storage")) {
|
|
58
|
+
injectProperty("storage", ({ tag, key, instance }) => {
|
|
59
|
+
if (!tag)
|
|
60
|
+
return;
|
|
61
|
+
const initstr = localStorage.getItem(tag);
|
|
62
|
+
if (initstr) {
|
|
63
|
+
const data = JSON.parse(initstr);
|
|
64
|
+
if (key) {
|
|
65
|
+
instance[key] = data;
|
|
66
|
+
} else {
|
|
67
|
+
for (const i in data) {
|
|
68
|
+
if (i)
|
|
69
|
+
instance[i] = data[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
globalThis.addEventListener("beforeunload", () => {
|
|
74
|
+
localStorage.setItem(tag, JSON.stringify(key ? instance[key] : instance));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
55
78
|
const originUnmount = app.unmount.bind(app);
|
|
56
79
|
app.unmount = () => {
|
|
57
80
|
eventRecord.forEach(([eventName, handler]) => emitter.off(eventName, handler));
|
|
@@ -255,23 +278,14 @@ function useEvent(eventName, cb) {
|
|
|
255
278
|
return () => emitter.off(eventName, cb);
|
|
256
279
|
}
|
|
257
280
|
__name(useEvent, "useEvent");
|
|
258
|
-
function
|
|
281
|
+
function initialize(Model) {
|
|
259
282
|
const instance = useO(Model);
|
|
260
283
|
if (instance) {
|
|
261
284
|
Object.assign(instance, new Model());
|
|
262
285
|
return instance;
|
|
263
286
|
}
|
|
264
287
|
}
|
|
265
|
-
__name(
|
|
266
|
-
function clearStorage(Model, isForceUpdate = true) {
|
|
267
|
-
localStorage.removeItem(`_phecda_${useO(Model)._symbol}`);
|
|
268
|
-
isForceUpdate && initalize(Model);
|
|
269
|
-
}
|
|
270
|
-
__name(clearStorage, "clearStorage");
|
|
271
|
-
function deleteStorage(tag) {
|
|
272
|
-
localStorage.removeItem(`_phecda_${tag}`);
|
|
273
|
-
}
|
|
274
|
-
__name(deleteStorage, "deleteStorage");
|
|
288
|
+
__name(initialize, "initialize");
|
|
275
289
|
|
|
276
290
|
// src/filter.ts
|
|
277
291
|
import { effectScope as effectScope2, reactive as reactive2, ref } from "vue";
|
|
@@ -380,8 +394,10 @@ function createForm(compSet, form, formItem, options = {}) {
|
|
|
380
394
|
...props.config[property],
|
|
381
395
|
[`${modelKey}`]: props.data[property],
|
|
382
396
|
[`onUpdate:${modelKey}`]: (v) => {
|
|
383
|
-
onUpdate
|
|
384
|
-
|
|
397
|
+
if (onUpdate)
|
|
398
|
+
onUpdate(property, v);
|
|
399
|
+
else
|
|
400
|
+
props.data[property] = v;
|
|
385
401
|
}
|
|
386
402
|
}, {
|
|
387
403
|
default: () => generateChildVNode(props.config[props.property])
|
|
@@ -720,7 +736,6 @@ export {
|
|
|
720
736
|
FN_RE,
|
|
721
737
|
GetDevUIRules,
|
|
722
738
|
PV,
|
|
723
|
-
clearStorage,
|
|
724
739
|
createFilter,
|
|
725
740
|
createForm,
|
|
726
741
|
createFormData,
|
|
@@ -728,7 +743,6 @@ export {
|
|
|
728
743
|
createPhecda,
|
|
729
744
|
createPipe,
|
|
730
745
|
createTable,
|
|
731
|
-
deleteStorage,
|
|
732
746
|
emitter,
|
|
733
747
|
getActivePhecda,
|
|
734
748
|
getAntDRules,
|
|
@@ -737,7 +751,7 @@ export {
|
|
|
737
751
|
getNutUIRules,
|
|
738
752
|
getReactiveMap,
|
|
739
753
|
getVantRules,
|
|
740
|
-
|
|
754
|
+
initialize,
|
|
741
755
|
phecdaSymbol,
|
|
742
756
|
setActivePhecda,
|
|
743
757
|
useEvent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "provide store/form/table with phecda function to vue",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"mitt": "^3.0.0",
|
|
16
16
|
"vue": "^3.2.45",
|
|
17
|
-
"phecda-core": "1.
|
|
17
|
+
"phecda-core": "1.2.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"tsup": "^6.5.0"
|