replace EditorLanguages with filaments Language

This commit is contained in:
Boy132 2025-09-02 09:54:46 +02:00
parent 9427015735
commit 2b2aace872
2 changed files with 29 additions and 144 deletions

View File

@ -1,141 +0,0 @@
<?php
namespace App\Enums;
use Filament\Support\Contracts\HasLabel;
enum EditorLanguages: string implements HasLabel
{
case plaintext = 'plaintext';
case abap = 'abap';
case apex = 'apex';
case azcali = 'azcali';
case bat = 'bat';
case bicep = 'bicep';
case cameligo = 'cameligo';
case coljure = 'coljure';
case coffeescript = 'coffeescript';
case c = 'c';
case cpp = 'cpp';
case csharp = 'csharp';
case csp = 'csp';
case css = 'css';
case cypher = 'cypher';
case dart = 'dart';
case dockerfile = 'dockerfile';
case ecl = 'ecl';
case elixir = 'elixir';
case flow9 = 'flow9';
case fsharp = 'fsharp';
case go = 'go';
case graphql = 'graphql';
case handlebars = 'handlebars';
case hcl = 'hcl';
case html = 'html';
case ini = 'ini';
case java = 'java';
case javascript = 'javascript';
case julia = 'julia';
case json = 'json';
case kotlin = 'kotlin';
case less = 'less';
case lexon = 'lexon';
case lua = 'lua';
case liquid = 'liquid';
case m3 = 'm3';
case markdown = 'markdown';
case mdx = 'mdx';
case mips = 'mips';
case msdax = 'msdax';
case mysql = 'mysql';
case objectivec = 'objective-c';
case pascal = 'pascal';
case pascaligo = 'pascaligo';
case perl = 'perl';
case pgsql = 'pgsql';
case php = 'php';
case pla = 'pla';
case postiats = 'postiats';
case powerquery = 'powerquery';
case powershell = 'powershell';
case proto = 'proto';
case pug = 'pug';
case python = 'python';
case qsharp = 'qsharp';
case r = 'r';
case razor = 'razor';
case redis = 'redis';
case redshift = 'redshift';
case restructuredtext = 'restructuredtext';
case ruby = 'ruby';
case rust = 'rust';
case sb = 'sb';
case scala = 'scala';
case scheme = 'scheme';
case scss = 'scss';
case shell = 'shell';
case sol = 'sol';
case aes = 'aes';
case sparql = 'sparql';
case sql = 'sql';
case st = 'st';
case swift = 'swift';
case systemverilog = 'systemverilog';
case verilog = 'verilog';
case tcl = 'tcl';
case twig = 'twig';
case typescript = 'typescript';
case typespec = 'typespec';
case vb = 'vb';
case wgsl = 'wgsl';
case xml = 'xml';
case yaml = 'yaml';
public static function fromWithAlias(string $match): self
{
return match ($match) {
'h' => self::c,
'cc', 'hpp' => self::cpp,
'cs' => self::csharp,
'class' => self::java,
'htm' => self::html,
'js', 'mjs', 'cjs' => self::javascript,
'kt', 'kts' => self::kotlin,
'md' => self::markdown,
'm' => self::objectivec,
'pl', 'pm' => self::perl,
'php3', 'php4', 'php5', 'phtml' => self::php,
'py', 'pyc', 'pyo', 'pyi' => self::python,
'rdata', 'rds' => self::r,
'rb', 'erb' => self::ruby,
'sc' => self::scala,
'sh', 'zsh' => self::shell,
'ts', 'tsx' => self::typescript,
'yml' => self::yaml,
default => self::tryFrom($match) ?? self::plaintext,
};
}
public function getLabel(): string
{
return $this->name;
}
}

View File

@ -3,7 +3,6 @@
namespace App\Filament\Server\Resources\Files\Pages; namespace App\Filament\Server\Resources\Files\Pages;
use Throwable; use Throwable;
use App\Enums\EditorLanguages;
use App\Exceptions\Http\Server\FileSizeTooLargeException; use App\Exceptions\Http\Server\FileSizeTooLargeException;
use App\Exceptions\Repository\FileNotEditableException; use App\Exceptions\Repository\FileNotEditableException;
use App\Facades\Activity; use App\Facades\Activity;
@ -17,6 +16,7 @@ use App\Traits\Filament\CanCustomizeHeaderWidgets;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Forms\Components\CodeEditor; use Filament\Forms\Components\CodeEditor;
use Filament\Forms\Components\CodeEditor\Enums\Language;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
@ -124,9 +124,35 @@ class EditFiles extends Page
->label(trans('server/file.actions.new_file.syntax')) ->label(trans('server/file.actions.new_file.syntax'))
->searchable() ->searchable()
->live() ->live()
->options(EditorLanguages::class) ->options(Language::class)
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->default(fn () => EditorLanguages::fromWithAlias(pathinfo($this->path, PATHINFO_EXTENSION))), ->default(fn () => match (pathinfo($this->path, PATHINFO_EXTENSION)) {
'cc', 'hpp' => Language::Cpp,
'css', 'scss' => Language::Css,
'go' => Language::Go,
'html' => Language::Html,
'class', 'kt', 'kts' => Language::Java,
'js', 'mjs', 'cjs', 'ts', 'tsx' => Language::JavaScript,
'json', 'json5' => Language::Json,
'md' => Language::Markdown,
'php3', 'php4', 'php5', 'phtml', 'php' => Language::Php,
'py', 'pyc', 'pyo', 'pyi' => Language::Python,
'xml' => Language::Xml,
'yml', 'yaml' => Language::Yaml,
default => null,
}),
CodeEditor::make('editor') CodeEditor::make('editor')
->hiddenLabel() ->hiddenLabel()
->default(function () { ->default(function () {