phecda-vue 2.1.1 → 2.1.3-alpha.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 +10 -17
- package/dist/index.js +22 -98
- package/dist/index.mjs +22 -96
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Events } from 'phecda-core';
|
|
2
2
|
export * from 'phecda-core';
|
|
3
3
|
import * as vue from 'vue';
|
|
4
|
-
import { Ref, App, UnwrapNestedRefs
|
|
4
|
+
import { Ref, App, UnwrapNestedRefs } from 'vue';
|
|
5
5
|
import { Handler } from 'mitt';
|
|
6
6
|
|
|
7
7
|
type ReplaceInstanceValues<I> = {
|
|
@@ -10,6 +10,13 @@ type ReplaceInstanceValues<I> = {
|
|
|
10
10
|
type SchemaToObj<S> = {
|
|
11
11
|
[P in keyof S]: S[P] extends object ? SchemaToObj<S[P]> : (S[P] extends string ? any : S[P]);
|
|
12
12
|
};
|
|
13
|
+
interface PhecdaInstance {
|
|
14
|
+
useOMap: Map<any, any>;
|
|
15
|
+
useVMap: WeakMap<any, any>;
|
|
16
|
+
useRMap: WeakMap<any, any>;
|
|
17
|
+
fnMap: WeakMap<any, any>;
|
|
18
|
+
computedMap: WeakMap<any, any>;
|
|
19
|
+
}
|
|
13
20
|
interface PhecdaEmitter {
|
|
14
21
|
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
15
22
|
off<N extends keyof Events>(eventName: N, cb?: (args: Events[N]) => void): void;
|
|
@@ -23,13 +30,6 @@ declare const interval: any;
|
|
|
23
30
|
declare function createPhecda(symbol?: string): vue.Raw<{
|
|
24
31
|
install(app: App): void;
|
|
25
32
|
}>;
|
|
26
|
-
interface PhecdaInstance {
|
|
27
|
-
useVMap: WeakMap<any, any>;
|
|
28
|
-
useOMap: Map<any, any>;
|
|
29
|
-
useRMap: WeakMap<any, any>;
|
|
30
|
-
fnMap: WeakMap<any, any>;
|
|
31
|
-
computedMap: WeakMap<any, any>;
|
|
32
|
-
}
|
|
33
33
|
declare function setActivePhecda(phecda: PhecdaInstance): void;
|
|
34
34
|
declare function getActivePhecda(): PhecdaInstance;
|
|
35
35
|
declare function getReactiveMap(symbol: string): Map<string, any> | null;
|
|
@@ -44,7 +44,7 @@ declare function usePatch<T extends new (...args: any) => any>(Model: T, Data: _
|
|
|
44
44
|
declare function useR<T extends new (...args: any) => any>(Model: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
45
45
|
declare function useV<T extends new (...args: any) => any>(Model: T): ReplaceInstanceValues<InstanceType<T>>;
|
|
46
46
|
declare function useEvent<Key extends keyof Events>(eventName: Key, cb: Handler<Events[Key]>): () => void;
|
|
47
|
-
declare function initialize<M extends new (...args: any) => any>(Model: M): InstanceType<M> | void;
|
|
47
|
+
declare function initialize<M extends new (...args: any) => any>(Model: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
|
|
48
48
|
|
|
49
49
|
declare const RE: RegExp;
|
|
50
50
|
declare function createFilter<Data extends Record<string, any>>(initState?: Object, option?: {
|
|
@@ -67,13 +67,6 @@ declare function createFilter<Data extends Record<string, any>>(initState?: Obje
|
|
|
67
67
|
delState: (key: string) => void;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
declare const createLayer: <T>(wrapComp: Component<T>, props?: Partial<T>, modelKey?: string) => <P>(comp: Component<P>, props?: P, modalProps?: Partial<T>) => void;
|
|
71
|
-
|
|
72
|
-
declare const createDialog: <T>(comp: Component<T>, opts?: {
|
|
73
|
-
modelKey?: string;
|
|
74
|
-
props?: Partial<T>;
|
|
75
|
-
}) => (props?: Partial<T>) => void;
|
|
76
|
-
|
|
77
70
|
declare class PV {
|
|
78
71
|
constructor();
|
|
79
72
|
get tag(): any;
|
|
@@ -82,4 +75,4 @@ declare class PV {
|
|
|
82
75
|
off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
|
|
83
76
|
}
|
|
84
77
|
|
|
85
|
-
export { PV, PhecdaEmitter, RE, ReplaceInstanceValues, SchemaToObj,
|
|
78
|
+
export { PV, PhecdaEmitter, PhecdaInstance, RE, ReplaceInstanceValues, SchemaToObj, createFilter, createPhecda, emitter, getActivePhecda, getReactiveMap, initialize, interval, phecdaSymbol, setActivePhecda, useEvent, useO, usePatch, useR, useRaw, useV };
|
package/dist/index.js
CHANGED
|
@@ -30,9 +30,7 @@ var src_exports = {};
|
|
|
30
30
|
__export(src_exports, {
|
|
31
31
|
PV: () => PV,
|
|
32
32
|
RE: () => RE,
|
|
33
|
-
createDialog: () => createDialog,
|
|
34
33
|
createFilter: () => createFilter,
|
|
35
|
-
createLayer: () => createLayer,
|
|
36
34
|
createPhecda: () => createPhecda,
|
|
37
35
|
emitter: () => emitter,
|
|
38
36
|
getActivePhecda: () => getActivePhecda,
|
|
@@ -248,18 +246,15 @@ function useRaw(Model) {
|
|
|
248
246
|
}
|
|
249
247
|
__name(useRaw, "useRaw");
|
|
250
248
|
function usePatch(Model, Data) {
|
|
251
|
-
useO(Model);
|
|
252
|
-
|
|
253
|
-
const target = useOMap.get(Model);
|
|
254
|
-
mergeReactiveObjects(target, Data);
|
|
249
|
+
const instance = useO(Model);
|
|
250
|
+
mergeReactiveObjects(instance, Data);
|
|
255
251
|
}
|
|
256
252
|
__name(usePatch, "usePatch");
|
|
257
253
|
function useR(Model) {
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
if (useRMap.has(
|
|
261
|
-
return useRMap.get(
|
|
262
|
-
const instance = useOMap.get(Model);
|
|
254
|
+
const { useRMap, fnMap } = getActivePhecda();
|
|
255
|
+
const instance = useO(Model);
|
|
256
|
+
if (useRMap.has(instance))
|
|
257
|
+
return useRMap.get(instance);
|
|
263
258
|
const proxy = new Proxy(instance, {
|
|
264
259
|
get(target, key) {
|
|
265
260
|
if (typeof target[key] === "function") {
|
|
@@ -279,17 +274,16 @@ function useR(Model) {
|
|
|
279
274
|
return true;
|
|
280
275
|
}
|
|
281
276
|
});
|
|
282
|
-
useRMap.set(
|
|
277
|
+
useRMap.set(instance, proxy);
|
|
283
278
|
return proxy;
|
|
284
279
|
}
|
|
285
280
|
__name(useR, "useR");
|
|
286
281
|
function useV(Model) {
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
if (useVMap.has(
|
|
290
|
-
return useVMap.get(
|
|
291
|
-
computedMap.set(
|
|
292
|
-
const instance = useOMap.get(Model);
|
|
282
|
+
const { useVMap, fnMap, computedMap } = getActivePhecda();
|
|
283
|
+
const instance = useO(Model);
|
|
284
|
+
if (useVMap.has(instance))
|
|
285
|
+
return useVMap.get(instance);
|
|
286
|
+
computedMap.set(instance, {});
|
|
293
287
|
const proxy = new Proxy(instance, {
|
|
294
288
|
get(target, key) {
|
|
295
289
|
if (typeof target[key] === "function") {
|
|
@@ -302,7 +296,7 @@ function useV(Model) {
|
|
|
302
296
|
fnMap.set(target[key], wrapper);
|
|
303
297
|
return wrapper;
|
|
304
298
|
}
|
|
305
|
-
const cache = computedMap.get(
|
|
299
|
+
const cache = computedMap.get(instance);
|
|
306
300
|
if (key in cache)
|
|
307
301
|
return cache[key]();
|
|
308
302
|
cache[key] = createSharedReactive(() => {
|
|
@@ -314,7 +308,7 @@ function useV(Model) {
|
|
|
314
308
|
return false;
|
|
315
309
|
}
|
|
316
310
|
});
|
|
317
|
-
useVMap.set(
|
|
311
|
+
useVMap.set(instance, proxy);
|
|
318
312
|
return proxy;
|
|
319
313
|
}
|
|
320
314
|
__name(useV, "useV");
|
|
@@ -326,11 +320,15 @@ function useEvent(eventName, cb) {
|
|
|
326
320
|
return () => emitter.off(eventName, cb);
|
|
327
321
|
}
|
|
328
322
|
__name(useEvent, "useEvent");
|
|
329
|
-
function initialize(Model) {
|
|
323
|
+
function initialize(Model, deleteOtherProperty = true) {
|
|
330
324
|
const instance = useO(Model);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
325
|
+
const newInstance = new Model();
|
|
326
|
+
Object.assign(instance, newInstance);
|
|
327
|
+
if (deleteOtherProperty) {
|
|
328
|
+
for (const key in instance) {
|
|
329
|
+
if (!(key in newInstance))
|
|
330
|
+
delete instance[key];
|
|
331
|
+
}
|
|
334
332
|
}
|
|
335
333
|
}
|
|
336
334
|
__name(initialize, "initialize");
|
|
@@ -433,78 +431,6 @@ __name(createFilter, "createFilter");
|
|
|
433
431
|
// src/index.ts
|
|
434
432
|
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
435
433
|
|
|
436
|
-
// src/components/createLayer.ts
|
|
437
|
-
var import_vue5 = require("vue");
|
|
438
|
-
var createLayer = /* @__PURE__ */ __name(function(modalWrapper, content_props = {}, modelKey = "modelValue") {
|
|
439
|
-
let isMounted = false;
|
|
440
|
-
const isShow = (0, import_vue5.shallowRef)(true);
|
|
441
|
-
const content = (0, import_vue5.shallowRef)();
|
|
442
|
-
const contentProps = (0, import_vue5.shallowRef)({});
|
|
443
|
-
const modalProps = (0, import_vue5.shallowRef)({});
|
|
444
|
-
const wrapper = (0, import_vue5.defineComponent)({
|
|
445
|
-
setup() {
|
|
446
|
-
return () => (0, import_vue5.h)(modalWrapper, {
|
|
447
|
-
[modelKey]: isShow.value,
|
|
448
|
-
[`onUpdate:${modelKey}`]: (v) => {
|
|
449
|
-
isShow.value = v;
|
|
450
|
-
},
|
|
451
|
-
...modalProps.value
|
|
452
|
-
}, {
|
|
453
|
-
default: (slot = {}) => content.value && (0, import_vue5.h)(content.value, {
|
|
454
|
-
...contentProps.value,
|
|
455
|
-
...slot
|
|
456
|
-
})
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
return (comp, props, modal_props) => {
|
|
461
|
-
content.value = comp;
|
|
462
|
-
contentProps.value = props;
|
|
463
|
-
modalProps.value = Object.assign({}, content_props, modal_props);
|
|
464
|
-
if (!isMounted) {
|
|
465
|
-
const el = document.createElement("div");
|
|
466
|
-
const vnode = (0, import_vue5.h)(wrapper);
|
|
467
|
-
vnode.appContext = interval.app?._context;
|
|
468
|
-
document.body.appendChild(((0, import_vue5.render)(vnode, el), el));
|
|
469
|
-
isMounted = true;
|
|
470
|
-
} else {
|
|
471
|
-
isShow.value = true;
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
}, "createLayer");
|
|
475
|
-
|
|
476
|
-
// src/components/createDialog.ts
|
|
477
|
-
var import_vue6 = require("vue");
|
|
478
|
-
var createDialog = /* @__PURE__ */ __name(function(comp, opts = {}) {
|
|
479
|
-
let isMounted = false;
|
|
480
|
-
const { modelKey = "modelValue", props = {} } = opts;
|
|
481
|
-
const isShow = (0, import_vue6.shallowRef)(true);
|
|
482
|
-
const contentProps = (0, import_vue6.shallowRef)({});
|
|
483
|
-
const wrapper = (0, import_vue6.defineComponent)({
|
|
484
|
-
setup() {
|
|
485
|
-
return () => (0, import_vue6.h)(comp, {
|
|
486
|
-
[modelKey]: isShow.value,
|
|
487
|
-
[`onUpdate:${modelKey}`]: (v) => {
|
|
488
|
-
isShow.value = v;
|
|
489
|
-
},
|
|
490
|
-
...contentProps.value
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
return (_props = {}) => {
|
|
495
|
-
contentProps.value = Object.assign({}, props, _props);
|
|
496
|
-
if (!isMounted) {
|
|
497
|
-
const el = document.createElement("div");
|
|
498
|
-
const vnode = (0, import_vue6.h)(wrapper);
|
|
499
|
-
vnode.appContext = interval.app?._context;
|
|
500
|
-
document.body.appendChild(((0, import_vue6.render)(vnode, el), el));
|
|
501
|
-
isMounted = true;
|
|
502
|
-
} else {
|
|
503
|
-
isShow.value = true;
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
}, "createDialog");
|
|
507
|
-
|
|
508
434
|
// src/wrapper.ts
|
|
509
435
|
var PV = class {
|
|
510
436
|
constructor() {
|
|
@@ -527,9 +453,7 @@ __name(PV, "PV");
|
|
|
527
453
|
0 && (module.exports = {
|
|
528
454
|
PV,
|
|
529
455
|
RE,
|
|
530
|
-
createDialog,
|
|
531
456
|
createFilter,
|
|
532
|
-
createLayer,
|
|
533
457
|
createPhecda,
|
|
534
458
|
emitter,
|
|
535
459
|
getActivePhecda,
|
package/dist/index.mjs
CHANGED
|
@@ -199,18 +199,15 @@ function useRaw(Model) {
|
|
|
199
199
|
}
|
|
200
200
|
__name(useRaw, "useRaw");
|
|
201
201
|
function usePatch(Model, Data) {
|
|
202
|
-
useO(Model);
|
|
203
|
-
|
|
204
|
-
const target = useOMap.get(Model);
|
|
205
|
-
mergeReactiveObjects(target, Data);
|
|
202
|
+
const instance = useO(Model);
|
|
203
|
+
mergeReactiveObjects(instance, Data);
|
|
206
204
|
}
|
|
207
205
|
__name(usePatch, "usePatch");
|
|
208
206
|
function useR(Model) {
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
if (useRMap.has(
|
|
212
|
-
return useRMap.get(
|
|
213
|
-
const instance = useOMap.get(Model);
|
|
207
|
+
const { useRMap, fnMap } = getActivePhecda();
|
|
208
|
+
const instance = useO(Model);
|
|
209
|
+
if (useRMap.has(instance))
|
|
210
|
+
return useRMap.get(instance);
|
|
214
211
|
const proxy = new Proxy(instance, {
|
|
215
212
|
get(target, key) {
|
|
216
213
|
if (typeof target[key] === "function") {
|
|
@@ -230,17 +227,16 @@ function useR(Model) {
|
|
|
230
227
|
return true;
|
|
231
228
|
}
|
|
232
229
|
});
|
|
233
|
-
useRMap.set(
|
|
230
|
+
useRMap.set(instance, proxy);
|
|
234
231
|
return proxy;
|
|
235
232
|
}
|
|
236
233
|
__name(useR, "useR");
|
|
237
234
|
function useV(Model) {
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
if (useVMap.has(
|
|
241
|
-
return useVMap.get(
|
|
242
|
-
computedMap.set(
|
|
243
|
-
const instance = useOMap.get(Model);
|
|
235
|
+
const { useVMap, fnMap, computedMap } = getActivePhecda();
|
|
236
|
+
const instance = useO(Model);
|
|
237
|
+
if (useVMap.has(instance))
|
|
238
|
+
return useVMap.get(instance);
|
|
239
|
+
computedMap.set(instance, {});
|
|
244
240
|
const proxy = new Proxy(instance, {
|
|
245
241
|
get(target, key) {
|
|
246
242
|
if (typeof target[key] === "function") {
|
|
@@ -253,7 +249,7 @@ function useV(Model) {
|
|
|
253
249
|
fnMap.set(target[key], wrapper);
|
|
254
250
|
return wrapper;
|
|
255
251
|
}
|
|
256
|
-
const cache = computedMap.get(
|
|
252
|
+
const cache = computedMap.get(instance);
|
|
257
253
|
if (key in cache)
|
|
258
254
|
return cache[key]();
|
|
259
255
|
cache[key] = createSharedReactive(() => {
|
|
@@ -265,7 +261,7 @@ function useV(Model) {
|
|
|
265
261
|
return false;
|
|
266
262
|
}
|
|
267
263
|
});
|
|
268
|
-
useVMap.set(
|
|
264
|
+
useVMap.set(instance, proxy);
|
|
269
265
|
return proxy;
|
|
270
266
|
}
|
|
271
267
|
__name(useV, "useV");
|
|
@@ -277,11 +273,15 @@ function useEvent(eventName, cb) {
|
|
|
277
273
|
return () => emitter.off(eventName, cb);
|
|
278
274
|
}
|
|
279
275
|
__name(useEvent, "useEvent");
|
|
280
|
-
function initialize(Model) {
|
|
276
|
+
function initialize(Model, deleteOtherProperty = true) {
|
|
281
277
|
const instance = useO(Model);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
278
|
+
const newInstance = new Model();
|
|
279
|
+
Object.assign(instance, newInstance);
|
|
280
|
+
if (deleteOtherProperty) {
|
|
281
|
+
for (const key in instance) {
|
|
282
|
+
if (!(key in newInstance))
|
|
283
|
+
delete instance[key];
|
|
284
|
+
}
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
__name(initialize, "initialize");
|
|
@@ -384,78 +384,6 @@ __name(createFilter, "createFilter");
|
|
|
384
384
|
// src/index.ts
|
|
385
385
|
export * from "phecda-core";
|
|
386
386
|
|
|
387
|
-
// src/components/createLayer.ts
|
|
388
|
-
import { defineComponent, h, render, shallowRef } from "vue";
|
|
389
|
-
var createLayer = /* @__PURE__ */ __name(function(modalWrapper, content_props = {}, modelKey = "modelValue") {
|
|
390
|
-
let isMounted = false;
|
|
391
|
-
const isShow = shallowRef(true);
|
|
392
|
-
const content = shallowRef();
|
|
393
|
-
const contentProps = shallowRef({});
|
|
394
|
-
const modalProps = shallowRef({});
|
|
395
|
-
const wrapper = defineComponent({
|
|
396
|
-
setup() {
|
|
397
|
-
return () => h(modalWrapper, {
|
|
398
|
-
[modelKey]: isShow.value,
|
|
399
|
-
[`onUpdate:${modelKey}`]: (v) => {
|
|
400
|
-
isShow.value = v;
|
|
401
|
-
},
|
|
402
|
-
...modalProps.value
|
|
403
|
-
}, {
|
|
404
|
-
default: (slot = {}) => content.value && h(content.value, {
|
|
405
|
-
...contentProps.value,
|
|
406
|
-
...slot
|
|
407
|
-
})
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
return (comp, props, modal_props) => {
|
|
412
|
-
content.value = comp;
|
|
413
|
-
contentProps.value = props;
|
|
414
|
-
modalProps.value = Object.assign({}, content_props, modal_props);
|
|
415
|
-
if (!isMounted) {
|
|
416
|
-
const el = document.createElement("div");
|
|
417
|
-
const vnode = h(wrapper);
|
|
418
|
-
vnode.appContext = interval.app?._context;
|
|
419
|
-
document.body.appendChild((render(vnode, el), el));
|
|
420
|
-
isMounted = true;
|
|
421
|
-
} else {
|
|
422
|
-
isShow.value = true;
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
}, "createLayer");
|
|
426
|
-
|
|
427
|
-
// src/components/createDialog.ts
|
|
428
|
-
import { defineComponent as defineComponent2, h as h2, render as render2, shallowRef as shallowRef2 } from "vue";
|
|
429
|
-
var createDialog = /* @__PURE__ */ __name(function(comp, opts = {}) {
|
|
430
|
-
let isMounted = false;
|
|
431
|
-
const { modelKey = "modelValue", props = {} } = opts;
|
|
432
|
-
const isShow = shallowRef2(true);
|
|
433
|
-
const contentProps = shallowRef2({});
|
|
434
|
-
const wrapper = defineComponent2({
|
|
435
|
-
setup() {
|
|
436
|
-
return () => h2(comp, {
|
|
437
|
-
[modelKey]: isShow.value,
|
|
438
|
-
[`onUpdate:${modelKey}`]: (v) => {
|
|
439
|
-
isShow.value = v;
|
|
440
|
-
},
|
|
441
|
-
...contentProps.value
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
return (_props = {}) => {
|
|
446
|
-
contentProps.value = Object.assign({}, props, _props);
|
|
447
|
-
if (!isMounted) {
|
|
448
|
-
const el = document.createElement("div");
|
|
449
|
-
const vnode = h2(wrapper);
|
|
450
|
-
vnode.appContext = interval.app?._context;
|
|
451
|
-
document.body.appendChild((render2(vnode, el), el));
|
|
452
|
-
isMounted = true;
|
|
453
|
-
} else {
|
|
454
|
-
isShow.value = true;
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
}, "createDialog");
|
|
458
|
-
|
|
459
387
|
// src/wrapper.ts
|
|
460
388
|
var PV = class {
|
|
461
389
|
constructor() {
|
|
@@ -477,9 +405,7 @@ __name(PV, "PV");
|
|
|
477
405
|
export {
|
|
478
406
|
PV,
|
|
479
407
|
RE,
|
|
480
|
-
createDialog,
|
|
481
408
|
createFilter,
|
|
482
|
-
createLayer,
|
|
483
409
|
createPhecda,
|
|
484
410
|
emitter,
|
|
485
411
|
getActivePhecda,
|