@updog/data-editor-wc 0.1.74 → 0.1.76

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.
Files changed (4) hide show
  1. package/index.css +1 -1
  2. package/index.d.ts +74 -13
  3. package/index.js +4064 -3818
  4. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -483,6 +483,8 @@ declare var export_default = {
483
483
  csvWarning_one: "{{count}} row had formatting issues (row {{rows}})",
484
484
  csvWarning_other:
485
485
  "{{count}} rows had formatting issues (rows {{rows}})",
486
+ customEmpty: "No tables were found in this file",
487
+ customFailed: "Could not process the file",
486
488
  downloadExample: "Download sample file",
487
489
  fileInputLabel: "Choose files to upload",
488
490
  fileTooLarge: "The file is too large to process",
@@ -529,6 +531,7 @@ declare var export_default = {
529
531
  "Unmatched columns won't be imported. Match this column to keep the data. You can transform columns after importing.",
530
532
  },
531
533
  sheetPreview: {
534
+ cancel: "Cancel processing",
532
535
  emptySheet: "Empty sheet",
533
536
  rowCount_one: "{{count}} row",
534
537
  rowCount_other: "{{count}} rows",
@@ -1147,8 +1150,13 @@ type DataEditorResult<TRow extends DataEditorRow = DataEditorRow> = {
1147
1150
  invalid: number;
1148
1151
  };
1149
1152
  /**
1150
- * Import mappings the user confirmed that weren't already known, split into
1151
- * `columns` and `values`. Persist and feed back through `synonyms` so repeat
1153
+ * Import mappings the user changed **by hand** in the wizard, split into
1154
+ * `columns` (header column title) and `values` (imported value option).
1155
+ * Mappings the SDK matched on its own are excluded, as are mappings returned
1156
+ * by `onColumnMatch` / `onValueMatch` and pairs the synonym tables already
1157
+ * cover. A cancelled import contributes nothing.
1158
+ *
1159
+ * Persist and feed back through `synonyms` — the shapes line up — so repeat
1152
1160
  * imports auto-match. Each list is `[]` when nothing new was learned.
1153
1161
  */
1154
1162
  learnedSynonyms: LearnedSynonyms;
@@ -1256,6 +1264,47 @@ type RemoteSource = {
1256
1264
  */
1257
1265
  fetch: () => Promise<File | Record<string, unknown>[]>;
1258
1266
  };
1267
+ /** One table returned by a custom format handler. */
1268
+ type CustomImportTable = {
1269
+ /** Table name, shown on the preview card. */
1270
+ name: string;
1271
+ rows: Record<string, unknown>[];
1272
+ };
1273
+ /**
1274
+ * A file format the SDK cannot read, handled by client code.
1275
+ *
1276
+ * The SDK accepts the file, hands it to `handle()`, and stages whatever comes
1277
+ * back. You own the processing; nothing about the file reaches Updog.
1278
+ *
1279
+ * @example
1280
+ * ```ts
1281
+ * const pdf: CustomImportFormat = {
1282
+ * label: "PDF",
1283
+ * extensions: [".pdf"],
1284
+ * handle: async (file, { signal }) => {
1285
+ * const body = new FormData();
1286
+ * body.append("file", file);
1287
+ * const res = await fetch("/api/extract", { method: "POST", body, signal });
1288
+ * return res.json(); // Record<string, unknown>[]
1289
+ * },
1290
+ * };
1291
+ * ```
1292
+ */
1293
+ type CustomImportFormat = {
1294
+ /** Shown in the format hint under the drop zone, e.g. "PDF". */
1295
+ label: string;
1296
+ /** Extensions this handler claims, leading dot included. */
1297
+ extensions: string[];
1298
+ /** Optional MIME match, wildcards allowed: `["image/*"]`. */
1299
+ mimeTypes?: string[];
1300
+ /**
1301
+ * Returns rows, named tables, or a `File` in a format the SDK already reads.
1302
+ * Throw to fail the import; the thrown message is shown to the user.
1303
+ */
1304
+ handle: (file: File, ctx: {
1305
+ signal: AbortSignal;
1306
+ }) => Promise<File | Record<string, unknown>[] | CustomImportTable[]>;
1307
+ };
1259
1308
  /**
1260
1309
  * Controls the initial view when the editor opens.
1261
1310
  *
@@ -1371,6 +1420,11 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
1371
1420
  * the result of `fetch()`.
1372
1421
  */
1373
1422
  remoteSources?: RemoteSource[];
1423
+ /**
1424
+ * File formats the SDK cannot read, handled by your own code. The SDK accepts
1425
+ * the file and stages whatever `handle()` returns.
1426
+ */
1427
+ customFormats?: CustomImportFormat[];
1374
1428
  /**
1375
1429
  * Which file formats the user can export to. `undefined` allows all
1376
1430
  * formats, `false` disables export entirely.
@@ -1420,24 +1474,31 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
1420
1474
  */
1421
1475
  onValueMatch?: (valuesToMatch: Record<string, ValueMatchInput>) => ValueMatchOutput | Promise<ValueMatchOutput>;
1422
1476
  /**
1423
- * Extra synonyms layered on top of the built-ins for both column matching
1424
- * (header vs column) and value matching (imported value vs select option).
1425
- * Each key is the canonical target (a column ID/title, or a select option
1426
- * value); the array lists aliases the matching engine should treat as
1427
- * equivalent. Merged with the built-ins as a union per key.
1477
+ * Extra synonyms layered on top of the built-ins, in two tables that stay
1478
+ * apart: `columns` scores a file header against your columns, `values`
1479
+ * scores an imported cell against a select option. Each key is the canonical
1480
+ * target (a column ID/title, or an option value); the array lists aliases the
1481
+ * matching engine treats as equivalent. Merged with the built-ins per key.
1482
+ *
1483
+ * Feed `result.learnedSynonyms` straight back — it comes out in this shape.
1428
1484
  *
1429
1485
  * @example
1430
1486
  * ```ts
1431
1487
  * synonyms={{
1432
- * // column aliases
1433
- * productSku: ["sku", "article_no", "item_code"],
1434
- * firstName: ["first", "given_name", "fname"],
1435
- * // value aliases (e.g. for a "status" select)
1436
- * Active: ["live", "enabled"],
1488
+ * columns: {
1489
+ * productSku: ["sku", "article_no", "item_code"],
1490
+ * firstName: ["first", "given_name", "fname"],
1491
+ * },
1492
+ * values: {
1493
+ * Active: ["live", "enabled"],
1494
+ * },
1437
1495
  * }}
1438
1496
  * ```
1439
1497
  */
1440
- synonyms?: Record<string, string[]>;
1498
+ synonyms?: {
1499
+ columns?: Record<string, string[]>;
1500
+ values?: Record<string, string[]>;
1501
+ };
1441
1502
  /**
1442
1503
  * Sample rows included in the "Download Example" file. When the user clicks
1443
1504
  * "Download Example" in the import wizard, the SDK generates a template