element-vir 26.12.0 → 26.12.1

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 (189) hide show
  1. package/dist/declarative-element/custom-tag-name.js +1 -0
  2. package/dist/declarative-element/declarative-element-init.d.ts +56 -0
  3. package/dist/declarative-element/declarative-element-init.js +1 -0
  4. package/dist/declarative-element/declarative-element.d.ts +114 -0
  5. package/dist/declarative-element/declarative-element.js +36 -0
  6. package/dist/declarative-element/define-element.d.ts +41 -0
  7. package/dist/declarative-element/define-element.js +248 -0
  8. package/{src/declarative-element/definition-options.ts → dist/declarative-element/definition-options.d.ts} +2 -7
  9. package/dist/declarative-element/definition-options.js +9 -0
  10. package/dist/declarative-element/directives/assign.directive.d.ts +24 -0
  11. package/dist/declarative-element/directives/assign.directive.js +34 -0
  12. package/dist/declarative-element/directives/async-prop.d.ts +61 -0
  13. package/{src/declarative-element/directives/async-prop.ts → dist/declarative-element/directives/async-prop.js} +8 -42
  14. package/dist/declarative-element/directives/attributes.directive.d.ts +30 -0
  15. package/dist/declarative-element/directives/attributes.directive.js +35 -0
  16. package/dist/declarative-element/directives/create-attribute-directive.d.ts +28 -0
  17. package/dist/declarative-element/directives/create-attribute-directive.js +41 -0
  18. package/dist/declarative-element/directives/directive-helpers.d.ts +27 -0
  19. package/dist/declarative-element/directives/directive-helpers.js +37 -0
  20. package/dist/declarative-element/directives/listen-to-activate.d.ts +15 -0
  21. package/{src/declarative-element/directives/listen-to-activate.ts → dist/declarative-element/directives/listen-to-activate.js} +3 -8
  22. package/dist/declarative-element/directives/listen.directive.d.ts +92 -0
  23. package/dist/declarative-element/directives/listen.directive.js +48 -0
  24. package/dist/declarative-element/directives/mutate.directive.d.ts +38 -0
  25. package/dist/declarative-element/directives/mutate.directive.js +45 -0
  26. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +44 -0
  27. package/dist/declarative-element/directives/on-dom-created.directive.js +51 -0
  28. package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +41 -0
  29. package/dist/declarative-element/directives/on-dom-rendered.directive.js +45 -0
  30. package/dist/declarative-element/directives/on-intersect.directive.d.ts +64 -0
  31. package/dist/declarative-element/directives/on-intersect.directive.js +89 -0
  32. package/dist/declarative-element/directives/on-resize.directive.d.ts +74 -0
  33. package/dist/declarative-element/directives/on-resize.directive.js +106 -0
  34. package/dist/declarative-element/directives/render-async.directive.d.ts +45 -0
  35. package/dist/declarative-element/directives/render-async.directive.js +33 -0
  36. package/dist/declarative-element/directives/render-if.directive.d.ts +32 -0
  37. package/{src/declarative-element/directives/render-if.directive.ts → dist/declarative-element/directives/render-if.directive.js} +3 -12
  38. package/dist/declarative-element/directives/test-id.directive.d.ts +52 -0
  39. package/{src/declarative-element/directives/test-id.directive.ts → dist/declarative-element/directives/test-id.directive.js} +2 -7
  40. package/dist/declarative-element/has-declarative-element-parent.d.ts +1 -0
  41. package/{src/declarative-element/has-declarative-element-parent.ts → dist/declarative-element/has-declarative-element-parent.js} +4 -7
  42. package/dist/declarative-element/is-declarative-element-definition.d.ts +17 -0
  43. package/{src/declarative-element/is-declarative-element-definition.ts → dist/declarative-element/is-declarative-element-definition.js} +11 -28
  44. package/dist/declarative-element/is-declarative-element.d.ts +15 -0
  45. package/{src/declarative-element/is-declarative-element.ts → dist/declarative-element/is-declarative-element.js} +5 -11
  46. package/dist/declarative-element/properties/assign-inputs.d.ts +1 -0
  47. package/dist/declarative-element/properties/assign-inputs.js +25 -0
  48. package/dist/declarative-element/properties/css-vars.d.ts +16 -0
  49. package/dist/declarative-element/properties/css-vars.js +1 -0
  50. package/dist/declarative-element/properties/element-events.d.ts +65 -0
  51. package/dist/declarative-element/properties/element-events.js +62 -0
  52. package/dist/declarative-element/properties/element-properties.js +1 -0
  53. package/dist/declarative-element/properties/host-classes.d.ts +36 -0
  54. package/dist/declarative-element/properties/host-classes.js +16 -0
  55. package/dist/declarative-element/properties/property-proxy.d.ts +22 -0
  56. package/{src/declarative-element/properties/property-proxy.ts → dist/declarative-element/properties/property-proxy.js} +21 -58
  57. package/dist/declarative-element/properties/string-names.d.ts +28 -0
  58. package/dist/declarative-element/properties/string-names.js +40 -0
  59. package/dist/declarative-element/properties/styles.d.ts +51 -0
  60. package/dist/declarative-element/properties/styles.js +41 -0
  61. package/dist/declarative-element/properties/tag-name.js +1 -0
  62. package/dist/declarative-element/render-callback.d.ts +56 -0
  63. package/dist/declarative-element/render-callback.js +27 -0
  64. package/dist/declarative-element/wrap-define-element.d.ts +36 -0
  65. package/dist/declarative-element/wrap-define-element.js +25 -0
  66. package/{src/index.ts → dist/index.d.ts} +0 -1
  67. package/dist/index.js +43 -0
  68. package/dist/lit-exports/all-lit-exports.js +2 -0
  69. package/{src/lit-exports/base-lit-exports.ts → dist/lit-exports/base-lit-exports.d.ts} +2 -10
  70. package/dist/lit-exports/base-lit-exports.js +24 -0
  71. package/{src/lit-exports/lit-repeat-fix.ts → dist/lit-exports/lit-repeat-fix.d.ts} +16 -45
  72. package/dist/lit-exports/lit-repeat-fix.js +37 -0
  73. package/dist/readme-examples/my-app.element.d.ts +1 -0
  74. package/{src/readme-examples/my-app.element.ts → dist/readme-examples/my-app.element.js} +4 -5
  75. package/dist/readme-examples/my-custom-action.event.d.ts +1 -0
  76. package/dist/readme-examples/my-custom-action.event.js +2 -0
  77. package/dist/readme-examples/my-custom-define.d.ts +4 -0
  78. package/{src/readme-examples/my-custom-define.ts → dist/readme-examples/my-custom-define.js} +4 -9
  79. package/dist/readme-examples/my-simple.element.d.ts +1 -0
  80. package/{src/readme-examples/my-simple.element.ts → dist/readme-examples/my-simple.element.js} +3 -4
  81. package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
  82. package/dist/readme-examples/my-with-assignment.element.js +15 -0
  83. package/dist/readme-examples/my-with-async-prop.element.d.ts +10 -0
  84. package/{src/readme-examples/my-with-async-prop.element.ts → dist/readme-examples/my-with-async-prop.element.js} +16 -24
  85. package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
  86. package/{src/readme-examples/my-with-cleanup-callback.element.ts → dist/readme-examples/my-with-cleanup-callback.element.js} +4 -5
  87. package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
  88. package/{src/readme-examples/my-with-css-vars.element.ts → dist/readme-examples/my-with-css-vars.element.js} +4 -5
  89. package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
  90. package/dist/readme-examples/my-with-custom-events.element.js +22 -0
  91. package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
  92. package/{src/readme-examples/my-with-event-listening.element.ts → dist/readme-examples/my-with-event-listening.element.js} +9 -10
  93. package/dist/readme-examples/my-with-events.element.d.ts +4 -0
  94. package/dist/readme-examples/my-with-events.element.js +20 -0
  95. package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
  96. package/{src/readme-examples/my-with-host-class-definition.element.ts → dist/readme-examples/my-with-host-class-definition.element.js} +6 -7
  97. package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
  98. package/{src/readme-examples/my-with-host-class-usage.element.ts → dist/readme-examples/my-with-host-class-usage.element.js} +4 -5
  99. package/dist/readme-examples/my-with-inputs.element.d.ts +4 -0
  100. package/dist/readme-examples/my-with-inputs.element.js +9 -0
  101. package/dist/readme-examples/my-with-on-dom-created.element.d.ts +1 -0
  102. package/{src/readme-examples/my-with-on-dom-created.element.ts → dist/readme-examples/my-with-on-dom-created.element.js} +6 -7
  103. package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
  104. package/dist/readme-examples/my-with-on-resize.element.js +18 -0
  105. package/dist/readme-examples/my-with-render-if.element.d.ts +3 -0
  106. package/dist/readme-examples/my-with-render-if.element.js +11 -0
  107. package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +1 -0
  108. package/{src/readme-examples/my-with-styles-and-interpolated-selector.element.ts → dist/readme-examples/my-with-styles-and-interpolated-selector.element.js} +5 -6
  109. package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
  110. package/{src/readme-examples/my-with-styles.element.ts → dist/readme-examples/my-with-styles.element.js} +4 -5
  111. package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
  112. package/{src/readme-examples/my-with-update-state.element.ts → dist/readme-examples/my-with-update-state.element.js} +7 -8
  113. package/dist/readme-examples/require-declarative-element.d.ts +1 -0
  114. package/dist/readme-examples/require-declarative-element.js +2 -0
  115. package/dist/require-declarative-element.d.ts +14 -0
  116. package/{src/require-declarative-element.ts → dist/require-declarative-element.js} +0 -1
  117. package/{src/template-transforms/minimal-element-definition.ts → dist/template-transforms/minimal-element-definition.d.ts} +7 -19
  118. package/dist/template-transforms/minimal-element-definition.js +19 -0
  119. package/dist/template-transforms/nested-mapped-templates.d.ts +6 -0
  120. package/dist/template-transforms/nested-mapped-templates.js +96 -0
  121. package/{src/template-transforms/template-transform-type.ts → dist/template-transforms/template-transform-type.d.ts} +1 -3
  122. package/dist/template-transforms/template-transform-type.js +1 -0
  123. package/dist/template-transforms/transform-template.d.ts +14 -0
  124. package/{src/template-transforms/transform-template.ts → dist/template-transforms/transform-template.js} +22 -70
  125. package/dist/template-transforms/vir-css/css-transform.d.ts +4 -0
  126. package/dist/template-transforms/vir-css/css-transform.js +15 -0
  127. package/dist/template-transforms/vir-css/vir-css.d.ts +12 -0
  128. package/dist/template-transforms/vir-css/vir-css.js +21 -0
  129. package/dist/template-transforms/vir-html/html-interpolation.d.ts +42 -0
  130. package/dist/template-transforms/vir-html/html-interpolation.js +1 -0
  131. package/dist/template-transforms/vir-html/html-transform.d.ts +5 -0
  132. package/dist/template-transforms/vir-html/html-transform.js +96 -0
  133. package/dist/template-transforms/vir-html/tag-name-keys.d.ts +7 -0
  134. package/{src/template-transforms/vir-html/tag-name-keys.ts → dist/template-transforms/vir-html/tag-name-keys.js} +1 -1
  135. package/dist/template-transforms/vir-html/vir-html.d.ts +11 -0
  136. package/{src/template-transforms/vir-html/vir-html.ts → dist/template-transforms/vir-html/vir-html.js} +5 -13
  137. package/dist/typed-event/typed-event.d.ts +55 -0
  138. package/dist/typed-event/typed-event.js +50 -0
  139. package/dist/util/array.d.ts +5 -0
  140. package/{src/util/array.ts → dist/util/array.js} +5 -18
  141. package/{src/util/increment.ts → dist/util/increment.d.ts} +5 -24
  142. package/dist/util/increment.js +1 -0
  143. package/dist/util/lit-template.d.ts +9 -0
  144. package/{src/util/lit-template.ts → dist/util/lit-template.js} +10 -30
  145. package/dist/util/map-async-value.d.ts +7 -0
  146. package/{src/util/map-async-value.ts → dist/util/map-async-value.js} +10 -12
  147. package/dist/util/type.js +1 -0
  148. package/package.json +4 -4
  149. package/src/declarative-element/declarative-element-init.ts +0 -115
  150. package/src/declarative-element/declarative-element.ts +0 -372
  151. package/src/declarative-element/define-element.ts +0 -515
  152. package/src/declarative-element/directives/assign.directive.ts +0 -89
  153. package/src/declarative-element/directives/attributes.directive.ts +0 -63
  154. package/src/declarative-element/directives/create-attribute-directive.ts +0 -47
  155. package/src/declarative-element/directives/directive-helpers.ts +0 -67
  156. package/src/declarative-element/directives/listen.directive.ts +0 -206
  157. package/src/declarative-element/directives/mutate.directive.ts +0 -78
  158. package/src/declarative-element/directives/on-dom-created.directive.ts +0 -68
  159. package/src/declarative-element/directives/on-dom-rendered.directive.ts +0 -61
  160. package/src/declarative-element/directives/on-intersect.directive.ts +0 -139
  161. package/src/declarative-element/directives/on-resize.directive.ts +0 -142
  162. package/src/declarative-element/directives/render-async.directive.ts +0 -111
  163. package/src/declarative-element/properties/assign-inputs.ts +0 -30
  164. package/src/declarative-element/properties/css-vars.ts +0 -24
  165. package/src/declarative-element/properties/element-events.ts +0 -161
  166. package/src/declarative-element/properties/host-classes.ts +0 -63
  167. package/src/declarative-element/properties/string-names.ts +0 -83
  168. package/src/declarative-element/properties/styles.ts +0 -112
  169. package/src/declarative-element/render-callback.ts +0 -196
  170. package/src/declarative-element/wrap-define-element.ts +0 -127
  171. package/src/readme-examples/my-custom-action.event.ts +0 -3
  172. package/src/readme-examples/my-with-assignment.element.ts +0 -16
  173. package/src/readme-examples/my-with-custom-events.element.ts +0 -23
  174. package/src/readme-examples/my-with-events.element.ts +0 -23
  175. package/src/readme-examples/my-with-inputs.element.ts +0 -13
  176. package/src/readme-examples/my-with-on-resize.element.ts +0 -19
  177. package/src/readme-examples/my-with-render-if.element.ts +0 -15
  178. package/src/readme-examples/require-declarative-element.ts +0 -3
  179. package/src/template-transforms/nested-mapped-templates.ts +0 -157
  180. package/src/template-transforms/vir-css/css-transform.ts +0 -30
  181. package/src/template-transforms/vir-css/vir-css.ts +0 -30
  182. package/src/template-transforms/vir-html/html-interpolation.ts +0 -103
  183. package/src/template-transforms/vir-html/html-transform.ts +0 -149
  184. package/src/typed-event/typed-event.ts +0 -90
  185. /package/{src/declarative-element/custom-tag-name.ts → dist/declarative-element/custom-tag-name.d.ts} +0 -0
  186. /package/{src/declarative-element/properties/element-properties.ts → dist/declarative-element/properties/element-properties.d.ts} +0 -0
  187. /package/{src/declarative-element/properties/tag-name.ts → dist/declarative-element/properties/tag-name.d.ts} +0 -0
  188. /package/{src/lit-exports/all-lit-exports.ts → dist/lit-exports/all-lit-exports.d.ts} +0 -0
  189. /package/{src/util/type.ts → dist/util/type.d.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ import { type Overwrite } from '@augment-vir/common';
2
+ import { CallbackObservable, type AsyncValue, type CallbackObservableInit } from 'observavir';
3
+ export type { AsyncValue } from 'observavir';
4
+ /**
5
+ * Class for constructing async props. Do not use this directly as its internal types won't be
6
+ * inferred correctly. Instead use {@link asyncProp} an async prop or {@link AsyncProp} for types.
7
+ *
8
+ * @category Internal
9
+ */
10
+ export declare class InternalAsyncPropClass<Value, Params> extends CallbackObservable<Value, Params> {
11
+ /**
12
+ * Checks if the current `.value` has resolved (meaning the Promise has settled and it was not
13
+ * rejected). This type guards the current instance's `.value` property.
14
+ */
15
+ isResolved(): this is Overwrite<this, {
16
+ value: Exclude<AsyncValue<Value>, Promise<any> | Error>;
17
+ }>;
18
+ /**
19
+ * Checks if the current `.value` has settled (meaning it is either a rejection error or a
20
+ * resolved value). This type guards the current instance's `.value` property.
21
+ */
22
+ isSettled(): this is Overwrite<this, {
23
+ value: Exclude<AsyncValue<Value>, Promise<any>>;
24
+ }>;
25
+ /**
26
+ * Checks if the current `.value` has not settled yet settled (meaning it is still an unsettled
27
+ * Promise). This type guards the current instance's `.value` property.
28
+ */
29
+ isWaiting(): this is Overwrite<this, {
30
+ value: Extract<AsyncValue<Value>, Promise<any>>;
31
+ }>;
32
+ /**
33
+ * Checks if the current `.value` is a rejection error. This type guards the current instance's
34
+ * `.value` property.
35
+ */
36
+ isError(): this is Overwrite<this, {
37
+ value: Extract<AsyncValue<Value>, Error>;
38
+ }>;
39
+ /**
40
+ * Checks if the current `.value` is resolved (and not an error) or still waiting. This type
41
+ * guards the current instance's `.value` property.
42
+ */
43
+ isNotError(): this is Overwrite<this, {
44
+ value: Exclude<AsyncValue<Value>, Error>;
45
+ }>;
46
+ }
47
+ /**
48
+ * An async property created by {@link asyncProp} for use within declarative elements. Do not use
49
+ * this directly as its internal types won't be inferred correctly.
50
+ *
51
+ * @category Internal
52
+ */
53
+ export type AsyncProp<Value, Params> = Omit<InternalAsyncPropClass<Value, Params>,
54
+ /** Hide these properties to make the `AsyncProp` interface much simpler. */
55
+ 'dispatch' | 'equalityCheck' | 'getListenerCount' | 'updateCallback' | 'removeListener' | 'removeAllListeners' | 'listenToEvent' | 'listen' | 'resolvedValue'>;
56
+ /**
57
+ * Create an async prop for a declarative element's state.
58
+ *
59
+ * @category Async
60
+ */
61
+ export declare function asyncProp<Value, Params = void>(init?: CallbackObservableInit<Value, Params>): AsyncProp<Value, Params>;
@@ -1,86 +1,52 @@
1
- import {type Overwrite} from '@augment-vir/common';
2
- import {CallbackObservable, type AsyncValue, type CallbackObservableInit} from 'observavir';
3
-
4
- export type {AsyncValue} from 'observavir';
5
-
1
+ import { CallbackObservable } from 'observavir';
6
2
  /**
7
3
  * Class for constructing async props. Do not use this directly as its internal types won't be
8
4
  * inferred correctly. Instead use {@link asyncProp} an async prop or {@link AsyncProp} for types.
9
5
  *
10
6
  * @category Internal
11
7
  */
12
- export class InternalAsyncPropClass<Value, Params> extends CallbackObservable<Value, Params> {
8
+ export class InternalAsyncPropClass extends CallbackObservable {
13
9
  /**
14
10
  * Checks if the current `.value` has resolved (meaning the Promise has settled and it was not
15
11
  * rejected). This type guards the current instance's `.value` property.
16
12
  */
17
- public isResolved(): this is Overwrite<
18
- this,
19
- {value: Exclude<AsyncValue<Value>, Promise<any> | Error>}
20
- > {
13
+ isResolved() {
21
14
  return !(this.value instanceof Promise);
22
15
  }
23
-
24
16
  /**
25
17
  * Checks if the current `.value` has settled (meaning it is either a rejection error or a
26
18
  * resolved value). This type guards the current instance's `.value` property.
27
19
  */
28
- public isSettled(): this is Overwrite<this, {value: Exclude<AsyncValue<Value>, Promise<any>>}> {
20
+ isSettled() {
29
21
  return !(this.value instanceof Promise);
30
22
  }
31
-
32
23
  /**
33
24
  * Checks if the current `.value` has not settled yet settled (meaning it is still an unsettled
34
25
  * Promise). This type guards the current instance's `.value` property.
35
26
  */
36
- public isWaiting(): this is Overwrite<this, {value: Extract<AsyncValue<Value>, Promise<any>>}> {
27
+ isWaiting() {
37
28
  return this.value instanceof Promise;
38
29
  }
39
-
40
30
  /**
41
31
  * Checks if the current `.value` is a rejection error. This type guards the current instance's
42
32
  * `.value` property.
43
33
  */
44
- public isError(): this is Overwrite<this, {value: Extract<AsyncValue<Value>, Error>}> {
34
+ isError() {
45
35
  return this.value instanceof Error;
46
36
  }
47
-
48
37
  /**
49
38
  * Checks if the current `.value` is resolved (and not an error) or still waiting. This type
50
39
  * guards the current instance's `.value` property.
51
40
  */
52
- public isNotError(): this is Overwrite<this, {value: Exclude<AsyncValue<Value>, Error>}> {
41
+ isNotError() {
53
42
  return !(this.value instanceof Error);
54
43
  }
55
44
  }
56
-
57
- /**
58
- * An async property created by {@link asyncProp} for use within declarative elements. Do not use
59
- * this directly as its internal types won't be inferred correctly.
60
- *
61
- * @category Internal
62
- */
63
- export type AsyncProp<Value, Params> = Omit<
64
- InternalAsyncPropClass<Value, Params>,
65
- /** Hide these properties to make the `AsyncProp` interface much simpler. */
66
- | 'dispatch'
67
- | 'equalityCheck'
68
- | 'getListenerCount'
69
- | 'updateCallback'
70
- | 'removeListener'
71
- | 'removeAllListeners'
72
- | 'listenToEvent'
73
- | 'listen'
74
- | 'resolvedValue'
75
- >;
76
-
77
45
  /**
78
46
  * Create an async prop for a declarative element's state.
79
47
  *
80
48
  * @category Async
81
49
  */
82
- export function asyncProp<Value, Params = void>(
83
- init?: CallbackObservableInit<Value, Params>,
84
- ): AsyncProp<Value, Params> {
50
+ export function asyncProp(init) {
85
51
  return new InternalAsyncPropClass(init);
86
52
  }
@@ -0,0 +1,30 @@
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
+ }>;
@@ -0,0 +1,35 @@
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
+ });
@@ -0,0 +1,28 @@
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
+ };
@@ -0,0 +1,41 @@
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
+ }
@@ -0,0 +1,27 @@
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;
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,15 @@
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,16 +1,13 @@
1
- import {type MaybePromise} from '@augment-vir/common';
2
- import {listen} from './listen.directive.js';
3
-
1
+ import { listen } from './listen.directive.js';
4
2
  /**
5
3
  * Listens to enter, return, and space key hits on an element. Similar to {@link listenToEnter} but
6
4
  * includes space.
7
5
  *
8
6
  * @category Directives
9
7
  */
10
- export function listenToActivate(callback: () => MaybePromise<void>) {
8
+ export function listenToActivate(callback) {
11
9
  return listen('keydown', async (event) => {
12
10
  const key = event.code.toLowerCase();
13
-
14
11
  if (key.includes('enter') || key.includes('return') || key === 'space') {
15
12
  event.stopImmediatePropagation();
16
13
  event.preventDefault();
@@ -18,17 +15,15 @@ export function listenToActivate(callback: () => MaybePromise<void>) {
18
15
  }
19
16
  });
20
17
  }
21
-
22
18
  /**
23
19
  * Listens to enter and return key hits on an element. Similar to {@link listenToActivate} but
24
20
  * doesn't include space.
25
21
  *
26
22
  * @category Directives
27
23
  */
28
- export function listenToEnter(callback: () => MaybePromise<void>) {
24
+ export function listenToEnter(callback) {
29
25
  return listen('keydown', async (event) => {
30
26
  const key = event.code.toLowerCase();
31
-
32
27
  if (key.includes('enter') || key.includes('return')) {
33
28
  event.stopImmediatePropagation();
34
29
  event.preventDefault();
@@ -0,0 +1,92 @@
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 {};
@@ -0,0 +1,48 @@
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
+ });
@@ -0,0 +1,38 @@
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
+ }>;
@@ -0,0 +1,45 @@
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
+ }