@funstack/ui 0.1.0-alpha.20 → 0.1.0-alpha.22

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 (176) hide show
  1. package/dist/alert-dialog/alert-dialog-root.mjs +2 -1
  2. package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -1
  3. package/dist/avatar/avatar-context.mjs +24 -0
  4. package/dist/avatar/avatar-context.mjs.map +1 -0
  5. package/dist/avatar/avatar-fallback.d.mts +32 -0
  6. package/dist/avatar/avatar-fallback.d.mts.map +1 -0
  7. package/dist/avatar/avatar-fallback.mjs +31 -0
  8. package/dist/avatar/avatar-fallback.mjs.map +1 -0
  9. package/dist/avatar/avatar-image.d.mts +37 -0
  10. package/dist/avatar/avatar-image.d.mts.map +1 -0
  11. package/dist/avatar/avatar-image.mjs +91 -0
  12. package/dist/avatar/avatar-image.mjs.map +1 -0
  13. package/dist/avatar/avatar-root.d.mts +48 -0
  14. package/dist/avatar/avatar-root.d.mts.map +1 -0
  15. package/dist/avatar/avatar-root.mjs +81 -0
  16. package/dist/avatar/avatar-root.mjs.map +1 -0
  17. package/dist/avatar/index.d.mts +24 -0
  18. package/dist/avatar/index.d.mts.map +1 -0
  19. package/dist/avatar/index.mjs +24 -0
  20. package/dist/avatar/index.mjs.map +1 -0
  21. package/dist/dialog/dialog-close.d.mts.map +1 -1
  22. package/dist/dialog/dialog-close.mjs +14 -3
  23. package/dist/dialog/dialog-close.mjs.map +1 -1
  24. package/dist/dialog/dialog-context.mjs +7 -1
  25. package/dist/dialog/dialog-context.mjs.map +1 -1
  26. package/dist/dialog/dialog-popup.d.mts +1 -0
  27. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  28. package/dist/dialog/dialog-popup.mjs +20 -2
  29. package/dist/dialog/dialog-popup.mjs.map +1 -1
  30. package/dist/dialog/dialog-root.mjs +6 -4
  31. package/dist/dialog/dialog-root.mjs.map +1 -1
  32. package/dist/docs/components/avatar.md +354 -0
  33. package/dist/docs/components/drawer.md +622 -0
  34. package/dist/docs/components/menu.md +1 -1
  35. package/dist/docs/components/menubar.md +309 -0
  36. package/dist/docs/components/meter.md +1 -1
  37. package/dist/docs/components/navigation-menu.md +501 -0
  38. package/dist/docs/components/number-field.md +2 -2
  39. package/dist/docs/components/otp-field.md +508 -0
  40. package/dist/docs/components/progress.md +1 -1
  41. package/dist/docs/components/radio-group.md +1 -1
  42. package/dist/docs/components/scroll-area.md +294 -0
  43. package/dist/docs/components/slider.md +1 -1
  44. package/dist/docs/concepts/direction-and-locales.md +106 -0
  45. package/dist/docs/index.md +8 -1
  46. package/dist/docs/roadmap.md +13 -0
  47. package/dist/drawer/drawer-close.d.mts +26 -0
  48. package/dist/drawer/drawer-close.d.mts.map +1 -0
  49. package/dist/drawer/drawer-close.mjs +19 -0
  50. package/dist/drawer/drawer-close.mjs.map +1 -0
  51. package/dist/drawer/drawer-description.d.mts +23 -0
  52. package/dist/drawer/drawer-description.d.mts.map +1 -0
  53. package/dist/drawer/drawer-description.mjs +18 -0
  54. package/dist/drawer/drawer-description.mjs.map +1 -0
  55. package/dist/drawer/drawer-form.d.mts +24 -0
  56. package/dist/drawer/drawer-form.d.mts.map +1 -0
  57. package/dist/drawer/drawer-form.mjs +19 -0
  58. package/dist/drawer/drawer-form.mjs.map +1 -0
  59. package/dist/drawer/drawer-popup.d.mts +77 -0
  60. package/dist/drawer/drawer-popup.d.mts.map +1 -0
  61. package/dist/drawer/drawer-popup.mjs +124 -0
  62. package/dist/drawer/drawer-popup.mjs.map +1 -0
  63. package/dist/drawer/drawer-root.d.mts +31 -0
  64. package/dist/drawer/drawer-root.d.mts.map +1 -0
  65. package/dist/drawer/drawer-root.mjs +23 -0
  66. package/dist/drawer/drawer-root.mjs.map +1 -0
  67. package/dist/drawer/drawer-swipe.d.mts +5 -0
  68. package/dist/drawer/drawer-swipe.d.mts.map +1 -0
  69. package/dist/drawer/drawer-swipe.mjs +193 -0
  70. package/dist/drawer/drawer-swipe.mjs.map +1 -0
  71. package/dist/drawer/drawer-title.d.mts +23 -0
  72. package/dist/drawer/drawer-title.d.mts.map +1 -0
  73. package/dist/drawer/drawer-title.mjs +18 -0
  74. package/dist/drawer/drawer-title.mjs.map +1 -0
  75. package/dist/drawer/drawer-trigger.d.mts +23 -0
  76. package/dist/drawer/drawer-trigger.d.mts.map +1 -0
  77. package/dist/drawer/drawer-trigger.mjs +18 -0
  78. package/dist/drawer/drawer-trigger.mjs.map +1 -0
  79. package/dist/drawer/index.d.mts +34 -0
  80. package/dist/drawer/index.d.mts.map +1 -0
  81. package/dist/drawer/index.mjs +33 -0
  82. package/dist/drawer/index.mjs.map +1 -0
  83. package/dist/index.d.mts +29 -2
  84. package/dist/index.mjs +6 -1
  85. package/dist/internal/menubar-context.mjs +12 -0
  86. package/dist/internal/menubar-context.mjs.map +1 -0
  87. package/dist/internal/overlay/trigger-ref.mjs +1 -1
  88. package/dist/internal/overlay/trigger-ref.mjs.map +1 -1
  89. package/dist/internal/overlay/use-overlay-root.mjs +3 -2
  90. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
  91. package/dist/internal/overlay/use-popover-trigger.mjs +2 -2
  92. package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -1
  93. package/dist/internal/range-value.mjs +5 -3
  94. package/dist/internal/range-value.mjs.map +1 -1
  95. package/dist/internal/swipe-arithmetic.mjs +75 -0
  96. package/dist/internal/swipe-arithmetic.mjs.map +1 -0
  97. package/dist/internal/swipe.mjs +169 -0
  98. package/dist/internal/swipe.mjs.map +1 -0
  99. package/dist/menu/menu-context-trigger.mjs +1 -1
  100. package/dist/menu/menu-popup.d.mts.map +1 -1
  101. package/dist/menu/menu-popup.mjs +34 -7
  102. package/dist/menu/menu-popup.mjs.map +1 -1
  103. package/dist/menu/menu-trigger.d.mts +10 -3
  104. package/dist/menu/menu-trigger.d.mts.map +1 -1
  105. package/dist/menu/menu-trigger.mjs +53 -5
  106. package/dist/menu/menu-trigger.mjs.map +1 -1
  107. package/dist/menubar/index.d.mts +3 -0
  108. package/dist/menubar/index.mjs +1 -0
  109. package/dist/menubar/menubar.d.mts +49 -0
  110. package/dist/menubar/menubar.d.mts.map +1 -0
  111. package/dist/menubar/menubar.mjs +147 -0
  112. package/dist/menubar/menubar.mjs.map +1 -0
  113. package/dist/meter/meter-root.d.mts +3 -2
  114. package/dist/meter/meter-root.d.mts.map +1 -1
  115. package/dist/meter/meter-root.mjs.map +1 -1
  116. package/dist/multi-select/multi-select-root.mjs +1 -1
  117. package/dist/multi-select/multi-select-trigger.mjs +1 -1
  118. package/dist/navigation-menu/index.d.mts +32 -0
  119. package/dist/navigation-menu/index.d.mts.map +1 -0
  120. package/dist/navigation-menu/index.mjs +32 -0
  121. package/dist/navigation-menu/index.mjs.map +1 -0
  122. package/dist/navigation-menu/navigation-menu-context.mjs +19 -0
  123. package/dist/navigation-menu/navigation-menu-context.mjs.map +1 -0
  124. package/dist/navigation-menu/navigation-menu-item.d.mts +79 -0
  125. package/dist/navigation-menu/navigation-menu-item.d.mts.map +1 -0
  126. package/dist/navigation-menu/navigation-menu-item.mjs +80 -0
  127. package/dist/navigation-menu/navigation-menu-item.mjs.map +1 -0
  128. package/dist/navigation-menu/navigation-menu-link.d.mts +48 -0
  129. package/dist/navigation-menu/navigation-menu-link.d.mts.map +1 -0
  130. package/dist/navigation-menu/navigation-menu-link.mjs +66 -0
  131. package/dist/navigation-menu/navigation-menu-link.mjs.map +1 -0
  132. package/dist/navigation-menu/navigation-menu-list.d.mts +33 -0
  133. package/dist/navigation-menu/navigation-menu-list.d.mts.map +1 -0
  134. package/dist/navigation-menu/navigation-menu-list.mjs +30 -0
  135. package/dist/navigation-menu/navigation-menu-list.mjs.map +1 -0
  136. package/dist/navigation-menu/navigation-menu-popup.d.mts +102 -0
  137. package/dist/navigation-menu/navigation-menu-popup.d.mts.map +1 -0
  138. package/dist/navigation-menu/navigation-menu-popup.mjs +93 -0
  139. package/dist/navigation-menu/navigation-menu-popup.mjs.map +1 -0
  140. package/dist/navigation-menu/navigation-menu-root.d.mts +33 -0
  141. package/dist/navigation-menu/navigation-menu-root.d.mts.map +1 -0
  142. package/dist/navigation-menu/navigation-menu-root.mjs +27 -0
  143. package/dist/navigation-menu/navigation-menu-root.mjs.map +1 -0
  144. package/dist/navigation-menu/navigation-menu-trigger.d.mts +32 -0
  145. package/dist/navigation-menu/navigation-menu-trigger.d.mts.map +1 -0
  146. package/dist/navigation-menu/navigation-menu-trigger.mjs +42 -0
  147. package/dist/navigation-menu/navigation-menu-trigger.mjs.map +1 -0
  148. package/dist/otp-field/index.d.mts +23 -0
  149. package/dist/otp-field/index.d.mts.map +1 -0
  150. package/dist/otp-field/index.mjs +23 -0
  151. package/dist/otp-field/index.mjs.map +1 -0
  152. package/dist/otp-field/otp-field-context.mjs +13 -0
  153. package/dist/otp-field/otp-field-context.mjs.map +1 -0
  154. package/dist/otp-field/otp-field-filter.d.mts +5 -0
  155. package/dist/otp-field/otp-field-filter.d.mts.map +1 -0
  156. package/dist/otp-field/otp-field-filter.mjs +135 -0
  157. package/dist/otp-field/otp-field-filter.mjs.map +1 -0
  158. package/dist/otp-field/otp-field-input.d.mts +41 -0
  159. package/dist/otp-field/otp-field-input.d.mts.map +1 -0
  160. package/dist/otp-field/otp-field-input.mjs +177 -0
  161. package/dist/otp-field/otp-field-input.mjs.map +1 -0
  162. package/dist/otp-field/otp-field-root.d.mts +152 -0
  163. package/dist/otp-field/otp-field-root.d.mts.map +1 -0
  164. package/dist/otp-field/otp-field-root.mjs +400 -0
  165. package/dist/otp-field/otp-field-root.mjs.map +1 -0
  166. package/dist/otp-field/otp-field-slot.d.mts +52 -0
  167. package/dist/otp-field/otp-field-slot.d.mts.map +1 -0
  168. package/dist/otp-field/otp-field-slot.mjs +67 -0
  169. package/dist/otp-field/otp-field-slot.mjs.map +1 -0
  170. package/dist/popover/index.d.mts +1 -1
  171. package/dist/popover/popover-trigger.mjs +1 -1
  172. package/dist/progress/progress-root.d.mts +3 -2
  173. package/dist/progress/progress-root.d.mts.map +1 -1
  174. package/dist/progress/progress-root.mjs.map +1 -1
  175. package/package.json +7 -1
  176. package/skills/funstack-ui-knowledge/SKILL.md +8 -1
