@simpreact/simpreact 0.0.4 → 0.0.6

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 (78) hide show
  1. package/LICENSE.txt +1 -1
  2. package/compat/context.d.ts +4 -4
  3. package/compat/context.js +3 -2
  4. package/compat/core.d.ts +4 -0
  5. package/compat/core.js +14 -9
  6. package/compat/dom.d.ts +4 -5
  7. package/compat/dom.js +3 -2
  8. package/compat/hooks.d.ts +16 -13
  9. package/compat/hooks.js +19 -15
  10. package/compat/index.d.ts +10 -9
  11. package/compat/renderRuntime.d.ts +2 -0
  12. package/compat/renderRuntime.js +14 -0
  13. package/component/index.d.ts +16 -0
  14. package/component/index.js +164 -0
  15. package/context/index.d.ts +12 -5
  16. package/context/index.js +62 -57
  17. package/core/createElement.d.ts +29 -20
  18. package/core/createElement.js +159 -133
  19. package/core/hostAdapter.d.ts +8 -12
  20. package/core/hostAdapter.js +1 -4
  21. package/core/hostOperations.d.ts +5 -0
  22. package/core/hostOperations.js +15 -0
  23. package/core/index.d.ts +29 -6
  24. package/core/internal.d.ts +3 -0
  25. package/core/internal.js +3 -0
  26. package/core/lifecycleEventBus.d.ts +15 -6
  27. package/core/lifecycleEventBus.js +16 -2
  28. package/core/memo.d.ts +0 -2
  29. package/core/memo.js +1 -3
  30. package/core/mounting.d.ts +7 -9
  31. package/core/mounting.js +221 -82
  32. package/core/patching.d.ts +7 -8
  33. package/core/patching.js +235 -255
  34. package/core/patchingChildren.d.ts +6 -0
  35. package/core/patchingChildren.js +330 -0
  36. package/core/portal.d.ts +1 -1
  37. package/core/portal.js +17 -7
  38. package/core/processStack.d.ts +69 -0
  39. package/core/processStack.js +63 -0
  40. package/core/ref.d.ts +4 -3
  41. package/core/rerender.d.ts +4 -14
  42. package/core/rerender.js +67 -112
  43. package/core/runtime.d.ts +17 -0
  44. package/core/runtime.js +2 -0
  45. package/core/unmounting.d.ts +11 -6
  46. package/core/unmounting.js +81 -40
  47. package/core/utils.d.ts +10 -0
  48. package/core/utils.js +143 -0
  49. package/dom/attach-element-to-dom.d.ts +4 -3
  50. package/dom/attach-element-to-dom.js +12 -7
  51. package/dom/domAdapter.js +22 -25
  52. package/dom/events.d.ts +5 -5
  53. package/dom/events.js +33 -16
  54. package/dom/index.d.ts +16 -5
  55. package/dom/index.js +4 -3
  56. package/dom/props/controlled/index.d.ts +3 -3
  57. package/dom/props/controlled/index.js +8 -8
  58. package/dom/props/controlled/input.d.ts +3 -3
  59. package/dom/props/controlled/input.js +57 -34
  60. package/dom/props/controlled/select.d.ts +3 -3
  61. package/dom/props/controlled/select.js +39 -26
  62. package/dom/props/controlled/textarea.d.ts +3 -3
  63. package/dom/props/controlled/textarea.js +57 -34
  64. package/dom/props/dangerInnerHTML.d.ts +2 -2
  65. package/dom/props/dangerInnerHTML.js +3 -2
  66. package/dom/props/props.d.ts +4 -4
  67. package/dom/props/props.js +24 -21
  68. package/dom/render.d.ts +4 -5
  69. package/dom/render.js +38 -34
  70. package/hooks/index.d.ts +15 -13
  71. package/hooks/index.js +155 -159
  72. package/jsx-runtime/index.d.ts +2 -1
  73. package/package.json +9 -1
  74. package/shared/index.d.ts +10 -0
  75. package/shared/index.js +4 -7
  76. package/shared/utils.js +4 -4
  77. package/shared/EventBus.d.ts +0 -18
  78. package/shared/EventBus.js +0 -28
