x-runtime-lib 0.8.189 → 0.8.190

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.js CHANGED
@@ -9857,64 +9857,29 @@ function unwrapSlotId(e) {
9857
9857
  }
9858
9858
  function makeTriggerId(e) {
9859
9859
  let C = [e.type];
9860
- if (e.type === "elementProperty") C.push(e.nodeId, e.propertyKeys);
9861
- else if (e.type === "elementSlotProperty") C.push(e.nodeId, e.elementKey, e.slotKey, e.propertyKey);
9862
- else if (e.type === "multipleElementSlotProperty") C.push(e.nodeId, e.spec, e.elementKey, e.slotKey, e.propertyKey);
9863
- else if (e.type === "customSlotProperty") C.push(e.compId, e.slotId, e.propertyId);
9864
- else if (e.type === "multipleCustomSlotProperty") C.push(e.spec, e.compId, e.slotId, e.propertyId);
9865
- else if (e.type === "customProperty") C.push(e.propertyId);
9860
+ if (e.type === "property") C.push(e.propertyId), e.spec && C.push(e.spec);
9866
9861
  else if (e.type === "state") C.push(e.stateId);
9867
9862
  else throw Error("not implemented trigger type");
9868
- return e.subKeys && C.push(e.subKeys), C.join("/");
9863
+ return C.join("@");
9869
9864
  }
9870
9865
  function unwrapTriggerId(e) {
9871
- let C = e.split("/");
9872
- if (C.length <= 0) throw Error("unwrap trigger id failed");
9866
+ let C = e.split("@");
9867
+ if (C.length < 1) throw Error("unwrap trigger id failed");
9873
9868
  let w = C[0];
9874
- if (w === "elementProperty") {
9875
- if (C.length < 3) throw Error("unwrap elementProperty trigger id failed");
9876
- return {
9877
- type: "elementProperty",
9878
- nodeId: C[1],
9879
- propertyKeys: C[2],
9880
- subKeys: C?.[3]
9881
- };
9882
- } else if (w === "elementSlotProperty") {
9883
- if (C.length < 5) throw Error("unwrap elementSlotProperty trigger id failed");
9884
- return {
9885
- type: "elementSlotProperty",
9886
- nodeId: C[1],
9887
- elementKey: C[2],
9888
- slotKey: C[3],
9889
- propertyKey: C[4],
9890
- subKeys: C?.[5]
9891
- };
9892
- } else if (w === "multipleElementSlotProperty") {
9893
- if (C.length < 6) throw Error("unwrap multipleElementSlotProperty trigger id failed");
9894
- return {
9895
- type: "multipleElementSlotProperty",
9896
- nodeId: C[1],
9897
- spec: C[2],
9898
- elementKey: C[3],
9899
- slotKey: C[4],
9900
- propertyKey: C[5],
9901
- subKeys: C?.[6]
9902
- };
9903
- } else if (w === "customProperty") {
9904
- if (C.length < 2) throw Error("unwrap customProperty trigger id failed");
9869
+ if (w === "property") {
9870
+ if (C.length < 2) throw Error("unwrap trigger id of property failed");
9905
9871
  return {
9906
- type: "customProperty",
9872
+ type: w,
9907
9873
  propertyId: C[1],
9908
- subKeys: C?.[2]
9874
+ spec: C[2]
9909
9875
  };
9910
9876
  } else if (w === "state") {
9911
- if (C.length < 2) throw Error("unwrap state trigger id failed");
9877
+ if (C.length !== 2) throw Error("unwrap trigger id of state failed");
9912
9878
  return {
9913
- type: "state",
9914
- stateId: C[1],
9915
- subKeys: C?.[2]
9879
+ type: w,
9880
+ stateId: C[1]
9916
9881
  };
9917
- } else throw Error("not implemented trigger type");
9882
+ } else throw Error("invalid trigger type");
9918
9883
  }
9919
9884
  async function triggerReactivity(e, C, w, T, E) {
9920
9885
  await triggerWatchEffect(e, C, w), await triggerBind(e, C, w, T, E);
@@ -9927,58 +9892,55 @@ async function triggerWatchEffect(e, C, w) {
9927
9892
  }
9928
9893
  }
9929
9894
  function isValidOfTrigger(e, C) {
9930
- if (C.type === "elementProperty") return e.isValidOfElementProperty(C.nodeId, C.propertyKeys);
9931
- if (C.type === "elementSlotProperty") return e.isValidOfElementSlotProperty(makePropertyId("elementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)));
9932
- if (C.type === "multipleElementSlotProperty") return e.isValidOfMultipleElementSlotProperty(makePropertyId("multipleElementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)));
9933
- if (C.type !== "customSlotProperty" && C.type !== "multipleCustomSlotProperty") {
9934
- if (C.type === "customProperty") return e.isValidOfCustomProperty(C.propertyId);
9935
- if (C.type === "state") return e.isValidOfState(C.stateId);
9936
- throw Error("not implemented trigger type");
9937
- }
9938
- return !1;
9895
+ if (C.type === "property") {
9896
+ let { kind: w, nodeId: T, propertyKey: E } = unwrapPropertyId(C.propertyId);
9897
+ switch (w) {
9898
+ case "elementProperty": return e.isValidOfElementProperty(T, E);
9899
+ case "elementSlotProperty": return e.isValidOfElementSlotProperty(E);
9900
+ case "multipleElementSlotProperty": return e.isValidOfMultipleElementSlotProperty(E);
9901
+ case "customProperty": return e.isValidOfCustomProperty(E);
9902
+ default: throw Error("not implemented");
9903
+ }
9904
+ } else if (C.type === "state") return e.isValidOfState(C.stateId);
9905
+ else throw Error("invalid trigger type");
9939
9906
  }
9940
9907
  function getTriggerValue(e, C) {
9941
- let w;
9942
- if (C.type === "elementProperty") w = e.getElementProperty(C.nodeId, C.propertyKeys);
9943
- else if (C.type === "elementSlotProperty") w = e.getElementSlotProperty(makePropertyId("elementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)));
9944
- else if (C.type === "multipleElementSlotProperty") w = e.getMultipleElementSlotProperty(C.spec, makePropertyId("multipleElementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)));
9945
- else if (C.type === "customSlotProperty") w = e.getCustomSlotProperty(C.propertyId);
9946
- else if (C.type !== "multipleCustomSlotProperty") if (C.type === "customProperty") w = e.getCustomProperty(C.propertyId);
9947
- else if (C.type === "state") w = e.getState(C.stateId);
9948
- else throw Error("not implemented trigger type");
9949
- return w;
9908
+ if (C.type === "property") {
9909
+ let { kind: w, nodeId: T, propertyKey: E } = unwrapPropertyId(C.propertyId);
9910
+ if (w === "elementProperty") return e.getElementProperty(T, E);
9911
+ if (w === "elementSlotProperty") {
9912
+ let w = e.children[`${T}/${C.spec}`];
9913
+ if (w) return w.getElementSlotProperty(E);
9914
+ throw Error("sandbox not found");
9915
+ } else if (w === "multipleElementSlotProperty") {
9916
+ let w = e.children[`${T}/${C.spec}`];
9917
+ if (w) return w.getMultipleElementSlotProperty(C.spec, E);
9918
+ throw Error("sandbox not found");
9919
+ } else if (w === "customProperty") return e.getCustomProperty(E);
9920
+ else throw Error("not implemented");
9921
+ } else if (C.type === "state") return e.getState(C.stateId);
9922
+ else throw Error("invalid trigger type");
9950
9923
  }
9951
9924
  function setTriggerValue(e, C, w) {
9952
- if (C.type === "elementProperty") e.setElementProperty(C.nodeId, C.propertyKeys.split("."), w);
9953
- else if (C.type === "elementSlotProperty") e.setElementSlotProperty(makePropertyId("elementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)), w);
9954
- else if (C.type === "multipleElementSlotProperty") e.setMultipeElementSlotProperty(C.spec, makePropertyId("multipleElementSlotProperty", C.nodeId, makePropertyKeyOfElementSlot(C.elementKey, C.slotKey, C.propertyKey)), w);
9955
- else if (C.type === "customSlotProperty") e.setCustomSlotProperty(makePropertyId("customSlotProperty", "globality", makePropertyKeyOfCustomSlot(C.compId, C.slotId, C.propertyId)), w);
9956
- else if (C.type !== "multipleCustomSlotProperty") if (C.type === "customProperty") e.setCustomProperty(makePropertyId("customProperty", "globality", C.propertyId), w);
9957
- else if (C.type === "state") e.setState(C.stateId, w);
9958
- else throw Error("not implemented trigger type");
9925
+ if (C.type === "property") {
9926
+ let { kind: T, nodeId: E, propertyKey: D } = unwrapPropertyId(C.propertyId);
9927
+ if (T === "elementProperty") e.setElementProperty(E, D, w);
9928
+ else if (T === "elementSlotProperty") if (e.children[`${E}/${C.spec}`]) e.setElementSlotProperty(D, w);
9929
+ else throw Error("sandbox not found");
9930
+ else if (T === "multipleElementSlotProperty") if (e.children[`${E}/${C.spec}`]) e.setMultipeElementSlotProperty(C.spec, D, w);
9931
+ else throw Error("sandbox not found");
9932
+ else if (T === "customProperty") e.setCustomProperty(D, w);
9933
+ else throw Error("not implemented");
9934
+ } else if (C.type === "state") e.setState(C.stateId, w);
9935
+ else throw Error("not implemented");
9959
9936
  }
9960
9937
  async function triggerBind(e, C, w, D, O) {
9961
- let { bind: k } = C, A = k.triggers[w];
9962
- if (!A) return;
9963
- let j = unwrapTriggerId(w);
9964
- if (!isValidOfTrigger(e, j)) return;
9965
- if (j.subKeys) {
9966
- if (isEqual_default(getField(D, j.subKeys), getField(O, j.subKeys))) return;
9967
- } else if (isEqual_default(D, O)) return;
9968
- let M;
9969
- M = j.subKeys ? getField(D, j.subKeys) : D;
9970
- for (let C of A) {
9938
+ let { bind: k } = C;
9939
+ if (isEqual_default(D, O)) return;
9940
+ let A = k.triggers[w];
9941
+ if (A && isValidOfTrigger(e, unwrapTriggerId(w))) for (let C of A) {
9971
9942
  let w = k.sets[C];
9972
- if (w) for (let C of w) if (C.subKeys) {
9973
- let w = getTriggerValue(e, C), D = getField(w, C.subKeys);
9974
- if (isEqual_default(M, D)) continue;
9975
- let O = cloneDeep_default(w);
9976
- setField(O, C.subKeys, cloneDeep_default(M)), setTriggerValue(e, C, O);
9977
- } else {
9978
- let w = getTriggerValue(e, C);
9979
- if (isEqual_default(M, w)) continue;
9980
- setTriggerValue(e, C, cloneDeep_default(M));
9981
- }
9943
+ if (w) for (let C of w) isValidOfTrigger(e, C) && (isEqual_default(D, getTriggerValue(e, C)) || setTriggerValue(e, C, cloneDeep_default(D)));
9982
9944
  }
9983
9945
  }
9984
9946
  function getImplementMethodName(e, C, w) {
@@ -10546,9 +10508,8 @@ function useSandbox(e, C, w, E, D, O, k) {
10546
10508
  C ? C.compId = w : console.assert(!1);
10547
10509
  }
10548
10510
  await L.callFunctionAsync("__triggerEventV1__", makeEventId("elementPropertyChangeEvent", e, toDotString(C)), "", w, E ?? w), O.value?.code.reactivity && triggerReactivity(L, O.value.code.reactivity, makeTriggerId({
10549
- type: "elementProperty",
10550
- nodeId: e,
10551
- propertyKeys: toDotString(C)
10511
+ type: "property",
10512
+ propertyId: toDotString(C)
10552
10513
  }), w, E);
10553
10514
  }
10554
10515
  }
@@ -10562,23 +10523,19 @@ function useSandbox(e, C, w, E, D, O, k) {
10562
10523
  }
10563
10524
  async function W(e, C, w) {
10564
10525
  L.vm && O.value?.code.reactivity && triggerReactivity(L, O.value.code.reactivity, makeTriggerId({
10565
- type: "customSlotProperty",
10566
- compId: "placeholder",
10567
- slotId: "placeholder",
10526
+ type: "property",
10568
10527
  propertyId: e
10569
10528
  }), C, w);
10570
10529
  }
10571
10530
  async function G(e, C, w, T) {
10572
10531
  L.vm && O.value?.code.reactivity && triggerReactivity(L, O.value.code.reactivity, makeTriggerId({
10573
- type: "customSlotProperty",
10574
- compId: "placeholder",
10575
- slotId: "placeholder",
10532
+ type: "property",
10576
10533
  propertyId: C
10577
10534
  }), w, T);
10578
10535
  }
10579
10536
  async function K(e, C, w) {
10580
10537
  L.vm && (await L.callFunctionAsync("__triggerEventV1__", makeEventId("customPropertyChangeEvent", "globality", e), "", C, w ?? C), O.value?.code.reactivity && triggerReactivity(L, O.value.code.reactivity, makeTriggerId({
10581
- type: "customProperty",
10538
+ type: "property",
10582
10539
  propertyId: e
10583
10540
  }), C, w), await L.parent.callFunctionAsync("__triggerEventV1__", makeEventId("refPropertyChangeEvent", L.nodeId, e), "", C, w ?? C), await L.parent.callFunctionAsync("__triggerEventV1__", makeEventId("multipleRefPropertyChangeEvent", L.nodeId, e), "", C, w ?? C));
10584
10541
  }
@@ -29,50 +29,16 @@ export interface View {
29
29
  [key: string]: Node;
30
30
  };
31
31
  }
32
- interface TriggerElementProperty {
33
- type: 'elementProperty';
34
- nodeId: string;
35
- propertyKeys: string;
36
- }
37
- interface TriggerElementSlotProperty {
38
- type: 'elementSlotProperty';
39
- nodeId: string;
40
- elementKey: string;
41
- slotKey: string;
42
- propertyKey: string;
43
- }
44
- interface TriggerMultipleElementSlotProperty {
45
- type: 'multipleElementSlotProperty';
46
- nodeId: string;
47
- spec: string;
48
- elementKey: string;
49
- slotKey: string;
50
- propertyKey: string;
51
- }
52
- interface TriggerCustomSlotProperty {
53
- type: 'customSlotProperty';
54
- compId: string;
55
- slotId: string;
56
- propertyId: string;
57
- }
58
- interface TriggerMultipleCustomSlotProperty {
59
- type: 'multipleCustomSlotProperty';
60
- spec: string;
61
- compId: string;
62
- slotId: string;
63
- propertyId: string;
64
- }
65
- interface TriggerCustomProperty {
66
- type: 'customProperty';
32
+ interface TriggerProperty {
33
+ type: 'property';
67
34
  propertyId: string;
35
+ spec?: string;
68
36
  }
69
37
  interface TriggerState {
70
38
  type: 'state';
71
39
  stateId: string;
72
40
  }
73
- export type Trigger = (TriggerElementProperty | TriggerElementSlotProperty | TriggerMultipleElementSlotProperty | TriggerCustomSlotProperty | TriggerMultipleCustomSlotProperty | TriggerCustomProperty | TriggerState) & {
74
- subKeys?: string;
75
- };
41
+ export type Trigger = TriggerProperty | TriggerState;
76
42
  export interface Reactivity {
77
43
  watchEffect: {
78
44
  [key: string]: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "x-runtime-lib",
3
3
  "private": false,
4
- "version": "0.8.189",
4
+ "version": "0.8.190",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",