Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update control flow syntax #101

Merged
merged 1 commit into from
Dec 17, 2023
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
6 changes: 1 addition & 5 deletions apps/e2e/karma-ci.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = function (config) {
require('../../karma.conf')(
config,
require('path').join(__dirname, '../../coverage/e2e'),
true
);
require('../../karma.conf')(config, 'e2e', true);
};
6 changes: 1 addition & 5 deletions apps/e2e/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = function (config) {
require('../../karma.conf')(
config,
require('path').join(__dirname, '../../coverage/e2e'),
false
);
require('../../karma.conf')(config, 'e2e', false);
};
16 changes: 9 additions & 7 deletions apps/e2e/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<nav>
<ul>
<ng-container *ngFor="let rootRoutes of routes">
<ng-container *ngFor="let route of rootRoutes">
<li *ngIf="route.title">
<a routerLink="{{ route.path }}">{{ route.title }}</a>
</li>
</ng-container>
</ng-container>
@for (rootRoutes of routes; track rootRoutes) {
@for (route of rootRoutes; track route.path) {
@if (route.title) {
<li>
<a routerLink="{{ route.path }}">{{ route.title }}</a>
</li>
}
}
}
</ul>
</nav>
<main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ <h1>Keyboard Sort Example With Handles</h1>
kbdSortListOrientation="vertical"
[cdkDropListData]="items"
[kbdSortListData]="items">
<li
*ngFor="let item of items; index as i; trackBy: trackByFn"
cdkDrag
cdkDragLockAxis="y"
[kbdSortItem]="i">
<div class="handle" kbdSortHandle>{{ item }}</div>
<div class="placeholder">🐶</div>
<span *kbdSortKeyboardSortItemIfActive>😇 active!</span>
<span *kbdSortKeyboardSortItemIfFocused>😊 focused.</span>
</li>
@for (item of items; track item; let i = $index) {
<li cdkDrag cdkDragLockAxis="y" [kbdSortItem]="i">
<div class="handle" kbdSortHandle>{{ item }}</div>
<div class="placeholder">🐶</div>
<span *kbdSortKeyboardSortItemIfActive>😇 active!</span>
<span *kbdSortKeyboardSortItemIfFocused>😊 focused.</span>
</li>
}
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export class ExampleWithHandlesComponent {
public drop($event: CdkDragDrop<string[]>) {
moveItemInArray(this.items, $event.previousIndex, $event.currentIndex);
}

protected trackByFn = (_: number, item: string) => item;
}

export default ExampleWithHandlesComponent;
24 changes: 11 additions & 13 deletions apps/e2e/src/app/example/example.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ <h1>Keyboard Sort Example</h1>
kbdSortListOrientation="horizontal"
[cdkDropListData]="items"
[kbdSortListData]="items">
<li
*ngFor="let item of items; index as i; trackBy: trackByFn"
cdkDrag
cdkDragLockAxis="x"
[kbdSortItem]="i">
{{ item }}
<span *kbdSortKeyboardSortItemIfActive class="indicator active-indicator"
>🤌</span
>
<span *kbdSortKeyboardSortItemIfFocused class="indicator focus-indicator"
>🫴</span
>
</li>
@for (item of items; track item; let i = $index) {
<li cdkDrag cdkDragLockAxis="x" [kbdSortItem]="i">
{{ item }}
<span *kbdSortKeyboardSortItemIfActive class="indicator active-indicator"
>🤌</span
>
<span *kbdSortKeyboardSortItemIfFocused class="indicator focus-indicator"
>🫴</span
>
</li>
}
</ul>
2 changes: 0 additions & 2 deletions apps/e2e/src/app/example/example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export class ExampleComponent {
public drop($event: CdkDragDrop<string[]>) {
moveItemInArray(this.items, $event.previousIndex, $event.currentIndex);
}

protected trackByFn = (_: number, item: string) => item;
}

