-
-
Notifications
You must be signed in to change notification settings - Fork 473
/
texteditor.py
64 lines (46 loc) · 1.88 KB
/
texteditor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Defines a WYSIWYG TextEditor widget based on quill.js.
"""
from __future__ import annotations
from typing import (
TYPE_CHECKING, ClassVar, Mapping, Optional,
)
import param
from pyviz_comms import JupyterComm
from ..util import lazy_load
from .base import Widget
if TYPE_CHECKING:
from bokeh.document import Document
from bokeh.model import Model
from pyviz_comms import Comm
class TextEditor(Widget):
"""
The `TextEditor` widget provides a WYSIWYG
(what-you-see-is-what-you-get) rich text editor which outputs HTML.
The editor is built on top of the [Quill.js](https://quilljs.com/) library.
Reference: https://panel.holoviz.org/reference/widgets/TextEditor.html
:Example:
>>> TextEditor(placeholder='Enter some text')
"""
disabled = param.Boolean(default=False, doc="""
Whether the editor is disabled.""")
mode = param.Selector(default='toolbar', objects=['bubble', 'toolbar'], doc="""
Whether to display a toolbar or a bubble menu on highlight.""")
toolbar = param.ClassSelector(default=True, class_=(list, bool), doc="""
Toolbar configuration either as a boolean toggle or a configuration
specified as a list.""")
placeholder = param.String(doc="Placeholder output when the editor is empty.")
value = param.String(doc="State of the current text in the editor")
_rename: ClassVar[Mapping[str, str | None]] = {
'name': 'name', 'value': 'text'
}
def _get_model(
self, doc: Document, root: Optional[Model] = None,
parent: Optional[Model] = None, comm: Optional[Comm] = None
) -> Model:
if self._widget_type is None:
self._widget_type = lazy_load(
'panel.models.quill', 'QuillInput', isinstance(comm, JupyterComm),
root, ext='texteditor'
)
return super()._get_model(doc, root, parent, comm)