Tastenkürzel-Plugin

Das Tastenkürzel-Plugin aktiviert globale Tastaturbefehle für Navigation, Terminverwaltung und Zwischenablage.

Installation

Installieren Sie das Plugin-Paket:

npm install @dayflow/plugin-keyboard-shortcuts
pnpm add @dayflow/plugin-keyboard-shortcuts
yarn add @dayflow/plugin-keyboard-shortcuts
bun add @dayflow/plugin-keyboard-shortcuts

Verwendung

import { useCalendarApp, DayFlowCalendar } from '@dayflow/react';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

function MyCalendar() {
  const calendar = useCalendarApp({
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      }),
    ],
  });

  return <DayFlowCalendar calendar={calendar} />;
}
<template>
  <DayFlowCalendar :calendar="calendar" />
</template>

<script setup>
import { DayFlowCalendar, useCalendarApp } from '@dayflow/vue';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

const calendar = useCalendarApp({
  views: [
    /* your views */
  ],
  plugins: [
    createKeyboardShortcutsPlugin({
      // Optional configuration
    }),
  ],
});
</script>
import { Component } from '@angular/core';
import { DayFlowCalendarModule } from '@dayflow/angular';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [DayFlowCalendarModule],
  template: `<dayflow-calendar [calendar]="calendar"></dayflow-calendar>`
})
export class AppComponent {
  calendar = {
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      })
    ]
  };
}
<script>
  import { DayFlowCalendar, useCalendarApp } from '@dayflow/svelte';
  import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

  const calendar = useCalendarApp({
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      }),
    ],
  });
</script>

<DayFlowCalendar {calendar} />

Standard-Tastenkürzel

AktionTaste (Mac)Taste (Windows/Linux)
Zu heute springenCmd + TCtrl + T
SuchenCmd + FCtrl + F
Neuer TerminCmd + NCtrl + N
NavigationArrowLeft / ArrowRightArrowLeft / ArrowRight
Termine durchtabbenTab / Shift + TabTab / Shift + Tab
RückgängigCmd + ZCtrl + Z
WiederholenCmd + Shift + Z / Cmd + YCtrl + Y
Termin kopierenCmd + CCtrl + C
Termin ausschneidenCmd + XCtrl + X
Termin einfügenCmd + VCtrl + V
Termin löschenBackspace / DeleteBackspace / Delete
Dialoge und Panels schließenEscEsc

Konfiguration

Sie können die Tastenbelegung anpassen und für jede Aktion eigene Callbacks hinterlegen:

createKeyboardShortcutsPlugin({
  keyMap: {
    today: 't',
    search: 'f',
    prev: 'ArrowLeft',
    next: 'ArrowRight',
    undo: 'z',
    redo: 'y',
    delete: 'Delete',
    newEvent: 'n',
  },
  callbacks: {
    undo: app => {
      console.log('Custom undo logic');
      app.undo();
    },
    redo: app => {
      console.log('Custom redo logic');
      if (app.redo) app.redo();
    },
    delete: app => {
      if (confirm('Are you sure?')) {
        const selectedId = app.state.selectedEventId;
        if (selectedId) app.deleteEvent(selectedId);
      }
    },
  },
});

Verfügbare Callbacks

Im Objekt callbacks werden folgende Einträge unterstützt:

  • undo, redo, paste (erhalten app)
  • copy, cut, delete (erhalten app und event?: Event)
  • today, search, prev, next, newEvent, dismiss (erhalten app)
  • tab (erhält app und reverse: boolean)

Plugin-API

Über den Plugin-Handle steuern Sie die Verarbeitung der Tastenkürzel zur Laufzeit:

import { type KeyboardShortcutsService } from '@dayflow/plugin-keyboard-shortcuts';

const kb = app.getPlugin<KeyboardShortcutsService>('keyboard-shortcuts');

KeyboardShortcutsService

MethodeRückgabeBeschreibung
enable()voidAktiviert die Verarbeitung der Tastenkürzel wieder
disable()voidUnterdrückt alle Tastenkürzel, bis enable() aufgerufen wird
isEnabled()booleanGibt zurück, ob die Tastenkürzel gerade aktiv sind

Ein typischer Anwendungsfall ist, die Kalender-Tastenkürzel zu unterdrücken, solange ein eigenes Modal oder ein Rich-Text-Editor geöffnet ist:

function MyModal() {
  const kb = app.getPlugin<KeyboardShortcutsService>('keyboard-shortcuts');

  useEffect(() => {
    kb?.disable();
    return () => kb?.enable(); // restore on unmount
  }, []);

  // ...
}

Sie können auch jede geöffnete Oberfläche programmgesteuert schließen:

app.dismissUI();

Auf dieser Seite