ng-primitives 0.0.7 → 0.2.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 (211) hide show
  1. package/README.md +14 -4
  2. package/accordion/accordion-trigger/accordion-trigger.directive.d.ts +2 -1
  3. package/autofill/README.md +3 -0
  4. package/autofill/autofill/autofill.directive.d.ts +19 -0
  5. package/{select/select-button/select-button.token.d.ts → autofill/autofill/autofill.token.d.ts} +4 -4
  6. package/autofill/index.d.ts +9 -0
  7. package/avatar/avatar/avatar.directive.d.ts +2 -1
  8. package/button/README.md +3 -0
  9. package/button/button/button.directive.d.ts +27 -0
  10. package/{select/select-option/select-option.token.d.ts → button/button/button.token.d.ts} +4 -4
  11. package/button/index.d.ts +9 -0
  12. package/checkbox/checkbox/checkbox.directive.d.ts +11 -61
  13. package/checkbox/index.d.ts +0 -4
  14. package/esm2022/a11y/visually-hidden/visually-hidden.directive.mjs +3 -3
  15. package/esm2022/accordion/accordion/accordion.directive.mjs +5 -4
  16. package/esm2022/accordion/accordion-content/accordion-content.directive.mjs +5 -6
  17. package/esm2022/accordion/accordion-item/accordion-item.directive.mjs +5 -5
  18. package/esm2022/accordion/accordion-trigger/accordion-trigger.directive.mjs +8 -5
  19. package/esm2022/autofill/autofill/autofill.directive.mjs +71 -0
  20. package/esm2022/autofill/autofill/autofill.token.mjs +16 -0
  21. package/esm2022/autofill/index.mjs +10 -0
  22. package/esm2022/autofill/ng-primitives-autofill.mjs +5 -0
  23. package/esm2022/avatar/avatar/avatar.directive.mjs +7 -4
  24. package/esm2022/avatar/avatar-fallback/avatar-fallback.directive.mjs +3 -3
  25. package/esm2022/avatar/avatar-image/avatar-image.directive.mjs +3 -3
  26. package/esm2022/button/button/button.directive.mjs +47 -0
  27. package/esm2022/button/button/button.token.mjs +16 -0
  28. package/esm2022/button/index.mjs +10 -0
  29. package/esm2022/button/ng-primitives-button.mjs +5 -0
  30. package/esm2022/checkbox/checkbox/checkbox.directive.mjs +29 -79
  31. package/esm2022/checkbox/index.mjs +1 -5
  32. package/esm2022/file-upload/file-upload/file-upload.directive.mjs +7 -4
  33. package/esm2022/focus-trap/focus-trap/focus-trap.directive.mjs +262 -0
  34. package/esm2022/focus-trap/focus-trap/focus-trap.token.mjs +16 -0
  35. package/esm2022/focus-trap/index.mjs +10 -0
  36. package/esm2022/focus-trap/ng-primitives-focus-trap.mjs +5 -0
  37. package/esm2022/form-field/description/description.directive.mjs +14 -14
  38. package/esm2022/form-field/error/error.directive.mjs +27 -29
  39. package/esm2022/form-field/form-control/form-control.directive.mjs +22 -16
  40. package/esm2022/form-field/form-field/form-field.directive.mjs +3 -3
  41. package/esm2022/form-field/form-field/form-field.token.mjs +3 -7
  42. package/esm2022/form-field/label/label.directive.mjs +56 -17
  43. package/esm2022/input/index.mjs +10 -0
  44. package/esm2022/input/input/input.directive.mjs +55 -0
  45. package/esm2022/input/input/input.token.mjs +16 -0
  46. package/esm2022/input/ng-primitives-input.mjs +5 -0
  47. package/esm2022/interactions/focus/focus.directive.mjs +15 -10
  48. package/esm2022/interactions/focus-visible/focus-visible.directive.mjs +12 -7
  49. package/esm2022/interactions/hover/hover.directive.mjs +16 -11
  50. package/esm2022/interactions/index.mjs +5 -1
  51. package/esm2022/interactions/move/move.directive.mjs +216 -0
  52. package/esm2022/interactions/move/move.token.mjs +16 -0
  53. package/esm2022/interactions/press/press.directive.mjs +118 -0
  54. package/esm2022/interactions/press/press.token.mjs +16 -0
  55. package/esm2022/internal/disabled/disabled.mjs +19 -0
  56. package/esm2022/internal/index.mjs +11 -0
  57. package/esm2022/internal/ng-primitives-internal.mjs +5 -0
  58. package/esm2022/internal/orientation/orientation.mjs +19 -0
  59. package/esm2022/internal/style-injector/style-injector.mjs +81 -0
  60. package/esm2022/progress/progress/progress.directive.mjs +3 -3
  61. package/esm2022/progress/progress-indicator/progress-indicator.directive.mjs +3 -3
  62. package/esm2022/radio/radio-group/radio-group.directive.mjs +14 -54
  63. package/esm2022/radio/radio-indicator/radio-indicator.directive.mjs +8 -5
  64. package/esm2022/radio/radio-item/radio-item.directive.mjs +8 -6
  65. package/esm2022/resize/resize/resize.directive.mjs +3 -3
  66. package/esm2022/roving-focus/roving-focus-group/roving-focus-group.directive.mjs +14 -9
  67. package/esm2022/roving-focus/roving-focus-item/roving-focus-item.directive.mjs +3 -3
  68. package/esm2022/search/index.mjs +10 -0
  69. package/esm2022/search/ng-primitives-search.mjs +5 -0
  70. package/esm2022/search/search-field/search-field.directive.mjs +47 -0
  71. package/esm2022/search/search-field/search-field.token.mjs +16 -0
  72. package/esm2022/select/index.mjs +1 -7
  73. package/esm2022/select/select/select.directive.mjs +23 -36
  74. package/esm2022/select/select/select.token.mjs +1 -1
  75. package/esm2022/slider/slider/slider.directive.mjs +18 -5
  76. package/esm2022/slider/slider-range/slider-range.directive.mjs +6 -5
  77. package/esm2022/slider/slider-thumb/slider-thumb.directive.mjs +7 -4
  78. package/esm2022/slider/slider-track/slider-track.directive.mjs +8 -4
  79. package/esm2022/switch/switch/switch.directive.mjs +18 -58
  80. package/esm2022/switch/switch-thumb/switch-thumb.directive.mjs +9 -6
  81. package/esm2022/tabs/tab-button/tab-button.directive.mjs +8 -6
  82. package/esm2022/tabs/tab-list/tab-list.directive.mjs +3 -3
  83. package/esm2022/tabs/tab-panel/tab-panel.directive.mjs +5 -6
  84. package/esm2022/tabs/tabset/tabset.directive.mjs +14 -18
  85. package/esm2022/textarea/index.mjs +10 -0
  86. package/esm2022/textarea/ng-primitives-textarea.mjs +5 -0
  87. package/esm2022/textarea/textarea/textarea.directive.mjs +37 -0
  88. package/esm2022/textarea/textarea/textarea.token.mjs +16 -0
  89. package/esm2022/toggle/toggle/toggle.directive.mjs +33 -13
  90. package/esm2022/tooltip/tooltip/tooltip.directive.mjs +3 -3
  91. package/esm2022/tooltip/tooltip-trigger/tooltip-trigger.directive.mjs +7 -7
  92. package/esm2022/utils/helpers/focus-manager.mjs +3 -3
  93. package/esm2022/utils/index.mjs +2 -2
  94. package/esm2022/utils/signals/async.mjs +11 -17
  95. package/fesm2022/ng-primitives-a11y.mjs +3 -3
  96. package/fesm2022/ng-primitives-accordion.mjs +19 -16
  97. package/fesm2022/ng-primitives-accordion.mjs.map +1 -1
  98. package/fesm2022/ng-primitives-autofill.mjs +100 -0
  99. package/fesm2022/ng-primitives-autofill.mjs.map +1 -0
  100. package/fesm2022/ng-primitives-avatar.mjs +13 -10
  101. package/fesm2022/ng-primitives-avatar.mjs.map +1 -1
  102. package/fesm2022/ng-primitives-button.mjs +76 -0
  103. package/fesm2022/ng-primitives-button.mjs.map +1 -0
  104. package/fesm2022/ng-primitives-checkbox.mjs +25 -203
  105. package/fesm2022/ng-primitives-checkbox.mjs.map +1 -1
  106. package/fesm2022/ng-primitives-file-upload.mjs +6 -3
  107. package/fesm2022/ng-primitives-file-upload.mjs.map +1 -1
  108. package/fesm2022/ng-primitives-focus-trap.mjs +291 -0
  109. package/fesm2022/ng-primitives-focus-trap.mjs.map +1 -0
  110. package/fesm2022/ng-primitives-form-field.mjs +119 -80
  111. package/fesm2022/ng-primitives-form-field.mjs.map +1 -1
  112. package/fesm2022/ng-primitives-input.mjs +84 -0
  113. package/fesm2022/ng-primitives-input.mjs.map +1 -0
  114. package/fesm2022/ng-primitives-interactions.mjs +394 -26
  115. package/fesm2022/ng-primitives-interactions.mjs.map +1 -1
  116. package/fesm2022/ng-primitives-internal.mjs +132 -0
  117. package/fesm2022/ng-primitives-internal.mjs.map +1 -0
  118. package/fesm2022/ng-primitives-progress.mjs +6 -6
  119. package/fesm2022/ng-primitives-radio.mjs +25 -62
  120. package/fesm2022/ng-primitives-radio.mjs.map +1 -1
  121. package/fesm2022/ng-primitives-resize.mjs +3 -3
  122. package/fesm2022/ng-primitives-roving-focus.mjs +15 -10
  123. package/fesm2022/ng-primitives-roving-focus.mjs.map +1 -1
  124. package/fesm2022/ng-primitives-search.mjs +76 -0
  125. package/fesm2022/ng-primitives-search.mjs.map +1 -0
  126. package/fesm2022/ng-primitives-select.mjs +23 -395
  127. package/fesm2022/ng-primitives-select.mjs.map +1 -1
  128. package/fesm2022/ng-primitives-slider.mjs +35 -14
  129. package/fesm2022/ng-primitives-slider.mjs.map +1 -1
  130. package/fesm2022/ng-primitives-switch.mjs +23 -62
  131. package/fesm2022/ng-primitives-switch.mjs.map +1 -1
  132. package/fesm2022/ng-primitives-tabs.mjs +27 -30
  133. package/fesm2022/ng-primitives-tabs.mjs.map +1 -1
  134. package/fesm2022/ng-primitives-textarea.mjs +66 -0
  135. package/fesm2022/ng-primitives-textarea.mjs.map +1 -0
  136. package/fesm2022/ng-primitives-toggle.mjs +32 -12
  137. package/fesm2022/ng-primitives-toggle.mjs.map +1 -1
  138. package/fesm2022/ng-primitives-tooltip.mjs +9 -9
  139. package/fesm2022/ng-primitives-tooltip.mjs.map +1 -1
  140. package/fesm2022/ng-primitives-utils.mjs +14 -20
  141. package/fesm2022/ng-primitives-utils.mjs.map +1 -1
  142. package/file-upload/file-upload/file-upload.directive.d.ts +2 -1
  143. package/focus-trap/README.md +3 -0
  144. package/focus-trap/focus-trap/focus-trap.directive.d.ts +64 -0
  145. package/{select/select-options/select-options.token.d.ts → focus-trap/focus-trap/focus-trap.token.d.ts} +4 -4
  146. package/focus-trap/index.d.ts +9 -0
  147. package/form-field/description/description.directive.d.ts +1 -1
  148. package/form-field/error/error.directive.d.ts +9 -5
  149. package/form-field/form-control/form-control.directive.d.ts +7 -3
  150. package/form-field/form-field/form-field.token.d.ts +1 -1
  151. package/form-field/label/label.directive.d.ts +3 -2
  152. package/input/README.md +3 -0
  153. package/input/index.d.ts +9 -0
  154. package/input/input/input.directive.d.ts +33 -0
  155. package/input/input/input.token.d.ts +14 -0
  156. package/interactions/focus/focus.directive.d.ts +6 -2
  157. package/interactions/focus-visible/focus-visible.directive.d.ts +5 -1
  158. package/interactions/hover/hover.directive.d.ts +5 -1
  159. package/interactions/index.d.ts +4 -0
  160. package/interactions/move/move.directive.d.ts +126 -0
  161. package/interactions/move/move.token.d.ts +14 -0
  162. package/interactions/press/press.directive.d.ts +59 -0
  163. package/interactions/press/press.token.d.ts +14 -0
  164. package/internal/README.md +3 -0
  165. package/internal/disabled/disabled.d.ts +21 -0
  166. package/internal/index.d.ts +10 -0
  167. package/internal/orientation/orientation.d.ts +22 -0
  168. package/internal/style-injector/style-injector.d.ts +36 -0
  169. package/package.json +49 -7
  170. package/radio/radio-group/radio-group.directive.d.ts +4 -41
  171. package/radio/radio-indicator/radio-indicator.directive.d.ts +2 -1
  172. package/radio/radio-item/radio-item.directive.d.ts +2 -1
  173. package/roving-focus/roving-focus-group/roving-focus-group.directive.d.ts +7 -2
  174. package/search/README.md +3 -0
  175. package/search/index.d.ts +9 -0
  176. package/search/search-field/search-field.directive.d.ts +15 -0
  177. package/search/search-field/search-field.token.d.ts +14 -0
  178. package/select/index.d.ts +0 -6
  179. package/select/select/select.directive.d.ts +7 -22
  180. package/select/select/select.token.d.ts +2 -2
  181. package/slider/slider/slider.directive.d.ts +4 -2
  182. package/slider/slider-thumb/slider-thumb.directive.d.ts +2 -1
  183. package/slider/slider-track/slider-track.directive.d.ts +1 -1
  184. package/switch/switch/switch.directive.d.ts +5 -45
  185. package/switch/switch-thumb/switch-thumb.directive.d.ts +2 -1
  186. package/tabs/tab-button/tab-button.directive.d.ts +2 -1
  187. package/tabs/tabset/tabset.directive.d.ts +3 -9
  188. package/textarea/README.md +3 -0
  189. package/textarea/index.d.ts +9 -0
  190. package/textarea/textarea/textarea.directive.d.ts +20 -0
  191. package/textarea/textarea/textarea.token.d.ts +14 -0
  192. package/toggle/toggle/toggle.directive.d.ts +16 -4
  193. package/utils/index.d.ts +1 -1
  194. package/utils/signals/async.d.ts +10 -12
  195. package/checkbox/checkbox-indicator/checkbox-indicator.directive.d.ts +0 -19
  196. package/checkbox/checkbox-indicator/checkbox-indicator.token.d.ts +0 -15
  197. package/checkbox/checkbox-input/checkbox-input.directive.d.ts +0 -10
  198. package/checkbox/checkbox-label/checkbox-label.directive.d.ts +0 -9
  199. package/esm2022/checkbox/checkbox-indicator/checkbox-indicator.directive.mjs +0 -51
  200. package/esm2022/checkbox/checkbox-indicator/checkbox-indicator.token.mjs +0 -17
  201. package/esm2022/checkbox/checkbox-input/checkbox-input.directive.mjs +0 -40
  202. package/esm2022/checkbox/checkbox-label/checkbox-label.directive.mjs +0 -32
  203. package/esm2022/select/select-button/select-button.directive.mjs +0 -84
  204. package/esm2022/select/select-button/select-button.token.mjs +0 -16
  205. package/esm2022/select/select-option/select-option.directive.mjs +0 -90
  206. package/esm2022/select/select-option/select-option.token.mjs +0 -16
  207. package/esm2022/select/select-options/select-options.directive.mjs +0 -157
  208. package/esm2022/select/select-options/select-options.token.mjs +0 -16
  209. package/select/select-button/select-button.directive.d.ts +0 -51
  210. package/select/select-option/select-option.directive.d.ts +0 -57
  211. package/select/select-options/select-options.directive.d.ts +0 -65
