@ai-matrx/records-ui 0.116.29 → 0.116.31

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/dist/index.d.cts CHANGED
@@ -5561,7 +5561,9 @@ interface PivotView {
5561
5561
  * draws the rest), the same Field is never both rows and columns, and a measure that needs a number
5562
5562
  * Field it does not have falls back to a count and `fellBack` says so.
5563
5563
  */
5564
- declare function pivotQuestion(view: PivotView, fields: readonly Pick<CoercibleField, "key" | "type">[]): PivotQuestion;
5564
+ declare function pivotQuestion(view: PivotView, fields: readonly (Pick<CoercibleField, "key" | "type"> & {
5565
+ config?: unknown;
5566
+ })[]): PivotQuestion;
5565
5567
  interface PivotAxisItem {
5566
5568
  id: string;
5567
5569
  /** The stored value, as the drill-through filters by it (`null` = no value). */
@@ -7811,9 +7813,10 @@ declare function colorPairContrast(pair: ColorPair, format: FieldFormatConfig, c
7811
7813
  light?: number;
7812
7814
  dark?: number;
7813
7815
  };
7814
- /** "17:1" with a tick, or a warning mark under 4.5:1. */
7815
- declare function ContrastMark({ ratio }: {
7816
+ /** "17:1" with a tick, or a warning mark under the color's minimum (its `min`, else text's 4.5:1). */
7817
+ declare function ContrastMark({ ratio, min }: {
7816
7818
  ratio: number;
7819
+ min?: number | undefined;
7817
7820
  }): react.JSX.Element;
7818
7821
  /** One side of a pair: a color well and its hex, typed or picked. */
7819
7822
  declare function ColorWell({ id, label, value, placeholder, onChange, disabled, }: {
package/dist/index.d.ts CHANGED
@@ -5561,7 +5561,9 @@ interface PivotView {
5561
5561
  * draws the rest), the same Field is never both rows and columns, and a measure that needs a number
5562
5562
  * Field it does not have falls back to a count and `fellBack` says so.
5563
5563
  */
5564
- declare function pivotQuestion(view: PivotView, fields: readonly Pick<CoercibleField, "key" | "type">[]): PivotQuestion;
5564
+ declare function pivotQuestion(view: PivotView, fields: readonly (Pick<CoercibleField, "key" | "type"> & {
5565
+ config?: unknown;
5566
+ })[]): PivotQuestion;
5565
5567
  interface PivotAxisItem {
5566
5568
  id: string;
5567
5569
  /** The stored value, as the drill-through filters by it (`null` = no value). */
@@ -7811,9 +7813,10 @@ declare function colorPairContrast(pair: ColorPair, format: FieldFormatConfig, c
7811
7813
  light?: number;
7812
7814
  dark?: number;
7813
7815
  };
7814
- /** "17:1" with a tick, or a warning mark under 4.5:1. */
7815
- declare function ContrastMark({ ratio }: {
7816
+ /** "17:1" with a tick, or a warning mark under the color's minimum (its `min`, else text's 4.5:1). */
7817
+ declare function ContrastMark({ ratio, min }: {
7816
7818
  ratio: number;
7819
+ min?: number | undefined;
7817
7820
  }): react.JSX.Element;
7818
7821
  /** One side of a pair: a color well and its hex, typed or picked. */
7819
7822
  declare function ColorWell({ id, label, value, placeholder, onChange, disabled, }: {
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ import {
182
182
  withoutAddition,
183
183
  withoutLeadingBlank,
184
184
  workedOutErrorFor
185
- } from "./chunk-5EFM2G2O.js";
185
+ } from "./chunk-BQS26T6D.js";
186
186
  import {
187
187
  CHART_PLOT_PX,
188
188
  EMBEDDED_ROW_PX,
@@ -293,7 +293,7 @@ import {
293
293
  visibilityLaneFor,
294
294
  whyNotAskable,
295
295
  writeOnTheWinningVersion_exports
296
- } from "./chunk-FLIERNH7.js";
296
+ } from "./chunk-4G6EOOKM.js";
297
297
  import {
298
298
  ACTION_CHECKING_ACCESS_REASON,
299
299
  ACTION_NOT_HERE_REASON,
@@ -9152,10 +9152,7 @@ function EnrichPanel({ tableId, fieldId, className }) {
9152
9152
  /* @__PURE__ */ jsx26("span", { className: "truncate text-muted-foreground", children: preview?.find((p) => p.record_id === w.record_id)?.title ?? w.record_id.slice(0, 8) }),
9153
9153
  /* @__PURE__ */ jsx26("span", { className: "min-w-0 truncate text-right", children: w.absent ? w.absent === "conflicting" ? "Sources disagree" : "Nothing found" : String(w.value ?? "") })
9154
9154
  ] }, w.record_id)) }) : null,
9155
- outcome && (outcome.fieldId === void 0 || outcome.fieldId === row.field_id) ? outcome.ok ? /* @__PURE__ */ jsxs25("p", { className: "text-xs text-muted-foreground", "data-testid": "enrich-outcome", children: [
9156
- outcome.message,
9157
- costInPoints(outcome.costCents, host.pointsRate) !== null ? ` \xB7 ${costInPoints(outcome.costCents, host.pointsRate)}` : ""
9158
- ] }) : (
9155
+ outcome && (outcome.fieldId === void 0 || outcome.fieldId === row.field_id) ? outcome.ok ? /* @__PURE__ */ jsx26("p", { className: "text-xs text-muted-foreground", "data-testid": "enrich-outcome", children: outcome.message }) : (
9159
9156
  // A run that did not happen is a refusal, with a heading and a remedy,
9160
9157
  // never the host's words in red (lane REFUSAL-SWEEP).
9161
9158
  /* @__PURE__ */ jsx26(
@@ -20849,7 +20846,7 @@ function useRowColorBy(all, colorKey, style) {
20849
20846
  // src/workedOutDate.ts
20850
20847
  import { FORMULA_NODE_RESULTS } from "@ai-matrx/records";
20851
20848
  var WORKED_OUT_DATE_LOCK = "Worked out \xB7 can't move";
20852
- var INLINE_DEPTH = 8;
20849
+ var FORMULA_TYPING_ROUNDS = 9;
20853
20850
  var configOf = (field) => field?.config ?? {};
20854
20851
  function isStoredDate(field) {
20855
20852
  if (!field || field.type !== "range") return false;
@@ -20863,27 +20860,36 @@ function ownExpression(field) {
20863
20860
  const expr = config["expr"];
20864
20861
  return !("via" in config) && expr && typeof expr === "object" && !Array.isArray(expr) ? expr : null;
20865
20862
  }
20866
- function inlineFormulas(node, all, seen = []) {
20867
- if (!node || typeof node !== "object" || Array.isArray(node)) return node;
20868
- const n = node;
20869
- if ("field" in n) {
20870
- const f = all.find((x) => x.id === n["field"]);
20871
- const expr = ownExpression(f);
20872
- if (!expr) return node;
20873
- const id = String(n["field"]);
20874
- if (seen.includes(id) || seen.length >= INLINE_DEPTH) return null;
20875
- return inlineFormulas(expr, all, [...seen, id]);
20863
+ function typedAs(field, kind2) {
20864
+ if (kind2 === "date") return { ...field, type: "range", config: { kind: "date", _typed: true } };
20865
+ if (kind2 === "number") return { ...field, type: "range", config: { _typed: true } };
20866
+ if (kind2 === "text") return { ...field, type: "text" };
20867
+ if (kind2 === "boolean") return { ...field, type: "boolean" };
20868
+ return field;
20869
+ }
20870
+ var typedRounds = /* @__PURE__ */ new WeakMap();
20871
+ function typedFormulaFields(all, rounds = FORMULA_TYPING_ROUNDS) {
20872
+ let byRounds = typedRounds.get(all);
20873
+ const hit = byRounds?.get(rounds);
20874
+ if (hit) return hit;
20875
+ let cur = all;
20876
+ for (let i = 0; i < rounds; i++) {
20877
+ const prev = cur;
20878
+ cur = all.map((f) => {
20879
+ const expr = ownExpression(f);
20880
+ return expr ? typedAs(f, formulaResultKind(expr, prev)) : f;
20881
+ });
20876
20882
  }
20877
- if (Array.isArray(n["args"])) {
20878
- const args = [];
20879
- for (const a of n["args"]) {
20880
- const r = inlineFormulas(a, all, seen);
20881
- if (r === null) return null;
20882
- args.push(r);
20883
- }
20884
- return { ...n, args };
20883
+ if (!byRounds) {
20884
+ byRounds = /* @__PURE__ */ new Map();
20885
+ typedRounds.set(all, byRounds);
20885
20886
  }
20886
- return node;
20887
+ byRounds.set(rounds, cur);
20888
+ return cur;
20889
+ }
20890
+ function formulaTypeOf(targetId, all, rounds = FORMULA_TYPING_ROUNDS) {
20891
+ const expr = ownExpression(all.find((f) => f.id === targetId));
20892
+ return expr ? formulaResultKind(expr, typedFormulaFields(all, rounds)) : "unknown";
20887
20893
  }
20888
20894
  function formulaResultKind(node, all) {
20889
20895
  if (!node || typeof node !== "object" || Array.isArray(node)) return "unknown";
@@ -20922,10 +20928,7 @@ function formulaResultKind(node, all) {
20922
20928
  return FORMULA_NODE_RESULTS[op] ?? "unknown";
20923
20929
  }
20924
20930
  function isDateFormula(field, all) {
20925
- const expr = ownExpression(field);
20926
- if (!expr || !field) return false;
20927
- const inlined = inlineFormulas(expr, all, [field.id]);
20928
- return inlined !== null && formulaResultKind(inlined, all) === "date";
20931
+ return !!field && formulaTypeOf(field.id, all) === "date";
20929
20932
  }
20930
20933
  function isComputedField(field) {
20931
20934
  return field?.type === "formula";
@@ -23578,10 +23581,75 @@ function ListRow({
23578
23581
  );
23579
23582
  }
23580
23583
 
23584
+ // src/pivot.ts
23585
+ import { measureKey as measureKey3 } from "@ai-matrx/records";
23586
+ var PIVOT_OPS = ["count", "sum", "avg", "min", "max"];
23587
+ var isPivotOp = (v) => PIVOT_OPS.includes(v ?? "");
23588
+ var PIVOT_OP_LABEL = { count: "Count", sum: "Sum", avg: "Average", min: "Min", max: "Max" };
23589
+ var PIVOT_CELL_LIMIT = 1e3;
23590
+ var NUMBER_TYPES = /* @__PURE__ */ new Set(["number", "integer", "decimal", "money", "currency", "percent", "percentage", "range"]);
23591
+ var isNumberField = (f) => {
23592
+ if (!NUMBER_TYPES.has(String(f.type))) return false;
23593
+ const kind2 = String((f.config ?? {})["kind"] ?? "number");
23594
+ return kind2 !== "date" && kind2 !== "datetime";
23595
+ };
23596
+ function pivotQuestion(view, fields) {
23597
+ const has = (key) => key && fields.some((f) => f.key === key) ? key : null;
23598
+ const rowKey = has(view.groupField);
23599
+ const colKey = has(view.columnField) !== rowKey ? has(view.columnField) : null;
23600
+ const op = isPivotOp(view.pivotMeasure) ? view.pivotMeasure : "count";
23601
+ const field = view.measure ? fields.find((f) => f.key === view.measure && isNumberField(f)) : void 0;
23602
+ const fellBack = op !== "count" && !field;
23603
+ const measure = op !== "count" && field ? { op, key: field.key } : { op: "count" };
23604
+ return { rowKey, colKey, op: fellBack ? "count" : op, measure, fellBack };
23605
+ }
23606
+ var NONE3 = "\0none";
23607
+ function groupId(value) {
23608
+ return value === null || value === void 0 || value === "" ? NONE3 : String(value);
23609
+ }
23610
+ function byValue(a, b) {
23611
+ if (a.id === NONE3 || b.id === NONE3) return a.id === b.id ? 0 : a.id === NONE3 ? 1 : -1;
23612
+ const x = typeof a.value === "number" ? a.value : null;
23613
+ const y = typeof b.value === "number" ? b.value : null;
23614
+ if (x !== null && y !== null) return x - y;
23615
+ return a.label.localeCompare(b.label, void 0, { numeric: true, sensitivity: "base" });
23616
+ }
23617
+ function pivotTable(q, answers, label, limit = PIVOT_CELL_LIMIT) {
23618
+ const m = measureKey3(q.measure);
23619
+ const read = (r) => r ? { value: typeof r.measures?.[m] === "number" ? r.measures[m] : null, n: r.row_count } : null;
23620
+ const axis = (key, sources) => {
23621
+ if (!key) return [{ id: NONE3, value: null, label: "" }];
23622
+ const seen = /* @__PURE__ */ new Map();
23623
+ for (const rows2 of sources)
23624
+ for (const r of rows2) {
23625
+ const raw = r.groups?.[key];
23626
+ const id = groupId(raw);
23627
+ if (!seen.has(id)) seen.set(id, { id, value: id === NONE3 ? null : raw, label: id === NONE3 ? "\u2014" : label(key, raw) });
23628
+ }
23629
+ return [...seen.values()].sort(byValue);
23630
+ };
23631
+ const rows = axis(q.rowKey, [answers.rowTotals, answers.cells]);
23632
+ const cols = axis(q.colKey, [answers.colTotals, answers.cells]);
23633
+ const cellAt = /* @__PURE__ */ new Map();
23634
+ for (const r of answers.cells) cellAt.set(`${groupId(q.rowKey ? r.groups?.[q.rowKey] : null)}${groupId(q.colKey ? r.groups?.[q.colKey] : null)}`, r);
23635
+ const rowAt = new Map(answers.rowTotals.map((r) => [groupId(q.rowKey ? r.groups?.[q.rowKey] : null), r]));
23636
+ const colAt = new Map(answers.colTotals.map((r) => [groupId(q.colKey ? r.groups?.[q.colKey] : null), r]));
23637
+ return {
23638
+ rows,
23639
+ cols,
23640
+ // With no row Field every cell is the one row; with no column Field, the one column.
23641
+ cell: (rowId, colId) => read(cellAt.get(`${rowId}${colId}`)),
23642
+ rowTotal: (rowId) => read(rowAt.get(rowId)),
23643
+ colTotal: (colId) => read(colAt.get(colId)),
23644
+ grand: read(answers.grand[0]),
23645
+ cut: answers.cells.length >= limit
23646
+ };
23647
+ }
23648
+
23581
23649
  // src/ChartLayout.tsx
23582
23650
  import { useEffect as useEffect67, useMemo as useMemo48, useState as useState76 } from "react";
23583
23651
  import { useRecordsClient as useRecordsClient60 } from "@ai-matrx/records/react";
23584
- import { fieldKindFor, measureKey as measureKey4 } from "@ai-matrx/records";
23652
+ import { fieldKindFor, measureKey as measureKey5 } from "@ai-matrx/records";
23585
23653
  import { Select as Select8, SelectContent as SelectContent6, SelectItem as SelectItem6, SelectTrigger as SelectTrigger6, SelectValue as SelectValue6 } from "@ai-matrx/design-system";
23586
23654
 
23587
23655
  // src/ChartBlock.tsx
@@ -23607,7 +23675,7 @@ import {
23607
23675
  YAxis
23608
23676
  } from "recharts";
23609
23677
  import {
23610
- measureKey as measureKey3
23678
+ measureKey as measureKey4
23611
23679
  } from "@ai-matrx/records";
23612
23680
  import { mapPgError as mapPgError2 } from "@ai-matrx/records/core";
23613
23681
  import { cn as cn36 } from "@ai-matrx/design-system";
@@ -24191,7 +24259,7 @@ function ChartBlock({ block, subject, tableName: tableName2, className, centerVa
24191
24259
  const kind2 = shape ? BASE_KIND_OF_SHAPE[shape] : block.kind;
24192
24260
  const tableId = block.table_id ?? subject;
24193
24261
  const measures = block.measures && block.measures.length > 0 ? block.measures : [{ op: "count" }];
24194
- const primary = measureKey3(measures[0]);
24262
+ const primary = measureKey4(measures[0]);
24195
24263
  const windows = kind2 === "stuck" ? null : block.compare ?? null;
24196
24264
  const compared = !!windows;
24197
24265
  const grain = block.bucket?.by ?? null;
@@ -24201,7 +24269,7 @@ function ChartBlock({ block, subject, tableName: tableName2, className, centerVa
24201
24269
  const measureFields = useMeasureFields(primary, source ? void 0 : tableId);
24202
24270
  const measureName = useMeasureWords(primary, tableId);
24203
24271
  const numberFormat = useMemo47(() => source ? null : chartFormatFor(primary, measureFields), [source, primary, measureFields]);
24204
- const yKey = drawn === "scatter" && measures[1] ? measureKey3(measures[1]) : null;
24272
+ const yKey = drawn === "scatter" && measures[1] ? measureKey4(measures[1]) : null;
24205
24273
  const yName = useMeasureWords(yKey ?? primary, tableId);
24206
24274
  const points = useMemo47(() => {
24207
24275
  if (kind2 === "stuck") return [];
@@ -24913,7 +24981,6 @@ import { Fragment as Fragment35, jsx as jsx84, jsxs as jsxs77 } from "react/jsx-
24913
24981
  var KIND_LABEL = { bar: "Bars", line: "Line", area: "Area", donut: "Donut", pie: "Pie", stacked: "Stacked bars", scatter: "Scatter" };
24914
24982
  var BASE_SHAPES = ["bar", "line", "donut"];
24915
24983
  var MEASURE_LABEL2 = { count: "Count", sum: "Sum", avg: "Average" };
24916
- var NUMBER_TYPES = /* @__PURE__ */ new Set(["number", "integer", "decimal", "money", "currency", "percent", "percentage"]);
24917
24984
  var DATE_TYPES = /* @__PURE__ */ new Set(["date", "datetime", "timestamp"]);
24918
24985
  var isChartKind = (v) => Object.prototype.hasOwnProperty.call(KIND_LABEL, v ?? "");
24919
24986
  var isChartMeasure = (v) => v === "count" || v === "sum" || v === "avg";
@@ -24971,7 +25038,7 @@ function ChartLayout({ view, fields, filter, onChange, remembered }) {
24971
25038
  return;
24972
25039
  }
24973
25040
  const wholeRow = overall && overall.ok ? (overall.data ?? [])[0] : void 0;
24974
- const wholeValue = wholeRow ? wholeRow.measures[measureKey4(question.measure)] : void 0;
25041
+ const wholeValue = wholeRow ? wholeRow.measures[measureKey5(question.measure)] : void 0;
24975
25042
  setState({
24976
25043
  error: null,
24977
25044
  ...question.kind === "donut" ? { total: typeof wholeValue === "number" ? wholeValue : null } : {},
@@ -24991,8 +25058,8 @@ function ChartLayout({ view, fields, filter, onChange, remembered }) {
24991
25058
  };
24992
25059
  }, [client, view.subject, view.name, qKey, filterKey]);
24993
25060
  const groupable = fields.filter((f) => !["attachment", "file", "formula", "button"].includes(String(f.type)));
24994
- const numeric = fields.filter((f) => NUMBER_TYPES.has(String(f.type)));
24995
- const pickMeasure = measureKey4(q.measure);
25061
+ const numeric = fields.filter(isNumberField);
25062
+ const pickMeasure = measureKey5(q.measure);
24996
25063
  const dataLabels = view.presentation?.chartLabels === true;
24997
25064
  const legend = view.presentation?.chartLegend !== false;
24998
25065
  const setLook = (patch) => onChange({ presentation: { ...view.presentation, ...patch } });
@@ -25057,69 +25124,6 @@ import { useRecordsClient as useRecordsClient61 } from "@ai-matrx/records/react"
25057
25124
  import { measureKey as measureKey6 } from "@ai-matrx/records";
25058
25125
  import { Select as Select9, SelectContent as SelectContent7, SelectItem as SelectItem7, SelectTrigger as SelectTrigger7, SelectValue as SelectValue7, cn as cn37 } from "@ai-matrx/design-system";
25059
25126
  import { Skeleton as Skeleton17 } from "@ai-matrx/design-system/skeleton";
25060
-
25061
- // src/pivot.ts
25062
- import { measureKey as measureKey5 } from "@ai-matrx/records";
25063
- var PIVOT_OPS = ["count", "sum", "avg", "min", "max"];
25064
- var isPivotOp = (v) => PIVOT_OPS.includes(v ?? "");
25065
- var PIVOT_OP_LABEL = { count: "Count", sum: "Sum", avg: "Average", min: "Min", max: "Max" };
25066
- var PIVOT_CELL_LIMIT = 1e3;
25067
- var NUMBER_TYPES2 = /* @__PURE__ */ new Set(["number", "integer", "decimal", "money", "currency", "percent", "percentage"]);
25068
- var isNumberField = (f) => NUMBER_TYPES2.has(String(f.type));
25069
- function pivotQuestion(view, fields) {
25070
- const has = (key) => key && fields.some((f) => f.key === key) ? key : null;
25071
- const rowKey = has(view.groupField);
25072
- const colKey = has(view.columnField) !== rowKey ? has(view.columnField) : null;
25073
- const op = isPivotOp(view.pivotMeasure) ? view.pivotMeasure : "count";
25074
- const field = view.measure ? fields.find((f) => f.key === view.measure && isNumberField(f)) : void 0;
25075
- const fellBack = op !== "count" && !field;
25076
- const measure = op !== "count" && field ? { op, key: field.key } : { op: "count" };
25077
- return { rowKey, colKey, op: fellBack ? "count" : op, measure, fellBack };
25078
- }
25079
- var NONE3 = "\0none";
25080
- function groupId(value) {
25081
- return value === null || value === void 0 || value === "" ? NONE3 : String(value);
25082
- }
25083
- function byValue(a, b) {
25084
- if (a.id === NONE3 || b.id === NONE3) return a.id === b.id ? 0 : a.id === NONE3 ? 1 : -1;
25085
- const x = typeof a.value === "number" ? a.value : null;
25086
- const y = typeof b.value === "number" ? b.value : null;
25087
- if (x !== null && y !== null) return x - y;
25088
- return a.label.localeCompare(b.label, void 0, { numeric: true, sensitivity: "base" });
25089
- }
25090
- function pivotTable(q, answers, label, limit = PIVOT_CELL_LIMIT) {
25091
- const m = measureKey5(q.measure);
25092
- const read = (r) => r ? { value: typeof r.measures?.[m] === "number" ? r.measures[m] : null, n: r.row_count } : null;
25093
- const axis = (key, sources) => {
25094
- if (!key) return [{ id: NONE3, value: null, label: "" }];
25095
- const seen = /* @__PURE__ */ new Map();
25096
- for (const rows2 of sources)
25097
- for (const r of rows2) {
25098
- const raw = r.groups?.[key];
25099
- const id = groupId(raw);
25100
- if (!seen.has(id)) seen.set(id, { id, value: id === NONE3 ? null : raw, label: id === NONE3 ? "\u2014" : label(key, raw) });
25101
- }
25102
- return [...seen.values()].sort(byValue);
25103
- };
25104
- const rows = axis(q.rowKey, [answers.rowTotals, answers.cells]);
25105
- const cols = axis(q.colKey, [answers.colTotals, answers.cells]);
25106
- const cellAt = /* @__PURE__ */ new Map();
25107
- for (const r of answers.cells) cellAt.set(`${groupId(q.rowKey ? r.groups?.[q.rowKey] : null)}${groupId(q.colKey ? r.groups?.[q.colKey] : null)}`, r);
25108
- const rowAt = new Map(answers.rowTotals.map((r) => [groupId(q.rowKey ? r.groups?.[q.rowKey] : null), r]));
25109
- const colAt = new Map(answers.colTotals.map((r) => [groupId(q.colKey ? r.groups?.[q.colKey] : null), r]));
25110
- return {
25111
- rows,
25112
- cols,
25113
- // With no row Field every cell is the one row; with no column Field, the one column.
25114
- cell: (rowId, colId) => read(cellAt.get(`${rowId}${colId}`)),
25115
- rowTotal: (rowId) => read(rowAt.get(rowId)),
25116
- colTotal: (colId) => read(colAt.get(colId)),
25117
- grand: read(answers.grand[0]),
25118
- cut: answers.cells.length >= limit
25119
- };
25120
- }
25121
-
25122
- // src/PivotLayout.tsx
25123
25127
  import { Fragment as Fragment36, jsx as jsx85, jsxs as jsxs78 } from "react/jsx-runtime";
25124
25128
  var PIVOT_BOX = "min-h-[16rem]";
25125
25129
  function defaultPivotRows(fields) {
@@ -25302,9 +25306,9 @@ import { useFieldMutation as useFieldMutation6, useRecordMutation as useRecordMu
25302
25306
  import { Button as Button61, Select as Select10, SelectContent as SelectContent8, SelectItem as SelectItem8, SelectTrigger as SelectTrigger8, SelectValue as SelectValue8, cn as cn38 } from "@ai-matrx/design-system";
25303
25307
 
25304
25308
  // src/mapPins.ts
25305
- var NUMBER_TYPES3 = /* @__PURE__ */ new Set(["number", "integer", "decimal", "money", "currency", "percent", "percentage", "range"]);
25309
+ var NUMBER_TYPES2 = /* @__PURE__ */ new Set(["number", "integer", "decimal", "money", "currency", "percent", "percentage", "range"]);
25306
25310
  function isNumberField2(field) {
25307
- if (!NUMBER_TYPES3.has(String(field.type))) return false;
25311
+ if (!NUMBER_TYPES2.has(String(field.type))) return false;
25308
25312
  const kind2 = String((field.config ?? {})["kind"] ?? "number");
25309
25313
  return kind2 !== "date" && kind2 !== "datetime";
25310
25314
  }
@@ -35771,7 +35775,6 @@ function QuestionAnswerView({ tableId, spec, answer, fields, related = NO_RELATE
35771
35775
 
35772
35776
  // src/TableAsk.tsx
35773
35777
  import { useEffect as useEffect91, useState as useState102 } from "react";
35774
- import { formatPoints as formatPoints2 } from "@ai-matrx/kit/format";
35775
35778
  import { BasicInput as BasicInput21, Button as Button85, Popover as Popover10, PopoverContent as PopoverContent10, PopoverTrigger as PopoverTrigger10, Skeleton as Skeleton35 } from "@ai-matrx/design-system";
35776
35779
  import { optionLabel as optionLabel2 } from "@ai-matrx/records";
35777
35780
  import { useFields as useFields30, useRecordsClient as useRecordsClient81, useTable as useTable31 } from "@ai-matrx/records/react";
@@ -36005,7 +36008,7 @@ function TableAsk({ tableId, onOpenInQuestions, viewId }) {
36005
36008
  setSaid({ kind: "asking", reads: words2.trim() });
36006
36009
  const got = await askTable({ tableId, question: words2.trim(), viewId: viewId ?? "" });
36007
36010
  setSaid(
36008
- got.ok ? { kind: "agent-answer", answer: got.answer, costPoints: got.costPoints ?? null } : { kind: "agent-failed", error: (0, refusals_exports.refusal)("door", got.message, got.hint ?? null) }
36011
+ got.ok ? { kind: "agent-answer", answer: got.answer } : { kind: "agent-failed", error: (0, refusals_exports.refusal)("door", got.message, got.hint ?? null) }
36009
36012
  );
36010
36013
  return;
36011
36014
  }
@@ -36058,7 +36061,7 @@ function TableAsk({ tableId, onOpenInQuestions, viewId }) {
36058
36061
  /* @__PURE__ */ jsx113(Skeleton35, { className: "h-24 w-full", "data-table-ask-pending": "" })
36059
36062
  ] }) : null,
36060
36063
  said.kind === "agent-failed" ? /* @__PURE__ */ jsx113("div", { "data-table-ask-failed": "", children: /* @__PURE__ */ jsx113(RefusalNotice, { error: said.error }) }) : null,
36061
- said.kind === "agent-answer" ? /* @__PURE__ */ jsx113(AgentAnswer, { tableId, answer: said.answer, fields: all, costPoints: said.costPoints }) : null,
36064
+ said.kind === "agent-answer" ? /* @__PURE__ */ jsx113(AgentAnswer, { tableId, answer: said.answer, fields: all }) : null,
36062
36065
  said.kind === "refused" ? /* @__PURE__ */ jsx113(RefusalNotice, { error: said.error }) : null,
36063
36066
  said.kind === "answer" ? /* @__PURE__ */ jsxs106(Fragment49, { children: [
36064
36067
  /* @__PURE__ */ jsx113("p", { className: "truncate text-muted-foreground", title: said.reads, "data-table-ask-reads": "", children: said.reads }),
@@ -36107,8 +36110,7 @@ function useNames(tableId, ids) {
36107
36110
  function AgentAnswer({
36108
36111
  tableId,
36109
36112
  answer,
36110
- fields,
36111
- costPoints = null
36113
+ fields
36112
36114
  }) {
36113
36115
  const client = useRecordsClient81();
36114
36116
  const ui = useRecordsUi();
@@ -36174,7 +36176,6 @@ function AgentAnswer({
36174
36176
  ] }, `${c.record_id}:${c.field_key}:${i}`)) }) : null,
36175
36177
  open.length > 1 ? /* @__PURE__ */ jsx113(Button85, { size: "sm", className: "w-fit self-end", disabled: busy, onClick: () => void apply(open), "data-table-ask-apply-all": "", children: "Apply all" }) : null,
36176
36178
  refusal3 ? /* @__PURE__ */ jsx113(RefusalNotice, { error: refusal3 }) : null,
36177
- costPoints !== null ? /* @__PURE__ */ jsx113("p", { className: "text-muted-foreground", "data-table-ask-cost": "", children: formatPoints2(costPoints) }) : null,
36178
36179
  answer.could_not.length > 0 ? /* @__PURE__ */ jsx113("ul", { className: "text-muted-foreground", "data-table-ask-could-not": "", children: answer.could_not.map((w) => /* @__PURE__ */ jsx113("li", { children: w }, w)) }) : null
36179
36180
  ] });
36180
36181
  }
@@ -42116,7 +42117,6 @@ import { useFields as useFields35, useRecordMutation as useRecordMutation3, useR
42116
42117
  import {
42117
42118
  BasicInput as BasicInput26,
42118
42119
  BasicTextarea as BasicTextarea8,
42119
- Button as Button103,
42120
42120
  Dialog as Dialog23,
42121
42121
  DialogContent as DialogContent23,
42122
42122
  DialogHeader as DialogHeader23,
@@ -42133,6 +42133,7 @@ import {
42133
42133
  } from "@ai-matrx/design-system";
42134
42134
  import { MessageSquareIcon, PlusIcon as PlusIcon2, StickyNoteIcon } from "@ai-matrx/design-system/icons";
42135
42135
  import { readColorPair, readShadowPair, shadowWords } from "@ai-matrx/design-system/field-formats";
42136
+ import { Button as Button103 } from "@ai-matrx/design-system/controls";
42136
42137
 
42137
42138
  // src/EntitySectionCard.tsx
42138
42139
  import { useState as useState124 } from "react";
@@ -42541,7 +42542,7 @@ function ChecksLine({ checks, onFix }) {
42541
42542
  if (checks.length === 0) return null;
42542
42543
  return /* @__PURE__ */ jsx137("span", { className: "mt-1 flex flex-col items-start gap-1", children: checks.map((check, i) => /* @__PURE__ */ jsxs129("span", { className: "flex flex-col items-start gap-1", children: [
42543
42544
  /* @__PURE__ */ jsx137("span", { className: "text-xs text-warning-ink", children: check.message }),
42544
- check.fix && onFix ? /* @__PURE__ */ jsx137(Button103, { type: "button", size: "sm", variant: "outline", className: "h-6 px-2 text-xs", onClick: () => onFix(check), children: check.fix.label }) : null
42545
+ check.fix && onFix ? /* @__PURE__ */ jsx137(Button103, { type: "button", variant: "outline", onClick: () => onFix(check), children: check.fix.label }) : null
42545
42546
  ] }, i)) });
42546
42547
  }
42547
42548
  function ValueCell({
@@ -42550,7 +42551,8 @@ function ValueCell({
42550
42551
  editable,
42551
42552
  save,
42552
42553
  onFix,
42553
- context
42554
+ context,
42555
+ stacked
42554
42556
  }) {
42555
42557
  const { field, format } = column;
42556
42558
  const stored = (row.document ?? {})[field.key];
@@ -42563,11 +42565,12 @@ function ValueCell({
42563
42565
  if (format?.id === "color_pair") {
42564
42566
  const pair = readColorPair(value) ?? null;
42565
42567
  const contrast = pair ? colorPairContrast(pair, format, context) : {};
42566
- return /* @__PURE__ */ jsx137("div", { className: "grid min-w-0 grid-cols-2", children: ["light", "dark"].map((part) => {
42568
+ return /* @__PURE__ */ jsx137("div", { className: stacked ? "flex min-w-0 flex-col gap-1.5" : "grid min-w-0 grid-cols-2", children: ["light", "dark"].map((part) => {
42567
42569
  const side = part === "light" ? pair?.light : pair?.dark ?? void 0;
42568
42570
  const ratio = contrast[part];
42569
- return /* @__PURE__ */ jsxs129("div", { className: "min-w-0 px-3", children: [
42571
+ return /* @__PURE__ */ jsxs129("div", { className: stacked ? "min-w-0" : "min-w-0 px-3", children: [
42570
42572
  /* @__PURE__ */ jsxs129("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [
42573
+ stacked ? /* @__PURE__ */ jsx137("span", { className: "w-9 shrink-0 text-xs text-muted-foreground", children: part === "light" ? "Light" : "Dark" }) : null,
42571
42574
  editable ? /* @__PURE__ */ jsx137(
42572
42575
  ColorWell,
42573
42576
  {
@@ -42583,7 +42586,7 @@ function ValueCell({
42583
42586
  }
42584
42587
  }
42585
42588
  ) : /* @__PURE__ */ jsx137("code", { className: "font-mono text-xs uppercase", children: side ?? (part === "dark" ? "Inherits light" : "\u2014") }),
42586
- ratio !== void 0 ? /* @__PURE__ */ jsx137(ContrastMark, { ratio }) : null
42589
+ ratio !== void 0 ? /* @__PURE__ */ jsx137(ContrastMark, { ratio, min: pair?.min }) : null
42587
42590
  ] }),
42588
42591
  /* @__PURE__ */ jsx137(ChecksLine, { checks: checks.filter((c) => c.part === part), onFix: fix })
42589
42592
  ] }, part);
@@ -42594,25 +42597,28 @@ function ValueCell({
42594
42597
  const ownDark = typeof value === "string" && value.includes('"dark"');
42595
42598
  const pack = (l) => l.length === 1 ? l[0] : { layers: l };
42596
42599
  const write = (light, dark) => change(JSON.stringify(dark ? { light: pack(light), dark: pack(dark) } : pack(light)));
42597
- return /* @__PURE__ */ jsx137("div", { className: "grid min-w-0 grid-cols-2", children: ["light", "dark"].map((part) => {
42600
+ return /* @__PURE__ */ jsx137("div", { className: stacked ? "flex min-w-0 flex-col gap-1.5" : "grid min-w-0 grid-cols-2", children: ["light", "dark"].map((part) => {
42598
42601
  const layers = pair ? pair[part] : null;
42599
42602
  const words2 = !layers ? "Set" : part === "dark" && !ownDark ? "Same as light" : shadowWords(layers);
42600
42603
  const inner = /* @__PURE__ */ jsxs129("span", { className: "flex min-w-0 items-center gap-2", children: [
42601
42604
  layers ? /* @__PURE__ */ jsx137(ShadowSwatch, { layers, theme: part }) : null,
42602
42605
  /* @__PURE__ */ jsx137("span", { className: cn75("truncate text-xs", part === "dark" && !ownDark ? "text-muted-foreground" : "text-foreground"), children: words2 })
42603
42606
  ] });
42604
- return /* @__PURE__ */ jsx137("div", { className: "min-w-0 px-3", children: editable ? /* @__PURE__ */ jsxs129(Popover12, { children: [
42605
- /* @__PURE__ */ jsx137(PopoverTrigger12, { asChild: true, children: /* @__PURE__ */ jsx137("button", { type: "button", "aria-label": `${fieldName(field)} ${part}`, className: "block w-full min-w-0 rounded-md px-1 py-0.5 text-left hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: inner }) }),
42606
- /* @__PURE__ */ jsx137(PopoverContent12, { align: "start", className: "w-80", children: /* @__PURE__ */ jsx137(
42607
- ShadowLayersEditor,
42608
- {
42609
- layers: layers ?? [{ x: 0, y: 4, blur: 12, spread: 0, color: "#0000001f" }],
42610
- id: `${id}-${part}`,
42611
- label: `${fieldName(field)} ${part}`,
42612
- onChange: (next) => part === "light" ? write(next, ownDark && pair ? pair.dark : null) : write(pair ? pair.light : next, next)
42613
- }
42614
- ) })
42615
- ] }) : inner }, part);
42607
+ return /* @__PURE__ */ jsxs129("div", { className: stacked ? "flex min-w-0 items-center gap-2" : "min-w-0 px-3", children: [
42608
+ stacked ? /* @__PURE__ */ jsx137("span", { className: "w-9 shrink-0 text-xs text-muted-foreground", children: part === "light" ? "Light" : "Dark" }) : null,
42609
+ editable ? /* @__PURE__ */ jsxs129(Popover12, { children: [
42610
+ /* @__PURE__ */ jsx137(PopoverTrigger12, { asChild: true, children: /* @__PURE__ */ jsx137("button", { type: "button", "aria-label": `${fieldName(field)} ${part}`, className: "block w-full min-w-0 rounded-md px-1 py-0.5 text-left hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: inner }) }),
42611
+ /* @__PURE__ */ jsx137(PopoverContent12, { align: "start", className: "w-80", children: /* @__PURE__ */ jsx137(
42612
+ ShadowLayersEditor,
42613
+ {
42614
+ layers: layers ?? [{ x: 0, y: 4, blur: 12, spread: 0, color: "#0000001f" }],
42615
+ id: `${id}-${part}`,
42616
+ label: `${fieldName(field)} ${part}`,
42617
+ onChange: (next) => part === "light" ? write(next, ownDark && pair ? pair.dark : null) : write(pair ? pair.light : next, next)
42618
+ }
42619
+ ) })
42620
+ ] }) : inner
42621
+ ] }, part);
42616
42622
  }) });
42617
42623
  }
42618
42624
  const look = fieldLookFor(format?.id);
@@ -42697,20 +42703,15 @@ function groundOf(row, rows, keys) {
42697
42703
  }
42698
42704
  function RowComments({ tableId, row, count, onClosed }) {
42699
42705
  return /* @__PURE__ */ jsxs129(Popover12, { onOpenChange: (open) => !open && onClosed(), children: [
42700
- /* @__PURE__ */ jsx137(PopoverTrigger12, { asChild: true, children: /* @__PURE__ */ jsxs129(
42701
- "button",
42706
+ /* @__PURE__ */ jsx137(PopoverTrigger12, { asChild: true, children: /* @__PURE__ */ jsx137(
42707
+ Button103,
42702
42708
  {
42703
42709
  type: "button",
42710
+ variant: "quiet",
42711
+ icon: /* @__PURE__ */ jsx137(MessageSquareIcon, {}),
42712
+ badge: count,
42704
42713
  "aria-label": count > 0 ? `${count} open comment${count === 1 ? "" : "s"}` : "Comment",
42705
- "data-records-row-comments": count,
42706
- className: cn75(
42707
- "inline-flex h-7 min-w-7 items-center justify-center gap-0.5 rounded-md px-1 hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
42708
- count > 0 ? "text-foreground" : "text-muted-foreground"
42709
- ),
42710
- children: [
42711
- /* @__PURE__ */ jsx137(MessageSquareIcon, { className: "h-3.5 w-3.5" }),
42712
- count > 0 ? /* @__PURE__ */ jsx137("span", { className: "text-xs tabular-nums", children: count }) : null
42713
- ]
42714
+ "data-records-row-comments": count
42714
42715
  }
42715
42716
  ) }),
42716
42717
  /* @__PURE__ */ jsx137(PopoverContent12, { align: "end", className: "w-96 p-0", children: /* @__PURE__ */ jsx137(CommentThread, { tableId, recordId: row.id, className: "max-h-[70dvh] overflow-y-auto p-3" }) })
@@ -42723,16 +42724,14 @@ function NoteButton({ row, noteField, editable, save }) {
42723
42724
  const has = text.trim() !== "";
42724
42725
  return /* @__PURE__ */ jsxs129(Popover12, { children: [
42725
42726
  /* @__PURE__ */ jsx137(PopoverTrigger12, { asChild: true, children: /* @__PURE__ */ jsx137(
42726
- "button",
42727
+ Button103,
42727
42728
  {
42728
42729
  type: "button",
42730
+ variant: "quiet",
42731
+ icon: /* @__PURE__ */ jsx137(StickyNoteIcon, {}),
42732
+ pressed: has,
42729
42733
  "aria-label": has ? `${fieldName(noteField)}: ${text}` : `Add ${fieldName(noteField).toLowerCase()}`,
42730
- title: has ? text : fieldName(noteField),
42731
- className: cn75(
42732
- "inline-flex h-7 w-7 items-center justify-center rounded-md hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
42733
- has ? "text-foreground" : "text-muted-foreground"
42734
- ),
42735
- children: /* @__PURE__ */ jsx137(StickyNoteIcon, { className: "h-4 w-4" })
42734
+ title: has ? text : fieldName(noteField)
42736
42735
  }
42737
42736
  ) }),
42738
42737
  /* @__PURE__ */ jsx137(PopoverContent12, { align: "end", className: "w-72", children: /* @__PURE__ */ jsx137(
@@ -42846,8 +42845,8 @@ function AddDialog({
42846
42845
  /* @__PURE__ */ jsx137(BasicTextarea8, { id: "section-add-note", rows: 2, placeholder: name.trim() ? `When should ${name.trim()} be used?` : "When should it be used?", value: note, onChange: (e) => setNote(e.target.value) })
42847
42846
  ] }) : null,
42848
42847
  /* @__PURE__ */ jsxs129("div", { className: "flex justify-end gap-2 pt-1", children: [
42849
- /* @__PURE__ */ jsx137(Button103, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }),
42850
- /* @__PURE__ */ jsx137(Button103, { type: "submit", disabled: !ready, children: "Add" })
42848
+ /* @__PURE__ */ jsx137(Button103, { type: "button", variant: "quiet", onClick: () => onOpenChange(false), children: "Cancel" }),
42849
+ /* @__PURE__ */ jsx137(Button103, { type: "submit", variant: "primary", disabled: !ready, children: "Add" })
42851
42850
  ] })
42852
42851
  ]
42853
42852
  }
@@ -42926,27 +42925,15 @@ function TableSectionCard(props) {
42926
42925
  return /* @__PURE__ */ jsxs129("section", { ref: sectionRef, "data-records-section-card": "", "data-narrow": narrow ? "" : void 0, className: cn75("rounded-2xl border border-border bg-card text-card-foreground", className), children: [
42927
42926
  /* @__PURE__ */ jsxs129("header", { className: "flex items-start justify-between gap-4 px-5 pt-5 pb-3 sm:px-6", children: [
42928
42927
  /* @__PURE__ */ jsxs129("div", { className: "min-w-0", children: [
42929
- /* @__PURE__ */ jsx137("h2", { className: "truncate font-serif text-2xl tracking-tight text-foreground", children: title || "\xA0" }),
42928
+ /* @__PURE__ */ jsx137("h2", { className: "type-heading truncate text-foreground", children: title || "\xA0" }),
42930
42929
  props.description ? /* @__PURE__ */ jsx137("p", { className: "mt-1 max-w-prose text-sm text-muted-foreground", children: props.description }) : null
42931
42930
  ] }),
42932
- mayWrite && nameField ? /* @__PURE__ */ jsxs129(Button103, { type: "button", variant: "outline", size: "sm", onClick: () => setAdding(groups[groups.length - 1]?.key ?? UNGROUPED2), children: [
42933
- /* @__PURE__ */ jsx137(PlusIcon2, { className: "h-3.5 w-3.5" }),
42934
- "Add"
42935
- ] }) : null
42931
+ mayWrite && nameField ? /* @__PURE__ */ jsx137(Button103, { type: "button", variant: "outline", icon: /* @__PURE__ */ jsx137(PlusIcon2, {}), onClick: () => setAdding(groups[groups.length - 1]?.key ?? UNGROUPED2), children: "Add" }) : null
42936
42932
  ] }),
42937
42933
  refused ? /* @__PURE__ */ jsx137("p", { className: "px-5 pb-5 text-sm text-muted-foreground sm:px-6", children: refusalSentence(refused) }) : !fieldsRead.data || page.loading && rows.length === 0 ? /* @__PURE__ */ jsx137("div", { className: "flex flex-col gap-1.5 px-5 pb-5 sm:px-6", "aria-busy": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ jsx137("div", { className: "h-9 rounded-md bg-muted" }, i)) }) : rows.length === 0 ? /* @__PURE__ */ jsx137("p", { className: "px-5 pb-5 text-sm text-muted-foreground sm:px-6", children: "Nothing here yet." }) : /* @__PURE__ */ jsx137("div", { className: cn75("-mb-px", !narrow && "overflow-x-auto"), children: groups.map((group) => /* @__PURE__ */ jsxs129("div", { "data-records-section-group": group.key, className: "", children: [
42938
42934
  cols.group ? /* @__PURE__ */ jsxs129("div", { className: "flex items-center justify-between border-y border-border px-5 py-1 sm:px-6", children: [
42939
42935
  /* @__PURE__ */ jsx137("span", { className: "text-xs font-semibold text-foreground", children: group.key || "No group" }),
42940
- mayWrite ? /* @__PURE__ */ jsx137(
42941
- "button",
42942
- {
42943
- type: "button",
42944
- "aria-label": `Add to ${group.key || "no group"}`,
42945
- className: "inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
42946
- onClick: () => setAdding(group.key),
42947
- children: /* @__PURE__ */ jsx137(PlusIcon2, { className: "h-4 w-4" })
42948
- }
42949
- ) : null
42936
+ mayWrite ? /* @__PURE__ */ jsx137(Button103, { type: "button", variant: "quiet", icon: /* @__PURE__ */ jsx137(PlusIcon2, {}), "aria-label": `Add to ${group.key || "no group"}`, onClick: () => setAdding(group.key) }) : null
42950
42937
  ] }) : null,
42951
42938
  /* @__PURE__ */ jsxs129("div", { role: "table", "aria-label": group.key || title, className: narrow ? "" : "min-w-[36rem]", children: [
42952
42939
  /* @__PURE__ */ jsxs129("div", { role: "row", style: gridStyle, className: cn75("grid border-b border-border text-xs text-muted-foreground", narrow && "hidden"), children: [
@@ -42986,7 +42973,7 @@ function TableSectionCard(props) {
42986
42973
  style: c.part ? { gridColumn: "span 2" } : void 0,
42987
42974
  className: narrow ? "min-w-0" : cn75("min-w-0 py-1", c.part ? "" : "px-3"),
42988
42975
  children: [
42989
- narrow ? /* @__PURE__ */ jsx137("span", { className: "mb-0.5 block text-xs text-muted-foreground", children: cellLabel(c) }) : null,
42976
+ narrow && !c.part ? /* @__PURE__ */ jsx137("span", { className: "mb-0.5 block text-xs text-muted-foreground", children: cellLabel(c) }) : null,
42990
42977
  /* @__PURE__ */ jsx137(
42991
42978
  ValueCell,
42992
42979
  {
@@ -42995,7 +42982,8 @@ function TableSectionCard(props) {
42995
42982
  editable,
42996
42983
  save: rowSave,
42997
42984
  onFix,
42998
- context: c.field.key === readsOnColorKey ? groundOf(row, rows, { name: cols.name, readsOn: cols.readsOn, color: c.field.key }) : void 0
42985
+ context: c.field.key === readsOnColorKey ? groundOf(row, rows, { name: cols.name, readsOn: cols.readsOn, color: c.field.key }) : void 0,
42986
+ stacked: narrow
42999
42987
  }
43000
42988
  )
43001
42989
  ]