kiru 0.44.4 → 0.45.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/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/appContext.d.ts +38 -0
- package/dist/appContext.d.ts.map +1 -0
- package/dist/appContext.js +143 -0
- package/dist/appContext.js.map +1 -0
- package/dist/cloneVNode.d.ts +2 -0
- package/dist/cloneVNode.d.ts.map +1 -0
- package/dist/cloneVNode.js +14 -0
- package/dist/cloneVNode.js.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +127 -0
- package/dist/constants.js.map +1 -0
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +50 -0
- package/dist/context.js.map +1 -0
- package/dist/dom.d.ts +8 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +582 -0
- package/dist/dom.js.map +1 -0
- package/dist/element.d.ts +6 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +41 -0
- package/dist/element.js.map +1 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +6 -0
- package/dist/env.js.map +1 -0
- package/dist/error.d.ts +19 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +63 -0
- package/dist/error.js.map +1 -0
- package/dist/flags.d.ts +6 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +16 -0
- package/dist/flags.js.map +1 -0
- package/dist/form/index.d.ts +4 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +509 -0
- package/dist/form/index.js.map +1 -0
- package/dist/form/types.d.ts +121 -0
- package/dist/form/types.d.ts.map +1 -0
- package/dist/form/types.js +2 -0
- package/dist/form/types.js.map +1 -0
- package/dist/form/utils.d.ts +3 -0
- package/dist/form/utils.d.ts.map +1 -0
- package/dist/form/utils.js +16 -0
- package/dist/form/utils.js.map +1 -0
- package/dist/generateId.d.ts +8 -0
- package/dist/generateId.d.ts.map +1 -0
- package/dist/generateId.js +15 -0
- package/dist/generateId.js.map +1 -0
- package/dist/globalContext.d.ts +37 -0
- package/dist/globalContext.d.ts.map +1 -0
- package/dist/globalContext.js +85 -0
- package/dist/globalContext.js.map +1 -0
- package/dist/globals.d.ts +16 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +15 -0
- package/dist/globals.js.map +1 -0
- package/dist/hmr.d.ts +32 -0
- package/dist/hmr.d.ts.map +1 -0
- package/dist/hmr.js +125 -0
- package/dist/hmr.js.map +1 -0
- package/dist/hooks/index.d.ts +15 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +15 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAsync.d.ts +29 -0
- package/dist/hooks/useAsync.d.ts.map +1 -0
- package/dist/hooks/useAsync.js +96 -0
- package/dist/hooks/useAsync.js.map +1 -0
- package/dist/hooks/useCallback.d.ts +7 -0
- package/dist/hooks/useCallback.d.ts.map +1 -0
- package/dist/hooks/useCallback.js +29 -0
- package/dist/hooks/useCallback.js.map +1 -0
- package/dist/hooks/useContext.d.ts +7 -0
- package/dist/hooks/useContext.d.ts.map +1 -0
- package/dist/hooks/useContext.js +59 -0
- package/dist/hooks/useContext.js.map +1 -0
- package/dist/hooks/useEffect.d.ts +8 -0
- package/dist/hooks/useEffect.d.ts.map +1 -0
- package/dist/hooks/useEffect.js +33 -0
- package/dist/hooks/useEffect.js.map +1 -0
- package/dist/hooks/useEffectEvent.d.ts +8 -0
- package/dist/hooks/useEffectEvent.d.ts.map +1 -0
- package/dist/hooks/useEffectEvent.js +22 -0
- package/dist/hooks/useEffectEvent.js.map +1 -0
- package/dist/hooks/useId.d.ts +8 -0
- package/dist/hooks/useId.d.ts.map +1 -0
- package/dist/hooks/useId.js +35 -0
- package/dist/hooks/useId.js.map +1 -0
- package/dist/hooks/useLayoutEffect.d.ts +8 -0
- package/dist/hooks/useLayoutEffect.d.ts.map +1 -0
- package/dist/hooks/useLayoutEffect.js +33 -0
- package/dist/hooks/useLayoutEffect.js.map +1 -0
- package/dist/hooks/useMemo.d.ts +8 -0
- package/dist/hooks/useMemo.d.ts.map +1 -0
- package/dist/hooks/useMemo.js +30 -0
- package/dist/hooks/useMemo.js.map +1 -0
- package/dist/hooks/useReducer.d.ts +7 -0
- package/dist/hooks/useReducer.d.ts.map +1 -0
- package/dist/hooks/useReducer.js +44 -0
- package/dist/hooks/useReducer.js.map +1 -0
- package/dist/hooks/useRef.d.ts +10 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/hooks/useRef.js +28 -0
- package/dist/hooks/useRef.js.map +1 -0
- package/dist/hooks/useState.d.ts +7 -0
- package/dist/hooks/useState.d.ts.map +1 -0
- package/dist/hooks/useState.js +54 -0
- package/dist/hooks/useState.js.map +1 -0
- package/dist/hooks/useSyncExternalStore.d.ts +8 -0
- package/dist/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/dist/hooks/useSyncExternalStore.js +50 -0
- package/dist/hooks/useSyncExternalStore.js.map +1 -0
- package/dist/hooks/useViewTransition.d.ts +10 -0
- package/dist/hooks/useViewTransition.d.ts.map +1 -0
- package/dist/hooks/useViewTransition.js +28 -0
- package/dist/hooks/useViewTransition.js.map +1 -0
- package/dist/hooks/utils.d.ts +69 -0
- package/dist/hooks/utils.d.ts.map +1 -0
- package/dist/hooks/utils.js +163 -0
- package/dist/hooks/utils.js.map +1 -0
- package/dist/hydration.d.ts +17 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +59 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx.d.ts +6 -0
- package/dist/jsx.d.ts.map +1 -0
- package/dist/jsx.js +8 -0
- package/dist/jsx.js.map +1 -0
- package/dist/lazy.d.ts +11 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +177 -0
- package/dist/lazy.js.map +1 -0
- package/dist/memo.d.ts +9 -0
- package/dist/memo.d.ts.map +1 -0
- package/dist/memo.js +25 -0
- package/dist/memo.js.map +1 -0
- package/dist/portal.d.ts +10 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +34 -0
- package/dist/portal.js.map +1 -0
- package/dist/profiling.d.ts +26 -0
- package/dist/profiling.d.ts.map +1 -0
- package/dist/profiling.js +83 -0
- package/dist/profiling.js.map +1 -0
- package/dist/props.d.ts +4 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +27 -0
- package/dist/props.js.map +1 -0
- package/dist/reconciler.d.ts +4 -0
- package/dist/reconciler.d.ts.map +1 -0
- package/dist/reconciler.js +466 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/renderToString.d.ts +2 -0
- package/dist/renderToString.d.ts.map +1 -0
- package/dist/renderToString.js +74 -0
- package/dist/renderToString.js.map +1 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +3 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/route.d.ts +46 -0
- package/dist/router/route.d.ts.map +1 -0
- package/dist/router/route.js +8 -0
- package/dist/router/route.js.map +1 -0
- package/dist/router/router.d.ts +62 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +178 -0
- package/dist/router/router.js.map +1 -0
- package/dist/router/routerUtils.d.ts +5 -0
- package/dist/router/routerUtils.d.ts.map +1 -0
- package/dist/router/routerUtils.js +39 -0
- package/dist/router/routerUtils.js.map +1 -0
- package/dist/scheduler.d.ts +14 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +457 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/signals/base.d.ts +36 -0
- package/dist/signals/base.d.ts.map +1 -0
- package/dist/signals/base.js +205 -0
- package/dist/signals/base.js.map +1 -0
- package/dist/signals/computed.d.ts +16 -0
- package/dist/signals/computed.d.ts.map +1 -0
- package/dist/signals/computed.js +116 -0
- package/dist/signals/computed.js.map +1 -0
- package/dist/signals/effect.d.ts +18 -0
- package/dist/signals/effect.d.ts.map +1 -0
- package/dist/signals/effect.js +43 -0
- package/dist/signals/effect.js.map +1 -0
- package/dist/signals/globals.d.ts +9 -0
- package/dist/signals/globals.d.ts.map +1 -0
- package/dist/signals/globals.js +9 -0
- package/dist/signals/globals.js.map +1 -0
- package/dist/signals/index.d.ts +12 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +12 -0
- package/dist/signals/index.js.map +1 -0
- package/dist/signals/jsx.d.ts +16 -0
- package/dist/signals/jsx.d.ts.map +1 -0
- package/dist/signals/jsx.js +11 -0
- package/dist/signals/jsx.js.map +1 -0
- package/dist/signals/types.d.ts +9 -0
- package/dist/signals/types.d.ts.map +1 -0
- package/dist/signals/types.js +2 -0
- package/dist/signals/types.js.map +1 -0
- package/dist/signals/utils.d.ts +4 -0
- package/dist/signals/utils.d.ts.map +1 -0
- package/dist/signals/utils.js +12 -0
- package/dist/signals/utils.js.map +1 -0
- package/dist/signals/watch.d.ts +24 -0
- package/dist/signals/watch.d.ts.map +1 -0
- package/dist/signals/watch.js +104 -0
- package/dist/signals/watch.js.map +1 -0
- package/dist/ssr/client.d.ts +4 -0
- package/dist/ssr/client.d.ts.map +1 -0
- package/dist/ssr/client.js +12 -0
- package/dist/ssr/client.js.map +1 -0
- package/dist/ssr/hydrationBoundary.d.ts +27 -0
- package/dist/ssr/hydrationBoundary.d.ts.map +1 -0
- package/dist/ssr/hydrationBoundary.js +30 -0
- package/dist/ssr/hydrationBoundary.js.map +1 -0
- package/dist/ssr/index.d.ts +2 -0
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/ssr/index.js +2 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/server.d.ts +3 -0
- package/dist/ssr/server.d.ts.map +1 -0
- package/dist/ssr/server.js +101 -0
- package/dist/ssr/server.js.map +1 -0
- package/dist/store.d.ts +28 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +166 -0
- package/dist/store.js.map +1 -0
- package/dist/swr.d.ts +74 -0
- package/dist/swr.d.ts.map +1 -0
- package/dist/swr.js +228 -0
- package/dist/swr.js.map +1 -0
- package/dist/transition.d.ts +18 -0
- package/dist/transition.d.ts.map +1 -0
- package/dist/transition.js +48 -0
- package/dist/transition.js.map +1 -0
- package/dist/types.d.ts +143 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.dom.d.ts +920 -0
- package/dist/types.dom.d.ts.map +1 -0
- package/dist/types.dom.js +2 -0
- package/dist/types.dom.js.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/types.utils.d.ts +41 -0
- package/dist/types.utils.d.ts.map +1 -0
- package/dist/types.utils.js +2 -0
- package/dist/types.utils.js.map +1 -0
- package/dist/utils.d.ts +61 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +478 -0
- package/dist/utils.js.map +1 -0
- package/dist/warning.d.ts +2 -0
- package/dist/warning.d.ts.map +1 -0
- package/dist/warning.js +4 -0
- package/dist/warning.js.map +1 -0
- package/package.json +2 -2
- package/src/appContext.ts +7 -7
- package/src/cloneVNode.ts +1 -1
- package/src/constants.ts +9 -9
- package/src/context.ts +7 -7
- package/src/dom.ts +13 -15
- package/src/element.ts +4 -4
- package/src/error.ts +11 -13
- package/src/globalContext.ts +6 -10
- package/src/globals.ts +3 -3
- package/src/hmr.ts +4 -4
- package/src/hooks/useAsync.ts +2 -2
- package/src/hooks/useCallback.ts +1 -1
- package/src/hooks/useContext.ts +6 -6
- package/src/hooks/useEffect.ts +2 -2
- package/src/hooks/useEffectEvent.ts +1 -1
- package/src/hooks/useId.ts +2 -2
- package/src/hooks/useLayoutEffect.ts +2 -2
- package/src/hooks/useMemo.ts +2 -2
- package/src/hooks/useReducer.ts +2 -2
- package/src/hooks/useRef.ts +5 -5
- package/src/hooks/useState.ts +5 -5
- package/src/hooks/useSyncExternalStore.ts +3 -3
- package/src/hooks/useViewTransition.ts +1 -1
- package/src/hooks/utils.ts +7 -9
- package/src/index.ts +4 -4
- package/src/jsx.ts +2 -2
- package/src/lazy.ts +15 -17
- package/src/memo.ts +2 -2
- package/src/portal.ts +4 -4
- package/src/props.ts +5 -7
- package/src/reconciler.ts +6 -6
- package/src/renderToString.ts +1 -1
- package/src/router/route.ts +1 -1
- package/src/router/router.ts +6 -6
- package/src/scheduler.ts +16 -16
- package/src/signals/base.ts +1 -1
- package/src/signals/types.ts +1 -1
- package/src/signals/watch.ts +2 -2
- package/src/ssr/hydrationBoundary.ts +1 -1
- package/src/ssr/server.ts +1 -1
- package/src/store.ts +7 -7
- package/src/swr.ts +2 -2
- package/src/types.dom.ts +1 -1
- package/src/types.ts +13 -13
- package/src/types.utils.ts +5 -5
- package/src/utils.ts +9 -12
- package/src/warning.ts +1 -1
package/src/dom.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { hydrationStack } from "./hydration.js"
|
|
|
12
12
|
import { StyleObject } from "./types.dom.js"
|
|
13
13
|
import { isPortal } from "./portal.js"
|
|
14
14
|
import { __DEV__ } from "./env.js"
|
|
15
|
-
import {
|
|
15
|
+
import { KiruError } from "./error.js"
|
|
16
16
|
import { flags } from "./flags.js"
|
|
17
17
|
import type {
|
|
18
18
|
DomVNode,
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
|
|
25
25
|
export { commitWork, createDom, updateDom, hydrateDom }
|
|
26
26
|
|
|
27
|
-
type VNode =
|
|
27
|
+
type VNode = Kiru.VNode
|
|
28
28
|
type HostNode = {
|
|
29
29
|
node: ElementVNode
|
|
30
30
|
lastChild?: DomVNode
|
|
@@ -35,7 +35,7 @@ type PlacementScope = {
|
|
|
35
35
|
child?: VNode
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function setDomRef(ref:
|
|
38
|
+
function setDomRef(ref: Kiru.Ref<SomeDom | null>, value: SomeDom | null) {
|
|
39
39
|
if (typeof ref === "function") {
|
|
40
40
|
ref(value)
|
|
41
41
|
return
|
|
@@ -47,7 +47,7 @@ function setDomRef(ref: Kaioken.Ref<SomeDom | null>, value: SomeDom | null) {
|
|
|
47
47
|
})
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
|
-
;(ref as
|
|
50
|
+
;(ref as Kiru.MutableRefObject<SomeDom | null>).current = value
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function createDom(vNode: DomVNode): SomeDom {
|
|
@@ -247,7 +247,7 @@ function setSignalProp(
|
|
|
247
247
|
cleanups[key] = signal.subscribe((value) => {
|
|
248
248
|
setProp(dom, key, value, null)
|
|
249
249
|
if (__DEV__) {
|
|
250
|
-
window.
|
|
250
|
+
window.__kiru?.profilingContext?.emit("signalAttrUpdate", _ctx)
|
|
251
251
|
}
|
|
252
252
|
})
|
|
253
253
|
|
|
@@ -257,9 +257,7 @@ function setSignalProp(
|
|
|
257
257
|
const evtName = bindAttrToEventMap[attr]
|
|
258
258
|
if (!evtName) {
|
|
259
259
|
if (__DEV__) {
|
|
260
|
-
console.error(
|
|
261
|
-
`[kaioken]: ${attr} is not a valid element binding attribute.`
|
|
262
|
-
)
|
|
260
|
+
console.error(`[kiru]: ${attr} is not a valid element binding attribute.`)
|
|
263
261
|
}
|
|
264
262
|
return
|
|
265
263
|
}
|
|
@@ -272,7 +270,7 @@ function setSignalProp(
|
|
|
272
270
|
const signalUpdateCallback = (value: any) => {
|
|
273
271
|
setAttr(value)
|
|
274
272
|
if (__DEV__) {
|
|
275
|
-
window.
|
|
273
|
+
window.__kiru?.profilingContext?.emit("signalAttrUpdate", _ctx)
|
|
276
274
|
}
|
|
277
275
|
}
|
|
278
276
|
|
|
@@ -324,7 +322,7 @@ function subTextNode(vNode: VNode, textNode: Text, signal: Signal<string>) {
|
|
|
324
322
|
;(vNode.cleanups ??= {}).nodeValue = signal.subscribe((v) => {
|
|
325
323
|
textNode.nodeValue = v
|
|
326
324
|
if (__DEV__) {
|
|
327
|
-
window.
|
|
325
|
+
window.__kiru?.profilingContext?.emit("signalTextUpdate", _ctx)
|
|
328
326
|
}
|
|
329
327
|
})
|
|
330
328
|
}
|
|
@@ -332,7 +330,7 @@ function subTextNode(vNode: VNode, textNode: Text, signal: Signal<string>) {
|
|
|
332
330
|
function hydrateDom(vNode: VNode) {
|
|
333
331
|
const dom = hydrationStack.nextChild()
|
|
334
332
|
if (!dom)
|
|
335
|
-
throw new
|
|
333
|
+
throw new KiruError({
|
|
336
334
|
message: `Hydration mismatch - no node found`,
|
|
337
335
|
vNode,
|
|
338
336
|
})
|
|
@@ -341,7 +339,7 @@ function hydrateDom(vNode: VNode) {
|
|
|
341
339
|
nodeName = nodeName.toLowerCase()
|
|
342
340
|
}
|
|
343
341
|
if ((vNode.type as string) !== nodeName) {
|
|
344
|
-
throw new
|
|
342
|
+
throw new KiruError({
|
|
345
343
|
message: `Hydration mismatch - expected node of type ${vNode.type.toString()} but received ${nodeName}`,
|
|
346
344
|
vNode,
|
|
347
345
|
})
|
|
@@ -523,7 +521,7 @@ function getDomParent(vNode: VNode): ElementVNode {
|
|
|
523
521
|
return vNode as ElementVNode
|
|
524
522
|
}
|
|
525
523
|
|
|
526
|
-
throw new
|
|
524
|
+
throw new KiruError({
|
|
527
525
|
message: "No DOM parent found while attempting to place node.",
|
|
528
526
|
vNode: vNode,
|
|
529
527
|
})
|
|
@@ -698,11 +696,11 @@ function commitDeletion(vNode: VNode) {
|
|
|
698
696
|
if (cleanups) Object.values(cleanups).forEach((c) => c())
|
|
699
697
|
|
|
700
698
|
if (__DEV__) {
|
|
701
|
-
window.
|
|
699
|
+
window.__kiru?.profilingContext?.emit("removeNode", ctx.current)
|
|
702
700
|
}
|
|
703
701
|
|
|
704
702
|
if (dom) {
|
|
705
|
-
if (ref) setDomRef(ref as
|
|
703
|
+
if (ref) setDomRef(ref as Kiru.Ref<SomeDom>, null)
|
|
706
704
|
if (dom.isConnected && !isPortal(node)) {
|
|
707
705
|
dom.remove()
|
|
708
706
|
}
|
package/src/element.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { $FRAGMENT, $MEMO } from "./constants.js"
|
|
|
2
2
|
import { isMemoFn } from "./memo.js"
|
|
3
3
|
import { isValidElementKeyProp, isValidElementRefProp } from "./props.js"
|
|
4
4
|
|
|
5
|
-
export function createElement<T extends
|
|
5
|
+
export function createElement<T extends Kiru.VNode["type"]>(
|
|
6
6
|
type: T,
|
|
7
7
|
props: null | Record<string, unknown> = null,
|
|
8
8
|
...children: unknown[]
|
|
9
|
-
):
|
|
9
|
+
): Kiru.VNode {
|
|
10
10
|
if ((type as any) === Fragment) {
|
|
11
11
|
return Fragment({ children: children as any, ...props })
|
|
12
12
|
}
|
|
13
|
-
const node:
|
|
13
|
+
const node: Kiru.VNode = {
|
|
14
14
|
type,
|
|
15
15
|
flags: 0,
|
|
16
16
|
index: 0,
|
|
@@ -49,6 +49,6 @@ export function Fragment({
|
|
|
49
49
|
}: {
|
|
50
50
|
children: JSX.Children
|
|
51
51
|
key?: JSX.ElementKey
|
|
52
|
-
}):
|
|
52
|
+
}): Kiru.VNode {
|
|
53
53
|
return createElement($FRAGMENT, key ? { key } : null, children)
|
|
54
54
|
}
|
package/src/error.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $KIRU_ERROR } from "./constants.js"
|
|
2
2
|
import { __DEV__ } from "./env.js"
|
|
3
3
|
import { findParent, noop } from "./utils.js"
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type KiruErrorOptions =
|
|
6
6
|
| string
|
|
7
7
|
| {
|
|
8
8
|
message: string
|
|
9
9
|
/** Used to indicate that the error is fatal and should crash the application */
|
|
10
10
|
fatal?: boolean
|
|
11
11
|
/** Used to generate custom node stack */
|
|
12
|
-
vNode?:
|
|
12
|
+
vNode?: Kiru.VNode
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export class
|
|
16
|
-
[$
|
|
15
|
+
export class KiruError extends Error {
|
|
16
|
+
[$KIRU_ERROR] = true
|
|
17
17
|
/** Indicates whether the error is fatal and should crash the application */
|
|
18
18
|
fatal?: boolean
|
|
19
19
|
/** Present if vNode is provided */
|
|
20
20
|
customNodeStack?: string
|
|
21
|
-
constructor(optionsOrMessage:
|
|
21
|
+
constructor(optionsOrMessage: KiruErrorOptions) {
|
|
22
22
|
const message =
|
|
23
23
|
typeof optionsOrMessage === "string"
|
|
24
24
|
? optionsOrMessage
|
|
@@ -34,14 +34,12 @@ export class KaiokenError extends Error {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
static
|
|
38
|
-
return (
|
|
39
|
-
error instanceof Error && (error as KaiokenError)[$KAIOKEN_ERROR] === true
|
|
40
|
-
)
|
|
37
|
+
static isKiruError(error: unknown): error is KiruError {
|
|
38
|
+
return error instanceof Error && (error as KiruError)[$KIRU_ERROR] === true
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
function captureErrorStack(vNode:
|
|
42
|
+
function captureErrorStack(vNode: Kiru.VNode) {
|
|
45
43
|
let n = vNode
|
|
46
44
|
let componentFns: string[] = []
|
|
47
45
|
while (n) {
|
|
@@ -57,7 +55,7 @@ function captureErrorStack(vNode: Kaioken.VNode) {
|
|
|
57
55
|
typeof vNode.type === "function"
|
|
58
56
|
? vNode
|
|
59
57
|
: findParent(vNode, (n) => typeof n.type === "function")
|
|
60
|
-
) as (
|
|
58
|
+
) as (Kiru.VNode & { type: Function }) | null
|
|
61
59
|
return `The above error occurred in the <${getFunctionName(
|
|
62
60
|
componentNode?.type || noop
|
|
63
61
|
)}> component:
|
|
@@ -81,5 +79,5 @@ function getFunctionName(fn: Function) {
|
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
function getComponentFileLink(fn: Function) {
|
|
84
|
-
return fn.toString().match(/\/\/ \[
|
|
82
|
+
return fn.toString().match(/\/\/ \[kiru_devtools\]:(.*)/)?.[1] ?? null
|
|
85
83
|
}
|
package/src/globalContext.ts
CHANGED
|
@@ -4,11 +4,7 @@ import { createHMRContext } from "./hmr.js"
|
|
|
4
4
|
import { createProfilingContext } from "./profiling.js"
|
|
5
5
|
import { Store } from "./store"
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
createKaiokenGlobalContext,
|
|
9
|
-
type GlobalKaiokenEvent,
|
|
10
|
-
type KaiokenGlobalContext,
|
|
11
|
-
}
|
|
7
|
+
export { createKiruGlobalContext, type GlobalKiruEvent, type KiruGlobalContext }
|
|
12
8
|
|
|
13
9
|
interface ReactiveMap<V> {
|
|
14
10
|
add(key: string, value: V): void
|
|
@@ -72,9 +68,9 @@ type Evt =
|
|
|
72
68
|
data: Error
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
type
|
|
71
|
+
type GlobalKiruEvent = Evt["name"]
|
|
76
72
|
|
|
77
|
-
interface
|
|
73
|
+
interface KiruGlobalContext {
|
|
78
74
|
readonly apps: AppContext[]
|
|
79
75
|
stores?: ReactiveMap<Store<any, any>>
|
|
80
76
|
HMRContext?: ReturnType<typeof createHMRContext>
|
|
@@ -91,10 +87,10 @@ interface KaiokenGlobalContext {
|
|
|
91
87
|
): void
|
|
92
88
|
}
|
|
93
89
|
|
|
94
|
-
function
|
|
90
|
+
function createKiruGlobalContext(): KiruGlobalContext {
|
|
95
91
|
const contexts = new Set<AppContext>()
|
|
96
92
|
const listeners = new Map<
|
|
97
|
-
|
|
93
|
+
GlobalKiruEvent,
|
|
98
94
|
Set<(ctx: AppContext, data?: Evt["data"]) => void>
|
|
99
95
|
>()
|
|
100
96
|
const globalState: Record<symbol, any> = {}
|
|
@@ -128,7 +124,7 @@ function createKaiokenGlobalContext(): KaiokenGlobalContext {
|
|
|
128
124
|
listeners.get(event)?.delete(callback)
|
|
129
125
|
}
|
|
130
126
|
|
|
131
|
-
const globalContext:
|
|
127
|
+
const globalContext: KiruGlobalContext = {
|
|
132
128
|
get apps() {
|
|
133
129
|
return Array.from(contexts)
|
|
134
130
|
},
|
package/src/globals.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AppContext } from "./appContext"
|
|
|
3
3
|
export { node, hookIndex, ctx, renderMode, nodeToCtxMap }
|
|
4
4
|
|
|
5
5
|
const node = {
|
|
6
|
-
current: null as
|
|
6
|
+
current: null as Kiru.VNode | null,
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const hookIndex = {
|
|
@@ -15,7 +15,7 @@ const ctx = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const renderMode = {
|
|
18
|
-
current: ("window" in globalThis ? "dom" : "string") as
|
|
18
|
+
current: ("window" in globalThis ? "dom" : "string") as Kiru.RenderMode,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const nodeToCtxMap = new WeakMap<
|
|
21
|
+
const nodeToCtxMap = new WeakMap<Kiru.VNode, AppContext<any>>()
|
package/src/hmr.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type HMRAccept<T = {}> = {
|
|
|
15
15
|
export type GenericHMRAcceptor<T = {}> = {
|
|
16
16
|
[$HMR_ACCEPT]: HMRAccept<T>
|
|
17
17
|
}
|
|
18
|
-
type HotVar =
|
|
18
|
+
type HotVar = Kiru.FC | Store<any, any> | Signal<any> | Kiru.Context<any>
|
|
19
19
|
|
|
20
20
|
type HotVarDesc = {
|
|
21
21
|
type: string
|
|
@@ -80,7 +80,7 @@ export function createHMRContext() {
|
|
|
80
80
|
hotVarRegistrationEntries: Record<string, HotVarRegistrationEntry>
|
|
81
81
|
) => {
|
|
82
82
|
if (currentModuleMemory === null)
|
|
83
|
-
throw new Error("[
|
|
83
|
+
throw new Error("[kiru]: HMR could not register: No active module")
|
|
84
84
|
|
|
85
85
|
let dirtiedApps: Set<AppContext> = new Set()
|
|
86
86
|
for (const [name, newEntry] of Object.entries(hotVarRegistrationEntries)) {
|
|
@@ -101,7 +101,7 @@ export function createHMRContext() {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if (newEntry.type === "createStore") {
|
|
104
|
-
window.
|
|
104
|
+
window.__kiru!.stores!.add(name, newEntry.value as Store<any, any>)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
currentModuleMemory.hotVars.set(name, newEntry)
|
|
@@ -117,7 +117,7 @@ export function createHMRContext() {
|
|
|
117
117
|
continue
|
|
118
118
|
}
|
|
119
119
|
if (oldEntry.type === "component" && newEntry.type === "component") {
|
|
120
|
-
window.
|
|
120
|
+
window.__kiru!.apps.forEach((ctx) => {
|
|
121
121
|
if (!ctx.mounted || !ctx.rootNode) return
|
|
122
122
|
traverseApply(ctx.rootNode, (vNode) => {
|
|
123
123
|
if (vNode.type === oldEntry.value) {
|
package/src/hooks/useAsync.ts
CHANGED
|
@@ -42,9 +42,9 @@ type AsyncTaskState<T> = {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Runs an asynchronous function on initial render, or when a value provided in the [dependency
|
|
45
|
-
* array](https://
|
|
45
|
+
* array](https://kirujs.dev/docs/hooks/dependency-arrays) has changed.
|
|
46
46
|
*
|
|
47
|
-
* @see https://
|
|
47
|
+
* @see https://kirujs.dev/docs/hooks/useAsync
|
|
48
48
|
*/
|
|
49
49
|
export function useAsync<T>(
|
|
50
50
|
func: (ctx: UseAsyncCallbackContext) => Promise<T>,
|
package/src/hooks/useCallback.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { depsRequireChange, useHook, sideEffectsEnabled } from "./utils.js"
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a memoized callback function.
|
|
6
6
|
*
|
|
7
|
-
* @see https://
|
|
7
|
+
* @see https://kirujs.dev/docs/hooks/useCallback
|
|
8
8
|
*/
|
|
9
9
|
export function useCallback<T extends Function>(
|
|
10
10
|
callback: T,
|
package/src/hooks/useContext.ts
CHANGED
|
@@ -5,17 +5,17 @@ import { $CONTEXT_PROVIDER } from "../constants.js"
|
|
|
5
5
|
|
|
6
6
|
type UseContextHookState<T> = {
|
|
7
7
|
provider?: ContextProviderNode<T>
|
|
8
|
-
context:
|
|
8
|
+
context: Kiru.Context<T>
|
|
9
9
|
warnIfNotFound: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Gets the current value of a context provider created by the context.
|
|
14
14
|
*
|
|
15
|
-
* @see https://
|
|
15
|
+
* @see https://kirujs.dev/docs/hooks/useContext
|
|
16
16
|
*/
|
|
17
17
|
export function useContext<T>(
|
|
18
|
-
context:
|
|
18
|
+
context: Kiru.Context<T>,
|
|
19
19
|
warnIfNotFound = true
|
|
20
20
|
): T {
|
|
21
21
|
return useHook(
|
|
@@ -70,10 +70,10 @@ const useContextCallback = <T>({
|
|
|
70
70
|
return hook.provider.props.value
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const contextsNotFound = new Set<
|
|
74
|
-
function warnProviderNotFound(ctx:
|
|
73
|
+
const contextsNotFound = new Set<Kiru.Context<any>>()
|
|
74
|
+
function warnProviderNotFound(ctx: Kiru.Context<any>) {
|
|
75
75
|
if (!contextsNotFound.has(ctx)) {
|
|
76
76
|
contextsNotFound.add(ctx)
|
|
77
|
-
console.warn("[
|
|
77
|
+
console.warn("[kiru]: Unable to find context provider")
|
|
78
78
|
}
|
|
79
79
|
}
|
package/src/hooks/useEffect.ts
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Runs a function after the component is rendered, or when a value provided in the optional [dependency
|
|
11
|
-
* array](https://
|
|
11
|
+
* array](https://kirujs.dev/docs/hooks/dependency-arrays) has changed.
|
|
12
12
|
*
|
|
13
|
-
* @see https://
|
|
13
|
+
* @see https://kirujs.dev/docs/hooks/useEffect
|
|
14
14
|
* */
|
|
15
15
|
export function useEffect(
|
|
16
16
|
callback: () => void | (() => void),
|
|
@@ -6,7 +6,7 @@ import { sideEffectsEnabled, useHook } from "./utils.js"
|
|
|
6
6
|
* Wraps a function to be called within effects and other callbacks.
|
|
7
7
|
* The function will be called with the same arguments as the original function.
|
|
8
8
|
*
|
|
9
|
-
* @see https://
|
|
9
|
+
* @see https://kirujs.dev/docs/hooks/useEffectEvent
|
|
10
10
|
*/
|
|
11
11
|
export function useEffectEvent<T extends Function>(callback: T): T {
|
|
12
12
|
if (!sideEffectsEnabled()) return callback
|
package/src/hooks/useId.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { HookCallback, useHook } from "./utils.js"
|
|
|
5
5
|
* Creates a unique id for the current node. This is derived based on the node's position in your application tree.
|
|
6
6
|
* Useful for assigning predictable ids to elements.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://kirujs.dev/docs/hooks/useId
|
|
9
9
|
*/
|
|
10
10
|
export function useId(): string {
|
|
11
11
|
return useHook("useId", createUseIdState, useIdCallback)
|
|
@@ -30,7 +30,7 @@ const useIdCallback: HookCallback<UseIdState> = ({ hook, isInit, vNode }) => {
|
|
|
30
30
|
if (isInit || vNode.index !== hook.idx) {
|
|
31
31
|
hook.idx = vNode.index
|
|
32
32
|
const accumulator: number[] = []
|
|
33
|
-
let n:
|
|
33
|
+
let n: Kiru.VNode | null = vNode
|
|
34
34
|
while (n) {
|
|
35
35
|
accumulator.push(n.index)
|
|
36
36
|
accumulator.push(n.depth)
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Runs a function before the component is rendered, or when a value provided in the optional [dependency
|
|
11
|
-
* array](https://
|
|
11
|
+
* array](https://kirujs.dev/docs/hooks/dependency-arrays) has changed.
|
|
12
12
|
*
|
|
13
|
-
* @see https://
|
|
13
|
+
* @see https://kirujs.dev/docs/hooks/useLayoutEffect
|
|
14
14
|
* */
|
|
15
15
|
export function useLayoutEffect(
|
|
16
16
|
callback: () => void | (() => void),
|
package/src/hooks/useMemo.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { depsRequireChange, sideEffectsEnabled, useHook } from "./utils.js"
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a memoized value that only changes when the [dependency
|
|
6
|
-
* array](https://
|
|
6
|
+
* array](https://kirujs.dev/docs/hooks/dependency-arrays) has changed.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://kirujs.dev/docs/hooks/useMemo
|
|
9
9
|
*/
|
|
10
10
|
export function useMemo<T>(factory: () => T, deps: unknown[]): T {
|
|
11
11
|
if (!sideEffectsEnabled()) return factory()
|
package/src/hooks/useReducer.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { sideEffectsEnabled, useHook } from "./utils.js"
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates 'dispatcher-driven' state.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://kirujs.dev/docs/hooks/useReducer
|
|
9
9
|
*/
|
|
10
10
|
export function useReducer<T, A>(
|
|
11
11
|
reducer: (state: T, action: A) => T,
|
|
@@ -23,7 +23,7 @@ export function useReducer<T, A>(
|
|
|
23
23
|
devtools: {
|
|
24
24
|
get: () => ({ value: hook.state }),
|
|
25
25
|
set: ({ value }) => (hook.state = value),
|
|
26
|
-
} satisfies
|
|
26
|
+
} satisfies Kiru.HookDevtoolsProvisions<{ value: T }>,
|
|
27
27
|
initialArgs: [reducer, state],
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/hooks/useRef.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { sideEffectsEnabled, useHook } from "./utils.js"
|
|
|
5
5
|
* Creates a ref object. Useful for persisting values between renders or getting
|
|
6
6
|
* a reference to an element.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://kirujs.dev/docs/hooks/useRef
|
|
9
9
|
*/
|
|
10
|
-
export function useRef<T>(initialValue: T):
|
|
11
|
-
export function useRef<T>(initialValue: T | null):
|
|
12
|
-
export function useRef<T = undefined>():
|
|
10
|
+
export function useRef<T>(initialValue: T): Kiru.MutableRefObject<T>
|
|
11
|
+
export function useRef<T>(initialValue: T | null): Kiru.RefObject<T>
|
|
12
|
+
export function useRef<T = undefined>(): Kiru.MutableRefObject<T | undefined>
|
|
13
13
|
export function useRef<T>(initialValue?: T | null) {
|
|
14
14
|
if (!sideEffectsEnabled()) return { current: initialValue }
|
|
15
15
|
return useHook(
|
|
@@ -22,7 +22,7 @@ export function useRef<T>(initialValue?: T | null) {
|
|
|
22
22
|
devtools: {
|
|
23
23
|
get: () => ({ value: hook.ref.current! }),
|
|
24
24
|
set: ({ value }) => (hook.ref.current = value),
|
|
25
|
-
} satisfies
|
|
25
|
+
} satisfies Kiru.HookDevtoolsProvisions<{ value: T }>,
|
|
26
26
|
initialArgs: [hook.ref.current],
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/hooks/useState.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { sideEffectsEnabled, useHook } from "./utils.js"
|
|
|
5
5
|
/**
|
|
6
6
|
* Creates a stateful value, and returns the current value and a function to update it.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://kirujs.dev/docs/hooks/useState
|
|
9
9
|
*/
|
|
10
10
|
export function useState<T>(
|
|
11
11
|
initial: T | (() => T)
|
|
12
|
-
): readonly [T, (value:
|
|
12
|
+
): readonly [T, (value: Kiru.StateSetter<T>) => void] {
|
|
13
13
|
if (!sideEffectsEnabled()) {
|
|
14
14
|
return [
|
|
15
15
|
typeof initial === "function" ? (initial as Function)() : initial,
|
|
@@ -20,7 +20,7 @@ export function useState<T>(
|
|
|
20
20
|
"useState",
|
|
21
21
|
{
|
|
22
22
|
state: undefined as T,
|
|
23
|
-
dispatch: noop as (value:
|
|
23
|
+
dispatch: noop as (value: Kiru.StateSetter<T>) => void,
|
|
24
24
|
},
|
|
25
25
|
({ hook, isInit, update, isHMR }) => {
|
|
26
26
|
if (__DEV__) {
|
|
@@ -29,7 +29,7 @@ export function useState<T>(
|
|
|
29
29
|
devtools: {
|
|
30
30
|
get: () => ({ value: hook.state }),
|
|
31
31
|
set: ({ value }) => (hook.state = value),
|
|
32
|
-
} satisfies
|
|
32
|
+
} satisfies Kiru.HookDevtoolsProvisions<{ value: T }>,
|
|
33
33
|
initialArgs: [initial],
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -45,7 +45,7 @@ export function useState<T>(
|
|
|
45
45
|
if (isInit) {
|
|
46
46
|
hook.state =
|
|
47
47
|
typeof initial === "function" ? (initial as Function)() : initial
|
|
48
|
-
hook.dispatch = (setter:
|
|
48
|
+
hook.dispatch = (setter: Kiru.StateSetter<T>) => {
|
|
49
49
|
const newState =
|
|
50
50
|
typeof setter === "function"
|
|
51
51
|
? (setter as Function)(hook.state)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { node } from "../globals.js"
|
|
2
|
-
import {
|
|
2
|
+
import { KiruError } from "../error.js"
|
|
3
3
|
import { noop } from "../utils.js"
|
|
4
4
|
import { sideEffectsEnabled, useHook } from "./utils.js"
|
|
5
5
|
import { __DEV__ } from "../env.js"
|
|
@@ -8,7 +8,7 @@ import { __DEV__ } from "../env.js"
|
|
|
8
8
|
* Allows you to use a generic external store as long as it provides
|
|
9
9
|
* a subscribe function and a way to get its current state.
|
|
10
10
|
*
|
|
11
|
-
* @see https://
|
|
11
|
+
* @see https://kirujs.dev/docs/hooks/useSyncExternalStore
|
|
12
12
|
*/
|
|
13
13
|
export function useSyncExternalStore<T>(
|
|
14
14
|
subscribe: (callback: () => void) => () => void,
|
|
@@ -17,7 +17,7 @@ export function useSyncExternalStore<T>(
|
|
|
17
17
|
): T {
|
|
18
18
|
if (!sideEffectsEnabled()) {
|
|
19
19
|
if (getServerState === undefined) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new KiruError({
|
|
21
21
|
message:
|
|
22
22
|
"useSyncExternalStore must receive a getServerSnapshot function if the component is rendered on the server.",
|
|
23
23
|
vNode: node.current!,
|
|
@@ -8,7 +8,7 @@ import { sideEffectsEnabled } from "./utils.js"
|
|
|
8
8
|
*
|
|
9
9
|
* Falls back to the regular `callback` if not supported.
|
|
10
10
|
*
|
|
11
|
-
* @see https://
|
|
11
|
+
* @see https://kirujs.dev/docs/hooks/useViewTransition
|
|
12
12
|
*/
|
|
13
13
|
export function useViewTransition() {
|
|
14
14
|
if (!sideEffectsEnabled()) return noop
|
package/src/hooks/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KiruError } from "../error.js"
|
|
2
2
|
import { __DEV__ } from "../env.js"
|
|
3
3
|
import { ctx, hookIndex, node, nodeToCtxMap } from "../globals.js"
|
|
4
4
|
import { getVNodeAppContext, noop } from "../utils.js"
|
|
@@ -17,7 +17,7 @@ export {
|
|
|
17
17
|
type HookCallbackContext as HookCallbackState,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
type HookState<T> =
|
|
20
|
+
type HookState<T> = Kiru.Hook<T>
|
|
21
21
|
|
|
22
22
|
enum HookDebugGroupAction {
|
|
23
23
|
Start = "start",
|
|
@@ -57,9 +57,7 @@ const useAppContext = () => {
|
|
|
57
57
|
if (!node.current) error_hookMustBeCalledTopLevel("useAppContext")
|
|
58
58
|
const ctx = nodeToCtxMap.get(node.current)
|
|
59
59
|
if (!ctx)
|
|
60
|
-
error_hookMustBeCalledTopLevel(
|
|
61
|
-
"[kaioken]: unable to find node's AppContext"
|
|
62
|
-
)
|
|
60
|
+
error_hookMustBeCalledTopLevel("[kiru]: unable to find node's AppContext")
|
|
63
61
|
return ctx
|
|
64
62
|
}
|
|
65
63
|
|
|
@@ -97,7 +95,7 @@ type HookCallbackContext<T> = {
|
|
|
97
95
|
/**
|
|
98
96
|
* The VNode associated with the current component
|
|
99
97
|
*/
|
|
100
|
-
vNode:
|
|
98
|
+
vNode: Kiru.VNode
|
|
101
99
|
/**
|
|
102
100
|
* The index of the current hook.
|
|
103
101
|
* You can count on this being stable across renders,
|
|
@@ -140,7 +138,7 @@ function useHook<
|
|
|
140
138
|
!nestedHookWarnings.has(hookName + currentHookName)
|
|
141
139
|
) {
|
|
142
140
|
nestedHookWarnings.add(hookName + currentHookName)
|
|
143
|
-
throw new
|
|
141
|
+
throw new KiruError({
|
|
144
142
|
message: `Nested primitive "useHook" calls are not supported. "${hookName}" was called inside "${currentHookName}". Strange will most certainly happen.`,
|
|
145
143
|
vNode,
|
|
146
144
|
})
|
|
@@ -173,7 +171,7 @@ function useHook<
|
|
|
173
171
|
} else {
|
|
174
172
|
if (vNode.hookSig[index] !== hookName) {
|
|
175
173
|
console.warn(
|
|
176
|
-
`[
|
|
174
|
+
`[kiru]: hooks must be called in the same order. Hook "${hookName}" was called in place of "${vNode.hookSig[index]}". Strange things may happen.`
|
|
177
175
|
)
|
|
178
176
|
vNode.hooks.length = index
|
|
179
177
|
vNode.hookSig.length = index
|
|
@@ -237,7 +235,7 @@ function useHook<
|
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
function error_hookMustBeCalledTopLevel(hookName: string): never {
|
|
240
|
-
throw new
|
|
238
|
+
throw new KiruError(
|
|
241
239
|
`Hook "${hookName}" must be used at the top level of a component or inside another composite hook.`
|
|
242
240
|
)
|
|
243
241
|
}
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
type AppContextOptions,
|
|
5
5
|
} from "./appContext.js"
|
|
6
6
|
import { ctx } from "./globals.js"
|
|
7
|
-
import {
|
|
7
|
+
import { createKiruGlobalContext } from "./globalContext.js"
|
|
8
8
|
import { __DEV__ } from "./env.js"
|
|
9
|
-
import {
|
|
9
|
+
import { KiruError } from "./error.js"
|
|
10
10
|
|
|
11
11
|
export type * from "./types"
|
|
12
12
|
export * from "./appContext.js"
|
|
@@ -23,7 +23,7 @@ export * from "./store.js"
|
|
|
23
23
|
export * from "./transition.js"
|
|
24
24
|
|
|
25
25
|
if ("window" in globalThis) {
|
|
26
|
-
globalThis.window.
|
|
26
|
+
globalThis.window.__kiru ??= createKiruGlobalContext()
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function mount<T extends Record<string, unknown>>(
|
|
@@ -52,7 +52,7 @@ export function mount<T extends Record<string, unknown>>(
|
|
|
52
52
|
root = optionsOrRoot.root!
|
|
53
53
|
if (__DEV__) {
|
|
54
54
|
if (!(root instanceof HTMLElement)) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new KiruError("Root node must be an HTMLElement")
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
package/src/jsx.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { createElement, Fragment } from "./element.js"
|
|
|
3
3
|
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment }
|
|
4
4
|
|
|
5
5
|
function jsx(
|
|
6
|
-
type:
|
|
7
|
-
{ children, ...props } = {} as { children?:
|
|
6
|
+
type: Kiru.VNode["type"],
|
|
7
|
+
{ children, ...props } = {} as { children?: Kiru.VNode[] }
|
|
8
8
|
) {
|
|
9
9
|
if (!children) return createElement(type, props)
|
|
10
10
|
return createElement(type, props, children)
|