tutuca 0.9.45 → 0.9.46

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.
@@ -1,4 +1,6 @@
1
1
  // src/path.js
2
+ var NONE = Symbol("NONE");
3
+
2
4
  class Step {
3
5
  lookup(_v, dval = null) {
4
6
  return dval;
@@ -6,8 +8,9 @@ class Step {
6
8
  setValue(root, _v) {
7
9
  return root;
8
10
  }
9
- updateBinds(_v, _o) {}
10
- isFrame = true;
11
+ enterFrame(stack, _prev, next) {
12
+ return stack.enter(next, {}, true);
13
+ }
11
14
  }
12
15
 
13
16
  class BindStep extends Step {
@@ -21,16 +24,15 @@ class BindStep extends Step {
21
24
  setValue(_root, v) {
22
25
  return v;
23
26
  }
27
+ enterFrame(stack, _prev, next) {
28
+ return stack.enter(next, { ...this.binds }, false);
29
+ }
24
30
  withIndex(i) {
25
31
  return new BindStep({ ...this.binds, key: i });
26
32
  }
27
33
  withKey(key) {
28
34
  return new BindStep({ ...this.binds, key });
29
35
  }
30
- updateBinds(_v, o) {
31
- Object.assign(o, this.binds);
32
- }
33
- isFrame = false;
34
36
  }
35
37
 
36
38
  class FieldStep extends Step {
@@ -65,8 +67,8 @@ class FieldSeqStep extends Step {
65
67
  setValue(root, v) {
66
68
  return root.set(this.field, root.get(this.field).set(this.key, v));
67
69
  }
68
- updateBinds(_v, o) {
69
- o.key = this.key;
70
+ enterFrame(stack, _prev, next) {
71
+ return stack.enter(next, { key: this.key }, true);
70
72
  }
71
73
  }
72
74
 
@@ -75,7 +77,6 @@ class SeqKeyStep extends FieldSeqStep {
75
77
 
76
78
  class SeqIndexStep extends FieldSeqStep {
77
79
  }
78
- var NONE = Symbol("NONE");
79
80
 
80
81
  class SeqAccessStep extends Step {
81
82
  constructor(seqField, keyField) {
@@ -93,8 +94,42 @@ class SeqAccessStep extends Step {
93
94
  const key = root?.get(this.keyField, NONE);
94
95
  return seq === NONE || key === NONE ? root : root.set(this.seqField, seq.set(key, v));
95
96
  }
96
- updateBinds(v, o) {
97
- o.key = v?.get(this.keyField, null);
97
+ }
98
+
99
+ class EachBindStep extends Step {
100
+ constructor(seqVal, key) {
101
+ super();
102
+ this.seqVal = seqVal;
103
+ this.key = key;
104
+ }
105
+ lookup(v, _dval) {
106
+ return v;
107
+ }
108
+ setValue(_root, v) {
109
+ return v;
110
+ }
111
+ enterFrame(stack, _prev, next) {
112
+ const item = this.seqVal.eval(stack)?.get(this.key, null);
113
+ return stack.enter(next, { key: this.key, value: item }, false);
114
+ }
115
+ }
116
+
117
+ class EachRenderItStep extends Step {
118
+ constructor(seqField, key) {
119
+ super();
120
+ this.seqField = seqField;
121
+ this.key = key;
122
+ }
123
+ lookup(v, dval = null) {
124
+ const seq = v?.get(this.seqField, null);
125
+ return seq?.get ? seq.get(this.key, dval) : dval;
126
+ }
127
+ setValue(root, v) {
128
+ const seq = root?.get(this.seqField, null);
129
+ return seq ? root.set(this.seqField, seq.set(this.key, v)) : root;
130
+ }
131
+ enterFrame(stack, _prev, next) {
132
+ return stack.enter(next, { key: this.key, value: next }, false).enter(next, {}, true);
98
133
  }
99
134
  }
100
135
 
@@ -134,16 +169,15 @@ class Path {
134
169
  return newVal;
135
170
  }
136
171
  buildStack(stack) {
137
- const root = stack.it;
138
- let curVal = root;
172
+ let prev = stack.it;
139
173
  for (const step of this.steps) {
140
- curVal = step.lookup(curVal, NONE);
141
- if (curVal === NONE) {
142
- console.warn(`bad PathItem`, { root, curVal, step, path: this });
174
+ const next = step.lookup(prev, NONE);
175
+ if (next === NONE) {
176
+ console.warn("bad PathItem", { root: stack.it, step, path: this });
143
177
  return null;
144
178
  }
145
- step.updateBinds(curVal, stack.binds[0].binds);
146
- stack = stack.enter(curVal, {}, step.isFrame);
179
+ stack = step.enterFrame(stack, prev, next);
180
+ prev = next;
147
181
  }
148
182
  return stack;
149
183
  }
@@ -211,12 +245,27 @@ function findHandlers(comp, eventIds, vid, eventName) {
211
245
  }
212
246
  function resolvePathStep(comp, nodeIds, vid) {
213
247
  for (let i = 0;i < nodeIds.length; i++) {
214
- const node = comp.getNodeForId(+nodeIds[i].nid, vid);
215
- const j = node.pathInNext ? i + 1 : i;
216
- const { si, sk, nid: nodeId } = nodeIds[j];
217
- const pi = node.pathInNext ? comp.getNodeForId(+nodeId, vid).val.toPathItem() : node.toPathItem();
248
+ const meta = nodeIds[i];
249
+ const node = comp.getNodeForId(+meta.nid, vid);
250
+ const key = meta.si !== undefined ? +meta.si : meta.sk;
251
+ if (node.pathInNext) {
252
+ const next = nodeIds[i + 1];
253
+ if (!next)
254
+ continue;
255
+ const nextNode = comp.getNodeForId(+next.nid, vid);
256
+ const nKey = next.si !== undefined ? +next.si : next.sk;
257
+ if (nextNode.toPathItemRenderIt && nKey !== undefined)
258
+ return nextNode.toPathItemRenderIt(nKey);
259
+ const pi2 = nextNode.val.toPathItem();
260
+ if (pi2 !== null)
261
+ return next.si !== undefined ? pi2.withIndex(nKey) : next.sk ? pi2.withKey(nKey) : pi2;
262
+ continue;
263
+ }
264
+ if (key !== undefined && node.toPathItemEachBind)
265
+ return node.toPathItemEachBind(key);
266
+ const pi = node.toPathItem();
218
267
  if (pi !== null)
219
- return si !== undefined ? pi.withIndex(+si) : sk ? pi.withKey(sk) : pi;
268
+ return meta.si !== undefined ? pi.withIndex(+meta.si) : meta.sk ? pi.withKey(meta.sk) : pi;
220
269
  }
221
270
  return null;
222
271
  }
@@ -1352,6 +1401,12 @@ class EachNode extends WrapperNode {
1352
1401
  toPathItem() {
1353
1402
  return new BindStep({});
1354
1403
  }
1404
+ toPathItemRenderIt(key) {
1405
+ return new EachRenderItStep(this.val.name, key);
1406
+ }
1407
+ toPathItemEachBind(key) {
1408
+ return new EachBindStep(this.val, key);
1409
+ }
1355
1410
  static register = true;
1356
1411
  }
1357
1412
 
@@ -1837,11 +1892,6 @@ class Stack {
1837
1892
  _enrichOnEnter() {
1838
1893
  return this.withDynamicBinds(this.comps.getOnEnterFor(this.it).call(this.it));
1839
1894
  }
1840
- upToFrameBinds() {
1841
- const { comps, binds, dynBinds, views, viewsId, ctx } = this;
1842
- const [head, tail] = binds;
1843
- return head.isFrame ? this : new Stack(comps, tail[0].it, tail, dynBinds, views, viewsId, ctx);
1844
- }
1845
1895
  static root(comps, it, ctx) {
1846
1896
  const binds = [new BindFrame(it, { it }, true), null];
1847
1897
  const dynBinds = [new ObjectFrame({}), null];
@@ -2026,8 +2076,7 @@ class Transaction {
2026
2076
  return Stack.root(comps, root);
2027
2077
  }
2028
2078
  buildStack(root, comps) {
2029
- const stack = this.path.buildStack(this.buildRootStack(root, comps));
2030
- return stack ? stack.upToFrameBinds() : null;
2079
+ return this.path.buildStack(this.buildRootStack(root, comps));
2031
2080
  }
2032
2081
  callHandler(root, instance, comps) {
2033
2082
  const [handler, args] = this.getHandlerAndArgs(root, instance, comps);
@@ -7993,10 +8042,10 @@ async function compileClassesToStyle(app, compileClasses, styleId = "margaui-css
7993
8042
  injectCss(styleId, css2);
7994
8043
  return t2 - t1;
7995
8044
  }
7996
- async function compileClassesToStyleText(app, compileClasses, extraCSSClasses, Ctx = ParseCtxClassSetCollector) {
8045
+ async function compileClassesToStyleText(app, compileClasses, Ctx = ParseCtxClassSetCollector) {
7997
8046
  app.ParseContext = Ctx;
7998
8047
  app.compile();
7999
- const classes = new Set(extraCSSClasses ?? []);
8048
+ const classes = new Set;
8000
8049
  for (const Comp of app.comps.byId.values()) {
8001
8050
  for (const key in Comp.views) {
8002
8051
  const view = Comp.views[key];