@sckyzo/cosmos-react 0.2.0 → 0.4.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 +261 -0
- package/README.md +1641 -5
- package/calendar.css +4 -0
- package/dist/CodeBlock-CY18_3tZ.d.cts +52 -0
- package/dist/CodeBlock-CY18_3tZ.d.ts +52 -0
- package/dist/code/index.cjs +331 -0
- package/dist/code/index.cjs.map +1 -0
- package/dist/code/index.d.cts +29 -0
- package/dist/code/index.d.ts +29 -0
- package/dist/code/index.js +326 -0
- package/dist/code/index.js.map +1 -0
- package/dist/editor/index.cjs +879 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +100 -0
- package/dist/editor/index.d.ts +100 -0
- package/dist/editor/index.js +872 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/fieldRecipe-Cao5uUIK.d.cts +3 -0
- package/dist/fieldRecipe-Cao5uUIK.d.ts +3 -0
- package/dist/index.cjs +25053 -8751
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5411 -1147
- package/dist/index.d.ts +5411 -1147
- package/dist/index.js +24944 -8735
- package/dist/index.js.map +1 -1
- package/dist/intent-D0bANgYJ.d.cts +12 -0
- package/dist/intent-D0bANgYJ.d.ts +12 -0
- package/dist/map/index.cjs +559 -0
- package/dist/map/index.cjs.map +1 -0
- package/dist/map/index.d.cts +95 -0
- package/dist/map/index.d.ts +95 -0
- package/dist/map/index.js +556 -0
- package/dist/map/index.js.map +1 -0
- package/package.json +105 -17
package/calendar.css
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type CodeBlockProps = {
|
|
5
|
+
code: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Turns `code` into highlighted nodes, rendered inside the block's `<code>`.
|
|
9
|
+
* Without it the code is plain text; `@sckyzo/cosmos-react/code` exports a
|
|
10
|
+
* `CodeBlock` with a Shiki highlighter plugged in, and any other highlighter
|
|
11
|
+
* can be given here. A highlighter that renders its tokens as elements keeps
|
|
12
|
+
* working with `lineNumbers`, `highlightLines`, `diff` and `variant="terminal"`.
|
|
13
|
+
* The copy button always copies the code, not the highlighted nodes.
|
|
14
|
+
*/
|
|
15
|
+
highlight?: (code: string, language?: string) => ReactNode;
|
|
16
|
+
/** Show the copy button (top corner at the end of the line, hover-revealed). Default `true`. */
|
|
17
|
+
showCopy?: boolean;
|
|
18
|
+
/** A line-number gutter. It is not selected and not copied. Default `false`. */
|
|
19
|
+
lineNumbers?: boolean;
|
|
20
|
+
/** Lines to emphasise, 1-based: `[3, '5-7']`. */
|
|
21
|
+
highlightLines?: ReadonlyArray<number | string>;
|
|
22
|
+
/**
|
|
23
|
+
* A header with the file name (and the language), next to the copy button. The file name
|
|
24
|
+
* also names the scrolling region of `maxHeight`.
|
|
25
|
+
*/
|
|
26
|
+
filename?: string;
|
|
27
|
+
/** Wrap long lines instead of scrolling sideways. Default `false`. */
|
|
28
|
+
wrap?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Scroll inside the block past this height (a number is pixels, a string any CSS length). The
|
|
31
|
+
* block then takes the focus (Tab) and scrolls with the arrow keys, so a keyboard user can
|
|
32
|
+
* read it all; it is a labelled region.
|
|
33
|
+
*/
|
|
34
|
+
maxHeight?: number | string;
|
|
35
|
+
/**
|
|
36
|
+
* Show `code` as a diff, written as a unified diff is: the first column of each line is its
|
|
37
|
+
* sign, `+` added, `-` removed, a space unchanged. Added and removed lines are tinted and
|
|
38
|
+
* marked in a gutter with `+` and `−`; the sign column is not part of the copy.
|
|
39
|
+
*/
|
|
40
|
+
diff?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* `terminal` shows a shell session: a line starting with `$ ` is a command (the prompt is drawn
|
|
43
|
+
* apart, a trailing `\` continues it onto the next line), any other line is its output. Only
|
|
44
|
+
* the commands are highlighted (as `bash`) and copied. Default `default`.
|
|
45
|
+
*/
|
|
46
|
+
variant?: 'default' | 'terminal';
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
declare const CodeBlock: ({ code, language, highlight, showCopy, lineNumbers, highlightLines, filename, wrap, maxHeight, diff, variant, className, }: CodeBlockProps) => react.JSX.Element;
|
|
50
|
+
|
|
51
|
+
export { CodeBlock as a };
|
|
52
|
+
export type { CodeBlockProps as C };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type CodeBlockProps = {
|
|
5
|
+
code: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Turns `code` into highlighted nodes, rendered inside the block's `<code>`.
|
|
9
|
+
* Without it the code is plain text; `@sckyzo/cosmos-react/code` exports a
|
|
10
|
+
* `CodeBlock` with a Shiki highlighter plugged in, and any other highlighter
|
|
11
|
+
* can be given here. A highlighter that renders its tokens as elements keeps
|
|
12
|
+
* working with `lineNumbers`, `highlightLines`, `diff` and `variant="terminal"`.
|
|
13
|
+
* The copy button always copies the code, not the highlighted nodes.
|
|
14
|
+
*/
|
|
15
|
+
highlight?: (code: string, language?: string) => ReactNode;
|
|
16
|
+
/** Show the copy button (top corner at the end of the line, hover-revealed). Default `true`. */
|
|
17
|
+
showCopy?: boolean;
|
|
18
|
+
/** A line-number gutter. It is not selected and not copied. Default `false`. */
|
|
19
|
+
lineNumbers?: boolean;
|
|
20
|
+
/** Lines to emphasise, 1-based: `[3, '5-7']`. */
|
|
21
|
+
highlightLines?: ReadonlyArray<number | string>;
|
|
22
|
+
/**
|
|
23
|
+
* A header with the file name (and the language), next to the copy button. The file name
|
|
24
|
+
* also names the scrolling region of `maxHeight`.
|
|
25
|
+
*/
|
|
26
|
+
filename?: string;
|
|
27
|
+
/** Wrap long lines instead of scrolling sideways. Default `false`. */
|
|
28
|
+
wrap?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Scroll inside the block past this height (a number is pixels, a string any CSS length). The
|
|
31
|
+
* block then takes the focus (Tab) and scrolls with the arrow keys, so a keyboard user can
|
|
32
|
+
* read it all; it is a labelled region.
|
|
33
|
+
*/
|
|
34
|
+
maxHeight?: number | string;
|
|
35
|
+
/**
|
|
36
|
+
* Show `code` as a diff, written as a unified diff is: the first column of each line is its
|
|
37
|
+
* sign, `+` added, `-` removed, a space unchanged. Added and removed lines are tinted and
|
|
38
|
+
* marked in a gutter with `+` and `−`; the sign column is not part of the copy.
|
|
39
|
+
*/
|
|
40
|
+
diff?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* `terminal` shows a shell session: a line starting with `$ ` is a command (the prompt is drawn
|
|
43
|
+
* apart, a trailing `\` continues it onto the next line), any other line is its output. Only
|
|
44
|
+
* the commands are highlighted (as `bash`) and copied. Default `default`.
|
|
45
|
+
*/
|
|
46
|
+
variant?: 'default' | 'terminal';
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
declare const CodeBlock: ({ code, language, highlight, showCopy, lineNumbers, highlightLines, filename, wrap, maxHeight, diff, variant, className, }: CodeBlockProps) => react.JSX.Element;
|
|
50
|
+
|
|
51
|
+
export { CodeBlock as a };
|
|
52
|
+
export type { CodeBlockProps as C };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var cosmosReact = require('@sckyzo/cosmos-react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __esm = (fn, res, err) => function __init() {
|
|
11
|
+
if (err) throw err[0];
|
|
12
|
+
try {
|
|
13
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw err = [e], e;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/code/promql.ts
|
|
24
|
+
var promql_exports = {};
|
|
25
|
+
__export(promql_exports, {
|
|
26
|
+
default: () => promql_default
|
|
27
|
+
});
|
|
28
|
+
var IDENT, GROUPING, promql, promql_default;
|
|
29
|
+
var init_promql = __esm({
|
|
30
|
+
"src/code/promql.ts"() {
|
|
31
|
+
IDENT = "[a-zA-Z_][a-zA-Z0-9_]*";
|
|
32
|
+
GROUPING = "by|without|on|ignoring|group_left|group_right";
|
|
33
|
+
promql = {
|
|
34
|
+
name: "promql",
|
|
35
|
+
displayName: "PromQL",
|
|
36
|
+
scopeName: "source.promql",
|
|
37
|
+
aliases: ["prometheus"],
|
|
38
|
+
patterns: [{ include: "#expression" }],
|
|
39
|
+
repository: {
|
|
40
|
+
expression: {
|
|
41
|
+
patterns: [
|
|
42
|
+
{ include: "#comment" },
|
|
43
|
+
{ include: "#string" },
|
|
44
|
+
{ include: "#label-matchers" },
|
|
45
|
+
{ include: "#grouping" },
|
|
46
|
+
{ include: "#duration" },
|
|
47
|
+
{ include: "#number" },
|
|
48
|
+
{ include: "#aggregation" },
|
|
49
|
+
{ include: "#keyword" },
|
|
50
|
+
{ include: "#function" },
|
|
51
|
+
{ include: "#metric" },
|
|
52
|
+
{ include: "#operator" },
|
|
53
|
+
{ include: "#punctuation" }
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
comment: {
|
|
57
|
+
name: "comment.line.number-sign.promql",
|
|
58
|
+
match: "#.*$"
|
|
59
|
+
},
|
|
60
|
+
string: {
|
|
61
|
+
patterns: [
|
|
62
|
+
{
|
|
63
|
+
name: "string.quoted.double.promql",
|
|
64
|
+
begin: '"',
|
|
65
|
+
end: '"',
|
|
66
|
+
patterns: [{ name: "constant.character.escape.promql", match: "\\\\." }]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "string.quoted.single.promql",
|
|
70
|
+
begin: "'",
|
|
71
|
+
end: "'",
|
|
72
|
+
patterns: [{ name: "constant.character.escape.promql", match: "\\\\." }]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "string.quoted.other.backtick.promql",
|
|
76
|
+
begin: "`",
|
|
77
|
+
end: "`"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
// {job="api", code!~"5..", instance=~".+"}
|
|
82
|
+
"label-matchers": {
|
|
83
|
+
name: "meta.label-matchers.promql",
|
|
84
|
+
begin: "\\{",
|
|
85
|
+
end: "\\}",
|
|
86
|
+
beginCaptures: { 0: { name: "punctuation.definition.label-matchers.begin.promql" } },
|
|
87
|
+
endCaptures: { 0: { name: "punctuation.definition.label-matchers.end.promql" } },
|
|
88
|
+
patterns: [
|
|
89
|
+
{ include: "#comment" },
|
|
90
|
+
{ include: "#string" },
|
|
91
|
+
{
|
|
92
|
+
name: "keyword.operator.comparison.label-matcher.promql",
|
|
93
|
+
match: "=~|!~|!=|="
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "meta.property-name.label.promql",
|
|
97
|
+
match: IDENT
|
|
98
|
+
},
|
|
99
|
+
{ name: "punctuation.separator.comma.promql", match: "," }
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
// sum by (job, instance) (...), a / on (job) group_left (...)
|
|
103
|
+
grouping: {
|
|
104
|
+
name: "meta.grouping.promql",
|
|
105
|
+
begin: `\\b(${GROUPING})\\b\\s*(\\()`,
|
|
106
|
+
end: "\\)",
|
|
107
|
+
beginCaptures: {
|
|
108
|
+
1: { name: "keyword.control.grouping.promql" },
|
|
109
|
+
2: { name: "punctuation.definition.grouping.begin.promql" }
|
|
110
|
+
},
|
|
111
|
+
endCaptures: { 0: { name: "punctuation.definition.grouping.end.promql" } },
|
|
112
|
+
patterns: [
|
|
113
|
+
{ include: "#string" },
|
|
114
|
+
{ name: "meta.property-name.label.promql", match: IDENT },
|
|
115
|
+
{ name: "punctuation.separator.comma.promql", match: "," }
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
// 5m, 1h30m, 500ms, as in [5m], [1h:5m] and offset 1d
|
|
119
|
+
duration: {
|
|
120
|
+
name: "constant.numeric.duration.promql",
|
|
121
|
+
match: "\\b\\d+(?:ms|[smhdwy])(?:\\d+(?:ms|[smhdwy]))*\\b"
|
|
122
|
+
},
|
|
123
|
+
number: {
|
|
124
|
+
name: "constant.numeric.promql",
|
|
125
|
+
match: "\\b(?:0[xX][0-9a-fA-F]+|\\d+\\.?\\d*(?:[eE][+-]?\\d+)?|[Ii]nf|[Nn]a[Nn])\\b|(?<![\\w.])\\.\\d+(?:[eE][+-]?\\d+)?\\b"
|
|
126
|
+
},
|
|
127
|
+
aggregation: {
|
|
128
|
+
name: "keyword.other.aggregation.promql",
|
|
129
|
+
match: "\\b(?:sum|min|max|avg|group|stddev|stdvar|count_values|count|bottomk|topk|quantile|limitk|limit_ratio)\\b(?=\\s*(?:\\(|by\\b|without\\b))"
|
|
130
|
+
},
|
|
131
|
+
keyword: {
|
|
132
|
+
patterns: [
|
|
133
|
+
{
|
|
134
|
+
name: "keyword.control.modifier.promql",
|
|
135
|
+
match: "\\b(?:offset|bool)\\b"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "keyword.operator.logical.promql",
|
|
139
|
+
match: "\\b(?:and|or|unless|atan2)\\b"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "keyword.control.grouping.promql",
|
|
143
|
+
match: `\\b(?:${GROUPING})\\b`
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
// Any name followed by "(" is a function: the list of PromQL functions grows with Prometheus.
|
|
148
|
+
function: {
|
|
149
|
+
name: "support.function.promql",
|
|
150
|
+
match: `\\b${IDENT}(?=\\s*\\()`
|
|
151
|
+
},
|
|
152
|
+
metric: {
|
|
153
|
+
name: "variable.other.metric.promql",
|
|
154
|
+
match: "(?<![\\w:])[a-zA-Z_][a-zA-Z0-9_:]*"
|
|
155
|
+
},
|
|
156
|
+
operator: {
|
|
157
|
+
patterns: [
|
|
158
|
+
{ name: "keyword.operator.comparison.promql", match: "==|!=|>=|<=|=~|!~|>|<" },
|
|
159
|
+
{ name: "keyword.operator.arithmetic.promql", match: "[-+*/%^]" },
|
|
160
|
+
{ name: "keyword.operator.modifier.at.promql", match: "@" }
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
punctuation: {
|
|
164
|
+
patterns: [
|
|
165
|
+
{ name: "punctuation.definition.range.promql", match: "[\\[\\]:]" },
|
|
166
|
+
{ name: "punctuation.definition.group.promql", match: "[()]" },
|
|
167
|
+
{ name: "punctuation.separator.comma.promql", match: "," }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
promql_default = [promql];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// src/code/languages.ts
|
|
177
|
+
var LOADERS = {
|
|
178
|
+
shellscript: () => import('shiki/langs/shellscript.mjs'),
|
|
179
|
+
shellsession: () => import('shiki/langs/shellsession.mjs'),
|
|
180
|
+
yaml: () => import('shiki/langs/yaml.mjs'),
|
|
181
|
+
json: () => import('shiki/langs/json.mjs'),
|
|
182
|
+
toml: () => import('shiki/langs/toml.mjs'),
|
|
183
|
+
ini: () => import('shiki/langs/ini.mjs'),
|
|
184
|
+
docker: () => import('shiki/langs/docker.mjs'),
|
|
185
|
+
sql: () => import('shiki/langs/sql.mjs'),
|
|
186
|
+
typescript: () => import('shiki/langs/typescript.mjs'),
|
|
187
|
+
javascript: () => import('shiki/langs/javascript.mjs'),
|
|
188
|
+
tsx: () => import('shiki/langs/tsx.mjs'),
|
|
189
|
+
jsx: () => import('shiki/langs/jsx.mjs'),
|
|
190
|
+
python: () => import('shiki/langs/python.mjs'),
|
|
191
|
+
go: () => import('shiki/langs/go.mjs'),
|
|
192
|
+
html: () => import('shiki/langs/html.mjs'),
|
|
193
|
+
xml: () => import('shiki/langs/xml.mjs'),
|
|
194
|
+
css: () => import('shiki/langs/css.mjs'),
|
|
195
|
+
diff: () => import('shiki/langs/diff.mjs'),
|
|
196
|
+
nginx: () => import('shiki/langs/nginx.mjs'),
|
|
197
|
+
hcl: () => import('shiki/langs/hcl.mjs'),
|
|
198
|
+
terraform: () => import('shiki/langs/terraform.mjs'),
|
|
199
|
+
rust: () => import('shiki/langs/rust.mjs'),
|
|
200
|
+
java: () => import('shiki/langs/java.mjs'),
|
|
201
|
+
php: () => import('shiki/langs/php.mjs'),
|
|
202
|
+
markdown: () => import('shiki/langs/markdown.mjs'),
|
|
203
|
+
promql: () => Promise.resolve().then(() => (init_promql(), promql_exports))
|
|
204
|
+
};
|
|
205
|
+
var ALIASES = {
|
|
206
|
+
bash: "shellscript",
|
|
207
|
+
sh: "shellscript",
|
|
208
|
+
shell: "shellscript",
|
|
209
|
+
zsh: "shellscript",
|
|
210
|
+
console: "shellsession",
|
|
211
|
+
yml: "yaml",
|
|
212
|
+
dockerfile: "docker",
|
|
213
|
+
ts: "typescript",
|
|
214
|
+
js: "javascript",
|
|
215
|
+
py: "python",
|
|
216
|
+
golang: "go",
|
|
217
|
+
tf: "terraform",
|
|
218
|
+
rs: "rust",
|
|
219
|
+
md: "markdown",
|
|
220
|
+
prometheus: "promql"
|
|
221
|
+
};
|
|
222
|
+
var languageId = (language) => {
|
|
223
|
+
const name = language?.trim().toLowerCase();
|
|
224
|
+
if (!name) return void 0;
|
|
225
|
+
if (Object.hasOwn(LOADERS, name)) return name;
|
|
226
|
+
return Object.hasOwn(ALIASES, name) ? ALIASES[name] : void 0;
|
|
227
|
+
};
|
|
228
|
+
var CODE_LANGUAGES = [...Object.keys(LOADERS), ...Object.keys(ALIASES)];
|
|
229
|
+
var THEME = "cosmos";
|
|
230
|
+
var ITALIC = 1;
|
|
231
|
+
var BOLD = 2;
|
|
232
|
+
var UNDERLINE = 4;
|
|
233
|
+
var missingShiki = (cause) => new Error(
|
|
234
|
+
'@sckyzo/cosmos-react/code needs the optional peer dependency "shiki". Install it with `pnpm add shiki` (or `npm install shiki`).',
|
|
235
|
+
{ cause }
|
|
236
|
+
);
|
|
237
|
+
var core;
|
|
238
|
+
var pending;
|
|
239
|
+
var loadCore = () => pending ??= (async () => {
|
|
240
|
+
let shiki;
|
|
241
|
+
let engine;
|
|
242
|
+
try {
|
|
243
|
+
[shiki, engine] = await Promise.all([
|
|
244
|
+
import('shiki/core'),
|
|
245
|
+
import('shiki/engine/javascript')
|
|
246
|
+
]);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
throw missingShiki(error);
|
|
249
|
+
}
|
|
250
|
+
core = await shiki.createHighlighterCore({
|
|
251
|
+
themes: [shiki.createCssVariablesTheme({ name: THEME, variablePrefix: "--color-code-" })],
|
|
252
|
+
langs: [],
|
|
253
|
+
engine: engine.createJavaScriptRegexEngine()
|
|
254
|
+
});
|
|
255
|
+
return core;
|
|
256
|
+
})();
|
|
257
|
+
var loading = /* @__PURE__ */ new Map();
|
|
258
|
+
var loadLanguage = (language) => {
|
|
259
|
+
const id = languageId(language);
|
|
260
|
+
if (!id) return Promise.resolve(false);
|
|
261
|
+
let promise = loading.get(id);
|
|
262
|
+
if (!promise) {
|
|
263
|
+
promise = (async () => {
|
|
264
|
+
const highlighter = await loadCore();
|
|
265
|
+
if (!highlighter.getLoadedLanguages().includes(id)) {
|
|
266
|
+
await highlighter.loadLanguage(await LOADERS[id]());
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
})();
|
|
270
|
+
promise.catch(() => loading.delete(id));
|
|
271
|
+
loading.set(id, promise);
|
|
272
|
+
}
|
|
273
|
+
return promise;
|
|
274
|
+
};
|
|
275
|
+
var isLanguageLoaded = (language) => {
|
|
276
|
+
const id = languageId(language);
|
|
277
|
+
return Boolean(id && core?.getLoadedLanguages().includes(id));
|
|
278
|
+
};
|
|
279
|
+
var tokenStyle = (color, fontStyle) => {
|
|
280
|
+
const style = {};
|
|
281
|
+
if (color) style.color = color;
|
|
282
|
+
if (fontStyle && fontStyle > 0) {
|
|
283
|
+
if (fontStyle & ITALIC) style.fontStyle = "italic";
|
|
284
|
+
if (fontStyle & BOLD) style.fontWeight = "bold";
|
|
285
|
+
if (fontStyle & UNDERLINE) style.textDecoration = "underline";
|
|
286
|
+
}
|
|
287
|
+
return style;
|
|
288
|
+
};
|
|
289
|
+
var highlight = (code, language) => {
|
|
290
|
+
const id = languageId(language);
|
|
291
|
+
if (!core || !id || !core.getLoadedLanguages().includes(id)) return code;
|
|
292
|
+
const { tokens } = core.codeToTokens(code, { lang: id, theme: THEME });
|
|
293
|
+
return tokens.map((line, i) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
|
|
294
|
+
i > 0 && "\n",
|
|
295
|
+
line.map((token, j) => /* @__PURE__ */ jsxRuntime.jsx("span", { style: tokenStyle(token.color, token.fontStyle), children: token.content }, j))
|
|
296
|
+
] }, i));
|
|
297
|
+
};
|
|
298
|
+
var CodeBlock = ({ highlight: highlight2, language, variant, ...props }) => {
|
|
299
|
+
const wanted = highlight2 ? void 0 : variant === "terminal" ? "bash" : language;
|
|
300
|
+
const [, loaded] = react.useReducer((n) => n + 1, 0);
|
|
301
|
+
const [failure, setFailure] = react.useState();
|
|
302
|
+
const ready = isLanguageLoaded(wanted);
|
|
303
|
+
react.useEffect(() => {
|
|
304
|
+
if (!wanted || ready) return;
|
|
305
|
+
let current = true;
|
|
306
|
+
loadLanguage(wanted).then(
|
|
307
|
+
() => current && loaded(),
|
|
308
|
+
(error) => current && setFailure(error)
|
|
309
|
+
);
|
|
310
|
+
return () => {
|
|
311
|
+
current = false;
|
|
312
|
+
};
|
|
313
|
+
}, [wanted, ready]);
|
|
314
|
+
if (failure) throw failure;
|
|
315
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
316
|
+
cosmosReact.CodeBlock,
|
|
317
|
+
{
|
|
318
|
+
...props,
|
|
319
|
+
language,
|
|
320
|
+
variant,
|
|
321
|
+
highlight: highlight2 ?? (ready ? highlight : void 0)
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
exports.CODE_LANGUAGES = CODE_LANGUAGES;
|
|
327
|
+
exports.CodeBlock = CodeBlock;
|
|
328
|
+
exports.highlight = highlight;
|
|
329
|
+
exports.loadLanguage = loadLanguage;
|
|
330
|
+
//# sourceMappingURL=index.cjs.map
|
|
331
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/code/promql.ts","../../src/code/languages.ts","../../src/code/highlighter.tsx","../../src/code/CodeBlock.tsx"],"names":["Fragment","highlight","useReducer","useState","useEffect","jsx","PlainCodeBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,EAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,OAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAAA,IAMM,KAAA,EACA,UAEA,MAAA,EA8IC,cAAA;AAvJP,IAAA,WAAA,GAAA,KAAA,CAAA;AAAA,EAAA,oBAAA,GAAA;AAMA,IAAM,KAAA,GAAQ,wBAAA;AACd,IAAM,QAAA,GAAW,+CAAA;AAEjB,IAAM,MAAA,GAA+B;AAAA,MACnC,IAAA,EAAM,QAAA;AAAA,MACN,WAAA,EAAa,QAAA;AAAA,MACb,SAAA,EAAW,eAAA;AAAA,MACX,OAAA,EAAS,CAAC,YAAY,CAAA;AAAA,MACtB,QAAA,EAAU,CAAC,EAAE,OAAA,EAAS,eAAe,CAAA;AAAA,MACrC,UAAA,EAAY;AAAA,QACV,UAAA,EAAY;AAAA,UACV,QAAA,EAAU;AAAA,YACR,EAAE,SAAS,UAAA,EAAW;AAAA,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AA,IAAI,SAAS,MAAM,OAAA;AAEnB,EAAA,uBACEC,cAAAA;AAAA,IAACC,qBAAA;AAAA,IAAA;AAAA,MACE,GAAG,KAAA;AAAA,MACJ,QAAA;AAAA,MACA,OAAA;AAAA,MACA,SAAA,EAAWL,UAAAA,KAAc,KAAA,GAAQ,SAAA,GAAU,MAAA;AAAA;AAAA,GAC7C;AAEJ","file":"index.cjs","sourcesContent":["import type { LanguageRegistration } from 'shiki/core';\n\n// Shiki ships no PromQL grammar. This is a small TextMate one, written for the\n// scopes the `--color-code-*` theme colours: functions and metric/label names\n// stand apart, aggregations and `by` / `without` read as keywords.\n\nconst IDENT = '[a-zA-Z_][a-zA-Z0-9_]*';\nconst GROUPING = 'by|without|on|ignoring|group_left|group_right';\n\nconst promql: LanguageRegistration = {\n name: 'promql',\n displayName: 'PromQL',\n scopeName: 'source.promql',\n aliases: ['prometheus'],\n patterns: [{ include: '#expression' }],\n repository: {\n expression: {\n patterns: [\n { include: '#comment' },\n { include: '#string' },\n { include: '#label-matchers' },\n { include: '#grouping' },\n { include: '#duration' },\n { include: '#number' },\n { include: '#aggregation' },\n { include: '#keyword' },\n { include: '#function' },\n { include: '#metric' },\n { include: '#operator' },\n { include: '#punctuation' },\n ],\n },\n comment: {\n name: 'comment.line.number-sign.promql',\n match: '#.*$',\n },\n string: {\n patterns: [\n {\n name: 'string.quoted.double.promql',\n begin: '\"',\n end: '\"',\n patterns: [{ name: 'constant.character.escape.promql', match: '\\\\\\\\.' }],\n },\n {\n name: 'string.quoted.single.promql',\n begin: \"'\",\n end: \"'\",\n patterns: [{ name: 'constant.character.escape.promql', match: '\\\\\\\\.' }],\n },\n {\n name: 'string.quoted.other.backtick.promql',\n begin: '`',\n end: '`',\n },\n ],\n },\n // {job=\"api\", code!~\"5..\", instance=~\".+\"}\n 'label-matchers': {\n name: 'meta.label-matchers.promql',\n begin: '\\\\{',\n end: '\\\\}',\n beginCaptures: { 0: { name: 'punctuation.definition.label-matchers.begin.promql' } },\n endCaptures: { 0: { name: 'punctuation.definition.label-matchers.end.promql' } },\n patterns: [\n { include: '#comment' },\n { include: '#string' },\n {\n name: 'keyword.operator.comparison.label-matcher.promql',\n match: '=~|!~|!=|=',\n },\n {\n name: 'meta.property-name.label.promql',\n match: IDENT,\n },\n { name: 'punctuation.separator.comma.promql', match: ',' },\n ],\n },\n // sum by (job, instance) (...), a / on (job) group_left (...)\n grouping: {\n name: 'meta.grouping.promql',\n begin: `\\\\b(${GROUPING})\\\\b\\\\s*(\\\\()`,\n end: '\\\\)',\n beginCaptures: {\n 1: { name: 'keyword.control.grouping.promql' },\n 2: { name: 'punctuation.definition.grouping.begin.promql' },\n },\n endCaptures: { 0: { name: 'punctuation.definition.grouping.end.promql' } },\n patterns: [\n { include: '#string' },\n { name: 'meta.property-name.label.promql', match: IDENT },\n { name: 'punctuation.separator.comma.promql', match: ',' },\n ],\n },\n // 5m, 1h30m, 500ms, as in [5m], [1h:5m] and offset 1d\n duration: {\n name: 'constant.numeric.duration.promql',\n match: '\\\\b\\\\d+(?:ms|[smhdwy])(?:\\\\d+(?:ms|[smhdwy]))*\\\\b',\n },\n number: {\n name: 'constant.numeric.promql',\n match:\n '\\\\b(?:0[xX][0-9a-fA-F]+|\\\\d+\\\\.?\\\\d*(?:[eE][+-]?\\\\d+)?|[Ii]nf|[Nn]a[Nn])\\\\b|(?<![\\\\w.])\\\\.\\\\d+(?:[eE][+-]?\\\\d+)?\\\\b',\n },\n aggregation: {\n name: 'keyword.other.aggregation.promql',\n match:\n '\\\\b(?:sum|min|max|avg|group|stddev|stdvar|count_values|count|bottomk|topk|quantile|limitk|limit_ratio)\\\\b(?=\\\\s*(?:\\\\(|by\\\\b|without\\\\b))',\n },\n keyword: {\n patterns: [\n {\n name: 'keyword.control.modifier.promql',\n match: '\\\\b(?:offset|bool)\\\\b',\n },\n {\n name: 'keyword.operator.logical.promql',\n match: '\\\\b(?:and|or|unless|atan2)\\\\b',\n },\n {\n name: 'keyword.control.grouping.promql',\n match: `\\\\b(?:${GROUPING})\\\\b`,\n },\n ],\n },\n // Any name followed by \"(\" is a function: the list of PromQL functions grows with Prometheus.\n function: {\n name: 'support.function.promql',\n match: `\\\\b${IDENT}(?=\\\\s*\\\\()`,\n },\n metric: {\n name: 'variable.other.metric.promql',\n match: '(?<![\\\\w:])[a-zA-Z_][a-zA-Z0-9_:]*',\n },\n operator: {\n patterns: [\n { name: 'keyword.operator.comparison.promql', match: '==|!=|>=|<=|=~|!~|>|<' },\n { name: 'keyword.operator.arithmetic.promql', match: '[-+*/%^]' },\n { name: 'keyword.operator.modifier.at.promql', match: '@' },\n ],\n },\n punctuation: {\n patterns: [\n { name: 'punctuation.definition.range.promql', match: '[\\\\[\\\\]:]' },\n { name: 'punctuation.definition.group.promql', match: '[()]' },\n { name: 'punctuation.separator.comma.promql', match: ',' },\n ],\n },\n },\n};\n\nexport default [promql];\n","import type { LanguageInput } from 'shiki/core';\n\n// Every language is one dynamic import: a bundler splits each into a chunk of its own, and a page\n// only downloads the ones its code blocks show. Keyed by the id Shiki knows the grammar by.\nexport const LOADERS = {\n shellscript: () => import('shiki/langs/shellscript.mjs'),\n shellsession: () => import('shiki/langs/shellsession.mjs'),\n yaml: () => import('shiki/langs/yaml.mjs'),\n json: () => import('shiki/langs/json.mjs'),\n toml: () => import('shiki/langs/toml.mjs'),\n ini: () => import('shiki/langs/ini.mjs'),\n docker: () => import('shiki/langs/docker.mjs'),\n sql: () => import('shiki/langs/sql.mjs'),\n typescript: () => import('shiki/langs/typescript.mjs'),\n javascript: () => import('shiki/langs/javascript.mjs'),\n tsx: () => import('shiki/langs/tsx.mjs'),\n jsx: () => import('shiki/langs/jsx.mjs'),\n python: () => import('shiki/langs/python.mjs'),\n go: () => import('shiki/langs/go.mjs'),\n html: () => import('shiki/langs/html.mjs'),\n xml: () => import('shiki/langs/xml.mjs'),\n css: () => import('shiki/langs/css.mjs'),\n diff: () => import('shiki/langs/diff.mjs'),\n nginx: () => import('shiki/langs/nginx.mjs'),\n hcl: () => import('shiki/langs/hcl.mjs'),\n terraform: () => import('shiki/langs/terraform.mjs'),\n rust: () => import('shiki/langs/rust.mjs'),\n java: () => import('shiki/langs/java.mjs'),\n php: () => import('shiki/langs/php.mjs'),\n markdown: () => import('shiki/langs/markdown.mjs'),\n promql: () => import('./promql'),\n} satisfies Record<string, () => PromiseLike<{ default: LanguageInput }>>;\n\nexport type LanguageId = keyof typeof LOADERS;\n\n/** The other names a language goes by in a code fence or a file name. */\nconst ALIASES: Record<string, LanguageId> = {\n bash: 'shellscript',\n sh: 'shellscript',\n shell: 'shellscript',\n zsh: 'shellscript',\n console: 'shellsession',\n yml: 'yaml',\n dockerfile: 'docker',\n ts: 'typescript',\n js: 'javascript',\n py: 'python',\n golang: 'go',\n tf: 'terraform',\n rs: 'rust',\n md: 'markdown',\n prometheus: 'promql',\n};\n\n/** The grammar behind a language name, or `undefined` for a language Cosmos has none for. */\nexport const languageId = (language?: string): LanguageId | undefined => {\n const name = language?.trim().toLowerCase();\n if (!name) return undefined;\n if (Object.hasOwn(LOADERS, name)) return name as LanguageId;\n return Object.hasOwn(ALIASES, name) ? ALIASES[name] : undefined;\n};\n\n/** The names the highlighter understands: the ids and their aliases. */\nexport const CODE_LANGUAGES: readonly string[] = [...Object.keys(LOADERS), ...Object.keys(ALIASES)];\n","import { Fragment, type CSSProperties, type ReactNode } from 'react';\nimport type { HighlighterCore } from 'shiki/core';\nimport { LOADERS, languageId } from './languages';\n\nconst THEME = 'cosmos';\n\n// Shiki's FontStyle bit flags.\nconst ITALIC = 1;\nconst BOLD = 2;\nconst UNDERLINE = 4;\n\nconst missingShiki = (cause: unknown) =>\n new Error(\n '@sckyzo/cosmos-react/code needs the optional peer dependency \"shiki\". Install it with `pnpm add shiki` (or `npm install shiki`).',\n { cause }\n );\n\nlet core: HighlighterCore | undefined;\nlet pending: Promise<HighlighterCore> | undefined;\n\n/**\n * The Shiki core, created on the first use: its colours are the `--color-code-*` tokens of the\n * theme, so a theme, accent or text size switch repaints on its own, and its regex engine is the\n * JavaScript one (no WebAssembly to load). No language is loaded yet.\n */\nconst loadCore = () =>\n (pending ??= (async () => {\n let shiki: typeof import('shiki/core');\n let engine: typeof import('shiki/engine/javascript');\n try {\n [shiki, engine] = await Promise.all([\n import('shiki/core'),\n import('shiki/engine/javascript'),\n ]);\n } catch (error) {\n throw missingShiki(error);\n }\n core = await shiki.createHighlighterCore({\n themes: [shiki.createCssVariablesTheme({ name: THEME, variablePrefix: '--color-code-' })],\n langs: [],\n engine: engine.createJavaScriptRegexEngine(),\n });\n return core;\n })());\n\nconst loading = new Map<string, Promise<boolean>>();\n\n/**\n * Loads the grammar of `language`: resolves `true` once the highlighter colours it, and `false`\n * for a language Cosmos has no grammar for (the block shows plain text). Rejects when `shiki` is\n * not installed. Loads each language once.\n */\nexport const loadLanguage = (language?: string): Promise<boolean> => {\n const id = languageId(language);\n if (!id) return Promise.resolve(false);\n let promise = loading.get(id);\n if (!promise) {\n promise = (async () => {\n const highlighter = await loadCore();\n if (!highlighter.getLoadedLanguages().includes(id)) {\n await highlighter.loadLanguage(await LOADERS[id]());\n }\n return true;\n })();\n // A failed load (no network, no shiki) is tried again on the next ask.\n promise.catch(() => loading.delete(id));\n loading.set(id, promise);\n }\n return promise;\n};\n\n/** Whether `highlight` colours `language` right now. */\nexport const isLanguageLoaded = (language?: string) => {\n const id = languageId(language);\n return Boolean(id && core?.getLoadedLanguages().includes(id));\n};\n\nconst tokenStyle = (color: string | undefined, fontStyle: number | undefined) => {\n const style: CSSProperties = {};\n if (color) style.color = color;\n if (fontStyle && fontStyle > 0) {\n if (fontStyle & ITALIC) style.fontStyle = 'italic';\n if (fontStyle & BOLD) style.fontWeight = 'bold';\n if (fontStyle & UNDERLINE) style.textDecoration = 'underline';\n }\n return style;\n};\n\n/**\n * `CodeBlock`'s `highlight` prop, ready to use: Shiki tokens as React elements (nothing goes\n * through `innerHTML`). It colours the languages that have loaded, and returns `code` as plain\n * text for the others, so a block shows its text first and its colours once\n * `loadLanguage(language)` has resolved. `CodeBlock` of this entry does both.\n */\nexport const highlight = (code: string, language?: string): ReactNode => {\n const id = languageId(language);\n if (!core || !id || !core.getLoadedLanguages().includes(id)) return code;\n const { tokens } = core.codeToTokens(code, { lang: id, theme: THEME });\n return tokens.map((line, i) => (\n <Fragment key={i}>\n {i > 0 && '\\n'}\n {line.map((token, j) => (\n <span key={j} style={tokenStyle(token.color, token.fontStyle)}>\n {token.content}\n </span>\n ))}\n </Fragment>\n ));\n};\n","import { useEffect, useReducer, useState } from 'react';\nimport { CodeBlock as PlainCodeBlock, type CodeBlockProps } from '../ui/CodeBlock';\nimport { highlight as builtIn, isLanguageLoaded, loadLanguage } from './highlighter';\n\nexport type { CodeBlockProps };\n\n/**\n * `CodeBlock` with the Shiki highlighter plugged in: `<CodeBlock language=\"yaml\" code={…} />` is\n * coloured with no setup. The language loads on demand; until it has, and for a language with no\n * grammar, the block shows plain text. A `highlight` prop still overrides the built-in one.\n */\nexport const CodeBlock = ({ highlight, language, variant, ...props }: CodeBlockProps) => {\n // A terminal session is highlighted as shell, whatever its `language` label says.\n const wanted = highlight ? undefined : variant === 'terminal' ? 'bash' : language;\n const [, loaded] = useReducer((n: number) => n + 1, 0);\n const [failure, setFailure] = useState<unknown>();\n const ready = isLanguageLoaded(wanted);\n\n useEffect(() => {\n if (!wanted || ready) return;\n let current = true;\n loadLanguage(wanted).then(\n () => current && loaded(),\n (error: unknown) => current && setFailure(error)\n );\n return () => {\n current = false;\n };\n }, [wanted, ready]);\n\n // Rendered, so an error boundary catches it: a missing peer names the package to install.\n if (failure) throw failure;\n\n return (\n <PlainCodeBlock\n {...props}\n language={language}\n variant={variant}\n highlight={highlight ?? (ready ? builtIn : undefined)}\n />\n );\n};\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { C as CodeBlockProps } from '../CodeBlock-CY18_3tZ.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `CodeBlock` with the Shiki highlighter plugged in: `<CodeBlock language="yaml" code={…} />` is
|
|
7
|
+
* coloured with no setup. The language loads on demand; until it has, and for a language with no
|
|
8
|
+
* grammar, the block shows plain text. A `highlight` prop still overrides the built-in one.
|
|
9
|
+
*/
|
|
10
|
+
declare const CodeBlock: ({ highlight, language, variant, ...props }: CodeBlockProps) => react.JSX.Element;
|
|
11
|
+
|
|
12
|
+
/** The names the highlighter understands: the ids and their aliases. */
|
|
13
|
+
declare const CODE_LANGUAGES: readonly string[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Loads the grammar of `language`: resolves `true` once the highlighter colours it, and `false`
|
|
17
|
+
* for a language Cosmos has no grammar for (the block shows plain text). Rejects when `shiki` is
|
|
18
|
+
* not installed. Loads each language once.
|
|
19
|
+
*/
|
|
20
|
+
declare const loadLanguage: (language?: string) => Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* `CodeBlock`'s `highlight` prop, ready to use: Shiki tokens as React elements (nothing goes
|
|
23
|
+
* through `innerHTML`). It colours the languages that have loaded, and returns `code` as plain
|
|
24
|
+
* text for the others, so a block shows its text first and its colours once
|
|
25
|
+
* `loadLanguage(language)` has resolved. `CodeBlock` of this entry does both.
|
|
26
|
+
*/
|
|
27
|
+
declare const highlight: (code: string, language?: string) => ReactNode;
|
|
28
|
+
|
|
29
|
+
export { CODE_LANGUAGES, CodeBlock, CodeBlockProps, highlight, loadLanguage };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { C as CodeBlockProps } from '../CodeBlock-CY18_3tZ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `CodeBlock` with the Shiki highlighter plugged in: `<CodeBlock language="yaml" code={…} />` is
|
|
7
|
+
* coloured with no setup. The language loads on demand; until it has, and for a language with no
|
|
8
|
+
* grammar, the block shows plain text. A `highlight` prop still overrides the built-in one.
|
|
9
|
+
*/
|
|
10
|
+
declare const CodeBlock: ({ highlight, language, variant, ...props }: CodeBlockProps) => react.JSX.Element;
|
|
11
|
+
|
|
12
|
+
/** The names the highlighter understands: the ids and their aliases. */
|
|
13
|
+
declare const CODE_LANGUAGES: readonly string[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Loads the grammar of `language`: resolves `true` once the highlighter colours it, and `false`
|
|
17
|
+
* for a language Cosmos has no grammar for (the block shows plain text). Rejects when `shiki` is
|
|
18
|
+
* not installed. Loads each language once.
|
|
19
|
+
*/
|
|
20
|
+
declare const loadLanguage: (language?: string) => Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* `CodeBlock`'s `highlight` prop, ready to use: Shiki tokens as React elements (nothing goes
|
|
23
|
+
* through `innerHTML`). It colours the languages that have loaded, and returns `code` as plain
|
|
24
|
+
* text for the others, so a block shows its text first and its colours once
|
|
25
|
+
* `loadLanguage(language)` has resolved. `CodeBlock` of this entry does both.
|
|
26
|
+
*/
|
|
27
|
+
declare const highlight: (code: string, language?: string) => ReactNode;
|
|
28
|
+
|
|
29
|
+
export { CODE_LANGUAGES, CodeBlock, CodeBlockProps, highlight, loadLanguage };
|