element-vir 26.11.2 → 26.12.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/package.json +12 -12
- package/src/declarative-element/declarative-element-init.ts +115 -0
- package/src/declarative-element/declarative-element.ts +372 -0
- package/src/declarative-element/define-element.ts +515 -0
- package/{dist/declarative-element/definition-options.d.ts → src/declarative-element/definition-options.ts} +7 -2
- package/src/declarative-element/directives/assign.directive.ts +89 -0
- package/{dist/declarative-element/directives/async-prop.js → src/declarative-element/directives/async-prop.ts} +42 -8
- package/src/declarative-element/directives/attributes.directive.ts +63 -0
- package/src/declarative-element/directives/create-attribute-directive.ts +47 -0
- package/src/declarative-element/directives/directive-helpers.ts +67 -0
- package/{dist/declarative-element/directives/listen-to-activate.js → src/declarative-element/directives/listen-to-activate.ts} +8 -3
- package/src/declarative-element/directives/listen.directive.ts +206 -0
- package/src/declarative-element/directives/mutate.directive.ts +78 -0
- package/src/declarative-element/directives/on-dom-created.directive.ts +68 -0
- package/src/declarative-element/directives/on-dom-rendered.directive.ts +61 -0
- package/src/declarative-element/directives/on-intersect.directive.ts +139 -0
- package/src/declarative-element/directives/on-resize.directive.ts +142 -0
- package/src/declarative-element/directives/render-async.directive.ts +111 -0
- package/{dist/declarative-element/directives/render-if.directive.js → src/declarative-element/directives/render-if.directive.ts} +12 -3
- package/{dist/declarative-element/directives/test-id.directive.js → src/declarative-element/directives/test-id.directive.ts} +7 -2
- package/{dist/declarative-element/has-declarative-element-parent.js → src/declarative-element/has-declarative-element-parent.ts} +7 -4
- package/{dist/declarative-element/is-declarative-element-definition.js → src/declarative-element/is-declarative-element-definition.ts} +28 -11
- package/{dist/declarative-element/is-declarative-element.js → src/declarative-element/is-declarative-element.ts} +11 -5
- package/src/declarative-element/properties/assign-inputs.ts +30 -0
- package/src/declarative-element/properties/css-vars.ts +24 -0
- package/src/declarative-element/properties/element-events.ts +161 -0
- package/src/declarative-element/properties/host-classes.ts +63 -0
- package/{dist/declarative-element/properties/property-proxy.js → src/declarative-element/properties/property-proxy.ts} +58 -21
- package/src/declarative-element/properties/string-names.ts +83 -0
- package/src/declarative-element/properties/styles.ts +112 -0
- package/src/declarative-element/render-callback.ts +196 -0
- package/src/declarative-element/wrap-define-element.ts +127 -0
- package/{dist/index.d.ts → src/index.ts} +2 -0
- package/{dist/lit-exports/base-lit-exports.js → src/lit-exports/base-lit-exports.ts} +10 -1
- package/{dist/lit-exports/lit-repeat-fix.d.ts → src/lit-exports/lit-repeat-fix.ts} +45 -16
- package/{dist/readme-examples/my-app.element.js → src/readme-examples/my-app.element.ts} +5 -4
- package/src/readme-examples/my-custom-action.event.ts +3 -0
- package/{dist/readme-examples/my-custom-define.js → src/readme-examples/my-custom-define.ts} +9 -4
- package/{dist/readme-examples/my-simple.element.js → src/readme-examples/my-simple.element.ts} +4 -3
- package/src/readme-examples/my-with-assignment.element.ts +16 -0
- package/{dist/readme-examples/my-with-async-prop.element.js → src/readme-examples/my-with-async-prop.element.ts} +24 -16
- package/{dist/readme-examples/my-with-cleanup-callback.element.js → src/readme-examples/my-with-cleanup-callback.element.ts} +5 -4
- package/{dist/readme-examples/my-with-css-vars.element.js → src/readme-examples/my-with-css-vars.element.ts} +5 -4
- package/src/readme-examples/my-with-custom-events.element.ts +23 -0
- package/{dist/readme-examples/my-with-event-listening.element.js → src/readme-examples/my-with-event-listening.element.ts} +10 -9
- package/src/readme-examples/my-with-events.element.ts +23 -0
- package/{dist/readme-examples/my-with-host-class-definition.element.js → src/readme-examples/my-with-host-class-definition.element.ts} +7 -6
- package/{dist/readme-examples/my-with-host-class-usage.element.js → src/readme-examples/my-with-host-class-usage.element.ts} +5 -4
- package/src/readme-examples/my-with-inputs.element.ts +13 -0
- package/{dist/readme-examples/my-with-on-dom-created.element.js → src/readme-examples/my-with-on-dom-created.element.ts} +7 -6
- package/src/readme-examples/my-with-on-resize.element.ts +19 -0
- package/src/readme-examples/my-with-render-if.element.ts +15 -0
- package/{dist/readme-examples/my-with-styles-and-interpolated-selector.element.js → src/readme-examples/my-with-styles-and-interpolated-selector.element.ts} +6 -5
- package/{dist/readme-examples/my-with-styles.element.js → src/readme-examples/my-with-styles.element.ts} +5 -4
- package/{dist/readme-examples/my-with-update-state.element.js → src/readme-examples/my-with-update-state.element.ts} +8 -7
- package/src/readme-examples/require-declarative-element.ts +3 -0
- package/{dist/require-declarative-element.js → src/require-declarative-element.ts} +1 -0
- package/{dist/template-transforms/minimal-element-definition.d.ts → src/template-transforms/minimal-element-definition.ts} +19 -7
- package/src/template-transforms/nested-mapped-templates.ts +157 -0
- package/{dist/template-transforms/template-transform-type.d.ts → src/template-transforms/template-transform-type.ts} +3 -1
- package/{dist/template-transforms/transform-template.js → src/template-transforms/transform-template.ts} +70 -22
- package/src/template-transforms/vir-css/css-transform.ts +30 -0
- package/src/template-transforms/vir-css/vir-css.ts +30 -0
- package/src/template-transforms/vir-html/html-interpolation.ts +103 -0
- package/src/template-transforms/vir-html/html-transform.ts +149 -0
- package/{dist/template-transforms/vir-html/tag-name-keys.js → src/template-transforms/vir-html/tag-name-keys.ts} +1 -1
- package/{dist/template-transforms/vir-html/vir-html.js → src/template-transforms/vir-html/vir-html.ts} +13 -5
- package/src/typed-event/typed-event.ts +90 -0
- package/{dist/util/array.js → src/util/array.ts} +18 -5
- package/{dist/util/increment.d.ts → src/util/increment.ts} +24 -5
- package/{dist/util/lit-template.js → src/util/lit-template.ts} +30 -10
- package/src/util/map-async-value.ts +33 -0
- package/dist/declarative-element/custom-tag-name.js +0 -1
- package/dist/declarative-element/declarative-element-init.d.ts +0 -56
- package/dist/declarative-element/declarative-element-init.js +0 -1
- package/dist/declarative-element/declarative-element.d.ts +0 -114
- package/dist/declarative-element/declarative-element.js +0 -36
- package/dist/declarative-element/define-element.d.ts +0 -41
- package/dist/declarative-element/define-element.js +0 -248
- package/dist/declarative-element/definition-options.js +0 -9
- package/dist/declarative-element/directives/assign.directive.d.ts +0 -24
- package/dist/declarative-element/directives/assign.directive.js +0 -34
- package/dist/declarative-element/directives/async-prop.d.ts +0 -61
- package/dist/declarative-element/directives/attributes.directive.d.ts +0 -30
- package/dist/declarative-element/directives/attributes.directive.js +0 -35
- package/dist/declarative-element/directives/create-attribute-directive.d.ts +0 -28
- package/dist/declarative-element/directives/create-attribute-directive.js +0 -41
- package/dist/declarative-element/directives/directive-helpers.d.ts +0 -27
- package/dist/declarative-element/directives/directive-helpers.js +0 -37
- package/dist/declarative-element/directives/listen-to-activate.d.ts +0 -15
- package/dist/declarative-element/directives/listen.directive.d.ts +0 -92
- package/dist/declarative-element/directives/listen.directive.js +0 -48
- package/dist/declarative-element/directives/mutate.directive.d.ts +0 -38
- package/dist/declarative-element/directives/mutate.directive.js +0 -45
- package/dist/declarative-element/directives/on-dom-created.directive.d.ts +0 -44
- package/dist/declarative-element/directives/on-dom-created.directive.js +0 -51
- package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +0 -41
- package/dist/declarative-element/directives/on-dom-rendered.directive.js +0 -45
- package/dist/declarative-element/directives/on-intersect.directive.d.ts +0 -64
- package/dist/declarative-element/directives/on-intersect.directive.js +0 -89
- package/dist/declarative-element/directives/on-resize.directive.d.ts +0 -74
- package/dist/declarative-element/directives/on-resize.directive.js +0 -106
- package/dist/declarative-element/directives/render-async.directive.d.ts +0 -45
- package/dist/declarative-element/directives/render-async.directive.js +0 -33
- package/dist/declarative-element/directives/render-if.directive.d.ts +0 -32
- package/dist/declarative-element/directives/test-id.directive.d.ts +0 -52
- package/dist/declarative-element/has-declarative-element-parent.d.ts +0 -1
- package/dist/declarative-element/is-declarative-element-definition.d.ts +0 -17
- package/dist/declarative-element/is-declarative-element.d.ts +0 -15
- package/dist/declarative-element/properties/assign-inputs.d.ts +0 -1
- package/dist/declarative-element/properties/assign-inputs.js +0 -25
- package/dist/declarative-element/properties/css-vars.d.ts +0 -16
- package/dist/declarative-element/properties/css-vars.js +0 -1
- package/dist/declarative-element/properties/element-events.d.ts +0 -65
- package/dist/declarative-element/properties/element-events.js +0 -62
- package/dist/declarative-element/properties/element-properties.js +0 -1
- package/dist/declarative-element/properties/host-classes.d.ts +0 -36
- package/dist/declarative-element/properties/host-classes.js +0 -16
- package/dist/declarative-element/properties/property-proxy.d.ts +0 -22
- package/dist/declarative-element/properties/string-names.d.ts +0 -28
- package/dist/declarative-element/properties/string-names.js +0 -40
- package/dist/declarative-element/properties/styles.d.ts +0 -51
- package/dist/declarative-element/properties/styles.js +0 -41
- package/dist/declarative-element/properties/tag-name.js +0 -1
- package/dist/declarative-element/render-callback.d.ts +0 -56
- package/dist/declarative-element/render-callback.js +0 -27
- package/dist/declarative-element/wrap-define-element.d.ts +0 -36
- package/dist/declarative-element/wrap-define-element.js +0 -25
- package/dist/index.js +0 -42
- package/dist/lit-exports/all-lit-exports.js +0 -2
- package/dist/lit-exports/base-lit-exports.d.ts +0 -25
- package/dist/lit-exports/lit-repeat-fix.js +0 -37
- package/dist/readme-examples/my-app.element.d.ts +0 -1
- package/dist/readme-examples/my-custom-action.event.d.ts +0 -1
- package/dist/readme-examples/my-custom-action.event.js +0 -2
- package/dist/readme-examples/my-custom-define.d.ts +0 -4
- package/dist/readme-examples/my-simple.element.d.ts +0 -1
- package/dist/readme-examples/my-with-assignment.element.d.ts +0 -1
- package/dist/readme-examples/my-with-assignment.element.js +0 -15
- package/dist/readme-examples/my-with-async-prop.element.d.ts +0 -10
- package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +0 -3
- package/dist/readme-examples/my-with-css-vars.element.d.ts +0 -1
- package/dist/readme-examples/my-with-custom-events.element.d.ts +0 -1
- package/dist/readme-examples/my-with-custom-events.element.js +0 -22
- package/dist/readme-examples/my-with-event-listening.element.d.ts +0 -3
- package/dist/readme-examples/my-with-events.element.d.ts +0 -4
- package/dist/readme-examples/my-with-events.element.js +0 -20
- package/dist/readme-examples/my-with-host-class-definition.element.d.ts +0 -3
- package/dist/readme-examples/my-with-host-class-usage.element.d.ts +0 -1
- package/dist/readme-examples/my-with-inputs.element.d.ts +0 -4
- package/dist/readme-examples/my-with-inputs.element.js +0 -9
- package/dist/readme-examples/my-with-on-dom-created.element.d.ts +0 -1
- package/dist/readme-examples/my-with-on-resize.element.d.ts +0 -1
- package/dist/readme-examples/my-with-on-resize.element.js +0 -18
- package/dist/readme-examples/my-with-render-if.element.d.ts +0 -3
- package/dist/readme-examples/my-with-render-if.element.js +0 -11
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +0 -1
- package/dist/readme-examples/my-with-styles.element.d.ts +0 -1
- package/dist/readme-examples/my-with-update-state.element.d.ts +0 -8
- package/dist/readme-examples/require-declarative-element.d.ts +0 -1
- package/dist/readme-examples/require-declarative-element.js +0 -2
- package/dist/require-declarative-element.d.ts +0 -14
- package/dist/template-transforms/minimal-element-definition.js +0 -19
- package/dist/template-transforms/nested-mapped-templates.d.ts +0 -6
- package/dist/template-transforms/nested-mapped-templates.js +0 -96
- package/dist/template-transforms/template-transform-type.js +0 -1
- package/dist/template-transforms/transform-template.d.ts +0 -14
- package/dist/template-transforms/vir-css/css-transform.d.ts +0 -4
- package/dist/template-transforms/vir-css/css-transform.js +0 -15
- package/dist/template-transforms/vir-css/vir-css.d.ts +0 -12
- package/dist/template-transforms/vir-css/vir-css.js +0 -21
- package/dist/template-transforms/vir-html/html-interpolation.d.ts +0 -42
- package/dist/template-transforms/vir-html/html-interpolation.js +0 -1
- package/dist/template-transforms/vir-html/html-transform.d.ts +0 -5
- package/dist/template-transforms/vir-html/html-transform.js +0 -96
- package/dist/template-transforms/vir-html/tag-name-keys.d.ts +0 -7
- package/dist/template-transforms/vir-html/vir-html.d.ts +0 -11
- package/dist/typed-event/typed-event.d.ts +0 -55
- package/dist/typed-event/typed-event.js +0 -50
- package/dist/util/array.d.ts +0 -5
- package/dist/util/increment.js +0 -1
- package/dist/util/lit-template.d.ts +0 -9
- package/dist/util/type.js +0 -1
- /package/{dist/declarative-element/custom-tag-name.d.ts → src/declarative-element/custom-tag-name.ts} +0 -0
- /package/{dist/declarative-element/properties/element-properties.d.ts → src/declarative-element/properties/element-properties.ts} +0 -0
- /package/{dist/declarative-element/properties/tag-name.d.ts → src/declarative-element/properties/tag-name.ts} +0 -0
- /package/{dist/lit-exports/all-lit-exports.d.ts → src/lit-exports/all-lit-exports.ts} +0 -0
- /package/{dist/util/type.d.ts → src/util/type.ts} +0 -0
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { type CSSResult } from '../lit-exports/base-lit-exports.js';
|
|
2
|
-
import { type CustomElementTagName } from './custom-tag-name.js';
|
|
3
|
-
import { type DeclarativeElementDefinitionOptions } from './definition-options.js';
|
|
4
|
-
import { type CssVarsInitMap } from './properties/css-vars.js';
|
|
5
|
-
import { type EventsInitMap } from './properties/element-events.js';
|
|
6
|
-
import { type PropertyInitMapBase } from './properties/element-properties.js';
|
|
7
|
-
import { type HostClassesInitMap } from './properties/host-classes.js';
|
|
8
|
-
import { type BaseStringName } from './properties/string-names.js';
|
|
9
|
-
import { type StylesCallback } from './properties/styles.js';
|
|
10
|
-
import { type InitCallback, type RenderCallback, type RenderParams } from './render-callback.js';
|
|
11
|
-
/**
|
|
12
|
-
* Initialization for an element-vir declarative element. This defines all the pieces required for
|
|
13
|
-
* rendering the element.
|
|
14
|
-
*
|
|
15
|
-
* @category Internal
|
|
16
|
-
*/
|
|
17
|
-
export type DeclarativeElementInit<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseStringName<TagName>, CssVarKeys extends BaseStringName<TagName>, SlotNames extends ReadonlyArray<string>, TestIds extends ReadonlyArray<string>> = {
|
|
18
|
-
/**
|
|
19
|
-
* HTML tag name. This should not be used directly, as interpolating it with the html tagged
|
|
20
|
-
* template from this package is preferred.
|
|
21
|
-
*/
|
|
22
|
-
tagName: TagName;
|
|
23
|
-
/** Static styles. These should not and cannot change. */
|
|
24
|
-
styles?: CSSResult | StylesCallback<TagName, HostClassKeys, CssVarKeys> | undefined;
|
|
25
|
-
/** Events that the element can dispatch. (These can be thought of as "outputs".) */
|
|
26
|
-
events?: EventsInit | undefined;
|
|
27
|
-
slotNames?: SlotNames | undefined;
|
|
28
|
-
testIds?: TestIds | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* HTML host classes. Values can be callbacks to determine when a host class should be defined,
|
|
31
|
-
* based on current instance state or inputs, or just false to indicate that the host class will
|
|
32
|
-
* only be manually set.
|
|
33
|
-
*/
|
|
34
|
-
hostClasses?: HostClassesInitMap<TagName, HostClassKeys, Inputs, State> | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* CSS Vars for the component. Keys of this object should be kebab-case and start with the
|
|
37
|
-
* element's tag name.
|
|
38
|
-
*
|
|
39
|
-
* Values of this object represent the default fallback value for the given CSS var. These are
|
|
40
|
-
* then passed to the styles property, which must be a callback to take advantage of these.
|
|
41
|
-
*/
|
|
42
|
-
cssVars?: CssVarsInitMap<TagName, CssVarKeys>;
|
|
43
|
-
/**
|
|
44
|
-
* Make sure to define this at the top of your element init object or TypeScript will fail to
|
|
45
|
-
* infer the element's state type.
|
|
46
|
-
*
|
|
47
|
-
* Setup the element's initial state. This is only called once per element instance, before the
|
|
48
|
-
* first render. The return type of this method becomes the element's state type.
|
|
49
|
-
*/
|
|
50
|
-
state?: (params: Omit<RenderParams<TagName, Inputs, any, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>, 'state' | 'updateState'>) => Extract<keyof State, keyof HTMLElement> extends never ? Extract<keyof State, keyof Inputs> extends never ? State : `ERROR: Cannot define an element state property that clashes with input properties: ${Extract<keyof State, keyof Inputs> extends string | number | bigint | boolean | null | undefined ? Extract<keyof State, keyof Inputs> : ''}` : `ERROR: Cannot define an element state property that clashes with native HTMLElement properties: ${Extract<keyof State, keyof HTMLElement>}`;
|
|
51
|
-
/** Called as part of the first render call, before the first render call. */
|
|
52
|
-
init?: InitCallback<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds> | undefined;
|
|
53
|
-
render: RenderCallback<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
54
|
-
cleanup?: InitCallback<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds> | undefined;
|
|
55
|
-
options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
|
|
56
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { type SetRequiredAndNotNull } from '@augment-vir/common';
|
|
2
|
-
import { type EmptyObject, type IsAny, type IsEmptyObject } from 'type-fest';
|
|
3
|
-
import { LitElement, type CSSResult } from '../lit-exports/base-lit-exports.js';
|
|
4
|
-
import { type MinimalDefinitionWithInputs } from '../template-transforms/minimal-element-definition.js';
|
|
5
|
-
import { type CustomElementTagName } from './custom-tag-name.js';
|
|
6
|
-
import { type DeclarativeElementInit } from './declarative-element-init.js';
|
|
7
|
-
import { type DeclarativeElementDefinitionOptions } from './definition-options.js';
|
|
8
|
-
import { type CssVars } from './properties/css-vars.js';
|
|
9
|
-
import { type EventDescriptorMap, type EventsInitMap } from './properties/element-events.js';
|
|
10
|
-
import { type PropertyInitMapBase } from './properties/element-properties.js';
|
|
11
|
-
import { type HostClassNamesMap } from './properties/host-classes.js';
|
|
12
|
-
import { type ObservableListenerMap } from './properties/property-proxy.js';
|
|
13
|
-
import { type BaseStringName, type StringNameMap } from './properties/string-names.js';
|
|
14
|
-
import { type RenderCallback, type RenderParams, type UpdateStateCallback } from './render-callback.js';
|
|
15
|
-
/**
|
|
16
|
-
* The `host` type for a declarative element. This references a declarative element instance's
|
|
17
|
-
* top-level HTML element and always contains a shadow root (wherein the element is rendered).
|
|
18
|
-
*
|
|
19
|
-
* @category Internal
|
|
20
|
-
*/
|
|
21
|
-
export type DeclarativeElementHost<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, State extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseStringName<TagName> = any, CssVarKeys extends BaseStringName<TagName> = any, SlotNames extends ReadonlyArray<string> = any, TestIds extends ReadonlyArray<string> = any> = SetRequiredAndNotNull<Omit<DeclarativeElement<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>, Exclude<keyof StaticDeclarativeElementProperties<any, any, any, any, any, any, any, any>, keyof HTMLElement>>, 'shadowRoot'>;
|
|
22
|
-
/**
|
|
23
|
-
* The full definition for a declarative element.
|
|
24
|
-
*
|
|
25
|
-
* @category Internal
|
|
26
|
-
*/
|
|
27
|
-
export type DeclarativeElementDefinition<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, State extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseStringName<TagName> = any, CssVarKeys extends BaseStringName<TagName> = any, SlotNames extends ReadonlyArray<string> = any, TestIds extends ReadonlyArray<string> = any> = (new () => DeclarativeElementHost<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>) & StaticDeclarativeElementProperties<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds> & {
|
|
28
|
-
InstanceType: DeclarativeElementHost<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Abstract class base for all declarative elements.
|
|
32
|
-
*
|
|
33
|
-
* @category Internal
|
|
34
|
-
*/
|
|
35
|
-
export declare abstract class DeclarativeElement<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, State extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseStringName<TagName> = any, CssVarKeys extends BaseStringName<TagName> = any, SlotNames extends ReadonlyArray<string> = any, TestIds extends ReadonlyArray<string> = any> extends LitElement {
|
|
36
|
-
/**
|
|
37
|
-
* Assign inputs to an element instantiation. Use only on the opening tag.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* import {html} from 'element-vir';
|
|
43
|
-
*
|
|
44
|
-
* const myTemplate = html`
|
|
45
|
-
* <${MyElement.assign({input1: 'a', input2: 'b'})}></${MyElement}>
|
|
46
|
-
* `;
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
static readonly assign: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['assign'];
|
|
50
|
-
static readonly assignedInputs: PropertyInitMapBase | undefined;
|
|
51
|
-
static readonly tagName: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['tagName'];
|
|
52
|
-
static readonly styles: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['styles'];
|
|
53
|
-
static readonly render: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['render'];
|
|
54
|
-
static readonly InputsType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['InputsType'];
|
|
55
|
-
static readonly StateType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['StateType'];
|
|
56
|
-
static readonly UpdateStateType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['UpdateStateType'];
|
|
57
|
-
static readonly events: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['events'];
|
|
58
|
-
static readonly init: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['init'];
|
|
59
|
-
static readonly elementOptions: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['elementOptions'];
|
|
60
|
-
static readonly hostClasses: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['hostClasses'];
|
|
61
|
-
static readonly cssVars: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['cssVars'];
|
|
62
|
-
static readonly slotNames: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['slotNames'];
|
|
63
|
-
static readonly testIds: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseStringName<CustomElementTagName>, BaseStringName<CustomElementTagName>, ReadonlyArray<string>, ReadonlyArray<string>>['testIds'];
|
|
64
|
-
abstract _lastRenderError: Error | undefined;
|
|
65
|
-
abstract _internalRenderCount: number;
|
|
66
|
-
abstract _lastRenderedProps: Readonly<Pick<RenderParams<any, Inputs, State, any, any, any, any, any>, 'inputs' | 'state'>>;
|
|
67
|
-
/**
|
|
68
|
-
* Calls all destroy methods on all state properties, if they exist. This is automatically
|
|
69
|
-
* called whenever the element is detached.
|
|
70
|
-
*/
|
|
71
|
-
abstract destroy(): void;
|
|
72
|
-
abstract render(): unknown;
|
|
73
|
-
abstract readonly instanceState: State;
|
|
74
|
-
abstract readonly observablePropertyListenerMap: ObservableListenerMap<State & Inputs>;
|
|
75
|
-
abstract readonly instanceInputs: Inputs;
|
|
76
|
-
/**
|
|
77
|
-
* Used to assign inputs to the given element. This can be externally called as an API for
|
|
78
|
-
* setting inputs on an element reference, though this is discouraged. Inputs should typically
|
|
79
|
-
* be called using the `.assign()` method on an element definition inside of an HTML template.
|
|
80
|
-
*/
|
|
81
|
-
abstract assignInputs(inputs: EmptyObject extends Required<Inputs> ? never : Partial<Inputs>): void;
|
|
82
|
-
/** The element definition for this element instance. */
|
|
83
|
-
abstract readonly definition: DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* The assign inputs method of a declarative element.
|
|
87
|
-
*
|
|
88
|
-
* @category Internal
|
|
89
|
-
*/
|
|
90
|
-
export type AssignMethod<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase> = IsAny<Inputs> extends true ? any : IsEmptyObject<Required<Inputs>> extends true ? (inputsObject: never) => never : (inputsObject: IsEmptyObject<Required<Inputs>> extends true ? never : Inputs) => MinimalDefinitionWithInputs<TagName>;
|
|
91
|
-
/**
|
|
92
|
-
* All static properties on a declarative element. These all come from the element's definition.
|
|
93
|
-
*
|
|
94
|
-
* @category Internal
|
|
95
|
-
*/
|
|
96
|
-
export type StaticDeclarativeElementProperties<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseStringName<TagName>, CssVarKeys extends BaseStringName<TagName>, SlotNames extends ReadonlyArray<string>, TestIds extends ReadonlyArray<string>> = {
|
|
97
|
-
/** Assign inputs to an element directly on its interpolated tag. */
|
|
98
|
-
readonly assign: AssignMethod<TagName, Inputs>;
|
|
99
|
-
assignedInputs: Inputs | undefined;
|
|
100
|
-
/** Pass through the render callback for direct unit testability */
|
|
101
|
-
readonly render: RenderCallback<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
102
|
-
readonly events: EventDescriptorMap<TagName, EventsInit>;
|
|
103
|
-
readonly slotNames: Readonly<StringNameMap<TagName, 'slot', SlotNames>>;
|
|
104
|
-
readonly testIds: Readonly<StringNameMap<TagName, 'test-id', TestIds>>;
|
|
105
|
-
readonly init: DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
106
|
-
readonly elementOptions: DeclarativeElementDefinitionOptions;
|
|
107
|
-
readonly InputsType: Inputs;
|
|
108
|
-
readonly StateType: Readonly<State>;
|
|
109
|
-
readonly UpdateStateType: UpdateStateCallback<State>;
|
|
110
|
-
readonly hostClasses: HostClassNamesMap<string, HostClassKeys>;
|
|
111
|
-
readonly cssVars: CssVars<TagName, CssVarKeys>;
|
|
112
|
-
readonly tagName: TagName;
|
|
113
|
-
readonly styles: CSSResult;
|
|
114
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { LitElement } from '../lit-exports/base-lit-exports.js';
|
|
2
|
-
/**
|
|
3
|
-
* Abstract class base for all declarative elements.
|
|
4
|
-
*
|
|
5
|
-
* @category Internal
|
|
6
|
-
*/
|
|
7
|
-
export class DeclarativeElement extends LitElement {
|
|
8
|
-
/**
|
|
9
|
-
* Assign inputs to an element instantiation. Use only on the opening tag.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import {html} from 'element-vir';
|
|
15
|
-
*
|
|
16
|
-
* const myTemplate = html`
|
|
17
|
-
* <${MyElement.assign({input1: 'a', input2: 'b'})}></${MyElement}>
|
|
18
|
-
* `;
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
static assign;
|
|
22
|
-
static assignedInputs;
|
|
23
|
-
static tagName;
|
|
24
|
-
static styles;
|
|
25
|
-
static render;
|
|
26
|
-
static InputsType;
|
|
27
|
-
static StateType;
|
|
28
|
-
static UpdateStateType;
|
|
29
|
-
static events;
|
|
30
|
-
static init;
|
|
31
|
-
static elementOptions;
|
|
32
|
-
static hostClasses;
|
|
33
|
-
static cssVars;
|
|
34
|
-
static slotNames;
|
|
35
|
-
static testIds;
|
|
36
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type CustomElementTagName } from './custom-tag-name.js';
|
|
2
|
-
import { type DeclarativeElementInit } from './declarative-element-init.js';
|
|
3
|
-
import { type DeclarativeElementDefinition } from './declarative-element.js';
|
|
4
|
-
import { type EventsInitMap } from './properties/element-events.js';
|
|
5
|
-
import { type PropertyInitMapBase } from './properties/element-properties.js';
|
|
6
|
-
import { type BaseStringName } from './properties/string-names.js';
|
|
7
|
-
/**
|
|
8
|
-
* Verifies that the given `Inputs` type does not clash with built-in HTMLElement properties. This
|
|
9
|
-
* is used within {@link defineElement}.
|
|
10
|
-
*
|
|
11
|
-
* @category Internal
|
|
12
|
-
*/
|
|
13
|
-
export type DeclarativeElementInputErrorParams<Inputs extends PropertyInitMapBase> = Extract<keyof Inputs, keyof HTMLElement> extends never ? [] : [
|
|
14
|
-
'ERROR: Cannot define an element input property that clashes with native HTMLElement properties.'
|
|
15
|
-
];
|
|
16
|
-
/**
|
|
17
|
-
* Defines an element with inputs. Note that this function must be called twice, due to TypeScript
|
|
18
|
-
* type inference limitations.
|
|
19
|
-
*
|
|
20
|
-
* @category Element Definition
|
|
21
|
-
* @example
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* import {defineElement, html} from 'element-vir';
|
|
25
|
-
*
|
|
26
|
-
* const MyElement = defineElement<{username: string}>()({
|
|
27
|
-
* tagName: 'my-element',
|
|
28
|
-
* render({inputs}) {
|
|
29
|
-
* return html`
|
|
30
|
-
* <p>hi: ${inputs.username}</p>
|
|
31
|
-
* `;
|
|
32
|
-
* },
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function defineElement<Inputs extends PropertyInitMapBase = {}>(
|
|
37
|
-
/**
|
|
38
|
-
* These `errorParams` is present when there are problems with the `Inputs` type. If it is
|
|
39
|
-
* present, the error should be fixed. This should always be empty.
|
|
40
|
-
*/
|
|
41
|
-
...errorParams: DeclarativeElementInputErrorParams<Inputs>): <const TagName extends CustomElementTagName, State extends PropertyInitMapBase = {}, EventsInit extends EventsInitMap = {}, const HostClassKeys extends BaseStringName<TagName> = `${TagName}-`, const CssVarKeys extends BaseStringName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>, const TestIds extends ReadonlyArray<string> = Readonly<[]>>(initInput: DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>) => DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
|
-
import { assert, check } from '@augment-vir/assert';
|
|
3
|
-
import { ensureErrorAndPrependMessage, extractErrorMessage, getObjectTypedKeys, kebabCaseToCamelCase, } from '@augment-vir/common';
|
|
4
|
-
import { defineCssVars } from 'lit-css-vars';
|
|
5
|
-
import { css } from '../template-transforms/vir-css/vir-css.js';
|
|
6
|
-
import { DeclarativeElement, } from './declarative-element.js';
|
|
7
|
-
import { defaultDeclarativeElementDefinitionOptions, } from './definition-options.js';
|
|
8
|
-
import { assignInputs } from './properties/assign-inputs.js';
|
|
9
|
-
import { createEventDescriptorMap, } from './properties/element-events.js';
|
|
10
|
-
import { createHostClassNamesMap } from './properties/host-classes.js';
|
|
11
|
-
import { bindReactiveProperty, createElementPropertyProxy } from './properties/property-proxy.js';
|
|
12
|
-
import { assertValidStringNames, createStringNameMap, } from './properties/string-names.js';
|
|
13
|
-
import { applyHostClasses, createStylesCallbackInput } from './properties/styles.js';
|
|
14
|
-
import { createRenderParams } from './render-callback.js';
|
|
15
|
-
/**
|
|
16
|
-
* Defines an element with inputs. Note that this function must be called twice, due to TypeScript
|
|
17
|
-
* type inference limitations.
|
|
18
|
-
*
|
|
19
|
-
* @category Element Definition
|
|
20
|
-
* @example
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* import {defineElement, html} from 'element-vir';
|
|
24
|
-
*
|
|
25
|
-
* const MyElement = defineElement<{username: string}>()({
|
|
26
|
-
* tagName: 'my-element',
|
|
27
|
-
* render({inputs}) {
|
|
28
|
-
* return html`
|
|
29
|
-
* <p>hi: ${inputs.username}</p>
|
|
30
|
-
* `;
|
|
31
|
-
* },
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function defineElement(
|
|
36
|
-
/**
|
|
37
|
-
* These `errorParams` is present when there are problems with the `Inputs` type. If it is
|
|
38
|
-
* present, the error should be fixed. This should always be empty.
|
|
39
|
-
*/
|
|
40
|
-
...errorParams) {
|
|
41
|
-
assert.isEmpty(errorParams);
|
|
42
|
-
return (initInput) => {
|
|
43
|
-
const init = initInput;
|
|
44
|
-
if (!check.isObject(init)) {
|
|
45
|
-
throw new TypeError('Cannot define element with non-object init: ${init}');
|
|
46
|
-
}
|
|
47
|
-
return internalDefineElement({
|
|
48
|
-
...init,
|
|
49
|
-
options: {
|
|
50
|
-
...init.options,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function internalDefineElement(init) {
|
|
56
|
-
if (!check.isObject(init)) {
|
|
57
|
-
throw new TypeError('Cannot define element with non-object init: ${init}');
|
|
58
|
-
}
|
|
59
|
-
if (!check.isString(init.tagName)) {
|
|
60
|
-
throw new TypeError('Missing valid tagName (expected a string).');
|
|
61
|
-
}
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
63
|
-
if (!init.render || typeof init.render === 'string') {
|
|
64
|
-
throw new Error(`Failed to define element '${init.tagName}': render is not a function`);
|
|
65
|
-
}
|
|
66
|
-
const elementOptions = {
|
|
67
|
-
...defaultDeclarativeElementDefinitionOptions,
|
|
68
|
-
...init.options,
|
|
69
|
-
};
|
|
70
|
-
const eventsMap = createEventDescriptorMap(init.tagName, init.events);
|
|
71
|
-
const hostClassNames = createHostClassNamesMap(init.hostClasses);
|
|
72
|
-
if (init.hostClasses) {
|
|
73
|
-
assertValidStringNames(init.tagName, init.hostClasses);
|
|
74
|
-
}
|
|
75
|
-
if (init.cssVars) {
|
|
76
|
-
assertValidStringNames(init.tagName, init.cssVars);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* As casts here are to prevent defineCssVars from complaining that our CSS var names are too
|
|
80
|
-
* generic or the names not being in kebab-case. (Which, in this line of code, are indeed true
|
|
81
|
-
* errors. However, this is for internal types only and the user will actually see much more
|
|
82
|
-
* specific types externally.)
|
|
83
|
-
*/
|
|
84
|
-
const cssVars = (init.cssVars ? defineCssVars(init.cssVars) : {});
|
|
85
|
-
const slotNamesMap = createStringNameMap(init.tagName, 'slot', init.slotNames);
|
|
86
|
-
const testIdsMap = createStringNameMap(init.tagName, 'test-id', init.testIds);
|
|
87
|
-
const calculatedStyles = typeof init.styles === 'function'
|
|
88
|
-
? init.styles(createStylesCallbackInput({ hostClassNames, cssVars }))
|
|
89
|
-
: init.styles || css ``;
|
|
90
|
-
const typedRenderCallback = init.render;
|
|
91
|
-
function typedAssignCallback(...[inputs]) {
|
|
92
|
-
const wrappedDefinition = {
|
|
93
|
-
_elementVirIsMinimalDefinitionWithInputs: true,
|
|
94
|
-
definition: anonymousClass,
|
|
95
|
-
inputs,
|
|
96
|
-
};
|
|
97
|
-
return wrappedDefinition;
|
|
98
|
-
}
|
|
99
|
-
const anonymousClass = class extends DeclarativeElement {
|
|
100
|
-
static elementOptions = elementOptions;
|
|
101
|
-
static tagName = init.tagName;
|
|
102
|
-
static styles = calculatedStyles;
|
|
103
|
-
_lastRenderError = undefined;
|
|
104
|
-
_internalRenderCount = 0;
|
|
105
|
-
createRenderParams() {
|
|
106
|
-
return createRenderParams({
|
|
107
|
-
element: this,
|
|
108
|
-
eventsMap,
|
|
109
|
-
cssVars,
|
|
110
|
-
slotNamesMap,
|
|
111
|
-
testIdsMap,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
static assign = typedAssignCallback;
|
|
115
|
-
static events = eventsMap;
|
|
116
|
-
static render = typedRenderCallback;
|
|
117
|
-
static hostClasses = hostClassNames;
|
|
118
|
-
static cssVars = cssVars;
|
|
119
|
-
static init = init;
|
|
120
|
-
static slotNames = slotNamesMap;
|
|
121
|
-
static testIds = testIdsMap;
|
|
122
|
-
get InstanceType() {
|
|
123
|
-
throw new Error(`'InstanceType' was called on ${init.tagName} as a value but it is only a type.`);
|
|
124
|
-
}
|
|
125
|
-
static get InputsType() {
|
|
126
|
-
throw new Error(`'InputsType' was called on ${init.tagName} as a value but it is only a type.`);
|
|
127
|
-
}
|
|
128
|
-
static get StateType() {
|
|
129
|
-
throw new Error(`'StateType' was called on ${init.tagName} as a value but it is only a type.`);
|
|
130
|
-
}
|
|
131
|
-
static get UpdateStateType() {
|
|
132
|
-
throw new Error(`'UpdateStateType' was called on ${init.tagName} as a value but it is only a type.`);
|
|
133
|
-
}
|
|
134
|
-
_initCalled = false;
|
|
135
|
-
_stateCalled = false;
|
|
136
|
-
_hasRendered = false;
|
|
137
|
-
_lastRenderedProps = undefined;
|
|
138
|
-
render() {
|
|
139
|
-
this._internalRenderCount++;
|
|
140
|
-
try {
|
|
141
|
-
this._hasRendered = true;
|
|
142
|
-
const renderParams = this.createRenderParams();
|
|
143
|
-
if (!this._stateCalled && init.state) {
|
|
144
|
-
this._stateCalled = true;
|
|
145
|
-
const stateInit = init.state(renderParams);
|
|
146
|
-
if (stateInit instanceof Promise) {
|
|
147
|
-
throw new TypeError('init cannot be asynchronous');
|
|
148
|
-
}
|
|
149
|
-
getObjectTypedKeys(stateInit).forEach((stateKey) => {
|
|
150
|
-
bindReactiveProperty(this, stateKey);
|
|
151
|
-
this.instanceState[stateKey] = stateInit[stateKey];
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
if (!this._initCalled && init.init) {
|
|
155
|
-
this._initCalled = true;
|
|
156
|
-
if (init.init(renderParams) instanceof Promise) {
|
|
157
|
-
throw new TypeError('init cannot be asynchronous');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const renderResult = typedRenderCallback(renderParams);
|
|
161
|
-
if (renderResult instanceof Promise) {
|
|
162
|
-
throw new TypeError('render cannot be asynchronous');
|
|
163
|
-
}
|
|
164
|
-
applyHostClasses({
|
|
165
|
-
host: renderParams.host,
|
|
166
|
-
hostClassesInit: init.hostClasses,
|
|
167
|
-
hostClassNames,
|
|
168
|
-
state: renderParams.state,
|
|
169
|
-
inputs: renderParams.inputs,
|
|
170
|
-
});
|
|
171
|
-
this._lastRenderedProps = {
|
|
172
|
-
inputs: { ...renderParams.inputs },
|
|
173
|
-
state: { ...renderParams.state },
|
|
174
|
-
};
|
|
175
|
-
return renderResult;
|
|
176
|
-
}
|
|
177
|
-
catch (caught) {
|
|
178
|
-
const error = ensureErrorAndPrependMessage(caught, `Failed to render ${init.tagName}`);
|
|
179
|
-
console.error(error);
|
|
180
|
-
this._lastRenderError = error;
|
|
181
|
-
void elementOptions.errorHandler?.(error);
|
|
182
|
-
return extractErrorMessage(error);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
connectedCallback() {
|
|
186
|
-
super.connectedCallback();
|
|
187
|
-
if (this._hasRendered && !this._initCalled && init.init) {
|
|
188
|
-
this._initCalled = true;
|
|
189
|
-
const renderParams = this.createRenderParams();
|
|
190
|
-
if (init.init(renderParams) instanceof Promise) {
|
|
191
|
-
throw new TypeError(`init in '${init.tagName}' cannot be asynchronous`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
destroy() {
|
|
196
|
-
Object.values(this.instanceState).forEach((stateValue) => {
|
|
197
|
-
if (check.hasKey(stateValue, 'destroy') && check.isFunction(stateValue.destroy)) {
|
|
198
|
-
stateValue.destroy();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
disconnectedCallback() {
|
|
203
|
-
super.disconnectedCallback();
|
|
204
|
-
if (init.cleanup) {
|
|
205
|
-
const renderParams = this.createRenderParams();
|
|
206
|
-
if (init.cleanup(renderParams) instanceof Promise) {
|
|
207
|
-
throw new TypeError(`cleanup in '${init.tagName}' cannot be asynchronous`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
this.destroy();
|
|
211
|
-
this._initCalled = false;
|
|
212
|
-
this._stateCalled = false;
|
|
213
|
-
}
|
|
214
|
-
// this is set below in Object.defineProperties
|
|
215
|
-
definition = {};
|
|
216
|
-
assignInputs(inputs) {
|
|
217
|
-
assignInputs(this, inputs);
|
|
218
|
-
}
|
|
219
|
-
observablePropertyListenerMap = {};
|
|
220
|
-
instanceInputs = createElementPropertyProxy(this, false);
|
|
221
|
-
instanceState = createElementPropertyProxy(this, !elementOptions.allowPolymorphicState);
|
|
222
|
-
constructor() {
|
|
223
|
-
super();
|
|
224
|
-
this.definition = anonymousClass;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
Object.defineProperties(anonymousClass, {
|
|
228
|
-
name: {
|
|
229
|
-
value: kebabCaseToCamelCase(init.tagName, {
|
|
230
|
-
capitalizeFirstLetter: true,
|
|
231
|
-
}),
|
|
232
|
-
writable: true,
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
/**
|
|
236
|
-
* `window` will be `undefined` in Node.js and we want to be able to import these files into
|
|
237
|
-
* Node.js.
|
|
238
|
-
*/
|
|
239
|
-
if (globalThis.window) {
|
|
240
|
-
if (globalThis.window.customElements.get(init.tagName)) {
|
|
241
|
-
console.warn(`Tried to define custom element '${init.tagName}' but it is already defined.`);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
globalThis.window.customElements.define(init.tagName, anonymousClass);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return anonymousClass;
|
|
248
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type EmptyObject } from 'type-fest';
|
|
2
|
-
import { type DirectiveResult } from '../../lit-exports/all-lit-exports.js';
|
|
3
|
-
import { type PropertyInitMapBase } from '../properties/element-properties.js';
|
|
4
|
-
export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBase = PropertyInitMapBase> = {
|
|
5
|
-
InputsType: InputsType;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Assign an object matching an element's inputs to its inputs.
|
|
9
|
-
*
|
|
10
|
-
* @deprecated Instead of using this directive, assign inputs directly on the element's
|
|
11
|
-
* interpolation opening tag interpolation.
|
|
12
|
-
* @example Html`<${MyElement} ${assign(MyElement, {value: 1})}>...` should be
|
|
13
|
-
* html`<${MyElement.assign({value: 1})}>...`
|
|
14
|
-
*/
|
|
15
|
-
export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType>(declarativeElement: SpecificDeclarativeElement, inputsObject: EmptyObject extends Required<SpecificDeclarativeElement['InputsType']> ? never : SpecificDeclarativeElement['InputsType']): DirectiveResult;
|
|
16
|
-
/**
|
|
17
|
-
* Assign an object matching an element's inputs to its inputs.
|
|
18
|
-
*
|
|
19
|
-
* @deprecated Instead of using this directive, assign inputs directly on the element's
|
|
20
|
-
* interpolation opening tag interpolation.
|
|
21
|
-
* @example Html`<${MyElement} ${assign(MyElement, {value: 1})}>...` should be
|
|
22
|
-
* html`<${MyElement.assign({value: 1})}>...`
|
|
23
|
-
*/
|
|
24
|
-
export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType, const SpecificInput extends SpecificDeclarativeElement['InputsType']>(inputsObject: SpecificInput extends typeof HTMLElement ? never : SpecificInput): DirectiveResult;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { directive, Directive, noChange, } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
-
import { assignInputs } from '../properties/assign-inputs.js';
|
|
3
|
-
import { extractElement } from './directive-helpers.js';
|
|
4
|
-
/**
|
|
5
|
-
* Assign an object matching an element's inputs to its inputs.
|
|
6
|
-
*
|
|
7
|
-
* @deprecated Instead of using this directive, assign inputs directly on the element's
|
|
8
|
-
* interpolation opening tag interpolation.
|
|
9
|
-
* @example Html`<${MyElement} ${assign(MyElement, {value: 1})}>...` should be
|
|
10
|
-
* html`<${MyElement.assign({value: 1})}>...`
|
|
11
|
-
*/
|
|
12
|
-
export function assign(declarativeElementOrInputs, inputsObject) {
|
|
13
|
-
/**
|
|
14
|
-
* The directive generics (in listenDirective) are not strong enough to maintain their values.
|
|
15
|
-
* Thus, the directive call is wrapped in this function.
|
|
16
|
-
*/
|
|
17
|
-
if (inputsObject) {
|
|
18
|
-
return assignDirective(declarativeElementOrInputs, inputsObject);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return assignDirective(undefined, declarativeElementOrInputs);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const assignDirective = directive(class extends Directive {
|
|
25
|
-
element;
|
|
26
|
-
constructor(partInfo) {
|
|
27
|
-
super(partInfo);
|
|
28
|
-
this.element = extractElement(partInfo, 'assign');
|
|
29
|
-
}
|
|
30
|
-
render(elementDefinition, inputsObject) {
|
|
31
|
-
assignInputs(this.element, inputsObject);
|
|
32
|
-
return noChange;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { type Overwrite } from '@augment-vir/common';
|
|
2
|
-
import { CallbackObservable, type AsyncValue, type CallbackObservableInit } from 'observavir';
|
|
3
|
-
export type { AsyncValue } from 'observavir';
|
|
4
|
-
/**
|
|
5
|
-
* Class for constructing async props. Do not use this directly as its internal types won't be
|
|
6
|
-
* inferred correctly. Instead use {@link asyncProp} an async prop or {@link AsyncProp} for types.
|
|
7
|
-
*
|
|
8
|
-
* @category Internal
|
|
9
|
-
*/
|
|
10
|
-
export declare class InternalAsyncPropClass<Value, Params> extends CallbackObservable<Value, Params> {
|
|
11
|
-
/**
|
|
12
|
-
* Checks if the current `.value` has resolved (meaning the Promise has settled and it was not
|
|
13
|
-
* rejected). This type guards the current instance's `.value` property.
|
|
14
|
-
*/
|
|
15
|
-
isResolved(): this is Overwrite<this, {
|
|
16
|
-
value: Exclude<AsyncValue<Value>, Promise<any> | Error>;
|
|
17
|
-
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Checks if the current `.value` has settled (meaning it is either a rejection error or a
|
|
20
|
-
* resolved value). This type guards the current instance's `.value` property.
|
|
21
|
-
*/
|
|
22
|
-
isSettled(): this is Overwrite<this, {
|
|
23
|
-
value: Exclude<AsyncValue<Value>, Promise<any>>;
|
|
24
|
-
}>;
|
|
25
|
-
/**
|
|
26
|
-
* Checks if the current `.value` has not settled yet settled (meaning it is still an unsettled
|
|
27
|
-
* Promise). This type guards the current instance's `.value` property.
|
|
28
|
-
*/
|
|
29
|
-
isWaiting(): this is Overwrite<this, {
|
|
30
|
-
value: Extract<AsyncValue<Value>, Promise<any>>;
|
|
31
|
-
}>;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if the current `.value` is a rejection error. This type guards the current instance's
|
|
34
|
-
* `.value` property.
|
|
35
|
-
*/
|
|
36
|
-
isError(): this is Overwrite<this, {
|
|
37
|
-
value: Extract<AsyncValue<Value>, Error>;
|
|
38
|
-
}>;
|
|
39
|
-
/**
|
|
40
|
-
* Checks if the current `.value` is resolved (and not an error) or still waiting. This type
|
|
41
|
-
* guards the current instance's `.value` property.
|
|
42
|
-
*/
|
|
43
|
-
isNotError(): this is Overwrite<this, {
|
|
44
|
-
value: Exclude<AsyncValue<Value>, Error>;
|
|
45
|
-
}>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* An async property created by {@link asyncProp} for use within declarative elements. Do not use
|
|
49
|
-
* this directly as its internal types won't be inferred correctly.
|
|
50
|
-
*
|
|
51
|
-
* @category Internal
|
|
52
|
-
*/
|
|
53
|
-
export type AsyncProp<Value, Params> = Omit<InternalAsyncPropClass<Value, Params>,
|
|
54
|
-
/** Hide these properties to make the `AsyncProp` interface much simpler. */
|
|
55
|
-
'dispatch' | 'equalityCheck' | 'getListenerCount' | 'updateCallback' | 'removeListener' | 'removeAllListeners' | 'listenToEvent' | 'listen' | 'resolvedValue'>;
|
|
56
|
-
/**
|
|
57
|
-
* Create an async prop for a declarative element's state.
|
|
58
|
-
*
|
|
59
|
-
* @category Async
|
|
60
|
-
*/
|
|
61
|
-
export declare function asyncProp<Value, Params = void>(init?: CallbackObservableInit<Value, Params>): AsyncProp<Value, Params>;
|