@eifi1/ui-kit 0.21.0 → 0.23.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/README.md +42 -25
- package/dist/chart.d.ts +19 -14
- package/dist/components/account-chips.d.ts +10 -3
- package/dist/components/account-chips.js +5 -2
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/account-settings.d.ts +33 -2
- package/dist/components/account-settings.js +43 -21
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/amount-input.d.ts +53 -14
- package/dist/components/amount-input.js +17 -28
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +29 -0
- package/dist/components/autocomplete.js +134 -104
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-group.d.ts +19 -14
- package/dist/components/calculator.d.ts +19 -14
- package/dist/components/checkbox-group.d.ts +104 -0
- package/dist/components/checkbox-group.js +111 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +19 -0
- package/dist/components/checkbox.js +30 -7
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/chip.d.ts +18 -0
- package/dist/components/chip.js +47 -10
- package/dist/components/chip.js.map +1 -1
- package/dist/components/column-mapper.d.ts +182 -0
- package/dist/components/column-mapper.js +375 -0
- package/dist/components/column-mapper.js.map +1 -0
- package/dist/components/combobox-core.d.ts +39 -2
- package/dist/components/combobox-core.js +29 -6
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +91 -2
- package/dist/components/combobox.js +454 -308
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +69 -161
- package/dist/components/confirm-dialog.js +7 -8
- package/dist/components/confirm-dialog.js.map +1 -1
- package/dist/components/copy-button.d.ts +16 -11
- package/dist/components/country-select.d.ts +167 -0
- package/dist/components/country-select.js +293 -0
- package/dist/components/country-select.js.map +1 -0
- package/dist/components/currency-select.d.ts +17 -1
- package/dist/components/currency-select.js +56 -23
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/danger-confirm.d.ts +69 -166
- package/dist/components/danger-confirm.js +144 -50
- package/dist/components/danger-confirm.js.map +1 -1
- package/dist/components/data-table-cells.d.ts +1 -2
- package/dist/components/data-table-filter-popover.d.ts +1 -2
- package/dist/components/data-table-filters.d.ts +1 -2
- package/dist/components/data-table-labels.d.ts +4 -97
- package/dist/components/data-table-labels.js +9 -1
- package/dist/components/data-table-labels.js.map +1 -1
- package/dist/components/data-table-pagination.d.ts +3 -1
- package/dist/components/data-table.d.ts +1 -2
- package/dist/components/data-table.js +98 -3
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +66 -5
- package/dist/components/date-picker.js +378 -66
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +42 -1
- package/dist/components/entity-combobox.js +154 -113
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/facing-pair.d.ts +19 -14
- package/dist/components/field-parts.d.ts +224 -0
- package/dist/components/field-parts.js +156 -0
- package/dist/components/field-parts.js.map +1 -0
- package/dist/components/field-strip.d.ts +105 -0
- package/dist/components/field-strip.js +46 -0
- package/dist/components/field-strip.js.map +1 -0
- package/dist/components/file-button.d.ts +19 -14
- package/dist/components/file-button.js +13 -3
- package/dist/components/file-button.js.map +1 -1
- package/dist/components/file-dropzone.d.ts +41 -15
- package/dist/components/file-dropzone.js +57 -34
- package/dist/components/file-dropzone.js.map +1 -1
- package/dist/components/form-actions.d.ts +18 -13
- package/dist/components/form-actions.js +69 -5
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/iban-input.d.ts +69 -0
- package/dist/components/iban-input.js +125 -0
- package/dist/components/iban-input.js.map +1 -0
- package/dist/components/icon-picker.d.ts +21 -2
- package/dist/components/icon-picker.js +19 -4
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/inline-edit-field.d.ts +167 -0
- package/dist/components/inline-edit-field.js +293 -0
- package/dist/components/inline-edit-field.js.map +1 -0
- package/dist/components/language-select.d.ts +130 -0
- package/dist/components/language-select.js +18 -0
- package/dist/components/language-select.js.map +1 -0
- package/dist/components/line-items.d.ts +25 -3
- package/dist/components/line-items.js +55 -46
- package/dist/components/line-items.js.map +1 -1
- package/dist/components/list.d.ts +25 -0
- package/dist/components/list.js +16 -5
- package/dist/components/list.js.map +1 -1
- package/dist/components/money-field.d.ts +32 -14
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-picker.d.ts +52 -4
- package/dist/components/month-picker.js +291 -86
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +26 -1
- package/dist/components/multi-entity-combobox.js +143 -102
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +8 -1
- package/dist/components/multi-select.js +9 -4
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +34 -19
- package/dist/components/number-field.js +6 -20
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.d.ts +79 -19
- package/dist/components/number-input.js +90 -38
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +19 -14
- package/dist/components/one-time-code-input.d.ts +100 -0
- package/dist/components/one-time-code-input.js +137 -0
- package/dist/components/one-time-code-input.js.map +1 -0
- package/dist/components/phone-input.d.ts +69 -0
- package/dist/components/phone-input.js +171 -0
- package/dist/components/phone-input.js.map +1 -0
- package/dist/components/reauth-dialog.d.ts +2 -2
- package/dist/components/reauth-dialog.js +6 -8
- package/dist/components/reauth-dialog.js.map +1 -1
- package/dist/components/series-chart.d.ts +19 -14
- package/dist/components/settings-fields.d.ts +19 -14
- package/dist/components/share-card.d.ts +16 -11
- package/dist/components/sign-chip.d.ts +66 -0
- package/dist/components/sign-chip.js +39 -0
- package/dist/components/sign-chip.js.map +1 -0
- package/dist/components/swatch-picker.d.ts +43 -2
- package/dist/components/swatch-picker.js +80 -32
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/switch.d.ts +19 -0
- package/dist/components/switch.js +24 -6
- package/dist/components/switch.js.map +1 -1
- package/dist/components/text-link.d.ts +18 -13
- package/dist/components/tile-radio.d.ts +88 -13
- package/dist/components/tile-radio.js +28 -11
- package/dist/components/tile-radio.js.map +1 -1
- package/dist/components/time-input.d.ts +24 -15
- package/dist/components/time-input.js.map +1 -1
- package/dist/components/toggle-group.d.ts +47 -1
- package/dist/components/toggle-group.js +110 -69
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/trigger-aria.d.ts +3 -0
- package/dist/components/trigger-aria.js +3 -1
- package/dist/components/trigger-aria.js.map +1 -1
- package/dist/components/ui.d.ts +16 -11
- package/dist/components/ui.js +284 -88
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -2
- package/dist/{data-table-3mi2R3so.d.ts → data-table-labels-B7OdnM0S.d.ts} +140 -3
- package/dist/data-table.d.ts +1 -2
- package/dist/data-table.js +2 -1
- package/dist/data-table.js.map +1 -1
- package/dist/feedback/feedback-attachment.d.ts +1 -1
- package/dist/feedback/feedback-attachment.js +348 -41
- package/dist/feedback/feedback-attachment.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +1 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +3 -2
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +68 -253
- package/dist/feedback/feedback-thread.js +46 -10
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/{kit-labels-D1J2_jyD.d.ts → feedback-BxeQVzwq.d.ts} +1206 -20
- package/dist/{feedback-attachment-WFiXJ8We.d.ts → feedback-attachment-fGAzZPf0.d.ts} +178 -11
- package/dist/feedback.d.ts +66 -2
- package/dist/hooks/use-file-drop.d.ts +19 -14
- package/dist/i18n/defaults.d.ts +19 -14
- package/dist/i18n/defaults.js +19 -2
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.d.ts +19 -14
- package/dist/i18n/german.js +84 -5
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -10
- package/dist/i18n/kit-labels.js +8 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/languages.d.ts +19 -14
- package/dist/i18n/locales/de-CH.d.ts +19 -14
- package/dist/i18n/locales/en.d.ts +19 -14
- package/dist/i18n/locales/en.js +16 -0
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +19 -14
- package/dist/i18n/locales/es.js +83 -5
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +19 -14
- package/dist/i18n/locales/fr.js +82 -5
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +19 -14
- package/dist/i18n/locales/hu.js +85 -5
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +19 -14
- package/dist/i18n/locales/it.js +84 -5
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +19 -14
- package/dist/i18n/locales/zh.js +80 -5
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +19 -14
- package/dist/i18n/review.js +27 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +21 -10
- package/dist/index.js +73 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/column-mapping.d.ts +81 -0
- package/dist/lib/column-mapping.js +108 -0
- package/dist/lib/column-mapping.js.map +1 -0
- package/dist/lib/countries.d.ts +43 -0
- package/dist/lib/countries.js +39 -0
- package/dist/lib/countries.js.map +1 -0
- package/dist/lib/decimal-marks.d.ts +46 -0
- package/dist/lib/decimal-marks.js +40 -0
- package/dist/lib/decimal-marks.js.map +1 -0
- package/dist/lib/iban.d.ts +98 -0
- package/dist/lib/iban.js +154 -0
- package/dist/lib/iban.js.map +1 -0
- package/dist/lib/isin.d.ts +30 -0
- package/dist/lib/isin.js +36 -0
- package/dist/lib/isin.js.map +1 -0
- package/dist/lib/phone.d.ts +69 -0
- package/dist/lib/phone.js +121 -0
- package/dist/lib/phone.js.map +1 -0
- package/dist/lib/table-text.d.ts +109 -1
- package/dist/lib/table-text.js +122 -1
- package/dist/lib/table-text.js.map +1 -1
- package/dist/rhf/fields.d.ts +233 -18
- package/dist/rhf/fields.js +456 -3
- package/dist/rhf/fields.js.map +1 -1
- package/dist/rhf/form.d.ts +19 -14
- package/dist/rhf.d.ts +22 -15
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +18 -13
- package/dist/shell/top-bar-brand.d.ts +19 -14
- package/dist/shell/topbar-action-menu.d.ts +36 -3
- package/dist/shell/topbar-action-menu.js +74 -33
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +18 -13
- package/dist/table-text.d.ts +1 -1
- package/dist/tour/tour.js +20 -24
- package/dist/tour/tour.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +49 -16
- package/dist/wizard/stepper-nav.js +4 -0
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard.d.ts +19 -14
- package/package.json +1 -1
- package/src/components/account-chips.tsx +17 -3
- package/src/components/account-settings.tsx +92 -26
- package/src/components/amount-input.tsx +68 -56
- package/src/components/autocomplete.tsx +198 -114
- package/src/components/checkbox-group.tsx +229 -0
- package/src/components/checkbox.tsx +72 -8
- package/src/components/chip.tsx +80 -10
- package/src/components/column-mapper.tsx +666 -0
- package/src/components/combobox-core.tsx +82 -9
- package/src/components/combobox.tsx +661 -340
- package/src/components/confirm-dialog.tsx +12 -8
- package/src/components/country-select.tsx +556 -0
- package/src/components/currency-select.tsx +109 -33
- package/src/components/danger-confirm.tsx +429 -82
- package/src/components/data-table-labels.ts +16 -1
- package/src/components/data-table.tsx +175 -6
- package/src/components/date-picker.tsx +595 -71
- package/src/components/entity-combobox.tsx +235 -124
- package/src/components/field-parts.tsx +403 -0
- package/src/components/field-strip.tsx +149 -0
- package/src/components/file-button.tsx +36 -3
- package/src/components/file-dropzone.tsx +106 -38
- package/src/components/form-actions.tsx +147 -6
- package/src/components/iban-input.tsx +231 -0
- package/src/components/icon-picker.tsx +47 -6
- package/src/components/inline-edit-field.tsx +533 -0
- package/src/components/language-select.tsx +78 -0
- package/src/components/line-items.tsx +35 -2
- package/src/components/list.tsx +55 -6
- package/src/components/money-field.tsx +13 -0
- package/src/components/month-picker.tsx +400 -63
- package/src/components/multi-entity-combobox.tsx +207 -120
- package/src/components/multi-select.tsx +80 -58
- package/src/components/number-field.tsx +28 -46
- package/src/components/number-input.tsx +210 -43
- package/src/components/one-time-code-input.tsx +288 -0
- package/src/components/phone-input.tsx +299 -0
- package/src/components/reauth-dialog.tsx +17 -18
- package/src/components/sign-chip.tsx +103 -0
- package/src/components/swatch-picker.tsx +143 -31
- package/src/components/switch.tsx +58 -7
- package/src/components/tile-radio.tsx +145 -29
- package/src/components/time-input.tsx +8 -1
- package/src/components/toggle-group.tsx +206 -73
- package/src/components/trigger-aria.ts +5 -0
- package/src/components/ui.tsx +479 -138
- package/src/data-table.ts +2 -1
- package/src/feedback/feedback-attachment.tsx +597 -46
- package/src/feedback/feedback-dialog.tsx +9 -3
- package/src/feedback/feedback-inbox.tsx +3 -2
- package/src/feedback/feedback-thread.tsx +113 -9
- package/src/i18n/defaults.ts +18 -1
- package/src/i18n/german.ts +89 -0
- package/src/i18n/kit-labels.tsx +82 -2
- package/src/i18n/locales/en.ts +36 -4
- package/src/i18n/locales/es.ts +87 -0
- package/src/i18n/locales/fr.ts +87 -0
- package/src/i18n/locales/hu.ts +83 -0
- package/src/i18n/locales/it.ts +88 -0
- package/src/i18n/locales/zh.ts +76 -0
- package/src/i18n/review.ts +26 -0
- package/src/index.ts +71 -3
- package/src/lib/column-mapping.ts +234 -0
- package/src/lib/countries.ts +91 -0
- package/src/lib/decimal-marks.ts +99 -0
- package/src/lib/iban.ts +171 -0
- package/src/lib/isin.ts +62 -0
- package/src/lib/phone.ts +211 -0
- package/src/lib/table-text.ts +271 -0
- package/src/rhf/fields.tsx +860 -9
- package/src/rhf.ts +3 -1
- package/src/shell/topbar-action-menu.tsx +134 -38
- package/src/tour/tour.tsx +66 -28
- package/src/wizard/stepper-nav.tsx +35 -1
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent, useState } from "react";
|
|
2
|
+
import type { ChangeEvent, DragEvent, ReactNode } from "react";
|
|
3
|
+
import { Upload } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { useKitLabels, useKitLocale } from "../i18n/kit-labels";
|
|
6
|
+
import { cn } from "../lib/cn";
|
|
7
|
+
import {
|
|
8
|
+
assignColumnRole,
|
|
9
|
+
guessMapping,
|
|
10
|
+
missingRoles,
|
|
11
|
+
readMappedTable,
|
|
12
|
+
readTextFile,
|
|
13
|
+
roleOfColumn,
|
|
14
|
+
} from "../lib/column-mapping";
|
|
15
|
+
import type {
|
|
16
|
+
ColumnMapperResult,
|
|
17
|
+
ColumnMapping,
|
|
18
|
+
ColumnRole,
|
|
19
|
+
} from "../lib/column-mapping";
|
|
20
|
+
import { parseTextTable } from "../lib/table-text";
|
|
21
|
+
import type { TableSeparator, TextTable } from "../lib/table-text";
|
|
22
|
+
import { AlertBanner } from "./alert-banner";
|
|
23
|
+
import { Checkbox } from "./checkbox";
|
|
24
|
+
import { Disclosure } from "./disclosure";
|
|
25
|
+
import { FileButton, useFilePicker } from "./file-button";
|
|
26
|
+
import {
|
|
27
|
+
Table,
|
|
28
|
+
TableBody,
|
|
29
|
+
TableCell,
|
|
30
|
+
TableHead,
|
|
31
|
+
TableHeaderCell,
|
|
32
|
+
TableRow,
|
|
33
|
+
} from "./table";
|
|
34
|
+
import { Select, Textarea } from "./ui";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A table pasted, dropped or chosen as a file, and which of its columns plays which
|
|
38
|
+
* part — Kurvenschmiede's columns input and keksdose's bank-file mapping step, once.
|
|
39
|
+
*
|
|
40
|
+
* Kurvenschmiede (`features/control/columns-input.tsx` + `csv.ts`) reads a recorder's
|
|
41
|
+
* export into a playground signal (time, value) and a comparison (time, setpoint,
|
|
42
|
+
* actual): a textarea, a file button, a parse, a select per role, and a line that says
|
|
43
|
+
* which decimal convention was assumed and how many lines were skipped. keksdose
|
|
44
|
+
* (`import-map-step.tsx`) shows a bank's CSV as a table with a role select on every
|
|
45
|
+
* column's header, the file's real values under it, ignored columns dimmed, and what
|
|
46
|
+
* the import still needs named under it. Same problem, two hand-built answers.
|
|
47
|
+
*
|
|
48
|
+
* Two layers, so both shapes fit:
|
|
49
|
+
*
|
|
50
|
+
* * {@link ColumnMapper} — the whole single panel: paste, drop or choose → parse
|
|
51
|
+
* ({@link parseTextTable}: separator, decimal convention, header line, all stated
|
|
52
|
+
* back) → preview with a role per column → `onChange(result)`. Kurvenschmiede's.
|
|
53
|
+
* * {@link ColumnRoleTable} — the preview with the role selects alone, controlled, over
|
|
54
|
+
* rows the caller already has. keksdose's map step, whose rows come from its server's
|
|
55
|
+
* sniff (encodings, quoted multi-line cells, skipped title rows) and whose mapping
|
|
56
|
+
* lives in the wizard's state between steps.
|
|
57
|
+
*
|
|
58
|
+
* The rules under both are headless in `lib/column-mapping.ts`: a role moves rather
|
|
59
|
+
* than doubling up, what is missing is named, and the rows a numeric role cannot read
|
|
60
|
+
* are reported by line number rather than dropped.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
// ── Labels ────────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
export interface ColumnMapperLabels {
|
|
66
|
+
/** The paste box's label. */
|
|
67
|
+
paste: string;
|
|
68
|
+
/** The caption under the paste box. */
|
|
69
|
+
pasteHint: string;
|
|
70
|
+
/** The file button. */
|
|
71
|
+
chooseFile: string;
|
|
72
|
+
/** A chosen or dropped file whose bytes could not be read at all. */
|
|
73
|
+
readError: (name: string) => string;
|
|
74
|
+
/** The checkbox that says whether the first line names the columns. */
|
|
75
|
+
headerRow: string;
|
|
76
|
+
/** What was read: so many columns and rows. */
|
|
77
|
+
summary: (columns: number, rows: number) => string;
|
|
78
|
+
/** The separator that was assumed. */
|
|
79
|
+
separatorSemicolon: string;
|
|
80
|
+
separatorComma: string;
|
|
81
|
+
separatorTab: string;
|
|
82
|
+
separatorSpace: string;
|
|
83
|
+
/** The decimal convention that was assumed — with an example, because "decimal
|
|
84
|
+
* comma" alone is a term, and `1,5` is something a reader recognises. */
|
|
85
|
+
decimalComma: string;
|
|
86
|
+
decimalPoint: string;
|
|
87
|
+
/** The title over the lines that could not be read. */
|
|
88
|
+
unreadCount: (count: number) => string;
|
|
89
|
+
/** One of them. */
|
|
90
|
+
unreadLine: (line: number) => string;
|
|
91
|
+
/** Past the first hundred listed. */
|
|
92
|
+
unreadMore: (count: number) => string;
|
|
93
|
+
/** The text has content, and none of it is a row. */
|
|
94
|
+
noRows: string;
|
|
95
|
+
/** The preview table's name. */
|
|
96
|
+
table: string;
|
|
97
|
+
/** A column the table names no header for. */
|
|
98
|
+
columnN: (n: number) => string;
|
|
99
|
+
/** The role select on a column's header — its accessible name. */
|
|
100
|
+
roleOf: (column: string) => string;
|
|
101
|
+
/** The role select's "no role" option. */
|
|
102
|
+
ignore: string;
|
|
103
|
+
/** A required role in the select. */
|
|
104
|
+
requiredRole: (role: string) => string;
|
|
105
|
+
/** Under the preview, when it shows fewer rows than were read. */
|
|
106
|
+
previewOf: (shown: number, total: number) => string;
|
|
107
|
+
/** A required group's roles, already joined as a list with "or". */
|
|
108
|
+
oneOf: (roles: string) => string;
|
|
109
|
+
/** What the table still needs, already joined as a list with "and". */
|
|
110
|
+
missing: (roles: string) => string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const DEFAULT_COLUMN_MAPPER_LABELS: ColumnMapperLabels = {
|
|
114
|
+
paste: "Paste a table",
|
|
115
|
+
pasteHint:
|
|
116
|
+
"Copy the rows out of a spreadsheet and paste them here, or drop a CSV or text file.",
|
|
117
|
+
chooseFile: "Choose a file",
|
|
118
|
+
readError: (name) => `“${name}” could not be read`,
|
|
119
|
+
headerRow: "The first line names the columns",
|
|
120
|
+
summary: (columns, rows) =>
|
|
121
|
+
`${columns} ${columns === 1 ? "column" : "columns"}, ${rows} ${rows === 1 ? "row" : "rows"}`,
|
|
122
|
+
separatorSemicolon: "separated by semicolons",
|
|
123
|
+
separatorComma: "separated by commas",
|
|
124
|
+
separatorTab: "separated by tabs",
|
|
125
|
+
separatorSpace: "separated by spaces",
|
|
126
|
+
decimalComma: "decimal comma (1,5)",
|
|
127
|
+
decimalPoint: "decimal point (1.5)",
|
|
128
|
+
unreadCount: (count) =>
|
|
129
|
+
count === 1
|
|
130
|
+
? "1 line could not be read"
|
|
131
|
+
: `${count} lines could not be read`,
|
|
132
|
+
unreadLine: (line) => `Line ${line} could not be read`,
|
|
133
|
+
unreadMore: (count) => `…and ${count} more`,
|
|
134
|
+
noRows: "No line of this text reads as a row of the table.",
|
|
135
|
+
table: "Columns and their roles",
|
|
136
|
+
columnN: (n) => `Column ${n}`,
|
|
137
|
+
roleOf: (column) => `What does column “${column}” hold?`,
|
|
138
|
+
ignore: "Ignore",
|
|
139
|
+
requiredRole: (role) => `${role} (required)`,
|
|
140
|
+
previewOf: (shown, total) =>
|
|
141
|
+
shown === 1
|
|
142
|
+
? `The first of ${total} rows`
|
|
143
|
+
: `The first ${shown} of ${total} rows`,
|
|
144
|
+
oneOf: (roles) => `either ${roles}`,
|
|
145
|
+
missing: (roles) => `Still needed: ${roles}.`,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const SEPARATOR_LABEL: Record<
|
|
149
|
+
TableSeparator,
|
|
150
|
+
"separatorSemicolon" | "separatorComma" | "separatorTab" | "separatorSpace"
|
|
151
|
+
> = {
|
|
152
|
+
";": "separatorSemicolon",
|
|
153
|
+
",": "separatorComma",
|
|
154
|
+
"\t": "separatorTab",
|
|
155
|
+
" ": "separatorSpace",
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** How many unread lines are listed before "…and N more". */
|
|
159
|
+
const UNREAD_LISTED = 100;
|
|
160
|
+
|
|
161
|
+
/** A file a table is likely to be in. Extensions only, so a refusal reads "Only .csv,
|
|
162
|
+
* .tsv, … files" rather than a list of MIME types; the parse is the real check. */
|
|
163
|
+
const DEFAULT_ACCEPT = ".csv,.tsv,.txt,.dat,.asc";
|
|
164
|
+
|
|
165
|
+
function formatList(
|
|
166
|
+
items: string[],
|
|
167
|
+
type: "conjunction" | "disjunction",
|
|
168
|
+
locale: string | undefined,
|
|
169
|
+
): string {
|
|
170
|
+
try {
|
|
171
|
+
return new Intl.ListFormat(locale, { type, style: "long" }).format(items);
|
|
172
|
+
} catch {
|
|
173
|
+
return items.join(", ");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── ColumnRoleTable ───────────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
export interface ColumnRoleTableProps<
|
|
180
|
+
R extends string,
|
|
181
|
+
M extends ColumnMapping<R> = ColumnMapping<R>,
|
|
182
|
+
> {
|
|
183
|
+
/** The columns' names — the file's header line — or `null` for a table without one
|
|
184
|
+
* (each column is then "Column 1", "Column 2", …). */
|
|
185
|
+
header: readonly string[] | null;
|
|
186
|
+
/** The rows to preview, as text. Only the first {@link previewRows} are drawn. */
|
|
187
|
+
rows: readonly (readonly string[])[];
|
|
188
|
+
/** How many columns. Default: the header's length or the widest previewed row. */
|
|
189
|
+
width?: number;
|
|
190
|
+
/** The parts a column can play. */
|
|
191
|
+
roles: readonly ColumnRole<R>[];
|
|
192
|
+
/** Role → column. Any object with the roles as nullable number fields — keksdose's
|
|
193
|
+
* `CsvMapping` as it stands; the other fields are handed back untouched. */
|
|
194
|
+
mapping: M;
|
|
195
|
+
/** The next mapping, with the picked role moved onto its column. */
|
|
196
|
+
onMappingChange: (next: M) => void;
|
|
197
|
+
/** Default 5. */
|
|
198
|
+
previewRows?: number;
|
|
199
|
+
/** How many rows the table has in all, for "The first 5 of 120 rows". Default:
|
|
200
|
+
* `rows.length`. */
|
|
201
|
+
totalRows?: number;
|
|
202
|
+
/** Every role select disabled — keksdose locks them while a re-sniff replaces the
|
|
203
|
+
* table they point into. */
|
|
204
|
+
disabled?: boolean;
|
|
205
|
+
labels?: Partial<ColumnMapperLabels>;
|
|
206
|
+
className?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A table's first rows, with a role select on every column's header.
|
|
211
|
+
*
|
|
212
|
+
* keksdose's mapping step (dev#462: "make it more table like, where the table columns
|
|
213
|
+
* can be chosen from the input and the column data changes with the chosen column
|
|
214
|
+
* header"): the file IS the form. The file's own column name sits on top, verbatim —
|
|
215
|
+
* it is how the reader recognises the column; under it the role, picked in place;
|
|
216
|
+
* under that the column's real values, so a column that is one off shows up here and
|
|
217
|
+
* not after the import. A column with no role says "Ignore" and its values are dimmed:
|
|
218
|
+
* the state that most needs to be visible in a twelve-column bank export.
|
|
219
|
+
*
|
|
220
|
+
* Picking a role another column holds MOVES it ({@link assignColumnRole}). Required
|
|
221
|
+
* roles say so in the list, and what the table still needs is named under it — a
|
|
222
|
+
* required group as "either Amount, Debit or Credit".
|
|
223
|
+
*
|
|
224
|
+
* The table scrolls sideways inside its own box (the kit {@link Table}'s wrapper, a
|
|
225
|
+
* named, keyboard-reachable region while it overflows), so a wide export never widens
|
|
226
|
+
* the page at 390px.
|
|
227
|
+
*/
|
|
228
|
+
export function ColumnRoleTable<
|
|
229
|
+
R extends string,
|
|
230
|
+
M extends ColumnMapping<R> = ColumnMapping<R>,
|
|
231
|
+
>({
|
|
232
|
+
header,
|
|
233
|
+
rows,
|
|
234
|
+
width: widthProp,
|
|
235
|
+
roles,
|
|
236
|
+
mapping,
|
|
237
|
+
onMappingChange,
|
|
238
|
+
previewRows = 5,
|
|
239
|
+
totalRows,
|
|
240
|
+
disabled,
|
|
241
|
+
labels: labelsProp,
|
|
242
|
+
className,
|
|
243
|
+
}: ColumnRoleTableProps<R, M>) {
|
|
244
|
+
const labels: ColumnMapperLabels = useKitLabels(
|
|
245
|
+
"columnMapper",
|
|
246
|
+
DEFAULT_COLUMN_MAPPER_LABELS,
|
|
247
|
+
labelsProp,
|
|
248
|
+
);
|
|
249
|
+
const locale = useKitLocale();
|
|
250
|
+
const shown = rows.slice(0, previewRows);
|
|
251
|
+
const width =
|
|
252
|
+
widthProp ??
|
|
253
|
+
shown.reduce(
|
|
254
|
+
(widest, row) => Math.max(widest, row.length),
|
|
255
|
+
header?.length ?? 0,
|
|
256
|
+
);
|
|
257
|
+
const columns = Array.from({ length: width }, (_, index) => index);
|
|
258
|
+
const total = totalRows ?? rows.length;
|
|
259
|
+
const nameOf = (column: number) =>
|
|
260
|
+
header?.[column] || labels.columnN(column + 1);
|
|
261
|
+
const labelOf = (value: R) =>
|
|
262
|
+
roles.find((role) => role.value === value)?.label ?? value;
|
|
263
|
+
const gaps = missingRoles(roles, mapping, width).map((gap) =>
|
|
264
|
+
gap.length === 1
|
|
265
|
+
? labelOf(gap[0])
|
|
266
|
+
: labels.oneOf(formatList(gap.map(labelOf), "disjunction", locale)),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
className={cn("min-w-0 space-y-1.5", className)}
|
|
272
|
+
data-slot="column-role-table"
|
|
273
|
+
>
|
|
274
|
+
<Table density="compact" framed aria-label={labels.table}>
|
|
275
|
+
<TableHead>
|
|
276
|
+
<TableRow>
|
|
277
|
+
{columns.map((column) => {
|
|
278
|
+
const role = roleOfColumn(roles, mapping, column);
|
|
279
|
+
const name = nameOf(column);
|
|
280
|
+
return (
|
|
281
|
+
<TableHeaderCell
|
|
282
|
+
key={column}
|
|
283
|
+
scope="col"
|
|
284
|
+
className="min-w-36 py-2 align-top"
|
|
285
|
+
>
|
|
286
|
+
<span className="block max-w-56 truncate pb-1 text-[11px] font-normal text-[var(--text-muted)]">
|
|
287
|
+
{name}
|
|
288
|
+
</span>
|
|
289
|
+
<Select
|
|
290
|
+
size="sm"
|
|
291
|
+
className="w-full"
|
|
292
|
+
aria-label={labels.roleOf(name)}
|
|
293
|
+
value={role ?? ""}
|
|
294
|
+
disabled={disabled}
|
|
295
|
+
onChange={(event) =>
|
|
296
|
+
onMappingChange(
|
|
297
|
+
assignColumnRole(
|
|
298
|
+
roles,
|
|
299
|
+
mapping,
|
|
300
|
+
column,
|
|
301
|
+
event.target.value === ""
|
|
302
|
+
? null
|
|
303
|
+
: (event.target.value as R),
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
>
|
|
308
|
+
<option value="">{labels.ignore}</option>
|
|
309
|
+
{roles.map((option) => (
|
|
310
|
+
<option key={option.value} value={option.value}>
|
|
311
|
+
{option.required === true
|
|
312
|
+
? labels.requiredRole(option.label)
|
|
313
|
+
: option.label}
|
|
314
|
+
</option>
|
|
315
|
+
))}
|
|
316
|
+
</Select>
|
|
317
|
+
</TableHeaderCell>
|
|
318
|
+
);
|
|
319
|
+
})}
|
|
320
|
+
</TableRow>
|
|
321
|
+
</TableHead>
|
|
322
|
+
<TableBody>
|
|
323
|
+
{shown.map((row, index) => (
|
|
324
|
+
<TableRow key={index}>
|
|
325
|
+
{columns.map((column) => (
|
|
326
|
+
<TableCell
|
|
327
|
+
key={column}
|
|
328
|
+
data-ignored={
|
|
329
|
+
roleOfColumn(roles, mapping, column) === null || undefined
|
|
330
|
+
}
|
|
331
|
+
className={cn(
|
|
332
|
+
"font-mono whitespace-nowrap",
|
|
333
|
+
// Dimmed, not hidden: its values are what tell you whether ignoring
|
|
334
|
+
// it was right.
|
|
335
|
+
roleOfColumn(roles, mapping, column) === null &&
|
|
336
|
+
"text-[var(--text-muted)]",
|
|
337
|
+
)}
|
|
338
|
+
>
|
|
339
|
+
<span className="block max-w-56 truncate">
|
|
340
|
+
{row[column] ?? ""}
|
|
341
|
+
</span>
|
|
342
|
+
</TableCell>
|
|
343
|
+
))}
|
|
344
|
+
</TableRow>
|
|
345
|
+
))}
|
|
346
|
+
</TableBody>
|
|
347
|
+
</Table>
|
|
348
|
+
{total > shown.length && (
|
|
349
|
+
<p className="text-xs text-[var(--text-muted)]">
|
|
350
|
+
{labels.previewOf(shown.length, total)}
|
|
351
|
+
</p>
|
|
352
|
+
)}
|
|
353
|
+
{gaps.length > 0 && (
|
|
354
|
+
<AlertBanner tone="warning" variant="inline" size="sm" block>
|
|
355
|
+
{labels.missing(formatList(gaps, "conjunction", locale))}
|
|
356
|
+
</AlertBanner>
|
|
357
|
+
)}
|
|
358
|
+
</div>
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ── ColumnMapper ──────────────────────────────────────────────────────────────
|
|
363
|
+
|
|
364
|
+
export interface ColumnMapperProps<R extends string> {
|
|
365
|
+
/** The parts the columns play — translated labels, which are required, which must
|
|
366
|
+
* be numbers. See {@link ColumnRole}. */
|
|
367
|
+
roles: readonly ColumnRole<R>[];
|
|
368
|
+
/**
|
|
369
|
+
* The table read through the current mapping, on every change: the text, the header
|
|
370
|
+
* checkbox, a role. `null` while there is no table at all (an empty box). Use it when
|
|
371
|
+
* `result.complete`; until then `result.missing` says what is not placed yet.
|
|
372
|
+
*
|
|
373
|
+
* The rows are strings. A numeric role's cells are guaranteed to read with
|
|
374
|
+
* `tableNumber(cell, result.decimalComma)`; anything else is the caller's to convert.
|
|
375
|
+
*/
|
|
376
|
+
onChange: (result: ColumnMapperResult<R> | null) => void;
|
|
377
|
+
/** The paste box's label. Default: `labels.paste`. */
|
|
378
|
+
label?: ReactNode;
|
|
379
|
+
/** The caption under the paste box. Default: `labels.pasteHint`. */
|
|
380
|
+
hint?: ReactNode;
|
|
381
|
+
/** What the file dialog offers, and what a drop is checked against. Default:
|
|
382
|
+
* `.csv,.tsv,.txt,.dat,.asc`. */
|
|
383
|
+
accept?: string;
|
|
384
|
+
/** The largest file taken, in bytes. Default: no limit. */
|
|
385
|
+
maxSize?: number;
|
|
386
|
+
/** Text to start with. `onChange` is called with its result once, on mount. */
|
|
387
|
+
defaultText?: string;
|
|
388
|
+
/** Rows in the preview. Default 5. */
|
|
389
|
+
previewRows?: number;
|
|
390
|
+
/** The first mapping for a new table. Default {@link guessMapping}: a column named
|
|
391
|
+
* like a role gets it, and the required roles left over take the free columns in
|
|
392
|
+
* order. */
|
|
393
|
+
guess?: (table: TextTable) => ColumnMapping<R>;
|
|
394
|
+
disabled?: boolean;
|
|
395
|
+
labels?: Partial<ColumnMapperLabels>;
|
|
396
|
+
className?: string;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface MapperState<R extends string> {
|
|
400
|
+
text: string;
|
|
401
|
+
/** The reader's answer to "does the first line name the columns", or `null` for
|
|
402
|
+
* the parse's own. */
|
|
403
|
+
header: boolean | null;
|
|
404
|
+
table: TextTable;
|
|
405
|
+
mapping: ColumnMapping<R>;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const hasFiles = (event: DragEvent) =>
|
|
409
|
+
Array.from(event.dataTransfer?.types ?? []).includes("Files");
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Paste, drop or choose a table, see what it was read as, and say which column is
|
|
413
|
+
* which — Kurvenschmiede's playground signal and comparison input as one kit part.
|
|
414
|
+
*
|
|
415
|
+
* Everything the parse assumed is stated, because a guess the reader cannot see is a
|
|
416
|
+
* guess they cannot correct: the shape it found, the separator, the decimal
|
|
417
|
+
* convention ("decimal comma (1,5)"), and every line it could not read, by number and
|
|
418
|
+
* with its text. The header line is a checkbox, since the detection is a guess either
|
|
419
|
+
* way and toggling it does not move a column (the mapping is kept, keksdose's
|
|
420
|
+
* `keepRoles`). A new file is a new table and is mapped afresh; typing that changes the
|
|
421
|
+
* column count re-guesses, because the old indexes point at nothing.
|
|
422
|
+
*
|
|
423
|
+
* A file can be chosen, dropped on the button, or dropped on the paste box — which,
|
|
424
|
+
* left to the browser, would open the file in place of the page. It is read as UTF-8,
|
|
425
|
+
* or as Windows-1252 when it is not UTF-8 ({@link readTextFile}).
|
|
426
|
+
*
|
|
427
|
+
* A two-step wizard that keeps the drop and the mapping apart (keksdose's) uses the
|
|
428
|
+
* parts: {@link parseTextTable} or its own server's sniff, then {@link ColumnRoleTable},
|
|
429
|
+
* then {@link readMappedTable}.
|
|
430
|
+
*/
|
|
431
|
+
export function ColumnMapper<R extends string>({
|
|
432
|
+
roles,
|
|
433
|
+
onChange,
|
|
434
|
+
label,
|
|
435
|
+
hint,
|
|
436
|
+
accept = DEFAULT_ACCEPT,
|
|
437
|
+
maxSize,
|
|
438
|
+
defaultText = "",
|
|
439
|
+
previewRows = 5,
|
|
440
|
+
guess,
|
|
441
|
+
disabled = false,
|
|
442
|
+
labels: labelsProp,
|
|
443
|
+
className,
|
|
444
|
+
}: ColumnMapperProps<R>) {
|
|
445
|
+
const labels: ColumnMapperLabels = useKitLabels(
|
|
446
|
+
"columnMapper",
|
|
447
|
+
DEFAULT_COLUMN_MAPPER_LABELS,
|
|
448
|
+
labelsProp,
|
|
449
|
+
);
|
|
450
|
+
const firstMapping = (table: TextTable) =>
|
|
451
|
+
guess ? guess(table) : guessMapping(roles, table.header, table.width);
|
|
452
|
+
const [state, setState] = useState<MapperState<R>>(() => {
|
|
453
|
+
const table = parseTextTable(defaultText);
|
|
454
|
+
return {
|
|
455
|
+
text: defaultText,
|
|
456
|
+
header: null,
|
|
457
|
+
table,
|
|
458
|
+
mapping: firstMapping(table),
|
|
459
|
+
};
|
|
460
|
+
});
|
|
461
|
+
const [reading, setReading] = useState(false);
|
|
462
|
+
const [refusal, setRefusal] = useState<string | null>(null);
|
|
463
|
+
const [dragOver, setDragOver] = useState(false);
|
|
464
|
+
|
|
465
|
+
// What is drawn and what is handed over are the same computation. Not memoised: a
|
|
466
|
+
// caller writes `roles={[…]}` inline, so a memo keyed on them would miss every time,
|
|
467
|
+
// and the read is one pass over rows that are already split.
|
|
468
|
+
const result = readMappedTable(state.table, roles, state.mapping);
|
|
469
|
+
|
|
470
|
+
const commit = (next: MapperState<R>) => {
|
|
471
|
+
setState(next);
|
|
472
|
+
onChange(
|
|
473
|
+
next.table.width === 0
|
|
474
|
+
? null
|
|
475
|
+
: readMappedTable(next.table, roles, next.mapping),
|
|
476
|
+
);
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/** New text. `fresh` (a file): the reader's header answer and the mapping start over. */
|
|
480
|
+
const take = (text: string, fresh: boolean) => {
|
|
481
|
+
const header = fresh ? null : state.header;
|
|
482
|
+
const table = parseTextTable(text, header === null ? {} : { header });
|
|
483
|
+
const keep =
|
|
484
|
+
!fresh && table.width === state.table.width && state.table.width > 0;
|
|
485
|
+
commit({
|
|
486
|
+
text,
|
|
487
|
+
header,
|
|
488
|
+
table,
|
|
489
|
+
mapping: keep ? state.mapping : firstMapping(table),
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const load = (file: File) => {
|
|
494
|
+
setRefusal(null);
|
|
495
|
+
setReading(true);
|
|
496
|
+
void readTextFile(file)
|
|
497
|
+
.then(
|
|
498
|
+
(text) => take(text, true),
|
|
499
|
+
// Only the read: an error thrown by the caller's onChange is not the file's.
|
|
500
|
+
() => setRefusal(labels.readError(file.name)),
|
|
501
|
+
)
|
|
502
|
+
.finally(() => setReading(false));
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
const refuse = (rejections: { message: string }[]) =>
|
|
506
|
+
setRefusal(rejections[0]?.message ?? null);
|
|
507
|
+
|
|
508
|
+
// A file dropped on the paste box. The same screening as the button's.
|
|
509
|
+
const drop = useFilePicker({
|
|
510
|
+
accept,
|
|
511
|
+
maxSize,
|
|
512
|
+
disabled,
|
|
513
|
+
onFiles: ([file]) => load(file),
|
|
514
|
+
onReject: refuse,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const seeded = useEffectEvent(() => {
|
|
518
|
+
if (state.table.width > 0) onChange(result);
|
|
519
|
+
});
|
|
520
|
+
useEffect(() => {
|
|
521
|
+
seeded();
|
|
522
|
+
}, []);
|
|
523
|
+
|
|
524
|
+
const { table } = state;
|
|
525
|
+
const separator = labels[SEPARATOR_LABEL[table.separator]];
|
|
526
|
+
const unread = result.unread;
|
|
527
|
+
|
|
528
|
+
return (
|
|
529
|
+
<div
|
|
530
|
+
className={cn("min-w-0 space-y-3", className)}
|
|
531
|
+
data-slot="column-mapper"
|
|
532
|
+
>
|
|
533
|
+
<Textarea
|
|
534
|
+
label={label ?? labels.paste}
|
|
535
|
+
hint={hint ?? labels.pasteHint}
|
|
536
|
+
rows={5}
|
|
537
|
+
wrap="off"
|
|
538
|
+
spellCheck={false}
|
|
539
|
+
autoCapitalize="off"
|
|
540
|
+
autoCorrect="off"
|
|
541
|
+
value={state.text}
|
|
542
|
+
disabled={disabled}
|
|
543
|
+
className={cn(
|
|
544
|
+
"font-mono text-xs",
|
|
545
|
+
dragOver && "rounded-md ring-2 ring-[var(--brand)]",
|
|
546
|
+
)}
|
|
547
|
+
data-drag-over={dragOver || undefined}
|
|
548
|
+
onChange={(event: ChangeEvent<HTMLTextAreaElement>) => {
|
|
549
|
+
setRefusal(null);
|
|
550
|
+
take(event.target.value, false);
|
|
551
|
+
}}
|
|
552
|
+
onDragEnter={(event) => {
|
|
553
|
+
if (!hasFiles(event)) return;
|
|
554
|
+
event.preventDefault();
|
|
555
|
+
if (!disabled) setDragOver(true);
|
|
556
|
+
}}
|
|
557
|
+
onDragOver={(event) => {
|
|
558
|
+
if (!hasFiles(event)) return;
|
|
559
|
+
// Cancelled for every file drag: an uncancelled one makes the browser open
|
|
560
|
+
// the file in place of the page.
|
|
561
|
+
event.preventDefault();
|
|
562
|
+
event.dataTransfer.dropEffect = disabled ? "none" : "copy";
|
|
563
|
+
}}
|
|
564
|
+
onDragLeave={() => setDragOver(false)}
|
|
565
|
+
onDrop={(event) => {
|
|
566
|
+
if (!hasFiles(event)) return;
|
|
567
|
+
event.preventDefault();
|
|
568
|
+
setDragOver(false);
|
|
569
|
+
drop.take(event.dataTransfer.files);
|
|
570
|
+
}}
|
|
571
|
+
/>
|
|
572
|
+
{drop.element}
|
|
573
|
+
|
|
574
|
+
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
|
575
|
+
<FileButton
|
|
576
|
+
variant="secondary"
|
|
577
|
+
accept={accept}
|
|
578
|
+
maxSize={maxSize}
|
|
579
|
+
droppable
|
|
580
|
+
pending={reading}
|
|
581
|
+
disabled={disabled}
|
|
582
|
+
onFiles={([file]) => load(file)}
|
|
583
|
+
onReject={refuse}
|
|
584
|
+
>
|
|
585
|
+
<Upload className="size-4" aria-hidden />
|
|
586
|
+
{labels.chooseFile}
|
|
587
|
+
</FileButton>
|
|
588
|
+
{table.width > 0 && (
|
|
589
|
+
<Checkbox
|
|
590
|
+
label={labels.headerRow}
|
|
591
|
+
checked={table.header !== null}
|
|
592
|
+
disabled={disabled}
|
|
593
|
+
onCheckedChange={(checked) => {
|
|
594
|
+
const next = parseTextTable(state.text, { header: checked });
|
|
595
|
+
// Same text, same split: the columns are where they were, and so are the
|
|
596
|
+
// roles on them.
|
|
597
|
+
commit({ ...state, header: checked, table: next });
|
|
598
|
+
}}
|
|
599
|
+
/>
|
|
600
|
+
)}
|
|
601
|
+
</div>
|
|
602
|
+
|
|
603
|
+
{refusal && (
|
|
604
|
+
<AlertBanner tone="danger" variant="inline" size="sm" block>
|
|
605
|
+
{refusal}
|
|
606
|
+
</AlertBanner>
|
|
607
|
+
)}
|
|
608
|
+
|
|
609
|
+
{table.width > 0 && (
|
|
610
|
+
<>
|
|
611
|
+
<p
|
|
612
|
+
className="text-xs text-[var(--text-secondary)]"
|
|
613
|
+
data-slot="column-mapper-summary"
|
|
614
|
+
>
|
|
615
|
+
{[
|
|
616
|
+
labels.summary(table.width, result.rows.length),
|
|
617
|
+
separator,
|
|
618
|
+
table.decimalComma ? labels.decimalComma : labels.decimalPoint,
|
|
619
|
+
].join(" · ")}
|
|
620
|
+
</p>
|
|
621
|
+
{result.rows.length === 0 && (
|
|
622
|
+
<AlertBanner tone="warning" variant="inline" size="sm" block>
|
|
623
|
+
{labels.noRows}
|
|
624
|
+
</AlertBanner>
|
|
625
|
+
)}
|
|
626
|
+
<ColumnRoleTable
|
|
627
|
+
header={table.header}
|
|
628
|
+
rows={result.rows}
|
|
629
|
+
width={table.width}
|
|
630
|
+
roles={roles}
|
|
631
|
+
mapping={state.mapping}
|
|
632
|
+
onMappingChange={(mapping) => commit({ ...state, mapping })}
|
|
633
|
+
previewRows={previewRows}
|
|
634
|
+
disabled={disabled}
|
|
635
|
+
labels={labelsProp}
|
|
636
|
+
/>
|
|
637
|
+
{unread.length > 0 && (
|
|
638
|
+
<Disclosure
|
|
639
|
+
variant="bare"
|
|
640
|
+
title={labels.unreadCount(unread.length)}
|
|
641
|
+
data-slot="column-mapper-unread"
|
|
642
|
+
>
|
|
643
|
+
<ul className="space-y-1 text-xs">
|
|
644
|
+
{unread.slice(0, UNREAD_LISTED).map((line) => (
|
|
645
|
+
<li key={line.line} className="min-w-0">
|
|
646
|
+
<span className="block text-[var(--text-secondary)]">
|
|
647
|
+
{labels.unreadLine(line.line)}
|
|
648
|
+
</span>
|
|
649
|
+
<code className="block truncate font-mono text-[var(--text-muted)]">
|
|
650
|
+
{line.text}
|
|
651
|
+
</code>
|
|
652
|
+
</li>
|
|
653
|
+
))}
|
|
654
|
+
{unread.length > UNREAD_LISTED && (
|
|
655
|
+
<li className="text-[var(--text-muted)]">
|
|
656
|
+
{labels.unreadMore(unread.length - UNREAD_LISTED)}
|
|
657
|
+
</li>
|
|
658
|
+
)}
|
|
659
|
+
</ul>
|
|
660
|
+
</Disclosure>
|
|
661
|
+
)}
|
|
662
|
+
</>
|
|
663
|
+
)}
|
|
664
|
+
</div>
|
|
665
|
+
);
|
|
666
|
+
}
|