@simpreact/simpreact 0.0.0-alpha.1f6ee65 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/core/createElement.d.ts +22 -15
  2. package/core/createElement.js +67 -23
  3. package/core/hostAdapter.d.ts +17 -7
  4. package/core/hostAdapter.js +4 -1
  5. package/core/index.d.ts +68 -3
  6. package/core/index.js +6 -3
  7. package/core/internal.d.ts +6 -3
  8. package/core/internal.js +6 -3
  9. package/core/lifecycleEventBus.d.ts +26 -0
  10. package/core/lifecycleEventBus.js +2 -0
  11. package/core/mounting.d.ts +9 -8
  12. package/core/mounting.js +87 -50
  13. package/core/patching.d.ts +6 -4
  14. package/core/patching.js +150 -162
  15. package/core/portal.d.ts +2 -0
  16. package/core/portal.js +9 -0
  17. package/core/ref.d.ts +17 -0
  18. package/core/ref.js +27 -0
  19. package/core/rerender.d.ts +11 -0
  20. package/core/rerender.js +61 -3
  21. package/core/unmounting.d.ts +2 -4
  22. package/core/unmounting.js +26 -27
  23. package/dom/attach-element-to-dom.d.ts +4 -0
  24. package/dom/attach-element-to-dom.js +9 -0
  25. package/dom/domAdapter.d.ts +3 -2
  26. package/dom/domAdapter.js +37 -113
  27. package/dom/events.d.ts +19 -0
  28. package/dom/events.js +129 -0
  29. package/dom/index.d.ts +1733 -1
  30. package/dom/index.js +2 -0
  31. package/dom/namespace.d.ts +2 -0
  32. package/dom/namespace.js +1 -0
  33. package/dom/props/controlled/index.d.ts +7 -0
  34. package/dom/props/controlled/index.js +51 -0
  35. package/dom/props/controlled/input.d.ts +7 -0
  36. package/dom/props/controlled/input.js +80 -0
  37. package/dom/props/controlled/select.d.ts +6 -0
  38. package/dom/props/controlled/select.js +76 -0
  39. package/dom/props/controlled/textarea.d.ts +6 -0
  40. package/dom/props/controlled/textarea.js +61 -0
  41. package/dom/props/dangerInnerHTML.d.ts +7 -0
  42. package/dom/props/dangerInnerHTML.js +24 -0
  43. package/dom/props/index.d.ts +1 -0
  44. package/dom/props/index.js +1 -0
  45. package/dom/props/props.d.ts +5 -0
  46. package/dom/props/props.js +197 -0
  47. package/dom/props/style.d.ts +1 -0
  48. package/dom/props/style.js +32 -0
  49. package/dom/render.d.ts +2 -2
  50. package/dom/render.js +31 -19
  51. package/hooks/index.d.ts +23 -12
  52. package/hooks/index.js +123 -29
  53. package/jsx-runtime/index.d.ts +247 -4
  54. package/jsx-runtime/index.js +2 -5
  55. package/package.json +22 -15
  56. package/shared/index.d.ts +19 -4
  57. package/shared/index.js +5 -4
  58. package/shared/lang.d.ts +3 -3
  59. package/shared/lang.js +3 -3
  60. package/shared/utils.d.ts +3 -2
  61. package/shared/utils.js +3 -6
  62. package/core/global.d.ts +0 -21
  63. package/core/global.js +0 -5
  64. package/shared/types.d.ts +0 -8
  65. package/shared/types.js +0 -1
