element-vir 7.0.0 → 7.0.2
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/dist/augments/array.d.ts +2 -0
- package/dist/augments/array.js +3 -0
- package/dist/augments/type.d.ts +9 -0
- package/dist/augments/type.js +13 -0
- package/dist/declarative-element/declarative-element-init.d.ts +45 -0
- package/dist/declarative-element/declarative-element-init.js +1 -0
- package/dist/declarative-element/declarative-element.d.ts +49 -0
- package/dist/declarative-element/declarative-element.js +18 -0
- package/dist/declarative-element/define-element-no-inputs.d.ts +6 -0
- package/dist/declarative-element/define-element-no-inputs.js +133 -0
- package/dist/declarative-element/define-element.d.ts +6 -0
- package/dist/declarative-element/define-element.js +13 -0
- package/dist/declarative-element/definition-options.d.ts +6 -0
- package/dist/declarative-element/definition-options.js +4 -0
- package/dist/declarative-element/directives/assign-with-clean-up.directive.d.ts +24 -0
- package/dist/declarative-element/directives/assign-with-clean-up.directive.js +43 -0
- package/dist/declarative-element/directives/assign.directive.d.ts +13 -0
- package/dist/declarative-element/directives/assign.directive.js +28 -0
- package/dist/declarative-element/directives/directive-helpers.d.ts +15 -0
- package/dist/declarative-element/directives/directive-helpers.js +21 -0
- package/dist/declarative-element/directives/listen.directive.d.ts +15 -0
- package/dist/declarative-element/directives/listen.directive.js +47 -0
- package/dist/declarative-element/directives/on-dom-created.directive.d.ts +12 -0
- package/dist/declarative-element/directives/on-dom-created.directive.js +23 -0
- package/dist/declarative-element/directives/on-resize.directive.d.ts +16 -0
- package/dist/declarative-element/directives/on-resize.directive.js +36 -0
- package/dist/declarative-element/directives/render-async-prop.directive.d.ts +10 -0
- package/dist/declarative-element/directives/render-async-prop.directive.js +12 -0
- package/dist/declarative-element/directives/render-if.directive.d.ts +2 -0
- package/dist/declarative-element/directives/render-if.directive.js +4 -0
- package/dist/declarative-element/has-declarative-element-parent.d.ts +2 -0
- package/dist/declarative-element/has-declarative-element-parent.js +16 -0
- package/dist/declarative-element/properties/async-prop.d.ts +27 -0
- package/dist/declarative-element/properties/async-prop.js +102 -0
- package/dist/declarative-element/properties/css-vars.d.ts +7 -0
- package/dist/declarative-element/properties/css-vars.js +22 -0
- package/dist/declarative-element/properties/element-events.d.ts +11 -0
- package/dist/declarative-element/properties/element-events.js +24 -0
- package/dist/declarative-element/properties/element-properties.d.ts +15 -0
- package/dist/declarative-element/properties/element-properties.js +21 -0
- package/dist/declarative-element/properties/element-updater-proxy.d.ts +4 -0
- package/dist/declarative-element/properties/element-updater-proxy.js +56 -0
- package/dist/declarative-element/properties/host-classes.d.ts +22 -0
- package/dist/declarative-element/properties/host-classes.js +12 -0
- package/dist/declarative-element/properties/styles.d.ts +24 -0
- package/dist/declarative-element/properties/styles.js +32 -0
- package/dist/declarative-element/properties/tag-name.d.ts +3 -0
- package/dist/declarative-element/properties/tag-name.js +4 -0
- package/dist/declarative-element/render-callback.d.ts +27 -0
- package/dist/declarative-element/render-callback.js +31 -0
- package/dist/declarative-element-marker-symbol.d.ts +2 -0
- package/dist/declarative-element-marker-symbol.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +19 -0
- package/dist/require-declarative-element.d.ts +3 -0
- package/dist/require-declarative-element.js +4 -0
- package/dist/template-transforms/has-static-tag-name.d.ts +5 -0
- package/dist/template-transforms/has-static-tag-name.js +6 -0
- package/dist/template-transforms/nested-mapped-templates.d.ts +7 -0
- package/dist/template-transforms/nested-mapped-templates.js +96 -0
- package/dist/template-transforms/transform-template.d.ts +17 -0
- package/dist/template-transforms/transform-template.js +87 -0
- package/dist/template-transforms/vir-css/css-transform.d.ts +8 -0
- package/dist/template-transforms/vir-css/css-transform.js +12 -0
- package/dist/template-transforms/vir-css/vir-css.d.ts +4 -0
- package/dist/template-transforms/vir-css/vir-css.js +12 -0
- package/dist/template-transforms/vir-html/html-transform.d.ts +4 -0
- package/dist/template-transforms/vir-html/html-transform.js +44 -0
- package/dist/template-transforms/vir-html/vir-html.d.ts +4 -0
- package/dist/template-transforms/vir-html/vir-html.js +16 -0
- package/dist/typed-event/typed-event.d.ts +20 -0
- package/dist/typed-event/typed-event.js +32 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NonEmptyString<T> = T extends '' ? never : T;
|
|
2
|
+
/**
|
|
3
|
+
* If the given value is not an instance of the given constructor, an error is thrown.
|
|
4
|
+
*
|
|
5
|
+
* This is a variation of assertInstanceOf that can be run in run-time code and doesn't require
|
|
6
|
+
* testing packages.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ensureInstanceOf<T>(value: unknown, constructor: new (...args: any) => T, message?: string): asserts value is T;
|
|
9
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* If the given value is not an instance of the given constructor, an error is thrown.
|
|
3
|
+
*
|
|
4
|
+
* This is a variation of assertInstanceOf that can be run in run-time code and doesn't require
|
|
5
|
+
* testing packages.
|
|
6
|
+
*/
|
|
7
|
+
export function ensureInstanceOf(value, constructor, message) {
|
|
8
|
+
if (!(value instanceof constructor)) {
|
|
9
|
+
const extraMessage = message ? `: ${message}` : '';
|
|
10
|
+
const errorMessage = `${value} is not an instanceof of ${constructor.name}${extraMessage}`;
|
|
11
|
+
throw new TypeError(errorMessage);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CSSResult } from 'lit';
|
|
2
|
+
import { DeclarativeElementDefinitionOptions } from './definition-options';
|
|
3
|
+
import { CssVarsInitMap } from './properties/css-vars';
|
|
4
|
+
import { EventsInitMap } from './properties/element-events';
|
|
5
|
+
import { PropertyInitMapBase } from './properties/element-properties';
|
|
6
|
+
import { HostClassesInitMap } from './properties/host-classes';
|
|
7
|
+
import { StylesCallback } from './properties/styles';
|
|
8
|
+
import { InitCallback, RenderCallback } from './render-callback';
|
|
9
|
+
export type CustomElementTagName = `${string}-${string}`;
|
|
10
|
+
export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
|
|
11
|
+
/**
|
|
12
|
+
* HTML tag name. This should not be used directly, as interpolating it with the html tagged
|
|
13
|
+
* template from this package is preferred.
|
|
14
|
+
*/
|
|
15
|
+
tagName: CustomElementTagName;
|
|
16
|
+
/** Static styles. These should not and cannot change. */
|
|
17
|
+
styles?: CSSResult | StylesCallback<HostClassKeys, CssVarKeys>;
|
|
18
|
+
/** Element properties. (These can be thought of as "inputs".) */
|
|
19
|
+
stateInit?: StateInit;
|
|
20
|
+
/** Events that the element can dispatch. (These can be thought of as "outputs".) */
|
|
21
|
+
events?: EventsInitGeneric;
|
|
22
|
+
/**
|
|
23
|
+
* CSS host classes. Values can be callbacks to determine when a host class should be defined,
|
|
24
|
+
* based on current instance state or inputs, or just undefined to indicate that the host class
|
|
25
|
+
* will only be manually set.
|
|
26
|
+
*/
|
|
27
|
+
hostClasses?: HostClassesInitMap<HostClassKeys, InputsGeneric, StateInit>;
|
|
28
|
+
/**
|
|
29
|
+
* CSS Vars for the component. Keys of this object should be camelCased (or whatever your casing
|
|
30
|
+
* convention is). They will be transformed, at runtime, to CSS vars with kebab-casing, to match
|
|
31
|
+
* CSS standards.
|
|
32
|
+
*
|
|
33
|
+
* Values of this object represent the default fallback value for the given CSS var. These are
|
|
34
|
+
* then passed to the styles property, which must be a callback to take advantage of these.
|
|
35
|
+
* cssVarValues or cssVarNames can then be destructured from the styles property's callback
|
|
36
|
+
* input.
|
|
37
|
+
*/
|
|
38
|
+
cssVars?: CssVarsInitMap<CssVarKeys>;
|
|
39
|
+
/** Called as part of the first renderCallback call, before the first renderCallback call. */
|
|
40
|
+
initCallback?: InitCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
41
|
+
renderCallback: RenderCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
42
|
+
cleanupCallback?: InitCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
43
|
+
options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=declarative-element-init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
|
|
2
|
+
import { CSSResult, LitElement, TemplateResult } from 'lit';
|
|
3
|
+
import { DeclarativeElementInit } from './declarative-element-init';
|
|
4
|
+
import { CssVarNameOrValueMap } from './properties/css-vars';
|
|
5
|
+
import { EventDescriptorMap, EventsInitMap } from './properties/element-events';
|
|
6
|
+
import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './properties/element-properties';
|
|
7
|
+
import { HostClassNamesMap } from './properties/host-classes';
|
|
8
|
+
import { RenderCallback } from './render-callback';
|
|
9
|
+
export type HostInstanceType<InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = RequiredAndNotNullBy<DeclarativeElement<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'shadowRoot'>;
|
|
10
|
+
export type DeclarativeElementDefinition<InputsGeneric extends PropertyInitMapBase = any, StateInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> = (new () => HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) & StaticDeclarativeElementProperties<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys> & {
|
|
11
|
+
instanceType: HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
12
|
+
};
|
|
13
|
+
export declare abstract class DeclarativeElement<InputsGeneric extends PropertyInitMapBase = any, StateInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> extends LitElement {
|
|
14
|
+
static readonly tagName: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['tagName'];
|
|
15
|
+
static readonly styles: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['styles'];
|
|
16
|
+
static readonly isStrictInstance: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['isStrictInstance'];
|
|
17
|
+
static readonly renderCallback: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['renderCallback'];
|
|
18
|
+
static readonly inputsType: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['inputsType'];
|
|
19
|
+
static readonly stateType: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateType'];
|
|
20
|
+
static readonly events: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['events'];
|
|
21
|
+
static readonly stateInit: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateInit'];
|
|
22
|
+
static readonly init: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['init'];
|
|
23
|
+
static readonly hostClasses: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['hostClasses'];
|
|
24
|
+
static readonly cssVarNames: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarNames'];
|
|
25
|
+
static readonly cssVarValues: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarValues'];
|
|
26
|
+
abstract render(): TemplateResult | Promise<TemplateResult>;
|
|
27
|
+
abstract readonly instanceState: StateInitGeneric;
|
|
28
|
+
abstract readonly instanceInputs: InputsGeneric;
|
|
29
|
+
abstract assignInputs(inputs: InputsGeneric): void;
|
|
30
|
+
abstract readonly haveInputsBeenSet: boolean;
|
|
31
|
+
abstract markInputsAsHavingBeenSet(): void;
|
|
32
|
+
abstract readonly definition: DeclarativeElementDefinition<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
33
|
+
}
|
|
34
|
+
export interface StaticDeclarativeElementProperties<InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> {
|
|
35
|
+
/** Pass through the render callback for direct unit testability */
|
|
36
|
+
readonly renderCallback: RenderCallback<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
37
|
+
events: EventDescriptorMap<EventsInitGeneric>;
|
|
38
|
+
stateInit: ElementPropertyDescriptorMap<StateInitGeneric>;
|
|
39
|
+
init: RequiredBy<DeclarativeElementInit<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'stateInit' | 'events'>;
|
|
40
|
+
inputsType: InputsGeneric;
|
|
41
|
+
stateType: StateInitGeneric;
|
|
42
|
+
isStrictInstance: (element: unknown) => element is DeclarativeElement<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
43
|
+
hostClasses: HostClassNamesMap<string, HostClassKeys>;
|
|
44
|
+
cssVarNames: CssVarNameOrValueMap<CssVarKeys>;
|
|
45
|
+
cssVarValues: CssVarNameOrValueMap<CssVarKeys>;
|
|
46
|
+
tagName: string;
|
|
47
|
+
styles: CSSResult;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=declarative-element.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement } from 'lit';
|
|
8
|
+
function staticImplements() {
|
|
9
|
+
return (constructor) => {
|
|
10
|
+
constructor;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
let DeclarativeElement = class DeclarativeElement extends LitElement {
|
|
14
|
+
};
|
|
15
|
+
DeclarativeElement = __decorate([
|
|
16
|
+
staticImplements()
|
|
17
|
+
], DeclarativeElement);
|
|
18
|
+
export { DeclarativeElement };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DeclarativeElementDefinition } from './declarative-element';
|
|
2
|
+
import { DeclarativeElementInit } from './declarative-element-init';
|
|
3
|
+
import { EventsInitMap } from './properties/element-events';
|
|
4
|
+
import { PropertyInitMapBase } from './properties/element-properties';
|
|
5
|
+
export declare function defineElementNoInputs<InputsGeneric extends PropertyInitMapBase = {}, StateGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = '', CssVarKeys extends string = ''>(initInput: DeclarativeElementInit<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>): DeclarativeElementDefinition<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
6
|
+
//# sourceMappingURL=define-element-no-inputs.d.ts.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getObjectTypedKeys, kebabCaseToCamelCase } from '@augment-vir/common';
|
|
2
|
+
import { css } from 'lit';
|
|
3
|
+
import { property } from 'lit/decorators.js';
|
|
4
|
+
import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
|
|
5
|
+
import { DeclarativeElement, } from './declarative-element';
|
|
6
|
+
import { defaultDeclarativeElementDefinitionOptions, IgnoreInputsNotBeenSetBeforeRenderWarningSymbol, } from './definition-options';
|
|
7
|
+
import { assign } from './directives/assign.directive';
|
|
8
|
+
import { hasDeclarativeElementParent } from './has-declarative-element-parent';
|
|
9
|
+
import { createCssVarNamesMap, createCssVarValuesMap } from './properties/css-vars';
|
|
10
|
+
import { createEventDescriptorMap } from './properties/element-events';
|
|
11
|
+
import { createElementUpdaterProxy } from './properties/element-updater-proxy';
|
|
12
|
+
import { createHostClassNamesMap } from './properties/host-classes';
|
|
13
|
+
import { applyHostClasses, hostClassNamesToStylesInput } from './properties/styles';
|
|
14
|
+
import { createRenderParams } from './render-callback';
|
|
15
|
+
export function defineElementNoInputs(initInput) {
|
|
16
|
+
var _a;
|
|
17
|
+
const eventsMap = createEventDescriptorMap(initInput.events);
|
|
18
|
+
const hostClassNames = createHostClassNamesMap(initInput.tagName, initInput.hostClasses);
|
|
19
|
+
const cssVarNames = createCssVarNamesMap(initInput.tagName, initInput.cssVars);
|
|
20
|
+
const cssVarValues = createCssVarValuesMap(initInput.cssVars, cssVarNames);
|
|
21
|
+
const elementOptions = {
|
|
22
|
+
...defaultDeclarativeElementDefinitionOptions,
|
|
23
|
+
...initInput.options,
|
|
24
|
+
};
|
|
25
|
+
const calculatedStyles = typeof initInput.styles === 'function'
|
|
26
|
+
? initInput.styles(hostClassNamesToStylesInput({ hostClassNames, cssVarNames, cssVarValues }))
|
|
27
|
+
: initInput.styles || css ``;
|
|
28
|
+
const typedRenderCallback = initInput.renderCallback;
|
|
29
|
+
const anonymousClass = (_a = class extends DeclarativeElement {
|
|
30
|
+
createRenderParams() {
|
|
31
|
+
return createRenderParams(this, eventsMap);
|
|
32
|
+
}
|
|
33
|
+
get instanceType() {
|
|
34
|
+
throw new Error(`"instanceType" was called on ${initInput.tagName} as a value but it is only for types.`);
|
|
35
|
+
}
|
|
36
|
+
static get inputsType() {
|
|
37
|
+
throw new Error(`"inputsType" was called on ${initInput.tagName} as a value but it is only for types.`);
|
|
38
|
+
}
|
|
39
|
+
static get stateType() {
|
|
40
|
+
throw new Error(`"stateType" was called on ${initInput.tagName} as a value but it is only for types.`);
|
|
41
|
+
}
|
|
42
|
+
markInputsAsHavingBeenSet() {
|
|
43
|
+
if (!this.haveInputsBeenSet) {
|
|
44
|
+
this.haveInputsBeenSet = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
render() {
|
|
48
|
+
if (
|
|
49
|
+
// This ignores elements at the root of a page, as they can't receive inputs from
|
|
50
|
+
// other elements (cause they have no custom element ancestors).
|
|
51
|
+
hasDeclarativeElementParent(this) &&
|
|
52
|
+
!this.haveInputsBeenSet &&
|
|
53
|
+
!elementOptions[IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]) {
|
|
54
|
+
console.warn(this, `${initInput.tagName} got rendered before its input object was set. This was most likely caused by forgetting to use the "${assign.name}" directive on it. If no inputs are intended, use "${defineElementNoInputs.name}" to define ${initInput.tagName}.`);
|
|
55
|
+
}
|
|
56
|
+
const renderParams = this.createRenderParams();
|
|
57
|
+
if (!this.initCalled && initInput.initCallback) {
|
|
58
|
+
this.initCalled = true;
|
|
59
|
+
initInput.initCallback(renderParams);
|
|
60
|
+
}
|
|
61
|
+
const renderResult = initInput.renderCallback(renderParams);
|
|
62
|
+
applyHostClasses({
|
|
63
|
+
host: renderParams.host,
|
|
64
|
+
hostClassesInit: initInput.hostClasses,
|
|
65
|
+
hostClassNames,
|
|
66
|
+
state: renderParams.state,
|
|
67
|
+
inputs: renderParams.inputs,
|
|
68
|
+
});
|
|
69
|
+
return renderResult;
|
|
70
|
+
}
|
|
71
|
+
disconnectedCallback() {
|
|
72
|
+
super.disconnectedCallback();
|
|
73
|
+
if (initInput.cleanupCallback) {
|
|
74
|
+
const renderParams = this.createRenderParams();
|
|
75
|
+
initInput.cleanupCallback(renderParams);
|
|
76
|
+
}
|
|
77
|
+
this.initCalled = false;
|
|
78
|
+
}
|
|
79
|
+
assignInputs(inputs) {
|
|
80
|
+
getObjectTypedKeys(inputs).forEach((key) => {
|
|
81
|
+
property()(this, key);
|
|
82
|
+
this.instanceInputs[key] = inputs[key];
|
|
83
|
+
});
|
|
84
|
+
this.markInputsAsHavingBeenSet();
|
|
85
|
+
}
|
|
86
|
+
constructor() {
|
|
87
|
+
super();
|
|
88
|
+
this.initCalled = false;
|
|
89
|
+
this.haveInputsBeenSet = false;
|
|
90
|
+
// this is set below in Object.defineProperties
|
|
91
|
+
this.definition = {};
|
|
92
|
+
this.instanceInputs = createElementUpdaterProxy(this, false);
|
|
93
|
+
this.instanceState = createElementUpdaterProxy(this, true);
|
|
94
|
+
const stateInit = initInput.stateInit || {};
|
|
95
|
+
Object.keys(stateInit).forEach((propName) => {
|
|
96
|
+
property()(this, propName);
|
|
97
|
+
this.instanceState[propName] = stateInit[propName];
|
|
98
|
+
});
|
|
99
|
+
this.definition = anonymousClass;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
_a.tagName = initInput.tagName,
|
|
103
|
+
_a.styles = calculatedStyles,
|
|
104
|
+
// this gets set below in Object.defineProperties
|
|
105
|
+
_a.isStrictInstance = () => false,
|
|
106
|
+
_a.events = eventsMap,
|
|
107
|
+
_a.renderCallback = typedRenderCallback,
|
|
108
|
+
_a.hostClasses = hostClassNames,
|
|
109
|
+
_a.cssVarNames = cssVarNames,
|
|
110
|
+
_a.stateInit = initInput.stateInit,
|
|
111
|
+
_a.cssVarValues = cssVarNames,
|
|
112
|
+
_a);
|
|
113
|
+
Object.defineProperties(anonymousClass, {
|
|
114
|
+
[DeclarativeElementMarkerSymbol]: {
|
|
115
|
+
value: true,
|
|
116
|
+
writable: false,
|
|
117
|
+
},
|
|
118
|
+
name: {
|
|
119
|
+
value: kebabCaseToCamelCase(initInput.tagName, {
|
|
120
|
+
capitalizeFirstLetter: true,
|
|
121
|
+
}),
|
|
122
|
+
writable: true,
|
|
123
|
+
},
|
|
124
|
+
isStrictInstance: {
|
|
125
|
+
value: (element) => {
|
|
126
|
+
return element instanceof anonymousClass;
|
|
127
|
+
},
|
|
128
|
+
writable: false,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
window.customElements.define(initInput.tagName, anonymousClass);
|
|
132
|
+
return anonymousClass;
|
|
133
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DeclarativeElementDefinition } from './declarative-element';
|
|
2
|
+
import { DeclarativeElementInit } from './declarative-element-init';
|
|
3
|
+
import { EventsInitMap } from './properties/element-events';
|
|
4
|
+
import { PropertyInitMapBase } from './properties/element-properties';
|
|
5
|
+
export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): <PropertyInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = "", CssVarKeys extends string = "">(initInput: DeclarativeElementInit<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => DeclarativeElementDefinition<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
6
|
+
//# sourceMappingURL=define-element.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineElementNoInputs } from './define-element-no-inputs';
|
|
2
|
+
import { IgnoreInputsNotBeenSetBeforeRenderWarningSymbol } from './definition-options';
|
|
3
|
+
export function defineElement() {
|
|
4
|
+
return (initInput) => {
|
|
5
|
+
return defineElementNoInputs({
|
|
6
|
+
...initInput,
|
|
7
|
+
options: {
|
|
8
|
+
[IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: false,
|
|
9
|
+
},
|
|
10
|
+
...initInput.options,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const IgnoreInputsNotBeenSetBeforeRenderWarningSymbol: unique symbol;
|
|
2
|
+
export type DeclarativeElementDefinitionOptions = {
|
|
3
|
+
[IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const defaultDeclarativeElementDefinitionOptions: DeclarativeElementDefinitionOptions;
|
|
6
|
+
//# sourceMappingURL=definition-options.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AsyncDirective } from 'lit/async-directive.js';
|
|
2
|
+
import { PartInfo } from 'lit/directive.js';
|
|
3
|
+
import { DeclarativeElementDefinition } from '../declarative-element';
|
|
4
|
+
export type CleanupCallback<T> = (oldValue: T) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Assign values but include a cleanup callback which gets called when a new value gets assigned so
|
|
7
|
+
* the previous value can get cleaned up. An optional equality check callback can be provided. If it
|
|
8
|
+
* is provided, the clean up callback will then only be called if the equality check callback
|
|
9
|
+
* resolves to false (which indicates that the previous value and the new value are not equal).
|
|
10
|
+
*
|
|
11
|
+
* Example use case: 3D graphics applications with classes that setup buffers and the like.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assignWithCleanup<DeclarativeElementGeneric extends DeclarativeElementDefinition>(elementDefinition: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric extends DeclarativeElementDefinition<infer InputsGeneric> ? InputsGeneric : never, cleanupCallback: CleanupCallback<DeclarativeElementGeneric extends DeclarativeElementDefinition<infer InputsGeneric> ? InputsGeneric : never>): import("lit-html/directive").DirectiveResult<typeof AssignWithCleanupDirectiveClass>;
|
|
14
|
+
declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
|
|
15
|
+
private readonly element;
|
|
16
|
+
private lastValue;
|
|
17
|
+
private lastCallback;
|
|
18
|
+
private hasBeenAssigned;
|
|
19
|
+
constructor(partInfo: PartInfo);
|
|
20
|
+
disconnected(): void;
|
|
21
|
+
render(elementDefinition: DeclarativeElementDefinition, inputsObject: Record<PropertyKey, unknown>, cleanupCallback: CleanupCallback<any>): symbol;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=assign-with-clean-up.directive.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { noChange } from 'lit';
|
|
2
|
+
import { AsyncDirective } from 'lit/async-directive.js';
|
|
3
|
+
import { directive } from 'lit/directive.js';
|
|
4
|
+
import { assignInputsObject } from './assign.directive';
|
|
5
|
+
import { extractDeclarativeElement } from './directive-helpers';
|
|
6
|
+
/**
|
|
7
|
+
* Assign values but include a cleanup callback which gets called when a new value gets assigned so
|
|
8
|
+
* the previous value can get cleaned up. An optional equality check callback can be provided. If it
|
|
9
|
+
* is provided, the clean up callback will then only be called if the equality check callback
|
|
10
|
+
* resolves to false (which indicates that the previous value and the new value are not equal).
|
|
11
|
+
*
|
|
12
|
+
* Example use case: 3D graphics applications with classes that setup buffers and the like.
|
|
13
|
+
*/
|
|
14
|
+
export function assignWithCleanup(elementDefinition, inputsObject, cleanupCallback) {
|
|
15
|
+
/**
|
|
16
|
+
* The directive generics (in listenDirective) are not strong enough to maintain their values.
|
|
17
|
+
* Thus, the directive call is wrapped in this function.
|
|
18
|
+
*/
|
|
19
|
+
return assignWithCleanupDirective(elementDefinition, inputsObject, cleanupCallback);
|
|
20
|
+
}
|
|
21
|
+
class AssignWithCleanupDirectiveClass extends AsyncDirective {
|
|
22
|
+
constructor(partInfo) {
|
|
23
|
+
super(partInfo);
|
|
24
|
+
this.hasBeenAssigned = false;
|
|
25
|
+
this.element = extractDeclarativeElement(partInfo, 'assign');
|
|
26
|
+
}
|
|
27
|
+
disconnected() {
|
|
28
|
+
if (this.lastValue != undefined && this.lastCallback != undefined) {
|
|
29
|
+
this.lastCallback(this.lastValue);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
render(elementDefinition, inputsObject, cleanupCallback) {
|
|
33
|
+
if (this.hasBeenAssigned) {
|
|
34
|
+
cleanupCallback(this.lastValue);
|
|
35
|
+
}
|
|
36
|
+
assignInputsObject(elementDefinition, this.element, inputsObject);
|
|
37
|
+
this.hasBeenAssigned = true;
|
|
38
|
+
this.lastValue = inputsObject;
|
|
39
|
+
this.lastCallback = cleanupCallback;
|
|
40
|
+
return noChange;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const assignWithCleanupDirective = directive(AssignWithCleanupDirectiveClass);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PartInfo } from 'lit/directive.js';
|
|
2
|
+
import { DeclarativeElement, DeclarativeElementDefinition } from '../declarative-element';
|
|
3
|
+
/** Assign an object matching an element's inputs to its inputs. */
|
|
4
|
+
export declare function assign<DeclarativeElementGeneric extends DeclarativeElementDefinition>(declarativeElement: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric['inputsType']): import("lit-html/directive").DirectiveResult<{
|
|
5
|
+
new (partInfo: PartInfo): {
|
|
6
|
+
readonly element: DeclarativeElement<any, any, any, string, string>;
|
|
7
|
+
render(elementDefinition: DeclarativeElementDefinition<any, any, any, string, string>, inputsObject: Record<PropertyKey, unknown>): symbol;
|
|
8
|
+
readonly _$isConnected: boolean;
|
|
9
|
+
update(_part: import("lit-html").Part, props: unknown[]): unknown;
|
|
10
|
+
};
|
|
11
|
+
}>;
|
|
12
|
+
export declare function assignInputsObject<DeclarativeElementInstanceGeneric extends DeclarativeElement, DeclarativeElementDefinitionGeneric extends DeclarativeElementDefinition>(expectedElementConstructor: DeclarativeElementDefinitionGeneric, element: DeclarativeElementInstanceGeneric, assignmentObject: DeclarativeElementDefinitionGeneric['inputsType']): void;
|
|
13
|
+
//# sourceMappingURL=assign.directive.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { noChange } from 'lit';
|
|
2
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
3
|
+
import { extractDeclarativeElement } from './directive-helpers';
|
|
4
|
+
/** Assign an object matching an element's inputs to its inputs. */
|
|
5
|
+
export function assign(declarativeElement, inputsObject) {
|
|
6
|
+
/**
|
|
7
|
+
* The directive generics (in listenDirective) are not strong enough to maintain their values.
|
|
8
|
+
* Thus, the directive call is wrapped in this function.
|
|
9
|
+
*/
|
|
10
|
+
return assignDirective(declarativeElement, inputsObject);
|
|
11
|
+
}
|
|
12
|
+
const assignDirective = directive(class extends Directive {
|
|
13
|
+
constructor(partInfo) {
|
|
14
|
+
super(partInfo);
|
|
15
|
+
this.element = extractDeclarativeElement(partInfo, 'assign');
|
|
16
|
+
}
|
|
17
|
+
render(elementDefinition, inputsObject) {
|
|
18
|
+
assignInputsObject(elementDefinition, this.element, inputsObject);
|
|
19
|
+
return noChange;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export function assignInputsObject(expectedElementConstructor, element, assignmentObject) {
|
|
23
|
+
if (element.tagName.toLowerCase() !== expectedElementConstructor.tagName.toLowerCase()) {
|
|
24
|
+
console.error(element, expectedElementConstructor);
|
|
25
|
+
throw new Error(`Assignment mismatch. Assignment was made for ${element.tagName.toLowerCase()} but it's attached to ${expectedElementConstructor.tagName.toLowerCase()}`);
|
|
26
|
+
}
|
|
27
|
+
element.assignInputs(assignmentObject);
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ElementPartInfo, PartInfo } from 'lit/directive.js';
|
|
2
|
+
import { DeclarativeElement } from '../declarative-element';
|
|
3
|
+
/** For some reason these aren't defined in lit's types already. */
|
|
4
|
+
export type ExtraPartInfoProperties = {
|
|
5
|
+
element: Element;
|
|
6
|
+
options: {
|
|
7
|
+
host: Element;
|
|
8
|
+
renderBefore: Element;
|
|
9
|
+
isConnected: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function extractDeclarativeElement(partInfo: PartInfo, directiveName: string): DeclarativeElement;
|
|
13
|
+
export declare function extractElement<ElementType = HTMLElement>(partInfo: PartInfo, directiveName: string, constructorClass: (new () => ElementType) | (abstract new () => ElementType)): ElementType;
|
|
14
|
+
export declare function assertIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
|
|
15
|
+
//# sourceMappingURL=directive-helpers.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PartType } from 'lit/directive.js';
|
|
2
|
+
import { DeclarativeElement } from '../declarative-element';
|
|
3
|
+
export function extractDeclarativeElement(partInfo, directiveName) {
|
|
4
|
+
return extractElement(partInfo, directiveName, DeclarativeElement);
|
|
5
|
+
}
|
|
6
|
+
export function extractElement(partInfo, directiveName, constructorClass) {
|
|
7
|
+
assertIsElementPartInfo(partInfo, directiveName);
|
|
8
|
+
const element = partInfo.element;
|
|
9
|
+
if (!(element instanceof constructorClass)) {
|
|
10
|
+
throw new Error(`${directiveName} attached to non ${constructorClass.name} element.`);
|
|
11
|
+
}
|
|
12
|
+
return element;
|
|
13
|
+
}
|
|
14
|
+
export function assertIsElementPartInfo(partInfo, directiveName) {
|
|
15
|
+
if (partInfo.type !== PartType.ELEMENT) {
|
|
16
|
+
throw new Error(`${directiveName} directive can only be attached directly to an element.`);
|
|
17
|
+
}
|
|
18
|
+
if (!partInfo.element) {
|
|
19
|
+
throw new Error(`${directiveName} directive found no element.`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DirectiveResult } from 'lit/directive.js';
|
|
2
|
+
import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
|
|
3
|
+
/**
|
|
4
|
+
* Listen to events. These can be native DOM events (use a string for the inputType argument) or
|
|
5
|
+
* typed events (pass in a return value from defineTypedEvent).
|
|
6
|
+
*
|
|
7
|
+
* @param definedTypedEvent Needs to come either from a declarative element (like
|
|
8
|
+
* MyDeclarativeElement.events.eventName) or from a typed event created via the defineTypedEvent
|
|
9
|
+
* function.
|
|
10
|
+
* @param listener The callback to fire when an event is caught. Assuming the definedTypedEvent
|
|
11
|
+
* input is properly typed, the event given to this callback will also be typed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: DefinedTypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>, listener: (event: TypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>) => void): DirectiveResult<any>;
|
|
14
|
+
export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: NativeElementEventNameGeneric, listener: (event: HTMLElementEventMap[NativeElementEventNameGeneric]) => void): DirectiveResult<any>;
|
|
15
|
+
//# sourceMappingURL=listen.directive.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { noChange } from 'lit';
|
|
2
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
3
|
+
import { extractElement } from './directive-helpers';
|
|
4
|
+
export function listen(eventType, listener) {
|
|
5
|
+
return listenDirective(eventType, listener);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The directive generics here are not strong enough to maintain their values. Thus, the directive
|
|
9
|
+
* call is wrapped in the function above.
|
|
10
|
+
*/
|
|
11
|
+
const listenDirective = directive(class extends Directive {
|
|
12
|
+
constructor(partInfo) {
|
|
13
|
+
super(partInfo);
|
|
14
|
+
this.element = extractElement(partInfo, 'listen', HTMLElement);
|
|
15
|
+
}
|
|
16
|
+
resetListener(listenerMetaData) {
|
|
17
|
+
if (this.lastListenerMetaData) {
|
|
18
|
+
this.element.removeEventListener(this.lastListenerMetaData.eventType, this.lastListenerMetaData.listener);
|
|
19
|
+
}
|
|
20
|
+
this.element.addEventListener(listenerMetaData.eventType, listenerMetaData.listener);
|
|
21
|
+
this.lastListenerMetaData = listenerMetaData;
|
|
22
|
+
}
|
|
23
|
+
createListenerMetaData(eventType, callback) {
|
|
24
|
+
return {
|
|
25
|
+
eventType,
|
|
26
|
+
callback,
|
|
27
|
+
listener: (event) => { var _a; return (_a = this.lastListenerMetaData) === null || _a === void 0 ? void 0 : _a.callback(event); },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
render(eventTypeInput, callback) {
|
|
31
|
+
const eventType = typeof eventTypeInput === 'string' ? eventTypeInput : eventTypeInput.type;
|
|
32
|
+
if (typeof eventType !== 'string') {
|
|
33
|
+
throw new Error(`Cannot listen to an event with a name that is not a string. Given event name: "${eventType}"`);
|
|
34
|
+
}
|
|
35
|
+
if (this.lastListenerMetaData && this.lastListenerMetaData.eventType === eventType) {
|
|
36
|
+
/**
|
|
37
|
+
* Store the callback here so we don't have to update the attached listener every
|
|
38
|
+
* time the callback is updated.
|
|
39
|
+
*/
|
|
40
|
+
this.lastListenerMetaData.callback = callback;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.resetListener(this.createListenerMetaData(eventType, callback));
|
|
44
|
+
}
|
|
45
|
+
return noChange;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PartInfo } from 'lit/directive.js';
|
|
2
|
+
export type OnDomCreatedCallback = (element: Element) => void;
|
|
3
|
+
/** Only fires once, when the element has been created. */
|
|
4
|
+
export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("lit-html/directive").DirectiveResult<{
|
|
5
|
+
new (partInfo: PartInfo): {
|
|
6
|
+
element: Element | undefined;
|
|
7
|
+
update(partInfo: PartInfo, [callback]: [OnDomCreatedCallback]): undefined;
|
|
8
|
+
render(callback: OnDomCreatedCallback): undefined;
|
|
9
|
+
readonly _$isConnected: boolean;
|
|
10
|
+
};
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=on-dom-created.directive.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { directive, Directive } from 'lit/directive.js';
|
|
2
|
+
import { assertIsElementPartInfo } from './directive-helpers';
|
|
3
|
+
const directiveName = 'onDomCreated';
|
|
4
|
+
/** Only fires once, when the element has been created. */
|
|
5
|
+
export const onDomCreated = directive(class extends Directive {
|
|
6
|
+
constructor(partInfo) {
|
|
7
|
+
super(partInfo);
|
|
8
|
+
assertIsElementPartInfo(partInfo, directiveName);
|
|
9
|
+
}
|
|
10
|
+
update(partInfo, [callback]) {
|
|
11
|
+
assertIsElementPartInfo(partInfo, directiveName);
|
|
12
|
+
const newElement = partInfo.element;
|
|
13
|
+
if (newElement !== this.element) {
|
|
14
|
+
// use requestAnimationFrame here so it can fire property changes outside of a render loop
|
|
15
|
+
requestAnimationFrame(() => callback(newElement));
|
|
16
|
+
this.element = newElement;
|
|
17
|
+
}
|
|
18
|
+
return this.render(callback);
|
|
19
|
+
}
|
|
20
|
+
render(callback) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PartInfo } from 'lit/directive.js';
|
|
2
|
+
export type OnResizeCallback = (
|
|
3
|
+
/** Only these two properties are supported in all major modern browsers */
|
|
4
|
+
entry: Readonly<Pick<ResizeObserverEntry, 'target' | 'contentRect'>>) => void;
|
|
5
|
+
export declare const onResize: (callback: OnResizeCallback) => import("lit-html/directive").DirectiveResult<{
|
|
6
|
+
new (partInfo: PartInfo): {
|
|
7
|
+
element: Element | undefined;
|
|
8
|
+
readonly resizeObserver: ResizeObserver;
|
|
9
|
+
callback: OnResizeCallback | undefined;
|
|
10
|
+
fireCallback(entries: ResizeObserverEntry[]): void;
|
|
11
|
+
update(partInfo: PartInfo, [callback]: [OnResizeCallback]): undefined;
|
|
12
|
+
render(callback: OnResizeCallback): undefined;
|
|
13
|
+
readonly _$isConnected: boolean;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=on-resize.directive.d.ts.map
|