element-vir 26.11.2 → 26.12.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 (188) hide show
  1. package/package.json +12 -12
  2. package/src/declarative-element/declarative-element-init.ts +115 -0
  3. package/src/declarative-element/declarative-element.ts +372 -0
  4. package/src/declarative-element/define-element.ts +515 -0
  5. package/{dist/declarative-element/definition-options.d.ts → src/declarative-element/definition-options.ts} +7 -2
  6. package/src/declarative-element/directives/assign.directive.ts +89 -0
  7. package/{dist/declarative-element/directives/async-prop.js → src/declarative-element/directives/async-prop.ts} +42 -8
  8. package/src/declarative-element/directives/attributes.directive.ts +63 -0
  9. package/src/declarative-element/directives/create-attribute-directive.ts +47 -0
  10. package/src/declarative-element/directives/directive-helpers.ts +67 -0
  11. package/{dist/declarative-element/directives/listen-to-activate.js → src/declarative-element/directives/listen-to-activate.ts} +8 -3
  12. package/src/declarative-element/directives/listen.directive.ts +206 -0
  13. package/src/declarative-element/directives/mutate.directive.ts +78 -0
  14. package/src/declarative-element/directives/on-dom-created.directive.ts +68 -0
  15. package/src/declarative-element/directives/on-dom-rendered.directive.ts +61 -0
  16. package/src/declarative-element/directives/on-intersect.directive.ts +139 -0
  17. package/src/declarative-element/directives/on-resize.directive.ts +142 -0
  18. package/src/declarative-element/directives/render-async.directive.ts +111 -0
  19. package/{dist/declarative-element/directives/render-if.directive.js → src/declarative-element/directives/render-if.directive.ts} +12 -3
  20. package/{dist/declarative-element/directives/test-id.directive.js → src/declarative-element/directives/test-id.directive.ts} +7 -2
  21. package/{dist/declarative-element/has-declarative-element-parent.js → src/declarative-element/has-declarative-element-parent.ts} +7 -4
  22. package/{dist/declarative-element/is-declarative-element-definition.js → src/declarative-element/is-declarative-element-definition.ts} +28 -11
  23. package/{dist/declarative-element/is-declarative-element.js → src/declarative-element/is-declarative-element.ts} +11 -5
  24. package/src/declarative-element/properties/assign-inputs.ts +30 -0
  25. package/src/declarative-element/properties/css-vars.ts +24 -0
  26. package/src/declarative-element/properties/element-events.ts +161 -0
  27. package/src/declarative-element/properties/host-classes.ts +63 -0
  28. package/{dist/declarative-element/properties/property-proxy.js → src/declarative-element/properties/property-proxy.ts} +58 -21
  29. package/src/declarative-element/properties/string-names.ts +83 -0
  30. package/src/declarative-element/properties/styles.ts +112 -0
  31. package/src/declarative-element/render-callback.ts +196 -0
  32. package/src/declarative-element/wrap-define-element.ts +127 -0
  33. package/{dist/index.d.ts → src/index.ts} +2 -0
  34. package/{dist/lit-exports/base-lit-exports.js → src/lit-exports/base-lit-exports.ts} +10 -1
  35. package/{dist/lit-exports/lit-repeat-fix.d.ts → src/lit-exports/lit-repeat-fix.ts} +45 -16
  36. package/{dist/readme-examples/my-app.element.js → src/readme-examples/my-app.element.ts} +5 -4
  37. package/src/readme-examples/my-custom-action.event.ts +3 -0
  38. package/{dist/readme-examples/my-custom-define.js → src/readme-examples/my-custom-define.ts} +9 -4
  39. package/{dist/readme-examples/my-simple.element.js → src/readme-examples/my-simple.element.ts} +4 -3
  40. package/src/readme-examples/my-with-assignment.element.ts +16 -0
  41. package/{dist/readme-examples/my-with-async-prop.element.js → src/readme-examples/my-with-async-prop.element.ts} +24 -16
  42. package/{dist/readme-examples/my-with-cleanup-callback.element.js → src/readme-examples/my-with-cleanup-callback.element.ts} +5 -4
  43. package/{dist/readme-examples/my-with-css-vars.element.js → src/readme-examples/my-with-css-vars.element.ts} +5 -4
  44. package/src/readme-examples/my-with-custom-events.element.ts +23 -0
  45. package/{dist/readme-examples/my-with-event-listening.element.js → src/readme-examples/my-with-event-listening.element.ts} +10 -9
  46. package/src/readme-examples/my-with-events.element.ts +23 -0
  47. package/{dist/readme-examples/my-with-host-class-definition.element.js → src/readme-examples/my-with-host-class-definition.element.ts} +7 -6
  48. package/{dist/readme-examples/my-with-host-class-usage.element.js → src/readme-examples/my-with-host-class-usage.element.ts} +5 -4
  49. package/src/readme-examples/my-with-inputs.element.ts +13 -0
  50. package/{dist/readme-examples/my-with-on-dom-created.element.js → src/readme-examples/my-with-on-dom-created.element.ts} +7 -6
  51. package/src/readme-examples/my-with-on-resize.element.ts +19 -0
  52. package/src/readme-examples/my-with-render-if.element.ts +15 -0
  53. package/{dist/readme-examples/my-with-styles-and-interpolated-selector.element.js → src/readme-examples/my-with-styles-and-interpolated-selector.element.ts} +6 -5
  54. package/{dist/readme-examples/my-with-styles.element.js → src/readme-examples/my-with-styles.element.ts} +5 -4
  55. package/{dist/readme-examples/my-with-update-state.element.js → src/readme-examples/my-with-update-state.element.ts} +8 -7
  56. package/src/readme-examples/require-declarative-element.ts +3 -0
  57. package/{dist/require-declarative-element.js → src/require-declarative-element.ts} +1 -0
  58. package/{dist/template-transforms/minimal-element-definition.d.ts → src/template-transforms/minimal-element-definition.ts} +19 -7
  59. package/src/template-transforms/nested-mapped-templates.ts +157 -0
  60. package/{dist/template-transforms/template-transform-type.d.ts → src/template-transforms/template-transform-type.ts} +3 -1
  61. package/{dist/template-transforms/transform-template.js → src/template-transforms/transform-template.ts} +70 -22
  62. package/src/template-transforms/vir-css/css-transform.ts +30 -0
  63. package/src/template-transforms/vir-css/vir-css.ts +30 -0
  64. package/src/template-transforms/vir-html/html-interpolation.ts +103 -0
  65. package/src/template-transforms/vir-html/html-transform.ts +149 -0
  66. package/{dist/template-transforms/vir-html/tag-name-keys.js → src/template-transforms/vir-html/tag-name-keys.ts} +1 -1
  67. package/{dist/template-transforms/vir-html/vir-html.js → src/template-transforms/vir-html/vir-html.ts} +13 -5
  68. package/src/typed-event/typed-event.ts +90 -0
  69. package/{dist/util/array.js → src/util/array.ts} +18 -5
  70. package/{dist/util/increment.d.ts → src/util/increment.ts} +24 -5
  71. package/{dist/util/lit-template.js → src/util/lit-template.ts} +30 -10
  72. package/src/util/map-async-value.ts +33 -0
  73. package/dist/declarative-element/custom-tag-name.js +0 -1
  74. package/dist/declarative-element/declarative-element-init.d.ts +0 -56
  75. package/dist/declarative-element/declarative-element-init.js +0 -1
  76. package/dist/declarative-element/declarative-element.d.ts +0 -114
  77. package/dist/declarative-element/declarative-element.js +0 -36
  78. package/dist/declarative-element/define-element.d.ts +0 -41
  79. package/dist/declarative-element/define-element.js +0 -248
  80. package/dist/declarative-element/definition-options.js +0 -9
  81. package/dist/declarative-element/directives/assign.directive.d.ts +0 -24
  82. package/dist/declarative-element/directives/assign.directive.js +0 -34
  83. package/dist/declarative-element/directives/async-prop.d.ts +0 -61
  84. package/dist/declarative-element/directives/attributes.directive.d.ts +0 -30
  85. package/dist/declarative-element/directives/attributes.directive.js +0 -35
  86. package/dist/declarative-element/directives/create-attribute-directive.d.ts +0 -28
  87. package/dist/declarative-element/directives/create-attribute-directive.js +0 -41
  88. package/dist/declarative-element/directives/directive-helpers.d.ts +0 -27
  89. package/dist/declarative-element/directives/directive-helpers.js +0 -37
  90. package/dist/declarative-element/directives/listen-to-activate.d.ts +0 -15
  91. package/dist/declarative-element/directives/listen.directive.d.ts +0 -92
  92. package/dist/declarative-element/directives/listen.directive.js +0 -48
  93. package/dist/declarative-element/directives/mutate.directive.d.ts +0 -38
  94. package/dist/declarative-element/directives/mutate.directive.js +0 -45
  95. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +0 -44
  96. package/dist/declarative-element/directives/on-dom-created.directive.js +0 -51
  97. package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +0 -41
  98. package/dist/declarative-element/directives/on-dom-rendered.directive.js +0 -45
  99. package/dist/declarative-element/directives/on-intersect.directive.d.ts +0 -64
  100. package/dist/declarative-element/directives/on-intersect.directive.js +0 -89
  101. package/dist/declarative-element/directives/on-resize.directive.d.ts +0 -74
  102. package/dist/declarative-element/directives/on-resize.directive.js +0 -106
  103. package/dist/declarative-element/directives/render-async.directive.d.ts +0 -45
  104. package/dist/declarative-element/directives/render-async.directive.js +0 -33
  105. package/dist/declarative-element/directives/render-if.directive.d.ts +0 -32
  106. package/dist/declarative-element/directives/test-id.directive.d.ts +0 -52
  107. package/dist/declarative-element/has-declarative-element-parent.d.ts +0 -1
  108. package/dist/declarative-element/is-declarative-element-definition.d.ts +0 -17
  109. package/dist/declarative-element/is-declarative-element.d.ts +0 -15
  110. package/dist/declarative-element/properties/assign-inputs.d.ts +0 -1
  111. package/dist/declarative-element/properties/assign-inputs.js +0 -25
  112. package/dist/declarative-element/properties/css-vars.d.ts +0 -16
  113. package/dist/declarative-element/properties/css-vars.js +0 -1
  114. package/dist/declarative-element/properties/element-events.d.ts +0 -65
  115. package/dist/declarative-element/properties/element-events.js +0 -62
  116. package/dist/declarative-element/properties/element-properties.js +0 -1
  117. package/dist/declarative-element/properties/host-classes.d.ts +0 -36
  118. package/dist/declarative-element/properties/host-classes.js +0 -16
  119. package/dist/declarative-element/properties/property-proxy.d.ts +0 -22
  120. package/dist/declarative-element/properties/string-names.d.ts +0 -28
  121. package/dist/declarative-element/properties/string-names.js +0 -40
  122. package/dist/declarative-element/properties/styles.d.ts +0 -51
  123. package/dist/declarative-element/properties/styles.js +0 -41
  124. package/dist/declarative-element/properties/tag-name.js +0 -1
  125. package/dist/declarative-element/render-callback.d.ts +0 -56
  126. package/dist/declarative-element/render-callback.js +0 -27
  127. package/dist/declarative-element/wrap-define-element.d.ts +0 -36
  128. package/dist/declarative-element/wrap-define-element.js +0 -25
  129. package/dist/index.js +0 -42
  130. package/dist/lit-exports/all-lit-exports.js +0 -2
  131. package/dist/lit-exports/base-lit-exports.d.ts +0 -25
  132. package/dist/lit-exports/lit-repeat-fix.js +0 -37
  133. package/dist/readme-examples/my-app.element.d.ts +0 -1
  134. package/dist/readme-examples/my-custom-action.event.d.ts +0 -1
  135. package/dist/readme-examples/my-custom-action.event.js +0 -2
  136. package/dist/readme-examples/my-custom-define.d.ts +0 -4
  137. package/dist/readme-examples/my-simple.element.d.ts +0 -1
  138. package/dist/readme-examples/my-with-assignment.element.d.ts +0 -1
  139. package/dist/readme-examples/my-with-assignment.element.js +0 -15
  140. package/dist/readme-examples/my-with-async-prop.element.d.ts +0 -10
  141. package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +0 -3
  142. package/dist/readme-examples/my-with-css-vars.element.d.ts +0 -1
  143. package/dist/readme-examples/my-with-custom-events.element.d.ts +0 -1
  144. package/dist/readme-examples/my-with-custom-events.element.js +0 -22
  145. package/dist/readme-examples/my-with-event-listening.element.d.ts +0 -3
  146. package/dist/readme-examples/my-with-events.element.d.ts +0 -4
  147. package/dist/readme-examples/my-with-events.element.js +0 -20
  148. package/dist/readme-examples/my-with-host-class-definition.element.d.ts +0 -3
  149. package/dist/readme-examples/my-with-host-class-usage.element.d.ts +0 -1
  150. package/dist/readme-examples/my-with-inputs.element.d.ts +0 -4
  151. package/dist/readme-examples/my-with-inputs.element.js +0 -9
  152. package/dist/readme-examples/my-with-on-dom-created.element.d.ts +0 -1
  153. package/dist/readme-examples/my-with-on-resize.element.d.ts +0 -1
  154. package/dist/readme-examples/my-with-on-resize.element.js +0 -18
  155. package/dist/readme-examples/my-with-render-if.element.d.ts +0 -3
  156. package/dist/readme-examples/my-with-render-if.element.js +0 -11
  157. package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +0 -1
  158. package/dist/readme-examples/my-with-styles.element.d.ts +0 -1
  159. package/dist/readme-examples/my-with-update-state.element.d.ts +0 -8
  160. package/dist/readme-examples/require-declarative-element.d.ts +0 -1
  161. package/dist/readme-examples/require-declarative-element.js +0 -2
  162. package/dist/require-declarative-element.d.ts +0 -14
  163. package/dist/template-transforms/minimal-element-definition.js +0 -19
  164. package/dist/template-transforms/nested-mapped-templates.d.ts +0 -6
  165. package/dist/template-transforms/nested-mapped-templates.js +0 -96
  166. package/dist/template-transforms/template-transform-type.js +0 -1
  167. package/dist/template-transforms/transform-template.d.ts +0 -14
  168. package/dist/template-transforms/vir-css/css-transform.d.ts +0 -4
  169. package/dist/template-transforms/vir-css/css-transform.js +0 -15
  170. package/dist/template-transforms/vir-css/vir-css.d.ts +0 -12
  171. package/dist/template-transforms/vir-css/vir-css.js +0 -21
  172. package/dist/template-transforms/vir-html/html-interpolation.d.ts +0 -42
  173. package/dist/template-transforms/vir-html/html-interpolation.js +0 -1
  174. package/dist/template-transforms/vir-html/html-transform.d.ts +0 -5
  175. package/dist/template-transforms/vir-html/html-transform.js +0 -96
  176. package/dist/template-transforms/vir-html/tag-name-keys.d.ts +0 -7
  177. package/dist/template-transforms/vir-html/vir-html.d.ts +0 -11
  178. package/dist/typed-event/typed-event.d.ts +0 -55
  179. package/dist/typed-event/typed-event.js +0 -50
  180. package/dist/util/array.d.ts +0 -5
  181. package/dist/util/increment.js +0 -1
  182. package/dist/util/lit-template.d.ts +0 -9
  183. package/dist/util/type.js +0 -1
  184. /package/{dist/declarative-element/custom-tag-name.d.ts → src/declarative-element/custom-tag-name.ts} +0 -0
  185. /package/{dist/declarative-element/properties/element-properties.d.ts → src/declarative-element/properties/element-properties.ts} +0 -0
  186. /package/{dist/declarative-element/properties/tag-name.d.ts → src/declarative-element/properties/tag-name.ts} +0 -0
  187. /package/{dist/lit-exports/all-lit-exports.d.ts → src/lit-exports/all-lit-exports.ts} +0 -0
  188. /package/{dist/util/type.d.ts → src/util/type.ts} +0 -0
