tutuca 0.9.46 → 0.9.48

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.
@@ -3927,29 +3927,48 @@ function findHandlers(comp, eventIds, vid, eventName) {
3927
3927
  }
3928
3928
  return null;
3929
3929
  }
3930
+
3931
+ class StepCtx {
3932
+ constructor(comp, nodeIds, idx, vid) {
3933
+ this.comp = comp;
3934
+ this.nodeIds = nodeIds;
3935
+ this.idx = idx;
3936
+ this.vid = vid;
3937
+ }
3938
+ get meta() {
3939
+ return this.nodeIds[this.idx];
3940
+ }
3941
+ get key() {
3942
+ const m = this.meta;
3943
+ return m.si !== undefined ? +m.si : m.sk;
3944
+ }
3945
+ get hasKey() {
3946
+ const m = this.meta;
3947
+ return m.si !== undefined || m.sk !== undefined;
3948
+ }
3949
+ next() {
3950
+ return this.idx + 1 < this.nodeIds.length ? new StepCtx(this.comp, this.nodeIds, this.idx + 1, this.vid) : null;
3951
+ }
3952
+ resolveNode() {
3953
+ return this.comp.getNodeForId(+this.meta.nid, this.vid);
3954
+ }
3955
+ applyKey(pi) {
3956
+ if (pi === null)
3957
+ return null;
3958
+ const m = this.meta;
3959
+ if (m.si !== undefined)
3960
+ return pi.withIndex(+m.si);
3961
+ if (m.sk !== undefined)
3962
+ return pi.withKey(m.sk);
3963
+ return pi;
3964
+ }
3965
+ }
3930
3966
  function resolvePathStep(comp, nodeIds, vid) {
3931
3967
  for (let i = 0;i < nodeIds.length; i++) {
3932
- const meta = nodeIds[i];
3933
- const node = comp.getNodeForId(+meta.nid, vid);
3934
- const key = meta.si !== undefined ? +meta.si : meta.sk;
3935
- if (node.pathInNext) {
3936
- const next = nodeIds[i + 1];
3937
- if (!next)
3938
- continue;
3939
- const nextNode = comp.getNodeForId(+next.nid, vid);
3940
- const nKey = next.si !== undefined ? +next.si : next.sk;
3941
- if (nextNode.toPathItemRenderIt && nKey !== undefined)
3942
- return nextNode.toPathItemRenderIt(nKey);
3943
- const pi2 = nextNode.val.toPathItem();
3944
- if (pi2 !== null)
3945
- return next.si !== undefined ? pi2.withIndex(nKey) : next.sk ? pi2.withKey(nKey) : pi2;
3946
- continue;
3947
- }
3948
- if (key !== undefined && node.toPathItemEachBind)
3949
- return node.toPathItemEachBind(key);
3950
- const pi = node.toPathItem();
3951
- if (pi !== null)
3952
- return meta.si !== undefined ? pi.withIndex(+meta.si) : meta.sk ? pi.withKey(meta.sk) : pi;
3968
+ const ctx = new StepCtx(comp, nodeIds, i, vid);
3969
+ const step = ctx.resolveNode().toPathStep(ctx);
3970
+ if (step !== null)
3971
+ return step;
3953
3972
  }
3954
3973
  return null;
3955
3974
  }
