@ai-matrx/records-ui 0.116.101 → 0.116.103

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
@@ -6751,6 +6751,27 @@ function WholeTextDialog({
6751
6751
  ] }) });
6752
6752
  }
6753
6753
 
6754
+ // src/systemFields.ts
6755
+ function isSystemField(field) {
6756
+ return field.config?.hidden === true;
6757
+ }
6758
+ function systemFieldKeys(fields) {
6759
+ return (fields ?? []).filter(isSystemField).map((f) => f.key);
6760
+ }
6761
+ function hiddenOrSystemDefault(saved, fields) {
6762
+ if (saved) return [...saved];
6763
+ const system = systemFieldKeys(fields);
6764
+ return system.length > 0 ? system : void 0;
6765
+ }
6766
+ function hiddenFieldsEntry(hidden, fields) {
6767
+ const kept = hiddenToWrite(hidden, fields);
6768
+ return kept ? { hiddenFields: kept } : {};
6769
+ }
6770
+ function hiddenToWrite(hidden, fields) {
6771
+ if (hidden.length > 0) return [...hidden];
6772
+ return systemFieldKeys(fields).length > 0 ? [] : void 0;
6773
+ }
6774
+
6754
6775
  // src/gridControls.tsx
6755
6776
  import { Fragment as Fragment4, jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
6756
6777
  var VALUE_COUNTS_FRESH_MS = 1e4;
@@ -6842,8 +6863,8 @@ function useMergedGridControls(args) {
6842
6863
  }, [held, fieldKeys, keptOrder, frozenKeys]);
6843
6864
  const hidden = useMemo14(() => {
6844
6865
  const known = new Set(fieldKeys);
6845
- return (held?.hidden ?? keptHidden ?? []).filter((k) => known.has(k) || k.startsWith(REVERSE_COLUMN_PREFIX));
6846
- }, [held, keptHidden, fieldKeys]);
6866
+ return (held?.hidden ?? hiddenOrSystemDefault(keptHidden, fields) ?? []).filter((k) => known.has(k) || k.startsWith(REVERSE_COLUMN_PREFIX));
6867
+ }, [held, keptHidden, fieldKeys, fields]);
6847
6868
  const naturalOrder = useMemo14(
6848
6869
  () => [...fieldKeys.filter((k) => frozenKeys.has(k)), ...fieldKeys.filter((k) => !frozenKeys.has(k))],
6849
6870
  [fieldKeys, frozenKeys]
@@ -6856,10 +6877,10 @@ function useMergedGridControls(args) {
6856
6877
  writeLook({
6857
6878
  ...rest,
6858
6879
  ...moved ? { columnOrder: next.order } : {},
6859
- ...next.hidden.length > 0 ? { hiddenFields: next.hidden } : {}
6880
+ ...hiddenFieldsEntry(next.hidden, fields)
6860
6881
  });
6861
6882
  },
6862
- [presentation, writeLook, naturalOrder]
6883
+ [presentation, writeLook, naturalOrder, fields]
6863
6884
  );
6864
6885
  const pendingInsert = useRef9(null);
