@simpreact/simpreact 0.0.6 → 0.0.8

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.
Files changed (45) hide show
  1. package/compat/context.d.ts +4 -5
  2. package/compat/context.js +3 -3
  3. package/compat/core.d.ts +28 -27
  4. package/compat/core.js +8 -7
  5. package/compat/dom.d.ts +5 -5
  6. package/compat/dom.js +5 -5
  7. package/compat/hooks.d.ts +7 -8
  8. package/compat/hooks.js +3 -3
  9. package/compat/index.d.ts +100 -43
  10. package/compat/index.js +3 -0
  11. package/compat/jsx-runtime.d.ts +7 -7
  12. package/compat/jsx-runtime.js +4 -4
  13. package/compat/renderRuntime.d.ts +4 -0
  14. package/compat/renderRuntime.js +3 -0
  15. package/component/index.d.ts +6 -7
  16. package/context/index.d.ts +5 -5
  17. package/context/index.js +1 -1
  18. package/core/index.d.ts +17 -19
  19. package/core/index.js +3 -2
  20. package/core/internal.d.ts +2 -0
  21. package/core/internal.js +2 -0
  22. package/core/mounting.d.ts +1 -2
  23. package/core/mounting.js +50 -101
  24. package/core/mountingChildren.d.ts +4 -0
  25. package/core/mountingChildren.js +47 -0
  26. package/core/patching.d.ts +1 -1
  27. package/core/patching.js +54 -44
  28. package/core/patchingChildren.d.ts +3 -3
  29. package/core/patchingChildren.js +104 -91
  30. package/core/processStack.d.ts +53 -16
  31. package/core/processStack.js +23 -11
  32. package/core/unmounting.d.ts +4 -8
  33. package/core/unmounting.js +45 -85
  34. package/core/unmountingChildren.d.ts +4 -0
  35. package/core/unmountingChildren.js +23 -0
  36. package/core/utils.d.ts +3 -2
  37. package/core/utils.js +28 -3
  38. package/dom/index.d.ts +4 -5
  39. package/dom/props/dangerInnerHTML.d.ts +5 -5
  40. package/dom/props/dangerInnerHTML.js +10 -16
  41. package/dom/props/props.js +5 -5
  42. package/hooks/index.d.ts +12 -10
  43. package/hooks/index.js +1 -0
  44. package/package.json +1 -1
  45. package/shared/index.d.ts +10 -6
@@ -1,8 +1,7 @@
1
- import * as SimpReactContext from '../context/index.js';
2
- export declare const createContext: SimpReactContext.CreateContext;
3
- export declare const useContext: SimpReactContext.UseContext;
1
+ export declare const createContext: import("../context/index.js").CreateContext;
2
+ export declare const useContext: import("../context/index.js").UseContext;
4
3
  declare const _default: {
5
- createContext: SimpReactContext.CreateContext;
6
- useContext: SimpReactContext.UseContext;
4
+ createContext: import("../context/index.js").CreateContext;
5
+ useContext: import("../context/index.js").UseContext;
7
6
  };
8
7
  export default _default;
package/compat/context.js CHANGED
@@ -1,7 +1,7 @@
1
- import * as SimpReactContext from '../context/index.js';
1
+ import { createCreateContext, createUseContext } from '../context/index.js';
2
2
  import { renderRuntime } from './renderRuntime.js';
