@b9g/crank 0.5.0-debug.0 → 0.5.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.
- package/README.md +6 -17
- package/crank.cjs +682 -392
- package/crank.cjs.map +1 -1
- package/crank.d.ts +57 -77
- package/crank.js +681 -391
- package/crank.js.map +1 -1
- package/dom.cjs +103 -27
- package/dom.cjs.map +1 -1
- package/dom.d.ts +1 -0
- package/dom.js +103 -25
- package/dom.js.map +1 -1
- package/html.cjs +1 -3
- package/html.cjs.map +1 -1
- package/html.d.ts +2 -1
- package/html.js +1 -1
- package/html.js.map +1 -1
- package/jsx-runtime.cjs +18 -0
- package/jsx-runtime.cjs.map +1 -0
- package/jsx-runtime.d.ts +5 -0
- package/jsx-runtime.js +15 -0
- package/jsx-runtime.js.map +1 -0
- package/{xm.cjs → jsx-tag.cjs} +8 -10
- package/jsx-tag.cjs.map +1 -0
- package/jsx-tag.d.ts +2 -0
- package/{xm.js → jsx-tag.js} +9 -9
- package/jsx-tag.js.map +1 -0
- package/package.json +41 -33
- package/{mod.cjs → standalone.cjs} +3 -5
- package/standalone.cjs.map +1 -0
- package/standalone.d.ts +2 -0
- package/{mod.js → standalone.js} +3 -3
- package/standalone.js.map +1 -0
- package/umd.js +787 -421
- package/umd.js.map +1 -1
- package/mod.cjs.map +0 -1
- package/mod.d.ts +0 -2
- package/mod.js.map +0 -1
- package/xm.cjs.map +0 -1
- package/xm.d.ts +0 -2
- package/xm.js.map +0 -1
package/crank.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A type which represents all valid values for an element tag.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type Tag = string | symbol | Component;
|
|
5
5
|
/**
|
|
6
6
|
* A helper type to map the tag of an element to its expected props.
|
|
7
7
|
*
|
|
8
8
|
* @template TTag - The tag associated with the props. Can be a string, symbol
|
|
9
9
|
* or a component function.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type TagProps<TTag extends Tag> = TTag extends string ? JSX.IntrinsicElements[TTag] : TTag extends Component<infer TProps> ? TProps : Record<string, unknown>;
|
|
12
12
|
/***
|
|
13
13
|
* SPECIAL TAGS
|
|
14
14
|
*
|
|
@@ -25,7 +25,7 @@ export declare type TagProps<TTag extends Tag> = TTag extends string ? JSX.Intri
|
|
|
25
25
|
* reference this export.
|
|
26
26
|
*/
|
|
27
27
|
export declare const Fragment = "";
|
|
28
|
-
export
|
|
28
|
+
export type Fragment = typeof Fragment;
|
|
29
29
|
/**
|
|
30
30
|
* A special tag for rendering into a new root node via a root prop.
|
|
31
31
|
*
|
|
@@ -36,7 +36,7 @@ export declare type Fragment = typeof Fragment;
|
|
|
36
36
|
* a Portal element.
|
|
37
37
|
*/
|
|
38
38
|
export declare const Portal: any;
|
|
39
|
-
export
|
|
39
|
+
export type Portal = typeof Portal;
|
|
40
40
|
/**
|
|
41
41
|
* A special tag which preserves whatever was previously rendered in the
|
|
42
42
|
* element’s position.
|
|
@@ -46,15 +46,14 @@ export declare type Portal = typeof Portal;
|
|
|
46
46
|
* in which case the previously rendered keyed element will be copied.
|
|
47
47
|
*/
|
|
48
48
|
export declare const Copy: any;
|
|
49
|
-
export
|
|
49
|
+
export type Copy = typeof Copy;
|
|
50
50
|
/**
|
|
51
51
|
* A special tag for injecting raw nodes or strings via a value prop.
|
|
52
52
|
*
|
|
53
|
-
*
|
|
54
|
-
* the string and the result will be set as the element’s value.
|
|
53
|
+
* Renderer.prototype.raw() is called with the value prop.
|
|
55
54
|
*/
|
|
56
55
|
export declare const Raw: any;
|
|
57
|
-
export
|
|
56
|
+
export type Raw = typeof Raw;
|
|
58
57
|
/**
|
|
59
58
|
* Describes all valid values of an element tree, excluding iterables.
|
|
60
59
|
*
|
|
@@ -62,7 +61,7 @@ export declare type Raw = typeof Raw;
|
|
|
62
61
|
* string using the toString() method. We exclude them from this type to catch
|
|
63
62
|
* potential mistakes.
|
|
64
63
|
*/
|
|
65
|
-
export
|
|
64
|
+
export type Child = Element | string | number | boolean | null | undefined;
|
|
66
65
|
/**
|
|
67
66
|
* An arbitrarily nested iterable of Child values.
|
|
68
67
|
*
|
|
@@ -79,18 +78,18 @@ export interface ChildIterable extends Iterable<Child | ChildIterable> {
|
|
|
79
78
|
* Describes all valid values of an element tree, including arbitrarily nested
|
|
80
79
|
* iterables of such values.
|
|
81
80
|
*/
|
|
82
|
-
export
|
|
81
|
+
export type Children = Child | ChildIterable;
|
|
83
82
|
/**
|
|
84
83
|
* Represents all functions which can be used as a component.
|
|
85
84
|
*
|
|
86
85
|
* @template [TProps=*] - The expected props for the component.
|
|
87
86
|
*/
|
|
88
|
-
export
|
|
87
|
+
export type Component<TProps extends Record<string, unknown> = any> = (this: Context<TProps>, props: TProps) => Children | PromiseLike<Children> | Iterator<Children, Children | void, any> | AsyncIterator<Children, Children | void, any>;
|
|
89
88
|
/**
|
|
90
89
|
* A type to keep track of keys. Any value can be a key, though null and
|
|
91
90
|
* undefined are ignored.
|
|
92
91
|
*/
|
|
93
|
-
|
|
92
|
+
type Key = unknown;
|
|
94
93
|
declare const ElementSymbol: unique symbol;
|
|
95
94
|
export interface Element<TTag extends Tag = Tag> {
|
|
96
95
|
/**
|
|
@@ -191,7 +190,7 @@ export declare function cloneElement<TTag extends Tag>(el: Element<TTag>): Eleme
|
|
|
191
190
|
*
|
|
192
191
|
* All of these possible values are reflected in this utility type.
|
|
193
192
|
*/
|
|
194
|
-
export
|
|
193
|
+
export type ElementValue<TNode> = Array<TNode | string> | TNode | string | undefined;
|
|
195
194
|
/**
|
|
196
195
|
* @internal
|
|
197
196
|
* The internal nodes which are cached and diffed against new elements when
|
|
@@ -220,25 +219,30 @@ declare class Retainer<TNode> {
|
|
|
220
219
|
* The cached child values of this element. Only host and component elements
|
|
221
220
|
* will use this property.
|
|
222
221
|
*/
|
|
223
|
-
|
|
222
|
+
cachedChildValues: ElementValue<TNode>;
|
|
224
223
|
/**
|
|
225
224
|
* The child which this retainer replaces. This property is used when an
|
|
226
225
|
* async retainer tree replaces previously rendered elements, so that the
|
|
227
226
|
* previously rendered elements can remain visible until the async tree
|
|
228
227
|
* fulfills. Will be set to undefined once this subtree fully renders.
|
|
229
228
|
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
fallbackValue: RetainerChild<TNode>;
|
|
230
|
+
inflightValue: Promise<ElementValue<TNode>> | undefined;
|
|
231
|
+
onNextValues: Function | undefined;
|
|
233
232
|
constructor(el: Element);
|
|
234
233
|
}
|
|
235
234
|
/**
|
|
236
235
|
* The retainer equivalent of ElementValue
|
|
237
236
|
*/
|
|
238
|
-
|
|
237
|
+
type RetainerChild<TNode> = Retainer<TNode> | string | undefined;
|
|
238
|
+
export interface HydrationData<TNode> {
|
|
239
|
+
props: Record<string, unknown>;
|
|
240
|
+
children: Array<TNode | string>;
|
|
241
|
+
}
|
|
239
242
|
export interface RendererImpl<TNode, TScope, TRoot extends TNode = TNode, TResult = ElementValue<TNode>> {
|
|
240
243
|
scope<TTag extends string | symbol>(scope: TScope | undefined, tag: TTag, props: TagProps<TTag>): TScope | undefined;
|
|
241
244
|
create<TTag extends string | symbol>(tag: TTag, props: TagProps<TTag>, scope: TScope | undefined): TNode;
|
|
245
|
+
hydrate<TTag extends string | symbol>(tag: TTag, node: TNode | TRoot, props: TagProps<TTag>): HydrationData<TNode> | undefined;
|
|
242
246
|
/**
|
|
243
247
|
* Called when an element’s rendered value is exposed via render, schedule,
|
|
244
248
|
* refresh, refs, or generator yield expressions.
|
|
@@ -261,14 +265,14 @@ export interface RendererImpl<TNode, TScope, TRoot extends TNode = TNode, TResul
|
|
|
261
265
|
* @param text - The string child.
|
|
262
266
|
* @param scope - The current scope.
|
|
263
267
|
*
|
|
264
|
-
* @returns
|
|
268
|
+
* @returns A string to be passed to arrange.
|
|
265
269
|
*
|
|
266
|
-
* Rather than returning
|
|
267
|
-
*
|
|
268
|
-
* adjacent strings can be concatenated and the actual element tree can be
|
|
269
|
-
* rendered in
|
|
270
|
+
* Rather than returning Text nodes as we would in the DOM case, for example,
|
|
271
|
+
* we delay that step for Renderer.prototype.arrange. We do this so that
|
|
272
|
+
* adjacent strings can be concatenated, and the actual element tree can be
|
|
273
|
+
* rendered in normalized form.
|
|
270
274
|
*/
|
|
271
|
-
|
|
275
|
+
text(text: string, scope: TScope | undefined, hydration: HydrationData<TNode> | undefined): string;
|
|
272
276
|
/**
|
|
273
277
|
* Called for each Raw element whose value prop is a string.
|
|
274
278
|
*
|
|
@@ -277,13 +281,13 @@ export interface RendererImpl<TNode, TScope, TRoot extends TNode = TNode, TResul
|
|
|
277
281
|
*
|
|
278
282
|
* @returns The parsed node or string.
|
|
279
283
|
*/
|
|
280
|
-
|
|
284
|
+
raw(value: string | TNode, scope: TScope | undefined, hydration: HydrationData<TNode> | undefined): ElementValue<TNode>;
|
|
281
285
|
patch<TTag extends string | symbol, TName extends string>(tag: TTag, node: TNode, name: TName, value: TagProps<TTag>[TName], oldValue: TagProps<TTag>[TName] | undefined, scope: TScope): unknown;
|
|
282
286
|
arrange<TTag extends string | symbol>(tag: TTag, node: TNode, props: TagProps<TTag>, children: Array<TNode | string>, oldProps: TagProps<TTag> | undefined, oldChildren: Array<TNode | string> | undefined): unknown;
|
|
283
287
|
dispose<TTag extends string | symbol>(tag: TTag, node: TNode, props: TagProps<TTag>): unknown;
|
|
284
288
|
flush(root: TRoot): unknown;
|
|
285
289
|
}
|
|
286
|
-
declare const
|
|
290
|
+
declare const _RendererImpl: unique symbol;
|
|
287
291
|
/**
|
|
288
292
|
* An abstract class which is subclassed to render to different target
|
|
289
293
|
* environments. This class is responsible for kicking off the rendering
|
|
@@ -300,7 +304,7 @@ export declare class Renderer<TNode extends object = object, TScope = unknown, T
|
|
|
300
304
|
* A weakmap which stores element trees by root.
|
|
301
305
|
*/
|
|
302
306
|
cache: WeakMap<object, Retainer<TNode>>;
|
|
303
|
-
[
|
|
307
|
+
[_RendererImpl]: RendererImpl<TNode, TScope, TRoot, TResult>;
|
|
304
308
|
constructor(impl: Partial<RendererImpl<TNode, TScope, TRoot, TResult>>);
|
|
305
309
|
/**
|
|
306
310
|
* Renders an element tree into a specific root.
|
|
@@ -309,7 +313,7 @@ export declare class Renderer<TNode extends object = object, TScope = unknown, T
|
|
|
309
313
|
* used root to delete the previously rendered element tree from the cache.
|
|
310
314
|
* @param root - The node to be rendered into. The renderer will cache
|
|
311
315
|
* element trees per root.
|
|
312
|
-
* @param
|
|
316
|
+
* @param bridge - An optional context that will be the ancestor context of all
|
|
313
317
|
* elements in the tree. Useful for connecting different renderers so that
|
|
314
318
|
* events/provisions properly propagate. The context for a given root must be
|
|
315
319
|
* the same or an error will be thrown.
|
|
@@ -318,6 +322,7 @@ export declare class Renderer<TNode extends object = object, TScope = unknown, T
|
|
|
318
322
|
* the result if the element tree renders asynchronously.
|
|
319
323
|
*/
|
|
320
324
|
render(children: Children, root?: TRoot | undefined, bridge?: Context | undefined): Promise<TResult> | TResult;
|
|
325
|
+
hydrate(children: Children, root: TRoot, bridge?: Context | undefined): Promise<TResult> | TResult;
|
|
321
326
|
}
|
|
322
327
|
export interface Context extends Crank.Context {
|
|
323
328
|
}
|
|
@@ -329,75 +334,50 @@ export interface ProvisionMap extends Crank.ProvisionMap {
|
|
|
329
334
|
}
|
|
330
335
|
/**
|
|
331
336
|
* @internal
|
|
332
|
-
* The internal class which holds
|
|
337
|
+
* The internal class which holds context data.
|
|
333
338
|
*/
|
|
334
339
|
declare class ContextImpl<TNode = unknown, TScope = unknown, TRoot extends TNode = TNode, TResult = unknown> {
|
|
335
|
-
/**
|
|
336
|
-
* flags - A bitmask. See CONTEXT FLAGS above.
|
|
337
|
-
*/
|
|
340
|
+
/** A bitmask. See CONTEXT FLAGS above. */
|
|
338
341
|
f: number;
|
|
342
|
+
/** The actual context associated with this impl. */
|
|
343
|
+
owner: Context<unknown, TResult>;
|
|
339
344
|
/**
|
|
340
|
-
*
|
|
341
|
-
*/
|
|
342
|
-
ctx: Context<unknown, TResult>;
|
|
343
|
-
/**
|
|
344
|
-
* renderer - The renderer which created this context.
|
|
345
|
+
* The renderer which created this context.
|
|
345
346
|
*/
|
|
346
347
|
renderer: RendererImpl<TNode, TScope, TRoot, TResult>;
|
|
347
|
-
/**
|
|
348
|
-
* root - The root node as set by the nearest ancestor portal.
|
|
349
|
-
*/
|
|
348
|
+
/** The root node as set by the nearest ancestor portal. */
|
|
350
349
|
root: TRoot | undefined;
|
|
351
350
|
/**
|
|
352
|
-
*
|
|
351
|
+
* The nearest ancestor host or portal retainer.
|
|
353
352
|
*
|
|
354
353
|
* When refresh is called, the host element will be arranged as the last step
|
|
355
354
|
* of the commit, to make sure the parent’s children properly reflects the
|
|
356
355
|
* components’s children.
|
|
357
356
|
*/
|
|
358
357
|
host: Retainer<TNode>;
|
|
359
|
-
/**
|
|
360
|
-
* parent - The parent context.
|
|
361
|
-
*/
|
|
358
|
+
/** The parent context impl. */
|
|
362
359
|
parent: ContextImpl<TNode, TScope, TRoot, TResult> | undefined;
|
|
363
|
-
/**
|
|
364
|
-
* scope - The value of the scope at the point of element’s creation.
|
|
365
|
-
*/
|
|
360
|
+
/** The value of the scope at the point of element’s creation. */
|
|
366
361
|
scope: TScope | undefined;
|
|
367
|
-
/**
|
|
368
|
-
* retainer - The internal node associated with this context.
|
|
369
|
-
*/
|
|
362
|
+
/** The internal node associated with this context. */
|
|
370
363
|
ret: Retainer<TNode>;
|
|
371
364
|
/**
|
|
372
|
-
*
|
|
365
|
+
* The iterator returned by the component function.
|
|
366
|
+
*
|
|
367
|
+
* Existence of this property implies that the component is a generator
|
|
368
|
+
* component. It is deleted when a component is returned.
|
|
373
369
|
*/
|
|
374
370
|
iterator: Iterator<Children, Children | void, unknown> | AsyncIterator<Children, Children | void, unknown> | undefined;
|
|
375
|
-
/*** async properties ***/
|
|
376
|
-
/**
|
|
377
|
-
* inflightBlock
|
|
378
|
-
*/
|
|
379
371
|
inflightBlock: Promise<unknown> | undefined;
|
|
380
|
-
/**
|
|
381
|
-
* inflightValue
|
|
382
|
-
*/
|
|
383
372
|
inflightValue: Promise<ElementValue<TNode>> | undefined;
|
|
384
|
-
/**
|
|
385
|
-
* enqueuedBlock
|
|
386
|
-
*/
|
|
387
373
|
enqueuedBlock: Promise<unknown> | undefined;
|
|
388
|
-
/**
|
|
389
|
-
* enqueuedValue
|
|
390
|
-
*/
|
|
391
374
|
enqueuedValue: Promise<ElementValue<TNode>> | undefined;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
* implement the props async iterator. See the Symbol.asyncIterator method
|
|
395
|
-
* and the resumeCtxIterator function.
|
|
396
|
-
*/
|
|
397
|
-
onAvailable: Function | undefined;
|
|
375
|
+
onProps: ((props: Record<string, any>) => unknown) | undefined;
|
|
376
|
+
onPropsRequested: Function | undefined;
|
|
398
377
|
constructor(renderer: RendererImpl<TNode, TScope, TRoot, TResult>, root: TRoot | undefined, host: Retainer<TNode>, parent: ContextImpl<TNode, TScope, TRoot, TResult> | undefined, scope: TScope | undefined, ret: Retainer<TNode>);
|
|
399
378
|
}
|
|
400
|
-
declare const
|
|
379
|
+
declare const _ContextImpl: unique symbol;
|
|
380
|
+
type ComponentProps<T> = T extends (props: infer U) => any ? U : T;
|
|
401
381
|
/**
|
|
402
382
|
* A class which is instantiated and passed to every component as its this
|
|
403
383
|
* value. Contexts form a tree just like elements and all components in the
|
|
@@ -414,7 +394,7 @@ export declare class Context<TProps = any, TResult = any> implements EventTarget
|
|
|
414
394
|
/**
|
|
415
395
|
* @internal
|
|
416
396
|
*/
|
|
417
|
-
[
|
|
397
|
+
[_ContextImpl]: ContextImpl<unknown, unknown, unknown, TResult>;
|
|
418
398
|
constructor(impl: ContextImpl<unknown, unknown, unknown, TResult>);
|
|
419
399
|
/**
|
|
420
400
|
* The current props of the associated element.
|
|
@@ -423,7 +403,7 @@ export declare class Context<TProps = any, TResult = any> implements EventTarget
|
|
|
423
403
|
* component or via the context iterator methods. This property is mainly for
|
|
424
404
|
* plugins or utilities which wrap contexts.
|
|
425
405
|
*/
|
|
426
|
-
get props(): TProps
|
|
406
|
+
get props(): ComponentProps<TProps>;
|
|
427
407
|
/**
|
|
428
408
|
* The current value of the associated element.
|
|
429
409
|
*
|
|
@@ -432,8 +412,8 @@ export declare class Context<TProps = any, TResult = any> implements EventTarget
|
|
|
432
412
|
* mainly for plugins or utilities which wrap contexts.
|
|
433
413
|
*/
|
|
434
414
|
get value(): TResult;
|
|
435
|
-
[Symbol.iterator](): Generator<TProps
|
|
436
|
-
[Symbol.asyncIterator](): AsyncGenerator<TProps
|
|
415
|
+
[Symbol.iterator](): Generator<ComponentProps<TProps>>;
|
|
416
|
+
[Symbol.asyncIterator](): AsyncGenerator<ComponentProps<TProps>>;
|
|
437
417
|
/**
|
|
438
418
|
* Re-executes a component.
|
|
439
419
|
*
|
|
@@ -477,8 +457,8 @@ export declare class Context<TProps = any, TResult = any> implements EventTarget
|
|
|
477
457
|
export interface EventMap extends Crank.EventMap {
|
|
478
458
|
[type: string]: Event;
|
|
479
459
|
}
|
|
480
|
-
|
|
481
|
-
|
|
460
|
+
type MappedEventListener<T extends string> = (ev: EventMap[T]) => unknown;
|
|
461
|
+
type MappedEventListenerOrEventListenerObject<T extends string> = MappedEventListener<T> | {
|
|
482
462
|
handleEvent: MappedEventListener<T>;
|
|
483
463
|
};
|
|
484
464
|
declare global {
|