Skip to content

Commit

Permalink
Back to configuring presets, sorry
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Dec 17, 2024
1 parent 3125f04 commit d72571d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ additional assets to load:
from js_asset import JS
DJANGO_PROSE_EDITOR_ASSETS = [
JS("prose-editors/announcements.js", {"defer": True}),
]
DJANGO_PROSE_EDITOR_PRESETS = {
"announcements": [
JS("prose-editors/announcements.js", {"defer": True}),
],
}
The preset can be selected when instantiating the field:

Expand Down
20 changes: 14 additions & 6 deletions django_prose_editor/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def base_media(self):
]
},
js=[
JS("django_prose_editor/editor.js", {"defer": True}),
JSON(
{
"stylesheets": [
Expand All @@ -39,18 +38,27 @@ def base_media(self):
},
"django-prose-editor-settings",
),
JS("django_prose_editor/init.js", {"defer": True}),
JS("django_prose_editor/editor.js", {"defer": True}),
],
)

@property
def media(self):
return (
(self.base_media + forms.Media(js=assets))
if (assets := getattr(settings, "DJANGO_PROSE_EDITOR_ASSETS", ()))
else self.base_media
return self.base_media + forms.Media(
js=[
JS("django_prose_editor/editor.js", {"defer": True}),
*self.get_presets()[self.preset],
]
)

def get_presets(self):
return {
"default": [
JS("django_prose_editor/editor.js", {"defer": True}),
JS("django_prose_editor/default.js", {"defer": True}),
],
} | getattr(settings, "DJANGO_PROSE_EDITOR_PRESETS", {})

def get_config(self):
return self.config or {
"types": None,
Expand Down
2 changes: 1 addition & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import postcss from "esbuild-postcss"

const devMode = process.argv.includes("watch")
const ctx = await esbuild.context({
entryPoints: ["./src/init.js", "./src/overrides.css", "./src/editor.js"],
entryPoints: ["./src/default.js", "./src/overrides.css", "./src/editor.js"],
minify: true,
bundle: true,
target: "es6",
Expand Down
File renamed without changes.

0 comments on commit d72571d

Please sign in to comment.