@@ -1,8 +1,10 @@
1
1
  import { DOCUMENT, isPlatformBrowser } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
3
  import { InjectionToken, inject, PLATFORM_ID, Injectable, input, booleanAttribute, signal, output, Directive, HostListener, ElementRef } from '@angular/core';
4
+ import { injectDisabled } from 'ng-primitives/internal';
4
5
  import { FocusMonitor } from '@angular/cdk/a11y';
5
6
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
+ import { injectDisposables } from 'ng-primitives/utils';
6
8
 
7
9
  /**
8
10
  * Copyright © 2024 Angular Primitives.
@@ -60,10 +62,10 @@ class GlobalPointerEvents {
60
62
  this.setGlobalIgnoreEmulatedMouseEvents();
61
63
  }
62
64
  }
63
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: GlobalPointerEvents, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
64
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: GlobalPointerEvents, providedIn: 'root' }); }
65
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: GlobalPointerEvents, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
66
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: GlobalPointerEvents, providedIn: 'root' }); }
65
67
  }
66
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: GlobalPointerEvents, decorators: [{
68
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: GlobalPointerEvents, decorators: [{
67
69
  type: Injectable,
68
70
  args: [{
69
71
  providedIn: 'root',
@@ -88,6 +90,10 @@ class NgpHover {
88
90
  alias: 'ngpHoverDisabled',
89
91
  transform: booleanAttribute,
90
92
  });
93
+ /**
94
+ * Access the disabled state from any parent.
95
+ */
96
+ this.isDisabled = injectDisabled(this.disabled);
91
97
  /**
92
98
  * Store the current hover state.
93
99
  */
