Skip to content

Commit

Permalink
introduce dependencies parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 7, 2024
1 parent 927766e commit 239b0ce
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/is_even/number_checker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nicegui import ui


class NumberChecker(ui.element, component='number_checker.js', exposed_libraries=['dist/is-odd.js']):
class NumberChecker(ui.element, component='number_checker.js', dependencies=['dist/is-odd.js']):

def __init__(self) -> None:
"""NumberChecker
Expand Down
8 changes: 4 additions & 4 deletions examples/signature_pad/signature_pad.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from typing import Dict
from typing import Dict, Optional

from nicegui import ui


class SignaturePad(ui.element,
component='signature_pad.js',
exposed_libraries=['node_modules/signature_pad/dist/signature_pad.min.js']):
dependencies=['node_modules/signature_pad/dist/signature_pad.min.js']):

def __init__(self, options: Dict = {}) -> None:
def __init__(self, options: Optional[Dict] = None) -> None:
"""SignaturePad
An element that integrates the `Signature Pad library <https://szimek.github.io/signature_pad/>`_.
"""
super().__init__()
self._props['options'] = options
self._props['options'] = options or {}

def clear(self):
"""Clear the signature."""
Expand Down
19 changes: 15 additions & 4 deletions nicegui/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ def __init__(self, tag: Optional[str] = None, *, _client: Optional[Client] = Non

def __init_subclass__(cls, *,
component: Union[str, Path, None] = None,
libraries: List[Union[str, Path]] = [], # noqa: B006
exposed_libraries: List[Union[str, Path]] = [], # noqa: B006
extra_libraries: List[Union[str, Path]] = [], # noqa: B006
dependencies: List[Union[str, Path]] = [], # noqa: B006
libraries: List[Union[str, Path]] = [], # noqa: B006 # DEPRECATED
exposed_libraries: List[Union[str, Path]] = [], # noqa: B006 # DEPRECATED
extra_libraries: List[Union[str, Path]] = [], # noqa: B006 # DEPRECATED
) -> None:
super().__init_subclass__()
base = Path(inspect.getfile(cls)).parent
Expand All @@ -120,6 +121,16 @@ def glob_absolute_paths(file: Union[str, Path]) -> List[Path]:
path = base / path
return sorted(path.parent.glob(path.name), key=lambda p: p.stem)

if libraries:
helpers.warn_once('The `libraries` parameter is deprecated. Use `dependencies` instead.',
stack_info=True)
if exposed_libraries:
helpers.warn_once('The `exposed_libraries` parameter is deprecated. Use `dependencies` instead.',
stack_info=True)
if extra_libraries:
helpers.warn_once('The `extra_libraries` parameter is deprecated. Use `dependencies` instead.',
stack_info=True)

cls.component = copy(cls.component)
cls.libraries = copy(cls.libraries)
cls.extra_libraries = copy(cls.extra_libraries)
Expand All @@ -133,7 +144,7 @@ def glob_absolute_paths(file: Union[str, Path]) -> List[Path]:
for library in extra_libraries:
for path in glob_absolute_paths(library):
cls.extra_libraries.append(register_library(path))
for library in exposed_libraries:
for library in exposed_libraries + dependencies:
for path in glob_absolute_paths(library):
cls.exposed_libraries.append(register_library(path, expose=True))

Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/aggrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
pass


class AgGrid(Element, component='aggrid.js', exposed_libraries=['lib/aggrid/ag-grid-community.min.js']):
class AgGrid(Element, component='aggrid.js', dependencies=['lib/aggrid/ag-grid-community.min.js']):

def __init__(self,
options: Dict, *,
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
pass


class EChart(Element, component='echart.js', exposed_libraries=['lib/echarts/echarts.min.js', 'lib/echarts-gl/echarts-gl.min.js']):
class EChart(Element, component='echart.js', dependencies=['lib/echarts/echarts.min.js', 'lib/echarts-gl/echarts-gl.min.js']):

def __init__(self, options: Dict, on_point_click: Optional[Callable] = None, *, enable_3d: bool = False) -> None:
"""Apache EChart
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..events import GenericEventArguments, JoystickEventArguments, handle_event


class Joystick(Element, component='joystick.vue', exposed_libraries=['lib/nipplejs/nipplejs.js']):
class Joystick(Element, component='joystick.vue', dependencies=['lib/nipplejs/nipplejs.js']):

def __init__(self, *,
on_start: Optional[Callable[..., Any]] = None,
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/json_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..events import GenericEventArguments, JsonEditorChangeEventArguments, JsonEditorSelectEventArguments, handle_event


class JsonEditor(Element, component='json_editor.js', exposed_libraries=['lib/vanilla-jsoneditor/index.js']):
class JsonEditor(Element, component='json_editor.js', dependencies=['lib/vanilla-jsoneditor/index.js']):

def __init__(self,
properties: Dict, *,
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Mermaid(ContentElement,
component='mermaid.js',
exposed_libraries=[
dependencies=[
'lib/mermaid/*.js',
'lib/mermaid/mermaid.esm.min.mjs',
]):
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pass


class Plotly(Element, component='plotly.vue', exposed_libraries=['lib/plotly/plotly.min.js']):
class Plotly(Element, component='plotly.vue', dependencies=['lib/plotly/plotly.min.js']):

def __init__(self, figure: Union[Dict, go.Figure]) -> None:
"""Plotly Element
Expand Down
2 changes: 1 addition & 1 deletion nicegui/elements/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SceneObject:

class Scene(Element,
component='scene.js',
exposed_libraries=[
dependencies=[
'lib/three/three.module.js',
'lib/three/modules/BufferGeometryUtils.js',
'lib/three/modules/CSS2DRenderer.js',
Expand Down
6 changes: 4 additions & 2 deletions nicegui/elements/scene_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

class SceneView(Element,
component='scene_view.js',
libraries=['lib/tween/tween.umd.js'],
exposed_libraries=['lib/three/three.module.js']):
dependencies=[
'lib/tween/tween.umd.js',
'lib/three/three.module.js',
]):

def __init__(self,
scene: Scene,
Expand Down

0 comments on commit 239b0ce

Please sign in to comment.