rask-ui 0.25.0 → 0.25.4
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.
- package/dist/component.d.ts +1 -0
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +5 -4
- package/dist/createContext.d.ts.map +1 -1
- package/dist/createContext.js +1 -4
- package/package.json +2 -2
- package/dist/asyncState.d.ts +0 -16
- package/dist/asyncState.d.ts.map +0 -1
- package/dist/asyncState.js +0 -24
- package/dist/compiler.d.ts +0 -2
- package/dist/compiler.d.ts.map +0 -1
- package/dist/compiler.js +0 -1
- package/dist/context.d.ts +0 -5
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -29
- package/dist/createAsync.d.ts +0 -39
- package/dist/createAsync.d.ts.map +0 -1
- package/dist/createAsync.js +0 -47
- package/dist/createAsync.test.d.ts +0 -2
- package/dist/createAsync.test.d.ts.map +0 -1
- package/dist/createAsync.test.js +0 -110
- package/dist/createMutation.d.ts +0 -43
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -76
- package/dist/createMutation.test.d.ts +0 -2
- package/dist/createMutation.test.d.ts.map +0 -1
- package/dist/createMutation.test.js +0 -168
- package/dist/createQuery.d.ts +0 -42
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -80
- package/dist/createQuery.test.d.ts +0 -2
- package/dist/createQuery.test.d.ts.map +0 -1
- package/dist/createQuery.test.js +0 -156
- package/dist/createRef.d.ts +0 -6
- package/dist/createRef.d.ts.map +0 -1
- package/dist/createRef.js +0 -8
- package/dist/createState.d.ts +0 -26
- package/dist/createState.d.ts.map +0 -1
- package/dist/createState.js +0 -94
- package/dist/createState.test.d.ts +0 -2
- package/dist/createState.test.d.ts.map +0 -1
- package/dist/createState.test.js +0 -111
- package/dist/createView.d.ts +0 -54
- package/dist/createView.d.ts.map +0 -1
- package/dist/createView.js +0 -68
- package/dist/createView.test.d.ts +0 -2
- package/dist/createView.test.d.ts.map +0 -1
- package/dist/createView.test.js +0 -203
- package/dist/error.d.ts +0 -16
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -17
- package/dist/jsx.d.ts +0 -257
- package/dist/observation.test.d.ts +0 -2
- package/dist/observation.test.d.ts.map +0 -1
- package/dist/observation.test.js +0 -150
- package/dist/suspense.d.ts +0 -25
- package/dist/suspense.d.ts.map +0 -1
- package/dist/suspense.js +0 -97
- package/dist/test-setup.d.ts +0 -16
- package/dist/test-setup.d.ts.map +0 -1
- package/dist/test-setup.js +0 -40
- package/dist/test.d.ts +0 -2
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js +0 -24
package/dist/jsx.d.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// JSX type definitions
|
|
2
|
-
// Note: This is JSXInternal, which gets renamed to JSX on export from jsx-runtime
|
|
3
|
-
import type { Ref } from "./state";
|
|
4
|
-
|
|
5
|
-
export namespace JSXInternal {
|
|
6
|
-
export type Element = any;
|
|
7
|
-
|
|
8
|
-
export interface ElementAttributesProperty {
|
|
9
|
-
props: {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ElementChildrenAttribute {
|
|
13
|
-
children: {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IntrinsicAttributes {
|
|
17
|
-
key?: any;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// CSS Properties
|
|
21
|
-
export type CSSProperties = {
|
|
22
|
-
[key: string]: string | number | undefined;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Common HTML Attributes
|
|
26
|
-
export interface HTMLAttributes<T = HTMLElement> {
|
|
27
|
-
ref?: Ref<T> | ((element: T | null) => void);
|
|
28
|
-
id?: string;
|
|
29
|
-
class?: string | Record<string, boolean>;
|
|
30
|
-
style?: string | CSSProperties;
|
|
31
|
-
title?: string;
|
|
32
|
-
role?: string;
|
|
33
|
-
tabIndex?: number;
|
|
34
|
-
|
|
35
|
-
onClick?: (event: MouseEvent) => void;
|
|
36
|
-
onDblClick?: (event: MouseEvent) => void;
|
|
37
|
-
onChange?: (event: Event) => void;
|
|
38
|
-
onInput?: (event: Event) => void;
|
|
39
|
-
onSubmit?: (event: Event) => void;
|
|
40
|
-
onFocus?: (event: FocusEvent) => void;
|
|
41
|
-
onBlur?: (event: FocusEvent) => void;
|
|
42
|
-
onKeyDown?: (event: KeyboardEvent) => void;
|
|
43
|
-
onKeyUp?: (event: KeyboardEvent) => void;
|
|
44
|
-
onKeyPress?: (event: KeyboardEvent) => void;
|
|
45
|
-
onMouseDown?: (event: MouseEvent) => void;
|
|
46
|
-
onMouseUp?: (event: MouseEvent) => void;
|
|
47
|
-
onMouseEnter?: (event: MouseEvent) => void;
|
|
48
|
-
onMouseLeave?: (event: MouseEvent) => void;
|
|
49
|
-
onMouseMove?: (event: MouseEvent) => void;
|
|
50
|
-
onMouseOver?: (event: MouseEvent) => void;
|
|
51
|
-
onMouseOut?: (event: MouseEvent) => void;
|
|
52
|
-
onWheel?: (event: WheelEvent) => void;
|
|
53
|
-
onScroll?: (event: Event) => void;
|
|
54
|
-
onTouchStart?: (event: TouchEvent) => void;
|
|
55
|
-
onTouchEnd?: (event: TouchEvent) => void;
|
|
56
|
-
onTouchMove?: (event: TouchEvent) => void;
|
|
57
|
-
onTouchCancel?: (event: TouchEvent) => void;
|
|
58
|
-
|
|
59
|
-
[key: `aria-${string}`]: string | boolean | number | undefined;
|
|
60
|
-
[key: `data-${string}`]: string | boolean | number | undefined;
|
|
61
|
-
|
|
62
|
-
children?: any;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface AnchorHTMLAttributes<T = HTMLAnchorElement>
|
|
66
|
-
extends HTMLAttributes<T> {
|
|
67
|
-
href?: string;
|
|
68
|
-
target?: "_blank" | "_self" | "_parent" | "_top";
|
|
69
|
-
rel?: string;
|
|
70
|
-
download?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface ButtonHTMLAttributes<T = HTMLButtonElement>
|
|
74
|
-
extends HTMLAttributes<T> {
|
|
75
|
-
type?: "button" | "submit" | "reset";
|
|
76
|
-
disabled?: boolean;
|
|
77
|
-
name?: string;
|
|
78
|
-
value?: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface FormHTMLAttributes<T = HTMLFormElement>
|
|
82
|
-
extends HTMLAttributes<T> {
|
|
83
|
-
action?: string;
|
|
84
|
-
method?: "get" | "post";
|
|
85
|
-
enctype?: string;
|
|
86
|
-
target?: string;
|
|
87
|
-
noValidate?: boolean;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface InputHTMLAttributes<T = HTMLInputElement>
|
|
91
|
-
extends HTMLAttributes<T> {
|
|
92
|
-
type?:
|
|
93
|
-
| "button"
|
|
94
|
-
| "checkbox"
|
|
95
|
-
| "color"
|
|
96
|
-
| "date"
|
|
97
|
-
| "datetime-local"
|
|
98
|
-
| "email"
|
|
99
|
-
| "file"
|
|
100
|
-
| "hidden"
|
|
101
|
-
| "image"
|
|
102
|
-
| "month"
|
|
103
|
-
| "number"
|
|
104
|
-
| "password"
|
|
105
|
-
| "radio"
|
|
106
|
-
| "range"
|
|
107
|
-
| "reset"
|
|
108
|
-
| "search"
|
|
109
|
-
| "submit"
|
|
110
|
-
| "tel"
|
|
111
|
-
| "text"
|
|
112
|
-
| "time"
|
|
113
|
-
| "url"
|
|
114
|
-
| "week";
|
|
115
|
-
value?: string | number;
|
|
116
|
-
defaultValue?: string | number;
|
|
117
|
-
placeholder?: string;
|
|
118
|
-
disabled?: boolean;
|
|
119
|
-
required?: boolean;
|
|
120
|
-
readOnly?: boolean;
|
|
121
|
-
name?: string;
|
|
122
|
-
checked?: boolean;
|
|
123
|
-
defaultChecked?: boolean;
|
|
124
|
-
min?: string | number;
|
|
125
|
-
max?: string | number;
|
|
126
|
-
step?: string | number;
|
|
127
|
-
pattern?: string;
|
|
128
|
-
accept?: string;
|
|
129
|
-
multiple?: boolean;
|
|
130
|
-
autoComplete?: string;
|
|
131
|
-
autoFocus?: boolean;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface LabelHTMLAttributes<T = HTMLLabelElement>
|
|
135
|
-
extends HTMLAttributes<T> {
|
|
136
|
-
htmlFor?: string;
|
|
137
|
-
for?: string;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface SelectHTMLAttributes<T = HTMLSelectElement>
|
|
141
|
-
extends HTMLAttributes<T> {
|
|
142
|
-
value?: string | string[];
|
|
143
|
-
defaultValue?: string | string[];
|
|
144
|
-
disabled?: boolean;
|
|
145
|
-
required?: boolean;
|
|
146
|
-
name?: string;
|
|
147
|
-
multiple?: boolean;
|
|
148
|
-
size?: number;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface OptionHTMLAttributes<T = HTMLOptionElement>
|
|
152
|
-
extends HTMLAttributes<T> {
|
|
153
|
-
value?: string | number;
|
|
154
|
-
selected?: boolean;
|
|
155
|
-
disabled?: boolean;
|
|
156
|
-
label?: string;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface TextareaHTMLAttributes<T = HTMLTextAreaElement>
|
|
160
|
-
extends HTMLAttributes<T> {
|
|
161
|
-
value?: string;
|
|
162
|
-
defaultValue?: string;
|
|
163
|
-
placeholder?: string;
|
|
164
|
-
disabled?: boolean;
|
|
165
|
-
required?: boolean;
|
|
166
|
-
readOnly?: boolean;
|
|
167
|
-
name?: string;
|
|
168
|
-
rows?: number;
|
|
169
|
-
cols?: number;
|
|
170
|
-
maxLength?: number;
|
|
171
|
-
wrap?: "soft" | "hard";
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface FieldsetHTMLAttributes<T = HTMLFieldSetElement>
|
|
175
|
-
extends HTMLAttributes<T> {
|
|
176
|
-
disabled?: boolean;
|
|
177
|
-
name?: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface ImgHTMLAttributes<T = HTMLImageElement>
|
|
181
|
-
extends HTMLAttributes<T> {
|
|
182
|
-
src?: string;
|
|
183
|
-
alt?: string;
|
|
184
|
-
width?: number | string;
|
|
185
|
-
height?: number | string;
|
|
186
|
-
loading?: "eager" | "lazy";
|
|
187
|
-
crossOrigin?: "anonymous" | "use-credentials";
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface SVGAttributes<T = SVGElement> extends HTMLAttributes<T> {
|
|
191
|
-
xmlns?: string;
|
|
192
|
-
viewBox?: string;
|
|
193
|
-
width?: number | string;
|
|
194
|
-
height?: number | string;
|
|
195
|
-
fill?: string;
|
|
196
|
-
stroke?: string;
|
|
197
|
-
strokeWidth?: number | string;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Intrinsic Elements
|
|
201
|
-
export interface IntrinsicElements {
|
|
202
|
-
a: AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
203
|
-
abbr: HTMLAttributes<HTMLElement>;
|
|
204
|
-
address: HTMLAttributes<HTMLElement>;
|
|
205
|
-
article: HTMLAttributes<HTMLElement>;
|
|
206
|
-
aside: HTMLAttributes<HTMLElement>;
|
|
207
|
-
b: HTMLAttributes<HTMLElement>;
|
|
208
|
-
blockquote: HTMLAttributes<HTMLQuoteElement>;
|
|
209
|
-
body: HTMLAttributes<HTMLBodyElement>;
|
|
210
|
-
br: HTMLAttributes<HTMLBRElement>;
|
|
211
|
-
button: ButtonHTMLAttributes<HTMLButtonElement>;
|
|
212
|
-
canvas: HTMLAttributes<HTMLCanvasElement>;
|
|
213
|
-
code: HTMLAttributes<HTMLElement>;
|
|
214
|
-
div: HTMLAttributes<HTMLDivElement>;
|
|
215
|
-
em: HTMLAttributes<HTMLElement>;
|
|
216
|
-
fieldset: FieldsetHTMLAttributes<HTMLFieldSetElement>;
|
|
217
|
-
footer: HTMLAttributes<HTMLElement>;
|
|
218
|
-
form: FormHTMLAttributes<HTMLFormElement>;
|
|
219
|
-
h1: HTMLAttributes<HTMLHeadingElement>;
|
|
220
|
-
h2: HTMLAttributes<HTMLHeadingElement>;
|
|
221
|
-
h3: HTMLAttributes<HTMLHeadingElement>;
|
|
222
|
-
h4: HTMLAttributes<HTMLHeadingElement>;
|
|
223
|
-
h5: HTMLAttributes<HTMLHeadingElement>;
|
|
224
|
-
h6: HTMLAttributes<HTMLHeadingElement>;
|
|
225
|
-
head: HTMLAttributes<HTMLHeadElement>;
|
|
226
|
-
header: HTMLAttributes<HTMLElement>;
|
|
227
|
-
hr: HTMLAttributes<HTMLHRElement>;
|
|
228
|
-
html: HTMLAttributes<HTMLHtmlElement>;
|
|
229
|
-
i: HTMLAttributes<HTMLElement>;
|
|
230
|
-
img: ImgHTMLAttributes<HTMLImageElement>;
|
|
231
|
-
input: InputHTMLAttributes<HTMLInputElement>;
|
|
232
|
-
label: LabelHTMLAttributes<HTMLLabelElement>;
|
|
233
|
-
legend: HTMLAttributes<HTMLLegendElement>;
|
|
234
|
-
li: HTMLAttributes<HTMLLIElement>;
|
|
235
|
-
main: HTMLAttributes<HTMLElement>;
|
|
236
|
-
nav: HTMLAttributes<HTMLElement>;
|
|
237
|
-
ol: HTMLAttributes<HTMLOListElement>;
|
|
238
|
-
option: OptionHTMLAttributes<HTMLOptionElement>;
|
|
239
|
-
p: HTMLAttributes<HTMLParagraphElement>;
|
|
240
|
-
pre: HTMLAttributes<HTMLPreElement>;
|
|
241
|
-
section: HTMLAttributes<HTMLElement>;
|
|
242
|
-
select: SelectHTMLAttributes<HTMLSelectElement>;
|
|
243
|
-
small: HTMLAttributes<HTMLElement>;
|
|
244
|
-
span: HTMLAttributes<HTMLSpanElement>;
|
|
245
|
-
strong: HTMLAttributes<HTMLElement>;
|
|
246
|
-
style: HTMLAttributes<HTMLStyleElement>;
|
|
247
|
-
textarea: TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
248
|
-
ul: HTMLAttributes<HTMLUListElement>;
|
|
249
|
-
|
|
250
|
-
// SVG
|
|
251
|
-
svg: SVGAttributes<SVGSVGElement>;
|
|
252
|
-
circle: SVGAttributes<SVGCircleElement>;
|
|
253
|
-
line: SVGAttributes<SVGLineElement>;
|
|
254
|
-
path: SVGAttributes<SVGPathElement>;
|
|
255
|
-
rect: SVGAttributes<SVGRectElement>;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observation.test.d.ts","sourceRoot":"","sources":["../src/observation.test.ts"],"names":[],"mappings":""}
|
package/dist/observation.test.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { Signal, Observer, getCurrentObserver } from './observation';
|
|
3
|
-
describe('Signal', () => {
|
|
4
|
-
it('should allow subscribing to notifications', () => {
|
|
5
|
-
const signal = new Signal();
|
|
6
|
-
const callback = vi.fn();
|
|
7
|
-
signal.subscribe(callback);
|
|
8
|
-
signal.notify();
|
|
9
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
10
|
-
});
|
|
11
|
-
it('should return a disposer function', () => {
|
|
12
|
-
const signal = new Signal();
|
|
13
|
-
const callback = vi.fn();
|
|
14
|
-
const dispose = signal.subscribe(callback);
|
|
15
|
-
dispose();
|
|
16
|
-
signal.notify();
|
|
17
|
-
expect(callback).not.toHaveBeenCalled();
|
|
18
|
-
});
|
|
19
|
-
it('should handle multiple subscribers', () => {
|
|
20
|
-
const signal = new Signal();
|
|
21
|
-
const callback1 = vi.fn();
|
|
22
|
-
const callback2 = vi.fn();
|
|
23
|
-
signal.subscribe(callback1);
|
|
24
|
-
signal.subscribe(callback2);
|
|
25
|
-
signal.notify();
|
|
26
|
-
expect(callback1).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(callback2).toHaveBeenCalledTimes(1);
|
|
28
|
-
});
|
|
29
|
-
it('should allow unsubscribing individual callbacks', () => {
|
|
30
|
-
const signal = new Signal();
|
|
31
|
-
const callback1 = vi.fn();
|
|
32
|
-
const callback2 = vi.fn();
|
|
33
|
-
const dispose1 = signal.subscribe(callback1);
|
|
34
|
-
signal.subscribe(callback2);
|
|
35
|
-
dispose1();
|
|
36
|
-
signal.notify();
|
|
37
|
-
expect(callback1).not.toHaveBeenCalled();
|
|
38
|
-
expect(callback2).toHaveBeenCalledTimes(1);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('Observer', () => {
|
|
42
|
-
it('should queue notifications in microtasks', async () => {
|
|
43
|
-
let callCount = 0;
|
|
44
|
-
const observer = new Observer(() => {
|
|
45
|
-
callCount++;
|
|
46
|
-
});
|
|
47
|
-
const signal = new Signal();
|
|
48
|
-
const dispose = observer.observe();
|
|
49
|
-
observer.subscribeSignal(signal);
|
|
50
|
-
dispose();
|
|
51
|
-
// Trigger multiple notifications
|
|
52
|
-
signal.notify();
|
|
53
|
-
signal.notify();
|
|
54
|
-
signal.notify();
|
|
55
|
-
// Should not be called synchronously
|
|
56
|
-
expect(callCount).toBe(0);
|
|
57
|
-
// Wait for microtask
|
|
58
|
-
await new Promise((resolve) => queueMicrotask(() => resolve()));
|
|
59
|
-
// Should be called only once due to queuing
|
|
60
|
-
expect(callCount).toBe(1);
|
|
61
|
-
});
|
|
62
|
-
it('should track signals during observation', () => {
|
|
63
|
-
const callback = vi.fn();
|
|
64
|
-
const observer = new Observer(callback);
|
|
65
|
-
const signal = new Signal();
|
|
66
|
-
const dispose = observer.observe();
|
|
67
|
-
observer.subscribeSignal(signal);
|
|
68
|
-
dispose();
|
|
69
|
-
signal.notify();
|
|
70
|
-
return new Promise((resolve) => {
|
|
71
|
-
queueMicrotask(() => {
|
|
72
|
-
expect(callback).toHaveBeenCalledTimes(1);
|
|
73
|
-
resolve(undefined);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
it('should clear signals when observing again', async () => {
|
|
78
|
-
let callCount = 0;
|
|
79
|
-
const observer = new Observer(() => {
|
|
80
|
-
callCount++;
|
|
81
|
-
});
|
|
82
|
-
const signal1 = new Signal();
|
|
83
|
-
const signal2 = new Signal();
|
|
84
|
-
// First observation
|
|
85
|
-
let dispose = observer.observe();
|
|
86
|
-
observer.subscribeSignal(signal1);
|
|
87
|
-
dispose();
|
|
88
|
-
// Second observation - should clear previous signals
|
|
89
|
-
dispose = observer.observe();
|
|
90
|
-
observer.subscribeSignal(signal2);
|
|
91
|
-
dispose();
|
|
92
|
-
// Notify first signal - should not trigger observer
|
|
93
|
-
signal1.notify();
|
|
94
|
-
await new Promise((resolve) => queueMicrotask(() => resolve()));
|
|
95
|
-
expect(callCount).toBe(0);
|
|
96
|
-
// Notify second signal - should trigger observer
|
|
97
|
-
signal2.notify();
|
|
98
|
-
await new Promise((resolve) => queueMicrotask(() => resolve()));
|
|
99
|
-
expect(callCount).toBe(1);
|
|
100
|
-
});
|
|
101
|
-
it('should dispose of all signal subscriptions', async () => {
|
|
102
|
-
const callback = vi.fn();
|
|
103
|
-
const observer = new Observer(callback);
|
|
104
|
-
const signal = new Signal();
|
|
105
|
-
const dispose = observer.observe();
|
|
106
|
-
observer.subscribeSignal(signal);
|
|
107
|
-
dispose();
|
|
108
|
-
observer.dispose();
|
|
109
|
-
signal.notify();
|
|
110
|
-
await new Promise((resolve) => queueMicrotask(() => resolve()));
|
|
111
|
-
expect(callback).not.toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
it('should set current observer during observation', () => {
|
|
114
|
-
const observer = new Observer(() => { });
|
|
115
|
-
expect(getCurrentObserver()).toBeUndefined();
|
|
116
|
-
const dispose = observer.observe();
|
|
117
|
-
expect(getCurrentObserver()).toBe(observer);
|
|
118
|
-
dispose();
|
|
119
|
-
expect(getCurrentObserver()).toBeUndefined();
|
|
120
|
-
});
|
|
121
|
-
it('should handle nested observations with stack', () => {
|
|
122
|
-
const observer1 = new Observer(() => { });
|
|
123
|
-
const observer2 = new Observer(() => { });
|
|
124
|
-
const dispose1 = observer1.observe();
|
|
125
|
-
expect(getCurrentObserver()).toBe(observer1);
|
|
126
|
-
const dispose2 = observer2.observe();
|
|
127
|
-
expect(getCurrentObserver()).toBe(observer2);
|
|
128
|
-
dispose2();
|
|
129
|
-
expect(getCurrentObserver()).toBe(observer1);
|
|
130
|
-
dispose1();
|
|
131
|
-
expect(getCurrentObserver()).toBeUndefined();
|
|
132
|
-
});
|
|
133
|
-
it('should prevent duplicate notifications while queued', async () => {
|
|
134
|
-
let callCount = 0;
|
|
135
|
-
const observer = new Observer(() => {
|
|
136
|
-
callCount++;
|
|
137
|
-
});
|
|
138
|
-
const signal = new Signal();
|
|
139
|
-
const dispose = observer.observe();
|
|
140
|
-
observer.subscribeSignal(signal);
|
|
141
|
-
dispose();
|
|
142
|
-
// Rapid-fire notifications
|
|
143
|
-
for (let i = 0; i < 100; i++) {
|
|
144
|
-
signal.notify();
|
|
145
|
-
}
|
|
146
|
-
await new Promise((resolve) => queueMicrotask(() => resolve()));
|
|
147
|
-
// Should only be called once
|
|
148
|
-
expect(callCount).toBe(1);
|
|
149
|
-
});
|
|
150
|
-
});
|
package/dist/suspense.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { VNode } from "snabbdom";
|
|
2
|
-
export declare function createSuspense<T extends Record<string, Promise<any>>>(promises: T): {
|
|
3
|
-
[K in keyof T]: Awaited<T[K]>;
|
|
4
|
-
};
|
|
5
|
-
export declare function Suspense(props: {
|
|
6
|
-
fallback: VNode;
|
|
7
|
-
children: VNode | VNode[];
|
|
8
|
-
}): () => VNode | VNode[];
|
|
9
|
-
type SuspensePromiseState<T> = {
|
|
10
|
-
status: "pending";
|
|
11
|
-
value: null;
|
|
12
|
-
error: null;
|
|
13
|
-
} | {
|
|
14
|
-
status: "resolved";
|
|
15
|
-
value: T;
|
|
16
|
-
error: null;
|
|
17
|
-
} | {
|
|
18
|
-
status: "rejected";
|
|
19
|
-
value: null;
|
|
20
|
-
error: string;
|
|
21
|
-
};
|
|
22
|
-
export type SuspensePromise<T> = Promise<T> & SuspensePromiseState<T>;
|
|
23
|
-
export declare function createSuspensePromise<T>(promise: Promise<T>): SuspensePromise<T>;
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=suspense.d.ts.map
|
package/dist/suspense.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../src/suspense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAKjC,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EACnE,QAAQ,EAAE,CAAC,GACV;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9B,CAuBA;AAQD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CAC3B,yBAmBA;AAED,KAAK,oBAAoB,CAAC,CAAC,IACvB;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAEtE,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,eAAe,CAAC,CAAC,CAAC,CAgEpB"}
|
package/dist/suspense.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { getCurrentComponent } from "./component";
|
|
2
|
-
import { createState } from "./createState";
|
|
3
|
-
import { getCurrentObserver, Signal } from "./observation";
|
|
4
|
-
export function createSuspense(promises) {
|
|
5
|
-
let currentComponent = getCurrentComponent();
|
|
6
|
-
if (!currentComponent) {
|
|
7
|
-
throw new Error("createSuspense must be used in the setup of a component");
|
|
8
|
-
}
|
|
9
|
-
const proxy = {};
|
|
10
|
-
for (const key in promises) {
|
|
11
|
-
const promise = promises[key];
|
|
12
|
-
const suspensePromise = isSuspensePromise(promise)
|
|
13
|
-
? promise
|
|
14
|
-
: createSuspensePromise(promise);
|
|
15
|
-
currentComponent.notifyAsync(suspensePromise);
|
|
16
|
-
Object.defineProperty(proxy, key, {
|
|
17
|
-
get() {
|
|
18
|
-
return suspensePromise.value;
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return proxy;
|
|
23
|
-
}
|
|
24
|
-
function isSuspensePromise(promise) {
|
|
25
|
-
return "status" in promise;
|
|
26
|
-
}
|
|
27
|
-
export function Suspense(props) {
|
|
28
|
-
const currentComponent = getCurrentComponent();
|
|
29
|
-
const state = createState({
|
|
30
|
-
suspendingPromises: [],
|
|
31
|
-
});
|
|
32
|
-
currentComponent.onAsync((promise) => {
|
|
33
|
-
state.suspendingPromises = state.suspendingPromises.concat(promise);
|
|
34
|
-
});
|
|
35
|
-
return () => {
|
|
36
|
-
const isAllResolved = state.suspendingPromises.every((promise) => promise.status === "resolved");
|
|
37
|
-
console.log(isAllResolved);
|
|
38
|
-
return isAllResolved ? props.children : props.fallback;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function createSuspensePromise(promise) {
|
|
42
|
-
const signal = new Signal();
|
|
43
|
-
const state = {
|
|
44
|
-
error: null,
|
|
45
|
-
status: "pending",
|
|
46
|
-
value: null,
|
|
47
|
-
};
|
|
48
|
-
Object.defineProperty(promise, "value", {
|
|
49
|
-
get() {
|
|
50
|
-
const observer = getCurrentObserver();
|
|
51
|
-
if (observer) {
|
|
52
|
-
observer.subscribeSignal(signal);
|
|
53
|
-
}
|
|
54
|
-
return state.value;
|
|
55
|
-
},
|
|
56
|
-
set(newValue) {
|
|
57
|
-
state.value = newValue;
|
|
58
|
-
signal.notify();
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(promise, "error", {
|
|
62
|
-
get() {
|
|
63
|
-
const observer = getCurrentObserver();
|
|
64
|
-
if (observer) {
|
|
65
|
-
observer.subscribeSignal(signal);
|
|
66
|
-
}
|
|
67
|
-
return state.error;
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(promise, "status", {
|
|
71
|
-
get() {
|
|
72
|
-
const observer = getCurrentObserver();
|
|
73
|
-
if (observer) {
|
|
74
|
-
observer.subscribeSignal(signal);
|
|
75
|
-
}
|
|
76
|
-
return state.status;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
promise
|
|
80
|
-
.then((value) => {
|
|
81
|
-
Object.assign(state, {
|
|
82
|
-
value,
|
|
83
|
-
error: null,
|
|
84
|
-
status: "resolved",
|
|
85
|
-
});
|
|
86
|
-
signal.notify();
|
|
87
|
-
})
|
|
88
|
-
.catch((error) => {
|
|
89
|
-
Object.assign(state, {
|
|
90
|
-
value: null,
|
|
91
|
-
error: String(error),
|
|
92
|
-
status: "rejected",
|
|
93
|
-
});
|
|
94
|
-
signal.notify();
|
|
95
|
-
});
|
|
96
|
-
return promise;
|
|
97
|
-
}
|
package/dist/test-setup.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { VNode } from 'snabbdom';
|
|
2
|
-
/**
|
|
3
|
-
* Test helper to render a component and provide easy cleanup
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const { container, unmount } = renderComponent(<MyComponent />);
|
|
7
|
-
* expect(container.textContent).toBe('hello');
|
|
8
|
-
* unmount();
|
|
9
|
-
*/
|
|
10
|
-
export declare function renderComponent(vnode: VNode): {
|
|
11
|
-
container: HTMLElement;
|
|
12
|
-
vnode: VNode;
|
|
13
|
-
unmount: () => void;
|
|
14
|
-
rerender: (newVnode: VNode) => VNode;
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=test-setup.d.ts.map
|
package/dist/test-setup.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAUtC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK;;;;yBAmBnB,KAAK;EAK7B"}
|
package/dist/test-setup.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Test setup file for vitest
|
|
2
|
-
import { afterEach } from 'vitest';
|
|
3
|
-
import { render, patch } from './render';
|
|
4
|
-
// Clean up after each test
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
document.body.innerHTML = '';
|
|
7
|
-
// Remove any style tags added by render function
|
|
8
|
-
document.querySelectorAll('style').forEach(style => style.remove());
|
|
9
|
-
});
|
|
10
|
-
/**
|
|
11
|
-
* Test helper to render a component and provide easy cleanup
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* const { container, unmount } = renderComponent(<MyComponent />);
|
|
15
|
-
* expect(container.textContent).toBe('hello');
|
|
16
|
-
* unmount();
|
|
17
|
-
*/
|
|
18
|
-
export function renderComponent(vnode) {
|
|
19
|
-
const container = document.createElement('div');
|
|
20
|
-
document.body.appendChild(container);
|
|
21
|
-
let currentVnode = render(vnode, container);
|
|
22
|
-
const actualElement = currentVnode.elm;
|
|
23
|
-
return {
|
|
24
|
-
// The actual rendered DOM element (after patch replaces container)
|
|
25
|
-
container: actualElement,
|
|
26
|
-
// The vnode returned by render
|
|
27
|
-
vnode: currentVnode,
|
|
28
|
-
// Cleanup function
|
|
29
|
-
unmount: () => {
|
|
30
|
-
if (actualElement && actualElement.parentNode) {
|
|
31
|
-
actualElement.parentNode.removeChild(actualElement);
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
// Re-render with new vnode
|
|
35
|
-
rerender: (newVnode) => {
|
|
36
|
-
currentVnode = patch(currentVnode, newVnode);
|
|
37
|
-
return currentVnode;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
package/dist/test.d.ts
DELETED
package/dist/test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAiBA,wBAAgB,IAAI,CAAC,SAAS,EAAE,GAAG,QA4BlC"}
|
package/dist/test.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { init, classModule, propsModule, styleModule, eventListenersModule, h, } from "snabbdom";
|
|
2
|
-
const patch = init([
|
|
3
|
-
// Init patch function with chosen modules
|
|
4
|
-
classModule, // makes it easy to toggle classes
|
|
5
|
-
propsModule, // for setting properties on DOM elements
|
|
6
|
-
styleModule, // handles styling on elements with support for animations
|
|
7
|
-
eventListenersModule, // attaches event listeners
|
|
8
|
-
]);
|
|
9
|
-
export function test(container) {
|
|
10
|
-
const vnode = h("div#container.two.classes", { on: { click: () => console.log("div clicked") } }, [
|
|
11
|
-
h("span", { style: { fontWeight: "bold" } }, "This is bold"),
|
|
12
|
-
" and this is just normal text",
|
|
13
|
-
h("a", { props: { href: "/foo" } }, "I'll take you places!"),
|
|
14
|
-
]);
|
|
15
|
-
// Patch into empty DOM element – this modifies the DOM as a side effect
|
|
16
|
-
patch(container, vnode);
|
|
17
|
-
const newVnode = h("div#container.two.classes", { on: { click: () => console.log("updated div clicked") } }, [
|
|
18
|
-
h("span", { style: { fontWeight: "normal", fontStyle: "italic" } }, "This is now italic type"),
|
|
19
|
-
" and this is still just normal text",
|
|
20
|
-
h("a", { props: { href: "/bar" } }, "I'll take you places!"),
|
|
21
|
-
]);
|
|
22
|
-
// Second `patch` invocation
|
|
23
|
-
patch(vnode, newVnode); // Snabbdom efficiently updates the old view to the new state
|
|
24
|
-
}
|