element-vir 22.2.2 → 23.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.
Files changed (137) hide show
  1. package/README.md +44 -38
  2. package/dist/declarative-element/custom-tag-name.d.ts +6 -0
  3. package/dist/declarative-element/declarative-element-init.d.ts +20 -14
  4. package/dist/declarative-element/declarative-element.d.ts +70 -24
  5. package/dist/declarative-element/declarative-element.js +34 -1
  6. package/dist/declarative-element/define-element-no-inputs.d.ts +31 -6
  7. package/dist/declarative-element/define-element-no-inputs.js +154 -257
  8. package/dist/declarative-element/define-element.d.ts +35 -7
  9. package/dist/declarative-element/define-element.js +26 -4
  10. package/dist/declarative-element/definition-options.d.ts +10 -0
  11. package/dist/declarative-element/definition-options.js +5 -0
  12. package/dist/declarative-element/directives/assign.directive.d.ts +8 -11
  13. package/dist/declarative-element/directives/assign.directive.js +6 -13
  14. package/dist/declarative-element/directives/async-prop.d.ts +19 -4
  15. package/dist/declarative-element/directives/async-prop.js +14 -4
  16. package/dist/declarative-element/directives/create-attribute-directive.d.ts +19 -4
  17. package/dist/declarative-element/directives/create-attribute-directive.js +18 -8
  18. package/dist/declarative-element/directives/directive-helpers.d.ts +19 -4
  19. package/dist/declarative-element/directives/directive-helpers.js +14 -2
  20. package/dist/declarative-element/directives/is-resolved.directive.d.ts +107 -1
  21. package/dist/declarative-element/directives/is-resolved.directive.js +107 -1
  22. package/dist/declarative-element/directives/listen.directive.d.ts +84 -10
  23. package/dist/declarative-element/directives/listen.directive.js +5 -15
  24. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +37 -4
  25. package/dist/declarative-element/directives/on-dom-created.directive.js +32 -12
  26. package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +33 -3
  27. package/dist/declarative-element/directives/on-dom-rendered.directive.js +29 -6
  28. package/dist/declarative-element/directives/on-resize.directive.d.ts +37 -4
  29. package/dist/declarative-element/directives/on-resize.directive.js +37 -24
  30. package/dist/declarative-element/directives/render-async.directive.d.ts +44 -4
  31. package/dist/declarative-element/directives/render-async.directive.js +13 -3
  32. package/dist/declarative-element/directives/render-if.directive.d.ts +31 -0
  33. package/dist/declarative-element/directives/render-if.directive.js +32 -1
  34. package/dist/declarative-element/directives/test-id.directive.d.ts +48 -4
  35. package/dist/declarative-element/directives/test-id.directive.js +47 -2
  36. package/dist/declarative-element/has-declarative-element-parent.js +1 -1
  37. package/dist/declarative-element/is-declarative-element-definition.d.ts +15 -1
  38. package/dist/declarative-element/is-declarative-element-definition.js +21 -18
  39. package/dist/declarative-element/is-declarative-element.d.ts +5 -1
  40. package/dist/declarative-element/is-declarative-element.js +7 -3
  41. package/dist/declarative-element/properties/assign-inputs.js +1 -1
  42. package/dist/declarative-element/properties/css-properties.d.ts +11 -1
  43. package/dist/declarative-element/properties/css-properties.js +5 -0
  44. package/dist/declarative-element/properties/css-vars.d.ts +14 -4
  45. package/dist/declarative-element/properties/element-events.d.ts +61 -7
  46. package/dist/declarative-element/properties/element-events.js +40 -5
  47. package/dist/declarative-element/properties/element-properties.d.ts +15 -6
  48. package/dist/declarative-element/properties/element-properties.js +1 -21
  49. package/dist/declarative-element/properties/element-vir-state-setup.d.ts +43 -3
  50. package/dist/declarative-element/properties/element-vir-state-setup.js +17 -3
  51. package/dist/declarative-element/properties/host-classes.d.ts +25 -12
  52. package/dist/declarative-element/properties/host-classes.js +5 -0
  53. package/dist/declarative-element/properties/per-instance.d.ts +23 -2
  54. package/dist/declarative-element/properties/per-instance.js +24 -3
  55. package/dist/declarative-element/properties/property-proxy.d.ts +19 -4
  56. package/dist/declarative-element/properties/property-proxy.js +14 -4
  57. package/dist/declarative-element/properties/styles.d.ts +33 -8
  58. package/dist/declarative-element/properties/styles.js +12 -2
  59. package/dist/declarative-element/properties/tag-name.d.ts +5 -0
  60. package/dist/declarative-element/render-callback.d.ts +38 -11
  61. package/dist/declarative-element/render-callback.js +6 -0
  62. package/dist/declarative-element/slot-names.d.ts +10 -2
  63. package/dist/declarative-element/slot-names.js +5 -1
  64. package/dist/declarative-element/wrap-define-element.d.ts +38 -11
  65. package/dist/declarative-element/wrap-define-element.js +17 -2
  66. package/dist/index.d.ts +40 -40
  67. package/dist/index.js +40 -39
  68. package/dist/lit-exports/all-lit-exports.d.ts +2 -2
  69. package/dist/lit-exports/all-lit-exports.js +2 -2
  70. package/dist/lit-exports/lit-repeat-fix.d.ts +60 -4
  71. package/dist/lit-exports/lit-repeat-fix.js +35 -1
  72. package/dist/readme-examples/my-app.element.d.ts +1 -0
  73. package/dist/readme-examples/my-app.element.js +11 -0
  74. package/dist/readme-examples/my-custom-action.event.d.ts +1 -0
  75. package/dist/readme-examples/my-custom-action.event.js +2 -0
  76. package/dist/readme-examples/my-custom-define.d.ts +4 -0
  77. package/dist/readme-examples/my-custom-define.js +19 -0
  78. package/dist/readme-examples/my-simple.element.d.ts +1 -0
  79. package/dist/readme-examples/my-simple.element.js +9 -0
  80. package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
  81. package/dist/readme-examples/my-with-assignment.element.js +14 -0
  82. package/dist/readme-examples/my-with-async-prop.element.d.ts +9 -0
  83. package/dist/readme-examples/my-with-async-prop.element.js +46 -0
  84. package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
  85. package/dist/readme-examples/my-with-cleanup-callback.element.js +23 -0
  86. package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
  87. package/dist/readme-examples/my-with-css-vars.element.js +24 -0
  88. package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
  89. package/dist/readme-examples/my-with-custom-events.element.js +21 -0
  90. package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
  91. package/dist/readme-examples/my-with-event-listening.element.js +22 -0
  92. package/dist/readme-examples/my-with-events.element.d.ts +4 -0
  93. package/dist/readme-examples/my-with-events.element.js +19 -0
  94. package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
  95. package/dist/readme-examples/my-with-host-class-definition.element.js +39 -0
  96. package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
  97. package/dist/readme-examples/my-with-host-class-usage.element.js +12 -0
  98. package/dist/readme-examples/my-with-inputs.element.d.ts +4 -0
  99. package/dist/readme-examples/my-with-inputs.element.js +9 -0
  100. package/dist/readme-examples/my-with-on-dom-created.element.d.ts +1 -0
  101. package/dist/readme-examples/my-with-on-dom-created.element.js +16 -0
  102. package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
  103. package/dist/readme-examples/my-with-on-resize.element.js +17 -0
  104. package/dist/readme-examples/my-with-render-if.element.d.ts +3 -0
  105. package/dist/readme-examples/my-with-render-if.element.js +11 -0
  106. package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +1 -0
  107. package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.js +15 -0
  108. package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
  109. package/dist/readme-examples/my-with-styles.element.js +21 -0
  110. package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
  111. package/dist/readme-examples/my-with-update-state.element.js +23 -0
  112. package/dist/readme-examples/require-declarative-element.d.ts +1 -0
  113. package/dist/readme-examples/require-declarative-element.js +2 -0
  114. package/dist/require-declarative-element.d.ts +12 -0
  115. package/dist/require-declarative-element.js +12 -0
  116. package/dist/template-transforms/minimal-element-definition.d.ts +30 -2
  117. package/dist/template-transforms/minimal-element-definition.js +14 -3
  118. package/dist/template-transforms/nested-mapped-templates.d.ts +1 -1
  119. package/dist/template-transforms/nested-mapped-templates.js +4 -3
  120. package/dist/template-transforms/template-transform-type.d.ts +1 -1
  121. package/dist/template-transforms/transform-template.d.ts +1 -1
  122. package/dist/template-transforms/transform-template.js +17 -21
  123. package/dist/template-transforms/vir-css/css-transform.d.ts +3 -3
  124. package/dist/template-transforms/vir-css/css-transform.js +3 -2
  125. package/dist/template-transforms/vir-css/vir-css.d.ts +11 -2
  126. package/dist/template-transforms/vir-css/vir-css.js +11 -2
  127. package/dist/template-transforms/vir-html/html-interpolation.d.ts +9 -5
  128. package/dist/template-transforms/vir-html/html-transform.d.ts +3 -3
  129. package/dist/template-transforms/vir-html/html-transform.js +14 -12
  130. package/dist/template-transforms/vir-html/vir-html.d.ts +4 -2
  131. package/dist/template-transforms/vir-html/vir-html.js +4 -2
  132. package/dist/typed-event/typed-event.d.ts +42 -6
  133. package/dist/typed-event/typed-event.js +31 -28
  134. package/dist/util/lit-template.d.ts +6 -1
  135. package/dist/util/lit-template.js +10 -7
  136. package/dist/util/type.d.ts +5 -0
  137. package/package.json +37 -35
