grist-widget-sdk 0.3.20 → 0.3.26

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 (38) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/advanced.d.cts +3 -2
  3. package/dist/advanced.d.ts +3 -2
  4. package/dist/app.cjs +5176 -0
  5. package/dist/app.cjs.map +1 -0
  6. package/dist/app.d.cts +147 -0
  7. package/dist/app.d.ts +147 -0
  8. package/dist/app.js +527 -0
  9. package/dist/app.js.map +1 -0
  10. package/dist/chunk-PDGEZ24B.js +2366 -0
  11. package/dist/chunk-PDGEZ24B.js.map +1 -0
  12. package/dist/{create-grist-emulator-_3_JK7Rr.d.ts → create-grist-emulator-BCqp1BF9.d.ts} +2 -2
  13. package/dist/{create-grist-emulator-K-iUKUCZ.d.cts → create-grist-emulator-DBM8OSIR.d.cts} +2 -2
  14. package/dist/emulator/testing.d.cts +2 -2
  15. package/dist/emulator/testing.d.ts +2 -2
  16. package/dist/emulator/transports.d.cts +3 -3
  17. package/dist/emulator/transports.d.ts +3 -3
  18. package/dist/emulator.d.cts +5 -5
  19. package/dist/emulator.d.ts +5 -5
  20. package/dist/index.d.cts +9 -500
  21. package/dist/index.d.ts +9 -500
  22. package/dist/index.js +57 -2291
  23. package/dist/index.js.map +1 -1
  24. package/dist/{inline-A8yaddmp.d.cts → inline-C7DkvuET.d.cts} +1 -1
  25. package/dist/{inline-B7QQeWul.d.ts → inline-DpcT8tV9.d.ts} +1 -1
  26. package/dist/{templates-CB_VwjEU.d.cts → templates-8k2LKoO-.d.cts} +1 -1
  27. package/dist/{templates-pRIXc2RR.d.ts → templates-DIwi_mvI.d.ts} +1 -1
  28. package/dist/{types-YcRfo7oy.d.cts → types-D3JxUCfL.d.cts} +1 -1
  29. package/dist/{types-YcRfo7oy.d.ts → types-D3JxUCfL.d.ts} +1 -1
  30. package/dist/{use-grist-widget-options-from-context-hl-NwOwP.d.ts → use-grist-reads-DUMvJgV7.d.ts} +3 -44
  31. package/dist/{use-grist-widget-options-from-context-Bbd5-f39.d.cts → use-grist-reads-DpjVuI0H.d.cts} +3 -44
  32. package/dist/use-grist-types-DdOLEJXN.d.cts +499 -0
  33. package/dist/use-grist-types-kwxoFeub.d.ts +499 -0
  34. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.cts +43 -0
  35. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.ts +43 -0
  36. package/package.json +15 -2
  37. package/tsconfig/app.json +38 -0
  38. package/tsconfig/node.json +36 -0
