tutuca 0.9.57 → 0.9.59

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.
@@ -3306,6 +3306,9 @@ class Step {
3306
3306
  enterFrame(stack, _prev, next) {
3307
3307
  return stack.enter(next, {}, true);
3308
3308
  }
3309
+ toAbstractPathStep() {
3310
+ return this;
3311
+ }
3309
3312
  }
3310
3313
 
3311
3314
  class BindStep extends Step {
@@ -3328,6 +3331,9 @@ class BindStep extends Step {
3328
3331
  withKey(key) {
3329
3332
  return new BindStep({ ...this.binds, key });
3330
3333
  }
3334
+ toAbstractPathStep() {
3335
+ return null;
3336
+ }
3331
3337
  }
3332
3338
 
3333
3339
  class FieldStep extends Step {
@@ -3342,14 +3348,14 @@ class FieldStep extends Step {
3342
3348
  return root.set(this.field, v);
3343
3349
  }
3344
3350
  withIndex(i) {
3345
- return new SeqIndexStep(this.field, i);
3351
+ return new SeqStep(this.field, i);
3346
3352
  }
3347
3353
  withKey(k) {
3348
- return new SeqKeyStep(this.field, k);
3354
+ return new SeqStep(this.field, k);
3349
3355
  }
3350
3356
  }
3351
3357
 
3352
- class FieldSeqStep extends Step {
3358
+ class SeqStep extends Step {
3353
3359
  constructor(field, key) {
3354
3360
  super();
3355
3361
  this.field = field;
@@ -3360,19 +3366,14 @@ class FieldSeqStep extends Step {
3360
3366
  return o?.get ? o.get(this.key, dval) : dval;
3361
3367
  }
3362
3368
  setValue(root, v) {
3363
- return root.set(this.field, root.get(this.field).set(this.key, v));
3369
+ const seq = root?.get(this.field, null);
3370
+ return seq ? root.set(this.field, seq.set(this.key, v)) : root;
3364
3371
  }
3365
3372
  enterFrame(stack, _prev, next) {
3366
3373
  return stack.enter(next, { key: this.key }, true);
3367
3374
  }
3368
3375
  }
3369
3376
 
3370
- class SeqKeyStep extends FieldSeqStep {
3371
- }
3372
-
3373
- class SeqIndexStep extends FieldSeqStep {
3374
- }
3375
-
3376
3377
  class SeqAccessStep extends Step {
3377
3378
  constructor(seqField, keyField) {
3378
3379
  super();
@@ -3407,25 +3408,18 @@ class EachBindStep extends Step {
3407
3408
  const item = this.seqVal.eval(stack)?.get(this.key, null);
3408
3409
  return stack.enter(next, { key: this.key, value: item }, false);
3409
3410
  }
3411
+ toAbstractPathStep() {
3412
+ return null;
3413
+ }
3410
3414
  }
3411
3415
 
3412
- class EachRenderItStep extends Step {
3413
- constructor(seqField, key) {
3414
- super();
3415
- this.seqField = seqField;
3416
- this.key = key;
3417
- }
3418
- lookup(v, dval = null) {
3419
- const seq = v?.get(this.seqField, null);
3420
- return seq?.get ? seq.get(this.key, dval) : dval;
3421
- }
3422
- setValue(root, v) {
3423
- const seq = root?.get(this.seqField, null);
3424
- return seq ? root.set(this.seqField, seq.set(this.key, v)) : root;
3425
- }
3416
+ class EachRenderItStep extends SeqStep {
3426
3417
  enterFrame(stack, _prev, next) {
3427
3418
  return stack.enter(next, { key: this.key, value: next }, false).enter(next, {}, true);
3428
3419
  }
3420
+ toAbstractPathStep() {
3421
+ return new SeqStep(this.field, this.key);
3422
+ }
3429
3423
  }
3430
3424
 
3431
3425
  class Path {
@@ -3438,6 +3432,15 @@ class Path {
3438
3432
  popStep() {
3439
3433
  return new Path(this.steps.slice(0, -1));
3440
3434
  }
3435
+ compact() {
3436
+ const out = [];
3437
+ for (const step of this.steps) {
3438
+ const s = step.toAbstractPathStep();
3439
+ if (s !== null)
3440
+ out.push(s);
3441
+ }
3442
+ return new Path(out);
3443
+ }
3441
3444
  lookup(v, dval = null) {
3442
3445
  let curVal = v;
3443
3446
  for (const step of this.steps) {
@@ -3478,6 +3481,7 @@ class Path {
3478
3481
  }
3479
3482
  static fromNodeAndEventName(node, eventName, rootNode, maxDepth, comps, stopOnNoEvent = true) {
3480
3483
  const pathSteps = [];
3484
+ const bubbles = BUBBLING_EVENTS.has(eventName);
3481
3485
  let depth = 0;
3482
3486
  let eventIds = [];
3483
3487
  let handlers = null;
@@ -3490,16 +3494,24 @@ class Path {
3490
3494
  if (eid !== undefined)
3491
3495
  eventIds.push(eid);
3492
3496
  if (cid !== undefined) {
3493
- const comp = comps.getComponentForId(+cid, vid);
3494
- if (isLeafComponent) {
3497
+ const comp = comps.getComponentForId(+cid);
3498
+ let pushStep = true;
3499
+ if (handlers === null && (isLeafComponent || bubbles)) {
3495
3500
  handlers = findHandlers(comp, eventIds, vid, eventName);
3496
- if (handlers === null && stopOnNoEvent)
3497
- return NO_EVENT_INFO;
3498
- isLeafComponent = false;
3501
+ if (handlers === null) {
3502
+ if (isLeafComponent && stopOnNoEvent && !bubbles)
3503
+ return NO_EVENT_INFO;
3504
+ } else if (!isLeafComponent) {
3505
+ pathSteps.length = 0;
3506
+ pushStep = false;
3507
+ }
3508
+ }
3509
+ isLeafComponent = false;
3510
+ if (pushStep) {
3511
+ const step = resolvePathStep(comp, nodeIds, vid);
3512
+ if (step)
3513
+ pathSteps.push(step);
3499
3514
  }
3500
- const step = resolvePathStep(comp, nodeIds, vid);
3501
- if (step)
3502
- pathSteps.push(step);
3503
3515
  eventIds = [];
3504
3516
  nodeIds = [];
3505
3517
  }
@@ -3584,6 +3596,7 @@ function resolvePathStep(comp, nodeIds, vid) {
3584
3596
  return null;
3585
3597
  }
3586
3598
  var NO_EVENT_INFO = [null, null];
3599
+ var BUBBLING_EVENTS = new Set(["drop"]);
3587
3600
 
3588
3601
  class PathBuilder {
3589
3602
  constructor() {
@@ -3597,10 +3610,10 @@ class PathBuilder {
3597
3610
  return this.add(new FieldStep(name));
3598
3611
  }
3599
3612
  index(name, index) {
3600
- return this.add(new SeqIndexStep(name, index));
3613
+ return this.add(new SeqStep(name, index));
3601
3614
  }
3602
3615
  key(name, key) {
3603
- return this.add(new SeqKeyStep(name, key));
3616
+ return this.add(new SeqStep(name, key));
3604
3617
  }
3605
3618
  }
3606
3619
 
@@ -3917,7 +3930,7 @@ class SeqAccessVal extends RenderVal {
3917
3930
  }
3918
3931
  eval(stack) {
3919
3932
  const key = this.keyVal.eval(stack);
3920
- return this.seqVal.eval(stack).get(key, null);
3933
+ return this.seqVal.eval(stack)?.get(key, null);
3921
3934
  }
3922
3935
  toString() {
3923
3936
  return `${this.seqVal}[${this.keyVal}]`;
@@ -8645,6 +8658,8 @@ class Component {
8645
8658
  this.extra[key] = o[key];
8646
8659
  }
8647
8660
  compile(ParseContext2) {
8661
+ for (const name in this.views)
8662
+ this.views[name].compile(new ParseContext2, this.scope, this.id);
8648
8663
  for (const key in this._rawDynamic) {
8649
8664
  const dinfo = this._rawDynamic[key];
8650
8665
  if (isString(dinfo)) {
@@ -8657,11 +8672,9 @@ class Component {
8657
8672
  this.dynamic[key] = new DynamicAlias(key, val, compName, dynName);
8658
8673
  }
8659
8674
  }
8660
- for (const name in this.views)
8661
- this.views[name].compile(new ParseContext2, this.scope, this.id);
8662
8675
  }
8663
8676
  make(args, opts) {
8664
- return this.Class.make(args, opts);
8677
+ return this.Class.make(args, opts ?? { scope: this.scope });
8665
8678
  }
8666
8679
  getView(name) {
8667
8680
  return this.views[name] ?? this.views.main;
@@ -8857,9 +8870,9 @@ class Transactor {
8857
8870
  pushSend(path, name, args = [], opts = {}, parent = null) {
8858
8871
  this.pushTransaction(new SendEvent(path, this, name, args, parent, opts));
8859
8872
  }
8860
- pushBubble(path, name, args = [], opts = {}, parent = null) {
8873
+ pushBubble(path, name, args = [], opts = {}, parent = null, targetPath = null) {
8861
8874
  const newOpts = opts.skipSelf ? { ...opts, skipSelf: false } : opts;
8862
- this.pushTransaction(new BubbleEvent(path, this, name, args, parent, newOpts));
8875
+ this.pushTransaction(new BubbleEvent(path, this, name, args, parent, newOpts, targetPath));
8863
8876
  }
8864
8877
  async pushRequest(path, name, args = [], opts = {}, parent = null) {
8865
8878
  const curRoot = this.state.val;
@@ -8972,14 +8985,15 @@ class InputEvent extends Transaction {
8972
8985
  getHandlerAndArgs(root, _instance, comps) {
8973
8986
  const stack = this.buildStack(root, comps);
8974
8987
  const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
8988
+ const path = this.path.compact();
8975
8989
  let dispatcher;
8976
8990
  for (let i = 0;i < args.length; i++) {
8977
8991
  if (args[i]?.toHandlerArg) {
8978
- dispatcher ??= new Dispatcher(this.path, this.transactor, this);
8992
+ dispatcher ??= new Dispatcher(path, this.transactor, this);
8979
8993
  args[i] = args[i].toHandlerArg(dispatcher);
8980
8994
  }
8981
8995
  }
8982
- args.push(new EventContext(this.path, this.transactor, this));
8996
+ args.push(new EventContext(path, this.transactor, this));
8983
8997
  return [handler, args];
8984
8998
  }
8985
8999
  lookupName(name) {
@@ -9031,6 +9045,7 @@ class NameArgsTransaction extends Transaction {
9031
9045
  this.name = name;
9032
9046
  this.args = args;
9033
9047
  this.opts = opts;
9048
+ this.targetPath = path;
9034
9049
  }
9035
9050
  handlerProp = null;
9036
9051
  getHandlerForName(comp) {
@@ -9053,22 +9068,25 @@ class SendEvent extends NameArgsTransaction {
9053
9068
  return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
9054
9069
  }
9055
9070
  afterTransaction() {
9056
- const { path, name, args, opts } = this;
9071
+ const { path, name, args, opts, targetPath } = this;
9057
9072
  if (opts.bubbles && path.steps.length > 0)
9058
- this.transactor.pushBubble(path.popStep(), name, args, opts, this);
9073
+ this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
9059
9074
  }
9060
9075
  }
9061
9076
 
9062
9077
  class BubbleEvent extends SendEvent {
9063
9078
  handlerProp = "bubble";
9079
+ constructor(path, transactor, name, args, parent, opts, targetPath) {
9080
+ super(path, transactor, name, args, parent, opts);
9081
+ this.targetPath = targetPath ?? path;
9082
+ }
9064
9083
  stopPropagation() {
9065
9084
  this.opts.bubbles = false;
9066
9085
  }
9067
9086
  }
9068
9087
 
9069
9088
  class Task {
9070
- constructor(info) {
9071
- this.info = info;
9089
+ constructor() {
9072
9090
  this.deps = [];
9073
9091
  this.val = this.resolve = this.reject = null;
9074
9092
  this.promise = new Promise((res, rej) => {
@@ -9127,6 +9145,9 @@ class EventContext extends Dispatcher {
9127
9145
  get name() {
9128
9146
  return this.parent?.name ?? null;
9129
9147
  }
9148
+ get targetPath() {
9149
+ return this.parent.targetPath;
9150
+ }
9130
9151
  stopPropagation() {
9131
9152
  return this.parent.stopPropagation();
9132
9153
  }
@@ -9510,7 +9531,7 @@ class App {
9510
9531
  }
9511
9532
  _dispatchEvent(e) {
9512
9533
  const { type: type3 } = e;
9513
- const isDrag = type3 === "dragover" || type3 === "dragstart" || type3 === "dragend";
9534
+ const isDrag = type3 === "dragover" || type3 === "dragstart" || type3 === "dragend" || type3 === "drop";
9514
9535
  const { rootNode: root, maxEventNodeDepth: maxDepth, comps, transactor } = this;
9515
9536
  const [path, handlers] = Path.fromEvent(e, root, maxDepth, comps, !isDrag);
9516
9537
  if (isDrag)
@@ -9546,7 +9567,7 @@ class App {
9546
9567
  if (!_touch.active) {
9547
9568
  const dx = clientX - _touch.startX;
9548
9569
  const dy = clientY - _touch.startY;
9549
- if (dx * dx + dy * dy < TOUCH_DRAG_THRESHOLD_SQ)
9570
+ if (dx * dx + dy * dy < 100)
9550
9571
  return;
9551
9572
  _touch.active = true;
9552
9573
  e.preventDefault();
@@ -9582,6 +9603,9 @@ class App {
9582
9603
  const dragType = e.target.dataset.dragtype ?? "?";
9583
9604
  const stack = path.buildStack(this.makeStack(rootValue));
9584
9605
  this.dragInfo = new DragInfo(path, stack, e, value, dragType, e.target);
9606
+ } else if (type3 === "drop") {
9607
+ e.preventDefault();
9608
+ this._cleanDragOverAttrs();
9585
9609
  } else {
9586
9610
  if (this.dragInfo !== null) {
9587
9611
  delete this.dragInfo.node.dataset.dragging;
@@ -9619,11 +9643,14 @@ class App {
9619
9643
  }
9620
9644
  this._compiled = true;
9621
9645
  }
9646
+ subscribeToEvents(eventNames) {
9647
+ for (const name of eventNames)
9648
+ this.rootNode.addEventListener(name, this, listenerOpts(name));
9649
+ }
9622
9650
  start(opts) {
9623
9651
  if (!this._compiled)
9624
9652
  this.compile();
9625
- for (const name of this._eventNames)
9626
- this.rootNode.addEventListener(name, this, listenerOpts(name));
9653
+ this.subscribeToEvents(this._eventNames);
9627
9654
  this.onChange((info) => {
9628
9655
  if (info.val !== info.old)
9629
9656
  this.render();
@@ -9677,8 +9704,6 @@ function injectCss(nodeId, style, styleTarget = document.head) {
9677
9704
  styleNode.innerHTML = style;
9678
9705
  styleTarget.appendChild(styleNode);
9679
9706
  }
9680
- var TOUCH_DRAG_THRESHOLD_PX = 10;
9681
- var TOUCH_DRAG_THRESHOLD_SQ = TOUCH_DRAG_THRESHOLD_PX * TOUCH_DRAG_THRESHOLD_PX;
9682
9707
  var NOOP = () => {};
9683
9708
  function findTouch(e, id) {
9684
9709
  for (const t of e.changedTouches)
@@ -14427,11 +14452,10 @@ class ClassBuilder {
14427
14452
  const field = fields[key];
14428
14453
  if (compFields.has(key))
14429
14454
  args[key] = mkCompField(field, opts.scope, inArgs[key]);
14430
- else if (field === undefined) {
14455
+ else if (field === undefined)
14431
14456
  console.warn("extra argument to constructor:", name, key, inArgs);
14432
- continue;
14433
- }
14434
- args[key] = field.coerceOrDefault(inArgs[key]);
14457
+ else
14458
+ args[key] = field.coerceOrDefault(inArgs[key]);
14435
14459
  }
14436
14460
  for (const key of compFields)
14437
14461
  if (args[key] === undefined)
@@ -14456,15 +14480,12 @@ class ClassBuilder {
14456
14480
  return Class;
14457
14481
  }
14458
14482
  methods(proto) {
14459
- return this._mergeProto(this._methods, proto, "method");
14483
+ for (const k in proto)
14484
+ this._methods[k] = proto[k];
14460
14485
  }
14461
14486
  statics(proto) {
14462
- return this._mergeProto(this._statics, proto, "static");
14463
- }
14464
- _mergeProto(target, proto, _name) {
14465
14487
  for (const k in proto)
14466
- target[k] = proto[k];
14467
- return this;
14488
+ this._statics[k] = proto[k];
14468
14489
  }
14469
14490
  addField(name, dval, FieldCls) {
14470
14491
  const field = new FieldCls(name, dval);
@@ -14635,7 +14656,7 @@ class Renderer {
14635
14656
  }
14636
14657
  renderRoot(stack, val, viewName = null) {
14637
14658
  const comp = this.comps.getCompFor(val);
14638
- const nid = comp.getView(viewName).anode.nodeId ?? null;
14659
+ const nid = comp?.getView(viewName).anode.nodeId ?? null;
14639
14660
  return comp ? this._rValComp(stack, val, comp, nid, "ROOT", viewName) : null;
14640
14661
  }
14641
14662
  renderIt(stack, nodeId, key, viewName) {
@@ -14643,7 +14664,7 @@ class Renderer {
14643
14664
  return comp ? this._rValComp(stack, stack.it, comp, nodeId, key, viewName) : null;
14644
14665
  }
14645
14666
  _rValComp(stack, val, comp, nid, key, viewName) {
14646
- const cacheKey = `${viewName ?? stack.viewsId ?? ""}${nid}-${key}`;
14667
+ const cacheKey = `${viewName ?? stack.viewsId ?? ""}-${nid}-${key}`;
14647
14668
  const cachePath = [val];
14648
14669
  stack._pushDynBindValuesToArray(cachePath, comp.dynamic);
14649
14670
  const cachedNode = this.cache.get(cachePath, cacheKey);