phecda-vue 5.0.0 → 5.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.mts CHANGED
@@ -36,4 +36,8 @@ declare function WatchEffect(option?: WatchOptions): (proto: any, key: string) =
36
36
  declare function markRaw<T extends object>(value: T): Raw<T>;
37
37
  declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
38
38
 
39
- export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, markRaw, phecdaSymbol, useEvent, usePhecda, useR, useRaw, useV };
39
+ declare function hasI(model: Construct): boolean;
40
+ declare function useIR<T extends Construct>(model: T, forceProvide?: boolean): UnwrapNestedRefs<InstanceType<T>>;
41
+ declare function useIV<T extends Construct>(model: T, forceProvide?: boolean): ReplaceInstanceValues<InstanceType<T>>;
42
+
43
+ export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, hasI, markRaw, phecdaSymbol, useEvent, useIR, useIV, usePhecda, useR, useRaw, useV };
package/dist/index.d.ts CHANGED
@@ -36,4 +36,8 @@ declare function WatchEffect(option?: WatchOptions): (proto: any, key: string) =
36
36
  declare function markRaw<T extends object>(value: T): Raw<T>;
37
37
  declare function createSharedReactive<F extends (...args: any) => any>(composable: F): () => ReturnType<F>;
38
38
 
39
- export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, markRaw, phecdaSymbol, useEvent, usePhecda, useR, useRaw, useV };
39
+ declare function hasI(model: Construct): boolean;
40
+ declare function useIR<T extends Construct>(model: T, forceProvide?: boolean): UnwrapNestedRefs<InstanceType<T>>;
41
+ declare function useIV<T extends Construct>(model: T, forceProvide?: boolean): ReplaceInstanceValues<InstanceType<T>>;
42
+
43
+ export { type Raw, RawSymbol, type ReplaceInstanceValues, Shallow, VuePhecda, WatchEffect, createPhecda, createSharedReactive, getPhecda, getR, getRaw, getV, hasI, markRaw, phecdaSymbol, useEvent, useIR, useIV, usePhecda, useR, useRaw, useV };
package/dist/index.js CHANGED
@@ -31,9 +31,12 @@ __export(src_exports, {
31
31
  getR: () => getR,
32
32
  getRaw: () => getRaw,
33
33
  getV: () => getV,
34
+ hasI: () => hasI,
34
35
  markRaw: () => markRaw,
35
36
  phecdaSymbol: () => phecdaSymbol,
36
37
  useEvent: () => useEvent,
38
+ useIR: () => useIR,
39
+ useIV: () => useIV,
37
40
  usePhecda: () => usePhecda,
38
41
  useR: () => useR,
39
42
  useRaw: () => useRaw,
@@ -537,6 +540,58 @@ function WatchEffect(option) {
537
540
  };
538
541
  }
539
542
  __name(WatchEffect, "WatchEffect");
543
+
544
+ // src/lib.ts
545
+ var import_phecda_web4 = require("phecda-web");
546
+ var import_vue5 = require("vue");
547
+ function hasI(model) {
548
+ const tag = (0, import_phecda_web4.getTag)(model);
549
+ const injectKey = `phecda-vue:lib ${tag.toString()}`;
550
+ return !!(0, import_vue5.inject)(injectKey);
551
+ }
552
+ __name(hasI, "hasI");
553
+ function useIR(model, forceProvide = false) {
554
+ const tag = (0, import_phecda_web4.getTag)(model);
555
+ const injectKey = `phecda-vue:lib ${tag.toString()}`;
556
+ let existModule = (0, import_vue5.inject)(injectKey);
557
+ if (!existModule || forceProvide) {
558
+ const data = {
559
+ // keep class name
560
+ [model.name]: class extends model {
561
+ }
562
+ };
563
+ existModule = (0, import_phecda_web4.bindMethod)((0, import_vue5.reactive)(new data[model.name]()));
564
+ (0, import_vue5.provide)(injectKey, existModule);
565
+ return existModule;
566
+ } else {
567
+ return existModule;
568
+ }
569
+ }
570
+ __name(useIR, "useIR");
571
+ var weakmap = /* @__PURE__ */ new WeakMap();
572
+ function useIV(model, forceProvide = false) {
573
+ const instance = useIR(model, forceProvide);
574
+ if (weakmap.has(instance)) return weakmap.get(instance);
575
+ const cache = {};
576
+ const proxy = new Proxy(instance, {
577
+ get(target, key) {
578
+ if (typeof target[key] === "function") return target[key];
579
+ if (target[key]?.__v_skip) return target[key];
580
+ const cacheRef = cache[key];
581
+ if (cacheRef && cacheRef.r) return cacheRef();
582
+ cache[key] = createSharedReactive(() => {
583
+ return (0, import_vue5.toRef)(target, key);
584
+ });
585
+ return cache[key]();
586
+ },
587
+ set() {
588
+ return false;
589
+ }
590
+ });
591
+ weakmap.set(instance, proxy);
592
+ return proxy;
593
+ }
594
+ __name(useIV, "useIV");
540
595
  // Annotate the CommonJS export names for ESM import in node:
541
596
  0 && (module.exports = {
542
597
  Shallow,
@@ -548,9 +603,12 @@ __name(WatchEffect, "WatchEffect");
548
603
  getR,
549
604
  getRaw,
550
605
  getV,
606
+ hasI,
551
607
  markRaw,
552
608
  phecdaSymbol,
553
609
  useEvent,
610
+ useIR,
611
+ useIV,
554
612
  usePhecda,
555
613
  useR,
556
614
  useRaw,
package/dist/index.mjs CHANGED
@@ -499,6 +499,58 @@ function WatchEffect(option) {
499
499
  };
500
500
  }
501
501
  __name(WatchEffect, "WatchEffect");
502
+
503
+ // src/lib.ts
504
+ import { bindMethod as bindMethod3, getTag as getTag3 } from "phecda-web";
505
+ import { inject as inject2, provide, reactive as reactive2, toRef as toRef2 } from "vue";
506
+ function hasI(model) {
507
+ const tag = getTag3(model);
508
+ const injectKey = `phecda-vue:lib ${tag.toString()}`;
509
+ return !!inject2(injectKey);
510
+ }
511
+ __name(hasI, "hasI");
512
+ function useIR(model, forceProvide = false) {
513
+ const tag = getTag3(model);
514
+ const injectKey = `phecda-vue:lib ${tag.toString()}`;
515
+ let existModule = inject2(injectKey);
516
+ if (!existModule || forceProvide) {
517
+ const data = {
518
+ // keep class name
519
+ [model.name]: class extends model {
520
+ }
521
+ };
522
+ existModule = bindMethod3(reactive2(new data[model.name]()));
523
+ provide(injectKey, existModule);
524
+ return existModule;
525
+ } else {
526
+ return existModule;
527
+ }
528
+ }
529
+ __name(useIR, "useIR");
530
+ var weakmap = /* @__PURE__ */ new WeakMap();
531
+ function useIV(model, forceProvide = false) {
532
+ const instance = useIR(model, forceProvide);
533
+ if (weakmap.has(instance)) return weakmap.get(instance);
534
+ const cache = {};
535
+ const proxy = new Proxy(instance, {
536
+ get(target, key) {
537
+ if (typeof target[key] === "function") return target[key];
538
+ if (target[key]?.__v_skip) return target[key];
539
+ const cacheRef = cache[key];
540
+ if (cacheRef && cacheRef.r) return cacheRef();
541
+ cache[key] = createSharedReactive(() => {
542
+ return toRef2(target, key);
543
+ });
544
+ return cache[key]();
545
+ },
546
+ set() {
547
+ return false;
548
+ }
549
+ });
550
+ weakmap.set(instance, proxy);
551
+ return proxy;
552
+ }
553
+ __name(useIV, "useIV");
502
554
  export {
503
555
  Shallow,
504
556
  VuePhecda,
@@ -509,9 +561,12 @@ export {
509
561
  getR,
510
562
  getRaw,
511
563
  getV,
564
+ hasI,
512
565
  markRaw,
513
566
  phecdaSymbol,
514
567
  useEvent,
568
+ useIR,
569
+ useIV,
515
570
  usePhecda,
516
571
  useR,
517
572
  useRaw,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-vue",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "provide phecda function to vue",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",