@@ -0,0 +1,46 @@
1
+ import { asyncProp, defineElement, html, listen, renderAsync } from '../index.js';
2
+ async function loadSomething(endpoint) {
3
+ // load something from the network
4
+ const data = await (await fetch([
5
+ '',
6
+ 'api',
7
+ endpoint,
8
+ ].join('/'))).json();
9
+ return data;
10
+ }
11
+ export const MyWithAsyncProp = defineElement()({
12
+ tagName: 'my-with-async-prop',
13
+ stateInitStatic: {
14
+ data: asyncProp({
15
+ async updateCallback({ endpoint }) {
16
+ return loadSomething(endpoint);
17
+ },
18
+ }),
19
+ },
20
+ render({ inputs, state }) {
21
+ /**
22
+ * This causes the a promise which automatically updates the state.data prop once the
23
+ * promise resolves. It only creates a new promise if the first input, the trigger, value
24
+ * changes from previous calls.
25
+ */
26
+ state.data.update(inputs);
27
+ return html `
28
+ Here's the data:
29
+ <br />
30
+ ${renderAsync(state.data, 'Loading...', (loadedData) => {
31
+ return html `
32
+ Got the data: ${loadedData}
33
+ `;
34
+ })}
35
+ <br />
36
+ <button
37
+ ${listen('click', () => {
38
+ /** You can force asyncProp to update by calling forceUpdate. */
39
+ state.data.forceUpdate(inputs);
40
+ })}
41
+ >
42
+ Refresh
43
+ </button>
44
+ `;
45
+ },
46
+ });
@@ -0,0 +1,3 @@
1
+ export declare const MyWithAssignmentCleanupCallback: import("../index.js").DeclarativeElementDefinition<"my-with-cleanup-callback", {}, {
2
+ intervalId: undefined | number;
3
+ }, {}, "my-with-cleanup-callback-", "my-with-cleanup-callback-", readonly []>;
@@ -0,0 +1,23 @@
1
+ import { defineElementNoInputs, html } from '../index.js';
2
+ export const MyWithAssignmentCleanupCallback = defineElementNoInputs({
3
+ tagName: 'my-with-cleanup-callback',
4
+ stateInitStatic: {
5
+ intervalId: undefined,
6
+ },
7
+ init: ({ updateState }) => {
8
+ updateState({
9
+ intervalId: window.setInterval(() => console.info('hi'), 1000),
10
+ });
11
+ },
12
+ render() {
13
+ return html `
14
+ <h1>My App</h1>
15
+ `;
16
+ },
17
+ cleanup: ({ state, updateState }) => {
18
+ window.clearInterval(state.intervalId);
19
+ updateState({
20
+ intervalId: undefined,
21
+ });
22
+ },
23
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithCssVars: import("../index.js").DeclarativeElementDefinition<"my-with-css-vars", {}, {}, {}, "my-with-css-vars-", "my-with-css-vars-my-var", readonly []>;
@@ -0,0 +1,24 @@
1
+ import { css, defineElementNoInputs, html } from '../index.js';
2
+ export const MyWithCssVars = defineElementNoInputs({
3
+ tagName: 'my-with-css-vars',
4
+ cssVars: {
5
+ /** The value assigned here ('blue') becomes the fallback value for this CSS var. */
6
+ 'my-with-css-vars-my-var': 'blue',
7
+ },
8
+ styles: ({ cssVars }) => css `
9
+ :host {
10
+ /*
11
+ Set CSS vars (or reference the name directly) via the ".name" property
12
+ */
13
+ ${cssVars['my-with-css-vars-my-var'].name}: yellow;
14
+ /*
15
+ Use CSS vars with the ".value" property. This includes a "var" wrapper and the
16
+ assigned fallback value (which in this case is 'blue').
17
+ */
18
+ color: ${cssVars['my-with-css-vars-my-var'].value};
19
+ }
20
+ `,
21
+ render() {
22
+ return html ``;
23
+ },
24
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithCustomEvents: import("../index.js").DeclarativeElementDefinition<"my-with-custom-events", {}, {}, {}, "my-with-custom-events-", "my-with-custom-events-", readonly []>;
@@ -0,0 +1,21 @@
1
+ import { randomInteger } from '@augment-vir/common';
2
+ import { defineElementNoInputs, html, listen } from '../index.js';
3
+ import { MyCustomActionEvent } from './my-custom-action.event.js';
4
+ export const MyWithCustomEvents = defineElementNoInputs({
5
+ tagName: 'my-with-custom-events',
6
+ render({ dispatch }) {
7
+ return html `
8
+ <div
9
+ ${listen(MyCustomActionEvent, (event) => {
10
+ console.info(`Got a number! ${event.detail}`);
11
+ })}
12
+ >
13
+ <div
14
+ ${listen('click', () => {
15
+ dispatch(new MyCustomActionEvent(randomInteger({ min: 0, max: 1_000_000 })));
16
+ })}
17
+ ></div>
18
+ </div>
19
+ `;
20
+ },
21
+ });
@@ -0,0 +1,3 @@
1
+ export declare const MyWithEventListening: import("../index.js").DeclarativeElementDefinition<"my-with-event-listening", {}, {
2
+ myNumber: number;
3
+ }, {}, "my-with-event-listening-", "my-with-event-listening-", readonly []>;
@@ -0,0 +1,22 @@
1
+ import { defineElementNoInputs, html, listen } from '../index.js';
2
+ import { MyWithEvents } from './my-with-events.element.js';
3
+ export const MyWithEventListening = defineElementNoInputs({
4
+ tagName: 'my-with-event-listening',
5
+ stateInitStatic: {
6
+ myNumber: -1,
7
+ },
8
+ render({ state, updateState }) {
9
+ return html `
10
+ <h1>My App</h1>
11
+ <${MyWithEvents}
12
+ ${listen(MyWithEvents.events.logoutClick, () => {
13
+ console.info('logout triggered');
14
+ })}
15
+ ${listen(MyWithEvents.events.randomNumber, (event) => {
16
+ updateState({ myNumber: event.detail });
17
+ })}
18
+ ></${MyWithEvents}>
19
+ <span>${state.myNumber}</span>
20
+ `;
21
+ },
22
+ });
@@ -0,0 +1,4 @@
1
+ export declare const MyWithEvents: import("../index.js").DeclarativeElementDefinition<"my-with-events", {}, {}, {
2
+ logoutClick: import("../index.js").DefineEvent<void>;
3
+ randomNumber: import("../index.js").DefineEvent<number>;
4
+ }, "my-with-events-", "my-with-events-", readonly []>;
@@ -0,0 +1,19 @@
1
+ import { randomInteger } from '@augment-vir/common';
2
+ import { defineElementEvent, defineElementNoInputs, html, listen } from '../index.js';
3
+ export const MyWithEvents = defineElementNoInputs({
4
+ tagName: 'my-with-events',
5
+ events: {
6
+ logoutClick: defineElementEvent(),
7
+ randomNumber: defineElementEvent(),
8
+ },
9
+ render({ dispatch, events }) {
10
+ return html `
11
+ <button ${listen('click', () => dispatch(new events.logoutClick()))}>log out</button>
12
+ <button
13
+ ${listen('click', () => dispatch(new events.randomNumber(randomInteger({ min: 0, max: 1_000_000 }))))}
14
+ >
15
+ generate random number
16
+ </button>
17
+ `;
18
+ },
19
+ });
@@ -0,0 +1,3 @@
1
+ export declare const MyWithHostClassDefinition: import("../index.js").DeclarativeElementDefinition<"my-with-host-class-definition", {}, {
2
+ myProp: string;
3
+ }, {}, "my-with-host-class-definition-a" | "my-with-host-class-definition-automatic", "my-with-host-class-definition-", readonly []>;
@@ -0,0 +1,39 @@
1
+ import { css, defineElementNoInputs, html } from '../index.js';
2
+ export const MyWithHostClassDefinition = defineElementNoInputs({
3
+ tagName: 'my-with-host-class-definition',
4
+ stateInitStatic: {
5
+ myProp: 'hello there',
6
+ },
7
+ hostClasses: {
8
+ /**
9
+ * Setting the value to false means this host class will never be automatically applied. It
10
+ * will simply be a static member on the element for manual application in consumers.
11
+ */
12
+ 'my-with-host-class-definition-a': false,
13
+ /**
14
+ * This host class will be automatically applied if the given callback is evaluated to true
15
+ * after a call to render.
16
+ */
17
+ 'my-with-host-class-definition-automatic': ({ state }) => {
18
+ return state.myProp === 'foo';
19
+ },
20
+ },
21
+ /**
22
+ * Apply styles to the host classes by using a callback for "styles". The callback's argument
23
+ * contains the host classes defined above in the "hostClasses" property.
24
+ */
25
+ styles: ({ hostClasses }) => css `
26
+ ${hostClasses['my-with-host-class-definition-automatic'].selector} {
27
+ color: blue;
28
+ }
29
+
30
+ ${hostClasses['my-with-host-class-definition-a'].selector} {
31
+ color: red;
32
+ }
33
+ `,
34
+ render({ state }) {
35
+ return html `
36
+ ${state.myProp}
37
+ `;
38
+ },
39
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithHostClassUsage: import("../index.js").DeclarativeElementDefinition<"my-with-host-class-usage", {}, {}, {}, "my-with-host-class-usage-", "my-with-host-class-usage-", readonly []>;
@@ -0,0 +1,12 @@
1
+ import { defineElementNoInputs, html } from '../index.js';
2
+ import { MyWithHostClassDefinition } from './my-with-host-class-definition.element.js';
3
+ export const MyWithHostClassUsage = defineElementNoInputs({
4
+ tagName: 'my-with-host-class-usage',
5
+ render() {
6
+ return html `
7
+ <${MyWithHostClassDefinition}
8
+ class=${MyWithHostClassDefinition.hostClasses['my-with-host-class-definition-a']}
9
+ ></${MyWithHostClassDefinition}>
10
+ `;
11
+ },
12
+ });
@@ -0,0 +1,4 @@
1
+ export declare const MyWithInputs: import("../index.js").DeclarativeElementDefinition<"my-with-inputs", {
2
+ username: string;
3
+ email: string;
4
+ }, {}, {}, "my-with-inputs-", "my-with-inputs-", readonly []>;
@@ -0,0 +1,9 @@
1
+ import { defineElement, html } from '../index.js';
2
+ export const MyWithInputs = defineElement()({
3
+ tagName: 'my-with-inputs',
4
+ render({ inputs }) {
5
+ return html `
6
+ <span>Hello there ${inputs.username}!</span>
7
+ `;
8
+ },
9
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithOnDomCreated: import("../index.js").DeclarativeElementDefinition<"my-with-on-dom-created", {}, {}, {}, "my-with-on-dom-created-", "my-with-on-dom-created-", readonly []>;
@@ -0,0 +1,16 @@
1
+ import { defineElementNoInputs, html, onDomCreated } from '../index.js';
2
+ export const MyWithOnDomCreated = defineElementNoInputs({
3
+ tagName: 'my-with-on-dom-created',
4
+ render() {
5
+ return html `
6
+ <span
7
+ ${onDomCreated((element) => {
8
+ // logs a span element
9
+ console.info(element);
10
+ })}
11
+ >
12
+ Hello there!
13
+ </span>
14
+ `;
15
+ },
16
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithOnResize: import("../index.js").DeclarativeElementDefinition<"my-with-on-resize", {}, {}, {}, "my-with-on-resize-", "my-with-on-resize-", readonly []>;
@@ -0,0 +1,17 @@
1
+ import { defineElementNoInputs, html, onResize } from '../index.js';
2
+ export const MyWithOnResize = defineElementNoInputs({
3
+ tagName: 'my-with-on-resize',
4
+ render() {
5
+ return html `
6
+ <span
7
+ ${onResize((entry) => {
8
+ // this will track resizing of this span
9
+ // the entry parameter contains target and contentRect properties
10
+ console.info(entry);
11
+ })}
12
+ >
13
+ Hello there!
14
+ </span>
15
+ `;
16
+ },
17
+ });
@@ -0,0 +1,3 @@
1
+ export declare const MyWithRenderIf: import("../index.js").DeclarativeElementDefinition<"my-with-render-if", {
2
+ shouldRender: boolean;
3
+ }, {}, {}, "my-with-render-if-", "my-with-render-if-", readonly []>;
@@ -0,0 +1,11 @@
1
+ import { defineElement, html, renderIf } from '../index.js';
2
+ export const MyWithRenderIf = defineElement()({
3
+ tagName: 'my-with-render-if',
4
+ render({ inputs }) {
5
+ return html `
6
+ ${renderIf(inputs.shouldRender, html `
7
+ I'm conditionally rendered!
8
+ `)}
9
+ `;
10
+ },
11
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithStylesAndInterpolatedSelector: import("../index.js").DeclarativeElementDefinition<"my-with-styles-and-interpolated-selector", {}, {}, {}, "my-with-styles-and-interpolated-selector-", "my-with-styles-and-interpolated-selector-", readonly []>;
@@ -0,0 +1,15 @@
1
+ import { css, defineElementNoInputs, html } from '../index.js';
2
+ import { MySimple } from './my-simple.element.js';
3
+ export const MyWithStylesAndInterpolatedSelector = defineElementNoInputs({
4
+ tagName: 'my-with-styles-and-interpolated-selector',
5
+ styles: css `
6
+ ${MySimple} {
7
+ background-color: blue;
8
+ }
9
+ `,
10
+ render() {
11
+ return html `
12
+ <${MySimple}></${MySimple}>
13
+ `;
14
+ },
15
+ });
@@ -0,0 +1 @@
1
+ export declare const MyWithStyles: import("../index.js").DeclarativeElementDefinition<"my-with-styles", {}, {}, {}, "my-with-styles-", "my-with-styles-", readonly []>;
@@ -0,0 +1,21 @@
1
+ import { css, defineElementNoInputs, html } from '../index.js';
2
+ export const MyWithStyles = defineElementNoInputs({
3
+ tagName: 'my-with-styles',
4
+ styles: css `
5
+ :host {
6
+ display: flex;
7
+ flex-direction: column;
8
+ font-family: sans-serif;
9
+ }
10
+
11
+ span + span {
12
+ margin-top: 16px;
13
+ }
14
+ `,
15
+ render() {
16
+ return html `
17
+ <span>Hello there!</span>
18
+ <span>How are you doing?</span>
19
+ `;
20
+ },
21
+ });
@@ -0,0 +1,8 @@
1
+ export declare const MyWithUpdateState: import("../index.js").DeclarativeElementDefinition<"my-with-update-state", {}, {
2
+ username: string;
3
+ /**
4
+ * Use "as" to create state properties that can be types other than the initial value's
5
+ * type. This is particularly useful when, as below, the initial value is undefined.
6
+ */
7
+ email: string | undefined;
8
+ }, {}, "my-with-update-state-", "my-with-update-state-", readonly []>;
@@ -0,0 +1,23 @@
1
+ import { defineElementNoInputs, html, listen } from '../index.js';
2
+ export const MyWithUpdateState = defineElementNoInputs({
3
+ tagName: 'my-with-update-state',
4
+ stateInitStatic: {
5
+ username: 'dev',
6
+ /**
7
+ * Use "as" to create state properties that can be types other than the initial value's
8
+ * type. This is particularly useful when, as below, the initial value is undefined.
9
+ */
10
+ email: undefined,
11
+ },
12
+ render({ state, updateState }) {
13
+ return html `
14
+ <span
15
+ ${listen('click', () => {
16
+ updateState({ username: 'new name!' });
17
+ })}
18
+ >
19
+ Hello there ${state.username}!
20
+ </span>
21
+ `;
22
+ },
23
+ });
@@ -0,0 +1,2 @@
1
+ import { requireAllCustomElementsToBeDeclarativeElements } from '../index.js';
2
+ requireAllCustomElementsToBeDeclarativeElements();
@@ -1,2 +1,14 @@
1
+ /**
2
+ * Set by {@link requireAllCustomElementsToBeDeclarativeElements} and read in the HTML tagged
3
+ * template function.
4
+ *
5
+ * @category Internal
6
+ */
1
7
  export declare let declarativeElementRequired: boolean;
8
+ /**
9
+ * Calling this requires all custom element children to be declarative elements defined by
10
+ * element-vir.
11
+ *
12
+ * @category Util
13
+ */
2
14
  export declare function requireAllCustomElementsToBeDeclarativeElements(): void;
@@ -1,4 +1,16 @@
1
+ /**
2
+ * Set by {@link requireAllCustomElementsToBeDeclarativeElements} and read in the HTML tagged
3
+ * template function.
4
+ *
5
+ * @category Internal
6
+ */
1
7
  export let declarativeElementRequired = false;
8
+ /**
9
+ * Calling this requires all custom element children to be declarative elements defined by
10
+ * element-vir.
11
+ *
12
+ * @category Util
13
+ */
2
14
  export function requireAllCustomElementsToBeDeclarativeElements() {
3
15
  declarativeElementRequired = true;
4
16
  }
@@ -1,5 +1,11 @@
1
- import { DeclarativeElementDefinitionOptions } from '../declarative-element/definition-options';
2
- import { PropertyInitMapBase } from '../declarative-element/properties/element-properties';
1
+ import { DeclarativeElementDefinitionOptions } from '../declarative-element/definition-options.js';
2
+ import { PropertyInitMapBase } from '../declarative-element/properties/element-properties.js';
3
+ /**
4
+ * A minimal element definition used for interpolating element definitions into HTML templates with
5
+ * a more generic type (to prevent insane circular dependencies).
6
+ *
7
+ * @category Internal
8
+ */
3
9
  export type MinimalElementDefinition = {
4
10
  tagName: string;
5
11
  elementOptions?: DeclarativeElementDefinitionOptions | undefined;
@@ -8,10 +14,32 @@ export type MinimalElementDefinition = {
8
14
  tagName: string;
9
15
  } | undefined;
10
16
  };
17
+ /**
18
+ * A parent definition of {@link MinimalElementDefinition} with inputs also specified with allows the
19
+ * `.assign()` method to be used inside of HTML templates.
20
+ *
21
+ * @category Internal
22
+ */
11
23
  export type MinimalDefinitionWithInputs = {
24
+ /**
25
+ * This is what marks instance of this type as such. This does not use a symbol so it's
26
+ * compatible with multiple `element-vir` versions being installed at once (like if a dependency
27
+ * uses a different version).
28
+ */
12
29
  _elementVirIsMinimalDefinitionWithInputs: true;
13
30
  definition: MinimalElementDefinition;
14
31
  inputs: PropertyInitMapBase;
15
32
  };
33
+ /**
34
+ * Checks if the input is an instance of {@link MinimalDefinitionWithInputs}.
35
+ *
36
+ * @category Internal
37
+ */
16
38
  export declare function isMinimalDefinitionWithInputs(value: unknown): value is MinimalDefinitionWithInputs;
39
+ /**
40
+ * Checks if the input is an object that has a `tagName` property. Used inside of the HTML tagged
41
+ * template functions for checking if interpolated values should be treated as element tags.
42
+ *
43
+ * @category Internal
44
+ */
17
45
  export declare function hasTagName(value: unknown): value is MinimalElementDefinition;
@@ -1,8 +1,19 @@
1
- import { typedHasProperty } from '@augment-vir/common';
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Checks if the input is an instance of {@link MinimalDefinitionWithInputs}.
4
+ *
5
+ * @category Internal
6
+ */
2
7
  export function isMinimalDefinitionWithInputs(value) {
3
- return (typedHasProperty(value, '_elementVirIsMinimalDefinitionWithInputs') &&
8
+ return (check.hasKey(value, '_elementVirIsMinimalDefinitionWithInputs') &&
4
9
  !!value._elementVirIsMinimalDefinitionWithInputs);
5
10
  }
11
+ /**
12
+ * Checks if the input is an object that has a `tagName` property. Used inside of the HTML tagged
13
+ * template functions for checking if interpolated values should be treated as element tags.
14
+ *
15
+ * @category Internal
16
+ */
6
17
  export function hasTagName(value) {
7
- return (typedHasProperty(value, 'tagName') && !!value.tagName && typeof value.tagName === 'string');
18
+ return check.hasKey(value, 'tagName') && !!value.tagName && typeof value.tagName === 'string';
8
19
  }
@@ -1,4 +1,4 @@
1
- import { TemplateTransform } from './template-transform-type';
1
+ import { TemplateTransform } from './template-transform-type.js';
2
2
  export declare function getAlreadyMappedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[]): TemplateTransform | undefined;
3
3
  export declare function setMappedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[], valueToSet: TemplateTransform): {
4
4
  result: boolean;
@@ -1,5 +1,6 @@
1
- import { filterMap, isTruthy } from '@augment-vir/common';
2
- import { hasTagName, isMinimalDefinitionWithInputs } from './minimal-element-definition';
1
+ import { check } from '@augment-vir/assert';
2
+ import { filterMap } from '@augment-vir/common';
3
+ import { hasTagName, isMinimalDefinitionWithInputs } from './minimal-element-definition.js';
3
4
  function extractElementKeys(values) {
4
5
  return filterMap(values, (value) => {
5
6
  if (isMinimalDefinitionWithInputs(value)) {
@@ -9,7 +10,7 @@ function extractElementKeys(values) {
9
10
  return value.tagInterpolationKey || value;
10
11
  }
11
12
  return undefined;
12
- }, isTruthy);
13
+ }, check.isTruthy);
13
14
  }
14
15
  /**
15
16
  * The transformed templates are written to a map so that we can preserve reference equality between
@@ -1,4 +1,4 @@
1
- import { ArrayInsertion } from '../util/array';
1
+ import { ArrayInsertion } from '../util/array.js';
2
2
  export type AllValueTransforms = {
3
3
  valueIndexDeletions: number[];
4
4
  valueInsertions: ArrayInsertion<unknown>[];
@@ -1,4 +1,4 @@
1
- import { TemplateTransform } from './template-transform-type';
1
+ import { TemplateTransform } from './template-transform-type.js';
2
2
  export type ValueInsertion = {
3
3
  index: number;
4
4
  value: unknown;
@@ -1,14 +1,5 @@
1
- import { insertAndRemoveValues } from '../util/array';
2
- import { getAlreadyMappedTemplate, setMappedTemplate } from './nested-mapped-templates';
3
- /**
4
- * The transformed templates are written to a map so that we can preserve reference equality between
5
- * calls. Without maintaining reference equality between html`` calls, lit-element reconstructs all
6
- * of its children on every render.
7
- *
8
- * This is a WeakMap because we only care about the transformed array value as long as the original
9
- * template array key exists.
10
- */
11
- const transformedTemplateStrings = new WeakMap();
1
+ import { insertAndRemoveValues } from '../util/array.js';
2
+ import { getAlreadyMappedTemplate, setMappedTemplate } from './nested-mapped-templates.js';
12
3
  export function getTransformedTemplate(templateStringsKey, values, fallbackTransform) {
13
4
  const alreadyTransformedTemplateStrings = getAlreadyMappedTemplate(templateStringsKey, values);
14
5
  const templateTransform = alreadyTransformedTemplateStrings ?? fallbackTransform();
@@ -17,9 +8,6 @@ export function getTransformedTemplate(templateStringsKey, values, fallbackTrans
17
8
  if (!result.result) {
18
9
  throw new Error(`Failed to set template transform: ${result.reason}`);
19
10
  }
20
- else {
21
- transformedTemplateStrings.set(templateStringsKey, templateTransform);
22
- }
23
11
  }
24
12
  const valueTransforms = templateTransform.valuesTransform(values);
25
13
  const transformedValuesArray = insertAndRemoveValues(values, valueTransforms.valueInsertions, valueTransforms.valueIndexDeletions);
@@ -38,13 +26,18 @@ export function transformTemplate(inputTemplateStrings, inputValues, transformVa
38
26
  const lastNewString = newStrings[lastNewStringsIndex];
39
27
  const currentValueIndex = currentTemplateStringIndex - 1;
40
28
  const currentValue = inputValues[currentValueIndex];
41
- assertValidString && assertValidString(currentTemplateString);
29
+ if (assertValidString) {
30
+ assertValidString(currentTemplateString);
31
+ }
42
32
  let transformOutput = undefined;
43
33
  let extraValues = [];
44
34
  if (typeof lastNewString === 'string') {
45
35
  transformOutput = transformValue(lastNewString, currentTemplateString, currentValue);
46
36
  if (transformOutput) {
47
- newStrings[lastNewStringsIndex] = lastNewString + transformOutput.replacement;
37
+ newStrings[lastNewStringsIndex] = [
38
+ lastNewString,
39
+ transformOutput.replacement,
40
+ ].join('');
48
41
  valueIndexDeletions.push(currentValueIndex);
49
42
  const getExtraValuesCallback = transformOutput.getExtraValues;
50
43
  extraValues = getExtraValuesCallback ? getExtraValuesCallback(currentValue) : [];
@@ -74,10 +67,15 @@ export function transformTemplate(inputTemplateStrings, inputValues, transformVa
74
67
  if (!transformOutput) {
75
68
  newStrings.push(currentTemplateString);
76
69
  }
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77
71
  const currentRawLitString = inputTemplateStrings.raw[currentTemplateStringIndex];
78
72
  if (transformOutput) {
79
- newRaws[lastNewStringsIndex] =
80
- newRaws[lastNewStringsIndex] + transformOutput.replacement + currentRawLitString;
73
+ newRaws[lastNewStringsIndex] = [
74
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75
+ newRaws[lastNewStringsIndex],
76
+ transformOutput.replacement,
77
+ currentRawLitString,
78
+ ].join('');
81
79
  if (extraValues.length) {
82
80
  extraValues.forEach(() => {
83
81
  newRaws.push('');
@@ -94,9 +92,7 @@ export function transformTemplate(inputTemplateStrings, inputValues, transformVa
94
92
  return {
95
93
  templateStrings: newTemplateStrings,
96
94
  valuesTransform(values) {
97
- const insertions = valueTransforms
98
- .map((transformCallback) => transformCallback(values))
99
- .flat();
95
+ const insertions = valueTransforms.flatMap((transformCallback) => transformCallback(values));
100
96
  return {
101
97
  valueIndexDeletions,
102
98
  valueInsertions: insertions,
@@ -1,4 +1,4 @@
1
- import { CSSResultGroup } from '../../lit-exports/all-lit-exports';
2
- import { MinimalElementDefinition } from '../minimal-element-definition';
3
- import { TemplateTransform } from '../template-transform-type';
1
+ import { CSSResultGroup } from '../../lit-exports/all-lit-exports.js';
2
+ import { MinimalElementDefinition } from '../minimal-element-definition.js';
3
+ import { TemplateTransform } from '../template-transform-type.js';
4
4
  export declare function transformCssTemplate(inputTemplateStrings: TemplateStringsArray, inputValues: (number | CSSResultGroup | MinimalElementDefinition)[]): TemplateTransform;