grist-widget-sdk 0.5.0 → 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.
Files changed (43) 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 +49 -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-DKCRFNAW.js} +104 -17
  18. package/dist/chunk-DKCRFNAW.js.map +1 -0
  19. package/dist/{chunk-LSALXIGM.js → chunk-TUPCTWE5.js} +7 -3
  20. package/dist/chunk-TUPCTWE5.js.map +1 -0
  21. package/dist/chunk-YGQXH2P5.js +81 -0
  22. package/dist/chunk-YGQXH2P5.js.map +1 -0
  23. package/dist/{define-widget-B1FIvI-h.d.cts → define-widget-CYYdqRmB.d.cts} +39 -29
  24. package/dist/{define-widget-B9gEtJP0.d.ts → define-widget-D-NmSglS.d.ts} +39 -29
  25. package/dist/emulator/testing.cjs +49 -8
  26. package/dist/emulator/testing.cjs.map +1 -1
  27. package/dist/emulator/testing.d.cts +1 -0
  28. package/dist/emulator/testing.d.ts +1 -0
  29. package/dist/emulator/testing.js +8 -6
  30. package/dist/emulator/testing.js.map +1 -1
  31. package/dist/emulator.cjs.map +1 -1
  32. package/dist/emulator.js +3 -2
  33. package/dist/index.cjs +128 -23
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +30 -3
  36. package/dist/index.d.ts +30 -3
  37. package/dist/index.js +12 -11
  38. package/dist/{mount-grist-widget-Dtelqao_.d.cts → mount-grist-widget-D0mr__ga.d.cts} +1 -1
  39. package/dist/{mount-grist-widget-CkB-3iG_.d.ts → mount-grist-widget-DVcFl5Ys.d.ts} +1 -1
  40. package/package.json +11 -1
  41. package/dist/chunk-4ZGVKGDF.js.map +0 -1
  42. package/dist/chunk-LSALXIGM.js.map +0 -1
  43. package/dist/chunk-MAPAWVQC.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # grist-widget-sdk
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 04fcfe6: **One way to do each thing: `fetchRows()`, `grist-widget-sdk/actions`, and soft deprecations.**
8
+
9
+ ```ts
10
+ const rows = await w.fetchRows() // the section's rows, in its order
11
+ const people = await w.fetchRows("People") // any table's rows (full access)
12
+ const columns = await w.fetchRows({ columnar: true }) // Grist's own column-oriented payload
13
+
14
+ import { gristAddColumnAction } from "grist-widget-sdk/actions"
15
+ ```
16
+
17
+ - `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.
18
+ - `grist-widget-sdk/actions` is the user actions' own entry point, with the bulk record builders (`gristBulkAddRecordAction`, `gristBulkUpdateRecordAction`, `gristBulkRemoveRecordAction`) the root entry never exported.
19
+ - 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.
20
+ - The examples (`create-grist-widget --example`) are declared with `defineGristWidget()` and use none of the deprecated names.
21
+
22
+ Existing widgets keep working unchanged. To clear the warnings, replace each name as the deprecations page says.
23
+
24
+ ## 0.5.1
25
+
26
+ ### Patch Changes
27
+
28
+ - 10015f7: **`mountGristWidget(entry)` and `smokeTestWidget(entry)` read an entry module that also exports its component as `App`.** A widget whose `src/app/App.tsx` has `export function App()` next to `export default App` was taken for the older `{ App, options }` form: `mountGristWidget(entry)` (the 0.5 template's `src/main.tsx`) mounted it without its `GRIST_OPTIONS` (no declared columns, no access level), and `smokeTestWidget(entry)` threw. An entry module is now recognised by its default export.
29
+
30
+ Existing widgets: nothing to do. A widget on `create-grist-widget` 0.5.0's template with a named `App` export gets its declaration back once this version is installed.
31
+
3
32
  ## 0.5.0
4
33
 
5
34
  ### Minor 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) {
@@ -607,15 +628,32 @@ function createGristApi(runtime) {
607
628
  destroy: (ids) => write(() => resolve().destroy(ids))
608
629
  });
609
630
  const tables = /* @__PURE__ */ new Map();
631
+ const selectedColumns = (options) => read(async () => {
632
+ const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
633
+ if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
634
+ return await impl({ keepEncoded: false, ...options });
635
+ });
636
+ const tableColumns = (tableId) => read(async () => await docApi().fetchTable(tableId));
637
+ const fetchRows = (async (a, b) => {
638
+ const tableId = typeof a === "string" ? a : null;
639
+ const { columnar, ...rowOptions } = (typeof a === "object" && a !== null ? a : b) ?? {};
640
+ if (tableId === null) {
641
+ const data = await selectedColumns(rowOptions.columns ? { keepEncoded: true } : void 0);
642
+ return columnar ? data : materializeGristRowsFromColumnar(data, { order: "none", ...rowOptions });
643
+ }
644
+ if (columnar) return tableColumns(tableId);
645
+ return read(() => fetchGristTableRows(docApi(), tableId, rowOptions));
646
+ });
610
647
  return {
611
648
  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 ?? {})),
649
+ fetchRows,
650
+ fetchSelectedTable: deprecatedFunction("useGrist().fetchSelectedTable()", "use fetchRows({ columnar: true }), or fetchRows() for rows", selectedColumns),
651
+ fetchTable: deprecatedFunction("useGrist().fetchTable()", "use fetchRows(tableId, { columnar: true }), or fetchRows(tableId) for rows", tableColumns),
652
+ fetchTableRows: deprecatedFunction(
653
+ "useGrist().fetchTableRows()",
654
+ "use fetchRows(tableId, options)",
655
+ (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {}))
656
+ ),
619
657
  listTables: (options) => read(async () => {
620
658
  const all = [...await docApi().listTables()];
621
659
  return options?.includeSystem ? all : all.filter((t) => !t.startsWith("_grist") && !t.startsWith("GristHidden_"));
@@ -2020,6 +2058,9 @@ function noop() {
2020
2058
 
2021
2059
  // src/app/mount-grist-widget.tsx
2022
2060
  var import_jsx_runtime7 = require("react/jsx-runtime");
2061
+ function isGristWidgetEntry(value) {
2062
+ return "default" in value && value.default != null;
2063
+ }
2023
2064
  function entryProps(entry, dev = false) {
2024
2065
  const widget = isGristWidget(entry.widget) ? entry.widget : void 0;
2025
2066
  const options = widget?.options ?? entry.GRIST_OPTIONS;
@@ -2040,7 +2081,7 @@ function entryProps(entry, dev = false) {
2040
2081
  return props;
2041
2082
  }
2042
2083
  function mountGristWidget(config, entryOptions = {}) {
2043
- const { root = "#root", ...props } = "App" in config ? config : { ...entryProps(config, entryOptions.dev), root: entryOptions.root };
2084
+ const { root = "#root", ...props } = isGristWidgetEntry(config) ? { ...entryProps(config, entryOptions.dev), root: entryOptions.root } : config;
2044
2085
  const container = typeof root === "string" ? document.querySelector(root) : root;
2045
2086
  if (!container) {
2046
2087
  throw new Error(`mountGristWidget: no element matches "${String(root)}" to render the widget into.`);