@rectify-dev/core 2.0.1 → 2.0.3

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.cts CHANGED
@@ -1,8 +1,24 @@
1
- import { FC } from '@rectify-dev/shared';
1
+ import { RectifyNode, FC, Fiber } from '@rectify-dev/shared';
2
2
  export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
3
- export { SyntheticEvent, createRoot } from '@rectify-dev/dom';
4
3
  export { Fragment, jsx } from './runtime.cjs';
5
- export { RectifyContext, RefObject, createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from '@rectify-dev/hook';
4
+
5
+ type RectifyDomRoot = {
6
+ render: (node: RectifyNode) => void;
7
+ unmount: () => void;
8
+ };
9
+ declare const createRoot: (container: Element) => RectifyDomRoot;
10
+
11
+ type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
12
+
13
+ declare class SyntheticEvent {
14
+ target: Element | null;
15
+ currentTarget: Element | null;
16
+ nativeEvent: AnyNativeEvent;
17
+ private propagationStopped;
18
+ constructor(nativeEvent: AnyNativeEvent);
19
+ stopPropagation(): void;
20
+ isPropagationStopped(): boolean;
21
+ }
6
22
 
7
23
  type MemoComponent<P = any> = FC<P> & {
8
24
  /** Marks this as a memo-wrapped component for the reconciler. */
@@ -28,4 +44,117 @@ type MemoComponent<P = any> = FC<P> & {
28
44
  */
29
45
  declare function memo<P = any>(Component: FC<P>, compare?: (prevProps: P, nextProps: P) => boolean): MemoComponent<P>;
30
46
 
31
- export { type MemoComponent, memo };
47
+ type StateUpdater<S> = S | ((prevState: S) => S);
48
+ type StateDispatcher<S> = (updater: StateUpdater<S>) => void;
49
+
50
+ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
51
+ declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
52
+ declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
53
+
54
+ declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
55
+
56
+ /**
57
+ * Like `useEffect`, but fires **synchronously after every DOM mutation** and
58
+ * before the browser has a chance to paint. Use this when you need to read
59
+ * layout or synchronously re-style the DOM (tooltips, scroll restoration,
60
+ * measuring element sizes, etc.).
61
+ *
62
+ * Prefer `useEffect` for everything else — `useLayoutEffect` blocks the paint.
63
+ *
64
+ * @example
65
+ * useLayoutEffect(() => {
66
+ * const { height } = ref.current.getBoundingClientRect();
67
+ * setTooltipTop(-height);
68
+ * }, []);
69
+ */
70
+ declare function useLayoutEffect(create: () => void | (() => void), deps?: any[]): void;
71
+
72
+ type RefObject<T> = {
73
+ current: T;
74
+ };
75
+ /**
76
+ * Returns a stable mutable ref object whose `.current` property is initialised
77
+ * to `initialValue`. The same object is returned on every render — updating
78
+ * `.current` does NOT trigger a re-render.
79
+ *
80
+ * Two common uses:
81
+ * 1. Hold a DOM node: const el = useRef<HTMLDivElement>(null)
82
+ * 2. Hold a mutable value across renders without causing re-renders.
83
+ */
84
+ declare function useRef<T>(initialValue: T): RefObject<T>;
85
+ declare function useRef<T>(initialValue: T | null): RefObject<T | null>;
86
+ declare function useRef<T = undefined>(): RefObject<T | undefined>;
87
+
88
+ /**
89
+ * Returns a memoized value. `factory` is only re-executed when one of the
90
+ * `deps` changes (using `Object.is` comparison), otherwise the cached value
91
+ * from the previous render is returned unchanged.
92
+ *
93
+ * @example
94
+ * const sorted = useMemo(() => [...list].sort(), [list]);
95
+ */
96
+ declare function useMemo<T>(factory: () => T, deps: any[]): T;
97
+
98
+ /**
99
+ * Returns a memoized callback. The same function reference is returned on
100
+ * every render unless one of the `deps` changes.
101
+ *
102
+ * This is sugar over `useMemo(() => fn, deps)` — it keeps function identity
103
+ * stable so child components that compare props by reference don't re-render
104
+ * unnecessarily.
105
+ *
106
+ * @example
107
+ * const handleClick = useCallback(() => doSomething(id), [id]);
108
+ */
109
+ declare function useCallback<T extends (...args: any[]) => any>(callback: T, deps: any[]): T;
110
+
111
+ /**
112
+ * A context object that is also its own Provider component.
113
+ * Both forms are equivalent:
114
+ * jsx(MyContext, { value, children }) // Context as Provider
115
+ * jsx(MyContext.Provider, { value, children }) // Classic Provider form
116
+ */
117
+ type RectifyContext<T> = {
118
+ (props: {
119
+ value: T;
120
+ children?: any;
121
+ }): null;
122
+ /** Self-reference used by the reconciler to identify Provider fibers. */
123
+ _context: RectifyContext<T>;
124
+ _defaultValue: T;
125
+ _subscribers: Set<Fiber>;
126
+ /** Alias to self — `Context.Provider === Context`. */
127
+ Provider: RectifyContext<T>;
128
+ };
129
+ /**
130
+ * Creates a new context. The returned object is itself a Provider component,
131
+ * so both forms below are equivalent:
132
+ *
133
+ * @example
134
+ * const ThemeCtx = createContext<'light' | 'dark'>('light');
135
+ *
136
+ * // Option A – Context used directly as Provider
137
+ * jsx(ThemeCtx, { value: 'dark', children: ... })
138
+ *
139
+ * // Option B – Classic .Provider form
140
+ * jsx(ThemeCtx.Provider, { value: 'dark', children: ... })
141
+ */
142
+ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
143
+ /**
144
+ * Reads the current value of `context` for the calling component.
145
+ *
146
+ * Walks up the fiber tree to the nearest matching Provider and reads its
147
+ * `pendingProps.value` directly — no render-time stack required. This means
148
+ * the correct value is always returned even when the Provider did not
149
+ * re-render in the current pass.
150
+ *
151
+ * The component re-renders whenever the nearest Provider supplies a new value
152
+ * (compared with `Object.is`). Unlike other hooks this does NOT consume a
153
+ * hook slot and may be called conditionally.
154
+ *
155
+ * @example
156
+ * const theme = useContext(ThemeCtx); // 'light' | 'dark'
157
+ */
158
+ declare function useContext<T>(context: RectifyContext<T>): T;
159
+
160
+ export { type MemoComponent, type RectifyContext, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,24 @@
1
- import { FC } from '@rectify-dev/shared';
1
+ import { RectifyNode, FC, Fiber } from '@rectify-dev/shared';
2
2
  export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
3
- export { SyntheticEvent, createRoot } from '@rectify-dev/dom';
4
3
  export { Fragment, jsx } from './runtime.js';
5
- export { RectifyContext, RefObject, createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from '@rectify-dev/hook';
4
+
5
+ type RectifyDomRoot = {
6
+ render: (node: RectifyNode) => void;
7
+ unmount: () => void;
8
+ };
9
+ declare const createRoot: (container: Element) => RectifyDomRoot;
10
+
11
+ type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
12
+
13
+ declare class SyntheticEvent {
14
+ target: Element | null;
15
+ currentTarget: Element | null;
16
+ nativeEvent: AnyNativeEvent;
17
+ private propagationStopped;
18
+ constructor(nativeEvent: AnyNativeEvent);
19
+ stopPropagation(): void;
20
+ isPropagationStopped(): boolean;
21
+ }
6
22
 
7
23
  type MemoComponent<P = any> = FC<P> & {
8
24
  /** Marks this as a memo-wrapped component for the reconciler. */
@@ -28,4 +44,117 @@ type MemoComponent<P = any> = FC<P> & {
28
44
  */
29
45
  declare function memo<P = any>(Component: FC<P>, compare?: (prevProps: P, nextProps: P) => boolean): MemoComponent<P>;
30
46
 
31
- export { type MemoComponent, memo };
47
+ type StateUpdater<S> = S | ((prevState: S) => S);
48
+ type StateDispatcher<S> = (updater: StateUpdater<S>) => void;
49
+
50
+ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
51
+ declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
52
+ declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
53
+
54
+ declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
55
+
56
+ /**
57
+ * Like `useEffect`, but fires **synchronously after every DOM mutation** and
58
+ * before the browser has a chance to paint. Use this when you need to read
59
+ * layout or synchronously re-style the DOM (tooltips, scroll restoration,
60
+ * measuring element sizes, etc.).
61
+ *
62
+ * Prefer `useEffect` for everything else — `useLayoutEffect` blocks the paint.
63
+ *
64
+ * @example
65
+ * useLayoutEffect(() => {
66
+ * const { height } = ref.current.getBoundingClientRect();
67
+ * setTooltipTop(-height);
68
+ * }, []);
69
+ */
70
+ declare function useLayoutEffect(create: () => void | (() => void), deps?: any[]): void;
71
+
72
+ type RefObject<T> = {
73
+ current: T;
74
+ };
75
+ /**
76
+ * Returns a stable mutable ref object whose `.current` property is initialised
77
+ * to `initialValue`. The same object is returned on every render — updating
78
+ * `.current` does NOT trigger a re-render.
79
+ *
80
+ * Two common uses:
81
+ * 1. Hold a DOM node: const el = useRef<HTMLDivElement>(null)
82
+ * 2. Hold a mutable value across renders without causing re-renders.
83
+ */
84
+ declare function useRef<T>(initialValue: T): RefObject<T>;
85
+ declare function useRef<T>(initialValue: T | null): RefObject<T | null>;
86
+ declare function useRef<T = undefined>(): RefObject<T | undefined>;
87
+
88
+ /**
89
+ * Returns a memoized value. `factory` is only re-executed when one of the
90
+ * `deps` changes (using `Object.is` comparison), otherwise the cached value
91
+ * from the previous render is returned unchanged.
92
+ *
93
+ * @example
94
+ * const sorted = useMemo(() => [...list].sort(), [list]);
95
+ */
96
+ declare function useMemo<T>(factory: () => T, deps: any[]): T;
97
+
98
+ /**
99
+ * Returns a memoized callback. The same function reference is returned on
100
+ * every render unless one of the `deps` changes.
101
+ *
102
+ * This is sugar over `useMemo(() => fn, deps)` — it keeps function identity
103
+ * stable so child components that compare props by reference don't re-render
104
+ * unnecessarily.
105
+ *
106
+ * @example
107
+ * const handleClick = useCallback(() => doSomething(id), [id]);
108
+ */
109
+ declare function useCallback<T extends (...args: any[]) => any>(callback: T, deps: any[]): T;
110
+
111
+ /**
112
+ * A context object that is also its own Provider component.
113
+ * Both forms are equivalent:
114
+ * jsx(MyContext, { value, children }) // Context as Provider
115
+ * jsx(MyContext.Provider, { value, children }) // Classic Provider form
116
+ */
117
+ type RectifyContext<T> = {
118
+ (props: {
119
+ value: T;
120
+ children?: any;
121
+ }): null;
122
+ /** Self-reference used by the reconciler to identify Provider fibers. */
123
+ _context: RectifyContext<T>;
124
+ _defaultValue: T;
125
+ _subscribers: Set<Fiber>;
126
+ /** Alias to self — `Context.Provider === Context`. */
127
+ Provider: RectifyContext<T>;
128
+ };
129
+ /**
130
+ * Creates a new context. The returned object is itself a Provider component,
131
+ * so both forms below are equivalent:
132
+ *
133
+ * @example
134
+ * const ThemeCtx = createContext<'light' | 'dark'>('light');
135
+ *
136
+ * // Option A – Context used directly as Provider
137
+ * jsx(ThemeCtx, { value: 'dark', children: ... })
138
+ *
139
+ * // Option B – Classic .Provider form
140
+ * jsx(ThemeCtx.Provider, { value: 'dark', children: ... })
141
+ */
142
+ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
143
+ /**
144
+ * Reads the current value of `context` for the calling component.
145
+ *
146
+ * Walks up the fiber tree to the nearest matching Provider and reads its
147
+ * `pendingProps.value` directly — no render-time stack required. This means
148
+ * the correct value is always returned even when the Provider did not
149
+ * re-render in the current pass.
150
+ *
151
+ * The component re-renders whenever the nearest Provider supplies a new value
152
+ * (compared with `Object.is`). Unlike other hooks this does NOT consume a
153
+ * hook slot and may be called conditionally.
154
+ *
155
+ * @example
156
+ * const theme = useContext(ThemeCtx); // 'light' | 'dark'
157
+ */
158
+ declare function useContext<T>(context: RectifyContext<T>): T;
159
+
160
+ export { type MemoComponent, type RectifyContext, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState };
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { __name } from './chunk-2FA4QXYL.js';
2
2
  export { Fragment, jsx } from './chunk-2FA4QXYL.js';
3
3
  import { isFunction, shallowEqual, createElementFromRectifyNode, isValidRectifyElement, isArray, isPlainObject, omit, RECTIFY_FRAGMENT_TYPE, RECTIFY_TEXT_TYPE, RECTIFY_ELEMENT_TYPE } from '@rectify-dev/shared';
4
- export { FC } from '@rectify-dev/shared';
5
4
 
6
5
  // ../rectify-dom-binding/src/events/RectifyEventRegistry.ts
7
6
  var allNativeEvents = /* @__PURE__ */ new Set();