phecda-vue 1.0.3 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as mitt from 'mitt';
2
2
  import { EventType, Handler, Emitter } from 'mitt';
3
3
  import * as vue from 'vue';
4
- import { Ref, App, UnwrapNestedRefs, Component, DefineComponent, ExtractPropTypes } from 'vue';
4
+ import { Ref, App, UnwrapNestedRefs, Component, DefineComponent, ExtractPropTypes, VNode } from 'vue';
5
5
  import { Phecda } from 'phecda-core';
6
6
  export * from 'phecda-core';
7
7
 
@@ -16,15 +16,13 @@ interface PhecdaEvents extends Record<EventType, unknown> {
16
16
  }
17
17
 
18
18
  declare const emitter: mitt.Emitter<PhecdaEvents>;
19
- declare const emit: {
19
+ declare const invokeAction: {
20
20
  <Key extends keyof PhecdaEvents>(type: Key, event: PhecdaEvents[Key]): void;
21
21
  <Key_1 extends keyof PhecdaEvents>(type: undefined extends PhecdaEvents[Key_1] ? Key_1 : never): void;
22
22
  };
23
23
 
24
- declare function Watcher(eventName: string): (obj: any, key: string) => void;
25
-
26
24
  declare const phecdaSymbol: unique symbol;
27
- declare function createPhecda(): vue.Raw<{
25
+ declare function createPhecda(symbol?: string): vue.Raw<{
28
26
  install(app: App): void;
29
27
  useVMap: WeakMap<object, any>;
30
28
  useOMap: WeakMap<object, any>;
@@ -41,6 +39,7 @@ interface PhecdaInstance {
41
39
  }
42
40
  declare function setActivePhecda(phecda: PhecdaInstance): void;
43
41
  declare function getActivePhecda(): PhecdaInstance;
42
+ declare function getReactiveMap(symbol: string): Map<string, any> | null;
44
43
 
45
44
  type _DeepPartial<T> = {
46
45
  [K in keyof T]?: _DeepPartial<T[K]>;
@@ -50,7 +49,7 @@ declare function useO<T extends new (...args: any) => any>(Model: T): UnwrapNest
50
49
  declare function usePatch<T extends new (...args: any) => any>(Model: T, Data: _DeepPartial<InstanceType<T>>): void;
51
50
  declare function useR<T extends new (...args: any) => any>(Model: T): UnwrapNestedRefs<InstanceType<T>>;
52
51
  declare function useV<T extends new (...args: any) => any>(Model: T): Vret<InstanceType<T>>;
53
- declare function useOn<Key extends keyof PhecdaEvents>(eventName: Key, cb: Handler<PhecdaEvents[Key]>): () => void;
52
+ declare function useEvent<Key extends keyof PhecdaEvents>(eventName: Key, cb: Handler<PhecdaEvents[Key]>): () => void;
54
53
  declare function initalize<M extends new (...args: any) => any>(Model: M): InstanceType<M> | void;
55
54
  declare function clearStorage<M extends new (...args: any) => any>(Model: M, isForceUpdate?: boolean): void;
56
55
  declare function deleteStorage(tag: string): void;
@@ -108,7 +107,7 @@ declare const getAntDRules: typeof getNaiveUIRules;
108
107
  declare function getNutUIRules<M, O extends object>(Model: M, options?: O): any;
109
108
  declare const getVantRules: typeof getNutUIRules;
110
109
 
111
- declare const createModal: <P>(w: Component, k: string) => (comp: DefineComponent<P, any, any>, props?: ExtractPropTypes<P>) => void;
110
+ declare const createModal: <P>(w: Component) => (comp: DefineComponent<P, any, any>, props?: ExtractPropTypes<P>) => void;
112
111
 
113
112
  declare function createTable<P extends {
114
113
  $props: any;
@@ -116,4 +115,18 @@ declare function createTable<P extends {
116
115
  config: Object;
117
116
  } & P['$props']>;
118
117
 
119
- export { EXPRESS_RE, FN_RE, GetDevUIRules, P, PhecdaEvents, SchemaToObj, Vret, Watcher, clearStorage, createFilter, createForm, createFormData, createModal, createPhecda, createTable, deleteStorage, emit, emitter, getActivePhecda, getAntDRules, getElementPlusRules, getNaiveUIRules, getNutUIRules, getVantRules, initalize, phecdaSymbol, setActivePhecda, useO, useOn, usePatch, useR, useV };
118
+ declare function createPipe<Props extends {
119
+ $props: any;
120
+ }>(comp: Component<Props>, props: Props['$props'] & {
121
+ [key in string]: any;
122
+ }, to?: string, slot?: any): PipeRet;
123
+ interface PipeRet {
124
+ to: <Props extends {
125
+ $props: any;
126
+ }>(comp: Component<Props>, props: Props['$props'] & {
127
+ [key in string]: any;
128
+ }, to: string) => PipeRet;
129
+ get: Record<string, () => VNode>;
130
+ }
131
+
132
+ export { EXPRESS_RE, FN_RE, GetDevUIRules, P, PhecdaEvents, SchemaToObj, Vret, clearStorage, createFilter, createForm, createFormData, createModal, createPhecda, createPipe, createTable, deleteStorage, emitter, getActivePhecda, getAntDRules, getElementPlusRules, getNaiveUIRules, getNutUIRules, getReactiveMap, getVantRules, initalize, invokeAction, phecdaSymbol, setActivePhecda, useEvent, useO, usePatch, useR, useV };
package/dist/index.js CHANGED
@@ -31,28 +31,29 @@ __export(src_exports, {
31
31
  FN_RE: () => FN_RE,
32
32
  GetDevUIRules: () => GetDevUIRules,
33
33
  P: () => P,
34
- Watcher: () => Watcher,
35
34
  clearStorage: () => clearStorage,
36
35
  createFilter: () => createFilter,
37
36
  createForm: () => createForm,
38
37
  createFormData: () => createFormData,
39
38
  createModal: () => createModal,
40
39
  createPhecda: () => createPhecda,
40
+ createPipe: () => createPipe,
41
41
  createTable: () => createTable,
42
42
  deleteStorage: () => deleteStorage,
43
- emit: () => emit,
44
43
  emitter: () => emitter,
45
44
  getActivePhecda: () => getActivePhecda,
46
45
  getAntDRules: () => getAntDRules,
47
46
  getElementPlusRules: () => getElementPlusRules,
48
47
  getNaiveUIRules: () => getNaiveUIRules,
49
48
  getNutUIRules: () => getNutUIRules,
49
+ getReactiveMap: () => getReactiveMap,
50
50
  getVantRules: () => getVantRules,
51
51
  initalize: () => initalize,
52
+ invokeAction: () => invokeAction,
52
53
  phecdaSymbol: () => phecdaSymbol,
53
54
  setActivePhecda: () => setActivePhecda,
55
+ useEvent: () => useEvent,
54
56
  useO: () => useO,
55
- useOn: () => useOn,
56
57
  usePatch: () => usePatch,
57
58
  useR: () => useR,
58
59
  useV: () => useV
@@ -62,32 +63,48 @@ module.exports = __toCommonJS(src_exports);
62
63
  // src/emitter.ts
63
64
  var import_mitt = __toESM(require("mitt"));
64
65
  var emitter = (0, import_mitt.default)();
65
- var emit = emitter.emit.bind(emitter);
66
-
67
- // src/decorators.ts
68
- var import_phecda_core = require("phecda-core");
69
- function Watcher(eventName) {
70
- return (obj, key) => {
71
- (0, import_phecda_core.setModalState)(obj, key);
72
- (0, import_phecda_core.regisHandler)(obj, key, {
73
- init(instance) {
74
- emitter.on(eventName, instance[key].bind(instance));
75
- }
76
- });
77
- };
78
- }
66
+ var invokeAction = emitter.emit.bind(emitter);
79
67
 
80
68
  // src/vue/phecda.ts
81
69
  var import_vue = require("vue");
70
+ var import_phecda_core = require("phecda-core");
82
71
  var phecdaSymbol = Symbol("phecda");
83
- function createPhecda() {
72
+ function createPhecda(symbol) {
84
73
  const phecda = (0, import_vue.markRaw)({
85
74
  install(app) {
86
75
  app.provide(phecdaSymbol, phecda);
87
76
  app.config.globalProperties.$phecda = phecda;
77
+ if (!window._phecda)
78
+ window._phecda = {};
79
+ if (symbol) {
80
+ window._phecda[symbol] = {
81
+ instance: phecda,
82
+ snapshot: () => {
83
+ const ret = [];
84
+ for (const [key, value] of phecda.useOMap)
85
+ ret.push({ key: (0, import_phecda_core.getTag)(key) || key.name, value });
86
+ return ret;
87
+ }
88
+ };
89
+ }
90
+ const eventRecord = [];
91
+ (0, import_phecda_core.injectProperty)("watcher", ({ eventName, instance, key }) => {
92
+ const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
93
+ eventRecord.push([eventName, fn]);
94
+ emitter.on(eventName, fn);
95
+ });
96
+ const originUnmount = app.unmount.bind(app);
97
+ app.unmount = () => {
98
+ eventRecord.forEach(
99
+ ([eventName, handler]) => emitter.off(eventName, handler)
100
+ );
101
+ if (symbol)
102
+ delete window._phecda[symbol];
103
+ originUnmount();
104
+ };
88
105
  },
89
106
  useVMap: /* @__PURE__ */ new WeakMap(),
90
- useOMap: /* @__PURE__ */ new WeakMap(),
107
+ useOMap: new (symbol ? Map : WeakMap)(),
91
108
  useRMap: /* @__PURE__ */ new WeakMap(),
92
109
  fnMap: /* @__PURE__ */ new WeakMap(),
93
110
  computedMap: /* @__PURE__ */ new WeakMap()
@@ -107,6 +124,15 @@ function setActivePhecda(phecda) {
107
124
  function getActivePhecda() {
108
125
  return activePhecda;
109
126
  }
127
+ function getReactiveMap(symbol) {
128
+ if (!window._phecda?.[symbol])
129
+ return null;
130
+ const ret = /* @__PURE__ */ new Map();
131
+ window._phecda[symbol].snapshot.forEach(({ key, value }) => {
132
+ ret.set(key, value);
133
+ });
134
+ return ret;
135
+ }
110
136
 
111
137
  // src/vue/composable.ts
112
138
  var import_vue3 = require("vue");
@@ -260,8 +286,8 @@ function useV(Model) {
260
286
  useVMap.set(Model, proxy);
261
287
  return proxy;
262
288
  }
263
- function useOn(eventName, cb) {
264
- (0, import_vue3.onScopeDispose)(() => {
289
+ function useEvent(eventName, cb) {
290
+ (0, import_vue3.onBeforeUnmount)(() => {
265
291
  emitter.off(eventName, cb);
266
292
  });
267
293
  emitter.on(eventName, cb);
@@ -657,34 +683,52 @@ function createTable(compSet, table, tableColumn, data) {
657
683
  }
658
684
  });
659
685
  }
686
+
687
+ // src/components/helper/pipe.ts
688
+ var import_vue8 = require("vue");
689
+ function createPipe(comp, props, to = "default", slot) {
690
+ const vnodeMap = { [`${to}`]: () => (0, import_vue8.h)(comp, props, slot) };
691
+ return {
692
+ to(comp2, props2, to2 = "default") {
693
+ return createPipe(comp2, props2, to2, vnodeMap);
694
+ },
695
+ get() {
696
+ return vnodeMap;
697
+ },
698
+ bind(vnode, to2) {
699
+ vnodeMap[to2] = () => vnode;
700
+ }
701
+ };
702
+ }
660
703
  // Annotate the CommonJS export names for ESM import in node:
661
704
  0 && (module.exports = {
662
705
  EXPRESS_RE,
663
706
  FN_RE,
664
707
  GetDevUIRules,
665
708
  P,
666
- Watcher,
667
709
  clearStorage,
668
710
  createFilter,
669
711
  createForm,
670
712
  createFormData,
671
713
  createModal,
672
714
  createPhecda,
715
+ createPipe,
673
716
  createTable,
674
717
  deleteStorage,
675
- emit,
676
718
  emitter,
677
719
  getActivePhecda,
678
720
  getAntDRules,
679
721
  getElementPlusRules,
680
722
  getNaiveUIRules,
681
723
  getNutUIRules,
724
+ getReactiveMap,
682
725
  getVantRules,
683
726
  initalize,
727
+ invokeAction,
684
728
  phecdaSymbol,
685
729
  setActivePhecda,
730
+ useEvent,
686
731
  useO,
687
- useOn,
688
732
  usePatch,
689
733
  useR,
690
734
  useV
package/dist/index.mjs CHANGED
@@ -1,32 +1,48 @@
1
1
  // src/emitter.ts
2
2
  import mitt from "mitt";
3
3
  var emitter = mitt();
4
- var emit = emitter.emit.bind(emitter);
5
-
6
- // src/decorators.ts
7
- import { regisHandler, setModalState } from "phecda-core";
8
- function Watcher(eventName) {
9
- return (obj, key) => {
10
- setModalState(obj, key);
11
- regisHandler(obj, key, {
12
- init(instance) {
13
- emitter.on(eventName, instance[key].bind(instance));
14
- }
15
- });
16
- };
17
- }
4
+ var invokeAction = emitter.emit.bind(emitter);
18
5
 
19
6
  // src/vue/phecda.ts
20
7
  import { markRaw } from "vue";
8
+ import { getTag, injectProperty } from "phecda-core";
21
9
  var phecdaSymbol = Symbol("phecda");
22
- function createPhecda() {
10
+ function createPhecda(symbol) {
23
11
  const phecda = markRaw({
24
12
  install(app) {
25
13
  app.provide(phecdaSymbol, phecda);
26
14
  app.config.globalProperties.$phecda = phecda;
15
+ if (!window._phecda)
16
+ window._phecda = {};
17
+ if (symbol) {
18
+ window._phecda[symbol] = {
19
+ instance: phecda,
20
+ snapshot: () => {
21
+ const ret = [];
22
+ for (const [key, value] of phecda.useOMap)
23
+ ret.push({ key: getTag(key) || key.name, value });
24
+ return ret;
25
+ }
26
+ };
27
+ }
28
+ const eventRecord = [];
29
+ injectProperty("watcher", ({ eventName, instance, key }) => {
30
+ const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
31
+ eventRecord.push([eventName, fn]);
32
+ emitter.on(eventName, fn);
33
+ });
34
+ const originUnmount = app.unmount.bind(app);
35
+ app.unmount = () => {
36
+ eventRecord.forEach(
37
+ ([eventName, handler]) => emitter.off(eventName, handler)
38
+ );
39
+ if (symbol)
40
+ delete window._phecda[symbol];
41
+ originUnmount();
42
+ };
27
43
  },
28
44
  useVMap: /* @__PURE__ */ new WeakMap(),
29
- useOMap: /* @__PURE__ */ new WeakMap(),
45
+ useOMap: new (symbol ? Map : WeakMap)(),
30
46
  useRMap: /* @__PURE__ */ new WeakMap(),
31
47
  fnMap: /* @__PURE__ */ new WeakMap(),
32
48
  computedMap: /* @__PURE__ */ new WeakMap()
@@ -46,9 +62,18 @@ function setActivePhecda(phecda) {
46
62
  function getActivePhecda() {
47
63
  return activePhecda;
48
64
  }
65
+ function getReactiveMap(symbol) {
66
+ if (!window._phecda?.[symbol])
67
+ return null;
68
+ const ret = /* @__PURE__ */ new Map();
69
+ window._phecda[symbol].snapshot.forEach(({ key, value }) => {
70
+ ret.set(key, value);
71
+ });
72
+ return ret;
73
+ }
49
74
 
50
75
  // src/vue/composable.ts
51
- import { computed, getCurrentInstance, inject, onScopeDispose as onScopeDispose2, reactive } from "vue";
76
+ import { computed, getCurrentInstance, inject, onBeforeUnmount, reactive } from "vue";
52
77
  import { getHandler, register } from "phecda-core";
53
78
 
54
79
  // src/vue/utils.ts
@@ -199,8 +224,8 @@ function useV(Model) {
199
224
  useVMap.set(Model, proxy);
200
225
  return proxy;
201
226
  }
202
- function useOn(eventName, cb) {
203
- onScopeDispose2(() => {
227
+ function useEvent(eventName, cb) {
228
+ onBeforeUnmount(() => {
204
229
  emitter.off(eventName, cb);
205
230
  });
206
231
  emitter.on(eventName, cb);
@@ -596,33 +621,51 @@ function createTable(compSet, table, tableColumn, data) {
596
621
  }
597
622
  });
598
623
  }
624
+
625
+ // src/components/helper/pipe.ts
626
+ import { h as h4 } from "vue";
627
+ function createPipe(comp, props, to = "default", slot) {
628
+ const vnodeMap = { [`${to}`]: () => h4(comp, props, slot) };
629
+ return {
630
+ to(comp2, props2, to2 = "default") {
631
+ return createPipe(comp2, props2, to2, vnodeMap);
632
+ },
633
+ get() {
634
+ return vnodeMap;
635
+ },
636
+ bind(vnode, to2) {
637
+ vnodeMap[to2] = () => vnode;
638
+ }
639
+ };
640
+ }
599
641
  export {
600
642
  EXPRESS_RE,
601
643
  FN_RE,
602
644
  GetDevUIRules,
603
645
  P,
604
- Watcher,
605
646
  clearStorage,
606
647
  createFilter,
607
648
  createForm,
608
649
  createFormData,
609
650
  createModal,
610
651
  createPhecda,
652
+ createPipe,
611
653
  createTable,
612
654
  deleteStorage,
613
- emit,
614
655
  emitter,
615
656
  getActivePhecda,
616
657
  getAntDRules,
617
658
  getElementPlusRules,
618
659
  getNaiveUIRules,
619
660
  getNutUIRules,
661
+ getReactiveMap,
620
662
  getVantRules,
621
663
  initalize,
664
+ invokeAction,
622
665
  phecdaSymbol,
623
666
  setActivePhecda,
667
+ useEvent,
624
668
  useO,
625
- useOn,
626
669
  usePatch,
627
670
  useR,
628
671
  useV
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
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.2"
17
+ "phecda-core": "1.0.4"
18
18
  },
19
19
  "devDependencies": {
20
20
  "tsup": "^6.5.0"