@gemina/elements 0.8.0 → 0.9.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-3SZSUO7E.js → chunk-DU6BUHR5.js} +2 -2
- package/dist/{chunk-5T2M557X.js → chunk-MITACKUW.js} +1348 -341
- package/dist/chunk-MITACKUW.js.map +1 -0
- package/dist/{chunk-724KJLIY.js → chunk-S4KBJRIP.js} +2 -2
- package/dist/{chunk-724KJLIY.js.map → chunk-S4KBJRIP.js.map} +1 -1
- package/dist/index.cjs +1351 -353
- 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 +1351 -353
- 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-DU6BUHR5.js.map} +0 -0
package/dist/verification.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(verification_exports, {
|
|
|
33
33
|
GeminaVerification: () => GeminaVerification
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(verification_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_react4 = require("react");
|
|
37
37
|
var import_sdk = require("@gemina/sdk");
|
|
38
38
|
|
|
39
39
|
// src/internal/response-like.ts
|
|
@@ -82,6 +82,178 @@ async function readErrorEnvelope(error) {
|
|
|
82
82
|
return info;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// src/verification/field-types.ts
|
|
86
|
+
var ISO_4217_CODES = [
|
|
87
|
+
"AED",
|
|
88
|
+
"ARS",
|
|
89
|
+
"AUD",
|
|
90
|
+
"BGN",
|
|
91
|
+
"BRL",
|
|
92
|
+
"CAD",
|
|
93
|
+
"CHF",
|
|
94
|
+
"CLP",
|
|
95
|
+
"CNY",
|
|
96
|
+
"COP",
|
|
97
|
+
"CZK",
|
|
98
|
+
"DKK",
|
|
99
|
+
"EGP",
|
|
100
|
+
"EUR",
|
|
101
|
+
"GBP",
|
|
102
|
+
"HKD",
|
|
103
|
+
"HRK",
|
|
104
|
+
"HUF",
|
|
105
|
+
"IDR",
|
|
106
|
+
"ILS",
|
|
107
|
+
"INR",
|
|
108
|
+
"ISK",
|
|
109
|
+
"JPY",
|
|
110
|
+
"KRW",
|
|
111
|
+
"MAD",
|
|
112
|
+
"MXN",
|
|
113
|
+
"MYR",
|
|
114
|
+
"NGN",
|
|
115
|
+
"NOK",
|
|
116
|
+
"NZD",
|
|
117
|
+
"PEN",
|
|
118
|
+
"PHP",
|
|
119
|
+
"PLN",
|
|
120
|
+
"RON",
|
|
121
|
+
"RSD",
|
|
122
|
+
"RUB",
|
|
123
|
+
"SAR",
|
|
124
|
+
"SEK",
|
|
125
|
+
"SGD",
|
|
126
|
+
"THB",
|
|
127
|
+
"TRY",
|
|
128
|
+
"TWD",
|
|
129
|
+
"UAH",
|
|
130
|
+
"USD",
|
|
131
|
+
"VND",
|
|
132
|
+
"ZAR"
|
|
133
|
+
];
|
|
134
|
+
var ISO_4217_SHAPE = /^[A-Za-z]{3}$/;
|
|
135
|
+
var DATE_SHAPE = /^\d{4}-\d{2}-\d{2}$/;
|
|
136
|
+
var NUMERIC_SHAPE = /^[+-]?[\d,_]*\.?\d+$/;
|
|
137
|
+
function toNumber(value) {
|
|
138
|
+
if (!NUMERIC_SHAPE.test(value)) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const parsed = Number(value.replace(/[,_]/g, ""));
|
|
142
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
143
|
+
}
|
|
144
|
+
function validateInput(value, field) {
|
|
145
|
+
const trimmed = value.trim();
|
|
146
|
+
if (trimmed === "" || !field) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (field.enum && field.enum.length > 0) {
|
|
150
|
+
return field.enum.includes(trimmed) ? null : `Choose one of: ${field.enum.join(", ")}`;
|
|
151
|
+
}
|
|
152
|
+
if (field.format === "iso4217") {
|
|
153
|
+
return ISO_4217_SHAPE.test(trimmed) ? null : "Use a 3-letter ISO 4217 code, e.g. USD";
|
|
154
|
+
}
|
|
155
|
+
switch (field.type) {
|
|
156
|
+
case "number":
|
|
157
|
+
return toNumber(trimmed) === null ? "Enter a number" : null;
|
|
158
|
+
case "integer": {
|
|
159
|
+
const parsed = toNumber(trimmed);
|
|
160
|
+
if (parsed === null || !Number.isInteger(parsed)) {
|
|
161
|
+
return "Enter a whole number";
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
case "date": {
|
|
166
|
+
if (!DATE_SHAPE.test(trimmed)) {
|
|
167
|
+
return "Enter a date as YYYY-MM-DD";
|
|
168
|
+
}
|
|
169
|
+
const [year, month, day] = trimmed.split("-").map(Number);
|
|
170
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
171
|
+
const survives = date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
172
|
+
return survives ? null : "Enter a date as YYYY-MM-DD";
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function readRowMutableTables(raw) {
|
|
179
|
+
if (!Array.isArray(raw)) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
const out = [];
|
|
183
|
+
for (const item of raw) {
|
|
184
|
+
if (item === null || typeof item !== "object") {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const source = item;
|
|
188
|
+
if (typeof source.pointer !== "string" || typeof source.keyTemplate !== "string") {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
out.push({
|
|
192
|
+
pointer: source.pointer,
|
|
193
|
+
keyTemplate: source.keyTemplate,
|
|
194
|
+
// Columns are descriptors keyed by `name` rather than `key`, so they get
|
|
195
|
+
// the same treatment with the name standing in as the identity.
|
|
196
|
+
columns: readDescriptors(
|
|
197
|
+
(Array.isArray(source.columns) ? source.columns : []).map((column) => {
|
|
198
|
+
const record = column ?? {};
|
|
199
|
+
return { ...record, key: record.name };
|
|
200
|
+
})
|
|
201
|
+
)
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
function cellSchemaKey(template, index, field) {
|
|
207
|
+
return template.replace(/\{index\}/g, String(index)).replace(/\{field\}/g, field);
|
|
208
|
+
}
|
|
209
|
+
function coerceInput(value, field) {
|
|
210
|
+
if (!field) {
|
|
211
|
+
return value;
|
|
212
|
+
}
|
|
213
|
+
switch (field.type) {
|
|
214
|
+
case "number":
|
|
215
|
+
case "integer": {
|
|
216
|
+
const parsed = toNumber(value);
|
|
217
|
+
return parsed === null ? value : parsed;
|
|
218
|
+
}
|
|
219
|
+
case "boolean": {
|
|
220
|
+
const lowered = value.trim().toLowerCase();
|
|
221
|
+
if (lowered === "true") return true;
|
|
222
|
+
if (lowered === "false") return false;
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
// `date` stays a string: the wire format IS the ISO string, and a Date
|
|
226
|
+
// object would serialise with a time component the extraction never had.
|
|
227
|
+
default:
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function readDescriptors(raw) {
|
|
232
|
+
if (!Array.isArray(raw)) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
const out = [];
|
|
236
|
+
for (const item of raw) {
|
|
237
|
+
if (item === null || typeof item !== "object") {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const source = item;
|
|
241
|
+
if (typeof source.key !== "string") {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const roster = source._enum ?? source.enum;
|
|
245
|
+
out.push({
|
|
246
|
+
key: source.key,
|
|
247
|
+
label: typeof source.label === "string" ? source.label : void 0,
|
|
248
|
+
type: typeof source.type === "string" ? source.type : void 0,
|
|
249
|
+
enum: Array.isArray(roster) ? roster.map(String) : null,
|
|
250
|
+
format: typeof source.format === "string" ? source.format : null,
|
|
251
|
+
description: typeof source.description === "string" ? source.description : null
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
|
|
85
257
|
// src/verification/classify.ts
|
|
86
258
|
var ACRONYMS = /* @__PURE__ */ new Set(["ID", "VAT", "OCR", "PDF", "URL", "API", "HTML", "CSS", "JSON", "XML", "UUID"]);
|
|
87
259
|
function formatLabel(key) {
|
|
@@ -403,6 +575,9 @@ function parseSchemaKey(raw) {
|
|
|
403
575
|
return { raw, label: match[1], pointer: match[2] };
|
|
404
576
|
}
|
|
405
577
|
var NOT_FOUND = /* @__PURE__ */ Symbol("gemina-verification-not-found");
|
|
578
|
+
function snakeToCamel(segment) {
|
|
579
|
+
return segment.replace(/_([a-zA-Z0-9])/g, (_unused, ch) => ch.toUpperCase());
|
|
580
|
+
}
|
|
406
581
|
|
|
407
582
|
// src/verification/bindings.ts
|
|
408
583
|
function unescapeSegment(raw) {
|
|
@@ -411,9 +586,6 @@ function unescapeSegment(raw) {
|
|
|
411
586
|
function escapeSegment2(segment) {
|
|
412
587
|
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
413
588
|
}
|
|
414
|
-
function snakeToCamel(segment) {
|
|
415
|
-
return segment.replace(/_([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
|
|
416
|
-
}
|
|
417
589
|
function camelizePointer(pointer) {
|
|
418
590
|
if (!pointer.startsWith("/")) {
|
|
419
591
|
return pointer;
|
|
@@ -464,7 +636,13 @@ function resolveCasingAware(doc, pointer) {
|
|
|
464
636
|
function stripValueSuffix(pointer) {
|
|
465
637
|
return pointer.endsWith("/value") ? pointer.slice(0, -"/value".length) : pointer;
|
|
466
638
|
}
|
|
467
|
-
function buildBindings(validationSchema, values) {
|
|
639
|
+
function buildBindings(validationSchema, values, fields) {
|
|
640
|
+
const descriptors = /* @__PURE__ */ new Map();
|
|
641
|
+
for (const descriptor of fields ?? []) {
|
|
642
|
+
if (typeof descriptor?.key === "string") {
|
|
643
|
+
descriptors.set(descriptor.key, descriptor);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
468
646
|
const bindings = [];
|
|
469
647
|
for (const raw of validationSchema) {
|
|
470
648
|
const key = parseSchemaKey(raw);
|
|
@@ -479,7 +657,8 @@ function buildBindings(validationSchema, values) {
|
|
|
479
657
|
serverValue,
|
|
480
658
|
extracted,
|
|
481
659
|
fieldPointer: stripValueSuffix(resolvedPointer),
|
|
482
|
-
editable
|
|
660
|
+
editable,
|
|
661
|
+
field: descriptors.get(key.raw)
|
|
483
662
|
});
|
|
484
663
|
}
|
|
485
664
|
return bindings;
|
|
@@ -500,39 +679,356 @@ function toInputString(extracted) {
|
|
|
500
679
|
}
|
|
501
680
|
return String(extracted);
|
|
502
681
|
}
|
|
503
|
-
function composeSubmission(bindings, edits) {
|
|
682
|
+
function composeSubmission(bindings, edits, options = {}) {
|
|
683
|
+
const cells = options.cells ?? bindings.map((binding) => ({
|
|
684
|
+
editKey: binding.key.raw,
|
|
685
|
+
submitKey: binding.key.raw,
|
|
686
|
+
column: binding.key.label,
|
|
687
|
+
rowKey: binding.key.raw,
|
|
688
|
+
binding,
|
|
689
|
+
added: false
|
|
690
|
+
}));
|
|
504
691
|
const data = {};
|
|
505
692
|
const byLabel = {};
|
|
506
693
|
let confirmed = 0;
|
|
507
694
|
let corrected = 0;
|
|
508
|
-
for (const
|
|
509
|
-
const
|
|
695
|
+
for (const cell of cells) {
|
|
696
|
+
const { binding } = cell;
|
|
697
|
+
const label = parseSchemaKey(cell.submitKey)?.label ?? binding.key.label;
|
|
698
|
+
const edit = edits.get(cell.editKey);
|
|
510
699
|
if (edit !== void 0) {
|
|
511
700
|
const trimmed = edit.trim();
|
|
512
701
|
if (trimmed === "" && binding.serverValue === NOT_FOUND) {
|
|
513
702
|
continue;
|
|
514
703
|
}
|
|
515
|
-
const value = trimmed === "" ? null : trimmed;
|
|
516
|
-
data[
|
|
517
|
-
byLabel[
|
|
704
|
+
const value = trimmed === "" ? null : coerceInput(trimmed, binding.field);
|
|
705
|
+
data[cell.submitKey] = value;
|
|
706
|
+
byLabel[label] = value;
|
|
518
707
|
corrected += 1;
|
|
519
708
|
} else {
|
|
520
709
|
if (binding.serverValue === NOT_FOUND) {
|
|
521
710
|
continue;
|
|
522
711
|
}
|
|
523
|
-
data[
|
|
524
|
-
byLabel[
|
|
712
|
+
data[cell.submitKey] = binding.serverValue;
|
|
713
|
+
byLabel[label] = binding.serverValue;
|
|
525
714
|
confirmed += 1;
|
|
526
715
|
}
|
|
527
716
|
}
|
|
528
|
-
return { data, byLabel, confirmed, corrected };
|
|
717
|
+
return { data, byLabel, confirmed, corrected, rowSources: options.rowSources ?? [] };
|
|
718
|
+
}
|
|
719
|
+
function countRowsAt(values, pointer) {
|
|
720
|
+
const { node } = resolveCasingAware(values, pointer);
|
|
721
|
+
return Array.isArray(node) ? node.length : 0;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// src/verification/row-plan.ts
|
|
725
|
+
var addedRowCounter = 0;
|
|
726
|
+
function initialRowPlan(extractedCount, scope = "") {
|
|
727
|
+
return Array.from({ length: Math.max(0, extractedCount) }, (_unused, index) => ({
|
|
728
|
+
// Derived from the source index, so it is stable across re-renders without
|
|
729
|
+
// any state to carry — an extracted row's identity never changes.
|
|
730
|
+
id: `${scope}#row-${index}`,
|
|
731
|
+
source: index
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
function nextAddedRowId(scope = "") {
|
|
735
|
+
addedRowCounter += 1;
|
|
736
|
+
return `${scope}#added-${addedRowCounter}`;
|
|
737
|
+
}
|
|
738
|
+
function removeRow(plan, position) {
|
|
739
|
+
if (position < 0 || position >= plan.length) {
|
|
740
|
+
return plan;
|
|
741
|
+
}
|
|
742
|
+
return plan.filter((_entry, index) => index !== position);
|
|
743
|
+
}
|
|
744
|
+
function insertRowAfter(plan, position, id) {
|
|
745
|
+
const added = { id: id ?? nextAddedRowId(), source: null };
|
|
746
|
+
const at = Math.min(Math.max(position + 1, 0), plan.length);
|
|
747
|
+
return [...plan.slice(0, at), added, ...plan.slice(at)];
|
|
748
|
+
}
|
|
749
|
+
function cellEditKey(rowId, column) {
|
|
750
|
+
return `cell:${rowId}|col:${column}`;
|
|
751
|
+
}
|
|
752
|
+
function rowSourcesOf(plan) {
|
|
753
|
+
return plan.map((entry) => entry.source);
|
|
754
|
+
}
|
|
755
|
+
function isIdentityPlan(plan, extractedCount) {
|
|
756
|
+
return plan.length === extractedCount && plan.every((entry, index) => entry.source === index);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/verification/row-cells.ts
|
|
760
|
+
function syntheticBinding(submitKey, descriptor) {
|
|
761
|
+
const key = parseSchemaKey(submitKey);
|
|
762
|
+
if (key === null) {
|
|
763
|
+
return null;
|
|
764
|
+
}
|
|
765
|
+
return {
|
|
766
|
+
key,
|
|
767
|
+
serverValue: NOT_FOUND,
|
|
768
|
+
extracted: NOT_FOUND,
|
|
769
|
+
// No extracted node, so nothing to point at on the document.
|
|
770
|
+
fieldPointer: key.pointer,
|
|
771
|
+
editable: true,
|
|
772
|
+
field: descriptor
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
function planTableCells(table, plan, columns, bindingsByRawKey) {
|
|
776
|
+
const descriptors = /* @__PURE__ */ new Map();
|
|
777
|
+
for (const column of table.columns) {
|
|
778
|
+
if (typeof column.key === "string") {
|
|
779
|
+
descriptors.set(column.key, column);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return plan.map((entry, submittedIndex) => {
|
|
783
|
+
const cells = [];
|
|
784
|
+
for (const column of columns) {
|
|
785
|
+
const submitKey = cellSchemaKey(table.keyTemplate, submittedIndex, column);
|
|
786
|
+
const editKey = cellEditKey(entry.id, column);
|
|
787
|
+
const extractedKey = entry.source === null ? null : cellSchemaKey(table.keyTemplate, entry.source, column);
|
|
788
|
+
const existing = extractedKey === null ? void 0 : bindingsByRawKey.get(extractedKey);
|
|
789
|
+
const binding = existing ?? syntheticBinding(submitKey, descriptors.get(column));
|
|
790
|
+
if (binding === null) {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
cells.push({ column, editKey, submitKey, binding, added: existing === void 0 });
|
|
794
|
+
}
|
|
795
|
+
return { entry, cells };
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
function displayColumns(table, classifiedColumns) {
|
|
799
|
+
const declared = table.columns.map((column) => column.key).filter((name) => typeof name === "string");
|
|
800
|
+
const seen = new Set(declared);
|
|
801
|
+
return [...declared, ...classifiedColumns.filter((name) => !seen.has(name))];
|
|
802
|
+
}
|
|
803
|
+
function matchesTablePointer(serverPointer, classifiedPointer) {
|
|
804
|
+
return serverPointer === classifiedPointer || snakeToCamel(serverPointer) === classifiedPointer;
|
|
805
|
+
}
|
|
806
|
+
function splitPointer(pointer) {
|
|
807
|
+
const cut = pointer.lastIndexOf("/");
|
|
808
|
+
return cut <= 0 ? null : { row: pointer.slice(0, cut), field: pointer.slice(cut + 1) };
|
|
809
|
+
}
|
|
810
|
+
function collectCellViews(bindings, plannedTables) {
|
|
811
|
+
const views = [];
|
|
812
|
+
const ownedPrefixes = [...plannedTables.keys()].map((pointer) => `${pointer}/`);
|
|
813
|
+
for (const rows of plannedTables.values()) {
|
|
814
|
+
for (const row of rows) {
|
|
815
|
+
for (const cell of row.cells) {
|
|
816
|
+
views.push({
|
|
817
|
+
editKey: cell.editKey,
|
|
818
|
+
submitKey: cell.submitKey,
|
|
819
|
+
column: cell.column,
|
|
820
|
+
rowKey: row.entry.id,
|
|
821
|
+
binding: cell.binding,
|
|
822
|
+
added: cell.added
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
for (const binding of bindings) {
|
|
828
|
+
if (ownedPrefixes.some((prefix) => binding.key.pointer.startsWith(prefix))) {
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
const split = splitPointer(binding.key.pointer);
|
|
832
|
+
views.push({
|
|
833
|
+
// Outside a plan all three identities coincide, which is why none of
|
|
834
|
+
// this was needed before row editing.
|
|
835
|
+
editKey: binding.key.raw,
|
|
836
|
+
submitKey: binding.key.raw,
|
|
837
|
+
column: split?.field ?? binding.key.label,
|
|
838
|
+
rowKey: split?.row ?? binding.key.raw,
|
|
839
|
+
binding,
|
|
840
|
+
added: false
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
return views;
|
|
844
|
+
}
|
|
845
|
+
var UNIT_SIZE = "unit_size";
|
|
846
|
+
var UNIT_SIZE_UOM = "unit_size_uom";
|
|
847
|
+
var UNIT_PAIR_MESSAGE = "Enter both value and unit";
|
|
848
|
+
function unitSizePairErrors(cells, edits) {
|
|
849
|
+
const rows = /* @__PURE__ */ new Map();
|
|
850
|
+
for (const cell of cells) {
|
|
851
|
+
if (cell.column !== UNIT_SIZE && cell.column !== UNIT_SIZE_UOM) {
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
const row = rows.get(cell.rowKey) ?? {};
|
|
855
|
+
if (cell.column === UNIT_SIZE) {
|
|
856
|
+
row.size = cell;
|
|
857
|
+
} else {
|
|
858
|
+
row.uom = cell;
|
|
859
|
+
}
|
|
860
|
+
rows.set(cell.rowKey, row);
|
|
861
|
+
}
|
|
862
|
+
const errors = /* @__PURE__ */ new Map();
|
|
863
|
+
for (const { size, uom } of rows.values()) {
|
|
864
|
+
if (!size || !uom) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const filled = (cell) => (edits.get(cell.editKey) ?? toInputString(cell.binding.extracted)).trim() !== "";
|
|
868
|
+
if (filled(size) !== filled(uom)) {
|
|
869
|
+
errors.set(size.editKey, UNIT_PAIR_MESSAGE);
|
|
870
|
+
errors.set(uom.editKey, UNIT_PAIR_MESSAGE);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return errors;
|
|
874
|
+
}
|
|
875
|
+
function pruneEmptyAddedRows(plannedTables, edits) {
|
|
876
|
+
const out = /* @__PURE__ */ new Map();
|
|
877
|
+
for (const [pointer, rows] of plannedTables) {
|
|
878
|
+
out.set(pointer, rows.filter((row) => {
|
|
879
|
+
if (row.entry.source !== null) {
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
return row.cells.some((cell) => (edits.get(cell.editKey) ?? "").trim() !== "");
|
|
883
|
+
}));
|
|
884
|
+
}
|
|
885
|
+
return out;
|
|
529
886
|
}
|
|
530
887
|
|
|
531
888
|
// src/verification/form.tsx
|
|
532
|
-
var
|
|
889
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
533
890
|
|
|
534
|
-
// src/verification/
|
|
891
|
+
// src/verification/tip.tsx
|
|
535
892
|
var import_react = require("react");
|
|
893
|
+
var import_react_dom = require("react-dom");
|
|
894
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
895
|
+
var GAP = 8;
|
|
896
|
+
var MARGIN = 8;
|
|
897
|
+
function isEmpty(content) {
|
|
898
|
+
return content == null || content === "" || content === false;
|
|
899
|
+
}
|
|
900
|
+
function rootClassesOf(node) {
|
|
901
|
+
const root = node?.closest(".gemina-verification");
|
|
902
|
+
return root ? root.className : "gemina-verification";
|
|
903
|
+
}
|
|
904
|
+
function mergeRefs(ours, theirs) {
|
|
905
|
+
return (value) => {
|
|
906
|
+
ours(value);
|
|
907
|
+
if (typeof theirs === "function") {
|
|
908
|
+
theirs(value);
|
|
909
|
+
} else if (theirs && typeof theirs === "object") {
|
|
910
|
+
theirs.current = value;
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
function Tip({ content, children }) {
|
|
915
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
916
|
+
const [position, setPosition] = (0, import_react.useState)(null);
|
|
917
|
+
const [rootClasses, setRootClasses] = (0, import_react.useState)("gemina-verification");
|
|
918
|
+
const triggerRef = (0, import_react.useRef)(null);
|
|
919
|
+
const tipRef = (0, import_react.useRef)(null);
|
|
920
|
+
const id = (0, import_react.useId)();
|
|
921
|
+
const empty = isEmpty(content);
|
|
922
|
+
const show = (0, import_react.useCallback)(() => {
|
|
923
|
+
if (empty) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
setRootClasses(rootClassesOf(triggerRef.current));
|
|
927
|
+
setPosition(null);
|
|
928
|
+
setOpen(true);
|
|
929
|
+
}, [empty]);
|
|
930
|
+
const hide = (0, import_react.useCallback)(() => setOpen(false), []);
|
|
931
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
932
|
+
if (!open) {
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
const trigger2 = triggerRef.current;
|
|
936
|
+
const tip = tipRef.current;
|
|
937
|
+
if (!trigger2 || !tip) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const anchor = trigger2.getBoundingClientRect();
|
|
941
|
+
const bubble = tip.getBoundingClientRect();
|
|
942
|
+
const viewportWidth = window.innerWidth || 0;
|
|
943
|
+
const viewportHeight = window.innerHeight || 0;
|
|
944
|
+
const fitsAbove = anchor.top - bubble.height - GAP >= MARGIN;
|
|
945
|
+
const fitsBelow = anchor.bottom + bubble.height + GAP <= viewportHeight - MARGIN;
|
|
946
|
+
const top = fitsAbove || !fitsBelow ? anchor.top - bubble.height - GAP : anchor.bottom + GAP;
|
|
947
|
+
const centred = anchor.left + anchor.width / 2 - bubble.width / 2;
|
|
948
|
+
const rightLimit = Math.max(MARGIN, viewportWidth - bubble.width - MARGIN);
|
|
949
|
+
const left = Math.min(Math.max(centred, MARGIN), rightLimit);
|
|
950
|
+
setPosition({ top: Math.max(top, MARGIN), left });
|
|
951
|
+
}, [open, content]);
|
|
952
|
+
(0, import_react.useEffect)(() => {
|
|
953
|
+
if (!open) {
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
const onKeyDown = (event) => {
|
|
957
|
+
if (event.key === "Escape") {
|
|
958
|
+
hide();
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
const onScrollOrResize = () => hide();
|
|
962
|
+
document.addEventListener("keydown", onKeyDown);
|
|
963
|
+
document.addEventListener("scroll", onScrollOrResize, true);
|
|
964
|
+
window.addEventListener("resize", onScrollOrResize);
|
|
965
|
+
return () => {
|
|
966
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
967
|
+
document.removeEventListener("scroll", onScrollOrResize, true);
|
|
968
|
+
window.removeEventListener("resize", onScrollOrResize);
|
|
969
|
+
};
|
|
970
|
+
}, [open, hide]);
|
|
971
|
+
if (!(0, import_react.isValidElement)(children)) {
|
|
972
|
+
return children;
|
|
973
|
+
}
|
|
974
|
+
const childProps = children.props;
|
|
975
|
+
const call = (name, event) => {
|
|
976
|
+
const handler = childProps[name];
|
|
977
|
+
if (typeof handler === "function") {
|
|
978
|
+
handler(event);
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
const trigger = (0, import_react.cloneElement)(children, {
|
|
982
|
+
ref: mergeRefs((node) => {
|
|
983
|
+
triggerRef.current = node;
|
|
984
|
+
}, children.ref),
|
|
985
|
+
// The tip is a DESCRIPTION. `aria-label` stays untouched — it already
|
|
986
|
+
// carries the reason into the accessible NAME, and duplicating it here
|
|
987
|
+
// would have a screen reader announce it twice.
|
|
988
|
+
"aria-describedby": open && !empty ? id : void 0,
|
|
989
|
+
onMouseEnter: (event) => {
|
|
990
|
+
call("onMouseEnter", event);
|
|
991
|
+
show();
|
|
992
|
+
},
|
|
993
|
+
onMouseLeave: (event) => {
|
|
994
|
+
call("onMouseLeave", event);
|
|
995
|
+
hide();
|
|
996
|
+
},
|
|
997
|
+
onFocus: (event) => {
|
|
998
|
+
call("onFocus", event);
|
|
999
|
+
show();
|
|
1000
|
+
},
|
|
1001
|
+
onBlur: (event) => {
|
|
1002
|
+
call("onBlur", event);
|
|
1003
|
+
hide();
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
const canPortal = typeof document !== "undefined" && document.body;
|
|
1007
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1008
|
+
trigger,
|
|
1009
|
+
open && !empty && canPortal ? (0, import_react_dom.createPortal)(
|
|
1010
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: rootClasses, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1011
|
+
"div",
|
|
1012
|
+
{
|
|
1013
|
+
ref: tipRef,
|
|
1014
|
+
id,
|
|
1015
|
+
role: "tooltip",
|
|
1016
|
+
className: "gemina-verification__tip",
|
|
1017
|
+
style: {
|
|
1018
|
+
top: position ? `${position.top}px` : "0px",
|
|
1019
|
+
left: position ? `${position.left}px` : "0px",
|
|
1020
|
+
visibility: position ? "visible" : "hidden"
|
|
1021
|
+
},
|
|
1022
|
+
children: content
|
|
1023
|
+
}
|
|
1024
|
+
) }),
|
|
1025
|
+
document.body
|
|
1026
|
+
) : null
|
|
1027
|
+
] });
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/verification/viewer.tsx
|
|
1031
|
+
var import_react2 = require("react");
|
|
536
1032
|
|
|
537
1033
|
// src/verification/viewer-math.ts
|
|
538
1034
|
function fitScaleFor(natural, container, rotationDeg) {
|
|
@@ -614,9 +1110,9 @@ function flashZoomTarget(rects, natural, container, rotationDeg, fitScale) {
|
|
|
614
1110
|
var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
615
1111
|
|
|
616
1112
|
// src/verification/viewer.tsx
|
|
617
|
-
var
|
|
1113
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
618
1114
|
function IconBase({ children }) {
|
|
619
|
-
return /* @__PURE__ */ (0,
|
|
1115
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
620
1116
|
"svg",
|
|
621
1117
|
{
|
|
622
1118
|
width: "16",
|
|
@@ -634,56 +1130,56 @@ function IconBase({ children }) {
|
|
|
634
1130
|
);
|
|
635
1131
|
}
|
|
636
1132
|
function GlassBody() {
|
|
637
|
-
return /* @__PURE__ */ (0,
|
|
638
|
-
/* @__PURE__ */ (0,
|
|
639
|
-
/* @__PURE__ */ (0,
|
|
1133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
1134
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "6.75", cy: "6.75", r: "4.25" }),
|
|
1135
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "9.9", y1: "9.9", x2: "13.5", y2: "13.5" })
|
|
640
1136
|
] });
|
|
641
1137
|
}
|
|
642
1138
|
function IconZoomIn() {
|
|
643
|
-
return /* @__PURE__ */ (0,
|
|
644
|
-
/* @__PURE__ */ (0,
|
|
645
|
-
/* @__PURE__ */ (0,
|
|
646
|
-
/* @__PURE__ */ (0,
|
|
1139
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1140
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}),
|
|
1141
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" }),
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "6.75", y1: "4.9", x2: "6.75", y2: "8.6" })
|
|
647
1143
|
] });
|
|
648
1144
|
}
|
|
649
1145
|
function IconZoomOut() {
|
|
650
|
-
return /* @__PURE__ */ (0,
|
|
651
|
-
/* @__PURE__ */ (0,
|
|
652
|
-
/* @__PURE__ */ (0,
|
|
1146
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1147
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}),
|
|
1148
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "4.9", y1: "6.75", x2: "8.6", y2: "6.75" })
|
|
653
1149
|
] });
|
|
654
1150
|
}
|
|
655
1151
|
function IconMagnifier() {
|
|
656
|
-
return /* @__PURE__ */ (0,
|
|
1152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GlassBody, {}) });
|
|
657
1153
|
}
|
|
658
1154
|
function IconActualSize() {
|
|
659
|
-
return /* @__PURE__ */ (0,
|
|
660
|
-
/* @__PURE__ */ (0,
|
|
661
|
-
/* @__PURE__ */ (0,
|
|
662
|
-
/* @__PURE__ */ (0,
|
|
663
|
-
/* @__PURE__ */ (0,
|
|
1155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1156
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "2.8 6.2 4 5 4 11" }),
|
|
1157
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "10.8 6.2 12 5 12 11" }),
|
|
1158
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "6.75", r: "0.8", fill: "currentColor", stroke: "none" }),
|
|
1159
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "9.25", r: "0.8", fill: "currentColor", stroke: "none" })
|
|
664
1160
|
] });
|
|
665
1161
|
}
|
|
666
1162
|
function IconFit() {
|
|
667
|
-
return /* @__PURE__ */ (0,
|
|
668
|
-
/* @__PURE__ */ (0,
|
|
669
|
-
/* @__PURE__ */ (0,
|
|
670
|
-
/* @__PURE__ */ (0,
|
|
671
|
-
/* @__PURE__ */ (0,
|
|
1163
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1164
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "13.8", y1: "2.2", x2: "9.6", y2: "6.4" }),
|
|
1165
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "9.6 3.9 9.6 6.4 12.1 6.4" }),
|
|
1166
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "2.2", y1: "13.8", x2: "6.4", y2: "9.6" }),
|
|
1167
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "6.4 12.1 6.4 9.6 3.9 9.6" })
|
|
672
1168
|
] });
|
|
673
1169
|
}
|
|
674
1170
|
function IconRotate() {
|
|
675
|
-
return /* @__PURE__ */ (0,
|
|
676
|
-
/* @__PURE__ */ (0,
|
|
677
|
-
/* @__PURE__ */ (0,
|
|
1171
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1172
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M11.83 4.79A5 5 0 1 1 8 3" }),
|
|
1173
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "6 1.7 8 3 6 4.3" })
|
|
678
1174
|
] });
|
|
679
1175
|
}
|
|
680
1176
|
function IconOverlay() {
|
|
681
|
-
return /* @__PURE__ */ (0,
|
|
1177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconBase, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "2.75", y: "2.75", width: "10.5", height: "10.5", rx: "1.5", strokeDasharray: "3 2.2" }) });
|
|
682
1178
|
}
|
|
683
1179
|
function IconEye() {
|
|
684
|
-
return /* @__PURE__ */ (0,
|
|
685
|
-
/* @__PURE__ */ (0,
|
|
686
|
-
/* @__PURE__ */ (0,
|
|
1180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(IconBase, { children: [
|
|
1181
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("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" }),
|
|
1182
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "8", cy: "8", r: "2.1" })
|
|
687
1183
|
] });
|
|
688
1184
|
}
|
|
689
1185
|
function ToolbarButton({
|
|
@@ -695,12 +1191,11 @@ function ToolbarButton({
|
|
|
695
1191
|
children
|
|
696
1192
|
}) {
|
|
697
1193
|
const active = (pressed ?? checked) === true;
|
|
698
|
-
return /* @__PURE__ */ (0,
|
|
1194
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Tip, { content: label, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
699
1195
|
"button",
|
|
700
1196
|
{
|
|
701
1197
|
type: "button",
|
|
702
1198
|
className: active ? "gemina-verification__toolbar-btn gemina-verification__toolbar-btn--active" : "gemina-verification__toolbar-btn",
|
|
703
|
-
title: label,
|
|
704
1199
|
"aria-label": label,
|
|
705
1200
|
role: checked === void 0 ? void 0 : "switch",
|
|
706
1201
|
"aria-checked": checked,
|
|
@@ -709,7 +1204,7 @@ function ToolbarButton({
|
|
|
709
1204
|
onClick,
|
|
710
1205
|
children
|
|
711
1206
|
}
|
|
712
|
-
);
|
|
1207
|
+
) });
|
|
713
1208
|
}
|
|
714
1209
|
var ZOOM_STEP = 1.2;
|
|
715
1210
|
var IDENTITY = { scale: 1, tx: 0, ty: 0 };
|
|
@@ -719,6 +1214,7 @@ var REDUCED_MOTION_FLASH_MS = 800;
|
|
|
719
1214
|
var MIN_SIZE_RATIO = 8e-3;
|
|
720
1215
|
var MAG_RADIUS = 150;
|
|
721
1216
|
var MAG_ZOOM = 2.5;
|
|
1217
|
+
var MAG_BORDER = 2;
|
|
722
1218
|
function rectGeometry(rect, natural) {
|
|
723
1219
|
const xs = rect.points.map((point) => point[0]);
|
|
724
1220
|
const ys = rect.points.map((point) => point[1]);
|
|
@@ -736,29 +1232,29 @@ function rectGeometry(rect, natural) {
|
|
|
736
1232
|
}
|
|
737
1233
|
function VerificationViewer(props) {
|
|
738
1234
|
const { src, alt, relativeRects, flashRects, onFlashComplete, onImageExpired } = props;
|
|
739
|
-
const canvasRef = (0,
|
|
740
|
-
const imgRef = (0,
|
|
741
|
-
const [natural, setNatural] = (0,
|
|
742
|
-
const [container, setContainer] = (0,
|
|
743
|
-
const [transform, setTransform] = (0,
|
|
744
|
-
const [rotation, setRotation] = (0,
|
|
745
|
-
const [showRects, setShowRects] = (0,
|
|
746
|
-
const [magnifierOn, setMagnifierOn] = (0,
|
|
747
|
-
const [showMag, setShowMag] = (0,
|
|
748
|
-
const [mousePos, setMousePos] = (0,
|
|
749
|
-
const [isPanning, setIsPanning] = (0,
|
|
750
|
-
const panStart = (0,
|
|
751
|
-
const [flashOpacity, setFlashOpacity] = (0,
|
|
752
|
-
const [activeFlashRects, setActiveFlashRects] = (0,
|
|
753
|
-
const travelRafRef = (0,
|
|
754
|
-
const fadeRafRef = (0,
|
|
755
|
-
const reducedFlashTimeoutRef = (0,
|
|
756
|
-
const transformRef = (0,
|
|
1235
|
+
const canvasRef = (0, import_react2.useRef)(null);
|
|
1236
|
+
const imgRef = (0, import_react2.useRef)(null);
|
|
1237
|
+
const [natural, setNatural] = (0, import_react2.useState)(null);
|
|
1238
|
+
const [container, setContainer] = (0, import_react2.useState)({ w: 0, h: 0 });
|
|
1239
|
+
const [transform, setTransform] = (0, import_react2.useState)(IDENTITY);
|
|
1240
|
+
const [rotation, setRotation] = (0, import_react2.useState)(0);
|
|
1241
|
+
const [showRects, setShowRects] = (0, import_react2.useState)(false);
|
|
1242
|
+
const [magnifierOn, setMagnifierOn] = (0, import_react2.useState)(false);
|
|
1243
|
+
const [showMag, setShowMag] = (0, import_react2.useState)(false);
|
|
1244
|
+
const [mousePos, setMousePos] = (0, import_react2.useState)({ x: 0, y: 0 });
|
|
1245
|
+
const [isPanning, setIsPanning] = (0, import_react2.useState)(false);
|
|
1246
|
+
const panStart = (0, import_react2.useRef)(null);
|
|
1247
|
+
const [flashOpacity, setFlashOpacity] = (0, import_react2.useState)(0);
|
|
1248
|
+
const [activeFlashRects, setActiveFlashRects] = (0, import_react2.useState)(null);
|
|
1249
|
+
const travelRafRef = (0, import_react2.useRef)(null);
|
|
1250
|
+
const fadeRafRef = (0, import_react2.useRef)(null);
|
|
1251
|
+
const reducedFlashTimeoutRef = (0, import_react2.useRef)(null);
|
|
1252
|
+
const transformRef = (0, import_react2.useRef)(transform);
|
|
757
1253
|
transformRef.current = transform;
|
|
758
|
-
const onFlashCompleteRef = (0,
|
|
1254
|
+
const onFlashCompleteRef = (0, import_react2.useRef)(onFlashComplete);
|
|
759
1255
|
onFlashCompleteRef.current = onFlashComplete;
|
|
760
|
-
const hasLoadedRef = (0,
|
|
761
|
-
(0,
|
|
1256
|
+
const hasLoadedRef = (0, import_react2.useRef)(false);
|
|
1257
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
762
1258
|
const el = canvasRef.current;
|
|
763
1259
|
if (!el) return;
|
|
764
1260
|
if (typeof ResizeObserver === "undefined") {
|
|
@@ -773,7 +1269,7 @@ function VerificationViewer(props) {
|
|
|
773
1269
|
ro.observe(el);
|
|
774
1270
|
return () => ro.disconnect();
|
|
775
1271
|
}, []);
|
|
776
|
-
const handleImgLoad = (0,
|
|
1272
|
+
const handleImgLoad = (0, import_react2.useCallback)(() => {
|
|
777
1273
|
const img = imgRef.current;
|
|
778
1274
|
if (!img) return;
|
|
779
1275
|
hasLoadedRef.current = true;
|
|
@@ -781,19 +1277,19 @@ function VerificationViewer(props) {
|
|
|
781
1277
|
const h = img.naturalHeight;
|
|
782
1278
|
setNatural((prev) => prev && prev.w === w && prev.h === h ? prev : { w, h });
|
|
783
1279
|
}, []);
|
|
784
|
-
(0,
|
|
1280
|
+
(0, import_react2.useEffect)(() => {
|
|
785
1281
|
hasLoadedRef.current = false;
|
|
786
1282
|
}, [src]);
|
|
787
|
-
const handleImgError = (0,
|
|
1283
|
+
const handleImgError = (0, import_react2.useCallback)(() => {
|
|
788
1284
|
if (!hasLoadedRef.current) return;
|
|
789
1285
|
hasLoadedRef.current = false;
|
|
790
1286
|
onImageExpired?.();
|
|
791
1287
|
}, [onImageExpired]);
|
|
792
|
-
const currentFitScale = (0,
|
|
1288
|
+
const currentFitScale = (0, import_react2.useCallback)(() => {
|
|
793
1289
|
if (!natural || !container.w || !container.h) return 1;
|
|
794
1290
|
return fitScaleFor(natural, container, rotation);
|
|
795
1291
|
}, [natural, container, rotation]);
|
|
796
|
-
(0,
|
|
1292
|
+
(0, import_react2.useEffect)(() => {
|
|
797
1293
|
if (!natural || !container.w || !container.h) return;
|
|
798
1294
|
const fit = fitScaleFor(natural, container, rotation);
|
|
799
1295
|
const { tx, ty } = centeredTranslation(natural, container, fit, rotation);
|
|
@@ -801,13 +1297,13 @@ function VerificationViewer(props) {
|
|
|
801
1297
|
(prev) => Math.abs(prev.scale - fit) < 1e-4 && prev.tx === tx && prev.ty === ty ? prev : { scale: fit, tx, ty }
|
|
802
1298
|
);
|
|
803
1299
|
}, [natural, container, rotation]);
|
|
804
|
-
const cancelFlashTravel = (0,
|
|
1300
|
+
const cancelFlashTravel = (0, import_react2.useCallback)(() => {
|
|
805
1301
|
if (travelRafRef.current !== null) {
|
|
806
1302
|
cancelAnimationFrame(travelRafRef.current);
|
|
807
1303
|
travelRafRef.current = null;
|
|
808
1304
|
}
|
|
809
1305
|
}, []);
|
|
810
|
-
const zoomBy = (0,
|
|
1306
|
+
const zoomBy = (0, import_react2.useCallback)(
|
|
811
1307
|
(factor) => {
|
|
812
1308
|
const node = canvasRef.current;
|
|
813
1309
|
if (!node || !natural) return;
|
|
@@ -820,9 +1316,9 @@ function VerificationViewer(props) {
|
|
|
820
1316
|
},
|
|
821
1317
|
[natural, rotation, currentFitScale, cancelFlashTravel]
|
|
822
1318
|
);
|
|
823
|
-
const handleZoomIn = (0,
|
|
824
|
-
const handleZoomOut = (0,
|
|
825
|
-
const zoomAtClientPoint = (0,
|
|
1319
|
+
const handleZoomIn = (0, import_react2.useCallback)(() => zoomBy(ZOOM_STEP), [zoomBy]);
|
|
1320
|
+
const handleZoomOut = (0, import_react2.useCallback)(() => zoomBy(1 / ZOOM_STEP), [zoomBy]);
|
|
1321
|
+
const zoomAtClientPoint = (0, import_react2.useCallback)(
|
|
826
1322
|
(factor, clientX, clientY) => {
|
|
827
1323
|
const node = canvasRef.current;
|
|
828
1324
|
if (!node || !natural) return;
|
|
@@ -834,7 +1330,7 @@ function VerificationViewer(props) {
|
|
|
834
1330
|
},
|
|
835
1331
|
[natural, rotation, currentFitScale]
|
|
836
1332
|
);
|
|
837
|
-
const handleWheel = (0,
|
|
1333
|
+
const handleWheel = (0, import_react2.useCallback)(
|
|
838
1334
|
(event) => {
|
|
839
1335
|
event.preventDefault();
|
|
840
1336
|
event.stopPropagation();
|
|
@@ -844,7 +1340,7 @@ function VerificationViewer(props) {
|
|
|
844
1340
|
},
|
|
845
1341
|
[zoomAtClientPoint, cancelFlashTravel]
|
|
846
1342
|
);
|
|
847
|
-
(0,
|
|
1343
|
+
(0, import_react2.useEffect)(() => {
|
|
848
1344
|
const node = canvasRef.current;
|
|
849
1345
|
if (!node) return;
|
|
850
1346
|
const listener = (event) => handleWheel(event);
|
|
@@ -852,7 +1348,7 @@ function VerificationViewer(props) {
|
|
|
852
1348
|
return () => node.removeEventListener("wheel", listener);
|
|
853
1349
|
}, [handleWheel]);
|
|
854
1350
|
const atFitScale = transform.scale <= currentFitScale() + 1e-3;
|
|
855
|
-
const handleMouseDown = (0,
|
|
1351
|
+
const handleMouseDown = (0, import_react2.useCallback)(
|
|
856
1352
|
(e) => {
|
|
857
1353
|
cancelFlashTravel();
|
|
858
1354
|
if (e.button !== 0) return;
|
|
@@ -863,7 +1359,7 @@ function VerificationViewer(props) {
|
|
|
863
1359
|
},
|
|
864
1360
|
[atFitScale, transform.tx, transform.ty, cancelFlashTravel]
|
|
865
1361
|
);
|
|
866
|
-
(0,
|
|
1362
|
+
(0, import_react2.useEffect)(() => {
|
|
867
1363
|
if (!isPanning) return;
|
|
868
1364
|
const onMove = (e) => {
|
|
869
1365
|
const start = panStart.current;
|
|
@@ -883,8 +1379,8 @@ function VerificationViewer(props) {
|
|
|
883
1379
|
document.removeEventListener("mouseup", onUp);
|
|
884
1380
|
};
|
|
885
1381
|
}, [isPanning]);
|
|
886
|
-
const touchState = (0,
|
|
887
|
-
const handleTouchStart = (0,
|
|
1382
|
+
const touchState = (0, import_react2.useRef)(null);
|
|
1383
|
+
const handleTouchStart = (0, import_react2.useCallback)(
|
|
888
1384
|
(e) => {
|
|
889
1385
|
cancelFlashTravel();
|
|
890
1386
|
const a = e.touches[0];
|
|
@@ -902,7 +1398,7 @@ function VerificationViewer(props) {
|
|
|
902
1398
|
},
|
|
903
1399
|
[atFitScale, transform.tx, transform.ty, cancelFlashTravel]
|
|
904
1400
|
);
|
|
905
|
-
const handleTouchMove = (0,
|
|
1401
|
+
const handleTouchMove = (0, import_react2.useCallback)(
|
|
906
1402
|
(e) => {
|
|
907
1403
|
const state = touchState.current;
|
|
908
1404
|
if (!state) return;
|
|
@@ -927,19 +1423,19 @@ function VerificationViewer(props) {
|
|
|
927
1423
|
},
|
|
928
1424
|
[zoomAtClientPoint]
|
|
929
1425
|
);
|
|
930
|
-
const handleTouchEnd = (0,
|
|
1426
|
+
const handleTouchEnd = (0, import_react2.useCallback)((e) => {
|
|
931
1427
|
if (e.touches.length === 0) touchState.current = null;
|
|
932
1428
|
}, []);
|
|
933
|
-
const handleCanvasMouseMove = (0,
|
|
1429
|
+
const handleCanvasMouseMove = (0, import_react2.useCallback)((e) => {
|
|
934
1430
|
const rect = canvasRef.current?.getBoundingClientRect();
|
|
935
1431
|
if (!rect) return;
|
|
936
1432
|
setShowMag(true);
|
|
937
1433
|
setMousePos({ x: e.clientX - rect.left, y: e.clientY - rect.top });
|
|
938
1434
|
}, []);
|
|
939
|
-
const handleCanvasMouseLeave = (0,
|
|
1435
|
+
const handleCanvasMouseLeave = (0, import_react2.useCallback)(() => {
|
|
940
1436
|
setShowMag(false);
|
|
941
1437
|
}, []);
|
|
942
|
-
const handleDoubleClick = (0,
|
|
1438
|
+
const handleDoubleClick = (0, import_react2.useCallback)(
|
|
943
1439
|
(e) => {
|
|
944
1440
|
cancelFlashTravel();
|
|
945
1441
|
if (!natural) return;
|
|
@@ -954,26 +1450,26 @@ function VerificationViewer(props) {
|
|
|
954
1450
|
},
|
|
955
1451
|
[natural, container, rotation, transform.scale, currentFitScale, zoomAtClientPoint, cancelFlashTravel]
|
|
956
1452
|
);
|
|
957
|
-
const handleFit = (0,
|
|
1453
|
+
const handleFit = (0, import_react2.useCallback)(() => {
|
|
958
1454
|
if (!natural) return;
|
|
959
1455
|
cancelFlashTravel();
|
|
960
1456
|
const fit = currentFitScale();
|
|
961
1457
|
setTransform({ scale: fit, ...centeredTranslation(natural, container, fit, rotation) });
|
|
962
1458
|
}, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
|
|
963
|
-
const handleActualSize = (0,
|
|
1459
|
+
const handleActualSize = (0, import_react2.useCallback)(() => {
|
|
964
1460
|
if (!natural) return;
|
|
965
1461
|
cancelFlashTravel();
|
|
966
1462
|
const target = clampScale(1, currentFitScale());
|
|
967
1463
|
setTransform({ scale: target, ...centeredTranslation(natural, container, target, rotation) });
|
|
968
1464
|
}, [natural, container, rotation, currentFitScale, cancelFlashTravel]);
|
|
969
|
-
const handleRotate = (0,
|
|
1465
|
+
const handleRotate = (0, import_react2.useCallback)(() => {
|
|
970
1466
|
setRotation((r) => (r + 90) % 360);
|
|
971
1467
|
}, []);
|
|
972
1468
|
const hasRects = relativeRects !== void 0 && relativeRects.length > 0;
|
|
973
|
-
(0,
|
|
1469
|
+
(0, import_react2.useEffect)(() => {
|
|
974
1470
|
if (!hasRects) setShowRects(false);
|
|
975
1471
|
}, [hasRects]);
|
|
976
|
-
(0,
|
|
1472
|
+
(0, import_react2.useEffect)(() => {
|
|
977
1473
|
if (!flashRects || flashRects.length === 0 || !natural || !container.w || !container.h) {
|
|
978
1474
|
setActiveFlashRects((prev) => prev === null ? prev : null);
|
|
979
1475
|
setFlashOpacity(0);
|
|
@@ -1044,71 +1540,72 @@ function VerificationViewer(props) {
|
|
|
1044
1540
|
const dy = mousePos.y - transform.ty;
|
|
1045
1541
|
const cxRaw = (cosA * dx + sinA * dy) / transform.scale;
|
|
1046
1542
|
const cyRaw = (-sinA * dx + cosA * dy) / transform.scale;
|
|
1047
|
-
const
|
|
1048
|
-
const clampedY = Math.max(0, Math.min(cyRaw, natural.h));
|
|
1543
|
+
const onImage = cxRaw >= 0 && cyRaw >= 0 && cxRaw <= natural.w && cyRaw <= natural.h;
|
|
1049
1544
|
const zoomScale = transform.scale * MAG_ZOOM;
|
|
1050
|
-
const px =
|
|
1051
|
-
const py =
|
|
1545
|
+
const px = cxRaw * zoomScale;
|
|
1546
|
+
const py = cyRaw * zoomScale;
|
|
1052
1547
|
const rotatedX = px * cosA - py * sinA;
|
|
1053
1548
|
const rotatedY = px * sinA + py * cosA;
|
|
1054
|
-
const translateX = MAG_RADIUS - rotatedX;
|
|
1055
|
-
const translateY = MAG_RADIUS - rotatedY;
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1549
|
+
const translateX = MAG_RADIUS - MAG_BORDER - rotatedX;
|
|
1550
|
+
const translateY = MAG_RADIUS - MAG_BORDER - rotatedY;
|
|
1551
|
+
if (onImage) {
|
|
1552
|
+
magnifier = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1553
|
+
"div",
|
|
1554
|
+
{
|
|
1555
|
+
className: "gemina-verification__magnifier",
|
|
1556
|
+
style: {
|
|
1557
|
+
width: MAG_RADIUS * 2,
|
|
1558
|
+
height: MAG_RADIUS * 2,
|
|
1559
|
+
top: mousePos.y - MAG_RADIUS,
|
|
1560
|
+
left: mousePos.x - MAG_RADIUS
|
|
1561
|
+
},
|
|
1562
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1563
|
+
"img",
|
|
1564
|
+
{
|
|
1565
|
+
src,
|
|
1566
|
+
alt: "",
|
|
1567
|
+
draggable: false,
|
|
1568
|
+
style: {
|
|
1569
|
+
position: "absolute",
|
|
1570
|
+
width: natural.w,
|
|
1571
|
+
height: natural.h,
|
|
1572
|
+
transformOrigin: "0 0",
|
|
1573
|
+
transform: `translate(${translateX}px, ${translateY}px) rotate(${rotation}deg) scale(${zoomScale})`
|
|
1574
|
+
}
|
|
1078
1575
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1576
|
+
)
|
|
1577
|
+
}
|
|
1578
|
+
);
|
|
1579
|
+
}
|
|
1083
1580
|
}
|
|
1084
|
-
return /* @__PURE__ */ (0,
|
|
1085
|
-
/* @__PURE__ */ (0,
|
|
1086
|
-
/* @__PURE__ */ (0,
|
|
1087
|
-
/* @__PURE__ */ (0,
|
|
1088
|
-
/* @__PURE__ */ (0,
|
|
1089
|
-
/* @__PURE__ */ (0,
|
|
1090
|
-
/* @__PURE__ */ (0,
|
|
1091
|
-
/* @__PURE__ */ (0,
|
|
1581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "gemina-verification__viewer", children: [
|
|
1582
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "gemina-verification__toolbar", children: [
|
|
1583
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Zoom out", onClick: handleZoomOut, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconZoomOut, {}) }),
|
|
1584
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Zoom in", onClick: handleZoomIn, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconZoomIn, {}) }),
|
|
1585
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Actual size (100%)", onClick: handleActualSize, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconActualSize, {}) }),
|
|
1586
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Fit to screen", onClick: handleFit, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconFit, {}) }),
|
|
1587
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ToolbarButton, { label: "Rotate 90 degrees", onClick: handleRotate, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconRotate, {}) }),
|
|
1588
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1092
1589
|
ToolbarButton,
|
|
1093
1590
|
{
|
|
1094
1591
|
label: "Toggle detection overlays",
|
|
1095
1592
|
pressed: showRects,
|
|
1096
1593
|
disabled: !hasRects,
|
|
1097
1594
|
onClick: () => setShowRects((prev) => !prev),
|
|
1098
|
-
children: /* @__PURE__ */ (0,
|
|
1595
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconOverlay, {})
|
|
1099
1596
|
}
|
|
1100
1597
|
),
|
|
1101
|
-
/* @__PURE__ */ (0,
|
|
1598
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1102
1599
|
ToolbarButton,
|
|
1103
1600
|
{
|
|
1104
1601
|
label: "Magnifier",
|
|
1105
1602
|
checked: magnifierOn,
|
|
1106
1603
|
onClick: () => setMagnifierOn((prev) => !prev),
|
|
1107
|
-
children: /* @__PURE__ */ (0,
|
|
1604
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IconMagnifier, {})
|
|
1108
1605
|
}
|
|
1109
1606
|
)
|
|
1110
1607
|
] }),
|
|
1111
|
-
/* @__PURE__ */ (0,
|
|
1608
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1112
1609
|
"div",
|
|
1113
1610
|
{
|
|
1114
1611
|
ref: canvasRef,
|
|
@@ -1125,7 +1622,7 @@ function VerificationViewer(props) {
|
|
|
1125
1622
|
onTouchEnd: handleTouchEnd,
|
|
1126
1623
|
onTouchCancel: handleTouchEnd,
|
|
1127
1624
|
children: [
|
|
1128
|
-
/* @__PURE__ */ (0,
|
|
1625
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
1129
1626
|
"div",
|
|
1130
1627
|
{
|
|
1131
1628
|
style: {
|
|
@@ -1137,7 +1634,7 @@ function VerificationViewer(props) {
|
|
|
1137
1634
|
willChange: "transform,left,top"
|
|
1138
1635
|
},
|
|
1139
1636
|
children: [
|
|
1140
|
-
/* @__PURE__ */ (0,
|
|
1637
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1141
1638
|
"img",
|
|
1142
1639
|
{
|
|
1143
1640
|
ref: imgRef,
|
|
@@ -1151,13 +1648,13 @@ function VerificationViewer(props) {
|
|
|
1151
1648
|
showRects && natural && relativeRects?.map((rect, idx) => {
|
|
1152
1649
|
const geometry = rectGeometry(rect, natural);
|
|
1153
1650
|
if (!geometry) return null;
|
|
1154
|
-
return /* @__PURE__ */ (0,
|
|
1651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1155
1652
|
"div",
|
|
1156
1653
|
{
|
|
1157
1654
|
className: "gemina-verification__rect",
|
|
1158
1655
|
style: geometry,
|
|
1159
1656
|
"aria-hidden": "true",
|
|
1160
|
-
children: /* @__PURE__ */ (0,
|
|
1657
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "gemina-verification__rect-badge", children: [
|
|
1161
1658
|
"#",
|
|
1162
1659
|
idx + 1
|
|
1163
1660
|
] })
|
|
@@ -1168,7 +1665,7 @@ function VerificationViewer(props) {
|
|
|
1168
1665
|
activeFlashRects && natural && activeFlashRects.map((rect, idx) => {
|
|
1169
1666
|
const geometry = rectGeometry(rect, natural);
|
|
1170
1667
|
if (!geometry) return null;
|
|
1171
|
-
return /* @__PURE__ */ (0,
|
|
1668
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1172
1669
|
"div",
|
|
1173
1670
|
{
|
|
1174
1671
|
className: "gemina-verification__flash-rect",
|
|
@@ -1189,7 +1686,7 @@ function VerificationViewer(props) {
|
|
|
1189
1686
|
}
|
|
1190
1687
|
|
|
1191
1688
|
// src/verification/form.tsx
|
|
1192
|
-
var
|
|
1689
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1193
1690
|
function ConfidenceDot(props) {
|
|
1194
1691
|
const { confidence } = props;
|
|
1195
1692
|
if (!confidence?.level) {
|
|
@@ -1215,93 +1712,156 @@ function ConfidenceDot(props) {
|
|
|
1215
1712
|
label = `${confidence.level} confidence`;
|
|
1216
1713
|
}
|
|
1217
1714
|
const reasons = confidence.reasons.map(formatLabel);
|
|
1218
|
-
const title = [label, ...reasons].join("\n");
|
|
1219
1715
|
const ariaLabel = reasons.length > 0 ? `${label}: ${reasons.join(", ")}` : label;
|
|
1220
|
-
|
|
1716
|
+
const tip = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1717
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("strong", { className: "gemina-verification__tip-title", children: label }),
|
|
1718
|
+
reasons.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "gemina-verification__tip-list", children: reasons.map((reason) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("li", { children: reason }, reason)) }) : null
|
|
1719
|
+
] });
|
|
1720
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: tip, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1221
1721
|
"span",
|
|
1222
1722
|
{
|
|
1223
1723
|
className: `gemina-verification__dot gemina-verification__dot--${variant}`,
|
|
1224
1724
|
role: "img",
|
|
1225
|
-
"aria-label": ariaLabel
|
|
1226
|
-
title
|
|
1725
|
+
"aria-label": ariaLabel
|
|
1227
1726
|
}
|
|
1228
|
-
);
|
|
1727
|
+
) });
|
|
1229
1728
|
}
|
|
1230
1729
|
function EyeButton(props) {
|
|
1231
1730
|
const { coordinates, onFlash } = props;
|
|
1232
1731
|
if (!coordinates) {
|
|
1233
1732
|
return null;
|
|
1234
1733
|
}
|
|
1235
|
-
return /* @__PURE__ */ (0,
|
|
1734
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: "Show on document", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1236
1735
|
"button",
|
|
1237
1736
|
{
|
|
1238
1737
|
type: "button",
|
|
1239
1738
|
className: "gemina-verification__eye",
|
|
1240
|
-
title: "Show on document",
|
|
1241
1739
|
"aria-label": "Show on document",
|
|
1242
1740
|
onClick: (event) => {
|
|
1243
1741
|
event.stopPropagation();
|
|
1244
1742
|
onFlash();
|
|
1245
1743
|
},
|
|
1246
|
-
children: /* @__PURE__ */ (0,
|
|
1744
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IconEye, {})
|
|
1247
1745
|
}
|
|
1248
|
-
);
|
|
1746
|
+
) });
|
|
1249
1747
|
}
|
|
1250
1748
|
function FieldInput(props) {
|
|
1251
|
-
const { binding, edit, onEdit, readOnly, ariaLabel } = props;
|
|
1252
|
-
const
|
|
1749
|
+
const { binding, edit, onEdit, readOnly, ariaLabel, pairError } = props;
|
|
1750
|
+
const editKey = props.editKey ?? binding.key.raw;
|
|
1751
|
+
const editedBadgeId = import_react3.default.useId();
|
|
1752
|
+
const errorId = import_react3.default.useId();
|
|
1753
|
+
const currencyListId = import_react3.default.useId();
|
|
1253
1754
|
if (readOnly || !binding.editable) {
|
|
1254
1755
|
const display = binding.extracted === NOT_FOUND ? null : binding.extracted;
|
|
1255
|
-
return /* @__PURE__ */ (0,
|
|
1756
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(display, binding.key.label) });
|
|
1256
1757
|
}
|
|
1257
1758
|
const dirty = edit !== void 0;
|
|
1258
1759
|
const missed = binding.serverValue === NOT_FOUND;
|
|
1760
|
+
const field = binding.field;
|
|
1761
|
+
const value = dirty ? edit : toInputString(binding.extracted);
|
|
1762
|
+
const error = pairError ?? (dirty ? validateInput(value, field) : null);
|
|
1259
1763
|
const className = [
|
|
1260
1764
|
"gemina-verification__input",
|
|
1261
1765
|
dirty ? "gemina-verification__input--dirty" : "",
|
|
1262
|
-
missed ? "gemina-verification__input--missed" : ""
|
|
1766
|
+
missed ? "gemina-verification__input--missed" : "",
|
|
1767
|
+
error ? "gemina-verification__input--invalid" : ""
|
|
1263
1768
|
].filter(Boolean).join(" ");
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1769
|
+
const describedBy = [dirty ? editedBadgeId : "", error ? errorId : ""].filter(Boolean).join(" ");
|
|
1770
|
+
const shared = {
|
|
1771
|
+
className,
|
|
1772
|
+
"aria-label": ariaLabel,
|
|
1773
|
+
"aria-describedby": describedBy || void 0,
|
|
1774
|
+
"aria-invalid": error ? true : void 0,
|
|
1775
|
+
onChange: (event) => onEdit(editKey, event.target.value, binding)
|
|
1776
|
+
};
|
|
1777
|
+
const roster = field?.enum && field.enum.length > 0 ? field.enum : null;
|
|
1778
|
+
const offRoster = roster && value !== "" && !roster.includes(value) ? value : null;
|
|
1779
|
+
const control = roster ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { ...shared, value, dir: "auto", children: [
|
|
1780
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: "\u2014" }),
|
|
1781
|
+
offRoster ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("option", { value: offRoster, children: [
|
|
1782
|
+
offRoster,
|
|
1783
|
+
" (as extracted)"
|
|
1784
|
+
] }) : null,
|
|
1785
|
+
roster.map((option) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: option, children: option }, option))
|
|
1786
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1787
|
+
"input",
|
|
1788
|
+
{
|
|
1789
|
+
...shared,
|
|
1790
|
+
type: field?.type === "date" ? "date" : "text",
|
|
1791
|
+
dir: "auto",
|
|
1792
|
+
value,
|
|
1793
|
+
inputMode: field?.type === "number" || field?.type === "integer" ? "decimal" : void 0,
|
|
1794
|
+
list: field?.format === "iso4217" ? currencyListId : void 0,
|
|
1795
|
+
placeholder: missed ? "Not detected \u2014 fill in if present" : void 0,
|
|
1796
|
+
autoComplete: "off"
|
|
1797
|
+
}
|
|
1798
|
+
);
|
|
1799
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1800
|
+
control,
|
|
1801
|
+
field?.format === "iso4217" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("datalist", { id: currencyListId, children: ISO_4217_CODES.map((code) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: code }, code)) }) : null,
|
|
1802
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__field-error", id: errorId, role: "alert", children: error }) : null,
|
|
1803
|
+
dirty ? (
|
|
1804
|
+
// The badge is where the ORIGINAL belongs, now that the input holds
|
|
1805
|
+
// the edit — otherwise the extracted value is simply gone from the
|
|
1806
|
+
// screen the moment someone corrects it.
|
|
1807
|
+
//
|
|
1808
|
+
// Known limit: the badge is a non-focusable span, so this channel is
|
|
1809
|
+
// hover-only. AT is not worse off than before (nothing carried the
|
|
1810
|
+
// original previously), and the input's aria-describedby still names
|
|
1811
|
+
// the field as edited. Giving it a keyboard path needs a focusable
|
|
1812
|
+
// affordance, which belongs with the Phase 8 row work, not here.
|
|
1813
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1814
|
+
Tip,
|
|
1815
|
+
{
|
|
1816
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1817
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__tip-label", children: "Was: " }),
|
|
1818
|
+
formatValue(
|
|
1819
|
+
binding.extracted === NOT_FOUND ? null : binding.extracted,
|
|
1820
|
+
binding.key.label
|
|
1821
|
+
)
|
|
1822
|
+
] }),
|
|
1823
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__edited", id: editedBadgeId, children: "edited" })
|
|
1824
|
+
}
|
|
1825
|
+
)
|
|
1826
|
+
) : null
|
|
1280
1827
|
] });
|
|
1281
1828
|
}
|
|
1829
|
+
var NO_PAIR_ERRORS = /* @__PURE__ */ new Map();
|
|
1830
|
+
var NO_TABLES = [];
|
|
1831
|
+
var NO_PLANNED = /* @__PURE__ */ new Map();
|
|
1832
|
+
var NOOP_ROW = () => {
|
|
1833
|
+
};
|
|
1282
1834
|
function isInteractiveTarget(target) {
|
|
1283
1835
|
return target instanceof Element && target.closest("input, button, a, select, textarea") !== null;
|
|
1284
1836
|
}
|
|
1837
|
+
function FieldLabel(props) {
|
|
1838
|
+
const { label, description } = props;
|
|
1839
|
+
if (!description) {
|
|
1840
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: label });
|
|
1841
|
+
}
|
|
1842
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: description, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "gemina-verification__label-described", tabIndex: 0, children: label }) });
|
|
1843
|
+
}
|
|
1285
1844
|
function FieldPair(props) {
|
|
1286
1845
|
const { label, ariaLabel, cell, shared } = props;
|
|
1287
1846
|
const binding = shared.bindingIndex.get(cell.pointer);
|
|
1288
|
-
return /* @__PURE__ */ (0,
|
|
1289
|
-
/* @__PURE__ */ (0,
|
|
1290
|
-
/* @__PURE__ */ (0,
|
|
1291
|
-
/* @__PURE__ */ (0,
|
|
1847
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
1848
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dt", { className: "gemina-verification__dt", children: [
|
|
1849
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: cell.confidence }),
|
|
1850
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldLabel, { label, description: binding?.field?.description })
|
|
1292
1851
|
] }),
|
|
1293
|
-
/* @__PURE__ */ (0,
|
|
1294
|
-
binding !== void 0 ? /* @__PURE__ */ (0,
|
|
1852
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dd", { className: "gemina-verification__dd", children: [
|
|
1853
|
+
binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1295
1854
|
FieldInput,
|
|
1296
1855
|
{
|
|
1297
1856
|
binding,
|
|
1857
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1298
1858
|
edit: shared.edits.get(binding.key.raw),
|
|
1299
1859
|
onEdit: shared.onEdit,
|
|
1300
1860
|
readOnly: shared.readOnly,
|
|
1301
1861
|
ariaLabel
|
|
1302
1862
|
}
|
|
1303
|
-
) : /* @__PURE__ */ (0,
|
|
1304
|
-
/* @__PURE__ */ (0,
|
|
1863
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(cell.value, label) }),
|
|
1864
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1305
1865
|
EyeButton,
|
|
1306
1866
|
{
|
|
1307
1867
|
coordinates: cell.coordinates,
|
|
@@ -1320,10 +1880,10 @@ function HeaderSection(props) {
|
|
|
1320
1880
|
if (headers.length === 0 && simpleLists.length === 0) {
|
|
1321
1881
|
return null;
|
|
1322
1882
|
}
|
|
1323
|
-
return /* @__PURE__ */ (0,
|
|
1324
|
-
/* @__PURE__ */ (0,
|
|
1325
|
-
/* @__PURE__ */ (0,
|
|
1326
|
-
headers.map((field) => /* @__PURE__ */ (0,
|
|
1883
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Details", children: [
|
|
1884
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Details" }),
|
|
1885
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dl", { className: "gemina-verification__dl", children: [
|
|
1886
|
+
headers.map((field) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1327
1887
|
FieldPair,
|
|
1328
1888
|
{
|
|
1329
1889
|
label: formatLabel(field.key),
|
|
@@ -1333,23 +1893,24 @@ function HeaderSection(props) {
|
|
|
1333
1893
|
},
|
|
1334
1894
|
field.pointer
|
|
1335
1895
|
)),
|
|
1336
|
-
simpleLists.map((list) => /* @__PURE__ */ (0,
|
|
1337
|
-
/* @__PURE__ */ (0,
|
|
1338
|
-
/* @__PURE__ */ (0,
|
|
1896
|
+
simpleLists.map((list) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react3.default.Fragment, { children: [
|
|
1897
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatLabel(list.key) }) }),
|
|
1898
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "gemina-verification__list", children: list.items.map((item, index) => {
|
|
1339
1899
|
const binding = shared.bindingIndex.get(item.pointer);
|
|
1340
|
-
return /* @__PURE__ */ (0,
|
|
1341
|
-
binding !== void 0 ? /* @__PURE__ */ (0,
|
|
1900
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "gemina-verification__cell", children: [
|
|
1901
|
+
binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1342
1902
|
FieldInput,
|
|
1343
1903
|
{
|
|
1344
1904
|
binding,
|
|
1905
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1345
1906
|
edit: shared.edits.get(binding.key.raw),
|
|
1346
1907
|
onEdit: shared.onEdit,
|
|
1347
1908
|
readOnly: shared.readOnly,
|
|
1348
1909
|
ariaLabel: `${formatLabel(list.key)} item ${index + 1}`
|
|
1349
1910
|
}
|
|
1350
|
-
) : /* @__PURE__ */ (0,
|
|
1351
|
-
/* @__PURE__ */ (0,
|
|
1352
|
-
/* @__PURE__ */ (0,
|
|
1911
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: formatValue(item.value) }),
|
|
1912
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: item.confidence }),
|
|
1913
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1353
1914
|
EyeButton,
|
|
1354
1915
|
{
|
|
1355
1916
|
coordinates: item.coordinates,
|
|
@@ -1370,20 +1931,20 @@ function EntitySection(props) {
|
|
|
1370
1931
|
const { entity, shared } = props;
|
|
1371
1932
|
const label = formatLabel(entity.key);
|
|
1372
1933
|
const singular = label.replace(/s$/, "");
|
|
1373
|
-
return /* @__PURE__ */ (0,
|
|
1374
|
-
/* @__PURE__ */ (0,
|
|
1934
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
|
|
1935
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__section-header", children: [
|
|
1375
1936
|
label,
|
|
1376
1937
|
" (",
|
|
1377
1938
|
entity.items.length,
|
|
1378
1939
|
")"
|
|
1379
1940
|
] }),
|
|
1380
|
-
/* @__PURE__ */ (0,
|
|
1381
|
-
/* @__PURE__ */ (0,
|
|
1941
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: entity.items.map((item, itemIndex) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card", children: [
|
|
1942
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__card-header", children: [
|
|
1382
1943
|
singular,
|
|
1383
1944
|
" ",
|
|
1384
1945
|
itemIndex + 1
|
|
1385
1946
|
] }),
|
|
1386
|
-
/* @__PURE__ */ (0,
|
|
1947
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: Object.entries(item).map(([fieldKey, cell]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1387
1948
|
FieldPair,
|
|
1388
1949
|
{
|
|
1389
1950
|
label: formatLabel(fieldKey),
|
|
@@ -1397,18 +1958,18 @@ function EntitySection(props) {
|
|
|
1397
1958
|
] });
|
|
1398
1959
|
}
|
|
1399
1960
|
function TableRowView(props) {
|
|
1400
|
-
const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared } = props;
|
|
1961
|
+
const { row, rowIndex, columns, tableLabel, hasCoords, hasRowConfidence, shared, planned, tablePointer } = props;
|
|
1401
1962
|
const { bindingIndex, edits, onEdit, readOnly, onFlash } = shared;
|
|
1402
|
-
const rects =
|
|
1963
|
+
const rects = import_react3.default.useMemo(() => {
|
|
1403
1964
|
const collected = [];
|
|
1404
|
-
for (const [key, cell] of Object.entries(row)) {
|
|
1965
|
+
for (const [key, cell] of Object.entries(row ?? {})) {
|
|
1405
1966
|
if (key !== ROW_META_KEY && cell.coordinates) {
|
|
1406
1967
|
collected.push(cell.coordinates);
|
|
1407
1968
|
}
|
|
1408
1969
|
}
|
|
1409
1970
|
return collected;
|
|
1410
1971
|
}, [row]);
|
|
1411
|
-
const handleRowClick =
|
|
1972
|
+
const handleRowClick = import_react3.default.useCallback(
|
|
1412
1973
|
(event) => {
|
|
1413
1974
|
if (isInteractiveTarget(event.target)) {
|
|
1414
1975
|
return;
|
|
@@ -1419,81 +1980,199 @@ function TableRowView(props) {
|
|
|
1419
1980
|
},
|
|
1420
1981
|
[rects, onFlash]
|
|
1421
1982
|
);
|
|
1983
|
+
const cellFor = (column) => {
|
|
1984
|
+
const classified = row?.[column];
|
|
1985
|
+
const fromPlan = planned?.cells.find((cell) => cell.column === column);
|
|
1986
|
+
if (fromPlan) {
|
|
1987
|
+
return { classified, binding: fromPlan.binding, editKey: fromPlan.editKey };
|
|
1988
|
+
}
|
|
1989
|
+
const binding = classified === void 0 ? void 0 : bindingIndex.get(classified.pointer);
|
|
1990
|
+
return { classified, binding, editKey: binding?.key.raw };
|
|
1991
|
+
};
|
|
1422
1992
|
const firstRect = rects.length > 0 ? rects[0] : null;
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1993
|
+
const showControls = planned !== void 0 && tablePointer !== void 0 && !readOnly;
|
|
1994
|
+
const rowLevel = (row?.[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
|
|
1995
|
+
const rowClass = rowLevel === "low" || rowLevel === "medium" ? `gemina-verification__row--${rowLevel}` : void 0;
|
|
1996
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { onClick: handleRowClick, className: rowClass, children: [
|
|
1997
|
+
hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(EyeButton, { coordinates: firstRect, onFlash: () => onFlash(rects) }) }) : null,
|
|
1998
|
+
hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: row?.[ROW_META_KEY]?.confidence ?? null }) }) : null,
|
|
1426
1999
|
columns.map((column) => {
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2000
|
+
const { classified, binding, editKey } = cellFor(column);
|
|
2001
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__cell", children: [
|
|
2002
|
+
binding !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1431
2003
|
FieldInput,
|
|
1432
2004
|
{
|
|
1433
2005
|
binding,
|
|
1434
|
-
|
|
2006
|
+
editKey,
|
|
2007
|
+
pairError: editKey === void 0 ? void 0 : shared.pairErrors.get(editKey),
|
|
2008
|
+
edit: editKey === void 0 ? void 0 : edits.get(editKey),
|
|
1435
2009
|
onEdit,
|
|
1436
2010
|
readOnly,
|
|
1437
2011
|
ariaLabel: `${tableLabel} row ${rowIndex + 1} \u2014 ${formatLabel(column)}`
|
|
1438
2012
|
}
|
|
1439
|
-
) : /* @__PURE__ */ (0,
|
|
1440
|
-
/* @__PURE__ */ (0,
|
|
2013
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: classified === void 0 ? "-" : formatValue(classified.value, column) }),
|
|
2014
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: classified?.confidence ?? null })
|
|
1441
2015
|
] }) }, column);
|
|
1442
|
-
})
|
|
2016
|
+
}),
|
|
2017
|
+
showControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("td", { className: "gemina-verification__row-actions", children: [
|
|
2018
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: "Insert a line below", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2019
|
+
"button",
|
|
2020
|
+
{
|
|
2021
|
+
type: "button",
|
|
2022
|
+
className: "gemina-verification__row-btn",
|
|
2023
|
+
"aria-label": `Insert line below line ${rowIndex + 1}`,
|
|
2024
|
+
onClick: () => shared.onAddRow(tablePointer, rowIndex),
|
|
2025
|
+
children: "+"
|
|
2026
|
+
}
|
|
2027
|
+
) }),
|
|
2028
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tip, { content: "Remove this line", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2029
|
+
"button",
|
|
2030
|
+
{
|
|
2031
|
+
type: "button",
|
|
2032
|
+
className: "gemina-verification__row-btn",
|
|
2033
|
+
"aria-label": `Remove line ${rowIndex + 1}`,
|
|
2034
|
+
onClick: () => shared.onRemoveRow(tablePointer, rowIndex),
|
|
2035
|
+
children: "\xD7"
|
|
2036
|
+
}
|
|
2037
|
+
) })
|
|
2038
|
+
] }) : null
|
|
1443
2039
|
] });
|
|
1444
2040
|
}
|
|
1445
2041
|
function areRowPropsEqual(prev, next) {
|
|
1446
|
-
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) {
|
|
2042
|
+
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) {
|
|
1447
2043
|
return false;
|
|
1448
2044
|
}
|
|
1449
2045
|
if (prev.shared.edits === next.shared.edits) {
|
|
1450
2046
|
return true;
|
|
1451
2047
|
}
|
|
1452
2048
|
for (const column of next.columns) {
|
|
1453
|
-
const
|
|
1454
|
-
const
|
|
1455
|
-
|
|
2049
|
+
const planned = next.planned?.cells.find((cell) => cell.column === column);
|
|
2050
|
+
const classified = next.row?.[column];
|
|
2051
|
+
const editKey = planned?.editKey ?? (classified === void 0 ? void 0 : next.shared.bindingIndex.get(classified.pointer)?.key.raw);
|
|
2052
|
+
if (editKey === void 0) {
|
|
2053
|
+
continue;
|
|
2054
|
+
}
|
|
2055
|
+
if (prev.shared.edits.get(editKey) !== next.shared.edits.get(editKey) || prev.shared.pairErrors.get(editKey) !== next.shared.pairErrors.get(editKey)) {
|
|
1456
2056
|
return false;
|
|
1457
2057
|
}
|
|
1458
2058
|
}
|
|
1459
2059
|
return true;
|
|
1460
2060
|
}
|
|
1461
|
-
var TableRow =
|
|
2061
|
+
var TableRow = import_react3.default.memo(TableRowView, areRowPropsEqual);
|
|
2062
|
+
function withEmptyMutableTables(classified, tables) {
|
|
2063
|
+
if (tables.length === 0) {
|
|
2064
|
+
return { tables: classified.tables, suppressed: EMPTY_SUPPRESSED };
|
|
2065
|
+
}
|
|
2066
|
+
const promoted = [...classified.tables];
|
|
2067
|
+
const suppressed = /* @__PURE__ */ new Set();
|
|
2068
|
+
for (const table of tables) {
|
|
2069
|
+
if (classified.tables.some((candidate) => matchesTablePointer(table.pointer, candidate.pointer))) {
|
|
2070
|
+
continue;
|
|
2071
|
+
}
|
|
2072
|
+
const header = classified.headers.find(
|
|
2073
|
+
(candidate) => matchesTablePointer(table.pointer, candidate.pointer)
|
|
2074
|
+
);
|
|
2075
|
+
const empty = header !== void 0 && (header.value === null || Array.isArray(header.value) && header.value.length === 0);
|
|
2076
|
+
if (!empty) {
|
|
2077
|
+
continue;
|
|
2078
|
+
}
|
|
2079
|
+
suppressed.add(header.pointer);
|
|
2080
|
+
promoted.push({
|
|
2081
|
+
key: header.key,
|
|
2082
|
+
pointer: header.pointer,
|
|
2083
|
+
columns: [],
|
|
2084
|
+
rows: [],
|
|
2085
|
+
overallConfidence: null
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
return { tables: promoted, suppressed };
|
|
2089
|
+
}
|
|
2090
|
+
var EMPTY_SUPPRESSED = /* @__PURE__ */ new Set();
|
|
1462
2091
|
function TableSection(props) {
|
|
1463
2092
|
const { table, shared } = props;
|
|
1464
2093
|
const label = formatLabel(table.key);
|
|
1465
|
-
const
|
|
2094
|
+
const mutable = import_react3.default.useMemo(
|
|
2095
|
+
() => shared.rowMutableTables.find((entry) => matchesTablePointer(entry.pointer, table.pointer)),
|
|
2096
|
+
[shared.rowMutableTables, table.pointer]
|
|
2097
|
+
);
|
|
2098
|
+
const columns = import_react3.default.useMemo(
|
|
2099
|
+
() => mutable ? displayColumns(mutable, table.columns) : table.columns,
|
|
2100
|
+
[mutable, table.columns]
|
|
2101
|
+
);
|
|
2102
|
+
const planned = mutable ? shared.plannedTables.get(mutable.pointer) : void 0;
|
|
2103
|
+
const hasCoords = import_react3.default.useMemo(
|
|
1466
2104
|
() => table.rows.some(
|
|
1467
2105
|
(row) => Object.entries(row).some(([key, cell]) => key !== ROW_META_KEY && cell.coordinates !== null)
|
|
1468
2106
|
),
|
|
1469
2107
|
[table]
|
|
1470
2108
|
);
|
|
1471
|
-
const hasRowConfidence =
|
|
2109
|
+
const hasRowConfidence = import_react3.default.useMemo(
|
|
1472
2110
|
() => table.rows.some((row) => Boolean(row[ROW_META_KEY]?.confidence?.level)),
|
|
1473
2111
|
[table]
|
|
1474
2112
|
);
|
|
1475
|
-
|
|
1476
|
-
/* @__PURE__ */ (
|
|
1477
|
-
|
|
2113
|
+
const columnDescriptions = import_react3.default.useMemo(() => {
|
|
2114
|
+
const map = /* @__PURE__ */ new Map();
|
|
2115
|
+
for (const column of mutable?.columns ?? []) {
|
|
2116
|
+
if (typeof column.key === "string" && column.description) {
|
|
2117
|
+
map.set(column.key, column.description);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
return map;
|
|
2121
|
+
}, [mutable]);
|
|
2122
|
+
const rowCount = planned ? planned.length : table.rows.length;
|
|
2123
|
+
const needsReview = import_react3.default.useMemo(
|
|
2124
|
+
() => table.rows.filter((row) => {
|
|
2125
|
+
const level = (row[ROW_META_KEY]?.confidence?.level ?? "").toLowerCase();
|
|
2126
|
+
return level === "low" || level === "medium";
|
|
2127
|
+
}).length,
|
|
2128
|
+
[table.rows]
|
|
2129
|
+
);
|
|
2130
|
+
const showControls = planned !== void 0 && mutable !== void 0 && !shared.readOnly;
|
|
2131
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": label, children: [
|
|
2132
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "gemina-verification__section-header", children: [
|
|
2133
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
|
|
1478
2134
|
label,
|
|
1479
2135
|
" (",
|
|
1480
|
-
|
|
1481
|
-
" rows
|
|
2136
|
+
rowCount,
|
|
2137
|
+
" rows",
|
|
2138
|
+
needsReview > 0 ? ` \xB7 ${needsReview} need review` : "",
|
|
2139
|
+
")"
|
|
1482
2140
|
] }),
|
|
1483
|
-
/* @__PURE__ */ (0,
|
|
2141
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConfidenceDot, { confidence: table.overallConfidence })
|
|
1484
2142
|
] }),
|
|
1485
|
-
/* @__PURE__ */ (0,
|
|
1486
|
-
/* @__PURE__ */ (0,
|
|
1487
|
-
hasCoords ? /* @__PURE__ */ (0,
|
|
1488
|
-
hasRowConfidence ? /* @__PURE__ */ (0,
|
|
1489
|
-
|
|
2143
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__table-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { className: "gemina-verification__table", children: [
|
|
2144
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
|
|
2145
|
+
hasCoords ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { "aria-label": "Show row on document" }) : null,
|
|
2146
|
+
hasRowConfidence ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { "aria-label": "Row confidence" }) : null,
|
|
2147
|
+
columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2148
|
+
FieldLabel,
|
|
2149
|
+
{
|
|
2150
|
+
label: formatLabel(column),
|
|
2151
|
+
description: columnDescriptions.get(column)
|
|
2152
|
+
}
|
|
2153
|
+
) }, column)),
|
|
2154
|
+
showControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { "aria-label": "Row actions" }) : null
|
|
1490
2155
|
] }) }),
|
|
1491
|
-
/* @__PURE__ */ (0,
|
|
2156
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: planned ? planned.map((plannedRow, position) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2157
|
+
TableRow,
|
|
2158
|
+
{
|
|
2159
|
+
row: plannedRow.entry.source === null ? void 0 : table.rows[plannedRow.entry.source],
|
|
2160
|
+
rowIndex: position,
|
|
2161
|
+
columns,
|
|
2162
|
+
tableLabel: label,
|
|
2163
|
+
hasCoords,
|
|
2164
|
+
hasRowConfidence,
|
|
2165
|
+
shared,
|
|
2166
|
+
planned: plannedRow,
|
|
2167
|
+
tablePointer: mutable.pointer
|
|
2168
|
+
},
|
|
2169
|
+
plannedRow.entry.id
|
|
2170
|
+
)) : table.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1492
2171
|
TableRow,
|
|
1493
2172
|
{
|
|
1494
2173
|
row,
|
|
1495
2174
|
rowIndex,
|
|
1496
|
-
columns
|
|
2175
|
+
columns,
|
|
1497
2176
|
tableLabel: label,
|
|
1498
2177
|
hasCoords,
|
|
1499
2178
|
hasRowConfidence,
|
|
@@ -1501,19 +2180,28 @@ function TableSection(props) {
|
|
|
1501
2180
|
},
|
|
1502
2181
|
rowIndex
|
|
1503
2182
|
)) })
|
|
1504
|
-
] }) })
|
|
2183
|
+
] }) }),
|
|
2184
|
+
showControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__table-footer", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2185
|
+
"button",
|
|
2186
|
+
{
|
|
2187
|
+
type: "button",
|
|
2188
|
+
className: "gemina-verification__add-row",
|
|
2189
|
+
onClick: () => shared.onAddRow(mutable.pointer, rowCount - 1),
|
|
2190
|
+
children: "Add line"
|
|
2191
|
+
}
|
|
2192
|
+
) }) : null
|
|
1505
2193
|
] });
|
|
1506
2194
|
}
|
|
1507
|
-
var FallbackSection =
|
|
2195
|
+
var FallbackSection = import_react3.default.memo(function FallbackSection2(props) {
|
|
1508
2196
|
const { fallback } = props;
|
|
1509
2197
|
if (fallback.length === 0) {
|
|
1510
2198
|
return null;
|
|
1511
2199
|
}
|
|
1512
|
-
return /* @__PURE__ */ (0,
|
|
1513
|
-
/* @__PURE__ */ (0,
|
|
1514
|
-
/* @__PURE__ */ (0,
|
|
1515
|
-
/* @__PURE__ */ (0,
|
|
1516
|
-
/* @__PURE__ */ (0,
|
|
2200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Additional Data", children: [
|
|
2201
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Additional Data" }),
|
|
2202
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-body", children: fallback.map((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: "gemina-verification__fallback", children: [
|
|
2203
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: formatLabel(item.key) }),
|
|
2204
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { children: JSON.stringify(item.data, null, 2) })
|
|
1517
2205
|
] }, item.key)) })
|
|
1518
2206
|
] });
|
|
1519
2207
|
});
|
|
@@ -1522,14 +2210,15 @@ function UnmatchedSection(props) {
|
|
|
1522
2210
|
if (unmatched.length === 0) {
|
|
1523
2211
|
return null;
|
|
1524
2212
|
}
|
|
1525
|
-
return /* @__PURE__ */ (0,
|
|
1526
|
-
/* @__PURE__ */ (0,
|
|
1527
|
-
/* @__PURE__ */ (0,
|
|
1528
|
-
/* @__PURE__ */ (0,
|
|
1529
|
-
/* @__PURE__ */ (0,
|
|
2213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "gemina-verification__section", "aria-label": "Not detected", children: [
|
|
2214
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "gemina-verification__section-header", children: "Not detected" }),
|
|
2215
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "gemina-verification__dl", children: unmatched.map((binding) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react3.default.Fragment, { children: [
|
|
2216
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dt", { className: "gemina-verification__dt", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: binding.key.label }) }),
|
|
2217
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "gemina-verification__dd", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1530
2218
|
FieldInput,
|
|
1531
2219
|
{
|
|
1532
2220
|
binding,
|
|
2221
|
+
pairError: shared.pairErrors.get(binding.key.raw),
|
|
1533
2222
|
edit: shared.edits.get(binding.key.raw),
|
|
1534
2223
|
onEdit: shared.onEdit,
|
|
1535
2224
|
readOnly: shared.readOnly,
|
|
@@ -1540,26 +2229,61 @@ function UnmatchedSection(props) {
|
|
|
1540
2229
|
] });
|
|
1541
2230
|
}
|
|
1542
2231
|
function VerificationForm(props) {
|
|
1543
|
-
const {
|
|
1544
|
-
|
|
2232
|
+
const {
|
|
2233
|
+
classified,
|
|
2234
|
+
unmatched,
|
|
2235
|
+
bindingIndex,
|
|
2236
|
+
edits,
|
|
2237
|
+
onEdit,
|
|
2238
|
+
readOnly,
|
|
2239
|
+
onFlash,
|
|
2240
|
+
pairErrors,
|
|
2241
|
+
rowMutableTables,
|
|
2242
|
+
plannedTables,
|
|
2243
|
+
onAddRow,
|
|
2244
|
+
onRemoveRow
|
|
2245
|
+
} = props;
|
|
2246
|
+
const { tables: promotedTables, suppressed } = import_react3.default.useMemo(
|
|
2247
|
+
() => withEmptyMutableTables(classified, rowMutableTables ?? NO_TABLES),
|
|
2248
|
+
[classified, rowMutableTables]
|
|
2249
|
+
);
|
|
2250
|
+
const shared = {
|
|
2251
|
+
bindingIndex,
|
|
2252
|
+
edits,
|
|
2253
|
+
onEdit,
|
|
2254
|
+
readOnly,
|
|
2255
|
+
onFlash,
|
|
2256
|
+
pairErrors: pairErrors ?? NO_PAIR_ERRORS,
|
|
2257
|
+
rowMutableTables: rowMutableTables ?? NO_TABLES,
|
|
2258
|
+
plannedTables: plannedTables ?? NO_PLANNED,
|
|
2259
|
+
onAddRow: onAddRow ?? NOOP_ROW,
|
|
2260
|
+
onRemoveRow: onRemoveRow ?? NOOP_ROW
|
|
2261
|
+
};
|
|
1545
2262
|
return (
|
|
1546
2263
|
// A real, labeled <form> (role "form" landmark): AT users can jump
|
|
1547
2264
|
// straight to the editable fields. Submission is owned by the root's
|
|
1548
2265
|
// footer button, never by the form element itself — preventDefault stops
|
|
1549
2266
|
// implicit submission (Enter in a payload with exactly one input would
|
|
1550
2267
|
// otherwise navigate).
|
|
1551
|
-
/* @__PURE__ */ (0,
|
|
2268
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1552
2269
|
"form",
|
|
1553
2270
|
{
|
|
1554
2271
|
className: "gemina-verification__form",
|
|
1555
2272
|
"aria-label": "Extraction fields",
|
|
1556
2273
|
onSubmit: (event) => event.preventDefault(),
|
|
1557
2274
|
children: [
|
|
1558
|
-
/* @__PURE__ */ (0,
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
2275
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2276
|
+
HeaderSection,
|
|
2277
|
+
{
|
|
2278
|
+
headers: classified.headers.filter((header) => !suppressed.has(header.pointer)),
|
|
2279
|
+
simpleLists: classified.simpleLists,
|
|
2280
|
+
shared
|
|
2281
|
+
}
|
|
2282
|
+
),
|
|
2283
|
+
classified.entities.map((entity) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(EntitySection, { entity, shared }, entity.pointer)),
|
|
2284
|
+
promotedTables.map((table) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TableSection, { table, shared }, table.pointer)),
|
|
2285
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FallbackSection, { fallback: classified.fallback }),
|
|
2286
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(UnmatchedSection, { unmatched, shared })
|
|
1563
2287
|
]
|
|
1564
2288
|
}
|
|
1565
2289
|
)
|
|
@@ -1567,7 +2291,7 @@ function VerificationForm(props) {
|
|
|
1567
2291
|
}
|
|
1568
2292
|
|
|
1569
2293
|
// src/version.ts
|
|
1570
|
-
var VERSION = "0.
|
|
2294
|
+
var VERSION = "0.9.0";
|
|
1571
2295
|
|
|
1572
2296
|
// src/verification/styles.ts
|
|
1573
2297
|
var DARK_VARS = `
|
|
@@ -1826,6 +2550,10 @@ var VERIFICATION_CSS = `
|
|
|
1826
2550
|
}
|
|
1827
2551
|
.gemina-verification__dd {
|
|
1828
2552
|
display: flex;
|
|
2553
|
+
/* Wrap so a field error takes its OWN line (it sets flex-basis:100%).
|
|
2554
|
+
Without this it competes with the input for width, and at 390px the
|
|
2555
|
+
message wrapped to one word per line while the input shrank to ~55px. */
|
|
2556
|
+
flex-wrap: wrap;
|
|
1829
2557
|
align-items: center;
|
|
1830
2558
|
gap: 6px;
|
|
1831
2559
|
margin: 0; /* resets the UA's margin-inline-start on <dd> */
|
|
@@ -1900,6 +2628,7 @@ var VERIFICATION_CSS = `
|
|
|
1900
2628
|
and list items \u2014 the fragment has no container of its own. */
|
|
1901
2629
|
.gemina-verification__cell {
|
|
1902
2630
|
display: flex;
|
|
2631
|
+
flex-wrap: wrap; /* same reason as __dd: the field error needs its own line */
|
|
1903
2632
|
align-items: center;
|
|
1904
2633
|
gap: 6px;
|
|
1905
2634
|
min-width: 0;
|
|
@@ -2160,6 +2889,157 @@ var VERIFICATION_CSS = `
|
|
|
2160
2889
|
transition: none;
|
|
2161
2890
|
}
|
|
2162
2891
|
}
|
|
2892
|
+
|
|
2893
|
+
/* A label that carries a description. Dotted underline is the long-standing
|
|
2894
|
+
convention for "there is more here", and tabIndex makes it reachable, so the
|
|
2895
|
+
tooltip is not mouse-only. */
|
|
2896
|
+
.gemina-verification__label-described {
|
|
2897
|
+
text-decoration: underline dotted;
|
|
2898
|
+
text-underline-offset: 3px;
|
|
2899
|
+
cursor: help;
|
|
2900
|
+
}
|
|
2901
|
+
.gemina-verification__label-described:focus-visible {
|
|
2902
|
+
outline: 2px solid var(--gemina-verification-accent);
|
|
2903
|
+
outline-offset: 2px;
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
/* Rows worth a second look. Uses the EXISTING confidence tokens \u2014 no new
|
|
2907
|
+
colours \u2014 as a start-edge rule, which is the one edge a reviewer scans down
|
|
2908
|
+
a long table. Logical property, so it lands on the right side under RTL. */
|
|
2909
|
+
.gemina-verification__row--low > td:first-child,
|
|
2910
|
+
.gemina-verification__row--medium > td:first-child {
|
|
2911
|
+
border-inline-start: 3px solid transparent;
|
|
2912
|
+
}
|
|
2913
|
+
.gemina-verification__row--low > td:first-child {
|
|
2914
|
+
border-inline-start-color: var(--gemina-verification-confidence-low);
|
|
2915
|
+
}
|
|
2916
|
+
.gemina-verification__row--medium > td:first-child {
|
|
2917
|
+
border-inline-start-color: var(--gemina-verification-confidence-medium);
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
/* --- Row editing ----------------------------------------------------------
|
|
2921
|
+
Quiet by design: adding and removing lines is a correction, not the primary
|
|
2922
|
+
action, so the controls stay muted until hovered and the accent is left to
|
|
2923
|
+
Submit. */
|
|
2924
|
+
.gemina-verification__row-actions {
|
|
2925
|
+
white-space: nowrap;
|
|
2926
|
+
text-align: end; /* logical \u2014 RTL for free */
|
|
2927
|
+
}
|
|
2928
|
+
.gemina-verification__row-btn {
|
|
2929
|
+
font: inherit;
|
|
2930
|
+
line-height: 1;
|
|
2931
|
+
padding: 2px 7px;
|
|
2932
|
+
margin-inline-start: 4px;
|
|
2933
|
+
border-radius: calc(var(--gemina-verification-radius) - 5px);
|
|
2934
|
+
border: 1px solid var(--gemina-verification-border);
|
|
2935
|
+
background: transparent;
|
|
2936
|
+
color: var(--gemina-verification-muted);
|
|
2937
|
+
cursor: pointer;
|
|
2938
|
+
transition: border-color 120ms ease, color 120ms ease;
|
|
2939
|
+
}
|
|
2940
|
+
.gemina-verification__row-btn:hover {
|
|
2941
|
+
border-color: var(--gemina-verification-accent);
|
|
2942
|
+
color: var(--gemina-verification-fg);
|
|
2943
|
+
}
|
|
2944
|
+
.gemina-verification__table-footer {
|
|
2945
|
+
display: flex;
|
|
2946
|
+
padding: 8px 10px 0;
|
|
2947
|
+
}
|
|
2948
|
+
.gemina-verification__add-row {
|
|
2949
|
+
font: inherit;
|
|
2950
|
+
font-size: 12px;
|
|
2951
|
+
padding: 4px 10px;
|
|
2952
|
+
border-radius: calc(var(--gemina-verification-radius) - 4px);
|
|
2953
|
+
border: 1px dashed var(--gemina-verification-border);
|
|
2954
|
+
background: transparent;
|
|
2955
|
+
color: var(--gemina-verification-muted);
|
|
2956
|
+
cursor: pointer;
|
|
2957
|
+
}
|
|
2958
|
+
.gemina-verification__add-row:hover {
|
|
2959
|
+
border-style: solid;
|
|
2960
|
+
border-color: var(--gemina-verification-accent);
|
|
2961
|
+
color: var(--gemina-verification-fg);
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
/* --- Typed controls -------------------------------------------------------
|
|
2965
|
+
A <select> for a closed roster must sit on the same baseline as the text
|
|
2966
|
+
inputs beside it in a table row, so it inherits the input's box entirely and
|
|
2967
|
+
only overrides what a select needs. */
|
|
2968
|
+
.gemina-verification__input:is(select) {
|
|
2969
|
+
cursor: pointer;
|
|
2970
|
+
/* A select's intrinsic width follows its longest option \u2014 the 24-member unit
|
|
2971
|
+
roster would blow out the column. */
|
|
2972
|
+
max-width: 100%;
|
|
2973
|
+
}
|
|
2974
|
+
/* The error border must beat --dirty and --missed: an invalid value is the
|
|
2975
|
+
most urgent thing true about the field, and the reviewer cannot submit
|
|
2976
|
+
until it is fixed. Placed after both for cascade order. */
|
|
2977
|
+
.gemina-verification__input--invalid,
|
|
2978
|
+
.gemina-verification__input--invalid:focus-visible {
|
|
2979
|
+
border-color: var(--gemina-verification-error);
|
|
2980
|
+
}
|
|
2981
|
+
/* Sits under the control it describes. Basis 100% breaks it onto its own line
|
|
2982
|
+
inside the flex row FieldInput renders into, so it never squeezes the
|
|
2983
|
+
input. */
|
|
2984
|
+
.gemina-verification__field-error {
|
|
2985
|
+
flex-basis: 100%;
|
|
2986
|
+
margin-block-start: 4px;
|
|
2987
|
+
color: var(--gemina-verification-error);
|
|
2988
|
+
font-size: 12px;
|
|
2989
|
+
line-height: 1.35;
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
/* Replaces __progress while anything is invalid \u2014 same slot, so the footer
|
|
2993
|
+
never grows a second status line competing for the same attention. */
|
|
2994
|
+
.gemina-verification__attention {
|
|
2995
|
+
color: var(--gemina-verification-error);
|
|
2996
|
+
font-size: 13px;
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
/* --- Tooltip -------------------------------------------------------------
|
|
3000
|
+
Renders in a portal on document.body, inside a div carrying the root's
|
|
3001
|
+
class list \u2014 so these rules and every --gemina-verification-* custom
|
|
3002
|
+
property resolve exactly as they do in the component.
|
|
3003
|
+
|
|
3004
|
+
Quieter than __confirm-dialog on purpose: an annotation, not a decision.
|
|
3005
|
+
Same border and shadow family, one step down in radius (the nested-element
|
|
3006
|
+
convention used by __chip et al), surface rather than bg so it separates
|
|
3007
|
+
from the panel it floats over, and a shorter shadow so it reads as sitting
|
|
3008
|
+
just above the page rather than over a scrim. */
|
|
3009
|
+
.gemina-verification__tip {
|
|
3010
|
+
position: fixed;
|
|
3011
|
+
z-index: 2147483000; /* above the host's own modal \u2014 this is the topmost layer */
|
|
3012
|
+
max-width: 260px; /* ~60 characters: past that a tooltip should be body copy */
|
|
3013
|
+
padding: 8px 10px;
|
|
3014
|
+
background: var(--gemina-verification-surface);
|
|
3015
|
+
color: var(--gemina-verification-fg);
|
|
3016
|
+
border: 1px solid var(--gemina-verification-border);
|
|
3017
|
+
border-radius: calc(var(--gemina-verification-radius) - 4px);
|
|
3018
|
+
box-shadow: 0 6px 16px rgba(16, 20, 24, 0.18);
|
|
3019
|
+
font-family: var(--gemina-verification-font);
|
|
3020
|
+
font-size: 12px;
|
|
3021
|
+
line-height: 1.45;
|
|
3022
|
+
text-align: start; /* logical \u2014 RTL for free */
|
|
3023
|
+
pointer-events: none; /* never eat the hover that opened it */
|
|
3024
|
+
}
|
|
3025
|
+
/* Structured content: a level heading over a reasons list. The list is the
|
|
3026
|
+
reason this exists at all \u2014 title= could only ever have been one line. */
|
|
3027
|
+
.gemina-verification__tip-title {
|
|
3028
|
+
display: block;
|
|
3029
|
+
font-weight: 600;
|
|
3030
|
+
margin-block-end: 4px;
|
|
3031
|
+
}
|
|
3032
|
+
.gemina-verification__tip-list {
|
|
3033
|
+
margin: 0;
|
|
3034
|
+
padding-inline-start: 16px;
|
|
3035
|
+
}
|
|
3036
|
+
.gemina-verification__tip-list li + li {
|
|
3037
|
+
margin-block-start: 2px;
|
|
3038
|
+
}
|
|
3039
|
+
/* A muted lead-in for single-fact tips ("Was:"), so the VALUE reads first. */
|
|
3040
|
+
.gemina-verification__tip-label {
|
|
3041
|
+
color: var(--gemina-verification-muted);
|
|
3042
|
+
}
|
|
2163
3043
|
`;
|
|
2164
3044
|
var STYLE_ATTR = "data-gemina-verification";
|
|
2165
3045
|
function ensureVerificationStylesInjected() {
|
|
@@ -2176,7 +3056,7 @@ function ensureVerificationStylesInjected() {
|
|
|
2176
3056
|
}
|
|
2177
3057
|
|
|
2178
3058
|
// src/verification/index.tsx
|
|
2179
|
-
var
|
|
3059
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
2180
3060
|
var HEBREW_RE = /[\u0590-\u05FF]/;
|
|
2181
3061
|
var STACKED_BREAKPOINT = 860;
|
|
2182
3062
|
var IMAGE_REFRESH_THROTTLE_MS = 6e4;
|
|
@@ -2189,11 +3069,23 @@ var PURGED_TEXT = "Document no longer available (retention policy).";
|
|
|
2189
3069
|
var NOT_COMPLETED_TEXT = "This extraction did not complete, so there is nothing to verify.";
|
|
2190
3070
|
var VERIFICATION_UNAVAILABLE_TEXT = "Verification isn't available for this extraction.";
|
|
2191
3071
|
var ALREADY_VALIDATED_TEXT = "Already verified \u2014 showing the original extraction.";
|
|
2192
|
-
var CONFIRM_TEXT = "Submit
|
|
3072
|
+
var CONFIRM_TEXT = "Submit these values? This is final \u2014 they can be submitted once and can't be changed.";
|
|
2193
3073
|
var SUBMITTING_TEXT = "Submitting\u2026";
|
|
2194
3074
|
var SUBMIT_FAILED_TEXT = "Submission failed \u2014 your corrections are still here.";
|
|
2195
|
-
var DONE_TITLE_TEXT = "
|
|
3075
|
+
var DONE_TITLE_TEXT = "Submitted";
|
|
2196
3076
|
var NO_EDITS = /* @__PURE__ */ new Map();
|
|
3077
|
+
var NO_ROW_PLANS = /* @__PURE__ */ new Map();
|
|
3078
|
+
var NO_PLANNED_TABLES = /* @__PURE__ */ new Map();
|
|
3079
|
+
function seedRowPlans(tables, values) {
|
|
3080
|
+
if (tables.length === 0) {
|
|
3081
|
+
return NO_ROW_PLANS;
|
|
3082
|
+
}
|
|
3083
|
+
const plans = /* @__PURE__ */ new Map();
|
|
3084
|
+
for (const table of tables) {
|
|
3085
|
+
plans.set(table.pointer, initialRowPlan(countRowsAt(values, table.pointer), table.pointer));
|
|
3086
|
+
}
|
|
3087
|
+
return plans;
|
|
3088
|
+
}
|
|
2197
3089
|
var ALERT_REASONS = /* @__PURE__ */ new Set([
|
|
2198
3090
|
"session-expired",
|
|
2199
3091
|
"not-available",
|
|
@@ -2210,43 +3102,44 @@ function GeminaVerification(props) {
|
|
|
2210
3102
|
onError,
|
|
2211
3103
|
className
|
|
2212
3104
|
} = props;
|
|
2213
|
-
const [phase, setPhase] = (0,
|
|
2214
|
-
const [alreadyValidated, setAlreadyValidated] = (0,
|
|
2215
|
-
const [loaded, setLoaded] = (0,
|
|
2216
|
-
const [
|
|
2217
|
-
const [
|
|
2218
|
-
const [
|
|
2219
|
-
const [
|
|
2220
|
-
const
|
|
2221
|
-
const
|
|
2222
|
-
const
|
|
2223
|
-
const
|
|
2224
|
-
const
|
|
3105
|
+
const [phase, setPhase] = (0, import_react4.useState)({ name: "loading" });
|
|
3106
|
+
const [alreadyValidated, setAlreadyValidated] = (0, import_react4.useState)(false);
|
|
3107
|
+
const [loaded, setLoaded] = (0, import_react4.useState)(null);
|
|
3108
|
+
const [rowPlans, setRowPlans] = (0, import_react4.useState)(NO_ROW_PLANS);
|
|
3109
|
+
const [edits, setEdits] = (0, import_react4.useState)(NO_EDITS);
|
|
3110
|
+
const [imageUrl, setImageUrl] = (0, import_react4.useState)(null);
|
|
3111
|
+
const [flashRects, setFlashRects] = (0, import_react4.useState)(null);
|
|
3112
|
+
const [stacked, setStacked] = (0, import_react4.useState)(false);
|
|
3113
|
+
const rootRef = (0, import_react4.useRef)(null);
|
|
3114
|
+
const mountedRef = (0, import_react4.useRef)(false);
|
|
3115
|
+
const loadSeqRef = (0, import_react4.useRef)(0);
|
|
3116
|
+
const lastImageRefreshRef = (0, import_react4.useRef)(0);
|
|
3117
|
+
const onErrorRef = (0, import_react4.useRef)(onError);
|
|
2225
3118
|
onErrorRef.current = onError;
|
|
2226
|
-
const onCompleteRef = (0,
|
|
3119
|
+
const onCompleteRef = (0, import_react4.useRef)(onComplete);
|
|
2227
3120
|
onCompleteRef.current = onComplete;
|
|
2228
|
-
const completedRef = (0,
|
|
2229
|
-
const submitInFlightRef = (0,
|
|
2230
|
-
const restoreFocusRef = (0,
|
|
2231
|
-
const submitButtonRef = (0,
|
|
2232
|
-
const confirmButtonRef = (0,
|
|
2233
|
-
const cancelButtonRef = (0,
|
|
2234
|
-
const retrySubmitButtonRef = (0,
|
|
2235
|
-
const doneStateRef = (0,
|
|
2236
|
-
const enterUnavailable = (0,
|
|
3121
|
+
const completedRef = (0, import_react4.useRef)(false);
|
|
3122
|
+
const submitInFlightRef = (0, import_react4.useRef)(false);
|
|
3123
|
+
const restoreFocusRef = (0, import_react4.useRef)(false);
|
|
3124
|
+
const submitButtonRef = (0, import_react4.useRef)(null);
|
|
3125
|
+
const confirmButtonRef = (0, import_react4.useRef)(null);
|
|
3126
|
+
const cancelButtonRef = (0, import_react4.useRef)(null);
|
|
3127
|
+
const retrySubmitButtonRef = (0, import_react4.useRef)(null);
|
|
3128
|
+
const doneStateRef = (0, import_react4.useRef)(null);
|
|
3129
|
+
const enterUnavailable = (0, import_react4.useCallback)(
|
|
2237
3130
|
(reason, message, canRetry, detail) => {
|
|
2238
3131
|
setPhase({ name: "unavailable", reason, message, canRetry });
|
|
2239
3132
|
onErrorRef.current?.(reason, detail);
|
|
2240
3133
|
},
|
|
2241
3134
|
[]
|
|
2242
3135
|
);
|
|
2243
|
-
const fetchOnce = (0,
|
|
3136
|
+
const fetchOnce = (0, import_react4.useCallback)(async () => {
|
|
2244
3137
|
const token = await tokenManager.getToken();
|
|
2245
3138
|
return import_sdk.GeminaClient.withSessionToken(token, baseUrl).documents.getDocumentExtraction({
|
|
2246
3139
|
documentExtractionId: extractionId
|
|
2247
3140
|
});
|
|
2248
3141
|
}, [tokenManager, baseUrl, extractionId]);
|
|
2249
|
-
const fetchWithRetry = (0,
|
|
3142
|
+
const fetchWithRetry = (0, import_react4.useCallback)(async () => {
|
|
2250
3143
|
try {
|
|
2251
3144
|
return await fetchOnce();
|
|
2252
3145
|
} catch (error) {
|
|
@@ -2257,7 +3150,7 @@ function GeminaVerification(props) {
|
|
|
2257
3150
|
return await fetchOnce();
|
|
2258
3151
|
}
|
|
2259
3152
|
}, [fetchOnce, tokenManager]);
|
|
2260
|
-
const load = (0,
|
|
3153
|
+
const load = (0, import_react4.useCallback)(async () => {
|
|
2261
3154
|
const seq = ++loadSeqRef.current;
|
|
2262
3155
|
const live = () => mountedRef.current && loadSeqRef.current === seq;
|
|
2263
3156
|
setPhase({ name: "loading" });
|
|
@@ -2288,9 +3181,12 @@ function GeminaVerification(props) {
|
|
|
2288
3181
|
const schema = view.meta.validationFeedback?.validationSchema;
|
|
2289
3182
|
setLoaded({
|
|
2290
3183
|
values: view.values,
|
|
2291
|
-
schema: Array.isArray(schema) ? schema : []
|
|
3184
|
+
schema: Array.isArray(schema) ? schema : [],
|
|
3185
|
+
fields: readDescriptors(view.meta.validationFeedback?.validationFields),
|
|
3186
|
+
rowMutableTables: readRowMutableTables(view.meta.validationFeedback?.rowMutableTables)
|
|
2292
3187
|
});
|
|
2293
3188
|
setEdits(NO_EDITS);
|
|
3189
|
+
setRowPlans(seedRowPlans(readRowMutableTables(view.meta.validationFeedback?.rowMutableTables), view.values));
|
|
2294
3190
|
const url = view.document.imageUrl;
|
|
2295
3191
|
setImageUrl(typeof url === "string" && url.length > 0 ? url : null);
|
|
2296
3192
|
setAlreadyValidated(validated);
|
|
@@ -2308,7 +3204,7 @@ function GeminaVerification(props) {
|
|
|
2308
3204
|
enterReview(false);
|
|
2309
3205
|
}
|
|
2310
3206
|
}, [fetchWithRetry, enterUnavailable]);
|
|
2311
|
-
(0,
|
|
3207
|
+
(0, import_react4.useEffect)(() => {
|
|
2312
3208
|
mountedRef.current = true;
|
|
2313
3209
|
ensureVerificationStylesInjected();
|
|
2314
3210
|
void load();
|
|
@@ -2316,7 +3212,7 @@ function GeminaVerification(props) {
|
|
|
2316
3212
|
mountedRef.current = false;
|
|
2317
3213
|
};
|
|
2318
3214
|
}, [load]);
|
|
2319
|
-
(0,
|
|
3215
|
+
(0, import_react4.useEffect)(() => {
|
|
2320
3216
|
const el = rootRef.current;
|
|
2321
3217
|
if (el === null) {
|
|
2322
3218
|
return;
|
|
@@ -2337,10 +3233,20 @@ function GeminaVerification(props) {
|
|
|
2337
3233
|
observer.observe(el);
|
|
2338
3234
|
return () => observer.disconnect();
|
|
2339
3235
|
}, []);
|
|
2340
|
-
const classified = (0,
|
|
2341
|
-
const bindings = (0,
|
|
2342
|
-
|
|
2343
|
-
|
|
3236
|
+
const classified = (0, import_react4.useMemo)(() => classifyData(loaded?.values), [loaded]);
|
|
3237
|
+
const bindings = (0, import_react4.useMemo)(
|
|
3238
|
+
() => buildBindings(loaded?.schema ?? [], loaded?.values, loaded?.fields),
|
|
3239
|
+
[loaded]
|
|
3240
|
+
);
|
|
3241
|
+
const bindingIndex = (0, import_react4.useMemo)(() => indexBindingsByFieldPointer(bindings), [bindings]);
|
|
3242
|
+
const bindingsByRawKey = (0, import_react4.useMemo)(() => {
|
|
3243
|
+
const map = /* @__PURE__ */ new Map();
|
|
3244
|
+
for (const binding of bindings) {
|
|
3245
|
+
map.set(binding.key.raw, binding);
|
|
3246
|
+
}
|
|
3247
|
+
return map;
|
|
3248
|
+
}, [bindings]);
|
|
3249
|
+
const unmatched = (0, import_react4.useMemo)(() => {
|
|
2344
3250
|
const rendered = /* @__PURE__ */ new Set();
|
|
2345
3251
|
for (const field of classified.headers) {
|
|
2346
3252
|
rendered.add(field.pointer);
|
|
@@ -2368,7 +3274,7 @@ function GeminaVerification(props) {
|
|
|
2368
3274
|
}
|
|
2369
3275
|
return bindings.filter((binding) => !rendered.has(binding.fieldPointer));
|
|
2370
3276
|
}, [classified, bindings]);
|
|
2371
|
-
const overlayRects = (0,
|
|
3277
|
+
const overlayRects = (0, import_react4.useMemo)(() => {
|
|
2372
3278
|
const rects = [];
|
|
2373
3279
|
for (const field of classified.headers) {
|
|
2374
3280
|
if (field.coordinates) {
|
|
@@ -2402,48 +3308,87 @@ function GeminaVerification(props) {
|
|
|
2402
3308
|
}
|
|
2403
3309
|
return rects.length > 0 ? rects : void 0;
|
|
2404
3310
|
}, [classified]);
|
|
2405
|
-
const hasHebrewContent = (0,
|
|
3311
|
+
const hasHebrewContent = (0, import_react4.useMemo)(
|
|
2406
3312
|
() => bindings.some((binding) => HEBREW_RE.test(toInputString(binding.extracted))),
|
|
2407
3313
|
[bindings]
|
|
2408
3314
|
);
|
|
2409
3315
|
const effectiveDir = dir === "auto" ? hasHebrewContent ? "rtl" : "ltr" : dir;
|
|
2410
|
-
const
|
|
2411
|
-
const
|
|
2412
|
-
for (const binding of bindings) {
|
|
2413
|
-
map.set(binding.key.raw, binding);
|
|
2414
|
-
}
|
|
2415
|
-
return map;
|
|
2416
|
-
}, [bindings]);
|
|
2417
|
-
const bindingsByRawKeyRef = (0, import_react3.useRef)(bindingsByRawKey);
|
|
2418
|
-
bindingsByRawKeyRef.current = bindingsByRawKey;
|
|
2419
|
-
const handleEdit = (0, import_react3.useCallback)((rawKey, value) => {
|
|
2420
|
-
const binding = bindingsByRawKeyRef.current.get(rawKey);
|
|
2421
|
-
const pristine = binding !== void 0 && value === toInputString(binding.extracted);
|
|
3316
|
+
const handleEdit = (0, import_react4.useCallback)((editKey, value, binding) => {
|
|
3317
|
+
const pristine = value === toInputString(binding.extracted);
|
|
2422
3318
|
setEdits((prev) => {
|
|
2423
3319
|
if (pristine) {
|
|
2424
|
-
if (!prev.has(
|
|
3320
|
+
if (!prev.has(editKey)) {
|
|
2425
3321
|
return prev;
|
|
2426
3322
|
}
|
|
2427
3323
|
const next2 = new Map(prev);
|
|
2428
|
-
next2.delete(
|
|
3324
|
+
next2.delete(editKey);
|
|
2429
3325
|
return next2;
|
|
2430
3326
|
}
|
|
2431
|
-
if (prev.get(
|
|
3327
|
+
if (prev.get(editKey) === value) {
|
|
2432
3328
|
return prev;
|
|
2433
3329
|
}
|
|
2434
3330
|
const next = new Map(prev);
|
|
2435
|
-
next.set(
|
|
3331
|
+
next.set(editKey, value);
|
|
2436
3332
|
return next;
|
|
2437
3333
|
});
|
|
2438
3334
|
}, []);
|
|
2439
|
-
const
|
|
2440
|
-
|
|
3335
|
+
const plannedTables = (0, import_react4.useMemo)(() => {
|
|
3336
|
+
const tables = loaded?.rowMutableTables ?? [];
|
|
3337
|
+
if (tables.length === 0) {
|
|
3338
|
+
return NO_PLANNED_TABLES;
|
|
3339
|
+
}
|
|
3340
|
+
const out = /* @__PURE__ */ new Map();
|
|
3341
|
+
for (const table of tables) {
|
|
3342
|
+
const plan = rowPlans.get(table.pointer);
|
|
3343
|
+
if (plan === void 0) {
|
|
3344
|
+
continue;
|
|
3345
|
+
}
|
|
3346
|
+
const classifiedTable = classified.tables.find(
|
|
3347
|
+
(candidate) => matchesTablePointer(table.pointer, candidate.pointer)
|
|
3348
|
+
);
|
|
3349
|
+
const columns = displayColumns(table, classifiedTable?.columns ?? []);
|
|
3350
|
+
out.set(table.pointer, planTableCells(table, plan, columns, bindingsByRawKey));
|
|
3351
|
+
}
|
|
3352
|
+
return out;
|
|
3353
|
+
}, [loaded, rowPlans, classified, bindingsByRawKey]);
|
|
3354
|
+
const cellViews = (0, import_react4.useMemo)(
|
|
3355
|
+
() => collectCellViews(bindings, plannedTables),
|
|
3356
|
+
[bindings, plannedTables]
|
|
3357
|
+
);
|
|
3358
|
+
const submissionTables = (0, import_react4.useMemo)(
|
|
3359
|
+
() => pruneEmptyAddedRows(plannedTables, edits),
|
|
3360
|
+
[plannedTables, edits]
|
|
3361
|
+
);
|
|
3362
|
+
const submissionCells = (0, import_react4.useMemo)(
|
|
3363
|
+
() => collectCellViews(bindings, submissionTables),
|
|
3364
|
+
[bindings, submissionTables]
|
|
3365
|
+
);
|
|
3366
|
+
const rowSources = (0, import_react4.useMemo)(() => {
|
|
3367
|
+
const entries = [];
|
|
3368
|
+
for (const table of loaded?.rowMutableTables ?? []) {
|
|
3369
|
+
const rows = submissionTables.get(table.pointer);
|
|
3370
|
+
if (rows === void 0) {
|
|
3371
|
+
continue;
|
|
3372
|
+
}
|
|
3373
|
+
const plan = rows.map((row) => row.entry);
|
|
3374
|
+
if (isIdentityPlan(plan, countRowsAt(loaded?.values, table.pointer))) {
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3377
|
+
entries.push({ table: table.pointer, sources: rowSourcesOf(plan) });
|
|
3378
|
+
}
|
|
3379
|
+
return entries;
|
|
3380
|
+
}, [loaded, submissionTables]);
|
|
3381
|
+
const submission = (0, import_react4.useMemo)(
|
|
3382
|
+
() => composeSubmission(bindings, edits, { cells: submissionCells, rowSources }),
|
|
3383
|
+
[bindings, edits, submissionCells, rowSources]
|
|
3384
|
+
);
|
|
3385
|
+
const handleFlash = (0, import_react4.useCallback)((rects) => {
|
|
2441
3386
|
setFlashRects(rects.map((rect) => ({ points: rect.points })));
|
|
2442
3387
|
}, []);
|
|
2443
|
-
const handleFlashComplete = (0,
|
|
3388
|
+
const handleFlashComplete = (0, import_react4.useCallback)(() => {
|
|
2444
3389
|
setFlashRects(null);
|
|
2445
3390
|
}, []);
|
|
2446
|
-
const handleImageExpired = (0,
|
|
3391
|
+
const handleImageExpired = (0, import_react4.useCallback)(() => {
|
|
2447
3392
|
const now = Date.now();
|
|
2448
3393
|
if (now - lastImageRefreshRef.current < IMAGE_REFRESH_THROTTLE_MS) {
|
|
2449
3394
|
return;
|
|
@@ -2461,10 +3406,52 @@ function GeminaVerification(props) {
|
|
|
2461
3406
|
}).catch(() => {
|
|
2462
3407
|
});
|
|
2463
3408
|
}, [fetchWithRetry]);
|
|
2464
|
-
const handleRetry = (0,
|
|
3409
|
+
const handleRetry = (0, import_react4.useCallback)(() => {
|
|
2465
3410
|
void load();
|
|
2466
3411
|
}, [load]);
|
|
2467
|
-
const
|
|
3412
|
+
const handleAddRow = (0, import_react4.useCallback)((tablePointer, afterPosition) => {
|
|
3413
|
+
const id = nextAddedRowId(tablePointer);
|
|
3414
|
+
setRowPlans((prev) => {
|
|
3415
|
+
const plan = prev.get(tablePointer);
|
|
3416
|
+
if (plan === void 0) {
|
|
3417
|
+
return prev;
|
|
3418
|
+
}
|
|
3419
|
+
const next = new Map(prev);
|
|
3420
|
+
next.set(tablePointer, insertRowAfter(plan, afterPosition, id));
|
|
3421
|
+
return next;
|
|
3422
|
+
});
|
|
3423
|
+
}, []);
|
|
3424
|
+
const handleRemoveRow = (0, import_react4.useCallback)((tablePointer, position) => {
|
|
3425
|
+
setRowPlans((prev) => {
|
|
3426
|
+
const plan = prev.get(tablePointer);
|
|
3427
|
+
if (plan === void 0) {
|
|
3428
|
+
return prev;
|
|
3429
|
+
}
|
|
3430
|
+
const nextPlan = removeRow(plan, position);
|
|
3431
|
+
if (nextPlan === plan) {
|
|
3432
|
+
return prev;
|
|
3433
|
+
}
|
|
3434
|
+
const next = new Map(prev);
|
|
3435
|
+
next.set(tablePointer, nextPlan);
|
|
3436
|
+
return next;
|
|
3437
|
+
});
|
|
3438
|
+
}, []);
|
|
3439
|
+
const pairErrors = (0, import_react4.useMemo)(() => unitSizePairErrors(cellViews, edits), [cellViews, edits]);
|
|
3440
|
+
const invalidCount = (0, import_react4.useMemo)(() => {
|
|
3441
|
+
const rowLevel = pairErrors.size;
|
|
3442
|
+
if (edits.size === 0) {
|
|
3443
|
+
return rowLevel;
|
|
3444
|
+
}
|
|
3445
|
+
const byEditKey = new Map(cellViews.map((view) => [view.editKey, view.binding]));
|
|
3446
|
+
let count = 0;
|
|
3447
|
+
for (const [editKey, value] of edits) {
|
|
3448
|
+
if (!pairErrors.has(editKey) && validateInput(value, byEditKey.get(editKey)?.field) !== null) {
|
|
3449
|
+
count += 1;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
return count + rowLevel;
|
|
3453
|
+
}, [edits, cellViews, pairErrors]);
|
|
3454
|
+
const doSubmit = (0, import_react4.useCallback)(async () => {
|
|
2468
3455
|
if (submitInFlightRef.current) {
|
|
2469
3456
|
return;
|
|
2470
3457
|
}
|
|
@@ -2477,7 +3464,13 @@ function GeminaVerification(props) {
|
|
|
2477
3464
|
const token = await tokenManager.getToken();
|
|
2478
3465
|
return import_sdk.GeminaClient.withSessionToken(token, baseUrl).documents.validateDocumentExtraction({
|
|
2479
3466
|
targetDocumentExtractionId: extractionId,
|
|
2480
|
-
|
|
3467
|
+
// Conditional spread, matching the house pattern: without a row edit
|
|
3468
|
+
// the request body is byte-identical to what it was before this
|
|
3469
|
+
// feature, so nothing changes for the overwhelmingly common path.
|
|
3470
|
+
extractionValidationInDTO: {
|
|
3471
|
+
data: body.data,
|
|
3472
|
+
...body.rowSources.length > 0 ? { rowSources: body.rowSources } : {}
|
|
3473
|
+
}
|
|
2481
3474
|
});
|
|
2482
3475
|
};
|
|
2483
3476
|
try {
|
|
@@ -2525,20 +3518,20 @@ function GeminaVerification(props) {
|
|
|
2525
3518
|
submitInFlightRef.current = false;
|
|
2526
3519
|
}
|
|
2527
3520
|
}, [submission, tokenManager, baseUrl, extractionId, load]);
|
|
2528
|
-
const handleSubmitClick = (0,
|
|
3521
|
+
const handleSubmitClick = (0, import_react4.useCallback)(() => {
|
|
2529
3522
|
setPhase({ name: "confirming" });
|
|
2530
3523
|
}, []);
|
|
2531
|
-
const handleConfirm = (0,
|
|
3524
|
+
const handleConfirm = (0, import_react4.useCallback)(() => {
|
|
2532
3525
|
void doSubmit();
|
|
2533
3526
|
}, [doSubmit]);
|
|
2534
|
-
const handleCancelConfirm = (0,
|
|
3527
|
+
const handleCancelConfirm = (0, import_react4.useCallback)(() => {
|
|
2535
3528
|
restoreFocusRef.current = true;
|
|
2536
3529
|
setPhase({ name: "review" });
|
|
2537
3530
|
}, []);
|
|
2538
|
-
const handleRetrySubmit = (0,
|
|
3531
|
+
const handleRetrySubmit = (0, import_react4.useCallback)(() => {
|
|
2539
3532
|
void doSubmit();
|
|
2540
3533
|
}, [doSubmit]);
|
|
2541
|
-
const handleConfirmKeyDown = (0,
|
|
3534
|
+
const handleConfirmKeyDown = (0, import_react4.useCallback)(
|
|
2542
3535
|
(event) => {
|
|
2543
3536
|
if (phase.name !== "confirming") {
|
|
2544
3537
|
return;
|
|
@@ -2569,7 +3562,7 @@ function GeminaVerification(props) {
|
|
|
2569
3562
|
},
|
|
2570
3563
|
[phase.name, handleCancelConfirm]
|
|
2571
3564
|
);
|
|
2572
|
-
(0,
|
|
3565
|
+
(0, import_react4.useEffect)(() => {
|
|
2573
3566
|
if (phase.name === "confirming") {
|
|
2574
3567
|
confirmButtonRef.current?.focus();
|
|
2575
3568
|
} else if (phase.name === "review" && restoreFocusRef.current) {
|
|
@@ -2588,13 +3581,13 @@ function GeminaVerification(props) {
|
|
|
2588
3581
|
stacked ? "gemina-verification--stacked" : "",
|
|
2589
3582
|
className ?? ""
|
|
2590
3583
|
].filter((part) => part.length > 0).join(" ");
|
|
2591
|
-
const dialogTextId = (0,
|
|
3584
|
+
const dialogTextId = (0, import_react4.useId)();
|
|
2592
3585
|
const renderReview = (reviewPhase) => {
|
|
2593
3586
|
const overlayUp = reviewPhase.name === "confirming" || reviewPhase.name === "submitting";
|
|
2594
|
-
return /* @__PURE__ */ (0,
|
|
2595
|
-
alreadyValidated && /* @__PURE__ */ (0,
|
|
2596
|
-
/* @__PURE__ */ (0,
|
|
2597
|
-
imageUrl !== null && /* @__PURE__ */ (0,
|
|
3587
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
3588
|
+
alreadyValidated && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__banner", children: ALREADY_VALIDATED_TEXT }),
|
|
3589
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__panes", children: [
|
|
3590
|
+
imageUrl !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2598
3591
|
VerificationViewer,
|
|
2599
3592
|
{
|
|
2600
3593
|
src: imageUrl,
|
|
@@ -2604,7 +3597,7 @@ function GeminaVerification(props) {
|
|
|
2604
3597
|
onImageExpired: handleImageExpired
|
|
2605
3598
|
}
|
|
2606
3599
|
),
|
|
2607
|
-
/* @__PURE__ */ (0,
|
|
3600
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2608
3601
|
VerificationForm,
|
|
2609
3602
|
{
|
|
2610
3603
|
classified,
|
|
@@ -2613,18 +3606,23 @@ function GeminaVerification(props) {
|
|
|
2613
3606
|
edits,
|
|
2614
3607
|
onEdit: handleEdit,
|
|
2615
3608
|
readOnly: alreadyValidated,
|
|
2616
|
-
onFlash: handleFlash
|
|
3609
|
+
onFlash: handleFlash,
|
|
3610
|
+
pairErrors,
|
|
3611
|
+
rowMutableTables: loaded?.rowMutableTables,
|
|
3612
|
+
plannedTables,
|
|
3613
|
+
onAddRow: handleAddRow,
|
|
3614
|
+
onRemoveRow: handleRemoveRow
|
|
2617
3615
|
}
|
|
2618
3616
|
)
|
|
2619
3617
|
] }),
|
|
2620
|
-
reviewPhase.name === "submit-error" && /* @__PURE__ */ (0,
|
|
3618
|
+
reviewPhase.name === "submit-error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2621
3619
|
"div",
|
|
2622
3620
|
{
|
|
2623
3621
|
className: "gemina-verification__banner gemina-verification__banner--error gemina-verification__submit-error",
|
|
2624
3622
|
role: "alert",
|
|
2625
3623
|
children: [
|
|
2626
|
-
/* @__PURE__ */ (0,
|
|
2627
|
-
/* @__PURE__ */ (0,
|
|
3624
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: reviewPhase.message }),
|
|
3625
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2628
3626
|
"button",
|
|
2629
3627
|
{
|
|
2630
3628
|
type: "button",
|
|
@@ -2637,21 +3635,21 @@ function GeminaVerification(props) {
|
|
|
2637
3635
|
]
|
|
2638
3636
|
}
|
|
2639
3637
|
),
|
|
2640
|
-
/* @__PURE__ */ (0,
|
|
2641
|
-
!alreadyValidated && /* @__PURE__ */ (0,
|
|
2642
|
-
/* @__PURE__ */ (0,
|
|
3638
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__footer", children: [
|
|
3639
|
+
!alreadyValidated && (invalidCount > 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__attention", "aria-live": "polite", children: invalidCount === 1 ? "1 field needs attention" : `${invalidCount} fields need attention` }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__progress", "aria-live": "polite", children: `${submission.confirmed} confirmed \xB7 ${submission.corrected} corrected` })),
|
|
3640
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2643
3641
|
"button",
|
|
2644
3642
|
{
|
|
2645
3643
|
type: "button",
|
|
2646
3644
|
ref: submitButtonRef,
|
|
2647
3645
|
className: "gemina-verification__submit",
|
|
2648
|
-
disabled: alreadyValidated || reviewPhase.name !== "review",
|
|
3646
|
+
disabled: alreadyValidated || reviewPhase.name !== "review" || invalidCount > 0,
|
|
2649
3647
|
onClick: handleSubmitClick,
|
|
2650
|
-
children: "Submit
|
|
3648
|
+
children: "Submit"
|
|
2651
3649
|
}
|
|
2652
3650
|
)
|
|
2653
3651
|
] }),
|
|
2654
|
-
overlayUp && /* @__PURE__ */ (0,
|
|
3652
|
+
overlayUp && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2655
3653
|
"div",
|
|
2656
3654
|
{
|
|
2657
3655
|
className: "gemina-verification__confirm",
|
|
@@ -2661,7 +3659,7 @@ function GeminaVerification(props) {
|
|
|
2661
3659
|
event.preventDefault();
|
|
2662
3660
|
}
|
|
2663
3661
|
},
|
|
2664
|
-
children: /* @__PURE__ */ (0,
|
|
3662
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2665
3663
|
"div",
|
|
2666
3664
|
{
|
|
2667
3665
|
className: "gemina-verification__confirm-dialog",
|
|
@@ -2669,9 +3667,9 @@ function GeminaVerification(props) {
|
|
|
2669
3667
|
"aria-modal": "true",
|
|
2670
3668
|
"aria-labelledby": dialogTextId,
|
|
2671
3669
|
children: [
|
|
2672
|
-
/* @__PURE__ */ (0,
|
|
2673
|
-
/* @__PURE__ */ (0,
|
|
2674
|
-
/* @__PURE__ */ (0,
|
|
3670
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { id: dialogTextId, className: "gemina-verification__confirm-text", children: reviewPhase.name === "submitting" ? SUBMITTING_TEXT : CONFIRM_TEXT }),
|
|
3671
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "gemina-verification__confirm-actions", children: [
|
|
3672
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2675
3673
|
"button",
|
|
2676
3674
|
{
|
|
2677
3675
|
type: "button",
|
|
@@ -2682,7 +3680,7 @@ function GeminaVerification(props) {
|
|
|
2682
3680
|
children: "Cancel"
|
|
2683
3681
|
}
|
|
2684
3682
|
),
|
|
2685
|
-
/* @__PURE__ */ (0,
|
|
3683
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2686
3684
|
"button",
|
|
2687
3685
|
{
|
|
2688
3686
|
type: "button",
|
|
@@ -2704,16 +3702,16 @@ function GeminaVerification(props) {
|
|
|
2704
3702
|
const content = (() => {
|
|
2705
3703
|
switch (phase.name) {
|
|
2706
3704
|
case "loading":
|
|
2707
|
-
return /* @__PURE__ */ (0,
|
|
3705
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__state", role: "status", children: LOADING_TEXT });
|
|
2708
3706
|
case "unavailable":
|
|
2709
|
-
return /* @__PURE__ */ (0,
|
|
3707
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2710
3708
|
"div",
|
|
2711
3709
|
{
|
|
2712
3710
|
className: "gemina-verification__state",
|
|
2713
3711
|
role: ALERT_REASONS.has(phase.reason) ? "alert" : "status",
|
|
2714
3712
|
children: [
|
|
2715
|
-
/* @__PURE__ */ (0,
|
|
2716
|
-
phase.canRetry && /* @__PURE__ */ (0,
|
|
3713
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: phase.message }),
|
|
3714
|
+
phase.canRetry && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "gemina-verification__retry", onClick: handleRetry, children: "Retry" })
|
|
2717
3715
|
]
|
|
2718
3716
|
}
|
|
2719
3717
|
);
|
|
@@ -2723,7 +3721,7 @@ function GeminaVerification(props) {
|
|
|
2723
3721
|
case "submit-error":
|
|
2724
3722
|
return renderReview(phase);
|
|
2725
3723
|
case "done":
|
|
2726
|
-
return /* @__PURE__ */ (0,
|
|
3724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2727
3725
|
"div",
|
|
2728
3726
|
{
|
|
2729
3727
|
ref: doneStateRef,
|
|
@@ -2731,7 +3729,7 @@ function GeminaVerification(props) {
|
|
|
2731
3729
|
className: "gemina-verification__state gemina-verification__state--done",
|
|
2732
3730
|
role: "status",
|
|
2733
3731
|
children: [
|
|
2734
|
-
/* @__PURE__ */ (0,
|
|
3732
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "gemina-verification__done-check", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2735
3733
|
"path",
|
|
2736
3734
|
{
|
|
2737
3735
|
d: "M4 10.5l4 4 8-9",
|
|
@@ -2741,14 +3739,14 @@ function GeminaVerification(props) {
|
|
|
2741
3739
|
strokeLinejoin: "round"
|
|
2742
3740
|
}
|
|
2743
3741
|
) }) }),
|
|
2744
|
-
/* @__PURE__ */ (0,
|
|
2745
|
-
/* @__PURE__ */ (0,
|
|
3742
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__done-title", children: DONE_TITLE_TEXT }),
|
|
3743
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "gemina-verification__progress", children: `${phase.confirmed} confirmed \xB7 ${phase.corrected} corrected` })
|
|
2746
3744
|
]
|
|
2747
3745
|
}
|
|
2748
3746
|
);
|
|
2749
3747
|
}
|
|
2750
3748
|
})();
|
|
2751
|
-
return /* @__PURE__ */ (0,
|
|
3749
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { ref: rootRef, className: rootClassName, dir: effectiveDir, children: content });
|
|
2752
3750
|
}
|
|
2753
3751
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2754
3752
|
0 && (module.exports = {
|