@thedatagrid/docs-kit 0.1.0 → 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/CHANGELOG.md +13 -0
- package/README.md +101 -0
- package/dist/demos/cli.js +35 -1
- package/dist/demos/cli.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/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/editor/install.ts +85 -0
- package/src/react/editor.ts +122 -5
- package/src/react/styles.css +87 -109
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @thedatagrid/docs-kit
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3852bc8: Editor theming, snippet labels, and an editor extension for fence links.
|
|
8
|
+
|
|
9
|
+
- The code editor takes every color and its font from `--dk-editor-*` CSS variables (text, background, cursor, selection, active line, gutter, matches, tooltips, search panel, and one variable per syntax token group). Unset variables fall back to the card variables. The colors come from a CodeMirror theme extension, so they win over CodeMirror's own light theme.
|
|
10
|
+
**Breaking:** `--dk-tok-*` is now `--dk-editor-*` (e.g. `--dk-tok-keyword` → `--dk-editor-keyword`), `--dk-selection` is now `--dk-editor-selection-bg`, and the editor no longer adds `tok-*` classes.
|
|
11
|
+
- `#highlight label` labels render as pills (`--dk-label-bg`, `--dk-label-fg`, `--dk-font-sans`) and stay out of text selections. Rows that hold only a label get their own layout.
|
|
12
|
+
- Token spans no longer paint the shiki theme background, which drew boxes over highlighted lines.
|
|
13
|
+
- New `--dk-line-number`, `--dk-code-font-size` and `--dk-code-line-height`.
|
|
14
|
+
- `docs-kit editor install [code] [cursor]` installs the **docs-kit links** extension into VS Code and/or Cursor. In a docs page, Cmd/Ctrl+click a fence's `file="…"` to open that file, at its `region="…"` when one is set. `docs-kit editor package` only builds the `.vsix`.
|
|
15
|
+
|
|
3
16
|
## 0.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -116,6 +116,107 @@ prebuilt demo. Fork sends the edited files.
|
|
|
116
116
|
|
|
117
117
|
Serve `*.wasm` with a long cache lifetime: the file name is content-hashed.
|
|
118
118
|
|
|
119
|
+
## Theming
|
|
120
|
+
|
|
121
|
+
The cards are styled through `--dk-*` CSS custom properties (the list is at the
|
|
122
|
+
top of `styles.css`). Set them in your own CSS, after importing
|
|
123
|
+
`@thedatagrid/docs-kit/react/styles.css`. Use `:root` for the light values and
|
|
124
|
+
`[data-theme='dark']` for the dark ones. Your selector can differ: these are
|
|
125
|
+
ordinary CSS variables.
|
|
126
|
+
|
|
127
|
+
Code blocks use these:
|
|
128
|
+
|
|
129
|
+
- `--dk-code-bg`, `--dk-code-font-size`, `--dk-code-line-height`: also used by the editor;
|
|
130
|
+
- `--dk-highlight-bg`, `--dk-highlight-border`: `#highlight`ed lines;
|
|
131
|
+
- `--dk-label-bg`, `--dk-label-fg`, `--dk-font-sans`: the `#highlight label` pills, which
|
|
132
|
+
stay out of the text when someone selects and copies a snippet;
|
|
133
|
+
- `--dk-line-number`: line numbers, and the editor's gutter.
|
|
134
|
+
|
|
135
|
+
The code editor has its own `--dk-editor-*` variables. When a site leaves one
|
|
136
|
+
unset, it falls back to the matching card variable, so out of the box the
|
|
137
|
+
editor looks like the static code:
|
|
138
|
+
|
|
139
|
+
```css
|
|
140
|
+
[data-theme='dark'] {
|
|
141
|
+
/* text, background, font */
|
|
142
|
+
--dk-editor-bg: #0d1117;
|
|
143
|
+
--dk-editor-fg: #e6edf3;
|
|
144
|
+
--dk-editor-font-family: 'JetBrains Mono', monospace;
|
|
145
|
+
--dk-editor-font-size: 14px;
|
|
146
|
+
--dk-editor-line-height: 1.7;
|
|
147
|
+
|
|
148
|
+
/* editing */
|
|
149
|
+
--dk-editor-cursor: #58a6ff;
|
|
150
|
+
--dk-editor-selection-bg: rgb(56 139 253 / 0.3);
|
|
151
|
+
--dk-editor-active-line-bg: rgb(255 255 255 / 0.04);
|
|
152
|
+
--dk-editor-selection-match-bg: rgb(255 255 255 / 0.08);
|
|
153
|
+
--dk-editor-bracket-match-bg: transparent;
|
|
154
|
+
--dk-editor-bracket-match-outline: #58a6ff;
|
|
155
|
+
--dk-editor-search-match-bg: rgb(187 128 9 / 0.3);
|
|
156
|
+
|
|
157
|
+
/* line numbers */
|
|
158
|
+
--dk-editor-gutter-bg: #0d1117;
|
|
159
|
+
--dk-editor-gutter-fg: #6e7681;
|
|
160
|
+
--dk-editor-gutter-border: #30363d;
|
|
161
|
+
--dk-editor-active-line-gutter-fg: #e6edf3;
|
|
162
|
+
|
|
163
|
+
/* syntax */
|
|
164
|
+
--dk-editor-keyword: #ff7b72;
|
|
165
|
+
--dk-editor-constant: #79c0ff; /* true, null, this */
|
|
166
|
+
--dk-editor-number: #79c0ff;
|
|
167
|
+
--dk-editor-string: #a5d6ff;
|
|
168
|
+
--dk-editor-regexp: #7ee787;
|
|
169
|
+
--dk-editor-comment: #8b949e;
|
|
170
|
+
--dk-editor-comment-font-style: normal;
|
|
171
|
+
--dk-editor-type: #ffa657;
|
|
172
|
+
--dk-editor-function: #d2a8ff;
|
|
173
|
+
--dk-editor-definition: #d2a8ff; /* declared names */
|
|
174
|
+
--dk-editor-variable: #e6edf3;
|
|
175
|
+
--dk-editor-property: #79c0ff;
|
|
176
|
+
--dk-editor-tag: #7ee787; /* JSX tags */
|
|
177
|
+
--dk-editor-attribute: #79c0ff; /* JSX attributes */
|
|
178
|
+
--dk-editor-operator: #ff7b72;
|
|
179
|
+
--dk-editor-punctuation: #e6edf3;
|
|
180
|
+
--dk-editor-meta: #8b949e;
|
|
181
|
+
--dk-editor-invalid: #f85149;
|
|
182
|
+
|
|
183
|
+
/* autocomplete and the search panel (Ctrl/Cmd-F) */
|
|
184
|
+
--dk-editor-tooltip-bg: #161b22;
|
|
185
|
+
--dk-editor-tooltip-fg: #e6edf3;
|
|
186
|
+
--dk-editor-tooltip-selected-bg: rgb(56 139 253 / 0.3);
|
|
187
|
+
--dk-editor-panel-bg: #161b22;
|
|
188
|
+
--dk-editor-border: #30363d;
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The static code blocks are colored by the shiki themes
|
|
193
|
+
(`github-light` / `tokyo-night` by default, `themes` option). The editor's
|
|
194
|
+
default syntax colors match them; when you change one, change the other.
|
|
195
|
+
`--dk-code-bg`, `--dk-code-font-size` and `--dk-code-line-height` apply to both.
|
|
196
|
+
|
|
197
|
+
The editor's colors are set through a CodeMirror theme extension, so they win
|
|
198
|
+
over CodeMirror's built-in light theme without `!important`. A site stylesheet
|
|
199
|
+
with unscoped `!important` rules on `.cm-*` classes, such as
|
|
200
|
+
`.cm-gutters { … !important }` written for another editor, still overrides
|
|
201
|
+
them. Scope those rules to their own editor (e.g. `.sp-wrapper .cm-gutters`).
|
|
202
|
+
|
|
203
|
+
## Editor extension (VS Code, Cursor)
|
|
204
|
+
|
|
205
|
+
The package includes a small extension, **docs-kit links**. In a docs page, Cmd/Ctrl+click
|
|
206
|
+
the `file="…"` of a fence to open that file. When the fence has `region="name"`, the file
|
|
207
|
+
opens at its `#region name` line. Paths resolve as in `remarkDemoFences`: from the page's
|
|
208
|
+
folder, or from the content root for `/…` paths. The content root is `docsKit.contentDir`,
|
|
209
|
+
or else `docsRoot.source`, in the site's `package.json`.
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
npx docs-kit editor install # every VS Code / Cursor CLI found
|
|
213
|
+
npx docs-kit editor install cursor # or only some: code, cursor
|
|
214
|
+
npx docs-kit editor package --out docs-kit-links.vsix # just the .vsix
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
It packages the extension with `@vscode/vsce`, fetched through `npx` on first use, and
|
|
218
|
+
versions it like the installed docs-kit. Run it again after upgrading docs-kit.
|
|
219
|
+
|
|
119
220
|
## Local development across repos
|
|
120
221
|
|
|
121
222
|
Check `docs-kit` out next to the consuming repo, and run the site with
|
package/dist/demos/cli.js
CHANGED
|
@@ -13,19 +13,53 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
13
13
|
* Loads `docs-kit.config.{mjs,js,ts}` from the current folder (or `--config`)
|
|
14
14
|
* and prebuilds the demos. The config's default export is a `DocsKitConfig`
|
|
15
15
|
* or a (sync/async) function returning one.
|
|
16
|
+
*
|
|
17
|
+
* `docs-kit editor install [code] [cursor]` installs the docs-kit links
|
|
18
|
+
* extension (cmd+click `file="…"` in fences) into VS Code and/or Cursor;
|
|
19
|
+
* `docs-kit editor package [--out <file>]` only builds its .vsix.
|
|
16
20
|
*/
|
|
17
21
|
import fs from 'node:fs';
|
|
18
22
|
import path from 'node:path';
|
|
19
23
|
import { pathToFileURL } from 'node:url';
|
|
24
|
+
import { installExtension, packageExtension } from "../editor/install.js";
|
|
20
25
|
import { buildDemos } from "./build.js";
|
|
21
26
|
const CONFIG_NAMES = ['docs-kit.config.mjs', 'docs-kit.config.js', 'docs-kit.config.ts'];
|
|
22
27
|
function usage() {
|
|
23
|
-
console.error(
|
|
28
|
+
console.error([
|
|
29
|
+
'usage: docs-kit demos [build] [--watch] [--config <file>]',
|
|
30
|
+
' docs-kit editor install [code] [cursor]',
|
|
31
|
+
' docs-kit editor package [--out <file>]',
|
|
32
|
+
].join('\n'));
|
|
24
33
|
process.exit(1);
|
|
25
34
|
}
|
|
35
|
+
function editorCommand(args) {
|
|
36
|
+
const sub = args.shift();
|
|
37
|
+
if (sub === 'install') {
|
|
38
|
+
const only = args.map((arg) => (arg === 'code' || arg === 'cursor' ? arg : usage()));
|
|
39
|
+
const { installed } = installExtension(only);
|
|
40
|
+
if (only.length && installed.length < only.length)
|
|
41
|
+
process.exit(1);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (sub === 'package') {
|
|
45
|
+
let out;
|
|
46
|
+
while (args.length) {
|
|
47
|
+
const arg = args.shift();
|
|
48
|
+
if (arg === '--out' || arg === '-o')
|
|
49
|
+
out = args.shift() ?? usage();
|
|
50
|
+
else
|
|
51
|
+
usage();
|
|
52
|
+
}
|
|
53
|
+
console.log(packageExtension(out));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
usage();
|
|
57
|
+
}
|
|
26
58
|
async function main(argv) {
|
|
27
59
|
const args = [...argv];
|
|
28
60
|
const command = args.shift();
|
|
61
|
+
if (command === 'editor')
|
|
62
|
+
return editorCommand(args);
|
|
29
63
|
if (command !== 'demos')
|
|
30
64
|
usage();
|
|
31
65
|
if (args[0] === 'build')
|
package/dist/demos/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/demos/cli.ts"],"names":[],"mappings":";;;;;;;;;AACA
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/demos/cli.ts"],"names":[],"mappings":";;;;;;;;;AACA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,YAAY,GAAG,CAAC,qBAAqB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAEzF,SAAS,KAAK;IACZ,OAAO,CAAC,KAAK,CACX;QACE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,kCAAC,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,EAAC,CAA0B,CAAC;IACvF,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,MAAM,MAAM,GAAG,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAkB,CAAC;IAE/F,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACxF,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE;YACtB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC1C,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const EXTENSION_DIR: string;
|
|
2
|
+
export type Editor = 'code' | 'cursor';
|
|
3
|
+
/** The CLI of each editor that is installed (`code`, `cursor`). */
|
|
4
|
+
export declare function findEditors(only?: Editor[]): {
|
|
5
|
+
editor: Editor;
|
|
6
|
+
bin: string;
|
|
7
|
+
}[];
|
|
8
|
+
/** Packages the extension, versioned like this docs-kit, into `outFile` (default: a temp file). */
|
|
9
|
+
export declare function packageExtension(outFile?: string): string;
|
|
10
|
+
/** Packages the extension and installs it into each editor found (or the ones in `only`). */
|
|
11
|
+
export declare function installExtension(only?: Editor[], log?: (message: string) => void): {
|
|
12
|
+
vsix: string;
|
|
13
|
+
installed: Editor[];
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/editor/install.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,QAA6C,CAAC;AAIxE,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAYvC,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,CAO9E;AAED,mGAAmG;AACnG,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAoBzD;AAED,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAkB;;eAQ1D,MAAM,EAAE;EAa3C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
/** Same folder from `src/editor/` (local mode) and `dist/editor/` (the package). */
|
|
12
|
+
const packageRoot = fileURLToPath(new URL('../../', import.meta.url));
|
|
13
|
+
export const EXTENSION_DIR = path.join(packageRoot, 'editor-extension');
|
|
14
|
+
const VSCE = '@vscode/vsce@4.1.0';
|
|
15
|
+
const FILES = ['package.json', 'extension.js', 'links.js', 'README.md'];
|
|
16
|
+
const APP_BINARIES = {
|
|
17
|
+
code: ['/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'],
|
|
18
|
+
cursor: ['/Applications/Cursor.app/Contents/Resources/app/bin/cursor'],
|
|
19
|
+
};
|
|
20
|
+
function onPath(command) {
|
|
21
|
+
const result = spawnSync(process.platform === 'win32' ? 'where' : 'which', [command], { encoding: 'utf8' });
|
|
22
|
+
return result.status === 0 ? result.stdout.split(/\r?\n/)[0].trim() || null : null;
|
|
23
|
+
}
|
|
24
|
+
/** The CLI of each editor that is installed (`code`, `cursor`). */
|
|
25
|
+
export function findEditors(only) {
|
|
26
|
+
return Object.keys(APP_BINARIES)
|
|
27
|
+
.filter((editor) => !only?.length || only.includes(editor))
|
|
28
|
+
.flatMap((editor) => {
|
|
29
|
+
const bin = onPath(editor) ?? APP_BINARIES[editor].find((file) => fs.existsSync(file));
|
|
30
|
+
return bin ? [{ editor, bin }] : [];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Packages the extension, versioned like this docs-kit, into `outFile` (default: a temp file). */
|
|
34
|
+
export function packageExtension(outFile) {
|
|
35
|
+
const { version } = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
36
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'docs-kit-editor-'));
|
|
37
|
+
for (const file of FILES)
|
|
38
|
+
fs.copyFileSync(path.join(EXTENSION_DIR, file), path.join(work, file));
|
|
39
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(work, 'package.json'), 'utf8'));
|
|
40
|
+
manifest.version = version;
|
|
41
|
+
fs.writeFileSync(path.join(work, 'package.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
42
|
+
const out = path.resolve(outFile ?? path.join(work, `docs-kit-links-${version}.vsix`));
|
|
43
|
+
const result = spawnSync('npx', ['--yes', VSCE, 'package', '--no-dependencies', '--skip-license', '--allow-missing-repository', '-o', out], { cwd: work, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', shell: process.platform === 'win32' });
|
|
44
|
+
if (result.status !== 0 || !fs.existsSync(out)) {
|
|
45
|
+
throw new Error(`[docs-kit] packaging the editor extension failed:\n${result.stdout}${result.stderr}`);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** Packages the extension and installs it into each editor found (or the ones in `only`). */
|
|
50
|
+
export function installExtension(only, log = console.log) {
|
|
51
|
+
const editors = findEditors(only);
|
|
52
|
+
const vsix = packageExtension();
|
|
53
|
+
if (!editors.length) {
|
|
54
|
+
log(`[docs-kit] no VS Code or Cursor CLI found. Install ${vsix} from the editor ` +
|
|
55
|
+
'(Extensions → … → Install from VSIX).');
|
|
56
|
+
return { vsix, installed: [] };
|
|
57
|
+
}
|
|
58
|
+
const installed = [];
|
|
59
|
+
for (const { editor, bin } of editors) {
|
|
60
|
+
const result = spawnSync(bin, ['--install-extension', vsix, '--force'], { encoding: 'utf8' });
|
|
61
|
+
if (result.status === 0) {
|
|
62
|
+
installed.push(editor);
|
|
63
|
+
log(`[docs-kit] installed the docs-kit links extension in ${editor}. Reload its windows to use it.`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
log(`[docs-kit] installing in ${editor} failed:\n${result.stdout}${result.stderr}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { vsix, installed };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/editor/install.ts"],"names":[],"mappings":"A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,GAAa,EAAE,CAAC;IAC/B,KAAK,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,OAAO,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9F,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,GAAG,CAAC,wDAAwD,MAAM,iCAAiC,CAAC,CAAC;QACvG,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,4BAA4B,MAAM,aAAa,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/react/editor.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
2
|
+
import { type Extension } from '@codemirror/state';
|
|
3
|
+
/**
|
|
4
|
+
* Editor chrome. Rules in an `EditorView.theme` come after CodeMirror's base
|
|
5
|
+
* theme, so they win over its light defaults without `!important`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const editorTheme: Extension;
|
|
8
|
+
/** Syntax colors: one variable per token group (README → Theming). */
|
|
9
|
+
export declare const editorHighlightStyle: HighlightStyle;
|
|
1
10
|
export declare function createCodeEditor(parent: HTMLElement, options: {
|
|
2
11
|
doc: string;
|
|
3
12
|
fileName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/react/editor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/react/editor.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,cAAc,EAIf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAqBhE;;;GAGG;AACH,eAAO,MAAM,WAAW,WA8DtB,CAAC;AAEH,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,gBAyB/B,CAAC;AASH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE;;EA8B9E"}
|
package/dist/react/editor.js
CHANGED
|
@@ -1,17 +1,122 @@
|
|
|
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 { bracketMatching, indentOnInput, indentUnit, syntaxHighlighting } from '@codemirror/language';
|
|
14
|
+
import { bracketMatching, HighlightStyle, indentOnInput, indentUnit, syntaxHighlighting, } from '@codemirror/language';
|
|
11
15
|
import { highlightSelectionMatches, searchKeymap } from '@codemirror/search';
|
|
12
16
|
import { EditorState } from '@codemirror/state';
|
|
13
17
|
import { drawSelection, EditorView, highlightActiveLine, highlightActiveLineGutter, keymap, lineNumbers, } from '@codemirror/view';
|
|
14
|
-
import {
|
|
18
|
+
import { tags as t } from '@lezer/highlight';
|
|
19
|
+
/** `var(--dk-editor-<name>, <fallback>)` */
|
|
20
|
+
const v = (name, fallback) => `var(--dk-editor-${name}, ${fallback})`;
|
|
21
|
+
const fg = v('fg', 'var(--dk-fg)');
|
|
22
|
+
const bg = v('bg', 'var(--dk-code-bg)');
|
|
23
|
+
const activeLineBg = v('active-line-bg', 'var(--dk-accent-soft)');
|
|
24
|
+
const gutterFg = v('gutter-fg', 'var(--dk-line-number, var(--dk-faint))');
|
|
25
|
+
const border = v('border', 'var(--dk-border)');
|
|
26
|
+
const surface = v('panel-bg', 'var(--dk-surface)');
|
|
27
|
+
/**
|
|
28
|
+
* Editor chrome. Rules in an `EditorView.theme` come after CodeMirror's base
|
|
29
|
+
* theme, so they win over its light defaults without `!important`.
|
|
30
|
+
*/
|
|
31
|
+
export const editorTheme = EditorView.theme({
|
|
32
|
+
'&': {
|
|
33
|
+
height: '100%',
|
|
34
|
+
color: fg,
|
|
35
|
+
backgroundColor: bg,
|
|
36
|
+
fontSize: v('font-size', 'var(--dk-code-font-size, 13.5px)'),
|
|
37
|
+
},
|
|
38
|
+
'&.cm-focused': { outline: 'none' },
|
|
39
|
+
'.cm-scroller': {
|
|
40
|
+
fontFamily: v('font-family', 'var(--dk-font-mono)'),
|
|
41
|
+
lineHeight: v('line-height', 'var(--dk-code-line-height, 1.6)'),
|
|
42
|
+
},
|
|
43
|
+
'.cm-content': { caretColor: v('cursor', fg) },
|
|
44
|
+
'.cm-cursor, .cm-dropCursor': { borderLeftColor: v('cursor', fg) },
|
|
45
|
+
'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': { backgroundColor: v('selection-bg', 'var(--dk-accent-soft)') },
|
|
46
|
+
'.cm-activeLine': { backgroundColor: activeLineBg },
|
|
47
|
+
'.cm-gutters': {
|
|
48
|
+
backgroundColor: v('gutter-bg', bg),
|
|
49
|
+
color: gutterFg,
|
|
50
|
+
border: 'none',
|
|
51
|
+
borderRight: `1px solid ${v('gutter-border', 'transparent')}`,
|
|
52
|
+
},
|
|
53
|
+
'.cm-activeLineGutter': {
|
|
54
|
+
backgroundColor: v('active-line-gutter-bg', activeLineBg),
|
|
55
|
+
color: v('active-line-gutter-fg', gutterFg),
|
|
56
|
+
},
|
|
57
|
+
'.cm-selectionMatch': { backgroundColor: v('selection-match-bg', 'var(--dk-accent-soft)') },
|
|
58
|
+
'&.cm-focused .cm-matchingBracket': {
|
|
59
|
+
backgroundColor: v('bracket-match-bg', 'var(--dk-accent-soft)'),
|
|
60
|
+
outline: `1px solid ${v('bracket-match-outline', 'var(--dk-accent)')}`,
|
|
61
|
+
},
|
|
62
|
+
'&.cm-focused .cm-nonmatchingBracket': {
|
|
63
|
+
backgroundColor: 'transparent',
|
|
64
|
+
outline: `1px solid ${v('invalid', 'var(--dk-error)')}`,
|
|
65
|
+
},
|
|
66
|
+
'.cm-searchMatch': {
|
|
67
|
+
backgroundColor: v('search-match-bg', 'var(--dk-highlight-bg)'),
|
|
68
|
+
outline: `1px solid ${v('search-match-outline', 'var(--dk-highlight-border)')}`,
|
|
69
|
+
},
|
|
70
|
+
'.cm-searchMatch.cm-searchMatch-selected': {
|
|
71
|
+
backgroundColor: v('search-match-selected-bg', 'var(--dk-accent-soft)'),
|
|
72
|
+
},
|
|
73
|
+
'.cm-tooltip': {
|
|
74
|
+
border: `1px solid ${border}`,
|
|
75
|
+
backgroundColor: v('tooltip-bg', surface),
|
|
76
|
+
color: v('tooltip-fg', fg),
|
|
77
|
+
},
|
|
78
|
+
'.cm-tooltip-autocomplete > ul > li[aria-selected]': {
|
|
79
|
+
backgroundColor: v('tooltip-selected-bg', 'var(--dk-accent-soft)'),
|
|
80
|
+
color: v('tooltip-selected-fg', fg),
|
|
81
|
+
},
|
|
82
|
+
'.cm-panels': { backgroundColor: surface, color: v('panel-fg', fg) },
|
|
83
|
+
'.cm-panels.cm-panels-top': { borderBottom: `1px solid ${border}` },
|
|
84
|
+
'.cm-panels.cm-panels-bottom': { borderTop: `1px solid ${border}` },
|
|
85
|
+
'.cm-textfield, .cm-button': {
|
|
86
|
+
border: `1px solid ${border}`,
|
|
87
|
+
borderRadius: '4px',
|
|
88
|
+
backgroundColor: bg,
|
|
89
|
+
backgroundImage: 'none',
|
|
90
|
+
color: fg,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
/** Syntax colors: one variable per token group (README → Theming). */
|
|
94
|
+
export const editorHighlightStyle = HighlightStyle.define([
|
|
95
|
+
{ tag: t.keyword, color: v('keyword', 'var(--dk-fg)') },
|
|
96
|
+
{ tag: [t.self, t.null, t.bool, t.atom], color: v('constant', v('keyword', 'var(--dk-fg)')) },
|
|
97
|
+
{ tag: [t.number, t.unit, t.color], color: v('number', 'var(--dk-fg)') },
|
|
98
|
+
{ tag: [t.string, t.special(t.string), t.character], color: v('string', 'var(--dk-fg)') },
|
|
99
|
+
{ tag: [t.regexp, t.escape], color: v('regexp', v('string', 'var(--dk-fg)')) },
|
|
100
|
+
{
|
|
101
|
+
tag: t.comment,
|
|
102
|
+
color: v('comment', 'var(--dk-faint)'),
|
|
103
|
+
fontStyle: v('comment-font-style', 'italic'),
|
|
104
|
+
},
|
|
105
|
+
{ tag: [t.typeName, t.className, t.namespace], color: v('type', 'var(--dk-fg)') },
|
|
106
|
+
{
|
|
107
|
+
tag: [t.function(t.variableName), t.function(t.propertyName)],
|
|
108
|
+
color: v('function', 'var(--dk-fg)'),
|
|
109
|
+
},
|
|
110
|
+
{ tag: t.definition(t.variableName), color: v('definition', v('function', 'var(--dk-fg)')) },
|
|
111
|
+
{ tag: t.variableName, color: v('variable', fg) },
|
|
112
|
+
{ tag: t.propertyName, color: v('property', 'var(--dk-fg)') },
|
|
113
|
+
{ tag: t.tagName, color: v('tag', 'var(--dk-fg)') },
|
|
114
|
+
{ tag: t.attributeName, color: v('attribute', 'var(--dk-fg)') },
|
|
115
|
+
{ tag: t.operator, color: v('operator', fg) },
|
|
116
|
+
{ tag: [t.punctuation, t.bracket, t.separator], color: v('punctuation', fg) },
|
|
117
|
+
{ tag: t.meta, color: v('meta', v('comment', 'var(--dk-faint)')) },
|
|
118
|
+
{ tag: t.invalid, color: v('invalid', 'var(--dk-error)') },
|
|
119
|
+
]);
|
|
15
120
|
function languageFor(fileName) {
|
|
16
121
|
if (/\.css$/.test(fileName))
|
|
17
122
|
return css();
|
|
@@ -36,7 +141,8 @@ export function createCodeEditor(parent, options) {
|
|
|
36
141
|
closeBrackets(),
|
|
37
142
|
autocompletion({ activateOnTyping: false }),
|
|
38
143
|
highlightSelectionMatches(),
|
|
39
|
-
|
|
144
|
+
editorTheme,
|
|
145
|
+
syntaxHighlighting(editorHighlightStyle),
|
|
40
146
|
languageFor(options.fileName),
|
|
41
147
|
keymap.of([...closeBracketsKeymap, ...defaultKeymap, ...searchKeymap, ...historyKeymap, indentWithTab]),
|
|
42
148
|
EditorView.updateListener.of((update) => {
|
package/dist/react/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../../src/react/editor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../../src/react/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAk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