grist-widget-sdk 0.5.1 → 0.6.1

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 (42) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/actions.cjs +96 -0
  3. package/dist/actions.cjs.map +1 -0
  4. package/dist/actions.d.cts +36 -0
  5. package/dist/actions.d.ts +36 -0
  6. package/dist/actions.js +29 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/app.cjs +50 -8
  9. package/dist/app.cjs.map +1 -1
  10. package/dist/app.d.cts +3 -2
  11. package/dist/app.d.ts +3 -2
  12. package/dist/app.js +4 -3
  13. package/dist/{chunk-4ZGVKGDF.js → chunk-A4KFKOEQ.js} +2 -58
  14. package/dist/chunk-A4KFKOEQ.js.map +1 -0
  15. package/dist/{chunk-OXA2VITC.js → chunk-CMN4M4S3.js} +6 -4
  16. package/dist/{chunk-OXA2VITC.js.map → chunk-CMN4M4S3.js.map} +1 -1
  17. package/dist/{chunk-MAPAWVQC.js → chunk-JJ23G6RR.js} +109 -18
  18. package/dist/chunk-JJ23G6RR.js.map +1 -0
  19. package/dist/{chunk-P5I5MRC6.js → chunk-KHOPLBCJ.js} +2 -2
  20. package/dist/chunk-YGQXH2P5.js +81 -0
  21. package/dist/chunk-YGQXH2P5.js.map +1 -0
  22. package/dist/{define-widget-B1FIvI-h.d.cts → define-widget-CYYdqRmB.d.cts} +39 -29
  23. package/dist/{define-widget-B9gEtJP0.d.ts → define-widget-D-NmSglS.d.ts} +39 -29
  24. package/dist/emulator/testing.cjs +50 -8
  25. package/dist/emulator/testing.cjs.map +1 -1
  26. package/dist/emulator/testing.d.cts +1 -0
  27. package/dist/emulator/testing.d.ts +1 -0
  28. package/dist/emulator/testing.js +5 -4
  29. package/dist/emulator/testing.js.map +1 -1
  30. package/dist/emulator.cjs.map +1 -1
  31. package/dist/emulator.js +3 -2
  32. package/dist/index.cjs +133 -24
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +30 -3
  35. package/dist/index.d.ts +30 -3
  36. package/dist/index.js +12 -11
  37. package/dist/{mount-grist-widget-Dtelqao_.d.cts → mount-grist-widget-D0mr__ga.d.cts} +1 -1
  38. package/dist/{mount-grist-widget-CkB-3iG_.d.ts → mount-grist-widget-DVcFl5Ys.d.ts} +1 -1
  39. package/package.json +13 -3
  40. package/dist/chunk-4ZGVKGDF.js.map +0 -1
  41. package/dist/chunk-MAPAWVQC.js.map +0 -1
  42. /package/dist/{chunk-P5I5MRC6.js.map → chunk-KHOPLBCJ.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # grist-widget-sdk
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 71785f8: **Attachment URLs only take an attachment id.** `getAttachmentUrl()`, `fetchAttachmentBlob()` (and the helpers behind them) now refuse anything but a positive integer as the attachment id, before asking Grist for an access token: the id usually comes from a cell, and the URL built from it carries the document's token, so a crafted value (`"1/../tables"`) could otherwise aim it at another route of the same Grist. The token in the URL is now encoded too.
8
+
9
+ `grist-widget-sdk` no longer depends on `grain-rpc`, which nothing imported since the iframe transport was removed: one package fewer in every widget.
10
+
11
+ ## 0.6.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 04fcfe6: **One way to do each thing: `fetchRows()`, `grist-widget-sdk/actions`, and soft deprecations.**
16
+
17
+ ```ts
18
+ const rows = await w.fetchRows() // the section's rows, in its order
19
+ const people = await w.fetchRows("People") // any table's rows (full access)
20
+ const columns = await w.fetchRows({ columnar: true }) // Grist's own column-oriented payload
21
+
22
+ import { gristAddColumnAction } from "grist-widget-sdk/actions"
23
+ ```
24
+
25
+ - `useGrist().fetchRows(tableId?, options?)` replaces three readers. Without a table id it reads the widget's own section (filters and sort applied); with one, any table, in Grist's order (`order`, `columns` as before). Rows by default, `{ columnar: true }` for columns.
26
+ - `grist-widget-sdk/actions` is the user actions' own entry point, with the bulk record builders (`gristBulkAddRecordAction`, `gristBulkUpdateRecordAction`, `gristBulkRemoveRecordAction`) the root entry never exported.
27
+ - Deprecated, removed in 1.0: `useGristContext()` (use `widget.useGrist()` or `useGrist()`); `useGrist().isReady` and `isAvailable`, and `useGristSchema().isAvailable` (use `status`); `fetchSelectedTable`, `fetchTable` and `fetchTableRows` (use `fetchRows`); the nine user-action builders in the root entry (import them from `grist-widget-sdk/actions`). Each still works, is struck through in the editor (`@deprecated`), and warns once in development with what replaces it; a production build stays silent. https://gristwidgets.com/docs/sdk/api/deprecated lists them.
28
+ - The examples (`create-grist-widget --example`) are declared with `defineGristWidget()` and use none of the deprecated names.
29
+
30
+ Existing widgets keep working unchanged. To clear the warnings, replace each name as the deprecations page says.
31
+
3
32
  ## 0.5.1
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/actions/index.ts
21
+ var actions_exports = {};
22
+ __export(actions_exports, {
23
+ gristAddColumnAction: () => gristAddColumnAction,
24
+ gristAddRecordAction: () => gristAddRecordAction,
25
+ gristAddTableAction: () => gristAddTableAction,
26
+ gristAddVisibleColumnAction: () => gristAddVisibleColumnAction,
27
+ gristBulkAddRecordAction: () => gristBulkAddRecordAction,
28
+ gristBulkRemoveRecordAction: () => gristBulkRemoveRecordAction,
29
+ gristBulkUpdateRecordAction: () => gristBulkUpdateRecordAction,
30
+ gristModifyColumnAction: () => gristModifyColumnAction,
31
+ gristRemoveColumnAction: () => gristRemoveColumnAction,
32
+ gristRemoveRecordAction: () => gristRemoveRecordAction,
33
+ gristRenameColumnAction: () => gristRenameColumnAction,
34
+ gristUpdateRecordAction: () => gristUpdateRecordAction
35
+ });
36
+ module.exports = __toCommonJS(actions_exports);
37
+
38
+ // src/sdk/helpers/grist-user-actions.ts
39
+ function gristUpdateRecordAction(tableId, rowId, patch) {
40
+ return ["UpdateRecord", tableId, rowId, patch];
41
+ }
42
+ function gristAddRecordAction(tableId, values) {
43
+ return ["AddRecord", tableId, null, values];
44
+ }
45
+ function gristRemoveRecordAction(tableId, rowId) {
46
+ return ["RemoveRecord", tableId, rowId];
47
+ }
48
+ function gristBulkUpdateRecordAction(tableId, rowIds, columnarPatch) {
49
+ return ["BulkUpdateRecord", tableId, rowIds, columnarPatch];
50
+ }
51
+ function gristBulkAddRecordAction(tableId, values, rowIds) {
52
+ const length = inferBulkLength(values);
53
+ const ids = rowIds ?? new Array(length).fill(null);
54
+ return ["BulkAddRecord", tableId, ids, values];
55
+ }
56
+ function gristBulkRemoveRecordAction(tableId, rowIds) {
57
+ return ["BulkRemoveRecord", tableId, rowIds];
58
+ }
59
+ function gristAddColumnAction(tableId, colId, colInfo) {
60
+ return ["AddColumn", tableId, colId, colInfo];
61
+ }
62
+ function gristAddVisibleColumnAction(tableId, colId, colInfo) {
63
+ return ["AddVisibleColumn", tableId, colId, colInfo];
64
+ }
65
+ function gristRenameColumnAction(tableId, colId, newColId) {
66
+ return ["RenameColumn", tableId, colId, newColId];
67
+ }
68
+ function gristModifyColumnAction(tableId, colId, colInfo) {
69
+ return ["ModifyColumn", tableId, colId, colInfo];
70
+ }
71
+ function gristRemoveColumnAction(tableId, colId) {
72
+ return ["RemoveColumn", tableId, colId];
73
+ }
74
+ function gristAddTableAction(tableId, tableInfo) {
75
+ return ["AddTable", tableId, tableInfo];
76
+ }
77
+ function inferBulkLength(values) {
78
+ for (const arr of Object.values(values)) if (Array.isArray(arr)) return arr.length;
79
+ return 0;
80
+ }
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ gristAddColumnAction,
84
+ gristAddRecordAction,
85
+ gristAddTableAction,
86
+ gristAddVisibleColumnAction,
87
+ gristBulkAddRecordAction,
88
+ gristBulkRemoveRecordAction,
89
+ gristBulkUpdateRecordAction,
90
+ gristModifyColumnAction,
91
+ gristRemoveColumnAction,
92
+ gristRemoveRecordAction,
93
+ gristRenameColumnAction,
94
+ gristUpdateRecordAction
95
+ });
96
+ //# sourceMappingURL=actions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/actions/index.ts","../src/sdk/helpers/grist-user-actions.ts"],"sourcesContent":["/**\n * grist-widget-sdk/actions: user actions for `useGrist().applyActions()`,\n * Grist's own tuples for what the table API doesn't cover: schema changes\n * (tables, columns) and batches of changes applied as one undoable step.\n *\n * ```ts\n * import { gristAddColumnAction, gristRenameColumnAction } from \"grist-widget-sdk/actions\"\n *\n * await w.applyActions([\n * gristAddColumnAction(\"Tasks\", \"Due\", { type: \"Date\" }),\n * gristRenameColumnAction(\"Tasks\", \"Owner\", \"Assignee\"),\n * ])\n * ```\n *\n * Record changes in the widget's table are simpler with `w.updateRecord()`,\n * `w.addRecord()` or `w.table`.\n */\n\nexport {\n gristAddColumnAction,\n gristAddRecordAction,\n gristAddTableAction,\n gristAddVisibleColumnAction,\n gristBulkAddRecordAction,\n gristBulkRemoveRecordAction,\n gristBulkUpdateRecordAction,\n gristModifyColumnAction,\n gristRemoveColumnAction,\n gristRemoveRecordAction,\n gristRenameColumnAction,\n gristUpdateRecordAction,\n type GristUserActionTuple,\n} from \"../sdk/helpers/grist-user-actions\"\n","/**\n * Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.\n * @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions\n */\n\nexport type GristUserActionTuple = unknown[]\n\n/** `[\"UpdateRecord\", tableId, rowId, { col: value, ... }]` */\nexport function gristUpdateRecordAction(\n tableId: string,\n rowId: number,\n patch: Record<string, unknown>\n): GristUserActionTuple {\n return [\"UpdateRecord\", tableId, rowId, patch]\n}\n\n/** `[\"AddRecord\", tableId, null, { col: value, ... }]` */\nexport function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple {\n return [\"AddRecord\", tableId, null, values]\n}\n\n/** `[\"RemoveRecord\", tableId, rowId]` */\nexport function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple {\n return [\"RemoveRecord\", tableId, rowId]\n}\n\n/** `[\"BulkUpdateRecord\", tableId, rowIds, { col: value[], ... }]` */\nexport function gristBulkUpdateRecordAction(\n tableId: string,\n rowIds: number[],\n columnarPatch: Record<string, unknown[]>\n): GristUserActionTuple {\n return [\"BulkUpdateRecord\", tableId, rowIds, columnarPatch]\n}\n\n/**\n * `[\"BulkAddRecord\", tableId, rowIds | nullArray, { col: value[], ... }]`.\n * Pass `null` (or omit) for `rowIds` to let Grist allocate ids; in user-action\n * format Grist expects an array of nulls of the same length as the value arrays.\n */\nexport function gristBulkAddRecordAction(\n tableId: string,\n values: Record<string, unknown[]>,\n rowIds?: Array<number | null>\n): GristUserActionTuple {\n const length = inferBulkLength(values)\n const ids = rowIds ?? new Array<number | null>(length).fill(null)\n return [\"BulkAddRecord\", tableId, ids, values]\n}\n\n/** `[\"BulkRemoveRecord\", tableId, rowIds]` */\nexport function gristBulkRemoveRecordAction(tableId: string, rowIds: number[]): GristUserActionTuple {\n return [\"BulkRemoveRecord\", tableId, rowIds]\n}\n\n/** `[\"AddColumn\", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */\nexport function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple {\n return [\"AddColumn\", tableId, colId, colInfo]\n}\n\n/** `[\"AddVisibleColumn\", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */\nexport function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple {\n return [\"AddVisibleColumn\", tableId, colId, colInfo]\n}\n\n/** `[\"RenameColumn\", tableId, colId, newColId]` */\nexport function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple {\n return [\"RenameColumn\", tableId, colId, newColId]\n}\n\n/** `[\"ModifyColumn\", tableId, colId, colInfo]` */\nexport function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple {\n return [\"ModifyColumn\", tableId, colId, colInfo]\n}\n\n/** `[\"RemoveColumn\", tableId, colId]` */\nexport function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple {\n return [\"RemoveColumn\", tableId, colId]\n}\n\n/** `[\"AddTable\", tableId, tableInfo]` */\nexport function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple {\n return [\"AddTable\", tableId, tableInfo]\n}\n\nfunction inferBulkLength(values: Record<string, unknown[]>): number {\n for (const arr of Object.values(values)) if (Array.isArray(arr)) return arr.length\n return 0\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQO,SAAS,wBACd,SACA,OACA,OACsB;AACtB,SAAO,CAAC,gBAAgB,SAAS,OAAO,KAAK;AAC/C;AAGO,SAAS,qBAAqB,SAAiB,QAAuD;AAC3G,SAAO,CAAC,aAAa,SAAS,MAAM,MAAM;AAC5C;AAGO,SAAS,wBAAwB,SAAiB,OAAqC;AAC5F,SAAO,CAAC,gBAAgB,SAAS,KAAK;AACxC;AAGO,SAAS,4BACd,SACA,QACA,eACsB;AACtB,SAAO,CAAC,oBAAoB,SAAS,QAAQ,aAAa;AAC5D;AAOO,SAAS,yBACd,SACA,QACA,QACsB;AACtB,QAAM,SAAS,gBAAgB,MAAM;AACrC,QAAM,MAAM,UAAU,IAAI,MAAqB,MAAM,EAAE,KAAK,IAAI;AAChE,SAAO,CAAC,iBAAiB,SAAS,KAAK,MAAM;AAC/C;AAGO,SAAS,4BAA4B,SAAiB,QAAwC;AACnG,SAAO,CAAC,oBAAoB,SAAS,MAAM;AAC7C;AAGO,SAAS,qBAAqB,SAAiB,OAAe,SAAwD;AAC3H,SAAO,CAAC,aAAa,SAAS,OAAO,OAAO;AAC9C;AAGO,SAAS,4BAA4B,SAAiB,OAAe,SAAwD;AAClI,SAAO,CAAC,oBAAoB,SAAS,OAAO,OAAO;AACrD;AAGO,SAAS,wBAAwB,SAAiB,OAAe,UAAwC;AAC9G,SAAO,CAAC,gBAAgB,SAAS,OAAO,QAAQ;AAClD;AAGO,SAAS,wBAAwB,SAAiB,OAAe,SAAwD;AAC9H,SAAO,CAAC,gBAAgB,SAAS,OAAO,OAAO;AACjD;AAGO,SAAS,wBAAwB,SAAiB,OAAqC;AAC5F,SAAO,CAAC,gBAAgB,SAAS,KAAK;AACxC;AAGO,SAAS,oBAAoB,SAAiB,WAA0D;AAC7G,SAAO,CAAC,YAAY,SAAS,SAAS;AACxC;AAEA,SAAS,gBAAgB,QAA2C;AAClE,aAAW,OAAO,OAAO,OAAO,MAAM,EAAG,KAAI,MAAM,QAAQ,GAAG,EAAG,QAAO,IAAI;AAC5E,SAAO;AACT;","names":[]}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.
3
+ * @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions
4
+ */
5
+ type GristUserActionTuple = unknown[];
6
+ /** `["UpdateRecord", tableId, rowId, { col: value, ... }]` */
7
+ declare function gristUpdateRecordAction(tableId: string, rowId: number, patch: Record<string, unknown>): GristUserActionTuple;
8
+ /** `["AddRecord", tableId, null, { col: value, ... }]` */
9
+ declare function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple;
10
+ /** `["RemoveRecord", tableId, rowId]` */
11
+ declare function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple;
12
+ /** `["BulkUpdateRecord", tableId, rowIds, { col: value[], ... }]` */
13
+ declare function gristBulkUpdateRecordAction(tableId: string, rowIds: number[], columnarPatch: Record<string, unknown[]>): GristUserActionTuple;
14
+ /**
15
+ * `["BulkAddRecord", tableId, rowIds | nullArray, { col: value[], ... }]`.
16
+ * Pass `null` (or omit) for `rowIds` to let Grist allocate ids; in user-action
17
+ * format Grist expects an array of nulls of the same length as the value arrays.
18
+ */
19
+ declare function gristBulkAddRecordAction(tableId: string, values: Record<string, unknown[]>, rowIds?: Array<number | null>): GristUserActionTuple;
20
+ /** `["BulkRemoveRecord", tableId, rowIds]` */
21
+ declare function gristBulkRemoveRecordAction(tableId: string, rowIds: number[]): GristUserActionTuple;
22
+ /** `["AddColumn", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */
23
+ declare function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
24
+ /** `["AddVisibleColumn", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */
25
+ declare function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
26
+ /** `["RenameColumn", tableId, colId, newColId]` */
27
+ declare function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple;
28
+ /** `["ModifyColumn", tableId, colId, colInfo]` */
29
+ declare function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
30
+ /** `["RemoveColumn", tableId, colId]` */
31
+ declare function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple;
32
+ /** `["AddTable", tableId, tableInfo]` */
33
+ declare function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple;
34
+
35
+ export { gristAddColumnAction, gristAddRecordAction, gristAddTableAction, gristAddVisibleColumnAction, gristBulkAddRecordAction, gristBulkRemoveRecordAction, gristBulkUpdateRecordAction, gristModifyColumnAction, gristRemoveColumnAction, gristRemoveRecordAction, gristRenameColumnAction, gristUpdateRecordAction };
36
+ export type { GristUserActionTuple };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Grist `docApi.applyUserActions` payloads are arrays of user-action tuples.
3
+ * @see https://support.getgrist.com/code/interfaces/grist_plugin_api.GristDocAPI/#applyuseractions
4
+ */
5
+ type GristUserActionTuple = unknown[];
6
+ /** `["UpdateRecord", tableId, rowId, { col: value, ... }]` */
7
+ declare function gristUpdateRecordAction(tableId: string, rowId: number, patch: Record<string, unknown>): GristUserActionTuple;
8
+ /** `["AddRecord", tableId, null, { col: value, ... }]` */
9
+ declare function gristAddRecordAction(tableId: string, values: Record<string, unknown>): GristUserActionTuple;
10
+ /** `["RemoveRecord", tableId, rowId]` */
11
+ declare function gristRemoveRecordAction(tableId: string, rowId: number): GristUserActionTuple;
12
+ /** `["BulkUpdateRecord", tableId, rowIds, { col: value[], ... }]` */
13
+ declare function gristBulkUpdateRecordAction(tableId: string, rowIds: number[], columnarPatch: Record<string, unknown[]>): GristUserActionTuple;
14
+ /**
15
+ * `["BulkAddRecord", tableId, rowIds | nullArray, { col: value[], ... }]`.
16
+ * Pass `null` (or omit) for `rowIds` to let Grist allocate ids; in user-action
17
+ * format Grist expects an array of nulls of the same length as the value arrays.
18
+ */
19
+ declare function gristBulkAddRecordAction(tableId: string, values: Record<string, unknown[]>, rowIds?: Array<number | null>): GristUserActionTuple;
20
+ /** `["BulkRemoveRecord", tableId, rowIds]` */
21
+ declare function gristBulkRemoveRecordAction(tableId: string, rowIds: number[]): GristUserActionTuple;
22
+ /** `["AddColumn", tableId, colId, colInfo]` — `colInfo` shape depends on Grist version / column type. */
23
+ declare function gristAddColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
24
+ /** `["AddVisibleColumn", tableId, colId, colInfo]` — like `AddColumn` but also adds the column to the current view section. */
25
+ declare function gristAddVisibleColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
26
+ /** `["RenameColumn", tableId, colId, newColId]` */
27
+ declare function gristRenameColumnAction(tableId: string, colId: string, newColId: string): GristUserActionTuple;
28
+ /** `["ModifyColumn", tableId, colId, colInfo]` */
29
+ declare function gristModifyColumnAction(tableId: string, colId: string, colInfo: Record<string, unknown>): GristUserActionTuple;
30
+ /** `["RemoveColumn", tableId, colId]` */
31
+ declare function gristRemoveColumnAction(tableId: string, colId: string): GristUserActionTuple;
32
+ /** `["AddTable", tableId, tableInfo]` */
33
+ declare function gristAddTableAction(tableId: string, tableInfo: Record<string, unknown>): GristUserActionTuple;
34
+
35
+ export { gristAddColumnAction, gristAddRecordAction, gristAddTableAction, gristAddVisibleColumnAction, gristBulkAddRecordAction, gristBulkRemoveRecordAction, gristBulkUpdateRecordAction, gristModifyColumnAction, gristRemoveColumnAction, gristRemoveRecordAction, gristRenameColumnAction, gristUpdateRecordAction };
36
+ export type { GristUserActionTuple };
@@ -0,0 +1,29 @@
1
+ import {
2
+ gristAddColumnAction,
3
+ gristAddRecordAction,
4
+ gristAddTableAction,
5
+ gristAddVisibleColumnAction,
6
+ gristBulkAddRecordAction,
7
+ gristBulkRemoveRecordAction,
8
+ gristBulkUpdateRecordAction,
9
+ gristModifyColumnAction,
10
+ gristRemoveColumnAction,
11
+ gristRemoveRecordAction,
12
+ gristRenameColumnAction,
13
+ gristUpdateRecordAction
14
+ } from "./chunk-YGQXH2P5.js";
15
+ export {
16
+ gristAddColumnAction,
17
+ gristAddRecordAction,
18
+ gristAddTableAction,
19
+ gristAddVisibleColumnAction,
20
+ gristBulkAddRecordAction,
21
+ gristBulkRemoveRecordAction,
22
+ gristBulkUpdateRecordAction,
23
+ gristModifyColumnAction,
24
+ gristRemoveColumnAction,
25
+ gristRemoveRecordAction,
26
+ gristRenameColumnAction,
27
+ gristUpdateRecordAction
28
+ };
29
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/app.cjs CHANGED
@@ -37,6 +37,27 @@ var import_client = require("react-dom/client");
37
37
  // src/sdk/use-grist.ts
