tutuca 0.13.0 → 0.13.2

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.
@@ -1069,9 +1069,10 @@ function resolvePathStep(comp, nodeIds, vid) {
1069
1069
  }
1070
1070
  return null;
1071
1071
  }
1072
- var NONE, readKey, writeKey, readSeqKey, writeSeqKey, Step, BindStep, ScopeBindStep, FieldStep, SeqStep, SeqAccessStep, EachBindStep, EachRenderItStep, DynStep, DynEachStep, Path, StepCtx, NO_EVENT_INFO, BUBBLING_EVENTS, PathBuilder;
1072
+ var NONE, readKey, writeKey, writeSeqKey, Step, BindStep, ScopeBindStep, FieldStep, SeqStep, SeqAccessStep, EachBindStep, EachRenderItStep, DynStep, DynEachStep, Path, StepCtx, NO_EVENT_INFO, BUBBLING_EVENTS, PathBuilder;
1073
1073
  var init_path = __esm({
1074
1074
  "src/path.js"() {
1075
+ init_collection();
1075
1076
  init_immer2();
1076
1077
  NONE = /* @__PURE__ */ Symbol("NONE");
1077
1078
  readKey = (value, key, dval = null) => {
@@ -1087,11 +1088,6 @@ var init_path = __esm({
1087
1088
  value.add(next);
1088
1089
  } else value[key] = next;
1089
1090
  };
1090
- readSeqKey = (value, key, dval = null) => {
1091
- const direct = readKey(value, key, NONE);
1092
- if (direct !== NONE) return direct;
1093
- return typeof value?.get === "function" ? value.get(key, dval) : dval;
1094
- };
1095
1091
  writeSeqKey = (value, key, next) => {
1096
1092
  if (value instanceof Map || value instanceof Set || Array.isArray(value) || Object.hasOwn(value, key))
1097
1093
  writeKey(value, key, next);
@@ -1104,7 +1100,7 @@ var init_path = __esm({
1104
1100
  }
1105
1101
  setDraftValue(_root, _v) {
1106
1102
  }
1107
- enterFrame(stack, _prev, next) {
1103
+ enterFrame(stack, next) {
1108
1104
  return stack.enter(next, {}, true);
1109
1105
  }
1110
1106
  toAbstractPathStep() {
@@ -1130,7 +1126,7 @@ var init_path = __esm({
1130
1126
  lookup(v, _dval) {
1131
1127
  return v;
1132
1128
  }
1133
- enterFrame(stack, _prev, next) {
1129
+ enterFrame(stack, next) {
1134
1130
  return stack.enter(next, { ...this.binds }, false);
1135
1131
  }
1136
1132
  withIndex(i) {
@@ -1148,7 +1144,7 @@ var init_path = __esm({
1148
1144
  super(binds);
1149
1145
  this.val = val;
1150
1146
  }
1151
- enterFrame(stack, _prev, next) {
1147
+ enterFrame(stack, next) {
1152
1148
  const dyn = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
1153
1149
  return stack.enter(next, { ...this.binds, ...dyn }, false);
1154
1150
  }
@@ -1187,13 +1183,13 @@ var init_path = __esm({
1187
1183
  this.key = key;
1188
1184
  }
1189
1185
  lookup(v, dval = null) {
1190
- return readSeqKey(readKey(v, this.field, null), this.key, dval);
1186
+ return seqGet(readKey(v, this.field, null), this.key, dval);
1191
1187
  }
1192
1188
  setDraftValue(root, v) {
1193
1189
  const seq = readKey(root, this.field, null);
1194
1190
  if (seq != null) writeSeqKey(seq, this.key, v);
1195
1191
  }
1196
- enterFrame(stack, _prev, next) {
1192
+ enterFrame(stack, next) {
1197
1193
  return stack.enter(next, { key: this.key }, true);
1198
1194
  }
1199
1195
  toKey() {
@@ -1209,7 +1205,7 @@ var init_path = __esm({
1209
1205
  lookup(v, dval = null) {
1210
1206
  const seq = readKey(v, this.seqField, NONE);
1211
1207
  const key = readKey(v, this.keyField, NONE);
1212
- return key !== NONE && seq !== NONE ? readSeqKey(seq, key, dval) : dval;
1208
+ return key !== NONE && seq !== NONE ? seqGet(seq, key, dval) : dval;
1213
1209
  }
1214
1210
  setDraftValue(root, v) {
1215
1211
  const seq = readKey(root, this.seqField, NONE);
@@ -1240,7 +1236,7 @@ var init_path = __esm({
1240
1236
  }
1241
1237
  // Replay the renderer's per-item binds (key, value + any @enrich-with binds)
1242
1238
  // so a rebuilt stack matches the one @each rendered with.
1243
- enterFrame(stack, _prev, next) {
1239
+ enterFrame(stack, next) {
1244
1240
  return stack.enter(next, this.iterInfo.enrichBinds(stack, this.key), false);
1245
1241
  }
1246
1242
  toAbstractPathStep() {
@@ -1248,7 +1244,7 @@ var init_path = __esm({
1248
1244
  }
1249
1245
  };
1250
1246
  EachRenderItStep = class extends SeqStep {
1251
- enterFrame(stack, _prev, next) {
1247
+ enterFrame(stack, next) {
1252
1248
  return stack.enter(next, { key: this.key, value: next }, false).enter(next, {}, true);
1253
1249
  }
1254
1250
  toAbstractPathStep() {
@@ -1270,7 +1266,7 @@ var init_path = __esm({
1270
1266
  warnRawDynStep("lookup", this);
1271
1267
  return dval;
1272
1268
  }
1273
- enterFrame(stack, _prev, _next) {
1269
+ enterFrame(stack, _next) {
1274
1270
  warnRawDynStep("enterFrame", this);
1275
1271
  return stack;
1276
1272
  }
@@ -1408,7 +1404,7 @@ var init_path = __esm({
1408
1404
  console.warn("bad PathItem", { root: stack.it, step, path: this });
1409
1405
  return null;
1410
1406
  }
1411
- stack = step.enterFrame(stack, prev, next);
1407
+ stack = step.enterFrame(stack, next);
1412
1408
  prev = next;
1413
1409
  }
1414
1410
  return stack;
@@ -1478,10 +1474,6 @@ var init_path = __esm({
1478
1474
  console.warn("event reconstruction: dynamic-var producer not found", pendingDyns);
1479
1475
  return [new _Path(pathSteps.reverse()), handlers];
1480
1476
  }
1481
- static fromEvent(e, rNode, maxDepth, comps, stopOnNoEvent = true) {
1482
- const { type: type3, target } = e;
1483
- return _Path.fromNodeAndEventName(target, type3, rNode, maxDepth, comps, stopOnNoEvent);
1484
- }
1485
1477
  };
1486
1478
  StepCtx = class _StepCtx {
1487
1479
  constructor(comp, nodeIds, idx, vid) {
@@ -2042,10 +2034,7 @@ function parseIterationDirectives(attributes, px) {
2042
2034
  };
2043
2035
  return { whenVal: parseNamed("when"), loopWithVal: parseNamed("loop-with") };
2044
2036
  }
2045
- function getAttrParser(px) {
2046
- return new AttrParser(px);
2047
- }
2048
- var Attributes, booleanAttrsRaw, booleanAttrs, AttrParser, ConstAttrs, DynAttrs, BaseAttr, Attr, ConstAttr, RawHtmlAttr, NOT_SET_VAL, IfAttr, EventHandler, IntentHandler;
2037
+ var Attributes, booleanAttrsRaw, booleanAttrs, AttrParser, ConstAttrs, DynAttrs, BaseAttr, Attr, ConstAttr, RawHtmlAttr, NOT_SET_VAL, IfAttr, EventHandler;
2049
2038
  var init_attribute = __esm({
2050
2039
  "src/attribute.js"() {
2051
2040
  init_value();
@@ -2054,7 +2043,7 @@ var init_attribute = __esm({
2054
2043
  this.items = items;
2055
2044
  }
2056
2045
  static parse(attributes, px, parseAll = false) {
2057
- return getAttrParser(px).parse(attributes, parseAll);
2046
+ return new AttrParser(px).parse(attributes, parseAll);
2058
2047
  }
2059
2048
  isConstant() {
2060
2049
  return false;
@@ -2297,16 +2286,19 @@ var init_attribute = __esm({
2297
2286
  return r === null ? null : new _EventHandler(r.handlerVal, r.args);
2298
2287
  }
2299
2288
  };
2300
- IntentHandler = class {
2301
- constructor(name, fn) {
2302
- this.name = name;
2303
- this.fn = fn;
2304
- }
2305
- };
2306
2289
  }
2307
2290
  });
2308
2291
 
2309
2292
  // src/iteration.js
2293
+ function bindsForKey({ seq, it, loopWith, enricher, ctx }, key) {
2294
+ const value = seqGet(seq, key, null);
2295
+ const binds = { key, value };
2296
+ if (enricher) {
2297
+ const { iterData } = unpackLoopResult(loopWith.call(it, seq, ctx), seq);
2298
+ callEnricher(enricher, it, binds, key, value, iterData);
2299
+ }
2300
+ return binds;
2301
+ }
2310
2302
  function walkLoopBindings({ seq, it, filter, loopWith, enricher, ctx }, visit) {
2311
2303
  const { iterData, start, end, keys } = unpackLoopResult(loopWith.call(it, seq, ctx), seq);
2312
2304
  const visitOne = (key, value, attrName) => {
@@ -2906,14 +2898,12 @@ function compileModifiers(eventName, names) {
2906
2898
  return w(this, f, args, ctx);
2907
2899
  };
2908
2900
  }
2909
- var BaseNode, TextNode, CommentNode, ChildsNode, DomNode, FragmentNode, maybeFragment, VALID_NODE_RE, ANode, MacroNode, RenderViewId, RenderNode, RenderItNode, RenderTextNode, RenderOnceNode, WrapperNode, ShowNode, HideNode, PushViewNameNode, SlotNode, ScopeNode, EachNode, IterInfo, X_OPS, WRAPPER_NODES, ParseContext, _htmlBlockTags, HTML_BLOCK_TAGS, isBlockDomNode, isEmptyText, isIgnorableXChild, hasMeaningfulChilds, View, NodeEvents, NodeEvent, fwdIfCtxPred, fwdIfKey, fwdCtrl, fwdMeta, fwdAlt, MOD_WRAPPERS_FOR_ANY_EVENT, MOD_WRAPPERS_BY_EVENT, MOD_EFFECTS, NO_WRAPPERS, identityModifierWrapper;
2901
+ var BaseNode, TextNode, CommentNode, ChildsNode, DomNode, FragmentNode, maybeFragment, VALID_NODE_RE, ANode, MacroNode, RenderViewId, RenderNode, RenderItNode, RenderTextNode, RenderOnceNode, WrapperNode, ShowNode, HideNode, PushViewNameNode, SlotNode, ScopeNode, EachNode, IterInfo, X_OPS, WRAPPER_NODES, ParseContext, _htmlBlockTags, HTML_BLOCK_TAGS, isBlockDomNode, isEmptyText, isIgnorableXChild, hasMeaningfulChilds, View, NodeEvents, NodeEvent, fwdIfCtxPred, fwdIfEventPred, fwdIfKey, fwdCtrl, fwdMeta, fwdAlt, MOD_WRAPPERS_FOR_ANY_EVENT, MOD_WRAPPERS_BY_EVENT, MOD_EFFECTS, NO_WRAPPERS, identityModifierWrapper;
2910
2902
  var init_anode = __esm({
2911
2903
  "src/anode.js"() {
2912
2904
  init_attribute();
2913
- init_collection();
2914
2905
  init_iteration();
2915
2906
  init_path();
2916
- init_env();
2917
2907
  init_value();
2918
2908
  init_vdom();
2919
2909
  BaseNode = class {
@@ -3253,20 +3243,11 @@ var init_anode = __esm({
3253
3243
  const enricher = this.enrichWithVal?.evalAsHandler(stack) ?? null;
3254
3244
  return { seq, filter, loopWith, enricher };
3255
3245
  }
3256
- // Rebuild the per-item binds for `key`, mirroring renderEachWhen: seed
3257
- // { key, value }, then run @enrich-with (with @loop-with's iterData) if any.
3246
+ // Rebuild the per-item binds for `key` (see iteration.js bindsForKey).
3258
3247
  enrichBinds(stack, key) {
3259
3248
  const { seq, filter, loopWith, enricher } = this.eval(stack);
3260
- const value = seqGet(seq, key, null);
3261
- const binds = { key, value };
3262
- if (enricher) {
3263
- const { iterData } = unpackLoopResult(
3264
- loopWith.call(stack.it, seq, makeLoopCtx(stack, filter)),
3265
- seq
3266
- );
3267
- callEnricher(enricher, stack.it, binds, key, value, iterData);
3268
- }
3269
- return binds;
3249
+ const ctx = makeLoopCtx(stack, filter);
3250
+ return bindsForKey({ seq, it: stack.it, loopWith, enricher, ctx }, key);
3270
3251
  }
3271
3252
  };
3272
3253
  X_OPS = {
@@ -3440,10 +3421,11 @@ var init_anode = __esm({
3440
3421
  }
3441
3422
  };
3442
3423
  fwdIfCtxPred = (pred) => (w) => (that, f, args, ctx) => pred(ctx) ? w(that, f, args, ctx) : that;
3443
- fwdIfKey = (keyName) => fwdIfCtxPred((ctx) => ctx.e.key === keyName);
3444
- fwdCtrl = fwdIfCtxPred(({ e }) => isMac && e.metaKey || e.ctrlKey);
3445
- fwdMeta = fwdIfCtxPred(({ e }) => e.metaKey);
3446
- fwdAlt = fwdIfCtxPred(({ e }) => e.altKey);
3424
+ fwdIfEventPred = (pred) => fwdIfCtxPred(({ e }) => pred(e));
3425
+ fwdIfKey = (keyName) => fwdIfEventPred(keyIs(keyName));
3426
+ fwdCtrl = fwdIfEventPred(macCtrl);
3427
+ fwdMeta = fwdIfEventPred((e) => e.metaKey);
3428
+ fwdAlt = fwdIfEventPred((e) => e.altKey);
3447
3429
  MOD_WRAPPERS_FOR_ANY_EVENT = {
3448
3430
  ctrl: fwdCtrl,
3449
3431
  cmd: fwdCtrl,
@@ -3470,7 +3452,6 @@ var COMPONENT, Components, ComponentStack, ProvideInfo, LookupInfo, isString, is
3470
3452
  var init_components = __esm({
3471
3453
  "src/components.js"() {
3472
3454
  init_anode();
3473
- init_attribute();
3474
3455
  init_value();
3475
3456
  COMPONENT = /* @__PURE__ */ Symbol.for("tutuca.component");
3476
3457
  Components = class {
@@ -3538,13 +3519,15 @@ var init_components = __esm({
3538
3519
  getCompFor(v) {
3539
3520
  return this.comps.getCompFor(v);
3540
3521
  }
3541
- // Handlers that answer an intent's `lex` leg. A name maps to a LIST, because the leg
3542
- // walks: a handler that returns PASS declines and hands the intent to the next one.
3543
- // A bare function is accepted as a one-element list.
3522
+ // Handlers that answer an intent's `lex` leg. A name maps to a LIST of plain
3523
+ // functions, because the leg walks: a handler that returns PASS declines and hands
3524
+ // the intent to the next one. Each runs with no `this` and takes a dispatcher
3525
+ // context as its final argument; resolving answers, throwing fails. A bare function
3526
+ // is accepted as a one-element list.
3544
3527
  registerIntentHandlers(handlers) {
3545
3528
  for (const name in handlers) {
3546
- const fns = Array.isArray(handlers[name]) ? handlers[name] : [handlers[name]];
3547
- this.intentsByName[name] = fns.map((fn) => new IntentHandler(name, fn));
3529
+ const fns = handlers[name];
3530
+ this.intentsByName[name] = Array.isArray(fns) ? fns : [fns];
3548
3531
  }
3549
3532
  }
3550
3533
  // Innermost scope first, then outward. Concatenated rather than first-match, so a
@@ -3574,14 +3557,12 @@ var init_components = __esm({
3574
3557
  }
3575
3558
  };
3576
3559
  ProvideInfo = class {
3577
- constructor(name, val) {
3578
- this.name = name;
3560
+ constructor(val) {
3579
3561
  this.val = val;
3580
3562
  }
3581
3563
  };
3582
3564
  LookupInfo = class {
3583
- constructor(name, val) {
3584
- this.name = name;
3565
+ constructor(val) {
3585
3566
  this.val = val;
3586
3567
  }
3587
3568
  };
@@ -3629,13 +3610,13 @@ var init_components = __esm({
3629
3610
  continue;
3630
3611
  }
3631
3612
  const val = parseProvide(this._rawProvide[key], ctx);
3632
- if (val) this.provide[key] = new ProvideInfo(key, val);
3613
+ if (val) this.provide[key] = new ProvideInfo(val);
3633
3614
  }
3634
3615
  for (const entry of this._rawLookup) {
3635
3616
  const name = isString(entry) ? entry : isString(entry?.name) ? entry.name : null;
3636
3617
  if (name === null) continue;
3637
3618
  const defStr = isString(entry?.default) ? entry.default : null;
3638
- this.lookup[name] = new LookupInfo(name, defStr === null ? null : parseField(defStr, ctx));
3619
+ this.lookup[name] = new LookupInfo(defStr === null ? null : parseField(defStr, ctx));
3639
3620
  }
3640
3621
  for (const key in this.lookup)
3641
3622
  if (this.provide[key] !== void 0)
@@ -6288,10 +6269,10 @@ function reportUnknownName(lx, code, name, candidates, info) {
6288
6269
  lx.error(code, { ...info, name }, replaceNameSuggestion(name, candidates));
6289
6270
  }
6290
6271
  function checkConsistentAttrVal(lx, val, env, skipNameVal = false, errCtx = null, isRoot = true) {
6291
- const check2 = ATTR_VAL_CHECKERS[val?.constructor.name];
6292
- if (check2 === void 0) return;
6272
+ const check = ATTR_VAL_CHECKERS[val?.constructor.name];
6273
+ if (check === void 0) return;
6293
6274
  const recurse = (sub) => checkConsistentAttrVal(lx, sub, env, skipNameVal, errCtx, false);
6294
- check2({ lx, val, env, errCtx, skipNameVal, recurse, isRoot });
6275
+ check({ lx, val, env, errCtx, skipNameVal, recurse, isRoot });
6295
6276
  }
6296
6277
  function nodeCtxForNode(nodeKind) {
6297
6278
  return NODE_KIND_TO_CTX[nodeKind] ?? null;
@@ -12836,12 +12817,12 @@ function computeViewsId(views) {
12836
12817
  }
12837
12818
  return s === "main" ? "" : s;
12838
12819
  }
12839
- var STOP, NEXT, DEFAULT_LOOKUP_ROUTE, BindFrame, ObjectFrame, Stack;
12820
+ var STOP, NEXT, DEFAULT_ROUTE, BindFrame, ObjectFrame, Stack;
12840
12821
  var init_stack = __esm({
12841
12822
  "src/stack.js"() {
12842
12823
  STOP = /* @__PURE__ */ Symbol("STOP");
12843
12824
  NEXT = /* @__PURE__ */ Symbol("NEXT");
12844
- DEFAULT_LOOKUP_ROUTE = ["dyn", "lex"];
12825
+ DEFAULT_ROUTE = ["dyn", "lex"];
12845
12826
  BindFrame = class {
12846
12827
  constructor(it, binds, isFrame) {
12847
12828
  this.it = it;
@@ -12929,20 +12910,6 @@ var init_stack = __esm({
12929
12910
  lookupBind(name) {
12930
12911
  return lookup(this.binds, name);
12931
12912
  }
12932
- // The `lex` leg: what a name means in the registration scope of the component being
12933
- // rendered. The scope chain holds components, so this leg only ever answers for a
12934
- // type name — for a value name it is a miss, which is why one default route serves
12935
- // both. Guarded: a non-component `it` has no scope to ask.
12936
- _lookupLex(name) {
12937
- return this.comps.getCompFor(this.it)?.scope.lookupComponent(name) ?? null;
12938
- }
12939
- lookupRouted(name, route = DEFAULT_LOOKUP_ROUTE) {
12940
- return routeLookup(
12941
- route,
12942
- () => this._lookupLex(name),
12943
- () => this.lookupDynamic(name)
12944
- );
12945
- }
12946
12913
  lookupFieldRaw(name) {
12947
12914
  return this.it[name] ?? null;
12948
12915
  }
@@ -12975,11 +12942,6 @@ var init_stack = __esm({
12975
12942
  });
12976
12943
 
12977
12944
  // src/oo.js
12978
- function defaultToData(v) {
12979
- if (v instanceof Map) return [...v.entries()];
12980
- if (v instanceof Set) return [...v.values()];
12981
- return v;
12982
- }
12983
12945
  function mkCompField(field, scope, args) {
12984
12946
  const Comp = scope?.lookupComponent(field.type) ?? null;
12985
12947
  if (Comp === null)
@@ -13021,7 +12983,7 @@ function classFromData(name, { fields = {}, methods, statics }) {
13021
12983
  return b.build();
13022
12984
  }
13023
12985
  function validateDraftFields(current2, draft) {
13024
- const meta = current2?.constructor?.[COMPONENT] ?? current2?.constructor?.getMetaClass?.();
12986
+ const meta = metaOf(current2);
13025
12987
  if (!meta) return;
13026
12988
  for (const [name, field] of Object.entries(meta.fields)) {
13027
12989
  const value = draft[name];
@@ -13041,7 +13003,7 @@ function assertNoReservedComponentStatics(statics = {}) {
13041
13003
  }
13042
13004
  }
13043
13005
  }
13044
- var BAD_VALUE2, nullCoercer, Field, Check, CheckTypeAny, CHECK_TYPE_ANY, FnCheck, check, CHECK_TYPE_INT, CHECK_TYPE_FLOAT, CHECK_TYPE_BOOL, CHECK_TYPE_STRING, CHECK_TYPE_LIST, CHECK_TYPE_OBJECT, CHECK_TYPE_MAP, CHECK_TYPE_SET, FieldBool, FieldAny, FieldString, FieldInt, FieldFloat, getTypeName, CheckTypeName, FieldComp, FieldList, FieldObject, FieldMap, FieldSet, ClassBuilder, FIELD_CLASS, fieldsByTypeName, META_KEYS, RESERVED_COMPONENT_STATICS;
13006
+ var BAD_VALUE2, nullCoercer, Field, CHECK_TYPE_ANY, CHECK_TYPE_INT, CHECK_TYPE_FLOAT, CHECK_TYPE_BOOL, CHECK_TYPE_STRING, CHECK_TYPE_LIST, CHECK_TYPE_OBJECT, CHECK_TYPE_MAP, CHECK_TYPE_SET, FieldBool, FieldAny, FieldString, FieldInt, FieldFloat, metaOf, getTypeName, FieldComp, FieldList, FieldObject, FieldMap, FieldSet, ClassBuilder, FIELD_CLASS, fieldsByTypeName, META_KEYS, RESERVED_COMPONENT_STATICS;
13045
13007
  var init_oo = __esm({
13046
13008
  "src/oo.js"() {
13047
13009
  init_collection();
@@ -13055,23 +13017,10 @@ var init_oo = __esm({
13055
13017
  this.name = name;
13056
13018
  this.typeCheck = typeCheck;
13057
13019
  this.coercer = coercer;
13058
- this.checks = [];
13059
13020
  this.defaultValue = defaultValue;
13060
13021
  }
13061
- toDataDef() {
13062
- return { type: this.type, defaultValue: defaultToData(this.defaultValue) };
13063
- }
13064
- getFirstFailingCheck(v) {
13065
- if (!this.typeCheck.isValid(v)) return this.typeCheck;
13066
- for (const check2 of this.checks) if (!check2.isValid(v)) return check2;
13067
- return null;
13068
- }
13069
13022
  isValid(v) {
13070
- return this.getFirstFailingCheck(v) === null;
13071
- }
13072
- addCheck(check2) {
13073
- this.checks.push(check2);
13074
- return this;
13023
+ return this.typeCheck(v);
13075
13024
  }
13076
13025
  coerceOr(v, defaultValue = null) {
13077
13026
  if (this.isValid(v)) return v;
@@ -13082,39 +13031,15 @@ var init_oo = __esm({
13082
13031
  return this.coerceOr(v, this.defaultValue);
13083
13032
  }
13084
13033
  };
13085
- Check = class {
13086
- isValid(_v) {
13087
- return true;
13088
- }
13089
- getMessage(_v) {
13090
- return "Invalid";
13091
- }
13092
- };
13093
- CheckTypeAny = class extends Check {
13094
- };
13095
- CHECK_TYPE_ANY = new CheckTypeAny();
13096
- FnCheck = class extends Check {
13097
- constructor(isValidFn, getMessageFn) {
13098
- super();
13099
- this._isValid = isValidFn;
13100
- this._getMessage = getMessageFn;
13101
- }
13102
- isValid(v) {
13103
- return this._isValid(v);
13104
- }
13105
- getMessage(v) {
13106
- return this._getMessage(v);
13107
- }
13108
- };
13109
- check = (fn, message) => new FnCheck(fn, () => message);
13110
- CHECK_TYPE_INT = check(Number.isInteger, "Integer expected");
13111
- CHECK_TYPE_FLOAT = check(Number.isFinite, "Float expected");
13112
- CHECK_TYPE_BOOL = check((v) => typeof v === "boolean", "Boolean expected");
13113
- CHECK_TYPE_STRING = check((v) => typeof v === "string", "String expected");
13114
- CHECK_TYPE_LIST = check(Array.isArray, "Array expected");
13115
- CHECK_TYPE_OBJECT = check(isPlainObject, "Plain object expected");
13116
- CHECK_TYPE_MAP = check((v) => v instanceof Map, "Map expected");
13117
- CHECK_TYPE_SET = check((v) => v instanceof Set, "Set expected");
13034
+ CHECK_TYPE_ANY = (_v) => true;
13035
+ CHECK_TYPE_INT = Number.isInteger;
13036
+ CHECK_TYPE_FLOAT = Number.isFinite;
13037
+ CHECK_TYPE_BOOL = (v) => typeof v === "boolean";
13038
+ CHECK_TYPE_STRING = (v) => typeof v === "string";
13039
+ CHECK_TYPE_LIST = Array.isArray;
13040
+ CHECK_TYPE_OBJECT = isPlainObject;
13041
+ CHECK_TYPE_MAP = (v) => v instanceof Map;
13042
+ CHECK_TYPE_SET = (v) => v instanceof Set;
13118
13043
  FieldBool = class extends Field {
13119
13044
  constructor(name, defaultValue = false) {
13120
13045
  super("bool", name, CHECK_TYPE_BOOL, (v) => !!v, defaultValue);
@@ -13124,9 +13049,6 @@ var init_oo = __esm({
13124
13049
  constructor(name, defaultValue = null) {
13125
13050
  super("any", name, CHECK_TYPE_ANY, nullCoercer, defaultValue);
13126
13051
  }
13127
- toDataDef() {
13128
- return { type: getTypeName(this.defaultValue) ?? "any", defaultValue: this.defaultValue };
13129
- }
13130
13052
  };
13131
13053
  FieldString = class extends Field {
13132
13054
  constructor(name, defaultValue = "") {
@@ -13149,26 +13071,13 @@ var init_oo = __esm({
13149
13071
  super("float", name, CHECK_TYPE_FLOAT, (_) => null, defaultValue);
13150
13072
  }
13151
13073
  };
13152
- getTypeName = (v) => v?.constructor?.[COMPONENT]?.name ?? v?.constructor?.getMetaClass?.()?.name ?? null;
13153
- CheckTypeName = class {
13154
- constructor(typeName) {
13155
- this.typeName = typeName;
13156
- }
13157
- isValid(v) {
13158
- return getTypeName(v) === this.typeName;
13159
- }
13160
- getMessage(v) {
13161
- return `Expected "${this.typeName}", got "${getTypeName(v)}"`;
13162
- }
13163
- };
13074
+ metaOf = (v) => v?.constructor?.[COMPONENT] ?? v?.constructor?.getMetaClass?.();
13075
+ getTypeName = (v) => metaOf(v)?.name ?? null;
13164
13076
  FieldComp = class extends Field {
13165
13077
  constructor(type3, name, args) {
13166
- super(type3, name, new CheckTypeName(type3), nullCoercer, null);
13078
+ super(type3, name, (v) => getTypeName(v) === type3, nullCoercer, null);
13167
13079
  this.args = args;
13168
13080
  }
13169
- toDataDef() {
13170
- return { component: this.type, args: this.args };
13171
- }
13172
13081
  };
13173
13082
  FieldList = class extends Field {
13174
13083
  constructor(name, defaultValue = []) {
@@ -13336,7 +13245,7 @@ function warnNotIntent(verb) {
13336
13245
  function rootDispatcher(transactor) {
13337
13246
  return new Dispatcher(new Path([]), transactor, null);
13338
13247
  }
13339
- var State2, Transactor, Transaction, InputEvent, NameArgsTransaction, SendEvent, IntentEvent, PASS, REFUSAL_RING_CAP, DEFAULT_ROUTE, INTENT_DEPTH, IntentWalk, Completion, Dispatcher, EventContext, PathChanges;
13248
+ var State2, Transactor, Transaction, InputEvent, NameArgsTransaction, SendEvent, IntentEvent, PASS, REFUSAL_RING_CAP, INTENT_DEPTH, IntentWalk, Completion, Dispatcher, EventContext, PathChanges;
13340
13249
  var init_transactor = __esm({
13341
13250
  "src/transactor.js"() {
13342
13251
  init_components();
@@ -13414,28 +13323,46 @@ var init_transactor = __esm({
13414
13323
  if (i !== -1) this._refusalObservers.splice(i, 1);
13415
13324
  };
13416
13325
  }
13417
- // Build and dispatch the observer record for a settled transaction. The
13418
- // resolved handler (`_resolvedHandler`/`_matched`) and per-leaf before/after
13419
- // (`_before`/`_after`) were captured while the handler ran (see callHandler /
13420
- // Transaction.run). No-op when nobody is observing.
13326
+ // Build and dispatch one observer record. Pins field-resolved keys (e.g. a
13327
+ // `.a[.selId]` render target reconstructed from a DOM event) against the root the
13328
+ // handler read, so pathKeys carries concrete keys instead of dropping the dynamic
13329
+ // step. No-op when nobody is observing.
13330
+ _emitRecord(root, { kind, name, args, path, targetPath, handler, handlerName, matched, before, after, parent }) {
13331
+ if (this._observers.length === 0) return;
13332
+ const pinned = path.pinKeys(root);
13333
+ this._emit({
13334
+ kind,
13335
+ name,
13336
+ args: args ?? null,
13337
+ path: pinned,
13338
+ pathKeys: pinned.toKeys(),
13339
+ targetPath,
13340
+ handler: handler ?? null,
13341
+ handlerName: handlerName ?? (handler?.name || null),
13342
+ matched: matched ?? null,
13343
+ before,
13344
+ after,
13345
+ parent,
13346
+ timestamp: Date.now()
13347
+ });
13348
+ }
13349
+ // The observer record for a settled transaction. The resolved handler
13350
+ // (`_resolvedHandler`/`_matched`) and per-leaf before/after (`_before`/`_after`)
13351
+ // were captured while the handler ran (see callHandler / Transaction.run).
13421
13352
  _emitTransaction(transaction, root) {
13422
13353
  if (this._observers.length === 0) return;
13423
13354
  if (transaction._resolvedHandler === void 0) return;
13424
- const path = transaction.getTransactionPath().pinKeys(root);
13425
- this._emit({
13355
+ this._emitRecord(root, {
13426
13356
  kind: transaction.observeKind,
13427
13357
  name: transaction.observeName,
13428
- args: transaction.args ?? null,
13429
- path,
13430
- pathKeys: path.toKeys(),
13358
+ args: transaction.args,
13359
+ path: transaction.getTransactionPath(),
13431
13360
  targetPath: transaction.targetPath ?? transaction.path,
13432
- handler: transaction._resolvedHandler ?? null,
13433
- handlerName: transaction._resolvedHandler?.name || null,
13434
- matched: transaction._matched ?? null,
13361
+ handler: transaction._resolvedHandler,
13362
+ matched: transaction._matched,
13435
13363
  before: transaction._before,
13436
13364
  after: transaction._after,
13437
- parent: transaction.parentTransaction,
13438
- timestamp: Date.now()
13365
+ parent: transaction.parentTransaction
13439
13366
  });
13440
13367
  }
13441
13368
  // Make `child` a tracked unit of `parent`'s subtree: the parent's completion stays open
@@ -13530,7 +13457,7 @@ var init_transactor = __esm({
13530
13457
  // rather than throwing, so a stray call from the wrong place is a message and not a
13531
13458
  // crash. `walk` is undefined here, which is how ctx.reply/ctx.fail tell the two apart.
13532
13459
  stop() {
13533
- console.warn('ctx.stop() is only meaningful in an "intent" handler - ignored');
13460
+ warnNotIntent("stop");
13534
13461
  }
13535
13462
  forward(_opts) {
13536
13463
  console.warn('ctx.forward() needs a "receive" or "intent" handler - ignored');
@@ -13615,11 +13542,8 @@ var init_transactor = __esm({
13615
13542
  }
13616
13543
  this.transactor.pushIntent(this.dispatchPath, name, args, rest, this);
13617
13544
  }
13618
- buildStack(root, comps) {
13619
- return this.path.toTransactionPath().buildStack(Stack.root(comps, root, this));
13620
- }
13621
13545
  getHandlerAndArgs(root, _instance, comps) {
13622
- const stack = this.buildStack(root, comps);
13546
+ const stack = this.path.toTransactionPath().buildStack(Stack.root(comps, root, this));
13623
13547
  const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
13624
13548
  this._handlerArgs = [...args];
13625
13549
  const path = this.dispatchPath;
@@ -13721,7 +13645,6 @@ var init_transactor = __esm({
13721
13645
  };
13722
13646
  PASS = /* @__PURE__ */ Symbol.for("tutuca.intent.pass");
13723
13647
  REFUSAL_RING_CAP = 200;
13724
- DEFAULT_ROUTE = ["dyn", "lex"];
13725
13648
  INTENT_DEPTH = 64;
13726
13649
  IntentWalk = class {
13727
13650
  constructor(transactor, path, name, args, opts, parent, release) {
@@ -13770,24 +13693,19 @@ var init_transactor = __esm({
13770
13693
  const txnPath = this.origin.toTransactionPath();
13771
13694
  const leaf = txnPath.lookup(root);
13772
13695
  const chain = this.transactor.comps.getIntentChainFor(leaf, this.name);
13773
- if (this.transactor._observers.length > 0) {
13774
- const path = txnPath.pinKeys(root);
13775
- this.transactor._emit({
13776
- kind: "intent",
13777
- name: this.name,
13778
- args: this.args,
13779
- path,
13780
- pathKeys: path.toKeys(),
13781
- targetPath: this.origin,
13782
- handler: chain[0]?.fn ?? null,
13783
- handlerName: chain[0]?.fn?.name || this.name,
13784
- matched: chain.length > 0 ? "exact" : "none",
13785
- before: leaf,
13786
- after: void 0,
13787
- parent: this.parent,
13788
- timestamp: Date.now()
13789
- });
13790
- }
13696
+ this.transactor._emitRecord(root, {
13697
+ kind: "intent",
13698
+ name: this.name,
13699
+ args: this.args,
13700
+ path: txnPath,
13701
+ targetPath: this.origin,
13702
+ handler: chain[0],
13703
+ handlerName: chain[0]?.name || this.name,
13704
+ matched: chain.length > 0 ? "exact" : "none",
13705
+ before: leaf,
13706
+ after: void 0,
13707
+ parent: this.parent
13708
+ });
13791
13709
  if (chain.length === 0) return this.advance();
13792
13710
  const p = this._runLex(chain, 0);
13793
13711
  this.transactor._inflight.add(p);
@@ -13798,7 +13716,7 @@ var init_transactor = __esm({
13798
13716
  if (i >= chain.length) return this.advance();
13799
13717
  const ctx = new Dispatcher(this.origin, this.transactor, this.parent);
13800
13718
  try {
13801
- const res = await chain[i].fn.apply(null, [...this.args, ctx]);
13719
+ const res = await chain[i].apply(null, [...this.args, ctx]);
13802
13720
  if (res === PASS) return this._runLex(chain, i + 1);
13803
13721
  this.answer("Ok", res);
13804
13722
  } catch (error) {
@@ -13951,9 +13869,8 @@ var init_transactor = __esm({
13951
13869
  // the same spelling as `ctx.intent` — `["dyn"]` the render ancestry, `["lex"]` the
13952
13870
  // registration scope, default both.
13953
13871
  lookup(name, opts) {
13954
- const route = opts?.route ?? DEFAULT_LOOKUP_ROUTE;
13955
13872
  return routeLookup(
13956
- route,
13873
+ opts?.route ?? DEFAULT_ROUTE,
13957
13874
  () => this._lookupLex(name),
13958
13875
  () => this._stack()?.lookupDynamic(name) ?? null
13959
13876
  );
@@ -13972,12 +13889,10 @@ var init_transactor = __esm({
13972
13889
  // can only ever answer with one; the `dyn` leg reads a binding an ancestor
13973
13890
  // published, so it is the leg that has to be checked.
13974
13891
  lookupType(name, opts) {
13975
- const v = this.lookup(name, opts);
13892
+ const route = opts?.route ?? DEFAULT_ROUTE;
13893
+ const v = this.lookup(name, { route });
13976
13894
  if (v == null) {
13977
- this.transactor.refuse("TYPE_NOT_FOUND", {
13978
- name,
13979
- route: opts?.route ?? DEFAULT_LOOKUP_ROUTE
13980
- });
13895
+ this.transactor.refuse("TYPE_NOT_FOUND", { name, route });
13981
13896
  return null;
13982
13897
  }
13983
13898
  if (v?.[COMPONENT] == null) {
@@ -14140,7 +14055,14 @@ var init_app = __esm({
14140
14055
  const { type: type3 } = e;
14141
14056
  const isDrag = type3 === "dragover" || type3 === "dragstart" || type3 === "dragend" || type3 === "drop";
14142
14057
  const { rootNode: root, maxEventNodeDepth: maxDepth, comps, transactor } = this;
14143
- const [path, handlers] = Path.fromEvent(e, root, maxDepth, comps, !isDrag);
14058
+ const [path, handlers] = Path.fromNodeAndEventName(
14059
+ e.target,
14060
+ type3,
14061
+ root,
14062
+ maxDepth,
14063
+ comps,
14064
+ !isDrag
14065
+ );
14144
14066
  if (isDrag) this._handleDragEvent(e, type3, path);
14145
14067
  if (path !== null && handlers !== null)
14146
14068
  for (const handler of handlers) transactor.transactInputNow(path, e, handler, this.dragInfo);
@@ -14202,7 +14124,7 @@ var init_app = __esm({
14202
14124
  const value = txnPath.lookup(rootValue);
14203
14125
  const dragType = e.target.dataset.dragtype ?? "?";
14204
14126
  const stack = path.toTransactionPath().buildStack(this.makeStack(rootValue));
14205
- this.dragInfo = new DragInfo(txnPath, stack, e, value, dragType, e.target);
14127
+ this.dragInfo = new DragInfo(stack, value, dragType, e.target);
14206
14128
  } else if (type3 === "drop") {
14207
14129
  e.preventDefault();
14208
14130
  this._cleanDragOverAttrs();
@@ -14305,10 +14227,8 @@ var init_app = __esm({
14305
14227
  };
14306
14228
  listenerOpts = (name) => name === "touchmove" ? { passive: false } : void 0;
14307
14229
  DragInfo = class {
14308
- constructor(path, stack, e, val, type3, node) {
14309
- this.path = path;
14230
+ constructor(stack, val, type3, node) {
14310
14231
  this.stack = stack;
14311
- this.e = e;
14312
14232
  this.val = val;
14313
14233
  this.type = type3;
14314
14234
  this.node = node;
@@ -14444,6 +14364,8 @@ var init_renderer = __esm({
14444
14364
  setNullCache() {
14445
14365
  this.cache = new NullDomCache();
14446
14366
  }
14367
+ // Library utilities for consumers embedding tutuca: render a value to a detached
14368
+ // DOM node / an HTML string. Not called by the framework itself.
14447
14369
  renderToDOM(stack, val) {
14448
14370
  const rootNode = document.createElement("div");
14449
14371
  const rOpts = { document };
@@ -15786,7 +15708,7 @@ ${JSON.stringify({ imports }, null, 6)}
15786
15708
  </html>
15787
15709
  `;
15788
15710
  }
15789
- function renderBootstrap(devModuleUrls, { margauiEnabled, margauiThemeUrl, check: check2, inspect: inspect3, noCache }) {
15711
+ function renderBootstrap(devModuleUrls, { margauiEnabled, margauiThemeUrl, check, inspect: inspect3, noCache }) {
15790
15712
  const lines = ['import { mountStorybook } from "tutuca/storybook";'];
15791
15713
  if (margauiEnabled) {
15792
15714
  lines.push('import { compileClassesToStyleText } from "tutuca/extra";');
@@ -15795,7 +15717,7 @@ function renderBootstrap(devModuleUrls, { margauiEnabled, margauiThemeUrl, check
15795
15717
  if (inspect3) {
15796
15718
  lines.push('import { shadowCheckComponent, runTests, expect } from "tutuca/dev";');
15797
15719
  }
15798
- if (check2) lines.push('import { check } from "tutuca/dev";');
15720
+ if (check) lines.push('import { check } from "tutuca/dev";');
15799
15721
  devModuleUrls.forEach((url, i) => {
15800
15722
  lines.push(`import * as m${i} from ${JSON.stringify(url)};`);
15801
15723
  });
@@ -15810,7 +15732,7 @@ function renderBootstrap(devModuleUrls, { margauiEnabled, margauiThemeUrl, check
15810
15732
  const opts = optParts.length ? `{ ${optParts.join(", ")} }` : "{}";
15811
15733
  lines.push("");
15812
15734
  lines.push(`const app = await mountStorybook("#app", [${modules}], ${opts});`);
15813
- if (check2) lines.push("check(app);");
15735
+ if (check) lines.push("check(app);");
15814
15736
  lines.push("");
15815
15737
  return lines.join("\n");
15816
15738
  }
@@ -15968,7 +15890,7 @@ async function run5(argv, opts = {}) {
15968
15890
  const margauiEnabled = !parsed.values["no-margaui"];
15969
15891
  const margauiOverride = parsed.values.margaui;
15970
15892
  const forceMargauiCdn = parsed.values["margaui-cdn"];
15971
- const check2 = !parsed.values["no-check"];
15893
+ const check = !parsed.values["no-check"];
15972
15894
  const inspect3 = !parsed.values["no-inspect"];
15973
15895
  const noCache = parsed.values["no-cache"];
15974
15896
  const self = findSelf();
@@ -15992,7 +15914,7 @@ async function run5(argv, opts = {}) {
15992
15914
  renderBootstrap(devModuleUrls, {
15993
15915
  margauiEnabled,
15994
15916
  margauiThemeUrl: mg2.themeUrl,
15995
- check: check2,
15917
+ check,
15996
15918
  inspect: inspect3,
15997
15919
  noCache
15998
15920
  })
@@ -16017,7 +15939,7 @@ async function run5(argv, opts = {}) {
16017
15939
  projectDir,
16018
15940
  tutuca: { source, base: base2, version: self.version },
16019
15941
  margaui: margauiEnabled ? { source: mg2.source, jsUrl: mg2.jsUrl, themeUrl: mg2.themeUrl } : null,
16020
- options: { margaui: margauiEnabled, check: check2, noCache, runTests: !parsed.values["no-tests"] },
15942
+ options: { margaui: margauiEnabled, check, noCache, runTests: !parsed.values["no-tests"] },
16021
15943
  imports: imports2,
16022
15944
  modules,
16023
15945
  tests,
@@ -16032,7 +15954,7 @@ async function run5(argv, opts = {}) {
16032
15954
  `tutuca storybook dry run (no server started)
16033
15955
  project: ${projectDir}
16034
15956
  tutuca runtime: ${source} (${base2}, version ${self.version})
16035
- margaui: ${margauiEnabled ? `on (${mg2.source})` : "off"}, in-browser check: ${check2 ? "on" : "off"}, cache: ${noCache ? "off" : "on"}
15957
+ margaui: ${margauiEnabled ? `on (${mg2.source})` : "off"}, in-browser check: ${check ? "on" : "off"}, cache: ${noCache ? "off" : "on"}
16036
15958
  ${modules.length} dev module(s):
16037
15959
  `
16038
15960
  );
@@ -16106,7 +16028,7 @@ async function run5(argv, opts = {}) {
16106
16028
  const bootstrapJs = renderBootstrap(devModuleUrls, {
16107
16029
  margauiEnabled,
16108
16030
  margauiThemeUrl: mg.themeUrl,
16109
- check: check2,
16031
+ check,
16110
16032
  inspect: inspect3,
16111
16033
  noCache
16112
16034
  });