@ai-matrx/records-ui 0.116.115 → 0.116.116

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.js CHANGED
@@ -43488,10 +43488,62 @@ function orderedRows(rows, nameKey, direction = "asc") {
43488
43488
  return sign * NATURAL2.compare(x, y);
43489
43489
  });
43490
43490
  }
43491
- function tableSortedRows(rows, sort, fields) {
43491
+ function tableSortedRows(rows, sort, fields, scaleKey) {
43492
43492
  const field = fields.find((f) => f.key === sort.id);
43493
43493
  if (!field || sortAsFor2(field) !== "text") return [...rows];
43494
- return orderedRows(rows, sort.id, sort.direction);
43494
+ const named = orderedRows(rows, sort.id, sort.direction);
43495
+ return scaleKey ? scaleOrdered(named, scaleKey) : named;
43496
+ }
43497
+ function scaleOrdered(rows, valueKey) {
43498
+ const sizes = rows.map((r) => scaleMagnitude((r.document ?? {})[valueKey]));
43499
+ if (rows.length < 2 || sizes.some((m) => m === null)) return [...rows];
43500
+ return rows.map((row, i) => ({ row, i, m: sizes[i] })).sort((a, b) => a.m - b.m || a.i - b.i).map((x) => x.row);
43501
+ }
43502
+ function cssShadowDepth(text) {
43503
+ if (text === "none") return 0;
43504
+ let deepest = null;
43505
+ for (const layer of text.split(/,(?![^(]*\))/)) {
43506
+ const lengths = layer.replace(/(rgba?|hsla?|oklch|oklab|lab|lch|color|var)\([^)]*\)/gi, " ").replace(/#[0-9a-f]{3,8}\b|\binset\b|\b[a-z]+\b(?!\()/gi, (m) => /^\d/.test(m) ? m : " ").trim().split(/\s+/).filter((w) => w !== "");
43507
+ if (lengths.length < 2 || lengths.length > 4 || !lengths.every((w) => /^-?\d+(\.\d+)?(px|rem|em)?$/i.test(w))) return null;
43508
+ const [, y = 0, blur = 0, spread = 0] = lengths.map((w) => parseFloat(w));
43509
+ const depth = Math.abs(y) + blur + spread / 2;
43510
+ deepest = deepest === null ? depth : Math.max(deepest, depth);
43511
+ }
43512
+ return deepest;
43513
+ }
43514
+ function scaleMagnitude(value) {
43515
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
43516
+ if (typeof value === "string") {
43517
+ const t = value.trim();
43518
+ const n = /^-?\d+(\.\d+)?/.exec(t);
43519
+ if (n && /^-?\d+(\.\d+)?\s*[a-z%]*$/i.test(t)) return Number(n[0]);
43520
+ if (t.startsWith("{")) {
43521
+ try {
43522
+ return scaleMagnitude(JSON.parse(t));
43523
+ } catch {
43524
+ return null;
43525
+ }
43526
+ }
43527
+ const timing = /^(\d+(?:\.\d+)?)(ms|s)\b/i.exec(t);
43528
+ if (timing) return Number(timing[1]) * (timing[2]?.toLowerCase() === "s" ? 1e3 : 1);
43529
+ return cssShadowDepth(t);
43530
+ }
43531
+ if (value && typeof value === "object") {
43532
+ const o = value;
43533
+ if (typeof o.duration === "number") return o.duration;
43534
+ const theme = o.light ?? o.dark;
43535
+ if (theme !== void 0) return scaleMagnitude(theme);
43536
+ const layers = Array.isArray(o.layers) ? o.layers : "blur" in o || "y" in o ? [o] : null;
43537
+ if (layers) {
43538
+ let deepest = null;
43539
+ for (const layer of layers) {
43540
+ const depth = (Number(layer.y) || 0) + (Number(layer.blur) || 0) + (Number(layer.spread) || 0) / 2;
43541
+ deepest = deepest === null ? depth : Math.max(deepest, depth);
43542
+ }
43543
+ return deepest;
43544
+ }
43545
+ }
43546
+ return null;
43495
43547
  }
43496
43548
  function sectionGroups(rows, groupKey) {
43497
43549
  if (!groupKey) return [{ key: UNGROUPED2, rows: [...rows] }];
@@ -43896,7 +43948,8 @@ function TableSectionCard(props) {
43896
43948
  const readsOnField = cols.readsOn ? fields.find((f) => f.key === cols.readsOn) : void 0;
43897
43949
  const readsOnColorKey = cols.readsOn ? cols.values.find((f) => formatForField(f)?.options?.contrastWith?.readsOnField === cols.readsOn)?.key : void 0;
43898
43950
  const columns = columnsOf(cols.values);
43899
- const rows = tableSort ? tableSortedRows(page.data?.rows ?? [], tableSort, fields) : orderedRows(page.data?.rows ?? [], cols.name);
43951
+ const scaleKey = cols.values.length === 1 && !cols.group ? cols.values[0]?.key : void 0;
43952
+ const rows = tableSort ? tableSortedRows(page.data?.rows ?? [], tableSort, fields, scaleKey) : scaleKey ? scaleOrdered(orderedRows(page.data?.rows ?? [], cols.name), scaleKey) : orderedRows(page.data?.rows ?? [], cols.name);
43900
43953
  const groups = sectionGroups(rows, cols.group);
43901
43954
  const level = rows[0]?.level ?? null;
43902
43955
  const mayWrite = !readOnly && (rows.length === 0 ? !readOnly : atLeast(level, "edit_content"));