@ng-annotate/angular 0.2.1 → 0.2.3

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.
@@ -1,51 +0,0 @@
1
- import { OnInit, ElementRef } from '@angular/core';
2
- import type { Annotation, ComponentContext } from '../types.js';
3
- type OverlayMode = 'hidden' | 'inspect' | 'annotate' | 'thread';
4
- interface HighlightRect {
5
- top: string;
6
- left: string;
7
- width: string;
8
- height: string;
9
- }
10
- interface AnnotationBadge {
11
- annotation: Annotation;
12
- top: string;
13
- left: string;
14
- icon: string;
15
- label: string;
16
- }
17
- export declare class OverlayComponent implements OnInit {
18
- textArea?: ElementRef<HTMLTextAreaElement>;
19
- mode: OverlayMode;
20
- hoveredContext: ComponentContext | null;
21
- highlightRect: HighlightRect | null;
22
- selectedContext: ComponentContext | null;
23
- annotationText: string;
24
- selectionText: string;
25
- threadAnnotation: Annotation | null;
26
- replyText: string;
27
- badges: AnnotationBadge[];
28
- private readonly inspector;
29
- private readonly bridge;
30
- private readonly cdr;
31
- ngOnInit(): void;
32
- toggleInspect(event?: Event): void;
33
- onEscape(): void;
34
- onScrollOrResize(): void;
35
- onMouseMove(event: MouseEvent): void;
36
- onClick(event: MouseEvent): void;
37
- submit(): void;
38
- cancel(): void;
39
- openThread(annotation: Annotation): void;
40
- closeThread(): void;
41
- sendReply(): void;
42
- inputEntries(): {
43
- key: string;
44
- value: unknown;
45
- }[];
46
- private updateBadges;
47
- private refreshBadgePositions;
48
- private findComponentElement;
49
- private badgeIcon;
50
- }
51
- export {};
@@ -1,430 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { Component, ChangeDetectionStrategy, ChangeDetectorRef, HostListener, ViewChild, ElementRef, inject, } from '@angular/core';
11
- import { JsonPipe } from '@angular/common';
12
- import { FormsModule } from '@angular/forms';
13
- import { InspectorService } from '../inspector.service.js';
14
- import { BridgeService } from '../bridge.service.js';
15
- let OverlayComponent = class OverlayComponent {
16
- constructor() {
17
- this.mode = 'hidden';
18
- this.hoveredContext = null;
19
- this.highlightRect = null;
20
- this.selectedContext = null;
21
- this.annotationText = '';
22
- this.selectionText = '';
23
- this.threadAnnotation = null;
24
- this.replyText = '';
25
- this.badges = [];
26
- this.inspector = inject(InspectorService);
27
- this.bridge = inject(BridgeService);
28
- this.cdr = inject(ChangeDetectorRef);
29
- }
30
- ngOnInit() {
31
- this.bridge.annotations$.subscribe((annotations) => {
32
- this.updateBadges(annotations);
33
- this.cdr.markForCheck();
34
- });
35
- }
36
- toggleInspect(event) {
37
- event?.preventDefault();
38
- if (this.mode === 'hidden')
39
- this.mode = 'inspect';
40
- else if (this.mode === 'inspect')
41
- this.mode = 'hidden';
42
- else if (this.mode === 'annotate')
43
- this.mode = 'inspect';
44
- this.cdr.markForCheck();
45
- }
46
- onEscape() {
47
- if (this.mode === 'annotate')
48
- this.mode = 'inspect';
49
- else if (this.mode === 'inspect')
50
- this.mode = 'hidden';
51
- else if (this.mode === 'thread')
52
- this.mode = 'hidden';
53
- this.cdr.markForCheck();
54
- }
55
- onScrollOrResize() {
56
- if (this.badges.length > 0) {
57
- this.refreshBadgePositions();
58
- this.cdr.markForCheck();
59
- }
60
- }
61
- onMouseMove(event) {
62
- if (this.mode !== 'inspect')
63
- return;
64
- const target = event.target;
65
- if (target.closest('nga-overlay'))
66
- return;
67
- const context = this.inspector.getComponentContext(target);
68
- this.hoveredContext = context;
69
- if (context) {
70
- const rect = target.getBoundingClientRect();
71
- this.highlightRect = {
72
- top: `${rect.top.toString()}px`,
73
- left: `${rect.left.toString()}px`,
74
- width: `${rect.width.toString()}px`,
75
- height: `${rect.height.toString()}px`,
76
- };
77
- }
78
- else {
79
- this.highlightRect = null;
80
- }
81
- this.cdr.markForCheck();
82
- }
83
- onClick(event) {
84
- if (this.mode !== 'inspect')
85
- return;
86
- const target = event.target;
87
- if (target.closest('nga-overlay'))
88
- return;
89
- const context = this.inspector.getComponentContext(target);
90
- if (!context)
91
- return;
92
- event.preventDefault();
93
- event.stopPropagation();
94
- this.selectedContext = context;
95
- this.annotationText = '';
96
- this.selectionText = window.getSelection()?.toString() ?? '';
97
- this.mode = 'annotate';
98
- this.cdr.markForCheck();
99
- setTimeout(() => { this.textArea?.nativeElement.focus(); }, 0);
100
- }
101
- submit() {
102
- if (!this.selectedContext || !this.annotationText.trim())
103
- return;
104
- this.bridge.createAnnotation({
105
- ...this.selectedContext,
106
- annotationText: this.annotationText.trim(),
107
- selectionText: this.selectionText || undefined,
108
- });
109
- this.selectedContext = null;
110
- this.annotationText = '';
111
- this.mode = 'inspect';
112
- this.cdr.markForCheck();
113
- }
114
- cancel() {
115
- this.mode = 'inspect';
116
- this.cdr.markForCheck();
117
- }
118
- openThread(annotation) {
119
- this.threadAnnotation = annotation;
120
- this.mode = 'thread';
121
- this.cdr.markForCheck();
122
- }
123
- closeThread() {
124
- this.threadAnnotation = null;
125
- this.mode = 'hidden';
126
- this.cdr.markForCheck();
127
- }
128
- sendReply() {
129
- if (!this.threadAnnotation || !this.replyText.trim())
130
- return;
131
- this.bridge.replyToAnnotation(this.threadAnnotation.id, this.replyText.trim());
132
- this.replyText = '';
133
- this.cdr.markForCheck();
134
- }
135
- inputEntries() {
136
- if (!this.selectedContext)
137
- return [];
138
- return Object.entries(this.selectedContext.inputs)
139
- .slice(0, 5)
140
- .map(([key, value]) => ({ key, value }));
141
- }
142
- updateBadges(annotations) {
143
- this.badges = annotations
144
- .map((annotation) => {
145
- const el = this.findComponentElement(annotation.componentName, annotation.selector);
146
- if (!el)
147
- return null;
148
- const rect = el.getBoundingClientRect();
149
- return {
150
- annotation,
151
- top: `${rect.top.toString()}px`,
152
- left: `${(rect.left + rect.width - 12).toString()}px`,
153
- icon: this.badgeIcon(annotation.status),
154
- label: `${annotation.componentName}: ${annotation.annotationText.slice(0, 40)}`,
155
- };
156
- })
157
- .filter((b) => b !== null);
158
- }
159
- refreshBadgePositions() {
160
- this.badges = this.badges.map((badge) => {
161
- const el = this.findComponentElement(badge.annotation.componentName, badge.annotation.selector);
162
- if (!el)
163
- return badge;
164
- const rect = el.getBoundingClientRect();
165
- return {
166
- ...badge,
167
- top: `${rect.top.toString()}px`,
168
- left: `${(rect.left + rect.width - 12).toString()}px`,
169
- };
170
- });
171
- }
172
- findComponentElement(componentName, selector) {
173
- const bySelector = document.querySelector(selector);
174
- if (bySelector)
175
- return bySelector;
176
- const all = document.querySelectorAll('*');
177
- for (const el of Array.from(all)) {
178
- try {
179
- const comp = window
180
- .ng;
181
- if (comp?.getComponent(el)?.constructor.name === componentName)
182
- return el;
183
- }
184
- catch {
185
- // ignore
186
- }
187
- }
188
- return null;
189
- }
190
- badgeIcon(status) {
191
- const icons = {
192
- pending: '●',
193
- acknowledged: '◐',
194
- resolved: '✓',
195
- dismissed: '✕',
196
- };
197
- return icons[status];
198
- }
199
- };
200
- __decorate([
201
- ViewChild('textArea'),
202
- __metadata("design:type", ElementRef)
203
- ], OverlayComponent.prototype, "textArea", void 0);
204
- __decorate([
205
- HostListener('document:keydown.alt.shift.a', ['$event']),
206
- __metadata("design:type", Function),
207
- __metadata("design:paramtypes", [Event]),
208
- __metadata("design:returntype", void 0)
209
- ], OverlayComponent.prototype, "toggleInspect", null);
210
- __decorate([
211
- HostListener('document:keydown.escape'),
212
- __metadata("design:type", Function),
213
- __metadata("design:paramtypes", []),
214
- __metadata("design:returntype", void 0)
215
- ], OverlayComponent.prototype, "onEscape", null);
216
- __decorate([
217
- HostListener('window:scroll'),
218
- HostListener('window:resize'),
219
- __metadata("design:type", Function),
220
- __metadata("design:paramtypes", []),
221
- __metadata("design:returntype", void 0)
222
- ], OverlayComponent.prototype, "onScrollOrResize", null);
223
- __decorate([
224
- HostListener('document:mousemove', ['$event']),
225
- __metadata("design:type", Function),
226
- __metadata("design:paramtypes", [MouseEvent]),
227
- __metadata("design:returntype", void 0)
228
- ], OverlayComponent.prototype, "onMouseMove", null);
229
- __decorate([
230
- HostListener('document:click', ['$event']),
231
- __metadata("design:type", Function),
232
- __metadata("design:paramtypes", [MouseEvent]),
233
- __metadata("design:returntype", void 0)
234
- ], OverlayComponent.prototype, "onClick", null);
235
- OverlayComponent = __decorate([
236
- Component({
237
- selector: 'nga-overlay',
238
- changeDetection: ChangeDetectionStrategy.OnPush,
239
- imports: [JsonPipe, FormsModule],
240
- styles: [`
241
- :host {
242
- position: fixed; top: 0; left: 0; width: 100%; height: 100%;
243
- pointer-events: none; z-index: 9999;
244
- }
245
- .nga-highlight-rect {
246
- position: fixed; border: 2px solid #3b82f6;
247
- background: rgba(59,130,246,0.1); pointer-events: none;
248
- transition: top 0.05s, left 0.05s, width 0.05s, height 0.05s;
249
- }
250
- .nga-component-label {
251
- position: absolute; top: -22px; left: 0; background: #1e293b; color: #f8fafc;
252
- font-family: monospace; font-size: 11px; padding: 2px 6px;
253
- border-radius: 3px; white-space: nowrap;
254
- }
255
- .nga-annotate-panel, .nga-thread-panel {
256
- pointer-events: all; position: fixed; right: 16px; top: 50%;
257
- transform: translateY(-50%); background: #ffffff; border: 1px solid #e2e8f0;
258
- border-radius: 8px; box-shadow: 0 4px 24px rgba(0,0,0,0.15);
259
- padding: 16px; min-width: 320px; max-width: 400px;
260
- }
261
- .nga-panel-title {
262
- margin: 0 0 12px; font-size: 14px; font-weight: 600;
263
- color: #1e293b; font-family: monospace;
264
- }
265
- .nga-inputs { margin-bottom: 10px; }
266
- .nga-input-row {
267
- display: flex; gap: 8px; font-size: 12px;
268
- font-family: monospace; margin-bottom: 4px;
269
- }
270
- .nga-input-key { color: #64748b; min-width: 80px; }
271
- .nga-input-val {
272
- color: #1e293b; overflow: hidden;
273
- text-overflow: ellipsis; white-space: nowrap;
274
- }
275
- .nga-selection {
276
- font-size: 12px; color: #475569; margin-bottom: 8px; font-style: italic;
277
- }
278
- .nga-textarea, .nga-reply-input {
279
- width: 100%; box-sizing: border-box; border: 1px solid #cbd5e1;
280
- border-radius: 4px; padding: 8px; font-size: 13px;
281
- font-family: inherit; resize: vertical; margin-bottom: 10px;
282
- }
283
- .nga-textarea:focus, .nga-reply-input:focus {
284
- outline: none; border-color: #3b82f6;
285
- }
286
- .nga-actions { display: flex; gap: 8px; }
287
- .nga-btn {
288
- padding: 6px 14px; border-radius: 4px; font-size: 13px;
289
- cursor: pointer; border: none; transition: opacity 0.15s;
290
- }
291
- .nga-btn:disabled { opacity: 0.4; cursor: not-allowed; }
292
- .nga-btn-submit { background: #3b82f6; color: #ffffff; }
293
- .nga-btn-cancel { background: #f1f5f9; color: #475569; }
294
- .nga-replies { max-height: 200px; overflow-y: auto; margin-bottom: 10px; }
295
- .nga-reply { display: flex; gap: 8px; margin-bottom: 8px; font-size: 13px; }
296
- .nga-reply-author { font-weight: 600; min-width: 48px; }
297
- .nga-reply-author--agent { color: #7c3aed; }
298
- .nga-reply-author--user { color: #2563eb; }
299
- .nga-badge {
300
- pointer-events: all; position: fixed; width: 18px; height: 18px;
301
- border-radius: 50%; display: flex; align-items: center;
302
- justify-content: center; font-size: 10px; cursor: pointer;
303
- transform: translate(-50%, -50%);
304
- }
305
- .nga-badge--pending { background: #3b82f6; color: #ffffff; }
306
- .nga-badge--acknowledged { background: #f59e0b; color: #ffffff; }
307
- .nga-badge--resolved { background: #22c55e; color: #ffffff; }
308
- .nga-badge--dismissed { background: #94a3b8; color: #ffffff; }
309
- .nga-keyboard-hint {
310
- pointer-events: none; position: fixed; bottom: 16px; right: 16px;
311
- background: rgba(15,23,42,0.7); color: #f8fafc; font-size: 12px;
312
- padding: 6px 10px; border-radius: 6px;
313
- }
314
- .nga-keyboard-hint kbd {
315
- background: rgba(255,255,255,0.15); border-radius: 3px;
316
- padding: 1px 5px; font-family: monospace;
317
- }
318
- `],
319
- template: `
320
- <!-- Keyboard hint -->
321
- @if (mode === 'hidden') {
322
- <div class="nga-keyboard-hint">
323
- <kbd>Alt+Shift+A</kbd> to annotate
324
- </div>
325
- }
326
- @if (mode === 'inspect') {
327
- <div class="nga-keyboard-hint">
328
- Click a component &nbsp; <kbd>Esc</kbd> to cancel
329
- </div>
330
- }
331
-
332
- <!-- Inspect highlight rect -->
333
- @if (mode === 'inspect' && hoveredContext !== null && highlightRect !== null) {
334
- <div
335
- class="nga-highlight-rect"
336
- [style.top]="highlightRect.top"
337
- [style.left]="highlightRect.left"
338
- [style.width]="highlightRect.width"
339
- [style.height]="highlightRect.height"
340
- >
341
- <span class="nga-component-label">{{ hoveredContext.componentName }}</span>
342
- </div>
343
- }
344
-
345
- <!-- Annotate panel -->
346
- @if (mode === 'annotate' && selectedContext !== null) {
347
- <div class="nga-annotate-panel">
348
- <h3 class="nga-panel-title">{{ selectedContext.componentName }}</h3>
349
-
350
- @if (inputEntries().length > 0) {
351
- <div class="nga-inputs">
352
- @for (entry of inputEntries(); track entry.key) {
353
- <div class="nga-input-row">
354
- <span class="nga-input-key">{{ entry.key }}:</span>
355
- <span class="nga-input-val">{{ entry.value | json }}</span>
356
- </div>
357
- }
358
- </div>
359
- }
360
-
361
- @if (selectionText) {
362
- <div class="nga-selection">
363
- <em>"{{ selectionText }}"</em>
364
- </div>
365
- }
366
-
367
- <textarea
368
- #textArea
369
- class="nga-textarea"
370
- [(ngModel)]="annotationText"
371
- placeholder="Describe the change..."
372
- rows="4"
373
- ></textarea>
374
-
375
- <div class="nga-actions">
376
- <button class="nga-btn nga-btn-submit" (click)="submit()" [disabled]="annotationText.trim() === ''">
377
- Submit
378
- </button>
379
- <button class="nga-btn nga-btn-cancel" (click)="cancel()">Cancel</button>
380
- </div>
381
- </div>
382
- }
383
-
384
- <!-- Thread panel -->
385
- @if (mode === 'thread' && threadAnnotation !== null) {
386
- <div class="nga-thread-panel">
387
- <h3 class="nga-panel-title">{{ threadAnnotation.componentName }}</h3>
388
-
389
- <div class="nga-replies">
390
- @for (reply of threadAnnotation.replies; track reply.message) {
391
- <div class="nga-reply">
392
- <span class="nga-reply-author nga-reply-author--{{ reply.author }}">{{ reply.author }}</span>
393
- <span class="nga-reply-text">{{ reply.message }}</span>
394
- </div>
395
- }
396
- </div>
397
-
398
- <input
399
- class="nga-reply-input"
400
- type="text"
401
- [(ngModel)]="replyText"
402
- placeholder="Reply..."
403
- (keydown.enter)="sendReply()"
404
- />
405
-
406
- <div class="nga-actions">
407
- <button class="nga-btn nga-btn-submit" (click)="sendReply()" [disabled]="replyText.trim() === ''">
408
- Send
409
- </button>
410
- <button class="nga-btn nga-btn-cancel" (click)="closeThread()">Close</button>
411
- </div>
412
- </div>
413
- }
414
-
415
- <!-- Annotation badges -->
416
- @for (badge of badges; track badge.annotation.id) {
417
- <div
418
- class="nga-badge nga-badge--{{ badge.annotation.status }}"
419
- [style.top]="badge.top"
420
- [style.left]="badge.left"
421
- (click)="openThread(badge.annotation)"
422
- [title]="badge.label"
423
- >
424
- {{ badge.icon }}
425
- </div>
426
- }
427
- `,
428
- })
429
- ], OverlayComponent);
430
- export { OverlayComponent };
@@ -1 +0,0 @@
1
- export declare function provideNgAnnotate(): import("@angular/core").EnvironmentProviders;
@@ -1,21 +0,0 @@
1
- import { ApplicationRef, EnvironmentInjector, createComponent, inject, isDevMode, makeEnvironmentProviders, provideAppInitializer, } from '@angular/core';
2
- import { InspectorService } from './inspector.service.js';
3
- import { BridgeService } from './bridge.service.js';
4
- import { OverlayComponent } from './overlay/overlay.component.js';
5
- export function provideNgAnnotate() {
6
- return makeEnvironmentProviders([
7
- InspectorService,
8
- BridgeService,
9
- provideAppInitializer(() => {
10
- if (!isDevMode())
11
- return;
12
- const bridge = inject(BridgeService);
13
- const appRef = inject(ApplicationRef);
14
- const envInjector = inject(EnvironmentInjector);
15
- bridge.init();
16
- const overlayRef = createComponent(OverlayComponent, { environmentInjector: envInjector });
17
- appRef.attachView(overlayRef.hostView);
18
- document.body.appendChild(overlayRef.location.nativeElement);
19
- }),
20
- ]);
21
- }
package/dist/types.d.ts DELETED
@@ -1,39 +0,0 @@
1
- export type AnnotationStatus = 'pending' | 'acknowledged' | 'resolved' | 'dismissed';
2
- export interface AnnotationReply {
3
- id: string;
4
- createdAt: string;
5
- author: 'agent' | 'user';
6
- message: string;
7
- }
8
- export interface Annotation {
9
- id: string;
10
- sessionId: string;
11
- createdAt: string;
12
- status: AnnotationStatus;
13
- replies: AnnotationReply[];
14
- componentName: string;
15
- componentFilePath: string;
16
- templateFilePath?: string;
17
- selector: string;
18
- inputs: Record<string, unknown>;
19
- domSnapshot: string;
20
- componentTreePath: string[];
21
- annotationText: string;
22
- selectionText?: string;
23
- }
24
- export interface Session {
25
- id: string;
26
- createdAt: string;
27
- lastSeenAt: string;
28
- active: boolean;
29
- url: string;
30
- }
31
- export interface ComponentContext {
32
- componentName: string;
33
- componentFilePath: string;
34
- templateFilePath?: string;
35
- selector: string;
36
- inputs: Record<string, unknown>;
37
- domSnapshot: string;
38
- componentTreePath: string[];
39
- }
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};