@blender-ui/react 0.1.0 → 0.2.1

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/index.d.ts CHANGED
@@ -1,95 +1,110 @@
1
- // Types for @blender-ui/react.
2
- import type { ReactNode, ReactElement, DependencyList, EffectCallback, Dispatch, SetStateAction, ElementType } from 'react'
3
- import type { App, Window, AppOptions, WindowOptions, Signal, Memo, ReadSignal, Ref } from '@blender-ui/native'
4
-
5
- export interface Root {
6
- render (element: ReactNode): void
7
- unmount (): void
8
- }
9
-
10
- /** A React root rendering into `window`'s body (unmounted when the window closes). */
11
- export function createRoot (window: Window): Root
12
-
13
- /** Open a window (and an App, unless `app` is given) and render `element` into it. */
14
- export function render (element: ReactNode, options?: WindowOptions & AppOptions & { app?: App }):
15
- { app: App, window: Window, root: Root }
16
-
17
- /** Run `fn` and flush React's work synchronously (tests). */
18
- export function act<R> (fn: () => R): R
19
-
20
- /** React's `createElement`, with render tracking for components. */
21
- export const createElement: typeof import('react').createElement
22
- /** A component type with render tracking (re-renders when a signal its render read changes). */
23
- export function track<T extends ElementType> (type: T): T
24
-
25
- // React's hooks that hold no state, as React exports them.
26
- export { use, useContext, useDebugValue, useId, useImperativeHandle } from 'react'
27
-
28
- // Signals.
29
- export { signal, effect, batch, untrack, createSignal, isSignal, Signal, Memo, ReadSignal, Ref } from '@blender-ui/native'
30
- /** A derived, cached signal (`memo` in @blender-ui/native; here `memo` stays React's). */
31
- export { memo as computed, ref } from '@blender-ui/native'
32
-
33
- /** React hooks re-exported unchanged, and why. */
34
- export const NO_TWIN: Record<string, string>
35
-
36
- // React's hooks by React's names, with signals for state. Same arguments and
37
- // timing as React's. A signal passed as a prop or child updates that node
38
- // alone; read while rendering (`.value`, `count + 1`), it re-renders the
39
- // component when it changes. Conditions and `===` need `.value`: a signal
40
- // object is always truthy.
41
-
42
- /** `[signal, setState]`: `setState(v)` or `setState(prev => next)`. */
43
- export function useState<T> (initialState: T | (() => T)): [Signal<T>, Dispatch<SetStateAction<T>>]
44
- export function useState<T = undefined> (): [Signal<T | undefined>, Dispatch<SetStateAction<T | undefined>>]
45
- /** `[signal, dispatch]`, with the latest render's reducer. */
46
- export function useReducer<S, A> (reducer: (state: S, action: A) => S, initialArg: S): [Signal<S>, Dispatch<A>]
47
- export function useReducer<S, A, I> (reducer: (state: S, action: A) => S, initialArg: I, init: (arg: I) => S): [Signal<S>, Dispatch<A>]
48
- /** `{ current }`, observable by effects and memos; reading it while rendering doesn't subscribe. */
49
- export function useRef<T> (initialValue: T): Ref<T>
50
- export function useRef<T = undefined> (): Ref<T | undefined>
51
- /** A memo following its signals, replaced when `deps` change (without deps: every render). */
52
- export function useMemo<T> (fn: () => T, deps?: DependencyList): Memo<T>
53
- /** React's `useCallback`; calls are batched and untracked. */
54
- export function useCallback<F extends (...args: any[]) => any> (fn: F, deps?: DependencyList): F
55
- /** React's `useEffectEvent`; calls are batched and untracked. */
56
- export function useEffectEvent<F extends (...args: any[]) => any> (fn: F): F
57
- /** React's `useEffect`, also re-run when the signals it read change. */
58
- export function useEffect (effect: EffectCallback, deps?: DependencyList): void
59
- /** React's `useLayoutEffect`, also re-run when the signals it read change. */
60
- export function useLayoutEffect (effect: EffectCallback, deps?: DependencyList): void
61
- /** React's `useInsertionEffect`, also re-run when the signals it read change. */
62
- export function useInsertionEffect (effect: EffectCallback, deps?: DependencyList): void
63
- /** A signal following the store. */
64
- export function useSyncExternalStore<T> (subscribe: (onChange: () => void) => () => void, getSnapshot: () => T,
65
- getServerSnapshot?: () => T): Signal<T>
66
- /** `[isPending, startTransition]`: what the action's writes trigger runs after urgent updates. */
67
- export function useTransition (): [Signal<boolean>, (action: () => void | Promise<void>) => void]
68
- /** React's `startTransition`, for signal writes too; settles when the action and its updates are done. */
69
- export function startTransition (action: () => void | Promise<void>): Promise<void>
70
- /** A signal following `value` (a signal or a value) at transition priority. */
71
- export function useDeferredValue<T> (value: T | ReadSignal<T>, initialValue?: T): Signal<T>
72
- /** `[state, dispatch, isPending]`: actions run in order, each with the previous state. */
73
- export function useActionState<S, P = void> (action: (state: S, payload: P) => S | Promise<S>, initialState: S,
74
- permalink?: string): [Signal<S>, (payload: P) => void, Signal<boolean>]
75
- /** `[optimistic, addOptimistic]`: updates last until their transition or action ends. */
76
- export function useOptimistic<S> (passthrough: S | ReadSignal<S>): [Memo<S>, (value: S) => void]
77
- export function useOptimistic<S, A> (passthrough: S | ReadSignal<S>, reducer: (state: S, action: A) => S):
78
- [Memo<S>, (action: A) => void]
79
-
80
- /** Rust's `use_signal`: a signal owned by this component. */
81
- export function useSignal<T> (initial: T | (() => T)): Signal<T>
82
- /** Rust's `Memo::new`: `useMemo(fn, deps = [])`. */
83
- export function useComputed<T> (fn: () => T, deps?: DependencyList): Memo<T>
84
- /** Re-render this component when `source` changes; returns its value (components
85
- * rendered without this package's JSX runtime or createElement). */
86
- export function useSignalValue<T> (source: ReadSignal<T>): T
87
-
88
- export type { ReactElement }
89
-
90
- // A signal is a valid child: `<span>Clicks: {count}</span>`.
91
- declare module 'react' {
92
- interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_REACT_NODES {
93
- buiSignal: ReadSignal<unknown>
94
- }
95
- }
1
+ // Types for @blender-ui/react.
2
+ import type { ReactNode, ReactElement, DependencyList, EffectCallback, Dispatch, SetStateAction, ElementType } from 'react'
3
+ import type { App, Window, AppOptions, WindowOptions, Signal, Memo, ReadSignal, Ref } from '@blender-ui/native'
4
+
5
+ export interface Root {
6
+ render (element: ReactNode): void
7
+ unmount (): void
8
+ }
9
+
10
+ /** A React root rendering into `window`'s body (unmounted when the window closes). */
11
+ export function createRoot (window: Window): Root
12
+
13
+ /** Open a window (and an App, unless `app` is given) and render `element` into it. */
14
+ export function render (element: ReactNode, options?: WindowOptions & AppOptions & { app?: App }):
15
+ { app: App, window: Window, root: Root }
16
+
17
+ /** Run `fn` and flush React's work synchronously (tests). */
18
+ export function act<R> (fn: () => R): R
19
+
20
+ /** React's `createElement`, with render tracking for components. */
21
+ export const createElement: typeof import('react').createElement
22
+ /** A component type with render tracking (re-renders when a signal its render read changes). */
23
+ export function track<T extends ElementType> (type: T): T
24
+
25
+ // React's hooks that hold no state, as React exports them.
26
+ export { use, useContext, useDebugValue, useId, useImperativeHandle } from 'react'
27
+
28
+ // Signals.
29
+ export { signal, effect, batch, untrack, createSignal, isSignal, Signal, Memo, ReadSignal, Ref } from '@blender-ui/native'
30
+ /** A derived, cached signal (`memo` in @blender-ui/native; here `memo` stays React's). */
31
+ export { memo as computed, ref } from '@blender-ui/native'
32
+
33
+ /** React hooks re-exported unchanged, and why. */
34
+ export const NO_TWIN: Record<string, string>
35
+
36
+ // React's hooks by React's names, with signals for state. Same arguments and
37
+ // timing as React's. A signal passed as a prop or child updates that node
38
+ // alone; read while rendering (`.value`, `count + 1`), it re-renders the
39
+ // component when it changes. Conditions and `===` need `.value`: a signal
40
+ // object is always truthy.
41
+
42
+ /** `[signal, setState]`: `setState(v)` or `setState(prev => next)`. */
43
+ export function useState<T> (initialState: T | (() => T)): [Signal<T>, Dispatch<SetStateAction<T>>]
44
+ export function useState<T = undefined> (): [Signal<T | undefined>, Dispatch<SetStateAction<T | undefined>>]
45
+ /** `[signal, dispatch]`, with the latest render's reducer. */
46
+ export function useReducer<S, A> (reducer: (state: S, action: A) => S, initialArg: S): [Signal<S>, Dispatch<A>]
47
+ export function useReducer<S, A, I> (reducer: (state: S, action: A) => S, initialArg: I, init: (arg: I) => S): [Signal<S>, Dispatch<A>]
48
+ /** `{ current }`, observable by effects and memos; reading it while rendering doesn't subscribe. */
49
+ export function useRef<T> (initialValue: T): Ref<T>
50
+ export function useRef<T = undefined> (): Ref<T | undefined>
51
+ /** A memo following its signals, replaced when `deps` change (without deps: every render). */
52
+ export function useMemo<T> (fn: () => T, deps?: DependencyList): Memo<T>
53
+ /** React's `useCallback`; calls are batched and untracked. */
54
+ export function useCallback<F extends (...args: any[]) => any> (fn: F, deps?: DependencyList): F
55
+ /** React's `useEffectEvent`; calls are batched and untracked. */
56
+ export function useEffectEvent<F extends (...args: any[]) => any> (fn: F): F
57
+ /** React's `useEffect`, also re-run when the signals it read change. */
58
+ export function useEffect (effect: EffectCallback, deps?: DependencyList): void
59
+ /** React's `useLayoutEffect`, also re-run when the signals it read change. */
60
+ export function useLayoutEffect (effect: EffectCallback, deps?: DependencyList): void
61
+ /** React's `useInsertionEffect`, also re-run when the signals it read change. */
62
+ export function useInsertionEffect (effect: EffectCallback, deps?: DependencyList): void
63
+ /** A signal following the store. */
64
+ export function useSyncExternalStore<T> (subscribe: (onChange: () => void) => () => void, getSnapshot: () => T,
65
+ getServerSnapshot?: () => T): Signal<T>
66
+ /** `[isPending, startTransition]`: what the action's writes trigger runs after urgent updates. */
67
+ export function useTransition (): [Signal<boolean>, (action: () => void | Promise<void>) => void]
68
+ /** React's `startTransition`, for signal writes too; settles when the action and its updates are done. */
69
+ export function startTransition (action: () => void | Promise<void>): Promise<void>
70
+ /** A signal following `value` (a signal or a value) at transition priority. */
71
+ export function useDeferredValue<T> (value: T | ReadSignal<T>, initialValue?: T): Signal<T>
72
+ /** `[state, dispatch, isPending]`: actions run in order, each with the previous state. */
73
+ export function useActionState<S, P = void> (action: (state: S, payload: P) => S | Promise<S>, initialState: S,
74
+ permalink?: string): [Signal<S>, (payload: P) => void, Signal<boolean>]
75
+ /** `[optimistic, addOptimistic]`: updates last until their transition or action ends. */
76
+ export function useOptimistic<S> (passthrough: S | ReadSignal<S>): [Memo<S>, (value: S) => void]
77
+ export function useOptimistic<S, A> (passthrough: S | ReadSignal<S>, reducer: (state: S, action: A) => S):
78
+ [Memo<S>, (action: A) => void]
79
+
80
+ /** Rust's `use_signal`: a signal owned by this component. */
81
+ export function useSignal<T> (initial: T | (() => T)): Signal<T>
82
+ /** Rust's `Memo::new`: `useMemo(fn, deps = [])`. */
83
+ export function useComputed<T> (fn: () => T, deps?: DependencyList): Memo<T>
84
+ /** Re-render this component when `source` changes; returns its value (components
85
+ * rendered without this package's JSX runtime or createElement). */
86
+ export function useSignalValue<T> (source: ReadSignal<T>): T
87
+
88
+ export type { ReactElement }
89
+
90
+ // A signal is a valid child: `<span>Clicks: {count}</span>`.
91
+ declare module 'react' {
92
+ interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_REACT_NODES {
93
+ buiSignal: ReadSignal<unknown>
94
+ }
95
+ }
96
+
97
+ /** Blender's widgets as components: always drawn and handled like Blender.
98
+ * Their lowercase HTML counterparts look like a browser's form controls
99
+ * (and like Blender inside an element with the `styled` attribute). */
100
+ type BlenderProps = Record<string, unknown> & { children?: ReactNode }
101
+ export function Button (props: BlenderProps): ReactNode
102
+ export function Checkbox (props: BlenderProps): ReactNode
103
+ export function Radio (props: BlenderProps): ReactNode
104
+ export function NumberField (props: BlenderProps): ReactNode
105
+ export function NumberSlider (props: BlenderProps): ReactNode
106
+ export function TextField (props: BlenderProps): ReactNode
107
+ export function TextArea (props: BlenderProps): ReactNode
108
+ export function ColorSwatch (props: BlenderProps): ReactNode
109
+ export function Dropdown (props: BlenderProps): ReactNode
110
+ export function ProgressBar (props: BlenderProps): ReactNode