@simpreact/simpreact 0.0.8 → 0.0.9

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 (75) hide show
  1. package/compat/core.js +101 -15
  2. package/compat/hooks.js +15 -0
  3. package/compat/index.d.ts +10 -1
  4. package/compat/renderRuntime.js +47 -12
  5. package/component/index.js +96 -94
  6. package/context/index.js +27 -17
  7. package/core/createElement.js +14 -17
  8. package/core/flags.js +31 -0
  9. package/core/hostOperations.js +5 -13
  10. package/core/index.d.ts +38 -8
  11. package/core/index.js +3 -2
  12. package/core/internal.d.ts +136 -16
  13. package/core/internal.js +8 -16
  14. package/core/lifecycleEventBus.js +35 -16
  15. package/core/memo.js +4 -1
  16. package/core/mounting.js +70 -150
  17. package/core/mountingChildren.js +11 -29
  18. package/core/patching.js +122 -181
  19. package/core/patchingChildren.js +74 -145
  20. package/core/portal.js +1 -1
  21. package/core/processStack.js +115 -45
  22. package/core/ref.js +1 -0
  23. package/core/rerender.js +20 -22
  24. package/core/runtime.js +10 -2
  25. package/core/unmounting.js +41 -49
  26. package/core/unmountingChildren.js +9 -12
  27. package/core/utils.js +38 -16
  28. package/dom/attach-element-to-dom.js +16 -8
  29. package/dom/events.js +11 -15
  30. package/dom/index.d.ts +2 -0
  31. package/dom/props/attrMaps.js +90 -0
  32. package/dom/props/controlled/select.js +8 -10
  33. package/dom/props/props.js +13 -14
  34. package/hooks/index.d.ts +3 -0
  35. package/hooks/index.js +107 -84
  36. package/package.json +10 -5
  37. package/compat/context.d.ts +0 -7
  38. package/compat/core.d.ts +0 -48
  39. package/compat/dom.d.ts +0 -10
  40. package/compat/hooks.d.ts +0 -26
  41. package/compat/jsx-runtime.d.ts +0 -10
  42. package/compat/renderRuntime.d.ts +0 -6
  43. package/core/createElement.d.ts +0 -39
  44. package/core/fragment.d.ts +0 -5
  45. package/core/hostAdapter.d.ts +0 -23
  46. package/core/hostOperations.d.ts +0 -5
  47. package/core/lifecycleEventBus.d.ts +0 -39
  48. package/core/memo.d.ts +0 -8
  49. package/core/mounting.d.ts +0 -7
  50. package/core/mountingChildren.d.ts +0 -4
  51. package/core/patching.d.ts +0 -8
  52. package/core/patchingChildren.d.ts +0 -6
  53. package/core/portal.d.ts +0 -2
  54. package/core/processStack.d.ts +0 -106
  55. package/core/ref.d.ts +0 -18
  56. package/core/rerender.d.ts +0 -4
  57. package/core/runtime.d.ts +0 -17
  58. package/core/unmounting.d.ts +0 -7
  59. package/core/unmountingChildren.d.ts +0 -4
  60. package/core/utils.d.ts +0 -11
  61. package/dom/attach-element-to-dom.d.ts +0 -5
  62. package/dom/domAdapter.d.ts +0 -3
  63. package/dom/events.d.ts +0 -27
  64. package/dom/namespace.d.ts +0 -2
  65. package/dom/props/controlled/index.d.ts +0 -7
  66. package/dom/props/controlled/input.d.ts +0 -7
  67. package/dom/props/controlled/select.d.ts +0 -6
  68. package/dom/props/controlled/textarea.d.ts +0 -6
  69. package/dom/props/dangerInnerHTML.d.ts +0 -7
  70. package/dom/props/index.d.ts +0 -1
  71. package/dom/props/props.d.ts +0 -5
  72. package/dom/props/style.d.ts +0 -1
  73. package/dom/render.d.ts +0 -8
  74. package/shared/lang.d.ts +0 -3
  75. package/shared/utils.d.ts +0 -5
