-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ImportMapScriptElement renders a json importmap which allows to tell browsers how to resolve javascript dependencies. Signed-off-by: Sylvain Rabot <[email protected]>
- Loading branch information
Showing
13 changed files
with
2,425 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assets/js/*.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
package components | ||
|
||
import ( | ||
"github.com/a-h/templ/examples/typescript/ts" | ||
) | ||
|
||
type Data struct { | ||
Message string `json:"msg"` | ||
} | ||
|
||
var ( | ||
// The importmap is generated outside the template to avoid | ||
// validating the JSON every time the template is executed. | ||
importMapScriptElement = templ.NewImportMapScriptElement("", ts.ImportMapJSON) | ||
) | ||
|
||
templ Page(attributeData Data, scriptData Data) { | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Script usage</title> | ||
<script src="/assets/js/index.js" defer></script> | ||
<title>Typescript</title> | ||
@importMapScriptElement | ||
<script src="/assets/js/alert.js" defer></script> | ||
</head> | ||
<body> | ||
<h2>Alert</h2> | ||
<button id="attributeAlerter" alert-data={ templ.JSONString(attributeData) }>Show alert from data in alert-data attribute</button> | ||
@templ.JSONScript("scriptData", scriptData) | ||
<button id="scriptAlerter">Show alert from data in script</button> | ||
|
||
<h2>Graph</h2> | ||
<div id="graph" style="height: 200px"></div> | ||
<script type="module"> | ||
import graph from "./assets/js/graph.js"; | ||
let container = document.getElementById("graph"); | ||
new graph.Graph(container); | ||
</script> | ||
</body> | ||
</html> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ts | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
//go:embed importmap.json | ||
var ImportMapJSON string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"env": [ | ||
"browser", | ||
"development", | ||
"module" | ||
], | ||
"imports": { | ||
"lightweight-charts": "https://cdn.jsdelivr.net/npm/[email protected]/dist/lightweight-charts.development.mjs" | ||
}, | ||
"scopes": { | ||
"https://cdn.jsdelivr.net/": { | ||
"fancy-canvas": "https://cdn.jsdelivr.net/npm/[email protected]/index.mjs" | ||
} | ||
} | ||
} |
Oops, something went wrong.