@timeax/digital-service-engine 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,6 +55,7 @@ __export(react_exports, {
55
55
  useFallbackEditorContext: () => useFallbackEditorContext,
56
56
  useFormApi: () => useFormApi,
57
57
  useInputs: () => useInputs,
58
+ useInputsMaybe: () => useInputsMaybe,
58
59
  useOptionalFormApi: () => useOptionalFormApi,
59
60
  useOrderFlow: () => useOrderFlow,
60
61
  useOrderFlowContext: () => useOrderFlowContext,
@@ -68,8 +69,8 @@ var EventBus = class {
68
69
  this.listeners = /* @__PURE__ */ new Map();
69
70
  }
70
71
  on(event, handler) {
71
- var _a;
72
- const set = (_a = this.listeners.get(event)) != null ? _a : /* @__PURE__ */ new Set();
72
+ var _a2;
73
+ const set = (_a2 = this.listeners.get(event)) != null ? _a2 : /* @__PURE__ */ new Set();
73
74
  set.add(handler);
74
75
  this.listeners.set(event, set);
75
76
  return () => {
@@ -101,9 +102,9 @@ var RetryQueue = class {
101
102
  constructor(opts = {}) {
102
103
  this.jobs = /* @__PURE__ */ new Map();
103
104
  this.paused = false;
104
- var _a, _b, _c, _d, _e, _f;
105
+ var _a2, _b, _c, _d, _e, _f;
105
106
  this.opts = {
106
- enabled: (_a = opts.enabled) != null ? _a : true,
107
+ enabled: (_a2 = opts.enabled) != null ? _a2 : true,
107
108
  maxAttempts: (_b = opts.maxAttempts) != null ? _b : 5,
108
109
  baseDelayMs: (_c = opts.baseDelayMs) != null ? _c : 800,
109
110
  maxDelayMs: (_d = opts.maxDelayMs) != null ? _d : 2e4,
@@ -120,11 +121,11 @@ var RetryQueue = class {
120
121
  }
121
122
  /** Enqueue or no-op if a job with same id already exists */
122
123
  enqueue(job) {
123
- var _a;
124
+ var _a2;
124
125
  if (!this.opts.enabled) return false;
125
126
  if (this.jobs.has(job.id)) return false;
126
127
  this.jobs.set(job.id, { job, attempt: 0 });
127
- (_a = job.onStatus) == null ? void 0 : _a.call(job, "scheduled", { attempt: 0 });
128
+ (_a2 = job.onStatus) == null ? void 0 : _a2.call(job, "scheduled", { attempt: 0 });
128
129
  this.kick(job.id);
129
130
  return true;
130
131
  }
@@ -138,12 +139,12 @@ var RetryQueue = class {
138
139
  return true;
139
140
  }
140
141
  cancel(id) {
141
- var _a, _b;
142
+ var _a2, _b;
142
143
  const rec = this.jobs.get(id);
143
144
  if (!rec) return false;
144
145
  if (rec.timer) clearTimeout(rec.timer);
145
146
  rec.cancelled = true;
146
- (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "cancelled", { attempt: rec.attempt });
147
+ (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "cancelled", { attempt: rec.attempt });
147
148
  this.jobs.delete(id);
148
149
  return true;
149
150
  }
@@ -157,11 +158,11 @@ var RetryQueue = class {
157
158
  return this.jobs.has(id);
158
159
  }
159
160
  drain() {
160
- var _a, _b;
161
+ var _a2, _b;
161
162
  for (const [id, rec] of this.jobs.entries()) {
162
163
  if (rec.timer) clearTimeout(rec.timer);
163
164
  rec.cancelled = true;
164
- (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "cancelled", { attempt: rec.attempt });
165
+ (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "cancelled", { attempt: rec.attempt });
165
166
  this.jobs.delete(id);
166
167
  }
167
168
  }
@@ -176,15 +177,15 @@ var RetryQueue = class {
176
177
  return Math.min(maxDelayMs, Math.floor(exp * r));
177
178
  }
178
179
  async kick(id, immediate = false) {
179
- var _a, _b;
180
+ var _a2, _b;
180
181
  const rec = this.jobs.get(id);
181
182
  if (!rec || rec.cancelled) return;
182
183
  if (this.paused && !immediate) return;
183
184
  const attempt = rec.attempt + 1;
184
185
  const run = async () => {
185
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
186
+ var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
186
187
  if (rec.cancelled) return;
187
- (_b2 = (_a2 = rec.job).onStatus) == null ? void 0 : _b2.call(_a2, "retrying", { attempt });
188
+ (_b2 = (_a3 = rec.job).onStatus) == null ? void 0 : _b2.call(_a3, "retrying", { attempt });
188
189
  try {
189
190
  const ok = await rec.job.perform(attempt);
190
191
  if (ok) {
@@ -209,7 +210,7 @@ var RetryQueue = class {
209
210
  else {
210
211
  const delay = this.opts.immediateFirst && attempt === 1 ? 0 : this.delayFor(attempt);
211
212
  if (delay) {
212
- (_b = (_a = rec.job).onStatus) == null ? void 0 : _b.call(_a, "scheduled", { attempt: 0, nextDelayMs: delay });
213
+ (_b = (_a2 = rec.job).onStatus) == null ? void 0 : _b.call(_a2, "scheduled", { attempt: 0, nextDelayMs: delay });
213
214
  rec.timer = setTimeout(run, delay);
214
215
  } else {
215
216
  void run();
@@ -229,8 +230,8 @@ var CommentsAPI = class {
229
230
  this.retry = new RetryQueue(deps.retry);
230
231
  }
231
232
  scope() {
232
- var _a, _b;
233
- return (_b = (_a = this.deps).getScope) == null ? void 0 : _b.call(_a);
233
+ var _a2, _b;
234
+ return (_b = (_a2 = this.deps).getScope) == null ? void 0 : _b.call(_a2);
234
235
  }
235
236
  emitSync(op, threadId, messageId, status, meta) {
236
237
  this.bus.emit("comment:sync", {
@@ -272,7 +273,7 @@ var CommentsAPI = class {
272
273
  }
273
274
  /* ─── Mutations (optimistic if backend present) ─────── */
274
275
  async create(anchor, initialBody, meta) {
275
- var _a, _b;
276
+ var _a2, _b;
276
277
  const now = Date.now();
277
278
  const localId = newLocalId("t");
278
279
  const msgId = newLocalId("m");
@@ -313,7 +314,7 @@ var CommentsAPI = class {
313
314
  return serverId;
314
315
  } catch (err) {
315
316
  const scope = this.scope();
316
- const branchKey = (_a = scope == null ? void 0 : scope.branchId) != null ? _a : "no_branch";
317
+ const branchKey = (_a2 = scope == null ? void 0 : scope.branchId) != null ? _a2 : "no_branch";
317
318
  const jobId = `comments:create_thread:${branchKey}:${localId}`;
318
319
  this.retry.enqueue({
319
320
  id: jobId,
@@ -344,7 +345,7 @@ var CommentsAPI = class {
344
345
  }
345
346
  }
346
347
  async reply(threadId, body, meta) {
347
- var _a, _b, _c;
348
+ var _a2, _b, _c;
348
349
  const th = this.ensure(threadId);
349
350
  const now = Date.now();
350
351
  const localMid = newLocalId("m");
@@ -357,7 +358,7 @@ var CommentsAPI = class {
357
358
  };
358
359
  th.messages.push(localMsg);
359
360
  th.updatedAt = now;
360
- (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
361
+ (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
361
362
  this.bus.emit("comment:message:create", {
362
363
  threadId,
363
364
  message: localMsg
@@ -416,7 +417,7 @@ var CommentsAPI = class {
416
417
  }
417
418
  }
418
419
  async editMessage(threadId, messageId, body) {
419
- var _a, _b, _c;
420
+ var _a2, _b, _c;
420
421
  const th = this.ensure(threadId);
421
422
  const orig = th.messages.find((m) => m.id === messageId);
422
423
  if (!orig) return;
@@ -425,7 +426,7 @@ var CommentsAPI = class {
425
426
  orig.editedAt = Date.now();
426
427
  th.updatedAt = orig.editedAt;
427
428
  const hasBackend = Boolean(this.deps.backend && this.scope());
428
- (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
429
+ (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
429
430
  this.bus.emit("comment:thread:update", { thread: th });
430
431
  if (!this.deps.backend) return;
431
432
  const performOnce = async () => {
@@ -478,13 +479,13 @@ var CommentsAPI = class {
478
479
  }
479
480
  }
480
481
  async deleteMessage(threadId, messageId) {
481
- var _a, _b, _c;
482
+ var _a2, _b, _c;
482
483
  const th = this.ensure(threadId);
483
484
  const backup = [...th.messages];
484
485
  th.messages = th.messages.filter((m) => m.id !== messageId);
485
486
  th.updatedAt = Date.now();
486
487
  const hasBackend = Boolean(this.deps.backend && this.scope());
487
- (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
488
+ (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
488
489
  this.bus.emit("comment:thread:update", { thread: th });
489
490
  if (!this.deps.backend) return;
490
491
  const performOnce = async () => {
@@ -533,13 +534,13 @@ var CommentsAPI = class {
533
534
  }
534
535
  }
535
536
  async move(threadId, anchor) {
536
- var _a, _b, _c;
537
+ var _a2, _b, _c;
537
538
  const th = this.ensure(threadId);
538
539
  const prev = th.anchor;
539
540
  th.anchor = anchor;
540
541
  th.updatedAt = Date.now();
541
542
  const hasBackend = Boolean(this.deps.backend && this.scope());
542
- (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
543
+ (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
543
544
  this.bus.emit("comment:move", { thread: th });
544
545
  this.bus.emit("comment:thread:update", { thread: th });
545
546
  if (!this.deps.backend) return;
@@ -591,13 +592,13 @@ var CommentsAPI = class {
591
592
  }
592
593
  }
593
594
  async resolve(threadId, value = true) {
594
- var _a, _b, _c;
595
+ var _a2, _b, _c;
595
596
  const th = this.ensure(threadId);
596
597
  const prev = th.resolved;
597
598
  th.resolved = value;
598
599
  th.updatedAt = Date.now();
599
600
  const hasBackend = Boolean(this.deps.backend && this.scope());
600
- (_a = th._sync) != null ? _a : th._sync = hasBackend ? "pending" : "synced";
601
+ (_a2 = th._sync) != null ? _a2 : th._sync = hasBackend ? "pending" : "synced";
601
602
  this.bus.emit("comment:resolve", { thread: th, resolved: value });
602
603
  this.bus.emit("comment:thread:update", { thread: th });
603
604
  if (!this.deps.backend) return;
@@ -649,7 +650,7 @@ var CommentsAPI = class {
649
650
  }
650
651
  }
651
652
  async deleteThread(threadId) {
652
- var _a, _b;
653
+ var _a2, _b;
653
654
  const prev = this.threads.get(threadId);
654
655
  if (!prev) return;
655
656
  this.threads.delete(threadId);
@@ -665,7 +666,7 @@ var CommentsAPI = class {
665
666
  await performOnce();
666
667
  } catch (err) {
667
668
  const scope = this.scope();
668
- const branchKey = (_a = scope == null ? void 0 : scope.branchId) != null ? _a : "no_branch";
669
+ const branchKey = (_a2 = scope == null ? void 0 : scope.branchId) != null ? _a2 : "no_branch";
669
670
  const jobId = `comments:delete_thread:${branchKey}:${threadId}`;
670
671
  this.retry.enqueue({
671
672
  id: jobId,
@@ -718,8 +719,8 @@ var import_lodash_es4 = require("lodash-es");
718
719
  // src/core/normalise.ts
719
720
  var import_lodash_es = require("lodash-es");
720
721
  function normalise(input, opts = {}) {
721
- var _a, _b;
722
- const defRole = (_a = opts.defaultPricingRole) != null ? _a : "base";
722
+ var _a2, _b;
723
+ const defRole = (_a2 = opts.defaultPricingRole) != null ? _a2 : "base";
723
724
  const constraints = (_b = opts.constraints) != null ? _b : ["refill", "cancel", "dripfeed"];
724
725
  const obj = toObject(input);
725
726
  const rawFilters = Array.isArray(obj.filters) ? obj.filters : [];
@@ -769,10 +770,10 @@ function propagateConstraints(props, flagKeys) {
769
770
  const starts = roots.length ? roots : tags;
770
771
  const visited = /* @__PURE__ */ new Set();
771
772
  const visit = (tag, inherited) => {
772
- var _a, _b;
773
+ var _a2, _b;
773
774
  if (visited.has(tag.id)) return;
774
775
  visited.add(tag.id);
775
- const local = (0, import_lodash_es.cloneDeep)((_a = tag.constraints) != null ? _a : {});
776
+ const local = (0, import_lodash_es.cloneDeep)((_a2 = tag.constraints) != null ? _a2 : {});
776
777
  if (tag.constraints_overrides) {
777
778
  for (const [k, over] of Object.entries(tag.constraints_overrides)) {
778
779
  if (over) local[k] = over.from;
@@ -1054,8 +1055,8 @@ function isServiceIdRef(v) {
1054
1055
  return typeof v === "string" && v.trim().length > 0 || typeof v === "number" && Number.isFinite(v);
1055
1056
  }
1056
1057
  function hasAnyServiceOption(f) {
1057
- var _a;
1058
- return ((_a = f.options) != null ? _a : []).some((o) => isServiceIdRef(o.service_id));
1058
+ var _a2;
1059
+ return ((_a2 = f.options) != null ? _a2 : []).some((o) => isServiceIdRef(o.service_id));
1059
1060
  }
1060
1061
  function getByPath(obj, path) {
1061
1062
  if (!path) return void 0;
@@ -1085,12 +1086,12 @@ function includesValue(arr, needle) {
1085
1086
  return false;
1086
1087
  }
1087
1088
  function matchesWhere(svc, where) {
1088
- var _a;
1089
+ var _a2;
1089
1090
  if (!where || where.length === 0) return true;
1090
1091
  const root = { service: svc };
1091
1092
  for (const clause of where) {
1092
1093
  const path = clause.path;
1093
- const op = (_a = clause.op) != null ? _a : "eq";
1094
+ const op = (_a2 = clause.op) != null ? _a2 : "eq";
1094
1095
  const value = clause.value;
1095
1096
  const cur = getByPath(root, path);
1096
1097
  if (op === "exists") {
@@ -1144,9 +1145,9 @@ function withAffected(details, ids) {
1144
1145
 
1145
1146
  // src/core/node-map.ts
1146
1147
  function buildNodeMap(props) {
1147
- var _a, _b, _c;
1148
+ var _a2, _b, _c;
1148
1149
  const map = /* @__PURE__ */ new Map();
1149
- for (const t of (_a = props.filters) != null ? _a : []) {
1150
+ for (const t of (_a2 = props.filters) != null ? _a2 : []) {
1150
1151
  if (!map.has(t.id)) map.set(t.id, { kind: "tag", id: t.id, node: t });
1151
1152
  }
1152
1153
  for (const f of (_b = props.fields) != null ? _b : []) {
@@ -1185,8 +1186,8 @@ function resolveTrigger(trigger, nodeMap) {
1185
1186
 
1186
1187
  // src/core/visibility.ts
1187
1188
  function visibleFieldIdsUnder(props, tagId, opts = {}) {
1188
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1189
- const tags = (_a = props.filters) != null ? _a : [];
1189
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1190
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
1190
1191
  const fields = (_b = props.fields) != null ? _b : [];
1191
1192
  const tagById = new Map(tags.map((t) => [t.id, t]));
1192
1193
  const tag = tagById.get(tagId);
@@ -1303,9 +1304,9 @@ function visibleFieldIdsUnder(props, tagId, opts = {}) {
1303
1304
  return base;
1304
1305
  }
1305
1306
  function visibleFieldsUnder(props, tagId, opts = {}) {
1306
- var _a;
1307
+ var _a2;
1307
1308
  const ids = visibleFieldIdsUnder(props, tagId, opts);
1308
- const fieldById = new Map(((_a = props.fields) != null ? _a : []).map((f) => [f.id, f]));
1309
+ const fieldById = new Map(((_a2 = props.fields) != null ? _a2 : []).map((f) => [f.id, f]));
1309
1310
  return ids.map((id) => fieldById.get(id)).filter(Boolean);
1310
1311
  }
1311
1312
 
@@ -1325,7 +1326,7 @@ function resolveRootTags(tags) {
1325
1326
  return roots.length ? roots : tags.slice(0, 1);
1326
1327
  }
1327
1328
  function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKeys) {
1328
- var _a;
1329
+ var _a2;
1329
1330
  const visible = visibleFieldsUnder(v.props, tagId, {
1330
1331
  selectedKeys
1331
1332
  });
@@ -1335,7 +1336,7 @@ function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKey
1335
1336
  const t = f.id;
1336
1337
  if (effectfulKeys.has(t)) triggers.push(t);
1337
1338
  }
1338
- for (const o of (_a = f.options) != null ? _a : []) {
1339
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
1339
1340
  const t = o.id;
1340
1341
  if (effectfulKeys.has(t)) triggers.push(t);
1341
1342
  }
@@ -1344,12 +1345,12 @@ function collectSelectableTriggersInContext(v, tagId, selectedKeys, effectfulKey
1344
1345
  return triggers;
1345
1346
  }
1346
1347
  function runVisibilityRulesOnce(v) {
1347
- var _a, _b, _c, _d, _e;
1348
+ var _a2, _b, _c, _d, _e;
1348
1349
  for (const t of v.tags) {
1349
1350
  const visible = v.fieldsVisibleUnder(t.id);
1350
1351
  const seen = /* @__PURE__ */ new Map();
1351
1352
  for (const f of visible) {
1352
- const label = ((_a = f.label) != null ? _a : "").trim();
1353
+ const label = ((_a2 = f.label) != null ? _a2 : "").trim();
1353
1354
  if (!label) continue;
1354
1355
  if (seen.has(label)) {
1355
1356
  const otherId = seen.get(label);
@@ -1421,8 +1422,8 @@ function runVisibilityRulesOnce(v) {
1421
1422
  function dedupeErrorsInPlace(v, startIndex) {
1422
1423
  const seen = /* @__PURE__ */ new Set();
1423
1424
  const keyOfErr = (e) => {
1424
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1425
- 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 : "";
1425
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1426
+ 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 : "";
1426
1427
  const other = (_g = (_f = e == null ? void 0 : e.details) == null ? void 0 : _f.other) != null ? _g : "";
1427
1428
  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 : ""}`;
1428
1429
  };
@@ -1437,7 +1438,7 @@ function dedupeErrorsInPlace(v, startIndex) {
1437
1438
  v.errors.splice(startIndex, v.errors.length - startIndex, ...kept);
1438
1439
  }
1439
1440
  function validateVisibility(v, options = {}) {
1440
- var _a, _b, _c, _d, _e;
1441
+ var _a2, _b, _c, _d, _e;
1441
1442
  v.simulatedVisibilityContexts = [];
1442
1443
  const simulate = options.simulate === true;
1443
1444
  if (!simulate) {
@@ -1451,7 +1452,7 @@ function validateVisibility(v, options = {}) {
1451
1452
  }
1452
1453
  return;
1453
1454
  }
1454
- const maxStates = Math.max(1, (_a = options.maxStates) != null ? _a : 500);
1455
+ const maxStates = Math.max(1, (_a2 = options.maxStates) != null ? _a2 : 500);
1455
1456
  const maxDepth = Math.max(0, (_b = options.maxDepth) != null ? _b : 6);
1456
1457
  const onlyEffectful = options.onlyEffectfulTriggers !== false;
1457
1458
  const effectfulKeys = /* @__PURE__ */ new Set();
@@ -1541,11 +1542,11 @@ function validateStructure(v) {
1541
1542
  const visiting = /* @__PURE__ */ new Set();
1542
1543
  const visited = /* @__PURE__ */ new Set();
1543
1544
  const hasCycleFrom = (id) => {
1544
- var _a;
1545
+ var _a2;
1545
1546
  if (visiting.has(id)) return true;
1546
1547
  if (visited.has(id)) return false;
1547
1548
  visiting.add(id);
1548
- const parent = (_a = v.tagById.get(id)) == null ? void 0 : _a.bind_id;
1549
+ const parent = (_a2 = v.tagById.get(id)) == null ? void 0 : _a2.bind_id;
1549
1550
  if (parent && v.tagById.has(parent) && hasCycleFrom(parent))
1550
1551
  return true;
1551
1552
  visiting.delete(id);
@@ -1606,7 +1607,7 @@ function validateStructure(v) {
1606
1607
 
1607
1608
  // src/core/validate/steps/identity.ts
1608
1609
  function validateIdentity(v) {
1609
- var _a, _b;
1610
+ var _a2, _b;
1610
1611
  const tags = v.tags;
1611
1612
  const fields = v.fields;
1612
1613
  {
@@ -1628,7 +1629,7 @@ function validateIdentity(v) {
1628
1629
  }
1629
1630
  for (const f of fields) {
1630
1631
  if (seen.has(f.id)) {
1631
- const kind = (_a = firstSeen.get(f.id)) != null ? _a : "tag/field";
1632
+ const kind = (_a2 = firstSeen.get(f.id)) != null ? _a2 : "tag/field";
1632
1633
  v.errors.push({
1633
1634
  code: "duplicate_id",
1634
1635
  severity: "error",
@@ -1730,14 +1731,14 @@ function parseFieldOptionKey(key) {
1730
1731
  return { fieldId, optionId };
1731
1732
  }
1732
1733
  function hasOption(v, fid, oid) {
1733
- var _a;
1734
+ var _a2;
1734
1735
  const f = v.fieldById.get(fid);
1735
1736
  if (!f) return false;
1736
- return !!((_a = f.options) != null ? _a : []).find((o) => o.id === oid);
1737
+ return !!((_a2 = f.options) != null ? _a2 : []).find((o) => o.id === oid);
1737
1738
  }
1738
1739
  function validateOptionMaps(v) {
1739
- var _a, _b;
1740
- const incMap = (_a = v.props.includes_for_buttons) != null ? _a : {};
1740
+ var _a2, _b;
1741
+ const incMap = (_a2 = v.props.includes_for_buttons) != null ? _a2 : {};
1741
1742
  const excMap = (_b = v.props.excludes_for_buttons) != null ? _b : {};
1742
1743
  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.`;
1743
1744
  const validateTriggerKey = (key) => {
@@ -1851,8 +1852,8 @@ function normalizeSelectedOrderKindTriggers(selectedTriggerKeys, nodeMap) {
1851
1852
  return out;
1852
1853
  }
1853
1854
  function resolveOrderKind(params) {
1854
- var _a, _b;
1855
- const nodeMap = (_a = params.nodeMap) != null ? _a : buildNodeMap(params.props);
1855
+ var _a2, _b;
1856
+ const nodeMap = (_a2 = params.nodeMap) != null ? _a2 : buildNodeMap(params.props);
1856
1857
  const orderKinds = (_b = params.props.orderKinds) != null ? _b : {};
1857
1858
  const normalizedSelected = normalizeSelectedOrderKindTriggers(
1858
1859
  params.selectedTriggerKeys,
@@ -1907,8 +1908,8 @@ function resolveOrderKind(params) {
1907
1908
 
1908
1909
  // src/core/validate/steps/order-kinds.ts
1909
1910
  function validateOrderKinds(v) {
1910
- var _a, _b, _c;
1911
- const selectedTriggerKeys = Array.from((_a = v.selectedKeys) != null ? _a : []);
1911
+ var _a2, _b, _c;
1912
+ const selectedTriggerKeys = Array.from((_a2 = v.selectedKeys) != null ? _a2 : []);
1912
1913
  if (!selectedTriggerKeys.length) return;
1913
1914
  const resolved = resolveOrderKind({
1914
1915
  props: v.props,
@@ -1934,8 +1935,8 @@ function validateOrderKinds(v) {
1934
1935
 
1935
1936
  // src/core/validate/steps/service-vs-input.ts
1936
1937
  function hasButtonTriggerMap(v, fieldId) {
1937
- var _a, _b;
1938
- const includes = (_a = v.props.includes_for_buttons) == null ? void 0 : _a[fieldId];
1938
+ var _a2, _b;
1939
+ const includes = (_a2 = v.props.includes_for_buttons) == null ? void 0 : _a2[fieldId];
1939
1940
  const excludes = (_b = v.props.excludes_for_buttons) == null ? void 0 : _b[fieldId];
1940
1941
  return Array.isArray(includes) && includes.length > 0 || Array.isArray(excludes) && excludes.length > 0;
1941
1942
  }
@@ -1980,7 +1981,7 @@ function validateServiceVsUserInput(v) {
1980
1981
 
1981
1982
  // src/core/validate/steps/utility.ts
1982
1983
  function validateUtilityMarkers(v) {
1983
- var _a, _b, _c, _d;
1984
+ var _a2, _b, _c, _d;
1984
1985
  const ALLOWED_UTILITY_MODES = /* @__PURE__ */ new Set([
1985
1986
  "flat",
1986
1987
  "per_quantity",
@@ -1990,7 +1991,7 @@ function validateUtilityMarkers(v) {
1990
1991
  for (const f of v.fields) {
1991
1992
  const optsArr = Array.isArray(f.options) ? f.options : [];
1992
1993
  for (const o of optsArr) {
1993
- const role = (_b = (_a = o.pricing_role) != null ? _a : f.pricing_role) != null ? _b : "base";
1994
+ const role = (_b = (_a2 = o.pricing_role) != null ? _a2 : f.pricing_role) != null ? _b : "base";
1994
1995
  const hasService = isServiceIdRef(o.service_id);
1995
1996
  const util = (_c = o.meta) == null ? void 0 : _c.utility;
1996
1997
  if (role === "utility" && hasService) {
@@ -2071,9 +2072,9 @@ function validateUtilityMarkers(v) {
2071
2072
 
2072
2073
  // src/utils/index.ts
2073
2074
  function isMultiField(f) {
2074
- var _a;
2075
+ var _a2;
2075
2076
  const t = (f.type || "").toLowerCase();
2076
- const metaMulti = !!((_a = f.meta) == null ? void 0 : _a.multi);
2077
+ const metaMulti = !!((_a2 = f.meta) == null ? void 0 : _a2.multi);
2077
2078
  return t === "multiselect" || t === "checkbox" || metaMulti;
2078
2079
  }
2079
2080
 
@@ -2093,8 +2094,8 @@ function constraintFitOk(svcMap, candidate, constraints) {
2093
2094
  return !(constraints.cancel === true && !cap.cancel);
2094
2095
  }
2095
2096
  function getServiceCapability(svcMap, candidate) {
2096
- var _a;
2097
- return (_a = getServiceCapabilityEntry(svcMap, candidate)) == null ? void 0 : _a.capability;
2097
+ var _a2;
2098
+ return (_a2 = getServiceCapabilityEntry(svcMap, candidate)) == null ? void 0 : _a2.capability;
2098
2099
  }
2099
2100
  function getServiceCapabilityCanonicalRef(svcMap, candidate) {
2100
2101
  const entry = getServiceCapabilityEntry(svcMap, candidate);
@@ -2121,10 +2122,10 @@ function isSameServiceCapabilityRef(svcMap, left, right) {
2121
2122
  return rightAliases.some((value) => leftAliases.has(String(value)));
2122
2123
  }
2123
2124
  function normalizeRatePolicy(policy) {
2124
- var _a;
2125
+ var _a2;
2125
2126
  if (!policy) return { kind: "lte_primary", pct: 5 };
2126
2127
  if (policy.kind === "eq_primary") return policy;
2127
- const pct = Math.max(0, Number((_a = policy.pct) != null ? _a : 0));
2128
+ const pct = Math.max(0, Number((_a2 = policy.pct) != null ? _a2 : 0));
2128
2129
  return { ...policy, pct };
2129
2130
  }
2130
2131
  function passesRatePolicy(policy, primaryRate, candidateRate) {
@@ -2225,12 +2226,12 @@ function normalizeServiceRef(value) {
2225
2226
 
2226
2227
  // src/core/validate/steps/rates.ts
2227
2228
  function validateRates(v) {
2228
- var _a, _b, _c;
2229
+ var _a2, _b, _c;
2229
2230
  const ratePolicy = normalizeRatePolicy(v.options.ratePolicy);
2230
2231
  for (const f of v.fields) {
2231
2232
  if (!isMultiField(f)) continue;
2232
2233
  const baseRates = [];
2233
- for (const o of (_a = f.options) != null ? _a : []) {
2234
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
2234
2235
  const role = (_c = (_b = o.pricing_role) != null ? _b : f.pricing_role) != null ? _c : "base";
2235
2236
  if (role !== "base") continue;
2236
2237
  const sid = o.service_id;
@@ -2283,7 +2284,7 @@ function validateRates(v) {
2283
2284
 
2284
2285
  // src/core/rate-coherence.ts
2285
2286
  function buildTriggerEffectMap(props) {
2286
- var _a, _b;
2287
+ var _a2, _b;
2287
2288
  const map = /* @__PURE__ */ new Map();
2288
2289
  const ensure = (key) => {
2289
2290
  let item = map.get(key);
@@ -2293,7 +2294,7 @@ function buildTriggerEffectMap(props) {
2293
2294
  }
2294
2295
  return item;
2295
2296
  };
2296
- for (const [key, ids] of Object.entries((_a = props.includes_for_buttons) != null ? _a : {})) {
2297
+ for (const [key, ids] of Object.entries((_a2 = props.includes_for_buttons) != null ? _a2 : {})) {
2297
2298
  const item = ensure(key);
2298
2299
  for (const id of ids != null ? ids : []) item.includes.add(id);
2299
2300
  }
@@ -2333,7 +2334,7 @@ function getRate(serviceMap, serviceId) {
2333
2334
  return rate;
2334
2335
  }
2335
2336
  function collectContextRefs(tag, visibleFields, serviceMap) {
2336
- var _a, _b, _c, _d, _e;
2337
+ var _a2, _b, _c, _d, _e;
2337
2338
  const serviceRefs = [];
2338
2339
  let tagDefault;
2339
2340
  if (tag.service_id !== void 0 && tag.service_id !== null) {
@@ -2345,7 +2346,7 @@ function collectContextRefs(tag, visibleFields, serviceMap) {
2345
2346
  nodeKind: "tag",
2346
2347
  serviceId: tag.service_id,
2347
2348
  rate: tagRate,
2348
- label: (_a = tag.label) != null ? _a : tag.id,
2349
+ label: (_a2 = tag.label) != null ? _a2 : tag.id,
2349
2350
  pricingRole: "base"
2350
2351
  };
2351
2352
  }
@@ -2622,7 +2623,7 @@ function constraintKeysInChain(v, tagId) {
2622
2623
  return keys;
2623
2624
  }
2624
2625
  function effectiveConstraints(v, tagId) {
2625
- var _a;
2626
+ var _a2;
2626
2627
  const out = {};
2627
2628
  const keys = constraintKeysInChain(v, tagId);
2628
2629
  for (const key of keys) {
@@ -2631,7 +2632,7 @@ function effectiveConstraints(v, tagId) {
2631
2632
  while (cur && !seen.has(cur)) {
2632
2633
  seen.add(cur);
2633
2634
  const t = v.tagById.get(cur);
2634
- const val = (_a = t == null ? void 0 : t.constraints) == null ? void 0 : _a[key];
2635
+ const val = (_a2 = t == null ? void 0 : t.constraints) == null ? void 0 : _a2[key];
2635
2636
  if (val === true || val === false) {
2636
2637
  out[key] = val;
2637
2638
  break;
@@ -2642,7 +2643,7 @@ function effectiveConstraints(v, tagId) {
2642
2643
  return out;
2643
2644
  }
2644
2645
  function validateConstraints(v) {
2645
- var _a, _b;
2646
+ var _a2, _b;
2646
2647
  for (const t of v.tags) {
2647
2648
  const eff = effectiveConstraints(v, t.id);
2648
2649
  const hasAnyRequired = Object.values(eff).some(
@@ -2651,7 +2652,7 @@ function validateConstraints(v) {
2651
2652
  if (!hasAnyRequired) continue;
2652
2653
  const visible = v.fieldsVisibleUnder(t.id);
2653
2654
  for (const f of visible) {
2654
- for (const o of (_a = f.options) != null ? _a : []) {
2655
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
2655
2656
  if (!isServiceIdRef(o.service_id)) continue;
2656
2657
  const svc = getServiceCapability(v.serviceMap, o.service_id);
2657
2658
  if (!svc || typeof svc !== "object") continue;
@@ -2739,12 +2740,12 @@ function validateCustomFields(v) {
2739
2740
 
2740
2741
  // src/core/validate/steps/global-utility-guard.ts
2741
2742
  function validateGlobalUtilityGuard(v) {
2742
- var _a, _b, _c;
2743
+ var _a2, _b, _c;
2743
2744
  if (!v.options.globalUtilityGuard) return;
2744
2745
  let hasUtility = false;
2745
2746
  let hasBase = false;
2746
2747
  for (const f of v.fields) {
2747
- for (const o of (_a = f.options) != null ? _a : []) {
2748
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
2748
2749
  if (!isServiceIdRef(o.service_id)) continue;
2749
2750
  const role = (_c = (_b = o.pricing_role) != null ? _b : f.pricing_role) != null ? _c : "base";
2750
2751
  if (role === "base") hasBase = true;
@@ -2766,14 +2767,14 @@ function validateGlobalUtilityGuard(v) {
2766
2767
 
2767
2768
  // src/core/validate/steps/unbound.ts
2768
2769
  function validateUnboundFields(v) {
2769
- var _a, _b;
2770
+ var _a2, _b;
2770
2771
  const boundFieldIds = /* @__PURE__ */ new Set();
2771
2772
  for (const f of v.fields) {
2772
2773
  if (f.bind_id) boundFieldIds.add(f.id);
2773
2774
  }
2774
2775
  const includedByTag = /* @__PURE__ */ new Set();
2775
2776
  for (const t of v.tags) {
2776
- for (const id of (_a = t.includes) != null ? _a : []) includedByTag.add(id);
2777
+ for (const id of (_a2 = t.includes) != null ? _a2 : []) includedByTag.add(id);
2777
2778
  }
2778
2779
  const includedByOption = /* @__PURE__ */ new Set();
2779
2780
  for (const arr of Object.values((_b = v.props.includes_for_buttons) != null ? _b : {})) {
@@ -2842,8 +2843,8 @@ function messageFor(code, d) {
2842
2843
  }
2843
2844
  }
2844
2845
  function validateFallbacks(v) {
2845
- var _a, _b, _c, _d;
2846
- const mode = (_b = (_a = v.options.fallbackSettings) == null ? void 0 : _a.mode) != null ? _b : "strict";
2846
+ var _a2, _b, _c, _d;
2847
+ const mode = (_b = (_a2 = v.options.fallbackSettings) == null ? void 0 : _a2.mode) != null ? _b : "strict";
2847
2848
  if (!v.props.fallbacks) return;
2848
2849
  const diags = collectFailedFallbacks(v.props, (_c = v.options.serviceMap) != null ? _c : {}, {
2849
2850
  ...v.options.fallbackSettings,
@@ -2904,7 +2905,7 @@ function svcSnapshot(serviceMap, sid) {
2904
2905
  };
2905
2906
  }
2906
2907
  function pushItem(out, next) {
2907
- var _a;
2908
+ var _a2;
2908
2909
  const key = `${String(next.serviceId)}|${next.role}`;
2909
2910
  const existing = out.get(key);
2910
2911
  if (!existing) {
@@ -2925,13 +2926,13 @@ function pushItem(out, next) {
2925
2926
  );
2926
2927
  out.set(key, {
2927
2928
  ...existing,
2928
- tagId: (_a = existing.tagId) != null ? _a : next.tagId,
2929
+ tagId: (_a2 = existing.tagId) != null ? _a2 : next.tagId,
2929
2930
  affectedIds: mergedIds
2930
2931
  });
2931
2932
  }
2932
2933
  function fieldRoleOf(f, o) {
2933
- var _a, _b;
2934
- const roleRaw = (_b = (_a = o == null ? void 0 : o.pricing_role) != null ? _a : f.pricing_role) != null ? _b : "base";
2934
+ var _a2, _b;
2935
+ const roleRaw = (_b = (_a2 = o == null ? void 0 : o.pricing_role) != null ? _a2 : f.pricing_role) != null ? _b : "base";
2935
2936
  return roleRaw === "utility" ? "utility" : "base";
2936
2937
  }
2937
2938
  function applyFilterAllowLists(tagId, fieldId, filter) {
@@ -2948,9 +2949,9 @@ function applyFilterAllowLists(tagId, fieldId, filter) {
2948
2949
  return true;
2949
2950
  }
2950
2951
  function collectServiceItems(args) {
2951
- var _a, _b, _c, _d, _e;
2952
+ var _a2, _b, _c, _d, _e;
2952
2953
  const filter = args.filter;
2953
- const roleFilter = (_a = filter == null ? void 0 : filter.role) != null ? _a : "both";
2954
+ const roleFilter = (_a2 = filter == null ? void 0 : filter.role) != null ? _a2 : "both";
2954
2955
  const where = filter == null ? void 0 : filter.where;
2955
2956
  const out = /* @__PURE__ */ new Map();
2956
2957
  const addServiceRef = (ref) => {
@@ -3155,26 +3156,26 @@ function defaultPolicyMessage(rule) {
3155
3156
  return `Policy "${rule.id}" violated`;
3156
3157
  }
3157
3158
  function affectedFromItems(items) {
3158
- var _a;
3159
+ var _a2;
3159
3160
  const ids = [];
3160
3161
  for (const it of items) {
3161
- for (const x of (_a = it.affectedIds) != null ? _a : []) ids.push(x);
3162
+ for (const x of (_a2 = it.affectedIds) != null ? _a2 : []) ids.push(x);
3162
3163
  ids.push(`service:${String(it.serviceId)}`);
3163
3164
  }
3164
3165
  return uniq(ids);
3165
3166
  }
3166
3167
  function visibleGroupNodeIds(tag, fields) {
3167
- var _a;
3168
+ var _a2;
3168
3169
  const ids = [tag.id];
3169
3170
  for (const f of fields) {
3170
- for (const o of (_a = f.options) != null ? _a : []) {
3171
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
3171
3172
  ids.push(o.id);
3172
3173
  }
3173
3174
  }
3174
3175
  return uniq(ids);
3175
3176
  }
3176
3177
  function visibleGroupPrimaries(tag, fields) {
3177
- var _a;
3178
+ var _a2;
3178
3179
  const prim = [];
3179
3180
  const tagSid = tag.service_id;
3180
3181
  if (typeof tagSid === "string" || typeof tagSid === "number" && Number.isFinite(tagSid)) {
@@ -3185,7 +3186,7 @@ function visibleGroupPrimaries(tag, fields) {
3185
3186
  if (typeof fsid === "string" || typeof fsid === "number" && Number.isFinite(fsid)) {
3186
3187
  prim.push(fsid);
3187
3188
  }
3188
- for (const o of (_a = f.options) != null ? _a : []) {
3189
+ for (const o of (_a2 = f.options) != null ? _a2 : []) {
3189
3190
  const osid = o.service_id;
3190
3191
  if (typeof osid === "string" || typeof osid === "number" && Number.isFinite(osid)) {
3191
3192
  prim.push(osid);
@@ -3195,12 +3196,12 @@ function visibleGroupPrimaries(tag, fields) {
3195
3196
  return uniq(prim);
3196
3197
  }
3197
3198
  function applyPolicies(errors, props, serviceMap, policies, fieldsVisibleUnder, tags) {
3198
- var _a, _b, _c, _d, _e;
3199
+ var _a2, _b, _c, _d, _e;
3199
3200
  if (!(policies == null ? void 0 : policies.length)) return;
3200
3201
  const tagById = /* @__PURE__ */ new Map();
3201
3202
  for (const t of tags) tagById.set(t.id, t);
3202
3203
  for (const rule of policies) {
3203
- const projPath = (_a = rule.projection) != null ? _a : "service.id";
3204
+ const projPath = (_a2 = rule.projection) != null ? _a2 : "service.id";
3204
3205
  const severity = stableSeverity(
3205
3206
  rule.severity
3206
3207
  );
@@ -3334,16 +3335,16 @@ function resolveGlobalRatePolicy(options) {
3334
3335
  return normalizeRatePolicy(options.ratePolicy);
3335
3336
  }
3336
3337
  function resolveFallbackSettings(options) {
3337
- var _a;
3338
+ var _a2;
3338
3339
  return {
3339
3340
  ...DEFAULT_FALLBACK_SETTINGS,
3340
- ...(_a = options.fallbackSettings) != null ? _a : {}
3341
+ ...(_a2 = options.fallbackSettings) != null ? _a2 : {}
3341
3342
  };
3342
3343
  }
3343
3344
  function mergeValidatorOptions(defaults = {}, overrides = {}) {
3344
- var _a, _b, _c, _d;
3345
+ var _a2, _b, _c, _d;
3345
3346
  const mergedFallbackSettings = {
3346
- ...(_a = defaults.fallbackSettings) != null ? _a : {},
3347
+ ...(_a2 = defaults.fallbackSettings) != null ? _a2 : {},
3347
3348
  ...(_b = overrides.fallbackSettings) != null ? _b : {}
3348
3349
  };
3349
3350
  return {
@@ -3372,12 +3373,12 @@ function readVisibilitySimOpts(ctx) {
3372
3373
  };
3373
3374
  }
3374
3375
  function validate(props, ctx = {}) {
3375
- var _a, _b, _c;
3376
+ var _a2, _b, _c;
3376
3377
  const options = mergeValidatorOptions({}, ctx);
3377
3378
  const fallbackSettings = resolveFallbackSettings(options);
3378
3379
  const ratePolicy = resolveGlobalRatePolicy(options);
3379
3380
  const errors = [];
3380
- const serviceMap = (_a = options.serviceMap) != null ? _a : {};
3381
+ const serviceMap = (_a2 = options.serviceMap) != null ? _a2 : {};
3381
3382
  const selectedKeys = new Set(
3382
3383
  (_b = options.selectedOptionKeys) != null ? _b : []
3383
3384
  );
@@ -3476,16 +3477,16 @@ var BuilderImpl = class {
3476
3477
  this.options = { ...this.options, ...patch };
3477
3478
  }
3478
3479
  getServiceMap() {
3479
- var _a;
3480
- return (_a = this.options.serviceMap) != null ? _a : {};
3480
+ var _a2;
3481
+ return (_a2 = this.options.serviceMap) != null ? _a2 : {};
3481
3482
  }
3482
3483
  getConstraints() {
3483
- var _a;
3484
+ var _a2;
3484
3485
  const serviceMap = this.getServiceMap();
3485
3486
  const out = /* @__PURE__ */ new Set();
3486
3487
  const guard = /* @__PURE__ */ new Set();
3487
3488
  for (const svc of Object.values(serviceMap)) {
3488
- const flags = (_a = svc.flags) != null ? _a : {};
3489
+ const flags = (_a2 = svc.flags) != null ? _a2 : {};
3489
3490
  for (const flagId of Object.keys(flags)) {
3490
3491
  if (guard.has(flagId)) continue;
3491
3492
  guard.add(flagId);
@@ -3501,7 +3502,7 @@ var BuilderImpl = class {
3501
3502
  }
3502
3503
  /* ───── querying ─────────────────────────────────────────────────────── */
3503
3504
  tree() {
3504
- var _a, _b, _c, _d;
3505
+ var _a2, _b, _c, _d;
3505
3506
  const nodes = [];
3506
3507
  const edges = [];
3507
3508
  const showSet = toStringSet(this.options.showOptionNodes);
@@ -3558,7 +3559,7 @@ var BuilderImpl = class {
3558
3559
  }
3559
3560
  }
3560
3561
  for (const t of this.props.filters) {
3561
- for (const id of (_a = t.includes) != null ? _a : []) {
3562
+ for (const id of (_a2 = t.includes) != null ? _a2 : []) {
3562
3563
  edges.push({ from: t.id, to: id, kind: "include" });
3563
3564
  }
3564
3565
  for (const id of (_b = t.excludes) != null ? _b : []) {
@@ -3568,9 +3569,9 @@ var BuilderImpl = class {
3568
3569
  const incMap = (_c = this.props.includes_for_buttons) != null ? _c : {};
3569
3570
  const excMap = (_d = this.props.excludes_for_buttons) != null ? _d : {};
3570
3571
  const pushButtonEdge = (keyId, targetFieldId, kind) => {
3571
- var _a2;
3572
+ var _a3;
3572
3573
  const owner = this.optionOwnerById.get(keyId);
3573
- const ownerFieldId = (_a2 = owner == null ? void 0 : owner.fieldId) != null ? _a2 : this.fieldById.has(keyId) ? keyId : void 0;
3574
+ const ownerFieldId = (_a3 = owner == null ? void 0 : owner.fieldId) != null ? _a3 : this.fieldById.has(keyId) ? keyId : void 0;
3574
3575
  if (!ownerFieldId) return;
3575
3576
  const fromNode = owner && showSet.has(owner.fieldId) ? keyId : ownerFieldId;
3576
3577
  const meta = owner ? showSet.has(owner.fieldId) ? {
@@ -3596,14 +3597,14 @@ var BuilderImpl = class {
3596
3597
  return { nodes, edges };
3597
3598
  }
3598
3599
  cleanedProps() {
3599
- var _a, _b, _c, _d, _e;
3600
+ var _a2, _b, _c, _d, _e;
3600
3601
  const fieldIds = new Set(this.props.fields.map((f) => f.id));
3601
3602
  const optionIds = /* @__PURE__ */ new Set();
3602
3603
  this.optionOwnerById.forEach((_v, oid) => optionIds.add(oid));
3603
3604
  const includedByTag = /* @__PURE__ */ new Set();
3604
3605
  const excludedAnywhere = /* @__PURE__ */ new Set();
3605
3606
  for (const t of this.props.filters) {
3606
- for (const id of (_a = t.includes) != null ? _a : []) includedByTag.add(id);
3607
+ for (const id of (_a2 = t.includes) != null ? _a2 : []) includedByTag.add(id);
3607
3608
  for (const id of (_b = t.excludes) != null ? _b : []) excludedAnywhere.add(id);
3608
3609
  }
3609
3610
  const incMap = (_c = this.props.includes_for_buttons) != null ? _c : {};
@@ -3634,8 +3635,8 @@ var BuilderImpl = class {
3634
3635
  else if (typeof b === "string") boundIds.add(b);
3635
3636
  }
3636
3637
  const fields = this.props.fields.filter((f) => {
3637
- var _a2;
3638
- const isUtility = ((_a2 = f.pricing_role) != null ? _a2 : "base") === "utility";
3638
+ var _a3;
3639
+ const isUtility = ((_a3 = f.pricing_role) != null ? _a3 : "base") === "utility";
3639
3640
  if (!isUtility) return true;
3640
3641
  const bound = !!f.bind_id;
3641
3642
  const included = includedByTag.has(f.id) || includedByButtons.has(f.id);
@@ -3682,10 +3683,10 @@ var BuilderImpl = class {
3682
3683
  return (0, import_lodash_es2.cloneDeep)(this.options);
3683
3684
  }
3684
3685
  visibleFields(tagId, selectedKeys) {
3685
- var _a;
3686
+ var _a2;
3686
3687
  return visibleFieldIdsUnder(this.props, tagId, {
3687
3688
  selectedKeys: new Set(
3688
- (_a = selectedKeys != null ? selectedKeys : this.options.selectedOptionKeys) != null ? _a : []
3689
+ (_a2 = selectedKeys != null ? selectedKeys : this.options.selectedOptionKeys) != null ? _a2 : []
3689
3690
  )
3690
3691
  });
3691
3692
  }
@@ -3723,10 +3724,10 @@ var DEFAULT_SETTINGS = {
3723
3724
  mode: "strict"
3724
3725
  };
3725
3726
  function collectFailedFallbacks(props, services, settings) {
3726
- var _a, _b, _c;
3727
+ var _a2, _b, _c;
3727
3728
  const s = { ...DEFAULT_SETTINGS, ...settings != null ? settings : {} };
3728
3729
  const out = [];
3729
- const fb = (_a = props.fallbacks) != null ? _a : {};
3730
+ const fb = (_a2 = props.fallbacks) != null ? _a2 : {};
3730
3731
  const primaryRate = (primary) => rateOf(services, primary);
3731
3732
  for (const [nodeId, list] of Object.entries((_b = fb.nodes) != null ? _b : {})) {
3732
3733
  const { primary, tagContexts } = primaryForNode(props, nodeId);
@@ -3834,9 +3835,9 @@ function collectFailedFallbacks(props, services, settings) {
3834
3835
  return out;
3835
3836
  }
3836
3837
  function rateOf(map, id) {
3837
- var _a, _b;
3838
+ var _a2, _b;
3838
3839
  if (id === void 0 || id === null) return void 0;
3839
- return (_b = (_a = getCap(map, id)) == null ? void 0 : _a.rate) != null ? _b : void 0;
3840
+ return (_b = (_a2 = getCap(map, id)) == null ? void 0 : _a2.rate) != null ? _b : void 0;
3840
3841
  }
3841
3842
  function passesRate(policy, primaryRate, candidateRate) {
3842
3843
  if (typeof candidateRate !== "number" || !Number.isFinite(candidateRate)) {
@@ -3855,8 +3856,8 @@ function getCap(map, id) {
3855
3856
  return getServiceCapability(map, id);
3856
3857
  }
3857
3858
  function isCapFlagEnabled(capability, flagId) {
3858
- var _a, _b;
3859
- const fromFlags = (_b = (_a = capability.flags) == null ? void 0 : _a[flagId]) == null ? void 0 : _b.enabled;
3859
+ var _a2, _b;
3860
+ const fromFlags = (_b = (_a2 = capability.flags) == null ? void 0 : _a2[flagId]) == null ? void 0 : _b.enabled;
3860
3861
  if (fromFlags === true) return true;
3861
3862
  if (fromFlags === false) return false;
3862
3863
  const legacy = capability[flagId];
@@ -3895,8 +3896,8 @@ function bindIdsToArray(bind) {
3895
3896
  return Array.isArray(bind) ? bind.slice() : [bind];
3896
3897
  }
3897
3898
  function getEligibleFallbacks(params) {
3898
- var _a, _b, _c, _d, _e, _f;
3899
- const s = { ...DEFAULT_SETTINGS, ...(_a = params.settings) != null ? _a : {} };
3899
+ var _a2, _b, _c, _d, _e, _f;
3900
+ const s = { ...DEFAULT_SETTINGS, ...(_a2 = params.settings) != null ? _a2 : {} };
3900
3901
  const { primary, nodeId, tagId, services } = params;
3901
3902
  const excludes = /* @__PURE__ */ new Set();
3902
3903
  for (const ref of (_b = params.exclude) != null ? _b : []) {
@@ -3942,8 +3943,8 @@ function getEligibleFallbacks(params) {
3942
3943
  }
3943
3944
  if (s.selectionStrategy === "cheapest") {
3944
3945
  eligible.sort((left, right) => {
3945
- var _a2, _b2;
3946
- const leftRate = (_a2 = rateOf(services, left)) != null ? _a2 : Infinity;
3946
+ var _a3, _b2;
3947
+ const leftRate = (_a3 = rateOf(services, left)) != null ? _a3 : Infinity;
3947
3948
  const rightRate = (_b2 = rateOf(services, right)) != null ? _b2 : Infinity;
3948
3949
  return leftRate - rightRate;
3949
3950
  });
@@ -3954,7 +3955,7 @@ function getEligibleFallbacks(params) {
3954
3955
  return eligible;
3955
3956
  }
3956
3957
  function getAssignedServiceIds(params) {
3957
- var _a, _b, _c, _d, _e;
3958
+ var _a2, _b, _c, _d, _e;
3958
3959
  const seen = /* @__PURE__ */ new Set();
3959
3960
  const out = [];
3960
3961
  const push = (value) => {
@@ -3966,7 +3967,7 @@ function getAssignedServiceIds(params) {
3966
3967
  };
3967
3968
  const props = params.props;
3968
3969
  if (props) {
3969
- for (const tag of (_a = props.filters) != null ? _a : []) {
3970
+ for (const tag of (_a2 = props.filters) != null ? _a2 : []) {
3970
3971
  push(tag.service_id);
3971
3972
  }
3972
3973
  for (const field of (_b = props.fields) != null ? _b : []) {
@@ -3998,9 +3999,9 @@ function getFallbackRegistrationInfo(props, nodeId) {
3998
3999
  return { primary, tagContexts };
3999
4000
  }
4000
4001
  function listRegisteredFallbackCandidates(fallbacks, primary, nodeId, services) {
4001
- var _a, _b;
4002
+ var _a2, _b;
4002
4003
  const lists = [];
4003
- if (nodeId && ((_a = fallbacks.nodes) == null ? void 0 : _a[nodeId])) {
4004
+ if (nodeId && ((_a2 = fallbacks.nodes) == null ? void 0 : _a2[nodeId])) {
4004
4005
  lists.push(fallbacks.nodes[nodeId]);
4005
4006
  }
4006
4007
  for (const [registeredPrimary, list] of Object.entries((_b = fallbacks.global) != null ? _b : {})) {
@@ -4023,8 +4024,8 @@ function listServicePoolCandidates(services) {
4023
4024
  return out;
4024
4025
  }
4025
4026
  function getServicePoolCandidateId(key, capability) {
4026
- var _a;
4027
- return (_a = getServiceCapabilityCanonicalRef({ [key]: capability }, key)) != null ? _a : key;
4027
+ var _a2;
4028
+ return (_a2 = getServiceCapabilityCanonicalRef({ [key]: capability }, key)) != null ? _a2 : key;
4028
4029
  }
4029
4030
  function addComparableServiceRef(target, services, value) {
4030
4031
  for (const ref of getComparableServiceRefs(services, value)) {
@@ -4059,10 +4060,10 @@ var toBindList = (b) => {
4059
4060
  return typeof b === "string" ? [b] : [...b];
4060
4061
  };
4061
4062
  function createNodeIndex(builder) {
4062
- var _a, _b, _c, _d;
4063
+ var _a2, _b, _c, _d;
4063
4064
  const props = builder.getProps();
4064
4065
  const nodeMap = builder.getNodeMap();
4065
- const tags = (_a = props.filters) != null ? _a : [];
4066
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
4066
4067
  const fields = (_b = props.fields) != null ? _b : [];
4067
4068
  const tagById = new Map(tags.map((t) => [t.id, t]));
4068
4069
  const fieldById = new Map(fields.map((f) => [f.id, f]));
@@ -4205,12 +4206,12 @@ function createNodeIndex(builder) {
4205
4206
  }
4206
4207
  });
4207
4208
  const getTag = (id) => {
4208
- var _a2, _b2;
4209
+ var _a3, _b2;
4209
4210
  const cached = tagNodeCache.get(id);
4210
4211
  if (cached) return cached;
4211
4212
  const raw = tagById.get(id);
4212
4213
  if (!raw) return void 0;
4213
- const includes = Object.freeze(new Set((_a2 = raw.includes) != null ? _a2 : []));
4214
+ const includes = Object.freeze(new Set((_a3 = raw.includes) != null ? _a3 : []));
4214
4215
  const excludes = Object.freeze(new Set((_b2 = raw.excludes) != null ? _b2 : []));
4215
4216
  const ancestryFn = makeAncestry([id]);
4216
4217
  const node = {
@@ -4225,17 +4226,17 @@ function createNodeIndex(builder) {
4225
4226
  return pid ? getTag(pid) : void 0;
4226
4227
  },
4227
4228
  children() {
4228
- var _a3;
4229
+ var _a4;
4229
4230
  const cachedChildren = tagChildrenCache.get(id);
4230
4231
  if (cachedChildren) return cachedChildren;
4231
- const childIds = (_a3 = childrenById.get(id)) != null ? _a3 : [];
4232
+ const childIds = (_a4 = childrenById.get(id)) != null ? _a4 : [];
4232
4233
  const arr = childIds.map((cid) => getTag(cid)).filter(Boolean);
4233
4234
  const frozen = Object.freeze(arr);
4234
4235
  tagChildrenCache.set(id, frozen);
4235
4236
  return frozen;
4236
4237
  },
4237
4238
  ancestors() {
4238
- var _a3;
4239
+ var _a4;
4239
4240
  const cachedAnc = tagAncestorsCache.get(id);
4240
4241
  if (cachedAnc) return cachedAnc;
4241
4242
  const rows = [];
@@ -4245,7 +4246,7 @@ function createNodeIndex(builder) {
4245
4246
  while (cur && !guard.has(cur)) {
4246
4247
  const n = getTag(cur);
4247
4248
  if (!n) break;
4248
- const p = (_a3 = pathBetween(id, cur)) != null ? _a3 : [id, cur];
4249
+ const p = (_a4 = pathBetween(id, cur)) != null ? _a4 : [id, cur];
4249
4250
  rows.push({ node: n, direct: index === 1, index, path: p });
4250
4251
  guard.add(cur);
4251
4252
  cur = parentById.get(cur);
@@ -4288,13 +4289,13 @@ function createNodeIndex(builder) {
4288
4289
  return node;
4289
4290
  };
4290
4291
  const getField = (id) => {
4291
- var _a2, _b2, _c2, _d2;
4292
+ var _a3, _b2, _c2, _d2;
4292
4293
  const cached = fieldNodeCache.get(id);
4293
4294
  if (cached) return cached;
4294
4295
  const raw = fieldById.get(id);
4295
4296
  if (!raw) return void 0;
4296
4297
  const isButton = raw.button === true;
4297
- const includes = isButton ? Object.freeze(new Set((_b2 = (_a2 = props.includes_for_buttons) == null ? void 0 : _a2[id]) != null ? _b2 : [])) : emptySet;
4298
+ const includes = isButton ? Object.freeze(new Set((_b2 = (_a3 = props.includes_for_buttons) == null ? void 0 : _a3[id]) != null ? _b2 : [])) : emptySet;
4298
4299
  const excludes = isButton ? Object.freeze(new Set((_d2 = (_c2 = props.excludes_for_buttons) == null ? void 0 : _c2[id]) != null ? _d2 : [])) : emptySet;
4299
4300
  const bindIds = () => {
4300
4301
  const cachedBind = fieldBindIdsCache.get(id);
@@ -4340,7 +4341,7 @@ function createNodeIndex(builder) {
4340
4341
  return node;
4341
4342
  };
4342
4343
  const getOption = (id) => {
4343
- var _a2, _b2, _c2, _d2;
4344
+ var _a3, _b2, _c2, _d2;
4344
4345
  const cached = optionNodeCache.get(id);
4345
4346
  if (cached) return cached;
4346
4347
  const raw = optionById.get(id);
@@ -4349,7 +4350,7 @@ function createNodeIndex(builder) {
4349
4350
  const owner = getField(ownerFieldId);
4350
4351
  if (!owner) return void 0;
4351
4352
  const includes = Object.freeze(
4352
- new Set((_b2 = (_a2 = props.includes_for_buttons) == null ? void 0 : _a2[id]) != null ? _b2 : [])
4353
+ new Set((_b2 = (_a3 = props.includes_for_buttons) == null ? void 0 : _a3[id]) != null ? _b2 : [])
4353
4354
  );
4354
4355
  const excludes = Object.freeze(
4355
4356
  new Set((_d2 = (_c2 = props.excludes_for_buttons) == null ? void 0 : _c2[id]) != null ? _d2 : [])
@@ -4384,13 +4385,13 @@ function createNodeIndex(builder) {
4384
4385
  return node;
4385
4386
  };
4386
4387
  const getNode2 = (input) => {
4387
- var _a2, _b2, _c2;
4388
+ var _a3, _b2, _c2;
4388
4389
  const id = typeof input === "object" ? input.id : input;
4389
4390
  const cached = nodeCache.get(id);
4390
4391
  if (cached) return cached;
4391
4392
  const node = nodeMap.get(id);
4392
4393
  if (!node) return mkUnknown(id);
4393
- if (node.kind === "tag") return (_a2 = getTag(id)) != null ? _a2 : mkUnknown(id);
4394
+ if (node.kind === "tag") return (_a3 = getTag(id)) != null ? _a3 : mkUnknown(id);
4394
4395
  if (node.kind == "field") return (_b2 = getField(id)) != null ? _b2 : mkUnknown(id);
4395
4396
  if (node.kind == "option") return (_c2 = getOption(id)) != null ? _c2 : mkUnknown(id);
4396
4397
  return mkUnknown(id);
@@ -4669,8 +4670,8 @@ function compilePolicies(raw) {
4669
4670
 
4670
4671
  // src/core/service-filter.ts
4671
4672
  function filterServicesForVisibleGroup(input, deps) {
4672
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4673
- const svcMap = (_c = (_b = (_a = deps.builder).getServiceMap) == null ? void 0 : _b.call(_a)) != null ? _c : {};
4673
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4674
+ const svcMap = (_c = (_b = (_a2 = deps.builder).getServiceMap) == null ? void 0 : _b.call(_a2)) != null ? _c : {};
4674
4675
  const builderOptions = (_e = (_d = deps.builder).getOptions) == null ? void 0 : _e.call(_d);
4675
4676
  const { context } = input;
4676
4677
  const usedSet = new Set(context.usedServiceIds.map(String));
@@ -4779,7 +4780,7 @@ function evaluatePoliciesRaw(raw, serviceIds, svcMap, tagId, visibleServiceIds)
4779
4780
  };
4780
4781
  }
4781
4782
  function evaluateServicePolicies(rules, svcIds, svcMap, tagId, visibleServiceIds) {
4782
- var _a, _b, _c;
4783
+ var _a2, _b, _c;
4783
4784
  const errors = [];
4784
4785
  const warnings = [];
4785
4786
  if (!rules || !rules.length) return { ok: true, errors, warnings };
@@ -4830,7 +4831,7 @@ function evaluateServicePolicies(rules, svcIds, svcMap, tagId, visibleServiceIds
4830
4831
  ok = true;
4831
4832
  }
4832
4833
  if (!ok) {
4833
- if (((_a = r.severity) != null ? _a : "error") === "error") {
4834
+ if (((_a2 = r.severity) != null ? _a2 : "error") === "error") {
4834
4835
  errors.push((_b = r.id) != null ? _b : "policy_error");
4835
4836
  } else {
4836
4837
  warnings.push((_c = r.id) != null ? _c : "policy_warning");
@@ -4844,10 +4845,10 @@ function scopeServiceIdsForRule(serviceIds, rule, visibleServiceIds) {
4844
4845
  return serviceIds.filter((id) => visibleServiceIds.has(String(id)));
4845
4846
  }
4846
4847
  function collectVisibleServiceIds(builder, tagId, selectedButtons) {
4847
- var _a, _b, _c;
4848
+ var _a2, _b, _c;
4848
4849
  const out = /* @__PURE__ */ new Set();
4849
4850
  const props = builder.getProps();
4850
- const tags = (_a = props.filters) != null ? _a : [];
4851
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
4851
4852
  const fields = (_b = props.fields) != null ? _b : [];
4852
4853
  const tag = tags.find((t) => t.id === tagId);
4853
4854
  if ((tag == null ? void 0 : tag.service_id) != null) out.add(String(tag.service_id));
@@ -4885,10 +4886,10 @@ function toStrSet(v) {
4885
4886
  return s;
4886
4887
  }
4887
4888
  function candidatePassesRateCoherence(builder, serviceMap, tagId, selectedKeys, usedServiceIds, candidateId, ratePolicy) {
4888
- var _a, _b, _c, _d;
4889
+ var _a2, _b, _c, _d;
4889
4890
  if (usedServiceIds.length === 0) return true;
4890
4891
  const props = builder.getProps();
4891
- const baseFields = (_a = props.fields) != null ? _a : [];
4892
+ const baseFields = (_a2 = props.fields) != null ? _a2 : [];
4892
4893
  const candidateFieldId = syntheticServiceFieldId("candidate", candidateId, 0);
4893
4894
  const syntheticFields = [
4894
4895
  ...usedServiceIds.map((serviceId, index) => ({
@@ -4965,10 +4966,10 @@ function syntheticServiceFieldId(kind, serviceId, index) {
4965
4966
  return `__service_filter_${kind}__:${index}:${String(serviceId)}`;
4966
4967
  }
4967
4968
  function rateIssueAffectsCandidate(error, candidateId, candidateFieldId, primaryAnchorId) {
4968
- var _a, _b, _c, _d;
4969
+ var _a2, _b, _c, _d;
4969
4970
  if (error.code !== "rate_coherence_violation") return false;
4970
4971
  const candidateKey = String(candidateId);
4971
- const details = (_a = error.details) != null ? _a : {};
4972
+ const details = (_a2 = error.details) != null ? _a2 : {};
4972
4973
  const anchorKey = primaryAnchorId == null ? void 0 : String(primaryAnchorId);
4973
4974
  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;
4974
4975
  if (primaryMatchesAnchor && ((_d = details.affectedServiceIds) == null ? void 0 : _d.some(
@@ -4988,7 +4989,7 @@ function rateIssueAffectsCandidate(error, candidateId, candidateFieldId, primary
4988
4989
 
4989
4990
  // src/utils/prune-fallbacks.ts
4990
4991
  function pruneInvalidNodeFallbacks(props, services, settings) {
4991
- var _a, _b;
4992
+ var _a2, _b;
4992
4993
  const fb = props.fallbacks;
4993
4994
  if (!(fb == null ? void 0 : fb.nodes) || Object.keys(fb.nodes).length === 0) {
4994
4995
  return { props, removed: [] };
@@ -5033,7 +5034,7 @@ function pruneInvalidNodeFallbacks(props, services, settings) {
5033
5034
  const prunedNodes = {};
5034
5035
  const removed = [];
5035
5036
  for (const [nodeId, list] of Object.entries(fb.nodes)) {
5036
- const contexts = (_a = nodeContexts.get(nodeId)) != null ? _a : [];
5037
+ const contexts = (_a2 = nodeContexts.get(nodeId)) != null ? _a2 : [];
5037
5038
  const totalContexts = Math.max(1, contexts.length);
5038
5039
  const keep = [];
5039
5040
  for (const cand of list) {
@@ -5074,8 +5075,8 @@ function toBindArray(bind) {
5074
5075
 
5075
5076
  // src/utils/build-order-snapshot.ts
5076
5077
  function buildOrderSnapshot(props, builder, selection, services, settings = {}) {
5077
- var _a, _b, _c, _d, _e, _f, _g, _h;
5078
- const mode = (_a = settings.mode) != null ? _a : "prod";
5078
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
5079
+ const mode = (_a2 = settings.mode) != null ? _a2 : "prod";
5079
5080
  const hostDefaultQty = Number.isFinite(
5080
5081
  (_b = settings.hostDefaultQuantity) != null ? _b : 1
5081
5082
  ) ? settings.hostDefaultQuantity : 1;
@@ -5101,8 +5102,8 @@ function buildOrderSnapshot(props, builder, selection, services, settings = {})
5101
5102
  );
5102
5103
  const tagConstraints = (_h = (_g = tagById.get(tagId)) == null ? void 0 : _g.constraints) != null ? _h : void 0;
5103
5104
  const selectionFields = visibleFieldIds.map((fid) => fieldById.get(fid)).filter((f) => !!f).map((f) => {
5104
- var _a2;
5105
- const optIds = isOptionBased(f) ? (_a2 = selection.optionSelectionsByFieldId[f.id]) != null ? _a2 : [] : void 0;
5105
+ var _a3;
5106
+ const optIds = isOptionBased(f) ? (_a3 = selection.optionSelectionsByFieldId[f.id]) != null ? _a3 : [] : void 0;
5106
5107
  return {
5107
5108
  id: f.id,
5108
5109
  type: String(f.type),
@@ -5244,12 +5245,12 @@ function buildInputs(visibleFieldIds, fieldById, selection) {
5244
5245
  return { formValues, selections };
5245
5246
  }
5246
5247
  function resolveQuantity(visibleFieldIds, fieldById, tagById, selection, tagId, hostDefault) {
5247
- var _a;
5248
+ var _a2;
5248
5249
  for (const fid of visibleFieldIds) {
5249
5250
  const f = fieldById.get(fid);
5250
5251
  if (!f) continue;
5251
5252
  const rule = readQuantityRule(
5252
- (_a = f.meta) == null ? void 0 : _a.quantity
5253
+ (_a2 = f.meta) == null ? void 0 : _a2.quantity
5253
5254
  );
5254
5255
  if (!rule) continue;
5255
5256
  const raw = selection.formValuesByFieldId[fid];
@@ -5359,12 +5360,12 @@ function applyClamp(value, clamp2) {
5359
5360
  return next;
5360
5361
  }
5361
5362
  function resolveNodeDefaultQuantity(visibleFieldIds, fieldById, tagById, selection, tagId) {
5362
- var _a, _b, _c, _d;
5363
+ var _a2, _b, _c, _d;
5363
5364
  const optionVisit = buildOptionVisitOrder(selection, fieldById);
5364
5365
  for (const { fieldId, optionId } of optionVisit) {
5365
5366
  if (!visibleFieldIds.includes(fieldId)) continue;
5366
5367
  const field = fieldById.get(fieldId);
5367
- const option = (_a = field == null ? void 0 : field.options) == null ? void 0 : _a.find((item) => item.id === optionId);
5368
+ const option = (_a2 = field == null ? void 0 : field.options) == null ? void 0 : _a2.find((item) => item.id === optionId);
5368
5369
  const quantityDefault = readQuantityDefault(
5369
5370
  (_b = option == null ? void 0 : option.meta) == null ? void 0 : _b.quantityDefault
5370
5371
  );
@@ -5405,7 +5406,7 @@ function readQuantityDefault(value) {
5405
5406
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
5406
5407
  }
5407
5408
  function resolveServices(tagId, visibleFieldIds, selection, tagById, fieldById) {
5408
- var _a;
5409
+ var _a2;
5409
5410
  const serviceMap = {};
5410
5411
  const ordered = [];
5411
5412
  const tag = tagById.get(tagId);
@@ -5422,7 +5423,7 @@ function resolveServices(tagId, visibleFieldIds, selection, tagById, fieldById)
5422
5423
  if (!f || !Array.isArray(f.options)) continue;
5423
5424
  const opt = f.options.find((o) => o.id === optionId);
5424
5425
  if (!opt) continue;
5425
- const role = (_a = opt.pricing_role) != null ? _a : "base";
5426
+ const role = (_a2 = opt.pricing_role) != null ? _a2 : "base";
5426
5427
  const sid = opt.service_id;
5427
5428
  if (role === "utility") continue;
5428
5429
  if (sid !== void 0) {
@@ -5446,13 +5447,13 @@ function resolveServices(tagId, visibleFieldIds, selection, tagById, fieldById)
5446
5447
  return { serviceMap, servicesList };
5447
5448
  }
5448
5449
  function buildOptionVisitOrder(selection, fieldById) {
5449
- var _a;
5450
+ var _a2;
5450
5451
  if (selection.optionTraversalOrder && selection.optionTraversalOrder.length) {
5451
5452
  return selection.optionTraversalOrder.slice();
5452
5453
  }
5453
5454
  const out = [];
5454
5455
  for (const [fid, optIds] of Object.entries(
5455
- (_a = selection.optionSelectionsByFieldId) != null ? _a : {}
5456
+ (_a2 = selection.optionSelectionsByFieldId) != null ? _a2 : {}
5456
5457
  )) {
5457
5458
  const f = fieldById.get(fid);
5458
5459
  if (!f) continue;
@@ -5477,7 +5478,7 @@ function dedupeByString(arr) {
5477
5478
  return out;
5478
5479
  }
5479
5480
  function pruneFallbacksConservative(fallbacks, env, svcMap, policy) {
5480
- var _a, _b;
5481
+ var _a2, _b;
5481
5482
  if (!fallbacks) return { pruned: void 0, original: void 0 };
5482
5483
  try {
5483
5484
  const { props: prunedProps } = pruneInvalidNodeFallbacks(
@@ -5496,7 +5497,7 @@ function pruneFallbacksConservative(fallbacks, env, svcMap, policy) {
5496
5497
  };
5497
5498
  } catch {
5498
5499
  const out = {};
5499
- const requireFit = (_a = policy.requireConstraintFit) != null ? _a : true;
5500
+ const requireFit = (_a2 = policy.requireConstraintFit) != null ? _a2 : true;
5500
5501
  if (fallbacks.nodes) {
5501
5502
  const keptNodes = {};
5502
5503
  for (const [nodeId, candidates] of Object.entries(
@@ -5545,12 +5546,12 @@ function isFiniteNumber2(v) {
5545
5546
  return typeof v === "number" && Number.isFinite(v);
5546
5547
  }
5547
5548
  function collectUtilityLineItems(visibleFieldIds, fieldById, selection, quantity) {
5548
- var _a, _b, _c, _d, _e;
5549
+ var _a2, _b, _c, _d, _e;
5549
5550
  const items = [];
5550
5551
  for (const fid of visibleFieldIds) {
5551
5552
  const f = fieldById.get(fid);
5552
5553
  if (!f) continue;
5553
- const isUtilityField = ((_a = f.pricing_role) != null ? _a : "base") === "utility";
5554
+ const isUtilityField = ((_a2 = f.pricing_role) != null ? _a2 : "base") === "utility";
5554
5555
  const marker = readUtilityMarker((_b = f.meta) == null ? void 0 : _b.utility);
5555
5556
  if (isUtilityField && marker) {
5556
5557
  const val = selection.formValuesByFieldId[f.id];
@@ -5607,7 +5608,7 @@ function readUtilityMarker(v) {
5607
5608
  return out;
5608
5609
  }
5609
5610
  function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5610
- var _a, _b;
5611
+ var _a2, _b;
5611
5612
  const base = {
5612
5613
  nodeId,
5613
5614
  mode: marker.mode,
@@ -5617,7 +5618,7 @@ function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5617
5618
  inputs: { quantity }
5618
5619
  };
5619
5620
  if (marker.mode === "per_value") {
5620
- base.inputs.valueBy = (_a = marker.valueBy) != null ? _a : "value";
5621
+ base.inputs.valueBy = (_a2 = marker.valueBy) != null ? _a2 : "value";
5621
5622
  if (marker.valueBy === "length") {
5622
5623
  base.inputs.value = Array.isArray(value) ? value.length : typeof value === "string" ? value.length : 0;
5623
5624
  } else {
@@ -5627,7 +5628,7 @@ function buildUtilityItemFromMarker(nodeId, marker, quantity, value) {
5627
5628
  return base;
5628
5629
  }
5629
5630
  function buildNodeContexts(tagId, visibleFieldIds, fieldById, selection) {
5630
- var _a;
5631
+ var _a2;
5631
5632
  const ctx = {};
5632
5633
  ctx[tagId] = tagId;
5633
5634
  for (const fid of visibleFieldIds) {
@@ -5635,7 +5636,7 @@ function buildNodeContexts(tagId, visibleFieldIds, fieldById, selection) {
5635
5636
  if (!f) continue;
5636
5637
  const binds = normalizeBindIds(f.bind_id);
5637
5638
  const applicable = binds.has(tagId);
5638
- const selectedOptIds = (_a = selection.optionSelectionsByFieldId[fid]) != null ? _a : [];
5639
+ const selectedOptIds = (_a2 = selection.optionSelectionsByFieldId[fid]) != null ? _a2 : [];
5639
5640
  for (const oid of selectedOptIds) {
5640
5641
  ctx[oid] = applicable ? tagId : null;
5641
5642
  }
@@ -5690,8 +5691,8 @@ function buildDevWarnings(props, svcMap, _tagId, _snapshotServiceMap, originalFa
5690
5691
  return out;
5691
5692
  }
5692
5693
  function toSnapshotPolicy(settings) {
5693
- var _a;
5694
- const requireConstraintFit = (_a = settings.requireConstraintFit) != null ? _a : true;
5694
+ var _a2;
5695
+ const requireConstraintFit = (_a2 = settings.requireConstraintFit) != null ? _a2 : true;
5695
5696
  const rp = normalizeRatePolicy(settings.ratePolicy);
5696
5697
  return { ratePolicy: rp, requireConstraintFit };
5697
5698
  }
@@ -5716,12 +5717,12 @@ function resolveMinMax(servicesList, services) {
5716
5717
 
5717
5718
  // src/core/fallback-editor.ts
5718
5719
  function createFallbackEditor(options = {}) {
5719
- var _a, _b;
5720
+ var _a2, _b;
5720
5721
  const original = cloneFallbacks(options.fallbacks);
5721
5722
  let current = cloneFallbacks(options.fallbacks);
5722
5723
  const props = options.props;
5723
5724
  const snapshot = options.snapshot;
5724
- const services = (_a = options.services) != null ? _a : {};
5725
+ const services = (_a2 = options.services) != null ? _a2 : {};
5725
5726
  const settings = (_b = options.settings) != null ? _b : {};
5726
5727
  function state() {
5727
5728
  return {
@@ -5738,9 +5739,9 @@ function createFallbackEditor(options = {}) {
5738
5739
  return state();
5739
5740
  }
5740
5741
  function get(serviceId) {
5741
- var _a2, _b2;
5742
+ var _a3, _b2;
5742
5743
  const out = [];
5743
- for (const [primary, list] of Object.entries((_a2 = current.global) != null ? _a2 : {})) {
5744
+ for (const [primary, list] of Object.entries((_a3 = current.global) != null ? _a3 : {})) {
5744
5745
  if (String(primary) !== String(serviceId)) continue;
5745
5746
  out.push({
5746
5747
  scope: "global",
@@ -5762,14 +5763,14 @@ function createFallbackEditor(options = {}) {
5762
5763
  return out;
5763
5764
  }
5764
5765
  function getScope(context) {
5765
- var _a2, _b2, _c, _d;
5766
+ var _a3, _b2, _c, _d;
5766
5767
  if (context.scope === "global") {
5767
- return [...(_b2 = (_a2 = current.global) == null ? void 0 : _a2[context.primary]) != null ? _b2 : []];
5768
+ return [...(_b2 = (_a3 = current.global) == null ? void 0 : _a3[context.primary]) != null ? _b2 : []];
5768
5769
  }
5769
5770
  return [...(_d = (_c = current.nodes) == null ? void 0 : _c[context.nodeId]) != null ? _d : []];
5770
5771
  }
5771
5772
  function check(context, candidates) {
5772
- var _a2, _b2;
5773
+ var _a3, _b2;
5773
5774
  const normalized = normalizeCandidateList(
5774
5775
  candidates != null ? candidates : getScope(context),
5775
5776
  true
@@ -5788,7 +5789,7 @@ function createFallbackEditor(options = {}) {
5788
5789
  }
5789
5790
  const tempFallbacks = cloneFallbacks(current);
5790
5791
  if (context.scope === "global") {
5791
- (_a2 = tempFallbacks.global) != null ? _a2 : tempFallbacks.global = {};
5792
+ (_a3 = tempFallbacks.global) != null ? _a3 : tempFallbacks.global = {};
5792
5793
  if (normalized.length)
5793
5794
  tempFallbacks.global[context.primary] = normalized;
5794
5795
  else delete tempFallbacks.global[context.primary];
@@ -5907,9 +5908,9 @@ function createFallbackEditor(options = {}) {
5907
5908
  return writeScope(context, []);
5908
5909
  }
5909
5910
  function eligible(context, opt) {
5910
- var _a2, _b2;
5911
+ var _a3, _b2;
5911
5912
  if (!props) return [];
5912
- const source = (_a2 = opt == null ? void 0 : opt.source) != null ? _a2 : "all_services";
5913
+ const source = (_a3 = opt == null ? void 0 : opt.source) != null ? _a3 : "all_services";
5913
5914
  const exclude2 = normalizeCandidateList(
5914
5915
  [
5915
5916
  ...(_b2 = opt == null ? void 0 : opt.exclude) != null ? _b2 : [],
@@ -5954,10 +5955,10 @@ function createFallbackEditor(options = {}) {
5954
5955
  });
5955
5956
  }
5956
5957
  function writeScope(context, nextList) {
5957
- var _a2, _b2;
5958
+ var _a3, _b2;
5958
5959
  const next = cloneFallbacks(current);
5959
5960
  if (context.scope === "global") {
5960
- (_a2 = next.global) != null ? _a2 : next.global = {};
5961
+ (_a3 = next.global) != null ? _a3 : next.global = {};
5961
5962
  if (nextList.length) {
5962
5963
  next.global[context.primary] = [...nextList];
5963
5964
  } else {
@@ -6047,9 +6048,9 @@ function getNodeRegistrationInfo(props, nodeId) {
6047
6048
  };
6048
6049
  }
6049
6050
  function findOptionOwner(fields, optionId) {
6050
- var _a;
6051
+ var _a2;
6051
6052
  for (const field of fields) {
6052
- for (const option of (_a = field.options) != null ? _a : []) {
6053
+ for (const option of (_a2 = field.options) != null ? _a2 : []) {
6053
6054
  if (option.id === optionId) return { field, option };
6054
6055
  }
6055
6056
  }
@@ -6060,8 +6061,8 @@ function bindIdsToArray2(v) {
6060
6061
  return v ? [v] : [];
6061
6062
  }
6062
6063
  function resolveNodeTagContext(params) {
6063
- var _a, _b, _c;
6064
- const nodeContexts = (_c = (_b = (_a = params.snapshot) == null ? void 0 : _a.meta) == null ? void 0 : _b.context) == null ? void 0 : _c.nodeContexts;
6064
+ var _a2, _b, _c;
6065
+ const nodeContexts = (_c = (_b = (_a2 = params.snapshot) == null ? void 0 : _a2.meta) == null ? void 0 : _b.context) == null ? void 0 : _c.nodeContexts;
6065
6066
  if (nodeContexts && Object.prototype.hasOwnProperty.call(nodeContexts, params.nodeId)) {
6066
6067
  const tagId = nodeContexts[params.nodeId];
6067
6068
  return typeof tagId === "string" && tagId.trim().length > 0 ? tagId : void 0;
@@ -6089,10 +6090,10 @@ function mapDiagReason(reason) {
6089
6090
 
6090
6091
  // src/react/canvas/editor/editor-ids.ts
6091
6092
  function uniqueId(ctx, base) {
6092
- var _a, _b;
6093
+ var _a2, _b;
6093
6094
  const props = ctx.getProps();
6094
6095
  const taken = /* @__PURE__ */ new Set([
6095
- ...((_a = props.filters) != null ? _a : []).map((t) => t.id),
6096
+ ...((_a2 = props.filters) != null ? _a2 : []).map((t) => t.id),
6096
6097
  ...((_b = props.fields) != null ? _b : []).map((f) => f.id)
6097
6098
  ]);
6098
6099
  let candidate = nextCopyId(base);
@@ -6100,9 +6101,9 @@ function uniqueId(ctx, base) {
6100
6101
  return candidate;
6101
6102
  }
6102
6103
  function uniqueOptionId(ctx, fieldId, base) {
6103
- var _a, _b;
6104
+ var _a2, _b;
6104
6105
  const props = ctx.getProps();
6105
- const fld = ((_a = props.fields) != null ? _a : []).find((f) => f.id === fieldId);
6106
+ const fld = ((_a2 = props.fields) != null ? _a2 : []).find((f) => f.id === fieldId);
6106
6107
  const taken = new Set(((_b = fld == null ? void 0 : fld.options) != null ? _b : []).map((o) => o.id));
6107
6108
  let candidate = base;
6108
6109
  if (taken.has(candidate)) candidate = nextCopyId(candidate);
@@ -6110,14 +6111,14 @@ function uniqueOptionId(ctx, fieldId, base) {
6110
6111
  return candidate;
6111
6112
  }
6112
6113
  function genId(ctx, prefix) {
6113
- var _a, _b, _c;
6114
+ var _a2, _b, _c;
6114
6115
  const props = ctx.getProps();
6115
6116
  const taken = /* @__PURE__ */ new Set([
6116
- ...((_a = props.filters) != null ? _a : []).map((t) => t.id),
6117
+ ...((_a2 = props.filters) != null ? _a2 : []).map((t) => t.id),
6117
6118
  ...((_b = props.fields) != null ? _b : []).map((f) => f.id),
6118
6119
  ...((_c = props.fields) != null ? _c : []).flatMap((f) => {
6119
- var _a2, _b2;
6120
- return (_b2 = (_a2 = f.options) == null ? void 0 : _a2.map((o) => o.id)) != null ? _b2 : [];
6120
+ var _a3, _b2;
6121
+ return (_b2 = (_a3 = f.options) == null ? void 0 : _a3.map((o) => o.id)) != null ? _b2 : [];
6121
6122
  })
6122
6123
  ]);
6123
6124
  for (let i = 1; i < 1e4; i++) {
@@ -6164,13 +6165,7 @@ function duplicate(ctx, ref, opts = {}) {
6164
6165
  try {
6165
6166
  let newId = "";
6166
6167
  ctx.transact("duplicate", () => {
6167
- if (ref.kind === "tag") {
6168
- newId = duplicateTag(ctx, ref.id, opts);
6169
- } else if (ref.kind === "field") {
6170
- newId = duplicateField(ctx, ref.id, opts);
6171
- } else {
6172
- newId = duplicateOption(ctx, ref.fieldId, ref.id, opts);
6173
- }
6168
+ newId = duplicateInPlace(ctx, ref, opts);
6174
6169
  });
6175
6170
  return newId;
6176
6171
  } catch (err) {
@@ -6178,22 +6173,90 @@ function duplicate(ctx, ref, opts = {}) {
6178
6173
  throw err;
6179
6174
  }
6180
6175
  }
6176
+ function duplicateMany(ctx, ids, opts = {}) {
6177
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
6178
+ if (!ordered.length) return [];
6179
+ const snapBefore = ctx.makeSnapshot("duplicateMany:before");
6180
+ try {
6181
+ const created = [];
6182
+ ctx.transact("duplicateMany", () => {
6183
+ var _a2, _b, _c;
6184
+ const props = ctx.getProps();
6185
+ const selectedFields = /* @__PURE__ */ new Set();
6186
+ for (const id of ordered) {
6187
+ if (ctx.isFieldId(id) && ((_a2 = props.fields) != null ? _a2 : []).some((f) => f.id === id)) {
6188
+ selectedFields.add(id);
6189
+ }
6190
+ }
6191
+ for (const id of ordered) {
6192
+ if (ctx.isTagId(id)) {
6193
+ if (!((_b = ctx.getProps().filters) != null ? _b : []).some((t) => t.id === id)) continue;
6194
+ created.push(
6195
+ duplicateInPlace(ctx, { kind: "tag", id }, opts)
6196
+ );
6197
+ continue;
6198
+ }
6199
+ if (ctx.isFieldId(id)) {
6200
+ if (!((_c = ctx.getProps().fields) != null ? _c : []).some((f) => f.id === id)) continue;
6201
+ created.push(
6202
+ duplicateInPlace(ctx, { kind: "field", id }, opts)
6203
+ );
6204
+ continue;
6205
+ }
6206
+ if (ctx.isOptionId(id)) {
6207
+ const owner = ownerFieldOfOption(ctx.getProps(), id);
6208
+ if (!owner) continue;
6209
+ if (selectedFields.has(owner.fieldId)) continue;
6210
+ created.push(
6211
+ duplicateInPlace(
6212
+ ctx,
6213
+ { kind: "option", fieldId: owner.fieldId, id },
6214
+ opts
6215
+ )
6216
+ );
6217
+ }
6218
+ }
6219
+ });
6220
+ return created;
6221
+ } catch (err) {
6222
+ ctx.loadSnapshot(snapBefore, "undo");
6223
+ throw err;
6224
+ }
6225
+ }
6226
+ function duplicateInPlace(ctx, ref, opts = {}) {
6227
+ if (ref.kind === "tag") {
6228
+ return duplicateTag(ctx, ref.id, opts);
6229
+ }
6230
+ if (ref.kind === "field") {
6231
+ return duplicateField(ctx, ref.id, opts);
6232
+ }
6233
+ return duplicateOption(ctx, ref.fieldId, ref.id, opts);
6234
+ }
6235
+ function ownerFieldOfOption(props, optionId) {
6236
+ var _a2, _b;
6237
+ for (const field of (_a2 = props.fields) != null ? _a2 : []) {
6238
+ if (((_b = field.options) != null ? _b : []).some((o) => o.id === optionId)) {
6239
+ return { fieldId: field.id };
6240
+ }
6241
+ }
6242
+ return null;
6243
+ }
6181
6244
  function duplicateTag(ctx, tagId, opts) {
6182
- var _a, _b, _c, _d;
6245
+ var _a2, _b, _c, _d;
6183
6246
  const props = ctx.getProps();
6184
- const tags = (_a = props.filters) != null ? _a : [];
6247
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
6185
6248
  const src = tags.find((t) => t.id === tagId);
6186
6249
  if (!src) throw new Error(`Tag not found: ${tagId}`);
6187
6250
  const id = (_b = opts.id) != null ? _b : ctx.uniqueId(src.id);
6188
6251
  const label = ((_c = opts.labelStrategy) != null ? _c : nextCopyLabel)((_d = src.label) != null ? _d : id);
6189
6252
  if (!opts.withChildren) {
6190
6253
  ctx.patchProps((p) => {
6191
- var _a2;
6254
+ var _a3;
6192
6255
  const clone2 = { ...src, id, label };
6193
6256
  clone2.bind_id = src.bind_id;
6194
6257
  clone2.constraints_overrides = void 0;
6195
6258
  clone2.constraints_origin = void 0;
6196
- const arr = (_a2 = p.filters) != null ? _a2 : [];
6259
+ const arr = (_a3 = p.filters) != null ? _a3 : [];
6197
6260
  const idx = arr.findIndex((t) => t.id === tagId);
6198
6261
  arr.splice(idx + 1, 0, clone2);
6199
6262
  p.filters = arr;
@@ -6213,18 +6276,18 @@ function duplicateTag(ctx, tagId, opts) {
6213
6276
  idMap.set(n.id, n.id === src.id ? id : ctx.uniqueId(n.id));
6214
6277
  }
6215
6278
  const clones = subtree.map((n) => {
6216
- var _a2, _b2, _c2;
6279
+ var _a3, _b2, _c2;
6217
6280
  const cloned = { ...n };
6218
6281
  cloned.id = idMap.get(n.id);
6219
- cloned.label = n.id === src.id ? label : ((_a2 = opts.labelStrategy) != null ? _a2 : nextCopyLabel)((_b2 = n.label) != null ? _b2 : n.id);
6282
+ cloned.label = n.id === src.id ? label : ((_a3 = opts.labelStrategy) != null ? _a3 : nextCopyLabel)((_b2 = n.label) != null ? _b2 : n.id);
6220
6283
  cloned.bind_id = n.bind_id ? (_c2 = idMap.get(n.bind_id)) != null ? _c2 : n.bind_id : void 0;
6221
6284
  cloned.constraints_origin = void 0;
6222
6285
  cloned.constraints_overrides = void 0;
6223
6286
  return cloned;
6224
6287
  });
6225
6288
  ctx.patchProps((p) => {
6226
- var _a2;
6227
- const arr = (_a2 = p.filters) != null ? _a2 : [];
6289
+ var _a3;
6290
+ const arr = (_a3 = p.filters) != null ? _a3 : [];
6228
6291
  const rootIdx = arr.findIndex((t) => t.id === tagId);
6229
6292
  arr.splice(rootIdx + 1, 0, clones[0]);
6230
6293
  for (const c of clones.slice(1)) arr.push(c);
@@ -6233,27 +6296,27 @@ function duplicateTag(ctx, tagId, opts) {
6233
6296
  return id;
6234
6297
  }
6235
6298
  function duplicateField(ctx, fieldId, opts) {
6236
- var _a, _b, _c, _d, _e, _f, _g;
6299
+ var _a2, _b, _c, _d, _e, _f, _g;
6237
6300
  const props = ctx.getProps();
6238
- const fields = (_a = props.fields) != null ? _a : [];
6301
+ const fields = (_a2 = props.fields) != null ? _a2 : [];
6239
6302
  const src = fields.find((f) => f.id === fieldId);
6240
6303
  if (!src) throw new Error(`Field not found: ${fieldId}`);
6241
6304
  const id = (_b = opts.id) != null ? _b : ctx.uniqueId(src.id);
6242
6305
  const label = ((_c = opts.labelStrategy) != null ? _c : nextCopyLabel)((_d = src.label) != null ? _d : id);
6243
6306
  const name = opts.nameStrategy ? opts.nameStrategy(src.name) : nextCopyName(src.name);
6244
6307
  const optId = (old) => {
6245
- var _a2;
6308
+ var _a3;
6246
6309
  return ctx.uniqueOptionId(
6247
6310
  id,
6248
- ((_a2 = opts.optionIdStrategy) != null ? _a2 : defaultOptionIdStrategy)(old)
6311
+ ((_a3 = opts.optionIdStrategy) != null ? _a3 : defaultOptionIdStrategy)(old)
6249
6312
  );
6250
6313
  };
6251
6314
  const clonedOptions = ((_e = src.options) != null ? _e : []).map((o) => {
6252
- var _a2, _b2;
6315
+ var _a3, _b2;
6253
6316
  return {
6254
6317
  ...o,
6255
6318
  id: optId(o.id),
6256
- label: ((_a2 = opts.labelStrategy) != null ? _a2 : nextCopyLabel)((_b2 = o.label) != null ? _b2 : o.id)
6319
+ label: ((_a3 = opts.labelStrategy) != null ? _a3 : nextCopyLabel)((_b2 = o.label) != null ? _b2 : o.id)
6257
6320
  };
6258
6321
  });
6259
6322
  const cloned = {
@@ -6266,13 +6329,13 @@ function duplicateField(ctx, fieldId, opts) {
6266
6329
  };
6267
6330
  const optionIdMap = /* @__PURE__ */ new Map();
6268
6331
  ((_g = src.options) != null ? _g : []).forEach((o, i) => {
6269
- var _a2, _b2;
6270
- const newOptId = (_b2 = (_a2 = clonedOptions[i]) == null ? void 0 : _a2.id) != null ? _b2 : o.id;
6332
+ var _a3, _b2;
6333
+ const newOptId = (_b2 = (_a3 = clonedOptions[i]) == null ? void 0 : _a3.id) != null ? _b2 : o.id;
6271
6334
  optionIdMap.set(o.id, newOptId);
6272
6335
  });
6273
6336
  ctx.patchProps((p) => {
6274
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2;
6275
- const arr = (_a2 = p.fields) != null ? _a2 : [];
6337
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2;
6338
+ const arr = (_a3 = p.fields) != null ? _a3 : [];
6276
6339
  const idx = arr.findIndex((f) => f.id === fieldId);
6277
6340
  arr.splice(idx + 1, 0, cloned);
6278
6341
  p.fields = arr;
@@ -6320,9 +6383,9 @@ function duplicateField(ctx, fieldId, opts) {
6320
6383
  return id;
6321
6384
  }
6322
6385
  function duplicateOption(ctx, fieldId, optionId, opts) {
6323
- var _a, _b, _c, _d, _e, _f;
6386
+ var _a2, _b, _c, _d, _e, _f;
6324
6387
  const props = ctx.getProps();
6325
- const fields = (_a = props.fields) != null ? _a : [];
6388
+ const fields = (_a2 = props.fields) != null ? _a2 : [];
6326
6389
  const f = fields.find((x) => x.id === fieldId);
6327
6390
  if (!f) throw new Error(`Field not found: ${fieldId}`);
6328
6391
  const optIdx = ((_b = f.options) != null ? _b : []).findIndex((o) => o.id === optionId);
@@ -6336,8 +6399,8 @@ function duplicateOption(ctx, fieldId, optionId, opts) {
6336
6399
  );
6337
6400
  const newLabel = ((_e = opts.labelStrategy) != null ? _e : nextCopyLabel)((_f = src.label) != null ? _f : src.id);
6338
6401
  ctx.patchProps((p) => {
6339
- var _a2, _b2, _c2;
6340
- const fld = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6402
+ var _a3, _b2, _c2;
6403
+ const fld = ((_a3 = p.fields) != null ? _a3 : []).find((x) => x.id === fieldId);
6341
6404
  const arr = (_b2 = fld.options) != null ? _b2 : [];
6342
6405
  const clone2 = { ...src, id: newId, label: newLabel };
6343
6406
  arr.splice(optIdx + 1, 0, clone2);
@@ -6362,8 +6425,8 @@ function duplicateOption(ctx, fieldId, optionId, opts) {
6362
6425
 
6363
6426
  // src/react/canvas/editor/editor-notices.ts
6364
6427
  function genNoticeId(ctx) {
6365
- var _a;
6366
- const taken = new Set(((_a = ctx.getProps().notices) != null ? _a : []).map((n) => n.id));
6428
+ var _a2;
6429
+ const taken = new Set(((_a2 = ctx.getProps().notices) != null ? _a2 : []).map((n) => n.id));
6367
6430
  for (let i = 1; i < 1e4; i++) {
6368
6431
  const id = `n:${i}`;
6369
6432
  if (!taken.has(id)) return id;
@@ -6371,13 +6434,13 @@ function genNoticeId(ctx) {
6371
6434
  throw new Error("Unable to generate notice id");
6372
6435
  }
6373
6436
  function addNotice(ctx, input) {
6374
- var _a;
6375
- const id = (_a = input.id) != null ? _a : genNoticeId(ctx);
6437
+ var _a2;
6438
+ const id = (_a2 = input.id) != null ? _a2 : genNoticeId(ctx);
6376
6439
  ctx.exec({
6377
6440
  name: "addNotice",
6378
6441
  do: () => ctx.patchProps((p) => {
6379
- var _a2;
6380
- const notices = (_a2 = p.notices) != null ? _a2 : p.notices = [];
6442
+ var _a3;
6443
+ const notices = (_a3 = p.notices) != null ? _a3 : p.notices = [];
6381
6444
  if (notices.some((n) => n.id === id)) {
6382
6445
  throw new Error(`Notice id '${id}' already exists`);
6383
6446
  }
@@ -6405,8 +6468,8 @@ function removeNotice(ctx, id) {
6405
6468
  ctx.exec({
6406
6469
  name: "removeNotice",
6407
6470
  do: () => ctx.patchProps((p) => {
6408
- var _a;
6409
- if (!((_a = p.notices) == null ? void 0 : _a.length)) return;
6471
+ var _a2;
6472
+ if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
6410
6473
  p.notices = p.notices.filter((n) => n.id !== id);
6411
6474
  if (!p.notices.length) delete p.notices;
6412
6475
  }),
@@ -6419,8 +6482,8 @@ var import_lodash_es3 = require("lodash-es");
6419
6482
 
6420
6483
  // src/react/canvas/editor/editor-utils.ts
6421
6484
  function ownerOfOption(props, optionId) {
6422
- var _a, _b;
6423
- for (const f of (_a = props.fields) != null ? _a : []) {
6485
+ var _a2, _b;
6486
+ for (const f of (_a2 = props.fields) != null ? _a2 : []) {
6424
6487
  const idx = ((_b = f.options) != null ? _b : []).findIndex((o) => o.id === optionId);
6425
6488
  if (idx >= 0) return { fieldId: f.id, index: idx };
6426
6489
  }
@@ -6433,8 +6496,8 @@ function isActualButtonField(field) {
6433
6496
  return (field == null ? void 0 : field.button) === true && !hasFieldOptions(field);
6434
6497
  }
6435
6498
  function clearFieldButtonReceiverMaps(props, fieldId) {
6436
- var _a, _b;
6437
- if ((_a = props.includes_for_buttons) == null ? void 0 : _a[fieldId]) {
6499
+ var _a2, _b;
6500
+ if ((_a2 = props.includes_for_buttons) == null ? void 0 : _a2[fieldId]) {
6438
6501
  delete props.includes_for_buttons[fieldId];
6439
6502
  }
6440
6503
  if ((_b = props.excludes_for_buttons) == null ? void 0 : _b[fieldId]) {
@@ -6464,14 +6527,137 @@ function ensureServiceExists(opts, id) {
6464
6527
  }
6465
6528
 
6466
6529
  // src/react/canvas/editor/editor-nodes.ts
6530
+ var RELATION_MAP_KEYS = [
6531
+ "includes_for_buttons",
6532
+ "excludes_for_buttons",
6533
+ "includes_for_options",
6534
+ "excludes_for_options"
6535
+ ];
6536
+ function stripDeletedIds(ids) {
6537
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
6538
+ return { ordered, set: new Set(ordered) };
6539
+ }
6540
+ function cleanTagRelationsForDeleted(p, deleted) {
6541
+ var _a2;
6542
+ for (const t of (_a2 = p.filters) != null ? _a2 : []) {
6543
+ if (t.bind_id && deleted.has(String(t.bind_id))) delete t.bind_id;
6544
+ if (t.includes) {
6545
+ const next = t.includes.filter((x) => !deleted.has(String(x)));
6546
+ if (next.length) t.includes = next;
6547
+ else delete t.includes;
6548
+ }
6549
+ if (t.excludes) {
6550
+ const next = t.excludes.filter((x) => !deleted.has(String(x)));
6551
+ if (next.length) t.excludes = next;
6552
+ else delete t.excludes;
6553
+ }
6554
+ }
6555
+ }
6556
+ function cleanFieldBindsForDeleted(p, deleted) {
6557
+ var _a2;
6558
+ for (const f of (_a2 = p.fields) != null ? _a2 : []) {
6559
+ const bind = f.bind_id;
6560
+ if (!bind) continue;
6561
+ if (Array.isArray(bind)) {
6562
+ const next = bind.filter((x) => !deleted.has(String(x)));
6563
+ if (next.length) f.bind_id = next;
6564
+ else delete f.bind_id;
6565
+ continue;
6566
+ }
6567
+ if (deleted.has(String(bind))) delete f.bind_id;
6568
+ }
6569
+ }
6570
+ function cleanRelationMapsForDeleted(p, deleted) {
6571
+ var _a2;
6572
+ for (const key of RELATION_MAP_KEYS) {
6573
+ const map = p[key];
6574
+ if (!map) continue;
6575
+ for (const mapKey of Object.keys(map)) {
6576
+ if (deleted.has(String(mapKey))) {
6577
+ delete map[mapKey];
6578
+ continue;
6579
+ }
6580
+ const next = ((_a2 = map[mapKey]) != null ? _a2 : []).filter(
6581
+ (item) => !deleted.has(String(item))
6582
+ );
6583
+ if (next.length) map[mapKey] = next;
6584
+ else delete map[mapKey];
6585
+ }
6586
+ if (!Object.keys(map).length) delete p[key];
6587
+ }
6588
+ }
6589
+ function cleanOrderForTagsForDeleted(p, deleted) {
6590
+ var _a2, _b;
6591
+ const map = p.order_for_tags;
6592
+ if (!map) return;
6593
+ const fieldIds = new Set(((_a2 = p.fields) != null ? _a2 : []).map((f) => String(f.id)));
6594
+ for (const key of Object.keys(map)) {
6595
+ if (deleted.has(String(key))) {
6596
+ delete map[key];
6597
+ continue;
6598
+ }
6599
+ const next = ((_b = map[key]) != null ? _b : []).filter(
6600
+ (fid) => !deleted.has(String(fid)) && fieldIds.has(String(fid))
6601
+ );
6602
+ if (next.length) map[key] = next;
6603
+ else delete map[key];
6604
+ }
6605
+ if (!Object.keys(map).length) delete p.order_for_tags;
6606
+ }
6607
+ function cleanNoticesForDeleted(p, deleted) {
6608
+ var _a2;
6609
+ if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
6610
+ p.notices = p.notices.filter((n) => {
6611
+ const target = n.target;
6612
+ if (!target || target.scope === "global") return true;
6613
+ if (target.scope === "node" && deleted.has(String(target.node_id))) {
6614
+ return false;
6615
+ }
6616
+ return true;
6617
+ });
6618
+ if (!p.notices.length) delete p.notices;
6619
+ }
6620
+ function applyDeleteCleanup(p, deleted) {
6621
+ cleanTagRelationsForDeleted(p, deleted);
6622
+ cleanFieldBindsForDeleted(p, deleted);
6623
+ cleanRelationMapsForDeleted(p, deleted);
6624
+ cleanOrderForTagsForDeleted(p, deleted);
6625
+ cleanNoticesForDeleted(p, deleted);
6626
+ }
6627
+ function removeOptionInPlace(p, optionId) {
6628
+ var _a2;
6629
+ const owner = ownerOfOption(p, optionId);
6630
+ if (!owner) return false;
6631
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
6632
+ if (!(f == null ? void 0 : f.options)) return false;
6633
+ const before = f.options.length;
6634
+ f.options = f.options.filter((o) => o.id !== optionId);
6635
+ return f.options.length !== before;
6636
+ }
6637
+ function removeFieldInPlace(p, fieldId) {
6638
+ var _a2, _b, _c, _d, _e;
6639
+ const field = ((_a2 = p.fields) != null ? _a2 : []).find((f) => f.id === fieldId);
6640
+ if (!field) return [];
6641
+ const deleted = [fieldId, ...((_b = field.options) != null ? _b : []).map((o) => String(o.id))];
6642
+ const before = ((_c = p.fields) != null ? _c : []).length;
6643
+ p.fields = ((_d = p.fields) != null ? _d : []).filter((f) => f.id !== fieldId);
6644
+ clearFieldButtonReceiverMaps(p, fieldId);
6645
+ return ((_e = p.fields) != null ? _e : []).length !== before ? deleted : [];
6646
+ }
6647
+ function removeTagInPlace(p, tagId) {
6648
+ var _a2, _b, _c;
6649
+ const before = ((_a2 = p.filters) != null ? _a2 : []).length;
6650
+ p.filters = ((_b = p.filters) != null ? _b : []).filter((t) => t.id !== tagId);
6651
+ return ((_c = p.filters) != null ? _c : []).length !== before;
6652
+ }
6467
6653
  function reLabel(ctx, id, nextLabel) {
6468
6654
  const label = String(nextLabel != null ? nextLabel : "").trim();
6469
6655
  ctx.exec({
6470
6656
  name: "reLabel",
6471
6657
  do: () => ctx.patchProps((p) => {
6472
- var _a, _b, _c, _d, _e, _f, _g;
6658
+ var _a2, _b, _c, _d, _e, _f, _g;
6473
6659
  if (ctx.isTagId(id)) {
6474
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6660
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6475
6661
  if (!t) return;
6476
6662
  if (((_b = t.label) != null ? _b : "") === label) return;
6477
6663
  t.label = label;
@@ -6504,8 +6690,8 @@ function setFieldName(ctx, fieldId, nextName) {
6504
6690
  ctx.exec({
6505
6691
  name: "setFieldName",
6506
6692
  do: () => ctx.patchProps((p) => {
6507
- var _a;
6508
- const fields = (_a = p.fields) != null ? _a : [];
6693
+ var _a2;
6694
+ const fields = (_a2 = p.fields) != null ? _a2 : [];
6509
6695
  const f = fields.find((x) => x.id === fieldId);
6510
6696
  if (!f) {
6511
6697
  ctx.api.emit("error", {
@@ -6537,8 +6723,8 @@ function setFieldName(ctx, fieldId, nextName) {
6537
6723
  }
6538
6724
  const collision = fields.find(
6539
6725
  (x) => {
6540
- var _a2;
6541
- return x.id !== fieldId && ((_a2 = x.name) != null ? _a2 : "") === name;
6726
+ var _a3;
6727
+ return x.id !== fieldId && ((_a3 = x.name) != null ? _a3 : "") === name;
6542
6728
  }
6543
6729
  );
6544
6730
  if (collision) {
@@ -6555,13 +6741,13 @@ function setFieldName(ctx, fieldId, nextName) {
6555
6741
  });
6556
6742
  }
6557
6743
  function addOption(ctx, fieldId, input) {
6558
- var _a;
6559
- const id = (_a = input.id) != null ? _a : ctx.genId("o");
6744
+ var _a2;
6745
+ const id = (_a2 = input.id) != null ? _a2 : ctx.genId("o");
6560
6746
  ctx.exec({
6561
6747
  name: "addOption",
6562
6748
  do: () => ctx.patchProps((p) => {
6563
- var _a2, _b;
6564
- const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6749
+ var _a3, _b;
6750
+ const f = ((_a3 = p.fields) != null ? _a3 : []).find((x) => x.id === fieldId);
6565
6751
  if (!f) throw new Error(`addOption: field '${fieldId}' not found`);
6566
6752
  const list = (_b = f.options) != null ? _b : f.options = [];
6567
6753
  if (list.some((o) => o.id === id)) {
@@ -6580,10 +6766,10 @@ function updateOption(ctx, optionId, patch) {
6580
6766
  ctx.exec({
6581
6767
  name: "updateOption",
6582
6768
  do: () => ctx.patchProps((p) => {
6583
- var _a;
6769
+ var _a2;
6584
6770
  const owner = ownerOfOption(p, optionId);
6585
6771
  if (!owner) return;
6586
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
6772
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
6587
6773
  if (!(f == null ? void 0 : f.options)) return;
6588
6774
  const o = f.options.find((x) => x.id === optionId);
6589
6775
  if (o) Object.assign(o, patch);
@@ -6598,22 +6784,9 @@ function removeOption(ctx, optionId) {
6598
6784
  ctx.exec({
6599
6785
  name: "removeOption",
6600
6786
  do: () => ctx.patchProps((p) => {
6601
- var _a;
6602
- const owner = ownerOfOption(p, optionId);
6603
- if (!owner) return;
6604
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
6605
- if (!(f == null ? void 0 : f.options)) return;
6606
- f.options = f.options.filter((o) => o.id !== optionId);
6607
- const maps = [
6608
- "includes_for_options",
6609
- "excludes_for_options"
6610
- ];
6611
- for (const m of maps) {
6612
- const map = p[m];
6613
- if (!map) continue;
6614
- if (map[optionId]) delete map[optionId];
6615
- if (!Object.keys(map).length) delete p[m];
6616
- }
6787
+ const removed = removeOptionInPlace(p, optionId);
6788
+ if (!removed) return;
6789
+ applyDeleteCleanup(p, /* @__PURE__ */ new Set([optionId]));
6617
6790
  }),
6618
6791
  undo: () => ctx.undo()
6619
6792
  });
@@ -6624,9 +6797,9 @@ function editLabel(ctx, id, label) {
6624
6797
  ctx.exec({
6625
6798
  name: "editLabel",
6626
6799
  do: () => ctx.patchProps((p) => {
6627
- var _a, _b, _c, _d;
6800
+ var _a2, _b, _c, _d;
6628
6801
  if (ctx.isTagId(id)) {
6629
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6802
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6630
6803
  if (t) t.label = next;
6631
6804
  return;
6632
6805
  }
@@ -6652,8 +6825,8 @@ function editName(ctx, fieldId, name) {
6652
6825
  ctx.exec({
6653
6826
  name: "editName",
6654
6827
  do: () => ctx.patchProps((p) => {
6655
- var _a;
6656
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === fieldId);
6828
+ var _a2;
6829
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === fieldId);
6657
6830
  if (!f) return;
6658
6831
  f.name = name;
6659
6832
  }),
@@ -6664,7 +6837,7 @@ function setService(ctx, id, input) {
6664
6837
  ctx.exec({
6665
6838
  name: "setService",
6666
6839
  do: () => ctx.patchProps((p) => {
6667
- var _a, _b, _c, _d, _e, _f;
6840
+ var _a2, _b, _c, _d, _e, _f;
6668
6841
  const hasSidKey = Object.prototype.hasOwnProperty.call(
6669
6842
  input,
6670
6843
  "service_id"
@@ -6673,7 +6846,7 @@ function setService(ctx, id, input) {
6673
6846
  const sid = validId ? typeof input.service_id === "string" ? input.service_id.trim() : Number(input.service_id) : void 0;
6674
6847
  const nextRole = input.pricing_role;
6675
6848
  if (ctx.isTagId(id)) {
6676
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
6849
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
6677
6850
  if (!t) return;
6678
6851
  if (hasSidKey) {
6679
6852
  if (sid === void 0) delete t.service_id;
@@ -6762,18 +6935,18 @@ function setService(ctx, id, input) {
6762
6935
  });
6763
6936
  }
6764
6937
  function addTag(ctx, partial) {
6765
- var _a;
6766
- const id = (_a = partial.id) != null ? _a : ctx.genId("t");
6938
+ var _a2;
6939
+ const id = (_a2 = partial.id) != null ? _a2 : ctx.genId("t");
6767
6940
  const payload = { ...partial, id };
6768
6941
  ctx.exec({
6769
6942
  name: "addTag",
6770
6943
  do: () => ctx.patchProps((p) => {
6771
- var _a2;
6772
- p.filters = [...(_a2 = p.filters) != null ? _a2 : [], payload];
6944
+ var _a3;
6945
+ p.filters = [...(_a3 = p.filters) != null ? _a3 : [], payload];
6773
6946
  }),
6774
6947
  undo: () => ctx.patchProps((p) => {
6775
- var _a2;
6776
- p.filters = ((_a2 = p.filters) != null ? _a2 : []).filter((t) => t.id !== id);
6948
+ var _a3;
6949
+ p.filters = ((_a3 = p.filters) != null ? _a3 : []).filter((t) => t.id !== id);
6777
6950
  })
6778
6951
  });
6779
6952
  }
@@ -6782,16 +6955,16 @@ function updateTag(ctx, id, patch) {
6782
6955
  ctx.exec({
6783
6956
  name: "updateTag",
6784
6957
  do: () => ctx.patchProps((p) => {
6785
- var _a;
6786
- p.filters = ((_a = p.filters) != null ? _a : []).map((t) => {
6958
+ var _a2;
6959
+ p.filters = ((_a2 = p.filters) != null ? _a2 : []).map((t) => {
6787
6960
  if (t.id !== id) return t;
6788
6961
  prev = t;
6789
6962
  return { ...t, ...patch };
6790
6963
  });
6791
6964
  }),
6792
6965
  undo: () => ctx.patchProps((p) => {
6793
- var _a;
6794
- p.filters = ((_a = p.filters) != null ? _a : []).map(
6966
+ var _a2;
6967
+ p.filters = ((_a2 = p.filters) != null ? _a2 : []).map(
6795
6968
  (t) => t.id === id && prev ? prev : t
6796
6969
  );
6797
6970
  })
@@ -6802,38 +6975,27 @@ function removeTag(ctx, id) {
6802
6975
  ctx.exec({
6803
6976
  name: "removeTag",
6804
6977
  do: () => ctx.patchProps((p) => {
6805
- var _a, _b, _c, _d, _e;
6806
6978
  prevSlice = (0, import_lodash_es3.cloneDeep)(p);
6807
- p.filters = ((_a = p.filters) != null ? _a : []).filter((t) => t.id !== id);
6808
- for (const t of (_b = p.filters) != null ? _b : []) {
6809
- if (t.bind_id === id) delete t.bind_id;
6810
- t.includes = ((_c = t.includes) != null ? _c : []).filter((x) => x !== id);
6811
- t.excludes = ((_d = t.excludes) != null ? _d : []).filter((x) => x !== id);
6812
- }
6813
- for (const f of (_e = p.fields) != null ? _e : []) {
6814
- if (Array.isArray(f.bind_id)) {
6815
- f.bind_id = f.bind_id.filter((x) => x !== id);
6816
- } else if (f.bind_id === id) {
6817
- delete f.bind_id;
6818
- }
6819
- }
6979
+ const removed = removeTagInPlace(p, id);
6980
+ if (!removed) return;
6981
+ applyDeleteCleanup(p, /* @__PURE__ */ new Set([id]));
6820
6982
  }),
6821
6983
  undo: () => ctx.replaceProps(prevSlice)
6822
6984
  });
6823
6985
  }
6824
6986
  function addField(ctx, partial) {
6825
- var _a;
6826
- const id = (_a = partial.id) != null ? _a : ctx.genId("f");
6987
+ var _a2;
6988
+ const id = (_a2 = partial.id) != null ? _a2 : ctx.genId("f");
6827
6989
  const payload = { ...partial, id };
6828
6990
  ctx.exec({
6829
6991
  name: "addField",
6830
6992
  do: () => ctx.patchProps((p) => {
6831
- var _a2;
6832
- p.fields = [...(_a2 = p.fields) != null ? _a2 : [], payload];
6993
+ var _a3;
6994
+ p.fields = [...(_a3 = p.fields) != null ? _a3 : [], payload];
6833
6995
  }),
6834
6996
  undo: () => ctx.patchProps((p) => {
6835
- var _a2;
6836
- p.fields = ((_a2 = p.fields) != null ? _a2 : []).filter((f) => f.id !== id);
6997
+ var _a3;
6998
+ p.fields = ((_a3 = p.fields) != null ? _a3 : []).filter((f) => f.id !== id);
6837
6999
  })
6838
7000
  });
6839
7001
  }
@@ -6844,8 +7006,8 @@ function updateField(ctx, id, patch) {
6844
7006
  ctx.exec({
6845
7007
  name: "updateField",
6846
7008
  do: () => ctx.patchProps((p) => {
6847
- var _a, _b, _c, _d, _e, _f, _g;
6848
- 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;
7009
+ var _a2, _b, _c, _d, _e, _f, _g;
7010
+ 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;
6849
7011
  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;
6850
7012
  p.fields = ((_g = p.fields) != null ? _g : []).map((f) => {
6851
7013
  if (f.id !== id) return f;
@@ -6858,8 +7020,8 @@ function updateField(ctx, id, patch) {
6858
7020
  });
6859
7021
  }),
6860
7022
  undo: () => ctx.patchProps((p) => {
6861
- var _a, _b, _c;
6862
- p.fields = ((_a = p.fields) != null ? _a : []).map(
7023
+ var _a2, _b, _c;
7024
+ p.fields = ((_a2 = p.fields) != null ? _a2 : []).map(
6863
7025
  (f) => f.id === id && prev ? prev : f
6864
7026
  );
6865
7027
  if (prevIncludesForButton) {
@@ -6884,58 +7046,23 @@ function removeField(ctx, id) {
6884
7046
  ctx.exec({
6885
7047
  name: "removeField",
6886
7048
  do: () => ctx.patchProps((p) => {
6887
- var _a, _b, _c, _d, _e, _f;
6888
7049
  prevSlice = (0, import_lodash_es3.cloneDeep)(p);
6889
- p.fields = ((_a = p.fields) != null ? _a : []).filter((f) => f.id !== id);
6890
- clearFieldButtonReceiverMaps(p, id);
6891
- for (const mapKey of [
6892
- "includes_for_buttons",
6893
- "excludes_for_buttons"
6894
- ]) {
6895
- const m = p[mapKey];
6896
- if (!m) continue;
6897
- for (const k of Object.keys(m)) {
6898
- m[k] = ((_b = m[k]) != null ? _b : []).filter((fid) => fid !== id);
6899
- if (!((_c = m[k]) == null ? void 0 : _c.length)) delete m[k];
6900
- }
6901
- }
6902
- for (const t of (_d = p.filters) != null ? _d : []) {
6903
- t.includes = ((_e = t.includes) != null ? _e : []).filter((x) => x !== id);
6904
- t.excludes = ((_f = t.excludes) != null ? _f : []).filter((x) => x !== id);
6905
- }
7050
+ const removedIds = removeFieldInPlace(p, id);
7051
+ if (!removedIds.length) return;
7052
+ applyDeleteCleanup(p, new Set(removedIds));
6906
7053
  }),
6907
7054
  undo: () => ctx.replaceProps(prevSlice)
6908
7055
  });
6909
7056
  }
6910
7057
  function remove(ctx, id) {
7058
+ const key = String(id);
6911
7059
  if (ctx.isTagId(id)) {
6912
7060
  ctx.exec({
6913
7061
  name: "removeTag",
6914
7062
  do: () => ctx.patchProps((p) => {
6915
- var _a, _b, _c, _d, _e, _f, _g, _h;
6916
- p.filters = ((_a = p.filters) != null ? _a : []).filter((t) => t.id !== id);
6917
- for (const t of (_b = p.filters) != null ? _b : []) {
6918
- if (t.bind_id === id) delete t.bind_id;
6919
- t.includes = ((_c = t.includes) != null ? _c : []).filter((x) => x !== id);
6920
- t.excludes = ((_d = t.excludes) != null ? _d : []).filter((x) => x !== id);
6921
- }
6922
- for (const f of (_e = p.fields) != null ? _e : []) {
6923
- if (Array.isArray(f.bind_id)) {
6924
- f.bind_id = f.bind_id.filter((x) => x !== id);
6925
- } else if (f.bind_id === id) {
6926
- delete f.bind_id;
6927
- }
6928
- }
6929
- if ((_f = p.order_for_tags) == null ? void 0 : _f[id]) delete p.order_for_tags[id];
6930
- for (const k of Object.keys((_g = p.order_for_tags) != null ? _g : {})) {
6931
- p.order_for_tags[k] = ((_h = p.order_for_tags[k]) != null ? _h : []).filter(
6932
- (fid) => {
6933
- var _a2;
6934
- return ((_a2 = p.fields) != null ? _a2 : []).some((f) => f.id === fid);
6935
- }
6936
- );
6937
- if (!p.order_for_tags[k].length) delete p.order_for_tags[k];
6938
- }
7063
+ const removed = removeTagInPlace(p, key);
7064
+ if (!removed) return;
7065
+ applyDeleteCleanup(p, /* @__PURE__ */ new Set([key]));
6939
7066
  }),
6940
7067
  undo: () => ctx.undo()
6941
7068
  });
@@ -6945,47 +7072,72 @@ function remove(ctx, id) {
6945
7072
  ctx.exec({
6946
7073
  name: "removeField",
6947
7074
  do: () => ctx.patchProps((p) => {
6948
- var _a, _b, _c, _d, _e, _f, _g, _h;
6949
- p.fields = ((_a = p.fields) != null ? _a : []).filter((f) => f.id !== id);
6950
- for (const t of (_b = p.filters) != null ? _b : []) {
6951
- t.includes = ((_c = t.includes) != null ? _c : []).filter((x) => x !== id);
6952
- t.excludes = ((_d = t.excludes) != null ? _d : []).filter((x) => x !== id);
6953
- }
6954
- for (const k of Object.keys((_e = p.order_for_tags) != null ? _e : {})) {
6955
- p.order_for_tags[k] = ((_f = p.order_for_tags[k]) != null ? _f : []).filter(
6956
- (fid) => fid !== id
6957
- );
6958
- if (!p.order_for_tags[k].length) delete p.order_for_tags[k];
6959
- }
6960
- const maps = [
6961
- "includes_for_options",
6962
- "excludes_for_options"
6963
- ];
6964
- for (const m of maps) {
6965
- const map = p[m];
6966
- if (!map) continue;
6967
- for (const key of Object.keys(map)) {
6968
- map[key] = ((_g = map[key]) != null ? _g : []).filter((fid) => fid !== id);
6969
- if (!((_h = map[key]) == null ? void 0 : _h.length)) delete map[key];
6970
- }
6971
- if (!Object.keys(map).length) delete p[m];
6972
- }
7075
+ const removedIds = removeFieldInPlace(p, key);
7076
+ if (!removedIds.length) return;
7077
+ applyDeleteCleanup(p, new Set(removedIds));
6973
7078
  }),
6974
7079
  undo: () => ctx.undo()
6975
7080
  });
6976
7081
  return;
6977
7082
  }
6978
7083
  if (ctx.isOptionId(id)) {
6979
- removeOption(ctx, id);
7084
+ ctx.exec({
7085
+ name: "removeOption",
7086
+ do: () => ctx.patchProps((p) => {
7087
+ const removed = removeOptionInPlace(p, key);
7088
+ if (!removed) return;
7089
+ applyDeleteCleanup(p, /* @__PURE__ */ new Set([key]));
7090
+ }),
7091
+ undo: () => ctx.undo()
7092
+ });
6980
7093
  return;
6981
7094
  }
6982
7095
  throw new Error("remove: unknown id prefix");
6983
7096
  }
7097
+ function removeMany(ctx, ids) {
7098
+ const { ordered } = stripDeletedIds(ids);
7099
+ if (!ordered.length) return;
7100
+ ctx.transact("removeMany", () => {
7101
+ ctx.patchProps((p) => {
7102
+ var _a2, _b, _c;
7103
+ const existingFieldIds = new Set(((_a2 = p.fields) != null ? _a2 : []).map((f) => String(f.id)));
7104
+ const existingTagIds = new Set(((_b = p.filters) != null ? _b : []).map((t) => String(t.id)));
7105
+ const existingOptionIds = new Set(
7106
+ ((_c = p.fields) != null ? _c : []).flatMap((f) => {
7107
+ var _a3;
7108
+ return ((_a3 = f.options) != null ? _a3 : []).map((o) => String(o.id));
7109
+ })
7110
+ );
7111
+ const fieldIds = ordered.filter((id) => ctx.isFieldId(id) && existingFieldIds.has(id));
7112
+ const fieldIdSet = new Set(fieldIds);
7113
+ const tagIds = ordered.filter((id) => ctx.isTagId(id) && existingTagIds.has(id));
7114
+ const optionIds = ordered.filter((id) => {
7115
+ if (!ctx.isOptionId(id) || !existingOptionIds.has(id)) return false;
7116
+ const owner = ownerOfOption(p, id);
7117
+ if (!owner) return false;
7118
+ return !fieldIdSet.has(String(owner.fieldId));
7119
+ });
7120
+ const deleted = /* @__PURE__ */ new Set();
7121
+ for (const optionId of optionIds) {
7122
+ if (removeOptionInPlace(p, optionId)) deleted.add(optionId);
7123
+ }
7124
+ for (const fieldId of fieldIds) {
7125
+ const removedIds = removeFieldInPlace(p, fieldId);
7126
+ for (const rid of removedIds) deleted.add(rid);
7127
+ }
7128
+ for (const tagId of tagIds) {
7129
+ if (removeTagInPlace(p, tagId)) deleted.add(tagId);
7130
+ }
7131
+ if (!deleted.size) return;
7132
+ applyDeleteCleanup(p, deleted);
7133
+ });
7134
+ });
7135
+ }
6984
7136
  function getNode(ctx, id) {
6985
- var _a, _b, _c, _d;
7137
+ var _a2, _b, _c, _d;
6986
7138
  const props = ctx.getProps();
6987
7139
  if (ctx.isTagId(id)) {
6988
- const t = ((_a = props.filters) != null ? _a : []).find((x) => x.id === id);
7140
+ const t = ((_a2 = props.filters) != null ? _a2 : []).find((x) => x.id === id);
6989
7141
  return {
6990
7142
  kind: "tag",
6991
7143
  data: t,
@@ -7016,8 +7168,8 @@ function setConstraint(ctx, tagId, flag, value) {
7016
7168
  ctx.exec({
7017
7169
  name: "setConstraint",
7018
7170
  do: () => ctx.patchProps((p) => {
7019
- var _a, _b;
7020
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7171
+ var _a2, _b;
7172
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7021
7173
  if (!t) return;
7022
7174
  prev = (_b = t.constraints) == null ? void 0 : _b[flag];
7023
7175
  if (!t.constraints) t.constraints = {};
@@ -7025,8 +7177,8 @@ function setConstraint(ctx, tagId, flag, value) {
7025
7177
  else t.constraints[flag] = value;
7026
7178
  }),
7027
7179
  undo: () => ctx.patchProps((p) => {
7028
- var _a;
7029
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7180
+ var _a2;
7181
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7030
7182
  if (!t) return;
7031
7183
  if (!t.constraints) t.constraints = {};
7032
7184
  if (prev === void 0) delete t.constraints[flag];
@@ -7040,8 +7192,8 @@ function clearConstraintOverride(ctx, tagId, flag) {
7040
7192
  ctx.exec({
7041
7193
  name: "clearConstraintOverride",
7042
7194
  do: () => ctx.patchProps((p) => {
7043
- var _a, _b, _c;
7044
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7195
+ var _a2, _b, _c;
7196
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7045
7197
  if (!t) return;
7046
7198
  prev = (_b = t.constraints) == null ? void 0 : _b[flag];
7047
7199
  prevOverride = (_c = t.constraints_overrides) == null ? void 0 : _c[flag];
@@ -7049,8 +7201,8 @@ function clearConstraintOverride(ctx, tagId, flag) {
7049
7201
  if (t.constraints_overrides) delete t.constraints_overrides[flag];
7050
7202
  }),
7051
7203
  undo: () => ctx.patchProps((p) => {
7052
- var _a;
7053
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === tagId);
7204
+ var _a2;
7205
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === tagId);
7054
7206
  if (!t) return;
7055
7207
  if (prev !== void 0) {
7056
7208
  if (!t.constraints) t.constraints = {};
@@ -7067,8 +7219,8 @@ function clearConstraint(ctx, tagId, flag) {
7067
7219
  ctx.exec({
7068
7220
  name: "clearConstraint",
7069
7221
  do: () => ctx.patchProps((p) => {
7070
- var _a;
7071
- const tags = (_a = p.filters) != null ? _a : [];
7222
+ var _a2;
7223
+ const tags = (_a2 = p.filters) != null ? _a2 : [];
7072
7224
  const byId = new Map(tags.map((t) => [t.id, t]));
7073
7225
  const children = /* @__PURE__ */ new Map();
7074
7226
  for (const t of tags) {
@@ -7078,10 +7230,10 @@ function clearConstraint(ctx, tagId, flag) {
7078
7230
  }
7079
7231
  }
7080
7232
  const process = (id) => {
7081
- var _a2, _b, _c;
7233
+ var _a3, _b, _c;
7082
7234
  const t = byId.get(id);
7083
7235
  if (!t) return;
7084
- const override = (_a2 = t.constraints_overrides) == null ? void 0 : _a2[flag];
7236
+ const override = (_a3 = t.constraints_overrides) == null ? void 0 : _a3[flag];
7085
7237
  if (override) {
7086
7238
  if (!t.constraints) t.constraints = {};
7087
7239
  t.constraints[flag] = override.from;
@@ -7107,9 +7259,9 @@ function clearConstraint(ctx, tagId, flag) {
7107
7259
 
7108
7260
  // src/react/canvas/editor/editor-field-rules.ts
7109
7261
  function getFieldQuantityRule(ctx, id) {
7110
- var _a, _b;
7262
+ var _a2, _b;
7111
7263
  const props = ctx.getProps();
7112
- const f = ((_a = props.fields) != null ? _a : []).find((x) => x.id === id);
7264
+ const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
7113
7265
  if (!f) return void 0;
7114
7266
  return normalizeQuantityRule((_b = f.meta) == null ? void 0 : _b.quantity);
7115
7267
  }
@@ -7117,8 +7269,8 @@ function setFieldQuantityRule(ctx, id, rule) {
7117
7269
  ctx.exec({
7118
7270
  name: "setFieldQuantityRule",
7119
7271
  do: () => ctx.patchProps((p) => {
7120
- var _a, _b;
7121
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7272
+ var _a2, _b;
7273
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7122
7274
  if (!f) return;
7123
7275
  const normalized = normalizeQuantityRule(rule);
7124
7276
  if (!normalized) {
@@ -7142,8 +7294,8 @@ function clearFieldQuantityRule(ctx, id) {
7142
7294
  ctx.exec({
7143
7295
  name: "clearFieldQuantityRule",
7144
7296
  do: () => ctx.patchProps((p) => {
7145
- var _a, _b;
7146
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7297
+ var _a2, _b;
7298
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7147
7299
  if (!f || !((_b = f.meta) == null ? void 0 : _b.quantity)) return;
7148
7300
  delete f.meta.quantity;
7149
7301
  if (f.meta && Object.keys(f.meta).length === 0) {
@@ -7154,9 +7306,9 @@ function clearFieldQuantityRule(ctx, id) {
7154
7306
  });
7155
7307
  }
7156
7308
  function getFieldValidation(ctx, id) {
7157
- var _a;
7309
+ var _a2;
7158
7310
  const props = ctx.getProps();
7159
- const f = ((_a = props.fields) != null ? _a : []).find((x) => x.id === id);
7311
+ const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
7160
7312
  if (!f) return void 0;
7161
7313
  return normalizeFieldValidation(f.validation);
7162
7314
  }
@@ -7164,8 +7316,8 @@ function setFieldValidation(ctx, id, rules) {
7164
7316
  ctx.exec({
7165
7317
  name: "setFieldValidation",
7166
7318
  do: () => ctx.patchProps((p) => {
7167
- var _a;
7168
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7319
+ var _a2;
7320
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7169
7321
  if (!f) return;
7170
7322
  const normalized = normalizeFieldValidation(rules);
7171
7323
  if (!normalized) {
@@ -7181,8 +7333,8 @@ function clearFieldValidation(ctx, id) {
7181
7333
  ctx.exec({
7182
7334
  name: "clearFieldValidation",
7183
7335
  do: () => ctx.patchProps((p) => {
7184
- var _a;
7185
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === id);
7336
+ var _a2;
7337
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
7186
7338
  if (!f || !f.validation) return;
7187
7339
  delete f.validation;
7188
7340
  }),
@@ -7301,9 +7453,9 @@ function pruneOrderKind(ctx, kind) {
7301
7453
 
7302
7454
  // src/react/canvas/editor/editor-relations.ts
7303
7455
  function wouldCreateTagCycle(_ctx, p, parentId, childId) {
7304
- var _a, _b;
7456
+ var _a2, _b;
7305
7457
  if (parentId === childId) return true;
7306
- const tagById = new Map(((_a = p.filters) != null ? _a : []).map((t) => [t.id, t]));
7458
+ const tagById = new Map(((_a2 = p.filters) != null ? _a2 : []).map((t) => [t.id, t]));
7307
7459
  let cur = parentId;
7308
7460
  const guard = /* @__PURE__ */ new Set();
7309
7461
  while (cur) {
@@ -7317,9 +7469,9 @@ function wouldCreateTagCycle(_ctx, p, parentId, childId) {
7317
7469
  function wouldCreateIncludeExcludeCycle(ctx, p, receiverId, targetId) {
7318
7470
  if (receiverId === targetId) return true;
7319
7471
  const getDirectRelations = (id) => {
7320
- var _a, _b, _c, _d, _e, _f, _g;
7472
+ var _a2, _b, _c, _d, _e, _f, _g;
7321
7473
  if (ctx.isTagId(id)) {
7322
- const t = ((_a = p.filters) != null ? _a : []).find((x) => x.id === id);
7474
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
7323
7475
  return [...(_b = t == null ? void 0 : t.includes) != null ? _b : [], ...(_c = t == null ? void 0 : t.excludes) != null ? _c : []];
7324
7476
  }
7325
7477
  const inc = (_e = (_d = p.includes_for_buttons) == null ? void 0 : _d[id]) != null ? _e : [];
@@ -7341,12 +7493,12 @@ function include(ctx, receiverId, idOrIds) {
7341
7493
  ctx.exec({
7342
7494
  name: "include",
7343
7495
  do: () => ctx.patchProps((p) => {
7344
- var _a, _b, _c, _d, _e, _f, _g;
7496
+ var _a2, _b, _c, _d, _e, _f, _g;
7345
7497
  const receiver = ctx.getNode(receiverId);
7346
7498
  const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
7347
7499
  if (receiver.kind === "tag" || receiver.kind === "field" && isActualButtonField(receiver.data) || receiver.kind === "option") {
7348
7500
  if (receiver.kind === "tag") {
7349
- const t = ((_a = p.filters) != null ? _a : []).find(
7501
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find(
7350
7502
  (x) => x.id === receiverId
7351
7503
  );
7352
7504
  if (t) {
@@ -7439,12 +7591,12 @@ function exclude(ctx, receiverId, idOrIds) {
7439
7591
  ctx.exec({
7440
7592
  name: "exclude",
7441
7593
  do: () => ctx.patchProps((p) => {
7442
- var _a, _b, _c, _d, _e, _f, _g;
7594
+ var _a2, _b, _c, _d, _e, _f, _g;
7443
7595
  const receiver = ctx.getNode(receiverId);
7444
7596
  const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
7445
7597
  if (receiver.kind === "tag" || receiver.kind === "field" && isActualButtonField(receiver.data) || receiver.kind === "option") {
7446
7598
  if (receiver.kind === "tag") {
7447
- const t = ((_a = p.filters) != null ? _a : []).find(
7599
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find(
7448
7600
  (x) => x.id === receiverId
7449
7601
  );
7450
7602
  if (t) {
@@ -7537,7 +7689,7 @@ function connect(ctx, kind, fromId, toId2) {
7537
7689
  ctx.exec({
7538
7690
  name: `connect:${kind}`,
7539
7691
  do: () => ctx.patchProps((p) => {
7540
- var _a, _b, _c, _d, _e, _f, _g, _h;
7692
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
7541
7693
  if (kind === "bind") {
7542
7694
  if (ctx.isTagId(fromId) && ctx.isTagId(toId2)) {
7543
7695
  if (wouldCreateTagCycle(ctx, p, fromId, toId2)) {
@@ -7545,7 +7697,7 @@ function connect(ctx, kind, fromId, toId2) {
7545
7697
  `bind would create a cycle: ${fromId} ? ${toId2}`
7546
7698
  );
7547
7699
  }
7548
- const child = ((_a = p.filters) != null ? _a : []).find(
7700
+ const child = ((_a2 = p.filters) != null ? _a2 : []).find(
7549
7701
  (t) => t.id === toId2
7550
7702
  );
7551
7703
  if (child) child.bind_id = fromId;
@@ -7639,10 +7791,10 @@ function disconnect(ctx, kind, fromId, toId2) {
7639
7791
  ctx.exec({
7640
7792
  name: `disconnect:${kind}`,
7641
7793
  do: () => ctx.patchProps((p) => {
7642
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
7794
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
7643
7795
  if (kind === "bind") {
7644
7796
  if (ctx.isTagId(fromId) && ctx.isTagId(toId2)) {
7645
- const child = ((_a = p.filters) != null ? _a : []).find(
7797
+ const child = ((_a2 = p.filters) != null ? _a2 : []).find(
7646
7798
  (t) => t.id === toId2
7647
7799
  );
7648
7800
  if ((child == null ? void 0 : child.bind_id) === fromId) {
@@ -7734,8 +7886,8 @@ function disconnect(ctx, kind, fromId, toId2) {
7734
7886
  });
7735
7887
  }
7736
7888
  function addMappedField(p, mapKey, fromId, toId2) {
7737
- var _a, _b;
7738
- const maps = (_a = p[mapKey]) != null ? _a : {};
7889
+ var _a2, _b;
7890
+ const maps = (_a2 = p[mapKey]) != null ? _a2 : {};
7739
7891
  const arr = (_b = maps[fromId]) != null ? _b : [];
7740
7892
  if (!arr.includes(toId2)) {
7741
7893
  maps[fromId] = [...arr, toId2];
@@ -7772,15 +7924,15 @@ function placeNode(ctx, id, opts) {
7772
7924
  ctx.exec({
7773
7925
  name: "placeTag",
7774
7926
  do: () => ctx.patchProps((p) => {
7775
- var _a, _b, _c;
7776
- const all = (_a = p.filters) != null ? _a : [];
7927
+ var _a2, _b, _c;
7928
+ const all = (_a2 = p.filters) != null ? _a2 : [];
7777
7929
  const cur = all.find((t) => t.id === id);
7778
7930
  if (!cur) return;
7779
7931
  const groupKey = (_b = cur.bind_id) != null ? _b : "__root__";
7780
7932
  const siblings = all.filter(
7781
7933
  (t) => {
7782
- var _a2;
7783
- return ((_a2 = t.bind_id) != null ? _a2 : "__root__") === groupKey;
7934
+ var _a3;
7935
+ return ((_a3 = t.bind_id) != null ? _a3 : "__root__") === groupKey;
7784
7936
  }
7785
7937
  );
7786
7938
  const curIdx = siblings.findIndex((t) => t.id === id);
@@ -7825,8 +7977,8 @@ function placeNode(ctx, id, opts) {
7825
7977
  ctx.exec({
7826
7978
  name: "placeField",
7827
7979
  do: () => ctx.patchProps((p) => {
7828
- var _a, _b;
7829
- const map = (_a = p.order_for_tags) != null ? _a : p.order_for_tags = {};
7980
+ var _a2, _b;
7981
+ const map = (_a2 = p.order_for_tags) != null ? _a2 : p.order_for_tags = {};
7830
7982
  const arr = (_b = map[tagId]) != null ? _b : map[tagId] = [];
7831
7983
  const curIdx = arr.indexOf(fieldId);
7832
7984
  if (curIdx >= 0) arr.splice(curIdx, 1);
@@ -7855,10 +8007,10 @@ function placeOption(ctx, optionId, opts) {
7855
8007
  ctx.exec({
7856
8008
  name: "placeOption",
7857
8009
  do: () => ctx.patchProps((p) => {
7858
- var _a;
8010
+ var _a2;
7859
8011
  const owner = ownerOfOption(p, optionId);
7860
8012
  if (!owner) return;
7861
- const f = ((_a = p.fields) != null ? _a : []).find((x) => x.id === owner.fieldId);
8013
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === owner.fieldId);
7862
8014
  if (!(f == null ? void 0 : f.options)) return;
7863
8015
  const curIdx = f.options.findIndex((o) => o.id === optionId);
7864
8016
  if (curIdx < 0) return;
@@ -7916,8 +8068,8 @@ function ensureCatalog(catalog) {
7916
8068
  return clone(catalog != null ? catalog : createEmptyCatalog());
7917
8069
  }
7918
8070
  function createCatalogId(catalog, prefix = "cg") {
7919
- var _a;
7920
- const taken = new Set(((_a = catalog == null ? void 0 : catalog.nodes) != null ? _a : []).map((x) => x.id));
8071
+ var _a2;
8072
+ const taken = new Set(((_a2 = catalog == null ? void 0 : catalog.nodes) != null ? _a2 : []).map((x) => x.id));
7921
8073
  for (let i = 1; i < 1e4; i++) {
7922
8074
  const id = `${prefix}:${i}`;
7923
8075
  if (!taken.has(id)) return id;
@@ -7925,9 +8077,9 @@ function createCatalogId(catalog, prefix = "cg") {
7925
8077
  throw new Error("Unable to generate catalog id");
7926
8078
  }
7927
8079
  function addCatalogGroup(catalog, input) {
7928
- var _a;
8080
+ var _a2;
7929
8081
  const next = ensureCatalog(catalog);
7930
- const id = (_a = input.id) != null ? _a : createCatalogId(next, "cg");
8082
+ const id = (_a2 = input.id) != null ? _a2 : createCatalogId(next, "cg");
7931
8083
  next.nodes.push({
7932
8084
  id,
7933
8085
  kind: "group",
@@ -7944,9 +8096,9 @@ function addCatalogGroup(catalog, input) {
7944
8096
  return next;
7945
8097
  }
7946
8098
  function addSmartCatalogGroup(catalog, input) {
7947
- var _a, _b, _c;
8099
+ var _a2, _b, _c;
7948
8100
  const next = ensureCatalog(catalog);
7949
- const id = (_a = input.id) != null ? _a : createCatalogId(next, "csg");
8101
+ const id = (_a2 = input.id) != null ? _a2 : createCatalogId(next, "csg");
7950
8102
  next.nodes.push({
7951
8103
  id,
7952
8104
  kind: "smart-group",
@@ -7964,7 +8116,7 @@ function addSmartCatalogGroup(catalog, input) {
7964
8116
  return next;
7965
8117
  }
7966
8118
  function updateCatalogNode(catalog, id, patch) {
7967
- var _a;
8119
+ var _a2;
7968
8120
  if (!catalog) return catalog;
7969
8121
  const next = ensureCatalog(catalog);
7970
8122
  const idx = next.nodes.findIndex((x) => x.id === id);
@@ -7974,7 +8126,7 @@ function updateCatalogNode(catalog, id, patch) {
7974
8126
  ...current,
7975
8127
  ...patch
7976
8128
  };
7977
- if (((_a = next.nodes[idx]) == null ? void 0 : _a.kind) === "group") {
8129
+ if (((_a2 = next.nodes[idx]) == null ? void 0 : _a2.kind) === "group") {
7978
8130
  next.nodes[idx] = {
7979
8131
  ...next.nodes[idx],
7980
8132
  serviceIds: normalizeServiceIds(
@@ -8000,27 +8152,27 @@ function setSelectedCatalogService(catalog, serviceId) {
8000
8152
  return next;
8001
8153
  }
8002
8154
  function toggleCatalogExpanded(catalog, id) {
8003
- var _a;
8155
+ var _a2;
8004
8156
  const next = ensureCatalog(catalog);
8005
- const expanded = new Set((_a = next.expandedIds) != null ? _a : []);
8157
+ const expanded = new Set((_a2 = next.expandedIds) != null ? _a2 : []);
8006
8158
  if (expanded.has(id)) expanded.delete(id);
8007
8159
  else expanded.add(id);
8008
8160
  next.expandedIds = Array.from(expanded);
8009
8161
  return next;
8010
8162
  }
8011
8163
  function setCatalogExpanded(catalog, id, expanded) {
8012
- var _a;
8164
+ var _a2;
8013
8165
  const next = ensureCatalog(catalog);
8014
- const set = new Set((_a = next.expandedIds) != null ? _a : []);
8166
+ const set = new Set((_a2 = next.expandedIds) != null ? _a2 : []);
8015
8167
  if (expanded) set.add(id);
8016
8168
  else set.delete(id);
8017
8169
  next.expandedIds = Array.from(set);
8018
8170
  return next;
8019
8171
  }
8020
8172
  function toggleCatalogPinned(catalog, id) {
8021
- var _a;
8173
+ var _a2;
8022
8174
  const next = ensureCatalog(catalog);
8023
- const pinned = new Set((_a = next.pinnedNodeIds) != null ? _a : []);
8175
+ const pinned = new Set((_a2 = next.pinnedNodeIds) != null ? _a2 : []);
8024
8176
  if (pinned.has(id)) pinned.delete(id);
8025
8177
  else pinned.add(id);
8026
8178
  next.pinnedNodeIds = Array.from(pinned);
@@ -8049,7 +8201,7 @@ function assignServicesToCatalogGroup(catalog, nodeId, serviceIds, mode = "appen
8049
8201
  return next;
8050
8202
  }
8051
8203
  function removeCatalogNode(catalog, id, opts) {
8052
- var _a, _b;
8204
+ var _a2, _b;
8053
8205
  if (!catalog) return catalog;
8054
8206
  const next = ensureCatalog(catalog);
8055
8207
  const ids = /* @__PURE__ */ new Set([id]);
@@ -8071,7 +8223,7 @@ function removeCatalogNode(catalog, id, opts) {
8071
8223
  if (next.activeNodeId && ids.has(next.activeNodeId)) {
8072
8224
  next.activeNodeId = void 0;
8073
8225
  }
8074
- next.expandedIds = ((_a = next.expandedIds) != null ? _a : []).filter((x) => !ids.has(x));
8226
+ next.expandedIds = ((_a2 = next.expandedIds) != null ? _a2 : []).filter((x) => !ids.has(x));
8075
8227
  next.pinnedNodeIds = ((_b = next.pinnedNodeIds) != null ? _b : []).filter((x) => !ids.has(x));
8076
8228
  return next;
8077
8229
  }
@@ -8082,8 +8234,8 @@ function moveCatalogNode(catalog, nodeId, opts) {
8082
8234
  if (!node) return next;
8083
8235
  node.parentId = opts.parentId;
8084
8236
  const siblings = next.nodes.filter((x) => x.parentId === opts.parentId && x.id !== nodeId).sort((a, b) => {
8085
- var _a, _b;
8086
- return ((_a = a.order) != null ? _a : 0) - ((_b = b.order) != null ? _b : 0);
8237
+ var _a2, _b;
8238
+ return ((_a2 = a.order) != null ? _a2 : 0) - ((_b = b.order) != null ? _b : 0);
8087
8239
  });
8088
8240
  let dest = typeof opts.index === "number" ? opts.index : siblings.length;
8089
8241
  if (opts.beforeId) {
@@ -8102,20 +8254,20 @@ function moveCatalogNode(catalog, nodeId, opts) {
8102
8254
  return next;
8103
8255
  }
8104
8256
  function resolveSmartCatalogGroup(catalog, nodeId, candidates, matchers) {
8105
- var _a, _b;
8257
+ var _a2, _b;
8106
8258
  if (!catalog) return catalog;
8107
8259
  const next = ensureCatalog(catalog);
8108
8260
  const node = next.nodes.find(
8109
8261
  (x) => x.id === nodeId && x.kind === "smart-group"
8110
8262
  );
8111
8263
  if (!node) return next;
8112
- const rules = (_a = node.rules) != null ? _a : [];
8264
+ const rules = (_a2 = node.rules) != null ? _a2 : [];
8113
8265
  const mode = (_b = node.match) != null ? _b : "all";
8114
8266
  const resolved = candidates.filter((candidate) => {
8115
8267
  const results = rules.map((rule) => {
8116
- var _a2, _b2, _c, _d, _e, _f;
8268
+ var _a3, _b2, _c, _d, _e, _f;
8117
8269
  if (rule.type === "service-field") {
8118
- return (_b2 = (_a2 = matchers.serviceField) == null ? void 0 : _a2.call(matchers, candidate, rule)) != null ? _b2 : false;
8270
+ return (_b2 = (_a3 = matchers.serviceField) == null ? void 0 : _a3.call(matchers, candidate, rule)) != null ? _b2 : false;
8119
8271
  }
8120
8272
  if (rule.type === "policy-family") {
8121
8273
  return (_d = (_c = matchers.policyFamily) == null ? void 0 : _c.call(matchers, candidate, rule)) != null ? _d : false;
@@ -8136,14 +8288,14 @@ var Editor = class {
8136
8288
  this.history = [];
8137
8289
  this.index = -1;
8138
8290
  this.txnDepth = 0;
8139
- var _a, _b;
8291
+ var _a2, _b;
8140
8292
  this.builder = builder;
8141
8293
  this.api = api;
8142
8294
  this.opts = {
8143
8295
  ...opts,
8144
8296
  historyLimit: Math.max(
8145
8297
  1,
8146
- Math.min((_a = opts.historyLimit) != null ? _a : MAX_LIMIT, 1e3)
8298
+ Math.min((_a2 = opts.historyLimit) != null ? _a2 : MAX_LIMIT, 1e3)
8147
8299
  ),
8148
8300
  validateAfterEach: (_b = opts.validateAfterEach) != null ? _b : false
8149
8301
  };
@@ -8186,14 +8338,14 @@ var Editor = class {
8186
8338
  }
8187
8339
  }
8188
8340
  exec(cmd) {
8189
- var _a;
8341
+ var _a2;
8190
8342
  try {
8191
8343
  const before = this.makeSnapshot(cmd.name + ":before");
8192
8344
  cmd.do();
8193
8345
  this.afterMutation(cmd.name, before);
8194
8346
  } catch (err) {
8195
8347
  this.emit("editor:error", {
8196
- message: (_a = err == null ? void 0 : err.message) != null ? _a : String(err),
8348
+ message: (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err),
8197
8349
  code: "command"
8198
8350
  });
8199
8351
  throw err;
@@ -8225,6 +8377,9 @@ var Editor = class {
8225
8377
  duplicate(ref, opts = {}) {
8226
8378
  return duplicate(this.moduleCtx(), ref, opts);
8227
8379
  }
8380
+ duplicateMany(ids, opts = {}) {
8381
+ return duplicateMany(this.moduleCtx(), ids, opts);
8382
+ }
8228
8383
  reLabel(id, nextLabel) {
8229
8384
  return reLabel(this.moduleCtx(), id, nextLabel);
8230
8385
  }
@@ -8288,6 +8443,260 @@ var Editor = class {
8288
8443
  remove(id) {
8289
8444
  return remove(this.moduleCtx(), id);
8290
8445
  }
8446
+ removeMany(ids) {
8447
+ return removeMany(this.moduleCtx(), ids);
8448
+ }
8449
+ clearServiceMany(ids) {
8450
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8451
+ if (!ordered.length) return;
8452
+ this.transact("clearServiceMany", () => {
8453
+ this.patchProps((p) => {
8454
+ var _a2, _b, _c, _d;
8455
+ for (const id of ordered) {
8456
+ if (this.isTagId(id)) {
8457
+ const t = ((_a2 = p.filters) != null ? _a2 : []).find((x) => x.id === id);
8458
+ if (t && "service_id" in t) delete t.service_id;
8459
+ continue;
8460
+ }
8461
+ if (this.isFieldId(id)) {
8462
+ const f = ((_b = p.fields) != null ? _b : []).find((x) => x.id === id);
8463
+ if (f && "service_id" in f) delete f.service_id;
8464
+ continue;
8465
+ }
8466
+ if (this.isOptionId(id)) {
8467
+ const own = ownerOfOption(p, id);
8468
+ if (!own) continue;
8469
+ const f = ((_c = p.fields) != null ? _c : []).find((x) => x.id === own.fieldId);
8470
+ const o = (_d = f == null ? void 0 : f.options) == null ? void 0 : _d.find((x) => x.id === id);
8471
+ if (o && "service_id" in o) delete o.service_id;
8472
+ }
8473
+ }
8474
+ });
8475
+ });
8476
+ }
8477
+ rebindMany(ids, targetTagId, opts) {
8478
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8479
+ if (!ordered.length) return;
8480
+ this.transact("rebindMany", () => {
8481
+ this.patchProps((p) => {
8482
+ var _a2, _b, _c;
8483
+ const targetExists = ((_a2 = p.filters) != null ? _a2 : []).some((t) => t.id === targetTagId);
8484
+ if (!targetExists) return;
8485
+ for (const id of ordered) {
8486
+ if (this.isFieldId(id)) {
8487
+ const f = ((_b = p.fields) != null ? _b : []).find((x) => x.id === id);
8488
+ if (!f) continue;
8489
+ f.bind_id = targetTagId;
8490
+ continue;
8491
+ }
8492
+ if (this.isTagId(id)) {
8493
+ const t = ((_c = p.filters) != null ? _c : []).find((x) => x.id === id);
8494
+ if (!t) continue;
8495
+ if (!(opts == null ? void 0 : opts.allowTagCycles) && wouldCreateTagCycle(this.moduleCtx(), p, targetTagId, id)) {
8496
+ continue;
8497
+ }
8498
+ t.bind_id = targetTagId;
8499
+ }
8500
+ }
8501
+ });
8502
+ });
8503
+ }
8504
+ includeMany(receiverId, ids) {
8505
+ const accepted = Array.from(new Set((ids != null ? ids : []).map((id) => String(id)))).filter((id) => id !== receiverId).filter((id) => this.getNode(id).data != null);
8506
+ if (!accepted.length) return;
8507
+ include(this.moduleCtx(), receiverId, accepted);
8508
+ }
8509
+ excludeMany(receiverId, ids) {
8510
+ const accepted = Array.from(new Set((ids != null ? ids : []).map((id) => String(id)))).filter((id) => id !== receiverId).filter((id) => this.getNode(id).data != null);
8511
+ if (!accepted.length) return;
8512
+ exclude(this.moduleCtx(), receiverId, accepted);
8513
+ }
8514
+ clearRelationsMany(ids, mode = "both") {
8515
+ const selected = new Set(Array.from(new Set((ids != null ? ids : []).map((id) => String(id)))));
8516
+ if (!selected.size) return;
8517
+ this.transact("clearRelationsMany", () => {
8518
+ this.patchProps((p) => {
8519
+ var _a2, _b, _c;
8520
+ const clearOwned = mode === "owned" || mode === "both";
8521
+ const clearIncoming = mode === "incoming" || mode === "both";
8522
+ for (const t of (_a2 = p.filters) != null ? _a2 : []) {
8523
+ if (clearOwned && selected.has(t.id)) {
8524
+ delete t.includes;
8525
+ delete t.excludes;
8526
+ }
8527
+ if (clearIncoming) {
8528
+ if (t.includes) {
8529
+ t.includes = t.includes.filter((x) => !selected.has(String(x)));
8530
+ if (!t.includes.length) delete t.includes;
8531
+ }
8532
+ if (t.excludes) {
8533
+ t.excludes = t.excludes.filter((x) => !selected.has(String(x)));
8534
+ if (!t.excludes.length) delete t.excludes;
8535
+ }
8536
+ }
8537
+ }
8538
+ const maps = [
8539
+ "includes_for_buttons",
8540
+ "excludes_for_buttons",
8541
+ "includes_for_options",
8542
+ "excludes_for_options"
8543
+ ];
8544
+ for (const k of maps) {
8545
+ const map = p[k];
8546
+ if (!map) continue;
8547
+ for (const key of Object.keys(map)) {
8548
+ if (clearOwned && selected.has(String(key))) {
8549
+ delete map[key];
8550
+ continue;
8551
+ }
8552
+ if (clearIncoming) {
8553
+ map[key] = ((_b = map[key]) != null ? _b : []).filter((x) => !selected.has(String(x)));
8554
+ if (!((_c = map[key]) == null ? void 0 : _c.length)) delete map[key];
8555
+ }
8556
+ }
8557
+ if (!Object.keys(map).length) delete p[k];
8558
+ }
8559
+ });
8560
+ });
8561
+ }
8562
+ renameLabelsMany(ids, input) {
8563
+ var _a2, _b;
8564
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8565
+ if (!ordered.length) return;
8566
+ const prefix = (_a2 = input.prefix) != null ? _a2 : "";
8567
+ const suffix = (_b = input.suffix) != null ? _b : "";
8568
+ this.transact("renameLabelsMany", () => {
8569
+ this.patchProps((p) => {
8570
+ var _a3, _b2, _c, _d, _e, _f, _g;
8571
+ for (const id of ordered) {
8572
+ if (this.isTagId(id)) {
8573
+ const t = ((_a3 = p.filters) != null ? _a3 : []).find((x) => x.id === id);
8574
+ if (t) t.label = `${prefix}${(_b2 = t.label) != null ? _b2 : ""}${suffix}`.trim();
8575
+ continue;
8576
+ }
8577
+ if (this.isFieldId(id)) {
8578
+ const f = ((_c = p.fields) != null ? _c : []).find((x) => x.id === id);
8579
+ if (f) f.label = `${prefix}${(_d = f.label) != null ? _d : ""}${suffix}`.trim();
8580
+ continue;
8581
+ }
8582
+ if (this.isOptionId(id)) {
8583
+ const own = ownerOfOption(p, id);
8584
+ if (!own) continue;
8585
+ const f = ((_e = p.fields) != null ? _e : []).find((x) => x.id === own.fieldId);
8586
+ const o = (_f = f == null ? void 0 : f.options) == null ? void 0 : _f.find((x) => x.id === id);
8587
+ if (o) o.label = `${prefix}${(_g = o.label) != null ? _g : ""}${suffix}`.trim();
8588
+ }
8589
+ }
8590
+ });
8591
+ });
8592
+ }
8593
+ setPricingRoleMany(ids, role) {
8594
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8595
+ if (!ordered.length) return;
8596
+ this.transact("setPricingRoleMany", () => {
8597
+ for (const id of ordered) {
8598
+ if (this.isFieldId(id) || this.isOptionId(id)) {
8599
+ this.setService(id, { pricing_role: role });
8600
+ }
8601
+ }
8602
+ });
8603
+ }
8604
+ clearFieldDefaultsMany(ids) {
8605
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8606
+ if (!ordered.length) return;
8607
+ this.transact("clearFieldDefaultsMany", () => {
8608
+ this.patchProps((p) => {
8609
+ var _a2;
8610
+ for (const id of ordered) {
8611
+ if (!this.isFieldId(id)) continue;
8612
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8613
+ if (f && "defaults" in f) delete f.defaults;
8614
+ }
8615
+ });
8616
+ });
8617
+ }
8618
+ clearFieldValidationMany(ids) {
8619
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8620
+ if (!ordered.length) return;
8621
+ this.transact("clearFieldValidationMany", () => {
8622
+ this.patchProps((p) => {
8623
+ var _a2;
8624
+ for (const id of ordered) {
8625
+ if (!this.isFieldId(id)) continue;
8626
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8627
+ if (f && "validation" in f) delete f.validation;
8628
+ }
8629
+ });
8630
+ });
8631
+ }
8632
+ autoCreateOptionsMany(ids, makeOption) {
8633
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8634
+ if (!ordered.length) return;
8635
+ this.transact("autoCreateOptionsMany", () => {
8636
+ this.patchProps((p) => {
8637
+ var _a2, _b, _c, _d;
8638
+ for (const id of ordered) {
8639
+ if (!this.isFieldId(id)) continue;
8640
+ const f = ((_a2 = p.fields) != null ? _a2 : []).find((x) => x.id === id);
8641
+ if (!f) continue;
8642
+ const opts = (_b = f.options) != null ? _b : f.options = [];
8643
+ if (opts.length > 0) continue;
8644
+ const next = (_c = makeOption == null ? void 0 : makeOption(id)) != null ? _c : { label: "Option label", value: "option" };
8645
+ opts.push({
8646
+ id: (_d = next.id) != null ? _d : this.moduleCtx().genId("o"),
8647
+ label: next.label,
8648
+ value: next.value
8649
+ });
8650
+ }
8651
+ });
8652
+ });
8653
+ }
8654
+ clearAllOptionsMany(ids) {
8655
+ var _a2, _b;
8656
+ const ordered = Array.from(new Set((ids != null ? ids : []).map((id) => String(id))));
8657
+ if (!ordered.length) return;
8658
+ const optionIds = [];
8659
+ const props = this.getProps();
8660
+ for (const id of ordered) {
8661
+ if (!this.isFieldId(id)) continue;
8662
+ const f = ((_a2 = props.fields) != null ? _a2 : []).find((x) => x.id === id);
8663
+ for (const o of (_b = f == null ? void 0 : f.options) != null ? _b : []) optionIds.push(o.id);
8664
+ }
8665
+ if (!optionIds.length) return;
8666
+ removeMany(this.moduleCtx(), optionIds);
8667
+ }
8668
+ removeNoticesForNodes(ids) {
8669
+ const selected = new Set(Array.from(new Set((ids != null ? ids : []).map((id) => String(id)))));
8670
+ if (!selected.size) return;
8671
+ this.transact("removeNoticesForNodes", () => {
8672
+ this.patchProps((p) => {
8673
+ var _a2;
8674
+ if (!((_a2 = p.notices) == null ? void 0 : _a2.length)) return;
8675
+ p.notices = p.notices.filter((n) => {
8676
+ const target = n.target;
8677
+ if (!target || target.scope === "global") return true;
8678
+ if (target.scope === "node") return !selected.has(String(target.node_id));
8679
+ return true;
8680
+ });
8681
+ if (!p.notices.length) delete p.notices;
8682
+ });
8683
+ });
8684
+ }
8685
+ setNoticesVisibilityForNodes(ids, type) {
8686
+ const selected = new Set(Array.from(new Set((ids != null ? ids : []).map((id) => String(id)))));
8687
+ if (!selected.size) return;
8688
+ this.transact("setNoticesVisibilityForNodes", () => {
8689
+ this.patchProps((p) => {
8690
+ var _a2;
8691
+ for (const n of (_a2 = p.notices) != null ? _a2 : []) {
8692
+ const target = n.target;
8693
+ if ((target == null ? void 0 : target.scope) === "node" && selected.has(String(target.node_id))) {
8694
+ n.type = type;
8695
+ }
8696
+ }
8697
+ });
8698
+ });
8699
+ }
8291
8700
  getNode(id) {
8292
8701
  return getNode(this.moduleCtx(), id);
8293
8702
  }
@@ -8440,7 +8849,7 @@ var Editor = class {
8440
8849
  );
8441
8850
  }
8442
8851
  resolveSmartCatalogGroup(nodeId, candidates, matchers) {
8443
- var _a, _b;
8852
+ var _a2, _b;
8444
8853
  const next = resolveSmartCatalogGroup(
8445
8854
  this.catalog,
8446
8855
  nodeId,
@@ -8451,7 +8860,7 @@ var Editor = class {
8451
8860
  const node = next == null ? void 0 : next.nodes.find(
8452
8861
  (x) => x.id === nodeId && x.kind === "smart-group"
8453
8862
  );
8454
- return (_b = (_a = node == null ? void 0 : node.resolvedServiceIds) == null ? void 0 : _a.slice()) != null ? _b : [];
8863
+ return (_b = (_a2 = node == null ? void 0 : node.resolvedServiceIds) == null ? void 0 : _a2.slice()) != null ? _b : [];
8455
8864
  }
8456
8865
  replaceCatalog(next, reason = "catalog:set") {
8457
8866
  this.catalog = (0, import_lodash_es4.cloneDeep)(next);
@@ -8531,9 +8940,8 @@ var Editor = class {
8531
8940
  Array.isArray(canvas.selection) ? canvas.selection : Array.from(canvas.selection)
8532
8941
  );
8533
8942
  }
8534
- } else {
8535
- this.api.refreshGraph();
8536
8943
  }
8944
+ this.api.refreshGraph();
8537
8945
  this.emit("editor:change", { props: s.props, reason, snapshot: s });
8538
8946
  }
8539
8947
  pushHistory(snap) {
@@ -8653,9 +9061,9 @@ var Selection = class {
8653
9061
  }
8654
9062
  // ── Main: visible group snapshot (env-aware) ─────────────────────────────
8655
9063
  visibleGroup() {
8656
- var _a;
9064
+ var _a2;
8657
9065
  const props = this.builder.getProps();
8658
- if (((_a = this.opts.env) != null ? _a : "client") === "workspace") {
9066
+ if (((_a2 = this.opts.env) != null ? _a2 : "client") === "workspace") {
8659
9067
  const tagIds = Array.from(this.set).filter(
8660
9068
  this.builder.isTagId.bind(this.builder)
8661
9069
  );
@@ -8686,12 +9094,12 @@ var Selection = class {
8686
9094
  * - de-dupes per field
8687
9095
  */
8688
9096
  buttonSelectionsByFieldId() {
8689
- var _a, _b, _c, _d, _e;
9097
+ var _a2, _b, _c, _d, _e;
8690
9098
  const nodeMap = this.builder.getNodeMap();
8691
9099
  const out = {};
8692
9100
  const push = (fieldId, triggerKey) => {
8693
- var _a2;
8694
- const arr = (_a2 = out[fieldId]) != null ? _a2 : out[fieldId] = [];
9101
+ var _a3;
9102
+ const arr = (_a3 = out[fieldId]) != null ? _a3 : out[fieldId] = [];
8695
9103
  if (!arr.includes(triggerKey)) arr.push(triggerKey);
8696
9104
  };
8697
9105
  for (const key of this.set) {
@@ -8708,7 +9116,7 @@ var Selection = class {
8708
9116
  const ref = nodeMap.get(key);
8709
9117
  if (!ref) continue;
8710
9118
  if (ref.kind === "option" && typeof ref.fieldId === "string") {
8711
- push(ref.fieldId, (_a = ref.id) != null ? _a : key);
9119
+ push(ref.fieldId, (_a2 = ref.id) != null ? _a2 : key);
8712
9120
  continue;
8713
9121
  }
8714
9122
  if (ref.kind === "field") {
@@ -8729,7 +9137,7 @@ var Selection = class {
8729
9137
  * Excludes tags and non-button fields.
8730
9138
  */
8731
9139
  selectedButtons() {
8732
- var _a, _b;
9140
+ var _a2, _b;
8733
9141
  const nodeMap = this.builder.getNodeMap();
8734
9142
  const out = [];
8735
9143
  const seen = /* @__PURE__ */ new Set();
@@ -8755,7 +9163,7 @@ var Selection = class {
8755
9163
  continue;
8756
9164
  }
8757
9165
  if (ref.kind === "field") {
8758
- const field = (_b = (_a = ref.node) != null ? _a : ref.field) != null ? _b : ref;
9166
+ const field = (_b = (_a2 = ref.node) != null ? _a2 : ref.field) != null ? _b : ref;
8759
9167
  if ((field == null ? void 0 : field.button) === true) push(key);
8760
9168
  }
8761
9169
  }
@@ -8770,9 +9178,9 @@ var Selection = class {
8770
9178
  for (const fn of this.onChangeFns) fn(payload);
8771
9179
  }
8772
9180
  updateCurrentTagFrom(id) {
8773
- var _a, _b;
9181
+ var _a2, _b;
8774
9182
  const props = this.builder.getProps();
8775
- const tags = (_a = props.filters) != null ? _a : [];
9183
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
8776
9184
  const fields = (_b = props.fields) != null ? _b : [];
8777
9185
  if (tags.some((t) => t.id === id)) {
8778
9186
  this.currentTagId = id;
@@ -8788,8 +9196,8 @@ var Selection = class {
8788
9196
  if (this.builder.isOptionId(id)) {
8789
9197
  return fields.find(
8790
9198
  (x) => {
8791
- var _a2;
8792
- return ((_a2 = x.options) != null ? _a2 : []).some((o) => o.id === id);
9199
+ var _a3;
9200
+ return ((_a3 = x.options) != null ? _a3 : []).some((o) => o.id === id);
8793
9201
  }
8794
9202
  );
8795
9203
  }
@@ -8816,10 +9224,10 @@ var Selection = class {
8816
9224
  if (fallbackTagId) this.currentTagId = fallbackTagId;
8817
9225
  }
8818
9226
  resolveTagContextId(props) {
8819
- var _a;
9227
+ var _a2;
8820
9228
  if (this.currentTagId) return this.currentTagId;
8821
9229
  for (const id of this.set) if (this.builder.isTagId(id)) return id;
8822
- const fields = (_a = props.fields) != null ? _a : [];
9230
+ const fields = (_a2 = props.fields) != null ? _a2 : [];
8823
9231
  for (const id of this.set) {
8824
9232
  const f = fields.find((x) => x.id === id);
8825
9233
  if (f == null ? void 0 : f.bind_id)
@@ -8829,8 +9237,8 @@ var Selection = class {
8829
9237
  if (this.builder.isOptionId(id)) {
8830
9238
  const host = fields.find(
8831
9239
  (x) => {
8832
- var _a2;
8833
- return ((_a2 = x.options) != null ? _a2 : []).some((o) => o.id === id);
9240
+ var _a3;
9241
+ return ((_a3 = x.options) != null ? _a3 : []).some((o) => o.id === id);
8834
9242
  }
8835
9243
  );
8836
9244
  if (host == null ? void 0 : host.bind_id)
@@ -8846,8 +9254,8 @@ var Selection = class {
8846
9254
  return this.opts.rootTagId;
8847
9255
  }
8848
9256
  computeGroupForTag(props, tagId) {
8849
- var _a, _b, _c, _d, _e, _f, _g;
8850
- const tags = (_a = props.filters) != null ? _a : [];
9257
+ var _a2, _b, _c, _d, _e, _f, _g;
9258
+ const tags = (_a2 = props.filters) != null ? _a2 : [];
8851
9259
  const fields = (_b = props.fields) != null ? _b : [];
8852
9260
  const tagById = new Map(tags.map((t) => [t.id, t]));
8853
9261
  const tag = tagById.get(tagId);
@@ -8931,10 +9339,10 @@ var Selection = class {
8931
9339
  return baseOverridden;
8932
9340
  }
8933
9341
  findOptionById(fields, selId) {
8934
- var _a, _b;
9342
+ var _a2, _b;
8935
9343
  if (this.builder.isOptionId(selId)) {
8936
9344
  for (const f of fields) {
8937
- const o = (_a = f.options) == null ? void 0 : _a.find((x) => x.id === selId);
9345
+ const o = (_a2 = f.options) == null ? void 0 : _a2.find((x) => x.id === selId);
8938
9346
  if (o) return o;
8939
9347
  }
8940
9348
  }
@@ -8959,9 +9367,9 @@ var CanvasAPI = class {
8959
9367
  /* ─── Option-node visibility (per field) ───────────────────────────────── */
8960
9368
  /** Internal mirror of which fields should show their options as nodes. */
8961
9369
  this.shownOptionFields = /* @__PURE__ */ new Set();
8962
- var _a, _b, _c;
9370
+ var _a2, _b, _c;
8963
9371
  this.builder = builder;
8964
- this.autoEmit = (_a = opts.autoEmitState) != null ? _a : true;
9372
+ this.autoEmit = (_a2 = opts.autoEmitState) != null ? _a2 : true;
8965
9373
  this.selection = new Selection(builder, {
8966
9374
  env: "workspace",
8967
9375
  rootTagId: "t:root"
@@ -9188,14 +9596,14 @@ function useOptionalFormApi() {
9188
9596
  }
9189
9597
  function FormProvider({ children, schema, initial }) {
9190
9598
  const [bag, setBag] = React.useState(() => {
9191
- var _a;
9599
+ var _a2;
9192
9600
  return {
9193
- ...(_a = initial == null ? void 0 : initial.values) != null ? _a : {}
9601
+ ...(_a2 = initial == null ? void 0 : initial.values) != null ? _a2 : {}
9194
9602
  };
9195
9603
  });
9196
9604
  const [selectionsBag, setSelectionsBag] = React.useState(() => {
9197
- var _a;
9198
- return { ...(_a = initial == null ? void 0 : initial.selections) != null ? _a : {} };
9605
+ var _a2;
9606
+ return { ...(_a2 = initial == null ? void 0 : initial.selections) != null ? _a2 : {} };
9199
9607
  });
9200
9608
  const listenersRef = React.useRef(/* @__PURE__ */ new Set());
9201
9609
  const publish = React.useCallback(() => {
@@ -9221,9 +9629,9 @@ function FormProvider({ children, schema, initial }) {
9221
9629
  return () => listenersRef.current.delete(fn);
9222
9630
  },
9223
9631
  get(fieldId) {
9224
- var _a, _b;
9632
+ var _a2, _b;
9225
9633
  const core = coreRef.current;
9226
- const live = (_b = (_a = core == null ? void 0 : core.values) == null ? void 0 : _a.call(core)) != null ? _b : void 0;
9634
+ const live = (_b = (_a2 = core == null ? void 0 : core.values) == null ? void 0 : _a2.call(core)) != null ? _b : void 0;
9227
9635
  if (live && fieldId in live) return live[fieldId];
9228
9636
  return bag[fieldId];
9229
9637
  },
@@ -9238,8 +9646,8 @@ function FormProvider({ children, schema, initial }) {
9238
9646
  },
9239
9647
  // Legacy selections API (compat; no longer used by the new Wrapper)
9240
9648
  getSelections(fieldId) {
9241
- var _a;
9242
- return (_a = selectionsBag[fieldId]) != null ? _a : [];
9649
+ var _a2;
9650
+ return (_a2 = selectionsBag[fieldId]) != null ? _a2 : [];
9243
9651
  },
9244
9652
  setSelections(fieldId, optionIds) {
9245
9653
  setSelectionsBag((prev) => ({
@@ -9250,8 +9658,8 @@ function FormProvider({ children, schema, initial }) {
9250
9658
  },
9251
9659
  toggleSelection(fieldId, optionId) {
9252
9660
  setSelectionsBag((prev) => {
9253
- var _a;
9254
- const current = new Set((_a = prev[fieldId]) != null ? _a : []);
9661
+ var _a2;
9662
+ const current = new Set((_a2 = prev[fieldId]) != null ? _a2 : []);
9255
9663
  if (current.has(optionId)) current.delete(optionId);
9256
9664
  else current.add(optionId);
9257
9665
  return { ...prev, [fieldId]: Array.from(current) };
@@ -9262,17 +9670,17 @@ function FormProvider({ children, schema, initial }) {
9262
9670
  const [fieldId, optionId] = String(token).split(":", 2);
9263
9671
  if (!fieldId || !optionId) return;
9264
9672
  setSelectionsBag((prev) => {
9265
- var _a;
9266
- const current = new Set((_a = prev[fieldId]) != null ? _a : []);
9673
+ var _a2;
9674
+ const current = new Set((_a2 = prev[fieldId]) != null ? _a2 : []);
9267
9675
  current.delete(optionId);
9268
9676
  return { ...prev, [fieldId]: Array.from(current) };
9269
9677
  });
9270
9678
  publish();
9271
9679
  },
9272
9680
  snapshot() {
9273
- var _a, _b;
9681
+ var _a2, _b;
9274
9682
  const core = coreRef.current;
9275
- const live = (_b = (_a = core == null ? void 0 : core.values) == null ? void 0 : _a.call(core)) != null ? _b : {};
9683
+ const live = (_b = (_a2 = core == null ? void 0 : core.values) == null ? void 0 : _a2.call(core)) != null ? _b : {};
9276
9684
  return live;
9277
9685
  },
9278
9686
  submit() {
@@ -9312,11 +9720,11 @@ function FormProvider({ children, schema, initial }) {
9312
9720
  function createInputRegistry() {
9313
9721
  const store = /* @__PURE__ */ new Map();
9314
9722
  const get = (kind, variant) => {
9315
- var _a;
9723
+ var _a2;
9316
9724
  const vm = store.get(kind);
9317
9725
  if (!vm) return void 0;
9318
9726
  const v = variant != null ? variant : "default";
9319
- return (_a = vm.get(v)) != null ? _a : vm.get("default");
9727
+ return (_a2 = vm.get(v)) != null ? _a2 : vm.get("default");
9320
9728
  };
9321
9729
  const register = (kind, descriptor, variant) => {
9322
9730
  let vm = store.get(kind);
@@ -9370,6 +9778,9 @@ function useInputs() {
9370
9778
  if (!v) throw new Error("useInputs() must be used within <InputsProvider>");
9371
9779
  return v;
9372
9780
  }
9781
+ function useInputsMaybe() {
9782
+ return (0, import_react2.useContext)(Ctx2);
9783
+ }
9373
9784
 
9374
9785
  // src/react/inputs/wrapper.tsx
9375
9786
  var React4 = __toESM(require("react"), 1);
@@ -9398,9 +9809,9 @@ function findDefaultTagId(tags) {
9398
9809
  return hasRoot ? ROOT_TAG_ID : tags[0].id;
9399
9810
  }
9400
9811
  function mapSnapshotFormToFieldIds(builder, snap) {
9401
- var _a, _b, _c, _d, _e;
9812
+ var _a2, _b, _c, _d, _e;
9402
9813
  const byFieldId = {};
9403
- const form = (_b = (_a = snap.inputs) == null ? void 0 : _a.form) != null ? _b : {};
9814
+ const form = (_b = (_a2 = snap.inputs) == null ? void 0 : _a2.form) != null ? _b : {};
9404
9815
  const fields = (_c = builder.getProps().fields) != null ? _c : [];
9405
9816
  const nameToIds = /* @__PURE__ */ new Map();
9406
9817
  for (const f of fields) {
@@ -9426,8 +9837,8 @@ function makeDefaultFallback(mode, patch) {
9426
9837
  };
9427
9838
  }
9428
9839
  function normalizeInit(init) {
9429
- var _a, _b, _c;
9430
- const mode = (_a = init.mode) != null ? _a : "prod";
9840
+ var _a2, _b, _c;
9841
+ const mode = (_a2 = init.mode) != null ? _a2 : "prod";
9431
9842
  const hostDefaultQuantity = Number.isFinite((_b = init.hostDefaultQuantity) != null ? _b : 1) ? Number((_c = init.hostDefaultQuantity) != null ? _c : 1) : 1;
9432
9843
  return { ...init, mode, hostDefaultQuantity };
9433
9844
  }
@@ -9469,8 +9880,8 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9469
9880
  const bump = () => force((x) => x + 1);
9470
9881
  const resolveBuilder = (0, import_react4.useCallback)(
9471
9882
  (p) => {
9472
- var _a, _b;
9473
- if ((_a = p.flow) == null ? void 0 : _a.builder) return p.flow.builder;
9883
+ var _a2, _b;
9884
+ if ((_a2 = p.flow) == null ? void 0 : _a2.builder) return p.flow.builder;
9474
9885
  if (p.builder) return p.builder;
9475
9886
  if (p.serviceProps) {
9476
9887
  const b = createBuilder((_b = p.builderOptions) != null ? _b : {});
@@ -9506,8 +9917,8 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9506
9917
  }, []);
9507
9918
  const resolveSelection = (0, import_react4.useCallback)(
9508
9919
  (b, nInit, p) => {
9509
- var _a, _b, _c;
9510
- return (_c = (_b = (_a = p.flow) == null ? void 0 : _a.selection) != null ? _b : p.selection) != null ? _c : new Selection(b, {
9920
+ var _a2, _b, _c;
9921
+ return (_c = (_b = (_a2 = p.flow) == null ? void 0 : _a2.selection) != null ? _b : p.selection) != null ? _c : new Selection(b, {
9511
9922
  env: "client",
9512
9923
  rootTagId: ROOT_TAG_ID,
9513
9924
  resolveService: nInit.resolveService
@@ -9537,7 +9948,7 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9537
9948
  }, []);
9538
9949
  const initialize = (0, import_react4.useCallback)(
9539
9950
  (params) => {
9540
- var _a, _b, _c, _d, _e, _f;
9951
+ var _a2, _b, _c, _d, _e, _f;
9541
9952
  const b = resolveBuilder(params);
9542
9953
  if (!b) {
9543
9954
  throw new Error(
@@ -9557,7 +9968,7 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9557
9968
  unsubRef.current = sel.onChange(
9558
9969
  () => setActiveTagId(sel.currentTag())
9559
9970
  );
9560
- const tags = (_a = b.getProps().filters) != null ? _a : [];
9971
+ const tags = (_a2 = b.getProps().filters) != null ? _a2 : [];
9561
9972
  const hydratedTag = (_c = (_b = nInit.hydrateFrom) == null ? void 0 : _b.selection) == null ? void 0 : _c.tag;
9562
9973
  const initialTag = nInit.hydrateFrom ? hydratedTag : (_d = nInit.initialTagId) != null ? _d : findDefaultTagId(tags);
9563
9974
  if (initialTag) sel.replace(initialTag);
@@ -9610,14 +10021,14 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9610
10021
  serviceProps
9611
10022
  ]);
9612
10023
  (0, import_react4.useEffect)(() => {
9613
- var _a, _b, _c, _d, _e;
10024
+ var _a2, _b, _c, _d, _e;
9614
10025
  if (!serviceProps) return;
9615
10026
  if (!ready()) return;
9616
10027
  const currentBuilder = builderRef.current;
9617
10028
  if (!currentBuilder || currentBuilder !== resolvedBuilder) return;
9618
10029
  if (!sameServiceProps(currentBuilder.getProps(), serviceProps)) {
9619
10030
  currentBuilder.load(serviceProps);
9620
- const currentTag = (_a = selectionRef.current) == null ? void 0 : _a.currentTag();
10031
+ const currentTag = (_a2 = selectionRef.current) == null ? void 0 : _a2.currentTag();
9621
10032
  if (selectionRef.current && currentTag && !currentBuilder.isTagId(currentTag)) {
9622
10033
  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;
9623
10034
  if (nextTag) selectionRef.current.replace(nextTag);
@@ -9639,12 +10050,12 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9639
10050
  [ensureReady]
9640
10051
  );
9641
10052
  const clearAllFields = (0, import_react4.useCallback)(() => {
9642
- var _a;
10053
+ var _a2;
9643
10054
  const api = formApiRef.current;
9644
10055
  if (!api) return;
9645
10056
  const b = builderRef.current;
9646
10057
  if (!b) return;
9647
- const fields = (_a = b.getProps().fields) != null ? _a : [];
10058
+ const fields = (_a2 = b.getProps().fields) != null ? _a2 : [];
9648
10059
  for (const f of fields) {
9649
10060
  api.set(f.id, void 0);
9650
10061
  api.setSelections(f.id, []);
@@ -9652,11 +10063,11 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9652
10063
  }, []);
9653
10064
  const setSnapshot = (0, import_react4.useCallback)(
9654
10065
  (snap, opts) => {
9655
- var _a, _b, _c, _d;
10066
+ var _a2, _b, _c, _d;
9656
10067
  const api = formApiRef.current;
9657
10068
  if (!api) return;
9658
10069
  const { builder, selection } = ensureReady("setSnapshot");
9659
- const clearFirst = (_a = opts == null ? void 0 : opts.clearFirst) != null ? _a : true;
10070
+ const clearFirst = (_a2 = opts == null ? void 0 : opts.clearFirst) != null ? _a2 : true;
9660
10071
  const tag = (_b = snap.selection) == null ? void 0 : _b.tag;
9661
10072
  if (tag) selection.replace(tag);
9662
10073
  if (clearFirst) clearAllFields();
@@ -9671,8 +10082,8 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9671
10082
  );
9672
10083
  const reset = (0, import_react4.useCallback)(
9673
10084
  (opts) => {
9674
- var _a, _b, _c, _d;
9675
- const keepTag = (_a = opts == null ? void 0 : opts.keepTag) != null ? _a : false;
10085
+ var _a2, _b, _c, _d;
10086
+ const keepTag = (_a2 = opts == null ? void 0 : opts.keepTag) != null ? _a2 : false;
9676
10087
  const { builder, selection } = ensureReady("reset");
9677
10088
  if (!keepTag) {
9678
10089
  const tags = (_b = builder.getProps().filters) != null ? _b : [];
@@ -9702,10 +10113,10 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9702
10113
  return mapSnapshotFormToFieldIds(b, i.hydrateFrom);
9703
10114
  }, [force]);
9704
10115
  const initialSelections = (0, import_react4.useMemo)(() => {
9705
- var _a, _b;
10116
+ var _a2, _b;
9706
10117
  const i = initRef.current;
9707
10118
  if (!(i == null ? void 0 : i.hydrateFrom)) return {};
9708
- return (_b = (_a = i.hydrateFrom.inputs) == null ? void 0 : _a.selections) != null ? _b : {};
10119
+ return (_b = (_a2 = i.hydrateFrom.inputs) == null ? void 0 : _a2.selections) != null ? _b : {};
9709
10120
  }, [force]);
9710
10121
  (0, import_react4.useImperativeHandle)(
9711
10122
  ref,
@@ -9720,8 +10131,8 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9720
10131
  setSnapshot,
9721
10132
  reset,
9722
10133
  refresh: () => {
9723
- var _a;
9724
- return setActiveTagId((_a = selectionRef.current) == null ? void 0 : _a.currentTag());
10134
+ var _a2;
10135
+ return setActiveTagId((_a2 = selectionRef.current) == null ? void 0 : _a2.currentTag());
9725
10136
  }
9726
10137
  }),
9727
10138
  [
@@ -9770,8 +10181,8 @@ var OrderFlowProvider = (0, import_react4.forwardRef)(function OrderFlowProvider
9770
10181
 
9771
10182
  // src/react/hooks/evalute-field-validation.ts
9772
10183
  function evaluateFieldValidationRule(rule, raw) {
9773
- var _a, _b;
9774
- const valueBy = (_a = rule.valueBy) != null ? _a : "value";
10184
+ var _a2, _b;
10185
+ const valueBy = (_a2 = rule.valueBy) != null ? _a2 : "value";
9775
10186
  let subject = raw;
9776
10187
  if (valueBy === "length") {
9777
10188
  if (typeof raw === "string" || Array.isArray(raw)) subject = raw.length;
@@ -9816,11 +10227,11 @@ function evaluateFieldValidationRule(rule, raw) {
9816
10227
  }
9817
10228
  }
9818
10229
  function validateVisibleFields(visibleFieldIds, fieldById, formValuesByFieldId) {
9819
- var _a;
10230
+ var _a2;
9820
10231
  const out = [];
9821
10232
  for (const fid of visibleFieldIds) {
9822
10233
  const field = fieldById.get(fid);
9823
- if (!((_a = field == null ? void 0 : field.validation) == null ? void 0 : _a.length)) continue;
10234
+ if (!((_a2 = field == null ? void 0 : field.validation) == null ? void 0 : _a2.length)) continue;
9824
10235
  const value = formValuesByFieldId[fid];
9825
10236
  for (const rule of field.validation) {
9826
10237
  const ok = evaluateFieldValidationRule(rule, value);
@@ -9840,7 +10251,7 @@ function validateVisibleFields(visibleFieldIds, fieldById, formValuesByFieldId)
9840
10251
  // src/react/hooks/use-order-flow.ts
9841
10252
  var ROOT_TAG_ID2 = "t:root";
9842
10253
  function useOrderFlow() {
9843
- var _a, _b, _c;
10254
+ var _a2, _b, _c;
9844
10255
  const ctx = useOrderFlowContext();
9845
10256
  const ready = ctx.ready();
9846
10257
  const initialize = (0, import_react6.useCallback)(
@@ -9866,22 +10277,22 @@ function useOrderFlow() {
9866
10277
  return ctx.formApi.subscribe(() => setFormTick((x) => x + 1));
9867
10278
  }, [ctx.formApi]);
9868
10279
  const visibleGroup = (0, import_react6.useMemo)(() => {
9869
- var _a2;
10280
+ var _a3;
9870
10281
  if (!ready) return null;
9871
10282
  const sel = ctx.selection;
9872
10283
  if (!sel) return null;
9873
10284
  const vg = sel.visibleGroup();
9874
10285
  if (vg.kind !== "single") return null;
9875
- return (_a2 = vg.group) != null ? _a2 : null;
10286
+ return (_a3 = vg.group) != null ? _a3 : null;
9876
10287
  }, [ready, ctx.selection, selTick]);
9877
10288
  const activeTagId = (0, import_react6.useMemo)(() => {
9878
- var _a2, _b2, _c2;
10289
+ var _a3, _b2, _c2;
9879
10290
  if (!ready) return void 0;
9880
- return (_c2 = (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.currentTag) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : ctx.activeTagId;
10291
+ return (_c2 = (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.currentTag) == null ? void 0 : _b2.call(_a3)) != null ? _c2 : ctx.activeTagId;
9881
10292
  }, [ready, ctx.selection, ctx.activeTagId, selTick]);
9882
10293
  const formValuesByFieldId = (0, import_react6.useMemo)(() => {
9883
- var _a2, _b2, _c2;
9884
- const values = (_c2 = (_b2 = (_a2 = ctx.formApi).snapshot) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : {};
10294
+ var _a3, _b2, _c2;
10295
+ const values = (_c2 = (_b2 = (_a3 = ctx.formApi).snapshot) == null ? void 0 : _b2.call(_a3)) != null ? _c2 : {};
9885
10296
  return values;
9886
10297
  }, [ctx.formApi, formTick]);
9887
10298
  const optionSelectionsByFieldId = (0, import_react6.useMemo)(
@@ -9889,7 +10300,7 @@ function useOrderFlow() {
9889
10300
  []
9890
10301
  );
9891
10302
  const previewSnapshot = (0, import_react6.useMemo)(() => {
9892
- var _a2, _b2, _c2;
10303
+ var _a3, _b2, _c2;
9893
10304
  if (!ready) {
9894
10305
  return {
9895
10306
  version: "1",
@@ -9904,7 +10315,7 @@ function useOrderFlow() {
9904
10315
  max: 1,
9905
10316
  serviceMap: {},
9906
10317
  meta: {
9907
- schema_version: (_a2 = propsRef.current) == null ? void 0 : _a2.schema_version,
10318
+ schema_version: (_a3 = propsRef.current) == null ? void 0 : _a3.schema_version,
9908
10319
  context: {
9909
10320
  tag: "unknown",
9910
10321
  constraints: {},
@@ -9946,7 +10357,7 @@ function useOrderFlow() {
9946
10357
  selTick
9947
10358
  ]);
9948
10359
  const pricingPreview = (0, import_react6.useMemo)(() => {
9949
- var _a2, _b2, _c2, _d, _e, _f;
10360
+ var _a3, _b2, _c2, _d, _e, _f;
9950
10361
  const empty = {
9951
10362
  unitRate: 0,
9952
10363
  base: 0,
@@ -9956,7 +10367,7 @@ function useOrderFlow() {
9956
10367
  };
9957
10368
  if (!ready) return empty;
9958
10369
  const { init } = ctx.ensureReady("pricingPreview");
9959
- const normalizeRate = (_a2 = init.normalizeRate) != null ? _a2 : ((s) => Number(s == null ? void 0 : s.rate));
10370
+ const normalizeRate = (_a3 = init.normalizeRate) != null ? _a3 : ((s) => Number(s == null ? void 0 : s.rate));
9960
10371
  const quantity = Number((_b2 = previewSnapshot.quantity) != null ? _b2 : 1) || 1;
9961
10372
  let bestId;
9962
10373
  let bestRate = 0;
@@ -10014,18 +10425,18 @@ function useOrderFlow() {
10014
10425
  }, [ready, ctx, previewSnapshot]);
10015
10426
  const selectTag = (0, import_react6.useCallback)(
10016
10427
  (tagId) => {
10017
- var _a2, _b2;
10428
+ var _a3, _b2;
10018
10429
  ctx.ensureReady("selectTag");
10019
- (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.replace) == null ? void 0 : _b2.call(_a2, tagId);
10430
+ (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.replace) == null ? void 0 : _b2.call(_a3, tagId);
10020
10431
  ctx.setActiveTag(tagId);
10021
10432
  },
10022
10433
  [ctx]
10023
10434
  );
10024
10435
  const toggleOption = (0, import_react6.useCallback)(
10025
10436
  (fieldId, optionId) => {
10026
- var _a2, _b2;
10437
+ var _a3, _b2;
10027
10438
  const token = optionId != null ? optionId : fieldId;
10028
- (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.toggle) == null ? void 0 : _b2.call(_a2, token);
10439
+ (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.toggle) == null ? void 0 : _b2.call(_a3, token);
10029
10440
  },
10030
10441
  [ctx]
10031
10442
  );
@@ -10037,9 +10448,9 @@ function useOrderFlow() {
10037
10448
  );
10038
10449
  const clearField = (0, import_react6.useCallback)(
10039
10450
  (fieldId) => {
10040
- var _a2, _b2;
10451
+ var _a3, _b2;
10041
10452
  ctx.formApi.set(fieldId, void 0);
10042
- (_b2 = (_a2 = ctx.selection) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2, fieldId);
10453
+ (_b2 = (_a3 = ctx.selection) == null ? void 0 : _a3.remove) == null ? void 0 : _b2.call(_a3, fieldId);
10043
10454
  },
10044
10455
  [ctx]
10045
10456
  );
@@ -10058,14 +10469,14 @@ function useOrderFlow() {
10058
10469
  [ctx]
10059
10470
  );
10060
10471
  const buildSnapshot = (0, import_react6.useCallback)(() => {
10061
- var _a2, _b2, _c2, _d, _e, _f;
10472
+ var _a3, _b2, _c2, _d, _e, _f;
10062
10473
  const { builder, selection, init } = ctx.ensureReady("buildSnapshot");
10063
10474
  const tagId = selection.currentTag();
10064
10475
  const selectedKeys = selection.selectedButtons();
10065
10476
  if (!tagId) {
10066
10477
  throw new Error("OrderFlow: no active tag/context selected");
10067
10478
  }
10068
- const mode = (_a2 = init.mode) != null ? _a2 : "prod";
10479
+ const mode = (_a3 = init.mode) != null ? _a3 : "prod";
10069
10480
  const hostDefaultQuantity = Number((_b2 = init.hostDefaultQuantity) != null ? _b2 : 1) || 1;
10070
10481
  const submitted = ctx.formApi.submit();
10071
10482
  const values = submitted.values;
@@ -10106,13 +10517,13 @@ function useOrderFlow() {
10106
10517
  );
10107
10518
  }, [ctx, optionSelectionsByFieldId]);
10108
10519
  const raw = (0, import_react6.useMemo)(() => {
10109
- var _a2;
10110
- if (!ready) return (_a2 = propsRef.current) != null ? _a2 : {};
10520
+ var _a3;
10521
+ if (!ready) return (_a3 = propsRef.current) != null ? _a3 : {};
10111
10522
  return ctx.ensureReady("raw").builder.getProps();
10112
10523
  }, [ctx, ready, selTick]);
10113
10524
  const notices = (0, import_react6.useMemo)(() => {
10114
- var _a2;
10115
- return (_a2 = raw.notices) != null ? _a2 : [];
10525
+ var _a3;
10526
+ return (_a3 = raw.notices) != null ? _a3 : [];
10116
10527
  }, [raw]);
10117
10528
  return {
10118
10529
  ready,
@@ -10127,7 +10538,7 @@ function useOrderFlow() {
10127
10538
  services: previewSnapshot.services,
10128
10539
  serviceMap: previewSnapshot.serviceMap,
10129
10540
  pricingPreview,
10130
- min: (_a = previewSnapshot.min) != null ? _a : 1,
10541
+ min: (_a2 = previewSnapshot.min) != null ? _a2 : 1,
10131
10542
  max: (_c = (_b = previewSnapshot.max) != null ? _b : previewSnapshot.min) != null ? _c : 1,
10132
10543
  selectTag,
10133
10544
  toggleOption,
@@ -10147,8 +10558,8 @@ function toKind(field) {
10147
10558
  return field.type;
10148
10559
  }
10149
10560
  function toVariant(field) {
10150
- var _a;
10151
- const v = (_a = field.meta) == null ? void 0 : _a.variant;
10561
+ var _a2;
10562
+ const v = (_a2 = field.meta) == null ? void 0 : _a2.variant;
10152
10563
  return typeof v === "string" && v.trim() ? v : void 0;
10153
10564
  }
10154
10565
  function getPath(ctx, path) {
@@ -10221,7 +10632,7 @@ function Wrapper({
10221
10632
  ctxOverrides,
10222
10633
  className = ""
10223
10634
  }) {
10224
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
10635
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
10225
10636
  const { registry } = useInputs();
10226
10637
  const flow = useOrderFlow();
10227
10638
  const kind = toKind(field);
@@ -10235,11 +10646,11 @@ function Wrapper({
10235
10646
  return null;
10236
10647
  }
10237
10648
  const Component = descriptor.Component;
10238
- const adapter = (_a = descriptor.adapter) != null ? _a : {};
10649
+ const adapter = (_a2 = descriptor.adapter) != null ? _a2 : {};
10239
10650
  const baseProps = (_b = descriptor.defaultProps) != null ? _b : {};
10240
10651
  const defaultProps = (0, import_react7.useMemo)(() => {
10241
- var _a2;
10242
- return { ...baseProps, ...(_a2 = field.defaults) != null ? _a2 : {} };
10652
+ var _a3;
10653
+ return { ...baseProps, ...(_a3 = field.defaults) != null ? _a3 : {} };
10243
10654
  }, [baseProps, field.defaults]);
10244
10655
  const valueProp = (_c = adapter.valueProp) != null ? _c : "value";
10245
10656
  const changeProp = (_d = adapter.changeProp) != null ? _d : "onChange";
@@ -10254,9 +10665,9 @@ function Wrapper({
10254
10665
  disabled: !!disabled
10255
10666
  });
10256
10667
  const optionIds = React4.useMemo(() => {
10257
- var _a2;
10668
+ var _a3;
10258
10669
  if (!isOptionBased2) return /* @__PURE__ */ new Set();
10259
- return new Set(((_a2 = field.options) != null ? _a2 : []).map((o) => o.id));
10670
+ return new Set(((_a3 = field.options) != null ? _a3 : []).map((o) => o.id));
10260
10671
  }, [isOptionBased2, field.options]);
10261
10672
  const prevSelectedRef = React4.useRef([]);
10262
10673
  React4.useEffect(() => {
@@ -10268,9 +10679,9 @@ function Wrapper({
10268
10679
  );
10269
10680
  const onHostChange = React4.useCallback(
10270
10681
  (next) => {
10271
- var _a2, _b2, _c2, _d2, _e2;
10682
+ var _a3, _b2, _c2, _d2, _e2;
10272
10683
  const currentStored = next == null ? void 0 : next.value;
10273
- const stored = (_c2 = (_b2 = (_a2 = adapter.getValue) == null ? void 0 : _a2.call(adapter, next, currentStored, adapterCtx)) != null ? _b2 : currentStored) != null ? _c2 : next;
10684
+ const stored = (_c2 = (_b2 = (_a3 = adapter.getValue) == null ? void 0 : _a3.call(adapter, next, currentStored, adapterCtx)) != null ? _b2 : currentStored) != null ? _c2 : next;
10274
10685
  fp.setValue(stored);
10275
10686
  if (isOptionBased2) {
10276
10687
  if (!adapter.getSelectedOptions) {
@@ -10319,8 +10730,8 @@ function Wrapper({
10319
10730
  ]
10320
10731
  );
10321
10732
  const templateCtx = React4.useMemo(() => {
10322
- var _a2, _b2;
10323
- const ctxFromInit = (_b2 = (_a2 = flow.init) == null ? void 0 : _a2.ctx) != null ? _b2 : {};
10733
+ var _a3, _b2;
10734
+ const ctxFromInit = (_b2 = (_a3 = flow.init) == null ? void 0 : _a3.ctx) != null ? _b2 : {};
10324
10735
  const ctx = ctxOverrides && typeof ctxOverrides === "object" ? { ...ctxFromInit, ...ctxOverrides } : ctxFromInit;
10325
10736
  return {
10326
10737
  ...ctx,
@@ -10822,6 +11233,12 @@ var phoneDescriptor = {
10822
11233
  var import_form_palette6 = require("@timeax/form-palette");
10823
11234
  var toggleGroupDescriptor = {
10824
11235
  Component: import_form_palette6.InputField,
11236
+ options: {
11237
+ supported: true,
11238
+ autoCreate: true,
11239
+ defaultLabel: "Option label",
11240
+ defaultValue: "option"
11241
+ },
10825
11242
  defaultProps: {
10826
11243
  variant: "toggle-group",
10827
11244
  // MUST
@@ -11339,6 +11756,12 @@ var toggleDescriptor = {
11339
11756
  var import_form_palette11 = require("@timeax/form-palette");
11340
11757
  var treeSelectDescriptor = {
11341
11758
  Component: import_form_palette11.InputField,
11759
+ options: {
11760
+ supported: true,
11761
+ autoCreate: true,
11762
+ defaultLabel: "Option label",
11763
+ defaultValue: "option"
11764
+ },
11342
11765
  defaultProps: {
11343
11766
  variant: "treeselect",
11344
11767
  // MUST
@@ -11419,6 +11842,12 @@ var treeSelectDescriptor = {
11419
11842
  var import_form_palette12 = require("@timeax/form-palette");
11420
11843
  var multiSelectDescriptor = {
11421
11844
  Component: import_form_palette12.InputField,
11845
+ options: {
11846
+ supported: true,
11847
+ autoCreate: true,
11848
+ defaultLabel: "Option label",
11849
+ defaultValue: "option"
11850
+ },
11422
11851
  defaultProps: {
11423
11852
  variant: "multi-select",
11424
11853
  // MUST
@@ -11465,6 +11894,12 @@ var multiSelectDescriptor = {
11465
11894
  var import_form_palette13 = require("@timeax/form-palette");
11466
11895
  var selectDescriptor = {
11467
11896
  Component: import_form_palette13.InputField,
11897
+ options: {
11898
+ supported: true,
11899
+ autoCreate: true,
11900
+ defaultLabel: "Option label",
11901
+ defaultValue: "option"
11902
+ },
11468
11903
  defaultProps: {
11469
11904
  variant: "select",
11470
11905
  // MUST
@@ -11499,6 +11934,12 @@ var selectDescriptor = {
11499
11934
  var import_form_palette14 = require("@timeax/form-palette");
11500
11935
  var radioDescriptor = {
11501
11936
  Component: import_form_palette14.InputField,
11937
+ options: {
11938
+ supported: true,
11939
+ autoCreate: true,
11940
+ defaultLabel: "Option label",
11941
+ defaultValue: "option"
11942
+ },
11502
11943
  defaultProps: {
11503
11944
  variant: "radio",
11504
11945
  // MUST
@@ -11525,12 +11966,111 @@ var radioDescriptor = {
11525
11966
 
11526
11967
  // src/react/inputs/entries/checkbox.tsx
11527
11968
  var import_form_palette15 = require("@timeax/form-palette");
11969
+ var checkboxBaseUi = {
11970
+ size: sharedUi.size,
11971
+ density: {
11972
+ type: "anyOf",
11973
+ label: "Density",
11974
+ description: "Vertical density of each option row.",
11975
+ items: [
11976
+ { type: "string", title: "Compact", value: "compact" },
11977
+ { type: "string", title: "Comfortable", value: "comfortable" },
11978
+ { type: "string", title: "Loose", value: "loose" }
11979
+ ]
11980
+ },
11981
+ single: {
11982
+ type: "boolean",
11983
+ label: "Single",
11984
+ description: "If enabled, behaves like a single checkbox (boolean). Otherwise renders a group (array)."
11985
+ },
11986
+ tristate: {
11987
+ type: "boolean",
11988
+ label: "Tri-state",
11989
+ description: 'Enable tri-state behaviour (supports an internal "none" state).'
11990
+ },
11991
+ layout: {
11992
+ type: "anyOf",
11993
+ label: "Layout",
11994
+ description: "Arrange options as a vertical list or grid.",
11995
+ items: [
11996
+ { type: "string", title: "List", value: "list" },
11997
+ { type: "string", title: "Grid", value: "grid" }
11998
+ ]
11999
+ },
12000
+ columns: {
12001
+ type: "number",
12002
+ label: "Columns",
12003
+ description: "Number of columns when layout is grid.",
12004
+ minimum: 1
12005
+ },
12006
+ itemGapPx: {
12007
+ type: "number",
12008
+ label: "Item gap (px)",
12009
+ description: "Gap between option rows/items in pixels.",
12010
+ minimum: 0
12011
+ },
12012
+ autoCap: {
12013
+ type: "boolean",
12014
+ label: "Auto capitalise",
12015
+ description: "Capitalise the first letter of labels (only when label resolves to a string)."
12016
+ },
12017
+ options: {
12018
+ type: "array",
12019
+ label: "Options",
12020
+ description: "Checkbox options. Can be primitives (string/number/boolean) or objects (label/value/description/disabled/tristate).",
12021
+ editable: true,
12022
+ item: {
12023
+ type: "object",
12024
+ label: "Option",
12025
+ description: "An option item for group mode.",
12026
+ editable: true,
12027
+ fields: {
12028
+ value: {
12029
+ type: "string",
12030
+ label: "Value",
12031
+ description: "Unique option value (string)."
12032
+ },
12033
+ label: {
12034
+ type: "string",
12035
+ label: "Label",
12036
+ description: "Display label for the option."
12037
+ },
12038
+ description: {
12039
+ type: "string",
12040
+ label: "Description",
12041
+ description: "Optional helper text under the label."
12042
+ },
12043
+ disabled: {
12044
+ type: "boolean",
12045
+ label: "Disabled",
12046
+ description: "Disable this option."
12047
+ },
12048
+ tristate: {
12049
+ type: "boolean",
12050
+ label: "Tri-state override",
12051
+ description: "Override tri-state behaviour for this option (if unset, uses variant tristate)."
12052
+ }
12053
+ },
12054
+ order: ["value", "label", "description", "disabled", "tristate"]
12055
+ }
12056
+ },
12057
+ optionValue: {
12058
+ type: "string",
12059
+ label: "Option value key",
12060
+ description: "Property name to read the option value from when using custom option objects."
12061
+ },
12062
+ optionLabel: {
12063
+ type: "string",
12064
+ label: "Option label key",
12065
+ description: "Property name to read the option label from when using custom option objects."
12066
+ }
12067
+ };
11528
12068
  var checkboxDescriptor = {
11529
12069
  Component: import_form_palette15.InputField,
11530
12070
  defaultProps: {
11531
12071
  variant: "checkbox",
11532
12072
  // MUST
11533
- single: false,
12073
+ single: true,
11534
12074
  tristate: false,
11535
12075
  layout: "list",
11536
12076
  columns: 2,
@@ -11540,120 +12080,23 @@ var checkboxDescriptor = {
11540
12080
  autoCap: false
11541
12081
  },
11542
12082
  adapter: {},
11543
- ui: {
11544
- size: sharedUi.size,
11545
- density: {
11546
- type: "anyOf",
11547
- label: "Density",
11548
- description: "Vertical density of each option row.",
11549
- items: [
11550
- { type: "string", title: "Compact", value: "compact" },
11551
- { type: "string", title: "Comfortable", value: "comfortable" },
11552
- { type: "string", title: "Loose", value: "loose" }
11553
- ]
11554
- },
11555
- // group vs single behavior
11556
- single: {
11557
- type: "boolean",
11558
- label: "Single",
11559
- description: "If enabled, behaves like a single checkbox (boolean). Otherwise renders a group (array)."
11560
- },
11561
- tristate: {
11562
- type: "boolean",
11563
- label: "Tri-state",
11564
- description: 'Enable tri-state behaviour (supports an internal "none" state).'
11565
- },
11566
- // layout
11567
- layout: {
11568
- type: "anyOf",
11569
- label: "Layout",
11570
- description: "Arrange options as a vertical list or grid.",
11571
- items: [
11572
- { type: "string", title: "List", value: "list" },
11573
- { type: "string", title: "Grid", value: "grid" }
11574
- ]
11575
- },
11576
- columns: {
11577
- type: "number",
11578
- label: "Columns",
11579
- description: "Number of columns when layout is grid.",
11580
- minimum: 1
11581
- },
11582
- itemGapPx: {
11583
- type: "number",
11584
- label: "Item gap (px)",
11585
- description: "Gap between option rows/items in pixels.",
11586
- minimum: 0
11587
- },
11588
- autoCap: {
11589
- type: "boolean",
11590
- label: "Auto capitalise",
11591
- description: "Capitalise the first letter of labels (only when label resolves to a string)."
11592
- },
11593
- // options (primitive arrays or object arrays)
11594
- options: {
11595
- type: "array",
11596
- label: "Options",
11597
- description: "Checkbox options. Can be primitives (string/number/boolean) or objects (label/value/description/disabled/tristate).",
11598
- editable: true,
11599
- item: {
11600
- type: "object",
11601
- label: "Option",
11602
- description: "An option item for group mode.",
11603
- editable: true,
11604
- fields: {
11605
- value: {
11606
- type: "string",
11607
- label: "Value",
11608
- description: "Unique option value (string)."
11609
- },
11610
- label: {
11611
- type: "string",
11612
- label: "Label",
11613
- description: "Display label for the option."
11614
- },
11615
- description: {
11616
- type: "string",
11617
- label: "Description",
11618
- description: "Optional helper text under the label."
11619
- },
11620
- disabled: {
11621
- type: "boolean",
11622
- label: "Disabled",
11623
- description: "Disable this option."
11624
- },
11625
- tristate: {
11626
- type: "boolean",
11627
- label: "Tri-state override",
11628
- description: "Override tri-state behaviour for this option (if unset, uses variant tristate)."
11629
- }
11630
- },
11631
- order: [
11632
- "value",
11633
- "label",
11634
- "description",
11635
- "disabled",
11636
- "tristate"
11637
- ]
11638
- }
11639
- },
11640
- // mapping keys (for custom item shapes)
11641
- optionValue: {
11642
- type: "string",
11643
- label: "Option value key",
11644
- description: "Property name to read the option value from when using custom option objects."
11645
- },
11646
- optionLabel: {
11647
- type: "string",
11648
- label: "Option label key",
11649
- description: "Property name to read the option label from when using custom option objects."
11650
- }
11651
- // intentionally excluded:
11652
- // - items (alias to options; keeping one is enough for builder)
11653
- // - mappers (functions)
11654
- // - renderOption (function)
11655
- // - singleLabel/singleDescription (ReactNode)
11656
- // - all *ClassName props (not allowed)
12083
+ options: {
12084
+ supported: false
12085
+ },
12086
+ ui: checkboxBaseUi
12087
+ };
12088
+ var _a;
12089
+ var checkboxOptionsDescriptor = {
12090
+ ...checkboxDescriptor,
12091
+ defaultProps: {
12092
+ ...(_a = checkboxDescriptor.defaultProps) != null ? _a : {},
12093
+ single: false
12094
+ },
12095
+ options: {
12096
+ supported: true,
12097
+ autoCreate: true,
12098
+ defaultLabel: "Option label",
12099
+ defaultValue: "option"
11657
12100
  }
11658
12101
  };
11659
12102
 
@@ -11661,6 +12104,9 @@ var checkboxDescriptor = {
11661
12104
  var import_form_palette16 = require("@timeax/form-palette");
11662
12105
  var chipsDescriptor = {
11663
12106
  Component: import_form_palette16.InputField,
12107
+ options: {
12108
+ supported: false
12109
+ },
11664
12110
  defaultProps: {
11665
12111
  variant: "chips",
11666
12112
  // MUST
@@ -12452,7 +12898,7 @@ var inputFieldUi = {
12452
12898
  }
12453
12899
  };
12454
12900
  function withInputFieldUi(desc) {
12455
- var _a;
12901
+ var _a2;
12456
12902
  return {
12457
12903
  ...desc,
12458
12904
  adapter: {
@@ -12462,7 +12908,7 @@ function withInputFieldUi(desc) {
12462
12908
  valueProp: "value",
12463
12909
  changeProp: "onChange",
12464
12910
  getInputPropsFromField({ field, props }) {
12465
- var _a2, _b;
12911
+ var _a3, _b;
12466
12912
  const severityPillClassMap = {
12467
12913
  info: "border-blue-200 bg-blue-50 text-blue-700 ring-1 ring-inset ring-blue-200",
12468
12914
  warning: "border-amber-200 bg-amber-50 text-amber-800 ring-1 ring-inset ring-amber-200",
@@ -12470,11 +12916,11 @@ function withInputFieldUi(desc) {
12470
12916
  };
12471
12917
  const pillBaseClassName = "inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-medium";
12472
12918
  const toTagPill = (tag) => {
12473
- var _a3;
12919
+ var _a4;
12474
12920
  return {
12475
12921
  label: tag.title,
12476
12922
  bgColor: tag.color,
12477
- className: `${pillBaseClassName} ${(_a3 = severityPillClassMap[tag.severity]) != null ? _a3 : severityPillClassMap.info}`
12923
+ className: `${pillBaseClassName} ${(_a4 = severityPillClassMap[tag.severity]) != null ? _a4 : severityPillClassMap.info}`
12478
12924
  };
12479
12925
  };
12480
12926
  const matchesNotice = (target, notice) => {
@@ -12483,7 +12929,7 @@ function withInputFieldUi(desc) {
12483
12929
  const isServiceMatch = !!target.service_id && String(target.service_id) === notice.id;
12484
12930
  return isNodeTargetMatch || isLegacyGlobalIdMatch || isServiceMatch;
12485
12931
  };
12486
- const notices = (_a2 = props.notices) != null ? _a2 : [];
12932
+ const notices = (_a3 = props.notices) != null ? _a3 : [];
12487
12933
  const fieldNotices = notices.filter(
12488
12934
  (notice) => matchesNotice(field, notice)
12489
12935
  );
@@ -12505,8 +12951,8 @@ function withInputFieldUi(desc) {
12505
12951
  };
12506
12952
  },
12507
12953
  getSelectedOptions(next, currentt, ctx) {
12508
- var _a2, _b, _c;
12509
- return (_c = (_b = (_a2 = next == null ? void 0 : next.detail) == null ? void 0 : _a2.selectedOptions) != null ? _b : []) == null ? void 0 : _c.map(
12954
+ var _a3, _b, _c;
12955
+ return (_c = (_b = (_a3 = next == null ? void 0 : next.detail) == null ? void 0 : _a3.selectedOptions) != null ? _b : []) == null ? void 0 : _c.map(
12510
12956
  (item) => item.id
12511
12957
  );
12512
12958
  },
@@ -12516,13 +12962,13 @@ function withInputFieldUi(desc) {
12516
12962
  },
12517
12963
  ui: {
12518
12964
  ...inputFieldUi,
12519
- ...(_a = desc.ui) != null ? _a : {}
12965
+ ...(_a2 = desc.ui) != null ? _a2 : {}
12520
12966
  }
12521
12967
  };
12522
12968
  }
12523
12969
  function variantOf(desc) {
12524
- var _a;
12525
- const v = (_a = desc.defaultProps) == null ? void 0 : _a.variant;
12970
+ var _a2;
12971
+ const v = (_a2 = desc.defaultProps) == null ? void 0 : _a2.variant;
12526
12972
  if (!v || typeof v !== "string") {
12527
12973
  throw new Error(
12528
12974
  `[inputs] Descriptor is missing defaultProps.variant: ${String(v)}`
@@ -12553,16 +12999,23 @@ function registerEntries(registry) {
12553
12999
  listerDescriptor,
12554
13000
  fileDescriptor
12555
13001
  ];
12556
- registry.registerMany(
12557
- entries.map((descriptor) => {
12558
- const finalDescriptor = withInputFieldUi(descriptor);
12559
- const variant = variantOf(finalDescriptor);
12560
- return {
12561
- kind: variant,
12562
- descriptor: finalDescriptor
12563
- };
12564
- })
12565
- );
13002
+ const baseEntries = entries.map((descriptor) => {
13003
+ const finalDescriptor = withInputFieldUi(descriptor);
13004
+ const variant = variantOf(finalDescriptor);
13005
+ return {
13006
+ kind: variant,
13007
+ descriptor: finalDescriptor
13008
+ };
13009
+ });
13010
+ const checkboxOptions = withInputFieldUi(checkboxOptionsDescriptor);
13011
+ registry.registerMany([
13012
+ ...baseEntries,
13013
+ {
13014
+ kind: "checkbox",
13015
+ descriptor: checkboxOptions,
13016
+ variant: "options"
13017
+ }
13018
+ ]);
12566
13019
  }
12567
13020
 
12568
13021
  // src/react/fallback-editor/useFallbackEditor.ts
@@ -12606,16 +13059,16 @@ function FallbackEditorProvider({
12606
13059
  );
12607
13060
  const resolvedEligibleServices = import_react9.default.useMemo(
12608
13061
  () => {
12609
- var _a;
12610
- return (_a = eligibleServices != null ? eligibleServices : primaryServices) != null ? _a : {};
13062
+ var _a2;
13063
+ return (_a2 = eligibleServices != null ? eligibleServices : primaryServices) != null ? _a2 : {};
12611
13064
  },
12612
13065
  [eligibleServices, primaryServices]
12613
13066
  );
12614
13067
  const editorRef = import_react9.default.useRef(null);
12615
13068
  const buildEditor = import_react9.default.useCallback(
12616
13069
  (next) => {
12617
- var _a, _b, _c, _d, _e, _f, _g, _h;
12618
- const currentValue = (_a = editorRef.current) == null ? void 0 : _a.value();
13070
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
13071
+ const currentValue = (_a2 = editorRef.current) == null ? void 0 : _a2.value();
12619
13072
  editorRef.current = createFallbackEditor({
12620
13073
  fallbacks: (_d = (_c = (_b = next == null ? void 0 : next.fallbacks) != null ? _b : currentValue) != null ? _c : fallbacks) != null ? _d : {},
12621
13074
  props: (_e = next == null ? void 0 : next.props) != null ? _e : props,
@@ -13006,7 +13459,7 @@ function VirtualServiceList({
13006
13459
  style: { height },
13007
13460
  onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
13008
13461
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "relative", style: { height: total * rowHeight }, children: visible.map((item, i) => {
13009
- var _a, _b;
13462
+ var _a2, _b;
13010
13463
  const index = start + i;
13011
13464
  const key = String(item.id);
13012
13465
  const checked = selected.has(key);
@@ -13027,7 +13480,7 @@ function VirtualServiceList({
13027
13480
  String(item.id),
13028
13481
  " \xB7",
13029
13482
  " ",
13030
- (_a = item.name) != null ? _a : "Unnamed"
13483
+ (_a2 = item.name) != null ? _a2 : "Unnamed"
13031
13484
  ] }),
13032
13485
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "mt-0.5 text-xs text-zinc-500 dark:text-zinc-400", children: [
13033
13486
  (_b = item.platform) != null ? _b : "Unknown",
@@ -13057,7 +13510,7 @@ function VirtualServiceList({
13057
13510
  var import_react18 = __toESM(require("react"), 1);
13058
13511
  var import_jsx_runtime8 = require("react/jsx-runtime");
13059
13512
  function FallbackDetailsPanel() {
13060
- var _a, _b, _c, _d, _e, _f, _g, _h;
13513
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
13061
13514
  const { activeServiceId, state, settings } = useFallbackEditor();
13062
13515
  const services = usePrimaryServiceList();
13063
13516
  const service = import_react18.default.useMemo(
@@ -13073,7 +13526,7 @@ function FallbackDetailsPanel() {
13073
13526
  Detail,
13074
13527
  {
13075
13528
  label: "Name",
13076
- value: (_a = service.name) != null ? _a : "Unnamed"
13529
+ value: (_a2 = service.name) != null ? _a2 : "Unnamed"
13077
13530
  }
13078
13531
  ),
13079
13532
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
@@ -13194,7 +13647,7 @@ var import_react19 = __toESM(require("react"), 1);
13194
13647
  var import_form_palette23 = require("@timeax/form-palette");
13195
13648
  var import_jsx_runtime10 = require("react/jsx-runtime");
13196
13649
  function FallbackSettingsPanel() {
13197
- var _a, _b, _c;
13650
+ var _a2, _b, _c;
13198
13651
  const { settings, saveSettings, settingsSaving } = useFallbackEditorContext();
13199
13652
  const [draft, setDraft] = import_react19.default.useState(settings);
13200
13653
  const [error, setError] = import_react19.default.useState(null);
@@ -13223,7 +13676,7 @@ function FallbackSettingsPanel() {
13223
13676
  ratePolicy: next
13224
13677
  }));
13225
13678
  }
13226
- const ratePolicy = (_a = draft.ratePolicy) != null ? _a : {
13679
+ const ratePolicy = (_a2 = draft.ratePolicy) != null ? _a2 : {
13227
13680
  kind: "lte_primary",
13228
13681
  pct: 5
13229
13682
  };
@@ -13422,8 +13875,8 @@ function FallbackServiceSidebar() {
13422
13875
  if (!q) return services;
13423
13876
  return services.filter(
13424
13877
  (service) => {
13425
- var _a, _b;
13426
- return String(service.id).includes(q) || String((_a = service.name) != null ? _a : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
13878
+ var _a2, _b;
13879
+ return String(service.id).includes(q) || String((_a2 = service.name) != null ? _a2 : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
13427
13880
  }
13428
13881
  );
13429
13882
  }, [query, services]);
@@ -13447,7 +13900,7 @@ function FallbackServiceSidebar() {
13447
13900
  }
13448
13901
  ) }),
13449
13902
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "mt-3 flex-1 space-y-2 overflow-y-auto", children: filtered.map((service) => {
13450
- var _a, _b;
13903
+ var _a2, _b;
13451
13904
  const active = String(service.id) === String(activeServiceId);
13452
13905
  const count = get(service.id).length;
13453
13906
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
@@ -13466,7 +13919,7 @@ function FallbackServiceSidebar() {
13466
13919
  String(service.id),
13467
13920
  " \xB7",
13468
13921
  " ",
13469
- (_a = service.name) != null ? _a : "Unnamed"
13922
+ (_a2 = service.name) != null ? _a2 : "Unnamed"
13470
13923
  ] }),
13471
13924
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "mt-1 text-xs text-zinc-500 dark:text-zinc-400", children: [
13472
13925
  (_b = service.platform) != null ? _b : "Unknown",
@@ -13541,7 +13994,7 @@ function FallbackRegistrationsPanel() {
13541
13994
  )
13542
13995
  ] }),
13543
13996
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "space-y-4", children: registrations.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("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) => {
13544
- var _a;
13997
+ var _a2;
13545
13998
  const context = makeContext(reg);
13546
13999
  const candidates = reg.services;
13547
14000
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
@@ -13563,7 +14016,7 @@ function FallbackRegistrationsPanel() {
13563
14016
  ] })
13564
14017
  ] }),
13565
14018
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "mt-4 flex flex-wrap gap-2", children: candidates.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "text-xs text-zinc-500 dark:text-zinc-400", children: "No fallback services yet." }) : candidates.map((candidate) => {
13566
- var _a2;
14019
+ var _a3;
13567
14020
  const preview = check(context, [
13568
14021
  candidate
13569
14022
  ]);
@@ -13577,7 +14030,7 @@ function FallbackRegistrationsPanel() {
13577
14030
  {
13578
14031
  className: `inline-flex items-center gap-2 rounded-xl border px-3 py-2 text-xs ${tone}`,
13579
14032
  children: [
13580
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: service ? `#${String(service.id)} \xB7 ${(_a2 = service.name) != null ? _a2 : "Unnamed"}` : `#${String(candidate)}` }),
14033
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: service ? `#${String(service.id)} \xB7 ${(_a3 = service.name) != null ? _a3 : "Unnamed"}` : `#${String(candidate)}` }),
13581
14034
  rejected ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "rounded-full border border-current/20 px-2 py-0.5 text-[10px]", children: rejected.reasons.join(
13582
14035
  ", "
13583
14036
  ) }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "rounded-full border border-current/20 px-2 py-0.5 text-[10px]", children: "valid" }),
@@ -13623,7 +14076,7 @@ function FallbackRegistrationsPanel() {
13623
14076
  ] })
13624
14077
  ]
13625
14078
  },
13626
- `${reg.scope}:${String((_a = reg.scopeId) != null ? _a : "global")}:${index}`
14079
+ `${reg.scope}:${String((_a2 = reg.scopeId) != null ? _a2 : "global")}:${index}`
13627
14080
  );
13628
14081
  }) })
13629
14082
  ] }),
@@ -13682,7 +14135,7 @@ function FallbackAddCandidatesDialog({
13682
14135
  const items = import_react25.default.useMemo(() => {
13683
14136
  const q = query.trim().toLowerCase();
13684
14137
  return eligibleServices.filter((service) => {
13685
- var _a, _b;
14138
+ var _a2, _b;
13686
14139
  if (primaryId !== void 0 && String(service.id) === String(primaryId)) {
13687
14140
  return false;
13688
14141
  }
@@ -13690,7 +14143,7 @@ function FallbackAddCandidatesDialog({
13690
14143
  return false;
13691
14144
  }
13692
14145
  if (!q) return true;
13693
- return String(service.id).includes(q) || String((_a = service.name) != null ? _a : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
14146
+ return String(service.id).includes(q) || String((_a2 = service.name) != null ? _a2 : "").toLowerCase().includes(q) || String((_b = service.platform) != null ? _b : "").toLowerCase().includes(q);
13694
14147
  });
13695
14148
  }, [eligibleServices, allowedIds, query, primaryId]);
13696
14149
  function toggle(id) {
@@ -13812,7 +14265,7 @@ function FallbackAddRegistrationDialog({
13812
14265
  return registrations.some((r) => r.scope === "global");
13813
14266
  }, [registrations]);
13814
14267
  const nodeTargets = import_react26.default.useMemo(() => {
13815
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14268
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
13816
14269
  if (activeServiceId === void 0 || activeServiceId === null) {
13817
14270
  return [];
13818
14271
  }
@@ -13833,7 +14286,7 @@ function FallbackAddRegistrationDialog({
13833
14286
  serviceId: activeServiceId
13834
14287
  });
13835
14288
  }
13836
- const activeTagId = (_a = snapshot.selection) == null ? void 0 : _a.tag;
14289
+ const activeTagId = (_a2 = snapshot.selection) == null ? void 0 : _a2.tag;
13837
14290
  out.sort((a, b) => {
13838
14291
  if (activeTagId && a.id === activeTagId && b.id !== activeTagId) {
13839
14292
  return -1;
@@ -13913,7 +14366,7 @@ function FallbackAddRegistrationDialog({
13913
14366
  }
13914
14367
  }, [scope, nodeId, nodeTargets]);
13915
14368
  function handleContinue() {
13916
- var _a;
14369
+ var _a2;
13917
14370
  if (activeServiceId === void 0 || activeServiceId === null) return;
13918
14371
  if (scope === "global") {
13919
14372
  onSelect(
@@ -13932,7 +14385,7 @@ function FallbackAddRegistrationDialog({
13932
14385
  scope: "node",
13933
14386
  nodeId
13934
14387
  },
13935
- (_a = node == null ? void 0 : node.serviceId) != null ? _a : activeServiceId
14388
+ (_a2 = node == null ? void 0 : node.serviceId) != null ? _a2 : activeServiceId
13936
14389
  );
13937
14390
  }
13938
14391
  if (!open) return null;
@@ -14012,11 +14465,11 @@ function FallbackAddRegistrationDialog({
14012
14465
  ] }) });
14013
14466
  }
14014
14467
  function resolveNodeMeta(props, nodeId) {
14015
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14468
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
14016
14469
  if (!props) {
14017
14470
  return { kind: "node", label: nodeId };
14018
14471
  }
14019
- const tag = (_a = props.filters) == null ? void 0 : _a.find((t) => t.id === nodeId);
14472
+ const tag = (_a2 = props.filters) == null ? void 0 : _a2.find((t) => t.id === nodeId);
14020
14473
  if (tag) {
14021
14474
  return {
14022
14475
  kind: "tag",
@@ -14068,6 +14521,7 @@ function resolveNodeMeta(props, nodeId) {
14068
14521
  useFallbackEditorContext,
14069
14522
  useFormApi,
14070
14523
  useInputs,
14524
+ useInputsMaybe,
14071
14525
  useOptionalFormApi,
14072
14526
  useOrderFlow,
14073
14527
  useOrderFlowContext,