Skip to content

Commit ce3613f

Browse files
authored
Merge pull request #2 from reflex-dev/move-to-uv
move to uv
2 parents d200973 + d04b77f commit ce3613f

File tree

9 files changed

+225
-1223
lines changed

9 files changed

+225
-1223
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: ci
2+
env:
3+
OPENAI_API_KEY: "dummy"
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
check-pyright:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install UV
16+
uses: astral-sh/setup-uv@v6
17+
with:
18+
python-version: "3.10"
19+
enable-cache: true
20+
activate-environment: true
21+
- name: Install Reflex
22+
run: uv sync
23+
- name: Run Pyright
24+
run: pyright .
25+
26+
check-ruff:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Install UV
31+
uses: astral-sh/setup-uv@v6
32+
with:
33+
python-version: "3.10"
34+
enable-cache: true
35+
activate-environment: true
36+
- name: Install Reflex
37+
run: uv sync
38+
- name: Run Ruff
39+
uses: astral-sh/ruff-action@v3

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
```reflex-suneditor``` is [suneditor](http://suneditor.com/sample/index.html) based package.
22

3-
package is avaiable at https://pypi.org/project/reflex-suneditor/0.0.11/
3+
package is avaiable at https://pypi.org/project/reflex-suneditor
44

55
Installation:
66

poetry.lock

Lines changed: 0 additions & 1155 deletions
This file was deleted.

pyproject.toml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
[tool.poetry]
1+
[project]
22
name = "reflex-suneditor"
3-
version = "0.0.11"
3+
version = "0.1.0"
44
description = "Reflex suneditor"
5-
authors = ["Akshay Awate <[email protected]>"]
5+
authors = [{ name = "Akshay Awate", email = "[email protected]" }]
66
readme = "README.md"
7-
packages = [{include = "reflex_suneditor"}]
7+
requires-python = ">=3.10"
88

99
[tool.poetry.dependencies]
10-
python = "^3.7"
11-
reflex = "0.6.2"
10+
reflex = "0.7.14"
11+
12+
[dependency-groups]
13+
dev = ["ruff", "pyright"]
14+
15+
[tool.ruff]
16+
target-version = "py310"
17+
output-format = "concise"
18+
lint.isort.split-on-trailing-comma = false
19+
lint.pydocstyle.convention = "google"
20+
lint.select = ["ALL"]
21+
lint.ignore = ["COM", "PLC0414", "RUF012", "TC002"]
1222

1323

1424
[build-system]
15-
requires = ["poetry-core"]
16-
build-backend = "poetry.core.masonry.api"
25+
requires = ["hatchling"]
26+
build-backend = "hatchling.build"

reflex_suneditor/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Editor component."""
22

3-
from .editor import Editor, EditorButtonList, EditorOptions
3+
from .editor import Editor as Editor
4+
from .editor import EditorButtonList as EditorButtonList
5+
from .editor import EditorOptions as EditorOptions
46

5-
editor = Editor.create
7+
editor = Editor.create

reflex_suneditor/editor.py

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from __future__ import annotations
44

55
import enum
6-
from typing import Dict, List, Literal, Optional, Union
6+
from typing import Literal
77

88
from reflex.base import Base
99
from reflex.components.component import Component, NoSSRComponent
10-
from reflex.event import EventHandler
10+
from reflex.event import EventHandler, no_args_event_spec, passthrough_event_spec
1111
from reflex.utils.format import to_camel_case
1212
from reflex.utils.imports import ImportDict, ImportVar
1313
from reflex.vars.base import Var
@@ -48,70 +48,99 @@ class EditorButtonList(list, enum.Enum):
4848

4949
class EditorOptions(Base):
5050
"""Some of the additional options to configure the Editor.
51+
5152
Complete list of options found here:
5253
https://github.com/JiHong88/SunEditor/blob/master/README.md#options.
5354
"""
5455

5556
# Specifies default tag name of the editor.
5657
# default: 'p' {String}
57-
default_tag: Optional[str] = None
58+
default_tag: str | None = None
5859

5960
# The mode of the editor ('classic', 'inline', 'balloon', 'balloon-always').
6061
# default: 'classic' {String}
61-
mode: Optional[str] = None
62+
mode: str | None = None
6263

6364
# If true, the editor is set to RTL(Right To Left) mode.
6465
# default: false {Boolean}
65-
rtl: Optional[bool] = None
66+
rtl: bool | None = None
6667

6768
# List of buttons to use in the toolbar.
68-
button_list: Optional[List[Union[List[str], str]]]
69+
button_list: list[list[str] | str] | None
70+
71+
72+
def on_blur_spec(_e: Var, content: Var[str]) -> tuple[Var[str]]:
73+
"""A helper function to specify the on_blur event handler.
74+
75+
Args:
76+
_e: The event.
77+
content: The content of the editor.
78+
79+
Returns:
80+
A tuple containing the content of the editor.
81+
"""
82+
return (content,)
83+
84+
85+
def on_paste_spec(
86+
_e: Var, clean_data: Var[str], max_char_count: Var[bool]
87+
) -> tuple[Var[str], Var[bool]]:
88+
"""A helper function to specify the on_paste event handler.
89+
90+
Args:
91+
_e: The event.
92+
clean_data: The clean data.
93+
max_char_count: The maximum character count.
94+
95+
Returns:
96+
A tuple containing the clean data and the maximum character count.
97+
"""
98+
return (clean_data, max_char_count)
6999

70100

71101
class Editor(NoSSRComponent):
72102
"""A Rich Text Editor component based on SunEditor.
103+
73104
Not every JS prop is listed here (some are not easily usable from python),
74105
refer to the library docs for a complete list.
75106
"""
76107

77-
library = "suneditor-react"
108+
library = "suneditor-react@3.6.1"
78109

79110
tag = "SunEditor"
80111

81112
is_default = True
82113

83-
lib_dependencies: List[str] = ["suneditor"]
114+
lib_dependencies: list[str] = ["suneditor"]
84115

85116
# Language of the editor.
86117
# Alternatively to a string, a dict of your language can be passed to this prop.
87118
# Please refer to the library docs for this.
88119
# options: "en" | "da" | "de" | "es" | "fr" | "ja" | "ko" | "pt_br" |
89-
# "ru" | "zh_cn" | "ro" | "pl" | "ckb" | "lv" | "se" | "ua" | "he" | "it"
90-
# default : "en"
120+
# "ru" | "zh_cn" | "ro" | "pl" | "ckb" | "lv" | "se" | "ua" | "he" | "it"
121+
# default: "en".
91122
lang: Var[
92-
Union[
93-
Literal[
94-
"en",
95-
"da",
96-
"de",
97-
"es",
98-
"fr",
99-
"ja",
100-
"ko",
101-
"pt_br",
102-
"ru",
103-
"zh_cn",
104-
"ro",
105-
"pl",
106-
"ckb",
107-
"lv",
108-
"se",
109-
"ua",
110-
"he",
111-
"it",
112-
],
113-
dict,
123+
Literal[
124+
"en",
125+
"da",
126+
"de",
127+
"es",
128+
"fr",
129+
"ja",
130+
"ko",
131+
"pt_br",
132+
"ru",
133+
"zh_cn",
134+
"ro",
135+
"pl",
136+
"ckb",
137+
"lv",
138+
"se",
139+
"ua",
140+
"he",
141+
"it",
114142
]
143+
| dict
115144
]
116145

117146
# This is used to set the HTML form name of the editor.
@@ -121,7 +150,7 @@ class Editor(NoSSRComponent):
121150

122151
# Sets the default value of the editor.
123152
# This is useful if you don't want the on_change method to be called on render.
124-
# If you want the on_change method to be called on render please use the set_contents prop
153+
# If you want the on_change method to be called on render use the set_contents prop
125154
default_value: Var[str]
126155

127156
# Sets the width of the editor.
@@ -140,10 +169,10 @@ class Editor(NoSSRComponent):
140169
auto_focus: Var[bool]
141170

142171
# Pass an EditorOptions instance to modify the behaviour of Editor even more.
143-
set_options: Var[Dict]
172+
set_options: Var[dict]
144173

145174
# Whether all SunEditor plugins should be loaded.
146-
# default: True
175+
# default: True.
147176
set_all_plugins: Var[bool]
148177

149178
# Set the content of the editor.
@@ -162,52 +191,47 @@ class Editor(NoSSRComponent):
162191
set_default_style: Var[str]
163192

164193
# Disable the editor
165-
# default: False
194+
# default: False.
166195
disable: Var[bool]
167196

168197
# Hide the editor
169-
# default: False
198+
# default: False.
170199
hide: Var[bool]
171200

172201
# Hide the editor toolbar
173-
# default: False
202+
# default: False.
174203
hide_toolbar: Var[bool]
175204

176205
# Disable the editor toolbar
177-
# default: False
206+
# default: False.
178207
disable_toolbar: Var[bool]
179208

180209
# Fired when the editor content changes.
181-
on_change: EventHandler[lambda content: [content]]
210+
on_change: EventHandler[passthrough_event_spec(str)]
182211

183212
# Fired when the something is inputted in the editor.
184-
on_input: EventHandler[lambda e: [e]]
213+
on_input: EventHandler[no_args_event_spec]
185214

186215
# Fired when the editor loses focus.
187-
on_blur: EventHandler[lambda e, content: [content]]
216+
on_blur: EventHandler[on_blur_spec]
188217

189218
# Fired when the editor is loaded.
190-
on_load: EventHandler[lambda reload: [reload]]
191-
192-
# Fired when the editor is resized.
193-
on_resize_editor: EventHandler[lambda height, prev_height: [height, prev_height]]
219+
on_load: EventHandler[passthrough_event_spec(bool)]
194220

195221
# Fired when the editor content is copied.
196-
on_copy: EventHandler[lambda e, clipboard_data: [clipboard_data]]
222+
on_copy: EventHandler[no_args_event_spec]
197223

198224
# Fired when the editor content is cut.
199-
on_cut: EventHandler[lambda e, clipboard_data: [clipboard_data]]
225+
on_cut: EventHandler[no_args_event_spec]
200226

201227
# Fired when the editor content is pasted.
202-
on_paste: EventHandler[
203-
lambda e, clean_data, max_char_count: [clean_data, max_char_count]
204-
]
228+
on_paste: EventHandler[on_paste_spec]
205229

206230
# Fired when the code view is toggled.
207-
toggle_code_view: EventHandler[lambda is_code_view: [is_code_view]]
231+
toggle_code_view: EventHandler[passthrough_event_spec(bool)]
208232

209233
# Fired when the full screen mode is toggled.
210-
toggle_full_screen: EventHandler[lambda is_full_screen: [is_full_screen]]
234+
toggle_full_screen: EventHandler[passthrough_event_spec(bool)]
211235

212236
def add_imports(self) -> ImportDict:
213237
"""Add imports for the Editor component.
@@ -220,11 +244,13 @@ def add_imports(self) -> ImportDict:
220244
}
221245

222246
@classmethod
223-
def create(cls, set_options: Optional[EditorOptions] = None, **props) -> Component:
247+
def create(
248+
cls, set_options: EditorOptions | None = None, **props: object
249+
) -> Component:
224250
"""Create an instance of Editor. No children allowed.
225251
226252
Args:
227-
set_options(Optional[EditorOptions]): Configuration object to further configure the instance.
253+
set_options: Configuration object to further configure the instance.
228254
**props: Any properties to be passed to the Editor
229255
230256
Returns:
@@ -235,10 +261,11 @@ def create(cls, set_options: Optional[EditorOptions] = None, **props) -> Compone
235261
"""
236262
if set_options is not None:
237263
if isinstance(set_options, Var):
238-
raise ValueError("EditorOptions cannot be a state Var")
264+
msg = "EditorOptions cannot be a state Var"
265+
raise ValueError(msg)
239266
props["set_options"] = {
240267
to_camel_case(k): v
241268
for k, v in set_options.dict().items()
242269
if v is not None
243270
}
244-
return super().create(*[], **props)
271+
return super().create(*[], **props)

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)