element-vir 7.0.2 → 8.0.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/README.md +40 -0
- package/dist/declarative-element/declarative-element-init.d.ts +9 -9
- package/dist/declarative-element/declarative-element.d.ts +25 -25
- package/dist/declarative-element/define-element-no-inputs.d.ts +2 -2
- package/dist/declarative-element/define-element-no-inputs.js +6 -1
- package/dist/declarative-element/define-element.d.ts +1 -1
- package/dist/declarative-element/directives/assign-with-clean-up.directive.d.ts +1 -1
- package/dist/declarative-element/directives/assign.directive.d.ts +2 -2
- package/dist/declarative-element/render-callback.d.ts +7 -5
- package/dist/declarative-element/wrap-define-element.d.ts +11 -0
- package/dist/declarative-element/wrap-define-element.js +20 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -437,6 +437,46 @@ export const MyWithCssVarsElement = defineElementNoInputs({
|
|
|
437
437
|
});
|
|
438
438
|
```
|
|
439
439
|
|
|
440
|
+
## Custom Type Requirements
|
|
441
|
+
|
|
442
|
+
Use `wrapDefineElement` to compose `defineElement` and `defineElementNoInputs`. This is particularly useful to adding restrictions on the element `tagName`, but it can be used for restricting any of the inputs:
|
|
443
|
+
|
|
444
|
+
<!-- example-link: src/readme-examples/my-custom-define.ts -->
|
|
445
|
+
|
|
446
|
+
```TypeScript
|
|
447
|
+
import {wrapDefineElement} from 'element-vir';
|
|
448
|
+
|
|
449
|
+
export type VirTagName = `vir-${string}`;
|
|
450
|
+
|
|
451
|
+
export const {defineElement: defineVirElement, defineElementNoInputs: defineVirElementNoInputs} =
|
|
452
|
+
wrapDefineElement<VirTagName>();
|
|
453
|
+
|
|
454
|
+
// add an optional assert callback
|
|
455
|
+
export const {
|
|
456
|
+
defineElement: defineVerifiedVirElement,
|
|
457
|
+
defineElementNoInputs: defineVerifiedVirElementNoInputs,
|
|
458
|
+
} = wrapDefineElement<VirTagName>({
|
|
459
|
+
assertInputs: (inputs) => {
|
|
460
|
+
if (!inputs.tagName.startsWith('vir-')) {
|
|
461
|
+
throw new Error(`all custom elements must start with "vir-"`);
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// add an optional transform callback
|
|
467
|
+
export const {
|
|
468
|
+
defineElement: defineTransformedVirElement,
|
|
469
|
+
defineElementNoInputs: defineTransformedVirElementNoInputs,
|
|
470
|
+
} = wrapDefineElement<VirTagName>({
|
|
471
|
+
transformInputs: (inputs) => {
|
|
472
|
+
return {
|
|
473
|
+
...inputs,
|
|
474
|
+
tagName: inputs.tagName.startsWith('vir-') ? `vir-${inputs.tagName}` : inputs.tagName,
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
```
|
|
479
|
+
|
|
440
480
|
## Directives
|
|
441
481
|
|
|
442
482
|
The following custom [`lit` directives](https://lit.dev/docs/templates/custom-directives/) are contained within this package.
|
|
@@ -7,16 +7,16 @@ import { HostClassesInitMap } from './properties/host-classes';
|
|
|
7
7
|
import { StylesCallback } from './properties/styles';
|
|
8
8
|
import { InitCallback, RenderCallback } from './render-callback';
|
|
9
9
|
export type CustomElementTagName = `${string}-${string}`;
|
|
10
|
-
export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase,
|
|
10
|
+
export type DeclarativeElementInit<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeysGeneric extends string, CssVarKeysGeneric extends string> = {
|
|
11
11
|
/**
|
|
12
12
|
* HTML tag name. This should not be used directly, as interpolating it with the html tagged
|
|
13
13
|
* template from this package is preferred.
|
|
14
14
|
*/
|
|
15
|
-
tagName:
|
|
15
|
+
tagName: TagNameGeneric;
|
|
16
16
|
/** Static styles. These should not and cannot change. */
|
|
17
|
-
styles?: CSSResult | StylesCallback<
|
|
17
|
+
styles?: CSSResult | StylesCallback<HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
18
18
|
/** Element properties. (These can be thought of as "inputs".) */
|
|
19
|
-
stateInit?:
|
|
19
|
+
stateInit?: StateInitGeneric;
|
|
20
20
|
/** Events that the element can dispatch. (These can be thought of as "outputs".) */
|
|
21
21
|
events?: EventsInitGeneric;
|
|
22
22
|
/**
|
|
@@ -24,7 +24,7 @@ export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, St
|
|
|
24
24
|
* based on current instance state or inputs, or just undefined to indicate that the host class
|
|
25
25
|
* will only be manually set.
|
|
26
26
|
*/
|
|
27
|
-
hostClasses?: HostClassesInitMap<
|
|
27
|
+
hostClasses?: HostClassesInitMap<HostClassKeysGeneric, InputsGeneric, StateInitGeneric>;
|
|
28
28
|
/**
|
|
29
29
|
* CSS Vars for the component. Keys of this object should be camelCased (or whatever your casing
|
|
30
30
|
* convention is). They will be transformed, at runtime, to CSS vars with kebab-casing, to match
|
|
@@ -35,11 +35,11 @@ export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, St
|
|
|
35
35
|
* cssVarValues or cssVarNames can then be destructured from the styles property's callback
|
|
36
36
|
* input.
|
|
37
37
|
*/
|
|
38
|
-
cssVars?: CssVarsInitMap<
|
|
38
|
+
cssVars?: CssVarsInitMap<CssVarKeysGeneric>;
|
|
39
39
|
/** Called as part of the first renderCallback call, before the first renderCallback call. */
|
|
40
|
-
initCallback?: InitCallback<InputsGeneric,
|
|
41
|
-
renderCallback: RenderCallback<InputsGeneric,
|
|
42
|
-
cleanupCallback?: InitCallback<InputsGeneric,
|
|
40
|
+
initCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
41
|
+
renderCallback: RenderCallback<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
42
|
+
cleanupCallback?: InitCallback<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
43
43
|
options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
|
|
44
44
|
};
|
|
45
45
|
//# sourceMappingURL=declarative-element-init.d.ts.map
|
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
|
|
2
|
-
import { CSSResult, LitElement
|
|
3
|
-
import { DeclarativeElementInit } from './declarative-element-init';
|
|
2
|
+
import { CSSResult, LitElement } from 'lit';
|
|
3
|
+
import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
|
|
4
4
|
import { CssVarNameOrValueMap } from './properties/css-vars';
|
|
5
5
|
import { EventDescriptorMap, EventsInitMap } from './properties/element-events';
|
|
6
6
|
import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './properties/element-properties';
|
|
7
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>;
|
|
8
|
+
import { RenderCallback, RenderOutput } from './render-callback';
|
|
9
|
+
export type HostInstanceType<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = RequiredAndNotNullBy<DeclarativeElement<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'shadowRoot'>;
|
|
10
|
+
export type DeclarativeElementDefinition<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> = (new () => HostInstanceType<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) & StaticDeclarativeElementProperties<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys> & {
|
|
11
|
+
instanceType: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
12
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():
|
|
13
|
+
export declare abstract class DeclarativeElement<TagNameGeneric extends CustomElementTagName = CustomElementTagName, 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<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['tagName'];
|
|
15
|
+
static readonly styles: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['styles'];
|
|
16
|
+
static readonly isStrictInstance: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['isStrictInstance'];
|
|
17
|
+
static readonly renderCallback: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['renderCallback'];
|
|
18
|
+
static readonly inputsType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['inputsType'];
|
|
19
|
+
static readonly stateType: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateType'];
|
|
20
|
+
static readonly events: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['events'];
|
|
21
|
+
static readonly stateInit: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateInit'];
|
|
22
|
+
static readonly init: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['init'];
|
|
23
|
+
static readonly hostClasses: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['hostClasses'];
|
|
24
|
+
static readonly cssVarNames: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarNames'];
|
|
25
|
+
static readonly cssVarValues: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarValues'];
|
|
26
|
+
abstract render(): RenderOutput;
|
|
27
27
|
abstract readonly instanceState: StateInitGeneric;
|
|
28
28
|
abstract readonly instanceInputs: InputsGeneric;
|
|
29
29
|
abstract assignInputs(inputs: InputsGeneric): void;
|
|
30
30
|
abstract readonly haveInputsBeenSet: boolean;
|
|
31
31
|
abstract markInputsAsHavingBeenSet(): void;
|
|
32
|
-
abstract readonly definition: DeclarativeElementDefinition<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
32
|
+
abstract readonly definition: DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
33
33
|
}
|
|
34
|
-
export interface StaticDeclarativeElementProperties<InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> {
|
|
34
|
+
export interface StaticDeclarativeElementProperties<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> {
|
|
35
35
|
/** Pass through the render callback for direct unit testability */
|
|
36
|
-
readonly renderCallback: RenderCallback<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
36
|
+
readonly renderCallback: RenderCallback<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
37
37
|
events: EventDescriptorMap<EventsInitGeneric>;
|
|
38
38
|
stateInit: ElementPropertyDescriptorMap<StateInitGeneric>;
|
|
39
|
-
init: RequiredBy<DeclarativeElementInit<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'stateInit' | 'events'>;
|
|
39
|
+
init: RequiredBy<DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'stateInit' | 'events'>;
|
|
40
40
|
inputsType: InputsGeneric;
|
|
41
41
|
stateType: StateInitGeneric;
|
|
42
|
-
isStrictInstance: (element: unknown) => element is DeclarativeElement<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
42
|
+
isStrictInstance: (element: unknown) => element is DeclarativeElement<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
43
43
|
hostClasses: HostClassNamesMap<string, HostClassKeys>;
|
|
44
44
|
cssVarNames: CssVarNameOrValueMap<CssVarKeys>;
|
|
45
45
|
cssVarValues: CssVarNameOrValueMap<CssVarKeys>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeclarativeElementDefinition } from './declarative-element';
|
|
2
|
-
import { DeclarativeElementInit } from './declarative-element-init';
|
|
2
|
+
import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
|
|
3
3
|
import { EventsInitMap } from './properties/element-events';
|
|
4
4
|
import { PropertyInitMapBase } from './properties/element-properties';
|
|
5
|
-
export declare function defineElementNoInputs<InputsGeneric extends PropertyInitMapBase = {},
|
|
5
|
+
export declare function defineElementNoInputs<TagNameGeneric extends CustomElementTagName = '-', InputsGeneric extends PropertyInitMapBase = {}, StateInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = '', CssVarKeys extends string = ''>(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>): DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
6
6
|
//# sourceMappingURL=define-element-no-inputs.d.ts.map
|
|
@@ -128,6 +128,11 @@ export function defineElementNoInputs(initInput) {
|
|
|
128
128
|
writable: false,
|
|
129
129
|
},
|
|
130
130
|
});
|
|
131
|
-
window.customElements.
|
|
131
|
+
if (window.customElements.get(initInput.tagName)) {
|
|
132
|
+
console.warn(`Tried to define custom element ${initInput.tagName} but it is already defined.`);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
window.customElements.define(initInput.tagName, anonymousClass);
|
|
136
|
+
}
|
|
132
137
|
return anonymousClass;
|
|
133
138
|
}
|
|
@@ -2,5 +2,5 @@ import { DeclarativeElementDefinition } from './declarative-element';
|
|
|
2
2
|
import { DeclarativeElementInit } from './declarative-element-init';
|
|
3
3
|
import { EventsInitMap } from './properties/element-events';
|
|
4
4
|
import { PropertyInitMapBase } from './properties/element-properties';
|
|
5
|
-
export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): <
|
|
5
|
+
export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): <TagNameGeneric extends `${string}-${string}`, StateInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeysGeneric extends string = "", CssVarKeysGeneric extends string = "">(initInput: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>) => DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
6
6
|
//# sourceMappingURL=define-element.d.ts.map
|
|
@@ -10,7 +10,7 @@ export type CleanupCallback<T> = (oldValue: T) => void;
|
|
|
10
10
|
*
|
|
11
11
|
* Example use case: 3D graphics applications with classes that setup buffers and the like.
|
|
12
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>;
|
|
13
|
+
export declare function assignWithCleanup<DeclarativeElementGeneric extends DeclarativeElementDefinition>(elementDefinition: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric extends DeclarativeElementDefinition<any, infer InputsGeneric> ? InputsGeneric : never, cleanupCallback: CleanupCallback<DeclarativeElementGeneric extends DeclarativeElementDefinition<any, infer InputsGeneric> ? InputsGeneric : never>): import("lit-html/directive").DirectiveResult<typeof AssignWithCleanupDirectiveClass>;
|
|
14
14
|
declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
|
|
15
15
|
private readonly element;
|
|
16
16
|
private lastValue;
|
|
@@ -3,8 +3,8 @@ import { DeclarativeElement, DeclarativeElementDefinition } from '../declarative
|
|
|
3
3
|
/** Assign an object matching an element's inputs to its inputs. */
|
|
4
4
|
export declare function assign<DeclarativeElementGeneric extends DeclarativeElementDefinition>(declarativeElement: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric['inputsType']): import("lit-html/directive").DirectiveResult<{
|
|
5
5
|
new (partInfo: PartInfo): {
|
|
6
|
-
readonly element: DeclarativeElement
|
|
7
|
-
render(elementDefinition: DeclarativeElementDefinition<any, any, any, string, string>, inputsObject: Record<PropertyKey, unknown>): symbol;
|
|
6
|
+
readonly element: DeclarativeElement<`${string}-${string}`, any, any, any, string, string>;
|
|
7
|
+
render(elementDefinition: DeclarativeElementDefinition<any, any, any, any, string, string>, inputsObject: Record<PropertyKey, unknown>): symbol;
|
|
8
8
|
readonly _$isConnected: boolean;
|
|
9
9
|
update(_part: import("lit-html").Part, props: unknown[]): unknown;
|
|
10
10
|
};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { TemplateResult } from 'lit';
|
|
2
2
|
import { TypedEvent } from '../typed-event/typed-event';
|
|
3
3
|
import { DeclarativeElement, HostInstanceType } from './declarative-element';
|
|
4
|
+
import { CustomElementTagName } from './declarative-element-init';
|
|
4
5
|
import { AsyncProp, SetAsyncPropInputs } from './properties/async-prop';
|
|
5
6
|
import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './properties/element-events';
|
|
6
7
|
import { PropertyInitMapBase } from './properties/element-properties';
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
8
|
+
export type RenderOutput = TemplateResult | string | ReadonlyArray<TemplateResult> | ReadonlyArray<string>;
|
|
9
|
+
export type RenderCallback<TagNameGeneric extends CustomElementTagName = any, InputsGeneric extends PropertyInitMapBase = any, StateGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = any, CssVarKeys extends string = any> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => RenderOutput;
|
|
10
|
+
export type InitCallback<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = (params: RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => void;
|
|
9
11
|
export type UpdateStateCallback<StateGeneric extends PropertyInitMapBase> = (newState: Partial<StateGeneric>) => void;
|
|
10
|
-
export type RenderParams<InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
|
|
12
|
+
export type RenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
|
|
11
13
|
state: Readonly<StateInitGeneric>;
|
|
12
14
|
updateState: UpdateStateCallback<StateInitGeneric>;
|
|
13
15
|
events: EventDescriptorMap<EventsInitGeneric>;
|
|
14
|
-
host: HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
16
|
+
host: HostInstanceType<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
15
17
|
dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>> | Event) => boolean;
|
|
16
18
|
inputs: InputsGeneric;
|
|
17
19
|
/**
|
|
@@ -23,5 +25,5 @@ export type RenderParams<InputsGeneric extends PropertyInitMapBase, StateInitGen
|
|
|
23
25
|
[StateKey in keyof StateInitGeneric as StateInitGeneric[StateKey] extends AsyncProp<any> ? StateKey : never]: StateInitGeneric[StateKey] extends AsyncProp<infer ValueGeneric> ? SetAsyncPropInputs<ValueGeneric> : never;
|
|
24
26
|
}>) => void;
|
|
25
27
|
};
|
|
26
|
-
export declare function createRenderParams<InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string>(element: DeclarativeElement<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
28
|
+
export declare function createRenderParams<TagNameGeneric extends CustomElementTagName, InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string>(element: DeclarativeElement<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<TagNameGeneric, InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
27
29
|
//# sourceMappingURL=render-callback.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PartialAndNullable } from '@augment-vir/common';
|
|
2
|
+
import { CustomElementTagName, DeclarativeElementInit, EventsInitMap, PropertyInitMapBase } from '..';
|
|
3
|
+
export type WrapDefineElementOptions<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = '', CssVarKeysRequirementGeneric extends string = ''> = PartialAndNullable<{
|
|
4
|
+
assertInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric>) => void;
|
|
5
|
+
transformInputs: (inputInit: DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric>) => DeclarativeElementInit<TagNameRequirementGeneric, InputsRequirementGeneric, StateInitRequirementGeneric, EventsInitRequirementGeneric, HostClassKeysRequirementGeneric, CssVarKeysRequirementGeneric>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function wrapDefineElement<TagNameRequirementGeneric extends CustomElementTagName = CustomElementTagName, InputsRequirementGeneric extends PropertyInitMapBase = {}, StateInitRequirementGeneric extends PropertyInitMapBase = {}, EventsInitRequirementGeneric extends EventsInitMap = {}, HostClassKeysRequirementGeneric extends string = '', CssVarKeysRequirementGeneric extends string = ''>(options?: WrapDefineElementOptions | undefined): {
|
|
8
|
+
defineElement: <InputsGeneric extends InputsRequirementGeneric>() => <TagNameGeneric extends TagNameRequirementGeneric, StateInitGeneric extends StateInitRequirementGeneric, EventsInitGeneric extends EventsInitRequirementGeneric, HostClassKeysGeneric extends HostClassKeysRequirementGeneric, CssVarKeysGeneric extends CssVarKeysRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeysGeneric, CssVarKeysGeneric>;
|
|
9
|
+
defineElementNoInputs: <TagNameGeneric_1 extends TagNameRequirementGeneric, InputsGeneric_1 extends InputsRequirementGeneric, StateInitGeneric_1 extends StateInitRequirementGeneric, EventsInitGeneric_1 extends EventsInitRequirementGeneric, HostClassKeysGeneric_1 extends HostClassKeysRequirementGeneric, CssVarKeysGeneric_1 extends CssVarKeysRequirementGeneric>(inputs: DeclarativeElementInit<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1>) => import("./declarative-element").DeclarativeElementDefinition<TagNameGeneric_1, InputsGeneric_1, StateInitGeneric_1, EventsInitGeneric_1, HostClassKeysGeneric_1, CssVarKeysGeneric_1>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=wrap-define-element.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineElement, defineElementNoInputs, } from '..';
|
|
2
|
+
export function wrapDefineElement(options) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const { assertInputs, transformInputs } = {
|
|
5
|
+
assertInputs: (_a = options === null || options === void 0 ? void 0 : options.assertInputs) !== null && _a !== void 0 ? _a : (() => { }),
|
|
6
|
+
transformInputs: (_b = options === null || options === void 0 ? void 0 : options.transformInputs) !== null && _b !== void 0 ? _b : ((inputs) => inputs),
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
defineElement: () => {
|
|
10
|
+
return (inputs) => {
|
|
11
|
+
assertInputs(inputs);
|
|
12
|
+
return defineElement()(transformInputs(inputs));
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
defineElementNoInputs: (inputs) => {
|
|
16
|
+
assertInputs(inputs);
|
|
17
|
+
return defineElementNoInputs(transformInputs(inputs));
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './declarative-element/declarative-element';
|
|
2
|
+
export * from './declarative-element/declarative-element-init';
|
|
2
3
|
export * from './declarative-element/define-element';
|
|
3
4
|
export * from './declarative-element/define-element-no-inputs';
|
|
4
5
|
export type { DeclarativeElementDefinitionOptions } from './declarative-element/definition-options';
|
|
@@ -11,9 +12,14 @@ export * from './declarative-element/directives/on-resize.directive';
|
|
|
11
12
|
export * from './declarative-element/directives/render-async-prop.directive';
|
|
12
13
|
export * from './declarative-element/directives/render-if.directive';
|
|
13
14
|
export * from './declarative-element/properties/async-prop';
|
|
15
|
+
export * from './declarative-element/properties/css-vars';
|
|
14
16
|
export * from './declarative-element/properties/element-events';
|
|
15
17
|
export * from './declarative-element/properties/element-properties';
|
|
18
|
+
export * from './declarative-element/properties/host-classes';
|
|
19
|
+
export * from './declarative-element/properties/styles';
|
|
20
|
+
export * from './declarative-element/properties/tag-name';
|
|
16
21
|
export * from './declarative-element/render-callback';
|
|
22
|
+
export * from './declarative-element/wrap-define-element';
|
|
17
23
|
export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
|
|
18
24
|
export * from './template-transforms/vir-css/vir-css';
|
|
19
25
|
export * from './template-transforms/vir-html/vir-html';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './declarative-element/declarative-element';
|
|
2
|
+
export * from './declarative-element/declarative-element-init';
|
|
2
3
|
export * from './declarative-element/define-element';
|
|
3
4
|
export * from './declarative-element/define-element-no-inputs';
|
|
4
5
|
export * from './declarative-element/directives/assign-with-clean-up.directive';
|
|
@@ -10,9 +11,14 @@ export * from './declarative-element/directives/on-resize.directive';
|
|
|
10
11
|
export * from './declarative-element/directives/render-async-prop.directive';
|
|
11
12
|
export * from './declarative-element/directives/render-if.directive';
|
|
12
13
|
export * from './declarative-element/properties/async-prop';
|
|
14
|
+
export * from './declarative-element/properties/css-vars';
|
|
13
15
|
export * from './declarative-element/properties/element-events';
|
|
14
16
|
export * from './declarative-element/properties/element-properties';
|
|
17
|
+
export * from './declarative-element/properties/host-classes';
|
|
18
|
+
export * from './declarative-element/properties/styles';
|
|
19
|
+
export * from './declarative-element/properties/tag-name';
|
|
15
20
|
export * from './declarative-element/render-callback';
|
|
21
|
+
export * from './declarative-element/wrap-define-element';
|
|
16
22
|
export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
|
|
17
23
|
export * from './template-transforms/vir-css/vir-css';
|
|
18
24
|
export * from './template-transforms/vir-html/vir-html';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-vir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"custom",
|
|
6
6
|
"web",
|
|
@@ -31,20 +31,21 @@
|
|
|
31
31
|
"publish": "virmator publish \"npm run compile && npm run test:all\"",
|
|
32
32
|
"start": "npm install && virmator frontend",
|
|
33
33
|
"test": "npm run test:types && virmator test-web",
|
|
34
|
-
"test:all": "npm run test:types && npm test && npm run test:spelling && npm run test:format && npm run test:docs",
|
|
34
|
+
"test:all": "npm run test:types && npm run test:coverage && npm run test:spelling && npm run test:format && npm run test:docs",
|
|
35
|
+
"test:coverage": "virmator test-web coverage",
|
|
35
36
|
"test:docs": "virmator code-in-markdown check",
|
|
36
37
|
"test:format": "virmator format check",
|
|
37
38
|
"test:spelling": "virmator spellcheck",
|
|
38
39
|
"test:types": "tsc --noEmit"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@augment-vir/browser": "^
|
|
42
|
-
"@augment-vir/common": "^
|
|
42
|
+
"@augment-vir/browser": "^11.0.0",
|
|
43
|
+
"@augment-vir/common": "^11.0.0",
|
|
43
44
|
"lit": "2.6.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/browser-testing": "^
|
|
47
|
-
"@augment-vir/node-js": "^
|
|
47
|
+
"@augment-vir/browser-testing": "^11.0.0",
|
|
48
|
+
"@augment-vir/node-js": "^11.0.0",
|
|
48
49
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
49
50
|
"@open-wc/testing": "^3.1.7",
|
|
50
51
|
"@types/mocha": "^10.0.1",
|
|
@@ -66,9 +67,9 @@
|
|
|
66
67
|
"prettier-plugin-sort-json": "^1.0.0",
|
|
67
68
|
"prettier-plugin-toml": "^0.3.1",
|
|
68
69
|
"ts-node": "^10.9.1",
|
|
69
|
-
"type-fest": "^3.5.
|
|
70
|
+
"type-fest": "^3.5.3",
|
|
70
71
|
"typescript": "^4.9.4",
|
|
71
|
-
"virmator": "^5.
|
|
72
|
+
"virmator": "^5.4.0",
|
|
72
73
|
"vite": "^4.0.4"
|
|
73
74
|
}
|
|
74
75
|
}
|