@gemina/elements 0.8.0 → 0.10.0
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/chat.cjs +1 -1
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/{chunk-5T2M557X.js → chunk-ILX5CY6H.js} +1446 -350
- package/dist/chunk-ILX5CY6H.js.map +1 -0
- package/dist/{chunk-724KJLIY.js → chunk-TSOUHYYB.js} +2 -2
- package/dist/{chunk-724KJLIY.js.map → chunk-TSOUHYYB.js.map} +1 -1
- package/dist/{chunk-3SZSUO7E.js → chunk-YVJI4TFI.js} +2 -2
- package/dist/index.cjs +1449 -362
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/verification.cjs +1449 -362
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-5T2M557X.js.map +0 -1
- /package/dist/{chunk-3SZSUO7E.js.map → chunk-YVJI4TFI.js.map} +0 -0
|
@@ -2,12 +2,184 @@ import {
|
|
|
2
2
|
VERSION,
|
|
3
3
|
httpStatus,
|
|
4
4
|
readErrorEnvelope
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TSOUHYYB.js";
|
|
6
6
|
|
|
7
7
|
// src/verification/index.tsx
|
|
8
|
-
import { useCallback as
|
|
8
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useId as useId2, useMemo, useRef as useRef3, useState as useState3 } from "react";
|
|
9
9
|
import { GeminaClient } from "@gemina/sdk";
|
|
10
10
|
|
|
11
|
+
// src/verification/field-types.ts
|
|
12
|
+
var ISO_4217_CODES = [
|
|
13
|
+
"AED",
|
|
14
|
+
"ARS",
|
|
15
|
+
"AUD",
|
|
16
|
+
"BGN",
|
|
17
|
+
"BRL",
|
|
18
|
+
"CAD",
|
|
19
|
+
"CHF",
|
|
20
|
+
"CLP",
|
|
21
|
+
"CNY",
|
|
22
|
+
"COP",
|
|
23
|
+
"CZK",
|
|
24
|
+
"DKK",
|
|
25
|
+
"EGP",
|
|
26
|
+
"EUR",
|
|
27
|
+
"GBP",
|
|
28
|
+
"HKD",
|
|
29
|
+
"HRK",
|
|
30
|
+
"HUF",
|
|
31
|
+
"IDR",
|
|
32
|
+
"ILS",
|
|
33
|
+
"INR",
|
|
34
|
+
"ISK",
|
|
35
|
+
"JPY",
|
|
36
|
+
"KRW",
|
|
37
|
+
"MAD",
|
|
38
|
+
"MXN",
|
|
39
|
+
"MYR",
|
|
40
|
+
"NGN",
|
|
41
|
+
"NOK",
|
|
42
|
+
"NZD",
|
|
43
|
+
"PEN",
|
|
44
|
+
"PHP",
|
|
45
|
+
"PLN",
|
|
46
|
+
"RON",
|
|
47
|
+
"RSD",
|
|
48
|
+
"RUB",
|
|
49
|
+
"SAR",
|
|
50
|
+
"SEK",
|
|
51
|
+
"SGD",
|
|
52
|
+
"THB",
|
|
53
|
+
"TRY",
|
|
54
|
+
"TWD",
|
|
55
|
+
"UAH",
|
|
56
|
+
"USD",
|
|
57
|
+
"VND",
|
|
58
|
+
"ZAR"
|
|
59
|
+
];
|
|
60
|
+
var ISO_4217_SHAPE = /^[A-Za-z]{3}$/;
|
|
61
|
+
var DATE_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
|
|
62
|
+
var NUMERIC_SHAPE = /^[+-]?[\d,_]*\.?\d+$/;
|
|
63
|
+
function toNumber(value) {
|
|
64
|
+
if (!NUMERIC_SHAPE.test(value)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const parsed = Number(value.replace(/[,_]/g, ""));
|
|
68
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
69
|
+
}
|
|
70
|
+
function validateInput(value, field) {
|
|
71
|
+
const trimmed = value.trim();
|
|
72
|
+
if (trimmed === "" || !field) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (field.enum && field.enum.length > 0) {
|
|
76
|
+
return field.enum.includes(trimmed) ? null : `Choose one of: ${field.enum.join(", ")}`;
|
|
77
|
+
}
|
|
78
|
+
if (field.format === "iso4217") {
|
|
79
|
+
return ISO_4217_SHAPE.test(trimmed) ? null : "Use a 3-letter ISO 4217 code, e.g. USD";
|
|
80
|
+
}
|
|
81
|
+
switch (field.type) {
|
|
82
|
+
case "number":
|
|
83
|
+
return toNumber(trimmed) === null ? "Enter a number" : null;
|
|
84
|
+
case "integer": {
|
|
85
|
+
const parsed = toNumber(trimmed);
|
|
86
|
+
if (parsed === null || !Number.isInteger(parsed)) {
|
|
87
|
+
return "Enter a whole number";
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
case "date": {
|
|
92
|
+
if (!DATE_SHAPE.test(trimmed)) {
|
|
93
|
+
return "Enter a date as YYYY-MM-DD";
|
|
94
|
+
}
|
|
95
|
+
const [year, month, day] = trimmed.split("-").map(Number);
|
|
96
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
97
|
+
const survives = date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
98
|
+
return survives ? null : "Enter a date as YYYY-MM-DD";
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function readRowMutableTables(raw) {
|
|
105
|
+
if (!Array.isArray(raw)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const item of raw) {
|
|
110
|
+
if (item === null || typeof item !== "object") {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const source = item;
|
|
114
|
+
if (typeof source.pointer !== "string" || typeof source.keyTemplate !== "string") {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
out.push({
|
|
118
|
+
pointer: source.pointer,
|
|
119
|
+
keyTemplate: source.keyTemplate,
|
|
120
|
+
// Columns are descriptors keyed by `name` rather than `key`, so they get
|
|
121
|
+
// the same treatment with the name standing in as the identity.
|
|
122
|
+
columns: readDescriptors(
|
|
123
|
+
(Array.isArray(source.columns) ? source.columns : []).map((column) => {
|
|
124
|
+
const record = column ?? {};
|
|
125
|
+
return { ...record, key: record.name };
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
function cellSchemaKey(template, index, field) {
|
|
133
|
+
return template.replace(/\{index\}/g, String(index)).replace(/\{field\}/g, field);
|
|
134
|
+
}
|
|
135
|
+
function coerceInput(value, field) {
|
|
136
|
+
if (!field) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
switch (field.type) {
|
|
140
|
+
case "number":
|
|
141
|
+
case "integer": {
|
|
142
|
+
const parsed = toNumber(value);
|
|
143
|
+
return parsed === null ? value : parsed;
|
|
144
|
+
}
|
|
145
|
+
case "boolean": {
|
|
146
|
+
const lowered = value.trim().toLowerCase();
|
|
147
|
+
if (lowered === "true") return true;
|
|
148
|
+
if (lowered === "false") return false;
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
// `date` stays a string: the wire format IS the ISO string, and a Date
|
|
152
|
+
// object would serialise with a time component the extraction never had.
|
|
153
|
+
default:
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function readDescriptors(raw) {
|
|
158
|
+
if (!Array.isArray(raw)) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const item of raw) {
|
|
163
|
+
if (item === null || typeof item !== "object") {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const source = item;
|
|
167
|
+
if (typeof source.key !== "string") {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const roster = source._enum ?? source.enum;
|
|
171
|
+
out.push({
|
|
172
|
+
key: source.key,
|
|
173
|
+
label: typeof source.label === "string" ? source.label : void 0,
|
|
174
|
+
type: typeof source.type === "string" ? source.type : void 0,
|
|
175
|
+
enum: Array.isArray(roster) ? roster.map(String) : null,
|
|
176
|
+
format: typeof source.format === "string" ? source.format : null,
|
|
177
|
+
description: typeof source.description === "string" ? source.description : null
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
|
|
11
183
|
// src/verification/classify.ts
|
|
12
184
|
var ACRONYMS = /* @__PURE__ */ new Set(["ID", "VAT", "OCR", "PDF", "URL", "API", "HTML", "CSS", "JSON", "XML", "UUID"]);
|
|
13
185
|
function formatLabel(key) {
|
|
@@ -119,6 +291,7 @@ function escapeSegment(segment) {
|
|
|
119
291
|
var ROW_META_KEY = "_rowMeta";
|
|
120
292
|
function classifyData(data) {
|
|
121
293
|
const result = {
|
|
294
|
+
overallConfidence: null,
|
|
122
295
|
headers: [],
|
|
123
296
|
simpleLists: [],
|
|
124
297
|
entities: [],
|
|
@@ -129,6 +302,7 @@ function classifyData(data) {
|
|
|
129
302
|
return result;
|
|
130
303
|
}
|
|
131
304
|
let rootData = data;
|
|
305
|
+
result.overallConfidence = readOverallConfidence(rootData);
|
|
132
306
|
let basePointer = "";
|
|
133
307
|
if ("data" in rootData && typeof rootData.data === "object" && rootData.data !== null && !Array.isArray(rootData.data)) {
|
|
134
308
|
for (const [key, value] of Object.entries(rootData)) {
|
|
@@ -136,6 +310,7 @@ function classifyData(data) {
|
|
|
136
310
|
processField(key, value, result, rootData, "");
|
|
137
311
|
}
|
|
138
312
|
rootData = rootData.data;
|
|
313
|
+
result.overallConfidence ?? (result.overallConfidence = readOverallConfidence(rootData));
|
|
139
314
|
basePointer = "/data";
|
|
140
315
|
}
|
|
141
316
|
for (const [key, value] of Object.entries(rootData)) {
|
|
@@ -143,8 +318,23 @@ function classifyData(data) {
|
|
|
143
318
|
}
|
|
144
319
|
return result;
|
|
145
320
|
}
|
|
321
|
+
function readOverallConfidence(source) {
|
|
322
|
+
const rawLevel = source.overall_confidence ?? source.overallConfidence;
|
|
323
|
+
const value = extractValue(rawLevel);
|
|
324
|
+
if (typeof value !== "string" || value.length === 0) return null;
|
|
325
|
+
const rawReasons = source.confidence_reasons ?? source.confidenceReasons;
|
|
326
|
+
const reasons = Array.isArray(rawReasons) ? rawReasons.filter((reason) => typeof reason === "string") : [];
|
|
327
|
+
return { level: value, reasons };
|
|
328
|
+
}
|
|
146
329
|
function processField(key, value, result, parentObj, basePointer) {
|
|
147
|
-
if ([
|
|
330
|
+
if ([
|
|
331
|
+
"confidence",
|
|
332
|
+
"confidence_reasons",
|
|
333
|
+
"confidenceReasons",
|
|
334
|
+
"coordinates",
|
|
335
|
+
"overall_confidence",
|
|
336
|
+
"overallConfidence"
|
|
337
|
+
].includes(key)) {
|
|
148
338
|
return;
|
|
149
339
|
}
|
|
150
340
|
const pointer = `${basePointer}/${escapeSegment(key)}`;
|
|
@@ -218,11 +408,6 @@ function processField(key, value, result, parentObj, basePointer) {
|
|
|
218
408
|
level: parentObj[confidenceKey],
|
|
219
409
|
reasons: parentObj[reasonsKey] || []
|
|
220
410
|
};
|
|
221
|
-
} else if (parentObj["overall_confidence"]) {
|
|
222
|
-
overallConfidence = {
|
|
223
|
-
level: parentObj["overall_confidence"],
|
|
224
|
-
reasons: parentObj["confidence_reasons"] || []
|
|
225
|
-
};
|
|
226
411
|
}
|
|
227
412
|
}
|
|
228
413
|
result.tables.push({
|
|
@@ -329,6 +514,9 @@ function parseSchemaKey(raw) {
|
|
|
329
514
|
return { raw, label: match[1], pointer: match[2] };
|
|
330
515
|
}
|
|
331
516
|
var NOT_FOUND = /* @__PURE__ */ Symbol("gemina-verification-not-found");
|
|
517
|
+
function snakeToCamel(segment) {
|
|
518
|
+
return segment.replace(/_([a-zA-Z0-9])/g, (_unused, ch) => ch.toUpperCase());
|
|
519
|
+
}
|
|
332
520
|
|
|
333
521
|
// src/verification/bindings.ts
|
|
334
522
|
function unescapeSegment(raw) {
|
|
@@ -337,9 +525,6 @@ function unescapeSegment(raw) {
|
|
|
337
525
|
function escapeSegment2(segment) {
|
|
338
526
|
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
339
527
|
}
|
|
340
|
-
function snakeToCamel(segment) {
|
|
341
|
-
return segment.replace(/_([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
|
|
342
|
-
}
|
|
343
528
|
function camelizePointer(pointer) {
|
|
344
529
|
if (!pointer.startsWith("/")) {
|
|
345
530
|
return pointer;
|
|
@@ -390,7 +575,13 @@ function resolveCasingAware(doc, pointer) {
|
|
|
390
575
|
function stripValueSuffix(pointer) {
|
|
391
576
|
return pointer.endsWith("/value") ? pointer.slice(0, -"/value".length) : pointer;
|
|
392
577
|
}
|
|
393
|
-
function buildBindings(validationSchema, values) {
|
|
578
|
+
function buildBindings(validationSchema, values, fields) {
|
|
579
|
+
const descriptors = /* @__PURE__ */ new Map();
|
|
580
|
+
for (const descriptor of fields ?? []) {
|
|
581
|
+
if (typeof descriptor?.key === "string") {
|
|
582
|
+
descriptors.set(descriptor.key, descriptor);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
394
585
|
const bindings = [];
|
|
395
586
|
for (const raw of validationSchema) {
|
|
396
587
|
const key = parseSchemaKey(raw);
|
|
@@ -405,7 +596,8 @@ function buildBindings(validationSchema, values) {
|
|
|
405
596
|
serverValue,
|
|
406
597
|
extracted,
|
|
407
598
|
fieldPointer: stripValueSuffix(resolvedPointer),
|
|
408
|
-
editable
|
|
599
|
+
editable,
|
|
600
|
+
field: descriptors.get(key.raw)
|
|
409
601
|
});
|
|
410
602
|
}
|
|
411
603
|
return bindings;
|
|
@@ -426,39 +618,368 @@ function toInputString(extracted) {
|
|
|
426
618
|
}
|
|
427
619
|
return String(extracted);
|
|
428
620
|
}
|
|
429
|
-
function composeSubmission(bindings, edits) {
|
|
621
|
+
function composeSubmission(bindings, edits, options = {}) {
|
|
622
|
+
const cells = options.cells ?? bindings.map((binding) => ({
|
|
623
|
+
editKey: binding.key.raw,
|
|
624
|
+
submitKey: binding.key.raw,
|
|
625
|
+
column: binding.key.label,
|
|
626
|
+
rowKey: binding.key.raw,
|
|
627
|
+
binding,
|
|
628
|
+
added: false
|
|
629
|
+
}));
|
|
430
630
|
const data = {};
|
|
431
631
|
const byLabel = {};
|
|
432
632
|
let confirmed = 0;
|
|
433
633
|
let corrected = 0;
|
|
434
|
-
for (const
|
|
435
|
-
const
|
|
634
|
+
for (const cell of cells) {
|
|
635
|
+
const { binding } = cell;
|
|
636
|
+
const label = parseSchemaKey(cell.submitKey)?.label ?? binding.key.label;
|
|
637
|
+
const edit = edits.get(cell.editKey);
|
|
436
638
|
if (edit !== void 0) {
|
|
437
639
|
const trimmed = edit.trim();
|
|
438
640
|
if (trimmed === "" && binding.serverValue === NOT_FOUND) {
|
|
439
641
|
continue;
|
|
440
642
|
}
|
|
441
|
-
const value = trimmed === "" ? null : trimmed;
|
|
442
|
-
data[
|
|
443
|
-
byLabel[
|
|
643
|
+
const value = trimmed === "" ? null : coerceInput(trimmed, binding.field);
|
|
644
|
+
data[cell.submitKey] = value;
|
|
645
|
+
byLabel[label] = value;
|
|
444
646
|
corrected += 1;
|
|
445
647
|
} else {
|
|
446
648
|
if (binding.serverValue === NOT_FOUND) {
|
|
447
649
|
continue;
|
|
448
650
|
}
|
|
449
|
-
data[
|
|
450
|
-
byLabel[
|
|
651
|
+
data[cell.submitKey] = binding.serverValue;
|
|
652
|
+
byLabel[label] = binding.serverValue;
|
|
451
653
|
confirmed += 1;
|
|
452
654
|
}
|
|
453
655
|
}
|
|
454
|
-
return { data, byLabel, confirmed, corrected };
|
|
656
|
+
return { data, byLabel, confirmed, corrected, rowSources: options.rowSources ?? [] };
|
|
657
|
+
}
|
|
658
|
+
function countRowsAt(values, pointer) {
|
|
659
|
+
const { node } = resolveCasingAware(values, pointer);
|
|
660
|
+
return Array.isArray(node) ? node.length : 0;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/verification/row-plan.ts
|
|
664
|
+
var addedRowCounter = 0;
|
|
665
|
+
function initialRowPlan(extractedCount, scope = "") {
|
|
666
|
+
return Array.from({ length: Math.max(0, extractedCount) }, (_unused, index) => ({
|
|
667
|
+
// Derived from the source index, so it is stable across re-renders without
|
|
668
|
+
// any state to carry — an extracted row's identity never changes.
|
|
669
|
+
id: `${scope}#row-${index}`,
|
|
670
|
+
source: index
|
|
671
|
+
}));
|
|
672
|
+
}
|
|
673
|
+
function nextAddedRowId(scope = "") {
|
|
674
|
+
addedRowCounter += 1;
|
|
675
|
+
return `${scope}#added-${addedRowCounter}`;
|
|
676
|
+
}
|
|
677
|
+
function removeRow(plan, position) {
|
|
678
|
+
if (position < 0 || position >= plan.length) {
|
|
679
|
+
return plan;
|
|
680
|
+
}
|
|
681
|
+
return plan.filter((_entry, index) => index !== position);
|
|
682
|
+
}
|
|
683
|
+
function insertRowAfter(plan, position, id) {
|
|
684
|
+
const added = { id: id ?? nextAddedRowId(), source: null };
|
|
685
|
+
const at = Math.min(Math.max(position + 1, 0), plan.length);
|
|
686
|
+
return [...plan.slice(0, at), added, ...plan.slice(at)];
|
|
687
|
+
}
|
|
688
|
+
function cellEditKey(rowId, column) {
|
|
689
|
+
return `cell:${rowId}|col:${column}`;
|
|
690
|
+
}
|
|
691
|
+
function rowSourcesOf(plan) {
|
|
692
|
+
return plan.map((entry) => entry.source);
|
|
693
|
+
}
|
|
694
|
+
function isIdentityPlan(plan, extractedCount) {
|
|
695
|
+
return plan.length === extractedCount && plan.every((entry, index) => entry.source === index);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// src/verification/row-cells.ts
|
|
699
|
+
function syntheticBinding(submitKey, descriptor) {
|
|
700
|
+
const key = parseSchemaKey(submitKey);
|
|
701
|
+
if (key === null) {
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
key,
|
|
706
|
+
serverValue: NOT_FOUND,
|
|
707
|
+
extracted: NOT_FOUND,
|
|
708
|
+
// No extracted node, so nothing to point at on the document.
|
|
709
|
+
fieldPointer: key.pointer,
|
|
710
|
+
editable: true,
|
|
711
|
+
field: descriptor
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
function planTableCells(table, plan, columns, bindingsByRawKey) {
|
|
715
|
+
const descriptors = /* @__PURE__ */ new Map();
|
|
716
|
+
for (const column of table.columns) {
|
|
717
|
+
if (typeof column.key === "string") {
|
|
718
|
+
descriptors.set(column.key, column);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return plan.map((entry, submittedIndex) => {
|
|
722
|
+
const cells = [];
|
|
723
|
+
for (const column of columns) {
|
|
724
|
+
const submitKey = cellSchemaKey(table.keyTemplate, submittedIndex, column);
|
|
725
|
+
const editKey = cellEditKey(entry.id, column);
|
|
726
|
+
const extractedKey = entry.source === null ? null : cellSchemaKey(table.keyTemplate, entry.source, column);
|
|
727
|
+
const existing = extractedKey === null ? void 0 : bindingsByRawKey.get(extractedKey);
|
|
728
|
+
const binding = existing ?? syntheticBinding(submitKey, descriptors.get(column));
|
|
729
|
+
if (binding === null) {
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
cells.push({ column, editKey, submitKey, binding, added: existing === void 0 });
|
|
733
|
+
}
|
|
734
|
+
return { entry, cells };
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function displayColumns(table, classifiedColumns) {
|
|
738
|
+
const declared = table.columns.map((column) => column.key).filter((name) => typeof name === "string");
|
|
739
|
+
const declaredAliases = new Set(declared.map(snakeToCamel));
|
|
740
|
+
return [
|
|
741
|
+
...declared,
|
|
742
|
+
...classifiedColumns.filter((name) => !declaredAliases.has(snakeToCamel(name)))
|
|
743
|
+
];
|
|
744
|
+
}
|
|
745
|
+
function matchesTablePointer(serverPointer, classifiedPointer) {
|
|
746
|
+
return serverPointer === classifiedPointer || snakeToCamel(serverPointer) === classifiedPointer;
|
|
747
|
+
}
|
|
748
|
+
function splitPointer(pointer) {
|
|
749
|
+
const cut = pointer.lastIndexOf("/");
|
|
750
|
+
return cut <= 0 ? null : { row: pointer.slice(0, cut), field: pointer.slice(cut + 1) };
|
|
751
|
+
}
|
|
752
|
+
function collectCellViews(bindings, plannedTables) {
|
|
753
|
+
const views = [];
|
|
754
|
+
const ownedPrefixes = [...plannedTables.keys()].map((pointer) => `${pointer}/`);
|
|
755
|
+
for (const rows of plannedTables.values()) {
|
|
756
|
+
for (const row of rows) {
|
|
757
|
+
for (const cell of row.cells) {
|
|
758
|
+
views.push({
|
|
759
|
+
editKey: cell.editKey,
|
|
760
|
+
submitKey: cell.submitKey,
|
|
761
|
+
column: cell.column,
|
|
762
|
+
rowKey: row.entry.id,
|
|
763
|
+
binding: cell.binding,
|
|
764
|
+
added: cell.added
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
for (const binding of bindings) {
|
|
770
|
+
if (ownedPrefixes.some((prefix) => binding.key.pointer.startsWith(prefix))) {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
const split = splitPointer(binding.key.pointer);
|
|
774
|
+
views.push({
|
|
775
|
+
// Outside a plan all three identities coincide, which is why none of
|
|
776
|
+
// this was needed before row editing.
|
|
777
|
+
editKey: binding.key.raw,
|
|
778
|
+
submitKey: binding.key.raw,
|
|
779
|
+
column: split?.field ?? binding.key.label,
|
|
780
|
+
rowKey: split?.row ?? binding.key.raw,
|
|
781
|
+
binding,
|
|
782
|
+
added: false
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return views;
|
|
786
|
+
}
|
|
787
|
+
var UNIT_SIZE = "unit_size";
|
|
788
|
+
var UNIT_SIZE_UOM = "unit_size_uom";
|
|
789
|
+
var UNIT_PAIR_MESSAGE = "Enter both value and unit";
|
|
790
|
+
function unitSizePairErrors(cells, edits) {
|
|
791
|
+
const rows = /* @__PURE__ */ new Map();
|
|
792
|
+
for (const cell of cells) {
|
|
793
|
+
if (cell.column !== UNIT_SIZE && cell.column !== UNIT_SIZE_UOM) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
const row = rows.get(cell.rowKey) ?? {};
|
|
797
|
+
if (cell.column === UNIT_SIZE) {
|
|
798
|
+
row.size = cell;
|
|
799
|
+
} else {
|
|
800
|
+
row.uom = cell;
|
|
801
|
+
}
|
|
802
|
+
rows.set(cell.rowKey, row);
|
|
803
|
+
}
|
|
804
|
+
const errors = /* @__PURE__ */ new Map();
|
|
805
|
+
for (const { size, uom } of rows.values()) {
|
|
806
|
+
if (!size || !uom) {
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
const filled = (cell) => (edits.get(cell.editKey) ?? toInputString(cell.binding.extracted)).trim() !== "";
|
|
810
|
+
if (filled(size) !== filled(uom)) {
|
|
811
|
+
errors.set(size.editKey, UNIT_PAIR_MESSAGE);
|
|
812
|
+
errors.set(uom.editKey, UNIT_PAIR_MESSAGE);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
return errors;
|
|
816
|
+
}
|
|
817
|
+
function pruneEmptyAddedRows(plannedTables, edits) {
|
|
818
|
+
const out = /* @__PURE__ */ new Map();
|
|
819
|
+
for (const [pointer, rows] of plannedTables) {
|
|
820
|
+
out.set(pointer, rows.filter((row) => {
|
|
821
|
+
if (row.entry.source !== null) {
|
|
822
|
+
return true;
|
|
823
|
+
}
|
|
824
|
+
return row.cells.some((cell) => (edits.get(cell.editKey) ?? "").trim() !== "");
|
|
825
|
+
}));
|
|
826
|
+
}
|
|
827
|
+
return out;
|
|
455
828
|
}
|
|
456
829
|
|
|
457
830
|
// src/verification/form.tsx
|
|
458
831
|
import React from "react";
|
|
459
832
|
|
|
833
|
+
// src/verification/tip.tsx
|
|
834
|
+
import {
|
|
835
|
+
cloneElement,
|
|
836
|
+
isValidElement,
|
|
837
|
+
useCallback,
|
|
838
|
+
useEffect,
|
|
839
|
+
useId,
|
|
840
|
+
useLayoutEffect,
|
|
841
|
+
useRef,
|
|
842
|
+
useState
|
|
843
|
+
} from "react";
|
|
844
|
+
import { createPortal } from "react-dom";
|
|
845
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
846
|
+
var GAP = 8;
|
|
847
|
+
var MARGIN = 8;
|
|
848
|
+
function isEmpty(content) {
|
|
849
|
+
return content == null || content === "" || content === false;
|
|
850
|
+
}
|
|
851
|
+
function rootClassesOf(node) {
|
|
852
|
+
const root = node?.closest(".gemina-verification");
|
|
853
|
+
return root ? root.className : "gemina-verification";
|
|
854
|
+
}
|
|
855
|
+
function mergeRefs(ours, theirs) {
|
|
856
|
+
return (value) => {
|
|
857
|
+
ours(value);
|
|
858
|
+
if (typeof theirs === "function") {
|
|
859
|
+
theirs(value);
|
|
860
|
+
} else if (theirs && typeof theirs === "object") {
|
|
861
|
+
theirs.current = value;
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function Tip({ content, children }) {
|
|
866
|
+
const [open, setOpen] = useState(false);
|
|
867
|
+
const [position, setPosition] = useState(null);
|
|
868
|
+
const [rootClasses, setRootClasses] = useState("gemina-verification");
|
|
869
|
+
const triggerRef = useRef(null);
|
|
870
|
+
const tipRef = useRef(null);
|
|
871
|
+
const id = useId();
|
|
872
|
+
const empty = isEmpty(content);
|
|
873
|
+
const show = useCallback(() => {
|
|
874
|
+
if (empty) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
setRootClasses(rootClassesOf(triggerRef.current));
|
|
878
|
+
setPosition(null);
|
|
879
|
+
setOpen(true);
|
|
880
|
+
}, [empty]);
|
|
881
|
+
const hide = useCallback(() => setOpen(false), []);
|
|
882
|
+
useLayoutEffect(() => {
|
|
883
|
+
if (!open) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const trigger2 = triggerRef.current;
|
|
887
|
+
const tip = tipRef.current;
|
|
888
|
+
if (!trigger2 || !tip) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
const anchor = trigger2.getBoundingClientRect();
|
|
892
|
+
const bubble = tip.getBoundingClientRect();
|
|
893
|
+
const viewportWidth = window.innerWidth || 0;
|
|
894
|
+
const viewportHeight = window.innerHeight || 0;
|
|
895
|
+
const fitsAbove = anchor.top - bubble.height - GAP >= MARGIN;
|
|
896
|
+
const fitsBelow = anchor.bottom + bubble.height + GAP <= viewportHeight - MARGIN;
|
|
897
|
+
const top = fitsAbove || !fitsBelow ? anchor.top - bubble.height - GAP : anchor.bottom + GAP;
|
|
898
|
+
const centred = anchor.left + anchor.width / 2 - bubble.width / 2;
|
|
899
|
+
const rightLimit = Math.max(MARGIN, viewportWidth - bubble.width - MARGIN);
|
|
900
|
+
const left = Math.min(Math.max(centred, MARGIN), rightLimit);
|
|
901
|
+
setPosition({ top: Math.max(top, MARGIN), left });
|
|
902
|
+
}, [open, content]);
|
|
903
|
+
useEffect(() => {
|
|
904
|
+
if (!open) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const onKeyDown = (event) => {
|
|
908
|
+
if (event.key === "Escape") {
|
|
909
|
+
hide();
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
const onScrollOrResize = () => hide();
|
|
913
|
+
document.addEventListener("keydown", onKeyDown);
|
|
914
|
+
document.addEventListener("scroll", onScrollOrResize, true);
|
|
915
|
+
window.addEventListener("resize", onScrollOrResize);
|
|
916
|
+
return () => {
|
|
917
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
918
|
+
document.removeEventListener("scroll", onScrollOrResize, true);
|
|
919
|
+
window.removeEventListener("resize", onScrollOrResize);
|
|
920
|
+
};
|
|
921
|
+
}, [open, hide]);
|
|
922
|
+
if (!isValidElement(children)) {
|
|
923
|
+
return children;
|
|
924
|
+
}
|
|
925
|
+
const childProps = children.props;
|
|
926
|
+
const call = (name, event) => {
|
|
927
|
+
const handler = childProps[name];
|
|
928
|
+
if (typeof handler === "function") {
|
|
929
|
+
handler(event);
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
const trigger = cloneElement(children, {
|
|
933
|
+
ref: mergeRefs((node) => {
|
|
934
|
+
triggerRef.current = node;
|
|
935
|
+
}, children.ref),
|
|
936
|
+
// The tip is a DESCRIPTION. `aria-label` stays untouched — it already
|
|
937
|
+
// carries the reason into the accessible NAME, and duplicating it here
|
|
938
|
+
// would have a screen reader announce it twice.
|
|
939
|
+
"aria-describedby": open && !empty ? id : void 0,
|
|
940
|
+
onMouseEnter: (event) => {
|
|
941
|
+
call("onMouseEnter", event);
|
|
942
|
+
show();
|
|
943
|
+
},
|
|
944
|
+
onMouseLeave: (event) => {
|
|
945
|
+
call("onMouseLeave", event);
|
|
946
|
+
hide();
|
|
947
|
+
},
|
|
948
|
+
onFocus: (event) => {
|
|
949
|
+
call("onFocus", event);
|
|
950
|
+
show();
|
|
951
|
+
},
|
|
952
|
+
onBlur: (event) => {
|
|
953
|
+
call("onBlur", event);
|
|
954
|
+
hide();
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
const canPortal = typeof document !== "undefined" && document.body;
|
|
958
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
959
|
+
trigger,
|
|
960
|
+
open && !empty && canPortal ? createPortal(
|
|
961
|
+
/* @__PURE__ */ jsx("div", { className: rootClasses, children: /* @__PURE__ */ jsx(
|
|
962
|
+
"div",
|
|
963
|
+
{
|
|
964
|
+
ref: tipRef,
|
|
965
|
+
id,
|
|
966
|
+
role: "tooltip",
|
|
967
|
+
className: "gemina-verification__tip",
|
|
968
|
+
style: {
|
|
969
|
+
top: position ? `${position.top}px` : "0px",
|
|
970
|
+
left: position ? `${position.left}px` : "0px",
|
|
971
|
+
visibility: position ? "visible" : "hidden"
|
|
972
|
+
},
|
|
973
|
+
children: content
|
|
974
|
+
}
|
|
975
|
+
) }),
|
|
976
|
+
document.body
|
|
977
|
+
) : null
|
|
978
|
+
] });
|
|
979
|
+
}
|
|
980
|
+
|
|
460
981
|
// src/verification/viewer.tsx
|
|
461
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
982
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
462
983
|
|
|
463
984
|
// src/verification/viewer-math.ts
|
|
464
985
|
function fitScaleFor(natural, container, rotationDeg) {
|
|
@@ -540,9 +1061,9 @@ function flashZoomTarget(rects, natural, container, rotationDeg, fitScale) {
|
|
|
540
1061
|
var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
541
1062
|
|
|
542
1063
|
// src/verification/viewer.tsx
|
|
543
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
1064
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
544
1065
|
function IconBase({ children }) {
|
|
545
|
-
return /* @__PURE__ */
|
|
1066
|
+
return /* @__PURE__ */ jsx2(
|
|
546
1067
|
"svg",
|
|
547
1068
|
{
|
|
548
1069
|
width: "16",
|
|
@@ -560,56 +1081,56 @@ function IconBase({ children }) {
|
|
|
560
1081
|
);
|
|
561
1082
|
}
|
|
562
1083
|
function GlassBody() {
|
|
563
|
-
return /* @__PURE__ */
|
|
564
|
-
/* @__PURE__ */
|
|
565
|
-
/* @__PURE__ */
|
|
1084
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
1085
|
+
/* @__PURE__ */ jsx2("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
|
|
1086
|
+
/* @__PURE__ */ jsx2("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
|
|
566
1087
|
] });
|
|
567
1088
|
}
|
|
568
1089
|
function IconZoomIn() {
|
|
569
|
-
return /* @__PURE__ */
|
|
570
|
-
/* @__PURE__ */
|
|
571
|
-
/* @__PURE__ */
|
|
572
|
-
/* @__PURE__ */
|
|
1090
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1091
|
+
/* @__PURE__ */ jsx2(GlassBody, {}),
|
|
1092
|
+
/* @__PURE__ */ jsx2("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
|
|
1093
|
+
/* @__PURE__ */ jsx2("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
|
|
573
1094
|
] });
|
|
574
1095
|
}
|
|
575
1096
|
function IconZoomOut() {
|
|
576
|
-
return /* @__PURE__ */
|
|
577
|
-
/* @__PURE__ */
|
|
578
|
-
/* @__PURE__ */
|
|
1097
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1098
|
+
/* @__PURE__ */ jsx2(GlassBody, {}),
|
|
1099
|
+
/* @__PURE__ */ jsx2("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
|
|
579
1100
|
] });
|
|
580
1101
|
}
|
|
581
1102
|
function IconMagnifier() {
|
|
582
|
-
return /* @__PURE__ */
|
|
1103
|
+
return /* @__PURE__ */ jsx2(IconBase, { children: /* @__PURE__ */ jsx2(GlassBody, {}) });
|
|
583
1104
|
}
|
|
584
1105
|
function IconActualSize() {
|
|
585
|
-
return /* @__PURE__ */
|
|
586
|
-
/* @__PURE__ */
|
|
587
|
-
/* @__PURE__ */
|
|
588
|
-
/* @__PURE__ */
|
|
589
|
-
/* @__PURE__ */
|
|
1106
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1107
|
+
/* @__PURE__ */ jsx2("polyline", { points: "2.8 6.2 4 5 4 11" }),
|
|
1108
|
+
/* @__PURE__ */ jsx2("polyline", { points: "10.8 6.2 12 5 12 11" }),
|
|
1109
|
+
/* @__PURE__ */ jsx2("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
|
|
1110
|
+
/* @__PURE__ */ jsx2("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
|
|
590
1111
|
] });
|
|
591
1112
|
}
|
|
592
1113
|
function IconFit() {
|
|
593
|
-
return /* @__PURE__ */
|
|
594
|
-
/* @__PURE__ */
|
|
595
|
-
/* @__PURE__ */
|
|
596
|
-
/* @__PURE__ */
|
|
597
|
-
/* @__PURE__ */
|
|
1114
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1115
|
+
/* @__PURE__ */ jsx2("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
|
|
1116
|
+
/* @__PURE__ */ jsx2("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
|
|
1117
|
+
/* @__PURE__ */ jsx2("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
|
|
1118
|
+
/* @__PURE__ */ jsx2("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
|
|
598
1119
|
] });
|
|
599
1120
|
}
|
|
600
1121
|
function IconRotate() {
|
|
601
|
-
return /* @__PURE__ */
|
|
602
|
-
/* @__PURE__ */
|
|
603
|
-
/* @__PURE__ */
|
|
1122
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1123
|
+
/* @__PURE__ */ jsx2("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
|
|
1124
|
+
/* @__PURE__ */ jsx2("polyline", { points: "6 1.7 8 3 6 4.3" })
|
|
604
1125
|
] });
|
|
605
1126
|
}
|
|
606
1127
|
function IconOverlay() {
|
|
607
|
-
return /* @__PURE__ */
|
|
1128
|
+
return /* @__PURE__ */ jsx2(IconBase, { children: /* @__PURE__ */ jsx2("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
|
|
608
1129
|
}
|
|
609
1130
|
function IconEye() {
|
|
610
|
-
return /* @__PURE__ */
|
|
611
|
-
/* @__PURE__ */
|
|
612
|
-
/* @__PURE__ */
|
|
1131
|
+
return /* @__PURE__ */ jsxs2(IconBase, { children: [
|
|
1132
|
+
/* @__PURE__ */ jsx2("path", { d: "M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8s-2.4 4.5-6.5 4.5S1.5 8 1.5 8z" }),
|
|
1133
|
+
/* @__PURE__ */ jsx2("circle", { cx: "8", cy: "8", r: "2.1" })
|
|
613
1134
|
] });
|
|
614
1135
|
}
|
|
615
1136
|
function ToolbarButton({
|
|
@@ -621,12 +1142,11 @@ function ToolbarButton({
|
|
|
621
1142
|
children
|
|
622
1143
|
}) {
|
|
623
1144
|
const active = (pressed ?? checked) === true;
|
|
624
|
-
return /* @__PURE__ */
|
|
1145
|
+
return /* @__PURE__ */ jsx2(Tip, { content: label, children: /* @__PURE__ */ jsx2(
|
|
625
1146
|
"button",
|
|
626
1147
|
{
|
|
627
1148
|
type: "button",
|
|
628
1149
|
className: active ? "gemina-verification__toolbar-btn gemina-verification__toolbar-btn--active" : "gemina-verification__toolbar-btn",
|
|
629
|
-
title: label,
|
|
630
1150
|
"aria-label": label,
|
|
631
1151
|
role: checked === void 0 ? void 0 : "switch",
|
|
632
1152
|
"aria-checked": checked,
|
|
@@ -635,7 +1155,7 @@ function ToolbarButton({
|
|
|
635
1155
|
onClick,
|
|
636
1156
|
children
|
|
637
1157
|
}
|
|
638
|
-
);
|
|
1158
|
+
) });
|
|
639
1159
|
}
|
|
640
1160
|
var ZOOM_STEP = 1.2;
|
|
641
1161
|
var IDENTITY = { scale: 1, tx: 0, ty: 0 };
|
|
@@ -645,6 +1165,7 @@ var REDUCED_MOTION_FLASH_MS = 800;
|
|
|
645
1165
|
var MIN_SIZE_RATIO = 8e-3;
|
|
646
1166
|
var MAG_RADIUS = 150;
|
|
647
1167
|
var MAG_ZOOM = 2.5;
|
|
1168
|
+
var MAG_BORDER = 2;
|
|
648
1169
|
function rectGeometry(rect, natural) {
|
|
649
1170
|
const xs = rect.points.map((point) => point[0]);
|
|
650
1171
|
const ys = rect.points.map((point) => point[1]);
|
|
@@ -662,29 +1183,30 @@ function rectGeometry(rect, natural) {
|
|
|
662
1183
|
}
|
|
663
1184
|
function VerificationViewer(props) {
|
|
664
1185
|
const { src, alt, relativeRects, flashRects, onFlashComplete, onImageExpired } = props;
|
|
665
|
-
const canvasRef =
|
|
666
|
-
const imgRef =
|
|
667
|
-
const [natural, setNatural] =
|
|
668
|
-
const [container, setContainer] =
|
|
669
|
-
const [transform, setTransform] =
|
|
670
|
-
const [rotation, setRotation] =
|
|
671
|
-
const [showRects, setShowRects] =
|
|
672
|
-
const [magnifierOn, setMagnifierOn] =
|
|
673
|
-
const [showMag, setShowMag] =
|
|
674
|
-
const [mousePos, setMousePos] =
|
|
675
|
-
const
|
|
676
|
-
const
|
|
677
|
-
const
|
|
678
|
-
const [
|
|
679
|
-
const
|
|
680
|
-
const
|
|
681
|
-
const
|
|
682
|
-
const
|
|
1186
|
+
const canvasRef = useRef2(null);
|
|
1187
|
+
const imgRef = useRef2(null);
|
|
1188
|
+
const [natural, setNatural] = useState2(null);
|
|
1189
|
+
const [container, setContainer] = useState2({ w: 0, h: 0 });
|
|
1190
|
+
const [transform, setTransform] = useState2(IDENTITY);
|
|
1191
|
+
const [rotation, setRotation] = useState2(0);
|
|
1192
|
+
const [showRects, setShowRects] = useState2(false);
|
|
1193
|
+
const [magnifierOn, setMagnifierOn] = useState2(false);
|
|
1194
|
+
const [showMag, setShowMag] = useState2(false);
|
|
1195
|
+
const [mousePos, setMousePos] = useState2({ x: 0, y: 0 });
|
|
1196
|
+
const lastMouseClientRef = useRef2(null);
|
|
1197
|
+
const [isPanning, setIsPanning] = useState2(false);
|
|
1198
|
+
const panStart = useRef2(null);
|
|
1199
|
+
const [flashOpacity, setFlashOpacity] = useState2(0);
|
|
1200
|
+
const [activeFlashRects, setActiveFlashRects] = useState2(null);
|
|
1201
|
+
const travelRafRef = useRef2(null);
|
|
1202
|
+
const fadeRafRef = useRef2(null);
|
|
1203
|
+
const reducedFlashTimeoutRef = useRef2(null);
|
|
1204
|
+
const transformRef = useRef2(transform);
|
|
683
1205
|
transformRef.current = transform;
|
|
684
|
-
const onFlashCompleteRef =
|
|
1206
|
+
const onFlashCompleteRef = useRef2(onFlashComplete);
|
|
685
1207
|
onFlashCompleteRef.current = onFlashComplete;
|
|
686
|
-
const hasLoadedRef =
|
|
687
|
-
|
|
1208
|
+
const hasLoadedRef = useRef2(false);
|
|
1209
|
+
useLayoutEffect2(() => {
|
|
688
1210
|
const el = canvasRef.current;
|
|
689
1211
|
if (!el) return;
|
|
690
1212
|
if (typeof ResizeObserver === "undefined") {
|
|
@@ -699,7 +1221,7 @@ function VerificationViewer(props) {
|
|
|
699
1221
|
ro.observe(el);
|
|
700
1222
|
return () => ro.disconnect();
|
|
701
1223
|
}, []);
|
|
702
|
-
const handleImgLoad =
|
|
1224
|
+
const handleImgLoad = useCallback2(() => {
|
|
703
1225
|
const img = imgRef.current;
|
|
704
1226
|
if (!img) return;
|
|
705
1227
|
hasLoadedRef.current = true;
|
|
@@ -707,19 +1229,19 @@ function VerificationViewer(props) {
|
|
|
707
1229
|
const h = img.naturalHeight;
|
|
708
1230
|
setNatural((prev) => prev && prev.w === w && prev.h === h ? prev : { w, h });
|
|
709
1231
|
}, []);
|
|
710
|
-
|
|
1232
|
+
useEffect2(() => {
|
|
711
1233
|
hasLoadedRef.current = false;
|
|
712
1234
|
}, [src]);
|
|
713
|
-
const handleImgError =
|
|
1235
|
+
const handleImgError = useCallback2(() => {
|
|
714
1236
|
if (!hasLoadedRef.current) return;
|
|
715
1237
|
hasLoadedRef.current = false;
|
|
716
1238
|
onImageExpired?.();
|
|
717
1239
|
}, [onImageExpired]);
|
|
718
|
-
const currentFitScale =
|
|
1240
|
+
const currentFitScale = useCallback2(() => {
|
|
719
1241
|
if (!natural || !container.w || !container.h) return 1;
|
|
720
1242
|
return fitScaleFor(natural, container, rotation);
|
|
721
1243
|
}, [natural, container, rotation]);
|
|
722
|
-
|
|
1244
|
+
useEffect2(() => {
|
|
723
1245
|
if (!natural || !container.w || !container.h) return;
|
|
724
1246
|
const fit = fitScaleFor(natural, container, rotation);
|
|
725
1247
|
const { tx, ty } = centeredTranslation(natural, container, fit, rotation);
|
|
@@ -727,13 +1249,13 @@ function VerificationViewer(props) {
|
|
|
727
1249
|
(prev) => Math.abs(prev.scale - fit) < 1e-4 && prev.tx === tx && prev.ty === ty ? prev : { scale: fit, tx, ty }
|
|
728
1250
|
);
|
|
729
1251
|
}, [natural, container, rotation]);
|
|
730
|
-
const cancelFlashTravel =
|
|
1252
|
+
const cancelFlashTravel = useCallback2(() => {
|
|
731
1253
|
if (travelRafRef.current !== null) {
|
|
732
1254
|
cancelAnimationFrame(travelRafRef.current);
|
|
733
1255
|
travelRafRef.current = null;
|
|
734
1256
|
}
|
|
735
1257
|
}, []);
|
|
736
|
-
const zoomBy =
|
|
1258
|
+
const zoomBy = useCallback2(
|
|
737
1259
|
(factor) => {
|
|
738
1260
|
const node = canvasRef.current;
|
|
739
1261
|
if (!node || !natural) return;
|
|
@@ -746,9 +1268,9 @@ function VerificationViewer(props) {
|
|
|
746
1268
|
},
|
|
747
1269
|
[natural, rotation, currentFitScale, cancelFlashTravel]
|
|
748
1270
|
);
|
|
749
|
-
const handleZoomIn =
|
|
750
|
-
const handleZoomOut =
|
|
751
|
-
const zoomAtClientPoint =
|
|
1271
|
+
const handleZoomIn = useCallback2(() => zoomBy(ZOOM_STEP), [zoomBy]);
|
|
1272
|
+
const handleZoomOut = useCallback2(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
|
|
1273
|
+
const zoomAtClientPoint = useCallback2(
|
|
752
1274
|
(factor, clientX, clientY) => {
|
|
753
1275
|
const node = canvasRef.current;
|
|
754
1276
|
if (!node || !natural) return;
|
|
@@ -760,7 +1282,7 @@ function VerificationViewer(props) {
|
|
|
760
1282
|
},
|
|
761
1283
|
[natural, rotation, currentFitScale]
|
|
762
1284
|
);
|
|
763
|
-
const handleWheel =
|
|
1285
|
+
const handleWheel = useCallback2(
|
|
764
1286
|
(event) => {
|
|
765
1287
|
event.preventDefault();
|
|
766
1288
|
event.stopPropagation();
|
|
@@ -770,7 +1292,7 @@ function VerificationViewer(props) {
|
|
|
770
1292
|
},
|
|
771
1293
|
[zoomAtClientPoint, cancelFlashTravel]
|
|
772
1294
|
);
|
|
773
|
-
|
|
1295
|
+
useEffect2(() => {
|
|
774
1296
|
const node = canvasRef.current;
|
|
775
1297
|
if (!node) return;
|
|
776
1298
|
const listener = (event) => handleWheel(event);
|
|
@@ -778,7 +1300,7 @@ function VerificationViewer(props) {
|
|
|
778
1300
|
return () => node.removeEventListener("wheel", listener);
|
|
779
1301
|
}, [handleWheel]);
|
|
780
1302
|
const atFitScale = transform.scale <= currentFitScale() + 1e-3;
|
|
781
|
-
const handleMouseDown =
|
|
1303
|
+
const handleMouseDown = useCallback2(
|
|
782
1304
|
(e) => {
|
|
783
1305
|
cancelFlashTravel();
|
|
784
1306
|
if (e.button !== 0) return;
|
|
@@ -789,7 +1311,7 @@ function VerificationViewer(props) {
|
|
|
789
1311
|
},
|
|
790
1312
|
[atFitScale, transform.tx, transform.ty, cancelFlashTravel]
|
|
791
1313
|
);
|
|
792
|
-
|
|
1314
|
+
useEffect2(() => {
|
|
793
1315
|
if (!isPanning) return;
|
|
794
1316
|
const onMove = (e) => {
|
|
795
1317
|
const start = panStart.current;
|
|
@@ -809,8 +1331,8 @@ function VerificationViewer(props) {
|
|
|
809
1331
|
document.removeEventListener("mouseup", onUp);
|
|
810
1332
|
};
|
|
811
1333
|
}, [isPanning]);
|
|
812
|
-
const touchState =
|
|
813
|
-
const handleTouchStart =
|
|
1334
|
+
const touchState = useRef2(null);
|
|
1335
|
+
const handleTouchStart = useCallback2(
|
|
814
1336
|
(e) => {
|
|
815
1337
|
cancelFlashTravel();
|
|
816
1338
|
const a = e.touches[0];
|
|
@@ -828,7 +1350,7 @@ function VerificationViewer(props) {
|
|
|
828
1350
|
},
|
|
829
1351
|
[atFitScale, transform.tx, transform.ty, cancelFlashTravel]
|
|
830
1352
|
);
|
|
831
|
-
const handleTouchMove =
|
|
1353
|
+
const handleTouchMove = useCallback2(
|
|
832
1354
|
(e) => {
|
|
833
1355
|
const state = touchState.current;
|
|
834
1356
|
if (!state) return;
|
|
@@ -853,19 +1375,42 @@ function VerificationViewer(props) {
|
|
|
853
1375
|
},
|
|
854
1376
|
[zoomAtClientPoint]
|
|
855
1377
|
);
|
|
856
|
-
const handleTouchEnd =
|
|
1378
|
+
const handleTouchEnd = useCallback2((e) => {
|
|
857
1379
|
if (e.touches.length === 0) touchState.current = null;
|
|
858
1380
|
}, []);
|
|
859
|
-
const
|
|
1381
|
+
const syncMagnifierToClientPoint = useCallback2((clientX, clientY, assumeInside = false) => {
|
|
860
1382
|
const rect = canvasRef.current?.getBoundingClientRect();
|
|
861
1383
|
if (!rect) return;
|
|
862
|
-
|
|
863
|
-
|
|
1384
|
+
const x = clientX - rect.left;
|
|
1385
|
+
const y = clientY - rect.top;
|
|
1386
|
+
const inside = assumeInside || x >= 0 && y >= 0 && x <= rect.width && y <= rect.height;
|
|
1387
|
+
setShowMag(inside);
|
|
1388
|
+
if (inside) {
|
|
1389
|
+
setMousePos({ x, y });
|
|
1390
|
+
}
|
|
864
1391
|
}, []);
|
|
865
|
-
const
|
|
1392
|
+
const handleCanvasMouseMove = useCallback2((e) => {
|
|
1393
|
+
lastMouseClientRef.current = { x: e.clientX, y: e.clientY };
|
|
1394
|
+
syncMagnifierToClientPoint(e.clientX, e.clientY, true);
|
|
1395
|
+
}, [syncMagnifierToClientPoint]);
|
|
1396
|
+
const handleCanvasMouseLeave = useCallback2(() => {
|
|
1397
|
+
lastMouseClientRef.current = null;
|
|
866
1398
|
setShowMag(false);
|
|
867
1399
|
}, []);
|
|
868
|
-
|
|
1400
|
+
useEffect2(() => {
|
|
1401
|
+
if (!magnifierOn || !showMag) return;
|
|
1402
|
+
const sync = () => {
|
|
1403
|
+
const point = lastMouseClientRef.current;
|
|
1404
|
+
if (point) syncMagnifierToClientPoint(point.x, point.y);
|
|
1405
|
+
};
|
|
1406
|
+
document.addEventListener("scroll", sync, true);
|
|
1407
|
+
window.addEventListener("resize", sync);
|
|
1408
|
+
return () => {
|
|
1409
|
+
document.removeEventListener("scroll", sync, true);
|
|
1410
|
+
window.removeEventListener("resize", sync);
|
|
1411
|
+
};
|
|
1412
|
+
}, [magnifierOn, showMag, syncMagnifierToClientPoint]);
|
|
1413
|
+
const handleDoubleClick = useCallback2(
|
|
869
1414
|
(e) => {
|
|
870
1415
|
cancelFlashTravel();
|
|
871
1416
|
if (!natural) return;
|
|
@@ -880,26 +1425,26 @@ function VerificationViewer(props) {
|
|
|
880
1425
|
},
|
|
881
1426
|
[natural, container, rotation, transform.scale, currentFitScale, zoomAtClientPoint, cancelFlashTravel]
|
|
882
1427
|
);
|
|
883
|
-
const handleFit =
|
|
1428
|
+
const handleFit = useCallback2(() => {
|
|
884
1429
|
if (!natural) return;
|
|
885
1430
|
cancelFlashTravel();
|
|
886
1431
|
const fit = currentFitScale();
|
|
887
1432
|
setTransform({ scale: fit, ...centeredTranslation(natural, container, fit, rotation) });
|
|
888
1433
|
}, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
|
|
889
|
-
const handleActualSize =
|
|
1434
|
+
const handleActualSize = useCallback2(() => {
|
|
890
1435
|
if (!natural) return;
|
|
891
1436
|
cancelFlashTravel();
|
|
892
1437
|
const target = clampScale(1, currentFitScale());
|
|
893
1438
|
setTransform({ scale: target, ...centeredTranslation(natural, container, target, rotation) });
|
|
894
1439
|
}, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
|
|
895
|
-
const handleRotate =
|
|
1440
|
+
const handleRotate = useCallback2(() => {
|
|
896
1441
|
setRotation((r) => (r + 90) % 360);
|
|
897
1442
|
}, []);
|
|
898
1443
|
const hasRects = relativeRects !== void 0 && relativeRects.length > 0;
|
|
899
|
-
|
|
1444
|
+
useEffect2(() => {
|
|
900
1445
|
if (!hasRects) setShowRects(false);
|
|
901
1446
|
}, [hasRects]);
|
|
902
|
-
|
|
1447
|
+
useEffect2(() => {
|
|
903
1448
|
if (!flashRects || flashRects.length === 0 || !natural || !container.w || !container.h) {
|
|
904
1449
|
setActiveFlashRects((prev) => prev === null ? prev : null);
|
|
905
1450
|
setFlashOpacity(0);
|
|
@@ -970,71 +1515,72 @@ function VerificationViewer(props) {
|
|
|
970
1515
|
const dy = mousePos.y - transform.ty;
|
|
971
1516
|
const cxRaw = (cosA * dx + sinA * dy) / transform.scale;
|
|
972
1517
|
const cyRaw = (-sinA * dx + cosA * dy) / transform.scale;
|
|
973
|
-
const
|
|
974
|
-
const clampedY = Math.max(0, Math.min(cyRaw, natural.h));
|
|
1518
|
+
const onImage = cxRaw >= 0 && cyRaw >= 0 && cxRaw <= natural.w && cyRaw <= natural.h;
|
|
975
1519
|
const zoomScale = transform.scale * MAG_ZOOM;
|
|
976
|
-
const px =
|
|
977
|
-
const py =
|
|
1520
|
+
const px = cxRaw * zoomScale;
|
|
1521
|
+
const py = cyRaw * zoomScale;
|
|
978
1522
|
const rotatedX = px * cosA - py * sinA;
|
|
979
1523
|
const rotatedY = px * sinA + py * cosA;
|
|
980
|
-
const translateX = MAG_RADIUS - rotatedX;
|
|
981
|
-
const translateY = MAG_RADIUS - rotatedY;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1524
|
+
const translateX = MAG_RADIUS - MAG_BORDER - rotatedX;
|
|
1525
|
+
const translateY = MAG_RADIUS - MAG_BORDER - rotatedY;
|
|
1526
|
+
if (onImage) {
|
|
1527
|
+
magnifier = /* @__PURE__ */ jsx2(
|
|
1528
|
+
"div",
|
|
1529
|
+
{
|
|
1530
|
+
className: "gemina-verification__magnifier",
|
|
1531
|
+
style: {
|
|
1532
|
+
width: MAG_RADIUS * 2,
|
|
1533
|
+
height: MAG_RADIUS * 2,
|
|
1534
|
+
top: mousePos.y - MAG_RADIUS,
|
|
1535
|
+
left: mousePos.x - MAG_RADIUS
|
|
1536
|
+
},
|
|
1537
|
+
children: /* @__PURE__ */ jsx2(
|
|
1538
|
+
"img",
|
|
1539
|
+
{
|
|
1540
|
+
src,
|
|
1541
|
+
alt: "",
|
|
1542
|
+
draggable: false,
|
|
1543
|
+
style: {
|
|
1544
|
+
position: "absolute",
|
|
1545
|
+
width: natural.w,
|
|
1546
|
+
height: natural.h,
|
|
1547
|
+
transformOrigin: "0 0",
|
|
1548
|
+
transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
|
|
1549
|
+
}
|
|
1004
1550
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1551
|
+
)
|
|
1552
|
+
}
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1009
1555
|
}
|
|
1010
|
-
return /* @__PURE__ */
|
|
1011
|
-
/* @__PURE__ */
|
|
1012
|
-
/* @__PURE__ */
|
|
1013
|
-
/* @__PURE__ */
|
|
1014
|
-
/* @__PURE__ */
|
|
1015
|
-
/* @__PURE__ */
|
|
1016
|
-
/* @__PURE__ */
|
|
1017
|
-
/* @__PURE__ */
|
|
1556
|
+
return /* @__PURE__ */ jsxs2("div", { className: "gemina-verification__viewer", children: [
|
|
1557
|
+
/* @__PURE__ */ jsxs2("div", { className: "gemina-verification__toolbar", children: [
|
|
1558
|
+
/* @__PURE__ */ jsx2(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ jsx2(IconZoomOut, {}) }),
|
|
1559
|
+
/* @__PURE__ */ jsx2(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ jsx2(IconZoomIn, {}) }),
|
|
1560
|
+
/* @__PURE__ */ jsx2(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ jsx2(IconActualSize, {}) }),
|
|
1561
|
+
/* @__PURE__ */ jsx2(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ jsx2(IconFit, {}) }),
|
|
1562
|
+
/* @__PURE__ */ jsx2(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ jsx2(IconRotate, {}) }),
|
|
1563
|
+
/* @__PURE__ */ jsx2(
|
|
1018
1564
|
ToolbarButton,
|
|
1019
1565
|
{
|
|
1020
1566
|
label: "Toggle detection overlays",
|
|
1021
1567
|
pressed: showRects,
|
|
1022
1568
|
disabled: !hasRects,
|
|
1023
1569
|
onClick: () => setShowRects((prev) => !prev),
|
|
1024
|
-
children: /* @__PURE__ */
|
|
1570
|
+
children: /* @__PURE__ */ jsx2(IconOverlay, {})
|
|
1025
1571
|
}
|
|
1026
1572
|
),
|
|
1027
|
-
/* @__PURE__ */
|
|
1573
|
+
/* @__PURE__ */ jsx2(
|
|
1028
1574
|
ToolbarButton,
|
|
1029
1575
|
{
|
|
1030
1576
|
label: "Magnifier",
|
|
1031
1577
|
checked: magnifierOn,
|
|
1032
1578
|
onClick: () => setMagnifierOn((prev) => !prev),
|
|
1033
|
-
children: /* @__PURE__ */
|
|
1579
|
+
children: /* @__PURE__ */ jsx2(IconMagnifier, {})
|
|
1034
1580
|
}
|
|
1035
1581
|
)
|
|
1036
1582
|
] }),
|
|
1037
|
-
/* @__PURE__ */
|
|
1583
|
+
/* @__PURE__ */ jsxs2(
|
|
1038
1584
|
"div",
|
|
1039
1585
|
{
|
|
1040
1586
|
ref: canvasRef,
|
|
@@ -1051,7 +1597,7 @@ function VerificationViewer(props) {
|
|
|
1051
1597
|
onTouchEnd: handleTouchEnd,
|
|
1052
1598
|
onTouchCancel: handleTouchEnd,
|
|
1053
1599
|
children: [
|
|
1054
|
-
/* @__PURE__ */
|
|
1600
|
+
/* @__PURE__ */ jsxs2(
|
|
1055
1601
|
"div",
|
|
1056
1602
|
{
|
|
1057
1603
|
style: {
|
|
@@ -1063,7 +1609,7 @@ function VerificationViewer(props) {
|
|
|
1063
1609
|
willChange: "transform,left,top"
|
|
1064
1610
|
},
|
|
1065
1611
|
children: [
|
|
1066
|
-
/* @__PURE__ */
|
|
1612
|
+
/* @__PURE__ */ jsx2(
|
|
1067
1613
|
"img",
|
|
1068
1614
|
{
|
|
1069
1615
|
ref: imgRef,
|
|
@@ -1077,13 +1623,13 @@ function VerificationViewer(props) {
|
|
|
1077
1623
|
showRects && natural && relativeRects?.map((rect, idx) => {
|
|
1078
1624
|
const geometry = rectGeometry(rect, natural);
|
|
1079
1625
|
if (!geometry) return null;
|
|
1080
|
-
return /* @__PURE__ */
|
|
1626
|
+
return /* @__PURE__ */ jsx2(
|
|
1081
1627
|
"div",
|
|
1082
1628
|
{
|
|
1083
1629
|
className: "gemina-verification__rect",
|
|
1084
1630
|
style: geometry,
|
|
1085
1631
|
"aria-hidden": "true",
|
|
1086
|
-
children: /* @__PURE__ */
|
|
1632
|
+
children: /* @__PURE__ */ jsxs2("span", { className: "gemina-verification__rect-badge", children: [
|
|
1087
1633
|
"#",
|
|
1088
1634
|
idx + 1
|
|
1089
1635
|
] })
|
|
@@ -1094,7 +1640,7 @@ function VerificationViewer(props) {
|
|
|
1094
1640
|
activeFlashRects && natural && activeFlashRects.map((rect, idx) => {
|
|
1095
1641
|
const geometry = rectGeometry(rect, natural);
|
|
1096
1642
|
if (!geometry) return null;
|
|
1097
|
-
return /* @__PURE__ */
|
|
1643
|
+
return /* @__PURE__ */ jsx2(
|
|
1098
1644
|
"div",
|
|
1099
1645
|
{
|
|
1100
1646
|
className: "gemina-verification__flash-rect",
|
|
@@ -1115,7 +1661,7 @@ function VerificationViewer(props) {
|
|
|
1115
1661
|
}
|
|
1116
1662
|
|
|
1117
1663
|
// src/verification/form.tsx
|
|
1118
|
-
import { Fragment as
|
|
1664
|
+
import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1119
1665
|
function ConfidenceDot(props) {
|
|
1120
1666
|
const { confidence } = props;
|
|
1121
1667
|
if (!confidence?.level) {
|
|
@@ -1141,93 +1687,156 @@ function ConfidenceDot(props) {
|
|
|
1141
1687
|
label = `${confidence.level} confidence`;
|
|
1142
1688
|
}
|
|
1143
1689
|
const reasons = confidence.reasons.map(formatLabel);
|
|
1144
|
-
const title = [label, ...reasons].join("\n");
|
|
1145
1690
|
const ariaLabel = reasons.length > 0 ? `${label}: ${reasons.join(", ")}` : label;
|
|
1146
|
-
|
|
1691
|
+
const tip = /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
1692
|
+
/* @__PURE__ */ jsx3("strong", { className: "gemina-verification__tip-title", children: label }),
|
|
1693
|
+
reasons.length > 0 ? /* @__PURE__ */ jsx3("ul", { className: "gemina-verification__tip-list", children: reasons.map((reason) => /* @__PURE__ */ jsx3("li", { children: reason }, reason)) }) : null
|
|
1694
|
+
] });
|
|
1695
|
+
return /* @__PURE__ */ jsx3(Tip, { content: tip, children: /* @__PURE__ */ jsx3(
|
|
1147
1696
|
"span",
|
|
1148
1697
|
{
|
|
1149
1698
|
className: `gemina-verification__dot gemina-verification__dot--${variant}`,
|
|
1150
1699
|
role: "img",
|
|
1151
|
-
"aria-label": ariaLabel
|
|
1152
|
-
title
|
|
1700
|
+
"aria-label": ariaLabel
|
|
1153
1701
|
}
|
|
1154
|
-
);
|
|
1702
|
+
) });
|
|
1155
1703
|
}
|
|
1156
1704
|
function EyeButton(props) {
|
|
1157
1705
|
const { coordinates, onFlash } = props;
|
|
1158
1706
|
if (!coordinates) {
|
|
1159
1707
|
return null;
|
|
1160
1708
|
}
|
|
1161
|
-
return /* @__PURE__ */
|
|
1709
|
+
return /* @__PURE__ */ jsx3(Tip, { content: "Show on document", children: /* @__PURE__ */ jsx3(
|
|
1162
1710
|
"button",
|
|
1163
1711
|
{
|
|
1164
1712
|
type: "button",
|
|
1165
1713
|
className: "gemina-verification__eye",
|
|
1166
|
-
title: "Show on document",
|
|
1167
1714
|
"aria-label": "Show on document",
|
|
1168
1715
|
onClick: (event) => {
|
|
1169
1716
|
event.stopPropagation();
|
|
1170
1717
|
onFlash();
|
|
1171
1718
|
},
|
|
1172
|
-
children: /* @__PURE__ */
|
|
1719
|
+
children: /* @__PURE__ */ jsx3(IconEye, {})
|
|
1173
1720
|
}
|
|
1174
|
-
);
|
|
1721
|
+
) });
|
|
1175
1722
|
}
|
|
1176
1723
|
function FieldInput(props) {
|
|
1177
|
-
const { binding, edit, onEdit, readOnly, ariaLabel } = props;
|
|
1724
|
+
const { binding, edit, onEdit, readOnly, ariaLabel, pairError } = props;
|
|
1725
|
+
const editKey = props.editKey ?? binding.key.raw;
|
|
1178
1726
|
const editedBadgeId = React.useId();
|
|
1727
|
+
const errorId = React.useId();
|
|
1728
|
+
const currencyListId = React.useId();
|
|
1179
1729
|
if (readOnly || !binding.editable) {
|
|
1180
1730
|
const display = binding.extracted === NOT_FOUND ? null : binding.extracted;
|
|
1181
|
-
return /* @__PURE__ */
|
|
1731
|
+
return /* @__PURE__ */ jsx3("span", { children: formatValue(display, binding.key.label) });
|
|
1182
1732
|
}
|
|
1183
1733
|
const dirty = edit !== void 0;
|
|
1184
1734
|
const missed = binding.serverValue === NOT_FOUND;
|
|
1735
|
+
const field = binding.field;
|
|
1736
|
+
const value = dirty ? edit : toInputString(binding.extracted);
|
|
1737
|
+
const error = pairError ?? (dirty ? validateInput(value, field) : null);
|
|
1185
1738
|
const className = [
|
|
1186
1739
|
"gemina-verification__input",
|
|
1187
1740
|
dirty ? "gemina-verification__input--dirty" : "",
|
|
1188
|
-
missed ? "gemina-verification__input--missed" : ""
|
|
1741
|
+
missed ? "gemina-verification__input--missed" : "",
|
|
1742
|
+
error ? "gemina-verification__input--invalid" : ""
|
|
1189
1743
|
].filter(Boolean).join(" ");
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1744
|
+
const describedBy = [dirty ? editedBadgeId : "", error ? errorId : ""].filter(Boolean).join(" ");
|
|
1745
|
+
const shared = {
|
|
1746
|
+
className,
|
|
1747
|
+
"aria-label": ariaLabel,
|
|
1748
|
+
"aria-describedby": describedBy || void 0,
|
|
1749
|
+
"aria-invalid": error ? true : void 0,
|
|
1750
|
+
onChange: (event) => onEdit(editKey, event.target.value, binding)
|
|
1751
|
+
};
|
|
1752
|
+
const roster = field?.enum && field.enum.length > 0 ? field.enum : null;
|
|
1753
|
+
const offRoster = roster && value !== "" && !roster.includes(value) ? value : null;
|
|
1754
|
+
const control = roster ? /* @__PURE__ */ jsxs3("select", { ...shared, value, dir: "auto", children: [
|
|
1755
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "\u2014" }),
|
|
1756
|
+
offRoster ? /* @__PURE__ */ jsxs3("option", { value: offRoster, children: [
|
|
1757
|
+
offRoster,
|
|
1758
|
+
" (as extracted)"
|
|
1759
|
+
] }) : null,
|
|
1760
|
+
roster.map((option) => /* @__PURE__ */ jsx3("option", { value: option, children: option }, option))
|
|
1761
|
+
] }) : /* @__PURE__ */ jsx3(
|
|
1762
|
+
"input",
|
|
1763
|
+
{
|
|
1764
|
+
...shared,
|
|
1765
|
+
type: field?.type === "date" ? "date" : "text",
|
|
1766
|
+
dir: "auto",
|
|
1767
|
+
value,
|
|
1768
|
+
inputMode: field?.type === "number" || field?.type === "integer" ? "decimal" : void 0,
|
|
1769
|
+
list: field?.format === "iso4217" ? currencyListId : void 0,
|
|
1770
|
+
placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
|
|
1771
|
+
autoComplete: "off"
|
|
1772
|
+
}
|
|
1773
|
+
);
|
|
1774
|
+
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
1775
|
+
control,
|
|
1776
|
+
field?.format === "iso4217" ? /* @__PURE__ */ jsx3("datalist", { id: currencyListId, children: ISO_4217_CODES.map((code) => /* @__PURE__ */ jsx3("option", { value: code }, code)) }) : null,
|
|
1777
|
+
error ? /* @__PURE__ */ jsx3("span", { className: "gemina-verification__field-error", id: errorId, role: "alert", children: error }) : null,
|
|
1778
|
+
dirty ? (
|
|
1779
|
+
// The badge is where the ORIGINAL belongs, now that the input holds
|
|
1780
|
+
// the edit — otherwise the extracted value is simply gone from the
|
|
1781
|
+
// screen the moment someone corrects it.
|
|
1782
|
+
//
|
|
1783
|
+
// Known limit: the badge is a non-focusable span, so this channel is
|
|
1784
|
+
// hover-only. AT is not worse off than before (nothing carried the
|
|
1785
|
+
// original previously), and the input's aria-describedby still names
|
|
1786
|
+
// the field as edited. Giving it a keyboard path needs a focusable
|
|
1787
|
+
// affordance, which belongs with the Phase 8 row work, not here.
|
|
1788
|
+
/* @__PURE__ */ jsx3(
|
|
1789
|
+
Tip,
|
|
1790
|
+
{
|
|
1791
|
+
content: /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
1792
|
+
/* @__PURE__ */ jsx3("span", { className: "gemina-verification__tip-label", children: "Was: " }),
|
|
1793
|
+
formatValue(
|
|
1794
|
+
binding.extracted === NOT_FOUND ? null : binding.extracted,
|
|
1795
|
+
binding.key.label
|
|
1796
|
+
)
|
|
1797
|
+
] }),
|
|
1798
|
+
children: /* @__PURE__ */ jsx3("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" })
|
|
1799
|
+
}
|
|
1800
|
+
)
|
|
1801
|
+
) : null
|
|
1206
1802
|
] });
|
|
1207
1803
|
}
|
|
1804
|
+
var NO_PAIR_ERRORS = /* @__PURE__ */ new Map();
|
|
1805
|
+
var NO_TABLES = [];
|
|
1806
|
+
var NO_PLANNED = /* @__PURE__ */ new Map();
|
|
1807
|
+
var NOOP_ROW = () => {
|
|
1808
|
+
};
|
|
1208
1809
|
function isInteractiveTarget(target) {
|
|
1209
1810
|
return target instanceof Element && target.closest("input, button, a, select, textarea") !== null;
|
|
1210
1811
|
}
|
|
1812
|
+
function FieldLabel(props) {
|
|
1813
|
+
const { label, description } = props;
|
|
1814
|
+
if (!description) {
|
|
1815
|
+
return /* @__PURE__ */ jsx3("span", { children: label });
|
|
1816
|
+
}
|
|
1817
|
+
return /* @__PURE__ */ jsx3(Tip, { content: description, children: /* @__PURE__ */ jsx3("span", { className: "gemina-verification__label-described", tabIndex: 0, children: label }) });
|
|
1818
|
+
}
|
|
1211
1819
|
function FieldPair(props) {
|
|
1212
1820
|
const { label, ariaLabel, cell, shared } = props;
|
|
1213
1821
|
const binding = shared.bindingIndex.get(cell.pointer);
|
|
1214
|
-
return /* @__PURE__ */
|
|
1215
|
-
/* @__PURE__ */
|
|
1216
|
-
/* @__PURE__ */
|
|
1217
|
-
/* @__PURE__ */
|
|
1822
|
+
return /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
1823
|
+
/* @__PURE__ */ jsxs3("dt", { className: "gemina-verification__dt", children: [
|
|
1824
|
+
/* @__PURE__ */ jsx3(ConfidenceDot, { confidence: cell.confidence }),
|
|
1825
|
+
/* @__PURE__ */ jsx3(FieldLabel, { label, description: binding?.field?.description })
|
|
1218
1826
|
] }),
|
|
1219
|
-
/* @__PURE__ */
|
|
1220
|
-
binding !== void 0 ? /* @__PURE__ */
|
|
1827
|
+
/* @__PURE__ */ jsxs3("dd", { className: "gemina-verification__dd", children: [
|
|
1828
|
+
binding !== void 0 ? /* @__PURE__ */ jsx3(
|
|
1221
1829
|
FieldInput,
|
|
1222
1830
|
{
|
|
1223
1831
|
binding,
|
|
1832
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1224
1833
|
edit: shared.edits.get(binding.key.raw),
|
|
1225
1834
|
onEdit: shared.onEdit,
|
|
1226
1835
|
readOnly: shared.readOnly,
|
|
1227
1836
|
ariaLabel
|
|
1228
1837
|
}
|
|
1229
|
-
) : /* @__PURE__ */
|
|
1230
|
-
/* @__PURE__ */
|
|
1838
|
+
) : /* @__PURE__ */ jsx3("span", { children: formatValue(cell.value, label) }),
|
|
1839
|
+
/* @__PURE__ */ jsx3(
|
|
1231
1840
|
EyeButton,
|
|
1232
1841
|
{
|
|
1233
1842
|
coordinates: cell.coordinates,
|
|
@@ -1246,10 +1855,10 @@ function HeaderSection(props) {
|
|
|
1246
1855
|
if (headers.length === 0 && simpleLists.length === 0) {
|
|
1247
1856
|
return null;
|
|
1248
1857
|
}
|
|
1249
|
-
return /* @__PURE__ */
|
|
1250
|
-
/* @__PURE__ */
|
|
1251
|
-
/* @__PURE__ */
|
|
1252
|
-
headers.map((field) => /* @__PURE__ */
|
|
1858
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
|
|
1859
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Details" }),
|
|
1860
|
+
/* @__PURE__ */ jsxs3("dl", { className: "gemina-verification__dl", children: [
|
|
1861
|
+
headers.map((field) => /* @__PURE__ */ jsx3(
|
|
1253
1862
|
FieldPair,
|
|
1254
1863
|
{
|
|
1255
1864
|
label: formatLabel(field.key),
|
|
@@ -1259,23 +1868,24 @@ function HeaderSection(props) {
|
|
|
1259
1868
|
},
|
|
1260
1869
|
field.pointer
|
|
1261
1870
|
)),
|
|
1262
|
-
simpleLists.map((list) => /* @__PURE__ */
|
|
1263
|
-
/* @__PURE__ */
|
|
1264
|
-
/* @__PURE__ */
|
|
1871
|
+
simpleLists.map((list) => /* @__PURE__ */ jsxs3(React.Fragment, { children: [
|
|
1872
|
+
/* @__PURE__ */ jsx3("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx3("span", { children: formatLabel(list.key) }) }),
|
|
1873
|
+
/* @__PURE__ */ jsx3("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx3("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
|
|
1265
1874
|
const binding = shared.bindingIndex.get(item.pointer);
|
|
1266
|
-
return /* @__PURE__ */
|
|
1267
|
-
binding !== void 0 ? /* @__PURE__ */
|
|
1875
|
+
return /* @__PURE__ */ jsxs3("li", { className: "gemina-verification__cell", children: [
|
|
1876
|
+
binding !== void 0 ? /* @__PURE__ */ jsx3(
|
|
1268
1877
|
FieldInput,
|
|
1269
1878
|
{
|
|
1270
1879
|
binding,
|
|
1880
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1271
1881
|
edit: shared.edits.get(binding.key.raw),
|
|
1272
1882
|
onEdit: shared.onEdit,
|
|
1273
1883
|
readOnly: shared.readOnly,
|
|
1274
1884
|
ariaLabel: `${formatLabel(list.key)} item ${index + 1}`
|
|
1275
1885
|
}
|
|
1276
|
-
) : /* @__PURE__ */
|
|
1277
|
-
/* @__PURE__ */
|
|
1278
|
-
/* @__PURE__ */
|
|
1886
|
+
) : /* @__PURE__ */ jsx3("span", { children: formatValue(item.value) }),
|
|
1887
|
+
/* @__PURE__ */ jsx3(ConfidenceDot, { confidence: item.confidence }),
|
|
1888
|
+
/* @__PURE__ */ jsx3(
|
|
1279
1889
|
EyeButton,
|
|
1280
1890
|
{
|
|
1281
1891
|
coordinates: item.coordinates,
|
|
@@ -1296,20 +1906,20 @@ function EntitySection(props) {
|
|
|
1296
1906
|
const { entity, shared } = props;
|
|
1297
1907
|
const label = formatLabel(entity.key);
|
|
1298
1908
|
const singular = label.replace(/s$/, "");
|
|
1299
|
-
return /* @__PURE__ */
|
|
1300
|
-
/* @__PURE__ */
|
|
1909
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": label, children: [
|
|
1910
|
+
/* @__PURE__ */ jsxs3("div", { className: "gemina-verification__section-header", children: [
|
|
1301
1911
|
label,
|
|
1302
1912
|
" (",
|
|
1303
1913
|
entity.items.length,
|
|
1304
1914
|
")"
|
|
1305
1915
|
] }),
|
|
1306
|
-
/* @__PURE__ */
|
|
1307
|
-
/* @__PURE__ */
|
|
1916
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__card", children: [
|
|
1917
|
+
/* @__PURE__ */ jsxs3("div", { className: "gemina-verification__card-header", children: [
|
|
1308
1918
|
singular,
|
|
1309
1919
|
" ",
|
|
1310
1920
|
itemIndex + 1
|
|
1311
1921
|
] }),
|
|
1312
|
-
/* @__PURE__ */
|
|
1922
|
+
/* @__PURE__ */ jsx3("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ jsx3(
|
|
1313
1923
|
FieldPair,
|
|
1314
1924
|
{
|
|
1315
1925
|
label: formatLabel(fieldKey),
|
|
@@ -1323,11 +1933,11 @@ function EntitySection(props) {
|
|
|
1323
1933
|
] });
|
|
1324
1934
|
}
|
|
1325
1935
|
function TableRowView(props) {
|
|
1326
|
-
const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared } = props;
|
|
1936
|
+
const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared, planned, tablePointer } = props;
|
|
1327
1937
|
const { bindingIndex, edits, onEdit, readOnly, onFlash } = shared;
|
|
1328
1938
|
const rects = React.useMemo(() => {
|
|
1329
1939
|
const collected = [];
|
|
1330
|
-
for (const [key, cell] of Object.entries(row)) {
|
|
1940
|
+
for (const [key, cell] of Object.entries(row ?? {})) {
|
|
1331
1941
|
if (key !== ROW_META_KEY && cell.coordinates) {
|
|
1332
1942
|
collected.push(cell.coordinates);
|
|
1333
1943
|
}
|
|
@@ -1345,49 +1955,129 @@ function TableRowView(props) {
|
|
|
1345
1955
|
},
|
|
1346
1956
|
[rects, onFlash]
|
|
1347
1957
|
);
|
|
1958
|
+
const cellFor = (column) => {
|
|
1959
|
+
const direct = row?.[column];
|
|
1960
|
+
const alias = direct === void 0 ? row?.[snakeToCamel(column)] : void 0;
|
|
1961
|
+
const fallbackKey = direct === void 0 && alias === void 0 && row !== void 0 ? Object.keys(row).find((key) => snakeToCamel(key) === snakeToCamel(column)) : void 0;
|
|
1962
|
+
const classified = direct ?? alias ?? (fallbackKey === void 0 ? void 0 : row?.[fallbackKey]);
|
|
1963
|
+
const fromPlan = planned?.cells.find((cell) => cell.column === column);
|
|
1964
|
+
if (fromPlan) {
|
|
1965
|
+
return { classified, binding: fromPlan.binding, editKey: fromPlan.editKey };
|
|
1966
|
+
}
|
|
1967
|
+
const binding = classified === void 0 ? void 0 : bindingIndex.get(classified.pointer);
|
|
1968
|
+
return { classified, binding, editKey: binding?.key.raw };
|
|
1969
|
+
};
|
|
1348
1970
|
const firstRect = rects.length > 0 ? rects[0] : null;
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1971
|
+
const showControls = planned !== void 0 && tablePointer !== void 0 && !readOnly;
|
|
1972
|
+
const rowLevel = (row?.[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
|
|
1973
|
+
const rowClass = rowLevel === "low" || rowLevel === "medium" ? `gemina-verification__row--${rowLevel}` : void 0;
|
|
1974
|
+
return /* @__PURE__ */ jsxs3("tr", { onClick: handleRowClick, className: rowClass, children: [
|
|
1975
|
+
hasCoords ? /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsx3(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
|
|
1976
|
+
hasRowConfidence ? /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsx3(ConfidenceDot, { confidence: row?.[ROW_META_KEY]?.confidence ?? null }) }) : null,
|
|
1352
1977
|
columns.map((column) => {
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
binding !== void 0 ? /* @__PURE__ */ jsx2(
|
|
1978
|
+
const { classified, binding, editKey } = cellFor(column);
|
|
1979
|
+
return /* @__PURE__ */ jsx3("td", { children: /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__cell", children: [
|
|
1980
|
+
binding !== void 0 ? /* @__PURE__ */ jsx3(
|
|
1357
1981
|
FieldInput,
|
|
1358
1982
|
{
|
|
1359
1983
|
binding,
|
|
1360
|
-
|
|
1984
|
+
editKey,
|
|
1985
|
+
pairError: editKey === void 0 ? void 0 : shared.pairErrors.get(editKey),
|
|
1986
|
+
edit: editKey === void 0 ? void 0 : edits.get(editKey),
|
|
1361
1987
|
onEdit,
|
|
1362
1988
|
readOnly,
|
|
1363
1989
|
ariaLabel: `${tableLabel} row ${rowIndex + 1} \u2014 ${formatLabel(column)}`
|
|
1364
1990
|
}
|
|
1365
|
-
) : /* @__PURE__ */
|
|
1366
|
-
/* @__PURE__ */
|
|
1991
|
+
) : /* @__PURE__ */ jsx3("span", { children: classified === void 0 ? "-" : formatValue(classified.value, column) }),
|
|
1992
|
+
/* @__PURE__ */ jsx3(ConfidenceDot, { confidence: classified?.confidence ?? null })
|
|
1367
1993
|
] }) }, column);
|
|
1368
|
-
})
|
|
1994
|
+
}),
|
|
1995
|
+
showControls ? /* @__PURE__ */ jsxs3("td", { className: "gemina-verification__row-actions", children: [
|
|
1996
|
+
/* @__PURE__ */ jsx3(Tip, { content: "Insert a line below", children: /* @__PURE__ */ jsx3(
|
|
1997
|
+
"button",
|
|
1998
|
+
{
|
|
1999
|
+
type: "button",
|
|
2000
|
+
className: "gemina-verification__row-btn",
|
|
2001
|
+
"aria-label": `Insert line below line ${rowIndex + 1}`,
|
|
2002
|
+
onClick: () => shared.onAddRow(tablePointer, rowIndex),
|
|
2003
|
+
children: "+"
|
|
2004
|
+
}
|
|
2005
|
+
) }),
|
|
2006
|
+
/* @__PURE__ */ jsx3(Tip, { content: "Remove this line", children: /* @__PURE__ */ jsx3(
|
|
2007
|
+
"button",
|
|
2008
|
+
{
|
|
2009
|
+
type: "button",
|
|
2010
|
+
className: "gemina-verification__row-btn",
|
|
2011
|
+
"aria-label": `Remove line ${rowIndex + 1}`,
|
|
2012
|
+
onClick: () => shared.onRemoveRow(tablePointer, rowIndex),
|
|
2013
|
+
children: "\xD7"
|
|
2014
|
+
}
|
|
2015
|
+
) })
|
|
2016
|
+
] }) : null
|
|
1369
2017
|
] });
|
|
1370
2018
|
}
|
|
1371
2019
|
function areRowPropsEqual(prev, next) {
|
|
1372
|
-
if (prev.row !== next.row || prev.rowIndex !== next.rowIndex || prev.columns !== next.columns || prev.tableLabel !== next.tableLabel || prev.hasCoords !== next.hasCoords || prev.hasRowConfidence !== next.hasRowConfidence || prev.shared.bindingIndex !== next.shared.bindingIndex || prev.shared.onEdit !== next.shared.onEdit || prev.shared.onFlash !== next.shared.onFlash || prev.shared.readOnly !== next.shared.readOnly) {
|
|
2020
|
+
if (prev.row !== next.row || prev.rowIndex !== next.rowIndex || prev.columns !== next.columns || prev.tableLabel !== next.tableLabel || prev.hasCoords !== next.hasCoords || prev.hasRowConfidence !== next.hasRowConfidence || prev.planned !== next.planned || prev.tablePointer !== next.tablePointer || prev.shared.bindingIndex !== next.shared.bindingIndex || prev.shared.onEdit !== next.shared.onEdit || prev.shared.onFlash !== next.shared.onFlash || prev.shared.readOnly !== next.shared.readOnly) {
|
|
1373
2021
|
return false;
|
|
1374
2022
|
}
|
|
1375
2023
|
if (prev.shared.edits === next.shared.edits) {
|
|
1376
2024
|
return true;
|
|
1377
2025
|
}
|
|
1378
2026
|
for (const column of next.columns) {
|
|
1379
|
-
const
|
|
1380
|
-
const
|
|
1381
|
-
|
|
2027
|
+
const planned = next.planned?.cells.find((cell) => cell.column === column);
|
|
2028
|
+
const classified = next.row?.[column];
|
|
2029
|
+
const editKey = planned?.editKey ?? (classified === void 0 ? void 0 : next.shared.bindingIndex.get(classified.pointer)?.key.raw);
|
|
2030
|
+
if (editKey === void 0) {
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
if (prev.shared.edits.get(editKey) !== next.shared.edits.get(editKey) || prev.shared.pairErrors.get(editKey) !== next.shared.pairErrors.get(editKey)) {
|
|
1382
2034
|
return false;
|
|
1383
2035
|
}
|
|
1384
2036
|
}
|
|
1385
2037
|
return true;
|
|
1386
2038
|
}
|
|
1387
2039
|
var TableRow = React.memo(TableRowView, areRowPropsEqual);
|
|
2040
|
+
function withEmptyMutableTables(classified, tables) {
|
|
2041
|
+
if (tables.length === 0) {
|
|
2042
|
+
return { tables: classified.tables, suppressed: EMPTY_SUPPRESSED };
|
|
2043
|
+
}
|
|
2044
|
+
const promoted = [...classified.tables];
|
|
2045
|
+
const suppressed = /* @__PURE__ */ new Set();
|
|
2046
|
+
for (const table of tables) {
|
|
2047
|
+
if (classified.tables.some((candidate) => matchesTablePointer(table.pointer, candidate.pointer))) {
|
|
2048
|
+
continue;
|
|
2049
|
+
}
|
|
2050
|
+
const header = classified.headers.find(
|
|
2051
|
+
(candidate) => matchesTablePointer(table.pointer, candidate.pointer)
|
|
2052
|
+
);
|
|
2053
|
+
const empty = header !== void 0 && (header.value === null || Array.isArray(header.value) && header.value.length === 0);
|
|
2054
|
+
if (!empty) {
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
suppressed.add(header.pointer);
|
|
2058
|
+
promoted.push({
|
|
2059
|
+
key: header.key,
|
|
2060
|
+
pointer: header.pointer,
|
|
2061
|
+
columns: [],
|
|
2062
|
+
rows: [],
|
|
2063
|
+
overallConfidence: null
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
return { tables: promoted, suppressed };
|
|
2067
|
+
}
|
|
2068
|
+
var EMPTY_SUPPRESSED = /* @__PURE__ */ new Set();
|
|
1388
2069
|
function TableSection(props) {
|
|
1389
2070
|
const { table, shared } = props;
|
|
1390
2071
|
const label = formatLabel(table.key);
|
|
2072
|
+
const mutable = React.useMemo(
|
|
2073
|
+
() => shared.rowMutableTables.find((entry) => matchesTablePointer(entry.pointer, table.pointer)),
|
|
2074
|
+
[shared.rowMutableTables, table.pointer]
|
|
2075
|
+
);
|
|
2076
|
+
const columns = React.useMemo(
|
|
2077
|
+
() => mutable ? displayColumns(mutable, table.columns) : table.columns,
|
|
2078
|
+
[mutable, table.columns]
|
|
2079
|
+
);
|
|
2080
|
+
const planned = mutable ? shared.plannedTables.get(mutable.pointer) : void 0;
|
|
1391
2081
|
const hasCoords = React.useMemo(
|
|
1392
2082
|
() => table.rows.some(
|
|
1393
2083
|
(row) => Object.entries(row).some(([key, cell]) => key !== ROW_META_KEY && cell.coordinates !== null)
|
|
@@ -1398,28 +2088,72 @@ function TableSection(props) {
|
|
|
1398
2088
|
() => table.rows.some((row) => Boolean(row[ROW_META_KEY]?.confidence?.level)),
|
|
1399
2089
|
[table]
|
|
1400
2090
|
);
|
|
1401
|
-
|
|
1402
|
-
/* @__PURE__ */
|
|
1403
|
-
|
|
2091
|
+
const columnDescriptions = React.useMemo(() => {
|
|
2092
|
+
const map = /* @__PURE__ */ new Map();
|
|
2093
|
+
for (const column of mutable?.columns ?? []) {
|
|
2094
|
+
if (typeof column.key === "string" && column.description) {
|
|
2095
|
+
map.set(column.key, column.description);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
return map;
|
|
2099
|
+
}, [mutable]);
|
|
2100
|
+
const rowCount = planned ? planned.length : table.rows.length;
|
|
2101
|
+
const needsReview = React.useMemo(
|
|
2102
|
+
() => table.rows.filter((row) => {
|
|
2103
|
+
const level = (row[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
|
|
2104
|
+
return level === "low" || level === "medium";
|
|
2105
|
+
}).length,
|
|
2106
|
+
[table.rows]
|
|
2107
|
+
);
|
|
2108
|
+
const showControls = planned !== void 0 && mutable !== void 0 && !shared.readOnly;
|
|
2109
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": label, children: [
|
|
2110
|
+
/* @__PURE__ */ jsxs3("div", { className: "gemina-verification__section-header", children: [
|
|
2111
|
+
/* @__PURE__ */ jsxs3("span", { children: [
|
|
1404
2112
|
label,
|
|
1405
2113
|
" (",
|
|
1406
|
-
|
|
1407
|
-
" rows
|
|
2114
|
+
rowCount,
|
|
2115
|
+
" rows",
|
|
2116
|
+
needsReview > 0 ? ` \xB7 ${needsReview} need review` : "",
|
|
2117
|
+
")"
|
|
1408
2118
|
] }),
|
|
1409
|
-
/* @__PURE__ */
|
|
2119
|
+
table.overallConfidence ? /* @__PURE__ */ jsxs3("span", { className: "gemina-verification__overall-confidence", children: [
|
|
2120
|
+
/* @__PURE__ */ jsx3("span", { children: "Overall confidence" }),
|
|
2121
|
+
/* @__PURE__ */ jsx3(ConfidenceDot, { confidence: table.overallConfidence })
|
|
2122
|
+
] }) : null
|
|
1410
2123
|
] }),
|
|
1411
|
-
/* @__PURE__ */
|
|
1412
|
-
/* @__PURE__ */
|
|
1413
|
-
hasCoords ? /* @__PURE__ */
|
|
1414
|
-
hasRowConfidence ? /* @__PURE__ */
|
|
1415
|
-
|
|
2124
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ jsxs3("table", { className: "gemina-verification__table", children: [
|
|
2125
|
+
/* @__PURE__ */ jsx3("thead", { children: /* @__PURE__ */ jsxs3("tr", { children: [
|
|
2126
|
+
hasCoords ? /* @__PURE__ */ jsx3("th", { "aria-label": "Show row on document" }) : null,
|
|
2127
|
+
hasRowConfidence ? /* @__PURE__ */ jsx3("th", { "aria-label": "Row confidence" }) : null,
|
|
2128
|
+
columns.map((column) => /* @__PURE__ */ jsx3("th", { children: /* @__PURE__ */ jsx3(
|
|
2129
|
+
FieldLabel,
|
|
2130
|
+
{
|
|
2131
|
+
label: formatLabel(column),
|
|
2132
|
+
description: columnDescriptions.get(column)
|
|
2133
|
+
}
|
|
2134
|
+
) }, column)),
|
|
2135
|
+
showControls ? /* @__PURE__ */ jsx3("th", { "aria-label": "Row actions" }) : null
|
|
1416
2136
|
] }) }),
|
|
1417
|
-
/* @__PURE__ */
|
|
2137
|
+
/* @__PURE__ */ jsx3("tbody", { children: planned ? planned.map((plannedRow, position) => /* @__PURE__ */ jsx3(
|
|
2138
|
+
TableRow,
|
|
2139
|
+
{
|
|
2140
|
+
row: plannedRow.entry.source === null ? void 0 : table.rows[plannedRow.entry.source],
|
|
2141
|
+
rowIndex: position,
|
|
2142
|
+
columns,
|
|
2143
|
+
tableLabel: label,
|
|
2144
|
+
hasCoords,
|
|
2145
|
+
hasRowConfidence,
|
|
2146
|
+
shared,
|
|
2147
|
+
planned: plannedRow,
|
|
2148
|
+
tablePointer: mutable.pointer
|
|
2149
|
+
},
|
|
2150
|
+
plannedRow.entry.id
|
|
2151
|
+
)) : table.rows.map((row, rowIndex) => /* @__PURE__ */ jsx3(
|
|
1418
2152
|
TableRow,
|
|
1419
2153
|
{
|
|
1420
2154
|
row,
|
|
1421
2155
|
rowIndex,
|
|
1422
|
-
columns
|
|
2156
|
+
columns,
|
|
1423
2157
|
tableLabel: label,
|
|
1424
2158
|
hasCoords,
|
|
1425
2159
|
hasRowConfidence,
|
|
@@ -1427,7 +2161,16 @@ function TableSection(props) {
|
|
|
1427
2161
|
},
|
|
1428
2162
|
rowIndex
|
|
1429
2163
|
)) })
|
|
1430
|
-
] }) })
|
|
2164
|
+
] }) }),
|
|
2165
|
+
showControls ? /* @__PURE__ */ jsx3("div", { className: "gemina-verification__table-footer", children: /* @__PURE__ */ jsx3(
|
|
2166
|
+
"button",
|
|
2167
|
+
{
|
|
2168
|
+
type: "button",
|
|
2169
|
+
className: "gemina-verification__add-row",
|
|
2170
|
+
onClick: () => shared.onAddRow(mutable.pointer, rowCount - 1),
|
|
2171
|
+
children: "Add line"
|
|
2172
|
+
}
|
|
2173
|
+
) }) : null
|
|
1431
2174
|
] });
|
|
1432
2175
|
}
|
|
1433
2176
|
var FallbackSection = React.memo(function FallbackSection2(props) {
|
|
@@ -1435,11 +2178,11 @@ var FallbackSection = React.memo(function FallbackSection2(props) {
|
|
|
1435
2178
|
if (fallback.length === 0) {
|
|
1436
2179
|
return null;
|
|
1437
2180
|
}
|
|
1438
|
-
return /* @__PURE__ */
|
|
1439
|
-
/* @__PURE__ */
|
|
1440
|
-
/* @__PURE__ */
|
|
1441
|
-
/* @__PURE__ */
|
|
1442
|
-
/* @__PURE__ */
|
|
2181
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
|
|
2182
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
|
|
2183
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ jsxs3("details", { className: "gemina-verification__fallback", children: [
|
|
2184
|
+
/* @__PURE__ */ jsx3("summary", { children: formatLabel(item.key) }),
|
|
2185
|
+
/* @__PURE__ */ jsx3("pre", { children: JSON.stringify(item.data, null, 2) })
|
|
1443
2186
|
] }, item.key)) })
|
|
1444
2187
|
] });
|
|
1445
2188
|
});
|
|
@@ -1448,14 +2191,15 @@ function UnmatchedSection(props) {
|
|
|
1448
2191
|
if (unmatched.length === 0) {
|
|
1449
2192
|
return null;
|
|
1450
2193
|
}
|
|
1451
|
-
return /* @__PURE__ */
|
|
1452
|
-
/* @__PURE__ */
|
|
1453
|
-
/* @__PURE__ */
|
|
1454
|
-
/* @__PURE__ */
|
|
1455
|
-
/* @__PURE__ */
|
|
2194
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
|
|
2195
|
+
/* @__PURE__ */ jsx3("div", { className: "gemina-verification__section-header", children: "Not detected" }),
|
|
2196
|
+
/* @__PURE__ */ jsx3("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ jsxs3(React.Fragment, { children: [
|
|
2197
|
+
/* @__PURE__ */ jsx3("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ jsx3("span", { children: binding.key.label }) }),
|
|
2198
|
+
/* @__PURE__ */ jsx3("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ jsx3(
|
|
1456
2199
|
FieldInput,
|
|
1457
2200
|
{
|
|
1458
2201
|
binding,
|
|
2202
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1459
2203
|
edit: shared.edits.get(binding.key.raw),
|
|
1460
2204
|
onEdit: shared.onEdit,
|
|
1461
2205
|
readOnly: shared.readOnly,
|
|
@@ -1466,26 +2210,65 @@ function UnmatchedSection(props) {
|
|
|
1466
2210
|
] });
|
|
1467
2211
|
}
|
|
1468
2212
|
function VerificationForm(props) {
|
|
1469
|
-
const {
|
|
1470
|
-
|
|
2213
|
+
const {
|
|
2214
|
+
classified,
|
|
2215
|
+
unmatched,
|
|
2216
|
+
bindingIndex,
|
|
2217
|
+
edits,
|
|
2218
|
+
onEdit,
|
|
2219
|
+
readOnly,
|
|
2220
|
+
onFlash,
|
|
2221
|
+
pairErrors,
|
|
2222
|
+
rowMutableTables,
|
|
2223
|
+
plannedTables,
|
|
2224
|
+
onAddRow,
|
|
2225
|
+
onRemoveRow
|
|
2226
|
+
} = props;
|
|
2227
|
+
const { tables: promotedTables, suppressed } = React.useMemo(
|
|
2228
|
+
() => withEmptyMutableTables(classified, rowMutableTables ?? NO_TABLES),
|
|
2229
|
+
[classified, rowMutableTables]
|
|
2230
|
+
);
|
|
2231
|
+
const shared = {
|
|
2232
|
+
bindingIndex,
|
|
2233
|
+
edits,
|
|
2234
|
+
onEdit,
|
|
2235
|
+
readOnly,
|
|
2236
|
+
onFlash,
|
|
2237
|
+
pairErrors: pairErrors ?? NO_PAIR_ERRORS,
|
|
2238
|
+
rowMutableTables: rowMutableTables ?? NO_TABLES,
|
|
2239
|
+
plannedTables: plannedTables ?? NO_PLANNED,
|
|
2240
|
+
onAddRow: onAddRow ?? NOOP_ROW,
|
|
2241
|
+
onRemoveRow: onRemoveRow ?? NOOP_ROW
|
|
2242
|
+
};
|
|
1471
2243
|
return (
|
|
1472
2244
|
// A real, labeled <form> (role "form" landmark): AT users can jump
|
|
1473
2245
|
// straight to the editable fields. Submission is owned by the root's
|
|
1474
2246
|
// footer button, never by the form element itself — preventDefault stops
|
|
1475
2247
|
// implicit submission (Enter in a payload with exactly one input would
|
|
1476
2248
|
// otherwise navigate).
|
|
1477
|
-
/* @__PURE__ */
|
|
2249
|
+
/* @__PURE__ */ jsxs3(
|
|
1478
2250
|
"form",
|
|
1479
2251
|
{
|
|
1480
2252
|
className: "gemina-verification__form",
|
|
1481
2253
|
"aria-label": "Extraction fields",
|
|
1482
2254
|
onSubmit: (event) => event.preventDefault(),
|
|
1483
2255
|
children: [
|
|
1484
|
-
/* @__PURE__ */
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
/* @__PURE__ */
|
|
2256
|
+
classified.overallConfidence ? /* @__PURE__ */ jsxs3("div", { className: "gemina-verification__confidence-summary", children: [
|
|
2257
|
+
/* @__PURE__ */ jsx3("span", { children: "Overall confidence" }),
|
|
2258
|
+
/* @__PURE__ */ jsx3(ConfidenceDot, { confidence: classified.overallConfidence })
|
|
2259
|
+
] }) : null,
|
|
2260
|
+
/* @__PURE__ */ jsx3(
|
|
2261
|
+
HeaderSection,
|
|
2262
|
+
{
|
|
2263
|
+
headers: classified.headers.filter((header) => !suppressed.has(header.pointer)),
|
|
2264
|
+
simpleLists: classified.simpleLists,
|
|
2265
|
+
shared
|
|
2266
|
+
}
|
|
2267
|
+
),
|
|
2268
|
+
classified.entities.map((entity) => /* @__PURE__ */ jsx3(EntitySection, { entity, shared }, entity.pointer)),
|
|
2269
|
+
promotedTables.map((table) => /* @__PURE__ */ jsx3(TableSection, { table, shared }, table.pointer)),
|
|
2270
|
+
/* @__PURE__ */ jsx3(FallbackSection, { fallback: classified.fallback }),
|
|
2271
|
+
/* @__PURE__ */ jsx3(UnmatchedSection, { unmatched, shared })
|
|
1489
2272
|
]
|
|
1490
2273
|
}
|
|
1491
2274
|
)
|
|
@@ -1592,9 +2375,15 @@ var VERIFICATION_CSS = `
|
|
|
1592
2375
|
background: var(--gemina-verification-bg);
|
|
1593
2376
|
border: 1px solid var(--gemina-verification-border);
|
|
1594
2377
|
border-radius: var(--gemina-verification-radius);
|
|
1595
|
-
overflow
|
|
2378
|
+
/* overflow hidden creates a scroll container and prevents the toolbar's sticky
|
|
2379
|
+
positioning from following the host modal's scrollport. Clip keeps the
|
|
2380
|
+
rounded frame without stealing sticky containment. */
|
|
2381
|
+
overflow: clip;
|
|
1596
2382
|
}
|
|
1597
2383
|
.gemina-verification__toolbar {
|
|
2384
|
+
position: sticky;
|
|
2385
|
+
top: 0;
|
|
2386
|
+
z-index: 5;
|
|
1598
2387
|
display: flex;
|
|
1599
2388
|
/* Narrow roots (~<330px) can't fit all 7 buttons on one line: wrap to a
|
|
1600
2389
|
second row instead of clipping past the canvas edge. The gap shorthand
|
|
@@ -1604,6 +2393,7 @@ var VERIFICATION_CSS = `
|
|
|
1604
2393
|
gap: 6px;
|
|
1605
2394
|
flex: 0 0 auto;
|
|
1606
2395
|
padding: 8px 10px;
|
|
2396
|
+
background: var(--gemina-verification-bg);
|
|
1607
2397
|
border-block-end: 1px solid var(--gemina-verification-border);
|
|
1608
2398
|
}
|
|
1609
2399
|
.gemina-verification__toolbar-btn {
|
|
@@ -1714,6 +2504,19 @@ var VERIFICATION_CSS = `
|
|
|
1714
2504
|
min-width: 0;
|
|
1715
2505
|
margin: 0;
|
|
1716
2506
|
}
|
|
2507
|
+
.gemina-verification__confidence-summary {
|
|
2508
|
+
display: flex;
|
|
2509
|
+
align-items: center;
|
|
2510
|
+
justify-content: space-between;
|
|
2511
|
+
gap: 12px;
|
|
2512
|
+
padding: 9px 12px;
|
|
2513
|
+
background: var(--gemina-verification-surface);
|
|
2514
|
+
border: 1px solid var(--gemina-verification-border);
|
|
2515
|
+
border-radius: var(--gemina-verification-radius);
|
|
2516
|
+
color: var(--gemina-verification-muted);
|
|
2517
|
+
font-size: 12px;
|
|
2518
|
+
font-weight: 600;
|
|
2519
|
+
}
|
|
1717
2520
|
.gemina-verification__section {
|
|
1718
2521
|
background: var(--gemina-verification-bg);
|
|
1719
2522
|
border: 1px solid var(--gemina-verification-border);
|
|
@@ -1730,6 +2533,16 @@ var VERIFICATION_CSS = `
|
|
|
1730
2533
|
font-size: 13px;
|
|
1731
2534
|
font-weight: 600;
|
|
1732
2535
|
}
|
|
2536
|
+
.gemina-verification__overall-confidence {
|
|
2537
|
+
display: inline-flex;
|
|
2538
|
+
align-items: center;
|
|
2539
|
+
gap: 6px;
|
|
2540
|
+
margin-inline-start: auto;
|
|
2541
|
+
color: var(--gemina-verification-muted);
|
|
2542
|
+
font-size: 11px;
|
|
2543
|
+
font-weight: 500;
|
|
2544
|
+
white-space: nowrap;
|
|
2545
|
+
}
|
|
1733
2546
|
.gemina-verification__dl {
|
|
1734
2547
|
display: grid;
|
|
1735
2548
|
grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
|
|
@@ -1749,6 +2562,10 @@ var VERIFICATION_CSS = `
|
|
|
1749
2562
|
}
|
|
1750
2563
|
.gemina-verification__dd {
|
|
1751
2564
|
display: flex;
|
|
2565
|
+
/* Wrap so a field error takes its OWN line (it sets flex-basis:100%).
|
|
2566
|
+
Without this it competes with the input for width, and at 390px the
|
|
2567
|
+
message wrapped to one word per line while the input shrank to ~55px. */
|
|
2568
|
+
flex-wrap: wrap;
|
|
1752
2569
|
align-items: center;
|
|
1753
2570
|
gap: 6px;
|
|
1754
2571
|
margin: 0; /* resets the UA's margin-inline-start on <dd> */
|
|
@@ -1768,6 +2585,15 @@ var VERIFICATION_CSS = `
|
|
|
1768
2585
|
border-radius: calc(var(--gemina-verification-radius) - 4px);
|
|
1769
2586
|
padding: 5px 8px;
|
|
1770
2587
|
}
|
|
2588
|
+
/* FieldInput is a fragment. Let its control take the remaining row width
|
|
2589
|
+
instead of forcing width:100%, so a coordinate eye can sit beside it rather
|
|
2590
|
+
than wrapping onto a visually disconnected second line. */
|
|
2591
|
+
.gemina-verification__dd > .gemina-verification__input,
|
|
2592
|
+
.gemina-verification__cell > .gemina-verification__input {
|
|
2593
|
+
flex: 1 1 8ch;
|
|
2594
|
+
width: auto;
|
|
2595
|
+
min-width: 0;
|
|
2596
|
+
}
|
|
1771
2597
|
.gemina-verification__input--dirty { border-color: var(--gemina-verification-dirty); }
|
|
1772
2598
|
.gemina-verification__input--missed {
|
|
1773
2599
|
border-color: var(--gemina-verification-error);
|
|
@@ -1823,6 +2649,7 @@ var VERIFICATION_CSS = `
|
|
|
1823
2649
|
and list items \u2014 the fragment has no container of its own. */
|
|
1824
2650
|
.gemina-verification__cell {
|
|
1825
2651
|
display: flex;
|
|
2652
|
+
flex-wrap: wrap; /* same reason as __dd: the field error needs its own line */
|
|
1826
2653
|
align-items: center;
|
|
1827
2654
|
gap: 6px;
|
|
1828
2655
|
min-width: 0;
|
|
@@ -2083,6 +2910,157 @@ var VERIFICATION_CSS = `
|
|
|
2083
2910
|
transition: none;
|
|
2084
2911
|
}
|
|
2085
2912
|
}
|
|
2913
|
+
|
|
2914
|
+
/* A label that carries a description. Dotted underline is the long-standing
|
|
2915
|
+
convention for "there is more here", and tabIndex makes it reachable, so the
|
|
2916
|
+
tooltip is not mouse-only. */
|
|
2917
|
+
.gemina-verification__label-described {
|
|
2918
|
+
text-decoration: underline dotted;
|
|
2919
|
+
text-underline-offset: 3px;
|
|
2920
|
+
cursor: help;
|
|
2921
|
+
}
|
|
2922
|
+
.gemina-verification__label-described:focus-visible {
|
|
2923
|
+
outline: 2px solid var(--gemina-verification-accent);
|
|
2924
|
+
outline-offset: 2px;
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
/* Rows worth a second look. Uses the EXISTING confidence tokens \u2014 no new
|
|
2928
|
+
colours \u2014 as a start-edge rule, which is the one edge a reviewer scans down
|
|
2929
|
+
a long table. Logical property, so it lands on the right side under RTL. */
|
|
2930
|
+
.gemina-verification__row--low > td:first-child,
|
|
2931
|
+
.gemina-verification__row--medium > td:first-child {
|
|
2932
|
+
border-inline-start: 3px solid transparent;
|
|
2933
|
+
}
|
|
2934
|
+
.gemina-verification__row--low > td:first-child {
|
|
2935
|
+
border-inline-start-color: var(--gemina-verification-confidence-low);
|
|
2936
|
+
}
|
|
2937
|
+
.gemina-verification__row--medium > td:first-child {
|
|
2938
|
+
border-inline-start-color: var(--gemina-verification-confidence-medium);
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
/* --- Row editing ----------------------------------------------------------
|
|
2942
|
+
Quiet by design: adding and removing lines is a correction, not the primary
|
|
2943
|
+
action, so the controls stay muted until hovered and the accent is left to
|
|
2944
|
+
Submit. */
|
|
2945
|
+
.gemina-verification__row-actions {
|
|
2946
|
+
white-space: nowrap;
|
|
2947
|
+
text-align: end; /* logical \u2014 RTL for free */
|
|
2948
|
+
}
|
|
2949
|
+
.gemina-verification__row-btn {
|
|
2950
|
+
font: inherit;
|
|
2951
|
+
line-height: 1;
|
|
2952
|
+
padding: 2px 7px;
|
|
2953
|
+
margin-inline-start: 4px;
|
|
2954
|
+
border-radius: calc(var(--gemina-verification-radius) - 5px);
|
|
2955
|
+
border: 1px solid var(--gemina-verification-border);
|
|
2956
|
+
background: transparent;
|
|
2957
|
+
color: var(--gemina-verification-muted);
|
|
2958
|
+
cursor: pointer;
|
|
2959
|
+
transition: border-color 120ms ease, color 120ms ease;
|
|
2960
|
+
}
|
|
2961
|
+
.gemina-verification__row-btn:hover {
|
|
2962
|
+
border-color: var(--gemina-verification-accent);
|
|
2963
|
+
color: var(--gemina-verification-fg);
|
|
2964
|
+
}
|
|
2965
|
+
.gemina-verification__table-footer {
|
|
2966
|
+
display: flex;
|
|
2967
|
+
padding: 8px 10px;
|
|
2968
|
+
}
|
|
2969
|
+
.gemina-verification__add-row {
|
|
2970
|
+
font: inherit;
|
|
2971
|
+
font-size: 12px;
|
|
2972
|
+
padding: 4px 10px;
|
|
2973
|
+
border-radius: calc(var(--gemina-verification-radius) - 4px);
|
|
2974
|
+
border: 1px dashed var(--gemina-verification-border);
|
|
2975
|
+
background: transparent;
|
|
2976
|
+
color: var(--gemina-verification-muted);
|
|
2977
|
+
cursor: pointer;
|
|
2978
|
+
}
|
|
2979
|
+
.gemina-verification__add-row:hover {
|
|
2980
|
+
border-style: solid;
|
|
2981
|
+
border-color: var(--gemina-verification-accent);
|
|
2982
|
+
color: var(--gemina-verification-fg);
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/* --- Typed controls -------------------------------------------------------
|
|
2986
|
+
A <select> for a closed roster must sit on the same baseline as the text
|
|
2987
|
+
inputs beside it in a table row, so it inherits the input's box entirely and
|
|
2988
|
+
only overrides what a select needs. */
|
|
2989
|
+
.gemina-verification__input:is(select) {
|
|
2990
|
+
cursor: pointer;
|
|
2991
|
+
/* A select's intrinsic width follows its longest option \u2014 the 24-member unit
|
|
2992
|
+
roster would blow out the column. */
|
|
2993
|
+
max-width: 100%;
|
|
2994
|
+
}
|
|
2995
|
+
/* The error border must beat --dirty and --missed: an invalid value is the
|
|
2996
|
+
most urgent thing true about the field, and the reviewer cannot submit
|
|
2997
|
+
until it is fixed. Placed after both for cascade order. */
|
|
2998
|
+
.gemina-verification__input--invalid,
|
|
2999
|
+
.gemina-verification__input--invalid:focus-visible {
|
|
3000
|
+
border-color: var(--gemina-verification-error);
|
|
3001
|
+
}
|
|
3002
|
+
/* Sits under the control it describes. Basis 100% breaks it onto its own line
|
|
3003
|
+
inside the flex row FieldInput renders into, so it never squeezes the
|
|
3004
|
+
input. */
|
|
3005
|
+
.gemina-verification__field-error {
|
|
3006
|
+
flex-basis: 100%;
|
|
3007
|
+
margin-block-start: 4px;
|
|
3008
|
+
color: var(--gemina-verification-error);
|
|
3009
|
+
font-size: 12px;
|
|
3010
|
+
line-height: 1.35;
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
/* Replaces __progress while anything is invalid \u2014 same slot, so the footer
|
|
3014
|
+
never grows a second status line competing for the same attention. */
|
|
3015
|
+
.gemina-verification__attention {
|
|
3016
|
+
color: var(--gemina-verification-error);
|
|
3017
|
+
font-size: 13px;
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
/* --- Tooltip -------------------------------------------------------------
|
|
3021
|
+
Renders in a portal on document.body, inside a div carrying the root's
|
|
3022
|
+
class list \u2014 so these rules and every --gemina-verification-* custom
|
|
3023
|
+
property resolve exactly as they do in the component.
|
|
3024
|
+
|
|
3025
|
+
Quieter than __confirm-dialog on purpose: an annotation, not a decision.
|
|
3026
|
+
Same border and shadow family, one step down in radius (the nested-element
|
|
3027
|
+
convention used by __chip et al), surface rather than bg so it separates
|
|
3028
|
+
from the panel it floats over, and a shorter shadow so it reads as sitting
|
|
3029
|
+
just above the page rather than over a scrim. */
|
|
3030
|
+
.gemina-verification__tip {
|
|
3031
|
+
position: fixed;
|
|
3032
|
+
z-index: 2147483000; /* above the host's own modal \u2014 this is the topmost layer */
|
|
3033
|
+
max-width: 260px; /* ~60 characters: past that a tooltip should be body copy */
|
|
3034
|
+
padding: 8px 10px;
|
|
3035
|
+
background: var(--gemina-verification-surface);
|
|
3036
|
+
color: var(--gemina-verification-fg);
|
|
3037
|
+
border: 1px solid var(--gemina-verification-border);
|
|
3038
|
+
border-radius: calc(var(--gemina-verification-radius) - 4px);
|
|
3039
|
+
box-shadow: 0 6px 16px rgba(16, 20, 24, 0.18);
|
|
3040
|
+
font-family: var(--gemina-verification-font);
|
|
3041
|
+
font-size: 12px;
|
|
3042
|
+
line-height: 1.45;
|
|
3043
|
+
text-align: start; /* logical \u2014 RTL for free */
|
|
3044
|
+
pointer-events: none; /* never eat the hover that opened it */
|
|
3045
|
+
}
|
|
3046
|
+
/* Structured content: a level heading over a reasons list. The list is the
|
|
3047
|
+
reason this exists at all \u2014 title= could only ever have been one line. */
|
|
3048
|
+
.gemina-verification__tip-title {
|
|
3049
|
+
display: block;
|
|
3050
|
+
font-weight: 600;
|
|
3051
|
+
margin-block-end: 4px;
|
|
3052
|
+
}
|
|
3053
|
+
.gemina-verification__tip-list {
|
|
3054
|
+
margin: 0;
|
|
3055
|
+
padding-inline-start: 16px;
|
|
3056
|
+
}
|
|
3057
|
+
.gemina-verification__tip-list li + li {
|
|
3058
|
+
margin-block-start: 2px;
|
|
3059
|
+
}
|
|
3060
|
+
/* A muted lead-in for single-fact tips ("Was:"), so the VALUE reads first. */
|
|
3061
|
+
.gemina-verification__tip-label {
|
|
3062
|
+
color: var(--gemina-verification-muted);
|
|
3063
|
+
}
|
|
2086
3064
|
`;
|
|
2087
3065
|
var STYLE_ATTR = "data-gemina-verification";
|
|
2088
3066
|
function ensureVerificationStylesInjected() {
|
|
@@ -2099,7 +3077,7 @@ function ensureVerificationStylesInjected() {
|
|
|
2099
3077
|
}
|
|
2100
3078
|
|
|
2101
3079
|
// src/verification/index.tsx
|
|
2102
|
-
import { Fragment as
|
|
3080
|
+
import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2103
3081
|
var HEBREW_RE = /[\u0590-\u05FF]/;
|
|
2104
3082
|
var STACKED_BREAKPOINT = 860;
|
|
2105
3083
|
var IMAGE_REFRESH_THROTTLE_MS = 6e4;
|
|
@@ -2112,11 +3090,23 @@ var PURGED_TEXT = "Document no longer available (retention policy).";
|
|
|
2112
3090
|
var NOT_COMPLETED_TEXT = "This extraction did not complete, so there is nothing to verify.";
|
|
2113
3091
|
var VERIFICATION_UNAVAILABLE_TEXT = "Verification isn't available for this extraction.";
|
|
2114
3092
|
var ALREADY_VALIDATED_TEXT = "Already verified \u2014 showing the original extraction.";
|
|
2115
|
-
var CONFIRM_TEXT = "Submit
|
|
3093
|
+
var CONFIRM_TEXT = "Submit these values? This is final \u2014 they can be submitted once and can't be changed.";
|
|
2116
3094
|
var SUBMITTING_TEXT = "Submitting\u2026";
|
|
2117
3095
|
var SUBMIT_FAILED_TEXT = "Submission failed \u2014 your corrections are still here.";
|
|
2118
|
-
var DONE_TITLE_TEXT = "
|
|
3096
|
+
var DONE_TITLE_TEXT = "Submitted";
|
|
2119
3097
|
var NO_EDITS = /* @__PURE__ */ new Map();
|
|
3098
|
+
var NO_ROW_PLANS = /* @__PURE__ */ new Map();
|
|
3099
|
+
var NO_PLANNED_TABLES = /* @__PURE__ */ new Map();
|
|
3100
|
+
function seedRowPlans(tables, values) {
|
|
3101
|
+
if (tables.length === 0) {
|
|
3102
|
+
return NO_ROW_PLANS;
|
|
3103
|
+
}
|
|
3104
|
+
const plans = /* @__PURE__ */ new Map();
|
|
3105
|
+
for (const table of tables) {
|
|
3106
|
+
plans.set(table.pointer, initialRowPlan(countRowsAt(values, table.pointer), table.pointer));
|
|
3107
|
+
}
|
|
3108
|
+
return plans;
|
|
3109
|
+
}
|
|
2120
3110
|
var ALERT_REASONS = /* @__PURE__ */ new Set([
|
|
2121
3111
|
"session-expired",
|
|
2122
3112
|
"not-available",
|
|
@@ -2133,43 +3123,44 @@ function GeminaVerification(props) {
|
|
|
2133
3123
|
onError,
|
|
2134
3124
|
className
|
|
2135
3125
|
} = props;
|
|
2136
|
-
const [phase, setPhase] =
|
|
2137
|
-
const [alreadyValidated, setAlreadyValidated] =
|
|
2138
|
-
const [loaded, setLoaded] =
|
|
2139
|
-
const [
|
|
2140
|
-
const [
|
|
2141
|
-
const [
|
|
2142
|
-
const [
|
|
2143
|
-
const
|
|
2144
|
-
const
|
|
2145
|
-
const
|
|
2146
|
-
const
|
|
2147
|
-
const
|
|
3126
|
+
const [phase, setPhase] = useState3({ name: "loading" });
|
|
3127
|
+
const [alreadyValidated, setAlreadyValidated] = useState3(false);
|
|
3128
|
+
const [loaded, setLoaded] = useState3(null);
|
|
3129
|
+
const [rowPlans, setRowPlans] = useState3(NO_ROW_PLANS);
|
|
3130
|
+
const [edits, setEdits] = useState3(NO_EDITS);
|
|
3131
|
+
const [imageUrl, setImageUrl] = useState3(null);
|
|
3132
|
+
const [flashRects, setFlashRects] = useState3(null);
|
|
3133
|
+
const [stacked, setStacked] = useState3(false);
|
|
3134
|
+
const rootRef = useRef3(null);
|
|
3135
|
+
const mountedRef = useRef3(false);
|
|
3136
|
+
const loadSeqRef = useRef3(0);
|
|
3137
|
+
const lastImageRefreshRef = useRef3(0);
|
|
3138
|
+
const onErrorRef = useRef3(onError);
|
|
2148
3139
|
onErrorRef.current = onError;
|
|
2149
|
-
const onCompleteRef =
|
|
3140
|
+
const onCompleteRef = useRef3(onComplete);
|
|
2150
3141
|
onCompleteRef.current = onComplete;
|
|
2151
|
-
const completedRef =
|
|
2152
|
-
const submitInFlightRef =
|
|
2153
|
-
const restoreFocusRef =
|
|
2154
|
-
const submitButtonRef =
|
|
2155
|
-
const confirmButtonRef =
|
|
2156
|
-
const cancelButtonRef =
|
|
2157
|
-
const retrySubmitButtonRef =
|
|
2158
|
-
const doneStateRef =
|
|
2159
|
-
const enterUnavailable =
|
|
3142
|
+
const completedRef = useRef3(false);
|
|
3143
|
+
const submitInFlightRef = useRef3(false);
|
|
3144
|
+
const restoreFocusRef = useRef3(false);
|
|
3145
|
+
const submitButtonRef = useRef3(null);
|
|
3146
|
+
const confirmButtonRef = useRef3(null);
|
|
3147
|
+
const cancelButtonRef = useRef3(null);
|
|
3148
|
+
const retrySubmitButtonRef = useRef3(null);
|
|
3149
|
+
const doneStateRef = useRef3(null);
|
|
3150
|
+
const enterUnavailable = useCallback3(
|
|
2160
3151
|
(reason, message, canRetry, detail) => {
|
|
2161
3152
|
setPhase({ name: "unavailable", reason, message, canRetry });
|
|
2162
3153
|
onErrorRef.current?.(reason, detail);
|
|
2163
3154
|
},
|
|
2164
3155
|
[]
|
|
2165
3156
|
);
|
|
2166
|
-
const fetchOnce =
|
|
3157
|
+
const fetchOnce = useCallback3(async () => {
|
|
2167
3158
|
const token = await tokenManager.getToken();
|
|
2168
3159
|
return GeminaClient.withSessionToken(token, baseUrl).documents.getDocumentExtraction({
|
|
2169
3160
|
documentExtractionId: extractionId
|
|
2170
3161
|
});
|
|
2171
3162
|
}, [tokenManager, baseUrl, extractionId]);
|
|
2172
|
-
const fetchWithRetry =
|
|
3163
|
+
const fetchWithRetry = useCallback3(async () => {
|
|
2173
3164
|
try {
|
|
2174
3165
|
return await fetchOnce();
|
|
2175
3166
|
} catch (error) {
|
|
@@ -2180,7 +3171,7 @@ function GeminaVerification(props) {
|
|
|
2180
3171
|
return await fetchOnce();
|
|
2181
3172
|
}
|
|
2182
3173
|
}, [fetchOnce, tokenManager]);
|
|
2183
|
-
const load =
|
|
3174
|
+
const load = useCallback3(async () => {
|
|
2184
3175
|
const seq = ++loadSeqRef.current;
|
|
2185
3176
|
const live = () => mountedRef.current && loadSeqRef.current === seq;
|
|
2186
3177
|
setPhase({ name: "loading" });
|
|
@@ -2211,9 +3202,12 @@ function GeminaVerification(props) {
|
|
|
2211
3202
|
const schema = view.meta.validationFeedback?.validationSchema;
|
|
2212
3203
|
setLoaded({
|
|
2213
3204
|
values: view.values,
|
|
2214
|
-
schema: Array.isArray(schema) ? schema : []
|
|
3205
|
+
schema: Array.isArray(schema) ? schema : [],
|
|
3206
|
+
fields: readDescriptors(view.meta.validationFeedback?.validationFields),
|
|
3207
|
+
rowMutableTables: readRowMutableTables(view.meta.validationFeedback?.rowMutableTables)
|
|
2215
3208
|
});
|
|
2216
3209
|
setEdits(NO_EDITS);
|
|
3210
|
+
setRowPlans(seedRowPlans(readRowMutableTables(view.meta.validationFeedback?.rowMutableTables), view.values));
|
|
2217
3211
|
const url = view.document.imageUrl;
|
|
2218
3212
|
setImageUrl(typeof url === "string" && url.length > 0 ? url : null);
|
|
2219
3213
|
setAlreadyValidated(validated);
|
|
@@ -2231,7 +3225,7 @@ function GeminaVerification(props) {
|
|
|
2231
3225
|
enterReview(false);
|
|
2232
3226
|
}
|
|
2233
3227
|
}, [fetchWithRetry, enterUnavailable]);
|
|
2234
|
-
|
|
3228
|
+
useEffect3(() => {
|
|
2235
3229
|
mountedRef.current = true;
|
|
2236
3230
|
ensureVerificationStylesInjected();
|
|
2237
3231
|
void load();
|
|
@@ -2239,7 +3233,7 @@ function GeminaVerification(props) {
|
|
|
2239
3233
|
mountedRef.current = false;
|
|
2240
3234
|
};
|
|
2241
3235
|
}, [load]);
|
|
2242
|
-
|
|
3236
|
+
useEffect3(() => {
|
|
2243
3237
|
const el = rootRef.current;
|
|
2244
3238
|
if (el === null) {
|
|
2245
3239
|
return;
|
|
@@ -2261,8 +3255,18 @@ function GeminaVerification(props) {
|
|
|
2261
3255
|
return () => observer.disconnect();
|
|
2262
3256
|
}, []);
|
|
2263
3257
|
const classified = useMemo(() => classifyData(loaded?.values), [loaded]);
|
|
2264
|
-
const bindings = useMemo(
|
|
3258
|
+
const bindings = useMemo(
|
|
3259
|
+
() => buildBindings(loaded?.schema ?? [], loaded?.values, loaded?.fields),
|
|
3260
|
+
[loaded]
|
|
3261
|
+
);
|
|
2265
3262
|
const bindingIndex = useMemo(() => indexBindingsByFieldPointer(bindings), [bindings]);
|
|
3263
|
+
const bindingsByRawKey = useMemo(() => {
|
|
3264
|
+
const map = /* @__PURE__ */ new Map();
|
|
3265
|
+
for (const binding of bindings) {
|
|
3266
|
+
map.set(binding.key.raw, binding);
|
|
3267
|
+
}
|
|
3268
|
+
return map;
|
|
3269
|
+
}, [bindings]);
|
|
2266
3270
|
const unmatched = useMemo(() => {
|
|
2267
3271
|
const rendered = /* @__PURE__ */ new Set();
|
|
2268
3272
|
for (const field of classified.headers) {
|
|
@@ -2330,43 +3334,82 @@ function GeminaVerification(props) {
|
|
|
2330
3334
|
[bindings]
|
|
2331
3335
|
);
|
|
2332
3336
|
const effectiveDir = dir === "auto" ? hasHebrewContent ? "rtl" : "ltr" : dir;
|
|
2333
|
-
const
|
|
2334
|
-
const
|
|
2335
|
-
for (const binding of bindings) {
|
|
2336
|
-
map.set(binding.key.raw, binding);
|
|
2337
|
-
}
|
|
2338
|
-
return map;
|
|
2339
|
-
}, [bindings]);
|
|
2340
|
-
const bindingsByRawKeyRef = useRef2(bindingsByRawKey);
|
|
2341
|
-
bindingsByRawKeyRef.current = bindingsByRawKey;
|
|
2342
|
-
const handleEdit = useCallback2((rawKey, value) => {
|
|
2343
|
-
const binding = bindingsByRawKeyRef.current.get(rawKey);
|
|
2344
|
-
const pristine = binding !== void 0 && value === toInputString(binding.extracted);
|
|
3337
|
+
const handleEdit = useCallback3((editKey, value, binding) => {
|
|
3338
|
+
const pristine = value === toInputString(binding.extracted);
|
|
2345
3339
|
setEdits((prev) => {
|
|
2346
3340
|
if (pristine) {
|
|
2347
|
-
if (!prev.has(
|
|
3341
|
+
if (!prev.has(editKey)) {
|
|
2348
3342
|
return prev;
|
|
2349
3343
|
}
|
|
2350
3344
|
const next2 = new Map(prev);
|
|
2351
|
-
next2.delete(
|
|
3345
|
+
next2.delete(editKey);
|
|
2352
3346
|
return next2;
|
|
2353
3347
|
}
|
|
2354
|
-
if (prev.get(
|
|
3348
|
+
if (prev.get(editKey) === value) {
|
|
2355
3349
|
return prev;
|
|
2356
3350
|
}
|
|
2357
3351
|
const next = new Map(prev);
|
|
2358
|
-
next.set(
|
|
3352
|
+
next.set(editKey, value);
|
|
2359
3353
|
return next;
|
|
2360
3354
|
});
|
|
2361
3355
|
}, []);
|
|
2362
|
-
const
|
|
2363
|
-
|
|
3356
|
+
const plannedTables = useMemo(() => {
|
|
3357
|
+
const tables = loaded?.rowMutableTables ?? [];
|
|
3358
|
+
if (tables.length === 0) {
|
|
3359
|
+
return NO_PLANNED_TABLES;
|
|
3360
|
+
}
|
|
3361
|
+
const out = /* @__PURE__ */ new Map();
|
|
3362
|
+
for (const table of tables) {
|
|
3363
|
+
const plan = rowPlans.get(table.pointer);
|
|
3364
|
+
if (plan === void 0) {
|
|
3365
|
+
continue;
|
|
3366
|
+
}
|
|
3367
|
+
const classifiedTable = classified.tables.find(
|
|
3368
|
+
(candidate) => matchesTablePointer(table.pointer, candidate.pointer)
|
|
3369
|
+
);
|
|
3370
|
+
const columns = displayColumns(table, classifiedTable?.columns ?? []);
|
|
3371
|
+
out.set(table.pointer, planTableCells(table, plan, columns, bindingsByRawKey));
|
|
3372
|
+
}
|
|
3373
|
+
return out;
|
|
3374
|
+
}, [loaded, rowPlans, classified, bindingsByRawKey]);
|
|
3375
|
+
const cellViews = useMemo(
|
|
3376
|
+
() => collectCellViews(bindings, plannedTables),
|
|
3377
|
+
[bindings, plannedTables]
|
|
3378
|
+
);
|
|
3379
|
+
const submissionTables = useMemo(
|
|
3380
|
+
() => pruneEmptyAddedRows(plannedTables, edits),
|
|
3381
|
+
[plannedTables, edits]
|
|
3382
|
+
);
|
|
3383
|
+
const submissionCells = useMemo(
|
|
3384
|
+
() => collectCellViews(bindings, submissionTables),
|
|
3385
|
+
[bindings, submissionTables]
|
|
3386
|
+
);
|
|
3387
|
+
const rowSources = useMemo(() => {
|
|
3388
|
+
const entries = [];
|
|
3389
|
+
for (const table of loaded?.rowMutableTables ?? []) {
|
|
3390
|
+
const rows = submissionTables.get(table.pointer);
|
|
3391
|
+
if (rows === void 0) {
|
|
3392
|
+
continue;
|
|
3393
|
+
}
|
|
3394
|
+
const plan = rows.map((row) => row.entry);
|
|
3395
|
+
if (isIdentityPlan(plan, countRowsAt(loaded?.values, table.pointer))) {
|
|
3396
|
+
continue;
|
|
3397
|
+
}
|
|
3398
|
+
entries.push({ table: table.pointer, sources: rowSourcesOf(plan) });
|
|
3399
|
+
}
|
|
3400
|
+
return entries;
|
|
3401
|
+
}, [loaded, submissionTables]);
|
|
3402
|
+
const submission = useMemo(
|
|
3403
|
+
() => composeSubmission(bindings, edits, { cells: submissionCells, rowSources }),
|
|
3404
|
+
[bindings, edits, submissionCells, rowSources]
|
|
3405
|
+
);
|
|
3406
|
+
const handleFlash = useCallback3((rects) => {
|
|
2364
3407
|
setFlashRects(rects.map((rect) => ({ points: rect.points })));
|
|
2365
3408
|
}, []);
|
|
2366
|
-
const handleFlashComplete =
|
|
3409
|
+
const handleFlashComplete = useCallback3(() => {
|
|
2367
3410
|
setFlashRects(null);
|
|
2368
3411
|
}, []);
|
|
2369
|
-
const handleImageExpired =
|
|
3412
|
+
const handleImageExpired = useCallback3(() => {
|
|
2370
3413
|
const now = Date.now();
|
|
2371
3414
|
if (now - lastImageRefreshRef.current < IMAGE_REFRESH_THROTTLE_MS) {
|
|
2372
3415
|
return;
|
|
@@ -2384,10 +3427,52 @@ function GeminaVerification(props) {
|
|
|
2384
3427
|
}).catch(() => {
|
|
2385
3428
|
});
|
|
2386
3429
|
}, [fetchWithRetry]);
|
|
2387
|
-
const handleRetry =
|
|
3430
|
+
const handleRetry = useCallback3(() => {
|
|
2388
3431
|
void load();
|
|
2389
3432
|
}, [load]);
|
|
2390
|
-
const
|
|
3433
|
+
const handleAddRow = useCallback3((tablePointer, afterPosition) => {
|
|
3434
|
+
const id = nextAddedRowId(tablePointer);
|
|
3435
|
+
setRowPlans((prev) => {
|
|
3436
|
+
const plan = prev.get(tablePointer);
|
|
3437
|
+
if (plan === void 0) {
|
|
3438
|
+
return prev;
|
|
3439
|
+
}
|
|
3440
|
+
const next = new Map(prev);
|
|
3441
|
+
next.set(tablePointer, insertRowAfter(plan, afterPosition, id));
|
|
3442
|
+
return next;
|
|
3443
|
+
});
|
|
3444
|
+
}, []);
|
|
3445
|
+
const handleRemoveRow = useCallback3((tablePointer, position) => {
|
|
3446
|
+
setRowPlans((prev) => {
|
|
3447
|
+
const plan = prev.get(tablePointer);
|
|
3448
|
+
if (plan === void 0) {
|
|
3449
|
+
return prev;
|
|
3450
|
+
}
|
|
3451
|
+
const nextPlan = removeRow(plan, position);
|
|
3452
|
+
if (nextPlan === plan) {
|
|
3453
|
+
return prev;
|
|
3454
|
+
}
|
|
3455
|
+
const next = new Map(prev);
|
|
3456
|
+
next.set(tablePointer, nextPlan);
|
|
3457
|
+
return next;
|
|
3458
|
+
});
|
|
3459
|
+
}, []);
|
|
3460
|
+
const pairErrors = useMemo(() => unitSizePairErrors(cellViews, edits), [cellViews, edits]);
|
|
3461
|
+
const invalidCount = useMemo(() => {
|
|
3462
|
+
const rowLevel = pairErrors.size;
|
|
3463
|
+
if (edits.size === 0) {
|
|
3464
|
+
return rowLevel;
|
|
3465
|
+
}
|
|
3466
|
+
const byEditKey = new Map(cellViews.map((view) => [view.editKey, view.binding]));
|
|
3467
|
+
let count = 0;
|
|
3468
|
+
for (const [editKey, value] of edits) {
|
|
3469
|
+
if (!pairErrors.has(editKey) && validateInput(value, byEditKey.get(editKey)?.field) !== null) {
|
|
3470
|
+
count += 1;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
return count + rowLevel;
|
|
3474
|
+
}, [edits, cellViews, pairErrors]);
|
|
3475
|
+
const doSubmit = useCallback3(async () => {
|
|
2391
3476
|
if (submitInFlightRef.current) {
|
|
2392
3477
|
return;
|
|
2393
3478
|
}
|
|
@@ -2400,7 +3485,13 @@ function GeminaVerification(props) {
|
|
|
2400
3485
|
const token = await tokenManager.getToken();
|
|
2401
3486
|
return GeminaClient.withSessionToken(token, baseUrl).documents.validateDocumentExtraction({
|
|
2402
3487
|
targetDocumentExtractionId: extractionId,
|
|
2403
|
-
|
|
3488
|
+
// Conditional spread, matching the house pattern: without a row edit
|
|
3489
|
+
// the request body is byte-identical to what it was before this
|
|
3490
|
+
// feature, so nothing changes for the overwhelmingly common path.
|
|
3491
|
+
extractionValidationInDTO: {
|
|
3492
|
+
data: body.data,
|
|
3493
|
+
...body.rowSources.length > 0 ? { rowSources: body.rowSources } : {}
|
|
3494
|
+
}
|
|
2404
3495
|
});
|
|
2405
3496
|
};
|
|
2406
3497
|
try {
|
|
@@ -2448,20 +3539,20 @@ function GeminaVerification(props) {
|
|
|
2448
3539
|
submitInFlightRef.current = false;
|
|
2449
3540
|
}
|
|
2450
3541
|
}, [submission, tokenManager, baseUrl, extractionId, load]);
|
|
2451
|
-
const handleSubmitClick =
|
|
3542
|
+
const handleSubmitClick = useCallback3(() => {
|
|
2452
3543
|
setPhase({ name: "confirming" });
|
|
2453
3544
|
}, []);
|
|
2454
|
-
const handleConfirm =
|
|
3545
|
+
const handleConfirm = useCallback3(() => {
|
|
2455
3546
|
void doSubmit();
|
|
2456
3547
|
}, [doSubmit]);
|
|
2457
|
-
const handleCancelConfirm =
|
|
3548
|
+
const handleCancelConfirm = useCallback3(() => {
|
|
2458
3549
|
restoreFocusRef.current = true;
|
|
2459
3550
|
setPhase({ name: "review" });
|
|
2460
3551
|
}, []);
|
|
2461
|
-
const handleRetrySubmit =
|
|
3552
|
+
const handleRetrySubmit = useCallback3(() => {
|
|
2462
3553
|
void doSubmit();
|
|
2463
3554
|
}, [doSubmit]);
|
|
2464
|
-
const handleConfirmKeyDown =
|
|
3555
|
+
const handleConfirmKeyDown = useCallback3(
|
|
2465
3556
|
(event) => {
|
|
2466
3557
|
if (phase.name !== "confirming") {
|
|
2467
3558
|
return;
|
|
@@ -2492,7 +3583,7 @@ function GeminaVerification(props) {
|
|
|
2492
3583
|
},
|
|
2493
3584
|
[phase.name, handleCancelConfirm]
|
|
2494
3585
|
);
|
|
2495
|
-
|
|
3586
|
+
useEffect3(() => {
|
|
2496
3587
|
if (phase.name === "confirming") {
|
|
2497
3588
|
confirmButtonRef.current?.focus();
|
|
2498
3589
|
} else if (phase.name === "review" && restoreFocusRef.current) {
|
|
@@ -2511,13 +3602,13 @@ function GeminaVerification(props) {
|
|
|
2511
3602
|
stacked ? "gemina-verification--stacked" : "",
|
|
2512
3603
|
className ?? ""
|
|
2513
3604
|
].filter((part) => part.length > 0).join(" ");
|
|
2514
|
-
const dialogTextId =
|
|
3605
|
+
const dialogTextId = useId2();
|
|
2515
3606
|
const renderReview = (reviewPhase) => {
|
|
2516
3607
|
const overlayUp = reviewPhase.name === "confirming" || reviewPhase.name === "submitting";
|
|
2517
|
-
return /* @__PURE__ */
|
|
2518
|
-
alreadyValidated && /* @__PURE__ */
|
|
2519
|
-
/* @__PURE__ */
|
|
2520
|
-
imageUrl !== null && /* @__PURE__ */
|
|
3608
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3609
|
+
alreadyValidated && /* @__PURE__ */ jsx4("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
|
|
3610
|
+
/* @__PURE__ */ jsxs4("div", { className: "gemina-verification__panes", children: [
|
|
3611
|
+
imageUrl !== null && /* @__PURE__ */ jsx4(
|
|
2521
3612
|
VerificationViewer,
|
|
2522
3613
|
{
|
|
2523
3614
|
src: imageUrl,
|
|
@@ -2527,7 +3618,7 @@ function GeminaVerification(props) {
|
|
|
2527
3618
|
onImageExpired: handleImageExpired
|
|
2528
3619
|
}
|
|
2529
3620
|
),
|
|
2530
|
-
/* @__PURE__ */
|
|
3621
|
+
/* @__PURE__ */ jsx4(
|
|
2531
3622
|
VerificationForm,
|
|
2532
3623
|
{
|
|
2533
3624
|
classified,
|
|
@@ -2536,18 +3627,23 @@ function GeminaVerification(props) {
|
|
|
2536
3627
|
edits,
|
|
2537
3628
|
onEdit: handleEdit,
|
|
2538
3629
|
readOnly: alreadyValidated,
|
|
2539
|
-
onFlash: handleFlash
|
|
3630
|
+
onFlash: handleFlash,
|
|
3631
|
+
pairErrors,
|
|
3632
|
+
rowMutableTables: loaded?.rowMutableTables,
|
|
3633
|
+
plannedTables,
|
|
3634
|
+
onAddRow: handleAddRow,
|
|
3635
|
+
onRemoveRow: handleRemoveRow
|
|
2540
3636
|
}
|
|
2541
3637
|
)
|
|
2542
3638
|
] }),
|
|
2543
|
-
reviewPhase.name === "submit-error" && /* @__PURE__ */
|
|
3639
|
+
reviewPhase.name === "submit-error" && /* @__PURE__ */ jsxs4(
|
|
2544
3640
|
"div",
|
|
2545
3641
|
{
|
|
2546
3642
|
className: "gemina-verification__banner gemina-verification__banner--error gemina-verification__submit-error",
|
|
2547
3643
|
role: "alert",
|
|
2548
3644
|
children: [
|
|
2549
|
-
/* @__PURE__ */
|
|
2550
|
-
/* @__PURE__ */
|
|
3645
|
+
/* @__PURE__ */ jsx4("span", { children: reviewPhase.message }),
|
|
3646
|
+
/* @__PURE__ */ jsx4(
|
|
2551
3647
|
"button",
|
|
2552
3648
|
{
|
|
2553
3649
|
type: "button",
|
|
@@ -2560,21 +3656,21 @@ function GeminaVerification(props) {
|
|
|
2560
3656
|
]
|
|
2561
3657
|
}
|
|
2562
3658
|
),
|
|
2563
|
-
/* @__PURE__ */
|
|
2564
|
-
!alreadyValidated && /* @__PURE__ */
|
|
2565
|
-
/* @__PURE__ */
|
|
3659
|
+
/* @__PURE__ */ jsxs4("div", { className: "gemina-verification__footer", children: [
|
|
3660
|
+
!alreadyValidated && (invalidCount > 0 ? /* @__PURE__ */ jsx4("div", { className: "gemina-verification__attention", "aria-live": "polite", children: invalidCount === 1 ? "1 field needs attention" : `${invalidCount} fields need attention` }) : /* @__PURE__ */ jsx4("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` })),
|
|
3661
|
+
/* @__PURE__ */ jsx4(
|
|
2566
3662
|
"button",
|
|
2567
3663
|
{
|
|
2568
3664
|
type: "button",
|
|
2569
3665
|
ref: submitButtonRef,
|
|
2570
3666
|
className: "gemina-verification__submit",
|
|
2571
|
-
disabled: alreadyValidated || reviewPhase.name !== "review",
|
|
3667
|
+
disabled: alreadyValidated || reviewPhase.name !== "review" || invalidCount > 0,
|
|
2572
3668
|
onClick: handleSubmitClick,
|
|
2573
|
-
children: "Submit
|
|
3669
|
+
children: "Submit"
|
|
2574
3670
|
}
|
|
2575
3671
|
)
|
|
2576
3672
|
] }),
|
|
2577
|
-
overlayUp && /* @__PURE__ */
|
|
3673
|
+
overlayUp && /* @__PURE__ */ jsx4(
|
|
2578
3674
|
"div",
|
|
2579
3675
|
{
|
|
2580
3676
|
className: "gemina-verification__confirm",
|
|
@@ -2584,7 +3680,7 @@ function GeminaVerification(props) {
|
|
|
2584
3680
|
event.preventDefault();
|
|
2585
3681
|
}
|
|
2586
3682
|
},
|
|
2587
|
-
children: /* @__PURE__ */
|
|
3683
|
+
children: /* @__PURE__ */ jsxs4(
|
|
2588
3684
|
"div",
|
|
2589
3685
|
{
|
|
2590
3686
|
className: "gemina-verification__confirm-dialog",
|
|
@@ -2592,9 +3688,9 @@ function GeminaVerification(props) {
|
|
|
2592
3688
|
"aria-modal": "true",
|
|
2593
3689
|
"aria-labelledby": dialogTextId,
|
|
2594
3690
|
children: [
|
|
2595
|
-
/* @__PURE__ */
|
|
2596
|
-
/* @__PURE__ */
|
|
2597
|
-
/* @__PURE__ */
|
|
3691
|
+
/* @__PURE__ */ jsx4("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
|
|
3692
|
+
/* @__PURE__ */ jsxs4("div", { className: "gemina-verification__confirm-actions", children: [
|
|
3693
|
+
/* @__PURE__ */ jsx4(
|
|
2598
3694
|
"button",
|
|
2599
3695
|
{
|
|
2600
3696
|
type: "button",
|
|
@@ -2605,7 +3701,7 @@ function GeminaVerification(props) {
|
|
|
2605
3701
|
children: "Cancel"
|
|
2606
3702
|
}
|
|
2607
3703
|
),
|
|
2608
|
-
/* @__PURE__ */
|
|
3704
|
+
/* @__PURE__ */ jsx4(
|
|
2609
3705
|
"button",
|
|
2610
3706
|
{
|
|
2611
3707
|
type: "button",
|
|
@@ -2627,16 +3723,16 @@ function GeminaVerification(props) {
|
|
|
2627
3723
|
const content = (() => {
|
|
2628
3724
|
switch (phase.name) {
|
|
2629
3725
|
case "loading":
|
|
2630
|
-
return /* @__PURE__ */
|
|
3726
|
+
return /* @__PURE__ */ jsx4("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
|
|
2631
3727
|
case "unavailable":
|
|
2632
|
-
return /* @__PURE__ */
|
|
3728
|
+
return /* @__PURE__ */ jsxs4(
|
|
2633
3729
|
"div",
|
|
2634
3730
|
{
|
|
2635
3731
|
className: "gemina-verification__state",
|
|
2636
3732
|
role: ALERT_REASONS.has(phase.reason) ? "alert" : "status",
|
|
2637
3733
|
children: [
|
|
2638
|
-
/* @__PURE__ */
|
|
2639
|
-
phase.canRetry && /* @__PURE__ */
|
|
3734
|
+
/* @__PURE__ */ jsx4("div", { children: phase.message }),
|
|
3735
|
+
phase.canRetry && /* @__PURE__ */ jsx4("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
|
|
2640
3736
|
]
|
|
2641
3737
|
}
|
|
2642
3738
|
);
|
|
@@ -2646,7 +3742,7 @@ function GeminaVerification(props) {
|
|
|
2646
3742
|
case "submit-error":
|
|
2647
3743
|
return renderReview(phase);
|
|
2648
3744
|
case "done":
|
|
2649
|
-
return /* @__PURE__ */
|
|
3745
|
+
return /* @__PURE__ */ jsxs4(
|
|
2650
3746
|
"div",
|
|
2651
3747
|
{
|
|
2652
3748
|
ref: doneStateRef,
|
|
@@ -2654,7 +3750,7 @@ function GeminaVerification(props) {
|
|
|
2654
3750
|
className: "gemina-verification__state gemina-verification__state--done",
|
|
2655
3751
|
role: "status",
|
|
2656
3752
|
children: [
|
|
2657
|
-
/* @__PURE__ */
|
|
3753
|
+
/* @__PURE__ */ jsx4("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ jsx4("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ jsx4(
|
|
2658
3754
|
"path",
|
|
2659
3755
|
{
|
|
2660
3756
|
d: "M4 10.5l4 4 8-9",
|
|
@@ -2664,17 +3760,17 @@ function GeminaVerification(props) {
|
|
|
2664
3760
|
strokeLinejoin: "round"
|
|
2665
3761
|
}
|
|
2666
3762
|
) }) }),
|
|
2667
|
-
/* @__PURE__ */
|
|
2668
|
-
/* @__PURE__ */
|
|
3763
|
+
/* @__PURE__ */ jsx4("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
|
|
3764
|
+
/* @__PURE__ */ jsx4("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
|
|
2669
3765
|
]
|
|
2670
3766
|
}
|
|
2671
3767
|
);
|
|
2672
3768
|
}
|
|
2673
3769
|
})();
|
|
2674
|
-
return /* @__PURE__ */
|
|
3770
|
+
return /* @__PURE__ */ jsx4("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
|
|
2675
3771
|
}
|
|
2676
3772
|
|
|
2677
3773
|
export {
|
|
2678
3774
|
GeminaVerification
|
|
2679
3775
|
};
|
|
2680
|
-
//# sourceMappingURL=chunk-
|
|
3776
|
+
//# sourceMappingURL=chunk-ILX5CY6H.js.map
|