wevu 1.0.0-alpha.4 → 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.cjs CHANGED
@@ -705,7 +705,11 @@ function setByPath(state, computedRefs, computedSetters, segments, value) {
705
705
  const [head, ...rest] = segments;
706
706
  if (!rest.length) {
707
707
  if (computedRefs[head]) setComputedValue$1(computedSetters, head, value);
708
- else state[head] = value;
708
+ else {
709
+ const current = state[head];
710
+ if (isRef(current)) current.value = value;
711
+ else state[head] = value;
712
+ }
709
713
  return;
710
714
  }
711
715
  if (computedRefs[head]) {
@@ -1067,6 +1071,17 @@ function callUpdateHooks(target, phase) {
1067
1071
 
1068
1072
  //#endregion
1069
1073
  //#region src/runtime/register.ts
1074
+ function decodeWxmlEntities(value) {
1075
+ return value.replace(/&amp;/g, "&").replace(/&quot;/g, "\"").replace(/&#34;/g, "\"").replace(/&apos;/g, "'").replace(/&#39;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
1076
+ }
1077
+ function parseModelEventValue(event) {
1078
+ if (event == null) return event;
1079
+ if (typeof event === "object") {
1080
+ if ("detail" in event && event.detail && "value" in event.detail) return event.detail.value;
1081
+ if ("target" in event && event.target && "value" in event.target) return event.target.value;
1082
+ }
1083
+ return event;
1084
+ }
1070
1085
  function runInlineExpression(ctx, expr, event) {
1071
1086
  const handlerName = typeof expr === "string" ? expr : void 0;
1072
1087
  if (!handlerName) return;
@@ -1075,8 +1090,13 @@ function runInlineExpression(ctx, expr, event) {
1075
1090
  if (typeof argsRaw === "string") try {
1076
1091
  args = JSON.parse(argsRaw);
1077
1092
  } catch {
1078
- args = [];
1093
+ try {
1094
+ args = JSON.parse(decodeWxmlEntities(argsRaw));
1095
+ } catch {
1096
+ args = [];
1097
+ }
1079
1098
  }
1099
+ if (!Array.isArray(args)) args = [];
1080
1100
  const resolvedArgs = args.map((item) => item === "$event" ? event : item);
1081
1101
  const handler = ctx?.[handlerName];
1082
1102
  if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
@@ -1202,7 +1222,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
1202
1222
  if (stops.length) target.__wevuWatchStops = stops;
1203
1223
  }
1204
1224
  if (setup) {
1205
- const props = target.properties || {};
1225
+ const props = shallowReactive({ ...target.properties || {} });
1226
+ try {
1227
+ Object.defineProperty(target, "__wevuProps", {
1228
+ value: props,
1229
+ configurable: true,
1230
+ enumerable: false,
1231
+ writable: false
1232
+ });
1233
+ } catch {
1234
+ target.__wevuProps = props;
1235
+ }
1206
1236
  const context = {
1207
1237
  props,
1208
1238
  runtime: runtimeWithDefaults,
@@ -1322,6 +1352,7 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1322
1352
  const userOnAddToFavorites = rest.onAddToFavorites;
1323
1353
  const features = rest.features ?? {};
1324
1354
  const restOptions = { ...rest };
1355
+ const userObservers = restOptions.observers;
1325
1356
  const legacyCreated = restOptions.created;
1326
1357
  delete restOptions.features;
1327
1358
  delete restOptions.created;
@@ -1377,11 +1408,56 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1377
1408
  multipleSlots: userOptions.multipleSlots ?? true,
1378
1409
  ...userOptions
1379
1410
  };
1411
+ const syncWevuPropsFromInstance = (instance) => {
1412
+ const propsProxy = instance.__wevuProps;
1413
+ const properties = instance.properties;
1414
+ if (!propsProxy || typeof propsProxy !== "object") return;
1415
+ if (!properties || typeof properties !== "object") return;
1416
+ const next = properties;
1417
+ const currentKeys = Object.keys(propsProxy);
1418
+ for (const existingKey of currentKeys) if (!Object.prototype.hasOwnProperty.call(next, existingKey)) try {
1419
+ delete propsProxy[existingKey];
1420
+ } catch {}
1421
+ for (const [k, v] of Object.entries(next)) try {
1422
+ propsProxy[k] = v;
1423
+ } catch {}
1424
+ };
1425
+ const syncWevuPropValue = (instance, key, value) => {
1426
+ const propsProxy = instance.__wevuProps;
1427
+ if (!propsProxy || typeof propsProxy !== "object") return;
1428
+ try {
1429
+ propsProxy[key] = value;
1430
+ } catch {}
1431
+ };
1432
+ const propKeys = restOptions.properties && typeof restOptions.properties === "object" ? Object.keys(restOptions.properties) : [];
1433
+ const injectedObservers = {};
1434
+ if (propKeys.length) for (const key of propKeys) injectedObservers[key] = function __wevu_prop_observer(newValue) {
1435
+ syncWevuPropValue(this, key, newValue);
1436
+ };
1437
+ const finalObservers = { ...userObservers ?? {} };
1438
+ for (const [key, injected] of Object.entries(injectedObservers)) {
1439
+ const existing = finalObservers[key];
1440
+ if (typeof existing === "function") finalObservers[key] = function chainedObserver(...args) {
1441
+ existing.apply(this, args);
1442
+ injected.apply(this, args);
1443
+ };
1444
+ else finalObservers[key] = injected;
1445
+ }
1380
1446
  const finalMethods = { ...userMethods };
1381
1447
  if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
1382
1448
  const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
1383
1449
  return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
1384
1450
  };
1451
+ if (!finalMethods.__weapp_vite_model) finalMethods.__weapp_vite_model = function __weapp_vite_model(event) {
1452
+ const path = event?.currentTarget?.dataset?.wvModel ?? event?.target?.dataset?.wvModel;
1453
+ if (typeof path !== "string" || !path) return;
1454
+ const runtime = this.__wevu;
1455
+ if (!runtime || typeof runtime.bindModel !== "function") return;
1456
+ const value = parseModelEventValue(event);
1457
+ try {
1458
+ runtime.bindModel(path).update(value);
1459
+ } catch {}
1460
+ };
1385
1461
  const methodNames = Object.keys(methods ?? {});
1386
1462
  for (const methodName of methodNames) {
1387
1463
  const userMethod = finalMethods[methodName];
@@ -1468,10 +1544,12 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1468
1544
  Component({
1469
1545
  ...restOptions,
1470
1546
  ...pageLifecycleHooks,
1547
+ observers: finalObservers,
1471
1548
  lifetimes: {
1472
1549
  ...userLifetimes,
1473
1550
  created: function created(...args) {
1474
1551
  mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
1552
+ syncWevuPropsFromInstance(this);
1475
1553
  if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
1476
1554
  if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
1477
1555
  },
@@ -1481,12 +1559,14 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1481
1559
  },
1482
1560
  attached: function attached(...args) {
1483
1561
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
1562
+ syncWevuPropsFromInstance(this);
1484
1563
  enableDeferredSetData(this);
1485
1564
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
1486
1565
  },
1487
1566
  ready: function ready(...args) {
1488
1567
  if (!this.__wevuReadyCalled) {
1489
1568
  this.__wevuReadyCalled = true;
1569
+ syncWevuPropsFromInstance(this);
1490
1570
  callHookList(this, "onReady", args);
1491
1571
  }
1492
1572
  if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
@@ -1655,6 +1735,7 @@ function createApp(options) {
1655
1735
  Object.keys(state).forEach((key) => {
1656
1736
  const v = state[key];
1657
1737
  if (isRef(v)) v.value;
1738
+ else if (isReactive(v)) touchReactive(v);
1658
1739
  });
1659
1740
  Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
1660
1741
  }, {
package/dist/index.d.cts CHANGED
@@ -1,9 +1,7 @@
1
+ import { Ref as Ref$1 } from "@vue/reactivity";
2
+
1
3
  //#region src/reactivity/ref.d.ts
2
- interface Ref<T$1 = any, S = T$1> {
3
- get value(): T$1;
4
- set value(_: S);
5
- [key: symbol]: any;
6
- }
4
+ type Ref<T$1 = any, S = T$1> = Ref$1<T$1, S>;
7
5
  declare function isRef(value: unknown): value is Ref<any>;
8
6
  declare function ref<T$1>(value: T$1): Ref<T$1>;
9
7
  declare function unref<T$1>(value: T$1 | Ref<T$1>): T$1;
package/dist/index.d.mts CHANGED
@@ -1,9 +1,7 @@
1
+ import { Ref as Ref$1 } from "@vue/reactivity";
2
+
1
3
  //#region src/reactivity/ref.d.ts
2
- interface Ref<T$1 = any, S = T$1> {
3
- get value(): T$1;
4
- set value(_: S);
5
- [key: symbol]: any;
6
- }
4
+ type Ref<T$1 = any, S = T$1> = Ref$1<T$1, S>;
7
5
  declare function isRef(value: unknown): value is Ref<any>;
8
6
  declare function ref<T$1>(value: T$1): Ref<T$1>;
9
7
  declare function unref<T$1>(value: T$1 | Ref<T$1>): T$1;
package/dist/index.mjs CHANGED
@@ -704,7 +704,11 @@ function setByPath(state, computedRefs, computedSetters, segments, value) {
704
704
  const [head, ...rest] = segments;
705
705
  if (!rest.length) {
706
706
  if (computedRefs[head]) setComputedValue$1(computedSetters, head, value);
707
- else state[head] = value;
707
+ else {
708
+ const current = state[head];
709
+ if (isRef(current)) current.value = value;
710
+ else state[head] = value;
711
+ }
708
712
  return;
709
713
  }
710
714
  if (computedRefs[head]) {
@@ -1066,6 +1070,17 @@ function callUpdateHooks(target, phase) {
1066
1070
 
1067
1071
  //#endregion
1068
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
+ }
1069
1084
  function runInlineExpression(ctx, expr, event) {
1070
1085
  const handlerName = typeof expr === "string" ? expr : void 0;
1071
1086
  if (!handlerName) return;
@@ -1074,8 +1089,13 @@ function runInlineExpression(ctx, expr, event) {
1074
1089
  if (typeof argsRaw === "string") try {
1075
1090
  args = JSON.parse(argsRaw);
1076
1091
  } catch {
1077
- args = [];
1092
+ try {
1093
+ args = JSON.parse(decodeWxmlEntities(argsRaw));
1094
+ } catch {
1095
+ args = [];
1096
+ }
1078
1097
  }
1098
+ if (!Array.isArray(args)) args = [];
1079
1099
  const resolvedArgs = args.map((item) => item === "$event" ? event : item);
1080
1100
  const handler = ctx?.[handlerName];
1081
1101
  if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
@@ -1201,7 +1221,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
1201
1221
  if (stops.length) target.__wevuWatchStops = stops;
1202
1222
  }
1203
1223
  if (setup) {
1204
- 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
+ }
1205
1235
  const context = {
1206
1236
  props,
1207
1237
  runtime: runtimeWithDefaults,
@@ -1321,6 +1351,7 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1321
1351
  const userOnAddToFavorites = rest.onAddToFavorites;
1322
1352
  const features = rest.features ?? {};
1323
1353
  const restOptions = { ...rest };
1354
+ const userObservers = restOptions.observers;
1324
1355
  const legacyCreated = restOptions.created;
1325
1356
  delete restOptions.features;
1326
1357
  delete restOptions.created;
@@ -1376,11 +1407,56 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1376
1407
  multipleSlots: userOptions.multipleSlots ?? true,
1377
1408
  ...userOptions
1378
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
+ }
1379
1445
  const finalMethods = { ...userMethods };
1380
1446
  if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
1381
1447
  const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
1382
1448
  return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
1383
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
+ };
1384
1460
  const methodNames = Object.keys(methods ?? {});
1385
1461
  for (const methodName of methodNames) {
1386
1462
  const userMethod = finalMethods[methodName];
@@ -1467,10 +1543,12 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1467
1543
  Component({
1468
1544
  ...restOptions,
1469
1545
  ...pageLifecycleHooks,
1546
+ observers: finalObservers,
1470
1547
  lifetimes: {
1471
1548
  ...userLifetimes,
1472
1549
  created: function created(...args) {
1473
1550
  mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
1551
+ syncWevuPropsFromInstance(this);
1474
1552
  if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
1475
1553
  if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
1476
1554
  },
@@ -1480,12 +1558,14 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
1480
1558
  },
1481
1559
  attached: function attached(...args) {
1482
1560
  mountRuntimeInstance(this, runtimeApp, watch$1, setup);
1561
+ syncWevuPropsFromInstance(this);
1483
1562
  enableDeferredSetData(this);
1484
1563
  if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
1485
1564
  },
1486
1565
  ready: function ready(...args) {
1487
1566
  if (!this.__wevuReadyCalled) {
1488
1567
  this.__wevuReadyCalled = true;
1568
+ syncWevuPropsFromInstance(this);
1489
1569
  callHookList(this, "onReady", args);
1490
1570
  }
1491
1571
  if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
@@ -1654,6 +1734,7 @@ function createApp(options) {
1654
1734
  Object.keys(state).forEach((key) => {
1655
1735
  const v = state[key];
1656
1736
  if (isRef(v)) v.value;
1737
+ else if (isReactive(v)) touchReactive(v);
1657
1738
  });
1658
1739
  Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
1659
1740
  }, {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "wevu",
3
3
  "type": "module",
4
- "version": "1.0.0-alpha.4",
4
+ "version": "1.0.0-alpha.5",
5
5
  "description": "Vue 3 风格的小程序运行时,包含响应式、diff+setData 与轻量状态管理",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
- "homepage": "https://github.com/weapp-vite/weapp-vite/tree/main/packages/wevu",
8
+ "homepage": "https://vite.icebreaker.top/wevu/",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/weapp-vite/weapp-vite.git",