@semos-labs/glyph 0.1.81 → 0.1.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -185,6 +185,50 @@ interface AppHandle {
185
185
  exit(code?: number): void;
186
186
  }
187
187
 
188
+ type GlyphNodeType = "box" | "text" | "input";
189
+ type GlyphChild = GlyphNode | GlyphTextInstance;
190
+ interface GlyphNode {
191
+ type: GlyphNodeType;
192
+ props: Record<string, any>;
193
+ style: Style;
194
+ children: GlyphNode[];
195
+ rawTextChildren: GlyphTextInstance[];
196
+ /** All children in order (both nodes and raw text) for correct text composition */
197
+ allChildren: GlyphChild[];
198
+ parent: GlyphNode | null;
199
+ yogaNode: Node | null;
200
+ text: string | null;
201
+ layout: LayoutRect;
202
+ focusId: string | null;
203
+ hidden: boolean;
204
+ }
205
+ interface GlyphTextInstance {
206
+ type: "raw-text";
207
+ text: string;
208
+ parent: GlyphNode | null;
209
+ }
210
+
211
+ /**
212
+ * Options for {@link ScrollViewContextValue.scrollTo} and
213
+ * {@link FocusableHandle.scrollIntoView}.
214
+ *
215
+ * @example
216
+ * ```tsx
217
+ * ref.current?.scrollIntoView({ block: "center" });
218
+ * ```
219
+ * @category Types
220
+ */
221
+ interface ScrollIntoViewOptions {
222
+ /**
223
+ * Where to align the element relative to the viewport.
224
+ * - `"nearest"` — minimal scroll to make visible (default)
225
+ * - `"start"` — align element top with viewport top
226
+ * - `"center"` — center element in viewport
227
+ * - `"end"` — align element bottom with viewport bottom
228
+ */
229
+ block?: "start" | "center" | "end" | "nearest";
230
+ }
231
+
188
232
  /**
189
233
  * DOM-like imperative handles for focusable components.
190
234
  * Use these with React refs to programmatically control components.
@@ -213,6 +257,25 @@ interface FocusableHandle {
213
257
  blur(): void;
214
258
  /** Whether this element is currently focused */
215
259
  readonly isFocused: boolean;
260
+ /**
261
+ * Scroll the nearest parent {@link ScrollView} to make this element visible.
262
+ * Behaves like the DOM `Element.scrollIntoView()` method.
263
+ * No-op if the element is not inside a ScrollView.
264
+ *
265
+ * @param options - Alignment options (default: `{ block: "nearest" }`)
266
+ *
267
+ * @example
268
+ * ```tsx
269
+ * const inputRef = useRef<InputHandle>(null);
270
+ *
271
+ * // Minimal scroll — just enough to make it visible
272
+ * inputRef.current?.scrollIntoView();
273
+ *
274
+ * // Center the element in the viewport
275
+ * inputRef.current?.scrollIntoView({ block: "center" });
276
+ * ```
277
+ */
278
+ scrollIntoView(options?: ScrollIntoViewOptions): void;
216
279
  }
217
280
  /** Handle for Button */
