wevu 0.0.2-alpha.0 → 1.0.0-alpha.1

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/README.md CHANGED
@@ -5,7 +5,7 @@ Vue 3 风格的小程序运行时,复用同款响应式与调度器,通过
5
5
  ## 特性
6
6
 
7
7
  - `ref`/`reactive`/`computed`/`watch` 与 `nextTick` 同源于 Vue 3 的响应式核心
8
- - `definePage`/`defineComponent` + `setup` 生命周期钩子(onShow/onPageScroll/onShareAppMessage 等)自动注册微信小程序 Page/Component
8
+ - `defineComponent` + `setup` 生命周期钩子(onShow/onPageScroll/onShareAppMessage 等)自动注册微信小程序 `Component`(在微信中可用于页面/组件)
9
9
  - 快照 diff + 去重调度,最小化 `setData` 体积,支持 `bindModel` 的双向绑定语法
10
10
  - 插件、`app.config.globalProperties` 及小程序原生选项可自由组合
11
11
  - 内置 `defineStore`/`storeToRefs`/`createStore`,支持 getters、actions、订阅与补丁
@@ -23,7 +23,7 @@ pnpm add wevu
23
23
  ```ts
24
24
  import {
25
25
  computed,
26
- definePage,
26
+ defineComponent,
27
27
  nextTick,
28
28
  onMounted,
29
29
  onPageScroll,
@@ -31,47 +31,45 @@ import {
31
31
  ref,
32
32
  } from 'wevu'
33
33
 
34
- definePage(
35
- {
36
- data: () => ({ count: 0 }),
37
- computed: {
38
- doubled() {
39
- return this.count * 2
40
- },
41
- },
42
- methods: {
43
- inc() {
44
- this.count += 1
45
- },
34
+ defineComponent({
35
+ features: {
36
+ listenPageScroll: true,
37
+ enableShareAppMessage: true,
38
+ },
39
+ data: () => ({ count: 0 }),
40
+ computed: {
41
+ doubled() {
42
+ return this.count * 2
46
43
  },
47
- watch: {
48
- count(n) {
49
- console.log('count changed', n)
50
- },
44
+ },
45
+ methods: {
46
+ inc() {
47
+ this.count += 1
51
48
  },
52
- setup({ state }) {
53
- const title = computed(() => `count: ${state.count}`)
54
- const local = ref(0)
55
-
56
- onMounted(() => {
57
- nextTick(() => console.log('page ready'))
58
- })
59
- onPageScroll((e) => {
60
- console.log('scrollTop', e?.scrollTop)
61
- })
62
- onShareAppMessage(() => ({ title: title.value }))
63
-
64
- return { local }
49
+ },
50
+ watch: {
51
+ count(n) {
52
+ console.log('count changed', n)
65
53
  },
66
54
  },
67
- {
68
- listenPageScroll: true,
69
- enableShareAppMessage: true,
55
+ setup({ state }) {
56
+ const title = computed(() => `count: ${state.count}`)
57
+ const local = ref(0)
58
+
59
+ onMounted(() => {
60
+ nextTick(() => console.log('page ready'))
61
+ })
62
+ onPageScroll((e) => {
63
+ console.log('scrollTop', e?.scrollTop)
64
+ })
65
+ onShareAppMessage(() => ({ title: title.value }))
66
+
67
+ return { local }
70
68
  },
71
- )
69
+ })
72
70
  ```
73
71
 
74
- - 当全局存在 `Page`/`Component` 构造器时自动注册;否则可拿到 `component.__wevu_runtime` 手动挂载适配器。
72
+ - 当全局存在 `Component` 构造器时自动注册;否则可拿到 `component.__wevu_runtime` 手动挂载适配器。
75
73
  - 组件场景使用 `defineComponent`,SFC 构建产物可调用 `createWevuComponent`。
76
74
 
77
75
  ## 状态管理
@@ -104,7 +102,6 @@ counter.inc()
104
102
 
105
103
  - 更新被批量加入微任务队列,`nextTick` 与 Vue 3 行为一致。
106
104
  - 对状态做快照 diff,只把变更路径传给 `setData`,避免大对象全量下发。
107
- - 可在 `createApp().mount(adapter)` 传入自定义 `setData` 适配器(例如单元测试或其他小程序平台)。
108
105
 
109
106
  ## 本地开发
110
107
 
@@ -1,6 +1,8 @@
1
1
  //#region src/reactivity/ref.d.ts
