wevu 1.0.0-alpha.1 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -4
- package/dist/compiler.cjs +17 -0
- package/dist/compiler.d.cts +17 -0
- package/dist/compiler.d.mts +17 -0
- package/dist/compiler.mjs +16 -0
- package/dist/index.cjs +232 -51
- package/dist/index.d.cts +201 -47
- package/dist/index.d.mts +201 -47
- package/dist/index.mjs +221 -52
- package/dist/{store-Cmw9vWBT.cjs → store-DTqmKv0w.cjs} +136 -13
- package/dist/{store-BcU7YVhB.mjs → store-YHZDsE3y.mjs} +101 -14
- package/dist/store.cjs +1 -1
- package/dist/store.d.cts +1 -1
- package/dist/store.d.mts +1 -1
- package/dist/store.mjs +1 -1
- package/package.json +15 -1
- /package/dist/{index-0dF4y5p6.d.mts → index-B63NgJPS.d.cts} +0 -0
- /package/dist/{index-DVEFI-Uo.d.cts → index-Bq83Mwxo.d.mts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as computed, a as isRef, b as
|
|
1
|
+
import { C as onScopeDispose, D as queueJob, E as nextTick, S as getCurrentScope, T as stop, _ as computed, a as isRef, b as effectScope, c as isObject, d as isShallowReactive, f as markRaw, g as touchReactive, h as toRaw, i as customRef, l as isRaw, m as shallowReactive, n as defineStore, o as ref, p as reactive, r as createStore, s as unref, t as storeToRefs, u as isReactive, v as batch, w as startBatch, x as endBatch, y as effect } from "./store-YHZDsE3y.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/reactivity/readonly.ts
|
|
4
4
|
function readonly(target) {
|
|
@@ -155,10 +155,13 @@ function watch(source, cb, options = {}) {
|
|
|
155
155
|
});
|
|
156
156
|
if (options.immediate) job();
|
|
157
157
|
else oldValue = runner();
|
|
158
|
-
|
|
158
|
+
const stopHandle = () => {
|
|
159
159
|
cleanup?.();
|
|
160
|
+
cleanup = void 0;
|
|
160
161
|
stop(runner);
|
|
161
162
|
};
|
|
163
|
+
onScopeDispose(stopHandle);
|
|
164
|
+
return stopHandle;
|
|
162
165
|
}
|
|
163
166
|
/**
|
|
164
167
|
* watchEffect 注册一个响应式副作用,可选清理函数。
|
|
@@ -173,14 +176,20 @@ function watchEffect(effectFn) {
|
|
|
173
176
|
cleanup?.();
|
|
174
177
|
cleanup = void 0;
|
|
175
178
|
effectFn(onCleanup);
|
|
176
|
-
}, {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
}, {
|
|
180
|
+
lazy: true,
|
|
181
|
+
scheduler: () => queueJob(() => {
|
|
182
|
+
if (runner.active) runner();
|
|
183
|
+
})
|
|
184
|
+
});
|
|
179
185
|
runner();
|
|
180
|
-
|
|
186
|
+
const stopHandle = () => {
|
|
181
187
|
cleanup?.();
|
|
188
|
+
cleanup = void 0;
|
|
182
189
|
stop(runner);
|
|
183
190
|
};
|
|
191
|
+
onScopeDispose(stopHandle);
|
|
192
|
+
return stopHandle;
|
|
184
193
|
}
|
|
185
194
|
|
|
186
195
|
//#endregion
|
|
@@ -283,7 +292,7 @@ function createBindModel(publicInstance, state, computedRefs, computedSetters) {
|
|
|
283
292
|
|
|
284
293
|
//#endregion
|
|
285
294
|
//#region src/runtime/diff.ts
|
|
286
|
-
function isPlainObject(value) {
|
|
295
|
+
function isPlainObject$1(value) {
|
|
287
296
|
if (Object.prototype.toString.call(value) !== "[object Object]") return false;
|
|
288
297
|
const proto = Object.getPrototypeOf(value);
|
|
289
298
|
return proto === null || proto === Object.prototype;
|
|
@@ -311,7 +320,7 @@ function toPlain(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
311
320
|
function isDeepEqual(a, b) {
|
|
312
321
|
if (Object.is(a, b)) return true;
|
|
313
322
|
if (Array.isArray(a) && Array.isArray(b)) return isArrayEqual(a, b);
|
|
314
|
-
if (isPlainObject(a) && isPlainObject(b)) return isPlainObjectEqual(a, b);
|
|
323
|
+
if (isPlainObject$1(a) && isPlainObject$1(b)) return isPlainObjectEqual(a, b);
|
|
315
324
|
return false;
|
|
316
325
|
}
|
|
317
326
|
function isArrayEqual(a, b) {
|
|
@@ -334,7 +343,7 @@ function normalizeSetDataValue(value) {
|
|
|
334
343
|
}
|
|
335
344
|
function assignNestedDiff(prev, next, path, output) {
|
|
336
345
|
if (isDeepEqual(prev, next)) return;
|
|
337
|
-
if (isPlainObject(prev) && isPlainObject(next)) {
|
|
346
|
+
if (isPlainObject$1(prev) && isPlainObject$1(next)) {
|
|
338
347
|
new Set([...Object.keys(prev), ...Object.keys(next)]).forEach((key) => {
|
|
339
348
|
if (!Object.prototype.hasOwnProperty.call(next, key)) {
|
|
340
349
|
output[`${path}.${key}`] = null;
|
|
@@ -428,6 +437,10 @@ function onShow(handler) {
|
|
|
428
437
|
if (!__currentInstance) throw new Error("onShow() must be called synchronously inside setup()");
|
|
429
438
|
pushHook(__currentInstance, "onShow", handler);
|
|
430
439
|
}
|
|
440
|
+
function onLoad(handler) {
|
|
441
|
+
if (!__currentInstance) throw new Error("onLoad() must be called synchronously inside setup()");
|
|
442
|
+
pushHook(__currentInstance, "onLoad", handler);
|
|
443
|
+
}
|
|
431
444
|
function onHide(handler) {
|
|
432
445
|
if (!__currentInstance) throw new Error("onHide() must be called synchronously inside setup()");
|
|
433
446
|
pushHook(__currentInstance, "onHide", handler);
|
|
@@ -440,6 +453,14 @@ function onReady(handler) {
|
|
|
440
453
|
if (!__currentInstance) throw new Error("onReady() must be called synchronously inside setup()");
|
|
441
454
|
pushHook(__currentInstance, "onReady", handler);
|
|
442
455
|
}
|
|
456
|
+
function onPullDownRefresh(handler) {
|
|
457
|
+
if (!__currentInstance) throw new Error("onPullDownRefresh() must be called synchronously inside setup()");
|
|
458
|
+
pushHook(__currentInstance, "onPullDownRefresh", handler);
|
|
459
|
+
}
|
|
460
|
+
function onReachBottom(handler) {
|
|
461
|
+
if (!__currentInstance) throw new Error("onReachBottom() must be called synchronously inside setup()");
|
|
462
|
+
pushHook(__currentInstance, "onReachBottom", handler);
|
|
463
|
+
}
|
|
443
464
|
function onPageScroll(handler) {
|
|
444
465
|
if (!__currentInstance) throw new Error("onPageScroll() must be called synchronously inside setup()");
|
|
445
466
|
pushHook(__currentInstance, "onPageScroll", handler);
|
|
@@ -452,6 +473,18 @@ function onTabItemTap(handler) {
|
|
|
452
473
|
if (!__currentInstance) throw new Error("onTabItemTap() must be called synchronously inside setup()");
|
|
453
474
|
pushHook(__currentInstance, "onTabItemTap", handler);
|
|
454
475
|
}
|
|
476
|
+
function onResize(handler) {
|
|
477
|
+
if (!__currentInstance) throw new Error("onResize() must be called synchronously inside setup()");
|
|
478
|
+
pushHook(__currentInstance, "onResize", handler);
|
|
479
|
+
}
|
|
480
|
+
function onMoved(handler) {
|
|
481
|
+
if (!__currentInstance) throw new Error("onMoved() must be called synchronously inside setup()");
|
|
482
|
+
pushHook(__currentInstance, "onMoved", handler);
|
|
483
|
+
}
|
|
484
|
+
function onError(handler) {
|
|
485
|
+
if (!__currentInstance) throw new Error("onError() must be called synchronously inside setup()");
|
|
486
|
+
pushHook(__currentInstance, "onError", handler);
|
|
487
|
+
}
|
|
455
488
|
function onSaveExitState(handler) {
|
|
456
489
|
if (!__currentInstance) throw new Error("onSaveExitState() must be called synchronously inside setup()");
|
|
457
490
|
pushHook(__currentInstance, "onSaveExitState", handler, { single: true });
|
|
@@ -624,11 +657,35 @@ function registerWatches(runtime, watchMap, instance) {
|
|
|
624
657
|
}
|
|
625
658
|
return stops;
|
|
626
659
|
}
|
|
627
|
-
function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
660
|
+
function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
628
661
|
if (target.__wevu) return target.__wevu;
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
662
|
+
const createDeferredAdapter = (instance) => {
|
|
663
|
+
let pending;
|
|
664
|
+
let enabled = false;
|
|
665
|
+
const adapter$1 = { setData(payload) {
|
|
666
|
+
if (!enabled) {
|
|
667
|
+
pending = {
|
|
668
|
+
...pending ?? {},
|
|
669
|
+
...payload
|
|
670
|
+
};
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (typeof instance.setData === "function") return instance.setData(payload);
|
|
674
|
+
} };
|
|
675
|
+
adapter$1.__wevu_enableSetData = () => {
|
|
676
|
+
enabled = true;
|
|
677
|
+
if (pending && Object.keys(pending).length && typeof instance.setData === "function") {
|
|
678
|
+
const payload = pending;
|
|
679
|
+
pending = void 0;
|
|
680
|
+
instance.setData(payload);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
return adapter$1;
|
|
684
|
+
};
|
|
685
|
+
const adapter = options?.deferSetData ? createDeferredAdapter(target) : { setData(payload) {
|
|
686
|
+
if (typeof target.setData === "function") return target.setData(payload);
|
|
687
|
+
} };
|
|
688
|
+
const runtime = runtimeApp.mount({ ...adapter });
|
|
632
689
|
const runtimeProxy = runtime?.proxy ?? {};
|
|
633
690
|
const runtimeState = runtime?.state ?? {};
|
|
634
691
|
if (!runtime?.methods) try {
|
|
@@ -666,8 +723,8 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
|
666
723
|
bindModel: runtimeBindModel.bind(runtimeWithDefaults),
|
|
667
724
|
watch: runtimeWatch.bind(runtimeWithDefaults),
|
|
668
725
|
instance: target,
|
|
669
|
-
emit: (event,
|
|
670
|
-
if (typeof target.triggerEvent === "function") target.triggerEvent(event,
|
|
726
|
+
emit: (event, detail, options$1) => {
|
|
727
|
+
if (typeof target.triggerEvent === "function") target.triggerEvent(event, detail, options$1);
|
|
671
728
|
},
|
|
672
729
|
expose: (exposed) => {
|
|
673
730
|
target.__wevuExposed = exposed;
|
|
@@ -695,6 +752,10 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
|
695
752
|
} catch {}
|
|
696
753
|
return runtime;
|
|
697
754
|
}
|
|
755
|
+
function enableDeferredSetData(target) {
|
|
756
|
+
const adapter = target.__wevu?.adapter;
|
|
757
|
+
if (adapter && typeof adapter.__wevu_enableSetData === "function") adapter.__wevu_enableSetData();
|
|
758
|
+
}
|
|
698
759
|
function teardownRuntimeInstance(target) {
|
|
699
760
|
const runtime = target.__wevu;
|
|
700
761
|
if (runtime && target.__wevuHooks) callHookList(target, "onUnload", []);
|
|
@@ -734,7 +795,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
734
795
|
if (typeof userOnHide === "function") userOnHide.apply(this, args);
|
|
735
796
|
};
|
|
736
797
|
const userOnError = appOptions.onError;
|
|
737
|
-
appOptions.onError = function onError(...args) {
|
|
798
|
+
appOptions.onError = function onError$1(...args) {
|
|
738
799
|
callHookList(this, "onAppError", args);
|
|
739
800
|
if (typeof userOnError === "function") userOnError.apply(this, args);
|
|
740
801
|
};
|
|
@@ -751,7 +812,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
751
812
|
}
|
|
752
813
|
App(appOptions);
|
|
753
814
|
}
|
|
754
|
-
function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions
|
|
815
|
+
function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
755
816
|
const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, options: userOptions = {}, ...rest } = mpOptions;
|
|
756
817
|
const userOnLoad = rest.onLoad;
|
|
757
818
|
const userOnUnload = rest.onUnload;
|
|
@@ -759,21 +820,68 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
759
820
|
const userOnHide = rest.onHide;
|
|
760
821
|
const userOnReady = rest.onReady;
|
|
761
822
|
const userOnSaveExitState = rest.onSaveExitState;
|
|
823
|
+
const userOnPullDownRefresh = rest.onPullDownRefresh;
|
|
824
|
+
const userOnReachBottom = rest.onReachBottom;
|
|
762
825
|
const userOnPageScroll = rest.onPageScroll;
|
|
826
|
+
const userOnRouteDone = rest.onRouteDone;
|
|
827
|
+
const userOnTabItemTap = rest.onTabItemTap;
|
|
828
|
+
const userOnResize = rest.onResize;
|
|
763
829
|
const userOnShareAppMessage = rest.onShareAppMessage;
|
|
764
830
|
const userOnShareTimeline = rest.onShareTimeline;
|
|
765
831
|
const userOnAddToFavorites = rest.onAddToFavorites;
|
|
832
|
+
const features = rest.features ?? {};
|
|
766
833
|
const restOptions = { ...rest };
|
|
834
|
+
const legacyCreated = restOptions.created;
|
|
835
|
+
delete restOptions.features;
|
|
836
|
+
delete restOptions.created;
|
|
767
837
|
delete restOptions.onLoad;
|
|
768
838
|
delete restOptions.onUnload;
|
|
769
839
|
delete restOptions.onShow;
|
|
770
840
|
delete restOptions.onHide;
|
|
771
841
|
delete restOptions.onReady;
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
842
|
+
const enableOnPullDownRefresh = typeof userOnPullDownRefresh === "function" || Boolean(features.enableOnPullDownRefresh);
|
|
843
|
+
const enableOnReachBottom = typeof userOnReachBottom === "function" || Boolean(features.enableOnReachBottom);
|
|
844
|
+
const enableOnPageScroll = typeof userOnPageScroll === "function" || Boolean(features.enableOnPageScroll);
|
|
845
|
+
const enableOnRouteDone = typeof userOnRouteDone === "function" || Boolean(features.enableOnRouteDone);
|
|
846
|
+
const enableOnTabItemTap = typeof userOnTabItemTap === "function" || Boolean(features.enableOnTabItemTap);
|
|
847
|
+
const enableOnResize = typeof userOnResize === "function" || Boolean(features.enableOnResize);
|
|
848
|
+
const enableOnShareAppMessage = typeof userOnShareAppMessage === "function" || Boolean(features.enableOnShareAppMessage);
|
|
849
|
+
const enableOnShareTimeline = typeof userOnShareTimeline === "function" || Boolean(features.enableOnShareTimeline);
|
|
850
|
+
const enableOnAddToFavorites = typeof userOnAddToFavorites === "function" || Boolean(features.enableOnAddToFavorites);
|
|
851
|
+
const enableOnSaveExitState = typeof userOnSaveExitState === "function" || Boolean(features.enableOnSaveExitState);
|
|
852
|
+
const fallbackNoop = () => {};
|
|
853
|
+
const fallbackShareContent = () => ({});
|
|
854
|
+
const fallbackTimelineContent = () => ({});
|
|
855
|
+
const effectiveOnSaveExitState = typeof userOnSaveExitState === "function" ? userOnSaveExitState : (() => ({ data: void 0 }));
|
|
856
|
+
const effectiveOnPullDownRefresh = typeof userOnPullDownRefresh === "function" ? userOnPullDownRefresh : fallbackNoop;
|
|
857
|
+
const effectiveOnReachBottom = typeof userOnReachBottom === "function" ? userOnReachBottom : fallbackNoop;
|
|
858
|
+
const effectiveOnPageScroll = typeof userOnPageScroll === "function" ? userOnPageScroll : fallbackNoop;
|
|
859
|
+
const effectiveOnRouteDone = typeof userOnRouteDone === "function" ? userOnRouteDone : fallbackNoop;
|
|
860
|
+
const effectiveOnTabItemTap = typeof userOnTabItemTap === "function" ? userOnTabItemTap : fallbackNoop;
|
|
861
|
+
const effectiveOnResize = typeof userOnResize === "function" ? userOnResize : fallbackNoop;
|
|
862
|
+
const effectiveOnShareAppMessage = typeof userOnShareAppMessage === "function" ? userOnShareAppMessage : fallbackShareContent;
|
|
863
|
+
const effectiveOnShareTimeline = typeof userOnShareTimeline === "function" ? userOnShareTimeline : fallbackTimelineContent;
|
|
864
|
+
const effectiveOnAddToFavorites = typeof userOnAddToFavorites === "function" ? userOnAddToFavorites : (() => ({}));
|
|
865
|
+
const hasHook = (target, name) => {
|
|
866
|
+
const hooks = target.__wevuHooks;
|
|
867
|
+
if (!hooks) return false;
|
|
868
|
+
const entry = hooks[name];
|
|
869
|
+
if (!entry) return false;
|
|
870
|
+
if (Array.isArray(entry)) return entry.length > 0;
|
|
871
|
+
return typeof entry === "function";
|
|
872
|
+
};
|
|
873
|
+
{
|
|
874
|
+
const userExport = restOptions.export;
|
|
875
|
+
restOptions.export = function __wevu_export() {
|
|
876
|
+
const exposed = this.__wevuExposed ?? {};
|
|
877
|
+
const base = typeof userExport === "function" ? userExport.call(this) : {};
|
|
878
|
+
if (base && typeof base === "object" && !Array.isArray(base)) return {
|
|
879
|
+
...exposed,
|
|
880
|
+
...base
|
|
881
|
+
};
|
|
882
|
+
return base ?? exposed;
|
|
883
|
+
};
|
|
884
|
+
}
|
|
777
885
|
const finalOptions = {
|
|
778
886
|
multipleSlots: userOptions.multipleSlots ?? true,
|
|
779
887
|
...userOptions
|
|
@@ -795,18 +903,11 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
795
903
|
return result;
|
|
796
904
|
};
|
|
797
905
|
}
|
|
798
|
-
const wrapSpecial = (name) => {
|
|
799
|
-
const user = userLifetimes[name] ?? userPageLifetimes[name];
|
|
800
|
-
finalMethods[name] = function wrapped(...args) {
|
|
801
|
-
callHookList(this, name, args);
|
|
802
|
-
if (typeof user === "function") return user.apply(this, args);
|
|
803
|
-
};
|
|
804
|
-
};
|
|
805
|
-
wrapSpecial("onTabItemTap");
|
|
806
|
-
wrapSpecial("onRouteDone");
|
|
807
906
|
const pageLifecycleHooks = {
|
|
808
907
|
onLoad(...args) {
|
|
809
908
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup);
|
|
909
|
+
enableDeferredSetData(this);
|
|
910
|
+
callHookList(this, "onLoad", args);
|
|
810
911
|
if (typeof userOnLoad === "function") return userOnLoad.apply(this, args);
|
|
811
912
|
},
|
|
812
913
|
onUnload(...args) {
|
|
@@ -827,39 +928,69 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
827
928
|
callHookList(this, "onReady", args);
|
|
828
929
|
}
|
|
829
930
|
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
931
|
}
|
|
836
932
|
};
|
|
837
|
-
if (
|
|
933
|
+
if (enableOnSaveExitState) pageLifecycleHooks.onSaveExitState = function onSaveExitState$1(...args) {
|
|
934
|
+
const ret = callHookReturn(this, "onSaveExitState", args);
|
|
935
|
+
if (ret !== void 0) return ret;
|
|
936
|
+
return effectiveOnSaveExitState.apply(this, args);
|
|
937
|
+
};
|
|
938
|
+
if (enableOnPullDownRefresh) pageLifecycleHooks.onPullDownRefresh = function onPullDownRefresh$1(...args) {
|
|
939
|
+
callHookList(this, "onPullDownRefresh", args);
|
|
940
|
+
if (!hasHook(this, "onPullDownRefresh")) return effectiveOnPullDownRefresh.apply(this, args);
|
|
941
|
+
};
|
|
942
|
+
if (enableOnReachBottom) pageLifecycleHooks.onReachBottom = function onReachBottom$1(...args) {
|
|
943
|
+
callHookList(this, "onReachBottom", args);
|
|
944
|
+
if (!hasHook(this, "onReachBottom")) return effectiveOnReachBottom.apply(this, args);
|
|
945
|
+
};
|
|
946
|
+
if (enableOnPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
|
|
838
947
|
callHookList(this, "onPageScroll", args);
|
|
839
|
-
if (
|
|
948
|
+
if (!hasHook(this, "onPageScroll")) return effectiveOnPageScroll.apply(this, args);
|
|
840
949
|
};
|
|
841
|
-
if (
|
|
950
|
+
if (enableOnRouteDone) pageLifecycleHooks.onRouteDone = function onRouteDone$1(...args) {
|
|
951
|
+
callHookList(this, "onRouteDone", args);
|
|
952
|
+
if (!hasHook(this, "onRouteDone")) return effectiveOnRouteDone.apply(this, args);
|
|
953
|
+
};
|
|
954
|
+
if (enableOnTabItemTap) pageLifecycleHooks.onTabItemTap = function onTabItemTap$1(...args) {
|
|
955
|
+
callHookList(this, "onTabItemTap", args);
|
|
956
|
+
if (!hasHook(this, "onTabItemTap")) return effectiveOnTabItemTap.apply(this, args);
|
|
957
|
+
};
|
|
958
|
+
if (enableOnResize) pageLifecycleHooks.onResize = function onResize$1(...args) {
|
|
959
|
+
callHookList(this, "onResize", args);
|
|
960
|
+
if (!hasHook(this, "onResize")) return effectiveOnResize.apply(this, args);
|
|
961
|
+
};
|
|
962
|
+
if (enableOnShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
|
|
842
963
|
const ret = callHookReturn(this, "onShareAppMessage", args);
|
|
843
964
|
if (ret !== void 0) return ret;
|
|
844
|
-
|
|
965
|
+
return effectiveOnShareAppMessage.apply(this, args);
|
|
845
966
|
};
|
|
846
|
-
if (
|
|
967
|
+
if (enableOnShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
|
|
847
968
|
const ret = callHookReturn(this, "onShareTimeline", args);
|
|
848
969
|
if (ret !== void 0) return ret;
|
|
849
|
-
|
|
970
|
+
return effectiveOnShareTimeline.apply(this, args);
|
|
850
971
|
};
|
|
851
|
-
if (
|
|
972
|
+
if (enableOnAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
|
|
852
973
|
const ret = callHookReturn(this, "onAddToFavorites", args);
|
|
853
974
|
if (ret !== void 0) return ret;
|
|
854
|
-
|
|
975
|
+
return effectiveOnAddToFavorites.apply(this, args);
|
|
855
976
|
};
|
|
856
977
|
Component({
|
|
857
978
|
...restOptions,
|
|
858
979
|
...pageLifecycleHooks,
|
|
859
980
|
lifetimes: {
|
|
860
981
|
...userLifetimes,
|
|
982
|
+
created: function created(...args) {
|
|
983
|
+
mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
|
|
984
|
+
if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
|
|
985
|
+
if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
|
|
986
|
+
},
|
|
987
|
+
moved: function moved(...args) {
|
|
988
|
+
callHookList(this, "onMoved", args);
|
|
989
|
+
if (typeof userLifetimes.moved === "function") userLifetimes.moved.apply(this, args);
|
|
990
|
+
},
|
|
861
991
|
attached: function attached(...args) {
|
|
862
992
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup);
|
|
993
|
+
enableDeferredSetData(this);
|
|
863
994
|
if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
|
|
864
995
|
},
|
|
865
996
|
ready: function ready(...args) {
|
|
@@ -872,6 +1003,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
872
1003
|
detached: function detached(...args) {
|
|
873
1004
|
teardownRuntimeInstance(this);
|
|
874
1005
|
if (typeof userLifetimes.detached === "function") userLifetimes.detached.apply(this, args);
|
|
1006
|
+
},
|
|
1007
|
+
error: function error(...args) {
|
|
1008
|
+
callHookList(this, "onError", args);
|
|
1009
|
+
if (typeof userLifetimes.error === "function") userLifetimes.error.apply(this, args);
|
|
875
1010
|
}
|
|
876
1011
|
},
|
|
877
1012
|
pageLifetimes: {
|
|
@@ -883,6 +1018,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
883
1018
|
hide: function hide(...args) {
|
|
884
1019
|
callHookList(this, "onHide", args);
|
|
885
1020
|
if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
|
|
1021
|
+
},
|
|
1022
|
+
resize: function resize(...args) {
|
|
1023
|
+
callHookList(this, "onResize", args);
|
|
1024
|
+
if (typeof userPageLifetimes.resize === "function") userPageLifetimes.resize.apply(this, args);
|
|
886
1025
|
}
|
|
887
1026
|
},
|
|
888
1027
|
methods: finalMethods,
|
|
@@ -1009,6 +1148,7 @@ function createApp(options) {
|
|
|
1009
1148
|
};
|
|
1010
1149
|
const job = () => {
|
|
1011
1150
|
if (!mounted) return;
|
|
1151
|
+
tracker();
|
|
1012
1152
|
const snapshot = collectSnapshot();
|
|
1013
1153
|
const diff = diffSnapshots(latestSnapshot, snapshot);
|
|
1014
1154
|
latestSnapshot = snapshot;
|
|
@@ -1018,10 +1158,18 @@ function createApp(options) {
|
|
|
1018
1158
|
if (result && typeof result.then === "function") result.catch(() => {});
|
|
1019
1159
|
}
|
|
1020
1160
|
};
|
|
1021
|
-
|
|
1161
|
+
let tracker;
|
|
1162
|
+
tracker = effect(() => {
|
|
1022
1163
|
touchReactive(state);
|
|
1164
|
+
Object.keys(state).forEach((key) => {
|
|
1165
|
+
const v = state[key];
|
|
1166
|
+
if (isRef(v)) v.value;
|
|
1167
|
+
});
|
|
1023
1168
|
Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
|
|
1024
|
-
}, {
|
|
1169
|
+
}, {
|
|
1170
|
+
lazy: true,
|
|
1171
|
+
scheduler: () => queueJob(job)
|
|
1172
|
+
});
|
|
1025
1173
|
job();
|
|
1026
1174
|
stopHandles.push(() => stop(tracker));
|
|
1027
1175
|
function registerWatch(source, cb, watchOptions) {
|
|
@@ -1108,7 +1256,6 @@ function setComputedValue(setters, key, value) {
|
|
|
1108
1256
|
* @example
|
|
1109
1257
|
* ```ts
|
|
1110
1258
|
* defineComponent({
|
|
1111
|
-
* features: { listenPageScroll: true },
|
|
1112
1259
|
* setup() {
|
|
1113
1260
|
* onPageScroll(() => {})
|
|
1114
1261
|
* }
|
|
@@ -1116,7 +1263,7 @@ function setComputedValue(setters, key, value) {
|
|
|
1116
1263
|
* ```
|
|
1117
1264
|
*/
|
|
1118
1265
|
function defineComponent(options) {
|
|
1119
|
-
const {
|
|
1266
|
+
const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
|
|
1120
1267
|
const runtimeApp = createApp({
|
|
1121
1268
|
data,
|
|
1122
1269
|
computed: computed$1,
|
|
@@ -1133,10 +1280,9 @@ function defineComponent(options) {
|
|
|
1133
1280
|
methods,
|
|
1134
1281
|
watch: watch$1,
|
|
1135
1282
|
setup: setupWrapper,
|
|
1136
|
-
mpOptions: mpOptionsWithProps
|
|
1137
|
-
features
|
|
1283
|
+
mpOptions: mpOptionsWithProps
|
|
1138
1284
|
};
|
|
1139
|
-
registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps
|
|
1285
|
+
registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
|
|
1140
1286
|
return {
|
|
1141
1287
|
__wevu_runtime: runtimeApp,
|
|
1142
1288
|
__wevu_options: componentOptions
|
|
@@ -1145,6 +1291,7 @@ function defineComponent(options) {
|
|
|
1145
1291
|
function applySetupResult(runtime, _target, result) {
|
|
1146
1292
|
const methods = runtime?.methods ?? Object.create(null);
|
|
1147
1293
|
const state = runtime?.state ?? Object.create(null);
|
|
1294
|
+
const rawState = isReactive(state) ? toRaw(state) : state;
|
|
1148
1295
|
if (runtime && !runtime.methods) try {
|
|
1149
1296
|
runtime.methods = methods;
|
|
1150
1297
|
} catch {}
|
|
@@ -1154,6 +1301,16 @@ function applySetupResult(runtime, _target, result) {
|
|
|
1154
1301
|
Object.keys(result).forEach((key) => {
|
|
1155
1302
|
const val = result[key];
|
|
1156
1303
|
if (typeof val === "function") methods[key] = (...args) => val.apply(runtime?.proxy ?? runtime, args);
|
|
1304
|
+
else if (val === _target || !shouldExposeInSnapshot(val)) try {
|
|
1305
|
+
Object.defineProperty(rawState, key, {
|
|
1306
|
+
value: val,
|
|
1307
|
+
configurable: true,
|
|
1308
|
+
enumerable: false,
|
|
1309
|
+
writable: true
|
|
1310
|
+
});
|
|
1311
|
+
} catch {
|
|
1312
|
+
state[key] = val;
|
|
1313
|
+
}
|
|
1157
1314
|
else state[key] = val;
|
|
1158
1315
|
});
|
|
1159
1316
|
if (runtime) {
|
|
@@ -1161,6 +1318,18 @@ function applySetupResult(runtime, _target, result) {
|
|
|
1161
1318
|
runtime.state = runtime.state ?? state;
|
|
1162
1319
|
}
|
|
1163
1320
|
}
|
|
1321
|
+
function isPlainObject(value) {
|
|
1322
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") return false;
|
|
1323
|
+
const proto = Object.getPrototypeOf(value);
|
|
1324
|
+
return proto === null || proto === Object.prototype;
|
|
1325
|
+
}
|
|
1326
|
+
function shouldExposeInSnapshot(value) {
|
|
1327
|
+
if (value == null) return true;
|
|
1328
|
+
if (typeof value !== "object") return true;
|
|
1329
|
+
if (isRef(value) || isReactive(value)) return true;
|
|
1330
|
+
if (Array.isArray(value)) return true;
|
|
1331
|
+
return isPlainObject(value);
|
|
1332
|
+
}
|
|
1164
1333
|
/**
|
|
1165
1334
|
* 从 Vue SFC 选项创建 wevu 组件,供 weapp-vite 编译产物直接调用的兼容入口。
|
|
1166
1335
|
*
|
|
@@ -1273,4 +1442,4 @@ function injectGlobal(key, defaultValue) {
|
|
|
1273
1442
|
}
|
|
1274
1443
|
|
|
1275
1444
|
//#endregion
|
|
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 };
|
|
1445
|
+
export { batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mountRuntimeInstance, nextTick, onActivated, onAddToFavorites, onAppError, onAppHide, onAppShow, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLoad, onMounted, onMoved, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onScopeDispose, onServerPrefetch, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onUnload, onUnmounted, onUpdated, provide, provideGlobal, reactive, readonly, ref, registerApp, registerComponent, runSetupFunction, setCurrentInstance, setDeepWatchStrategy, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, watch, watchEffect };
|