bits-ui 2.8.0 → 2.8.2

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 (99) hide show
  1. package/dist/bits/accordion/accordion.svelte.d.ts +6 -1
  2. package/dist/bits/accordion/accordion.svelte.js +15 -5
  3. package/dist/bits/alert-dialog/components/alert-dialog-content.svelte +6 -9
  4. package/dist/bits/aspect-ratio/aspect-ratio.svelte.d.ts +2 -1
  5. package/dist/bits/aspect-ratio/aspect-ratio.svelte.js +3 -1
  6. package/dist/bits/avatar/avatar.svelte.d.ts +4 -1
  7. package/dist/bits/avatar/avatar.svelte.js +9 -3
  8. package/dist/bits/calendar/calendar.svelte.d.ts +15 -1
  9. package/dist/bits/calendar/calendar.svelte.js +42 -14
  10. package/dist/bits/calendar/components/calendar-next-button.svelte +3 -1
  11. package/dist/bits/calendar/components/calendar-prev-button.svelte +3 -1
  12. package/dist/bits/checkbox/checkbox.svelte.d.ts +4 -1
  13. package/dist/bits/checkbox/checkbox.svelte.js +9 -3
  14. package/dist/bits/collapsible/collapsible.svelte.d.ts +4 -1
  15. package/dist/bits/collapsible/collapsible.svelte.js +9 -3
  16. package/dist/bits/command/command.svelte.d.ts +13 -1
  17. package/dist/bits/command/command.svelte.js +36 -12
  18. package/dist/bits/context-menu/components/context-menu-content.svelte +1 -1
  19. package/dist/bits/date-field/date-field.svelte.d.ts +8 -2
  20. package/dist/bits/date-field/date-field.svelte.js +18 -6
  21. package/dist/bits/date-range-field/date-range-field.svelte.d.ts +3 -1
  22. package/dist/bits/date-range-field/date-range-field.svelte.js +6 -2
  23. package/dist/bits/dialog/components/dialog-content.svelte +5 -7
  24. package/dist/bits/dialog/dialog.svelte.d.ts +9 -1
  25. package/dist/bits/dialog/dialog.svelte.js +33 -18
  26. package/dist/bits/dropdown-menu/components/dropdown-menu-content.svelte +3 -2
  27. package/dist/bits/label/label.svelte.d.ts +2 -1
  28. package/dist/bits/label/label.svelte.js +3 -1
  29. package/dist/bits/link-preview/link-preview.svelte.d.ts +3 -1
  30. package/dist/bits/link-preview/link-preview.svelte.js +6 -2
  31. package/dist/bits/menu/menu.svelte.d.ts +12 -1
  32. package/dist/bits/menu/menu.svelte.js +38 -26
  33. package/dist/bits/menubar/components/menubar-trigger.svelte +4 -3
  34. package/dist/bits/menubar/menubar.svelte.d.ts +4 -3
  35. package/dist/bits/menubar/menubar.svelte.js +9 -6
  36. package/dist/bits/meter/meter.svelte.d.ts +2 -1
  37. package/dist/bits/meter/meter.svelte.js +3 -1
  38. package/dist/bits/navigation-menu/components/navigation-menu-link.svelte +2 -1
  39. package/dist/bits/navigation-menu/components/navigation-menu-trigger.svelte +2 -1
  40. package/dist/bits/navigation-menu/navigation-menu.svelte.d.ts +14 -3
  41. package/dist/bits/navigation-menu/navigation-menu.svelte.js +33 -13
  42. package/dist/bits/pagination/pagination.svelte.d.ts +4 -1
  43. package/dist/bits/pagination/pagination.svelte.js +9 -3
  44. package/dist/bits/pin-input/pin-input.svelte.d.ts +4 -1
  45. package/dist/bits/pin-input/pin-input.svelte.js +8 -3
  46. package/dist/bits/popover/popover.svelte.d.ts +4 -1
  47. package/dist/bits/popover/popover.svelte.js +9 -3
  48. package/dist/bits/progress/progress.svelte.d.ts +2 -1
  49. package/dist/bits/progress/progress.svelte.js +3 -1
  50. package/dist/bits/radio-group/radio-group.svelte.d.ts +3 -1
  51. package/dist/bits/radio-group/radio-group.svelte.js +6 -2
  52. package/dist/bits/range-calendar/range-calendar.svelte.d.ts +4 -1
  53. package/dist/bits/range-calendar/range-calendar.svelte.js +9 -3
  54. package/dist/bits/rating-group/rating-group.svelte.d.ts +3 -1
  55. package/dist/bits/rating-group/rating-group.svelte.js +6 -2
  56. package/dist/bits/scroll-area/scroll-area.svelte.d.ts +8 -1
  57. package/dist/bits/scroll-area/scroll-area.svelte.js +20 -7
  58. package/dist/bits/select/select.svelte.d.ts +10 -1
  59. package/dist/bits/select/select.svelte.js +27 -9
  60. package/dist/bits/separator/separator.svelte.d.ts +2 -1
  61. package/dist/bits/separator/separator.svelte.js +3 -1
  62. package/dist/bits/slider/slider.svelte.d.ts +7 -1
  63. package/dist/bits/slider/slider.svelte.js +18 -6
  64. package/dist/bits/switch/switch.svelte.d.ts +3 -1
  65. package/dist/bits/switch/switch.svelte.js +6 -2
  66. package/dist/bits/tabs/tabs.svelte.d.ts +5 -1
  67. package/dist/bits/tabs/tabs.svelte.js +12 -4
  68. package/dist/bits/time-field/time-field.svelte.d.ts +7 -1
  69. package/dist/bits/time-field/time-field.svelte.js +18 -6
  70. package/dist/bits/time-range-field/time-range-field.svelte.d.ts +3 -1
  71. package/dist/bits/time-range-field/time-range-field.svelte.js +6 -2
  72. package/dist/bits/toggle/toggle.svelte.d.ts +2 -1
  73. package/dist/bits/toggle/toggle.svelte.js +3 -1
  74. package/dist/bits/toggle-group/toggle-group.svelte.d.ts +3 -1
  75. package/dist/bits/toggle-group/toggle-group.svelte.js +6 -2
  76. package/dist/bits/toolbar/toolbar.svelte.d.ts +6 -1
  77. package/dist/bits/toolbar/toolbar.svelte.js +15 -5
  78. package/dist/bits/tooltip/tooltip.svelte.d.ts +3 -1
  79. package/dist/bits/tooltip/tooltip.svelte.js +6 -2
  80. package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.d.ts +9 -0
  81. package/dist/bits/utilities/floating-layer/use-floating-layer.svelte.js +6 -3
  82. package/dist/bits/utilities/focus-scope/focus-scope-manager.d.ts +12 -0
  83. package/dist/bits/utilities/focus-scope/focus-scope-manager.js +40 -0
  84. package/dist/bits/utilities/focus-scope/focus-scope.svelte +6 -8
  85. package/dist/bits/utilities/focus-scope/focus-scope.svelte.d.ts +1 -0
  86. package/dist/bits/utilities/focus-scope/focus-scope.svelte.js +204 -0
  87. package/dist/bits/utilities/focus-scope/types.d.ts +2 -6
  88. package/dist/bits/utilities/popper-layer/popper-layer-inner.svelte +2 -2
  89. package/dist/internal/focus.js +1 -1
  90. package/dist/internal/should-enable-focus-trap.d.ts +5 -0
  91. package/dist/internal/should-enable-focus-trap.js +5 -0
  92. package/dist/internal/types.d.ts +2 -1
  93. package/package.json +2 -2
  94. package/dist/bits/utilities/focus-scope/focus-scope-stack.svelte.d.ts +0 -14
  95. package/dist/bits/utilities/focus-scope/focus-scope-stack.svelte.js +0 -50
  96. package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.d.ts +0 -49
  97. package/dist/bits/utilities/focus-scope/use-focus-scope.svelte.js +0 -218
  98. package/dist/internal/should-trap-focus.d.ts +0 -6
  99. package/dist/internal/should-trap-focus.js +0 -5
