@constructive-io/sheets 0.3.0 → 0.4.1
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/dist/advanced.cjs +449 -109
- package/dist/advanced.cjs.map +1 -1
- package/dist/advanced.js +3 -3
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.js +2 -2
- package/dist/{chunk-FNVHSOQQ.js → chunk-3BNOZQIJ.js} +2 -2
- package/dist/{chunk-ODUBS2NL.js → chunk-BWJVRYJT.js} +3 -3
- package/dist/{chunk-TU7ATZ4X.js → chunk-BWKB52JB.js} +73 -34
- package/dist/chunk-BWKB52JB.js.map +1 -0
- package/dist/{chunk-4PGPVMZB.js → chunk-FG2LRZP5.js} +1 -1
- package/dist/chunk-FG2LRZP5.js.map +1 -0
- package/dist/chunk-SDKHWE7G.js +469 -0
- package/dist/chunk-SDKHWE7G.js.map +1 -0
- package/dist/index.cjs +630 -254
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -3
- package/dist/index.d.ts +40 -3
- package/dist/index.js +66 -34
- package/dist/index.js.map +1 -1
- package/dist/{sheets-context-Da55TTR9.d.ts → sheets-context-9u9r7Bs0.d.ts} +23 -0
- package/dist/{sheets-context-CojEFlaY.d.cts → sheets-context-BjGIHocT.d.cts} +23 -0
- package/dist/testing.cjs +391 -89
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-4PGPVMZB.js.map +0 -1
- package/dist/chunk-H4JJTMP5.js +0 -160
- package/dist/chunk-H4JJTMP5.js.map +0 -1
- package/dist/chunk-TU7ATZ4X.js.map +0 -1
- /package/dist/{chunk-FNVHSOQQ.js.map → chunk-3BNOZQIJ.js.map} +0 -0
- /package/dist/{chunk-ODUBS2NL.js.map → chunk-BWJVRYJT.js.map} +0 -0
package/dist/advanced.cjs
CHANGED
|
@@ -1623,7 +1623,7 @@ function useSheetsStoreApi() {
|
|
|
1623
1623
|
// src/hooks/use-sheets-upload.ts
|
|
1624
1624
|
var import_react12 = require("react");
|
|
1625
1625
|
var import_react_query3 = require("@tanstack/react-query");
|
|
1626
|
-
var
|
|
1626
|
+
var import_data10 = require("@constructive-io/data");
|
|
1627
1627
|
|
|
1628
1628
|
// src/hooks/use-sheets-meta.ts
|
|
1629
1629
|
var import_react_query2 = require("@tanstack/react-query");
|
|
@@ -1924,7 +1924,7 @@ function transformToPostGraphileVariables(table, options = {}) {
|
|
|
1924
1924
|
variables.orderBy = options.orderBy.filter(({ field }) => availableFields.has(field)).map(({ field, direction }) => (0, import_data5.toOrderByEnumValue)(field, direction));
|
|
1925
1925
|
}
|
|
1926
1926
|
if (options.where) {
|
|
1927
|
-
variables.
|
|
1927
|
+
variables.where = options.where;
|
|
1928
1928
|
}
|
|
1929
1929
|
return variables;
|
|
1930
1930
|
}
|
|
@@ -2554,20 +2554,346 @@ function useSheetsMeta(options = {}) {
|
|
|
2554
2554
|
}
|
|
2555
2555
|
|
|
2556
2556
|
// src/hooks/use-sheets-upload.ts
|
|
2557
|
-
var
|
|
2557
|
+
var import_data11 = require("@constructive-io/data");
|
|
2558
2558
|
|
|
2559
2559
|
// src/context/sheets-execute.ts
|
|
2560
|
+
var import_graphql2 = require("graphql");
|
|
2561
|
+
var import_data8 = require("@constructive-io/data");
|
|
2562
|
+
|
|
2563
|
+
// src/context/sheets-upload-presigned.ts
|
|
2560
2564
|
var import_graphql = require("graphql");
|
|
2561
2565
|
var import_data7 = require("@constructive-io/data");
|
|
2562
|
-
|
|
2566
|
+
async function sha256HexFromBuffer(buffer) {
|
|
2567
|
+
if (!globalThis.crypto?.subtle) {
|
|
2568
|
+
throw import_data7.createError.badRequest("Web Crypto (crypto.subtle) is unavailable; cannot hash file for upload.");
|
|
2569
|
+
}
|
|
2570
|
+
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
2571
|
+
const bytes = new Uint8Array(digest);
|
|
2572
|
+
let hex = "";
|
|
2573
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2574
|
+
hex += bytes[i].toString(16).padStart(2, "0");
|
|
2575
|
+
}
|
|
2576
|
+
return hex;
|
|
2577
|
+
}
|
|
2578
|
+
var capabilityCache = /* @__PURE__ */ new Map();
|
|
2579
|
+
function discoverUploadCapability(endpoint, execute) {
|
|
2580
|
+
const cached = capabilityCache.get(endpoint);
|
|
2581
|
+
if (cached) return cached;
|
|
2582
|
+
const promise = (async () => {
|
|
2583
|
+
const data = await execute((0, import_graphql.getIntrospectionQuery)());
|
|
2584
|
+
const schema = data?.__schema;
|
|
2585
|
+
if (!schema) {
|
|
2586
|
+
throw import_data7.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2587
|
+
}
|
|
2588
|
+
return resolveUploadCapability(schema);
|
|
2589
|
+
})();
|
|
2590
|
+
promise.catch(() => capabilityCache.delete(endpoint));
|
|
2591
|
+
capabilityCache.set(endpoint, promise);
|
|
2592
|
+
return promise;
|
|
2593
|
+
}
|
|
2594
|
+
function namedTypeName(ref) {
|
|
2595
|
+
let cur = ref;
|
|
2596
|
+
while (cur && (cur.kind === "NON_NULL" || cur.kind === "LIST")) {
|
|
2597
|
+
cur = cur.ofType ?? null;
|
|
2598
|
+
}
|
|
2599
|
+
return cur?.name ?? null;
|
|
2600
|
+
}
|
|
2601
|
+
function isListTypeRef(ref) {
|
|
2602
|
+
let cur = ref;
|
|
2603
|
+
while (cur && cur.kind === "NON_NULL") {
|
|
2604
|
+
cur = cur.ofType ?? null;
|
|
2605
|
+
}
|
|
2606
|
+
return cur?.kind === "LIST";
|
|
2607
|
+
}
|
|
2608
|
+
var PK_FIELD_NAME = "id";
|
|
2609
|
+
function resolveUploadCapability(schema) {
|
|
2610
|
+
const typeByName = /* @__PURE__ */ new Map();
|
|
2611
|
+
for (const t of schema.types) {
|
|
2612
|
+
if (t.name) typeByName.set(t.name, t);
|
|
2613
|
+
}
|
|
2614
|
+
const objectHasFields = (typeName, names) => {
|
|
2615
|
+
if (!typeName) return false;
|
|
2616
|
+
const t = typeByName.get(typeName);
|
|
2617
|
+
if (!t?.fields) return false;
|
|
2618
|
+
const present = new Set(t.fields.map((f) => f.name));
|
|
2619
|
+
return names.every((n) => present.has(n));
|
|
2620
|
+
};
|
|
2621
|
+
const inputHasFields = (typeName, names) => {
|
|
2622
|
+
if (!typeName) return false;
|
|
2623
|
+
const t = typeByName.get(typeName);
|
|
2624
|
+
if (!t?.inputFields) return false;
|
|
2625
|
+
const present = new Set(t.inputFields.map((f) => f.name));
|
|
2626
|
+
return names.every((n) => present.has(n));
|
|
2627
|
+
};
|
|
2628
|
+
const PAYLOAD_FIELDS = ["uploadUrl", "fileId", "deduplicated"];
|
|
2629
|
+
const INPUT_FIELDS = ["contentHash", "bucketKey", "contentType", "size"];
|
|
2630
|
+
const mutationType = schema.mutationType ? typeByName.get(schema.mutationType.name) : null;
|
|
2631
|
+
const queryType = schema.queryType ? typeByName.get(schema.queryType.name) : null;
|
|
2632
|
+
let upload = null;
|
|
2633
|
+
for (const field of mutationType?.fields ?? []) {
|
|
2634
|
+
const inputArg = field.args.find((a) => a.name === "input");
|
|
2635
|
+
if (!inputArg) continue;
|
|
2636
|
+
const inputTypeName = namedTypeName(inputArg.type);
|
|
2637
|
+
const payloadTypeName = namedTypeName(field.type);
|
|
2638
|
+
if (inputHasFields(inputTypeName, INPUT_FIELDS) && objectHasFields(payloadTypeName, PAYLOAD_FIELDS)) {
|
|
2639
|
+
upload = { uploadFieldName: field.name, inputTypeName };
|
|
2640
|
+
break;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
if (!upload) {
|
|
2644
|
+
throw import_data7.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2645
|
+
}
|
|
2646
|
+
const downloadById = resolveDownloadByIdField(schema, typeByName, queryType, upload.uploadFieldName);
|
|
2647
|
+
return {
|
|
2648
|
+
...upload,
|
|
2649
|
+
...downloadById
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
function resolveDownloadByIdField(schema, typeByName, queryType, uploadFieldName) {
|
|
2653
|
+
const fileTypesWithDownloadUrl = /* @__PURE__ */ new Set();
|
|
2654
|
+
for (const t of schema.types) {
|
|
2655
|
+
if (t.kind === "OBJECT" && t.name && t.fields?.some((f) => f.name === "downloadUrl")) {
|
|
2656
|
+
fileTypesWithDownloadUrl.add(t.name);
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
for (const field of queryType?.fields ?? []) {
|
|
2660
|
+
const returnTypeName = namedTypeName(field.type);
|
|
2661
|
+
if (!returnTypeName || !fileTypesWithDownloadUrl.has(returnTypeName)) continue;
|
|
2662
|
+
if (field.args.length === 1 && field.args[0].name === PK_FIELD_NAME) {
|
|
2663
|
+
return {
|
|
2664
|
+
fileByIdField: field.name,
|
|
2665
|
+
fileByIdArgName: "id",
|
|
2666
|
+
fileTypeName: returnTypeName,
|
|
2667
|
+
idScalarName: namedTypeName(field.args[0].type) ?? void 0
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
const connection = resolveConnectionDownloadField(typeByName, queryType, fileTypesWithDownloadUrl, uploadFieldName);
|
|
2672
|
+
if (connection) return connection;
|
|
2673
|
+
const nodeField = queryType?.fields?.find(
|
|
2674
|
+
(f) => f.name === "node" && f.args.some((a) => a.name === "nodeId")
|
|
2675
|
+
);
|
|
2676
|
+
if (nodeField && fileTypesWithDownloadUrl.size > 0) {
|
|
2677
|
+
const preferred = uploadFieldName.replace(/^upload/, "");
|
|
2678
|
+
const fileTypeName = fileTypesWithDownloadUrl.has(preferred) ? preferred : [...fileTypesWithDownloadUrl][0];
|
|
2679
|
+
return { fileByIdField: "node", fileByIdArgName: "nodeId", fileTypeName };
|
|
2680
|
+
}
|
|
2681
|
+
throw import_data7.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2682
|
+
}
|
|
2683
|
+
function resolveConnectionDownloadField(typeByName, queryType, fileTypesWithDownloadUrl, uploadFieldName) {
|
|
2684
|
+
const EQUALITY_OPERATORS = ["equalTo", "eq"];
|
|
2685
|
+
const candidates = [];
|
|
2686
|
+
for (const field of queryType?.fields ?? []) {
|
|
2687
|
+
const connTypeName = namedTypeName(field.type);
|
|
2688
|
+
if (!connTypeName) continue;
|
|
2689
|
+
const connType = typeByName.get(connTypeName);
|
|
2690
|
+
if (connType?.kind !== "OBJECT" || !connType.fields) continue;
|
|
2691
|
+
const nodesField = connType.fields.find((f) => {
|
|
2692
|
+
if (!isListTypeRef(f.type)) return false;
|
|
2693
|
+
const elem = namedTypeName(f.type);
|
|
2694
|
+
return elem != null && fileTypesWithDownloadUrl.has(elem);
|
|
2695
|
+
});
|
|
2696
|
+
if (!nodesField) continue;
|
|
2697
|
+
const fileTypeName = namedTypeName(nodesField.type);
|
|
2698
|
+
for (const arg of field.args) {
|
|
2699
|
+
const filterTypeName = namedTypeName(arg.type);
|
|
2700
|
+
const filterType = filterTypeName ? typeByName.get(filterTypeName) : null;
|
|
2701
|
+
if (filterType?.kind !== "INPUT_OBJECT" || !filterType.inputFields) continue;
|
|
2702
|
+
const idField = filterType.inputFields.find((f) => f.name === PK_FIELD_NAME);
|
|
2703
|
+
if (!idField) continue;
|
|
2704
|
+
const idFieldTypeName = namedTypeName(idField.type);
|
|
2705
|
+
const idFieldType = idFieldTypeName ? typeByName.get(idFieldTypeName) : null;
|
|
2706
|
+
if (idFieldType?.kind === "INPUT_OBJECT" && idFieldType.inputFields) {
|
|
2707
|
+
const opField = EQUALITY_OPERATORS.map(
|
|
2708
|
+
(op) => idFieldType.inputFields.find((f) => f.name === op)
|
|
2709
|
+
).find((f) => f != null);
|
|
2710
|
+
if (opField) {
|
|
2711
|
+
candidates.push({
|
|
2712
|
+
fileByIdField: field.name,
|
|
2713
|
+
fileByIdArgName: "connection",
|
|
2714
|
+
fileTypeName,
|
|
2715
|
+
idScalarName: namedTypeName(opField.type) ?? void 0,
|
|
2716
|
+
connectionFilterArgName: arg.name,
|
|
2717
|
+
connectionIdField: idField.name,
|
|
2718
|
+
connectionIdOperator: opField.name,
|
|
2719
|
+
connectionNodesField: nodesField.name
|
|
2720
|
+
});
|
|
2721
|
+
break;
|
|
2722
|
+
}
|
|
2723
|
+
continue;
|
|
2724
|
+
}
|
|
2725
|
+
if (idFieldType?.kind === "SCALAR" || !idFieldType && idFieldTypeName) {
|
|
2726
|
+
candidates.push({
|
|
2727
|
+
fileByIdField: field.name,
|
|
2728
|
+
fileByIdArgName: "connection",
|
|
2729
|
+
fileTypeName,
|
|
2730
|
+
idScalarName: idFieldTypeName ?? void 0,
|
|
2731
|
+
connectionFilterArgName: arg.name,
|
|
2732
|
+
connectionIdField: idField.name,
|
|
2733
|
+
connectionNodesField: nodesField.name
|
|
2734
|
+
});
|
|
2735
|
+
break;
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
if (candidates.length === 0) return null;
|
|
2740
|
+
const preferred = uploadFieldName.replace(/^upload/, "");
|
|
2741
|
+
return candidates.find((c) => c.fileTypeName === preferred) ?? candidates[0];
|
|
2742
|
+
}
|
|
2743
|
+
async function callUploadOp(execute, cap, input) {
|
|
2744
|
+
const mutation = `
|
|
2745
|
+
mutation SheetsUpload($input: ${cap.inputTypeName}!) {
|
|
2746
|
+
${cap.uploadFieldName}(input: $input) {
|
|
2747
|
+
uploadUrl
|
|
2748
|
+
fileId
|
|
2749
|
+
key
|
|
2750
|
+
deduplicated
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
`.trim();
|
|
2754
|
+
const data = await execute(mutation, {
|
|
2755
|
+
input: {
|
|
2756
|
+
bucketKey: input.bucketKey,
|
|
2757
|
+
contentHash: input.contentHash,
|
|
2758
|
+
contentType: input.contentType,
|
|
2759
|
+
size: input.size,
|
|
2760
|
+
filename: input.filename
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
const payload = data?.[cap.uploadFieldName];
|
|
2764
|
+
if (!payload) {
|
|
2765
|
+
throw import_data7.createError.badRequest("Upload failed: no payload returned from upload mutation.");
|
|
2766
|
+
}
|
|
2767
|
+
return payload;
|
|
2768
|
+
}
|
|
2769
|
+
async function presignedPut(url, buffer, contentType, onProgress) {
|
|
2770
|
+
const total = buffer.byteLength;
|
|
2771
|
+
if (onProgress && typeof XMLHttpRequest !== "undefined") {
|
|
2772
|
+
await putWithXHR(url, buffer, contentType, total, onProgress);
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
let response;
|
|
2776
|
+
try {
|
|
2777
|
+
response = await fetch(url, {
|
|
2778
|
+
method: "PUT",
|
|
2779
|
+
headers: { "Content-Type": contentType },
|
|
2780
|
+
body: buffer
|
|
2781
|
+
});
|
|
2782
|
+
} catch (error) {
|
|
2783
|
+
throw import_data7.createError.network(error instanceof Error ? error : void 0);
|
|
2784
|
+
}
|
|
2785
|
+
if (!response.ok) {
|
|
2786
|
+
const body = await response.text().catch(() => "");
|
|
2787
|
+
throw import_data7.createError.badRequest(`Upload failed: ${response.status} ${response.statusText}${body ? ` \u2014 ${body}` : ""}`);
|
|
2788
|
+
}
|
|
2789
|
+
onProgress?.({ loaded: total, total, percentage: 100 });
|
|
2790
|
+
}
|
|
2791
|
+
function putWithXHR(url, buffer, contentType, total, onProgress) {
|
|
2792
|
+
return new Promise((resolve, reject) => {
|
|
2793
|
+
const xhr = new XMLHttpRequest();
|
|
2794
|
+
xhr.open("PUT", url);
|
|
2795
|
+
xhr.setRequestHeader("Content-Type", contentType);
|
|
2796
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
2797
|
+
if (event.lengthComputable) {
|
|
2798
|
+
onProgress({
|
|
2799
|
+
loaded: event.loaded,
|
|
2800
|
+
total: event.total,
|
|
2801
|
+
percentage: Math.round(event.loaded / event.total * 100)
|
|
2802
|
+
});
|
|
2803
|
+
}
|
|
2804
|
+
});
|
|
2805
|
+
xhr.addEventListener("load", () => {
|
|
2806
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
2807
|
+
onProgress({ loaded: total, total, percentage: 100 });
|
|
2808
|
+
resolve();
|
|
2809
|
+
} else {
|
|
2810
|
+
reject(import_data7.createError.badRequest(`Upload failed: ${xhr.status} ${xhr.statusText}${xhr.responseText ? ` \u2014 ${xhr.responseText}` : ""}`));
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
xhr.addEventListener("error", () => reject(import_data7.createError.network()));
|
|
2814
|
+
xhr.send(buffer);
|
|
2815
|
+
});
|
|
2816
|
+
}
|
|
2817
|
+
function toGlobalId(typeName, id) {
|
|
2818
|
+
if (typeof btoa !== "function") {
|
|
2819
|
+
throw import_data7.createError.badRequest("Cannot encode the file node id: btoa is unavailable in this environment.");
|
|
2820
|
+
}
|
|
2821
|
+
return btoa(JSON.stringify([typeName, id]));
|
|
2822
|
+
}
|
|
2823
|
+
async function fetchDownloadUrl(execute, cap, fileId) {
|
|
2824
|
+
if (cap.fileByIdArgName === "nodeId") {
|
|
2825
|
+
const nodeId = toGlobalId(cap.fileTypeName, fileId);
|
|
2826
|
+
const query2 = `
|
|
2827
|
+
query SheetsDownloadUrl($nodeId: ID!) {
|
|
2828
|
+
${cap.fileByIdField}(nodeId: $nodeId) {
|
|
2829
|
+
... on ${cap.fileTypeName} {
|
|
2830
|
+
downloadUrl
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
`.trim();
|
|
2835
|
+
const data2 = await execute(query2, { nodeId });
|
|
2836
|
+
const node = data2?.[cap.fileByIdField];
|
|
2837
|
+
const url2 = node?.downloadUrl;
|
|
2838
|
+
if (!url2) {
|
|
2839
|
+
throw import_data7.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2840
|
+
}
|
|
2841
|
+
return url2;
|
|
2842
|
+
}
|
|
2843
|
+
if (cap.fileByIdArgName === "connection") {
|
|
2844
|
+
const idScalar2 = cap.idScalarName ?? "ID";
|
|
2845
|
+
const filterArg = cap.connectionFilterArgName;
|
|
2846
|
+
const idField = cap.connectionIdField;
|
|
2847
|
+
const nodesField = cap.connectionNodesField;
|
|
2848
|
+
const filterLiteral = cap.connectionIdOperator ? `{ ${idField}: { ${cap.connectionIdOperator}: $id } }` : `{ ${idField}: $id }`;
|
|
2849
|
+
const query2 = `
|
|
2850
|
+
query SheetsDownloadUrl($id: ${idScalar2}!) {
|
|
2851
|
+
${cap.fileByIdField}(${filterArg}: ${filterLiteral}, first: 1) {
|
|
2852
|
+
${nodesField} {
|
|
2853
|
+
downloadUrl
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
`.trim();
|
|
2858
|
+
const data2 = await execute(
|
|
2859
|
+
query2,
|
|
2860
|
+
{ id: fileId }
|
|
2861
|
+
);
|
|
2862
|
+
const conn = data2?.[cap.fileByIdField];
|
|
2863
|
+
const url2 = conn?.[nodesField]?.[0]?.downloadUrl;
|
|
2864
|
+
if (!url2) {
|
|
2865
|
+
throw import_data7.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2866
|
+
}
|
|
2867
|
+
return url2;
|
|
2868
|
+
}
|
|
2869
|
+
const idScalar = cap.idScalarName ?? "ID";
|
|
2870
|
+
const query = `
|
|
2871
|
+
query SheetsDownloadUrl($id: ${idScalar}!) {
|
|
2872
|
+
${cap.fileByIdField}(id: $id) {
|
|
2873
|
+
id
|
|
2874
|
+
downloadUrl
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
`.trim();
|
|
2878
|
+
const data = await execute(query, { id: fileId });
|
|
2879
|
+
const file = data?.[cap.fileByIdField];
|
|
2880
|
+
const url = file?.downloadUrl;
|
|
2881
|
+
if (!url) {
|
|
2882
|
+
throw import_data7.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2883
|
+
}
|
|
2884
|
+
return url;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
// src/context/sheets-execute.ts
|
|
2888
|
+
var import_data9 = require("@constructive-io/data");
|
|
2563
2889
|
function documentToString(document2) {
|
|
2564
2890
|
if (typeof document2 === "string") return document2;
|
|
2565
2891
|
if (document2 instanceof String) return document2.toString();
|
|
2566
2892
|
if (document2 && typeof document2 === "object" && "kind" in document2) {
|
|
2567
|
-
return (0,
|
|
2893
|
+
return (0, import_graphql2.print)(document2);
|
|
2568
2894
|
}
|
|
2569
2895
|
if (document2 === null || document2 === void 0) {
|
|
2570
|
-
throw
|
|
2896
|
+
throw import_data8.createError.badRequest("Invalid GraphQL document: null or undefined");
|
|
2571
2897
|
}
|
|
2572
2898
|
return String(document2);
|
|
2573
2899
|
}
|
|
@@ -2582,18 +2908,18 @@ function parseGraphQLResponse(response, onAuthError) {
|
|
|
2582
2908
|
const message = error.message || "GraphQL query failed";
|
|
2583
2909
|
if (code === "UNAUTHENTICATED" || hasAuthMessage(message)) {
|
|
2584
2910
|
onAuthError?.();
|
|
2585
|
-
return
|
|
2911
|
+
return import_data8.createError.unauthorized("Authentication required. Please log in again.");
|
|
2586
2912
|
}
|
|
2587
2913
|
if (code === "FORBIDDEN") {
|
|
2588
|
-
return
|
|
2914
|
+
return import_data8.createError.forbidden("You do not have permission to perform this action.");
|
|
2589
2915
|
}
|
|
2590
|
-
return
|
|
2916
|
+
return import_data8.createError.graphql(message, code);
|
|
2591
2917
|
}
|
|
2592
2918
|
function createSheetsExecute(config, getToken) {
|
|
2593
2919
|
return async (document2, variables) => {
|
|
2594
2920
|
const url = config.endpoint;
|
|
2595
2921
|
if (!url) {
|
|
2596
|
-
throw
|
|
2922
|
+
throw import_data8.createError.badRequest("No GraphQL endpoint configured.");
|
|
2597
2923
|
}
|
|
2598
2924
|
const token = getToken();
|
|
2599
2925
|
const headers = {
|
|
@@ -2614,29 +2940,29 @@ function createSheetsExecute(config, getToken) {
|
|
|
2614
2940
|
})
|
|
2615
2941
|
});
|
|
2616
2942
|
} catch (error) {
|
|
2617
|
-
throw
|
|
2943
|
+
throw import_data8.createError.network(error instanceof Error ? error : void 0);
|
|
2618
2944
|
}
|
|
2619
2945
|
if (!response.ok) {
|
|
2620
2946
|
const { status, statusText } = response;
|
|
2621
2947
|
if (status === 401) {
|
|
2622
2948
|
config.onAuthError?.();
|
|
2623
|
-
throw
|
|
2949
|
+
throw import_data8.createError.unauthorized("Authentication required. Please log in again.");
|
|
2624
2950
|
}
|
|
2625
2951
|
if (status === 403) {
|
|
2626
|
-
throw
|
|
2952
|
+
throw import_data8.createError.forbidden("You do not have permission to perform this action.");
|
|
2627
2953
|
}
|
|
2628
2954
|
if (status === 404) {
|
|
2629
|
-
throw
|
|
2955
|
+
throw import_data8.createError.notFound("The requested endpoint does not exist.");
|
|
2630
2956
|
}
|
|
2631
2957
|
try {
|
|
2632
2958
|
const body = await response.json();
|
|
2633
2959
|
if (body.errors?.length) {
|
|
2634
|
-
throw
|
|
2960
|
+
throw import_data8.createError.graphql(body.errors[0].message || `Request failed: ${status}`, body.errors[0].extensions?.code);
|
|
2635
2961
|
}
|
|
2636
2962
|
} catch (e) {
|
|
2637
|
-
if (e instanceof
|
|
2963
|
+
if (e instanceof import_data8.DataError) throw e;
|
|
2638
2964
|
}
|
|
2639
|
-
throw
|
|
2965
|
+
throw import_data8.createError.badRequest(`Request failed: ${status} ${statusText}`);
|
|
2640
2966
|
}
|
|
2641
2967
|
const result = await response.json();
|
|
2642
2968
|
const graphqlError = parseGraphQLResponse(result, config.onAuthError);
|
|
@@ -2647,74 +2973,50 @@ function createSheetsExecute(config, getToken) {
|
|
|
2647
2973
|
};
|
|
2648
2974
|
}
|
|
2649
2975
|
function createSheetsUpload(config, getToken) {
|
|
2650
|
-
|
|
2976
|
+
const execute = config.execute ?? createSheetsExecute(config, getToken);
|
|
2977
|
+
return async (file, _path, options) => {
|
|
2651
2978
|
if (!config.endpoint) {
|
|
2652
|
-
throw
|
|
2653
|
-
}
|
|
2654
|
-
const url = config.endpoint.replace(/\/graphql\/?$/, "/upload");
|
|
2655
|
-
const token = getToken();
|
|
2656
|
-
const formData = new FormData();
|
|
2657
|
-
formData.append("file", file);
|
|
2658
|
-
if (path) formData.append("path", path);
|
|
2659
|
-
const headers = {};
|
|
2660
|
-
if (token) {
|
|
2661
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
2662
|
-
}
|
|
2663
|
-
let response;
|
|
2664
|
-
try {
|
|
2665
|
-
response = await fetch(url, {
|
|
2666
|
-
method: "POST",
|
|
2667
|
-
headers,
|
|
2668
|
-
body: formData
|
|
2669
|
-
});
|
|
2670
|
-
} catch (error) {
|
|
2671
|
-
throw import_data7.createError.network(error instanceof Error ? error : void 0);
|
|
2672
|
-
}
|
|
2673
|
-
if (!response.ok) {
|
|
2674
|
-
if (response.status === 401) {
|
|
2675
|
-
config.onAuthError?.();
|
|
2676
|
-
throw import_data7.createError.unauthorized("Authentication required. Please log in again.");
|
|
2677
|
-
}
|
|
2678
|
-
if (response.status === 403) {
|
|
2679
|
-
throw import_data7.createError.forbidden("You do not have permission to perform this action.");
|
|
2680
|
-
}
|
|
2681
|
-
try {
|
|
2682
|
-
const body = await response.json();
|
|
2683
|
-
const graphqlError = parseGraphQLResponse(body, config.onAuthError);
|
|
2684
|
-
if (graphqlError) {
|
|
2685
|
-
throw graphqlError;
|
|
2686
|
-
}
|
|
2687
|
-
if (body.errors?.length) {
|
|
2688
|
-
const firstError = body.errors[0];
|
|
2689
|
-
throw import_data7.createError.graphql(firstError.message || "Upload failed", firstError.extensions?.code);
|
|
2690
|
-
}
|
|
2691
|
-
} catch (error) {
|
|
2692
|
-
if (error instanceof import_data7.DataError) throw error;
|
|
2693
|
-
}
|
|
2694
|
-
if (response.status === 400) throw import_data7.createError.badRequest("No file provided for upload.");
|
|
2695
|
-
if (response.status === 413) throw import_data7.createError.badRequest("File is too large. Maximum size is 10 MB.");
|
|
2696
|
-
throw import_data7.createError.badRequest(`Upload failed: ${response.status} ${response.statusText}`);
|
|
2979
|
+
throw import_data8.createError.badRequest("No GraphQL endpoint configured.");
|
|
2697
2980
|
}
|
|
2698
|
-
const
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2981
|
+
const bucketKey = config.upload?.bucketKey ?? "public";
|
|
2982
|
+
const contentType = file.type || "application/octet-stream";
|
|
2983
|
+
const buffer = await file.arrayBuffer();
|
|
2984
|
+
const contentHash = await sha256HexFromBuffer(buffer);
|
|
2985
|
+
const cap = await discoverUploadCapability(config.endpoint, execute);
|
|
2986
|
+
const payload = await callUploadOp(execute, cap, {
|
|
2987
|
+
bucketKey,
|
|
2988
|
+
contentHash,
|
|
2989
|
+
contentType,
|
|
2990
|
+
size: file.size,
|
|
2991
|
+
filename: file.name
|
|
2992
|
+
});
|
|
2993
|
+
if (!payload.deduplicated) {
|
|
2994
|
+
if (!payload.uploadUrl) {
|
|
2995
|
+
throw import_data8.createError.badRequest("Upload failed: server returned no uploadUrl for a non-deduplicated file.");
|
|
2703
2996
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2997
|
+
await presignedPut(payload.uploadUrl, buffer, contentType, options?.onProgress);
|
|
2998
|
+
} else {
|
|
2999
|
+
options?.onProgress?.({ loaded: file.size, total: file.size, percentage: 100 });
|
|
2706
3000
|
}
|
|
2707
|
-
|
|
3001
|
+
const url = await fetchDownloadUrl(execute, cap, payload.fileId);
|
|
3002
|
+
return {
|
|
3003
|
+
url,
|
|
3004
|
+
filename: file.name,
|
|
3005
|
+
mime: file.type,
|
|
3006
|
+
size: file.size,
|
|
3007
|
+
key: payload.key,
|
|
3008
|
+
fileId: payload.fileId
|
|
3009
|
+
};
|
|
2708
3010
|
};
|
|
2709
3011
|
}
|
|
2710
3012
|
|
|
2711
3013
|
// src/hooks/use-sheets-upload.ts
|
|
2712
3014
|
function resolveUploadNaming(tableName, table) {
|
|
2713
3015
|
return {
|
|
2714
|
-
mutationName: (0,
|
|
2715
|
-
singularName: (0,
|
|
2716
|
-
patchFieldName: (0,
|
|
2717
|
-
updateInputTypeName: (0,
|
|
3016
|
+
mutationName: (0, import_data11.toUpdateMutationName)(tableName, table),
|
|
3017
|
+
singularName: (0, import_data11.toCamelCaseSingular)(tableName, table),
|
|
3018
|
+
patchFieldName: (0, import_data11.toPatchFieldName)(tableName, table),
|
|
3019
|
+
updateInputTypeName: (0, import_data11.toUpdateInputTypeName)(tableName)
|
|
2718
3020
|
};
|
|
2719
3021
|
}
|
|
2720
3022
|
function resolveTransport(endpoint, getToken, options) {
|
|
@@ -2791,7 +3093,7 @@ function useSheetsFieldUpload(tableName, fieldName, recordId, options = {}) {
|
|
|
2791
3093
|
const table = (0, import_react12.useMemo)(() => {
|
|
2792
3094
|
if (!meta?._meta?.tables) return null;
|
|
2793
3095
|
const candidate = meta._meta.tables.find((item) => item?.name === tableName);
|
|
2794
|
-
return candidate ? (0,
|
|
3096
|
+
return candidate ? (0, import_data10.cleanTable)(candidate) : null;
|
|
2795
3097
|
}, [meta, tableName]);
|
|
2796
3098
|
const resolvedNaming = (0, import_react12.useMemo)(() => resolveUploadNaming(tableName, table), [tableName, table]);
|
|
2797
3099
|
const getToken = (0, import_react12.useMemo)(() => {
|
|
@@ -2967,6 +3269,20 @@ function RemoveButton({ onClick, label }) {
|
|
|
2967
3269
|
}
|
|
2968
3270
|
) });
|
|
2969
3271
|
}
|
|
3272
|
+
function FilePreview({ name, size, mime }) {
|
|
3273
|
+
const hasMime = !!mime && mime !== "unknown";
|
|
3274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex size-full flex-col items-center justify-center gap-2 p-4 text-center", children: [
|
|
3275
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "bg-muted/60 flex size-12 shrink-0 items-center justify-center rounded-lg", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.FileIcon, { className: "text-muted-foreground size-6" }) }),
|
|
3276
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "min-w-0 max-w-full", children: [
|
|
3277
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "truncate text-sm font-medium", title: name, children: name || "File" }),
|
|
3278
|
+
(size || hasMime) && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("p", { className: "text-muted-foreground mt-0.5 text-xs", children: [
|
|
3279
|
+
size ? formatFileSize(size) : null,
|
|
3280
|
+
size && hasMime ? " \u2022 " : null,
|
|
3281
|
+
hasMime ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "uppercase", children: mime }) : null
|
|
3282
|
+
] })
|
|
3283
|
+
] })
|
|
3284
|
+
] });
|
|
3285
|
+
}
|
|
2970
3286
|
var ImageEditor = ({
|
|
2971
3287
|
value,
|
|
2972
3288
|
onFinishedEditing,
|
|
@@ -2976,8 +3292,11 @@ var ImageEditor = ({
|
|
|
2976
3292
|
onSaveComplete,
|
|
2977
3293
|
isDraftRow = false,
|
|
2978
3294
|
onSubmitDraft,
|
|
2979
|
-
onDraftUploadComplete
|
|
3295
|
+
onDraftUploadComplete,
|
|
3296
|
+
acceptAnyFile = false
|
|
2980
3297
|
}) => {
|
|
3298
|
+
const noun = acceptAnyFile ? "file" : "image";
|
|
3299
|
+
const Noun = acceptAnyFile ? "File" : "Image";
|
|
2981
3300
|
const [uploadState, setUploadState] = (0, import_react15.useState)("idle");
|
|
2982
3301
|
const { config } = useSheetsContext();
|
|
2983
3302
|
const storeApi = useSheetsStoreApi();
|
|
@@ -3000,10 +3319,12 @@ var ImageEditor = ({
|
|
|
3000
3319
|
const isUploading = uploadState === "uploading";
|
|
3001
3320
|
const isBusy = uploadState !== "idle";
|
|
3002
3321
|
const imageUrl = (0, import_react15.useMemo)(() => getImageUrl(imageValue), [imageValue]);
|
|
3003
|
-
const imageStatus = useImageStatus(imageUrl || void 0);
|
|
3004
|
-
const imageLoadFailed = imageUrl != null && imageStatus === "error";
|
|
3005
|
-
const hasImage = imageUrl != null && !imageLoadFailed;
|
|
3006
3322
|
const imageMetadata = (0, import_react15.useMemo)(() => getImageMetadata(imageValue), [imageValue]);
|
|
3323
|
+
const storedMime = imageMetadata?.mime;
|
|
3324
|
+
const storedIsImage = !acceptAnyFile || !!storedMime && storedMime.startsWith("image/");
|
|
3325
|
+
const imageStatus = useImageStatus(storedIsImage ? imageUrl || void 0 : void 0);
|
|
3326
|
+
const imageLoadFailed = storedIsImage && imageUrl != null && imageStatus === "error";
|
|
3327
|
+
const hasImage = imageUrl != null && !imageLoadFailed && storedIsImage;
|
|
3007
3328
|
const revokePreviewUrl = (0, import_react15.useCallback)(() => {
|
|
3008
3329
|
if (previewUrlRef.current) {
|
|
3009
3330
|
URL.revokeObjectURL(previewUrlRef.current);
|
|
@@ -3023,8 +3344,8 @@ var ImageEditor = ({
|
|
|
3023
3344
|
setImageValue(normalized);
|
|
3024
3345
|
onSaveComplete?.({ imageData: normalized });
|
|
3025
3346
|
onFinishedEditing();
|
|
3026
|
-
import_toast.toast.success({ message:
|
|
3027
|
-
}, [resetFileState, onSaveComplete, onFinishedEditing]);
|
|
3347
|
+
import_toast.toast.success({ message: `${Noun} uploaded successfully` });
|
|
3348
|
+
}, [resetFileState, onSaveComplete, onFinishedEditing, Noun]);
|
|
3028
3349
|
const handleUploadError = (0, import_react15.useCallback)((error) => {
|
|
3029
3350
|
setUploadState("idle");
|
|
3030
3351
|
sheetsLogger().error("[image-editor] upload failed:", error);
|
|
@@ -3044,20 +3365,22 @@ var ImageEditor = ({
|
|
|
3044
3365
|
const handleFileSelection = (0, import_react15.useCallback)((acceptedFiles) => {
|
|
3045
3366
|
if (acceptedFiles.length === 0) return;
|
|
3046
3367
|
const file = acceptedFiles[0];
|
|
3047
|
-
if (!
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3368
|
+
if (!acceptAnyFile) {
|
|
3369
|
+
if (!file.type.startsWith("image/")) {
|
|
3370
|
+
import_toast.toast.error({ message: "Please select an image file" });
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3373
|
+
if (file.size > 10 * 1024 * 1024) {
|
|
3374
|
+
import_toast.toast.error({ message: "File size must be less than 10MB" });
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3054
3377
|
}
|
|
3055
3378
|
revokePreviewUrl();
|
|
3056
3379
|
setSelectedFile(file);
|
|
3057
3380
|
const url = URL.createObjectURL(file);
|
|
3058
3381
|
previewUrlRef.current = url;
|
|
3059
3382
|
setPreviewUrl(url);
|
|
3060
|
-
}, [revokePreviewUrl]);
|
|
3383
|
+
}, [revokePreviewUrl, acceptAnyFile]);
|
|
3061
3384
|
const handleDragEnter = (0, import_react15.useCallback)((e) => {
|
|
3062
3385
|
e.preventDefault();
|
|
3063
3386
|
e.stopPropagation();
|
|
@@ -3092,7 +3415,7 @@ var ImageEditor = ({
|
|
|
3092
3415
|
const committedId = committedRecordIdRef.current ?? recordId;
|
|
3093
3416
|
if (committedRecordIdRef.current != null) {
|
|
3094
3417
|
try {
|
|
3095
|
-
import_toast.toast.info({ message:
|
|
3418
|
+
import_toast.toast.info({ message: `Uploading ${noun}...` });
|
|
3096
3419
|
setUploadState("uploading");
|
|
3097
3420
|
const uploadResult = await executeFieldUpload(
|
|
3098
3421
|
tableName,
|
|
@@ -3108,7 +3431,7 @@ var ImageEditor = ({
|
|
|
3108
3431
|
resetFileState();
|
|
3109
3432
|
setImageValue(normalized);
|
|
3110
3433
|
onDraftUploadComplete?.();
|
|
3111
|
-
import_toast.toast.success({ message:
|
|
3434
|
+
import_toast.toast.success({ message: `${Noun} uploaded successfully` });
|
|
3112
3435
|
onFinishedEditing();
|
|
3113
3436
|
} catch (error) {
|
|
3114
3437
|
onDraftUploadComplete?.();
|
|
@@ -3128,7 +3451,7 @@ var ImageEditor = ({
|
|
|
3128
3451
|
const result = await onSubmitDraft();
|
|
3129
3452
|
if (!result.createdRow?.id) throw new Error("Failed to create row");
|
|
3130
3453
|
committedRecordIdRef.current = result.createdRow.id;
|
|
3131
|
-
import_toast.toast.info({ message:
|
|
3454
|
+
import_toast.toast.info({ message: `Uploading ${noun}...` });
|
|
3132
3455
|
setUploadState("uploading");
|
|
3133
3456
|
const uploadResult = await executeFieldUpload(
|
|
3134
3457
|
tableName,
|
|
@@ -3144,7 +3467,7 @@ var ImageEditor = ({
|
|
|
3144
3467
|
resetFileState();
|
|
3145
3468
|
setImageValue(normalized);
|
|
3146
3469
|
onDraftUploadComplete?.();
|
|
3147
|
-
import_toast.toast.success({ message:
|
|
3470
|
+
import_toast.toast.success({ message: `Row created and ${noun} uploaded` });
|
|
3148
3471
|
onFinishedEditing();
|
|
3149
3472
|
} catch (error) {
|
|
3150
3473
|
onDraftUploadComplete?.();
|
|
@@ -3159,7 +3482,7 @@ var ImageEditor = ({
|
|
|
3159
3482
|
}
|
|
3160
3483
|
setUploadState("uploading");
|
|
3161
3484
|
uploadMutation.mutate(selectedFile);
|
|
3162
|
-
}, [selectedFile, uploadMutation, tableName, fieldName, recordId, isDraftRow, onSubmitDraft, config.endpoint, config.onAuthError, getToken, resetFileState, onDraftUploadComplete, onFinishedEditing]);
|
|
3485
|
+
}, [selectedFile, uploadMutation, tableName, fieldName, recordId, isDraftRow, onSubmitDraft, config.endpoint, config.onAuthError, getToken, resetFileState, onDraftUploadComplete, onFinishedEditing, noun, Noun]);
|
|
3163
3486
|
const handleSave = (0, import_react15.useCallback)(() => {
|
|
3164
3487
|
if (!imageValue) {
|
|
3165
3488
|
onFinishedEditing(null);
|
|
@@ -3184,12 +3507,13 @@ var ImageEditor = ({
|
|
|
3184
3507
|
handleSave();
|
|
3185
3508
|
}
|
|
3186
3509
|
}, [handleSave]);
|
|
3187
|
-
const
|
|
3510
|
+
const hasStoredFile = acceptAnyFile && !!imageUrl && !storedIsImage;
|
|
3511
|
+
const dropzoneKey = isBusy ? "busy" : previewUrl ? "preview" : hasImage ? "loaded" : hasStoredFile ? "file" : imageLoadFailed ? "broken" : "empty";
|
|
3188
3512
|
const renderDropzoneContent = () => {
|
|
3189
3513
|
if (isBusy) {
|
|
3190
3514
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { "data-state": uploadState, className: "text-muted-foreground flex w-full flex-col items-center justify-center p-6", children: [
|
|
3191
3515
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.Loader2, { className: "mb-2 size-6 animate-spin" }),
|
|
3192
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "text-sm", children: isSubmittingDraft ? "Creating row..." :
|
|
3516
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "text-sm", children: isSubmittingDraft ? "Creating row..." : `Uploading ${noun}...` }),
|
|
3193
3517
|
isUploading && uploadProgress && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "mt-3 w-full max-w-xs", children: [
|
|
3194
3518
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "bg-muted h-1.5 overflow-hidden rounded-full", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3195
3519
|
"div",
|
|
@@ -3206,8 +3530,9 @@ var ImageEditor = ({
|
|
|
3206
3530
|
] });
|
|
3207
3531
|
}
|
|
3208
3532
|
if (previewUrl) {
|
|
3533
|
+
const selectedIsImage = !acceptAnyFile || (selectedFile?.type.startsWith("image/") ?? false);
|
|
3209
3534
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative w-full", style: { height: "13rem" }, children: [
|
|
3210
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("img", { src: previewUrl, alt: selectedFile?.name || "
|
|
3535
|
+
selectedIsImage ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("img", { src: previewUrl, alt: selectedFile?.name || "Selected file", className: "size-full object-contain p-2" }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FilePreview, { name: selectedFile?.name, size: selectedFile?.size, mime: selectedFile?.type }),
|
|
3211
3536
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(RemoveButton, { onClick: removeFile, label: "Remove selected file" })
|
|
3212
3537
|
] });
|
|
3213
3538
|
}
|
|
@@ -3226,6 +3551,12 @@ var ImageEditor = ({
|
|
|
3226
3551
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(RemoveButton, { onClick: handleRemoveImage, label: "Remove image" })
|
|
3227
3552
|
] });
|
|
3228
3553
|
}
|
|
3554
|
+
if (hasStoredFile) {
|
|
3555
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative w-full", style: { height: "13rem" }, children: [
|
|
3556
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FilePreview, { name: imageMetadata?.filename, size: imageMetadata?.size, mime: imageMetadata?.mime }),
|
|
3557
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(RemoveButton, { onClick: handleRemoveImage, label: "Remove file" })
|
|
3558
|
+
] });
|
|
3559
|
+
}
|
|
3229
3560
|
if (imageLoadFailed) {
|
|
3230
3561
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex w-full flex-col items-center justify-center px-4 py-6 text-center", children: [
|
|
3231
3562
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
@@ -3279,8 +3610,12 @@ var ImageEditor = ({
|
|
|
3279
3610
|
}
|
|
3280
3611
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex w-full flex-col items-center justify-center px-4 py-6 text-center", children: [
|
|
3281
3612
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "bg-muted/60 mb-3 flex size-10 shrink-0 items-center justify-center rounded-full", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.UploadIcon, { className: "text-muted-foreground size-4" }) }),
|
|
3282
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.
|
|
3283
|
-
|
|
3613
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("p", { className: "text-sm font-medium", children: [
|
|
3614
|
+
"Drop ",
|
|
3615
|
+
noun,
|
|
3616
|
+
" here or browse"
|
|
3617
|
+
] }),
|
|
3618
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "text-muted-foreground mt-1 text-xs", children: acceptAnyFile ? "Any file type" : "SVG, PNG, JPG or GIF (max. 10MB)" }),
|
|
3284
3619
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
3285
3620
|
import_button5.Button,
|
|
3286
3621
|
{
|
|
@@ -3294,7 +3629,8 @@ var ImageEditor = ({
|
|
|
3294
3629
|
disabled: isBusy,
|
|
3295
3630
|
children: [
|
|
3296
3631
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.UploadIcon, { className: "-ms-0.5 opacity-60", "aria-hidden": "true" }),
|
|
3297
|
-
"Select
|
|
3632
|
+
"Select ",
|
|
3633
|
+
noun
|
|
3298
3634
|
]
|
|
3299
3635
|
}
|
|
3300
3636
|
)
|
|
@@ -3309,17 +3645,17 @@ var ImageEditor = ({
|
|
|
3309
3645
|
style: overlayMaxHeight > 0 ? { maxHeight: overlayMaxHeight } : void 0,
|
|
3310
3646
|
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { onKeyDown: handleEditorKeyDown, className: "flex min-h-0 flex-1 flex-col", children: [
|
|
3311
3647
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "flex shrink-0 items-center gap-2 border-b px-6 py-3", children: [
|
|
3312
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.ImageIcon, { className: "text-muted-foreground size-4" }),
|
|
3313
|
-
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: "text-sm font-medium", children: imageUrl ?
|
|
3648
|
+
acceptAnyFile ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.FileIcon, { className: "text-muted-foreground size-4" }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_lucide_react4.ImageIcon, { className: "text-muted-foreground size-4" }),
|
|
3649
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h3", { className: "text-sm font-medium", children: imageUrl ? `Edit ${Noun}` : `Add ${Noun}` })
|
|
3314
3650
|
] }),
|
|
3315
3651
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3316
3652
|
"input",
|
|
3317
3653
|
{
|
|
3318
3654
|
ref: fileInputRef,
|
|
3319
3655
|
type: "file",
|
|
3320
|
-
accept: "image/*",
|
|
3656
|
+
accept: acceptAnyFile ? void 0 : "image/*",
|
|
3321
3657
|
className: "hidden",
|
|
3322
|
-
"aria-label":
|
|
3658
|
+
"aria-label": `Upload ${noun}`,
|
|
3323
3659
|
tabIndex: -1,
|
|
3324
3660
|
onChange: (e) => {
|
|
3325
3661
|
const files = Array.from(e.target.files || []);
|
|
@@ -3393,6 +3729,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
|
3393
3729
|
var DRAFT_PREFIX = "draft:";
|
|
3394
3730
|
function ImageEditorDom({
|
|
3395
3731
|
value,
|
|
3732
|
+
cell,
|
|
3396
3733
|
colKey,
|
|
3397
3734
|
rowId,
|
|
3398
3735
|
tableName,
|
|
@@ -3402,6 +3739,8 @@ function ImageEditorDom({
|
|
|
3402
3739
|
onInvalidateData
|
|
3403
3740
|
}) {
|
|
3404
3741
|
const isDraftRow = rowId.startsWith(DRAFT_PREFIX);
|
|
3742
|
+
const cellType = cell.meta?.cellType;
|
|
3743
|
+
const acceptAnyFile = cellType != null && cellType !== "image";
|
|
3405
3744
|
const handleSaveComplete = onCommitPatch ? (saveData) => onCommitPatch({ [colKey]: saveData.imageData }) : void 0;
|
|
3406
3745
|
const handleSubmitDraft = isDraftRow && onSubmitDraftRow ? async () => {
|
|
3407
3746
|
const createdRow = await onSubmitDraftRow(rowId);
|
|
@@ -3411,6 +3750,7 @@ function ImageEditorDom({
|
|
|
3411
3750
|
ImageEditor,
|
|
3412
3751
|
{
|
|
3413
3752
|
value,
|
|
3753
|
+
acceptAnyFile,
|
|
3414
3754
|
onFinishedEditing: () => onCancel(),
|
|
3415
3755
|
tableName,
|
|
3416
3756
|
fieldName: colKey,
|
|
@@ -4007,9 +4347,9 @@ var import_react_query5 = require("@tanstack/react-query");
|
|
|
4007
4347
|
// src/hooks/use-sheets-table-cursor.ts
|
|
4008
4348
|
var import_react22 = require("react");
|
|
4009
4349
|
var import_react_query4 = require("@tanstack/react-query");
|
|
4010
|
-
var import_data11 = require("@constructive-io/data");
|
|
4011
4350
|
var import_data12 = require("@constructive-io/data");
|
|
4012
4351
|
var import_data13 = require("@constructive-io/data");
|
|
4352
|
+
var import_data14 = require("@constructive-io/data");
|
|
4013
4353
|
function useSheetsTableCursor(tableName, options = {}) {
|
|
4014
4354
|
const queryClient = (0, import_react_query4.useQueryClient)();
|
|
4015
4355
|
const { execute, scopeKey } = useSheetsContext();
|
|
@@ -4017,7 +4357,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4017
4357
|
const adapter = useSheetsAdapter();
|
|
4018
4358
|
const tables = (0, import_react22.useMemo)(() => {
|
|
4019
4359
|
if (!meta?._meta?.tables) return [];
|
|
4020
|
-
return meta._meta.tables.filter((candidate) => candidate != null).map((metaTable) => (0,
|
|
4360
|
+
return meta._meta.tables.filter((candidate) => candidate != null).map((metaTable) => (0, import_data12.cleanTable)(metaTable));
|
|
4021
4361
|
}, [meta]);
|
|
4022
4362
|
const table = (0, import_react22.useMemo)(
|
|
4023
4363
|
() => tables.find((candidate) => candidate.name === tableName) ?? null,
|
|
@@ -4049,7 +4389,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4049
4389
|
queryKey: sheetsQueryKeys.cursorTable(scopeKey, tableName, stableOptions),
|
|
4050
4390
|
queryFn: async ({ pageParam }) => {
|
|
4051
4391
|
if (!table) {
|
|
4052
|
-
throw
|
|
4392
|
+
throw import_data13.createError.notFound(`Table '${tableName}' not found`);
|
|
4053
4393
|
}
|
|
4054
4394
|
const cursor = pageParam;
|
|
4055
4395
|
const variableOptions = {
|
|
@@ -4072,7 +4412,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4072
4412
|
const validatedOrderByEnum = new Set(variables.orderBy ?? []);
|
|
4073
4413
|
const availableOrderByFields = new Set(table.fields.map((field) => field.name));
|
|
4074
4414
|
const validatedOrderBy = orderBy?.filter(
|
|
4075
|
-
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0,
|
|
4415
|
+
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0, import_data14.toOrderByEnumValue)(field, direction))
|
|
4076
4416
|
);
|
|
4077
4417
|
const res = await adapter.listRows(
|
|
4078
4418
|
{ table, allTables: tables, tableName },
|