@faiwer/react 0.8.3 → 0.9.0

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 (239) hide show
  1. package/README.md +20 -14
  2. package/dist/core/Children.d.ts +11 -0
  3. package/dist/core/Children.d.ts.map +1 -0
  4. package/dist/core/Children.js +35 -0
  5. package/dist/core/Children.js.map +1 -0
  6. package/dist/core/actions/applyAction.d.ts.map +1 -1
  7. package/dist/core/actions/applyAction.js +2 -0
  8. package/dist/core/actions/applyAction.js.map +1 -1
  9. package/dist/core/actions/createComment.action.d.ts +2 -2
  10. package/dist/core/actions/createComment.action.d.ts.map +1 -1
  11. package/dist/core/actions/createComment.action.js +1 -8
  12. package/dist/core/actions/createComment.action.js.map +1 -1
  13. package/dist/core/actions/createContainer.action.d.ts +7 -0
  14. package/dist/core/actions/createContainer.action.d.ts.map +1 -0
  15. package/dist/core/actions/createContainer.action.js +28 -0
  16. package/dist/core/actions/createContainer.action.js.map +1 -0
  17. package/dist/core/actions/createTag.action.d.ts +2 -1
  18. package/dist/core/actions/createTag.action.d.ts.map +1 -1
  19. package/dist/core/actions/createTag.action.js +107 -5
  20. package/dist/core/actions/createTag.action.js.map +1 -1
  21. package/dist/core/actions/createText.action.d.ts.map +1 -1
  22. package/dist/core/actions/createText.action.js +2 -5
  23. package/dist/core/actions/createText.action.js.map +1 -1
  24. package/dist/core/actions/dom/attributes.d.ts +4 -0
  25. package/dist/core/actions/dom/attributes.d.ts.map +1 -0
  26. package/dist/core/actions/dom/attributes.js +56 -0
  27. package/dist/core/actions/dom/attributes.js.map +1 -0
  28. package/dist/core/actions/dom/css.d.ts +6 -0
  29. package/dist/core/actions/dom/css.d.ts.map +1 -0
  30. package/dist/core/actions/dom/css.js +54 -0
  31. package/dist/core/actions/dom/css.js.map +1 -0
  32. package/dist/core/actions/dom/events.d.ts +3 -0
  33. package/dist/core/actions/dom/events.d.ts.map +1 -0
  34. package/dist/core/actions/dom/events.js +45 -0
  35. package/dist/core/actions/dom/events.js.map +1 -0
  36. package/dist/core/actions/dom/svg.d.ts +7 -0
  37. package/dist/core/actions/dom/svg.d.ts.map +1 -0
  38. package/dist/core/actions/dom/svg.js +76 -0
  39. package/dist/core/actions/dom/svg.js.map +1 -0
  40. package/dist/core/actions/dom/value.d.ts +17 -0
  41. package/dist/core/actions/dom/value.d.ts.map +1 -0
  42. package/dist/core/actions/dom/value.js +204 -0
  43. package/dist/core/actions/dom/value.js.map +1 -0
  44. package/dist/core/actions/helpers.d.ts +18 -11
  45. package/dist/core/actions/helpers.d.ts.map +1 -1
  46. package/dist/core/actions/helpers.js +78 -68
  47. package/dist/core/actions/helpers.js.map +1 -1
  48. package/dist/core/actions/relayout.action.d.ts +2 -1
  49. package/dist/core/actions/relayout.action.d.ts.map +1 -1
  50. package/dist/core/actions/relayout.action.js +119 -30
  51. package/dist/core/actions/relayout.action.js.map +1 -1
  52. package/dist/core/actions/remove.action.d.ts +3 -2
  53. package/dist/core/actions/remove.action.d.ts.map +1 -1
  54. package/dist/core/actions/remove.action.js +22 -18
  55. package/dist/core/actions/remove.action.js.map +1 -1
  56. package/dist/core/actions/replace.action.d.ts +1 -1
  57. package/dist/core/actions/replace.action.d.ts.map +1 -1
  58. package/dist/core/actions/replace.action.js +36 -11
  59. package/dist/core/actions/replace.action.js.map +1 -1
  60. package/dist/core/actions/setAttr.action.d.ts +1 -1
  61. package/dist/core/actions/setAttr.action.d.ts.map +1 -1
  62. package/dist/core/actions/setAttr.action.js +55 -87
  63. package/dist/core/actions/setAttr.action.js.map +1 -1
  64. package/dist/core/actions/setProps.action.d.ts.map +1 -1
  65. package/dist/core/actions/setProps.action.js +2 -1
  66. package/dist/core/actions/setProps.action.js.map +1 -1
  67. package/dist/core/actions/setRef.action.d.ts +1 -1
  68. package/dist/core/actions/setRef.action.d.ts.map +1 -1
  69. package/dist/core/actions/setRef.action.js +5 -6
  70. package/dist/core/actions/setRef.action.js.map +1 -1
  71. package/dist/core/actions/setText.action.d.ts.map +1 -1
  72. package/dist/core/actions/setText.action.js +3 -3
  73. package/dist/core/actions/setText.action.js.map +1 -1
  74. package/dist/core/classComponent.d.ts +33 -0
  75. package/dist/core/classComponent.d.ts.map +1 -0
  76. package/dist/core/classComponent.js +127 -0
  77. package/dist/core/classComponent.js.map +1 -0
  78. package/dist/core/compact.d.ts +10 -29
  79. package/dist/core/compact.d.ts.map +1 -1
  80. package/dist/core/compact.js +12 -100
  81. package/dist/core/compact.js.map +1 -1
  82. package/dist/core/components.d.ts +2 -2
  83. package/dist/core/components.d.ts.map +1 -1
  84. package/dist/core/components.js +22 -5
  85. package/dist/core/components.js.map +1 -1
  86. package/dist/core/createElement.d.ts +9 -9
  87. package/dist/core/createElement.d.ts.map +1 -1
  88. package/dist/core/createElement.js +19 -3
  89. package/dist/core/createElement.js.map +1 -1
  90. package/dist/core/createRoot.js.map +1 -1
  91. package/dist/core/reactNodeToFiberNode.d.ts.map +1 -1
  92. package/dist/core/reactNodeToFiberNode.js +6 -1
  93. package/dist/core/reactNodeToFiberNode.js.map +1 -1
  94. package/dist/core/reconciliation/app.js +3 -3
  95. package/dist/core/reconciliation/app.js.map +1 -1
  96. package/dist/core/reconciliation/collect/fromApp.d.ts.map +1 -1
  97. package/dist/core/reconciliation/collect/fromApp.js +3 -27
  98. package/dist/core/reconciliation/collect/fromApp.js.map +1 -1
  99. package/dist/core/reconciliation/collect/fromChildrenPair.d.ts.map +1 -1
  100. package/dist/core/reconciliation/collect/fromChildrenPair.js +24 -15
  101. package/dist/core/reconciliation/collect/fromChildrenPair.js.map +1 -1
  102. package/dist/core/reconciliation/collect/fromComponent.d.ts +2 -2
  103. package/dist/core/reconciliation/collect/fromComponent.d.ts.map +1 -1
  104. package/dist/core/reconciliation/collect/fromComponent.js +4 -8
  105. package/dist/core/reconciliation/collect/fromComponent.js.map +1 -1
  106. package/dist/core/reconciliation/collect/fromFiberPair.d.ts.map +1 -1
  107. package/dist/core/reconciliation/collect/fromFiberPair.js +6 -4
  108. package/dist/core/reconciliation/collect/fromFiberPair.js.map +1 -1
  109. package/dist/core/reconciliation/collect/fromNewFiber.d.ts.map +1 -1
  110. package/dist/core/reconciliation/collect/fromNewFiber.js +7 -15
  111. package/dist/core/reconciliation/collect/fromNewFiber.js.map +1 -1
  112. package/dist/core/reconciliation/effects.d.ts.map +1 -1
  113. package/dist/core/reconciliation/effects.js +0 -5
  114. package/dist/core/reconciliation/effects.js.map +1 -1
  115. package/dist/core/reconciliation/errors/ReactError.d.ts +7 -0
  116. package/dist/core/reconciliation/errors/ReactError.d.ts.map +1 -0
  117. package/dist/core/reconciliation/errors/ReactError.js +26 -0
  118. package/dist/core/reconciliation/errors/ReactError.js.map +1 -0
  119. package/dist/core/reconciliation/errors/stack.d.ts +9 -0
  120. package/dist/core/reconciliation/errors/stack.d.ts.map +1 -0
  121. package/dist/core/reconciliation/errors/stack.js +80 -0
  122. package/dist/core/reconciliation/errors/stack.js.map +1 -0
  123. package/dist/core/reconciliation/fibers.d.ts +7 -0
  124. package/dist/core/reconciliation/fibers.d.ts.map +1 -1
  125. package/dist/core/reconciliation/fibers.js +9 -2
  126. package/dist/core/reconciliation/fibers.js.map +1 -1
  127. package/dist/core/reconciliation/heap.d.ts +18 -0
  128. package/dist/core/reconciliation/heap.d.ts.map +1 -0
  129. package/dist/core/reconciliation/heap.js +81 -0
  130. package/dist/core/reconciliation/heap.js.map +1 -0
  131. package/dist/core/reconciliation/invalidateFiber.d.ts.map +1 -1
  132. package/dist/core/reconciliation/invalidateFiber.js +10 -4
  133. package/dist/core/reconciliation/invalidateFiber.js.map +1 -1
  134. package/dist/core/reconciliation/mount.d.ts.map +1 -1
  135. package/dist/core/reconciliation/mount.js +17 -7
  136. package/dist/core/reconciliation/mount.js.map +1 -1
  137. package/dist/core/reconciliation/postCommit.d.ts +1 -1
  138. package/dist/core/reconciliation/postCommit.d.ts.map +1 -1
  139. package/dist/core/reconciliation/postCommit.js +19 -4
  140. package/dist/core/reconciliation/postCommit.js.map +1 -1
  141. package/dist/core/reconciliation/queue.d.ts +21 -0
  142. package/dist/core/reconciliation/queue.d.ts.map +1 -0
  143. package/dist/core/reconciliation/queue.js +55 -0
  144. package/dist/core/reconciliation/queue.js.map +1 -0
  145. package/dist/core/reconciliation/render.js +5 -5
  146. package/dist/core/reconciliation/render.js.map +1 -1
  147. package/dist/core/reconciliation/runFiberComponents.d.ts.map +1 -1
  148. package/dist/core/reconciliation/runFiberComponents.js +2 -1
  149. package/dist/core/reconciliation/runFiberComponents.js.map +1 -1
  150. package/dist/core/reconciliation/typeGuards.d.ts +9 -1
  151. package/dist/core/reconciliation/typeGuards.d.ts.map +1 -1
  152. package/dist/core/reconciliation/typeGuards.js +25 -0
  153. package/dist/core/reconciliation/typeGuards.js.map +1 -1
  154. package/dist/core/reconciliation/validateApp.d.ts +3 -0
  155. package/dist/core/reconciliation/validateApp.d.ts.map +1 -0
  156. package/dist/core/reconciliation/validateApp.js +74 -0
  157. package/dist/core/reconciliation/validateApp.js.map +1 -0
  158. package/dist/hooks/helpers.d.ts +2 -2
  159. package/dist/hooks/helpers.d.ts.map +1 -1
  160. package/dist/hooks/helpers.js +3 -2
  161. package/dist/hooks/helpers.js.map +1 -1
  162. package/dist/hooks/index.d.ts +1 -1
  163. package/dist/hooks/index.d.ts.map +1 -1
  164. package/dist/hooks/index.js +1 -1
  165. package/dist/hooks/index.js.map +1 -1
  166. package/dist/hooks/useContext.d.ts.map +1 -1
  167. package/dist/hooks/useContext.js +16 -0
  168. package/dist/hooks/useContext.js.map +1 -1
  169. package/dist/hooks/useEffect.d.ts +2 -1
  170. package/dist/hooks/useEffect.d.ts.map +1 -1
  171. package/dist/hooks/useEffect.js +1 -1
  172. package/dist/hooks/useEffect.js.map +1 -1
  173. package/dist/hooks/useRef.d.ts +8 -3
  174. package/dist/hooks/useRef.d.ts.map +1 -1
  175. package/dist/hooks/useRef.js +27 -0
  176. package/dist/hooks/useRef.js.map +1 -1
  177. package/dist/hooks/useState.d.ts +1 -1
  178. package/dist/hooks/useState.d.ts.map +1 -1
  179. package/dist/hooks/useState.js +24 -1
  180. package/dist/hooks/useState.js.map +1 -1
  181. package/dist/index.d.ts +8 -1
  182. package/dist/index.d.ts.map +1 -1
  183. package/dist/index.js +5 -0
  184. package/dist/index.js.map +1 -1
  185. package/dist/jsx-dev-runtime.d.ts +4 -4
  186. package/dist/jsx-dev-runtime.d.ts.map +1 -1
  187. package/dist/jsx-dev-runtime.js +4 -4
  188. package/dist/jsx-dev-runtime.js.map +1 -1
  189. package/dist/jsx-runtime.d.ts +3 -3
  190. package/dist/jsx-runtime.d.ts.map +1 -1
  191. package/dist/jsx-runtime.js +3 -3
  192. package/dist/jsx-runtime.js.map +1 -1
  193. package/dist/jsx.d.ts +176 -36
  194. package/dist/mocks.d.ts +21 -0
  195. package/dist/mocks.d.ts.map +1 -0
  196. package/dist/mocks.js +27 -0
  197. package/dist/mocks.js.map +1 -0
  198. package/dist/react.d.ts +46 -0
  199. package/dist/types/actions.d.ts +12 -4
  200. package/dist/types/actions.d.ts.map +1 -1
  201. package/dist/types/app.d.ts +17 -2
  202. package/dist/types/app.d.ts.map +1 -1
  203. package/dist/types/attributes.d.ts +42 -0
  204. package/dist/types/attributes.d.ts.map +1 -0
  205. package/dist/types/attributes.js +2 -0
  206. package/dist/types/attributes.js.map +1 -0
  207. package/dist/types/common.d.ts +13 -0
  208. package/dist/types/common.d.ts.map +1 -0
  209. package/dist/types/common.js +2 -0
  210. package/dist/types/common.js.map +1 -0
  211. package/dist/types/component.d.ts +5 -1
  212. package/dist/types/component.d.ts.map +1 -1
  213. package/dist/types/context.d.ts +3 -2
  214. package/dist/types/context.d.ts.map +1 -1
  215. package/dist/types/core.d.ts +17 -13
  216. package/dist/types/core.d.ts.map +1 -1
  217. package/dist/types/dom.d.ts +23 -27
  218. package/dist/types/dom.d.ts.map +1 -1
  219. package/dist/types/events.d.ts +31 -0
  220. package/dist/types/events.d.ts.map +1 -0
  221. package/dist/types/events.js +2 -0
  222. package/dist/types/events.js.map +1 -0
  223. package/dist/types/fiber.d.ts +31 -11
  224. package/dist/types/fiber.d.ts.map +1 -1
  225. package/dist/types/fiber.js +5 -1
  226. package/dist/types/fiber.js.map +1 -1
  227. package/dist/types/hooks.d.ts +8 -5
  228. package/dist/types/hooks.d.ts.map +1 -1
  229. package/dist/types/react.d.ts +35 -0
  230. package/dist/types/react.d.ts.map +1 -0
  231. package/dist/types/react.js +2 -0
  232. package/dist/types/react.js.map +1 -0
  233. package/dist/types/refs.d.ts +5 -8
  234. package/dist/types/refs.d.ts.map +1 -1
  235. package/package.json +15 -3
  236. package/dist/core/reconciliation/validateTree.d.ts +0 -6
  237. package/dist/core/reconciliation/validateTree.d.ts.map +0 -1
  238. package/dist/core/reconciliation/validateTree.js +0 -48
  239. package/dist/core/reconciliation/validateTree.js.map +0 -1
