@emberbox/ui 0.1.0 → 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.
Files changed (49) hide show
  1. package/README.md +9 -9
  2. package/dist/vite/logo.d.ts +3 -4
  3. package/dist/vite/logo.js +15 -16
  4. package/dist/vite/prerender.d.ts +17 -0
  5. package/dist/vite/prerender.js +57 -0
  6. package/dist/vite.d.ts +24 -24
  7. package/dist/vite.js +46 -46
  8. package/package.json +6 -6
  9. package/src/build-info.ts +23 -0
  10. package/src/clipboard.ts +34 -0
  11. package/src/components/AppFooter.vue +66 -0
  12. package/src/{komponenten/AppKopf.vue → components/AppHeader.vue} +13 -13
  13. package/src/components/CodeDisplay.vue +78 -0
  14. package/src/components/ConfirmDialog.vue +25 -0
  15. package/src/{komponenten → components}/EmberboxApp.vue +4 -4
  16. package/src/{komponenten/HilfeMockup.vue → components/HelpMockup.vue} +3 -3
  17. package/src/components/HelpPage.vue +16 -0
  18. package/src/components/HelpSection.vue +11 -0
  19. package/src/components/HelpTopic.vue +20 -0
  20. package/src/{komponenten/NeueFassung.vue → components/NewBuildBanner.vue} +8 -8
  21. package/src/composables/useConfirm.ts +27 -0
  22. package/src/composables/useNewBuild.ts +45 -0
  23. package/src/composables/usePolling.ts +55 -57
  24. package/src/create-app.ts +11 -0
  25. package/src/index.ts +22 -21
  26. package/src/page.ts +81 -0
  27. package/src/prerender.ts +23 -0
  28. package/src/{stil.css → style.css} +58 -58
  29. package/src/urls.ts +8 -0
  30. package/src/vite/logo.ts +16 -17
  31. package/src/vite/prerender.ts +72 -0
  32. package/src/vite.ts +55 -55
  33. package/dist/vite/vorrendern.d.ts +0 -17
  34. package/dist/vite/vorrendern.js +0 -57
  35. package/src/adressen.ts +0 -8
  36. package/src/app.ts +0 -11
  37. package/src/composables/useNeueFassung.ts +0 -45
  38. package/src/composables/useRueckfrage.ts +0 -27
  39. package/src/fassung.ts +0 -23
  40. package/src/komponenten/AppFuss.vue +0 -58
  41. package/src/komponenten/CodeAnzeige.vue +0 -79
  42. package/src/komponenten/HilfeAbschnitt.vue +0 -11
  43. package/src/komponenten/HilfeSeite.vue +0 -16
  44. package/src/komponenten/HilfeThema.vue +0 -20
  45. package/src/komponenten/Rueckfrage.vue +0 -24
  46. package/src/seite.ts +0 -81
  47. package/src/vite/vorrendern.ts +0 -72
  48. package/src/vorrendern.ts +0 -24
  49. package/src/zwischenablage.ts +0 -34
@@ -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>
@@ -2,11 +2,11 @@
2
2
  import UApp from '@nuxt/ui/components/App.vue'
3
3
  import {de} from '@nuxt/ui/locale'
4
4
  import {useHead} from '@unhead/vue'
5
- import NeueFassung from './NeueFassung.vue'
5
+ import NewBuildBanner from './NewBuildBanner.vue'
6
6
 
7
7
  /**
8
- * Der äußere Rahmen jedes Werkzeugs: Nuxt UI auf Deutsch, Platz für Meldungen, Tooltips und
9
- * Fenster, und der Hinweis auf einen neuen Build.
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
10
  */
11
11
  defineOptions({name: 'EmberboxApp'})
12
12
  useHead({htmlAttrs: {lang: 'de'}})
@@ -15,7 +15,7 @@ useHead({htmlAttrs: {lang: 'de'}})
15
15
  <template>
16
16
  <UApp :locale="de">
17
17
  <div class="flex min-h-screen flex-col">
18
- <NeueFassung/>
18
+ <NewBuildBanner/>
19
19
  <slot/>
20
20
  </div>
21
21
  </UApp>
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
- /** Ein Abbild eines Oberflächenteils in der Hilfe; es lässt sich weder anklicken noch fokussieren. */
3
- defineProps<{ beschriftung: string }>()
2
+ /** A replica of part of the interface in the help; it can be neither clicked nor focused. */
3
+ defineProps<{ caption: string }>()
4
4
  </script>
5
5
 
6
6
  <template>
@@ -10,6 +10,6 @@ defineProps<{ beschriftung: string }>()
10
10
  <slot/>
