@mcp-b/interactive-components 0.2.0
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/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/code-editor-B94tewLC.js +425 -0
- package/dist/code-preview-gKk0nBKP.js +269 -0
- package/dist/components/code-editor/code-editor.d.ts +65 -0
- package/dist/components/code-editor/code-editor.js +2 -0
- package/dist/components/code-preview/code-preview.d.ts +58 -0
- package/dist/components/code-preview/code-preview.js +3 -0
- package/dist/components/interactive-editor/interactive-editor.d.ts +77 -0
- package/dist/components/interactive-editor/interactive-editor.js +3 -0
- package/dist/components/r-editor/r-editor.d.ts +68 -0
- package/dist/components/r-editor/r-editor.js +2 -0
- package/dist/components/sql-editor/sql-editor.d.ts +78 -0
- package/dist/components/sql-editor/sql-editor.js +2 -0
- package/dist/decorate-DcF3lt7P.js +9 -0
- package/dist/docs/custom-elements.json +2807 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/interactive-editor-WfTWxJGF.js +1454 -0
- package/dist/lib/runner-channel.d.ts +25 -0
- package/dist/lib/runner-channel.js +55 -0
- package/dist/lib/runner-url.d.ts +15 -0
- package/dist/lib/runner-url.js +19 -0
- package/dist/lib/transform.d.ts +2 -0
- package/dist/lib/transform.js +210 -0
- package/dist/r-editor-DwSyDo2i.js +743 -0
- package/dist/runners/ephemeral-indexeddb.js +114 -0
- package/dist/runners/pglite-runner.js +175 -0
- package/dist/runners/pyscript-runner.html +189 -0
- package/dist/runners/webr-runner.html +282 -0
- package/dist/sql-editor-CsNrjJ2_.js +968 -0
- package/dist/themes/interactive.css +79 -0
- package/dist/transform-DWhHlnkw.d.ts +53 -0
- package/dist/vite.d.ts +14 -0
- package/dist/vite.js +62 -0
- package/package.json +96 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editor and syntax-highlighting tokens for the interactive editors.
|
|
3
|
+
*
|
|
4
|
+
* These are component tokens owned by this package, not design-system tokens:
|
|
5
|
+
* CodeMirror needs a named colour per syntax role, and the design system has no
|
|
6
|
+
* such vocabulary. Everything structural (surface, gutter, selection, cursor,
|
|
7
|
+
* text) is expressed in --sigvelo-* so the editors track the active theme, and
|
|
8
|
+
* only the syntax hues are literals — a hue ramp is the one thing that cannot
|
|
9
|
+
* be derived from a neutral-forward semantic palette.
|
|
10
|
+
*
|
|
11
|
+
* Theming follows the design system's contract rather than a class toggle: the
|
|
12
|
+
* document follows the OS by default and [data-theme] is an explicit override.
|
|
13
|
+
* Hues are held at the same tier in both modes so contrast against the editor
|
|
14
|
+
* surface stays even.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
:root {
|
|
18
|
+
/* Structure: derived, so the editor sits on the same surfaces as CodeBlock. */
|
|
19
|
+
--sigvelo-interactive-editor-bg: var(--sigvelo-color-neutral-bg-subtle);
|
|
20
|
+
--sigvelo-interactive-editor-gutter-bg: transparent;
|
|
21
|
+
--sigvelo-interactive-editor-gutter-text: var(--sigvelo-color-text-faint);
|
|
22
|
+
--sigvelo-interactive-editor-selection: var(--sigvelo-color-primary-bg-muted);
|
|
23
|
+
--sigvelo-interactive-editor-active-line: var(--sigvelo-color-neutral-bg-muted);
|
|
24
|
+
--sigvelo-interactive-editor-cursor: var(--sigvelo-color-text);
|
|
25
|
+
--sigvelo-interactive-editor-text: var(--sigvelo-color-text);
|
|
26
|
+
--sigvelo-interactive-preview-bg: var(--sigvelo-color-surface);
|
|
27
|
+
|
|
28
|
+
/* Syntax hues, light. */
|
|
29
|
+
--sigvelo-interactive-syn-keyword: #a032a8;
|
|
30
|
+
--sigvelo-interactive-syn-string: #0a6640;
|
|
31
|
+
--sigvelo-interactive-syn-comment: var(--sigvelo-color-text-subtle);
|
|
32
|
+
--sigvelo-interactive-syn-number: #7c4dff;
|
|
33
|
+
--sigvelo-interactive-syn-function: #0550ae;
|
|
34
|
+
--sigvelo-interactive-syn-variable: #b3541e;
|
|
35
|
+
--sigvelo-interactive-syn-type: #0550ae;
|
|
36
|
+
--sigvelo-interactive-syn-tag: #0a6640;
|
|
37
|
+
--sigvelo-interactive-syn-attribute: #b3541e;
|
|
38
|
+
--sigvelo-interactive-syn-property: #0550ae;
|
|
39
|
+
--sigvelo-interactive-syn-punctuation: var(--sigvelo-color-text-muted);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Syntax hues, dark. Lightened so each role clears AA on the dark surface. */
|
|
43
|
+
@media (prefers-color-scheme: dark) {
|
|
44
|
+
:root {
|
|
45
|
+
--sigvelo-interactive-syn-keyword: #d9a2e8;
|
|
46
|
+
--sigvelo-interactive-syn-string: #7ec699;
|
|
47
|
+
--sigvelo-interactive-syn-number: #c4a7ff;
|
|
48
|
+
--sigvelo-interactive-syn-function: #86baf5;
|
|
49
|
+
--sigvelo-interactive-syn-variable: #e8a87c;
|
|
50
|
+
--sigvelo-interactive-syn-type: #86baf5;
|
|
51
|
+
--sigvelo-interactive-syn-tag: #7ec699;
|
|
52
|
+
--sigvelo-interactive-syn-attribute: #e8a87c;
|
|
53
|
+
--sigvelo-interactive-syn-property: #86baf5;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
[data-theme="light"] {
|
|
58
|
+
--sigvelo-interactive-syn-keyword: #a032a8;
|
|
59
|
+
--sigvelo-interactive-syn-string: #0a6640;
|
|
60
|
+
--sigvelo-interactive-syn-number: #7c4dff;
|
|
61
|
+
--sigvelo-interactive-syn-function: #0550ae;
|
|
62
|
+
--sigvelo-interactive-syn-variable: #b3541e;
|
|
63
|
+
--sigvelo-interactive-syn-type: #0550ae;
|
|
64
|
+
--sigvelo-interactive-syn-tag: #0a6640;
|
|
65
|
+
--sigvelo-interactive-syn-attribute: #b3541e;
|
|
66
|
+
--sigvelo-interactive-syn-property: #0550ae;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[data-theme="dark"] {
|
|
70
|
+
--sigvelo-interactive-syn-keyword: #d9a2e8;
|
|
71
|
+
--sigvelo-interactive-syn-string: #7ec699;
|
|
72
|
+
--sigvelo-interactive-syn-number: #c4a7ff;
|
|
73
|
+
--sigvelo-interactive-syn-function: #86baf5;
|
|
74
|
+
--sigvelo-interactive-syn-variable: #e8a87c;
|
|
75
|
+
--sigvelo-interactive-syn-type: #86baf5;
|
|
76
|
+
--sigvelo-interactive-syn-tag: #7ec699;
|
|
77
|
+
--sigvelo-interactive-syn-attribute: #e8a87c;
|
|
78
|
+
--sigvelo-interactive-syn-property: #86baf5;
|
|
79
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/lib/transform.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* In-browser code transformation and preview building.
|
|
4
|
+
*
|
|
5
|
+
* - esm.sh transform API for TS/TSX/JSX → ES module transpilation
|
|
6
|
+
* - Blob URLs for inter-file module resolution
|
|
7
|
+
* - Import rewriting for npm packages via esm.sh CDN
|
|
8
|
+
*/
|
|
9
|
+
type FileLanguage = "javascript" | "typescript" | "jsx" | "tsx" | "html" | "css" | "python" | "r" | "sql";
|
|
10
|
+
interface EditorFile {
|
|
11
|
+
name: string;
|
|
12
|
+
content: string;
|
|
13
|
+
language?: FileLanguage;
|
|
14
|
+
}
|
|
15
|
+
declare function detectLanguage(filename: string): FileLanguage;
|
|
16
|
+
declare function needsTransform(lang: FileLanguage): boolean;
|
|
17
|
+
declare function transformCode(code: string, filename: string): Promise<string>;
|
|
18
|
+
/** Rewrites bare npm specifiers (`from 'react'`) to esm.sh CDN URLs. */
|
|
19
|
+
declare function rewriteNpmImports(code: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Builds a preview for HTML-entry projects. Inlines referenced CSS and JS
|
|
22
|
+
* files, transforming TS/JSX as needed.
|
|
23
|
+
*/
|
|
24
|
+
declare function buildHtmlPreview(files: Map<string, EditorFile>): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Builds a preview for module-entry projects (TS/TSX/JS). Transforms each
|
|
27
|
+
* file, creates Blob URLs for inter-file imports, and wraps in HTML.
|
|
28
|
+
*
|
|
29
|
+
* Returns `{ html, blobUrls }` — caller should revoke blob URLs on cleanup.
|
|
30
|
+
*/
|
|
31
|
+
declare function buildModulePreview(files: Map<string, EditorFile>, entryName: string): Promise<{
|
|
32
|
+
html: string;
|
|
33
|
+
blobUrls: string[];
|
|
34
|
+
}>;
|
|
35
|
+
/** Payload sent to the pyscript-runner.html page via postMessage. */
|
|
36
|
+
interface PyScriptRunPayload {
|
|
37
|
+
type: "pyscript-run";
|
|
38
|
+
code: string;
|
|
39
|
+
bodyHtml: string;
|
|
40
|
+
css: string;
|
|
41
|
+
config: Record<string, unknown> | null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds a postMessage payload for the PyScript runner page.
|
|
45
|
+
*
|
|
46
|
+
* PyScript cannot run inside srcdoc or blob-URL iframes because it uses
|
|
47
|
+
* `new URL(m, location.href)` internally, and those iframe types have
|
|
48
|
+
* invalid base URLs. Instead, we load a static `pyscript-runner.html`
|
|
49
|
+
* page (served at a real HTTP URL) and send code to it via postMessage.
|
|
50
|
+
*/
|
|
51
|
+
declare function buildPythonPayload(files: Map<string, EditorFile>, entryName: string): PyScriptRunPayload;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { buildModulePreview as a, needsTransform as c, buildHtmlPreview as i, rewriteNpmImports as l, FileLanguage as n, buildPythonPayload as o, PyScriptRunPayload as r, detectLanguage as s, EditorFile as t, transformCode as u };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { viteStaticCopy } from "vite-plugin-static-copy";
|
|
2
|
+
|
|
3
|
+
//#region src/vite.d.ts
|
|
4
|
+
interface InteractiveRuntimeAssetsOptions {
|
|
5
|
+
/** Output directory relative to Vite's public/build root. */
|
|
6
|
+
destination?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Copies the sandbox runner entry points and installed engine assets into a
|
|
10
|
+
* Vite application's public output without embedding them in this package.
|
|
11
|
+
*/
|
|
12
|
+
declare function interactiveRuntimeAssets(options?: InteractiveRuntimeAssetsOptions): ReturnType<typeof viteStaticCopy>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { InteractiveRuntimeAssetsOptions, interactiveRuntimeAssets };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join, posix, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { viteStaticCopy } from "vite-plugin-static-copy";
|
|
5
|
+
//#region src/vite.ts
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const runnerRoot = resolve(dirname(fileURLToPath(import.meta.url)), "runners");
|
|
8
|
+
function packageRuntime(entrypoint, license) {
|
|
9
|
+
const dist = dirname(require.resolve(entrypoint));
|
|
10
|
+
return {
|
|
11
|
+
dist,
|
|
12
|
+
license: resolve(dist, "..", license)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function pyscriptRuntime() {
|
|
16
|
+
const root = dirname(require.resolve("@pyscript/core/package.json"));
|
|
17
|
+
return {
|
|
18
|
+
dist: resolve(root, "dist"),
|
|
19
|
+
license: resolve(root, "LICENSE")
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Copies the sandbox runner entry points and installed engine assets into a
|
|
24
|
+
* Vite application's public output without embedding them in this package.
|
|
25
|
+
*/
|
|
26
|
+
function interactiveRuntimeAssets(options = {}) {
|
|
27
|
+
const destination = options.destination ?? "sigvelo-runners";
|
|
28
|
+
const runtimes = [
|
|
29
|
+
{
|
|
30
|
+
directory: "pglite",
|
|
31
|
+
...packageRuntime("@electric-sql/pglite", "LICENSE")
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
directory: "pglite-postgis",
|
|
35
|
+
...packageRuntime("@electric-sql/pglite-postgis", "LICENSE")
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
directory: "pyscript",
|
|
39
|
+
...pyscriptRuntime()
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
directory: "webr",
|
|
43
|
+
...packageRuntime("webr", "LICENSE.md")
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
return viteStaticCopy({ targets: [{
|
|
47
|
+
src: join(runnerRoot, "*.{html,js}"),
|
|
48
|
+
dest: destination
|
|
49
|
+
}, ...runtimes.flatMap(({ directory, dist, license }) => {
|
|
50
|
+
const runtimeDestination = posix.join(destination, directory);
|
|
51
|
+
return [{
|
|
52
|
+
src: dist,
|
|
53
|
+
dest: runtimeDestination,
|
|
54
|
+
rename: "."
|
|
55
|
+
}, {
|
|
56
|
+
src: license,
|
|
57
|
+
dest: runtimeDestination
|
|
58
|
+
}];
|
|
59
|
+
})] });
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { interactiveRuntimeAssets };
|
package/package.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcp-b/interactive-components",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Sigvelo interactive code editor components built with Lit.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"code-editor",
|
|
7
|
+
"codemirror",
|
|
8
|
+
"custom-elements",
|
|
9
|
+
"interactive",
|
|
10
|
+
"lit-element",
|
|
11
|
+
"typescript",
|
|
12
|
+
"web-components"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/WebMCP-org/design-system.git",
|
|
18
|
+
"directory": "packages/interactive-components"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./components/*": "./dist/components/*",
|
|
31
|
+
"./runners/*": "./dist/runners/*",
|
|
32
|
+
"./themes/*": "./dist/themes/*",
|
|
33
|
+
"./vite": {
|
|
34
|
+
"types": "./dist/vite.d.ts",
|
|
35
|
+
"import": "./dist/vite.js"
|
|
36
|
+
},
|
|
37
|
+
"./custom-elements.json": "./dist/docs/custom-elements.json"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@codemirror/autocomplete": "^6.18.6",
|
|
44
|
+
"@codemirror/commands": "^6.8.1",
|
|
45
|
+
"@codemirror/lang-css": "^6.3.1",
|
|
46
|
+
"@codemirror/lang-html": "^6.4.9",
|
|
47
|
+
"@codemirror/lang-javascript": "^6.2.3",
|
|
48
|
+
"@codemirror/lang-python": "^6.2.1",
|
|
49
|
+
"@codemirror/lang-sql": "^6.8.0",
|
|
50
|
+
"@codemirror/language": "^6.11.0",
|
|
51
|
+
"@codemirror/legacy-modes": "^6.5.2",
|
|
52
|
+
"@codemirror/search": "^6.5.10",
|
|
53
|
+
"@codemirror/state": "^6.5.2",
|
|
54
|
+
"@codemirror/theme-one-dark": "^6.1.2",
|
|
55
|
+
"@codemirror/view": "^6.36.8",
|
|
56
|
+
"@electric-sql/pglite": "0.4.2",
|
|
57
|
+
"@electric-sql/pglite-postgis": "0.0.4",
|
|
58
|
+
"@lezer/highlight": "^1.2.1",
|
|
59
|
+
"@pyscript/core": "0.7.19",
|
|
60
|
+
"vite-plugin-static-copy": "^3.3.0",
|
|
61
|
+
"webr": "0.5.8",
|
|
62
|
+
"@mcp-b/wc-support": "0.2.0",
|
|
63
|
+
"@mcp-b/web-components": "0.2.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@custom-elements-manifest/analyzer": "^0.10.4",
|
|
67
|
+
"@storybook/addon-a11y": "^10.5.2",
|
|
68
|
+
"@storybook/addon-docs": "^10.5.2",
|
|
69
|
+
"@storybook/addon-vitest": "^10.5.2",
|
|
70
|
+
"@storybook/web-components-vite": "10.5.2",
|
|
71
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
72
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
73
|
+
"playwright": "~1.61.0",
|
|
74
|
+
"storybook": "^10.5.2",
|
|
75
|
+
"tinyglobby": "^0.2.15",
|
|
76
|
+
"typescript": "^6.0.3",
|
|
77
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
78
|
+
"vite-plugin-static-copy": "^3.3.0",
|
|
79
|
+
"vitest": "^4.1.10"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"lit": "^3.0.0",
|
|
83
|
+
"lit-html": "^3.0.0"
|
|
84
|
+
},
|
|
85
|
+
"customElements": "dist/docs/custom-elements.json",
|
|
86
|
+
"scripts": {
|
|
87
|
+
"analyze": "cem analyze --globs \"src/**/*.ts\" --exclude \"**/*.stories.ts\" --exclude \"**/*.test.ts\" --exclude \"**/*.styles.ts\" --outdir \"dist/docs\"",
|
|
88
|
+
"analyze:dev": "cem analyze --globs \"src/**/*.ts\" --exclude \"**/*.stories.ts\" --exclude \"**/*.test.ts\" --exclude \"**/*.styles.ts\" --outdir \"dist/docs\" --watch",
|
|
89
|
+
"build": "tsc -p tsconfig.prod.json && vp run build:lib && vp run analyze",
|
|
90
|
+
"build:lib": "vp pack && node scripts/copy-runner-entrypoints.mjs",
|
|
91
|
+
"lint": "cem analyze",
|
|
92
|
+
"storybook": "vp run @mcp-b/web-components#storybook",
|
|
93
|
+
"test": "vp run @mcp-b/web-components#test",
|
|
94
|
+
"typecheck": "tsc --noEmit"
|
|
95
|
+
}
|
|
96
|
+
}
|