wally-ui 1.13.1 → 1.14.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 (31) hide show
  1. package/package.json +1 -1
  2. package/playground/showcase/package-lock.json +48 -0
  3. package/playground/showcase/package.json +1 -0
  4. package/playground/showcase/src/app/app.routes.server.ts +4 -0
  5. package/playground/showcase/src/app/components/ai/ai-chat/ai-chat.html +7 -2
  6. package/playground/showcase/src/app/components/ai/ai-chat/ai-chat.ts +12 -1
  7. package/playground/showcase/src/app/components/ai/ai-chat.service.spec.ts +16 -0
  8. package/playground/showcase/src/app/components/ai/ai-chat.service.ts +6 -0
  9. package/playground/showcase/src/app/components/ai/ai-composer/ai-composer.html +14 -7
  10. package/playground/showcase/src/app/components/ai/ai-composer/ai-composer.ts +3 -1
  11. package/playground/showcase/src/app/components/ai/ai-message/ai-message.css +0 -0
  12. package/playground/showcase/src/app/components/ai/ai-message/ai-message.html +165 -0
  13. package/playground/showcase/src/app/components/ai/ai-message/ai-message.spec.ts +23 -0
  14. package/playground/showcase/src/app/components/ai/ai-message/ai-message.ts +51 -0
  15. package/playground/showcase/src/app/components/button/button.html +1 -1
  16. package/playground/showcase/src/app/components/button/button.ts +3 -3
  17. package/playground/showcase/src/app/components/selection-popover/selection-popover.css +0 -0
  18. package/playground/showcase/src/app/components/selection-popover/selection-popover.html +33 -0
  19. package/playground/showcase/src/app/components/selection-popover/selection-popover.spec.ts +23 -0
  20. package/playground/showcase/src/app/components/selection-popover/selection-popover.ts +269 -0
  21. package/playground/showcase/src/app/pages/documentation/chat-sdk/chat-sdk.html +1 -1
  22. package/playground/showcase/src/app/pages/documentation/components/button-docs/button-docs.examples.ts +10 -10
  23. package/playground/showcase/src/app/pages/documentation/components/button-docs/button-docs.html +2 -2
  24. package/playground/showcase/src/app/pages/documentation/components/components.html +27 -0
  25. package/playground/showcase/src/app/pages/documentation/components/components.routes.ts +4 -0
  26. package/playground/showcase/src/app/pages/documentation/components/selection-popover-docs/selection-popover-docs.css +1 -0
  27. package/playground/showcase/src/app/pages/documentation/components/selection-popover-docs/selection-popover-docs.examples.ts +328 -0
  28. package/playground/showcase/src/app/pages/documentation/components/selection-popover-docs/selection-popover-docs.html +555 -0
  29. package/playground/showcase/src/app/pages/documentation/components/selection-popover-docs/selection-popover-docs.ts +97 -0
  30. package/playground/showcase/src/app/pages/home/home.html +2 -2
  31. package/playground/showcase/src/styles.css +1 -0
