@gemina/elements 0.13.0 → 0.13.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.
package/dist/index.d.cts CHANGED
@@ -5,6 +5,6 @@ import 'react';
5
5
  import '@gemina/sdk';
6
6
 
7
7
  /** Package version. Keep in sync with package.json. */
8
- declare const VERSION = "0.13.0";
8
+ declare const VERSION = "0.13.2";
9
9
 
10
10
  export { VERSION };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,6 @@ import 'react';
5
5
  import '@gemina/sdk';
6
6
 
7
7
  /** Package version. Keep in sync with package.json. */
8
- declare const VERSION = "0.13.0";
8
+ declare const VERSION = "0.13.2";
9
9
 
10
10
  export { VERSION };
package/dist/index.js CHANGED
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-CUOHJGPN.js";
4
4
  import {
5
5
  GeminaChat
6
- } from "./chunk-XFE7C6IS.js";
6
+ } from "./chunk-HRWPF27V.js";
7
7
  import {
8
8
  GeminaVerification
9
- } from "./chunk-5X7CGCOV.js";
9
+ } from "./chunk-JGZOUFGG.js";
10
10
  import {
11
11
  VERSION
12
- } from "./chunk-7FT4EJTY.js";
12
+ } from "./chunk-R7LDCMGS.js";
13
13
  export {
14
14
  GeminaChat,
15
15
  GeminaTokenManager,
@@ -913,87 +913,98 @@ var NOTHING_HIDDEN = {
913
913
  rows: /* @__PURE__ */ new Set()
914
914
  };
915
915
  var unplannedRowKey = (tablePointer, index) => `${tablePointer}/${index}`;
916
- function computeHidden(input) {
917
- const { classified, plannedTables, cellViews, bindingIndex, edits, pairErrors, suppressed } = input;
918
- const fields = /* @__PURE__ */ new Set();
919
- const rows = /* @__PURE__ */ new Set();
920
- const touched = (editKey) => editKey !== void 0 && (edits.has(editKey) || pairErrors.has(editKey));
921
- const editKeysByRow = /* @__PURE__ */ new Map();
922
- for (const view of cellViews) {
923
- const list = editKeysByRow.get(view.rowKey);
924
- if (list) list.push(view.editKey);
925
- else editKeysByRow.set(view.rowKey, [view.editKey]);
926
- }
927
- const considerField = (pointer, confidence) => {
928
- if (suppressed.has(pointer)) return;
929
- if (!isHighConfidence(confidence)) return;
930
- const editKey = bindingIndex.get(pointer)?.key.raw;
931
- if (editKey === void 0 || touched(editKey)) return;
932
- fields.add(pointer);
933
- };
934
- for (const header of classified.headers) {
935
- considerField(header.pointer, header.confidence);
936
- }
916
+ function forEachFieldUnit(classified, visit) {
917
+ for (const header of classified.headers) visit(header.pointer, header.confidence);
937
918
  for (const list of classified.simpleLists) {
938
- for (const item of list.items) considerField(item.pointer, item.confidence);
919
+ for (const item of list.items) visit(item.pointer, item.confidence);
939
920
  }
940
921
  for (const entity of classified.entities) {
941
922
  for (const item of entity.items) {
942
- for (const entityCell of Object.values(item)) considerField(entityCell.pointer, entityCell.confidence);
923
+ for (const cell of Object.values(item)) visit(cell.pointer, cell.confidence);
943
924
  }
944
925
  }
945
- const rowConfidence = (row) => {
926
+ }
927
+ function forEachRowUnit(tables, plannedTables, visit) {
928
+ const confidenceOf = (row) => {
946
929
  const meta = row?.[ROW_META_KEY];
947
930
  return meta?.confidence ?? null;
948
931
  };
949
- const rowIsHidable = (rowKey) => !(editKeysByRow.get(rowKey) ?? []).some((editKey) => touched(editKey));
950
- for (const table of classified.tables) {
951
- const planned = plannedTables.get(table.pointer);
932
+ const planFor = (tablePointer) => {
933
+ const exact = plannedTables.get(tablePointer);
934
+ if (exact !== void 0) return exact;
935
+ for (const [serverPointer, planned] of plannedTables) {
936
+ if (matchesTablePointer(serverPointer, tablePointer)) return planned;
937
+ }
938
+ return void 0;
939
+ };
940
+ for (const table of tables) {
941
+ const planned = planFor(table.pointer);
952
942
  if (planned) {
953
- for (const plannedRow of planned) {
954
- if (plannedRow.entry.source === null) continue;
955
- if (!isHighConfidence(rowConfidence(table.rows[plannedRow.entry.source]))) continue;
956
- if (!rowIsHidable(plannedRow.entry.id)) continue;
957
- rows.add(plannedRow.entry.id);
943
+ for (const row of planned) {
944
+ const { source } = row.entry;
945
+ visit(row.entry.id, source === null ? null : confidenceOf(table.rows[source]), source === null);
958
946
  }
959
947
  continue;
960
948
  }
961
949
  table.rows.forEach((row, index) => {
962
- if (!isHighConfidence(rowConfidence(row))) return;
963
- const key = unplannedRowKey(table.pointer, index);
964
- if (!rowIsHidable(key)) return;
965
- rows.add(key);
950
+ visit(unplannedRowKey(table.pointer, index), confidenceOf(row), false);
966
951
  });
967
952
  }
953
+ }
954
+ function computeHidden(input) {
955
+ const {
956
+ classified,
957
+ tables,
958
+ plannedTables,
959
+ cellViews,
960
+ bindingIndex,
961
+ edits,
962
+ pairErrors,
963
+ suppressed
964
+ } = input;
965
+ const fields = /* @__PURE__ */ new Set();
966
+ const rows = /* @__PURE__ */ new Set();
967
+ const touched = (editKey) => edits.has(editKey) || pairErrors.has(editKey);
968
+ const editKeysByRow = /* @__PURE__ */ new Map();
969
+ for (const view of cellViews) {
970
+ const list = editKeysByRow.get(view.rowKey);
971
+ if (list) list.push(view.editKey);
972
+ else editKeysByRow.set(view.rowKey, [view.editKey]);
973
+ }
974
+ forEachFieldUnit(classified, (pointer, confidence) => {
975
+ if (suppressed.has(pointer) || !isHighConfidence(confidence)) return;
976
+ const editKey = bindingIndex.get(pointer)?.key.raw;
977
+ if (editKey === void 0 || touched(editKey)) return;
978
+ fields.add(pointer);
979
+ });
980
+ forEachRowUnit(tables, plannedTables, (rowKey, confidence, added) => {
981
+ if (added || !isHighConfidence(confidence)) return;
982
+ if ((editKeysByRow.get(rowKey) ?? []).some(touched)) return;
983
+ rows.add(rowKey);
984
+ });
968
985
  if (fields.size === 0 && rows.size === 0) return NOTHING_HIDDEN;
969
986
  return { fields, rows };
970
987
  }
971
- function countUnits(classified, plannedTables, suppressed) {
988
+ function countUnits(classified, tables, plannedTables, suppressed) {
972
989
  let total = 0;
973
- total += classified.headers.filter((header) => !suppressed.has(header.pointer)).length;
974
- for (const list of classified.simpleLists) {
975
- total += list.items.filter((item) => !suppressed.has(item.pointer)).length;
976
- }
977
- for (const entity of classified.entities) {
978
- for (const item of entity.items) {
979
- total += Object.values(item).filter((entityCell) => !suppressed.has(entityCell.pointer)).length;
980
- }
981
- }
982
- for (const table of classified.tables) {
983
- total += plannedTables.get(table.pointer)?.length ?? table.rows.length;
984
- }
990
+ forEachFieldUnit(classified, (pointer) => {
991
+ if (!suppressed.has(pointer)) total += 1;
992
+ });
993
+ forEachRowUnit(tables, plannedTables, () => {
994
+ total += 1;
995
+ });
985
996
  return total;
986
997
  }
987
- function hasAnyConfidence(classified) {
988
- if (classified.headers.some((header) => header.confidence?.level)) return true;
989
- if (classified.simpleLists.some((list) => list.items.some((item) => item.confidence?.level))) return true;
990
- if (classified.entities.some((entity) => entity.items.some(
991
- (item) => Object.values(item).some((entityCell) => entityCell.confidence?.level)
992
- ))) return true;
993
- return classified.tables.some((table) => table.rows.some((row) => {
994
- const meta = row[ROW_META_KEY];
995
- return Boolean(meta?.confidence?.level);
996
- }));
998
+ function hasAnyConfidence(classified, tables, plannedTables) {
999
+ let found = false;
1000
+ forEachFieldUnit(classified, (_pointer, confidence) => {
1001
+ if (confidence?.level) found = true;
1002
+ });
1003
+ if (found) return true;
1004
+ forEachRowUnit(tables, plannedTables, (_rowKey, confidence) => {
1005
+ if (confidence?.level) found = true;
1006
+ });
1007
+ return found;
997
1008
  }
998
1009
 
999
1010
  // src/verification/tip.tsx
@@ -2063,35 +2074,42 @@ function HeaderSection(props) {
2063
2074
  }
2064
2075
  function EntitySection(props) {
2065
2076
  const { entity, shared } = props;
2066
- const visibleItems = entity.items.map((item) => Object.fromEntries(
2067
- Object.entries(item).filter(([, cellValue]) => !shared.hidden.fields.has(cellValue.pointer))
2068
- )).filter((item) => Object.keys(item).length > 0);
2077
+ const visibleItems = entity.items.map((item, index) => ({
2078
+ index,
2079
+ cells: Object.fromEntries(
2080
+ Object.entries(item).filter(([, cellValue]) => !shared.hidden.fields.has(cellValue.pointer))
2081
+ )
2082
+ })).filter(({ cells }) => Object.keys(cells).length > 0);
2069
2083
  const label = formatLabel(entity.key);
2070
2084
  const singular = label.replace(/s$/, "");
2071
2085
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
2072
2086
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__section-header", children: [
2073
2087
  label,
2074
2088
  " (",
2075
- visibleItems.length,
2089
+ entity.items.length,
2076
2090
  ")"
2077
2091
  ] }),
2078
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: visibleItems.map((item, itemIndex) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card", children: [
2079
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card-header", children: [
2080
- singular,
2081
- " ",
2082
- itemIndex + 1
2083
- ] }),
2084
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2085
- FieldPair,
2086
- {
2087
- label: formatLabel(fieldKey),
2088
- ariaLabel: `${singular} ${itemIndex + 1} \u2014 ${formatLabel(fieldKey)}`,
2089
- cell,
2090
- shared
2091
- },
2092
- fieldKey
2093
- )) })
2094
- ] }, itemIndex)) })
2092
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: visibleItems.map(({ index, cells }) => (
2093
+ // Keyed by the original index, never the filtered position, or React
2094
+ // reuses a hidden card's DOM (and its focus) for its successor.
2095
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card", children: [
2096
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card-header", children: [
2097
+ singular,
2098
+ " ",
2099
+ index + 1
2100
+ ] }),
2101
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: Object.entries(cells).map(([fieldKey, cell]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2102
+ FieldPair,
2103
+ {
2104
+ label: formatLabel(fieldKey),
2105
+ ariaLabel: `${singular} ${index + 1} \u2014 ${formatLabel(fieldKey)}`,
2106
+ cell,
2107
+ shared
2108
+ },
2109
+ fieldKey
2110
+ )) })
2111
+ ] }, index)
2112
+ )) })
2095
2113
  ] });
