fix(web): share artifact files instead of URLs
This commit is contained in:
+17
-7
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user