2
- interface Ref<T = any> {
3
- value: T;
2
+ interface Ref<T = any, S = T> {
3
+ get value(): T;
4
+ set value(_: S);
5
+ [key: symbol]: any;
4
6
  }
5
7
  declare function isRef(value: unknown): value is Ref<any>;
6
8
  declare function ref<T>(value: T): Ref<T>;
@@ -1,6 +1,8 @@
1
1
  //#region src/reactivity/ref.d.ts
2
- interface Ref<T = any> {
3
- value: T;
2
+ interface Ref<T = any, S = T> {
3
+ get value(): T;
4
+ set value(_: S);
5
+ [key: symbol]: any;
4
6
  }
5
7
  declare function isRef(value: unknown): value is Ref<any>;
6
8
  declare function ref<T>(value: T): Ref<T>;
package/dist/index.cjs CHANGED
@@ -546,6 +546,20 @@ function callUpdateHooks(target, phase) {
546
546
 
547
547
  //#endregion
548
548
  //#region src/runtime/register.ts
549
+ function runInlineExpression(ctx, expr, event) {
550
+ const handlerName = typeof expr === "string" ? expr : void 0;
551
+ if (!handlerName) return;
552
+ const argsRaw = (event?.currentTarget)?.dataset?.wvArgs ?? (event?.target)?.dataset?.wvArgs;
553
+ let args = [];
554
+ if (typeof argsRaw === "string") try {
555
+ args = JSON.parse(argsRaw);
556
+ } catch {
557
+ args = [];
558
+ }
559
+ const resolvedArgs = args.map((item) => item === "$event" ? event : item);
560
+ const handler = ctx?.[handlerName];
561
+ if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
562
+ }
549
563
  function runSetupFunction(setup, props, context) {
550
564
  if (typeof setup !== "function") return;
551
565
  const runtimeContext = context?.runtime ?? {
@@ -611,6 +625,7 @@ function registerWatches(runtime, watchMap, instance) {
611
625
  return stops;
612
626
  }
613
627
  function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
628
+ if (target.__wevu) return target.__wevu;
614
629
  const runtime = runtimeApp.mount({ setData(payload) {
615
630
  if (typeof target.setData === "function") target.setData(payload);
616
631
  } });
@@ -682,6 +697,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
682
697
  }
683
698
  function teardownRuntimeInstance(target) {
684
699
  const runtime = target.__wevu;
700
+ if (runtime && target.__wevuHooks) callHookList(target, "onUnload", []);
685
701
  if (target.__wevuHooks) target.__wevuHooks = void 0;
686
702
  const stops = target.__wevuWatchStops;
687
703
  if (Array.isArray(stops)) for (const stop$1 of stops) try {
@@ -697,6 +713,10 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
697
713
  const methodNames = Object.keys(methods ?? {});
698
714
  const appOptions = { ...mpOptions };
699
715
  appOptions.globalData = appOptions.globalData ?? {};
716
+ if (!appOptions.__weapp_vite_inline) appOptions.__weapp_vite_inline = function __weapp_vite_inline(event) {
717
+ const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
718
+ return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
719
+ };
700
720
  const userOnLaunch = appOptions.onLaunch;
701
721
  appOptions.onLaunch = function onLaunch(...args) {
702
722
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
@@ -731,89 +751,38 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
731
751
  }
732
752
  App(appOptions);
733
753
  }
734
- function registerPage(runtimeApp, methods, watch$1, setup, mpOptions, features) {
735
- if (typeof Page !== "function") throw new TypeError("definePage requires the global Page constructor to be available");
736
- const methodNames = Object.keys(methods ?? {});
737
- const pageOptions = { ...mpOptions };
738
- const userOnLoad = mpOptions.onLoad;
739
- pageOptions.onLoad = function onLoad(...args) {
740
- mountRuntimeInstance(this, runtimeApp, watch$1, setup);
741
- callHookList(this, "onShow", args);
742
- if (typeof userOnLoad === "function") userOnLoad.apply(this, args);
743
- };
744
- const userOnUnload = mpOptions.onUnload;
745
- pageOptions.onUnload = function onUnload$1(...args) {
746
- teardownRuntimeInstance(this);
747
- if (typeof userOnUnload === "function") userOnUnload.apply(this, args);
748
- };
749
- const userOnShow = mpOptions.onShow;
750
- pageOptions.onShow = function onShow$1(...args) {
751
- callHookList(this, "onShow", args);
752
- if (typeof userOnShow === "function") userOnShow.apply(this, args);
753
- };
754
- const userOnHide = mpOptions.onHide;
755
- pageOptions.onHide = function onHide$1(...args) {
756
- callHookList(this, "onHide", args);
757
- if (typeof userOnHide === "function") userOnHide.apply(this, args);
754
+ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, features) {
755
+ const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, options: userOptions = {}, ...rest } = mpOptions;
756
+ const userOnLoad = rest.onLoad;
757
+ const userOnUnload = rest.onUnload;
758
+ const userOnShow = rest.onShow;
759
+ const userOnHide = rest.onHide;
760
+ const userOnReady = rest.onReady;
761
+ const userOnSaveExitState = rest.onSaveExitState;
762
+ const userOnPageScroll = rest.onPageScroll;
763
+ const userOnShareAppMessage = rest.onShareAppMessage;
764
+ const userOnShareTimeline = rest.onShareTimeline;
765
+ const userOnAddToFavorites = rest.onAddToFavorites;
766
+ const restOptions = { ...rest };
767
+ delete restOptions.onLoad;
768
+ delete restOptions.onUnload;
769
+ delete restOptions.onShow;
770
+ delete restOptions.onHide;
771
+ delete restOptions.onReady;
772
+ delete restOptions.onSaveExitState;
773
+ delete restOptions.onPageScroll;
774
+ delete restOptions.onShareAppMessage;
775
+ delete restOptions.onShareTimeline;
776
+ delete restOptions.onAddToFavorites;
777
+ const finalOptions = {
778
+ multipleSlots: userOptions.multipleSlots ?? true,
779
+ ...userOptions
758
780
  };
759
- const userOnReady = mpOptions.onReady;
760
- pageOptions.onReady = function onReady$1(...args) {
761
- callHookList(this, "onReady", args);
762
- if (typeof userOnReady === "function") return userOnReady.apply(this, args);
763
- };
764
- const userOnSaveExitState = mpOptions.onSaveExitState;
765
- pageOptions.onSaveExitState = function onSaveExitState$1(...args) {
766
- const ret = callHookReturn(this, "onSaveExitState", args);
767
- if (ret !== void 0) return ret;
768
- if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
769
- };
770
- if (features?.listenPageScroll) {
771
- const userOnPageScroll = mpOptions.onPageScroll;
772
- pageOptions.onPageScroll = function onPageScroll$1(...args) {
773
- callHookList(this, "onPageScroll", args);
774
- if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
775
- };
776
- }
777
- if (features?.enableShareAppMessage) {
778
- const userOnShare = mpOptions.onShareAppMessage;
779
- pageOptions.onShareAppMessage = function pageOnShareAppMessage(...args) {
780
- const ret = callHookReturn(this, "onShareAppMessage", args);
781
- if (ret !== void 0) return ret;
782
- if (typeof userOnShare === "function") return userOnShare.apply(this, args);
783
- };
784
- }
785
- if (features?.enableShareTimeline) {
786
- const userOnShareTimeline = mpOptions.onShareTimeline;
787
- pageOptions.onShareTimeline = function pageOnShareTimeline(...args) {
788
- const ret = callHookReturn(this, "onShareTimeline", args);
789
- if (ret !== void 0) return ret;
790
- if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
791
- };
792
- }
793
- if (features?.enableAddToFavorites) {
794
- const userOnAddToFavorites = mpOptions.onAddToFavorites;
795
- pageOptions.onAddToFavorites = function pageOnAddToFavorites(...args) {
796
- const ret = callHookReturn(this, "onAddToFavorites", args);
797
- if (ret !== void 0) return ret;
798
- if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
799
- };
800
- }
801
- for (const methodName of methodNames) {
802
- const userMethod = mpOptions[methodName];
803
- pageOptions[methodName] = function runtimeMethod(...args) {
804
- const runtime = this.__wevu;
805
- let result;
806
- const bound = runtime?.methods?.[methodName];
807
- if (bound) result = bound.apply(runtime.proxy, args);
808
- if (typeof userMethod === "function") return userMethod.apply(this, args);
809
- return result;
810
- };
811
- }
812
- Page(pageOptions);
813
- }
814
- function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
815
- const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, ...rest } = mpOptions;
816
781
  const finalMethods = { ...userMethods };
782
+ if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
783
+ const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
784
+ return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
785
+ };
817
786
  const methodNames = Object.keys(methods ?? {});
818
787
  for (const methodName of methodNames) {
819
788
  const userMethod = finalMethods[methodName];
@@ -835,8 +804,58 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
835
804
  };
836
805
  wrapSpecial("onTabItemTap");
837
806
  wrapSpecial("onRouteDone");
807
+ const pageLifecycleHooks = {
808
+ onLoad(...args) {
809
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup);
810
+ if (typeof userOnLoad === "function") return userOnLoad.apply(this, args);
811
+ },
812
+ onUnload(...args) {
813
+ teardownRuntimeInstance(this);
814
+ if (typeof userOnUnload === "function") return userOnUnload.apply(this, args);
815
+ },
816
+ onShow(...args) {
817
+ callHookList(this, "onShow", args);
818
+ if (typeof userOnShow === "function") return userOnShow.apply(this, args);
819
+ },
820
+ onHide(...args) {
821
+ callHookList(this, "onHide", args);
822
+ if (typeof userOnHide === "function") return userOnHide.apply(this, args);
823
+ },
824
+ onReady(...args) {
825
+ if (!this.__wevuReadyCalled) {
826
+ this.__wevuReadyCalled = true;
827
+ callHookList(this, "onReady", args);
828
+ }
829
+ if (typeof userOnReady === "function") return userOnReady.apply(this, args);
830
+ },
831
+ onSaveExitState(...args) {
832
+ const ret = callHookReturn(this, "onSaveExitState", args);
833
+ if (ret !== void 0) return ret;
834
+ if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
835
+ }
836
+ };
837
+ if (features?.listenPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
838
+ callHookList(this, "onPageScroll", args);
839
+ if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
840
+ };
841
+ if (features?.enableShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
842
+ const ret = callHookReturn(this, "onShareAppMessage", args);
843
+ if (ret !== void 0) return ret;
844
+ if (typeof userOnShareAppMessage === "function") return userOnShareAppMessage.apply(this, args);
845
+ };
846
+ if (features?.enableShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
847
+ const ret = callHookReturn(this, "onShareTimeline", args);
848
+ if (ret !== void 0) return ret;
849
+ if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
850
+ };
851
+ if (features?.enableAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
852
+ const ret = callHookReturn(this, "onAddToFavorites", args);
853
+ if (ret !== void 0) return ret;
854
+ if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
855
+ };
838
856
  Component({
839
- ...rest,
857
+ ...restOptions,
858
+ ...pageLifecycleHooks,
840
859
  lifetimes: {
841
860
  ...userLifetimes,
842
861
  attached: function attached(...args) {
@@ -844,7 +863,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
844
863
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
845
864
  },
846
865
  ready: function ready(...args) {
847
- callHookList(this, "onReady", args);
866
+ if (!this.__wevuReadyCalled) {
867
+ this.__wevuReadyCalled = true;
868
+ callHookList(this, "onReady", args);
869
+ }
848
870
  if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
849
871
  },
850
872
  detached: function detached(...args) {
@@ -863,7 +885,8 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
863
885
  if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
864
886
  }
865
887
  },
866
- methods: finalMethods
888
+ methods: finalMethods,
889
+ options: finalOptions
867
890
  });
868
891
  }
869
892
 
@@ -1065,7 +1088,9 @@ function setComputedValue(setters, key, value) {
1065
1088
  //#endregion
1066
1089
  //#region src/runtime/define.ts
1067
1090
  /**
1068
- * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
1091
+ * 按 Vue 3 风格定义一个小程序组件/页面。
1092
+ *
1093
+ * - 统一注册为 `Component()`
1069
1094
  *
1070
1095
  * @param options 组件定义项
1071
1096
  * @returns 可手动注册的组件定义
@@ -1079,57 +1104,19 @@ function setComputedValue(setters, key, value) {
1079
1104
  * }
1080
1105
  * })
1081
1106
  * ```
1082
- */
1083
- function defineComponent(options) {
1084
- const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1085
- const mpOptionsWithProps = normalizeProps(mpOptions, props);
1086
- const runtimeApp = createApp({
1087
- data,
1088
- computed: computed$1,
1089
- methods
1090
- });
1091
- const setupWrapper = (ctx) => {
1092
- const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1093
- if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1094
- };
1095
- const componentOptions = {
1096
- data,
1097
- computed: computed$1,
1098
- methods,
1099
- watch: watch$1,
1100
- setup: setupWrapper,
1101
- mpOptions: mpOptionsWithProps
1102
- };
1103
- registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
1104
- return {
1105
- __wevu_runtime: runtimeApp,
1106
- __wevu_options: componentOptions
1107
- };
1108
- }
1109
- /**
1110
- * 按 Vue 3 风格定义一个小程序页面
1111
- *
1112
- * @param options 页面定义
1113
- * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
1114
- * @returns 页面定义
1115
1107
  *
1116
1108
  * @example
1117
1109
  * ```ts
1118
- * definePage({
1119
- * data: () => ({ count: 0 }),
1110
+ * defineComponent({
1111
+ * features: { listenPageScroll: true },
1120
1112
  * setup() {
1121
- * const count = ref(0)
1122
- * onMounted(() => console.log('page mounted'))
1123
- * return { count }
1113
+ * onPageScroll(() => {})
1124
1114
  * }
1125
- * }, {
1126
- * listenPageScroll: true,
1127
- * enableShareAppMessage: true
1128
1115
  * })
1129
1116
  * ```
1130
1117
  */
1131
- function definePage(options, features) {
1132
- const { data, computed: computed$1, methods, watch: watch$1, setup, props: _props, ...mpOptions } = options;
1118
+ function defineComponent(options) {
1119
+ const { features, data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1133
1120
  const runtimeApp = createApp({
1134
1121
  data,
1135
1122
  computed: computed$1,
@@ -1139,19 +1126,18 @@ function definePage(options, features) {
1139
1126
  const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1140
1127
  if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1141
1128
  };
1129
+ const mpOptionsWithProps = normalizeProps(mpOptions, props);
1142
1130
  const componentOptions = {
1143
- type: "page",
1144
1131
  data,
1145
1132
  computed: computed$1,
1146
1133
  methods,
1147
1134
  watch: watch$1,
1148
1135
  setup: setupWrapper,
1149
- mpOptions,
1136
+ mpOptions: mpOptionsWithProps,
1150
1137
  features
1151
1138
  };
1152
- registerPage(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptions, features);
1139
+ registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps, features);
1153
1140
  return {
1154
- mount: () => {},
1155
1141
  __wevu_runtime: runtimeApp,
1156
1142
  __wevu_options: componentOptions
1157
1143
  };
@@ -1295,7 +1281,6 @@ exports.createApp = createApp;
1295
1281
  exports.createStore = require_store.createStore;
1296
1282
  exports.createWevuComponent = createWevuComponent;
1297
1283
  exports.defineComponent = defineComponent;
1298
- exports.definePage = definePage;
1299
1284
  exports.defineStore = require_store.defineStore;
1300
1285
  exports.effect = require_store.effect;
1301
1286
  exports.getCurrentInstance = getCurrentInstance;
@@ -1341,7 +1326,6 @@ exports.readonly = readonly;
1341
1326
  exports.ref = require_store.ref;
1342
1327
  exports.registerApp = registerApp;
1343
1328
  exports.registerComponent = registerComponent;
1344
- exports.registerPage = registerPage;
1345
1329
  exports.runSetupFunction = runSetupFunction;
1346
1330
  exports.setCurrentInstance = setCurrentInstance;
1347
1331
  exports.setDeepWatchStrategy = setDeepWatchStrategy;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,15 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-D1r6nN-t.cjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-DVEFI-Uo.cjs";
2
2
 
3
3
  //#region src/reactivity/computed.d.ts
4
4
  type ComputedGetter<T$1> = () => T$1;
5
5
  type ComputedSetter<T$1> = (value: T$1) => void;
6
- interface ComputedRef<T$1> {
6
+ interface BaseComputedRef<T$1, S = T$1> extends Ref<T$1, S> {
7
+ [key: symbol]: any;
8
+ }
9
+ interface ComputedRef<T$1 = any> extends BaseComputedRef<T$1> {
7
10
  readonly value: T$1;
8
11
  }
9
- interface WritableComputedRef<T$1> {
12
+ interface WritableComputedRef<T$1, S = T$1> extends BaseComputedRef<T$1, S> {
10
13
  value: T$1;
11
14
  }
12
15
  interface WritableComputedOptions<T$1> {
@@ -328,6 +331,11 @@ interface InternalRuntimeState {
328
331
  __wevuExposed?: Record<string, any>;
329
332
  }
330
333
  interface DefineComponentOptions<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends Omit<CreateAppOptions<D, C, M>, 'setup'> {
334
+ /**
335
+ * Page-only feature gates (e.g. scroll/share hooks).
336
+ * Only takes effect on page entries.
337
+ */
338
+ features?: PageFeatures;
331
339
  /**
332
340
  * Vue-like props definition (will be normalized to mini-program `properties`)
333
341
  */
@@ -380,10 +388,13 @@ interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M
380
388
  watch: Record<string, any> | undefined;
381
389
  setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'];
382
390
  mpOptions: Record<string, any>;
391
+ features?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['features'];
383
392
  };
384
393
  }
385
394
  /**
386
- * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
395
+ * 按 Vue 3 风格定义一个小程序组件/页面。
396
+ *
397
+ * - 统一注册为 `Component()`
387
398
  *
388
399
  * @param options 组件定义项
389
400
  * @returns 可手动注册的组件定义
@@ -397,31 +408,18 @@ interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M
397
408
  * }
398
409
  * })
399
410
  * ```
400
- */
401
- declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
402
- /**
403
- * 按 Vue 3 风格定义一个小程序页面
404
- *
405
- * @param options 页面定义
406
- * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
407
- * @returns 页面定义
408
411
  *
409
412
  * @example
410
413
  * ```ts
411
- * definePage({
412
- * data: () => ({ count: 0 }),
414
+ * defineComponent({
415
+ * features: { listenPageScroll: true },
413
416
  * setup() {
414
- * const count = ref(0)
415
- * onMounted(() => console.log('page mounted'))
416
- * return { count }
417
+ * onPageScroll(() => {})
417
418
  * }
418
- * }, {
419
- * listenPageScroll: true,
420
- * enableShareAppMessage: true
421
419
  * })
422
420
  * ```
423
421
  */
424
- declare function definePage<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: Omit<DefineComponentOptions<P$1, D, C, M>, 'type'>, features?: PageFeatures): ComponentDefinition<D, C, M>;
422
+ declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
425
423
  /**
426
424
  * 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
427
425
  *
@@ -551,7 +549,6 @@ declare function runSetupFunction(setup: ((...args: any[]) => any) | undefined,
551
549
  declare function mountRuntimeInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(target: InternalRuntimeState, runtimeApp: RuntimeApp<D, C, M>, watchMap: WatchMap | undefined, setup?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']): RuntimeInstance<D, C, M>;
552
550
  declare function teardownRuntimeInstance(target: InternalRuntimeState): void;
553
551
  declare function registerApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineAppOptions<D, C, M>['setup'], mpOptions: Record<string, any>): void;
554
- declare function registerPage<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
555
- declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>): void;
552
+ declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
556
553
  //#endregion
557
- export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, definePage, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, registerPage, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
554
+ export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,15 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-DHBSC7mS.mjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, d as ref, f as unref, i as ActionSubscriber, l as Ref, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs, u as isRef } from "./index-0dF4y5p6.mjs";
2
2
 
3
3
  //#region src/reactivity/computed.d.ts
4
4
  type ComputedGetter<T$1> = () => T$1;
5
5
  type ComputedSetter<T$1> = (value: T$1) => void;
6
- interface ComputedRef<T$1> {
6
+ interface BaseComputedRef<T$1, S = T$1> extends Ref<T$1, S> {
7
+ [key: symbol]: any;
8
+ }
9
+ interface ComputedRef<T$1 = any> extends BaseComputedRef<T$1> {
7
10
  readonly value: T$1;
8
11
  }
9
- interface WritableComputedRef<T$1> {
12
+ interface WritableComputedRef<T$1, S = T$1> extends BaseComputedRef<T$1, S> {
10
13
  value: T$1;
11
14
  }
12
15
  interface WritableComputedOptions<T$1> {
@@ -328,6 +331,11 @@ interface InternalRuntimeState {
328
331
  __wevuExposed?: Record<string, any>;
329
332
  }
330
333
  interface DefineComponentOptions<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions> extends Omit<CreateAppOptions<D, C, M>, 'setup'> {
334
+ /**
335
+ * Page-only feature gates (e.g. scroll/share hooks).
336
+ * Only takes effect on page entries.
337
+ */
338
+ features?: PageFeatures;
331
339
  /**
332
340
  * Vue-like props definition (will be normalized to mini-program `properties`)
333
341
  */
@@ -380,10 +388,13 @@ interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M
380
388
  watch: Record<string, any> | undefined;
381
389
  setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'];
382
390
  mpOptions: Record<string, any>;
391
+ features?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['features'];
383
392
  };
384
393
  }
385
394
  /**
386
- * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
395
+ * 按 Vue 3 风格定义一个小程序组件/页面。
396
+ *
397
+ * - 统一注册为 `Component()`
387
398
  *
388
399
  * @param options 组件定义项
389
400
  * @returns 可手动注册的组件定义
@@ -397,31 +408,18 @@ interface ComponentDefinition<D extends object, C extends ComputedDefinitions, M
397
408
  * }
398
409
  * })
399
410
  * ```
400
- */
401
- declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
402
- /**
403
- * 按 Vue 3 风格定义一个小程序页面
404
- *
405
- * @param options 页面定义
406
- * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
407
- * @returns 页面定义
408
411
  *
409
412
  * @example
410
413
  * ```ts
411
- * definePage({
412
- * data: () => ({ count: 0 }),
414
+ * defineComponent({
415
+ * features: { listenPageScroll: true },
413
416
  * setup() {
414
- * const count = ref(0)
415
- * onMounted(() => console.log('page mounted'))
416
- * return { count }
417
+ * onPageScroll(() => {})
417
418
  * }
418
- * }, {
419
- * listenPageScroll: true,
420
- * enableShareAppMessage: true
421
419
  * })
422
420
  * ```
423
421
  */
424
- declare function definePage<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: Omit<DefineComponentOptions<P$1, D, C, M>, 'type'>, features?: PageFeatures): ComponentDefinition<D, C, M>;
422
+ declare function defineComponent<P$1 extends ComponentPropsOptions = ComponentPropsOptions, D extends object = Record<string, any>, C extends ComputedDefinitions = ComputedDefinitions, M extends MethodDefinitions = MethodDefinitions>(options: DefineComponentOptions<P$1, D, C, M>): ComponentDefinition<D, C, M>;
425
423
  /**
426
424
  * 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
427
425
  *
@@ -551,7 +549,6 @@ declare function runSetupFunction(setup: ((...args: any[]) => any) | undefined,
551
549
  declare function mountRuntimeInstance<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(target: InternalRuntimeState, runtimeApp: RuntimeApp<D, C, M>, watchMap: WatchMap | undefined, setup?: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup']): RuntimeInstance<D, C, M>;
552
550
  declare function teardownRuntimeInstance(target: InternalRuntimeState): void;
553
551
  declare function registerApp<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineAppOptions<D, C, M>['setup'], mpOptions: Record<string, any>): void;
554
- declare function registerPage<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
555
- declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>): void;
552
+ declare function registerComponent<D extends object, C extends ComputedDefinitions, M extends MethodDefinitions>(runtimeApp: RuntimeApp<D, C, M>, methods: MethodDefinitions, watch: WatchMap | undefined, setup: DefineComponentOptions<ComponentPropsOptions, D, C, M>['setup'], mpOptions: Record<string, any>, features?: PageFeatures): void;
556
553
  //#endregion
557
- export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, definePage, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, registerPage, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
554
+ export { ActionSubscriber, AppConfig, ComponentDefinition, ComponentPropsOptions, ComponentPublicInstance, ComputedDefinitions, ComputedGetter, ComputedRef, ComputedSetter, CreateAppOptions, DefineAppOptions, DefineComponentOptions, DefineStoreOptions, ExtractComputed, ExtractMethods, InferPropType, InferProps, InternalRuntimeState, MethodDefinitions, MiniProgramAdapter, ModelBinding, ModelBindingOptions, MutationType, PageFeatures, PropConstructor, PropOptions, PropType, Ref, RuntimeApp, RuntimeInstance, SetupContext, SetupFunction, StoreManager, SubscriptionCallback, ToRefs, WatchOptions, WatchStopHandle, WevuPlugin, WritableComputedOptions, WritableComputedRef, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
package/dist/index.mjs CHANGED
@@ -546,6 +546,20 @@ function callUpdateHooks(target, phase) {
546
546
 
547
547
  //#endregion
548
548
  //#region src/runtime/register.ts
549
+ function runInlineExpression(ctx, expr, event) {
550
+ const handlerName = typeof expr === "string" ? expr : void 0;
551
+ if (!handlerName) return;
552
+ const argsRaw = (event?.currentTarget)?.dataset?.wvArgs ?? (event?.target)?.dataset?.wvArgs;
553
+ let args = [];
554
+ if (typeof argsRaw === "string") try {
555
+ args = JSON.parse(argsRaw);
556
+ } catch {
557
+ args = [];
558
+ }
559
+ const resolvedArgs = args.map((item) => item === "$event" ? event : item);
560
+ const handler = ctx?.[handlerName];
561
+ if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
562
+ }
549
563
  function runSetupFunction(setup, props, context) {
550
564
  if (typeof setup !== "function") return;
551
565
  const runtimeContext = context?.runtime ?? {
@@ -611,6 +625,7 @@ function registerWatches(runtime, watchMap, instance) {
611
625
  return stops;
612
626
  }
613
627
  function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
628
+ if (target.__wevu) return target.__wevu;
614
629
  const runtime = runtimeApp.mount({ setData(payload) {
615
630
  if (typeof target.setData === "function") target.setData(payload);
616
631
  } });
@@ -682,6 +697,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
682
697
  }
683
698
  function teardownRuntimeInstance(target) {
684
699
  const runtime = target.__wevu;
700
+ if (runtime && target.__wevuHooks) callHookList(target, "onUnload", []);
685
701
  if (target.__wevuHooks) target.__wevuHooks = void 0;
686
702
  const stops = target.__wevuWatchStops;
687
703
  if (Array.isArray(stops)) for (const stop$1 of stops) try {
@@ -697,6 +713,10 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
697
713
  const methodNames = Object.keys(methods ?? {});
698
714
  const appOptions = { ...mpOptions };
699
715
  appOptions.globalData = appOptions.globalData ?? {};
716
+ if (!appOptions.__weapp_vite_inline) appOptions.__weapp_vite_inline = function __weapp_vite_inline(event) {
717
+ const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
718
+ return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
719
+ };
700
720
  const userOnLaunch = appOptions.onLaunch;
701
721
  appOptions.onLaunch = function onLaunch(...args) {
702
722
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
@@ -731,89 +751,38 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
731
751
  }
732
752
  App(appOptions);
733
753
  }
734
- function registerPage(runtimeApp, methods, watch$1, setup, mpOptions, features) {
735
- if (typeof Page !== "function") throw new TypeError("definePage requires the global Page constructor to be available");
736
- const methodNames = Object.keys(methods ?? {});
737
- const pageOptions = { ...mpOptions };
738
- const userOnLoad = mpOptions.onLoad;
739
- pageOptions.onLoad = function onLoad(...args) {
740
- mountRuntimeInstance(this, runtimeApp, watch$1, setup);
741
- callHookList(this, "onShow", args);
742
- if (typeof userOnLoad === "function") userOnLoad.apply(this, args);
743
- };
744
- const userOnUnload = mpOptions.onUnload;
745
- pageOptions.onUnload = function onUnload$1(...args) {
746
- teardownRuntimeInstance(this);
747
- if (typeof userOnUnload === "function") userOnUnload.apply(this, args);
748
- };
749
- const userOnShow = mpOptions.onShow;
750
- pageOptions.onShow = function onShow$1(...args) {
751
- callHookList(this, "onShow", args);
752
- if (typeof userOnShow === "function") userOnShow.apply(this, args);
753
- };
754
- const userOnHide = mpOptions.onHide;
755
- pageOptions.onHide = function onHide$1(...args) {
756
- callHookList(this, "onHide", args);
757
- if (typeof userOnHide === "function") userOnHide.apply(this, args);
754
+ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, features) {
755
+ const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, options: userOptions = {}, ...rest } = mpOptions;
756
+ const userOnLoad = rest.onLoad;
757
+ const userOnUnload = rest.onUnload;
758
+ const userOnShow = rest.onShow;
759
+ const userOnHide = rest.onHide;
760
+ const userOnReady = rest.onReady;
761
+ const userOnSaveExitState = rest.onSaveExitState;
762
+ const userOnPageScroll = rest.onPageScroll;
763
+ const userOnShareAppMessage = rest.onShareAppMessage;
764
+ const userOnShareTimeline = rest.onShareTimeline;
765
+ const userOnAddToFavorites = rest.onAddToFavorites;
766
+ const restOptions = { ...rest };
767
+ delete restOptions.onLoad;
768
+ delete restOptions.onUnload;
769
+ delete restOptions.onShow;
770
+ delete restOptions.onHide;
771
+ delete restOptions.onReady;
772
+ delete restOptions.onSaveExitState;
773
+ delete restOptions.onPageScroll;
774
+ delete restOptions.onShareAppMessage;
775
+ delete restOptions.onShareTimeline;
776
+ delete restOptions.onAddToFavorites;
777
+ const finalOptions = {
778
+ multipleSlots: userOptions.multipleSlots ?? true,
779
+ ...userOptions
758
780
  };
759
- const userOnReady = mpOptions.onReady;
760
- pageOptions.onReady = function onReady$1(...args) {
761
- callHookList(this, "onReady", args);
762
- if (typeof userOnReady === "function") return userOnReady.apply(this, args);
763
- };
764
- const userOnSaveExitState = mpOptions.onSaveExitState;
765
- pageOptions.onSaveExitState = function onSaveExitState$1(...args) {
766
- const ret = callHookReturn(this, "onSaveExitState", args);
767
- if (ret !== void 0) return ret;
768
- if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
769
- };
770
- if (features?.listenPageScroll) {
771
- const userOnPageScroll = mpOptions.onPageScroll;
772
- pageOptions.onPageScroll = function onPageScroll$1(...args) {
773
- callHookList(this, "onPageScroll", args);
774
- if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
775
- };
776
- }
777
- if (features?.enableShareAppMessage) {
778
- const userOnShare = mpOptions.onShareAppMessage;
779
- pageOptions.onShareAppMessage = function pageOnShareAppMessage(...args) {
780
- const ret = callHookReturn(this, "onShareAppMessage", args);
781
- if (ret !== void 0) return ret;
782
- if (typeof userOnShare === "function") return userOnShare.apply(this, args);
783
- };
784
- }
785
- if (features?.enableShareTimeline) {
786
- const userOnShareTimeline = mpOptions.onShareTimeline;
787
- pageOptions.onShareTimeline = function pageOnShareTimeline(...args) {
788
- const ret = callHookReturn(this, "onShareTimeline", args);
789
- if (ret !== void 0) return ret;
790
- if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
791
- };
792
- }
793
- if (features?.enableAddToFavorites) {
794
- const userOnAddToFavorites = mpOptions.onAddToFavorites;
795
- pageOptions.onAddToFavorites = function pageOnAddToFavorites(...args) {
796
- const ret = callHookReturn(this, "onAddToFavorites", args);
797
- if (ret !== void 0) return ret;
798
- if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
799
- };
800
- }
801
- for (const methodName of methodNames) {
802
- const userMethod = mpOptions[methodName];
803
- pageOptions[methodName] = function runtimeMethod(...args) {
804
- const runtime = this.__wevu;
805
- let result;
806
- const bound = runtime?.methods?.[methodName];
807
- if (bound) result = bound.apply(runtime.proxy, args);
808
- if (typeof userMethod === "function") return userMethod.apply(this, args);
809
- return result;
810
- };
811
- }
812
- Page(pageOptions);
813
- }
814
- function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
815
- const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, ...rest } = mpOptions;
816
781
  const finalMethods = { ...userMethods };
782
+ if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
783
+ const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
784
+ return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
785
+ };
817
786
  const methodNames = Object.keys(methods ?? {});
818
787
  for (const methodName of methodNames) {
819
788
  const userMethod = finalMethods[methodName];
@@ -835,8 +804,58 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
835
804
  };
836
805
  wrapSpecial("onTabItemTap");
837
806
  wrapSpecial("onRouteDone");
807
+ const pageLifecycleHooks = {
808
+ onLoad(...args) {
809
+ mountRuntimeInstance(this, runtimeApp, watch$1, setup);
810
+ if (typeof userOnLoad === "function") return userOnLoad.apply(this, args);
811
+ },
812
+ onUnload(...args) {
813
+ teardownRuntimeInstance(this);
814
+ if (typeof userOnUnload === "function") return userOnUnload.apply(this, args);
815
+ },
816
+ onShow(...args) {
817
+ callHookList(this, "onShow", args);
818
+ if (typeof userOnShow === "function") return userOnShow.apply(this, args);
819
+ },
820
+ onHide(...args) {
821
+ callHookList(this, "onHide", args);
822
+ if (typeof userOnHide === "function") return userOnHide.apply(this, args);
823
+ },
824
+ onReady(...args) {
825
+ if (!this.__wevuReadyCalled) {
826
+ this.__wevuReadyCalled = true;
827
+ callHookList(this, "onReady", args);
828
+ }
829
+ if (typeof userOnReady === "function") return userOnReady.apply(this, args);
830
+ },
831
+ onSaveExitState(...args) {
832
+ const ret = callHookReturn(this, "onSaveExitState", args);
833
+ if (ret !== void 0) return ret;
834
+ if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
835
+ }
836
+ };
837
+ if (features?.listenPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
838
+ callHookList(this, "onPageScroll", args);
839
+ if (typeof userOnPageScroll === "function") return userOnPageScroll.apply(this, args);
840
+ };
841
+ if (features?.enableShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
842
+ const ret = callHookReturn(this, "onShareAppMessage", args);
843
+ if (ret !== void 0) return ret;
844
+ if (typeof userOnShareAppMessage === "function") return userOnShareAppMessage.apply(this, args);
845
+ };
846
+ if (features?.enableShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
847
+ const ret = callHookReturn(this, "onShareTimeline", args);
848
+ if (ret !== void 0) return ret;
849
+ if (typeof userOnShareTimeline === "function") return userOnShareTimeline.apply(this, args);
850
+ };
851
+ if (features?.enableAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
852
+ const ret = callHookReturn(this, "onAddToFavorites", args);
853
+ if (ret !== void 0) return ret;
854
+ if (typeof userOnAddToFavorites === "function") return userOnAddToFavorites.apply(this, args);
855
+ };
838
856
  Component({
839
- ...rest,
857
+ ...restOptions,
858
+ ...pageLifecycleHooks,
840
859
  lifetimes: {
841
860
  ...userLifetimes,
842
861
  attached: function attached(...args) {
@@ -844,7 +863,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
844
863
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
845
864
  },
846
865
  ready: function ready(...args) {
847
- callHookList(this, "onReady", args);
866
+ if (!this.__wevuReadyCalled) {
867
+ this.__wevuReadyCalled = true;
868
+ callHookList(this, "onReady", args);
869
+ }
848
870
  if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
849
871
  },
850
872
  detached: function detached(...args) {
@@ -863,7 +885,8 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
863
885
  if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
864
886
  }
865
887
  },
866
- methods: finalMethods
888
+ methods: finalMethods,
889
+ options: finalOptions
867
890
  });
868
891
  }
869
892
 
@@ -1065,7 +1088,9 @@ function setComputedValue(setters, key, value) {
1065
1088
  //#endregion
1066
1089
  //#region src/runtime/define.ts
1067
1090
  /**
1068
- * 按 Vue 3 风格定义一个小程序组件(始终注册为 Component,页面请用 definePage)。
1091
+ * 按 Vue 3 风格定义一个小程序组件/页面。
1092
+ *
1093
+ * - 统一注册为 `Component()`
1069
1094
  *
1070
1095
  * @param options 组件定义项
1071
1096
  * @returns 可手动注册的组件定义
@@ -1079,57 +1104,19 @@ function setComputedValue(setters, key, value) {
1079
1104
  * }
1080
1105
  * })
1081
1106
  * ```
1082
- */
1083
- function defineComponent(options) {
1084
- const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1085
- const mpOptionsWithProps = normalizeProps(mpOptions, props);
1086
- const runtimeApp = createApp({
1087
- data,
1088
- computed: computed$1,
1089
- methods
1090
- });
1091
- const setupWrapper = (ctx) => {
1092
- const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1093
- if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1094
- };
1095
- const componentOptions = {
1096
- data,
1097
- computed: computed$1,
1098
- methods,
1099
- watch: watch$1,
1100
- setup: setupWrapper,
1101
- mpOptions: mpOptionsWithProps
1102
- };
1103
- registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
1104
- return {
1105
- __wevu_runtime: runtimeApp,
1106
- __wevu_options: componentOptions
1107
- };
1108
- }
1109
- /**
1110
- * 按 Vue 3 风格定义一个小程序页面
1111
- *
1112
- * @param options 页面定义
1113
- * @param features 页面特性(例如 listenPageScroll、enableShareAppMessage 等)
1114
- * @returns 页面定义
1115
1107
  *
1116
1108
  * @example
1117
1109
  * ```ts
1118
- * definePage({
1119
- * data: () => ({ count: 0 }),
1110
+ * defineComponent({
1111
+ * features: { listenPageScroll: true },
1120
1112
  * setup() {
1121
- * const count = ref(0)
1122
- * onMounted(() => console.log('page mounted'))
1123
- * return { count }
1113
+ * onPageScroll(() => {})
1124
1114
  * }
1125
- * }, {
1126
- * listenPageScroll: true,
1127
- * enableShareAppMessage: true
1128
1115
  * })
1129
1116
  * ```
1130
1117
  */
1131
- function definePage(options, features) {
1132
- const { data, computed: computed$1, methods, watch: watch$1, setup, props: _props, ...mpOptions } = options;
1118
+ function defineComponent(options) {
1119
+ const { features, data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
1133
1120
  const runtimeApp = createApp({
1134
1121
  data,
1135
1122
  computed: computed$1,
@@ -1139,19 +1126,18 @@ function definePage(options, features) {
1139
1126
  const result = runSetupFunction(setup, ctx?.props ?? {}, ctx);
1140
1127
  if (result) applySetupResult(ctx.runtime, ctx.instance, result);
1141
1128
  };
1129
+ const mpOptionsWithProps = normalizeProps(mpOptions, props);
1142
1130
  const componentOptions = {
1143
- type: "page",
1144
1131
  data,
1145
1132
  computed: computed$1,
1146
1133
  methods,
1147
1134
  watch: watch$1,
1148
1135
  setup: setupWrapper,
1149
- mpOptions,
1136
+ mpOptions: mpOptionsWithProps,
1150
1137
  features
1151
1138
  };
1152
- registerPage(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptions, features);
1139
+ registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps, features);
1153
1140
  return {
1154
- mount: () => {},
1155
1141
  __wevu_runtime: runtimeApp,
1156
1142
  __wevu_options: componentOptions
1157
1143
  };
@@ -1287,4 +1273,4 @@ function injectGlobal(key, defaultValue) {
1287
1273
  }
1288
1274
 
1289
1275
  //#endregion
1290
- export { callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, definePage, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, registerPage, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
1276
+ export { callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, getCurrentInstance, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onHide, onMounted, onPageScroll, onReady, onRouteDone, onSaveExitState, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
package/dist/store.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-D1r6nN-t.cjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-DVEFI-Uo.cjs";
2
2
  export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
package/dist/store.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-DHBSC7mS.mjs";
1
+ import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-0dF4y5p6.mjs";
2
2
  export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wevu",
3
3
  "type": "module",
4
- "version": "0.0.2-alpha.0",
4
+ "version": "1.0.0-alpha.1",
5
5
  "description": "Vue 3 风格的小程序运行时,包含响应式、diff+setData 与轻量状态管理",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",