2096
2114
  }
2097
2115
  function TableRowView(props) {
@@ -2269,7 +2287,7 @@ function TableSection(props) {
2269
2287
  );
2270
2288
  const showControls = planned !== void 0 && mutable !== void 0 && !shared.readOnly && !shared.filterOn;
2271
2289
  const visiblePlanned = planned?.map((plannedRow, position) => ({ plannedRow, position })).filter(({ plannedRow }) => !shared.hidden.rows.has(plannedRow.entry.id));
2272
- const visibleRowIndices = planned ? null : table.rows.map((_row, index) => index).filter((index) => !shared.hidden.rows.has(unplannedRowKey(table.pointer, index)));
2290
+ const visibleRowIndices = planned ? [] : table.rows.map((_row, index) => index).filter((index) => !shared.hidden.rows.has(unplannedRowKey(table.pointer, index)));
2273
2291
  const visibleCount = visiblePlanned ? visiblePlanned.length : visibleRowIndices.length;
2274
2292
  const allHidden = visibleCount === 0 && rowCount > 0;
2275
2293
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
@@ -2282,6 +2300,7 @@ function TableSection(props) {
2282
2300
  needsReview > 0 ? ` \xB7 ${needsReview} need review` : "",
2283
2301
  ")"
2284
2302
  ] }),
