@thedatagrid/docs-kit 0.1.0 → 0.2.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/CHANGELOG.md +19 -0
- package/README.md +106 -3
- package/dist/demos/cli.js +35 -1
- package/dist/demos/cli.js.map +1 -1
- package/dist/demos/pages.d.ts +2 -1
- package/dist/demos/pages.d.ts.map +1 -1
- package/dist/demos/pages.js +26 -1
- package/dist/demos/pages.js.map +1 -1
- package/dist/editor/install.d.ts +15 -0
- package/dist/editor/install.d.ts.map +1 -0
- package/dist/editor/install.js +71 -0
- package/dist/editor/install.js.map +1 -0
- package/dist/react/editor.d.ts +9 -0
- package/dist/react/editor.d.ts.map +1 -1
- package/dist/react/editor.js +111 -5
- package/dist/react/editor.js.map +1 -1
- package/dist/react/styles.css +87 -109
- package/dist/remark/remarkDemoFences.d.ts +14 -3
- package/dist/remark/remarkDemoFences.d.ts.map +1 -1
- package/dist/remark/remarkDemoFences.js +60 -3
- package/dist/remark/remarkDemoFences.js.map +1 -1
- package/editor-extension/README.md +23 -0
- package/editor-extension/extension.js +40 -0
- package/editor-extension/links.js +137 -0
- package/editor-extension/package.json +19 -0
- package/package.json +2 -1
- package/src/demos/cli.ts +34 -1
- package/src/demos/pages.ts +24 -1
- package/src/editor/install.ts +85 -0
- package/src/react/editor.ts +122 -5
- package/src/react/styles.css +87 -109
- package/src/remark/remarkDemoFences.ts +60 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thedatagrid/docs-kit",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Docs tooling: type-checked file snippets with regions and highlights, prebuilt and editable live demos, CodeSandbox forks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"files": [
|
|
59
59
|
"dist",
|
|
60
60
|
"src",
|
|
61
|
+
"editor-extension",
|
|
61
62
|
"README.md",
|
|
62
63
|
"CHANGELOG.md"
|
|
63
64
|
],
|
package/src/demos/cli.ts
CHANGED
|
@@ -5,24 +5,57 @@
|
|
|
5
5
|
* Loads `docs-kit.config.{mjs,js,ts}` from the current folder (or `--config`)
|
|
6
6
|
* and prebuilds the demos. The config's default export is a `DocsKitConfig`
|
|
7
7
|
* or a (sync/async) function returning one.
|
|
8
|
+
*
|
|
9
|
+
* `docs-kit editor install [code] [cursor]` installs the docs-kit links
|
|
10
|
+
* extension (cmd+click `file="…"` in fences) into VS Code and/or Cursor;
|
|
11
|
+
* `docs-kit editor package [--out <file>]` only builds its .vsix.
|
|
8
12
|
*/
|
|
9
13
|
import fs from 'node:fs';
|
|
10
14
|
import path from 'node:path';
|
|
11
15
|
import { pathToFileURL } from 'node:url';
|
|
12
16
|
|
|
17
|
+
import { installExtension, packageExtension, type Editor } from '../editor/install.ts';
|
|
13
18
|
import { buildDemos } from './build.ts';
|
|
14
19
|
import type { DocsKitConfig } from './config.ts';
|
|
15
20
|
|
|
16
21
|
const CONFIG_NAMES = ['docs-kit.config.mjs', 'docs-kit.config.js', 'docs-kit.config.ts'];
|
|
17
22
|
|
|
18
23
|
function usage(): never {
|
|
19
|
-
console.error(
|
|
24
|
+
console.error(
|
|
25
|
+
[
|
|
26
|
+
'usage: docs-kit demos [build] [--watch] [--config <file>]',
|
|
27
|
+
' docs-kit editor install [code] [cursor]',
|
|
28
|
+
' docs-kit editor package [--out <file>]',
|
|
29
|
+
].join('\n'),
|
|
30
|
+
);
|
|
20
31
|
process.exit(1);
|
|
21
32
|
}
|
|
22
33
|
|
|
34
|
+
function editorCommand(args: string[]) {
|
|
35
|
+
const sub = args.shift();
|
|
36
|
+
if (sub === 'install') {
|
|
37
|
+
const only = args.map((arg) => (arg === 'code' || arg === 'cursor' ? (arg as Editor) : usage()));
|
|
38
|
+
const { installed } = installExtension(only);
|
|
39
|
+
if (only.length && installed.length < only.length) process.exit(1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (sub === 'package') {
|
|
43
|
+
let out: string | undefined;
|
|
44
|
+
while (args.length) {
|
|
45
|
+
const arg = args.shift()!;
|
|
46
|
+
if (arg === '--out' || arg === '-o') out = args.shift() ?? usage();
|
|
47
|
+
else usage();
|
|
48
|
+
}
|
|
49
|
+
console.log(packageExtension(out));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
usage();
|
|
53
|
+
}
|
|
54
|
+
|
|
23
55
|
async function main(argv: string[]) {
|
|
24
56
|
const args = [...argv];
|
|
25
57
|
const command = args.shift();
|
|
58
|
+
if (command === 'editor') return editorCommand(args);
|
|
26
59
|
if (command !== 'demos') usage();
|
|
27
60
|
if (args[0] === 'build') args.shift();
|
|
28
61
|
|
package/src/demos/pages.ts
CHANGED
|
@@ -18,6 +18,26 @@ export function findFiles(dir: string, suffix: string): string[] {
|
|
|
18
18
|
return walk(dir, (name) => name.endsWith(suffix)).sort();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The `<DemoTitle>` among the `<DemoTitle>` / `<DemoDescription>` blocks
|
|
23
|
+
* that end right before a fence (no `<Demo>` wrapper), or null.
|
|
24
|
+
*/
|
|
25
|
+
function looseDemoTitle(before: string): string | null {
|
|
26
|
+
let rest = before.trimEnd();
|
|
27
|
+
for (let part = 0; part < 2; part++) {
|
|
28
|
+
const close = /<\/(DemoTitle|DemoDescription)>$/.exec(rest);
|
|
29
|
+
if (!close) return null;
|
|
30
|
+
const start = rest.lastIndexOf(`<${close[1]}>`);
|
|
31
|
+
if (start === -1) return null;
|
|
32
|
+
if (close[1] === 'DemoTitle') {
|
|
33
|
+
const text = rest.slice(start + '<DemoTitle>'.length, close.index);
|
|
34
|
+
return text.replace(/<[^>]+>/g, '').trim() || null;
|
|
35
|
+
}
|
|
36
|
+
rest = rest.slice(0, start).trimEnd();
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
21
41
|
const toPosix = (p: string) => p.split(path.sep).join('/');
|
|
22
42
|
|
|
23
43
|
export function defaultRouteForPage(pagePath: string): string {
|
|
@@ -28,7 +48,8 @@ export function defaultRouteForPage(pagePath: string): string {
|
|
|
28
48
|
/**
|
|
29
49
|
* Maps demo ids to the docs page (and card anchor) that shows them, so a demo
|
|
30
50
|
* opened on its own can link back. The anchor matches the `<Demo>` card's
|
|
31
|
-
* slug: `<DemoTitle>`
|
|
51
|
+
* slug: `<DemoTitle>` (inside `<Demo>`, or right before the fence) > `<Demo title>`
|
|
52
|
+
* > the fence's `title` > `<name>.demo.tsx`.
|
|
32
53
|
*/
|
|
33
54
|
export function findDocsLinks(options: {
|
|
34
55
|
contentDir: string;
|
|
@@ -67,6 +88,8 @@ export function findDocsLinks(options: {
|
|
|
67
88
|
const demoTitle = /<DemoTitle>\s*([\s\S]*?)\s*<\/DemoTitle>/.exec(block);
|
|
68
89
|
const titleAttr = /^<Demo\b[^>]*\btitle=(?:"([^"]*)"|'([^']*)')/.exec(block);
|
|
69
90
|
title = demoTitle?.[1].replace(/<[^>]+>/g, '').trim() || titleAttr?.[1] || titleAttr?.[2] || null;
|
|
91
|
+
} else {
|
|
92
|
+
title = looseDemoTitle(before);
|
|
70
93
|
}
|
|
71
94
|
if (!title) {
|
|
72
95
|
const fenceTitle = /\btitle=(?:"([^"]*)"|'([^']*)')/.exec(info);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `docs-kit editor install|package`: packages the docs-kit links extension
|
|
3
|
+
* (`editor-extension/` in this package) into a .vsix with @vscode/vsce and
|
|
4
|
+
* installs it into VS Code and/or Cursor.
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
|
|
12
|
+
/** Same folder from `src/editor/` (local mode) and `dist/editor/` (the package). */
|
|
13
|
+
const packageRoot = fileURLToPath(new URL('../../', import.meta.url));
|
|
14
|
+
export const EXTENSION_DIR = path.join(packageRoot, 'editor-extension');
|
|
15
|
+
const VSCE = '@vscode/vsce@4.1.0';
|
|
16
|
+
const FILES = ['package.json', 'extension.js', 'links.js', 'README.md'];
|
|
17
|
+
|
|
18
|
+
export type Editor = 'code' | 'cursor';
|
|
19
|
+
|
|
20
|
+
const APP_BINARIES: Record<Editor, string[]> = {
|
|
21
|
+
code: ['/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'],
|
|
22
|
+
cursor: ['/Applications/Cursor.app/Contents/Resources/app/bin/cursor'],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function onPath(command: string): string | null {
|
|
26
|
+
const result = spawnSync(process.platform === 'win32' ? 'where' : 'which', [command], { encoding: 'utf8' });
|
|
27
|
+
return result.status === 0 ? result.stdout.split(/\r?\n/)[0].trim() || null : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The CLI of each editor that is installed (`code`, `cursor`). */
|
|
31
|
+
export function findEditors(only?: Editor[]): { editor: Editor; bin: string }[] {
|
|
32
|
+
return (Object.keys(APP_BINARIES) as Editor[])
|
|
33
|
+
.filter((editor) => !only?.length || only.includes(editor))
|
|
34
|
+
.flatMap((editor) => {
|
|
35
|
+
const bin = onPath(editor) ?? APP_BINARIES[editor].find((file) => fs.existsSync(file));
|
|
36
|
+
return bin ? [{ editor, bin }] : [];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Packages the extension, versioned like this docs-kit, into `outFile` (default: a temp file). */
|
|
41
|
+
export function packageExtension(outFile?: string): string {
|
|
42
|
+
const { version } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8')) as {
|
|
43
|
+
version: string;
|
|
44
|
+
};
|
|
45
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'docs-kit-editor-'));
|
|
46
|
+
for (const file of FILES) fs.copyFileSync(path.join(EXTENSION_DIR, file), path.join(work, file));
|
|
47
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(work, 'package.json'), 'utf8')) as { version: string };
|
|
48
|
+
manifest.version = version;
|
|
49
|
+
fs.writeFileSync(path.join(work, 'package.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
50
|
+
|
|
51
|
+
const out = path.resolve(outFile ?? path.join(work, `docs-kit-links-${version}.vsix`));
|
|
52
|
+
const result = spawnSync(
|
|
53
|
+
'npx',
|
|
54
|
+
['--yes', VSCE, 'package', '--no-dependencies', '--skip-license', '--allow-missing-repository', '-o', out],
|
|
55
|
+
{ cwd: work, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', shell: process.platform === 'win32' },
|
|
56
|
+
);
|
|
57
|
+
if (result.status !== 0 || !fs.existsSync(out)) {
|
|
58
|
+
throw new Error(`[docs-kit] packaging the editor extension failed:\n${result.stdout}${result.stderr}`);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Packages the extension and installs it into each editor found (or the ones in `only`). */
|
|
64
|
+
export function installExtension(only?: Editor[], log: (message: string) => void = console.log) {
|
|
65
|
+
const editors = findEditors(only);
|
|
66
|
+
const vsix = packageExtension();
|
|
67
|
+
if (!editors.length) {
|
|
68
|
+
log(
|
|
69
|
+
`[docs-kit] no VS Code or Cursor CLI found. Install ${vsix} from the editor ` +
|
|
70
|
+
'(Extensions → … → Install from VSIX).',
|
|
71
|
+
);
|
|
72
|
+
return { vsix, installed: [] as Editor[] };
|
|
73
|
+
}
|
|
74
|
+
const installed: Editor[] = [];
|
|
75
|
+
for (const { editor, bin } of editors) {
|
|
76
|
+
const result = spawnSync(bin, ['--install-extension', vsix, '--force'], { encoding: 'utf8' });
|
|
77
|
+
if (result.status === 0) {
|
|
78
|
+
installed.push(editor);
|
|
79
|
+
log(`[docs-kit] installed the docs-kit links extension in ${editor}. Reload its windows to use it.`);
|
|
80
|
+
} else {
|
|
81
|
+
log(`[docs-kit] installing in ${editor} failed:\n${result.stdout}${result.stderr}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { vsix, installed };
|
|
85
|
+
}
|
package/src/react/editor.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CodeMirror 6 for demo editing. Only imported (dynamically) when someone
|
|
3
|
-
* clicks Edit, so pages that are just read never download it.
|
|
4
|
-
*
|
|
3
|
+
* clicks Edit, so pages that are just read never download it.
|
|
4
|
+
*
|
|
5
|
+
* Every color, and the font, comes from a `--dk-editor-*` CSS variable, so a
|
|
6
|
+
* site restyles the editor from its own CSS (see "Theming" in the README).
|
|
7
|
+
* The variables a site doesn't set fall back to the card's `--dk-*` ones
|
|
8
|
+
* (styles.css), so the editor matches the cards by default.
|
|
5
9
|
*/
|
|
6
10
|
import { autocompletion, closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
|
|
7
11
|
import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
|
8
12
|
import { css } from '@codemirror/lang-css';
|
|
9
13
|
import { javascript } from '@codemirror/lang-javascript';
|
|
10
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
bracketMatching,
|
|
16
|
+
HighlightStyle,
|
|
17
|
+
indentOnInput,
|
|
18
|
+
indentUnit,
|
|
19
|
+
syntaxHighlighting,
|
|
20
|
+
} from '@codemirror/language';
|
|
11
21
|
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
|
|
12
22
|
import { EditorState, type Extension } from '@codemirror/state';
|
|
13
23
|
import {
|
|
@@ -18,7 +28,113 @@ import {
|
|
|
18
28
|
keymap,
|
|
19
29
|
lineNumbers,
|
|
20
30
|
} from '@codemirror/view';
|
|
21
|
-
import {
|
|
31
|
+
import { tags as t } from '@lezer/highlight';
|
|
32
|
+
|
|
33
|
+
/** `var(--dk-editor-<name>, <fallback>)` */
|
|
34
|
+
const v = (name: string, fallback: string) => `var(--dk-editor-${name}, ${fallback})`;
|
|
35
|
+
|
|
36
|
+
const fg = v('fg', 'var(--dk-fg)');
|
|
37
|
+
const bg = v('bg', 'var(--dk-code-bg)');
|
|
38
|
+
const activeLineBg = v('active-line-bg', 'var(--dk-accent-soft)');
|
|
39
|
+
const gutterFg = v('gutter-fg', 'var(--dk-line-number, var(--dk-faint))');
|
|
40
|
+
const border = v('border', 'var(--dk-border)');
|
|
41
|
+
const surface = v('panel-bg', 'var(--dk-surface)');
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Editor chrome. Rules in an `EditorView.theme` come after CodeMirror's base
|
|
45
|
+
* theme, so they win over its light defaults without `!important`.
|
|
46
|
+
*/
|
|
47
|
+
export const editorTheme = EditorView.theme({
|
|
48
|
+
'&': {
|
|
49
|
+
height: '100%',
|
|
50
|
+
color: fg,
|
|
51
|
+
backgroundColor: bg,
|
|
52
|
+
fontSize: v('font-size', 'var(--dk-code-font-size, 13.5px)'),
|
|
53
|
+
},
|
|
54
|
+
'&.cm-focused': { outline: 'none' },
|
|
55
|
+
'.cm-scroller': {
|
|
56
|
+
fontFamily: v('font-family', 'var(--dk-font-mono)'),
|
|
57
|
+
lineHeight: v('line-height', 'var(--dk-code-line-height, 1.6)'),
|
|
58
|
+
},
|
|
59
|
+
'.cm-content': { caretColor: v('cursor', fg) },
|
|
60
|
+
'.cm-cursor, .cm-dropCursor': { borderLeftColor: v('cursor', fg) },
|
|
61
|
+
'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection':
|
|
62
|
+
{ backgroundColor: v('selection-bg', 'var(--dk-accent-soft)') },
|
|
63
|
+
'.cm-activeLine': { backgroundColor: activeLineBg },
|
|
64
|
+
'.cm-gutters': {
|
|
65
|
+
backgroundColor: v('gutter-bg', bg),
|
|
66
|
+
color: gutterFg,
|
|
67
|
+
border: 'none',
|
|
68
|
+
borderRight: `1px solid ${v('gutter-border', 'transparent')}`,
|
|
69
|
+
},
|
|
70
|
+
'.cm-activeLineGutter': {
|
|
71
|
+
backgroundColor: v('active-line-gutter-bg', activeLineBg),
|
|
72
|
+
color: v('active-line-gutter-fg', gutterFg),
|
|
73
|
+
},
|
|
74
|
+
'.cm-selectionMatch': { backgroundColor: v('selection-match-bg', 'var(--dk-accent-soft)') },
|
|
75
|
+
'&.cm-focused .cm-matchingBracket': {
|
|
76
|
+
backgroundColor: v('bracket-match-bg', 'var(--dk-accent-soft)'),
|
|
77
|
+
outline: `1px solid ${v('bracket-match-outline', 'var(--dk-accent)')}`,
|
|
78
|
+
},
|
|
79
|
+
'&.cm-focused .cm-nonmatchingBracket': {
|
|
80
|
+
backgroundColor: 'transparent',
|
|
81
|
+
outline: `1px solid ${v('invalid', 'var(--dk-error)')}`,
|
|
82
|
+
},
|
|
83
|
+
'.cm-searchMatch': {
|
|
84
|
+
backgroundColor: v('search-match-bg', 'var(--dk-highlight-bg)'),
|
|
85
|
+
outline: `1px solid ${v('search-match-outline', 'var(--dk-highlight-border)')}`,
|
|
86
|
+
},
|
|
87
|
+
'.cm-searchMatch.cm-searchMatch-selected': {
|
|
88
|
+
backgroundColor: v('search-match-selected-bg', 'var(--dk-accent-soft)'),
|
|
89
|
+
},
|
|
90
|
+
'.cm-tooltip': {
|
|
91
|
+
border: `1px solid ${border}`,
|
|
92
|
+
backgroundColor: v('tooltip-bg', surface),
|
|
93
|
+
color: v('tooltip-fg', fg),
|
|
94
|
+
},
|
|
95
|
+
'.cm-tooltip-autocomplete > ul > li[aria-selected]': {
|
|
96
|
+
backgroundColor: v('tooltip-selected-bg', 'var(--dk-accent-soft)'),
|
|
97
|
+
color: v('tooltip-selected-fg', fg),
|
|
98
|
+
},
|
|
99
|
+
'.cm-panels': { backgroundColor: surface, color: v('panel-fg', fg) },
|
|
100
|
+
'.cm-panels.cm-panels-top': { borderBottom: `1px solid ${border}` },
|
|
101
|
+
'.cm-panels.cm-panels-bottom': { borderTop: `1px solid ${border}` },
|
|
102
|
+
'.cm-textfield, .cm-button': {
|
|
103
|
+
border: `1px solid ${border}`,
|
|
104
|
+
borderRadius: '4px',
|
|
105
|
+
backgroundColor: bg,
|
|
106
|
+
backgroundImage: 'none',
|
|
107
|
+
color: fg,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/** Syntax colors: one variable per token group (README → Theming). */
|
|
112
|
+
export const editorHighlightStyle = HighlightStyle.define([
|
|
113
|
+
{ tag: t.keyword, color: v('keyword', 'var(--dk-fg)') },
|
|
114
|
+
{ tag: [t.self, t.null, t.bool, t.atom], color: v('constant', v('keyword', 'var(--dk-fg)')) },
|
|
115
|
+
{ tag: [t.number, t.unit, t.color], color: v('number', 'var(--dk-fg)') },
|
|
116
|
+
{ tag: [t.string, t.special(t.string), t.character], color: v('string', 'var(--dk-fg)') },
|
|
117
|
+
{ tag: [t.regexp, t.escape], color: v('regexp', v('string', 'var(--dk-fg)')) },
|
|
118
|
+
{
|
|
119
|
+
tag: t.comment,
|
|
120
|
+
color: v('comment', 'var(--dk-faint)'),
|
|
121
|
+
fontStyle: v('comment-font-style', 'italic'),
|
|
122
|
+
},
|
|
123
|
+
{ tag: [t.typeName, t.className, t.namespace], color: v('type', 'var(--dk-fg)') },
|
|
124
|
+
{
|
|
125
|
+
tag: [t.function(t.variableName), t.function(t.propertyName)],
|
|
126
|
+
color: v('function', 'var(--dk-fg)'),
|
|
127
|
+
},
|
|
128
|
+
{ tag: t.definition(t.variableName), color: v('definition', v('function', 'var(--dk-fg)')) },
|
|
129
|
+
{ tag: t.variableName, color: v('variable', fg) },
|
|
130
|
+
{ tag: t.propertyName, color: v('property', 'var(--dk-fg)') },
|
|
131
|
+
{ tag: t.tagName, color: v('tag', 'var(--dk-fg)') },
|
|
132
|
+
{ tag: t.attributeName, color: v('attribute', 'var(--dk-fg)') },
|
|
133
|
+
{ tag: t.operator, color: v('operator', fg) },
|
|
134
|
+
{ tag: [t.punctuation, t.bracket, t.separator], color: v('punctuation', fg) },
|
|
135
|
+
{ tag: t.meta, color: v('meta', v('comment', 'var(--dk-faint)')) },
|
|
136
|
+
{ tag: t.invalid, color: v('invalid', 'var(--dk-error)') },
|
|
137
|
+
]);
|
|
22
138
|
|
|
23
139
|
function languageFor(fileName: string): Extension {
|
|
24
140
|
if (/\.css$/.test(fileName)) return css();
|
|
@@ -47,7 +163,8 @@ export function createCodeEditor(
|
|
|
47
163
|
closeBrackets(),
|
|
48
164
|
autocompletion({ activateOnTyping: false }),
|
|
49
165
|
highlightSelectionMatches(),
|
|
50
|
-
|
|
166
|
+
editorTheme,
|
|
167
|
+
syntaxHighlighting(editorHighlightStyle),
|
|
51
168
|
languageFor(options.fileName),
|
|
52
169
|
keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, indentWithTab]),
|
|
53
170
|
EditorView.updateListener.of((update) => {
|
package/src/react/styles.css
CHANGED
|
@@ -2,9 +2,34 @@
|
|
|
2
2
|
* docs-kit demo cards. Plain CSS on custom properties: sites restyle by
|
|
3
3
|
* overriding the --dk-* variables (light values on :root, dark ones under
|
|
4
4
|
* [data-theme='dark']), or any .dk-* rule.
|
|
5
|
+
*
|
|
6
|
+
* The code editor reads --dk-editor-* variables (README → Theming). Only the
|
|
7
|
+
* syntax colors have defaults here; every other --dk-editor-* variable falls
|
|
8
|
+
* back to a card variable:
|
|
9
|
+
* --dk-editor-bg --dk-code-bg
|
|
10
|
+
* --dk-editor-fg --dk-fg
|
|
11
|
+
* --dk-editor-font-family --dk-font-mono
|
|
12
|
+
* --dk-editor-font-size --dk-code-font-size
|
|
13
|
+
* --dk-editor-line-height --dk-code-line-height
|
|
14
|
+
* --dk-editor-cursor --dk-editor-fg
|
|
15
|
+
* --dk-editor-selection-bg (set below)
|
|
16
|
+
* --dk-editor-active-line-bg --dk-accent-soft
|
|
17
|
+
* --dk-editor-gutter-bg --dk-editor-bg
|
|
18
|
+
* --dk-editor-gutter-fg --dk-line-number
|
|
19
|
+
* --dk-editor-gutter-border transparent
|
|
20
|
+
* --dk-editor-active-line-gutter-bg / -fg active line bg / gutter fg
|
|
21
|
+
* --dk-editor-selection-match-bg --dk-accent-soft
|
|
22
|
+
* --dk-editor-bracket-match-bg / -outline --dk-accent-soft / --dk-accent
|
|
23
|
+
* --dk-editor-search-match-bg / -outline --dk-highlight-bg / -border
|
|
24
|
+
* --dk-editor-search-match-selected-bg --dk-accent-soft
|
|
25
|
+
* --dk-editor-tooltip-bg / -fg --dk-editor-panel-bg / -fg
|
|
26
|
+
* --dk-editor-tooltip-selected-bg / -fg --dk-accent-soft / -fg
|
|
27
|
+
* --dk-editor-panel-bg / -fg --dk-surface / -fg (search panel)
|
|
28
|
+
* --dk-editor-border --dk-border
|
|
5
29
|
*/
|
|
6
30
|
:root {
|
|
7
31
|
--dk-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
32
|
+
--dk-font-sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
8
33
|
--dk-radius: 12px;
|
|
9
34
|
--dk-border: rgb(0 0 0 / 0.12);
|
|
10
35
|
--dk-surface: #ffffff;
|
|
@@ -18,21 +43,29 @@
|
|
|
18
43
|
--dk-accent-soft: rgb(9 105 218 / 0.1);
|
|
19
44
|
--dk-highlight-bg: rgb(9 105 218 / 0.1);
|
|
20
45
|
--dk-highlight-border: #0969da;
|
|
46
|
+
/* `#highlight label` pills, line numbers */
|
|
47
|
+
--dk-label-bg: rgb(9 105 218 / 0.12);
|
|
48
|
+
--dk-label-fg: #0550ae;
|
|
49
|
+
--dk-line-number: #818b98;
|
|
21
50
|
--dk-error: #cf222e;
|
|
22
51
|
--dk-ok: #1a7f37;
|
|
23
52
|
--dk-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
|
|
24
53
|
--dk-code-max-height: 560px;
|
|
25
|
-
|
|
26
|
-
--dk-
|
|
27
|
-
|
|
28
|
-
--dk-
|
|
29
|
-
--dk-
|
|
30
|
-
--dk-
|
|
31
|
-
--dk-
|
|
32
|
-
--dk-
|
|
33
|
-
--dk-
|
|
34
|
-
--dk-
|
|
35
|
-
--dk-
|
|
54
|
+
--dk-code-font-size: 13.5px;
|
|
55
|
+
--dk-code-line-height: 1.6;
|
|
56
|
+
/* editor syntax colors (github-light, like the static code) */
|
|
57
|
+
--dk-editor-keyword: #cf222e;
|
|
58
|
+
--dk-editor-constant: #0550ae;
|
|
59
|
+
--dk-editor-string: #0a3069;
|
|
60
|
+
--dk-editor-number: #0550ae;
|
|
61
|
+
--dk-editor-comment: #6e7781;
|
|
62
|
+
--dk-editor-type: #953800;
|
|
63
|
+
--dk-editor-function: #8250df;
|
|
64
|
+
--dk-editor-property: #0550ae;
|
|
65
|
+
--dk-editor-tag: #116329;
|
|
66
|
+
--dk-editor-attribute: #0550ae;
|
|
67
|
+
--dk-editor-operator: #cf222e;
|
|
68
|
+
--dk-editor-selection-bg: rgb(9 105 218 / 0.2);
|
|
36
69
|
}
|
|
37
70
|
|
|
38
71
|
[data-theme='dark'] {
|
|
@@ -48,30 +81,37 @@
|
|
|
48
81
|
--dk-accent-soft: rgb(88 166 255 / 0.14);
|
|
49
82
|
--dk-highlight-bg: rgb(122 162 247 / 0.14);
|
|
50
83
|
--dk-highlight-border: #7aa2f7;
|
|
84
|
+
--dk-label-bg: rgb(122 162 247 / 0.28);
|
|
85
|
+
--dk-label-fg: #e3eaff;
|
|
86
|
+
--dk-line-number: #6e7681;
|
|
51
87
|
--dk-error: #ff7b72;
|
|
52
88
|
--dk-ok: #3fb950;
|
|
53
|
-
|
|
54
|
-
--dk-
|
|
55
|
-
--dk-
|
|
56
|
-
--dk-
|
|
57
|
-
--dk-
|
|
58
|
-
--dk-
|
|
59
|
-
--dk-
|
|
60
|
-
--dk-
|
|
61
|
-
--dk-
|
|
62
|
-
--dk-
|
|
89
|
+
/* editor syntax colors (tokyo-night, like the static code) */
|
|
90
|
+
--dk-editor-keyword: #bb9af7;
|
|
91
|
+
--dk-editor-constant: #ff9e64;
|
|
92
|
+
--dk-editor-string: #9ece6a;
|
|
93
|
+
--dk-editor-number: #ff9e64;
|
|
94
|
+
--dk-editor-comment: #565f89;
|
|
95
|
+
--dk-editor-type: #2ac3de;
|
|
96
|
+
--dk-editor-function: #7aa2f7;
|
|
97
|
+
--dk-editor-property: #73daca;
|
|
98
|
+
--dk-editor-tag: #f7768e;
|
|
99
|
+
--dk-editor-attribute: #e0af68;
|
|
100
|
+
--dk-editor-operator: #89ddff;
|
|
101
|
+
--dk-editor-punctuation: #9abdf5;
|
|
102
|
+
--dk-editor-selection-bg: rgb(122 162 247 / 0.25);
|
|
63
103
|
}
|
|
64
104
|
|
|
65
|
-
/* shiki dual themes (defaultColor: false)
|
|
105
|
+
/* shiki dual themes (defaultColor: false). Only the text color: the code
|
|
106
|
+
background is --dk-code-bg, and a background on the token spans would paint
|
|
107
|
+
boxes over highlighted lines. */
|
|
66
108
|
.dk-demo .shiki,
|
|
67
109
|
.dk-demo .shiki span {
|
|
68
110
|
color: var(--shiki-light);
|
|
69
|
-
background-color: var(--shiki-light-bg);
|
|
70
111
|
}
|
|
71
112
|
[data-theme='dark'] .dk-demo .shiki,
|
|
72
113
|
[data-theme='dark'] .dk-demo .shiki span {
|
|
73
114
|
color: var(--shiki-dark);
|
|
74
|
-
background-color: var(--shiki-dark-bg);
|
|
75
115
|
}
|
|
76
116
|
|
|
77
117
|
.dk-demo {
|
|
@@ -274,8 +314,8 @@
|
|
|
274
314
|
border-radius: 0;
|
|
275
315
|
overflow: visible;
|
|
276
316
|
font-family: var(--dk-font-mono);
|
|
277
|
-
font-size:
|
|
278
|
-
line-height:
|
|
317
|
+
font-size: var(--dk-code-font-size);
|
|
318
|
+
line-height: var(--dk-code-line-height);
|
|
279
319
|
tab-size: 2;
|
|
280
320
|
background-color: var(--dk-code-bg) !important;
|
|
281
321
|
}
|
|
@@ -296,13 +336,28 @@
|
|
|
296
336
|
display: flex;
|
|
297
337
|
gap: 16px;
|
|
298
338
|
}
|
|
339
|
+
/* `#highlight label`: a pill at the end of the line, left out of text selections */
|
|
299
340
|
.dk-demo pre.shiki .line-label {
|
|
341
|
+
align-self: center;
|
|
300
342
|
margin-left: auto;
|
|
301
|
-
padding
|
|
343
|
+
padding: 0 8px;
|
|
344
|
+
border-radius: 999px;
|
|
345
|
+
background: var(--dk-label-bg);
|
|
346
|
+
color: var(--dk-label-fg);
|
|
347
|
+
font-family: var(--dk-font-sans);
|
|
302
348
|
font-size: 12px;
|
|
303
|
-
font-
|
|
304
|
-
|
|
349
|
+
font-weight: 500;
|
|
350
|
+
line-height: 1.6;
|
|
305
351
|
white-space: nowrap;
|
|
352
|
+
user-select: none;
|
|
353
|
+
}
|
|
354
|
+
/* a label on a line of its own (`// #highlight label` above the code) */
|
|
355
|
+
.dk-demo pre.shiki .line.label-only {
|
|
356
|
+
gap: 0;
|
|
357
|
+
user-select: none;
|
|
358
|
+
}
|
|
359
|
+
.dk-demo pre.shiki .line.label-only .line-label {
|
|
360
|
+
margin-left: 0;
|
|
306
361
|
}
|
|
307
362
|
.dk-demo pre.shiki.has-line-numbers .line::before {
|
|
308
363
|
content: attr(data-line);
|
|
@@ -310,7 +365,7 @@
|
|
|
310
365
|
width: 2.5em;
|
|
311
366
|
margin-right: 16px;
|
|
312
367
|
text-align: right;
|
|
313
|
-
color: var(--dk-
|
|
368
|
+
color: var(--dk-line-number);
|
|
314
369
|
user-select: none;
|
|
315
370
|
}
|
|
316
371
|
.dk-demo .dk-file-link {
|
|
@@ -370,87 +425,10 @@
|
|
|
370
425
|
border-bottom: 1px solid var(--dk-border);
|
|
371
426
|
}
|
|
372
427
|
}
|
|
428
|
+
/* the editor's colors and font: --dk-editor-* (editor.ts) */
|
|
373
429
|
.dk-demo-editor {
|
|
374
430
|
height: 100%;
|
|
375
|
-
background: var(--dk-code-bg);
|
|
376
|
-
}
|
|
377
|
-
.dk-demo-editor .cm-editor {
|
|
378
|
-
height: 100%;
|
|
379
|
-
font-size: 13.5px;
|
|
380
|
-
background: var(--dk-code-bg);
|
|
381
|
-
color: var(--dk-fg);
|
|
382
|
-
}
|
|
383
|
-
.dk-demo-editor .cm-editor.cm-focused {
|
|
384
|
-
outline: none;
|
|
385
|
-
}
|
|
386
|
-
.dk-demo-editor .cm-scroller {
|
|
387
|
-
font-family: var(--dk-font-mono);
|
|
388
|
-
line-height: 1.6;
|
|
389
|
-
}
|
|
390
|
-
.dk-demo-editor .cm-gutters {
|
|
391
|
-
border: 0;
|
|
392
|
-
background: var(--dk-code-bg);
|
|
393
|
-
color: var(--dk-faint);
|
|
394
|
-
}
|
|
395
|
-
.dk-demo-editor .cm-activeLine,
|
|
396
|
-
.dk-demo-editor .cm-activeLineGutter {
|
|
397
|
-
background: var(--dk-accent-soft);
|
|
398
|
-
}
|
|
399
|
-
.dk-demo-editor .cm-content {
|
|
400
|
-
caret-color: var(--dk-fg);
|
|
401
|
-
}
|
|
402
|
-
.dk-demo-editor .cm-cursor {
|
|
403
|
-
border-left-color: var(--dk-fg);
|
|
404
|
-
}
|
|
405
|
-
.dk-demo-editor .cm-selectionBackground,
|
|
406
|
-
.dk-demo-editor .cm-focused .cm-selectionBackground,
|
|
407
|
-
.dk-demo-editor ::selection {
|
|
408
|
-
background: var(--dk-selection) !important;
|
|
409
|
-
}
|
|
410
|
-
.dk-demo-editor .cm-matchingBracket {
|
|
411
|
-
background: var(--dk-accent-soft);
|
|
412
|
-
outline: 1px solid var(--dk-accent);
|
|
413
|
-
}
|
|
414
|
-
.dk-demo-editor .cm-tooltip {
|
|
415
|
-
border: 1px solid var(--dk-border);
|
|
416
|
-
background: var(--dk-surface);
|
|
417
|
-
color: var(--dk-fg);
|
|
418
|
-
}
|
|
419
|
-
.dk-demo-editor .tok-keyword,
|
|
420
|
-
.dk-demo-editor .tok-operatorKeyword,
|
|
421
|
-
.dk-demo-editor .tok-modifier {
|
|
422
|
-
color: var(--dk-tok-keyword);
|
|
423
|
-
}
|
|
424
|
-
.dk-demo-editor .tok-string,
|
|
425
|
-
.dk-demo-editor .tok-string2 {
|
|
426
|
-
color: var(--dk-tok-string);
|
|
427
|
-
}
|
|
428
|
-
.dk-demo-editor .tok-number,
|
|
429
|
-
.dk-demo-editor .tok-bool,
|
|
430
|
-
.dk-demo-editor .tok-atom {
|
|
431
|
-
color: var(--dk-tok-number);
|
|
432
|
-
}
|
|
433
|
-
.dk-demo-editor .tok-comment {
|
|
434
|
-
color: var(--dk-tok-comment);
|
|
435
|
-
font-style: italic;
|
|
436
|
-
}
|
|
437
|
-
.dk-demo-editor .tok-typeName,
|
|
438
|
-
.dk-demo-editor .tok-className,
|
|
439
|
-
.dk-demo-editor .tok-namespace {
|
|
440
|
-
color: var(--dk-tok-type);
|
|
441
|
-
}
|
|
442
|
-
.dk-demo-editor .tok-variableName.tok-definition,
|
|
443
|
-
.dk-demo-editor .tok-function {
|
|
444
|
-
color: var(--dk-tok-function);
|
|
445
|
-
}
|
|
446
|
-
.dk-demo-editor .tok-propertyName {
|
|
447
|
-
color: var(--dk-tok-property);
|
|
448
|
-
}
|
|
449
|
-
.dk-demo-editor .tok-tagName {
|
|
450
|
-
color: var(--dk-tok-tag);
|
|
451
|
-
}
|
|
452
|
-
.dk-demo-editor .tok-attributeName {
|
|
453
|
-
color: var(--dk-tok-attribute);
|
|
431
|
+
background: var(--dk-editor-bg, var(--dk-code-bg));
|
|
454
432
|
}
|
|
455
433
|
.dk-demo-editor-error {
|
|
456
434
|
margin: 0;
|