@@ -1,10 +1,12 @@
1
1
  import type { ReactContext } from './context';
2
- import type { ContextFiberNode } from './fiber';
3
- import type { Ref } from './refs';
2
+ import type { ContextFiberNode, FiberNode } from './fiber';
3
+ import type { RefObject } from './refs';
4
4
  export type UseStateItem<T = unknown> = {
5
5
  type: 'state';
6
6
  state: T;
7
7
  setter: StateSetter<T>;
8
+ destructor: null | (() => void);
9
+ move: (newFiber: FiberNode) => void;
8
10
  };
9
11
  export type UseMemoItem = {
10
12
  type: 'memo';
@@ -13,7 +15,7 @@ export type UseMemoItem = {
13
15
  };
14
16
  export type UseRefItem<T = unknown> = {
15
17
  type: 'ref';
16
- value: Ref<T>;
18
+ value: RefObject<T>;
17
19
  };
18
20
  export type UseEffectItem = {
19
21
  type: 'effect';
@@ -26,6 +28,7 @@ export type UseContextItem<T = unknown> = {
26
28
  type: 'context';
27
29
  ctx: ReactContext<T>;
28
30
  destructor: () => void;
31
+ move: (newFiber: FiberNode) => void;
29
32
  providerFiber: ContextFiberNode | null;
30
33
  };
31
34
  export type HookStateItem = UseStateItem | UseMemoItem | UseRefItem | UseEffectItem | UseContextItem;
@@ -36,12 +39,12 @@ export type HookStore = HookStateItem[];
36
39
  */
37
40
  export type HookDeps = unknown[];
38
41
  /** const [, setter] = useState(...) */
39
- export type StateSetter<T> = (valueOrFn: (T extends Function ? (prev: T) => T : T) | ((prev: T) => T)) => void;
42
+ export type StateSetter<T> = (valueOrFn: T | ((prev: T) => T)) => void;
40
43
  /**
41
44
  * In this library useEffect & useLayoutEffect are a little more complex. They
42
45
  * support async functions and abort signals. But they are still back-compatible
43
46
  * with the original React ones.
44
47
  */
45
48
  export type EffectHandler = (signal: AbortSignal) => void | Promise<void> | (() => void);
46
- export type EffectMode = 'refs' | 'layout' | 'normal';
49
+ export type EffectMode = 'afterActions' | 'refsUnmount' | 'refsMount' | 'layout' | 'normal';
47
50
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/types/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAElC,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,IAAI;IACtC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI;IACpC,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,QA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U,GACV,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;AAEjC,uCAAuC;AACvC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,MAAM,EAAE,WAAW,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEzC,MAAM,MAAM,UAAU,GAElB,cAAc,GAEd,aAAa,GACb,WAAW,GAEX,QAAQ,GAER,QAAQ,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ReactContext } from './context';
2
+ import { type ReactComponent } from './component';
3
+ import type { ElementCommonAttrs, UnknownProps } from './core';
4
+ import type { EventHandler, PatchEvent } from './events';
5
+ import type { TagNativeProps } from './attributes';
6
+ import type { TagProps, TagStyles } from './dom';
7
+ import type { Ref } from './refs';
8
+ export type FC<Props extends UnknownProps = UnknownProps> = ReactComponent<Props>;
9
+ export type ReactNode = JSX.Element;
10
+ export type Context<T> = ReactContext<T>;
11
+ export type CSSProperties = TagStyles;
12
+ export type ComponentType<Props extends UnknownProps = UnknownProps> = ReactComponent<Props>;
13
+ export type ForwardRefExoticComponent<Props extends UnknownProps = UnknownProps> = FC<Props>;
14
+ export type ErrorInfo = {
15
+ componentStack: string | null;
16
+ digest?: string | null;
17
+ };
18
+ export type SyntheticEvent<T extends Element = Element, E extends Event = Event> = PatchEvent<T, E>;
19
+ export type ClipboardEvent<T extends Element = Element> = SyntheticEvent<T> & {
20
+ clipboardData: DataTransfer;
21
+ };
22
+ export type FormEvent<T extends Element = Element> = SyntheticEvent<T>;
23
+ export type ChangeEvent<T extends Element = Element> = Omit<SyntheticEvent<T>, 'target'> & {
24
+ target: EventTarget & T;
25
+ };
26
+ export type ChangeEventHandler<T extends Element = Element> = EventHandler<T, Event>;
27
+ export type KeyboardEvent<T extends Element = Element> = PatchEvent<T, globalThis.KeyboardEvent>;
28
+ export type ReactEventHandler<T extends Element = Element> = EventHandler<T, Event>;
29
+ export type HTMLAttributes<T extends Element> = TagNativeProps<T>;
30
+ export type TextareaHTMLAttributes<T extends Element = HTMLTextAreaElement> = TagProps<T>;
31
+ export type InputHTMLAttributes<T extends Element = HTMLInputElement> = TagProps<T>;
32
+ export type RefAttributes<T extends Element> = {
33
+ ref?: Ref<T>;
34
+ } & ElementCommonAttrs;
35
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/types/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAKlC,MAAM,MAAM,EAAE,CAAC,KAAK,SAAS,YAAY,GAAG,YAAY,IACtD,cAAc,CAAC,KAAK,CAAC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC;AACpC,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AACzC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;A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AAMzB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,OAAO,GAAG,mBAAmB,IACxE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACd,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,OAAO,GAAG,gBAAgB,IAClE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACd,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,IACvC;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GACjB,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/types/react.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  /** A ref produced in `useRef(default)` */
2
- export type Ref<T> = {
2
+ export type RefObject<T> = {
3
3
  current: T;
4
4
  };
5
5
  /**
@@ -8,12 +8,9 @@ export type Ref<T> = {
8
8
  * <div ref={(node: HTMLDivElement | null) => …}
9
9
  * // ^ RefSetter<HTMLDivElement | null>
10
10
  **/
11
- export type RefSetter<T> = (v: T) => void;
11
+ export type RefSetter<T> = (v: T | null) => void;
12
12
  /**
13
- * HTML Tag refs:
14
- * @example
15
- * const ref = useRef<HTMLDivElement>()
16
- * <div ref={ref}/>
17
- **/
18
- export type HtmlRef<T extends HTMLElement | SVGElement> = Ref<T | null | undefined>;
13
+ * Both `RefSetter` or `RefObject`.
14
+ */
15
+ export type Ref<T> = RefObject<T | null> | RefSetter<T>;
19
16
  //# sourceMappingURL=refs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../src/types/refs.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAEpC;;;;;IAKI;AACJ,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;AAE1C;;;;;IAKI;AACJ,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,WAAW,GAAG,UAAU,IAAI,GAAG,CACzD,CAAC,GACD,IAAI,GACJ,SAAS,CACZ,CAAC"}
1
+ {"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../../src/types/refs.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAE1C;;;;;IAKI;AACJ,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
2
  "name": "@faiwer/react",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "A hobby project. A naive and simplified React implementation",
5
- "keywords": ["react", "jsx", "hooks", "virtual-dom", "frontend", "ui-library"],
5
+ "keywords": [
6
+ "react",
7
+ "jsx",
8
+ "hooks",
9
+ "virtual-dom",
10
+ "frontend",
11
+ "ui-library"
12
+ ],
6
13
  "repository": {
7
14
  "type": "git",
8
15
  "url": "https://github.com/faiwer/faiwer-react.git"
@@ -22,6 +29,10 @@
22
29
  "types": "./dist/index.d.ts",
23
30
  "default": "./dist/index.js"
24
31
  },
32
+ "./client": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
25
36
  "./jsx-runtime": {
26
37
  "types": "./dist/jsx-runtime.d.ts",
27
38
  "default": "./dist/jsx-runtime.js"
@@ -35,7 +46,8 @@
35
46
  }
36
47
  },
37
48
  "scripts": {
38
- "build": "npm run clean && npx tsgo -p tsconfig.build.json && npx tsc-alias -p tsconfig.build.json && cp src/jsx.d.ts dist/jsx.d.ts",
49
+ "build": "npm run clean && npx tsgo -p tsconfig.build.json && npx tsc-alias -p tsconfig.build.json && cp src/jsx.d.ts dist/jsx.d.ts && npm run prepend-dts",
50
+ "prepend-dts": "cp ./src/react.d.ts ./dist && printf '/// <reference path=\"./jsx.d.ts\" />\n/// <reference path=\"./react.d.ts\" />\n' | cat - ./dist/index.d.ts > temp && mv temp ./dist/index.d.ts",
39
51
  "clean": "rm -rf dist",
40
52
  "prepublishOnly": "npm run build",
41
53
  "test": "jest",
@@ -1,6 +0,0 @@
1
- import type { FiberNode } from '../../types';
2
- /**
3
- * Validates the given fiber node and its subnodes. In case of error it throws.
4
- */
5
- export declare const validateTree: (node: FiberNode, path?: string) => void;
6
- //# sourceMappingURL=validateTree.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateTree.d.ts","sourceRoot":"","sources":["../../../src/core/reconciliation/validateTree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD;;GAEG;AACH,eAAO,MAAM,YAAY,0CA+BxB,CAAC"}
@@ -1,48 +0,0 @@
1
- import { nullthrows } from '../../utils';
2
- /**
3
- * Validates the given fiber node and its subnodes. In case of error it throws.
4
- */
5
- export const validateTree = (node, path = '') => {
6
- // Each rendered node must be associated with at least one real DOM node.
7
- nullthrows(node.element, `${path}.element`);
8
- if (node.type === 'tag') {
9
- if (!node.tag) {
10
- throw new Error(`${path} has empty "tag" field `);
11
- }
12
- const domNode = node.role === 'portal' ? node.data : node.element;
13
- if (!(domNode instanceof Element)) {
14
- throw new Error(`${path} doesn't have element`);
15
- }
16
- }
17
- else if (node.type === 'component' && !node.component) {
18
- throw new Error(`${path} has empty "component" field `);
19
- }
20
- else if (node.role === 'context' && !node.data.ctx) {
21
- throw new Error(`${path} has no context`);
22
- }
23
- else if (node.type === 'text' && !(node.element instanceof Text)) {
24
- throw new Error(`${path}'s element is not a Text`);
25
- }
26
- for (const [idx, child] of node.children.entries()) {
27
- const label = getFiberPathLabel(child);
28
- const key = (child.key ?? idx) + `^${label}`;
29
- if (child.parent !== node) {
30
- throw new Error(`${path}.${key}.parent is ${child.parent ? 'wrong' : 'empty'}`);
31
- }
32
- validateTree(child, `${path}.${key}`);
33
- }
34
- };
35
- const getFiberPathLabel = (node) => {
36
- return node.type === 'text' || node.type === 'null'
37
- ? node.type
38
- : node.type === 'tag'
39
- ? `<${nullthrows(node.tag)}/>`
40
- : node.type === 'fragment'
41
- ? node.role === 'context'
42
- ? '<ctx/>'
43
- : '[]'
44
- : node.type === 'component'
45
- ? `<${node.component.name || 'Comp'}/>`
46
- : 'unknown';
47
- };
48
- //# sourceMappingURL=validateTree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateTree.js","sourceRoot":"","sources":["../../../src/core/reconciliation/validateTree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAe,EAAE,IAAI,GAAG,EAAE,EAAQ,EAAE,CAAC;IAChE,yEAAyE;IACzE,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,UAAU,CAAC,CAAC;IAE5C,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,yBAAyB,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,C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