Skip to content

Commit

Permalink
Merge pull request #156 from anvilistas/client-config
Browse files Browse the repository at this point in the history
support non cdn version using client configs
  • Loading branch information
s-cork authored Sep 10, 2024
2 parents 9c22ccc + 474222e commit bd6e1e8
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ startup_form: null
native_deps: {head_html: ''}
db_schema: {}
renamed: true
config_schema:
client:
cdn: {type: boolean, default_value: true}
4 changes: 2 additions & 2 deletions client_code/Tabulator/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
in_designer = False

from ._js_tabulator import TabulatorModule
from ._js_tabulator import TabulatorModule, theme_url

_RE_SNAKE = RegExp("_[a-z]", "g")
_replace = String.prototype.replace
Expand Down Expand Up @@ -104,7 +104,7 @@ def _inject_theme(theme):
link = document.createElement("link")
if theme in _themes:
theme = "_" + theme if theme != "standard" else ""
theme = f"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/tabulator{theme}.min.css"
theme = theme_url.format(theme)
link.href = theme
link.rel = "stylesheet"
link.crossorigin = "anonymous"
Expand Down
13 changes: 12 additions & 1 deletion client_code/Tabulator/_js_tabulator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2022 Stu Cork

import anvil
from anvil.js import import_from, report_exceptions
from anvil.js.window import Function

# from anvil.js.window import TabulatorModule
url = "https://cdn.skypack.dev/pin/[email protected]/mode=imports,min/optimized/tabulator-tables.js"
url = "https://cdn.skypack.dev/pin/[email protected]/mode=imports,min/optimized/tabulator-tables.js"

theme_url = (
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/tabulator{}.min.css"
)

config = anvil.app.get_client_config("tabulator")
if not config.get("cdn", True):
url = "./_/theme/tabulator-tables/js/tabulator_esm.min.js"
theme_url = "./_/theme/tabulator-tables/css/tabulator{}.min.css"

TabulatorModule = import_from(url)


Expand Down
4 changes: 2 additions & 2 deletions client_code/Tabulator/form_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ container:
properties: {tooltip: '', background: '', foreground: '', border: '', visible: true,
role: null, html: "<div style=\"height:152px; margin:8px 0;\">\n <div class='placeholder-table'></div>\n\
</div>\n\n<script type=\"module\" type=\"text/javascript\">\nimport {TabulatorFull\
\ as Tabulator} from \"https://cdn.skypack.dev/tabulator-tables@6.2.0\";\n\n\
\ as Tabulator} from \"./_/theme/tabulator-tables/js/tabulator_esm.min.js\";\n\n\
let p = Promise.resolve();\nif (!window.anvilTabulatorLoaded) {\n window.anvilTabulatorLoaded\
\ = true;\n const l = document.createElement(\"link\");\n l.href = \"https://cdn.jsdelivr.net/npm/tabulator-tables@6.2.0/dist/css/tabulator_bootstrap3.min.css\"\
\ = true;\n const l = document.createElement(\"link\");\n l.href = \"./_/theme/tabulator-tables/css/tabulator_bootstrap3.min.css\"\
;\n l.rel = \"stylesheet\";\n p = new Promise((resolve) => {\n l.onload\
\ = resolve;\n l.onerror = resolve;\n });\n document.body.appendChild(l);\n\
}\n\np.then(() => {\n $('.placeholder-table').each(function() {\n new Tabulator(this,\
Expand Down
2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator.min.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_bulma.min.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_midnight.min.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_modern.min.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_simple.min.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_site.min.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions theme/assets/tabulator-tables/css/tabulator_site_dark.min.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions theme/assets/tabulator-tables/js/tabulator_esm.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions theme/assets/tabulator-tables/js/tabulator_esm.min.js.map

Large diffs are not rendered by default.

0 comments on commit bd6e1e8

Please sign in to comment.