|
| 1 | +<template> |
| 2 | + <DualSheet |
| 3 | + title="Embed Options" |
| 4 | + description="Embed one or more pipeline into your website." |
| 5 | + > |
| 6 | + <template #trigger> |
| 7 | + <slot /> |
| 8 | + </template> |
| 9 | + <template #center> |
| 10 | + <Card class="relative max-w-full resize overflow-auto rounded-md"> |
| 11 | + <div class="rounded-t-md bg-secondary p-2"> |
| 12 | + <CardTitle class="relative flex justify-between gap-2"> |
| 13 | + Preview |
| 14 | + <div |
| 15 | + class="absolute -bottom-1 right-0 font-mono text-xs text-muted-foreground" |
| 16 | + > |
| 17 | + {{ Math.ceil(size.width.value) }}x{{ |
| 18 | + Math.ceil(size.height.value) |
| 19 | + }} |
| 20 | + </div> |
| 21 | + </CardTitle> |
| 22 | + </div> |
| 23 | + <CardContent ref="frameContent" class="group p-0"> |
| 24 | + <DomExplorerFrame :state="_state" /> |
| 25 | + </CardContent> |
| 26 | + </Card> |
| 27 | + </template> |
| 28 | + <template #side> |
| 29 | + <div |
| 30 | + class="grid grid-flow-row auto-rows-[minmax(32px,auto)] grid-cols-[auto_1fr] gap-x-8" |
| 31 | + > |
| 32 | + <Label class="content-center"> Input </Label> |
| 33 | + <VisibilitySelect v-model="settings.input" /> |
| 34 | + <Label class="content-center"> Title Bar </Label> |
| 35 | + <VisibilitySelect v-model="settings.titleBar" /> |
| 36 | + <Label |
| 37 | + class="group col-span-full grid cursor-pointer grid-cols-[subgrid] content-center items-center" |
| 38 | + > |
| 39 | + Readonly |
| 40 | + <Checkbox |
| 41 | + id="readonly-check" |
| 42 | + v-model="settings.readonly" |
| 43 | + class="outline outline-1 outline-transparent transition-all group-hover:outline-blue-400" |
| 44 | + /> |
| 45 | + </Label> |
| 46 | + <h2 class="col-span-full pb-2 pt-4 text-lg font-light"> |
| 47 | + Pipes Options |
| 48 | + </h2> |
| 49 | + <Label |
| 50 | + class="group col-span-full grid cursor-pointer grid-cols-[subgrid] content-center items-center" |
| 51 | + > |
| 52 | + Title bar |
| 53 | + <Checkbox |
| 54 | + id="readonly-check" |
| 55 | + v-model="settings.pipe.titleBar" |
| 56 | + class="outline outline-1 outline-transparent transition-all group-hover:outline-blue-400" |
| 57 | + /> |
| 58 | + </Label> |
| 59 | + <Label |
| 60 | + class="group col-span-full grid cursor-pointer grid-cols-[subgrid] content-center items-center" |
| 61 | + > |
| 62 | + Settings button |
| 63 | + <Checkbox |
| 64 | + id="readonly-check" |
| 65 | + v-model="settings.pipe.settings" |
| 66 | + class="outline outline-1 outline-transparent transition-all group-hover:outline-blue-400" |
| 67 | + /> |
| 68 | + </Label> |
| 69 | + |
| 70 | + <Label |
| 71 | + class="group col-span-full grid cursor-pointer grid-cols-[subgrid] content-center items-center" |
| 72 | + > |
| 73 | + Render button |
| 74 | + <Checkbox |
| 75 | + id="readonly-check" |
| 76 | + v-model="settings.pipe.render" |
| 77 | + class="outline outline-1 outline-transparent transition-all group-hover:outline-blue-400" |
| 78 | + /> |
| 79 | + </Label> |
| 80 | + |
| 81 | + <Label |
| 82 | + class="group col-span-full grid cursor-pointer grid-cols-[subgrid] content-center items-center" |
| 83 | + > |
| 84 | + Skip button |
| 85 | + <Checkbox |
| 86 | + id="readonly-check" |
| 87 | + v-model="settings.pipe.skip" |
| 88 | + class="outline outline-1 outline-transparent transition-all group-hover:outline-blue-400" |
| 89 | + /> |
| 90 | + </Label> |
| 91 | + </div> |
| 92 | + |
| 93 | + <div class="flex flex-col gap-3 pb-4 pt-8"> |
| 94 | + <h2 class="col-span-full pb-2 pt-4 text-lg font-light">Code</h2> |
| 95 | + <Textarea |
| 96 | + :model-value="code" |
| 97 | + spellcheck="false" |
| 98 | + class="min-h-24 min-w-0 overflow-auto break-all font-mono" |
| 99 | + /> |
| 100 | + <div class="flex justify-between gap-4 pt-2"> |
| 101 | + <NuxtLink :to="url" target="_blank"> |
| 102 | + <Button label="Open in new tab" icon="externalLink" /> |
| 103 | + </NuxtLink> |
| 104 | + <CopyButton :value="code" icon="copy" no-tooltip label="Copy code" /> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </template> |
| 108 | + </DualSheet> |
| 109 | +</template> |
| 110 | + |
| 111 | +<script lang="ts" setup> |
| 112 | +import type { DomExplorerState } from "~/types"; |
| 113 | +
|
| 114 | +const props = defineProps<{ |
| 115 | + state: DomExplorerState; |
| 116 | +}>(); |
| 117 | +
|
| 118 | +const _state = ref(cloneState(props.state)); |
| 119 | +
|
| 120 | +watch( |
| 121 | + () => props.state, |
| 122 | + (state) => { |
| 123 | + _state.value = cloneState(state); |
| 124 | + }, |
| 125 | +); |
| 126 | +
|
| 127 | +const frameContent = ref(); |
| 128 | +const size = useElementBounding(frameContent); |
| 129 | +
|
| 130 | +const settings = createDomExplorerSettings({ |
| 131 | + input: "editable", |
| 132 | + titleBar: "readonly", |
| 133 | + readonly: true, |
| 134 | + pipe: { |
| 135 | + titleBar: true, |
| 136 | + settings: true, |
| 137 | + render: true, |
| 138 | + skip: true, |
| 139 | + }, |
| 140 | +}); |
| 141 | +
|
| 142 | +const url = computed(() => { |
| 143 | + return resolveRemoteLink({ |
| 144 | + name: "frame", |
| 145 | + hash: "#" + b64EncodeUnicode(JSON.stringify(_state.value)), |
| 146 | + query: { |
| 147 | + input: settings.input, |
| 148 | + titleBar: settings.titleBar, |
| 149 | + readonly: settings.readonly ? "true" : "false", |
| 150 | + "pipe[titleBar]": settings.pipe.titleBar ? "true" : "false", |
| 151 | + "pipe[settings]": settings.pipe.settings ? "true" : "false", |
| 152 | + "pipe[render]": settings.pipe.render ? "true" : "false", |
| 153 | + "pipe[skip]": settings.pipe.skip ? "true" : "false", |
| 154 | + }, |
| 155 | + }); |
| 156 | +}); |
| 157 | +
|
| 158 | +const code = computed(() => { |
| 159 | + const iframe = document.createElement("iframe"); |
| 160 | + iframe.sandbox.add("allow-scripts", "allow-modals", "allow-popups"); |
| 161 | + iframe.src = url.value; |
| 162 | + return iframe.outerHTML; |
| 163 | +}); |
| 164 | +</script> |
0 commit comments