@constructive-io/sheets 0.3.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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -0
  3. package/dist/advanced.cjs +5477 -0
  4. package/dist/advanced.cjs.map +1 -0
  5. package/dist/advanced.d.cts +83 -0
  6. package/dist/advanced.d.ts +83 -0
  7. package/dist/advanced.js +34 -0
  8. package/dist/advanced.js.map +1 -0
  9. package/dist/auth.cjs +1396 -0
  10. package/dist/auth.cjs.map +1 -0
  11. package/dist/auth.d.cts +60 -0
  12. package/dist/auth.d.ts +60 -0
  13. package/dist/auth.js +19 -0
  14. package/dist/auth.js.map +1 -0
  15. package/dist/chunk-4PGPVMZB.js +670 -0
  16. package/dist/chunk-4PGPVMZB.js.map +1 -0
  17. package/dist/chunk-FNVHSOQQ.js +1314 -0
  18. package/dist/chunk-FNVHSOQQ.js.map +1 -0
  19. package/dist/chunk-GGECS2BP.js +17 -0
  20. package/dist/chunk-GGECS2BP.js.map +1 -0
  21. package/dist/chunk-GLVZSPV2.js +43 -0
  22. package/dist/chunk-GLVZSPV2.js.map +1 -0
  23. package/dist/chunk-H4JJTMP5.js +160 -0
  24. package/dist/chunk-H4JJTMP5.js.map +1 -0
  25. package/dist/chunk-ODUBS2NL.js +100 -0
  26. package/dist/chunk-ODUBS2NL.js.map +1 -0
  27. package/dist/chunk-PZL2BCWF.js +168 -0
  28. package/dist/chunk-PZL2BCWF.js.map +1 -0
  29. package/dist/chunk-TU7ATZ4X.js +4494 -0
  30. package/dist/chunk-TU7ATZ4X.js.map +1 -0
  31. package/dist/chunk-X7DHTSOX.js +21 -0
  32. package/dist/chunk-X7DHTSOX.js.map +1 -0
  33. package/dist/chunk-YDQQA46V.js +13 -0
  34. package/dist/chunk-YDQQA46V.js.map +1 -0
  35. package/dist/date-editor-CXKKGNL6.js +361 -0
  36. package/dist/date-editor-CXKKGNL6.js.map +1 -0
  37. package/dist/editor-props-M6Dh0P9f.d.cts +245 -0
  38. package/dist/editor-props-M6Dh0P9f.d.ts +245 -0
  39. package/dist/index.cjs +15861 -0
  40. package/dist/index.cjs.map +1 -0
  41. package/dist/index.d.cts +1650 -0
  42. package/dist/index.d.ts +1650 -0
  43. package/dist/index.js +8470 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/map-picker-VTKDS6CM.js +290 -0
  46. package/dist/map-picker-VTKDS6CM.js.map +1 -0
  47. package/dist/sheets-context-CojEFlaY.d.cts +214 -0
  48. package/dist/sheets-context-Da55TTR9.d.ts +214 -0
  49. package/dist/testing.cjs +1113 -0
  50. package/dist/testing.cjs.map +1 -0
  51. package/dist/testing.d.cts +45 -0
  52. package/dist/testing.d.ts +45 -0
  53. package/dist/testing.js +269 -0
  54. package/dist/testing.js.map +1 -0
  55. package/package.json +144 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Constructive
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # @constructive-io/sheets
2
+
3
+ Portable spreadsheet-like CRUD editor for PostGraphile backends. Drop-in React component that provides a full-featured data grid with filtering, pagination, cell editing, draft rows, relation handling, and standalone authentication.
4
+
5
+ ## Requirements
6
+
7
+ - **Backend**: Constructive server (`cnc server`) or PostGraphile v5 with the `_meta` introspection plugin
8
+ - **Frontend**: React 18+, Tailwind CSS v4
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @constructive-io/sheets @constructive-io/data @constructive-io/ui \
14
+ @glideapps/glide-data-grid @tanstack/react-query @tanstack/react-form
15
+ ```
16
+
17
+ ### Optional peer dependencies
18
+
19
+ | Package | For |
20
+ |---------|-----|
21
+ | `leaflet` + `react-leaflet` | Geometry/map editors |
22
+ | `react-aria-components` + `@internationalized/date` | Date picker editors |
23
+ | `lucide-react` | Icons |
24
+ | `@remixicon/react` | Icons |
25
+
26
+ ## Quick Start
27
+
28
+ ### Standalone mode (built-in login UI)
29
+
30
+ ```tsx
31
+ import {
32
+ SheetsProvider, Sheets, SheetsTableSelector,
33
+ SheetsAuthGate, useSheetsMeta,
34
+ } from '@constructive-io/sheets';
35
+
36
+ function SpreadsheetApp() {
37
+ const [activeTable, setActiveTable] = useState('');
38
+ const { data: meta, isLoading } = useSheetsMeta();
39
+
40
+ const tables = useMemo(() => {
41
+ const metaTables = meta?._meta?.tables;
42
+ if (!metaTables?.length) return [];
43
+ return metaTables
44
+ .filter((t): t is NonNullable<typeof t> => Boolean(t?.name))
45
+ .map((t) => ({ name: t.name }))
46
+ .sort((a, b) => a.name.localeCompare(b.name));
47
+ }, [meta?._meta?.tables]);
48
+
49
+ return (
50
+ <>
51
+ <SheetsTableSelector
52
+ tables={tables}
53
+ activeTable={activeTable}
54
+ onTableChange={setActiveTable}
55
+ isLoading={isLoading}
56
+ />
57
+ {activeTable && <Sheets tableName={activeTable} />}
58
+ </>
59
+ );
60
+ }
61
+
62
+ function App() {
63
+ return (
64
+ <SheetsProvider config={{
65
+ endpoint: 'http://localhost:3000/graphql',
66
+ auth: { mode: 'standalone' },
67
+ }}>
68
+ <SheetsAuthGate>
69
+ <SpreadsheetApp />
70
+ </SheetsAuthGate>
71
+ </SheetsProvider>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ### Embedded mode (bring your own auth)
77
+
78
+ ```tsx
79
+ import { SheetsProvider, Sheets } from '@constructive-io/sheets';
80
+
81
+ function MySpreadsheet() {
82
+ return (
83
+ <SheetsProvider config={{
84
+ endpoint: 'http://localhost:3000/graphql',
85
+ auth: {
86
+ mode: 'embedded',
87
+ getToken: () => localStorage.getItem('my-jwt-token'),
88
+ },
89
+ onAuthError: () => {
90
+ // Handle 401 — clear tokens, redirect to login, etc.
91
+ },
92
+ }}>
93
+ <Sheets tableName="users" />
94
+ </SheetsProvider>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ## CSS Setup
100
+
101
+ Sheets requires Tailwind CSS v4 and the glide-data-grid styles.
102
+
103
+ ### 1. Install Tailwind v4
104
+
105
+ ```bash
106
+ npm install tailwindcss @tailwindcss/postcss
107
+ ```
108
+
109
+ ### 2. Import styles in your global CSS
110
+
111
+ ```css
112
+ /* globals.css */
113
+ @import 'tailwindcss';
114
+ @import '@constructive-io/ui/globals.css';
115
+
116
+ /* Scan sheets + ui packages for Tailwind classes */
117
+ @source "../node_modules/@constructive-io/ui/src";
118
+ @source "../node_modules/@constructive-io/sheets/src";
119
+ ```
120
+
121
+ Then import the glide-data-grid CSS in your layout or entry component (not in the Tailwind CSS file):
122
+
123
+ ```tsx
124
+ // app/layout.tsx
125
+ import '@glideapps/glide-data-grid/dist/index.css';
126
+ ```
127
+
128
+ ### 3. Add the portal element
129
+
130
+ Glide Data Grid renders overlay editors into a portal. Add this as the last child of `<body>` in your root layout:
131
+
132
+ ```tsx
133
+ // app/layout.tsx
134
+ <body>
135
+ {children}
136
+ <div id="portal" />
137
+ </body>
138
+ ```
139
+
140
+ Without this, cell editors (date pickers, relation selectors, JSON editors, etc.) won't open.
141
+
142
+ ## Configuration
143
+
144
+ The `SheetsConfig` object passed to `<SheetsProvider>`:
145
+
146
+ | Prop | Type | Required | Description |
147
+ |------|------|----------|-------------|
148
+ | `endpoint` | `string` | Yes | PostGraphile GraphQL endpoint URL |
149
+ | `auth` | `SheetsAuthEmbedded \| SheetsAuthStandalone` | Yes | Auth mode |
150
+ | `authEndpoint` | `string` | No | Separate auth GraphQL endpoint |
151
+ | `databaseId` | `string` | No | Multi-tenant database scope |
152
+ | `fieldTypeOverrides` | `Record<string, string>` | No | Override detected field types |
153
+ | `execute` | `SheetsExecuteFn` | No | Custom GraphQL executor |
154
+ | `executeUpload` | `SheetsUploadFn` | No | Custom file upload handler |
155
+ | `queryClient` | `QueryClient` | No | Bring-your-own TanStack Query client |
156
+ | `onAuthError` | `() => void` | No | Callback on 401/UNAUTHENTICATED |
157
+
158
+ ## Components
159
+
160
+ | Component | Description |
161
+ |-----------|-------------|
162
+ | `SheetsProvider` | Context provider — wrap your app once |
163
+ | `Sheets` | Main data grid (table name required) |
164
+ | `SheetsTableSelector` | Table picker sidebar |
165
+ | `SheetsControls` | Filter/search bar (included in Sheets by default) |
166
+ | `SheetsPagination` | Page navigation (included in Sheets by default) |
167
+ | `SheetsAuthGate` | Login/register UI for standalone mode |
168
+
169
+ ## Hooks
170
+
171
+ | Hook | Description |
172
+ |------|-------------|
173
+ | `useSheetsTable(tableName, options)` | Full CRUD operations for a table |
174
+ | `useSheetsInfiniteTable(tableName, options)` | Infinite scroll variant |
175
+ | `useSheetsMeta()` | Schema introspection metadata |
176
+ | `useSheetsStore(selector)` | Access sheets Zustand store |
177
+ | `useDynamicCreate(tableName)` | Programmatic row creation |
178
+ | `useDynamicUpdate(tableName)` | Programmatic row updates |
179
+
180
+ ## Documentation
181
+
182
+ - [Embedding Guide](./docs/EMBEDDING.md) — full integration walkthrough
183
+ - [Host Integration](./docs/HOST_INTEGRATION.md) — auth error handling, QueryClient sharing
184
+ - [Overlay Editors](./docs/OVERLAY_EDITORS.md) — editor architecture and custom editors
185
+
186
+ ## License
187
+
188
+ MIT