MathEditor.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Filament\Fields;
  3. use Filament\Forms\Components\Textarea;
  4. use Filament\Support\Enums\FontFamily;
  5. use Illuminate\Support\Js;
  6. class MathEditor extends Textarea
  7. {
  8. protected string $view = 'filament.fields.math-editor';
  9. protected int $columns = 12;
  10. protected function setUp(): void
  11. {
  12. parent::setUp();
  13. $this->columnSpan('full');
  14. $this->rows(8);
  15. $this->fontFamily(FontFamily::Mono);
  16. $this->placeholder('Enter LaTeX code here... e.g., $f(x) = ax^2 + bx + c$');
  17. $this->helperText('Supported formats: $...$, $$...$$, \(...\), \[...\]');
  18. }
  19. public function columns(int $columns): static
  20. {
  21. $this->columns = $columns;
  22. return $this;
  23. }
  24. public function getColumns(): int
  25. {
  26. return $this->columns;
  27. }
  28. public static function getPreview(string $value): ?string
  29. {
  30. if (empty($value)) {
  31. return null;
  32. }
  33. // 简单预览:不渲染 LaTeX,仅显示原始内容
  34. return $value;
  35. }
  36. }