@octanejs/radix 0.1.32 → 0.1.33

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 (60) hide show
  1. package/dist/cjs/AccessibleIcon.cjs +56 -0
  2. package/dist/cjs/Accordion.cjs +272 -0
  3. package/dist/cjs/AlertDialog.cjs +144 -0
  4. package/dist/cjs/Arrow.cjs +43 -0
  5. package/dist/cjs/AspectRatio.cjs +56 -0
  6. package/dist/cjs/Avatar.cjs +150 -0
  7. package/dist/cjs/Checkbox.cjs +281 -0
  8. package/dist/cjs/Collapsible.cjs +176 -0
  9. package/dist/cjs/ContextMenu.cjs +315 -0
  10. package/dist/cjs/Dialog.cjs +291 -0
  11. package/dist/cjs/DismissableLayer.cjs +382 -0
  12. package/dist/cjs/DropdownMenu.cjs +296 -0
  13. package/dist/cjs/FocusScope.cjs +257 -0
  14. package/dist/cjs/Form.cjs +537 -0
  15. package/dist/cjs/HoverCard.cjs +309 -0
  16. package/dist/cjs/Label.cjs +42 -0
  17. package/dist/cjs/Menu.cjs +925 -0
  18. package/dist/cjs/Menubar.cjs +475 -0
  19. package/dist/cjs/NavigationMenu.cjs +942 -0
  20. package/dist/cjs/OneTimePasswordField.cjs +729 -0
  21. package/dist/cjs/PasswordToggleField.cjs +377 -0
  22. package/dist/cjs/Popover.cjs +340 -0
  23. package/dist/cjs/Popper.cjs +368 -0
  24. package/dist/cjs/Portal.cjs +40 -0
  25. package/dist/cjs/Presence.cjs +183 -0
  26. package/dist/cjs/Primitive.cjs +63 -0
  27. package/dist/cjs/Progress.cjs +111 -0
  28. package/dist/cjs/Radio.cjs +240 -0
  29. package/dist/cjs/RadioGroup.cjs +216 -0
  30. package/dist/cjs/RovingFocusGroup.cjs +253 -0
  31. package/dist/cjs/ScrollArea.cjs +828 -0
  32. package/dist/cjs/Select.cjs +1429 -0
  33. package/dist/cjs/Separator.cjs +51 -0
  34. package/dist/cjs/Slider.cjs +634 -0
  35. package/dist/cjs/Slot.cjs +97 -0
  36. package/dist/cjs/Switch.cjs +253 -0
  37. package/dist/cjs/Tabs.cjs +195 -0
  38. package/dist/cjs/Toast.cjs +733 -0
  39. package/dist/cjs/Toggle.cjs +54 -0
  40. package/dist/cjs/ToggleGroup.cjs +174 -0
  41. package/dist/cjs/Toolbar.cjs +165 -0
  42. package/dist/cjs/Tooltip.cjs +628 -0
  43. package/dist/cjs/VisuallyHidden.cjs +52 -0
  44. package/dist/cjs/collection.cjs +95 -0
  45. package/dist/cjs/compose-event-handlers.cjs +35 -0
  46. package/dist/cjs/compose-refs.cjs +68 -0
  47. package/dist/cjs/context.cjs +96 -0
  48. package/dist/cjs/direction.cjs +41 -0
  49. package/dist/cjs/focus-guards.cjs +76 -0
  50. package/dist/cjs/index.cjs +174 -0
  51. package/dist/cjs/internal.cjs +51 -0
  52. package/dist/cjs/scroll-lock.cjs +67 -0
  53. package/dist/cjs/use-callback-ref.cjs +47 -0
  54. package/dist/cjs/use-effect-event.cjs +52 -0
  55. package/dist/cjs/use-is-hydrated.cjs +43 -0
  56. package/dist/cjs/use-previous.cjs +47 -0
  57. package/dist/cjs/use-size.cjs +69 -0
  58. package/dist/cjs/useControllableState.cjs +80 -0
  59. package/dist/cjs/useId.cjs +36 -0
  60. package/package.json +14 -7
@@ -0,0 +1,377 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var PasswordToggleField_exports = {};
20
+ __export(PasswordToggleField_exports, {
21
+ Icon: () => PasswordToggleFieldIcon,
22
+ Input: () => PasswordToggleFieldInput,
23
+ PasswordToggleField: () => PasswordToggleField,
24
+ PasswordToggleFieldIcon: () => PasswordToggleFieldIcon,
25
+ PasswordToggleFieldInput: () => PasswordToggleFieldInput,
26
+ PasswordToggleFieldSlot: () => PasswordToggleFieldSlot,
27
+ PasswordToggleFieldToggle: () => PasswordToggleFieldToggle,
28
+ Root: () => PasswordToggleField,
29
+ Slot: () => PasswordToggleFieldSlot,
30
+ Toggle: () => PasswordToggleFieldToggle,
31
+ createPasswordToggleFieldScope: () => createPasswordToggleFieldScope
32
+ });
33
+ module.exports = __toCommonJS(PasswordToggleField_exports);
34
+ var import_octane = require("octane");
35
+ var import_compose_event_handlers = require("./compose-event-handlers.cjs");
36
+ var import_compose_refs = require("./compose-refs.cjs");
37
+ var import_context = require("./context.cjs");
38
+ var import_internal = require("./internal.cjs");
39
+ var import_Primitive = require("./Primitive.cjs");
40
+ var import_use_effect_event = require("./use-effect-event.cjs");
41
+ var import_useId = require("./useId.cjs");
42
+ var import_use_is_hydrated = require("./use-is-hydrated.cjs");
43
+ var import_useControllableState = require("./useControllableState.cjs");
44
+ const PASSWORD_TOGGLE_FIELD_NAME = "PasswordToggleField";
45
+ const [createPasswordToggleFieldContext, createPasswordToggleFieldScope] = (0, import_context.createContextScope)(
46
+ PASSWORD_TOGGLE_FIELD_NAME
47
+ );
48
+ const [PasswordToggleFieldProvider, usePasswordToggleFieldContext] = createPasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_NAME);
49
+ const INITIAL_FOCUS_STATE = {
50
+ clickTriggered: false,
51
+ selectionStart: null,
52
+ selectionEnd: null
53
+ };
54
+ function PasswordToggleField(props) {
55
+ const slot = (0, import_internal.S)("PasswordToggleField.Root");
56
+ const {
57
+ __scopePasswordToggleField,
58
+ visible: visibleProp,
59
+ defaultVisible,
60
+ children
61
+ } = props ?? {};
62
+ const baseId = (0, import_useId.useId)(props?.id, (0, import_internal.subSlot)(slot, "id"));
63
+ const defaultInputId = `${baseId}-input`;
64
+ const [inputIdState, setInputIdState] = (0, import_octane.useState)(
65
+ defaultInputId,
66
+ (0, import_internal.subSlot)(slot, "inputId")
67
+ );
68
+ const inputId = inputIdState ?? defaultInputId;
69
+ const syncInputId = (0, import_octane.useCallback)(
70
+ (providedId) => setInputIdState(providedId != null ? String(providedId) : null),
71
+ [],
72
+ (0, import_internal.subSlot)(slot, "syncId")
73
+ );
74
+ let onVisibilityChange = props?.onVisibilityChange;
75
+ if (!onVisibilityChange && props != null && "onVisiblityChange" in props && typeof props.onVisiblityChange === "function") {
76
+ onVisibilityChange = props.onVisiblityChange;
77
+ }
78
+ const [visible = false, setVisible] = (0, import_useControllableState.useControllableState)(
79
+ {
80
+ prop: visibleProp,
81
+ defaultProp: defaultVisible ?? false,
82
+ onChange: onVisibilityChange
83
+ },
84
+ (0, import_internal.subSlot)(slot, "visible")
85
+ );
86
+ const inputRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "inputRef"));
87
+ const focusState = (0, import_octane.useRef)(INITIAL_FOCUS_STATE, (0, import_internal.subSlot)(slot, "focusState"));
88
+ return (0, import_octane.createElement)(PasswordToggleFieldProvider, {
89
+ scope: __scopePasswordToggleField,
90
+ inputId,
91
+ inputRef,
92
+ setVisible,
93
+ syncInputId,
94
+ visible,
95
+ focusState,
96
+ children
97
+ });
98
+ }
99
+ const PASSWORD_TOGGLE_FIELD_INPUT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Input";
100
+ function PasswordToggleFieldInput(props) {
101
+ const slot = (0, import_internal.S)("PasswordToggleField.Input");
102
+ const {
103
+ __scopePasswordToggleField,
104
+ autoComplete = "current-password",
105
+ autoCapitalize = "off",
106
+ spellCheck = false,
107
+ id: idProp,
108
+ ref: forwardedRef,
109
+ onBlur,
110
+ ...inputProps
111
+ } = props ?? {};
112
+ const { visible, inputRef, inputId, syncInputId, setVisible, focusState } = usePasswordToggleFieldContext(PASSWORD_TOGGLE_FIELD_INPUT_NAME, __scopePasswordToggleField);
113
+ (0, import_octane.useEffect)(
114
+ () => {
115
+ syncInputId(idProp);
116
+ },
117
+ [idProp, syncInputId],
118
+ (0, import_internal.subSlot)(slot, "e:syncId")
119
+ );
120
+ const _setVisible = (0, import_use_effect_event.useEffectEvent)(setVisible, (0, import_internal.subSlot)(slot, "setVisible"));
121
+ (0, import_octane.useEffect)(
122
+ () => {
123
+ const inputElement = inputRef.current;
124
+ const form = inputElement?.form;
125
+ if (!form) {
126
+ return;
127
+ }
128
+ const controller = new AbortController();
129
+ form.addEventListener(
130
+ "reset",
131
+ (event) => {
132
+ if (!event.defaultPrevented) {
133
+ _setVisible(false);
134
+ }
135
+ },
136
+ { signal: controller.signal }
137
+ );
138
+ form.addEventListener(
139
+ "submit",
140
+ () => {
141
+ _setVisible(false);
142
+ },
143
+ { signal: controller.signal }
144
+ );
145
+ return () => {
146
+ controller.abort();
147
+ };
148
+ },
149
+ [inputRef],
150
+ (0, import_internal.subSlot)(slot, "e:form")
151
+ );
152
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, inputRef, (0, import_internal.subSlot)(slot, "refs"));
153
+ return (0, import_octane.createElement)(import_Primitive.Primitive.input, {
154
+ ...inputProps,
155
+ id: idProp ?? inputId,
156
+ autoCapitalize,
157
+ autoComplete,
158
+ ref: composedRefs,
159
+ // octane: boolean spellCheck must render the literal "true"/"false" attribute value
160
+ // (octane's setAttribute removes `false`-valued attributes; React stringifies it).
161
+ spellCheck: typeof spellCheck === "boolean" ? String(spellCheck) : spellCheck,
162
+ type: visible ? "text" : "password",
163
+ onBlur: (0, import_compose_event_handlers.composeEventHandlers)(onBlur, (event) => {
164
+ const { selectionStart, selectionEnd } = event.currentTarget;
165
+ focusState.current.selectionStart = selectionStart;
166
+ focusState.current.selectionEnd = selectionEnd;
167
+ })
168
+ });
169
+ }
170
+ const PASSWORD_TOGGLE_FIELD_TOGGLE_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Toggle";
171
+ function PasswordToggleFieldToggle(props) {
172
+ const slot = (0, import_internal.S)("PasswordToggleField.Toggle");
173
+ const {
174
+ __scopePasswordToggleField,
175
+ onClick,
176
+ onPointerDown,
177
+ onPointerCancel,
178
+ onPointerUp,
179
+ // Kept verbatim from the source: `onFocus` is destructured off the props and never
180
+ // attached to the button (the upstream component swallows it).
181
+ onFocus: _onFocus,
182
+ children,
183
+ "aria-label": ariaLabelProp,
184
+ ref: forwardedRef,
185
+ ...toggleProps
186
+ } = props ?? {};
187
+ let { "aria-controls": ariaControls, "aria-hidden": ariaHidden, tabIndex } = toggleProps;
188
+ delete toggleProps["aria-controls"];
189
+ delete toggleProps["aria-hidden"];
190
+ delete toggleProps.tabIndex;
191
+ const { setVisible, visible, inputRef, inputId, focusState } = usePasswordToggleFieldContext(
192
+ PASSWORD_TOGGLE_FIELD_TOGGLE_NAME,
193
+ __scopePasswordToggleField
194
+ );
195
+ const [internalAriaLabel, setInternalAriaLabel] = (0, import_octane.useState)(
196
+ void 0,
197
+ (0, import_internal.subSlot)(slot, "ariaLabel")
198
+ );
199
+ const elementRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "el"));
200
+ const ref = (0, import_compose_refs.useComposedRefs)(forwardedRef, elementRef, (0, import_internal.subSlot)(slot, "refs"));
201
+ const isHydrated = (0, import_use_is_hydrated.useIsHydrated)((0, import_internal.subSlot)(slot, "hydrated"));
202
+ (0, import_octane.useEffect)(
203
+ () => {
204
+ const element = elementRef.current;
205
+ if (!element || ariaLabelProp) {
206
+ setInternalAriaLabel(void 0);
207
+ return;
208
+ }
209
+ const DEFAULT_ARIA_LABEL = visible ? "Hide password" : "Show password";
210
+ function checkForInnerTextLabel(textContent) {
211
+ const text = textContent ? textContent : void 0;
212
+ setInternalAriaLabel(text ? void 0 : DEFAULT_ARIA_LABEL);
213
+ }
214
+ checkForInnerTextLabel(element.textContent);
215
+ const observer = new MutationObserver((entries) => {
216
+ let textContent;
217
+ for (const entry of entries) {
218
+ if (entry.type === "characterData") {
219
+ if (element.textContent) {
220
+ textContent = element.textContent;
221
+ }
222
+ }
223
+ }
224
+ checkForInnerTextLabel(textContent);
225
+ });
226
+ observer.observe(element, { characterData: true, subtree: true });
227
+ return () => {
228
+ observer.disconnect();
229
+ };
230
+ },
231
+ [visible, ariaLabelProp],
232
+ (0, import_internal.subSlot)(slot, "e:label")
233
+ );
234
+ const ariaLabel = ariaLabelProp || internalAriaLabel;
235
+ if (!isHydrated) {
236
+ ariaHidden ??= true;
237
+ tabIndex ??= -1;
238
+ } else {
239
+ ariaControls ??= inputId;
240
+ }
241
+ void tabIndex;
242
+ (0, import_octane.useEffect)(
243
+ () => {
244
+ let cleanup = () => {
245
+ };
246
+ const ownerWindow = elementRef.current?.ownerDocument?.defaultView || window;
247
+ const reset = () => focusState.current.clickTriggered = false;
248
+ const handlePointerUp = () => {
249
+ cleanup = requestIdleCallback(ownerWindow, reset);
250
+ };
251
+ ownerWindow.addEventListener("pointerup", handlePointerUp);
252
+ return () => {
253
+ cleanup();
254
+ ownerWindow.removeEventListener("pointerup", handlePointerUp);
255
+ };
256
+ },
257
+ [focusState],
258
+ (0, import_internal.subSlot)(slot, "e:pointerup")
259
+ );
260
+ return (0, import_octane.createElement)(import_Primitive.Primitive.button, {
261
+ "aria-controls": ariaControls,
262
+ "aria-hidden": ariaHidden,
263
+ "aria-label": ariaLabel,
264
+ ref,
265
+ id: inputId,
266
+ ...toggleProps,
267
+ onPointerDown: (0, import_compose_event_handlers.composeEventHandlers)(onPointerDown, () => {
268
+ focusState.current.clickTriggered = true;
269
+ }),
270
+ onPointerCancel: (event) => {
271
+ onPointerCancel?.(event);
272
+ focusState.current = INITIAL_FOCUS_STATE;
273
+ },
274
+ // do not use `composeEventHandlers` here because we always want to
275
+ // reset the ref after click, regardless of whether the user has
276
+ // called preventDefault on the event
277
+ onClick: (event) => {
278
+ onClick?.(event);
279
+ if (event.defaultPrevented) {
280
+ focusState.current = INITIAL_FOCUS_STATE;
281
+ return;
282
+ }
283
+ (0, import_octane.flushSync)(() => {
284
+ setVisible((s) => !s);
285
+ });
286
+ if (focusState.current.clickTriggered) {
287
+ const input = inputRef.current;
288
+ if (input) {
289
+ const { selectionStart, selectionEnd } = focusState.current;
290
+ input.focus();
291
+ if (selectionStart !== null || selectionEnd !== null) {
292
+ requestAnimationFrame(() => {
293
+ if (input.ownerDocument.activeElement === input) {
294
+ input.selectionStart = selectionStart;
295
+ input.selectionEnd = selectionEnd;
296
+ }
297
+ });
298
+ }
299
+ }
300
+ }
301
+ focusState.current = INITIAL_FOCUS_STATE;
302
+ },
303
+ onPointerUp: (event) => {
304
+ onPointerUp?.(event);
305
+ setTimeout(() => {
306
+ focusState.current = INITIAL_FOCUS_STATE;
307
+ }, 50);
308
+ },
309
+ type: "button",
310
+ children
311
+ });
312
+ }
313
+ const PASSWORD_TOGGLE_FIELD_SLOT_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Slot";
314
+ function PasswordToggleFieldSlot(props) {
315
+ const { __scopePasswordToggleField, ...slotProps } = props ?? {};
316
+ const { visible } = usePasswordToggleFieldContext(
317
+ PASSWORD_TOGGLE_FIELD_SLOT_NAME,
318
+ __scopePasswordToggleField
319
+ );
320
+ return "render" in slotProps ? (
321
+ //
322
+ slotProps.render({ visible })
323
+ ) : visible ? slotProps.visible : slotProps.hidden;
324
+ }
325
+ const PASSWORD_TOGGLE_FIELD_ICON_NAME = PASSWORD_TOGGLE_FIELD_NAME + "Icon";
326
+ function PasswordToggleFieldIcon(props) {
327
+ const {
328
+ __scopePasswordToggleField,
329
+ // (source drops `children` — the icon elements come through the
330
+ // `visible`/`hidden` props)
331
+ children: _children,
332
+ ref: forwardedRef,
333
+ ...rest
334
+ } = props ?? {};
335
+ const { visible } = usePasswordToggleFieldContext(
336
+ PASSWORD_TOGGLE_FIELD_ICON_NAME,
337
+ __scopePasswordToggleField
338
+ );
339
+ const { visible: visibleIcon, hidden: hiddenIcon, ...domProps } = rest;
340
+ return (0, import_octane.createElement)(import_Primitive.Primitive.svg, {
341
+ ...domProps,
342
+ ref: forwardedRef,
343
+ "aria-hidden": true,
344
+ asChild: true,
345
+ children: visible ? visibleIcon : hiddenIcon
346
+ });
347
+ }
348
+ function requestIdleCallback(window2, callback, options) {
349
+ if (window2.requestIdleCallback) {
350
+ const id2 = window2.requestIdleCallback(callback, options);
351
+ return () => {
352
+ window2.cancelIdleCallback(id2);
353
+ };
354
+ }
355
+ const start = Date.now();
356
+ const id = window2.setTimeout(() => {
357
+ const timeRemaining = () => Math.max(0, 50 - (Date.now() - start));
358
+ callback({ didTimeout: false, timeRemaining });
359
+ }, 1);
360
+ return () => {
361
+ window2.clearTimeout(id);
362
+ };
363
+ }
364
+ // Annotate the CommonJS export names for ESM import in node:
365
+ 0 && (module.exports = {
366
+ Icon,
367
+ Input,
368
+ PasswordToggleField,
369
+ PasswordToggleFieldIcon,
370
+ PasswordToggleFieldInput,
371
+ PasswordToggleFieldSlot,
372
+ PasswordToggleFieldToggle,
373
+ Root,
374
+ Slot,
375
+ Toggle,
376
+ createPasswordToggleFieldScope
377
+ });