@taggor/component 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +67 -2
- package/assets.d.ts +35 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/assets.d.ts +26 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +14 -0
- package/dist/assets.js.map +1 -0
- package/dist/bounded-json.d.ts +21 -0
- package/dist/bounded-json.d.ts.map +1 -0
- package/dist/bounded-json.js +55 -0
- package/dist/bounded-json.js.map +1 -0
- package/dist/build/check-messages.d.ts +41 -0
- package/dist/build/check-messages.d.ts.map +1 -0
- package/dist/build/check-messages.js +142 -0
- package/dist/build/check-messages.js.map +1 -0
- package/dist/build/extract-manifest.d.ts +48 -0
- package/dist/build/extract-manifest.d.ts.map +1 -0
- package/dist/build/extract-manifest.js +81 -0
- package/dist/build/extract-manifest.js.map +1 -0
- package/dist/build/extract-styles.d.ts +36 -0
- package/dist/build/extract-styles.d.ts.map +1 -0
- package/dist/build/extract-styles.js +48 -0
- package/dist/build/extract-styles.js.map +1 -0
- package/dist/build/find-definition.d.ts +14 -0
- package/dist/build/find-definition.d.ts.map +1 -0
- package/dist/build/find-definition.js +23 -0
- package/dist/build/find-definition.js.map +1 -0
- package/dist/build/index.d.ts +10 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +10 -0
- package/dist/build/index.js.map +1 -0
- package/dist/consent.d.ts +100 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +147 -0
- package/dist/consent.js.map +1 -0
- package/dist/data-client.d.ts +34 -0
- package/dist/data-client.d.ts.map +1 -0
- package/dist/data-client.js +78 -0
- package/dist/data-client.js.map +1 -0
- package/dist/data-declaration.d.ts +59 -0
- package/dist/data-declaration.d.ts.map +1 -0
- package/dist/data-declaration.js +2 -0
- package/dist/data-declaration.js.map +1 -0
- package/dist/data-errors.d.ts +33 -0
- package/dist/data-errors.d.ts.map +1 -0
- package/dist/data-errors.js +73 -0
- package/dist/data-errors.js.map +1 -0
- package/dist/data-transport.d.ts +73 -0
- package/dist/data-transport.d.ts.map +1 -0
- package/dist/data-transport.js +2 -0
- package/dist/data-transport.js.map +1 -0
- package/dist/debug.d.ts +14 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +11 -0
- package/dist/debug.js.map +1 -0
- package/dist/define-component.d.ts +162 -0
- package/dist/define-component.d.ts.map +1 -0
- package/dist/define-component.js +79 -0
- package/dist/define-component.js.map +1 -0
- package/dist/define-library.d.ts +24 -0
- package/dist/define-library.d.ts.map +1 -0
- package/dist/define-library.js +24 -0
- package/dist/define-library.js.map +1 -0
- package/dist/edge-transport.d.ts +25 -0
- package/dist/edge-transport.d.ts.map +1 -0
- package/dist/edge-transport.js +94 -0
- package/dist/edge-transport.js.map +1 -0
- package/dist/events.d.ts +50 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/form-field.d.ts +59 -0
- package/dist/form-field.d.ts.map +1 -0
- package/dist/form-field.js +114 -0
- package/dist/form-field.js.map +1 -0
- package/dist/host.d.ts +45 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +30 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/intl-format.d.ts +37 -0
- package/dist/intl-format.d.ts.map +1 -0
- package/dist/intl-format.js +56 -0
- package/dist/intl-format.js.map +1 -0
- package/dist/issued-proofs.d.ts +19 -0
- package/dist/issued-proofs.d.ts.map +1 -0
- package/dist/issued-proofs.js +19 -0
- package/dist/issued-proofs.js.map +1 -0
- package/dist/locale.d.ts +28 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +62 -0
- package/dist/locale.js.map +1 -0
- package/dist/memory-transport.d.ts +39 -0
- package/dist/memory-transport.d.ts.map +1 -0
- package/dist/memory-transport.js +34 -0
- package/dist/memory-transport.js.map +1 -0
- package/dist/messages.d.ts +34 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +54 -0
- package/dist/messages.js.map +1 -0
- package/dist/none.d.ts +7 -0
- package/dist/none.d.ts.map +1 -0
- package/dist/none.js +6 -0
- package/dist/none.js.map +1 -0
- package/dist/props.d.ts +89 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +25 -0
- package/dist/props.js.map +1 -0
- package/dist/slots.d.ts +26 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +70 -0
- package/dist/slots.js.map +1 -0
- package/dist/submit-result.d.ts +19 -0
- package/dist/submit-result.d.ts.map +1 -0
- package/dist/submit-result.js +58 -0
- package/dist/submit-result.js.map +1 -0
- package/dist/testing/form-internals.d.ts +59 -0
- package/dist/testing/form-internals.d.ts.map +1 -0
- package/dist/testing/form-internals.js +150 -0
- package/dist/testing/form-internals.js.map +1 -0
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +14 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mount-component.d.ts +105 -0
- package/dist/testing/mount-component.d.ts.map +1 -0
- package/dist/testing/mount-component.js +270 -0
- package/dist/testing/mount-component.js.map +1 -0
- package/dist/testing/visitor.d.ts +23 -0
- package/dist/testing/visitor.d.ts.map +1 -0
- package/dist/testing/visitor.js +34 -0
- package/dist/testing/visitor.js.map +1 -0
- package/dist/theming.d.ts +42 -0
- package/dist/theming.d.ts.map +1 -0
- package/dist/theming.js +19 -0
- package/dist/theming.js.map +1 -0
- package/dist/turnstile.d.ts +60 -0
- package/dist/turnstile.d.ts.map +1 -0
- package/dist/turnstile.js +179 -0
- package/dist/turnstile.js.map +1 -0
- package/dist/use-font.d.ts +65 -0
- package/dist/use-font.d.ts.map +1 -0
- package/dist/use-font.js +145 -0
- package/dist/use-font.js.map +1 -0
- package/dist/use-locale.d.ts +46 -0
- package/dist/use-locale.d.ts.map +1 -0
- package/dist/use-locale.js +57 -0
- package/dist/use-locale.js.map +1 -0
- package/dist/use-taggor-data.d.ts +72 -0
- package/dist/use-taggor-data.d.ts.map +1 -0
- package/dist/use-taggor-data.js +179 -0
- package/dist/use-taggor-data.js.map +1 -0
- package/dist/use-track.d.ts +17 -0
- package/dist/use-track.d.ts.map +1 -0
- package/dist/use-track.js +64 -0
- package/dist/use-track.js.map +1 -0
- package/dist/value-types.d.ts +69 -0
- package/dist/value-types.d.ts.map +1 -0
- package/dist/value-types.js +15 -0
- package/dist/value-types.js.map +1 -0
- package/dist/visitor-action.d.ts +49 -0
- package/dist/visitor-action.d.ts.map +1 -0
- package/dist/visitor-action.js +77 -0
- package/dist/visitor-action.js.map +1 -0
- package/package.json +71 -3
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prop declarations for authors (TAG-202): the `prop.<type>(options)` builders and `PropsOf`, the
|
|
3
|
+
* type `render` receives. The declaration is the contract's own `PropDeclaration` (the nine types
|
|
4
|
+
* of `propTypeCatalog`, TAG-205), written as plain data: a builder only adds `type`, so what the
|
|
5
|
+
* author writes is exactly what lands in the manifest and what the runtime coerces with.
|
|
6
|
+
*
|
|
7
|
+
* Why the types cannot diverge from the runtime: `PropsOf` reads the value type from the
|
|
8
|
+
* declaration (`PropValueTypes` of the contract, narrowed by `ValueOf` for `enum`, `array` and
|
|
9
|
+
* `object`, which is what `checkValue` accepts), and a prop is `T | undefined` unless it declares a
|
|
10
|
+
* `default`, because the runtime falls back to `default` (possibly absent) whenever an attribute
|
|
11
|
+
* is missing or invalid (`attributeToValue`, `propertyToValue`).
|
|
12
|
+
*
|
|
13
|
+
* TAG-227: every value is `DeepReadonly`, because the runtime freezes the props in depth before
|
|
14
|
+
* `render` sees them (TAG-304); copy before sorting or changing (`[...props.items].sort()`).
|
|
15
|
+
*/
|
|
16
|
+
import type { PropDeclarationOf, PropType, PropValueTypes } from "@taggor/contract/zod-free";
|
|
17
|
+
import type { DeepReadonly, ValueOf } from "./value-types.js";
|
|
18
|
+
/** The options of a prop of type `T`: its declaration without `type`. */
|
|
19
|
+
export type PropOptions<T extends PropType> = Omit<PropDeclarationOf<T>, "type">;
|
|
20
|
+
/** A declared prop: any declaration of the contract, as written by the author. */
|
|
21
|
+
export type AnyPropDeclaration = {
|
|
22
|
+
readonly [T in PropType]: PropDeclarationOf<T>;
|
|
23
|
+
}[PropType];
|
|
24
|
+
/** The `props` map of a component: prop name → declaration. */
|
|
25
|
+
export type PropsDeclaration = Readonly<Record<string, AnyPropDeclaration>>;
|
|
26
|
+
/** The value type of one declaration, before the `undefined` of a missing default. */
|
|
27
|
+
type DeclaredValue<D> = D extends {
|
|
28
|
+
readonly type: "enum" | "array" | "object";
|
|
29
|
+
} ? ValueOf<D> : D extends {
|
|
30
|
+
readonly type: infer T extends PropType;
|
|
31
|
+
} ? PropValueTypes[T] : never;
|
|
32
|
+
/** True when the declaration has a `default` the runtime can fall back to. */
|
|
33
|
+
type HasDefault<D> = D extends {
|
|
34
|
+
readonly default: infer Default;
|
|
35
|
+
} ? undefined extends Default ? false : true : false;
|
|
36
|
+
/**
|
|
37
|
+
* The value `render` receives for one declaration: read-only in depth (the runtime deep-freezes
|
|
38
|
+
* props, TAG-304), and `| undefined` when there is no `default`.
|
|
39
|
+
*/
|
|
40
|
+
export type PropValueOf<D> = DeepReadonly<HasDefault<D> extends true ? DeclaredValue<D> : DeclaredValue<D> | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* The props object `render` receives: every declared prop, typed from its declaration
|
|
43
|
+
* (`prop.number({ default: 1.2 })` → `number`; without a default → `number | undefined`), and
|
|
44
|
+
* read-only at every level (`prop.array` → `readonly T[]`, `prop.object` → readonly fields),
|
|
45
|
+
* since the runtime hands them over deep-frozen (TAG-304, TAG-227).
|
|
46
|
+
*/
|
|
47
|
+
export type PropsOf<P> = {
|
|
48
|
+
readonly [K in keyof P]: PropValueOf<P[K]>;
|
|
49
|
+
};
|
|
50
|
+
/** A builder: options in, the same options plus `type` out. */
|
|
51
|
+
type Builder<T extends PropType> = <const O extends PropOptions<T>>(options?: O) => O & {
|
|
52
|
+
readonly type: T;
|
|
53
|
+
};
|
|
54
|
+
/** Same as `Builder`, for the types whose options have required members (`enum`, `array`…). */
|
|
55
|
+
type RequiredBuilder<T extends PropType> = <const O extends PropOptions<T>>(options: O) => O & {
|
|
56
|
+
readonly type: T;
|
|
57
|
+
};
|
|
58
|
+
/** Enum options whose `default` must be one of the declared `values` (checked by the compiler). */
|
|
59
|
+
type EnumBuilder = <const O extends PropOptions<"enum">>(options: O & {
|
|
60
|
+
readonly default?: O["values"][number];
|
|
61
|
+
}) => O & {
|
|
62
|
+
readonly type: "enum";
|
|
63
|
+
};
|
|
64
|
+
/** Boolean props default to `false` (the only default the contract allows), so they are `boolean`. */
|
|
65
|
+
type BooleanBuilder = <const O extends PropOptions<"boolean">>(options?: O) => {
|
|
66
|
+
readonly type: "boolean";
|
|
67
|
+
readonly default: false;
|
|
68
|
+
} & O;
|
|
69
|
+
/**
|
|
70
|
+
* The prop builders, one per prop type of the contract.
|
|
71
|
+
*
|
|
72
|
+
* Inputs: the declaration options of that type (`min`, `max`, `default`, `values`, `items`…).
|
|
73
|
+
* Output: a fresh plain object `{ ...options, type }`; `prop.boolean()` also sets
|
|
74
|
+
* `default: false`. Errors: none at runtime; wrong options are compile errors here and manifest
|
|
75
|
+
* issues in `extractManifest` (the builder's check). Side effects: none.
|
|
76
|
+
*/
|
|
77
|
+
export declare const prop: {
|
|
78
|
+
readonly string: Builder<"string">;
|
|
79
|
+
readonly number: Builder<"number">;
|
|
80
|
+
readonly boolean: BooleanBuilder;
|
|
81
|
+
readonly enum: EnumBuilder;
|
|
82
|
+
readonly color: Builder<"color">;
|
|
83
|
+
readonly url: Builder<"url">;
|
|
84
|
+
readonly date: Builder<"date">;
|
|
85
|
+
readonly array: RequiredBuilder<"array">;
|
|
86
|
+
readonly object: RequiredBuilder<"object">;
|
|
87
|
+
};
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../src/props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE7F,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE9D,yEAAyE;AACzE,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEjF,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,QAAQ,GAAG,iBAAiB,CAAC,CAAC,CAAC;CAAE,CAAC,QAAQ,CAAC,CAAC;AAE9F,+DAA+D;AAC/D,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE5E,sFAAsF;AACtF,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;CAAE,GAC5E,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,QAAQ,CAAA;CAAE,GACnD,cAAc,CAAC,CAAC,CAAC,GACjB,KAAK,CAAC;AAEZ,8EAA8E;AAC9E,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,GAC9D,SAAS,SAAS,OAAO,GAC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E,CAAC,KACR;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GAAG,CAAC,CAAC;AAM/D;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,EAAE;IACjB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CAanC,CAAC"}
|
package/dist/props.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function builder(type, defaults) {
|
|
2
|
+
return (options) => ({ ...defaults, ...options, type });
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* The prop builders, one per prop type of the contract.
|
|
6
|
+
*
|
|
7
|
+
* Inputs: the declaration options of that type (`min`, `max`, `default`, `values`, `items`…).
|
|
8
|
+
* Output: a fresh plain object `{ ...options, type }`; `prop.boolean()` also sets
|
|
9
|
+
* `default: false`. Errors: none at runtime; wrong options are compile errors here and manifest
|
|
10
|
+
* issues in `extractManifest` (the builder's check). Side effects: none.
|
|
11
|
+
*/
|
|
12
|
+
export const prop = {
|
|
13
|
+
string: builder("string"),
|
|
14
|
+
number: builder("number"),
|
|
15
|
+
boolean: builder("boolean", { default: false }),
|
|
16
|
+
enum: builder("enum"),
|
|
17
|
+
color: builder("color"),
|
|
18
|
+
url: builder("url"),
|
|
19
|
+
date: builder("date"),
|
|
20
|
+
array: builder("array"),
|
|
21
|
+
object: builder("object"),
|
|
22
|
+
// The generic signatures above are what callers see; one untyped spread implements all of them,
|
|
23
|
+
// which keeps the SDK a few bytes per type instead of nine copies.
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../src/props.ts"],"names":[],"mappings":"AA8EA,SAAS,OAAO,CAAqB,IAAO,EAAE,QAAiB;IAC7D,OAAO,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAUb;IACF,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC/C,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;IACvB,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC;IACzB,gGAAgG;IAChG,mEAAmE;CAC3D,CAAC"}
|
package/dist/slots.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The manifest's name for the unnamed slot: the children without a `slot` attribute. */
|
|
2
|
+
export declare const DEFAULT_SLOT = "default";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the light DOM of `element` assigns anything to the slot `name`, by the native rule: an
|
|
5
|
+
* element child goes to the slot named by its `slot` attribute (absent or empty means the unnamed
|
|
6
|
+
* slot); a text child goes to the unnamed slot and counts only if it is not whitespace.
|
|
7
|
+
*
|
|
8
|
+
* Inputs: the host element and a slot name from the manifest (`"default"` is the unnamed slot).
|
|
9
|
+
* Output: a boolean. Errors: none. Side effects: none (reads `childNodes` only).
|
|
10
|
+
*/
|
|
11
|
+
export declare function slotHasContent(element: Element, name: string): boolean;
|
|
12
|
+
/** What `useSlot` reports about one slot. */
|
|
13
|
+
export interface SlotState {
|
|
14
|
+
/** True when the page assigned at least one node to the slot. */
|
|
15
|
+
readonly hasContent: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Tracks whether the slot `name` has content, updating when the page adds, removes or re-slots
|
|
19
|
+
* light DOM children.
|
|
20
|
+
*
|
|
21
|
+
* Inputs: a slot name declared in the manifest's `slots` (`"default"` for the unnamed slot).
|
|
22
|
+
* Output: `{ hasContent }`. Errors: as `useHost` outside a mounted component. Side effects: observes
|
|
23
|
+
* the host element's light DOM with a `MutationObserver`, disconnected on unmount or name change.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useSlot(name: string): SlotState;
|
|
26
|
+
//# sourceMappingURL=slots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../src/slots.ts"],"names":[],"mappings":"AAYA,yFAAyF;AACzF,eAAO,MAAM,YAAY,YAAY,CAAC;AAStC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAUtE;AAED,6CAA6C;AAC7C,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAqB/C"}
|
package/dist/slots.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slots for authors (TAG-202): `useSlot(name)` says whether the page put content into a slot, so a
|
|
3
|
+
* component can render its own fallback (a default title) only when the slot is empty.
|
|
4
|
+
*
|
|
5
|
+
* Content is never copied: the component renders a native `<slot name="…">` and the browser projects
|
|
6
|
+
* the light DOM nodes (TAG-306). This module only reads the host element's children; it never
|
|
7
|
+
* reads or writes HTML (golden rule 5).
|
|
8
|
+
*/
|
|
9
|
+
import { useEffect, useState } from "preact/hooks";
|
|
10
|
+
import { useHost } from "./host.js";
|
|
11
|
+
/** The manifest's name for the unnamed slot: the children without a `slot` attribute. */
|
|
12
|
+
export const DEFAULT_SLOT = "default";
|
|
13
|
+
// Node.ELEMENT_NODE and Node.TEXT_NODE, inlined so the module needs no `Node` global.
|
|
14
|
+
const ELEMENT_NODE = 1;
|
|
15
|
+
const TEXT_NODE = 3;
|
|
16
|
+
/** Whitespace-only text between tags is not content. */
|
|
17
|
+
const HAS_TEXT = /\S/;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the light DOM of `element` assigns anything to the slot `name`, by the native rule: an
|
|
20
|
+
* element child goes to the slot named by its `slot` attribute (absent or empty means the unnamed
|
|
21
|
+
* slot); a text child goes to the unnamed slot and counts only if it is not whitespace.
|
|
22
|
+
*
|
|
23
|
+
* Inputs: the host element and a slot name from the manifest (`"default"` is the unnamed slot).
|
|
24
|
+
* Output: a boolean. Errors: none. Side effects: none (reads `childNodes` only).
|
|
25
|
+
*/
|
|
26
|
+
export function slotHasContent(element, name) {
|
|
27
|
+
const wanted = name === DEFAULT_SLOT ? "" : name;
|
|
28
|
+
for (const node of element.childNodes) {
|
|
29
|
+
if (node.nodeType === ELEMENT_NODE) {
|
|
30
|
+
if ((node.getAttribute("slot") ?? "") === wanted)
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
else if (node.nodeType === TEXT_NODE && wanted === "") {
|
|
34
|
+
if (HAS_TEXT.test(node.textContent ?? ""))
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Tracks whether the slot `name` has content, updating when the page adds, removes or re-slots
|
|
42
|
+
* light DOM children.
|
|
43
|
+
*
|
|
44
|
+
* Inputs: a slot name declared in the manifest's `slots` (`"default"` for the unnamed slot).
|
|
45
|
+
* Output: `{ hasContent }`. Errors: as `useHost` outside a mounted component. Side effects: observes
|
|
46
|
+
* the host element's light DOM with a `MutationObserver`, disconnected on unmount or name change.
|
|
47
|
+
*/
|
|
48
|
+
export function useSlot(name) {
|
|
49
|
+
const { element } = useHost();
|
|
50
|
+
const [hasContent, setHasContent] = useState(() => slotHasContent(element, name));
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const update = () => {
|
|
53
|
+
setHasContent(slotHasContent(element, name));
|
|
54
|
+
};
|
|
55
|
+
update();
|
|
56
|
+
const observer = new MutationObserver(update);
|
|
57
|
+
// subtree + characterData: a direct text child edited in place changes the default slot.
|
|
58
|
+
observer.observe(element, {
|
|
59
|
+
childList: true,
|
|
60
|
+
subtree: true,
|
|
61
|
+
characterData: true,
|
|
62
|
+
attributeFilter: ["slot"],
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
observer.disconnect();
|
|
66
|
+
};
|
|
67
|
+
}, [element, name]);
|
|
68
|
+
return { hasContent };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=slots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.js","sourceRoot":"","sources":["../src/slots.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;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AC,MAAM,CAAC,CAAC;QAC9C,yFAAyF;QACzF,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE;YACxB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;YACb,aAAa,EAAE,IAAI;YACnB,eAAe,EAAE,CAAC,MAAM,CAAC;SAC1B,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SubmitResult } from "./data-transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reads a data API error body.
|
|
4
|
+
*
|
|
5
|
+
* Inputs: any value (parsed JSON, untrusted). Output: a failed `SubmitResult` with the known
|
|
6
|
+
* `code` and its well-formed `fields` (at most `maxErrorFields`, strings capped), or
|
|
7
|
+
* `network_error` when the value is not a data API error (unknown or missing `code`). Errors:
|
|
8
|
+
* none. Side effects: none.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readDataError(body: unknown): SubmitResult;
|
|
11
|
+
/**
|
|
12
|
+
* Normalizes what a transport resolved to.
|
|
13
|
+
*
|
|
14
|
+
* Inputs: any value (a transport may break its contract: `undefined`, no `ok`, no `fields`, an
|
|
15
|
+
* unknown `code`). Output: `{ ok: true }` only for `ok === true`; otherwise `readDataError` of it.
|
|
16
|
+
* Errors: none. Side effects: none.
|
|
17
|
+
*/
|
|
18
|
+
export declare function normalizeSubmitResult(result: unknown): SubmitResult;
|
|
19
|
+
//# sourceMappingURL=submit-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-result.d.ts","sourceRoot":"","sources":["../src/submit-result.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AActE;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAezD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKnE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading untrusted submit results (TAG-203): the edge's error body and whatever a transport
|
|
3
|
+
* resolves to both pass through here before the hook trusts them, so a malformed answer becomes
|
|
4
|
+
* `network_error` instead of an exception on the visitor's page (golden rule 2).
|
|
5
|
+
*/
|
|
6
|
+
import { DATA_API_LIMITS } from "@taggor/contract/zod-free";
|
|
7
|
+
import { isSubmitErrorCode } from "./data-errors.js";
|
|
8
|
+
const NETWORK_ERROR = Object.freeze({
|
|
9
|
+
ok: false,
|
|
10
|
+
code: "network_error",
|
|
11
|
+
fields: Object.freeze([]),
|
|
12
|
+
});
|
|
13
|
+
const ACCEPTED = Object.freeze({ ok: true });
|
|
14
|
+
/** A server string, cut to the contract's limit so a hostile answer cannot flood the component. */
|
|
15
|
+
function bounded(value) {
|
|
16
|
+
return value.slice(0, DATA_API_LIMITS.errorMessageMaxLength);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads a data API error body.
|
|
20
|
+
*
|
|
21
|
+
* Inputs: any value (parsed JSON, untrusted). Output: a failed `SubmitResult` with the known
|
|
22
|
+
* `code` and its well-formed `fields` (at most `maxErrorFields`, strings capped), or
|
|
23
|
+
* `network_error` when the value is not a data API error (unknown or missing `code`). Errors:
|
|
24
|
+
* none. Side effects: none.
|
|
25
|
+
*/
|
|
26
|
+
export function readDataError(body) {
|
|
27
|
+
if (typeof body !== "object" || body === null)
|
|
28
|
+
return NETWORK_ERROR;
|
|
29
|
+
const { code, fields } = body;
|
|
30
|
+
if (!isSubmitErrorCode(code))
|
|
31
|
+
return NETWORK_ERROR;
|
|
32
|
+
const problems = [];
|
|
33
|
+
if (Array.isArray(fields)) {
|
|
34
|
+
for (const field of fields.slice(0, DATA_API_LIMITS.maxErrorFields)) {
|
|
35
|
+
if (typeof field !== "object" || field === null)
|
|
36
|
+
continue;
|
|
37
|
+
const { path, message } = field;
|
|
38
|
+
if (typeof path === "string" && typeof message === "string") {
|
|
39
|
+
problems.push({ path: bounded(path), message: bounded(message) });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { ok: false, code, fields: problems };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Normalizes what a transport resolved to.
|
|
47
|
+
*
|
|
48
|
+
* Inputs: any value (a transport may break its contract: `undefined`, no `ok`, no `fields`, an
|
|
49
|
+
* unknown `code`). Output: `{ ok: true }` only for `ok === true`; otherwise `readDataError` of it.
|
|
50
|
+
* Errors: none. Side effects: none.
|
|
51
|
+
*/
|
|
52
|
+
export function normalizeSubmitResult(result) {
|
|
53
|
+
if (typeof result === "object" && result !== null && result.ok === true) {
|
|
54
|
+
return ACCEPTED;
|
|
55
|
+
}
|
|
56
|
+
return readDataError(result);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=submit-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-result.js","sourceRoot":"","sources":["../src/submit-result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,aAAa,GAAiB,MAAM,CAAC,MAAM,CAAC;IAChD,EAAE,EAAE,KAAK;IACT,IAAI,EAAE,eAAe;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC1B,CAAC,CAAC;AACH,MAAM,QAAQ,GAAiB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3D,mGAAmG;AACnG,SAAS,OAAO,CAAC,KA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QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recording `ElementInternals` for `mountComponent` (TAG-235): happy-dom has no `attachInternals`, so
|
|
3
|
+
* a form field component (`formAssociated: true`, TAG-314) mounted in an author's test got no
|
|
4
|
+
* `host.internals`, and `useFormField` recorded nothing. This module gives the component's own element
|
|
5
|
+
* class an `attachInternals` that returns internals which keep what the component set (the form value,
|
|
6
|
+
* the validity flags, the message and its anchor), so the test can read them back, which real
|
|
7
|
+
* internals never allow for the value.
|
|
8
|
+
*
|
|
9
|
+
* The fake follows the browser where the SDK depends on it: `setValidity` throws a `TypeError` for
|
|
10
|
+
* a flag without a message and a `NotFoundError` for an anchor outside the element (`useFormField`
|
|
11
|
+
* falls back to no anchor), a second `attachInternals` throws (`NotSupportedError`), `form` is the
|
|
12
|
+
* `form` attribute's target or the closest `<form>`, and `labels` are the `<label for>` of the
|
|
13
|
+
* element's id and a wrapping `<label>` without `for`. It does not make the page's `<form>` see the
|
|
14
|
+
* value (`new FormData(form)` in happy-dom leaves the element out): the runtime's `forms.e2e.ts`
|
|
15
|
+
* proves the real submission in Chromium.
|
|
16
|
+
*
|
|
17
|
+
* Test-only: reached from `@taggor/component/testing` alone, never from a component bundle.
|
|
18
|
+
*/
|
|
19
|
+
/** Every flag of a `ValidityState`, all `false` until the component sets them. */
|
|
20
|
+
declare const VALIDITY_FLAGS: readonly ["badInput", "customError", "patternMismatch", "rangeOverflow", "rangeUnderflow", "stepMismatch", "tooLong", "tooShort", "typeMismatch", "valueMissing"];
|
|
21
|
+
/** A validity flag `setValidity` accepts. */
|
|
22
|
+
type ValidityFlag = (typeof VALIDITY_FLAGS)[number];
|
|
23
|
+
/** The validity a form field set: each flag, and `valid` when none is set. */
|
|
24
|
+
export type FormFieldValidity = {
|
|
25
|
+
readonly [K in ValidityFlag]: boolean;
|
|
26
|
+
} & {
|
|
27
|
+
readonly valid: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** What a form field component set on its internals, read by `MountedComponent.form`. */
|
|
30
|
+
export interface FormFieldRecord {
|
|
31
|
+
/** The last value given to `setFormValue` (`null` until then, as in a browser: nothing sent). */
|
|
32
|
+
readonly value: string | File | FormData | null;
|
|
33
|
+
/** The validity flags of the last `setValidity`; valid until the component sets a flag. */
|
|
34
|
+
readonly validity: FormFieldValidity;
|
|
35
|
+
/** The message of the last `setValidity`; `""` while valid. */
|
|
36
|
+
readonly validationMessage: string;
|
|
37
|
+
/** Where the browser would show the message and put the focus; `undefined`: the element. */
|
|
38
|
+
readonly anchor: HTMLElement | undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What `element`'s component set on its internals so far.
|
|
42
|
+
*
|
|
43
|
+
* Inputs: an element whose class went through `installFormInternals`. Output: a frozen
|
|
44
|
+
* `FormFieldRecord` (a snapshot, read again for later changes), or `undefined` when the element
|
|
45
|
+
* never attached internals (not a form field). Errors: none. Side effects: none.
|
|
46
|
+
*/
|
|
47
|
+
export declare function readFormField(element: Element): FormFieldRecord | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Gives a form field's element class (and only it) the recording `attachInternals`, in place of
|
|
50
|
+
* whatever the environment has, so the record is the same with or without real internals.
|
|
51
|
+
*
|
|
52
|
+
* Inputs: the class `customElements.get(tag)` returned for a component whose manifest declares
|
|
53
|
+
* `formAssociated: true`. Output: none. Errors: none. Side effects: defines `attachInternals` on
|
|
54
|
+
* that class's prototype; each element's first call returns new recording internals, a second
|
|
55
|
+
* call throws a `NotSupportedError` `DOMException`, as in a browser.
|
|
56
|
+
*/
|
|
57
|
+
export declare function installFormInternals(elementClass: CustomElementConstructor): void;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=form-internals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-internals.d.ts","sourceRoot":"","sources":["../../src/testing/form-internals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,kFAAkF;AAClF,QAAA,MAAM,cAAc,mKAWV,CAAC;AAEX,6CAA6C;AAC7C,KAAK,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpD,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,YAAY,GAAG,OAAO;CAAE,GAAG;IAC1E,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,yFAAyF;AACzF,MAAM,WAAW,eAAe;IAC9B,iGAAiG;IACjG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,CAAC;IAChD,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,+DAA+D;IAC/D,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;CAC1C;AAKD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,wBAAwB,GAAG,IAAI,CAWjF"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recording `ElementInternals` for `mountComponent` (TAG-235): happy-dom has no `attachInternals`, so
|
|
3
|
+
* a form field component (`formAssociated: true`, TAG-314) mounted in an author's test got no
|
|
4
|
+
* `host.internals`, and `useFormField` recorded nothing. This module gives the component's own element
|
|
5
|
+
* class an `attachInternals` that returns internals which keep what the component set (the form value,
|
|
6
|
+
* the validity flags, the message and its anchor), so the test can read them back, which real
|
|
7
|
+
* internals never allow for the value.
|
|
8
|
+
*
|
|
9
|
+
* The fake follows the browser where the SDK depends on it: `setValidity` throws a `TypeError` for
|
|
10
|
+
* a flag without a message and a `NotFoundError` for an anchor outside the element (`useFormField`
|
|
11
|
+
* falls back to no anchor), a second `attachInternals` throws (`NotSupportedError`), `form` is the
|
|
12
|
+
* `form` attribute's target or the closest `<form>`, and `labels` are the `<label for>` of the
|
|
13
|
+
* element's id and a wrapping `<label>` without `for`. It does not make the page's `<form>` see the
|
|
14
|
+
* value (`new FormData(form)` in happy-dom leaves the element out): the runtime's `forms.e2e.ts`
|
|
15
|
+
* proves the real submission in Chromium.
|
|
16
|
+
*
|
|
17
|
+
* Test-only: reached from `@taggor/component/testing` alone, never from a component bundle.
|
|
18
|
+
*/
|
|
19
|
+
/** Every flag of a `ValidityState`, all `false` until the component sets them. */
|
|
20
|
+
const VALIDITY_FLAGS = [
|
|
21
|
+
"badInput",
|
|
22
|
+
"customError",
|
|
23
|
+
"patternMismatch",
|
|
24
|
+
"rangeOverflow",
|
|
25
|
+
"rangeUnderflow",
|
|
26
|
+
"stepMismatch",
|
|
27
|
+
"tooLong",
|
|
28
|
+
"tooShort",
|
|
29
|
+
"typeMismatch",
|
|
30
|
+
"valueMissing",
|
|
31
|
+
];
|
|
32
|
+
/** The recorder of each element whose internals this module attached. */
|
|
33
|
+
const records = new WeakMap();
|
|
34
|
+
/**
|
|
35
|
+
* What `element`'s component set on its internals so far.
|
|
36
|
+
*
|
|
37
|
+
* Inputs: an element whose class went through `installFormInternals`. Output: a frozen
|
|
38
|
+
* `FormFieldRecord` (a snapshot, read again for later changes), or `undefined` when the element
|
|
39
|
+
* never attached internals (not a form field). Errors: none. Side effects: none.
|
|
40
|
+
*/
|
|
41
|
+
export function readFormField(element) {
|
|
42
|
+
return records.get(element)?.();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gives a form field's element class (and only it) the recording `attachInternals`, in place of
|
|
46
|
+
* whatever the environment has, so the record is the same with or without real internals.
|
|
47
|
+
*
|
|
48
|
+
* Inputs: the class `customElements.get(tag)` returned for a component whose manifest declares
|
|
49
|
+
* `formAssociated: true`. Output: none. Errors: none. Side effects: defines `attachInternals` on
|
|
50
|
+
* that class's prototype; each element's first call returns new recording internals, a second
|
|
51
|
+
* call throws a `NotSupportedError` `DOMException`, as in a browser.
|
|
52
|
+
*/
|
|
53
|
+
export function installFormInternals(elementClass) {
|
|
54
|
+
Object.defineProperty(elementClass.prototype, "attachInternals", {
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: function attachInternals() {
|
|
58
|
+
if (records.has(this)) {
|
|
59
|
+
throw new DOMException("internals were already attached", "NotSupportedError");
|
|
60
|
+
}
|
|
61
|
+
return createRecordingInternals(this);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function validityOf(flags) {
|
|
66
|
+
const entries = VALIDITY_FLAGS.map((flag) => [flag, flags[flag] === true]);
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
...Object.fromEntries(entries),
|
|
69
|
+
valid: entries.every(([, set]) => !set),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Whether `node` is `element` or inside it, shadow roots included (the browser's anchor rule). */
|
|
73
|
+
function isShadowIncludingInclusiveDescendant(node, element) {
|
|
74
|
+
let current = node;
|
|
75
|
+
while (current !== null) {
|
|
76
|
+
if (current === element)
|
|
77
|
+
return true;
|
|
78
|
+
const root = current.getRootNode();
|
|
79
|
+
current = current.parentNode ?? (root instanceof ShadowRoot ? root.host : null);
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
function formOf(element) {
|
|
84
|
+
const id = element.getAttribute("form");
|
|
85
|
+
if (id === null)
|
|
86
|
+
return element.closest("form");
|
|
87
|
+
const target = element.getRootNode().getElementById(id);
|
|
88
|
+
return target instanceof HTMLFormElement ? target : null;
|
|
89
|
+
}
|
|
90
|
+
function labelsOf(element) {
|
|
91
|
+
const tree = element.getRootNode();
|
|
92
|
+
const byFor = element.id === ""
|
|
93
|
+
? []
|
|
94
|
+
: [...tree.querySelectorAll("label")].filter((label) => label.htmlFor === element.id);
|
|
95
|
+
const wrapping = element.parentElement?.closest("label");
|
|
96
|
+
const extra = wrapping !== null && wrapping !== undefined && !wrapping.hasAttribute("for") ? [wrapping] : [];
|
|
97
|
+
return [...byFor, ...extra.filter((label) => !byFor.includes(label))];
|
|
98
|
+
}
|
|
99
|
+
function createRecordingInternals(element) {
|
|
100
|
+
let value = null;
|
|
101
|
+
let validity = validityOf({});
|
|
102
|
+
let validationMessage = "";
|
|
103
|
+
let anchor;
|
|
104
|
+
records.set(element, () => Object.freeze({ value, validity, validationMessage, anchor }));
|
|
105
|
+
const check = () => {
|
|
106
|
+
if (!validity.valid)
|
|
107
|
+
element.dispatchEvent(new Event("invalid", { cancelable: true }));
|
|
108
|
+
return validity.valid;
|
|
109
|
+
};
|
|
110
|
+
// Only the members a form field uses; the cast covers the ARIA mixin and `states`.
|
|
111
|
+
const internals = {
|
|
112
|
+
setFormValue(next) {
|
|
113
|
+
value = next;
|
|
114
|
+
},
|
|
115
|
+
setValidity(flags = {}, message, target) {
|
|
116
|
+
const next = validityOf(flags);
|
|
117
|
+
if (!next.valid && (message === undefined || message === "")) {
|
|
118
|
+
throw new TypeError("setValidity: a validity flag needs a message");
|
|
119
|
+
}
|
|
120
|
+
if (target !== undefined && !isShadowIncludingInclusiveDescendant(target, element)) {
|
|
121
|
+
throw new DOMException("the anchor is not inside the element", "NotFoundError");
|
|
122
|
+
}
|
|
123
|
+
validity = next;
|
|
124
|
+
validationMessage = next.valid ? "" : (message ?? "");
|
|
125
|
+
anchor = next.valid ? undefined : target;
|
|
126
|
+
},
|
|
127
|
+
get validity() {
|
|
128
|
+
return validity;
|
|
129
|
+
},
|
|
130
|
+
get validationMessage() {
|
|
131
|
+
return validationMessage;
|
|
132
|
+
},
|
|
133
|
+
get willValidate() {
|
|
134
|
+
return !element.hasAttribute("disabled");
|
|
135
|
+
},
|
|
136
|
+
get form() {
|
|
137
|
+
return formOf(element);
|
|
138
|
+
},
|
|
139
|
+
get labels() {
|
|
140
|
+
return labelsOf(element);
|
|
141
|
+
},
|
|
142
|
+
get shadowRoot() {
|
|
143
|
+
return element.shadowRoot;
|
|
144
|
+
},
|
|
145
|
+
checkValidity: check,
|
|
146
|
+
reportValidity: check,
|
|
147
|
+
};
|
|
148
|
+
return internals;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=form-internals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-internals.js","sourceRoot":"","sources":["../../src/testing/form-internals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,kFAAkF;AAClF,MAAM,cAAc,GAAG;IACrB,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,SAAS;IACT,UAAU;IACV,cAAc;IACd,cAAc;CACN,CAAC;AAsBX,yEAAyE;AACzE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAkC,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAsC;IACzE,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,SAAS,EAAE,iBAAiB,EAAE;QAC/D,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,SAAS,eAAe;YAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,YAAY,CAAC,iCAAiC,EAAE,mBAAmB,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;A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AAC;QAC3B,CAAC;QACD,IAAI,UAAU;YACZ,OAAO,OAAO,CAAC,UAAU,CAAC;QAC5B,CAAC;QACD,aAAa,EAAE,KAAK;QACpB,cAAc,EAAE,KAAK;KACtB,CAAC;IACF,OAAO,SAAwC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@taggor/component/testing` (TAG-209): helpers for component authors' unit tests, in Vitest with
|
|
3
|
+
* `environment: "happy-dom"`. `mountComponent` mounts a definition in the runtime's real Custom Element
|
|
4
|
+
* wrapper (`createComponentElement`, TAG-302) with an in-memory data transport, and returns helpers to
|
|
5
|
+
* query the shadow root, change attributes and props, wait for the component to settle, read the
|
|
6
|
+
* events it emitted (`expectEvent`) and the submissions it sent (`transport.submissions`); for a
|
|
7
|
+
* form field component, `form` holds the value and validity it set on its internals (TAG-235).
|
|
8
|
+
*
|
|
9
|
+
* Test-only: this entry imports the runtime and `preact/test-utils`, so it must never be imported
|
|
10
|
+
* by a component's own code; `bundle.test.ts` proves the SDK's main entry does not reach it.
|
|
11
|
+
*/
|
|
12
|
+
export { cleanup, mountComponent, type MountOptions, type MountedComponent, type RecordedEvent, } from "./mount-component.js";
|
|
13
|
+
export type { FormFieldRecord, FormFieldValidity } from "./form-internals.js";
|
|
14
|
+
export { createMemoryTransport, type MemoryResponder, type MemoryTransport, type RecordedSubmission, } from "../memory-transport.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,OAAO,EACP,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@taggor/component/testing` (TAG-209): helpers for component authors' unit tests, in Vitest with
|
|
3
|
+
* `environment: "happy-dom"`. `mountComponent` mounts a definition in the runtime's real Custom Element
|
|
4
|
+
* wrapper (`createComponentElement`, TAG-302) with an in-memory data transport, and returns helpers to
|
|
5
|
+
* query the shadow root, change attributes and props, wait for the component to settle, read the
|
|
6
|
+
* events it emitted (`expectEvent`) and the submissions it sent (`transport.submissions`); for a
|
|
7
|
+
* form field component, `form` holds the value and validity it set on its internals (TAG-235).
|
|
8
|
+
*
|
|
9
|
+
* Test-only: this entry imports the runtime and `preact/test-utils`, so it must never be imported
|
|
10
|
+
* by a component's own code; `bundle.test.ts` proves the SDK's main entry does not reach it.
|
|
11
|
+
*/
|
|
12
|
+
export { cleanup, mountComponent, } from "./mount-component.js";
|
|
13
|
+
export { createMemoryTransport, } from "../memory-transport.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,OAAO,EACP,cAAc,GAIf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,qBAAqB,GAItB,MAAM,wBAAwB,CAAC"}
|