layout sharing via url

[deploy]
This commit is contained in:
2023-07-08 23:19:58 +02:00
parent 3a167030da
commit 391c9d8837
7 changed files with 395 additions and 8 deletions

22
src/lib/share.ts Normal file
View File

@@ -0,0 +1,22 @@
import type {Action} from "svelte/action"
import {readonly, writable} from "svelte/store"
const setCanShare = writable(false)
export const canShare = readonly(setCanShare)
let shareCallback: ((event: Event) => void) | undefined
export function triggerShare(event: Event) {
shareCallback?.(event)
}
export const share: Action<Window, (event: Event) => void> = (node, callback: (event: Event) => void) => {
setCanShare.set(true)
shareCallback = callback
return {
destroy() {
setCanShare.set(false)
shareCallback = undefined
},
}
}