@zooui/nuxt 0.3.1 → 0.4.1

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/README.md CHANGED
@@ -53,7 +53,7 @@ plain Nuxt UI. Three rules:
53
53
  | `ZCard`, `ZModal`, `ZSlideover`, `ZDrawer` | Nuxt UI's surfaces with a `color` that draws a 3px colored edge |
54
54
  | `ZKicker` | The mono label over a section: `[ DEPLOYMENTS ]` |
55
55
  | `ZIdentifier` | A package, version or hash in the mono face |
56
- | `ZStatus` | Status by shape, so it survives grayscale |
56
+ | `ZStatus` | Status by shape, so it survives grayscale; takes a product's own statuses from app.config |
57
57
  | `ZSlots` | One named chip per slot of capacity |
58
58
  | `ZQuotaMeter` | Usage against a limit |
59
59
  | `ZCodeBlock` | The near-black code surface, with copy |
@@ -64,12 +64,18 @@ plain Nuxt UI. Three rules:
64
64
  | `ZOrderList` | An ordered list with one selected row and a move toolbar, for master-detail editors |
65
65
  | `ZNumberInput` | One number input for money, percent, count and hours, with a calc mode |
66
66
  | `ZDateField` | A calendar-day field on `Temporal.PlainDate` or `CalendarDate`, with Nuxt UI's limit props |
67
+ | `ZMonthField`, `ZYearField` | ZDateField for a month (`Temporal.PlainYearMonth` or `CalendarDate`) and for a year (a number), with calendars of months and years |
67
68
  | `ZFileDropOverlay` | Files dropped anywhere in the window, or contained in a dialog or region; nested overlays defer to the innermost |
68
69
  | `ZFileList` | A form's files, stored and newly added, with an async remove, thumbnails and row slots |
69
70
  | `ZConfirmDialog`, `ZConfirmButton` | `useConfirm()`'s promise-based questions, and a button that asks in a popover |
70
71
  | `ZOptionalDate` | A checkbox in front of a `ZDateField`: the date can be edited only while it's ticked |
71
72
  | `ZSelectMenu` | Nuxt UI's `USelectMenu` with typeahead from the top of the list, Tab that moves on, a focus ring on any focus, and optional open on focus |
72
73
  | `ZFilterSelect` | A faceted multi-select filter for list and table toolbars: search, counts, All and Clear |
74
+ | `ZSearchInput` | A search box for list and table toolbars: handed back once typing pauses, with a clear button and Escape |
75
+ | `useNotify()`, `errorMessage()` | Toasts in one line per tone (success, info, warning, error, primary), and readable text for a caught fetch error |
76
+ | `ZUrlInput` | A website address field: adds `https://` and checks for a real host when you leave it |
77
+ | `ZMaskedInput` | A text input with a mask (`(###) ###-####`, or a list chosen as typed), with US phone and tax-ID presets |
78
+ | `ZHighlight` | Text with each match of a search marked, never through `v-html` |
73
79
 
74
80
  ## Docs
75
81
 
@@ -78,10 +84,16 @@ plain Nuxt UI. Three rules:
78
84
  [ZOrderList](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/order-list.md),
79
85
  [ZNumberInput](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/number-input.md),
80
86
  [ZDateField](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/date-field.md),
87
+ [ZMonthField and ZYearField](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/month-year-field.md),
81
88
  [useConfirm and ZConfirmButton](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/confirm.md),
82
89
  [ZOptionalDate](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/optional-date.md),
83
90
  [ZSelectMenu](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/select-menu.md),
84
- [ZFilterSelect](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/filter-select.md)
91
+ [ZFilterSelect](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/filter-select.md),
92
+ [ZSearchInput](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/search-input.md),
93
+ [useNotify and errorMessage](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/notify.md),
94
+ [ZUrlInput](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/url-input.md),
95
+ [ZMaskedInput](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/masked-input.md),
96
+ [ZHighlight](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/highlight.md)
85
97
  - [The base and a theme](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/base-and-theme.md): what each layer carries, and why they're two layers
86
98
  - [Accents and colored edges](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/accents-and-edges.md): `data-accent` sections and the `color` edge