@@ -5094,8 +5113,8 @@ var init_anode = __esm(() => {
5094
5113
  this.nodeId = nodeId;
5095
5114
  this.val = val;
5096
5115
  }
5097
- toPathItem() {
5098
- return this.val.toPathItem();
5116
+ toPathStep(ctx) {
5117
+ return ctx.applyKey(this.val?.toPathItem?.() ?? null);
5099
5118
  }
5100
5119
  static parse(html, px) {
5101
5120
  const nodes = px.parseHTML(html);
@@ -5209,7 +5228,15 @@ var init_anode = __esm(() => {
5209
5228
  const newStack = stack.enter(stack.it, {}, true);
5210
5229
  return rx.renderIt(newStack, this.nodeId, "", this.viewId);
5211
5230
  }
5212
- pathInNext = true;
5231
+ toPathStep(ctx) {
5232
+ const next = ctx.next();
5233
+ if (next === null)
5234
+ return null;
5235
+ const nextNode = next.resolveNode();
5236
+ if (nextNode instanceof EachNode && next.hasKey)
5237
+ return new EachRenderItStep(nextNode.val.name, next.key);
5238
+ return null;
5239
+ }
5213
5240
  };
5214
5241
  RenderEachNode = class RenderEachNode extends RenderViewId {
5215
5242
  constructor(nodeId, val, viewId) {
@@ -5296,7 +5323,7 @@ var init_anode = __esm(() => {
5296
5323
  const binds = this.val.eval(stack)?.call(stack.it) ?? {};
5297
5324
  return this.node.render(stack.enter(stack.it, binds, false), rx);
5298
5325
  }
5299
- toPathItem() {
5326
+ toPathStep(_ctx) {
5300
5327
  return new BindStep({});
5301
5328
  }
5302
5329
  wrapNode(node) {
@@ -5313,14 +5340,8 @@ var init_anode = __esm(() => {
5313
5340
  render(stack, rx) {
5314
5341
  return rx.renderEachWhen(stack, this.iterInfo, this.node, this.nodeId);
5315
5342
  }
5316
- toPathItem() {
5317
- return new BindStep({});
5318
- }
5319
- toPathItemRenderIt(key) {
5320
- return new EachRenderItStep(this.val.name, key);
5321
- }
5322
- toPathItemEachBind(key) {
5323
- return new EachBindStep(this.val, key);
5343
+ toPathStep(ctx) {
5344
+ return ctx.hasKey ? new EachBindStep(this.val, ctx.key) : null;
5324
5345
  }
5325
5346
  static register = true;
5326
5347
  };
@@ -5406,7 +5427,8 @@ class ComponentStack {
5406
5427
  enter() {
5407
5428
  return new ComponentStack(this.comps, this);
5408
5429
  }
5409
- registerComponents(comps, aliases2 = {}) {
5430
+ registerComponents(comps, opts) {
5431
+ const { aliases: aliases2 = {} } = opts ?? {};
5410
5432
  for (let i = 0;i < comps.length; i++) {
5411
5433
  const comp = comps[i];
5412
5434
  comp.scope = this.enter();
@@ -9098,9 +9120,9 @@ class App {
9098
9120
  sendAtRoot(name, args, opts) {
9099
9121
  this.transactor.pushSend(new Path([]), name, args, opts);
9100
9122
  }
9101
- registerComponents(comps, aliases2) {
9123
+ registerComponents(comps, opts) {
9102
9124
  const scope = this.compStack.enter();
9103
- scope.registerComponents(comps, aliases2);
9125
+ scope.registerComponents(comps, opts);
9104
9126
  return scope;
9105
9127
  }
9106
9128
  _transactNextBatch(maxRunTimeMs = 10) {
@@ -13552,8 +13574,8 @@ class Renderer {
13552
13574
  renderEachWhen(stack, iterInfo, view, nid) {
13553
13575
  const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
13554
13576
  const r = [];
13555
- const iterData = loopWith.call(stack.it, seq);
13556
13577
  const it = stack.it;
13578
+ const iterData = loopWith.call(it, seq);
13557
13579
  this.getSeqInfo(seq)(seq, (key, value, attrName) => {
13558
13580
  if (filter.call(it, key, value, iterData)) {
13559
13581
  const cachePath = enricher ? [it, value] : [value];
@@ -3538,29 +3538,48 @@ function findHandlers(comp, eventIds, vid, eventName) {
3538
3538
  }
3539
3539
  return null;
3540
3540
  }
3541
+
3542
+ class StepCtx {
3543
+ constructor(comp, nodeIds, idx, vid) {
3544
+ this.comp = comp;
3545
+ this.nodeIds = nodeIds;
3546
+ this.idx = idx;
3547
+ this.vid = vid;
3548
+ }
3549
+ get meta() {
3550
+ return this.nodeIds[this.idx];
3551
+ }
3552
+ get key() {
3553
+ const m = this.meta;
3554
+ return m.si !== undefined ? +m.si : m.sk;
3555
+ }
3556
+ get hasKey() {
3557
+ const m = this.meta;
3558
+ return m.si !== undefined || m.sk !== undefined;
3559
+ }
3560
+ next() {
3561
+ return this.idx + 1 < this.nodeIds.length ? new StepCtx(this.comp, this.nodeIds, this.idx + 1, this.vid) : null;
3562
+ }
3563
+ resolveNode() {
3564
+ return this.comp.getNodeForId(+this.meta.nid, this.vid);
3565
+ }
3566
+ applyKey(pi) {
3567
+ if (pi === null)
3568
+ return null;
3569
+ const m = this.meta;
3570
+ if (m.si !== undefined)
3571
+ return pi.withIndex(+m.si);
3572
+ if (m.sk !== undefined)
3573
+ return pi.withKey(m.sk);
3574
+ return pi;
3575
+ }
3576
+ }
3541
3577
  function resolvePathStep(comp, nodeIds, vid) {
3542
3578
  for (let i = 0;i < nodeIds.length; i++) {
3543
- const meta = nodeIds[i];
3544
- const node = comp.getNodeForId(+meta.nid, vid);
3545
- const key = meta.si !== undefined ? +meta.si : meta.sk;
3546
- if (node.pathInNext) {
3547
- const next = nodeIds[i + 1];
3548
- if (!next)
3549
- continue;
3550
- const nextNode = comp.getNodeForId(+next.nid, vid);
3551
- const nKey = next.si !== undefined ? +next.si : next.sk;
3552
- if (nextNode.toPathItemRenderIt && nKey !== undefined)
3553
- return nextNode.toPathItemRenderIt(nKey);
3554
- const pi2 = nextNode.val.toPathItem();
3555
- if (pi2 !== null)
3556
- return next.si !== undefined ? pi2.withIndex(nKey) : next.sk ? pi2.withKey(nKey) : pi2;
3557
- continue;
3558
- }
3559
- if (key !== undefined && node.toPathItemEachBind)
3560
- return node.toPathItemEachBind(key);
3561
- const pi = node.toPathItem();
3562
- if (pi !== null)
3563
- return meta.si !== undefined ? pi.withIndex(+meta.si) : meta.sk ? pi.withKey(meta.sk) : pi;
3579
+ const ctx = new StepCtx(comp, nodeIds, i, vid);
3580
+ const step = ctx.resolveNode().toPathStep(ctx);
3581
+ if (step !== null)
3582
+ return step;
3564
3583
  }
3565
3584
  return null;
3566
3585
  }
@@ -4360,8 +4379,8 @@ class ANode extends BaseNode {
4360
4379
  this.nodeId = nodeId;
4361
4380
  this.val = val;
4362
4381
  }
4363
- toPathItem() {
4364
- return this.val.toPathItem();
4382
+ toPathStep(ctx) {
4383
+ return ctx.applyKey(this.val?.toPathItem?.() ?? null);
4365
4384
  }
4366
4385
  static parse(html, px) {
4367
4386
  const nodes = px.parseHTML(html);
@@ -4579,7 +4598,15 @@ class RenderItNode extends RenderViewId {
4579
4598
  const newStack = stack.enter(stack.it, {}, true);
4580
4599
  return rx.renderIt(newStack, this.nodeId, "", this.viewId);
4581
4600
  }
4582
- pathInNext = true;
4601
+ toPathStep(ctx) {
4602
+ const next = ctx.next();
4603
+ if (next === null)
4604
+ return null;
4605
+ const nextNode = next.resolveNode();
4606
+ if (nextNode instanceof EachNode && next.hasKey)
4607
+ return new EachRenderItStep(nextNode.val.name, next.key);
4608
+ return null;
4609
+ }
4583
4610
  }
4584
4611
 
4585
4612
  class RenderEachNode extends RenderViewId {
@@ -4675,7 +4702,7 @@ class ScopeNode extends WrapperNode {
4675
4702
  const binds = this.val.eval(stack)?.call(stack.it) ?? {};
4676
4703
  return this.node.render(stack.enter(stack.it, binds, false), rx);
4677
4704
  }
4678
- toPathItem() {
4705
+ toPathStep(_ctx) {
4679
4706
  return new BindStep({});
4680
4707
  }
4681
4708
  wrapNode(node) {
@@ -4693,14 +4720,8 @@ class EachNode extends WrapperNode {
4693
4720
  render(stack, rx) {
4694
4721
  return rx.renderEachWhen(stack, this.iterInfo, this.node, this.nodeId);
4695
4722
  }
4696
- toPathItem() {
4697
- return new BindStep({});
4698
- }
4699
- toPathItemRenderIt(key) {
4700
- return new EachRenderItStep(this.val.name, key);
4701
- }
4702
- toPathItemEachBind(key) {
4703
- return new EachBindStep(this.val, key);
4723
+ toPathStep(ctx) {
4724
+ return ctx.hasKey ? new EachBindStep(this.val, ctx.key) : null;
4704
4725
  }
4705
4726
  static register = true;
4706
4727
  }
@@ -8325,7 +8346,8 @@ class ComponentStack {
8325
8346
  enter() {
8326
8347
  return new ComponentStack(this.comps, this);
8327
8348
  }
8328
- registerComponents(comps, aliases2 = {}) {
8349
+ registerComponents(comps, opts) {
8350
+ const { aliases: aliases2 = {} } = opts ?? {};
8329
8351
  for (let i = 0;i < comps.length; i++) {
8330
8352
  const comp = comps[i];
8331
8353
  comp.scope = this.enter();
@@ -9417,9 +9439,9 @@ class App {
9417
9439
  sendAtRoot(name, args, opts) {
9418
9440
  this.transactor.pushSend(new Path([]), name, args, opts);
9419
9441
  }
9420
- registerComponents(comps, aliases2) {
9442
+ registerComponents(comps, opts) {
9421
9443
  const scope = this.compStack.enter();
9422
- scope.registerComponents(comps, aliases2);
9444
+ scope.registerComponents(comps, opts);
9423
9445
  return scope;
9424
9446
  }
9425
9447
  _transactNextBatch(maxRunTimeMs = 10) {
@@ -14450,8 +14472,8 @@ class Renderer {
14450
14472
  renderEachWhen(stack, iterInfo, view, nid) {
14451
14473
  const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
14452
14474
  const r = [];
14453
- const iterData = loopWith.call(stack.it, seq);
14454
14475
  const it = stack.it;
14476
+ const iterData = loopWith.call(it, seq);
14455
14477
  this.getSeqInfo(seq)(seq, (key, value, attrName) => {
14456
14478
  if (filter.call(it, key, value, iterData)) {
14457
14479
  const cachePath = enricher ? [it, value] : [value];