@@ -107,7 +113,7 @@ class NgpHover {
107
113
  /**
108
114
  * Emit an event when the hover state changes.
109
115
  */
110
- this.hoverChange = output({ alias: 'ngpHoverChange' });
116
+ this.hoverChange = output({ alias: 'ngpHover' });
111
117
  }
112
118
  ngOnChanges(changes) {
113
119
  if ('disabled' in changes) {
@@ -124,7 +130,7 @@ class NgpHover {
124
130
  * @param pointerType
125
131
  */
126
132
  onHoverStart(event, pointerType) {
127
- if (this.disabled() ||
133
+ if (this.isDisabled() ||
128
134
  pointerType === 'touch' ||
129
135
  this.hovered() ||
130
136
  !event.currentTarget?.contains(event.target)) {
@@ -153,7 +159,7 @@ class NgpHover {
153
159
  this.onHoverStart(event, event.pointerType);
154
160
  }
155
161
  onPointerLeave(event) {
156
- if (!this.disabled() && event.currentTarget?.contains(event.target)) {
162
+ if (!this.isDisabled() && event.currentTarget?.contains(event.target)) {
157
163
  this.onHoverEnd(event.pointerType);
158
164
  }
159
165
  }
@@ -167,14 +173,14 @@ class NgpHover {
167
173
  this.ignoreEmulatedMouseEvents = false;
168
174
  }
169
175
  onMouseLeave(event) {
170
- if (!this.disabled() && event.currentTarget?.contains(event.target)) {
176
+ if (!this.isDisabled() && event.currentTarget?.contains(event.target)) {
171
177
  this.onHoverEnd('mouse');
172
178
  }
173
179
  }
174
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpHover, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
175
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.0.2", type: NgpHover, isStandalone: true, selector: "[ngpHover]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpHoverDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hoverStart: "ngpHoverStart", hoverEnd: "ngpHoverEnd", hoverChange: "ngpHoverChange" }, host: { listeners: { "pointerenter": "onPointerEnter($event)", "pointerleave": "onPointerLeave($event)", "touchstart": "onTouchStart()", "mouseenter": "onMouseEnter($event)", "mouseleave": "onMouseLeave($event)" }, properties: { "attr.data-hover": "hovered()" } }, providers: [{ provide: NgpHoverToken, useExisting: NgpHover }], exportAs: ["ngpHover"], usesOnChanges: true, ngImport: i0 }); }
180
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpHover, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
181
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.1.1", type: NgpHover, isStandalone: true, selector: "[ngpHover]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpHoverDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { hoverStart: "ngpHoverStart", hoverEnd: "ngpHoverEnd", hoverChange: "ngpHover" }, host: { listeners: { "pointerenter": "onPointerEnter($event)", "pointerleave": "onPointerLeave($event)", "touchstart": "onTouchStart()", "mouseenter": "onMouseEnter($event)", "mouseleave": "onMouseLeave($event)" }, properties: { "attr.data-hover": "hovered()" } }, providers: [{ provide: NgpHoverToken, useExisting: NgpHover }], exportAs: ["ngpHover"], usesOnChanges: true, ngImport: i0 }); }
176
182
  }