export default ExampleComponent;
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (config, coverageDir, isCi) {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: coverageDir,
dir: __dirname + '/coverage/' + coverageDir,
subdir: '.',
reporters: isCi
? [{ type: 'text' }]
Expand Down
6 changes: 1 addition & 5 deletions libs/ng-keyboard-sort/karma-ci.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = function (config) {
require('../../karma.conf')(
config,
require('path').join(__dirname, '../../coverage/ng-keyboard-sort'),
true
);
require('../../karma.conf')(config, 'ng-keyboard-sort', true);
};
6 changes: 1 addition & 5 deletions libs/ng-keyboard-sort/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = function (config) {
require('../../karma.conf')(
config,
require('path').join(__dirname, '../../coverage/ng-keyboard-sort'),
false
);
require('../../karma.conf')(config, 'ng-keyboard-sort', false);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import { KeyboardSortEventDrop } from '../keyboard-sort-event-drop';
[kbdSortListOrientation]="direction"
[kbdSortListDisabled]="disabled"
(kdbSortDrop)="sortDrop($event)">
<li
*ngFor="let item of data || []; index as i; trackBy: trackByFn"
[kbdSortItem]="i"
[attr.id]="'item-' + i">
{{ item }}
<span *kbdSortKeyboardSortItemIfActive>{{ ' ' }}Active</span>
<span *kbdSortKeyboardSortItemIfFocused>{{ ' ' }}Focused</span>
</li>
@for (item of data || []; track item; let i = $index) {
<li [kbdSortItem]="i" [attr.id]="'item-' + i">
{{ item }}
<span *kbdSortKeyboardSortItemIfActive>{{ ' ' }}Active</span>
<span *kbdSortKeyboardSortItemIfFocused>{{ ' ' }}Focused</span>
</li>
}
</ul>
<div>
<button (click)="activateLastItem()">Activate last item</button>
Expand All @@ -55,6 +54,4 @@ export class KeyboardSortListFixtureComponent {
public sortDrop($event: KeyboardSortEventDrop) {
this.drops.push($event);
}

protected trackByFn = (_: number, item: string) => item;
}
22 changes: 7 additions & 15 deletions libs/ng-keyboard-sort/src/lib/keyboard-sort-item.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Output,
QueryList,
} from '@angular/core';
import { concatWith, of, Subscription } from 'rxjs';
import { Subscription } from 'rxjs';
import { KeyboardSortHandleDirective } from './keyboard-sort-handle.directive';
import { KeyboardSortListService } from './keyboard-sort-list.service';
import { KeyboardSortItemService } from './keyboard-sort-item.service';
Expand Down Expand Up @@ -50,11 +50,13 @@ export class KeyboardSortItemDirective
return this.#activated;
}
public set activated(value: boolean) {
if (value && this.focused) {
this.focused = false;
if (this.#activated !== value) {
if (value && this.focused) {
this.focused = false;
}
this.#activated = value;
this.kbdSortItemActivated.emit(value);
}
this.#activated = value;
this.kbdSortItemActivated.emit(value);
}

public get focused(): boolean {
Expand Down Expand Up @@ -102,7 +104,6 @@ export class KeyboardSortItemDirective
#kbdSortItemDisabled = false;
#activated = false;
#focused = false;
#hasHandles = false;

constructor() {
this.#itemService.item = this;
Expand All @@ -112,15 +113,6 @@ export class KeyboardSortItemDirective
if (this.activated) {
this.activated = true;
}
if (this.handles) {
this.#subscriptions.add(
of(this.handles)
.pipe(concatWith(this.handles.changes))
.subscribe((handles: QueryList<KeyboardSortHandleDirective>) => {
this.#hasHandles = handles.length > 0;
})
);
}
}

public ngOnDestroy(): void {
Expand Down
10 changes: 2 additions & 8 deletions libs/ng-keyboard-sort/src/lib/keyboard-sort-list.directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
AfterViewInit,
ApplicationRef,
ChangeDetectorRef,
ContentChildren,
Directive,
Expand Down Expand Up @@ -57,7 +56,6 @@ export class KeyboardSortListDirective
@Output()
public readonly kdbSortDrop = new EventEmitter<KeyboardSortEventDrop>();

readonly #appRef = inject(ApplicationRef);
readonly #changeDetectorRef = inject(ChangeDetectorRef);
#focusKeyManager: FocusKeyManager<KeyboardSortItemDirective> | undefined;
readonly #focusMonitor = inject(FocusMonitor);
Expand Down Expand Up @@ -193,12 +191,8 @@ export class KeyboardSortListDirective
public deactivateAll(except?: number): void {
this.items?.forEach((item) => {
if (item.position !== except) {
if (item.activated) {
item.activated = false;
}
if (item.focused) {
item.focused = false;
}
item.activated = false;
item.focused = false;
}
});
}
Expand Down
Loading