@b9g/crank 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_utils.d.ts +14 -0
- package/async.cjs +237 -0
- package/async.cjs.map +1 -0
- package/async.d.ts +104 -0
- package/async.js +234 -0
- package/async.js.map +1 -0
- package/crank.cjs +1671 -1311
- package/crank.cjs.map +1 -1
- package/crank.d.ts +229 -248
- package/crank.js +1671 -1312
- package/crank.js.map +1 -1
- package/dom.cjs +350 -230
- package/dom.cjs.map +1 -1
- package/dom.d.ts +5 -5
- package/dom.js +350 -230
- package/dom.js.map +1 -1
- package/event-target.cjs +254 -0
- package/event-target.cjs.map +1 -0
- package/event-target.d.ts +26 -0
- package/event-target.js +249 -0
- package/event-target.js.map +1 -0
- package/html.cjs +7 -23
- package/html.cjs.map +1 -1
- package/html.d.ts +3 -3
- package/html.js +7 -23
- package/html.js.map +1 -1
- package/jsx-runtime.cjs +1 -0
- package/jsx-runtime.cjs.map +1 -1
- package/jsx-runtime.js +1 -0
- package/jsx-runtime.js.map +1 -1
- package/jsx-tag.cjs +3 -2
- package/jsx-tag.cjs.map +1 -1
- package/jsx-tag.js +3 -2
- package/jsx-tag.js.map +1 -1
- package/package.json +17 -1
- package/standalone.cjs +2 -0
- package/standalone.cjs.map +1 -1
- package/standalone.js +2 -1
- package/standalone.js.map +1 -1
- package/umd.js +2268 -1566
- package/umd.js.map +1 -1
package/crank.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CustomEventTarget } from "./event-target.js";
|
|
1
2
|
/**
|
|
2
3
|
* A type which represents all valid values for an element tag.
|
|
3
4
|
*/
|
|
@@ -9,11 +10,41 @@ export type Tag = string | symbol | Component;
|
|
|
9
10
|
* or a component function.
|
|
10
11
|
*/
|
|
11
12
|
export type TagProps<TTag extends Tag> = TTag extends string ? JSX.IntrinsicElements[TTag] : TTag extends Component<infer TProps> ? TProps & JSX.IntrinsicAttributes : Record<string, unknown> & JSX.IntrinsicAttributes;
|
|
12
|
-
|
|
13
|
-
*
|
|
13
|
+
/**
|
|
14
|
+
* Describes all valid values of an element tree, excluding iterables.
|
|
15
|
+
*
|
|
16
|
+
* Arbitrary objects can also be safely rendered, but will be converted to a
|
|
17
|
+
* string using the toString() method. We exclude them from this type to catch
|
|
18
|
+
* potential mistakes.
|
|
19
|
+
*/
|
|
20
|
+
export type Child = Element | string | number | boolean | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* An arbitrarily nested iterable of Child values.
|
|
23
|
+
*
|
|
24
|
+
* We use a recursive interface here rather than making the Children type
|
|
25
|
+
* directly recursive because recursive type aliases were added in TypeScript
|
|
26
|
+
* 3.7.
|
|
27
|
+
*
|
|
28
|
+
* You should avoid referencing this type directly, as it is mainly exported to
|
|
29
|
+
* prevent TypeScript errors.
|
|
30
|
+
*/
|
|
31
|
+
export interface ChildIterable extends Iterable<Child | ChildIterable> {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describes all valid values for an element tree, including arbitrarily nested
|
|
35
|
+
* iterables of such values.
|
|
14
36
|
*
|
|
15
|
-
*
|
|
16
|
-
|
|
37
|
+
* This type can be used to represent the type of the children prop for an
|
|
38
|
+
* element or the return/yield type of a component.
|
|
39
|
+
*/
|
|
40
|
+
export type Children = Child | ChildIterable;
|
|
41
|
+
/**
|
|
42
|
+
* Represents all functions which can be used as a component.
|
|
43
|
+
*
|
|
44
|
+
* @template [TProps=*] - The expected props for the component.
|
|
45
|
+
*/
|
|
46
|
+
export type Component<TProps extends Record<string, unknown> = any> = (this: Context<TProps>, props: TProps, ctx: Context<TProps>) => Children | PromiseLike<Children> | Iterator<Children, Children | void, any> | AsyncIterator<Children, Children | void, any>;
|
|
47
|
+
/*** SPECIAL TAGS ***/
|
|
17
48
|
/**
|
|
18
49
|
* A special tag for grouping multiple children within the same parent.
|
|
19
50
|
*
|
|
@@ -32,64 +63,39 @@ export type Fragment = typeof Fragment;
|
|
|
32
63
|
* This tag is useful for creating element trees with multiple roots, for
|
|
33
64
|
* things like modals or tooltips.
|
|
34
65
|
*
|
|
35
|
-
* Renderer.prototype.render()
|
|
36
|
-
*
|
|
66
|
+
* Renderer.prototype.render() implicitly wraps top-level in a Portal element
|
|
67
|
+
* with the root set to the second argument passed in.
|
|
37
68
|
*/
|
|
38
|
-
export declare const Portal:
|
|
69
|
+
export declare const Portal: Component<{
|
|
70
|
+
root?: object;
|
|
71
|
+
}> & symbol;
|
|
39
72
|
export type Portal = typeof Portal;
|
|
40
73
|
/**
|
|
41
74
|
* A special tag which preserves whatever was previously rendered in the
|
|
42
|
-
* element
|
|
75
|
+
* element's position.
|
|
43
76
|
*
|
|
44
77
|
* Copy elements are useful for when you want to prevent a subtree from
|
|
45
78
|
* rerendering as a performance optimization. Copy elements can also be keyed,
|
|
46
79
|
* in which case the previously rendered keyed element will be copied.
|
|
47
80
|
*/
|
|
48
|
-
export declare const Copy:
|
|
81
|
+
export declare const Copy: Component<{}> & symbol;
|
|
49
82
|
export type Copy = typeof Copy;
|
|
50
83
|
/**
|
|
51
|
-
* A special tag for
|
|
84
|
+
* A special tag for rendering text nodes.
|
|
52
85
|
*
|
|
53
|
-
*
|
|
86
|
+
* Strings in the element tree are implicitly wrapped in a Text element with
|
|
87
|
+
* value set to the string.
|
|
54
88
|
*/
|
|
55
|
-
export declare const
|
|
89
|
+
export declare const Text: Component<{
|
|
90
|
+
value: string;
|
|
91
|
+
}> & symbol;
|
|
92
|
+
export type Text = typeof Text;
|
|
93
|
+
/** A special tag for injecting raw nodes or strings via a value prop. */
|
|
94
|
+
export declare const Raw: Component<{
|
|
95
|
+
value: string | object;
|
|
96
|
+
}> & symbol;
|
|
56
97
|
export type Raw = typeof Raw;
|
|
57
|
-
|
|
58
|
-
* Describes all valid values of an element tree, excluding iterables.
|
|
59
|
-
*
|
|
60
|
-
* Arbitrary objects can also be safely rendered, but will be converted to a
|
|
61
|
-
* string using the toString() method. We exclude them from this type to catch
|
|
62
|
-
* potential mistakes.
|
|
63
|
-
*/
|
|
64
|
-
export type Child = Element | string | number | boolean | null | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* An arbitrarily nested iterable of Child values.
|
|
67
|
-
*
|
|
68
|
-
* We use a recursive interface here rather than making the Children type
|
|
69
|
-
* directly recursive because recursive type aliases were added in TypeScript
|
|
70
|
-
* 3.7.
|
|
71
|
-
*
|
|
72
|
-
* You should avoid referencing this type directly, as it is mainly exported to
|
|
73
|
-
* prevent TypeScript errors.
|
|
74
|
-
*/
|
|
75
|
-
export interface ChildIterable extends Iterable<Child | ChildIterable> {
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Describes all valid values of an element tree, including arbitrarily nested
|
|
79
|
-
* iterables of such values.
|
|
80
|
-
*/
|
|
81
|
-
export type Children = Child | ChildIterable;
|
|
82
|
-
/**
|
|
83
|
-
* Represents all functions which can be used as a component.
|
|
84
|
-
*
|
|
85
|
-
* @template [TProps=*] - The expected props for the component.
|
|
86
|
-
*/
|
|
87
|
-
export type Component<TProps extends Record<string, unknown> = any> = (this: Context<TProps>, props: TProps, ctx: Context<TProps>) => Children | PromiseLike<Children> | Iterator<Children, Children | void, any> | AsyncIterator<Children, Children | void, any>;
|
|
88
|
-
/**
|
|
89
|
-
* A type to keep track of keys. Any value can be a key, though null and
|
|
90
|
-
* undefined are ignored.
|
|
91
|
-
*/
|
|
92
|
-
type Key = unknown;
|
|
98
|
+
type ChildrenIteratorResult = IteratorResult<Children, Children | void>;
|
|
93
99
|
declare const ElementSymbol: unique symbol;
|
|
94
100
|
export interface Element<TTag extends Tag = Tag> {
|
|
95
101
|
/**
|
|
@@ -134,9 +140,6 @@ export interface Element<TTag extends Tag = Tag> {
|
|
|
134
140
|
*/
|
|
135
141
|
export declare class Element<TTag extends Tag = Tag> {
|
|
136
142
|
constructor(tag: TTag, props: TagProps<TTag>);
|
|
137
|
-
get key(): Key;
|
|
138
|
-
get ref(): unknown;
|
|
139
|
-
get copy(): boolean;
|
|
140
143
|
}
|
|
141
144
|
export declare function isElement(value: any): value is Element;
|
|
142
145
|
/**
|
|
@@ -144,7 +147,7 @@ export declare function isElement(value: any): value is Element;
|
|
|
144
147
|
*
|
|
145
148
|
* This function is usually used as a transpilation target for JSX transpilers,
|
|
146
149
|
* but it can also be called directly. It additionally extracts special props so
|
|
147
|
-
* they aren
|
|
150
|
+
* they aren't accessible to renderer methods or components, and assigns the
|
|
148
151
|
* children prop according to any additional arguments passed to the function.
|
|
149
152
|
*/
|
|
150
153
|
export declare function createElement<TTag extends Tag>(tag: TTag, props?: TagProps<TTag> | null | undefined, ...children: Array<unknown>): Element<TTag>;
|
|
@@ -153,155 +156,134 @@ export declare function cloneElement<TTag extends Tag>(el: Element<TTag>): Eleme
|
|
|
153
156
|
/**
|
|
154
157
|
* A helper type which repesents all possible rendered values of an element.
|
|
155
158
|
*
|
|
156
|
-
* @template TNode - The
|
|
159
|
+
* @template TNode - The type of node produced by the associated renderer.
|
|
157
160
|
*
|
|
158
161
|
* When asking the question, what is the "value" of a specific element, the
|
|
159
162
|
* answer varies depending on the tag:
|
|
160
163
|
*
|
|
161
|
-
* For
|
|
162
|
-
* DOM node in the case of the DOMRenderer.
|
|
164
|
+
* For intrinsic elements, the value is the node created for the element, e.g.
|
|
165
|
+
* the DOM node in the case of the DOMRenderer.
|
|
163
166
|
*
|
|
164
|
-
* For
|
|
165
|
-
*
|
|
166
|
-
* For portals, the value is undefined, because a Portal element’s root and
|
|
167
|
+
* For portals, the value is undefined, because a Portal element's root and
|
|
167
168
|
* children are opaque to its parent.
|
|
168
169
|
*
|
|
169
|
-
* For
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* Rendered values can also be strings or arrays of nodes and strings, in the
|
|
173
|
-
* case of component or fragment elements with strings or multiple children.
|
|
174
|
-
*
|
|
175
|
-
* All of these possible values are reflected in this utility type.
|
|
170
|
+
* For component or fragment elements the value can be a node or an array of
|
|
171
|
+
* nodes, depending on how many children they have.
|
|
176
172
|
*/
|
|
177
|
-
export type ElementValue<TNode> = Array<TNode
|
|
173
|
+
export type ElementValue<TNode> = Array<TNode> | TNode | undefined;
|
|
178
174
|
/**
|
|
179
175
|
* @internal
|
|
180
|
-
*
|
|
181
|
-
*
|
|
176
|
+
* Retainers are objects which act as the internal representation of elements,
|
|
177
|
+
* mirroring the element tree.
|
|
182
178
|
*/
|
|
183
|
-
declare class Retainer<TNode> {
|
|
184
|
-
/**
|
|
185
|
-
|
|
186
|
-
*/
|
|
179
|
+
declare class Retainer<TNode, TScope = unknown> {
|
|
180
|
+
/** A bitmask. See RETAINER FLAGS above. */
|
|
181
|
+
f: number;
|
|
187
182
|
el: Element;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* The value associated with this element.
|
|
200
|
-
*/
|
|
201
|
-
value: ElementValue<TNode>;
|
|
202
|
-
/**
|
|
203
|
-
* The cached child values of this element. Only host and component elements
|
|
204
|
-
* will use this property.
|
|
205
|
-
*/
|
|
206
|
-
cachedChildValues: ElementValue<TNode>;
|
|
207
|
-
/**
|
|
208
|
-
* The child which this retainer replaces. This property is used when an
|
|
209
|
-
* async retainer tree replaces previously rendered elements, so that the
|
|
210
|
-
* previously rendered elements can remain visible until the async tree
|
|
211
|
-
* fulfills. Will be set to undefined once this subtree fully renders.
|
|
212
|
-
*/
|
|
213
|
-
fallbackValue: RetainerChild<TNode>;
|
|
214
|
-
inflightValue: Promise<ElementValue<TNode>> | undefined;
|
|
215
|
-
onNextValues: Function | undefined;
|
|
183
|
+
ctx: ContextState<TNode, TScope, any> | undefined;
|
|
184
|
+
children: Array<Retainer<TNode, TScope> | undefined> | Retainer<TNode, TScope> | undefined;
|
|
185
|
+
fallback: Retainer<TNode, TScope> | undefined;
|
|
186
|
+
value: ElementValue<TNode> | undefined;
|
|
187
|
+
scope: TScope | undefined;
|
|
188
|
+
oldProps: Record<string, any> | undefined;
|
|
189
|
+
pendingDiff: Promise<undefined> | undefined;
|
|
190
|
+
onNextDiff: Function | undefined;
|
|
191
|
+
graveyard: Array<Retainer<TNode, TScope>> | undefined;
|
|
192
|
+
lingerers: Array<Set<Retainer<TNode, TScope>> | undefined> | undefined;
|
|
216
193
|
constructor(el: Element);
|
|
217
194
|
}
|
|
218
195
|
/**
|
|
219
|
-
*
|
|
196
|
+
* Interface for adapting the rendering process to a specific target
|
|
197
|
+
* environment. This interface is implemented by Renderer subclasses and passed
|
|
198
|
+
* to the Renderer constructor.
|
|
220
199
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
200
|
+
export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined = TNode, TResult = ElementValue<TNode>> {
|
|
201
|
+
create(data: {
|
|
202
|
+
tag: string | symbol;
|
|
203
|
+
tagName: string;
|
|
204
|
+
props: Record<string, any>;
|
|
205
|
+
scope: TScope | undefined;
|
|
206
|
+
}): TNode;
|
|
207
|
+
adopt(data: {
|
|
208
|
+
tag: string | symbol;
|
|
209
|
+
tagName: string;
|
|
210
|
+
props: Record<string, any>;
|
|
211
|
+
node: TNode | undefined;
|
|
212
|
+
scope: TScope | undefined;
|
|
213
|
+
}): Array<TNode> | undefined;
|
|
214
|
+
text(data: {
|
|
215
|
+
value: string;
|
|
216
|
+
scope: TScope | undefined;
|
|
217
|
+
oldNode: TNode | undefined;
|
|
218
|
+
hydrationNodes: Array<TNode> | undefined;
|
|
219
|
+
}): TNode;
|
|
220
|
+
scope(data: {
|
|
221
|
+
tag: string | symbol;
|
|
222
|
+
tagName: string;
|
|
223
|
+
props: Record<string, any>;
|
|
224
|
+
scope: TScope | undefined;
|
|
225
|
+
}): TScope | undefined;
|
|
226
|
+
raw(data: {
|
|
227
|
+
value: string | TNode;
|
|
228
|
+
scope: TScope | undefined;
|
|
229
|
+
hydrationNodes: Array<TNode> | undefined;
|
|
230
|
+
}): ElementValue<TNode>;
|
|
231
|
+
patch(data: {
|
|
232
|
+
tag: string | symbol;
|
|
233
|
+
tagName: string;
|
|
234
|
+
node: TNode;
|
|
235
|
+
props: Record<string, any>;
|
|
236
|
+
oldProps: Record<string, any> | undefined;
|
|
237
|
+
scope: TScope | undefined;
|
|
238
|
+
copyProps: Set<string> | undefined;
|
|
239
|
+
isHydrating: boolean;
|
|
240
|
+
quietProps: Set<string> | undefined;
|
|
241
|
+
}): void;
|
|
242
|
+
arrange(data: {
|
|
243
|
+
tag: string | symbol;
|
|
244
|
+
tagName: string;
|
|
245
|
+
node: TNode;
|
|
246
|
+
props: Record<string, any>;
|
|
247
|
+
children: Array<TNode>;
|
|
248
|
+
oldProps: Record<string, any> | undefined;
|
|
249
|
+
}): void;
|
|
250
|
+
remove(data: {
|
|
251
|
+
node: TNode;
|
|
252
|
+
parentNode: TNode;
|
|
253
|
+
isNested: boolean;
|
|
254
|
+
}): void;
|
|
245
255
|
read(value: ElementValue<TNode>): TResult;
|
|
246
|
-
|
|
247
|
-
* Called for each string in an element tree.
|
|
248
|
-
*
|
|
249
|
-
* @param text - The string child.
|
|
250
|
-
* @param scope - The current scope.
|
|
251
|
-
*
|
|
252
|
-
* @returns A string to be passed to arrange.
|
|
253
|
-
*
|
|
254
|
-
* Rather than returning Text nodes as we would in the DOM case, for example,
|
|
255
|
-
* we delay that step for Renderer.prototype.arrange. We do this so that
|
|
256
|
-
* adjacent strings can be concatenated, and the actual element tree can be
|
|
257
|
-
* rendered in normalized form.
|
|
258
|
-
*/
|
|
259
|
-
text(text: string, scope: TScope | undefined, hydration: HydrationData<TNode> | undefined): string;
|
|
260
|
-
/**
|
|
261
|
-
* Called for each Raw element whose value prop is a string.
|
|
262
|
-
*
|
|
263
|
-
* @param text - The string child.
|
|
264
|
-
* @param scope - The current scope.
|
|
265
|
-
*
|
|
266
|
-
* @returns The parsed node or string.
|
|
267
|
-
*/
|
|
268
|
-
raw(value: string | TNode, scope: TScope | undefined, hydration: HydrationData<TNode> | undefined): ElementValue<TNode>;
|
|
269
|
-
patch<TTag extends string | symbol, TName extends string>(tag: TTag, node: TNode, name: TName, value: unknown, oldValue: unknown, scope: TScope): unknown;
|
|
270
|
-
arrange<TTag extends string | symbol>(tag: TTag, node: TNode, props: Record<string, unknown>, children: Array<TNode | string>, oldProps: Record<string, unknown> | undefined, oldChildren: Array<TNode | string> | undefined): unknown;
|
|
271
|
-
dispose<TTag extends string | symbol>(tag: TTag, node: TNode, props: Record<string, unknown>): unknown;
|
|
272
|
-
flush(root: TRoot): unknown;
|
|
256
|
+
finalize(root: TRoot): void;
|
|
273
257
|
}
|
|
274
|
-
declare const _RendererImpl: unique symbol;
|
|
275
258
|
/**
|
|
276
259
|
* An abstract class which is subclassed to render to different target
|
|
277
|
-
* environments. Subclasses
|
|
278
|
-
*
|
|
279
|
-
*
|
|
260
|
+
* environments. Subclasses call super() with a custom RenderAdapter object.
|
|
261
|
+
* This class is responsible for kicking off the rendering process and caching
|
|
262
|
+
* previous trees by root.
|
|
280
263
|
*
|
|
281
264
|
* @template TNode - The type of the node for a rendering environment.
|
|
282
265
|
* @template TScope - Data which is passed down the tree.
|
|
283
266
|
* @template TRoot - The type of the root for a rendering environment.
|
|
284
267
|
* @template TResult - The type of exposed values.
|
|
285
268
|
*/
|
|
286
|
-
export declare class Renderer<TNode extends object
|
|
269
|
+
export declare class Renderer<TNode extends object, TScope, TRoot extends TNode | undefined = TNode, TResult = ElementValue<TNode>> {
|
|
287
270
|
/**
|
|
288
271
|
* @internal
|
|
289
272
|
* A weakmap which stores element trees by root.
|
|
290
273
|
*/
|
|
291
|
-
cache: WeakMap<object, Retainer<TNode>>;
|
|
292
|
-
|
|
293
|
-
constructor(
|
|
274
|
+
cache: WeakMap<object, Retainer<TNode, TScope>>;
|
|
275
|
+
adapter: RenderAdapter<TNode, TScope, TRoot, TResult>;
|
|
276
|
+
constructor(adapter: Partial<RenderAdapter<TNode, TScope, TRoot, TResult>>);
|
|
294
277
|
/**
|
|
295
278
|
* Renders an element tree into a specific root.
|
|
296
279
|
*
|
|
297
|
-
* @param children - An element tree.
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* the same or an error will be thrown.
|
|
280
|
+
* @param children - An element tree. Rendering null deletes cached renders.
|
|
281
|
+
* @param root - The root to be rendered into. The renderer caches renders
|
|
282
|
+
* per root.
|
|
283
|
+
* @param bridge - An optional context that will be the ancestor context of
|
|
284
|
+
* all elements in the tree. Useful for connecting different renderers so
|
|
285
|
+
* that events/provisions/errors properly propagate. The context for a given
|
|
286
|
+
* root must be the same between renders.
|
|
305
287
|
*
|
|
306
288
|
* @returns The result of rendering the children, or a possible promise of
|
|
307
289
|
* the result if the element tree renders asynchronously.
|
|
@@ -309,65 +291,65 @@ export declare class Renderer<TNode extends object = object, TScope = unknown, T
|
|
|
309
291
|
render(children: Children, root?: TRoot | undefined, bridge?: Context | undefined): Promise<TResult> | TResult;
|
|
310
292
|
hydrate(children: Children, root: TRoot, bridge?: Context | undefined): Promise<TResult> | TResult;
|
|
311
293
|
}
|
|
312
|
-
|
|
294
|
+
interface PullController {
|
|
295
|
+
iterationP: Promise<ChildrenIteratorResult> | undefined;
|
|
296
|
+
diff: Promise<undefined> | undefined;
|
|
297
|
+
onChildError: ((err: unknown) => void) | undefined;
|
|
313
298
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
*/
|
|
318
|
-
export interface ProvisionMap extends Crank.ProvisionMap {
|
|
299
|
+
interface ScheduleController {
|
|
300
|
+
promise: Promise<unknown>;
|
|
301
|
+
onAbort: () => void;
|
|
319
302
|
}
|
|
320
303
|
/**
|
|
321
304
|
* @internal
|
|
322
305
|
* The internal class which holds context data.
|
|
323
306
|
*/
|
|
324
|
-
declare class
|
|
325
|
-
/**
|
|
326
|
-
|
|
327
|
-
/** The actual context associated with this impl. */
|
|
328
|
-
owner: Context<unknown, TResult>;
|
|
329
|
-
/**
|
|
330
|
-
* The renderer which created this context.
|
|
331
|
-
*/
|
|
332
|
-
renderer: RendererImpl<TNode, TScope, TRoot, TResult>;
|
|
307
|
+
declare class ContextState<TNode = unknown, TScope = unknown, TRoot extends TNode | undefined = TNode | undefined, TResult = unknown> {
|
|
308
|
+
/** The adapter of the renderer which created this context. */
|
|
309
|
+
adapter: RenderAdapter<TNode, TScope, TRoot, TResult>;
|
|
333
310
|
/** The root node as set by the nearest ancestor portal. */
|
|
334
311
|
root: TRoot | undefined;
|
|
335
312
|
/**
|
|
336
313
|
* The nearest ancestor host or portal retainer.
|
|
337
314
|
*
|
|
338
315
|
* When refresh is called, the host element will be arranged as the last step
|
|
339
|
-
* of the commit, to make sure the parent
|
|
340
|
-
* components
|
|
316
|
+
* of the commit, to make sure the parent's children properly reflects the
|
|
317
|
+
* components's childrenk
|
|
341
318
|
*/
|
|
342
319
|
host: Retainer<TNode>;
|
|
343
|
-
/** The parent context
|
|
344
|
-
parent:
|
|
345
|
-
/** The
|
|
320
|
+
/** The parent context state. */
|
|
321
|
+
parent: ContextState | undefined;
|
|
322
|
+
/** The actual context associated with this state. */
|
|
323
|
+
ctx: Context<unknown, TResult>;
|
|
324
|
+
/** The value of the scope at the point of element's creation. */
|
|
346
325
|
scope: TScope | undefined;
|
|
347
326
|
/** The internal node associated with this context. */
|
|
348
327
|
ret: Retainer<TNode>;
|
|
349
328
|
/**
|
|
350
|
-
*
|
|
329
|
+
* Any iterator returned by a component function.
|
|
351
330
|
*
|
|
352
331
|
* Existence of this property implies that the component is a generator
|
|
353
332
|
* component. It is deleted when a component is returned.
|
|
354
333
|
*/
|
|
355
334
|
iterator: Iterator<Children, Children | void, unknown> | AsyncIterator<Children, Children | void, unknown> | undefined;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
335
|
+
inflight: [Promise<undefined>, Promise<undefined>] | undefined;
|
|
336
|
+
enqueued: [Promise<undefined>, Promise<undefined>] | undefined;
|
|
337
|
+
pull: PullController | undefined;
|
|
338
|
+
onPropsProvided: ((props: unknown) => unknown) | undefined;
|
|
339
|
+
onPropsRequested: (() => unknown) | undefined;
|
|
340
|
+
index: number;
|
|
341
|
+
schedule: ScheduleController | undefined;
|
|
342
|
+
constructor(adapter: RenderAdapter<TNode, TScope, TRoot, TResult>, root: TRoot, host: Retainer<TNode>, parent: ContextState | undefined, scope: TScope | undefined, ret: Retainer<TNode>);
|
|
363
343
|
}
|
|
364
|
-
|
|
365
|
-
type
|
|
344
|
+
export type ComponentProps<T> = T extends () => unknown ? {} : T extends (props: infer U) => unknown ? U : never;
|
|
345
|
+
export type ComponentPropsOrProps<T> = T extends Function ? ComponentProps<T> : T;
|
|
346
|
+
declare const _ContextState: unique symbol;
|
|
366
347
|
/**
|
|
367
348
|
* A class which is instantiated and passed to every component as its this
|
|
368
|
-
* value. Contexts form a tree just like elements and all
|
|
369
|
-
* element tree are connected via contexts. Components can
|
|
370
|
-
* communicate data upwards via events and downwards via
|
|
349
|
+
* value/second parameter. Contexts form a tree just like elements and all
|
|
350
|
+
* components in the element tree are connected via contexts. Components can
|
|
351
|
+
* use this tree to communicate data upwards via events and downwards via
|
|
352
|
+
* provisions.
|
|
371
353
|
*
|
|
372
354
|
* @template [T=*] - The expected shape of the props passed to the component,
|
|
373
355
|
* or a component function. Used to strongly type the Context iterator methods.
|
|
@@ -375,74 +357,86 @@ type ComponentProps<T> = T extends () => any ? {} : T extends (props: infer U) =
|
|
|
375
357
|
* places such as the return value of refresh and the argument passed to
|
|
376
358
|
* schedule and cleanup callbacks.
|
|
377
359
|
*/
|
|
378
|
-
export declare class Context<T = any, TResult = any>
|
|
360
|
+
export declare class Context<T = any, TResult = any> extends CustomEventTarget<Context> {
|
|
379
361
|
/**
|
|
380
362
|
* @internal
|
|
363
|
+
* DO NOT USE READ THIS PROPERTY.
|
|
381
364
|
*/
|
|
382
|
-
[
|
|
383
|
-
constructor(
|
|
365
|
+
[_ContextState]: ContextState<unknown, unknown, unknown, TResult>;
|
|
366
|
+
constructor(state: ContextState<unknown, unknown, unknown, TResult>);
|
|
384
367
|
/**
|
|
385
368
|
* The current props of the associated element.
|
|
386
369
|
*/
|
|
387
|
-
get props():
|
|
370
|
+
get props(): ComponentPropsOrProps<T>;
|
|
388
371
|
/**
|
|
389
372
|
* The current value of the associated element.
|
|
390
373
|
*
|
|
391
374
|
* @deprecated
|
|
392
375
|
*/
|
|
393
376
|
get value(): TResult;
|
|
394
|
-
|
|
395
|
-
|
|
377
|
+
get isExecuting(): boolean;
|
|
378
|
+
get isUnmounted(): boolean;
|
|
379
|
+
[Symbol.iterator](): Generator<ComponentPropsOrProps<T>, undefined>;
|
|
380
|
+
[Symbol.asyncIterator](): AsyncGenerator<ComponentPropsOrProps<T>, undefined>;
|
|
396
381
|
/**
|
|
397
382
|
* Re-executes a component.
|
|
398
383
|
*
|
|
399
|
-
* @
|
|
384
|
+
* @param callback - Optional callback to execute before refresh
|
|
385
|
+
* @returns The rendered result of the component or a promise thereof if the
|
|
400
386
|
* component or its children execute asynchronously.
|
|
401
|
-
*
|
|
402
|
-
* The refresh method works a little differently for async generator
|
|
403
|
-
* components, in that it will resume the Context’s props async iterator
|
|
404
|
-
* rather than resuming execution. This is because async generator components
|
|
405
|
-
* are perpetually resumed independent of updates, and rely on the props
|
|
406
|
-
* async iterator to suspend.
|
|
407
387
|
*/
|
|
408
|
-
refresh(): Promise<TResult> | TResult;
|
|
388
|
+
refresh(callback?: () => unknown): Promise<TResult> | TResult;
|
|
409
389
|
/**
|
|
410
|
-
* Registers a callback which fires when the component
|
|
411
|
-
* fire once per callback and update.
|
|
390
|
+
* Registers a callback which fires when the component's children are
|
|
391
|
+
* created. Will only fire once per callback and update.
|
|
412
392
|
*/
|
|
393
|
+
schedule(): Promise<TResult>;
|
|
413
394
|
schedule(callback: (value: TResult) => unknown): void;
|
|
414
395
|
/**
|
|
415
|
-
* Registers a callback which fires when the component
|
|
416
|
-
* rendered
|
|
396
|
+
* Registers a callback which fires when the component's children are fully
|
|
397
|
+
* rendered. Will only fire once per callback and update.
|
|
398
|
+
*/
|
|
399
|
+
after(): Promise<TResult>;
|
|
400
|
+
after(callback: (value: TResult) => unknown): void;
|
|
401
|
+
/**
|
|
402
|
+
* @deprecated the flush() method has been renamed to after().
|
|
417
403
|
*/
|
|
404
|
+
flush(): Promise<TResult>;
|
|
418
405
|
flush(callback: (value: TResult) => unknown): void;
|
|
419
406
|
/**
|
|
420
|
-
* Registers a callback which fires when the component unmounts.
|
|
421
|
-
*
|
|
407
|
+
* Registers a callback which fires when the component unmounts.
|
|
408
|
+
*
|
|
409
|
+
* The callback can be async to defer the unmounting of a component's children.
|
|
422
410
|
*/
|
|
411
|
+
cleanup(): Promise<TResult>;
|
|
423
412
|
cleanup(callback: (value: TResult) => unknown): void;
|
|
424
413
|
consume<TKey extends keyof ProvisionMap>(key: TKey): ProvisionMap[TKey];
|
|
425
414
|
consume(key: unknown): any;
|
|
426
415
|
provide<TKey extends keyof ProvisionMap>(key: TKey, value: ProvisionMap[TKey]): void;
|
|
427
416
|
provide(key: unknown, value: any): void;
|
|
428
|
-
|
|
429
|
-
removeEventListener<T extends string>(type: T, listener: MappedEventListenerOrEventListenerObject<T> | null, options?: EventListenerOptions | boolean): void;
|
|
430
|
-
dispatchEvent(ev: Event): boolean;
|
|
417
|
+
[CustomEventTarget.dispatchEventOnSelf](ev: Event): void;
|
|
431
418
|
}
|
|
432
419
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
420
|
+
* An interface which can be extended to provide strongly typed provisions.
|
|
421
|
+
* See Context.prototype.consume and Context.prototype.provide.
|
|
435
422
|
*/
|
|
423
|
+
export interface ProvisionMap extends Crank.ProvisionMap {
|
|
424
|
+
}
|
|
436
425
|
export interface EventMap extends Crank.EventMap {
|
|
437
|
-
[type: string]: Event;
|
|
438
426
|
}
|
|
439
|
-
type MappedEventListener<T extends string> = (ev: EventMap[T]) => unknown;
|
|
427
|
+
type MappedEventListener<T extends string> = (ev: Crank.EventMap[T]) => unknown;
|
|
440
428
|
type MappedEventListenerOrEventListenerObject<T extends string> = MappedEventListener<T> | {
|
|
441
429
|
handleEvent: MappedEventListener<T>;
|
|
442
430
|
};
|
|
431
|
+
export interface Context extends Crank.Context {
|
|
432
|
+
addEventListener<T extends string>(type: T, listener: MappedEventListenerOrEventListenerObject<T> | null, options?: boolean | AddEventListenerOptions): void;
|
|
433
|
+
removeEventListener<T extends string>(type: T, listener: MappedEventListenerOrEventListenerObject<T> | null, options?: EventListenerOptions | boolean): void;
|
|
434
|
+
dispatchEvent<T extends string>(ev: EventMap[T] | Event): boolean;
|
|
435
|
+
}
|
|
443
436
|
declare global {
|
|
444
437
|
namespace Crank {
|
|
445
438
|
interface EventMap {
|
|
439
|
+
[tag: string]: Event;
|
|
446
440
|
}
|
|
447
441
|
interface ProvisionMap {
|
|
448
442
|
}
|
|
@@ -458,32 +452,19 @@ declare global {
|
|
|
458
452
|
key?: unknown;
|
|
459
453
|
ref?: unknown;
|
|
460
454
|
copy?: unknown;
|
|
461
|
-
|
|
462
|
-
["static"]?: unknown;
|
|
463
|
-
/** @deprecated */
|
|
464
|
-
["crank-key"]?: unknown;
|
|
465
|
-
/** @deprecated */
|
|
466
|
-
["crank-ref"]?: unknown;
|
|
467
|
-
/** @deprecated */
|
|
468
|
-
["crank-static"]?: unknown;
|
|
469
|
-
/** @deprecated */
|
|
470
|
-
["c-key"]?: unknown;
|
|
471
|
-
/** @deprecated */
|
|
472
|
-
["c-ref"]?: unknown;
|
|
473
|
-
/** @deprecated */
|
|
474
|
-
["c-static"]?: unknown;
|
|
475
|
-
/** @deprecated */
|
|
476
|
-
$key?: unknown;
|
|
477
|
-
/** @deprecated */
|
|
478
|
-
$ref?: unknown;
|
|
479
|
-
/** @deprecated */
|
|
480
|
-
$static?: unknown;
|
|
455
|
+
hydrate?: unknown;
|
|
481
456
|
}
|
|
482
457
|
interface ElementChildrenAttribute {
|
|
483
458
|
children: {};
|
|
484
459
|
}
|
|
485
460
|
}
|
|
486
461
|
}
|
|
462
|
+
/**
|
|
463
|
+
* A re-export of some Crank exports as the default export.
|
|
464
|
+
*
|
|
465
|
+
* Some JSX tools expect things like createElement/Fragment to be defined on
|
|
466
|
+
* the default export. Prefer using the named exports directly.
|
|
467
|
+
*/
|
|
487
468
|
declare const _default: {
|
|
488
469
|
createElement: typeof createElement;
|
|
489
470
|
Fragment: string;
|