6865
6886
  useEffect19(() => {
@@ -9294,6 +9315,25 @@ import { humanizeIdentifier as humanizeIdentifier6 } from "@ai-matrx/kit/text-ca
9294
9315
  import { useState as useState28 } from "react";
9295
9316
  import { Badge as Badge3, Button as Button24, Separator as Separator2 } from "@ai-matrx/design-system";
9296
9317
  import { Fragment as Fragment7, jsx as jsx29, jsxs as jsxs27 } from "react/jsx-runtime";
9318
+ function keptWhileAway(outcome, readBackUnsent, readBackRefusal) {
9319
+ if (!readBackUnsent || outcome.written === 0) return outcome;
9320
+ const values = outcome.readBack + outcome.missing;
9321
+ return {
9322
+ ...outcome,
9323
+ readBack: 0,
9324
+ missing: 0,
9325
+ waiting: values,
9326
+ refusals: readBackRefusal === void 0 ? outcome.refusals : outcome.refusals.filter((why) => why !== readBackRefusal)
9327
+ };
9328
+ }
9329
+ function outcomeSentence(outcome) {
9330
+ const waiting = outcome.waiting ?? 0;
9331
+ if (waiting > 0) {
9332
+ return `${waiting} ${waiting === 1 ? "value is" : "values are"} saved on this computer and will be sent to the table when you are back online.`;
9333
+ }
9334
+ const whole = outcome.missing === 0 && outcome.refusals.length === 0;
9335
+ return whole ? `All ${outcome.readBack} ${outcome.readBack === 1 ? "value is" : "values are"} in the table \u2014 read back out of it, not just accepted.` : `${outcome.readBack} of ${outcome.readBack + outcome.missing} values are in the table. The rest are not, and nothing was lost from what you copied \u2014 it is still on your clipboard.`;
9336
+ }
9297
9337
  function PastePreview({
9298
9338
  plan,
9299
9339
  noun,
@@ -9436,8 +9476,9 @@ function PastePreview({
9436
9476
  }
9437
9477
  function Outcome({ outcome, onClose }) {
9438
9478
  const whole = outcome.missing === 0 && outcome.refusals.length === 0;
9479
+ const look = (outcome.waiting ?? 0) > 0 ? "waiting" : whole ? "whole" : "partial";
9439
9480
  return /* @__PURE__ */ jsxs27(Fragment7, { children: [
9440
- /* @__PURE__ */ jsx29("p", { className: "text-sm", "data-matrx-paste-outcome": whole ? "whole" : "partial", children: whole ? `All ${outcome.readBack} ${outcome.readBack === 1 ? "value is" : "values are"} in the table \u2014 read back out of it, not just accepted.` : `${outcome.readBack} of ${outcome.readBack + outcome.missing} values are in the table. The rest are not, and nothing was lost from what you copied \u2014 it is still on your clipboard.` }),
9481
+ /* @__PURE__ */ jsx29("p", { className: "text-sm", "data-matrx-paste-outcome": look, children: outcomeSentence(outcome) }),
9441
9482
  outcome.refusals.length > 0 ? /* @__PURE__ */ jsx29("ul", { className: "flex flex-col gap-1", children: outcome.refusals.slice(0, 8).map((why, index) => /* @__PURE__ */ jsx29("li", { className: "text-xs text-muted-foreground", children: why }, index)) }) : null,
9442
9483
  /* @__PURE__ */ jsx29("div", { className: "flex justify-end pt-1", children: /* @__PURE__ */ jsx29(Button24, { size: "sm", onClick: onClose, autoFocus: true, children: "Close" }) })
9443
9484
  ] });
@@ -12758,7 +12799,8 @@ function GridBody({
12758
12799
  let missing = 0;
12759
12800
  const fieldOf = new Map((fields.data ?? []).map((f) => [f.key, f]));
12760
12801
  const refusals = [];
12761
- if (!reread.ok) refusals.push(`The rows were written and this could not read them back to check: ${refusalSentence(reread.error)}`);
12802
+ const readBackRefusal = reread.ok ? void 0 : `The rows were written and this could not read them back to check: ${refusalSentence(reread.error)}`;
12803
+ if (readBackRefusal !== void 0) refusals.push(readBackRefusal);
12762
12804
  const seen = new Map((reread.ok ? reread.data : []).map((r) => [r.id, r.document ?? {}]));
12763
12805
  for (const entry of expected) {
12764
12806
  const stored = seen.get(entry.recordId);
@@ -12768,7 +12810,7 @@ function GridBody({
12768
12810
  }
12769
12811
  }
12770
12812
  records.reload();
12771
- return { written: lines2, readBack, missing, refusals };
12813
+ return keptWhileAway({ written: lines2, readBack, missing, refusals }, !reread.ok && isUnsentWrite(reread.error), readBackRefusal);
12772
12814
  },
12773
12815
  [rows, client, tableId, editing, undo, records, versions, fields.data]
12774
12816
  );
@@ -12800,7 +12842,7 @@ function GridBody({
12800
12842
  if (!held) return { written: 0, readBack: 0, missing: 0, refusals: [] };
12801
12843
  if (merged) {
12802
12844
  const outcome = await applyPasteAsOne(held.plan);
12803
- if (outcome.missing === 0 && outcome.refusals.length === 0) {
12845
+ if (outcome.missing === 0 && outcome.refusals.length === 0 && (outcome.waiting ?? 0) === 0) {
12804
12846
  setPastePlan(null);
12805
12847
  sheetController.current?.focusGrid();
12806
12848
  }
@@ -12848,12 +12890,14 @@ function GridBody({
12848
12890
  const fieldOf = new Map((fields.data ?? []).map((f) => [f.key, f]));
12849
12891
  const seen = /* @__PURE__ */ new Map();
12850
12892
  const READ_BACK_PAGE = 500;
12893
+ let readBackRefusal;
12894
+ let readBackUnsent = false;
12851
12895
  for (let offset = 0; ; offset += READ_BACK_PAGE) {
12852
12896
  const reread = await client.list({ table_id: tableId, limit: READ_BACK_PAGE, offset });
12853
12897
  if (!reread.ok) {
12854
- refusals.push(
12855
- `The rows were written and this could not read them back to check: ${refusalSentence(reread.error)}`
12856
- );
12898
+ readBackRefusal = `The rows were written and this could not read them back to check: ${refusalSentence(reread.error)}`;
12899
+ readBackUnsent = isUnsentWrite(reread.error);
12900
+ refusals.push(readBackRefusal);
12857
12901
  break;
12858
12902
  }
12859
12903
  for (const row of reread.data.rows) {
@@ -12873,7 +12917,7 @@ function GridBody({
12873
12917
  }
12874
12918
  }
12875
12919
  records.reload();
12876
- return { written, readBack, missing, refusals };
12920
+ return keptWhileAway({ written, readBack, missing, refusals }, readBackUnsent, readBackRefusal);
12877
12921
  }, [pastePlan, client, tableId, records, merged, applyPasteAsOne, versions, fields.data]);
12878
12922
  const columnIds = useMemo27(() => ordered.map((field) => field.key), [ordered]);
12879
12923
  const lookWrites = useRef19(null);
@@ -12924,7 +12968,7 @@ function GridBody({
12924
12968
  }),
12925
12969
  [host, tableId, table.data, fields.data]
12926
12970
  );
12927
- const hiddenKeys = presentation.hiddenFields;
12971
+ const hiddenKeys = hiddenOrSystemDefault(presentation.hiddenFields, fields.data);
12928
12972
  const shownKeys = useMemo27(
12929
12973
  () => hiddenKeys && hiddenKeys.length > 0 ? columnIds.filter((k) => !hiddenKeys.includes(k)) : columnIds,
12930
12974
  [columnIds, hiddenKeys]
@@ -13406,7 +13450,7 @@ function GridBody({
13406
13450
  // THE CLASSIC GRID OBEYS THE VIEW TOO (CHAIR-GRID-LINKS 07): with no merged controls the kept
13407
13451
  // `presentation.hiddenFields` / `columnOrder` still decide what is drawn.
13408
13452
  order: controls.columns?.order ?? localColumns?.order ?? (presentation.columnOrder?.length ? columnsInKeptOrder(columnIds, presentation.columnOrder) : columnIds),
13409
- hidden: controls.columns?.hidden ?? localColumns?.hidden ?? presentation.hiddenFields ?? [],
13453
+ hidden: controls.columns?.hidden ?? localColumns?.hidden ?? hiddenOrSystemDefault(presentation.hiddenFields, fields.data) ?? [],
13410
13454
  onChange: (drawn) => {
13411
13455
  const next = { order: fieldColumnIds(drawn.order, fields.data ?? []), hidden: fieldColumnIds(drawn.hidden, fields.data ?? []) };
13412
13456
  if (controls.columns) controls.columns.onChange(next);
@@ -20813,7 +20857,7 @@ function isEmptyOnCard(value) {
20813
20857
  return value === null || value === void 0 || value === "" || Array.isArray(value) && value.length === 0;
20814
20858
  }
20815
20859
  function cardFieldsShown(fields, hiddenFields, exclude) {
20816
- const hidden = new Set(hiddenFields ?? []);
20860
+ const hidden = new Set(hiddenOrSystemDefault(hiddenFields, fields) ?? []);
20817
20861
  const out = new Set(exclude.filter((k) => Boolean(k)));
20818
20862
  return fields.filter((field) => !hidden.has(field.key) && !out.has(field.key));
20819
20863
  }
@@ -20825,7 +20869,7 @@ function CardFieldsPicker({
20825
20869
  remembered,
20826
20870
  layout
20827
20871
  }) {
20828
- const hidden = new Set(hiddenFields ?? []);
20872
+ const hidden = new Set(hiddenOrSystemDefault(hiddenFields, fields) ?? []);
20829
20873
  return /* @__PURE__ */ jsxs73("details", { className: "text-xs text-muted-foreground", "data-records-card-fields": layout, children: [
20830
20874
  /* @__PURE__ */ jsx81("summary", { className: "cursor-pointer select-none", children: summary }),
20831
20875
  /* @__PURE__ */ jsx81("div", { className: "mt-1 flex flex-wrap gap-2", children: fields.map((field) => /* @__PURE__ */ jsxs73("label", { className: "flex items-center gap-1", children: [
@@ -25580,7 +25624,8 @@ function selfLinkFields(fields, tableId) {
25580
25624
  function orgCardFields(fields, hidden, exclude) {
25581
25625
  const skip = new Set(exclude.filter((k) => Boolean(k)));
25582
25626
  const usable = fields.filter((f) => !skip.has(f.key) && !["attachment", "button", "formula"].includes(String(f.type)));
25583
- const shown4 = hidden === void 0 ? usable : usable.filter((f) => !hidden.includes(f.key));
25627
+ const kept = hiddenOrSystemDefault(hidden, fields);
25628
+ const shown4 = kept === void 0 ? usable : usable.filter((f) => !kept.includes(f.key));
25584
25629
  return shown4.slice(0, 2);
25585
25630
  }
25586
25631
  function orgNotes(forest, total) {
@@ -27346,7 +27391,7 @@ function Gallery({
27346
27391
  onNew,
27347
27392
  newLabel
27348
27393
  }) {
27349
- const hidden = useMemo53(() => new Set(hiddenFields ?? []), [hiddenFields]);
27394
+ const hidden = useMemo53(() => new Set(hiddenOrSystemDefault(hiddenFields, fields) ?? []), [hiddenFields, fields]);
27350
27395
  const imageField = imageKey ? fields.find((field) => field.key === imageKey) : void 0;
27351
27396
  const shown4 = fields.filter((field) => !hidden.has(field.key) && field.key !== imageKey && field.key !== titleKey);
27352
27397
  const chose = hiddenFields !== void 0;
@@ -41530,6 +41575,7 @@ function TablePage({
41530
41575
  });
41531
41576
  }, [view, looks]);
41532
41577
  const hiddenNow = shown4?.presentation?.hiddenFields ?? [];
41578
+ const hiddenInList = hiddenOrSystemDefault(shown4?.presentation?.hiddenFields, allFields.data) ?? [];
41533
41579
  const hiddenSaved = view?.presentation?.hiddenFields ?? [];
41534
41580
  const hiddenDiffers = JSON.stringify(hiddenNow) !== JSON.stringify(hiddenSaved);
41535
41581
  const addressNow = {
@@ -42389,12 +42435,12 @@ function TablePage({
42389
42435
  tableId,
42390
42436
  archiveAsked,
42391
42437
  columns: view ? {
42392
- hidden: hiddenNow,
42438
+ hidden: hiddenInList,
42393
42439
  order: shown4?.presentation?.columnOrder ?? null,
42394
42440
  onChange: ({ hidden, order }) => {
42395
42441
  const { hiddenFields: _h, columnOrder: _o, ...rest } = shown4?.presentation ?? {};
42396
42442
  return patchView({
42397
- presentation: { ...rest, ...hidden.length > 0 ? { hiddenFields: hidden } : {}, ...order ? { columnOrder: order } : {} }
42443
+ presentation: { ...rest, ...hiddenFieldsEntry(hidden, allFields.data), ...order ? { columnOrder: order } : {} }
42398
42444
  });
42399
42445
  }
42400
42446
  } : void 0