Skip to content

Commit dcddcc4

Browse files
v0.1.3 - Auto-render when @view detected (no attribute needed)
1 parent d595752 commit dcddcc4

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solid-shim",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Minimal Solid data browser using solid-panes-jss with solid-oidc authentication",
55
"type": "module",
66
"main": "dist/solid-shim.js",

src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,18 @@ export { $rdf, panes, UI, authn, authSession, store, solidLogicSingleton }
252252
export { renderView, parseJsonLdToStore }
253253
export type { PaneModule, PaneContext }
254254

255-
// Auto-render: if script tag has data-auto-render attribute, render automatically
256-
// Usage: <script src="solid-shim.min.js" data-auto-render></script>
255+
// Auto-render: if JSON-LD with @view exists, render automatically
256+
// No attribute needed - @view in data IS the opt-in
257257
if (typeof document !== 'undefined') {
258-
const scripts = document.querySelectorAll('script[src*="solid-shim"], script[src*="mashlib"]')
259-
scripts.forEach(script => {
260-
if (script.hasAttribute('data-auto-render')) {
261-
renderView()
258+
const jsonLdScript = document.querySelector('script[type="application/ld+json"]')
259+
if (jsonLdScript) {
260+
try {
261+
const data = JSON.parse(jsonLdScript.textContent || '')
262+
if (data['@view']) {
263+
renderView()
264+
}
265+
} catch (e) {
266+
// Invalid JSON-LD, skip auto-render
262267
}
263-
})
268+
}
264269
}

0 commit comments

Comments
 (0)