@adia-ai/web-modules 0.3.4 → 0.3.6
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/CHANGELOG.md +50 -0
- package/chat/chat-composer/chat-composer.a2ui.json +94 -0
- package/chat/chat-composer/chat-composer.examples.html +28 -0
- package/chat/chat-composer/chat-composer.html +43 -0
- package/chat/chat-composer/chat-composer.js +107 -0
- package/chat/chat-composer/chat-composer.test.js +112 -0
- package/chat/chat-composer/chat-composer.yaml +91 -0
- package/chat/chat-empty/chat-empty.a2ui.json +68 -0
- package/chat/chat-empty/chat-empty.examples.html +34 -0
- package/chat/chat-empty/chat-empty.html +42 -0
- package/chat/chat-empty/chat-empty.yaml +58 -0
- package/chat/chat-header/chat-header.a2ui.json +77 -0
- package/chat/chat-header/chat-header.examples.html +30 -0
- package/chat/chat-header/chat-header.html +42 -0
- package/chat/chat-header/chat-header.yaml +68 -0
- package/chat/chat-shell/chat-shell.css +1 -0
- package/chat/chat-shell/chat-shell.examples.html +43 -2
- package/chat/chat-shell/chat-shell.js +35 -7
- package/chat/chat-shell/css/chat-shell.bespoke.css +196 -0
- package/chat/chat-sidebar/chat-sidebar.a2ui.json +136 -0
- package/chat/chat-sidebar/chat-sidebar.examples.html +36 -0
- package/chat/chat-sidebar/chat-sidebar.html +43 -0
- package/chat/chat-sidebar/chat-sidebar.js +227 -0
- package/chat/chat-sidebar/chat-sidebar.test.js +110 -0
- package/chat/chat-sidebar/chat-sidebar.yaml +140 -0
- package/chat/chat-status/chat-status.a2ui.json +63 -0
- package/chat/chat-status/chat-status.examples.html +29 -0
- package/chat/chat-status/chat-status.html +42 -0
- package/chat/chat-status/chat-status.yaml +52 -0
- package/chat/chat-thread/chat-thread.a2ui.json +91 -0
- package/chat/chat-thread/chat-thread.examples.html +36 -0
- package/chat/chat-thread/chat-thread.html +43 -0
- package/chat/chat-thread/chat-thread.js +106 -0
- package/chat/chat-thread/chat-thread.test.js +82 -0
- package/chat/chat-thread/chat-thread.yaml +89 -0
- package/chat/index.js +3 -0
- package/editor/editor-canvas/editor-canvas.a2ui.json +87 -0
- package/editor/editor-canvas/editor-canvas.js +103 -0
- package/editor/editor-canvas/editor-canvas.test.js +100 -0
- package/editor/editor-canvas/editor-canvas.yaml +88 -0
- package/editor/editor-canvas-empty/editor-canvas-empty.a2ui.json +69 -0
- package/editor/editor-canvas-empty/editor-canvas-empty.yaml +56 -0
- package/editor/editor-shell/css/editor-shell.bespoke.css +172 -0
- package/editor/editor-shell/editor-shell.css +1 -0
- package/editor/editor-shell/editor-shell.js +85 -30
- package/editor/editor-sidebar/editor-sidebar.a2ui.json +88 -0
- package/editor/editor-sidebar/editor-sidebar.js +173 -0
- package/editor/editor-sidebar/editor-sidebar.test.js +126 -0
- package/editor/editor-sidebar/editor-sidebar.yaml +83 -0
- package/editor/editor-statusbar/editor-statusbar.a2ui.json +76 -0
- package/editor/editor-statusbar/editor-statusbar.yaml +57 -0
- package/editor/editor-toolbar/editor-toolbar.a2ui.json +96 -0
- package/editor/editor-toolbar/editor-toolbar.js +58 -0
- package/editor/editor-toolbar/editor-toolbar.test.js +99 -0
- package/editor/editor-toolbar/editor-toolbar.yaml +81 -0
- package/editor/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://adiaui.dev/a2ui/v0_9/components/ChatSidebar.json",
|
|
4
|
+
"title": "ChatSidebar",
|
|
5
|
+
"description": "Module-tier chat-cluster sidebar — owns resize, snap-to-collapsed,\npersistence, and the [collapsed] reflected attribute. Sits inside\n<chat-shell> as slot=\"leading\" (conversation history rail) or\nslot=\"trailing\" (artifacts/citations panel). Mirrors the admin-sidebar\nshape — same 4 concerns, cluster-namespaced for the chat family.\n\nThis is the chat-cluster equivalent of <admin-sidebar> per ADR-0023.\n<chat-shell> doesn't currently have a legacy sidebar shape (chat is\ntypically a single-pane experience), so <chat-sidebar> is purely\nforward-looking — for chat apps that want conversation-history or\ninspector rails.\n",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"allOf": [
|
|
8
|
+
{
|
|
9
|
+
"$ref": "common_types.json#/$defs/ComponentCommon"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"$ref": "common_types.json#/$defs/CatalogComponentCommon"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"collapsed": {
|
|
17
|
+
"description": "Reflected — set when the sidebar's measured width is at or below\n96px. Consumers query this to style \"collapsed mode\" without\nduplicating threshold math.\n",
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"default": false
|
|
20
|
+
},
|
|
21
|
+
"collapsible": {
|
|
22
|
+
"description": "Opts in to programmatic collapse — toggle button wiring + the\n.toggle() / .collapse() / .expand() public methods.\n",
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"default": false
|
|
25
|
+
},
|
|
26
|
+
"component": {
|
|
27
|
+
"const": "ChatSidebar"
|
|
28
|
+
},
|
|
29
|
+
"min-width": {
|
|
30
|
+
"description": "Optional override for the snap-floor width. Defaults to reading\nCSS min-width via getComputedStyle.\n",
|
|
31
|
+
"type": "string",
|
|
32
|
+
"default": ""
|
|
33
|
+
},
|
|
34
|
+
"name": {
|
|
35
|
+
"description": "Identifier for localStorage namespacing. Defaults to slot value\n(\"leading\" or \"trailing\"). Override when running multiple sidebars\nwith the same slot.\n",
|
|
36
|
+
"type": "string",
|
|
37
|
+
"default": ""
|
|
38
|
+
},
|
|
39
|
+
"resizable": {
|
|
40
|
+
"description": "Opts in to drag-to-resize behavior. Author supplies a child\n[data-resize] element as the drag handle.\n",
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": false
|
|
43
|
+
},
|
|
44
|
+
"resizing": {
|
|
45
|
+
"description": "Reflected — set during an active pointer-drag on the resize handle.\nUseful for suppressing transitions while dragging.\n",
|
|
46
|
+
"type": "boolean",
|
|
47
|
+
"default": false
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"required": [
|
|
51
|
+
"component"
|
|
52
|
+
],
|
|
53
|
+
"unevaluatedProperties": false,
|
|
54
|
+
"x-adiaui": {
|
|
55
|
+
"anti_patterns": [],
|
|
56
|
+
"category": "layout",
|
|
57
|
+
"events": {
|
|
58
|
+
"sidebar-resize": {
|
|
59
|
+
"description": "Bubbles when an active pointer-drag releases.",
|
|
60
|
+
"detail": {
|
|
61
|
+
"name": "string",
|
|
62
|
+
"width": "number"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"sidebar-toggle": {
|
|
66
|
+
"description": "Bubbles when sidebar collapses or expands.",
|
|
67
|
+
"detail": {
|
|
68
|
+
"expanded": "boolean",
|
|
69
|
+
"name": "string"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"examples": [],
|
|
74
|
+
"keywords": [
|
|
75
|
+
"chat-sidebar",
|
|
76
|
+
"chat-sidebar",
|
|
77
|
+
"conversation-history",
|
|
78
|
+
"chat-rail",
|
|
79
|
+
"sidebar",
|
|
80
|
+
"leading",
|
|
81
|
+
"trailing",
|
|
82
|
+
"inspector"
|
|
83
|
+
],
|
|
84
|
+
"name": "ChatSidebar",
|
|
85
|
+
"related": [
|
|
86
|
+
"ChatShell",
|
|
87
|
+
"ChatComposer",
|
|
88
|
+
"ChatHeader",
|
|
89
|
+
"List",
|
|
90
|
+
"Nav"
|
|
91
|
+
],
|
|
92
|
+
"slots": {
|
|
93
|
+
"default": {
|
|
94
|
+
"description": "Default content — typically a <nav-ui> for navigation, or a list / tree for the trailing inspector pattern."
|
|
95
|
+
},
|
|
96
|
+
"footer": {
|
|
97
|
+
"description": "Bottom chrome bar (user select, status indicator, etc.)."
|
|
98
|
+
},
|
|
99
|
+
"header": {
|
|
100
|
+
"description": "Top chrome bar (workspace select, breadcrumb, etc.)."
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"states": [
|
|
104
|
+
{
|
|
105
|
+
"description": "Default, expanded.",
|
|
106
|
+
"name": "idle"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"description": "Sidebar width is at or below the snap threshold; CSS container queries flip child layout to icon-only mode.",
|
|
110
|
+
"attribute": "collapsed",
|
|
111
|
+
"name": "collapsed"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"description": "Active pointer-drag in progress.",
|
|
115
|
+
"attribute": "resizing",
|
|
116
|
+
"name": "resizing"
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
"synonyms": {
|
|
120
|
+
"collapsed": [
|
|
121
|
+
"minimized",
|
|
122
|
+
"narrow",
|
|
123
|
+
"icon-only"
|
|
124
|
+
],
|
|
125
|
+
"sidebar": [
|
|
126
|
+
"aside",
|
|
127
|
+
"rail",
|
|
128
|
+
"panel"
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"tag": "chat-sidebar",
|
|
132
|
+
"tokens": {},
|
|
133
|
+
"traits": [],
|
|
134
|
+
"version": 1
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<header>
|
|
2
|
+
<div>
|
|
3
|
+
<h1>Chat Sidebar</h1>
|
|
4
|
+
<div data-actions>
|
|
5
|
+
<tag-ui size="sm">chat-sidebar</tag-ui>
|
|
6
|
+
<tag-ui size="sm" variant="ghost">JS-bearing</tag-ui>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
<p>Module-tier chat-cluster sidebar — mirrors admin-sidebar (resize + collapse + persist), cluster-namespaced for the chat family.</p>
|
|
10
|
+
</header>
|
|
11
|
+
|
|
12
|
+
<section data-section>
|
|
13
|
+
<h2 variant="section">Role</h2>
|
|
14
|
+
<p>Mirrors <code><admin-sidebar></code> — resize drag, snap-to-collapsed, localStorage persistence, ResizeObserver. Cluster-namespaced for the chat family. JS-bearing.</p>
|
|
15
|
+
</section>
|
|
16
|
+
|
|
17
|
+
<section data-section>
|
|
18
|
+
<h2 variant="section">Composition</h2>
|
|
19
|
+
<p>Typical placement inside <code><chat-shell></code>:</p>
|
|
20
|
+
<code-ui language="html"><chat-shell>
|
|
21
|
+
<chat-sidebar slot="leading" resizable collapsible>
|
|
22
|
+
<chat-header slot="header">
|
|
23
|
+
<span slot="name">Conversations</span>
|
|
24
|
+
</chat-header>
|
|
25
|
+
<list-ui>…conversation history…</list-ui>
|
|
26
|
+
<div data-resize></div>
|
|
27
|
+
</chat-sidebar>
|
|
28
|
+
<chat-thread>…</chat-thread>
|
|
29
|
+
<chat-composer>…</chat-composer>
|
|
30
|
+
</chat-shell></code-ui>
|
|
31
|
+
</section>
|
|
32
|
+
|
|
33
|
+
<section data-section>
|
|
34
|
+
<h2 variant="section">Family</h2>
|
|
35
|
+
<p>Per <a href="../../../../.brain/adrs/0023-bespoke-shell-tier-children.md">ADR-0023</a>, the chat cluster's bespoke family — <code><chat-shell></code> (host), <code><chat-thread></code>, <code><chat-composer></code>, <code><chat-sidebar></code> (JS-bearing) + <code><chat-header></code>, <code><chat-status></code>, <code><chat-empty></code> (CSS-only). Mirrors the admin cluster's pattern.</p>
|
|
36
|
+
</section>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" data-theme="auto">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Chat Sidebar — AdiaUI</title>
|
|
7
|
+
|
|
8
|
+
<link rel="stylesheet" href="../../../web-components/styles/resets.css">
|
|
9
|
+
<link rel="stylesheet" href="../../../web-components/styles/tokens.css">
|
|
10
|
+
<link rel="stylesheet" href="../chat-shell/chat-shell.css">
|
|
11
|
+
<link rel="stylesheet" href="../../../web-components/components/code/code.css">
|
|
12
|
+
<link rel="stylesheet" href="../../../web-components/components/tag/tag.css">
|
|
13
|
+
|
|
14
|
+
<script type="module" src="../chat-shell/chat-shell.js"></script>
|
|
15
|
+
<script type="module" src="./chat-sidebar.js"></script>
|
|
16
|
+
<script type="module" src="../../../web-components/components/code/code.js"></script>
|
|
17
|
+
<script type="module" src="../../../web-components/components/tag/tag.js"></script>
|
|
18
|
+
|
|
19
|
+
<style>
|
|
20
|
+
:where(html, body) { margin: 0; min-height: 100vh; background: var(--a-bg); color: var(--a-fg); font-family: var(--a-font); }
|
|
21
|
+
main { max-width: 960px; margin-inline: auto; padding: var(--a-space-6) var(--a-space-5); }
|
|
22
|
+
</style>
|
|
23
|
+
</head>
|
|
24
|
+
<body>
|
|
25
|
+
|
|
26
|
+
<main id="demo-root">
|
|
27
|
+
<p>Loading examples…</p>
|
|
28
|
+
</main>
|
|
29
|
+
|
|
30
|
+
<script type="module">
|
|
31
|
+
const root = document.getElementById('demo-root');
|
|
32
|
+
try {
|
|
33
|
+
const res = await fetch('./chat-sidebar.examples.html');
|
|
34
|
+
if (!res.ok) throw new Error(`fetch failed (${res.status})`);
|
|
35
|
+
root.innerHTML = await res.text();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
root.innerHTML = `<p style="color:var(--a-danger-strong);">Failed to load chat-sidebar.examples.html — ${err.message}</p>`;
|
|
38
|
+
console.error('[chat-sidebar.html]', err);
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <chat-sidebar slot="leading|trailing" resizable collapsible>
|
|
3
|
+
* <chat-header slot="header">…</chat-header> (or any chrome bar)
|
|
4
|
+
* …default content (nav, list, etc.)…
|
|
5
|
+
* <chat-status slot="footer">…</chat-status>
|
|
6
|
+
* </chat-sidebar>
|
|
7
|
+
*
|
|
8
|
+
* Module-tier chat-cluster sidebar — owns resize, snap-to-collapsed, persistence,
|
|
9
|
+
* and the [collapsed] reflected attribute. Sits inside <chat-shell>
|
|
10
|
+
* but doesn't reach into it; the shell coordinates without orchestrating
|
|
11
|
+
* child internals.
|
|
12
|
+
*
|
|
13
|
+
* Reflected attributes (the consumer-queryable state):
|
|
14
|
+
* [collapsed] — set when sidebar width is at or below SNAP_THRESHOLD
|
|
15
|
+
* [resizing] — set during an active pointer-drag
|
|
16
|
+
*
|
|
17
|
+
* Author-supplied attributes (read once at connect, never overwritten):
|
|
18
|
+
* [slot="leading"|"trailing"] — required, drives drag direction +
|
|
19
|
+
* localStorage namespacing
|
|
20
|
+
* [resizable] — opts in to drag handle wiring
|
|
21
|
+
* [collapsible] — opts in to programmatic collapse
|
|
22
|
+
* (toggle button + window.toggle())
|
|
23
|
+
* [name="<id>"] — optional override for the localStorage
|
|
24
|
+
* key. Defaults to slot value.
|
|
25
|
+
* [min-width="48px"] — optional override for the snap-floor
|
|
26
|
+
* width (otherwise reads CSS min-width)
|
|
27
|
+
*
|
|
28
|
+
* Events:
|
|
29
|
+
* sidebar-toggle — bubbles. detail: { name, expanded }
|
|
30
|
+
* sidebar-resize — bubbles. detail: { name, width }
|
|
31
|
+
*
|
|
32
|
+
* The drag handle is conventional: a child `[data-resize]` element.
|
|
33
|
+
* Authors may provide a custom one, or omit (no resize affordance).
|
|
34
|
+
*
|
|
35
|
+
* Backwards compat: <chat-shell> still recognizes the legacy
|
|
36
|
+
* `<aside data-sidebar="leading">` shape via :is() selector. New
|
|
37
|
+
* code should prefer <chat-sidebar>.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import { UIElement } from '../../../web-components/core/element.js';
|
|
41
|
+
|
|
42
|
+
const SNAP_THRESHOLD = 96;
|
|
43
|
+
const SNAP_MIN_USABLE = 160;
|
|
44
|
+
|
|
45
|
+
class ChatSidebar extends UIElement {
|
|
46
|
+
static properties = {
|
|
47
|
+
collapsed: { type: Boolean, default: false, reflect: true },
|
|
48
|
+
resizing: { type: Boolean, default: false, reflect: true },
|
|
49
|
+
resizable: { type: Boolean, default: false, reflect: true },
|
|
50
|
+
collapsible: { type: Boolean, default: false, reflect: true },
|
|
51
|
+
name: { type: String, default: '', reflect: true },
|
|
52
|
+
minWidth: { type: String, default: '', reflect: true, attribute: 'min-width' },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static template = () => null;
|
|
56
|
+
|
|
57
|
+
// The width the sidebar had before being collapsed — used for restore.
|
|
58
|
+
// Map keyed by sidebar name allows multiple sidebars on one host.
|
|
59
|
+
#previousExpandedWidth = '';
|
|
60
|
+
#resizeCleanups = [];
|
|
61
|
+
#childRO = null;
|
|
62
|
+
|
|
63
|
+
connected() {
|
|
64
|
+
this.#restoreFromStorage();
|
|
65
|
+
if (this.resizable) this.#setupResizeHandle();
|
|
66
|
+
this.#setupChildResizeObserver();
|
|
67
|
+
this.#syncCollapsedFromWidth();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
disconnected() {
|
|
71
|
+
for (const cleanup of this.#resizeCleanups) cleanup();
|
|
72
|
+
this.#resizeCleanups = [];
|
|
73
|
+
this.#childRO?.disconnect();
|
|
74
|
+
this.#childRO = null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ── Public API (callable from <chat-shell> or external code) ──
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Toggle collapsed state. Collapses if expanded, restores if collapsed.
|
|
81
|
+
* Returns the new collapsed value.
|
|
82
|
+
*/
|
|
83
|
+
toggle() {
|
|
84
|
+
if (this.collapsed) {
|
|
85
|
+
this.expand();
|
|
86
|
+
} else {
|
|
87
|
+
this.collapse();
|
|
88
|
+
}
|
|
89
|
+
return this.collapsed;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Collapse to the snap-floor width. Persists to localStorage. */
|
|
93
|
+
collapse() {
|
|
94
|
+
if (this.collapsed) return;
|
|
95
|
+
// Remember current expanded width before collapsing
|
|
96
|
+
const currentWidth = this.style.width || getComputedStyle(this).width;
|
|
97
|
+
if (parseFloat(currentWidth) > SNAP_THRESHOLD) {
|
|
98
|
+
this.#previousExpandedWidth = currentWidth;
|
|
99
|
+
}
|
|
100
|
+
const minW = this.minWidth || getComputedStyle(this).minWidth;
|
|
101
|
+
this.style.width = minW;
|
|
102
|
+
this.#persist(minW);
|
|
103
|
+
this.collapsed = true;
|
|
104
|
+
this.#dispatchToggle(false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Restore to the previous expanded width (or default if none). */
|
|
108
|
+
expand() {
|
|
109
|
+
if (!this.collapsed) return;
|
|
110
|
+
const restoreWidth = this.#previousExpandedWidth || '';
|
|
111
|
+
this.style.width = restoreWidth;
|
|
112
|
+
this.#persist(restoreWidth);
|
|
113
|
+
this.collapsed = false;
|
|
114
|
+
this.#dispatchToggle(true);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ── Persistence ──
|
|
118
|
+
|
|
119
|
+
#storageKey() {
|
|
120
|
+
const id = this.name || this.getAttribute('slot') || 'default';
|
|
121
|
+
return `adia-chat-sidebar-${id}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#persist(width) {
|
|
125
|
+
try { localStorage.setItem(this.#storageKey(), width); } catch {}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#restoreFromStorage() {
|
|
129
|
+
try {
|
|
130
|
+
const saved = localStorage.getItem(this.#storageKey());
|
|
131
|
+
if (!saved) return;
|
|
132
|
+
this.style.width = saved;
|
|
133
|
+
// Only treat as "previous expanded" if actually expanded
|
|
134
|
+
const w = parseFloat(saved);
|
|
135
|
+
if (!isNaN(w) && w > SNAP_THRESHOLD) {
|
|
136
|
+
this.#previousExpandedWidth = saved;
|
|
137
|
+
}
|
|
138
|
+
} catch {}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ── Reflect [collapsed] from current measured width ──
|
|
142
|
+
|
|
143
|
+
#syncCollapsedFromWidth() {
|
|
144
|
+
const w = this.getBoundingClientRect().width;
|
|
145
|
+
this.collapsed = w <= SNAP_THRESHOLD;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ── Resize drag handle ──
|
|
149
|
+
|
|
150
|
+
#setupResizeHandle() {
|
|
151
|
+
const handle = this.querySelector(':scope > [data-resize]');
|
|
152
|
+
if (!handle) return;
|
|
153
|
+
|
|
154
|
+
const slot = this.getAttribute('slot');
|
|
155
|
+
const isLeading = slot === 'leading';
|
|
156
|
+
|
|
157
|
+
const onPointerDown = (e) => {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
handle.setPointerCapture(e.pointerId);
|
|
160
|
+
const startX = e.clientX;
|
|
161
|
+
const startW = this.getBoundingClientRect().width;
|
|
162
|
+
this.resizing = true;
|
|
163
|
+
document.documentElement.style.cursor = 'col-resize';
|
|
164
|
+
|
|
165
|
+
const onMove = (e) => {
|
|
166
|
+
const dx = e.clientX - startX;
|
|
167
|
+
const max = parseInt(getComputedStyle(this).getPropertyValue('max-width')) || 480;
|
|
168
|
+
const w = Math.max(48, Math.min(max, startW + (isLeading ? dx : -dx)));
|
|
169
|
+
this.style.width = `${w}px`;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const onUp = () => {
|
|
173
|
+
this.resizing = false;
|
|
174
|
+
document.documentElement.style.cursor = '';
|
|
175
|
+
handle.removeEventListener('pointermove', onMove);
|
|
176
|
+
handle.removeEventListener('pointerup', onUp);
|
|
177
|
+
|
|
178
|
+
// Snap logic
|
|
179
|
+
const w = this.getBoundingClientRect().width;
|
|
180
|
+
if (w <= SNAP_THRESHOLD) {
|
|
181
|
+
this.style.width = this.minWidth || getComputedStyle(this).minWidth;
|
|
182
|
+
} else if (w < SNAP_MIN_USABLE) {
|
|
183
|
+
this.style.width = `${SNAP_MIN_USABLE}px`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.#persist(this.style.width);
|
|
187
|
+
this.#syncCollapsedFromWidth();
|
|
188
|
+
this.dispatchEvent(new CustomEvent('sidebar-resize', {
|
|
189
|
+
bubbles: true,
|
|
190
|
+
detail: { name: this.name || slot, width: this.getBoundingClientRect().width },
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
handle.addEventListener('pointermove', onMove);
|
|
195
|
+
handle.addEventListener('pointerup', onUp);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
handle.addEventListener('pointerdown', onPointerDown);
|
|
199
|
+
this.#resizeCleanups.push(() => handle.removeEventListener('pointerdown', onPointerDown));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ── Child ResizeObserver — flips select-ui placement in narrow mode ──
|
|
203
|
+
|
|
204
|
+
#setupChildResizeObserver() {
|
|
205
|
+
this.#childRO = new ResizeObserver((entries) => {
|
|
206
|
+
for (const entry of entries) {
|
|
207
|
+
const narrow = entry.contentBoxSize[0].inlineSize <= SNAP_THRESHOLD;
|
|
208
|
+
for (const sel of this.querySelectorAll('select-ui')) {
|
|
209
|
+
sel.setAttribute('placement', narrow ? 'right' : 'bottom-start');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
this.#childRO.observe(this);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ── Internal — dispatch the toggle event in a consistent shape ──
|
|
217
|
+
|
|
218
|
+
#dispatchToggle(expanded) {
|
|
219
|
+
this.dispatchEvent(new CustomEvent('sidebar-toggle', {
|
|
220
|
+
bubbles: true,
|
|
221
|
+
detail: { name: this.name || this.getAttribute('slot') || 'default', expanded },
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
customElements.define('chat-sidebar', ChatSidebar);
|
|
227
|
+
export { ChatSidebar };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import '../../../web-components/core/element.js';
|
|
3
|
+
import './chat-sidebar.js';
|
|
4
|
+
|
|
5
|
+
const tick = () => new Promise((r) => queueMicrotask(r));
|
|
6
|
+
|
|
7
|
+
function mount(html) {
|
|
8
|
+
const wrap = document.createElement('div');
|
|
9
|
+
wrap.innerHTML = html;
|
|
10
|
+
document.body.appendChild(wrap);
|
|
11
|
+
return wrap.firstElementChild;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let originalRect;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
document.body.innerHTML = '';
|
|
17
|
+
try { localStorage.clear(); } catch {}
|
|
18
|
+
globalThis.ResizeObserver = class {
|
|
19
|
+
observe() {} unobserve() {} disconnect() {}
|
|
20
|
+
};
|
|
21
|
+
originalRect = HTMLElement.prototype.getBoundingClientRect;
|
|
22
|
+
HTMLElement.prototype.getBoundingClientRect = function () {
|
|
23
|
+
const inline = this.style?.width || '';
|
|
24
|
+
const w = parseFloat(inline) || 240;
|
|
25
|
+
return { width: w, height: 600, top: 0, left: 0, right: w, bottom: 600, x: 0, y: 0 };
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
if (originalRect) HTMLElement.prototype.getBoundingClientRect = originalRect;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('chat-sidebar', () => {
|
|
34
|
+
it('registers chat-sidebar as a custom element', () => {
|
|
35
|
+
expect(customElements.get('chat-sidebar')).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('defaults to collapsed=false on connect', () => {
|
|
39
|
+
const sb = mount('<chat-sidebar slot="leading"></chat-sidebar>');
|
|
40
|
+
expect(sb.collapsed).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('reflects [collapsed] via property assignment', async () => {
|
|
44
|
+
const sb = mount('<chat-sidebar slot="leading"></chat-sidebar>');
|
|
45
|
+
sb.collapsed = true;
|
|
46
|
+
await tick();
|
|
47
|
+
expect(sb.hasAttribute('collapsed')).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('reflects [resizing] via property assignment', async () => {
|
|
51
|
+
const sb = mount('<chat-sidebar slot="leading"></chat-sidebar>');
|
|
52
|
+
sb.resizing = true;
|
|
53
|
+
await tick();
|
|
54
|
+
expect(sb.hasAttribute('resizing')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('exposes .toggle() / .collapse() / .expand() public methods', () => {
|
|
58
|
+
const sb = mount('<chat-sidebar slot="leading" collapsible></chat-sidebar>');
|
|
59
|
+
expect(typeof sb.toggle).toBe('function');
|
|
60
|
+
expect(typeof sb.collapse).toBe('function');
|
|
61
|
+
expect(typeof sb.expand).toBe('function');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('persists width to chat-namespaced localStorage key (not collide with admin)', async () => {
|
|
65
|
+
const sb = mount('<chat-sidebar slot="leading" collapsible></chat-sidebar>');
|
|
66
|
+
sb.style.width = '240px';
|
|
67
|
+
sb.collapse();
|
|
68
|
+
expect(sb.collapsed).toBe(true);
|
|
69
|
+
// localStorage key should be chat-namespaced
|
|
70
|
+
expect(localStorage.getItem('adia-chat-sidebar-leading')).not.toBeNull();
|
|
71
|
+
// Should NOT have written to the admin namespace
|
|
72
|
+
expect(localStorage.getItem('adia-sidebar-leading')).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('uses [name] override for the localStorage key', () => {
|
|
76
|
+
const sb = mount('<chat-sidebar slot="leading" name="conversations" collapsible></chat-sidebar>');
|
|
77
|
+
sb.style.width = '200px';
|
|
78
|
+
sb.collapse();
|
|
79
|
+
expect(localStorage.getItem('adia-chat-sidebar-conversations')).not.toBeNull();
|
|
80
|
+
expect(localStorage.getItem('adia-chat-sidebar-leading')).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('toggle() returns the new collapsed value', () => {
|
|
84
|
+
const sb = mount('<chat-sidebar slot="leading" collapsible></chat-sidebar>');
|
|
85
|
+
sb.style.width = '200px';
|
|
86
|
+
const result = sb.toggle();
|
|
87
|
+
expect(result).toBe(sb.collapsed);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('dispatches sidebar-toggle event on toggle()', () => {
|
|
91
|
+
const sb = mount('<chat-sidebar slot="leading" collapsible></chat-sidebar>');
|
|
92
|
+
sb.style.width = '200px';
|
|
93
|
+
const onToggle = vi.fn();
|
|
94
|
+
sb.addEventListener('sidebar-toggle', onToggle);
|
|
95
|
+
sb.toggle();
|
|
96
|
+
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(onToggle.mock.calls[0][0].detail).toEqual(
|
|
98
|
+
expect.objectContaining({ name: expect.any(String), expanded: expect.any(Boolean) })
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('cleans up resize handlers on disconnect', () => {
|
|
103
|
+
const sb = mount('<chat-sidebar slot="leading" resizable><div data-resize></div></chat-sidebar>');
|
|
104
|
+
const handle = sb.querySelector('[data-resize]');
|
|
105
|
+
const removeSpy = vi.spyOn(handle, 'removeEventListener');
|
|
106
|
+
sb.remove();
|
|
107
|
+
const removedTypes = removeSpy.mock.calls.map((args) => args[0]);
|
|
108
|
+
expect(removedTypes).toContain('pointerdown');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Edit this file; run `npm run build:components` to regenerate a2ui.json.
|
|
2
|
+
$schema: ../../../../scripts/schemas/component.yaml.schema.json
|
|
3
|
+
name: ChatSidebar
|
|
4
|
+
tag: chat-sidebar
|
|
5
|
+
component: ChatSidebar
|
|
6
|
+
category: layout
|
|
7
|
+
version: 1
|
|
8
|
+
description: |
|
|
9
|
+
Module-tier chat-cluster sidebar — owns resize, snap-to-collapsed,
|
|
10
|
+
persistence, and the [collapsed] reflected attribute. Sits inside
|
|
11
|
+
<chat-shell> as slot="leading" (conversation history rail) or
|
|
12
|
+
slot="trailing" (artifacts/citations panel). Mirrors the admin-sidebar
|
|
13
|
+
shape — same 4 concerns, cluster-namespaced for the chat family.
|
|
14
|
+
|
|
15
|
+
This is the chat-cluster equivalent of <admin-sidebar> per ADR-0023.
|
|
16
|
+
<chat-shell> doesn't currently have a legacy sidebar shape (chat is
|
|
17
|
+
typically a single-pane experience), so <chat-sidebar> is purely
|
|
18
|
+
forward-looking — for chat apps that want conversation-history or
|
|
19
|
+
inspector rails.
|
|
20
|
+
|
|
21
|
+
props:
|
|
22
|
+
collapsed:
|
|
23
|
+
description: |
|
|
24
|
+
Reflected — set when the sidebar's measured width is at or below
|
|
25
|
+
96px. Consumers query this to style "collapsed mode" without
|
|
26
|
+
duplicating threshold math.
|
|
27
|
+
type: boolean
|
|
28
|
+
default: false
|
|
29
|
+
reflect: true
|
|
30
|
+
|
|
31
|
+
resizing:
|
|
32
|
+
description: |
|
|
33
|
+
Reflected — set during an active pointer-drag on the resize handle.
|
|
34
|
+
Useful for suppressing transitions while dragging.
|
|
35
|
+
type: boolean
|
|
36
|
+
default: false
|
|
37
|
+
reflect: true
|
|
38
|
+
|
|
39
|
+
resizable:
|
|
40
|
+
description: |
|
|
41
|
+
Opts in to drag-to-resize behavior. Author supplies a child
|
|
42
|
+
[data-resize] element as the drag handle.
|
|
43
|
+
type: boolean
|
|
44
|
+
default: false
|
|
45
|
+
reflect: true
|
|
46
|
+
|
|
47
|
+
collapsible:
|
|
48
|
+
description: |
|
|
49
|
+
Opts in to programmatic collapse — toggle button wiring + the
|
|
50
|
+
.toggle() / .collapse() / .expand() public methods.
|
|
51
|
+
type: boolean
|
|
52
|
+
default: false
|
|
53
|
+
reflect: true
|
|
54
|
+
|
|
55
|
+
name:
|
|
56
|
+
description: |
|
|
57
|
+
Identifier for localStorage namespacing. Defaults to slot value
|
|
58
|
+
("leading" or "trailing"). Override when running multiple sidebars
|
|
59
|
+
with the same slot.
|
|
60
|
+
type: string
|
|
61
|
+
default: ""
|
|
62
|
+
reflect: true
|
|
63
|
+
|
|
64
|
+
min-width:
|
|
65
|
+
description: |
|
|
66
|
+
Optional override for the snap-floor width. Defaults to reading
|
|
67
|
+
CSS min-width via getComputedStyle.
|
|
68
|
+
type: string
|
|
69
|
+
default: ""
|
|
70
|
+
reflect: true
|
|
71
|
+
|
|
72
|
+
events:
|
|
73
|
+
sidebar-toggle:
|
|
74
|
+
description: Bubbles when sidebar collapses or expands.
|
|
75
|
+
detail:
|
|
76
|
+
name: string
|
|
77
|
+
expanded: boolean
|
|
78
|
+
sidebar-resize:
|
|
79
|
+
description: Bubbles when an active pointer-drag releases.
|
|
80
|
+
detail:
|
|
81
|
+
name: string
|
|
82
|
+
width: number
|
|
83
|
+
|
|
84
|
+
slots:
|
|
85
|
+
default:
|
|
86
|
+
description: >-
|
|
87
|
+
Default content — typically a <nav-ui> for navigation, or a list
|
|
88
|
+
/ tree for the trailing inspector pattern.
|
|
89
|
+
header:
|
|
90
|
+
description: >-
|
|
91
|
+
Top chrome bar (workspace select, breadcrumb, etc.).
|
|
92
|
+
footer:
|
|
93
|
+
description: >-
|
|
94
|
+
Bottom chrome bar (user select, status indicator, etc.).
|
|
95
|
+
|
|
96
|
+
states:
|
|
97
|
+
- name: idle
|
|
98
|
+
description: Default, expanded.
|
|
99
|
+
- name: collapsed
|
|
100
|
+
attribute: collapsed
|
|
101
|
+
description: Sidebar width is at or below the snap threshold; CSS
|
|
102
|
+
container queries flip child layout to icon-only mode.
|
|
103
|
+
- name: resizing
|
|
104
|
+
attribute: resizing
|
|
105
|
+
description: Active pointer-drag in progress.
|
|
106
|
+
|
|
107
|
+
traits: []
|
|
108
|
+
|
|
109
|
+
a2ui:
|
|
110
|
+
rules:
|
|
111
|
+
- >-
|
|
112
|
+
chat-sidebar is the bespoke replacement for legacy
|
|
113
|
+
<aside data-sidebar>. Use slot="leading" or slot="trailing"
|
|
114
|
+
to position. Add resizable + collapsible attributes to opt in
|
|
115
|
+
to interactive behaviors.
|
|
116
|
+
- >-
|
|
117
|
+
For chrome bars inside the sidebar, prefer <admin-topbar
|
|
118
|
+
slot="header"> and <admin-statusbar slot="footer"> over raw
|
|
119
|
+
<header-ui> / <footer-ui> when authoring shell-tier markup.
|
|
120
|
+
|
|
121
|
+
keywords:
|
|
122
|
+
- chat-sidebar
|
|
123
|
+
- chat-sidebar
|
|
124
|
+
- conversation-history
|
|
125
|
+
- chat-rail
|
|
126
|
+
- sidebar
|
|
127
|
+
- leading
|
|
128
|
+
- trailing
|
|
129
|
+
- inspector
|
|
130
|
+
|
|
131
|
+
synonyms:
|
|
132
|
+
sidebar: [aside, rail, panel]
|
|
133
|
+
collapsed: [minimized, narrow, icon-only]
|
|
134
|
+
|
|
135
|
+
related:
|
|
136
|
+
- ChatShell
|
|
137
|
+
- ChatComposer
|
|
138
|
+
- ChatHeader
|
|
139
|
+
- List
|
|
140
|
+
- Nav
|