@rectify-dev/core 2.0.3 → 2.3.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.
- package/README.md +445 -0
- package/dist/index.cjs +870 -439
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -3
- package/dist/index.d.ts +130 -3
- package/dist/index.js +866 -440
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.cts +6 -0
- package/dist/jsx-runtime.d.ts +6 -0
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as _rectify_dev_shared from '@rectify-dev/shared';
|
|
2
|
+
import { RectifyNode, FC, LazyComponent, SuspenseProps, Fiber } from '@rectify-dev/shared';
|
|
3
|
+
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, RectifyNode, ScriptHTMLAttributes, SelectHTMLAttributes, SuspenseProps, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
3
4
|
export { Fragment, jsx } from './runtime.cjs';
|
|
4
5
|
|
|
5
6
|
type RectifyDomRoot = {
|
|
@@ -44,6 +45,109 @@ type MemoComponent<P = any> = FC<P> & {
|
|
|
44
45
|
*/
|
|
45
46
|
declare function memo<P = any>(Component: FC<P>, compare?: (prevProps: P, nextProps: P) => boolean): MemoComponent<P>;
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Lazily loads a component via a dynamic import factory.
|
|
50
|
+
*
|
|
51
|
+
* The returned object is used as a JSX element type and behaves like a normal
|
|
52
|
+
* function component once loaded. While loading it suspends the nearest
|
|
53
|
+
* `<Suspense>` boundary, which renders its `fallback` instead.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const HeavyChart = lazy(() => import("./HeavyChart"));
|
|
57
|
+
*
|
|
58
|
+
* function App() {
|
|
59
|
+
* return (
|
|
60
|
+
* <Suspense fallback={<Spinner />}>
|
|
61
|
+
* <HeavyChart />
|
|
62
|
+
* </Suspense>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
declare const lazy: <T>(factory: () => Promise<{
|
|
67
|
+
default: T;
|
|
68
|
+
} | T>) => LazyComponent<T>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Catches thrown promises from any child (including lazy components) and
|
|
72
|
+
* renders `fallback` until they resolve.
|
|
73
|
+
*
|
|
74
|
+
* Marked as a sentinel with `_isSuspense` so the reconciler can identify it
|
|
75
|
+
* without a dedicated $$typeof symbol — consistent with how MemoComponent
|
|
76
|
+
* and ContextProvider are detected.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* <Suspense fallback={<Spinner />}>
|
|
80
|
+
* <LazyPage />
|
|
81
|
+
* </Suspense>
|
|
82
|
+
*/
|
|
83
|
+
declare const Suspense: (_props: SuspenseProps) => null;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Base class for Rectify class components.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* class Counter extends Component<{}, { count: number }> {
|
|
90
|
+
* state = { count: 0 };
|
|
91
|
+
*
|
|
92
|
+
* render() {
|
|
93
|
+
* return (
|
|
94
|
+
* <button onClick={() => this.setState({ count: this.state.count + 1 })}>
|
|
95
|
+
* {this.state.count}
|
|
96
|
+
* </button>
|
|
97
|
+
* );
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
*/
|
|
101
|
+
declare class Component<P = {}, S = {}> {
|
|
102
|
+
/** Marks this as a class component for the reconciler. */
|
|
103
|
+
static readonly _isClassComponent = true;
|
|
104
|
+
props: P;
|
|
105
|
+
state: S;
|
|
106
|
+
/**
|
|
107
|
+
* @internal Set by the reconciler when the instance is created so
|
|
108
|
+
* `setState` can enqueue a re-render on the correct fiber.
|
|
109
|
+
*/
|
|
110
|
+
_fiber: _rectify_dev_shared.Fiber | null;
|
|
111
|
+
/**
|
|
112
|
+
* @internal Snapshots taken by the reconciler in beginWork before each
|
|
113
|
+
* update render so that `componentDidUpdate` receives the correct prev values.
|
|
114
|
+
* Cleared after `componentDidUpdate` is called.
|
|
115
|
+
*/
|
|
116
|
+
_prevProps: P | undefined;
|
|
117
|
+
_prevState: S | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* @internal Queue of pending setState updates, flushed by the reconciler
|
|
120
|
+
* during beginWork so that prevState snapshots can be taken first.
|
|
121
|
+
*/
|
|
122
|
+
_pendingStateQueue: Array<Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)>;
|
|
123
|
+
constructor(props: P);
|
|
124
|
+
/** Called once, immediately after the component is inserted into the DOM. */
|
|
125
|
+
componentDidMount?(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Called after every re-render.
|
|
128
|
+
* @param prevProps — props before the update
|
|
129
|
+
* @param prevState — state before the update
|
|
130
|
+
*/
|
|
131
|
+
componentDidUpdate?(prevProps: P, prevState: S): void;
|
|
132
|
+
/** Called immediately before the component is removed from the DOM. */
|
|
133
|
+
componentWillUnmount?(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Return false to skip re-rendering when props or state haven't changed.
|
|
136
|
+
* Defaults to always re-render.
|
|
137
|
+
*/
|
|
138
|
+
shouldComponentUpdate?(nextProps: P, nextState: S): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Merges `partialState` into the current state and schedules a re-render.
|
|
141
|
+
* Accepts either a plain partial state object or an updater function.
|
|
142
|
+
*/
|
|
143
|
+
setState(partialState: Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)): void;
|
|
144
|
+
/**
|
|
145
|
+
* Must be implemented by every class component.
|
|
146
|
+
* Returns the subtree to render.
|
|
147
|
+
*/
|
|
148
|
+
render(): RectifyNode;
|
|
149
|
+
}
|
|
150
|
+
|
|
47
151
|
type StateUpdater<S> = S | ((prevState: S) => S);
|
|
48
152
|
type StateDispatcher<S> = (updater: StateUpdater<S>) => void;
|
|
49
153
|
|
|
@@ -51,6 +155,11 @@ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
|
|
|
51
155
|
declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
|
|
52
156
|
declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
|
|
53
157
|
|
|
158
|
+
type Reducer<S, A> = (state: S, action: A) => S;
|
|
159
|
+
type Dispatch<A> = (action: A) => void;
|
|
160
|
+
declare function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>];
|
|
161
|
+
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, Dispatch<A>];
|
|
162
|
+
|
|
54
163
|
declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
|
|
55
164
|
|
|
56
165
|
/**
|
|
@@ -157,4 +266,22 @@ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
|
|
|
157
266
|
*/
|
|
158
267
|
declare function useContext<T>(context: RectifyContext<T>): T;
|
|
159
268
|
|
|
160
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Returns a stable, globally unique ID string that is consistent across
|
|
271
|
+
* server and client renders within the same component instance.
|
|
272
|
+
*
|
|
273
|
+
* The ID is generated once on mount and returned unchanged on every
|
|
274
|
+
* subsequent render — it never changes for the lifetime of the component.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* const inputId = useId();
|
|
278
|
+
* return (
|
|
279
|
+
* <>
|
|
280
|
+
* <label htmlFor={inputId}>Name</label>
|
|
281
|
+
* <input id={inputId} />
|
|
282
|
+
* </>
|
|
283
|
+
* );
|
|
284
|
+
*/
|
|
285
|
+
declare const useId: () => string;
|
|
286
|
+
|
|
287
|
+
export { Component, type Dispatch, type MemoComponent, type RectifyContext, type Reducer, type RefObject, Suspense, SyntheticEvent, createContext, createRoot, lazy, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useReducer, useRef, useState };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as _rectify_dev_shared from '@rectify-dev/shared';
|
|
2
|
+
import { RectifyNode, FC, LazyComponent, SuspenseProps, Fiber } from '@rectify-dev/shared';
|
|
3
|
+
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, RectifyNode, ScriptHTMLAttributes, SelectHTMLAttributes, SuspenseProps, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
3
4
|
export { Fragment, jsx } from './runtime.js';
|
|
4
5
|
|
|
5
6
|
type RectifyDomRoot = {
|
|
@@ -44,6 +45,109 @@ type MemoComponent<P = any> = FC<P> & {
|
|
|
44
45
|
*/
|
|
45
46
|
declare function memo<P = any>(Component: FC<P>, compare?: (prevProps: P, nextProps: P) => boolean): MemoComponent<P>;
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Lazily loads a component via a dynamic import factory.
|
|
50
|
+
*
|
|
51
|
+
* The returned object is used as a JSX element type and behaves like a normal
|
|
52
|
+
* function component once loaded. While loading it suspends the nearest
|
|
53
|
+
* `<Suspense>` boundary, which renders its `fallback` instead.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const HeavyChart = lazy(() => import("./HeavyChart"));
|
|
57
|
+
*
|
|
58
|
+
* function App() {
|
|
59
|
+
* return (
|
|
60
|
+
* <Suspense fallback={<Spinner />}>
|
|
61
|
+
* <HeavyChart />
|
|
62
|
+
* </Suspense>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
*/
|
|
66
|
+
declare const lazy: <T>(factory: () => Promise<{
|
|
67
|
+
default: T;
|
|
68
|
+
} | T>) => LazyComponent<T>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Catches thrown promises from any child (including lazy components) and
|
|
72
|
+
* renders `fallback` until they resolve.
|
|
73
|
+
*
|
|
74
|
+
* Marked as a sentinel with `_isSuspense` so the reconciler can identify it
|
|
75
|
+
* without a dedicated $$typeof symbol — consistent with how MemoComponent
|
|
76
|
+
* and ContextProvider are detected.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* <Suspense fallback={<Spinner />}>
|
|
80
|
+
* <LazyPage />
|
|
81
|
+
* </Suspense>
|
|
82
|
+
*/
|
|
83
|
+
declare const Suspense: (_props: SuspenseProps) => null;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Base class for Rectify class components.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* class Counter extends Component<{}, { count: number }> {
|
|
90
|
+
* state = { count: 0 };
|
|
91
|
+
*
|
|
92
|
+
* render() {
|
|
93
|
+
* return (
|
|
94
|
+
* <button onClick={() => this.setState({ count: this.state.count + 1 })}>
|
|
95
|
+
* {this.state.count}
|
|
96
|
+
* </button>
|
|
97
|
+
* );
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
*/
|
|
101
|
+
declare class Component<P = {}, S = {}> {
|
|
102
|
+
/** Marks this as a class component for the reconciler. */
|
|
103
|
+
static readonly _isClassComponent = true;
|
|
104
|
+
props: P;
|
|
105
|
+
state: S;
|
|
106
|
+
/**
|
|
107
|
+
* @internal Set by the reconciler when the instance is created so
|
|
108
|
+
* `setState` can enqueue a re-render on the correct fiber.
|
|
109
|
+
*/
|
|
110
|
+
_fiber: _rectify_dev_shared.Fiber | null;
|
|
111
|
+
/**
|
|
112
|
+
* @internal Snapshots taken by the reconciler in beginWork before each
|
|
113
|
+
* update render so that `componentDidUpdate` receives the correct prev values.
|
|
114
|
+
* Cleared after `componentDidUpdate` is called.
|
|
115
|
+
*/
|
|
116
|
+
_prevProps: P | undefined;
|
|
117
|
+
_prevState: S | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* @internal Queue of pending setState updates, flushed by the reconciler
|
|
120
|
+
* during beginWork so that prevState snapshots can be taken first.
|
|
121
|
+
*/
|
|
122
|
+
_pendingStateQueue: Array<Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)>;
|
|
123
|
+
constructor(props: P);
|
|
124
|
+
/** Called once, immediately after the component is inserted into the DOM. */
|
|
125
|
+
componentDidMount?(): void;
|
|
126
|
+
/**
|
|
127
|
+
* Called after every re-render.
|
|
128
|
+
* @param prevProps — props before the update
|
|
129
|
+
* @param prevState — state before the update
|
|
130
|
+
*/
|
|
131
|
+
componentDidUpdate?(prevProps: P, prevState: S): void;
|
|
132
|
+
/** Called immediately before the component is removed from the DOM. */
|
|
133
|
+
componentWillUnmount?(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Return false to skip re-rendering when props or state haven't changed.
|
|
136
|
+
* Defaults to always re-render.
|
|
137
|
+
*/
|
|
138
|
+
shouldComponentUpdate?(nextProps: P, nextState: S): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Merges `partialState` into the current state and schedules a re-render.
|
|
141
|
+
* Accepts either a plain partial state object or an updater function.
|
|
142
|
+
*/
|
|
143
|
+
setState(partialState: Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)): void;
|
|
144
|
+
/**
|
|
145
|
+
* Must be implemented by every class component.
|
|
146
|
+
* Returns the subtree to render.
|
|
147
|
+
*/
|
|
148
|
+
render(): RectifyNode;
|
|
149
|
+
}
|
|
150
|
+
|
|
47
151
|
type StateUpdater<S> = S | ((prevState: S) => S);
|
|
48
152
|
type StateDispatcher<S> = (updater: StateUpdater<S>) => void;
|
|
49
153
|
|
|
@@ -51,6 +155,11 @@ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
|
|
|
51
155
|
declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
|
|
52
156
|
declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
|
|
53
157
|
|
|
158
|
+
type Reducer<S, A> = (state: S, action: A) => S;
|
|
159
|
+
type Dispatch<A> = (action: A) => void;
|
|
160
|
+
declare function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>];
|
|
161
|
+
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, Dispatch<A>];
|
|
162
|
+
|
|
54
163
|
declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
|
|
55
164
|
|
|
56
165
|
/**
|
|
@@ -157,4 +266,22 @@ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
|
|
|
157
266
|
*/
|
|
158
267
|
declare function useContext<T>(context: RectifyContext<T>): T;
|
|
159
268
|
|
|
160
|
-
|
|
269
|
+
/**
|
|
270
|
+
* Returns a stable, globally unique ID string that is consistent across
|
|
271
|
+
* server and client renders within the same component instance.
|
|
272
|
+
*
|
|
273
|
+
* The ID is generated once on mount and returned unchanged on every
|
|
274
|
+
* subsequent render — it never changes for the lifetime of the component.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* const inputId = useId();
|
|
278
|
+
* return (
|
|
279
|
+
* <>
|
|
280
|
+
* <label htmlFor={inputId}>Name</label>
|
|
281
|
+
* <input id={inputId} />
|
|
282
|
+
* </>
|
|
283
|
+
* );
|
|
284
|
+
*/
|
|
285
|
+
declare const useId: () => string;
|
|
286
|
+
|
|
287
|
+
export { Component, type Dispatch, type MemoComponent, type RectifyContext, type Reducer, type RefObject, Suspense, SyntheticEvent, createContext, createRoot, lazy, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useReducer, useRef, useState };
|