wevu 1.0.0-alpha.3 → 1.0.0-alpha.5

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.mjs CHANGED
@@ -1,5 +1,485 @@
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";
1
+ //#region src/scheduler.ts
2
+ const resolvedPromise = Promise.resolve();
3
+ const jobQueue = /* @__PURE__ */ new Set();
4
+ let isFlushing = false;
5
+ function flushJobs() {
6
+ isFlushing = true;
7
+ try {
8
+ jobQueue.forEach((job) => job());
9
+ } finally {
10
+ jobQueue.clear();
11
+ isFlushing = false;
12
+ }
13
+ }
14
+ function queueJob(job) {
15
+ jobQueue.add(job);
16
+ if (!isFlushing) resolvedPromise.then(flushJobs);
17
+ }
18
+ function nextTick(fn) {
19
+ return fn ? resolvedPromise.then(fn) : resolvedPromise;
20
+ }
21
+
22
+ //#endregion
23
+ //#region src/reactivity/core.ts
24
+ const targetMap = /* @__PURE__ */ new WeakMap();
25
+ let activeEffect = null;
26
+ const effectStack = [];
27
+ let batchDepth = 0;
28
+ const batchedEffects = /* @__PURE__ */ new Set();
29
+ function startBatch() {
30
+ batchDepth++;
31
+ }
32
+ function endBatch() {
33
+ if (batchDepth === 0) return;
34
+ batchDepth--;
35
+ if (batchDepth === 0) flushBatchedEffects();
36
+ }
37
+ function batch(fn) {
38
+ startBatch();
39
+ try {
40
+ return fn();
41
+ } finally {
42
+ endBatch();
43
+ }
44
+ }
45
+ function flushBatchedEffects() {
46
+ while (batchedEffects.size) {
47
+ const effects = Array.from(batchedEffects);
48
+ batchedEffects.clear();
49
+ for (const ef of effects) ef();
50
+ }
51
+ }
52
+ let activeEffectScope;
53
+ var EffectScopeImpl = class {
54
+ active = true;
55
+ effects = [];
56
+ cleanups = [];
57
+ parent;
58
+ scopes;
59
+ constructor(detached = false) {
60
+ this.detached = detached;
61
+ if (!detached && activeEffectScope) {
62
+ this.parent = activeEffectScope;
63
+ (activeEffectScope.scopes ||= []).push(this);
64
+ }
65
+ }
66
+ run(fn) {
67
+ if (!this.active) return;
68
+ const prev = activeEffectScope;
69
+ activeEffectScope = this;
70
+ try {
71
+ return fn();
72
+ } finally {
73
+ activeEffectScope = prev;
74
+ }
75
+ }
76
+ stop() {
77
+ if (!this.active) return;
78
+ this.active = false;
79
+ for (const effect$1 of this.effects) stop(effect$1);
80
+ this.effects.length = 0;
81
+ for (const cleanup of this.cleanups) cleanup();
82
+ this.cleanups.length = 0;
83
+ if (this.scopes) {
84
+ for (const scope of this.scopes) scope.stop();
85
+ this.scopes.length = 0;
86
+ }
87
+ if (this.parent?.scopes) {
88
+ const index = this.parent.scopes.indexOf(this);
89
+ if (index >= 0) this.parent.scopes.splice(index, 1);
90
+ }
91
+ this.parent = void 0;
92
+ }
93
+ };
94
+ function effectScope(detached = false) {
95
+ return new EffectScopeImpl(detached);
96
+ }
97
+ function getCurrentScope() {
98
+ return activeEffectScope;
99
+ }
100
+ function onScopeDispose(fn) {
101
+ if (activeEffectScope?.active) activeEffectScope.cleanups.push(fn);
102
+ }
103
+ function recordEffectScope(effect$1) {
104
+ if (activeEffectScope?.active) activeEffectScope.effects.push(effect$1);
105
+ }
106
+ function cleanupEffect(effect$1) {
107
+ const { deps } = effect$1;
108
+ for (let i = 0; i < deps.length; i++) deps[i].delete(effect$1);
109
+ deps.length = 0;
110
+ }
111
+ function createReactiveEffect(fn, options = {}) {
112
+ const effect$1 = function reactiveEffect() {
113
+ if (!effect$1.active) return fn();
114
+ if (effect$1._running) return fn();
115
+ cleanupEffect(effect$1);
116
+ try {
117
+ effect$1._running = true;
118
+ effectStack.push(effect$1);
119
+ activeEffect = effect$1;
120
+ return fn();
121
+ } finally {
122
+ effectStack.pop();
123
+ activeEffect = effectStack[effectStack.length - 1] ?? null;
124
+ effect$1._running = false;
125
+ }
126
+ };
127
+ effect$1.deps = [];
128
+ effect$1.scheduler = options.scheduler;
129
+ effect$1.onStop = options.onStop;
130
+ effect$1.active = true;
131
+ effect$1._running = false;
132
+ effect$1._fn = fn;
133
+ return effect$1;
134
+ }
135
+ function effect(fn, options = {}) {
136
+ const _effect = createReactiveEffect(fn, options);
137
+ recordEffectScope(_effect);
138
+ if (!options.lazy) _effect();
139
+ return _effect;
140
+ }
141
+ function stop(runner) {
142
+ if (!runner.active) return;
143
+ runner.active = false;
144
+ cleanupEffect(runner);
145
+ runner.onStop?.();
146
+ }
147
+ function track(target, key) {
148
+ if (!activeEffect) return;
149
+ let depsMap = targetMap.get(target);
150
+ if (!depsMap) {
151
+ depsMap = /* @__PURE__ */ new Map();
152
+ targetMap.set(target, depsMap);
153
+ }
154
+ let dep = depsMap.get(key);
155
+ if (!dep) {
156
+ dep = /* @__PURE__ */ new Set();
157
+ depsMap.set(key, dep);
158
+ }
159
+ if (!dep.has(activeEffect)) {
160
+ dep.add(activeEffect);
161
+ activeEffect.deps.push(dep);
162
+ }
163
+ }
164
+ function trigger(target, key) {
165
+ const depsMap = targetMap.get(target);
166
+ if (!depsMap) return;
167
+ const effects = depsMap.get(key);
168
+ if (!effects) return;
169
+ const effectsToRun = /* @__PURE__ */ new Set();
170
+ effects.forEach((ef) => {
171
+ if (ef !== activeEffect) effectsToRun.add(ef);
172
+ });
173
+ effectsToRun.forEach(scheduleEffect);
174
+ }
175
+ function trackEffects(dep) {
176
+ if (!activeEffect) return;
177
+ if (!dep.has(activeEffect)) {
178
+ dep.add(activeEffect);
179
+ activeEffect.deps.push(dep);
180
+ }
181
+ }
182
+ function triggerEffects(dep) {
183
+ dep.forEach(scheduleEffect);
184
+ }
185
+ function scheduleEffect(ef) {
186
+ if (ef.scheduler) {
187
+ ef.scheduler();
188
+ return;
189
+ }
190
+ if (batchDepth > 0) {
191
+ batchedEffects.add(ef);
192
+ return;
193
+ }
194
+ ef();
195
+ }
196
+
197
+ //#endregion
198
+ //#region src/reactivity/computed.ts
199
+ function computed(getterOrOptions) {
200
+ let getter;
201
+ let setter;
202
+ const onlyGetter = typeof getterOrOptions === "function";
203
+ if (onlyGetter) {
204
+ getter = getterOrOptions;
205
+ setter = () => {
206
+ throw new Error("Computed value is readonly");
207
+ };
208
+ } else {
209
+ getter = getterOrOptions.get;
210
+ setter = getterOrOptions.set;
211
+ }
212
+ let value;
213
+ let dirty = true;
214
+ let runner;
215
+ const obj = {
216
+ get value() {
217
+ if (dirty) {
218
+ value = runner();
219
+ dirty = false;
220
+ }
221
+ track(obj, "value");
222
+ return value;
223
+ },
224
+ set value(newValue) {
225
+ setter(newValue);
226
+ }
227
+ };
228
+ runner = effect(getter, {
229
+ lazy: true,
230
+ scheduler: () => {
231
+ if (!dirty) {
232
+ dirty = true;
233
+ trigger(obj, "value");
234
+ }
235
+ }
236
+ });
237
+ return onlyGetter ? obj : obj;
238
+ }
239
+
240
+ //#endregion
241
+ //#region src/reactivity/reactive.ts
242
+ const reactiveMap = /* @__PURE__ */ new WeakMap();
243
+ const rawMap = /* @__PURE__ */ new WeakMap();
244
+ const rawRootMap = /* @__PURE__ */ new WeakMap();
245
+ let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags$1) {
246
+ ReactiveFlags$1["IS_REACTIVE"] = "__r_isReactive";
247
+ ReactiveFlags$1["RAW"] = "__r_raw";
248
+ ReactiveFlags$1["SKIP"] = "__r_skip";
249
+ return ReactiveFlags$1;
250
+ }({});
251
+ function isObject$1(value) {
252
+ return typeof value === "object" && value !== null;
253
+ }
254
+ const VERSION_KEY = Symbol("wevu.version");
255
+ const mutableHandlers = {
256
+ get(target, key, receiver) {
257
+ if (key === ReactiveFlags.IS_REACTIVE) return true;
258
+ if (key === ReactiveFlags.RAW) return target;
259
+ const res = Reflect.get(target, key, receiver);
260
+ track(target, key);
261
+ if (isObject$1(res)) {
262
+ if (res[ReactiveFlags.SKIP]) return res;
263
+ const child = res;
264
+ const parentRoot = rawRootMap.get(target) ?? target;
265
+ if (!rawRootMap.has(child)) rawRootMap.set(child, parentRoot);
266
+ return reactive(res);
267
+ }
268
+ return res;
269
+ },
270
+ set(target, key, value, receiver) {
271
+ const oldValue = Reflect.get(target, key, receiver);
272
+ const result = Reflect.set(target, key, value, receiver);
273
+ if (!Object.is(oldValue, value)) {
274
+ trigger(target, key);
275
+ trigger(target, VERSION_KEY);
276
+ const root = rawRootMap.get(target);
277
+ if (root && root !== target) trigger(root, VERSION_KEY);
278
+ }
279
+ return result;
280
+ },
281
+ deleteProperty(target, key) {
282
+ const hadKey = Object.prototype.hasOwnProperty.call(target, key);
283
+ const result = Reflect.deleteProperty(target, key);
284
+ if (hadKey && result) {
285
+ trigger(target, key);
286
+ trigger(target, VERSION_KEY);
287
+ const root = rawRootMap.get(target);
288
+ if (root && root !== target) trigger(root, VERSION_KEY);
289
+ }
290
+ return result;
291
+ },
292
+ ownKeys(target) {
293
+ track(target, Symbol.iterator);
294
+ track(target, VERSION_KEY);
295
+ return Reflect.ownKeys(target);
296
+ }
297
+ };
298
+ function reactive(target) {
299
+ if (!isObject$1(target)) return target;
300
+ const existingProxy = reactiveMap.get(target);
301
+ if (existingProxy) return existingProxy;
302
+ if (target[ReactiveFlags.IS_REACTIVE]) return target;
303
+ const proxy = new Proxy(target, mutableHandlers);
304
+ reactiveMap.set(target, proxy);
305
+ rawMap.set(proxy, target);
306
+ if (!rawRootMap.has(target)) rawRootMap.set(target, target);
307
+ return proxy;
308
+ }
309
+ function isReactive(value) {
310
+ return Boolean(value && value[ReactiveFlags.IS_REACTIVE]);
311
+ }
312
+ function toRaw(observed) {
313
+ return observed?.[ReactiveFlags.RAW] ?? observed;
314
+ }
315
+ function convertToReactive(value) {
316
+ return isObject$1(value) ? reactive(value) : value;
317
+ }
318
+ /**
319
+ * 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
320
+ */
321
+ function touchReactive(target) {
322
+ track(toRaw(target), VERSION_KEY);
323
+ }
324
+ const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
325
+ const shallowHandlers = {
326
+ get(target, key, receiver) {
327
+ if (key === ReactiveFlags.IS_REACTIVE) return true;
328
+ if (key === ReactiveFlags.RAW) return target;
329
+ const res = Reflect.get(target, key, receiver);
330
+ track(target, key);
331
+ return res;
332
+ },
333
+ set(target, key, value, receiver) {
334
+ const oldValue = Reflect.get(target, key, receiver);
335
+ const result = Reflect.set(target, key, value, receiver);
336
+ if (!Object.is(oldValue, value)) {
337
+ trigger(target, key);
338
+ trigger(target, VERSION_KEY);
339
+ }
340
+ return result;
341
+ },
342
+ deleteProperty(target, key) {
343
+ const hadKey = Object.prototype.hasOwnProperty.call(target, key);
344
+ const result = Reflect.deleteProperty(target, key);
345
+ if (hadKey && result) {
346
+ trigger(target, key);
347
+ trigger(target, VERSION_KEY);
348
+ }
349
+ return result;
350
+ },
351
+ ownKeys(target) {
352
+ track(target, Symbol.iterator);
353
+ track(target, VERSION_KEY);
354
+ return Reflect.ownKeys(target);
355
+ }
356
+ };
357
+ /**
358
+ * 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
359
+ *
360
+ * @param target 待转换的对象
361
+ * @returns 浅层响应式代理
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * const state = shallowReactive({ nested: { count: 0 } })
366
+ *
367
+ * state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
368
+ * state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
369
+ * ```
370
+ */
371
+ function shallowReactive(target) {
372
+ if (!isObject$1(target)) return target;
373
+ const existingProxy = shallowReactiveMap.get(target);
374
+ if (existingProxy) return existingProxy;
375
+ if (target[ReactiveFlags.IS_REACTIVE]) return target;
376
+ const proxy = new Proxy(target, shallowHandlers);
377
+ shallowReactiveMap.set(target, proxy);
378
+ rawMap.set(proxy, target);
379
+ return proxy;
380
+ }
381
+ /**
382
+ * 判断一个值是否为 shallowReactive 创建的浅层响应式对象
383
+ */
384
+ function isShallowReactive(value) {
385
+ const raw = toRaw(value);
386
+ return shallowReactiveMap.has(raw);
387
+ }
388
+ /**
389
+ * 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
390
+ *
391
+ * @param value 需要标记的对象
392
+ * @returns 带有跳过标记的原对象
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const foo = markRaw({
397
+ * nested: {}
398
+ * })
399
+ *
400
+ * const state = reactive({
401
+ * foo
402
+ * })
403
+ *
404
+ * state.foo // 不是响应式对象
405
+ * ```
406
+ */
407
+ function markRaw(value) {
408
+ if (!isObject$1(value)) return value;
409
+ Object.defineProperty(value, ReactiveFlags.SKIP, {
410
+ value: true,
411
+ configurable: true,
412
+ enumerable: false,
413
+ writable: true
414
+ });
415
+ return value;
416
+ }
417
+ /**
418
+ * 判断某个值是否被标记为原始(即不应转换为响应式)。
419
+ *
420
+ * @param value 待检测的值
421
+ * @returns 若含有跳过标记则返回 true
422
+ */
423
+ function isRaw(value) {
424
+ return isObject$1(value) && ReactiveFlags.SKIP in value;
425
+ }
426
+
427
+ //#endregion
428
+ //#region src/reactivity/ref.ts
429
+ function isRef(value) {
430
+ return Boolean(value && typeof value === "object" && "value" in value);
431
+ }
432
+ var RefImpl = class {
433
+ _value;
434
+ _rawValue;
435
+ dep;
436
+ constructor(value) {
437
+ this._rawValue = value;
438
+ this._value = convertToReactive(value);
439
+ }
440
+ get value() {
441
+ if (!this.dep) this.dep = /* @__PURE__ */ new Set();
442
+ trackEffects(this.dep);
443
+ return this._value;
444
+ }
445
+ set value(newValue) {
446
+ if (!Object.is(newValue, this._rawValue)) {
447
+ this._rawValue = newValue;
448
+ this._value = convertToReactive(newValue);
449
+ if (this.dep) triggerEffects(this.dep);
450
+ }
451
+ }
452
+ };
453
+ function ref(value) {
454
+ if (isRef(value)) return value;
455
+ return markRaw(new RefImpl(value));
456
+ }
457
+ function unref(value) {
458
+ return isRef(value) ? value.value : value;
459
+ }
460
+ var CustomRefImpl = class {
461
+ _value;
462
+ _factory;
463
+ dep;
464
+ constructor(factory, defaultValue) {
465
+ this._factory = factory;
466
+ this._value = defaultValue;
467
+ }
468
+ get value() {
469
+ if (!this.dep) this.dep = /* @__PURE__ */ new Set();
470
+ trackEffects(this.dep);
471
+ return this._factory.get();
472
+ }
473
+ set value(newValue) {
474
+ this._factory.set(newValue);
475
+ if (this.dep) triggerEffects(this.dep);
476
+ }
477
+ };
478
+ function customRef(factory, defaultValue) {
479
+ return markRaw(new CustomRefImpl(factory, defaultValue));
480
+ }
2
481
 
