@emberbox/ui 0.1.0 → 0.3.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 (55) 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 +48 -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/CollapsibleSection.vue +75 -0
  15. package/src/components/ComboboxField.vue +132 -0
  16. package/src/components/ConfirmDialog.vue +25 -0
  17. package/src/components/DateTimeField.vue +47 -0
  18. package/src/{komponenten → components}/EmberboxApp.vue +4 -4
  19. package/src/{komponenten/HilfeMockup.vue → components/HelpMockup.vue} +3 -3
  20. package/src/components/HelpPage.vue +16 -0
  21. package/src/components/HelpSection.vue +11 -0
  22. package/src/components/HelpTopic.vue +20 -0
  23. package/src/{komponenten/NeueFassung.vue → components/NewBuildBanner.vue} +8 -8
  24. package/src/components/TextAreaField.vue +14 -0
  25. package/src/components/TextField.vue +29 -0
  26. package/src/components/YesNoField.vue +47 -0
  27. package/src/composables/useConfirm.ts +27 -0
  28. package/src/composables/useNewBuild.ts +45 -0
  29. package/src/composables/usePolling.ts +55 -57
  30. package/src/create-app.ts +11 -0
  31. package/src/index.ts +28 -21
  32. package/src/page.ts +81 -0
  33. package/src/prerender.ts +23 -0
  34. package/src/{stil.css → style.css} +67 -58
  35. package/src/urls.ts +8 -0
  36. package/src/vite/logo.ts +16 -17
  37. package/src/vite/prerender.ts +72 -0
  38. package/src/vite.ts +57 -55
  39. package/dist/vite/vorrendern.d.ts +0 -17
  40. package/dist/vite/vorrendern.js +0 -57
  41. package/src/adressen.ts +0 -8
  42. package/src/app.ts +0 -11
  43. package/src/composables/useNeueFassung.ts +0 -45
  44. package/src/composables/useRueckfrage.ts +0 -27
  45. package/src/fassung.ts +0 -23
  46. package/src/komponenten/AppFuss.vue +0 -58
  47. package/src/komponenten/CodeAnzeige.vue +0 -79
  48. package/src/komponenten/HilfeAbschnitt.vue +0 -11
  49. package/src/komponenten/HilfeSeite.vue +0 -16
  50. package/src/komponenten/HilfeThema.vue +0 -20
  51. package/src/komponenten/Rueckfrage.vue +0 -24
  52. package/src/seite.ts +0 -81
  53. package/src/vite/vorrendern.ts +0 -72
  54. package/src/vorrendern.ts +0 -24
  55. 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,75 @@
