isomorfeus-preact 10.9.0 → 22.9.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -3
  3. data/README.md +23 -39
  4. data/lib/browser/delegate_native.rb +94 -72
  5. data/lib/browser/document.rb +38 -0
  6. data/lib/browser/element.rb +160 -176
  7. data/lib/browser/event.rb +99 -94
  8. data/lib/browser/history.rb +40 -20
  9. data/lib/browser/location.rb +59 -0
  10. data/lib/browser/window.rb +58 -0
  11. data/lib/data_uri/open_uri.rb +18 -0
  12. data/lib/data_uri/uri.rb +61 -0
  13. data/lib/data_uri.rb +4 -0
  14. data/lib/isomorfeus/preact/config.rb +42 -54
  15. data/lib/isomorfeus/preact/imports.rb +5 -20
  16. data/lib/isomorfeus/preact/ssr.rb +34 -0
  17. data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
  18. data/lib/isomorfeus/preact/version.rb +5 -0
  19. data/lib/isomorfeus/preact/view_helper.rb +72 -0
  20. data/lib/isomorfeus/props/validator.rb +19 -11
  21. data/lib/isomorfeus/top_level.rb +55 -33
  22. data/lib/isomorfeus-preact.rb +78 -103
  23. data/lib/link.rb +52 -0
  24. data/lib/lucid_app.rb +117 -0
  25. data/lib/lucid_component.rb +154 -0
  26. data/lib/nano_css.rb +282 -465
  27. data/lib/preact/component.rb +222 -0
  28. data/lib/preact/component_resolution.rb +49 -83
  29. data/lib/preact/context.rb +68 -0
  30. data/lib/preact/elements.rb +2 -9
  31. data/lib/preact/module_component_resolution.rb +50 -0
  32. data/lib/preact/prop_declaration_mixin.rb +73 -0
  33. data/lib/preact.rb +1548 -257
  34. data/lib/redirect.rb +34 -0
  35. data/lib/route.rb +15 -0
  36. data/lib/router.rb +145 -0
  37. data/lib/switch.rb +70 -0
  38. data/opal/iso_uri.rb +29 -0
  39. data/opal/uri/common.rb +18 -0
  40. data/opal/uri/generic.rb +47 -0
  41. metadata +45 -309
  42. data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
  43. data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
  44. data/lib/isomorfeus/preact/ssr/history.rb +0 -23
  45. data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
  46. data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
  47. data/lib/isomorfeus/preact_view_helper.rb +0 -129
  48. data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
  49. data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
  50. data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
  51. data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
  52. data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
  53. data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
  54. data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
  55. data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
  56. data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
  57. data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
  58. data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
  59. data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
  60. data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
  61. data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
  62. data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
  63. data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
  64. data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -164
  65. data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
  66. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
  67. data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
  68. data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
  69. data/lib/lucid_app/context.rb +0 -24
  70. data/lib/lucid_prop_declaration/mixin.rb +0 -126
  71. data/lib/preact/component/api.rb +0 -137
  72. data/lib/preact/component/base.rb +0 -7
  73. data/lib/preact/component/callbacks.rb +0 -111
  74. data/lib/preact/component/initializer.rb +0 -7
  75. data/lib/preact/component/mixin.rb +0 -11
  76. data/lib/preact/component/native_component_constructor.rb +0 -77
  77. data/lib/preact/context_wrapper.rb +0 -48
  78. data/lib/preact/native_constant_wrapper.rb +0 -29
  79. data/lib/preact/option_hooks.rb +0 -98
  80. data/lib/preact/params.rb +0 -16
  81. data/lib/preact/props.rb +0 -69
  82. data/lib/preact/ref.rb +0 -17
  83. data/lib/preact/state.rb +0 -87
  84. data/lib/preact/version.rb +0 -3
  85. data/node_modules/.package-lock.json +0 -38
  86. data/node_modules/preact/LICENSE +0 -21
  87. data/node_modules/preact/README.md +0 -188
  88. data/node_modules/preact/compat/LICENSE +0 -21
  89. data/node_modules/preact/compat/client.js +0 -19
  90. data/node_modules/preact/compat/client.mjs +0 -17
  91. data/node_modules/preact/compat/dist/compat.js +0 -2
  92. data/node_modules/preact/compat/dist/compat.js.map +0 -1
  93. data/node_modules/preact/compat/dist/compat.mjs +0 -2
  94. data/node_modules/preact/compat/dist/compat.module.js +0 -2
  95. data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
  96. data/node_modules/preact/compat/dist/compat.umd.js +0 -2
  97. data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
  98. data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
  99. data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
  100. data/node_modules/preact/compat/jsx-runtime.js +0 -3
  101. data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
  102. data/node_modules/preact/compat/package.json +0 -49
  103. data/node_modules/preact/compat/scheduler.js +0 -15
  104. data/node_modules/preact/compat/scheduler.mjs +0 -23
  105. data/node_modules/preact/compat/server.browser.js +0 -4
  106. data/node_modules/preact/compat/server.js +0 -15
  107. data/node_modules/preact/compat/server.mjs +0 -4
  108. data/node_modules/preact/compat/src/Children.js +0 -21
  109. data/node_modules/preact/compat/src/PureComponent.js +0 -15
  110. data/node_modules/preact/compat/src/forwardRef.js +0 -44
  111. data/node_modules/preact/compat/src/index.d.ts +0 -164
  112. data/node_modules/preact/compat/src/index.js +0 -223
  113. data/node_modules/preact/compat/src/internal.d.ts +0 -47
  114. data/node_modules/preact/compat/src/memo.js +0 -34
  115. data/node_modules/preact/compat/src/portals.js +0 -82
  116. data/node_modules/preact/compat/src/render.js +0 -238
  117. data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
  118. data/node_modules/preact/compat/src/suspense-list.js +0 -126
  119. data/node_modules/preact/compat/src/suspense.d.ts +0 -15
  120. data/node_modules/preact/compat/src/suspense.js +0 -270
  121. data/node_modules/preact/compat/src/util.js +0 -28
  122. data/node_modules/preact/compat/test-utils.js +0 -1
  123. data/node_modules/preact/debug/LICENSE +0 -21
  124. data/node_modules/preact/debug/dist/debug.js +0 -2
  125. data/node_modules/preact/debug/dist/debug.js.map +0 -1
  126. data/node_modules/preact/debug/dist/debug.mjs +0 -2
  127. data/node_modules/preact/debug/dist/debug.module.js +0 -2
  128. data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
  129. data/node_modules/preact/debug/dist/debug.umd.js +0 -2
  130. data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
  131. data/node_modules/preact/debug/package.json +0 -26
  132. data/node_modules/preact/debug/src/check-props.js +0 -54
  133. data/node_modules/preact/debug/src/component-stack.js +0 -146
  134. data/node_modules/preact/debug/src/constants.js +0 -3
  135. data/node_modules/preact/debug/src/debug.js +0 -437
  136. data/node_modules/preact/debug/src/index.js +0 -6
  137. data/node_modules/preact/debug/src/internal.d.ts +0 -82
  138. data/node_modules/preact/debug/src/util.js +0 -11
  139. data/node_modules/preact/devtools/LICENSE +0 -21
  140. data/node_modules/preact/devtools/dist/devtools.js +0 -2
  141. data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
  142. data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
  143. data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
  144. data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
  145. data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
  146. data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
  147. data/node_modules/preact/devtools/package.json +0 -25
  148. data/node_modules/preact/devtools/src/devtools.js +0 -10
  149. data/node_modules/preact/devtools/src/index.d.ts +0 -8
  150. data/node_modules/preact/devtools/src/index.js +0 -15
  151. data/node_modules/preact/dist/preact.js +0 -2
  152. data/node_modules/preact/dist/preact.js.map +0 -1
  153. data/node_modules/preact/dist/preact.min.js +0 -2
  154. data/node_modules/preact/dist/preact.min.js.map +0 -1
  155. data/node_modules/preact/dist/preact.mjs +0 -2
  156. data/node_modules/preact/dist/preact.module.js +0 -2
  157. data/node_modules/preact/dist/preact.module.js.map +0 -1
  158. data/node_modules/preact/dist/preact.umd.js +0 -2
  159. data/node_modules/preact/dist/preact.umd.js.map +0 -1
  160. data/node_modules/preact/hooks/LICENSE +0 -21
  161. data/node_modules/preact/hooks/dist/hooks.js +0 -2
  162. data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
  163. data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
  164. data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
  165. data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
  166. data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
  167. data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
  168. data/node_modules/preact/hooks/package.json +0 -35
  169. data/node_modules/preact/hooks/src/index.d.ts +0 -139
  170. data/node_modules/preact/hooks/src/index.js +0 -417
  171. data/node_modules/preact/hooks/src/internal.d.ts +0 -78
  172. data/node_modules/preact/jsx-runtime/LICENSE +0 -21
  173. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
  174. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
  175. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
  176. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
  177. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
  178. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
  179. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
  180. data/node_modules/preact/jsx-runtime/package.json +0 -28
  181. data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
  182. data/node_modules/preact/jsx-runtime/src/index.js +0 -77
  183. data/node_modules/preact/package.json +0 -304
  184. data/node_modules/preact/src/cjs.js +0 -3
  185. data/node_modules/preact/src/clone-element.js +0 -34
  186. data/node_modules/preact/src/component.js +0 -225
  187. data/node_modules/preact/src/constants.js +0 -3
  188. data/node_modules/preact/src/create-context.js +0 -68
  189. data/node_modules/preact/src/create-element.js +0 -98
  190. data/node_modules/preact/src/diff/catch-error.js +0 -40
  191. data/node_modules/preact/src/diff/children.js +0 -335
  192. data/node_modules/preact/src/diff/index.js +0 -533
  193. data/node_modules/preact/src/diff/props.js +0 -158
  194. data/node_modules/preact/src/index.d.ts +0 -317
  195. data/node_modules/preact/src/index.js +0 -13
  196. data/node_modules/preact/src/internal.d.ts +0 -155
  197. data/node_modules/preact/src/jsx.d.ts +0 -1014
  198. data/node_modules/preact/src/options.js +0 -16
  199. data/node_modules/preact/src/render.js +0 -75
  200. data/node_modules/preact/src/util.js +0 -27
  201. data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
  202. data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
  203. data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
  204. data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
  205. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
  206. data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
  207. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
  208. data/node_modules/preact/test-utils/package.json +0 -28
  209. data/node_modules/preact/test-utils/src/index.d.ts +0 -3
  210. data/node_modules/preact/test-utils/src/index.js +0 -118
  211. data/node_modules/preact-render-to-string/LICENSE +0 -21
  212. data/node_modules/preact-render-to-string/README.md +0 -102
  213. data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
  214. data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
  215. data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
  216. data/node_modules/preact-render-to-string/dist/index.js +0 -1
  217. data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
  218. data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
  219. data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
  220. data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
  221. data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
  222. data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
  223. data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
  224. data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
  225. data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
  226. data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
  227. data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
  228. data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
  229. data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
  230. data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
  231. data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
  232. data/node_modules/preact-render-to-string/jsx.js +0 -1
  233. data/node_modules/preact-render-to-string/package.json +0 -142
  234. data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
  235. data/node_modules/preact-render-to-string/src/index.js +0 -462
  236. data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
  237. data/node_modules/preact-render-to-string/src/jsx.js +0 -76
  238. data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
  239. data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
  240. data/node_modules/preact-render-to-string/src/util.js +0 -78
  241. data/node_modules/preact-render-to-string/typings.json +0 -5
  242. data/node_modules/pretty-format/.npmignore +0 -3
  243. data/node_modules/pretty-format/LICENSE.md +0 -15
  244. data/node_modules/pretty-format/README.md +0 -94
  245. data/node_modules/pretty-format/index.js +0 -343
  246. data/node_modules/pretty-format/package.json +0 -26
  247. data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
  248. data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
  249. data/node_modules/pretty-format/printString.js +0 -7
  250. data/node_modules/wouter-preact/cjs/index.js +0 -180
  251. data/node_modules/wouter-preact/cjs/matcher.js +0 -72
  252. data/node_modules/wouter-preact/cjs/package.json +0 -1
  253. data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
  254. data/node_modules/wouter-preact/cjs/static-location.js +0 -21
  255. data/node_modules/wouter-preact/cjs/use-location.js +0 -94
  256. data/node_modules/wouter-preact/index.d.ts +0 -110
  257. data/node_modules/wouter-preact/index.js +0 -178
  258. data/node_modules/wouter-preact/matcher.d.ts +0 -30
  259. data/node_modules/wouter-preact/matcher.js +0 -66
  260. data/node_modules/wouter-preact/package.json +0 -33
  261. data/node_modules/wouter-preact/react-deps.js +0 -15
  262. data/node_modules/wouter-preact/static-location.d.ts +0 -16
  263. data/node_modules/wouter-preact/static-location.js +0 -17
  264. data/node_modules/wouter-preact/use-location.d.ts +0 -43
  265. data/node_modules/wouter-preact/use-location.js +0 -86
  266. data/package.json +0 -8
