@symbiotejs/symbiote 3.8.3 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -2
- package/core/AppRouter.js +97 -58
- package/core/PubSub.js +42 -11
- package/core/Symbiote.js +90 -59
- package/core/itemizeProcessor-keyed.js +88 -188
- package/core/itemizeProcessor.js +1 -12
- package/core/itemizeSetup.js +26 -3
- package/core/ownElements.js +1 -4
- package/core/resolveTemplate.js +12 -0
- package/core/tpl-processors.js +3 -3
- package/docs/README.md +5 -4
- package/docs/html-app-vs-htmx.md +55 -0
- package/docs/lifecycle.md +2 -0
- package/docs/list-rendering.md +10 -2
- package/docs/properties.md +28 -1
- package/docs/pubsub.md +3 -0
- package/docs/routing.md +15 -4
- package/docs/security.md +41 -12
- package/docs/templates.md +29 -0
- package/html-app/BaseClass.js +203 -0
- package/html-app/README.md +369 -0
- package/html-app/action-data.js +168 -0
- package/html-app/actions.js +366 -0
- package/html-app/collection-actions.js +104 -0
- package/html-app/collection-data.js +234 -0
- package/html-app/collection-items.js +45 -0
- package/html-app/conditions.js +42 -0
- package/html-app/context-data.js +185 -0
- package/html-app/context-requests.js +374 -0
- package/html-app/context-storage.js +376 -0
- package/html-app/declarations.js +55 -0
- package/html-app/examples/assets/actions.html +56 -0
- package/html-app/examples/assets/collections.html +72 -0
- package/html-app/examples/assets/components.html +25 -0
- package/html-app/examples/assets/conditional.html +29 -0
- package/html-app/examples/assets/data.html +31 -0
- package/html-app/examples/assets/guide.html +4 -0
- package/html-app/examples/assets/imports.html +11 -0
- package/html-app/examples/assets/not-found.html +4 -0
- package/html-app/examples/assets/routes.json +58 -0
- package/html-app/examples/assets/routing.html +27 -0
- package/html-app/examples/assets/state.html +32 -0
- package/html-app/examples/assets/storage.html +28 -0
- package/html-app/examples/assets/tasks.json +25 -0
- package/html-app/examples/full-app.html +147 -0
- package/html-app/examples/todo-ref.html +37 -0
- package/html-app/fetch-source.js +147 -0
- package/html-app/fragment-content.js +29 -0
- package/html-app/fragment-source.js +169 -0
- package/html-app/index.js +34 -0
- package/html-app/initial-data.js +88 -0
- package/html-app/pub-map.js +93 -0
- package/html-app/router-data.js +50 -0
- package/html-app/router-navigation.js +70 -0
- package/html-app/storage-revisions.js +130 -0
- package/html-app/sym-collection.js +142 -0
- package/html-app/sym-component.js +20 -0
- package/html-app/sym-conditional.js +141 -0
- package/html-app/sym-context.js +176 -0
- package/html-app/sym-import.js +218 -0
- package/html-app/sym-router.js +107 -0
- package/package.json +18 -8
- package/scripts/check-html-app-package.js +117 -0
- package/scripts/check-html-app-size.js +91 -0
- package/scripts/update-exports.js +4 -0
- package/skills/symbiote/SKILL.md +197 -0
- package/skills/symbiote/agents/openai.yaml +3 -0
- package/types/core/AppRouter.d.ts +13 -4
- package/types/core/AppRouter.d.ts.map +1 -1
- package/types/core/PubSub.d.ts +1 -1
- package/types/core/PubSub.d.ts.map +1 -1
- package/types/core/Symbiote.d.ts +6 -2
- package/types/core/Symbiote.d.ts.map +1 -1
- package/types/core/itemizeProcessor-keyed.d.ts.map +1 -1
- package/types/core/itemizeProcessor.d.ts.map +1 -1
- package/types/core/itemizeSetup.d.ts +1 -0
- package/types/core/itemizeSetup.d.ts.map +1 -1
- package/types/core/ownElements.d.ts +1 -1
- package/types/core/ownElements.d.ts.map +1 -1
- package/types/core/resolveTemplate.d.ts +2 -0
- package/types/core/resolveTemplate.d.ts.map +1 -0
- package/types/html-app/BaseClass.d.ts +24 -0
- package/types/html-app/BaseClass.d.ts.map +1 -0
- package/types/html-app/action-data.d.ts +15 -0
- package/types/html-app/action-data.d.ts.map +1 -0
- package/types/html-app/actions.d.ts +104 -0
- package/types/html-app/actions.d.ts.map +1 -0
- package/types/html-app/collection-actions.d.ts +12 -0
- package/types/html-app/collection-actions.d.ts.map +1 -0
- package/types/html-app/collection-data.d.ts +13 -0
- package/types/html-app/collection-data.d.ts.map +1 -0
- package/types/html-app/collection-items.d.ts +7 -0
- package/types/html-app/collection-items.d.ts.map +1 -0
- package/types/html-app/conditions.d.ts +5 -0
- package/types/html-app/conditions.d.ts.map +1 -0
- package/types/html-app/context-data.d.ts +31 -0
- package/types/html-app/context-data.d.ts.map +1 -0
- package/types/html-app/context-requests.d.ts +97 -0
- package/types/html-app/context-requests.d.ts.map +1 -0
- package/types/html-app/context-storage.d.ts +102 -0
- package/types/html-app/context-storage.d.ts.map +1 -0
- package/types/html-app/declarations.d.ts +3 -0
- package/types/html-app/declarations.d.ts.map +1 -0
- package/types/html-app/fetch-source.d.ts +23 -0
- package/types/html-app/fetch-source.d.ts.map +1 -0
- package/types/html-app/fragment-content.d.ts +6 -0
- package/types/html-app/fragment-content.d.ts.map +1 -0
- package/types/html-app/fragment-source.d.ts +14 -0
- package/types/html-app/fragment-source.d.ts.map +1 -0
- package/types/html-app/index.d.ts +9 -0
- package/types/html-app/index.d.ts.map +1 -0
- package/types/html-app/initial-data.d.ts +8 -0
- package/types/html-app/initial-data.d.ts.map +1 -0
- package/types/html-app/pub-map.d.ts +19 -0
- package/types/html-app/pub-map.d.ts.map +1 -0
- package/types/html-app/router-data.d.ts +4 -0
- package/types/html-app/router-data.d.ts.map +1 -0
- package/types/html-app/router-navigation.d.ts +3 -0
- package/types/html-app/router-navigation.d.ts.map +1 -0
- package/types/html-app/storage-revisions.d.ts +11 -0
- package/types/html-app/storage-revisions.d.ts.map +1 -0
- package/types/html-app/sym-collection.d.ts +16 -0
- package/types/html-app/sym-collection.d.ts.map +1 -0
- package/types/html-app/sym-component.d.ts +5 -0
- package/types/html-app/sym-component.d.ts.map +1 -0
- package/types/html-app/sym-conditional.d.ts +10 -0
- package/types/html-app/sym-conditional.d.ts.map +1 -0
- package/types/html-app/sym-context.d.ts +16 -0
- package/types/html-app/sym-context.d.ts.map +1 -0
- package/types/html-app/sym-import.d.ts +19 -0
- package/types/html-app/sym-import.d.ts.map +1 -0
- package/types/html-app/sym-router.d.ts +12 -0
- package/types/html-app/sym-router.d.ts.map +1 -0
- package/docs/llms-index.md +0 -49
- package/llms-full.txt +0 -5432
- package/llms.txt +0 -49
- package/scripts/build-llms.js +0 -56
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<section class="grid gap-5">
|
|
2
|
+
<p class="max-w-3xl text-sm leading-relaxed text-muted"><code>sym-import</code> fetches trusted authored HTML, initializes its components and bindings, and resolves relative URLs against the fragment. Every feature section in this app uses it. The nested fragment below edits the surrounding preferences context.</p>
|
|
3
|
+
<div class="panel grid gap-4">
|
|
4
|
+
<h2 class="font-semibold">Imported fragment with outgoing binding</h2>
|
|
5
|
+
<sym-import src="./guide.html">
|
|
6
|
+
<p bind="hidden: !+loading">Loading fragment...</p>
|
|
7
|
+
<p class="text-rose-500" bind="textContent: +loadErrorMessage"></p>
|
|
8
|
+
</sym-import>
|
|
9
|
+
</div>
|
|
10
|
+
<sym-conditional when="PREFERENCES/showCounts" is="true"><p class="rounded-lg bg-accent/10 p-4 text-sm text-accent">Task counts are enabled in the Collections section.</p></sym-conditional>
|
|
11
|
+
</section>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"routes": {
|
|
3
|
+
"state": {
|
|
4
|
+
"href": "?state",
|
|
5
|
+
"src": "./assets/state.html",
|
|
6
|
+
"title": "State & bindings",
|
|
7
|
+
"default": true
|
|
8
|
+
},
|
|
9
|
+
"actions": {
|
|
10
|
+
"href": "?actions",
|
|
11
|
+
"src": "./assets/actions.html",
|
|
12
|
+
"title": "Actions & forms"
|
|
13
|
+
},
|
|
14
|
+
"collections": {
|
|
15
|
+
"href": "?collections",
|
|
16
|
+
"src": "./assets/collections.html",
|
|
17
|
+
"title": "Collections"
|
|
18
|
+
},
|
|
19
|
+
"components": {
|
|
20
|
+
"href": "?components",
|
|
21
|
+
"src": "./assets/components.html",
|
|
22
|
+
"title": "Components"
|
|
23
|
+
},
|
|
24
|
+
"conditional": {
|
|
25
|
+
"href": "?conditional",
|
|
26
|
+
"src": "./assets/conditional.html",
|
|
27
|
+
"title": "Conditional content"
|
|
28
|
+
},
|
|
29
|
+
"imports": {
|
|
30
|
+
"href": "?imports",
|
|
31
|
+
"src": "./assets/imports.html",
|
|
32
|
+
"title": "HTML imports"
|
|
33
|
+
},
|
|
34
|
+
"data": {
|
|
35
|
+
"href": "?data",
|
|
36
|
+
"src": "./assets/data.html",
|
|
37
|
+
"title": "JSON requests"
|
|
38
|
+
},
|
|
39
|
+
"storage": {
|
|
40
|
+
"href": "?storage",
|
|
41
|
+
"src": "./assets/storage.html",
|
|
42
|
+
"title": "Browser storage"
|
|
43
|
+
},
|
|
44
|
+
"routing": {
|
|
45
|
+
"href": "?routing",
|
|
46
|
+
"src": "./assets/routing.html",
|
|
47
|
+
"title": "Routing",
|
|
48
|
+
"source": "direct",
|
|
49
|
+
"tab": "example"
|
|
50
|
+
},
|
|
51
|
+
"notFound": {
|
|
52
|
+
"href": "?notFound",
|
|
53
|
+
"src": "./assets/not-found.html",
|
|
54
|
+
"title": "Page not found",
|
|
55
|
+
"error": true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<section class="grid gap-5">
|
|
2
|
+
<p class="max-w-3xl text-sm leading-relaxed text-muted">The shell's <code>sym-router</code> configures native AppRouter and publishes route, title and URL options. <code>[navigate]</code> works on controls and explicitly bound links. Browser Back/Forward keeps working. There is one application router; views compose existing imports and conditionals.</p>
|
|
3
|
+
<sym-context ctx="ROUTE_DEMO">
|
|
4
|
+
<script type="application/json">{"parameters": {"source": "button", "tab": "example"}}</script>
|
|
5
|
+
<div class="panel grid gap-4">
|
|
6
|
+
<h2 class="font-semibold">URL-driven tabs</h2>
|
|
7
|
+
<sym-context bind="$: ROUTER/+params">
|
|
8
|
+
<nav class="flex overflow-x-auto border-b border-line">
|
|
9
|
+
<button class="tab-link" type="button" value="routing" action-data="ROUTE_DEMO/parameters" bind="onclick: [navigate]ROUTER">Example
|
|
10
|
+
<sym-conditional when="^tab" is="example"><span class="absolute inset-x-0 bottom-0 border-b-2 border-accent"></span></sym-conditional>
|
|
11
|
+
</button>
|
|
12
|
+
<a class="tab-link" href="../full-app.html?routing&source=link&tab=details" bind="onclick: [navigate]ROUTER">Details
|
|
13
|
+
<sym-conditional when="^tab" is="details"><span class="absolute inset-x-0 bottom-0 border-b-2 border-accent"></span></sym-conditional>
|
|
14
|
+
</a>
|
|
15
|
+
</nav>
|
|
16
|
+
<div class="grid gap-3 rounded-lg bg-accent/10 p-4">
|
|
17
|
+
<p class="text-sm">Source: <strong>{{source}}</strong> / selected tab: <strong>{{tab}}</strong></p>
|
|
18
|
+
<sym-conditional when="^tab" is="example"><p>Example view selected. Choose Details to switch tabs through a link.</p></sym-conditional>
|
|
19
|
+
<sym-conditional when="^tab" is="details"><p>Details view selected. Choose Example to switch tabs through a button.</p></sym-conditional>
|
|
20
|
+
</div>
|
|
21
|
+
</sym-context>
|
|
22
|
+
<p class="text-sm">Route: {{ROUTER/route}} / title: {{ROUTER/title}}</p>
|
|
23
|
+
<p class="text-sm text-muted">The tabs navigate with <code>[navigate]ROUTER</code>; <code>bind="$: ROUTER/+params"</code> consumes the selected tab from the URL. Route metadata supplies defaults. Reload and Back/Forward preserve the selection.</p>
|
|
24
|
+
</div>
|
|
25
|
+
</sym-context>
|
|
26
|
+
<p class="text-sm text-muted">For path URLs, give every route a pattern such as <code>/tasks/:id</code> and configure the host's SPA fallback. This static example uses query routes.</p>
|
|
27
|
+
</section>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<section class="grid gap-5">
|
|
2
|
+
<p class="max-w-3xl text-sm leading-relaxed text-muted">A context owns JSON data. Native <code>bind="$: ..."</code> supplies an object to a child; <code>pub-to</code> writes edits back. <code>pub-map</code> publishes several local properties to named destinations.</p>
|
|
3
|
+
<sym-context ctx="PROFILE">
|
|
4
|
+
<script type="application/json">
|
|
5
|
+
{"person": {"name": "Alex", "role": "Designer"}, "namePreview": "", "rolePreview": ""}
|
|
6
|
+
</script>
|
|
7
|
+
<div class="grid gap-5 lg:grid-cols-2">
|
|
8
|
+
<sym-context bind="$: PROFILE/person" pub-to="PROFILE/person"
|
|
9
|
+
pub-map="PROFILE/namePreview: name; PROFILE/rolePreview: role">
|
|
10
|
+
<div class="panel grid gap-4">
|
|
11
|
+
<h2 class="font-semibold">Edit the child context</h2>
|
|
12
|
+
<label>Name<input bind="value: name; oninput: [pub-to]name"></label>
|
|
13
|
+
<label>Role<select bind="value: role; onchange: [pub-to]role">
|
|
14
|
+
<option>Designer</option><option>Developer</option><option>Reviewer</option>
|
|
15
|
+
</select></label>
|
|
16
|
+
</div>
|
|
17
|
+
</sym-context>
|
|
18
|
+
<div class="panel grid content-start gap-5">
|
|
19
|
+
<h2 class="font-semibold">Parent object and outgoing fields</h2>
|
|
20
|
+
<sym-context bind="$: PROFILE/person">
|
|
21
|
+
<p class="text-2xl font-semibold">{{name}}</p>
|
|
22
|
+
<p class="text-muted">{{role}}</p>
|
|
23
|
+
</sym-context>
|
|
24
|
+
<p class="border-t border-line pt-4 text-sm">Published with <code>pub-map</code>: {{PROFILE/namePreview}} / {{PROFILE/rolePreview}}</p>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</sym-context>
|
|
28
|
+
<sym-component process-inner-html="false">
|
|
29
|
+
<pre class="panel overflow-auto text-sm text-muted"><code><p>{{name}}</p></code></pre>
|
|
30
|
+
</sym-component>
|
|
31
|
+
<p class="text-sm text-muted"><code>process-inner-html="false"</code> keeps the code sample literal; nested components can still process their own content.</p>
|
|
32
|
+
</section>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<section class="grid gap-5">
|
|
2
|
+
<p class="max-w-3xl text-sm leading-relaxed text-muted"><code>storage-key</code> and <code>storage-keys</code> opt into browser storage. <code>[persist]</code> saves selected fields; <code>[restore]</code> explicitly accepts them. These operations are separate from backend synchronization. Cross-tab changes flag a conflict without replacing your draft.</p>
|
|
3
|
+
<div class="panel grid max-w-xl gap-4">
|
|
4
|
+
<h2 class="font-semibold">Save tasks and preferences on this device</h2>
|
|
5
|
+
<label>List title<input bind="value: PREFERENCES/title; oninput: [pub-to]PREFERENCES/title"></label>
|
|
6
|
+
<label class="field-row"><input type="checkbox" bind="checked: PREFERENCES/showCounts; onchange: [pub-to]PREFERENCES/showCounts">Show task counts</label>
|
|
7
|
+
<div class="field-row flex-wrap">
|
|
8
|
+
<button type="button" class="primary" bind="onclick: [persist]APP">Save in this browser</button>
|
|
9
|
+
<button type="button" bind="onclick: [restore]APP">Restore browser data</button>
|
|
10
|
+
</div>
|
|
11
|
+
<p class="text-sm text-amber-500" bind="hidden: !APP/+storageDirty">Browser changes are not saved.</p>
|
|
12
|
+
<p class="text-sm text-muted">Saved fields: tasks, settings and sorting.</p>
|
|
13
|
+
<div class="flex flex-wrap gap-4 text-sm text-accent underline underline-offset-4">
|
|
14
|
+
<a href="?storage">Reload this page</a>
|
|
15
|
+
<a href="?storage" target="_blank">Open a second tab</a>
|
|
16
|
+
</div>
|
|
17
|
+
<sym-conditional when="APP/+storageError"><p class="text-sm text-rose-500" bind="textContent: APP/+storageErrorMessage"></p></sym-conditional>
|
|
18
|
+
</div>
|
|
19
|
+
<sym-conditional when="APP/+storageConflict">
|
|
20
|
+
<div class="panel grid gap-3 border-amber-400">
|
|
21
|
+
<p>Another tab changed the saved data. Choose which version to keep.</p>
|
|
22
|
+
<div class="field-row flex-wrap">
|
|
23
|
+
<button type="button" bind="onclick: [restore]APP">Use saved data</button>
|
|
24
|
+
<button type="button" action-overwrite bind="onclick: [persist]APP">Keep this draft</button>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</sym-conditional>
|
|
28
|
+
</section>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tasks": [
|
|
3
|
+
{
|
|
4
|
+
"id": "outline",
|
|
5
|
+
"title": "Outline the next release",
|
|
6
|
+
"note": "Keep the scope small and the acceptance checks concrete.",
|
|
7
|
+
"done": false,
|
|
8
|
+
"pinned": true
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "review",
|
|
12
|
+
"title": "Review the new workspace",
|
|
13
|
+
"note": "Try filters, notes, preferences and browser saving.",
|
|
14
|
+
"done": false,
|
|
15
|
+
"pinned": false
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "source",
|
|
19
|
+
"title": "Connect the JSON source",
|
|
20
|
+
"note": "Initial tasks load from this JSON file; Save tasks keeps edits in your browser.",
|
|
21
|
+
"done": true,
|
|
22
|
+
"pinned": false
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>HTML-app features</title>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
|
8
|
+
<script type="module" src="../index.js" webmcp-mode="true"></script>
|
|
9
|
+
<style type="text/tailwindcss">
|
|
10
|
+
@theme {
|
|
11
|
+
--color-paper: #f5f5f5;
|
|
12
|
+
--color-surface: #ffffff;
|
|
13
|
+
--color-ink: #171717;
|
|
14
|
+
--color-muted: #666666;
|
|
15
|
+
--color-line: #e5e5e5;
|
|
16
|
+
--color-accent: #2563eb;
|
|
17
|
+
--color-on-accent: #ffffff;
|
|
18
|
+
}
|
|
19
|
+
@layer base {
|
|
20
|
+
[data-dark] {
|
|
21
|
+
--color-paper: #171717;
|
|
22
|
+
--color-surface: #262626;
|
|
23
|
+
--color-ink: #f5f5f5;
|
|
24
|
+
--color-muted: #a3a3a3;
|
|
25
|
+
--color-line: #404040;
|
|
26
|
+
--color-accent: #60a5fa;
|
|
27
|
+
--color-on-accent: #171717;
|
|
28
|
+
color-scheme: dark;
|
|
29
|
+
}
|
|
30
|
+
button, a, summary {
|
|
31
|
+
@apply cursor-pointer;
|
|
32
|
+
}
|
|
33
|
+
button {
|
|
34
|
+
@apply inline-flex h-10 shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-line bg-surface px-3 text-sm font-medium transition hover:border-accent;
|
|
35
|
+
}
|
|
36
|
+
input:not([type="checkbox"]), select, textarea {
|
|
37
|
+
@apply w-full min-w-0 rounded-lg border border-line bg-surface px-3 text-sm outline-none focus:border-accent;
|
|
38
|
+
}
|
|
39
|
+
input:not([type="checkbox"]), select {
|
|
40
|
+
@apply h-10;
|
|
41
|
+
}
|
|
42
|
+
textarea {
|
|
43
|
+
@apply py-3;
|
|
44
|
+
}
|
|
45
|
+
input[type="checkbox"] {
|
|
46
|
+
@apply size-4 shrink-0 accent-accent;
|
|
47
|
+
}
|
|
48
|
+
label {
|
|
49
|
+
@apply grid gap-2 text-sm;
|
|
50
|
+
}
|
|
51
|
+
button:disabled {
|
|
52
|
+
@apply cursor-wait opacity-40;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
@layer components {
|
|
56
|
+
.panel {
|
|
57
|
+
@apply rounded-2xl border border-line bg-surface p-5;
|
|
58
|
+
}
|
|
59
|
+
.primary {
|
|
60
|
+
@apply border-transparent bg-accent text-on-accent hover:opacity-90;
|
|
61
|
+
}
|
|
62
|
+
.nav-link {
|
|
63
|
+
@apply flex h-11 items-center justify-between rounded-lg px-3 text-sm font-medium hover:bg-accent/10;
|
|
64
|
+
}
|
|
65
|
+
.tab-link {
|
|
66
|
+
@apply relative inline-flex h-10 shrink-0 items-center justify-center rounded-none border-0 bg-transparent px-4 text-sm font-medium text-muted hover:text-ink;
|
|
67
|
+
}
|
|
68
|
+
.tab-link:has(> sym-conditional:not([hidden])) {
|
|
69
|
+
@apply text-accent;
|
|
70
|
+
}
|
|
71
|
+
.field-row {
|
|
72
|
+
@apply flex min-w-0 items-center gap-3;
|
|
73
|
+
}
|
|
74
|
+
task-card {
|
|
75
|
+
@apply block rounded-xl border border-line bg-surface p-4;
|
|
76
|
+
}
|
|
77
|
+
task-card:has(input[type="checkbox"]:checked) input[name="title"] {
|
|
78
|
+
@apply text-muted line-through;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
82
|
+
</head>
|
|
83
|
+
<body>
|
|
84
|
+
<!-- Shared data stays mounted while feature sections load and unload. -->
|
|
85
|
+
<sym-context ctx="ENDPOINTS">
|
|
86
|
+
<script type="application/json">
|
|
87
|
+
{"source": "./assets/tasks.json", "destination": "/api/tasks", "method": "PUT"}
|
|
88
|
+
</script>
|
|
89
|
+
<sym-context ctx="APP" sync-keys="tasks" storage-key="html-app-workspace" storage-keys="tasks,settings,sort"
|
|
90
|
+
bind="@src: ENDPOINTS/source; @sync: ENDPOINTS/destination; @sync-method: ENDPOINTS/method">
|
|
91
|
+
<script type="application/json">
|
|
92
|
+
{
|
|
93
|
+
"tasks": [],
|
|
94
|
+
"draft": {"title": "", "note": "", "done": false, "pinned": false},
|
|
95
|
+
"settings": {"title": "Project board", "dark": false, "showCounts": true},
|
|
96
|
+
"filter": {},
|
|
97
|
+
"allFilter": {},
|
|
98
|
+
"activeFilter": {"done": false},
|
|
99
|
+
"completedFilter": {"done": true},
|
|
100
|
+
"completePatch": {"done": true},
|
|
101
|
+
"sort": {"field": "title", "direction": "asc"},
|
|
102
|
+
"query": "",
|
|
103
|
+
"shown": 0,
|
|
104
|
+
"total": 0
|
|
105
|
+
}
|
|
106
|
+
</script>
|
|
107
|
+
<sym-context ctx="PREFERENCES" bind="$: APP/settings" pub-to="APP/settings">
|
|
108
|
+
<div class="grid min-h-dvh bg-paper text-ink md:h-dvh md:grid-cols-[14rem_minmax(0,1fr)]" bind="@data-dark: dark">
|
|
109
|
+
<aside class="flex flex-col gap-6 border-b border-line bg-surface p-5 md:overflow-y-auto md:border-r md:border-b-0">
|
|
110
|
+
<p class="text-lg font-semibold tracking-tight">HTML-app<span class="text-accent">.</span></p>
|
|
111
|
+
<nav class="grid gap-1" itemize="ROUTER/routes">
|
|
112
|
+
<template>
|
|
113
|
+
<a class="nav-link" bind="@href: href; @hidden: !!error; onclick: [navigate]ROUTER">{{title}}
|
|
114
|
+
<sym-conditional when="ROUTER/route" bind="@is: _KEY_">
|
|
115
|
+
<span class="size-1.5 rounded-full bg-accent"></span>
|
|
116
|
+
</sym-conditional>
|
|
117
|
+
</a>
|
|
118
|
+
</template>
|
|
119
|
+
</nav>
|
|
120
|
+
<div class="mt-auto border-t border-line pt-5">
|
|
121
|
+
<label class="field-row"><input type="checkbox" bind="checked: dark; onchange: [pub-to]dark">Dark mode</label>
|
|
122
|
+
</div>
|
|
123
|
+
</aside>
|
|
124
|
+
<main class="min-w-0 md:overflow-y-auto">
|
|
125
|
+
<sym-router ctx="ROUTER" src="./assets/routes.json" use-template="#app-shell"></sym-router>
|
|
126
|
+
</main>
|
|
127
|
+
</div>
|
|
128
|
+
</sym-context>
|
|
129
|
+
</sym-context>
|
|
130
|
+
</sym-context>
|
|
131
|
+
|
|
132
|
+
<template id="app-shell">
|
|
133
|
+
<header class="sticky top-0 z-10 flex items-center justify-between gap-4 border-b border-line bg-surface/95 px-6 py-4 backdrop-blur">
|
|
134
|
+
<h1 class="text-xl font-semibold tracking-tight">{{title}}</h1>
|
|
135
|
+
<a class="text-sm text-accent underline underline-offset-4" href="./todo-ref.html">Basic Todo</a>
|
|
136
|
+
</header>
|
|
137
|
+
<div class="mx-auto grid max-w-5xl gap-5 p-5 lg:p-8">
|
|
138
|
+
<p class="text-sm text-muted" bind="hidden: !+loading">Loading routes...</p>
|
|
139
|
+
<p class="panel text-sm text-rose-500" bind="hidden: !+loadError; textContent: +loadErrorMessage"></p>
|
|
140
|
+
<sym-import bind="@src: ROUTER/+src">
|
|
141
|
+
<p class="text-sm text-muted" bind="hidden: !+loading">Loading content...</p>
|
|
142
|
+
<p class="panel text-sm text-rose-500" bind="hidden: !+loadError; textContent: +loadErrorMessage"></p>
|
|
143
|
+
</sym-import>
|
|
144
|
+
</div>
|
|
145
|
+
</template>
|
|
146
|
+
</body>
|
|
147
|
+
</html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Todo</title>
|
|
6
|
+
<script type="module" src="../index.js"></script>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<sym-context ctx="APP">
|
|
10
|
+
<script type="application/json">
|
|
11
|
+
{
|
|
12
|
+
"tasks": [],
|
|
13
|
+
"draft": {"title": "", "done": false}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
<h1>Todo</h1>
|
|
17
|
+
<sym-context bind="$: APP/draft" pub-to="APP/draft">
|
|
18
|
+
<form action-data="APP/draft" action-reset="APP/draft" bind="onsubmit: [append]APP/tasks">
|
|
19
|
+
<input placeholder="New task" required bind="value: title; oninput: [pub-to]title">
|
|
20
|
+
<button>Add task</button>
|
|
21
|
+
</form>
|
|
22
|
+
</sym-context>
|
|
23
|
+
<sym-collection data="APP/tasks">
|
|
24
|
+
<ul itemize="items">
|
|
25
|
+
<template>
|
|
26
|
+
<li>
|
|
27
|
+
<input type="checkbox" bind="checked: done; onchange: [item-pub]done">
|
|
28
|
+
<input required bind="value: title; oninput: [item-pub]title">
|
|
29
|
+
<button bind="onclick: [item-remove]">Delete</button>
|
|
30
|
+
</li>
|
|
31
|
+
</template>
|
|
32
|
+
</ul>
|
|
33
|
+
<p bind="hidden: !empty">No tasks yet.</p>
|
|
34
|
+
</sym-collection>
|
|
35
|
+
</sym-context>
|
|
36
|
+
</body>
|
|
37
|
+
</html>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export class SourceError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} code
|
|
4
|
+
* @param {string} message
|
|
5
|
+
* @param {number | null} [status]
|
|
6
|
+
*/
|
|
7
|
+
constructor(code, message, status = null) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = status;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} source
|
|
16
|
+
* @param {string} base
|
|
17
|
+
*/
|
|
18
|
+
export function sourceURL(source, base) {
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(source, base);
|
|
22
|
+
} catch {
|
|
23
|
+
throw new SourceError('INVALID_URL', 'Expected an HTTP(S) source URL.');
|
|
24
|
+
}
|
|
25
|
+
if (!source.trim() || ![
|
|
26
|
+
'http:',
|
|
27
|
+
'https:',
|
|
28
|
+
].includes(url.protocol) || url.username || url.password) {
|
|
29
|
+
throw new SourceError('INVALID_URL', 'Expected an HTTP(S) URL without embedded credentials.');
|
|
30
|
+
}
|
|
31
|
+
url.hash = '';
|
|
32
|
+
return url.href;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {Element} owner
|
|
37
|
+
*/
|
|
38
|
+
export function requestLimits(owner) {
|
|
39
|
+
let read = (/** @type {string} */ name, /** @type {number} */ fallback) => {
|
|
40
|
+
let value = owner.hasAttribute(name) ? Number(owner.getAttribute(name)) : fallback;
|
|
41
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > 2147483647) {
|
|
42
|
+
throw new SourceError('INVALID_CONFIG', name + ' must be a positive integer.');
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
timeout: read('request-timeout', 15000),
|
|
48
|
+
maxBytes: read('max-bytes', 1048576),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Shared bounded text transport for JSON sources and authored fragments.
|
|
54
|
+
* @param {string} url
|
|
55
|
+
* @param {{ signal: AbortSignal, timeout: number, maxBytes: number, method?: string, body?: string }} options
|
|
56
|
+
*/
|
|
57
|
+
export async function fetchSource(url, options) {
|
|
58
|
+
let controller = new AbortController();
|
|
59
|
+
let abort = () => controller.abort(options.signal.reason);
|
|
60
|
+
options.signal.addEventListener('abort', abort, {
|
|
61
|
+
once: true,
|
|
62
|
+
});
|
|
63
|
+
if (options.signal.aborted) {
|
|
64
|
+
abort();
|
|
65
|
+
}
|
|
66
|
+
let timer = setTimeout(() => controller.abort(new SourceError('TIMEOUT', 'The request timed out.')), options.timeout);
|
|
67
|
+
try {
|
|
68
|
+
if (options.body !== undefined && new TextEncoder().encode(options.body).byteLength > options.maxBytes) {
|
|
69
|
+
throw new SourceError('TOO_LARGE', 'The request exceeds max-bytes.');
|
|
70
|
+
}
|
|
71
|
+
let response = await fetch(url, {
|
|
72
|
+
signal: controller.signal,
|
|
73
|
+
method: options.method ?? 'GET',
|
|
74
|
+
body: options.body,
|
|
75
|
+
headers: options.body === undefined ? undefined : {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
},
|
|
78
|
+
credentials: 'same-origin',
|
|
79
|
+
redirect: 'error',
|
|
80
|
+
cache: 'no-store',
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
throw new SourceError('HTTP_ERROR', 'HTTP request failed: ' + response.status + '.', response.status);
|
|
84
|
+
}
|
|
85
|
+
if (Number(response.headers.get('content-length')) > options.maxBytes) {
|
|
86
|
+
throw new SourceError('TOO_LARGE', 'The response exceeds max-bytes.');
|
|
87
|
+
}
|
|
88
|
+
let text = '';
|
|
89
|
+
if (response.body) {
|
|
90
|
+
let reader = response.body.getReader();
|
|
91
|
+
let decoder = new TextDecoder('utf-8', {
|
|
92
|
+
fatal: true,
|
|
93
|
+
});
|
|
94
|
+
let size = 0;
|
|
95
|
+
try {
|
|
96
|
+
while (true) {
|
|
97
|
+
let chunk = await reader.read();
|
|
98
|
+
if (chunk.done) {
|
|
99
|
+
text += decoder.decode();
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
size += chunk.value.byteLength;
|
|
103
|
+
if (size > options.maxBytes) {
|
|
104
|
+
throw new SourceError('TOO_LARGE', 'The response exceeds max-bytes.');
|
|
105
|
+
}
|
|
106
|
+
text += decoder.decode(chunk.value, {
|
|
107
|
+
stream: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
await reader.cancel().catch(() => {});
|
|
112
|
+
reader.releaseLock();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
text,
|
|
117
|
+
status: response.status,
|
|
118
|
+
contentType: response.headers.get('content-type') ?? '',
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (controller.signal.aborted) {
|
|
122
|
+
throw controller.signal.reason;
|
|
123
|
+
}
|
|
124
|
+
if (error instanceof SourceError) {
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
throw new SourceError('NETWORK_ERROR', 'The request could not be completed.');
|
|
128
|
+
} finally {
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
controller.abort();
|
|
131
|
+
options.signal.removeEventListener('abort', abort);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {Awaited<ReturnType<typeof fetchSource>>} response
|
|
137
|
+
*/
|
|
138
|
+
export function parseResponseJSON(response) {
|
|
139
|
+
if (!/^[^;]+\/(?:json|[^;]+\+json)(?:;|$)/i.test(response.contentType)) {
|
|
140
|
+
throw new SourceError('INVALID_CONTENT_TYPE', 'Expected a JSON response.');
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(response.text);
|
|
144
|
+
} catch {
|
|
145
|
+
throw new SourceError('INVALID_DATA', 'The response is not valid JSON.');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Symbiote from '../core/Symbiote.js';
|
|
2
|
+
import BaseClass from './BaseClass.js';
|
|
3
|
+
|
|
4
|
+
// A native owner isolates fragment subscriptions while retaining local scope.
|
|
5
|
+
export class FragmentContent extends BaseClass {
|
|
6
|
+
/** @type {import('../core/PubSub.js').PubSub | undefined} */
|
|
7
|
+
context;
|
|
8
|
+
|
|
9
|
+
get localCtx() {
|
|
10
|
+
return this.context ?? super.localCtx;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
FragmentContent.reg();
|
|
14
|
+
|
|
15
|
+
/** @param {Element} element */
|
|
16
|
+
export function disposeContent(element) {
|
|
17
|
+
for (let child of [
|
|
18
|
+
...element.children,
|
|
19
|
+
...(element.shadowRoot?.children || []),
|
|
20
|
+
]) {
|
|
21
|
+
disposeContent(child);
|
|
22
|
+
}
|
|
23
|
+
if (element instanceof Symbiote) {
|
|
24
|
+
element.destroy();
|
|
25
|
+
if (!element.isConnected) {
|
|
26
|
+
element.ref = Object.create(null);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|