Mercurial > libervia-web
annotate libervia/web/pages/_browser/popup.py @ 1635:332822ceae85
browser (chat): Add rich editor, forward and extra recipients:
A new "extra" menu is now available next to input field, allowing to toggle to rich
editor. Rich editors allows message styling using bold, italic, underline, (un)numbered
list and link. Other features will probably follow with time.
An extra menu item allows to add recipients, with `to`, `cc` or `bcc` flag like for
emails.
Messages can now be forwarded to any entity with a new item in the 3 dots menu.
rel 461
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Jul 2025 17:47:37 +0200 |
parents | a2cd4222c702 |
children |
rev | line source |
---|---|
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 from browser import document, timer |
1619 | 2 from js_modules.tippy_js import tippy as tippy_ori |
3 from javascript import pyobj2jsobj | |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
1619 | 5 # FIXME: workaround for https://github.com/brython-dev/brython/issues/2542 |
6 def tippy(target, data): | |
7 return tippy_ori(target, pyobj2jsobj(data)) | |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 def create_popup( |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 target, |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 content_elt, |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 focus_class="has-popup-focus", |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 focus_elt=None, |
1635
332822ceae85
browser (chat): Add rich editor, forward and extra recipients:
Goffi <goffi@goffi.org>
parents:
1619
diff
changeset
|
14 placement="bottom", |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 **kwargs |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 ): |
1635
332822ceae85
browser (chat): Add rich editor, forward and extra recipients:
Goffi <goffi@goffi.org>
parents:
1619
diff
changeset
|
17 """Create a popup and show a popup next to a target |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 The popup is created and destroyed on each call, this can be used for dynamic content. |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 @param target: element where the popup will appear, or a selector |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 @param content_elt: HTML element to show in the popup |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 @param focus_class: class added to target element when popup is shown |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 @param focus_elt: element where focus_class is added. If None, target will be used. |
1635
332822ceae85
browser (chat): Add rich editor, forward and extra recipients:
Goffi <goffi@goffi.org>
parents:
1619
diff
changeset
|
24 @param placement: where the popup must be located. |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 @param kwargs: arguments used to override tippy options |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 """ |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 if focus_elt is None: |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 focus_elt = target |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 def on_hide(__): |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 focus_elt.classList.remove(focus_class) |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 timer.set_timeout(tippy_instance.destroy, 0) |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 tippy_opts = { |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 "trigger": "click", |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 "content": content_elt, |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 "appendTo": document.body, |
1635
332822ceae85
browser (chat): Add rich editor, forward and extra recipients:
Goffi <goffi@goffi.org>
parents:
1619
diff
changeset
|
36 "placement": placement, |
1582
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "interactive": True, |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 "trigger": "manual", |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 "theme": "light", |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "onShow": lambda __: focus_elt.classList.add(focus_class), |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "onHide": on_hide |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 tippy_opts.update(kwargs) |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 tippy_instance = tippy( |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 target, |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 tippy_opts |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 ) |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 tippy_instance.show() |
f52b89365002
browser: new `popup` module to create dynamic popups
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 return tippy_instance |