@constructive-io/sheets 0.3.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.
- package/README.md +19 -24
- package/dist/advanced.cjs +659 -474
- package/dist/advanced.cjs.map +1 -1
- package/dist/advanced.d.cts +9 -10
- package/dist/advanced.d.ts +9 -10
- package/dist/advanced.js +3 -3
- package/dist/auth.cjs +10 -10
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -4
- package/dist/auth.d.ts +5 -4
- package/dist/auth.js +3 -3
- package/dist/{chunk-GLVZSPV2.js → chunk-4EZ6A23C.js} +4 -3
- package/dist/chunk-4EZ6A23C.js.map +1 -0
- package/dist/{chunk-FNVHSOQQ.js → chunk-KKAWMVEG.js} +11 -11
- package/dist/chunk-KKAWMVEG.js.map +1 -0
- package/dist/{chunk-4PGPVMZB.js → chunk-KOZAW264.js} +4 -3
- package/dist/chunk-KOZAW264.js.map +1 -0
- package/dist/{chunk-ODUBS2NL.js → chunk-KVPVEXWB.js} +40 -17
- package/dist/chunk-KVPVEXWB.js.map +1 -0
- package/dist/{chunk-TU7ATZ4X.js → chunk-LR64FLWO.js} +301 -410
- package/dist/chunk-LR64FLWO.js.map +1 -0
- package/dist/chunk-ZETPUEXH.js +494 -0
- package/dist/chunk-ZETPUEXH.js.map +1 -0
- package/dist/{date-editor-CXKKGNL6.js → date-editor-QT47WY5T.js} +5 -3
- package/dist/date-editor-QT47WY5T.js.map +1 -0
- package/dist/{editor-props-M6Dh0P9f.d.ts → grid-cell-types-C3ARj148.d.cts} +70 -62
- package/dist/{editor-props-M6Dh0P9f.d.cts → grid-cell-types-C3ARj148.d.ts} +70 -62
- package/dist/index.cjs +1150 -703
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -35
- package/dist/index.d.ts +123 -35
- package/dist/index.js +323 -99
- package/dist/index.js.map +1 -1
- package/dist/{sheets-context-CojEFlaY.d.cts → sheets-context-B03WDhZ9.d.cts} +36 -6
- package/dist/{sheets-context-Da55TTR9.d.ts → sheets-context-DmVCOgiX.d.ts} +36 -6
- package/dist/styles.css +6 -0
- package/dist/testing.cjs +476 -108
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +11 -7
- package/dist/testing.d.ts +11 -7
- package/dist/testing.js +34 -8
- package/dist/testing.js.map +1 -1
- package/package.json +15 -16
- package/dist/chunk-4PGPVMZB.js.map +0 -1
- package/dist/chunk-FNVHSOQQ.js.map +0 -1
- package/dist/chunk-GLVZSPV2.js.map +0 -1
- package/dist/chunk-H4JJTMP5.js +0 -160
- package/dist/chunk-H4JJTMP5.js.map +0 -1
- package/dist/chunk-ODUBS2NL.js.map +0 -1
- package/dist/chunk-TU7ATZ4X.js.map +0 -1
- package/dist/date-editor-CXKKGNL6.js.map +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
createSheetsExecute,
|
|
4
|
-
createSheetsUpload
|
|
5
|
-
|
|
4
|
+
createSheetsUpload,
|
|
5
|
+
sheetsQueryKeys
|
|
6
|
+
} from "./chunk-ZETPUEXH.js";
|
|
6
7
|
import {
|
|
7
8
|
useSheetsContext,
|
|
8
9
|
useSheetsStore,
|
|
9
10
|
useSheetsStoreApi
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KOZAW264.js";
|
|
11
12
|
import {
|
|
12
13
|
BOOLEAN_TYPES,
|
|
13
14
|
DATE_TIME_TYPES,
|
|
@@ -26,28 +27,73 @@ import {
|
|
|
26
27
|
sheetsLogger
|
|
27
28
|
} from "./chunk-X7DHTSOX.js";
|
|
28
29
|
|
|
29
|
-
// src/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// src/row-identity.ts
|
|
31
|
+
import {
|
|
32
|
+
assessTableWriteCapability,
|
|
33
|
+
resolveRowIdentity,
|
|
34
|
+
rowIdentityToPrimaryKey,
|
|
35
|
+
serializeRowIdentity
|
|
36
|
+
} from "@constructive-io/data";
|
|
37
|
+
function isLegacyScalarId(primaryKey) {
|
|
38
|
+
const entries = Object.entries(primaryKey);
|
|
39
|
+
return entries.length === 1 && entries[0][0] === "id" && (typeof entries[0][1] === "string" || typeof entries[0][1] === "number");
|
|
40
|
+
}
|
|
41
|
+
function resolveSheetsRowIdentity(table, row) {
|
|
42
|
+
const resolution = resolveRowIdentity(table, row);
|
|
43
|
+
if (resolution.status === "read-only") {
|
|
44
|
+
return { status: "unavailable", reason: "no-primary-key" };
|
|
45
|
+
}
|
|
46
|
+
if (resolution.status === "invalid-row") {
|
|
47
|
+
return { status: "unavailable", reason: "invalid-row" };
|
|
48
|
+
}
|
|
49
|
+
const primaryKey = rowIdentityToPrimaryKey(resolution.identity);
|
|
50
|
+
return {
|
|
51
|
+
status: "identified",
|
|
52
|
+
identifier: isLegacyScalarId(primaryKey) ? primaryKey.id : primaryKey,
|
|
53
|
+
primaryKey,
|
|
54
|
+
key: serializeRowIdentity(resolution.identity)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function resolveSheetsIdentifier(table, identifier) {
|
|
58
|
+
const row = typeof identifier === "object" && identifier !== null ? identifier : { id: identifier };
|
|
59
|
+
return resolveSheetsRowIdentity(table, row);
|
|
60
|
+
}
|
|
61
|
+
function sheetsIdentifierToWhere(table, identifier) {
|
|
62
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
63
|
+
if (resolution.status !== "identified") return null;
|
|
64
|
+
return Object.fromEntries(
|
|
65
|
+
Object.entries(resolution.primaryKey).map(([field, value]) => [field, { equalTo: value }])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function sheetsIdentifierCacheKey(table, identifier) {
|
|
69
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
70
|
+
if (resolution.status !== "identified") return null;
|
|
71
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
72
|
+
}
|
|
73
|
+
function sheetsRowKey(table, row, index) {
|
|
74
|
+
const resolution = resolveSheetsRowIdentity(table, row);
|
|
75
|
+
if (resolution.status === "identified") {
|
|
76
|
+
return typeof resolution.identifier === "object" ? resolution.key : String(resolution.identifier);
|
|
77
|
+
}
|
|
78
|
+
return `${table.schemaName ?? ""}:${table.name}:row:${index}`;
|
|
79
|
+
}
|
|
80
|
+
function getSheetsWriteCapability(table) {
|
|
81
|
+
return table ? assessTableWriteCapability(table) : null;
|
|
82
|
+
}
|
|
83
|
+
function canRunSheetsMutation(capability, operation) {
|
|
84
|
+
if (!capability || capability.status !== "mutable") return false;
|
|
85
|
+
return capability.operations[operation];
|
|
86
|
+
}
|
|
87
|
+
function assertSheetsMutationAllowed(table, operation) {
|
|
88
|
+
const capability = assessTableWriteCapability(table);
|
|
89
|
+
if (capability.status === "read-only") {
|
|
90
|
+
throw new Error(`Table '${table.name}' is read-only because it has no primary key.`);
|
|
91
|
+
}
|
|
92
|
+
if (!capability.operations[operation]) {
|
|
93
|
+
const article = operation === "update" ? "an" : "a";
|
|
94
|
+
throw new Error(`Table '${table.name}' does not expose ${article} ${operation} mutation.`);
|
|
95
|
+
}
|
|
34
96
|
}
|
|
35
|
-
var sheetsQueryKeys = {
|
|
36
|
-
root: ["sheets"],
|
|
37
|
-
scope: (scope) => ["sheets", scope],
|
|
38
|
-
meta: (scope) => [...sheetsQueryKeys.scope(scope), "meta"],
|
|
39
|
-
typeFields: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "type-fields", typeName],
|
|
40
|
-
enumValues: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "enum-values", typeName],
|
|
41
|
-
relations: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "relations", tableName],
|
|
42
|
-
table: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "table", tableName],
|
|
43
|
-
tableRows: (scope, tableName, options) => [...sheetsQueryKeys.table(scope, tableName), "rows", options],
|
|
44
|
-
tableRow: (scope, tableName, id) => [...sheetsQueryKeys.table(scope, tableName), "row", id],
|
|
45
|
-
tableCount: (scope, tableName, where) => [...sheetsQueryKeys.table(scope, tableName), "count", where],
|
|
46
|
-
infiniteTable: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "infinite-table", tableName],
|
|
47
|
-
infiniteTablePage: (scope, tableName, pageIndex, options) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "page", pageIndex, options],
|
|
48
|
-
infiniteTableTotalCount: (scope, tableName, where) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "totalCount", where],
|
|
49
|
-
cursorTable: (scope, tableName, options) => [...sheetsQueryKeys.scope(scope), "cursor-table", tableName, options]
|
|
50
|
-
};
|
|
51
97
|
|
|
52
98
|
// src/hooks/use-sheets-table.ts
|
|
53
99
|
import { useMemo } from "react";
|
|
@@ -58,321 +104,92 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
58
104
|
|
|
59
105
|
// src/adapter/postgraphile-adapter.ts
|
|
60
106
|
import {
|
|
107
|
+
META_CONTRACT_INTROSPECTION_DOCUMENT,
|
|
108
|
+
META_DOCUMENT,
|
|
109
|
+
SCHEMA_INTROSPECTION_QUERY,
|
|
110
|
+
analyzeSchemaIntrospectionCompatibility,
|
|
111
|
+
assertMetaContract,
|
|
112
|
+
assertMetaQuery,
|
|
61
113
|
buildPostGraphileCreate,
|
|
62
114
|
buildPostGraphileDelete,
|
|
63
115
|
buildPostGraphileUpdate,
|
|
64
116
|
buildSelect,
|
|
117
|
+
createError,
|
|
118
|
+
normalizeSchemaEnumInputValues,
|
|
65
119
|
prepareCreateInput,
|
|
66
120
|
prepareUpdateInput,
|
|
67
121
|
toCamelCasePlural,
|
|
68
122
|
toCamelCaseSingular,
|
|
69
123
|
toCreateMutationName,
|
|
70
124
|
toPatchFieldName,
|
|
71
|
-
toUpdateMutationName
|
|
72
|
-
TypedDocumentString
|
|
125
|
+
toUpdateMutationName
|
|
73
126
|
} from "@constructive-io/data";
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
name
|
|
119
|
-
type {
|
|
120
|
-
gqlType
|
|
121
|
-
isArray
|
|
122
|
-
pgType
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
constraints {
|
|
127
|
-
primaryKey {
|
|
128
|
-
name
|
|
129
|
-
fields {
|
|
130
|
-
name
|
|
131
|
-
type {
|
|
132
|
-
gqlType
|
|
133
|
-
isArray
|
|
134
|
-
pgType
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
unique {
|
|
139
|
-
name
|
|
140
|
-
fields {
|
|
141
|
-
name
|
|
142
|
-
type {
|
|
143
|
-
gqlType
|
|
144
|
-
isArray
|
|
145
|
-
pgType
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
foreignKey {
|
|
150
|
-
name
|
|
151
|
-
fields {
|
|
152
|
-
name
|
|
153
|
-
type {
|
|
154
|
-
gqlType
|
|
155
|
-
isArray
|
|
156
|
-
pgType
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
refFields {
|
|
160
|
-
name
|
|
161
|
-
type {
|
|
162
|
-
gqlType
|
|
163
|
-
isArray
|
|
164
|
-
pgType
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
refTable {
|
|
168
|
-
name
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
foreignKeyConstraints {
|
|
173
|
-
name
|
|
174
|
-
fields {
|
|
175
|
-
name
|
|
176
|
-
type {
|
|
177
|
-
gqlType
|
|
178
|
-
isArray
|
|
179
|
-
pgType
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
refFields {
|
|
183
|
-
name
|
|
184
|
-
type {
|
|
185
|
-
gqlType
|
|
186
|
-
isArray
|
|
187
|
-
pgType
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
refTable {
|
|
191
|
-
name
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
primaryKeyConstraints {
|
|
195
|
-
name
|
|
196
|
-
fields {
|
|
197
|
-
name
|
|
198
|
-
type {
|
|
199
|
-
gqlType
|
|
200
|
-
isArray
|
|
201
|
-
pgType
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
uniqueConstraints {
|
|
206
|
-
name
|
|
207
|
-
fields {
|
|
208
|
-
name
|
|
209
|
-
type {
|
|
210
|
-
gqlType
|
|
211
|
-
isArray
|
|
212
|
-
pgType
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
relations {
|
|
217
|
-
belongsTo {
|
|
218
|
-
fieldName
|
|
219
|
-
isUnique
|
|
220
|
-
keys {
|
|
221
|
-
name
|
|
222
|
-
type {
|
|
223
|
-
gqlType
|
|
224
|
-
isArray
|
|
225
|
-
pgType
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
references {
|
|
229
|
-
name
|
|
230
|
-
}
|
|
231
|
-
type
|
|
232
|
-
}
|
|
233
|
-
has {
|
|
234
|
-
fieldName
|
|
235
|
-
isUnique
|
|
236
|
-
keys {
|
|
237
|
-
name
|
|
238
|
-
type {
|
|
239
|
-
gqlType
|
|
240
|
-
isArray
|
|
241
|
-
pgType
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
referencedBy {
|
|
245
|
-
name
|
|
246
|
-
}
|
|
247
|
-
type
|
|
248
|
-
}
|
|
249
|
-
hasOne {
|
|
250
|
-
fieldName
|
|
251
|
-
isUnique
|
|
252
|
-
keys {
|
|
253
|
-
name
|
|
254
|
-
type {
|
|
255
|
-
gqlType
|
|
256
|
-
isArray
|
|
257
|
-
pgType
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
referencedBy {
|
|
261
|
-
name
|
|
262
|
-
}
|
|
263
|
-
type
|
|
264
|
-
}
|
|
265
|
-
hasMany {
|
|
266
|
-
fieldName
|
|
267
|
-
isUnique
|
|
268
|
-
keys {
|
|
269
|
-
name
|
|
270
|
-
type {
|
|
271
|
-
gqlType
|
|
272
|
-
isArray
|
|
273
|
-
pgType
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
referencedBy {
|
|
277
|
-
name
|
|
278
|
-
}
|
|
279
|
-
type
|
|
280
|
-
}
|
|
281
|
-
manyToMany {
|
|
282
|
-
fieldName
|
|
283
|
-
junctionLeftConstraint {
|
|
284
|
-
name
|
|
285
|
-
fields {
|
|
286
|
-
name
|
|
287
|
-
type {
|
|
288
|
-
gqlType
|
|
289
|
-
isArray
|
|
290
|
-
pgType
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
refFields {
|
|
294
|
-
name
|
|
295
|
-
type {
|
|
296
|
-
gqlType
|
|
297
|
-
isArray
|
|
298
|
-
pgType
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
refTable {
|
|
302
|
-
name
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
junctionLeftKeyAttributes {
|
|
306
|
-
name
|
|
307
|
-
type {
|
|
308
|
-
gqlType
|
|
309
|
-
isArray
|
|
310
|
-
pgType
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
junctionRightConstraint {
|
|
314
|
-
name
|
|
315
|
-
fields {
|
|
316
|
-
name
|
|
317
|
-
type {
|
|
318
|
-
gqlType
|
|
319
|
-
isArray
|
|
320
|
-
pgType
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
refFields {
|
|
324
|
-
name
|
|
325
|
-
type {
|
|
326
|
-
gqlType
|
|
327
|
-
isArray
|
|
328
|
-
pgType
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
refTable {
|
|
332
|
-
name
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
junctionRightKeyAttributes {
|
|
336
|
-
name
|
|
337
|
-
type {
|
|
338
|
-
gqlType
|
|
339
|
-
isArray
|
|
340
|
-
pgType
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
junctionTable {
|
|
344
|
-
name
|
|
345
|
-
}
|
|
346
|
-
leftKeyAttributes {
|
|
347
|
-
name
|
|
348
|
-
type {
|
|
349
|
-
gqlType
|
|
350
|
-
isArray
|
|
351
|
-
pgType
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
rightKeyAttributes {
|
|
355
|
-
name
|
|
356
|
-
type {
|
|
357
|
-
gqlType
|
|
358
|
-
isArray
|
|
359
|
-
pgType
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
rightTable {
|
|
363
|
-
name
|
|
364
|
-
}
|
|
365
|
-
type
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
`);
|
|
127
|
+
var compatibilityChecks = /* @__PURE__ */ new WeakMap();
|
|
128
|
+
var enumMappings = /* @__PURE__ */ new WeakMap();
|
|
129
|
+
async function ensureCurrentMetaContract(execute) {
|
|
130
|
+
const cached = compatibilityChecks.get(execute);
|
|
131
|
+
if (cached) return cached;
|
|
132
|
+
const check = execute(META_CONTRACT_INTROSPECTION_DOCUMENT).then(
|
|
133
|
+
(result) => {
|
|
134
|
+
assertMetaContract(result);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
compatibilityChecks.set(execute, check);
|
|
138
|
+
try {
|
|
139
|
+
await check;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (compatibilityChecks.get(execute) === check) compatibilityChecks.delete(execute);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function hasDeclaredEnums(meta) {
|
|
146
|
+
return Boolean(meta._meta?.tables?.some(
|
|
147
|
+
(table) => table?.fields?.some((field) => Boolean(field?.enumValues?.name))
|
|
148
|
+
));
|
|
149
|
+
}
|
|
150
|
+
function schemaCompatibilityError(missingPaths) {
|
|
151
|
+
const detail = missingPaths.length > 0 ? ` Missing: ${missingPaths.join(", ")}.` : "";
|
|
152
|
+
return createError.badRequest(
|
|
153
|
+
`The GraphQL schema does not match the enum values declared by Constructive _meta.${detail}`,
|
|
154
|
+
"SCHEMA_INTROSPECTION_INCOMPATIBLE"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function normalizeMutationEnums(ctx, input, execute) {
|
|
158
|
+
const hasEnumInput = ctx.table.fields.some(
|
|
159
|
+
(field) => Boolean(field.enumValues?.length) && Object.prototype.hasOwnProperty.call(input, field.name)
|
|
160
|
+
);
|
|
161
|
+
if (!hasEnumInput) return input;
|
|
162
|
+
const mappings = enumMappings.get(execute);
|
|
163
|
+
if (!mappings) {
|
|
164
|
+
throw createError.badRequest(
|
|
165
|
+
"Enum schema mappings are unavailable. Load table metadata before mutating enum fields.",
|
|
166
|
+
"ENUM_MAPPING_UNAVAILABLE"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return normalizeSchemaEnumInputValues(input, ctx.table, mappings);
|
|
170
|
+
}
|
|
372
171
|
function createPostGraphileAdapter() {
|
|
373
172
|
return {
|
|
374
173
|
async fetchMeta(execute) {
|
|
375
|
-
|
|
174
|
+
await ensureCurrentMetaContract(execute);
|
|
175
|
+
const meta = await execute(META_DOCUMENT);
|
|
176
|
+
assertMetaQuery(meta);
|
|
177
|
+
if (!hasDeclaredEnums(meta)) {
|
|
178
|
+
enumMappings.set(execute, []);
|
|
179
|
+
return meta;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const introspection = await execute(SCHEMA_INTROSPECTION_QUERY);
|
|
183
|
+
const analysis = analyzeSchemaIntrospectionCompatibility(introspection, meta);
|
|
184
|
+
if (analysis.status !== "compatible") {
|
|
185
|
+
throw schemaCompatibilityError(analysis.missingPaths);
|
|
186
|
+
}
|
|
187
|
+
enumMappings.set(execute, analysis.enumMappings);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
enumMappings.delete(execute);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
return meta;
|
|
376
193
|
},
|
|
377
194
|
async listRows(ctx, query, execute) {
|
|
378
195
|
const { table, allTables, tableName } = ctx;
|
|
@@ -396,7 +213,6 @@ function createPostGraphileAdapter() {
|
|
|
396
213
|
const directData = connection || [];
|
|
397
214
|
return {
|
|
398
215
|
rows: transformRelationData(directData, table),
|
|
399
|
-
// Non-Relay direct-array response: page length only, not a full filtered count.
|
|
400
216
|
totalCount: directData.length
|
|
401
217
|
};
|
|
402
218
|
},
|
|
@@ -407,7 +223,11 @@ function createPostGraphileAdapter() {
|
|
|
407
223
|
fieldSelection: options.fieldSelection || "display"
|
|
408
224
|
});
|
|
409
225
|
const singularName = toCamelCaseSingular(tableName, table);
|
|
410
|
-
const sanitizedData =
|
|
226
|
+
const sanitizedData = normalizeMutationEnums(
|
|
227
|
+
ctx,
|
|
228
|
+
prepareCreateInput(data),
|
|
229
|
+
execute
|
|
230
|
+
);
|
|
411
231
|
const variables = {
|
|
412
232
|
input: {
|
|
413
233
|
[singularName]: sanitizedData
|
|
@@ -426,13 +246,12 @@ function createPostGraphileAdapter() {
|
|
|
426
246
|
});
|
|
427
247
|
const patchFieldName = toPatchFieldName(tableName, table);
|
|
428
248
|
const sanitizedPatch = prepareUpdateInput(patch);
|
|
429
|
-
if (Object.keys(sanitizedPatch).length === 0)
|
|
430
|
-
|
|
431
|
-
}
|
|
249
|
+
if (Object.keys(sanitizedPatch).length === 0) return null;
|
|
250
|
+
const normalizedPatch = normalizeMutationEnums(ctx, sanitizedPatch, execute);
|
|
432
251
|
const variables = {
|
|
433
252
|
input: {
|
|
434
|
-
id,
|
|
435
|
-
[patchFieldName]:
|
|
253
|
+
...typeof id === "object" ? id : { id },
|
|
254
|
+
[patchFieldName]: normalizedPatch
|
|
436
255
|
}
|
|
437
256
|
};
|
|
438
257
|
const result = await execute(doc, variables);
|
|
@@ -480,7 +299,7 @@ function useSheetsMeta(options = {}) {
|
|
|
480
299
|
|
|
481
300
|
// src/hooks/use-sheets-table.ts
|
|
482
301
|
import { cleanTable } from "@constructive-io/data";
|
|
483
|
-
import { createError } from "@constructive-io/data";
|
|
302
|
+
import { createError as createError2 } from "@constructive-io/data";
|
|
484
303
|
import {
|
|
485
304
|
buildSelect as buildSelect2,
|
|
486
305
|
toCamelCasePlural as toCamelCasePlural2,
|
|
@@ -490,8 +309,8 @@ import {
|
|
|
490
309
|
|
|
491
310
|
// src/hooks/relation-field-resolution.ts
|
|
492
311
|
import { toCamelCase, toPascalCase, pluralize, singularize } from "inflekt";
|
|
493
|
-
import { TypedDocumentString
|
|
494
|
-
var TypeFieldsDoc = new
|
|
312
|
+
import { TypedDocumentString } from "@constructive-io/data";
|
|
313
|
+
var TypeFieldsDoc = new TypedDocumentString(`
|
|
495
314
|
query TypeFields($typeName: String!) {
|
|
496
315
|
__type(name: $typeName) {
|
|
497
316
|
fields {
|
|
@@ -659,8 +478,8 @@ async function getTypeFieldSet(table, scopeKey, queryClient, execute) {
|
|
|
659
478
|
}
|
|
660
479
|
|
|
661
480
|
// src/hooks/orderby-enum-resolution.ts
|
|
662
|
-
import { TypedDocumentString as
|
|
663
|
-
var EnumValuesDoc = new
|
|
481
|
+
import { TypedDocumentString as TypedDocumentString2 } from "@constructive-io/data";
|
|
482
|
+
var EnumValuesDoc = new TypedDocumentString2(`
|
|
664
483
|
query EnumValues($typeName: String!) {
|
|
665
484
|
__type(name: $typeName) {
|
|
666
485
|
enumValues {
|
|
@@ -695,13 +514,6 @@ async function validateOrderByVariables(variables, table, scopeKey, queryClient,
|
|
|
695
514
|
}
|
|
696
515
|
|
|
697
516
|
// src/hooks/use-sheets-table.ts
|
|
698
|
-
function extractRowId(row) {
|
|
699
|
-
if (!row || typeof row !== "object") {
|
|
700
|
-
return null;
|
|
701
|
-
}
|
|
702
|
-
const candidate = row.id;
|
|
703
|
-
return typeof candidate === "string" || typeof candidate === "number" ? candidate : null;
|
|
704
|
-
}
|
|
705
517
|
function transformRelationData(data, table) {
|
|
706
518
|
if (!data) return [];
|
|
707
519
|
if (!Array.isArray(data)) return data;
|
|
@@ -756,7 +568,7 @@ function transformToPostGraphileVariables(table, options = {}) {
|
|
|
756
568
|
variables.orderBy = options.orderBy.filter(({ field }) => availableFields.has(field)).map(({ field, direction }) => toOrderByEnumValue(field, direction));
|
|
757
569
|
}
|
|
758
570
|
if (options.where) {
|
|
759
|
-
variables.
|
|
571
|
+
variables.where = options.where;
|
|
760
572
|
}
|
|
761
573
|
return variables;
|
|
762
574
|
}
|
|
@@ -765,14 +577,33 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
765
577
|
const { execute, scopeKey } = useSheetsContext();
|
|
766
578
|
const { data: meta } = useSheetsMeta();
|
|
767
579
|
const adapter = useSheetsAdapter();
|
|
768
|
-
const
|
|
580
|
+
const metaTables = useMemo(() => {
|
|
769
581
|
if (!meta?._meta?.tables) return [];
|
|
770
|
-
return meta._meta.tables.filter((candidate) => candidate != null)
|
|
582
|
+
return meta._meta.tables.filter((candidate) => candidate != null);
|
|
771
583
|
}, [meta]);
|
|
584
|
+
const tables = useMemo(() => metaTables.map(cleanTable), [metaTables]);
|
|
772
585
|
const table = useMemo(
|
|
773
586
|
() => tables.find((candidate) => candidate.name === tableName) ?? null,
|
|
774
587
|
[tables, tableName]
|
|
775
588
|
);
|
|
589
|
+
const tableMeta = useMemo(
|
|
590
|
+
() => metaTables.find((candidate) => candidate.name === tableName) ?? null,
|
|
591
|
+
[metaTables, tableName]
|
|
592
|
+
);
|
|
593
|
+
const resolveIdentifier = (identifier) => {
|
|
594
|
+
if (!tableMeta) throw createError2.notFound(`Table '${tableName}' not found`);
|
|
595
|
+
const resolution = resolveSheetsIdentifier(tableMeta, identifier);
|
|
596
|
+
if (resolution.status !== "identified") {
|
|
597
|
+
throw createError2.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
598
|
+
}
|
|
599
|
+
return resolution.identifier;
|
|
600
|
+
};
|
|
601
|
+
const rowCacheKey = (row) => {
|
|
602
|
+
if (!tableMeta || !row) return null;
|
|
603
|
+
const resolution = resolveSheetsRowIdentity(tableMeta, row);
|
|
604
|
+
if (resolution.status !== "identified") return null;
|
|
605
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
606
|
+
};
|
|
776
607
|
const { enabled = true, select: fieldSelection, mutationOptions = {}, ...queryOptions } = options;
|
|
777
608
|
const finalQueryOptions = {
|
|
778
609
|
...queryOptions,
|
|
@@ -787,7 +618,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
787
618
|
queryKey: sheetsTableQueryKeys.tableRows(scopeKey, tableName, finalQueryOptions),
|
|
788
619
|
queryFn: async () => {
|
|
789
620
|
if (!table) {
|
|
790
|
-
throw
|
|
621
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
791
622
|
}
|
|
792
623
|
const variables = transformToPostGraphileVariables(table, finalQueryOptions);
|
|
793
624
|
const [relationFieldMap] = await Promise.all([
|
|
@@ -829,9 +660,10 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
829
660
|
const createMutation = useMutation({
|
|
830
661
|
mutationKey: sheetsTableMutationKeys.create(scopeKey, tableName),
|
|
831
662
|
mutationFn: async (data2) => {
|
|
832
|
-
if (!table) {
|
|
833
|
-
throw
|
|
663
|
+
if (!table || !tableMeta) {
|
|
664
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
834
665
|
}
|
|
666
|
+
assertSheetsMutationAllowed(tableMeta, "create");
|
|
835
667
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
836
668
|
const createdRow = await adapter.createRow({ table, allTables, tableName }, data2, execute, {
|
|
837
669
|
...mutationOptions,
|
|
@@ -842,20 +674,22 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
842
674
|
onSuccess: ({ createdRow }) => {
|
|
843
675
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
844
676
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
677
|
+
const createdRowKey = rowCacheKey(createdRow);
|
|
678
|
+
if (createdRowKey !== null) {
|
|
679
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, createdRowKey), createdRow);
|
|
848
680
|
}
|
|
849
681
|
}
|
|
850
682
|
});
|
|
851
683
|
const updateMutation = useMutation({
|
|
852
684
|
mutationKey: sheetsTableMutationKeys.update(scopeKey, tableName),
|
|
853
685
|
mutationFn: async ({ id, patch }) => {
|
|
854
|
-
if (!table) {
|
|
855
|
-
throw
|
|
686
|
+
if (!table || !tableMeta) {
|
|
687
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
856
688
|
}
|
|
689
|
+
assertSheetsMutationAllowed(tableMeta, "update");
|
|
690
|
+
const mutationIdentifier = resolveIdentifier(id);
|
|
857
691
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
858
|
-
const updatedRow = await adapter.updateRow({ table, allTables, tableName },
|
|
692
|
+
const updatedRow = await adapter.updateRow({ table, allTables, tableName }, mutationIdentifier, patch, execute, {
|
|
859
693
|
...mutationOptions,
|
|
860
694
|
fieldSelection: mutationOptions.fieldSelection || fieldSelection || "display"
|
|
861
695
|
});
|
|
@@ -870,6 +704,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
870
704
|
onMutate: async ({ id, patch }) => {
|
|
871
705
|
const tablePrefix = sheetsTableQueryKeys.table(scopeKey, tableName);
|
|
872
706
|
await queryClient.cancelQueries({ queryKey: tablePrefix });
|
|
707
|
+
const targetKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, id) : null;
|
|
873
708
|
const isRowsKey = (key) => key[key.length - 2] === "rows";
|
|
874
709
|
const previousRows = queryClient.getQueriesData({ queryKey: tablePrefix }).filter(([key]) => isRowsKey(key));
|
|
875
710
|
for (const [key] of previousRows) {
|
|
@@ -877,7 +712,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
877
712
|
if (!old) return old;
|
|
878
713
|
let changed = false;
|
|
879
714
|
const rows = old.rows.map((row) => {
|
|
880
|
-
if (
|
|
715
|
+
if (targetKey !== null && rowCacheKey(row) === targetKey) {
|
|
881
716
|
changed = true;
|
|
882
717
|
return { ...row, ...patch };
|
|
883
718
|
}
|
|
@@ -893,42 +728,49 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
893
728
|
},
|
|
894
729
|
onSuccess: ({ updatedRow }) => {
|
|
895
730
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
731
|
+
const updatedRowKey = rowCacheKey(updatedRow);
|
|
732
|
+
if (updatedRowKey !== null) {
|
|
733
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, updatedRowKey), updatedRow);
|
|
899
734
|
}
|
|
900
735
|
}
|
|
901
736
|
});
|
|
902
737
|
const deleteMutation = useMutation({
|
|
903
738
|
mutationKey: sheetsTableMutationKeys.delete(scopeKey, tableName),
|
|
904
739
|
mutationFn: async (idOrPk) => {
|
|
905
|
-
if (!table) {
|
|
906
|
-
throw
|
|
740
|
+
if (!table || !tableMeta) {
|
|
741
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
907
742
|
}
|
|
743
|
+
assertSheetsMutationAllowed(tableMeta, "delete");
|
|
744
|
+
const mutationIdentifier = resolveIdentifier(idOrPk);
|
|
908
745
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
909
|
-
await adapter.deleteRow({ table, allTables, tableName },
|
|
746
|
+
await adapter.deleteRow({ table, allTables, tableName }, mutationIdentifier, execute, mutationOptions);
|
|
910
747
|
return { deletedId: idOrPk, __rawResult: {} };
|
|
911
748
|
},
|
|
912
749
|
onSuccess: ({ deletedId }) => {
|
|
913
750
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
914
751
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
915
|
-
|
|
752
|
+
const deletedRowKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, deletedId) : null;
|
|
753
|
+
if (deletedRowKey !== null) {
|
|
916
754
|
queryClient.removeQueries({
|
|
917
|
-
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
755
|
+
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName, deletedRowKey)
|
|
918
756
|
});
|
|
919
757
|
}
|
|
920
758
|
}
|
|
921
759
|
});
|
|
922
760
|
const findOne = async (id) => {
|
|
923
|
-
if (!table) {
|
|
924
|
-
throw
|
|
761
|
+
if (!table || !tableMeta) {
|
|
762
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
763
|
+
}
|
|
764
|
+
const where = sheetsIdentifierToWhere(tableMeta, id);
|
|
765
|
+
if (!where) {
|
|
766
|
+
throw createError2.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
925
767
|
}
|
|
926
768
|
const doc = buildSelect2(table, tables, {
|
|
927
|
-
where
|
|
769
|
+
where,
|
|
928
770
|
limit: 1
|
|
929
771
|
});
|
|
930
772
|
const variables = transformToPostGraphileVariables(table, {
|
|
931
|
-
where
|
|
773
|
+
where,
|
|
932
774
|
limit: 1
|
|
933
775
|
});
|
|
934
776
|
const result = await execute(doc, variables);
|
|
@@ -1702,7 +1544,7 @@ import { useInfiniteQuery, useQueryClient as useQueryClient3 } from "@tanstack/r
|
|
|
1702
1544
|
import {
|
|
1703
1545
|
cleanTable as cleanTable3
|
|
1704
1546
|
} from "@constructive-io/data";
|
|
1705
|
-
import { createError as
|
|
1547
|
+
import { createError as createError3 } from "@constructive-io/data";
|
|
1706
1548
|
import { toOrderByEnumValue as toOrderByEnumValue2 } from "@constructive-io/data";
|
|
1707
1549
|
function useSheetsTableCursor(tableName, options = {}) {
|
|
1708
1550
|
const queryClient = useQueryClient3();
|
|
@@ -1743,7 +1585,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
1743
1585
|
queryKey: sheetsQueryKeys.cursorTable(scopeKey, tableName, stableOptions),
|
|
1744
1586
|
queryFn: async ({ pageParam }) => {
|
|
1745
1587
|
if (!table) {
|
|
1746
|
-
throw
|
|
1588
|
+
throw createError3.notFound(`Table '${tableName}' not found`);
|
|
1747
1589
|
}
|
|
1748
1590
|
const cursor = pageParam;
|
|
1749
1591
|
const variableOptions = {
|
|
@@ -1996,7 +1838,7 @@ function ArrayEditorDom({ value, onCommit, onCancel }) {
|
|
|
1996
1838
|
// src/grid-dom/editors/date-editor.tsx
|
|
1997
1839
|
import { lazy, Suspense } from "react";
|
|
1998
1840
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1999
|
-
var DateEditor = lazy(() => import("./date-editor-
|
|
1841
|
+
var DateEditor = lazy(() => import("./date-editor-QT47WY5T.js").then((m) => ({ default: m.DateEditor })));
|
|
2000
1842
|
function DateEditorDom({ value, cell, onCommit, onCancel }) {
|
|
2001
1843
|
const cellType = cell.meta?.cellType;
|
|
2002
1844
|
const dateType = cellType && DATE_TIME_TYPES.has(cellType) ? cellType : void 0;
|
|
@@ -2388,7 +2230,7 @@ import { Suspense as Suspense4 } from "react";
|
|
|
2388
2230
|
|
|
2389
2231
|
// src/grid/editors/image-editor.tsx
|
|
2390
2232
|
import { useCallback as useCallback3, useContext as useContext2, useEffect as useEffect4, useMemo as useMemo8, useRef as useRef5, useState as useState5 } from "react";
|
|
2391
|
-
import { AlertCircleIcon, ImageIcon, ImageOff, Loader2 as Loader22, UploadIcon, XIcon as XIcon2 } from "lucide-react";
|
|
2233
|
+
import { AlertCircleIcon, FileIcon, ImageIcon, ImageOff, Loader2 as Loader22, UploadIcon, XIcon as XIcon2 } from "lucide-react";
|
|
2392
2234
|
import { AnimatePresence, motion } from "motion/react";
|
|
2393
2235
|
import { toast } from "@constructive-io/ui/toast";
|
|
2394
2236
|
|
|
@@ -2520,6 +2362,20 @@ function RemoveButton({ onClick, label }) {
|
|
|
2520
2362
|
}
|
|
2521
2363
|
) });
|
|
2522
2364
|
}
|
|
2365
|
+
function FilePreview({ name, size, mime }) {
|
|
2366
|
+
const hasMime = !!mime && mime !== "unknown";
|
|
2367
|
+
return /* @__PURE__ */ jsxs3("div", { className: "flex size-full flex-col items-center justify-center gap-2 p-4 text-center", children: [
|
|
2368
|
+
/* @__PURE__ */ jsx8("div", { className: "bg-muted/60 flex size-12 shrink-0 items-center justify-center rounded-lg", "aria-hidden": "true", children: /* @__PURE__ */ jsx8(FileIcon, { className: "text-muted-foreground size-6" }) }),
|
|
2369
|
+
/* @__PURE__ */ jsxs3("div", { className: "min-w-0 max-w-full", children: [
|
|
2370
|
+
/* @__PURE__ */ jsx8("p", { className: "truncate text-sm font-medium", title: name, children: name || "File" }),
|
|
2371
|
+
(size || hasMime) && /* @__PURE__ */ jsxs3("p", { className: "text-muted-foreground mt-0.5 text-xs", children: [
|
|
2372
|
+
size ? formatFileSize(size) : null,
|
|
2373
|
+
size && hasMime ? " \u2022 " : null,
|
|
2374
|
+
hasMime ? /* @__PURE__ */ jsx8("span", { className: "uppercase", children: mime }) : null
|
|
2375
|
+
] })
|
|
2376
|
+
] })
|
|
2377
|
+
] });
|
|
2378
|
+
}
|
|
2523
2379
|
var ImageEditor = ({
|
|
2524
2380
|
value,
|
|
2525
2381
|
onFinishedEditing,
|
|
@@ -2529,8 +2385,11 @@ var ImageEditor = ({
|
|
|
2529
2385
|
onSaveComplete,
|
|
2530
2386
|
isDraftRow = false,
|
|
2531
2387
|
onSubmitDraft,
|
|
2532
|
-
onDraftUploadComplete
|
|
2388
|
+
onDraftUploadComplete,
|
|
2389
|
+
acceptAnyFile = false
|
|
2533
2390
|
}) => {
|
|
2391
|
+
const noun = acceptAnyFile ? "file" : "image";
|
|
2392
|
+
const Noun = acceptAnyFile ? "File" : "Image";
|
|
2534
2393
|
const [uploadState, setUploadState] = useState5("idle");
|
|
2535
2394
|
const { config } = useSheetsContext();
|
|
2536
2395
|
const storeApi = useSheetsStoreApi();
|
|
@@ -2553,10 +2412,12 @@ var ImageEditor = ({
|
|
|
2553
2412
|
const isUploading = uploadState === "uploading";
|
|
2554
2413
|
const isBusy = uploadState !== "idle";
|
|
2555
2414
|
const imageUrl = useMemo8(() => getImageUrl(imageValue), [imageValue]);
|
|
2556
|
-
const imageStatus = useImageStatus(imageUrl || void 0);
|
|
2557
|
-
const imageLoadFailed = imageUrl != null && imageStatus === "error";
|
|
2558
|
-
const hasImage = imageUrl != null && !imageLoadFailed;
|
|
2559
2415
|
const imageMetadata = useMemo8(() => getImageMetadata(imageValue), [imageValue]);
|
|
2416
|
+
const storedMime = imageMetadata?.mime;
|
|
2417
|
+
const storedIsImage = !acceptAnyFile || !!storedMime && storedMime.startsWith("image/");
|
|
2418
|
+
const imageStatus = useImageStatus(storedIsImage ? imageUrl || void 0 : void 0);
|
|
2419
|
+
const imageLoadFailed = storedIsImage && imageUrl != null && imageStatus === "error";
|
|
2420
|
+
const hasImage = imageUrl != null && !imageLoadFailed && storedIsImage;
|
|
2560
2421
|
const revokePreviewUrl = useCallback3(() => {
|
|
2561
2422
|
if (previewUrlRef.current) {
|
|
2562
2423
|
URL.revokeObjectURL(previewUrlRef.current);
|
|
@@ -2576,8 +2437,8 @@ var ImageEditor = ({
|
|
|
2576
2437
|
setImageValue(normalized);
|
|
2577
2438
|
onSaveComplete?.({ imageData: normalized });
|
|
2578
2439
|
onFinishedEditing();
|
|
2579
|
-
toast.success({ message:
|
|
2580
|
-
}, [resetFileState, onSaveComplete, onFinishedEditing]);
|
|
2440
|
+
toast.success({ message: `${Noun} uploaded successfully` });
|
|
2441
|
+
}, [resetFileState, onSaveComplete, onFinishedEditing, Noun]);
|
|
2581
2442
|
const handleUploadError = useCallback3((error) => {
|
|
2582
2443
|
setUploadState("idle");
|
|
2583
2444
|
sheetsLogger().error("[image-editor] upload failed:", error);
|
|
@@ -2597,20 +2458,22 @@ var ImageEditor = ({
|
|
|
2597
2458
|
const handleFileSelection = useCallback3((acceptedFiles) => {
|
|
2598
2459
|
if (acceptedFiles.length === 0) return;
|
|
2599
2460
|
const file = acceptedFiles[0];
|
|
2600
|
-
if (!
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2461
|
+
if (!acceptAnyFile) {
|
|
2462
|
+
if (!file.type.startsWith("image/")) {
|
|
2463
|
+
toast.error({ message: "Please select an image file" });
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2466
|
+
if (file.size > 10 * 1024 * 1024) {
|
|
2467
|
+
toast.error({ message: "File size must be less than 10MB" });
|
|
2468
|
+
return;
|
|
2469
|
+
}
|
|
2607
2470
|
}
|
|
2608
2471
|
revokePreviewUrl();
|
|
2609
2472
|
setSelectedFile(file);
|
|
2610
2473
|
const url = URL.createObjectURL(file);
|
|
2611
2474
|
previewUrlRef.current = url;
|
|
2612
2475
|
setPreviewUrl(url);
|
|
2613
|
-
}, [revokePreviewUrl]);
|
|
2476
|
+
}, [revokePreviewUrl, acceptAnyFile]);
|
|
2614
2477
|
const handleDragEnter = useCallback3((e) => {
|
|
2615
2478
|
e.preventDefault();
|
|
2616
2479
|
e.stopPropagation();
|
|
@@ -2645,7 +2508,7 @@ var ImageEditor = ({
|
|
|
2645
2508
|
const committedId = committedRecordIdRef.current ?? recordId;
|
|
2646
2509
|
if (committedRecordIdRef.current != null) {
|
|
2647
2510
|
try {
|
|
2648
|
-
toast.info({ message:
|
|
2511
|
+
toast.info({ message: `Uploading ${noun}...` });
|
|
2649
2512
|
setUploadState("uploading");
|
|
2650
2513
|
const uploadResult = await executeFieldUpload(
|
|
2651
2514
|
tableName,
|
|
@@ -2661,7 +2524,7 @@ var ImageEditor = ({
|
|
|
2661
2524
|
resetFileState();
|
|
2662
2525
|
setImageValue(normalized);
|
|
2663
2526
|
onDraftUploadComplete?.();
|
|
2664
|
-
toast.success({ message:
|
|
2527
|
+
toast.success({ message: `${Noun} uploaded successfully` });
|
|
2665
2528
|
onFinishedEditing();
|
|
2666
2529
|
} catch (error) {
|
|
2667
2530
|
onDraftUploadComplete?.();
|
|
@@ -2679,14 +2542,17 @@ var ImageEditor = ({
|
|
|
2679
2542
|
toast.info({ message: "Creating row..." });
|
|
2680
2543
|
setUploadState("submitting-draft");
|
|
2681
2544
|
const result = await onSubmitDraft();
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2545
|
+
const createdId = result.createdRow?.id;
|
|
2546
|
+
if (typeof createdId !== "string" && typeof createdId !== "number") {
|
|
2547
|
+
throw new Error("Image uploads require a scalar id primary key.");
|
|
2548
|
+
}
|
|
2549
|
+
committedRecordIdRef.current = createdId;
|
|
2550
|
+
toast.info({ message: `Uploading ${noun}...` });
|
|
2685
2551
|
setUploadState("uploading");
|
|
2686
2552
|
const uploadResult = await executeFieldUpload(
|
|
2687
2553
|
tableName,
|
|
2688
2554
|
fieldName,
|
|
2689
|
-
|
|
2555
|
+
createdId,
|
|
2690
2556
|
selectedFile,
|
|
2691
2557
|
config.endpoint,
|
|
2692
2558
|
getToken,
|
|
@@ -2697,7 +2563,7 @@ var ImageEditor = ({
|
|
|
2697
2563
|
resetFileState();
|
|
2698
2564
|
setImageValue(normalized);
|
|
2699
2565
|
onDraftUploadComplete?.();
|
|
2700
|
-
toast.success({ message:
|
|
2566
|
+
toast.success({ message: `Row created and ${noun} uploaded` });
|
|
2701
2567
|
onFinishedEditing();
|
|
2702
2568
|
} catch (error) {
|
|
2703
2569
|
onDraftUploadComplete?.();
|
|
@@ -2712,7 +2578,7 @@ var ImageEditor = ({
|
|
|
2712
2578
|
}
|
|
2713
2579
|
setUploadState("uploading");
|
|
2714
2580
|
uploadMutation.mutate(selectedFile);
|
|
2715
|
-
}, [selectedFile, uploadMutation, tableName, fieldName, recordId, isDraftRow, onSubmitDraft, config.endpoint, config.onAuthError, getToken, resetFileState, onDraftUploadComplete, onFinishedEditing]);
|
|
2581
|
+
}, [selectedFile, uploadMutation, tableName, fieldName, recordId, isDraftRow, onSubmitDraft, config.endpoint, config.onAuthError, getToken, resetFileState, onDraftUploadComplete, onFinishedEditing, noun, Noun]);
|
|
2716
2582
|
const handleSave = useCallback3(() => {
|
|
2717
2583
|
if (!imageValue) {
|
|
2718
2584
|
onFinishedEditing(null);
|
|
@@ -2737,12 +2603,13 @@ var ImageEditor = ({
|
|
|
2737
2603
|
handleSave();
|
|
2738
2604
|
}
|
|
2739
2605
|
}, [handleSave]);
|
|
2740
|
-
const
|
|
2606
|
+
const hasStoredFile = acceptAnyFile && !!imageUrl && !storedIsImage;
|
|
2607
|
+
const dropzoneKey = isBusy ? "busy" : previewUrl ? "preview" : hasImage ? "loaded" : hasStoredFile ? "file" : imageLoadFailed ? "broken" : "empty";
|
|
2741
2608
|
const renderDropzoneContent = () => {
|
|
2742
2609
|
if (isBusy) {
|
|
2743
2610
|
return /* @__PURE__ */ jsxs3("div", { "data-state": uploadState, className: "text-muted-foreground flex w-full flex-col items-center justify-center p-6", children: [
|
|
2744
2611
|
/* @__PURE__ */ jsx8(Loader22, { className: "mb-2 size-6 animate-spin" }),
|
|
2745
|
-
/* @__PURE__ */ jsx8("p", { className: "text-sm", children: isSubmittingDraft ? "Creating row..." :
|
|
2612
|
+
/* @__PURE__ */ jsx8("p", { className: "text-sm", children: isSubmittingDraft ? "Creating row..." : `Uploading ${noun}...` }),
|
|
2746
2613
|
isUploading && uploadProgress && /* @__PURE__ */ jsxs3("div", { className: "mt-3 w-full max-w-xs", children: [
|
|
2747
2614
|
/* @__PURE__ */ jsx8("div", { className: "bg-muted h-1.5 overflow-hidden rounded-full", children: /* @__PURE__ */ jsx8(
|
|
2748
2615
|
"div",
|
|
@@ -2759,8 +2626,9 @@ var ImageEditor = ({
|
|
|
2759
2626
|
] });
|
|
2760
2627
|
}
|
|
2761
2628
|
if (previewUrl) {
|
|
2629
|
+
const selectedIsImage = !acceptAnyFile || (selectedFile?.type.startsWith("image/") ?? false);
|
|
2762
2630
|
return /* @__PURE__ */ jsxs3("div", { className: "relative w-full", style: { height: "13rem" }, children: [
|
|
2763
|
-
/* @__PURE__ */ jsx8("img", { src: previewUrl, alt: selectedFile?.name || "
|
|
2631
|
+
selectedIsImage ? /* @__PURE__ */ jsx8("img", { src: previewUrl, alt: selectedFile?.name || "Selected file", className: "size-full object-contain p-2" }) : /* @__PURE__ */ jsx8(FilePreview, { name: selectedFile?.name, size: selectedFile?.size, mime: selectedFile?.type }),
|
|
2764
2632
|
/* @__PURE__ */ jsx8(RemoveButton, { onClick: removeFile, label: "Remove selected file" })
|
|
2765
2633
|
] });
|
|
2766
2634
|
}
|
|
@@ -2779,6 +2647,12 @@ var ImageEditor = ({
|
|
|
2779
2647
|
/* @__PURE__ */ jsx8(RemoveButton, { onClick: handleRemoveImage, label: "Remove image" })
|
|
2780
2648
|
] });
|
|
2781
2649
|
}
|
|
2650
|
+
if (hasStoredFile) {
|
|
2651
|
+
return /* @__PURE__ */ jsxs3("div", { className: "relative w-full", style: { height: "13rem" }, children: [
|
|
2652
|
+
/* @__PURE__ */ jsx8(FilePreview, { name: imageMetadata?.filename, size: imageMetadata?.size, mime: imageMetadata?.mime }),
|
|
2653
|
+
/* @__PURE__ */ jsx8(RemoveButton, { onClick: handleRemoveImage, label: "Remove file" })
|
|
2654
|
+
] });
|
|
2655
|
+
}
|
|
2782
2656
|
if (imageLoadFailed) {
|
|
2783
2657
|
return /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col items-center justify-center px-4 py-6 text-center", children: [
|
|
2784
2658
|
/* @__PURE__ */ jsx8(
|
|
@@ -2832,8 +2706,12 @@ var ImageEditor = ({
|
|
|
2832
2706
|
}
|
|
2833
2707
|
return /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col items-center justify-center px-4 py-6 text-center", children: [
|
|
2834
2708
|
/* @__PURE__ */ jsx8("div", { className: "bg-muted/60 mb-3 flex size-10 shrink-0 items-center justify-center rounded-full", "aria-hidden": "true", children: /* @__PURE__ */ jsx8(UploadIcon, { className: "text-muted-foreground size-4" }) }),
|
|
2835
|
-
/* @__PURE__ */
|
|
2836
|
-
|
|
2709
|
+
/* @__PURE__ */ jsxs3("p", { className: "text-sm font-medium", children: [
|
|
2710
|
+
"Drop ",
|
|
2711
|
+
noun,
|
|
2712
|
+
" here or browse"
|
|
2713
|
+
] }),
|
|
2714
|
+
/* @__PURE__ */ jsx8("p", { className: "text-muted-foreground mt-1 text-xs", children: acceptAnyFile ? "Any file type" : "SVG, PNG, JPG or GIF (max. 10MB)" }),
|
|
2837
2715
|
/* @__PURE__ */ jsxs3(
|
|
2838
2716
|
Button3,
|
|
2839
2717
|
{
|
|
@@ -2847,7 +2725,8 @@ var ImageEditor = ({
|
|
|
2847
2725
|
disabled: isBusy,
|
|
2848
2726
|
children: [
|
|
2849
2727
|
/* @__PURE__ */ jsx8(UploadIcon, { className: "-ms-0.5 opacity-60", "aria-hidden": "true" }),
|
|
2850
|
-
"Select
|
|
2728
|
+
"Select ",
|
|
2729
|
+
noun
|
|
2851
2730
|
]
|
|
2852
2731
|
}
|
|
2853
2732
|
)
|
|
@@ -2862,17 +2741,17 @@ var ImageEditor = ({
|
|
|
2862
2741
|
style: overlayMaxHeight > 0 ? { maxHeight: overlayMaxHeight } : void 0,
|
|
2863
2742
|
children: /* @__PURE__ */ jsxs3("div", { onKeyDown: handleEditorKeyDown, className: "flex min-h-0 flex-1 flex-col", children: [
|
|
2864
2743
|
/* @__PURE__ */ jsxs3("div", { className: "flex shrink-0 items-center gap-2 border-b px-6 py-3", children: [
|
|
2865
|
-
/* @__PURE__ */ jsx8(ImageIcon, { className: "text-muted-foreground size-4" }),
|
|
2866
|
-
/* @__PURE__ */ jsx8("h3", { className: "text-sm font-medium", children: imageUrl ?
|
|
2744
|
+
acceptAnyFile ? /* @__PURE__ */ jsx8(FileIcon, { className: "text-muted-foreground size-4" }) : /* @__PURE__ */ jsx8(ImageIcon, { className: "text-muted-foreground size-4" }),
|
|
2745
|
+
/* @__PURE__ */ jsx8("h3", { className: "text-sm font-medium", children: imageUrl ? `Edit ${Noun}` : `Add ${Noun}` })
|
|
2867
2746
|
] }),
|
|
2868
2747
|
/* @__PURE__ */ jsx8(
|
|
2869
2748
|
"input",
|
|
2870
2749
|
{
|
|
2871
2750
|
ref: fileInputRef,
|
|
2872
2751
|
type: "file",
|
|
2873
|
-
accept: "image/*",
|
|
2752
|
+
accept: acceptAnyFile ? void 0 : "image/*",
|
|
2874
2753
|
className: "hidden",
|
|
2875
|
-
"aria-label":
|
|
2754
|
+
"aria-label": `Upload ${noun}`,
|
|
2876
2755
|
tabIndex: -1,
|
|
2877
2756
|
onChange: (e) => {
|
|
2878
2757
|
const files = Array.from(e.target.files || []);
|
|
@@ -2946,6 +2825,7 @@ import { jsx as jsx9 } from "react/jsx-runtime";
|
|
|
2946
2825
|
var DRAFT_PREFIX = "draft:";
|
|
2947
2826
|
function ImageEditorDom({
|
|
2948
2827
|
value,
|
|
2828
|
+
cell,
|
|
2949
2829
|
colKey,
|
|
2950
2830
|
rowId,
|
|
2951
2831
|
tableName,
|
|
@@ -2955,6 +2835,8 @@ function ImageEditorDom({
|
|
|
2955
2835
|
onInvalidateData
|
|
2956
2836
|
}) {
|
|
2957
2837
|
const isDraftRow = rowId.startsWith(DRAFT_PREFIX);
|
|
2838
|
+
const cellType = cell.meta?.cellType;
|
|
2839
|
+
const acceptAnyFile = cellType != null && cellType !== "image";
|
|
2958
2840
|
const handleSaveComplete = onCommitPatch ? (saveData) => onCommitPatch({ [colKey]: saveData.imageData }) : void 0;
|
|
2959
2841
|
const handleSubmitDraft = isDraftRow && onSubmitDraftRow ? async () => {
|
|
2960
2842
|
const createdRow = await onSubmitDraftRow(rowId);
|
|
@@ -2964,6 +2846,7 @@ function ImageEditorDom({
|
|
|
2964
2846
|
ImageEditor,
|
|
2965
2847
|
{
|
|
2966
2848
|
value,
|
|
2849
|
+
acceptAnyFile,
|
|
2967
2850
|
onFinishedEditing: () => onCancel(),
|
|
2968
2851
|
tableName,
|
|
2969
2852
|
fieldName: colKey,
|
|
@@ -3490,7 +3373,7 @@ function parseValue(text) {
|
|
|
3490
3373
|
if (trimmed === "") return null;
|
|
3491
3374
|
return Number(trimmed);
|
|
3492
3375
|
}
|
|
3493
|
-
function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
3376
|
+
function NumberEditorDom({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
3494
3377
|
const [text, setText] = useState9(() => initialText != null ? initialText : seedText(value));
|
|
3495
3378
|
const escapedRef = useRef8(false);
|
|
3496
3379
|
const parsed = parseValue(text);
|
|
@@ -3527,6 +3410,7 @@ function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
|
3527
3410
|
/* @__PURE__ */ jsx16(
|
|
3528
3411
|
"input",
|
|
3529
3412
|
{
|
|
3413
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
3530
3414
|
value: text,
|
|
3531
3415
|
onChange: (e) => setText(e.target.value),
|
|
3532
3416
|
onKeyDown: handleKeyDown,
|
|
@@ -4153,7 +4037,7 @@ function RelationEditorDom({
|
|
|
4153
4037
|
import { useRef as useRef11, useState as useState12 } from "react";
|
|
4154
4038
|
import { Button as Button9 } from "@constructive-io/ui/button";
|
|
4155
4039
|
import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
4156
|
-
function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
4040
|
+
function TextEditor({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
4157
4041
|
const [text, setText] = useState12(() => initialText != null ? initialText : String(value ?? ""));
|
|
4158
4042
|
const escapedRef = useRef11(false);
|
|
4159
4043
|
function handleKeyDown(e) {
|
|
@@ -4179,6 +4063,7 @@ function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
|
4179
4063
|
/* @__PURE__ */ jsx20(
|
|
4180
4064
|
"input",
|
|
4181
4065
|
{
|
|
4066
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
4182
4067
|
value: text,
|
|
4183
4068
|
onChange: (e) => setText(e.target.value),
|
|
4184
4069
|
onKeyDown: handleKeyDown,
|
|
@@ -4469,10 +4354,15 @@ function resolveNativeEditor(typeKey, consumer) {
|
|
|
4469
4354
|
}
|
|
4470
4355
|
|
|
4471
4356
|
export {
|
|
4472
|
-
isSheetsScopeKey,
|
|
4473
|
-
sheetsQueryKeys,
|
|
4474
4357
|
resolveRelationFieldMap,
|
|
4475
4358
|
validateOrderByVariables,
|
|
4359
|
+
resolveSheetsRowIdentity,
|
|
4360
|
+
resolveSheetsIdentifier,
|
|
4361
|
+
sheetsIdentifierToWhere,
|
|
4362
|
+
sheetsIdentifierCacheKey,
|
|
4363
|
+
sheetsRowKey,
|
|
4364
|
+
getSheetsWriteCapability,
|
|
4365
|
+
canRunSheetsMutation,
|
|
4476
4366
|
sheetsTableQueryKeys,
|
|
4477
4367
|
transformToPostGraphileVariables,
|
|
4478
4368
|
useSheetsTable,
|
|
@@ -4480,6 +4370,7 @@ export {
|
|
|
4480
4370
|
useSheetsAdapter,
|
|
4481
4371
|
useSheetsMeta,
|
|
4482
4372
|
createSheetsCell,
|
|
4373
|
+
getImageMetadata,
|
|
4483
4374
|
OverlayMeasureContext,
|
|
4484
4375
|
computeOverlayGeometry,
|
|
4485
4376
|
OverlayViewportGuard,
|
|
@@ -4491,4 +4382,4 @@ export {
|
|
|
4491
4382
|
DOM_EDITOR_REGISTRY,
|
|
4492
4383
|
resolveNativeEditor
|
|
4493
4384
|
};
|
|
4494
|
-
//# sourceMappingURL=chunk-
|
|
4385
|
+
//# sourceMappingURL=chunk-LR64FLWO.js.map
|