package/hooks/index.d.ts CHANGED
@@ -1,12 +1,23 @@
1
- import type { SimpContext } from '../core';
2
- import type { VoidFunction } from '../shared';
3
- type Cleanup = VoidFunction;
4
- type Effect = () => void | Cleanup;
5
- type DependencyList = readonly unknown[];
6
- export declare function useRef<T>(initialValue: T): {
7
- current: T;
8
- };
9
- export declare function useRerender(): VoidFunction;
10
- export declare function useEffect(effect: Effect, deps?: DependencyList): void;
11
- export declare function useContext<T>(context: SimpContext<T>): T;
12
- export {};
1
+ import type { RefObject, SimpContext } from '../core';
2
+
3
+ export type Cleanup = () => void;
4
+ export type Effect = () => void | Cleanup;
5
+ export type DependencyList = readonly unknown[];
6
+
7
+ declare function useRef<T>(initialValue: T): RefObject<T>;
8
+ declare function useRef<T>(initialValue: T | null): RefObject<T | null>;
9
+ declare function useRef<T>(initialValue: T | undefined): RefObject<T | undefined>;
10
+
11
+ declare function useRerender(): () => void;
12
+
13
+ declare function useEffect(effect: Effect, deps?: DependencyList): void;
14
+
15
+ declare function useMounted(effect: Effect): void;
16
+
17
+ declare function useUnmounted(cleanup: Cleanup): void;
18
+
19
+ declare function useContext<T>(context: SimpContext<T>): T;
20
+
21
+ declare function useCatch(cb: (error: any) => void): void;
22
+
23
+ declare function areDepsEqual(nextDeps: DependencyList | undefined, prevDeps: DependencyList | undefined): boolean;
package/hooks/index.js CHANGED
@@ -1,61 +1,136 @@
1
- import { GLOBAL, rerender } from '../core/internal';
1
+ import { lifecycleEventBus, rerender, syncRerenderLocker } from '../core/internal.js';
2
+ import { noop } from '../shared';
2
3
  let currentIndex = 0;
