Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.2

- **fix: ⌃⌥Space never opened Spotlight.** `App.onKeydown` called `shortcuts.handleKeydown(event)` twice per keydown, so every toggle shortcut flipped and flipped straight back, and ⌃⌥Tab cycled two windows at a time. It's now bound once through `host: { '(document:keydown)': … }` instead of `@HostListener`
- **fix: ⌘Space was still swallowed.** The same handler kept a `preventDefault()` on ⌘Space that the 1.3.4 remap meant to remove, so the real macOS Spotlight shortcut did nothing while the site had focus. Specs now pin both: one ⌃⌥Space opens Spotlight, and ⌘Space is left un-prevented
- **Readable thought dates**: cards and the reader show "Jun 15, 2026" instead of `2026-06-15`, inside a `<time datetime>`. Formatting is in UTC on purpose: a bare `YYYY-MM-DD` parses as UTC midnight, so local time would show the day before for anyone west of UTC, and SSR and the browser would disagree
- I used `DatePipe` first, and the production build put the initial bundle up 13 kB (375.71 → 389.07 kB). `@angular/common` is one module the app already loads eagerly, so `DatePipe`'s locale code landed in the initial chunk even though both views are lazy. A small `utcDate` pipe over `Intl.DateTimeFormat` brought it back to 377.25 kB. It throws on an unparseable date rather than printing "Invalid Date"
- **Reading time** on prose thoughts via a pure `readingTime` pipe (200 wpm, rounded up). Lesson pages skip it, since a word count of their intro would undersell them
- **Angular guide, lesson 03: templates and binding** (`/thoughts/angular-03-templates`). Two live demos: property vs attribute binding on an input you type into, and `@for`/`@empty`/`@let`/`@switch` on a removable tag list. Both bugs above are in the lesson as pitfalls

## 2026-11-21 - version 1.4.1

- **Angular guide, lesson 02: components** (`/thoughts/angular-02-components`). Covers standalone components, `input()`, `output()`, `model()`, content projection, dynamic components and view encapsulation. The live demo is a badge whose label and tone flow in through inputs, whose count is two-way through `[(count)]`, and whose dismiss button emits an output into an event log
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.4.1",
"version": "1.4.2",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
28 changes: 28 additions & 0 deletions src/app/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter, Router } from '@angular/router';
import { App } from './app';
import { KeyboardShortcutService } from './shared/keyboard-shortcut.service';

@Component({ template: '' })
class StubThought {}
Expand Down Expand Up @@ -65,4 +66,31 @@ describe('App', () => {
expect(reader.classList.contains('thoughts-reader--open')).toBe(false);
});
});

describe('global keyboard shortcuts', () => {
const press = (init: KeyboardEventInit) => {
const event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, ...init });
document.dispatchEvent(event);
return event;
};

it('opens Spotlight on one ⌃⌥Space (each keydown is handled exactly once)', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const shortcuts = TestBed.inject(KeyboardShortcutService);

press({ code: 'Space', key: ' ', ctrlKey: true, altKey: true });

expect(shortcuts.spotlightOpen()).toBe(true);
});

it('leaves ⌘Space to the browser and macOS', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();

const event = press({ code: 'Space', key: ' ', metaKey: true });

expect(event.defaultPrevented).toBe(false);
});
});
});
16 changes: 10 additions & 6 deletions src/app/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgComponentOutlet } from '@angular/common';
import { Component, effect, HostListener, inject, viewChild } from '@angular/core';
import { Component, effect, inject, viewChild } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { filter, map } from 'rxjs';
Expand Down Expand Up @@ -32,6 +32,10 @@ import { WindowManagerService } from './window-manager/window-manager.service';
],
templateUrl: './app.html',
styleUrl: './app.css',
// [ng-03 templates] Event binding on the host, or here on `document`.
// Preferred over @HostListener: it's plain metadata, it's type-checked
// against the class, and it's the style the Angular team now recommends.
host: { '(document:keydown)': 'onKeydown($event)' },
})
export class App {
protected readonly launcher = inject(AppLauncherService);
Expand Down Expand Up @@ -76,17 +80,17 @@ export class App {
});
}

@HostListener('document:keydown', ['$event'])
// [ng-03 templates] Bound through `host: { '(document:keydown)': … }` above.
// This used to call handleKeydown twice, so every toggle shortcut flipped
// and flipped back: ⌃⌥Space never opened Spotlight. It also still
// preventDefault()ed ⌘Space, which the 1.3.4 remap meant to hand back to
// the browser. One event, one handler call.
onKeydown(event: KeyboardEvent): void {
if (event.key === 'Escape' && this.onThoughtsRoute()) {
this.closeThoughts();
return;
}
this.shortcuts.handleKeydown(event);
if (event.metaKey && event.code === 'Space') {
event.preventDefault();
}
this.shortcuts.handleKeydown(event);
}

toggleSpotlight(): void {
Expand Down
75 changes: 75 additions & 0 deletions src/app/thoughts-content/lessons/lesson-03-templates.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import * as axeMatchers from 'vitest-axe/matchers';
import { axe } from '../../../test/a11y';
import { LESSON_PAGES } from './lessons';
import { Lesson03Templates } from './lesson-03-templates';

expect.extend(axeMatchers);

describe('Lesson03Templates', () => {
let fixture: ComponentFixture<Lesson03Templates>;
let el: HTMLElement;

const click = async (selector: string) => {
el.querySelector<HTMLButtonElement>(selector)!.click();
await fixture.whenStable();
};

beforeEach(async () => {
await TestBed.configureTestingModule({ imports: [Lesson03Templates] }).compileComponents();
fixture = TestBed.createComponent(Lesson03Templates);
fixture.detectChanges();
el = fixture.nativeElement as HTMLElement;
});

it('is registered as the lesson page for its thought', () => {
expect(LESSON_PAGES['angular-03-templates']).toBeDefined();
});

it('teaches at three levels, then pitfalls and interview questions', () => {
const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim());
expect(headings).toEqual(
expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']),
);
});

describe('property vs attribute demo', () => {
let probe: HTMLInputElement;

beforeEach(() => {
probe = el.querySelector<HTMLInputElement>('#binding-probe')!;
probe.value = 'typed by hand';
probe.dispatchEvent(new Event('input'));
});

it('[attr.value] changes the attribute but not what the box shows once typed in', async () => {
await click('#set-attribute');
expect(probe.getAttribute('value')).toContain('attribute');
expect(probe.value).toBe('typed by hand');
});

it('[value] changes what the box shows', async () => {
await click('#set-property');
expect(probe.value).toContain('property');
});
});

describe('control flow demo', () => {
it('removes a tag and switches the summary as the count changes', async () => {
const summary = () => el.querySelector('#tag-summary')?.textContent ?? '';
expect(summary()).toContain('3 tags');

await click('.tag-remove');
await click('.tag-remove');
expect(summary()).toContain('One tag');

await click('.tag-remove');
expect(summary()).toContain('No tags');
expect(el.querySelector('.tag-list')?.textContent).toContain('All gone');
});
});

it('has no axe violations', async () => {
expect(await axe(el)).toHaveNoViolations();
});
});
Loading
Loading