@@ -1,30 +1,39 @@
1
- import type { Many, Maybe, Nullable, SimpText } from '../shared/index.js';
2
- import type { HostReference } from './hostAdapter.js';
1
+ import type { Nullable, SimpText } from '../shared/index.js';
3
2
  export type SimpNode = SimpElement | SimpText | Array<SimpNode> | boolean | null | undefined;
4
3
  export type Key = string | number | bigint;
5
4
  export type FC = (props: any) => SimpNode;
6
- export type SimpElementFlag = 'FC' | 'HOST' | 'TEXT' | 'FRAGMENT' | 'PORTAL';
5
+ export declare const SIMP_ELEMENT_FLAG_HOST = 1;
6
+ export declare const SIMP_ELEMENT_FLAG_FC: number;
7
+ export declare const SIMP_ELEMENT_FLAG_TEXT: number;
8
+ export declare const SIMP_ELEMENT_FLAG_PORTAL: number;
9
+ export declare const SIMP_ELEMENT_FLAG_FRAGMENT: number;
10
+ export declare const SIMP_ELEMENT_CHILD_FLAG_EMPTY = 1;
11
+ export declare const SIMP_ELEMENT_CHILD_FLAG_UNKNOWN: number;
12
+ export declare const SIMP_ELEMENT_CHILD_FLAG_ELEMENT: number;
13
+ export declare const SIMP_ELEMENT_CHILD_FLAG_LIST: number;
14
+ export declare const SIMP_ELEMENT_CHILD_FLAG_TEXT: number;
7
15
  export interface SimpElementStore {
8
- latestElement?: Maybe<SimpElement>;
9
- hostNamespace?: Maybe<string>;
10
- forceRender?: boolean;
11
- [key: string]: unknown;
16
+ latestElement: Nullable<SimpElement>;
17
+ hostNamespace: Nullable<string>;
18
+ forceRerender: boolean;
12
19
  }
13
20
  export interface SimpElement {
14
- flag: SimpElementFlag;
21
+ flag: number;
22
+ childFlag: number;
15
23
  parent: Nullable<SimpElement>;
16
- key?: Maybe<Key>;
17
- type?: string | FC;
18
- props?: any;
19
- children?: Maybe<SimpNode>;
20
- className?: Maybe<string>;
21
- reference?: Maybe<HostReference>;
22
- store?: SimpElementStore;
23
- context?: any;
24
- ref?: any;
25
- unmounted?: boolean;
24
+ key: Nullable<Key>;
25
+ type: Nullable<string | FC>;
26
+ props: any;
27
+ children: SimpNode;
28
+ className: Nullable<string>;
29
+ reference: unknown;
30
+ store: Nullable<SimpElementStore>;
31
+ context: any;
32
+ ref: any;
33
+ unmounted: Nullable<boolean>;
34
+ index: number;
26
35
  }
27
36
  export declare function createElement(type: string | FC, props?: any, ...children: SimpNode[]): SimpElement;
28
37
  export declare function createTextElement(text: SimpText): SimpElement;
29
- export declare function normalizeChildren(children: SimpNode, skipIgnoredCheck: boolean): Maybe<Many<SimpElement>>;
30
- export declare function normalizeRoot(node: SimpNode, skipIgnoredCheck: boolean): Maybe<SimpElement>;
38
+ export declare function normalizeChildren(element: SimpElement, children: SimpNode, skipIgnoredCheck: boolean): SimpElement;
39
+ export declare function normalizeRoot(element: SimpElement, node: SimpNode, skipIgnoredCheck: boolean): SimpElement;
@@ -1,181 +1,207 @@
1
1
  import { isSimpText } from '../shared/index.js';
2
2
  import { Fragment } from './fragment.js';