@@ -0,0 +1,152 @@
1
+ import { Action, ActionDetails, ChangeReason, RenderProp, StateValue, UrgentChangeHandler } from "../internal/types.mjs";
2
+ import { OTPFieldCharset } from "./otp-field-filter.mjs";
3
+ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
4
+ //#region src/otp-field/otp-field-root.d.ts
5
+ /** Details passed as the second argument of `onValueChange`. */
6
+ export interface OTPFieldValueChangeDetails extends ActionDetails {
7
+ /**
8
+ * `"activate"`: the user edited the text (`details.event` is the `input` event, or the
9
+ * `compositionend` that ended a composition). `"platform"`: a form reset (the `reset` event),
10
+ * text adopted at hydration or a WebOTP fill (`undefined`).
11
+ */
12
+ readonly reason: ChangeReason;
13
+ }
14
+ /** Details passed as the second argument of `completeAction`. */
15
+ export interface OTPFieldCompleteDetails extends ActionDetails {
16
+ /**
17
+ * `"activate"`: an edit completed the code (typing, paste, keyboard autofill; `details.event`
18
+ * is the `input` event). `"platform"`: a WebOTP fill (`details.event` is `undefined`).
19
+ */
20
+ readonly reason: ChangeReason;
21
+ }
22
+ /** The state the Root's and the Input's function props receive. */
23
+ export interface OTPFieldState {
24
+ /** The text shown, already filtered: at most `length` characters of `charset`. */
25
+ readonly value: string;
26
+ /** The number of characters in a complete code. */
27
+ readonly length: number;
28
+ /** `value.length === length`. */
29
+ readonly complete: boolean;
30
+ /** A `completeAction` is in flight. */
31
+ readonly pending: boolean;
32
+ /** The `disabled` prop, or the enclosing Field's. */
33
+ readonly disabled: boolean;
34
+ /** The `readOnly` prop. */
35
+ readonly readOnly: boolean;
36
+ /** Inside a `Field.Root`: an error is shown for the field. `false` outside. */
37
+ readonly invalid: boolean;
38
+ }
39
+ /**
40
+ * Props of `OTPField.Root`.
41
+ *
42
+ * @see https://ui.funstack.work/components/otp-field
43
+ */
44
+ export interface OTPFieldRootProps extends Omit<ComponentPropsWithRef<"div">, "className" | "style" | "children" | "defaultValue"> {
45
+ /** The number of characters in a complete code. */
46
+ length: number;
47
+ /**
48
+ * Which characters a code may contain; also picks the Input's `inputmode` and `pattern`.
49
+ *
50
+ * @defaultValue `"numeric"`
51
+ */
52
+ charset?: OTPFieldCharset;
53
+ /** Controlled text. Follows the input: it cannot hold an edit back (the urgent lane). */
54
+ value?: string;
55
+ /**
56
+ * Initial text in uncontrolled mode (filtered), and the form-reset target.
57
+ *
58
+ * @defaultValue `""`
59
+ */
60
+ defaultValue?: string;
61
+ /**
62
+ * The text changed: an edit (`"activate"`), a form reset, text adopted at hydration or a WebOTP
63
+ * fill (`"platform"`). A fact: called synchronously, outside any transition, not awaited.
64
+ * Called before `completeAction` for the same edit.
65
+ */
66
+ onValueChange?: UrgentChangeHandler<string, OTPFieldValueChangeDetails>;
67
+ /**
68
+ * An edit left the code complete: runs in the Root's transition and is awaited, with
69
+ * `data-pending` on the Root and the Input. Runs for every such edit, also while an earlier run
70
+ * is pending (a different code), and for the same code pasted again. Not at mount, on a reset,
71
+ * for a controlled change, or while disabled or read-only. A rejection reaches the nearest Error
72
+ * Boundary. May be a Server Function.
73
+ */
74
+ completeAction?: Action<[value: string, details: OTPFieldCompleteDetails]>;
75
+ /**
76
+ * Submit the Input's form (`requestSubmit()`) when an edit leaves the code complete, right
77
+ * after dispatching `completeAction`. A change of context on input (WCAG 3.2.2): say so before
78
+ * the field.
79
+ *
80
+ * @defaultValue `false`
81
+ */
82
+ submitOnComplete?: boolean;
83
+ /**
84
+ * Native `name` on the Input.
85
+ *
86
+ * @defaultValue the Field's `name` inside a `Field.Root`
87
+ */
88
+ name?: string;
89
+ /** Native `form` on the Input. */
90
+ form?: string;
91
+ /**
92
+ * Native `required` on the Input; or the Field's.
93
+ *
94
+ * @defaultValue `false`
95
+ */
96
+ required?: boolean;
97
+ /**
98
+ * Native `disabled` on the Input; or the Field's.
99
+ *
100
+ * @defaultValue `false`
101
+ */
102
+ disabled?: boolean;
103
+ /**
104
+ * Native `readonly` on the Input: no edits, no completion.
105
+ *
106
+ * @defaultValue `false`
107
+ */
108
+ readOnly?: boolean;
109
+ /**
110
+ * The native attribute, with a library default: a code is read left to right in every locale,
111
+ * so the Slots, the Input's text and its caret keys stay left to right inside an RTL page.
112
+ * Pass `"rtl"` for a code that is read right to left (the attribute has no value meaning
113
+ * "inherit"). A `dir` on a `render` element wins as well.
114
+ *
115
+ * @defaultValue `"ltr"`
116
+ */
117
+ dir?: ComponentPropsWithRef<"div">["dir"];
118
+ /**
119
+ * Ask the browser for the code of an origin-bound SMS (WebOTP, `navigator.credentials.get({
120
+ * otp })`) while the Input is mounted. Chromium and Safari; nothing happens where the API is
121
+ * missing (Firefox).
122
+ *
123
+ * @defaultValue `false`
124
+ */
125
+ experimental_webOTP?: boolean;
126
+ /** Class name, or a function of the state that returns one. */
127
+ className?: StateValue<string | undefined, OTPFieldState>;
128
+ /** Inline style, or a function of the state that returns one. `position: relative` unless given. */
129
+ style?: StateValue<CSSProperties | undefined, OTPFieldState>;
130
+ /** The parts. The function form receives the state. */
131
+ children?: StateValue<ReactNode, OTPFieldState>;
132
+ /** Replace the default `<div>` (element form) or take over rendering (function form). */
133
+ render?: RenderProp<ComponentPropsWithRef<"div">, OTPFieldState>;
134
+ }
135
+ /**
136
+ * Owns the text of a one-time-code field (design/components/otp-field.md): the urgent value
137
+ * (`value` / `defaultValue` / `onValueChange`), the filter that keeps it a code, the selection the
138
+ * Slots draw, the completion transition (`completeAction`, `submitOnComplete`), form reset,
139
+ * hydration adoption and WebOTP. Renders a `div` with `position: relative`: the box the Input
140
+ * covers.
141
+ *
142
+ * Owned keys (conventions 1.2): `data-complete`, `data-pending`, `data-disabled`,
143
+ * `data-invalid` (inside a Field); `position` in `style` unless the consumer's style sets it.
144
+ *
145
+ * @see https://ui.funstack.work/components/otp-field
146
+ */
147
+ export declare function OTPFieldRoot(props: OTPFieldRootProps): import("react").JSX.Element;
148
+ export declare namespace OTPFieldRoot {
149
+ var displayName: string;
150
+ }
151
+ //#endregion
152
+ //# sourceMappingURL=otp-field-root.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp-field-root.d.mts","names":[],"sources":["../../src/otp-field/otp-field-root.tsx"],"mappings":";;;;;iBA+CiB,mCAAmC;;;;;;WAMzC,QAAQ;;;iBAIF,gCAAgC;;;;;WAKtC,QAAQ;;;iBAIF;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,0BAA0B,KACzC;;EAIA;;;;;;EAMA,UAAU;;EAEV;;;;;;EAMA;;;;;;EAMA,gBAAgB,4BAA4B;;;;;;;;EAQ5C,iBAAiB,QAAQ,eAAe,SAAS;;;;;;;;EAQjD;;;;;;EAMA;;EAEA;;;;;;EAMA;;;;;;EAMA;;;;;;EAMA;;;;;;;;;EASA,MAAM;;;;;;;;EAQN;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;wBAiEpC,aAAa,OAAO,oCAAiB,IAAA;yBAArC"}
@@ -0,0 +1,400 @@
1
+ "use client";
2
+ import { createActionDetails } from "../internal/action/action-details.mjs";
3
+ import { dataAttr } from "../internal/data-attr.mjs";
4
+ import { useDevWarning } from "../internal/use-dev-warning.mjs";
5
+ import { resolveStateValue } from "../internal/render-element.mjs";
6
+ import { useActionTrigger } from "../internal/action/use-action-trigger.mjs";
7
+ import { useRender } from "../internal/use-render.mjs";
8
+ import { transitionTypes } from "../internal/transition-types.mjs";
9
+ import { useLatest } from "../internal/use-latest.mjs";
10
+ import { callUrgentHandler } from "../internal/action/call-urgent-handler.mjs";
11
+ import { FieldContext } from "../internal/form/field-context.mjs";
12
+ import { resolveFieldDefaults, useFieldValueChange } from "../internal/form/use-field-control.mjs";
13
+ import { useFormReset, useResetTarget } from "../internal/form/use-form-reset.mjs";
14
+ import { OTPFieldContext } from "./otp-field-context.mjs";
15
+ import { activeRange, applyEdit, filterChars, normalizeCode } from "./otp-field-filter.mjs";
16
+ import { addTransitionType, use, useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
17
+ import { jsx } from "react/jsx-runtime";
18
+ //#region src/otp-field/otp-field-root.tsx
19
+ const isDev = process.env.NODE_ENV !== "production";
20
+ const COMPLETE_TYPES = transitionTypes("otp-field", "complete");
21
+ const BLURRED = {
22
+ focused: false,
23
+ start: null,
24
+ end: null
25
+ };
26
+ function isFocused(input) {
27
+ return input.ownerDocument.activeElement === input || input.matches(":focus");
28
+ }
29
+ /** Writes `value` into the input when it differs and puts the selection at `[start, end]`. */
30
+ function writeInput(input, value, start, end = start) {
31
+ if (input.value !== value) input.value = value;
32
+ if (start === null || end === null || !isFocused(input)) return;
33
+ if (input.selectionStart !== start || input.selectionEnd !== end) input.setSelectionRange(start, end);
34
+ }
35
+ /** The development check of the mounted Slots' indices (design 1). */
36
+ function slotIndexProblem(slots, length) {
37
+ if (slots.size === 0) return null;
38
+ const seen = /* @__PURE__ */ new Set();
39
+ for (const index of slots.values()) {
40
+ if (!Number.isInteger(index) || index < 0 || index >= length) return `OTPField.Slot: index ${index} is outside 0 to ${length - 1} (length ${length}).`;
41
+ if (seen.has(index)) return `OTPField.Slot: index ${index} is used by more than one Slot.`;
42
+ seen.add(index);
43
+ }
44
+ for (let i = 0; i < length; i++) if (!seen.has(i)) return `OTPField.Slot: no Slot has index ${i} (length ${length}). Render one Slot per position, or the code's characters are not all shown.`;
45
+ return null;
46
+ }
47
+ /**
48
+ * Owns the text of a one-time-code field (design/components/otp-field.md): the urgent value
49
+ * (`value` / `defaultValue` / `onValueChange`), the filter that keeps it a code, the selection the
50
+ * Slots draw, the completion transition (`completeAction`, `submitOnComplete`), form reset,
51
+ * hydration adoption and WebOTP. Renders a `div` with `position: relative`: the box the Input
52
+ * covers.
53
+ *
54
+ * Owned keys (conventions 1.2): `data-complete`, `data-pending`, `data-disabled`,
55
+ * `data-invalid` (inside a Field); `position` in `style` unless the consumer's style sets it.
56
+ *
57
+ * @see https://ui.funstack.work/components/otp-field
58
+ */
59
+ function OTPFieldRoot(props) {
60
+ const { length: lengthProp, charset: charsetProp = "numeric", value: valueProp, defaultValue, onValueChange, completeAction, submitOnComplete = false, name: nameProp, form, required: requiredProp = false, disabled: disabledProp = false, readOnly = false, dir = "ltr", experimental_webOTP: experimentalWebOTP = false, className, style, children, render, ...rest } = props;
61
+ const lengthValid = Number.isInteger(lengthProp) && lengthProp > 0;
62
+ const length = lengthValid ? lengthProp : Math.max(1, Math.floor(lengthProp) || 1);
63
+ useDevWarning(!lengthValid, isDev && `OTPField.Root: \`length\` must be a positive integer; got ${String(lengthProp)}.`);
64
+ const charset = charsetProp === "alphanumeric" || charsetProp === "alphabetic" ? charsetProp : "numeric";
65
+ const fieldContext = use(FieldContext);
66
+ const { disabled, required, name } = resolveFieldDefaults(fieldContext, {
67
+ name: nameProp,
68
+ disabled: disabledProp,
69
+ required: requiredProp
70
+ });
71
+ const fieldInvalid = fieldContext === null ? void 0 : fieldContext.state.invalid;
72
+ const controlled = valueProp !== void 0;
73
+ const controlledValue = controlled ? normalizeCode(valueProp, charset, length) : void 0;
74
+ useDevWarning(controlled && controlledValue !== valueProp, isDev && `OTPField.Root: the controlled \`value\` ("${valueProp ?? ""}") holds characters outside \`charset\` ("${charset}") or more than \`length\` (${length}); it is rendered as "${controlledValue ?? ""}".`);
75
+ const [internalValue, setInternalValue] = useState(() => normalizeCode(defaultValue ?? "", charset, length));
76
+ const value = controlledValue ?? internalValue;
77
+ const valueRef = useRef(value);
78
+ useLayoutEffect(() => {
79
+ valueRef.current = value;
80
+ });
81
+ /** The raw text while a composition is open (design 4.1, Composition): rendered as is. */
82
+ const [composingText, setComposingText] = useState(null);
83
+ const composingRef = useRef(false);
84
+ const [selection, setSelection] = useState(BLURRED);
85
+ const inputRef = useRef(null);
86
+ const beforeRef = useRef(null);
87
+ /** The value change the Field is told about next was an edit (design 7: `takeEdit`). */
88
+ const editRef = useRef(false);
89
+ const webOTPAbort = useRef(null);
90
+ /** A completion happened: no WebOTP request starts any more, and a late code is ignored. */
91
+ const webOTPDone = useRef(false);
92
+ /** `submitOnComplete` was held back by an open composition. */
93
+ const submitAfterComposition = useRef(false);
94
+ const { pending, run } = useActionTrigger();
95
+ const propsRef = useLatest({
96
+ charset,
97
+ length,
98
+ disabled,
99
+ readOnly,
100
+ controlled,
101
+ onValueChange,
102
+ completeAction,
103
+ submitOnComplete,
104
+ run,
105
+ notifyField: fieldContext?.notifyChange
106
+ });
107
+ /** Writes the value (urgent) and reports it to `onValueChange` (design 3.2). */
108
+ const commitValue = useCallback((next, reason, event, edit) => {
109
+ const props = propsRef.current;
110
+ editRef.current = edit;
111
+ if (!props.controlled) {
112
+ valueRef.current = next;
113
+ setInternalValue(next);
114
+ }
115
+ callUrgentHandler(props.onValueChange, next, createActionDetails(event, { reason }));
116
+ }, [propsRef]);
117
+ /** Submits the Input's form, after the Field re-validated the text just written (design 3.1). */
118
+ const submit = useCallback(() => {
119
+ const form = inputRef.current?.form;
120
+ if (form == null) return;
121
+ propsRef.current.notifyField?.(true);
122
+ form.requestSubmit();
123
+ }, [propsRef]);
124
+ /** The code is complete after an edit or a WebOTP fill (design 3.1). */
125
+ const complete = useCallback((code, reason, event, composing = false) => {
126
+ const { disabled: off, readOnly: ro, completeAction: action, submitOnComplete: submitting, run: runAction } = propsRef.current;
127
+ if (off || ro) return;
128
+ webOTPDone.current = true;
129
+ webOTPAbort.current?.abort();
130
+ webOTPAbort.current = null;
131
+ if (action !== void 0) {
132
+ const details = createActionDetails(event, { reason });
133
+ runAction(() => {
134
+ for (const type of COMPLETE_TYPES) addTransitionType(type);
135
+ return action(code, details);
136
+ });
137
+ }
138
+ if (!submitting) return;
139
+ if (composing) submitAfterComposition.current = true;
140
+ else submit();
141
+ }, [propsRef, submit]);
142
+ const readSelection = useCallback(() => {
143
+ const input = inputRef.current;
144
+ const next = input === null || !isFocused(input) ? BLURRED : {
145
+ focused: true,
146
+ start: input.selectionStart,
147
+ end: input.selectionEnd
148
+ };
149
+ setSelection((prev) => prev.focused === next.focused && prev.start === next.start && prev.end === next.end ? prev : next);
150
+ }, []);
151
+ const beforeInput = useCallback((event) => {
152
+ const input = event.target;
153
+ beforeRef.current = {
154
+ text: input.value,
155
+ selectionStart: input.selectionStart ?? input.value.length,
156
+ selectionEnd: input.selectionEnd ?? input.value.length
157
+ };
158
+ }, []);
159
+ const change = useCallback((event) => {
160
+ const input = event.currentTarget;
161
+ const native = event.nativeEvent;
162
+ const before = beforeRef.current;
163
+ beforeRef.current = null;
164
+ const { charset: cs, length: len, disabled: off, readOnly: ro } = propsRef.current;
165
+ if (off || ro) return;
166
+ if (composingRef.current || native.isComposing === true) {
167
+ const next = normalizeCode(input.value, cs, len);
168
+ setComposingText(input.value);
169
+ readSelection();
170
+ if (next === valueRef.current) return;
171
+ commitValue(next, "activate", native, true);
172
+ if (next.length === len) complete(next, "activate", native, true);
173
+ return;
174
+ }
175
+ const result = applyEdit({
176
+ before,
177
+ dom: input.value,
178
+ caret: input.selectionStart,
179
+ inputType: native.inputType ?? "",
180
+ charset: cs,
181
+ length: len
182
+ });
183
+ setComposingText(null);
184
+ if (result.selection !== null) writeInput(input, result.value, result.selection[0], result.selection[1]);
185
+ else writeInput(input, result.value, result.caret);
186
+ readSelection();
187
+ const changed = result.value !== valueRef.current;
188
+ if (changed) commitValue(result.value, "activate", native, true);
189
+ if (result.value.length === len && (changed || result.kept > 0)) complete(result.value, "activate", native);
190
+ }, [
191
+ commitValue,
192
+ complete,
193
+ propsRef,
194
+ readSelection
195
+ ]);
196
+ const compositionStart = useCallback(() => {
197
+ composingRef.current = true;
198
+ }, []);
199
+ const compositionEnd = useCallback((event) => {
200
+ composingRef.current = false;
201
+ const input = inputRef.current;
202
+ setComposingText(null);
203
+ if (input === null) return;
204
+ const { charset: cs, length: len } = propsRef.current;
205
+ const dom = input.value;
206
+ const next = normalizeCode(dom, cs, len);
207
+ writeInput(input, next, Math.min(filterChars(dom.slice(0, input.selectionStart ?? dom.length), cs).length, next.length));
208
+ readSelection();
209
+ const held = submitAfterComposition.current;
210
+ submitAfterComposition.current = false;
211
+ if (next !== valueRef.current) {
212
+ commitValue(next, "activate", event, true);
213
+ if (next.length === len) complete(next, "activate", event);
214
+ return;
215
+ }
216
+ if (held && next.length === len && propsRef.current.submitOnComplete) submit();
217
+ }, [
218
+ commitValue,
219
+ complete,
220
+ propsRef,
221
+ readSelection,
222
+ submit
223
+ ]);
224
+ const blurred = useCallback(() => {
225
+ setSelection(BLURRED);
226
+ }, []);
227
+ const slots = useRef(/* @__PURE__ */ new Map());
228
+ const registerSlot = useCallback((index, element) => {
229
+ slots.current.set(element, index);
230
+ return () => {
231
+ if (slots.current.get(element) === index) slots.current.delete(element);
232
+ };
233
+ }, []);
234
+ const click = useCallback((event) => {
235
+ const input = inputRef.current;
236
+ if (input === null || event.detail > 1 || input.selectionStart !== input.selectionEnd) return;
237
+ let target = null;
238
+ let distance = Infinity;
239
+ for (const [element, index] of slots.current) {
240
+ const box = element.getBoundingClientRect();
241
+ if (box.width === 0 && box.height === 0) continue;
242
+ const dx = Math.max(box.left - event.clientX, 0, event.clientX - box.right);
243
+ const dy = Math.max(box.top - event.clientY, 0, event.clientY - box.bottom);
244
+ const d = dx * dx + dy * dy;
245
+ if (d < distance) {
246
+ distance = d;
247
+ target = index;
248
+ }
249
+ }
250
+ if (target === null) return;
251
+ const caret = Math.min(target, input.value.length);
252
+ if (input.selectionStart !== caret || input.selectionEnd !== caret) input.setSelectionRange(caret, caret);
253
+ }, []);
254
+ const inputMounted = useCallback(() => {
255
+ const input = inputRef.current;
256
+ if (input === null) return;
257
+ const { charset: cs, length: len } = propsRef.current;
258
+ const dom = input.value;
259
+ const next = normalizeCode(dom, cs, len);
260
+ if (dom !== next) input.value = next;
261
+ if (next !== valueRef.current) commitValue(next, "platform", void 0, false);
262
+ }, [commitValue, propsRef]);
263
+ const resetTarget = normalizeCode(useResetTarget(valueProp, defaultValue) ?? "", charset, length);
264
+ const [resync, setResync] = useState(0);
265
+ const inputText = composingText ?? value;
266
+ const inputTextRef = useLatest(inputText);
267
+ useLayoutEffect(() => {
268
+ const input = inputRef.current;
269
+ if (resync > 0 && input !== null && input.value !== inputTextRef.current) input.value = inputTextRef.current;
270
+ }, [resync, inputTextRef]);
271
+ useFormReset(inputRef, (event) => {
272
+ composingRef.current = false;
273
+ setComposingText(null);
274
+ if (resetTarget !== valueRef.current) commitValue(resetTarget, "platform", event, false);
275
+ setResync((n) => n + 1);
276
+ }, () => {
277
+ const input = inputRef.current;
278
+ if (input !== null && input.defaultValue !== resetTarget) input.defaultValue = resetTarget;
279
+ });
280
+ const webOTPCode = useCallback((code) => {
281
+ const { charset: cs, length: len, disabled: off, readOnly: ro } = propsRef.current;
282
+ if (off || ro || webOTPDone.current) return;
283
+ const next = filterChars(code, cs);
284
+ if (next.length !== len) return;
285
+ const input = inputRef.current;
286
+ if (input !== null) input.value = next;
287
+ if (next !== valueRef.current) commitValue(next, "platform", void 0, true);
288
+ complete(next, "platform", void 0);
289
+ }, [
290
+ commitValue,
291
+ complete,
292
+ propsRef
293
+ ]);
294
+ useFieldValueChange(value, () => {
295
+ const edit = editRef.current;
296
+ editRef.current = false;
297
+ return edit;
298
+ });
299
+ const slotWarned = useRef(false);
300
+ useLayoutEffect(() => {
301
+ if (!isDev || slotWarned.current) return;
302
+ const problem = slotIndexProblem(slots.current, length);
303
+ if (problem === null) return;
304
+ slotWarned.current = true;
305
+ console.error(problem);
306
+ });
307
+ const state = useMemo(() => ({
308
+ value,
309
+ length,
310
+ complete: value.length === length,
311
+ pending,
312
+ disabled,
313
+ readOnly,
314
+ invalid: fieldInvalid === true
315
+ }), [
316
+ value,
317
+ length,
318
+ pending,
319
+ disabled,
320
+ readOnly,
321
+ fieldInvalid
322
+ ]);
323
+ const [activeFrom, activeTo] = activeRange(selection.focused, selection.start, selection.end, length);
324
+ const context = useMemo(() => ({
325
+ state,
326
+ charset,
327
+ name,
328
+ form,
329
+ required,
330
+ fieldInvalid,
331
+ inputText,
332
+ active: [activeFrom, activeTo],
333
+ experimentalWebOTP,
334
+ inputRef,
335
+ change,
336
+ beforeInput,
337
+ compositionStart,
338
+ compositionEnd,
339
+ selectionChanged: readSelection,
340
+ blurred,
341
+ click,
342
+ inputMounted,
343
+ webOTPCode,
344
+ registerSlot,
345
+ webOTPAbort,
346
+ webOTPDone
347
+ }), [
348
+ state,
349
+ charset,
350
+ name,
351
+ form,
352
+ required,
353
+ fieldInvalid,
354
+ inputText,
355
+ activeFrom,
356
+ activeTo,
357
+ experimentalWebOTP,
358
+ change,
359
+ beforeInput,
360
+ compositionStart,
361
+ compositionEnd,
362
+ readSelection,
363
+ blurred,
364
+ click,
365
+ inputMounted,
366
+ webOTPCode,
367
+ registerSlot
368
+ ]);
369
+ const libraryProps = {
370
+ ...fieldContext !== null ? { "data-invalid": dataAttr(fieldInvalid === true) } : {},
371
+ "data-complete": dataAttr(state.complete),
372
+ "data-pending": dataAttr(pending),
373
+ "data-disabled": dataAttr(disabled)
374
+ };
375
+ const element = useRender({
376
+ defaultElement: "div",
377
+ render,
378
+ state,
379
+ className,
380
+ style: (s) => ({
381
+ position: "relative",
382
+ ...resolveStateValue(style, s)
383
+ }),
384
+ children,
385
+ props: {
386
+ ...rest,
387
+ dir
388
+ },
389
+ libraryProps
390
+ });
391
+ return /* @__PURE__ */ jsx(OTPFieldContext, {
392
+ value: context,
393
+ children: element
394
+ });
395
+ }
396
+ OTPFieldRoot.displayName = "OTPFieldRoot";
397
+ //#endregion
398
+ export { OTPFieldRoot };
399
+
400
+ //# sourceMappingURL=otp-field-root.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp-field-root.mjs","names":[],"sources":["../../src/otp-field/otp-field-root.tsx"],"sourcesContent":["\"use client\";\nimport {\n addTransitionType,\n use,\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n ReactNode,\n RefObject,\n} from \"react\";\nimport { createActionDetails } from \"../internal/action/action-details.js\";\nimport { callUrgentHandler } from \"../internal/action/call-urgent-handler.js\";\nimport { useActionTrigger } from \"../internal/action/use-action-trigger.js\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport { FieldContext } from \"../internal/form/field-context.js\";\nimport { resolveFieldDefaults, useFieldValueChange } from \"../internal/form/use-field-control.js\";\nimport { useFormReset, useResetTarget } from \"../internal/form/use-form-reset.js\";\nimport type { FormAssociatedElement } from \"../internal/form/use-form-owner-event.js\";\nimport { resolveStateValue } from \"../internal/render-element.js\";\nimport { transitionTypes } from \"../internal/transition-types.js\";\nimport type {\n Action,\n ActionDetails,\n ChangeReason,\n RenderProp,\n StateValue,\n UrgentChangeHandler,\n} from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { OTPFieldContext } from \"./otp-field-context.js\";\nimport type { OTPFieldContextValue } from \"./otp-field-context.js\";\nimport { activeRange, applyEdit, filterChars, normalizeCode } from \"./otp-field-filter.js\";\nimport type { EditBefore, OTPFieldCharset } from \"./otp-field-filter.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** Details passed as the second argument of `onValueChange`. */\nexport interface OTPFieldValueChangeDetails extends ActionDetails {\n /**\n * `\"activate\"`: the user edited the text (`details.event` is the `input` event, or the\n * `compositionend` that ended a composition). `\"platform\"`: a form reset (the `reset` event),\n * text adopted at hydration or a WebOTP fill (`undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/** Details passed as the second argument of `completeAction`. */\nexport interface OTPFieldCompleteDetails extends ActionDetails {\n /**\n * `\"activate\"`: an edit completed the code (typing, paste, keyboard autofill; `details.event`\n * is the `input` event). `\"platform\"`: a WebOTP fill (`details.event` is `undefined`).\n */\n readonly reason: ChangeReason;\n}\n\n/** The state the Root's and the Input's function props receive. */\nexport interface OTPFieldState {\n /** The text shown, already filtered: at most `length` characters of `charset`. */\n readonly value: string;\n /** The number of characters in a complete code. */\n readonly length: number;\n /** `value.length === length`. */\n readonly complete: boolean;\n /** A `completeAction` is in flight. */\n readonly pending: boolean;\n /** The `disabled` prop, or the enclosing Field's. */\n readonly disabled: boolean;\n /** The `readOnly` prop. */\n readonly readOnly: boolean;\n /** Inside a `Field.Root`: an error is shown for the field. `false` outside. */\n readonly invalid: boolean;\n}\n\n/**\n * Props of `OTPField.Root`.\n *\n * @see https://ui.funstack.work/components/otp-field\n */\nexport interface OTPFieldRootProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"className\" | \"style\" | \"children\" | \"defaultValue\"\n> {\n /** The number of characters in a complete code. */\n length: number;\n /**\n * Which characters a code may contain; also picks the Input's `inputmode` and `pattern`.\n *\n * @defaultValue `\"numeric\"`\n */\n charset?: OTPFieldCharset;\n /** Controlled text. Follows the input: it cannot hold an edit back (the urgent lane). */\n value?: string;\n /**\n * Initial text in uncontrolled mode (filtered), and the form-reset target.\n *\n * @defaultValue `\"\"`\n */\n defaultValue?: string;\n /**\n * The text changed: an edit (`\"activate\"`), a form reset, text adopted at hydration or a WebOTP\n * fill (`\"platform\"`). A fact: called synchronously, outside any transition, not awaited.\n * Called before `completeAction` for the same edit.\n */\n onValueChange?: UrgentChangeHandler<string, OTPFieldValueChangeDetails>;\n /**\n * An edit left the code complete: runs in the Root's transition and is awaited, with\n * `data-pending` on the Root and the Input. Runs for every such edit, also while an earlier run\n * is pending (a different code), and for the same code pasted again. Not at mount, on a reset,\n * for a controlled change, or while disabled or read-only. A rejection reaches the nearest Error\n * Boundary. May be a Server Function.\n */\n completeAction?: Action<[value: string, details: OTPFieldCompleteDetails]>;\n /**\n * Submit the Input's form (`requestSubmit()`) when an edit leaves the code complete, right\n * after dispatching `completeAction`. A change of context on input (WCAG 3.2.2): say so before\n * the field.\n *\n * @defaultValue `false`\n */\n submitOnComplete?: boolean;\n /**\n * Native `name` on the Input.\n *\n * @defaultValue the Field's `name` inside a `Field.Root`\n */\n name?: string;\n /** Native `form` on the Input. */\n form?: string;\n /**\n * Native `required` on the Input; or the Field's.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /**\n * Native `disabled` on the Input; or the Field's.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Native `readonly` on the Input: no edits, no completion.\n *\n * @defaultValue `false`\n */\n readOnly?: boolean;\n /**\n * The native attribute, with a library default: a code is read left to right in every locale,\n * so the Slots, the Input's text and its caret keys stay left to right inside an RTL page.\n * Pass `\"rtl\"` for a code that is read right to left (the attribute has no value meaning\n * \"inherit\"). A `dir` on a `render` element wins as well.\n *\n * @defaultValue `\"ltr\"`\n */\n dir?: ComponentPropsWithRef<\"div\">[\"dir\"];\n /**\n * Ask the browser for the code of an origin-bound SMS (WebOTP, `navigator.credentials.get({\n * otp })`) while the Input is mounted. Chromium and Safari; nothing happens where the API is\n * missing (Firefox).\n *\n * @defaultValue `false`\n */\n experimental_webOTP?: boolean;\n /** Class name, or a function of the state that returns one. */\n className?: StateValue<string | undefined, OTPFieldState>;\n /** Inline style, or a function of the state that returns one. `position: relative` unless given. */\n style?: StateValue<CSSProperties | undefined, OTPFieldState>;\n /** The parts. The function form receives the state. */\n children?: StateValue<ReactNode, OTPFieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, OTPFieldState>;\n}\n\nconst COMPLETE_TYPES = transitionTypes(\"otp-field\", \"complete\");\n\ninterface Selection {\n readonly focused: boolean;\n readonly start: number | null;\n readonly end: number | null;\n}\n\nconst BLURRED: Selection = { focused: false, start: null, end: null };\n\nfunction isFocused(input: HTMLInputElement): boolean {\n return input.ownerDocument.activeElement === input || input.matches(\":focus\");\n}\n\n/** Writes `value` into the input when it differs and puts the selection at `[start, end]`. */\nfunction writeInput(\n input: HTMLInputElement,\n value: string,\n start: number | null,\n end: number | null = start,\n): void {\n if (input.value !== value) input.value = value;\n if (start === null || end === null || !isFocused(input)) return;\n if (input.selectionStart !== start || input.selectionEnd !== end) {\n input.setSelectionRange(start, end);\n }\n}\n\n/** The development check of the mounted Slots' indices (design 1). */\nfunction slotIndexProblem(slots: Map<HTMLElement, number>, length: number): string | null {\n if (slots.size === 0) return null;\n const seen = new Set<number>();\n for (const index of slots.values()) {\n if (!Number.isInteger(index) || index < 0 || index >= length) {\n return `OTPField.Slot: index ${index} is outside 0 to ${length - 1} (length ${length}).`;\n }\n if (seen.has(index)) return `OTPField.Slot: index ${index} is used by more than one Slot.`;\n seen.add(index);\n }\n for (let i = 0; i < length; i++) {\n if (!seen.has(i)) {\n return (\n `OTPField.Slot: no Slot has index ${i} (length ${length}). Render one Slot per ` +\n \"position, or the code's characters are not all shown.\"\n );\n }\n }\n return null;\n}\n\n/**\n * Owns the text of a one-time-code field (design/components/otp-field.md): the urgent value\n * (`value` / `defaultValue` / `onValueChange`), the filter that keeps it a code, the selection the\n * Slots draw, the completion transition (`completeAction`, `submitOnComplete`), form reset,\n * hydration adoption and WebOTP. Renders a `div` with `position: relative`: the box the Input\n * covers.\n *\n * Owned keys (conventions 1.2): `data-complete`, `data-pending`, `data-disabled`,\n * `data-invalid` (inside a Field); `position` in `style` unless the consumer's style sets it.\n *\n * @see https://ui.funstack.work/components/otp-field\n */\nexport function OTPFieldRoot(props: OTPFieldRootProps) {\n const {\n length: lengthProp,\n charset: charsetProp = \"numeric\",\n value: valueProp,\n defaultValue,\n onValueChange,\n completeAction,\n submitOnComplete = false,\n name: nameProp,\n form,\n required: requiredProp = false,\n disabled: disabledProp = false,\n readOnly = false,\n // design/components/otp-field.md 4.4, conventions 14.1 rule 8: a pass-through prop with a\n // default, so a `render` element's own `dir` wins over it (conventions 1.2).\n dir = \"ltr\",\n experimental_webOTP: experimentalWebOTP = false,\n className,\n style,\n children,\n render,\n ...rest\n } = props;\n\n const lengthValid = Number.isInteger(lengthProp) && lengthProp > 0;\n const length = lengthValid ? lengthProp : Math.max(1, Math.floor(lengthProp) || 1);\n useDevWarning(\n !lengthValid,\n isDev && `OTPField.Root: \\`length\\` must be a positive integer; got ${String(lengthProp)}.`,\n );\n const charset: OTPFieldCharset =\n charsetProp === \"alphanumeric\" || charsetProp === \"alphabetic\" ? charsetProp : \"numeric\";\n\n // --- Field ----------------------------------------------------------------------------------\n\n // OTPField.Input registers the control (design 7); the Root resolves the defaults.\n const fieldContext = use(FieldContext);\n const { disabled, required, name } = resolveFieldDefaults(fieldContext, {\n name: nameProp,\n disabled: disabledProp,\n required: requiredProp,\n });\n const fieldInvalid = fieldContext === null ? undefined : fieldContext.state.invalid;\n\n // --- The text (design 3.2) ------------------------------------------------------------------\n\n const controlled = valueProp !== undefined;\n const controlledValue = controlled ? normalizeCode(valueProp, charset, length) : undefined;\n useDevWarning(\n controlled && controlledValue !== valueProp,\n isDev &&\n `OTPField.Root: the controlled \\`value\\` (\"${valueProp ?? \"\"}\") holds characters outside ` +\n `\\`charset\\` (\"${charset}\") or more than \\`length\\` (${length}); it is rendered as ` +\n `\"${controlledValue ?? \"\"}\".`,\n );\n const [internalValue, setInternalValue] = useState(() =>\n normalizeCode(defaultValue ?? \"\", charset, length),\n );\n const value = controlledValue ?? internalValue;\n const valueRef = useRef(value);\n // The latest value for handlers between two renders (two edits in one task).\n useLayoutEffect(() => {\n valueRef.current = value;\n });\n\n /** The raw text while a composition is open (design 4.1, Composition): rendered as is. */\n const [composingText, setComposingText] = useState<string | null>(null);\n const composingRef = useRef(false);\n const [selection, setSelection] = useState<Selection>(BLURRED);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const beforeRef = useRef<EditBefore | null>(null);\n /** The value change the Field is told about next was an edit (design 7: `takeEdit`). */\n const editRef = useRef(false);\n const webOTPAbort = useRef<AbortController | null>(null);\n /** A completion happened: no WebOTP request starts any more, and a late code is ignored. */\n const webOTPDone = useRef(false);\n /** `submitOnComplete` was held back by an open composition. */\n const submitAfterComposition = useRef(false);\n\n const { pending, run } = useActionTrigger();\n\n // The latest committed props and `run`, for the stable callbacks below. Named `*Ref` so that\n // React Compiler's lint treats `.current` as a ref read, not a missing memo dependency.\n // `run` is a new function on every render: reading it through the ref keeps every handler,\n // the context and the Input's listeners and WebOTP request stable across renders.\n const propsRef = useLatest({\n charset,\n length,\n disabled,\n readOnly,\n controlled,\n onValueChange,\n completeAction,\n submitOnComplete,\n run,\n notifyField: fieldContext?.notifyChange,\n });\n\n // --- Writes ---------------------------------------------------------------------------------\n\n /** Writes the value (urgent) and reports it to `onValueChange` (design 3.2). */\n const commitValue = useCallback(\n (next: string, reason: ChangeReason, event: Event | undefined, edit: boolean) => {\n const props = propsRef.current;\n editRef.current = edit;\n // Controlled: the value is the parent's until it renders it (it may not adopt the edit).\n if (!props.controlled) {\n valueRef.current = next;\n setInternalValue(next);\n }\n callUrgentHandler(\n props.onValueChange,\n next,\n createActionDetails(event, { reason }) as OTPFieldValueChangeDetails,\n );\n },\n [propsRef],\n );\n\n /** Submits the Input's form, after the Field re-validated the text just written (design 3.1). */\n const submit = useCallback(() => {\n const form = inputRef.current?.form;\n if (form == null) return;\n // The Field validated the browser's pre-filter text in its `input` listener; the commit\n // that re-validates the written text comes after this event. Refresh it now.\n propsRef.current.notifyField?.(true);\n form.requestSubmit();\n }, [propsRef]);\n\n /** The code is complete after an edit or a WebOTP fill (design 3.1). */\n const complete = useCallback(\n (code: string, reason: ChangeReason, event: Event | undefined, composing = false) => {\n const {\n disabled: off,\n readOnly: ro,\n completeAction: action,\n submitOnComplete: submitting,\n run: runAction,\n } = propsRef.current;\n if (off || ro) return;\n // A code completed by hand makes a waiting WebOTP request moot (design 8), and no new one\n // starts after it.\n webOTPDone.current = true;\n webOTPAbort.current?.abort();\n webOTPAbort.current = null;\n if (action !== undefined) {\n const details = createActionDetails(event, { reason }) as OTPFieldCompleteDetails;\n runAction(() => {\n for (const type of COMPLETE_TYPES) addTransitionType(type);\n return action(code, details);\n });\n }\n if (!submitting) return;\n // The IME has not committed the text yet: submit at `compositionend` (design 4.1).\n if (composing) submitAfterComposition.current = true;\n else submit();\n },\n [propsRef, submit],\n );\n\n const readSelection = useCallback(() => {\n const input = inputRef.current;\n const next: Selection =\n input === null || !isFocused(input)\n ? BLURRED\n : { focused: true, start: input.selectionStart, end: input.selectionEnd };\n setSelection((prev) =>\n prev.focused === next.focused && prev.start === next.start && prev.end === next.end\n ? prev\n : next,\n );\n }, []);\n\n // --- Editing (design 4.1) -------------------------------------------------------------------\n\n const beforeInput = useCallback((event: InputEvent) => {\n const input = event.target as HTMLInputElement;\n beforeRef.current = {\n text: input.value,\n selectionStart: input.selectionStart ?? input.value.length,\n selectionEnd: input.selectionEnd ?? input.value.length,\n };\n }, []);\n\n const change = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const input = event.currentTarget;\n const native = event.nativeEvent as Partial<InputEvent> & Event;\n const before = beforeRef.current;\n beforeRef.current = null;\n const { charset: cs, length: len, disabled: off, readOnly: ro } = propsRef.current;\n if (off || ro) return;\n\n if (composingRef.current || native.isComposing === true) {\n // Derive always, write when allowed: the composition keeps its text in the input.\n const next = normalizeCode(input.value, cs, len);\n setComposingText(input.value);\n readSelection();\n if (next === valueRef.current) return;\n commitValue(next, \"activate\", native, true);\n if (next.length === len) complete(next, \"activate\", native, true);\n return;\n }\n\n const result = applyEdit({\n before,\n dom: input.value,\n caret: input.selectionStart,\n inputType: native.inputType ?? \"\",\n charset: cs,\n length: len,\n });\n setComposingText(null);\n if (result.selection !== null) {\n writeInput(input, result.value, result.selection[0], result.selection[1]);\n } else {\n writeInput(input, result.value, result.caret);\n }\n readSelection();\n const changed = result.value !== valueRef.current;\n if (changed) commitValue(result.value, \"activate\", native, true);\n if (result.value.length === len && (changed || result.kept > 0)) {\n complete(result.value, \"activate\", native);\n }\n },\n [commitValue, complete, propsRef, readSelection],\n );\n\n const compositionStart = useCallback(() => {\n composingRef.current = true;\n }, []);\n\n const compositionEnd = useCallback(\n (event: CompositionEvent) => {\n composingRef.current = false;\n const input = inputRef.current;\n setComposingText(null);\n if (input === null) return;\n const { charset: cs, length: len } = propsRef.current;\n const dom = input.value;\n const next = normalizeCode(dom, cs, len);\n const caret = Math.min(\n filterChars(dom.slice(0, input.selectionStart ?? dom.length), cs).length,\n next.length,\n );\n writeInput(input, next, caret);\n readSelection();\n const held = submitAfterComposition.current;\n submitAfterComposition.current = false;\n if (next !== valueRef.current) {\n commitValue(next, \"activate\", event, true);\n if (next.length === len) complete(next, \"activate\", event);\n return;\n }\n // The code was completed while composing: the submission held back then goes now.\n if (held && next.length === len && propsRef.current.submitOnComplete) submit();\n },\n [commitValue, complete, propsRef, readSelection, submit],\n );\n\n const blurred = useCallback(() => {\n setSelection(BLURRED);\n }, []);\n\n // --- The pointer (design 4.3) ---------------------------------------------------------------\n\n const slots = useRef(new Map<HTMLElement, number>());\n const registerSlot = useCallback((index: number, element: HTMLElement) => {\n slots.current.set(element, index);\n return () => {\n if (slots.current.get(element) === index) slots.current.delete(element);\n };\n }, []);\n\n const click = useCallback((event: MouseEvent) => {\n const input = inputRef.current;\n // A double click selects; a drag made a range: the browser's selection stands.\n if (input === null || event.detail > 1 || input.selectionStart !== input.selectionEnd) return;\n let target: number | null = null;\n let distance = Infinity;\n for (const [element, index] of slots.current) {\n const box = element.getBoundingClientRect();\n if (box.width === 0 && box.height === 0) continue;\n const dx = Math.max(box.left - event.clientX, 0, event.clientX - box.right);\n const dy = Math.max(box.top - event.clientY, 0, event.clientY - box.bottom);\n const d = dx * dx + dy * dy;\n if (d < distance) {\n distance = d;\n target = index;\n }\n }\n if (target === null) return;\n const caret = Math.min(target, input.value.length);\n if (input.selectionStart !== caret || input.selectionEnd !== caret) {\n input.setSelectionRange(caret, caret);\n }\n }, []);\n\n // --- Residual paths: hydration, reset, WebOTP (design 7, 8, 9) -----------------------------\n\n const inputMounted = useCallback(() => {\n const input = inputRef.current;\n if (input === null) return;\n const { charset: cs, length: len } = propsRef.current;\n const dom = input.value;\n const next = normalizeCode(dom, cs, len);\n if (dom !== next) input.value = next;\n // No completion for adopted text (design 9): a restored code is not a fresh one.\n if (next !== valueRef.current) commitValue(next, \"platform\", undefined, false);\n }, [commitValue, propsRef]);\n\n const resetTarget = normalizeCode(useResetTarget(valueProp, defaultValue) ?? \"\", charset, length);\n const [resync, setResync] = useState(0);\n const inputText = composingText ?? value;\n const inputTextRef = useLatest(inputText);\n useLayoutEffect(() => {\n // A controlled parent that did not adopt the reset gets the DOM put back.\n const input = inputRef.current;\n if (resync > 0 && input !== null && input.value !== inputTextRef.current) {\n input.value = inputTextRef.current;\n }\n }, [resync, inputTextRef]);\n useFormReset(\n inputRef as RefObject<FormAssociatedElement | null>,\n (event) => {\n composingRef.current = false;\n setComposingText(null);\n // The target is computed, not read from the input: after a click on a reset button this\n // microtask runs before the browser's reset algorithm (there is a microtask checkpoint\n // after each `reset` listener), so the input may still hold the old text here.\n if (resetTarget !== valueRef.current) commitValue(resetTarget, \"platform\", event, false);\n setResync((n) => n + 1);\n },\n () => {\n // react-dom rewrites a controlled input's `defaultValue` after every update; the reset\n // target is written right before the browser's reset algorithm reads it.\n const input = inputRef.current;\n if (input !== null && input.defaultValue !== resetTarget) input.defaultValue = resetTarget;\n },\n );\n\n const webOTPCode = useCallback(\n (code: string) => {\n const { charset: cs, length: len, disabled: off, readOnly: ro } = propsRef.current;\n if (off || ro || webOTPDone.current) return;\n const next = filterChars(code, cs);\n if (next.length !== len) return;\n // Written now, so that `submitOnComplete` posts it before React renders.\n const input = inputRef.current;\n if (input !== null) input.value = next;\n if (next !== valueRef.current) commitValue(next, \"platform\", undefined, true);\n complete(next, \"platform\", undefined);\n },\n [commitValue, complete, propsRef],\n );\n\n // A write-back or a WebOTP fill changed the value with no event the Field heard after it.\n useFieldValueChange(value, () => {\n const edit = editRef.current;\n editRef.current = false;\n return edit;\n });\n\n // --- Development warnings -------------------------------------------------------------------\n\n const slotWarned = useRef(false);\n useLayoutEffect(() => {\n if (!isDev || slotWarned.current) return;\n const problem = slotIndexProblem(slots.current, length);\n if (problem === null) return;\n slotWarned.current = true;\n console.error(problem);\n });\n\n // --- Render ---------------------------------------------------------------------------------\n\n const state = useMemo<OTPFieldState>(\n () => ({\n value,\n length,\n complete: value.length === length,\n pending,\n disabled,\n readOnly,\n invalid: fieldInvalid === true,\n }),\n [value, length, pending, disabled, readOnly, fieldInvalid],\n );\n\n const [activeFrom, activeTo] = activeRange(\n selection.focused,\n selection.start,\n selection.end,\n length,\n );\n\n const context = useMemo<OTPFieldContextValue>(\n () => ({\n state,\n charset,\n name,\n form,\n required,\n fieldInvalid,\n inputText,\n active: [activeFrom, activeTo],\n experimentalWebOTP,\n inputRef,\n change,\n beforeInput,\n compositionStart,\n compositionEnd,\n selectionChanged: readSelection,\n blurred,\n click,\n inputMounted,\n webOTPCode,\n registerSlot,\n webOTPAbort,\n webOTPDone,\n }),\n [\n state,\n charset,\n name,\n form,\n required,\n fieldInvalid,\n inputText,\n activeFrom,\n activeTo,\n experimentalWebOTP,\n change,\n beforeInput,\n compositionStart,\n compositionEnd,\n readSelection,\n blurred,\n click,\n inputMounted,\n webOTPCode,\n registerSlot,\n ],\n );\n\n const libraryProps: Partial<ComponentPropsWithRef<\"div\">> & DataAttributes = {\n ...(fieldContext !== null ? { \"data-invalid\": dataAttr(fieldInvalid === true) } : {}),\n \"data-complete\": dataAttr(state.complete),\n \"data-pending\": dataAttr(pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, OTPFieldState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // `position: relative` is the Input's containing block (design 6), unless the consumer's\n // style places the Root itself.\n style: (s) => ({ position: \"relative\", ...resolveStateValue(style, s) }),\n children,\n props: { ...rest, dir },\n libraryProps,\n });\n\n return <OTPFieldContext value={context}>{element}</OTPFieldContext>;\n}\n\nOTPFieldRoot.displayName = \"O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