what-react 0.11.1 → 0.11.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/dom.d.ts +57 -0
- package/index.d.ts +272 -0
- package/jsx-dev-runtime.d.ts +18 -0
- package/jsx-runtime.d.ts +300 -0
- package/package.json +29 -8
- package/src/runtime.js +45 -5
- package/vite.d.ts +21 -0
package/dom.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// what-react/dom — react-dom compatible surface (src/dom.js).
|
|
2
|
+
// Alias `react-dom` → `what-react/dom` to run React libraries that render.
|
|
3
|
+
|
|
4
|
+
import type { ReactNode } from './index';
|
|
5
|
+
|
|
6
|
+
export interface Root {
|
|
7
|
+
render(children: ReactNode): void;
|
|
8
|
+
unmount(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createRoot(container: Element | DocumentFragment): Root;
|
|
12
|
+
export function hydrateRoot(
|
|
13
|
+
container: Element | DocumentFragment,
|
|
14
|
+
initialChildren: ReactNode,
|
|
15
|
+
): Root;
|
|
16
|
+
|
|
17
|
+
export function render(
|
|
18
|
+
element: ReactNode,
|
|
19
|
+
container: Element | DocumentFragment,
|
|
20
|
+
callback?: () => void,
|
|
21
|
+
): void;
|
|
22
|
+
|
|
23
|
+
export function unmountComponentAtNode(
|
|
24
|
+
container: Element | DocumentFragment,
|
|
25
|
+
): boolean;
|
|
26
|
+
|
|
27
|
+
export function createPortal(
|
|
28
|
+
children: ReactNode,
|
|
29
|
+
container: Element | DocumentFragment,
|
|
30
|
+
key?: string | null,
|
|
31
|
+
): ReactNode;
|
|
32
|
+
|
|
33
|
+
export function flushSync<R>(fn: () => R): R;
|
|
34
|
+
|
|
35
|
+
export function findDOMNode(
|
|
36
|
+
component: unknown,
|
|
37
|
+
): Element | Text | null;
|
|
38
|
+
|
|
39
|
+
export function unstable_batchedUpdates<A, R>(
|
|
40
|
+
fn: (arg: A) => R,
|
|
41
|
+
arg?: A,
|
|
42
|
+
): R;
|
|
43
|
+
|
|
44
|
+
export const version: string;
|
|
45
|
+
|
|
46
|
+
declare const ReactDOM: {
|
|
47
|
+
createRoot: typeof createRoot;
|
|
48
|
+
hydrateRoot: typeof hydrateRoot;
|
|
49
|
+
render: typeof render;
|
|
50
|
+
unmountComponentAtNode: typeof unmountComponentAtNode;
|
|
51
|
+
createPortal: typeof createPortal;
|
|
52
|
+
flushSync: typeof flushSync;
|
|
53
|
+
findDOMNode: typeof findDOMNode;
|
|
54
|
+
unstable_batchedUpdates: typeof unstable_batchedUpdates;
|
|
55
|
+
version: string;
|
|
56
|
+
};
|
|
57
|
+
export default ReactDOM;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// what-react — TypeScript declarations for the React compatibility layer.
|
|
2
|
+
//
|
|
3
|
+
// what-react implements React's public API (hooks that return VALUES,
|
|
4
|
+
// re-rendering components, keyed reconciliation) on What's runtime. These
|
|
5
|
+
// declarations type the surface that is *actually exported* from src/index.js
|
|
6
|
+
// so `import { useState, createElement } from 'what-react'` is type-checked
|
|
7
|
+
// instead of resolving to `any`.
|
|
8
|
+
//
|
|
9
|
+
// Scope: the module's own exports. When you alias `react` → `what-react` to run
|
|
10
|
+
// third-party React libraries, those libraries still bring their own
|
|
11
|
+
// `@types/react` declarations — these types are for code that imports
|
|
12
|
+
// what-react directly.
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Core element / node types
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
export type Key = string | number;
|
|
19
|
+
|
|
20
|
+
export interface RefObject<T> {
|
|
21
|
+
readonly current: T | null;
|
|
22
|
+
}
|
|
23
|
+
export interface MutableRefObject<T> {
|
|
24
|
+
current: T;
|
|
25
|
+
}
|
|
26
|
+
export type RefCallback<T> = (instance: T | null) => void;
|
|
27
|
+
export type Ref<T> = RefCallback<T> | RefObject<T> | null;
|
|
28
|
+
|
|
29
|
+
export interface ReactElement<P = any, T = any> {
|
|
30
|
+
type: T;
|
|
31
|
+
props: P;
|
|
32
|
+
key: Key | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ReactNode =
|
|
36
|
+
| ReactElement
|
|
37
|
+
| string
|
|
38
|
+
| number
|
|
39
|
+
| boolean
|
|
40
|
+
| null
|
|
41
|
+
| undefined
|
|
42
|
+
| Iterable<ReactNode>;
|
|
43
|
+
|
|
44
|
+
export interface FunctionComponent<P = {}> {
|
|
45
|
+
(props: P & { children?: ReactNode }): ReactElement | null;
|
|
46
|
+
displayName?: string;
|
|
47
|
+
}
|
|
48
|
+
export type FC<P = {}> = FunctionComponent<P>;
|
|
49
|
+
|
|
50
|
+
export interface ComponentClass<P = {}, S = {}> {
|
|
51
|
+
new (props: P): Component<P, S>;
|
|
52
|
+
displayName?: string;
|
|
53
|
+
}
|
|
54
|
+
export type ComponentType<P = {}> = FunctionComponent<P> | ComponentClass<P>;
|
|
55
|
+
|
|
56
|
+
export interface ExoticComponent<P = {}> {
|
|
57
|
+
(props: P): ReactElement | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Hooks
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
export type Dispatch<A> = (value: A) => void;
|
|
65
|
+
export type SetStateAction<S> = S | ((prev: S) => S);
|
|
66
|
+
|
|
67
|
+
export function useState<S>(
|
|
68
|
+
initialState: S | (() => S),
|
|
69
|
+
): [S, Dispatch<SetStateAction<S>>];
|
|
70
|
+
export function useState<S = undefined>(): [
|
|
71
|
+
S | undefined,
|
|
72
|
+
Dispatch<SetStateAction<S | undefined>>,
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
76
|
+
export type ReducerState<R> = R extends Reducer<infer S, any> ? S : never;
|
|
77
|
+
export type ReducerAction<R> = R extends Reducer<any, infer A> ? A : never;
|
|
78
|
+
|
|
79
|
+
export function useReducer<R extends Reducer<any, any>>(
|
|
80
|
+
reducer: R,
|
|
81
|
+
initialState: ReducerState<R>,
|
|
82
|
+
): [ReducerState<R>, Dispatch<ReducerAction<R>>];
|
|
83
|
+
export function useReducer<R extends Reducer<any, any>, I>(
|
|
84
|
+
reducer: R,
|
|
85
|
+
initialArg: I,
|
|
86
|
+
init: (arg: I) => ReducerState<R>,
|
|
87
|
+
): [ReducerState<R>, Dispatch<ReducerAction<R>>];
|
|
88
|
+
|
|
89
|
+
export type DependencyList = ReadonlyArray<unknown>;
|
|
90
|
+
export type EffectCallback = () => void | (() => void);
|
|
91
|
+
|
|
92
|
+
export function useEffect(effect: EffectCallback, deps?: DependencyList): void;
|
|
93
|
+
export function useLayoutEffect(
|
|
94
|
+
effect: EffectCallback,
|
|
95
|
+
deps?: DependencyList,
|
|
96
|
+
): void;
|
|
97
|
+
export function useInsertionEffect(
|
|
98
|
+
effect: EffectCallback,
|
|
99
|
+
deps?: DependencyList,
|
|
100
|
+
): void;
|
|
101
|
+
|
|
102
|
+
export function useMemo<T>(factory: () => T, deps: DependencyList | undefined): T;
|
|
103
|
+
export function useCallback<T extends (...args: any[]) => any>(
|
|
104
|
+
callback: T,
|
|
105
|
+
deps: DependencyList,
|
|
106
|
+
): T;
|
|
107
|
+
|
|
108
|
+
export function useRef<T>(initialValue: T): MutableRefObject<T>;
|
|
109
|
+
export function useRef<T>(initialValue: T | null): RefObject<T>;
|
|
110
|
+
export function useRef<T = undefined>(): MutableRefObject<T | undefined>;
|
|
111
|
+
|
|
112
|
+
export function useImperativeHandle<T, R extends T>(
|
|
113
|
+
ref: Ref<T> | undefined,
|
|
114
|
+
create: () => R,
|
|
115
|
+
deps?: DependencyList,
|
|
116
|
+
): void;
|
|
117
|
+
|
|
118
|
+
export interface ProviderProps<T> {
|
|
119
|
+
value: T;
|
|
120
|
+
children?: ReactNode;
|
|
121
|
+
}
|
|
122
|
+
export interface ConsumerProps<T> {
|
|
123
|
+
children: (value: T) => ReactNode;
|
|
124
|
+
}
|
|
125
|
+
export type Provider<T> = FunctionComponent<ProviderProps<T>>;
|
|
126
|
+
export type Consumer<T> = FunctionComponent<ConsumerProps<T>>;
|
|
127
|
+
export interface Context<T> {
|
|
128
|
+
Provider: Provider<T>;
|
|
129
|
+
Consumer: Consumer<T>;
|
|
130
|
+
displayName?: string;
|
|
131
|
+
}
|
|
132
|
+
export function createContext<T>(defaultValue: T): Context<T>;
|
|
133
|
+
export function useContext<T>(context: Context<T>): T;
|
|
134
|
+
|
|
135
|
+
export function useSyncExternalStore<T>(
|
|
136
|
+
subscribe: (onStoreChange: () => void) => () => void,
|
|
137
|
+
getSnapshot: () => T,
|
|
138
|
+
getServerSnapshot?: () => T,
|
|
139
|
+
): T;
|
|
140
|
+
|
|
141
|
+
export function useTransition(): [boolean, (callback: () => void) => void];
|
|
142
|
+
export function startTransition(scope: () => void): void;
|
|
143
|
+
export function useDeferredValue<T>(value: T): T;
|
|
144
|
+
export function useId(): string;
|
|
145
|
+
export function useDebugValue<T>(value?: T, format?: (value: T) => any): void;
|
|
146
|
+
export function use<T>(usable: Promise<T> | Context<T>): T;
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Element creation & utilities
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
export function createElement(
|
|
153
|
+
type: any,
|
|
154
|
+
props?: any,
|
|
155
|
+
...children: ReactNode[]
|
|
156
|
+
): ReactElement;
|
|
157
|
+
|
|
158
|
+
export const Fragment: ExoticComponent<{ children?: ReactNode }>;
|
|
159
|
+
|
|
160
|
+
export interface ForwardRefRenderFunction<T, P = {}> {
|
|
161
|
+
(props: P, ref: Ref<T>): ReactElement | null;
|
|
162
|
+
}
|
|
163
|
+
export function forwardRef<T, P = {}>(
|
|
164
|
+
render: ForwardRefRenderFunction<T, P>,
|
|
165
|
+
): FunctionComponent<P & { ref?: Ref<T> }>;
|
|
166
|
+
|
|
167
|
+
export function createRef<T = any>(): RefObject<T>;
|
|
168
|
+
|
|
169
|
+
export function memo<P extends object>(
|
|
170
|
+
Component: FunctionComponent<P>,
|
|
171
|
+
areEqual?: (prev: Readonly<P>, next: Readonly<P>) => boolean,
|
|
172
|
+
): FunctionComponent<P>;
|
|
173
|
+
|
|
174
|
+
export function lazy<T extends ComponentType<any>>(
|
|
175
|
+
loader: () => Promise<{ default: T }>,
|
|
176
|
+
): T;
|
|
177
|
+
|
|
178
|
+
export interface SuspenseProps {
|
|
179
|
+
children?: ReactNode;
|
|
180
|
+
fallback?: ReactNode;
|
|
181
|
+
}
|
|
182
|
+
export function Suspense(props: SuspenseProps): ReactElement | null;
|
|
183
|
+
|
|
184
|
+
export const Children: {
|
|
185
|
+
map<T>(
|
|
186
|
+
children: ReactNode,
|
|
187
|
+
fn: (child: ReactNode, index: number) => T,
|
|
188
|
+
): T[];
|
|
189
|
+
forEach(
|
|
190
|
+
children: ReactNode,
|
|
191
|
+
fn: (child: ReactNode, index: number) => void,
|
|
192
|
+
): void;
|
|
193
|
+
count(children: ReactNode): number;
|
|
194
|
+
only(children: ReactNode): ReactElement;
|
|
195
|
+
toArray(children: ReactNode): ReactNode[];
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function cloneElement(
|
|
199
|
+
element: ReactElement,
|
|
200
|
+
props?: any,
|
|
201
|
+
...children: ReactNode[]
|
|
202
|
+
): ReactElement;
|
|
203
|
+
|
|
204
|
+
export function createFactory(
|
|
205
|
+
type: any,
|
|
206
|
+
): (props?: any, ...children: ReactNode[]) => ReactElement;
|
|
207
|
+
|
|
208
|
+
export function isValidElement(object: unknown): object is ReactElement;
|
|
209
|
+
|
|
210
|
+
export function StrictMode(props: { children?: ReactNode }): ReactElement | null;
|
|
211
|
+
|
|
212
|
+
export function act(callback: () => void | Promise<void>): Promise<void>;
|
|
213
|
+
|
|
214
|
+
// Class components are shimmed but expose the familiar base-class surface.
|
|
215
|
+
export class Component<P = {}, S = {}> {
|
|
216
|
+
constructor(props: P);
|
|
217
|
+
props: Readonly<P> & { children?: ReactNode };
|
|
218
|
+
state: Readonly<S>;
|
|
219
|
+
setState(
|
|
220
|
+
state: Partial<S> | ((prev: Readonly<S>, props: Readonly<P>) => Partial<S>),
|
|
221
|
+
callback?: () => void,
|
|
222
|
+
): void;
|
|
223
|
+
forceUpdate(callback?: () => void): void;
|
|
224
|
+
render(): ReactNode;
|
|
225
|
+
}
|
|
226
|
+
export class PureComponent<P = {}, S = {}> extends Component<P, S> {}
|
|
227
|
+
|
|
228
|
+
export function unstable_flushUpdates(): void;
|
|
229
|
+
|
|
230
|
+
export const version: string;
|
|
231
|
+
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
// Default export — the React namespace object bundling the above.
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
declare const React: {
|
|
237
|
+
createElement: typeof createElement;
|
|
238
|
+
cloneElement: typeof cloneElement;
|
|
239
|
+
createFactory: typeof createFactory;
|
|
240
|
+
createRef: typeof createRef;
|
|
241
|
+
createContext: typeof createContext;
|
|
242
|
+
forwardRef: typeof forwardRef;
|
|
243
|
+
memo: typeof memo;
|
|
244
|
+
lazy: typeof lazy;
|
|
245
|
+
isValidElement: typeof isValidElement;
|
|
246
|
+
Children: typeof Children;
|
|
247
|
+
Fragment: typeof Fragment;
|
|
248
|
+
Suspense: typeof Suspense;
|
|
249
|
+
StrictMode: typeof StrictMode;
|
|
250
|
+
Component: typeof Component;
|
|
251
|
+
PureComponent: typeof PureComponent;
|
|
252
|
+
act: typeof act;
|
|
253
|
+
useState: typeof useState;
|
|
254
|
+
useReducer: typeof useReducer;
|
|
255
|
+
useMemo: typeof useMemo;
|
|
256
|
+
useCallback: typeof useCallback;
|
|
257
|
+
useRef: typeof useRef;
|
|
258
|
+
useEffect: typeof useEffect;
|
|
259
|
+
useLayoutEffect: typeof useLayoutEffect;
|
|
260
|
+
useInsertionEffect: typeof useInsertionEffect;
|
|
261
|
+
useImperativeHandle: typeof useImperativeHandle;
|
|
262
|
+
useContext: typeof useContext;
|
|
263
|
+
useSyncExternalStore: typeof useSyncExternalStore;
|
|
264
|
+
useTransition: typeof useTransition;
|
|
265
|
+
useDeferredValue: typeof useDeferredValue;
|
|
266
|
+
startTransition: typeof startTransition;
|
|
267
|
+
useId: typeof useId;
|
|
268
|
+
useDebugValue: typeof useDebugValue;
|
|
269
|
+
use: typeof use;
|
|
270
|
+
version: string;
|
|
271
|
+
};
|
|
272
|
+
export default React;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// what-react/jsx-dev-runtime — development JSX runtime type definitions.
|
|
2
|
+
// Mirrors jsx-runtime.d.ts; TS uses this under "jsx": "react-jsxdev".
|
|
3
|
+
|
|
4
|
+
import type { ReactElement, Key } from './index';
|
|
5
|
+
|
|
6
|
+
export { Fragment } from './index';
|
|
7
|
+
export { JSX } from './jsx-runtime';
|
|
8
|
+
|
|
9
|
+
export function jsx(type: any, props: any, key?: Key): ReactElement;
|
|
10
|
+
export function jsxs(type: any, props: any, key?: Key): ReactElement;
|
|
11
|
+
export function jsxDEV(
|
|
12
|
+
type: any,
|
|
13
|
+
props: any,
|
|
14
|
+
key?: Key,
|
|
15
|
+
isStaticChildren?: boolean,
|
|
16
|
+
source?: unknown,
|
|
17
|
+
self?: unknown,
|
|
18
|
+
): ReactElement;
|
package/jsx-runtime.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// what-react/jsx-runtime — JSX automatic-runtime type definitions.
|
|
2
|
+
//
|
|
3
|
+
// Enables type-checked JSX authoring against what-react with:
|
|
4
|
+
// "jsx": "react-jsx", "jsxImportSource": "what-react"
|
|
5
|
+
//
|
|
6
|
+
// The prop model is React's (camelCase events, `className`, object `style`,
|
|
7
|
+
// plain — not reactive — values), matching what-react's real React semantics.
|
|
8
|
+
// Common attributes are typed for autocomplete; an index signature keeps
|
|
9
|
+
// arbitrary/custom attributes and web-component tags valid.
|
|
10
|
+
|
|
11
|
+
import type { ReactElement, ReactNode, Ref, Key } from './index';
|
|
12
|
+
|
|
13
|
+
export { Fragment } from './index';
|
|
14
|
+
|
|
15
|
+
export function jsx(type: any, props: any, key?: Key): ReactElement;
|
|
16
|
+
export function jsxs(type: any, props: any, key?: Key): ReactElement;
|
|
17
|
+
|
|
18
|
+
type EventHandler<E extends Event = Event> = (
|
|
19
|
+
event: E & { currentTarget: EventTarget & Element; target: Element },
|
|
20
|
+
) => void;
|
|
21
|
+
|
|
22
|
+
interface DOMEventHandlers {
|
|
23
|
+
onClick?: EventHandler<MouseEvent>;
|
|
24
|
+
onDoubleClick?: EventHandler<MouseEvent>;
|
|
25
|
+
onMouseDown?: EventHandler<MouseEvent>;
|
|
26
|
+
onMouseUp?: EventHandler<MouseEvent>;
|
|
27
|
+
onMouseEnter?: EventHandler<MouseEvent>;
|
|
28
|
+
onMouseLeave?: EventHandler<MouseEvent>;
|
|
29
|
+
onMouseMove?: EventHandler<MouseEvent>;
|
|
30
|
+
onMouseOver?: EventHandler<MouseEvent>;
|
|
31
|
+
onMouseOut?: EventHandler<MouseEvent>;
|
|
32
|
+
onContextMenu?: EventHandler<MouseEvent>;
|
|
33
|
+
onInput?: EventHandler<InputEvent>;
|
|
34
|
+
onChange?: EventHandler<Event>;
|
|
35
|
+
onSubmit?: EventHandler<SubmitEvent>;
|
|
36
|
+
onReset?: EventHandler<Event>;
|
|
37
|
+
onKeyDown?: EventHandler<KeyboardEvent>;
|
|
38
|
+
onKeyUp?: EventHandler<KeyboardEvent>;
|
|
39
|
+
onKeyPress?: EventHandler<KeyboardEvent>;
|
|
40
|
+
onFocus?: EventHandler<FocusEvent>;
|
|
41
|
+
onBlur?: EventHandler<FocusEvent>;
|
|
42
|
+
onScroll?: EventHandler<Event>;
|
|
43
|
+
onWheel?: EventHandler<WheelEvent>;
|
|
44
|
+
onDragStart?: EventHandler<DragEvent>;
|
|
45
|
+
onDragOver?: EventHandler<DragEvent>;
|
|
46
|
+
onDrop?: EventHandler<DragEvent>;
|
|
47
|
+
onTouchStart?: EventHandler<TouchEvent>;
|
|
48
|
+
onTouchMove?: EventHandler<TouchEvent>;
|
|
49
|
+
onTouchEnd?: EventHandler<TouchEvent>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface HTMLAttributes extends DOMEventHandlers {
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
key?: Key;
|
|
55
|
+
ref?: Ref<any>;
|
|
56
|
+
dangerouslySetInnerHTML?: { __html: string };
|
|
57
|
+
|
|
58
|
+
className?: string;
|
|
59
|
+
class?: string;
|
|
60
|
+
id?: string;
|
|
61
|
+
style?: string | Record<string, string | number>;
|
|
62
|
+
title?: string;
|
|
63
|
+
role?: string;
|
|
64
|
+
slot?: string;
|
|
65
|
+
lang?: string;
|
|
66
|
+
dir?: string;
|
|
67
|
+
hidden?: boolean;
|
|
68
|
+
draggable?: boolean;
|
|
69
|
+
contentEditable?: boolean | 'true' | 'false' | 'inherit';
|
|
70
|
+
spellCheck?: boolean;
|
|
71
|
+
tabIndex?: number;
|
|
72
|
+
|
|
73
|
+
[dataAttr: `data-${string}`]: any;
|
|
74
|
+
[ariaAttr: `aria-${string}`]: any;
|
|
75
|
+
// what-react passes unknown attributes straight through — keep them valid.
|
|
76
|
+
[attr: string]: any;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface InputAttributes extends HTMLAttributes {
|
|
80
|
+
type?: string;
|
|
81
|
+
value?: string | number | ReadonlyArray<string>;
|
|
82
|
+
defaultValue?: string | number | ReadonlyArray<string>;
|
|
83
|
+
checked?: boolean;
|
|
84
|
+
defaultChecked?: boolean;
|
|
85
|
+
placeholder?: string;
|
|
86
|
+
disabled?: boolean;
|
|
87
|
+
readOnly?: boolean;
|
|
88
|
+
required?: boolean;
|
|
89
|
+
name?: string;
|
|
90
|
+
min?: string | number;
|
|
91
|
+
max?: string | number;
|
|
92
|
+
step?: string | number;
|
|
93
|
+
pattern?: string;
|
|
94
|
+
autoComplete?: string;
|
|
95
|
+
autoFocus?: boolean;
|
|
96
|
+
multiple?: boolean;
|
|
97
|
+
accept?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface AnchorAttributes extends HTMLAttributes {
|
|
101
|
+
href?: string;
|
|
102
|
+
target?: string;
|
|
103
|
+
rel?: string;
|
|
104
|
+
download?: string | boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface ImgAttributes extends HTMLAttributes {
|
|
108
|
+
src?: string;
|
|
109
|
+
srcSet?: string;
|
|
110
|
+
alt?: string;
|
|
111
|
+
width?: string | number;
|
|
112
|
+
height?: string | number;
|
|
113
|
+
loading?: 'eager' | 'lazy';
|
|
114
|
+
decoding?: 'async' | 'auto' | 'sync';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface ButtonAttributes extends HTMLAttributes {
|
|
118
|
+
type?: 'button' | 'submit' | 'reset';
|
|
119
|
+
disabled?: boolean;
|
|
120
|
+
name?: string;
|
|
121
|
+
value?: string | number;
|
|
122
|
+
form?: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface FormAttributes extends HTMLAttributes {
|
|
126
|
+
action?: string;
|
|
127
|
+
method?: string;
|
|
128
|
+
encType?: string;
|
|
129
|
+
noValidate?: boolean;
|
|
130
|
+
target?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface LabelAttributes extends HTMLAttributes {
|
|
134
|
+
htmlFor?: string;
|
|
135
|
+
for?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
interface OptionAttributes extends HTMLAttributes {
|
|
139
|
+
value?: string | number;
|
|
140
|
+
selected?: boolean;
|
|
141
|
+
disabled?: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface SelectAttributes extends HTMLAttributes {
|
|
145
|
+
value?: string | number | ReadonlyArray<string>;
|
|
146
|
+
defaultValue?: string | number | ReadonlyArray<string>;
|
|
147
|
+
name?: string;
|
|
148
|
+
disabled?: boolean;
|
|
149
|
+
required?: boolean;
|
|
150
|
+
multiple?: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface TextareaAttributes extends HTMLAttributes {
|
|
154
|
+
value?: string;
|
|
155
|
+
defaultValue?: string;
|
|
156
|
+
placeholder?: string;
|
|
157
|
+
rows?: number;
|
|
158
|
+
cols?: number;
|
|
159
|
+
disabled?: boolean;
|
|
160
|
+
readOnly?: boolean;
|
|
161
|
+
required?: boolean;
|
|
162
|
+
name?: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface MediaAttributes extends HTMLAttributes {
|
|
166
|
+
src?: string;
|
|
167
|
+
controls?: boolean;
|
|
168
|
+
autoPlay?: boolean;
|
|
169
|
+
loop?: boolean;
|
|
170
|
+
muted?: boolean;
|
|
171
|
+
poster?: string;
|
|
172
|
+
preload?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface SVGAttributes extends HTMLAttributes {
|
|
176
|
+
width?: string | number;
|
|
177
|
+
height?: string | number;
|
|
178
|
+
viewBox?: string;
|
|
179
|
+
fill?: string;
|
|
180
|
+
stroke?: string;
|
|
181
|
+
strokeWidth?: string | number;
|
|
182
|
+
x?: string | number;
|
|
183
|
+
y?: string | number;
|
|
184
|
+
cx?: string | number;
|
|
185
|
+
cy?: string | number;
|
|
186
|
+
r?: string | number;
|
|
187
|
+
d?: string;
|
|
188
|
+
points?: string;
|
|
189
|
+
transform?: string;
|
|
190
|
+
xmlns?: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export namespace JSX {
|
|
194
|
+
type Element = ReactElement;
|
|
195
|
+
interface ElementChildrenAttribute {
|
|
196
|
+
children: {};
|
|
197
|
+
}
|
|
198
|
+
interface IntrinsicAttributes {
|
|
199
|
+
key?: Key;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
interface IntrinsicElements {
|
|
203
|
+
a: AnchorAttributes;
|
|
204
|
+
img: ImgAttributes;
|
|
205
|
+
input: InputAttributes;
|
|
206
|
+
button: ButtonAttributes;
|
|
207
|
+
form: FormAttributes;
|
|
208
|
+
label: LabelAttributes;
|
|
209
|
+
option: OptionAttributes;
|
|
210
|
+
select: SelectAttributes;
|
|
211
|
+
textarea: TextareaAttributes;
|
|
212
|
+
video: MediaAttributes;
|
|
213
|
+
audio: MediaAttributes;
|
|
214
|
+
source: MediaAttributes;
|
|
215
|
+
|
|
216
|
+
div: HTMLAttributes;
|
|
217
|
+
span: HTMLAttributes;
|
|
218
|
+
p: HTMLAttributes;
|
|
219
|
+
section: HTMLAttributes;
|
|
220
|
+
article: HTMLAttributes;
|
|
221
|
+
header: HTMLAttributes;
|
|
222
|
+
footer: HTMLAttributes;
|
|
223
|
+
main: HTMLAttributes;
|
|
224
|
+
aside: HTMLAttributes;
|
|
225
|
+
nav: HTMLAttributes;
|
|
226
|
+
h1: HTMLAttributes;
|
|
227
|
+
h2: HTMLAttributes;
|
|
228
|
+
h3: HTMLAttributes;
|
|
229
|
+
h4: HTMLAttributes;
|
|
230
|
+
h5: HTMLAttributes;
|
|
231
|
+
h6: HTMLAttributes;
|
|
232
|
+
ul: HTMLAttributes;
|
|
233
|
+
ol: HTMLAttributes;
|
|
234
|
+
li: HTMLAttributes;
|
|
235
|
+
dl: HTMLAttributes;
|
|
236
|
+
dt: HTMLAttributes;
|
|
237
|
+
dd: HTMLAttributes;
|
|
238
|
+
table: HTMLAttributes;
|
|
239
|
+
thead: HTMLAttributes;
|
|
240
|
+
tbody: HTMLAttributes;
|
|
241
|
+
tfoot: HTMLAttributes;
|
|
242
|
+
tr: HTMLAttributes;
|
|
243
|
+
th: HTMLAttributes;
|
|
244
|
+
td: HTMLAttributes;
|
|
245
|
+
caption: HTMLAttributes;
|
|
246
|
+
colgroup: HTMLAttributes;
|
|
247
|
+
col: HTMLAttributes;
|
|
248
|
+
fieldset: HTMLAttributes;
|
|
249
|
+
legend: HTMLAttributes;
|
|
250
|
+
strong: HTMLAttributes;
|
|
251
|
+
em: HTMLAttributes;
|
|
252
|
+
b: HTMLAttributes;
|
|
253
|
+
i: HTMLAttributes;
|
|
254
|
+
u: HTMLAttributes;
|
|
255
|
+
small: HTMLAttributes;
|
|
256
|
+
mark: HTMLAttributes;
|
|
257
|
+
code: HTMLAttributes;
|
|
258
|
+
pre: HTMLAttributes;
|
|
259
|
+
kbd: HTMLAttributes;
|
|
260
|
+
blockquote: HTMLAttributes;
|
|
261
|
+
hr: HTMLAttributes;
|
|
262
|
+
br: HTMLAttributes;
|
|
263
|
+
figure: HTMLAttributes;
|
|
264
|
+
figcaption: HTMLAttributes;
|
|
265
|
+
details: HTMLAttributes;
|
|
266
|
+
summary: HTMLAttributes;
|
|
267
|
+
dialog: HTMLAttributes;
|
|
268
|
+
picture: HTMLAttributes;
|
|
269
|
+
iframe: HTMLAttributes;
|
|
270
|
+
canvas: HTMLAttributes;
|
|
271
|
+
template: HTMLAttributes;
|
|
272
|
+
time: HTMLAttributes;
|
|
273
|
+
progress: HTMLAttributes;
|
|
274
|
+
meter: HTMLAttributes;
|
|
275
|
+
output: HTMLAttributes;
|
|
276
|
+
datalist: HTMLAttributes;
|
|
277
|
+
optgroup: HTMLAttributes;
|
|
278
|
+
|
|
279
|
+
svg: SVGAttributes;
|
|
280
|
+
g: SVGAttributes;
|
|
281
|
+
path: SVGAttributes;
|
|
282
|
+
circle: SVGAttributes;
|
|
283
|
+
ellipse: SVGAttributes;
|
|
284
|
+
rect: SVGAttributes;
|
|
285
|
+
line: SVGAttributes;
|
|
286
|
+
polyline: SVGAttributes;
|
|
287
|
+
polygon: SVGAttributes;
|
|
288
|
+
text: SVGAttributes;
|
|
289
|
+
tspan: SVGAttributes;
|
|
290
|
+
defs: SVGAttributes;
|
|
291
|
+
linearGradient: SVGAttributes;
|
|
292
|
+
radialGradient: SVGAttributes;
|
|
293
|
+
stop: SVGAttributes;
|
|
294
|
+
clipPath: SVGAttributes;
|
|
295
|
+
use: SVGAttributes;
|
|
296
|
+
|
|
297
|
+
// Custom elements / web components remain valid.
|
|
298
|
+
[tagName: string]: HTMLAttributes;
|
|
299
|
+
}
|
|
300
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "what-react",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "React compatibility layer for What Framework — real React semantics (value hooks, re-renders, context) on a dedicated compat runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "src/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"test": "node --test 'test/*.test.js'"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|
|
12
|
-
".":
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"./
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"import": "./src/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./dom": {
|
|
18
|
+
"types": "./dom.d.ts",
|
|
19
|
+
"import": "./src/dom.js"
|
|
20
|
+
},
|
|
21
|
+
"./jsx-runtime": {
|
|
22
|
+
"types": "./jsx-runtime.d.ts",
|
|
23
|
+
"import": "./src/jsx-runtime.js"
|
|
24
|
+
},
|
|
25
|
+
"./jsx-dev-runtime": {
|
|
26
|
+
"types": "./jsx-dev-runtime.d.ts",
|
|
27
|
+
"import": "./src/jsx-dev-runtime.js"
|
|
28
|
+
},
|
|
29
|
+
"./vite": {
|
|
30
|
+
"types": "./vite.d.ts",
|
|
31
|
+
"import": "./src/vite-plugin.js"
|
|
32
|
+
}
|
|
17
33
|
},
|
|
18
34
|
"files": [
|
|
19
|
-
"src"
|
|
35
|
+
"src",
|
|
36
|
+
"index.d.ts",
|
|
37
|
+
"dom.d.ts",
|
|
38
|
+
"jsx-runtime.d.ts",
|
|
39
|
+
"jsx-dev-runtime.d.ts",
|
|
40
|
+
"vite.d.ts"
|
|
20
41
|
],
|
|
21
42
|
"keywords": [
|
|
22
43
|
"react",
|
|
@@ -27,7 +48,7 @@
|
|
|
27
48
|
"compatibility"
|
|
28
49
|
],
|
|
29
50
|
"peerDependencies": {
|
|
30
|
-
"what-core": "^0.11.
|
|
51
|
+
"what-core": "^0.11.3"
|
|
31
52
|
},
|
|
32
53
|
"author": "ZVN DEV (https://zvndev.com)",
|
|
33
54
|
"license": "MIT",
|
package/src/runtime.js
CHANGED
|
@@ -467,6 +467,38 @@ function mountRNode(v, kind, container, svg, owner) {
|
|
|
467
467
|
|
|
468
468
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
469
469
|
|
|
470
|
+
// A portal target may live inside an <svg> (recharts 3.x z-index layers are
|
|
471
|
+
// SVG <g> portal targets). Children portaled into an SVG container must be
|
|
472
|
+
// created in the SVG namespace, not HTML.
|
|
473
|
+
function targetSvg(target) {
|
|
474
|
+
return !!target && target.namespaceURI === SVG_NS && target.tagName !== 'foreignObject';
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// camelCase React SVG prop → correct kebab/colon SVG attribute name.
|
|
478
|
+
// Covers the presentation/text/clip attributes charting libs (recharts) emit.
|
|
479
|
+
const SVG_ATTR_MAP = {
|
|
480
|
+
strokeWidth: 'stroke-width', strokeDasharray: 'stroke-dasharray',
|
|
481
|
+
strokeDashoffset: 'stroke-dashoffset', strokeLinecap: 'stroke-linecap',
|
|
482
|
+
strokeLinejoin: 'stroke-linejoin', strokeMiterlimit: 'stroke-miterlimit',
|
|
483
|
+
strokeOpacity: 'stroke-opacity', fillOpacity: 'fill-opacity',
|
|
484
|
+
fillRule: 'fill-rule', clipPath: 'clip-path', clipRule: 'clip-rule',
|
|
485
|
+
stopColor: 'stop-color', stopOpacity: 'stop-opacity',
|
|
486
|
+
textAnchor: 'text-anchor', dominantBaseline: 'dominant-baseline',
|
|
487
|
+
alignmentBaseline: 'alignment-baseline', baselineShift: 'baseline-shift',
|
|
488
|
+
colorInterpolation: 'color-interpolation',
|
|
489
|
+
colorInterpolationFilters: 'color-interpolation-filters',
|
|
490
|
+
floodColor: 'flood-color', floodOpacity: 'flood-opacity',
|
|
491
|
+
letterSpacing: 'letter-spacing', wordSpacing: 'word-spacing',
|
|
492
|
+
pointerEvents: 'pointer-events', shapeRendering: 'shape-rendering',
|
|
493
|
+
vectorEffect: 'vector-effect', paintOrder: 'paint-order',
|
|
494
|
+
markerStart: 'marker-start', markerMid: 'marker-mid', markerEnd: 'marker-end',
|
|
495
|
+
// Font + rendering attrs recharts emits on <text>/axis/tick/legend elements.
|
|
496
|
+
fontSize: 'font-size', fontFamily: 'font-family', fontWeight: 'font-weight',
|
|
497
|
+
fontStyle: 'font-style', fontVariant: 'font-variant', fontStretch: 'font-stretch',
|
|
498
|
+
textRendering: 'text-rendering', imageRendering: 'image-rendering',
|
|
499
|
+
writingMode: 'writing-mode', lightingColor: 'lighting-color',
|
|
500
|
+
};
|
|
501
|
+
|
|
470
502
|
function mountElement(v, container, svg, owner) {
|
|
471
503
|
const tag = v.tag;
|
|
472
504
|
const childSvg = (svg || tag === 'svg') && tag !== 'foreignObject';
|
|
@@ -551,7 +583,7 @@ function mountPortal(v, container, owner) {
|
|
|
551
583
|
console.warn('[what-react] createPortal: target container not found');
|
|
552
584
|
return rn;
|
|
553
585
|
}
|
|
554
|
-
rn.children = patchChildren(target, [], normalizeChildren(v.children), null,
|
|
586
|
+
rn.children = patchChildren(target, [], normalizeChildren(v.children), null, targetSvg(target), owner);
|
|
555
587
|
return rn;
|
|
556
588
|
}
|
|
557
589
|
|
|
@@ -705,13 +737,13 @@ function patchPortal(rn, v, owner) {
|
|
|
705
737
|
const target = v.props && v.props.container;
|
|
706
738
|
if (target === rn.container) {
|
|
707
739
|
if (target) {
|
|
708
|
-
rn.children = patchChildren(target, rn.children, normalizeChildren(v.children), null,
|
|
740
|
+
rn.children = patchChildren(target, rn.children, normalizeChildren(v.children), null, targetSvg(target), owner);
|
|
709
741
|
}
|
|
710
742
|
} else {
|
|
711
743
|
for (const child of rn.children) unmountRNode(child, true);
|
|
712
744
|
rn.container = target || null;
|
|
713
745
|
rn.children = target
|
|
714
|
-
? patchChildren(target, [], normalizeChildren(v.children), null,
|
|
746
|
+
? patchChildren(target, [], normalizeChildren(v.children), null, targetSvg(target), owner)
|
|
715
747
|
: [];
|
|
716
748
|
}
|
|
717
749
|
rn.vnode = v;
|
|
@@ -1130,8 +1162,16 @@ export function setProperty(el, name, value, oldValue, svg) {
|
|
|
1130
1162
|
el.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value);
|
|
1131
1163
|
return;
|
|
1132
1164
|
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1165
|
+
// React accepts camelCase SVG presentation props (strokeWidth, fontSize, …)
|
|
1166
|
+
// and the spec expects kebab-case attribute names. Unlike HTML elements,
|
|
1167
|
+
// SVG-namespaced elements preserve the exact case passed to setAttribute —
|
|
1168
|
+
// so "strokeWidth" stays "strokeWidth", not "strokewidth". That camelCase
|
|
1169
|
+
// name is not a valid SVG presentation attribute, so the renderer silently
|
|
1170
|
+
// ignores it. Map the known ones to their correct kebab-case equivalents.
|
|
1171
|
+
const mapped = SVG_ATTR_MAP[name];
|
|
1172
|
+
const attr = mapped || name;
|
|
1173
|
+
if (value == null || value === false) el.removeAttribute(attr);
|
|
1174
|
+
else el.setAttribute(attr, value === true ? '' : value);
|
|
1135
1175
|
return;
|
|
1136
1176
|
}
|
|
1137
1177
|
|
package/vite.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// what-react/vite — Vite plugin that aliases `react`/`react-dom` to what-react
|
|
2
|
+
// and keeps installed React packages out of pre-bundling (src/vite-plugin.js).
|
|
3
|
+
|
|
4
|
+
export interface ReactCompatOptions {
|
|
5
|
+
/** Additional packages to exclude from Vite's dependency pre-bundling. */
|
|
6
|
+
exclude?: string[];
|
|
7
|
+
/** Auto-detect installed React packages to exclude. Defaults to true. */
|
|
8
|
+
autoDetect?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Structural Vite plugin shape — assignable to Vite's `PluginOption` without
|
|
12
|
+
// taking a hard type dependency on `vite`.
|
|
13
|
+
export interface ReactCompatPlugin {
|
|
14
|
+
name: string;
|
|
15
|
+
enforce?: 'pre' | 'post';
|
|
16
|
+
[hook: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function reactCompat(options?: ReactCompatOptions): ReactCompatPlugin;
|
|
20
|
+
|
|
21
|
+
export default reactCompat;
|