meowtail 0.4.0-alpha.0 → 0.4.0-alpha.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/ASSISTANT.md +2 -2
- package/AUTHORING.md +268 -0
- package/CHANGELOG.md +116 -0
- package/COMPONENTS.md +182 -140
- package/README.md +145 -34
- package/dist/src/chat/assistant-content.js +3 -1
- package/dist/src/chat/assistant-markdown.d.ts +8 -5
- package/dist/src/chat/assistant-markdown.js +11 -26
- package/dist/src/components/autocomplete.d.ts +47 -0
- package/dist/src/components/autocomplete.js +169 -0
- package/dist/src/components/card-title.d.ts +1 -0
- package/dist/src/components/card-title.js +2 -1
- package/dist/src/components/chart-scale.d.ts +46 -0
- package/dist/src/components/chart-scale.js +118 -0
- package/dist/src/components/chart.d.ts +38 -0
- package/dist/src/components/chart.js +210 -0
- package/dist/src/components/choice-group.js +2 -2
- package/dist/src/components/choice-select.js +2 -2
- package/dist/src/components/code-block.d.ts +3 -1
- package/dist/src/components/code-block.js +75 -16
- package/dist/src/components/command-palette.d.ts +44 -0
- package/dist/src/components/command-palette.js +198 -0
- package/dist/src/components/context-menu.d.ts +2 -1
- package/dist/src/components/context-menu.js +2 -1
- package/dist/src/components/credential-source.d.ts +2 -1
- package/dist/src/components/credential-source.js +2 -1
- package/dist/src/components/detail-section.d.ts +2 -1
- package/dist/src/components/detail-section.js +8 -3
- package/dist/src/components/dialog.d.ts +4 -1
- package/dist/src/components/dialog.js +7 -2
- package/dist/src/components/entry.d.ts +45 -0
- package/dist/src/components/entry.js +38 -0
- package/dist/src/components/entry.options.d.ts +4 -0
- package/dist/src/components/entry.options.js +3 -0
- package/dist/src/components/field-group.js +2 -2
- package/dist/src/components/field.d.ts +4 -0
- package/dist/src/components/field.js +15 -3
- package/dist/src/components/form.d.ts +34 -0
- package/dist/src/components/form.js +58 -0
- package/dist/src/components/heading-level.d.ts +9 -0
- package/dist/src/components/heading-level.js +12 -0
- package/dist/src/components/hover-card.d.ts +3 -2
- package/dist/src/components/hover-card.js +50 -15
- package/dist/src/components/index.d.ts +11 -1
- package/dist/src/components/index.js +11 -1
- package/dist/src/components/markdown-blocks.d.ts +27 -0
- package/dist/src/components/markdown-blocks.js +141 -0
- package/dist/src/components/markdown.d.ts +35 -0
- package/dist/src/components/markdown.js +35 -0
- package/dist/src/components/menu-button.d.ts +2 -1
- package/dist/src/components/menu.d.ts +2 -1
- package/dist/src/components/menu.js +2 -1
- package/dist/src/components/modal.js +2 -2
- package/dist/src/components/page.js +1 -1
- package/dist/src/components/pagination.d.ts +52 -0
- package/dist/src/components/pagination.js +89 -0
- package/dist/src/components/path-label.js +5 -27
- package/dist/src/components/popover.d.ts +2 -1
- package/dist/src/components/popover.js +33 -6
- package/dist/src/components/resource-card.d.ts +4 -1
- package/dist/src/components/resource-card.js +7 -2
- package/dist/src/components/risk-confirmation.d.ts +2 -1
- package/dist/src/components/risk-confirmation.js +2 -1
- package/dist/src/components/section.d.ts +1 -7
- package/dist/src/components/section.js +3 -8
- package/dist/src/components/segmented-control.d.ts +2 -1
- package/dist/src/components/segmented-control.js +2 -1
- package/dist/src/components/tabs.d.ts +2 -1
- package/dist/src/components/tabs.js +2 -1
- package/dist/src/components/token-field.d.ts +45 -0
- package/dist/src/components/token-field.js +175 -0
- package/dist/src/components/tooltip.d.ts +2 -1
- package/dist/src/components/tooltip.js +2 -1
- package/dist/src/components/tree-view.d.ts +39 -0
- package/dist/src/components/tree-view.js +244 -0
- package/dist/src/components/tree-view.options.d.ts +2 -0
- package/dist/src/components/tree-view.options.js +3 -0
- package/dist/src/icons/README.md +11 -10
- package/dist/src/icons/icon.d.ts +1 -0
- package/dist/src/icons/icon.js +2 -1
- package/dist/src/icons/index.d.ts +0 -1
- package/dist/src/icons/index.js +0 -1
- package/dist/src/registry/index.d.ts +41 -1
- package/dist/src/registry/index.js +20 -0
- package/dist/src/shared/element-id.d.ts +6 -0
- package/dist/src/shared/element-id.js +10 -0
- package/dist/src/shared/page-attribute.d.ts +5 -0
- package/dist/src/shared/page-attribute.js +5 -0
- package/dist/src/theme/base.styles.d.ts +2 -0
- package/dist/src/theme/base.styles.js +41 -4
- package/dist/src/theme/chat/assistant.styles.js +21 -1
- package/dist/src/theme/chat/attachments.styles.js +35 -6
- package/dist/src/theme/chat/composer.styles.js +30 -3
- package/dist/src/theme/chat/conversation.styles.js +13 -1
- package/dist/src/theme/chat/records.styles.js +10 -5
- package/dist/src/theme/components/autocomplete.styles.d.ts +1 -0
- package/dist/src/theme/components/autocomplete.styles.js +68 -0
- package/dist/src/theme/components/button.styles.js +0 -1
- package/dist/src/theme/components/card.styles.js +2 -1
- package/dist/src/theme/components/chart.styles.d.ts +1 -0
- package/dist/src/theme/components/chart.styles.js +173 -0
- package/dist/src/theme/components/code-block.styles.js +79 -38
- package/dist/src/theme/components/command-palette.styles.d.ts +1 -0
- package/dist/src/theme/components/command-palette.styles.js +143 -0
- package/dist/src/theme/components/dialog.styles.js +2 -1
- package/dist/src/theme/components/empty-state.styles.js +2 -1
- package/dist/src/theme/components/entry.styles.d.ts +1 -0
- package/dist/src/theme/components/entry.styles.js +86 -0
- package/dist/src/theme/components/form.styles.d.ts +1 -0
- package/dist/src/theme/components/form.styles.js +32 -0
- package/dist/src/theme/components/hover-card.styles.js +57 -12
- package/dist/src/theme/components/image-preview.styles.js +25 -0
- package/dist/src/theme/components/layout.styles.js +6 -0
- package/dist/src/theme/components/markdown.styles.d.ts +1 -0
- package/dist/src/theme/components/markdown.styles.js +10 -0
- package/dist/src/theme/components/nav-list.styles.js +6 -7
- package/dist/src/theme/components/pagination.styles.d.ts +1 -0
- package/dist/src/theme/components/pagination.styles.js +103 -0
- package/dist/src/theme/components/path-label.styles.js +19 -6
- package/dist/src/theme/components/resource-card.styles.js +2 -1
- package/dist/src/theme/components/search-input.styles.js +23 -0
- package/dist/src/theme/components/slider.styles.js +4 -0
- package/dist/src/theme/components/token-field.styles.d.ts +1 -0
- package/dist/src/theme/components/token-field.styles.js +109 -0
- package/dist/src/theme/components/tree-view.styles.d.ts +1 -0
- package/dist/src/theme/components/tree-view.styles.js +104 -0
- package/dist/src/theme/icons/icons.styles.js +0 -18
- package/dist/src/theme/index.d.ts +446 -9
- package/dist/src/theme/index.js +58 -1
- package/dist/src/theme/journal.tokens.d.ts +389 -0
- package/dist/src/theme/journal.tokens.js +181 -0
- package/dist/src/theme/meow.tokens.d.ts +362 -0
- package/dist/src/theme/meow.tokens.js +91 -0
- package/dist/src/theme/shared/field-surface.styles.js +11 -7
- package/dist/src/theme/shared/prose.styles.js +12 -4
- package/dist/src/theme/tokens.d.ts +286 -7
- package/dist/src/theme/tokens.js +15 -2
- package/dist/src/theme/utilities.js +4 -4
- package/dist/src/web/focus-modality.d.ts +20 -0
- package/dist/src/web/focus-modality.js +72 -0
- package/dist/src/web/index.d.ts +2 -0
- package/dist/src/web/index.js +2 -0
- package/dist/src/web/theme-plugin.d.ts +33 -0
- package/dist/src/web/theme-plugin.js +93 -0
- package/package.json +14 -6
- package/dist/src/icons/doodle-cat.d.ts +0 -5
- package/dist/src/icons/doodle-cat.js +0 -8
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { h } from "meowjsx";
|
|
2
2
|
import { derived, signal, unwrap } from "meowjsx/signal";
|
|
3
|
-
import {
|
|
3
|
+
import { IconButton } from "./icon-button.js";
|
|
4
|
+
import { Icon } from "../icons/icon.js";
|
|
4
5
|
import { copyTextToClipboard } from "../clipboard.js";
|
|
5
6
|
// The highlighter stays in this module. Themes use type-only component imports,
|
|
6
7
|
// so unused code surfaces drop out of the bundle.
|
|
@@ -9,32 +10,75 @@ import { highlightCode } from "../syntax-highlight.js";
|
|
|
9
10
|
function provided(value) {
|
|
10
11
|
return value !== undefined && value !== null && value !== false;
|
|
11
12
|
}
|
|
13
|
+
const languageNames = {
|
|
14
|
+
typescript: "TypeScript",
|
|
15
|
+
ts: "TypeScript",
|
|
16
|
+
javascript: "JavaScript",
|
|
17
|
+
js: "JavaScript",
|
|
18
|
+
tsx: "TSX",
|
|
19
|
+
jsx: "JSX",
|
|
20
|
+
json: "JSON",
|
|
21
|
+
shellscript: "Shell",
|
|
22
|
+
shell: "Shell",
|
|
23
|
+
sh: "Shell",
|
|
24
|
+
bash: "Shell",
|
|
25
|
+
zsh: "Shell",
|
|
26
|
+
python: "Python",
|
|
27
|
+
py: "Python",
|
|
28
|
+
go: "Go",
|
|
29
|
+
rust: "Rust",
|
|
30
|
+
rs: "Rust",
|
|
31
|
+
yaml: "YAML",
|
|
32
|
+
yml: "YAML",
|
|
33
|
+
html: "HTML",
|
|
34
|
+
css: "CSS",
|
|
35
|
+
sql: "SQL",
|
|
36
|
+
markdown: "Markdown",
|
|
37
|
+
md: "Markdown",
|
|
38
|
+
};
|
|
39
|
+
/** The reader-facing name of a language id: `ts` reads TypeScript; unknown ids stay as given. */
|
|
40
|
+
export function codeLanguageName(language) {
|
|
41
|
+
const id = language?.trim();
|
|
42
|
+
if (!id)
|
|
43
|
+
return "Code";
|
|
44
|
+
return languageNames[id.toLowerCase()] ?? id;
|
|
45
|
+
}
|
|
12
46
|
/** A block of code with its language, an optional title, soft wrap and copy. */
|
|
13
47
|
export function CodeBlock({ code, language, title, caption, actions, defaultWrap = false, onCopy, ref, ...props }, context) {
|
|
14
48
|
// These are enumerated attributes, not native boolean attributes such as disabled.
|
|
15
49
|
const wrap = signal(defaultWrap ? "true" : "false");
|
|
16
50
|
const copying = signal(false);
|
|
17
|
-
const
|
|
51
|
+
const copied = signal(false);
|
|
52
|
+
const failure = signal("");
|
|
18
53
|
const highlighted = signal(unwrap(code));
|
|
19
|
-
const languageLabel = derived(() => unwrap(language)
|
|
54
|
+
const languageLabel = derived(() => codeLanguageName(unwrap(language)));
|
|
20
55
|
let disposed = false;
|
|
56
|
+
let copiedTimer;
|
|
57
|
+
// The last highlight, kept so streamed code extends it instead of flashing back to plain text.
|
|
58
|
+
let shown;
|
|
21
59
|
context.onCleanup(() => {
|
|
22
60
|
disposed = true;
|
|
61
|
+
clearTimeout(copiedTimer);
|
|
23
62
|
});
|
|
24
63
|
context.effect(() => {
|
|
25
64
|
const currentCode = unwrap(code);
|
|
26
65
|
const currentLanguage = unwrap(language);
|
|
27
|
-
highlighted.value =
|
|
66
|
+
highlighted.value =
|
|
67
|
+
shown && shown.language === currentLanguage && currentCode.startsWith(shown.source)
|
|
68
|
+
? [...shown.spans, currentCode.slice(shown.source.length)]
|
|
69
|
+
: currentCode;
|
|
28
70
|
let active = true;
|
|
29
71
|
void highlightCode(currentCode, currentLanguage).then((spans) => {
|
|
30
72
|
if (!active || disposed || !spans)
|
|
31
73
|
return;
|
|
32
|
-
|
|
74
|
+
const rendered = spans.map((span) => (h("span", { style: {
|
|
33
75
|
color: span.color,
|
|
34
76
|
fontStyle: (span.fontStyle ?? 0) & 1 ? "italic" : undefined,
|
|
35
77
|
fontWeight: (span.fontStyle ?? 0) & 2 ? "bold" : undefined,
|
|
36
78
|
textDecoration: (span.fontStyle ?? 0) & 4 ? "underline" : undefined,
|
|
37
79
|
} }, span.text)));
|
|
80
|
+
shown = { source: currentCode, language: currentLanguage, spans: rendered };
|
|
81
|
+
highlighted.value = rendered;
|
|
38
82
|
});
|
|
39
83
|
return () => {
|
|
40
84
|
active = false;
|
|
@@ -44,19 +88,25 @@ export function CodeBlock({ code, language, title, caption, actions, defaultWrap
|
|
|
44
88
|
if (copying.value)
|
|
45
89
|
return;
|
|
46
90
|
copying.value = true;
|
|
47
|
-
|
|
91
|
+
failure.value = "";
|
|
48
92
|
const text = unwrap(code);
|
|
49
93
|
try {
|
|
50
94
|
if (onCopy)
|
|
51
95
|
await onCopy(text);
|
|
52
96
|
else
|
|
53
97
|
await copyTextToClipboard(text);
|
|
54
|
-
if (
|
|
55
|
-
|
|
98
|
+
if (disposed)
|
|
99
|
+
return;
|
|
100
|
+
copied.value = true;
|
|
101
|
+
clearTimeout(copiedTimer);
|
|
102
|
+
copiedTimer = setTimeout(() => {
|
|
103
|
+
if (!disposed)
|
|
104
|
+
copied.value = false;
|
|
105
|
+
}, 1600);
|
|
56
106
|
}
|
|
57
107
|
catch {
|
|
58
108
|
if (!disposed)
|
|
59
|
-
|
|
109
|
+
failure.value = "Copy failed; select the code and copy it manually.";
|
|
60
110
|
}
|
|
61
111
|
finally {
|
|
62
112
|
if (!disposed)
|
|
@@ -65,28 +115,37 @@ export function CodeBlock({ code, language, title, caption, actions, defaultWrap
|
|
|
65
115
|
};
|
|
66
116
|
return (h("figure", { ...props, ref: [context.parts.root, ref] },
|
|
67
117
|
h("figcaption", { ref: context.parts.header },
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
118
|
+
h("span", { ref: context.parts.heading },
|
|
119
|
+
provided(title) ? h("span", { ref: context.parts.title }, title) : null,
|
|
120
|
+
provided(caption) ? h("span", { ref: context.parts.caption }, caption) : null,
|
|
121
|
+
h("span", { ref: context.parts.language }, languageLabel)),
|
|
71
122
|
h("div", { ref: context.parts.actions },
|
|
72
123
|
provided(actions) ? actions : null,
|
|
73
|
-
h(
|
|
124
|
+
h(IconButton, { size: "small", label: "Soft wrap", "aria-pressed": wrap, onClick: () => {
|
|
74
125
|
wrap.value = wrap.value === "true" ? "false" : "true";
|
|
75
|
-
} },
|
|
76
|
-
|
|
126
|
+
} },
|
|
127
|
+
h(Icon, { name: "text-wrap" })),
|
|
128
|
+
h(IconButton, { size: "small", label: derived(() => (copied.value ? "Copied" : "Copy code")), disabled: copying, "data-copied": derived(() => String(copied.value)), onClick: copy },
|
|
129
|
+
h("span", { ref: context.parts.copyIcon },
|
|
130
|
+
h(Icon, { name: "copy" })),
|
|
131
|
+
h("span", { ref: context.parts.copiedIcon },
|
|
132
|
+
h(Icon, { name: "check" }))))),
|
|
77
133
|
h("pre", { tabIndex: 0, "aria-label": "Code content", "data-wrap": wrap, ref: context.parts.content },
|
|
78
134
|
h("code", { ref: context.parts.code }, highlighted)),
|
|
79
|
-
h("span", { role: "status", "aria-live": "polite", ref: context.parts.feedback },
|
|
135
|
+
h("span", { role: "status", "aria-live": "polite", "data-failed": derived(() => (failure.value ? "true" : undefined)), ref: context.parts.feedback }, derived(() => failure.value || (copied.value ? "Copied" : "")))));
|
|
80
136
|
}
|
|
81
137
|
CodeBlock.meta = {
|
|
82
138
|
name: "code-block",
|
|
83
139
|
parts: [
|
|
84
140
|
"root",
|
|
85
141
|
"header",
|
|
142
|
+
"heading",
|
|
86
143
|
"title",
|
|
87
144
|
"caption",
|
|
88
145
|
"language",
|
|
89
146
|
"actions",
|
|
147
|
+
"copyIcon",
|
|
148
|
+
"copiedIcon",
|
|
90
149
|
"content",
|
|
91
150
|
"code",
|
|
92
151
|
"feedback",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Context, type Props } from "meowjsx";
|
|
2
|
+
import { type MaybeSignal } from "meowjsx/signal";
|
|
3
|
+
import { type IconName } from "../icons/icon.js";
|
|
4
|
+
export interface CommandPaletteCommand {
|
|
5
|
+
/** Unique in the list; reported to onRun. */
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** Commands of one group are shown together, groups in order of first appearance. */
|
|
9
|
+
group?: string;
|
|
10
|
+
/** Extra words the query matches, such as synonyms. */
|
|
11
|
+
keywords?: readonly string[];
|
|
12
|
+
/** Effective key labels, owned by the host (for example ["⌘", "K"]). */
|
|
13
|
+
shortcut?: readonly string[];
|
|
14
|
+
icon?: IconName;
|
|
15
|
+
/** Shown and skipped by the arrow keys; never runs. */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface CommandPaletteProps extends Props {
|
|
19
|
+
/** Required; the host owns the state and registers the shortcut that opens it. */
|
|
20
|
+
open: MaybeSignal<boolean>;
|
|
21
|
+
/** Called with false when the reader dismisses the palette or runs a command. */
|
|
22
|
+
onOpenChange: (open: boolean) => void;
|
|
23
|
+
commands: MaybeSignal<readonly CommandPaletteCommand[]>;
|
|
24
|
+
/** Called after the palette has closed and focus has returned to the opener. */
|
|
25
|
+
onRun: (id: string) => void;
|
|
26
|
+
/** Accessible name of the dialog. */
|
|
27
|
+
label?: string;
|
|
28
|
+
searchLabel?: string;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
emptyMessage?: string;
|
|
31
|
+
/** The polite count announced as the query changes. */
|
|
32
|
+
resultsMessage?: (count: number) => string;
|
|
33
|
+
className?: Props["className"];
|
|
34
|
+
}
|
|
35
|
+
/** Every query term must appear in the label, the group or a keyword. */
|
|
36
|
+
export declare function commandMatches(command: CommandPaletteCommand, query: string): boolean;
|
|
37
|
+
/** Search the host's commands, run one, and give focus back to where the reader was. */
|
|
38
|
+
export declare function CommandPalette({ open, onOpenChange, commands, onRun, label, searchLabel, placeholder, emptyMessage, resultsMessage, className, ref, ...props }: CommandPaletteProps, context: Context<typeof CommandPalette>): import("meowjsx").VNode;
|
|
39
|
+
export declare namespace CommandPalette {
|
|
40
|
+
var meta: {
|
|
41
|
+
readonly name: "command-palette";
|
|
42
|
+
readonly parts: readonly ["root", "dialog", "search", "searchIcon", "input", "list", "group", "heading", "option", "icon", "label", "empty", "count"];
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { h, keyed } from "meowjsx";
|
|
2
|
+
import { derived, signal, unwrap } from "meowjsx/signal";
|
|
3
|
+
import { Icon } from "../icons/icon.js";
|
|
4
|
+
import { activeElementInRoot, elementByIdInRoot } from "../shared/dom-root.js";
|
|
5
|
+
import { elementId } from "../shared/element-id.js";
|
|
6
|
+
import { ShortcutKeys } from "./shortcut-keys.js";
|
|
7
|
+
/** Groups in order of first appearance; ungrouped commands form their own unnamed group. */
|
|
8
|
+
function groupCommands(commands) {
|
|
9
|
+
const groups = new Map();
|
|
10
|
+
for (const command of commands) {
|
|
11
|
+
const key = command.group === undefined ? "" : `group:${command.group}`;
|
|
12
|
+
let group = groups.get(key);
|
|
13
|
+
if (!group)
|
|
14
|
+
groups.set(key, (group = { key, name: command.group, commands: [] }));
|
|
15
|
+
group.commands.push(command);
|
|
16
|
+
}
|
|
17
|
+
return [...groups.values()];
|
|
18
|
+
}
|
|
19
|
+
/** Every query term must appear in the label, the group or a keyword. */
|
|
20
|
+
export function commandMatches(command, query) {
|
|
21
|
+
const text = [command.label, command.group ?? "", ...(command.keywords ?? [])]
|
|
22
|
+
.join(" ")
|
|
23
|
+
.toLocaleLowerCase();
|
|
24
|
+
return query
|
|
25
|
+
.toLocaleLowerCase()
|
|
26
|
+
.split(/\s+/)
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.every((term) => text.includes(term));
|
|
29
|
+
}
|
|
30
|
+
/** Search the host's commands, run one, and give focus back to where the reader was. */
|
|
31
|
+
export function CommandPalette({ open, onOpenChange, commands, onRun, label = "Command palette", searchLabel = "Search commands", placeholder = "Type a command", emptyMessage = "No matching commands", resultsMessage = (count) => (count === 1 ? "1 command" : `${count} commands`), className, ref, ...props }, context) {
|
|
32
|
+
const base = elementId("command-palette");
|
|
33
|
+
const listId = `${base}-list`;
|
|
34
|
+
const query = signal("");
|
|
35
|
+
const chosen = signal(undefined);
|
|
36
|
+
let dialog;
|
|
37
|
+
let input;
|
|
38
|
+
let opener = null;
|
|
39
|
+
let pending;
|
|
40
|
+
let alive = true;
|
|
41
|
+
context.onCleanup(() => {
|
|
42
|
+
alive = false;
|
|
43
|
+
});
|
|
44
|
+
const groups = derived(() => groupCommands(unwrap(commands)));
|
|
45
|
+
const matching = derived(() => {
|
|
46
|
+
const text = query.value;
|
|
47
|
+
return groups.value.flatMap((group) => group.commands.filter((command) => commandMatches(command, text)));
|
|
48
|
+
});
|
|
49
|
+
const enabled = derived(() => matching.value.filter((command) => !command.disabled));
|
|
50
|
+
// The chosen command while it still matches, else the first enabled match.
|
|
51
|
+
const active = derived(() => {
|
|
52
|
+
const ids = enabled.value.map((command) => command.id);
|
|
53
|
+
return chosen.value !== undefined && ids.includes(chosen.value) ? chosen.value : ids[0];
|
|
54
|
+
});
|
|
55
|
+
const optionId = (id) => `${base}-option-${id}`;
|
|
56
|
+
const restoreOpener = () => {
|
|
57
|
+
const target = opener;
|
|
58
|
+
opener = null;
|
|
59
|
+
if (target?.isConnected)
|
|
60
|
+
target.focus();
|
|
61
|
+
};
|
|
62
|
+
const sync = () => {
|
|
63
|
+
if (!alive || !dialog?.isConnected)
|
|
64
|
+
return;
|
|
65
|
+
if (unwrap(open)) {
|
|
66
|
+
if (dialog.open)
|
|
67
|
+
return;
|
|
68
|
+
const focused = activeElementInRoot(dialog);
|
|
69
|
+
opener = focused instanceof HTMLElement && !dialog.contains(focused) ? focused : null;
|
|
70
|
+
query.value = "";
|
|
71
|
+
chosen.value = undefined;
|
|
72
|
+
if (input)
|
|
73
|
+
input.value = "";
|
|
74
|
+
dialog.showModal();
|
|
75
|
+
input?.focus();
|
|
76
|
+
}
|
|
77
|
+
else if (dialog.open) {
|
|
78
|
+
dialog.close();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
context.effect(() => {
|
|
82
|
+
unwrap(open);
|
|
83
|
+
sync();
|
|
84
|
+
});
|
|
85
|
+
const run = (id) => {
|
|
86
|
+
const command = unwrap(commands).find((candidate) => candidate.id === id);
|
|
87
|
+
if (!command || command.disabled || !dialog?.open)
|
|
88
|
+
return;
|
|
89
|
+
// Close first, so focus is back with the opener before the command moves it anywhere.
|
|
90
|
+
pending = id;
|
|
91
|
+
dialog.close();
|
|
92
|
+
};
|
|
93
|
+
const move = (step) => {
|
|
94
|
+
const ids = enabled.value.map((command) => command.id);
|
|
95
|
+
if (ids.length === 0)
|
|
96
|
+
return;
|
|
97
|
+
const index = ids.indexOf(active.value ?? "");
|
|
98
|
+
const next = ids[(index + step + ids.length) % ids.length];
|
|
99
|
+
chosen.value = next;
|
|
100
|
+
queueMicrotask(() => {
|
|
101
|
+
if (alive && dialog)
|
|
102
|
+
elementByIdInRoot(dialog, optionId(next))?.scrollIntoView?.({ block: "nearest" });
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
return (h("div", { ...props, className: className, ref: [context.parts.root, ref] },
|
|
106
|
+
h("dialog", { "aria-label": label, onCancel: (event) => {
|
|
107
|
+
// Dismissal goes through the owner, like Modal.
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
if (alive)
|
|
110
|
+
onOpenChange(false);
|
|
111
|
+
}, onClose: () => {
|
|
112
|
+
if (!alive)
|
|
113
|
+
return;
|
|
114
|
+
restoreOpener();
|
|
115
|
+
if (unwrap(open))
|
|
116
|
+
onOpenChange(false);
|
|
117
|
+
const id = pending;
|
|
118
|
+
pending = undefined;
|
|
119
|
+
if (id !== undefined)
|
|
120
|
+
onRun(id);
|
|
121
|
+
}, onClick: (event) => {
|
|
122
|
+
// A backdrop click targets the dialog element itself.
|
|
123
|
+
if (alive && event.target === event.currentTarget)
|
|
124
|
+
onOpenChange(false);
|
|
125
|
+
}, ref: [
|
|
126
|
+
context.parts.dialog,
|
|
127
|
+
(element) => {
|
|
128
|
+
dialog = element;
|
|
129
|
+
queueMicrotask(sync);
|
|
130
|
+
return () => {
|
|
131
|
+
if (element.open)
|
|
132
|
+
element.close();
|
|
133
|
+
dialog = undefined;
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
] },
|
|
137
|
+
h("div", { ref: context.parts.search },
|
|
138
|
+
h("span", { "aria-hidden": "true", ref: context.parts.searchIcon },
|
|
139
|
+
h(Icon, { name: "search" })),
|
|
140
|
+
h("input", { type: "text", role: "combobox", "aria-label": searchLabel, "aria-expanded": "true", "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": derived(() => active.value === undefined ? undefined : optionId(active.value)), placeholder: placeholder, autoComplete: "off", spellcheck: "false", onInput: (event) => {
|
|
141
|
+
query.value = event.currentTarget.value;
|
|
142
|
+
chosen.value = undefined;
|
|
143
|
+
}, onKeyDown: (event) => {
|
|
144
|
+
if (event.isComposing)
|
|
145
|
+
return;
|
|
146
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
move(event.key === "ArrowDown" ? 1 : -1);
|
|
149
|
+
}
|
|
150
|
+
else if (event.key === "Enter") {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
if (active.value !== undefined)
|
|
153
|
+
run(active.value);
|
|
154
|
+
}
|
|
155
|
+
}, ref: [
|
|
156
|
+
context.parts.input,
|
|
157
|
+
(element) => {
|
|
158
|
+
input = element;
|
|
159
|
+
},
|
|
160
|
+
] })),
|
|
161
|
+
h("div", { id: listId, role: "listbox", "aria-label": label, ref: context.parts.list }, keyed(groups, (group) => group.key, (group) => {
|
|
162
|
+
const headingId = `${base}-${group.value.key || "ungrouped"}`;
|
|
163
|
+
const visible = derived(() => group.value.commands.some((command) => commandMatches(command, query.value)));
|
|
164
|
+
return (h("div", { role: group.value.name === undefined ? "presentation" : "group", "aria-labelledby": group.value.name === undefined ? undefined : headingId, hidden: derived(() => !visible.value), ref: context.parts.group },
|
|
165
|
+
group.value.name === undefined ? null : (h("div", { id: headingId, role: "presentation", ref: context.parts.heading }, derived(() => group.value.name ?? ""))),
|
|
166
|
+
keyed(derived(() => group.value.commands), (command) => command.id, (command) => {
|
|
167
|
+
const id = command.value.id;
|
|
168
|
+
return (h("div", { id: optionId(id), role: "option", "aria-selected": derived(() => String(active.value === id)), "aria-disabled": derived(() => command.value.disabled ? "true" : undefined), hidden: derived(() => !commandMatches(command.value, query.value)), onMouseDown: (event) => event.preventDefault(), onMouseMove: () => {
|
|
169
|
+
if (!command.value.disabled && active.value !== id)
|
|
170
|
+
chosen.value = id;
|
|
171
|
+
}, onClick: () => run(id), ref: context.parts.option },
|
|
172
|
+
command.value.icon ? (h("span", { "aria-hidden": "true", ref: context.parts.icon },
|
|
173
|
+
h(Icon, { name: command.value.icon }))) : null,
|
|
174
|
+
h("span", { ref: context.parts.label }, derived(() => command.value.label)),
|
|
175
|
+
command.value.shortcut ? (h(ShortcutKeys, { keys: command.value.shortcut })) : null));
|
|
176
|
+
})));
|
|
177
|
+
})),
|
|
178
|
+
h("p", { hidden: derived(() => matching.value.length > 0), ref: context.parts.empty }, emptyMessage),
|
|
179
|
+
h("p", { role: "status", ref: context.parts.count }, derived(() => resultsMessage(matching.value.length))))));
|
|
180
|
+
}
|
|
181
|
+
CommandPalette.meta = {
|
|
182
|
+
name: "command-palette",
|
|
183
|
+
parts: [
|
|
184
|
+
"root",
|
|
185
|
+
"dialog",
|
|
186
|
+
"search",
|
|
187
|
+
"searchIcon",
|
|
188
|
+
"input",
|
|
189
|
+
"list",
|
|
190
|
+
"group",
|
|
191
|
+
"heading",
|
|
192
|
+
"option",
|
|
193
|
+
"icon",
|
|
194
|
+
"label",
|
|
195
|
+
"empty",
|
|
196
|
+
"count",
|
|
197
|
+
],
|
|
198
|
+
};
|
|
@@ -2,7 +2,8 @@ import { type Child, type Props, type Context } from "meowjsx";
|
|
|
2
2
|
import { type MaybeSignal } from "meowjsx/signal";
|
|
3
3
|
import { type MenuEntry } from "./menu.js";
|
|
4
4
|
export interface ContextMenuProps extends Props {
|
|
5
|
-
id
|
|
5
|
+
/** Base id for the ARIA references this component wires; generated when omitted. */
|
|
6
|
+
id?: string;
|
|
6
7
|
items: readonly MenuEntry[];
|
|
7
8
|
open?: MaybeSignal<boolean>;
|
|
8
9
|
onOpenChange?: (open: boolean) => void;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { h } from "meowjsx";
|
|
2
2
|
import { signal, unwrap } from "meowjsx/signal";
|
|
3
3
|
import { Menu } from "./menu.js";
|
|
4
|
+
import { elementId } from "../shared/element-id.js";
|
|
4
5
|
/** Right-click or Shift+F10 opens the existing Menu, including nested items. */
|
|
5
|
-
export function ContextMenu({ id, items, open, onOpenChange, className, children, ...props }, context) {
|
|
6
|
+
export function ContextMenu({ id = elementId("context-menu"), items, open, onOpenChange, className, children, ...props }, context) {
|
|
6
7
|
const local = signal(false);
|
|
7
8
|
const state = open !== undefined ? open : local;
|
|
8
9
|
let point = { x: 0, y: 0 };
|
|
@@ -6,9 +6,10 @@ import { ListGroup, ListRow } from "./list-group.js";
|
|
|
6
6
|
import { Select } from "./select.js";
|
|
7
7
|
import { Stack } from "./stack.js";
|
|
8
8
|
import { Status } from "./status.js";
|
|
9
|
+
import { elementId } from "../shared/element-id.js";
|
|
9
10
|
/** Controlled credential editor. Discovery and secret persistence belong to the host. */
|
|
10
11
|
export function CredentialSource(props) {
|
|
11
|
-
const { id, disabled } = props;
|
|
12
|
+
const { id = elementId("credential-source"), disabled } = props;
|
|
12
13
|
return (h(Stack, { gap: "compact" },
|
|
13
14
|
h(Field, { label: "API Key source", htmlFor: `${id}-source` },
|
|
14
15
|
h(Select, { id: `${id}-source`, value: props.source, disabled: disabled, onChange: (event) => props.onSourceChange(event.target.value) },
|
|
@@ -7,7 +7,8 @@ export interface DetailSectionProps extends Props {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* One titled block inside a detail surface (a side panel or a full-screen reader). Blocks are
|
|
10
|
-
* separated by a hairline; the heading is a small label, not a page title.
|
|
10
|
+
* separated by a hairline; the heading is a small label, not a page title. Its level sits one
|
|
11
|
+
* below the surrounding `Page` or `Section` heading, and nested sections continue from it.
|
|
11
12
|
*/
|
|
12
13
|
export declare function DetailSection({ title, aside, className, children, ...props }: DetailSectionProps, context: Context<typeof DetailSection>): import("meowjsx").VNode;
|
|
13
14
|
export declare namespace DetailSection {
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { h } from "meowjsx";
|
|
2
|
+
import { nestedHeadingLevel, sectionLevelContext } from "./heading-level.js";
|
|
2
3
|
/**
|
|
3
4
|
* One titled block inside a detail surface (a side panel or a full-screen reader). Blocks are
|
|
4
|
-
* separated by a hairline; the heading is a small label, not a page title.
|
|
5
|
+
* separated by a hairline; the heading is a small label, not a page title. Its level sits one
|
|
6
|
+
* below the surrounding `Page` or `Section` heading, and nested sections continue from it.
|
|
5
7
|
*/
|
|
6
8
|
export function DetailSection({ title, aside, className, children, ...props }, context) {
|
|
9
|
+
const level = nestedHeadingLevel();
|
|
10
|
+
const Heading = `h${level}`;
|
|
7
11
|
return (h("section", { ...props, className: className, ref: [context.parts.root, props.ref] },
|
|
8
12
|
h("div", { ref: [context.parts.header] },
|
|
9
|
-
h(
|
|
13
|
+
h(Heading, { ref: [context.parts.title] }, title),
|
|
10
14
|
aside !== undefined && aside !== null && aside !== false ? (h("span", { ref: [context.parts.aside] }, aside)) : null),
|
|
11
|
-
h("div", { ref: [context.parts.body] },
|
|
15
|
+
h("div", { ref: [context.parts.body] },
|
|
16
|
+
h(sectionLevelContext.Provider, { value: level }, children))));
|
|
12
17
|
}
|
|
13
18
|
DetailSection.meta = {
|
|
14
19
|
name: "detail-section",
|
|
@@ -4,7 +4,10 @@ export interface DialogProps extends Props {
|
|
|
4
4
|
describedBy?: string;
|
|
5
5
|
className?: Props["className"];
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The native dialog element, themed; Modal builds a complete dialog on top of it. Its title is
|
|
9
|
+
* an h2 (`DialogHeader`), so sections and card titles inside it start at h3.
|
|
10
|
+
*/
|
|
8
11
|
export declare function Dialog({ labelledBy, describedBy, className, children, ref, ...props }: DialogProps, context: Context<typeof Dialog>): import("meowjsx").VNode;
|
|
9
12
|
export declare namespace Dialog {
|
|
10
13
|
var meta: {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { h } from "meowjsx";
|
|
2
|
-
|
|
2
|
+
import { sectionLevelContext } from "./heading-level.js";
|
|
3
|
+
/**
|
|
4
|
+
* The native dialog element, themed; Modal builds a complete dialog on top of it. Its title is
|
|
5
|
+
* an h2 (`DialogHeader`), so sections and card titles inside it start at h3.
|
|
6
|
+
*/
|
|
3
7
|
export function Dialog({ labelledBy, describedBy, className, children, ref, ...props }, context) {
|
|
4
|
-
return (h("dialog", { ...props, className: className, "aria-labelledby": labelledBy, "aria-describedby": describedBy, ref: [context.parts.root, ref] },
|
|
8
|
+
return (h("dialog", { ...props, className: className, "aria-labelledby": labelledBy, "aria-describedby": describedBy, ref: [context.parts.root, ref] },
|
|
9
|
+
h(sectionLevelContext.Provider, { value: 2 }, children)));
|
|
5
10
|
}
|
|
6
11
|
Dialog.meta = { name: "dialog", parts: ["root"] };
|
|
7
12
|
// One component per module, so a bundler keeps only the dialog pieces a host uses.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Child, type Context, type Props } from "meowjsx";
|
|
2
|
+
import { type ThemedProps } from "meowcss/meowjsx";
|
|
3
|
+
import { entryOptions } from "./entry.options.js";
|
|
4
|
+
export interface EntryListProps extends Props {
|
|
5
|
+
className?: Props["className"];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A run of content entries, such as posts, notes or releases. Entries are separated by hairlines
|
|
9
|
+
* and sit on the surrounding surface; there is no box around the run.
|
|
10
|
+
*/
|
|
11
|
+
export declare function EntryList({ className, children, ref, ...props }: EntryListProps, context: Context<typeof EntryList>): import("meowjsx").VNode;
|
|
12
|
+
export declare namespace EntryList {
|
|
13
|
+
var meta: {
|
|
14
|
+
readonly name: "entry-list";
|
|
15
|
+
readonly parts: readonly ["root"];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface EntryProps extends Props, ThemedProps<typeof entryOptions> {
|
|
19
|
+
/** The entry's name; rendered as a heading one level below the surrounding region. */
|
|
20
|
+
title: Child;
|
|
21
|
+
/** Where the entry lives; the title links to it. */
|
|
22
|
+
href?: string;
|
|
23
|
+
/** A short kicker above the title, such as the date or the section. */
|
|
24
|
+
eyebrow?: Child;
|
|
25
|
+
/** One or two sentences that say what the entry is about. */
|
|
26
|
+
description?: Child;
|
|
27
|
+
/** Facts under the description, such as a byline, reading time or tags. */
|
|
28
|
+
meta?: Child;
|
|
29
|
+
className?: Props["className"];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One summary of a piece of content: an optional kicker, a titled heading that can link to the
|
|
33
|
+
* content, a standfirst and its facts. In an EntryList it is a list item; on its own it is an
|
|
34
|
+
* article. Its heading level follows the surrounding `Page` or `Section`.
|
|
35
|
+
*/
|
|
36
|
+
export declare function Entry({ title, href, eyebrow, description, meta, className, children, ref, ...props }: EntryProps, context: Context<typeof Entry>): import("meowjsx").VNode;
|
|
37
|
+
export declare namespace Entry {
|
|
38
|
+
var meta: {
|
|
39
|
+
readonly name: "entry";
|
|
40
|
+
readonly parts: readonly ["root", "eyebrow", "title", "link", "description", "meta"];
|
|
41
|
+
readonly style: import("meowcss/meowjsx").StylePropsBinding<import("meowcss").Options<{
|
|
42
|
+
readonly size: readonly ["default", "feature"];
|
|
43
|
+
}>>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createContext, h, useContext } from "meowjsx";
|
|
2
|
+
import { defineStyleProps } from "meowcss/meowjsx";
|
|
3
|
+
import { entryOptions } from "./entry.options.js";
|
|
4
|
+
import { nestedHeadingLevel } from "./heading-level.js";
|
|
5
|
+
/** Whether an Entry sits directly in an EntryList, which makes it a list item. */
|
|
6
|
+
const entryListContext = createContext(false);
|
|
7
|
+
/**
|
|
8
|
+
* A run of content entries, such as posts, notes or releases. Entries are separated by hairlines
|
|
9
|
+
* and sit on the surrounding surface; there is no box around the run.
|
|
10
|
+
*/
|
|
11
|
+
export function EntryList({ className, children, ref, ...props }, context) {
|
|
12
|
+
return (h("ul", { ...props, className: className, ref: [context.parts.root, ref] },
|
|
13
|
+
h(entryListContext.Provider, { value: true }, children)));
|
|
14
|
+
}
|
|
15
|
+
EntryList.meta = { name: "entry-list", parts: ["root"] };
|
|
16
|
+
/**
|
|
17
|
+
* One summary of a piece of content: an optional kicker, a titled heading that can link to the
|
|
18
|
+
* content, a standfirst and its facts. In an EntryList it is a list item; on its own it is an
|
|
19
|
+
* article. Its heading level follows the surrounding `Page` or `Section`.
|
|
20
|
+
*/
|
|
21
|
+
export function Entry({ title, href, eyebrow, description, meta, className, children, ref, ...props }, context) {
|
|
22
|
+
const Root = useContext(entryListContext) ? "li" : "article";
|
|
23
|
+
const Heading = `h${nestedHeadingLevel()}`;
|
|
24
|
+
return (h(Root, { ...props, className: className, ref: [context.parts.root, ref] },
|
|
25
|
+
hasSlot(eyebrow) ? h("p", { ref: context.parts.eyebrow }, eyebrow) : null,
|
|
26
|
+
h(Heading, { ref: context.parts.title }, href === undefined ? (title) : (h("a", { href: href, ref: context.parts.link }, title))),
|
|
27
|
+
hasSlot(description) ? h("p", { ref: context.parts.description }, description) : null,
|
|
28
|
+
hasSlot(meta) ? h("div", { ref: context.parts.meta }, meta) : null,
|
|
29
|
+
children));
|
|
30
|
+
}
|
|
31
|
+
Entry.meta = {
|
|
32
|
+
name: "entry",
|
|
33
|
+
parts: ["root", "eyebrow", "title", "link", "description", "meta"],
|
|
34
|
+
style: defineStyleProps(entryOptions, { defaults: { size: "default" } }),
|
|
35
|
+
};
|
|
36
|
+
function hasSlot(value) {
|
|
37
|
+
return value !== undefined && value !== null && value !== false && value !== "";
|
|
38
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { h } from "meowjsx";
|
|
2
|
-
|
|
2
|
+
import { elementId } from "../shared/element-id.js";
|
|
3
3
|
/** A titled set of related fields, as a native fieldset. */
|
|
4
4
|
export function FieldGroup({ legend, description, descriptionId, disabled, children, className, ...props }, context) {
|
|
5
5
|
const hasDescription = description !== undefined && description !== null && description !== false;
|
|
6
6
|
const resolvedDescriptionId = hasDescription
|
|
7
|
-
? (descriptionId ??
|
|
7
|
+
? (descriptionId ?? `${elementId("field-group")}-description`)
|
|
8
8
|
: undefined;
|
|
9
9
|
return (h("fieldset", { ...props, disabled: disabled, className: className, "aria-describedby": [props["aria-describedby"], resolvedDescriptionId].filter(Boolean).join(" ") || undefined, ref: [context.parts.root, props.ref] },
|
|
10
10
|
h("legend", { ref: [context.parts.legend] }, legend),
|
|
@@ -4,6 +4,10 @@ export interface FieldProps extends Props {
|
|
|
4
4
|
label: Child;
|
|
5
5
|
description?: Child;
|
|
6
6
|
error?: Child;
|
|
7
|
+
/**
|
|
8
|
+
* Id of the labelled control. When omitted, Field uses the single child control's own `id`,
|
|
9
|
+
* or generates one and gives it to that control.
|
|
10
|
+
*/
|
|
7
11
|
htmlFor?: string;
|
|
8
12
|
descriptionId?: string;
|
|
9
13
|
errorId?: string;
|