Skip to content

Commit 3bef130

Browse files
author
Bizley
authored
Merge pull request #27 from bizley/active-field-and-resize
Active Field class fix and allowResize property
2 parents e733d53 + e01779d commit 3bef130

9 files changed

+223
-130
lines changed

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ You can find Quill at https://quilljs.com/
2121
Run console command
2222

2323
```
24-
composer require bizley/quill:^3.1
24+
composer require bizley/quill:^3.2
2525
```
2626

2727
Or add the package to your `composer.json`:
2828

2929
```json
3030
{
3131
"require": {
32-
"bizley/quill": "^3.1"
32+
"bizley/quill": "^3.2"
3333
}
3434
}
3535
```
@@ -104,8 +104,9 @@ copied to hidden input field so it can be used in forms. You can modify containe
104104

105105
### Editor box's height
106106

107-
Default editor height is *150px* (this can be changed by setting `'options'` parameter) and its box extends as new text
108-
lines are added.
107+
When `allowResize` option is set to `false` (default) editor's height is *150px* (this can be changed by setting
108+
`'options'` parameter). Setting `allowResize` to `true` resets the minimum height and allows it to be expanded freely.
109+
Editor's box extends as new text lines are added.
109110

110111
### Quill source
111112

@@ -169,15 +170,15 @@ the `'katexVersion'` parameter. Starting from version 3.0.0 you can use local as
169170
packet manager - to do so run
170171

171172
```
172-
composer require npm-asset/katex:^0.11
173+
composer require npm-asset/katex:^0.12
173174
```
174175

175176
Or add the package to your `composer.json`:
176177

177178
```json
178179
{
179180
"require": {
180-
"npm-asset/katex": "^0.11"
181+
"npm-asset/katex": "^0.12"
181182
}
182183
}
183184
```
@@ -203,15 +204,15 @@ highlight.js by setting the `'highlightVersion'` parameter. Starting from versio
203204
highlight.js provided through NPM packet manager - to do so run
204205

205206
```
206-
composer require npm-asset/highlight.js:^9.18
207+
composer require npm-asset/highlight.js:^10.2
207208
```
208209

209210
Or add the package to your `composer.json`:
210211

211212
```json
212213
{
213214
"require": {
214-
"npm-asset/highlight.js": "^9.18"
215+
"npm-asset/highlight.js": "^10.2"
215216
}
216217
}
217218
```
@@ -239,15 +240,15 @@ previous versions you would have to add it through custom JS (see `js` property)
239240
Run
240241

241242
```
242-
composer require npm-asset/quill-smart-break:^0.1
243+
composer require npm-asset/quill-smart-break:^0.2
243244
```
244245

245246
Or add the package to your `composer.json`:
246247

247248
```json
248249
{
249250
"require": {
250-
"npm-asset/quill-smart-break": ">=0.1.1 <1.0.0"
251+
"npm-asset/quill-smart-break": "^0.2"
251252
}
252253
}
253254
```

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"yiisoft/yii2": "^2.0.0"
1919
},
2020
"require-dev": {
21-
"npm-asset/highlight.js": "^10.1",
21+
"npm-asset/highlight.js": "^10.2",
2222
"npm-asset/katex": "^0.12",
2323
"npm-asset/quill": "^1.3",
24-
"npm-asset/quill-smart-break": ">= 0.1.1 <1.0.0",
24+
"npm-asset/quill-smart-break": "^0.2",
2525
"phpunit/phpunit": "^7.5",
2626
"roave/security-advisories": "dev-master"
2727
},

src/Quill.php

+33-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* See the documentation for more details.
3333
*
3434
* @author Paweł Bizley Brzozowski
35-
* @version 3.1.0
35+
* @version 3.2.0
3636
* @license Apache 2.0
3737
* https://github.com/bizley/yii2-quill
3838
*
@@ -49,8 +49,8 @@ class Quill extends InputWidget
4949
public const TOOLBAR_BASIC = 'BASIC';
5050

5151
public const QUILL_VERSION = '1.3.7';
52-
public const KATEX_VERSION = '0.11.1';
53-
public const HIGHLIGHTJS_VERSION = '9.18.1';
52+
public const KATEX_VERSION = '0.12.0';
53+
public const HIGHLIGHTJS_VERSION = '10.2.0';
5454

5555
/** {@inheritdoc} */
5656
public static $autoIdPrefix = 'quill-';
@@ -182,12 +182,6 @@ class Quill extends InputWidget
182182
*/
183183
public $highlightStyle = 'default';
184184

185-
/**
186-
* @var array HTML attributes for the input tag (editor box).
187-
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
188-
*/
189-
public $options = ['style' => 'min-height:150px;'];
190-
191185
/**
192186
* @var array HTML attributes for the hidden input tag (field keeping raw HTML text).
193187
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
@@ -207,6 +201,12 @@ class Quill extends InputWidget
207201
*/
208202
public $localAssets = false;
209203

204+
/**
205+
* @var bool Whether to allow resizing the editor box.
206+
* @since 3.2.0
207+
*/
208+
public $allowResize = false;
209+
210210
/** @var string ID of the editor */
211211
protected $_fieldId;
212212

@@ -245,6 +245,10 @@ public function init(): void
245245
$this->_fieldId = $this->options['id'];
246246
$this->options['id'] = 'editor-' . $this->id;
247247

248+
if (!$this->allowResize && !isset($this->options['style'])) {
249+
$this->options['style'] = 'min-height:150px;';
250+
}
251+
248252
$this->prepareOptions();
249253
}
250254

@@ -523,13 +527,29 @@ public function renderToolbar()
523527
return $this->toolbarOptions;
524528
}
525529

530+
private function removeFormControlClass(): void
531+
{
532+
if (isset($this->options['class'])) {
533+
$oldClasses = explode(' ', $this->options['class']);
534+
$newClasses = [];
535+
foreach ($oldClasses as $class) {
536+
if ($class !== 'form-control') {
537+
$newClasses[] = $class;
538+
}
539+
}
540+
$this->options['class'] = implode(' ', $newClasses);
541+
}
542+
}
543+
526544
/** {@inheritdoc} */
527545
public function run(): string
528546
{
529547
$this->registerClientScript();
530548

531549
$hiddenOptions = array_merge($this->hiddenOptions, ['id' => $this->_fieldId]);
532550

551+
$this->removeFormControlClass();
552+
533553
if ($this->hasModel()) {
534554
return Html::activeHiddenInput($this->model, $this->attribute, $hiddenOptions)
535555
. Html::tag($this->tag, $this->model->{$this->attribute}, $this->options);
@@ -547,6 +567,10 @@ public function registerClientScript(): void
547567
{
548568
$view = $this->view;
549569

570+
if ($this->allowResize) {
571+
$view->registerCss('.ql-editor{resize:vertical;overflow-y:scroll}');
572+
}
573+
550574
if ($this->localAssets) {
551575
if ($this->isKatex()) {
552576
KatexLocalAsset::register($view);

0 commit comments

Comments
 (0)