element-vir 16.2.0 → 16.3.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.
@@ -30,6 +30,7 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
30
30
  static readonly hostClasses: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseCssPropertyName<CustomElementTagName>, BaseCssPropertyName<CustomElementTagName>, unknown>['hostClasses'];
31
31
  static readonly cssVars: StaticDeclarativeElementProperties<CustomElementTagName, PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, BaseCssPropertyName<CustomElementTagName>, BaseCssPropertyName<CustomElementTagName>, unknown>['cssVars'];
32
32
  abstract lastRenderError: Error | undefined;
33
+ abstract renderCount: number;
33
34
  abstract lastRenderedProps: Pick<RenderParams<any, Inputs, StateInit, any, any, any>, 'inputs' | 'state'>;
34
35
  abstract render(): unknown;
35
36
  abstract readonly instanceState: FlattenElementVirStateSetup<StateInit>;
@@ -66,6 +66,7 @@ export function defineElementNoInputs(initInput) {
66
66
  throw new Error(`"stateType" was called on ${initInput.tagName} as a value but it is only for types.`);
67
67
  }
68
68
  render() {
69
+ this.renderCount++;
69
70
  try {
70
71
  if (
71
72
  // This ignores elements at the root of a page, as they can't receive inputs from
@@ -133,6 +134,7 @@ export function defineElementNoInputs(initInput) {
133
134
  constructor() {
134
135
  super();
135
136
  this.lastRenderError = undefined;
137
+ this.renderCount = 0;
136
138
  this.initCalled = false;
137
139
  this.hasRendered = false;
138
140
  this.lastRenderedProps = undefined;
@@ -0,0 +1,13 @@
1
+ import { PartInfo } from 'lit/directive.js';
2
+ export declare function createAttributeDirective(attributeName: string): {
3
+ attributeSelector(attributeValue: string): string;
4
+ attributeDirective(attributeValue: string): import("lit-html/directive").DirectiveResult<{
5
+ new (partInfo: PartInfo): {
6
+ readonly element: Element;
7
+ render(testId: string): symbol;
8
+ readonly _$isConnected: boolean;
9
+ update(_part: import("lit-html").Part, props: unknown[]): unknown;
10
+ };
11
+ }>;
12
+ attributeName: string;
13
+ };
@@ -0,0 +1,24 @@
1
+ import { noChange } from 'lit';
2
+ import { directive, Directive } from 'lit/directive.js';
3
+ import { extractElement } from './directive-helpers';
4
+ export function createAttributeDirective(attributeName) {
5
+ const newDirective = directive(class extends Directive {
6
+ constructor(partInfo) {
7
+ super(partInfo);
8
+ this.element = extractElement(partInfo, 'testId');
9
+ }
10
+ render(testId) {
11
+ this.element.setAttribute(attributeName, testId);
12
+ return noChange;
13
+ }
14
+ });
15
+ return {
16
+ attributeSelector(attributeValue) {
17
+ return `[${attributeName}="${attributeValue}"]`;
18
+ },
19
+ attributeDirective(attributeValue) {
20
+ return newDirective(attributeValue);
21
+ },
22
+ attributeName,
23
+ };
24
+ }
@@ -0,0 +1,8 @@
1
+ export declare const testId: (attributeValue: string) => import("lit-html/directive").DirectiveResult<{
2
+ new (partInfo: import("lit-html/directive").PartInfo): {
3
+ readonly element: Element;
4
+ render(testId: string): symbol;
5
+ readonly _$isConnected: boolean;
6
+ update(_part: import("lit-html").Part, props: unknown[]): unknown;
7
+ };
8
+ }>, testIdBy: (attributeValue: string) => string, testIdAttribute: string;
@@ -0,0 +1,2 @@
1
+ import { createAttributeDirective } from './create-attribute-directive';
2
+ export const { attributeDirective: testId, attributeSelector: testIdBy, attributeName: testIdAttribute, } = createAttributeDirective('data-test-id');
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export type { DeclarativeElementDefinitionOptions } from './declarative-element/
8
8
  export * from './declarative-element/directives/assign-with-clean-up.directive';
9
9
  export * from './declarative-element/directives/assign.directive';
10
10
  export * from './declarative-element/directives/async-prop';
11
+ export * from './declarative-element/directives/create-attribute-directive';
11
12
  export * from './declarative-element/directives/directive-helpers';
12
13
  export * from './declarative-element/directives/is-render-ready.directive';
13
14
  export * from './declarative-element/directives/listen.directive';
@@ -15,6 +16,7 @@ export * from './declarative-element/directives/on-dom-created.directive';
15
16
  export * from './declarative-element/directives/on-resize.directive';
16
17
  export * from './declarative-element/directives/render-async.directive';
17
18
  export * from './declarative-element/directives/render-if.directive';
19
+ export * from './declarative-element/directives/test-id.directive';
18
20
  export * from './declarative-element/is-declarative-element';
19
21
  export * from './declarative-element/properties/css-properties';
20
22
  export * from './declarative-element/properties/css-vars';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './declarative-element/define-element-no-inputs';
7
7
  export * from './declarative-element/directives/assign-with-clean-up.directive';
8
8
  export * from './declarative-element/directives/assign.directive';
9
9
  export * from './declarative-element/directives/async-prop';
10
+ export * from './declarative-element/directives/create-attribute-directive';
10
11
  export * from './declarative-element/directives/directive-helpers';
11
12
  export * from './declarative-element/directives/is-render-ready.directive';
12
13
  export * from './declarative-element/directives/listen.directive';
@@ -14,6 +15,7 @@ export * from './declarative-element/directives/on-dom-created.directive';
14
15
  export * from './declarative-element/directives/on-resize.directive';
15
16
  export * from './declarative-element/directives/render-async.directive';
16
17
  export * from './declarative-element/directives/render-if.directive';
18
+ export * from './declarative-element/directives/test-id.directive';
17
19
  export * from './declarative-element/is-declarative-element';
18
20
  export * from './declarative-element/properties/css-properties';
19
21
  export * from './declarative-element/properties/css-vars';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "16.2.0",
3
+ "version": "16.3.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",