@@ -1,106 +0,0 @@
1
- import type { Many, Maybe, Nullable } from '../shared/index.js';
2
- import type { SimpElement } from './createElement.js';
3
- import type { SimpRenderRuntime } from './runtime.js';
4
- export declare const MOUNT_ENTER = 10;
5
- export declare const MOUNT_EXIT = 11;
6
- export declare const MOUNT_CHILDREN_ENTER = 12;
7
- export declare const PATCH_ENTER = 20;
8
- export declare const PATCH_EXIT = 21;
9
- export declare const PATCH_CHILDREN = 22;
10
- export declare const PATCH_KEYED_CHILDREN = 24;
11
- export declare const UNMOUNT_ENTER = 30;
12
- export declare const UNMOUNT_EXIT = 31;
13
- export declare const UNMOUNT_CHILDREN_ENTER = 32;
14
- export declare const HOST_OPS_PLACE_ELEMENT_BEFORE_ANCHOR = 40;
15
- export declare const HOST_OPS_REPLACE_CHILD = 42;
16
- export interface MountFrameMeta {
17
- parentReference: unknown;
18
- subtreeRightBoundary: Nullable<SimpElement>;
19
- context: unknown;
20
- hostNamespace: Maybe<string>;
21
- renderRuntime: SimpRenderRuntime;
22
- placeHolderElement: Nullable<SimpElement>;
23
- }
24
- export interface MountChildrenFrameMeta {
25
- children: Nullable<Many<SimpElement>>;
26
- parentReference: unknown;
27
- subtreeRightBoundary: Nullable<SimpElement>;
28
- context: unknown;
29
- hostNamespace: Maybe<string>;
30
- renderRuntime: SimpRenderRuntime;
31
- }
32
- export interface PatchFrameMeta {
33
- parentReference: unknown;
34
- subtreeRightBoundary: Nullable<SimpElement>;
35
- context: unknown;
36
- hostNamespace: Maybe<string>;
37
- renderRuntime: SimpRenderRuntime;
38
- prevElement: SimpElement;
39
- }
40
- export interface PatchChildrenFrameMeta {
41
- parentReference: unknown;
42
- subtreeRightBoundary: Nullable<SimpElement>;
43
- context: unknown;
44
- hostNamespace: Maybe<string>;
45
- renderRuntime: SimpRenderRuntime;
46
- nextChildren: Nullable<Many<SimpElement>>;
47
- prevChildren: Nullable<Many<SimpElement>>;
48
- prevParentChildFlag: number;
49
- nextParentChildFlag: number;
50
- prevParentElement: SimpElement;
51
- }
52
- export interface UnmountFrameMeta {
53
- renderRuntime: SimpRenderRuntime;
54
- }
55
- export interface PlaceElementFrameMeta {
56
- parentReference: unknown;
57
- subtreeRightBoundary: Nullable<SimpElement>;
58
- renderRuntime: SimpRenderRuntime;
59
- }
60
- export interface ReplaceElementFrameMeta {
61
- parentReference: unknown;
62
- prevElement: SimpElement;
63
- }
64
- export interface MountFrame {
65
- node: SimpElement;
66
- kind: typeof MOUNT_ENTER | typeof MOUNT_EXIT;
67
- meta: MountFrameMeta;
68
- }
69
- export interface MountChildrenFrame {
70
- node: SimpElement;
71
- kind: typeof MOUNT_CHILDREN_ENTER;
72
- meta: MountChildrenFrameMeta;
73
- }
74
- export interface PatchFrame {
75
- node: SimpElement;
76
- kind: typeof PATCH_ENTER | typeof PATCH_EXIT;
77
- meta: PatchFrameMeta;
78
- }
79
- export interface PatchChildrenFrame {
80
- node: SimpElement;
81
- kind: typeof PATCH_CHILDREN | typeof PATCH_KEYED_CHILDREN;
82
- meta: PatchChildrenFrameMeta;
83
- }
84
- export interface UnmountFrame {
85
- node: SimpElement;
86
- kind: typeof UNMOUNT_ENTER | typeof UNMOUNT_EXIT;
87
- meta: UnmountFrameMeta;
88
- }
89
- export interface UnmountChildrenFrame {
90
- node: SimpElement;
91
- kind: typeof UNMOUNT_CHILDREN_ENTER;
92
- meta: UnmountFrameMeta;
93
- }
94
- export interface PlaceElementFrame {
95
- node: SimpElement;
96
- kind: typeof HOST_OPS_PLACE_ELEMENT_BEFORE_ANCHOR;
97
- meta: PlaceElementFrameMeta;
98
- }
99
- export interface ReplaceElementFrame {
100
- node: SimpElement;
101
- kind: typeof HOST_OPS_REPLACE_CHILD;
102
- meta: ReplaceElementFrameMeta;
103
- }
104
- export type SimpRenderFrame = MountFrame | MountChildrenFrame | PatchFrame | PatchChildrenFrame | UnmountFrame | UnmountChildrenFrame | PlaceElementFrame | ReplaceElementFrame;
105
- export type SimpRenderStack = SimpRenderFrame[];
106
- export declare function processStack(renderRuntime: SimpRenderRuntime): void;
package/core/ref.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { Nullable } from '../shared/index.js';
2
- import type { SimpElement } from './createElement.js';
3
- interface RefSimpElement extends SimpElement {
4
- ref: Nullable<{
5
- value: NonNullable<Ref<unknown>>;
6
- cleanup: Nullable<() => void>;
7
- }>;
8
- }
9
- export type RefObject<T> = {
10
- current: T;
11
- };
12
- export type RefCallback<T> = {
13
- bivarianceHack(instance: T): (() => void | undefined) | void;
14
- }['bivarianceHack'];
15
- export type Ref<T> = RefCallback<T> | RefObject<T | null> | null;
16
- export declare function unmountRef(element: RefSimpElement): void;
17
- export declare function applyRef(element: RefSimpElement): void;
18
- export {};
@@ -1,4 +0,0 @@
1
- import type { SimpElementStore } from './createElement.js';
2
- import type { SimpRenderRuntime } from './runtime.js';
3
- export declare function rerender(store: SimpElementStore, renderRuntime: SimpRenderRuntime): void;
4
- export declare function withSyncRerender(renderRuntime: SimpRenderRuntime, callback: () => void): void;
package/core/runtime.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import type { Nullable } from '../shared/index.js';
2
- import type { FC, SimpElement, SimpNode } from './createElement.js';
3
- import type { HostAdapter } from './hostAdapter.js';
4
- import type { SimpRenderStack } from './processStack.js';
5
- export interface SimpRuntimeFCRenderer {
6
- (component: FC, element: SimpElement, renderRuntime: SimpRenderRuntime): SimpNode;
7
- }
8
- export declare const MOUNTING_PHASE = 0;
9
- export declare const UPDATING_PHASE = 1;
10
- export interface SimpRenderRuntime {
11
- hostAdapter: HostAdapter;
12
- renderer: SimpRuntimeFCRenderer;
13
- renderStack: SimpRenderStack;
14
- elementToHostMap: Map<unknown, SimpElement>;
15
- currentRenderingFCElement: Nullable<SimpElement>;
16
- renderPhase: Nullable<typeof MOUNTING_PHASE | typeof UPDATING_PHASE>;
17
- }
@@ -1,7 +0,0 @@
1
- import type { SimpElement } from './createElement.js';
2
- import { type UnmountFrame, type UnmountFrameMeta } from './processStack.js';
3
- import type { SimpRenderRuntime } from './runtime.js';
4
- export declare function unmount(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
5
- export declare function _unmount(frame: UnmountFrame): void;
6
- export declare function _pushUnmountEnterFrame(element: SimpElement, meta: UnmountFrameMeta): void;
7
- export declare function _pushUnmountExitFrame(element: SimpElement, meta: UnmountFrameMeta): void;
@@ -1,4 +0,0 @@
1
- import { type SimpElement } from './createElement.js';
2
- import { type UnmountChildrenFrame, type UnmountFrameMeta } from './processStack.js';
3
- export declare function _pushUnmountChildrenFrame(parent: SimpElement, meta: UnmountFrameMeta): void;
4
- export declare function _unmountChildren(frame: UnmountChildrenFrame): void;
package/core/utils.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { Maybe, Nullable } from '../shared/index.js';
2
- import { type SimpElement } from './createElement.js';
3
- import type { SimpRenderRuntime } from './runtime.js';
4
- export declare function bitScanForwardIndex(flag: number): number;
5
- export declare function isHostLike(flag: number): boolean;
6
- export declare function findParentReferenceFromElement(element: SimpElement): unknown | null;
7
- export declare function placeElementBeforeAnchor(element: SimpElement, anchor: unknown, parentReference: unknown, renderRuntime: SimpRenderRuntime): void;
8
- export declare function resolveAnchorReference(subtreeRightBoundary: Nullable<SimpElement>): unknown | null;
9
- export declare function findHostReferenceFromElement(element: Nullable<SimpElement>): unknown | null;
10
- export declare function getLongestIncreasingSubsequenceIndexes(sequence: Int32Array): Int32Array;
11
- export declare function _clearElementHostReference(element: Maybe<SimpElement>, parentHostReference: unknown, renderRuntime: SimpRenderRuntime): void;
@@ -1,5 +0,0 @@
1
- import { type SimpElement, type SimpRenderRuntime } from '../core/internal.js';
2
- import type { Nullable } from '../shared/index.js';
3
- export declare function attachElementToDom(element: SimpElement, dom: Node, renderRuntime: SimpRenderRuntime): void;
4
- export declare function getElementFromDom(target: Nullable<EventTarget>, renderRuntime: SimpRenderRuntime): Nullable<SimpElement>;
5
- export declare function detachElementFromDom(dom: Node, renderRuntime: SimpRenderRuntime): void;
@@ -1,3 +0,0 @@
1
- import type { HostAdapter } from '../core/internal.js';
2
- import type { Namespace } from './namespace.js';
3
- export declare const domAdapter: HostAdapter<HTMLElement | SVGElement, Text, Namespace>;
package/dom/events.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { type SimpRenderRuntime } from '../core/internal.js';
2
- import type { Nullable } from '../shared/index.js';
3
- export type DelegatedEventType = 'click' | 'dblclick' | 'mousedown' | 'mouseup' | 'mousemove' | 'pointerdown' | 'pointerup' | 'pointermove' | 'touchstart' | 'touchmove' | 'touchend' | 'keydown' | 'keyup' | 'focusin' | 'focusout';
4
- export declare class SyntheticEvent {
5
- nativeEvent: Event;
6
- currentTarget: Nullable<EventTarget>;
7
- isPropagationStopped: boolean;
8
- _isDefaultPrevented: boolean;
9
- button?: number;
10
- buttons?: number;
11
- pointerId?: number;
12
- altKey?: boolean;
13
- ctrlKey?: boolean;
14
- shiftKey?: boolean;
15
- metaKey?: boolean;
16
- constructor(event: Event);
17
- get target(): EventTarget | null;
18
- get type(): string;
19
- stopPropagation(): void;
20
- preventDefault(): void;
21
- isDefaultPrevented(): boolean;
22
- }
23
- export declare function dispatchDelegatedEvent(event: Event, renderRuntime: SimpRenderRuntime): void;
24
- export declare function patchEvent(name: string, prevValue: any, nextValue: any, dom: Element, renderRuntime: SimpRenderRuntime): void;
25
- export declare function patchDelegatedEvent(eventType: DelegatedEventType, prevHandler: any, nextHandler: any, eventHandlerCounts: Record<DelegatedEventType, number>, renderRuntime: SimpRenderRuntime): void;
26
- export declare function patchNormalEvent(eventType: string, prevValue: any, nextValue: any, dom: Element, capture: boolean): void;
27
- export declare function isPropNameEventName(name: string): boolean;
@@ -1,2 +0,0 @@
1
- export type Namespace = 'http://www.w3.org/1999/xhtml' | 'http://www.w3.org/2000/svg' | (string & {});
2
- export declare const defaultNamespace: Namespace;
@@ -1,7 +0,0 @@
1
- import type { SimpElement, SimpRenderRuntime } from '../../../core/internal.js';
2
- import type { Dict } from '../../../shared/index.js';
3
- export declare function isEventNameIgnored(element: SimpElement, eventName: string): boolean;
4
- export declare function isFormElementControlled(props: Dict): boolean;
5
- export declare function addControlledFormElementEventHandlers(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
6
- export declare function removeControlledFormElementEventHandlers(element: SimpElement, renderRuntime: SimpRenderRuntime): void;
7
- export declare function syncControlledFormElementPropsWithAttrs(element: SimpElement, props: Dict, mounting?: boolean): void;
@@ -1,7 +0,0 @@
1
- import type { SimpElement, SimpRenderRuntime } from '../../../core/internal.js';
2
- import type { Dict } from '../../../shared/index.js';
3
- export declare function isCheckedType(type: string): boolean;
4
- export declare function isEventNameIgnored(props: Dict, eventName: string): boolean;
5
- export declare function addControlledInputEventHandlers(dom: HTMLInputElement, renderRuntime: SimpRenderRuntime): void;
6
- export declare function removeControlledInputEventHandlers(dom: HTMLInputElement, renderRuntime: SimpRenderRuntime): void;
7
- export declare function syncControlledInputProps(element: SimpElement, props: Dict): void;
@@ -1,6 +0,0 @@
1
- import type { SimpElement, SimpRenderRuntime } from '../../../core/internal.js';
2
- import type { Dict } from '../../../shared/index.js';
3
- export declare function isEventNameIgnored(eventName: string): boolean;
4
- export declare function addControlledSelectEventHandlers(dom: HTMLSelectElement, renderRuntime: SimpRenderRuntime): void;
5
- export declare function removeControlledSelectEventHandlers(dom: HTMLSelectElement, renderRuntime: SimpRenderRuntime): void;
6
- export declare function syncControlledSelectProps(element: SimpElement, props: Dict, mounting?: boolean): void;
@@ -1,6 +0,0 @@
1
- import type { SimpElement, SimpRenderRuntime } from '../../../core/internal.js';
2
- import type { Dict } from '../../../shared/index.js';
3
- export declare function isEventNameIgnored(eventName: string): boolean;
4
- export declare function addControlledTextareaEventHandlers(dom: HTMLTextAreaElement, renderRuntime: SimpRenderRuntime): void;
5
- export declare function removeControlledTextareaEventHandlers(dom: HTMLTextAreaElement, renderRuntime: SimpRenderRuntime): void;
6
- export declare function syncControlledTextareaProps(element: SimpElement, props: Dict, mounting?: boolean): void;
@@ -1,7 +0,0 @@
1
- import type { SimpElement } from '../../core/internal.js';
2
- import type { Maybe } from '../../shared/index.js';
3
- type DangerInnerHTMLValue = {
4
- __html: string;
5
- };
6
- export declare function patchDangerInnerHTML(prevValue: Maybe<DangerInnerHTMLValue>, nextValue: Maybe<DangerInnerHTMLValue>, nextElement: SimpElement, dom: Element): void;
7
- export {};
@@ -1 +0,0 @@
1
- export * from './props.js';
@@ -1,5 +0,0 @@
1
- import type { SimpElement, SimpRenderRuntime } from '../../core/internal.js';
2
- import type { Namespace } from '../namespace.js';
3
- export declare function mountProps(dom: HTMLElement | SVGElement, element: SimpElement, namespace: Namespace, renderRuntime: SimpRenderRuntime): void;
4
- export declare function unmountProps(dom: HTMLElement | SVGElement, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
5
- export declare function patchProps(dom: HTMLElement | SVGElement, prevElement: SimpElement, nextElement: SimpElement, namespace: Namespace, renderRuntime: SimpRenderRuntime): void;
@@ -1 +0,0 @@
1
- export declare function patchStyle(prevAttrValue: any, nextAttrValue: any, dom: HTMLElement | SVGElement): void;
package/dom/render.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { type SimpElement, type SimpRenderRuntime } from '../core/internal.js';
2
- import type { Nullable } from '../shared/index.js';
3
- export declare function createRenderer(renderRuntime: SimpRenderRuntime): (element: Nullable<SimpElement>, container: Nullable<Element | DocumentFragment>) => void;
4
- export interface SimpRoot {
5
- render(element: SimpElement): void;
6
- unmount(): void;
7
- }
8
- export declare function createCreateRoot(renderRuntime: SimpRenderRuntime): (container: Element | DocumentFragment) => SimpRoot;
package/shared/lang.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const emptyObject: Readonly<{}>;
2
- export declare const emptyArray: readonly never[];
3
- export declare const emptyMap: Map<any, any>;
package/shared/utils.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { SimpText } from './public.js';
2
- export declare function isSimpText(value: unknown): value is SimpText;
3
- export declare function noop(): void;
4
- export declare function callOrGet<T, A extends any[]>(value: T | ((...args: A) => T), ...args: A): T;
5
- export declare function shallowEqual(objA: any, objB: any): boolean;