scoobie 21.2.0 → 22.0.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/lib/_virtual/_rolldown/runtime.cjs +23 -0
- package/lib/components/Blockquote.cjs +25 -0
- package/lib/components/Blockquote.css.cjs +29 -0
- package/lib/components/Blockquote.css.js +27 -0
- package/lib/components/Blockquote.d.cts +10 -0
- package/lib/components/Blockquote.d.ts +10 -0
- package/lib/components/Blockquote.js +24 -0
- package/lib/components/CodeBlock/CodeChild.cjs +82 -0
- package/lib/components/CodeBlock/CodeChild.d.cts +8 -0
- package/lib/components/CodeBlock/CodeChild.d.ts +8 -0
- package/lib/components/CodeBlock/CodeChild.js +82 -0
- package/lib/components/CodeBlock/GraphQLPlaygroundAction.cjs +22 -0
- package/lib/components/CodeBlock/GraphQLPlaygroundAction.js +21 -0
- package/lib/components/CodeBlock.cjs +84 -0
- package/lib/components/CodeBlock.d.cts +24 -0
- package/lib/components/CodeBlock.d.ts +24 -0
- package/lib/components/CodeBlock.js +83 -0
- package/lib/components/CodeContainer.cjs +71 -0
- package/lib/components/CodeContainer.css.cjs +41 -0
- package/lib/components/CodeContainer.css.js +39 -0
- package/lib/components/CodeContainer.d.cts +14 -0
- package/lib/components/CodeContainer.d.ts +14 -0
- package/lib/components/CodeContainer.js +68 -0
- package/lib/components/CodeThemeProvider.cjs +13 -0
- package/lib/components/CodeThemeProvider.d.cts +20 -0
- package/lib/components/CodeThemeProvider.d.ts +20 -0
- package/lib/components/CodeThemeProvider.js +11 -0
- package/lib/components/CopyableText.cjs +32 -0
- package/lib/components/CopyableText.d.cts +23 -0
- package/lib/components/CopyableText.d.ts +23 -0
- package/lib/components/CopyableText.js +31 -0
- package/lib/components/InlineCode.cjs +35 -0
- package/lib/components/InlineCode.css.cjs +47 -0
- package/lib/components/InlineCode.css.js +42 -0
- package/lib/components/InlineCode.d.cts +14 -0
- package/lib/components/InlineCode.d.ts +14 -0
- package/lib/components/InlineCode.js +34 -0
- package/lib/components/InternalLink.cjs +29 -0
- package/lib/components/InternalLink.css.cjs +13 -0
- package/lib/components/InternalLink.css.js +12 -0
- package/lib/components/InternalLink.d.cts +15 -0
- package/lib/components/InternalLink.d.ts +15 -0
- package/lib/components/InternalLink.js +27 -0
- package/lib/components/ScoobieLink.cjs +33 -0
- package/lib/components/ScoobieLink.d.cts +6 -0
- package/lib/components/ScoobieLink.d.ts +6 -0
- package/lib/components/ScoobieLink.js +32 -0
- package/lib/components/ScoobieLinkProvider.cjs +13 -0
- package/lib/components/ScoobieLinkProvider.d.cts +19 -0
- package/lib/components/ScoobieLinkProvider.d.ts +19 -0
- package/lib/components/ScoobieLinkProvider.js +11 -0
- package/lib/components/SmartTextLink.cjs +21 -0
- package/lib/components/SmartTextLink.d.cts +19 -0
- package/lib/components/SmartTextLink.d.ts +19 -0
- package/lib/components/SmartTextLink.js +20 -0
- package/lib/index.cjs +21 -0
- package/lib/index.d.cts +11 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/private/ExternalTextLink.cjs +19 -0
- package/lib/private/ExternalTextLink.js +18 -0
- package/lib/private/Prism.cjs +1138 -0
- package/lib/private/Prism.js +1138 -0
- package/lib/private/ScrollableInline.cjs +16 -0
- package/lib/private/ScrollableInline.css.cjs +26 -0
- package/lib/private/ScrollableInline.css.js +24 -0
- package/lib/private/ScrollableInline.js +15 -0
- package/lib/private/codeThemes.cjs +150 -0
- package/lib/private/codeThemes.d.cts +136 -0
- package/lib/private/codeThemes.d.ts +136 -0
- package/lib/private/codeThemes.js +150 -0
- package/lib/private/color.cjs +179 -0
- package/lib/private/color.js +178 -0
- package/lib/private/font.css.cjs +54 -0
- package/lib/private/font.css.js +52 -0
- package/lib/private/prismUtils.cjs +47 -0
- package/lib/private/prismUtils.js +46 -0
- package/lib/private/types.d.cts +7 -0
- package/lib/private/types.d.ts +7 -0
- package/lib/private/url.cjs +24 -0
- package/lib/private/url.js +23 -0
- package/lib/typography.cjs +19 -0
- package/lib/typography.d.cts +7 -0
- package/lib/typography.d.ts +7 -0
- package/lib/typography.js +15 -0
- package/package.json +39 -22
- package/src/components/Blockquote.css.ts +0 -26
- package/src/components/Blockquote.tsx +0 -24
- package/src/components/CodeBlock/CodeChild.tsx +0 -147
- package/src/components/CodeBlock/GraphQLPlaygroundAction.tsx +0 -31
- package/src/components/CodeBlock.tsx +0 -129
- package/src/components/CodeContainer.css.ts +0 -48
- package/src/components/CodeContainer.tsx +0 -85
- package/src/components/CodeThemeProvider.tsx +0 -25
- package/src/components/CopyableText.tsx +0 -62
- package/src/components/InlineCode.css.ts +0 -54
- package/src/components/InlineCode.tsx +0 -47
- package/src/components/InternalLink.css.ts +0 -9
- package/src/components/InternalLink.tsx +0 -50
- package/src/components/Placeholder.css.ts +0 -20
- package/src/components/Placeholder.tsx +0 -28
- package/src/components/ScoobieLink.tsx +0 -38
- package/src/components/ScoobieLinkProvider.tsx +0 -29
- package/src/components/SmartTextLink.tsx +0 -30
- package/src/index.ts +0 -10
- package/src/private/ExternalTextLink.tsx +0 -30
- package/src/private/HorizontalRule.css.ts +0 -7
- package/src/private/HorizontalRule.tsx +0 -7
- package/src/private/OrderedListContext.tsx +0 -29
- package/src/private/Prism.d.ts +0 -3
- package/src/private/Prism.js +0 -1472
- package/src/private/ScrollableInline.css.ts +0 -22
- package/src/private/ScrollableInline.tsx +0 -21
- package/src/private/Wrapper.css.ts +0 -5
- package/src/private/codeThemes.ts +0 -139
- package/src/private/color.ts +0 -180
- package/src/private/font.css.ts +0 -58
- package/src/private/prismUtils.ts +0 -60
- package/src/private/types.ts +0 -4
- package/src/private/url.ts +0 -45
- package/typography.ts +0 -25
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_Blockquote_css = require("./Blockquote.css.cjs");
|
|
3
|
+
let braid_design_system = require("braid-design-system");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/components/Blockquote.tsx
|
|
6
|
+
const Blockquote = ({ children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(braid_design_system.Box, {
|
|
7
|
+
className: require_Blockquote_css.quoteBlock,
|
|
8
|
+
padding: "medium",
|
|
9
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Stack, {
|
|
10
|
+
space: "medium",
|
|
11
|
+
children
|
|
12
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Box, {
|
|
13
|
+
position: "absolute",
|
|
14
|
+
className: require_Blockquote_css.quoteMark,
|
|
15
|
+
userSelect: "none",
|
|
16
|
+
zIndex: 0,
|
|
17
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Heading, {
|
|
18
|
+
component: "div",
|
|
19
|
+
level: "2",
|
|
20
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Secondary, { children: "”" })
|
|
21
|
+
})
|
|
22
|
+
})]
|
|
23
|
+
});
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.Blockquote = Blockquote;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _vanilla_extract_css_fileScope = require("@vanilla-extract/css/fileScope");
|
|
3
|
+
let _vanilla_extract_css = require("@vanilla-extract/css");
|
|
4
|
+
let braid_design_system_css = require("braid-design-system/css");
|
|
5
|
+
//#region src/components/Blockquote.css.ts
|
|
6
|
+
(0, _vanilla_extract_css_fileScope.setFileScope)("src/components/Blockquote.css.ts", "scoobie");
|
|
7
|
+
const quoteBlock = (0, _vanilla_extract_css.style)([{
|
|
8
|
+
borderLeftStyle: "solid",
|
|
9
|
+
borderLeftWidth: braid_design_system_css.vars.space.xxsmall,
|
|
10
|
+
borderRadius: braid_design_system_css.vars.borderRadius.standard,
|
|
11
|
+
position: "relative"
|
|
12
|
+
}, (0, braid_design_system_css.colorModeStyle)({
|
|
13
|
+
darkMode: {
|
|
14
|
+
backgroundColor: braid_design_system_css.vars.backgroundColor.neutral,
|
|
15
|
+
borderLeftColor: braid_design_system_css.vars.borderColor.field
|
|
16
|
+
},
|
|
17
|
+
lightMode: {
|
|
18
|
+
backgroundColor: braid_design_system_css.vars.backgroundColor.neutralLight,
|
|
19
|
+
borderLeftColor: braid_design_system_css.vars.borderColor.neutralLight
|
|
20
|
+
}
|
|
21
|
+
})], "quoteBlock");
|
|
22
|
+
const quoteMark = (0, _vanilla_extract_css.style)({
|
|
23
|
+
right: braid_design_system_css.vars.space.xxsmall,
|
|
24
|
+
top: braid_design_system_css.vars.space.xxsmall
|
|
25
|
+
}, "quoteMark");
|
|
26
|
+
(0, _vanilla_extract_css_fileScope.endFileScope)();
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.quoteBlock = quoteBlock;
|
|
29
|
+
exports.quoteMark = quoteMark;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { endFileScope, setFileScope } from "@vanilla-extract/css/fileScope";
|
|
2
|
+
import { style } from "@vanilla-extract/css";
|
|
3
|
+
import { colorModeStyle, vars } from "braid-design-system/css";
|
|
4
|
+
//#region src/components/Blockquote.css.ts
|
|
5
|
+
setFileScope("src/components/Blockquote.css.ts", "scoobie");
|
|
6
|
+
const quoteBlock = style([{
|
|
7
|
+
borderLeftStyle: "solid",
|
|
8
|
+
borderLeftWidth: vars.space.xxsmall,
|
|
9
|
+
borderRadius: vars.borderRadius.standard,
|
|
10
|
+
position: "relative"
|
|
11
|
+
}, colorModeStyle({
|
|
12
|
+
darkMode: {
|
|
13
|
+
backgroundColor: vars.backgroundColor.neutral,
|
|
14
|
+
borderLeftColor: vars.borderColor.field
|
|
15
|
+
},
|
|
16
|
+
lightMode: {
|
|
17
|
+
backgroundColor: vars.backgroundColor.neutralLight,
|
|
18
|
+
borderLeftColor: vars.borderColor.neutralLight
|
|
19
|
+
}
|
|
20
|
+
})], "quoteBlock");
|
|
21
|
+
const quoteMark = style({
|
|
22
|
+
right: vars.space.xxsmall,
|
|
23
|
+
top: vars.space.xxsmall
|
|
24
|
+
}, "quoteMark");
|
|
25
|
+
endFileScope();
|
|
26
|
+
//#endregion
|
|
27
|
+
export { quoteBlock, quoteMark };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StackChildrenProps } from "../private/types.cjs";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/Blockquote.d.ts
|
|
5
|
+
type Props = StackChildrenProps;
|
|
6
|
+
declare const Blockquote: ({
|
|
7
|
+
children
|
|
8
|
+
}: Props) => _$react.JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Blockquote };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StackChildrenProps } from "../private/types.js";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/Blockquote.d.ts
|
|
5
|
+
type Props = StackChildrenProps;
|
|
6
|
+
declare const Blockquote: ({
|
|
7
|
+
children
|
|
8
|
+
}: Props) => _$react.JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Blockquote };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { quoteBlock, quoteMark } from "./Blockquote.css.js";
|
|
2
|
+
import { Box, Heading, Secondary, Stack } from "braid-design-system";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/Blockquote.tsx
|
|
5
|
+
const Blockquote = ({ children }) => /* @__PURE__ */ jsxs(Box, {
|
|
6
|
+
className: quoteBlock,
|
|
7
|
+
padding: "medium",
|
|
8
|
+
children: [/* @__PURE__ */ jsx(Stack, {
|
|
9
|
+
space: "medium",
|
|
10
|
+
children
|
|
11
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
12
|
+
position: "absolute",
|
|
13
|
+
className: quoteMark,
|
|
14
|
+
userSelect: "none",
|
|
15
|
+
zIndex: 0,
|
|
16
|
+
children: /* @__PURE__ */ jsx(Heading, {
|
|
17
|
+
component: "div",
|
|
18
|
+
level: "2",
|
|
19
|
+
children: /* @__PURE__ */ jsx(Secondary, { children: "”" })
|
|
20
|
+
})
|
|
21
|
+
})]
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Blockquote };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const require_prismUtils = require("../../private/prismUtils.cjs");
|
|
2
|
+
//#region src/components/CodeBlock/CodeChild.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Apply labels to the provided code nodes.
|
|
5
|
+
*/
|
|
6
|
+
const withLabels = (children, labels) => children.map((child, index) => ({
|
|
7
|
+
...child,
|
|
8
|
+
label: labels[index]
|
|
9
|
+
}));
|
|
10
|
+
/**
|
|
11
|
+
* Determine a unique label for each code node.
|
|
12
|
+
*
|
|
13
|
+
* If an explicit label is not provided, the language field is used instead. On
|
|
14
|
+
* conflicts, the label is suffixed with an incrementing integer starting at 1.
|
|
15
|
+
*/
|
|
16
|
+
const determineUniqueLabels = (rawChildren) => {
|
|
17
|
+
const children = withLabels(rawChildren, rawChildren.map((child) => child.label ?? require_prismUtils.displayLanguage(child.language)));
|
|
18
|
+
const originalLabelCounts = children.reduce((map, child) => {
|
|
19
|
+
map.set(child.label, (map.get(child.label) ?? 0) + 1);
|
|
20
|
+
return map;
|
|
21
|
+
}, /* @__PURE__ */ new Map());
|
|
22
|
+
const usedLabels = /* @__PURE__ */ new Set();
|
|
23
|
+
return children.map((child) => {
|
|
24
|
+
let label = child.label;
|
|
25
|
+
while (usedLabels.has(label) || (originalLabelCounts.get(label) ?? 0) > 1) {
|
|
26
|
+
const increment = label.match(/ (\d+)$/)?.[1];
|
|
27
|
+
label = increment ? label.replace(/\d+$/, String(Number(increment) + 1)) : `${label} 1`;
|
|
28
|
+
}
|
|
29
|
+
usedLabels.add(label);
|
|
30
|
+
return label;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const createLabeller = (fallback, ...matchers) => (children) => {
|
|
34
|
+
if (children.some((child) => child.label)) return fallback(children);
|
|
35
|
+
const actualLanguages = JSON.stringify(children.map((child) => child.language));
|
|
36
|
+
for (const { languages, labels } of matchers) if (JSON.stringify(languages) === actualLanguages) return labels(children);
|
|
37
|
+
return fallback(children);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Infer the operation type from a trimmed GraphQL operation definition.
|
|
41
|
+
*/
|
|
42
|
+
const inferGraphQLOperationType = ({ code }) => {
|
|
43
|
+
if (code.startsWith("mutation")) return "Mutation";
|
|
44
|
+
if (code.startsWith("subscription")) return "Subscription";
|
|
45
|
+
return "Query";
|
|
46
|
+
};
|
|
47
|
+
const labeller = createLabeller(determineUniqueLabels, {
|
|
48
|
+
languages: [
|
|
49
|
+
"graphql",
|
|
50
|
+
"json",
|
|
51
|
+
"json"
|
|
52
|
+
],
|
|
53
|
+
labels: ([child]) => [
|
|
54
|
+
inferGraphQLOperationType(child),
|
|
55
|
+
"Variables",
|
|
56
|
+
"Result"
|
|
57
|
+
]
|
|
58
|
+
}, {
|
|
59
|
+
languages: ["graphql", "json"],
|
|
60
|
+
labels: ([child]) => [inferGraphQLOperationType(child), "Variables"]
|
|
61
|
+
}, {
|
|
62
|
+
languages: ["http", "http"],
|
|
63
|
+
labels: () => ["Request", "Response"]
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Normalise code nodes with the following operations:
|
|
67
|
+
*
|
|
68
|
+
* - Trim code whitespace
|
|
69
|
+
* - Map language to Prism value
|
|
70
|
+
* - Infer label based on language(s)
|
|
71
|
+
* - Ensure label uniqueness
|
|
72
|
+
*/
|
|
73
|
+
const normaliseChildren = (rawChildren, trim) => {
|
|
74
|
+
const children = rawChildren.map((child) => ({
|
|
75
|
+
code: trim ? child.code.trim() : child.code,
|
|
76
|
+
label: child.label,
|
|
77
|
+
language: require_prismUtils.prismLanguage(child.language)
|
|
78
|
+
}));
|
|
79
|
+
return withLabels(children, labeller(children));
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.normaliseChildren = normaliseChildren;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { displayLanguage, prismLanguage } from "../../private/prismUtils.js";
|
|
2
|
+
//#region src/components/CodeBlock/CodeChild.tsx
|
|
3
|
+
/**
|
|
4
|
+
* Apply labels to the provided code nodes.
|
|
5
|
+
*/
|
|
6
|
+
const withLabels = (children, labels) => children.map((child, index) => ({
|
|
7
|
+
...child,
|
|
8
|
+
label: labels[index]
|
|
9
|
+
}));
|
|
10
|
+
/**
|
|
11
|
+
* Determine a unique label for each code node.
|
|
12
|
+
*
|
|
13
|
+
* If an explicit label is not provided, the language field is used instead. On
|
|
14
|
+
* conflicts, the label is suffixed with an incrementing integer starting at 1.
|
|
15
|
+
*/
|
|
16
|
+
const determineUniqueLabels = (rawChildren) => {
|
|
17
|
+
const children = withLabels(rawChildren, rawChildren.map((child) => child.label ?? displayLanguage(child.language)));
|
|
18
|
+
const originalLabelCounts = children.reduce((map, child) => {
|
|
19
|
+
map.set(child.label, (map.get(child.label) ?? 0) + 1);
|
|
20
|
+
return map;
|
|
21
|
+
}, /* @__PURE__ */ new Map());
|
|
22
|
+
const usedLabels = /* @__PURE__ */ new Set();
|
|
23
|
+
return children.map((child) => {
|
|
24
|
+
let label = child.label;
|
|
25
|
+
while (usedLabels.has(label) || (originalLabelCounts.get(label) ?? 0) > 1) {
|
|
26
|
+
const increment = label.match(/ (\d+)$/)?.[1];
|
|
27
|
+
label = increment ? label.replace(/\d+$/, String(Number(increment) + 1)) : `${label} 1`;
|
|
28
|
+
}
|
|
29
|
+
usedLabels.add(label);
|
|
30
|
+
return label;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const createLabeller = (fallback, ...matchers) => (children) => {
|
|
34
|
+
if (children.some((child) => child.label)) return fallback(children);
|
|
35
|
+
const actualLanguages = JSON.stringify(children.map((child) => child.language));
|
|
36
|
+
for (const { languages, labels } of matchers) if (JSON.stringify(languages) === actualLanguages) return labels(children);
|
|
37
|
+
return fallback(children);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Infer the operation type from a trimmed GraphQL operation definition.
|
|
41
|
+
*/
|
|
42
|
+
const inferGraphQLOperationType = ({ code }) => {
|
|
43
|
+
if (code.startsWith("mutation")) return "Mutation";
|
|
44
|
+
if (code.startsWith("subscription")) return "Subscription";
|
|
45
|
+
return "Query";
|
|
46
|
+
};
|
|
47
|
+
const labeller = createLabeller(determineUniqueLabels, {
|
|
48
|
+
languages: [
|
|
49
|
+
"graphql",
|
|
50
|
+
"json",
|
|
51
|
+
"json"
|
|
52
|
+
],
|
|
53
|
+
labels: ([child]) => [
|
|
54
|
+
inferGraphQLOperationType(child),
|
|
55
|
+
"Variables",
|
|
56
|
+
"Result"
|
|
57
|
+
]
|
|
58
|
+
}, {
|
|
59
|
+
languages: ["graphql", "json"],
|
|
60
|
+
labels: ([child]) => [inferGraphQLOperationType(child), "Variables"]
|
|
61
|
+
}, {
|
|
62
|
+
languages: ["http", "http"],
|
|
63
|
+
labels: () => ["Request", "Response"]
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Normalise code nodes with the following operations:
|
|
67
|
+
*
|
|
68
|
+
* - Trim code whitespace
|
|
69
|
+
* - Map language to Prism value
|
|
70
|
+
* - Infer label based on language(s)
|
|
71
|
+
* - Ensure label uniqueness
|
|
72
|
+
*/
|
|
73
|
+
const normaliseChildren = (rawChildren, trim) => {
|
|
74
|
+
const children = rawChildren.map((child) => ({
|
|
75
|
+
code: trim ? child.code.trim() : child.code,
|
|
76
|
+
label: child.label,
|
|
77
|
+
language: prismLanguage(child.language)
|
|
78
|
+
}));
|
|
79
|
+
return withLabels(children, labeller(children));
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { normaliseChildren };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let braid_design_system = require("braid-design-system");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
//#region src/components/CodeBlock/GraphQLPlaygroundAction.tsx
|
|
5
|
+
const GraphQLPlaygroundAction = ({ query, variables, graphqlPlayground }) => {
|
|
6
|
+
const playgroundUrl = new URL(graphqlPlayground);
|
|
7
|
+
playgroundUrl.searchParams.set("query", query);
|
|
8
|
+
playgroundUrl.searchParams.set("variables", variables ?? "{}");
|
|
9
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Text, {
|
|
10
|
+
size: "small",
|
|
11
|
+
weight: "medium",
|
|
12
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.TextLink, {
|
|
13
|
+
href: playgroundUrl.toString(),
|
|
14
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.IconVideo, { alignY: "lowercase" }),
|
|
15
|
+
rel: "noreferrer",
|
|
16
|
+
target: "_blank",
|
|
17
|
+
children: "GraphQL Explorer"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.GraphQLPlaygroundAction = GraphQLPlaygroundAction;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IconVideo, Text, TextLink } from "braid-design-system";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/components/CodeBlock/GraphQLPlaygroundAction.tsx
|
|
4
|
+
const GraphQLPlaygroundAction = ({ query, variables, graphqlPlayground }) => {
|
|
5
|
+
const playgroundUrl = new URL(graphqlPlayground);
|
|
6
|
+
playgroundUrl.searchParams.set("query", query);
|
|
7
|
+
playgroundUrl.searchParams.set("variables", variables ?? "{}");
|
|
8
|
+
return /* @__PURE__ */ jsx(Text, {
|
|
9
|
+
size: "small",
|
|
10
|
+
weight: "medium",
|
|
11
|
+
children: /* @__PURE__ */ jsx(TextLink, {
|
|
12
|
+
href: playgroundUrl.toString(),
|
|
13
|
+
icon: /* @__PURE__ */ jsx(IconVideo, { alignY: "lowercase" }),
|
|
14
|
+
rel: "noreferrer",
|
|
15
|
+
target: "_blank",
|
|
16
|
+
children: "GraphQL Explorer"
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { GraphQLPlaygroundAction };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_ScrollableInline = require("../private/ScrollableInline.cjs");
|
|
3
|
+
const require_CodeChild = require("./CodeBlock/CodeChild.cjs");
|
|
4
|
+
const require_GraphQLPlaygroundAction = require("./CodeBlock/GraphQLPlaygroundAction.cjs");
|
|
5
|
+
const require_CodeContainer = require("./CodeContainer.cjs");
|
|
6
|
+
const require_CopyableText = require("./CopyableText.cjs");
|
|
7
|
+
let braid_design_system = require("braid-design-system");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
let jsonc_parser = require("jsonc-parser");
|
|
10
|
+
let react = require("react");
|
|
11
|
+
//#region src/components/CodeBlock.tsx
|
|
12
|
+
const CodeBlock = ({ children: rawChildren, graphqlPlayground, initialIndex = 0, label: rawLabel, language: rawLanguage, trim = true, lineNumbers = true }) => {
|
|
13
|
+
const children = require_CodeChild.normaliseChildren(typeof rawChildren === "string" ? [{
|
|
14
|
+
code: rawChildren,
|
|
15
|
+
label: rawLabel,
|
|
16
|
+
language: rawLanguage
|
|
17
|
+
}] : rawChildren, trim);
|
|
18
|
+
const [index, setIndex] = (0, react.useState)({
|
|
19
|
+
dirty: false,
|
|
20
|
+
value: initialIndex
|
|
21
|
+
});
|
|
22
|
+
(0, react.useEffect)(() => setIndex((i) => i.dirty ? i : {
|
|
23
|
+
...i,
|
|
24
|
+
value: initialIndex
|
|
25
|
+
}), [initialIndex]);
|
|
26
|
+
const child = children[index.value] ?? children[0];
|
|
27
|
+
const variableIndexBlock = [index.value, 1].find((idx) => children[idx]?.language?.startsWith("json") && children[idx]?.label?.startsWith("Variables"));
|
|
28
|
+
const jsoncVariables = children[0].language === "graphql" && variableIndexBlock !== void 0 ? children[variableIndexBlock].code : void 0;
|
|
29
|
+
const variables = jsoncVariables && JSON.stringify((0, jsonc_parser.parse)(jsoncVariables), null, 2);
|
|
30
|
+
const graphqlPlaygroundButton = children[0].language === "graphql" && graphqlPlayground ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Box, {
|
|
31
|
+
component: "span",
|
|
32
|
+
paddingLeft: "small",
|
|
33
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_GraphQLPlaygroundAction.GraphQLPlaygroundAction, {
|
|
34
|
+
graphqlPlayground,
|
|
35
|
+
query: children[0].code,
|
|
36
|
+
variables
|
|
37
|
+
})
|
|
38
|
+
}) : void 0;
|
|
39
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(braid_design_system.Stack, {
|
|
40
|
+
space: "small",
|
|
41
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ScrollableInline.ScrollableInline, {
|
|
42
|
+
whiteSpace: "nowrap",
|
|
43
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(braid_design_system.Box, {
|
|
44
|
+
display: "flex",
|
|
45
|
+
justifyContent: "spaceBetween",
|
|
46
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Box, {
|
|
47
|
+
display: "flex",
|
|
48
|
+
children: children.map(({ label }, labelIndex) => label ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Box, {
|
|
49
|
+
component: "span",
|
|
50
|
+
paddingLeft: labelIndex === 0 ? void 0 : "small",
|
|
51
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Text, {
|
|
52
|
+
size: "small",
|
|
53
|
+
tone: index.value === labelIndex ? "secondary" : void 0,
|
|
54
|
+
weight: "medium",
|
|
55
|
+
children: children.length === 1 || index.value === labelIndex ? label : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.TextLinkButton, {
|
|
56
|
+
onClick: () => setIndex({
|
|
57
|
+
dirty: true,
|
|
58
|
+
value: labelIndex
|
|
59
|
+
}),
|
|
60
|
+
children: label
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
}, label) : null)
|
|
64
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(braid_design_system.Box, {
|
|
65
|
+
display: "flex",
|
|
66
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(braid_design_system.Box, {
|
|
67
|
+
component: "span",
|
|
68
|
+
paddingLeft: "small",
|
|
69
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CopyableText.CopyableText, {
|
|
70
|
+
size: "small",
|
|
71
|
+
children: child.code
|
|
72
|
+
})
|
|
73
|
+
}), graphqlPlaygroundButton]
|
|
74
|
+
})]
|
|
75
|
+
})
|
|
76
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CodeContainer.CodeContainer, {
|
|
77
|
+
code: child.code,
|
|
78
|
+
language: child.language,
|
|
79
|
+
lineNumbers
|
|
80
|
+
})]
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.CodeBlock = CodeBlock;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CodeChildProps } from "./CodeBlock/CodeChild.cjs";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/CodeBlock.d.ts
|
|
5
|
+
interface Props {
|
|
6
|
+
children: readonly CodeChildProps[] | string;
|
|
7
|
+
graphqlPlayground?: string;
|
|
8
|
+
initialIndex?: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
language?: string;
|
|
11
|
+
trim?: boolean;
|
|
12
|
+
lineNumbers?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const CodeBlock: ({
|
|
15
|
+
children: rawChildren,
|
|
16
|
+
graphqlPlayground,
|
|
17
|
+
initialIndex,
|
|
18
|
+
label: rawLabel,
|
|
19
|
+
language: rawLanguage,
|
|
20
|
+
trim,
|
|
21
|
+
lineNumbers
|
|
22
|
+
}: Props) => _$react.JSX.Element;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CodeChildProps } from "./CodeBlock/CodeChild.js";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/CodeBlock.d.ts
|
|
5
|
+
interface Props {
|
|
6
|
+
children: readonly CodeChildProps[] | string;
|
|
7
|
+
graphqlPlayground?: string;
|
|
8
|
+
initialIndex?: number;
|
|
9
|
+
label?: string;
|
|
10
|
+
language?: string;
|
|
11
|
+
trim?: boolean;
|
|
12
|
+
lineNumbers?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const CodeBlock: ({
|
|
15
|
+
children: rawChildren,
|
|
16
|
+
graphqlPlayground,
|
|
17
|
+
initialIndex,
|
|
18
|
+
label: rawLabel,
|
|
19
|
+
language: rawLanguage,
|
|
20
|
+
trim,
|
|
21
|
+
lineNumbers
|
|
22
|
+
}: Props) => _$react.JSX.Element;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CodeBlock };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ScrollableInline } from "../private/ScrollableInline.js";
|
|
2
|
+
import { normaliseChildren } from "./CodeBlock/CodeChild.js";
|
|
3
|
+
import { GraphQLPlaygroundAction } from "./CodeBlock/GraphQLPlaygroundAction.js";
|
|
4
|
+
import { CodeContainer } from "./CodeContainer.js";
|
|
5
|
+
import { CopyableText } from "./CopyableText.js";
|
|
6
|
+
import { Box, Stack, Text, TextLinkButton } from "braid-design-system";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { parse } from "jsonc-parser";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
//#region src/components/CodeBlock.tsx
|
|
11
|
+
const CodeBlock = ({ children: rawChildren, graphqlPlayground, initialIndex = 0, label: rawLabel, language: rawLanguage, trim = true, lineNumbers = true }) => {
|
|
12
|
+
const children = normaliseChildren(typeof rawChildren === "string" ? [{
|
|
13
|
+
code: rawChildren,
|
|
14
|
+
label: rawLabel,
|
|
15
|
+
language: rawLanguage
|
|
16
|
+
}] : rawChildren, trim);
|
|
17
|
+
const [index, setIndex] = useState({
|
|
18
|
+
dirty: false,
|
|
19
|
+
value: initialIndex
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => setIndex((i) => i.dirty ? i : {
|
|
22
|
+
...i,
|
|
23
|
+
value: initialIndex
|
|
24
|
+
}), [initialIndex]);
|
|
25
|
+
const child = children[index.value] ?? children[0];
|
|
26
|
+
const variableIndexBlock = [index.value, 1].find((idx) => children[idx]?.language?.startsWith("json") && children[idx]?.label?.startsWith("Variables"));
|
|
27
|
+
const jsoncVariables = children[0].language === "graphql" && variableIndexBlock !== void 0 ? children[variableIndexBlock].code : void 0;
|
|
28
|
+
const variables = jsoncVariables && JSON.stringify(parse(jsoncVariables), null, 2);
|
|
29
|
+
const graphqlPlaygroundButton = children[0].language === "graphql" && graphqlPlayground ? /* @__PURE__ */ jsx(Box, {
|
|
30
|
+
component: "span",
|
|
31
|
+
paddingLeft: "small",
|
|
32
|
+
children: /* @__PURE__ */ jsx(GraphQLPlaygroundAction, {
|
|
33
|
+
graphqlPlayground,
|
|
34
|
+
query: children[0].code,
|
|
35
|
+
variables
|
|
36
|
+
})
|
|
37
|
+
}) : void 0;
|
|
38
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
39
|
+
space: "small",
|
|
40
|
+
children: [/* @__PURE__ */ jsx(ScrollableInline, {
|
|
41
|
+
whiteSpace: "nowrap",
|
|
42
|
+
children: /* @__PURE__ */ jsxs(Box, {
|
|
43
|
+
display: "flex",
|
|
44
|
+
justifyContent: "spaceBetween",
|
|
45
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
46
|
+
display: "flex",
|
|
47
|
+
children: children.map(({ label }, labelIndex) => label ? /* @__PURE__ */ jsx(Box, {
|
|
48
|
+
component: "span",
|
|
49
|
+
paddingLeft: labelIndex === 0 ? void 0 : "small",
|
|
50
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
51
|
+
size: "small",
|
|
52
|
+
tone: index.value === labelIndex ? "secondary" : void 0,
|
|
53
|
+
weight: "medium",
|
|
54
|
+
children: children.length === 1 || index.value === labelIndex ? label : /* @__PURE__ */ jsx(TextLinkButton, {
|
|
55
|
+
onClick: () => setIndex({
|
|
56
|
+
dirty: true,
|
|
57
|
+
value: labelIndex
|
|
58
|
+
}),
|
|
59
|
+
children: label
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}, label) : null)
|
|
63
|
+
}), /* @__PURE__ */ jsxs(Box, {
|
|
64
|
+
display: "flex",
|
|
65
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
66
|
+
component: "span",
|
|
67
|
+
paddingLeft: "small",
|
|
68
|
+
children: /* @__PURE__ */ jsx(CopyableText, {
|
|
69
|
+
size: "small",
|
|
70
|
+
children: child.code
|
|
71
|
+
})
|
|
72
|
+
}), graphqlPlaygroundButton]
|
|
73
|
+
})]
|
|
74
|
+
})
|
|
75
|
+
}), /* @__PURE__ */ jsx(CodeContainer, {
|
|
76
|
+
code: child.code,
|
|
77
|
+
language: child.language,
|
|
78
|
+
lineNumbers
|
|
79
|
+
})]
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
83
|
+
export { CodeBlock };
|