177
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpHover, decorators: [{
183
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpHover, decorators: [{
178
184
  type: Directive,
179
185
  args: [{
180
186
  standalone: true,
@@ -234,23 +240,27 @@ class NgpFocus {
234
240
  alias: 'ngpFocusDisabled',
235
241
  transform: booleanAttribute,
236
242
  });
243
+ /**
244
+ * Access the disabled state from any parent.
245
+ */
246
+ this.isDisabled = injectDisabled(this.disabled);
237
247
  /**
238
248
  * Emit when the focus state changes.
239
249
  */
240
- this.stateChange = output({ alias: 'ngpFocusChange' });
250
+ this.focus = output({ alias: 'ngpFocus' });
241
251
  }
242
252
  /**
243
253
  * Listen for focus events.
244
254
  * @param event
245
255
  */
246
256
  onFocus(event) {
247
- if (this.disabled()) {
257
+ if (this.isDisabled()) {
248
258
  return;
249
259
  }
250
260
  const ownerDocument = event.target?.ownerDocument ?? document;
251
261
  // ensure this element is still focused
252
262
  if (ownerDocument.activeElement === event.target && event.currentTarget === event.target) {
253
- this.stateChange.emit(true);
263
+ this.focus.emit(true);
254
264
  this.isFocused.set(true);
255
265
  }
256
266
  }
@@ -259,18 +269,18 @@ class NgpFocus {
259
269
  * @param event
260
270
  */
261
271
  onBlur(event) {
262
- if (this.disabled()) {
272
+ if (this.isDisabled()) {
263
273
  return;
264
274
  }
265
275
  if (event.currentTarget === event.target) {
266
- this.stateChange.emit(false);
276
+ this.focus.emit(false);
267
277
  this.isFocused.set(false);
268
278
  }
269
279
  }
270
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpFocus, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
271
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.0.2", type: NgpFocus, isStandalone: true, selector: "[ngpFocus]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpFocusDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { stateChange: "ngpFocusChange" }, host: { listeners: { "focus": "onFocus($event)", "blur": "onBlur($event)" }, properties: { "attr.data-focused": "isFocused()" } }, providers: [{ provide: NgpFocusToken, useExisting: NgpFocus }], exportAs: ["ngpFocus"], ngImport: i0 }); }
280
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpFocus, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
281
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.1.1", type: NgpFocus, isStandalone: true, selector: "[ngpFocus]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpFocusDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { focus: "ngpFocus" }, host: { listeners: { "focus": "onFocus($event)", "blur": "onBlur($event)" }, properties: { "attr.data-focus": "isFocused()" } }, providers: [{ provide: NgpFocusToken, useExisting: NgpFocus }], exportAs: ["ngpFocus"], ngImport: i0 }); }
272
282
  }