3
- export function createElement(type, props, ...children) {
4
- let newProps;
5
- let className;
6
- let key;
3
+ export const SIMP_ELEMENT_FLAG_HOST = 1;
4
+ export const SIMP_ELEMENT_FLAG_FC = 1 << 1;
5
+ export const SIMP_ELEMENT_FLAG_TEXT = 1 << 2;
6
+ export const SIMP_ELEMENT_FLAG_PORTAL = 1 << 3;
7
+ export const SIMP_ELEMENT_FLAG_FRAGMENT = 1 << 4;
8
+ export const SIMP_ELEMENT_CHILD_FLAG_EMPTY = 1;
9
+ export const SIMP_ELEMENT_CHILD_FLAG_UNKNOWN = 1 << 1;
10
+ export const SIMP_ELEMENT_CHILD_FLAG_ELEMENT = 1 << 2;
11
+ export const SIMP_ELEMENT_CHILD_FLAG_LIST = 1 << 3;
12
+ export const SIMP_ELEMENT_CHILD_FLAG_TEXT = 1 << 4;
13
+ export function createElement(type, props) {
7
14
  let definedChildren;
8
- const childLength = children.length;
9
- if (childLength === 1) {
10
- definedChildren = children[0];
11
- }
12
- else if (childLength > 1) {
13
- definedChildren = [];
14
- for (let i = 0; i < childLength; i++) {
15
- definedChildren.push(children[i]);
15
+ const argLength = arguments.length;
16
+ if (argLength > 2) {
17
+ if (argLength === 3) {
18
+ definedChildren = arguments[2];
16
19
  }
17
- }
18
- if (typeof type === 'string') {
19
- let ref;
20
- if (props != null) {
21
- for (const propName in props) {
22
- if (propName === 'className') {
23
- className = props[propName];
24
- }
25
- else if (propName === 'key') {
26
- key = props[propName];
27
- }
28
- else if (propName === 'children') {
29
- if (definedChildren === undefined) {
30
- definedChildren = props[propName];
31
- }
32
- }
33
- else if (propName === 'ref' &&
34
- // Handle only a callback ref or an object ref with `current`.
35
- props[propName]) {
36
- ref = {
37
- value: props[propName],
38
- };
39
- }
40
- else {
41
- (newProps ||= {})[propName] = props[propName];
42
- }
20
+ else {
21
+ const arr = [];
22
+ for (let i = 2; i < argLength; i++) {
23
+ arr.push(arguments[i]);
43
24
  }
25
+ definedChildren = arr;
44
26
  }
45
- const element = {
46
- flag: 'HOST',
47
- type,
48
- parent: null,
49
- };
50
- if (className) {
51
- element.className = className;
52
- }
53
- if (key) {
54
- element.key = key;
55
- }
56
- if (isSimpText(definedChildren)) {
27
+ }
28
+ definedChildren = definedChildren === undefined ? props?.children : definedChildren;
29
+ const key = props?.key == null ? null : props.key.toString();
30
+ switch (typeof type) {
31
+ case 'string': {
32
+ if (!isSimpText(definedChildren)) {
33
+ return normalizeChildren({
34
+ flag: SIMP_ELEMENT_FLAG_HOST,
35
+ childFlag: SIMP_ELEMENT_CHILD_FLAG_UNKNOWN,
36
+ parent: null,
37
+ key,
38
+ type,
39
+ props: props || null,
40
+ children: null,
41
+ className: props?.className || null,
42
+ reference: null,
43
+ store: null,
44
+ context: null,
45
+ ref: props?.ref ? { value: props.ref } : null,
46
+ unmounted: null,
47
+ index: 0,
48
+ }, definedChildren, false);
49
+ }
50
+ let childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
51
+ definedChildren = definedChildren.toString();
57
52
  if (definedChildren !== '') {
58
- (newProps ||= {}).children = definedChildren.toString();
53
+ (props ||= {}).children = definedChildren;
54
+ childFlag = SIMP_ELEMENT_CHILD_FLAG_TEXT;
59
55
  }
56
+ return {
57
+ flag: SIMP_ELEMENT_FLAG_HOST,
58
+ childFlag,
59
+ parent: null,
60
+ key,
61
+ type,
62
+ props: props || null,
63
+ children: null,
64
+ className: props?.className || null,
65
+ reference: null,
66
+ store: null,
67
+ context: null,
68
+ ref: props?.ref ? { value: props.ref } : null,
69
+ unmounted: null,
70
+ index: 0,
71
+ };
60
72
  }
61
- else if ((definedChildren = normalizeChildren(definedChildren, false))) {
62
- element.children = definedChildren;
63
- }
64
- if (newProps) {
65
- element.props = newProps;
66
- }
67
- if (ref) {
68
- element.ref = ref;
69
- }
70
- return element;
71
- }
72
- else if (type === Fragment) {
73
- const element = {
74
- flag: 'FRAGMENT',
75
- parent: null,
76
- };
77
- if ((definedChildren = normalizeChildren(definedChildren || (props != null ? props.children : null), false))) {
78
- element.children = definedChildren;
79
- }
80
- if (props != null && props.key) {
81
- element.key = props?.key;
82
- }
83
- return element;
84
- }
85
- else {
86
- if (props != null) {
87
- for (const propName in props) {
88
- if (propName === 'key') {
89
- key = props[propName];
90
- }
91
- else if (propName === 'children') {
92
- if (definedChildren === undefined) {
93
- definedChildren = props[propName];
94
- }
95
- }
96
- else {
97
- (newProps ||= {})[propName] = props[propName];
98
- }
73
+ case 'function': {
74
+ if (definedChildren !== undefined) {
75
+ (props ||= {}).children = definedChildren;
99
76
  }
77
+ return {
78
+ flag: SIMP_ELEMENT_FLAG_FC,
79
+ childFlag: SIMP_ELEMENT_CHILD_FLAG_UNKNOWN,
80
+ parent: null,
81
+ key,
82
+ type,
83
+ props: props || null,
84
+ children: null,
85
+ className: null,
86
+ reference: null,
87
+ store: null,
88
+ context: null,
89
+ ref: null,
90
+ unmounted: null,
91
+ index: 0,
92
+ };
100
93
  }
101
- if (definedChildren !== undefined) {
102
- (newProps ||= {})['children'] = definedChildren;
103
- }
104
- const element = {
105
- flag: 'FC',
106
- type,
107
- parent: null,
108
- };
109
- if (key) {
110
- element.key = key;
94
+ default: {
95
+ return normalizeChildren({
96
+ flag: SIMP_ELEMENT_FLAG_FRAGMENT,
97
+ childFlag: SIMP_ELEMENT_CHILD_FLAG_UNKNOWN,
98
+ parent: null,
99
+ key,
100
+ type: null,
101
+ props: null,
102
+ children: null,
103
+ className: null,
104
+ reference: null,
105
+ store: null,
106
+ context: null,
107
+ ref: null,
108
+ unmounted: null,
109
+ index: 0,
110
+ }, definedChildren, false);
111
111
  }
112
- if (newProps != null) {
113
- element.props = newProps;
114
- }
115
- return element;
116
112
  }
117
113
  }
118
114
  export function createTextElement(text) {
119
115
  return {
120
- flag: 'TEXT',
121
- children: text.toString(),
116
+ flag: SIMP_ELEMENT_FLAG_TEXT,
117
+ childFlag: SIMP_ELEMENT_CHILD_FLAG_TEXT,
122
118
  parent: null,
119
+ key: null,
120
+ type: null,
121
+ props: null,
122
+ children: text.toString(),
123
+ className: null,
124
+ reference: null,
125
+ store: null,
126
+ context: null,
127
+ ref: null,
128
+ unmounted: null,
129
+ index: 0,
123
130
  };
124
131
  }
125
- export function normalizeChildren(children, skipIgnoredCheck) {
132
+ export function normalizeChildren(element, children, skipIgnoredCheck) {
126
133
  if (!skipIgnoredCheck && isIgnoredNode(children)) {
127
- return;
134
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
135
+ element.children = null;
136
+ return element;
128
137
  }
129
138
  const result = [];
130
139
  normalizeNode(children, result, undefined, true);
131
140
  if (result.length === 0) {
132
- return;
141
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
142
+ element.children = null;
143
+ return element;
144
+ }
145
+ if (result.length === 1) {
146
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
147
+ element.children = result[0];
148
+ return element;
133
149
  }
134
- return result.length === 1 ? result[0] : result;
150
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_LIST;
151
+ element.children = result;
152
+ return element;
135
153
  }
136
- function normalizeNode(child, result, currentKey = '', skipIgnoredCheck) {
154
+ function normalizeNode(child, result, currentKey = null, skipIgnoredCheck) {
137
155
  if (!skipIgnoredCheck && isIgnoredNode(child)) {
138
156
  return;
139
157
  }
140
158
  if (isSimpText(child)) {
141
- child = createTextElement(child);
142
- child.key =
143
- currentKey ||
144
- // Hack to treat a single child as a one-item list for more consistent reconciliation.
145
- '.0';
146
- result.push(child);
159
+ const element = createTextElement(child);
160
+ element.key = currentKey;
161
+ element.index = result.length;
162
+ result.push(element);
147
163
  return;
148
164
  }
149
165
  if (Array.isArray(child)) {
150
166
  for (let i = 0; i < child.length; i++) {
151
- normalizeNode(child[i], result, currentKey + '.' + i, false);
167
+ normalizeNode(child[i], result, `${currentKey ?? ''}.${i}`, false);
152
168
  }
153
169
  return;
154
170
  }
155
- if (child.key) {
156
- currentKey = currentKey.slice(0, -2) + child.key;
171
+ const element = child;
172
+ if (element.key != null) {
173
+ currentKey = `${(currentKey ?? '').slice(0, -2)}${element.key}`;
157
174
  }
158
- child.key =
159
- currentKey ||
160
- // Hack to treat a single child as a one-item list for more consistent reconciliation.
161
- '.0';
162
- result.push(child);
175
+ element.key = currentKey;
176
+ element.index = result.length;
177
+ result.push(element);
163
178
  }
164
- export function normalizeRoot(node, skipIgnoredCheck) {
179
+ export function normalizeRoot(element, node, skipIgnoredCheck) {
165
180
  if (!skipIgnoredCheck && isIgnoredNode(node)) {
166
- return;
181
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_EMPTY;
182
+ element.children = null;
183
+ return element;
167
184
  }
168
185
  if (isSimpText(node)) {
169
- return createTextElement(node);
186
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
187
+ element.children = createTextElement(node);
188
+ return element;
170
189
  }
171
190
  if (!Array.isArray(node)) {
172
- return node;
191
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
192
+ element.children = node;
193
+ return element;
173
194
  }
174
- node = normalizeChildren(node, true);
175
- if (Array.isArray(node)) {
176
- return createElement(Fragment, { children: node });
195
+ normalizeChildren(element, node, true);
196
+ if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_ELEMENT) {
197
+ return element;
198
+ }
199
+ if (element.childFlag === SIMP_ELEMENT_CHILD_FLAG_EMPTY) {
200
+ return element;
177
201
  }
178
- return node;
202
+ element.childFlag = SIMP_ELEMENT_CHILD_FLAG_ELEMENT;
203
+ element.children = createElement(Fragment, { children: element.children });
204
+ return element;
179
205
  }
180
206
  function isIgnoredNode(node) {
181
207
  if (node == null || typeof node === 'boolean' || node === '') {
@@ -187,7 +213,7 @@ function isIgnoredNode(node) {
187
213
  if (isSimpText(node)) {
188
214
  return false;
189
215
  }
190
- if (node.flag === 'FRAGMENT' || node.flag === 'PORTAL') {
216
+ if ((node.flag & SIMP_ELEMENT_FLAG_FRAGMENT) !== 0 || (node.flag & SIMP_ELEMENT_FLAG_PORTAL) !== 0) {
191
217
  return node.children == null;
192
218
  }
193
219
  return false;
@@ -1,27 +1,23 @@
1
1
  import type { Maybe, Nullable } from '../shared/index.js';
2
2
  import type { SimpElement } from './createElement.js';
3
- export type HostReference = any;
4
- export interface HostAdapter<HostRef = any, HostTextRef = any, NS = string> {
3
+ import type { SimpRenderRuntime } from './runtime.js';
4
+ export interface HostAdapter<HostRef = unknown, HostTextRef = unknown, NS = string> {
5
5
  createReference(type: string, namespace?: Maybe<NS>): HostRef;
6
6
  createTextReference(text: string): HostTextRef;
7
- mountProps(reference: HostRef, element: SimpElement, namespace?: Maybe<NS>): void;
8
- patchProps(reference: HostRef, prevElement: SimpElement, nextElement: SimpElement, namespace?: Maybe<NS>): void;
9
- unmountProps(reference: HostRef, element: SimpElement): void;
7
+ mountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime, namespace?: Maybe<NS>): void;
8
+ patchProps(reference: HostRef, prevElement: SimpElement, nextElement: SimpElement, renderRuntime: SimpRenderRuntime, namespace?: Maybe<NS>): void;
9
+ unmountProps(reference: HostRef, element: SimpElement, renderRuntime: SimpRenderRuntime): void;
10
10
  setClassname(reference: HostRef, className: Maybe<string>, namespace?: Maybe<NS>): void;
11
11
  setTextContent(reference: HostRef, text: string, referenceHasOnlyTextElement?: boolean): void;
12
- appendChild(parent: HostRef, child: HostRef | HostTextRef): void;
13
12
  removeChild(parent: HostRef, child: HostRef | HostTextRef): void;
14
13
  replaceChild(parent: HostRef, replacer: HostRef | HostTextRef, toBeReplaced: HostRef | HostTextRef): void;
15
- insertBefore(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
16
14
  insertOrAppend(parent: HostRef, child: HostRef | HostTextRef, before: Nullable<HostRef | HostTextRef>): void;
17
- findParentReference(reference: HostRef | HostTextRef): Nullable<HostRef>;
18
- findNextSiblingReference(reference: HostRef | HostTextRef): Nullable<HostRef>;
19
15
  clearNode(reference: HostRef | HostTextRef): void;
20
- attachElementToReference(element: SimpElement, reference: HostRef | HostTextRef): void;
16
+ attachElementToReference(element: SimpElement, reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): void;
17
+ detachElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): void;
18
+ getElementFromReference(reference: HostRef | HostTextRef, renderRuntime: SimpRenderRuntime): Nullable<SimpElement>;
21
19
  getHostNamespaces(element: SimpElement, currentNamespace: Maybe<NS>): Nullable<{
22
20
  self: Nullable<NS>;
23
21
  children: Nullable<NS>;
24
22
  }>;
25
23
  }
26
- export declare let hostAdapter: HostAdapter;
27
- export declare function provideHostAdapter(adapter: HostAdapter): void;
@@ -1,4 +1 @@
1
- export let hostAdapter;
2
- export function provideHostAdapter(adapter) {
3
- hostAdapter = adapter;
4
- }
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { SimpElement } from './createElement.js';
2
+ import { type PlaceElementFrameMeta, type ReplaceElementFrameMeta } from './processStack.js';
3
+ import type { SimpRenderRuntime } from './runtime.js';
4
+ export declare function _pushHostOperationPlaceElement(element: SimpElement, meta: PlaceElementFrameMeta): void;
5
+ export declare function _pushHostOperationReplaceElement(element: SimpElement, renderRuntime: SimpRenderRuntime, meta: ReplaceElementFrameMeta): void;
@@ -0,0 +1,15 @@
1
+ import { HOST_OPS_PLACE_ELEMENT_BEFORE_ANCHOR, HOST_OPS_REPLACE_CHILD, } from './processStack.js';
2
+ export function _pushHostOperationPlaceElement(element, meta) {
3
+ meta.renderRuntime.renderStack.push({
4
+ node: element,
5
+ kind: HOST_OPS_PLACE_ELEMENT_BEFORE_ANCHOR,
6
+ meta,
7
+ });
8
+ }
9
+ export function _pushHostOperationReplaceElement(element, renderRuntime, meta) {
10
+ renderRuntime.renderStack.push({
11
+ node: element,
12
+ kind: HOST_OPS_REPLACE_CHILD,
13
+ meta,
14
+ });
15
+ }
package/core/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { SimpText } from '../shared/index.js';
1
+ import type { HostReference, TraversalStack } from './internal.js';
2
+ import type { Maybe, Nullable, SimpText } from '../shared/index.js';
2
3
 
3
- export type ComponentType<P = {}> = FunctionComponent<P>;
4
+ export type ComponentType<P = {}> = FunctionalComponent<P>;
4
5
 
5
6
  export type RefObject<T> = { current: T };
6
7
  export type RefCallback<T> = {
@@ -18,7 +19,7 @@ export interface RefAttributes<T> extends Attributes {
18
19
  ref?: Ref<T> | undefined;
19
20
  }
20
21
 
21
- export interface SimpElement<P = unknown, T extends string | FunctionComponent<P> = string> {
22
+ export interface SimpElement<P = unknown, T extends string | FunctionalComponent<P> = string> {
22
23
  type?: T;
23
24
  props?: P;
24
25
  key?: string | null;
@@ -32,7 +33,7 @@ declare function createElement<P extends {}, T>(
32
33
  ...children: SimpNode[]
33
34
  ): SimpElement<P>;
34
35
  declare function createElement<P extends {}>(
35
- type: FunctionComponent<P>,
36
+ type: FunctionalComponent<P>,
36
37
  props?: (Attributes & P) | null,
37
38
  ...children: SimpNode[]
38
39
  ): SimpElement<P>;
@@ -41,9 +42,31 @@ declare function createPortal<HostRef = {}>(children: SimpNode, container: HostR
41
42
 
42
43
  declare function Fragment(props: PropsWithChildren): SimpElement;
43
44
 
44
- export type FunctionComponent<P = {}> = (props: P) => SimpNode;
45
- export type FC<P = {}> = FunctionComponent<P>;
45
+ export type FunctionalComponent<P = {}> = (props: P) => SimpNode;
46
+ export type FC<P = {}> = FunctionalComponent<P>;
46
47
 
47
48
  export type PropsWithChildren<P = {}> = P & { children?: SimpNode | undefined };
48
49
 
49
50
  declare function memo<P = {}>(Component: FC<P>, compare?: (objA: Readonly<P>, objB: Readonly<P>) => boolean): FC<P>;
51
+
52
+ export interface SimpRuntimeFCRenderer {
53
+ (component: FC, element: SimpElement): SimpNode;
54
+ }
55
+
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
+ export interface SimpRenderRuntime {
68
+ hostAdapter: HostAdapter;
69
+ renderer: SimpRuntimeFCRenderer;
70
+ renderStack: TraversalStack<SimpElement, RenderMeta>;
71
+ elementToHostMap: Map<unknown, SimpElement>;
72
+ }
@@ -5,7 +5,10 @@ export * from './lifecycleEventBus.js';
5
5
  export * from './memo.js';
6
6
  export * from './mounting.js';
7
7
  export * from './patching.js';
8
+ export * from './patchingChildren.js';
8
9
  export * from './portal.js';
10
+ export * from './processStack.js';
9
11
  export * from './ref.js';
10
12
  export * from './rerender.js';
13
+ export * from './runtime.js';
11
14
  export * from './unmounting.js';
package/core/internal.js CHANGED
@@ -5,7 +5,10 @@ export * from './lifecycleEventBus.js';
5
5
  export * from './memo.js';
6
6
  export * from './mounting.js';
7
7
  export * from './patching.js';
8
+ export * from './patchingChildren.js';
8
9
  export * from './portal.js';
10
+ export * from './processStack.js';
9
11
  export * from './ref.js';
10
12
  export * from './rerender.js';
13
+ export * from './runtime.js';
11
14
  export * from './unmounting.js';
@@ -1,30 +1,39 @@
1
- import { EventBus } from '../shared/index.js';
2
1
  import type { SimpElement } from './createElement.js';
2
+ import type { SimpRenderRuntime } from './runtime.js';
3
3
  export type LifecycleEvent = {
4
4
  type: 'beforeRender';
5
5
  element: SimpElement;
6
- phase: 'mounting' | 'updating';
6
+ renderRuntime: SimpRenderRuntime;
7
7
  } | {
8
8
  type: 'afterRender';
9
9
  element: SimpElement;
10
- phase: 'mounting' | 'updating';
10
+ renderRuntime: SimpRenderRuntime;
11
11
  } | {
12
12
  type: 'triedToRerender';
13
13
  element: SimpElement;
14
+ renderRuntime: SimpRenderRuntime;
14
15
  } | {
15
16
  type: 'mounted';
16
17
  element: SimpElement;
18
+ renderRuntime: SimpRenderRuntime;
17
19
  } | {
18
20
  type: 'updated';
19
21
  element: SimpElement;
22
+ renderRuntime: SimpRenderRuntime;
20
23
  } | {
21
24
  type: 'unmounted';
22
25
  element: SimpElement;
26
+ renderRuntime: SimpRenderRuntime;
23
27
  } | {
24
28
  type: 'errored';
25
29
  element: SimpElement;
26
30
  error: any;
27
- phase: 'mounting' | 'updating';
31
+ handled: boolean;
32
+ renderRuntime: SimpRenderRuntime;
28
33
  };
29
- export type LifecycleEventBus = EventBus<LifecycleEvent>;
30
- export declare const lifecycleEventBus: EventBus<LifecycleEvent>;
34
+ type Subscriber = (event: LifecycleEvent) => boolean | void;
35
+ export declare const lifecycleEventBus: {
36
+ publish(event: LifecycleEvent): void;
37
+ subscribe(subscriber: Subscriber): () => void;
38
+ };
39
+ export {};
@@ -1,2 +1,16 @@
1
- import { EventBus } from '../shared/index.js';
2
- export const lifecycleEventBus = new EventBus();
1
+ const subscribers = [];
2
+ export const lifecycleEventBus = {
3
+ publish(event) {
4
+ for (const subscriber of subscribers) {
5
+ subscriber(event);
6
+ }
7
+ },
8
+ subscribe(subscriber) {
9
+ if (subscribers.indexOf(subscriber) === -1) {
10
+ subscribers.push(subscriber);
11
+ }
12
+ return () => {
13
+ subscribers.splice(subscribers.indexOf(subscriber), 1);
14
+ };
15
+ },
16
+ };
package/core/memo.d.ts CHANGED
@@ -2,8 +2,6 @@ import { shallowEqual } from '../shared/index.js';
2
2
  import type { FC, SimpNode } from './createElement.js';
3
3
  export interface MemoizedComponent {
4
4
  (props: any): SimpNode;
5
- _isMemo: true;
6
- _render: FC;
7
5
  _compare: (prevProps: any, nextProps: any) => boolean;
8
6
  }
9
7
  export declare function memo(Component: FC, compare?: typeof shallowEqual): MemoizedComponent;
package/core/memo.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { shallowEqual } from '../shared/index.js';
2
2
  export function memo(Component, compare = shallowEqual) {
3
3
  const Memoized = (props => Component(props));
4
- Memoized._isMemo = true;
5
- Memoized._render = Component;
6
4
  Memoized._compare = compare;
7
5
  return Memoized;
8
6
  }
9
7
  export function isMemo(type) {
10
- return type._isMemo;
8
+ return !!type._compare;
11
9
  }