1
+ <script setup lang="ts">
2
+ import UCard from '@nuxt/ui/components/Card.vue'
3
+ import UIcon from '@nuxt/ui/components/Icon.vue'
4
+ import {onMounted, ref, useId, watch} from 'vue'
5
+
6
+ /**
7
+ * A section that can be collapsed. With many lists open at once a page is something to scroll
8
+ * through rather than read. The browser remembers what was open, under `name` in the object stored
9
+ * at `storageKey`, so all sections of a tool share one entry. The remembered state is applied after
10
+ * mounting, so prerendered pages hydrate with `defaultOpen` first.
11
+ */
12
+ const {
13
+ name, title, count, icon, defaultOpen = false, storageKey = 'emberbox_sections', level = 2,
14
+ } = defineProps<{
15
+ /** Key under which the state is remembered. */
16
+ name: string
17
+ /** The browser storage entry that holds the state of all sections. */
18
+ storageKey?: string
19
+ title: string
20
+ /** What the section holds, visible without opening it. */
21
+ count?: number
22
+ /** An icon before the title, where the section is one of several kinds. */
23
+ icon?: string
24
+ /** How it starts while nothing is remembered. */
25
+ defaultOpen?: boolean
26
+ /** The heading level of the title within the page. */
27
+ level?: 2 | 3 | 4
28
+ }>()
29
+
30
+ const bodyId = `${useId()}-body`
31
+ const open = ref(defaultOpen)
32
+
33
+ function remembered(): boolean {
34
+ try {
35
+ const state = JSON.parse(localStorage.getItem(storageKey) ?? '{}')?.[name]
36
+ return state === undefined ? defaultOpen : Boolean(state)
37
+ } catch {
38
+ return defaultOpen
39
+ }
40
+ }
41
+
42
+ onMounted(() => {
43
+ open.value = remembered()
44
+ watch(open, value => {
45
+ try {
46
+ const state = JSON.parse(localStorage.getItem(storageKey) ?? '{}') ?? {}
47
+ localStorage.setItem(storageKey, JSON.stringify({...state, [name]: value}))
48
+ } catch {
49
+ return
50
+ }
51
+ })
52
+ })
53
+ </script>
54
+
55
+ <template>
56
+ <UCard :ui="{body: 'p-4 sm:p-4'}">
57
+ <div class="flex flex-wrap items-center gap-3">
58
+ <component :is="`h${level}`" class="section-title m-0 grow">
59
+ <button type="button" class="flex w-full items-center gap-3 text-left" :aria-expanded="open"
60
+ :aria-controls="open ? bodyId : undefined" @click="open = !open">
61
+ <UIcon :name="open ? 'i-lucide-chevron-down' : 'i-lucide-chevron-right'" class="text-muted"/>
62
+ <UIcon v-if="icon" :name="icon" class="text-muted"/>
63
+ <span>{{ title }}</span>
64
+ <span v-if="count !== undefined" class="tabular text-sm font-normal normal-case tracking-normal text-muted">
65
+ {{ count }}
66
+ </span>
67
+ </button>
68
+ </component>
69
+ <slot v-if="open" name="actions"/>
70
+ </div>
71
+ <div v-if="open" :id="bodyId" class="mt-3">
72
+ <slot/>
73
+ </div>
74
+ </UCard>
75
+ </template>
@@ -0,0 +1,132 @@
1
+ <script setup lang="ts">
2
+ import UButton from '@nuxt/ui/components/Button.vue'
3
+ import UFormField from '@nuxt/ui/components/FormField.vue'
4
+ import UInput from '@nuxt/ui/components/Input.vue'
5
+ import {computed, nextTick, ref, useId, watch} from 'vue'
6
+
7
+ /**
8
+ * A text field that also opens the list it draws on, so an entry can be picked rather than typed,
9
+ * while anything typed stays the value. A bare datalist offers no visible way in.
10
+ */
11
+ const props = defineProps<{
12
+ label: string
13
+ suggestions: string[]
14
+ placeholder?: string
15
+ wide?: boolean
16
+ /** The list already answers the typing; filtering it again here would only cut it down. */
17
+ prefiltered?: boolean
18
+ disabled?: boolean
19
+ }>()
20
+
21
+ const emit = defineEmits<{ change: [] }>()
22
+ const model = defineModel<string>({default: ''})
23
+ const id = useId()
24
+ const labelId = `${id}-label`
25
+ const input = ref<{ inputRef: HTMLInputElement | null }>()
26
+ const open = ref(false)
27
+
28
+ /** Which entry the arrow keys are on, or -1 while the typing stands on its own. */
29
+ const active = ref(-1)
30
+
31
+ /**
32
+ * Typing narrows the list, but a value taken from the list matches only itself, so a field that
33
+ * already holds an entry would offer that one alone. Showing everything once the text is an exact
34
+ * hit keeps the list usable for changing one's mind.
35
+ */
36
+ const filtered = computed(() => {
37
+ const search = model.value.trim().toLowerCase()
38
+ if (props.prefiltered || !search) return props.suggestions
39
+ if (props.suggestions.some(value => value.toLowerCase() === search)) return props.suggestions
40
+ return props.suggestions.filter(value => value.toLowerCase().includes(search))
41
+ })
42
+
43
+ const visible = computed(() => open.value && filtered.value.length > 0)
44
+ const optionId = (index: number) => `${id}-option-${index}`
45
+
46
+ function pick(value: string) {
47
+ model.value = value
48
+ close()
49
+ emit('change')
50
+ }
51
+
52
+ function close() {
53
+ open.value = false
54
+ active.value = -1
55
+ }
56
+
57
+ function toggle() {
58
+ open.value = !open.value
59
+ active.value = -1
60
+ if (open.value) input.value?.inputRef?.focus()
61
+ }
62
+
63
+ /**
64
+ * Wraps at both ends, so holding one arrow key walks the whole list either way. With nothing
65
+ * highlighted yet, down starts at the top and up at the bottom.
66
+ */
67
+ async function move(steps: number) {
68
+ const count = filtered.value.length
69
+ if (!count) return
70
+ open.value = true
71
+ active.value = active.value < 0
72
+ ? (steps > 0 ? 0 : count - 1)
73
+ : (active.value + steps + count) % count
74
+ await nextTick()
75
+ document.getElementById(optionId(active.value))?.scrollIntoView({block: 'nearest'})
76
+ }
77
+
78
+ /**
79
+ * Enter takes the highlighted entry. With nothing highlighted it only closes the list and is
80
+ * otherwise left alone, so the input fires its own change event for what was typed and a
81
+ * surrounding form still submits.
82
+ */
83
+ function confirm(event: KeyboardEvent) {
84
+ const chosen = visible.value ? filtered.value[active.value] : undefined
85
+ if (chosen === undefined) {
86
+ close()
87
+ return
88
+ }
89
+ event.preventDefault()
90
+ pick(chosen)
91
+ }
92
+
93
+ /** Escape closes an open list without also closing a dialog around the field. */
94
+ function escape(event: KeyboardEvent) {
95
+ if (!visible.value) return
96
+ event.stopPropagation()
97
+ close()
98
+ }
99
+
100
+ watch(filtered, () => (active.value = -1))
101
+ </script>
102
+
103
+ <template>
104
+ <UFormField :class="wide ? 'col-span-2' : ''" class="relative">
105
+ <template #label>
106
+ <span :id="labelId">{{ label }}</span>
107
+ </template>
108
+ <UInput ref="input" v-model="model" class="w-full" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
109
+ role="combobox" aria-autocomplete="list" :aria-expanded="visible"
110
+ :aria-controls="visible ? `${id}-list` : undefined"
111
+ :aria-activedescendant="active >= 0 ? optionId(active) : undefined"
112
+ @focus="open = true" @blur="close" @change="emit('change')"
113
+ @keydown.down.prevent="move(1)" @keydown.up.prevent="move(-1)" @keydown.enter="confirm"
114
+ @keydown.tab="close" @keydown.escape="escape">
115
+ <template v-if="suggestions.length" #trailing>
116
+ <UButton color="neutral" variant="link" size="sm" icon="i-lucide-chevron-down" tabindex="-1"
117
+ aria-label="Auswahl öffnen" :aria-expanded="visible" :disabled="disabled"
118
+ @mousedown.prevent @click="toggle"/>
119
+ </template>
120
+ </UInput>
121
+ <ul v-if="visible" :id="`${id}-list`" role="listbox" :aria-labelledby="labelId"
122
+ class="absolute inset-x-0 top-full z-30 mt-1 max-h-64 overflow-auto rounded-sm border border-default bg-default py-1 shadow-lg">
123
+ <li v-for="(value, index) in filtered" :id="optionId(index)" :key="`${index}-${value}`" role="option"
124
+ :aria-selected="index === active"
125
+ class="cursor-pointer px-3 py-1.5 text-sm"
126
+ :class="[index === active ? 'bg-elevated' : '', value === model ? 'font-semibold' : '']"
127
+ @mousedown.prevent="pick(value)" @mousemove="active = index">
128
+ {{ value }}
129
+ </li>
130
+ </ul>
131
+ </UFormField>
132
+ </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,47 @@
1
+ <script setup lang="ts">
2
+ import UFormField from '@nuxt/ui/components/FormField.vue'
3
+ import UInput from '@nuxt/ui/components/Input.vue'
4
+ import {computed} from 'vue'
5
+
6
+ /**
7
+ * One date-time field for a date and a time kept as two strings in German notation, as a printed
8
+ * form shows them. They are entered with the browser's picker, which brings a calendar and a clock.
9
+ * The field reads `19.9.2026` and `8:00` as well as zero-padded values, and writes zero-padded ones
10
+ * (`19.09.2026`, `08:00`). A date without a time shows as midnight, so the first edit writes
11
+ * `00:00`; a date that does not exist, such as `31.2.2026`, shows as an empty field.
12
+ */
13
+ const date = defineModel<string>('date', {default: ''})
14
+ const time = defineModel<string>('time', {default: ''})
15
+ const {label, disabled} = defineProps<{ label: string, disabled?: boolean }>()
16
+ /** Fires only once both values are set, so listeners never see half a change. */
17
+ const emit = defineEmits<{ change: [] }>()
18
+
19
+ /** Turns "19.9.2026" and "08:00" into what a `datetime-local` understands, or into nothing. */
20
+ const value = computed(() => {
21
+ const day = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(date.value.trim())
22
+ const clock = /^(\d{1,2}):(\d{2})/.exec(time.value.trim())
23
+ if (!day) return ''
24
+ const isoDay = `${day[3]}-${day[2]!.padStart(2, '0')}-${day[1]!.padStart(2, '0')}`
25
+ return clock ? `${isoDay}T${clock[1]!.padStart(2, '0')}:${clock[2]}` : `${isoDay}T00:00`
26
+ })
27
+
28
+ /** Back to the slip's notation; clearing the field clears both values. */
29
+ function update(input: string) {
30
+ const parts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(input)
31
+ if (!parts) {
32
+ date.value = ''
33
+ time.value = ''
34
+ } else {
35
+ date.value = `${parts[3]}.${parts[2]}.${parts[1]}`
36
+ time.value = `${parts[4]}:${parts[5]}`
37
+ }
38
+ emit('change')
39
+ }
40
+ </script>
41
+
42
+ <template>
43
+ <UFormField :label="label">
44
+ <UInput :model-value="value" type="datetime-local" step="60" class="w-full" :disabled="disabled"
45
+ @change="update(($event.target as HTMLInputElement).value)"/>
46
+ </UFormField>
47
+ </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,14 @@
1
+ <script setup lang="ts">
2
+ import UFormField from '@nuxt/ui/components/FormField.vue'
3
+ import UTextarea from '@nuxt/ui/components/Textarea.vue'
4
+
5
+ /** A labelled multi-line text field. */
6
+ defineProps<{ label: string, placeholder?: string, rows?: number, disabled?: boolean }>()
7
+ const model = defineModel<string>({default: ''})
8
+ </script>
9
+
10
+ <template>
11
+ <UFormField :label="label">
12
+ <UTextarea v-model="model" class="w-full" :rows="rows ?? 3" :placeholder="placeholder" :disabled="disabled"/>
13
+ </UFormField>
14
+ </template>
@@ -0,0 +1,29 @@
1
+ <script setup lang="ts">
2
+ import UFormField from '@nuxt/ui/components/FormField.vue'
3
+ import UInput from '@nuxt/ui/components/Input.vue'
4
+ import {computed, useId} from 'vue'
5
+
6
+ /** A labelled single-line text field, optionally offering suggestions from a list while typing. */
7
+ const props = defineProps<{
8
+ label: string
9
+ suggestions?: string[]
10
+ placeholder?: string
11
+ /** Spans two columns in a grid. */
12
+ wide?: boolean
13
+ disabled?: boolean
14
+ }>()
15
+
16
+ defineEmits<{ change: [] }>()
17
+ const model = defineModel<string>({default: ''})
18
+ const id = useId()
19
+ const listId = computed(() => props.suggestions?.length ? `${id}-list` : undefined)
20
+ </script>
21
+
22
+ <template>
23
+ <UFormField :label="label" :class="wide ? 'col-span-2' : ''">
24
+ <UInput v-model="model" class="w-full" :list="listId" :placeholder="placeholder" :disabled="disabled" @change="$emit('change')"/>
25
+ <datalist v-if="listId" :id="listId">
26
+ <option v-for="value in suggestions" :key="value" :value="value"/>
27
+ </datalist>
28
+ </UFormField>
29
+ </template>
@@ -0,0 +1,47 @@
1
+ <script setup lang="ts">
2
+ import UButton from '@nuxt/ui/components/Button.vue'
3
+ import UFieldGroup from '@nuxt/ui/components/FieldGroup.vue'
4
+ import UFormField from '@nuxt/ui/components/FormField.vue'
5
+ import {useId} from 'vue'
6
+
7
+ /**
8
+ * A yes/no choice as two buttons. The stored values and the button labels are configurable, so a
9
+ * tool can store exactly what it prints, such as `J` and `N`; `yesTitle` and `noTitle` spell out
10
+ * labels that are abbreviations.
11
+ */
12
+ const {
13
+ yesValue = 'ja',
14
+ noValue = 'nein',
15
+ yesLabel = 'Ja',
16
+ noLabel = 'Nein',
17
+ } = defineProps<{
18
+ label: string
19
+ yesValue?: string
20
+ noValue?: string
21
+ yesLabel?: string
22
+ noLabel?: string
23
+ yesTitle?: string
24
+ noTitle?: string
25
+ disabled?: boolean
26
+ }>()
27
+ const model = defineModel<string>({required: true})
28
+ const labelId = `${useId()}-label`
29
+ </script>
30
+
31
+ <template>
32
+ <UFormField>
33
+ <template #label>
34
+ <span :id="labelId">{{ label }}</span>
35
+ </template>
36
+ <UFieldGroup role="group" :aria-labelledby="labelId">
37
+ <UButton size="sm" :color="model === yesValue ? 'primary' : 'neutral'"
38
+ :variant="model === yesValue ? 'solid' : 'outline'" :label="yesLabel" :title="yesTitle"
39
+ :aria-label="yesTitle" :aria-pressed="model === yesValue" :disabled="disabled"
40
+ @click="model = yesValue"/>
41
+ <UButton size="sm" :color="model === noValue ? 'primary' : 'neutral'"
42
+ :variant="model === noValue ? 'solid' : 'outline'" :label="noLabel" :title="noTitle"
43
+ :aria-label="noTitle" :aria-pressed="model === noValue" :disabled="disabled"
44
+ @click="model = noValue"/>
45
+ </UFieldGroup>
46
+ </UFormField>
47
+ </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
+ }