@ai-matrx/records-ui 0.116.27 → 0.116.28

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.
package/CHANGELOG.md CHANGED
@@ -24,7 +24,7 @@
24
24
  - Tests: `vitest.setup.ts` gives jsdom a no-op `performance.mark` / `measure`.
25
25
  - **New subpath `@ai-matrx/records-ui/data-source`:** `recordsDataSource`, `personActor` and the who-changed words (`whenWords`, `actorWords`, `actorBadge`, `lastChangeSentence`, `SOMEBODY`, `THE_SYSTEM`) alone. `/helpers` also carries the field-type words, the colour resolver and the table builders, which read `@ai-matrx/records/core`; this entry reaches `@ai-matrx/kit` only, and shares the one data-source cache with `/helpers` and the root. Additive. Consumer action: a shell-reachable service that only binds its supabase client or says when imports from `/data-source`.
26
26
 
27
- ## 0.116.27
27
+ ## 0.116.28
28
28
 
29
29
  UNVERIFIED: this release has no Unreleased entry and the source comparison could not be made (the caller supplied no source comparison). Whether source changed is unknown; consumer action is unknown.
30
30
  Check the package's gitHead on npm against this version's gitHead: `git diff <previous gitHead> <this gitHead> -- apps/shared/records-ui/src`.
@@ -5537,6 +5537,16 @@ var LIST_TERMS = [
5537
5537
  { op: "is_empty", label: "is empty" },
5538
5538
  { op: "is_not_empty", label: "is not empty" }
5539
5539
  ];
5540
+ var CHOICE_LIST_TERMS = [
5541
+ { op: "has_any", label: "is any of" },
5542
+ { op: "has_none", label: "is none of" }
5543
+ ];
5544
+ var ChoiceListTermsContext = createContext3(false);
5545
+ var CHOICE_LIST_OPS = /* @__PURE__ */ new Set(["has_any", "has_none"]);
5546
+ function wordsOfValue(value) {
5547
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
5548
+ return typeof value === "string" && value !== "" ? [value] : [];
5549
+ }
5540
5550
  var VALUELESS_OPS = /* @__PURE__ */ new Set(["present", "is_empty", "is_not_empty"]);
5541
5551
  var LINK_SEP = ">";
