@luxalgo/vela-ui 0.4.2 → 0.4.4

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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to `@luxalgo/vela-ui`, newest first. Vela's own changes, including how it
4
4
  uses the kit, are in [Vela's changelog](../../CHANGELOG.md).
5
5
 
6
+ ## [0.4.4]
7
+
8
+ ### Fixed
9
+
10
+ - **A dialog opened on top of another dialog stacks above it.** Opening a dialog that was
11
+ already mounted earlier in the host now moves its backdrop and positioner to the end of
12
+ the host, so nested dialogs such as a symbol picker opened from indicator settings appear
13
+ in front of the dialog that triggered them.
14
+
15
+ ## [0.4.3]
16
+
17
+ ### Added
18
+
19
+ - **A dropdown menu opens against any box.** `openAt` takes a rectangle as well as a point,
20
+ such as the box of a button the menu does not own as its trigger:
21
+ `menu.openAt(button.getBoundingClientRect())`. The list opens on the menu's `side` of the
22
+ box, with its `align` and offsets, and on the box's other side when that one lacks room,
23
+ so it never covers the button. It keeps its place in its host like any other open menu.
24
+
25
+ ### Fixed
26
+
27
+ - **An open menu follows its host when the page scrolls.** A dropdown menu opened from its
28
+ trigger stayed at the same place on screen while the page scrolled the trigger away. A
29
+ menu opened with `openAt`, a context menu included, jumped to the top of the window. An
30
+ open menu now keeps its place inside its host, whichever way it opened, and still stays
31
+ where it is when its trigger moves inside the host.
32
+
6
33
  ## [0.4.2]
7
34
 
8
35
  ### Added
@@ -53,8 +53,11 @@ var Surface = class _Surface {
53
53
  this.items = [];
54
54
  /** Branch item id → the surface it opens. */
55
55
  this.subs = /* @__PURE__ */ new Map();
56
- /** Trigger rect captured when this level opened — the list stays put if the
57
- * trigger then moves (favorite chips shifting the caret). */
56
+ /** What this level opened against, as an offset inside the host: its trigger's rect, or
57
+ * the point or rectangle `openAt` was given. Held in the host's space, not the
58
+ * viewport's, so the list keeps its place in the host: a trigger that then moves leaves
59
+ * it still (favorite chips shifting the caret), and a page that scrolls the host carries
60
+ * it along. Null on a submenu, which follows its row. */
58
61
  this.pinnedAnchor = null;
59
62
  /** The open state last announced — see {@link announce}. */
60
63
  this.shown = false;
@@ -82,14 +85,10 @@ var Surface = class _Surface {
82
85
  id: opts.id,
83
86
  ...opts.placement,
84
87
  onSelect: (id) => this.onSelect(id),
85
- getAnchorRect: () => this.pinnedAnchor,
88
+ getAnchorRect: () => this.anchorRect(),
86
89
  onOpenChange: (open) => {
87
- if (open && trigger) {
88
- const r = trigger.getBoundingClientRect();
89
- this.pinnedAnchor = { x: r.x, y: r.y, width: r.width, height: r.height };
90
- } else {
91
- this.pinnedAnchor = null;
92
- }
90
+ if (!open) this.pinnedAnchor = null;
91
+ else if (trigger && !this.pinnedAnchor) this.pin(trigger.getBoundingClientRect());
93
92
  opts.onOpenChange?.(open);
94
93
  },
95
94
  triggerId: opts.triggerId
@@ -132,6 +131,18 @@ var Surface = class _Surface {
132
131
  get api() {
133
132
  return this.ctrl.connect(this.handle.service);
134
133
  }
134
+ /** Anchor this level to `rect`, given in viewport coordinates. */
135
+ pin(rect) {
136
+ const origin = this.host.getBoundingClientRect();
137
+ this.pinnedAnchor = { x: rect.x - origin.x, y: rect.y - origin.y, width: rect.width, height: rect.height };
138
+ }
139
+ /** The anchor in viewport coordinates, where the host stands now. */
140
+ anchorRect() {
141
+ const anchor = this.pinnedAnchor;
142
+ if (!anchor) return null;
143
+ const origin = this.host.getBoundingClientRect();
144
+ return { x: origin.x + anchor.x, y: origin.y + anchor.y, width: anchor.width, height: anchor.height };
145
+ }
135
146
  announce(open) {
136
147
  this.shown = open;
137
148
  announceSurface(this.list, open, "menu", this.opener);
@@ -328,11 +339,12 @@ var DropdownMenu = class {
328
339
  open() {
329
340
  this.api.setOpen(true);
330
341
  }
331
- /** Open anchored to a viewport point (context menus). */
332
- openAt(clientX, clientY) {
342
+ openAt(at, clientY = 0) {
343
+ const rect = typeof at === "number" ? { x: at, y: clientY, width: 0, height: 0 } : { x: at.x, y: at.y, width: at.width, height: at.height };
333
344
  const api = this.api;
345
+ queueMicrotask(() => this.root.pin(rect));
334
346
  api.setOpen(true);
335
- api.reposition({ getAnchorRect: () => ({ x: clientX, y: clientY, width: 0, height: 0 }) });
347
+ api.reposition({ getAnchorRect: () => this.root.anchorRect() });
336
348
  }
337
349
  close() {
338
350
  this.api.setOpen(false);
@@ -1,4 +1,4 @@
1
- import { DropdownMenu } from './chunk-64XYQQBY.js';
1
+ import { DropdownMenu } from './chunk-H3YWXJNS.js';
2
2
  import { kitTranslator } from './chunk-FVH6L7FM.js';
3
3
  import './chunk-FN2BUFNM.js';
4
4
  import './chunk-J2QJATCD.js';
package/dist/dialog.js CHANGED
@@ -174,6 +174,9 @@ var Dialog = class {
174
174
  if (api.open) {
175
175
  this.exit?.cancel();
176
176
  this.exit = null;
177
+ if (!this.wasOpen && this.positioner.parentNode === host && host.lastElementChild !== this.positioner) {
178
+ host.append(this.backdrop, this.positioner);
179
+ }
177
180
  this.setShown(true);
178
181
  } else if (closing) {
179
182
  this.holdExit();
@@ -106,6 +106,16 @@ declare class DropdownMenu {
106
106
  open(): void;
107
107
  /** Open anchored to a viewport point (context menus). */
108
108
  openAt(clientX: number, clientY: number): void;
109
+ /** Open against a rectangle in viewport coordinates, such as the box of a button the menu
110
+ * does not own as its trigger (`button.getBoundingClientRect()`): on the menu's side of
111
+ * it, with its alignment and offsets, and on the rectangle's other side when that one
112
+ * lacks room. */
113
+ openAt(rect: {
114
+ x: number;
115
+ y: number;
116
+ width: number;
117
+ height: number;
118
+ }): void;
109
119
  close(): void;
110
120
  /** Swap the item descriptors (e.g. checked states) and re-project. */
111
121
  setItems(items: readonly MenuItemDescriptor[]): void;
@@ -1,4 +1,4 @@
1
- export { DropdownMenu, createDropdownMenu, dropdownMenuController, dropdownMenuDef } from './chunk-64XYQQBY.js';
1
+ export { DropdownMenu, createDropdownMenu, dropdownMenuController, dropdownMenuDef } from './chunk-H3YWXJNS.js';
2
2
  import './chunk-FVH6L7FM.js';
3
3
  import './chunk-FN2BUFNM.js';
4
4
  import './chunk-J2QJATCD.js';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@luxalgo/vela-ui",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "tokens": [
5
5
  "space-1",
6
6
  "space-2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "@luxalgo/vela-ui 0.4.2 theme",
3
+ "title": "@luxalgo/vela-ui 0.4.4 theme",
4
4
  "description": "The input of createTheme. Every field is optional: an empty theme is the dark theme.",
5
5
  "type": "object",
6
6
  "additionalProperties": false,
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # @luxalgo/vela-ui 0.4.2
1
+ # @luxalgo/vela-ui 0.4.4
2
2
 
3
3
  > The component kit of Vela: one file per component, Zag state machines for behavior, CSS in
4
4
  > cascade layers over design tokens, and one typed theme config.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxalgo/vela-ui",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "The component kit of Vela: one file per component, Zag state machines for behavior, CSS in cascade layers over design tokens.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "LuxAlgo",
@@ -433,6 +433,11 @@ export class Dialog {
433
433
  if (api.open) {
434
434
  this.exit?.cancel();
435
435
  this.exit = null;
436
+ // A dialog opened on top of an already-open sibling (for example a symbol picker
437
+ // launched from indicator settings) must stack above it in DOM order.
438
+ if (!this.wasOpen && this.positioner.parentNode === host && host.lastElementChild !== this.positioner) {
439
+ host.append(this.backdrop, this.positioner);
440
+ }
436
441
  this.setShown(true);
437
442
  } else if (closing) {
438
443
  this.holdExit();
@@ -394,6 +394,14 @@ interface SurfaceOptions {
394
394
  submenu?: boolean;
395
395
  }
396
396
 
397
+ /** The rectangle a menu level is placed against. */
398
+ interface AnchorRect {
399
+ x: number;
400
+ y: number;
401
+ width: number;
402
+ height: number;
403
+ }
404
+
397
405
  /** How far a row sits inside its list: the list's padding (6px) plus its border (1px). */
398
406
  const ROW_INSET_PX = 7;
399
407
  /** The space between a submenu and the list it opened from. */
@@ -420,9 +428,12 @@ class Surface {
420
428
  private items: readonly MenuItemDescriptor[] = [];
421
429
  /** Branch item id → the surface it opens. */
422
430
  private readonly subs = new Map<string, Surface>();
423
- /** Trigger rect captured when this level opened — the list stays put if the
424
- * trigger then moves (favorite chips shifting the caret). */
425
- private pinnedAnchor: { x: number; y: number; width: number; height: number } | null = null;
431
+ /** What this level opened against, as an offset inside the host: its trigger's rect, or
432
+ * the point or rectangle `openAt` was given. Held in the host's space, not the
433
+ * viewport's, so the list keeps its place in the host: a trigger that then moves leaves
434
+ * it still (favorite chips shifting the caret), and a page that scrolls the host carries
435
+ * it along. Null on a submenu, which follows its row. */
436
+ private pinnedAnchor: AnchorRect | null = null;
426
437
  /** The open state last announced — see {@link announce}. */
427
438
  private shown = false;
428
439
  /** The list's exit animation after a close; a reopen cancels it. */
@@ -454,14 +465,11 @@ class Surface {
454
465
  id: opts.id,
455
466
  ...opts.placement,
456
467
  onSelect: (id) => this.onSelect(id),
457
- getAnchorRect: () => this.pinnedAnchor,
468
+ getAnchorRect: () => this.anchorRect(),
458
469
  onOpenChange: (open) => {
459
- if (open && trigger) {
460
- const r = trigger.getBoundingClientRect();
461
- this.pinnedAnchor = { x: r.x, y: r.y, width: r.width, height: r.height };
462
- } else {
463
- this.pinnedAnchor = null;
464
- }
470
+ // An anchor already there is the point this opening was asked at.
471
+ if (!open) this.pinnedAnchor = null;
472
+ else if (trigger && !this.pinnedAnchor) this.pin(trigger.getBoundingClientRect());
465
473
  opts.onOpenChange?.(open);
466
474
  },
467
475
  triggerId: opts.triggerId,
@@ -512,6 +520,20 @@ class Surface {
512
520
  return this.ctrl.connect(this.handle.service);
513
521
  }
514
522
 
523
+ /** Anchor this level to `rect`, given in viewport coordinates. */
524
+ pin(rect: AnchorRect): void {
525
+ const origin = this.host.getBoundingClientRect();
526
+ this.pinnedAnchor = { x: rect.x - origin.x, y: rect.y - origin.y, width: rect.width, height: rect.height };
527
+ }
528
+
529
+ /** The anchor in viewport coordinates, where the host stands now. */
530
+ anchorRect(): AnchorRect | null {
531
+ const anchor = this.pinnedAnchor;
532
+ if (!anchor) return null;
533
+ const origin = this.host.getBoundingClientRect();
534
+ return { x: origin.x + anchor.x, y: origin.y + anchor.y, width: anchor.width, height: anchor.height };
535
+ }
536
+
515
537
  private announce(open: boolean): void {
516
538
  this.shown = open;
517
539
  announceSurface(this.list, open, 'menu', this.opener);
@@ -740,10 +762,21 @@ export class DropdownMenu {
740
762
  }
741
763
 
742
764
  /** Open anchored to a viewport point (context menus). */
743
- openAt(clientX: number, clientY: number): void {
765
+ openAt(clientX: number, clientY: number): void;
766
+ /** Open against a rectangle in viewport coordinates, such as the box of a button the menu
767
+ * does not own as its trigger (`button.getBoundingClientRect()`): on the menu's side of
768
+ * it, with its alignment and offsets, and on the rectangle's other side when that one
769
+ * lacks room. */
770
+ openAt(rect: { x: number; y: number; width: number; height: number }): void;
771
+ openAt(at: number | { x: number; y: number; width: number; height: number }, clientY = 0): void {
772
+ // Read now: the caller's rectangle may be one it goes on changing.
773
+ const rect: AnchorRect = typeof at === 'number' ? { x: at, y: clientY, width: 0, height: 0 } : { x: at.x, y: at.y, width: at.width, height: at.height };
744
774
  const api = this.api;
775
+ // Queued, as the machine's own events are: a close still under way lands first, and
776
+ // must not take this anchor with it.
777
+ queueMicrotask(() => this.root.pin(rect));
745
778
  api.setOpen(true);
746
- api.reposition({ getAnchorRect: () => ({ x: clientX, y: clientY, width: 0, height: 0 }) });
779
+ api.reposition({ getAnchorRect: () => this.root.anchorRect() });
747
780
  }
748
781
 
749
782
  close(): void {
@@ -433,6 +433,11 @@ export class Dialog {
433
433
  if (api.open) {
434
434
  this.exit?.cancel();
435
435
  this.exit = null;
436
+ // A dialog opened on top of an already-open sibling (for example a symbol picker
437
+ // launched from indicator settings) must stack above it in DOM order.
438
+ if (!this.wasOpen && this.positioner.parentNode === host && host.lastElementChild !== this.positioner) {
439
+ host.append(this.backdrop, this.positioner);
440
+ }
436
441
  this.setShown(true);
437
442
  } else if (closing) {
438
443
  this.holdExit();
@@ -394,6 +394,14 @@ interface SurfaceOptions {
394
394
  submenu?: boolean;
395
395
  }
396
396
 
397
+ /** The rectangle a menu level is placed against. */
398
+ interface AnchorRect {
399
+ x: number;
400
+ y: number;
401
+ width: number;
402
+ height: number;
403
+ }
404
+
397
405
  /** How far a row sits inside its list: the list's padding (6px) plus its border (1px). */
398
406
  const ROW_INSET_PX = 7;
399
407
  /** The space between a submenu and the list it opened from. */
@@ -420,9 +428,12 @@ class Surface {
420
428
  private items: readonly MenuItemDescriptor[] = [];
421
429
  /** Branch item id → the surface it opens. */
422
430
  private readonly subs = new Map<string, Surface>();
423
- /** Trigger rect captured when this level opened — the list stays put if the
424
- * trigger then moves (favorite chips shifting the caret). */
425
- private pinnedAnchor: { x: number; y: number; width: number; height: number } | null = null;
431
+ /** What this level opened against, as an offset inside the host: its trigger's rect, or
432
+ * the point or rectangle `openAt` was given. Held in the host's space, not the
433
+ * viewport's, so the list keeps its place in the host: a trigger that then moves leaves
434
+ * it still (favorite chips shifting the caret), and a page that scrolls the host carries
435
+ * it along. Null on a submenu, which follows its row. */
436
+ private pinnedAnchor: AnchorRect | null = null;
426
437
  /** The open state last announced — see {@link announce}. */
427
438
  private shown = false;
428
439
  /** The list's exit animation after a close; a reopen cancels it. */
@@ -454,14 +465,11 @@ class Surface {
454
465
  id: opts.id,
455
466
  ...opts.placement,
456
467
  onSelect: (id) => this.onSelect(id),
457
- getAnchorRect: () => this.pinnedAnchor,
468
+ getAnchorRect: () => this.anchorRect(),
458
469
  onOpenChange: (open) => {
459
- if (open && trigger) {
460
- const r = trigger.getBoundingClientRect();
461
- this.pinnedAnchor = { x: r.x, y: r.y, width: r.width, height: r.height };
462
- } else {
463
- this.pinnedAnchor = null;
464
- }
470
+ // An anchor already there is the point this opening was asked at.
471
+ if (!open) this.pinnedAnchor = null;
472
+ else if (trigger && !this.pinnedAnchor) this.pin(trigger.getBoundingClientRect());
465
473
  opts.onOpenChange?.(open);
466
474
  },
467
475
  triggerId: opts.triggerId,
@@ -512,6 +520,20 @@ class Surface {
512
520
  return this.ctrl.connect(this.handle.service);
513
521
  }
514
522
 
523
+ /** Anchor this level to `rect`, given in viewport coordinates. */
524
+ pin(rect: AnchorRect): void {
525
+ const origin = this.host.getBoundingClientRect();
526
+ this.pinnedAnchor = { x: rect.x - origin.x, y: rect.y - origin.y, width: rect.width, height: rect.height };
527
+ }
528
+
529
+ /** The anchor in viewport coordinates, where the host stands now. */
530
+ anchorRect(): AnchorRect | null {
531
+ const anchor = this.pinnedAnchor;
532
+ if (!anchor) return null;
533
+ const origin = this.host.getBoundingClientRect();
534
+ return { x: origin.x + anchor.x, y: origin.y + anchor.y, width: anchor.width, height: anchor.height };
535
+ }
536
+
515
537
  private announce(open: boolean): void {
516
538
  this.shown = open;
517
539
  announceSurface(this.list, open, 'menu', this.opener);
@@ -740,10 +762,21 @@ export class DropdownMenu {
740
762
  }
741
763
 
742
764
  /** Open anchored to a viewport point (context menus). */
743
- openAt(clientX: number, clientY: number): void {
765
+ openAt(clientX: number, clientY: number): void;
766
+ /** Open against a rectangle in viewport coordinates, such as the box of a button the menu
767
+ * does not own as its trigger (`button.getBoundingClientRect()`): on the menu's side of
768
+ * it, with its alignment and offsets, and on the rectangle's other side when that one
769
+ * lacks room. */
770
+ openAt(rect: { x: number; y: number; width: number; height: number }): void;
771
+ openAt(at: number | { x: number; y: number; width: number; height: number }, clientY = 0): void {
772
+ // Read now: the caller's rectangle may be one it goes on changing.
773
+ const rect: AnchorRect = typeof at === 'number' ? { x: at, y: clientY, width: 0, height: 0 } : { x: at.x, y: at.y, width: at.width, height: at.height };
744
774
  const api = this.api;
775
+ // Queued, as the machine's own events are: a close still under way lands first, and
776
+ // must not take this anchor with it.
777
+ queueMicrotask(() => this.root.pin(rect));
745
778
  api.setOpen(true);
746
- api.reposition({ getAnchorRect: () => ({ x: clientX, y: clientY, width: 0, height: 0 }) });
779
+ api.reposition({ getAnchorRect: () => this.root.anchorRect() });
747
780
  }
748
781
 
749
782
  close(): void {