@intentface/ui 0.0.0 → 0.7.0

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 (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -2
  3. package/dist/ask-user/ask-user.d.ts +104 -0
  4. package/dist/ask-user/ask-user.js +245 -0
  5. package/dist/ask-user/index.d.ts +3 -0
  6. package/dist/ask-user/index.js +3 -0
  7. package/dist/ask-user/index.parts.d.ts +1 -0
  8. package/dist/ask-user/index.parts.js +5 -0
  9. package/dist/attachments/attachments.d.ts +73 -0
  10. package/dist/attachments/attachments.js +121 -0
  11. package/dist/attachments/index.d.ts +3 -0
  12. package/dist/attachments/index.js +3 -0
  13. package/dist/attachments/index.parts.d.ts +1 -0
  14. package/dist/attachments/index.parts.js +5 -0
  15. package/dist/chip/chip.d.ts +45 -0
  16. package/dist/chip/chip.js +43 -0
  17. package/dist/chip/index.d.ts +2 -0
  18. package/dist/chip/index.js +2 -0
  19. package/dist/chip/index.parts.d.ts +1 -0
  20. package/dist/chip/index.parts.js +5 -0
  21. package/dist/chip-markdown.d.ts +25 -0
  22. package/dist/chip-markdown.js +54 -0
  23. package/dist/composer/actions.d.ts +35 -0
  24. package/dist/composer/actions.js +76 -0
  25. package/dist/composer/ask-user-machine.d.ts +52 -0
  26. package/dist/composer/ask-user-machine.js +164 -0
  27. package/dist/composer/attachments-machine.d.ts +34 -0
  28. package/dist/composer/attachments-machine.js +91 -0
  29. package/dist/composer/attachments.d.ts +16 -0
  30. package/dist/composer/attachments.js +32 -0
  31. package/dist/composer/command-list.d.ts +49 -0
  32. package/dist/composer/command-list.js +360 -0
  33. package/dist/composer/commands.d.ts +28 -0
  34. package/dist/composer/commands.js +56 -0
  35. package/dist/composer/container.d.ts +3 -0
  36. package/dist/composer/container.js +32 -0
  37. package/dist/composer/controller.d.ts +3 -0
  38. package/dist/composer/controller.js +6 -0
  39. package/dist/composer/editor-dom.d.ts +57 -0
  40. package/dist/composer/editor-dom.js +517 -0
  41. package/dist/composer/fuzzy.d.ts +4 -0
  42. package/dist/composer/fuzzy.js +49 -0
  43. package/dist/composer/index.d.ts +25 -0
  44. package/dist/composer/index.js +13 -0
  45. package/dist/composer/index.parts.d.ts +11 -0
  46. package/dist/composer/index.parts.js +15 -0
  47. package/dist/composer/internals.d.ts +30 -0
  48. package/dist/composer/internals.js +102 -0
  49. package/dist/composer/keyboard.d.ts +61 -0
  50. package/dist/composer/keyboard.js +75 -0
  51. package/dist/composer/panel.d.ts +28 -0
  52. package/dist/composer/panel.js +76 -0
  53. package/dist/composer/placeholder.d.ts +10 -0
  54. package/dist/composer/placeholder.js +8 -0
  55. package/dist/composer/popover.d.ts +12 -0
  56. package/dist/composer/popover.js +62 -0
  57. package/dist/composer/prefix-detection.d.ts +23 -0
  58. package/dist/composer/prefix-detection.js +67 -0
  59. package/dist/composer/root.d.ts +21 -0
  60. package/dist/composer/root.js +124 -0
  61. package/dist/composer/segments.d.ts +108 -0
  62. package/dist/composer/segments.js +366 -0
  63. package/dist/composer/store.d.ts +98 -0
  64. package/dist/composer/store.js +457 -0
  65. package/dist/composer/textarea.d.ts +39 -0
  66. package/dist/composer/textarea.js +64 -0
  67. package/dist/composer/trigger-tracker.d.ts +12 -0
  68. package/dist/composer/trigger-tracker.js +90 -0
  69. package/dist/composer/types.d.ts +127 -0
  70. package/dist/composer/types.js +4 -0
  71. package/dist/composer/use-composer-editor.d.ts +43 -0
  72. package/dist/composer/use-composer-editor.js +653 -0
  73. package/dist/generative/catalog.d.ts +177 -0
  74. package/dist/generative/catalog.js +20 -0
  75. package/dist/generative/index.d.ts +26 -0
  76. package/dist/generative/index.js +20 -0
  77. package/dist/generative/json-schema.d.ts +45 -0
  78. package/dist/generative/json-schema.js +216 -0
  79. package/dist/generative/markdown.d.ts +21 -0
  80. package/dist/generative/markdown.js +76 -0
  81. package/dist/generative/tree.d.ts +56 -0
  82. package/dist/generative/tree.js +365 -0
  83. package/dist/generative/use-tree.d.ts +12 -0
  84. package/dist/generative/use-tree.js +64 -0
  85. package/dist/internal/change-event-details.d.ts +12 -0
  86. package/dist/internal/change-event-details.js +16 -0
  87. package/dist/internal/collapsible.d.ts +22 -0
  88. package/dist/internal/collapsible.js +94 -0
  89. package/dist/internal/collection.d.ts +32 -0
  90. package/dist/internal/collection.js +72 -0
  91. package/dist/internal/iso-layout-effect.d.ts +2 -0
  92. package/dist/internal/iso-layout-effect.js +6 -0
  93. package/dist/internal/portal.d.ts +6 -0
  94. package/dist/internal/portal.js +18 -0
  95. package/dist/internal/primitive-props.d.ts +4 -0
  96. package/dist/internal/primitive-props.js +3 -0
  97. package/dist/internal/render/baseTypes.d.ts +18 -0
  98. package/dist/internal/render/baseTypes.js +4 -0
  99. package/dist/internal/render/empty.d.ts +3 -0
  100. package/dist/internal/render/empty.js +5 -0
  101. package/dist/internal/render/getReactElementRef.d.ts +5 -0
  102. package/dist/internal/render/getReactElementRef.js +15 -0
  103. package/dist/internal/render/getStateAttributesProps.d.ts +4 -0
  104. package/dist/internal/render/getStateAttributesProps.js +23 -0
  105. package/dist/internal/render/mergeObjects.d.ts +1 -0
  106. package/dist/internal/render/mergeObjects.js +14 -0
  107. package/dist/internal/render/mergeProps.d.ts +55 -0
  108. package/dist/internal/render/mergeProps.js +183 -0
  109. package/dist/internal/render/positioning.d.ts +33 -0
  110. package/dist/internal/render/positioning.js +112 -0
  111. package/dist/internal/render/reactVersion.d.ts +3 -0
  112. package/dist/internal/render/reactVersion.js +7 -0
  113. package/dist/internal/render/resolveClassName.d.ts +8 -0
  114. package/dist/internal/render/resolveClassName.js +12 -0
  115. package/dist/internal/render/resolveStyle.d.ts +8 -0
  116. package/dist/internal/render/resolveStyle.js +12 -0
  117. package/dist/internal/render/transition.d.ts +47 -0
  118. package/dist/internal/render/transition.js +259 -0
  119. package/dist/internal/render/types.d.ts +74 -0
  120. package/dist/internal/render/types.js +3 -0
  121. package/dist/internal/render/useMergedRefs.d.ts +21 -0
  122. package/dist/internal/render/useMergedRefs.js +102 -0
  123. package/dist/internal/render/useRefWithInit.d.ts +10 -0
  124. package/dist/internal/render/useRefWithInit.js +12 -0
  125. package/dist/internal/render/useRender.d.ts +71 -0
  126. package/dist/internal/render/useRender.js +12 -0
  127. package/dist/internal/render/useRenderElement.d.ts +62 -0
  128. package/dist/internal/render/useRenderElement.js +157 -0
  129. package/dist/internal/render/warn.d.ts +1 -0
  130. package/dist/internal/render/warn.js +15 -0
  131. package/dist/internal/safe-polygon.d.ts +21 -0
  132. package/dist/internal/safe-polygon.js +179 -0
  133. package/dist/internal/scroll-into-view-within.d.ts +1 -0
  134. package/dist/internal/scroll-into-view-within.js +26 -0
  135. package/dist/internal/standard-schema.d.ts +38 -0
  136. package/dist/internal/standard-schema.js +4 -0
  137. package/dist/internal/state-mappings.d.ts +8 -0
  138. package/dist/internal/state-mappings.js +17 -0
  139. package/dist/internal/use-controlled.d.ts +19 -0
  140. package/dist/internal/use-controlled.js +33 -0
  141. package/dist/message/index.d.ts +3 -0
  142. package/dist/message/index.js +3 -0
  143. package/dist/message/index.parts.d.ts +1 -0
  144. package/dist/message/index.parts.js +5 -0
  145. package/dist/message/message.d.ts +58 -0
  146. package/dist/message/message.js +93 -0
  147. package/dist/message-utils.d.ts +55 -0
  148. package/dist/message-utils.js +79 -0
  149. package/dist/nav/index.d.ts +4 -0
  150. package/dist/nav/index.js +5 -0
  151. package/dist/nav/index.parts.d.ts +3 -0
  152. package/dist/nav/index.parts.js +7 -0
  153. package/dist/nav/nav.d.ts +152 -0
  154. package/dist/nav/nav.js +660 -0
  155. package/dist/nav/store.d.ts +50 -0
  156. package/dist/nav/store.js +95 -0
  157. package/dist/reasoning/index.d.ts +3 -0
  158. package/dist/reasoning/index.js +3 -0
  159. package/dist/reasoning/index.parts.d.ts +1 -0
  160. package/dist/reasoning/index.parts.js +5 -0
  161. package/dist/reasoning/reasoning.d.ts +38 -0
  162. package/dist/reasoning/reasoning.js +67 -0
  163. package/dist/shell/index.d.ts +5 -0
  164. package/dist/shell/index.js +5 -0
  165. package/dist/shell/index.parts.d.ts +3 -0
  166. package/dist/shell/index.parts.js +7 -0
  167. package/dist/shell/shell.d.ts +108 -0
  168. package/dist/shell/shell.js +390 -0
  169. package/dist/shell/store.d.ts +112 -0
  170. package/dist/shell/store.js +134 -0
  171. package/dist/steps/index.d.ts +2 -0
  172. package/dist/steps/index.js +2 -0
  173. package/dist/steps/index.parts.d.ts +1 -0
  174. package/dist/steps/index.parts.js +5 -0
  175. package/dist/steps/steps.d.ts +90 -0
  176. package/dist/steps/steps.js +116 -0
  177. package/dist/tabs/anchored.d.ts +59 -0
  178. package/dist/tabs/anchored.js +109 -0
  179. package/dist/tabs/hover.d.ts +33 -0
  180. package/dist/tabs/hover.js +169 -0
  181. package/dist/tabs/index.d.ts +5 -0
  182. package/dist/tabs/index.js +4 -0
  183. package/dist/tabs/index.parts.d.ts +4 -0
  184. package/dist/tabs/index.parts.js +8 -0
  185. package/dist/tabs/store.d.ts +131 -0
  186. package/dist/tabs/store.js +248 -0
  187. package/dist/tabs/tabs.d.ts +217 -0
  188. package/dist/tabs/tabs.js +458 -0
  189. package/dist/thread/geometry.d.ts +23 -0
  190. package/dist/thread/geometry.js +48 -0
  191. package/dist/thread/index.d.ts +4 -0
  192. package/dist/thread/index.js +3 -0
  193. package/dist/thread/index.parts.d.ts +1 -0
  194. package/dist/thread/index.parts.js +5 -0
  195. package/dist/thread/stores.d.ts +21 -0
  196. package/dist/thread/stores.js +63 -0
  197. package/dist/thread/thread.d.ts +57 -0
  198. package/dist/thread/thread.js +663 -0
  199. package/dist/types.d.ts +58 -0
  200. package/dist/types.js +17 -0
  201. package/package.json +120 -4
@@ -0,0 +1,8 @@
1
+ /**
2
+ * If the provided style is an object, it will be returned as is.
3
+ * Otherwise, the function will call the style function with the state as the first argument.
4
+ *
5
+ * @param style
6
+ * @param state
7
+ */
8
+ export declare function resolveStyle<State>(style: React.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined, state: State): import("react").CSSProperties | undefined;
@@ -0,0 +1,12 @@
1
+ // Vendored from @base-ui/react v1.6.0 (MIT) — packages/react/src/utils/resolveStyle.ts
2
+ // https://github.com/mui/base-ui — exact copy.
3
+ /**
4
+ * If the provided style is an object, it will be returned as is.
5
+ * Otherwise, the function will call the style function with the state as the first argument.
6
+ *
7
+ * @param style
8
+ * @param state
9
+ */
10
+ export function resolveStyle(style, state) {
11
+ return typeof style === 'function' ? style(state) : style;
12
+ }
@@ -0,0 +1,47 @@
1
+ import { type RefObject } from "react";
2
+ export type TransitionStatus = "starting" | "ending" | "idle" | undefined;
3
+ /**
4
+ * A status string for CSS open/close animations.
5
+ * @param open - whether the element is open.
6
+ * @param enableIdleState - enables the `'idle'` state between `'starting'` and settled.
7
+ * @param deferEndingState - defer the `'ending'` state by a frame (avoids a same-commit flip).
8
+ */
9
+ export declare const useTransitionStatus: (open: boolean, enableIdleState?: boolean, deferEndingState?: boolean) => {
10
+ mounted: boolean;
11
+ setMounted: import("react").Dispatch<import("react").SetStateAction<boolean>>;
12
+ transitionStatus: TransitionStatus;
13
+ };
14
+ /**
15
+ * Returns a function that runs `fn` once all animations on the element finish (or immediately
16
+ * if none / unsupported). Flushes synchronously so the browser can't paint a settled frame
17
+ * before the component unmounts (mui/base-ui#979).
18
+ */
19
+ export declare const useAnimationsFinished: (elementOrRef: RefObject<HTMLElement | null> | HTMLElement | null, waitForStartingStyleRemoved?: boolean, treatAbortedAsFinished?: boolean,
20
+ /**
21
+ * Wait on descendants too — for when the element that animates is not the one being
22
+ * unmounted, such as a collapsible whose wrapper carries the transition.
23
+ */
24
+ subtree?: boolean) => (fnToExecute: () => void, signal?: AbortSignal | null | undefined) => void | undefined;
25
+ export type UseOpenChangeCompleteParameters = {
26
+ /** Whether the hook is enabled. @default true */
27
+ enabled?: boolean;
28
+ /** Whether the element is open. */
29
+ open?: boolean;
30
+ /** Ref to the animating element. */
31
+ ref: RefObject<HTMLElement | null>;
32
+ /** Called once the open/close animation completes (or there is no animation). */
33
+ onComplete: () => void;
34
+ };
35
+ /** Calls `onComplete` when the CSS open/close animation or transition completes. */
36
+ export declare const useOpenChangeComplete: ({ enabled, open, ref, onComplete: onCompleteParam, }: UseOpenChangeCompleteParameters) => void;
37
+ export type UseOpenTransitionOptions = {
38
+ /** Measure the element's natural height into `height` (for a height-collapse CSS var). */
39
+ measureHeight?: boolean;
40
+ /** Called when the close animation completes, alongside the internal unmount. */
41
+ onClosed?: () => void;
42
+ };
43
+ export declare const useOpenTransition: (open: boolean, ref: RefObject<HTMLElement | null>, { measureHeight, onClosed }?: UseOpenTransitionOptions) => {
44
+ mounted: boolean;
45
+ transitionStatus: TransitionStatus;
46
+ height: number | null;
47
+ };
@@ -0,0 +1,259 @@
1
+ "use client";
2
+ // Adapted from @base-ui/react master (MIT) — the open/close transition lifecycle hooks
3
+ // (internals/useTransitionStatus, useAnimationsFinished, useOpenChangeComplete). Consolidated
4
+ // into one self-contained module and trimmed of the @base-ui/utils runtime dep (the tiny
5
+ // AnimationFrame / useStableCallback / resolveRef helpers are inlined), mirroring how this
6
+ // package already vendors useRenderElement. Behavior is preserved bar two deliberate
7
+ // departures in useAnimationsFinished: a `subtree` option (the animating element is not always
8
+ // the one unmounting), and running the callback when there is no element instead of returning
9
+ // silently, which otherwise strands whoever unmounts from it.
10
+ //
11
+ // Model: presence is the `mounted` boolean; `transitionStatus` is a CSS-animation status
12
+ // ('starting' | 'ending' | 'idle' | undefined). Pair with data-starting-style/data-ending-style
13
+ // (see state-mappings.ts) and drive unmount off `mounted`, cleared once animations finish.
14
+ import { useEffect, useInsertionEffect, useLayoutEffect, useRef, useState, } from "react";
15
+ import { flushSync } from "react-dom";
16
+ import { useRefWithInit } from "./useRefWithInit.js";
17
+ const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
18
+ // ---------------------------------------------------------------------------
19
+ // Small helpers (inlined from @base-ui/utils)
20
+ // ---------------------------------------------------------------------------
21
+ // Stable callback: identity-stable trampoline over the latest callback. Must only be called
22
+ // from effects/handlers, never during render.
23
+ const useStableCallback = (callback) => {
24
+ const latest = useRef(callback);
25
+ useInsertionEffect(() => {
26
+ latest.current = callback;
27
+ });
28
+ return useRefWithInit(() => (...args) => latest.current?.(...args)).current;
29
+ };
30
+ const resolveRef = (elementOrRef) => elementOrRef && "current" in elementOrRef ? elementOrRef.current : elementOrRef;
31
+ // requestAnimationFrame handle with auto-cancel on unmount and single-in-flight semantics.
32
+ class AnimationFrameHandle {
33
+ id = null;
34
+ request(fn) {
35
+ this.cancel();
36
+ this.id = requestAnimationFrame(() => {
37
+ this.id = null;
38
+ fn();
39
+ });
40
+ }
41
+ cancel = () => {
42
+ if (this.id !== null) {
43
+ cancelAnimationFrame(this.id);
44
+ this.id = null;
45
+ }
46
+ };
47
+ }
48
+ const useAnimationFrame = () => {
49
+ const handle = useRefWithInit(() => new AnimationFrameHandle()).current;
50
+ useEffect(() => handle.cancel, [handle]);
51
+ return handle;
52
+ };
53
+ /**
54
+ * A status string for CSS open/close animations.
55
+ * @param open - whether the element is open.
56
+ * @param enableIdleState - enables the `'idle'` state between `'starting'` and settled.
57
+ * @param deferEndingState - defer the `'ending'` state by a frame (avoids a same-commit flip).
58
+ */
59
+ export const useTransitionStatus = (open, enableIdleState = false, deferEndingState = false) => {
60
+ const [transitionStatus, setTransitionStatus] = useState(open && enableIdleState ? "idle" : undefined);
61
+ const [mounted, setMounted] = useState(open);
62
+ if (open && !mounted) {
63
+ setMounted(true);
64
+ setTransitionStatus("starting");
65
+ }
66
+ if (!open && mounted && transitionStatus !== "ending" && !deferEndingState) {
67
+ setTransitionStatus("ending");
68
+ }
69
+ if (!open && !mounted && transitionStatus === "ending") {
70
+ setTransitionStatus(undefined);
71
+ }
72
+ useIsoLayoutEffect(() => {
73
+ if (!open && mounted && transitionStatus !== "ending" && deferEndingState) {
74
+ const frame = requestAnimationFrame(() => setTransitionStatus("ending"));
75
+ return () => cancelAnimationFrame(frame);
76
+ }
77
+ return undefined;
78
+ }, [open, mounted, transitionStatus, deferEndingState]);
79
+ useIsoLayoutEffect(() => {
80
+ if (!open || enableIdleState)
81
+ return undefined;
82
+ // Avoid flushSync here (Firefox). See mui/base-ui#3424.
83
+ const frame = requestAnimationFrame(() => setTransitionStatus(undefined));
84
+ return () => cancelAnimationFrame(frame);
85
+ }, [enableIdleState, open]);
86
+ useIsoLayoutEffect(() => {
87
+ if (!open || !enableIdleState)
88
+ return undefined;
89
+ if (open && mounted && transitionStatus !== "idle") {
90
+ setTransitionStatus("starting");
91
+ }
92
+ const frame = requestAnimationFrame(() => setTransitionStatus("idle"));
93
+ return () => cancelAnimationFrame(frame);
94
+ }, [enableIdleState, open, mounted, transitionStatus]);
95
+ return { mounted, setMounted, transitionStatus };
96
+ };
97
+ // ---------------------------------------------------------------------------
98
+ // useAnimationsFinished
99
+ // ---------------------------------------------------------------------------
100
+ /**
101
+ * Returns a function that runs `fn` once all animations on the element finish (or immediately
102
+ * if none / unsupported). Flushes synchronously so the browser can't paint a settled frame
103
+ * before the component unmounts (mui/base-ui#979).
104
+ */
105
+ export const useAnimationsFinished = (elementOrRef, waitForStartingStyleRemoved = false, treatAbortedAsFinished = true,
106
+ /**
107
+ * Wait on descendants too — for when the element that animates is not the one being
108
+ * unmounted, such as a collapsible whose wrapper carries the transition.
109
+ */
110
+ subtree = false) => {
111
+ const frame = useAnimationFrame();
112
+ return useStableCallback((fnToExecute, signal = null) => {
113
+ frame.cancel();
114
+ const element = resolveRef(elementOrRef);
115
+ // No element means there is nothing to wait for. Run the callback rather than returning,
116
+ // or a caller that unmounts from it (setMounted(false)) is stranded and the surface stays
117
+ // mounted for good.
118
+ if (element == null) {
119
+ fnToExecute();
120
+ return;
121
+ }
122
+ const resolvedElement = element;
123
+ const done = () => flushSync(fnToExecute);
124
+ if (typeof resolvedElement.getAnimations !== "function") {
125
+ fnToExecute();
126
+ return;
127
+ }
128
+ const exec = () => {
129
+ Promise.all(resolvedElement.getAnimations({ subtree }).map((animation) => animation.finished))
130
+ .then(() => {
131
+ if (!signal?.aborted)
132
+ done();
133
+ })
134
+ .catch(() => {
135
+ if (treatAbortedAsFinished) {
136
+ if (!signal?.aborted)
137
+ done();
138
+ return;
139
+ }
140
+ const current = resolvedElement.getAnimations({ subtree });
141
+ if (!signal?.aborted &&
142
+ current.length > 0 &&
143
+ current.some((animation) => animation.pending || animation.playState !== "finished")) {
144
+ // A dependency changed mid-animation and aborted it; re-check for new animations.
145
+ exec();
146
+ }
147
+ });
148
+ };
149
+ if (waitForStartingStyleRemoved) {
150
+ const startingStyleAttribute = "data-starting-style";
151
+ // Not present yet → wait a frame so "open" animations can register.
152
+ if (!resolvedElement.hasAttribute(startingStyleAttribute)) {
153
+ frame.request(exec);
154
+ return;
155
+ }
156
+ // Wait for [data-starting-style] to be removed, then check.
157
+ const observer = new MutationObserver(() => {
158
+ if (!resolvedElement.hasAttribute(startingStyleAttribute)) {
159
+ observer.disconnect();
160
+ exec();
161
+ }
162
+ });
163
+ observer.observe(resolvedElement, {
164
+ attributes: true,
165
+ attributeFilter: [startingStyleAttribute],
166
+ });
167
+ signal?.addEventListener("abort", () => observer.disconnect(), { once: true });
168
+ return;
169
+ }
170
+ frame.request(exec);
171
+ });
172
+ };
173
+ /** Calls `onComplete` when the CSS open/close animation or transition completes. */
174
+ export const useOpenChangeComplete = ({ enabled = true, open, ref, onComplete: onCompleteParam, }) => {
175
+ const onComplete = useStableCallback(onCompleteParam);
176
+ const runOnceAnimationsFinish = useAnimationsFinished(ref, open, false);
177
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `open` isn't read in the body but re-arms the finalize when it flips — runOnceAnimationsFinish is identity-stable, so without it the effect wouldn't re-run on open/close (matches Base UI).
178
+ useEffect(() => {
179
+ if (!enabled)
180
+ return undefined;
181
+ const abortController = new AbortController();
182
+ runOnceAnimationsFinish(onComplete, abortController.signal);
183
+ return () => abortController.abort();
184
+ }, [enabled, open, onComplete, runOnceAnimationsFinish]);
185
+ };
186
+ /**
187
+ * Drives a Base UI-style open/close for an element: keeps it `mounted` through the exit,
188
+ * reports `transitionStatus` (feed it to a stateAttributesMapping for data-open/closed/
189
+ * starting-style/ending-style), optionally measures its natural `height`, and unmounts once
190
+ * `element.getAnimations()` resolve. Composes useTransitionStatus + useOpenChangeComplete.
191
+ */
192
+ // Inline alignment can distort a scroll-based measurement, so it is neutralized for the read
193
+ // and restored immediately after (Base UI does the same before measuring a collapsible).
194
+ const ALIGNMENT_PROPERTIES = ["justify-content", "align-items", "align-content", "justify-items"];
195
+ const measureNaturalHeight = (element) => {
196
+ const saved = ALIGNMENT_PROPERTIES.map((property) => [
197
+ property,
198
+ element.style.getPropertyValue(property),
199
+ element.style.getPropertyPriority(property),
200
+ ]);
201
+ for (const [property] of saved) {
202
+ element.style.setProperty(property, "initial", "important");
203
+ }
204
+ const naturalHeight = element.scrollHeight;
205
+ for (const [property, value, priority] of saved) {
206
+ if (value)
207
+ element.style.setProperty(property, value, priority);
208
+ else
209
+ element.style.removeProperty(property);
210
+ }
211
+ return naturalHeight;
212
+ };
213
+ export const useOpenTransition = (open, ref, { measureHeight = false, onClosed } = {}) => {
214
+ // Both flags on: `idle` is the settled-open status the height release gates on, and
215
+ // deferring `ending` by a frame leaves one frame where a closing panel is still at its
216
+ // open size — which is where the close has to be measured.
217
+ const { mounted, setMounted, transitionStatus } = useTransitionStatus(open, true, true);
218
+ const [height, setHeight] = useState(null);
219
+ useIsoLayoutEffect(() => {
220
+ if (!measureHeight)
221
+ return;
222
+ const element = ref.current;
223
+ if (!element)
224
+ return;
225
+ // Closing: measure on the deferred frame. By the `ending` frame the consumer's closed
226
+ // styles have landed, so we would measure the clamped box instead of the natural one.
227
+ if (!open && mounted && (transitionStatus === "idle" || transitionStatus === "starting")) {
228
+ setHeight(measureNaturalHeight(element));
229
+ return;
230
+ }
231
+ // Opening: measure on the first frame, before the transition runs.
232
+ if (open && transitionStatus === "starting") {
233
+ setHeight(measureNaturalHeight(element));
234
+ }
235
+ }, [measureHeight, open, mounted, transitionStatus, ref]);
236
+ // Release the measurement once the open transition settles, so the panel tracks content
237
+ // that grows while it is open. With `height` null the custom property is never written, so
238
+ // a consumer's `height: var(--…)` is invalid at computed-value time and falls back to
239
+ // `auto`. The close re-measures a pixel value first, so it still animates from a number.
240
+ useOpenChangeComplete({
241
+ open: true,
242
+ ref,
243
+ enabled: measureHeight && open && mounted && transitionStatus === "idle",
244
+ onComplete: () => setHeight(null),
245
+ });
246
+ useOpenChangeComplete({
247
+ open,
248
+ ref,
249
+ // Gated on `ending`, not merely `!open`: with the ending state deferred by a frame, an
250
+ // earlier check would call getAnimations() before the closed styles applied, find
251
+ // nothing running, and cut the exit off.
252
+ enabled: !open && mounted && transitionStatus === "ending",
253
+ onComplete: () => {
254
+ setMounted(false);
255
+ onClosed?.();
256
+ },
257
+ });
258
+ return { mounted, transitionStatus, height };
259
+ };
@@ -0,0 +1,74 @@
1
+ import type * as React from 'react';
2
+ import type { PreventableEvent, ComponentRenderFn, HTMLProps } from './baseTypes.js';
3
+ export type { HTMLProps, PreventableEvent, ComponentRenderFn };
4
+ export type MaybePreventableEvent<E extends React.SyntheticEvent<Element, Event>> = E & Partial<Pick<PreventableEvent<E>, 'preventPrimitiveHandler' | 'primitiveHandlerPrevented'>>;
5
+ export interface FloatingUIOpenChangeDetails {
6
+ open: boolean;
7
+ reason: string;
8
+ nativeEvent: Event;
9
+ nested: boolean;
10
+ triggerElement?: Element | undefined;
11
+ }
12
+ type WithPreventableHandler<T> = T extends (event: infer E) => any ? E extends React.SyntheticEvent<Element, Event> ? (event: PreventableEvent<E>) => ReturnType<T> : T : T extends undefined ? undefined : T;
13
+ /**
14
+ * Adds a `preventPrimitiveHandler` method to all event handlers.
15
+ */
16
+ export type WithPreventableEvents<T> = {
17
+ [K in keyof T]: WithPreventableHandler<T[K]>;
18
+ };
19
+ /**
20
+ * Props shared by all primitive parts.
21
+ * Contains `className` (string or callback taking the component's state as an argument) and `render` (function to customize rendering).
22
+ */
23
+ export type RenderComponentProps<ElementType extends React.ElementType, State, RenderFunctionProps = HTMLProps> = Omit<WithPreventableEvents<React.ComponentPropsWithRef<ElementType>>, 'className' | 'color' | 'defaultValue' | 'defaultChecked' | 'style'> & {
24
+ /**
25
+ * CSS class applied to the element, or a function that
26
+ * returns a class based on the component's state.
27
+ */
28
+ className?: string | ((state: State) => string | undefined) | undefined;
29
+ /**
30
+ * Allows you to replace the component's HTML element
31
+ * with a different tag, or compose it with another component.
32
+ *
33
+ * Accepts a `ReactElement` or a function that returns the element to render.
34
+ */
35
+ render?: React.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined;
36
+ /**
37
+ * Style applied to the element, or a function that
38
+ * returns a style object based on the component's state.
39
+ */
40
+ style?: React.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined;
41
+ };
42
+ export interface NativeButtonProps {
43
+ /**
44
+ * Whether the component renders a native `<button>` element when replacing it
45
+ * via the `render` prop.
46
+ * Set to `false` if the rendered element is not a button (for example, `<div>`).
47
+ * @default true
48
+ */
49
+ nativeButton?: boolean | undefined;
50
+ }
51
+ export interface NonNativeButtonProps {
52
+ /**
53
+ * Whether the component renders a native `<button>` element when replacing it
54
+ * via the `render` prop.
55
+ * Set to `true` if the rendered element is a native button.
56
+ * @default false
57
+ */
58
+ nativeButton?: boolean | undefined;
59
+ }
60
+ /**
61
+ * Simplifies the display of a type (without modifying it).
62
+ * Taken from https://effectivetypescript.com/2022/02/25/gentips-4-display/
63
+ */
64
+ export type Simplify<T> = T extends Function ? T : {
65
+ [K in keyof T]: T[K];
66
+ };
67
+ /**
68
+ * Makes specified keys in a type required.
69
+ *
70
+ * @template T - The original type.
71
+ * @template K - The keys to make required.
72
+ */
73
+ export type RequiredExcept<T, K extends keyof T> = Required<Omit<T, K>> & Pick<T, K>;
74
+ export type Orientation = 'horizontal' | 'vertical';
@@ -0,0 +1,3 @@
1
+ // Vendored from @base-ui/react v1.6.0 (MIT) — packages/react/src/internals/types.ts
2
+ // https://github.com/mui/base-ui — import specifiers rewired and names made neutral; otherwise an exact copy.
3
+ export {};
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ type Empty = null | undefined;
3
+ type InputRef<I> = React.Ref<I> | Empty;
4
+ type Result<I> = React.RefCallback<I> | null;
5
+ /**
6
+ * Merges refs into a single memoized callback ref or `null`.
7
+ * This makes sure multiple refs are updated together and have the same value.
8
+ *
9
+ * This function accepts up to four refs. If you need to merge more, or have an unspecified number of refs to merge,
10
+ * use `useMergedRefsN` instead.
11
+ */
12
+ export declare function useMergedRefs<I>(a: InputRef<I>, b: InputRef<I>): Result<I>;
13
+ export declare function useMergedRefs<I>(a: InputRef<I>, b: InputRef<I>, c: InputRef<I>): Result<I>;
14
+ export declare function useMergedRefs<I>(a: InputRef<I>, b: InputRef<I>, c: InputRef<I>, d: InputRef<I>): Result<I>;
15
+ /**
16
+ * Merges an array of refs into a single memoized callback ref or `null`.
17
+ *
18
+ * If you need to merge a fixed number (up to four) of refs, use `useMergedRefs` instead for better performance.
19
+ */
20
+ export declare function useMergedRefsN<I>(refs: InputRef<I>[]): Result<I>;
21
+ export {};
@@ -0,0 +1,102 @@
1
+ // Vendored from @base-ui/utils v1.6.0 (MIT) — packages/utils/src/useMergedRefs.ts
2
+ // https://github.com/mui/base-ui — exact copy.
3
+ import * as React from 'react';
4
+ import { useRefWithInit } from './useRefWithInit.js';
5
+ export function useMergedRefs(a, b, c, d) {
6
+ const forkRef = useRefWithInit((createForkRef)).current;
7
+ if (didChange(forkRef, a, b, c, d)) {
8
+ update(forkRef, [a, b, c, d]);
9
+ }
10
+ return forkRef.callback;
11
+ }
12
+ /**
13
+ * Merges an array of refs into a single memoized callback ref or `null`.
14
+ *
15
+ * If you need to merge a fixed number (up to four) of refs, use `useMergedRefs` instead for better performance.
16
+ */
17
+ export function useMergedRefsN(refs) {
18
+ const forkRef = useRefWithInit((createForkRef)).current;
19
+ if (didChangeN(forkRef, refs)) {
20
+ update(forkRef, refs);
21
+ }
22
+ return forkRef.callback;
23
+ }
24
+ function createForkRef() {
25
+ return {
26
+ callback: null,
27
+ cleanup: null,
28
+ refs: [],
29
+ };
30
+ }
31
+ function didChange(forkRef, a, b, c, d) {
32
+ // prettier-ignore
33
+ return (forkRef.refs[0] !== a ||
34
+ forkRef.refs[1] !== b ||
35
+ forkRef.refs[2] !== c ||
36
+ forkRef.refs[3] !== d);
37
+ }
38
+ function didChangeN(forkRef, newRefs) {
39
+ return (forkRef.refs.length !== newRefs.length ||
40
+ forkRef.refs.some((ref, index) => ref !== newRefs[index]));
41
+ }
42
+ function update(forkRef, refs) {
43
+ forkRef.refs = refs;
44
+ if (refs.every((ref) => ref == null)) {
45
+ forkRef.callback = null;
46
+ return;
47
+ }
48
+ forkRef.callback = (instance) => {
49
+ if (forkRef.cleanup) {
50
+ forkRef.cleanup();
51
+ forkRef.cleanup = null;
52
+ }
53
+ if (instance != null) {
54
+ const cleanupCallbacks = Array(refs.length).fill(null);
55
+ for (let i = 0; i < refs.length; i += 1) {
56
+ const ref = refs[i];
57
+ if (ref == null) {
58
+ continue;
59
+ }
60
+ switch (typeof ref) {
61
+ case 'function': {
62
+ const refCleanup = ref(instance);
63
+ if (typeof refCleanup === 'function') {
64
+ cleanupCallbacks[i] = refCleanup;
65
+ }
66
+ break;
67
+ }
68
+ case 'object': {
69
+ ref.current = instance;
70
+ break;
71
+ }
72
+ default:
73
+ }
74
+ }
75
+ forkRef.cleanup = () => {
76
+ for (let i = 0; i < refs.length; i += 1) {
77
+ const ref = refs[i];
78
+ if (ref == null) {
79
+ continue;
80
+ }
81
+ switch (typeof ref) {
82
+ case 'function': {
83
+ const cleanupCallback = cleanupCallbacks[i];
84
+ if (typeof cleanupCallback === 'function') {
85
+ cleanupCallback();
86
+ }
87
+ else {
88
+ ref(null);
89
+ }
90
+ break;
91
+ }
92
+ case 'object': {
93
+ ref.current = null;
94
+ break;
95
+ }
96
+ default:
97
+ }
98
+ }
99
+ };
100
+ }
101
+ };
102
+ }
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * A React.useRef() that is initialized with a function. Note that it accepts an optional
4
+ * initialization argument, so the initialization function doesn't need to be an inline closure.
5
+ *
6
+ * @usage
7
+ * const ref = useRefWithInit(sortColumns, columns)
8
+ */
9
+ export declare function useRefWithInit<T>(init: () => T): React.RefObject<T>;
10
+ export declare function useRefWithInit<T, U>(init: (arg: U) => T, initArg: U): React.RefObject<T>;
@@ -0,0 +1,12 @@
1
+ // Vendored from @base-ui/utils v1.6.0 (MIT) — packages/utils/src/useRefWithInit.ts
2
+ // https://github.com/mui/base-ui — exact copy.
3
+ 'use client';
4
+ import * as React from 'react';
5
+ const UNINITIALIZED = {};
6
+ export function useRefWithInit(init, initArg) {
7
+ const ref = React.useRef(UNINITIALIZED);
8
+ if (ref.current === UNINITIALIZED) {
9
+ ref.current = init(initArg);
10
+ }
11
+ return ref;
12
+ }
@@ -0,0 +1,71 @@
1
+ import * as React from 'react';
2
+ import type { ComponentRenderFn } from './types.js';
3
+ import type { HTMLProps } from './types.js';
4
+ import type { StateAttributesMapping } from './getStateAttributesProps.js';
5
+ /**
6
+ * Renders a primitive part's element.
7
+ *
8
+ * @public
9
+ */
10
+ export declare function useRender<State extends Record<string, unknown>, RenderedElementType extends Element, Enabled extends boolean | undefined = undefined>(params: useRender.Parameters<State, RenderedElementType, Enabled>): useRender.ReturnValue<Enabled>;
11
+ export type UseRenderRenderProp<State = Record<string, unknown>> = React.ReactElement | ComponentRenderFn<React.HTMLAttributes<any>, State>;
12
+ export type UseRenderElementProps<ElementType extends React.ElementType> = React.ComponentPropsWithRef<ElementType>;
13
+ export type UseRenderComponentProps<ElementType extends React.ElementType, State = {}, RenderFunctionProps = HTMLProps> = React.ComponentPropsWithRef<ElementType> & {
14
+ /**
15
+ * Allows you to replace the component's HTML element
16
+ * with a different tag, or compose it with another component.
17
+ *
18
+ * Accepts a `ReactElement` or a function that returns the element to render.
19
+ */
20
+ render?: React.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined;
21
+ };
22
+ export interface UseRenderParameters<State, RenderedElementType extends Element, Enabled extends boolean | undefined> {
23
+ /**
24
+ * The React element or a function that returns one to override the default element.
25
+ */
26
+ render?: UseRenderRenderProp<State> | undefined;
27
+ /**
28
+ * The ref to apply to the rendered element.
29
+ */
30
+ ref?: React.Ref<RenderedElementType> | React.Ref<RenderedElementType>[] | undefined;
31
+ /**
32
+ * The state of the component, passed as the second argument to the `render` callback.
33
+ * State properties are automatically converted to data-* attributes.
34
+ */
35
+ state?: State | undefined;
36
+ /**
37
+ * Custom mapping for converting state properties to data-* attributes.
38
+ * @example
39
+ * { isActive: (value) => (value ? { 'data-is-active': '' } : null) }
40
+ */
41
+ stateAttributesMapping?: StateAttributesMapping<State> | undefined;
42
+ /**
43
+ * Props to be spread on the rendered element.
44
+ * They are merged with the internal props of the component, so that event handlers
45
+ * are merged, `className` strings and `style` properties are joined, while other external props overwrite the
46
+ * internal ones.
47
+ */
48
+ props?: Record<string, unknown> | undefined;
49
+ /**
50
+ * If `false`, the hook will skip most of its internal logic and return `null`.
51
+ * This is useful for rendering a component conditionally.
52
+ * @default true
53
+ */
54
+ enabled?: Enabled | undefined;
55
+ /**
56
+ * The default tag name to use for the rendered element when `render` is not provided.
57
+ * @default 'div'
58
+ */
59
+ defaultTagName?: keyof React.JSX.IntrinsicElements | undefined;
60
+ }
61
+ export type UseRenderReturnValue<Enabled extends boolean | undefined> = Enabled extends false ? null : React.ReactElement;
62
+ export interface UseRenderState {
63
+ }
64
+ export declare namespace useRender {
65
+ type State = UseRenderState;
66
+ type RenderProp<TState = Record<string, unknown>> = UseRenderRenderProp<TState>;
67
+ type ElementProps<ElementType extends React.ElementType> = UseRenderElementProps<ElementType>;
68
+ type ComponentProps<ElementType extends React.ElementType, TState = {}, RenderFunctionProps = HTMLProps> = UseRenderComponentProps<ElementType, TState, RenderFunctionProps>;
69
+ type Parameters<TState, RenderedElementType extends Element, Enabled extends boolean | undefined> = UseRenderParameters<TState, RenderedElementType, Enabled>;
70
+ type ReturnValue<Enabled extends boolean | undefined> = UseRenderReturnValue<Enabled>;
71
+ }
@@ -0,0 +1,12 @@
1
+ // Vendored from @base-ui/react v1.6.0 (MIT) — packages/react/src/use-render/useRender.ts
2
+ // https://github.com/mui/base-ui — import specifiers rewired and comments made neutral; otherwise an exact copy.
3
+ import * as React from 'react';
4
+ import { useRenderElement } from './useRenderElement.js';
5
+ /**
6
+ * Renders a primitive part's element.
7
+ *
8
+ * @public
9
+ */
10
+ export function useRender(params) {
11
+ return useRenderElement(params.defaultTagName ?? 'div', params, params);
12
+ }