@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.
- package/LICENSE +21 -0
- package/README.md +188 -0
- package/dist/advanced.cjs +5477 -0
- package/dist/advanced.cjs.map +1 -0
- package/dist/advanced.d.cts +83 -0
- package/dist/advanced.d.ts +83 -0
- package/dist/advanced.js +34 -0
- package/dist/advanced.js.map +1 -0
- package/dist/auth.cjs +1396 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +60 -0
- package/dist/auth.d.ts +60 -0
- package/dist/auth.js +19 -0
- package/dist/auth.js.map +1 -0
- package/dist/chunk-4PGPVMZB.js +670 -0
- package/dist/chunk-4PGPVMZB.js.map +1 -0
- package/dist/chunk-FNVHSOQQ.js +1314 -0
- package/dist/chunk-FNVHSOQQ.js.map +1 -0
- package/dist/chunk-GGECS2BP.js +17 -0
- package/dist/chunk-GGECS2BP.js.map +1 -0
- package/dist/chunk-GLVZSPV2.js +43 -0
- package/dist/chunk-GLVZSPV2.js.map +1 -0
- package/dist/chunk-H4JJTMP5.js +160 -0
- package/dist/chunk-H4JJTMP5.js.map +1 -0
- package/dist/chunk-ODUBS2NL.js +100 -0
- package/dist/chunk-ODUBS2NL.js.map +1 -0
- package/dist/chunk-PZL2BCWF.js +168 -0
- package/dist/chunk-PZL2BCWF.js.map +1 -0
- package/dist/chunk-TU7ATZ4X.js +4494 -0
- package/dist/chunk-TU7ATZ4X.js.map +1 -0
- package/dist/chunk-X7DHTSOX.js +21 -0
- package/dist/chunk-X7DHTSOX.js.map +1 -0
- package/dist/chunk-YDQQA46V.js +13 -0
- package/dist/chunk-YDQQA46V.js.map +1 -0
- package/dist/date-editor-CXKKGNL6.js +361 -0
- package/dist/date-editor-CXKKGNL6.js.map +1 -0
- package/dist/editor-props-M6Dh0P9f.d.cts +245 -0
- package/dist/editor-props-M6Dh0P9f.d.ts +245 -0
- package/dist/index.cjs +15861 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1650 -0
- package/dist/index.d.ts +1650 -0
- package/dist/index.js +8470 -0
- package/dist/index.js.map +1 -0
- package/dist/map-picker-VTKDS6CM.js +290 -0
- package/dist/map-picker-VTKDS6CM.js.map +1 -0
- package/dist/sheets-context-CojEFlaY.d.cts +214 -0
- package/dist/sheets-context-Da55TTR9.d.ts +214 -0
- package/dist/testing.cjs +1113 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +45 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +269 -0
- package/dist/testing.js.map +1 -0
- package/package.json +144 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { DocumentNode } from 'graphql';
|
|
4
|
+
import { TypedDocumentString, MetaQuery, CleanTable, FieldSelection, MutationOptions } from '@constructive-io/data';
|
|
5
|
+
import { S as SheetsCell, b as CellType, c as CellCategory, C as CellCreationMetadata, E as EditorProps } from './editor-props-M6Dh0P9f.js';
|
|
6
|
+
|
|
7
|
+
type ExecutableDocument = TypedDocumentString<any, any> | DocumentNode | string | unknown;
|
|
8
|
+
type SheetsExecuteFn = <T = unknown>(document: ExecutableDocument, variables?: Record<string, unknown>) => Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Result of an upload through the seam. `url` is the only guaranteed field;
|
|
11
|
+
* the REST upload endpoint also returns `{ filename, mime, size }` (and may
|
|
12
|
+
* return server-internal extras). Keeping it open-ended lets callers read the
|
|
13
|
+
* richer metadata while a bare `{ url }` (e.g. the mock) still satisfies it.
|
|
14
|
+
*/
|
|
15
|
+
type SheetsUploadResult = {
|
|
16
|
+
url: string;
|
|
17
|
+
} & Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Optional upload metadata carried through the seam (third arg). Lets an
|
|
20
|
+
* injected `executeUpload` see the destination field/row and report progress.
|
|
21
|
+
* All fields optional, so existing `(file, path?)` callers stay valid.
|
|
22
|
+
*/
|
|
23
|
+
interface SheetsUploadOptions {
|
|
24
|
+
tableName?: string;
|
|
25
|
+
fieldName?: string;
|
|
26
|
+
recordId?: string | number;
|
|
27
|
+
onProgress?: (progress: {
|
|
28
|
+
loaded: number;
|
|
29
|
+
total: number;
|
|
30
|
+
percentage: number;
|
|
31
|
+
}) => void;
|
|
32
|
+
}
|
|
33
|
+
type SheetsUploadFn = (file: File, path?: string, options?: SheetsUploadOptions) => Promise<SheetsUploadResult>;
|
|
34
|
+
declare function createSheetsExecute(config: SheetsConfig, getToken: () => string | null): SheetsExecuteFn;
|
|
35
|
+
declare function createSheetsUpload(config: SheetsConfig, getToken: () => string | null): SheetsUploadFn;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Injectable logger seam for @constructive-io/sheets.
|
|
39
|
+
*
|
|
40
|
+
* The host app may provide a custom logger via SheetsConfig.logger. The provider
|
|
41
|
+
* installs it into this module singleton (see sheets-provider.tsx), so any module
|
|
42
|
+
* or hook can log without threading the logger through props/context.
|
|
43
|
+
*
|
|
44
|
+
* Default behaviour matches the prior console.* calls. `debug` is omitted from the
|
|
45
|
+
* default logger (no-op) so verbose diagnostics stay silent unless a host opts in.
|
|
46
|
+
*/
|
|
47
|
+
interface SheetsLogger {
|
|
48
|
+
debug?(msg: string, ctx?: unknown): void;
|
|
49
|
+
warn(msg: string, ctx?: unknown): void;
|
|
50
|
+
error(msg: string, ctx?: unknown): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Smallest render-column descriptor a cell view needs now. Overridable. */
|
|
54
|
+
interface CellColumnDescriptor {
|
|
55
|
+
key: string;
|
|
56
|
+
name: string;
|
|
57
|
+
cellType: CellType;
|
|
58
|
+
}
|
|
59
|
+
/** Props every native cell view receives. Minimal and overridable. */
|
|
60
|
+
interface CellProps {
|
|
61
|
+
cell: SheetsCell;
|
|
62
|
+
value: unknown;
|
|
63
|
+
colKey: string;
|
|
64
|
+
rowId: string;
|
|
65
|
+
rowIndex: number;
|
|
66
|
+
column: CellColumnDescriptor;
|
|
67
|
+
isEditing: boolean;
|
|
68
|
+
onStartEdit: () => void;
|
|
69
|
+
disabled: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Schema-only inputs used to DETECT a cell type. Never the runtime value. */
|
|
73
|
+
interface CellTypeMatchInput {
|
|
74
|
+
gqlType: string;
|
|
75
|
+
isArray: boolean;
|
|
76
|
+
pgAlias?: string | null;
|
|
77
|
+
pgType?: string | null;
|
|
78
|
+
subtype?: string | null;
|
|
79
|
+
fieldName?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Context handed to `toSheetsCell` so a definition can build the neutral cell.
|
|
82
|
+
* Geometry uses the built-in fallback, so no `createGeometry` callback is needed. */
|
|
83
|
+
interface SheetsCellRenderContext {
|
|
84
|
+
metadata: CellCreationMetadata;
|
|
85
|
+
}
|
|
86
|
+
interface CellTypeDefinition<TValue = unknown> {
|
|
87
|
+
/** Stable key. A def whose typeKey equals a built-in (e.g. 'relation') overrides it. */
|
|
88
|
+
typeKey: string;
|
|
89
|
+
category?: CellCategory;
|
|
90
|
+
/** Toolbar / type-picker icon. */
|
|
91
|
+
icon?: React.ComponentType<{
|
|
92
|
+
size?: number;
|
|
93
|
+
}>;
|
|
94
|
+
defaultWidth?: number;
|
|
95
|
+
supportsInlineEdit?: boolean;
|
|
96
|
+
/** DETECTION (schema-only). Highest-priority match wins; omit for typeKey-only. */
|
|
97
|
+
match?: (meta: CellTypeMatchInput) => boolean;
|
|
98
|
+
/** Native DISPLAY. Build the neutral SheetsCell. Omit to keep the built-in renderer. */
|
|
99
|
+
toSheetsCell?: (value: TValue, ctx: SheetsCellRenderContext) => SheetsCell;
|
|
100
|
+
/** Native cell COMPONENT override (the slot target). Omit to keep the built-in view. */
|
|
101
|
+
cell?: React.ComponentType<CellProps>;
|
|
102
|
+
/** Native EDITOR override (DOM portal overlay). Omit to keep the built-in native editor. */
|
|
103
|
+
editorComponent?: React.ComponentType<EditorProps>;
|
|
104
|
+
/** Value -> display/copy/export string. */
|
|
105
|
+
format?: (value: TValue) => string;
|
|
106
|
+
defaultValue?: () => TValue;
|
|
107
|
+
}
|
|
108
|
+
/** Identity helper that pins the generic — `defineCellType<number>({ ... })`. */
|
|
109
|
+
declare function defineCellType<T = unknown>(def: CellTypeDefinition<T>): CellTypeDefinition<T>;
|
|
110
|
+
/** A named bundle of cell types, registered via `SheetsConfig.plugins`. */
|
|
111
|
+
interface CellTypePlugin {
|
|
112
|
+
name: string;
|
|
113
|
+
cellTypes: CellTypeDefinition<any>[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The table being operated on, plus all tables (needed for relation-aware AST building). */
|
|
117
|
+
interface AdapterTableContext {
|
|
118
|
+
table: CleanTable;
|
|
119
|
+
allTables: CleanTable[];
|
|
120
|
+
tableName: string;
|
|
121
|
+
}
|
|
122
|
+
/** A normalized list query. `relationFieldMap` is resolved by the hook (it is cache-bound). */
|
|
123
|
+
interface AdapterListQuery {
|
|
124
|
+
where?: unknown;
|
|
125
|
+
orderBy?: Array<{
|
|
126
|
+
field: string;
|
|
127
|
+
direction: 'asc' | 'desc';
|
|
128
|
+
}>;
|
|
129
|
+
limit?: number;
|
|
130
|
+
offset?: number;
|
|
131
|
+
/** Relay cursor for forward pagination (infinite/cursor mode). */
|
|
132
|
+
after?: string;
|
|
133
|
+
fieldSelection?: FieldSelection;
|
|
134
|
+
/** Resolved relation field name map, threaded from the hook's cached resolution. */
|
|
135
|
+
relationFieldMap?: Record<string, string>;
|
|
136
|
+
}
|
|
137
|
+
interface AdapterPageInfo {
|
|
138
|
+
endCursor?: string | null;
|
|
139
|
+
startCursor?: string | null;
|
|
140
|
+
hasNextPage?: boolean;
|
|
141
|
+
hasPreviousPage?: boolean;
|
|
142
|
+
}
|
|
143
|
+
interface AdapterListResult<T = Record<string, unknown>> {
|
|
144
|
+
rows: T[];
|
|
145
|
+
totalCount: number;
|
|
146
|
+
pageInfo?: AdapterPageInfo;
|
|
147
|
+
}
|
|
148
|
+
interface SheetsBackendAdapter {
|
|
149
|
+
/** Introspect the schema. Default adapter runs the v5 `_meta` query. */
|
|
150
|
+
fetchMeta(execute: SheetsExecuteFn): Promise<MetaQuery>;
|
|
151
|
+
/** Read a page of rows, flattening relation connections into arrays. */
|
|
152
|
+
listRows<T = Record<string, unknown>>(ctx: AdapterTableContext, query: AdapterListQuery, execute: SheetsExecuteFn): Promise<AdapterListResult<T>>;
|
|
153
|
+
/** Create a row; resolves to the created row (or null). */
|
|
154
|
+
createRow<T = Record<string, unknown>>(ctx: AdapterTableContext, data: Record<string, unknown>, execute: SheetsExecuteFn, options?: MutationOptions): Promise<T | null>;
|
|
155
|
+
/** Update a row by id (or composite PK object); resolves to the updated row (or null). */
|
|
156
|
+
updateRow<T = Record<string, unknown>>(ctx: AdapterTableContext, id: string | number | Record<string, unknown>, patch: Record<string, unknown>, execute: SheetsExecuteFn, options?: MutationOptions): Promise<T | null>;
|
|
157
|
+
/** Delete a row by id (or composite PK object). */
|
|
158
|
+
deleteRow(ctx: AdapterTableContext, id: string | number | Record<string, unknown>, execute: SheetsExecuteFn, options?: MutationOptions): Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface SheetsAuthEmbedded {
|
|
162
|
+
mode: 'embedded';
|
|
163
|
+
getToken: () => string | null;
|
|
164
|
+
}
|
|
165
|
+
interface SheetsAuthStandalone {
|
|
166
|
+
mode: 'standalone';
|
|
167
|
+
}
|
|
168
|
+
interface SheetsConfig {
|
|
169
|
+
/** Data endpoint (app-public GraphQL) */
|
|
170
|
+
endpoint: string;
|
|
171
|
+
/** Auth endpoint (auth GraphQL) — required for standalone mode */
|
|
172
|
+
authEndpoint?: string;
|
|
173
|
+
/** Database ID for multi-tenant scoping */
|
|
174
|
+
databaseId?: string;
|
|
175
|
+
/** Auth mode */
|
|
176
|
+
auth: SheetsAuthEmbedded | SheetsAuthStandalone;
|
|
177
|
+
/** Field type overrides (replaces schema-builder smart tags) */
|
|
178
|
+
fieldTypeOverrides?: Record<string, string>;
|
|
179
|
+
/** Optional: BCP-47 locale for locale-aware date/number formatting (default 'en-US'). */
|
|
180
|
+
locale?: string;
|
|
181
|
+
/** Optional: inject custom execute function */
|
|
182
|
+
execute?: SheetsExecuteFn;
|
|
183
|
+
/** Optional: inject custom upload function */
|
|
184
|
+
executeUpload?: SheetsUploadFn;
|
|
185
|
+
/** Optional: inject existing QueryClient */
|
|
186
|
+
queryClient?: QueryClient;
|
|
187
|
+
/** Optional: inject a custom backend adapter. Defaults to the PostGraphile adapter. */
|
|
188
|
+
adapter?: SheetsBackendAdapter;
|
|
189
|
+
/** Optional: provider-level cell-type plugins (consumer override layer). */
|
|
190
|
+
plugins?: CellTypePlugin[];
|
|
191
|
+
/** Called on 401/UNAUTHENTICATED before the error is thrown. Host app handles token cleanup. */
|
|
192
|
+
onAuthError?: () => void;
|
|
193
|
+
/** Optional: inject a custom logger. Installed into the module logger singleton by the provider. */
|
|
194
|
+
logger?: SheetsLogger;
|
|
195
|
+
/** Optional: called when a grid/editor/mutation/upload error surfaces. Host app handles reporting. */
|
|
196
|
+
onError?: (error: unknown, ctx?: {
|
|
197
|
+
source?: 'grid' | 'editor' | 'mutation' | 'upload';
|
|
198
|
+
tableName?: string;
|
|
199
|
+
}) => void;
|
|
200
|
+
}
|
|
201
|
+
interface SheetsContextValue {
|
|
202
|
+
config: SheetsConfig;
|
|
203
|
+
execute: SheetsExecuteFn;
|
|
204
|
+
executeUpload: SheetsUploadFn;
|
|
205
|
+
scopeKey: SheetsScopeKey;
|
|
206
|
+
}
|
|
207
|
+
interface SheetsScopeKey {
|
|
208
|
+
databaseId: string | null;
|
|
209
|
+
endpoint: string;
|
|
210
|
+
}
|
|
211
|
+
declare const SheetsContext: React$1.Context<SheetsContextValue | null>;
|
|
212
|
+
declare function useSheetsContext(): SheetsContextValue;
|
|
213
|
+
|
|
214
|
+
export { type AdapterTableContext as A, type CellProps as C, type SheetsExecuteFn as S, type SheetsUploadFn as a, type SheetsConfig as b, type CellTypeDefinition as c, type CellTypeMatchInput as d, type SheetsCellRenderContext as e, type SheetsScopeKey as f, type SheetsBackendAdapter as g, SheetsContext as h, type SheetsContextValue as i, type SheetsAuthEmbedded as j, type SheetsAuthStandalone as k, createSheetsExecute as l, createSheetsUpload as m, type AdapterListQuery as n, type AdapterListResult as o, type AdapterPageInfo as p, defineCellType as q, type CellTypePlugin as r, type CellColumnDescriptor as s, type SheetsLogger as t, useSheetsContext as u };
|