@simpreact/simpreact 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/compat/core.d.ts +46 -0
  2. package/compat/core.js +93 -0
  3. package/compat/dom.d.ts +11 -0
  4. package/compat/dom.js +10 -0
  5. package/compat/hooks.d.ts +26 -0
  6. package/compat/hooks.js +77 -0
  7. package/compat/index.d.ts +42 -0
  8. package/compat/index.js +14 -0
  9. package/compat/jsx-runtime.d.ts +10 -0
  10. package/compat/jsx-runtime.js +9 -0
  11. package/compat/utils.d.ts +1 -0
  12. package/compat/utils.js +3 -0
  13. package/core/context.d.ts +1 -1
  14. package/core/createElement.d.ts +4 -4
  15. package/core/createElement.js +13 -6
  16. package/core/fragment.d.ts +1 -1
  17. package/core/hostAdapter.d.ts +3 -3
  18. package/core/index.d.ts +3 -3
  19. package/core/index.js +4 -4
  20. package/core/internal.d.ts +11 -11
  21. package/core/internal.js +11 -11
  22. package/core/lifecycleEventBus.d.ts +6 -2
  23. package/core/lifecycleEventBus.js +1 -1
  24. package/core/mounting.d.ts +4 -4
  25. package/core/mounting.js +42 -11
  26. package/core/patching.d.ts +4 -4
  27. package/core/patching.js +89 -19
  28. package/core/portal.d.ts +1 -1
  29. package/core/portal.js +1 -1
  30. package/core/ref.d.ts +5 -5
  31. package/core/rerender.d.ts +5 -5
  32. package/core/rerender.js +38 -25
  33. package/core/unmounting.d.ts +3 -3
  34. package/core/unmounting.js +7 -3
  35. package/dom/attach-element-to-dom.d.ts +1 -1
  36. package/dom/attach-element-to-dom.js +1 -1
  37. package/dom/domAdapter.d.ts +1 -1
  38. package/dom/domAdapter.js +10 -5
  39. package/dom/events.d.ts +4 -1
  40. package/dom/events.js +10 -4
  41. package/dom/index.d.ts +2 -2
  42. package/dom/index.js +2 -2
  43. package/dom/props/controlled/index.d.ts +1 -1
  44. package/dom/props/controlled/index.js +3 -3
  45. package/dom/props/controlled/input.d.ts +1 -1
  46. package/dom/props/controlled/input.js +6 -6
  47. package/dom/props/controlled/select.d.ts +1 -1
  48. package/dom/props/controlled/select.js +5 -5
  49. package/dom/props/controlled/textarea.d.ts +1 -1
  50. package/dom/props/controlled/textarea.js +6 -6
  51. package/dom/props/dangerInnerHTML.d.ts +1 -1
  52. package/dom/props/index.d.ts +1 -1
  53. package/dom/props/index.js +1 -1
  54. package/dom/props/props.d.ts +1 -1
  55. package/dom/props/props.js +6 -6
  56. package/dom/props/style.js +6 -3
  57. package/dom/render.d.ts +1 -1
  58. package/dom/render.js +5 -5
  59. package/hooks/index.d.ts +7 -1
  60. package/hooks/index.js +43 -10
  61. package/jsx-runtime/index.d.ts +3 -3
  62. package/package.json +8 -1
  63. package/shared/index.js +3 -3
  64. package/shared/utils.d.ts +2 -1
  65. package/shared/utils.js +16 -0