482
+ //#endregion
3
483
  //#region src/reactivity/readonly.ts
4
484
  function readonly(target) {
5
485
  if (isRef(target)) {
@@ -13,7 +493,7 @@ function readonly(target) {
13
493
  }
14
494
  };
15
495
  }
16
- if (!isObject(target)) return target;
496
+ if (!isObject$1(target)) return target;
17
497
  return new Proxy(target, {
18
498
  set() {
19
499
  throw new Error("Cannot set property on readonly object");
@@ -33,15 +513,15 @@ function readonly(target) {
33
513
  //#endregion
34
514
  //#region src/reactivity/shallowRef.ts
35
515
  function shallowRef(value, defaultValue) {
36
- return customRef((track, trigger) => ({
516
+ return customRef((track$1, trigger$1) => ({
37
517
  get() {
38
- track();
518
+ track$1();
39
519
  return value;
40
520
  },
41
521
  set(newValue) {
42
522
  if (Object.is(value, newValue)) return;
43
523
  value = newValue;
44
- trigger();
524
+ trigger$1();
45
525
  }
46
526
  }), defaultValue);
47
527
  }
@@ -89,14 +569,14 @@ function toRefs(object) {
89
569
  function toRef(object, key, defaultValue) {
90
570
  const value = object[key];
91
571
  if (isRef(value)) return value;
92
- return customRef((track, trigger) => ({
572
+ return customRef((track$1, trigger$1) => ({
93
573
  get() {
94
- track();
574
+ track$1();
95
575
  return object[key];
96
576
  },
97
577
  set(newValue) {
98
578
  object[key] = newValue;
99
- trigger();
579
+ trigger$1();
100
580
  }
101
581
  }), defaultValue);
102
582
  }
@@ -104,7 +584,7 @@ function toRef(object, key, defaultValue) {
104
584
  //#endregion
105
585
  //#region src/reactivity/traverse.ts
106
586
  function traverse(value, seen = /* @__PURE__ */ new Set()) {
107
- if (!isObject(value) || seen.has(value)) return value;
587
+ if (!isObject$1(value) || seen.has(value)) return value;
108
588
  seen.add(value);
109
589
  for (const key in value) traverse(value[key], seen);
110
590
  return value;
@@ -224,7 +704,11 @@ function setByPath(state, computedRefs, computedSetters, segments, value) {
224
704
  const [head, ...rest] = segments;
225
705
  if (!rest.length) {
226
706
  if (computedRefs[head]) setComputedValue$1(computedSetters, head, value);
227
- else state[head] = value;
707
+ else {
708
+ const current = state[head];
709
+ if (isRef(current)) current.value = value;
710
+ else state[head] = value;
711
+ }
228
712
  return;
229
713
  }
230
714
  if (computedRefs[head]) {
@@ -374,12 +858,19 @@ function diffSnapshots(prev, next) {
374
858
  //#endregion
375
859
  //#region src/runtime/hooks.ts
376
860
  let __currentInstance;
861
+ let __currentSetupContext;
377
862
  function getCurrentInstance() {
378
863
  return __currentInstance;
379
864
  }
380
865
  function setCurrentInstance(inst) {
381
866
  __currentInstance = inst;
382
867
  }
868
+ function getCurrentSetupContext() {
869
+ return __currentSetupContext;
870
+ }
871
+ function setCurrentSetupContext(ctx) {
872
+ __currentSetupContext = ctx;
873
+ }
383
874
  function ensureHookBucket(target) {
384
875
  if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
385
876
  return target.__wevuHooks;
@@ -579,6 +1070,17 @@ function callUpdateHooks(target, phase) {
579
1070
 
580
1071
  //#endregion
581
1072
  //#region src/runtime/register.ts
1073
+ function decodeWxmlEntities(value) {
1074
+ return value.replace(/&amp;/g, "&").replace(/&quot;/g, "\"").replace(/&#34;/g, "\"").replace(/&apos;/g, "'").replace(/&#39;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
1075
+ }
1076
+ function parseModelEventValue(event) {
1077
+ if (event == null) return event;
1078
+ if (typeof event === "object") {
1079
+ if ("detail" in event && event.detail && "value" in event.detail) return event.detail.value;
1080
+ if ("target" in event && event.target && "value" in event.target) return event.target.value;
1081
+ }
1082
+ return event;
1083
+ }
582
1084
  function runInlineExpression(ctx, expr, event) {
583
1085
  const handlerName = typeof expr === "string" ? expr : void 0;
584
1086
  if (!handlerName) return;
@@ -587,8 +1089,13 @@ function runInlineExpression(ctx, expr, event) {
587
1089
  if (typeof argsRaw === "string") try {
588
1090
  args = JSON.parse(argsRaw);
589
1091
  } catch {
590
- args = [];
1092
+ try {
1093
+ args = JSON.parse(decodeWxmlEntities(argsRaw));
1094
+ } catch {
1095
+ args = [];
1096
+ }
591
1097
  }
1098
+ if (!Array.isArray(args)) args = [];
592
1099
  const resolvedArgs = args.map((item) => item === "$event" ? event : item);
593
1100
  const handler = ctx?.[handlerName];
594
1101
  if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
@@ -714,7 +1221,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
714
1221
  if (stops.length) target.__wevuWatchStops = stops;
715
1222
  }
716
1223
  if (setup) {
717
- const props = target.properties || {};
1224
+ const props = shallowReactive({ ...target.properties || {} });
1225
+ try {
1226
+ Object.defineProperty(target, "__wevuProps", {
1227
+ value: props,
1228
+ configurable: true,
1229
+ enumerable: false,
1230
+ writable: false
1231
+ });
1232
+ } catch {
1233
+ target.__wevuProps = props;
1234
+ }
718
1235
  const context = {
719
1236
  props,
720
1237
  runtime: runtimeWithDefaults,
@@ -729,9 +1246,11 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
729
1246
  expose: (exposed) => {
730
1247
  target.__wevuExposed = exposed;
731
1248
  },
732
- attrs: {}
1249
+ attrs: {},
1250
+ slots: Object.create(null)
733
1251
  };
734
1252
  setCurrentInstance(target);
1253
+ setCurrentSetupContext(context);
735
1254
  try {
736
1255
  const result = runSetupFunction(setup, props, context);
737
1256
  if (result && typeof result === "object") Object.keys(result).forEach((key) => {
@@ -740,6 +1259,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
740
1259
  else runtime.state[key] = val;
741
1260
  });
742
1261
  } finally {
1262
+ setCurrentSetupContext(void 0);
743
1263
  setCurrentInstance(void 0);
744
1264
  }
745
1265
  }
@@ -831,6 +1351,7 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
831
1351
  const userOnAddToFavorites = rest.onAddToFavorites;
832
1352
  const features = rest.features ?? {};
833
1353
  const restOptions = { ...rest };
1354
+ const userObservers = restOptions.observers;
834
1355
  const legacyCreated = restOptions.created;
835
1356
  delete restOptions.features;
836
1357
  delete restOptions.created;
@@ -886,11 +1407,56 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
886
1407
  multipleSlots: userOptions.multipleSlots ?? true,
887
1408
  ...userOptions
888
1409
  };
1410
+ const syncWevuPropsFromInstance = (instance) => {
1411
+ const propsProxy = instance.__wevuProps;
1412
+ const properties = instance.properties;
1413
+ if (!propsProxy || typeof propsProxy !== "object") return;
1414
+ if (!properties || typeof properties !== "object") return;
1415
+ const next = properties;
1416
+ const currentKeys = Object.keys(propsProxy);
1417
+ for (const existingKey of currentKeys) if (!Object.prototype.hasOwnProperty.call(next, existingKey)) try {
1418
+ delete propsProxy[existingKey];
1419
+ } catch {}
1420
+ for (const [k, v] of Object.entries(next)) try {
1421
+ propsProxy[k] = v;
1422
+ } catch {}
1423
+ };
1424
+ const syncWevuPropValue = (instance, key, value) => {
1425
+ const propsProxy = instance.__wevuProps;
1426
+ if (!propsProxy || typeof propsProxy !== "object") return;
1427
+ try {
1428
+ propsProxy[key] = value;
1429
+ } catch {}
1430
+ };
1431
+ const propKeys = restOptions.properties && typeof restOptions.properties === "object" ? Object.keys(restOptions.properties) : [];
1432
+ const injectedObservers = {};
1433
+ if (propKeys.length) for (const key of propKeys) injectedObservers[key] = function __wevu_prop_observer(newValue) {
1434
+ syncWevuPropValue(this, key, newValue);
1435
+ };
1436
+ const finalObservers = { ...userObservers ?? {} };
1437
+ for (const [key, injected] of Object.entries(injectedObservers)) {
1438
+ const existing = finalObservers[key];
1439
+ if (typeof existing === "function") finalObservers[key] = function chainedObserver(...args) {
1440
+ existing.apply(this, args);
1441
+ injected.apply(this, args);
1442
+ };
1443
+ else finalObservers[key] = injected;
1444
+ }
889
1445
  const finalMethods = { ...userMethods };
890
1446
  if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
891
1447
  const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
892
1448
  return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
893
1449
  };
1450
+ if (!finalMethods.__weapp_vite_model) finalMethods.__weapp_vite_model = function __weapp_vite_model(event) {
1451
+ const path = event?.currentTarget?.dataset?.wvModel ?? event?.target?.dataset?.wvModel;
1452
+ if (typeof path !== "string" || !path) return;
1453
+ const runtime = this.__wevu;
1454
+ if (!runtime || typeof runtime.bindModel !== "function") return;
1455
+ const value = parseModelEventValue(event);
1456
+ try {
1457
+ runtime.bindModel(path).update(value);
1458
+ } catch {}
1459
+ };
894
1460
  const methodNames = Object.keys(methods ?? {});
895
1461
  for (const methodName of methodNames) {
896
1462
  const userMethod = finalMethods[methodName];
@@ -977,10 +1543,12 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
977
1543
  Component({
978
1544
  ...restOptions,
979
1545
  ...pageLifecycleHooks,
1546
+ observers: finalObservers,
980
1547
  lifetimes: {
981
1548
  ...userLifetimes,
982
1549
  created: function created(...args) {
983
1550
  mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
1551
+ syncWevuPropsFromInstance(this);
984
1552
  if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
985
1553
  if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
986
1554
  },
@@ -990,12 +1558,14 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
990
1558
  },
991
1559
  attached: function attached(...args) {
992
1560
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
1561
+ syncWevuPropsFromInstance(this);
993
1562
  enableDeferredSetData(this);
994
1563
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
995
1564
  },
996
1565
  ready: function ready(...args) {
997
1566
  if (!this.__wevuReadyCalled) {
998
1567
  this.__wevuReadyCalled = true;
1568
+ syncWevuPropsFromInstance(this);
999
1569
  callHookList(this, "onReady", args);
1000
1570
  }
1001
1571
  if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
@@ -1164,6 +1734,7 @@ function createApp(options) {
1164
1734
  Object.keys(state).forEach((key) => {
1165
1735
  const v = state[key];
1166
1736
  if (isRef(v)) v.value;
1737
+ else if (isReactive(v)) touchReactive(v);
1167
1738
  });
1168
1739
  Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
1169
1740
  }, {
@@ -1352,6 +1923,13 @@ function normalizeProps(baseOptions, props, explicitProperties) {
1352
1923
  return;
1353
1924
  }
1354
1925
  if (typeof definition === "object") {
1926
+ if (key.endsWith("Modifiers") && Object.keys(definition).length === 0) {
1927
+ properties[key] = {
1928
+ type: Object,
1929
+ value: {}
1930
+ };
1931
+ return;
1932
+ }
1355
1933
  const propOptions = {};
1356
1934
  if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
1357
1935
  const defaultValue = "default" in definition ? definition.default : definition.value;
@@ -1442,4 +2020,281 @@ function injectGlobal(key, defaultValue) {
1442
2020
  }
1443
2021
 
1444
2022
  //#endregion
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 };
2023
+ //#region src/runtime/vueCompat.ts
2024
+ function useAttrs() {
2025
+ const ctx = getCurrentSetupContext();
2026
+ if (!ctx) throw new Error("useAttrs() must be called synchronously inside setup()");
2027
+ return ctx.attrs ?? {};
2028
+ }
2029
+ function useSlots() {
2030
+ const ctx = getCurrentSetupContext();
2031
+ if (!ctx) throw new Error("useSlots() must be called synchronously inside setup()");
2032
+ return ctx.slots ?? Object.create(null);
2033
+ }
2034
+ function useModel(props, name) {
2035
+ const ctx = getCurrentSetupContext();
2036
+ if (!ctx) throw new Error("useModel() must be called synchronously inside setup()");
2037
+ const emit = ctx.emit;
2038
+ const eventName = `update:${name}`;
2039
+ return customRef({
2040
+ get: () => props?.[name],
2041
+ set: (value) => {
2042
+ emit?.(eventName, value);
2043
+ }
2044
+ });
2045
+ }
2046
+ function mergeModels(a, b) {
2047
+ if (a == null) return b;
2048
+ if (b == null) return a;
2049
+ if (Array.isArray(a) && Array.isArray(b)) return Array.from(new Set([...a, ...b]));
2050
+ if (typeof a === "object" && typeof b === "object") return {
2051
+ ...a,
2052
+ ...b
2053
+ };
2054
+ return b;
2055
+ }
2056
+
2057
+ //#endregion
2058
+ //#region src/store/actions.ts
2059
+ function wrapAction(store, name, action, actionSubs) {
2060
+ return function wrapped(...args) {
2061
+ const afterCbs = [];
2062
+ const errorCbs = [];
2063
+ const after = (cb) => afterCbs.push(cb);
2064
+ const onError$1 = (cb) => errorCbs.push(cb);
2065
+ actionSubs.forEach((sub) => {
2066
+ try {
2067
+ sub({
2068
+ name,
2069
+ store,
2070
+ args,
2071
+ after,
2072
+ onError: onError$1
2073
+ });
2074
+ } catch {}
2075
+ });
2076
+ let res;
2077
+ try {
2078
+ res = action.apply(store, args);
2079
+ } catch (e) {
2080
+ errorCbs.forEach((cb) => cb(e));
2081
+ throw e;
2082
+ }
2083
+ const finalize = (r) => {
2084
+ afterCbs.forEach((cb) => cb(r));
2085
+ return r;
2086
+ };
2087
+ if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
2088
+ errorCbs.forEach((cb) => cb(e));
2089
+ return Promise.reject(e);
2090
+ });
2091
+ return finalize(res);
2092
+ };
2093
+ }
2094
+
2095
+ //#endregion
2096
+ //#region src/store/utils.ts
2097
+ function isObject(val) {
2098
+ return typeof val === "object" && val !== null;
2099
+ }
2100
+ function mergeShallow(target, patch) {
2101
+ for (const k in patch) target[k] = patch[k];
2102
+ }
2103
+
2104
+ //#endregion
2105
+ //#region src/store/base.ts
2106
+ function createBaseApi(id, stateObj, notify, resetImpl) {
2107
+ const api = { $id: id };
2108
+ Object.defineProperty(api, "$state", {
2109
+ get() {
2110
+ return stateObj;
2111
+ },
2112
+ set(v) {
2113
+ if (stateObj && isObject(v)) {
2114
+ mergeShallow(stateObj, v);
2115
+ notify("patch object");
2116
+ }
2117
+ }
2118
+ });
2119
+ api.$patch = (patch) => {
2120
+ if (!stateObj) {
2121
+ if (typeof patch === "function") {
2122
+ patch(api);
2123
+ notify("patch function");
2124
+ } else {
2125
+ mergeShallow(api, patch);
2126
+ notify("patch object");
2127
+ }
2128
+ return;
2129
+ }
2130
+ if (typeof patch === "function") {
2131
+ patch(stateObj);
2132
+ notify("patch function");
2133
+ } else {
2134
+ mergeShallow(stateObj, patch);
2135
+ notify("patch object");
2136
+ }
2137
+ };
2138
+ if (resetImpl) api.$reset = () => resetImpl();
2139
+ const subs = /* @__PURE__ */ new Set();
2140
+ api.$subscribe = (cb, _opts) => {
2141
+ subs.add(cb);
2142
+ return () => subs.delete(cb);
2143
+ };
2144
+ const actionSubs = /* @__PURE__ */ new Set();
2145
+ api.$onAction = (cb) => {
2146
+ actionSubs.add(cb);
2147
+ return () => actionSubs.delete(cb);
2148
+ };
2149
+ return {
2150
+ api,
2151
+ subs,
2152
+ actionSubs
2153
+ };
2154
+ }
2155
+
2156
+ //#endregion
2157
+ //#region src/store/manager.ts
2158
+ function createStore() {
2159
+ const manager = {
2160
+ _stores: /* @__PURE__ */ new Map(),
2161
+ _plugins: [],
2162
+ install(_app) {},
2163
+ use(plugin) {
2164
+ if (typeof plugin === "function") manager._plugins.push(plugin);
2165
+ return manager;
2166
+ }
2167
+ };
2168
+ createStore._instance = manager;
2169
+ return manager;
2170
+ }
2171
+
2172
+ //#endregion
2173
+ //#region src/store/define.ts
2174
+ function defineStore(id, setupOrOptions) {
2175
+ let instance;
2176
+ let created = false;
2177
+ const manager = createStore._instance;
2178
+ return function useStore() {
2179
+ if (created && instance) return instance;
2180
+ created = true;
2181
+ if (typeof setupOrOptions === "function") {
2182
+ const result = setupOrOptions();
2183
+ let notify$1 = () => {};
2184
+ const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
2185
+ notify$1 = (type) => {
2186
+ base$1.subs.forEach((cb) => {
2187
+ try {
2188
+ cb({
2189
+ type,
2190
+ storeId: id
2191
+ }, instance);
2192
+ } catch {}
2193
+ });
2194
+ };
2195
+ instance = Object.assign({}, result);
2196
+ for (const key of Object.getOwnPropertyNames(base$1.api)) {
2197
+ const d = Object.getOwnPropertyDescriptor(base$1.api, key);
2198
+ if (d) Object.defineProperty(instance, key, d);
2199
+ }
2200
+ Object.keys(result).forEach((k) => {
2201
+ const val = result[k];
2202
+ if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
2203
+ });
2204
+ const plugins$1 = manager?._plugins ?? [];
2205
+ for (const plugin of plugins$1) try {
2206
+ plugin({ store: instance });
2207
+ } catch {}
2208
+ return instance;
2209
+ }
2210
+ const options = setupOrOptions;
2211
+ const rawState = options.state ? options.state() : {};
2212
+ const state = reactive(rawState);
2213
+ const initialSnapshot = { ...toRaw(rawState) };
2214
+ let notify = () => {};
2215
+ const base = createBaseApi(id, state, (t) => notify(t), () => {
2216
+ mergeShallow(state, initialSnapshot);
2217
+ notify("patch object");
2218
+ });
2219
+ notify = (type) => {
2220
+ base.subs.forEach((cb) => {
2221
+ try {
2222
+ cb({
2223
+ type,
2224
+ storeId: id
2225
+ }, state);
2226
+ } catch {}
2227
+ });
2228
+ };
2229
+ const store = {};
2230
+ for (const key of Object.getOwnPropertyNames(base.api)) {
2231
+ const d = Object.getOwnPropertyDescriptor(base.api, key);
2232
+ if (d) Object.defineProperty(store, key, d);
2233
+ }
2234
+ const getterDefs = options.getters ?? {};
2235
+ const computedMap = {};
2236
+ Object.keys(getterDefs).forEach((key) => {
2237
+ const getter = getterDefs[key];
2238
+ if (typeof getter === "function") {
2239
+ const c = computed(() => getter.call(store, state));
2240
+ computedMap[key] = c;
2241
+ Object.defineProperty(store, key, {
2242
+ enumerable: true,
2243
+ configurable: true,
2244
+ get() {
2245
+ return c.value;
2246
+ }
2247
+ });
2248
+ }
2249
+ });
2250
+ const actionDefs = options.actions ?? {};
2251
+ Object.keys(actionDefs).forEach((key) => {
2252
+ const act = actionDefs[key];
2253
+ if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
2254
+ return act.apply(store, args);
2255
+ }, base.actionSubs);
2256
+ });
2257
+ Object.keys(state).forEach((k) => {
2258
+ Object.defineProperty(store, k, {
2259
+ enumerable: true,
2260
+ configurable: true,
2261
+ get() {
2262
+ return state[k];
2263
+ },
2264
+ set(v) {
2265
+ state[k] = v;
2266
+ }
2267
+ });
2268
+ });
2269
+ instance = store;
2270
+ const plugins = manager?._plugins ?? [];
2271
+ for (const plugin of plugins) try {
2272
+ plugin({ store: instance });
2273
+ } catch {}
2274
+ return instance;
2275
+ };
2276
+ }
2277
+
2278
+ //#endregion
2279
+ //#region src/store/storeToRefs.ts
2280
+ function storeToRefs(store) {
2281
+ const result = {};
2282
+ for (const key in store) {
2283
+ const value = store[key];
2284
+ if (typeof value === "function") {
2285
+ result[key] = value;
2286
+ continue;
2287
+ }
2288
+ if (isRef(value)) result[key] = value;
2289
+ else result[key] = computed({
2290
+ get: () => store[key],
2291
+ set: (v) => {
2292
+ store[key] = v;
2293
+ }
2294
+ });
2295
+ }
2296
+ return result;
2297
+ }
2298
+
2299
+ //#endregion
2300
+ export { batch, callHookList, callHookReturn, callUpdateHooks, computed, createApp, createStore, createWevuComponent, defineComponent, defineStore, effect, effectScope, endBatch, getCurrentInstance, getCurrentScope, getCurrentSetupContext, getDeepWatchStrategy, inject, injectGlobal, isRaw, isReactive, isRef, isShallowReactive, isShallowRef, markRaw, mergeModels, 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, setCurrentSetupContext, setDeepWatchStrategy, shallowReactive, shallowRef, startBatch, stop, storeToRefs, teardownRuntimeInstance, toRaw, toRef, toRefs, touchReactive, traverse, triggerRef, unref, useAttrs, useModel, useSlots, watch, watchEffect };