@craft-ts/component 0.7.0-beta.13 → 0.7.0-beta.16
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/package.json +7 -2
- package/src/index.d.ts +40 -40
- package/src/index.js +35 -35
- package/src/lib/a11y-control.d.ts +0 -1
- package/src/lib/a11y-control.js +0 -1
- package/src/lib/a11y.d.ts +4 -5
- package/src/lib/a11y.js +3 -4
- package/src/lib/ai/ai-context-menu.d.ts +24 -25
- package/src/lib/ai/ai-context-menu.js +2 -3
- package/src/lib/ai/ai-send-dialog.d.ts +277 -278
- package/src/lib/ai/ai-send-dialog.js +4 -5
- package/src/lib/ai/send-context-to-ai.d.ts +1 -2
- package/src/lib/ai/send-context-to-ai.js +4 -5
- package/src/lib/assert-defined-input.d.ts +1 -2
- package/src/lib/assert-defined-input.js +0 -1
- package/src/lib/bootstrap.d.ts +4 -3
- package/src/lib/bootstrap.js +6 -8
- package/src/lib/bridge.d.ts +9 -10
- package/src/lib/bridge.js +3 -4
- package/src/lib/catch-node.d.ts +35 -0
- package/src/lib/{block.js → catch-node.js} +9 -10
- package/src/lib/component.d.ts +23 -10
- package/src/lib/component.js +5 -6
- package/src/lib/composition.d.ts +1 -2
- package/src/lib/composition.js +2 -3
- package/src/lib/craft-defaults.d.ts +0 -1
- package/src/lib/craft-defaults.js +4 -5
- package/src/lib/craft-host-tokens.d.ts +0 -1
- package/src/lib/craft-host-tokens.js +0 -1
- package/src/lib/craft-router-outlet.d.ts +1 -2
- package/src/lib/craft-router-outlet.js +1 -2
- package/src/lib/css-vars.d.ts +0 -1
- package/src/lib/css-vars.js +0 -1
- package/src/lib/css-vars.type.d.ts +1 -2
- package/src/lib/css-vars.type.js +0 -1
- package/src/lib/{defer.d.ts → defer-node.d.ts} +4 -5
- package/src/lib/{defer.js → defer-node.js} +1 -2
- package/src/lib/directive.d.ts +1 -2
- package/src/lib/directive.js +1 -2
- package/src/lib/factory-runtime.d.ts +1 -2
- package/src/lib/factory-runtime.js +0 -1
- package/src/lib/{field-exception-block.d.ts → field-error-node.d.ts} +22 -23
- package/src/lib/{field-exception-block.js → field-error-node.js} +8 -9
- package/src/lib/for-node.d.ts +28 -0
- package/src/lib/{each.js → for-node.js} +4 -5
- package/src/lib/for-scheduling.d.ts +58 -0
- package/src/lib/{each-scheduling.js → for-scheduling.js} +14 -15
- package/src/lib/host-runtime.d.ts +0 -1
- package/src/lib/host-runtime.js +0 -1
- package/src/lib/hydrate.d.ts +2 -3
- package/src/lib/hydrate.js +57 -18
- package/src/lib/hyperscript.d.ts +1 -2
- package/src/lib/hyperscript.js +1 -2
- package/src/lib/if-node.d.ts +7 -0
- package/src/lib/{if-block.js → if-node.js} +2 -3
- package/src/lib/locator.d.ts +5 -6
- package/src/lib/locator.js +1 -2
- package/src/lib/{match-block.d.ts → match-node.d.ts} +8 -9
- package/src/lib/{match-block.js → match-node.js} +3 -4
- package/src/lib/{pending-block.d.ts → pending-node.d.ts} +28 -29
- package/src/lib/{pending-block.js → pending-node.js} +12 -13
- package/src/lib/project.d.ts +2 -3
- package/src/lib/project.js +2 -3
- package/src/lib/render/hydration-metadata.d.ts +0 -1
- package/src/lib/render/hydration-metadata.js +0 -1
- package/src/lib/render/hydration.d.ts +0 -1
- package/src/lib/render/hydration.js +0 -1
- package/src/lib/render/interpreter.d.ts +9 -8
- package/src/lib/render/interpreter.js +156 -81
- package/src/lib/render/server-style-collector.d.ts +0 -1
- package/src/lib/render/server-style-collector.js +0 -1
- package/src/lib/render/ssr-coordinator.d.ts +4 -2
- package/src/lib/render/ssr-coordinator.js +14 -3
- package/src/lib/render/string-dom.d.ts +0 -1
- package/src/lib/render/string-dom.js +48 -7
- package/src/lib/render/style-registry.d.ts +3 -2
- package/src/lib/render/style-registry.js +3 -2
- package/src/lib/render/style-scope.d.ts +0 -1
- package/src/lib/render/style-scope.js +0 -1
- package/src/lib/render/vnode.d.ts +117 -54
- package/src/lib/render/vnode.js +26 -27
- package/src/lib/security.d.ts +54 -0
- package/src/lib/security.js +502 -0
- package/src/lib/server-render.d.ts +12 -3
- package/src/lib/server-render.js +76 -17
- package/src/lib/start.d.ts +2 -3
- package/src/lib/start.js +3 -3
- package/src/lib/template-contract.d.ts +22 -23
- package/src/lib/template-contract.js +0 -1
- package/src/lib/template.d.ts +2 -3
- package/src/lib/template.js +2 -3
- package/src/lib/testing.d.ts +3 -4
- package/src/lib/testing.js +5 -6
- package/src/lib/types.d.ts +40 -28
- package/src/lib/types.js +3 -4
- package/testing/public-api.d.ts +0 -1
- package/testing/public-api.js +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/a11y-control.d.ts.map +0 -1
- package/src/lib/a11y-control.js.map +0 -1
- package/src/lib/a11y.d.ts.map +0 -1
- package/src/lib/a11y.js.map +0 -1
- package/src/lib/ai/ai-context-menu.d.ts.map +0 -1
- package/src/lib/ai/ai-context-menu.js.map +0 -1
- package/src/lib/ai/ai-send-dialog.d.ts.map +0 -1
- package/src/lib/ai/ai-send-dialog.js.map +0 -1
- package/src/lib/ai/send-context-to-ai.d.ts.map +0 -1
- package/src/lib/ai/send-context-to-ai.js.map +0 -1
- package/src/lib/assert-defined-input.d.ts.map +0 -1
- package/src/lib/assert-defined-input.js.map +0 -1
- package/src/lib/block.d.ts +0 -36
- package/src/lib/block.d.ts.map +0 -1
- package/src/lib/block.js.map +0 -1
- package/src/lib/bootstrap.d.ts.map +0 -1
- package/src/lib/bootstrap.js.map +0 -1
- package/src/lib/bridge.d.ts.map +0 -1
- package/src/lib/bridge.js.map +0 -1
- package/src/lib/component.d.ts.map +0 -1
- package/src/lib/component.js.map +0 -1
- package/src/lib/composition.d.ts.map +0 -1
- package/src/lib/composition.js.map +0 -1
- package/src/lib/craft-defaults.d.ts.map +0 -1
- package/src/lib/craft-defaults.js.map +0 -1
- package/src/lib/craft-host-tokens.d.ts.map +0 -1
- package/src/lib/craft-host-tokens.js.map +0 -1
- package/src/lib/craft-router-outlet.d.ts.map +0 -1
- package/src/lib/craft-router-outlet.js.map +0 -1
- package/src/lib/css-vars.d.ts.map +0 -1
- package/src/lib/css-vars.js.map +0 -1
- package/src/lib/css-vars.type.d.ts.map +0 -1
- package/src/lib/css-vars.type.js.map +0 -1
- package/src/lib/defer.d.ts.map +0 -1
- package/src/lib/defer.js.map +0 -1
- package/src/lib/directive.d.ts.map +0 -1
- package/src/lib/directive.js.map +0 -1
- package/src/lib/each-scheduling.d.ts +0 -59
- package/src/lib/each-scheduling.d.ts.map +0 -1
- package/src/lib/each-scheduling.js.map +0 -1
- package/src/lib/each.d.ts +0 -29
- package/src/lib/each.d.ts.map +0 -1
- package/src/lib/each.js.map +0 -1
- package/src/lib/factory-runtime.d.ts.map +0 -1
- package/src/lib/factory-runtime.js.map +0 -1
- package/src/lib/field-exception-block.d.ts.map +0 -1
- package/src/lib/field-exception-block.js.map +0 -1
- package/src/lib/host-runtime.d.ts.map +0 -1
- package/src/lib/host-runtime.js.map +0 -1
- package/src/lib/hydrate.d.ts.map +0 -1
- package/src/lib/hydrate.js.map +0 -1
- package/src/lib/hyperscript.d.ts.map +0 -1
- package/src/lib/hyperscript.js.map +0 -1
- package/src/lib/if-block.d.ts +0 -8
- package/src/lib/if-block.d.ts.map +0 -1
- package/src/lib/if-block.js.map +0 -1
- package/src/lib/locator.d.ts.map +0 -1
- package/src/lib/locator.js.map +0 -1
- package/src/lib/match-block.d.ts.map +0 -1
- package/src/lib/match-block.js.map +0 -1
- package/src/lib/pending-block.d.ts.map +0 -1
- package/src/lib/pending-block.js.map +0 -1
- package/src/lib/project.d.ts.map +0 -1
- package/src/lib/project.js.map +0 -1
- package/src/lib/render/hydration-metadata.d.ts.map +0 -1
- package/src/lib/render/hydration-metadata.js.map +0 -1
- package/src/lib/render/hydration.d.ts.map +0 -1
- package/src/lib/render/hydration.js.map +0 -1
- package/src/lib/render/interpreter.d.ts.map +0 -1
- package/src/lib/render/interpreter.js.map +0 -1
- package/src/lib/render/server-style-collector.d.ts.map +0 -1
- package/src/lib/render/server-style-collector.js.map +0 -1
- package/src/lib/render/ssr-coordinator.d.ts.map +0 -1
- package/src/lib/render/ssr-coordinator.js.map +0 -1
- package/src/lib/render/string-dom.d.ts.map +0 -1
- package/src/lib/render/string-dom.js.map +0 -1
- package/src/lib/render/style-registry.d.ts.map +0 -1
- package/src/lib/render/style-registry.js.map +0 -1
- package/src/lib/render/style-scope.d.ts.map +0 -1
- package/src/lib/render/style-scope.js.map +0 -1
- package/src/lib/render/vnode.d.ts.map +0 -1
- package/src/lib/render/vnode.js.map +0 -1
- package/src/lib/server-render.d.ts.map +0 -1
- package/src/lib/server-render.js.map +0 -1
- package/src/lib/start.d.ts.map +0 -1
- package/src/lib/start.js.map +0 -1
- package/src/lib/template-contract.d.ts.map +0 -1
- package/src/lib/template-contract.js.map +0 -1
- package/src/lib/template.d.ts.map +0 -1
- package/src/lib/template.js.map +0 -1
- package/src/lib/testing.d.ts.map +0 -1
- package/src/lib/testing.js.map +0 -1
- package/src/lib/types.d.ts.map +0 -1
- package/src/lib/types.js.map +0 -1
- package/testing/public-api.d.ts.map +0 -1
- package/testing/public-api.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AnyCraftException, CEmailException, CMaxException, CMaxLengthException, CMinException, CMinLengthException, CRequiredException, CraftField, FieldExceptionVisibility, FieldValidationCase } from '@craft-ts/core';
|
|
2
|
-
import {
|
|
3
|
-
import type { CraftNodeChildren, CraftNodeChildrenFieldExceptions } from './render/vnode';
|
|
4
|
-
export {
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type
|
|
2
|
+
import { COMPONENT_FIELD_ERROR_NODE, FIELD_ERROR_NODE_DIRECTIVE, type CraftDirective } from './types.js';
|
|
3
|
+
import type { CraftNodeChildren, CraftNodeChildrenFieldExceptions } from './render/vnode.js';
|
|
4
|
+
export { FIELD_ERROR_NODE_DIRECTIVE } from './types.js';
|
|
5
|
+
export type FieldErrorMode = 'first' | 'all';
|
|
6
|
+
export type FieldErrorPosition = 'before' | 'after';
|
|
7
|
+
export type FieldErrorOptions = {
|
|
8
8
|
readonly visibility?: FieldExceptionVisibility;
|
|
9
|
-
readonly mode?:
|
|
10
|
-
readonly position?:
|
|
9
|
+
readonly mode?: FieldErrorMode;
|
|
10
|
+
readonly position?: FieldErrorPosition;
|
|
11
11
|
};
|
|
12
12
|
export type FieldExceptionHandlerContext<Field extends CraftField<any> = CraftField<any>, Path extends string = string, Exception extends AnyCraftException = AnyCraftException> = {
|
|
13
13
|
readonly field: Field;
|
|
@@ -58,39 +58,38 @@ type HasSeveralPaths<Cases> = true extends IsUnion<CasePath<Cases>> ? true : fal
|
|
|
58
58
|
type HandlersAreLocal<Handlers> = Handlers[keyof Handlers] extends (...args: any[]) => any ? true : false;
|
|
59
59
|
type ReachableHandlerKeys<Cases, Handlers> = HandlersAreLocal<Handlers> extends true ? HasSeveralPaths<Cases> extends true ? CaseIdentity<Cases> : CaseCode<Cases> : CaseIdentity<Cases>;
|
|
60
60
|
type ProvidedHandlerKeys<Handlers> = HandlersAreLocal<Handlers> extends true ? HandlerIdentity<Handlers> : HandlerIdentity<Handlers>;
|
|
61
|
-
export type
|
|
61
|
+
export type FieldErrorExhaustiveCheck<Cases, Handlers> = [
|
|
62
62
|
Exclude<ReachableHandlerKeys<Cases, Handlers>, ProvidedHandlerKeys<Handlers>>
|
|
63
63
|
] extends [never] ? [
|
|
64
64
|
Exclude<ProvidedHandlerKeys<Handlers>, ReachableHandlerKeys<Cases, Handlers>>
|
|
65
65
|
] extends [never] ? unknown : {
|
|
66
|
-
'
|
|
66
|
+
'fieldErrorNode.exhaustive has handlers for unreachable field exceptions': Exclude<ProvidedHandlerKeys<Handlers>, ReachableHandlerKeys<Cases, Handlers>>;
|
|
67
67
|
} : {
|
|
68
|
-
'
|
|
68
|
+
'fieldErrorNode.exhaustive is missing handlers for field exceptions': Exclude<ReachableHandlerKeys<Cases, Handlers>, ProvidedHandlerKeys<Handlers>>;
|
|
69
69
|
};
|
|
70
|
-
export type
|
|
70
|
+
export type FieldErrorPartialCheck<Cases, Handlers> = [
|
|
71
71
|
Exclude<ProvidedHandlerKeys<Handlers>, ReachableHandlerKeys<Cases, Handlers>>
|
|
72
72
|
] extends [never] ? unknown : {
|
|
73
|
-
'
|
|
73
|
+
'fieldErrorNode.partial has handlers for unreachable field exceptions': Exclude<ProvidedHandlerKeys<Handlers>, ReachableHandlerKeys<Cases, Handlers>>;
|
|
74
74
|
};
|
|
75
75
|
type HandledIdentity<Cases, Handlers> = HandlersAreLocal<Handlers> extends true ? Cases extends FieldValidationCase<infer Path, any, infer Exception> ? Exception['_tag'] extends keyof Handlers ? `${Path}.${Exception['_tag']}` : never : never : HandlerIdentity<Handlers>;
|
|
76
76
|
export type FieldValidationHandledIdentities<Cases, Handlers> = HandledIdentity<UnhandledFieldValidationCases<Cases>, Handlers> | ([UnhandledFieldValidationCases<Cases>] extends [never] ? HandlerIdentity<Handlers> : never);
|
|
77
77
|
export type ResidualFieldValidationCases<Cases, Handlers> = Cases extends unknown ? CaseIdentity<Cases> extends HandledIdentity<Cases, Handlers> ? never : Cases : never;
|
|
78
78
|
export type ResidualFieldValidationCasesByIdentity<Cases, Identities> = Cases extends unknown ? CaseIdentity<Cases> extends Identities ? never : Cases : never;
|
|
79
79
|
export type FieldExceptionHandlerFieldExceptions<Handlers> = CraftNodeChildrenFieldExceptions<FieldExceptionHandlerChildren<Handlers[keyof Handlers]>>;
|
|
80
|
-
export type
|
|
81
|
-
readonly [
|
|
82
|
-
readonly [
|
|
80
|
+
export type FieldErrorDirective<Handlers extends FieldExceptionHandlers, Exhaustive extends boolean = boolean> = CraftDirective & {
|
|
81
|
+
readonly [COMPONENT_FIELD_ERROR_NODE]: true;
|
|
82
|
+
readonly [FIELD_ERROR_NODE_DIRECTIVE]: {
|
|
83
83
|
readonly handlers: Handlers;
|
|
84
84
|
readonly exhaustive: Exhaustive;
|
|
85
|
-
readonly options: Required<Pick<
|
|
85
|
+
readonly options: Required<Pick<FieldErrorOptions, 'mode' | 'position'>> & Pick<FieldErrorOptions, 'visibility'>;
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
|
-
declare function exhaustive<const Handlers extends LocalHandlerMap>(handlers: Handlers & ContextualLocalHandlers<Handlers>, options?:
|
|
89
|
-
declare function exhaustive<const Handlers extends GroupedHandlerMap>(handlers: Handlers & ContextualGroupedHandlers<Handlers>, options?:
|
|
90
|
-
declare function partial<const Handlers extends LocalHandlerMap>(handlers: Handlers & ContextualLocalHandlers<Handlers>, options?:
|
|
91
|
-
declare function partial<const Handlers extends GroupedHandlerMap>(handlers: Handlers & ContextualGroupedHandlers<Handlers>, options?:
|
|
92
|
-
export declare const
|
|
88
|
+
declare function exhaustive<const Handlers extends LocalHandlerMap>(handlers: Handlers & ContextualLocalHandlers<Handlers>, options?: FieldErrorOptions): FieldErrorDirective<Handlers, true>;
|
|
89
|
+
declare function exhaustive<const Handlers extends GroupedHandlerMap>(handlers: Handlers & ContextualGroupedHandlers<Handlers>, options?: FieldErrorOptions): FieldErrorDirective<Handlers, true>;
|
|
90
|
+
declare function partial<const Handlers extends LocalHandlerMap>(handlers: Handlers & ContextualLocalHandlers<Handlers>, options?: FieldErrorOptions): FieldErrorDirective<Handlers, false>;
|
|
91
|
+
declare function partial<const Handlers extends GroupedHandlerMap>(handlers: Handlers & ContextualGroupedHandlers<Handlers>, options?: FieldErrorOptions): FieldErrorDirective<Handlers, false>;
|
|
92
|
+
export declare const fieldErrorNode: {
|
|
93
93
|
exhaustive: typeof exhaustive;
|
|
94
94
|
partial: typeof partial;
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=field-exception-block.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CRAFT_DIRECTIVE,
|
|
2
|
-
export {
|
|
3
|
-
function
|
|
1
|
+
import { CRAFT_DIRECTIVE, COMPONENT_FIELD_ERROR_NODE, FIELD_ERROR_NODE_DIRECTIVE, } from './types.js';
|
|
2
|
+
export { FIELD_ERROR_NODE_DIRECTIVE } from './types.js';
|
|
3
|
+
function createFieldErrorDirective(name, handlers, options, exhaustive) {
|
|
4
4
|
const definition = {
|
|
5
5
|
handlers,
|
|
6
6
|
exhaustive,
|
|
@@ -24,21 +24,20 @@ function createFieldExceptionBlockDirective(name, handlers, options, exhaustive)
|
|
|
24
24
|
},
|
|
25
25
|
enumerable: false,
|
|
26
26
|
});
|
|
27
|
-
Object.defineProperty(directive,
|
|
27
|
+
Object.defineProperty(directive, FIELD_ERROR_NODE_DIRECTIVE, {
|
|
28
28
|
value: definition,
|
|
29
29
|
enumerable: false,
|
|
30
30
|
});
|
|
31
|
-
Object.defineProperty(directive,
|
|
31
|
+
Object.defineProperty(directive, COMPONENT_FIELD_ERROR_NODE, {
|
|
32
32
|
value: true,
|
|
33
33
|
enumerable: false,
|
|
34
34
|
});
|
|
35
35
|
return directive;
|
|
36
36
|
}
|
|
37
37
|
function exhaustive(handlers, options = {}) {
|
|
38
|
-
return
|
|
38
|
+
return createFieldErrorDirective('fieldErrorNode.exhaustive', handlers, options, true);
|
|
39
39
|
}
|
|
40
40
|
function partial(handlers, options = {}) {
|
|
41
|
-
return
|
|
41
|
+
return createFieldErrorDirective('fieldErrorNode.partial', handlers, options, false);
|
|
42
42
|
}
|
|
43
|
-
export const
|
|
44
|
-
//# sourceMappingURL=field-exception-block.js.map
|
|
43
|
+
export const fieldErrorNode = { exhaustive, partial };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CraftNodeChildrenDependencies, CraftNodeChildren, ForNode } from './render/vnode.js';
|
|
2
|
+
import type { InputValue } from './types.js';
|
|
3
|
+
import { YIELDABLE_VALUE } from '@craft-ts/core';
|
|
4
|
+
export interface ForOptions<Item, Key> {
|
|
5
|
+
readonly track: (item: Item, index: number) => Key;
|
|
6
|
+
readonly empty?: () => CraftNodeChildren;
|
|
7
|
+
}
|
|
8
|
+
type CallbackDependencies<Callback> = Callback extends (...args: any[]) => infer Output ? CraftNodeChildrenDependencies<Output> : {};
|
|
9
|
+
type EmptyDependencies<Options> = Options extends {
|
|
10
|
+
readonly empty?: infer Empty;
|
|
11
|
+
} ? CallbackDependencies<NonNullable<Empty>> : {};
|
|
12
|
+
type SourceName<Source> = Source extends {
|
|
13
|
+
readonly [YIELDABLE_VALUE]: infer Name extends string;
|
|
14
|
+
} ? Name : undefined;
|
|
15
|
+
type ForSource = readonly unknown[] | null | undefined | (() => readonly unknown[] | null | undefined) | Generator<unknown, readonly unknown[] | null | undefined, unknown> | (() => Generator<unknown, readonly unknown[] | null | undefined, unknown>);
|
|
16
|
+
type ForItemFromValue<Value> = [NonNullable<Value>] extends [never] ? never : NonNullable<Value> extends (...args: any[]) => infer Result ? ForItemFromValue<Result> : NonNullable<Value> extends Generator<any, infer Result, any> ? ForItemFromValue<Result> : NonNullable<Value> extends readonly (infer Item)[] ? Item : never;
|
|
17
|
+
type ForItem<Source> = [NonNullable<Source>] extends [never] ? unknown : ForItemFromValue<Source>;
|
|
18
|
+
type ForItemInput<Source> = InputValue<ForItem<Source>>;
|
|
19
|
+
export declare function forNode<Name extends string, Source extends ForSource, Key, Options extends ForOptions<NoInfer<ForItem<Source>>, Key>, ItemTemplate extends (item: NoInfer<ForItemInput<Source>>, index: number) => CraftNodeChildren>(source: Source & {
|
|
20
|
+
readonly [YIELDABLE_VALUE]: Name;
|
|
21
|
+
}, options: Options, itemTemplate: ItemTemplate): ForNode<ForItem<Source>, Key, CallbackDependencies<ItemTemplate> | EmptyDependencies<Options>, Name, ReturnType<ItemTemplate>, Options extends {
|
|
22
|
+
readonly empty?: (...args: any[]) => infer Empty;
|
|
23
|
+
} ? Empty : never>;
|
|
24
|
+
export declare function forNode<Source extends ForSource, Key, Options extends ForOptions<NoInfer<ForItem<Source>>, Key>, ItemTemplate extends (item: NoInfer<ForItemInput<Source>>, index: number) => CraftNodeChildren>(source: Source & ForSource, options: Options, itemTemplate: ItemTemplate): ForNode<ForItem<Source>, Key, CallbackDependencies<ItemTemplate> | EmptyDependencies<Options>, SourceName<Source>, ReturnType<ItemTemplate>, Options extends {
|
|
25
|
+
readonly empty?: (...args: any[]) => infer Empty;
|
|
26
|
+
} ? Empty : never>;
|
|
27
|
+
export type { ScheduleForDirective } from './for-scheduling.js';
|
|
28
|
+
export { FOR_SCHEDULER, FrameForScheduler, SyncForScheduler, createForScheduler, scheduleFor, } from './for-scheduling.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { pipeCraftNode } from './render/vnode';
|
|
1
|
+
import { pipeCraftNode } from './render/vnode.js';
|
|
2
2
|
import { YIELDABLE_VALUE } from '@craft-ts/core';
|
|
3
|
-
export function
|
|
3
|
+
export function forNode(source, options, itemTemplate) {
|
|
4
4
|
const sourceName = typeof source === 'function' &&
|
|
5
5
|
typeof source[YIELDABLE_VALUE] === 'string'
|
|
6
6
|
? source[YIELDABLE_VALUE]
|
|
7
7
|
: undefined;
|
|
8
8
|
const node = {
|
|
9
|
-
kind: '
|
|
9
|
+
kind: 'for',
|
|
10
10
|
source: source,
|
|
11
11
|
sourceName: sourceName,
|
|
12
12
|
track: options.track,
|
|
@@ -19,5 +19,4 @@ export function each(source, options, itemTemplate) {
|
|
|
19
19
|
});
|
|
20
20
|
return node;
|
|
21
21
|
}
|
|
22
|
-
export {
|
|
23
|
-
//# sourceMappingURL=each.js.map
|
|
22
|
+
export { FOR_SCHEDULER, FrameForScheduler, SyncForScheduler, createForScheduler, scheduleFor, } from './for-scheduling.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CraftDirective } from './types.js';
|
|
2
|
+
export type ForScheduleStrategy = 'sync' | 'frame';
|
|
3
|
+
export interface ForScheduleOptions {
|
|
4
|
+
readonly enabled?: boolean;
|
|
5
|
+
readonly strategy?: ForScheduleStrategy;
|
|
6
|
+
readonly frameBudgetMs?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ForSchedulePolicy {
|
|
9
|
+
readonly enabled: boolean;
|
|
10
|
+
readonly strategy: ForScheduleStrategy;
|
|
11
|
+
readonly frameBudgetMs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const SCHEDULE_FOR_DIRECTIVE: unique symbol;
|
|
14
|
+
export type ScheduleForDirective<Policy extends ForSchedulePolicy = ForSchedulePolicy> = CraftDirective & {
|
|
15
|
+
readonly [SCHEDULE_FOR_DIRECTIVE]: Policy;
|
|
16
|
+
};
|
|
17
|
+
type NormalizedPolicy<Options extends ForScheduleOptions> = {
|
|
18
|
+
readonly enabled: Options['enabled'] extends false ? false : true;
|
|
19
|
+
readonly strategy: Options['strategy'] extends ForScheduleStrategy ? Options['strategy'] : 'frame';
|
|
20
|
+
readonly frameBudgetMs: Options['frameBudgetMs'] extends number ? Options['frameBudgetMs'] : 4;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Adds progressive rendering metadata to an `each` block.
|
|
24
|
+
*
|
|
25
|
+
* This is registered through the normal Craft directive factory so it remains
|
|
26
|
+
* part of the directive authoring model. The renderer recognizes the marker
|
|
27
|
+
* before the generic directive path, so its identity does not imply a DOM
|
|
28
|
+
* wrapper or a CraftDirectiveRenderedNode.
|
|
29
|
+
*/
|
|
30
|
+
export declare function scheduleFor<const Options extends ForScheduleOptions>(options?: Options): ScheduleForDirective<NormalizedPolicy<Options>>;
|
|
31
|
+
export interface CancelHandle {
|
|
32
|
+
cancel(): void;
|
|
33
|
+
}
|
|
34
|
+
export interface ForScheduler {
|
|
35
|
+
schedule(task: () => void): CancelHandle;
|
|
36
|
+
}
|
|
37
|
+
/** Injectable override used by deterministic tests and host integrations. */
|
|
38
|
+
export declare const FOR_SCHEDULER: import("../../../../dist/libs/core/src").InjectionToken<ForScheduler>;
|
|
39
|
+
export declare class SyncForScheduler implements ForScheduler {
|
|
40
|
+
schedule(task: () => void): CancelHandle;
|
|
41
|
+
}
|
|
42
|
+
export declare class FrameForScheduler implements ForScheduler {
|
|
43
|
+
private readonly queue;
|
|
44
|
+
private frame;
|
|
45
|
+
private destroyed;
|
|
46
|
+
private readonly frameBudgetMs;
|
|
47
|
+
constructor(frameBudgetMs?: number);
|
|
48
|
+
schedule(task: () => void): CancelHandle;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
private requestFrame;
|
|
51
|
+
private flush;
|
|
52
|
+
private cancelFrame;
|
|
53
|
+
}
|
|
54
|
+
export declare function createForScheduler(policy: ForSchedulePolicy): ForScheduler & {
|
|
55
|
+
destroy?(): void;
|
|
56
|
+
};
|
|
57
|
+
export declare function isScheduleForDirective(value: unknown): value is ScheduleForDirective;
|
|
58
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InjectionToken } from './host-runtime';
|
|
2
|
-
import { craftDirective } from './directive';
|
|
3
|
-
export const
|
|
1
|
+
import { InjectionToken } from './host-runtime.js';
|
|
2
|
+
import { craftDirective } from './directive.js';
|
|
3
|
+
export const SCHEDULE_FOR_DIRECTIVE = Symbol('schedule-for-directive');
|
|
4
4
|
/**
|
|
5
5
|
* Adds progressive rendering metadata to an `each` block.
|
|
6
6
|
*
|
|
@@ -9,7 +9,7 @@ export const SCHEDULE_EACH_DIRECTIVE = Symbol('schedule-each-directive');
|
|
|
9
9
|
* before the generic directive path, so its identity does not imply a DOM
|
|
10
10
|
* wrapper or a CraftDirectiveRenderedNode.
|
|
11
11
|
*/
|
|
12
|
-
export function
|
|
12
|
+
export function scheduleFor(options = {}) {
|
|
13
13
|
const frameBudgetMs = typeof options.frameBudgetMs === 'number' && options.frameBudgetMs > 0
|
|
14
14
|
? options.frameBudgetMs
|
|
15
15
|
: 4;
|
|
@@ -18,23 +18,23 @@ export function scheduleEach(options = {}) {
|
|
|
18
18
|
strategy: options.strategy ?? 'frame',
|
|
19
19
|
frameBudgetMs,
|
|
20
20
|
};
|
|
21
|
-
const directive = craftDirective('
|
|
22
|
-
Object.defineProperty(directive,
|
|
21
|
+
const directive = craftDirective('scheduleFor', {}, (baseLogic) => baseLogic, (baseTemplate) => baseTemplate);
|
|
22
|
+
Object.defineProperty(directive, SCHEDULE_FOR_DIRECTIVE, {
|
|
23
23
|
value: Object.freeze(policy),
|
|
24
24
|
enumerable: false,
|
|
25
25
|
});
|
|
26
26
|
return directive;
|
|
27
27
|
}
|
|
28
28
|
/** Injectable override used by deterministic tests and host integrations. */
|
|
29
|
-
export const
|
|
29
|
+
export const FOR_SCHEDULER = new InjectionToken('FOR_SCHEDULER');
|
|
30
30
|
const NOOP_CANCEL = { cancel: () => undefined };
|
|
31
|
-
export class
|
|
31
|
+
export class SyncForScheduler {
|
|
32
32
|
schedule(task) {
|
|
33
33
|
task();
|
|
34
34
|
return NOOP_CANCEL;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export class
|
|
37
|
+
export class FrameForScheduler {
|
|
38
38
|
queue = [];
|
|
39
39
|
frame;
|
|
40
40
|
destroyed = false;
|
|
@@ -106,15 +106,14 @@ function now() {
|
|
|
106
106
|
? globalThis.performance.now()
|
|
107
107
|
: Date.now();
|
|
108
108
|
}
|
|
109
|
-
export function
|
|
109
|
+
export function createForScheduler(policy) {
|
|
110
110
|
if (!policy.enabled || policy.strategy === 'sync') {
|
|
111
|
-
return new
|
|
111
|
+
return new SyncForScheduler();
|
|
112
112
|
}
|
|
113
|
-
return new
|
|
113
|
+
return new FrameForScheduler(policy.frameBudgetMs);
|
|
114
114
|
}
|
|
115
|
-
export function
|
|
115
|
+
export function isScheduleForDirective(value) {
|
|
116
116
|
return ((typeof value === 'function' ||
|
|
117
117
|
(typeof value === 'object' && value !== null)) &&
|
|
118
|
-
|
|
118
|
+
SCHEDULE_FOR_DIRECTIVE in value);
|
|
119
119
|
}
|
|
120
|
-
//# sourceMappingURL=each-scheduling.js.map
|
package/src/lib/host-runtime.js
CHANGED
package/src/lib/hydrate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type CraftTransferSnapshot } from '@craft-ts/core';
|
|
2
|
-
import { type CraftAppRef, type BootstrapCraftOptions } from './bootstrap';
|
|
3
|
-
import { type HydrationMismatchError } from './render/hydration';
|
|
2
|
+
import { type CraftAppRef, type BootstrapCraftOptions } from './bootstrap.js';
|
|
3
|
+
import { type HydrationMismatchError } from './render/hydration.js';
|
|
4
4
|
export type HydrateCraftOptions = BootstrapCraftOptions & Readonly<{
|
|
5
5
|
snapshot?: CraftTransferSnapshot;
|
|
6
6
|
props?: object;
|
|
@@ -12,4 +12,3 @@ export type HydratedCraftAppRef = CraftAppRef & Readonly<{
|
|
|
12
12
|
}>;
|
|
13
13
|
/** Claims server DOM, restores state, then attaches bindings and listeners. */
|
|
14
14
|
export declare function hydrateCraft(options: HydrateCraftOptions): HydratedCraftAppRef;
|
|
15
|
-
//# sourceMappingURL=hydrate.d.ts.map
|
package/src/lib/hydrate.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { CRAFT_PLATFORM, CRAFT_PRIMITIVE_REGISTRY, createBrowserDomAdapter, createBrowserPlatform, createCraftRenderIdentity, primeCraftTransferSnapshot, } from '@craft-ts/core';
|
|
2
|
-
import { ɵcreateCraftApplicationInjector, ɵrunCraftAppInitializers, } from './bootstrap';
|
|
3
|
-
import { CRAFT_ROOT_COMPONENT } from './craft-host-tokens';
|
|
4
|
-
import { CRAFT_STYLE_REGISTRY,
|
|
5
|
-
import { mountInterpretedComponentWithOptions, } from './render/interpreter';
|
|
6
|
-
import { createHydrationCursor, } from './render/hydration';
|
|
7
|
-
import { CRAFT_TRANSFER_SCRIPT_ID } from './server-render';
|
|
8
|
-
import { CRAFT_COMPONENT } from './types';
|
|
1
|
+
import { CRAFT_HYDRATION_RUNTIME, CRAFT_PLATFORM, CRAFT_PRIMITIVE_REGISTRY, CRAFT_SECURITY_POLICY, CraftCspNonce, createCraftSecurityPolicy, createBrowserDomAdapter, createBrowserPlatform, createCraftRenderIdentity, primeCraftTransferSnapshot, } from '@craft-ts/core';
|
|
2
|
+
import { ɵcreateCraftApplicationInjector, ɵrunCraftAppInitializers, } from './bootstrap.js';
|
|
3
|
+
import { CRAFT_ROOT_COMPONENT } from './craft-host-tokens.js';
|
|
4
|
+
import { CRAFT_STYLE_REGISTRY, createCraftStyleRegistry, } from './render/style-registry.js';
|
|
5
|
+
import { mountInterpretedComponentWithOptions, } from './render/interpreter.js';
|
|
6
|
+
import { createHydrationCursor, } from './render/hydration.js';
|
|
7
|
+
import { CRAFT_TRANSFER_SCRIPT_ID } from './server-render.js';
|
|
8
|
+
import { CRAFT_COMPONENT } from './types.js';
|
|
9
9
|
/** Claims server DOM, restores state, then attaches bindings and listeners. */
|
|
10
10
|
export function hydrateCraft(options) {
|
|
11
11
|
const host = options.host ?? document.querySelector('craft-root') ?? document.body;
|
|
12
12
|
const win = host.ownerDocument.defaultView ?? window;
|
|
13
13
|
const platform = createBrowserPlatform(win, { hydrating: true });
|
|
14
|
+
const hydrationRuntime = createHydrationRuntime();
|
|
14
15
|
const injector = ɵcreateCraftApplicationInjector(options.config, [
|
|
15
16
|
{ provide: CRAFT_PLATFORM, useValue: platform },
|
|
16
|
-
|
|
17
|
+
{ provide: CRAFT_HYDRATION_RUNTIME, useValue: hydrationRuntime },
|
|
18
|
+
], options.mode);
|
|
17
19
|
const mismatches = [];
|
|
18
20
|
let mounted;
|
|
19
21
|
try {
|
|
20
22
|
const snapshot = options.snapshot ?? readTransferSnapshot(host.ownerDocument);
|
|
21
23
|
if (snapshot) {
|
|
22
|
-
primeCraftTransferSnapshot(injector.get(CRAFT_PRIMITIVE_REGISTRY), snapshot);
|
|
24
|
+
primeCraftTransferSnapshot(injector.get(CRAFT_PRIMITIVE_REGISTRY), snapshot, injector.get(CRAFT_SECURITY_POLICY, createCraftSecurityPolicy()).transfer);
|
|
23
25
|
}
|
|
24
26
|
ɵrunCraftAppInitializers(injector);
|
|
25
27
|
const root = injector.get(CRAFT_ROOT_COMPONENT);
|
|
@@ -36,7 +38,9 @@ export function hydrateCraft(options) {
|
|
|
36
38
|
(typeof ShadowRoot !== 'undefined' && rootNode instanceof ShadowRoot)
|
|
37
39
|
? rootNode
|
|
38
40
|
: host.ownerDocument;
|
|
39
|
-
const styles = injector.get(CRAFT_STYLE_REGISTRY,
|
|
41
|
+
const styles = injector.get(CRAFT_STYLE_REGISTRY, createCraftStyleRegistry({
|
|
42
|
+
nonce: injector.get(CraftCspNonce, null) ?? undefined,
|
|
43
|
+
}));
|
|
40
44
|
mounted = mountInterpretedComponentWithOptions(root, host, injector, (options.props ?? {}), {
|
|
41
45
|
renderer: createBrowserDomAdapter(host.ownerDocument),
|
|
42
46
|
mode: 'hydrate',
|
|
@@ -46,13 +50,23 @@ export function hydrateCraft(options) {
|
|
|
46
50
|
styleRoot,
|
|
47
51
|
styles,
|
|
48
52
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const finishHydration = () => {
|
|
54
|
+
cursor.finish();
|
|
55
|
+
platform.hydrating = false;
|
|
56
|
+
if (options.removeTransferScript !== false) {
|
|
57
|
+
host.ownerDocument.getElementById(CRAFT_TRANSFER_SCRIPT_ID)?.remove();
|
|
58
|
+
}
|
|
59
|
+
for (const style of host.ownerDocument.querySelectorAll('style[data-craft-ssr]')) {
|
|
60
|
+
style.remove();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
if (hydrationRuntime.hasPending()) {
|
|
64
|
+
void hydrationRuntime.whenSettled().then(() => {
|
|
65
|
+
queueMicrotask(finishHydration);
|
|
66
|
+
});
|
|
53
67
|
}
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
else {
|
|
69
|
+
finishHydration();
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
72
|
catch (error) {
|
|
@@ -70,10 +84,35 @@ export function hydrateCraft(options) {
|
|
|
70
84
|
},
|
|
71
85
|
};
|
|
72
86
|
}
|
|
87
|
+
function createHydrationRuntime() {
|
|
88
|
+
let pending = 0;
|
|
89
|
+
let waiters = [];
|
|
90
|
+
const settle = () => {
|
|
91
|
+
pending -= 1;
|
|
92
|
+
if (pending !== 0)
|
|
93
|
+
return;
|
|
94
|
+
const current = waiters;
|
|
95
|
+
waiters = [];
|
|
96
|
+
current.forEach((resolve) => resolve());
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
track(_source, work) {
|
|
100
|
+
pending += 1;
|
|
101
|
+
Promise.resolve(work).then(settle, settle);
|
|
102
|
+
},
|
|
103
|
+
hasPending() {
|
|
104
|
+
return pending > 0;
|
|
105
|
+
},
|
|
106
|
+
whenSettled() {
|
|
107
|
+
if (pending === 0)
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
73
113
|
function readTransferSnapshot(documentRef) {
|
|
74
114
|
const script = documentRef.getElementById(CRAFT_TRANSFER_SCRIPT_ID);
|
|
75
115
|
if (!script?.textContent)
|
|
76
116
|
return undefined;
|
|
77
117
|
return JSON.parse(script.textContent);
|
|
78
118
|
}
|
|
79
|
-
//# sourceMappingURL=hydrate.js.map
|
package/src/lib/hyperscript.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CraftNodeChildrenDependencies, CraftNodeChildrenCssVars, CraftNodeChildrenHandledExceptionCodes, CraftNodeChildren, ElementNode, RequireCaughtComponentExceptions } from './render/vnode';
|
|
1
|
+
import type { CraftNodeChildrenDependencies, CraftNodeChildrenCssVars, CraftNodeChildrenHandledExceptionCodes, CraftNodeChildren, ElementNode, RequireCaughtComponentExceptions } from './render/vnode.js';
|
|
2
2
|
import type { Yieldable } from '@craft-ts/core';
|
|
3
3
|
type ClassValueResult = string | null | undefined | false | readonly ClassValueResult[] | Readonly<Record<string, boolean | null | undefined>>;
|
|
4
4
|
/** Properties that can be supplied to a component's host element. */
|
|
@@ -145,4 +145,3 @@ export declare const area: RequiredAltTagHelper<"area">;
|
|
|
145
145
|
/** SVG is not an HTMLElement; the helper still produces a typed Craft element node. */
|
|
146
146
|
export declare const svg: TagHelper<keyof HTMLElementTagNameMap>;
|
|
147
147
|
export {};
|
|
148
|
-
//# sourceMappingURL=hyperscript.d.ts.map
|
package/src/lib/hyperscript.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pipeCraftNode } from './render/vnode';
|
|
1
|
+
import { pipeCraftNode } from './render/vnode.js';
|
|
2
2
|
function looksLikeChildren(value) {
|
|
3
3
|
return (value === null ||
|
|
4
4
|
value === undefined ||
|
|
@@ -93,4 +93,3 @@ export const iframe = tagHelper('iframe');
|
|
|
93
93
|
export const area = tagHelper('area');
|
|
94
94
|
/** SVG is not an HTMLElement; the helper still produces a typed Craft element node. */
|
|
95
95
|
export const svg = tagHelper('svg');
|
|
96
|
-
//# sourceMappingURL=hyperscript.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type NamedYieldableValue } from '@craft-ts/core';
|
|
2
|
+
import type { CraftNodeChildren, CraftNodeChildrenDependencies, IfNode } from './render/vnode.js';
|
|
3
|
+
type Condition<Name extends string> = NamedYieldableValue<Name, () => unknown>;
|
|
4
|
+
type BranchDependencies<Branch> = Branch extends (...args: any[]) => infer Output ? CraftNodeChildrenDependencies<Output> : {};
|
|
5
|
+
/** Creates a conditionally rendered Craft template block. */
|
|
6
|
+
export declare function ifNode<Name extends string, TrueBranch extends () => CraftNodeChildren, FalseBranch extends (() => CraftNodeChildren) | undefined = undefined>(condition: Condition<Name>, whenTrue: TrueBranch, whenFalse?: FalseBranch): IfNode<Name, BranchDependencies<TrueBranch> | BranchDependencies<FalseBranch>, ReturnType<TrueBranch>, FalseBranch extends (...args: any[]) => infer False ? False : never>;
|
|
7
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { YIELDABLE_VALUE } from '@craft-ts/core';
|
|
2
2
|
/** Creates a conditionally rendered Craft template block. */
|
|
3
|
-
export function
|
|
3
|
+
export function ifNode(condition, whenTrue, whenFalse) {
|
|
4
4
|
const conditionName = condition[YIELDABLE_VALUE];
|
|
5
5
|
if (typeof conditionName !== 'string') {
|
|
6
|
-
throw new Error('
|
|
6
|
+
throw new Error('ifNode(...) requires a named Craft reactive value as its condition.');
|
|
7
7
|
}
|
|
8
8
|
return {
|
|
9
9
|
kind: 'if',
|
|
@@ -13,4 +13,3 @@ export function ifBlock(condition, whenTrue, whenFalse) {
|
|
|
13
13
|
whenFalse: whenFalse,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
//# sourceMappingURL=if-block.js.map
|
package/src/lib/locator.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CraftComponent, ComponentTemplateOf } from './types';
|
|
1
|
+
import type { CraftComponent, ComponentTemplateOf } from './types.js';
|
|
2
2
|
import { YIELDABLE_VALUE } from '@craft-ts/core';
|
|
3
|
-
import type { CraftDirectiveNode, ElementNodeBase, CraftNodeChildren } from './render/vnode';
|
|
3
|
+
import type { CraftDirectiveNode, ElementNodeBase, CraftNodeChildren } from './render/vnode.js';
|
|
4
4
|
type IsAny<Value> = 0 extends 1 & Value ? true : false;
|
|
5
5
|
type LiteralString<Value> = Value extends string ? string extends Value ? never : Value : never;
|
|
6
6
|
type ClassTokens<Value> = [Value] extends [string] ? LiteralString<Value> extends infer Text extends string ? Text extends '' ? never : Text extends `${infer Head} ${infer Tail}` ? Head extends '' ? ClassTokens<Tail> : Head | ClassTokens<Tail> : Text : never : [Value] extends [readonly unknown[]] ? ClassTokens<Value[number]> : [Value] extends [Readonly<Record<string, boolean | null | undefined>>] ? string extends keyof Value ? never : Extract<keyof Value, string> : never;
|
|
@@ -53,7 +53,7 @@ type VisitContentNode<Node, Optional extends boolean, Repeated extends boolean,
|
|
|
53
53
|
...Depth,
|
|
54
54
|
unknown
|
|
55
55
|
]> : Node extends {
|
|
56
|
-
readonly kind: '
|
|
56
|
+
readonly kind: 'for';
|
|
57
57
|
readonly itemTemplate: (...args: any[]) => infer ItemChildren;
|
|
58
58
|
readonly empty?: () => infer EmptyChildren;
|
|
59
59
|
} ? VisitContentNode<ItemChildren | EmptyChildren, true, true, Seen, [
|
|
@@ -91,7 +91,7 @@ type VisitOptionalTag<Node, Tag extends keyof HTMLElementTagNameMap, Optional ex
|
|
|
91
91
|
...Depth,
|
|
92
92
|
unknown
|
|
93
93
|
]> : Node extends {
|
|
94
|
-
readonly kind: '
|
|
94
|
+
readonly kind: 'for';
|
|
95
95
|
readonly itemTemplate: (...args: any[]) => infer ItemChildren;
|
|
96
96
|
readonly empty?: () => infer EmptyChildren;
|
|
97
97
|
} ? VisitOptionalTag<ItemChildren | EmptyChildren, Tag, true, Seen, [
|
|
@@ -116,7 +116,7 @@ type VisitNode<Node, Depth extends readonly unknown[], Optional extends boolean,
|
|
|
116
116
|
readonly whenTrue: () => infer TrueChildren;
|
|
117
117
|
readonly whenFalse?: () => infer FalseChildren;
|
|
118
118
|
} ? VisitChildren<TrueChildren | FalseChildren, NextDepth<Depth>, true, Repeated, Seen> : Node extends {
|
|
119
|
-
readonly kind: '
|
|
119
|
+
readonly kind: 'for';
|
|
120
120
|
readonly itemTemplate: (...args: any[]) => infer ItemChildren;
|
|
121
121
|
readonly empty?: () => infer EmptyChildren;
|
|
122
122
|
} ? VisitChildren<ItemChildren | EmptyChildren, NextDepth<Depth>, true, true, Seen> : Node extends {
|
|
@@ -167,4 +167,3 @@ export declare const CRAFT_LOCATOR_CONTENT_NAMES: unique symbol;
|
|
|
167
167
|
export declare function directCraftContentNames(children: CraftNodeChildren): readonly string[];
|
|
168
168
|
export declare function findCraftTemplateLocator(host: Element, template: CraftNodeChildren, tag: string, criteria: RuntimeLocatorCriteria): Element | undefined;
|
|
169
169
|
export {};
|
|
170
|
-
//# sourceMappingURL=locator.d.ts.map
|
package/src/lib/locator.js
CHANGED
|
@@ -97,7 +97,7 @@ function runtimeTemplateMatches(children, tag, criteria, optional = false, repea
|
|
|
97
97
|
? runtimeTemplateMatches(node.whenFalse(), tag, criteria, true, repeated, seen)
|
|
98
98
|
: []));
|
|
99
99
|
break;
|
|
100
|
-
case '
|
|
100
|
+
case 'for':
|
|
101
101
|
matches.push(...runtimeTemplateMatches(node.itemTemplate(undefined, 0), tag, criteria, true, true, seen));
|
|
102
102
|
if (node.empty) {
|
|
103
103
|
matches.push(...runtimeTemplateMatches(node.empty(), tag, criteria, true, true, seen));
|
|
@@ -148,4 +148,3 @@ export function findCraftTemplateLocator(host, template, tag, criteria) {
|
|
|
148
148
|
}
|
|
149
149
|
return matches[0];
|
|
150
150
|
}
|
|
151
|
-
//# sourceMappingURL=locator.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { YieldableReactiveValue } from '@craft-ts/core';
|
|
2
|
-
import type { CraftNodeChildren, CraftNodeChildrenDependencies,
|
|
2
|
+
import type { CraftNodeChildren, CraftNodeChildrenDependencies, MatchNode } from './render/vnode.js';
|
|
3
3
|
type ExceptionCode<Value extends object, Key extends keyof Value> = Extract<Value[Key], string | number>;
|
|
4
4
|
type ExceptionHandlerMap<Value extends object, Key extends keyof Value> = {
|
|
5
5
|
[Code in ExceptionCode<Value, Key>]: (exception: Extract<Value, Record<Key, Code>>) => CraftNodeChildren;
|
|
6
6
|
};
|
|
7
|
-
type
|
|
7
|
+
type MatchDependencies<Handlers> = Handlers extends Record<string, (...args: any[]) => infer Output> ? CraftNodeChildrenDependencies<Output> : Record<never, never>;
|
|
8
8
|
type ExceptionKey<Value extends object> = {
|
|
9
9
|
[K in keyof Value]-?: Value[K] extends string | number ? K : never;
|
|
10
10
|
}[keyof Value];
|
|
@@ -19,20 +19,19 @@ type GeneratorSourceValue<Source> = Source extends (...args: any[]) => Generator
|
|
|
19
19
|
* discriminated-union matching without importing the component template
|
|
20
20
|
* layer into core's component primitives.
|
|
21
21
|
*/
|
|
22
|
-
declare function exhaustive<Source extends ((...args: any[]) => Generator<any, any, any>) | undefined, Value extends object = GeneratorSourceValue<Source>, Key extends ExceptionKey<Value> = ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key> = ExceptionHandlerMap<Value, Key>>(source: Source, key: Key, handlers: Handlers):
|
|
23
|
-
declare function exhaustive<Value extends object, Key extends ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key>>(source: YieldableReactiveValue<Value>, key: Key, handlers: Handlers):
|
|
24
|
-
declare function exhaustive<Value extends object, Key extends ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key>>(source: (() => Value | undefined) | Value, key: Key, handlers: Handlers):
|
|
25
|
-
declare function exhaustive<Value extends ScalarValue, Handlers extends ScalarHandlerMap<Value>>(source: YieldableReactiveValue<Value>, handlers: Handlers):
|
|
22
|
+
declare function exhaustive<Source extends ((...args: any[]) => Generator<any, any, any>) | undefined, Value extends object = GeneratorSourceValue<Source>, Key extends ExceptionKey<Value> = ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key> = ExceptionHandlerMap<Value, Key>>(source: Source, key: Key, handlers: Handlers): MatchNode<MatchDependencies<Handlers>, NonNullable<Source>, ReturnType<Handlers[ExceptionCode<Value, Key>]>, Extract<ExceptionCode<Value, Key>, string>>;
|
|
23
|
+
declare function exhaustive<Value extends object, Key extends ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key>>(source: YieldableReactiveValue<Value>, key: Key, handlers: Handlers): MatchNode<MatchDependencies<Handlers>, YieldableReactiveValue<Value>, ReturnType<Handlers[ExceptionCode<Value, Key>]>, Extract<ExceptionCode<Value, Key>, string>>;
|
|
24
|
+
declare function exhaustive<Value extends object, Key extends ExceptionKey<Value>, Handlers extends ExceptionHandlerMap<Value, Key>>(source: (() => Value | undefined) | Value, key: Key, handlers: Handlers): MatchNode<MatchDependencies<Handlers>, (() => Value | undefined) | Value, ReturnType<Handlers[ExceptionCode<Value, Key>]>, Extract<ExceptionCode<Value, Key>, string>>;
|
|
25
|
+
declare function exhaustive<Value extends ScalarValue, Handlers extends ScalarHandlerMap<Value>>(source: YieldableReactiveValue<Value>, handlers: Handlers): MatchNode<MatchDependencies<Handlers>, YieldableReactiveValue<{
|
|
26
26
|
value: Value;
|
|
27
27
|
}>, ReturnType<Handlers[Extract<Value, string | number>]>, Extract<Value, string>>;
|
|
28
|
-
declare function exhaustive<Value extends ScalarValue, Handlers extends ScalarHandlerMap<Value>>(source: (() => Value | Generator<unknown, Value, unknown>) | Value, handlers: Handlers):
|
|
28
|
+
declare function exhaustive<Value extends ScalarValue, Handlers extends ScalarHandlerMap<Value>>(source: (() => Value | Generator<unknown, Value, unknown>) | Value, handlers: Handlers): MatchNode<MatchDependencies<Handlers>, (() => {
|
|
29
29
|
value: Value;
|
|
30
30
|
}) | {
|
|
31
31
|
value: Value;
|
|
32
32
|
}, ReturnType<Handlers[Extract<Value, string | number>]>, Extract<Value, string>>;
|
|
33
33
|
/** Reactive template counterpart of discriminated-union matching. */
|
|
34
|
-
export declare const
|
|
34
|
+
export declare const matchNode: {
|
|
35
35
|
exhaustive: typeof exhaustive;
|
|
36
36
|
};
|
|
37
37
|
export {};
|
|
38
|
-
//# sourceMappingURL=match-block.d.ts.map
|
|
@@ -8,7 +8,7 @@ function exhaustive(source, keyOrHandlers, maybeHandlers) {
|
|
|
8
8
|
})
|
|
9
9
|
: { value: source };
|
|
10
10
|
return {
|
|
11
|
-
kind: 'match
|
|
11
|
+
kind: 'match',
|
|
12
12
|
source: scalarSource,
|
|
13
13
|
key: 'value',
|
|
14
14
|
handlers: Object.fromEntries(Object.entries(handlers).map(([code, handler]) => [
|
|
@@ -18,12 +18,11 @@ function exhaustive(source, keyOrHandlers, maybeHandlers) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
|
-
kind: 'match
|
|
21
|
+
kind: 'match',
|
|
22
22
|
source,
|
|
23
23
|
key: keyOrHandlers,
|
|
24
24
|
handlers: maybeHandlers,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
/** Reactive template counterpart of discriminated-union matching. */
|
|
28
|
-
export const
|
|
29
|
-
//# sourceMappingURL=match-block.js.map
|
|
28
|
+
export const matchNode = { exhaustive };
|