grist-widget-sdk 0.5.1 → 0.6.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/CHANGELOG.md +21 -0
- package/dist/actions.cjs +96 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +36 -0
- package/dist/actions.d.ts +36 -0
- package/dist/actions.js +29 -0
- package/dist/actions.js.map +1 -0
- package/dist/app.cjs +45 -7
- package/dist/app.cjs.map +1 -1
- package/dist/app.d.cts +3 -2
- package/dist/app.d.ts +3 -2
- package/dist/app.js +4 -3
- package/dist/{chunk-4ZGVKGDF.js → chunk-A4KFKOEQ.js} +2 -58
- package/dist/chunk-A4KFKOEQ.js.map +1 -0
- package/dist/{chunk-OXA2VITC.js → chunk-CMN4M4S3.js} +6 -4
- package/dist/{chunk-OXA2VITC.js.map → chunk-CMN4M4S3.js.map} +1 -1
- package/dist/{chunk-MAPAWVQC.js → chunk-DKCRFNAW.js} +104 -17
- package/dist/chunk-DKCRFNAW.js.map +1 -0
- package/dist/{chunk-P5I5MRC6.js → chunk-TUPCTWE5.js} +2 -2
- package/dist/chunk-YGQXH2P5.js +81 -0
- package/dist/chunk-YGQXH2P5.js.map +1 -0
- package/dist/{define-widget-B1FIvI-h.d.cts → define-widget-CYYdqRmB.d.cts} +39 -29
- package/dist/{define-widget-B9gEtJP0.d.ts → define-widget-D-NmSglS.d.ts} +39 -29
- package/dist/emulator/testing.cjs +45 -7
- package/dist/emulator/testing.cjs.map +1 -1
- package/dist/emulator/testing.d.cts +1 -0
- package/dist/emulator/testing.d.ts +1 -0
- package/dist/emulator/testing.js +5 -4
- package/dist/emulator/testing.js.map +1 -1
- package/dist/emulator.cjs.map +1 -1
- package/dist/emulator.js +3 -2
- package/dist/index.cjs +128 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +12 -11
- package/dist/{mount-grist-widget-Dtelqao_.d.cts → mount-grist-widget-D0mr__ga.d.cts} +1 -1
- package/dist/{mount-grist-widget-CkB-3iG_.d.ts → mount-grist-widget-DVcFl5Ys.d.ts} +1 -1
- package/package.json +11 -1
- package/dist/chunk-4ZGVKGDF.js.map +0 -1
- package/dist/chunk-MAPAWVQC.js.map +0 -1
- /package/dist/{chunk-P5I5MRC6.js.map → chunk-TUPCTWE5.js.map} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { e as GristReplicaColumn, f as GristRowRecord, i as GristReadyOptions, j as GristFetchSelectedOptions, k as GristTableOperations, o as GristApplyUserActionsOptions, c as GristCursorPos, b as GristWidgetColumnMap } from './types-DBStn0Dk.cjs';
|
|
2
|
+
import { GristUserActionTuple } from './actions.cjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Typed reads, with read-only access: each mapped cell checked against the
|
|
@@ -180,30 +181,6 @@ type FetchGristTableRowsOptions = {
|
|
|
180
181
|
/** Turn `fetchTable` output into row objects (order follows the `id` column). */
|
|
181
182
|
declare function tableDataToRows<T = Record<string, unknown>>(data: GristColumnarTable): GristRowRecord<T>[];
|
|
182
183
|
|
|
183
|
-
/**
|
|
184
|
-
* Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.
|
|
185
|
-
* @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions
|
|
186
|
-
*/
|
|
187
|
-
type GristUserActionTuple = unknown[];
|
|
188
|
-
/** `["UpdateRecord", tableId, rowId, { col: value, ... }]` */
|
|
189
|
-
declare function gristUpdateRecordAction(tableId: string, rowId: number, patch: Record<string, unknown>): GristUserActionTuple;
|
|
190
|
-
/** `["AddRecord", tableId, null, { col: value, ... }]` */
|
|
191
|
-
declare function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple;
|
|
192
|
-
/** `["RemoveRecord", tableId, rowId]` */
|
|
193
|
-
declare function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple;
|
|
194
|
-
/** `["AddColumn", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */
|
|
195
|
-
declare function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
196
|
-
/** `["AddVisibleColumn", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */
|
|
197
|
-
declare function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
198
|
-
/** `["RenameColumn", tableId, colId, newColId]` */
|
|
199
|
-
declare function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple;
|
|
200
|
-
/** `["ModifyColumn", tableId, colId, colInfo]` */
|
|
201
|
-
declare function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
202
|
-
/** `["RemoveColumn", tableId, colId]` */
|
|
203
|
-
declare function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple;
|
|
204
|
-
/** `["AddTable", tableId, tableInfo]` */
|
|
205
|
-
declare function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple;
|
|
206
|
-
|
|
207
184
|
/**
|
|
208
185
|
* The alerts `mountGristWidget()` shows above a running widget: what needs the
|
|
209
186
|
* user's attention in Grist (column mapping, access, a failed write, an
|
|
@@ -262,10 +239,39 @@ type GristColumnInfo = {
|
|
|
262
239
|
formula?: string;
|
|
263
240
|
description?: string;
|
|
264
241
|
};
|
|
242
|
+
/** `fetchRows()` options: rows (the default) or Grist's columns. */
|
|
243
|
+
type FetchRowsOptions = FetchGristTableRowsOptions & {
|
|
244
|
+
/** Grist's column-oriented payload (`{ id: [...], Name: [...] }`) instead of rows. */
|
|
245
|
+
columnar?: boolean;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* A table's rows, each `{ id, ...cells }` under real column ids. Without a
|
|
249
|
+
* table id, the widget's own table as its section shows it (filters and
|
|
250
|
+
* sort applied); with one, any table (full access), in Grist's row order.
|
|
251
|
+
* `{ columnar: true }` gives Grist's columns instead.
|
|
252
|
+
*/
|
|
253
|
+
type FetchRows = {
|
|
254
|
+
<T extends Record<string, unknown> = Record<string, unknown>>(tableId?: string | null, options?: FetchRowsOptions & {
|
|
255
|
+
columnar?: false;
|
|
256
|
+
}): Promise<GristRowRecord<T>[]>;
|
|
257
|
+
<T extends Record<string, unknown> = Record<string, unknown>>(options: FetchRowsOptions & {
|
|
258
|
+
columnar?: false;
|
|
259
|
+
}): Promise<GristRowRecord<T>[]>;
|
|
260
|
+
(tableId: string | null | undefined, options: FetchRowsOptions & {
|
|
261
|
+
columnar: true;
|
|
262
|
+
}): Promise<GristColumnarTable>;
|
|
263
|
+
(options: FetchRowsOptions & {
|
|
264
|
+
columnar: true;
|
|
265
|
+
}): Promise<GristColumnarTable>;
|
|
266
|
+
};
|
|
265
267
|
type GristApi = {
|
|
266
268
|
reload: () => Promise<void>;
|
|
269
|
+
fetchRows: FetchRows;
|
|
270
|
+
/** @deprecated Use `fetchRows({ columnar: true })` (or `fetchRows()` for rows). */
|
|
267
271
|
fetchSelectedTable: (options?: GristFetchSelectedOptions) => Promise<GristColumnarTable>;
|
|
272
|
+
/** @deprecated Use `fetchRows(tableId, { columnar: true })` (or `fetchRows(tableId)` for rows). */
|
|
268
273
|
fetchTable: (tableId: string) => Promise<GristColumnarTable>;
|
|
274
|
+
/** @deprecated Use `fetchRows(tableId, options)`. */
|
|
269
275
|
fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: FetchGristTableRowsOptions) => Promise<GristRowRecord<T>[]>;
|
|
270
276
|
listTables: (options?: ListTablesOptions) => Promise<string[]>;
|
|
271
277
|
listColumns: (tableId: string, options?: ListColumnsOptions) => Promise<GristColumnInfo[]>;
|
|
@@ -313,8 +319,9 @@ type GristWidgetMode = "empty" | "row" | "new-row";
|
|
|
313
319
|
type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = Omit<GristApi, "fetchTableRows"> & {
|
|
314
320
|
/** `"booting"` until Grist answers, then `"ready"`; `"unavailable"` outside Grist; `"error"` otherwise. */
|
|
315
321
|
status: GristWidgetStatus;
|
|
316
|
-
/**
|
|
322
|
+
/** @deprecated Use `status`: `status !== "unavailable"` once it isn't `"booting"`. */
|
|
317
323
|
isAvailable: boolean | null;
|
|
324
|
+
/** @deprecated Use `status === "ready"`. */
|
|
318
325
|
isReady: boolean;
|
|
319
326
|
/** Why the widget can't run (status `"error"` or `"unavailable"`), else null. */
|
|
320
327
|
error: string | null;
|
|
@@ -359,7 +366,7 @@ type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unk
|
|
|
359
366
|
addRecord: (patch: GristRecordPatch<TMapped>) => Promise<number>;
|
|
360
367
|
/** The section's table id. */
|
|
361
368
|
currentTableId: string | null;
|
|
362
|
-
/**
|
|
369
|
+
/** @deprecated Use `fetchRows(tableId, options)`. */
|
|
363
370
|
fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: Parameters<GristApi["fetchTableRows"]>[1]) => Promise<GristRowRecord<T>[]>;
|
|
364
371
|
/** The last write's state. */
|
|
365
372
|
actionStatus: GristWidgetActionStatus;
|
|
@@ -375,7 +382,10 @@ type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unk
|
|
|
375
382
|
declare function useGrist<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(options?: UseGristOptions): UseGristResult<TRow, TMapped>;
|
|
376
383
|
/** `useGrist()` inside a provider, or null outside one: for components that also work without Grist. */
|
|
377
384
|
declare function useGristOptional<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped> | null;
|
|
378
|
-
/**
|
|
385
|
+
/**
|
|
386
|
+
* `useGrist()` inside `<GristWidgetProvider>`; throws outside one.
|
|
387
|
+
* @deprecated Use `widget.useGrist()` (or `useGrist()`): `mountGristWidget()` always renders the provider.
|
|
388
|
+
*/
|
|
379
389
|
declare function useGristContext<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped>;
|
|
380
390
|
|
|
381
391
|
/**
|
|
@@ -429,5 +439,5 @@ type GristWidget<D extends GristWidgetDefinition = GristWidgetDefinition> = {
|
|
|
429
439
|
*/
|
|
430
440
|
declare function defineGristWidget<const D extends GristWidgetDefinition>(definition: D): GristWidget<D>;
|
|
431
441
|
|
|
432
|
-
export {
|
|
433
|
-
export type { GristWidget as G, ListColumnsOptions as L, StandardSchema as S, UseGristOptions as U, ValidateColumnMappingsResult as V, GristNoiseColumnsOptions as a,
|
|
442
|
+
export { tableDataToRows as A, useGrist as B, useGristContext as C, useGristOptional as D, checkGristCell as s, defineGristWidget as t, encodeGristCell as u, extractGristAttachmentId as v, extractGristAttachmentIdsFromCell as w, gristAttachmentCellValue as x, gristAttachmentCellValues as y, mergeGristAttachmentCellValue as z };
|
|
443
|
+
export type { FetchRows as F, GristWidget as G, ListColumnsOptions as L, StandardSchema as S, UseGristOptions as U, ValidateColumnMappingsResult as V, GristNoiseColumnsOptions as a, FetchRowsOptions as b, GristAttachmentUploadResult as c, GristCellIssue as d, GristColumnInfo as e, GristColumnarTable as f, GristFetchedAttachmentBlob as g, GristMappedRow as h, GristRecordPatch as i, GristSdkAlertKind as j, GristTheme as k, GristWidgetActionStatus as l, GristWidgetDefinition as m, GristWidgetMode as n, GristWidgetRow as o, GristWidgetStatus as p, ListTablesOptions as q, UseGristResult as r };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { e as GristReplicaColumn, f as GristRowRecord, i as GristReadyOptions, j as GristFetchSelectedOptions, k as GristTableOperations, o as GristApplyUserActionsOptions, c as GristCursorPos, b as GristWidgetColumnMap } from './types-DBStn0Dk.js';
|
|
2
|
+
import { GristUserActionTuple } from './actions.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Typed reads, with read-only access: each mapped cell checked against the
|
|
@@ -180,30 +181,6 @@ type FetchGristTableRowsOptions = {
|
|
|
180
181
|
/** Turn `fetchTable` output into row objects (order follows the `id` column). */
|
|
181
182
|
declare function tableDataToRows<T = Record<string, unknown>>(data: GristColumnarTable): GristRowRecord<T>[];
|
|
182
183
|
|
|
183
|
-
/**
|
|
184
|
-
* Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.
|
|
185
|
-
* @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions
|
|
186
|
-
*/
|
|
187
|
-
type GristUserActionTuple = unknown[];
|
|
188
|
-
/** `["UpdateRecord", tableId, rowId, { col: value, ... }]` */
|
|
189
|
-
declare function gristUpdateRecordAction(tableId: string, rowId: number, patch: Record<string, unknown>): GristUserActionTuple;
|
|
190
|
-
/** `["AddRecord", tableId, null, { col: value, ... }]` */
|
|
191
|
-
declare function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple;
|
|
192
|
-
/** `["RemoveRecord", tableId, rowId]` */
|
|
193
|
-
declare function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple;
|
|
194
|
-
/** `["AddColumn", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */
|
|
195
|
-
declare function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
196
|
-
/** `["AddVisibleColumn", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */
|
|
197
|
-
declare function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
198
|
-
/** `["RenameColumn", tableId, colId, newColId]` */
|
|
199
|
-
declare function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple;
|
|
200
|
-
/** `["ModifyColumn", tableId, colId, colInfo]` */
|
|
201
|
-
declare function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
|
|
202
|
-
/** `["RemoveColumn", tableId, colId]` */
|
|
203
|
-
declare function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple;
|
|
204
|
-
/** `["AddTable", tableId, tableInfo]` */
|
|
205
|
-
declare function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple;
|
|
206
|
-
|
|
207
184
|
/**
|
|
208
185
|
* The alerts `mountGristWidget()` shows above a running widget: what needs the
|
|
209
186
|
* user's attention in Grist (column mapping, access, a failed write, an
|
|
@@ -262,10 +239,39 @@ type GristColumnInfo = {
|
|
|
262
239
|
formula?: string;
|
|
263
240
|
description?: string;
|
|
264
241
|
};
|
|
242
|
+
/** `fetchRows()` options: rows (the default) or Grist's columns. */
|
|
243
|
+
type FetchRowsOptions = FetchGristTableRowsOptions & {
|
|
244
|
+
/** Grist's column-oriented payload (`{ id: [...], Name: [...] }`) instead of rows. */
|
|
245
|
+
columnar?: boolean;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* A table's rows, each `{ id, ...cells }` under real column ids. Without a
|
|
249
|
+
* table id, the widget's own table as its section shows it (filters and
|
|
250
|
+
* sort applied); with one, any table (full access), in Grist's row order.
|
|
251
|
+
* `{ columnar: true }` gives Grist's columns instead.
|
|
252
|
+
*/
|
|
253
|
+
type FetchRows = {
|
|
254
|
+
<T extends Record<string, unknown> = Record<string, unknown>>(tableId?: string | null, options?: FetchRowsOptions & {
|
|
255
|
+
columnar?: false;
|
|
256
|
+
}): Promise<GristRowRecord<T>[]>;
|
|
257
|
+
<T extends Record<string, unknown> = Record<string, unknown>>(options: FetchRowsOptions & {
|
|
258
|
+
columnar?: false;
|
|
259
|
+
}): Promise<GristRowRecord<T>[]>;
|
|
260
|
+
(tableId: string | null | undefined, options: FetchRowsOptions & {
|
|
261
|
+
columnar: true;
|
|
262
|
+
}): Promise<GristColumnarTable>;
|
|
263
|
+
(options: FetchRowsOptions & {
|
|
264
|
+
columnar: true;
|
|
265
|
+
}): Promise<GristColumnarTable>;
|
|
266
|
+
};
|
|
265
267
|
type GristApi = {
|
|
266
268
|
reload: () => Promise<void>;
|
|
269
|
+
fetchRows: FetchRows;
|
|
270
|
+
/** @deprecated Use `fetchRows({ columnar: true })` (or `fetchRows()` for rows). */
|
|
267
271
|
fetchSelectedTable: (options?: GristFetchSelectedOptions) => Promise<GristColumnarTable>;
|
|
272
|
+
/** @deprecated Use `fetchRows(tableId, { columnar: true })` (or `fetchRows(tableId)` for rows). */
|
|
268
273
|
fetchTable: (tableId: string) => Promise<GristColumnarTable>;
|
|
274
|
+
/** @deprecated Use `fetchRows(tableId, options)`. */
|
|
269
275
|
fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: FetchGristTableRowsOptions) => Promise<GristRowRecord<T>[]>;
|
|
270
276
|
listTables: (options?: ListTablesOptions) => Promise<string[]>;
|
|
271
277
|
listColumns: (tableId: string, options?: ListColumnsOptions) => Promise<GristColumnInfo[]>;
|
|
@@ -313,8 +319,9 @@ type GristWidgetMode = "empty" | "row" | "new-row";
|
|
|
313
319
|
type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = Omit<GristApi, "fetchTableRows"> & {
|
|
314
320
|
/** `"booting"` until Grist answers, then `"ready"`; `"unavailable"` outside Grist; `"error"` otherwise. */
|
|
315
321
|
status: GristWidgetStatus;
|
|
316
|
-
/**
|
|
322
|
+
/** @deprecated Use `status`: `status !== "unavailable"` once it isn't `"booting"`. */
|
|
317
323
|
isAvailable: boolean | null;
|
|
324
|
+
/** @deprecated Use `status === "ready"`. */
|
|
318
325
|
isReady: boolean;
|
|
319
326
|
/** Why the widget can't run (status `"error"` or `"unavailable"`), else null. */
|
|
320
327
|
error: string | null;
|
|
@@ -359,7 +366,7 @@ type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unk
|
|
|
359
366
|
addRecord: (patch: GristRecordPatch<TMapped>) => Promise<number>;
|
|
360
367
|
/** The section's table id. */
|
|
361
368
|
currentTableId: string | null;
|
|
362
|
-
/**
|
|
369
|
+
/** @deprecated Use `fetchRows(tableId, options)`. */
|
|
363
370
|
fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: Parameters<GristApi["fetchTableRows"]>[1]) => Promise<GristRowRecord<T>[]>;
|
|
364
371
|
/** The last write's state. */
|
|
365
372
|
actionStatus: GristWidgetActionStatus;
|
|
@@ -375,7 +382,10 @@ type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unk
|
|
|
375
382
|
declare function useGrist<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(options?: UseGristOptions): UseGristResult<TRow, TMapped>;
|
|
376
383
|
/** `useGrist()` inside a provider, or null outside one: for components that also work without Grist. */
|
|
377
384
|
declare function useGristOptional<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped> | null;
|
|
378
|
-
/**
|
|
385
|
+
/**
|
|
386
|
+
* `useGrist()` inside `<GristWidgetProvider>`; throws outside one.
|
|
387
|
+
* @deprecated Use `widget.useGrist()` (or `useGrist()`): `mountGristWidget()` always renders the provider.
|
|
388
|
+
*/
|
|
379
389
|
declare function useGristContext<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped>;
|
|
380
390
|
|
|
381
391
|
/**
|
|
@@ -429,5 +439,5 @@ type GristWidget<D extends GristWidgetDefinition = GristWidgetDefinition> = {
|
|
|
429
439
|
*/
|
|
430
440
|
declare function defineGristWidget<const D extends GristWidgetDefinition>(definition: D): GristWidget<D>;
|
|
431
441
|
|
|
432
|
-
export {
|
|
433
|
-
export type { GristWidget as G, ListColumnsOptions as L, StandardSchema as S, UseGristOptions as U, ValidateColumnMappingsResult as V, GristNoiseColumnsOptions as a,
|
|
442
|
+
export { tableDataToRows as A, useGrist as B, useGristContext as C, useGristOptional as D, checkGristCell as s, defineGristWidget as t, encodeGristCell as u, extractGristAttachmentId as v, extractGristAttachmentIdsFromCell as w, gristAttachmentCellValue as x, gristAttachmentCellValues as y, mergeGristAttachmentCellValue as z };
|
|
443
|
+
export type { FetchRows as F, GristWidget as G, ListColumnsOptions as L, StandardSchema as S, UseGristOptions as U, ValidateColumnMappingsResult as V, GristNoiseColumnsOptions as a, FetchRowsOptions as b, GristAttachmentUploadResult as c, GristCellIssue as d, GristColumnInfo as e, GristColumnarTable as f, GristFetchedAttachmentBlob as g, GristMappedRow as h, GristRecordPatch as i, GristSdkAlertKind as j, GristTheme as k, GristWidgetActionStatus as l, GristWidgetDefinition as m, GristWidgetMode as n, GristWidgetRow as o, GristWidgetStatus as p, ListTablesOptions as q, UseGristResult as r };
|
|
@@ -47,6 +47,27 @@ var import_client = require("react-dom/client");
|
|
|
47
47
|
// src/sdk/use-grist.ts
|
|
48
48
|
var import_react = require("react");
|
|
49
49
|
|
|
50
|
+
// src/sdk/helpers/deprecate.ts
|
|
51
|
+
function isDevelopment() {
|
|
52
|
+
try {
|
|
53
|
+
return process.env.NODE_ENV !== "production";
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
var warned = /* @__PURE__ */ new Set();
|
|
59
|
+
function warnDeprecated(name, instead) {
|
|
60
|
+
if (warned.has(name) || !isDevelopment()) return;
|
|
61
|
+
warned.add(name);
|
|
62
|
+
console.warn(`[grist-widget-sdk] ${name} is deprecated and goes in 1.0: ${instead}. https://gristwidgets.com/docs/sdk/api/deprecated`);
|
|
63
|
+
}
|
|
64
|
+
function deprecatedFunction(name, instead, fn) {
|
|
65
|
+
return ((...args) => {
|
|
66
|
+
warnDeprecated(name, instead);
|
|
67
|
+
return fn(...args);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
50
71
|
// src/sdk/helpers/grist-value-codec.ts
|
|
51
72
|
var MARSHALLED_TAGS = /* @__PURE__ */ new Set(["E", "L", "D", "d", "R", "r", "P"]);
|
|
52
73
|
function isMarshalledTuple(value) {
|
|
@@ -617,15 +638,32 @@ function createGristApi(runtime) {
|
|
|
617
638
|
destroy: (ids) => write(() => resolve().destroy(ids))
|
|
618
639
|
});
|
|
619
640
|
const tables = /* @__PURE__ */ new Map();
|
|
641
|
+
const selectedColumns = (options) => read(async () => {
|
|
642
|
+
const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
|
|
643
|
+
if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
|
|
644
|
+
return await impl({ keepEncoded: false, ...options });
|
|
645
|
+
});
|
|
646
|
+
const tableColumns = (tableId) => read(async () => await docApi().fetchTable(tableId));
|
|
647
|
+
const fetchRows = (async (a, b) => {
|
|
648
|
+
const tableId = typeof a === "string" ? a : null;
|
|
649
|
+
const { columnar, ...rowOptions } = (typeof a === "object" && a !== null ? a : b) ?? {};
|
|
650
|
+
if (tableId === null) {
|
|
651
|
+
const data = await selectedColumns(rowOptions.columns ? { keepEncoded: true } : void 0);
|
|
652
|
+
return columnar ? data : materializeGristRowsFromColumnar(data, { order: "none", ...rowOptions });
|
|
653
|
+
}
|
|
654
|
+
if (columnar) return tableColumns(tableId);
|
|
655
|
+
return read(() => fetchGristTableRows(docApi(), tableId, rowOptions));
|
|
656
|
+
});
|
|
620
657
|
return {
|
|
621
658
|
reload: () => runtime.reload(),
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
659
|
+
fetchRows,
|
|
660
|
+
fetchSelectedTable: deprecatedFunction("useGrist().fetchSelectedTable()", "use fetchRows({ columnar: true }), or fetchRows() for rows", selectedColumns),
|
|
661
|
+
fetchTable: deprecatedFunction("useGrist().fetchTable()", "use fetchRows(tableId, { columnar: true }), or fetchRows(tableId) for rows", tableColumns),
|
|
662
|
+
fetchTableRows: deprecatedFunction(
|
|
663
|
+
"useGrist().fetchTableRows()",
|
|
664
|
+
"use fetchRows(tableId, options)",
|
|
665
|
+
(tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {}))
|
|
666
|
+
),
|
|
629
667
|
listTables: (options) => read(async () => {
|
|
630
668
|
const all = [...await docApi().listTables()];
|
|
631
669
|
return options?.includeSystem ? all : all.filter((t) => !t.startsWith("_grist") && !t.startsWith("GristHidden_"));
|