218
281
  interface ButtonHandle extends FocusableHandle {
@@ -280,29 +343,6 @@ interface TextHandle extends FocusableHandle {
280
343
  */
281
344
  declare function render(element: ReactElement, opts?: RenderOptions): AppHandle;
282
345
 
283
- type GlyphNodeType = "box" | "text" | "input";
284
- type GlyphChild = GlyphNode | GlyphTextInstance;
285
- interface GlyphNode {
286
- type: GlyphNodeType;
287
- props: Record<string, any>;
288
- style: Style;
289
- children: GlyphNode[];
290
- rawTextChildren: GlyphTextInstance[];
291
- /** All children in order (both nodes and raw text) for correct text composition */
292
- allChildren: GlyphChild[];
293
- parent: GlyphNode | null;
294
- yogaNode: Node | null;
295
- text: string | null;
296
- layout: LayoutRect;
297
- focusId: string | null;
298
- hidden: boolean;
299
- }
300
- interface GlyphTextInstance {
301
- type: "raw-text";
302
- text: string;
303
- parent: GlyphNode | null;
304
- }
305
-
306
346
  /**
307
347
  * Props for the {@link Box} component.
308
348
  */
@@ -1636,6 +1676,31 @@ interface FocusRegistryValue {
1636
1676
  */
1637
1677
  declare function useFocusRegistry(): FocusRegistryValue | null;
1638
1678
 
1679
+ /**
1680
+ * Returns a function that scrolls the nearest parent {@link ScrollView}
1681
+ * to make the referenced node visible.
1682
+ *
1683
+ * This is the non-focusable counterpart to `handle.scrollIntoView()` —
1684
+ * use it with plain `Box` refs or any `GlyphNode`.
1685
+ *
1686
+ * @param nodeRef - React ref pointing to the target node.
1687
+ * @returns A stable callback you can invoke to scroll to the node.
1688
+ *
1689
+ * @example
1690
+ * ```tsx
1691
+ * const boxRef = useRef<GlyphNode>(null);
1692
+ * const scrollIntoView = useScrollIntoView(boxRef);
1693
+ *
1694
+ * // Later, e.g. in an effect or event handler:
1695
+ * scrollIntoView(); // minimal scroll
1696
+ * scrollIntoView({ block: "center" }); // center in viewport
1697
+ * ```
1698
+ * @category Hooks
1699
+ */
1700
+ declare function useScrollIntoView(nodeRef: {
1701
+ current: GlyphNode | null;
1702
+ }): (options?: ScrollIntoViewOptions) => void;
1703
+
1639
1704
  /**
1640
1705
  * Input mask utilities for Glyph Input component.
1641
1706
  *
@@ -1769,4 +1834,4 @@ declare function detectTerminalCapabilities(debug?: boolean): TerminalCapabiliti
1769
1834
  */
1770
1835
  declare function supportsInlineImages(): boolean;
1771
1836
 
1772
- export { type AlertOptions, type AnsiStyle, type AppHandle, type BorderStyle, Box, type BoxProps, Button, type ButtonHandle, type ButtonProps, Checkbox, type CheckboxHandle, type CheckboxProps, type Color, type ConfirmOptions, type DialogContextValue, DialogHost, type DialogHostProps, type DimensionValue, type FocusRegistryValue, FocusScope, type FocusScopeProps, type FocusableElement, type FocusableHandle, type HexColor, Image, type ImageHandle, type ImageProps, type ImageState, Input, type InputHandle, type InputProps, type InputType, JumpNav, type JumpNavProps, type Key, Keybind, type KeybindProps, type LayoutRect, List, type ListHandle, type ListItemInfo, type ListProps, type MaskOptions, Menu, type MenuItem, type MenuProps, type NamedColor, Portal, type PortalProps, Progress, type ProgressProps, type RGBColor, Radio, type RadioHandle, type RadioItem, type RadioProps, type RenderOptions, ScrollView, type ScrollViewProps, Select, type SelectHandle, type SelectItem, type SelectProps, Spacer, type SpacerProps, Spinner, type SpinnerProps, type Style, type StyledSegment, type TerminalCapabilities, Text, type TextAlign, type TextHandle, type TextProps, type Toast, ToastHost, type ToastHostProps, type ToastPosition, type ToastVariant, type UseFocusableOptions, type UseFocusableResult, type VisibleRange, type WrapMode, createMask, detectTerminalCapabilities, masks, parseAnsi, render, stripAnsi, supportsInlineImages, useApp, useDialog, useFocus, useFocusRegistry, useFocusable, useInput, useLayout, useToast };
1837
+ export { type AlertOptions, type AnsiStyle, type AppHandle, type BorderStyle, Box, type BoxProps, Button, type ButtonHandle, type ButtonProps, Checkbox, type CheckboxHandle, type CheckboxProps, type Color, type ConfirmOptions, type DialogContextValue, DialogHost, type DialogHostProps, type DimensionValue, type FocusRegistryValue, FocusScope, type FocusScopeProps, type FocusableElement, type FocusableHandle, type HexColor, Image, type ImageHandle, type ImageProps, type ImageState, Input, type InputHandle, type InputProps, type InputType, JumpNav, type JumpNavProps, type Key, Keybind, type KeybindProps, type LayoutRect, List, type ListHandle, type ListItemInfo, type ListProps, type MaskOptions, Menu, type MenuItem, type MenuProps, type NamedColor, Portal, type PortalProps, Progress, type ProgressProps, type RGBColor, Radio, type RadioHandle, type RadioItem, type RadioProps, type RenderOptions, type ScrollIntoViewOptions, ScrollView, type ScrollViewProps, Select, type SelectHandle, type SelectItem, type SelectProps, Spacer, type SpacerProps, Spinner, type SpinnerProps, type Style, type StyledSegment, type TerminalCapabilities, Text, type TextAlign, type TextHandle, type TextProps, type Toast, ToastHost, type ToastHostProps, type ToastPosition, type ToastVariant, type UseFocusableOptions, type UseFocusableResult, type VisibleRange, type WrapMode, createMask, detectTerminalCapabilities, masks, parseAnsi, render, stripAnsi, supportsInlineImages, useApp, useDialog, useFocus, useFocusRegistry, useFocusable, useInput, useLayout, useScrollIntoView, useToast };