package/dist/app.d.cts ADDED
@@ -0,0 +1,147 @@
1
+ import * as react from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
3
+ import { UseGristOptions } from './index.cjs';
4
+ import './types-D3JxUCfL.cjs';
5
+ import './use-grist-reads-DpjVuI0H.cjs';
6
+ import 'zod';
7
+
8
+ /**
9
+ * Where a deployed build is being served from.
10
+ *
11
+ * A widget's deploy pipeline publishes the same build at its root and at
12
+ * `/latest/`, a preview at `/dev/`, and each release at `/v<version>/`, all
13
+ * under one base path (e.g. `/my-widget/` on GitHub Pages). Opened outside
14
+ * Grist, the page tells them apart from `window.location.pathname` alone.
15
+ */
16
+ type DeployChannel = {
17
+ kind: "latest";
18
+ } | {
19
+ kind: "dev";
20
+ } | {
21
+ kind: "version";
22
+ version: string;
23
+ };
24
+ type DeployPath = {
25
+ channel: DeployChannel;
26
+ /**
27
+ * The path the channels live under, always ending in `/`: the current
28
+ * path without its channel segment. `"/my-widget/v1.2.0/"` gives
29
+ * `"/my-widget/"`.
30
+ */
31
+ basePath: string;
32
+ };
33
+ /**
34
+ * Parse a pathname into its deploy channel and base path. A path without a
35
+ * channel segment (the deployed root, or a local dev server) is `latest`:
36
+ * the deploy places the latest release at the root too.
37
+ */
38
+ declare function parseDeployPath(pathname: string): DeployPath;
39
+ /** `"latest"`, `"dev"` or `"v1.2.0"`. */
40
+ declare function deployChannelLabel(channel: DeployChannel): string;
41
+
42
+ type GristWidgetAppProps = {
43
+ /** The widget. A `React.lazy()` component works too: its code then loads only inside Grist. */
44
+ App: ComponentType;
45
+ /** The widget's `GRIST_OPTIONS`: access level, columns, and so on. */
46
+ options: UseGristOptions;
47
+ /**
48
+ * Whether this is the local dev server. Pass `import.meta.env.DEV`.
49
+ * Outside Grist it picks the local-dev page over the release page.
50
+ */
51
+ dev?: boolean;
52
+ /**
53
+ * Wraps the widget inside Grist, under {@link GristBoundary}. The default
54
+ * lists what needs the user's attention (column mapping, access level,
55
+ * failed writes) above the widget; `null` renders the widget alone.
56
+ */
57
+ Alerts?: ComponentType<{
58
+ children: ReactNode;
59
+ }> | null;
60
+ /** Shown outside Grist on the local dev server. Defaults to a page pointing at `pnpm test` and the `dev` loop. */
61
+ LocalDevPage?: ComponentType;
62
+ /**
63
+ * Shown outside Grist on a deployed URL (`/latest/`, `/dev/`, `/v<version>/`).
64
+ * Defaults to a page linking every channel and version, with the URL to
65
+ * paste into Grist.
66
+ */
67
+ ReleasePage?: ComponentType<{
68
+ channel: DeployChannel;
69
+ }>;
70
+ };
71
+ type MountGristWidgetConfig = GristWidgetAppProps & {
72
+ /** The element to render into, or its CSS selector. Defaults to `#root`. */
73
+ root?: Element | string;
74
+ };
75
+ type MountedGristWidget = {
76
+ unmount: () => void;
77
+ };
78
+ /**
79
+ * Render a widget into the page: everything `src/main.tsx` used to wire by
80
+ * hand.
81
+ *
82
+ * ```tsx
83
+ * import { mountGristWidget } from "grist-widget-sdk/app"
84
+ * import "./index.css"
85
+ * import App, { GRIST_OPTIONS } from "./App"
86
+ *
87
+ * mountGristWidget({ App, options: GRIST_OPTIONS, dev: import.meta.env.DEV })
88
+ * ```
89
+ *
90
+ * Inside Grist, the widget renders in {@link GristWidgetProvider} and
91
+ * {@link GristBoundary}, which gates on its mapped columns when it declares
92
+ * any, and follows Grist's light/dark theme. Outside Grist, where there is
93
+ * nothing to connect to, the page shows `LocalDevPage` on the dev server and
94
+ * `ReleasePage` on a deployed URL.
95
+ */
96
+ declare function mountGristWidget(config: MountGristWidgetConfig): MountedGristWidget;
97
+ /**
98
+ * The tree {@link mountGristWidget} renders, as a component: for a test, or
99
+ * for a page that manages its own React root.
100
+ */
101
+ declare function GristWidgetApp({ App, options, dev, Alerts, LocalDevPage, ReleasePage, }: GristWidgetAppProps): react.JSX.Element;
102
+
103
+ type WidgetTheme = "light" | "dark" | "system";
104
+ type ResolvedWidgetTheme = "light" | "dark";
105
+ type UseThemeResult = {
106
+ /**
107
+ * Inside Grist: Grist's theme, or `"system"` until Grist has sent it.
108
+ * Outside Grist: the saved choice, `"system"` by default.
109
+ */
110
+ theme: WidgetTheme;
111
+ /** The theme applied to `<html class>`: `"system"` resolved to light or dark. */
112
+ resolvedTheme: ResolvedWidgetTheme;
113
+ /**
114
+ * Choose a theme outside Grist; it is saved in `localStorage`. Inside Grist
115
+ * this does nothing: the widget follows Grist's theme.
116
+ */
117
+ setTheme: (theme: WidgetTheme) => void;
118
+ };
119
+ /**
120
+ * The widget's current theme, for components that need it in JavaScript
121
+ * (a toaster, a chart). Same shape as shadcn's `useTheme()`. Styles should
122
+ * rely on the `dark` class that {@link mountGristWidget} keeps on `<html>`.
123
+ * Outside a mounted widget (a unit test, for instance) it reports the
124
+ * system theme and `setTheme` does nothing.
125
+ */
126
+ declare function useTheme(): UseThemeResult;
127
+
128
+ /** One entry of the `versions.json` a widget's deploy pipeline maintains. */
129
+ type ReleasedVersion = {
130
+ version: string;
131
+ publishedAt: string;
132
+ };
133
+ type UseReleasedVersionsResult = {
134
+ /** Newest first, as the deploy writes them; `null` until loaded. */
135
+ versions: ReleasedVersion[] | null;
136
+ /** `true` when `versions.json` couldn't be fetched or read. */
137
+ error: boolean;
138
+ };
139
+ /**
140
+ * The widget's released versions, read from the `versions.json` next to its
141
+ * channels (see {@link parseDeployPath}). For a page shown outside Grist,
142
+ * such as a release page linking to each version.
143
+ */
144
+ declare function useReleasedVersions(pathname?: string): UseReleasedVersionsResult;
145
+
146
+ export { GristWidgetApp, deployChannelLabel, mountGristWidget, parseDeployPath, useReleasedVersions, useTheme };
147
+ export type { DeployChannel, DeployPath, GristWidgetAppProps, MountGristWidgetConfig, MountedGristWidget, ReleasedVersion, ResolvedWidgetTheme, UseReleasedVersionsResult, UseThemeResult, WidgetTheme };
package/dist/app.d.ts ADDED
@@ -0,0 +1,147 @@
1
+ import * as react from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
3
+ import { UseGristOptions } from './index.js';
4
+ import './types-D3JxUCfL.js';
5
+ import './use-grist-reads-DUMvJgV7.js';
6
+ import 'zod';
7
+
8
+ /**
9
+ * Where a deployed build is being served from.
10
+ *
11
+ * A widget's deploy pipeline publishes the same build at its root and at
12
+ * `/latest/`, a preview at `/dev/`, and each release at `/v<version>/`, all
13
+ * under one base path (e.g. `/my-widget/` on GitHub Pages). Opened outside
14
+ * Grist, the page tells them apart from `window.location.pathname` alone.
15
+ */
16
+ type DeployChannel = {
17
+ kind: "latest";
18
+ } | {
19
+ kind: "dev";
20
+ } | {
21
+ kind: "version";
22
+ version: string;
23
+ };
24
+ type DeployPath = {
25
+ channel: DeployChannel;
26
+ /**
27
+ * The path the channels live under, always ending in `/`: the current
28
+ * path without its channel segment. `"/my-widget/v1.2.0/"` gives
29
+ * `"/my-widget/"`.
30
+ */
31
+ basePath: string;
32
+ };
33
+ /**
34
+ * Parse a pathname into its deploy channel and base path. A path without a
35
+ * channel segment (the deployed root, or a local dev server) is `latest`:
36
+ * the deploy places the latest release at the root too.
37
+ */
38
+ declare function parseDeployPath(pathname: string): DeployPath;
39
+ /** `"latest"`, `"dev"` or `"v1.2.0"`. */
40
+ declare function deployChannelLabel(channel: DeployChannel): string;
41
+
42
+ type GristWidgetAppProps = {
43
+ /** The widget. A `React.lazy()` component works too: its code then loads only inside Grist. */
44
+ App: ComponentType;
45
+ /** The widget's `GRIST_OPTIONS`: access level, columns, and so on. */
46
+ options: UseGristOptions;
47
+ /**
48
+ * Whether this is the local dev server. Pass `import.meta.env.DEV`.
49
+ * Outside Grist it picks the local-dev page over the release page.
50
+ */
51
+ dev?: boolean;
52
+ /**
53
+ * Wraps the widget inside Grist, under {@link GristBoundary}. The default
54
+ * lists what needs the user's attention (column mapping, access level,
55
+ * failed writes) above the widget; `null` renders the widget alone.
56
+ */
57
+ Alerts?: ComponentType<{
58
+ children: ReactNode;
59
+ }> | null;
60
+ /** Shown outside Grist on the local dev server. Defaults to a page pointing at `pnpm test` and the `dev` loop. */
61
+ LocalDevPage?: ComponentType;
62
+ /**
63
+ * Shown outside Grist on a deployed URL (`/latest/`, `/dev/`, `/v<version>/`).
64
+ * Defaults to a page linking every channel and version, with the URL to
65
+ * paste into Grist.
66
+ */
67
+ ReleasePage?: ComponentType<{
68
+ channel: DeployChannel;
69
+ }>;
70
+ };
71
+ type MountGristWidgetConfig = GristWidgetAppProps & {
72
+ /** The element to render into, or its CSS selector. Defaults to `#root`. */
73
+ root?: Element | string;
74
+ };
75
+ type MountedGristWidget = {
76
+ unmount: () => void;
77
+ };
78
+ /**
79
+ * Render a widget into the page: everything `src/main.tsx` used to wire by
80
+ * hand.
81
+ *
82
+ * ```tsx
83
+ * import { mountGristWidget } from "grist-widget-sdk/app"
84
+ * import "./index.css"
85
+ * import App, { GRIST_OPTIONS } from "./App"
86
+ *
87
+ * mountGristWidget({ App, options: GRIST_OPTIONS, dev: import.meta.env.DEV })
88
+ * ```
89
+ *
90
+ * Inside Grist, the widget renders in {@link GristWidgetProvider} and
91
+ * {@link GristBoundary}, which gates on its mapped columns when it declares
92
+ * any, and follows Grist's light/dark theme. Outside Grist, where there is
93
+ * nothing to connect to, the page shows `LocalDevPage` on the dev server and
94
+ * `ReleasePage` on a deployed URL.
95
+ */
96
+ declare function mountGristWidget(config: MountGristWidgetConfig): MountedGristWidget;
97
+ /**
98
+ * The tree {@link mountGristWidget} renders, as a component: for a test, or
99
+ * for a page that manages its own React root.
100
+ */
101
+ declare function GristWidgetApp({ App, options, dev, Alerts, LocalDevPage, ReleasePage, }: GristWidgetAppProps): react.JSX.Element;
102
+
103
+ type WidgetTheme = "light" | "dark" | "system";
104
+ type ResolvedWidgetTheme = "light" | "dark";
105
+ type UseThemeResult = {
106
+ /**
107
+ * Inside Grist: Grist's theme, or `"system"` until Grist has sent it.
108
+ * Outside Grist: the saved choice, `"system"` by default.
109
+ */
110
+ theme: WidgetTheme;
111
+ /** The theme applied to `<html class>`: `"system"` resolved to light or dark. */
112
+ resolvedTheme: ResolvedWidgetTheme;
113
+ /**
114
+ * Choose a theme outside Grist; it is saved in `localStorage`. Inside Grist
115
+ * this does nothing: the widget follows Grist's theme.
116
+ */
117
+ setTheme: (theme: WidgetTheme) => void;
118
+ };
119
+ /**
120
+ * The widget's current theme, for components that need it in JavaScript
121
+ * (a toaster, a chart). Same shape as shadcn's `useTheme()`. Styles should
122
+ * rely on the `dark` class that {@link mountGristWidget} keeps on `<html>`.
123
+ * Outside a mounted widget (a unit test, for instance) it reports the
124
+ * system theme and `setTheme` does nothing.
125
+ */
126
+ declare function useTheme(): UseThemeResult;
127
+
128
+ /** One entry of the `versions.json` a widget's deploy pipeline maintains. */
129
+ type ReleasedVersion = {
130
+ version: string;
131
+ publishedAt: string;
132
+ };
133
+ type UseReleasedVersionsResult = {
134
+ /** Newest first, as the deploy writes them; `null` until loaded. */
135
+ versions: ReleasedVersion[] | null;
136
+ /** `true` when `versions.json` couldn't be fetched or read. */
137
+ error: boolean;
138
+ };
139
+ /**
140
+ * The widget's released versions, read from the `versions.json` next to its
141
+ * channels (see {@link parseDeployPath}). For a page shown outside Grist,
142
+ * such as a release page linking to each version.
143
+ */
144
+ declare function useReleasedVersions(pathname?: string): UseReleasedVersionsResult;
145
+
146
+ export { GristWidgetApp, deployChannelLabel, mountGristWidget, parseDeployPath, useReleasedVersions, useTheme };
147
+ export type { DeployChannel, DeployPath, GristWidgetAppProps, MountGristWidgetConfig, MountedGristWidget, ReleasedVersion, ResolvedWidgetTheme, UseReleasedVersionsResult, UseThemeResult, WidgetTheme };