2303
+ shared.filterOn && mutable !== void 0 && !shared.readOnly ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__filter-note", children: "Row editing is off while filtering" }) : null,
2285
2304
  table.overallConfidence ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "gemina-verification__overall-confidence", children: [
2286
2305
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Overall confidence" }),
2287
2306
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: table.overallConfidence })
@@ -2450,7 +2469,7 @@ function VerificationForm(props) {
2450
2469
  }
2451
2470
 
2452
2471
  // src/version.ts
2453
- var VERSION = "0.13.0";
2472
+ var VERSION = "0.13.2";
2454
2473
 
2455
2474
  // src/verification/styles.ts
2456
2475
  var DARK_VARS = `
@@ -3033,6 +3052,10 @@ var VERIFICATION_CSS = `
3033
3052
  font-size: 12px;
3034
3053
  color: var(--gemina-verification-muted);
3035
3054
  }
3055
+ .gemina-verification__filter-note {
3056
+ font-size: 12px;
3057
+ color: var(--gemina-verification-muted);
3058
+ }
3036
3059
  .gemina-verification__all-scored {
3037
3060
  margin: 0;
3038
3061
  padding: 12px;
@@ -3535,19 +3558,19 @@ function GeminaVerification(props) {
3535
3558
  return map;
3536
3559
  }, [bindings]);
