XetaIO /
Xetaravel
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Xetaravel\View\Components; |
||
| 6 | |||
| 7 | use Closure; |
||
| 8 | use Illuminate\Contracts\View\View; |
||
| 9 | use Illuminate\View\Component; |
||
| 10 | |||
| 11 | class Markdown extends Component |
||
| 12 | { |
||
| 13 | public string $uuid; |
||
| 14 | |||
| 15 | public string $uploadUrl = ''; |
||
| 16 | |||
| 17 | public function __construct( |
||
| 18 | public ?string $value = null, |
||
| 19 | public ?string $label = null, |
||
| 20 | public ?string $hint = null, |
||
| 21 | public ?string $hintClass = 'fieldset-label', |
||
| 22 | public ?string $disk = 'public', |
||
| 23 | public ?string $folder = 'markdown', |
||
| 24 | public ?array $config = [], |
||
| 25 | |||
| 26 | // Validations |
||
| 27 | public ?string $errorClass = 'text-error', |
||
| 28 | public ?bool $omitError = false, |
||
| 29 | public ?bool $firstErrorOnly = false, |
||
| 30 | ) { |
||
| 31 | $this->uuid = md5(serialize($this)); |
||
| 32 | //$this->uploadUrl = route('upload', absolute: false); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function setup(): string |
||
| 36 | { |
||
| 37 | $setup = array_merge([ |
||
| 38 | 'spellChecker' => false, |
||
| 39 | 'autoSave' => false, |
||
| 40 | 'uploadImage' => false, |
||
| 41 | 'imageAccept' => 'image/png, image/jpeg', |
||
| 42 | 'toolbar' => [ |
||
| 43 | 'heading', 'bold', 'italic', 'strikethrough', '|', |
||
| 44 | 'code', 'quote', 'unordered-list', 'ordered-list', 'horizontal-rule', '|', |
||
| 45 | 'link', 'table', '|', |
||
| 46 | 'preview', 'side-by-side' |
||
| 47 | ], |
||
| 48 | //'forceSync' => true |
||
| 49 | ], $this->config); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 50 | |||
| 51 | // Table default CSS class `.table` breaks the layout. |
||
| 52 | // Here is a workaround |
||
| 53 | $table = "{ 'title' : 'Table', 'name' : 'myTable', 'action' : EasyMDE.drawTable, 'className' : 'fa fa-table' }"; |
||
| 54 | |||
| 55 | return str(json_encode($setup)) |
||
| 56 | ->replace("\"", "'") |
||
| 57 | ->trim('{}') |
||
| 58 | ->replace("'table'", $table) |
||
| 59 | ->toString(); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function modelName(): ?string |
||
| 63 | { |
||
| 64 | return $this->attributes->whereStartsWith('wire:model')->first(); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function errorFieldName(): ?string |
||
| 68 | { |
||
| 69 | return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first(); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the view / contents that represent the component. |
||
| 74 | */ |
||
| 75 | public function render(): View|Closure|string |
||
| 76 | { |
||
| 77 | return view('components.markdown'); |
||
| 78 | } |
||
| 79 | } |
||
| 80 |