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

Add SimpleMDEField #379

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
651cc3d
Ignore .sqlite3 extensions.
hasansezertasan Nov 4, 2023
141651d
SimpleMDE integration.
hasansezertasan Nov 4, 2023
ee7f016
SimpleMDE.
hasansezertasan Nov 4, 2023
88bb04c
SimpleMDEField
hasansezertasan Nov 4, 2023
0995a9a
New example to showcase fields - to be improved.
hasansezertasan Nov 4, 2023
8be4387
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
8ea55ad
More fields added.
hasansezertasan Nov 4, 2023
8337824
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
e0c674a
Added SimpleMDEField to the api ref.
hasansezertasan Nov 4, 2023
7eea04d
Merge branch 'SimpleMDE' of https://github.com/hasansezertasan/starle…
hasansezertasan Nov 4, 2023
9eff3a2
Undo changes made in TinyMCEEditorField
hasansezertasan Nov 4, 2023
d8613e5
Fix type annotations.
hasansezertasan Nov 4, 2023
34be3a8
Added type annotations.
hasansezertasan Nov 4, 2023
0c5c779
Improved options method.
hasansezertasan Nov 4, 2023
8d055b0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2023
a061f5f
SimpleMDE added to the third party
hasansezertasan Nov 4, 2023
b8adace
Requested changes granted!
hasansezertasan Nov 5, 2023
56cdae2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2023
4c53e2c
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Nov 6, 2023
9aa089d
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Nov 7, 2023
93ece57
Update starlette_admin/fields.py
hasansezertasan Nov 14, 2023
29353d6
Update starlette_admin/fields.py
hasansezertasan Nov 14, 2023
8d4c017
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Nov 14, 2023
dc9f5d8
Some requests are resolved.
hasansezertasan Nov 14, 2023
415db79
Some requests are resolved.
hasansezertasan Nov 14, 2023
d22457a
Merge branch 'SimpleMDE' of https://github.com/hasansezertasan/starle…
hasansezertasan Nov 14, 2023
2f71de0
Using 'displays/tinymce.html' for SimpleMDEField.
hasansezertasan Nov 14, 2023
0e77883
Remove gitignore changes.
hasansezertasan Nov 14, 2023
8cead59
Rename 'other_options' to 'data_options'
hasansezertasan Nov 14, 2023
249373d
Fixes incorrect variable name.
hasansezertasan Nov 14, 2023
d697829
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Nov 23, 2023
944de90
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Dec 27, 2023
287dcf9
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Dec 29, 2023
c58003e
Used .data instead of .attr.
hasansezertasan Dec 29, 2023
27c240b
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Jan 6, 2024
49a111f
Adoptive changes.
hasansezertasan Jan 11, 2024
247ab71
Merge branch 'jowilf:main' into SimpleMDE
hasansezertasan Jan 11, 2024
655db35
Merge branch 'main' into SimpleMDE
hasansezertasan Jan 13, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Access your admin interface in your browser at [http://localhost:8000/admin](htt
- [jsoneditor](https://github.com/josdejong/jsoneditor)
- [fontawesome](https://fontawesome.com/)
- [TinyMCE](https://www.tiny.cloud/)
- [SimpleMDE](https://simplemde.com/)

## Contributing

Expand Down
1 change: 1 addition & 0 deletions docs/api/fields/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- StringField
- TextAreaField
- TinyMCEEditorField
- SimpleMDEField
- TagsField
- EmailField
- URLField
Expand Down
1 change: 1 addition & 0 deletions starlette_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from .fields import PasswordField as PasswordField
from .fields import PhoneField as PhoneField
from .fields import RelationField as RelationField
from .fields import SimpleMDEField as SimpleMDEField
from .fields import StringField as StringField
from .fields import TagsField as TagsField
from .fields import TextAreaField as TextAreaField
Expand Down
64 changes: 64 additions & 0 deletions starlette_admin/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,70 @@ def input_params(self) -> str:
)


@dataclass
class SimpleMDEField(TextAreaField):
"""A field that provides a Markdown editor for long text content using the
[SimpleMDE](https://simplemde.com/) library.

This field can be used as an alternative to the [TextAreaField][starlette_admin.fields.TextAreaField]
to provide a more sophisticated editor for user input.

Parameters:
version: SimpleMDE version
spell_checker: Enable spell checker
status: Show status bar at the bottom
hide_icons: Hide icons from toolbar
autofocus: Enable autofocus
extra_options: Other options to pass to SimpleMDE
"""

class_: str = "field-simplemde form-control"
display_template: str = "displays/tinymce.html"
version: str = "1.11.2"
placeholder: str = ""
spell_checker: bool = False
status: bool = False
hide_icons: List[str] = dc_field(default_factory=list)
autofocus: bool = True
extra_options: Dict[str, Any] = dc_field(default_factory=dict)
"""For more options, see the [SimpleMDE](https://simplemde.com/)"""

def __post_init__(self) -> None:
super().__post_init__()

def additional_js_links(self, request: Request, action: RequestAction) -> List[str]:
if action.is_form():
return [
f"https://cdn.jsdelivr.net/npm/simplemde@{self.version}/dist/simplemde.min.js",
]
return []

def additional_css_links(
self, request: Request, action: RequestAction
) -> List[str]:
if action.is_form():
return [
f"https://cdn.jsdelivr.net/npm/simplemde@{self.version}/dist/simplemde.min.css",
]
return []

def input_params(self) -> str:
_options = {
"placeholder": self.placeholder,
"spellChecker": self.spell_checker,
"status": self.status,
"hideIcons": self.hide_icons,
"autofocus": self.autofocus,
**self.extra_options,
}

return (
super().input_params()
+ " "
+ html_params({"data-options": json.dumps(_options)})
)


@dataclass
class NumberField(StringField):
"""This field is used to represent the value of properties
Expand Down
15 changes: 15 additions & 0 deletions starlette_admin/statics/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,19 @@ registerFieldInitializer(function (element) {
});

// end TinyMCEEditorField integration

// SimpleMDEField integration

$(".field-simplemde", element).each(function(){
let options = $(this).data("options");
new SimpleMDE({
element: this,
...options
});
});

// end SimpleMDEField integration

}

});