@timeax/digital-service-engine 0.3.4 → 0.3.5

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.
@@ -4,8 +4,8 @@ var EventBus = class {
4
4
  this.listeners = /* @__PURE__ */ new Map();
5
5
  }
6
6
  on(event, handler) {
7
- var _a2;
8
- const set = (_a2 = this.listeners.get(event)) != null ? _a2 : /* @__PURE__ */ new Set();
7
+ var _a;
8
+ const set = (_a = this.listeners.get(event)) != null ? _a : /* @__PURE__ */ new Set();
9
9
  set.add(handler);
10
10
  this.listeners.set(event, set);
11
11
  return () => {
@@ -37,9 +37,9 @@ var RetryQueue = class {
37
37
  constructor(opts = {}) {
38
38
  this.jobs = /* @__PURE__ */ new Map();
39
39
  this.paused = false;
40
- var _a2, _b, _c, _d, _e, _f;
40
+ var _a, _b, _c, _d, _e, _f;
41
41
  this.opts = {
42
- enabled: (_a2 = opts.enabled) != null ? _a2 : true,
42
+ enabled: (_a = opts.enabled) != null ? _a : true,
43
43
  maxAttempts: (_b = opts.maxAttempts) != null ? _b : 5,
44
44
  baseDelayMs: (_c = opts.baseDelayMs) != null ? _c : 800,
45
45
  maxDelayMs: (_d = opts.maxDelayMs) != null ? _d : 2e4,
@@ -56,11 +56,11 @@ var RetryQueue = class {
56
56
  }
57
57
  /** Enqueue or no-op if a job with same id already exists */
58
58
  enqueue(job) {
59
- var _a2;
59
+ var _a;
60
60
  if (!this.opts.enabled) return false;
61
61
  if (this.jobs.has(job.id)) return false;
62
62
  this.jobs.set(job.id, { job, attempt: 0 });
63
- (_a2 = job.onStatus) == null ? void 0 : _a2.call(job, "scheduled", { attempt: 0 });
63
+ (_a = job.onStatus) == null ? void 0 : _a.call(job, "scheduled", { attempt: 0 });
64
64
  this.kick(job.id);
65
65
  return true;
66
66
  }
@@ -74,12 +74,12 @@ var RetryQueue = class {
74
74
  return true;
75
75
  }
76
76
  cancel(id) {
77
- var _a2, _b;
77
+ var _a, _b;
78
78
  const rec = this.jobs.get(id);
79
79
  if (!rec) return false;
80
80
  if (rec.timer) clearTimeout(rec.timer);
81
81
  rec.cancelled = true;
82
- (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "cancelled", { attempt: rec.attempt });
82
+ (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "cancelled", { attempt: rec.attempt });
83
83
  this.jobs.delete(id);
84
84
  return true;
85
85
  }
@@ -93,11 +93,11 @@ var RetryQueue = class {
93
93
  return this.jobs.has(id);
94
94
  }
95
95
  drain() {
96
- var _a2, _b;
96
+ var _a, _b;
97
97
  for (const [id, rec] of this.jobs.entries()) {
98
98
  if (rec.timer) clearTimeout(rec.timer);
99
99
  rec.cancelled = true;
100
- (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "cancelled", { attempt: rec.attempt });
100
+ (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "cancelled", { attempt: rec.attempt });
101
101
  this.jobs.delete(id);
102
102
  }
103
103
  }
@@ -112,15 +112,15 @@ var RetryQueue = class {
112
112
  return Math.min(maxDelayMs, Math.floor(exp * r));
113
113
  }
114
114
  async kick(id, immediate = false) {
115
- var _a2, _b;
115
+ var _a, _b;
116
116
  const rec = this.jobs.get(id);
117
117
  if (!rec || rec.cancelled) return;
118
118
  if (this.paused && !immediate) return;
119
119
  const attempt = rec.attempt + 1;
120
120
  const run = async () => {
121
- var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
121
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
122
122
  if (rec.cancelled) return;
123
- (_b2 = (_a3 = rec.job).onStatus) == null ? void 0 : _b2.call(_a3, "retrying", { attempt });
123
+ (_b2 = (_a2 = rec.job).onStatus) == null ? void 0 : _b2.call(_a2, "retrying", { attempt });
124
124
  try {
125
125
  const ok = await rec.job.perform(attempt);
126
126
  if (ok) {
@@ -145,7 +145,7 @@ var RetryQueue = class {
145
145
  else {
146
146
  const delay = this.opts.immediateFirst && attempt === 1 ? 0 : this.delayFor(attempt);
147
147
  if (delay) {
148
- (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "scheduled", { attempt: 0, nextDelayMs: delay });
148
+ (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "scheduled", { attempt: 0, nextDelayMs: delay });
149
149
  rec.timer = setTimeout(run, delay);
150
150
  } else {
151
151
  void run();
@@ -165,8 +165,8 @@ var CommentsAPI = class {
165
165
  this.retry = new RetryQueue(deps.retry);
166
166
  }
167
167
  scope() {
168
- var _a2, _b;
169
- return (_b = (_a2 = this.deps).getScope) == null ? void 0 : _b.call(_a2);
168
+ var _a, _b;
169
+ return (_b = (_a = this.deps).getScope) == null ? void 0 : _b.call(_a);
170
170
  }
171
171
  emitSync(op, threadId, messageId, status, meta) {
172
172
  this.bus.emit("comment:sync", {
@@ -208,7 +208,7 @@ var CommentsAPI = class {
208
208
  }
209
209
  /* ─── Mutations (optimistic if backend present) ─────── */
210
210
  async create(anchor, initialBody, meta) {
211
- var _a2, _b;
211
+ var _a, _b;
212
212
  const now = Date.now();
213
213
  const localId = newLocalId("t");
214
214
  const msgId = newLocalId("m");
@@ -249,7 +249,7 @@ var CommentsAPI = class {
249
249
  return serverId;
250
250
  } catch (err) {
251
251
  const scope = this.scope();
252
- const branchKey = (_a2 = scope == null ? void 0 : scope.branchId) != null ? _a2 : "no_branch";
252
+ const branchKey = (_a = scope == null ? void 0 : scope.branchId) != null ? _a : "no_branch";
253
253
  const jobId = `comments:create_thread:${branchKey}:${localId}`;
254
254
  this.retry.enqueue({
255
255
  id: jobId,
@@ -280,7 +280,7 @@ var CommentsAPI = class {
280
280
  }
281
281
  }
282
282
  async reply(threadId, body, meta) {
283
- var _a2, _b, _c;
283
+ var _a, _b, _c;
284
284
  const th = this.ensure(threadId);
285
285
  const now = Date.now();
286
286
  const localMid = newLocalId("m");
@@ -293,7 +293,7 @@ var CommentsAPI = class {
293
293
  };
294
294
  th.messages.push(localMsg);
295
295
  th.updatedAt = now;
296
- (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
296
+ (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
297
297
  this.bus.emit("comment:message:create", {
298
298
  threadId,
299
299
  message: localMsg
@@ -352,7 +352,7 @@ var CommentsAPI = class {
352
352
  }
353
353
  }
354
354
  async editMessage(threadId, messageId, body) {
355
- var _a2, _b, _c;
355
+ var _a, _b, _c;
356
356
  const th = this.ensure(threadId);
357
357
  const orig = th.messages.find((m) => m.id === messageId);
358
358
  if (!orig) return;
@@ -361,7 +361,7 @@ var CommentsAPI = class {
361
361
  orig.editedAt = Date.now();
362
362
  th.updatedAt = orig.editedAt;
363
363
  const hasBackend = Boolean(this.deps.backend && this.scope());
364
- (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
364
+ (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
365
365
  this.bus.emit("comment:thread:update", { thread: th });
366
366
  if (!this.deps.backend) return;
367
367
  const performOnce = async () => {
@@ -414,13 +414,13 @@ var CommentsAPI = class {
414
414
  }
415
415
  }
416
416
  async deleteMessage(threadId, messageId) {
417
- var _a2, _b, _c;
417
+ var _a, _b, _c;
418
418
  const th = this.ensure(threadId);
419
419
  const backup = [...th.messages];
420
420
  th.messages = th.messages.filter((m) => m.id !== messageId);
421
421
  th.updatedAt = Date.now();
422
422
  const hasBackend = Boolean(this.deps.backend && this.scope());
423
- (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
423
+ (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
424
424
  this.bus.emit("comment:thread:update", { thread: th });
425
425
  if (!this.deps.backend) return;
426
426
  const performOnce = async () => {
@@ -469,13 +469,13 @@ var CommentsAPI = class {
469
469
  }
470
470
  }
471
471
  async move(threadId, anchor) {
472
- var _a2, _b, _c;
472
+ var _a, _b, _c;
473
473
  const th = this.ensure(threadId);
474
474
  const prev = th.anchor;
475
475
  th.anchor = anchor;
476
476
  th.updatedAt = Date.now();
477
477
  const hasBackend = Boolean(this.deps.backend && this.scope());
478
- (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
478
+ (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
479
479
  this.bus.emit("comment:move", { thread: th });
480
480
  this.bus.emit("comment:thread:update", { thread: th });
481
481
  if (!this.deps.backend) return;
@@ -527,13 +527,13 @@ var CommentsAPI = class {
527
527
  }
528
528
  }
529
529
  async resolve(threadId, value = true) {
530
- var _a2, _b, _c;
530
+ var _a, _b, _c;
531
531
  const th = this.ensure(threadId);
532
532
  const prev = th.resolved;
533
533
  th.resolved = value;
534
534
  th.updatedAt = Date.now();
535
535
  const hasBackend = Boolean(this.deps.backend && this.scope());
536
- (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
536
+ (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
537
537
  this.bus.emit("comment:resolve", { thread: th, resolved: value });
538
538
  this.bus.emit("comment:thread:update", { thread: th });
539
539
  if (!this.deps.backend) return;
@@ -585,7 +585,7 @@ var CommentsAPI = class {
585
585
  }
586
586
  }
587
587
  async deleteThread(threadId) {
588
- var _a2, _b;
588
+ var _a, _b;
589
589
  const prev = this.threads.get(threadId);
590
590
  if (!prev) return;
591
591
  this.threads.delete(threadId);
@@ -601,7 +601,7 @@ var CommentsAPI = class {
601
601
  await performOnce();
602
602
  } catch (err) {
603
603
  const scope = this.scope();
604
- const branchKey = (_a2 = scope == null ? void 0 : scope.branchId) != null ? _a2 : "no_branch";
604
+ const branchKey = (_a = scope == null ? void 0 : scope.branchId) != null ? _a : "no_branch";
605
605
  const jobId = `comments:delete_thread:${branchKey}:${threadId}`;
606
606
  this.retry.enqueue({
607
607
  id: jobId,
@@ -654,8 +654,8 @@ import { cloneDeep as cloneDeep4 } from "lodash-es";
654
654
  // src/core/normalise.ts
655
655
  import { cloneDeep } from "lodash-es";
656
656
  function normalise(input, opts = {}) {
657
- var _a2, _b;
658
- const defRole = (_a2 = opts.defaultPricingRole) != null ? _a2 : "base";
657
+ var _a, _b;
658
+ const defRole = (_a = opts.defaultPricingRole) != null ? _a : "base";
659
659
  const constraints = (_b = opts.constraints) != null ? _b : ["refill", "cancel", "dripfeed"];
660
660
  const obj = toObject(input);
661
661
  const rawFilters = Array.isArray(obj.filters) ? obj.filters : [];
@@ -705,10 +705,10 @@ function propagateConstraints(props, flagKeys) {
705
705
  const starts = roots.length ? roots : tags;
706
706
  const visited = /* @__PURE__ */ new Set();
707
707
  const visit = (tag, inherited) => {
708
- var _a2, _b;
708
+ var _a, _b;
709
709
  if (visited.has(tag.id)) return;
710
710
  visited.add(tag.id);
711
- const local = cloneDeep((_a2 = tag.constraints) != null ? _a2 : {});
711
+ const local = cloneDeep((_a = tag.constraints) != null ? _a : {});
712
712
  if (tag.constraints_overrides) {
713
713
  for (const [k, over] of Object.entries(tag.constraints_overrides)) {
714
714
  if (over) local[k] = over.from;
@@ -990,8 +990,8 @@ function isServiceIdRef(v) {
990
990
  return typeof v === "string" && v.trim().length > 0 || typeof v === "number" && Number.isFinite(v);
991
991
  }
992
992
  function hasAnyServiceOption(f) {
993
- var _a2;
994
- return ((_a2 = f.options) != null ? _a2 : []).some((o) => isServiceIdRef(o.service_id));
993
+ var _a;
994
+ return ((_a = f.options) != null ? _a : []).some((o) => isServiceIdRef(o.service_id));
995
995
  }
996
996
  function getByPath(obj, path) {
997
997
  if (!path) return void 0;
@@ -1021,12 +1021,12 @@ function includesValue(arr, needle) {
1021
1021
  return false;
1022
1022
  }
1023
1023
  function matchesWhere(svc, where) {
1024
- var _a2;
1024
+ var _a;
1025
1025
  if (!where || where.length === 0) return true;
1026
1026
  const root = { service: svc };
1027
1027
  for (const clause of where) {
1028
1028
  const path = clause.path;
1029
- const op = (_a2 = clause.op) != null ? _a2 : "eq";
1029
+ const op = (_a = clause.op) != null ? _a : "eq";
1030
1030
  const value = clause.value;
1031
1031
  const cur = getByPath(root, path);
1032
1032
  if (op === "exists") {
@@ -1080,9 +1080,9 @@ function withAffected(details, ids) {
1080
1080
 
1081
1081
  // src/core/node-map.ts
1082
1082
  function buildNodeMap(props) {
1083
- var _a2, _b, _c;
1083
+ var _a, _b, _c;
1084
1084
  const map = /* @__PURE__ */ new Map();
1085
- for (const t of (_a2 = props.filters) != null ? _a2 : []) {
1085
+ for (const t of (_a = props.filters) != null ? _a : []) {
1086
1086
  if (!map.has(t.id)) map.set(t.id, { kind: "tag", id: t.id, node: t });
1087
1087
  }
1088
1088
  for (const f of (_b = props.fields) != null ? _b : []) {
@@ -1121,8 +1121,8 @@ function resolveTrigger(trigger, nodeMap) {
1121
1121
 
1122
1122
  // src/core/visibility.ts
1123
1123
  function visibleFieldIdsUnder(props, tagId, opts = {}) {
1124
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1125
- const tags = (_a2 = props.filters) != null ? _a2 : [];
1124
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1125
+ const tags = (_a = props.filters) != null ? _a : [];
1126
1126
  const fields = (_b = props.fields) != null ? _b : [];
1127
1127
  const tagById = new Map(tags.map((t) => [t.id, t]));
1128
1128
  const tag = tagById.get(tagId);
@@ -1239,9 +1239,9 @@ function visibleFieldIdsUnder(props, tagId, opts = {}) {
1239
1239
  return base;
1240
1240
  }
1241
1241
  function visibleFieldsUnder(props, tagId, opts = {}) {
1242
- var _a2;
1242
+ var _a;
1243
1243
  const ids = visibleFieldIdsUnder(props, tagId, opts);
1244
- const fieldById = new Map(((_a2 = props.fields) != null ? _a2 : []).map((f) => [f.id, f]));
1244
+ const fieldById = new Map(((_a = props.fields) != null ? _a : []).map((f) => [f.id, f]));
1245
1245
  return ids.map((id) => fieldById.get(id)).filter(Boolean);
1246
1246
  }
1247
1247
 
@@ -1261,7 +1261,7 @@ function resolveRootTags(tags) {
1261
1261
  return roots.length ? roots : tags.slice(0, 1);
1262
1262
  }
1263
1263
  function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKeys) {
1264
- var _a2;
1264
+ var _a;
1265
1265
  const visible = visibleFieldsUnder(v.props, tagId, {
1266
1266
  selectedKeys
1267
1267
  });
@@ -1271,7 +1271,7 @@ function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKey
1271
1271
  const t = f.id;
1272
1272
  if (effectfulKeys.has(t)) triggers.push(t);
1273
1273
  }
1274
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
1274
+ for (const o of (_a = f.options) != null ? _a : []) {
1275
1275
  const t = o.id;
1276
1276
  if (effectfulKeys.has(t)) triggers.push(t);
1277
1277
  }
@@ -1280,12 +1280,12 @@ function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKey
1280
1280
  return triggers;
1281
1281
  }
1282
1282
  function runVisibilityRulesOnce(v) {
1283
- var _a2, _b, _c, _d, _e;
1283
+ var _a, _b, _c, _d, _e;
1284
1284
  for (const t of v.tags) {
1285
1285
  const visible = v.fieldsVisibleUnder(t.id);
1286
1286
  const seen = /* @__PURE__ */ new Map();
1287
1287
  for (const f of visible) {
1288
- const label = ((_a2 = f.label) != null ? _a2 : "").trim();
1288
+ const label = ((_a = f.label) != null ? _a : "").trim();
1289
1289
  if (!label) continue;
1290
1290
  if (seen.has(label)) {
1291
1291
  const otherId = seen.get(label);
@@ -1357,8 +1357,8 @@ function runVisibilityRulesOnce(v) {
1357
1357
  function dedupeErrorsInPlace(v, startIndex) {
1358
1358
  const seen = /* @__PURE__ */ new Set();
1359
1359
  const keyOfErr = (e) => {
1360
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1361
- const tagId = (_e = (_d = (_a2 = e == null ? void 0 : e.details) == null ? void 0 : _a2.tagId) != null ? _d : (_c = (_b = e == null ? void 0 : e.details) == null ? void 0 : _b.affected) == null ? void 0 : _c.tagId) != null ? _e : "";
1360
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1361
+ const tagId = (_e = (_d = (_a = e == null ? void 0 : e.details) == null ? void 0 : _a.tagId) != null ? _d : (_c = (_b = e == null ? void 0 : e.details) == null ? void 0 : _b.affected) == null ? void 0 : _c.tagId) != null ? _e : "";
1362
1362
  const other = (_g = (_f = e == null ? void 0 : e.details) == null ? void 0 : _f.other) != null ? _g : "";
1363
1363
  return `${(_h = e == null ? void 0 : e.code) != null ? _h : ""}::${(_i = e == null ? void 0 : e.nodeId) != null ? _i : ""}::${tagId}::${other}::${(_j = e == null ? void 0 : e.message) != null ? _j : ""}`;
1364
1364
  };
@@ -1373,7 +1373,7 @@ function dedupeErrorsInPlace(v, startIndex) {
1373
1373
  v.errors.splice(startIndex, v.errors.length - startIndex, ...kept);
1374
1374
  }
1375
1375
  function validateVisibility(v, options = {}) {
1376
- var _a2, _b, _c, _d, _e;
1376
+ var _a, _b, _c, _d, _e;
1377
1377
  v.simulatedVisibilityContexts = [];
1378
1378
  const simulate = options.simulate === true;
1379
1379
  if (!simulate) {
@@ -1387,7 +1387,7 @@ function validateVisibility(v, options = {}) {
1387
1387
  }
1388
1388
  return;
1389
1389
  }
1390
- const maxStates = Math.max(1, (_a2 = options.maxStates) != null ? _a2 : 500);
1390
+ const maxStates = Math.max(1, (_a = options.maxStates) != null ? _a : 500);
1391
1391
  const maxDepth = Math.max(0, (_b = options.maxDepth) != null ? _b : 6);
1392
1392
  const onlyEffectful = options.onlyEffectfulTriggers !== false;
1393
1393
  const effectfulKeys = /* @__PURE__ */ new Set();
@@ -1477,11 +1477,11 @@ function validateStructure(v) {
1477
1477
  const visiting = /* @__PURE__ */ new Set();
1478
1478
  const visited = /* @__PURE__ */ new Set();
1479
1479
  const hasCycleFrom = (id) => {
1480
- var _a2;
1480
+ var _a;
1481
1481
  if (visiting.has(id)) return true;
1482
1482
  if (visited.has(id)) return false;
1483
1483
  visiting.add(id);
1484
- const parent = (_a2 = v.tagById.get(id)) == null ? void 0 : _a2.bind_id;
1484
+ const parent = (_a = v.tagById.get(id)) == null ? void 0 : _a.bind_id;
1485
1485
  if (parent && v.tagById.has(parent) && hasCycleFrom(parent))
1486
1486
  return true;
1487
1487
  visiting.delete(id);
@@ -1542,7 +1542,7 @@ function validateStructure(v) {
1542
1542
 
1543
1543
  // src/core/validate/steps/identity.ts
1544
1544
  function validateIdentity(v) {
1545
- var _a2, _b;
1545
+ var _a, _b;
1546
1546
  const tags = v.tags;
1547
1547
  const fields = v.fields;
1548
1548
  {
@@ -1564,7 +1564,7 @@ function validateIdentity(v) {
1564
1564
  }
1565
1565
  for (const f of fields) {
1566
1566
  if (seen.has(f.id)) {
1567
- const kind = (_a2 = firstSeen.get(f.id)) != null ? _a2 : "tag/field";
1567
+ const kind = (_a = firstSeen.get(f.id)) != null ? _a : "tag/field";
1568
1568
  v.errors.push({
1569
1569
  code: "duplicate_id",
1570
1570
  severity: "error",
@@ -1666,14 +1666,14 @@ function parseFieldOptionKey(key) {
1666
1666
  return { fieldId, optionId };
1667
1667
  }
1668
1668
  function hasOption(v, fid, oid) {
1669
- var _a2;
1669
+ var _a;
1670
1670
  const f = v.fieldById.get(fid);
1671
1671
  if (!f) return false;
1672
- return !!((_a2 = f.options) != null ? _a2 : []).find((o) => o.id === oid);
1672
+ return !!((_a = f.options) != null ? _a : []).find((o) => o.id === oid);
1673
1673
  }
1674
1674
  function validateOptionMaps(v) {
1675
- var _a2, _b;
1676
- const incMap = (_a2 = v.props.includes_for_buttons) != null ? _a2 : {};
1675
+ var _a, _b;
1676
+ const incMap = (_a = v.props.includes_for_buttons) != null ? _a : {};
1677
1677
  const excMap = (_b = v.props.excludes_for_buttons) != null ? _b : {};
1678
1678
  const badKeyMessage = (key) => `Invalid trigger-map key "${key}". Expected a known node id (option or button-field), or "fieldId::optionId" pointing to an existing option.`;
1679
1679
  const validateTriggerKey = (key) => {
@@ -1787,8 +1787,8 @@ function normalizeSelectedOrderKindTriggers(selectedTriggerKeys, nodeMap) {
1787
1787
  return out;
1788
1788
  }
1789
1789
  function resolveOrderKind(params) {
1790
- var _a2, _b;
1791
- const nodeMap = (_a2 = params.nodeMap) != null ? _a2 : buildNodeMap(params.props);
1790
+ var _a, _b;
1791
+ const nodeMap = (_a = params.nodeMap) != null ? _a : buildNodeMap(params.props);
1792
1792
  const orderKinds = (_b = params.props.orderKinds) != null ? _b : {};
1793
1793
  const normalizedSelected = normalizeSelectedOrderKindTriggers(
1794
1794
  params.selectedTriggerKeys,
@@ -1843,8 +1843,8 @@ function resolveOrderKind(params) {
1843
1843
 
1844
1844
  // src/core/validate/steps/order-kinds.ts
1845
1845
  function validateOrderKinds(v) {
1846
- var _a2, _b, _c;
1847
- const selectedTriggerKeys = Array.from((_a2 = v.selectedKeys) != null ? _a2 : []);
1846
+ var _a, _b, _c;
1847
+ const selectedTriggerKeys = Array.from((_a = v.selectedKeys) != null ? _a : []);
1848
1848
  if (!selectedTriggerKeys.length) return;
1849
1849
  const resolved = resolveOrderKind({
1850
1850
  props: v.props,
@@ -1870,8 +1870,8 @@ function validateOrderKinds(v) {
1870
1870
 
1871
1871
  // src/core/validate/steps/service-vs-input.ts
1872
1872
  function hasButtonTriggerMap(v, fieldId) {
1873
- var _a2, _b;
1874
- const includes = (_a2 = v.props.includes_for_buttons) == null ? void 0 : _a2[fieldId];
1873
+ var _a, _b;
1874
+ const includes = (_a = v.props.includes_for_buttons) == null ? void 0 : _a[fieldId];
1875
1875
  const excludes = (_b = v.props.excludes_for_buttons) == null ? void 0 : _b[fieldId];
1876
1876
  return Array.isArray(includes) && includes.length > 0 || Array.isArray(excludes) && excludes.length > 0;
1877
1877
  }
@@ -1916,7 +1916,7 @@ function validateServiceVsUserInput(v) {
1916
1916
 
1917
1917
  // src/core/validate/steps/utility.ts
1918
1918
  function validateUtilityMarkers(v) {
1919
- var _a2, _b, _c, _d;
1919
+ var _a, _b, _c, _d;
1920
1920
  const ALLOWED_UTILITY_MODES = /* @__PURE__ */ new Set([
1921
1921
  "flat",
1922
1922
  "per_quantity",
@@ -1926,7 +1926,7 @@ function validateUtilityMarkers(v) {
1926
1926
  for (const f of v.fields) {
1927
1927
  const optsArr = Array.isArray(f.options) ? f.options : [];
1928
1928
  for (const o of optsArr) {
1929
- const role = (_b = (_a2 = o.pricing_role) != null ? _a2 : f.pricing_role) != null ? _b : "base";
1929
+ const role = (_b = (_a = o.pricing_role) != null ? _a : f.pricing_role) != null ? _b : "base";
1930
1930
  const hasService = isServiceIdRef(o.service_id);
1931
1931
  const util = (_c = o.meta) == null ? void 0 : _c.utility;
1932
1932
  if (role === "utility" && hasService) {
@@ -2007,9 +2007,9 @@ function validateUtilityMarkers(v) {
2007
2007
 
2008
2008
  // src/utils/index.ts
2009
2009
  function isMultiField(f) {
2010
- var _a2;
2010
+ var _a;
2011
2011
  const t = (f.type || "").toLowerCase();
2012
- const metaMulti = !!((_a2 = f.meta) == null ? void 0 : _a2.multi);
2012
+ const metaMulti = !!((_a = f.meta) == null ? void 0 : _a.multi);
2013
2013
  return t === "multiselect" || t === "checkbox" || metaMulti;
2014
2014
  }
2015
2015
 
@@ -2029,8 +2029,8 @@ function constraintFitOk(svcMap, candidate, constraints) {
2029
2029
  return !(constraints.cancel === true && !cap.cancel);
2030
2030
  }
2031
2031
  function getServiceCapability(svcMap, candidate) {
2032
- var _a2;
2033
- return (_a2 = getServiceCapabilityEntry(svcMap, candidate)) == null ? void 0 : _a2.capability;
2032
+ var _a;
2033
+ return (_a = getServiceCapabilityEntry(svcMap, candidate)) == null ? void 0 : _a.capability;
2034
2034
  }
2035
2035
  function getServiceCapabilityCanonicalRef(svcMap, candidate) {
2036
2036
  const entry = getServiceCapabilityEntry(svcMap, candidate);
@@ -2057,10 +2057,10 @@ function isSameServiceCapabilityRef(svcMap, left, right) {
2057
2057
  return rightAliases.some((value) => leftAliases.has(String(value)));
2058
2058
  }
2059
2059
  function normalizeRatePolicy(policy) {
2060
- var _a2;
2060
+ var _a;
2061
2061
  if (!policy) return { kind: "lte_primary", pct: 5 };
2062
2062
  if (policy.kind === "eq_primary") return policy;
2063
- const pct = Math.max(0, Number((_a2 = policy.pct) != null ? _a2 : 0));
2063
+ const pct = Math.max(0, Number((_a = policy.pct) != null ? _a : 0));
2064
2064
  return { ...policy, pct };
2065
2065
  }
2066
2066
  function passesRatePolicy(policy, primaryRate, candidateRate) {
@@ -2161,12 +2161,12 @@ function normalizeServiceRef(value) {
2161
2161
 
2162
2162
  // src/core/validate/steps/rates.ts
2163
2163
  function validateRates(v) {
2164
- var _a2, _b, _c;
2164
+ var _a, _b, _c;
2165
2165
  const ratePolicy = normalizeRatePolicy(v.options.ratePolicy);
2166
2166
  for (const f of v.fields) {
2167
2167
  if (!isMultiField(f)) continue;
2168
2168
  const baseRates = [];
2169
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
2169
+ for (const o of (_a = f.options) != null ? _a : []) {
2170
2170
  const role = (_c = (_b = o.pricing_role) != null ? _b : f.pricing_role) != null ? _c : "base";
2171
2171
  if (role !== "base") continue;
2172
2172
  const sid = o.service_id;
@@ -2219,7 +2219,7 @@ function validateRates(v) {
2219
2219
 
2220
2220
  // src/core/rate-coherence.ts
2221
2221
  function buildTriggerEffectMap(props) {
2222
- var _a2, _b;
2222
+ var _a, _b;
2223
2223
  const map = /* @__PURE__ */ new Map();
2224
2224
  const ensure = (key) => {
2225
2225
  let item = map.get(key);
@@ -2229,7 +2229,7 @@ function buildTriggerEffectMap(props) {
2229
2229
  }
2230
2230
  return item;
2231
2231
  };
2232
- for (const [key, ids] of Object.entries((_a2 = props.includes_for_buttons) != null ? _a2 : {})) {
2232
+ for (const [key, ids] of Object.entries((_a = props.includes_for_buttons) != null ? _a : {})) {
2233
2233
  const item = ensure(key);
2234
2234
  for (const id of ids != null ? ids : []) item.includes.add(id);
2235
2235
  }
@@ -2269,7 +2269,7 @@ function getRate(serviceMap, serviceId) {
2269
2269
  return rate;
2270
2270
  }
2271
2271
  function collectContextRefs(tag, visibleFields, serviceMap) {
2272
- var _a2, _b, _c, _d, _e;
2272
+ var _a, _b, _c, _d, _e;
2273
2273
  const serviceRefs = [];
2274
2274
  let tagDefault;
2275
2275
  if (tag.service_id !== void 0 && tag.service_id !== null) {
@@ -2281,7 +2281,7 @@ function collectContextRefs(tag, visibleFields, serviceMap) {
2281
2281
  nodeKind: "tag",
2282
2282
  serviceId: tag.service_id,
2283
2283
  rate: tagRate,
2284
- label: (_a2 = tag.label) != null ? _a2 : tag.id,
2284
+ label: (_a = tag.label) != null ? _a : tag.id,
2285
2285
  pricingRole: "base"
2286
2286
  };
2287
2287
  }
@@ -2558,7 +2558,7 @@ function constraintKeysInChain(v, tagId) {
2558
2558
  return keys;
2559
2559
  }
2560
2560
  function effectiveConstraints(v, tagId) {
2561
- var _a2;
2561
+ var _a;
2562
2562
  const out = {};
2563
2563
  const keys = constraintKeysInChain(v, tagId);
2564
2564
  for (const key of keys) {
@@ -2567,7 +2567,7 @@ function effectiveConstraints(v, tagId) {
2567
2567
  while (cur && !seen.has(cur)) {
2568
2568
  seen.add(cur);
2569
2569
  const t = v.tagById.get(cur);
2570
- const val = (_a2 = t == null ? void 0 : t.constraints) == null ? void 0 : _a2[key];
2570
+ const val = (_a = t == null ? void 0 : t.constraints) == null ? void 0 : _a[key];
2571
2571
  if (val === true || val === false) {
2572
2572
  out[key] = val;
2573
2573
  break;
@@ -2578,7 +2578,7 @@ function effectiveConstraints(v, tagId) {
2578
2578
  return out;
2579
2579
  }
2580
2580
  function validateConstraints(v) {
2581
- var _a2, _b;
2581
+ var _a, _b;
2582
2582
  for (const t of v.tags) {
2583
2583
  const eff = effectiveConstraints(v, t.id);
2584
2584
  const hasAnyRequired = Object.values(eff).some(
@@ -2587,7 +2587,7 @@ function validateConstraints(v) {
2587
2587
  if (!hasAnyRequired) continue;
2588
2588
  const visible = v.fieldsVisibleUnder(t.id);
2589
2589
  for (const f of visible) {
2590
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
2590
+ for (const o of (_a = f.options) != null ? _a : []) {
2591
2591
  if (!isServiceIdRef(o.service_id)) continue;
2592
2592
  const svc = getServiceCapability(v.serviceMap, o.service_id);
2593
2593
  if (!svc || typeof svc !== "object") continue;
@@ -2675,12 +2675,12 @@ function validateCustomFields(v) {
2675
2675
 
2676
2676
  // src/core/validate/steps/global-utility-guard.ts
2677
2677
  function validateGlobalUtilityGuard(v) {
2678
- var _a2, _b, _c;
2678
+ var _a, _b, _c;
2679
2679
  if (!v.options.globalUtilityGuard) return;
2680
2680
  let hasUtility = false;
2681
2681
  let hasBase = false;
2682
2682
  for (const f of v.fields) {
2683
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
2683
+ for (const o of (_a = f.options) != null ? _a : []) {
2684
2684
  if (!isServiceIdRef(o.service_id)) continue;
2685
2685
  const role = (_c = (_b = o.pricing_role) != null ? _b : f.pricing_role) != null ? _c : "base";
2686
2686
  if (role === "base") hasBase = true;
@@ -2702,14 +2702,14 @@ function validateGlobalUtilityGuard(v) {
2702
2702
 
2703
2703
  // src/core/validate/steps/unbound.ts
2704
2704
  function validateUnboundFields(v) {
2705
- var _a2, _b;
2705
+ var _a, _b;
2706
2706
  const boundFieldIds = /* @__PURE__ */ new Set();
2707
2707
  for (const f of v.fields) {
2708
2708
  if (f.bind_id) boundFieldIds.add(f.id);
2709
2709
  }
2710
2710
  const includedByTag = /* @__PURE__ */ new Set();
2711
2711
  for (const t of v.tags) {
2712
- for (const id of (_a2 = t.includes) != null ? _a2 : []) includedByTag.add(id);
2712
+ for (const id of (_a = t.includes) != null ? _a : []) includedByTag.add(id);
2713
2713
  }
2714
2714
  const includedByOption = /* @__PURE__ */ new Set();
2715
2715
  for (const arr of Object.values((_b = v.props.includes_for_buttons) != null ? _b : {})) {
@@ -2778,8 +2778,8 @@ function messageFor(code, d) {
2778
2778
  }
2779
2779
  }
2780
2780
  function validateFallbacks(v) {
2781
- var _a2, _b, _c, _d;
2782
- const mode = (_b = (_a2 = v.options.fallbackSettings) == null ? void 0 : _a2.mode) != null ? _b : "strict";
2781
+ var _a, _b, _c, _d;
2782
+ const mode = (_b = (_a = v.options.fallbackSettings) == null ? void 0 : _a.mode) != null ? _b : "strict";
2783
2783
  if (!v.props.fallbacks) return;
2784
2784
  const diags = collectFailedFallbacks(v.props, (_c = v.options.serviceMap) != null ? _c : {}, {
2785
2785
  ...v.options.fallbackSettings,
@@ -2840,7 +2840,7 @@ function svcSnapshot(serviceMap, sid) {
2840
2840
  };
2841
2841
  }
2842
2842
  function pushItem(out, next) {
2843
- var _a2;
2843
+ var _a;
2844
2844
  const key = `${String(next.serviceId)}|${next.role}`;
2845
2845
  const existing = out.get(key);
2846
2846
  if (!existing) {
@@ -2861,13 +2861,13 @@ function pushItem(out, next) {
2861
2861
  );
2862
2862
  out.set(key, {
2863
2863
  ...existing,
2864
- tagId: (_a2 = existing.tagId) != null ? _a2 : next.tagId,
2864
+ tagId: (_a = existing.tagId) != null ? _a : next.tagId,
2865
2865
  affectedIds: mergedIds
2866
2866
  });
2867
2867
  }
2868
2868
  function fieldRoleOf(f, o) {
2869
- var _a2, _b;
2870
- const roleRaw = (_b = (_a2 = o == null ? void 0 : o.pricing_role) != null ? _a2 : f.pricing_role) != null ? _b : "base";
2869
+ var _a, _b;
2870
+ const roleRaw = (_b = (_a = o == null ? void 0 : o.pricing_role) != null ? _a : f.pricing_role) != null ? _b : "base";
2871
2871
  return roleRaw === "utility" ? "utility" : "base";
2872
2872
  }
2873
2873
  function applyFilterAllowLists(tagId, fieldId, filter) {
@@ -2884,9 +2884,9 @@ function applyFilterAllowLists(tagId, fieldId, filter) {
2884
2884
  return true;
2885
2885
  }
2886
2886
  function collectServiceItems(args) {
2887
- var _a2, _b, _c, _d, _e;
2887
+ var _a, _b, _c, _d, _e;
2888
2888
  const filter = args.filter;
2889
- const roleFilter = (_a2 = filter == null ? void 0 : filter.role) != null ? _a2 : "both";
2889
+ const roleFilter = (_a = filter == null ? void 0 : filter.role) != null ? _a : "both";
2890
2890
  const where = filter == null ? void 0 : filter.where;
2891
2891
  const out = /* @__PURE__ */ new Map();
2892
2892
  const addServiceRef = (ref) => {
@@ -3091,26 +3091,26 @@ function defaultPolicyMessage(rule) {
3091
3091
  return `Policy "${rule.id}" violated`;
3092
3092
  }
3093
3093
  function affectedFromItems(items) {
3094
- var _a2;
3094
+ var _a;
3095
3095
  const ids = [];
3096
3096
  for (const it of items) {
3097
- for (const x of (_a2 = it.affectedIds) != null ? _a2 : []) ids.push(x);
3097
+ for (const x of (_a = it.affectedIds) != null ? _a : []) ids.push(x);
3098
3098
  ids.push(`service:${String(it.serviceId)}`);
3099
3099
  }
3100
3100
  return uniq(ids);
3101
3101
  }
3102
3102
  function visibleGroupNodeIds(tag, fields) {
3103
- var _a2;
3103
+ var _a;
3104
3104
  const ids = [tag.id];
3105
3105
  for (const f of fields) {
3106
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
3106
+ for (const o of (_a = f.options) != null ? _a : []) {
3107
3107
  ids.push(o.id);
3108
3108
  }
3109
3109
  }
3110
3110
  return uniq(ids);
3111
3111
  }
3112
3112
  function visibleGroupPrimaries(tag, fields) {
3113
- var _a2;
3113
+ var _a;
3114
3114
  const prim = [];
3115
3115
  const tagSid = tag.service_id;
3116
3116
  if (typeof tagSid === "string" || typeof tagSid === "number" && Number.isFinite(tagSid)) {
@@ -3121,7 +3121,7 @@ function visibleGroupPrimaries(tag, fields) {
3121
3121
  if (typeof fsid === "string" || typeof fsid === "number" && Number.isFinite(fsid)) {
3122
3122
  prim.push(fsid);
3123
3123
  }
3124
- for (const o of (_a2 = f.options) != null ? _a2 : []) {
3124
+ for (const o of (_a = f.options) != null ? _a : []) {
3125
3125
  const osid = o.service_id;
3126
3126
  if (typeof osid === "string" || typeof osid === "number" && Number.isFinite(osid)) {
3127
3127
  prim.push(osid);
@@ -3131,12 +3131,12 @@ function visibleGroupPrimaries(tag, fields) {
3131
3131
  return uniq(prim);
3132
3132
  }
3133
3133
  function applyPolicies(errors, props, serviceMap, policies, fieldsVisibleUnder, tags) {
3134
- var _a2, _b, _c, _d, _e;
3134
+ var _a, _b, _c, _d, _e;
3135
3135
  if (!(policies == null ? void 0 : policies.length)) return;
3136
3136
  const tagById = /* @__PURE__ */ new Map();
3137
3137
  for (const t of tags) tagById.set(t.id, t);
3138
3138
  for (const rule of policies) {
3139
- const projPath = (_a2 = rule.projection) != null ? _a2 : "service.id";
3139
+ const projPath = (_a = rule.projection) != null ? _a : "service.id";
3140
3140
  const severity = stableSeverity(
3141
3141
  rule.severity
3142
3142
  );
@@ -3270,16 +3270,16 @@ function resolveGlobalRatePolicy(options) {
3270
3270
  return normalizeRatePolicy(options.ratePolicy);
3271
3271
  }
3272
3272
  function resolveFallbackSettings(options) {
3273
- var _a2;
3273
+ var _a;
3274
3274
  return {
3275
3275
  ...DEFAULT_FALLBACK_SETTINGS,
3276
- ...(_a2 = options.fallbackSettings) != null ? _a2 : {}
3276
+ ...(_a = options.fallbackSettings) != null ? _a : {}
3277
3277
  };
3278
3278
  }
3279
3279
  function mergeValidatorOptions(defaults = {}, overrides = {}) {
3280
- var _a2, _b, _c, _d;
3280
+ var _a, _b, _c, _d;
3281
3281
  const mergedFallbackSettings = {
3282
- ...(_a2 = defaults.fallbackSettings) != null ? _a2 : {},
3282
+ ...(_a = defaults.fallbackSettings) != null ? _a : {},
3283
3283
  ...(_b = overrides.fallbackSettings) != null ? _b : {}
3284
3284
  };
3285
3285
  return {
@@ -3308,12 +3308,12 @@ function readVisibilitySimOpts(ctx) {
3308
3308
  };
3309
3309
  }
3310
3310
  function validate(props, ctx = {}) {
3311
- var _a2, _b, _c;
3311
+ var _a, _b, _c;
3312
3312
  const options = mergeValidatorOptions({}, ctx);
3313
3313
  const fallbackSettings = resolveFallbackSettings(options);
3314
3314
  const ratePolicy = resolveGlobalRatePolicy(options);
3315
3315
  const errors = [];
3316
- const serviceMap = (_a2 = options.serviceMap) != null ? _a2 : {};
3316
+ const serviceMap = (_a = options.serviceMap) != null ? _a : {};
3317
3317
  const selectedKeys = new Set(
3318
3318
  (_b = options.selectedOptionKeys) != null ? _b : []
3319
3319
  );
@@ -3412,16 +3412,16 @@ var BuilderImpl = class {
3412
3412
  this.options = { ...this.options, ...patch };
3413
3413
  }
3414
3414
  getServiceMap() {
3415
- var _a2;
3416
- return (_a2 = this.options.serviceMap) != null ? _a2 : {};
3415
+ var _a;
3416
+ return (_a = this.options.serviceMap) != null ? _a : {};
3417
3417
  }
3418
3418
  getConstraints() {
3419
- var _a2;
3419
+ var _a;
3420
3420
  const serviceMap = this.getServiceMap();
3421
3421
  const out = /* @__PURE__ */ new Set();
3422
3422
  const guard = /* @__PURE__ */ new Set();
3423
3423
  for (const svc of Object.values(serviceMap)) {
3424
- const flags = (_a2 = svc.flags) != null ? _a2 : {};
3424
+ const flags = (_a = svc.flags) != null ? _a : {};
3425
3425
  for (const flagId of Object.keys(flags)) {
3426
3426
  if (guard.has(flagId)) continue;
3427
3427
  guard.add(flagId);
@@ -3437,7 +3437,7 @@ var BuilderImpl = class {
3437
3437
  }
3438
3438
  /* ───── querying ─────────────────────────────────────────────────────── */
3439
3439
  tree() {
3440
- var _a2, _b, _c, _d;
3440
+ var _a, _b, _c, _d;
3441
3441
  const nodes = [];
3442
3442
  const edges = [];
3443
3443
  const showSet = toStringSet(this.options.showOptionNodes);
@@ -3494,7 +3494,7 @@ var BuilderImpl = class {
3494
3494
  }
3495
3495
  }
3496
3496
  for (const t of this.props.filters) {
3497
- for (const id of (_a2 = t.includes) != null ? _a2 : []) {
3497
+ for (const id of (_a = t.includes) != null ? _a : []) {
3498
3498
  edges.push({ from: t.id, to: id, kind: "include" });
3499
3499
  }
3500
3500
  for (const id of (_b = t.excludes) != null ? _b : []) {
@@ -3504,9 +3504,9 @@ var BuilderImpl = class {
3504
3504
  const incMap = (_c = this.props.includes_for_buttons) != null ? _c : {};
3505
3505
  const excMap = (_d = this.props.excludes_for_buttons) != null ? _d : {};
3506
3506
  const pushButtonEdge = (keyId, targetFieldId, kind) => {
3507
- var _a3;
3507
+ var _a2;
3508
3508
  const owner = this.optionOwnerById.get(keyId);
3509
- const ownerFieldId = (_a3 = owner == null ? void 0 : owner.fieldId) != null ? _a3 : this.fieldById.has(keyId) ? keyId : void 0;
3509
+ const ownerFieldId = (_a2 = owner == null ? void 0 : owner.fieldId) != null ? _a2 : this.fieldById.has(keyId) ? keyId : void 0;
3510
3510
  if (!ownerFieldId) return;
3511
3511
  const fromNode = owner && showSet.has(owner.fieldId) ? keyId : ownerFieldId;
3512
3512
  const meta = owner ? showSet.has(owner.fieldId) ? {
@@ -3532,14 +3532,14 @@ var BuilderImpl = class {
3532
3532
  return { nodes, edges };
3533
3533
  }
3534
3534
  cleanedProps() {
3535
- var _a2, _b, _c, _d, _e;
3535
+ var _a, _b, _c, _d, _e;
3536
3536
  const fieldIds = new Set(this.props.fields.map((f) => f.id));
3537
3537
  const optionIds = /* @__PURE__ */ new Set();
3538
3538
  this.optionOwnerById.forEach((_v, oid) => optionIds.add(oid));
3539
3539
  const includedByTag = /* @__PURE__ */ new Set();
3540
3540
  const excludedAnywhere = /* @__PURE__ */ new Set();
3541
3541
  for (const t of this.props.filters) {
3542
- for (const id of (_a2 = t.includes) != null ? _a2 : []) includedByTag.add(id);
3542
+ for (const id of (_a = t.includes) != null ? _a : []) includedByTag.add(id);
3543
3543
  for (const id of (_b = t.excludes) != null ? _b : []) excludedAnywhere.add(id);
3544
3544
  }
3545
3545
  const incMap = (_c = this.props.includes_for_buttons) != null ? _c : {};
@@ -3570,8 +3570,8 @@ var BuilderImpl = class {
3570
3570
  else if (typeof b === "string") boundIds.add(b);
3571
3571
  }
3572
3572
  const fields = this.props.fields.filter((f) => {
3573
- var _a3;
3574
- const isUtility = ((_a3 = f.pricing_role) != null ? _a3 : "base") === "utility";
3573
+ var _a2;
3574
+ const isUtility = ((_a2 = f.pricing_role) != null ? _a2 : "base") === "utility";
3575
3575
  if (!isUtility) return true;
3576
3576
  const bound = !!f.bind_id;
3577
3577
  const included = includedByTag.has(f.id) || includedByButtons.has(f.id);
@@ -3618,10 +3618,10 @@ var BuilderImpl = class {
3618
3618
  return cloneDeep2(this.options);
3619
3619
  }
3620
3620
  visibleFields(tagId, selectedKeys) {
3621
- var _a2;
3621
+ var _a;
3622
3622
  return visibleFieldIdsUnder(this.props, tagId, {
3623
3623
  selectedKeys: new Set(
3624
- (_a2 = selectedKeys != null ? selectedKeys : this.options.selectedOptionKeys) != null ? _a2 : []
3624
+ (_a = selectedKeys != null ? selectedKeys : this.options.selectedOptionKeys) != null ? _a : []
3625
3625
  )
3626
3626
  });
3627
3627
  }
@@ -3659,10 +3659,10 @@ var DEFAULT_SETTINGS = {
3659
3659
  mode: "strict"
3660
3660
  };
3661
3661
  function collectFailedFallbacks(props, services, settings) {
3662
- var _a2, _b, _c;
3662
+ var _a, _b, _c;
3663
3663
  const s = { ...DEFAULT_SETTINGS, ...settings != null ? settings : {} };
3664
3664
  const out = [];
3665
- const fb = (_a2 = props.fallbacks) != null ? _a2 : {};
3665
+ const fb = (_a = props.fallbacks) != null ? _a : {};
3666
3666
  const primaryRate = (primary) => rateOf(services, primary);
3667
3667
  for (const [nodeId, list] of Object.entries((_b = fb.nodes) != null ? _b : {})) {
3668
3668
  const { primary, tagContexts } = primaryForNode(props, nodeId);
@@ -3770,9 +3770,9 @@ function collectFailedFallbacks(props, services, settings) {
3770
3770
  return out;
3771
3771
  }
3772
3772
  function rateOf(map, id) {
3773
- var _a2, _b;
3773
+ var _a, _b;
3774
3774
  if (id === void 0 || id === null) return void 0;
3775
- return (_b = (_a2 = getCap(map, id)) == null ? void 0 : _a2.rate) != null ? _b : void 0;
3775
+ return (_b = (_a = getCap(map, id)) == null ? void 0 : _a.rate) != null ? _b : void 0;
3776
3776
  }
3777
3777
  function passesRate(policy, primaryRate, candidateRate) {
3778
3778
  if (typeof candidateRate !== "number" || !Number.isFinite(candidateRate)) {
@@ -3791,8 +3791,8 @@ function getCap(map, id) {
3791
3791
  return getServiceCapability(map, id);
3792
3792
  }
3793
3793
  function isCapFlagEnabled(capability, flagId) {
3794
- var _a2, _b;
3795
- const fromFlags = (_b = (_a2 = capability.flags) == null ? void 0 : _a2[flagId]) == null ? void 0 : _b.enabled;
3794
+ var _a, _b;
3795
+ const fromFlags = (_b = (_a = capability.flags) == null ? void 0 : _a[flagId]) == null ? void 0 : _b.enabled;
3796
3796
  if (fromFlags === true) return true;
3797
3797
  if (fromFlags === false) return false;
3798
3798
  const legacy = capability[flagId];
@@ -3831,8 +3831,8 @@ function bindIdsToArray(bind) {
3831
3831
  return Array.isArray(bind) ? bind.slice() : [bind];
3832
3832
  }
3833
3833
  function getEligibleFallbacks(params) {
3834
- var _a2, _b, _c, _d, _e, _f;
3835
- const s = { ...DEFAULT_SETTINGS, ...(_a2 = params.settings) != null ? _a2 : {} };
3834
+ var _a, _b, _c, _d, _e, _f;
3835
+ const s = { ...DEFAULT_SETTINGS, ...(_a = params.settings) != null ? _a : {} };
3836
3836
  const { primary, nodeId, tagId, services } = params;
3837
3837
  const excludes = /* @__PURE__ */ new Set();
3838
3838
  for (const ref of (_b = params.exclude) != null ? _b : []) {
@@ -3878,8 +3878,8 @@ function getEligibleFallbacks(params) {
3878
3878
  }
3879
3879
  if (s.selectionStrategy === "cheapest") {
3880
3880
  eligible.sort((left, right) => {
3881
- var _a3, _b2;
3882
- const leftRate = (_a3 = rateOf(services, left)) != null ? _a3 : Infinity;
3881
+ var _a2, _b2;
3882
+ const leftRate = (_a2 = rateOf(services, left)) != null ? _a2 : Infinity;
3883
3883
  const rightRate = (_b2 = rateOf(services, right)) != null ? _b2 : Infinity;
3884
3884
  return leftRate - rightRate;
3885
3885
  });
@@ -3890,7 +3890,7 @@ function getEligibleFallbacks(params) {
3890
3890
  return eligible;
3891
3891
  }
3892
3892
  function getAssignedServiceIds(params) {
3893
- var _a2, _b, _c, _d, _e;
3893
+ var _a, _b, _c, _d, _e;
3894
3894
  const seen = /* @__PURE__ */ new Set();
3895
3895
  const out = [];
3896
3896
  const push = (value) => {
@@ -3902,7 +3902,7 @@ function getAssignedServiceIds(params) {
3902
3902
  };
3903
3903
  const props = params.props;
3904
3904
  if (props) {
3905
- for (const tag of (_a2 = props.filters) != null ? _a2 : []) {
3905
+ for (const tag of (_a = props.filters) != null ? _a : []) {
3906
3906
  push(tag.service_id);
3907
3907
  }
3908
3908
  for (const field of (_b = props.fields) != null ? _b : []) {
@@ -3934,9 +3934,9 @@ function getFallbackRegistrationInfo(props, nodeId) {
3934
3934
  return { primary, tagContexts };
3935
3935
  }
3936
3936
  function listRegisteredFallbackCandidates(fallbacks, primary, nodeId, services) {
3937
- var _a2, _b;
3937
+ var _a, _b;
3938
3938
  const lists = [];
3939
- if (nodeId && ((_a2 = fallbacks.nodes) == null ? void 0 : _a2[nodeId])) {
3939
+ if (nodeId && ((_a = fallbacks.nodes) == null ? void 0 : _a[nodeId])) {
3940
3940
  lists.push(fallbacks.nodes[nodeId]);
3941
3941
  }
3942
3942
  for (const [registeredPrimary, list] of Object.entries((_b = fallbacks.global) != null ? _b : {})) {
@@ -3959,8 +3959,8 @@ function listServicePoolCandidates(services) {
3959
3959
  return out;
3960
3960
  }
3961
3961
  function getServicePoolCandidateId(key, capability) {
3962
- var _a2;
3963
- return (_a2 = getServiceCapabilityCanonicalRef({ [key]: capability }, key)) != null ? _a2 : key;
3962
+ var _a;
3963
+ return (_a = getServiceCapabilityCanonicalRef({ [key]: capability }, key)) != null ? _a : key;
3964
3964
  }
3965
3965
  function addComparableServiceRef(target, services, value) {
3966
3966
  for (const ref of getComparableServiceRefs(services, value)) {
@@ -3995,10 +3995,10 @@ var toBindList = (b) => {
3995
3995
  return typeof b === "string" ? [b] : [...b];
3996
3996
  };
3997
3997
  function createNodeIndex(builder) {
3998
- var _a2, _b, _c, _d;
3998
+ var _a, _b, _c, _d;
3999
3999
  const props = builder.getProps();
4000
4000
  const nodeMap = builder.getNodeMap();
4001
- const tags = (_a2 = props.filters) != null ? _a2 : [];
4001
+ const tags = (_a = props.filters) != null ? _a : [];
4002
4002
  const fields = (_b = props.fields) != null ? _b : [];
4003
4003
  const tagById = new Map(tags.map((t) => [t.id, t]));
4004
4004
  const fieldById = new Map(fields.map((f) => [f.id, f]));
@@ -4141,12 +4141,12 @@ function createNodeIndex(builder) {
4141
4141
  }
4142
4142
  });
4143
4143
  const getTag = (id) => {
4144
- var _a3, _b2;
4144
+ var _a2, _b2;
4145
4145
  const cached = tagNodeCache.get(id);
4146
4146
  if (cached) return cached;
4147
4147
  const raw = tagById.get(id);
4148
4148
  if (!raw) return void 0;
4149
- const includes = Object.freeze(new Set((_a3 = raw.includes) != null ? _a3 : []));
4149
+ const includes = Object.freeze(new Set((_a2 = raw.includes) != null ? _a2 : []));
4150
4150
  const excludes = Object.freeze(new Set((_b2 = raw.excludes) != null ? _b2 : []));
4151
4151
  const ancestryFn = makeAncestry([id]);
4152
4152
  const node = {
@@ -4161,17 +4161,17 @@ function createNodeIndex(builder) {
4161
4161
  return pid ? getTag(pid) : void 0;
4162
4162
  },
4163
4163
  children() {
4164
- var _a4;
4164
+ var _a3;
4165
4165
  const cachedChildren = tagChildrenCache.get(id);
4166
4166
  if (cachedChildren) return cachedChildren;
4167
- const childIds = (_a4 = childrenById.get(id)) != null ? _a4 : [];
4167
+ const childIds = (_a3 = childrenById.get(id)) != null ? _a3 : [];
4168
4168
  const arr = childIds.map((cid) => getTag(cid)).filter(Boolean);
4169
4169
  const frozen = Object.freeze(arr);
4170
4170
  tagChildrenCache.set(id, frozen);
4171
4171
  return frozen;
4172
4172
  },
4173
4173
  ancestors() {
4174
- var _a4;
4174
+ var _a3;
4175
4175
  const cachedAnc = tagAncestorsCache.get(id);
4176
4176
  if (cachedAnc) return cachedAnc;
4177
4177
  const rows = [];
@@ -4181,7 +4181,7 @@ function createNodeIndex(builder) {
4181
4181
  while (cur && !guard.has(cur)) {
4182
4182
  const n = getTag(cur);
4183
4183
  if (!n) break;
4184
- const p = (_a4 = pathBetween(id, cur)) != null ? _a4 : [id, cur];
4184
+ const p = (_a3 = pathBetween(id, cur)) != null ? _a3 : [id, cur];
4185
4185
  rows.push({ node: n, direct: index === 1, index, path: p });
4186
4186
  guard.add(cur);
4187
4187
  cur = parentById.get(cur);
@@ -4224,13 +4224,13 @@ function createNodeIndex(builder) {
4224
4224
  return node;
4225
4225
  };
4226
4226
  const getField = (id) => {
4227
- var _a3, _b2, _c2, _d2;
4227
+ var _a2, _b2, _c2, _d2;
4228
4228
  const cached = fieldNodeCache.get(id);
4229
4229
  if (cached) return cached;
4230
4230
  const raw = fieldById.get(id);
4231
4231
  if (!raw) return void 0;
4232
4232
  const isButton = raw.button === true;
4233
- const includes = isButton ? Object.freeze(new Set((_b2 = (_a3 = props.includes_for_buttons) == null ? void 0 : _a3[id]) != null ? _b2 : [])) : emptySet;
4233
+ const includes = isButton ? Object.freeze(new Set((_b2 = (_a2 = props.includes_for_buttons) == null ? void 0 : _a2[id]) != null ? _b2 : [])) : emptySet;
4234
4234
  const excludes = isButton ? Object.freeze(new Set((_d2 = (_c2 = props.excludes_for_buttons) == null ? void 0 : _c2[id]) != null ? _d2 : [])) : emptySet;
4235
4235
  const bindIds = () => {
4236
4236
  const cachedBind = fieldBindIdsCache.get(id);
@@ -4276,7 +4276,7 @@ function createNodeIndex(builder) {
4276
4276
  return node;
4277
4277
  };
4278
4278
  const getOption = (id) => {
4279
- var _a3, _b2, _c2, _d2;
4279
+ var _a2, _b2, _c2, _d2;
4280
4280
  const cached = optionNodeCache.get(id);
4281
4281
  if (cached) return cached;
4282
4282
  const raw = optionById.get(id);
@@ -4285,7 +4285,7 @@ function createNodeIndex(builder) {
4285
4285
  const owner = getField(ownerFieldId);
4286
4286
  if (!owner) return void 0;
4287
4287
  const includes = Object.freeze(
4288
- new Set((_b2 = (_a3 = props.includes_for_buttons) == null ? void 0 : _a3[id]) != null ? _b2 : [])
4288
+ new Set((_b2 = (_a2 = props.includes_for_buttons) == null ? void 0 : _a2[id]) != null ? _b2 : [])
4289
4289
  );
4290
4290
  const excludes = Object.freeze(
4291
4291
  new Set((_d2 = (_c2 = props.excludes_for_buttons) == null ? void 0 : _c2[id]) != null ? _d2 : [])
@@ -4320,13 +4320,13 @@ function createNodeIndex(builder) {
4320
4320
  return node;
4321
4321
  };
4322
4322
  const getNode2 = (input) => {
4323
- var _a3, _b2, _c2;
4323
+ var _a2, _b2, _c2;
4324
4324
  const id = typeof input === "object" ? input.id : input;
4325
4325
  const cached = nodeCache.get(id);
4326
4326
  if (cached) return cached;
4327
4327
  const node = nodeMap.get(id);
4328
4328
  if (!node) return mkUnknown(id);
4329
- if (node.kind === "tag") return (_a3 = getTag(id)) != null ? _a3 : mkUnknown(id);
4329
+ if (node.kind === "tag") return (_a2 = getTag(id)) != null ? _a2 : mkUnknown(id);
4330
4330
  if (node.kind == "field") return (_b2 = getField(id)) != null ? _b2 : mkUnknown(id);
4331
4331
  if (node.kind == "option") return (_c2 = getOption(id)) != null ? _c2 : mkUnknown(id);
4332
4332
  return mkUnknown(id);
@@ -4605,8 +4605,8 @@ function compilePolicies(raw) {
4605
4605
 
4606
4606
  // src/core/service-filter.ts
4607
4607
  function filterServicesForVisibleGroup(input, deps) {
4608
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4609
- const svcMap = (_c = (_b = (_a2 = deps.builder).getServiceMap) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
4608
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4609
+ const svcMap = (_c = (_b = (_a = deps.builder).getServiceMap) == null ? void 0 : _b.call(_a)) != null ? _c : {};
4610
4610
  const builderOptions = (_e = (_d = deps.builder).getOptions) == null ? void 0 : _e.call(_d);
4611
4611
  const { context } = input;
4612
4612
  const usedSet = new Set(context.usedServiceIds.map(String));
@@ -4715,7 +4715,7 @@ function evaluatePoliciesRaw(raw, serviceIds, svcMap, tagId, visibleServiceIds)
4715
4715
  };
4716
4716
  }
4717
4717
  function evaluateServicePolicies(rules, svcIds, svcMap, tagId, visibleServiceIds) {
4718
- var _a2, _b, _c;
4718
+ var _a, _b, _c;
4719
4719
  const errors = [];
4720
4720
  const warnings = [];
4721
4721
  if (!rules || !rules.length) return { ok: true, errors, warnings };
@@ -4766,7 +4766,7 @@ function evaluateServicePolicies(rules, svcIds, svcMap, tagId, visibleServiceIds
4766
4766
  ok = true;
4767
4767
  }
4768
4768
  if (!ok) {
4769
- if (((_a2 = r.severity) != null ? _a2 : "error") === "error") {
4769
+ if (((_a = r.severity) != null ? _a : "error") === "error") {
4770
4770
  errors.push((_b = r.id) != null ? _b : "policy_error");
4771
4771
  } else {
4772
4772
  warnings.push((_c = r.id) != null ? _c : "policy_warning");
@@ -4780,10 +4780,10 @@ function scopeServiceIdsForRule(serviceIds, rule, visibleServiceIds) {
4780
4780
  return serviceIds.filter((id) => visibleServiceIds.has(String(id)));
4781
4781
  }
4782
4782
  function collectVisibleServiceIds(builder, tagId, selectedButtons) {
4783
- var _a2, _b, _c;
4783
+ var _a, _b, _c;
4784
4784
  const out = /* @__PURE__ */ new Set();
4785
4785
  const props = builder.getProps();
4786
- const tags = (_a2 = props.filters) != null ? _a2 : [];
4786
+ const tags = (_a = props.filters) != null ? _a : [];
4787
4787
  const fields = (_b = props.fields) != null ? _b : [];
4788
4788
  const tag = tags.find((t) => t.id === tagId);
4789
4789
  if ((tag == null ? void 0 : tag.service_id) != null) out.add(String(tag.service_id));
@@ -4821,10 +4821,10 @@ function toStrSet(v) {
4821
4821
  return s;
4822
4822
  }
4823
4823
  function candidatePassesRateCoherence(builder, serviceMap, tagId, selectedKeys, usedServiceIds, candidateId, ratePolicy) {
4824
- var _a2, _b, _c, _d;
4824
+ var _a, _b, _c, _d;
4825
4825
  if (usedServiceIds.length === 0) return true;
4826
4826
  const props = builder.getProps();
4827
- const baseFields = (_a2 = props.fields) != null ? _a2 : [];
4827
+ const baseFields = (_a = props.fields) != null ? _a : [];
4828
4828
  const candidateFieldId = syntheticServiceFieldId("candidate", candidateId, 0);
4829
4829
  const syntheticFields = [
4830
4830
  ...usedServiceIds.map((serviceId, index) => ({
@@ -4901,10 +4901,10 @@ function syntheticServiceFieldId(kind, serviceId, index) {
4901
4901
  return `__service_filter_${kind}__:${index}:${String(serviceId)}`;
4902
4902
  }
4903
4903
  function rateIssueAffectsCandidate(error, candidateId, candidateFieldId, primaryAnchorId) {
4904
- var _a2, _b, _c, _d;
4904
+ var _a, _b, _c, _d;
4905
4905
  if (error.code !== "rate_coherence_violation") return false;
4906
4906
  const candidateKey = String(candidateId);
4907
- const details = (_a2 = error.details) != null ? _a2 : {};
4907
+ const details = (_a = error.details) != null ? _a : {};
4908
4908
  const anchorKey = primaryAnchorId == null ? void 0 : String(primaryAnchorId);
4909
4909
  const primaryMatchesAnchor = anchorKey == null || String((_b = details.primary) == null ? void 0 : _b.serviceId) === anchorKey || String((_c = details.primary) == null ? void 0 : _c.service_id) === anchorKey;
4910
4910
  if (primaryMatchesAnchor && ((_d = details.affectedServiceIds) == null ? void 0 : _d.some(
@@ -4924,7 +4924,7 @@ function rateIssueAffectsCandidate(error, candidateId, candidateFieldId, primary
4924
4924
 
4925
4925
  // src/utils/prune-fallbacks.ts
4926
4926
  function pruneInvalidNodeFallbacks(props, services, settings) {
4927
- var _a2, _b;
4927
+ var _a, _b;
4928
4928
  const fb = props.fallbacks;
4929
4929
  if (!(fb == null ? void 0 : fb.nodes) || Object.keys(fb.nodes).length === 0) {
4930
4930
  return { props, removed: [] };
@@ -4969,7 +4969,7 @@ function pruneInvalidNodeFallbacks(props, services, settings) {
4969
4969
  const prunedNodes = {};
4970
4970
  const removed = [];
4971
4971
  for (const [nodeId, list] of Object.entries(fb.nodes)) {
4972
- const contexts = (_a2 = nodeContexts.get(nodeId)) != null ? _a2 : [];
4972
+ const contexts = (_a = nodeContexts.get(nodeId)) != null ? _a : [];
4973
4973
  const totalContexts = Math.max(1, contexts.length);
4974
4974
  const keep = [];
4975
4975
  for (const cand of list) {
@@ -5010,7 +5010,7 @@ function toBindArray(bind) {
5010
5010
 
5011
5011
  // src/utils/build-order-snapshot/fallbacks.ts
5012
5012
  function pruneFallbacksConservative(fallbacks, env, svcMap, policy) {
5013
- var _a2, _b;
5013
+ var _a, _b;
5014
5014
  if (!fallbacks) return { pruned: void 0, original: void 0 };
5015
5015
  try {
5016
5016
  const { props: prunedProps } = pruneInvalidNodeFallbacks(
@@ -5029,7 +5029,7 @@ function pruneFallbacksConservative(fallbacks, env, svcMap, policy) {
5029
5029
  };
5030
5030
  } catch {
5031
5031
  const out = {};
5032
- const requireFit = (_a2 = policy.requireConstraintFit) != null ? _a2 : true;
5032
+ const requireFit = (_a = policy.requireConstraintFit) != null ? _a : true;
5033
5033
  if (fallbacks.nodes) {
5034
5034
  const keptNodes = {};
5035
5035
  for (const [nodeId, candidates] of Object.entries(
@@ -5089,17 +5089,37 @@ function toSelectedOptionKeys(byField) {
5089
5089
  }
5090
5090
  return keys;
5091
5091
  }
5092
- function getSelectedOptionsByFieldId(selection, fieldById) {
5093
- const out = {};
5092
+ function getSelectedOptionsByFieldId(selection, fieldById, mode) {
5093
+ var _a, _b;
5094
+ const collected = {};
5094
5095
  for (const visit of buildSelectedNodeVisitOrder(selection, fieldById)) {
5095
5096
  if (visit.kind !== "option") continue;
5096
- if (!out[visit.fieldId]) out[visit.fieldId] = [];
5097
- out[visit.fieldId].push(visit.optionId);
5097
+ if (!collected[visit.fieldId]) collected[visit.fieldId] = [];
5098
+ collected[visit.fieldId].push(visit.optionId);
5099
+ }
5100
+ const out = {};
5101
+ for (const [fieldId, optionIds] of Object.entries(collected)) {
5102
+ const field = fieldById.get(fieldId);
5103
+ if (!field) continue;
5104
+ const validOptionIds = new Set(
5105
+ ((_a = field.options) != null ? _a : []).map((option) => option.id)
5106
+ );
5107
+ const dedupedValid = [];
5108
+ const seen = /* @__PURE__ */ new Set();
5109
+ for (const optionId of optionIds) {
5110
+ if (!validOptionIds.has(optionId)) continue;
5111
+ if (seen.has(optionId)) continue;
5112
+ seen.add(optionId);
5113
+ dedupedValid.push(optionId);
5114
+ }
5115
+ const isMulti = ((_b = field.meta) == null ? void 0 : _b.multi) === true;
5116
+ const normalized = mode === "prod" && !isMulti ? dedupedValid.length ? [dedupedValid[dedupedValid.length - 1]] : [] : dedupedValid;
5117
+ if (normalized.length) out[fieldId] = normalized;
5098
5118
  }
5099
5119
  return out;
5100
5120
  }
5101
5121
  function buildSelectedNodeVisitOrder(selection, fieldById) {
5102
- var _a2, _b, _c;
5122
+ var _a, _b, _c;
5103
5123
  const out = [];
5104
5124
  const seen = /* @__PURE__ */ new Set();
5105
5125
  function pushField(fieldId) {
@@ -5114,7 +5134,7 @@ function buildSelectedNodeVisitOrder(selection, fieldById) {
5114
5134
  seen.add(key);
5115
5135
  out.push({ kind: "option", fieldId, optionId });
5116
5136
  }
5117
- for (const item of (_a2 = selection.optionTraversalOrder) != null ? _a2 : []) {
5137
+ for (const item of (_a = selection.optionTraversalOrder) != null ? _a : []) {
5118
5138
  pushOption(item.fieldId, item.optionId);
5119
5139
  }
5120
5140
  for (const rawKey of (_b = selection.selectedKeys) != null ? _b : []) {
@@ -5143,23 +5163,23 @@ function buildSelectedNodeVisitOrder(selection, fieldById) {
5143
5163
  return out;
5144
5164
  }
5145
5165
  function findOptionOwnerField(optionId, fieldById) {
5146
- var _a2;
5166
+ var _a;
5147
5167
  for (const field of fieldById.values()) {
5148
- if ((_a2 = field.options) == null ? void 0 : _a2.some((option) => option.id === optionId)) return field;
5168
+ if ((_a = field.options) == null ? void 0 : _a.some((option) => option.id === optionId)) return field;
5149
5169
  }
5150
5170
  return void 0;
5151
5171
  }
5152
5172
 
5153
5173
  // src/utils/build-order-snapshot/services.ts
5154
5174
  function isServiceBased(field) {
5155
- var _a2;
5175
+ var _a;
5156
5176
  if (field.service_id !== void 0 && field.service_id !== null) return true;
5157
- return !!((_a2 = field.options) == null ? void 0 : _a2.some(
5177
+ return !!((_a = field.options) == null ? void 0 : _a.some(
5158
5178
  (item) => item.service_id !== void 0 && item.service_id !== null
5159
5179
  ));
5160
5180
  }
5161
5181
  function resolveServices(tagId, visibleFieldIds, selection, tagById, fieldById, services) {
5162
- var _a2, _b, _c, _d;
5182
+ var _a, _b, _c, _d;
5163
5183
  const serviceMap = {};
5164
5184
  const visible = new Set(visibleFieldIds);
5165
5185
  const selectedBaseServices = [];
@@ -5179,7 +5199,7 @@ function resolveServices(tagId, visibleFieldIds, selection, tagById, fieldById,
5179
5199
  const field = fieldById.get(visit.fieldId);
5180
5200
  if (!field) continue;
5181
5201
  if (visit.kind === "field") {
5182
- const role2 = (_a2 = field.pricing_role) != null ? _a2 : "base";
5202
+ const role2 = (_a = field.pricing_role) != null ? _a : "base";
5183
5203
  if (role2 === "utility") continue;
5184
5204
  if (field.service_id !== void 0 && field.service_id !== null) {
5185
5205
  addSelectedBaseService(field.id, field.service_id);
@@ -5217,12 +5237,12 @@ function pickHighestRatePrimary2(services) {
5217
5237
  return best;
5218
5238
  }
5219
5239
  function getCap2(map, id) {
5220
- var _a2;
5221
- return (_a2 = map == null ? void 0 : map[id]) != null ? _a2 : map == null ? void 0 : map[String(id)];
5240
+ var _a;
5241
+ return (_a = map == null ? void 0 : map[id]) != null ? _a : map == null ? void 0 : map[String(id)];
5222
5242
  }
5223
5243
  function readServiceRate(services, sid) {
5224
- var _a2;
5225
- const rate = Number((_a2 = getCap2(services, sid)) == null ? void 0 : _a2.rate);
5244
+ var _a;
5245
+ const rate = Number((_a = getCap2(services, sid)) == null ? void 0 : _a.rate);
5226
5246
  return Number.isFinite(rate) ? rate : Number.NEGATIVE_INFINITY;
5227
5247
  }
5228
5248
  function pushService(map, nodeId, sid) {
@@ -5262,8 +5282,8 @@ function buildInputs(visibleFieldIds, fieldById, selection, selectedOptionsByFie
5262
5282
 
5263
5283
  // src/utils/build-order-snapshot/min-max.ts
5264
5284
  function getCap3(map, id) {
5265
- var _a2;
5266
- return (_a2 = map == null ? void 0 : map[id]) != null ? _a2 : map == null ? void 0 : map[String(id)];
5285
+ var _a;
5286
+ return (_a = map == null ? void 0 : map[id]) != null ? _a : map == null ? void 0 : map[String(id)];
5267
5287
  }
5268
5288
  function resolveMinMax(servicesList, services) {
5269
5289
  let min;
@@ -5283,20 +5303,20 @@ function resolveMinMax(servicesList, services) {
5283
5303
 
5284
5304
  // src/utils/build-order-snapshot/policy.ts
5285
5305
  function toSnapshotPolicy(settings) {
5286
- var _a2;
5306
+ var _a;
5287
5307
  return {
5288
5308
  ratePolicy: normalizeRatePolicy(settings.ratePolicy),
5289
- requireConstraintFit: (_a2 = settings.requireConstraintFit) != null ? _a2 : true
5309
+ requireConstraintFit: (_a = settings.requireConstraintFit) != null ? _a : true
5290
5310
  };
5291
5311
  }
5292
5312
 
5293
5313
  // src/utils/build-order-snapshot/quantity.ts
5294
5314
  function resolveQuantity(visibleFieldIds, fieldById, tagById, selection, tagId, hostDefault) {
5295
- var _a2;
5315
+ var _a;
5296
5316
  for (const fid of visibleFieldIds) {
5297
5317
  const field = fieldById.get(fid);
5298
5318
  if (!field) continue;
5299
- const rule = readQuantityRule((_a2 = field.meta) == null ? void 0 : _a2.quantity);
5319
+ const rule = readQuantityRule((_a = field.meta) == null ? void 0 : _a.quantity);
5300
5320
  if (!rule) continue;
5301
5321
  const raw = selection.formValuesByFieldId[fid];
5302
5322
  const evaluated = evaluateQuantityRule(rule, raw);
@@ -5319,14 +5339,14 @@ function resolveQuantity(visibleFieldIds, fieldById, tagById, selection, tagId,
5319
5339
  return { quantity: hostDefault, source: { kind: "default", defaultedFromHost: true } };
5320
5340
  }
5321
5341
  function resolveNodeDefaultQuantity(visibleFieldIds, fieldById, tagById, selection, tagId) {
5322
- var _a2, _b, _c;
5342
+ var _a, _b, _c;
5323
5343
  const visible = new Set(visibleFieldIds);
5324
5344
  const visits = buildSelectedNodeVisitOrder(selection, fieldById);
5325
5345
  for (const visit of visits) {
5326
5346
  if (visit.kind !== "option") continue;
5327
5347
  if (!visible.has(visit.fieldId)) continue;
5328
5348
  const field = fieldById.get(visit.fieldId);
5329
- if (!((_a2 = field == null ? void 0 : field.options) == null ? void 0 : _a2.length)) continue;
5349
+ if (!((_a = field == null ? void 0 : field.options) == null ? void 0 : _a.length)) continue;
5330
5350
  const option = field.options.find((item) => item.id === visit.optionId);
5331
5351
  const quantity = readPositiveFiniteNumber((_b = option == null ? void 0 : option.meta) == null ? void 0 : _b.quantityDefault);
5332
5352
  if (quantity !== void 0) {
@@ -5434,12 +5454,12 @@ function readPositiveFiniteNumber(value) {
5434
5454
 
5435
5455
  // src/utils/build-order-snapshot/utilities.ts
5436
5456
  function collectUtilityLineItems(visibleFieldIds, fieldById, selection, selectedOptionsByFieldId, quantity) {
5437
- var _a2, _b, _c, _d, _e;
5457
+ var _a, _b, _c, _d, _e;
5438
5458
  const items = [];
5439
5459
  for (const fid of visibleFieldIds) {
5440
5460
  const field = fieldById.get(fid);
5441
5461
  if (!field) continue;
5442
- const isUtilityField = ((_a2 = field.pricing_role) != null ? _a2 : "base") === "utility";
5462
+ const isUtilityField = ((_a = field.pricing_role) != null ? _a : "base") === "utility";
5443
5463
  const marker = readUtilityMarker((_b = field.meta) == null ? void 0 : _b.utility);
5444
5464
  if (isUtilityField && marker) {
5445
5465
  const value = selection.formValuesByFieldId[field.id];
@@ -5485,7 +5505,7 @@ function readUtilityMarker(v) {
5485
5505
  return out;
5486
5506
  }
5487
5507
  function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5488
- var _a2, _b;
5508
+ var _a, _b;
5489
5509
  const base = {
5490
5510
  nodeId,
5491
5511
  mode: marker.mode,
@@ -5495,7 +5515,7 @@ function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5495
5515
  inputs: { quantity }
5496
5516
  };
5497
5517
  if (marker.mode === "per_value") {
5498
- base.inputs.valueBy = (_a2 = marker.valueBy) != null ? _a2 : "value";
5518
+ base.inputs.valueBy = (_a = marker.valueBy) != null ? _a : "value";
5499
5519
  if (marker.valueBy === "length") {
5500
5520
  base.inputs.value = Array.isArray(value) ? value.length : typeof value === "string" ? value.length : 0;
5501
5521
  } else {
@@ -5507,7 +5527,7 @@ function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5507
5527
 
5508
5528
  // src/utils/build-order-snapshot/context.ts
5509
5529
  function buildNodeContexts(tagId, visibleFieldIds, fieldById, _selection, selectedOptionsByFieldId) {
5510
- var _a2;
5530
+ var _a;
5511
5531
  const ctx = {};
5512
5532
  ctx[tagId] = tagId;
5513
5533
  for (const fid of visibleFieldIds) {
@@ -5515,7 +5535,7 @@ function buildNodeContexts(tagId, visibleFieldIds, fieldById, _selection, select
5515
5535
  if (!field) continue;
5516
5536
  const binds = normalizeBindIds(field.bind_id);
5517
5537
  const applicable = binds.has(tagId);
5518
- const selectedOptionIds = (_a2 = selectedOptionsByFieldId[fid]) != null ? _a2 : [];
5538
+ const selectedOptionIds = (_a = selectedOptionsByFieldId[fid]) != null ? _a : [];
5519
5539
  for (const oid of selectedOptionIds) {
5520
5540
  ctx[oid] = applicable ? tagId : null;
5521
5541
  }
@@ -5567,8 +5587,8 @@ function buildDevWarnings(props, svcMap, originalFallbacks, fieldById, visibleFi
5567
5587
 
5568
5588
  // src/utils/build-order-snapshot/index.ts
5569
5589
  function buildOrderSnapshot(props, builder, selection, services, settings = {}) {
5570
- var _a2, _b, _c, _d, _e, _f, _g, _h;
5571
- const mode = (_a2 = settings.mode) != null ? _a2 : "prod";
5590
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5591
+ const mode = (_a = settings.mode) != null ? _a : "prod";
5572
5592
  const hostDefaultQty = Number.isFinite((_b = settings.hostDefaultQuantity) != null ? _b : 1) ? settings.hostDefaultQuantity : 1;
5573
5593
  const fbSettings = {
5574
5594
  requireConstraintFit: true,
@@ -5584,10 +5604,14 @@ function buildOrderSnapshot(props, builder, selection, services, settings = {})
5584
5604
  const tagById = new Map(((_e = props.filters) != null ? _e : []).map((t) => [t.id, t]));
5585
5605
  const fieldById = new Map(((_f = props.fields) != null ? _f : []).map((f) => [f.id, f]));
5586
5606
  const tagConstraints = (_h = (_g = tagById.get(tagId)) == null ? void 0 : _g.constraints) != null ? _h : void 0;
5587
- const selectedOptionsByFieldId = getSelectedOptionsByFieldId(selection, fieldById);
5607
+ const selectedOptionsByFieldId = getSelectedOptionsByFieldId(
5608
+ selection,
5609
+ fieldById,
5610
+ mode
5611
+ );
5588
5612
  const selectionFields = visibleFieldIds.map((fid) => fieldById.get(fid)).filter((f) => !!f).map((f) => {
5589
- var _a3;
5590
- const optionIds = isOptionBased(f) ? (_a3 = selectedOptionsByFieldId[f.id]) != null ? _a3 : [] : void 0;
5613
+ var _a2;
5614
+ const optionIds = isOptionBased(f) ? (_a2 = selectedOptionsByFieldId[f.id]) != null ? _a2 : [] : void 0;
5591
5615
  return {
5592
5616
  id: f.id,
5593
5617
  type: String(f.type),
@@ -5689,12 +5713,12 @@ function buildOrderSnapshot(props, builder, selection, services, settings = {})
5689
5713
 
5690
5714
  // src/core/fallback-editor.ts
5691
5715
  function createFallbackEditor(options = {}) {
5692
- var _a2, _b;
5716
+ var _a, _b;
5693
5717
  const original = cloneFallbacks(options.fallbacks);
5694
5718
  let current = cloneFallbacks(options.fallbacks);
5695
5719
  const props = options.props;
5696
5720
  const snapshot = options.snapshot;
5697
- const services = (_a2 = options.services) != null ? _a2 : {};
5721
+ const services = (_a = options.services) != null ? _a : {};
5698
5722
  const settings = (_b = options.settings) != null ? _b : {};
5699
5723
  function state() {
5700
5724
  return {
@@ -5711,9 +5735,9 @@ function createFallbackEditor(options = {}) {
5711
5735
  return state();
5712
5736
  }
5713
5737
  function get(serviceId) {
5714
- var _a3, _b2;
5738
+ var _a2, _b2;
5715
5739
  const out = [];
5716
- for (const [primary, list] of Object.entries((_a3 = current.global) != null ? _a3 : {})) {
5740
+ for (const [primary, list] of Object.entries((_a2 = current.global) != null ? _a2 : {})) {
5717
5741
  if (String(primary) !== String(serviceId)) continue;
5718
5742
  out.push({
5719
5743
  scope: "global",
@@ -5735,14 +5759,14 @@ function createFallbackEditor(options = {}) {
5735
5759
  return out;
5736
5760
  }
5737
5761
  function getScope(context) {
5738
- var _a3, _b2, _c, _d;
5762
+ var _a2, _b2, _c, _d;
5739
5763
  if (context.scope === "global") {
5740
- return [...(_b2 = (_a3 = current.global) == null ? void 0 : _a3[context.primary]) != null ? _b2 : []];
5764
+ return [...(_b2 = (_a2 = current.global) == null ? void 0 : _a2[context.primary]) != null ? _b2 : []];
5741
5765
  }
5742
5766
  return [...(_d = (_c = current.nodes) == null ? void 0 : _c[context.nodeId]) != null ? _d : []];
5743
5767
  }
5744
5768
  function check(context, candidates) {
5745
- var _a3, _b2;
5769
+ var _a2, _b2;
5746
5770
  const normalized = normalizeCandidateList(
5747
5771
  candidates != null ? candidates : getScope(context),
5748
5772
  true
@@ -5761,7 +5785,7 @@ function createFallbackEditor(options = {}) {
5761
5785
  }
5762
5786
  const tempFallbacks = cloneFallbacks(current);
5763
5787
  if (context.scope === "global") {
5764
- (_a3 = tempFallbacks.global) != null ? _a3 : tempFallbacks.global = {};
5788
+ (_a2 = tempFallbacks.global) != null ? _a2 : tempFallbacks.global = {};
5765
5789
  if (normalized.length)
5766
5790
  tempFallbacks.global[context.primary] = normalized;
5767
5791
  else delete tempFallbacks.global[context.primary];
@@ -5880,9 +5904,9 @@ function createFallbackEditor(options = {}) {
5880
5904
  return writeScope(context, []);
5881
5905
  }
5882
5906
  function eligible(context, opt) {
5883
- var _a3, _b2;
5907
+ var _a2, _b2;
5884
5908
  if (!props) return [];
5885
- const source = (_a3 = opt == null ? void 0 : opt.source) != null ? _a3 : "all_services";
5909
+ const source = (_a2 = opt == null ? void 0 : opt.source) != null ? _a2 : "all_services";
5886
5910
  const exclude2 = normalizeCandidateList(
5887
5911
  [
5888
5912
  ...(_b2 = opt == null ? void 0 : opt.exclude) != null ? _b2 : [],
@@ -5927,10 +5951,10 @@ function createFallbackEditor(options = {}) {
5927
5951
  });
5928
5952
  }
5929
5953
  function writeScope(context, nextList) {
5930
- var _a3, _b2;
5954
+ var _a2, _b2;
5931
5955
  const next = cloneFallbacks(current);
5932
5956
  if (context.scope === "global") {
5933
- (_a3 = next.global) != null ? _a3 : next.global = {};
5957
+ (_a2 = next.global) != null ? _a2 : next.global = {};
5934
5958
  if (nextList.length) {
5935
5959
  next.global[context.primary] = [...nextList];
5936
5960
  } else {
@@ -6020,9 +6044,9 @@ function getNodeRegistrationInfo(props, nodeId) {
6020
6044
  };
6021
6045
  }
6022
6046
  function findOptionOwner(fields, optionId) {
6023
- var _a2;
6047
+ var _a;
6024
6048
  for (const field of fields) {
6025
- for (const option of (_a2 = field.options) != null ? _a2 : []) {
6049
+ for (const option of (_a = field.options) != null ? _a : []) {
6026
6050
  if (option.id === optionId) return { field, option };
6027
6051
  }
6028
6052
  }
@@ -6033,8 +6057,8 @@ function bindIdsToArray2(v) {
6033
6057
  return v ? [v] : [];
6034
6058
  }
6035
6059
  function resolveNodeTagContext(params) {
6036
- var _a2, _b, _c;
6037
- const nodeContexts = (_c = (_b = (_a2 = params.snapshot) == null ? void 0 : _a2.meta) == null ? void 0 : _b.context) == null ? void 0 : _c.nodeContexts;
6060
+ var _a, _b, _c;
6061
+ const nodeContexts = (_c = (_b = (_a = params.snapshot) == null ? void 0 : _a.meta) == null ? void 0 : _b.context) == null ? void 0 : _c.nodeContexts;
6038
6062
  if (nodeContexts && Object.prototype.hasOwnProperty.call(nodeContexts, params.nodeId)) {
6039
6063
  const tagId = nodeContexts[params.nodeId];
6040
6064
  return typeof tagId === "string" && tagId.trim().length > 0 ? tagId : void 0;
@@ -6060,12 +6084,46 @@ function mapDiagReason(reason) {
6060
6084
  }
6061
6085
  }
6062
6086
 
6087
+ // src/react/inputs/registry.ts
6088
+ function createInputRegistry() {
6089
+ const store = /* @__PURE__ */ new Map();
6090
+ const get = (kind, variant) => {
6091
+ var _a;
6092
+ const vm = store.get(kind);
6093
+ if (!vm) return void 0;
6094
+ const v = variant != null ? variant : "default";
6095
+ return (_a = vm.get(v)) != null ? _a : vm.get("default");
6096
+ };
6097
+ const register = (kind, descriptor, variant) => {
6098
+ let vm = store.get(kind);
6099
+ if (!vm) {
6100
+ vm = /* @__PURE__ */ new Map();
6101
+ store.set(kind, vm);
6102
+ }
6103
+ vm.set(variant != null ? variant : "default", descriptor);
6104
+ };
6105
+ const unregister = (kind, variant) => {
6106
+ const vm = store.get(kind);
6107
+ if (!vm) return;
6108
+ const key = variant != null ? variant : "default";
6109
+ vm.delete(key);
6110
+ if (vm.size === 0) store.delete(kind);
6111
+ };
6112
+ const registerMany = (entries) => {
6113
+ for (const e of entries) register(e.kind, e.descriptor, e.variant);
6114
+ };
6115
+ return { get, register, unregister, registerMany, _store: store };
6116
+ }
6117
+ function resolveInputDescriptor(registry, kind, variant) {
6118
+ return registry.get(kind, variant);
6119
+ }
6120
+
6063
6121
  // src/react/canvas/editor/editor-ids.ts
6064
6122
  function uniqueId(ctx, base) {
6065
- var _a2, _b;
6123
+ var _a, _b;
6066
6124
  const props = ctx.getProps();
6067
6125
  const taken = /* @__PURE__ */ new Set([
6068
- ...((_a2 = props.filters) != null ? _a2 : []).map((t) => t.id),
6126
+ ...((_a = props.filters) != null ? _a : []).map((t) => t.id),
6069
6127
  ...((_b = props.fields) != null ? _b : []).map((f) => f.id)
6070
6128
  ]);
6071
6129
  let candidate = nextCopyId(base);
@@ -6073,9 +6131,9 @@ function uniqueId(ctx, base) {
6073
6131
  return candidate;
6074
6132
  }
6075
6133
  function uniqueOptionId(ctx, fieldId, base) {
6076
- var _a2, _b;
6134
+ var _a, _b;
6077
6135
  const props = ctx.getProps();
6078
- const fld = ((_a2 = props.fields) != null ? _a2 : []).find((f) => f.id === fieldId);
6136
+ const fld = ((_a = props.fields) != null ? _a : []).find((f) => f.id === fieldId);
6079
6137
  const taken = new Set(((_b = fld == null ? void 0 : fld.options) != null ? _b : []).map((o) => o.id));
6080
6138
  let candidate = base;
6081
6139
  if (taken.has(candidate)) candidate = nextCopyId(candidate);
@@ -6083,14 +6141,14 @@ function uniqueOptionId(ctx, fieldId, base) {
6083
6141
  return candidate;
6084
6142
  }
6085
6143
  function genId(ctx, prefix) {
6086
- var _a2, _b, _c;
6144
+ var _a, _b, _c;
6087
6145
  const props = ctx.getProps();
6088
6146
  const taken = /* @__PURE__ */ new Set([
6089
- ...((_a2 = props.filters) != null ? _a2 : []).map((t) => t.id),
6147
+ ...((_a = props.filters) != null ? _a : []).map((t) => t.id),
6090
6148
  ...((_b = props.fields) != null ? _b : []).map((f) => f.id),
6091
6149
  ...((_c = props.fields) != null ? _c : []).flatMap((f) => {
6092
- var _a3, _b2;
6093
- return (_b2 = (_a3 = f.options) == null ? void 0 : _a3.map((o) => o.id)) != null ? _b2 : [];
6150
+ var _a2, _b2;
6151
+ return (_b2 = (_a2 = f.options) == null ? void 0 : _a2.map((o) => o.id)) != null ? _b2 : [];
6094
6152
  })
6095
6153
  ]);
6096
6154
  for (let i = 1; i < 1e4; i++) {
@@ -6152,11 +6210,11 @@ function duplicateMany(ctx, ids, opts = {}) {
6152
6210
  try {
6153
6211
  const created = [];
6154
6212
  ctx.transact("duplicateMany", () => {
6155
- var _a2, _b, _c;
6213
+ var _a, _b, _c;
6156
6214
  const props = ctx.getProps();
6157
6215
  const selectedFields = /* @__PURE__ */ new Set();
6158
6216
  for (const id of ordered) {
6159
- if (ctx.isFieldId(id) && ((_a2 = props.fields) != null ? _a2 : []).some((f) => f.id === id)) {
6217
+ if (ctx.isFieldId(id) && ((_a = props.fields) != null ? _a : []).some((f) => f.id === id)) {
6160
6218
  selectedFields.add(id);
6161
6219
  }
6162
6220
  }
@@ -6205,8 +6263,8 @@ function duplicateInPlace(ctx, ref, opts = {}) {
6205
6263
  return duplicateOption(ctx, ref.fieldId, ref.id, opts);
6206
6264
  }
6207
6265
  function ownerFieldOfOption(props, optionId) {
6208
- var _a2, _b;
6209
- for (const field of (_a2 = props.fields) != null ? _a2 : []) {
6266
+ var _a, _b;
6267
+ for (const field of (_a = props.fields) != null ? _a : []) {
6210
6268
  if (((_b = field.options) != null ? _b : []).some((o) => o.id === optionId)) {
6211
6269
  return { fieldId: field.id };
6212
6270
  }
@@ -6214,21 +6272,21 @@ function ownerFieldOfOption(props, optionId) {
6214
6272
  return null;
6215
6273
  }
6216
6274
  function duplicateTag(ctx, tagId, opts) {
6217
- var _a2, _b, _c, _d;
6275
+ var _a, _b, _c, _d;
6218
6276
  const props = ctx.getProps();
6219
- const tags = (_a2 = props.filters) != null ? _a2 : [];
6277
+ const tags = (_a = props.filters) != null ? _a : [];
6220
6278
  const src = tags.find((t) => t.id === tagId);
6221
6279
  if (!src) throw new Error(`Tag not found: ${tagId}`);
6222
6280
  const id = (_b = opts.id) != null ? _b : ctx.uniqueId(src.id);
6223
6281
  const label = ((_c = opts.labelStrategy) != null ? _c : nextCopyLabel)((_d = src.label) != null ? _d : id);
6224
6282
  if (!opts.withChildren) {
6225
6283
  ctx.patchProps((p) => {
6226
- var _a3;
6284
+ var _a2;
6227
6285
  const clone2 = { ...src, id, label };
6228
6286
  clone2.bind_id = src.bind_id;
6229
6287
  clone2.constraints_overrides = void 0;
6230
6288
  clone2.constraints_origin = void 0;
6231
- const arr = (_a3 = p.filters) != null ? _a3 : [];
6289
+ const arr = (_a2 = p.filters) != null ? _a2 : [];
6232
6290
  const idx = arr.findIndex((t) => t.id === tagId);
6233
6291
  arr.splice(idx + 1, 0, clone2);
6234
6292
  p.filters = arr;
@@ -6248,18 +6306,18 @@ function duplicateTag(ctx, tagId, opts) {
6248
6306
  idMap.set(n.id, n.id === src.id ? id : ctx.uniqueId(n.id));
6249
6307
  }
6250
6308
  const clones = subtree.map((n) => {
6251
- var _a3, _b2, _c2;
6309
+ var _a2, _b2, _c2;
6252
6310
  const cloned = { ...n };
6253
6311
  cloned.id = idMap.get(n.id);
6254
- cloned.label = n.id === src.id ? label : ((_a3 = opts.labelStrategy) != null ? _a3 : nextCopyLabel)((_b2 = n.label) != null ? _b2 : n.id);
6312
+ cloned.label = n.id === src.id ? label : ((_a2 = opts.labelStrategy) != null ? _a2 : nextCopyLabel)((_b2 = n.label) != null ? _b2 : n.id);
6255
6313
  cloned.bind_id = n.bind_id ? (_c2 = idMap.get(n.bind_id)) != null ? _c2 : n.bind_id : void 0;
6256
6314
  cloned.constraints_origin = void 0;
6257
6315
  cloned.constraints_overrides = void 0;
6258
6316
  return cloned;
6259
6317
  });
6260
6318
  ctx.patchProps((p) => {
6261
- var _a3;
6262
- const arr = (_a3 = p.filters) != null ? _a3 : [];
6319
+ var _a2;
6320
+ const arr = (_a2 = p.filters) != null ? _a2 : [];
6263
6321
  const rootIdx = arr.findIndex((t) => t.id === tagId);
6264
6322
  arr.splice(rootIdx + 1, 0, clones[0]);
6265
6323
  for (const c of clones.slice(1)) arr.push(c);
@@ -6268,27 +6326,27 @@ function duplicateTag(ctx, tagId, opts) {
6268
6326
  return id;
6269
6327
  }
6270
6328
  function duplicateField(ctx, fieldId, opts) {
6271
- var _a2, _b, _c, _d, _e, _f, _g;
6329
+ var _a, _b, _c, _d, _e, _f, _g;
6272
6330
  const props = ctx.getProps();
6273
- const fields = (_a2 = props.fields) != null ? _a2 : [];
6331
+ const fields = (_a = props.fields) != null ? _a : [];
6274
6332
  const src = fields.find((f) => f.id === fieldId);
6275
6333
  if (!src) throw new Error(`Field not found: ${fieldId}`);
6276
6334
  const id = (_b = opts.id) != null ? _b : ctx.uniqueId(src.id);
6277
6335
  const label = ((_c = opts.labelStrategy) != null ? _c : nextCopyLabel)((_d = src.label) != null ? _d : id);
6278
6336
  const name = opts.nameStrategy ? opts.nameStrategy(src.name) : nextCopyName(src.name);
6279
6337
  const optId = (old) => {
6280
- var _a3;
6338
+ var _a2;
6281
6339
  return ctx.uniqueOptionId(
6282
6340
  id,
6283
- ((_a3 = opts.optionIdStrategy) != null ? _a3 : defaultOptionIdStrategy)(old)
6341
+ ((_a2 = opts.optionIdStrategy) != null ? _a2 : defaultOptionIdStrategy)(old)
6284
6342
  );
6285
6343
  };
6286
6344
  const clonedOptions = ((_e = src.options) != null ? _e : []).map((o) => {
6287
- var _a3, _b2;
6345
+ var _a2, _b2;
6288
6346
  return {
6289
6347
  ...o,
6290
6348
  id: optId(o.id),
6291
- label: ((_a3 = opts.labelStrategy) != null ? _a3 : nextCopyLabel)((_b2 = o.label) != null ? _b2 : o.id)
6349
+ label: ((_a2 = opts.labelStrategy) != null ? _a2 : nextCopyLabel)((_b2 = o.label) != null ? _b2 : o.id)
6292
6350
  };
6293
6351
  });
6294
6352
  const cloned = {
@@ -6301,13 +6359,13 @@ function duplicateField(ctx, fieldId, opts) {
6301
6359
  };
6302
6360
  const optionIdMap = /* @__PURE__ */ new Map();
6303
6361
  ((_g = src.options) != null ? _g : []).forEach((o, i) => {
6304
- var _a3, _b2;
6305
- const newOptId = (_b2 = (_a3 = clonedOptions[i]) == null ? void 0 : _a3.id) != null ? _b2 : o.id;
6362
+ var _a2, _b2;
6363
+ const newOptId = (_b2 = (_a2 = clonedOptions[i]) == null ? void 0 : _a2.id) != null ? _b2 : o.id;
6306
6364
  optionIdMap.set(o.id, newOptId);
6307
6365
  });
6308
6366
  ctx.patchProps((p) => {
6309
- var _a3, _b2, _c2, _d2, _e2, _f2, _g2;
6310
- const arr = (_a3 = p.fields) != null ? _a3 : [];
6367
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
6368
+ const arr = (_a2 = p.fields) != null ? _a2 : [];
6311
6369
  const idx = arr.findIndex((f) => f.id === fieldId);
6312
6370
  arr.splice(idx + 1, 0, cloned);
6313
6371
  p.fields = arr;
@@ -6355,9 +6413,9 @@ function duplicateField(ctx, fieldId, opts) {
6355
6413
  return id;
6356
6414
  }
6357
6415
  function duplicateOption(ctx, fieldId, optionId, opts) {
6358
- var _a2, _b, _c, _d, _e, _f;
6416
+ var _a, _b, _c, _d, _e, _f;
6359
6417
  const props = ctx.getProps();
6360
- const fields = (_a2 = props.fields) != null ? _a2 : [];
6418
+ const fields = (_a = props.fields) != null ? _a : [];
6361
6419
  const f = fields.find((x) => x.id === fieldId);
6362
6420
  if (!f) throw new Error(`Field not found: ${fieldId}`);
6363
6421
  const optIdx = ((_b = f.options) != null ? _b : []).findIndex((o) => o.id === optionId);
@@ -6371,8 +6429,8 @@ function duplicateOption(ctx, fieldId, optionId, opts) {
6371
6429
  );
6372
6430
  const newLabel = ((_e = opts.labelStrategy) != null ? _e : nextCopyLabel)((_f = src.label) != null ? _f : src.id);
6373
6431
  ctx.patchProps((p) => {
6374
- var _a3, _b2, _c2;
6375
- const fld = ((_a3 = p.fields) != null ? _a3 : []).find((x) => x.id === fieldId);
6432
+ var _a2, _b2, _c2;
6433
+ const fld = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6376
6434
  const arr = (_b2 = fld.options) != null ? _b2 : [];
6377
6435
  const clone2 = { ...src, id: newId, label: newLabel };
6378
6436
  arr.splice(optIdx + 1, 0, clone2);
@@ -6397,8 +6455,8 @@ function duplicateOption(ctx, fieldId, optionId, opts) {
6397
6455
 
6398
6456
  // src/react/canvas/editor/editor-notices.ts
6399
6457
  function genNoticeId(ctx) {
6400
- var _a2;
6401
- const taken = new Set(((_a2 = ctx.getProps().notices) != null ? _a2 : []).map((n) => n.id));
6458
+ var _a;
6459
+ const taken = new Set(((_a = ctx.getProps().notices) != null ? _a : []).map((n) => n.id));
6402
6460
  for (let i = 1; i < 1e4; i++) {
6403
6461
  const id = `n:${i}`;
6404
6462
  if (!taken.has(id)) return id;
@@ -6406,13 +6464,13 @@ function genNoticeId(ctx) {
6406
6464
  throw new Error("Unable to generate notice id");
6407
6465
  }
6408
6466
  function addNotice(ctx, input) {
6409
- var _a2;
6410
- const id = (_a2 = input.id) != null ? _a2 : genNoticeId(ctx);
6467
+ var _a;
6468
+ const id = (_a = input.id) != null ? _a : genNoticeId(ctx);
6411
6469
  ctx.exec({
6412
6470
  name: "addNotice",
6413
6471
  do: () => ctx.patchProps((p) => {
6414
- var _a3;
6415
- const notices = (_a3 = p.notices) != null ? _a3 : p.notices = [];
6472
+ var _a2;
6473
+ const notices = (_a2 = p.notices) != null ? _a2 : p.notices = [];
6416
6474
  if (notices.some((n) => n.id === id)) {
6417
6475
  throw new Error(`Notice id '${id}' already exists`);
6418
6476
  }
@@ -6440,8 +6498,8 @@ function removeNotice(ctx, id) {
6440
6498
  ctx.exec({
6441
6499
  name: "removeNotice",
6442
6500
  do: () => ctx.patchProps((p) => {
6443
- var _a2;
6444
- if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
6501
+ var _a;
6502
+ if (!((_a = p.notices) == null ? void 0 : _a.length)) return;
6445
6503
  p.notices = p.notices.filter((n) => n.id !== id);
6446
6504
  if (!p.notices.length) delete p.notices;
6447
6505
  }),
@@ -6454,8 +6512,8 @@ import { cloneDeep as cloneDeep3 } from "lodash-es";
6454
6512
 
6455
6513
  // src/react/canvas/editor/editor-utils.ts
6456
6514
  function ownerOfOption(props, optionId) {
6457
- var _a2, _b;
6458
- for (const f of (_a2 = props.fields) != null ? _a2 : []) {
6515
+ var _a, _b;
6516
+ for (const f of (_a = props.fields) != null ? _a : []) {
6459
6517
  const idx = ((_b = f.options) != null ? _b : []).findIndex((o) => o.id === optionId);
6460
6518
  if (idx >= 0) return { fieldId: f.id, index: idx };
6461
6519
  }
@@ -6468,8 +6526,8 @@ function isActualButtonField(field) {
6468
6526
  return (field == null ? void 0 : field.button) === true && !hasFieldOptions(field);
6469
6527
  }
6470
6528
  function clearFieldButtonReceiverMaps(props, fieldId) {
6471
- var _a2, _b;
6472
- if ((_a2 = props.includes_for_buttons) == null ? void 0 : _a2[fieldId]) {
6529
+ var _a, _b;
6530
+ if ((_a = props.includes_for_buttons) == null ? void 0 : _a[fieldId]) {
6473
6531
  delete props.includes_for_buttons[fieldId];
6474
6532
  }
6475
6533
  if ((_b = props.excludes_for_buttons) == null ? void 0 : _b[fieldId]) {
@@ -6510,8 +6568,8 @@ function stripDeletedIds(ids) {
6510
6568
  return { ordered, set: new Set(ordered) };
6511
6569
  }
6512
6570
  function cleanTagRelationsForDeleted(p, deleted) {
6513
- var _a2;
6514
- for (const t of (_a2 = p.filters) != null ? _a2 : []) {
6571
+ var _a;
6572
+ for (const t of (_a = p.filters) != null ? _a : []) {
6515
6573
  if (t.bind_id && deleted.has(String(t.bind_id))) delete t.bind_id;
6516
6574
  if (t.includes) {
6517
6575
  const next = t.includes.filter((x) => !deleted.has(String(x)));
@@ -6526,8 +6584,8 @@ function cleanTagRelationsForDeleted(p, deleted) {
6526
6584
  }
6527
6585
  }
6528
6586
  function cleanFieldBindsForDeleted(p, deleted) {
6529
- var _a2;
6530
- for (const f of (_a2 = p.fields) != null ? _a2 : []) {
6587
+ var _a;
6588
+ for (const f of (_a = p.fields) != null ? _a : []) {
6531
6589
  const bind = f.bind_id;
6532
6590
  if (!bind) continue;
6533
6591
  if (Array.isArray(bind)) {
@@ -6540,7 +6598,7 @@ function cleanFieldBindsForDeleted(p, deleted) {
6540
6598
  }
6541
6599
  }
6542
6600
  function cleanRelationMapsForDeleted(p, deleted) {
6543
- var _a2;
6601
+ var _a;
6544
6602
  for (const key of RELATION_MAP_KEYS) {
6545
6603
  const map = p[key];
6546
6604
  if (!map) continue;
@@ -6549,7 +6607,7 @@ function cleanRelationMapsForDeleted(p, deleted) {
6549
6607
  delete map[mapKey];
6550
6608
  continue;
6551
6609
  }
6552
- const next = ((_a2 = map[mapKey]) != null ? _a2 : []).filter(
6610
+ const next = ((_a = map[mapKey]) != null ? _a : []).filter(
6553
6611
  (item) => !deleted.has(String(item))
6554
6612
  );
6555
6613
  if (next.length) map[mapKey] = next;
@@ -6559,10 +6617,10 @@ function cleanRelationMapsForDeleted(p, deleted) {
6559
6617
  }
6560
6618
  }
6561
6619
  function cleanOrderForTagsForDeleted(p, deleted) {
6562
- var _a2, _b;
6620
+ var _a, _b;
6563
6621
  const map = p.order_for_tags;
6564
6622
  if (!map) return;
6565
- const fieldIds = new Set(((_a2 = p.fields) != null ? _a2 : []).map((f) => String(f.id)));
6623
+ const fieldIds = new Set(((_a = p.fields) != null ? _a : []).map((f) => String(f.id)));
6566
6624
  for (const key of Object.keys(map)) {
6567
6625
  if (deleted.has(String(key))) {
6568
6626
  delete map[key];
@@ -6577,8 +6635,8 @@ function cleanOrderForTagsForDeleted(p, deleted) {
6577
6635
  if (!Object.keys(map).length) delete p.order_for_tags;
6578
6636
  }
6579
6637
  function cleanNoticesForDeleted(p, deleted) {
6580
- var _a2;
6581
- if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
6638
+ var _a;
6639
+ if (!((_a = p.notices) == null ? void 0 : _a.length)) return;
6582
6640
  p.notices = p.notices.filter((n) => {
6583
6641
  const target = n.target;
6584
6642
  if (!target || target.scope === "global") return true;
@@ -6597,18 +6655,18 @@ function applyDeleteCleanup(p, deleted) {
6597
6655
  cleanNoticesForDeleted(p, deleted);
6598
6656
  }
6599
6657
  function removeOptionInPlace(p, optionId) {
6600
- var _a2;
6658
+ var _a;
6601
6659
  const owner = ownerOfOption(p, optionId);
6602
6660
  if (!owner) return false;
6603
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
6661
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
6604
6662
  if (!(f == null ? void 0 : f.options)) return false;
6605
6663
  const before = f.options.length;
6606
6664
  f.options = f.options.filter((o) => o.id !== optionId);
6607
6665
  return f.options.length !== before;
6608
6666
  }
6609
6667
  function removeFieldInPlace(p, fieldId) {
6610
- var _a2, _b, _c, _d, _e;
6611
- const field = ((_a2 = p.fields) != null ? _a2 : []).find((f) => f.id === fieldId);
6668
+ var _a, _b, _c, _d, _e;
6669
+ const field = ((_a = p.fields) != null ? _a : []).find((f) => f.id === fieldId);
6612
6670
  if (!field) return [];
6613
6671
  const deleted = [fieldId, ...((_b = field.options) != null ? _b : []).map((o) => String(o.id))];
6614
6672
  const before = ((_c = p.fields) != null ? _c : []).length;
@@ -6617,8 +6675,8 @@ function removeFieldInPlace(p, fieldId) {
6617
6675
  return ((_e = p.fields) != null ? _e : []).length !== before ? deleted : [];
6618
6676
  }
6619
6677
  function removeTagInPlace(p, tagId) {
6620
- var _a2, _b, _c;
6621
- const before = ((_a2 = p.filters) != null ? _a2 : []).length;
6678
+ var _a, _b, _c;
6679
+ const before = ((_a = p.filters) != null ? _a : []).length;
6622
6680
  p.filters = ((_b = p.filters) != null ? _b : []).filter((t) => t.id !== tagId);
6623
6681
  return ((_c = p.filters) != null ? _c : []).length !== before;
6624
6682
  }
@@ -6627,9 +6685,9 @@ function reLabel(ctx, id, nextLabel) {
6627
6685
  ctx.exec({
6628
6686
  name: "reLabel",
6629
6687
  do: () => ctx.patchProps((p) => {
6630
- var _a2, _b, _c, _d, _e, _f, _g;
6688
+ var _a, _b, _c, _d, _e, _f, _g;
6631
6689
  if (ctx.isTagId(id)) {
6632
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6690
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6633
6691
  if (!t) return;
6634
6692
  if (((_b = t.label) != null ? _b : "") === label) return;
6635
6693
  t.label = label;
@@ -6662,8 +6720,8 @@ function setFieldName(ctx, fieldId, nextName) {
6662
6720
  ctx.exec({
6663
6721
  name: "setFieldName",
6664
6722
  do: () => ctx.patchProps((p) => {
6665
- var _a2;
6666
- const fields = (_a2 = p.fields) != null ? _a2 : [];
6723
+ var _a;
6724
+ const fields = (_a = p.fields) != null ? _a : [];
6667
6725
  const f = fields.find((x) => x.id === fieldId);
6668
6726
  if (!f) {
6669
6727
  ctx.api.emit("error", {
@@ -6695,8 +6753,8 @@ function setFieldName(ctx, fieldId, nextName) {
6695
6753
  }
6696
6754
  const collision = fields.find(
6697
6755
  (x) => {
6698
- var _a3;
6699
- return x.id !== fieldId && ((_a3 = x.name) != null ? _a3 : "") === name;
6756
+ var _a2;
6757
+ return x.id !== fieldId && ((_a2 = x.name) != null ? _a2 : "") === name;
6700
6758
  }
6701
6759
  );
6702
6760
  if (collision) {
@@ -6713,13 +6771,13 @@ function setFieldName(ctx, fieldId, nextName) {
6713
6771
  });
6714
6772
  }
6715
6773
  function addOption(ctx, fieldId, input) {
6716
- var _a2;
6717
- const id = (_a2 = input.id) != null ? _a2 : ctx.genId("o");
6774
+ var _a;
6775
+ const id = (_a = input.id) != null ? _a : ctx.genId("o");
6718
6776
  ctx.exec({
6719
6777
  name: "addOption",
6720
6778
  do: () => ctx.patchProps((p) => {
6721
- var _a3, _b;
6722
- const f = ((_a3 = p.fields) != null ? _a3 : []).find((x) => x.id === fieldId);
6779
+ var _a2, _b;
6780
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6723
6781
  if (!f) throw new Error(`addOption: field '${fieldId}' not found`);
6724
6782
  const list = (_b = f.options) != null ? _b : f.options = [];
6725
6783
  if (list.some((o) => o.id === id)) {
@@ -6738,10 +6796,10 @@ function updateOption(ctx, optionId, patch) {
6738
6796
  ctx.exec({
6739
6797
  name: "updateOption",
6740
6798
  do: () => ctx.patchProps((p) => {
6741
- var _a2;
6799
+ var _a;
6742
6800
  const owner = ownerOfOption(p, optionId);
6743
6801
  if (!owner) return;
6744
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
6802
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
6745
6803
  if (!(f == null ? void 0 : f.options)) return;
6746
6804
  const o = f.options.find((x) => x.id === optionId);
6747
6805
  if (o) Object.assign(o, patch);
@@ -6769,9 +6827,9 @@ function editLabel(ctx, id, label) {
6769
6827
  ctx.exec({
6770
6828
  name: "editLabel",
6771
6829
  do: () => ctx.patchProps((p) => {
6772
- var _a2, _b, _c, _d;
6830
+ var _a, _b, _c, _d;
6773
6831
  if (ctx.isTagId(id)) {
6774
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6832
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6775
6833
  if (t) t.label = next;
6776
6834
  return;
6777
6835
  }
@@ -6797,8 +6855,8 @@ function editName(ctx, fieldId, name) {
6797
6855
  ctx.exec({
6798
6856
  name: "editName",
6799
6857
  do: () => ctx.patchProps((p) => {
6800
- var _a2;
6801
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6858
+ var _a;
6859
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === fieldId);
6802
6860
  if (!f) return;
6803
6861
  f.name = name;
6804
6862
  }),
@@ -6809,7 +6867,7 @@ function setService(ctx, id, input) {
6809
6867
  ctx.exec({
6810
6868
  name: "setService",
6811
6869
  do: () => ctx.patchProps((p) => {
6812
- var _a2, _b, _c, _d, _e, _f;
6870
+ var _a, _b, _c, _d, _e, _f;
6813
6871
  const hasSidKey = Object.prototype.hasOwnProperty.call(
6814
6872
  input,
6815
6873
  "service_id"
@@ -6818,7 +6876,7 @@ function setService(ctx, id, input) {
6818
6876
  const sid = validId ? typeof input.service_id === "string" ? input.service_id.trim() : Number(input.service_id) : void 0;
6819
6877
  const nextRole = input.pricing_role;
6820
6878
  if (ctx.isTagId(id)) {
6821
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6879
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6822
6880
  if (!t) return;
6823
6881
  if (hasSidKey) {
6824
6882
  if (sid === void 0) delete t.service_id;
@@ -6907,18 +6965,18 @@ function setService(ctx, id, input) {
6907
6965
  });
6908
6966
  }
6909
6967
  function addTag(ctx, partial) {
6910
- var _a2;
6911
- const id = (_a2 = partial.id) != null ? _a2 : ctx.genId("t");
6968
+ var _a;
6969
+ const id = (_a = partial.id) != null ? _a : ctx.genId("t");
6912
6970
  const payload = { ...partial, id };
6913
6971
  ctx.exec({
6914
6972
  name: "addTag",
6915
6973
  do: () => ctx.patchProps((p) => {
6916
- var _a3;
6917
- p.filters = [...(_a3 = p.filters) != null ? _a3 : [], payload];
6974
+ var _a2;
6975
+ p.filters = [...(_a2 = p.filters) != null ? _a2 : [], payload];
6918
6976
  }),
6919
6977
  undo: () => ctx.patchProps((p) => {
6920
- var _a3;
6921
- p.filters = ((_a3 = p.filters) != null ? _a3 : []).filter((t) => t.id !== id);
6978
+ var _a2;
6979
+ p.filters = ((_a2 = p.filters) != null ? _a2 : []).filter((t) => t.id !== id);
6922
6980
  })
6923
6981
  });
6924
6982
  }
@@ -6927,16 +6985,16 @@ function updateTag(ctx, id, patch) {
6927
6985
  ctx.exec({
6928
6986
  name: "updateTag",
6929
6987
  do: () => ctx.patchProps((p) => {
6930
- var _a2;
6931
- p.filters = ((_a2 = p.filters) != null ? _a2 : []).map((t) => {
6988
+ var _a;
6989
+ p.filters = ((_a = p.filters) != null ? _a : []).map((t) => {
6932
6990
  if (t.id !== id) return t;
6933
6991
  prev = t;
6934
6992
  return { ...t, ...patch };
6935
6993
  });
6936
6994
  }),
6937
6995
  undo: () => ctx.patchProps((p) => {
6938
- var _a2;
6939
- p.filters = ((_a2 = p.filters) != null ? _a2 : []).map(
6996
+ var _a;
6997
+ p.filters = ((_a = p.filters) != null ? _a : []).map(
6940
6998
  (t) => t.id === id && prev ? prev : t
6941
6999
  );
6942
7000
  })
@@ -6956,20 +7014,21 @@ function removeTag(ctx, id) {
6956
7014
  });
6957
7015
  }
6958
7016
  function addField(ctx, partial) {
6959
- var _a2;
6960
- const id = (_a2 = partial.id) != null ? _a2 : ctx.genId("f");
7017
+ var _a;
7018
+ const id = (_a = partial.id) != null ? _a : ctx.genId("f");
6961
7019
  const payload = { ...partial, id };
6962
7020
  ctx.exec({
6963
7021
  name: "addField",
6964
7022
  do: () => ctx.patchProps((p) => {
6965
- var _a3;
6966
- p.fields = [...(_a3 = p.fields) != null ? _a3 : [], payload];
7023
+ var _a2;
7024
+ p.fields = [...(_a2 = p.fields) != null ? _a2 : [], payload];
6967
7025
  }),
6968
7026
  undo: () => ctx.patchProps((p) => {
6969
- var _a3;
6970
- p.fields = ((_a3 = p.fields) != null ? _a3 : []).filter((f) => f.id !== id);
7027
+ var _a2;
7028
+ p.fields = ((_a2 = p.fields) != null ? _a2 : []).filter((f) => f.id !== id);
6971
7029
  })
6972
7030
  });
7031
+ return id;
6973
7032
  }
6974
7033
  function updateField(ctx, id, patch) {
6975
7034
  let prev;
@@ -6978,8 +7037,8 @@ function updateField(ctx, id, patch) {
6978
7037
  ctx.exec({
6979
7038
  name: "updateField",
6980
7039
  do: () => ctx.patchProps((p) => {
6981
- var _a2, _b, _c, _d, _e, _f, _g;
6982
- prevIncludesForButton = ((_a2 = p.includes_for_buttons) == null ? void 0 : _a2[id]) ? [...(_c = (_b = p.includes_for_buttons) == null ? void 0 : _b[id]) != null ? _c : []] : void 0;
7040
+ var _a, _b, _c, _d, _e, _f, _g;
7041
+ prevIncludesForButton = ((_a = p.includes_for_buttons) == null ? void 0 : _a[id]) ? [...(_c = (_b = p.includes_for_buttons) == null ? void 0 : _b[id]) != null ? _c : []] : void 0;
6983
7042
  prevExcludesForButton = ((_d = p.excludes_for_buttons) == null ? void 0 : _d[id]) ? [...(_f = (_e = p.excludes_for_buttons) == null ? void 0 : _e[id]) != null ? _f : []] : void 0;
6984
7043
  p.fields = ((_g = p.fields) != null ? _g : []).map((f) => {
6985
7044
  if (f.id !== id) return f;
@@ -6992,8 +7051,8 @@ function updateField(ctx, id, patch) {
6992
7051
  });
6993
7052
  }),
6994
7053
  undo: () => ctx.patchProps((p) => {
6995
- var _a2, _b, _c;
6996
- p.fields = ((_a2 = p.fields) != null ? _a2 : []).map(
7054
+ var _a, _b, _c;
7055
+ p.fields = ((_a = p.fields) != null ? _a : []).map(
6997
7056
  (f) => f.id === id && prev ? prev : f
6998
7057
  );
6999
7058
  if (prevIncludesForButton) {
@@ -7071,13 +7130,13 @@ function removeMany(ctx, ids) {
7071
7130
  if (!ordered.length) return;
7072
7131
  ctx.transact("removeMany", () => {
7073
7132
  ctx.patchProps((p) => {
7074
- var _a2, _b, _c;
7075
- const existingFieldIds = new Set(((_a2 = p.fields) != null ? _a2 : []).map((f) => String(f.id)));
7133
+ var _a, _b, _c;
7134
+ const existingFieldIds = new Set(((_a = p.fields) != null ? _a : []).map((f) => String(f.id)));
7076
7135
  const existingTagIds = new Set(((_b = p.filters) != null ? _b : []).map((t) => String(t.id)));
7077
7136
  const existingOptionIds = new Set(
7078
7137
  ((_c = p.fields) != null ? _c : []).flatMap((f) => {
7079
- var _a3;
7080
- return ((_a3 = f.options) != null ? _a3 : []).map((o) => String(o.id));
7138
+ var _a2;
7139
+ return ((_a2 = f.options) != null ? _a2 : []).map((o) => String(o.id));
7081
7140
  })
7082
7141
  );
7083
7142
  const fieldIds = ordered.filter((id) => ctx.isFieldId(id) && existingFieldIds.has(id));
@@ -7106,10 +7165,10 @@ function removeMany(ctx, ids) {
7106
7165
  });
7107
7166
  }
7108
7167
  function getNode(ctx, id) {
7109
- var _a2, _b, _c, _d;
7168
+ var _a, _b, _c, _d;
7110
7169
  const props = ctx.getProps();
7111
7170
  if (ctx.isTagId(id)) {
7112
- const t = ((_a2 = props.filters) != null ? _a2 : []).find((x) => x.id === id);
7171
+ const t = ((_a = props.filters) != null ? _a : []).find((x) => x.id === id);
7113
7172
  return {
7114
7173
  kind: "tag",
7115
7174
  data: t,
@@ -7140,8 +7199,8 @@ function setConstraint(ctx, tagId, flag, value) {
7140
7199
  ctx.exec({
7141
7200
  name: "setConstraint",
7142
7201
  do: () => ctx.patchProps((p) => {
7143
- var _a2, _b;
7144
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7202
+ var _a, _b;
7203
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7145
7204
  if (!t) return;
7146
7205
  prev = (_b = t.constraints) == null ? void 0 : _b[flag];
7147
7206
  if (!t.constraints) t.constraints = {};
@@ -7149,8 +7208,8 @@ function setConstraint(ctx, tagId, flag, value) {
7149
7208
  else t.constraints[flag] = value;
7150
7209
  }),
7151
7210
  undo: () => ctx.patchProps((p) => {
7152
- var _a2;
7153
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7211
+ var _a;
7212
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7154
7213
  if (!t) return;
7155
7214
  if (!t.constraints) t.constraints = {};
7156
7215
  if (prev === void 0) delete t.constraints[flag];
@@ -7164,8 +7223,8 @@ function clearConstraintOverride(ctx, tagId, flag) {
7164
7223
  ctx.exec({
7165
7224
  name: "clearConstraintOverride",
7166
7225
  do: () => ctx.patchProps((p) => {
7167
- var _a2, _b, _c;
7168
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7226
+ var _a, _b, _c;
7227
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7169
7228
  if (!t) return;
7170
7229
  prev = (_b = t.constraints) == null ? void 0 : _b[flag];
7171
7230
  prevOverride = (_c = t.constraints_overrides) == null ? void 0 : _c[flag];
@@ -7173,8 +7232,8 @@ function clearConstraintOverride(ctx, tagId, flag) {
7173
7232
  if (t.constraints_overrides) delete t.constraints_overrides[flag];
7174
7233
  }),
7175
7234
  undo: () => ctx.patchProps((p) => {
7176
- var _a2;
7177
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7235
+ var _a;
7236
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7178
7237
  if (!t) return;
7179
7238
  if (prev !== void 0) {
7180
7239
  if (!t.constraints) t.constraints = {};
@@ -7191,8 +7250,8 @@ function clearConstraint(ctx, tagId, flag) {
7191
7250
  ctx.exec({
7192
7251
  name: "clearConstraint",
7193
7252
  do: () => ctx.patchProps((p) => {
7194
- var _a2;
7195
- const tags = (_a2 = p.filters) != null ? _a2 : [];
7253
+ var _a;
7254
+ const tags = (_a = p.filters) != null ? _a : [];
7196
7255
  const byId = new Map(tags.map((t) => [t.id, t]));
7197
7256
  const children = /* @__PURE__ */ new Map();
7198
7257
  for (const t of tags) {
@@ -7202,10 +7261,10 @@ function clearConstraint(ctx, tagId, flag) {
7202
7261
  }
7203
7262
  }
7204
7263
  const process = (id) => {
7205
- var _a3, _b, _c;
7264
+ var _a2, _b, _c;
7206
7265
  const t = byId.get(id);
7207
7266
  if (!t) return;
7208
- const override = (_a3 = t.constraints_overrides) == null ? void 0 : _a3[flag];
7267
+ const override = (_a2 = t.constraints_overrides) == null ? void 0 : _a2[flag];
7209
7268
  if (override) {
7210
7269
  if (!t.constraints) t.constraints = {};
7211
7270
  t.constraints[flag] = override.from;
@@ -7231,9 +7290,9 @@ function clearConstraint(ctx, tagId, flag) {
7231
7290
 
7232
7291
  // src/react/canvas/editor/editor-field-rules.ts
7233
7292
  function getFieldQuantityRule(ctx, id) {
7234
- var _a2, _b;
7293
+ var _a, _b;
7235
7294
  const props = ctx.getProps();
7236
- const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
7295
+ const f = ((_a = props.fields) != null ? _a : []).find((x) => x.id === id);
7237
7296
  if (!f) return void 0;
7238
7297
  return normalizeQuantityRule((_b = f.meta) == null ? void 0 : _b.quantity);
7239
7298
  }
@@ -7241,8 +7300,8 @@ function setFieldQuantityRule(ctx, id, rule) {
7241
7300
  ctx.exec({
7242
7301
  name: "setFieldQuantityRule",
7243
7302
  do: () => ctx.patchProps((p) => {
7244
- var _a2, _b;
7245
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7303
+ var _a, _b;
7304
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7246
7305
  if (!f) return;
7247
7306
  const normalized = normalizeQuantityRule(rule);
7248
7307
  if (!normalized) {
@@ -7266,8 +7325,8 @@ function clearFieldQuantityRule(ctx, id) {
7266
7325
  ctx.exec({
7267
7326
  name: "clearFieldQuantityRule",
7268
7327
  do: () => ctx.patchProps((p) => {
7269
- var _a2, _b;
7270
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7328
+ var _a, _b;
7329
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7271
7330
  if (!f || !((_b = f.meta) == null ? void 0 : _b.quantity)) return;
7272
7331
  delete f.meta.quantity;
7273
7332
  if (f.meta && Object.keys(f.meta).length === 0) {
@@ -7278,9 +7337,9 @@ function clearFieldQuantityRule(ctx, id) {
7278
7337
  });
7279
7338
  }
7280
7339
  function getFieldValidation(ctx, id) {
7281
- var _a2;
7340
+ var _a;
7282
7341
  const props = ctx.getProps();
7283
- const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
7342
+ const f = ((_a = props.fields) != null ? _a : []).find((x) => x.id === id);
7284
7343
  if (!f) return void 0;
7285
7344
  return normalizeFieldValidation(f.validation);
7286
7345
  }
@@ -7288,8 +7347,8 @@ function setFieldValidation(ctx, id, rules) {
7288
7347
  ctx.exec({
7289
7348
  name: "setFieldValidation",
7290
7349
  do: () => ctx.patchProps((p) => {
7291
- var _a2;
7292
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7350
+ var _a;
7351
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7293
7352
  if (!f) return;
7294
7353
  const normalized = normalizeFieldValidation(rules);
7295
7354
  if (!normalized) {
@@ -7305,8 +7364,8 @@ function clearFieldValidation(ctx, id) {
7305
7364
  ctx.exec({
7306
7365
  name: "clearFieldValidation",
7307
7366
  do: () => ctx.patchProps((p) => {
7308
- var _a2;
7309
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7367
+ var _a;
7368
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7310
7369
  if (!f || !f.validation) return;
7311
7370
  delete f.validation;
7312
7371
  }),
@@ -7425,9 +7484,9 @@ function pruneOrderKind(ctx, kind) {
7425
7484
 
7426
7485
  // src/react/canvas/editor/editor-relations.ts
7427
7486
  function wouldCreateTagCycle(_ctx, p, parentId, childId) {
7428
- var _a2, _b;
7487
+ var _a, _b;
7429
7488
  if (parentId === childId) return true;
7430
- const tagById = new Map(((_a2 = p.filters) != null ? _a2 : []).map((t) => [t.id, t]));
7489
+ const tagById = new Map(((_a = p.filters) != null ? _a : []).map((t) => [t.id, t]));
7431
7490
  let cur = parentId;
7432
7491
  const guard = /* @__PURE__ */ new Set();
7433
7492
  while (cur) {
@@ -7441,9 +7500,9 @@ function wouldCreateTagCycle(_ctx, p, parentId, childId) {
7441
7500
  function wouldCreateIncludeExcludeCycle(ctx, p, receiverId, targetId) {
7442
7501
  if (receiverId === targetId) return true;
7443
7502
  const getDirectRelations = (id) => {
7444
- var _a2, _b, _c, _d, _e, _f, _g;
7503
+ var _a, _b, _c, _d, _e, _f, _g;
7445
7504
  if (ctx.isTagId(id)) {
7446
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
7505
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
7447
7506
  return [...(_b = t == null ? void 0 : t.includes) != null ? _b : [], ...(_c = t == null ? void 0 : t.excludes) != null ? _c : []];
7448
7507
  }
7449
7508
  const inc = (_e = (_d = p.includes_for_buttons) == null ? void 0 : _d[id]) != null ? _e : [];
@@ -7465,12 +7524,12 @@ function include(ctx, receiverId, idOrIds) {
7465
7524
  ctx.exec({
7466
7525
  name: "include",
7467
7526
  do: () => ctx.patchProps((p) => {
7468
- var _a2, _b, _c, _d, _e, _f, _g;
7527
+ var _a, _b, _c, _d, _e, _f, _g;
7469
7528
  const receiver = ctx.getNode(receiverId);
7470
7529
  const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
7471
7530
  if (receiver.kind === "tag" || receiver.kind === "field" && isActualButtonField(receiver.data) || receiver.kind === "option") {
7472
7531
  if (receiver.kind === "tag") {
7473
- const t = ((_a2 = p.filters) != null ? _a2 : []).find(
7532
+ const t = ((_a = p.filters) != null ? _a : []).find(
7474
7533
  (x) => x.id === receiverId
7475
7534
  );
7476
7535
  if (t) {
@@ -7563,12 +7622,12 @@ function exclude(ctx, receiverId, idOrIds) {
7563
7622
  ctx.exec({
7564
7623
  name: "exclude",
7565
7624
  do: () => ctx.patchProps((p) => {
7566
- var _a2, _b, _c, _d, _e, _f, _g;
7625
+ var _a, _b, _c, _d, _e, _f, _g;
7567
7626
  const receiver = ctx.getNode(receiverId);
7568
7627
  const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
7569
7628
  if (receiver.kind === "tag" || receiver.kind === "field" && isActualButtonField(receiver.data) || receiver.kind === "option") {
7570
7629
  if (receiver.kind === "tag") {
7571
- const t = ((_a2 = p.filters) != null ? _a2 : []).find(
7630
+ const t = ((_a = p.filters) != null ? _a : []).find(
7572
7631
  (x) => x.id === receiverId
7573
7632
  );
7574
7633
  if (t) {
@@ -7661,7 +7720,7 @@ function connect(ctx, kind, fromId, toId2) {
7661
7720
  ctx.exec({
7662
7721
  name: `connect:${kind}`,
7663
7722
  do: () => ctx.patchProps((p) => {
7664
- var _a2, _b, _c, _d, _e, _f, _g, _h;
7723
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7665
7724
  if (kind === "bind") {
7666
7725
  if (ctx.isTagId(fromId) && ctx.isTagId(toId2)) {
7667
7726
  if (wouldCreateTagCycle(ctx, p, fromId, toId2)) {
@@ -7669,7 +7728,7 @@ function connect(ctx, kind, fromId, toId2) {
7669
7728
  `bind would create a cycle: ${fromId} ? ${toId2}`
7670
7729
  );
7671
7730
  }
7672
- const child = ((_a2 = p.filters) != null ? _a2 : []).find(
7731
+ const child = ((_a = p.filters) != null ? _a : []).find(
7673
7732
  (t) => t.id === toId2
7674
7733
  );
7675
7734
  if (child) child.bind_id = fromId;
@@ -7763,10 +7822,10 @@ function disconnect(ctx, kind, fromId, toId2) {
7763
7822
  ctx.exec({
7764
7823
  name: `disconnect:${kind}`,
7765
7824
  do: () => ctx.patchProps((p) => {
7766
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
7825
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
7767
7826
  if (kind === "bind") {
7768
7827
  if (ctx.isTagId(fromId) && ctx.isTagId(toId2)) {
7769
- const child = ((_a2 = p.filters) != null ? _a2 : []).find(
7828
+ const child = ((_a = p.filters) != null ? _a : []).find(
7770
7829
  (t) => t.id === toId2
7771
7830
  );
7772
7831
  if ((child == null ? void 0 : child.bind_id) === fromId) {
@@ -7858,8 +7917,8 @@ function disconnect(ctx, kind, fromId, toId2) {
7858
7917
  });
7859
7918
  }
7860
7919
  function addMappedField(p, mapKey, fromId, toId2) {
7861
- var _a2, _b;
7862
- const maps = (_a2 = p[mapKey]) != null ? _a2 : {};
7920
+ var _a, _b;
7921
+ const maps = (_a = p[mapKey]) != null ? _a : {};
7863
7922
  const arr = (_b = maps[fromId]) != null ? _b : [];
7864
7923
  if (!arr.includes(toId2)) {
7865
7924
  maps[fromId] = [...arr, toId2];
@@ -7896,15 +7955,15 @@ function placeNode(ctx, id, opts) {
7896
7955
  ctx.exec({
7897
7956
  name: "placeTag",
7898
7957
  do: () => ctx.patchProps((p) => {
7899
- var _a2, _b, _c;
7900
- const all = (_a2 = p.filters) != null ? _a2 : [];
7958
+ var _a, _b, _c;
7959
+ const all = (_a = p.filters) != null ? _a : [];
7901
7960
  const cur = all.find((t) => t.id === id);
7902
7961
  if (!cur) return;
7903
7962
  const groupKey = (_b = cur.bind_id) != null ? _b : "__root__";
7904
7963
  const siblings = all.filter(
7905
7964
  (t) => {
7906
- var _a3;
7907
- return ((_a3 = t.bind_id) != null ? _a3 : "__root__") === groupKey;
7965
+ var _a2;
7966
+ return ((_a2 = t.bind_id) != null ? _a2 : "__root__") === groupKey;
7908
7967
  }
7909
7968
  );
7910
7969
  const curIdx = siblings.findIndex((t) => t.id === id);
@@ -7949,8 +8008,8 @@ function placeNode(ctx, id, opts) {
7949
8008
  ctx.exec({
7950
8009
  name: "placeField",
7951
8010
  do: () => ctx.patchProps((p) => {
7952
- var _a2, _b;
7953
- const map = (_a2 = p.order_for_tags) != null ? _a2 : p.order_for_tags = {};
8011
+ var _a, _b;
8012
+ const map = (_a = p.order_for_tags) != null ? _a : p.order_for_tags = {};
7954
8013
  const arr = (_b = map[tagId]) != null ? _b : map[tagId] = [];
7955
8014
  const curIdx = arr.indexOf(fieldId);
7956
8015
  if (curIdx >= 0) arr.splice(curIdx, 1);
@@ -7979,10 +8038,10 @@ function placeOption(ctx, optionId, opts) {
7979
8038
  ctx.exec({
7980
8039
  name: "placeOption",
7981
8040
  do: () => ctx.patchProps((p) => {
7982
- var _a2;
8041
+ var _a;
7983
8042
  const owner = ownerOfOption(p, optionId);
7984
8043
  if (!owner) return;
7985
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
8044
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
7986
8045
  if (!(f == null ? void 0 : f.options)) return;
7987
8046
  const curIdx = f.options.findIndex((o) => o.id === optionId);
7988
8047
  if (curIdx < 0) return;
@@ -8040,8 +8099,8 @@ function ensureCatalog(catalog) {
8040
8099
  return clone(catalog != null ? catalog : createEmptyCatalog());
8041
8100
  }
8042
8101
  function createCatalogId(catalog, prefix = "cg") {
8043
- var _a2;
8044
- const taken = new Set(((_a2 = catalog == null ? void 0 : catalog.nodes) != null ? _a2 : []).map((x) => x.id));
8102
+ var _a;
8103
+ const taken = new Set(((_a = catalog == null ? void 0 : catalog.nodes) != null ? _a : []).map((x) => x.id));
8045
8104
  for (let i = 1; i < 1e4; i++) {
8046
8105
  const id = `${prefix}:${i}`;
8047
8106
  if (!taken.has(id)) return id;
@@ -8049,9 +8108,9 @@ function createCatalogId(catalog, prefix = "cg") {
8049
8108
  throw new Error("Unable to generate catalog id");
8050
8109
  }
8051
8110
  function addCatalogGroup(catalog, input) {
8052
- var _a2;
8111
+ var _a;
8053
8112
  const next = ensureCatalog(catalog);
8054
- const id = (_a2 = input.id) != null ? _a2 : createCatalogId(next, "cg");
8113
+ const id = (_a = input.id) != null ? _a : createCatalogId(next, "cg");
8055
8114
  next.nodes.push({
8056
8115
  id,
8057
8116
  kind: "group",
@@ -8068,9 +8127,9 @@ function addCatalogGroup(catalog, input) {
8068
8127
  return next;
8069
8128
  }
8070
8129
  function addSmartCatalogGroup(catalog, input) {
8071
- var _a2, _b, _c;
8130
+ var _a, _b, _c;
8072
8131
  const next = ensureCatalog(catalog);
8073
- const id = (_a2 = input.id) != null ? _a2 : createCatalogId(next, "csg");
8132
+ const id = (_a = input.id) != null ? _a : createCatalogId(next, "csg");
8074
8133
  next.nodes.push({
8075
8134
  id,
8076
8135
  kind: "smart-group",
@@ -8088,7 +8147,7 @@ function addSmartCatalogGroup(catalog, input) {
8088
8147
  return next;
8089
8148
  }
8090
8149
  function updateCatalogNode(catalog, id, patch) {
8091
- var _a2;
8150
+ var _a;
8092
8151
  if (!catalog) return catalog;
8093
8152
  const next = ensureCatalog(catalog);
8094
8153
  const idx = next.nodes.findIndex((x) => x.id === id);
@@ -8098,7 +8157,7 @@ function updateCatalogNode(catalog, id, patch) {
8098
8157
  ...current,
8099
8158
  ...patch
8100
8159
  };
8101
- if (((_a2 = next.nodes[idx]) == null ? void 0 : _a2.kind) === "group") {
8160
+ if (((_a = next.nodes[idx]) == null ? void 0 : _a.kind) === "group") {
8102
8161
  next.nodes[idx] = {
8103
8162
  ...next.nodes[idx],
8104
8163
  serviceIds: normalizeServiceIds(
@@ -8124,27 +8183,27 @@ function setSelectedCatalogService(catalog, serviceId) {
8124
8183
  return next;
8125
8184
  }
8126
8185
  function toggleCatalogExpanded(catalog, id) {
8127
- var _a2;
8186
+ var _a;
8128
8187
  const next = ensureCatalog(catalog);
8129
- const expanded = new Set((_a2 = next.expandedIds) != null ? _a2 : []);
8188
+ const expanded = new Set((_a = next.expandedIds) != null ? _a : []);
8130
8189
  if (expanded.has(id)) expanded.delete(id);
8131
8190
  else expanded.add(id);
8132
8191
  next.expandedIds = Array.from(expanded);
8133
8192
  return next;
8134
8193
  }
8135
8194
  function setCatalogExpanded(catalog, id, expanded) {
8136
- var _a2;
8195
+ var _a;
8137
8196
  const next = ensureCatalog(catalog);
8138
- const set = new Set((_a2 = next.expandedIds) != null ? _a2 : []);
8197
+ const set = new Set((_a = next.expandedIds) != null ? _a : []);
8139
8198
  if (expanded) set.add(id);
8140
8199
  else set.delete(id);
8141
8200
  next.expandedIds = Array.from(set);
8142
8201
  return next;
8143
8202
  }
8144
8203
  function toggleCatalogPinned(catalog, id) {
8145
- var _a2;
8204
+ var _a;
8146
8205
  const next = ensureCatalog(catalog);
8147
- const pinned = new Set((_a2 = next.pinnedNodeIds) != null ? _a2 : []);
8206
+ const pinned = new Set((_a = next.pinnedNodeIds) != null ? _a : []);
8148
8207
  if (pinned.has(id)) pinned.delete(id);
8149
8208
  else pinned.add(id);
8150
8209
  next.pinnedNodeIds = Array.from(pinned);
@@ -8173,7 +8232,7 @@ function assignServicesToCatalogGroup(catalog, nodeId, serviceIds, mode = "appen
8173
8232
  return next;
8174
8233
  }
8175
8234
  function removeCatalogNode(catalog, id, opts) {
8176
- var _a2, _b;
8235
+ var _a, _b;
8177
8236
  if (!catalog) return catalog;
8178
8237
  const next = ensureCatalog(catalog);
8179
8238
  const ids = /* @__PURE__ */ new Set([id]);
@@ -8195,7 +8254,7 @@ function removeCatalogNode(catalog, id, opts) {
8195
8254
  if (next.activeNodeId && ids.has(next.activeNodeId)) {
8196
8255
  next.activeNodeId = void 0;
8197
8256
  }
8198
- next.expandedIds = ((_a2 = next.expandedIds) != null ? _a2 : []).filter((x) => !ids.has(x));
8257
+ next.expandedIds = ((_a = next.expandedIds) != null ? _a : []).filter((x) => !ids.has(x));
8199
8258
  next.pinnedNodeIds = ((_b = next.pinnedNodeIds) != null ? _b : []).filter((x) => !ids.has(x));
8200
8259
  return next;
8201
8260
  }
@@ -8206,8 +8265,8 @@ function moveCatalogNode(catalog, nodeId, opts) {
8206
8265
  if (!node) return next;
8207
8266
  node.parentId = opts.parentId;
8208
8267
  const siblings = next.nodes.filter((x) => x.parentId === opts.parentId && x.id !== nodeId).sort((a, b) => {
8209
- var _a2, _b;
8210
- return ((_a2 = a.order) != null ? _a2 : 0) - ((_b = b.order) != null ? _b : 0);
8268
+ var _a, _b;
8269
+ return ((_a = a.order) != null ? _a : 0) - ((_b = b.order) != null ? _b : 0);
8211
8270
  });
8212
8271
  let dest = typeof opts.index === "number" ? opts.index : siblings.length;
8213
8272
  if (opts.beforeId) {
@@ -8226,20 +8285,20 @@ function moveCatalogNode(catalog, nodeId, opts) {
8226
8285
  return next;
8227
8286
  }
8228
8287
  function resolveSmartCatalogGroup(catalog, nodeId, candidates, matchers) {
8229
- var _a2, _b;
8288
+ var _a, _b;
8230
8289
  if (!catalog) return catalog;
8231
8290
  const next = ensureCatalog(catalog);
8232
8291
  const node = next.nodes.find(
8233
8292
  (x) => x.id === nodeId && x.kind === "smart-group"
8234
8293
  );
8235
8294
  if (!node) return next;
8236
- const rules = (_a2 = node.rules) != null ? _a2 : [];
8295
+ const rules = (_a = node.rules) != null ? _a : [];
8237
8296
  const mode = (_b = node.match) != null ? _b : "all";
8238
8297
  const resolved = candidates.filter((candidate) => {
8239
8298
  const results = rules.map((rule) => {
8240
- var _a3, _b2, _c, _d, _e, _f;
8299
+ var _a2, _b2, _c, _d, _e, _f;
8241
8300
  if (rule.type === "service-field") {
8242
- return (_b2 = (_a3 = matchers.serviceField) == null ? void 0 : _a3.call(matchers, candidate, rule)) != null ? _b2 : false;
8301
+ return (_b2 = (_a2 = matchers.serviceField) == null ? void 0 : _a2.call(matchers, candidate, rule)) != null ? _b2 : false;
8243
8302
  }
8244
8303
  if (rule.type === "policy-family") {
8245
8304
  return (_d = (_c = matchers.policyFamily) == null ? void 0 : _c.call(matchers, candidate, rule)) != null ? _d : false;
@@ -8260,14 +8319,14 @@ var Editor = class {
8260
8319
  this.history = [];
8261
8320
  this.index = -1;
8262
8321
  this.txnDepth = 0;
8263
- var _a2, _b;
8322
+ var _a, _b;
8264
8323
  this.builder = builder;
8265
8324
  this.api = api;
8266
8325
  this.opts = {
8267
8326
  ...opts,
8268
8327
  historyLimit: Math.max(
8269
8328
  1,
8270
- Math.min((_a2 = opts.historyLimit) != null ? _a2 : MAX_LIMIT, 1e3)
8329
+ Math.min((_a = opts.historyLimit) != null ? _a : MAX_LIMIT, 1e3)
8271
8330
  ),
8272
8331
  validateAfterEach: (_b = opts.validateAfterEach) != null ? _b : false
8273
8332
  };
@@ -8310,14 +8369,14 @@ var Editor = class {
8310
8369
  }
8311
8370
  }
8312
8371
  exec(cmd) {
8313
- var _a2;
8372
+ var _a;
8314
8373
  try {
8315
8374
  const before = this.makeSnapshot(cmd.name + ":before");
8316
8375
  cmd.do();
8317
8376
  this.afterMutation(cmd.name, before);
8318
8377
  } catch (err) {
8319
8378
  this.emit("editor:error", {
8320
- message: (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err),
8379
+ message: (_a = err == null ? void 0 : err.message) != null ? _a : String(err),
8321
8380
  code: "command"
8322
8381
  });
8323
8382
  throw err;
@@ -8406,6 +8465,36 @@ var Editor = class {
8406
8465
  addField(partial) {
8407
8466
  return addField(this.moduleCtx(), partial);
8408
8467
  }
8468
+ addFieldFromDescriptor(registry, partial, opts) {
8469
+ var _a, _b, _c, _d, _e;
8470
+ const variant = (_b = opts == null ? void 0 : opts.variant) != null ? _b : typeof ((_a = partial == null ? void 0 : partial.meta) == null ? void 0 : _a.variant) === "string" ? partial.meta.variant : void 0;
8471
+ const descriptor = resolveInputDescriptor(
8472
+ registry,
8473
+ String(partial.type),
8474
+ variant
8475
+ );
8476
+ const nextMeta = {
8477
+ ...(_c = partial.meta) != null ? _c : {}
8478
+ };
8479
+ if (((_d = descriptor == null ? void 0 : descriptor.multi) == null ? void 0 : _d.autoEnable) === true) {
8480
+ nextMeta.multi = true;
8481
+ }
8482
+ const fieldInput = {
8483
+ ...partial,
8484
+ ...Object.keys(nextMeta).length ? { meta: nextMeta } : {}
8485
+ };
8486
+ const fieldId = this.addField(fieldInput);
8487
+ if (((_e = descriptor == null ? void 0 : descriptor.options) == null ? void 0 : _e.autoCreate) === true) {
8488
+ this.autoCreateOptionsMany([fieldId], () => {
8489
+ var _a2, _b2, _c2, _d2;
8490
+ return {
8491
+ label: (_b2 = (_a2 = descriptor.options) == null ? void 0 : _a2.defaultLabel) != null ? _b2 : "Option label",
8492
+ value: (_d2 = (_c2 = descriptor.options) == null ? void 0 : _c2.defaultValue) != null ? _d2 : "option"
8493
+ };
8494
+ });
8495
+ }
8496
+ return fieldId;
8497
+ }
8409
8498
  updateField(id, patch) {
8410
8499
  return updateField(this.moduleCtx(), id, patch);
8411
8500
  }
@@ -8423,10 +8512,10 @@ var Editor = class {
8423
8512
  if (!ordered.length) return;
8424
8513
  this.transact("clearServiceMany", () => {
8425
8514
  this.patchProps((p) => {
8426
- var _a2, _b, _c, _d;
8515
+ var _a, _b, _c, _d;
8427
8516
  for (const id of ordered) {
8428
8517
  if (this.isTagId(id)) {
8429
- const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
8518
+ const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
8430
8519
  if (t && "service_id" in t) delete t.service_id;
8431
8520
  continue;
8432
8521
  }
@@ -8451,8 +8540,8 @@ var Editor = class {
8451
8540
  if (!ordered.length) return;
8452
8541
  this.transact("rebindMany", () => {
8453
8542
  this.patchProps((p) => {
8454
- var _a2, _b, _c;
8455
- const targetExists = ((_a2 = p.filters) != null ? _a2 : []).some((t) => t.id === targetTagId);
8543
+ var _a, _b, _c;
8544
+ const targetExists = ((_a = p.filters) != null ? _a : []).some((t) => t.id === targetTagId);
8456
8545
  if (!targetExists) return;
8457
8546
  for (const id of ordered) {
8458
8547
  if (this.isFieldId(id)) {
@@ -8488,10 +8577,10 @@ var Editor = class {
8488
8577
  if (!selected.size) return;
8489
8578
  this.transact("clearRelationsMany", () => {
8490
8579
  this.patchProps((p) => {
8491
- var _a2, _b, _c;
8580
+ var _a, _b, _c;
8492
8581
  const clearOwned = mode === "owned" || mode === "both";
8493
8582
  const clearIncoming = mode === "incoming" || mode === "both";
8494
- for (const t of (_a2 = p.filters) != null ? _a2 : []) {
8583
+ for (const t of (_a = p.filters) != null ? _a : []) {
8495
8584
  if (clearOwned && selected.has(t.id)) {
8496
8585
  delete t.includes;
8497
8586
  delete t.excludes;
@@ -8532,17 +8621,17 @@ var Editor = class {
8532
8621
  });
8533
8622
  }
8534
8623
  renameLabelsMany(ids, input) {
8535
- var _a2, _b;
8624
+ var _a, _b;
8536
8625
  const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8537
8626
  if (!ordered.length) return;
8538
- const prefix = (_a2 = input.prefix) != null ? _a2 : "";
8627
+ const prefix = (_a = input.prefix) != null ? _a : "";
8539
8628
  const suffix = (_b = input.suffix) != null ? _b : "";
8540
8629
  this.transact("renameLabelsMany", () => {
8541
8630
  this.patchProps((p) => {
8542
- var _a3, _b2, _c, _d, _e, _f, _g;
8631
+ var _a2, _b2, _c, _d, _e, _f, _g;
8543
8632
  for (const id of ordered) {
8544
8633
  if (this.isTagId(id)) {
8545
- const t = ((_a3 = p.filters) != null ? _a3 : []).find((x) => x.id === id);
8634
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
8546
8635
  if (t) t.label = `${prefix}${(_b2 = t.label) != null ? _b2 : ""}${suffix}`.trim();
8547
8636
  continue;
8548
8637
  }
@@ -8578,10 +8667,10 @@ var Editor = class {
8578
8667
  if (!ordered.length) return;
8579
8668
  this.transact("clearFieldDefaultsMany", () => {
8580
8669
  this.patchProps((p) => {
8581
- var _a2;
8670
+ var _a;
8582
8671
  for (const id of ordered) {
8583
8672
  if (!this.isFieldId(id)) continue;
8584
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8673
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
8585
8674
  if (f && "defaults" in f) delete f.defaults;
8586
8675
  }
8587
8676
  });
@@ -8592,24 +8681,46 @@ var Editor = class {
8592
8681
  if (!ordered.length) return;
8593
8682
  this.transact("clearFieldValidationMany", () => {
8594
8683
  this.patchProps((p) => {
8595
- var _a2;
8684
+ var _a;
8596
8685
  for (const id of ordered) {
8597
8686
  if (!this.isFieldId(id)) continue;
8598
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8687
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
8599
8688
  if (f && "validation" in f) delete f.validation;
8600
8689
  }
8601
8690
  });
8602
8691
  });
8603
8692
  }
8693
+ setFieldMulti(fieldId, enabled) {
8694
+ const flag = enabled === true;
8695
+ this.transact("setFieldMulti", () => {
8696
+ this.patchProps((p) => {
8697
+ var _a, _b;
8698
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === fieldId);
8699
+ if (!f) return;
8700
+ const currentMeta = (_b = f.meta) != null ? _b : {};
8701
+ const nextMeta = { ...currentMeta };
8702
+ if (flag) {
8703
+ nextMeta.multi = true;
8704
+ } else {
8705
+ delete nextMeta.multi;
8706
+ }
8707
+ if (Object.keys(nextMeta).length === 0) {
8708
+ delete f.meta;
8709
+ } else {
8710
+ f.meta = nextMeta;
8711
+ }
8712
+ });
8713
+ });
8714
+ }
8604
8715
  autoCreateOptionsMany(ids, makeOption) {
8605
8716
  const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8606
8717
  if (!ordered.length) return;
8607
8718
  this.transact("autoCreateOptionsMany", () => {
8608
8719
  this.patchProps((p) => {
8609
- var _a2, _b, _c, _d;
8720
+ var _a, _b, _c, _d;
8610
8721
  for (const id of ordered) {
8611
8722
  if (!this.isFieldId(id)) continue;
8612
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8723
+ const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
8613
8724
  if (!f) continue;
8614
8725
  const opts = (_b = f.options) != null ? _b : f.options = [];
8615
8726
  if (opts.length > 0) continue;
@@ -8624,14 +8735,14 @@ var Editor = class {
8624
8735
  });
8625
8736
  }
8626
8737
  clearAllOptionsMany(ids) {
8627
- var _a2, _b;
8738
+ var _a, _b;
8628
8739
  const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8629
8740
  if (!ordered.length) return;
8630
8741
  const optionIds = [];
8631
8742
  const props = this.getProps();
8632
8743
  for (const id of ordered) {
8633
8744
  if (!this.isFieldId(id)) continue;
8634
- const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
8745
+ const f = ((_a = props.fields) != null ? _a : []).find((x) => x.id === id);
8635
8746
  for (const o of (_b = f == null ? void 0 : f.options) != null ? _b : []) optionIds.push(o.id);
8636
8747
  }
8637
8748
  if (!optionIds.length) return;
@@ -8642,8 +8753,8 @@ var Editor = class {
8642
8753
  if (!selected.size) return;
8643
8754
  this.transact("removeNoticesForNodes", () => {
8644
8755
  this.patchProps((p) => {
8645
- var _a2;
8646
- if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
8756
+ var _a;
8757
+ if (!((_a = p.notices) == null ? void 0 : _a.length)) return;
8647
8758
  p.notices = p.notices.filter((n) => {
8648
8759
  const target = n.target;
8649
8760
  if (!target || target.scope === "global") return true;
@@ -8659,8 +8770,8 @@ var Editor = class {
8659
8770
  if (!selected.size) return;
8660
8771
  this.transact("setNoticesVisibilityForNodes", () => {
8661
8772
  this.patchProps((p) => {
8662
- var _a2;
8663
- for (const n of (_a2 = p.notices) != null ? _a2 : []) {
8773
+ var _a;
8774
+ for (const n of (_a = p.notices) != null ? _a : []) {
8664
8775
  const target = n.target;
8665
8776
  if ((target == null ? void 0 : target.scope) === "node" && selected.has(String(target.node_id))) {
8666
8777
  n.type = type;
@@ -8821,7 +8932,7 @@ var Editor = class {
8821
8932
  );
8822
8933
  }
8823
8934
  resolveSmartCatalogGroup(nodeId, candidates, matchers) {
8824
- var _a2, _b;
8935
+ var _a, _b;
8825
8936
  const next = resolveSmartCatalogGroup(
8826
8937
  this.catalog,
8827
8938
  nodeId,
@@ -8832,7 +8943,7 @@ var Editor = class {
8832
8943
  const node = next == null ? void 0 : next.nodes.find(
8833
8944
  (x) => x.id === nodeId && x.kind === "smart-group"
8834
8945
  );
8835
- return (_b = (_a2 = node == null ? void 0 : node.resolvedServiceIds) == null ? void 0 : _a2.slice()) != null ? _b : [];
8946
+ return (_b = (_a = node == null ? void 0 : node.resolvedServiceIds) == null ? void 0 : _a.slice()) != null ? _b : [];
8836
8947
  }
8837
8948
  replaceCatalog(next, reason = "catalog:set") {
8838
8949
  this.catalog = cloneDeep4(next);
@@ -9033,9 +9144,9 @@ var Selection = class {
9033
9144
  }
9034
9145
  // ── Main: visible group snapshot (env-aware) ─────────────────────────────
9035
9146
  visibleGroup() {
9036
- var _a2;
9147
+ var _a;
9037
9148
  const props = this.builder.getProps();
9038
- if (((_a2 = this.opts.env) != null ? _a2 : "client") === "workspace") {
9149
+ if (((_a = this.opts.env) != null ? _a : "client") === "workspace") {
9039
9150
  const tagIds = Array.from(this.set).filter(
9040
9151
  this.builder.isTagId.bind(this.builder)
9041
9152
  );
@@ -9066,12 +9177,12 @@ var Selection = class {
9066
9177
  * - de-dupes per field
9067
9178
  */
9068
9179
  buttonSelectionsByFieldId() {
9069
- var _a2, _b, _c, _d, _e;
9180
+ var _a, _b, _c, _d, _e;
9070
9181
  const nodeMap = this.builder.getNodeMap();
9071
9182
  const out = {};
9072
9183
  const push = (fieldId, triggerKey) => {
9073
- var _a3;
9074
- const arr = (_a3 = out[fieldId]) != null ? _a3 : out[fieldId] = [];
9184
+ var _a2;
9185
+ const arr = (_a2 = out[fieldId]) != null ? _a2 : out[fieldId] = [];
9075
9186
  if (!arr.includes(triggerKey)) arr.push(triggerKey);
9076
9187
  };
9077
9188
  for (const key of this.set) {
@@ -9088,7 +9199,7 @@ var Selection = class {
9088
9199
  const ref = nodeMap.get(key);
9089
9200
  if (!ref) continue;
9090
9201
  if (ref.kind === "option" && typeof ref.fieldId === "string") {
9091
- push(ref.fieldId, (_a2 = ref.id) != null ? _a2 : key);
9202
+ push(ref.fieldId, (_a = ref.id) != null ? _a : key);
9092
9203
  continue;
9093
9204
  }
9094
9205
  if (ref.kind === "field") {
@@ -9109,7 +9220,7 @@ var Selection = class {
9109
9220
  * Excludes tags and non-button fields.
9110
9221
  */
9111
9222
  selectedButtons() {
9112
- var _a2, _b;
9223
+ var _a, _b;
9113
9224
  const nodeMap = this.builder.getNodeMap();
9114
9225
  const out = [];
9115
9226
  const seen = /* @__PURE__ */ new Set();
@@ -9135,7 +9246,7 @@ var Selection = class {
9135
9246
  continue;
9136
9247
  }
9137
9248
  if (ref.kind === "field") {
9138
- const field = (_b = (_a2 = ref.node) != null ? _a2 : ref.field) != null ? _b : ref;
9249
+ const field = (_b = (_a = ref.node) != null ? _a : ref.field) != null ? _b : ref;
9139
9250
  if ((field == null ? void 0 : field.button) === true) push(key);
9140
9251
  }
9141
9252
  }
@@ -9150,9 +9261,9 @@ var Selection = class {
9150
9261
  for (const fn of this.onChangeFns) fn(payload);
9151
9262
  }
9152
9263
  updateCurrentTagFrom(id) {
9153
- var _a2, _b;
9264
+ var _a, _b;
9154
9265
  const props = this.builder.getProps();
9155
- const tags = (_a2 = props.filters) != null ? _a2 : [];
9266
+ const tags = (_a = props.filters) != null ? _a : [];
9156
9267
  const fields = (_b = props.fields) != null ? _b : [];
9157
9268
  if (tags.some((t) => t.id === id)) {
9158
9269
  this.currentTagId = id;
@@ -9168,8 +9279,8 @@ var Selection = class {
9168
9279
  if (this.builder.isOptionId(id)) {
9169
9280
  return fields.find(
9170
9281
  (x) => {
9171
- var _a3;
9172
- return ((_a3 = x.options) != null ? _a3 : []).some((o) => o.id === id);
9282
+ var _a2;
9283
+ return ((_a2 = x.options) != null ? _a2 : []).some((o) => o.id === id);
9173
9284
  }
9174
9285
  );
9175
9286
  }
@@ -9196,10 +9307,10 @@ var Selection = class {
9196
9307
  if (fallbackTagId) this.currentTagId = fallbackTagId;
9197
9308
  }
9198
9309
  resolveTagContextId(props) {
9199
- var _a2;
9310
+ var _a;
9200
9311
  if (this.currentTagId) return this.currentTagId;
9201
9312
  for (const id of this.set) if (this.builder.isTagId(id)) return id;
9202
- const fields = (_a2 = props.fields) != null ? _a2 : [];
9313
+ const fields = (_a = props.fields) != null ? _a : [];
9203
9314
  for (const id of this.set) {
9204
9315
  const f = fields.find((x) => x.id === id);
9205
9316
  if (f == null ? void 0 : f.bind_id)
@@ -9209,8 +9320,8 @@ var Selection = class {
9209
9320
  if (this.builder.isOptionId(id)) {
9210
9321
  const host = fields.find(
9211
9322
  (x) => {
9212
- var _a3;
9213
- return ((_a3 = x.options) != null ? _a3 : []).some((o) => o.id === id);
9323
+ var _a2;
9324
+ return ((_a2 = x.options) != null ? _a2 : []).some((o) => o.id === id);
9214
9325
  }
9215
9326
  );
9216
9327
  if (host == null ? void 0 : host.bind_id)
@@ -9226,8 +9337,8 @@ var Selection = class {
9226
9337
  return this.opts.rootTagId;
9227
9338
  }
9228
9339
  computeGroupForTag(props, tagId) {
9229
- var _a2, _b, _c, _d, _e, _f, _g;
9230
- const tags = (_a2 = props.filters) != null ? _a2 : [];
9340
+ var _a, _b, _c, _d, _e, _f, _g;
9341
+ const tags = (_a = props.filters) != null ? _a : [];
9231
9342
  const fields = (_b = props.fields) != null ? _b : [];
9232
9343
  const tagById = new Map(tags.map((t) => [t.id, t]));
9233
9344
  const tag = tagById.get(tagId);
@@ -9311,10 +9422,10 @@ var Selection = class {
9311
9422
  return baseOverridden;
9312
9423
  }
9313
9424
  findOptionById(fields, selId) {
9314
- var _a2, _b;
9425
+ var _a, _b;
9315
9426
  if (this.builder.isOptionId(selId)) {
9316
9427
  for (const f of fields) {
9317
- const o = (_a2 = f.options) == null ? void 0 : _a2.find((x) => x.id === selId);
9428
+ const o = (_a = f.options) == null ? void 0 : _a.find((x) => x.id === selId);
9318
9429
  if (o) return o;
9319
9430
  }
9320
9431
  }
@@ -9339,9 +9450,9 @@ var CanvasAPI = class {
9339
9450
  /* ─── Option-node visibility (per field) ───────────────────────────────── */
9340
9451
  /** Internal mirror of which fields should show their options as nodes. */
9341
9452
  this.shownOptionFields = /* @__PURE__ */ new Set();
9342
- var _a2, _b, _c;
9453
+ var _a, _b, _c;
9343
9454
  this.builder = builder;
9344
- this.autoEmit = (_a2 = opts.autoEmitState) != null ? _a2 : true;
9455
+ this.autoEmit = (_a = opts.autoEmitState) != null ? _a : true;
9345
9456
  this.selection = new Selection(builder, {
9346
9457
  env: "workspace",
9347
9458
  rootTagId: "t:root"
@@ -9568,14 +9679,14 @@ function useOptionalFormApi() {
9568
9679
  }
9569
9680
  function FormProvider({ children, schema, initial }) {
9570
9681
  const [bag, setBag] = React.useState(() => {
9571
- var _a2;
9682
+ var _a;
9572
9683
  return {
9573
- ...(_a2 = initial == null ? void 0 : initial.values) != null ? _a2 : {}
9684
+ ...(_a = initial == null ? void 0 : initial.values) != null ? _a : {}
9574
9685
  };
9575
9686
  });
9576
9687
  const [selectionsBag, setSelectionsBag] = React.useState(() => {
9577
- var _a2;
9578
- return { ...(_a2 = initial == null ? void 0 : initial.selections) != null ? _a2 : {} };
9688
+ var _a;
9689
+ return { ...(_a = initial == null ? void 0 : initial.selections) != null ? _a : {} };
9579
9690
  });
9580
9691
  const listenersRef = React.useRef(/* @__PURE__ */ new Set());
9581
9692
  const publish = React.useCallback(() => {
@@ -9601,9 +9712,9 @@ function FormProvider({ children, schema, initial }) {
9601
9712
  return () => listenersRef.current.delete(fn);
9602
9713
  },
9603
9714
  get(fieldId) {
9604
- var _a2, _b;
9715
+ var _a, _b;
9605
9716
  const core = coreRef.current;
9606
- const live = (_b = (_a2 = core == null ? void 0 : core.values) == null ? void 0 : _a2.call(core)) != null ? _b : void 0;
9717
+ const live = (_b = (_a = core == null ? void 0 : core.values) == null ? void 0 : _a.call(core)) != null ? _b : void 0;
9607
9718
  if (live && fieldId in live) return live[fieldId];
9608
9719
  return bag[fieldId];
9609
9720
  },
@@ -9618,8 +9729,8 @@ function FormProvider({ children, schema, initial }) {
9618
9729
  },
9619
9730
  // Legacy selections API (compat; no longer used by the new Wrapper)
9620
9731
  getSelections(fieldId) {
9621
- var _a2;
9622
- return (_a2 = selectionsBag[fieldId]) != null ? _a2 : [];
9732
+ var _a;
9733
+ return (_a = selectionsBag[fieldId]) != null ? _a : [];
9623
9734
  },
9624
9735
  setSelections(fieldId, optionIds) {
9625
9736
  setSelectionsBag((prev) => ({
@@ -9630,8 +9741,8 @@ function FormProvider({ children, schema, initial }) {
9630
9741
  },
9631
9742
  toggleSelection(fieldId, optionId) {
9632
9743
  setSelectionsBag((prev) => {
9633
- var _a2;
9634
- const current = new Set((_a2 = prev[fieldId]) != null ? _a2 : []);
9744
+ var _a;
9745
+ const current = new Set((_a = prev[fieldId]) != null ? _a : []);
9635
9746
  if (current.has(optionId)) current.delete(optionId);
9636
9747
  else current.add(optionId);
9637
9748
  return { ...prev, [fieldId]: Array.from(current) };
@@ -9642,17 +9753,17 @@ function FormProvider({ children, schema, initial }) {
9642
9753
  const [fieldId, optionId] = String(token).split(":", 2);
9643
9754
  if (!fieldId || !optionId) return;
9644
9755
  setSelectionsBag((prev) => {
9645
- var _a2;
9646
- const current = new Set((_a2 = prev[fieldId]) != null ? _a2 : []);
9756
+ var _a;
9757
+ const current = new Set((_a = prev[fieldId]) != null ? _a : []);
9647
9758
  current.delete(optionId);
9648
9759
  return { ...prev, [fieldId]: Array.from(current) };
9649
9760
  });
9650
9761
  publish();
9651
9762
  },
9652
9763
  snapshot() {
9653
- var _a2, _b;
9764
+ var _a, _b;
9654
9765
  const core = coreRef.current;
9655
- const live = (_b = (_a2 = core == null ? void 0 : core.values) == null ? void 0 : _a2.call(core)) != null ? _b : {};
9766
+ const live = (_b = (_a = core == null ? void 0 : core.values) == null ? void 0 : _a.call(core)) != null ? _b : {};
9656
9767
  return live;
9657
9768
  },
9658
9769
  submit() {
@@ -9688,40 +9799,6 @@ function FormProvider({ children, schema, initial }) {
9688
9799
  ) });
9689
9800
  }
9690
9801
 
9691
- // src/react/inputs/registry.ts
9692
- function createInputRegistry() {
9693
- const store = /* @__PURE__ */ new Map();
9694
- const get = (kind, variant) => {
9695
- var _a2;
9696
- const vm = store.get(kind);
9697
- if (!vm) return void 0;
9698
- const v = variant != null ? variant : "default";
9699
- return (_a2 = vm.get(v)) != null ? _a2 : vm.get("default");
9700
- };
9701
- const register = (kind, descriptor, variant) => {
9702
- let vm = store.get(kind);
9703
- if (!vm) {
9704
- vm = /* @__PURE__ */ new Map();
9705
- store.set(kind, vm);
9706
- }
9707
- vm.set(variant != null ? variant : "default", descriptor);
9708
- };
9709
- const unregister = (kind, variant) => {
9710
- const vm = store.get(kind);
9711
- if (!vm) return;
9712
- const key = variant != null ? variant : "default";
9713
- vm.delete(key);
9714
- if (vm.size === 0) store.delete(kind);
9715
- };
9716
- const registerMany = (entries) => {
9717
- for (const e of entries) register(e.kind, e.descriptor, e.variant);
9718
- };
9719
- return { get, register, unregister, registerMany, _store: store };
9720
- }
9721
- function resolveInputDescriptor(registry, kind, variant) {
9722
- return registry.get(kind, variant);
9723
- }
9724
-
9725
9802
  // src/react/inputs/provider.tsx
9726
9803
  import { createContext as createContext2, useContext as useContext2, useMemo as useMemo2 } from "react";
9727
9804
  import { jsx as jsx2 } from "react/jsx-runtime";
@@ -9791,9 +9868,9 @@ function findDefaultTagId(tags) {
9791
9868
  return hasRoot ? ROOT_TAG_ID : tags[0].id;
9792
9869
  }
9793
9870
  function mapSnapshotFormToFieldIds(builder, snap) {
9794
- var _a2, _b, _c, _d, _e;
9871
+ var _a, _b, _c, _d, _e;
9795
9872
  const byFieldId = {};
9796
- const form = (_b = (_a2 = snap.inputs) == null ? void 0 : _a2.form) != null ? _b : {};
9873
+ const form = (_b = (_a = snap.inputs) == null ? void 0 : _a.form) != null ? _b : {};
9797
9874
  const fields = (_c = builder.getProps().fields) != null ? _c : [];
9798
9875
  const nameToIds = /* @__PURE__ */ new Map();
9799
9876
  for (const f of fields) {
@@ -9819,8 +9896,8 @@ function makeDefaultFallback(mode, patch) {
9819
9896
  };
9820
9897
  }
9821
9898
  function normalizeInit(init) {
9822
- var _a2, _b, _c;
9823
- const mode = (_a2 = init.mode) != null ? _a2 : "prod";
9899
+ var _a, _b, _c;
9900
+ const mode = (_a = init.mode) != null ? _a : "prod";
9824
9901
  const hostDefaultQuantity = Number.isFinite((_b = init.hostDefaultQuantity) != null ? _b : 1) ? Number((_c = init.hostDefaultQuantity) != null ? _c : 1) : 1;
9825
9902
  return { ...init, mode, hostDefaultQuantity };
9826
9903
  }
@@ -9862,8 +9939,8 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
9862
9939
  const bump = () => force((x) => x + 1);
9863
9940
  const resolveBuilder = useCallback2(
9864
9941
  (p) => {
9865
- var _a2, _b;
9866
- if ((_a2 = p.flow) == null ? void 0 : _a2.builder) return p.flow.builder;
9942
+ var _a, _b;
9943
+ if ((_a = p.flow) == null ? void 0 : _a.builder) return p.flow.builder;
9867
9944
  if (p.builder) return p.builder;
9868
9945
  if (p.serviceProps) {
9869
9946
  const b = createBuilder((_b = p.builderOptions) != null ? _b : {});
@@ -9899,8 +9976,8 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
9899
9976
  }, []);
9900
9977
  const resolveSelection = useCallback2(
9901
9978
  (b, nInit, p) => {
9902
- var _a2, _b, _c;
9903
- return (_c = (_b = (_a2 = p.flow) == null ? void 0 : _a2.selection) != null ? _b : p.selection) != null ? _c : new Selection(b, {
9979
+ var _a, _b, _c;
9980
+ return (_c = (_b = (_a = p.flow) == null ? void 0 : _a.selection) != null ? _b : p.selection) != null ? _c : new Selection(b, {
9904
9981
  env: "client",
9905
9982
  rootTagId: ROOT_TAG_ID,
9906
9983
  resolveService: nInit.resolveService
@@ -9930,7 +10007,7 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
9930
10007
  }, []);
9931
10008
  const initialize = useCallback2(
9932
10009
  (params) => {
9933
- var _a2, _b, _c, _d, _e, _f;
10010
+ var _a, _b, _c, _d, _e, _f;
9934
10011
  const b = resolveBuilder(params);
9935
10012
  if (!b) {
9936
10013
  throw new Error(
@@ -9950,7 +10027,7 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
9950
10027
  unsubRef.current = sel.onChange(
9951
10028
  () => setActiveTagId(sel.currentTag())
9952
10029
  );
9953
- const tags = (_a2 = b.getProps().filters) != null ? _a2 : [];
10030
+ const tags = (_a = b.getProps().filters) != null ? _a : [];
9954
10031
  const hydratedTag = (_c = (_b = nInit.hydrateFrom) == null ? void 0 : _b.selection) == null ? void 0 : _c.tag;
9955
10032
  const initialTag = nInit.hydrateFrom ? hydratedTag : (_d = nInit.initialTagId) != null ? _d : findDefaultTagId(tags);
9956
10033
  if (initialTag) sel.replace(initialTag);
@@ -10003,14 +10080,14 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10003
10080
  serviceProps
10004
10081
  ]);
10005
10082
  useEffect2(() => {
10006
- var _a2, _b, _c, _d, _e;
10083
+ var _a, _b, _c, _d, _e;
10007
10084
  if (!serviceProps) return;
10008
10085
  if (!ready()) return;
10009
10086
  const currentBuilder = builderRef.current;
10010
10087
  if (!currentBuilder || currentBuilder !== resolvedBuilder) return;
10011
10088
  if (!sameServiceProps(currentBuilder.getProps(), serviceProps)) {
10012
10089
  currentBuilder.load(serviceProps);
10013
- const currentTag = (_a2 = selectionRef.current) == null ? void 0 : _a2.currentTag();
10090
+ const currentTag = (_a = selectionRef.current) == null ? void 0 : _a.currentTag();
10014
10091
  if (selectionRef.current && currentTag && !currentBuilder.isTagId(currentTag)) {
10015
10092
  const nextTag = (_e = findDefaultTagId((_b = currentBuilder.getProps().filters) != null ? _b : [])) != null ? _e : (_d = (_c = currentBuilder.getProps().filters) == null ? void 0 : _c[0]) == null ? void 0 : _d.id;
10016
10093
  if (nextTag) selectionRef.current.replace(nextTag);
@@ -10032,12 +10109,12 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10032
10109
  [ensureReady]
10033
10110
  );
10034
10111
  const clearAllFields = useCallback2(() => {
10035
- var _a2;
10112
+ var _a;
10036
10113
  const api = formApiRef.current;
10037
10114
  if (!api) return;
10038
10115
  const b = builderRef.current;
10039
10116
  if (!b) return;
10040
- const fields = (_a2 = b.getProps().fields) != null ? _a2 : [];
10117
+ const fields = (_a = b.getProps().fields) != null ? _a : [];
10041
10118
  for (const f of fields) {
10042
10119
  api.set(f.id, void 0);
10043
10120
  api.setSelections(f.id, []);
@@ -10045,11 +10122,11 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10045
10122
  }, []);
10046
10123
  const setSnapshot = useCallback2(
10047
10124
  (snap, opts) => {
10048
- var _a2, _b, _c, _d;
10125
+ var _a, _b, _c, _d;
10049
10126
  const api = formApiRef.current;
10050
10127
  if (!api) return;
10051
10128
  const { builder, selection } = ensureReady("setSnapshot");
10052
- const clearFirst = (_a2 = opts == null ? void 0 : opts.clearFirst) != null ? _a2 : true;
10129
+ const clearFirst = (_a = opts == null ? void 0 : opts.clearFirst) != null ? _a : true;
10053
10130
  const tag = (_b = snap.selection) == null ? void 0 : _b.tag;
10054
10131
  if (tag) selection.replace(tag);
10055
10132
  if (clearFirst) clearAllFields();
@@ -10064,8 +10141,8 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10064
10141
  );
10065
10142
  const reset = useCallback2(
10066
10143
  (opts) => {
10067
- var _a2, _b, _c, _d;
10068
- const keepTag = (_a2 = opts == null ? void 0 : opts.keepTag) != null ? _a2 : false;
10144
+ var _a, _b, _c, _d;
10145
+ const keepTag = (_a = opts == null ? void 0 : opts.keepTag) != null ? _a : false;
10069
10146
  const { builder, selection } = ensureReady("reset");
10070
10147
  if (!keepTag) {
10071
10148
  const tags = (_b = builder.getProps().filters) != null ? _b : [];
@@ -10095,10 +10172,10 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10095
10172
  return mapSnapshotFormToFieldIds(b, i.hydrateFrom);
10096
10173
  }, [force]);
10097
10174
  const initialSelections = useMemo3(() => {
10098
- var _a2, _b;
10175
+ var _a, _b;
10099
10176
  const i = initRef.current;
10100
10177
  if (!(i == null ? void 0 : i.hydrateFrom)) return {};
10101
- return (_b = (_a2 = i.hydrateFrom.inputs) == null ? void 0 : _a2.selections) != null ? _b : {};
10178
+ return (_b = (_a = i.hydrateFrom.inputs) == null ? void 0 : _a.selections) != null ? _b : {};
10102
10179
  }, [force]);
10103
10180
  useImperativeHandle(
10104
10181
  ref,
@@ -10113,8 +10190,8 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10113
10190
  setSnapshot,
10114
10191
  reset,
10115
10192
  refresh: () => {
10116
- var _a2;
10117
- return setActiveTagId((_a2 = selectionRef.current) == null ? void 0 : _a2.currentTag());
10193
+ var _a;
10194
+ return setActiveTagId((_a = selectionRef.current) == null ? void 0 : _a.currentTag());
10118
10195
  }
10119
10196
  }),
10120
10197
  [
@@ -10163,8 +10240,8 @@ var OrderFlowProvider = forwardRef(function OrderFlowProvider2({
10163
10240
 
10164
10241
  // src/react/hooks/evalute-field-validation.ts
10165
10242
  function evaluateFieldValidationRule(rule, raw) {
10166
- var _a2, _b;
10167
- const valueBy = (_a2 = rule.valueBy) != null ? _a2 : "value";
10243
+ var _a, _b;
10244
+ const valueBy = (_a = rule.valueBy) != null ? _a : "value";
10168
10245
  let subject = raw;
10169
10246
  if (valueBy === "length") {
10170
10247
  if (typeof raw === "string" || Array.isArray(raw)) subject = raw.length;
@@ -10209,11 +10286,11 @@ function evaluateFieldValidationRule(rule, raw) {
10209
10286
  }
10210
10287
  }
10211
10288
  function validateVisibleFields(visibleFieldIds, fieldById, formValuesByFieldId) {
10212
- var _a2;
10289
+ var _a;
10213
10290
  const out = [];
10214
10291
  for (const fid of visibleFieldIds) {
10215
10292
  const field = fieldById.get(fid);
10216
- if (!((_a2 = field == null ? void 0 : field.validation) == null ? void 0 : _a2.length)) continue;
10293
+ if (!((_a = field == null ? void 0 : field.validation) == null ? void 0 : _a.length)) continue;
10217
10294
  const value = formValuesByFieldId[fid];
10218
10295
  for (const rule of field.validation) {
10219
10296
  const ok = evaluateFieldValidationRule(rule, value);
@@ -10233,7 +10310,7 @@ function validateVisibleFields(visibleFieldIds, fieldById, formValuesByFieldId)
10233
10310
  // src/react/hooks/use-order-flow.ts
10234
10311
  var ROOT_TAG_ID2 = "t:root";
10235
10312
  function useOrderFlow() {
10236
- var _a2, _b, _c;
10313
+ var _a, _b, _c;
10237
10314
  const ctx = useOrderFlowContext();
10238
10315
  const ready = ctx.ready();
10239
10316
  const initialize = useCallback3(
@@ -10259,22 +10336,22 @@ function useOrderFlow() {
10259
10336
  return ctx.formApi.subscribe(() => setFormTick((x) => x + 1));
10260
10337
  }, [ctx.formApi]);
10261
10338
  const visibleGroup = useMemo4(() => {
10262
- var _a3;
10339
+ var _a2;
10263
10340
  if (!ready) return null;
10264
10341
  const sel = ctx.selection;
10265
10342
  if (!sel) return null;
10266
10343
  const vg = sel.visibleGroup();
10267
10344
  if (vg.kind !== "single") return null;
10268
- return (_a3 = vg.group) != null ? _a3 : null;
10345
+ return (_a2 = vg.group) != null ? _a2 : null;
10269
10346
  }, [ready, ctx.selection, selTick]);
10270
10347
  const activeTagId = useMemo4(() => {
10271
- var _a3, _b2, _c2;
10348
+ var _a2, _b2, _c2;
10272
10349
  if (!ready) return void 0;
10273
- return (_c2 = (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.currentTag) == null ? void 0 : _b2.call(_a3)) != null ? _c2 : ctx.activeTagId;
10350
+ return (_c2 = (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.currentTag) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : ctx.activeTagId;
10274
10351
  }, [ready, ctx.selection, ctx.activeTagId, selTick]);
10275
10352
  const formValuesByFieldId = useMemo4(() => {
10276
- var _a3, _b2, _c2;
10277
- const values = (_c2 = (_b2 = (_a3 = ctx.formApi).snapshot) == null ? void 0 : _b2.call(_a3)) != null ? _c2 : {};
10353
+ var _a2, _b2, _c2;
10354
+ const values = (_c2 = (_b2 = (_a2 = ctx.formApi).snapshot) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : {};
10278
10355
  return values;
10279
10356
  }, [ctx.formApi, formTick]);
10280
10357
  const optionSelectionsByFieldId = useMemo4(
@@ -10282,7 +10359,7 @@ function useOrderFlow() {
10282
10359
  []
10283
10360
  );
10284
10361
  const previewSnapshot = useMemo4(() => {
10285
- var _a3, _b2, _c2;
10362
+ var _a2, _b2, _c2;
10286
10363
  if (!ready) {
10287
10364
  return {
10288
10365
  version: "1",
@@ -10297,7 +10374,7 @@ function useOrderFlow() {
10297
10374
  max: 1,
10298
10375
  serviceMap: {},
10299
10376
  meta: {
10300
- schema_version: (_a3 = propsRef.current) == null ? void 0 : _a3.schema_version,
10377
+ schema_version: (_a2 = propsRef.current) == null ? void 0 : _a2.schema_version,
10301
10378
  context: {
10302
10379
  tag: "unknown",
10303
10380
  constraints: {},
@@ -10339,7 +10416,7 @@ function useOrderFlow() {
10339
10416
  selTick
10340
10417
  ]);
10341
10418
  const pricingPreview = useMemo4(() => {
10342
- var _a3, _b2, _c2, _d, _e, _f;
10419
+ var _a2, _b2, _c2, _d, _e, _f;
10343
10420
  const empty = {
10344
10421
  unitRate: 0,
10345
10422
  base: 0,
@@ -10349,7 +10426,7 @@ function useOrderFlow() {
10349
10426
  };
10350
10427
  if (!ready) return empty;
10351
10428
  const { init } = ctx.ensureReady("pricingPreview");
10352
- const normalizeRate = (_a3 = init.normalizeRate) != null ? _a3 : ((s) => Number(s == null ? void 0 : s.rate));
10429
+ const normalizeRate = (_a2 = init.normalizeRate) != null ? _a2 : ((s) => Number(s == null ? void 0 : s.rate));
10353
10430
  const quantity = Number((_b2 = previewSnapshot.quantity) != null ? _b2 : 1) || 1;
10354
10431
  let bestId;
10355
10432
  let bestRate = 0;
@@ -10407,18 +10484,80 @@ function useOrderFlow() {
10407
10484
  }, [ready, ctx, previewSnapshot]);
10408
10485
  const selectTag = useCallback3(
10409
10486
  (tagId) => {
10410
- var _a3, _b2;
10487
+ var _a2, _b2;
10411
10488
  ctx.ensureReady("selectTag");
10412
- (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.replace) == null ? void 0 : _b2.call(_a3, tagId);
10489
+ (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.replace) == null ? void 0 : _b2.call(_a2, tagId);
10413
10490
  ctx.setActiveTag(tagId);
10414
10491
  },
10415
10492
  [ctx]
10416
10493
  );
10417
10494
  const toggleOption = useCallback3(
10418
10495
  (fieldId, optionId) => {
10419
- var _a3, _b2;
10496
+ var _a2, _b2;
10420
10497
  const token = optionId != null ? optionId : fieldId;
10421
- (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.toggle) == null ? void 0 : _b2.call(_a3, token);
10498
+ (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.toggle) == null ? void 0 : _b2.call(_a2, token);
10499
+ },
10500
+ [ctx]
10501
+ );
10502
+ const setFieldOptions = useCallback3(
10503
+ (fieldId, optionIds) => {
10504
+ var _a2, _b2, _c2, _d;
10505
+ const { builder, selection, init } = ctx.ensureReady(
10506
+ "setFieldOptions"
10507
+ );
10508
+ const fields = (_a2 = builder.getProps().fields) != null ? _a2 : [];
10509
+ const field = fields.find((f) => f.id === fieldId);
10510
+ if (!field) return;
10511
+ const validOptionIds = new Set(
10512
+ ((_b2 = field.options) != null ? _b2 : []).map((option) => String(option.id))
10513
+ );
10514
+ const dedupedValid = [];
10515
+ const seen = /* @__PURE__ */ new Set();
10516
+ for (const rawOptionId of optionIds != null ? optionIds : []) {
10517
+ const optionId = String(rawOptionId);
10518
+ if (!validOptionIds.has(optionId)) continue;
10519
+ if (seen.has(optionId)) continue;
10520
+ seen.add(optionId);
10521
+ dedupedValid.push(optionId);
10522
+ }
10523
+ const mode = (_c2 = init.mode) != null ? _c2 : "prod";
10524
+ const isMulti = ((_d = field.meta) == null ? void 0 : _d.multi) === true;
10525
+ const normalized = mode === "prod" && !isMulti ? dedupedValid.length ? [dedupedValid[dedupedValid.length - 1]] : [] : dedupedValid;
10526
+ const fieldById = new Map(fields.map((f) => [f.id, f]));
10527
+ const nodeMap = builder.getNodeMap();
10528
+ const resolveOptionOwnerFieldId = (token) => {
10529
+ var _a3;
10530
+ if (!token) return void 0;
10531
+ if (token.includes("::")) {
10532
+ const [legacyFieldId, optionId] = token.split("::", 2);
10533
+ if (!optionId) return void 0;
10534
+ const optionRef2 = nodeMap.get(optionId);
10535
+ if ((optionRef2 == null ? void 0 : optionRef2.kind) === "option" && typeof optionRef2.fieldId === "string") {
10536
+ return optionRef2.fieldId;
10537
+ }
10538
+ if (legacyFieldId && fieldById.has(legacyFieldId)) {
10539
+ return legacyFieldId;
10540
+ }
10541
+ return void 0;
10542
+ }
10543
+ const optionRef = nodeMap.get(token);
10544
+ if ((optionRef == null ? void 0 : optionRef.kind) === "option" && typeof optionRef.fieldId === "string") {
10545
+ return optionRef.fieldId;
10546
+ }
10547
+ for (const f of fields) {
10548
+ if ((_a3 = f.options) == null ? void 0 : _a3.some((option) => option.id === token)) {
10549
+ return f.id;
10550
+ }
10551
+ }
10552
+ return void 0;
10553
+ };
10554
+ const retained = Array.from(selection.all()).filter(
10555
+ (token) => resolveOptionOwnerFieldId(token) !== fieldId
10556
+ );
10557
+ for (const optionId of normalized) {
10558
+ if (!retained.includes(optionId)) retained.push(optionId);
10559
+ }
10560
+ selection.many(retained, retained[retained.length - 1]);
10422
10561
  },
10423
10562
  [ctx]
10424
10563
  );
@@ -10430,9 +10569,9 @@ function useOrderFlow() {
10430
10569
  );
10431
10570
  const clearField = useCallback3(
10432
10571
  (fieldId) => {
10433
- var _a3, _b2;
10572
+ var _a2, _b2;
10434
10573
  ctx.formApi.set(fieldId, void 0);
10435
- (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.remove) == null ? void 0 : _b2.call(_a3, fieldId);
10574
+ (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2, fieldId);
10436
10575
  },
10437
10576
  [ctx]
10438
10577
  );
@@ -10451,14 +10590,14 @@ function useOrderFlow() {
10451
10590
  [ctx]
10452
10591
  );
10453
10592
  const buildSnapshot = useCallback3(() => {
10454
- var _a3, _b2, _c2, _d, _e, _f;
10593
+ var _a2, _b2, _c2, _d, _e, _f;
10455
10594
  const { builder, selection, init } = ctx.ensureReady("buildSnapshot");
10456
10595
  const tagId = selection.currentTag();
10457
10596
  const selectedKeys = selection.selectedButtons();
10458
10597
  if (!tagId) {
10459
10598
  throw new Error("OrderFlow: no active tag/context selected");
10460
10599
  }
10461
- const mode = (_a3 = init.mode) != null ? _a3 : "prod";
10600
+ const mode = (_a2 = init.mode) != null ? _a2 : "prod";
10462
10601
  const hostDefaultQuantity = Number((_b2 = init.hostDefaultQuantity) != null ? _b2 : 1) || 1;
10463
10602
  const submitted = ctx.formApi.submit();
10464
10603
  const values = submitted.values;
@@ -10499,13 +10638,13 @@ function useOrderFlow() {
10499
10638
  );
10500
10639
  }, [ctx, optionSelectionsByFieldId]);
10501
10640
  const raw = useMemo4(() => {
10502
- var _a3;
10503
- if (!ready) return (_a3 = propsRef.current) != null ? _a3 : {};
10641
+ var _a2;
10642
+ if (!ready) return (_a2 = propsRef.current) != null ? _a2 : {};
10504
10643
  return ctx.ensureReady("raw").builder.getProps();
10505
10644
  }, [ctx, ready, selTick]);
10506
10645
  const notices = useMemo4(() => {
10507
- var _a3;
10508
- return (_a3 = raw.notices) != null ? _a3 : [];
10646
+ var _a2;
10647
+ return (_a2 = raw.notices) != null ? _a2 : [];
10509
10648
  }, [raw]);
10510
10649
  return {
10511
10650
  ready,
@@ -10520,10 +10659,11 @@ function useOrderFlow() {
10520
10659
  services: previewSnapshot.services,
10521
10660
  serviceMap: previewSnapshot.serviceMap,
10522
10661
  pricingPreview,
10523
- min: (_a2 = previewSnapshot.min) != null ? _a2 : 1,
10662
+ min: (_a = previewSnapshot.min) != null ? _a : 1,
10524
10663
  max: (_c = (_b = previewSnapshot.max) != null ? _b : previewSnapshot.min) != null ? _c : 1,
10525
10664
  selectTag,
10526
10665
  toggleOption,
10666
+ setFieldOptions,
10527
10667
  setValue,
10528
10668
  clearField,
10529
10669
  reset,
@@ -10540,8 +10680,8 @@ function toKind(field) {
10540
10680
  return field.type;
10541
10681
  }
10542
10682
  function toVariant(field) {
10543
- var _a2;
10544
- const v = (_a2 = field.meta) == null ? void 0 : _a2.variant;
10683
+ var _a;
10684
+ const v = (_a = field.meta) == null ? void 0 : _a.variant;
10545
10685
  return typeof v === "string" && v.trim() ? v : void 0;
10546
10686
  }
10547
10687
  function getPath(ctx, path) {
@@ -10614,7 +10754,7 @@ function Wrapper({
10614
10754
  ctxOverrides,
10615
10755
  className = ""
10616
10756
  }) {
10617
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
10757
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
10618
10758
  const { registry } = useInputs();
10619
10759
  const flow = useOrderFlow();
10620
10760
  const kind = toKind(field);
@@ -10628,11 +10768,11 @@ function Wrapper({
10628
10768
  return null;
10629
10769
  }
10630
10770
  const Component = descriptor.Component;
10631
- const adapter = (_a2 = descriptor.adapter) != null ? _a2 : {};
10771
+ const adapter = (_a = descriptor.adapter) != null ? _a : {};
10632
10772
  const baseProps = (_b = descriptor.defaultProps) != null ? _b : {};
10633
10773
  const defaultProps = useMemo6(() => {
10634
- var _a3;
10635
- return { ...baseProps, ...(_a3 = field.defaults) != null ? _a3 : {} };
10774
+ var _a2;
10775
+ return { ...baseProps, ...(_a2 = field.defaults) != null ? _a2 : {} };
10636
10776
  }, [baseProps, field.defaults]);
10637
10777
  const valueProp = (_c = adapter.valueProp) != null ? _c : "value";
10638
10778
  const changeProp = (_d = adapter.changeProp) != null ? _d : "onChange";
@@ -10647,23 +10787,19 @@ function Wrapper({
10647
10787
  disabled: !!disabled
10648
10788
  });
10649
10789
  const optionIds = React4.useMemo(() => {
10650
- var _a3;
10790
+ var _a2;
10651
10791
  if (!isOptionBased2) return /* @__PURE__ */ new Set();
10652
- return new Set(((_a3 = field.options) != null ? _a3 : []).map((o) => o.id));
10792
+ return new Set(((_a2 = field.options) != null ? _a2 : []).map((o) => o.id));
10653
10793
  }, [isOptionBased2, field.options]);
10654
- const prevSelectedRef = React4.useRef([]);
10655
- React4.useEffect(() => {
10656
- prevSelectedRef.current = [];
10657
- }, [field.id]);
10658
10794
  const adapterCtx = React4.useMemo(
10659
10795
  () => ({ field, props: flow.raw }),
10660
10796
  [field, flow.raw]
10661
10797
  );
10662
10798
  const onHostChange = React4.useCallback(
10663
10799
  (next) => {
10664
- var _a3, _b2, _c2, _d2, _e2;
10800
+ var _a2, _b2, _c2, _d2, _e2;
10665
10801
  const currentStored = next == null ? void 0 : next.value;
10666
- const stored = (_c2 = (_b2 = (_a3 = adapter.getValue) == null ? void 0 : _a3.call(adapter, next, currentStored, adapterCtx)) != null ? _b2 : currentStored) != null ? _c2 : next;
10802
+ const stored = (_c2 = (_b2 = (_a2 = adapter.getValue) == null ? void 0 : _a2.call(adapter, next, currentStored, adapterCtx)) != null ? _b2 : currentStored) != null ? _c2 : next;
10667
10803
  fp.setValue(stored);
10668
10804
  if (isOptionBased2) {
10669
10805
  if (!adapter.getSelectedOptions) {
@@ -10681,16 +10817,7 @@ function Wrapper({
10681
10817
  (rawIds != null ? rawIds : []).map(String).filter((id) => optionIds.has(id))
10682
10818
  )
10683
10819
  );
10684
- const prev = prevSelectedRef.current;
10685
- prevSelectedRef.current = nextIds;
10686
- const prevSet = new Set(prev);
10687
- const nextSet = new Set(nextIds);
10688
- for (const id of nextIds) {
10689
- if (!prevSet.has(id)) flow.toggleOption(field.id, id);
10690
- }
10691
- for (const id of prev) {
10692
- if (!nextSet.has(id)) flow.toggleOption(field.id, id);
10693
- }
10820
+ flow.setFieldOptions(field.id, nextIds);
10694
10821
  return;
10695
10822
  }
10696
10823
  if (isActionButton) {
@@ -10712,8 +10839,8 @@ function Wrapper({
10712
10839
  ]
10713
10840
  );
10714
10841
  const templateCtx = React4.useMemo(() => {
10715
- var _a3, _b2;
10716
- const ctxFromInit = (_b2 = (_a3 = flow.init) == null ? void 0 : _a3.ctx) != null ? _b2 : {};
10842
+ var _a2, _b2;
10843
+ const ctxFromInit = (_b2 = (_a2 = flow.init) == null ? void 0 : _a2.ctx) != null ? _b2 : {};
10717
10844
  const ctx = ctxOverrides && typeof ctxOverrides === "object" ? { ...ctxFromInit, ...ctxOverrides } : ctxFromInit;
10718
10845
  return {
10719
10846
  ...ctx,
@@ -11221,6 +11348,9 @@ var toggleGroupDescriptor = {
11221
11348
  defaultLabel: "Option label",
11222
11349
  defaultValue: "option"
11223
11350
  },
11351
+ multi: {
11352
+ supported: true
11353
+ },
11224
11354
  defaultProps: {
11225
11355
  variant: "toggle-group",
11226
11356
  // MUST
@@ -11744,6 +11874,10 @@ var treeSelectDescriptor = {
11744
11874
  defaultLabel: "Option label",
11745
11875
  defaultValue: "option"
11746
11876
  },
11877
+ multi: {
11878
+ supported: true,
11879
+ autoEnable: true
11880
+ },
11747
11881
  defaultProps: {
11748
11882
  variant: "treeselect",
11749
11883
  // MUST
@@ -11830,6 +11964,10 @@ var multiSelectDescriptor = {
11830
11964
  defaultLabel: "Option label",
11831
11965
  defaultValue: "option"
11832
11966
  },
11967
+ multi: {
11968
+ supported: true,
11969
+ autoEnable: true
11970
+ },
11833
11971
  defaultProps: {
11834
11972
  variant: "multi-select",
11835
11973
  // MUST
@@ -11948,7 +12086,15 @@ var radioDescriptor = {
11948
12086
 
11949
12087
  // src/react/inputs/entries/checkbox.tsx
11950
12088
  import { InputField as InputField13 } from "@timeax/form-palette";
11951
- var checkboxBaseUi = {
12089
+ var checkboxSingleUi = {
12090
+ size: sharedUi.size,
12091
+ tristate: {
12092
+ type: "boolean",
12093
+ label: "Tri-state",
12094
+ description: 'Enable tri-state behaviour (supports an internal "none" state).'
12095
+ }
12096
+ };
12097
+ var checkboxOptionsUi = {
11952
12098
  size: sharedUi.size,
11953
12099
  density: {
11954
12100
  type: "anyOf",
@@ -11960,11 +12106,6 @@ var checkboxBaseUi = {
11960
12106
  { type: "string", title: "Loose", value: "loose" }
11961
12107
  ]
11962
12108
  },
11963
- single: {
11964
- type: "boolean",
11965
- label: "Single",
11966
- description: "If enabled, behaves like a single checkbox (boolean). Otherwise renders a group (array)."
11967
- },
11968
12109
  tristate: {
11969
12110
  type: "boolean",
11970
12111
  label: "Tri-state",
@@ -11994,23 +12135,23 @@ var checkboxBaseUi = {
11994
12135
  autoCap: {
11995
12136
  type: "boolean",
11996
12137
  label: "Auto capitalise",
11997
- description: "Capitalise the first letter of labels (only when label resolves to a string)."
12138
+ description: "Capitalise the first letter of labels when the label resolves to a string."
11998
12139
  },
11999
12140
  options: {
12000
12141
  type: "array",
12001
12142
  label: "Options",
12002
- description: "Checkbox options. Can be primitives (string/number/boolean) or objects (label/value/description/disabled/tristate).",
12143
+ description: "Checkbox options. Can be primitives or objects with label/value/description/disabled/tristate.",
12003
12144
  editable: true,
12004
12145
  item: {
12005
12146
  type: "object",
12006
12147
  label: "Option",
12007
- description: "An option item for group mode.",
12148
+ description: "An option item for checkbox group mode.",
12008
12149
  editable: true,
12009
12150
  fields: {
12010
12151
  value: {
12011
12152
  type: "string",
12012
12153
  label: "Value",
12013
- description: "Unique option value (string)."
12154
+ description: "Unique option value."
12014
12155
  },
12015
12156
  label: {
12016
12157
  type: "string",
@@ -12030,7 +12171,7 @@ var checkboxBaseUi = {
12030
12171
  tristate: {
12031
12172
  type: "boolean",
12032
12173
  label: "Tri-state override",
12033
- description: "Override tri-state behaviour for this option (if unset, uses variant tristate)."
12174
+ description: "Override tri-state behaviour for this option."
12034
12175
  }
12035
12176
  },
12036
12177
  order: ["value", "label", "description", "disabled", "tristate"]
@@ -12051,35 +12192,42 @@ var checkboxDescriptor = {
12051
12192
  Component: InputField13,
12052
12193
  defaultProps: {
12053
12194
  variant: "checkbox",
12054
- // MUST
12055
12195
  single: true,
12056
12196
  tristate: false,
12057
- layout: "list",
12058
- columns: 2,
12059
- itemGapPx: 8,
12060
- size: "md",
12061
- density: "comfortable",
12062
- autoCap: false
12197
+ size: "md"
12063
12198
  },
12064
- adapter: {},
12065
12199
  options: {
12066
12200
  supported: false
12067
12201
  },
12068
- ui: checkboxBaseUi
12202
+ multi: {
12203
+ supported: false
12204
+ },
12205
+ ui: checkboxSingleUi
12069
12206
  };
12070
- var _a;
12071
12207
  var checkboxOptionsDescriptor = {
12072
- ...checkboxDescriptor,
12208
+ Component: InputField13,
12073
12209
  defaultProps: {
12074
- ...(_a = checkboxDescriptor.defaultProps) != null ? _a : {},
12075
- single: false
12210
+ variant: "checkbox",
12211
+ single: false,
12212
+ tristate: false,
12213
+ layout: "list",
12214
+ columns: 2,
12215
+ itemGapPx: 8,
12216
+ size: "md",
12217
+ density: "comfortable",
12218
+ autoCap: false
12076
12219
  },
12077
12220
  options: {
12078
12221
  supported: true,
12079
12222
  autoCreate: true,
12080
12223
  defaultLabel: "Option label",
12081
12224
  defaultValue: "option"
12082
- }
12225
+ },
12226
+ multi: {
12227
+ supported: true,
12228
+ autoEnable: true
12229
+ },
12230
+ ui: checkboxOptionsUi
12083
12231
  };
12084
12232
 
12085
12233
  // src/react/inputs/entries/chips.tsx
@@ -12880,7 +13028,7 @@ var inputFieldUi = {
12880
13028
  }
12881
13029
  };
12882
13030
  function withInputFieldUi(desc) {
12883
- var _a2;
13031
+ var _a;
12884
13032
  return {
12885
13033
  ...desc,
12886
13034
  adapter: {
@@ -12890,7 +13038,7 @@ function withInputFieldUi(desc) {
12890
13038
  valueProp: "value",
12891
13039
  changeProp: "onChange",
12892
13040
  getInputPropsFromField({ field, props }) {
12893
- var _a3, _b;
13041
+ var _a2, _b;
12894
13042
  const severityPillClassMap = {
12895
13043
  info: "border-blue-200 bg-blue-50 text-blue-700 ring-1 ring-inset ring-blue-200",
12896
13044
  warning: "border-amber-200 bg-amber-50 text-amber-800 ring-1 ring-inset ring-amber-200",
@@ -12898,11 +13046,11 @@ function withInputFieldUi(desc) {
12898
13046
  };
12899
13047
  const pillBaseClassName = "inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-medium";
12900
13048
  const toTagPill = (tag) => {
12901
- var _a4;
13049
+ var _a3;
12902
13050
  return {
12903
13051
  label: tag.title,
12904
13052
  bgColor: tag.color,
12905
- className: `${pillBaseClassName} ${(_a4 = severityPillClassMap[tag.severity]) != null ? _a4 : severityPillClassMap.info}`
13053
+ className: `${pillBaseClassName} ${(_a3 = severityPillClassMap[tag.severity]) != null ? _a3 : severityPillClassMap.info}`
12906
13054
  };
12907
13055
  };
12908
13056
  const matchesNotice = (target, notice) => {
@@ -12911,7 +13059,7 @@ function withInputFieldUi(desc) {
12911
13059
  const isServiceMatch = !!target.service_id && String(target.service_id) === notice.id;
12912
13060
  return isNodeTargetMatch || isLegacyGlobalIdMatch || isServiceMatch;
12913
13061
  };
12914
- const notices = (_a3 = props.notices) != null ? _a3 : [];
13062
+ const notices = (_a2 = props.notices) != null ? _a2 : [];
12915
13063
  const fieldNotices = notices.filter(
12916
13064
  (notice) => matchesNotice(field, notice)
12917
13065
  );
@@ -12933,8 +13081,8 @@ function withInputFieldUi(desc) {
12933
13081
  };
12934
13082
  },
12935
13083
  getSelectedOptions(next, currentt, ctx) {
12936
- var _a3, _b, _c;
12937
- return (_c = (_b = (_a3 = next == null ? void 0 : next.detail) == null ? void 0 : _a3.selectedOptions) != null ? _b : []) == null ? void 0 : _c.map(
13084
+ var _a2, _b, _c;
13085
+ return (_c = (_b = (_a2 = next == null ? void 0 : next.detail) == null ? void 0 : _a2.selectedOptions) != null ? _b : []) == null ? void 0 : _c.map(
12938
13086
  (item) => item.id
12939
13087
  );
12940
13088
  },
@@ -12944,13 +13092,13 @@ function withInputFieldUi(desc) {
12944
13092
  },
12945
13093
  ui: {
12946
13094
  ...inputFieldUi,
12947
- ...(_a2 = desc.ui) != null ? _a2 : {}
13095
+ ...(_a = desc.ui) != null ? _a : {}
12948
13096
  }
12949
13097
  };
12950
13098
  }
12951
13099
  function variantOf(desc) {
12952
- var _a2;
12953
- const v = (_a2 = desc.defaultProps) == null ? void 0 : _a2.variant;
13100
+ var _a;
13101
+ const v = (_a = desc.defaultProps) == null ? void 0 : _a.variant;
12954
13102
  if (!v || typeof v !== "string") {
12955
13103
  throw new Error(
12956
13104
  `[inputs] Descriptor is missing defaultProps.variant: ${String(v)}`
@@ -13041,16 +13189,16 @@ function FallbackEditorProvider({
13041
13189
  );
13042
13190
  const resolvedEligibleServices = React5.useMemo(
13043
13191
  () => {
13044
- var _a2;
13045
- return (_a2 = eligibleServices != null ? eligibleServices : primaryServices) != null ? _a2 : {};
13192
+ var _a;
13193
+ return (_a = eligibleServices != null ? eligibleServices : primaryServices) != null ? _a : {};
13046
13194
  },
13047
13195
  [eligibleServices, primaryServices]
13048
13196
  );
13049
13197
  const editorRef = React5.useRef(null);
13050
13198
  const buildEditor = React5.useCallback(
13051
13199
  (next) => {
13052
- var _a2, _b, _c, _d, _e, _f, _g, _h;
13053
- const currentValue = (_a2 = editorRef.current) == null ? void 0 : _a2.value();
13200
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13201
+ const currentValue = (_a = editorRef.current) == null ? void 0 : _a.value();
13054
13202
  editorRef.current = createFallbackEditor({
13055
13203
  fallbacks: (_d = (_c = (_b = next == null ? void 0 : next.fallbacks) != null ? _b : currentValue) != null ? _c : fallbacks) != null ? _d : {},
13056
13204
  props: (_e = next == null ? void 0 : next.props) != null ? _e : props,
@@ -13441,7 +13589,7 @@ function VirtualServiceList({
13441
13589
  style: { height },
13442
13590
  onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
13443
13591
  children: /* @__PURE__ */ jsx7("div", { className: "relative", style: { height: total * rowHeight }, children: visible.map((item, i) => {
13444
- var _a2, _b;
13592
+ var _a, _b;
13445
13593
  const index = start + i;
13446
13594
  const key = String(item.id);
13447
13595
  const checked = selected.has(key);
@@ -13462,7 +13610,7 @@ function VirtualServiceList({
13462
13610
  String(item.id),
13463
13611
  " \xB7",
13464
13612
  " ",
13465
- (_a2 = item.name) != null ? _a2 : "Unnamed"
13613
+ (_a = item.name) != null ? _a : "Unnamed"
13466
13614
  ] }),
13467
13615
  /* @__PURE__ */ jsxs3("div", { className: "mt-0.5 text-xs text-zinc-500 dark:text-zinc-400", children: [
13468
13616
  (_b = item.platform) != null ? _b : "Unknown",
@@ -13492,7 +13640,7 @@ function VirtualServiceList({
13492
13640
  import React8 from "react";
13493
13641
  import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
13494
13642
  function FallbackDetailsPanel() {
13495
- var _a2, _b, _c, _d, _e, _f, _g, _h;
13643
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13496
13644
  const { activeServiceId, state, settings } = useFallbackEditor();
13497
13645
  const services = usePrimaryServiceList();
13498
13646
  const service = React8.useMemo(
@@ -13508,7 +13656,7 @@ function FallbackDetailsPanel() {
13508
13656
  Detail,
13509
13657
  {
13510
13658
  label: "Name",
13511
- value: (_a2 = service.name) != null ? _a2 : "Unnamed"
13659
+ value: (_a = service.name) != null ? _a : "Unnamed"
13512
13660
  }
13513
13661
  ),
13514
13662
  /* @__PURE__ */ jsx8(
@@ -13629,7 +13777,7 @@ import React9 from "react";
13629
13777
  import { InputField as InputField21 } from "@timeax/form-palette";
13630
13778
  import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
13631
13779
  function FallbackSettingsPanel() {
13632
- var _a2, _b, _c;
13780
+ var _a, _b, _c;
13633
13781
  const { settings, saveSettings, settingsSaving } = useFallbackEditorContext();
13634
13782
  const [draft, setDraft] = React9.useState(settings);
13635
13783
  const [error, setError] = React9.useState(null);
@@ -13658,7 +13806,7 @@ function FallbackSettingsPanel() {
13658
13806
  ratePolicy: next
13659
13807
  }));
13660
13808
  }
13661
- const ratePolicy = (_a2 = draft.ratePolicy) != null ? _a2 : {
13809
+ const ratePolicy = (_a = draft.ratePolicy) != null ? _a : {
13662
13810
  kind: "lte_primary",
13663
13811
  pct: 5
13664
13812
  };
@@ -13857,8 +14005,8 @@ function FallbackServiceSidebar() {
13857
14005
  if (!q) return services;
13858
14006
  return services.filter(
13859
14007
  (service) => {
13860
- var _a2, _b;
13861
- return String(service.id).includes(q) || String((_a2 = service.name) != null ? _a2 : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
14008
+ var _a, _b;
14009
+ return String(service.id).includes(q) || String((_a = service.name) != null ? _a : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
13862
14010
  }
13863
14011
  );
13864
14012
  }, [query, services]);
@@ -13882,7 +14030,7 @@ function FallbackServiceSidebar() {
13882
14030
  }
13883
14031
  ) }),
13884
14032
  /* @__PURE__ */ jsx11("div", { className: "mt-3 flex-1 space-y-2 overflow-y-auto", children: filtered.map((service) => {
13885
- var _a2, _b;
14033
+ var _a, _b;
13886
14034
  const active = String(service.id) === String(activeServiceId);
13887
14035
  const count = get(service.id).length;
13888
14036
  return /* @__PURE__ */ jsx11(
@@ -13901,7 +14049,7 @@ function FallbackServiceSidebar() {
13901
14049
  String(service.id),
13902
14050
  " \xB7",
13903
14051
  " ",
13904
- (_a2 = service.name) != null ? _a2 : "Unnamed"
14052
+ (_a = service.name) != null ? _a : "Unnamed"
13905
14053
  ] }),
13906
14054
  /* @__PURE__ */ jsxs7("div", { className: "mt-1 text-xs text-zinc-500 dark:text-zinc-400", children: [
13907
14055
  (_b = service.platform) != null ? _b : "Unknown",
@@ -13976,7 +14124,7 @@ function FallbackRegistrationsPanel() {
13976
14124
  )
13977
14125
  ] }),
13978
14126
  /* @__PURE__ */ jsx12("div", { className: "space-y-4", children: registrations.length === 0 ? /* @__PURE__ */ jsx12("div", { className: "rounded-2xl border border-dashed border-zinc-300 p-6 text-sm text-zinc-500 dark:border-zinc-700 dark:text-zinc-400", children: "No registrations yet for this primary service." }) : registrations.map((reg, index) => {
13979
- var _a2;
14127
+ var _a;
13980
14128
  const context = makeContext(reg);
13981
14129
  const candidates = reg.services;
13982
14130
  return /* @__PURE__ */ jsxs8(
@@ -13998,7 +14146,7 @@ function FallbackRegistrationsPanel() {
13998
14146
  ] })
13999
14147
  ] }),
14000
14148
  /* @__PURE__ */ jsx12("div", { className: "mt-4 flex flex-wrap gap-2", children: candidates.length === 0 ? /* @__PURE__ */ jsx12("span", { className: "text-xs text-zinc-500 dark:text-zinc-400", children: "No fallback services yet." }) : candidates.map((candidate) => {
14001
- var _a3;
14149
+ var _a2;
14002
14150
  const preview = check(context, [
14003
14151
  candidate
14004
14152
  ]);
@@ -14012,7 +14160,7 @@ function FallbackRegistrationsPanel() {
14012
14160
  {
14013
14161
  className: `inline-flex items-center gap-2 rounded-xl border px-3 py-2 text-xs ${tone}`,
14014
14162
  children: [
14015
- /* @__PURE__ */ jsx12("span", { children: service ? `#${String(service.id)} \xB7 ${(_a3 = service.name) != null ? _a3 : "Unnamed"}` : `#${String(candidate)}` }),
14163
+ /* @__PURE__ */ jsx12("span", { children: service ? `#${String(service.id)} \xB7 ${(_a2 = service.name) != null ? _a2 : "Unnamed"}` : `#${String(candidate)}` }),
14016
14164
  rejected ? /* @__PURE__ */ jsx12("span", { className: "rounded-full border border-current/20 px-2 py-0.5 text-[10px]", children: rejected.reasons.join(
14017
14165
  ", "
14018
14166
  ) }) : /* @__PURE__ */ jsx12("span", { className: "rounded-full border border-current/20 px-2 py-0.5 text-[10px]", children: "valid" }),
@@ -14058,7 +14206,7 @@ function FallbackRegistrationsPanel() {
14058
14206
  ] })
14059
14207
  ]
14060
14208
  },
14061
- `${reg.scope}:${String((_a2 = reg.scopeId) != null ? _a2 : "global")}:${index}`
14209
+ `${reg.scope}:${String((_a = reg.scopeId) != null ? _a : "global")}:${index}`
14062
14210
  );
14063
14211
  }) })
14064
14212
  ] }),
@@ -14117,7 +14265,7 @@ function FallbackAddCandidatesDialog({
14117
14265
  const items = React12.useMemo(() => {
14118
14266
  const q = query.trim().toLowerCase();
14119
14267
  return eligibleServices.filter((service) => {
14120
- var _a2, _b;
14268
+ var _a, _b;
14121
14269
  if (primaryId !== void 0 && String(service.id) === String(primaryId)) {
14122
14270
  return false;
14123
14271
  }
@@ -14125,7 +14273,7 @@ function FallbackAddCandidatesDialog({
14125
14273
  return false;
14126
14274
  }
14127
14275
  if (!q) return true;
14128
- return String(service.id).includes(q) || String((_a2 = service.name) != null ? _a2 : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
14276
+ return String(service.id).includes(q) || String((_a = service.name) != null ? _a : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
14129
14277
  });
14130
14278
  }, [eligibleServices, allowedIds, query, primaryId]);
14131
14279
  function toggle(id) {
@@ -14247,7 +14395,7 @@ function FallbackAddRegistrationDialog({
14247
14395
  return registrations.some((r) => r.scope === "global");
14248
14396
  }, [registrations]);
14249
14397
  const nodeTargets = React13.useMemo(() => {
14250
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14398
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14251
14399
  if (activeServiceId === void 0 || activeServiceId === null) {
14252
14400
  return [];
14253
14401
  }
@@ -14268,7 +14416,7 @@ function FallbackAddRegistrationDialog({
14268
14416
  serviceId: activeServiceId
14269
14417
  });
14270
14418
  }
14271
- const activeTagId = (_a2 = snapshot.selection) == null ? void 0 : _a2.tag;
14419
+ const activeTagId = (_a = snapshot.selection) == null ? void 0 : _a.tag;
14272
14420
  out.sort((a, b) => {
14273
14421
  if (activeTagId && a.id === activeTagId && b.id !== activeTagId) {
14274
14422
  return -1;
@@ -14348,7 +14496,7 @@ function FallbackAddRegistrationDialog({
14348
14496
  }
14349
14497
  }, [scope, nodeId, nodeTargets]);
14350
14498
  function handleContinue() {
14351
- var _a2;
14499
+ var _a;
14352
14500
  if (activeServiceId === void 0 || activeServiceId === null) return;
14353
14501
  if (scope === "global") {
14354
14502
  onSelect(
@@ -14367,7 +14515,7 @@ function FallbackAddRegistrationDialog({
14367
14515
  scope: "node",
14368
14516
  nodeId
14369
14517
  },
14370
- (_a2 = node == null ? void 0 : node.serviceId) != null ? _a2 : activeServiceId
14518
+ (_a = node == null ? void 0 : node.serviceId) != null ? _a : activeServiceId
14371
14519
  );
14372
14520
  }
14373
14521
  if (!open) return null;
@@ -14447,11 +14595,11 @@ function FallbackAddRegistrationDialog({
14447
14595
  ] }) });
14448
14596
  }
14449
14597
  function resolveNodeMeta(props, nodeId) {
14450
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14598
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14451
14599
  if (!props) {
14452
14600
  return { kind: "node", label: nodeId };
14453
14601
  }
14454
- const tag = (_a2 = props.filters) == null ? void 0 : _a2.find((t) => t.id === nodeId);
14602
+ const tag = (_a = props.filters) == null ? void 0 : _a.find((t) => t.id === nodeId);
14455
14603
  if (tag) {
14456
14604
  return {
14457
14605
  kind: "tag",