element-vir 14.2.1 → 15.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 +1 -1
- package/dist/declarative-element/declarative-element-init.d.ts +1 -1
- package/dist/declarative-element/declarative-element.d.ts +4 -5
- package/dist/declarative-element/define-element-no-inputs.js +2 -2
- package/dist/declarative-element/directives/assign-with-clean-up.directive.js +2 -2
- package/dist/declarative-element/directives/assign.directive.d.ts +12 -8
- package/dist/declarative-element/directives/assign.directive.js +11 -4
- package/dist/declarative-element/properties/element-updater-proxy.d.ts +1 -1
- package/dist/declarative-element/properties/element-updater-proxy.js +4 -4
- package/dist/declarative-element/render-callback.d.ts +1 -1
- package/package.json +9 -10
- package/www-static/index.css +7 -0
package/README.md
CHANGED
|
@@ -637,7 +637,7 @@ export const MyWithRenderIf = defineElement<{shouldRender: boolean}>()({
|
|
|
637
637
|
|
|
638
638
|
### `asyncProp`
|
|
639
639
|
|
|
640
|
-
Use `
|
|
640
|
+
Use `renderAsync` or `isRenderReady` in conjunction with `asyncProp` to seamlessly render and update element state based on async values:
|
|
641
641
|
|
|
642
642
|
<!-- example-link: src/readme-examples/my-with-async-prop.element.ts -->
|
|
643
643
|
|
|
@@ -30,7 +30,7 @@ export type DeclarativeElementInit<TagName extends CustomElementTagName, Inputs
|
|
|
30
30
|
* based on current instance state or inputs, or just false to indicate that the host class will
|
|
31
31
|
* only be manually set.
|
|
32
32
|
*/
|
|
33
|
-
hostClasses?: HostClassesInitMap<TagName, HostClassKeys,
|
|
33
|
+
hostClasses?: HostClassesInitMap<TagName, HostClassKeys, Inputs, FlattenObservablePropertyGetters<StateInit>>;
|
|
34
34
|
/**
|
|
35
35
|
* CSS Vars for the component. Keys of this object should be kebab-case and start with the
|
|
36
36
|
* element's tag name.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
|
|
2
2
|
import { CSSResult, LitElement } from 'lit';
|
|
3
|
+
import { Exact } from 'type-fest';
|
|
3
4
|
import { WrappedMinimalDefinition } from '../template-transforms/minimal-element-definition';
|
|
4
5
|
import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
|
|
5
6
|
import { BaseCssPropertyName } from './properties/css-properties';
|
|
@@ -7,7 +8,7 @@ import { CssVars } from './properties/css-vars';
|
|
|
7
8
|
import { EventDescriptorMap, EventsInitMap } from './properties/element-events';
|
|
8
9
|
import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './properties/element-properties';
|
|
9
10
|
import { HostClassNamesMap } from './properties/host-classes';
|
|
10
|
-
import {
|
|
11
|
+
import { FlattenObservablePropertyGetters, ObservablePropertyHandlerMap } from './properties/observable-property/observable-property-handler';
|
|
11
12
|
import { RenderCallback, RenderParams, UpdateStateCallback } from './render-callback';
|
|
12
13
|
export type DeclarativeElementHost<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, StateInit extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseCssPropertyName<TagName> = any, CssVarKeys extends BaseCssPropertyName<TagName> = any> = RequiredAndNotNullBy<Omit<DeclarativeElement<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, any>, Exclude<keyof StaticDeclarativeElementProperties<any, any, any, any, any, any, any>, keyof HTMLElement>>, 'shadowRoot'>;
|
|
13
14
|
export type DeclarativeElementDefinition<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, StateInit extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseCssPropertyName<TagName> = any, CssVarKeys extends BaseCssPropertyName<TagName> = any, RenderOutputGeneric = any> = (new () => DeclarativeElementHost<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>) & StaticDeclarativeElementProperties<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric> & {
|
|
@@ -32,7 +33,7 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
|
|
|
32
33
|
abstract render(): unknown;
|
|
33
34
|
abstract readonly instanceState: FlattenObservablePropertyGetters<StateInit>;
|
|
34
35
|
abstract readonly observablePropertyHandlerMap: ObservablePropertyHandlerMap<StateInit>;
|
|
35
|
-
abstract readonly instanceInputs:
|
|
36
|
+
abstract readonly instanceInputs: Inputs;
|
|
36
37
|
abstract assignInputs(inputs: {} extends Required<Inputs> ? never : Partial<Inputs>): void;
|
|
37
38
|
abstract haveInputsBeenSet: boolean;
|
|
38
39
|
abstract markInputsAsHavingBeenSet(): void;
|
|
@@ -40,9 +41,7 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
|
|
|
40
41
|
}
|
|
41
42
|
export interface StaticDeclarativeElementProperties<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutputGeneric> {
|
|
42
43
|
/** Assign inputs to an element directly on its interpolated tag. */
|
|
43
|
-
readonly assign: <
|
|
44
|
-
[Prop in keyof Inputs]: unknown;
|
|
45
|
-
}>(inputsObject: {} extends Required<Inputs> ? never : AllowObservablePropertySetter<Inputs, SpecificInputs>) => WrappedMinimalDefinition;
|
|
44
|
+
readonly assign: <SpecificInputs extends Exact<Inputs, SpecificInputs>>(inputsObject: {} extends Required<Inputs> ? never : SpecificInputs) => WrappedMinimalDefinition;
|
|
46
45
|
assignedInputs: Inputs | undefined;
|
|
47
46
|
/** Pass through the render callback for direct unit testability */
|
|
48
47
|
readonly renderCallback: RenderCallback<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
|
|
@@ -142,8 +142,8 @@ export function defineElementNoInputs(initInput) {
|
|
|
142
142
|
// this is set below in Object.defineProperties
|
|
143
143
|
this.definition = {};
|
|
144
144
|
this.observablePropertyHandlerMap = {};
|
|
145
|
-
this.instanceInputs = createElementUpdaterProxy(this, false);
|
|
146
|
-
this.instanceState = createElementUpdaterProxy(this, !initInput.options?.allowPolymorphicState);
|
|
145
|
+
this.instanceInputs = createElementUpdaterProxy(this, false, false);
|
|
146
|
+
this.instanceState = createElementUpdaterProxy(this, !initInput.options?.allowPolymorphicState, true);
|
|
147
147
|
const stateInitStatic = initInput.stateInitStatic ||
|
|
148
148
|
{};
|
|
149
149
|
getObjectTypedKeys(stateInitStatic).forEach((stateKey) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { noChange } from 'lit';
|
|
2
2
|
import { AsyncDirective } from 'lit/async-directive.js';
|
|
3
3
|
import { directive } from 'lit/directive.js';
|
|
4
|
-
import {
|
|
4
|
+
import { assignInputs } from '../properties/assign-inputs';
|
|
5
5
|
import { extractElement } from './directive-helpers';
|
|
6
6
|
/**
|
|
7
7
|
* Assign values but include a cleanup callback which gets called when a new value gets assigned so
|
|
@@ -33,7 +33,7 @@ class AssignWithCleanupDirectiveClass extends AsyncDirective {
|
|
|
33
33
|
if (this.hasBeenAssigned) {
|
|
34
34
|
cleanupCallback(this.lastValue);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
assignInputs(this.element, inputsObject);
|
|
37
37
|
this.hasBeenAssigned = true;
|
|
38
38
|
this.lastValue = inputsObject;
|
|
39
39
|
this.lastCallback = cleanupCallback;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DirectiveResult } from 'lit/directive.js';
|
|
2
2
|
import { PropertyInitMapBase } from '../properties/element-properties';
|
|
3
|
-
import { AllowObservablePropertySetter } from '../properties/observable-property/observable-property-handler';
|
|
4
3
|
export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBase = PropertyInitMapBase> = {
|
|
5
4
|
inputsType: InputsType;
|
|
6
5
|
};
|
|
@@ -14,10 +13,15 @@ export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBa
|
|
|
14
13
|
* should be
|
|
15
14
|
* html`<${MyElement.assign({value: 1})}>...`
|
|
16
15
|
*/
|
|
17
|
-
export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType>(declarativeElement: SpecificDeclarativeElement, inputsObject: {} extends Required<SpecificDeclarativeElement['inputsType']> ? never : SpecificDeclarativeElement['inputsType']): DirectiveResult;
|
|
17
|
+
/**
|
|
18
|
+
* Assign an object matching an element's inputs to its inputs.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated Instead of using this directive, assign inputs directly on the element's
|
|
21
|
+
* interpolation opening tag interpolation.
|
|
22
|
+
* @example
|
|
23
|
+
* html`<${MyElement} ${assign(MyElement, {value: 1})}>...`
|
|
24
|
+
* should be
|
|
25
|
+
* html`<${MyElement.assign({value: 1})}>...`
|
|
26
|
+
*/
|
|
27
|
+
export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType, const SpecificInput extends SpecificDeclarativeElement['inputsType']>(inputsObject: SpecificInput extends typeof HTMLElement ? never : SpecificInput): DirectiveResult;
|
|
@@ -2,6 +2,16 @@ import { noChange } from 'lit';
|
|
|
2
2
|
import { directive, Directive } from 'lit/directive.js';
|
|
3
3
|
import { assignInputs } from '../properties/assign-inputs';
|
|
4
4
|
import { extractElement } from './directive-helpers';
|
|
5
|
+
/**
|
|
6
|
+
* Assign an object matching an element's inputs to its inputs.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Instead of using this directive, assign inputs directly on the element's
|
|
9
|
+
* interpolation opening tag interpolation.
|
|
10
|
+
* @example
|
|
11
|
+
* html`<${MyElement} ${assign(MyElement, {value: 1})}>...`
|
|
12
|
+
* should be
|
|
13
|
+
* html`<${MyElement.assign({value: 1})}>...`
|
|
14
|
+
*/
|
|
5
15
|
export function assign(declarativeElementOrInputs, inputsObject) {
|
|
6
16
|
/**
|
|
7
17
|
* The directive generics (in listenDirective) are not strong enough to maintain their values.
|
|
@@ -20,10 +30,7 @@ const assignDirective = directive(class extends Directive {
|
|
|
20
30
|
this.element = extractElement(partInfo, 'assign');
|
|
21
31
|
}
|
|
22
32
|
render(elementDefinition, inputsObject) {
|
|
23
|
-
|
|
33
|
+
assignInputs(this.element, inputsObject);
|
|
24
34
|
return noChange;
|
|
25
35
|
}
|
|
26
36
|
});
|
|
27
|
-
export function assignInputsObject(expectedElementConstructor, element, assignmentObject) {
|
|
28
|
-
assignInputs(element, assignmentObject);
|
|
29
|
-
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DeclarativeElement } from '../declarative-element';
|
|
2
2
|
import { PropertyInitMapBase } from './element-properties';
|
|
3
|
-
export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean): PropertyInitGeneric;
|
|
3
|
+
export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean, unwrapObservables: boolean): PropertyInitGeneric;
|
|
@@ -8,7 +8,7 @@ function assertValidPropertyName(propKey, element, elementTagName) {
|
|
|
8
8
|
throw new Error(`Property '${String(propKey)}' does not exist on '${elementTagName.toLowerCase()}'.`);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export function createElementUpdaterProxy(element, verifyExists) {
|
|
11
|
+
export function createElementUpdaterProxy(element, verifyExists, unwrapObservables) {
|
|
12
12
|
/**
|
|
13
13
|
* Lit element updates state and inputs by setting them directly on the element, so we must do
|
|
14
14
|
* that here. DeclarativeElement's types, however, do not expose this behavior, so we add that
|
|
@@ -45,11 +45,11 @@ export function createElementUpdaterProxy(element, verifyExists) {
|
|
|
45
45
|
target[propertyKey] = value;
|
|
46
46
|
elementAsProps[propertyKey] = value;
|
|
47
47
|
}
|
|
48
|
-
if (isObservablePropertyHandlerCreator(newValue)) {
|
|
48
|
+
if (unwrapObservables && isObservablePropertyHandlerCreator(newValue)) {
|
|
49
49
|
newValue = newValue.init();
|
|
50
50
|
}
|
|
51
51
|
/** If we're using an existing observable property */
|
|
52
|
-
if (isObservablePropertyHandlerInstance(newValue)) {
|
|
52
|
+
if (unwrapObservables && isObservablePropertyHandlerInstance(newValue)) {
|
|
53
53
|
if (existingObservablePropertyHandler &&
|
|
54
54
|
newValue !== existingObservablePropertyHandler) {
|
|
55
55
|
newValue.addMultipleListeners(existingObservablePropertyHandler.getAllListeners());
|
|
@@ -64,7 +64,7 @@ export function createElementUpdaterProxy(element, verifyExists) {
|
|
|
64
64
|
element.observablePropertyHandlerMap[propertyKey] = newValue;
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
|
-
if (existingObservablePropertyHandler) {
|
|
67
|
+
if (unwrapObservables && existingObservablePropertyHandler) {
|
|
68
68
|
existingObservablePropertyHandler.setValue(newValue);
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
@@ -14,6 +14,6 @@ export type RenderParams<TagName extends CustomElementTagName, Inputs extends Pr
|
|
|
14
14
|
events: EventDescriptorMap<EventsInit>;
|
|
15
15
|
host: DeclarativeElementHost<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>;
|
|
16
16
|
dispatch: <EventTypeName extends keyof EventsInit>(event: TypedEvent<EventTypeName extends string ? EventTypeName : never, EventInitMapEventDetailExtractor<EventTypeName, EventsInit>> | Event) => boolean;
|
|
17
|
-
inputs: Readonly<
|
|
17
|
+
inputs: Readonly<Inputs>;
|
|
18
18
|
};
|
|
19
19
|
export declare function createRenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutput>(element: DeclarativeElement<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutput>, eventsMap: EventDescriptorMap<EventsInit>): RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-vir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"custom",
|
|
6
6
|
"web",
|
|
@@ -39,15 +39,14 @@
|
|
|
39
39
|
"test:types": "tsc --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@augment-vir/browser": "^15.4.
|
|
43
|
-
"@augment-vir/common": "^15.4.
|
|
44
|
-
"element-vir": "^14.1.0",
|
|
42
|
+
"@augment-vir/browser": "^15.4.1",
|
|
43
|
+
"@augment-vir/common": "^15.4.1",
|
|
45
44
|
"lit": "2.7.6",
|
|
46
45
|
"lit-css-vars": "^2.0.3"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@augment-vir/browser-testing": "^15.4.
|
|
50
|
-
"@augment-vir/node-js": "^15.4.
|
|
48
|
+
"@augment-vir/browser-testing": "^15.4.1",
|
|
49
|
+
"@augment-vir/node-js": "^15.4.1",
|
|
51
50
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
52
51
|
"@open-wc/testing": "^3.2.0",
|
|
53
52
|
"@types/chai": "^4.3.5",
|
|
@@ -56,11 +55,11 @@
|
|
|
56
55
|
"@web/test-runner": "^0.17.0",
|
|
57
56
|
"@web/test-runner-commands": "^0.8.0",
|
|
58
57
|
"@web/test-runner-playwright": "^0.10.1",
|
|
59
|
-
"@web/test-runner-visual-regression": "^0.8.
|
|
58
|
+
"@web/test-runner-visual-regression": "^0.8.2",
|
|
60
59
|
"ansi-colors": "^4.1.3",
|
|
61
60
|
"concurrently": "^8.2.0",
|
|
62
61
|
"cspell": "^6.31.2",
|
|
63
|
-
"esbuild": "^0.18.
|
|
62
|
+
"esbuild": "^0.18.15",
|
|
64
63
|
"istanbul-smart-text-reporter": "^1.1.2",
|
|
65
64
|
"markdown-code-example-inserter": "^0.3.1",
|
|
66
65
|
"mocha-spec-reporter-with-file-names": "^0.0.3",
|
|
@@ -77,8 +76,8 @@
|
|
|
77
76
|
"ts-node": "^10.9.1",
|
|
78
77
|
"type-fest": "^4.0.0",
|
|
79
78
|
"typescript": "~5.1.6",
|
|
80
|
-
"virmator": "^7.2.
|
|
81
|
-
"vite": "^4.4.
|
|
79
|
+
"virmator": "^7.2.5",
|
|
80
|
+
"vite": "^4.4.6",
|
|
82
81
|
"vite-tsconfig-paths": "^4.2.0"
|
|
83
82
|
},
|
|
84
83
|
"overrides": {
|