87
99
  - [Mechanisms](https://github.com/zooui-dev/zooui/blob/main/packages/nuxt/docs/mechanisms.md): `light-dark()`, the hydration label fix, icon bundling, shipping as source
@@ -33,6 +33,10 @@ const parts = computed(() => {
33
33
  : [{ text: chunk, tok: false }]);
34
34
  });
35
35
 
36
+ /** A block of one line (a shown-once token, an `export`) keeps the row: the toolbar beside it costs no height, where
37
+ * the corner toolbar would leave an empty band above the code. Only multi-line code gets the corner toolbar. */
38
+ const layout = computed(() => (props.variant === "block" && props.code.includes("\n") ? "block" : "line"));
39
+
36
40
  let reset: ReturnType<typeof setTimeout> | undefined;
37
41
  async function copy() {
38
42
  try {
@@ -52,11 +56,13 @@ onBeforeUnmount(() => clearTimeout(reset));
52
56
  <template>
53
57
  <code v-if="variant === 'inline'" :class="cx(ident.base, ident.kind.package)">{{ code }}</code>
54
58
 
55
- <div v-else :class="codeCls.wrap">
59
+ <div v-else :class="cx(codeCls.wrap, codeCls.layout[layout])">
56
60
  <span v-if="variant === 'line' && prompt" :class="codeCls.prompt">{{ prompt }}</span>
57
- <pre :class="cx(codeCls.pre, wrap ? 'whitespace-pre-wrap break-all @max-[359px]:whitespace-pre @max-[359px]:break-normal' : 'whitespace-pre')"><template v-for="(p, i) in parts" :key="i"><span v-if="p.tok" :class="codeCls.tok">{{ p.text }}</span><template v-else>{{ p.text }}</template></template></pre>
58
- <span v-if="lang" :class="codeCls.lang">{{ lang }}</span>
59
- <button type="button" :class="codeCls.copy" :data-done="result === 'copied'" @click="copy">{{ result === "copied" ? "copied" : result === "failed" ? "copy failed" : "copy" }}</button>
61
+ <pre :class="cx(codeCls.pre[layout], wrap ? 'whitespace-pre-wrap wrap-anywhere @max-[359px]:whitespace-pre @max-[359px]:wrap-normal' : 'whitespace-pre')"><template v-for="(p, i) in parts" :key="i"><span v-if="p.tok" :class="codeCls.tok">{{ p.text }}</span><template v-else>{{ p.text }}</template></template></pre>
62
+ <div :class="codeCls.bar[layout]">
63
+ <span v-if="lang" :class="codeCls.lang">{{ lang }}</span>
64
+ <button type="button" :class="codeCls.copy" :data-done="result === 'copied'" @click="copy">{{ result === "copied" ? "copied" : result === "failed" ? "copy failed" : "copy" }}</button>
65
+ </div>
60
66
  <!-- a changed button label is not announced; this is -->
61
67
  <span class="sr-only" role="status">{{ result === "copied" ? "Copied to clipboard" : result === "failed" ? "Couldn't copy — select the text and copy it" : "" }}</span>
62
68
  </div>
@@ -46,10 +46,15 @@
46
46
  //
47
47
  // Also: a leading `icon` whose click emits `iconClick` (or a `#leading` slot in its place), a `calendarIcon` in place
48
48
  // of the calendar, and one-letter weekday headers (the locale's narrow weekday).
49
+ //
50
+ // The box, the commit rules, the invalid mark and `dateUpdate` are the field under it (internal/EntryField.vue), the
51
+ // same one ZMonthField and ZYearField use; what is a day's here is the reading and writing (date-entry.ts), the types
52
+ // and the calendar.
49
53
  import { CalendarDate } from '@internationalized/date'
50
- import { formFieldInjectionKey, useLocale } from '@nuxt/ui/composables'
54
+ import { useLocale } from '@nuxt/ui/composables'
51
55
  import type { Temporal } from 'temporal-polyfill/implementation'
52
- import { useToday } from '../composables/useToday'
56
+ import EntryField from './internal/EntryField.vue'
57
+ import type { EntryEngine, EntryProblem, InputSlotUi } from './internal/entry-field'
53
58
  import {
54
59
  applyDateShortcut, checkDateLimits, commitDateEntry, dateEntryFormat, dateEntryFormatFor, dateLimitMessage, dateModelTypeOf, formatDateEntry,
55
60
  fromPlainDate, isDateShortcut, parseDateEntry, toPlainDate,
@@ -108,13 +113,12 @@ const emit = defineEmits<{
108
113
  const model = defineModel<T | null>({ default: null })
109
114
  defineSlots<{
110
115
  /** UInput's leading slot, in place of the `icon` when given; `ui` is the input's, for its `leadingIcon` class. */
111
- leading?(props: { ui: Record<string, (options?: { class?: unknown }) => string> }): unknown
116
+ leading?(props: { ui: InputSlotUi }): unknown
112
117
  }>()
113
118
 
114
119
  const { locale: uiLocale } = useLocale()
115
120
  const localeCode = computed(() => props.locale ?? uiLocale.value.code)
116
121
  const entryFormat = computed(() => (props.format ? dateEntryFormat(props.format) : dateEntryFormatFor(localeCode.value)))
117
- const show = (d: Temporal.PlainDate | null) => formatDateEntry(d, entryFormat.value)
118
122
 
119
123
  // The caller's type, kept through an empty spell, and the CalendarDate it last held (whose class builds the next).
120
124
  let remembered: DateModelType | undefined
@@ -125,14 +129,14 @@ function remember(v: unknown) {
125
129
  if (type === 'calendar-date') like = v as CalendarDateLike
126
130
  }
127
131
  remember(model.value)
132
+ watch(model, remember)
128
133
  const kind = () => dateModelTypeOf(model.value) ?? remembered ?? props.modelType
129
134
  /** A day as the caller's type. */
130
135
  const out = (d: Temporal.PlainDate | null) => fromPlainDate(d, kind(), like) as T | null
131
136
  const outDay = (d: Temporal.PlainDate) => fromPlainDate(d, kind(), like) as Day
132
137
 
133
- const open = ref(false)
134
- const text = ref(show(toPlainDate(model.value)))
135
-
138
+ // The field holds a PlainDate. A computed, so the field sees a new day only when the model changes, never on a render.
139
+ const day = computed(() => toPlainDate(model.value))
136
140
  const sameDay = (a: Temporal.PlainDate | null, b: Temporal.PlainDate | null) => a === b || (!!a && !!b && a.equals(b))
137
141
 
138
142
  const limits = computed<DateLimits>(() => {
@@ -144,181 +148,34 @@ const limits = computed<DateLimits>(() => {
144
148
  }
145
149
  })
146
150
 
147
- // ── Invalid ───────────────────────────────────────────────────────────────────────────────────────────────────
148
- const problem = ref<DateLimitProblem | null>(null)
149
- const problemMessage = computed(() => (problem.value ? dateLimitMessage(problem.value, entryFormat.value) : ''))
150
- function flag(p: DateLimitProblem | null) {
151
- if (!p && !problem.value) return
152
- problem.value = p
153
- emit('invalid', p && { reason: p.reason, date: outDay(p.date), limit: p.limit && outDay(p.limit), message: problemMessage.value })
154
- }
155
- // In a UFormField, Nuxt UI's UInput takes aria-invalid, its error color and aria-describedby from the field, over
156
- // anything passed to it: so while a day is refused the field the UInput sees carries the message as its error (unless
157
- // it has one of its own, which the product may have set from `invalid`), and the message below takes the id that
158
- // aria-describedby names. Outside one, they are passed to the UInput directly.
159
- const formField = inject(formFieldInjectionKey, undefined)
160
- if (formField) {
161
- provide(formFieldInjectionKey, computed(() => {
162
- const f = formField.value
163
- return problem.value && f && !f.error ? { ...f, error: problemMessage.value } : f
164
- }))
165
- }
166
- const panelId = useId()
167
- const messageId = computed(() => {
168
- if (!problem.value) return undefined
169
- if (!formField?.value) return `${panelId}-invalid`
170
- return formField.value.error ? undefined : `${formField.value.ariaId}-error`
171
- })
172
- const attrs = useAttrs()
173
- const invalidAttrs = computed(() => {
174
- if (!problem.value || formField?.value) return {}
175
- const describedBy = [attrs['aria-describedby'], messageId.value].filter(Boolean).join(' ')
176
- return { 'color': 'error', 'aria-invalid': true, 'aria-describedby': describedBy }
177
- })
178
-
179
- // The date this field last settled on, which is what `dateUpdate` reports. NEVER re-read `model.value` for
180
- // that: when the parent owns the v-model, writing it only emits `update:modelValue`, and the prop comes back
181
- // on the parent's next render — so in the same tick `model.value` is still the OLD date, and a blur that just
182
- // committed "5/12" would announce null.
183
- let settled = toPlainDate(model.value)
184
- // The date `dateUpdate` last carried, boxed so an announced null is told apart from nothing announced yet.
185
- let announced: { date: Temporal.PlainDate | null } | undefined
186
- watch(model, (v) => {
187
- remember(v)
188
- const d = toPlainDate(v)
189
- // The parent set a different date, so whatever we announced before is no longer what's in the field.
190
- if (!sameDay(d, settled)) {
191
- announced = undefined
192
- flag(null)
151
+ const engine = computed<EntryEngine<Temporal.PlainDate>>(() => {
152
+ const format = entryFormat.value
153
+ const within = limits.value
154
+ return {
155
+ pattern: format.pattern,
156
+ show: (d) => formatDateEntry(d, format),
157
+ parse: (text, today) => parseDateEntry(text, today, format),
158
+ commit: (text, current, today) => commitDateEntry(text, current, today, format),
159
+ same: sameDay,
160
+ check: (d) => checkDateLimits(d, within),
161
+ message: (p) => dateLimitMessage(p as DateLimitProblem, format),
162
+ isShortcut: (key) => isDateShortcut(key, format),
163
+ shortcut: (key, current, today) => applyDateShortcut(key, current, today, format, within),
164
+ today: (today) => today,
193
165
  }
194
- settled = d
195
- text.value = show(d)
196
166
  })
197
- // A new format redraws the date it holds.
198
- watch(entryFormat, () => { text.value = show(settled) })
199
-
200
- const inputCmp = useTemplateRef<{ inputRef: HTMLInputElement | null, $el: HTMLElement }>('inputCmp')
201
-
202
- function set(d: Temporal.PlainDate | null) {
203
- if (!sameDay(d, settled)) model.value = out(d)
204
- settled = d
205
- text.value = show(d)
206
- return d
207
- }
208
-
209
- // What's typed becomes the value — or nothing, when it isn't a date. Leaving "5/32" in the box would show one
210
- // thing while the form saved another. Untouched text keeps the date as it is, so passing through the field
211
- // can't blank a stored date it wouldn't read back (a year before 1000). A day the limits refuse keeps the date
212
- // there was, drawn back in the box, and marks the field invalid: undefined, for nothing settled.
213
- function commitText(): { date: Temporal.PlainDate | null } | undefined {
214
- const next = commitDateEntry(text.value, settled, useToday(), entryFormat.value)
215
- const refused = next && !sameDay(next, settled) ? checkDateLimits(next, limits.value) : null
216
- if (refused) {
217
- text.value = show(settled)
218
- flag(refused)
219
- return undefined
220
- }
221
- return { date: set(next) }
222
- }
223
-
224
- function onType(v: string | number | null | undefined) {
225
- text.value = v == null ? '' : String(v)
226
- flag(null)
227
- }
228
167
 
229
- function focusInput() {
230
- nextTick(() => {
231
- const el = inputCmp.value?.inputRef
232
- if (!el) return
233
- el.focus()
234
- el.setSelectionRange(el.value.length, el.value.length)
235
- })
168
+ // The field's problem is the engine's, which is DateLimitProblem's.
169
+ function onInvalid(problem: (EntryProblem<Temporal.PlainDate> & { message: string }) | null) {
170
+ const p = problem as (DateLimitProblem & { message: string }) | null
171
+ emit('invalid', p && { reason: p.reason, date: outDay(p.date), limit: p.limit && outDay(p.limit), message: p.message })
236
172
  }
237
173
 
238
- // Focus is "still ours" on the input and anywhere in the calendar popover (which is teleported, so it isn't
239
- // inside the input's element).
240
- function isOurs(target: EventTarget | null) {
241
- if (!(target instanceof Element)) return false
242
- return !!inputCmp.value?.$el?.contains(target) || !!target.closest(`[data-date-field-panel="${panelId}"]`)
243
- }
244
-
245
- function announce(d: Temporal.PlainDate | null) {
246
- announced = { date: d }
247
- emit('dateUpdate', out(d))
248
- }
249
-
250
- // Leaving settles the field, but a date already announced (by Enter, say) isn't announced again: an inline
251
- // editor saving on dateUpdate would save it twice.
252
- function leave(e: FocusEvent) {
253
- if (isOurs(e.relatedTarget)) return
254
- if (announced && sameDay(announced.date, settled)) return
255
- announce(settled)
256
- }
257
-
258
- function onBlur(e: FocusEvent) {
259
- commitText()
260
- leave(e)
261
- }
262
-
263
- function onKeydown(e: KeyboardEvent) {
264
- if (e.isComposing || e.ctrlKey || e.metaKey) return
265
- if (e.altKey) {
266
- if (e.key === 'ArrowDown') {
267
- e.preventDefault()
268
- open.value = true
269
- }
270
- return
271
- }
272
- if (e.key === 'Enter') {
273
- open.value = false
274
- const committed = commitText()
275
- if (committed) announce(committed.date)
276
- // Refused: the date it kept is selected, so typing another replaces it.
277
- else nextTick(() => inputCmp.value?.inputRef?.select())
278
- return
279
- }
280
- // Tab commits here, so the text is settled before focus moves; the blur that follows announces it, once.
281
- if (e.key === 'Tab') {
282
- commitText()
283
- open.value = false
284
- return
285
- }
286
- if (e.key.length !== 1 || !isDateShortcut(e.key, entryFormat.value)) return
287
- e.preventDefault()
288
- const today = useToday()
289
- // Shortcuts step from the committed date, not from text typed since: the typed text is dropped. With no allowed day
290
- // to go to, the key does nothing.
291
- const next = applyDateShortcut(e.key, settled, today, entryFormat.value, limits.value)
292
- if (!next) return
293
- flag(null)
294
- announce(set(next))
295
- // Selected, so typing a date replaces the shortcut's rather than appending to it.
296
- nextTick(() => inputCmp.value?.inputRef?.select())
297
- }
298
-
299
- function clear() {
300
- const d = set(null)
301
- flag(null)
302
- emit('clear')
303
- announce(d)
304
- focusInput()
305
- }
174
+ const fieldCmp = useTemplateRef<{ focus: () => void }>('fieldCmp')
306
175
 
307
176
  // ── Calendar ──────────────────────────────────────────────────────────────────────────────────────────────
308
177
  // UCalendar takes Nuxt UI's CalendarDate, a bare year/month/day, so the conversion is by fields both ways.
309
178
  const toCalendar = (d: Temporal.PlainDate) => new CalendarDate(d.year, d.month, d.day)
310
-
311
- // The selection follows text typed but not yet committed, as the month and the shortcuts do, so the picker and the
312
- // input never disagree; untouched or unreadable text falls back to the model.
313
- const calendarValue = computed(() => {
314
- const day = parseDateEntry(text.value, useToday(), entryFormat.value) ?? toPlainDate(model.value)
315
- return day ? toCalendar(day) : undefined
316
- })
317
- // The month the calendar shows: the date in the box (typed or committed), else this month. Only read while
318
- // the popover is open, which is only ever in the browser.
319
- const calendarMonth = computed(() =>
320
- toCalendar(parseDateEntry(text.value, useToday(), entryFormat.value) ?? toPlainDate(model.value) ?? useToday()),
321
- )
322
179
  // The limits, for the calendar to disable those days.
323
180
  const calendarMin = computed(() => (limits.value.minValue ? toCalendar(limits.value.minValue as Temporal.PlainDate) : undefined))
324
181
  const calendarMax = computed(() => (limits.value.maxValue ? toCalendar(limits.value.maxValue as Temporal.PlainDate) : undefined))
@@ -327,13 +184,8 @@ const calendarUnavailable = computed(() => {
327
184
  return unavailable ? (v: CalendarDateLike) => unavailable(toPlainDate(v)!) : undefined
328
185
  })
329
186
 
330
- function onPick(v: unknown) {
331
- const type = dateModelTypeOf(v)
332
- if (type !== 'calendar-date') return
333
- open.value = false
334
- flag(null)
335
- announce(set(toPlainDate(v as CalendarDateLike)))
336
- focusInput()
187
+ function onPick(v: unknown, pick: (d: Temporal.PlainDate) => void) {
188
+ if (dateModelTypeOf(v) === 'calendar-date') pick(toPlainDate(v as CalendarDateLike)!)
337
189
  }
338
190
 
339
191
  // The month heading is the one thing in the calendar whose width depends on what it says, and the popover
@@ -342,94 +194,39 @@ function onPick(v: unknown) {
342
194
  // month the same. In em, so it follows the button's own font at every `size`; plus room for its padding, which is rem.
343
195
  const headingButton = { class: 'w-[calc(8.5em+1.5rem)] flex-none' }
344
196
 
345
- const popoverContent = computed(() => ({
346
- side: 'bottom' as const,
347
- align: 'start' as const,
348
- 'data-date-field-panel': panelId,
349
- // The input keeps focus while the calendar is open, so typing and shortcuts still work.
350
- onOpenAutoFocus: (e: Event) => e.preventDefault(),
351
- onCloseAutoFocus: (e: Event) => e.preventDefault(),
352
- // A click on our own input or icon isn't "outside"; the icon toggles the calendar itself.
353
- onInteractOutside: (e: CustomEvent<{ originalEvent?: Event }>) => {
354
- if (isOurs(e.detail?.originalEvent?.target ?? e.target)) e.preventDefault()
355
- },
356
- onFocusout: leave,
357
- }))
358
-
359
- function toggle() {
360
- if (props.disabled) return
361
- open.value = !open.value
362
- focusInput()
363
- }
364
-
365
- defineExpose({ focus: focusInput })
197
+ defineExpose({ focus: () => fieldCmp.value?.focus() })
366
198
  </script>
367
199
 
368
200
  <template>
369
- <UPopover v-model:open="open" :content="popoverContent" :portal="portal">
370
- <template #anchor>
371
- <!-- The placeholder keeps the input's own ink, the product's: a product may darken it (a date's shape must not read as
372
- a date someone typed), through `ui.base` or its app.config's input. While the calendar is open the field
373
- takes Nuxt UI's highlight ring, so it reads as the one being edited. -->
374
- <UInput
375
- ref="inputCmp"
376
- :model-value="text"
377
- type="text"
378
- autocomplete="off"
379
- v-bind="{ ...$attrs, ...invalidAttrs }"
380
- :size="size"
381
- :icon="icon"
382
- :disabled="disabled"
383
- :placeholder="placeholder ?? entryFormat.pattern"
384
- :highlight="highlight || open || !!problem"
385
- :ui="{ ...ui, root: `group ${ui?.root ?? ''}` }"
386
- @update:model-value="onType"
387
- @keydown="onKeydown"
388
- @blur="onBlur"
389
- >
390
- <template v-if="$slots.leading" #leading="slotProps">
391
- <slot name="leading" v-bind="slotProps as never" />
392
- </template>
393
- <template v-else-if="icon" #leading="{ ui: inputUi }">
394
- <UIcon :name="icon" data-slot="leadingIcon" :class="inputUi.leadingIcon({ class: ui?.leadingIcon })" @click="emit('iconClick', $event)" />
395
- </template>
396
- <template #trailing="{ ui: inputUi }">
397
- <!-- Why a typed day was refused, for screen readers: the input's aria-describedby names it. -->
398
- <span v-if="messageId" :id="messageId" class="sr-only">{{ problemMessage }}</span>
399
- <!-- Neither button takes focus (mousedown is prevented), so the input never blurs to them. Each icon is
400
- `text-current`, over Nuxt UI's dimmed trailing icon, so the button's own color reaches it. -->
401
- <button
402
- v-if="clearable && model && !disabled"
403
- type="button"
404
- tabindex="-1"
405
- :aria-label="clearLabel"
406
- class="cursor-pointer items-center text-dimmed hover:text-primary"
407
- :class="open ? 'flex' : 'hidden group-focus-within:flex'"
408
- @mousedown.prevent
409
- @click="clear"
410
- >
411
- <UIcon name="i-lucide-x" :class="inputUi.trailingIcon({ class: 'text-current' })" />
412
- </button>
413
- <button
414
- type="button"
415
- tabindex="-1"
416
- :aria-label="chooseLabel"
417
- :disabled="disabled"
418
- class="flex cursor-pointer items-center hover:text-primary disabled:cursor-not-allowed"
419
- :class="open ? 'text-primary' : 'text-dimmed group-focus-within:text-primary'"
420
- @mousedown.prevent
421
- @click="toggle"
422
- >
423
- <UIcon :name="calendarIcon" :class="inputUi.trailingIcon({ class: 'text-current' })" />
424
- </button>
425
- </template>
426
- </UInput>
201
+ <EntryField
202
+ ref="fieldCmp"
203
+ v-bind="$attrs"
204
+ :model-value="day"
205
+ :engine="engine"
206
+ :clearable="clearable"
207
+ :disabled="disabled"
208
+ :placeholder="placeholder"
209
+ :size="size"
210
+ :icon="icon"
211
+ :calendar-icon="calendarIcon"
212
+ :highlight="highlight"
213
+ :ui="ui"
214
+ :portal="portal"
215
+ :clear-label="clearLabel"
216
+ :choose-label="chooseLabel"
217
+ @update:model-value="(d) => (model = out(d))"
218
+ @date-update="(d) => emit('dateUpdate', out(d))"
219
+ @invalid="onInvalid"
220
+ @clear="emit('clear')"
221
+ @icon-click="emit('iconClick', $event)"
222
+ >
223
+ <template v-if="$slots.leading" #leading="slotProps">
224
+ <slot name="leading" v-bind="slotProps" />
427
225
  </template>
428
-
429
- <template #content>
226
+ <template #calendar="{ value, view, pick }">
430
227
  <UCalendar
431
- :model-value="calendarValue"
432
- :placeholder="calendarMonth"
228
+ :model-value="value ? toCalendar(value) : undefined"
229
+ :placeholder="toCalendar(view)"
433
230
  :locale="localeCode"
434
231
  :size="size"
435
232
  :view-control="headingButton"
@@ -439,8 +236,8 @@ defineExpose({ focus: focusInput })
439
236
  weekday-format="narrow"
440
237
  prevent-deselect
441
238
  class="p-2"
442
- @update:model-value="onPick"
239
+ @update:model-value="(v) => onPick(v, pick)"
443
240
  />
444
241
  </template>
445
- </UPopover>
242
+ </EntryField>
446
243
  </template>
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import { dragCarriesFiles, droppedFiles, sortDroppedFiles, type FileFilter, type RejectedFile } from '../utils/file-drop'
3
+
2
4
  /**
3
5
  * Drag events an overlay nearer the event's target has already counted. Every instance shares it: listeners on an
4
6
  * inner target run before those on an outer one (or the window), so the innermost overlay under the pointer claims each
@@ -60,7 +62,6 @@ function outrankedByModal(container: HTMLElement) {
60
62
  // page are left alone. The overlay is only a picture (`pointer-events: none`): the drag's events stay on the page's
61
63
  // own elements, so showing or hiding it never moves the pointer off one, a drop zone under it still gets its drop, and
62
64
  // an overlay nested inside it can be reached.
63
- import { dragCarriesFiles, droppedFiles, sortDroppedFiles, type FileFilter, type RejectedFile } from '../utils/file-drop'
64
65
 
65
66
  defineOptions({ inheritAttrs: false })
66
67
 
@@ -11,8 +11,8 @@
11
11
  // without one (then compared by identity). Values the options no longer hold are kept, not dropped.
12
12
  //
13
13
  // SEARCH is literal and case-insensitive (utils/filter-match.ts): what is typed is text, never a pattern, so `(` or
14
- // `.` match themselves. The options keep their order, and each label is drawn as segments with the matches in <mark>,
15
- // never through v-html. Checking or unchecking an option clears the search, so the next pick
14
+ // `.` match themselves. The options keep their order, and each label is drawn by ZHighlight, with the matches in
15
+ // <mark>, never through v-html. Checking or unchecking an option clears the search, so the next pick
16
16
  // starts from the whole list. All checks every option on screen (the matches, while searching) and leaves the search
17
17
  // as it is; Clear empties the filter.
18
18
  //
@@ -310,10 +310,7 @@ const searchInput = computed(() => props.searchable
310
310
  <UIcon v-if="iconOf(item as T)" :name="iconOf(item as T)!" :class="iconClasses(item as T)" aria-hidden="true" data-icon />
311
311
  <span :class="cls('itemLabel', 'min-w-0 flex-1 truncate')" data-label>
312
312
  <slot name="option-label" :option="(item as T)" :segments="filterSelectSegments(labelOf(item as T), query)" :selected="isSelected(item as T)">
313
- <template v-for="(segment, i) in filterSelectSegments(labelOf(item as T), query)" :key="i">
314
- <mark v-if="segment.match" class="rounded-xs bg-primary/15 font-semibold text-highlighted">{{ segment.text }}</mark>
315
- <template v-else>{{ segment.text }}</template>
316
- </template>
313
+ <ZHighlight :text="labelOf(item as T)" :query="query" />
317
314
  </slot>
318
315
  </span>
319
316
  <span v-if="countOf(item as T) !== undefined" :class="cls('itemCount', 'ms-auto shrink-0 text-xs tabular-nums text-muted')" data-count>
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ // Text with each match of a search wrapped in <mark>: a search result's name, an option's label or description.
3
+ //
4
+ // <ZHighlight :text="person.name" :query="searchTerm" />
5
+ // <ZHighlight :text="person.email" :query="searchTerm" :ui="{ mark: 'bg-transparent text-primary underline' }" />
6
+ //
7
+ // The search is ZFilterSelect's (utils/filter-match.ts): literal and case-insensitive, every match marked, left to
8
+ // right. What is typed is text, never a pattern, so `(` or `.` match themselves. The text is drawn as Vue text nodes
9
+ // and <mark> elements, never through v-html, so a `<b>` or an `<img onerror>` in it reads as those characters.
10
+ //
11
+ // It renders no element of its own, only the runs of text and the marks, so it drops into whatever holds it (a
12
+ // truncating span, a menu item's label) without changing its layout. Put classes on that element, not on ZHighlight.
13
+ // `ui.mark` takes classes for the marks, merged over the defaults with tailwind-merge.
14
+ import { twMerge } from 'tailwind-merge'
15
+ import { filterSelectSegments } from '../utils/filter-match'
16
+
17
+ defineOptions({ inheritAttrs: false })
18
+
19
+ const props = defineProps<{
20
+ /** The text to draw. A number is drawn as its string; null or undefined as nothing. */
21
+ text?: string | number | null
22
+ /** What to find in it. Empty, null or undefined: the text with nothing marked. */
23
+ query?: string | null
24
+ /** Classes for the parts, merged over the defaults. */
25
+ ui?: { mark?: string }
26
+ }>()
27
+
28
+ const segments = computed(() => filterSelectSegments(props.text == null ? '' : String(props.text), props.query ?? ''))
29
+ const markClass = computed(() => twMerge('rounded-xs bg-primary/15 font-semibold text-highlighted', props.ui?.mark))
30
+ </script>
31
+
32
+ <template>
33
+ <template v-for="(segment, i) in segments" :key="i">
34
+ <mark v-if="segment.match" :class="markClass">{{ segment.text }}</mark>
35
+ <template v-else>{{ segment.text }}</template>
36
+ </template>
37
+ </template>