@kerf-js/veneer 0.1.2-nightly.20261118.85 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerf-js/veneer",
3
- "version": "0.1.2-nightly.20261118.85",
3
+ "version": "0.1.3",
4
4
  "description": "veneer, the UI toolkit for kerf: components over @kerf-js/veneer-core",
5
5
  "keywords": [
6
6
  "kerf"
@@ -47,12 +47,12 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@kerf-js/scroll": "0.1.2-nightly.20261118.85",
51
- "@kerf-js/veneer-core": "0.1.2-nightly.20261118.85",
52
- "@kerf-js/veneer-icons": "0.1.2-nightly.20261118.85"
50
+ "@kerf-js/scroll": "0.1.3",
51
+ "@kerf-js/veneer-core": "0.1.3",
52
+ "@kerf-js/veneer-icons": "0.1.3"
53
53
  },
54
54
  "peerDependencies": {
55
- "@kerf-js/core": "^0.1.2-nightly.20261118.85"
55
+ "@kerf-js/core": "^0.1.3"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=24"
@@ -1,5 +1,5 @@
1
1
  import { DownIcon } from '@kerf-js/veneer-icons'
2
- import { derived, untrack } from '@kerf-js/core'
2
+ import { derived, state, untrack } from '@kerf-js/core'
3
3
  import { bindable, type Bindable } from './bind'
4
4
  import { Field, type FieldShell } from './Field'
5
5
  import '@kerf-js/veneer-core/styles/inputs/text.css'
@@ -30,15 +30,37 @@ type NumberOptions = {
30
30
  function numberModel(opts: NumberOptions) {
31
31
  const v = bindable<number | null>(opts.value, opts.initial, null, opts.onChange)
32
32
  const fit = (n: number) => Math.min(opts.max() ?? Infinity, Math.max(opts.min() ?? -Infinity, n))
33
- const shown = derived(() => (v.value === null ? '' : String(v.value)))
33
+ const draft = state<string | null>(null)
34
+ const shown = derived(() => draft.value ?? (v.value === null ? '' : String(v.value)))
35
+ const number = (text: string) => {
36
+ const n = Number(text.trim())
37
+ return text.trim() !== '' && Number.isFinite(n) ? n : undefined
38
+ }
34
39
  let input: HTMLInputElement | undefined
35
40
  const write = (n: number | null) => {
41
+ draft.value = null
36
42
  if (n !== untrack(() => v.value)) v.set(n, 'keyboard')
37
43
  if (input) input.value = n === null ? '' : String(n)
38
44
  }
39
- const nudge = (by: number) => write(fit((untrack(() => v.value) ?? opts.min() ?? 0) + by))
45
+ const discard = () => {
46
+ draft.value = null
47
+ if (input) input.value = untrack(() => shown.value)
48
+ }
49
+ const commit = () => {
50
+ const raw = untrack(() => draft.value)
51
+ if (raw === null) return discard()
52
+ const n = number(raw)
53
+ write(raw.trim() === '' ? null : n === undefined ? untrack(() => v.value) : fit(n))
54
+ }
55
+ const nudge = (by: number) => {
56
+ const raw = untrack(() => draft.value)
57
+ const n = raw === null ? undefined : number(raw)
58
+ write(fit((n ?? untrack(() => v.value) ?? opts.min() ?? 0) + by))
59
+ }
40
60
  const onKey = (e: KeyboardEvent) => {
41
61
  if (opts.disabled() || opts.readonly()) return
62
+ if (e.key === 'Escape') return discard()
63
+ if (e.key === 'Enter') return commit()
42
64
  const by = (
43
65
  {
44
66
  ArrowUp: opts.step(),
@@ -62,14 +84,18 @@ function numberModel(opts: NumberOptions) {
62
84
  }
63
85
 
64
86
  const onInput = (e: Event) => {
65
- const text = (e.currentTarget as HTMLInputElement).value.trim()
66
- const n = Number(text)
67
- if (text === '') v.set(null, 'keyboard')
68
- else if (Number.isFinite(n)) v.set(fit(n), 'keyboard')
87
+ if (opts.disabled() || opts.readonly()) return
88
+ const raw = (e.currentTarget as HTMLInputElement).value
89
+ draft.value = raw
90
+ const n = number(raw)
91
+ if (raw.trim() === '') {
92
+ if (untrack(() => v.value) !== null) v.set(null, 'keyboard')
93
+ } else if (n !== undefined && fit(n) === n && n !== untrack(() => v.value)) v.set(n, 'keyboard')
69
94
  }
70
95
 
71
96
  const onBlur = () => {
72
- if (input) input.value = untrack(() => shown.value)
97
+ if (opts.disabled() || opts.readonly()) discard()
98
+ else commit()
73
99
  }
74
100
  return [v, shown, nudge, onKey, onInput, onBlur, (n: HTMLInputElement) => (input = n)] as const
75
101
  }
@@ -77,7 +103,8 @@ function numberModel(opts: NumberOptions) {
77
103
  /**
78
104
  * A number in the field shell (03: `inputmode` over `type="number"`, which changes on a wheel, takes "e" and has its own
79
105
  * locale bugs). The input stays real text, so editing, paste and the numeric keypad are the OS's; Veneer adds APG spinbutton
80
- * keys (↑/↓, Page keys, Home/End with a bound) and two steppers. Text that isn't a number leaves the value alone until blur.
106
+ * keys (↑/↓, Page keys, Home/End with a bound) and two steppers. A raw draft preserves partial input; only in-range values
107
+ * are emitted while typing. Blur/Enter clamp a numeric draft; Escape discards it before bubbling.
81
108
  */
82
109
  export function NumberField({
83
110
  value,
@@ -147,7 +174,7 @@ export function NumberField({
147
174
  aria-describedby={p.describedby}
148
175
  aria-invalid={p.invalid ? 'true' : undefined}
149
176
  onInput={onInput}
150
- onKeyDown={onKey}
177
+ onKeyDownCapture={onKey}
151
178
  onBlur={onBlur}
152
179
  />
153
180
  )}
@@ -50,15 +50,16 @@ export function tableDetails<T>({
50
50
  pick,
51
51
  toggle,
52
52
  span: () => cols.value.length + (sel ? 1 : 0) + (hasDetails ? 1 : 0),
53
- body: (row) =>
54
- props.expand
55
- ? props.expand(row)
56
- : untrack(() =>
57
- tableFields(
58
- () => row,
59
- () => ctx,
60
- ),
53
+ body: (row) => {
54
+ const fields = () =>
55
+ untrack(() =>
56
+ tableFields(
57
+ () => row,
58
+ () => ctx,
61
59
  ),
60
+ )
61
+ return props.expand ? props.expand(row, fields) : fields()
62
+ },
62
63
  edit: (r, c, v) => props.onEdit?.(r, c, v),
63
64
  }
64
65
 
@@ -72,8 +72,11 @@ export interface TableProps<T> {
72
72
  page?: { size: number } | undefined
73
73
  /** Called on Next or Previous, with the page or server cursor to load. */
74
74
  onPageChange?: ((to: unknown, reason: 'next' | 'prev') => void) | undefined
75
- /** A row's details. Default a list of every column. */
76
- expand?: ((row: T) => unknown) | undefined
75
+ /**
76
+ * A row's details. Default a list of every column. `fields` renders that default list, so details can keep it and
77
+ * add to it.
78
+ */
79
+ expand?: ((row: T, fields: () => unknown) => unknown) | undefined
77
80
  /** inline (default): they slide open in place at every width. sheet: a panel over the table below 1000px. */
78
81
  details?: 'inline' | 'sheet' | undefined
79
82
  /** Called with the row, the column's id and the new value when a cell edit is committed. */