273
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpFocus, decorators: [{
283
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpFocus, decorators: [{
274
284
  type: Directive,
275
285
  args: [{
276
286
  standalone: true,
@@ -278,7 +288,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImpor
278
288
  exportAs: 'ngpFocus',
279
289
  providers: [{ provide: NgpFocusToken, useExisting: NgpFocus }],
280
290
  host: {
281
- '[attr.data-focused]': 'isFocused()',
291
+ '[attr.data-focus]': 'isFocused()',
282
292
  },
283
293
  }]
284
294
  }], propDecorators: { onFocus: [{
@@ -328,11 +338,15 @@ class NgpFocusVisible {
328
338
  alias: 'ngpFocusVisibleDisabled',
329
339
  transform: booleanAttribute,
330
340
  });
341
+ /**
342
+ * Access the disabled state from any parent.
343
+ */
344
+ this.isDisabled = injectDisabled(this.disabled);
331
345
  /**
332
346
  * Emit when the element is visually focused.
333
347
  */
334
348
  this.focusChange = output({
335
- alias: 'ngpFocusVisibleChange',
349
+ alias: 'ngpFocusVisible',
336
350
  });
337
351
  /**
338
352
  * Whether the element is currently focused.
@@ -344,7 +358,7 @@ class NgpFocusVisible {
344
358
  .subscribe(origin => this.onFocus(origin));
345
359
  }
346
360
  onFocus(origin) {
347
- if (this.disabled() || this.isFocused()) {
361
+ if (this.isDisabled() || this.isFocused()) {
348
362
  return;
349
363
  }
350
364
  // for some elements the focus visible state should always appear on focus
@@ -364,7 +378,7 @@ class NgpFocusVisible {
364
378
  * Listen for blur events.
365
379
  */
366
380
  onBlur() {
367
- if (this.disabled() || !this.isFocused()) {
381
+ if (this.isDisabled() || !this.isFocused()) {
368
382
  return;
369
383
  }
370
384
  this.isFocused.set(false);
@@ -398,10 +412,10 @@ class NgpFocusVisible {
398
412
  }
399
413
  return false;
400
414
  }
401
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpFocusVisible, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
402
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.0.2", type: NgpFocusVisible, isStandalone: true, selector: "[ngpFocusVisible]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpFocusVisibleDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { focusChange: "ngpFocusVisibleChange" }, host: { listeners: { "blur": "onBlur()" }, properties: { "attr.data-focus-visible": "isFocused()" } }, providers: [{ provide: NgpFocusVisibleToken, useExisting: NgpFocusVisible }], exportAs: ["ngpFocusVisible"], ngImport: i0 }); }
415
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpFocusVisible, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
416
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.1.1", type: NgpFocusVisible, isStandalone: true, selector: "[ngpFocusVisible]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpFocusVisibleDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { focusChange: "ngpFocusVisible" }, host: { listeners: { "blur": "onBlur()" }, properties: { "attr.data-focus-visible": "isFocused()" } }, providers: [{ provide: NgpFocusVisibleToken, useExisting: NgpFocusVisible }], exportAs: ["ngpFocusVisible"], ngImport: i0 }); }
403
417
  }