@@ -27,12 +27,13 @@
27
27
  });
28
28
 
29
29
  const dropdownTriggerState = DropdownMenuTriggerState.create(triggerState.opts);
30
+ const triggerAttachment = attachRef(
31
+ (v: HTMLElement | null) => (dropdownTriggerState.parentMenu.triggerNode = v)
32
+ );
30
33
 
31
34
  const mergedProps = $derived(
32
35
  mergeProps(restProps, triggerState.props, {
33
- ...attachRef(
34
- (v: HTMLElement | null) => (dropdownTriggerState.parentMenu.triggerNode = v)
35
- ),
36
+ ...triggerAttachment,
36
37
  })
37
38
  );
38
39
  </script>
@@ -1,8 +1,7 @@
1
1
  import { type ReadableBox, type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
2
2
  import type { InteractOutsideBehaviorType } from "../utilities/dismissible-layer/types.js";
3
3
  import type { Direction } from "../../shared/index.js";
4
- import type { OnChangeFn, WithRefOpts } from "../../internal/types.js";
5
- import { type FocusScopeContextValue } from "../utilities/focus-scope/use-focus-scope.svelte.js";
4
+ import type { OnChangeFn, RefAttachment, WithRefOpts } from "../../internal/types.js";
6
5
  import type { FocusEventHandler, KeyboardEventHandler, PointerEventHandler } from "svelte/elements";
7
6
  import { RovingFocusGroup } from "../../internal/roving-focus-group.js";
8
7
  interface MenubarRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
@@ -16,6 +15,7 @@ export declare class MenubarRootState {
16
15
  static create(opts: MenubarRootStateOpts): MenubarRootState;
17
16
  readonly opts: MenubarRootStateOpts;
18
17
  readonly rovingFocusGroup: RovingFocusGroup;
18
+ readonly attachment: RefAttachment;
19
19
  wasOpenedByKeyboard: boolean;
20
20
  triggerIds: string[];
21
21
  valueToChangeHandler: Map<string, ReadableBox<OnChangeFn<boolean>>>;
@@ -71,6 +71,7 @@ export declare class MenubarTriggerState {
71
71
  readonly opts: MenubarTriggerStateOpts;
72
72
  readonly menu: MenubarMenuState;
73
73
  readonly root: MenubarRootState;
74
+ readonly attachment: RefAttachment;
74
75
  isFocused: boolean;
75
76
  constructor(opts: MenubarTriggerStateOpts, menu: MenubarMenuState);
76
77
  onpointerdown: PointerEventHandler<HTMLElement>;
@@ -111,7 +112,7 @@ export declare class MenubarContentState {
111
112
  readonly opts: MenubarContentStateOpts;
112
113
  readonly menu: MenubarMenuState;
113
114
  readonly root: MenubarRootState;
114
- focusScopeContext: FocusScopeContextValue;
115
+ readonly attachment: RefAttachment;
115
116
  constructor(opts: MenubarContentStateOpts, menu: MenubarMenuState);
116
117
  onCloseAutoFocus: (e: Event) => void;
117
118
  onFocusOutside: (e: FocusEvent) => void;
@@ -3,7 +3,6 @@ import { Context, watch } from "runed";
3
3
  import { createBitsAttrs, getAriaExpanded, getDataDisabled, getDataOpenClosed, } from "../../internal/attrs.js";
4
4
  import { kbd } from "../../internal/kbd.js";
5
5
  import { wrapArray } from "../../internal/arrays.js";
6
- import { FocusScopeContext, } from "../utilities/focus-scope/use-focus-scope.svelte.js";
7
6
  import { onMount } from "svelte";
8
7
  import { getFloatingContentCSSVars } from "../../internal/floating-svelte/floating-utils.svelte";
9
8
  import { RovingFocusGroup } from "../../internal/roving-focus-group.js";
@@ -19,11 +18,13 @@ export class MenubarRootState {
19
18
  }
20
19
  opts;
21
20
  rovingFocusGroup;
21
+ attachment;
22
22
  wasOpenedByKeyboard = $state(false);
23
23
  triggerIds = $state([]);
24
24
  valueToChangeHandler = new Map();
25
25
  constructor(opts) {
26
26
  this.opts = opts;
27
+ this.attachment = attachRef(this.opts.ref);
27
28
  this.rovingFocusGroup = new RovingFocusGroup({
28
29
  rootNode: this.opts.ref,
29
30
  candidateAttr: menubarAttrs.trigger,
@@ -84,7 +85,7 @@ export class MenubarRootState {
84
85
  id: this.opts.id.current,
85
86
  role: "menubar",
86
87
  [menubarAttrs.root]: "",
87
- ...attachRef(this.opts.ref),
88
+ ...this.attachment,
88
89
  }));
89
90
  }
90
91
  export class MenubarMenuState {
@@ -128,12 +129,14 @@ export class MenubarTriggerState {
128
129
  opts;
129
130
  menu;
130
131
  root;
132
+ attachment;
131
133
  isFocused = $state(false);
132
134
  #tabIndex = $state(0);
133
135
  constructor(opts, menu) {
134
136
  this.opts = opts;
135
137
  this.menu = menu;
136
138
  this.root = menu.root;
139
+ this.attachment = attachRef(this.opts.ref, (v) => (this.menu.triggerNode = v));
137
140
  onMount(() => {
138
141
  return this.root.registerTrigger(opts.id.current);
139
142
  });
@@ -205,7 +208,7 @@ export class MenubarTriggerState {
205
208
  onkeydown: this.onkeydown,
206
209
  onfocus: this.onfocus,
207
210
  onblur: this.onblur,
208
- ...attachRef(this.opts.ref, (v) => (this.menu.triggerNode = v)),
211
+ ...this.attachment,
209
212
  }));
210
213
  }
211
214
  export class MenubarContentState {
@@ -215,12 +218,12 @@ export class MenubarContentState {
215
218
  opts;
216
219
  menu;
217
220
  root;
218
- focusScopeContext;
221
+ attachment;
219
222
  constructor(opts, menu) {
220
223
  this.opts = opts;
221
224
  this.menu = menu;
222
225
  this.root = menu.root;
223
- this.focusScopeContext = FocusScopeContext.get();
226
+ this.attachment = attachRef(this.opts.ref, (v) => (this.menu.contentNode = v));
224
227
  }
225
228
  onCloseAutoFocus = (e) => {
226
229
  this.opts.onCloseAutoFocus.current(e);
@@ -283,7 +286,7 @@ export class MenubarContentState {
283
286
  onkeydown: this.onkeydown,
284
287
  "data-menu-content": "",
285
288
  [menubarAttrs.content]: "",
286
- ...attachRef(this.opts.ref, (v) => (this.menu.contentNode = v)),
289
+ ...this.attachment,
287
290
  }));
288
291
  popperProps = {
289
292
  onCloseAutoFocus: this.onCloseAutoFocus,
@@ -1,5 +1,5 @@
1
1
  import { type ReadableBoxedValues } from "svelte-toolbelt";
2
- import type { WithRefOpts } from "../../internal/types.js";
2
+ import type { RefAttachment, WithRefOpts } from "../../internal/types.js";
3
3
  interface MeterRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
4
4
  value: number;
5
5
  max: number;
@@ -9,6 +9,7 @@ interface MeterRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
9
9
  export declare class MeterRootState {
10
10
  static create(opts: MeterRootStateOpts): MeterRootState;
11
11
  readonly opts: MeterRootStateOpts;
12
+ readonly attachment: RefAttachment;
12
13
  constructor(opts: MeterRootStateOpts);
13
14
  readonly props: {
14
15
  readonly role: "meter";
@@ -9,8 +9,10 @@ export class MeterRootState {
9
9
  return new MeterRootState(opts);
10
10
  }
11
11
  opts;
12
+ attachment;
12
13
  constructor(opts) {
13
14
  this.opts = opts;
15
+ this.attachment = attachRef(this.opts.ref);
14
16
  }
15
17
  props = $derived.by(() => ({
16
18
  role: "meter",
@@ -22,6 +24,6 @@ export class MeterRootState {
22
24
  "data-max": this.opts.max.current,
23
25
  "data-min": this.opts.min.current,
24
26
  [meterAttrs.root]: "",
25
- ...attachRef(this.opts.ref),
27
+ ...this.attachment,
26
28
  }));
27
29
  }
@@ -14,6 +14,7 @@
14
14
  children,
15
15
  active = false,
16
16
  onSelect = noop,
17
+ tabindex = 0,
17
18
  ...restProps
18
19
  }: NavigationMenuLinkProps = $props();
19
20
 
@@ -27,7 +28,7 @@
27
28
  onSelect: box.with(() => onSelect),
28
29
  });
29
30
 
30
- const mergedProps = $derived(mergeProps(restProps, linkState.props));
31
+ const mergedProps = $derived(mergeProps(restProps, linkState.props, { tabindex }));
31
32
  </script>
32
33
 
33
34
  {#if child}
@@ -14,6 +14,7 @@
14
14
  children,
15
15
  child,
16
16
  ref = $bindable(null),
17
+ tabindex = 0,
17
18
  ...restProps
18
19
  }: NavigationMenuTriggerProps = $props();
19
20
 
@@ -26,7 +27,7 @@
26
27
  ),
27
28
  });
28
29
 
29
- const mergedProps = $derived(mergeProps(restProps, triggerState.props));
30
+ const mergedProps = $derived(mergeProps(restProps, triggerState.props, { tabindex }));
30
31
  </script>
31
32
 
32
33
  {#if child}
@@ -7,7 +7,7 @@ import { Context } from "runed";
7
7
  import { type Snippet } from "svelte";
8
8
  import { SvelteMap } from "svelte/reactivity";
9
9
  import { type Direction, type Orientation } from "../../shared/index.js";
10
- import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, BitsPointerEvent } from "../../internal/types.js";
10
+ import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, BitsPointerEvent, RefAttachment } from "../../internal/types.js";
11
11
  import type { FocusEventHandler, KeyboardEventHandler, MouseEventHandler, PointerEventHandler } from "svelte/elements";
12
12
  import { RovingFocusGroup } from "../../internal/roving-focus-group.js";
13
13
  declare const navigationMenuAttrs: import("../../internal/attrs.js").CreateBitsAttrsReturn<readonly ["root", "sub", "item", "list", "trigger", "content", "link", "viewport", "menu", "indicator"]>;
@@ -58,6 +58,7 @@ export declare class NavigationMenuRootState {
58
58
  #private;
59
59
  static create(opts: NavigationMenuRootStateOpts): NavigationMenuRootState;
60
60
  readonly opts: NavigationMenuRootStateOpts;
61
+ readonly attachment: RefAttachment;
61
62
  provider: NavigationMenuProviderState;
62
63
  previousValue: WritableBox<string>;
63
64
  isDelaySkipped: WritableBox<boolean>;
@@ -81,6 +82,7 @@ export declare class NavigationMenuSubState {
81
82
  readonly context: NavigationMenuProviderState;
82
83
  previousValue: WritableBox<string>;
83
84
  readonly subProvider: NavigationMenuProviderState;
85
+ readonly attachment: RefAttachment;
84
86
  constructor(opts: NavigationMenuSubStateOpts, context: NavigationMenuProviderState);
85
87
  setValue: (newValue: string, itemState: NavigationMenuItemState | null) => void;
86
88
  readonly props: {
@@ -92,10 +94,12 @@ interface NavigationMenuListStateOpts extends WithRefProps {
92
94
  }
93
95
  export declare class NavigationMenuListState {
94
96
  static create(opts: NavigationMenuListStateOpts): NavigationMenuListState;
95
- readonly opts: NavigationMenuListStateOpts;
96
- readonly context: NavigationMenuProviderState;
97
97
  wrapperId: WritableBox<string>;
98
98
  wrapperRef: WritableBox<HTMLElement | null>;
99
+ readonly opts: NavigationMenuListStateOpts;
100
+ readonly context: NavigationMenuProviderState;
101
+ readonly attachment: RefAttachment;
102
+ readonly wrapperAttachment: RefAttachment;
99
103
  listTriggers: HTMLElement[];
100
104
  readonly rovingFocusGroup: RovingFocusGroup;
101
105
  wrapperMounted: boolean;
@@ -149,8 +153,10 @@ interface NavigationMenuTriggerStateOpts extends WithRefProps, ReadableBoxedValu
149
153
  export declare class NavigationMenuTriggerState {
150
154
  static create(opts: NavigationMenuTriggerStateOpts): NavigationMenuTriggerState;
151
155
  readonly opts: NavigationMenuTriggerStateOpts;
156
+ readonly attachment: RefAttachment;
152
157
  focusProxyId: WritableBox<string>;
153
158
  focusProxyRef: WritableBox<HTMLElement | null>;
159
+ readonly focusProxyAttachment: RefAttachment;
154
160
  context: NavigationMenuProviderState;
155
161
  itemContext: NavigationMenuItemState;
156
162
  listContext: NavigationMenuListState;
@@ -203,6 +209,7 @@ export declare class NavigationMenuLinkState {
203
209
  provider: NavigationMenuProviderState;
204
210
  item: NavigationMenuItemState;
205
211
  };
212
+ readonly attachment: RefAttachment;
206
213
  isFocused: boolean;
207
214
  constructor(opts: NavigationMenuLinkStateOpts, context: {
208
215
  provider: NavigationMenuProviderState;
@@ -238,6 +245,7 @@ export declare class NavigationMenuIndicatorState {
238
245
  export declare class NavigationMenuIndicatorImplState {
239
246
  static create(opts: NavigationMenuIndicatorStateOpts): NavigationMenuIndicatorImplState;
240
247
  readonly opts: NavigationMenuIndicatorStateOpts;
248
+ readonly attachment: RefAttachment;
241
249
  context: NavigationMenuProviderState;
242
250
  listContext: NavigationMenuListState;
243
251
  position: {
@@ -278,6 +286,7 @@ export declare class NavigationMenuContentState {
278
286
  readonly context: NavigationMenuProviderState;
279
287
  readonly itemContext: NavigationMenuItemState;
280
288
  readonly listContext: NavigationMenuListState;
289
+ readonly attachment: RefAttachment;
281
290
  mounted: boolean;
282
291
  readonly open: boolean;
283
292
  readonly value: string;
@@ -304,6 +313,7 @@ export declare class NavigationMenuContentImplState {
304
313
  readonly itemContext: NavigationMenuItemState;
305
314
  readonly context: NavigationMenuProviderState;
306
315
  readonly listContext: NavigationMenuListState;
316
+ readonly attachment: RefAttachment;
307
317
  prevMotionAttribute: MotionAttribute | null;
308
318
  readonly motionAttribute: MotionAttribute | null;
309
319
  domContext: DOMContext;
@@ -327,6 +337,7 @@ export declare class NavigationMenuViewportState {
327
337
  static create(opts: NavigationMenuViewportStateOpts): NavigationMenuViewportState;
328
338
  readonly opts: NavigationMenuViewportStateOpts;
329
339
  readonly context: NavigationMenuProviderState;
340
+ readonly attachment: RefAttachment;
330
341
  readonly open: boolean;
331
342
  readonly viewportWidth: string | undefined;
332
343
  readonly viewportHeight: string | undefined;
@@ -72,6 +72,7 @@ export class NavigationMenuRootState {
72
72
  return new NavigationMenuRootState(opts);
73
73
  }
74
74
  opts;
75
+ attachment;
75
76
  provider;
76
77
  previousValue = box("");
77
78
  isDelaySkipped;
@@ -87,6 +88,7 @@ export class NavigationMenuRootState {
87
88
  });
88
89
  constructor(opts) {
89
90
  this.opts = opts;
91
+ this.attachment = attachRef(this.opts.ref);
90
92
  this.isDelaySkipped = boxAutoReset(false, {
91
93
  afterMs: this.opts.skipDelayDuration.current,
92
94
  getWindow: () => getWindow(opts.ref.current),
@@ -153,7 +155,7 @@ export class NavigationMenuRootState {
153
155
  dir: this.opts.dir.current,
154
156
  [navigationMenuAttrs.root]: "",
155
157
  [navigationMenuAttrs.menu]: "",
156
- ...attachRef(this.opts.ref),
158
+ ...this.attachment,
157
159
  }));
158
160
  }
159
161
  export class NavigationMenuSubState {
@@ -164,9 +166,11 @@ export class NavigationMenuSubState {
164
166
  context;
165
167
  previousValue = box("");
166
168
  subProvider;
169
+ attachment;
167
170
  constructor(opts, context) {
168
171
  this.opts = opts;
169
172
  this.context = context;
173
+ this.attachment = attachRef(this.opts.ref);
170
174
  this.subProvider = NavigationMenuProviderState.create({
171
175
  isRootMenu: false,
172
176
  value: this.opts.value,
@@ -194,23 +198,26 @@ export class NavigationMenuSubState {
194
198
  "data-orientation": getDataOrientation(this.opts.orientation.current),
195
199
  [navigationMenuAttrs.sub]: "",
196
200
  [navigationMenuAttrs.menu]: "",
197
- ...attachRef(this.opts.ref),
201
+ ...this.attachment,
198
202
  }));
199
203
  }
200
204
  export class NavigationMenuListState {
201
205
  static create(opts) {
202
206
  return NavigationMenuListContext.set(new NavigationMenuListState(opts, NavigationMenuProviderContext.get()));
203
207
  }
204
- opts;
205
- context;
206
208
  wrapperId = box(useId());
207
209
  wrapperRef = box(null);
210
+ opts;
211
+ context;
212
+ attachment;
213
+ wrapperAttachment = attachRef(this.wrapperRef, (v) => (this.context.indicatorTrackRef.current = v));
208
214
  listTriggers = $state.raw([]);
209
215
  rovingFocusGroup;
210
216
  wrapperMounted = $state(false);
211
217
  constructor(opts, context) {
212
218
  this.opts = opts;
213
219
  this.context = context;
220
+ this.attachment = attachRef(this.opts.ref);
214
221
  this.rovingFocusGroup = new RovingFocusGroup({
215
222
  rootNode: opts.ref,
216
223
  candidateSelector: `${navigationMenuAttrs.selector("trigger")}:not([data-disabled]), ${navigationMenuAttrs.selector("link")}:not([data-disabled])`,
@@ -227,13 +234,13 @@ export class NavigationMenuListState {
227
234
  }
228
235
  wrapperProps = $derived.by(() => ({
229
236
  id: this.wrapperId.current,
230
- ...attachRef(this.wrapperRef, (v) => (this.context.indicatorTrackRef.current = v)),
237
+ ...this.wrapperAttachment,
231
238
  }));
232
239
  props = $derived.by(() => ({
233
240
  id: this.opts.id.current,
234
241
  "data-orientation": getDataOrientation(this.context.opts.orientation.current),
235
242
  [navigationMenuAttrs.list]: "",
236
- ...attachRef(this.opts.ref),
243
+ ...this.attachment,
237
244
  }));
238
245
  }
239
246
  export class NavigationMenuItemState {
@@ -292,8 +299,10 @@ export class NavigationMenuTriggerState {
292
299
  });
293
300
  }
294
301
  opts;
302
+ attachment;
295
303
  focusProxyId = box(useId());
296
304
  focusProxyRef = box(null);
305
+ focusProxyAttachment = attachRef(this.focusProxyRef, (v) => (this.itemContext.focusProxyNode = v));
297
306
  context;
298
307
  itemContext;
299
308
  listContext;
@@ -303,6 +312,7 @@ export class NavigationMenuTriggerState {
303
312
  open = $derived.by(() => this.itemContext.opts.value.current === this.context.opts.value.current);
304
313
  constructor(opts, context) {
305
314
  this.opts = opts;
315
+ this.attachment = attachRef(this.opts.ref, (v) => (this.itemContext.triggerNode = v));
306
316
  this.hasPointerMoveOpened = boxAutoReset(false, {
307
317
  afterMs: 300,
308
318
  getWindow: () => getWindow(opts.ref.current),
@@ -386,13 +396,13 @@ export class NavigationMenuTriggerState {
386
396
  onpointerenter: this.onpointerenter,
387
397
  onclick: this.onclick,
388
398
  onkeydown: this.onkeydown,
389
- ...attachRef(this.opts.ref, (v) => (this.itemContext.triggerNode = v)),
399
+ ...this.attachment,
390
400
  }));
391
401
  focusProxyProps = $derived.by(() => ({
392
402
  id: this.focusProxyId.current,
393
403
  tabindex: 0,
394
404
  onfocus: this.focusProxyOnFocus,
395
- ...attachRef(this.focusProxyRef, (v) => (this.itemContext.focusProxyNode = v)),
405
+ ...this.focusProxyAttachment,
396
406
  }));
397
407
  }
398
408
  const LINK_SELECT_EVENT = new CustomEventDispatcher("bitsLinkSelect", {
@@ -412,10 +422,12 @@ export class NavigationMenuLinkState {
412
422
  }
413
423
  opts;
414
424
  context;
425
+ attachment;
415
426
  isFocused = $state(false);
416
427
  constructor(opts, context) {
417
428
  this.opts = opts;
418
429
  this.context = context;
430
+ this.attachment = attachRef(this.opts.ref);
419
431
  }
420
432
  onclick = (e) => {
421
433
  const currTarget = e.currentTarget;
@@ -465,7 +477,7 @@ export class NavigationMenuLinkState {
465
477
  onpointerenter: this.onpointerenter,
466
478
  onpointermove: this.onpointermove,
467
479
  [navigationMenuAttrs.link]: "",
468
- ...attachRef(this.opts.ref),
480
+ ...this.attachment,
469
481
  }));
470
482
  }
471
483
  export class NavigationMenuIndicatorState {
@@ -486,6 +498,7 @@ export class NavigationMenuIndicatorImplState {
486
498
  });
487
499
  }
488
500
  opts;
501
+ attachment;
489
502
  context;
490
503
  listContext;
491
504
  position = $state.raw(null);
@@ -501,6 +514,7 @@ export class NavigationMenuIndicatorImplState {
501
514
  this.opts = opts;
502
515
  this.context = context.provider;
503
516
  this.listContext = context.list;
517
+ this.attachment = attachRef(this.opts.ref);
504
518
  new SvelteResizeObserver(() => this.activeTrigger, this.handlePositionChange);
505
519
  new SvelteResizeObserver(() => this.context.indicatorTrackRef.current, this.handlePositionChange);
506
520
  }
@@ -535,7 +549,7 @@ export class NavigationMenuIndicatorImplState {
535
549
  }),
536
550
  },
537
551
  [navigationMenuAttrs.indicator]: "",
538
- ...attachRef(this.opts.ref),
552
+ ...this.attachment,
539
553
  }));
540
554
  }
541
555
  export class NavigationMenuContentState {
@@ -550,6 +564,7 @@ export class NavigationMenuContentState {
550
564
  context;
551
565
  itemContext;
552
566
  listContext;
567
+ attachment;
553
568
  mounted = $state(false);
554
569
  open = $derived.by(() => this.itemContext.opts.value.current === this.context.opts.value.current);
555
570
  value = $derived.by(() => this.itemContext.opts.value.current);
@@ -568,6 +583,7 @@ export class NavigationMenuContentState {
568
583
  this.context = context.provider;
569
584
  this.itemContext = context.item;
570
585
  this.listContext = context.list;
586
+ this.attachment = attachRef(this.opts.ref, (v) => (this.itemContext.contentNode = v));
571
587
  }
572
588
  onpointerenter = (_) => {
573
589
  this.context.onContentEnter();
@@ -581,7 +597,7 @@ export class NavigationMenuContentState {
581
597
  id: this.opts.id.current,
582
598
  onpointerenter: this.onpointerenter,
583
599
  onpointerleave: this.onpointerleave,
584
- ...attachRef(this.opts.ref, (v) => (this.itemContext.contentNode = v)),
600
+ ...this.attachment,
585
601
  }));
586
602
  }
587
603
  export class NavigationMenuContentImplState {
@@ -592,6 +608,7 @@ export class NavigationMenuContentImplState {
592
608
  itemContext;
593
609
  context;
594
610
  listContext;
611
+ attachment;
595
612
  prevMotionAttribute = $state(null);
596
613
  motionAttribute = $derived.by(() => {
597
614
  const items = this.listContext.listTriggers;
@@ -631,6 +648,7 @@ export class NavigationMenuContentImplState {
631
648
  domContext;
632
649
  constructor(opts, itemContext) {
633
650
  this.opts = opts;
651
+ this.attachment = attachRef(this.opts.ref);
634
652
  this.itemContext = itemContext;
635
653
  this.listContext = itemContext.listContext;
636
654
  this.context = itemContext.listContext.context;
@@ -744,7 +762,7 @@ export class NavigationMenuContentImplState {
744
762
  "data-state": getDataOpenClosed(this.context.opts.value.current === this.itemContext.opts.value.current),
745
763
  onkeydown: this.onkeydown,
746
764
  [navigationMenuAttrs.content]: "",
747
- ...attachRef(this.opts.ref),
765
+ ...this.attachment,
748
766
  }));
749
767
  }
750
768
  export class NavigationMenuViewportState {
@@ -753,6 +771,7 @@ export class NavigationMenuViewportState {
753
771
  }
754
772
  opts;
755
773
  context;
774
+ attachment;
756
775
  open = $derived.by(() => !!this.context.opts.value.current);
757
776
  viewportWidth = $derived.by(() => (this.size ? `${this.size.width}px` : undefined));
758
777
  viewportHeight = $derived.by(() => (this.size ? `${this.size.height}px` : undefined));
@@ -763,6 +782,7 @@ export class NavigationMenuViewportState {
763
782
  constructor(opts, context) {
764
783
  this.opts = opts;
765
784
  this.context = context;
785
+ this.attachment = attachRef(this.opts.ref, (v) => (this.context.viewportRef.current = v));
766
786
  watch([() => this.activeContentValue, () => this.open], () => {
767
787
  afterTick(() => {
768
788
  const currNode = this.context.viewportRef.current;
@@ -806,7 +826,7 @@ export class NavigationMenuViewportState {
806
826
  [navigationMenuAttrs.viewport]: "",
807
827
  onpointerenter: this.context.onContentEnter,
808
828
  onpointerleave: this.context.onContentLeave,
809
- ...attachRef(this.opts.ref, (v) => (this.context.viewportRef.current = v)),
829
+ ...this.attachment,
810
830
  }));
811
831
  }
812
832
  //
@@ -1,6 +1,6 @@
1
1
  import { type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
2
2
  import type { Page, PageItem } from "./types.js";
3
- import type { BitsKeyboardEvent, BitsMouseEvent, WithRefOpts } from "../../internal/types.js";
3
+ import type { BitsKeyboardEvent, BitsMouseEvent, RefAttachment, WithRefOpts } from "../../internal/types.js";
4
4
  import { type Orientation } from "../../shared/index.js";
5
5
  interface PaginationRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
6
6
  count: number;
@@ -15,6 +15,7 @@ interface PaginationRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
15
15
  export declare class PaginationRootState {
16
16
  static create(opts: PaginationRootStateOpts): PaginationRootState;
17
17
  readonly opts: PaginationRootStateOpts;
18
+ readonly attachment: RefAttachment;
18
19
  readonly totalPages: number;
19
20
  readonly range: {
20
21
  start: number;
@@ -52,6 +53,7 @@ export declare class PaginationPageState {
52
53
  static create(opts: PaginationPageStateOpts): PaginationPageState;
53
54
  readonly opts: PaginationPageStateOpts;
54
55
  readonly root: PaginationRootState;
56
+ readonly attachment: RefAttachment;
55
57
  constructor(opts: PaginationPageStateOpts, root: PaginationRootState);
56
58
  onclick(e: BitsMouseEvent): void;
57
59
  onkeydown(e: BitsKeyboardEvent): void;
@@ -74,6 +76,7 @@ export declare class PaginationButtonState {
74
76
  static create(opts: PaginationButtonStateOpts): PaginationButtonState;
75
77
  readonly opts: PaginationButtonStateOpts;
76
78
  readonly root: PaginationRootState;
79
+ readonly attachment: RefAttachment;
77
80
  constructor(opts: PaginationButtonStateOpts, root: PaginationRootState);
78
81
  onclick(e: BitsMouseEvent): void;
79
82
  onkeydown(e: BitsKeyboardEvent): void;
@@ -15,6 +15,7 @@ export class PaginationRootState {
15
15
  return PaginationRootContext.set(new PaginationRootState(opts));
16
16
  }
17
17
  opts;
18
+ attachment;
18
19
  totalPages = $derived.by(() => {
19
20
  if (this.opts.count.current === 0)
20
21
  return 1;
@@ -34,6 +35,7 @@ export class PaginationRootState {
34
35
  hasNextPage = $derived.by(() => this.opts.page.current < this.totalPages);
35
36
  constructor(opts) {
36
37
  this.opts = opts;
38
+ this.attachment = attachRef(this.opts.ref);
37
39
  }
38
40
  setPage(page) {
39
41
  this.opts.page.current = page;
@@ -65,7 +67,7 @@ export class PaginationRootState {
65
67
  id: this.opts.id.current,
66
68
  "data-orientation": getDataOrientation(this.opts.orientation.current),
67
69
  [paginationAttrs.root]: "",
68
- ...attachRef(this.opts.ref),
70
+ ...this.attachment,
69
71
  }));
70
72
  }
71
73
  export class PaginationPageState {
@@ -74,10 +76,12 @@ export class PaginationPageState {
74
76
  }
75
77
  opts;
76
78
  root;
79
+ attachment;
77
80
  #isSelected = $derived.by(() => this.opts.page.current.value === this.root.opts.page.current);
78
81
  constructor(opts, root) {
79
82
  this.opts = opts;
80
83
  this.root = root;
84
+ this.attachment = attachRef(this.opts.ref);
81
85
  this.onclick = this.onclick.bind(this);
82
86
  this.onkeydown = this.onkeydown.bind(this);
83
87
  }
@@ -106,7 +110,7 @@ export class PaginationPageState {
106
110
  //
107
111
  onclick: this.onclick,
108
112
  onkeydown: this.onkeydown,
109
- ...attachRef(this.opts.ref),
113
+ ...this.attachment,
110
114
  }));
111
115
  }
112
116
  export class PaginationButtonState {
@@ -115,9 +119,11 @@ export class PaginationButtonState {
115
119
  }
116
120
  opts;
117
121
  root;
122
+ attachment;
118
123
  constructor(opts, root) {
119
124
  this.opts = opts;
120
125
  this.root = root;
126
+ this.attachment = attachRef(this.opts.ref);
121
127
  this.onclick = this.onclick.bind(this);
122
128
  this.onkeydown = this.onkeydown.bind(this);
123
129
  }
@@ -156,7 +162,7 @@ export class PaginationButtonState {
156
162
  //
157
163
  onclick: this.onclick,
158
164
  onkeydown: this.onkeydown,
159
- ...attachRef(this.opts.ref),
165
+ ...this.attachment,
160
166
  }));
161
167
  }
162
168
  //
@@ -1,6 +1,6 @@
1
1
  import { DOMContext, type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
2
2
  import type { PinInputCell, PinInputRootProps as RootComponentProps } from "./types.js";
3
- import type { BitsEvent, BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, WithRefOpts } from "../../internal/types.js";
3
+ import type { BitsEvent, BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, RefAttachment, WithRefOpts } from "../../internal/types.js";
4
4
  export declare const REGEXP_ONLY_DIGITS = "^\\d+$";
5
5
  export declare const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
6
6
  export declare const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
@@ -23,6 +23,8 @@ export declare class PinInputRootState {
23
23
  #private;
24
24
  static create(opts: PinInputRootStateOpts): PinInputRootState;
25
25
  readonly opts: PinInputRootStateOpts;
26
+ readonly attachment: RefAttachment;
27
+ readonly inputAttachment: RefAttachment<HTMLInputElement>;
26
28
  domContext: DOMContext;
27
29
  constructor(opts: PinInputRootStateOpts);
28
30
  onkeydown: (e: BitsKeyboardEvent) => void;
@@ -107,6 +109,7 @@ interface PinInputCellStateOpts extends WithRefOpts, ReadableBoxedValues<{
107
109
  export declare class PinInputCellState {
108
110
  static create(opts: PinInputCellStateOpts): PinInputCellState;
109
111
  readonly opts: PinInputCellStateOpts;
112
+ readonly attachment: RefAttachment;
110
113
  constructor(opts: PinInputCellStateOpts);
111
114
  readonly props: {
112
115
  readonly id: string;