grist-widget-sdk 0.2.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 +730 -0
- package/LICENSE +15 -0
- package/README.md +249 -0
- package/dist/advanced.cjs +2749 -0
- package/dist/advanced.cjs.map +1 -0
- package/dist/advanced.d.cts +790 -0
- package/dist/advanced.d.ts +790 -0
- package/dist/advanced.js +825 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-64SVRWW7.js +758 -0
- package/dist/chunk-64SVRWW7.js.map +1 -0
- package/dist/chunk-BNBV24WM.js +479 -0
- package/dist/chunk-BNBV24WM.js.map +1 -0
- package/dist/chunk-ELGVOHFD.js +32 -0
- package/dist/chunk-ELGVOHFD.js.map +1 -0
- package/dist/chunk-GTTD5HPO.js +36 -0
- package/dist/chunk-GTTD5HPO.js.map +1 -0
- package/dist/chunk-JASMM2YC.js +243 -0
- package/dist/chunk-JASMM2YC.js.map +1 -0
- package/dist/chunk-PM3B4WYV.js +12 -0
- package/dist/chunk-PM3B4WYV.js.map +1 -0
- package/dist/chunk-QKXKZ27D.js +1189 -0
- package/dist/chunk-QKXKZ27D.js.map +1 -0
- package/dist/chunk-QZG7SNUG.js +463 -0
- package/dist/chunk-QZG7SNUG.js.map +1 -0
- package/dist/chunk-REV5AUXD.js +25 -0
- package/dist/chunk-REV5AUXD.js.map +1 -0
- package/dist/chunk-XE2SKNLH.js +1641 -0
- package/dist/chunk-XE2SKNLH.js.map +1 -0
- package/dist/create-grist-emulator-C_0I4wax.d.ts +80 -0
- package/dist/create-grist-emulator-DBS6gmiI.d.cts +80 -0
- package/dist/emulator/devtools.cjs +1367 -0
- package/dist/emulator/devtools.cjs.map +1 -0
- package/dist/emulator/devtools.d.cts +46 -0
- package/dist/emulator/devtools.d.ts +46 -0
- package/dist/emulator/devtools.js +480 -0
- package/dist/emulator/devtools.js.map +1 -0
- package/dist/emulator/testing.cjs +2061 -0
- package/dist/emulator/testing.cjs.map +1 -0
- package/dist/emulator/testing.d.cts +50 -0
- package/dist/emulator/testing.d.ts +50 -0
- package/dist/emulator/testing.js +124 -0
- package/dist/emulator/testing.js.map +1 -0
- package/dist/emulator/transports.cjs +1132 -0
- package/dist/emulator/transports.cjs.map +1 -0
- package/dist/emulator/transports.d.cts +37 -0
- package/dist/emulator/transports.d.ts +37 -0
- package/dist/emulator/transports.js +12 -0
- package/dist/emulator/transports.js.map +1 -0
- package/dist/emulator.cjs +1796 -0
- package/dist/emulator.cjs.map +1 -0
- package/dist/emulator.d.cts +107 -0
- package/dist/emulator.d.ts +107 -0
- package/dist/emulator.js +26 -0
- package/dist/emulator.js.map +1 -0
- package/dist/index.cjs +5511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +825 -0
- package/dist/index.d.ts +825 -0
- package/dist/index.js +2447 -0
- package/dist/index.js.map +1 -0
- package/dist/inline-CRwQQ-GW.d.cts +311 -0
- package/dist/inline-QitZwXKP.d.ts +311 -0
- package/dist/templates-BC7FoSdW.d.ts +24 -0
- package/dist/templates-DBq719O_.d.cts +24 -0
- package/dist/types-Fb2wplkv.d.cts +228 -0
- package/dist/types-Fb2wplkv.d.ts +228 -0
- package/dist/use-grist-widget-options-from-context-BFhQBGRY.d.ts +522 -0
- package/dist/use-grist-widget-options-from-context-qpFMdoBJ.d.cts +522 -0
- package/package.json +131 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How row bodies were populated when the replica document was built (hint only).
|
|
3
|
+
* Loaders should still treat omitted `rows` like `[]` via {@link normalizeReplicaTableInput}.
|
|
4
|
+
*/
|
|
5
|
+
type GristDocumentMode = "schema-only" | "schema+samples" | "schema+data";
|
|
6
|
+
/**
|
|
7
|
+
* Decoded row in replica JSON (`id` + fields). Same as wire `fetchTable` row objects,
|
|
8
|
+
* but **not** columnar `Record<colId, unknown[]>` — that shape is only on `docApi.fetchTable`.
|
|
9
|
+
*/
|
|
10
|
+
type GristReplicaRow = GristRowRecord;
|
|
11
|
+
/**
|
|
12
|
+
* Column metadata in replica JSON: Grist-native fields only (no samples / scan stats).
|
|
13
|
+
* `formulaKind` is optional UI convenience; use {@link resolveGristFormulaKind} when missing.
|
|
14
|
+
*/
|
|
15
|
+
type GristReplicaColumn = {
|
|
16
|
+
/** Internal row id in `_grist_Tables_column` for this column. */
|
|
17
|
+
colRef?: number;
|
|
18
|
+
type?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
parentPos?: number;
|
|
21
|
+
isFormula?: boolean;
|
|
22
|
+
formulaKind?: GristFormulaKind;
|
|
23
|
+
/** Present only when non-empty; may be truncated. */
|
|
24
|
+
formula?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
widgetOptions?: Record<string, unknown>;
|
|
27
|
+
/** Internal `_grist_Tables_column` row id of the display helper for refs. */
|
|
28
|
+
displayColRef?: number;
|
|
29
|
+
/** Internal `_grist_Tables_column` row id of the visible column. */
|
|
30
|
+
visibleColRef?: number;
|
|
31
|
+
};
|
|
32
|
+
type GristReplicaTable = {
|
|
33
|
+
label?: string;
|
|
34
|
+
columns?: Record<string, GristReplicaColumn>;
|
|
35
|
+
/** Decoded rows; omit or `[]` interchangeably until normalized at boundaries. */
|
|
36
|
+
rows?: GristReplicaRow[];
|
|
37
|
+
rowCount?: number;
|
|
38
|
+
dataOmitted?: boolean;
|
|
39
|
+
dataOmittedReason?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Canonical Grist replica document: one JSON type for `getDocumentJson`, fixtures,
|
|
44
|
+
* and `createGristEmulator({ document })`.
|
|
45
|
+
*/
|
|
46
|
+
type GristReplicaDocument = {
|
|
47
|
+
generatedAt: string;
|
|
48
|
+
/** Optional provenance label (e.g. widget id); hosts may log this when building or persisting replicas. */
|
|
49
|
+
source?: string;
|
|
50
|
+
docName?: string;
|
|
51
|
+
mode?: GristDocumentMode;
|
|
52
|
+
tables: Record<string, GristReplicaTable>;
|
|
53
|
+
selection?: Partial<GristReplicaSelection> & {
|
|
54
|
+
tableId?: string;
|
|
55
|
+
};
|
|
56
|
+
widgetOptions?: Record<string, unknown>;
|
|
57
|
+
widgetInteraction?: GristWidgetInteraction;
|
|
58
|
+
configuration?: GristWidgetConfiguration;
|
|
59
|
+
accessToken?: {
|
|
60
|
+
token: string;
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
ttlMsecs: number;
|
|
63
|
+
} | null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Access level passed to `grist.ready({ requiredAccess })`. */
|
|
67
|
+
type GristRequiredAccess = "none" | "read table" | "full";
|
|
68
|
+
/**
|
|
69
|
+
* Single-column declaration in `grist.ready({ columns })`.
|
|
70
|
+
* Mirrors Grist `ColumnToMap`. See https://support.getgrist.com/code/interfaces/grist_plugin_api.ColumnToMap/
|
|
71
|
+
*/
|
|
72
|
+
type GristColumnToMap = {
|
|
73
|
+
/** Logical column name your widget code uses (must be a valid JSON property name). */
|
|
74
|
+
name: string;
|
|
75
|
+
/** Short label shown in the section mapping UI. */
|
|
76
|
+
title?: string | null;
|
|
77
|
+
/** Long help text for the section mapping UI. */
|
|
78
|
+
description?: string | null;
|
|
79
|
+
/** Comma-separated list of allowed Grist column types. Defaults to `"Any"`. */
|
|
80
|
+
type?: string;
|
|
81
|
+
/** Mark column as optional (default: required). */
|
|
82
|
+
optional?: boolean;
|
|
83
|
+
/** Allow multiple column assignment (resulting `mappings[name]` becomes `string[]`). */
|
|
84
|
+
allowMultiple?: boolean;
|
|
85
|
+
/** Match column type strictly (so `"Any"` matches only `"Any"`). */
|
|
86
|
+
strictType?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/** Argument shape for `grist.ready({ columns })`. */
|
|
89
|
+
type GristColumnsToMap = Array<string | GristColumnToMap>;
|
|
90
|
+
/**
|
|
91
|
+
* Mapping returned by Grist between logical widget column names and real table column ids.
|
|
92
|
+
* Single mappings are `string`; `allowMultiple` columns are `string[]`.
|
|
93
|
+
*/
|
|
94
|
+
type GristWidgetColumnMap = Record<string, string | string[] | undefined>;
|
|
95
|
+
/** A row from `grist.onRecord` or `fetchTable`. Always carries a numeric `id`. */
|
|
96
|
+
type GristRowRecord<T = Record<string, unknown>> = T & {
|
|
97
|
+
id: number;
|
|
98
|
+
};
|
|
99
|
+
/** Arguments accepted by `grist.ready` for custom widgets. */
|
|
100
|
+
type GristReadyOptions = {
|
|
101
|
+
requiredAccess?: GristRequiredAccess;
|
|
102
|
+
columns?: GristColumnsToMap;
|
|
103
|
+
allowSelectBy?: boolean;
|
|
104
|
+
hasCustomOptions?: boolean;
|
|
105
|
+
onEditOptions?: () => void | Promise<void>;
|
|
106
|
+
/** Passed to availability detection (default 10). */
|
|
107
|
+
availabilityMaxAttempts?: number;
|
|
108
|
+
/** Ms between availability polls (default 1000). */
|
|
109
|
+
availabilityIntervalMs?: number;
|
|
110
|
+
/** Log when the page is not iframe-embedded (default false). */
|
|
111
|
+
logWhenNotEmbedded?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/** Optional second argument to `docApi.applyUserActions`. */
|
|
114
|
+
type GristApplyUserActionsOptions = {
|
|
115
|
+
/** Description shown in the document undo stack. */
|
|
116
|
+
desc?: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Last `grist.ready` options mirrored with the emulator (optional on fixtures).
|
|
120
|
+
*/
|
|
121
|
+
type GristWidgetConfiguration = {
|
|
122
|
+
requiredAccess?: GristRequiredAccess;
|
|
123
|
+
columns?: GristColumnsToMap;
|
|
124
|
+
allowSelectBy?: boolean;
|
|
125
|
+
hasCustomOptions?: boolean;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* How Grist treats the column (from `_grist_Tables_column` `isFormula` + `formula`).
|
|
129
|
+
* `empty_slot` is Grist's "empty column" state: `isFormula` true with no formula text.
|
|
130
|
+
*/
|
|
131
|
+
type GristFormulaKind = "computed" | "trigger" | "none" | "empty_slot";
|
|
132
|
+
/** Options for `fetchSelectedTable` / `fetchSelectedRecord` on `docApi` (GristView). */
|
|
133
|
+
type GristFetchSelectedOptions = {
|
|
134
|
+
keepEncoded?: boolean;
|
|
135
|
+
format?: "rows" | "columns" | string;
|
|
136
|
+
};
|
|
137
|
+
/** Argument to `grist.setCursorPos` (subset of Grist `CursorPos`). */
|
|
138
|
+
type GristCursorPos = {
|
|
139
|
+
rowId?: number;
|
|
140
|
+
field?: string;
|
|
141
|
+
colRef?: string;
|
|
142
|
+
sectionId?: number;
|
|
143
|
+
};
|
|
144
|
+
/** Selection slice persisted on replica fixtures (emulator / widget). */
|
|
145
|
+
type GristReplicaSelection = {
|
|
146
|
+
tableId: string;
|
|
147
|
+
rowId: number | "new" | null;
|
|
148
|
+
mappings?: GristWidgetColumnMap | null;
|
|
149
|
+
cursor?: GristCursorPos;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Linking state reported by Grist in `onOptions` settings (`InteractionOptions.linking`).
|
|
153
|
+
* @see https://github.com/gristlabs/grist-core/blob/main/app/plugin/CustomSectionAPI.ts
|
|
154
|
+
*/
|
|
155
|
+
type GristWidgetLinkingInfo = {
|
|
156
|
+
/** Incoming link type, or `null` when this section is not driven by a selector. */
|
|
157
|
+
asTarget: string | null;
|
|
158
|
+
/** True when another section uses this widget as a link source. */
|
|
159
|
+
asSource: boolean;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Second argument to `grist.onOptions` — document ↔ widget relationship (subset of Grist `InteractionOptions`).
|
|
163
|
+
*/
|
|
164
|
+
type GristWidgetInteraction = {
|
|
165
|
+
access_level?: string;
|
|
166
|
+
/** Present on Grist builds that report page linking; absent on older hosts. */
|
|
167
|
+
linking?: GristWidgetLinkingInfo;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* `TableOperations`-style record for `update`. Must include `id`; other fields are partial.
|
|
172
|
+
* @see https://support.getgrist.com/code/interfaces/TableOperations.TableOperations/#update
|
|
173
|
+
*/
|
|
174
|
+
type GristTableUpdateRecord = {
|
|
175
|
+
id: number;
|
|
176
|
+
fields: Record<string, unknown>;
|
|
177
|
+
};
|
|
178
|
+
/** Record for `create` (no id needed). */
|
|
179
|
+
type GristTableNewRecord = {
|
|
180
|
+
fields: Record<string, unknown>;
|
|
181
|
+
};
|
|
182
|
+
/** Record for `upsert`: `require` is the match key set, `fields` is what to write. */
|
|
183
|
+
type GristTableUpsertRecord = {
|
|
184
|
+
require: Record<string, unknown>;
|
|
185
|
+
fields?: Record<string, unknown>;
|
|
186
|
+
};
|
|
187
|
+
/** Options accepted by `TableOperations.create / update`. */
|
|
188
|
+
type GristTableOpOptions = {
|
|
189
|
+
parseStrings?: boolean;
|
|
190
|
+
};
|
|
191
|
+
/** Options accepted by `TableOperations.upsert`. */
|
|
192
|
+
type GristTableUpsertOptions = GristTableOpOptions & {
|
|
193
|
+
add?: boolean;
|
|
194
|
+
update?: boolean;
|
|
195
|
+
onMany?: "first" | "none" | "all";
|
|
196
|
+
allowEmptyRequire?: boolean;
|
|
197
|
+
};
|
|
198
|
+
type GristMinimalRecord = {
|
|
199
|
+
id: number;
|
|
200
|
+
};
|
|
201
|
+
/** Wraps `grist.getTable(...)` / `grist.selectedTable`. */
|
|
202
|
+
type GristTableOperations = {
|
|
203
|
+
getTableId: () => Promise<string>;
|
|
204
|
+
create: (records: GristTableNewRecord | GristTableNewRecord[], options?: GristTableOpOptions) => Promise<GristMinimalRecord | GristMinimalRecord[]>;
|
|
205
|
+
update: (records: GristTableUpdateRecord | GristTableUpdateRecord[], options?: GristTableOpOptions) => Promise<void>;
|
|
206
|
+
upsert: (records: GristTableUpsertRecord | GristTableUpsertRecord[], options?: GristTableUpsertOptions) => Promise<void>;
|
|
207
|
+
destroy: (recordIds: number | number[]) => Promise<void>;
|
|
208
|
+
};
|
|
209
|
+
/** Subset of `grist.docApi` from https://docs.getgrist.com/grist-plugin-api.js */
|
|
210
|
+
type GristDocApi = {
|
|
211
|
+
getDocName: () => Promise<string> | string;
|
|
212
|
+
listTables: () => Promise<string[]> | string[];
|
|
213
|
+
fetchTable: (tableId: string) => Promise<Record<string, unknown[]>>;
|
|
214
|
+
applyUserActions: (actions: unknown[][], options?: GristApplyUserActionsOptions) => Promise<unknown>;
|
|
215
|
+
/** Present when the widget requested sufficient access (e.g. full). */
|
|
216
|
+
getAccessToken?: (options?: {
|
|
217
|
+
readOnly?: boolean;
|
|
218
|
+
}) => Promise<{
|
|
219
|
+
token: string;
|
|
220
|
+
baseUrl: string;
|
|
221
|
+
}>;
|
|
222
|
+
/** Current section's table data (often smaller than {@link fetchTable} for the whole table). */
|
|
223
|
+
fetchSelectedTable?: (options?: GristFetchSelectedOptions) => Promise<Record<string, unknown[]>>;
|
|
224
|
+
/** Single row in the current section by numeric row id. */
|
|
225
|
+
fetchSelectedRecord?: (rowId: number, options?: GristFetchSelectedOptions) => Promise<Record<string, unknown>>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type { GristApplyUserActionsOptions as G, GristColumnToMap as a, GristColumnsToMap as b, GristCursorPos as c, GristDocApi as d, GristDocumentMode as e, GristFetchSelectedOptions as f, GristFormulaKind as g, GristMinimalRecord as h, GristReadyOptions as i, GristReplicaColumn as j, GristReplicaDocument as k, GristReplicaRow as l, GristReplicaSelection as m, GristReplicaTable as n, GristRequiredAccess as o, GristRowRecord as p, GristTableNewRecord as q, GristTableOpOptions as r, GristTableOperations as s, GristTableUpdateRecord as t, GristTableUpsertOptions as u, GristTableUpsertRecord as v, GristWidgetColumnMap as w, GristWidgetConfiguration as x, GristWidgetInteraction as y, GristWidgetLinkingInfo as z };
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How row bodies were populated when the replica document was built (hint only).
|
|
3
|
+
* Loaders should still treat omitted `rows` like `[]` via {@link normalizeReplicaTableInput}.
|
|
4
|
+
*/
|
|
5
|
+
type GristDocumentMode = "schema-only" | "schema+samples" | "schema+data";
|
|
6
|
+
/**
|
|
7
|
+
* Decoded row in replica JSON (`id` + fields). Same as wire `fetchTable` row objects,
|
|
8
|
+
* but **not** columnar `Record<colId, unknown[]>` — that shape is only on `docApi.fetchTable`.
|
|
9
|
+
*/
|
|
10
|
+
type GristReplicaRow = GristRowRecord;
|
|
11
|
+
/**
|
|
12
|
+
* Column metadata in replica JSON: Grist-native fields only (no samples / scan stats).
|
|
13
|
+
* `formulaKind` is optional UI convenience; use {@link resolveGristFormulaKind} when missing.
|
|
14
|
+
*/
|
|
15
|
+
type GristReplicaColumn = {
|
|
16
|
+
/** Internal row id in `_grist_Tables_column` for this column. */
|
|
17
|
+
colRef?: number;
|
|
18
|
+
type?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
parentPos?: number;
|
|
21
|
+
isFormula?: boolean;
|
|
22
|
+
formulaKind?: GristFormulaKind;
|
|
23
|
+
/** Present only when non-empty; may be truncated. */
|
|
24
|
+
formula?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
widgetOptions?: Record<string, unknown>;
|
|
27
|
+
/** Internal `_grist_Tables_column` row id of the display helper for refs. */
|
|
28
|
+
displayColRef?: number;
|
|
29
|
+
/** Internal `_grist_Tables_column` row id of the visible column. */
|
|
30
|
+
visibleColRef?: number;
|
|
31
|
+
};
|
|
32
|
+
type GristReplicaTable = {
|
|
33
|
+
label?: string;
|
|
34
|
+
columns?: Record<string, GristReplicaColumn>;
|
|
35
|
+
/** Decoded rows; omit or `[]` interchangeably until normalized at boundaries. */
|
|
36
|
+
rows?: GristReplicaRow[];
|
|
37
|
+
rowCount?: number;
|
|
38
|
+
dataOmitted?: boolean;
|
|
39
|
+
dataOmittedReason?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Canonical Grist replica document: one JSON type for `getDocumentJson`, fixtures,
|
|
44
|
+
* and `createGristEmulator({ document })`.
|
|
45
|
+
*/
|
|
46
|
+
type GristReplicaDocument = {
|
|
47
|
+
generatedAt: string;
|
|
48
|
+
/** Optional provenance label (e.g. widget id); hosts may log this when building or persisting replicas. */
|
|
49
|
+
source?: string;
|
|
50
|
+
docName?: string;
|
|
51
|
+
mode?: GristDocumentMode;
|
|
52
|
+
tables: Record<string, GristReplicaTable>;
|
|
53
|
+
selection?: Partial<GristReplicaSelection> & {
|
|
54
|
+
tableId?: string;
|
|
55
|
+
};
|
|
56
|
+
widgetOptions?: Record<string, unknown>;
|
|
57
|
+
widgetInteraction?: GristWidgetInteraction;
|
|
58
|
+
configuration?: GristWidgetConfiguration;
|
|
59
|
+
accessToken?: {
|
|
60
|
+
token: string;
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
ttlMsecs: number;
|
|
63
|
+
} | null;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Access level passed to `grist.ready({ requiredAccess })`. */
|
|
67
|
+
type GristRequiredAccess = "none" | "read table" | "full";
|
|
68
|
+
/**
|
|
69
|
+
* Single-column declaration in `grist.ready({ columns })`.
|
|
70
|
+
* Mirrors Grist `ColumnToMap`. See https://support.getgrist.com/code/interfaces/grist_plugin_api.ColumnToMap/
|
|
71
|
+
*/
|
|
72
|
+
type GristColumnToMap = {
|
|
73
|
+
/** Logical column name your widget code uses (must be a valid JSON property name). */
|
|
74
|
+
name: string;
|
|
75
|
+
/** Short label shown in the section mapping UI. */
|
|
76
|
+
title?: string | null;
|
|
77
|
+
/** Long help text for the section mapping UI. */
|
|
78
|
+
description?: string | null;
|
|
79
|
+
/** Comma-separated list of allowed Grist column types. Defaults to `"Any"`. */
|
|
80
|
+
type?: string;
|
|
81
|
+
/** Mark column as optional (default: required). */
|
|
82
|
+
optional?: boolean;
|
|
83
|
+
/** Allow multiple column assignment (resulting `mappings[name]` becomes `string[]`). */
|
|
84
|
+
allowMultiple?: boolean;
|
|
85
|
+
/** Match column type strictly (so `"Any"` matches only `"Any"`). */
|
|
86
|
+
strictType?: boolean;
|
|
87
|
+
};
|
|
88
|
+
/** Argument shape for `grist.ready({ columns })`. */
|
|
89
|
+
type GristColumnsToMap = Array<string | GristColumnToMap>;
|
|
90
|
+
/**
|
|
91
|
+
* Mapping returned by Grist between logical widget column names and real table column ids.
|
|
92
|
+
* Single mappings are `string`; `allowMultiple` columns are `string[]`.
|
|
93
|
+
*/
|
|
94
|
+
type GristWidgetColumnMap = Record<string, string | string[] | undefined>;
|
|
95
|
+
/** A row from `grist.onRecord` or `fetchTable`. Always carries a numeric `id`. */
|
|
96
|
+
type GristRowRecord<T = Record<string, unknown>> = T & {
|
|
97
|
+
id: number;
|
|
98
|
+
};
|
|
99
|
+
/** Arguments accepted by `grist.ready` for custom widgets. */
|
|
100
|
+
type GristReadyOptions = {
|
|
101
|
+
requiredAccess?: GristRequiredAccess;
|
|
102
|
+
columns?: GristColumnsToMap;
|
|
103
|
+
allowSelectBy?: boolean;
|
|
104
|
+
hasCustomOptions?: boolean;
|
|
105
|
+
onEditOptions?: () => void | Promise<void>;
|
|
106
|
+
/** Passed to availability detection (default 10). */
|
|
107
|
+
availabilityMaxAttempts?: number;
|
|
108
|
+
/** Ms between availability polls (default 1000). */
|
|
109
|
+
availabilityIntervalMs?: number;
|
|
110
|
+
/** Log when the page is not iframe-embedded (default false). */
|
|
111
|
+
logWhenNotEmbedded?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/** Optional second argument to `docApi.applyUserActions`. */
|
|
114
|
+
type GristApplyUserActionsOptions = {
|
|
115
|
+
/** Description shown in the document undo stack. */
|
|
116
|
+
desc?: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Last `grist.ready` options mirrored with the emulator (optional on fixtures).
|
|
120
|
+
*/
|
|
121
|
+
type GristWidgetConfiguration = {
|
|
122
|
+
requiredAccess?: GristRequiredAccess;
|
|
123
|
+
columns?: GristColumnsToMap;
|
|
124
|
+
allowSelectBy?: boolean;
|
|
125
|
+
hasCustomOptions?: boolean;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* How Grist treats the column (from `_grist_Tables_column` `isFormula` + `formula`).
|
|
129
|
+
* `empty_slot` is Grist's "empty column" state: `isFormula` true with no formula text.
|
|
130
|
+
*/
|
|
131
|
+
type GristFormulaKind = "computed" | "trigger" | "none" | "empty_slot";
|
|
132
|
+
/** Options for `fetchSelectedTable` / `fetchSelectedRecord` on `docApi` (GristView). */
|
|
133
|
+
type GristFetchSelectedOptions = {
|
|
134
|
+
keepEncoded?: boolean;
|
|
135
|
+
format?: "rows" | "columns" | string;
|
|
136
|
+
};
|
|
137
|
+
/** Argument to `grist.setCursorPos` (subset of Grist `CursorPos`). */
|
|
138
|
+
type GristCursorPos = {
|
|
139
|
+
rowId?: number;
|
|
140
|
+
field?: string;
|
|
141
|
+
colRef?: string;
|
|
142
|
+
sectionId?: number;
|
|
143
|
+
};
|
|
144
|
+
/** Selection slice persisted on replica fixtures (emulator / widget). */
|
|
145
|
+
type GristReplicaSelection = {
|
|
146
|
+
tableId: string;
|
|
147
|
+
rowId: number | "new" | null;
|
|
148
|
+
mappings?: GristWidgetColumnMap | null;
|
|
149
|
+
cursor?: GristCursorPos;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Linking state reported by Grist in `onOptions` settings (`InteractionOptions.linking`).
|
|
153
|
+
* @see https://github.com/gristlabs/grist-core/blob/main/app/plugin/CustomSectionAPI.ts
|
|
154
|
+
*/
|
|
155
|
+
type GristWidgetLinkingInfo = {
|
|
156
|
+
/** Incoming link type, or `null` when this section is not driven by a selector. */
|
|
157
|
+
asTarget: string | null;
|
|
158
|
+
/** True when another section uses this widget as a link source. */
|
|
159
|
+
asSource: boolean;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Second argument to `grist.onOptions` — document ↔ widget relationship (subset of Grist `InteractionOptions`).
|
|
163
|
+
*/
|
|
164
|
+
type GristWidgetInteraction = {
|
|
165
|
+
access_level?: string;
|
|
166
|
+
/** Present on Grist builds that report page linking; absent on older hosts. */
|
|
167
|
+
linking?: GristWidgetLinkingInfo;
|
|
168
|
+
[key: string]: unknown;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* `TableOperations`-style record for `update`. Must include `id`; other fields are partial.
|
|
172
|
+
* @see https://support.getgrist.com/code/interfaces/TableOperations.TableOperations/#update
|
|
173
|
+
*/
|
|
174
|
+
type GristTableUpdateRecord = {
|
|
175
|
+
id: number;
|
|
176
|
+
fields: Record<string, unknown>;
|
|
177
|
+
};
|
|
178
|
+
/** Record for `create` (no id needed). */
|
|
179
|
+
type GristTableNewRecord = {
|
|
180
|
+
fields: Record<string, unknown>;
|
|
181
|
+
};
|
|
182
|
+
/** Record for `upsert`: `require` is the match key set, `fields` is what to write. */
|
|
183
|
+
type GristTableUpsertRecord = {
|
|
184
|
+
require: Record<string, unknown>;
|
|
185
|
+
fields?: Record<string, unknown>;
|
|
186
|
+
};
|
|
187
|
+
/** Options accepted by `TableOperations.create / update`. */
|
|
188
|
+
type GristTableOpOptions = {
|
|
189
|
+
parseStrings?: boolean;
|
|
190
|
+
};
|
|
191
|
+
/** Options accepted by `TableOperations.upsert`. */
|
|
192
|
+
type GristTableUpsertOptions = GristTableOpOptions & {
|
|
193
|
+
add?: boolean;
|
|
194
|
+
update?: boolean;
|
|
195
|
+
onMany?: "first" | "none" | "all";
|
|
196
|
+
allowEmptyRequire?: boolean;
|
|
197
|
+
};
|
|
198
|
+
type GristMinimalRecord = {
|
|
199
|
+
id: number;
|
|
200
|
+
};
|
|
201
|
+
/** Wraps `grist.getTable(...)` / `grist.selectedTable`. */
|
|
202
|
+
type GristTableOperations = {
|
|
203
|
+
getTableId: () => Promise<string>;
|
|
204
|
+
create: (records: GristTableNewRecord | GristTableNewRecord[], options?: GristTableOpOptions) => Promise<GristMinimalRecord | GristMinimalRecord[]>;
|
|
205
|
+
update: (records: GristTableUpdateRecord | GristTableUpdateRecord[], options?: GristTableOpOptions) => Promise<void>;
|
|
206
|
+
upsert: (records: GristTableUpsertRecord | GristTableUpsertRecord[], options?: GristTableUpsertOptions) => Promise<void>;
|
|
207
|
+
destroy: (recordIds: number | number[]) => Promise<void>;
|
|
208
|
+
};
|
|
209
|
+
/** Subset of `grist.docApi` from https://docs.getgrist.com/grist-plugin-api.js */
|
|
210
|
+
type GristDocApi = {
|
|
211
|
+
getDocName: () => Promise<string> | string;
|
|
212
|
+
listTables: () => Promise<string[]> | string[];
|
|
213
|
+
fetchTable: (tableId: string) => Promise<Record<string, unknown[]>>;
|
|
214
|
+
applyUserActions: (actions: unknown[][], options?: GristApplyUserActionsOptions) => Promise<unknown>;
|
|
215
|
+
/** Present when the widget requested sufficient access (e.g. full). */
|
|
216
|
+
getAccessToken?: (options?: {
|
|
217
|
+
readOnly?: boolean;
|
|
218
|
+
}) => Promise<{
|
|
219
|
+
token: string;
|
|
220
|
+
baseUrl: string;
|
|
221
|
+
}>;
|
|
222
|
+
/** Current section's table data (often smaller than {@link fetchTable} for the whole table). */
|
|
223
|
+
fetchSelectedTable?: (options?: GristFetchSelectedOptions) => Promise<Record<string, unknown[]>>;
|
|
224
|
+
/** Single row in the current section by numeric row id. */
|
|
225
|
+
fetchSelectedRecord?: (rowId: number, options?: GristFetchSelectedOptions) => Promise<Record<string, unknown>>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type { GristApplyUserActionsOptions as G, GristColumnToMap as a, GristColumnsToMap as b, GristCursorPos as c, GristDocApi as d, GristDocumentMode as e, GristFetchSelectedOptions as f, GristFormulaKind as g, GristMinimalRecord as h, GristReadyOptions as i, GristReplicaColumn as j, GristReplicaDocument as k, GristReplicaRow as l, GristReplicaSelection as m, GristReplicaTable as n, GristRequiredAccess as o, GristRowRecord as p, GristTableNewRecord as q, GristTableOpOptions as r, GristTableOperations as s, GristTableUpdateRecord as t, GristTableUpsertOptions as u, GristTableUpsertRecord as v, GristWidgetColumnMap as w, GristWidgetConfiguration as x, GristWidgetInteraction as y, GristWidgetLinkingInfo as z };
|