phecda-vue 1.2.10 → 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 +2 -4
- package/dist/index.js +47 -37
- package/dist/index.mjs +47 -35
- 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;
|
|
@@ -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");
|
|
@@ -782,7 +794,6 @@ __name(PV, "PV");
|
|
|
782
794
|
FN_RE,
|
|
783
795
|
GetDevUIRules,
|
|
784
796
|
PV,
|
|
785
|
-
clearStorage,
|
|
786
797
|
createFilter,
|
|
787
798
|
createForm,
|
|
788
799
|
createFormData,
|
|
@@ -790,7 +801,6 @@ __name(PV, "PV");
|
|
|
790
801
|
createPhecda,
|
|
791
802
|
createPipe,
|
|
792
803
|
createTable,
|
|
793
|
-
deleteStorage,
|
|
794
804
|
emitter,
|
|
795
805
|
getActivePhecda,
|
|
796
806
|
getAntDRules,
|
|
@@ -799,7 +809,7 @@ __name(PV, "PV");
|
|
|
799
809
|
getNutUIRules,
|
|
800
810
|
getReactiveMap,
|
|
801
811
|
getVantRules,
|
|
802
|
-
|
|
812
|
+
initialize,
|
|
803
813
|
phecdaSymbol,
|
|
804
814
|
setActivePhecda,
|
|
805
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";
|
|
@@ -722,7 +736,6 @@ export {
|
|
|
722
736
|
FN_RE,
|
|
723
737
|
GetDevUIRules,
|
|
724
738
|
PV,
|
|
725
|
-
clearStorage,
|
|
726
739
|
createFilter,
|
|
727
740
|
createForm,
|
|
728
741
|
createFormData,
|
|
@@ -730,7 +743,6 @@ export {
|
|
|
730
743
|
createPhecda,
|
|
731
744
|
createPipe,
|
|
732
745
|
createTable,
|
|
733
|
-
deleteStorage,
|
|
734
746
|
emitter,
|
|
735
747
|
getActivePhecda,
|
|
736
748
|
getAntDRules,
|
|
@@ -739,7 +751,7 @@ export {
|
|
|
739
751
|
getNutUIRules,
|
|
740
752
|
getReactiveMap,
|
|
741
753
|
getVantRules,
|
|
742
|
-
|
|
754
|
+
initialize,
|
|
743
755
|
phecdaSymbol,
|
|
744
756
|
setActivePhecda,
|
|
745
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"
|