@@ -0,0 +1,269 @@
1
+ import { AfterViewInit, Component, computed, ElementRef, HostListener, output, OutputEmitterRef, signal, ViewChild, WritableSignal } from '@angular/core';
2
+
3
+ /**
4
+ * Selection Popover Component
5
+ *
6
+ * Displays a floating action toolbar above selected text (similar to Medium, Notion, Google Docs).
7
+ * Uses Selection API for text detection and supports custom actions via content projection.
8
+ *
9
+ * @example
10
+ * ```html
11
+ * <wally-selection-popover (textSelected)="onTextSelected($event)">
12
+ * <div popoverActions>
13
+ * <button>Custom Action</button>
14
+ * </div>
15
+ * <article>Selectable content...</article>
16
+ * </wally-selection-popover>
17
+ * ```
18
+ */
19
+ @Component({
20
+ selector: 'wally-selection-popover',
21
+ standalone: true,
22
+ imports: [],
23
+ templateUrl: './selection-popover.html',
24
+ styleUrl: './selection-popover.css'
25
+ })
26
+ export class SelectionPopover implements AfterViewInit {
27
+ /** Reference to the popover element for positioning calculations */
28
+ @ViewChild('popover') popoverElement!: ElementRef<HTMLDivElement>;
29
+
30
+ /** Reference to custom actions slot for detecting projected content */
31
+ @ViewChild('customActionsSlot', { read: ElementRef }) customActionsSlot?: ElementRef;
32
+
33
+ /** Emits when text is selected (fallback action only) */
34
+ textSelected: OutputEmitterRef<string> = output<string>();
35
+
36
+ /** Current popover position (top, left in pixels) */
37
+ popoverPosition: WritableSignal<{ top: number; left: number; }> = signal<{ top: number; left: number; }>({ top: 0, left: 0 });
38
+
39
+ /** Whether custom actions are projected */
40
+ hasCustomActionsSignal: WritableSignal<boolean> = signal<boolean>(false);
41
+
42
+ /** Whether popover should be rendered in DOM */
43
+ isVisible: WritableSignal<boolean> = signal<boolean>(false);
44
+
45
+ /** Whether popover is positioned correctly (controls opacity) */
46
+ isPositioned: WritableSignal<boolean> = signal<boolean>(false);
47
+
48
+ /** Currently selected text */
49
+ selectedText: WritableSignal<string> = signal<string>('');
50
+
51
+ /**
52
+ * Detects if user is on mobile device
53
+ */
54
+ isMobile = computed(() => {
55
+ if (typeof window === 'undefined') return false;
56
+
57
+ return 'ontouchstart' in window ||
58
+ navigator.maxTouchPoints > 0 ||
59
+ window.innerWidth < 768;
60
+ });
61
+
62
+ /**
63
+ * Computes adjusted position with viewport constraints
64
+ * Prevents popover from overflowing screen edges
65
+ * Mobile-aware: accounts for virtual keyboard and smaller screens
66
+ */
67
+ adjustedPosition = computed(() => {
68
+ const position = this.popoverPosition();
69
+ const viewportWidth = window.innerWidth;
70
+ const viewportHeight = window.innerHeight;
71
+
72
+ // Get real popover dimensions if available, otherwise estimate
73
+ const popoverWidth = this.popoverElement?.nativeElement?.offsetWidth || 200;
74
+ const popoverHeight = this.popoverElement?.nativeElement?.offsetHeight || 50;
75
+
76
+ let left = position.left;
77
+ let top = position.top;
78
+
79
+ // Horizontal adjustment
80
+ if (left + popoverWidth > viewportWidth) {
81
+ left = viewportWidth - popoverWidth - 10;
82
+ }
83
+ if (left < 10) {
84
+ left = 10;
85
+ }
86
+
87
+ // Vertical adjustment for mobile (avoid keyboard and screen edges)
88
+ if (this.isMobile()) {
89
+ // If too close to top, position below selection instead
90
+ if (top < 80) {
91
+ const selection = window.getSelection();
92
+ if (selection && selection.rangeCount > 0) {
93
+ const range = selection.getRangeAt(0);
94
+ const rect = range.getBoundingClientRect();
95
+ top = rect.bottom + 10; // 10px below selection
96
+ }
97
+ }
98
+
99
+ // If too close to bottom (virtual keyboard area), keep visible
100
+ if (top + popoverHeight > viewportHeight - 100) {
101
+ top = viewportHeight - popoverHeight - 100;
102
+ }
103
+ }
104
+
105
+ return { top, left };
106
+ });
107
+
108
+ /**
109
+ * Handles both mouse and touch selection events
110
+ * Mobile: touchend after long-press selection
111
+ * Desktop: mouseup after click-drag selection
112
+ */
113
+ @HostListener('mouseup', ['$event'])
114
+ @HostListener('touchend', ['$event'])
115
+ onMouseUp(event: MouseEvent | TouchEvent): void {
116
+ const isMobile = 'ontouchstart' in window;
117
+ const delay = isMobile ? 100 : 10;
118
+
119
+ setTimeout(() => {
120
+ this.handleTextSelection();
121
+ }, delay);
122
+ }
123
+
124
+ /**
125
+ * Closes popover when clicking outside
126
+ * @param event - Mouse event from document click
127
+ */
128
+ @HostListener('document:mousedown', ['$event'])
129
+ onDocumentClick(event: MouseEvent): void {
130
+ if (this.isVisible() && this.popoverElement) {
131
+ const clickedInside = this.popoverElement.nativeElement.contains(event.target as Node);
132
+
133
+ if (!clickedInside) {
134
+ this.hide();
135
+ }
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Closes popover when ESC key is pressed
141
+ */
142
+ @HostListener('document:keydown.escape')
143
+ onEscape(): void {
144
+ this.hide();
145
+ }
146
+
147
+ /**
148
+ * Prevents native mobile selection menu from appearing
149
+ * This ensures only our custom popover is shown
150
+ */
151
+ @HostListener('selectionchange')
152
+ onNativeSelectionChange() {
153
+ const selection = window.getSelection();
154
+
155
+ if (selection && selection.toString().trim().length >= 3) {
156
+ // Prevent native menu only if valid selection exists
157
+ // and our popover will appear
158
+ event?.preventDefault?.();
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Prevents scroll when touching the popover on mobile
164
+ * Ensures users can interact with actions without accidentally scrolling
165
+ */
166
+ @HostListener('touchmove', ['$event'])
167
+ onTouchMove(event: TouchEvent): void {
168
+ if (this.isVisible() && this.popoverElement) {
169
+ const target = event.target as Node;
170
+ const isPopoverTouch = this.popoverElement.nativeElement.contains(target);
171
+
172
+ if (isPopoverTouch) {
173
+ event.preventDefault();
174
+ }
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Handles text selection and shows popover
180
+ *
181
+ * Two-step positioning algorithm to prevent visual "flash":
182
+ * 1. Render popover invisible (opacity: 0) at selection center
183
+ * 2. Wait for DOM render to get real popover width
184
+ * 3. Recalculate centered position with actual width
185
+ * 4. Fade in popover (opacity: 100) at correct position
186
+ *
187
+ * Uses position: fixed + getBoundingClientRect() for viewport-relative positioning
188
+ * No window.scrollY needed - stays in place during scroll
189
+ */
190
+ handleTextSelection(): void {
191
+ const selection = window.getSelection();
192
+
193
+ if (!selection || selection.toString().trim().length < 3) {
194
+ this.hide();
195
+ return;
196
+ }
197
+
198
+ const text = selection.toString().trim();
199
+ const range = selection.getRangeAt(0);
200
+ const rect = range.getBoundingClientRect();
201
+
202
+ this.selectedText.set(text);
203
+
204
+ // Calculate selection center point
205
+ const selectionCenterX = rect.left + (rect.width / 2);
206
+ const selectionTop = rect.top;
207
+
208
+ // Step 1: Render invisible for width calculation
209
+ this.isVisible.set(true);
210
+ this.isPositioned.set(false); // opacity: 0
211
+
212
+ // Step 2: Recalculate position with real popover width
213
+ setTimeout(() => {
214
+ if (this.popoverElement?.nativeElement) {
215
+ const popoverWidth = this.popoverElement.nativeElement.offsetWidth;
216
+
217
+ // Center popover above selection (60px offset)
218
+ this.popoverPosition.set({
219
+ top: selectionTop - 60,
220
+ left: selectionCenterX - (popoverWidth / 2)
221
+ });
222
+
223
+ // Fade in at correct position
224
+ this.isPositioned.set(true); // opacity: 100
225
+ }
226
+
227
+ // Detect projected custom actions
228
+ if (this.customActionsSlot?.nativeElement) {
229
+ const slot = this.customActionsSlot.nativeElement;
230
+ const firstChild = slot.children[0] as HTMLElement;
231
+ const hasContent = firstChild && firstChild.children.length > 0;
232
+ this.hasCustomActionsSignal.set(hasContent);
233
+ }
234
+ }, 0);
235
+ }
236
+
237
+ /**
238
+ * Hides popover and clears browser text selection
239
+ */
240
+ hide(): void {
241
+ this.isVisible.set(false);
242
+ this.isPositioned.set(false);
243
+
244
+ window.getSelection()?.removeAllRanges();
245
+ }
246
+
247
+ /**
248
+ * Handles any click inside the popover
249
+ * Emits selected text and closes popover
250
+ * This allows both custom actions and fallback button to work
251
+ */
252
+ onPopoverClick() {
253
+ const text = this.selectedText();
254
+ this.textSelected.emit(text);
255
+ this.hide();
256
+ }
257
+
258
+ /**
259
+ * Lifecycle hook - detects custom actions on component init
260
+ */
261
+ ngAfterViewInit(): void {
262
+ if (this.customActionsSlot?.nativeElement) {
263
+ const slot = this.customActionsSlot.nativeElement;
264
+ const firstChild = slot.children[0] as HTMLElement;
265
+ const hasContent = firstChild && firstChild.children.length > 0;
266
+ this.hasCustomActionsSignal.set(hasContent);
267
+ }
268
+ }
269
+ }
@@ -22,7 +22,7 @@
22
22
  </header>
23
23
 
24
24
  <!-- Live Demo -->
25
- <section id="live-demo" class="mb-12" aria-labelledby="demo-heading">
25
+ <section id="live-demo" class="mb-12 font-sans" aria-labelledby="demo-heading">
26
26
  <h2 id="demo-heading" class="text-[10px] sm:text-xs text-neutral-500 dark:text-neutral-500 uppercase tracking-wider mb-4">
27
27
  [ Live Demo ]
28
28
  </h2>
@@ -79,7 +79,7 @@ export const ButtonCodeExamples = {
79
79
  <wally-button
80
80
  variant="secondary"
81
81
  type="button"
82
- (click)="goToSignUp()">
82
+ (buttonClick)="goToSignUp()">
83
83
  Create Account
84
84
  </wally-button>
85
85
  </div>
@@ -109,14 +109,14 @@ export const ButtonCodeExamples = {
109
109
  <div class="flex gap-2 justify-end">
110
110
  <wally-button
111
111
  variant="ghost"
112
- (click)="closeModal()">
112
+ (buttonClick)="closeModal()">
113
113
  Cancel
114
114
  </wally-button>
115
115
 
116
116
  <wally-button
117
117
  variant="destructive"
118
118
  [loading]="isDeleting()"
119
- (click)="confirmDelete()">
119
+ (buttonClick)="confirmDelete()">
120
120
  Delete Account
121
121
  </wally-button>
122
122
  </div>
@@ -125,7 +125,7 @@ export const ButtonCodeExamples = {
125
125
  // Dashboard Actions
126
126
  dashboardExample: `<!-- Dashboard Actions -->
127
127
  <div class="dashboard-header">
128
- <wally-button variant="outline" (click)="exportData()">
128
+ <wally-button variant="outline" (buttonClick)="exportData()">
129
129
  Export
130
130
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
131
131
  stroke-width="1.5" stroke="currentColor" class="size-5">
@@ -134,7 +134,7 @@ export const ButtonCodeExamples = {
134
134
  </svg>
135
135
  </wally-button>
136
136
 
137
- <wally-button (click)="createNew()">
137
+ <wally-button (buttonClick)="createNew()">
138
138
  Create New
139
139
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
140
140
  stroke-width="2" stroke="currentColor" class="size-5">
@@ -162,7 +162,7 @@ export const ButtonCodeExamples = {
162
162
 
163
163
  // === EVENTS ===
164
164
 
165
- clickTemplate: `<wally-button (click)="handleClick()">Click Me</wally-button>`,
165
+ clickTemplate: `<wally-button (buttonClick)="handleClick()">Click Me</wally-button>`,
166
166
 
167
167
  clickMethod: `handleClick(): void {
168
168
  console.log('Button clicked!');
@@ -263,7 +263,7 @@ export const ButtonCodeExamples = {
263
263
  </wally-button>
264
264
 
265
265
  <!-- Programmatic navigation -->
266
- <wally-button (click)="navigateToProfile()">
266
+ <wally-button (buttonClick)="navigateToProfile()">
267
267
  View Profile
268
268
  </wally-button>`,
269
269
 
@@ -312,18 +312,18 @@ export class MyComponent {
312
312
  <wally-button
313
313
  [loading]="isLoading()"
314
314
  [disabled]="isDisabled()"
315
- (click)="handleSubmit()">
315
+ (buttonClick)="handleSubmit()">
316
316
  Submit
317
317
  </wally-button>`,
318
318
 
319
319
  // Button vs type="button"
320
320
  buttonTypeExplained: `<!-- GOOD: Explicit type prevents accidental form submission -->
321
- <wally-button type="button" (click)="openModal()">
321
+ <wally-button type="button" (buttonClick)="openModal()">
322
322
  Open
323
323
  </wally-button>
324
324
 
325
325
  <!-- CAUTION: Default type="button" is safe, but explicit is better -->
326
- <wally-button (click)="openModal()">Open</wally-button>
326
+ <wally-button (buttonClick)="openModal()">Open</wally-button>
327
327
 
328
328
  <!-- GOOD: Use type="submit" for form submission -->
329
329
  <form (ngSubmit)="save()">
@@ -484,7 +484,7 @@
484
484
  <div class="p-8 border-2 border-neutral-300 dark:border-neutral-700 bg-white dark:bg-[#0a0a0a]" role="img"
485
485
  aria-label="Live preview of button click event handling with feedback message">
486
486
  <div class="flex flex-col gap-2 text-center">
487
- <wally-button (click)="handleClick()">Click Me</wally-button>
487
+ <wally-button (buttonClick)="handleClick()">Click Me</wally-button>
488
488
  @if (clickMessage()) {
489
489
  <p class="text-sm text-green-600 dark:text-green-400 font-medium">
490
490
  {{ clickMessage() }}
@@ -753,7 +753,7 @@
753
753
  </thead>
754
754
  <tbody>
755
755
  <tr>
756
- <td class="p-4 font-mono text-blue-600 dark:text-blue-400">click</td>
756
+ <td class="p-4 font-mono text-blue-600 dark:text-blue-400">buttonClick</td>
757
757
  <td class="p-4 font-mono text-purple-600 dark:text-purple-400">void</td>
758
758
  <td class="p-4 text-gray-700 dark:text-gray-300">Emitted when button is clicked. Also handles
759
759
  navigation for link variant</td>
@@ -181,6 +181,33 @@
181
181
  </article>
182
182
 
183
183
 
184
+ <!-- Selection Popover Component -->
185
+ <article class="group border-b-2 border-neutral-300 dark:border-neutral-700 last:border-b-0" role="article"
186
+ aria-labelledby="selection-popover-heading">
187
+ <a href="/documentation/components/selection-popover"
188
+ class="block px-4 py-4 sm:py-5 bg-white dark:bg-[#0a0a0a] hover:bg-[#0a0a0a] dark:hover:bg-white transition-all duration-150 cursor-pointer"
189
+ aria-label="Navigate to Selection Popover component documentation with text selection detection, viewport-aware positioning, and zero-flash rendering">
190
+ <div class="flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3">
191
+ <div class="flex-1">
192
+ <div class="flex items-center gap-3 mb-2">
193
+ <h3 id="selection-popover-heading"
194
+ class="text-base sm:text-lg font-bold text-[#0a0a0a] dark:text-white group-hover:text-white dark:group-hover:text-[#0a0a0a] uppercase tracking-wide transition-colors duration-150">
195
+ <span aria-hidden="true">&gt;_ </span>Selection Popover
196
+ </h3>
197
+ <span class="text-[10px] font-bold bg-blue-500 text-white px-2 py-1 uppercase tracking-wider"
198
+ aria-label="Status: New Component">
199
+ NEW
200
+ </span>
201
+ </div>
202
+ <p
203
+ class="text-xs sm:text-sm text-neutral-600 dark:text-neutral-400 group-hover:text-neutral-300 dark:group-hover:text-neutral-600 transition-colors duration-150">
204
+ Floating action toolbar that appears above selected text (Medium/Notion-style). Features Selection API integration, viewport-aware positioning, zero-flash rendering, and custom actions via content projection.
205
+ </p>
206
+ </div>
207
+ </div>
208
+ </a>
209
+ </article>
210
+
184
211
  <!-- Tooltip Component -->
185
212
  <article class="group border-b-2 border-neutral-300 dark:border-neutral-700 last:border-b-0" role="article"
186
213
  aria-labelledby="tooltip-heading">
@@ -28,5 +28,9 @@ export const componentsRoutes: Routes = [
28
28
  {
29
29
  path: 'dropdown-menu',
30
30
  loadComponent: () => import('./dropdown-menu-docs/dropdown-menu-docs').then(m => m.DropdownMenuDocs)
31
+ },
32
+ {
33
+ path: 'selection-popover',
34
+ loadComponent: () => import('./selection-popover-docs/selection-popover-docs').then(m => m.SelectionPopoverDocs)
31
35
  }
32
36
  ];