tutuca 0.9.45 → 0.9.47

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
  }
@@ -209,14 +243,48 @@ function findHandlers(comp, eventIds, vid, eventName) {
209
243
  }
210
244
  return null;
211
245
  }
246
+
247
+ class StepCtx {
248
+ constructor(comp, nodeIds, idx, vid) {
249
+ this.comp = comp;
250
+ this.nodeIds = nodeIds;
251
+ this.idx = idx;
252
+ this.vid = vid;
253
+ }
254
+ get meta() {
255
+ return this.nodeIds[this.idx];
256
+ }
257
+ get key() {
258
+ const m = this.meta;
259
+ return m.si !== undefined ? +m.si : m.sk;
260
+ }
261
+ get hasKey() {
262
+ const m = this.meta;
263
+ return m.si !== undefined || m.sk !== undefined;
264
+ }
265
+ next() {
266
+ return this.idx + 1 < this.nodeIds.length ? new StepCtx(this.comp, this.nodeIds, this.idx + 1, this.vid) : null;
267
+ }
268
+ resolveNode() {
269
+ return this.comp.getNodeForId(+this.meta.nid, this.vid);
270
+ }
271
+ applyKey(pi) {
272
+ if (pi === null)
273
+ return null;
274
+ const m = this.meta;
275
+ if (m.si !== undefined)
276
+ return pi.withIndex(+m.si);
277
+ if (m.sk !== undefined)
278
+ return pi.withKey(m.sk);
279
+ return pi;
280
+ }
281
+ }
212
282
  function resolvePathStep(comp, nodeIds, vid) {
213
283
  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();
218
- if (pi !== null)
219
- return si !== undefined ? pi.withIndex(+si) : sk ? pi.withKey(sk) : pi;
284
+ const ctx = new StepCtx(comp, nodeIds, i, vid);
285
+ const step = ctx.resolveNode().toPathStep(ctx);
286
+ if (step !== null)
287
+ return step;
220
288
  }
221
289
  return null;
222
290
  }
@@ -1016,8 +1084,8 @@ class ANode extends BaseNode {
1016
1084
  this.nodeId = nodeId;
1017
1085
  this.val = val;
1018
1086
  }
1019
- toPathItem() {
1020
- return this.val.toPathItem();
1087
+ toPathStep(ctx) {
1088
+ return ctx.applyKey(this.val?.toPathItem?.() ?? null);
1021
1089
  }
1022
1090
  static parse(html, px) {
1023
1091
  const nodes = px.parseHTML(html);
@@ -1235,7 +1303,15 @@ class RenderItNode extends RenderViewId {
1235
1303
  const newStack = stack.enter(stack.it, {}, true);
1236
1304
  return rx.renderIt(newStack, this.nodeId, "", this.viewId);
1237
1305
  }
1238
- pathInNext = true;
1306
+ toPathStep(ctx) {
1307
+ const next = ctx.next();
1308
+ if (next === null)
1309
+ return null;
1310
+ const nextNode = next.resolveNode();
1311
+ if (nextNode instanceof EachNode && next.hasKey)
1312
+ return new EachRenderItStep(nextNode.val.name, next.key);
1313
+ return null;
1314
+ }
1239
1315
  }
1240
1316
 
1241
1317
  class RenderEachNode extends RenderViewId {
@@ -1331,7 +1407,7 @@ class ScopeNode extends WrapperNode {
1331
1407
  const binds = this.val.eval(stack)?.call(stack.it) ?? {};
1332
1408
  return this.node.render(stack.enter(stack.it, binds, false), rx);
1333
1409
  }
1334
- toPathItem() {
1410
+ toPathStep(_ctx) {
1335
1411
  return new BindStep({});
1336
1412
  }
1337
1413
  wrapNode(node) {
@@ -1349,8 +1425,8 @@ class EachNode extends WrapperNode {
1349
1425
  render(stack, rx) {
1350
1426
  return rx.renderEachWhen(stack, this.iterInfo, this.node, this.nodeId);
1351
1427
  }
1352
- toPathItem() {
1353
- return new BindStep({});
1428
+ toPathStep(ctx) {
1429
+ return ctx.hasKey ? new EachBindStep(this.val, ctx.key) : null;
1354
1430
  }
1355
1431
  static register = true;
1356
1432
  }
@@ -1837,11 +1913,6 @@ class Stack {
1837
1913
  _enrichOnEnter() {
1838
1914
  return this.withDynamicBinds(this.comps.getOnEnterFor(this.it).call(this.it));
1839
1915
  }
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
1916
  static root(comps, it, ctx) {
1846
1917
  const binds = [new BindFrame(it, { it }, true), null];
1847
1918
  const dynBinds = [new ObjectFrame({}), null];
@@ -2026,8 +2097,7 @@ class Transaction {
2026
2097
  return Stack.root(comps, root);
2027
2098
  }
2028
2099
  buildStack(root, comps) {
2029
- const stack = this.path.buildStack(this.buildRootStack(root, comps));
2030
- return stack ? stack.upToFrameBinds() : null;
2100
+ return this.path.buildStack(this.buildRootStack(root, comps));
2031
2101
  }
2032
2102
  callHandler(root, instance, comps) {
2033
2103
  const [handler, args] = this.getHandlerAndArgs(root, instance, comps);
@@ -7822,8 +7892,8 @@ class Renderer {
7822
7892
  renderEachWhen(stack, iterInfo, view, nid) {
7823
7893
  const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
7824
7894
  const r = [];
7825
- const iterData = loopWith.call(stack.it, seq);
7826
7895
  const it = stack.it;
7896
+ const iterData = loopWith.call(it, seq);
7827
7897
  this.getSeqInfo(seq)(seq, (key, value, attrName) => {
7828
7898
  if (filter.call(it, key, value, iterData)) {
7829
7899
  const cachePath = enricher ? [it, value] : [value];
@@ -7993,10 +8063,10 @@ async function compileClassesToStyle(app, compileClasses, styleId = "margaui-css
7993
8063
  injectCss(styleId, css2);
7994
8064
  return t2 - t1;
7995
8065
  }
7996
- async function compileClassesToStyleText(app, compileClasses, extraCSSClasses, Ctx = ParseCtxClassSetCollector) {
8066
+ async function compileClassesToStyleText(app, compileClasses, Ctx = ParseCtxClassSetCollector) {
7997
8067
  app.ParseContext = Ctx;
7998
8068
  app.compile();
7999
- const classes = new Set(extraCSSClasses ?? []);
8069
+ const classes = new Set;
8000
8070
  for (const Comp of app.comps.byId.values()) {
8001
8071
  for (const key in Comp.views) {
8002
8072
  const view = Comp.views[key];