phecda-vue 1.0.1 → 1.0.3
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 +10 -6
- package/dist/index.js +76 -35
- package/dist/index.mjs +79 -38
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -26,14 +26,18 @@ declare function Watcher(eventName: string): (obj: any, key: string) => void;
|
|
|
26
26
|
declare const phecdaSymbol: unique symbol;
|
|
27
27
|
declare function createPhecda(): vue.Raw<{
|
|
28
28
|
install(app: App): void;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
useVMap: WeakMap<object, any>;
|
|
30
|
+
useOMap: WeakMap<object, any>;
|
|
31
|
+
useRMap: WeakMap<object, any>;
|
|
32
|
+
fnMap: WeakMap<object, any>;
|
|
33
|
+
computedMap: WeakMap<object, any>;
|
|
32
34
|
}>;
|
|
33
35
|
interface PhecdaInstance {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
useVMap: WeakMap<any, any>;
|
|
37
|
+
useOMap: WeakMap<any, any>;
|
|
38
|
+
useRMap: WeakMap<any, any>;
|
|
39
|
+
fnMap: WeakMap<any, any>;
|
|
40
|
+
computedMap: WeakMap<any, any>;
|
|
37
41
|
}
|
|
38
42
|
declare function setActivePhecda(phecda: PhecdaInstance): void;
|
|
39
43
|
declare function getActivePhecda(): PhecdaInstance;
|
package/dist/index.js
CHANGED
|
@@ -86,16 +86,20 @@ function createPhecda() {
|
|
|
86
86
|
app.provide(phecdaSymbol, phecda);
|
|
87
87
|
app.config.globalProperties.$phecda = phecda;
|
|
88
88
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
useVMap: /* @__PURE__ */ new WeakMap(),
|
|
90
|
+
useOMap: /* @__PURE__ */ new WeakMap(),
|
|
91
|
+
useRMap: /* @__PURE__ */ new WeakMap(),
|
|
92
|
+
fnMap: /* @__PURE__ */ new WeakMap(),
|
|
93
|
+
computedMap: /* @__PURE__ */ new WeakMap()
|
|
92
94
|
});
|
|
93
95
|
return phecda;
|
|
94
96
|
}
|
|
95
97
|
var activePhecda = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
useVMap: /* @__PURE__ */ new WeakMap(),
|
|
99
|
+
useOMap: /* @__PURE__ */ new WeakMap(),
|
|
100
|
+
useRMap: /* @__PURE__ */ new WeakMap(),
|
|
101
|
+
fnMap: /* @__PURE__ */ new WeakMap(),
|
|
102
|
+
computedMap: /* @__PURE__ */ new WeakMap()
|
|
99
103
|
};
|
|
100
104
|
function setActivePhecda(phecda) {
|
|
101
105
|
activePhecda = phecda;
|
|
@@ -145,6 +149,26 @@ function wrapError(target, key, errorHandler) {
|
|
|
145
149
|
function isAsyncFunc(fn) {
|
|
146
150
|
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
147
151
|
}
|
|
152
|
+
function createSharedReactive(composable) {
|
|
153
|
+
let subscribers = 0;
|
|
154
|
+
let state;
|
|
155
|
+
let scope;
|
|
156
|
+
const dispose = () => {
|
|
157
|
+
if (scope && --subscribers <= 0) {
|
|
158
|
+
scope.stop();
|
|
159
|
+
state = scope = null;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return () => {
|
|
163
|
+
subscribers++;
|
|
164
|
+
if (!state) {
|
|
165
|
+
scope = (0, import_vue2.effectScope)(true);
|
|
166
|
+
state = scope.run(() => composable());
|
|
167
|
+
}
|
|
168
|
+
(0, import_vue2.onScopeDispose)(dispose);
|
|
169
|
+
return state;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
148
172
|
|
|
149
173
|
// src/vue/composable.ts
|
|
150
174
|
function useO(Model) {
|
|
@@ -153,33 +177,37 @@ function useO(Model) {
|
|
|
153
177
|
if (cur)
|
|
154
178
|
setActivePhecda(cur);
|
|
155
179
|
}
|
|
156
|
-
const {
|
|
157
|
-
if (!
|
|
180
|
+
const { useOMap } = getActivePhecda();
|
|
181
|
+
if (!useOMap.has(Model)) {
|
|
158
182
|
const instance = (0, import_vue3.reactive)(new Model());
|
|
159
|
-
|
|
183
|
+
useOMap.set(Model, instance);
|
|
160
184
|
(0, import_phecda_core2.register)(instance);
|
|
161
185
|
}
|
|
162
|
-
return
|
|
186
|
+
return useOMap.get(Model);
|
|
163
187
|
}
|
|
164
188
|
function usePatch(Model, Data) {
|
|
165
189
|
useO(Model);
|
|
166
|
-
const {
|
|
167
|
-
const target =
|
|
190
|
+
const { useOMap } = getActivePhecda();
|
|
191
|
+
const target = useOMap.get(Model);
|
|
168
192
|
mergeReactiveObjects(target, Data);
|
|
169
193
|
}
|
|
170
194
|
function useR(Model) {
|
|
171
195
|
useO(Model);
|
|
172
|
-
const {
|
|
173
|
-
if (
|
|
174
|
-
return
|
|
175
|
-
const instance =
|
|
196
|
+
const { useRMap, useOMap, fnMap } = getActivePhecda();
|
|
197
|
+
if (useRMap.has(Model))
|
|
198
|
+
return useRMap.get(Model);
|
|
199
|
+
const instance = useOMap.get(Model);
|
|
176
200
|
const proxy = new Proxy(instance, {
|
|
177
201
|
get(target, key) {
|
|
178
202
|
if (typeof target[key] === "function") {
|
|
203
|
+
if (fnMap.has(target[key]))
|
|
204
|
+
return fnMap.get(target[key]);
|
|
179
205
|
const errorHandler = (0, import_phecda_core2.getHandler)(target, key).find((item) => item.error)?.error;
|
|
180
206
|
if (!errorHandler)
|
|
181
207
|
return target[key].bind(target);
|
|
182
|
-
|
|
208
|
+
const wrapper = wrapError(target, key, errorHandler);
|
|
209
|
+
fnMap.set(target[key], wrapper);
|
|
210
|
+
return wrapper;
|
|
183
211
|
}
|
|
184
212
|
return target[key];
|
|
185
213
|
},
|
|
@@ -188,41 +216,52 @@ function useR(Model) {
|
|
|
188
216
|
return true;
|
|
189
217
|
}
|
|
190
218
|
});
|
|
191
|
-
|
|
219
|
+
useRMap.set(Model, proxy);
|
|
192
220
|
return proxy;
|
|
193
221
|
}
|
|
194
222
|
function useV(Model) {
|
|
195
223
|
useO(Model);
|
|
196
|
-
const {
|
|
197
|
-
if (
|
|
198
|
-
return
|
|
199
|
-
|
|
224
|
+
const { useVMap, useOMap, fnMap, computedMap } = getActivePhecda();
|
|
225
|
+
if (useVMap.has(Model))
|
|
226
|
+
return useVMap.get(Model);
|
|
227
|
+
computedMap.set(Model, {});
|
|
228
|
+
const instance = useOMap.get(Model);
|
|
200
229
|
const proxy = new Proxy(instance, {
|
|
201
230
|
get(target, key) {
|
|
202
231
|
if (typeof target[key] === "function") {
|
|
232
|
+
if (fnMap.has(target[key]))
|
|
233
|
+
return fnMap.get(target[key]);
|
|
203
234
|
const errorHandler = (0, import_phecda_core2.getHandler)(target, key).find((item) => item.error)?.error;
|
|
204
235
|
if (!errorHandler)
|
|
205
236
|
return target[key].bind(target);
|
|
206
|
-
|
|
237
|
+
const wrapper = wrapError(target, key, errorHandler);
|
|
238
|
+
fnMap.set(target[key], wrapper);
|
|
239
|
+
return wrapper;
|
|
207
240
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
241
|
+
const cache = computedMap.get(Model);
|
|
242
|
+
if (key in cache)
|
|
243
|
+
return cache[key]();
|
|
244
|
+
cache[key] = createSharedReactive(() => {
|
|
245
|
+
return (0, import_vue3.computed)({
|
|
246
|
+
get() {
|
|
247
|
+
return target[key];
|
|
248
|
+
},
|
|
249
|
+
set(v) {
|
|
250
|
+
return target[key] = v;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
215
253
|
});
|
|
254
|
+
return cache[key]();
|
|
216
255
|
},
|
|
217
256
|
set() {
|
|
218
257
|
return false;
|
|
219
258
|
}
|
|
220
259
|
});
|
|
221
|
-
|
|
260
|
+
useVMap.set(Model, proxy);
|
|
222
261
|
return proxy;
|
|
223
262
|
}
|
|
224
263
|
function useOn(eventName, cb) {
|
|
225
|
-
(0, import_vue3.
|
|
264
|
+
(0, import_vue3.onScopeDispose)(() => {
|
|
226
265
|
emitter.off(eventName, cb);
|
|
227
266
|
});
|
|
228
267
|
emitter.on(eventName, cb);
|
|
@@ -256,7 +295,8 @@ function createFilter(initState = {}, option = {}) {
|
|
|
256
295
|
},
|
|
257
296
|
option
|
|
258
297
|
);
|
|
259
|
-
|
|
298
|
+
const scope = (0, import_vue4.effectScope)(true);
|
|
299
|
+
let data = scope.run(() => (0, import_vue4.ref)(initState));
|
|
260
300
|
let store = {};
|
|
261
301
|
function traverse(obj) {
|
|
262
302
|
for (const i in obj) {
|
|
@@ -314,6 +354,7 @@ function createFilter(initState = {}, option = {}) {
|
|
|
314
354
|
function dispose() {
|
|
315
355
|
data = null;
|
|
316
356
|
store = null;
|
|
357
|
+
scope.stop();
|
|
317
358
|
}
|
|
318
359
|
return { filter, data, init, setState, storeState, store, applyStore, dispose, clearStore };
|
|
319
360
|
}
|
|
@@ -346,7 +387,7 @@ var import_vue5 = require("vue");
|
|
|
346
387
|
function createForm(compSet, form, formItem, modelKey = "modelValue") {
|
|
347
388
|
function generateChildVNode(props) {
|
|
348
389
|
return props._children?.map(
|
|
349
|
-
(item) => (0, import_vue5.h)(compSet[item._component], item)
|
|
390
|
+
(item) => item._active === false ? null : (0, import_vue5.h)(compSet[item._component], item)
|
|
350
391
|
);
|
|
351
392
|
}
|
|
352
393
|
function generateVNode(props) {
|
|
@@ -417,7 +458,7 @@ function createForm(compSet, form, formItem, modelKey = "modelValue") {
|
|
|
417
458
|
return () => {
|
|
418
459
|
return (0, import_vue5.h)(form, Object.assign({ ref: dom }, ctx.attrs), {
|
|
419
460
|
default: () => Object.keys(props.config).map((item) => {
|
|
420
|
-
return (0, import_vue5.h)(FormItem, {
|
|
461
|
+
return props.config[item]._active === false ? null : (0, import_vue5.h)(FormItem, {
|
|
421
462
|
formItem: props.config[item]._formItem,
|
|
422
463
|
config: props.config,
|
|
423
464
|
property: item,
|
package/dist/index.mjs
CHANGED
|
@@ -25,16 +25,20 @@ function createPhecda() {
|
|
|
25
25
|
app.provide(phecdaSymbol, phecda);
|
|
26
26
|
app.config.globalProperties.$phecda = phecda;
|
|
27
27
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
useVMap: /* @__PURE__ */ new WeakMap(),
|
|
29
|
+
useOMap: /* @__PURE__ */ new WeakMap(),
|
|
30
|
+
useRMap: /* @__PURE__ */ new WeakMap(),
|
|
31
|
+
fnMap: /* @__PURE__ */ new WeakMap(),
|
|
32
|
+
computedMap: /* @__PURE__ */ new WeakMap()
|
|
31
33
|
});
|
|
32
34
|
return phecda;
|
|
33
35
|
}
|
|
34
36
|
var activePhecda = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
useVMap: /* @__PURE__ */ new WeakMap(),
|
|
38
|
+
useOMap: /* @__PURE__ */ new WeakMap(),
|
|
39
|
+
useRMap: /* @__PURE__ */ new WeakMap(),
|
|
40
|
+
fnMap: /* @__PURE__ */ new WeakMap(),
|
|
41
|
+
computedMap: /* @__PURE__ */ new WeakMap()
|
|
38
42
|
};
|
|
39
43
|
function setActivePhecda(phecda) {
|
|
40
44
|
activePhecda = phecda;
|
|
@@ -44,11 +48,11 @@ function getActivePhecda() {
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
// src/vue/composable.ts
|
|
47
|
-
import { computed, getCurrentInstance, inject,
|
|
51
|
+
import { computed, getCurrentInstance, inject, onScopeDispose as onScopeDispose2, reactive } from "vue";
|
|
48
52
|
import { getHandler, register } from "phecda-core";
|
|
49
53
|
|
|
50
54
|
// src/vue/utils.ts
|
|
51
|
-
import { isReactive, isRef } from "vue";
|
|
55
|
+
import { effectScope, isReactive, isRef, onScopeDispose } from "vue";
|
|
52
56
|
function isObject(o) {
|
|
53
57
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
54
58
|
}
|
|
@@ -84,6 +88,26 @@ function wrapError(target, key, errorHandler) {
|
|
|
84
88
|
function isAsyncFunc(fn) {
|
|
85
89
|
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
86
90
|
}
|
|
91
|
+
function createSharedReactive(composable) {
|
|
92
|
+
let subscribers = 0;
|
|
93
|
+
let state;
|
|
94
|
+
let scope;
|
|
95
|
+
const dispose = () => {
|
|
96
|
+
if (scope && --subscribers <= 0) {
|
|
97
|
+
scope.stop();
|
|
98
|
+
state = scope = null;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return () => {
|
|
102
|
+
subscribers++;
|
|
103
|
+
if (!state) {
|
|
104
|
+
scope = effectScope(true);
|
|
105
|
+
state = scope.run(() => composable());
|
|
106
|
+
}
|
|
107
|
+
onScopeDispose(dispose);
|
|
108
|
+
return state;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
87
111
|
|
|
88
112
|
// src/vue/composable.ts
|
|
89
113
|
function useO(Model) {
|
|
@@ -92,33 +116,37 @@ function useO(Model) {
|
|
|
92
116
|
if (cur)
|
|
93
117
|
setActivePhecda(cur);
|
|
94
118
|
}
|
|
95
|
-
const {
|
|
96
|
-
if (!
|
|
119
|
+
const { useOMap } = getActivePhecda();
|
|
120
|
+
if (!useOMap.has(Model)) {
|
|
97
121
|
const instance = reactive(new Model());
|
|
98
|
-
|
|
122
|
+
useOMap.set(Model, instance);
|
|
99
123
|
register(instance);
|
|
100
124
|
}
|
|
101
|
-
return
|
|
125
|
+
return useOMap.get(Model);
|
|
102
126
|
}
|
|
103
127
|
function usePatch(Model, Data) {
|
|
104
128
|
useO(Model);
|
|
105
|
-
const {
|
|
106
|
-
const target =
|
|
129
|
+
const { useOMap } = getActivePhecda();
|
|
130
|
+
const target = useOMap.get(Model);
|
|
107
131
|
mergeReactiveObjects(target, Data);
|
|
108
132
|
}
|
|
109
133
|
function useR(Model) {
|
|
110
134
|
useO(Model);
|
|
111
|
-
const {
|
|
112
|
-
if (
|
|
113
|
-
return
|
|
114
|
-
const instance =
|
|
135
|
+
const { useRMap, useOMap, fnMap } = getActivePhecda();
|
|
136
|
+
if (useRMap.has(Model))
|
|
137
|
+
return useRMap.get(Model);
|
|
138
|
+
const instance = useOMap.get(Model);
|
|
115
139
|
const proxy = new Proxy(instance, {
|
|
116
140
|
get(target, key) {
|
|
117
141
|
if (typeof target[key] === "function") {
|
|
142
|
+
if (fnMap.has(target[key]))
|
|
143
|
+
return fnMap.get(target[key]);
|
|
118
144
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
119
145
|
if (!errorHandler)
|
|
120
146
|
return target[key].bind(target);
|
|
121
|
-
|
|
147
|
+
const wrapper = wrapError(target, key, errorHandler);
|
|
148
|
+
fnMap.set(target[key], wrapper);
|
|
149
|
+
return wrapper;
|
|
122
150
|
}
|
|
123
151
|
return target[key];
|
|
124
152
|
},
|
|
@@ -127,41 +155,52 @@ function useR(Model) {
|
|
|
127
155
|
return true;
|
|
128
156
|
}
|
|
129
157
|
});
|
|
130
|
-
|
|
158
|
+
useRMap.set(Model, proxy);
|
|
131
159
|
return proxy;
|
|
132
160
|
}
|
|
133
161
|
function useV(Model) {
|
|
134
162
|
useO(Model);
|
|
135
|
-
const {
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
|
|
163
|
+
const { useVMap, useOMap, fnMap, computedMap } = getActivePhecda();
|
|
164
|
+
if (useVMap.has(Model))
|
|
165
|
+
return useVMap.get(Model);
|
|
166
|
+
computedMap.set(Model, {});
|
|
167
|
+
const instance = useOMap.get(Model);
|
|
139
168
|
const proxy = new Proxy(instance, {
|
|
140
169
|
get(target, key) {
|
|
141
170
|
if (typeof target[key] === "function") {
|
|
171
|
+
if (fnMap.has(target[key]))
|
|
172
|
+
return fnMap.get(target[key]);
|
|
142
173
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
143
174
|
if (!errorHandler)
|
|
144
175
|
return target[key].bind(target);
|
|
145
|
-
|
|
176
|
+
const wrapper = wrapError(target, key, errorHandler);
|
|
177
|
+
fnMap.set(target[key], wrapper);
|
|
178
|
+
return wrapper;
|
|
146
179
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
180
|
+
const cache = computedMap.get(Model);
|
|
181
|
+
if (key in cache)
|
|
182
|
+
return cache[key]();
|
|
183
|
+
cache[key] = createSharedReactive(() => {
|
|
184
|
+
return computed({
|
|
185
|
+
get() {
|
|
186
|
+
return target[key];
|
|
187
|
+
},
|
|
188
|
+
set(v) {
|
|
189
|
+
return target[key] = v;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
154
192
|
});
|
|
193
|
+
return cache[key]();
|
|
155
194
|
},
|
|
156
195
|
set() {
|
|
157
196
|
return false;
|
|
158
197
|
}
|
|
159
198
|
});
|
|
160
|
-
|
|
199
|
+
useVMap.set(Model, proxy);
|
|
161
200
|
return proxy;
|
|
162
201
|
}
|
|
163
202
|
function useOn(eventName, cb) {
|
|
164
|
-
|
|
203
|
+
onScopeDispose2(() => {
|
|
165
204
|
emitter.off(eventName, cb);
|
|
166
205
|
});
|
|
167
206
|
emitter.on(eventName, cb);
|
|
@@ -183,7 +222,7 @@ function deleteStorage(tag) {
|
|
|
183
222
|
}
|
|
184
223
|
|
|
185
224
|
// src/filter.ts
|
|
186
|
-
import { reactive as reactive2, ref } from "vue";
|
|
225
|
+
import { effectScope as effectScope2, reactive as reactive2, ref } from "vue";
|
|
187
226
|
var EXPRESS_RE = /^{{(.*)}}$/;
|
|
188
227
|
var FN_RE = /^\[\[(.*)\]\]$/;
|
|
189
228
|
function createFilter(initState = {}, option = {}) {
|
|
@@ -195,7 +234,8 @@ function createFilter(initState = {}, option = {}) {
|
|
|
195
234
|
},
|
|
196
235
|
option
|
|
197
236
|
);
|
|
198
|
-
|
|
237
|
+
const scope = effectScope2(true);
|
|
238
|
+
let data = scope.run(() => ref(initState));
|
|
199
239
|
let store = {};
|
|
200
240
|
function traverse(obj) {
|
|
201
241
|
for (const i in obj) {
|
|
@@ -253,6 +293,7 @@ function createFilter(initState = {}, option = {}) {
|
|
|
253
293
|
function dispose() {
|
|
254
294
|
data = null;
|
|
255
295
|
store = null;
|
|
296
|
+
scope.stop();
|
|
256
297
|
}
|
|
257
298
|
return { filter, data, init, setState, storeState, store, applyStore, dispose, clearStore };
|
|
258
299
|
}
|
|
@@ -285,7 +326,7 @@ import { defineComponent, h, onMounted, ref as ref2 } from "vue";
|
|
|
285
326
|
function createForm(compSet, form, formItem, modelKey = "modelValue") {
|
|
286
327
|
function generateChildVNode(props) {
|
|
287
328
|
return props._children?.map(
|
|
288
|
-
(item) => h(compSet[item._component], item)
|
|
329
|
+
(item) => item._active === false ? null : h(compSet[item._component], item)
|
|
289
330
|
);
|
|
290
331
|
}
|
|
291
332
|
function generateVNode(props) {
|
|
@@ -356,7 +397,7 @@ function createForm(compSet, form, formItem, modelKey = "modelValue") {
|
|
|
356
397
|
return () => {
|
|
357
398
|
return h(form, Object.assign({ ref: dom }, ctx.attrs), {
|
|
358
399
|
default: () => Object.keys(props.config).map((item) => {
|
|
359
|
-
return h(FormItem, {
|
|
400
|
+
return props.config[item]._active === false ? null : h(FormItem, {
|
|
360
401
|
formItem: props.config[item]._formItem,
|
|
361
402
|
config: props.config,
|
|
362
403
|
property: item,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-vue",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
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.0.
|
|
17
|
+
"phecda-core": "1.0.2"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"tsup": "^6.5.0"
|