@@ -0,0 +1,46 @@
1
+ import * as SimpReactInternal from '../core/internal.js';
2
+ import { identity } from './utils.js';
3
+ export declare const Children: {
4
+ map(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
5
+ forEach(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => void): void;
6
+ count(children: SimpReactInternal.SimpNode): number;
7
+ toArray(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
8
+ only(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpElement;
9
+ };
10
+ export declare function cloneElement(element: SimpReactInternal.SimpElement, props?: any, ...children: SimpReactInternal.SimpNode[]): SimpReactInternal.SimpElement;
11
+ export declare function isValidElement(element: unknown): element is SimpReactInternal.SimpElement;
12
+ export declare function Suspense(props: {
13
+ fallback: SimpReactInternal.SimpNode;
14
+ children: SimpReactInternal.SimpNode;
15
+ }): SimpReactInternal.SimpNode;
16
+ export declare function forwardRef<P, T>(Component: (props: P, ref: SimpReactInternal.Ref<T>) => any): (props: P) => any;
17
+ export declare const Fragment: SimpReactInternal.Fragment;
18
+ export declare const createElement: typeof SimpReactInternal.createElement;
19
+ export declare const createContext: typeof SimpReactInternal.createContext;
20
+ export declare const createPortal: typeof SimpReactInternal.createPortal;
21
+ export declare const memo: typeof identity;
22
+ export declare const flushSync: typeof identity;
23
+ export declare class Component {
24
+ constructor();
25
+ }
26
+ declare const _default: {
27
+ Children: {
28
+ map(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
29
+ forEach(children: SimpReactInternal.SimpNode, fn: (child: SimpReactInternal.SimpNode, index: number) => void): void;
30
+ count(children: SimpReactInternal.SimpNode): number;
31
+ toArray(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpNode[];
32
+ only(children: SimpReactInternal.SimpNode): SimpReactInternal.SimpElement;
33
+ };
34
+ cloneElement: typeof cloneElement;
35
+ isValidElement: typeof isValidElement;
36
+ Suspense: typeof Suspense;
37
+ forwardRef: typeof forwardRef;
38
+ Fragment: SimpReactInternal.Fragment;
39
+ createElement: typeof SimpReactInternal.createElement;
40
+ createContext: typeof SimpReactInternal.createContext;
41
+ createPortal: typeof SimpReactInternal.createPortal;
42
+ memo: typeof identity;
43
+ flushSync: typeof identity;
44
+ Component: typeof Component;
45
+ };
46
+ export default _default;
package/compat/core.js ADDED
@@ -0,0 +1,93 @@
1
+ import * as SimpReactInternal from '../core/internal.js';
2
+ import * as SimpReactHooks from '../hooks/index.js';
3
+ import { identity } from './utils.js';
4
+ export const Children = {
5
+ map(children, fn) {
6
+ return Children.toArray(children).map(fn);
7
+ },
8
+ forEach(children, fn) {
9
+ Children.toArray(children).forEach(fn);
10
+ },
11
+ count(children) {
12
+ return Children.toArray(children).length;
13
+ },
14
+ toArray(children) {
15
+ const result = [];
16
+ function traverse(node) {
17
+ if (node == null || typeof node === 'boolean') {
18
+ return;
19
+ }
20
+ if (Array.isArray(node)) {
21
+ for (const child of node) {
22
+ traverse(child);
23
+ }
24
+ return;
25
+ }
26
+ result.push(node);
27
+ }
28
+ traverse(children);
29
+ return result;
30
+ },
31
+ only(children) {
32
+ const array = Children.toArray(children);
33
+ if (array.length !== 1 || !isValidElement(array[0])) {
34
+ throw new Error('Children.only expected a single SimpElement child.');
35
+ }
36
+ return array[0];
37
+ },
38
+ };
39
+ export function cloneElement(element, props, ...children) {
40
+ if (!isValidElement(element)) {
41
+ throw new Error(`cloneElement: expected a SimpElement, got ${element}`);
42
+ }
43
+ if (element.flag === 'PORTAL') {
44
+ throw new Error('cloneElement: the argument must be a SimpElement, but you passed a portal instead.');
45
+ }
46
+ return SimpReactInternal.createElement(element.flag === 'FRAGMENT' ? SimpReactInternal.Fragment : element.type, Object.assign({}, element.props, props), arguments.length > 2 ? children : props.children || element.children);
47
+ }
48
+ export function isValidElement(element) {
49
+ return typeof element === 'object' && element !== null && 'flag' in element;
50
+ }
51
+ export function Suspense(props) {
52
+ const [isSuspended, setIsSuspended] = SimpReactHooks.useState(false);
53
+ SimpReactHooks.useCatch(error => {
54
+ if (isSuspended) {
55
+ return;
56
+ }
57
+ if (error instanceof Promise) {
58
+ setIsSuspended(true);
59
+ error.then(() => setIsSuspended(false));
60
+ }
61
+ });
62
+ return isSuspended ? props.fallback : props.children;
63
+ }
64
+ export function forwardRef(Component) {
65
+ return function Forwarded(props) {
66
+ return Component(props, props?.ref || null);
67
+ };
68
+ }
69
+ export const Fragment = SimpReactInternal.Fragment;
70
+ export const createElement = SimpReactInternal.createElement;
71
+ export const createContext = SimpReactInternal.createContext;
72
+ export const createPortal = SimpReactInternal.createPortal;
73
+ export const memo = identity;
74
+ export const flushSync = identity;
75
+ export class Component {
76
+ constructor() {
77
+ throw new Error('Not implemented.');
78
+ }
79
+ }
80
+ export default {
81
+ Children,
82
+ cloneElement,
83
+ isValidElement,
84
+ Suspense,
85
+ forwardRef,
86
+ Fragment,
87
+ createElement,
88
+ createContext,
89
+ createPortal,
90
+ memo,
91
+ flushSync,
92
+ Component,
93
+ };
@@ -0,0 +1,11 @@
1
+ import * as SimpReactDOM from '../dom/index.js';
2
+ import * as SimpReactShared from '../shared/index.js';
3
+ export declare const hydrate: typeof SimpReactShared.noop;
4
+ export declare const render: typeof SimpReactDOM.render;
5
+ export declare const createRoot: typeof SimpReactDOM.createRoot;
6
+ declare const _default: {
7
+ hydrate: typeof SimpReactShared.noop;
8
+ render: typeof SimpReactDOM.render;
9
+ createRoot: typeof SimpReactDOM.createRoot;
10
+ };
11
+ export default _default;
package/compat/dom.js ADDED
@@ -0,0 +1,10 @@
1
+ import * as SimpReactDOM from '../dom/index.js';
2
+ import * as SimpReactShared from '../shared/index.js';
3
+ export const hydrate = SimpReactShared.noop;
4
+ export const render = SimpReactDOM.render;
5
+ export const createRoot = SimpReactDOM.createRoot;
6
+ export default {
7
+ hydrate,
8
+ render,
9
+ createRoot,
10
+ };
@@ -0,0 +1,26 @@
1
+ import * as SimpReactHooks from '../hooks/index.js';
2
+ export declare function useSyncExternalStore<T>(subscribe: (callback: () => void) => () => void, getSnapshot: () => T): T;
3
+ export declare function useReducer<R extends (state: any, action: any) => any, I>(reducer: R, initializerArg: I, initializer?: (arg: I) => ReturnType<R>): [ReturnType<R>, (action: Parameters<R>[1]) => void];
4
+ export declare function useId(prefix?: string): string;
5
+ export declare function useMemo<T>(factory: () => T, deps: SimpReactHooks.DependencyList): T;
6
+ export declare function useCallback<T>(cb: T, deps: SimpReactHooks.DependencyList): T;
7
+ export declare const useState: typeof SimpReactHooks.useState;
8
+ export declare const useEffect: typeof SimpReactHooks.useEffect;
9
+ export declare const useLayoutEffect: typeof SimpReactHooks.useEffect;
10
+ export declare const useInsertionEffect: typeof SimpReactHooks.useEffect;
11
+ export declare const useRef: typeof SimpReactHooks.useRef;
12
+ export declare const useContext: typeof SimpReactHooks.useContext;
13
+ declare const _default: {
14
+ useSyncExternalStore: typeof useSyncExternalStore;
15
+ useReducer: typeof useReducer;
16
+ useId: typeof useId;
17
+ useMemo: typeof useMemo;
18
+ useCallback: typeof useCallback;
19
+ useState: typeof SimpReactHooks.useState;
20
+ useEffect: typeof SimpReactHooks.useEffect;
21
+ useLayoutEffect: typeof SimpReactHooks.useEffect;
22
+ useInsertionEffect: typeof SimpReactHooks.useEffect;
23
+ useRef: typeof SimpReactHooks.useRef;
24
+ useContext: typeof SimpReactHooks.useContext;
25
+ };
26
+ export default _default;
@@ -0,0 +1,77 @@
1
+ import * as SimpReactHooks from '../hooks/index.js';
2
+ export function useSyncExternalStore(subscribe, getSnapshot) {
3
+ const rerender = SimpReactHooks.useRerender();
4
+ const lastSnapshotRef = SimpReactHooks.useRef(getSnapshot());
5
+ SimpReactHooks.useEffect(() => {
6
+ function checkForUpdates() {
7
+ const nextSnapshot = getSnapshot();
8
+ if (!Object.is(lastSnapshotRef.current, nextSnapshot)) {
9
+ lastSnapshotRef.current = nextSnapshot;
10
+ rerender();
11
+ }
12
+ }
13
+ const unsubscribe = subscribe(checkForUpdates);
14
+ checkForUpdates();
15
+ return unsubscribe;
16
+ }, [subscribe, getSnapshot]);
17
+ return lastSnapshotRef.current;
18
+ }
19
+ export function useReducer(reducer, initializerArg, initializer) {
20
+ const rerender = SimpReactHooks.useRerender();
21
+ const reducerRef = SimpReactHooks.useRef(reducer);
22
+ reducerRef.current = reducer;
23
+ const stateRef = SimpReactHooks.useRef([
24
+ initializer ? initializer(initializerArg) : initializerArg,
25
+ function dispatch(action) {
26
+ const newState = reducerRef.current(stateRef.current[0], action);
27
+ if (Object.is(newState, stateRef.current[0])) {
28
+ return;
29
+ }
30
+ stateRef.current[0] = newState;
31
+ rerender();
32
+ },
33
+ ]);
34
+ return stateRef.current;
35
+ }
36
+ let globalId = 0;
37
+ export function useId(prefix = 'id') {
38
+ const idRef = SimpReactHooks.useRef('');
39
+ if (idRef.current === '') {
40
+ globalId += 1;
41
+ idRef.current = `${prefix}-${globalId}`;
42
+ }
43
+ return idRef.current;
44
+ }
45
+ export function useMemo(factory, deps) {
46
+ const ref = SimpReactHooks.useRef({
47
+ deps: undefined,
48
+ value: undefined,
49
+ });
50
+ if (!SimpReactHooks.areDepsEqual(ref.current.deps, deps)) {
51
+ ref.current.value = factory();
52
+ ref.current.deps = deps;
53
+ }
54
+ return ref.current.value;
55
+ }
56
+ export function useCallback(cb, deps) {
57
+ return useMemo(() => cb, deps);
58
+ }
59
+ export const useState = SimpReactHooks.useState;
60
+ export const useEffect = SimpReactHooks.useEffect;
61
+ export const useLayoutEffect = SimpReactHooks.useEffect;
62
+ export const useInsertionEffect = SimpReactHooks.useEffect;
63
+ export const useRef = SimpReactHooks.useRef;
64
+ export const useContext = SimpReactHooks.useContext;
65
+ export default {
66
+ useSyncExternalStore,
67
+ useReducer,
68
+ useId,
69
+ useMemo,
70
+ useCallback,
71
+ useState,
72
+ useEffect,
73
+ useLayoutEffect,
74
+ useInsertionEffect,
75
+ useRef,
76
+ useContext,
77
+ };
@@ -0,0 +1,42 @@
1
+ export * from './core.js';
2
+ export * from './dom.js';
3
+ export * from './hooks.js';
4
+ export * from './jsx-runtime.js';
5
+ declare const _default: {
6
+ jsx: typeof import("../jsx-runtime/index.js").jsx;
7
+ jsxDEV: typeof import("../jsx-runtime/index.js").jsx;
8
+ jsxs: typeof import("../jsx-runtime/index.js").jsx;
9
+ useSyncExternalStore: typeof import("./hooks.js").useSyncExternalStore;
10
+ useReducer: typeof import("./hooks.js").useReducer;
11
+ useId: typeof import("./hooks.js").useId;
12
+ useMemo: typeof import("./hooks.js").useMemo;
13
+ useCallback: typeof import("./hooks.js").useCallback;
14
+ useState: typeof import("../hooks/index.js").useState;
15
+ useEffect: typeof import("../hooks/index.js").useEffect;
16
+ useLayoutEffect: typeof import("../hooks/index.js").useEffect;
17
+ useInsertionEffect: typeof import("../hooks/index.js").useEffect;
18
+ useRef: typeof import("../hooks/index.js").useRef;
19
+ useContext: typeof import("../hooks/index.js").useContext;
20
+ hydrate: typeof import("../shared/utils.js").noop;
21
+ render: typeof import("../dom/render.js").render;
22
+ createRoot: typeof import("../dom/render.js").createRoot;
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
+ forwardRef: typeof import("./core.js").forwardRef;
34
+ Fragment: import("../core/fragment.js").Fragment;
35
+ createElement: typeof import("../core/createElement.js").createElement;
36
+ createContext: typeof import("../core/context.js").createContext;
37
+ createPortal: typeof import("../core/portal.js").createPortal;
38
+ memo: typeof import("./utils.js").identity;
39
+ flushSync: typeof import("./utils.js").identity;
40
+ Component: typeof import("./core.js").Component;
41
+ };
42
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import coreDefault from './core.js';
2
+ import domDefault from './dom.js';
3
+ import hooksDefault from './hooks.js';
4
+ import jsxRuntimeDefault from './jsx-runtime.js';
5
+ export * from './core.js';
6
+ export * from './dom.js';
7
+ export * from './hooks.js';
8
+ export * from './jsx-runtime.js';
9
+ export default {
10
+ ...coreDefault,
11
+ ...domDefault,
12
+ ...hooksDefault,
13
+ ...jsxRuntimeDefault,
14
+ };
@@ -0,0 +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;
5
+ declare const _default: {
6
+ jsx: typeof SimpReactJSXRuntime.jsx;
7
+ jsxDEV: typeof SimpReactJSXRuntime.jsx;
8
+ jsxs: typeof SimpReactJSXRuntime.jsx;
9
+ };
10
+ export default _default;
@@ -0,0 +1,9 @@
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;
5
+ export default {
6
+ jsx,
7
+ jsxDEV,
8
+ jsxs,
9
+ };
@@ -0,0 +1 @@
1
+ export declare function identity(value: any): any;
@@ -0,0 +1,3 @@
1
+ export function identity(value) {
2
+ return value;
3
+ }
package/core/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SimpNode } from './createElement';
1
+ import type { SimpNode } from './createElement.js';
2
2
  type Provider<T = any> = (props: {
3
3
  value: T;
4
4
  children: SimpNode;
@@ -1,6 +1,6 @@
1
- import type { Many, Maybe, Nullable, SimpText } from '../shared';
2
- import type { HostReference } from './hostAdapter';
3
- import type { SimpContextMap } from './context';
1
+ import type { Many, Maybe, Nullable, SimpText } from '../shared/index.js';
2
+ import type { HostReference } from './hostAdapter.js';
3
+ import type { SimpContextMap } from './context.js';
4
4
  export type SimpNode = SimpElement | SimpText | Array<SimpNode> | boolean | null | undefined;
5
5
  export type Key = string | number | bigint;
6
6
  export interface FunctionComponent {
@@ -17,7 +17,7 @@ export interface SimpElement {
17
17
  flag: SimpElementFlag;
18
18
  parent: Nullable<SimpElement>;
19
19
  key?: Maybe<Key>;
20
- type?: Maybe<string | FunctionComponent>;
20
+ type?: string | FunctionComponent;
21
21
  props?: any;
22
22
  children?: Maybe<SimpNode>;
23
23
  className?: Maybe<string>;
@@ -1,6 +1,6 @@
1
- import { isSimpText } from '../shared';
2
- import { Fragment } from './fragment';
3
- import { isConsumer, isProvider } from './context';
1
+ import { isSimpText } from '../shared/index.js';
2
+ import { Fragment } from './fragment.js';
3
+ import { isConsumer, isProvider } from './context.js';
4
4
  export function createElement(type, props, ...children) {
5
5
  let newProps;
6
6
  let className;
@@ -31,7 +31,9 @@ export function createElement(type, props, ...children) {
31
31
  definedChildren = props[propName];
32
32
  }
33
33
  }
34
- else if (propName === 'ref') {
34
+ else if (propName === 'ref' &&
35
+ // Handle only a callback ref or an object ref with `current`.
36
+ props[propName]) {
35
37
  ref = {
36
38
  value: props[propName],
37
39
  };
@@ -52,7 +54,12 @@ export function createElement(type, props, ...children) {
52
54
  if (key) {
53
55
  element.key = key;
54
56
  }
55
- if ((definedChildren = normalizeChildren(definedChildren, false))) {
57
+ if (isSimpText(definedChildren)) {
58
+ if (definedChildren !== '') {
59
+ (newProps ||= {}).children = definedChildren.toString();
60
+ }
61
+ }
62
+ else if ((definedChildren = normalizeChildren(definedChildren, false))) {
56
63
  element.children = definedChildren;
57
64
  }
58
65
  if (newProps) {
@@ -134,7 +141,7 @@ export function createElement(type, props, ...children) {
134
141
  export function createTextElement(text) {
135
142
  return {
136
143
  flag: 'TEXT',
137
- children: text,
144
+ children: text.toString(),
138
145
  parent: null,
139
146
  };
140
147
  }
@@ -1,4 +1,4 @@
1
- import type { SimpNode } from './createElement';
1
+ import type { SimpNode } from './createElement.js';
2
2
  export type Fragment = (props: {
3
3
  children?: SimpNode;
4
4
  }) => SimpNode;
@@ -1,5 +1,5 @@
1
- import type { Maybe, Nullable } from '../shared';
2
- import type { SimpElement } from './createElement';
1
+ import type { Maybe, Nullable } from '../shared/index.js';
2
+ import type { SimpElement } from './createElement.js';
3
3
  export type HostReference = any;
4
4
  export interface HostAdapter<HostRef = any, HostTextRef = any, NS = string> {
5
5
  createReference(type: string, namespace?: Maybe<NS>): HostRef;
@@ -8,7 +8,7 @@ export interface HostAdapter<HostRef = any, HostTextRef = any, NS = string> {
8
8
  patchProps(reference: HostRef, prevElement: SimpElement, nextElement: SimpElement, namespace?: Maybe<NS>): void;
9
9
  unmountProps(reference: HostRef, element: SimpElement): void;
10
10
  setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
11
- setTextContent(reference: HostRef, text: string): void;
11
+ setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): void;
12
12
  appendChild(parent: HostRef, child: HostRef | HostTextRef): void;
13
13
  removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
14
14
  replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
package/core/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import type { SimpText } from '../shared';
1
+ import type { SimpText } from '../shared/index.js';
2
2
 
3
3
  export type ComponentType<P = {}> = FunctionComponent<P>;
4
4
 
5
5
  export type RefObject<T> = { current: T };
6
6
  export type RefCallback<T> = {
7
- bivarianceHack(instance: T | null): (() => void | undefined) | void;
7
+ bivarianceHack(instance: T): (() => void | undefined) | void;
8
8
  }['bivarianceHack'];
9
- export type Ref<T> = RefCallback<T> | RefObject<T> | null;
9
+ export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;
10
10
 
11
11
  export type Key = string | number | bigint;
12
12
 
package/core/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createElement } from './createElement';
2
- import { Fragment } from './fragment';
3
- import { createContext } from './context';
4
- import { createPortal } from './portal';
1
+ import { createElement } from './createElement.js';
2
+ import { Fragment } from './fragment.js';
3
+ import { createContext } from './context.js';
4
+ import { createPortal } from './portal.js';
5
5
  export { createElement, Fragment, createContext, createPortal };
6
6
  export default { createElement, Fragment, createContext, createPortal };
@@ -1,11 +1,11 @@
1
- export * from './context';
2
- export * from './createElement';
3
- export * from './fragment';
4
- export * from './hostAdapter';
5
- export * from './lifecycleEventBus';
6
- export * from './mounting';
7
- export * from './patching';
8
- export * from './portal';
9
- export * from './ref';
10
- export * from './rerender';
11
- export * from './unmounting';
1
+ export * from './context.js';
2
+ export * from './createElement.js';
3
+ export * from './fragment.js';
4
+ export * from './hostAdapter.js';
5
+ export * from './lifecycleEventBus.js';
6
+ export * from './mounting.js';
7
+ export * from './patching.js';
8
+ export * from './portal.js';
9
+ export * from './ref.js';
10
+ export * from './rerender.js';
11
+ export * from './unmounting.js';
package/core/internal.js CHANGED
@@ -1,11 +1,11 @@
1
- export * from './context';
2
- export * from './createElement';
3
- export * from './fragment';
4
- export * from './hostAdapter';
5
- export * from './lifecycleEventBus';
6
- export * from './mounting';
7
- export * from './patching';
8
- export * from './portal';
9
- export * from './ref';
10
- export * from './rerender';
11
- export * from './unmounting';
1
+ export * from './context.js';
2
+ export * from './createElement.js';
3
+ export * from './fragment.js';
4
+ export * from './hostAdapter.js';
5
+ export * from './lifecycleEventBus.js';
6
+ export * from './mounting.js';
7
+ export * from './patching.js';
8
+ export * from './portal.js';
9
+ export * from './ref.js';
10
+ export * from './rerender.js';
11
+ export * from './unmounting.js';
@@ -1,12 +1,16 @@
1
- import { EventBus } from '../shared';
2
- import type { SimpElement } from './createElement';
1
+ import { EventBus } from '../shared/index.js';
2
+ import type { SimpElement } from './createElement.js';
3
3
  export type LifecycleEvent = {
4
4
  type: 'beforeRender';
5
5
  element: SimpElement;
6
6
  phase: 'mounting' | 'updating';
7
7
  } | {
8
8
  type: 'afterRender';
9
+ element: SimpElement;
9
10
  phase: 'mounting' | 'updating';
11
+ } | {
12
+ type: 'triedToRerender';
13
+ element: SimpElement;
10
14
  } | {
11
15
  type: 'mounted';
12
16
  element: SimpElement;
@@ -1,2 +1,2 @@
1
- import { EventBus } from '../shared';
1
+ import { EventBus } from '../shared/index.js';
2
2
  export const lifecycleEventBus = new EventBus();
@@ -1,7 +1,7 @@
1
- import type { Maybe, Nullable } from '../shared';
2
- import type { HostReference } from './hostAdapter';
3
- import type { SimpElement } from './createElement';
4
- import type { SimpContextMap } from './context';
1
+ import type { Maybe, Nullable } from '../shared/index.js';
2
+ import type { HostReference } from './hostAdapter.js';
3
+ import type { SimpElement } from './createElement.js';
4
+ import type { SimpContextMap } from './context.js';
5
5
  export declare function mount(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;
6
6
  export declare function mountTextElement(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>): void;
7
7
  export declare function mountHostElement(element: SimpElement, parentReference: Nullable<HostReference>, nextReference: Nullable<HostReference>, contextMap: Nullable<SimpContextMap>, hostNamespace: Maybe<string>): void;