404
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImport: i0, type: NgpFocusVisible, decorators: [{
418
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpFocusVisible, decorators: [{
405
419
  type: Directive,
406
420
  args: [{
407
421
  standalone: true,
@@ -417,6 +431,360 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImpor
417
431
  args: ['blur']
418
432
  }] } });
419
433
 
434
+ /**
435
+ * Copyright © 2024 Angular Primitives.
436
+ * https://github.com/ng-primitives/ng-primitives
437
+ *
438
+ * This source code is licensed under the CC BY-ND 4.0 license found in the
439
+ * LICENSE file in the root directory of this source tree.
440
+ */
441
+ const NgpPressToken = new InjectionToken('NgpPressToken');
442
+ /**
443
+ * Inject the Press directive instance
444
+ */
445
+ function injectPress() {
446
+ return inject(NgpPressToken);
447
+ }
448
+
449
+ /**
450
+ * This was inpsired by Headless UI's active-press hook:
451
+ * https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/hooks/use-active-press.tsx
452
+ */
453
+ class NgpPress {
454
+ constructor() {
455
+ /**
456
+ * Access the HTML Element.
457
+ */
458
+ this.element = inject(ElementRef);
459
+ /**
460
+ * Access the disposables.
461
+ */
462
+ this.disposables = injectDisposables();
463
+ /**
464
+ * Whether listening for press events is disabled.
465
+ */
466
+ this.disabled = input(false, {
467
+ alias: 'ngpPressDisabled',
468
+ transform: booleanAttribute,
469
+ });
470
+ /**
471
+ * Access the disabled state from any parent.
472
+ */
473
+ this.isDisabled = injectDisabled(this.disabled);
474
+ /**
475
+ * Emit when the press begins.
476
+ */
477
+ this.pressStart = output({
478
+ alias: 'ngpPressStart',
479
+ });
480
+ /**
481
+ * Emit when the press ends.
482
+ */
483
+ this.pressEnd = output({
484
+ alias: 'ngpPressEnd',
485
+ });
486
+ /**
487
+ * Emit when the press changes.
488
+ */
489
+ this.pressChange = output({
490
+ alias: 'ngpPress',
491
+ });
492
+ /**
493
+ * The press state.
494
+ */
495
+ this.pressed = signal(false);
496
+ /**
497
+ * Store the list of disposables.
498
+ */
499
+ this.disposableListeners = [];
500
+ }
501
+ /**
502
+ * Reset the press state.
503
+ */
504
+ reset() {
505
+ // if we are not pressing, then do nothing
506
+ if (!this.pressed()) {
507
+ return;
508
+ }
509
+ // clear any existing disposables
510
+ this.disposableListeners.forEach(dispose => dispose());
511
+ this.pressed.set(false);
512
+ this.pressEnd.emit();
513
+ this.pressChange.emit(false);
514
+ }
515
+ onPointerDown() {
516
+ if (this.isDisabled()) {
517
+ return;
518
+ }
519
+ // clear any existing disposables
520
+ this.disposableListeners.forEach(dispose => dispose());
521
+ // update the press state
522
+ this.pressed.set(true);
523
+ this.pressStart.emit();
524
+ this.pressChange.emit(true);
525
+ // setup global event listeners to catch events on elements outside the directive
526
+ const ownerDocument = this.element.nativeElement.ownerDocument ?? document;
527
+ // if the pointer up event happens on any elements, then we are no longer pressing on this element
528
+ const pointerUp = this.disposables.addEventListener(ownerDocument, 'pointerup', this.reset.bind(this), false);
529
+ // Instead of relying on the `pointerleave` event, which is not consistently called on iOS Safari,
530
+ // we use the `pointermove` event to determine if we are still "pressing".
531
+ // By checking if the target is still within the element, we can determine if the press is ongoing.
532
+ const pointerMove = this.disposables.addEventListener(ownerDocument, 'pointermove', this.onPointerMove.bind(this), false);
533
+ // if the pointer is cancelled, then we are no longer pressing on this element
534
+ const pointerCancel = this.disposables.addEventListener(ownerDocument, 'pointercancel', this.reset.bind(this), false);
535
+ this.disposableListeners = [pointerUp, pointerMove, pointerCancel];
536
+ }
537
+ onPointerMove(event) {
538
+ if (this.element.nativeElement !== event.target &&
539
+ !this.element.nativeElement.contains(event.target)) {
540
+ this.reset();
541
+ }
542
+ }
543
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpPress, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
544
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.1.1", type: NgpPress, isStandalone: true, selector: "[ngpPress]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpPressDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { pressStart: "ngpPressStart", pressEnd: "ngpPressEnd", pressChange: "ngpPress" }, host: { listeners: { "pointerdown": "onPointerDown()" }, properties: { "attr.data-press": "pressed()" } }, providers: [{ provide: NgpPressToken, useExisting: NgpPress }], exportAs: ["ngpPress"], ngImport: i0 }); }
545
+ }
546
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpPress, decorators: [{
547
+ type: Directive,
548
+ args: [{
549
+ standalone: true,
550
+ selector: '[ngpPress]',
551
+ exportAs: 'ngpPress',
552
+ providers: [{ provide: NgpPressToken, useExisting: NgpPress }],
553
+ host: {
554
+ '[attr.data-press]': 'pressed()',
555
+ },
556
+ }]
557
+ }], propDecorators: { onPointerDown: [{
558
+ type: HostListener,
559
+ args: ['pointerdown']
560
+ }] } });
561
+
562
+ /**
563
+ * Copyright © 2024 Angular Primitives.
564
+ * https://github.com/ng-primitives/ng-primitives
565
+ *
566
+ * This source code is licensed under the CC BY-ND 4.0 license found in the
567
+ * LICENSE file in the root directory of this source tree.
568
+ */
569
+ const NgpMoveToken = new InjectionToken('NgpMoveToken');
570
+ /**
571
+ * Inject the Move directive instance
572
+ */
573
+ function injectMove() {
574
+ return inject(NgpMoveToken);
575
+ }
576
+
577
+ /**
578
+ * Inspired by react-aria useMove hook:
579
+ * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/useMove.ts
580
+ */
581
+ class NgpMove {
582
+ constructor() {
583
+ /**
584
+ * Access the disposable helper.
585
+ */
586
+ this.disposables = injectDisposables();
587
+ /**
588
+ * Whether movement is disabled.
589
+ */
590
+ this.disabled = input(false, {
591
+ alias: 'ngpMoveDisabled',
592
+ transform: booleanAttribute,
593
+ });
594
+ /**
595
+ * Access the disabled state from any parent.
596
+ */
597
+ this.isDisabled = injectDisabled(this.disabled);
598
+ /**
599
+ * Emit when the move event begins.
600
+ */
601
+ this.start = output({
602
+ alias: 'ngpMoveStart',
603
+ });
604
+ /**
605
+ * Emit when the element is moved.
606
+ */
607
+ this.move = output({
608
+ alias: 'ngpMove',
609
+ });
610
+ /**
611
+ * Emit when the move event ends.
612
+ */
613
+ this.end = output({
614
+ alias: 'ngpMoveEnd',
615
+ });
616
+ /**
617
+ * Whether the element is currently being moved.
618
+ */
619
+ this.isMoving = signal(false);
620
+ /**
621
+ * Store the last x position of the element.
622
+ */
623
+ this.x = null;
624
+ /**
625
+ * Store the last y position of the element.
626
+ */
627
+ this.y = null;
628
+ /**
629
+ * Store the id of the last pointer.
630
+ */
631
+ this.pointerId = null;
632
+ /**
633
+ * Store the disposable event listeners.
634
+ */
635
+ this.disposableListeners = [];
636
+ }
637
+ /**
638
+ * Handle a move start.
639
+ */
640
+ onMoveStart(event, pointerType) {
641
+ this.start.emit({
642
+ pointerType,
643
+ shiftKey: event.shiftKey,
644
+ ctrlKey: event.ctrlKey,
645
+ metaKey: event.metaKey,
646
+ altKey: event.altKey,
647
+ });
648
+ this.isMoving.set(true);
649
+ }
650
+ /**
651
+ * Handle a move event.
652
+ */
653
+ onMove(event, pointerType, deltaX, deltaY) {
654
+ if (deltaX === 0 && deltaY === 0) {
655
+ return;
656
+ }
657
+ this.move.emit({
658
+ deltaX,
659
+ deltaY,
660
+ pointerType,
661
+ shiftKey: event.shiftKey,
662
+ ctrlKey: event.ctrlKey,
663
+ metaKey: event.metaKey,
664
+ altKey: event.altKey,
665
+ });
666
+ }
667
+ /**
668
+ * Handle a move end.
669
+ */
670
+ onMoveEnd(event, pointerType) {
671
+ this.end.emit({
672
+ pointerType,
673
+ shiftKey: event.shiftKey,
674
+ ctrlKey: event.ctrlKey,
675
+ metaKey: event.metaKey,
676
+ altKey: event.altKey,
677
+ });
678
+ this.isMoving.set(false);
679
+ }
680
+ /**
681
+ * Handle the pointer down event.
682
+ */
683
+ onPointerDown(event) {
684
+ // ignore right-click or additional pointers
685
+ if (event.button !== 0 || this.pointerId !== null || this.isDisabled()) {
686
+ return;
687
+ }
688
+ // prevent the default behavior
689
+ event.preventDefault();
690
+ event.stopPropagation();
691
+ this.onMoveStart(event, event.pointerType);
692
+ // store the pointer id and initial position
693
+ this.pointerId = event.pointerId;
694
+ this.x = event.pageX;
695
+ this.y = event.pageY;
696
+ // add global event listeners
697
+ const pointerMove = this.disposables.addEventListener(window, 'pointermove', this.onPointerMove.bind(this), false);
698
+ const pointerUp = this.disposables.addEventListener(window, 'pointerup', this.onPointerUp.bind(this), false);
699
+ const pointerCancel = this.disposables.addEventListener(window, 'pointercancel', this.onPointerUp.bind(this), false);
700
+ // store the disposable event listeners
701
+ this.disposableListeners = [pointerMove, pointerUp, pointerCancel];
702
+ }
703
+ /**
704
+ * Handle the pointer up event.
705
+ */
706
+ onPointerUp(event) {
707
+ if (this.pointerId !== event.pointerId) {
708
+ return;
709
+ }
710
+ const pointerType = (event.pointerType ?? 'mouse');
711
+ this.onMoveEnd(event, pointerType);
712
+ this.pointerId = null;
713
+ this.disposableListeners.forEach(dispose => dispose());
714
+ }
715
+ /**
716
+ * Handle the pointer move event.
717
+ */
718
+ onPointerMove(event) {
719
+ if (this.pointerId !== event.pointerId) {
720
+ return;
721
+ }
722
+ // Problems with PointerEvent#movementX/movementY:
723
+ // 1. it is always 0 on macOS Safari.
724
+ // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
725
+ this.onMove(event, event.pointerType, event.pageX - (this.x ?? 0), event.pageY - (this.y ?? 0));
726
+ this.x = event.pageX;
727
+ this.y = event.pageY;
728
+ }
729
+ triggerKeyboardMove(event, deltaX, deltaY) {
730
+ if (this.isDisabled()) {
731
+ return;
732
+ }
733
+ this.onMoveStart(event, 'keyboard');
734
+ this.onMove(event, 'keyboard', deltaX, deltaY);
735
+ this.onMoveEnd(event, 'keyboard');
736
+ }
737
+ onArrowUp(event) {
738
+ event.preventDefault();
739
+ event.stopPropagation();
740
+ this.triggerKeyboardMove(event, 0, -1);
741
+ }
742
+ onArrowDown(event) {
743
+ event.preventDefault();
744
+ event.stopPropagation();
745
+ this.triggerKeyboardMove(event, 0, 1);
746
+ }
747
+ onArrowLeft(event) {
748
+ event.preventDefault();
749
+ event.stopPropagation();
750
+ this.triggerKeyboardMove(event, -1, 0);
751
+ }
752
+ onArrowRight(event) {
753
+ event.preventDefault();
754
+ event.stopPropagation();
755
+ this.triggerKeyboardMove(event, 1, 0);
756
+ }
757
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpMove, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
758
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.1.1", type: NgpMove, isStandalone: true, selector: "[ngpMove]", inputs: { disabled: { classPropertyName: "disabled", publicName: "ngpMoveDisabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { start: "ngpMoveStart", move: "ngpMove", end: "ngpMoveEnd" }, host: { listeners: { "pointerdown": "onPointerDown($event)", "keydown.ArrowUp": "onArrowUp($event)", "keydown.ArrowDown": "onArrowDown($event)", "keydown.ArrowLeft": "onArrowLeft($event)", "keydown.ArrowRight": "onArrowRight($event)" }, properties: { "attr.data-move": "isMoving()" } }, providers: [{ provide: NgpMoveToken, useExisting: NgpMove }], exportAs: ["ngpMove"], ngImport: i0 }); }
759
+ }
760
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.1", ngImport: i0, type: NgpMove, decorators: [{
761
+ type: Directive,
762
+ args: [{
763
+ standalone: true,
764
+ selector: '[ngpMove]',
765
+ exportAs: 'ngpMove',
766
+ providers: [{ provide: NgpMoveToken, useExisting: NgpMove }],
767
+ host: {
768
+ '[attr.data-move]': 'isMoving()',
769
+ },
770
+ }]
771
+ }], propDecorators: { onPointerDown: [{
772
+ type: HostListener,
773
+ args: ['pointerdown', ['$event']]
774
+ }], onArrowUp: [{
775
+ type: HostListener,
776
+ args: ['keydown.ArrowUp', ['$event']]
777
+ }], onArrowDown: [{
778
+ type: HostListener,
779
+ args: ['keydown.ArrowDown', ['$event']]
780
+ }], onArrowLeft: [{
781
+ type: HostListener,
782
+ args: ['keydown.ArrowLeft', ['$event']]
783
+ }], onArrowRight: [{
784
+ type: HostListener,
785
+ args: ['keydown.ArrowRight', ['$event']]
786
+ }] } });
787
+
420
788
  /**
421
789
  * Copyright © 2024 Angular Primitives.
422
790
  * https://github.com/ng-primitives/ng-primitives
@@ -429,5 +797,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.2", ngImpor
429
797
  * Generated bundle index. Do not edit.
430
798
  */
431
799
 
432
- export { NgpFocus, NgpFocusToken, NgpFocusVisible, NgpFocusVisibleToken, NgpHover, NgpHoverToken, injectHover };
800
+ export { NgpFocus, NgpFocusToken, NgpFocusVisible, NgpFocusVisibleToken, NgpHover, NgpHoverToken, NgpMove, NgpMoveToken, NgpPress, NgpPressToken, injectHover };
433
801
  //# sourceMappingURL=ng-primitives-interactions.mjs.map