5542
5552
  function linkedNode(viaId, innerId, op2, value) {
@@ -5608,6 +5618,59 @@ function isChoiceColumn(f) {
5608
5618
  const kind = String(editorKindFor(f.field));
5609
5619
  return kind === "select" || kind === "multi_select";
5610
5620
  }
5621
+ function ChoiceValues({ field: field2, value, onChange }) {
5622
+ const client = useOptionalRecordsClient8();
5623
+ const [choices, setChoices] = useState22(null);
5624
+ useEffect14(() => {
5625
+ if (!client) return;
5626
+ let cancelled = false;
5627
+ void (0, askOnce_exports.fieldOptionsOnce)(client, field2.id).then((got) => {
5628
+ if (cancelled) return;
5629
+ setChoices(got.ok ? (got.data ?? []).map((o) => ({ key: optionKey2(o), label: optionLabel(o) ?? "" })).filter((c) => c.label !== "") : []);
5630
+ });
5631
+ return () => {
5632
+ cancelled = true;
5633
+ };
5634
+ }, [client, field2.id]);
5635
+ const lower = value.map((w) => w.toLowerCase());
5636
+ const isOn = (c) => lower.includes(c.key.toLowerCase()) || lower.includes(c.label.toLowerCase());
5637
+ const known = (choices ?? []).flatMap((c) => [c.key.toLowerCase(), c.label.toLowerCase()]);
5638
+ const strays = value.filter((w) => !known.includes(w.toLowerCase()));
5639
+ const toggle = (c) => {
5640
+ const rest = value.filter((w) => w.toLowerCase() !== c.key.toLowerCase() && w.toLowerCase() !== c.label.toLowerCase());
5641
+ const next = isOn(c) ? rest : [...rest, c.label];
5642
+ const order = (choices ?? []).map((x) => x.label);
5643
+ onChange([...next].sort((a, b) => (order.indexOf(a) === -1 ? 1e6 : order.indexOf(a)) - (order.indexOf(b) === -1 ? 1e6 : order.indexOf(b))));
5644
+ };
5645
+ if (!choices || choices.length === 0) {
5646
+ return /* @__PURE__ */ jsx29(
5647
+ BasicInput6,
5648
+ {
5649
+ className: "h-8 w-40 text-xs",
5650
+ "aria-label": "Condition values, separated by commas",
5651
+ value: value.join(", "),
5652
+ onChange: (e) => onChange(e.target.value.split(",").map((w) => w.trim()).filter((w) => w !== ""))
5653
+ }
5654
+ );
5655
+ }
5656
+ return /* @__PURE__ */ jsxs25("span", { className: "inline-flex flex-wrap items-center gap-1", "data-records-condition-choices": "", "data-pick-values": value.join("|"), children: [
5657
+ choices.map((c) => /* @__PURE__ */ jsx29(
5658
+ Button12,
5659
+ {
5660
+ type: "button",
5661
+ size: "sm",
5662
+ variant: isOn(c) ? "default" : "outline",
5663
+ className: "h-7 px-2 text-xs",
5664
+ "aria-pressed": isOn(c),
5665
+ "aria-label": `${c.label} for ${field2.label || field2.key}`,
5666
+ onClick: () => toggle(c),
5667
+ children: c.label
5668
+ },
5669
+ c.key
5670
+ )),
5671
+ strays.map((w) => /* @__PURE__ */ jsx29(Button12, { type: "button", size: "sm", variant: "default", className: "h-7 px-2 text-xs", "aria-pressed": true, "aria-label": `${w} (not a choice of this column)`, onClick: () => onChange(value.filter((x) => x !== w)), children: w }, `stray-${w}`))
5672
+ ] });
5673
+ }
5611
5674
  function ChoiceValue({ field: field2, value, onChange }) {
5612
5675
  const client = useOptionalRecordsClient8();
5613
5676
  const [choices, setChoices] = useState22(null);
@@ -5672,7 +5735,7 @@ function conditionIsSimple(expr) {
5672
5735
  if (expr === null || expr === void 0) return true;
5673
5736
  if (relativeDayOf(expr) !== null || meOf(expr) !== null || linkedOf(expr) !== null) return true;
5674
5737
  const node = expr;
5675
- if (typeof node.op !== "string" || !(CONDITION_OPS.some((c) => c.op === node.op) || LIST_TERMS.some((c) => c.op === node.op))) {
5738
+ if (typeof node.op !== "string" || !(CONDITION_OPS.some((c) => c.op === node.op) || LIST_TERMS.some((c) => c.op === node.op) || CHOICE_LIST_OPS.has(node.op))) {
5676
5739
  return false;
5677
5740
  }
5678
5741
  if (!Array.isArray(node.args)) return false;
@@ -5759,6 +5822,7 @@ function conditionValue(typed) {
5759
5822
  function ConditionRow({ lead, expr, fields, onChange, emptyLabel = "always", className }) {
5760
5823
  const node = expr ?? null;
5761
5824
  const filterTerms = useContext2(FilterTermsContext);
5825
+ const choiceListTerms = useContext2(ChoiceListTermsContext) || filterTerms;
5762
5826
  const relative = relativeDayOf(expr);
5763
5827
  const reader = meOf(expr);
5764
5828
  const linked = linkedOf(expr);
@@ -5767,7 +5831,11 @@ function ConditionRow({ lead, expr, fields, onChange, emptyLabel = "always", cla
5767
5831
  const value = relative || reader ? "" : linked ? linked.value : node?.args?.[1]?.const ?? "";
5768
5832
  const chosen = fields.find((f) => f.id === onField);
5769
5833
  const chosenKind = chosen?.field ? String(editorKindFor(chosen.field)) : "";
5770
- const extraTerms = !filterTerms || chosen?.via ? [] : chosenKind === "datetime" ? RELATIVE_DAY_TERMS.map((t) => ({ op: `rel:${t.kind}`, label: t.label })) : chosenKind === "member" ? [{ op: "me", label: "is me" }, { op: "not_me", label: "is not me" }] : chosenKind === "multi_select" ? LIST_TERMS : [];
5834
+ const choiceTerms = choiceListTerms && !chosen?.via && (chosenKind === "select" || chosenKind === "multi_select") ? CHOICE_LIST_TERMS : [];
5835
+ const extraTerms = [
5836
+ ...!filterTerms || chosen?.via ? [] : chosenKind === "datetime" ? RELATIVE_DAY_TERMS.map((t) => ({ op: `rel:${t.kind}`, label: t.label })) : chosenKind === "member" ? [{ op: "me", label: "is me" }, { op: "not_me", label: "is not me" }] : chosenKind === "multi_select" ? LIST_TERMS : [],
5837
+ ...choiceTerms
5838
+ ];
5771
5839
  const baseTerms = chosen?.via ? CONDITION_OPS.filter((c) => c.op === "eq" || c.op === "ne") : CONDITION_OPS;
5772
5840
  const relativeTerm = relative ? RELATIVE_DAY_TERMS.find((t) => t.kind === relative.kind) : void 0;
5773
5841
  function write(next) {
@@ -5790,7 +5858,9 @@ function ConditionRow({ lead, expr, fields, onChange, emptyLabel = "always", cla
5790
5858
  }
5791
5859
  const chosenOp = next.op ?? (op2 || (next.field ? CONDITION_OPS[0].op : ""));
5792
5860
  const chosenField = next.field ?? onField;
5793
- const chosenValue = next.value ?? value;
5861
+ let chosenValue = next.value ?? value;
5862
+ if (CHOICE_LIST_OPS.has(chosenOp)) chosenValue = wordsOfValue(chosenValue);
5863
+ else if (Array.isArray(chosenValue)) chosenValue = wordsOfValue(chosenValue)[0] ?? "";
5794
5864
  if (!chosenOp || !chosenField) {
5795
5865
  onChange(null);
5796
5866
  return;
@@ -5866,7 +5936,7 @@ function ConditionRow({ lead, expr, fields, onChange, emptyLabel = "always", cla
5866
5936
  allowCreate: false
5867
5937
  }
5868
5938
  )
5869
- ) : isChoiceColumn(chosen) && (op2 === "eq" || op2 === "ne" || op2 === "contains" || op2 === "not_contains") ? /* @__PURE__ */ jsx29(ChoiceValue, { field: chosen.field, value: String(value ?? ""), onChange: (word) => write({ value: word }) }) : /* @__PURE__ */ jsx29(
5939
+ ) : isChoiceColumn(chosen) && CHOICE_LIST_OPS.has(op2) ? /* @__PURE__ */ jsx29(ChoiceValues, { field: chosen.field, value: wordsOfValue(value), onChange: (words) => write({ value: words }) }) : isChoiceColumn(chosen) && (op2 === "eq" || op2 === "ne" || op2 === "contains" || op2 === "not_contains") ? /* @__PURE__ */ jsx29(ChoiceValue, { field: chosen.field, value: String(value ?? ""), onChange: (word) => write({ value: word }) }) : /* @__PURE__ */ jsx29(
5870
5940
  BasicInput6,
5871
5941
  {
5872
5942
  className: "h-8 w-28 text-xs",
@@ -6182,6 +6252,11 @@ async function forgetWrittenWords(client, tableId, key, written) {
6182
6252
 
6183
6253
  // src/FieldRetype.tsx
6184
6254
  import { jsx as jsx30, jsxs as jsxs26 } from "react/jsx-runtime";
6255
+ var RETYPE_PREVIEW_DEBOUNCE_MS = 300;
6256
+ function scheduleRetypePreview(ask, ms = RETYPE_PREVIEW_DEBOUNCE_MS) {
6257
+ const timer = setTimeout(ask, ms);
6258
+ return () => clearTimeout(timer);
6259
+ }
6185
6260
  var RETYPE_TARGETS = [
6186
6261
  { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words", via: "behaviour" },
6187
6262
  { id: "number", behaviour: "range", kind: "number", label: "Number", holds: "a number", via: "behaviour" },
@@ -6282,23 +6357,26 @@ function FieldRetype({ field: field2, tableId, onRetyped }) {
6282
6357
  cancelled = true;
6283
6358
  };
6284
6359
  }
6285
- void client.fieldRetypePreview({ field_id: field2.id, patch: retypePatch(to) }).then((answer) => {
6286
- if (cancelled) return;
6287
- setAsking(false);
6288
- if (!answer.ok) {
6289
- setRefusal(answer.error);
6290
- return;
6291
- }
6292
- if (answer.data.limited || answer.data.converts === null || answer.data.kept_aside === null) {
6293
- setLimitedHeld(answer.data.held_before);
6294
- setPreview({ converts: answer.data.held_before, keptAside: 0, examples: [], partial: false });
6295
- return;
6296
- }
6297
- setLimitedHeld(null);
6298
- setPreview({ converts: answer.data.converts, keptAside: answer.data.kept_aside, examples: answer.data.examples, partial: false });
6360
+ const cancelAsk = scheduleRetypePreview(() => {
6361
+ void client.fieldRetypePreview({ field_id: field2.id, patch: retypePatch(to) }).then((answer) => {
6362
+ if (cancelled) return;
6363
+ setAsking(false);
6364
+ if (!answer.ok) {
6365
+ setRefusal(answer.error);
6366
+ return;
6367
+ }
6368
+ if (answer.data.limited || answer.data.converts === null || answer.data.kept_aside === null) {
6369
+ setLimitedHeld(answer.data.held_before);
6370
+ setPreview({ converts: answer.data.held_before, keptAside: 0, examples: [], partial: false });
6371
+ return;
6372
+ }
6373
+ setLimitedHeld(null);
6374
+ setPreview({ converts: answer.data.converts, keptAside: answer.data.kept_aside, examples: answer.data.examples, partial: false });
6375
+ });
6299
6376
  });
6300
6377
  return () => {
6301
6378
  cancelled = true;
6379
+ cancelAsk();
6302
6380
  };
6303
6381
  }, [client, tableId, field2.key, to, person, roster]);
6304
6382
  if (!retypeableFrom(field2)) {
@@ -9414,7 +9492,7 @@ function RollupFilterQuestion({
9414
9492
  "."
9415
9493
  ] }),
9416
9494
  /* @__PURE__ */ jsx37(Button15, { type: "button", size: "sm", variant: "ghost", className: "h-6 px-2 text-xs", onClick: () => onChange(null), children: "Clear" })
9417
- ] }) : /* @__PURE__ */ jsx37(
9495
+ ] }) : /* @__PURE__ */ jsx37(ChoiceListTermsContext.Provider, { value: true, children: /* @__PURE__ */ jsx37(
9418
9496
  ConditionGroup,
9419
9497
  {
9420
9498
  lead: rollupFilterLead(agg),
@@ -9423,7 +9501,7 @@ function RollupFilterQuestion({
9423
9501
  fields: conditionFields,
9424
9502
  onChange
9425
9503
  }
9426
- ) });
9504
+ ) }) });
9427
9505
  }
9428
9506
  function ValueOnTheOtherSide({
9429
9507
  label,
@@ -12242,4 +12320,4 @@ export {
12242
12320
  RecordNameText,
12243
12321
  HeldChangeDecision
12244
12322
  };
12245
- //# sourceMappingURL=chunk-6GJLCWSO.js.map
12323
+ //# sourceMappingURL=chunk-5EFM2G2O.js.map