@stackone/malachite 2.96.0 → 2.98.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/COMPONENTS.md +2 -1
- package/dist/components/CodeBlock.js +161 -109
- package/dist/components/CodeBlock.js.map +1 -1
- package/dist/components/Timeline.js +103 -0
- package/dist/components/Timeline.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +354 -352
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -115,6 +115,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
115
115
|
- **`LevelMeter`** — Rising bars, shortest first, that picture how much of a scale is on — an access level in a level menu or on a level chip. Each step is `on` (a solid accent-green bar), `partial` (a green outline over a faint tint, for a step only some of whose actions are on) or `off` (an empty grey outline); every step keeps 3:1 against the surface, and colours come from the theme. Styled inline so it still draws inside an `ActionMenu`, which portals outside the shadow root and its stylesheet. Beside text that already names the level it is decorative and hidden from assistive tech; give it a `label` only when it stands alone and it reads as an image of that name. As an `ActionMenu` item `icon` or a `Button` `icon`, leave `label` off: the icon joins the item name, and the text already says the level. _Key props:_ `steps` (`LevelMeterStep[]`: `on` | `partial` | `off`), `label`, `className`.
|
|
116
116
|
- **`TimeBarChart`** — Counts per time bucket as stacked bars on a UTC axis, the request-volume chart above a log list. Every bucket in `range` takes a slot whether or not it has data, so gaps read as gaps; a zone-less time string is read as UTC. Hover or arrow-key through buckets for a tooltip listing every series and the total; `highlightTime` shades the bucket holding a time from elsewhere on the page, such as the hovered log row. With `onRangeSelect`, dragging across bars reports the whole buckets covered, `end` exclusive so it goes straight back in as `range`, and whether the selection takes in the last bucket. `loading` dims bars already drawn rather than replacing them, and shows a spinner only when there is nothing to dim. Series colours follow the theme’s status tokens by `tone`, and failures always stack above successes whatever order `series` comes in, so position separates them where colour alone might not; a legend names them unless `legend={false}`. A visually hidden table carries the same numbers for screen readers. _Key props:_ `series` (`{ key, label, tone }[]`, stacked by tone with `error` on top; `TimeBarChartTone`: `success` | `error` | `neutral`), `buckets` (`{ start, values }[]`), `interval` (`{ unit, step }`; `TimeBarChartUnit`: `minute` | `hour` | `day` | `week` | `month`), `range` (`end` exclusive, as a selection reports it; at most 2,000 buckets, the newest kept), `TimeBarChartSize` (`small` | `medium` | `large`), `loading`, `error`, `errorTitle`, `errorSubTitle`, `valueLabel`, `legend`, `highlightTime`, `onRangeSelect`, `aria-label`, `aria-labelledby`, `className`, `style`.
|
|
117
117
|
- **`TimeBarChartSwatch`** — The mark a `TimeBarChart` draws a series in, by its `tone`, for naming the series somewhere other than the chart's legend, such as a count beside the chart standing in for it. It matches the legend and the tooltip, and the bars draw the same colour at 40%; it follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
|
|
118
|
+
- **`Timeline`** — A vertical sequence of steps as an ordered list (`Timeline.Item`): a dot on a connecting line, a title, its timing at the right and a free-form body below, such as what happened to one API call. The dot is painted by `tone` from the theme’s text tokens (`neutral` is secondary text, the rest their status colours), or replaced by a decorative `marker` such as the caller’s logo. `stopped` puts an error badge (`stoppedLabel`, default "Stopped here") after the title of the step a flow ended on and paints its dot `error` unless a `tone` is set; the line ends at the last item. For steps a person works through (complete, open, locked) use `StepList`. _Key props:_ `aria-label`, `aria-labelledby`; on `Timeline.Item`: `title`, `time`, `tone` (`TimelineTone`: `neutral` | `info` | `success` | `warning` | `error`), `marker` (fills the 24px circle in place of the ringed dot), `stopped`, `stoppedLabel`.
|
|
118
119
|
- **`Table`** — Data table with columns, sizing, pagination and row selection. `column.align` places a column's header as well as its cells. What lands on the aligned edge is the last thing in the header row rather than the title: the sort caret on a sortable column, the info icon on one carrying `info` without a sorter. `headerVariant` picks the header layout, and only `inline` lines header and body up exactly, because both are cells of one `<table>`. `detached` builds them from flex rows, where a sortable header cell is 32px narrower than a non-sortable one — its padding sits on the inner button rather than on the flex item — so its header cells sit 15–17px off their column at any alignment; reach for `inline` where exact alignment matters. Sorting is internal, so the array passed as `data` is not the order rendered once a column is sorted: `onVisibleOrderChange` reports the rows in render order — the whole of `data`, compared by `rowKey` so an equal order never re-fires — for a consumer stepping a master-detail view the way the user sees it. On the detached header, `title`, `subtitle` and `extra` add a title row on the frame above the column headers, the row a `framed` `Card` draws, and it docks with them under `stickyHeaderTop` (with `showHeader={false}` nothing docks and it scrolls with the rows). The inline header has no frame, so it draws none of the three and warns in development. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition` (`pagination.position`, in antd naming: a pager on each edge named, aligned as named, 16px from the rows; bottom right by default), `headerVariant`, `title`, `subtitle`, `extra`, `onVisibleOrderChange`, `scrollHeight` (a height, or `"fill"` for the room left in its scroller once the content above and below it fits, so the page itself never scrolls).
|
|
119
120
|
- **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
|
|
120
121
|
- **`Avatar`** — Logo/initial avatar. Renders the image when available, otherwise a coloured tile with the first letter of `name`, or with `fallback="placeholder"` the generic "no logo available" tile. Encapsulates the fallback colour. _Key props:_ `src`, `name`, `size`, `shape="square" | "circle"`, `fallback="initial" | "placeholder"`.
|
|
@@ -123,7 +124,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
123
124
|
- **`UserIdentity`** — A person as a list or table shows them: their `Avatar`, their name, and their email beneath in secondary text. Without a name the email takes the first line and there is no second line; without either the line reads `-`. Both lines keep to one line and ellipsise in a narrow cell. The avatar is hidden from assistive tech, as the text already names the person. _Key props:_ `name`, `email`, `src`, `size` (`small` | `medium`).
|
|
124
125
|
- **`AppLogo`** — A connector's mark, optionally with its name and version tag. Builds on `Avatar`, so a missing or broken logo falls back to the generic "no logo available" placeholder, a neutral grey tile with a darker square, the same mark stackone-logos.com serves. The gap tightens below 18px so the mark and label still read as one unit. _Key props:_ `src`, `name`, `showName`, `size`, `nameSize`, `nameWeight`, `version`, `truncate`, `className`.
|
|
125
126
|
- **`ConnectionHeader`** — Two tilted logo tiles (from → to) showing a connection between apps. _Key props:_ `from`, `to` (`ConnectionEndpoint`: `icon`, `label`, `background`).
|
|
126
|
-
- **`CodeBlock`** — Syntax-styled code block. _Key props:_ `code`.
|
|
127
|
+
- **`CodeBlock`** — Syntax-styled code block, a JSON tree, or a diff. A `json` tree folds by depth with `collapsed`; `collapseLargerThan` also starts any nested array or object with more entries than the limit collapsed at any depth, so a large payload mounts a row per node rather than per item; a node over the limit gets a keyboard toggle named by its path and size, and a folded one says how many entries it holds. _Key props:_ `code`, `json`, `language` (`yaml` | `cedar`), `collapsed`, `collapseLargerThan`, `diff`, `showLineNumbers`, `wrapLines`, `enableCopy`, `height`, `aria-label`, `aria-labelledby`.
|
|
127
128
|
- **`Stepper`** — Progress dots/segments for a multi-step flow; optionally clickable. `groups` takes a long flow in labelled sections: the active step’s group opens into one bar per step across the full width and every other group folds to a short bar. Folded bars keep a fixed width and the open group shares what is left, so allow about 20px per other group and 12px per step in the open group. With `onChange` each folded bar is a button named after its group. _Key props:_ `steps` or `groups` (`{ label, steps }[]`), `active`, `onChange`.
|
|
128
129
|
- **`Swatch`** — Colour swatch preview.
|
|
129
130
|
|
|
@@ -1,115 +1,154 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { diffHunks as
|
|
7
|
-
import { CodeLine as
|
|
8
|
-
import { rowsWrapperStyle as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
1
|
+
import { jsxs as x, jsx as r, Fragment as P } from "react/jsx-runtime";
|
|
2
|
+
import v from "@uiw/react-json-view";
|
|
3
|
+
import A from "react";
|
|
4
|
+
import q from "./CustomIcons/CheckmarkIcon.js";
|
|
5
|
+
import J from "./CustomIcons/CopyIcon.js";
|
|
6
|
+
import { diffHunks as W } from "./codeBlockDiff.js";
|
|
7
|
+
import { CodeLine as V } from "./codeBlockLine.js";
|
|
8
|
+
import { rowsWrapperStyle as Q } from "./codeBlockStyles.js";
|
|
9
|
+
import { devWarning as X } from "./devWarning.js";
|
|
10
|
+
import { FOCUS_RING_INSET as Y, FOCUS_RING as z } from "./focusRing.js";
|
|
11
|
+
import { useClipboardCopy as Z } from "./useClipboardCopy.js";
|
|
12
|
+
const $ = (e, o) => (t, { type: c }) => c === "value" ? /* @__PURE__ */ r("span", { ...t, style: { ...t.style, color: `var(--w-rjv-type-${o}-color)` }, children: e }) : null, B = (e) => e !== null && typeof e == "object" ? Object.keys(e).length : 0, I = (e, o, t) => t.length > 0 && B(o) > e, E = (e) => {
|
|
13
|
+
const o = B(e);
|
|
14
|
+
return `${o} ${o === 1 ? "item" : "items"}`;
|
|
15
|
+
}, L = (e) => e.map((o) => String(o) || '""').join("."), ee = (e) => (o, { value: t, keys: c }) => o || I(e, t, c), oe = (e) => (o, { value: t, keys: c }) => {
|
|
16
|
+
var m;
|
|
17
|
+
if (!I(e, t, c ?? []))
|
|
18
|
+
return null;
|
|
19
|
+
const k = String(((m = o.style) == null ? void 0 : m.transform) ?? "").includes("-90");
|
|
20
|
+
return /* @__PURE__ */ r(
|
|
21
|
+
"button",
|
|
22
|
+
{
|
|
23
|
+
type: "button",
|
|
24
|
+
"aria-expanded": !k,
|
|
25
|
+
"aria-label": `${L(c ?? [])}, ${E(t)}`,
|
|
26
|
+
className: `${o.className ?? ""} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${z}`,
|
|
27
|
+
style: o.style,
|
|
28
|
+
children: o.children
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}, re = (e) => (
|
|
32
|
+
// This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.
|
|
33
|
+
(o, { value: t, keyName: c }) => Reflect.get(o, "data-expanded") && I(e, t, c === void 0 ? [] : [c]) ? (
|
|
34
|
+
// Its toggle already names the size, so this would say it twice.
|
|
35
|
+
/* @__PURE__ */ r(
|
|
36
|
+
"span",
|
|
37
|
+
{
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
className: `${Reflect.get(o, "className") ?? ""} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`,
|
|
40
|
+
children: `… ${E(t)}`
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
) : null
|
|
44
|
+
), T = A.lazy(() => import("./CodeBlockHighlighter.js")), te = {
|
|
12
45
|
added: "var(--malachite-codeblock-diff-added-background)",
|
|
13
46
|
removed: "var(--malachite-codeblock-diff-removed-background)",
|
|
14
47
|
context: void 0
|
|
15
|
-
},
|
|
48
|
+
}, ce = {
|
|
16
49
|
added: "+",
|
|
17
50
|
removed: "-",
|
|
18
51
|
context: void 0
|
|
19
|
-
},
|
|
52
|
+
}, le = {
|
|
20
53
|
added: "var(--malachite-codeblock-diff-assistant-background)",
|
|
21
54
|
removed: "var(--malachite-codeblock-diff-assistant-removed-background)",
|
|
22
55
|
context: void 0
|
|
23
|
-
},
|
|
56
|
+
}, ae = {
|
|
24
57
|
added: "✦",
|
|
25
58
|
// U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.
|
|
26
59
|
removed: "−",
|
|
27
60
|
context: "·"
|
|
28
|
-
},
|
|
61
|
+
}, ne = {
|
|
29
62
|
added: "var(--malachite-codeblock-diff-assistant-foreground)",
|
|
30
63
|
removed: "var(--malachite-codeblock-diff-removed-foreground)",
|
|
31
64
|
context: "var(--malachite-codeblock-diff-context-foreground)"
|
|
32
|
-
},
|
|
33
|
-
const
|
|
65
|
+
}, de = (e) => `⋯ ${e} unchanged ${e === 1 ? "line" : "lines"}`, ie = (e, o, t) => {
|
|
66
|
+
const c = t === "assistant";
|
|
34
67
|
return {
|
|
35
|
-
background:
|
|
36
|
-
marker:
|
|
37
|
-
markerColor:
|
|
68
|
+
background: c ? le[e.type] : te[e.type],
|
|
69
|
+
marker: c ? ae[e.type] : ce[e.type],
|
|
70
|
+
markerColor: c ? ne[e.type] : void 0,
|
|
38
71
|
// Reserved on unchanged rows too, so the code column does not step in and out.
|
|
39
72
|
reserveMarker: !0,
|
|
40
73
|
// Context rows read as de-emphasised, not just unmarked, in the assistant palette.
|
|
41
|
-
textColor:
|
|
42
|
-
strikethrough:
|
|
43
|
-
separatorAbove: e.skippedAbove === void 0 ? void 0 :
|
|
74
|
+
textColor: c && e.type === "context" ? "var(--malachite-codeblock-diff-context-text)" : void 0,
|
|
75
|
+
strikethrough: c && e.type === "removed",
|
|
76
|
+
separatorAbove: e.skippedAbove === void 0 ? void 0 : de(e.skippedAbove),
|
|
44
77
|
// A removed line has no number in the after-text, so it keeps the one it had before.
|
|
45
|
-
lineNumber:
|
|
78
|
+
lineNumber: o ? e.afterNumber ?? e.beforeNumber : void 0
|
|
46
79
|
};
|
|
47
|
-
},
|
|
80
|
+
}, je = ({
|
|
48
81
|
code: e,
|
|
49
|
-
json:
|
|
50
|
-
showLineNumbers:
|
|
51
|
-
className:
|
|
52
|
-
style:
|
|
53
|
-
height:
|
|
54
|
-
enableCopy:
|
|
55
|
-
wrapLines:
|
|
56
|
-
language:
|
|
57
|
-
collapsed:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"aria-
|
|
82
|
+
json: o,
|
|
83
|
+
showLineNumbers: t = !0,
|
|
84
|
+
className: c = "",
|
|
85
|
+
style: k = {},
|
|
86
|
+
height: m,
|
|
87
|
+
enableCopy: C = !0,
|
|
88
|
+
wrapLines: h = !1,
|
|
89
|
+
language: p,
|
|
90
|
+
collapsed: K = !1,
|
|
91
|
+
collapseLargerThan: a,
|
|
92
|
+
diff: n,
|
|
93
|
+
"aria-label": O,
|
|
94
|
+
"aria-labelledby": R
|
|
61
95
|
}) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
96
|
+
const d = a !== void 0 && Number.isInteger(a) && a >= 0 ? a : void 0;
|
|
97
|
+
a !== void 0 && d === void 0 && X(
|
|
98
|
+
`CodeBlock.collapseLargerThan:${a}`,
|
|
99
|
+
`CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${a} is ignored.`
|
|
100
|
+
);
|
|
101
|
+
const l = n ? W(n.before, n.after, n.context) : null, f = (l == null ? void 0 : l.map((s) => s.text).join(`
|
|
102
|
+
`)) ?? "", y = (() => {
|
|
64
103
|
if (l)
|
|
65
|
-
return
|
|
104
|
+
return f;
|
|
66
105
|
if (e)
|
|
67
106
|
return e;
|
|
68
|
-
if (
|
|
107
|
+
if (o !== void 0)
|
|
69
108
|
try {
|
|
70
|
-
return JSON.stringify(
|
|
109
|
+
return JSON.stringify(o, null, 2);
|
|
71
110
|
} catch {
|
|
72
111
|
return;
|
|
73
112
|
}
|
|
74
|
-
})(), { outcome:
|
|
75
|
-
/* @__PURE__ */
|
|
113
|
+
})(), { outcome: U, copy: G } = Z(y), F = U === "copied", _ = C && y !== void 0 && /* @__PURE__ */ x(P, { children: [
|
|
114
|
+
/* @__PURE__ */ r(
|
|
76
115
|
"button",
|
|
77
116
|
{
|
|
78
117
|
type: "button",
|
|
79
118
|
"aria-label": "Copy",
|
|
80
119
|
onClick: () => {
|
|
81
|
-
|
|
120
|
+
y !== void 0 && G(y);
|
|
82
121
|
},
|
|
83
|
-
className: `absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${
|
|
122
|
+
className: `absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${z}`,
|
|
84
123
|
style: { color: "var(--malachite-codeblock-line-number)" },
|
|
85
|
-
children:
|
|
124
|
+
children: F ? /* @__PURE__ */ r(q, { size: 14 }) : /* @__PURE__ */ r(J, { size: 14 })
|
|
86
125
|
}
|
|
87
126
|
),
|
|
88
|
-
/* @__PURE__ */
|
|
89
|
-
] }),
|
|
127
|
+
/* @__PURE__ */ r("span", { "aria-live": "polite", className: "sr-only", children: F ? "Copied to clipboard" : "" })
|
|
128
|
+
] }), b = {
|
|
90
129
|
role: "region",
|
|
91
|
-
"aria-label":
|
|
92
|
-
"aria-labelledby":
|
|
130
|
+
"aria-label": R ? O : O ?? "Code",
|
|
131
|
+
"aria-labelledby": R,
|
|
93
132
|
tabIndex: 0,
|
|
94
|
-
className: `box-border h-full overflow-auto ${
|
|
133
|
+
className: `box-border h-full overflow-auto ${Y}`
|
|
95
134
|
};
|
|
96
|
-
if (
|
|
97
|
-
return /* @__PURE__ */
|
|
135
|
+
if (o && !l)
|
|
136
|
+
return /* @__PURE__ */ x(
|
|
98
137
|
"div",
|
|
99
138
|
{
|
|
100
|
-
className: `relative border border-solid rounded-lg overflow-hidden ${
|
|
139
|
+
className: `relative border border-solid rounded-lg overflow-hidden ${c}`,
|
|
101
140
|
style: {
|
|
102
141
|
backgroundColor: "var(--malachite-codeblock-background)",
|
|
103
142
|
borderColor: "var(--malachite-codeblock-border)",
|
|
104
|
-
height:
|
|
105
|
-
...
|
|
143
|
+
height: m,
|
|
144
|
+
...k
|
|
106
145
|
},
|
|
107
146
|
children: [
|
|
108
147
|
_,
|
|
109
|
-
/* @__PURE__ */
|
|
110
|
-
|
|
148
|
+
/* @__PURE__ */ r("div", { ...b, children: /* @__PURE__ */ x(
|
|
149
|
+
v,
|
|
111
150
|
{
|
|
112
|
-
value:
|
|
151
|
+
value: o,
|
|
113
152
|
style: {
|
|
114
153
|
backgroundColor: "var(--malachite-codeblock-background)",
|
|
115
154
|
color: "var(--malachite-codeblock-foreground)",
|
|
@@ -145,47 +184,60 @@ const w = (e, a) => (c, { type: r }) => r === "value" ? /* @__PURE__ */ o("span"
|
|
|
145
184
|
"--w-rjv-type-undefined-color": "var(--malachite-codeblock-keyword)"
|
|
146
185
|
},
|
|
147
186
|
displayDataTypes: !1,
|
|
148
|
-
enableClipboard:
|
|
149
|
-
collapsed:
|
|
187
|
+
enableClipboard: C,
|
|
188
|
+
collapsed: K,
|
|
189
|
+
shouldExpandNodeInitially: d === void 0 ? void 0 : ee(d),
|
|
150
190
|
displayObjectSize: !1,
|
|
151
191
|
children: [
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
/* @__PURE__ */
|
|
192
|
+
/* @__PURE__ */ r(v.Null, { render: $("null", "null") }),
|
|
193
|
+
/* @__PURE__ */ r(v.Undefined, { render: $("undefined", "undefined") }),
|
|
194
|
+
/* @__PURE__ */ r(v.Nan, { render: $("NaN", "nan") }),
|
|
195
|
+
/* @__PURE__ */ r(
|
|
196
|
+
v.Arrow,
|
|
197
|
+
{
|
|
198
|
+
render: d === void 0 ? void 0 : oe(d)
|
|
199
|
+
}
|
|
200
|
+
),
|
|
201
|
+
/* @__PURE__ */ r(
|
|
202
|
+
v.Ellipsis,
|
|
203
|
+
{
|
|
204
|
+
render: d === void 0 ? void 0 : re(d)
|
|
205
|
+
}
|
|
206
|
+
)
|
|
155
207
|
]
|
|
156
208
|
}
|
|
157
209
|
) })
|
|
158
210
|
]
|
|
159
211
|
}
|
|
160
212
|
);
|
|
161
|
-
const
|
|
162
|
-
const
|
|
213
|
+
const j = C && (!!e || !!l), N = (s, i) => {
|
|
214
|
+
const w = s.split(`
|
|
163
215
|
`);
|
|
164
|
-
return /* @__PURE__ */
|
|
216
|
+
return /* @__PURE__ */ r(
|
|
165
217
|
"div",
|
|
166
218
|
{
|
|
167
|
-
...
|
|
168
|
-
className: `${
|
|
169
|
-
style: { paddingRight:
|
|
170
|
-
children: /* @__PURE__ */
|
|
171
|
-
const
|
|
172
|
-
return /* @__PURE__ */
|
|
173
|
-
|
|
219
|
+
...b,
|
|
220
|
+
className: `${b.className} p-4 text-left`,
|
|
221
|
+
style: { paddingRight: j ? 44 : void 0 },
|
|
222
|
+
children: /* @__PURE__ */ r("div", { style: Q(h), children: w.map((u, S) => {
|
|
223
|
+
const g = i == null ? void 0 : i(S);
|
|
224
|
+
return /* @__PURE__ */ r(
|
|
225
|
+
V,
|
|
174
226
|
{
|
|
175
|
-
line:
|
|
176
|
-
lineNumber: (
|
|
177
|
-
wrap:
|
|
178
|
-
decoration:
|
|
179
|
-
children:
|
|
227
|
+
line: u,
|
|
228
|
+
lineNumber: (g == null ? void 0 : g.lineNumber) ?? (t ? S + 1 : void 0),
|
|
229
|
+
wrap: h,
|
|
230
|
+
decoration: g,
|
|
231
|
+
children: u
|
|
180
232
|
},
|
|
181
|
-
|
|
233
|
+
S
|
|
182
234
|
);
|
|
183
235
|
}) })
|
|
184
236
|
}
|
|
185
237
|
);
|
|
186
|
-
},
|
|
187
|
-
if (
|
|
188
|
-
return /* @__PURE__ */
|
|
238
|
+
}, D = () => e ? N(e) : null, M = (s) => {
|
|
239
|
+
if (s.length === 0)
|
|
240
|
+
return /* @__PURE__ */ r(
|
|
189
241
|
"div",
|
|
190
242
|
{
|
|
191
243
|
className: "p-4 text-left",
|
|
@@ -193,51 +245,51 @@ const w = (e, a) => (c, { type: r }) => r === "value" ? /* @__PURE__ */ o("span"
|
|
|
193
245
|
children: "No changes"
|
|
194
246
|
}
|
|
195
247
|
);
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
return
|
|
248
|
+
const i = (w) => {
|
|
249
|
+
const u = s[w];
|
|
250
|
+
return u ? ie(u, t, n == null ? void 0 : n.origin) : void 0;
|
|
199
251
|
};
|
|
200
|
-
return
|
|
252
|
+
return p ? /* @__PURE__ */ r(A.Suspense, { fallback: N(f, i), children: /* @__PURE__ */ r(
|
|
201
253
|
T,
|
|
202
254
|
{
|
|
203
|
-
code:
|
|
204
|
-
language:
|
|
205
|
-
showLineNumbers:
|
|
206
|
-
wrapLines:
|
|
207
|
-
copyClearance:
|
|
208
|
-
decorate:
|
|
209
|
-
viewportProps:
|
|
255
|
+
code: f,
|
|
256
|
+
language: p,
|
|
257
|
+
showLineNumbers: t,
|
|
258
|
+
wrapLines: h,
|
|
259
|
+
copyClearance: j,
|
|
260
|
+
decorate: i,
|
|
261
|
+
viewportProps: b
|
|
210
262
|
}
|
|
211
|
-
) }) :
|
|
212
|
-
},
|
|
263
|
+
) }) : N(f, i);
|
|
264
|
+
}, H = () => e ? p ? /* @__PURE__ */ r(A.Suspense, { fallback: D(), children: /* @__PURE__ */ r(
|
|
213
265
|
T,
|
|
214
266
|
{
|
|
215
267
|
code: e,
|
|
216
|
-
language:
|
|
217
|
-
showLineNumbers:
|
|
218
|
-
wrapLines:
|
|
219
|
-
copyClearance:
|
|
220
|
-
viewportProps:
|
|
268
|
+
language: p,
|
|
269
|
+
showLineNumbers: t,
|
|
270
|
+
wrapLines: h,
|
|
271
|
+
copyClearance: j,
|
|
272
|
+
viewportProps: b
|
|
221
273
|
}
|
|
222
|
-
) }) :
|
|
223
|
-
return /* @__PURE__ */
|
|
274
|
+
) }) : D() : null;
|
|
275
|
+
return /* @__PURE__ */ x(
|
|
224
276
|
"div",
|
|
225
277
|
{
|
|
226
|
-
className: `relative border border-solid rounded-lg overflow-hidden ${
|
|
278
|
+
className: `relative border border-solid rounded-lg overflow-hidden ${c}`,
|
|
227
279
|
style: {
|
|
228
280
|
backgroundColor: "var(--malachite-codeblock-background)",
|
|
229
281
|
borderColor: "var(--malachite-codeblock-border)",
|
|
230
|
-
height:
|
|
231
|
-
...
|
|
282
|
+
height: m,
|
|
283
|
+
...k
|
|
232
284
|
},
|
|
233
285
|
children: [
|
|
234
286
|
_,
|
|
235
|
-
l ?
|
|
287
|
+
l ? M(l) : H()
|
|
236
288
|
]
|
|
237
289
|
}
|
|
238
290
|
);
|
|
239
291
|
};
|
|
240
292
|
export {
|
|
241
|
-
|
|
293
|
+
je as default
|
|
242
294
|
};
|
|
243
295
|
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.js","sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import JsonView from '@uiw/react-json-view';\nimport React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\nimport { useClipboardCopy } from './useClipboardCopy';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region by a visible label instead of `aria-label`. */\n 'aria-labelledby'?: string;\n}\n\nconst DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-added-background)',\n removed: 'var(--malachite-codeblock-diff-removed-background)',\n context: undefined,\n};\n\nconst DIFF_MARKERS: Record<DiffRowType, string | undefined> = {\n added: '+',\n removed: '-',\n context: undefined,\n};\n\n// The assistant palette also marks context rows, which the neutral one leaves bare.\nconst ASSISTANT_DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-assistant-background)',\n removed: 'var(--malachite-codeblock-diff-assistant-removed-background)',\n context: undefined,\n};\n\nconst ASSISTANT_DIFF_MARKERS: Record<DiffRowType, string> = {\n added: '\\u2726',\n // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.\n removed: '\\u2212',\n context: '\\u00b7',\n};\n\nconst ASSISTANT_DIFF_MARKER_COLORS: Record<DiffRowType, string> = {\n added: 'var(--malachite-codeblock-diff-assistant-foreground)',\n removed: 'var(--malachite-codeblock-diff-removed-foreground)',\n context: 'var(--malachite-codeblock-diff-context-foreground)',\n};\n\nconst unchangedRun = (count: number): string =>\n `\\u22ef ${count} unchanged ${count === 1 ? 'line' : 'lines'}`;\n\nconst diffDecoration = (\n row: DiffDisplayRow,\n showLineNumbers: boolean,\n origin?: 'assistant',\n): CodeLineDecoration => {\n const assistant = origin === 'assistant';\n\n return {\n background: assistant ? ASSISTANT_DIFF_BACKGROUNDS[row.type] : DIFF_BACKGROUNDS[row.type],\n marker: assistant ? ASSISTANT_DIFF_MARKERS[row.type] : DIFF_MARKERS[row.type],\n markerColor: assistant ? ASSISTANT_DIFF_MARKER_COLORS[row.type] : undefined,\n // Reserved on unchanged rows too, so the code column does not step in and out.\n reserveMarker: true,\n // Context rows read as de-emphasised, not just unmarked, in the assistant palette.\n textColor:\n assistant && row.type === 'context'\n ? 'var(--malachite-codeblock-diff-context-text)'\n : undefined,\n strikethrough: assistant && row.type === 'removed',\n separatorAbove: row.skippedAbove === undefined ? undefined : unchangedRun(row.skippedAbove),\n // A removed line has no number in the after-text, so it keeps the one it had before.\n lineNumber: showLineNumbers ? (row.afterNumber ?? row.beforeNumber) : undefined,\n };\n};\n\nconst CodeBlock: React.FC<CodeBlockProps> = ({\n code,\n json,\n showLineNumbers = true,\n className = '',\n style = {},\n height,\n enableCopy = true,\n wrapLines = false,\n language,\n collapsed = false,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const diffRows = diff ? diffHunks(diff.before, diff.after, diff.context) : null;\n const diffText = diffRows?.map((row) => row.text).join('\\n') ?? '';\n\n /**\n * What the button puts on the clipboard, in the same form the block is showing. A JSON\n * block is pretty-printed rather than handed over minified: the reader is copying what\n * they can see. `undefined` means there is nothing to copy and no button to offer.\n */\n const copyText = (): string | undefined => {\n if (diffRows) {\n return diffText;\n }\n\n // An empty block has nothing to copy, so it offers no button — `!== undefined` would\n // hand back the empty string and put a dead control on it.\n if (code) {\n return code;\n }\n\n if (json !== undefined) {\n try {\n return JSON.stringify(json, null, 2);\n } catch {\n // A cycle or a BigInt: no honest text to copy, so offer no button.\n return undefined;\n }\n }\n\n return undefined;\n };\n\n const textToCopy = copyText();\n\n const { outcome: copyOutcome, copy } = useClipboardCopy(textToCopy);\n const copied = copyOutcome === 'copied';\n\n const handleCopy = () => {\n if (textToCopy !== undefined) {\n void copy(textToCopy);\n }\n };\n\n // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <>\n <button\n type=\"button\"\n aria-label=\"Copy\"\n onClick={handleCopy}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n >\n {copied ? <CheckmarkIcon size={14} /> : <CopyIcon size={14} />}\n </button>\n {/* Not role=\"status\": one per block would collide with a page's own status queries. */}\n <span aria-live=\"polite\" className=\"sr-only\">\n {copied ? 'Copied to clipboard' : ''}\n </span>\n </>\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-copied-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-copied-success-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-quotes-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-int-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-float-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-bigint-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-boolean-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-date-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-url-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-null-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-nan-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-undefined-color':\n 'var(--malachite-codeblock-keyword)',\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","count","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapsed","diff","ariaLabel","ariaLabelledBy","diffRows","diffHunks","diffText","textToCopy","copyOutcome","copy","useClipboardCopy","copied","copyButton","jsxs","Fragment","FOCUS_RING","CheckmarkIcon","CopyIcon","viewportProps","FOCUS_RING_INSET","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;;AAeA,MAAMA,IACF,CAACC,GAAcC,MACf,CAACC,GAA8C,EAAE,MAAMC,EAAA,MACnDA,MAAS,UACL,gBAAAC,EAAC,QAAA,EAAM,GAAGF,GAAO,OAAO,EAAE,GAAGA,EAAM,OAAO,OAAO,oBAAoBD,CAAI,UAAA,GACpE,UAAAD,EAAA,CACL,IACA,MAENK,IAAuBC,EAAM,KAAK,MAAM,OAAO,2BAAwB,CAAC,GAmDxEC,IAA4D;AAAA,EAC9D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAwD;AAAA,EAC1D,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAGMC,IAAsE;AAAA,EACxE,OAAO;AAAA,EACP,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAsD;AAAA,EACxD,OAAO;AAAA;AAAA,EAEP,SAAS;AAAA,EACT,SAAS;A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AA/C;AAAA,MAACC;AAAA,MAAA;AAAA,QACG,MAAM6B;AAAA,QACN,UAAAP;AAAA,QACA,iBAAAX;AAAA,QACA,WAAAU;AAAA,QACA,eAAAuB;AAAA,QACA,UAAAE;AAAA,QACA,eAAAL;AAAA,MAAA;AAAA,IAAA,GAER,IAIDI,EAAiBhB,GAAUiB,CAAQ;AAAA,EAC9C,GAGMU,IAAoB,MACjBzC,IAIDO,sBAEKrB,EAAM,UAAN,EAAe,UAAUoD,KACtB,UAAA,gBAAAtD;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,MAAAe;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAuB;AAAA,MACA,eAAAH;AAAA,IAAA;AAAA,EAAA,GAER,IAIDY,EAAA,IAlBI;AAqBf,SACI,gBAAAjB;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DnB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAiB;AAAA,QACAR,IAAW2B,EAAW3B,CAAQ,IAAI6B,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
|
|
1
|
+
{"version":3,"file":"CodeBlock.js","sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import JsonView from '@uiw/react-json-view';\nimport React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { type DiffDisplayRow, type DiffRowType, diffHunks } from './codeBlockDiff';\nimport { CodeLine, type CodeLineDecoration } from './codeBlockLine';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\nimport { useClipboardCopy } from './useClipboardCopy';\n\n/**\n * The value side of a JSON literal that has no value of its own to print, in its type's\n * colour. These read as keywords, as `true` and `false` do: the comment grey is under AA\n * contrast on the light background.\n */\nconst renderLiteral =\n (text: string, type: 'null' | 'undefined' | 'nan') =>\n (props: React.HTMLAttributes<HTMLSpanElement>, { type: part }: { type: 'type' | 'value' }) =>\n part === 'value' ? (\n <span {...props} style={{ ...props.style, color: `var(--w-rjv-type-${type}-color)` }}>\n {text}\n </span>\n ) : null;\n\n/** A json node's own entries, as the library counts them to draw it. */\nconst entryCount = (value: unknown): number =>\n value !== null && typeof value === 'object' ? Object.keys(value).length : 0;\n\n/** A nested node over the limit: the only kind the limit folds, toggles and sizes. */\nconst isOverLimit = (limit: number, value: unknown, keys: readonly (number | string)[]): boolean =>\n keys.length > 0 && entryCount(value) > limit;\n\nconst sizeOf = (value: unknown): string => {\n const count = entryCount(value);\n return `${count} ${count === 1 ? 'item' : 'items'}`;\n};\n\n/** Where a node sits, so two toggles for nodes sharing a key read apart: `users.0.roles`. */\nconst pathOf = (keys: readonly (number | string)[]): string =>\n keys.map((key) => String(key) || '\"\"').join('.');\n\n// The library's flag is the inverse of its name: returning true starts the node collapsed.\nconst collapseNodesLargerThan =\n (limit: number) =>\n (\n isCollapsed: boolean,\n { value, keys }: { value?: unknown; keys: (number | string)[] },\n ): boolean =>\n isCollapsed || isOverLimit(limit, value, keys);\n\n// The row around the arrow owns the click and the arrow's rotation is its only state, so this\n// button is a keyboard toggle that reads `aria-expanded` from it.\nconst toggleArrowOver =\n (limit: number) =>\n (\n props: { className?: string; style?: React.CSSProperties; children?: React.ReactNode },\n { value, keys }: { value?: unknown; keys?: (number | string)[] },\n ) => {\n if (!isOverLimit(limit, value, keys ?? [])) {\n return null;\n }\n const collapsed = String(props.style?.transform ?? '').includes('-90');\n return (\n <button\n type=\"button\"\n aria-expanded={!collapsed}\n aria-label={`${pathOf(keys ?? [])}, ${sizeOf(value)}`}\n className={`${props.className ?? ''} inline-flex cursor-pointer items-center border-0 bg-transparent p-0 text-inherit ${FOCUS_RING}`}\n style={props.style}\n >\n {props.children}\n </button>\n );\n };\n\nconst foldedSizeOver =\n (limit: number) =>\n // This slot gets no `keys`; the root alone has no `keyName`, as the arrow's slot reads it.\n (props: object, { value, keyName }: { value?: unknown; keyName?: string | number }) =>\n Reflect.get(props, 'data-expanded') &&\n isOverLimit(limit, value, keyName === undefined ? [] : [keyName]) ? (\n // Its toggle already names the size, so this would say it twice.\n <span\n aria-hidden=\"true\"\n className={`${Reflect.get(props, 'className') ?? ''} mx-[4px] cursor-pointer select-none text-[var(--malachite-codeblock-foreground)]`}\n >\n {`\\u2026 ${sizeOf(value)}`}\n </span>\n ) : null;\n\nconst CodeBlockHighlighter = React.lazy(() => import('./CodeBlockHighlighter'));\n\nexport interface CodeBlockProps {\n /** The code content to display */\n code?: string;\n /** JSON object to display as formatted JSON */\n json?: object;\n /** Show line numbers */\n showLineNumbers?: boolean;\n /** Custom class name */\n className?: string;\n /** Custom styles */\n style?: React.CSSProperties;\n /** Height of the code block */\n height?: string | number;\n /** Enable copy functionality */\n enableCopy?: boolean;\n /** Wrap long lines instead of scrolling horizontally */\n wrapLines?: boolean;\n /**\n * Highlight the code with this language's grammar. `cedar` is a grammar this library\n * ships itself (`prismCedar.ts`), since Prism and refractor carry none; widen the union\n * as further grammars are registered in CodeBlockHighlighter.\n */\n language?: 'yaml' | 'cedar';\n /** How much of a `json` tree starts collapsed: `true` all of it, a number below that depth. */\n collapsed?: boolean | number;\n /**\n * Starts any nested node with more entries than this collapsed, at any depth, behind a keyboard\n * toggle naming its path and size; nodes within the limit keep the library's arrow. 0 or more.\n */\n collapseLargerThan?: number;\n /**\n * Renders the change between two texts rather than one text, and takes precedence over\n * `code` and `json`. Only the changed lines are shown, with `context` unchanged ones either\n * side, so a small edit to a long document reads as a few hunks instead of the whole thing.\n */\n diff?: {\n before: string;\n after: string;\n /** Unchanged lines kept either side of each change. Three by convention. */\n context?: number;\n /**\n * Swaps the `+`/`-` gutter and tinted rows for the palette a mock specified for\n * AI-authored changes: star, minus-sign and middle-dot markers, and a struck-through\n * removal. Omit to keep the neutral markers; there is no default consumer for the\n * assistant look yet.\n */\n origin?: 'assistant';\n };\n /** Names the scrollable region. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region by a visible label instead of `aria-label`. */\n 'aria-labelledby'?: string;\n}\n\nconst DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-added-background)',\n removed: 'var(--malachite-codeblock-diff-removed-background)',\n context: undefined,\n};\n\nconst DIFF_MARKERS: Record<DiffRowType, string | undefined> = {\n added: '+',\n removed: '-',\n context: undefined,\n};\n\n// The assistant palette also marks context rows, which the neutral one leaves bare.\nconst ASSISTANT_DIFF_BACKGROUNDS: Record<DiffRowType, string | undefined> = {\n added: 'var(--malachite-codeblock-diff-assistant-background)',\n removed: 'var(--malachite-codeblock-diff-assistant-removed-background)',\n context: undefined,\n};\n\nconst ASSISTANT_DIFF_MARKERS: Record<DiffRowType, string> = {\n added: '\\u2726',\n // U+2212 minus sign, not a hyphen: the mock is explicit about which glyph.\n removed: '\\u2212',\n context: '\\u00b7',\n};\n\nconst ASSISTANT_DIFF_MARKER_COLORS: Record<DiffRowType, string> = {\n added: 'var(--malachite-codeblock-diff-assistant-foreground)',\n removed: 'var(--malachite-codeblock-diff-removed-foreground)',\n context: 'var(--malachite-codeblock-diff-context-foreground)',\n};\n\nconst unchangedRun = (count: number): string =>\n `\\u22ef ${count} unchanged ${count === 1 ? 'line' : 'lines'}`;\n\nconst diffDecoration = (\n row: DiffDisplayRow,\n showLineNumbers: boolean,\n origin?: 'assistant',\n): CodeLineDecoration => {\n const assistant = origin === 'assistant';\n\n return {\n background: assistant ? ASSISTANT_DIFF_BACKGROUNDS[row.type] : DIFF_BACKGROUNDS[row.type],\n marker: assistant ? ASSISTANT_DIFF_MARKERS[row.type] : DIFF_MARKERS[row.type],\n markerColor: assistant ? ASSISTANT_DIFF_MARKER_COLORS[row.type] : undefined,\n // Reserved on unchanged rows too, so the code column does not step in and out.\n reserveMarker: true,\n // Context rows read as de-emphasised, not just unmarked, in the assistant palette.\n textColor:\n assistant && row.type === 'context'\n ? 'var(--malachite-codeblock-diff-context-text)'\n : undefined,\n strikethrough: assistant && row.type === 'removed',\n separatorAbove: row.skippedAbove === undefined ? undefined : unchangedRun(row.skippedAbove),\n // A removed line has no number in the after-text, so it keeps the one it had before.\n lineNumber: showLineNumbers ? (row.afterNumber ?? row.beforeNumber) : undefined,\n };\n};\n\nconst CodeBlock: React.FC<CodeBlockProps> = ({\n code,\n json,\n showLineNumbers = true,\n className = '',\n style = {},\n height,\n enableCopy = true,\n wrapLines = false,\n language,\n collapsed = false,\n collapseLargerThan,\n diff,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const limit =\n collapseLargerThan !== undefined &&\n Number.isInteger(collapseLargerThan) &&\n collapseLargerThan >= 0\n ? collapseLargerThan\n : undefined;\n if (collapseLargerThan !== undefined && limit === undefined) {\n devWarning(\n `CodeBlock.collapseLargerThan:${collapseLargerThan}`,\n `CodeBlock's collapseLargerThan takes a whole count of 0 or more; ${collapseLargerThan} is ignored.`,\n );\n }\n const diffRows = diff ? diffHunks(diff.before, diff.after, diff.context) : null;\n const diffText = diffRows?.map((row) => row.text).join('\\n') ?? '';\n\n /**\n * What the button puts on the clipboard, in the same form the block is showing. A JSON\n * block is pretty-printed rather than handed over minified: the reader is copying what\n * they can see. `undefined` means there is nothing to copy and no button to offer.\n */\n const copyText = (): string | undefined => {\n if (diffRows) {\n return diffText;\n }\n\n // An empty block has nothing to copy, so it offers no button — `!== undefined` would\n // hand back the empty string and put a dead control on it.\n if (code) {\n return code;\n }\n\n if (json !== undefined) {\n try {\n return JSON.stringify(json, null, 2);\n } catch {\n // A cycle or a BigInt: no honest text to copy, so offer no button.\n return undefined;\n }\n }\n\n return undefined;\n };\n\n const textToCopy = copyText();\n\n const { outcome: copyOutcome, copy } = useClipboardCopy(textToCopy);\n const copied = copyOutcome === 'copied';\n\n const handleCopy = () => {\n if (textToCopy !== undefined) {\n void copy(textToCopy);\n }\n };\n\n // Declared once and rendered by both the JSON branch and the code branch below, so the\n // two tabs of one document do not disagree about whether it can be copied.\n const copyButton = enableCopy && textToCopy !== undefined && (\n <>\n <button\n type=\"button\"\n aria-label=\"Copy\"\n onClick={handleCopy}\n className={`absolute top-2 right-2 z-10 flex items-center justify-center rounded-md border border-solid border-[var(--malachite-codeblock-border)] bg-[var(--malachite-codeblock-background)] p-1.5 transition-colors hover:bg-[var(--malachite-codeblock-border)] ${FOCUS_RING}`}\n style={{ color: 'var(--malachite-codeblock-line-number)' }}\n >\n {copied ? <CheckmarkIcon size={14} /> : <CopyIcon size={14} />}\n </button>\n {/* Not role=\"status\": one per block would collide with a page's own status queries. */}\n <span aria-live=\"polite\" className=\"sr-only\">\n {copied ? 'Copied to clipboard' : ''}\n </span>\n </>\n );\n\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n const viewportProps = {\n role: 'region',\n 'aria-label': ariaLabelledBy ? ariaLabel : (ariaLabel ?? 'Code'),\n 'aria-labelledby': ariaLabelledBy,\n tabIndex: 0,\n className: `box-border h-full overflow-auto ${FOCUS_RING_INSET}`,\n } satisfies React.HTMLAttributes<HTMLElement>;\n\n // If JSON is provided, use JsonView component\n if (json && !diffRows) {\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {/* The frame clips at `height`; this scrolls inside it, so the copy button stays put. */}\n <div {...viewportProps}>\n <JsonView\n value={json}\n style={\n {\n backgroundColor: 'var(--malachite-codeblock-background)',\n color: 'var(--malachite-codeblock-foreground)',\n fontSize: '14px',\n fontFamily: 'var(--malachite-font-mono, monospace)',\n padding: '16px',\n lineHeight: '1.5',\n textAlign: 'left',\n '--w-rjv-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-key-string': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-background-color': 'var(--malachite-codeblock-background)',\n '--w-rjv-line-color': 'var(--malachite-codeblock-border)',\n '--w-rjv-arrow-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-edit-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-info-color': 'var(--malachite-codeblock-line-number)',\n '--w-rjv-update-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-copied-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-copied-success-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-curlybraces-color':\n 'var(--malachite-codeblock-foreground)',\n '--w-rjv-colon-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-brackets-color': 'var(--malachite-codeblock-foreground)',\n '--w-rjv-quotes-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-quotes-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-string-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-int-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-float-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-bigint-color': 'var(--malachite-codeblock-number)',\n '--w-rjv-type-boolean-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-date-color': 'var(--malachite-codeblock-string)',\n '--w-rjv-type-url-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-null-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-nan-color': 'var(--malachite-codeblock-keyword)',\n '--w-rjv-type-undefined-color':\n 'var(--malachite-codeblock-keyword)',\n } as React.CSSProperties\n }\n displayDataTypes={false}\n enableClipboard={enableCopy}\n collapsed={collapsed}\n shouldExpandNodeInitially={\n limit === undefined ? undefined : collapseNodesLargerThan(limit)\n }\n displayObjectSize={false}\n >\n {/* The library draws these three only as their type label, which\n `displayDataTypes` turns off, so without a value of their own a\n `null` reads as a key with nothing after it. */}\n <JsonView.Null render={renderLiteral('null', 'null')} />\n <JsonView.Undefined render={renderLiteral('undefined', 'undefined')} />\n <JsonView.Nan render={renderLiteral('NaN', 'nan')} />\n {/* Mounted either way: the library keeps a slot's last render, so it is\n switched off by passing none rather than by unmounting. */}\n <JsonView.Arrow\n render={limit === undefined ? undefined : toggleArrowOver(limit)}\n />\n <JsonView.Ellipsis\n render={limit === undefined ? undefined : foldedSizeOver(limit)}\n />\n </JsonView>\n </div>\n </div>\n );\n }\n\n // Reserve clearance so a wide first line never sits under the floating copy button.\n const copyClearance = enableCopy && (!!code || !!diffRows);\n\n const renderPlainLines = (\n text: string,\n decorate?: (index: number) => CodeLineDecoration | undefined,\n ) => {\n const lines = text.split('\\n');\n\n return (\n <div\n {...viewportProps}\n className={`${viewportProps.className} p-4 text-left`}\n style={{ paddingRight: copyClearance ? 44 : undefined }}\n >\n <div style={rowsWrapperStyle(wrapLines)}>\n {lines.map((line, index) => {\n const decoration = decorate?.(index);\n\n return (\n <CodeLine\n key={index}\n line={line}\n lineNumber={\n decoration?.lineNumber ??\n (showLineNumbers ? index + 1 : undefined)\n }\n wrap={wrapLines}\n decoration={decoration}\n >\n {line}\n </CodeLine>\n );\n })}\n </div>\n </div>\n );\n };\n\n const renderPlainCode = () => (code ? renderPlainLines(code) : null);\n\n const renderDiff = (rows: DiffDisplayRow[]) => {\n if (rows.length === 0) {\n return (\n <div\n className=\"p-4 text-left\"\n style={{ color: 'var(--malachite-codeblock-comment)' }}\n >\n No changes\n </div>\n );\n }\n\n const decorate = (index: number) => {\n const row = rows[index];\n\n return row ? diffDecoration(row, showLineNumbers, diff?.origin) : undefined;\n };\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainLines(diffText, decorate)}>\n {/*\n * The whole merged text goes to the highlighter in one piece, so a hunk\n * is tokenised in the company of its neighbours rather than on its own.\n * Prism still cannot see the lines the hunks left out, so a construct\n * spanning an omitted run can highlight oddly — the reason `context`\n * defaults to a few lines rather than none.\n */}\n <CodeBlockHighlighter\n code={diffText}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n decorate={decorate}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainLines(diffText, decorate);\n };\n\n // For code strings, create a simple syntax-highlighted view\n const renderCodeContent = () => {\n if (!code) {\n return null;\n }\n\n if (language) {\n return (\n <React.Suspense fallback={renderPlainCode()}>\n <CodeBlockHighlighter\n code={code}\n language={language}\n showLineNumbers={showLineNumbers}\n wrapLines={wrapLines}\n copyClearance={copyClearance}\n viewportProps={viewportProps}\n />\n </React.Suspense>\n );\n }\n\n return renderPlainCode();\n };\n\n return (\n <div\n className={`relative border border-solid rounded-lg overflow-hidden ${className}`}\n style={{\n backgroundColor: 'var(--malachite-codeblock-background)',\n borderColor: 'var(--malachite-codeblock-border)',\n height,\n ...style,\n }}\n >\n {copyButton}\n {diffRows ? renderDiff(diffRows) : renderCodeContent()}\n </div>\n );\n};\n\nexport default CodeBlock;\n"],"names":["renderLiteral","text","type","props","part","jsx","entryCount","value","isOverLimit","limit","keys","sizeOf","count","pathOf","key","collapseNodesLargerThan","isCollapsed","toggleArrowOver","collapsed","_a","FOCUS_RING","foldedSizeOver","keyName","CodeBlockHighlighter","React","DIFF_BACKGROUNDS","DIFF_MARKERS","ASSISTANT_DIFF_BACKGROUNDS","ASSISTANT_DIFF_MARKERS","ASSISTANT_DIFF_MARKER_COLORS","unchangedRun","diffDecoration","row","showLineNumbers","origin","assistant","CodeBlock","code","json","className","style","height","enableCopy","wrapLines","language","collapseLargerThan","diff","ariaLabel","ariaLabelledBy","devWarning","diffRows","diffHunks","diffText","textToCopy","copyOutcome","copy","useClipboardCopy","copied","copyButton","jsxs","Fragment","CheckmarkIcon","CopyIcon","viewportProps","FOCUS_RING_INSET","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;;;AAgBA,MAAMA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