Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building ESM based components #5593

Merged
merged 146 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
72071be
Add support for ESM bundle on ReactiveHTML
philippjfr Oct 7, 2023
9124d18
Add helper function for watching property changes
philippjfr Nov 19, 2023
984081a
Make preact hooks available in ESM namespace
philippjfr Nov 20, 2023
d73489c
Add watchfiles support for ESM
philippjfr Nov 20, 2023
dba5be4
Pull out ReactiveESM
philippjfr Nov 21, 2023
303c2c4
Revert ReactiveHTML changes
philippjfr Nov 21, 2023
aded649
Major improvements
philippjfr Jan 9, 2024
ad01ec3
Merge origin/main
philippjfr Apr 30, 2024
606aa72
Update esm code
philippjfr May 1, 2024
8d2218e
Add some tests
philippjfr May 1, 2024
3e32901
Add event handling
philippjfr May 1, 2024
e38860d
Allow rendering htm
philippjfr May 1, 2024
e527f1d
Disconnect signals and re-render htm
philippjfr May 1, 2024
abe4305
Load module shim from CDN/server
philippjfr May 2, 2024
d3e2f8f
Patch wrapper code
philippjfr May 2, 2024
5237ff0
Re-add esm module
philippjfr May 3, 2024
1d86398
Handle Mui specifically
philippjfr May 3, 2024
19135f2
No templating in ESM
philippjfr May 3, 2024
f8cab96
start working on esm documentation
MarcSkovMadsen May 4, 2024
8613b08
add more docs
MarcSkovMadsen May 5, 2024
673485e
jsx
MarcSkovMadsen May 5, 2024
da1eb4a
Instrument setup/cleanup of autoreload for stylesheets
philippjfr May 5, 2024
17bc267
Remove core module
philippjfr May 5, 2024
2bbaeaf
Small fix
philippjfr May 5, 2024
825c5ab
Fix import map setup in simple case
philippjfr May 5, 2024
08a1057
update
MarcSkovMadsen May 5, 2024
65ec36c
Allow .js, .jsx, .ts and .tsx file types
philippjfr May 5, 2024
74f7d8d
Fix dynamic reload of CSS
philippjfr May 5, 2024
cff03a7
fix importmap and add back el description
MarcSkovMadsen May 5, 2024
de237a0
Merge branch 'reactive_html_esm' of https://github.com/holoviz/panel …
MarcSkovMadsen May 5, 2024
c32b206
Merge origin/main
philippjfr May 5, 2024
70fdeee
add canvas draw example
MarcSkovMadsen May 5, 2024
81aaac2
Merge branch 'reactive_html_esm' of https://github.com/holoviz/panel …
MarcSkovMadsen May 5, 2024
1076764
Fix links
philippjfr May 5, 2024
1edad0c
Rename event handler methods
philippjfr May 5, 2024
40faac2
Add ability to render lists of children
philippjfr May 5, 2024
b3b261d
Make eslint happy
philippjfr May 6, 2024
1675691
Merge branch 'main' into reactive_html_esm
philippjfr May 6, 2024
b4b20b3
Modernize
philippjfr May 7, 2024
e01693d
children and html
MarcSkovMadsen May 9, 2024
75e0068
layout single panel component
MarcSkovMadsen May 9, 2024
fe18bd0
fix html example
MarcSkovMadsen May 10, 2024
79f26ca
improve children description and examples
MarcSkovMadsen May 10, 2024
2648fdf
Allow configuring react version
philippjfr May 15, 2024
2d58aac
Separate ReactiveESM component classes
philippjfr May 16, 2024
232eb7e
seperate components
MarcSkovMadsen May 17, 2024
c596afc
Add custom examples
philippjfr May 18, 2024
60ed019
Small fixes
philippjfr May 18, 2024
1ff20af
Improve dev experience
philippjfr May 18, 2024
832e772
Minor fixes
philippjfr May 19, 2024
13a9bcc
Fix indent
philippjfr May 19, 2024
00ed49d
Move imports from panel.esm to panel.custom
philippjfr May 19, 2024
88c9f50
Fix ident
philippjfr May 19, 2024
4c96684
Support tuples in Viewable parameter declarations
philippjfr May 19, 2024
4609e52
Fix and test child model cleanup
philippjfr May 19, 2024
196c5fa
Define View and Views parameters
philippjfr May 19, 2024
4367639
Improvements for child(ren) rendering
philippjfr May 20, 2024
2d7c44b
Merge origin/main
philippjfr May 20, 2024
77ebdc1
Fix lint
philippjfr May 20, 2024
eaed204
Further lint
philippjfr May 20, 2024
71a8dc4
Fix compile errors
philippjfr May 20, 2024
8681968
Refactoring
philippjfr May 20, 2024
f129ebf
Implement on child update re-render
philippjfr May 20, 2024
519116b
update layout guide
MarcSkovMadsen May 22, 2024
55b7643
add widget example
MarcSkovMadsen May 22, 2024
eaa3a52
Small refactor
philippjfr May 21, 2024
43e90bc
Deduplicate javascript modules on subclasses
philippjfr May 23, 2024
e6afcda
Remove console.log
philippjfr May 23, 2024
037c086
Minor cleanup
philippjfr May 23, 2024
4ed63c8
Do not auto-resolve refs on Child and Children parameters
philippjfr May 23, 2024
691d47a
Fix lint
philippjfr May 23, 2024
ce4e9d0
update docs after child changes
MarcSkovMadsen May 24, 2024
c9aaf36
update docs after implementation changes
MarcSkovMadsen May 24, 2024
b818df6
add anywidget migration guide
MarcSkovMadsen May 25, 2024
a63e298
review feedback
MarcSkovMadsen May 25, 2024
10b7941
review feedback
MarcSkovMadsen May 25, 2024
cb6bbfa
add mario button tutorial example
MarcSkovMadsen May 25, 2024
d341983
add references
MarcSkovMadsen May 25, 2024
4e7c810
reflection on Trevor feedback
MarcSkovMadsen May 26, 2024
da5e2da
finalize mariobutton tutorial
MarcSkovMadsen May 26, 2024
eaedc66
document the React object
MarcSkovMadsen May 26, 2024
7849476
extend React description
MarcSkovMadsen May 26, 2024
8ec1380
improve tutorial
MarcSkovMadsen May 26, 2024
2a003aa
Add AnyWidgetComponent
philippjfr May 30, 2024
462b57f
Improve ESM reload logic
philippjfr May 30, 2024
31ef412
Further align AnyWidgetComponent
philippjfr May 30, 2024
35ea5c7
Set size
philippjfr May 30, 2024
25605fe
Execute ESM code in isolated module
philippjfr May 30, 2024
1b7e73a
Treat (P)react render as component
philippjfr May 30, 2024
daed230
Improve module initialization
philippjfr May 30, 2024
5d506e9
Fix lint
philippjfr May 30, 2024
5d362ed
Fix more lint
philippjfr May 30, 2024
f2573c9
Add esm rerender tests
philippjfr May 30, 2024
13c7a12
Fix lint
philippjfr May 30, 2024
147e468
Unify data and model into proxy
philippjfr May 30, 2024
228e0e3
Implement AnyWidget save_changes API
philippjfr May 30, 2024
5611027
Fix lint
philippjfr May 30, 2024
7e50b79
Merge remote-tracking branch 'origin/main' into reactive_html_esm
philippjfr May 31, 2024
c1994ff
Fix material UI
philippjfr May 31, 2024
36cc074
Replace state and children with model.useState and model.get_child
philippjfr Jun 3, 2024
d336d6d
Move compilation onto model
philippjfr Jun 3, 2024
3579f24
Remove PreactComponent
philippjfr Jun 3, 2024
15c82ac
Move watchers onto model
philippjfr Jun 3, 2024
5568c15
Allow unwatch
philippjfr Jun 3, 2024
a2d9e11
add AnyWidgetComponent reference guide
MarcSkovMadsen Jun 4, 2024
5b59d24
review feedback
MarcSkovMadsen Jun 4, 2024
083acf1
fix ReactComponent code + Add AnyWidget widget example
MarcSkovMadsen Jun 6, 2024
ceba6fd
add Viewer reference guide
MarcSkovMadsen Jun 9, 2024
882aa48
add Viewer layout example
MarcSkovMadsen Jun 9, 2024
1ff870e
Add how-to for NameListLike layouts
MarcSkovMadsen Jun 9, 2024
37b2be1
Update panel/__init__.py
MarcSkovMadsen Jun 10, 2024
07ae098
Merge origin/main
philippjfr Jun 13, 2024
220ee28
Add ReactComponent error boundary and allow templating children indiv…
philippjfr Jun 13, 2024
e7c4b5f
Fix lint
philippjfr Jun 13, 2024
38efacc
Fix type
philippjfr Jun 13, 2024
5aba545
Merge origin/main
philippjfr Jun 14, 2024
872b0f9
Allow sending server side events to ESM components
philippjfr Jun 14, 2024
e515344
Test fixes
philippjfr Jun 14, 2024
ca7cde4
Update test
philippjfr Jun 14, 2024
ef31103
Add WidgetBase class
philippjfr Jun 15, 2024
73d229d
Fix MenuButton
philippjfr Jun 15, 2024
a77c587
Small fixes
philippjfr Jun 15, 2024
10e3dff
Add ESM docs to index
philippjfr Jun 15, 2024
8d5173a
Add to toc
philippjfr Jun 17, 2024
288c05c
Add custom components pages to index
philippjfr Jun 17, 2024
fd9f776
Add redirect
philippjfr Jun 17, 2024
2feea70
Fix FileDownload
philippjfr Jun 17, 2024
ba3be9a
Add custom_components tutorial to toc
philippjfr Jun 17, 2024
3190bc3
Factor out Pane and PaneBase
philippjfr Jun 17, 2024
5da72f5
Ignore missing Pane in ref gallery
philippjfr Jun 18, 2024
422ca62
Fix test
philippjfr Jun 18, 2024
827f5e5
Reorganize custom component how-to guides
philippjfr Jun 18, 2024
b56ee34
Clean up ListLike constructor
philippjfr Jun 18, 2024
60f4a68
Add PaneBase and WidgetBase to panel.custom namespace
philippjfr Jun 18, 2024
d042f22
More cleanup
philippjfr Jun 18, 2024
bbdf693
Move and fix callbacks how-to
philippjfr Jun 18, 2024
508efd6
Add dataframe example
philippjfr Jun 19, 2024
77c4e23
Improve react version handling
philippjfr Jun 19, 2024
611479d
Rename model.watch to model.on and add lifecycle handlers
philippjfr Jun 20, 2024
4ff9c25
Fix lint
philippjfr Jun 20, 2024
7ecc9cb
More lint
philippjfr Jun 20, 2024
ac80b41
Doc fixes
philippjfr Jun 20, 2024
5ec3a7d
Add examples
philippjfr Jun 21, 2024
a807275
Fix tab definitions in docs
philippjfr Jun 21, 2024
692f8c1
Add custom components section to ref gallery
philippjfr Jun 21, 2024
ac438a7
Update docs and add tests for lifecycle handlers
philippjfr Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,5 @@ app_streamlit.py
pixi.lock
panel/_version.py
.uicoveragerc
mario_button.*
counter_button.*
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@
'galleries': {
'reference': {
'title': 'Component Gallery',
'extensions': ['*.ipynb', '*.py', '*.md'],
'sections': [
'panes',
'widgets',
'layouts',
# 3 most important by expected usage. Rest alphabetically
'chat',
'custom_components',
'global',
'indicators',
'templates',
Expand Down
72 changes: 72 additions & 0 deletions doc/how_to/custom_components/esm/callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ESM component with callback

In this guide we will show you how to add callbacks to your ESM components.

## Slideshow with Python callback

This example shows you how to create a `SlideShow` component that uses a Python *callback* function to update the `Slideshow` image when its clicked:

```{pyodide}
import param
import panel as pn

from panel.custom import JSComponent

pn.extension()

class Slideshow(JSComponent):

index = param.Integer(default=0)

_esm = """
export function render({ model }) {
const img = document.createElement('img')
img.src = `https://picsum.photos/800/300?image=${model.index}`
img.addEventListener('click', (event) => model.send_event('click', event))
model.on('index', () => {
img.src = `https://picsum.photos/800/300?image=${model.index}`
})
return img
}
"""

def _handle_click(self, event):
self.index += 1

Slideshow(width=500, height=200).servable()
```

This approach lets you quickly build custom components with complex interactivity. However if you do not need any complex computations in Python you can also construct a pure JS equivalent:

## Slideshow with Javascript Callback

This example shows you how to create a `Slideshow` component that uses a Javascript *callback* function to update the `Slideshow` image when its clicked:

```{pyodide}
import param
import panel as pn

from panel.custom import JSComponent

pn.extension()

class JSSlideshow(JSComponent):

index = param.Integer(default=0)

_esm = """
export function render({ model }) {
const img = document.createElement('img')
img.src = `https://picsum.photos/800/300?image=${model.index}`
img.addEventListener('click', (event) => { model.index += 1 })
model.on('index', () => {
img.src = `https://picsum.photos/800/300?image=${model.index}`
})
return img
}
"""

JSSlideshow(width=800, height=300).servable()
```

By using Javascript callbacks instead of Python callbacks you can achieve higher performance, components that can be *js linked* and components that will also work when your app is saved to static html.
Loading
Loading