3
- let currentElement = null;
4
- GLOBAL.eventBus.subscribe(event => {
4
+ // In runtime this is a nullable variable.
5
+ let currentElement;
6
+ lifecycleEventBus.subscribe(event => {
5
7
  if (event.type === 'beforeRender') {
6
8
  currentElement = event.element;
7
- currentElement.store ||= { hookStates: [], mountEffects: [] };
8
- currentElement.store.mountEffects = [];
9
+ if (currentElement.store?.catchHandlers) {
10
+ currentElement.store.catchHandlers = undefined;
11
+ }
9
12
  }
10
- if (event.type === 'afterRender') {
13
+ if (event.type === 'afterRender' || event.type === 'errored') {
11
14
  currentElement = null;
12
15
  currentIndex = 0;
13
16
  }
14
17
  if (event.type === 'mounted') {
15
- for (const state of event.element.store.mountEffects) {
16
- if (typeof state.cleanup === 'function') {
17
- state.cleanup();
18
+ const element = event.element;
19
+ if (element.store?.effectsHookStates) {
20
+ syncRerenderLocker.lock();
21
+ const effects = element.store.effectsHookStates;
22
+ element.store.effectsHookStates = undefined;
23
+ for (const state of effects) {
24
+ state.cleanup = state.effect() || undefined;
25
+ }
26
+ syncRerenderLocker.flush();
27
+ }
28
+ }
29
+ if (event.type === 'updated') {
30
+ const element = event.element;
31
+ if (element.store?.effectsHookStates) {
32
+ syncRerenderLocker.lock();
33
+ const effects = element.store.effectsHookStates;
34
+ element.store.effectsHookStates = undefined;
35
+ for (const state of effects) {
36
+ if (typeof state.cleanup === 'function') {
37
+ state.cleanup();
38
+ }
39
+ state.cleanup = state.effect() || undefined;
18
40
  }
19
- state.cleanup = state.effect() || undefined;
41
+ syncRerenderLocker.flush();
20
42
  }
21
43
  }
22
44
  if (event.type === 'unmounted') {
23
- for (const state of event.element.store.hookStates) {
24
- if (state && 'cleanup' in state && typeof state.cleanup === 'function') {
25
- state.cleanup();
45
+ const element = event.element;
46
+ if (element.store?.hookStates) {
47
+ for (const state of element.store.hookStates) {
48
+ if (state && 'cleanup' in state && typeof state.cleanup === 'function') {
49
+ state.cleanup();
50
+ }
51
+ }
52
+ }
53
+ }
54
+ if (event.type === 'errored') {
55
+ const element = findElementWithCatchHandlers(event.element);
56
+ if (!element) {
57
+ throw new Error('Error occurred during rendering a component', { cause: event.error });
58
+ }
59
+ if (element.store.catchHandlers) {
60
+ syncRerenderLocker.lock();
61
+ for (const state of element.store.catchHandlers) {
62
+ state(event.error);
26
63
  }
64
+ syncRerenderLocker.flush();
27
65
  }
28
66
  }
29
67
  });
68
+ function findElementWithCatchHandlers(element) {
69
+ let temp = element;
70
+ while (temp != null) {
71
+ if (temp.store?.catchHandlers) {
72
+ return temp;
73
+ }
74
+ temp = temp.parent;
75
+ }
76
+ return null;
77
+ }
30
78
  export function useRef(initialValue) {
31
- return (currentElement.store.hookStates[currentIndex++] ||= { current: initialValue });
79
+ const hookStates = getOrCreateHookStates(currentElement);
80
+ if (!hookStates[currentIndex]) {
81
+ hookStates[currentIndex] = { current: initialValue };
82
+ }
83
+ return hookStates[currentIndex++];
32
84
  }
33
85
  export function useRerender() {
34
- const state = (currentElement.store.hookStates[currentIndex++] ||= {
35
- element: null,
36
- fn() {
37
- rerender(state.element);
38
- },
39
- });
40
- state.element = currentElement;
41
- return state.fn;
86
+ const hookStates = getOrCreateHookStates(currentElement);
87
+ if (!hookStates[currentIndex]) {
88
+ const elementStore = currentElement.store;
89
+ hookStates[currentIndex] = () => rerender(elementStore.latestElement);
90
+ }
91
+ return hookStates[currentIndex++];
42
92
  }
43
93
  export function useEffect(effect, deps) {
44
- const state = (currentElement.store.hookStates[currentIndex++] ||= {
45
- effect,
46
- deps: undefined,
47
- cleanup: undefined,
48
- });
94
+ const hookStates = getOrCreateHookStates(currentElement);
95
+ let state = hookStates[currentIndex];
96
+ if (!state) {
97
+ state = hookStates[currentIndex] = { effect };
98
+ }
49
99
  if (!areDepsEqual(deps, state.deps)) {
50
100
  state.effect = effect;
51
101
  state.deps = deps;
52
- currentElement.store.mountEffects.push(state);
102
+ getOrCreateEffectHookStates(currentElement).push(state);
53
103
  }
104
+ currentIndex++;
105
+ }
106
+ export function useMounted(effect) {
107
+ const hookStates = getOrCreateHookStates(currentElement);
108
+ if (!hookStates[currentIndex]) {
109
+ hookStates[currentIndex] = { effect };
110
+ getOrCreateEffectHookStates(currentElement).push(hookStates[currentIndex]);
111
+ }
112
+ currentIndex++;
113
+ }
114
+ export function useUnmounted(cleanup) {
115
+ const hookStates = getOrCreateHookStates(currentElement);
116
+ if (!hookStates[currentIndex]) {
117
+ hookStates[currentIndex] = { cleanup, effect: noop };
118
+ }
119
+ currentIndex++;
54
120
  }
55
121
  export function useContext(context) {
56
122
  return currentElement.contextMap?.get(context) ?? context.defaultValue;
57
123
  }
58
- function areDepsEqual(nextDeps, prevDeps) {
124
+ export function useCatch(cb) {
125
+ if (!currentElement.store) {
126
+ currentElement.store = {};
127
+ }
128
+ if (!currentElement.store.catchHandlers) {
129
+ currentElement.store.catchHandlers = [];
130
+ }
131
+ currentElement.store.catchHandlers.push(cb);
132
+ }
133
+ export function areDepsEqual(nextDeps, prevDeps) {
59
134
  if (nextDeps == null || prevDeps == null || nextDeps.length !== prevDeps.length) {
60
135
  return false;
61
136
  }
@@ -66,3 +141,22 @@ function areDepsEqual(nextDeps, prevDeps) {
66
141
  }
67
142
  return true;
68
143
  }
144
+ function getOrCreateHookStates(element) {
145
+ if (!element.store) {
146
+ element.store = {};
147
+ }
148
+ if (!element.store.hookStates) {
149
+ element.store.hookStates = [];
150
+ }
151
+ return element.store.hookStates;
152
+ }
153
+ function getOrCreateEffectHookStates(element) {
154
+ if (!element.store) {
155
+ element.store = {};
156
+ }
157
+ if (!element.store.effectsHookStates) {
158
+ element.store.effectsHookStates = [];
159
+ }
160
+ return element.store.effectsHookStates;
161
+ }
162
+ export default { useRef, useRerender, useEffect, useMounted, useUnmounted, useContext, useCatch, areDepsEqual };
@@ -1,7 +1,250 @@
1
- import type { FunctionComponent, SimpElement } from '../core';
2
- import { Fragment } from '../core';
1
+ import type { FC, Fragment as FragmentType, Key, SimpElement } from '../core';
3
2
  import type { Maybe } from '../shared';
4
- import type { Key, Props } from '../core/createElement';
5
- export declare function jsx(type: string | FunctionComponent<any>, props?: Maybe<Props>, key?: Maybe<Key>): SimpElement;
3
+ import type {
4
+ AnchorHTMLAttributes,
5
+ AreaHTMLAttributes,
6
+ AudioHTMLAttributes,
7
+ BaseHTMLAttributes,
8
+ BlockquoteHTMLAttributes,
9
+ ButtonHTMLAttributes,
10
+ CanvasHTMLAttributes,
11
+ ColgroupHTMLAttributes,
12
+ ColHTMLAttributes,
13
+ DataHTMLAttributes,
14
+ DelHTMLAttributes,
15
+ DetailedHTMLProps,
16
+ DetailsHTMLAttributes,
17
+ DialogHTMLAttributes,
18
+ EmbedHTMLAttributes,
19
+ FieldsetHTMLAttributes,
20
+ FormHTMLAttributes,
21
+ HTMLAttributes,
22
+ HtmlHTMLAttributes,
23
+ IframeHTMLAttributes,
24
+ ImgHTMLAttributes,
25
+ InputHTMLAttributes,
26
+ InsHTMLAttributes,
27
+ KeygenHTMLAttributes,
28
+ LabelHTMLAttributes,
29
+ LiHTMLAttributes,
30
+ LinkHTMLAttributes,
31
+ MapHTMLAttributes,
32
+ MenuHTMLAttributes,
33
+ MetaHTMLAttributes,
34
+ MeterHTMLAttributes,
35
+ ObjectHTMLAttributes,
36
+ OlHTMLAttributes,
37
+ OptgroupHTMLAttributes,
38
+ OptionHTMLAttributes,
39
+ OutputHTMLAttributes,
40
+ ParamHTMLAttributes,
41
+ ProgressHTMLAttributes,
42
+ QuoteHTMLAttributes,
43
+ ScriptHTMLAttributes,
44
+ SelectHTMLAttributes,
45
+ SlotHTMLAttributes,
46
+ SourceHTMLAttributes,
47
+ StyleHTMLAttributes,
48
+ SVGProps,
49
+ TableHTMLAttributes,
50
+ TdHTMLAttributes,
51
+ TextareaHTMLAttributes,
52
+ ThHTMLAttributes,
53
+ TimeHTMLAttributes,
54
+ TrackHTMLAttributes,
55
+ VideoHTMLAttributes,
56
+ WebViewHTMLAttributes,
57
+ } from '../dom';
58
+
59
+ declare function jsx<P = {}>(type: string | FC<P>, props?: P, key?: Maybe<Key>): SimpElement<P>;
60
+
61
+ type Fragment = FragmentType;
62
+
6
63
  export { jsx as jsxs, jsx as jsxDEV };
7
64
  export { Fragment };
65
+
66
+ declare global {
67
+ namespace JSX {
68
+ interface IntrinsicElements {
69
+ // HTML
70
+ a: DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
71
+ abbr: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
72
+ address: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
73
+ area: DetailedHTMLProps<AreaHTMLAttributes<HTMLAreaElement>, HTMLAreaElement>;
74
+ article: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
75
+ aside: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
76
+ audio: DetailedHTMLProps<AudioHTMLAttributes<HTMLAudioElement>, HTMLAudioElement>;
77
+ b: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
78
+ base: DetailedHTMLProps<BaseHTMLAttributes<HTMLBaseElement>, HTMLBaseElement>;
79
+ bdi: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
80
+ bdo: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
81
+ big: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
82
+ blockquote: DetailedHTMLProps<BlockquoteHTMLAttributes<HTMLQuoteElement>, HTMLQuoteElement>;
83
+ body: DetailedHTMLProps<HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>;
84
+ br: DetailedHTMLProps<HTMLAttributes<HTMLBRElement>, HTMLBRElement>;
85
+ button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
86
+ canvas: DetailedHTMLProps<CanvasHTMLAttributes<HTMLCanvasElement>, HTMLCanvasElement>;
87
+ caption: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
88
+ center: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
89
+ cite: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
90
+ code: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
91
+ col: DetailedHTMLProps<ColHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>;
92
+ colgroup: DetailedHTMLProps<ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>;
93
+ data: DetailedHTMLProps<DataHTMLAttributes<HTMLDataElement>, HTMLDataElement>;
94
+ datalist: DetailedHTMLProps<HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>;
95
+ dd: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
96
+ del: DetailedHTMLProps<DelHTMLAttributes<HTMLModElement>, HTMLModElement>;
97
+ details: DetailedHTMLProps<DetailsHTMLAttributes<HTMLDetailsElement>, HTMLDetailsElement>;
98
+ dfn: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
99
+ dialog: DetailedHTMLProps<DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>;
100
+ div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
101
+ dl: DetailedHTMLProps<HTMLAttributes<HTMLDListElement>, HTMLDListElement>;
102
+ dt: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
103
+ em: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
104
+ embed: DetailedHTMLProps<EmbedHTMLAttributes<HTMLEmbedElement>, HTMLEmbedElement>;
105
+ fieldset: DetailedHTMLProps<FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>;
106
+ figcaption: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
107
+ figure: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
108
+ footer: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
109
+ form: DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>;
110
+ h1: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
111
+ h2: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
112
+ h3: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
113
+ h4: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
114
+ h5: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
115
+ h6: DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>;
116
+ head: DetailedHTMLProps<HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>;
117
+ header: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
118
+ hgroup: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
119
+ hr: DetailedHTMLProps<HTMLAttributes<HTMLHRElement>, HTMLHRElement>;
120
+ html: DetailedHTMLProps<HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>;
121
+ i: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
122
+ iframe: DetailedHTMLProps<IframeHTMLAttributes<HTMLIFrameElement>, HTMLIFrameElement>;
123
+ img: DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>;
124
+ input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
125
+ ins: DetailedHTMLProps<InsHTMLAttributes<HTMLModElement>, HTMLModElement>;
126
+ kbd: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
127
+ keygen: DetailedHTMLProps<KeygenHTMLAttributes<HTMLElement>, HTMLElement>;
128
+ label: DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>;
129
+ legend: DetailedHTMLProps<HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>;
130
+ li: DetailedHTMLProps<LiHTMLAttributes<HTMLLIElement>, HTMLLIElement>;
131
+ link: DetailedHTMLProps<LinkHTMLAttributes<HTMLLinkElement>, HTMLLinkElement>;
132
+ main: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
133
+ map: DetailedHTMLProps<MapHTMLAttributes<HTMLMapElement>, HTMLMapElement>;
134
+ mark: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
135
+ menu: DetailedHTMLProps<MenuHTMLAttributes<HTMLElement>, HTMLElement>;
136
+ menuitem: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
137
+ meta: DetailedHTMLProps<MetaHTMLAttributes<HTMLMetaElement>, HTMLMetaElement>;
138
+ meter: DetailedHTMLProps<MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>;
139
+ nav: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
140
+ noindex: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
141
+ noscript: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
142
+ object: DetailedHTMLProps<ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>;
143
+ ol: DetailedHTMLProps<OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>;
144
+ optgroup: DetailedHTMLProps<OptgroupHTMLAttributes<HTMLOptGroupElement>, HTMLOptGroupElement>;
145
+ option: DetailedHTMLProps<OptionHTMLAttributes<HTMLOptionElement>, HTMLOptionElement>;
146
+ output: DetailedHTMLProps<OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>;
147
+ p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>;
148
+ param: DetailedHTMLProps<ParamHTMLAttributes<HTMLParamElement>, HTMLParamElement>;
149
+ picture: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
150
+ pre: DetailedHTMLProps<HTMLAttributes<HTMLPreElement>, HTMLPreElement>;
151
+ progress: DetailedHTMLProps<ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>;
152
+ q: DetailedHTMLProps<QuoteHTMLAttributes<HTMLQuoteElement>, HTMLQuoteElement>;
153
+ rp: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
154
+ rt: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
155
+ ruby: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
156
+ s: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
157
+ samp: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
158
+ search: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
159
+ slot: DetailedHTMLProps<SlotHTMLAttributes<HTMLSlotElement>, HTMLSlotElement>;
160
+ script: DetailedHTMLProps<ScriptHTMLAttributes<HTMLScriptElement>, HTMLScriptElement>;
161
+ section: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
162
+ select: DetailedHTMLProps<SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement>;
163
+ small: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
164
+ source: DetailedHTMLProps<SourceHTMLAttributes<HTMLSourceElement>, HTMLSourceElement>;
165
+ span: DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>;
166
+ strong: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
167
+ style: DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>;
168
+ sub: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
169
+ summary: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
170
+ sup: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
171
+ table: DetailedHTMLProps<TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>;
172
+ template: DetailedHTMLProps<HTMLAttributes<HTMLTemplateElement>, HTMLTemplateElement>;
173
+ tbody: DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>;
174
+ td: DetailedHTMLProps<TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>;
175
+ textarea: DetailedHTMLProps<TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>;
176
+ tfoot: DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>;
177
+ th: DetailedHTMLProps<ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>;
178
+ thead: DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>;
179
+ time: DetailedHTMLProps<TimeHTMLAttributes<HTMLTimeElement>, HTMLTimeElement>;
180
+ title: DetailedHTMLProps<HTMLAttributes<HTMLTitleElement>, HTMLTitleElement>;
181
+ tr: DetailedHTMLProps<HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>;
182
+ track: DetailedHTMLProps<TrackHTMLAttributes<HTMLTrackElement>, HTMLTrackElement>;
183
+ u: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
184
+ ul: DetailedHTMLProps<HTMLAttributes<HTMLUListElement>, HTMLUListElement>;
185
+ var: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
186
+ video: DetailedHTMLProps<VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>;
187
+ wbr: DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
188
+ webview: DetailedHTMLProps<WebViewHTMLAttributes<HTMLElement>, HTMLElement>;
189
+
190
+ // SVG
191
+ svg: SVGProps<SVGSVGElement>;
192
+
193
+ circle: SVGProps<SVGCircleElement>;
194
+ clipPath: SVGProps<SVGClipPathElement>;
195
+ defs: SVGProps<SVGDefsElement>;
196
+ desc: SVGProps<SVGDescElement>;
197
+ ellipse: SVGProps<SVGEllipseElement>;
198
+ feBlend: SVGProps<SVGFEBlendElement>;
199
+ feColorMatrix: SVGProps<SVGFEColorMatrixElement>;
200
+ feComponentTransfer: SVGProps<SVGFEComponentTransferElement>;
201
+ feComposite: SVGProps<SVGFECompositeElement>;
202
+ feConvolveMatrix: SVGProps<SVGFEConvolveMatrixElement>;
203
+ feDiffuseLighting: SVGProps<SVGFEDiffuseLightingElement>;
204
+ feDisplacementMap: SVGProps<SVGFEDisplacementMapElement>;
205
+ feDistantLight: SVGProps<SVGFEDistantLightElement>;
206
+ feDropShadow: SVGProps<SVGFEDropShadowElement>;
207
+ feFlood: SVGProps<SVGFEFloodElement>;
208
+ feFuncA: SVGProps<SVGFEFuncAElement>;
209
+ feFuncB: SVGProps<SVGFEFuncBElement>;
210
+ feFuncG: SVGProps<SVGFEFuncGElement>;
211
+ feFuncR: SVGProps<SVGFEFuncRElement>;
212
+ feGaussianBlur: SVGProps<SVGFEGaussianBlurElement>;
213
+ feImage: SVGProps<SVGFEImageElement>;
214
+ feMerge: SVGProps<SVGFEMergeElement>;
215
+ feMergeNode: SVGProps<SVGFEMergeNodeElement>;
216
+ feMorphology: SVGProps<SVGFEMorphologyElement>;
217
+ feOffset: SVGProps<SVGFEOffsetElement>;
218
+ fePointLight: SVGProps<SVGFEPointLightElement>;
219
+ feSpecularLighting: SVGProps<SVGFESpecularLightingElement>;
220
+ feSpotLight: SVGProps<SVGFESpotLightElement>;
221
+ feTile: SVGProps<SVGFETileElement>;
222
+ feTurbulence: SVGProps<SVGFETurbulenceElement>;
223
+ filter: SVGProps<SVGFilterElement>;
224
+ foreignObject: SVGProps<SVGForeignObjectElement>;
225
+ g: SVGProps<SVGGElement>;
226
+ image: SVGProps<SVGImageElement>;
227
+ line: SVGProps<SVGLineElement>;
228
+ linearGradient: SVGProps<SVGLinearGradientElement>;
229
+ marker: SVGProps<SVGMarkerElement>;
230
+ mask: SVGProps<SVGMaskElement>;
231
+ metadata: SVGProps<SVGMetadataElement>;
232
+ mpath: SVGProps<SVGElement>;
233
+ path: SVGProps<SVGPathElement>;
234
+ pattern: SVGProps<SVGPatternElement>;
235
+ polygon: SVGProps<SVGPolygonElement>;
236
+ polyline: SVGProps<SVGPolylineElement>;
237
+ radialGradient: SVGProps<SVGRadialGradientElement>;
238
+ rect: SVGProps<SVGRectElement>;
239
+ set: SVGProps<SVGSetElement>;
240
+ stop: SVGProps<SVGStopElement>;
241
+ switch: SVGProps<SVGSwitchElement>;
242
+ symbol: SVGProps<SVGSymbolElement>;
243
+ text: SVGProps<SVGTextElement>;
244
+ textPath: SVGProps<SVGTextPathElement>;
245
+ tspan: SVGProps<SVGTSpanElement>;
246
+ use: SVGProps<SVGUseElement>;
247
+ view: SVGProps<SVGViewElement>;
248
+ }
249
+ }
250
+ }
@@ -1,9 +1,6 @@
1
- import { createElement, Fragment } from '../core';
1
+ import { createElement, Fragment } from '../core/internal.js';
2
2
  export function jsx(type, props, key) {
3
- let _key;
4
- if (key != null) {
5
- _key = key;
6
- }
3
+ let _key = key;
7
4
  if (props && props.key != null) {
8
5
  _key = props.key;
9
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpreact/simpreact",
3
- "version": "0.0.0-alpha.1f6ee65",
3
+ "version": "0.0.1",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/dPaskhin/simpreact#readme",
6
6
  "main": "./core/index.js",
@@ -8,28 +8,32 @@
8
8
  "types": "./core/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./core/index.d.ts",
12
- "import": "./core/index.js"
11
+ "import": "./core/index.js",
12
+ "types": "./core/index.d.ts"
13
+ },
14
+ "./internal": {
15
+ "import": "./core/internal.js",
16
+ "types": "./core/internal.d.ts"
13
17
  },
14
18
  "./jsx-runtime": {
15
- "types": "./jsx-runtime/index.d.ts",
16
- "import": "./jsx-runtime/index.js"
19
+ "import": "./jsx-runtime/index.js",
20
+ "types": "./jsx-runtime/index.d.ts"
17
21
  },
18
22
  "./jsx-dev-runtime": {
19
- "types": "./jsx-runtime/index.d.ts",
20
- "import": "./jsx-runtime/index.js"
23
+ "import": "./jsx-runtime/index.js",
24
+ "types": "./jsx-runtime/index.d.ts"
21
25
  },
22
26
  "./hooks": {
23
- "types": "./hooks/index.d.ts",
24
- "import": "./hooks/index.js"
27
+ "import": "./hooks/index.js",
28
+ "types": "./hooks/index.d.ts"
25
29
  },
26
30
  "./dom": {
27
- "types": "./dom/index.d.ts",
28
- "import": "./dom/index.js"
31
+ "import": "./dom/index.js",
32
+ "types": "./dom/index.d.ts"
29
33
  },
30
34
  "./shared": {
31
- "types": "./shared/index.d.ts",
32
- "import": "./shared/index.js"
35
+ "import": "./shared/index.js",
36
+ "types": "./shared/index.d.ts"
33
37
  }
34
38
  },
35
39
  "bugs": {
@@ -39,7 +43,10 @@
39
43
  "type": "git",
40
44
  "url": "git+https://github.com/dPaskhin/simpreact.git"
41
45
  },
42
- "type": "module",
46
+ "sideEffects": false,
43
47
  "license": "MIT",
44
- "author": "Dmitrii Paskhin <d.pasxin@gmail.com>"
48
+ "author": "Dmitrii Paskhin <d.pasxin@gmail.com>",
49
+ "dependencies": {
50
+ "csstype": "^3.1.3"
51
+ }
45
52
  }
package/shared/index.d.ts CHANGED
@@ -1,4 +1,19 @@
1
- export * from './EventBus';
2
- export * from './lang';
3
- export * from './types';
4
- export * from './utils';
1
+ export type Nullable<T> = T | null;
2
+
3
+ export type Maybe<T> = Nullable<T> | undefined;
4
+
5
+ export type Many<T> = T[] | T;
6
+
7
+ export type Dict<T = any> = Record<string, T>;
8
+
9
+ export type SimpText = string | number | bigint;
10
+
11
+ type Subscriber<Event> = (event: Event) => boolean | void;
12
+
13
+ declare class EventBus<Event = void> {
14
+ public publish(event: Event): void;
15
+
16
+ public subscribe(subscriber: Subscriber<Event>): () => void;
17
+ }
18
+
19
+ declare function isSimpText(value: unknown): value is SimpText;
package/shared/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export * from './EventBus';
2
- export * from './lang';
3
- export * from './types';
4
- export * from './utils';
1
+ import { EventBus } from './EventBus';
2
+ import { emptyArray, emptyMap, emptyObject } from './lang';
3
+ import { isSimpText, noop } from './utils';
4
+ export { emptyObject, emptyMap, emptyArray, isSimpText, EventBus, noop };
5
+ export default { isSimpText, EMPTY_MAP: emptyMap, EMPTY_ARRAY: emptyArray, EMPTY_OBJECT: emptyObject, EventBus, noop };
package/shared/lang.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const EMPTY_OBJECT: Readonly<{}>;
2
- export declare const EMPTY_ARRAY: readonly never[];
3
- export declare const EMPTY_MAP: Map<any, any>;
1
+ export declare const emptyObject: Readonly<{}>;
2
+ export declare const emptyArray: readonly never[];
3
+ export declare const emptyMap: Map<any, any>;
package/shared/lang.js CHANGED
@@ -1,3 +1,3 @@
1
- export const EMPTY_OBJECT = Object.freeze({});
2
- export const EMPTY_ARRAY = Object.freeze([]);
3
- export const EMPTY_MAP = new Map();
1
+ export const emptyObject = Object.freeze({});
2
+ export const emptyArray = Object.freeze([]);
3
+ export const emptyMap = new Map();
package/shared/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import type { Primitive } from './types';
2
- export declare function isPrimitive(value: unknown): value is Primitive;
1
+ import type { SimpText } from './public';
2
+ export declare function isSimpText(value: unknown): value is SimpText;
3
+ export declare function noop(): void;
package/shared/utils.js CHANGED
@@ -1,7 +1,4 @@
1
- export function isPrimitive(value) {
2
- return (value == null ||
3
- typeof value === 'string' ||
4
- typeof value === 'number' ||
5
- typeof value === 'bigint' ||
6
- typeof value === 'boolean');
1
+ export function isSimpText(value) {
2
+ return typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint';
7
3
  }
4
+ export function noop() { }
package/core/global.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { HostAdapter } from './hostAdapter';
2
- import type { SimpElement } from './createElement';
3
- import { EventBus } from '../shared';
4
- export type LifecycleEvent = {
5
- type: 'beforeRender';
6
- element: SimpElement;
7
- } | {
8
- type: 'afterRender';
9
- } | {
10
- type: 'mounted';
11
- element: SimpElement;
12
- } | {
13
- type: 'unmounted';
14
- element: SimpElement;
15
- };
16
- interface Global {
17
- hostAdapter: HostAdapter;
18
- eventBus: EventBus<LifecycleEvent>;
19
- }
20
- export declare const GLOBAL: Global;
21
- export {};
package/core/global.js DELETED
@@ -1,5 +0,0 @@
1
- import { EventBus } from '../shared';
2
- export const GLOBAL = {
3
- hostAdapter: null,
4
- eventBus: new EventBus(),
5
- };