11
11
  </div>
12
12
  </div>
13
- <figcaption class="text-xs text-muted">{{ beschriftung }}</figcaption>
13
+ <figcaption class="text-xs text-muted">{{ caption }}</figcaption>
14
14
  </figure>
15
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>
@@ -1,24 +1,24 @@
1
1
  <script setup lang="ts">
2
2
  import UButton from '@nuxt/ui/components/Button.vue'
3
- import {useNeueFassung} from '../composables/useNeueFassung'
3
+ import {useNewBuild} from '../composables/useNewBuild'
4
4
 
5
5
  /**
6
- * Ein Hinweisband, sobald der Server einen neueren Build ausliefert, mit Knopf zum Neuladen.
7
- * `immer` zeigt es ohne Prüfung, etwa auf einer Musterseite.
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
8
  */
9
- const props = defineProps<{ immer?: boolean }>()
10
- const neu = props.immer ? true : useNeueFassung()
9
+ const props = defineProps<{ always?: boolean }>()
10
+ const newer = props.always ? true : useNewBuild()
11
11
 
12
- function neuLaden(): void {
12
+ function reload(): void {
13
13
  window.location.reload()
14
14
  }
15
15
  </script>
16
16
 
17
17
  <template>
18
- <div v-if="neu" role="status"
18
+ <div v-if="newer" role="status"
19
19
  class="flex flex-wrap items-center justify-center gap-3 bg-inverted px-4 py-2 text-sm font-semibold text-inverted">
20
20
  Eine neue Version ist da. Bitte neu laden, damit alles zusammenpasst.
21
21
  <UButton size="xs" color="neutral" variant="outline" icon="i-lucide-rotate-cw" label="Neu laden"
22
- class="bg-default text-default" @click="neuLaden"/>
22
+ class="bg-default text-default" @click="reload"/>
23
23
  </div>
24
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
+ }
@@ -1,93 +1,91 @@
1
1
  import {onBeforeUnmount, onMounted, ref} from 'vue'
2
2
 
3
- /** Wie ein Werkzeug den Server abfragt. */
4
- export interface PollingOptionen {
5
- /** Abstand zwischen zwei Abfragen, solange der Server antwortet. */
6
- intervallMs?: number
7
- /** Längster Abstand, auf den das Warten nach Fehlern anwächst. */
8
- hoechstensMs?: number
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
9
  }
10
10
 
11
11
  /**
12
- * Fragt regelmäßig ab, solange die Seite sichtbar ist. Scheitert eine Abfrage, verdoppelt sich der
13
- * Abstand bis `hoechstensMs`, damit ein ausgefallener Server nicht im Sekundentakt angefragt wird;
14
- * die erste gelungene Abfrage setzt ihn zurück. Ein verdeckter Tab fragt nicht, und beim
15
- * Zurückkehren wird sofort abgefragt.
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.
16
15
  *
17
- * Es läuft nie mehr als eine Abfrage zugleich, damit eine spät eintreffende ältere Antwort keine
18
- * neuere überschreibt. Wird während einer laufenden Abfrage erneut angestoßen, folgt genau eine
19
- * weitere, sobald sie fertig ist.
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.
20
18
  *
21
- * @param abfrage holt den Stand; ein Fehler gilt als verlorene Verbindung
22
- * @returns ob die letzte Abfrage gelang, und `jetzt`, das sofort neu abfragt
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
23
21
  */