38
38
  var import_react = require("react");
39
39
 
40
+ // src/sdk/helpers/deprecate.ts
41
+ function isDevelopment() {
42
+ try {
43
+ return process.env.NODE_ENV !== "production";
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ var warned = /* @__PURE__ */ new Set();
49
+ function warnDeprecated(name, instead) {
50
+ if (warned.has(name) || !isDevelopment()) return;
51
+ warned.add(name);
52
+ console.warn(`[grist-widget-sdk] ${name} is deprecated and goes in 1.0: ${instead}. https://gristwidgets.com/docs/sdk/api/deprecated`);
53
+ }
54
+ function deprecatedFunction(name, instead, fn) {
55
+ return ((...args) => {
56
+ warnDeprecated(name, instead);
57
+ return fn(...args);
58
+ });
59
+ }
60
+
40
61
  // src/sdk/helpers/grist-value-codec.ts
41
62
  var MARSHALLED_TAGS = /* @__PURE__ */ new Set(["E", "L", "D", "d", "R", "r", "P"]);
42
63
  function isMarshalledTuple(value) {
@@ -344,8 +365,12 @@ async function getAttachmentDownloadUrl(docApi, attachmentId, options) {
344
365
  if (!getAccessToken) {
345
366
  throw new Error("getAccessToken is not available on docApi");
346
367
  }
368
+ const id = String(attachmentId).trim();
369
+ if (!/^[1-9]\d*$/.test(id)) {
370
+ throw new Error(`getAttachmentDownloadUrl: "${attachmentId}" is not an attachment id (a positive integer).`);
371
+ }
347
372
  const { token: token2, baseUrl } = await getAccessToken({ readOnly: options?.readOnly ?? false });
348
- return `${baseUrl}/attachments/${attachmentId}/download?auth=${token2}`;
373
+ return `${baseUrl}/attachments/${id}/download?auth=${encodeURIComponent(token2)}`;
349
374
  }
350
375
  async function fetchBytesFromSignedAttachmentUrl(url) {
351
376
  const response = await fetch(url);
@@ -607,15 +632,32 @@ function createGristApi(runtime) {
607
632
  destroy: (ids) => write(() => resolve().destroy(ids))
608
633
  });
609
634
  const tables = /* @__PURE__ */ new Map();
635
+ const selectedColumns = (options) => read(async () => {
636
+ const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
637
+ if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
638
+ return await impl({ keepEncoded: false, ...options });
639
+ });
640
+ const tableColumns = (tableId) => read(async () => await docApi().fetchTable(tableId));
641
+ const fetchRows = (async (a, b) => {
642
+ const tableId = typeof a === "string" ? a : null;
643
+ const { columnar, ...rowOptions } = (typeof a === "object" && a !== null ? a : b) ?? {};
644
+ if (tableId === null) {
645
+ const data = await selectedColumns(rowOptions.columns ? { keepEncoded: true } : void 0);
646
+ return columnar ? data : materializeGristRowsFromColumnar(data, { order: "none", ...rowOptions });
647
+ }
648
+ if (columnar) return tableColumns(tableId);
649
+ return read(() => fetchGristTableRows(docApi(), tableId, rowOptions));
650
+ });
610
651
  return {
611
652
  reload: () => runtime.reload(),
612
- fetchSelectedTable: (options) => read(async () => {
613
- const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
614
- if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
615
- return await impl({ keepEncoded: false, ...options });
616
- }),
617
- fetchTable: (tableId) => read(async () => await docApi().fetchTable(tableId)),
618
- fetchTableRows: (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {})),
653
+ fetchRows,
654
+ fetchSelectedTable: deprecatedFunction("useGrist().fetchSelectedTable()", "use fetchRows({ columnar: true }), or fetchRows() for rows", selectedColumns),
655
+ fetchTable: deprecatedFunction("useGrist().fetchTable()", "use fetchRows(tableId, { columnar: true }), or fetchRows(tableId) for rows", tableColumns),
656
+ fetchTableRows: deprecatedFunction(
657
+ "useGrist().fetchTableRows()",
658
+ "use fetchRows(tableId, options)",
659
+ (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {}))
660
+ ),
619
661
  listTables: (options) => read(async () => {
620
662
  const all = [...await docApi().listTables()];
621
663
  return options?.includeSystem ? all : all.filter((t) => !t.startsWith("_grist") && !t.startsWith("GristHidden_"));