@tanstack/redact 0.0.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/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +7 -0
- package/dist/core/internal.d.ts +76 -0
- package/dist/core/internal.js +59 -0
- package/dist/core/internal.js.map +7 -0
- package/dist/core/types.d.ts +21 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +7 -0
- package/dist/dom/_all.d.ts +17 -0
- package/dist/dom/_all.js +51 -0
- package/dist/dom/_all.js.map +7 -0
- package/dist/dom/client.d.ts +3 -0
- package/dist/dom/client.js +8 -0
- package/dist/dom/client.js.map +7 -0
- package/dist/dom/dispatcher.d.ts +20 -0
- package/dist/dom/dispatcher.js +267 -0
- package/dist/dom/dispatcher.js.map +7 -0
- package/dist/dom/dom.d.ts +10 -0
- package/dist/dom/dom.js +262 -0
- package/dist/dom/dom.js.map +7 -0
- package/dist/dom/event-replay.d.ts +13 -0
- package/dist/dom/event-replay.js +46 -0
- package/dist/dom/event-replay.js.map +7 -0
- package/dist/dom/features/class/full.d.ts +1 -0
- package/dist/dom/features/class/full.js +91 -0
- package/dist/dom/features/class/full.js.map +7 -0
- package/dist/dom/features/class/index.d.ts +1 -0
- package/dist/dom/features/class/index.js +3 -0
- package/dist/dom/features/class/index.js.map +7 -0
- package/dist/dom/features/class/stub.d.ts +1 -0
- package/dist/dom/features/class/stub.js +50 -0
- package/dist/dom/features/class/stub.js.map +7 -0
- package/dist/dom/features/context/full.d.ts +1 -0
- package/dist/dom/features/context/full.js +49 -0
- package/dist/dom/features/context/full.js.map +7 -0
- package/dist/dom/features/context/index.d.ts +1 -0
- package/dist/dom/features/context/index.js +3 -0
- package/dist/dom/features/context/index.js.map +7 -0
- package/dist/dom/features/context/stub.d.ts +1 -0
- package/dist/dom/features/context/stub.js +22 -0
- package/dist/dom/features/context/stub.js.map +7 -0
- package/dist/dom/features/forward-ref/full.d.ts +1 -0
- package/dist/dom/features/forward-ref/full.js +51 -0
- package/dist/dom/features/forward-ref/full.js.map +7 -0
- package/dist/dom/features/forward-ref/index.d.ts +1 -0
- package/dist/dom/features/forward-ref/index.js +3 -0
- package/dist/dom/features/forward-ref/index.js.map +7 -0
- package/dist/dom/features/forward-ref/stub.d.ts +1 -0
- package/dist/dom/features/forward-ref/stub.js +22 -0
- package/dist/dom/features/forward-ref/stub.js.map +7 -0
- package/dist/dom/features/hydration/full.d.ts +61 -0
- package/dist/dom/features/hydration/full.js +264 -0
- package/dist/dom/features/hydration/full.js.map +7 -0
- package/dist/dom/features/hydration/index.d.ts +1 -0
- package/dist/dom/features/hydration/index.js +3 -0
- package/dist/dom/features/hydration/index.js.map +7 -0
- package/dist/dom/features/hydration/stub.d.ts +28 -0
- package/dist/dom/features/hydration/stub.js +66 -0
- package/dist/dom/features/hydration/stub.js.map +7 -0
- package/dist/dom/features/index.d.ts +7 -0
- package/dist/dom/features/index.js +9 -0
- package/dist/dom/features/index.js.map +7 -0
- package/dist/dom/features/lazy/full.d.ts +1 -0
- package/dist/dom/features/lazy/full.js +78 -0
- package/dist/dom/features/lazy/full.js.map +7 -0
- package/dist/dom/features/lazy/index.d.ts +1 -0
- package/dist/dom/features/lazy/index.js +3 -0
- package/dist/dom/features/lazy/index.js.map +7 -0
- package/dist/dom/features/lazy/stub.d.ts +1 -0
- package/dist/dom/features/lazy/stub.js +36 -0
- package/dist/dom/features/lazy/stub.js.map +7 -0
- package/dist/dom/features/memo/full.d.ts +1 -0
- package/dist/dom/features/memo/full.js +59 -0
- package/dist/dom/features/memo/full.js.map +7 -0
- package/dist/dom/features/memo/index.d.ts +1 -0
- package/dist/dom/features/memo/index.js +3 -0
- package/dist/dom/features/memo/index.js.map +7 -0
- package/dist/dom/features/memo/stub.d.ts +1 -0
- package/dist/dom/features/memo/stub.js +36 -0
- package/dist/dom/features/memo/stub.js.map +7 -0
- package/dist/dom/features/portal/full.d.ts +1 -0
- package/dist/dom/features/portal/full.js +19 -0
- package/dist/dom/features/portal/full.js.map +7 -0
- package/dist/dom/features/portal/index.d.ts +1 -0
- package/dist/dom/features/portal/index.js +3 -0
- package/dist/dom/features/portal/index.js.map +7 -0
- package/dist/dom/features/portal/stub.d.ts +1 -0
- package/dist/dom/features/portal/stub.js +7 -0
- package/dist/dom/features/portal/stub.js.map +7 -0
- package/dist/dom/features/suspense/full.d.ts +1 -0
- package/dist/dom/features/suspense/full.js +146 -0
- package/dist/dom/features/suspense/full.js.map +7 -0
- package/dist/dom/features/suspense/index.d.ts +1 -0
- package/dist/dom/features/suspense/index.js +3 -0
- package/dist/dom/features/suspense/index.js.map +7 -0
- package/dist/dom/features/suspense/stub.d.ts +1 -0
- package/dist/dom/features/suspense/stub.js +6 -0
- package/dist/dom/features/suspense/stub.js.map +7 -0
- package/dist/dom/index.d.ts +25 -0
- package/dist/dom/index.js +45 -0
- package/dist/dom/index.js.map +7 -0
- package/dist/dom/portal.d.ts +2 -0
- package/dist/dom/portal.js +15 -0
- package/dist/dom/portal.js.map +7 -0
- package/dist/dom/reconcile.d.ts +40 -0
- package/dist/dom/reconcile.js +795 -0
- package/dist/dom/reconcile.js.map +7 -0
- package/dist/dom/root.d.ts +15 -0
- package/dist/dom/root.js +85 -0
- package/dist/dom/root.js.map +7 -0
- package/dist/dom/test-utils.d.ts +1 -0
- package/dist/dom/test-utils.js +10 -0
- package/dist/dom/test-utils.js.map +7 -0
- package/dist/react/children.d.ts +8 -0
- package/dist/react/children.js +75 -0
- package/dist/react/children.js.map +7 -0
- package/dist/react/class.d.ts +31 -0
- package/dist/react/class.js +40 -0
- package/dist/react/class.js.map +7 -0
- package/dist/react/context.d.ts +27 -0
- package/dist/react/context.js +31 -0
- package/dist/react/context.js.map +7 -0
- package/dist/react/element.d.ts +10 -0
- package/dist/react/element.js +64 -0
- package/dist/react/element.js.map +7 -0
- package/dist/react/hooks.d.ts +37 -0
- package/dist/react/hooks.js +146 -0
- package/dist/react/hooks.js.map +7 -0
- package/dist/react/index.d.ts +76 -0
- package/dist/react/index.js +187 -0
- package/dist/react/index.js.map +7 -0
- package/dist/react/jsx-runtime.d.ts +5 -0
- package/dist/react/jsx-runtime.js +21 -0
- package/dist/react/jsx-runtime.js.map +7 -0
- package/dist/react/memo.d.ts +29 -0
- package/dist/react/memo.js +47 -0
- package/dist/react/memo.js.map +7 -0
- package/dist/react/portal.d.ts +1 -0
- package/dist/react/portal.js +6 -0
- package/dist/react/portal.js.map +7 -0
- package/dist/react/shared-internals.d.ts +33 -0
- package/dist/react/shared-internals.js +29 -0
- package/dist/react/shared-internals.js.map +7 -0
- package/dist/react/suspense.d.ts +15 -0
- package/dist/react/suspense.js +16 -0
- package/dist/react/suspense.js.map +7 -0
- package/dist/scheduler/index.d.ts +44 -0
- package/dist/scheduler/index.js +109 -0
- package/dist/scheduler/index.js.map +7 -0
- package/dist/server/bootstrap-script.d.ts +22 -0
- package/dist/server/bootstrap-script.js +16 -0
- package/dist/server/bootstrap-script.js.map +7 -0
- package/dist/server/dispatcher.d.ts +37 -0
- package/dist/server/dispatcher.js +140 -0
- package/dist/server/dispatcher.js.map +7 -0
- package/dist/server/escape.d.ts +7 -0
- package/dist/server/escape.js +159 -0
- package/dist/server/escape.js.map +7 -0
- package/dist/server/index.d.ts +16 -0
- package/dist/server/index.js +26 -0
- package/dist/server/index.js.map +7 -0
- package/dist/server/renderToString.d.ts +7 -0
- package/dist/server/renderToString.js +29 -0
- package/dist/server/renderToString.js.map +7 -0
- package/dist/server/stream.d.ts +40 -0
- package/dist/server/stream.js +200 -0
- package/dist/server/stream.js.map +7 -0
- package/dist/server/walk.d.ts +33 -0
- package/dist/server/walk.js +298 -0
- package/dist/server/walk.js.map +7 -0
- package/dist/vite/index.d.ts +96 -0
- package/dist/vite/index.js +217 -0
- package/dist/vite/index.js.map +7 -0
- package/package.json +83 -0
- package/src/core/index.ts +2 -0
- package/src/core/internal.ts +107 -0
- package/src/core/types.ts +36 -0
- package/src/dom/_all.ts +54 -0
- package/src/dom/client.ts +4 -0
- package/src/dom/dispatcher.ts +318 -0
- package/src/dom/dom.ts +316 -0
- package/src/dom/event-replay.ts +55 -0
- package/src/dom/features/class/full.ts +104 -0
- package/src/dom/features/class/index.ts +1 -0
- package/src/dom/features/class/stub.ts +65 -0
- package/src/dom/features/context/full.ts +57 -0
- package/src/dom/features/context/index.ts +1 -0
- package/src/dom/features/context/stub.ts +32 -0
- package/src/dom/features/forward-ref/full.ts +54 -0
- package/src/dom/features/forward-ref/index.ts +1 -0
- package/src/dom/features/forward-ref/stub.ts +28 -0
- package/src/dom/features/hydration/full.ts +345 -0
- package/src/dom/features/hydration/index.ts +1 -0
- package/src/dom/features/hydration/stub.ts +72 -0
- package/src/dom/features/index.ts +11 -0
- package/src/dom/features/lazy/full.ts +98 -0
- package/src/dom/features/lazy/index.ts +1 -0
- package/src/dom/features/lazy/stub.ts +45 -0
- package/src/dom/features/memo/full.ts +74 -0
- package/src/dom/features/memo/index.ts +1 -0
- package/src/dom/features/memo/stub.ts +42 -0
- package/src/dom/features/portal/full.ts +22 -0
- package/src/dom/features/portal/index.ts +1 -0
- package/src/dom/features/portal/stub.ts +11 -0
- package/src/dom/features/suspense/full.ts +191 -0
- package/src/dom/features/suspense/index.ts +1 -0
- package/src/dom/features/suspense/stub.ts +12 -0
- package/src/dom/index.ts +33 -0
- package/src/dom/portal.ts +16 -0
- package/src/dom/reconcile.ts +1169 -0
- package/src/dom/root.ts +107 -0
- package/src/dom/test-utils.ts +6 -0
- package/src/react/children.ts +85 -0
- package/src/react/class.ts +56 -0
- package/src/react/context.ts +50 -0
- package/src/react/element.ts +80 -0
- package/src/react/hooks.ts +190 -0
- package/src/react/index.ts +132 -0
- package/src/react/jsx-runtime.ts +16 -0
- package/src/react/memo.ts +45 -0
- package/src/react/portal.ts +1 -0
- package/src/react/shared-internals.ts +79 -0
- package/src/react/suspense.ts +18 -0
- package/src/scheduler/index.ts +124 -0
- package/src/server/bootstrap-script.ts +52 -0
- package/src/server/dispatcher.ts +158 -0
- package/src/server/escape.ts +187 -0
- package/src/server/index.ts +26 -0
- package/src/server/renderToString.ts +33 -0
- package/src/server/stream.ts +302 -0
- package/src/server/walk.ts +448 -0
- package/src/vite/index.ts +401 -0
package/src/dom/root.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { FiberTag, createFiber, type FiberRoot, type ReactNode } from '../core'
|
|
2
|
+
import { renderRoot, flushSyncWork, batchedUpdates } from './reconcile'
|
|
3
|
+
import {
|
|
4
|
+
beginHydration,
|
|
5
|
+
endHydration,
|
|
6
|
+
drainReplayQueue,
|
|
7
|
+
installHydrationScrollGuard,
|
|
8
|
+
} from './features/hydration'
|
|
9
|
+
|
|
10
|
+
export interface RootOptions {
|
|
11
|
+
identifierPrefix?: string
|
|
12
|
+
onRecoverableError?: (error: unknown) => void
|
|
13
|
+
onCaughtError?: (error: unknown) => void
|
|
14
|
+
onUncaughtError?: (error: unknown) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface Root {
|
|
18
|
+
render(children: ReactNode): void
|
|
19
|
+
unmount(): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createRoot(container: Element | DocumentFragment, options: RootOptions = {}): Root {
|
|
23
|
+
const rootFiber = createFiber(FiberTag.Root, null, null)
|
|
24
|
+
rootFiber.dom = container
|
|
25
|
+
const root: FiberRoot = {
|
|
26
|
+
container,
|
|
27
|
+
current: rootFiber,
|
|
28
|
+
pending: new Set(),
|
|
29
|
+
scheduled: false,
|
|
30
|
+
onRecoverableError: options.onRecoverableError,
|
|
31
|
+
onCaughtError: options.onCaughtError,
|
|
32
|
+
onUncaughtError: options.onUncaughtError,
|
|
33
|
+
identifierPrefix: options.identifierPrefix ?? ':r',
|
|
34
|
+
hydrating: false,
|
|
35
|
+
}
|
|
36
|
+
rootFiber.root = root
|
|
37
|
+
rootFiber.stateNode = container
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
render(children) {
|
|
41
|
+
flushSyncWork(() => {
|
|
42
|
+
renderRoot(root, children)
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
unmount() {
|
|
46
|
+
flushSyncWork(() => {
|
|
47
|
+
renderRoot(root, null)
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function hydrateRoot(
|
|
54
|
+
container: Element | Document,
|
|
55
|
+
initialChildren: ReactNode,
|
|
56
|
+
options: RootOptions = {},
|
|
57
|
+
): Root {
|
|
58
|
+
// `container` may be the Document when the React tree renders <html>...</html>
|
|
59
|
+
// (e.g. TanStack Start's default client entry). In that case we adopt
|
|
60
|
+
// documentElement as a CHILD of the root, not as the root itself — otherwise
|
|
61
|
+
// we'd try to render <html> inside <html>.
|
|
62
|
+
const target = container as any as Element | Document
|
|
63
|
+
const rootFiber = createFiber(FiberTag.Root, null, null)
|
|
64
|
+
rootFiber.dom = target as unknown as Node
|
|
65
|
+
const root: FiberRoot = {
|
|
66
|
+
container: target as any,
|
|
67
|
+
current: rootFiber,
|
|
68
|
+
pending: new Set(),
|
|
69
|
+
scheduled: false,
|
|
70
|
+
onRecoverableError: options.onRecoverableError,
|
|
71
|
+
onCaughtError: options.onCaughtError,
|
|
72
|
+
onUncaughtError: options.onUncaughtError,
|
|
73
|
+
identifierPrefix: options.identifierPrefix ?? ':r',
|
|
74
|
+
hydrating: false,
|
|
75
|
+
}
|
|
76
|
+
rootFiber.root = root
|
|
77
|
+
rootFiber.stateNode = target
|
|
78
|
+
|
|
79
|
+
// Preserve the user's scroll position across hydration (see feature impl
|
|
80
|
+
// for the details). No-op in SSR; no-op in the stub.
|
|
81
|
+
installHydrationScrollGuard()
|
|
82
|
+
|
|
83
|
+
beginHydration(root)
|
|
84
|
+
try {
|
|
85
|
+
flushSyncWork(() => {
|
|
86
|
+
renderRoot(root, initialChildren)
|
|
87
|
+
})
|
|
88
|
+
} finally {
|
|
89
|
+
endHydration(root)
|
|
90
|
+
}
|
|
91
|
+
drainReplayQueue()
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
render(children) {
|
|
95
|
+
flushSyncWork(() => {
|
|
96
|
+
renderRoot(root, children)
|
|
97
|
+
})
|
|
98
|
+
},
|
|
99
|
+
unmount() {
|
|
100
|
+
flushSyncWork(() => {
|
|
101
|
+
renderRoot(root, null)
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { flushSyncWork as flushSync, batchedUpdates }
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isValidElement, cloneElement } from './element'
|
|
2
|
+
import type { ReactNode, ReactElement } from '../core'
|
|
3
|
+
|
|
4
|
+
function flatten(node: ReactNode, out: any[], prefix: string): void {
|
|
5
|
+
if (node == null || typeof node === 'boolean') return
|
|
6
|
+
if (Array.isArray(node)) {
|
|
7
|
+
for (let i = 0; i < node.length; i++) flatten(node[i], out, prefix + '.' + i)
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
out.push(node)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getKey(node: any, index: number, prefix: string): string {
|
|
14
|
+
if (isValidElement(node) && node.key != null) return prefix + '$' + node.key
|
|
15
|
+
return prefix + ':' + index
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function mapChildren(
|
|
19
|
+
children: ReactNode,
|
|
20
|
+
fn: (child: ReactNode, index: number) => any,
|
|
21
|
+
prefix = '',
|
|
22
|
+
): any[] {
|
|
23
|
+
const flat: any[] = []
|
|
24
|
+
flatten(children, flat, prefix)
|
|
25
|
+
const out: any[] = []
|
|
26
|
+
for (let i = 0; i < flat.length; i++) {
|
|
27
|
+
const child = flat[i]
|
|
28
|
+
const mapped = fn(child, i)
|
|
29
|
+
if (mapped == null) continue
|
|
30
|
+
if (Array.isArray(mapped)) {
|
|
31
|
+
for (let j = 0; j < mapped.length; j++) {
|
|
32
|
+
const m = mapped[j]
|
|
33
|
+
if (m == null) continue
|
|
34
|
+
out.push(
|
|
35
|
+
isValidElement(m) && m.key == null
|
|
36
|
+
? cloneElement(m as ReactElement, { key: getKey(child, i, prefix) + '/' + j })
|
|
37
|
+
: m,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
out.push(
|
|
42
|
+
isValidElement(mapped) && mapped.key == null
|
|
43
|
+
? cloneElement(mapped as ReactElement, { key: getKey(child, i, prefix) })
|
|
44
|
+
: mapped,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const Children = {
|
|
52
|
+
map(children: ReactNode, fn: (child: ReactNode, index: number) => any): any[] | null {
|
|
53
|
+
if (children == null) return null
|
|
54
|
+
return mapChildren(children, fn)
|
|
55
|
+
},
|
|
56
|
+
forEach(children: ReactNode, fn: (child: ReactNode, index: number) => void): void {
|
|
57
|
+
if (children == null) return
|
|
58
|
+
mapChildren(children, (c, i) => {
|
|
59
|
+
fn(c, i)
|
|
60
|
+
return null
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
count(children: ReactNode): number {
|
|
64
|
+
let n = 0
|
|
65
|
+
const flat: any[] = []
|
|
66
|
+
flatten(children, flat, '')
|
|
67
|
+
for (let i = 0; i < flat.length; i++) n++
|
|
68
|
+
return n
|
|
69
|
+
},
|
|
70
|
+
toArray(children: ReactNode): any[] {
|
|
71
|
+
const flat: any[] = []
|
|
72
|
+
flatten(children, flat, '')
|
|
73
|
+
return flat.map((c, i) =>
|
|
74
|
+
isValidElement(c) && c.key == null
|
|
75
|
+
? cloneElement(c as ReactElement, { key: '' + i })
|
|
76
|
+
: c,
|
|
77
|
+
)
|
|
78
|
+
},
|
|
79
|
+
only(children: ReactNode): ReactElement {
|
|
80
|
+
if (!isValidElement(children)) {
|
|
81
|
+
throw new Error('Children.only expected a single React element.')
|
|
82
|
+
}
|
|
83
|
+
return children
|
|
84
|
+
},
|
|
85
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ReactNode } from '../core'
|
|
2
|
+
|
|
3
|
+
type SetStateCallback<S, P> =
|
|
4
|
+
| Partial<S>
|
|
5
|
+
| ((prev: S, props: P) => Partial<S> | null)
|
|
6
|
+
| null
|
|
7
|
+
|
|
8
|
+
export class Component<P = {}, S = {}> {
|
|
9
|
+
static contextType?: any
|
|
10
|
+
static getDerivedStateFromProps?(props: any, state: any): any
|
|
11
|
+
static getDerivedStateFromError?(error: any): any
|
|
12
|
+
static defaultProps?: any
|
|
13
|
+
static displayName?: string
|
|
14
|
+
|
|
15
|
+
props: P
|
|
16
|
+
state: S = {} as S
|
|
17
|
+
context: any
|
|
18
|
+
refs: Record<string, any> = {}
|
|
19
|
+
|
|
20
|
+
// Injected by reconciler
|
|
21
|
+
_fiber: any = null
|
|
22
|
+
_enqueueUpdate: ((updater: SetStateCallback<S, P>, cb?: () => void) => void) | null = null
|
|
23
|
+
_forceUpdate: ((cb?: () => void) => void) | null = null
|
|
24
|
+
|
|
25
|
+
constructor(props: P, context?: any) {
|
|
26
|
+
this.props = props
|
|
27
|
+
this.context = context
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setState(updater: SetStateCallback<S, P>, callback?: () => void): void {
|
|
31
|
+
if (!this._enqueueUpdate) {
|
|
32
|
+
throw new Error('Cannot call setState on an unmounted component.')
|
|
33
|
+
}
|
|
34
|
+
this._enqueueUpdate(updater, callback)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
forceUpdate(callback?: () => void): void {
|
|
38
|
+
if (!this._forceUpdate) return
|
|
39
|
+
this._forceUpdate(callback)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
render(): ReactNode {
|
|
43
|
+
throw new Error('Component subclass must implement render().')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
componentDidMount?(): void
|
|
47
|
+
componentDidUpdate?(prevProps: P, prevState: S, snapshot?: any): void
|
|
48
|
+
componentWillUnmount?(): void
|
|
49
|
+
shouldComponentUpdate?(nextProps: P, nextState: S, nextCtx: any): boolean
|
|
50
|
+
getSnapshotBeforeUpdate?(prevProps: P, prevState: S): any
|
|
51
|
+
componentDidCatch?(error: any, info: { componentStack: string }): void
|
|
52
|
+
}
|
|
53
|
+
;(Component.prototype as any).isReactComponent = {}
|
|
54
|
+
|
|
55
|
+
export class PureComponent<P = {}, S = {}> extends Component<P, S> {}
|
|
56
|
+
;(PureComponent.prototype as any).isPureReactComponent = true
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from '../core'
|
|
2
|
+
import { useContext } from './hooks'
|
|
3
|
+
|
|
4
|
+
export const REACT_CONTEXT_TYPE = Symbol.for('react.context')
|
|
5
|
+
export const REACT_PROVIDER_TYPE = Symbol.for('react.provider')
|
|
6
|
+
export const REACT_CONSUMER_TYPE = Symbol.for('react.consumer')
|
|
7
|
+
|
|
8
|
+
export interface Context<T> {
|
|
9
|
+
$$typeof: typeof REACT_CONTEXT_TYPE
|
|
10
|
+
_currentValue: T
|
|
11
|
+
Provider: ProviderExoticComponent<{ value: T; children?: ReactNode }>
|
|
12
|
+
Consumer: ConsumerExoticComponent<T>
|
|
13
|
+
displayName?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ProviderExoticComponent<P> {
|
|
17
|
+
$$typeof: typeof REACT_PROVIDER_TYPE
|
|
18
|
+
_context: Context<any>
|
|
19
|
+
(props: P): ReactElement
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ConsumerExoticComponent<T> {
|
|
23
|
+
$$typeof: typeof REACT_CONSUMER_TYPE
|
|
24
|
+
_context: Context<T>
|
|
25
|
+
(props: { children: (value: T) => ReactNode }): ReactElement
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createContext<T>(defaultValue: T): Context<T> {
|
|
29
|
+
const context: Context<T> = {
|
|
30
|
+
$$typeof: REACT_CONTEXT_TYPE,
|
|
31
|
+
_currentValue: defaultValue,
|
|
32
|
+
} as Context<T>
|
|
33
|
+
|
|
34
|
+
const Provider: any = function Provider(_props: any): any {
|
|
35
|
+
throw new Error('Provider components are handled by the renderer.')
|
|
36
|
+
}
|
|
37
|
+
Provider.$$typeof = REACT_PROVIDER_TYPE
|
|
38
|
+
Provider._context = context
|
|
39
|
+
|
|
40
|
+
const Consumer: any = function Consumer(props: { children: (v: T) => any }): any {
|
|
41
|
+
return props.children(useContext(context))
|
|
42
|
+
}
|
|
43
|
+
Consumer.$$typeof = REACT_CONSUMER_TYPE
|
|
44
|
+
Consumer._context = context
|
|
45
|
+
|
|
46
|
+
context.Provider = Provider
|
|
47
|
+
context.Consumer = Consumer
|
|
48
|
+
|
|
49
|
+
return context
|
|
50
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
REACT_ELEMENT_TYPE,
|
|
3
|
+
REACT_LEGACY_ELEMENT_TYPE,
|
|
4
|
+
REACT_FRAGMENT_TYPE,
|
|
5
|
+
type ReactElement,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from '../core'
|
|
8
|
+
|
|
9
|
+
export const Fragment = REACT_FRAGMENT_TYPE as unknown as (props: {
|
|
10
|
+
children?: ReactNode
|
|
11
|
+
}) => ReactElement
|
|
12
|
+
|
|
13
|
+
const RESERVED_PROPS: Record<string, 1> = { key: 1, ref: 1, __self: 1, __source: 1 }
|
|
14
|
+
|
|
15
|
+
export function createElement(
|
|
16
|
+
type: any,
|
|
17
|
+
config: Record<string, any> | null,
|
|
18
|
+
...children: ReactNode[]
|
|
19
|
+
): ReactElement {
|
|
20
|
+
let key: string | null = null
|
|
21
|
+
let ref: any = null
|
|
22
|
+
const props: Record<string, any> = {}
|
|
23
|
+
|
|
24
|
+
if (config != null) {
|
|
25
|
+
if (config.key !== undefined && config.key !== null) key = '' + config.key
|
|
26
|
+
if (config.ref !== undefined) ref = config.ref
|
|
27
|
+
for (const k in config) {
|
|
28
|
+
if (!RESERVED_PROPS[k] && Object.prototype.hasOwnProperty.call(config, k)) {
|
|
29
|
+
props[k] = config[k]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (children.length === 1) props.children = children[0]
|
|
35
|
+
else if (children.length > 1) props.children = children
|
|
36
|
+
|
|
37
|
+
if (type && type.defaultProps) {
|
|
38
|
+
const dp = type.defaultProps
|
|
39
|
+
for (const k in dp) {
|
|
40
|
+
if (props[k] === undefined) props[k] = dp[k]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref, props }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function cloneElement(
|
|
48
|
+
element: ReactElement,
|
|
49
|
+
config: Record<string, any> | null,
|
|
50
|
+
...children: ReactNode[]
|
|
51
|
+
): ReactElement {
|
|
52
|
+
let key = element.key
|
|
53
|
+
let ref = element.ref
|
|
54
|
+
const props = { ...element.props }
|
|
55
|
+
|
|
56
|
+
if (config != null) {
|
|
57
|
+
if (config.ref !== undefined) ref = config.ref
|
|
58
|
+
if (config.key !== undefined) key = '' + config.key
|
|
59
|
+
const defaultProps = element.type?.defaultProps
|
|
60
|
+
for (const k in config) {
|
|
61
|
+
if (RESERVED_PROPS[k] || !Object.prototype.hasOwnProperty.call(config, k)) continue
|
|
62
|
+
props[k] = config[k] === undefined && defaultProps ? defaultProps[k] : config[k]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (children.length === 1) props.children = children[0]
|
|
67
|
+
else if (children.length > 1) props.children = children
|
|
68
|
+
|
|
69
|
+
return { $$typeof: REACT_ELEMENT_TYPE, type: element.type, key, ref, props }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isValidElement(obj: any): obj is ReactElement {
|
|
73
|
+
if (typeof obj !== 'object' || obj === null) return false
|
|
74
|
+
const t = obj.$$typeof
|
|
75
|
+
return t === REACT_ELEMENT_TYPE || t === REACT_LEGACY_ELEMENT_TYPE
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createRef<T = any>() {
|
|
79
|
+
return { current: null as T | null }
|
|
80
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Dispatch,
|
|
3
|
+
SetStateAction,
|
|
4
|
+
EffectCallback,
|
|
5
|
+
DependencyList,
|
|
6
|
+
} from '../core'
|
|
7
|
+
import type { Context } from './context'
|
|
8
|
+
import { getDispatcher } from './shared-internals'
|
|
9
|
+
|
|
10
|
+
export function useState<S>(initial: S | (() => S)): [S, Dispatch<SetStateAction<S>>] {
|
|
11
|
+
return getDispatcher().useState(initial)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useReducer<S, A>(
|
|
15
|
+
reducer: (s: S, a: A) => S,
|
|
16
|
+
initial: any,
|
|
17
|
+
init?: (a: any) => S,
|
|
18
|
+
): [S, Dispatch<A>] {
|
|
19
|
+
return getDispatcher().useReducer(reducer, initial, init)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useEffect(create: EffectCallback, deps?: DependencyList): void {
|
|
23
|
+
getDispatcher().useEffect(create, deps)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useLayoutEffect(create: EffectCallback, deps?: DependencyList): void {
|
|
27
|
+
getDispatcher().useLayoutEffect(create, deps)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useInsertionEffect(create: EffectCallback, deps?: DependencyList): void {
|
|
31
|
+
getDispatcher().useInsertionEffect(create, deps)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useRef<T>(initial: T): { current: T }
|
|
35
|
+
export function useRef<T>(initial: T | null): { current: T | null }
|
|
36
|
+
export function useRef<T = undefined>(): { current: T | undefined }
|
|
37
|
+
export function useRef(initial?: any): { current: any } {
|
|
38
|
+
return getDispatcher().useRef(initial)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useMemo<T>(factory: () => T, deps?: DependencyList): T {
|
|
42
|
+
return getDispatcher().useMemo(factory, deps)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function useCallback<T extends Function>(fn: T, deps?: DependencyList): T {
|
|
46
|
+
return getDispatcher().useCallback(fn, deps)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useContext<T>(ctx: Context<T>): T {
|
|
50
|
+
return getDispatcher().useContext(ctx)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useImperativeHandle<T>(
|
|
54
|
+
ref: any,
|
|
55
|
+
factory: () => T,
|
|
56
|
+
deps?: DependencyList,
|
|
57
|
+
): void {
|
|
58
|
+
getDispatcher().useImperativeHandle(ref, factory, deps)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useDebugValue<T>(value: T, formatter?: (v: T) => any): void {
|
|
62
|
+
getDispatcher().useDebugValue(value, formatter)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function useId(): string {
|
|
66
|
+
return getDispatcher().useId()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function useTransition(): [boolean, (fn: () => void) => void] {
|
|
70
|
+
return getDispatcher().useTransition()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function useDeferredValue<T>(v: T): T {
|
|
74
|
+
return getDispatcher().useDeferredValue(v)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function useSyncExternalStore<T>(
|
|
78
|
+
subscribe: (cb: () => void) => () => void,
|
|
79
|
+
getSnapshot: () => T,
|
|
80
|
+
getServerSnapshot?: () => T,
|
|
81
|
+
): T {
|
|
82
|
+
return getDispatcher().useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function use<T>(resource: any): T {
|
|
86
|
+
return getDispatcher().use(resource)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function startTransition(fn: () => void): void {
|
|
90
|
+
fn()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function useActionState<S, P>(
|
|
94
|
+
_action: (state: Awaited<S>, payload: P) => S | Promise<S>,
|
|
95
|
+
initial: Awaited<S>,
|
|
96
|
+
): [Awaited<S>, (payload: P) => void, boolean] {
|
|
97
|
+
return [initial, () => {}, false]
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function useFormStatus() {
|
|
101
|
+
return { pending: false, data: null, method: null, action: null }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function useOptimistic<S, A = S>(
|
|
105
|
+
state: S,
|
|
106
|
+
_updateFn?: (s: S, a: A) => S,
|
|
107
|
+
): [S, (action: A) => void] {
|
|
108
|
+
return [state, () => {}]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Composed hook — returns a stable callback that always invokes the latest
|
|
112
|
+
// `fn`. The ref is updated in useInsertionEffect so any useLayoutEffect /
|
|
113
|
+
// useEffect reading ref.current in the next commit sees the fresh function.
|
|
114
|
+
export function useEffectEvent<Args extends unknown[], Return>(
|
|
115
|
+
fn: (...args: Args) => Return,
|
|
116
|
+
): (...args: Args) => Return {
|
|
117
|
+
const ref = useRef(fn)
|
|
118
|
+
useInsertionEffect(() => {
|
|
119
|
+
ref.current = fn
|
|
120
|
+
})
|
|
121
|
+
return useCallback(
|
|
122
|
+
((...args: Args) => ref.current(...args)) as (...args: Args) => Return,
|
|
123
|
+
[],
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// `useSyncExternalStoreWithSelector` — provided here so consumers (like
|
|
128
|
+
// @tanstack/react-store) that historically import from
|
|
129
|
+
// `use-sync-external-store/shim/with-selector` can be aliased to this
|
|
130
|
+
// package via the @tanstack/redact/vite plugin. The CJS shim is unsuitable
|
|
131
|
+
// for Cloudflare Workers (it does `var React = require('react')` which
|
|
132
|
+
// fails in workerd). Implementation matches React's reference impl —
|
|
133
|
+
// selector + isEqual gate to avoid re-renders when the selected slice is
|
|
134
|
+
// unchanged across snapshots.
|
|
135
|
+
export function useSyncExternalStoreWithSelector<Snapshot, Selection>(
|
|
136
|
+
subscribe: (cb: () => void) => () => void,
|
|
137
|
+
getSnapshot: () => Snapshot,
|
|
138
|
+
getServerSnapshot: (() => Snapshot) | undefined,
|
|
139
|
+
selector: (snapshot: Snapshot) => Selection,
|
|
140
|
+
isEqual?: (a: Selection, b: Selection) => boolean,
|
|
141
|
+
): Selection {
|
|
142
|
+
const instRef = useRef<{ hasValue: boolean; value: Selection | null } | null>(null)
|
|
143
|
+
let inst: { hasValue: boolean; value: Selection | null }
|
|
144
|
+
if (instRef.current === null) {
|
|
145
|
+
inst = { hasValue: false, value: null }
|
|
146
|
+
instRef.current = inst
|
|
147
|
+
} else {
|
|
148
|
+
inst = instRef.current
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const [getSelection, getServerSelection] = useMemo(() => {
|
|
152
|
+
let hasMemo = false
|
|
153
|
+
let memoizedSnapshot: Snapshot
|
|
154
|
+
let memoizedSelection: Selection
|
|
155
|
+
const memoizedSelector = (nextSnapshot: Snapshot): Selection => {
|
|
156
|
+
if (!hasMemo) {
|
|
157
|
+
hasMemo = true
|
|
158
|
+
memoizedSnapshot = nextSnapshot
|
|
159
|
+
const nextSelection = selector(nextSnapshot)
|
|
160
|
+
if (isEqual !== undefined && inst.hasValue) {
|
|
161
|
+
const currentSelection = inst.value as Selection
|
|
162
|
+
if (isEqual(currentSelection, nextSelection)) {
|
|
163
|
+
memoizedSelection = currentSelection
|
|
164
|
+
return currentSelection
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
memoizedSelection = nextSelection
|
|
168
|
+
return nextSelection
|
|
169
|
+
}
|
|
170
|
+
const prevSnapshot: Snapshot = memoizedSnapshot
|
|
171
|
+
const prevSelection: Selection = memoizedSelection
|
|
172
|
+
if (Object.is(prevSnapshot, nextSnapshot)) return prevSelection
|
|
173
|
+
const nextSelection = selector(nextSnapshot)
|
|
174
|
+
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) return prevSelection
|
|
175
|
+
memoizedSnapshot = nextSnapshot
|
|
176
|
+
memoizedSelection = nextSelection
|
|
177
|
+
return nextSelection
|
|
178
|
+
}
|
|
179
|
+
const get = () => memoizedSelector(getSnapshot())
|
|
180
|
+
const getServer =
|
|
181
|
+
getServerSnapshot === undefined ? undefined : () => memoizedSelector(getServerSnapshot())
|
|
182
|
+
return [get, getServer] as const
|
|
183
|
+
}, [getSnapshot, getServerSnapshot, selector, isEqual])
|
|
184
|
+
|
|
185
|
+
const value = useSyncExternalStore(subscribe, getSelection, getServerSelection)
|
|
186
|
+
useDebugValue(value)
|
|
187
|
+
inst.hasValue = true
|
|
188
|
+
inst.value = value
|
|
189
|
+
return value
|
|
190
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export { createElement, cloneElement, isValidElement, createRef, Fragment } from './element'
|
|
2
|
+
export {
|
|
3
|
+
useState,
|
|
4
|
+
useReducer,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useInsertionEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useMemo,
|
|
10
|
+
useCallback,
|
|
11
|
+
useContext,
|
|
12
|
+
useImperativeHandle,
|
|
13
|
+
useDebugValue,
|
|
14
|
+
useId,
|
|
15
|
+
useTransition,
|
|
16
|
+
useDeferredValue,
|
|
17
|
+
useSyncExternalStore,
|
|
18
|
+
useSyncExternalStoreWithSelector,
|
|
19
|
+
use,
|
|
20
|
+
useActionState,
|
|
21
|
+
useFormStatus,
|
|
22
|
+
useOptimistic,
|
|
23
|
+
useEffectEvent,
|
|
24
|
+
startTransition,
|
|
25
|
+
} from './hooks'
|
|
26
|
+
export {
|
|
27
|
+
createContext,
|
|
28
|
+
REACT_CONTEXT_TYPE,
|
|
29
|
+
REACT_PROVIDER_TYPE,
|
|
30
|
+
REACT_CONSUMER_TYPE,
|
|
31
|
+
type Context,
|
|
32
|
+
type ProviderExoticComponent,
|
|
33
|
+
type ConsumerExoticComponent,
|
|
34
|
+
} from './context'
|
|
35
|
+
export { Component, PureComponent } from './class'
|
|
36
|
+
export {
|
|
37
|
+
memo, forwardRef, lazy,
|
|
38
|
+
REACT_MEMO_TYPE,
|
|
39
|
+
REACT_FORWARD_REF_TYPE,
|
|
40
|
+
REACT_LAZY_TYPE,
|
|
41
|
+
} from './memo'
|
|
42
|
+
export {
|
|
43
|
+
Suspense, StrictMode, Profiler,
|
|
44
|
+
REACT_SUSPENSE_TYPE,
|
|
45
|
+
REACT_STRICT_MODE_TYPE,
|
|
46
|
+
REACT_PROFILER_TYPE,
|
|
47
|
+
} from './suspense'
|
|
48
|
+
export { REACT_PORTAL_TYPE } from './portal'
|
|
49
|
+
export { Children } from './children'
|
|
50
|
+
export { ReactSharedInternals } from './shared-internals'
|
|
51
|
+
|
|
52
|
+
// Stub exports
|
|
53
|
+
export const cache = <T extends Function>(fn: T): T => fn
|
|
54
|
+
export const act = async (fn: () => any) => {
|
|
55
|
+
const r = fn()
|
|
56
|
+
if (r && typeof r.then === 'function') await r
|
|
57
|
+
}
|
|
58
|
+
export function taintUniqueValue(_msg: string, _lifetime: any, _value: any): void {}
|
|
59
|
+
export function taintObjectReference(_msg: string, _object: any): void {}
|
|
60
|
+
|
|
61
|
+
export const version = '19.2.3'
|
|
62
|
+
|
|
63
|
+
// Default export for `import React from 'react'` usage
|
|
64
|
+
import { createElement, cloneElement, isValidElement, createRef, Fragment } from './element'
|
|
65
|
+
import {
|
|
66
|
+
useState,
|
|
67
|
+
useReducer,
|
|
68
|
+
useEffect,
|
|
69
|
+
useLayoutEffect,
|
|
70
|
+
useInsertionEffect,
|
|
71
|
+
useRef,
|
|
72
|
+
useMemo,
|
|
73
|
+
useCallback,
|
|
74
|
+
useContext,
|
|
75
|
+
useImperativeHandle,
|
|
76
|
+
useDebugValue,
|
|
77
|
+
useId,
|
|
78
|
+
useTransition,
|
|
79
|
+
useDeferredValue,
|
|
80
|
+
useSyncExternalStore,
|
|
81
|
+
use,
|
|
82
|
+
useActionState,
|
|
83
|
+
useFormStatus,
|
|
84
|
+
useOptimistic,
|
|
85
|
+
useEffectEvent,
|
|
86
|
+
startTransition,
|
|
87
|
+
} from './hooks'
|
|
88
|
+
import { createContext } from './context'
|
|
89
|
+
import { Component, PureComponent } from './class'
|
|
90
|
+
import { memo, forwardRef, lazy } from './memo'
|
|
91
|
+
import { Suspense, StrictMode, Profiler } from './suspense'
|
|
92
|
+
import { Children } from './children'
|
|
93
|
+
|
|
94
|
+
export default {
|
|
95
|
+
createElement,
|
|
96
|
+
cloneElement,
|
|
97
|
+
isValidElement,
|
|
98
|
+
createRef,
|
|
99
|
+
Fragment,
|
|
100
|
+
useState,
|
|
101
|
+
useReducer,
|
|
102
|
+
useEffect,
|
|
103
|
+
useLayoutEffect,
|
|
104
|
+
useInsertionEffect,
|
|
105
|
+
useRef,
|
|
106
|
+
useMemo,
|
|
107
|
+
useCallback,
|
|
108
|
+
useContext,
|
|
109
|
+
useImperativeHandle,
|
|
110
|
+
useDebugValue,
|
|
111
|
+
useId,
|
|
112
|
+
useTransition,
|
|
113
|
+
useDeferredValue,
|
|
114
|
+
useSyncExternalStore,
|
|
115
|
+
use,
|
|
116
|
+
useActionState,
|
|
117
|
+
useFormStatus,
|
|
118
|
+
useOptimistic,
|
|
119
|
+
useEffectEvent,
|
|
120
|
+
startTransition,
|
|
121
|
+
createContext,
|
|
122
|
+
Component,
|
|
123
|
+
PureComponent,
|
|
124
|
+
memo,
|
|
125
|
+
forwardRef,
|
|
126
|
+
lazy,
|
|
127
|
+
Suspense,
|
|
128
|
+
StrictMode,
|
|
129
|
+
Profiler,
|
|
130
|
+
Children,
|
|
131
|
+
version: '19.2.3',
|
|
132
|
+
}
|