Py.Cafe

rob.on.lists/

solara-markdown-message-editor

Solara-based Markdown Message Editor

DocsPricing
  • app.py
  • requirements.txt
app.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
# show map of messages, display map in Page() after a change

import solara

store={'one':'message 1','two':'*message 2*','three':'__message 3__'}

@solara.component
def MarkdownEditor(fld:str):
    md, set_md = solara.use_state(store[fld])
    def propagate(newval):
        set_md(newval)
        store[fld]=newval  # update map
        process_it = 1  # trigger display of map in Page()
        print(store)  # proof that on_value was triggered
    with solara.VBox() as main:
        solara.InputText('value '+fld,value=md, on_value=propagate)
        solara.Markdown(md)
    return main

@solara.component
def Page():
    def process_it_rtn():  # process update on any of the map fields
        print('changed?')
        process_it = 0
    process_it = solara.use_reactive(0,process_it_rtn)
    for fld in store.keys():
        MarkdownEditor(fld)
    if process_it.value==1:  # process update on any of the map fields
        solara.Markdown(str(store))
        process_it = 0