【Laravel Prompts】そろそろ出てきそうな全選択機能

Laravel

Laravel11の公式パッケージ Promptsで提案されている全選択機能(仮名)がそろそろ出てきそうです。

※2024/05/27(月)無事、マージされました。

※今週中にv0.1.23としてリリースされると思います。

※2024/05/29(火)、v0.1.23 としてリリースされました。

Allow selecting all options in a `multiselect` by duncanmcclean · Pull Request #147 · laravel/prompts
Currently, when using the multiselect component, if you want to select all of the available options, you have to manuall...

※「全選択機能」は筆者が勝手に付けている仮名です。

multiselect で選択肢を全選択/全解除する機能です。

最初のPRでは、選択肢の最上部に表示される「All」を選択することで全選択/全解除をするようになっていました。

が、レビュアーのJess Archer氏が「これは実にクールだが、Allが選択内容に含まれるのは。。」のようなニュアンスのことを言っており、

筆者がヨコヤリで提案した[Ctrl]+[A]で機能するように変更されました。

※いや、PRしたDuncan McClean氏(Statamicの作者)も最初はそうしたいと思っていたけど、[Ctrl]+[A]が既に別のキーバインドで使われているので諦めていた模様。きっと誰もが最初はそうしたいと思うことでしょう。

こちらは勝手なことを言ってるだけですみませぬ。

まだmultisearchでの挙動について調整段階ですが、

最終段階に来ているものと思われます。

Duncan McClean氏は忙しい中、スキマ時間で対応しているようです。

Jess Archer氏も 忙しい中、「猫の手が欲しいなら多分オレも手伝えるぜ!」みたいなことを言っています。

早ければ来週辺りににはマージ&リリースされるかも知れません。(勝手な推測)

変更内容をローカルで実装してみました

PR内容のリポジトリをcloneしてきて、

ローカルのLaravel11プロジェクト内の vendor/laravel/prompts/ 以下を、

先にcloneしてきた内容で丸ごと置き換え、

そこにレビュアーの提案内容を反映してから、

artisanコマンドを作成して動かしてみました。

php artisan make:command SelectAll

▼app/Console/Commands/SelectAll.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use function Laravel\Prompts\multiselect;

class SelectAll extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'select:all';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $result = multiselect(
            label: 'Select your favourite Laravel packages',
            options: [
                'laravel/prompts',
                'laravel/pulse',
                'laravel/horizon',
                'laravel/octane',
                'laravel/jetstream',
            ],
            //canSelectAll: true, 👈このオプションはもはや不要です。
        );
        var_dump($result);
    }
}

▼実行

php artisan select:all

実際の動きは、次の動画のようになります。

コメント

タイトルとURLをコピーしました