element-vir 10.0.0 → 10.1.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/dist/declarative-element/declarative-element.d.ts +1 -1
- package/dist/declarative-element/define-element-no-inputs.js +3 -8
- package/dist/declarative-element/directives/assign-with-clean-up.directive.js +2 -2
- package/dist/declarative-element/directives/assign.directive.d.ts +5 -11
- package/dist/declarative-element/directives/assign.directive.js +11 -10
- package/dist/declarative-element/directives/directive-helpers.d.ts +1 -3
- package/dist/declarative-element/directives/directive-helpers.js +1 -8
- package/dist/declarative-element/directives/listen.directive.js +1 -1
- package/dist/declarative-element/properties/assign-inputs.d.ts +3 -0
- package/dist/declarative-element/properties/assign-inputs.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -27,7 +27,7 @@ export declare abstract class DeclarativeElement<TagNameGeneric extends CustomEl
|
|
|
27
27
|
abstract readonly instanceState: StateInitGeneric;
|
|
28
28
|
abstract readonly instanceInputs: InputsGeneric;
|
|
29
29
|
abstract assignInputs(inputs: InputsGeneric): void;
|
|
30
|
-
abstract
|
|
30
|
+
abstract haveInputsBeenSet: boolean;
|
|
31
31
|
abstract markInputsAsHavingBeenSet(): void;
|
|
32
32
|
abstract readonly definition: DeclarativeElementDefinition<TagNameGeneric, InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
33
33
|
}
|
|
@@ -10,6 +10,7 @@ import { DeclarativeElement, } from './declarative-element';
|
|
|
10
10
|
import { IgnoreInputsNotBeenSetBeforeRenderWarningSymbol, defaultDeclarativeElementDefinitionOptions, } from './definition-options';
|
|
11
11
|
import { assign } from './directives/assign.directive';
|
|
12
12
|
import { hasDeclarativeElementParent } from './has-declarative-element-parent';
|
|
13
|
+
import { assignInputs, markInputsAsHavingBeenSet } from './properties/assign-inputs';
|
|
13
14
|
import { createCssVarNamesMap, createCssVarValuesMap } from './properties/css-vars';
|
|
14
15
|
import { createEventDescriptorMap } from './properties/element-events';
|
|
15
16
|
import { createElementUpdaterProxy } from './properties/element-updater-proxy';
|
|
@@ -44,9 +45,7 @@ export function defineElementNoInputs(initInput) {
|
|
|
44
45
|
throw new Error(`"stateType" was called on ${initInput.tagName} as a value but it is only for types.`);
|
|
45
46
|
}
|
|
46
47
|
markInputsAsHavingBeenSet() {
|
|
47
|
-
|
|
48
|
-
this.haveInputsBeenSet = true;
|
|
49
|
-
}
|
|
48
|
+
markInputsAsHavingBeenSet(this);
|
|
50
49
|
}
|
|
51
50
|
render() {
|
|
52
51
|
try {
|
|
@@ -97,11 +96,7 @@ export function defineElementNoInputs(initInput) {
|
|
|
97
96
|
this.initCalled = false;
|
|
98
97
|
}
|
|
99
98
|
assignInputs(inputs) {
|
|
100
|
-
|
|
101
|
-
property()(this, key);
|
|
102
|
-
this.instanceInputs[key] = inputs[key];
|
|
103
|
-
});
|
|
104
|
-
this.markInputsAsHavingBeenSet();
|
|
99
|
+
assignInputs(this, inputs);
|
|
105
100
|
}
|
|
106
101
|
constructor() {
|
|
107
102
|
super();
|
|
@@ -2,7 +2,7 @@ import { noChange } from 'lit';
|
|
|
2
2
|
import { AsyncDirective } from 'lit/async-directive.js';
|
|
3
3
|
import { directive } from 'lit/directive.js';
|
|
4
4
|
import { assignInputsObject } from './assign.directive';
|
|
5
|
-
import {
|
|
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
|
|
8
8
|
* the previous value can get cleaned up. An optional equality check callback can be provided. If it
|
|
@@ -22,7 +22,7 @@ class AssignWithCleanupDirectiveClass extends AsyncDirective {
|
|
|
22
22
|
constructor(partInfo) {
|
|
23
23
|
super(partInfo);
|
|
24
24
|
this.hasBeenAssigned = false;
|
|
25
|
-
this.element =
|
|
25
|
+
this.element = extractElement(partInfo, 'assign');
|
|
26
26
|
}
|
|
27
27
|
disconnected() {
|
|
28
28
|
if (this.lastValue != undefined && this.lastCallback != undefined) {
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DirectiveResult } from 'lit/directive.js';
|
|
2
|
+
import { DeclarativeElementDefinition } from '../declarative-element';
|
|
3
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']):
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
render(elementDefinition: DeclarativeElementDefinition, 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;
|
|
4
|
+
export declare function assign<DeclarativeElementGeneric extends DeclarativeElementDefinition>(declarativeElement: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric['inputsType']): DirectiveResult;
|
|
5
|
+
export declare function assign<DeclarativeElementGeneric extends DeclarativeElementDefinition>(inputsObject: Record<string, any>): DirectiveResult;
|
|
6
|
+
export declare function assignInputsObject<DeclarativeElementDefinitionGeneric extends DeclarativeElementDefinition>(expectedElementConstructor: DeclarativeElementDefinitionGeneric | undefined, element: Element, assignmentObject: DeclarativeElementDefinitionGeneric['inputsType']): void;
|
|
13
7
|
//# sourceMappingURL=assign.directive.d.ts.map
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { noChange } from 'lit';
|
|
2
2
|
import { directive, Directive } from 'lit/directive.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export function assign(
|
|
3
|
+
import { assignInputs } from '../properties/assign-inputs';
|
|
4
|
+
import { extractElement } from './directive-helpers';
|
|
5
|
+
export function assign(declarativeElementOrInputs, inputsObject) {
|
|
6
6
|
/**
|
|
7
7
|
* The directive generics (in listenDirective) are not strong enough to maintain their values.
|
|
8
8
|
* Thus, the directive call is wrapped in this function.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
if (inputsObject) {
|
|
11
|
+
return assignDirective(declarativeElementOrInputs, inputsObject);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return assignDirective(undefined, declarativeElementOrInputs);
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
const assignDirective = directive(class extends Directive {
|
|
13
18
|
constructor(partInfo) {
|
|
14
19
|
super(partInfo);
|
|
15
|
-
this.element =
|
|
20
|
+
this.element = extractElement(partInfo, 'assign');
|
|
16
21
|
}
|
|
17
22
|
render(elementDefinition, inputsObject) {
|
|
18
23
|
assignInputsObject(elementDefinition, this.element, inputsObject);
|
|
@@ -20,9 +25,5 @@ const assignDirective = directive(class extends Directive {
|
|
|
20
25
|
}
|
|
21
26
|
});
|
|
22
27
|
export function assignInputsObject(expectedElementConstructor, element, assignmentObject) {
|
|
23
|
-
|
|
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
|
+
assignInputs(element, assignmentObject);
|
|
28
29
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ElementPartInfo, PartInfo } from 'lit/directive.js';
|
|
2
|
-
import { DeclarativeElement } from '../declarative-element';
|
|
3
2
|
/** For some reason these aren't defined in lit's types already. */
|
|
4
3
|
export type ExtraPartInfoProperties = {
|
|
5
4
|
element: Element;
|
|
@@ -9,7 +8,6 @@ export type ExtraPartInfoProperties = {
|
|
|
9
8
|
isConnected: boolean;
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function extractElement<ElementType = HTMLElement>(partInfo: PartInfo, directiveName: string, constructorClass: (new () => ElementType) | (abstract new () => ElementType)): ElementType;
|
|
11
|
+
export declare function extractElement(partInfo: PartInfo, directiveName: string): Element;
|
|
14
12
|
export declare function assertIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
|
|
15
13
|
//# sourceMappingURL=directive-helpers.d.ts.map
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { PartType } from 'lit/directive.js';
|
|
2
|
-
|
|
3
|
-
export function extractDeclarativeElement(partInfo, directiveName) {
|
|
4
|
-
return extractElement(partInfo, directiveName, DeclarativeElement);
|
|
5
|
-
}
|
|
6
|
-
export function extractElement(partInfo, directiveName, constructorClass) {
|
|
2
|
+
export function extractElement(partInfo, directiveName) {
|
|
7
3
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
8
4
|
const element = partInfo.element;
|
|
9
|
-
if (!(element instanceof constructorClass)) {
|
|
10
|
-
throw new Error(`${directiveName} attached to non ${constructorClass.name} element.`);
|
|
11
|
-
}
|
|
12
5
|
return element;
|
|
13
6
|
}
|
|
14
7
|
export function assertIsElementPartInfo(partInfo, directiveName) {
|
|
@@ -11,7 +11,7 @@ export function listen(eventType, listener) {
|
|
|
11
11
|
const listenDirective = directive(class extends Directive {
|
|
12
12
|
constructor(partInfo) {
|
|
13
13
|
super(partInfo);
|
|
14
|
-
this.element = extractElement(partInfo, 'listen'
|
|
14
|
+
this.element = extractElement(partInfo, 'listen');
|
|
15
15
|
}
|
|
16
16
|
resetListener(listenerMetaData) {
|
|
17
17
|
if (this.lastListenerMetaData) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getObjectTypedKeys } from '@augment-vir/common';
|
|
2
|
+
import { property } from 'lit/decorators.js';
|
|
3
|
+
export function assignInputs(element, inputs) {
|
|
4
|
+
getObjectTypedKeys(inputs).forEach((key) => {
|
|
5
|
+
property()(element, key);
|
|
6
|
+
if ('instanceInputs' in element) {
|
|
7
|
+
element.instanceInputs[key] = inputs[key];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
element[key] = inputs[key];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
markInputsAsHavingBeenSet(element);
|
|
14
|
+
}
|
|
15
|
+
export function markInputsAsHavingBeenSet(element) {
|
|
16
|
+
if (!element.haveInputsBeenSet) {
|
|
17
|
+
element.haveInputsBeenSet = true;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED