optimize drag'n'drop

This commit is contained in:
2026-03-11 12:08:34 +01:00
parent 68a257e2bd
commit 03fb395605
4 changed files with 64 additions and 5 deletions

View File

@@ -31,13 +31,13 @@
@if (showSongs && !useSwiper) { @if (showSongs && !useSwiper) {
<div (cdkDropListDropped)="drop($event, show)" <div (cdkDropListDropped)="drop($event, show)"
[cdkDropListDisabled]="show.published || showText" [cdkDropListDisabled]="show.published || showText"
[style.cursor]="!(show.published || showText) ? 'drag' : 'inherit'"
[style.font-size]="textSize + 'em'" [style.font-size]="textSize + 'em'"
cdkDropList cdkDropList
class="song-list"> class="song-list">
@for (song of orderedShowSongs(show); track trackBy(i, song); let i = $index) { @for (song of orderedShowSongs(show); track trackBy(i, song); let i = $index) {
<div cdkDrag class="song-row"> <div cdkDrag class="song-row">
<app-song <app-song
[dragHandle]="!(show.published || showText)"
[fullscreen]="useSwiper" [fullscreen]="useSwiper"
[index]="i" [index]="i"
[showId]="showId" [showId]="showId"

View File

@@ -8,6 +8,14 @@
} }
@if (!show.published && !fullscreen) { @if (!show.published && !fullscreen) {
<div class="song"> <div class="song">
@if (dragHandle && !edit) {
<button
aria-label="Lied verschieben"
cdkDragHandle
class="drag-handle"
type="button"
></button>
}
<span class="title">{{ iSong.title }}</span> <span class="title">{{ iSong.title }}</span>
@if (!edit) { @if (!edit) {
<div class="keys-container"> <div class="keys-container">
@@ -30,7 +38,9 @@
</div> </div>
@if (!edit) { @if (!edit) {
<div aria-hidden="true" class="song select"> <div aria-hidden="true" class="song select">
<span></span> @if (dragHandle) {
<span class="drag-handle-placeholder"></span>
}
<span> <mat-form-field class="keys-select"> <span> <mat-form-field class="keys-select">
<mat-select #option [formControl]="keyFormControl" tabIndex="-1"> <mat-select #option [formControl]="keyFormControl" tabIndex="-1">
@for (key of keys; track key) { @for (key of keys; track key) {

View File

@@ -5,11 +5,11 @@
} }
display: grid; display: grid;
grid-template-columns: auto 70px 25px 25px; grid-template-columns: 24px auto 70px 25px 25px;
@media screen and (max-width: 860px) { @media screen and (max-width: 860px) {
grid-template-columns: auto 70px 45px 45px; grid-template-columns: 24px auto 70px 45px 45px;
} }
grid-template-areas: "title keys edit delete"; grid-template-areas: "drag title keys edit delete";
& > * { & > * {
display: flex; display: flex;
@@ -19,6 +19,51 @@
overflow: hidden; overflow: hidden;
} }
.drag-handle,
.drag-handle-placeholder {
grid-area: drag;
}
.drag-handle {
width: 16px;
height: 36px;
padding: 4px 0;
border: 0;
background: transparent;
cursor: grab;
justify-self: start;
position: relative;
&::before {
content: "";
width: 10px;
height: 18px;
display: block;
border-radius: 999px;
background-image: radial-gradient(circle, var(--text-soft) 1.2px, transparent 1.3px),
radial-gradient(circle, var(--text-soft) 1.2px, transparent 1.3px);
background-position: 0 0, 6px 0;
background-size: 6px 6px;
background-repeat: repeat-y;
opacity: 0.65;
transition: var(--transition);
}
&:hover::before {
opacity: 1;
background-image: radial-gradient(circle, var(--primary-color) 1.2px, transparent 1.3px),
radial-gradient(circle, var(--primary-color) 1.2px, transparent 1.3px);
}
&:active {
cursor: grabbing;
}
}
.drag-handle-placeholder {
width: 16px;
}
.keys-container { .keys-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -59,6 +104,7 @@
.title { .title {
grid-area: title; grid-area: title;
min-width: 0;
&.published { &.published {
margin: 10px 0; margin: 10px 0;

View File

@@ -17,6 +17,7 @@ import {MatInput} from '@angular/material/input';
import {CdkTextareaAutosize} from '@angular/cdk/text-field'; import {CdkTextareaAutosize} from '@angular/cdk/text-field';
import {ButtonRowComponent} from '../../../../widget-modules/components/button-row/button-row.component'; import {ButtonRowComponent} from '../../../../widget-modules/components/button-row/button-row.component';
import {ButtonComponent} from '../../../../widget-modules/components/button/button.component'; import {ButtonComponent} from '../../../../widget-modules/components/button/button.component';
import {CdkDragHandle} from '@angular/cdk/drag-drop';
@Component({ @Component({
selector: 'app-song', selector: 'app-song',
@@ -36,6 +37,7 @@ import {ButtonComponent} from '../../../../widget-modules/components/button/butt
ButtonRowComponent, ButtonRowComponent,
ButtonComponent, ButtonComponent,
SongTextComponent, SongTextComponent,
CdkDragHandle,
], ],
}) })
export class SongComponent implements OnInit { export class SongComponent implements OnInit {
@@ -44,6 +46,7 @@ export class SongComponent implements OnInit {
@Input() public show: Show | null = null; @Input() public show: Show | null = null;
@Input() public showId: string | null = null; @Input() public showId: string | null = null;
@Input() public showText: boolean | null = null; @Input() public showText: boolean | null = null;
@Input() public dragHandle = false;
@Input() public index = -1; @Input() public index = -1;
@Input() public fullscreen = false; @Input() public fullscreen = false;
public keys: string[] = []; public keys: string[] = [];