@updog/data-editor 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.
package/index.d.ts CHANGED
@@ -485,6 +485,8 @@ declare var export_default = {
485
485
  csvWarning_one: "{{count}} row had formatting issues (row {{rows}})",
486
486
  csvWarning_other:
487
487
  "{{count}} rows had formatting issues (rows {{rows}})",
488
+ customEmpty: "No tables were found in this file",
489
+ customFailed: "Could not process the file",
488
490
  downloadExample: "Download sample file",
489
491
  fileInputLabel: "Choose files to upload",
490
492
  fileTooLarge: "The file is too large to process",
@@ -531,6 +533,7 @@ declare var export_default = {
531
533
  "Unmatched columns won't be imported. Match this column to keep the data. You can transform columns after importing.",
532
534
  },
533
535
  sheetPreview: {
536
+ cancel: "Cancel processing",
534
537
  emptySheet: "Empty sheet",
535
538
  rowCount_one: "{{count}} row",
536
539
  rowCount_other: "{{count}} rows",
@@ -1550,21 +1553,6 @@ declare class ErrorHandler {
1550
1553
  handleError(error: UpdogError): void;
1551
1554
  }
1552
1555
 
1553
- type UniqueConfig = {
1554
- message?: string;
1555
- fn?: UniqueRemoteFn;
1556
- };
1557
- /**
1558
- * Core-internal column shape produced by normalizeUniqueColumns. Uniqueness
1559
- * lives in `uniqueConfig` and asyncFunction rules in `asyncConfig` — the
1560
- * single internal sources of truth — never as entries in `validators`.
1561
- * Never exported from the package entry.
1562
- */
1563
- type NormalizedColumn = DataEditorColumn & {
1564
- uniqueConfig?: UniqueConfig;
1565
- asyncConfig?: AsyncFunctionValidator[];
1566
- };
1567
-
1568
1556
  type FormulaCellContext = {
1569
1557
  value: unknown;
1570
1558
  field: string;
@@ -1648,6 +1636,21 @@ declare class FormulaRegistry {
1648
1636
  getExpressionCallable(): FormulaDefinition[];
1649
1637
  }
1650
1638
 
1639
+ type UniqueConfig = {
1640
+ message?: string;
1641
+ fn?: UniqueRemoteFn;
1642
+ };
1643
+ /**
1644
+ * Core-internal column shape produced by normalizeUniqueColumns. Uniqueness
1645
+ * lives in `uniqueConfig` and asyncFunction rules in `asyncConfig` — the
1646
+ * single internal sources of truth — never as entries in `validators`.
1647
+ * Never exported from the package entry.
1648
+ */
1649
+ type NormalizedColumn = DataEditorColumn & {
1650
+ uniqueConfig?: UniqueConfig;
1651
+ asyncConfig?: AsyncFunctionValidator[];
1652
+ };
1653
+
1651
1654
  type RegisterSourceOptions = {
1652
1655
  name: string;
1653
1656
  id?: DataSourceId;
@@ -1659,6 +1662,8 @@ type MergeEntry<TRow> = {
1659
1662
  sourceId: DataSourceId;
1660
1663
  isNew: boolean;
1661
1664
  isEdited: boolean;
1665
+ /** Diff basis the row carried before the merge. Present only when isEdited. */
1666
+ originalRow?: TRow;
1662
1667
  };
1663
1668
  type RemovalPlan<TRow> = {
1664
1669
  rowsToDelete: Set<TRowId>;
@@ -1668,6 +1673,7 @@ type RemovalPlan<TRow> = {
1668
1673
  originalSourceId: DataSourceId;
1669
1674
  isNew: boolean;
1670
1675
  isEdited: boolean;
1676
+ originalRow?: TRow;
1671
1677
  }>;
1672
1678
  };
1673
1679
  type ExtendedRemovalPlan<TRow> = RemovalPlan<TRow> & {
@@ -1702,7 +1708,7 @@ declare class SourceManager<TRow extends DataEditorRow = DataEditorRow> {
1702
1708
  finalizeAllSources(): void;
1703
1709
  values(): IterableIterator<DataSourceState>;
1704
1710
  getHiddenSourceIds(): Set<DataSourceId>;
1705
- saveMergeSnapshot(sourceId: DataSourceId, rowId: TRowId, existingRow: TRow, previousSourceId: DataSourceId, isNew: boolean, isEdited: boolean): void;
1711
+ saveMergeSnapshot(sourceId: DataSourceId, rowId: TRowId, existingRow: TRow, previousSourceId: DataSourceId, isNew: boolean, isEdited: boolean, originalRow?: TRow): void;
1706
1712
  /**
1707
1713
  * Public so commands can re-install merge entries during undo of a remove.
1708
1714
  */
@@ -1939,9 +1945,8 @@ type IDirtyTracker<TRow extends DataEditorRow = DataEditorRow> = {
1939
1945
  hasOriginalRow(id: TRowId): boolean;
1940
1946
  trackNonBackendRow(id: TRowId): void;
1941
1947
  markNew(id: TRowId): void;
1942
- markEdited(id: TRowId): void;
1943
- snapshotOriginal(id: TRowId, row: TRow): void;
1944
1948
  classifyOnFirstEdit(id: TRowId, row: TRow): void;
1949
+ classifyOverwrite(id: TRowId, originalRow: TRow, currentRow: TRow): void;
1945
1950
  checkRevert(id: TRowId, currentRow: TRow): {
1946
1951
  wasNew: boolean;
1947
1952
  wasEdited: boolean;
@@ -1953,7 +1958,7 @@ type IDirtyTracker<TRow extends DataEditorRow = DataEditorRow> = {
1953
1958
  isNew: boolean;
1954
1959
  isEdited: boolean;
1955
1960
  };
1956
- restoreMergeClassification(id: TRowId, isNew: boolean, isEdited: boolean): void;
1961
+ restoreMergeClassification(id: TRowId, isNew: boolean, isEdited: boolean, originalRow?: TRow): void;
1957
1962
  clear(): void;
1958
1963
  };
1959
1964
 
@@ -2733,6 +2738,7 @@ declare class DataStore<TRow extends DataEditorRow = DataEditorRow> {
2733
2738
  clearColumn(field: string): Promise<void>;
2734
2739
  clearColumns(fields: string[]): Promise<void>;
2735
2740
  private syncClearToServer;
2741
+ purgeField(columnId: string, rowIds?: TRowId[]): void;
2736
2742
  deleteColumn(columnId: string): Promise<void>;
2737
2743
  deleteColumns(columnIds: readonly string[]): Promise<void>;
2738
2744
  clearRange(rects: SelectionRect[]): Promise<void>;
@@ -2890,8 +2896,13 @@ type DataEditorResult<TRow extends DataEditorRow = DataEditorRow> = {
2890
2896
  invalid: number;
2891
2897
  };
2892
2898
  /**
2893
- * Import mappings the user confirmed that weren't already known, split into
2894
- * `columns` and `values`. Persist and feed back through `synonyms` so repeat
2899
+ * Import mappings the user changed **by hand** in the wizard, split into
2900
+ * `columns` (header column title) and `values` (imported value option).
2901
+ * Mappings the SDK matched on its own are excluded, as are mappings returned
2902
+ * by `onColumnMatch` / `onValueMatch` and pairs the synonym tables already
2903
+ * cover. A cancelled import contributes nothing.
2904
+ *
2905
+ * Persist and feed back through `synonyms` — the shapes line up — so repeat
2895
2906
  * imports auto-match. Each list is `[]` when nothing new was learned.
2896
2907
  */
2897
2908
  learnedSynonyms: LearnedSynonyms;
@@ -3061,6 +3072,47 @@ type RemoteSource = {
3061
3072
  */
3062
3073
  fetch: () => Promise<File | Record<string, unknown>[]>;
3063
3074
  };
3075
+ /** One table returned by a custom format handler. */
3076
+ type CustomImportTable = {
3077
+ /** Table name, shown on the preview card. */
3078
+ name: string;
3079
+ rows: Record<string, unknown>[];
3080
+ };
3081
+ /**
3082
+ * A file format the SDK cannot read, handled by client code.
3083
+ *
3084
+ * The SDK accepts the file, hands it to `handle()`, and stages whatever comes
3085
+ * back. You own the processing; nothing about the file reaches Updog.
3086
+ *
3087
+ * @example
3088
+ * ```ts
3089
+ * const pdf: CustomImportFormat = {
3090
+ * label: "PDF",
3091
+ * extensions: [".pdf"],
3092
+ * handle: async (file, { signal }) => {
3093
+ * const body = new FormData();
3094
+ * body.append("file", file);
3095
+ * const res = await fetch("/api/extract", { method: "POST", body, signal });
3096
+ * return res.json(); // Record<string, unknown>[]
3097
+ * },
3098
+ * };
3099
+ * ```
3100
+ */
3101
+ type CustomImportFormat = {
3102
+ /** Shown in the format hint under the drop zone, e.g. "PDF". */
3103
+ label: string;
3104
+ /** Extensions this handler claims, leading dot included. */
3105
+ extensions: string[];
3106
+ /** Optional MIME match, wildcards allowed: `["image/*"]`. */
3107
+ mimeTypes?: string[];
3108
+ /**
3109
+ * Returns rows, named tables, or a `File` in a format the SDK already reads.
3110
+ * Throw to fail the import; the thrown message is shown to the user.
3111
+ */
3112
+ handle: (file: File, ctx: {
3113
+ signal: AbortSignal;
3114
+ }) => Promise<File | Record<string, unknown>[] | CustomImportTable[]>;
3115
+ };
3064
3116
  /**
3065
3117
  * Controls the initial view when the editor opens.
3066
3118
  *
@@ -3176,6 +3228,11 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
3176
3228
  * the result of `fetch()`.
3177
3229
  */
3178
3230
  remoteSources?: RemoteSource[];
3231
+ /**
3232
+ * File formats the SDK cannot read, handled by your own code. The SDK accepts
3233
+ * the file and stages whatever `handle()` returns.
3234
+ */
3235
+ customFormats?: CustomImportFormat[];
3179
3236
  /**
3180
3237
  * Which file formats the user can export to. `undefined` allows all
3181
3238
  * formats, `false` disables export entirely.
@@ -3225,24 +3282,31 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
3225
3282
  */
3226
3283
  onValueMatch?: (valuesToMatch: Record<string, ValueMatchInput>) => ValueMatchOutput | Promise<ValueMatchOutput>;
3227
3284
  /**
3228
- * Extra synonyms layered on top of the built-ins for both column matching
3229
- * (header vs column) and value matching (imported value vs select option).
3230
- * Each key is the canonical target (a column ID/title, or a select option
3231
- * value); the array lists aliases the matching engine should treat as
3232
- * equivalent. Merged with the built-ins as a union per key.
3285
+ * Extra synonyms layered on top of the built-ins, in two tables that stay
3286
+ * apart: `columns` scores a file header against your columns, `values`
3287
+ * scores an imported cell against a select option. Each key is the canonical
3288
+ * target (a column ID/title, or an option value); the array lists aliases the
3289
+ * matching engine treats as equivalent. Merged with the built-ins per key.
3290
+ *
3291
+ * Feed `result.learnedSynonyms` straight back — it comes out in this shape.
3233
3292
  *
3234
3293
  * @example
3235
3294
  * ```ts
3236
3295
  * synonyms={{
3237
- * // column aliases
3238
- * productSku: ["sku", "article_no", "item_code"],
3239
- * firstName: ["first", "given_name", "fname"],
3240
- * // value aliases (e.g. for a "status" select)
3241
- * Active: ["live", "enabled"],
3296
+ * columns: {
3297
+ * productSku: ["sku", "article_no", "item_code"],
3298
+ * firstName: ["first", "given_name", "fname"],
3299
+ * },
3300
+ * values: {
3301
+ * Active: ["live", "enabled"],
3302
+ * },
3242
3303
  * }}
3243
3304
  * ```
3244
3305
  */
3245
- synonyms?: Record<string, string[]>;
3306
+ synonyms?: {
3307
+ columns?: Record<string, string[]>;
3308
+ values?: Record<string, string[]>;
3309
+ };
3246
3310
  /**
3247
3311
  * Sample rows included in the "Download Example" file. When the user clicks
3248
3312
  * "Download Example" in the import wizard, the SDK generates a template
@@ -3414,4 +3478,4 @@ declare function exportDataEditor<TRow extends DataEditorRow>(params: ExportPara
3414
3478
  declare function DataEditor<TRow extends DataEditorRow = DataEditorRow>(allProps: DataEditorProps<TRow>): react_jsx_runtime.JSX.Element;
3415
3479
 
3416
3480
  export { DataEditor, downloadExampleFile, exportDataEditor };
3417
- export type { CellValidator, ChatContext, ChatErrorSummary, ChatResponseChunk, ChatRow, ChatRowStatus, ChunkSourceOptions, DataEditorChat, DataEditorColumn, DataEditorFormat, DataEditorInlineProps, DataEditorLocalStorage, DataEditorModalProps, DataEditorMode, DataEditorProps, DataEditorResult, DataEditorRow, DataEditorSourceResult, DataEditorTranslations, DataEditorVariant, InitialRowChange, RemoteSource, ResultRow, UpdogError, UpdogErrorCode, ValidationError, ValueMatchInput, ValueMatchOutput };
3481
+ export type { CellValidator, ChatContext, ChatErrorSummary, ChatResponseChunk, ChatRow, ChatRowStatus, ChunkSourceOptions, CustomImportFormat, CustomImportTable, DataEditorChat, DataEditorColumn, DataEditorFormat, DataEditorInlineProps, DataEditorLocalStorage, DataEditorModalProps, DataEditorMode, DataEditorProps, DataEditorResult, DataEditorRow, DataEditorSourceResult, DataEditorTranslations, DataEditorVariant, InitialRowChange, RemoteSource, ResultRow, UpdogError, UpdogErrorCode, ValidationError, ValueMatchInput, ValueMatchOutput };