キーボードショートカットプラグイン

キーボードショートカット (Keyboard Shortcuts) プラグインは、ナビゲーション、イベント管理、およびクリップボード操作のためのグローバルなキーボードコントロールを可能にします。

インストール

プラグインパッケージをインストールします:

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

使い方

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

function MyCalendar() {
  const calendar = useCalendarApp({
    // ...
    plugins: [
      createKeyboardShortcutsPlugin({
        // オプション設定
      }),
    ],
  });

  return <DayFlowCalendar calendar={calendar} />;
}

デフォルトのショートカット

操作キー (Mac)キー (Windows/Linux)
今日に移動Cmd + TCtrl + T
検索Cmd + FCtrl + F
新規イベントCmd + NCtrl + N
ナビゲーションArrowLeft / ArrowRightArrowLeft / ArrowRight
イベントのタブ移動Tab / Shift + TabTab / Shift + Tab
元に戻すCmd + ZCtrl + Z
やり直しCmd + Shift + Z / Cmd + YCtrl + Y
イベントをコピーCmd + CCtrl + C
イベントを切り取りCmd + XCtrl + X
イベントを貼り付けCmd + VCtrl + V
イベントを削除Backspace / DeleteBackspace / Delete
ダイアログ/パネルを閉じるEscEsc

設定

キーマッピングをカスタマイズしたり、各アクションにカスタムコールバックを提供したりできます:

createKeyboardShortcutsPlugin({
  keyMap: {
    today: 't',
    search: 'f',
    prev: 'ArrowLeft',
    next: 'ArrowRight',
    undo: 'z',
    redo: 'y',
    delete: 'Delete',
    newEvent: 'n',
  },
  callbacks: {
    undo: app => {
      console.log('カスタムの元に戻すロジック');
      app.undo();
    },
    redo: app => {
      console.log('カスタムのやり直しロジック');
      if ((app as any).redo) (app as any).redo();
    },
    delete: app => {
      if (confirm('本当に削除しますか?')) {
        const selectedId = app.state.selectedEventId;
        if (selectedId) app.deleteEvent(selectedId);
      }
    },
  },
});

利用可能なコールバック

callbacks オブジェクトでは以下のコールバックがサポートされています:

  • undo, redo, paste (app を受け取ります)
  • copy, cut, delete (appevent?: Event を受け取ります)
  • today, search, prev, next, newEvent, dismiss (app を受け取ります)
  • tab (appreverse: boolean を受け取ります)

プラグイン API

プラグインハンドルを取得して、実行時にショートカットの動作を制御できます:

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

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

KeyboardShortcutsService

メソッド返り値説明
enable()voidショートカット処理を再有効化する
disable()voidenable() が呼ばれるまで全ショートカットを抑制する
isEnabled()booleanショートカットが現在有効かどうかを返す

よくある使用例として、カスタムモーダルやリッチテキストエディタが開いている間、カレンダーのショートカットを一時的に抑制する場合があります:

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

  useEffect(() => {
    kb?.disable();
    return () => kb?.enable(); // アンマウント時に復元
  }, []);

  // ...
}

プログラムから開いている UI を閉じることもできます:

app.dismissUI();

On this page