@updog/data-editor-wc 0.1.88 → 0.1.89

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 +72 -1
  2. package/index.js +608 -550
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1121,7 +1121,7 @@ type DataEditorChat<TRow extends DataEditorRow = DataEditorRow> = {
1121
1121
  * `license.*` codes cover license validation failures (previously a separate
1122
1122
  * `LicenseErrorCode` enum).
1123
1123
  */
1124
- 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";
1124
+ 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";
1125
1125
  /**
1126
1126
  * An internal error caught by the SDK and passed to `onError`. The SDK
1127
1127
  * recovers gracefully where possible — `onError` is for your logging and
@@ -1147,6 +1147,43 @@ type UpdogError = {
1147
1147
  originalError?: unknown;
1148
1148
  };
1149
1149
 
1150
+ /** One input row: the schema shape after reading plus the raw file row. */
1151
+ type RowImportInputRow = {
1152
+ /**
1153
+ * Keys are your schema column ids; values went through format reading,
1154
+ * value mapping, and the column's `transformer`.
1155
+ */
1156
+ row: Record<string, unknown>;
1157
+ /**
1158
+ * Keys are the file's headers, unmapped ones included; values are the
1159
+ * cell texts as they appear in the file.
1160
+ */
1161
+ raw: Record<string, string>;
1162
+ };
1163
+ type RowImportMeta = {
1164
+ /** Zero-based chunk number within the current workbook. */
1165
+ chunkIndex: number;
1166
+ /** Total number of chunks in the current workbook. */
1167
+ chunkCount: number;
1168
+ isLastChunk: boolean;
1169
+ /** The workbook being imported: source name, sheet (XLSX), file headers. */
1170
+ workbook: {
1171
+ name: string;
1172
+ sheetName?: string;
1173
+ headers: string[];
1174
+ };
1175
+ /** This workbook's column mapping: file header → schema column id. */
1176
+ mapping: Record<string, string | undefined>;
1177
+ /** The `context` prop, untouched. */
1178
+ context: unknown;
1179
+ };
1180
+ /**
1181
+ * Chunk in, chunk out. The returned array is positional: element `i` answers
1182
+ * `rows[i]`, `null` drops that row, elements past `rows.length` append new
1183
+ * rows. Returning nothing leaves the chunk as it is.
1184
+ */
1185
+ type RowImportHook = (rows: RowImportInputRow[], meta: RowImportMeta) => (Record<string, unknown> | null)[] | void | Promise<(Record<string, unknown> | null)[] | void>;
1186
+
1150
1187
  /**
1151
1188
  * A single row in the submit result, with orthogonal flags describing its state.
1152
1189
  *
@@ -1561,6 +1598,40 @@ type DataEditorBaseProps<TRow extends DataEditorRow = DataEditorRow> = {
1561
1598
  * ```
1562
1599
  */
1563
1600
  onValueMatch?: (valuesToMatch: Record<string, ValueMatchInput>) => ValueMatchOutput | Promise<ValueMatchOutput>;
1601
+ /**
1602
+ * Edit, drop, or append rows between the file and the editor. Called once
1603
+ * per chunk of 5,000 rows of each imported workbook, after every cell went
1604
+ * through format reading, value mapping, and the column's `transformer` —
1605
+ * the raw file row rides along in `raw`, unmapped headers included.
1606
+ *
1607
+ * The returned array is positional: element `i` replaces `rows[i].row`,
1608
+ * `null` drops that row, elements past `rows.length` append new rows.
1609
+ * Return nothing to leave the chunk as it is. Every field the hook changed
1610
+ * is re-read as if it came from the file — format reading, value mapping,
1611
+ * and `transformer` run again on it.
1612
+ *
1613
+ * A thrown error, a timeout of 30 seconds per chunk, or an array shorter
1614
+ * than the input counts as a failure: the chunk lands unchanged, one
1615
+ * `HOOK_ERROR` reaches `onError`, and the hook stays off for the rest of
1616
+ * that import run.
1617
+ *
1618
+ * @example
1619
+ * ```ts
1620
+ * // Split "USD 100" from the file's price column into two schema fields.
1621
+ * onRowImport={(rows) =>
1622
+ * rows.map(({ row, raw }) => {
1623
+ * const [currency, amount] = (raw["price"] ?? "").split(" ");
1624
+ * return { ...row, currency, amount };
1625
+ * })
1626
+ * }
1627
+ * ```
1628
+ */
1629
+ onRowImport?: RowImportHook;
1630
+ /**
1631
+ * Anything you want your hooks to see: `onRowImport` receives it untouched
1632
+ * as `meta.context`.
1633
+ */
1634
+ context?: unknown;
1564
1635
  /**
1565
1636
  * Extra synonyms layered on top of the built-ins, in two tables that stay
1566
1637
  * apart: `columns` scores a file header against your columns, `values`