@@ -1,30 +0,0 @@
1
- import { type Primitive } from 'type-fest';
2
- import { nothing } from '../../lit-exports/all-lit-exports.js';
3
- /**
4
- * Possible attribute values for {@link AttributeValues}.
5
- *
6
- * @category Internal
7
- */
8
- export type AttributeValue = Exclude<Primitive, symbol> | string | typeof nothing;
9
- /**
10
- * Parameters object for applying attributes to an HTML element via the {@link attributes} directive.
11
- * Make sure that all keys (attribute names) are lowercase.
12
- *
13
- * @category Internal
14
- */
15
- export type AttributeValues = {
16
- [LowercaseKey in Lowercase<string>]: AttributeValue;
17
- };
18
- /**
19
- * A directive applies multiple HTML attributes to the parent element all at once.
20
- *
21
- * @category Directives
22
- */
23
- export declare const attributes: (values_0: AttributeValues | undefined) => import("lit-html/directive.js").DirectiveResult<{
24
- new (partInfo: import("lit-html/directive.js").PartInfo): {
25
- readonly element: HTMLElement;
26
- render(params_0: AttributeValues | undefined): symbol;
27
- get _$isConnected(): boolean;
28
- update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
29
- };
30
- }>;
@@ -1,35 +0,0 @@
1
- import { getObjectTypedKeys, getOrSet } from '@augment-vir/common';
2
- import { nothing } from '../../lit-exports/all-lit-exports.js';
3
- import { createMutateDirective } from './mutate.directive.js';
4
- /**
5
- * A directive applies multiple HTML attributes to the parent element all at once.
6
- *
7
- * @category Directives
8
- */
9
- export const attributes = createMutateDirective('attributes', ({ element, params: [attributesToApply], directive: rawDirective }) => {
10
- if (!attributesToApply) {
11
- return;
12
- }
13
- const directive = rawDirective;
14
- const allAttributeNames = getOrSet(directive, 'allAttributesApplied', () => new Set());
15
- getObjectTypedKeys(attributesToApply).forEach((attributeName) => {
16
- if (attributeName.toLowerCase() !== attributeName) {
17
- throw new Error(`Cannot assign attribute name with uppercase letters: ${attributeName}`);
18
- }
19
- allAttributeNames.add(attributeName);
20
- });
21
- allAttributeNames.forEach((attributeName) => {
22
- const attributeValue = attributesToApply[attributeName];
23
- if (attributeValue == undefined ||
24
- attributeValue === false ||
25
- attributeValue === nothing) {
26
- element.removeAttribute(attributeName);
27
- }
28
- else if (attributeValue === '' || attributeValue === true) {
29
- element.setAttribute(attributeName, '');
30
- }
31
- else {
32
- element.setAttribute(attributeName, String(attributeValue));
33
- }
34
- });
35
- });
@@ -1,28 +0,0 @@
1
- import { type PartInfo } from '../../lit-exports/all-lit-exports.js';
2
- /**
3
- * Creates a lit directive that used simply for setting attributes on its parent element.
4
- *
5
- * @category Internal
6
- */
7
- export declare function createAttributeDirective(attributeName: string): {
8
- /**
9
- * Creates a string for use with the
10
- * [`querySelector`](https://developer.mozilla.org/docs/Web/API/Document/querySelector) API
11
- * that selects this directive's attribute set to the given `attributeValue`.
12
- */
13
- attributeSelector(this: void, attributeValue: string): string;
14
- /**
15
- * Instantiates the attribute directive. This must be used on an element inside of an HTML
16
- * template.
17
- */
18
- attributeDirective(this: void, attributeValue: string): import("lit-html/directive.js").DirectiveResult<{
19
- new (partInfo: PartInfo): {
20
- readonly element: Element;
21
- render(attributeValue: string): symbol;
22
- get _$isConnected(): boolean;
23
- update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
24
- };
25
- }>;
26
- /** The name of the attribute used in the directive. */
27
- attributeName: string;
28
- };
@@ -1,41 +0,0 @@
1
- import { directive, Directive, noChange } from '../../lit-exports/all-lit-exports.js';
2
- import { extractElement } from './directive-helpers.js';
3
- /**
4
- * Creates a lit directive that used simply for setting attributes on its parent element.
5
- *
6
- * @category Internal
7
- */
8
- export function createAttributeDirective(attributeName) {
9
- const newDirective = directive(
10
- /** @internal */
11
- class extends Directive {
12
- element;
13
- constructor(partInfo) {
14
- super(partInfo);
15
- this.element = extractElement(partInfo, attributeName);
16
- }
17
- render(attributeValue) {
18
- this.element.setAttribute(attributeName, attributeValue);
19
- return noChange;
20
- }
21
- });
22
- return {
23
- /**
24
- * Creates a string for use with the
25
- * [`querySelector`](https://developer.mozilla.org/docs/Web/API/Document/querySelector) API
26
- * that selects this directive's attribute set to the given `attributeValue`.
27
- */
28
- attributeSelector(attributeValue) {
29
- return `[${attributeName}="${attributeValue}"]`;
30
- },
31
- /**
32
- * Instantiates the attribute directive. This must be used on an element inside of an HTML
33
- * template.
34
- */
35
- attributeDirective(attributeValue) {
36
- return newDirective(attributeValue);
37
- },
38
- /** The name of the attribute used in the directive. */
39
- attributeName,
40
- };
41
- }
@@ -1,27 +0,0 @@
1
- import { type ElementPartInfo, type PartInfo } from '../../lit-exports/all-lit-exports.js';
2
- /**
3
- * The full type for `ElementPartInfo` because `lit`'s built-in type leaves out of most of its
4
- * interface.
5
- *
6
- * @category Internal
7
- */
8
- export type FullElementPartInfo = ElementPartInfo /** For some reason these aren't defined in lit's types already, even though they _do_ exist. */ & {
9
- element: Element;
10
- options: {
11
- host: Element;
12
- renderBefore: Element;
13
- isConnected: boolean;
14
- };
15
- };
16
- /**
17
- * Extracts the element from the given part info. Used in lit directives.
18
- *
19
- * @category Internal
20
- */
21
- export declare function extractElement(partInfo: PartInfo, directiveName: string): Element;
22
- /**
23
- * Asserts that the given part info is an instance of {@link FullElementPartInfo}.
24
- *
25
- * @category Internal
26
- */
27
- export declare function assertIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is FullElementPartInfo;
@@ -1,37 +0,0 @@
1
- import { PartType, } from '../../lit-exports/all-lit-exports.js';
2
- /**
3
- * Extracts the element from the given part info. Used in lit directives.
4
- *
5
- * @category Internal
6
- */
7
- export function extractElement(partInfo, directiveName) {
8
- assertIsElementPartInfo(partInfo, directiveName);
9
- const element = partInfo.element;
10
- return element;
11
- }
12
- function getPartHostTagName(partInfo) {
13
- try {
14
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15
- const tagName = partInfo.options.host.tagName.toLowerCase();
16
- return tagName;
17
- }
18
- catch {
19
- return undefined;
20
- }
21
- }
22
- /**
23
- * Asserts that the given part info is an instance of {@link FullElementPartInfo}.
24
- *
25
- * @category Internal
26
- */
27
- export function assertIsElementPartInfo(partInfo, directiveName) {
28
- const hostTagName = getPartHostTagName(partInfo);
29
- const hostTagMessage = hostTagName ? `: in ${hostTagName}` : '';
30
- if (partInfo.type !== PartType.ELEMENT) {
31
- throw new Error(`${directiveName} directive can only be attached directly to an element${hostTagMessage}.`);
32
- }
33
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
34
- if (!partInfo.element) {
35
- throw new Error(`${directiveName} directive found no element${hostTagMessage}.`);
36
- }
37
- }
@@ -1,15 +0,0 @@
1
- import { type MaybePromise } from '@augment-vir/common';
2
- /**
3
- * Listens to enter, return, and space key hits on an element. Similar to {@link listenToEnter} but
4
- * includes space.
5
- *
6
- * @category Directives
7
- */
8
- export declare function listenToActivate(callback: () => MaybePromise<void>): import("lit-html/directive.js").DirectiveResult<any>;
9
- /**
10
- * Listens to enter and return key hits on an element. Similar to {@link listenToActivate} but
11
- * doesn't include space.
12
- *
13
- * @category Directives
14
- */
15
- export declare function listenToEnter(callback: () => MaybePromise<void>): import("lit-html/directive.js").DirectiveResult<any>;
@@ -1,92 +0,0 @@
1
- import { type MaybePromise } from '@augment-vir/common';
2
- import { type DirectiveResult } from '../../lit-exports/all-lit-exports.js';
3
- import { type DefinedTypedEvent, type TypedEvent } from '../../typed-event/typed-event.js';
4
- /** We don't care at all what this returns, just allow anything! */
5
- type ListenCallbackReturn = MaybePromise<any>;
6
- /**
7
- * Listen to events. These can be native DOM events (use a string for the inputType argument) or
8
- * typed events (pass in a return value from {@link defineTypedEvent}).
9
- *
10
- * @category Directives
11
- * @example
12
- *
13
- * ```ts
14
- * import {html, defineElement, listen} from 'element-vir';
15
- *
16
- * const MyElement = defineElement()({
17
- * tagName: 'my-element',
18
- * render() {
19
- * return html`
20
- * <div
21
- * ${listen('click', () => {
22
- * console.log('clicked!');
23
- * })}
24
- * >
25
- * Some div
26
- * </div>
27
- * <${MyOtherElement}
28
- * ${listen(MyOtherElement.events.someEvent, (event) => {
29
- * console.log('event value', event.detail);
30
- * })}
31
- * ></${MyOtherElement}>
32
- * `;
33
- * },
34
- * });
35
- * ```
36
- */
37
- export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric>(
38
- /**
39
- * Needs to come either from a declarative element (like MyDeclarativeElement.events.eventName),
40
- * from a typed event created via the {@link defineTypedEvent} function, or be the name of a
41
- * built-in event (like `'click'`).
42
- */
43
- eventType: DefinedTypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>,
44
- /**
45
- * The callback to fire when an event is caught. Assuming the {@link defineTypedEvent} input is
46
- * properly typed, the event given to this callback will also be typed.
47
- */
48
- listener: (event: TypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>) => ListenCallbackReturn): DirectiveResult<any>;
49
- /**
50
- * Listen to events. These can be native DOM events (use a string for the inputType argument) or
51
- * typed events (pass in a return value from {@link defineTypedEvent}).
52
- *
53
- * @category Directives
54
- * @example
55
- *
56
- * ```ts
57
- * import {html, defineElement, listen} from 'element-vir';
58
- *
59
- * const MyElement = defineElement()({
60
- * tagName: 'my-element',
61
- * render() {
62
- * return html`
63
- * <div
64
- * ${listen('click', () => {
65
- * console.log('clicked!');
66
- * })}
67
- * >
68
- * Some div
69
- * </div>
70
- * <${MyOtherElement}
71
- * ${listen(MyOtherElement.events.someEvent, (event) => {
72
- * console.log('event value', event.detail);
73
- * })}
74
- * ></${MyOtherElement}>
75
- * `;
76
- * },
77
- * });
78
- * ```
79
- */
80
- export declare function listen<NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(
81
- /**
82
- * Needs to come either from a declarative element (like MyDeclarativeElement.events.eventName),
83
- * from a typed event created via the {@link defineTypedEvent} function, or be the name of a
84
- * built-in event (like `'click'`).
85
- */
86
- eventType: NativeElementEventNameGeneric,
87
- /**
88
- * The callback to fire when an event is caught. Assuming the {@link defineTypedEvent} input is
89
- * properly typed, the event given to this callback will also be typed.
90
- */
91
- listener: (event: HTMLElementEventMap[NativeElementEventNameGeneric]) => ListenCallbackReturn): DirectiveResult<any>;
92
- export {};
@@ -1,48 +0,0 @@
1
- import { directive, Directive, noChange, } from '../../lit-exports/all-lit-exports.js';
2
- import { extractElement } from './directive-helpers.js';
3
- export function listen(eventType, listener) {
4
- return listenDirective(eventType, listener);
5
- }
6
- /**
7
- * The directive generics here are not strong enough to maintain their values. Thus, the directive
8
- * call is wrapped in the function above.
9
- */
10
- const listenDirective = directive(class extends Directive {
11
- element;
12
- lastListenerMetaData;
13
- constructor(partInfo) {
14
- super(partInfo);
15
- this.element = extractElement(partInfo, 'listen');
16
- }
17
- resetListener(listenerMetaData) {
18
- if (this.lastListenerMetaData) {
19
- this.element.removeEventListener(this.lastListenerMetaData.eventType, this.lastListenerMetaData.listener);
20
- }
21
- this.element.addEventListener(listenerMetaData.eventType, listenerMetaData.listener);
22
- this.lastListenerMetaData = listenerMetaData;
23
- }
24
- createListenerMetaData(eventType, callback) {
25
- return {
26
- eventType,
27
- callback,
28
- listener: (event) => this.lastListenerMetaData?.callback(event),
29
- };
30
- }
31
- render(eventTypeInput, callback) {
32
- const eventType = typeof eventTypeInput === 'string' ? eventTypeInput : eventTypeInput.type;
33
- if (typeof eventType !== 'string') {
34
- throw new TypeError(`Cannot listen to an event with a name that is not a string. Given event name: '${String(eventType)}'`);
35
- }
36
- if (this.lastListenerMetaData && this.lastListenerMetaData.eventType === eventType) {
37
- /**
38
- * Store the callback here so we don't have to update the attached listener every
39
- * time the callback is updated.
40
- */
41
- this.lastListenerMetaData.callback = callback;
42
- }
43
- else {
44
- this.resetListener(this.createListenerMetaData(eventType, callback));
45
- }
46
- return noChange;
47
- }
48
- });
@@ -1,38 +0,0 @@
1
- import { Directive, type PartInfo } from '../../lit-exports/all-lit-exports.js';
2
- /**
3
- * Parameters for the callback given to the {@link mutate} directive.
4
- *
5
- * @category Internal
6
- */
7
- export type MutateDirectiveParams<Params extends any[] = []> = {
8
- directive: Directive;
9
- element: HTMLElement;
10
- params: Params;
11
- };
12
- /**
13
- * A directive that allows arbitrary modifications to be made to the element that it's attached to.
14
- *
15
- * @category Directives
16
- */
17
- export declare const mutate: (callback: (params: Omit<MutateDirectiveParams, "params">) => void) => import("lit-html/directive.js").DirectiveResult<{
18
- new (partInfo: PartInfo): {
19
- readonly element: HTMLElement;
20
- lastKey: string | undefined;
21
- render(callback: (params: Omit<MutateDirectiveParams, "params">) => void): symbol;
22
- get _$isConnected(): boolean;
23
- update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
24
- };
25
- }>;
26
- /**
27
- * A helper for making new directives.
28
- *
29
- * @category Internal
30
- */
31
- export declare function createMutateDirective<Params extends any[]>(directiveName: string, callback: (this: void, params: MutateDirectiveParams<Params>) => void): (...values: Params) => import("lit-html/directive.js").DirectiveResult<{
32
- new (partInfo: PartInfo): {
33
- readonly element: HTMLElement;
34
- render(...params: Params): symbol;
35
- get _$isConnected(): boolean;
36
- update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
37
- };
38
- }>;
@@ -1,45 +0,0 @@
1
- import { assertWrap } from '@augment-vir/assert';
2
- import { directive, Directive, noChange } from '../../lit-exports/all-lit-exports.js';
3
- import { extractElement } from './directive-helpers.js';
4
- /**
5
- * A directive that allows arbitrary modifications to be made to the element that it's attached to.
6
- *
7
- * @category Directives
8
- */
9
- export const mutate = directive(class extends Directive {
10
- element;
11
- lastKey;
12
- constructor(partInfo) {
13
- super(partInfo);
14
- this.element = assertWrap.instanceOf(extractElement(partInfo, 'modifyElement'), HTMLElement);
15
- }
16
- render(callback) {
17
- callback({
18
- directive: this,
19
- element: this.element,
20
- });
21
- return noChange;
22
- }
23
- });
24
- /**
25
- * A helper for making new directives.
26
- *
27
- * @category Internal
28
- */
29
- export function createMutateDirective(directiveName, callback) {
30
- return directive(class extends Directive {
31
- element;
32
- constructor(partInfo) {
33
- super(partInfo);
34
- this.element = assertWrap.instanceOf(extractElement(partInfo, directiveName), HTMLElement);
35
- }
36
- render(...params) {
37
- callback({
38
- params,
39
- directive: this,
40
- element: this.element,
41
- });
42
- return noChange;
43
- }
44
- });
45
- }
@@ -1,44 +0,0 @@
1
- import { type MaybePromise } from '@augment-vir/common';
2
- import { type PartInfo } from '../../lit-exports/all-lit-exports.js';
3
- /**
4
- * The callback / listener passed to {@link onDomCreated}. The `element` parameter is a reference to
5
- * the DOM element that the directive was attached to.
6
- *
7
- * @category Internal
8
- */
9
- export type OnDomCreatedCallback = (element: Element) => MaybePromise<void>;
10
- /**
11
- * A directive that fires its listener only once, when the element that it's attached to is
12
- * constructed. This is particularly useful for getting references to internal elements immediately
13
- * after they've rendered.
14
- *
15
- * @category Directives
16
- * @example
17
- *
18
- * ```ts
19
- * import {html, defineElement, onDomCreated} from 'element-vir';
20
- *
21
- * const MyElement = defineElement()({
22
- * tagName: 'my-element',
23
- * render() {
24
- * return html`
25
- * <div
26
- * ${onDomCreated((element) => {
27
- * console.log('created!', element);
28
- * })}
29
- * >
30
- * Some div
31
- * </div>
32
- * `;
33
- * },
34
- * });
35
- * ```
36
- */
37
- export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("lit-html/directive.js").DirectiveResult<{
38
- new (partInfo: PartInfo): {
39
- element: Element | undefined;
40
- update(partInfo: PartInfo, [callback]: [OnDomCreatedCallback]): undefined;
41
- render(callback: OnDomCreatedCallback): undefined;
42
- get _$isConnected(): boolean;
43
- };
44
- }>;
@@ -1,51 +0,0 @@
1
- import { directive, Directive } from '../../lit-exports/all-lit-exports.js';
2
- import { assertIsElementPartInfo } from './directive-helpers.js';
3
- const directiveName = 'onDomCreated';
4
- /**
5
- * A directive that fires its listener only once, when the element that it's attached to is
6
- * constructed. This is particularly useful for getting references to internal elements immediately
7
- * after they've rendered.
8
- *
9
- * @category Directives
10
- * @example
11
- *
12
- * ```ts
13
- * import {html, defineElement, onDomCreated} from 'element-vir';
14
- *
15
- * const MyElement = defineElement()({
16
- * tagName: 'my-element',
17
- * render() {
18
- * return html`
19
- * <div
20
- * ${onDomCreated((element) => {
21
- * console.log('created!', element);
22
- * })}
23
- * >
24
- * Some div
25
- * </div>
26
- * `;
27
- * },
28
- * });
29
- * ```
30
- */
31
- export const onDomCreated = directive(class extends Directive {
32
- element;
33
- constructor(partInfo) {
34
- super(partInfo);
35
- assertIsElementPartInfo(partInfo, directiveName);
36
- }
37
- update(partInfo, [callback]) {
38
- assertIsElementPartInfo(partInfo, directiveName);
39
- const newElement = partInfo.element;
40
- if (newElement !== this.element) {
41
- // use requestAnimationFrame here so it can fire property changes outside of a render loop
42
- window.requestAnimationFrame(() => callback(newElement));
43
- this.element = newElement;
44
- }
45
- return this.render(callback);
46
- }
47
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
- render(callback) {
49
- return undefined;
50
- }
51
- });
@@ -1,41 +0,0 @@
1
- import { type MaybePromise } from '@augment-vir/common';
2
- import { type PartInfo } from '../../lit-exports/all-lit-exports.js';
3
- /**
4
- * The callback / listener passed to {@link onDomRendered}. The `element` parameter is a reference to
5
- * the DOM element that the directive was attached to.
6
- *
7
- * @category Internal
8
- */
9
- export type OnDomRenderedCallback = (element: Element) => MaybePromise<void>;
10
- /**
11
- * A directive that fires its listener each time the element that it's attached to is rendered.
12
- *
13
- * @category Directives
14
- * @example
15
- *
16
- * ```ts
17
- * import {html, defineElement, onDomRendered} from 'element-vir';
18
- *
19
- * const MyElement = defineElement()({
20
- * tagName: 'my-element',
21
- * render() {
22
- * return html`
23
- * <div
24
- * ${onDomRendered((element) => {
25
- * console.log('rendered!', element);
26
- * })}
27
- * >
28
- * Some div
29
- * </div>
30
- * `;
31
- * },
32
- * });
33
- * ```
34
- */
35
- export declare const onDomRendered: (callback: OnDomRenderedCallback) => import("lit-html/directive.js").DirectiveResult<{
36
- new (partInfo: PartInfo): {
37
- update(partInfo: PartInfo, [callback]: [OnDomRenderedCallback]): undefined;
38
- render(callback: OnDomRenderedCallback): undefined;
39
- get _$isConnected(): boolean;
40
- };
41
- }>;
@@ -1,45 +0,0 @@
1
- import { directive, Directive } from '../../lit-exports/all-lit-exports.js';
2
- import { assertIsElementPartInfo } from './directive-helpers.js';
3
- const directiveName = 'onDomRendered';
4
- /**
5
- * A directive that fires its listener each time the element that it's attached to is rendered.
6
- *
7
- * @category Directives
8
- * @example
9
- *
10
- * ```ts
11
- * import {html, defineElement, onDomRendered} from 'element-vir';
12
- *
13
- * const MyElement = defineElement()({
14
- * tagName: 'my-element',
15
- * render() {
16
- * return html`
17
- * <div
18
- * ${onDomRendered((element) => {
19
- * console.log('rendered!', element);
20
- * })}
21
- * >
22
- * Some div
23
- * </div>
24
- * `;
25
- * },
26
- * });
27
- * ```
28
- */
29
- export const onDomRendered = directive(class extends Directive {
30
- constructor(partInfo) {
31
- super(partInfo);
32
- assertIsElementPartInfo(partInfo, directiveName);
33
- }
34
- update(partInfo, [callback]) {
35
- assertIsElementPartInfo(partInfo, directiveName);
36
- const element = partInfo.element;
37
- // use `requestAnimationFrame` here so it can fire property changes outside of a render loop
38
- window.requestAnimationFrame(() => callback(element));
39
- return this.render(callback);
40
- }
41
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- render(callback) {
43
- return undefined;
44
- }
45
- });