1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\View\Components; |
4
|
|
|
|
5
|
|
|
class Wysiwyg extends TwillFormComponent |
6
|
|
|
{ |
7
|
|
|
public $translated; |
8
|
|
|
public $required; |
9
|
|
|
public $maxlength; |
10
|
|
|
public $options; |
11
|
|
|
public $placeholder; |
12
|
|
|
public $note; |
13
|
|
|
public $disabled; |
14
|
|
|
public $readonly; |
15
|
|
|
public $editSource; |
16
|
|
|
public $toolbarOptions; |
17
|
|
|
public $inModal; |
18
|
|
|
public $hideCounter; |
19
|
|
|
public $type; |
20
|
|
|
public $limitHeight; |
21
|
|
|
public $syntax; |
22
|
|
|
public $customTheme; |
23
|
|
|
public $customOptions; |
24
|
|
|
public $default; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
$name, |
28
|
|
|
$label, |
29
|
|
|
$renderForBlocks = false, |
30
|
|
|
$renderForModal = false, |
31
|
|
|
$translated = false, |
32
|
|
|
$required = false, |
33
|
|
|
$maxlength = null, |
34
|
|
|
$options = null, |
35
|
|
|
$placeholder = null, |
36
|
|
|
$note = null, |
37
|
|
|
$default = null, |
38
|
|
|
$disabled = false, |
39
|
|
|
$readonly = false, |
40
|
|
|
$editSource = false, |
41
|
|
|
$toolbarOptions = null, |
42
|
|
|
$inModal = false, |
43
|
|
|
$hideCounter = false, |
44
|
|
|
$type = 'quill', |
45
|
|
|
$limitHeight = false, |
46
|
|
|
$syntax = false, |
47
|
|
|
$customTheme = 'github', |
48
|
|
|
$customOptions = null |
49
|
|
|
) { |
50
|
|
|
parent::__construct($name, $label, $renderForBlocks, $renderForModal); |
51
|
|
|
$this->translated = $translated; |
52
|
|
|
$this->required = $required; |
53
|
|
|
$this->maxlength = $maxlength; |
54
|
|
|
$this->options = $options; |
55
|
|
|
$this->placeholder = $placeholder; |
56
|
|
|
$this->note = $note; |
57
|
|
|
$this->disabled = $disabled; |
58
|
|
|
$this->readonly = $readonly; |
59
|
|
|
$this->editSource = $editSource; |
60
|
|
|
$this->toolbarOptions = $toolbarOptions; |
61
|
|
|
$this->inModal = $inModal; |
62
|
|
|
$this->hideCounter = $hideCounter; |
63
|
|
|
$this->type = $type; |
64
|
|
|
$this->limitHeight = $limitHeight; |
65
|
|
|
$this->syntax = $syntax; |
66
|
|
|
$this->customTheme = $customTheme; |
67
|
|
|
$this->customOptions = $customOptions; |
68
|
|
|
$this->default = $default; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function render() |
72
|
|
|
{ |
73
|
|
|
if ($this->toolbarOptions) { |
74
|
|
|
$toolbarOptions = array_map(static function ($option) { |
75
|
|
|
if ($option === 'list-unordered') { |
76
|
|
|
return (object)['list' => 'bullet']; |
77
|
|
|
} |
78
|
|
|
if ($option === 'list-ordered') { |
79
|
|
|
return (object)['list' => 'ordered']; |
80
|
|
|
} |
81
|
|
|
if ($option === 'h1') { |
82
|
|
|
return (object)['header' => 1]; |
83
|
|
|
} |
84
|
|
|
if ($option === 'h2') { |
85
|
|
|
return (object)['header' => 2]; |
86
|
|
|
} |
87
|
|
|
return $option; |
88
|
|
|
}, $this->toolbarOptions); |
89
|
|
|
|
90
|
|
|
$toolbarOptions = [ |
91
|
|
|
'modules' => [ |
92
|
|
|
'toolbar' => $toolbarOptions, |
93
|
|
|
'syntax' => $this->syntax, |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$options = $this->customOptions ?? $toolbarOptions ?? false; |
99
|
|
|
|
100
|
|
|
return view('twill::partials.form._wysiwyg', [ |
101
|
|
|
'theme' => $this->customTheme, |
102
|
|
|
'activeSyntax' => $this->syntax, |
103
|
|
|
'options' => $options, |
104
|
|
|
]); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|