fix(web): share artifact files instead of URLs

This commit is contained in:
2026-10-21 12:36:06 +01:00
parent 93be42b06e
commit 870c70aefa
10 changed files with 204 additions and 16 deletions
+17 -7
View File
@@ -3,6 +3,7 @@
// textContent, never innerHTML.
import { artifactBrowserLinkProps } from "./artifactNavigation.js";
import { canShareFiles, shareArtifactFile } from "./artifactSharing.js";
export { artifactBrowserLinkProps } from "./artifactNavigation.js";
export function h(tag, props = {}, ...children) {
@@ -49,9 +50,9 @@ export function canCopyLink() {
return typeof navigator !== "undefined" && Boolean(navigator.clipboard?.writeText);
}
/** Whether the Web Share API can be used for a share control. */
/** Whether the browser exposes file sharing (not just URL sharing). */
export function canShare() {
return typeof navigator !== "undefined" && typeof navigator.share === "function";
return canShareFiles();
}
export async function copyText(text) {
@@ -72,12 +73,21 @@ export async function copyArtifactLink(resolved) {
}
}
export async function shareArtifact(resolved) {
if (!resolved || !canShare()) return;
export async function shareArtifact(resolved, artifact, trigger) {
if (!trigger || trigger.getAttribute("aria-busy") === "true") return;
const host = trigger.closest(".artifact-tile-wrap, .artifact-list-row, .viewer-panel");
let status = host?.querySelector(".artifact-share-status");
if (!status && host) {
status = h("div", { class: "artifact-share-status muted", role: "status", "aria-live": "polite" });
host.append(status);
}
if (status) status.textContent = "Preparing file…";
trigger.setAttribute("aria-busy", "true");
try {
await navigator.share({ url: resolved });
} catch {
// The share chooser may be dismissed.
const result = await shareArtifactFile(resolved, artifact, trigger);
if (status && trigger.isConnected) status.textContent = result.message;
} finally {
trigger.removeAttribute("aria-busy");
}
}