3537
3560
  const unmatched = (0, import_react4.useMemo)(() => {
3538
- const rendered = /* @__PURE__ */ new Set();
3561
+ const rendered2 = /* @__PURE__ */ new Set();
3539
3562
  for (const field of classified.headers) {
3540
- rendered.add(field.pointer);
3563
+ rendered2.add(field.pointer);
3541
3564
  }
3542
3565
  for (const list of classified.simpleLists) {
3543
3566
  for (const item of list.items) {
3544
- rendered.add(item.pointer);
3567
+ rendered2.add(item.pointer);
3545
3568
  }
3546
3569
  }
3547
3570
  for (const entity of classified.entities) {
3548
3571
  for (const item of entity.items) {
3549
3572
  for (const cell of Object.values(item)) {
3550
- rendered.add(cell.pointer);
3573
+ rendered2.add(cell.pointer);
3551
3574
  }
3552
3575
  }
3553
3576
  }
@@ -3555,12 +3578,12 @@ function GeminaVerification(props) {
3555
3578
  for (const row of table.rows) {
3556
3579
  for (const [key, cell] of Object.entries(row)) {
3557
3580
  if (key !== ROW_META_KEY) {
3558
- rendered.add(cell.pointer);
3581
+ rendered2.add(cell.pointer);
3559
3582
  }
3560
3583
  }
3561
3584
  }
3562
3585
  }
3563
- return bindings.filter((binding) => !rendered.has(binding.fieldPointer));
3586
+ return bindings.filter((binding) => !rendered2.has(binding.fieldPointer));
3564
3587
  }, [classified, bindings]);
3565
3588
  const overlayRects = (0, import_react4.useMemo)(() => {
3566
3589
  const rects = [];
@@ -3725,28 +3748,33 @@ function GeminaVerification(props) {
3725
3748
  });
3726
3749
  }, []);
3727
3750
  const pairErrors = (0, import_react4.useMemo)(() => unitSizePairErrors(cellViews, edits), [cellViews, edits]);
3728
- const suppressed = (0, import_react4.useMemo)(
3729
- () => withEmptyMutableTables(classified, loaded?.rowMutableTables ?? []).suppressed,
3751
+ const rendered = (0, import_react4.useMemo)(
3752
+ () => withEmptyMutableTables(classified, loaded?.rowMutableTables ?? []),
3730
3753
  [classified, loaded?.rowMutableTables]
3731
3754
  );
3732
- const canFilter = (0, import_react4.useMemo)(() => hasAnyConfidence(classified), [classified]);
3755
+ const canFilter = (0, import_react4.useMemo)(
3756
+ () => hasAnyConfidence(classified, rendered.tables, plannedTables),
3757
+ [classified, rendered, plannedTables]
3758
+ );
3733
3759
  const hidden = (0, import_react4.useMemo)(
3734
3760
  () => filterOn && canFilter ? computeHidden({
3735
3761
  classified,
3762
+ tables: rendered.tables,
3736
3763
  plannedTables,
3737
3764
  cellViews,
3738
3765
  bindingIndex,
3739
3766
  edits,
3740
3767
  pairErrors,
3741
- suppressed
3768
+ suppressed: rendered.suppressed
3742
3769
  }) : NOTHING_HIDDEN,
3743
- [filterOn, canFilter, classified, plannedTables, cellViews, bindingIndex, edits, pairErrors, suppressed]
3770
+ [filterOn, canFilter, classified, rendered, plannedTables, cellViews, bindingIndex, edits, pairErrors]
3744
3771
  );
3745
3772
  const totalUnits = (0, import_react4.useMemo)(
3746
- () => countUnits(classified, plannedTables, suppressed) + unmatched.length,
3747
- [classified, plannedTables, suppressed, unmatched]
3773
+ () => countUnits(classified, rendered.tables, plannedTables, rendered.suppressed) + unmatched.length,
3774
+ [classified, rendered, plannedTables, unmatched]
3748
3775
  );
3749
3776
  const visibleUnits = totalUnits - hidden.fields.size - hidden.rows.size;
3777
+ const allClear = filterOn && totalUnits > 0 && visibleUnits === 0;
3750
3778
  const invalidCount = (0, import_react4.useMemo)(() => {
3751
3779
  const rowLevel = pairErrors.size;
3752
3780
  if (edits.size === 0) {
@@ -3907,7 +3935,7 @@ function GeminaVerification(props) {
3907
3935
  onImageExpired: handleImageExpired
3908
3936
  }
3909
3937
  ),
3910
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3938
+ allClear ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "gemina-verification__all-scored", role: "status", children: `Nothing needs review \u2014 all ${totalUnits} fields scored high.` }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3911
3939
  VerificationForm,
3912
3940
  {
3913
3941
  classified,