24
- export function usePolling(abfrage: () => Promise<unknown>, optionen: PollingOptionen = {}) {
25
- const intervallMs = optionen.intervallMs ?? 2_000
26
- const hoechstensMs = optionen.hoechstensMs ?? 30_000
27
- const verbunden = ref(false)
28
- let abstand = intervallMs
29
- let zeitgeber: ReturnType<typeof setTimeout> | undefined
30
- let aktiv = false
31
- let laeuft = false
32
- let nochmal = false
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
33
31
 
34
- function planen(): void {
35
- clearTimeout(zeitgeber)
36
- if (aktiv && document.visibilityState === 'visible') {
37
- zeitgeber = setTimeout(() => void runde(), abstand)
32
+ function schedule(): void {
33
+ clearTimeout(timer)
34
+ if (active && document.visibilityState === 'visible') {
35
+ timer = setTimeout(() => void poll(), delay)
38
36
  }
39
37
  }
40
38
 
41
- async function runde(): Promise<void> {
42
- if (laeuft) {
43
- nochmal = true
39
+ async function poll(): Promise<void> {
40
+ if (running) {
41
+ again = true
44
42
  return
45
43
  }
46
- laeuft = true
47
- clearTimeout(zeitgeber)
44
+ running = true
45
+ clearTimeout(timer)
48
46
  try {
49
- await abfrage()
50
- verbunden.value = true
51
- abstand = intervallMs
47
+ await request()
48
+ connected.value = true
49
+ delay = intervalMs
52
50
  } catch {
53
- verbunden.value = false
54
- abstand = Math.min(abstand * 2, hoechstensMs)
51
+ connected.value = false
52
+ delay = Math.min(delay * 2, maxIntervalMs)
55
53
  } finally {
56
- laeuft = false
54
+ running = false
57
55
  }
58
- if (nochmal && aktiv) {
59
- nochmal = false
60
- void runde()
56
+ if (again && active) {
57
+ again = false
58
+ void poll()
61
59
  return
62
60
  }
63
- planen()
61
+ schedule()
64
62
  }
65
63
 
66
- function sichtbar(): void {
64
+ function onVisibilityChange(): void {
67
65
  if (document.visibilityState === 'visible') {
68
- void runde()
66
+ void poll()
69
67
  } else {
70
- clearTimeout(zeitgeber)
68
+ clearTimeout(timer)
71
69
  }
72
70
  }
73
71
 
74
- function jetzt(): void {
75
- abstand = intervallMs
76
- void runde()
72
+ function refresh(): void {
73
+ delay = intervalMs
74
+ void poll()
77
75
  }
78
76
 
79
77
  onMounted(() => {
80
- aktiv = true
81
- document.addEventListener('visibilitychange', sichtbar)
82
- void runde()
78
+ active = true
79
+ document.addEventListener('visibilitychange', onVisibilityChange)
80
+ void poll()
83
81
  })
84
82
 
85
83
  onBeforeUnmount(() => {
86
- aktiv = false
87
- nochmal = false
88
- clearTimeout(zeitgeber)
89
- document.removeEventListener('visibilitychange', sichtbar)
84
+ active = false
85
+ again = false
86
+ clearTimeout(timer)
87
+ document.removeEventListener('visibilitychange', onVisibilityChange)
90
88
  })
91
89
 
92
- return {verbunden, jetzt}
90
+ return {connected, refresh}
93
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 CHANGED
@@ -2,32 +2,33 @@ import {_api} from '@iconify/vue'
2
2
  import nuxtUi from '@nuxt/ui/vue-plugin'
3
3
  import type {App} from 'vue'
4
4
 
5
- export {HUB_URL, IMPRESSUM_URL, DATENSCHUTZ_URL} from './adressen'
6
- export {fassung, gebautLesbar} from './fassung'
7
- export {appErzeugen} from './app'
8
- export {ADRESSE, useSeite, werkzeugDaten, type SeitenAngaben, type WerkzeugAngaben} from './seite'
9
- export {useNeueFassung} from './composables/useNeueFassung'
10
- export {usePolling, type PollingOptionen} from './composables/usePolling'
11
- export {useRueckfrage, type RueckfrageOptionen} from './composables/useRueckfrage'
12
- export {default as EmberboxApp} from './komponenten/EmberboxApp.vue'
13
- export {default as AppKopf} from './komponenten/AppKopf.vue'
14
- export {default as AppFuss} from './komponenten/AppFuss.vue'
15
- export {default as NeueFassung} from './komponenten/NeueFassung.vue'
16
- export {default as CodeAnzeige} from './komponenten/CodeAnzeige.vue'
17
- export {default as Rueckfrage} from './komponenten/Rueckfrage.vue'
18
- export {default as HilfeSeite} from './komponenten/HilfeSeite.vue'
19
- export {default as HilfeAbschnitt} from './komponenten/HilfeAbschnitt.vue'
20
- export {default as HilfeThema} from './komponenten/HilfeThema.vue'
21
- export {default as HilfeMockup} from './komponenten/HilfeMockup.vue'
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'
22
23
 
23
24
  /**
24
- * Vue-Plugin, das Nuxt UI im Emberbox-Stil in eine App einhängt. Icons kommen ausschließlich aus
25
- * dem gebündelten Satz; ein fehlendes Icon bleibt leer, statt bei der Iconify-API nachgeladen zu
26
- * werden, damit kein Besuch eines Werkzeugs bei einem Dritten landet.
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.
27
28
  */
28
29
  export const emberboxUi = {
29
30
  install(app: App) {
30
- _api.setFetch(() => Promise.reject(new Error('Icons werden nicht nachgeladen.')))
31
+ _api.setFetch(() => Promise.reject(new Error('Icons are not fetched at runtime.')))
31
32
  app.use(nuxtUi)
32
33
  },
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
+ }
@@ -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
+ }