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

キーボードショートカット (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 } from '@dayflow/core';
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

UI をプログラムから閉じることができます:

calendar.app.dismissUI();

On this page