@torpor/ui 1.3.4 → 1.3.6

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.
@@ -63,8 +63,15 @@ export default function ColorPickerInput($props: ColorPickerInputProps | undefin
63
63
 
64
64
  function handleInput(e: Event) {
65
65
  const el = e.currentTarget as HTMLInputElement;
66
- $state.editing = true;
66
+ // Order matters: while `editing` is false, `display()` only reads the
67
+ // committed value, so assigning `text` first doesn't re-trigger the
68
+ // reactive `value` attribute. Flipping `editing` last re-applies
69
+ // `display()` — which by then returns the new text. The other order
70
+ // flushes the attribute effect with `text` still at its old value,
71
+ // wiping the input mid-keystroke (the bug that made hex commits
72
+ // silently read "" and never fire onchange)
67
73
  $state.text = el.value;
74
+ $state.editing = true;
68
75
  }
69
76
 
70
77
  function handleKey(e: KeyboardEvent) {
@@ -1,4 +1,4 @@
1
- import { n as normalizeLoadResult, t as createItemLoader } from "../loader-DEeG5vFY.js";
1
+ import { n as normalizeLoadResult, t as createItemLoader } from "../loader-CBGbVpkN.js";
2
2
  import ComboBox from "./ComboBox.torp";
3
3
  import ComboBoxContent from "./ComboBoxContent.torp";
4
4
  import ComboBoxInput from "./ComboBoxInput.torp";
@@ -19,6 +19,14 @@ interface ContextualHoverProps {
19
19
  exitGrace?: number;
20
20
  /** Whether hovering and focusing are ignored */
21
21
  disabled?: boolean;
22
+ /**
23
+ * How taps on touch screens open the contextual window (hover never
24
+ * fires on touch). "auto" (default): tapping the trigger's inert surface
25
+ * opens it, but tapping a control inside the trigger — a button, link,
26
+ * … — runs that control's action without opening. "open": any tap opens
27
+ * it, even over embedded controls. "ignore": taps never open it.
28
+ */
29
+ touchBehavior?: "auto" | "open" | "ignore";
22
30
  }
23
31
 
24
32
  /**
@@ -77,6 +85,7 @@ export default function ContextualHover($props?: ContextualHoverProps) {
77
85
  getContent: () => ($state.contentId ? document.getElementById($state.contentId) : undefined),
78
86
  hoverDelay: $props?.hoverDelay,
79
87
  exitGrace: $props?.exitGrace,
88
+ touchBehavior: $props?.touchBehavior,
80
89
  });
81
90
 
82
91
  $run(() => {
@@ -84,8 +93,10 @@ export default function ContextualHover($props?: ContextualHoverProps) {
84
93
  });
85
94
 
86
95
  function handleEnter() {
96
+ // Suppressed touch taps (a tap on an embedded control) don't anchor
97
+ // the content either — the tap belongs to the control's action
98
+ if (!hover.handleEnter()) return;
87
99
  activate({ clientX: node.offsetWidth / 2, clientY: node.offsetHeight / 2 } as MouseEvent);
88
- hover.handleEnter();
89
100
  }
90
101
 
91
102
  @render {
@@ -99,6 +110,7 @@ export default function ContextualHover($props?: ContextualHoverProps) {
99
110
  aria-controls={$state.contentId}
100
111
  onmouseenter={handleEnter}
101
112
  onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
113
+ onpointerdown={(e: PointerEvent) => hover.handlePointerDown(e)}
102
114
  onfocus={() => hover.handleFocus()}
103
115
  onblur={(e: FocusEvent) => hover.handleBlur(e)}
104
116
  onmount={(el) => {
@@ -228,6 +228,11 @@ export default function DataGrid($props: DataGridProps) {
228
228
  // Incremented on every load; only the latest load's settle updates
229
229
  // the pending flag
230
230
  let loadGeneration = 0;
231
+ // The in-flight load's controller: starting a new load aborts it, so
232
+ // loaders that take the signal can cancel the wire request. Loaders that
233
+ // ignore it still work — the generation check discards stale results
234
+ // application-side either way.
235
+ let loadAbort: AbortController | null = null;
231
236
 
232
237
  function runLoad(): Promise<LoadResult> {
233
238
  const request: LoadRequest = {};
@@ -243,9 +248,22 @@ export default function DataGrid($props: DataGridProps) {
243
248
  // only the latest load's settle clears the flag, so a reload that
244
249
  // overtakes an older request doesn't drop the indicator early
245
250
  const generation = ++loadGeneration;
251
+ loadAbort?.abort();
252
+ const controller = new AbortController();
253
+ loadAbort = controller;
246
254
  $state.reloading = true;
247
255
  $props.onloadstart?.();
248
- const result = Promise.resolve(($props.load as Loader)(request)).then(normalizeLoadResult);
256
+ const result = Promise.resolve(($props.load as Loader)(request, controller.signal))
257
+ .then(normalizeLoadResult)
258
+ .catch((error) => {
259
+ // Our own abort is not an error — the superseding load owns the
260
+ // UI, so this one never settles instead of rejecting into the
261
+ // error boundary
262
+ if (controller.signal.aborted) {
263
+ return new Promise<LoadResult>(() => {});
264
+ }
265
+ throw error;
266
+ });
249
267
  // Report successful loads to the consumer; failures surface through
250
268
  // the component's error boundary, not this notification chain
251
269
  result.then(
@@ -16,6 +16,14 @@ interface PopoverHoverProps {
16
16
  exitGrace?: number;
17
17
  /** Whether hovering and focusing are ignored */
18
18
  disabled?: boolean;
19
+ /**
20
+ * How taps on touch screens open the popover (hover never fires on
21
+ * touch). "auto" (default): tapping the trigger's inert surface opens it,
22
+ * but tapping a control inside the trigger — a button, link, … — runs
23
+ * that control's action without opening. "open": any tap opens it, even
24
+ * over embedded controls. "ignore": taps never open it.
25
+ */
26
+ touchBehavior?: "auto" | "open" | "ignore";
19
27
  }
20
28
 
21
29
  /**
@@ -59,6 +67,7 @@ export default function PopoverHover($props?: PopoverHoverProps) {
59
67
  getContent: () => ($state.contentId ? document.getElementById($state.contentId) : undefined),
60
68
  hoverDelay: $props?.hoverDelay,
61
69
  exitGrace: $props?.exitGrace,
70
+ touchBehavior: $props?.touchBehavior,
62
71
  });
63
72
 
64
73
  $run(() => {
@@ -80,6 +89,7 @@ export default function PopoverHover($props?: PopoverHoverProps) {
80
89
  aria-controls={$state.contentId}
81
90
  onmouseenter={() => hover.handleEnter()}
82
91
  onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
92
+ onpointerdown={(e: PointerEvent) => hover.handlePointerDown(e)}
83
93
  onfocus={() => hover.handleFocus()}
84
94
  onblur={(e: FocusEvent) => hover.handleBlur(e)}
85
95
  onmount={anchor}
@@ -1,4 +1,4 @@
1
- import { n as normalizeLoadResult, t as createItemLoader } from "../loader-DEeG5vFY.js";
1
+ import { n as normalizeLoadResult, t as createItemLoader } from "../loader-CBGbVpkN.js";
2
2
  import SelectBox from "./SelectBox.torp";
3
3
  import SelectBoxContent from "./SelectBoxContent.torp";
4
4
  import SelectBoxTrigger from "./SelectBoxTrigger.torp";
@@ -25,10 +25,17 @@ function normalizeLoadResult(result) {
25
25
  * ```
26
26
  */
27
27
  function createItemLoader(options) {
28
+ let abort = null;
28
29
  return $watch({
29
30
  get result() {
30
31
  return $async(() => {
31
- const promise = Promise.resolve(options.load(options.getRequest())).then(normalizeLoadResult);
32
+ abort?.abort();
33
+ const controller = new AbortController();
34
+ abort = controller;
35
+ const promise = Promise.resolve(options.load(options.getRequest(), controller.signal)).then(normalizeLoadResult).catch((error) => {
36
+ if (controller.signal.aborted) return new Promise(() => {});
37
+ throw error;
38
+ });
32
39
  promise.then((r) => options.onload?.(r), () => {});
33
40
  return promise;
34
41
  });
@@ -41,4 +48,4 @@ function createItemLoader(options) {
41
48
  //#endregion
42
49
  export { normalizeLoadResult as n, createItemLoader as t };
43
50
 
44
- //# sourceMappingURL=loader-DEeG5vFY.js.map
51
+ //# sourceMappingURL=loader-CBGbVpkN.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-DEeG5vFY.js","names":[],"sources":["../src/utils/loader.ts"],"sourcesContent":["import { $async, $watch } from \"@torpor/view\";\n\n/**\n * Shared contract for loading data from the network, used by components that\n * can take either static data or a loader function (DataGrid now, ComboBox\n * auto-complete and others later).\n *\n * A loader receives a request object describing what to fetch -- paging,\n * search text and sorting are standard; components extend it with their own\n * fields -- plus an AbortSignal so stale requests can be cancelled.\n */\n\n/** The base shape of a load request. Components extend this with their own fields. */\nexport interface LoadRequest {\n\t/** 1-based page number to load */\n\tpage?: number;\n\t/** Number of items per page */\n\tpageSize?: number;\n\t/** Search or filter text entered by the user */\n\tsearchText?: string;\n\t/** The field to sort by */\n\tsortBy?: string;\n\t/** The direction to sort in */\n\tsortDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * The result of a load: the items for the current request, and optionally\n * the total count (needed for paged components to show a pager).\n */\nexport interface LoadResult<T = any> {\n\titems: T[];\n\t/** The total number of items across all pages, if known */\n\ttotal?: number;\n}\n\n/**\n * Reads data for a request. May return a promise or a plain result, and may\n * return just an array of items when no total is available.\n */\nexport type Loader<T = any, TRequest extends LoadRequest = LoadRequest> = (\n\trequest: TRequest,\n\tsignal?: AbortSignal,\n) => Promise<LoadResult<T> | T[]> | LoadResult<T> | T[];\n\n/** Wraps a bare array in a LoadResult so consumers always get the same shape */\nexport function normalizeLoadResult<T>(result: LoadResult<T> | T[]): LoadResult<T> {\n\treturn Array.isArray(result) ? { items: result } : result;\n}\n\nexport interface ItemLoaderOptions<T = any, TRequest extends LoadRequest = LoadRequest> {\n\t/** The loader function to fetch items */\n\tload: Loader<T, TRequest>;\n\t/**\n\t * Builds the request for the current fetch. Called inside the async\n\t * getter, so reads of reactive state here re-fetch when they change.\n\t */\n\tgetRequest: () => TRequest;\n\t/** Called after each successful load with the normalized result */\n\tonload?: (result: LoadResult<T>) => void;\n}\n\n/** Reactive loading state returned by createItemLoader */\nexport interface ItemLoaderState<T = any> {\n\t/** The full result of the current load; suspends while a fetch is pending */\n\treadonly result: LoadResult<T> | undefined;\n\t/** The loaded items; suspends while a fetch is pending */\n\treadonly items: T[];\n}\n\n/**\n * Shared loading state for components that read items from a network loader\n * (DataGrid, ComboBox auto-complete etc). Read the returned state's `items`\n * or `result` inside an `@await` boundary: while a fetch is pending the read\n * suspends, and when dependencies read inside `getRequest` change the fetch\n * re-runs.\n *\n * For lazy loading (fetch only once some condition is met), gate the whole\n * rendering of the region that reads this loader behind that condition\n * (`@if`), so the `@await` boundary -- and with it the first fetch --\n * comes into existence when the condition flips.\n *\n * ```\n * let $load = createItemLoader({\n * \tload: $props.load,\n * \tgetRequest: () => ({ searchText: $state.searchText }),\n * });\n * @await { ...$load.items... } with { <span>Loading…</span> }\n * ```\n */\nexport function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(\n\toptions: ItemLoaderOptions<T, TRequest>,\n): ItemLoaderState<T> {\n\treturn $watch({\n\t\tget result(): LoadResult<T> | undefined {\n\t\t\treturn $async(() => {\n\t\t\t\tconst promise = Promise.resolve(options.load(options.getRequest())).then(\n\t\t\t\t\tnormalizeLoadResult,\n\t\t\t\t);\n\t\t\t\t// Report successful loads to the consumer; failures surface\n\t\t\t\t// through the component's error boundary, not this chain\n\t\t\t\tpromise.then(\n\t\t\t\t\t(r) => options.onload?.(r),\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t\treturn promise as Promise<LoadResult<T>>;\n\t\t\t});\n\t\t},\n\t\tget items(): T[] {\n\t\t\treturn this.result?.items ?? [];\n\t\t},\n\t});\n}\n"],"mappings":";;;AA8CA,SAAgB,oBAAuB,QAA4C;CAClF,OAAO,MAAM,QAAQ,MAAM,IAAI,EAAE,OAAO,OAAO,IAAI;AACpD;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,iBACf,SACqB;CACrB,OAAO,OAAO;EACb,IAAI,SAAoC;GACvC,OAAO,aAAa;IACnB,MAAM,UAAU,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,WAAW,CAAC,CAAC,CAAC,CAAC,KACnE,mBACD;IAGA,QAAQ,MACN,MAAM,QAAQ,SAAS,CAAC,SACnB,CAAC,CACR;IACA,OAAO;GACR,CAAC;EACF;EACA,IAAI,QAAa;GAChB,OAAO,KAAK,QAAQ,SAAS,CAAC;EAC/B;CACD,CAAC;AACF"}
1
+ {"version":3,"file":"loader-CBGbVpkN.js","names":[],"sources":["../src/utils/loader.ts"],"sourcesContent":["import { $async, $watch } from \"@torpor/view\";\n\n/**\n * Shared contract for loading data from the network, used by components that\n * can take either static data or a loader function (DataGrid now, ComboBox\n * auto-complete and others later).\n *\n * A loader receives a request object describing what to fetch -- paging,\n * search text and sorting are standard; components extend it with their own\n * fields -- plus an AbortSignal so stale requests can be cancelled.\n */\n\n/** The base shape of a load request. Components extend this with their own fields. */\nexport interface LoadRequest {\n\t/** 1-based page number to load */\n\tpage?: number;\n\t/** Number of items per page */\n\tpageSize?: number;\n\t/** Search or filter text entered by the user */\n\tsearchText?: string;\n\t/** The field to sort by */\n\tsortBy?: string;\n\t/** The direction to sort in */\n\tsortDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * The result of a load: the items for the current request, and optionally\n * the total count (needed for paged components to show a pager).\n */\nexport interface LoadResult<T = any> {\n\titems: T[];\n\t/** The total number of items across all pages, if known */\n\ttotal?: number;\n}\n\n/**\n * Reads data for a request. May return a promise or a plain result, and may\n * return just an array of items when no total is available.\n */\nexport type Loader<T = any, TRequest extends LoadRequest = LoadRequest> = (\n\trequest: TRequest,\n\tsignal?: AbortSignal,\n) => Promise<LoadResult<T> | T[]> | LoadResult<T> | T[];\n\n/** Wraps a bare array in a LoadResult so consumers always get the same shape */\nexport function normalizeLoadResult<T>(result: LoadResult<T> | T[]): LoadResult<T> {\n\treturn Array.isArray(result) ? { items: result } : result;\n}\n\nexport interface ItemLoaderOptions<T = any, TRequest extends LoadRequest = LoadRequest> {\n\t/** The loader function to fetch items */\n\tload: Loader<T, TRequest>;\n\t/**\n\t * Builds the request for the current fetch. Called inside the async\n\t * getter, so reads of reactive state here re-fetch when they change.\n\t */\n\tgetRequest: () => TRequest;\n\t/** Called after each successful load with the normalized result */\n\tonload?: (result: LoadResult<T>) => void;\n}\n\n/** Reactive loading state returned by createItemLoader */\nexport interface ItemLoaderState<T = any> {\n\t/** The full result of the current load; suspends while a fetch is pending */\n\treadonly result: LoadResult<T> | undefined;\n\t/** The loaded items; suspends while a fetch is pending */\n\treadonly items: T[];\n}\n\n/**\n * Shared loading state for components that read items from a network loader\n * (DataGrid, ComboBox auto-complete etc). Read the returned state's `items`\n * or `result` inside an `@await` boundary: while a fetch is pending the read\n * suspends, and when dependencies read inside `getRequest` change the fetch\n * re-runs.\n *\n * For lazy loading (fetch only once some condition is met), gate the whole\n * rendering of the region that reads this loader behind that condition\n * (`@if`), so the `@await` boundary -- and with it the first fetch --\n * comes into existence when the condition flips.\n *\n * ```\n * let $load = createItemLoader({\n * \tload: $props.load,\n * \tgetRequest: () => ({ searchText: $state.searchText }),\n * });\n * @await { ...$load.items... } with { <span>Loading…</span> }\n * ```\n */\nexport function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(\n\toptions: ItemLoaderOptions<T, TRequest>,\n): ItemLoaderState<T> {\n\t// The in-flight fetch's controller: a re-run (search text changed, item\n\t// expanded) aborts it, so loaders that take the signal can cancel the\n\t// wire request. The $async generation guard discards stale results\n\t// application-side either way.\n\tlet abort: AbortController | null = null;\n\n\treturn $watch({\n\t\tget result(): LoadResult<T> | undefined {\n\t\t\treturn $async(() => {\n\t\t\t\tabort?.abort();\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\tabort = controller;\n\t\t\t\tconst promise = Promise.resolve(options.load(options.getRequest(), controller.signal))\n\t\t\t\t\t.then(normalizeLoadResult)\n\t\t\t\t\t.catch((error) => {\n\t\t\t\t\t\t// Our own abort is not an error — the superseding fetch\n\t\t\t\t\t\t// owns the UI, so this one never settles instead of\n\t\t\t\t\t\t// rejecting into the await boundary\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\treturn new Promise<LoadResult<T>>(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t// Report successful loads to the consumer; failures surface\n\t\t\t\t// through the component's error boundary, not this chain\n\t\t\t\tpromise.then(\n\t\t\t\t\t(r) => options.onload?.(r),\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t\treturn promise as Promise<LoadResult<T>>;\n\t\t\t});\n\t\t},\n\t\tget items(): T[] {\n\t\t\treturn this.result?.items ?? [];\n\t\t},\n\t});\n}\n"],"mappings":";;;AA8CA,SAAgB,oBAAuB,QAA4C;CAClF,OAAO,MAAM,QAAQ,MAAM,IAAI,EAAE,OAAO,OAAO,IAAI;AACpD;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,iBACf,SACqB;CAKrB,IAAI,QAAgC;CAEpC,OAAO,OAAO;EACb,IAAI,SAAoC;GACvC,OAAO,aAAa;IACnB,OAAO,MAAM;IACb,MAAM,aAAa,IAAI,gBAAgB;IACvC,QAAQ;IACR,MAAM,UAAU,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,WAAW,GAAG,WAAW,MAAM,CAAC,CAAC,CACpF,KAAK,mBAAmB,CAAC,CACzB,OAAO,UAAU;KAIjB,IAAI,WAAW,OAAO,SACrB,OAAO,IAAI,cAA6B,CAAC,CAAC;KAE3C,MAAM;IACP,CAAC;IAGF,QAAQ,MACN,MAAM,QAAQ,SAAS,CAAC,SACnB,CAAC,CACR;IACA,OAAO;GACR,CAAC;EACF;EACA,IAAI,QAAa;GAChB,OAAO,KAAK,QAAQ,SAAS,CAAC;EAC/B;CACD,CAAC;AACF"}
@@ -1,4 +1,4 @@
1
- import { $watch } from "@torpor/view";
1
+ import { $batch, $watch } from "@torpor/view";
2
2
  import type DataSeries from "../Charts/DataSeries";
3
3
  import {
4
4
  calculateItemWidth,
@@ -196,20 +196,29 @@ export function createChartLayout(options: ChartLayoutOptions): ChartLayout {
196
196
  const claims = this.claims as Record<string, SpaceClaim>;
197
197
  const current = claims[id];
198
198
  if (current && current.side === side && current.size === size) return;
199
- claims[id] = { side, size };
200
- this.claimsVersion++;
199
+ // One claim change is one state transition: adding a key to the
200
+ // claims object notifies both the per-key signal and the key-set
201
+ // (ownKeys) signal, so the writes are batched to a single flush
202
+ $batch(() => {
203
+ claims[id] = { side, size };
204
+ this.claimsVersion++;
205
+ });
201
206
  },
202
207
  release(id: string) {
203
208
  const claims = this.claims as Record<string, SpaceClaim>;
204
209
  if (!claims[id]) return;
205
- delete claims[id];
206
- this.claimsVersion++;
210
+ $batch(() => {
211
+ delete claims[id];
212
+ this.claimsVersion++;
213
+ });
207
214
  },
208
215
  announceMax(id: string, value: number) {
209
216
  const claims = this.maxClaims as Record<string, number>;
210
217
  if (claims[id] === value) return;
211
- claims[id] = value;
212
- this.maxVersion++;
218
+ $batch(() => {
219
+ claims[id] = value;
220
+ this.maxVersion++;
221
+ });
213
222
  },
214
223
 
215
224
  setTextSize(width: number, height: number) {
@@ -27,17 +27,42 @@ export interface HoverRevealOptions {
27
27
  hoverDelay?: number;
28
28
  /** Milliseconds to wait after the pointer leaves before closing (default 300) */
29
29
  exitGrace?: number;
30
+ /**
31
+ * How taps on touch screens open the popout (hover never fires on touch).
32
+ * - "auto" (default): tapping the trigger's inert surface opens it;
33
+ * tapping an interactive control inside the trigger (a button, link,
34
+ * …) runs the control's action and does NOT open the popout.
35
+ * - "open": any tap opens it, even over embedded controls — for pure
36
+ * hovercards whose content is the whole point.
37
+ * - "ignore": taps never open it — the component provides its own touch
38
+ * trigger.
39
+ */
40
+ touchBehavior?: "auto" | "open" | "ignore";
30
41
  }
31
42
 
32
43
  export interface HoverRevealHandlers {
33
- /** Handles the pointer entering the trigger */
34
- handleEnter: () => void;
44
+ /**
45
+ * Handles the pointer entering the trigger. Returns false when the enter
46
+ * was suppressed (a touch tap that shouldn't open the popout), so callers
47
+ * with their own enter bookkeeping (e.g. Contextual's anchor positioning)
48
+ * can skip it too.
49
+ */
50
+ handleEnter: () => boolean;
35
51
  /** Handles the pointer leaving the trigger; closes unless it moved into the content element */
36
52
  handleLeave: (e: MouseEvent | FocusEvent) => void;
37
53
  /** Handles focus landing on the trigger (opens immediately) */
38
54
  handleFocus: () => void;
39
55
  /** Handles focus leaving the trigger (closes unless focus moved into the content element) */
40
56
  handleBlur: (e: FocusEvent) => void;
57
+ /**
58
+ * Handles a pointerdown on the trigger. Touch taps synthesize the
59
+ * mouseenter/focus sequence the hover machine reacts to — but a tap on an
60
+ * interactive control is an *action*, not a request to see the popout, so
61
+ * this records the modality and target for `handleEnter`/`handleFocus` to
62
+ * discriminate (the compatibility mouse events carry no pointerType, and
63
+ * focus carries none at all).
64
+ */
65
+ handlePointerDown: (e: PointerEvent) => void;
41
66
  /** Cancels pending open/close timers */
42
67
  dispose: () => void;
43
68
  }
@@ -50,10 +75,45 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
50
75
  const getContent = options.getContent ?? (() => undefined);
51
76
  const hoverDelay = options.hoverDelay ?? 500;
52
77
  const exitGrace = options.exitGrace ?? 300;
78
+ const touchBehavior = options.touchBehavior ?? "auto";
53
79
 
54
80
  let openTimer: ReturnType<typeof setTimeout> | undefined;
55
81
  let closeTimer: ReturnType<typeof setTimeout> | undefined;
56
82
 
83
+ // The last touch/pen pointerdown on the trigger: a tap synthesizes the
84
+ // mouseenter and focus the machine reacts to, so the pointerdown is the
85
+ // only place where the input modality — and the tapped control — is
86
+ // observable. Time-boxed rather than reset manually, so a stale tap can't
87
+ // suppress a later real mouse hover for more than a moment.
88
+ const TOUCH_WINDOW = 1000;
89
+ let touchTapAt = 0;
90
+ let touchTapInteractive = false;
91
+
92
+ // Controls whose activation is an action in its own right: tapping them
93
+ // must not also reveal the popout ("don't punish the action"). Inert
94
+ // surfaces fall through, so the tap fallback still works for pure content.
95
+ const INTERACTIVE =
96
+ "button, a, input, select, textarea, label, [role='button'], [role='link'], [role='menuitem'], [role='tab'], [role='option'], [role='checkbox'], [role='radio'], [role='switch']";
97
+
98
+ function touchSuppressesEnter(): boolean {
99
+ if (Date.now() - touchTapAt > TOUCH_WINDOW) return false;
100
+ if (touchBehavior === "open") return false;
101
+ if (touchBehavior === "ignore") return true;
102
+ return touchTapInteractive;
103
+ }
104
+
105
+ /**
106
+ * Focus is only suppressed in "ignore" mode: in "auto", a tap on an
107
+ * embedded control focuses the *control* (focus doesn't bubble to the
108
+ * trigger), so the trigger's focus handler only ever runs for inert
109
+ * taps — which are exactly the fallback that should open — and for
110
+ * keyboard focus, which must always open.
111
+ */
112
+ function touchSuppressesFocus(): boolean {
113
+ if (touchBehavior !== "ignore") return false;
114
+ return Date.now() - touchTapAt <= TOUCH_WINDOW;
115
+ }
116
+
57
117
  // The content element currently watched for pointer/focus leaving it. It
58
118
  // is attached once the pointer or focus enters the content (which cancels
59
119
  // the trigger's close timer), so that leaving the content arms a close
@@ -183,7 +243,13 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
183
243
 
184
244
  return {
185
245
  handleEnter() {
186
- if (disabled()) return;
246
+ if (disabled()) return false;
247
+ if (touchSuppressesEnter()) {
248
+ // A touch tap on an interactive control (or with "ignore"):
249
+ // the tap runs the control's action; it doesn't request the
250
+ // popout. Don't resume a closing popout or arm the timer
251
+ return false;
252
+ }
187
253
 
188
254
  if (closeTimer !== undefined) {
189
255
  clearTimeout(closeTimer);
@@ -191,11 +257,11 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
191
257
  stopListening();
192
258
  unwatchContent();
193
259
  }
194
- if (isVisible()) return;
260
+ if (isVisible()) return true;
195
261
 
196
262
  if (hoverDelay <= 0) {
197
263
  reveal();
198
- return;
264
+ return true;
199
265
  }
200
266
  if (openTimer === undefined) {
201
267
  openTimer = setTimeout(() => {
@@ -203,6 +269,7 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
203
269
  reveal();
204
270
  }, hoverDelay);
205
271
  }
272
+ return true;
206
273
  },
207
274
 
208
275
  handleLeave(_e) {
@@ -218,6 +285,21 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
218
285
  scheduleClose();
219
286
  },
220
287
 
288
+ handlePointerDown(e: PointerEvent) {
289
+ if (disabled()) return;
290
+ if (e.pointerType !== "touch" && e.pointerType !== "pen") return;
291
+
292
+ const target = e.target as Element | null;
293
+ const interactive = target?.closest?.(INTERACTIVE) != null;
294
+ touchTapAt = Date.now();
295
+ touchTapInteractive = interactive;
296
+ if (touchSuppressesEnter()) {
297
+ // A tap that shouldn't reveal the popout must also cancel an
298
+ // open armed by the synthesized mouseenter that precedes it
299
+ cancelPendingOpen();
300
+ }
301
+ },
302
+
221
303
  handleFocus() {
222
304
  if (disabled()) return;
223
305
 
@@ -228,6 +310,12 @@ export function createHoverReveal(options: HoverRevealOptions): HoverRevealHandl
228
310
  return;
229
311
  }
230
312
 
313
+ // A touch tap that shouldn't reveal the popout focuses the
314
+ // trigger too (tapping its inert surface); don't open
315
+ if (touchSuppressesFocus()) {
316
+ return;
317
+ }
318
+
231
319
  if (closeTimer !== undefined) {
232
320
  clearTimeout(closeTimer);
233
321
  closeTimer = undefined;
@@ -91,12 +91,29 @@ export interface ItemLoaderState<T = any> {
91
91
  export function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(
92
92
  options: ItemLoaderOptions<T, TRequest>,
93
93
  ): ItemLoaderState<T> {
94
+ // The in-flight fetch's controller: a re-run (search text changed, item
95
+ // expanded) aborts it, so loaders that take the signal can cancel the
96
+ // wire request. The $async generation guard discards stale results
97
+ // application-side either way.
98
+ let abort: AbortController | null = null;
99
+
94
100
  return $watch({
95
101
  get result(): LoadResult<T> | undefined {
96
102
  return $async(() => {
97
- const promise = Promise.resolve(options.load(options.getRequest())).then(
98
- normalizeLoadResult,
99
- );
103
+ abort?.abort();
104
+ const controller = new AbortController();
105
+ abort = controller;
106
+ const promise = Promise.resolve(options.load(options.getRequest(), controller.signal))
107
+ .then(normalizeLoadResult)
108
+ .catch((error) => {
109
+ // Our own abort is not an error — the superseding fetch
110
+ // owns the UI, so this one never settles instead of
111
+ // rejecting into the await boundary
112
+ if (controller.signal.aborted) {
113
+ return new Promise<LoadResult<T>>(() => {});
114
+ }
115
+ throw error;
116
+ });
100
117
  // Report successful loads to the consumer; failures surface
101
118
  // through the component's error boundary, not this chain
102
119
  promise.then(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/ui",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Accessible, unstyled components for use in your Torpor front-end",
5
5
  "type": "module",
6
6
  "torpor": true,
@@ -181,15 +181,15 @@
181
181
  "author": "",
182
182
  "license": "ISC",
183
183
  "dependencies": {
184
- "@torpor/unplugin": "^1.2.9",
185
- "@torpor/view": "^1.2.6"
184
+ "@torpor/unplugin": "^1.2.11",
185
+ "@torpor/view": "^1.3.1"
186
186
  },
187
187
  "devDependencies": {
188
188
  "@testing-library/dom": "^10.4.2",
189
189
  "@testing-library/jest-dom": "^7.0.1",
190
190
  "@testing-library/user-event": "^14.6.8",
191
- "@torpor/check": "^1.0.14",
192
- "@torpor/prettier": "^1.0.14",
191
+ "@torpor/check": "^1.0.16",
192
+ "@torpor/prettier": "^1.0.16",
193
193
  "@types/jsdom": "^30.0.0",
194
194
  "@types/node": "^26.6.5",
195
195
  "@typescript/native-preview": "7.0.0-dev.20260707.2",