@emberbox/ui 0.0.0-stage → 0.2.0
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/LICENSE +44 -0
- package/README.md +17 -2
- package/dist/vite/logo.d.ts +8 -0
- package/dist/vite/logo.js +43 -0
- package/dist/vite/prerender.d.ts +17 -0
- package/dist/vite/prerender.js +57 -0
- package/dist/vite.d.ts +39 -0
- package/dist/vite.js +121 -0
- package/logos/alarmzettel-180.png +0 -0
- package/logos/alarmzettel-512.png +0 -0
- package/logos/alarmzettel.svg +1 -0
- package/logos/calltaker-180.png +0 -0
- package/logos/calltaker-512.png +0 -0
- package/logos/calltaker.svg +1 -0
- package/logos/emberbox-180.png +0 -0
- package/logos/emberbox-512.png +0 -0
- package/logos/emberbox.svg +1 -0
- package/logos/statussim-180.png +0 -0
- package/logos/statussim-512.png +0 -0
- package/logos/statussim.svg +1 -0
- package/package.json +62 -4
- package/src/build-info.ts +23 -0
- package/src/clipboard.ts +34 -0
- package/src/components/AppFooter.vue +66 -0
- package/src/components/AppHeader.vue +45 -0
- package/src/components/CodeDisplay.vue +78 -0
- package/src/components/ConfirmDialog.vue +25 -0
- package/src/components/EmberboxApp.vue +22 -0
- package/src/components/HelpMockup.vue +15 -0
- package/src/components/HelpPage.vue +16 -0
- package/src/components/HelpSection.vue +11 -0
- package/src/components/HelpTopic.vue +20 -0
- package/src/components/NewBuildBanner.vue +24 -0
- package/src/composables/useConfirm.ts +27 -0
- package/src/composables/useNewBuild.ts +45 -0
- package/src/composables/usePolling.ts +91 -0
- package/src/create-app.ts +11 -0
- package/src/index.ts +34 -0
- package/src/page.ts +81 -0
- package/src/prerender.ts +23 -0
- package/src/style.css +172 -0
- package/src/urls.ts +8 -0
- package/src/vite/logo.ts +49 -0
- package/src/vite/prerender.ts +72 -0
- package/src/vite.ts +145 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import UPopover from '@nuxt/ui/components/Popover.vue'
|
|
4
|
+
import UTooltip from '@nuxt/ui/components/Tooltip.vue'
|
|
5
|
+
import {renderSVG} from 'uqr'
|
|
6
|
+
import {computed, onBeforeUnmount, ref} from 'vue'
|
|
7
|
+
import {copyToClipboard} from '../clipboard'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A join code, large and copyable. With `link`, the address that joins with the code directly can
|
|
11
|
+
* be copied too, and `qr` shows it as a QR code. `hidden` keeps the code blurred until it is held
|
|
12
|
+
* down or focused with the keyboard, so it cannot be read along on a shared screen.
|
|
13
|
+
*/
|
|
14
|
+
const props = defineProps<{
|
|
15
|
+
title: string
|
|
16
|
+
code: string
|
|
17
|
+
link?: string
|
|
18
|
+
qr?: boolean
|
|
19
|
+
hidden?: boolean
|
|
20
|
+
}>()
|
|
21
|
+
|
|
22
|
+
const FEEDBACK_MS = 1500
|
|
23
|
+
|
|
24
|
+
const revealed = ref(false)
|
|
25
|
+
const result = ref<{ what: 'code' | 'link', succeeded: boolean } | null>(null)
|
|
26
|
+
const qrImage = computed(() => renderSVG(props.link ?? props.code, {border: 1}))
|
|
27
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
28
|
+
|
|
29
|
+
const message = computed(() => result.value === null
|
|
30
|
+
? ''
|
|
31
|
+
: result.value.succeeded ? 'Kopiert' : 'Kopieren fehlgeschlagen')
|
|
32
|
+
|
|
33
|
+
function icon(what: 'code' | 'link', idle: string): string {
|
|
34
|
+
if (result.value?.what !== what) return idle
|
|
35
|
+
return result.value.succeeded ? 'i-lucide-check' : 'i-lucide-x'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function copy(what: 'code' | 'link'): Promise<void> {
|
|
39
|
+
const succeeded = await copyToClipboard(what === 'link' && props.link ? props.link : props.code)
|
|
40
|
+
result.value = {what, succeeded}
|
|
41
|
+
clearTimeout(timer)
|
|
42
|
+
timer = setTimeout(() => {
|
|
43
|
+
result.value = null
|
|
44
|
+
}, FEEDBACK_MS)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
onBeforeUnmount(() => clearTimeout(timer))
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div class="inline-flex flex-col gap-1">
|
|
52
|
+
<span class="field-label">{{ title }}</span>
|
|
53
|
+
<div class="inline-flex items-center gap-1 rounded-sm border border-default bg-default py-1 pl-3 pr-1">
|
|
54
|
+
<span class="tabular select-all text-lg font-medium transition-[filter]"
|
|
55
|
+
:class="hidden && !revealed ? 'blur-sm' : ''"
|
|
56
|
+
:tabindex="hidden ? 0 : undefined"
|
|
57
|
+
:aria-label="hidden ? `${title}: ${code}` : undefined"
|
|
58
|
+
@pointerdown="revealed = true" @pointerup="revealed = false" @pointerleave="revealed = false"
|
|
59
|
+
@focus="revealed = true" @blur="revealed = false">{{ code }}</span>
|
|
60
|
+
<UTooltip :text="result?.what === 'code' ? message : 'Code kopieren'">
|
|
61
|
+
<UButton :icon="icon('code', 'i-lucide-copy')" color="neutral" variant="ghost" size="sm"
|
|
62
|
+
:aria-label="`Code ${title} kopieren`" @click="copy('code')"/>
|
|
63
|
+
</UTooltip>
|
|
64
|
+
<UTooltip v-if="link" :text="result?.what === 'link' ? message : 'Link kopieren'">
|
|
65
|
+
<UButton :icon="icon('link', 'i-lucide-link')" color="neutral" variant="ghost" size="sm"
|
|
66
|
+
:aria-label="`Link für ${title} kopieren`" @click="copy('link')"/>
|
|
67
|
+
</UTooltip>
|
|
68
|
+
<UPopover v-if="qr">
|
|
69
|
+
<UButton icon="i-lucide-qr-code" color="neutral" variant="ghost" size="sm" :aria-label="`QR-Code für ${title}`"/>
|
|
70
|
+
<template #content>
|
|
71
|
+
<div class="size-56 bg-white p-2 text-black [&>svg]:size-full" role="img" :aria-label="`QR-Code für ${title}`"
|
|
72
|
+
v-html="qrImage"/>
|
|
73
|
+
</template>
|
|
74
|
+
</UPopover>
|
|
75
|
+
<span class="sr-only" role="status">{{ message }}</span>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</template>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import UModal from '@nuxt/ui/components/Modal.vue'
|
|
4
|
+
|
|
5
|
+
/** The content of a confirmation dialog; open it through `useConfirm`. */
|
|
6
|
+
defineProps<{
|
|
7
|
+
question: string
|
|
8
|
+
description?: string
|
|
9
|
+
confirmLabel?: string
|
|
10
|
+
danger?: boolean
|
|
11
|
+
}>()
|
|
12
|
+
const emit = defineEmits<{ close: [confirmed: boolean] }>()
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<UModal :title="question" :description="description" :dismissible="true"
|
|
17
|
+
@update:open="(open: boolean) => !open && emit('close', false)">
|
|
18
|
+
<template #footer>
|
|
19
|
+
<div class="flex w-full justify-end gap-2">
|
|
20
|
+
<UButton color="neutral" variant="outline" label="Abbrechen" @click="emit('close', false)"/>
|
|
21
|
+
<UButton :color="danger ? 'signal' : 'primary'" :label="confirmLabel ?? 'Weiter'" @click="emit('close', true)"/>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
</UModal>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UApp from '@nuxt/ui/components/App.vue'
|
|
3
|
+
import {de} from '@nuxt/ui/locale'
|
|
4
|
+
import {useHead} from '@unhead/vue'
|
|
5
|
+
import NewBuildBanner from './NewBuildBanner.vue'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The outer frame of every tool: Nuxt UI in German, room for toasts, tooltips and dialogs, and the
|
|
9
|
+
* notice about a newer build.
|
|
10
|
+
*/
|
|
11
|
+
defineOptions({name: 'EmberboxApp'})
|
|
12
|
+
useHead({htmlAttrs: {lang: 'de'}})
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<UApp :locale="de">
|
|
17
|
+
<div class="flex min-h-screen flex-col">
|
|
18
|
+
<NewBuildBanner/>
|
|
19
|
+
<slot/>
|
|
20
|
+
</div>
|
|
21
|
+
</UApp>
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/** A replica of part of the interface in the help; it can be neither clicked nor focused. */
|
|
3
|
+
defineProps<{ caption: string }>()
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<figure class="m-0 flex flex-col gap-1.5">
|
|
8
|
+
<div class="overflow-x-auto rounded-sm border border-dashed border-accented bg-muted">
|
|
9
|
+
<div inert class="pointer-events-none min-w-[36rem] select-none p-3">
|
|
10
|
+
<slot/>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<figcaption class="text-xs text-muted">{{ caption }}</figcaption>
|
|
14
|
+
</figure>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import ULink from '@nuxt/ui/components/Link.vue'
|
|
3
|
+
|
|
4
|
+
/** The frame of a help page: title, a way back and the sections below. */
|
|
5
|
+
withDefaults(defineProps<{ title: string, back?: string }>(), {back: '/'})
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<main class="mx-auto flex w-full max-w-4xl flex-col gap-6 p-5">
|
|
10
|
+
<header class="flex flex-col items-center gap-1 text-center">
|
|
11
|
+
<h1 class="headline m-0 text-3xl">{{ title }}</h1>
|
|
12
|
+
<ULink :to="back" class="text-sm underline">Zurück</ULink>
|
|
13
|
+
</header>
|
|
14
|
+
<slot/>
|
|
15
|
+
</main>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/** A section of the help with a heading that groups several topics. */
|
|
3
|
+
defineProps<{ title: string }>()
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<section :aria-label="title" class="flex flex-col gap-4 rounded-sm border border-default bg-default p-5">
|
|
8
|
+
<h2 class="headline m-0 text-xl">{{ title }}</h2>
|
|
9
|
+
<slot/>
|
|
10
|
+
</section>
|
|
11
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import HelpMockup from './HelpMockup.vue'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A help topic: paragraphs and, optionally, a non-interactive replica of the interface below them
|
|
6
|
+
* (the default slot), captioned with `mockup`.
|
|
7
|
+
*/
|
|
8
|
+
defineProps<{ title?: string, paragraphs: string[], mockup?: string }>()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<div class="flex flex-col gap-2">
|
|
13
|
+
<h3 v-if="title" class="m-0 text-base font-semibold text-highlighted">{{ title }}</h3>
|
|
14
|
+
<p v-for="paragraph in paragraphs" :key="paragraph" class="m-0 leading-relaxed text-muted">{{ paragraph }}</p>
|
|
15
|
+
<slot name="content"/>
|
|
16
|
+
<HelpMockup v-if="mockup" :caption="mockup">
|
|
17
|
+
<slot/>
|
|
18
|
+
</HelpMockup>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
|
+
import {useNewBuild} from '../composables/useNewBuild'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A banner shown as soon as the server serves a newer build, with a button to reload. `always`
|
|
7
|
+
* shows it without checking, for example on a pattern page.
|
|
8
|
+
*/
|
|
9
|
+
const props = defineProps<{ always?: boolean }>()
|
|
10
|
+
const newer = props.always ? true : useNewBuild()
|
|
11
|
+
|
|
12
|
+
function reload(): void {
|
|
13
|
+
window.location.reload()
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<div v-if="newer" role="status"
|
|
19
|
+
class="flex flex-wrap items-center justify-center gap-3 bg-inverted px-4 py-2 text-sm font-semibold text-inverted">
|
|
20
|
+
Eine neue Version ist da. Bitte neu laden, damit alles zusammenpasst.
|
|
21
|
+
<UButton size="xs" color="neutral" variant="outline" icon="i-lucide-rotate-cw" label="Neu laden"
|
|
22
|
+
class="bg-default text-default" @click="reload"/>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {useOverlay} from '@nuxt/ui/composables'
|
|
2
|
+
import ConfirmDialog from '../components/ConfirmDialog.vue'
|
|
3
|
+
|
|
4
|
+
/** What a confirmation shows besides the question itself. */
|
|
5
|
+
export interface ConfirmOptions {
|
|
6
|
+
/** A sentence below the question, such as what the action does. */
|
|
7
|
+
description?: string
|
|
8
|
+
/** The label of the confirming button. */
|
|
9
|
+
confirmLabel?: string
|
|
10
|
+
/** Whether the action destroys something; the button then shows in signal red. */
|
|
11
|
+
danger?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An in-page confirmation instead of `window.confirm`, which blocks the whole page and with it
|
|
16
|
+
* every running request. Call it in the `setup` of a component inside `EmberboxApp`. Every
|
|
17
|
+
* confirmation creates its own dialog and removes it after closing.
|
|
18
|
+
*
|
|
19
|
+
* @returns a function that opens the confirmation and resolves to `true` when confirmed
|
|
20
|
+
*/
|
|
21
|
+
export function useConfirm() {
|
|
22
|
+
const overlay = useOverlay()
|
|
23
|
+
return async (question: string, options: ConfirmOptions = {}): Promise<boolean> => {
|
|
24
|
+
const dialog = overlay.create(ConfirmDialog, {destroyOnClose: true})
|
|
25
|
+
return Boolean(await dialog.open({question, ...options}).result)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {onBeforeUnmount, onMounted, ref} from 'vue'
|
|
2
|
+
import {buildInfo} from '../build-info'
|
|
3
|
+
|
|
4
|
+
/** How often an open page asks which build the server serves. */
|
|
5
|
+
export const CHECK_INTERVAL_MS = 60_000
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whether the server serves a newer build than the one this page runs. The page asks for the
|
|
9
|
+
* `build.json` that `emberbox()` puts next to every build, now and then and whenever it comes back
|
|
10
|
+
* into view. A page left open across a deployment would otherwise keep running the old frontend
|
|
11
|
+
* against the new server.
|
|
12
|
+
*/
|
|
13
|
+
export function useNewBuild() {
|
|
14
|
+
const newer = ref(false)
|
|
15
|
+
let timer: ReturnType<typeof setInterval> | undefined
|
|
16
|
+
|
|
17
|
+
async function check(): Promise<void> {
|
|
18
|
+
if (newer.value) return
|
|
19
|
+
try {
|
|
20
|
+
const response = await fetch('/build.json', {cache: 'no-store'})
|
|
21
|
+
if (!response.ok) return
|
|
22
|
+
const {builtAt} = await response.json() as {builtAt?: string}
|
|
23
|
+
newer.value = Boolean(builtAt) && builtAt !== buildInfo.builtAt
|
|
24
|
+
} catch {
|
|
25
|
+
newer.value = false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function onVisibilityChange(): void {
|
|
30
|
+
if (document.visibilityState === 'visible') void check()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
onMounted(() => {
|
|
34
|
+
timer = setInterval(() => void check(), CHECK_INTERVAL_MS)
|
|
35
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
36
|
+
void check()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
onBeforeUnmount(() => {
|
|
40
|
+
clearInterval(timer)
|
|
41
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return newer
|
|
45
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {onBeforeUnmount, onMounted, ref} from 'vue'
|
|
2
|
+
|
|
3
|
+
/** How a tool polls the server. */
|
|
4
|
+
export interface PollingOptions {
|
|
5
|
+
/** Delay between two requests while the server answers. */
|
|
6
|
+
intervalMs?: number
|
|
7
|
+
/** Longest delay the wait grows to after failures. */
|
|
8
|
+
maxIntervalMs?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Polls regularly while the page is visible. When a request fails, the delay doubles up to
|
|
13
|
+
* `maxIntervalMs`, so a server that is down is not hit every second; the first successful request
|
|
14
|
+
* resets it. A hidden tab does not poll, and coming back polls at once.
|
|
15
|
+
*
|
|
16
|
+
* Never more than one request runs at a time, so a late older answer cannot overwrite a newer one.
|
|
17
|
+
* A trigger during a running request queues exactly one more request after it.
|
|
18
|
+
*
|
|
19
|
+
* @param request fetches the state; an error counts as a lost connection
|
|
20
|
+
* @returns whether the last request succeeded, and `refresh`, which polls immediately
|
|
21
|
+
*/
|
|
22
|
+
export function usePolling(request: () => Promise<unknown>, options: PollingOptions = {}) {
|
|
23
|
+
const intervalMs = options.intervalMs ?? 2_000
|
|
24
|
+
const maxIntervalMs = options.maxIntervalMs ?? 30_000
|
|
25
|
+
const connected = ref(false)
|
|
26
|
+
let delay = intervalMs
|
|
27
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
28
|
+
let active = false
|
|
29
|
+
let running = false
|
|
30
|
+
let again = false
|
|
31
|
+
|
|
32
|
+
function schedule(): void {
|
|
33
|
+
clearTimeout(timer)
|
|
34
|
+
if (active && document.visibilityState === 'visible') {
|
|
35
|
+
timer = setTimeout(() => void poll(), delay)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function poll(): Promise<void> {
|
|
40
|
+
if (running) {
|
|
41
|
+
again = true
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
running = true
|
|
45
|
+
clearTimeout(timer)
|
|
46
|
+
try {
|
|
47
|
+
await request()
|
|
48
|
+
connected.value = true
|
|
49
|
+
delay = intervalMs
|
|
50
|
+
} catch {
|
|
51
|
+
connected.value = false
|
|
52
|
+
delay = Math.min(delay * 2, maxIntervalMs)
|
|
53
|
+
} finally {
|
|
54
|
+
running = false
|
|
55
|
+
}
|
|
56
|
+
if (again && active) {
|
|
57
|
+
again = false
|
|
58
|
+
void poll()
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
schedule()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function onVisibilityChange(): void {
|
|
65
|
+
if (document.visibilityState === 'visible') {
|
|
66
|
+
void poll()
|
|
67
|
+
} else {
|
|
68
|
+
clearTimeout(timer)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function refresh(): void {
|
|
73
|
+
delay = intervalMs
|
|
74
|
+
void poll()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onMounted(() => {
|
|
78
|
+
active = true
|
|
79
|
+
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
80
|
+
void poll()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
onBeforeUnmount(() => {
|
|
84
|
+
active = false
|
|
85
|
+
again = false
|
|
86
|
+
clearTimeout(timer)
|
|
87
|
+
document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return {connected, refresh}
|
|
91
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {type Component, createApp, createSSRApp} from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a tool's app in the browser. On a prerendered page Vue takes over the existing HTML
|
|
5
|
+
* (hydration), otherwise it builds the page from scratch. Wait for `router.isReady()` before
|
|
6
|
+
* `mount`, so hydration hits the same page.
|
|
7
|
+
*/
|
|
8
|
+
export function createToolApp(root: Component) {
|
|
9
|
+
const prerendered = (document.getElementById('app')?.childElementCount ?? 0) > 0
|
|
10
|
+
return prerendered ? createSSRApp(root) : createApp(root)
|
|
11
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {_api} from '@iconify/vue'
|
|
2
|
+
import nuxtUi from '@nuxt/ui/vue-plugin'
|
|
3
|
+
import type {App} from 'vue'
|
|
4
|
+
|
|
5
|
+
export {HUB_URL, IMPRINT_URL, PRIVACY_URL} from './urls'
|
|
6
|
+
export {buildInfo, formatBuiltAt} from './build-info'
|
|
7
|
+
export {createToolApp} from './create-app'
|
|
8
|
+
export {copyToClipboard} from './clipboard'
|
|
9
|
+
export {SITE_URL, usePage, webApplicationData, type PageMeta, type WebApplicationInfo} from './page'
|
|
10
|
+
export {useNewBuild} from './composables/useNewBuild'
|
|
11
|
+
export {usePolling, type PollingOptions} from './composables/usePolling'
|
|
12
|
+
export {useConfirm, type ConfirmOptions} from './composables/useConfirm'
|
|
13
|
+
export {default as EmberboxApp} from './components/EmberboxApp.vue'
|
|
14
|
+
export {default as AppHeader} from './components/AppHeader.vue'
|
|
15
|
+
export {default as AppFooter} from './components/AppFooter.vue'
|
|
16
|
+
export {default as NewBuildBanner} from './components/NewBuildBanner.vue'
|
|
17
|
+
export {default as CodeDisplay} from './components/CodeDisplay.vue'
|
|
18
|
+
export {default as ConfirmDialog} from './components/ConfirmDialog.vue'
|
|
19
|
+
export {default as HelpPage} from './components/HelpPage.vue'
|
|
20
|
+
export {default as HelpSection} from './components/HelpSection.vue'
|
|
21
|
+
export {default as HelpTopic} from './components/HelpTopic.vue'
|
|
22
|
+
export {default as HelpMockup} from './components/HelpMockup.vue'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Vue plugin that installs Nuxt UI in the Emberbox style. Icons come only from the bundled set; a
|
|
26
|
+
* missing icon stays empty instead of being fetched from the Iconify API, so no visit to a tool
|
|
27
|
+
* reaches a third party.
|
|
28
|
+
*/
|
|
29
|
+
export const emberboxUi = {
|
|
30
|
+
install(app: App) {
|
|
31
|
+
_api.setFetch(() => Promise.reject(new Error('Icons are not fetched at runtime.')))
|
|
32
|
+
app.use(nuxtUi)
|
|
33
|
+
},
|
|
34
|
+
}
|
package/src/page.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {useHead, useSeoMeta} from '@unhead/vue'
|
|
2
|
+
|
|
3
|
+
declare const __EMBERBOX_URL__: string | undefined
|
|
4
|
+
declare const __EMBERBOX_IMAGE__: string | undefined
|
|
5
|
+
|
|
6
|
+
/** The tool's public address, as `emberbox({url})` sets it at build time. */
|
|
7
|
+
export const SITE_URL = typeof __EMBERBOX_URL__ === 'string' ? __EMBERBOX_URL__ : ''
|
|
8
|
+
|
|
9
|
+
/** The preview image when a page names none: the tool's logo from `emberbox({logo})`. */
|
|
10
|
+
const DEFAULT_IMAGE = typeof __EMBERBOX_IMAGE__ === 'string' ? __EMBERBOX_IMAGE__ : ''
|
|
11
|
+
|
|
12
|
+
/** What search engines and link previews learn about a page. */
|
|
13
|
+
export interface PageMeta {
|
|
14
|
+
/** The full title as it appears in the tab and in search results. */
|
|
15
|
+
title: string
|
|
16
|
+
/** One or two sentences for search results and previews. */
|
|
17
|
+
description: string
|
|
18
|
+
/** The page's path; together with `url` it becomes the canonical address. */
|
|
19
|
+
path?: string
|
|
20
|
+
/** `false` for pages that do not belong in search results, such as exercises with a code. */
|
|
21
|
+
index?: boolean
|
|
22
|
+
/** Preview image as an absolute address or a path below `url`; the logo otherwise. */
|
|
23
|
+
image?: string
|
|
24
|
+
/** Structured data (JSON-LD), for example from `webApplicationData`. */
|
|
25
|
+
structuredData?: object[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function absolute(path: string): string {
|
|
29
|
+
return /^https?:\/\//.test(path) ? path : `${SITE_URL}${path}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sets a page's title, description, canonical address, OpenGraph and Twitter tags, `robots` and
|
|
34
|
+
* structured data. Works the same in the browser and when prerendering.
|
|
35
|
+
*/
|
|
36
|
+
export function usePage(meta: PageMeta): void {
|
|
37
|
+
const index = meta.index ?? true
|
|
38
|
+
const url = meta.path !== undefined && SITE_URL ? absolute(meta.path) : undefined
|
|
39
|
+
const imageSource = meta.image ?? DEFAULT_IMAGE
|
|
40
|
+
const image = imageSource && SITE_URL ? absolute(imageSource) : undefined
|
|
41
|
+
useHead({
|
|
42
|
+
title: meta.title,
|
|
43
|
+
link: url ? [{rel: 'canonical', href: url}] : [],
|
|
44
|
+
script: (meta.structuredData ?? []).map(data => ({type: 'application/ld+json', innerHTML: JSON.stringify(data)})),
|
|
45
|
+
})
|
|
46
|
+
useSeoMeta({
|
|
47
|
+
description: meta.description,
|
|
48
|
+
robots: index ? 'index, follow' : 'noindex, nofollow',
|
|
49
|
+
ogType: 'website',
|
|
50
|
+
ogLocale: 'de_DE',
|
|
51
|
+
ogSiteName: 'Emberbox',
|
|
52
|
+
ogTitle: meta.title,
|
|
53
|
+
ogDescription: meta.description,
|
|
54
|
+
ogUrl: url,
|
|
55
|
+
ogImage: image,
|
|
56
|
+
twitterCard: meta.image ? 'summary_large_image' : 'summary',
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** What a tool states about itself as a web application. */
|
|
61
|
+
export interface WebApplicationInfo {
|
|
62
|
+
name: string
|
|
63
|
+
description: string
|
|
64
|
+
url?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Structured data (schema.org `WebApplication`) for a tool's start page. */
|
|
68
|
+
export function webApplicationData(info: WebApplicationInfo): object {
|
|
69
|
+
return {
|
|
70
|
+
'@context': 'https://schema.org',
|
|
71
|
+
'@type': 'WebApplication',
|
|
72
|
+
name: info.name,
|
|
73
|
+
description: info.description,
|
|
74
|
+
url: info.url ?? (SITE_URL || undefined),
|
|
75
|
+
applicationCategory: 'EducationalApplication',
|
|
76
|
+
operatingSystem: 'Web',
|
|
77
|
+
inLanguage: 'de',
|
|
78
|
+
isAccessibleForFree: true,
|
|
79
|
+
offers: {'@type': 'Offer', price: '0', priceCurrency: 'EUR'},
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/prerender.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {createHead, transformHtmlTemplate} from '@unhead/vue/server'
|
|
2
|
+
import type {App} from 'vue'
|
|
3
|
+
import {renderToString} from 'vue/server-renderer'
|
|
4
|
+
import {emberboxUi} from './index'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders a fully set up app (router on the path, data loaded) to a complete HTML page. Installs
|
|
8
|
+
* head management and Nuxt UI itself, so the app must not use `emberboxUi` yet. The content goes
|
|
9
|
+
* into the template's `<div id="app">`, title and meta tags into its head.
|
|
10
|
+
*
|
|
11
|
+
* @param app the app created with `createSSRApp`
|
|
12
|
+
* @param template the tool's built `index.html`
|
|
13
|
+
* @returns the prerendered page
|
|
14
|
+
*/
|
|
15
|
+
export async function renderPage(app: App, template: string): Promise<string> {
|
|
16
|
+
const head = createHead({disableDefaults: true})
|
|
17
|
+
app.use(head)
|
|
18
|
+
app.use(emberboxUi)
|
|
19
|
+
const content = await renderToString(app)
|
|
20
|
+
const page = template.replace('<div id="app"></div>', `<div id="app">${content}</div>`)
|
|
21
|
+
if (page === template) throw new Error('The template has no empty <div id="app"></div>.')
|
|
22
|
+
return transformHtmlTemplate(head, page)
|
|
23
|
+
}
|