@@ -1,317 +0,0 @@
1
- export as namespace preact;
2
-
3
- import { JSXInternal } from './jsx';
4
-
5
- export import JSX = JSXInternal;
6
-
7
- //
8
- // Preact Virtual DOM
9
- // -----------------------------------
10
-
11
- export interface VNode<P = {}> {
12
- type: ComponentType<P> | string;
13
- props: P & { children: ComponentChildren };
14
- key: Key;
15
- /**
16
- * ref is not guaranteed by React.ReactElement, for compatibility reasons
17
- * with popular react libs we define it as optional too
18
- */
19
- ref?: Ref<any> | null;
20
- /**
21
- * The time this `vnode` started rendering. Will only be set when
22
- * the devtools are attached.
23
- * Default value: `0`
24
- */
25
- startTime?: number;
26
- /**
27
- * The time that the rendering of this `vnode` was completed. Will only be
28
- * set when the devtools are attached.
29
- * Default value: `-1`
30
- */
31
- endTime?: number;
32
- }
33
-
34
- //
35
- // Preact Component interface
36
- // -----------------------------------
37
-
38
- export type Key = string | number | any;
39
-
40
- export type RefObject<T> = { current: T | null };
41
- export type RefCallback<T> = (instance: T | null) => void;
42
- export type Ref<T> = RefObject<T> | RefCallback<T>;
43
-
44
- export type ComponentChild =
45
- | VNode<any>
46
- | object
47
- | string
48
- | number
49
- | bigint
50
- | boolean
51
- | null
52
- | undefined;
53
- export type ComponentChildren = ComponentChild[] | ComponentChild;
54
-
55
- export interface Attributes {
56
- key?: Key;
57
- jsx?: boolean;
58
- }
59
-
60
- export interface ClassAttributes<T> extends Attributes {
61
- ref?: Ref<T>;
62
- }
63
-
64
- export interface PreactDOMAttributes {
65
- children?: ComponentChildren;
66
- dangerouslySetInnerHTML?: {
67
- __html: string;
68
- };
69
- }
70
-
71
- export interface ErrorInfo {
72
- componentStack?: string;
73
- }
74
-
75
- export type RenderableProps<P, RefType = any> = P &
76
- Readonly<Attributes & { children?: ComponentChildren; ref?: Ref<RefType> }>;
77
-
78
- export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
79
- export type ComponentFactory<P = {}> = ComponentType<P>;
80
-
81
- export type ComponentProps<
82
- C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
83
- > = C extends ComponentType<infer P>
84
- ? P
85
- : C extends keyof JSXInternal.IntrinsicElements
86
- ? JSXInternal.IntrinsicElements[C]
87
- : never;
88
-
89
- export interface FunctionComponent<P = {}> {
90
- (props: RenderableProps<P>, context?: any): VNode<any> | null;
91
- displayName?: string;
92
- defaultProps?: Partial<P>;
93
- }
94
- export interface FunctionalComponent<P = {}> extends FunctionComponent<P> {}
95
-
96
- export interface ComponentClass<P = {}, S = {}> {
97
- new (props: P, context?: any): Component<P, S>;
98
- displayName?: string;
99
- defaultProps?: Partial<P>;
100
- contextType?: Context<any>;
101
- getDerivedStateFromProps?(
102
- props: Readonly<P>,
103
- state: Readonly<S>
104
- ): Partial<S> | null;
105
- getDerivedStateFromError?(error: any): Partial<S> | null;
106
- }
107
- export interface ComponentConstructor<P = {}, S = {}>
108
- extends ComponentClass<P, S> {}
109
-
110
- // Type alias for a component instance considered generally, whether stateless or stateful.
111
- export type AnyComponent<P = {}, S = {}> =
112
- | FunctionComponent<P>
113
- | Component<P, S>;
114
-
115
- export interface Component<P = {}, S = {}> {
116
- componentWillMount?(): void;
117
- componentDidMount?(): void;
118
- componentWillUnmount?(): void;
119
- getChildContext?(): object;
120
- componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
121
- shouldComponentUpdate?(
122
- nextProps: Readonly<P>,
123
- nextState: Readonly<S>,
124
- nextContext: any
125
- ): boolean;
126
- componentWillUpdate?(
127
- nextProps: Readonly<P>,
128
- nextState: Readonly<S>,
129
- nextContext: any
130
- ): void;
131
- getSnapshotBeforeUpdate?(oldProps: Readonly<P>, oldState: Readonly<S>): any;
132
- componentDidUpdate?(
133
- previousProps: Readonly<P>,
134
- previousState: Readonly<S>,
135
- snapshot: any
136
- ): void;
137
- componentDidCatch?(error: any, errorInfo: ErrorInfo): void;
138
- }
139
-
140
- export abstract class Component<P, S> {
141
- constructor(props?: P, context?: any);
142
-
143
- static displayName?: string;
144
- static defaultProps?: any;
145
- static contextType?: Context<any>;
146
-
147
- // Static members cannot reference class type parameters. This is not
148
- // supported in TypeScript. Reusing the same type arguments from `Component`
149
- // will lead to an impossible state where one cannot satisfy the type
150
- // constraint under no circumstances, see #1356.In general type arguments
151
- // seem to be a bit buggy and not supported well at the time of this
152
- // writing with TS 3.3.3333.
153
- static getDerivedStateFromProps?(
154
- props: Readonly<object>,
155
- state: Readonly<object>
156
- ): object | null;
157
- static getDerivedStateFromError?(error: any): object | null;
158
-
159
- state: Readonly<S>;
160
- props: RenderableProps<P>;
161
- context: any;
162
- base?: Element | Text;
163
-
164
- // From https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e836acc75a78cf0655b5dfdbe81d69fdd4d8a252/types/react/index.d.ts#L402
165
- // // We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
166
- // // See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
167
- setState<K extends keyof S>(
168
- state:
169
- | ((
170
- prevState: Readonly<S>,
171
- props: Readonly<P>
172
- ) => Pick<S, K> | Partial<S> | null)
173
- | (Pick<S, K> | Partial<S> | null),
174
- callback?: () => void
175
- ): void;
176
-
177
- forceUpdate(callback?: () => void): void;
178
-
179
- abstract render(
180
- props?: RenderableProps<P>,
181
- state?: Readonly<S>,
182
- context?: any
183
- ): ComponentChild;
184
- }
185
-
186
- //
187
- // Preact createElement
188
- // -----------------------------------
189
-
190
- export function createElement(
191
- type: string,
192
- props:
193
- | (JSXInternal.HTMLAttributes &
194
- JSXInternal.SVGAttributes &
195
- Record<string, any>)
196
- | null,
197
- ...children: ComponentChildren[]
198
- ): VNode<any>;
199
- export function createElement<P>(
200
- type: ComponentType<P>,
201
- props: (Attributes & P) | null,
202
- ...children: ComponentChildren[]
203
- ): VNode<any>;
204
- export namespace createElement {
205
- export import JSX = JSXInternal;
206
- }
207
-
208
- export function h(
209
- type: string,
210
- props:
211
- | (JSXInternal.HTMLAttributes &
212
- JSXInternal.SVGAttributes &
213
- Record<string, any>)
214
- | null,
215
- ...children: ComponentChildren[]
216
- ): VNode<any>;
217
- export function h<P>(
218
- type: ComponentType<P>,
219
- props: (Attributes & P) | null,
220
- ...children: ComponentChildren[]
221
- ): VNode<any>;
222
- export namespace h {
223
- export import JSX = JSXInternal;
224
- }
225
-
226
- //
227
- // Preact render
228
- // -----------------------------------
229
-
230
- export function render(
231
- vnode: ComponentChild,
232
- parent: Element | Document | ShadowRoot | DocumentFragment,
233
- replaceNode?: Element | Text
234
- ): void;
235
- export function hydrate(
236
- vnode: ComponentChild,
237
- parent: Element | Document | ShadowRoot | DocumentFragment
238
- ): void;
239
- export function cloneElement(
240
- vnode: VNode<any>,
241
- props?: any,
242
- ...children: ComponentChildren[]
243
- ): VNode<any>;
244
- export function cloneElement<P>(
245
- vnode: VNode<P>,
246
- props?: any,
247
- ...children: ComponentChildren[]
248
- ): VNode<P>;
249
-
250
- //
251
- // Preact Built-in Components
252
- // -----------------------------------
253
-
254
- // TODO: Revisit what the public type of this is...
255
- export const Fragment: FunctionComponent<{}>;
256
-
257
- //
258
- // Preact options
259
- // -----------------------------------
260
-
261
- /**
262
- * Global options for preact
263
- */
264
- export interface Options {
265
- /** Attach a hook that is invoked whenever a VNode is created. */
266
- vnode?(vnode: VNode): void;
267
- /** Attach a hook that is invoked immediately before a vnode is unmounted. */
268
- unmount?(vnode: VNode): void;
269
- /** Attach a hook that is invoked after a vnode has rendered. */
270
- diffed?(vnode: VNode): void;
271
- event?(e: Event): any;
272
- requestAnimationFrame?(callback: () => void): void;
273
- debounceRendering?(cb: () => void): void;
274
- useDebugValue?(value: string | number): void;
275
- _addHookName?(name: string | number): void;
276
- __suspenseDidResolve?(vnode: VNode, cb: () => void): void;
277
- // __canSuspenseResolve?(vnode: VNode, cb: () => void): void;
278
- }
279
-
280
- export const options: Options;
281
-
282
- //
283
- // Preact helpers
284
- // -----------------------------------
285
- export function createRef<T = any>(): RefObject<T>;
286
- export function toChildArray(
287
- children: ComponentChildren
288
- ): Array<VNode | string | number>;
289
- export function isValidElement(vnode: any): vnode is VNode;
290
-
291
- //
292
- // Context
293
- // -----------------------------------
294
- export interface Consumer<T>
295
- extends FunctionComponent<{
296
- children: (value: T) => ComponentChildren;
297
- }> {}
298
- export interface PreactConsumer<T> extends Consumer<T> {}
299
-
300
- export interface Provider<T>
301
- extends FunctionComponent<{
302
- value: T;
303
- children: ComponentChildren;
304
- }> {}
305
- export interface PreactProvider<T> extends Provider<T> {}
306
- export type ContextType<C extends Context<any>> = C extends Context<infer T>
307
- ? T
308
- : never;
309
-
310
- export interface Context<T> {
311
- Consumer: Consumer<T>;
312
- Provider: Provider<T>;
313
- displayName?: string;
314
- }
315
- export interface PreactContext<T> extends Context<T> {}
316
-
317
- export function createContext<T>(defaultValue: T): Context<T>;
@@ -1,13 +0,0 @@
1
- export { render, hydrate } from './render';
2
- export {
3
- createElement,
4
- createElement as h,
5
- Fragment,
6
- createRef,
7
- isValidElement
8
- } from './create-element';
9
- export { Component } from './component';
10
- export { cloneElement } from './clone-element';
11
- export { createContext } from './create-context';
12
- export { toChildArray } from './diff/children';
13
- export { default as options } from './options';
@@ -1,155 +0,0 @@
1
- import * as preact from './index';
2
-
3
- export enum HookType {
4
- useState = 1,
5
- useReducer = 2,
6
- useEffect = 3,
7
- useLayoutEffect = 4,
8
- useRef = 5,
9
- useImperativeHandle = 6,
10
- useMemo = 7,
11
- useCallback = 8,
12
- useContext = 9,
13
- useErrorBoundary = 10,
14
- // Not a real hook, but the devtools treat is as such
15
- useDebugvalue = 11
16
- }
17
-
18
- export interface DevSource {
19
- fileName: string;
20
- lineNumber: number;
21
- }
22
-
23
- export interface ErrorInfo {
24
- componentStack?: string;
25
- }
26
-
27
- export interface Options extends preact.Options {
28
- /** Attach a hook that is invoked before render, mainly to check the arguments. */
29
- _root?(
30
- vnode: ComponentChild,
31
- parent: Element | Document | ShadowRoot | DocumentFragment
32
- ): void;
33
- /** Attach a hook that is invoked before a vnode is diffed. */
34
- _diff?(vnode: VNode): void;
35
- /** Attach a hook that is invoked after a tree was mounted or was updated. */
36
- _commit?(vnode: VNode, commitQueue: Component[]): void;
37
- /** Attach a hook that is invoked before a vnode has rendered. */
38
- _render?(vnode: VNode): void;
39
- /** Attach a hook that is invoked before a hook's state is queried. */
40
- _hook?(component: Component, index: number, type: HookType): void;
41
- /** Bypass effect execution. Currenty only used in devtools for hooks inspection */
42
- _skipEffects?: boolean;
43
- /** Attach a hook that is invoked after an error is caught in a component but before calling lifecycle hooks */
44
- _catchError(
45
- error: any,
46
- vnode: VNode,
47
- oldVNode: VNode | undefined,
48
- errorInfo: ErrorInfo | undefined
49
- ): void;
50
- }
51
-
52
- export type ComponentChild =
53
- | VNode<any>
54
- | string
55
- | number
56
- | boolean
57
- | null
58
- | undefined;
59
- export type ComponentChildren = ComponentChild[] | ComponentChild;
60
-
61
- export interface FunctionComponent<P = {}> extends preact.FunctionComponent<P> {
62
- // Internally, createContext uses `contextType` on a Function component to
63
- // implement the Consumer component
64
- contextType?: PreactContext;
65
-
66
- // Internally, createContext stores a ref to the context object on the Provider
67
- // Function component to help devtools
68
- _contextRef?: PreactContext;
69
-
70
- // Define these properties as undefined on FunctionComponent to get rid of
71
- // some errors in `diff()`
72
- getDerivedStateFromProps?: undefined;
73
- getDerivedStateFromError?: undefined;
74
- }
75
-
76
- export interface ComponentClass<P = {}> extends preact.ComponentClass<P> {
77
- _contextRef?: any;
78
-
79
- // Override public contextType with internal PreactContext type
80
- contextType?: PreactContext;
81
- }
82
-
83
- // Redefine ComponentType using our new internal FunctionComponent interface above
84
- export type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
85
-
86
- export interface PreactElement extends HTMLElement {
87
- _children?: VNode<any> | null;
88
- /** Event listeners to support event delegation */
89
- _listeners?: Record<string, (e: Event) => void>;
90
-
91
- // Preact uses this attribute to detect SVG nodes
92
- ownerSVGElement?: SVGElement | null;
93
-
94
- // style: HTMLElement["style"]; // From HTMLElement
95
-
96
- data?: string | number; // From Text node
97
- }
98
-
99
- // We use the `current` property to differentiate between the two kinds of Refs so
100
- // internally we'll define `current` on both to make TypeScript happy
101
- type RefObject<T> = { current: T | null };
102
- type RefCallback<T> = { (instance: T | null): void; current: undefined };
103
- type Ref<T> = RefObject<T> | RefCallback<T>;
104
-
105
- export interface VNode<P = {}> extends preact.VNode<P> {
106
- // Redefine type here using our internal ComponentType type
107
- type: string | ComponentType<P>;
108
- props: P & { children: ComponentChildren };
109
- ref?: Ref<any> | null;
110
- _children: Array<VNode<any>> | null;
111
- _parent: VNode | null;
112
- _depth: number | null;
113
- /**
114
- * The [first (for Fragments)] DOM child of a VNode
115
- */
116
- _dom: PreactElement | null;
117
- /**
118
- * The last dom child of a Fragment, or components that return a Fragment
119
- */
120
- _nextDom: PreactElement | null;
121
- _component: Component | null;
122
- _hydrating: boolean | null;
123
- constructor: undefined;
124
- _original: number;
125
- }
126
-
127
- export interface Component<P = {}, S = {}> extends preact.Component<P, S> {
128
- // When component is functional component, this is reset to functional component
129
- constructor: ComponentType<P>;
130
- state: S; // Override Component["state"] to not be readonly for internal use, specifically Hooks
131
- base?: PreactElement;
132
-
133
- _dirty: boolean;
134
- _force?: boolean;
135
- _renderCallbacks: Array<() => void>; // Only class components
136
- _globalContext?: any;
137
- _vnode?: VNode<P> | null;
138
- _nextState?: S | null; // Only class components
139
- /** Only used in the devtools to later dirty check if state has changed */
140
- _prevState?: S | null;
141
- /**
142
- * Pointer to the parent dom node. This is only needed for top-level Fragment
143
- * components or array returns.
144
- */
145
- _parentDom?: PreactElement | null;
146
- // Always read, set only when handling error
147
- _processingException?: Component<any, any> | null;
148
- // Always read, set only when handling error. This is used to indicate at diffTime to set _processingException
149
- _pendingError?: Component<any, any> | null;
150
- }
151
-
152
- export interface PreactContext extends preact.Context<any> {
153
- _id: string;
154
- _defaultValue: any;
155
- }