@updog/data-editor 0.1.88 → 0.1.90

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 (3) hide show
  1. package/index.d.ts +83 -2
  2. package/index.js +2653 -2543
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1286,7 +1286,7 @@ type ColumnFormat = {
1286
1286
  * `license.*` codes cover license validation failures (previously a separate
1287
1287
  * `LicenseErrorCode` enum).
1288
1288
  */
1289
- type UpdogErrorCode = "PARSE_ERROR" | "RENDER_ERROR" | "TRANSFORM_ERROR" | "VALIDATION_ERROR" | "WORKER_ERROR" | "COMMAND_ERROR" | "OPERATION_ERROR" | "license.invalid" | "license.missing" | "license.domain_not_allowed" | "license.subscription_inactive" | "license.trial_expired";
1289
+ type UpdogErrorCode = "PARSE_ERROR" | "RENDER_ERROR" | "TRANSFORM_ERROR" | "VALIDATION_ERROR" | "WORKER_ERROR" | "COMMAND_ERROR" | "OPERATION_ERROR" | "HOOK_ERROR" | "license.invalid" | "license.missing" | "license.domain_not_allowed" | "license.subscription_inactive" | "license.trial_expired";
1290
1290
  /**
1291
1291
  * An internal error caught by the SDK and passed to `onError`. The SDK
1292
1292
  * recovers gracefully where possible — `onError` is for your logging and
@@ -2250,6 +2250,11 @@ declare class DataStore<TRow extends DataEditorRow = DataEditorRow> {
2250
2250
  * the dialog is out of scope (spec section 10).
2251
2251
  */
2252
2252
  private reportAmbiguity;
2253
+ /**
2254
+ * `fieldReader`, public: the value takes the column's storage shape; a
2255
+ * field outside the schema returns it untouched.
2256
+ */
2257
+ readFieldValue(field: string, value: unknown): unknown;
2253
2258
  /**
2254
2259
  * The column's reader with no verdict behind it. A formula result is one
2255
2260
  * value, so there is nothing to vote on; the reader is here to give the
@@ -2469,6 +2474,48 @@ type ColumnDelta = {
2469
2474
  newValues: Map<TRowId, unknown>;
2470
2475
  };
2471
2476
 
2477
+ /** One input row: the schema shape after reading plus the raw file row. */
2478
+ type RowImportInputRow = {
2479
+ /**
2480
+ * Keys are your schema column ids; values went through format reading,
2481
+ * value mapping, and the column's `transformer`.
2482
+ */
2483
+ row: Record<string, unknown>;
2484
+ /**
2485
+ * Keys are the file's headers, unmapped ones included; values are the
2486
+ * cell texts as they appear in the file.
2487
+ */
2488
+ raw: Record<string, string>;
2489
+ };
2490
+ type RowImportMeta = {
2491
+ /** Zero-based chunk number within the current workbook. */
2492
+ chunkIndex: number;
2493
+ /** Total number of chunks in the current workbook. */
2494
+ chunkCount: number;
2495
+ isLastChunk: boolean;
2496
+ /** The workbook being imported: source name, sheet (XLSX), file headers. */
2497
+ workbook: {
2498
+ name: string;
2499
+ sheetName?: string;
2500
+ headers: string[];
2501
+ };
2502
+ /** This workbook's column mapping: file header → schema column id. */
2503
+ mapping: Record<string, string | undefined>;
2504
+ /** The `context` prop, untouched. */
2505
+ context: unknown;
2506
+ /**
2507
+ * Aborted when the import is cancelled and when the chunk's 30-second
2508
+ * timeout fires; hand it to your own fetch.
2509
+ */
2510
+ signal: AbortSignal;
2511
+ };
2512
+ /**
2513
+ * Chunk in, chunk out. The returned array is positional: element `i` answers
2514
+ * `rows[i]`, `null` drops that row, elements past `rows.length` append new
2515
+ * rows. Returning nothing leaves the chunk as it is.
2516
+ */
2517
+ type RowImportHook = (rows: RowImportInputRow[], meta: RowImportMeta) => (Record<string, unknown> | null)[] | void | Promise<(Record<string, unknown> | null)[] | void>;
2518
+
2472
2519
  /** Numeric row identifier. V8 stores small integers (Smi) inline — no heap allocation. */
2473
2520
  type TRowId = number;
2474
2521
  type SortType = "text" | "number" | "date" | "time";
@@ -2960,6 +3007,40 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
2960
3007
  * ```
2961
3008
  */
2962
3009
  onValueMatch?: (valuesToMatch: Record<string, ValueMatchInput>) => ValueMatchOutput | Promise<ValueMatchOutput>;
3010
+ /**
3011
+ * Edit, drop, or append rows between the file and the editor. Called once
3012
+ * per chunk of 5,000 rows of each imported workbook, after every cell went
3013
+ * through format reading, value mapping, and the column's `transformer` —
3014
+ * the raw file row rides along in `raw`, unmapped headers included.
3015
+ *
3016
+ * The returned array is positional: element `i` replaces `rows[i].row`,
3017
+ * `null` drops that row, elements past `rows.length` append new rows.
3018
+ * Return nothing to leave the chunk as it is. Every field the hook changed
3019
+ * is re-read as if it came from the file — format reading, value mapping,
3020
+ * and `transformer` run again on it.
3021
+ *
3022
+ * A thrown error, a timeout of 30 seconds per chunk, or an array shorter
3023
+ * than the input counts as a failure: the chunk lands unchanged, one
3024
+ * `HOOK_ERROR` reaches `onError`, and the hook stays off for the rest of
3025
+ * that import run.
3026
+ *
3027
+ * @example
3028
+ * ```ts
3029
+ * // Split "USD 100" from the file's price column into two schema fields.
3030
+ * onRowImport={(rows) =>
3031
+ * rows.map(({ row, raw }) => {
3032
+ * const [currency, amount] = (raw["price"] ?? "").split(" ");
3033
+ * return { ...row, currency, amount };
3034
+ * })
3035
+ * }
3036
+ * ```
3037
+ */
3038
+ onRowImport?: RowImportHook;
3039
+ /**
3040
+ * Anything you want your hooks to see: `onRowImport` receives it untouched
3041
+ * as `meta.context`.
3042
+ */
3043
+ context?: unknown;
2963
3044
  /**
2964
3045
  * Extra synonyms layered on top of the built-ins, in two tables that stay
2965
3046
  * apart: `columns` scores a file header against your columns, `values`
@@ -3154,4 +3235,4 @@ declare function exportDataEditor<TRow extends DataEditorRow>(params: ExportPara
3154
3235
  declare function DataEditor<TRow extends DataEditorRow = DataEditorRow>(allProps: DataEditorProps<TRow>): react.JSX.Element;
3155
3236
 
3156
3237
  export { DataEditor, downloadExampleFile, exportDataEditor };
3157
- 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 };
3238
+ 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, RowImportHook, RowImportInputRow, RowImportMeta, UpdogError, UpdogErrorCode, ValidationError, ValueMatchInput, ValueMatchOutput };