clay-server 3.8.1 → 4.0.0-beta.2
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/lib/ask-user-mcp-server.js +5 -119
- package/lib/builtin-mates.js +6 -6
- package/lib/claude-hook-installer.js +15 -0
- package/lib/clay-history-mcp-server.js +62 -297
- package/lib/daemon.js +1 -1
- package/lib/debate-model-selection.js +119 -0
- package/lib/home-debate-tool-policy.js +164 -0
- package/lib/home-response-notifications.js +26 -0
- package/lib/mate-creation-mcp-server.js +55 -0
- package/lib/mate-ready-creation.js +95 -0
- package/lib/mates.js +2 -0
- package/lib/notes.js +2 -1
- package/lib/project-ask-user.js +64 -0
- package/lib/project-capsule-catalog.js +101 -0
- package/lib/project-connection.js +4 -0
- package/lib/project-debate-proposal.js +133 -17
- package/lib/project-debate.js +214 -110
- package/lib/project-delegated-follow-up.js +84 -0
- package/lib/project-delegated-session.js +53 -0
- package/lib/project-filesystem.js +7 -9
- package/lib/project-knowledge.js +1 -0
- package/lib/project-mate-creation-proposal.js +120 -0
- package/lib/project-memory.js +14 -7
- package/lib/project-models.js +157 -32
- package/lib/project-session-notes.js +2 -2
- package/lib/project-session-pair.js +8 -8
- package/lib/project-sessions.js +66 -51
- package/lib/project-vendor-login.js +397 -0
- package/lib/project-worker-proposal.js +25 -25
- package/lib/project-workspace-query.js +144 -0
- package/lib/project.js +349 -102
- package/lib/public/app.js +85 -42
- package/lib/public/css/avatar-imprints.css +0 -1
- package/lib/public/css/base.css +4 -0
- package/lib/public/css/capsule-ui.css +389 -0
- package/lib/public/css/command-palette.css +306 -6
- package/lib/public/css/home-capsule-library.css +243 -0
- package/lib/public/css/home-capsule-source.css +192 -0
- package/lib/public/css/home-debate-live.css +146 -0
- package/lib/public/css/home-debate-planning.css +125 -0
- package/lib/public/css/home-debates-archive.css +281 -0
- package/lib/public/css/home-hub.css +896 -405
- package/lib/public/css/home-mate-creation.css +34 -0
- package/lib/public/css/home-mate-model-picker.css +131 -0
- package/lib/public/css/home-mate-settings.css +344 -0
- package/lib/public/css/home-session-actions.css +265 -0
- package/lib/public/css/home-sidebar.css +667 -0
- package/lib/public/css/icon-strip.css +1 -2
- package/lib/public/css/mates.css +7 -34
- package/lib/public/css/pane.css +1 -1
- package/lib/public/css/playbook.css +0 -80
- package/lib/public/css/sticky-notes.css +53 -117
- package/lib/public/css/tui-attention.css +0 -44
- package/lib/public/css/workspace-assignment.css +45 -0
- package/lib/public/fonts/source-serif-4/LICENSE.md +93 -0
- package/lib/public/fonts/source-serif-4/SourceSerif4Caption-Semibold.ttf.woff2 +0 -0
- package/lib/public/index.html +93 -74
- package/lib/public/modules/app-connection.js +10 -1
- package/lib/public/modules/app-dm.js +43 -160
- package/lib/public/modules/app-home-hub.js +328 -585
- package/lib/public/modules/app-message-cards.js +242 -0
- package/lib/public/modules/app-message-router.js +84 -0
- package/lib/public/modules/app-messages.js +102 -37
- package/lib/public/modules/app-notifications.js +8 -119
- package/lib/public/modules/app-projects.js +9 -1
- package/lib/public/modules/app-rendering.js +21 -602
- package/lib/public/modules/avatar-imprint.js +11 -8
- package/lib/public/modules/chat-bubble-renderer.js +152 -0
- package/lib/public/modules/chat-render-runtime.js +198 -0
- package/lib/public/modules/command-palette.js +225 -436
- package/lib/public/modules/dm-render.js +82 -0
- package/lib/public/modules/home-capsule-creation-intent.js +31 -0
- package/lib/public/modules/home-capsule-library.js +146 -0
- package/lib/public/modules/home-capsule-source.js +383 -0
- package/lib/public/modules/home-chat-identity.js +35 -0
- package/lib/public/modules/home-chat-scroll.js +77 -0
- package/lib/public/modules/home-chat-stream-state.js +34 -0
- package/lib/public/modules/home-composer-focus.js +25 -0
- package/lib/public/modules/home-conversations-sheet.js +179 -0
- package/lib/public/modules/home-debate-activity.js +48 -0
- package/lib/public/modules/home-debate-controls.js +295 -0
- package/lib/public/modules/home-debate-launch.js +41 -0
- package/lib/public/modules/home-debate-live.js +284 -0
- package/lib/public/modules/home-debate-models.js +73 -0
- package/lib/public/modules/home-debate-planning.js +335 -0
- package/lib/public/modules/home-debates-archive.js +279 -0
- package/lib/public/modules/home-dock-resize.js +74 -0
- package/lib/public/modules/home-dock.js +446 -0
- package/lib/public/modules/home-mate-chat.js +496 -0
- package/lib/public/modules/home-mate-creation.js +109 -0
- package/lib/public/modules/home-mate-model-picker.js +281 -0
- package/lib/public/modules/home-mate-selection.js +38 -0
- package/lib/public/modules/home-mate-settings-menu.js +131 -0
- package/lib/public/modules/home-mate-settings.js +383 -0
- package/lib/public/modules/home-session-actions.js +373 -0
- package/lib/public/modules/home-session-model-confirmation.js +13 -0
- package/lib/public/modules/home-shell.js +9 -0
- package/lib/public/modules/home-sidebar-chat-list.js +63 -0
- package/lib/public/modules/home-sidebar.js +158 -0
- package/lib/public/modules/home-sub-surface.js +19 -0
- package/lib/public/modules/home-surface-boot.js +68 -0
- package/lib/public/modules/home-surface.js +141 -0
- package/lib/public/modules/home-tools.js +271 -0
- package/lib/public/modules/markdown.js +50 -2
- package/lib/public/modules/mate-management.js +86 -0
- package/lib/public/modules/mate-wizard.js +0 -7
- package/lib/public/modules/mention.js +17 -19
- package/lib/public/modules/pane-bridge.js +9 -0
- package/lib/public/modules/profile.js +4 -5
- package/lib/public/modules/project-settings.js +34 -28
- package/lib/public/modules/project-switcher.js +11 -5
- package/lib/public/modules/project-workspace-assignment.js +23 -0
- package/lib/public/modules/search-clay-chat.js +402 -0
- package/lib/public/modules/server-settings.js +14 -12
- package/lib/public/modules/session-actions.js +1 -1
- package/lib/public/modules/sidebar-mates.js +56 -552
- package/lib/public/modules/sidebar-mobile.js +7 -64
- package/lib/public/modules/sidebar-presence.js +37 -0
- package/lib/public/modules/split-pair-ui.js +13 -13
- package/lib/public/modules/split-view.js +7 -0
- package/lib/public/modules/sticky-notes.js +7 -6
- package/lib/public/modules/tool-input-composition.js +48 -0
- package/lib/public/modules/tool-llm-status.js +167 -0
- package/lib/public/modules/tool-renderer-advanced.js +285 -0
- package/lib/public/modules/tool-renderer-chart.js +158 -0
- package/lib/public/modules/tool-renderer-semantics.js +35 -0
- package/lib/public/modules/tool-renderer.js +464 -0
- package/lib/public/modules/tool-runtime.js +309 -0
- package/lib/public/modules/tool-ui-evaluator.js +97 -0
- package/lib/public/modules/tool-ui-tree.js +21 -0
- package/lib/public/modules/tui-attention.js +10 -0
- package/lib/public/modules/user-settings.js +16 -23
- package/lib/public/modules/vendor-login.js +287 -0
- package/lib/public/modules/worker-proposal.js +2 -2
- package/lib/public/modules/workspace-assignment-card.js +149 -0
- package/lib/public/modules/workspace-assignment-routing.js +4 -0
- package/lib/public/style.css +13 -2
- package/lib/runtime-env.js +65 -0
- package/lib/sdk-bridge.js +120 -32
- package/lib/sdk-message-processor.js +10 -6
- package/lib/server-home-capsule-creation.js +36 -0
- package/lib/server-home-chat-events.js +287 -0
- package/lib/server-home-chat.js +518 -0
- package/lib/server-home-clay-entry.js +65 -0
- package/lib/server-home-clay-session-links.js +26 -0
- package/lib/server-home-debate-planning.js +214 -0
- package/lib/server-home-debates.js +137 -0
- package/lib/server-home-mate-creation.js +261 -0
- package/lib/server-home-models.js +241 -0
- package/lib/server-home-preferences.js +61 -0
- package/lib/server-mates.js +37 -0
- package/lib/server-tools.js +377 -0
- package/lib/server.js +111 -59
- package/lib/session-pair-mcp-server.js +6 -6
- package/lib/sessions.js +18 -3
- package/lib/tool-capsule-source.js +142 -0
- package/lib/tool-control-mcp-server.js +126 -0
- package/lib/tool-llm.js +48 -0
- package/lib/tool-storage.js +77 -0
- package/lib/tool-ui-spec-advanced.js +82 -0
- package/lib/tool-ui-spec.js +261 -0
- package/lib/tools-registry.js +286 -0
- package/lib/users-home-dock-preferences.js +77 -0
- package/lib/users-home-surface-preferences.js +99 -0
- package/lib/users-preferences.js +4 -7
- package/lib/users.js +12 -0
- package/lib/whats-new-content.js +3 -3
- package/lib/workspace-assignment-service.js +420 -0
- package/lib/workspace-query-mcp-server.js +154 -0
- package/lib/workspace-query-service.js +492 -0
- package/lib/ws-schema.js +93 -12
- package/lib/yoke/adapters/acp.js +2 -1
- package/lib/yoke/adapters/antigravity.js +2 -1
- package/lib/yoke/adapters/claude-worker.js +11 -4
- package/lib/yoke/adapters/claude.js +73 -43
- package/lib/yoke/adapters/codex.js +40 -10
- package/lib/yoke/adapters/kiro.js +2 -1
- package/lib/yoke/claude-user-input.js +38 -0
- package/lib/yoke/codex-app-server.js +20 -2
- package/lib/yoke/codex-user-input.js +64 -0
- package/lib/yoke/complete-once.js +164 -0
- package/lib/yoke/index.js +5 -1
- package/lib/yoke/interface.js +19 -0
- package/lib/yoke/mcp-bridge-server.js +2 -6
- package/lib/yoke/user-input.js +254 -0
- package/package.json +3 -2
- package/lib/public/css/home-chat.css +0 -380
- package/lib/public/modules/home-chat.js +0 -438
- package/lib/server-clay-home.js +0 -245
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// Host-owned advanced controls for the safe Capsule UI vocabulary.
|
|
2
|
+
|
|
3
|
+
import { collectionView, normalizeOptions, resolveProps, resolveValue, valueAtPath } from './tool-ui-evaluator.js';
|
|
4
|
+
import { renderChartNode } from './tool-renderer-chart.js';
|
|
5
|
+
|
|
6
|
+
var dialogOpeners = new WeakMap();
|
|
7
|
+
|
|
8
|
+
function nextGroupToken(context, prefix, authoredId) {
|
|
9
|
+
if (authoredId) return authoredId;
|
|
10
|
+
if (!Number.isInteger(context.autoControlIndex) || context.autoControlIndex < 1) context.autoControlIndex = 1;
|
|
11
|
+
return prefix + "-" + context.autoControlIndex++;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function emit(node, props, context, extra) {
|
|
15
|
+
var args = Object.assign({}, resolveValue(props.args || {}, context.state, context.item), extra || {});
|
|
16
|
+
if (node.id) args.controlId = node.id;
|
|
17
|
+
context.emit(node.action, args);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function appendRenderedChildren(target, children, context, renderNode) {
|
|
21
|
+
for (var i = 0; i < children.length; i++) {
|
|
22
|
+
var rendered = renderNode(children[i], context);
|
|
23
|
+
if (rendered) target.appendChild(rendered);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function renderForm(node, props, context, renderNode) {
|
|
28
|
+
var form = document.createElement("form");
|
|
29
|
+
form.className = "tool-form";
|
|
30
|
+
if (props.label) form.setAttribute("aria-label", String(props.label));
|
|
31
|
+
appendRenderedChildren(form, node.children || [], context, renderNode);
|
|
32
|
+
var error = document.createElement("div");
|
|
33
|
+
error.className = "tool-form-error hidden";
|
|
34
|
+
error.setAttribute("role", "alert");
|
|
35
|
+
form.appendChild(error);
|
|
36
|
+
form.addEventListener("submit", function (event) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
var invalid = form.querySelector(":invalid");
|
|
39
|
+
if (invalid) {
|
|
40
|
+
error.textContent = invalid.validationMessage || "Check the highlighted fields.";
|
|
41
|
+
error.classList.remove("hidden");
|
|
42
|
+
invalid.focus();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
error.classList.add("hidden");
|
|
46
|
+
emit(node, props, context, {});
|
|
47
|
+
});
|
|
48
|
+
var submit = document.createElement("button");
|
|
49
|
+
submit.type = "submit";
|
|
50
|
+
submit.className = "tool-button tool-button--variant-primary";
|
|
51
|
+
submit.dataset.toolControlId = node.id || "form-submit-" + context.autoControlIndex++;
|
|
52
|
+
submit.textContent = String(props.submitLabel || "Submit");
|
|
53
|
+
form.appendChild(submit);
|
|
54
|
+
return form;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function renderTabs(node, props, context, renderNode) {
|
|
58
|
+
var wrapper = document.createElement("div");
|
|
59
|
+
wrapper.className = "tool-tabs";
|
|
60
|
+
var list = document.createElement("div");
|
|
61
|
+
list.className = "tool-tab-list";
|
|
62
|
+
list.setAttribute("role", "tablist");
|
|
63
|
+
list.setAttribute("aria-label", String(props.label || "Sections"));
|
|
64
|
+
var panels = document.createElement("div");
|
|
65
|
+
var selected = valueAtPath(context.state, node.bind, context.item);
|
|
66
|
+
var groupToken = nextGroupToken(context, "tabs", node.id);
|
|
67
|
+
var children = node.children || [];
|
|
68
|
+
var dynamic = props.options ? normalizeOptions(props.options) : null;
|
|
69
|
+
var tabs = dynamic ? dynamic.map(function (option) { return { props: option, children: [] }; }) : children;
|
|
70
|
+
var buttons = [];
|
|
71
|
+
for (var i = 0; i < tabs.length; i++) {
|
|
72
|
+
var tab = tabs[i];
|
|
73
|
+
var tabProps = resolveProps(tab.props || {}, context.state, context.item);
|
|
74
|
+
var active = selected === tabProps.value || (selected === undefined && i === 0);
|
|
75
|
+
var button = document.createElement("button");
|
|
76
|
+
button.type = "button";
|
|
77
|
+
button.className = "tool-tab";
|
|
78
|
+
button.textContent = String(tabProps.label);
|
|
79
|
+
button.setAttribute("role", "tab");
|
|
80
|
+
button.setAttribute("aria-selected", active ? "true" : "false");
|
|
81
|
+
button.tabIndex = active ? 0 : -1;
|
|
82
|
+
button.disabled = tabProps.disabled === true;
|
|
83
|
+
var panelId = "tool-tab-panel-" + context.toolId + "-" + groupToken + "-" + i;
|
|
84
|
+
var tabId = "tool-tab-" + context.toolId + "-" + groupToken + "-" + i;
|
|
85
|
+
button.id = tabId;
|
|
86
|
+
button.setAttribute("aria-controls", panelId);
|
|
87
|
+
button.dataset.tabIndex = String(i);
|
|
88
|
+
button.addEventListener("click", function (event) {
|
|
89
|
+
var index = Number(event.currentTarget.dataset.tabIndex);
|
|
90
|
+
emit(node, props, context, { value: resolveProps(tabs[index].props || {}, context.state, context.item).value });
|
|
91
|
+
});
|
|
92
|
+
buttons.push(button);
|
|
93
|
+
list.appendChild(button);
|
|
94
|
+
if (active) {
|
|
95
|
+
var panel = document.createElement("div");
|
|
96
|
+
panel.id = panelId;
|
|
97
|
+
panel.className = "tool-tab-panel";
|
|
98
|
+
panel.setAttribute("role", "tabpanel");
|
|
99
|
+
panel.setAttribute("aria-labelledby", tabId);
|
|
100
|
+
appendRenderedChildren(panel, tab.children || [], context, renderNode);
|
|
101
|
+
panels.appendChild(panel);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
list.addEventListener("keydown", function (event) {
|
|
105
|
+
if (["ArrowLeft", "ArrowRight", "Home", "End"].indexOf(event.key) === -1) return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
var enabled = buttons.filter(function (button) { return !button.disabled; });
|
|
108
|
+
if (!enabled.length) return;
|
|
109
|
+
var index = enabled.indexOf(document.activeElement);
|
|
110
|
+
var next = event.key === "Home" ? 0 : event.key === "End" ? enabled.length - 1 : (index + (event.key === "ArrowRight" ? 1 : -1) + enabled.length) % enabled.length;
|
|
111
|
+
enabled[next].focus();
|
|
112
|
+
});
|
|
113
|
+
wrapper.appendChild(list);
|
|
114
|
+
wrapper.appendChild(panels);
|
|
115
|
+
return wrapper;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function renderDialog(node, props, context, renderNode) {
|
|
119
|
+
var placeholder = document.createElement("span");
|
|
120
|
+
var dialogToken = nextGroupToken(context, "dialog", node.id);
|
|
121
|
+
if (props.open !== true) {
|
|
122
|
+
var openerId = dialogOpeners.get(context.container);
|
|
123
|
+
dialogOpeners.delete(context.container);
|
|
124
|
+
var returnTimer = openerId ? setTimeout(function () {
|
|
125
|
+
var controls = context.container.querySelectorAll("[data-tool-control-id]");
|
|
126
|
+
for (var i = 0; i < controls.length; i++) if (controls[i].dataset.toolControlId === openerId) controls[i].focus({ preventScroll: true });
|
|
127
|
+
}, 0) : null;
|
|
128
|
+
if (returnTimer) context.disposers.push(function () { clearTimeout(returnTimer); });
|
|
129
|
+
return placeholder;
|
|
130
|
+
}
|
|
131
|
+
if (context.activeControlId) dialogOpeners.set(context.container, context.activeControlId);
|
|
132
|
+
var overlay = document.createElement("div");
|
|
133
|
+
overlay.className = "tool-dialog-overlay";
|
|
134
|
+
var dialog = document.createElement("section");
|
|
135
|
+
dialog.className = "tool-dialog";
|
|
136
|
+
dialog.setAttribute("role", "dialog");
|
|
137
|
+
dialog.setAttribute("aria-modal", "true");
|
|
138
|
+
var title = document.createElement("h3");
|
|
139
|
+
var titleId = "tool-dialog-title-" + context.toolId + "-" + dialogToken;
|
|
140
|
+
title.id = titleId;
|
|
141
|
+
title.className = "tool-dialog-title";
|
|
142
|
+
title.textContent = String(props.label);
|
|
143
|
+
dialog.appendChild(title);
|
|
144
|
+
dialog.setAttribute("aria-labelledby", titleId);
|
|
145
|
+
if (props.description) {
|
|
146
|
+
var description = document.createElement("p");
|
|
147
|
+
var descriptionId = "tool-dialog-description-" + context.toolId + "-" + dialogToken;
|
|
148
|
+
description.id = descriptionId;
|
|
149
|
+
description.className = "tool-dialog-description";
|
|
150
|
+
description.textContent = String(props.description);
|
|
151
|
+
dialog.appendChild(description);
|
|
152
|
+
dialog.setAttribute("aria-describedby", descriptionId);
|
|
153
|
+
}
|
|
154
|
+
var close = document.createElement("button");
|
|
155
|
+
close.type = "button";
|
|
156
|
+
close.className = "tool-dialog-close";
|
|
157
|
+
close.textContent = "Close";
|
|
158
|
+
close.setAttribute("aria-label", "Close " + String(props.label));
|
|
159
|
+
close.addEventListener("click", function () { context.emit(props.closeAction, {}); });
|
|
160
|
+
dialog.appendChild(close);
|
|
161
|
+
appendRenderedChildren(dialog, node.children || [], context, renderNode);
|
|
162
|
+
overlay.appendChild(dialog);
|
|
163
|
+
overlay.addEventListener("mousedown", function (event) { if (event.target === overlay) context.emit(props.closeAction, {}); });
|
|
164
|
+
overlay.addEventListener("keydown", function (event) {
|
|
165
|
+
if (event.key === "Escape") { event.preventDefault(); context.emit(props.closeAction, {}); return; }
|
|
166
|
+
if (event.key !== "Tab") return;
|
|
167
|
+
var focusable = dialog.querySelectorAll("button:not(:disabled),input:not(:disabled),select:not(:disabled),textarea:not(:disabled),[tabindex]:not([tabindex='-1'])");
|
|
168
|
+
if (!focusable.length) return;
|
|
169
|
+
var first = focusable[0];
|
|
170
|
+
var last = focusable[focusable.length - 1];
|
|
171
|
+
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
|
172
|
+
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
|
173
|
+
});
|
|
174
|
+
var focusTimer = setTimeout(function () { if (context.container.contains(overlay)) close.focus(); }, 0);
|
|
175
|
+
context.disposers.push(function () { clearTimeout(focusTimer); });
|
|
176
|
+
return overlay;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function renderMenu(node, props, context) {
|
|
180
|
+
var wrapper = document.createElement("div");
|
|
181
|
+
wrapper.className = "tool-menu";
|
|
182
|
+
var trigger = document.createElement("button");
|
|
183
|
+
trigger.type = "button";
|
|
184
|
+
trigger.className = "tool-button tool-button--variant-ghost";
|
|
185
|
+
trigger.dataset.toolControlId = node.id || "menu-trigger-" + context.autoControlIndex++;
|
|
186
|
+
trigger.textContent = String(props.triggerLabel || props.label);
|
|
187
|
+
trigger.setAttribute("aria-haspopup", "menu");
|
|
188
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
189
|
+
var menu = document.createElement("div");
|
|
190
|
+
menu.className = "tool-menu-popup hidden";
|
|
191
|
+
menu.setAttribute("role", "menu");
|
|
192
|
+
menu.setAttribute("aria-label", String(props.label));
|
|
193
|
+
var dynamic = props.options ? normalizeOptions(props.options) : null;
|
|
194
|
+
var items = dynamic ? dynamic.map(function (option) { return { action: node.action, props: { label: option.label, disabled: option.disabled, args: { value: option.value } } }; }) : node.children || [];
|
|
195
|
+
for (var i = 0; i < items.length; i++) {
|
|
196
|
+
var item = document.createElement("button");
|
|
197
|
+
item.type = "button";
|
|
198
|
+
item.className = "tool-menu-item";
|
|
199
|
+
item.setAttribute("role", "menuitem");
|
|
200
|
+
var itemProps = resolveProps(items[i].props || {}, context.state, context.item);
|
|
201
|
+
item.textContent = String(itemProps.label);
|
|
202
|
+
item.disabled = itemProps.disabled === true;
|
|
203
|
+
item.dataset.menuIndex = String(i);
|
|
204
|
+
item.addEventListener("click", function (event) {
|
|
205
|
+
var selected = items[Number(event.currentTarget.dataset.menuIndex)];
|
|
206
|
+
closeMenu(true);
|
|
207
|
+
emit(selected, resolveProps(selected.props || {}, context.state, context.item), context, {});
|
|
208
|
+
});
|
|
209
|
+
menu.appendChild(item);
|
|
210
|
+
}
|
|
211
|
+
function closeMenu(focus) { menu.classList.add("hidden"); trigger.setAttribute("aria-expanded", "false"); if (focus) trigger.focus(); }
|
|
212
|
+
function openMenu() { menu.classList.remove("hidden"); trigger.setAttribute("aria-expanded", "true"); var first = menu.querySelector("[role='menuitem']:not(:disabled)"); if (first) first.focus(); }
|
|
213
|
+
trigger.addEventListener("click", function () { if (menu.classList.contains("hidden")) openMenu(); else closeMenu(false); });
|
|
214
|
+
trigger.addEventListener("keydown", function (event) { if (event.key === "ArrowDown") { event.preventDefault(); openMenu(); } });
|
|
215
|
+
menu.addEventListener("keydown", function (event) {
|
|
216
|
+
var controls = Array.prototype.slice.call(menu.querySelectorAll("[role='menuitem']:not(:disabled)"));
|
|
217
|
+
if (event.key === "Escape") { event.preventDefault(); closeMenu(true); return; }
|
|
218
|
+
if (["ArrowDown", "ArrowUp", "Home", "End"].indexOf(event.key) === -1) return;
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
if (!controls.length) return;
|
|
221
|
+
var current = controls.indexOf(document.activeElement);
|
|
222
|
+
var next = event.key === "Home" ? 0 : event.key === "End" ? controls.length - 1 : (current + (event.key === "ArrowDown" ? 1 : -1) + controls.length) % controls.length;
|
|
223
|
+
controls[next].focus();
|
|
224
|
+
});
|
|
225
|
+
var outside = function (event) { if (!wrapper.contains(event.target)) closeMenu(false); };
|
|
226
|
+
document.addEventListener("mousedown", outside);
|
|
227
|
+
context.disposers.push(function () { document.removeEventListener("mousedown", outside); });
|
|
228
|
+
wrapper.appendChild(trigger);
|
|
229
|
+
wrapper.appendChild(menu);
|
|
230
|
+
return wrapper;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function renderPagination(node, props, context) {
|
|
234
|
+
var nav = document.createElement("nav");
|
|
235
|
+
nav.className = "tool-pagination";
|
|
236
|
+
nav.setAttribute("aria-label", String(props.label || "Pagination"));
|
|
237
|
+
var page = Math.max(1, Number(valueAtPath(context.state, node.bind, context.item)) || 1);
|
|
238
|
+
var total = Math.max(0, Number(props.total) || 0);
|
|
239
|
+
var pageSize = Math.max(1, Math.min(100, Number(props.pageSize) || 20));
|
|
240
|
+
var pages = Math.max(1, Math.ceil(total / pageSize));
|
|
241
|
+
function appendPageButton(target, label, current) {
|
|
242
|
+
var button = document.createElement("button");
|
|
243
|
+
button.type = "button";
|
|
244
|
+
button.className = "tool-button tool-button--variant-ghost";
|
|
245
|
+
button.textContent = label;
|
|
246
|
+
button.disabled = target < 1 || target > pages;
|
|
247
|
+
if (current) button.setAttribute("aria-current", "page");
|
|
248
|
+
button.addEventListener("click", function () { context.emit(props.pageAction, { value: target, pageSize: pageSize }); });
|
|
249
|
+
nav.appendChild(button);
|
|
250
|
+
}
|
|
251
|
+
appendPageButton(page - 1, "Previous", false);
|
|
252
|
+
var first = Math.max(1, Math.min(pages - 4, page - 2));
|
|
253
|
+
var last = Math.min(pages, first + 4);
|
|
254
|
+
for (var pi = first; pi <= last; pi++) appendPageButton(pi, String(pi), pi === page);
|
|
255
|
+
var status = document.createElement("span");
|
|
256
|
+
status.textContent = "Page " + Math.min(page, pages) + " of " + pages;
|
|
257
|
+
status.setAttribute("aria-live", "polite");
|
|
258
|
+
nav.appendChild(status);
|
|
259
|
+
appendPageButton(page + 1, "Next", false);
|
|
260
|
+
if (Array.isArray(props.pageSizes) && props.pageSizeAction) {
|
|
261
|
+
var size = document.createElement("select");
|
|
262
|
+
size.className = "tool-select tool-pagination-size";
|
|
263
|
+
size.setAttribute("aria-label", "Items per page");
|
|
264
|
+
props.pageSizes.slice(0, 10).forEach(function (value) {
|
|
265
|
+
var option = document.createElement("option");
|
|
266
|
+
option.value = String(value);
|
|
267
|
+
option.textContent = String(value) + " per page";
|
|
268
|
+
option.selected = value === pageSize;
|
|
269
|
+
size.appendChild(option);
|
|
270
|
+
});
|
|
271
|
+
size.addEventListener("change", function () { context.emit(props.pageSizeAction, { value: Number(size.value) }); });
|
|
272
|
+
nav.appendChild(size);
|
|
273
|
+
}
|
|
274
|
+
return nav;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function renderAdvancedNode(node, props, context, renderNode) {
|
|
278
|
+
if (node.type === "form") return renderForm(node, props, context, renderNode);
|
|
279
|
+
if (node.type === "tabs") return renderTabs(node, props, context, renderNode);
|
|
280
|
+
if (node.type === "dialog") return renderDialog(node, props, context, renderNode);
|
|
281
|
+
if (node.type === "menu") return renderMenu(node, props, context);
|
|
282
|
+
if (node.type === "pagination") return renderPagination(node, props, context);
|
|
283
|
+
if (node.type === "chart") return renderChartNode(node, props, context);
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Truthful fixed-geometry charts for declarative Capsule UI.
|
|
2
|
+
|
|
3
|
+
import { collectionView, valueAtPath } from './tool-ui-evaluator.js';
|
|
4
|
+
|
|
5
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
6
|
+
|
|
7
|
+
function finiteNumber(value) {
|
|
8
|
+
var number = Number(value);
|
|
9
|
+
return Number.isFinite(number) ? number : 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function positiveNumber(value, fallback) {
|
|
13
|
+
var number = Number(value);
|
|
14
|
+
return Number.isFinite(number) && number > 0 ? number : fallback;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function chartData(state, bind, props, item) {
|
|
18
|
+
var limit = Math.max(1, Math.min(50, Number(props.maxItems) || 50));
|
|
19
|
+
var rows = collectionView(valueAtPath(state, bind, item), { pageSize: limit });
|
|
20
|
+
return rows.map(function (row, index) {
|
|
21
|
+
var category = props.categoryKey ? valueAtPath(row, props.categoryKey, null) : index + 1;
|
|
22
|
+
return {
|
|
23
|
+
label: String(category === undefined || category === null ? "Item " + (index + 1) : category).slice(0, 200),
|
|
24
|
+
value: Math.max(0, finiteNumber(valueAtPath(row, props.valueKey, null))),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function lineGeometry(data) {
|
|
30
|
+
var max = data.reduce(function (result, entry) { return Math.max(result, entry.value); }, 0) || 1;
|
|
31
|
+
return data.map(function (entry, index) {
|
|
32
|
+
return {
|
|
33
|
+
x: data.length === 1 ? 50 : index / (data.length - 1) * 100,
|
|
34
|
+
y: 40 - entry.value / max * 38,
|
|
35
|
+
label: entry.label,
|
|
36
|
+
value: entry.value,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function donutGeometry(data) {
|
|
42
|
+
var limited = data.slice(0, 12);
|
|
43
|
+
var total = limited.reduce(function (sum, entry) { return sum + entry.value; }, 0);
|
|
44
|
+
var offset = 0;
|
|
45
|
+
return limited.map(function (entry, index) {
|
|
46
|
+
var percent = total > 0 ? entry.value / total * 100 : 0;
|
|
47
|
+
var segment = { percent: percent, offset: offset, color: index % 8, label: entry.label, value: entry.value };
|
|
48
|
+
offset += percent;
|
|
49
|
+
return segment;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createSvg(className, viewBox) {
|
|
54
|
+
var svg = document.createElementNS(SVG_NS, "svg");
|
|
55
|
+
svg.setAttribute("class", className);
|
|
56
|
+
svg.setAttribute("viewBox", viewBox);
|
|
57
|
+
svg.setAttribute("aria-hidden", "true");
|
|
58
|
+
svg.setAttribute("focusable", "false");
|
|
59
|
+
return svg;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function appendAccessibleData(figure, data) {
|
|
63
|
+
var list = document.createElement("ul");
|
|
64
|
+
list.className = "tool-chart-data";
|
|
65
|
+
for (var i = 0; i < data.length; i++) {
|
|
66
|
+
var entry = document.createElement("li");
|
|
67
|
+
entry.textContent = data[i].label + ": " + data[i].value;
|
|
68
|
+
list.appendChild(entry);
|
|
69
|
+
}
|
|
70
|
+
figure.appendChild(list);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function renderBar(figure, data) {
|
|
74
|
+
var svg = createSvg("tool-chart-svg tool-chart-bar", "0 0 100 50");
|
|
75
|
+
var max = data.reduce(function (result, entry) { return Math.max(result, entry.value); }, 0) || 1;
|
|
76
|
+
var width = data.length ? Math.max(1, 90 / data.length) : 1;
|
|
77
|
+
for (var i = 0; i < data.length; i++) {
|
|
78
|
+
var height = data[i].value / max * 46;
|
|
79
|
+
var rect = document.createElementNS(SVG_NS, "rect");
|
|
80
|
+
rect.setAttribute("class", "tool-chart-bar-mark");
|
|
81
|
+
rect.setAttribute("x", String(5 + i * width));
|
|
82
|
+
rect.setAttribute("y", String(48 - height));
|
|
83
|
+
rect.setAttribute("width", String(Math.max(1, width - 2)));
|
|
84
|
+
rect.setAttribute("height", String(height));
|
|
85
|
+
svg.appendChild(rect);
|
|
86
|
+
}
|
|
87
|
+
figure.appendChild(svg);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function renderLine(figure, data) {
|
|
91
|
+
var geometry = lineGeometry(data);
|
|
92
|
+
var svg = createSvg("tool-chart-svg tool-chart-line", "0 0 100 40");
|
|
93
|
+
if (geometry.length) {
|
|
94
|
+
var polyline = document.createElementNS(SVG_NS, "polyline");
|
|
95
|
+
polyline.setAttribute("class", "tool-chart-line-path");
|
|
96
|
+
polyline.setAttribute("points", geometry.map(function (point) { return point.x.toFixed(2) + "," + point.y.toFixed(2); }).join(" "));
|
|
97
|
+
svg.appendChild(polyline);
|
|
98
|
+
}
|
|
99
|
+
for (var i = 0; i < geometry.length; i++) {
|
|
100
|
+
var point = document.createElementNS(SVG_NS, "circle");
|
|
101
|
+
point.setAttribute("class", "tool-chart-line-point");
|
|
102
|
+
point.setAttribute("cx", geometry[i].x.toFixed(2));
|
|
103
|
+
point.setAttribute("cy", geometry[i].y.toFixed(2));
|
|
104
|
+
point.setAttribute("r", "1.8");
|
|
105
|
+
svg.appendChild(point);
|
|
106
|
+
}
|
|
107
|
+
figure.appendChild(svg);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function renderDonut(figure, data) {
|
|
111
|
+
var segments = donutGeometry(data);
|
|
112
|
+
var svg = createSvg("tool-chart-svg tool-chart-donut", "0 0 42 42");
|
|
113
|
+
var track = document.createElementNS(SVG_NS, "circle");
|
|
114
|
+
track.setAttribute("class", "tool-chart-donut-track");
|
|
115
|
+
track.setAttribute("cx", "21"); track.setAttribute("cy", "21"); track.setAttribute("r", "15.9155");
|
|
116
|
+
svg.appendChild(track);
|
|
117
|
+
for (var i = 0; i < segments.length; i++) {
|
|
118
|
+
if (segments[i].percent <= 0) continue;
|
|
119
|
+
var circle = document.createElementNS(SVG_NS, "circle");
|
|
120
|
+
circle.setAttribute("class", "tool-chart-donut-segment tool-chart-color-" + segments[i].color);
|
|
121
|
+
circle.setAttribute("cx", "21"); circle.setAttribute("cy", "21"); circle.setAttribute("r", "15.9155");
|
|
122
|
+
circle.setAttribute("stroke-dasharray", segments[i].percent.toFixed(4) + " " + (100 - segments[i].percent).toFixed(4));
|
|
123
|
+
circle.setAttribute("stroke-dashoffset", String(-segments[i].offset.toFixed(4)));
|
|
124
|
+
svg.appendChild(circle);
|
|
125
|
+
}
|
|
126
|
+
figure.appendChild(svg);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function renderChartNode(node, props, context) {
|
|
130
|
+
var figure = document.createElement("figure");
|
|
131
|
+
figure.className = "tool-chart tool-chart--" + props.kind;
|
|
132
|
+
figure.setAttribute("aria-label", String(props.label));
|
|
133
|
+
var caption = document.createElement("figcaption");
|
|
134
|
+
caption.textContent = String(props.label);
|
|
135
|
+
figure.appendChild(caption);
|
|
136
|
+
var data = chartData(context.state, node.bind, props, context.item);
|
|
137
|
+
if (props.kind === "donut") data = data.slice(0, 12);
|
|
138
|
+
if (props.kind === "metric") {
|
|
139
|
+
var metric = document.createElement("strong");
|
|
140
|
+
metric.className = "tool-chart-metric";
|
|
141
|
+
metric.textContent = data.length ? String(data[0].value) : "0";
|
|
142
|
+
figure.appendChild(metric);
|
|
143
|
+
} else if (props.kind === "progress") {
|
|
144
|
+
var maximum = positiveNumber(props.max, 1);
|
|
145
|
+
var current = Math.min(maximum, data.length ? data[0].value : 0);
|
|
146
|
+
var progress = document.createElement("progress");
|
|
147
|
+
progress.className = "tool-chart-progress";
|
|
148
|
+
progress.max = maximum;
|
|
149
|
+
progress.value = current;
|
|
150
|
+
progress.textContent = current + " of " + maximum;
|
|
151
|
+
figure.appendChild(progress);
|
|
152
|
+
data = [{ label: props.label, value: current }];
|
|
153
|
+
} else if (props.kind === "line") renderLine(figure, data);
|
|
154
|
+
else if (props.kind === "donut") renderDonut(figure, data);
|
|
155
|
+
else renderBar(figure, data);
|
|
156
|
+
appendAccessibleData(figure, data);
|
|
157
|
+
return figure;
|
|
158
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Fixed class mapping for the validated Capsule UI semantic grammar.
|
|
2
|
+
|
|
3
|
+
var TOKEN_KEYS = ["tone", "size", "emphasis", "gap", "variant", "align", "justify", "padding", "role"];
|
|
4
|
+
var SAFE_TOKENS = /^[a-z]+(?:-[a-z]+)*$/;
|
|
5
|
+
var TOKEN_VALUES = {
|
|
6
|
+
tone: ["neutral", "accent", "info", "success", "warning", "danger"],
|
|
7
|
+
size: ["xs", "sm", "md", "lg"], emphasis: ["subtle", "regular", "strong"],
|
|
8
|
+
gap: ["none", "xs", "sm", "md", "lg", "xl"],
|
|
9
|
+
variant: ["plain", "inset", "cards", "divided", "outlined", "raised", "callout", "output", "soft", "primary", "secondary", "ghost", "danger"],
|
|
10
|
+
align: ["start", "center", "end", "baseline", "stretch"], justify: ["start", "center", "end", "between"],
|
|
11
|
+
padding: ["none", "sm", "md", "lg"], role: ["body", "muted", "caption", "strong", "output", "display", "section"],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function semanticClasses(base, props) {
|
|
15
|
+
var classes = [base];
|
|
16
|
+
props = props || {};
|
|
17
|
+
for (var i = 0; i < TOKEN_KEYS.length; i++) {
|
|
18
|
+
var key = TOKEN_KEYS[i];
|
|
19
|
+
var value = props[key];
|
|
20
|
+
if (typeof value === "string" && SAFE_TOKENS.test(value) && TOKEN_VALUES[key].indexOf(value) !== -1) classes.push(base + "--" + key + "-" + value);
|
|
21
|
+
}
|
|
22
|
+
if (props.wrap === true) classes.push(base + "--wrap");
|
|
23
|
+
return classes.join(" ");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function appendToolIcon(element, name, label) {
|
|
27
|
+
if (!name) return null;
|
|
28
|
+
var icon = document.createElement("i");
|
|
29
|
+
icon.className = "tool-icon";
|
|
30
|
+
icon.setAttribute("data-lucide", name);
|
|
31
|
+
if (label) icon.setAttribute("aria-label", label);
|
|
32
|
+
else icon.setAttribute("aria-hidden", "true");
|
|
33
|
+
element.appendChild(icon);
|
|
34
|
+
return icon;
|
|
35
|
+
}
|