3
- export const createContext = SimpReactContext.createCreateContext(renderRuntime);
4
- export const useContext = SimpReactContext.createUseContext(renderRuntime);
3
+ export const createContext = createCreateContext(renderRuntime);
4
+ export const useContext = createUseContext(renderRuntime);
5
5
  export default {
6
6
  createContext,
7
7
  useContext,
package/compat/core.d.ts CHANGED
@@ -1,46 +1,47 @@
1
- import * as SimpReactInternal from '../core/internal.js';
1
+ import type { Ref, SimpElement, SimpNode } from '../core/index.js';
2
+ import { createElement as _createElement, createPortal as _createPortal, Fragment as _Fragment, memo as _memo } from '../core/index.js';
2
3
  export declare const Children: {
3
- map(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
4
- forEach(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => void): void;
5
- count(children: SimpReactInternal.SimpNode): number;
6
- toArray(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
7
- only(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpElement;
4
+ map(children: SimpNode, fn: (child: SimpNode, index: number) => SimpNode): SimpNode[];
5
+ forEach(children: SimpNode, fn: (child: SimpNode, index: number) => void): void;
6
+ count(children: SimpNode): number;
7
+ toArray(children: SimpNode): SimpNode[];
8
+ only(children: SimpNode): SimpElement;
8
9
  };
9
- export declare function cloneElement(element: SimpReactInternal.SimpElement, props?: any, ...children: SimpReactInternal.SimpNode[]): SimpReactInternal.SimpElement;
10
- export declare function isValidElement(element: unknown): element is SimpReactInternal.SimpElement;
10
+ export declare function cloneElement(element: SimpElement, props?: any, ...children: SimpNode[]): SimpElement;
11
+ export declare function isValidElement(element: unknown): element is SimpElement;
11
12
  export declare function Suspense(props: {
12
- fallback: SimpReactInternal.SimpNode;
13
- children: SimpReactInternal.SimpNode;
14
- }): SimpReactInternal.SimpNode;
13
+ fallback: SimpNode;
14
+ children: SimpNode;
15
+ }): SimpNode;
15
16
  export declare function StrictMode(props: {
16
- children: SimpReactInternal.SimpNode;
17
- }): SimpReactInternal.SimpNode;
18
- export declare function forwardRef<P, T>(Component: (props: P, ref: SimpReactInternal.Ref<T>) => any): (props: P) => any;
19
- export declare const Fragment: SimpReactInternal.Fragment;
20
- export declare const createElement: typeof SimpReactInternal.createElement;
21
- export declare const createPortal: typeof SimpReactInternal.createPortal;
22
- export declare const memo: typeof SimpReactInternal.memo;
17
+ children: SimpNode;
18
+ }): SimpNode;
19
+ export declare function forwardRef<P, T>(Component: (props: P, ref: Ref<T>) => any): (props: P) => any;
20
+ export declare const Fragment: _Fragment;
21
+ export declare const createElement: typeof _createElement;
22
+ export declare const createPortal: typeof _createPortal;
23
+ export declare const memo: typeof _memo;
23
24
  export declare const flushSync: (value: any) => any;
24
25
  export declare class Component {
25
26
  constructor();
26
27
  }
