@mcpview/components 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/esm/src/preact/snippet-javascript.d.ts +10 -0
- package/esm/src/preact/snippet-javascript.d.ts.map +1 -0
- package/esm/src/preact/snippet-javascript.js +46 -0
- package/esm/src/preact/snippet-library.d.ts +2 -0
- package/esm/src/preact/snippet-library.d.ts.map +1 -1
- package/esm/src/preact/snippet-library.js +23 -2
- package/esm/src/theme.d.ts.map +1 -1
- package/esm/src/theme.js +11 -0
- package/package.json +2 -1
- package/script/src/preact/snippet-javascript.d.ts +10 -0
- package/script/src/preact/snippet-javascript.d.ts.map +1 -0
- package/script/src/preact/snippet-javascript.js +49 -0
- package/script/src/preact/snippet-library.d.ts +2 -0
- package/script/src/preact/snippet-library.d.ts.map +1 -1
- package/script/src/preact/snippet-library.js +22 -1
- package/script/src/theme.d.ts.map +1 -1
- package/script/src/theme.js +11 -0
package/README.md
CHANGED
|
@@ -270,7 +270,8 @@ technical control. Keep consequential state in `status` or `primary`.
|
|
|
270
270
|
Import `SnippetLibrary` from `@mcpview/components/preact/components`. Supply the snippet summaries
|
|
271
271
|
as `entries` and localized text as `labels`. The library filters names and descriptions locally. Use
|
|
272
272
|
`onInspect(entry)` to fetch the selected source, then pass it as `source` to show the program as
|
|
273
|
-
selectable text.
|
|
273
|
+
selectable text. Set `source.language` to `"javascript"` for syntax highlighting. Clear `source` in
|
|
274
|
+
`onBack` to return to the list.
|
|
274
275
|
|
|
275
276
|
The App owns the catalog calls and can provide navigation next to the library title through
|
|
276
277
|
`headerAction`. The component uses the package's existing theme styles.
|
|
@@ -596,7 +597,7 @@ local checkout); the `/surface` entry is derived from the latter unless
|
|
|
596
597
|
`MCP_VIEW_COMPONENTS_SURFACE_MODULE` names it. Run the generator from JSR:
|
|
597
598
|
|
|
598
599
|
```sh
|
|
599
|
-
deno run -A jsr:@mcpview/components@0.13.
|
|
600
|
+
deno run -A jsr:@mcpview/components@0.13.1/scaffold result-viewer ./result-viewer
|
|
600
601
|
```
|
|
601
602
|
|
|
602
603
|
The npm package contains only the runtime and presentation entry points. It does not export or ship
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Style = "comment" | "keyword" | "string" | "literal";
|
|
2
|
+
type Range = {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
style: Style;
|
|
6
|
+
};
|
|
7
|
+
/** Offset ranges leave line endings, escape sequences and all other source text untouched. */
|
|
8
|
+
export declare function javascriptHighlightRanges(code: string): Range[];
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=snippet-javascript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snippet-javascript.d.ts","sourceRoot":"","sources":["../../../src/src/preact/snippet-javascript.ts"],"names":[],"mappings":"AAEA,KAAK,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC1D,KAAK,KAAK,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAuB1D,8FAA8F;AAC9F,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CAmB/D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parse, tokTypes } from "acorn";
|
|
2
|
+
function tokenStyle(type, text) {
|
|
3
|
+
switch (type) {
|
|
4
|
+
case tokTypes.string:
|
|
5
|
+
case tokTypes.regexp:
|
|
6
|
+
case tokTypes.template:
|
|
7
|
+
case tokTypes.invalidTemplate:
|
|
8
|
+
case tokTypes.backQuote:
|
|
9
|
+
return "string";
|
|
10
|
+
case tokTypes.num:
|
|
11
|
+
case tokTypes._null:
|
|
12
|
+
case tokTypes._true:
|
|
13
|
+
case tokTypes._false:
|
|
14
|
+
return "literal";
|
|
15
|
+
case tokTypes.name:
|
|
16
|
+
if (["async", "await", "let", "yield"].includes(text))
|
|
17
|
+
return "keyword";
|
|
18
|
+
return;
|
|
19
|
+
default:
|
|
20
|
+
if (type.keyword)
|
|
21
|
+
return "keyword";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Offset ranges leave line endings, escape sequences and all other source text untouched. */
|
|
25
|
+
export function javascriptHighlightRanges(code) {
|
|
26
|
+
const ranges = [];
|
|
27
|
+
try {
|
|
28
|
+
parse(code, {
|
|
29
|
+
ecmaVersion: "latest",
|
|
30
|
+
sourceType: "module",
|
|
31
|
+
allowReturnOutsideFunction: true,
|
|
32
|
+
onComment: (_block, _text, start, end) => {
|
|
33
|
+
ranges.push({ start, end, style: "comment" });
|
|
34
|
+
},
|
|
35
|
+
onToken: ({ type, start, end }) => {
|
|
36
|
+
const style = tokenStyle(type, code.slice(start, end));
|
|
37
|
+
if (style && start < end)
|
|
38
|
+
ranges.push({ start, end, style });
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return ranges.sort((a, b) => a.start - b.start);
|
|
46
|
+
}
|
|
@@ -10,6 +10,8 @@ export interface SnippetLibrarySource {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
readonly description?: string;
|
|
12
12
|
readonly code: string;
|
|
13
|
+
/** Omit to display plain text. */
|
|
14
|
+
readonly language?: "javascript";
|
|
13
15
|
}
|
|
14
16
|
export interface SnippetLibraryLabels {
|
|
15
17
|
readonly title: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-library.d.ts","sourceRoot":"","sources":["../../../src/src/preact/snippet-library.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"snippet-library.d.ts","sourceRoot":"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CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9B;AA4BD,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,EAC7B,OAAY,EACZ,MAAM,EACN,MAAM,EACN,IAAY,EACZ,YAAY,EACZ,SAAS,EACT,MAAM,GACP,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAwFnC"}
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
-
import { useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
3
3
|
import { Button, CodeBlock } from "./components.js";
|
|
4
|
+
import { javascriptHighlightRanges } from "./snippet-javascript.js";
|
|
5
|
+
function SnippetCode({ code, language }) {
|
|
6
|
+
const content = useMemo(() => {
|
|
7
|
+
if (language !== "javascript")
|
|
8
|
+
return code;
|
|
9
|
+
const ranges = javascriptHighlightRanges(code);
|
|
10
|
+
if (!ranges.length)
|
|
11
|
+
return code;
|
|
12
|
+
const children = [];
|
|
13
|
+
let offset = 0;
|
|
14
|
+
for (const { start, end, style } of ranges) {
|
|
15
|
+
if (start > offset)
|
|
16
|
+
children.push(code.slice(offset, start));
|
|
17
|
+
children.push(_jsx("span", { class: `mcp-view-snippet-token-${style}`, children: code.slice(start, end) }, start));
|
|
18
|
+
offset = end;
|
|
19
|
+
}
|
|
20
|
+
children.push(code.slice(offset));
|
|
21
|
+
return children;
|
|
22
|
+
}, [code, language]);
|
|
23
|
+
return _jsx(CodeBlock, { children: content });
|
|
24
|
+
}
|
|
4
25
|
/** Search snippet metadata and present caller-supplied source as exact, selectable text. */
|
|
5
26
|
export function SnippetLibrary({ entries = [], source, labels, busy = false, headerAction, onInspect, onBack, }) {
|
|
6
27
|
const [filter, setFilter] = useState("");
|
|
@@ -13,7 +34,7 @@ export function SnippetLibrary({ entries = [], source, labels, busy = false, hea
|
|
|
13
34
|
const matches = entries.filter(({ name, description }) => name.toLocaleLowerCase().includes(query) ||
|
|
14
35
|
description?.toLocaleLowerCase().includes(query));
|
|
15
36
|
return (_jsxs("section", { class: "mcp-view-snippet-library", "aria-label": labels.title, "aria-busy": busy, children: [_jsxs("header", { class: "mcp-view-snippet-header", children: [_jsx("h2", { children: labels.title }), !source && headerAction] }), source
|
|
16
|
-
? (_jsxs("div", { class: "mcp-view-snippet-source", children: [_jsx("h3", { ref: heading, tabIndex: -1, children: _jsx("bdi", { children: source.name }) }), source.description && _jsx("p", { dir: "auto", children: source.description }), _jsx("div", { class: "mcp-view-snippet-code", role: "region", "aria-label": labels.viewNamed(source.name), tabIndex: 0, dir: "ltr", children: _jsx(
|
|
37
|
+
? (_jsxs("div", { class: "mcp-view-snippet-source", children: [_jsx("h3", { ref: heading, tabIndex: -1, children: _jsx("bdi", { children: source.name }) }), source.description && _jsx("p", { dir: "auto", children: source.description }), _jsx("div", { class: "mcp-view-snippet-code", role: "region", "aria-label": labels.viewNamed(source.name), tabIndex: 0, dir: "ltr", children: _jsx(SnippetCode, { code: source.code, language: source.language }) }), onBack && (_jsx(Button, { disabled: busy, onClick: onBack, children: labels.back }))] }))
|
|
17
38
|
: (_jsxs(_Fragment, { children: [_jsxs("label", { class: "mcp-view-snippet-search", children: [labels.search, _jsx("input", { class: "mcp-view-text-input", type: "search", ref: search, value: filter, onInput: (event) => setFilter(event.currentTarget.value) })] }), matches.length > 0
|
|
18
39
|
? (_jsx("ul", { class: "mcp-view-snippet-list", children: matches.map((entry) => (_jsxs("li", { children: [_jsxs("div", { children: [_jsx("strong", { children: _jsx("bdi", { children: entry.name }) }), entry.description && _jsx("p", { dir: "auto", children: entry.description })] }), _jsx("button", { class: "mcp-view-button", type: "button", disabled: busy || !onInspect, "aria-label": labels.viewNamed(entry.name), onClick: () => onInspect?.(entry), children: labels.view })] }, entry.id))) }))
|
|
19
40
|
: (_jsx("p", { class: "mcp-view-snippet-empty", role: "status", children: entries.length ? labels.noMatch : labels.empty }))] }))] }));
|
package/esm/src/theme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/src/theme.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,sEAAsE;AACtE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,WAAW,EAAE,yBAAyB,CAAC;IACvC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,WAAW,EAAE,sBAAsB,CAAC;IACpC,GAAG,EAAE,gBAAgB,CAAC;IACtB,aAAa,EAAE,2BAA2B,CAAC;IAC3C,KAAK,EAAE,kBAAkB,CAAC;IAC1B,UAAU,EAAE,wBAAwB,CAAC;IACrC,YAAY,EAAE,0BAA0B,CAAC;IACzC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,UAAU,EAAE,wBAAwB,CAAC;IACrC,SAAS,EAAE,uBAAuB,CAAC;IACnC,WAAW,EAAE,yBAAyB,CAAC;IACvC,aA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,eAAO,MAAM,qBAAqB,EAAE,kBA+CnC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,MAAM,kBAAkB,CAAC,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,MA27DhC,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAC/C,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAAC;CACnD;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,oBAA+B,GACtC,gBAAgB,CASlB"}
|
package/esm/src/theme.js
CHANGED
|
@@ -736,6 +736,17 @@ export const MCP_VIEW_THEME_CSS = String.raw `
|
|
|
736
736
|
border: 0;
|
|
737
737
|
white-space: pre;
|
|
738
738
|
}
|
|
739
|
+
.mcp-view-snippet-code code {
|
|
740
|
+
font-variant-ligatures: none;
|
|
741
|
+
font-feature-settings: "liga" 0, "calt" 0;
|
|
742
|
+
}
|
|
743
|
+
.mcp-view-snippet-token-comment { color: var(--mcp-view-muted); }
|
|
744
|
+
.mcp-view-snippet-token-keyword { color: var(--mcp-view-brand-text); }
|
|
745
|
+
.mcp-view-snippet-token-string {
|
|
746
|
+
color: var(--mcp-view-text-secondary);
|
|
747
|
+
color: color-mix(in srgb, var(--mcp-view-success) 85%, var(--mcp-view-text-secondary));
|
|
748
|
+
}
|
|
749
|
+
.mcp-view-snippet-token-literal { color: var(--mcp-view-accent-text); }
|
|
739
750
|
.mcp-view-snippet-source button { justify-self: start; }
|
|
740
751
|
.mcp-view-snippet-empty {
|
|
741
752
|
padding: 8px;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpview/components",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Optional light-first component runtime for small composable MCP App viewers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"node": ">=20"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
+
"acorn": "^8.19.0",
|
|
65
66
|
"@mcpview/view": "^0.11.1",
|
|
66
67
|
"@mcpview/contracts": "^0.2.1"
|
|
67
68
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Style = "comment" | "keyword" | "string" | "literal";
|
|
2
|
+
type Range = {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
style: Style;
|
|
6
|
+
};
|
|
7
|
+
/** Offset ranges leave line endings, escape sequences and all other source text untouched. */
|
|
8
|
+
export declare function javascriptHighlightRanges(code: string): Range[];
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=snippet-javascript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snippet-javascript.d.ts","sourceRoot":"","sources":["../../../src/src/preact/snippet-javascript.ts"],"names":[],"mappings":"AAEA,KAAK,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC1D,KAAK,KAAK,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAuB1D,8FAA8F;AAC9F,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CAmB/D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.javascriptHighlightRanges = javascriptHighlightRanges;
|
|
4
|
+
const acorn_1 = require("acorn");
|
|
5
|
+
function tokenStyle(type, text) {
|
|
6
|
+
switch (type) {
|
|
7
|
+
case acorn_1.tokTypes.string:
|
|
8
|
+
case acorn_1.tokTypes.regexp:
|
|
9
|
+
case acorn_1.tokTypes.template:
|
|
10
|
+
case acorn_1.tokTypes.invalidTemplate:
|
|
11
|
+
case acorn_1.tokTypes.backQuote:
|
|
12
|
+
return "string";
|
|
13
|
+
case acorn_1.tokTypes.num:
|
|
14
|
+
case acorn_1.tokTypes._null:
|
|
15
|
+
case acorn_1.tokTypes._true:
|
|
16
|
+
case acorn_1.tokTypes._false:
|
|
17
|
+
return "literal";
|
|
18
|
+
case acorn_1.tokTypes.name:
|
|
19
|
+
if (["async", "await", "let", "yield"].includes(text))
|
|
20
|
+
return "keyword";
|
|
21
|
+
return;
|
|
22
|
+
default:
|
|
23
|
+
if (type.keyword)
|
|
24
|
+
return "keyword";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Offset ranges leave line endings, escape sequences and all other source text untouched. */
|
|
28
|
+
function javascriptHighlightRanges(code) {
|
|
29
|
+
const ranges = [];
|
|
30
|
+
try {
|
|
31
|
+
(0, acorn_1.parse)(code, {
|
|
32
|
+
ecmaVersion: "latest",
|
|
33
|
+
sourceType: "module",
|
|
34
|
+
allowReturnOutsideFunction: true,
|
|
35
|
+
onComment: (_block, _text, start, end) => {
|
|
36
|
+
ranges.push({ start, end, style: "comment" });
|
|
37
|
+
},
|
|
38
|
+
onToken: ({ type, start, end }) => {
|
|
39
|
+
const style = tokenStyle(type, code.slice(start, end));
|
|
40
|
+
if (style && start < end)
|
|
41
|
+
ranges.push({ start, end, style });
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
return ranges.sort((a, b) => a.start - b.start);
|
|
49
|
+
}
|
|
@@ -10,6 +10,8 @@ export interface SnippetLibrarySource {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
readonly description?: string;
|
|
12
12
|
readonly code: string;
|
|
13
|
+
/** Omit to display plain text. */
|
|
14
|
+
readonly language?: "javascript";
|
|
13
15
|
}
|
|
14
16
|
export interface SnippetLibraryLabels {
|
|
15
17
|
readonly title: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-library.d.ts","sourceRoot":"","sources":["../../../src/src/preact/snippet-library.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"snippet-library.d.ts","sourceRoot":"","sources":["../../../src/src/preact/snippet-library.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAKrD,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,yEAAyE;IACzE,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC1D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9B;AA4BD,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,EAC7B,OAAY,EACZ,MAAM,EACN,MAAM,EACN,IAAY,EACZ,YAAY,EACZ,SAAS,EACT,MAAM,GACP,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAwFnC"}
|
|
@@ -4,6 +4,27 @@ exports.SnippetLibrary = SnippetLibrary;
|
|
|
4
4
|
const jsx_runtime_1 = require("preact/jsx-runtime");
|
|
5
5
|
const hooks_1 = require("preact/hooks");
|
|
6
6
|
const components_js_1 = require("./components.js");
|
|
7
|
+
const snippet_javascript_js_1 = require("./snippet-javascript.js");
|
|
8
|
+
function SnippetCode({ code, language }) {
|
|
9
|
+
const content = (0, hooks_1.useMemo)(() => {
|
|
10
|
+
if (language !== "javascript")
|
|
11
|
+
return code;
|
|
12
|
+
const ranges = (0, snippet_javascript_js_1.javascriptHighlightRanges)(code);
|
|
13
|
+
if (!ranges.length)
|
|
14
|
+
return code;
|
|
15
|
+
const children = [];
|
|
16
|
+
let offset = 0;
|
|
17
|
+
for (const { start, end, style } of ranges) {
|
|
18
|
+
if (start > offset)
|
|
19
|
+
children.push(code.slice(offset, start));
|
|
20
|
+
children.push((0, jsx_runtime_1.jsx)("span", { class: `mcp-view-snippet-token-${style}`, children: code.slice(start, end) }, start));
|
|
21
|
+
offset = end;
|
|
22
|
+
}
|
|
23
|
+
children.push(code.slice(offset));
|
|
24
|
+
return children;
|
|
25
|
+
}, [code, language]);
|
|
26
|
+
return (0, jsx_runtime_1.jsx)(components_js_1.CodeBlock, { children: content });
|
|
27
|
+
}
|
|
7
28
|
/** Search snippet metadata and present caller-supplied source as exact, selectable text. */
|
|
8
29
|
function SnippetLibrary({ entries = [], source, labels, busy = false, headerAction, onInspect, onBack, }) {
|
|
9
30
|
const [filter, setFilter] = (0, hooks_1.useState)("");
|
|
@@ -16,7 +37,7 @@ function SnippetLibrary({ entries = [], source, labels, busy = false, headerActi
|
|
|
16
37
|
const matches = entries.filter(({ name, description }) => name.toLocaleLowerCase().includes(query) ||
|
|
17
38
|
description?.toLocaleLowerCase().includes(query));
|
|
18
39
|
return ((0, jsx_runtime_1.jsxs)("section", { class: "mcp-view-snippet-library", "aria-label": labels.title, "aria-busy": busy, children: [(0, jsx_runtime_1.jsxs)("header", { class: "mcp-view-snippet-header", children: [(0, jsx_runtime_1.jsx)("h2", { children: labels.title }), !source && headerAction] }), source
|
|
19
|
-
? ((0, jsx_runtime_1.jsxs)("div", { class: "mcp-view-snippet-source", children: [(0, jsx_runtime_1.jsx)("h3", { ref: heading, tabIndex: -1, children: (0, jsx_runtime_1.jsx)("bdi", { children: source.name }) }), source.description && (0, jsx_runtime_1.jsx)("p", { dir: "auto", children: source.description }), (0, jsx_runtime_1.jsx)("div", { class: "mcp-view-snippet-code", role: "region", "aria-label": labels.viewNamed(source.name), tabIndex: 0, dir: "ltr", children: (0, jsx_runtime_1.jsx)(
|
|
40
|
+
? ((0, jsx_runtime_1.jsxs)("div", { class: "mcp-view-snippet-source", children: [(0, jsx_runtime_1.jsx)("h3", { ref: heading, tabIndex: -1, children: (0, jsx_runtime_1.jsx)("bdi", { children: source.name }) }), source.description && (0, jsx_runtime_1.jsx)("p", { dir: "auto", children: source.description }), (0, jsx_runtime_1.jsx)("div", { class: "mcp-view-snippet-code", role: "region", "aria-label": labels.viewNamed(source.name), tabIndex: 0, dir: "ltr", children: (0, jsx_runtime_1.jsx)(SnippetCode, { code: source.code, language: source.language }) }), onBack && ((0, jsx_runtime_1.jsx)(components_js_1.Button, { disabled: busy, onClick: onBack, children: labels.back }))] }))
|
|
20
41
|
: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("label", { class: "mcp-view-snippet-search", children: [labels.search, (0, jsx_runtime_1.jsx)("input", { class: "mcp-view-text-input", type: "search", ref: search, value: filter, onInput: (event) => setFilter(event.currentTarget.value) })] }), matches.length > 0
|
|
21
42
|
? ((0, jsx_runtime_1.jsx)("ul", { class: "mcp-view-snippet-list", children: matches.map((entry) => ((0, jsx_runtime_1.jsxs)("li", { children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("strong", { children: (0, jsx_runtime_1.jsx)("bdi", { children: entry.name }) }), entry.description && (0, jsx_runtime_1.jsx)("p", { dir: "auto", children: entry.description })] }), (0, jsx_runtime_1.jsx)("button", { class: "mcp-view-button", type: "button", disabled: busy || !onInspect, "aria-label": labels.viewNamed(entry.name), onClick: () => onInspect?.(entry), children: labels.view })] }, entry.id))) }))
|
|
22
43
|
: ((0, jsx_runtime_1.jsx)("p", { class: "mcp-view-snippet-empty", role: "status", children: entries.length ? labels.noMatch : labels.empty }))] }))] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/src/theme.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,sEAAsE;AACtE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAA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AgB,mBAAmB,CACjC,MAAM,GAAE,oBAA+B,GACtC,gBAAgB,CASlB"}
|
package/script/src/theme.js
CHANGED
|
@@ -740,6 +740,17 @@ exports.MCP_VIEW_THEME_CSS = String.raw `
|
|
|
740
740
|
border: 0;
|
|
741
741
|
white-space: pre;
|
|
742
742
|
}
|
|
743
|
+
.mcp-view-snippet-code code {
|
|
744
|
+
font-variant-ligatures: none;
|
|
745
|
+
font-feature-settings: "liga" 0, "calt" 0;
|
|
746
|
+
}
|
|
747
|
+
.mcp-view-snippet-token-comment { color: var(--mcp-view-muted); }
|
|
748
|
+
.mcp-view-snippet-token-keyword { color: var(--mcp-view-brand-text); }
|
|
749
|
+
.mcp-view-snippet-token-string {
|
|
750
|
+
color: var(--mcp-view-text-secondary);
|
|
751
|
+
color: color-mix(in srgb, var(--mcp-view-success) 85%, var(--mcp-view-text-secondary));
|
|
752
|
+
}
|
|
753
|
+
.mcp-view-snippet-token-literal { color: var(--mcp-view-accent-text); }
|
|
743
754
|
.mcp-view-snippet-source button { justify-self: start; }
|
|
744
755
|
.mcp-view-snippet-empty {
|
|
745
756
|
padding: 8px;
|