27
28
  declare const _default: {
28
29
  Children: {
29
- map(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
30
- forEach(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => void): void;
31
- count(children: SimpReactInternal.SimpNode): number;
32
- toArray(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
33
- only(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpElement;
30
+ map(children: SimpNode, fn: (child: SimpNode, index: number) => SimpNode): SimpNode[];
31
+ forEach(children: SimpNode, fn: (child: SimpNode, index: number) => void): void;
32
+ count(children: SimpNode): number;
33
+ toArray(children: SimpNode): SimpNode[];
34
+ only(children: SimpNode): SimpElement;
34
35
  };
35
36
  cloneElement: typeof cloneElement;
36
37
  isValidElement: typeof isValidElement;
37
38
  Suspense: typeof Suspense;
38
39
  StrictMode: typeof StrictMode;
39
40
  forwardRef: typeof forwardRef;
40
- Fragment: SimpReactInternal.Fragment;
41
- createElement: typeof SimpReactInternal.createElement;
42
- createPortal: typeof SimpReactInternal.createPortal;
43
- memo: typeof SimpReactInternal.memo;
41
+ Fragment: _Fragment;
42
+ createElement: typeof _createElement;
43
+ createPortal: typeof _createPortal;
44
+ memo: typeof _memo;
44
45
  flushSync: (value: any) => any;
45
46
  Component: typeof Component;
46
47
  };
package/compat/core.js CHANGED
@@ -1,4 +1,5 @@
1
- import * as SimpReactInternal from '../core/internal.js';
1
+ import { createElement as _createElement, createPortal as _createPortal, Fragment as _Fragment, memo as _memo, } from '../core/index.js';
2
+ import { SIMP_ELEMENT_FLAG_FRAGMENT, SIMP_ELEMENT_FLAG_PORTAL } from '../core/internal.js';
2
3
  import { useCatch, useState } from './hooks.js';
3
4
  export const Children = {
4
5
  map(children, fn) {
@@ -39,10 +40,10 @@ export function cloneElement(element, props, ...children) {
39
40
  if (!isValidElement(element)) {
40
41
  throw new Error(`cloneElement: expected a SimpElement, got ${element}`);
41
42
  }
42
- if ((element.flag & SimpReactInternal.SIMP_ELEMENT_FLAG_PORTAL) !== 0) {
43
+ if ((element.flag & SIMP_ELEMENT_FLAG_PORTAL) !== 0) {
43
44
  throw new Error('cloneElement: the argument must be a SimpElement, but you passed a portal instead.');
44
45
  }
45
- return SimpReactInternal.createElement((element.flag & SimpReactInternal.SIMP_ELEMENT_FLAG_FRAGMENT) !== 0 ? SimpReactInternal.Fragment : element.type, Object.assign({}, element.props, props), arguments.length > 2 ? children : props.children || element.children);
46
+ return createElement((element.flag & SIMP_ELEMENT_FLAG_FRAGMENT) !== 0 ? Fragment : element.type, Object.assign({}, element.props, props), arguments.length > 2 ? children : props.children || element.children);
46
47
  }
47
48
  export function isValidElement(element) {
48
49
  return typeof element === 'object' && element !== null && 'flag' in element;
@@ -69,10 +70,10 @@ export function forwardRef(Component) {
69
70
  return Component(props, props?.ref || null);
70
71
  };
71
72
  }
72
- export const Fragment = SimpReactInternal.Fragment;
73
- export const createElement = SimpReactInternal.createElement;
74
- export const createPortal = SimpReactInternal.createPortal;
75
- export const memo = SimpReactInternal.memo;
73
+ export const Fragment = _Fragment;
74
+ export const createElement = _createElement;
75
+ export const createPortal = _createPortal;
76
+ export const memo = _memo;
76
77
  export const flushSync = (value) => value;
77
78
  export class Component {
78
79
  constructor() {
package/compat/dom.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import * as SimpReactShared from '../shared/index.js';
2
- export declare const hydrate: typeof SimpReactShared.noop;
3
- export declare const render: (element: SimpReactShared.Nullable<import("../core/createElement.js").SimpElement>, container: SimpReactShared.Nullable<Element | DocumentFragment>) => void;
1
+ import { noop } from '../shared/index.js';
2
+ export declare const hydrate: typeof noop;
3
+ export declare const render: (element: import("../shared/index.js").Nullable<import("../core/createElement.js").SimpElement>, container: import("../shared/index.js").Nullable<Element | DocumentFragment>) => void;
4
4
  export declare const createRoot: (container: Element | DocumentFragment) => import("../dom/render.js").SimpRoot;
5
5
  declare const _default: {
6
- hydrate: typeof SimpReactShared.noop;
7
- render: (element: SimpReactShared.Nullable<import("../core/createElement.js").SimpElement>, container: SimpReactShared.Nullable<Element | DocumentFragment>) => void;
6
+ hydrate: typeof noop;
7
+ render: (element: import("../shared/index.js").Nullable<import("../core/createElement.js").SimpElement>, container: import("../shared/index.js").Nullable<Element | DocumentFragment>) => void;
8
8
  createRoot: (container: Element | DocumentFragment) => import("../dom/render.js").SimpRoot;
9
9
  };
10
10
  export default _default;
package/compat/dom.js CHANGED
@@ -1,9 +1,9 @@
1
- import * as SimpReactDOM from '../dom/index.js';
2
- import * as SimpReactShared from '../shared/index.js';
1
+ import { createCreateRoot, createRenderer } from '../dom/index.js';
2
+ import { noop } from '../shared/index.js';
3
3
  import { renderRuntime } from './renderRuntime.js';
4
- export const hydrate = SimpReactShared.noop;
5
- export const render = SimpReactDOM.createRenderer(renderRuntime);
6
- export const createRoot = SimpReactDOM.createCreateRoot(renderRuntime);
4
+ export const hydrate = noop;
5
+ export const render = createRenderer(renderRuntime);
6
+ export const createRoot = createCreateRoot(renderRuntime);
7
7
  export default {
8
8
  hydrate,
9
9
  render,
package/compat/hooks.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { type DependencyList } from '../hooks/index.js';
2
- import * as SimpReactShared from '../shared/index.js';
1
+ import { type DependencyList } from '../shared/index.js';
3
2
  export declare const useRerender: () => () => void;
4
3
  export declare const useState: import("../hooks/index.js").UseState;
5
- export declare const useEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
6
- export declare const useLayoutEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
7
- export declare const useInsertionEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
4
+ export declare const useEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
5
+ export declare const useLayoutEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
6
+ export declare const useInsertionEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
8
7
  export declare const useRef: import("../hooks/index.js").UseRef;
9
8
  export declare const useCatch: (cb: (error: any) => void) => void;
10
9
  export declare function useSyncExternalStore<T>(subscribe: (callback: () => void) => () => void, getSnapshot: () => T): T;
@@ -19,9 +18,9 @@ declare const _default: {
19
18
  useMemo: typeof useMemo;
20
19
  useCallback: typeof useCallback;
21
20
  useState: import("../hooks/index.js").UseState;
22
- useEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
23
- useLayoutEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
24
- useInsertionEffect: (effect: SimpReactShared.Effect, deps?: SimpReactShared.DependencyList) => void;
21
+ useEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
22
+ useLayoutEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
23
+ useInsertionEffect: (effect: import("../shared/index.js").Effect, deps?: DependencyList) => void;
25
24
  useRef: import("../hooks/index.js").UseRef;
26
25
  };
27
26
  export default _default;
package/compat/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createUseCatch, createUseEffect, createUseRef, createUseRerender, createUseState, } from '../hooks/index.js';
2
- import * as SimpReactShared from '../shared/index.js';
1
+ import { createUseCatch, createUseEffect, createUseRef, createUseRerender, createUseState } from '../hooks/index.js';
2
+ import { shallowEqual } from '../shared/index.js';
3
3
  import { renderRuntime } from './renderRuntime.js';
4
4
  export const useRerender = createUseRerender(renderRuntime);
5
5
  export const useState = createUseState(renderRuntime);
@@ -56,7 +56,7 @@ export function useMemo(factory, deps) {
56
56
  deps: undefined,
57
57
  value: undefined,
58
58
  });
59
- if (!SimpReactShared.shallowEqual(ref.current.deps, deps)) {
59
+ if (!shallowEqual(ref.current.deps, deps)) {
60
60
  ref.current.value = factory();
61
61
  ref.current.deps = deps;
62
62
  }
package/compat/index.d.ts CHANGED
@@ -1,44 +1,101 @@
1
- export * from './context.js';
2
- export * from './core.js';
3
- export * from './dom.js';
4
- export * from './hooks.js';
5
- export * from './jsx-runtime.js';
6
- declare const _default: {
7
- jsx: typeof import("../jsx-runtime/index.js").jsx;
8
- jsxDEV: typeof import("../jsx-runtime/index.js").jsx;
9
- jsxs: typeof import("../jsx-runtime/index.js").jsx;
10
- useSyncExternalStore: typeof import("./hooks.js").useSyncExternalStore;
11
- useReducer: typeof import("./hooks.js").useReducer;
12
- useId: typeof import("./hooks.js").useId;
13
- useMemo: typeof import("./hooks.js").useMemo;
14
- useCallback: typeof import("./hooks.js").useCallback;
15
- useState: import("../hooks/index.js").UseState;
16
- useEffect: (effect: import("../shared/public.js").Effect, deps?: import("../shared/public.js").DependencyList) => void;
17
- useLayoutEffect: (effect: import("../shared/public.js").Effect, deps?: import("../shared/public.js").DependencyList) => void;
18
- useInsertionEffect: (effect: import("../shared/public.js").Effect, deps?: import("../shared/public.js").DependencyList) => void;
19
- useRef: import("../hooks/index.js").UseRef;
20
- hydrate: typeof import("../shared/utils.js").noop;
21
- render: (element: import("../shared/public.js").Nullable<import("../core/createElement.js").SimpElement>, container: import("../shared/public.js").Nullable<Element | DocumentFragment>) => void;
22
- createRoot: (container: Element | DocumentFragment) => import("../dom/render.js").SimpRoot;
23
- Children: {
24
- map(children: import("../core/createElement.js").SimpNode, fn: (child: import("../core/createElement.js").SimpNode, index: number) => import("../core/createElement.js").SimpNode): import("../core/createElement.js").SimpNode[];
25
- forEach(children: import("../core/createElement.js").SimpNode, fn: (child: import("../core/createElement.js").SimpNode, index: number) => void): void;
26
- count(children: import("../core/createElement.js").SimpNode): number;
27
- toArray(children: import("../core/createElement.js").SimpNode): import("../core/createElement.js").SimpNode[];
28
- only(children: import("../core/createElement.js").SimpNode): import("../core/createElement.js").SimpElement;
29
- };
30
- cloneElement: typeof import("./core.js").cloneElement;
31
- isValidElement: typeof import("./core.js").isValidElement;
32
- Suspense: typeof import("./core.js").Suspense;
33
- StrictMode: typeof import("./core.js").StrictMode;
34
- forwardRef: typeof import("./core.js").forwardRef;
35
- Fragment: import("../core/fragment.js").Fragment;
36
- createElement: typeof import("../core/createElement.js").createElement;
37
- createPortal: typeof import("../core/portal.js").createPortal;
38
- memo: typeof import("../core/memo.js").memo;
39
- flushSync: (value: any) => any;
40
- Component: typeof import("./core.js").Component;
41
- createContext: import("../context/index.js").CreateContext;
42
- useContext: import("../context/index.js").UseContext;
1
+ import type { SimpContext } from '../context/index.js';
2
+ import type {
3
+ Attributes,
4
+ FC,
5
+ FunctionalComponent,
6
+ Key,
7
+ Ref,
8
+ RefAttributes,
9
+ RefObject,
10
+ SimpElement,
11
+ SimpNode,
12
+ SimpRenderRuntime,
13
+ } from '../core/index.js';
14
+ import type { SimpRoot } from '../dom/index.js';
15
+ import type { Dispatch, SetStateAction } from '../hooks/index.js';
16
+ import type { DependencyList, Effect, Maybe, Nullable } from '../shared/index.js';
17
+
18
+ export type { SimpContext } from '../context/index.js';
19
+ export type {
20
+ Attributes,
21
+ FC,
22
+ FunctionalComponent,
23
+ Key,
24
+ Ref,
25
+ RefAttributes,
26
+ RefObject,
27
+ SimpElement,
28
+ SimpNode,
29
+ SimpRenderRuntime,
30
+ } from '../core/index.js';
31
+ export type { SimpRoot } from '../dom/index.js';
32
+ export type { Dispatch, SetStateAction } from '../hooks/index.js';
33
+ export type { DependencyList, Effect, Maybe, Nullable } from '../shared/index.js';
34
+
35
+ export declare const renderRuntime: SimpRenderRuntime;
36
+
37
+ export declare function jsx<P = {}>(type: string | FC<P>, props?: P, key?: Maybe<Key>): SimpElement<P>;
38
+ export declare function jsxs<P = {}>(type: string | FC<P>, props?: P, key?: Maybe<Key>): SimpElement<P>;
39
+ export declare function jsxDEV<P = {}>(type: string | FC<P>, props?: P, key?: Maybe<Key>): SimpElement<P>;
40
+
41
+ export declare function useSyncExternalStore<T>(
42
+ subscribe: (callback: () => void) => () => void,
43
+ getSnapshot: () => T
44
+ ): T;
45
+ export declare function useReducer<R extends (state: any, action: any) => any, I>(
46
+ reducer: R,
47
+ initializerArg: I,
48
+ initializer?: (arg: I) => ReturnType<R>
49
+ ): [ReturnType<R>, (action: Parameters<R>[1]) => void];
50
+ export declare function useId(prefix?: string): string;
51
+ export declare function useMemo<T>(factory: () => T, deps: DependencyList): T;
52
+ export declare function useCallback<T>(cb: T, deps: DependencyList): T;
53
+ export declare function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
54
+ export declare function useState<S>(): [S | undefined, Dispatch<SetStateAction<S | undefined>>];
55
+ export declare function useEffect(effect: Effect, deps?: DependencyList): void;
56
+ export declare function useLayoutEffect(effect: Effect, deps?: DependencyList): void;
57
+ export declare function useInsertionEffect(effect: Effect, deps?: DependencyList): void;
58
+ export declare function useRef<T>(initialValue: T): RefObject<T>;
59
+ export declare function useRef<T>(initialValue: T | null): RefObject<T | null>;
60
+ export declare function useRef<T = undefined>(initialValue?: T): RefObject<T | undefined>;
61
+ export declare function useCatch(errorBoundary: FC): [Error | null, (error: Error) => void];
62
+
63
+ export declare function hydrate(): void;
64
+ export declare function render(element: SimpElement, parentReference: Nullable<HTMLElement>): void;
65
+ export declare function createRoot(container: Element | DocumentFragment): SimpRoot;
66
+
67
+ export declare const Children: {
68
+ map(children: SimpNode, fn: (child: SimpNode, index: number) => SimpNode): SimpNode[];
69
+ forEach(children: SimpNode, fn: (child: SimpNode, index: number) => void): void;
70
+ count(children: SimpNode): number;
71
+ toArray(children: SimpNode): SimpNode[];
72
+ only(children: SimpNode): SimpElement;
43
73
  };
44
- export default _default;
74
+
75
+ export declare function cloneElement(element: SimpElement, props?: any, ...children: SimpNode[]): SimpElement;
76
+ export declare function isValidElement(element: unknown): element is SimpElement;
77
+ export declare function Suspense(props: { fallback: SimpNode; children: SimpNode }): SimpNode;
78
+ export declare function StrictMode(props: { children: SimpNode }): SimpNode;
79
+ export declare function forwardRef<P, T>(Component: (props: P, ref: Ref<T>) => any): FC;
80
+ export declare function Fragment(props: { children?: SimpNode }): SimpNode;
81
+
82
+ export declare function createElement<P extends {}, T>(
83
+ type: string,
84
+ props?: (RefAttributes<T> & P) | null,
85
+ ...children: SimpNode[]
86
+ ): SimpElement<P>;
87
+ export declare function createElement<P extends {}>(
88
+ type: FunctionalComponent<P>,
89
+ props?: (Attributes & P) | null,
90
+ ...children: SimpNode[]
91
+ ): SimpElement<P>;
92
+
93
+ export declare function createPortal(children: SimpNode, container: any): SimpElement;
94
+
95
+ export declare function memo(Component: FC, compare: (objA: any, objB: any) => boolean): FC;
96
+ export declare function flushSync(value: any): any;
97
+
98
+ export declare class Component {}
99
+
100
+ export declare function createContext<T>(defaultValue: T): SimpContext<T>;
101
+ export declare function useContext<T>(context: SimpContext<T>): T;
package/compat/index.js CHANGED
@@ -3,15 +3,18 @@ import coreDefault from './core.js';
3
3
  import domDefault from './dom.js';
4
4
  import hooksDefault from './hooks.js';
5
5
  import jsxRuntimeDefault from './jsx-runtime.js';
6
+ import renderRuntimeDefault from './renderRuntime.js';
6
7
  export * from './context.js';
7
8
  export * from './core.js';
8
9
  export * from './dom.js';
9
10
  export * from './hooks.js';
10
11
  export * from './jsx-runtime.js';
12
+ export * from './renderRuntime.js';
11
13
  export default {
12
14
  ...contextDefault,
13
15
  ...coreDefault,
14
16
  ...domDefault,
15
17
  ...hooksDefault,
16
18
  ...jsxRuntimeDefault,
19
+ ...renderRuntimeDefault,
17
20
  };
@@ -1,10 +1,10 @@
1
- import * as SimpReactJSXRuntime from '../jsx-runtime/index.js';
2
- export declare const jsx: typeof SimpReactJSXRuntime.jsx;
3
- export declare const jsxDEV: typeof SimpReactJSXRuntime.jsx;
4
- export declare const jsxs: typeof SimpReactJSXRuntime.jsx;
1
+ import { jsx as _jsx } from '../jsx-runtime/index.js';
2
+ export declare const jsx: typeof _jsx;
3
+ export declare const jsxDEV: typeof _jsx;
4
+ export declare const jsxs: typeof _jsx;
5
5
  declare const _default: {
6
- jsx: typeof SimpReactJSXRuntime.jsx;
7
- jsxDEV: typeof SimpReactJSXRuntime.jsx;
8
- jsxs: typeof SimpReactJSXRuntime.jsx;
6
+ jsx: typeof _jsx;
7
+ jsxDEV: typeof _jsx;
8
+ jsxs: typeof _jsx;
9
9
  };
10
10
  export default _default;
@@ -1,7 +1,7 @@
1
- import * as SimpReactJSXRuntime from '../jsx-runtime/index.js';
2
- export const jsx = SimpReactJSXRuntime.jsx;
3
- export const jsxDEV = SimpReactJSXRuntime.jsxDEV;
4
- export const jsxs = SimpReactJSXRuntime.jsxs;
1
+ import { jsx as _jsx, jsxDEV as _jsxDEV, jsxs as _jsxs } from '../jsx-runtime/index.js';
2
+ export const jsx = _jsx;
3
+ export const jsxDEV = _jsxDEV;
4
+ export const jsxs = _jsxs;
5
5
  export default {
6
6
  jsx,
7
7
  jsxDEV,
@@ -1,2 +1,6 @@
1
1
  import type { SimpRenderRuntime } from '../core/internal.js';
2
2
  export declare const renderRuntime: SimpRenderRuntime;
3
+ declare const _default: {
4
+ renderRuntime: SimpRenderRuntime;
5
+ };
6
+ export default _default;
@@ -10,5 +10,8 @@ export const renderRuntime = {
10
10
  currentRenderingFCElement: null,
11
11
  renderPhase: null,
12
12
  };
13
+ export default {
14
+ renderRuntime,
15
+ };
13
16
  // TODO
14
17
  window.__SIMP_RUNTIME__ = renderRuntime;
@@ -1,8 +1,5 @@
1
- import type { FC, SimpNode } from '../core/index.js';
2
-
3
- export type Cleanup = () => void;
4
- export type Effect = () => void | Cleanup;
5
- export type DependencyList = readonly unknown[];
1
+ import type { FC, SimpElement, SimpNode } from '../core/index.js';
2
+ import type { DependencyList, Effect } from '../shared/index.js';
6
3
 
7
4
  export interface ComponentRenderContext<S = {}> {
8
5
  state: S;
@@ -11,6 +8,8 @@ export interface ComponentRenderContext<S = {}> {
11
8
  catchers: Array<(error: any) => void>;
12
9
  }
13
10
 
14
- declare function component<P = {}, S = {}>(Component: (props: P, ctx: ComponentRenderContext<S>) => SimpNode): FC<P>;
11
+ export declare function component<P = {}, S = {}>(
12
+ Component: (props: P, ctx: ComponentRenderContext<S>) => SimpNode
13
+ ): FC<P>;
15
14
 
16
- export function componentRenderer(component: FC, element: SimpElement): SimpNode;
15
+ export declare function componentRenderer(component: FC, element: SimpElement): SimpNode;
@@ -1,4 +1,4 @@
1
- import type { FunctionalComponent, SimpNode } from '../core/index.js';
1
+ import type { FC, SimpNode, SimpRenderRuntime } from '../core/index.js';
2
2
 
3
3
  export interface ProviderProps<T> {
4
4
  value: T;
@@ -16,16 +16,16 @@ export type SimpContext<T> = {
16
16
 
17
17
  export type ContextType<C extends SimpContext<any>> = C extends SimpContext<infer T> ? T : never;
18
18
 
19
- export type Provider<T> = FunctionalComponent<ProviderProps<T>>;
20
- export type Consumer<T> = FunctionalComponent<ConsumerProps<T>>;
19
+ export type Provider<T> = FC<ProviderProps<T>>;
20
+ export type Consumer<T> = FC<ConsumerProps<T>>;
21
21
 
22
22
  export interface CreateContext {
23
23
  <T>(defaultValue: T): SimpContext<T>;
24
24
  }
25
25
 
26
- declare function createCreateContext(renderRuntime: SimpRenderRuntime): CreateContext;
26
+ export declare function createCreateContext(renderRuntime: SimpRenderRuntime): CreateContext;
27
27
 
28
28
  export interface UseContext {
29
29
  <T>(context: SimpContext<T>): T;
30
30
  }
31
- declare function createUseContext(renderRuntime: SimpRenderRuntime): UseContext;
31
+ export declare function createUseContext(renderRuntime: SimpRenderRuntime): UseContext;
package/context/index.js CHANGED
@@ -18,7 +18,7 @@ export function createCreateContext(renderRuntime) {
18
18
  if (!contextMap) {
19
19
  currentElement.context = contextMap = new Map();
20
20
  }
21
- if (contextMap && renderPhase === MOUNTING_PHASE) {
21
+ else if (renderPhase === MOUNTING_PHASE) {
22
22
  currentElement.context = contextMap = new Map(currentElement.context);
23
23
  }
24
24
  if (renderPhase === MOUNTING_PHASE) {
package/core/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import type { HostReference, TraversalStack } from './internal.js';
2
- import type { Maybe, Nullable, SimpText } from '../shared/index.js';
1
+ import type { Nullable, SimpText } from '../shared/index.js';
2
+ import type { HostAdapter } from './hostAdapter.js';
3
+
4
+ export { HostAdapter } from './hostAdapter.js';
3
5
 
4
6
  export type ComponentType<P = {}> = FunctionalComponent<P>;
5
7
 
@@ -27,46 +29,42 @@ export interface SimpElement<P = unknown, T extends string | FunctionalComponent
27
29
 
28
30
  export type SimpNode = SimpElement | SimpText | Array<SimpNode> | boolean | null | undefined;
29
31
 
30
- declare function createElement<P extends {}, T>(
32
+ export declare function createElement<P extends {}, T>(
31
33
  type: string,
32
34
  props?: (RefAttributes<T> & P) | null,
33
35
  ...children: SimpNode[]
34
36
  ): SimpElement<P>;
35
- declare function createElement<P extends {}>(
37
+ export declare function createElement<P extends {}>(
36
38
  type: FunctionalComponent<P>,
37
39
  props?: (Attributes & P) | null,
38
40
  ...children: SimpNode[]
39
41
  ): SimpElement<P>;
40
42
 
41
- declare function createPortal<HostRef = {}>(children: SimpNode, container: HostRef): SimpElement;
43
+ export declare function createPortal<HostRef = {}>(children: SimpNode, container: HostRef): SimpElement;
42
44
 
43
- declare function Fragment(props: PropsWithChildren): SimpElement;
45
+ export declare function Fragment(props: PropsWithChildren): SimpElement;
44
46
 
45
47
  export type FunctionalComponent<P = {}> = (props: P) => SimpNode;
46
48
  export type FC<P = {}> = FunctionalComponent<P>;
47
49
 
48
50
  export type PropsWithChildren<P = {}> = P & { children?: SimpNode | undefined };
49
51
 
50
- declare function memo<P = {}>(Component: FC<P>, compare?: (objA: Readonly<P>, objB: Readonly<P>) => boolean): FC<P>;
52
+ export declare function memo<P = {}>(
53
+ Component: FC<P>,
54
+ compare?: (objA: Readonly<P>, objB: Readonly<P>) => boolean
55
+ ): FC<P>;
56
+
57
+ export declare function withSyncRerender(runtime: SimpRenderRuntime, callback: () => void): void;
51
58
 
52
59
  export interface SimpRuntimeFCRenderer {
53
60
  (component: FC, element: SimpElement): SimpNode;
54
61
  }
55
62
 
56
- export interface RenderMeta {
57
- prevElement: Nullable<SimpElement>;
58
- parentReference: HostReference;
59
- parentAnchorReference: HostReference;
60
- rightSibling: Nullable<SimpElement>;
61
- context: unknown;
62
- hostNamespace: Maybe<string>;
63
- renderRuntime: SimpRenderRuntime;
64
- placeHolderElement: Nullable<SimpElement>;
65
- }
66
-
67
63
  export interface SimpRenderRuntime {
68
64
  hostAdapter: HostAdapter;
69
65
  renderer: SimpRuntimeFCRenderer;
70
- renderStack: TraversalStack<SimpElement, RenderMeta>;
66
+ renderStack: Array<{ node: SimpElement; kind: number; meta: any }>;
71
67
  elementToHostMap: Map<unknown, SimpElement>;
68
+ currentRenderingFCElement: Nullable<SimpElement>;
69
+ renderPhase: Nullable<number>;
72
70
  }
package/core/index.js CHANGED
@@ -2,5 +2,6 @@ import { createElement } from './createElement.js';
2
2
  import { Fragment } from './fragment.js';
3
3
  import { memo } from './memo.js';
4
4
  import { createPortal } from './portal.js';
5
- export { createElement, Fragment, memo, createPortal };
6
- export default { createElement, Fragment, memo, createPortal };
5
+ import { withSyncRerender } from './rerender.js';
6
+ export { createElement, Fragment, memo, createPortal, withSyncRerender };
7
+ export default { createElement, Fragment, memo, createPortal, withSyncRerender };
@@ -4,6 +4,7 @@ export * from './hostAdapter.js';
4
4
  export * from './lifecycleEventBus.js';
5
5
  export * from './memo.js';
6
6
  export * from './mounting.js';
7
+ export * from './mountingChildren.js';
7
8
  export * from './patching.js';
8
9
  export * from './patchingChildren.js';
9
10
  export * from './portal.js';
@@ -12,3 +13,4 @@ export * from './ref.js';
12
13
  export * from './rerender.js';
13
14
  export * from './runtime.js';
14
15
  export * from './unmounting.js';
16
+ export * from './unmountingChildren.js';
package/core/internal.js CHANGED
@@ -4,6 +4,7 @@ export * from './hostAdapter.js';
4
4
  export * from './lifecycleEventBus.js';
5
5
  export * from './memo.js';
6
6
  export * from './mounting.js';
7
+ export * from './mountingChildren.js';
7
8
  export * from './patching.js';
8
9
  export * from './patchingChildren.js';
9
10
  export * from './portal.js';
@@ -12,3 +13,4 @@ export * from './ref.js';
12
13
  export * from './rerender.js';
13
14
  export * from './runtime.js';
14
15
  export * from './unmounting.js';
16
+ export * from './unmountingChildren.js';
@@ -2,7 +2,6 @@ import type { Maybe, Nullable } from '../shared/index.js';
2
2
  import { type SimpElement } from './createElement.js';
3
3
  import { type MountFrame, type MountFrameMeta } from './processStack.js';
4
4
  import { type SimpRenderRuntime } from './runtime.js';
5
- export declare function mount(element: SimpElement, parentReference: unknown, rightSibling: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
5
+ export declare function mount(element: SimpElement, parentReference: unknown, subtreeRightBoundary: Nullable<SimpElement>, context: unknown, hostNamespace: Maybe<string>, renderRuntime: SimpRenderRuntime): void;
6
6
  export declare function _mount(frame: MountFrame): void;
7
7
  export declare function _pushMountEnterFrame(element: SimpElement, meta: MountFrameMeta): void;
8
- export declare function _pushMountArrayChildrenFrame(element: SimpElement, meta: MountFrameMeta): void;