@stackone/malachite 2.108.1 → 2.110.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 +4 -4
- package/dist/components/CodeBlock.js +107 -115
- package/dist/components/CodeBlock.js.map +1 -1
- package/dist/components/CodePreview.js +75 -59
- package/dist/components/CodePreview.js.map +1 -1
- package/dist/components/ConfirmationDialog.js +58 -56
- package/dist/components/ConfirmationDialog.js.map +1 -1
- package/dist/components/CopyOverlayButton.js +31 -0
- package/dist/components/CopyOverlayButton.js.map +1 -0
- package/dist/components/Modal.js +39 -36
- package/dist/components/Modal.js.map +1 -1
- package/dist/components/SidePanel.js +193 -186
- package/dist/components/SidePanel.js.map +1 -1
- package/dist/components/SidePanelNavFooter.js +22 -20
- package/dist/components/SidePanelNavFooter.js.map +1 -1
- package/dist/components/SidePanelSheet.js +93 -0
- package/dist/components/SidePanelSheet.js.map +1 -0
- package/dist/components/SidePanelTitle.js +16 -0
- package/dist/components/SidePanelTitle.js.map +1 -0
- package/dist/components/TabStrip.js +42 -37
- package/dist/components/TabStrip.js.map +1 -1
- package/dist/components/Tabs.js.map +1 -1
- package/dist/components/portalOverlay.js.map +1 -1
- package/dist/components/useClipboardCopy.js +24 -21
- package/dist/components/useClipboardCopy.js.map +1 -1
- package/dist/index.d.ts +46 -1
- package/dist/tailwind.css.js +1 -1
- package/dist/theme.js +9 -3
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,98 +1,104 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { jsxs as o, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { useState as L, useId as v, useMemo as E } from "react";
|
|
3
|
+
import M from "./CopyOverlayButton.js";
|
|
4
|
+
import j from "./CustomIcons/CaretDownIcon.js";
|
|
5
|
+
import i from "./Typography/Text.js";
|
|
6
|
+
import { rowsWrapperStyle as U } from "./codeBlockStyles.js";
|
|
7
|
+
import { FOCUS_RING_INSET as I, FOCUS_RING as W } from "./focusRing.js";
|
|
8
|
+
import { isRenderableNode as B } from "./renderableNode.js";
|
|
9
|
+
import { canCopyToClipboard as G } from "./useClipboardCopy.js";
|
|
10
|
+
const w = 5, C = 2e3, H = 360, S = "var(--malachite-card-border,rgb(232,232,232))", $ = "var(--malachite-card-subtle-divider,rgb(241,241,241))", P = (e) => e === "" ? [] : e.replace(/\r?\n$/, "").split(/\r\n|\r|\n/), _ = (e, l) => !Number.isNaN(e) && e >= 1 ? Math.floor(e) : l, V = (e) => e ? "flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]" : "flex border-0 border-s-[3px] border-solid border-transparent", X = (e, l, c) => {
|
|
9
11
|
if (e)
|
|
10
12
|
return "Show Less";
|
|
11
|
-
const
|
|
12
|
-
return `Show All ${
|
|
13
|
-
},
|
|
13
|
+
const s = c > 0 ? ` · ${c} flagged` : "";
|
|
14
|
+
return `Show All ${l} Lines${s}`;
|
|
15
|
+
}, te = ({
|
|
14
16
|
title: e,
|
|
15
|
-
meta:
|
|
17
|
+
meta: l,
|
|
18
|
+
titleHidden: c = !1,
|
|
16
19
|
code: s,
|
|
17
|
-
previewLines:
|
|
20
|
+
previewLines: k = w,
|
|
18
21
|
highlightLines: f = [],
|
|
19
|
-
showLineNumbers:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
showLineNumbers: d = !0,
|
|
23
|
+
copyable: z = !1,
|
|
24
|
+
maxRenderedLines: D = C,
|
|
25
|
+
className: R = ""
|
|
22
26
|
}) => {
|
|
23
|
-
const [
|
|
27
|
+
const [p, O] = L(!1), y = z && G(), m = v(), u = v(), a = E(() => P(s), [s]), b = E(
|
|
24
28
|
() => new Set(
|
|
25
29
|
f.filter(
|
|
26
30
|
(t) => Number.isInteger(t) && t >= 1 && t <= a.length
|
|
27
31
|
)
|
|
28
32
|
),
|
|
29
33
|
[f, a.length]
|
|
30
|
-
), x =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
),
|
|
34
|
-
return /* @__PURE__ */
|
|
34
|
+
), x = _(k, w), N = a.length > x, h = p || !N, g = Math.min(
|
|
35
|
+
h ? a.length : x,
|
|
36
|
+
_(D, C)
|
|
37
|
+
), T = a.slice(0, g), A = [...b].filter((t) => t > x).length, F = `max(40px, calc(${String(a.length).length}ch + 14px))`;
|
|
38
|
+
return /* @__PURE__ */ o(
|
|
35
39
|
"div",
|
|
36
40
|
{
|
|
37
|
-
className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${
|
|
38
|
-
style: { borderColor:
|
|
41
|
+
className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${R}`,
|
|
42
|
+
style: { borderColor: S },
|
|
39
43
|
children: [
|
|
40
|
-
/* @__PURE__ */
|
|
44
|
+
c ? /* @__PURE__ */ r("span", { id: m, className: "sr-only", children: e }) : /* @__PURE__ */ o(
|
|
41
45
|
"div",
|
|
42
46
|
{
|
|
43
47
|
className: "flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]",
|
|
44
|
-
style: { borderColor:
|
|
48
|
+
style: { borderColor: $ },
|
|
45
49
|
children: [
|
|
46
|
-
/* @__PURE__ */ r("span", { id:
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
/* @__PURE__ */ r("span", { id: m, className: "flex min-w-0", children: /* @__PURE__ */ r(i, { size: "xsmall", color: "secondary", fontWeight: "semi-bold", children: e }) }),
|
|
51
|
+
B(l) && /* @__PURE__ */ r(
|
|
52
|
+
i,
|
|
49
53
|
{
|
|
50
54
|
size: "xsmall",
|
|
51
55
|
color: "secondary",
|
|
52
56
|
font: "mono",
|
|
53
57
|
wrap: !1,
|
|
54
58
|
className: "truncate",
|
|
55
|
-
children:
|
|
59
|
+
children: l
|
|
56
60
|
}
|
|
57
61
|
)
|
|
58
62
|
]
|
|
59
63
|
}
|
|
60
64
|
),
|
|
61
|
-
a.length === 0 ? /* @__PURE__ */ r(
|
|
62
|
-
// Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.
|
|
65
|
+
a.length === 0 ? /* @__PURE__ */ r(i, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] py-[8px]", children: "Empty" }) : /* @__PURE__ */ o("div", { className: "relative", children: [
|
|
63
66
|
/* @__PURE__ */ r(
|
|
64
67
|
"pre",
|
|
65
68
|
{
|
|
66
69
|
id: u,
|
|
67
70
|
role: "region",
|
|
68
|
-
"aria-labelledby":
|
|
71
|
+
"aria-labelledby": m,
|
|
69
72
|
tabIndex: 0,
|
|
70
|
-
className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${
|
|
71
|
-
style: {
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${d ? "py-[6px] leading-[14px]" : "py-[10px] leading-[1.65]"} text-[var(--malachite-text-primary,rgb(10,10,10))] ${I}`,
|
|
74
|
+
style: {
|
|
75
|
+
maxHeight: H,
|
|
76
|
+
paddingInlineEnd: y ? 40 : void 0
|
|
77
|
+
},
|
|
78
|
+
children: /* @__PURE__ */ o("span", { className: "block", style: U(!1), children: [
|
|
79
|
+
T.map((t, n) => (
|
|
74
80
|
// A line's position is its identity: its text can repeat.
|
|
75
|
-
/* @__PURE__ */
|
|
81
|
+
/* @__PURE__ */ o(
|
|
76
82
|
"span",
|
|
77
83
|
{
|
|
78
|
-
"data-flagged":
|
|
79
|
-
className:
|
|
84
|
+
"data-flagged": b.has(n + 1) || void 0,
|
|
85
|
+
className: V(b.has(n + 1)),
|
|
80
86
|
children: [
|
|
81
|
-
|
|
87
|
+
d && /* @__PURE__ */ r(
|
|
82
88
|
"span",
|
|
83
89
|
{
|
|
84
90
|
"aria-hidden": "true",
|
|
85
91
|
className: "flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]",
|
|
86
|
-
style: { width:
|
|
92
|
+
style: { width: F },
|
|
87
93
|
children: n + 1
|
|
88
94
|
}
|
|
89
95
|
),
|
|
90
|
-
/* @__PURE__ */
|
|
96
|
+
/* @__PURE__ */ o(
|
|
91
97
|
"span",
|
|
92
98
|
{
|
|
93
|
-
className: `min-w-0 whitespace-pre ${
|
|
99
|
+
className: `min-w-0 whitespace-pre ${d ? "" : "px-[11px]"}`,
|
|
94
100
|
children: [
|
|
95
|
-
|
|
101
|
+
b.has(n + 1) && /* @__PURE__ */ r("span", { className: "sr-only select-none", children: "Flagged: " }),
|
|
96
102
|
t || " "
|
|
97
103
|
]
|
|
98
104
|
}
|
|
@@ -102,30 +108,40 @@ const w = 5, I = 2e3, T = 360, F = "var(--malachite-card-border,rgb(232,232,232)
|
|
|
102
108
|
n
|
|
103
109
|
)
|
|
104
110
|
)),
|
|
105
|
-
!
|
|
111
|
+
!h && !d && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "block select-none px-[14px]", children: "…" })
|
|
106
112
|
] })
|
|
107
113
|
}
|
|
114
|
+
),
|
|
115
|
+
y && /* @__PURE__ */ r(
|
|
116
|
+
M,
|
|
117
|
+
{
|
|
118
|
+
text: s,
|
|
119
|
+
"aria-label": `Copy ${e}`,
|
|
120
|
+
iconSize: 12,
|
|
121
|
+
className: `absolute end-[6px] top-[6px] z-[1] flex cursor-pointer items-center justify-center rounded-md border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] p-[5px] text-[var(--malachite-text-secondary,rgb(115,115,115))] hover:text-[var(--malachite-text-primary,rgb(10,10,10))] ${W}`,
|
|
122
|
+
style: { borderColor: S }
|
|
123
|
+
}
|
|
108
124
|
)
|
|
109
|
-
),
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
] }),
|
|
126
|
+
h && g < a.length && /* @__PURE__ */ r(i, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] pb-[8px]", children: `Showing the first ${g.toLocaleString()} of ${a.length.toLocaleString()} lines.` }),
|
|
127
|
+
N && /* @__PURE__ */ o(
|
|
112
128
|
"button",
|
|
113
129
|
{
|
|
114
130
|
type: "button",
|
|
115
|
-
"aria-expanded":
|
|
131
|
+
"aria-expanded": p,
|
|
116
132
|
"aria-controls": u,
|
|
117
|
-
"aria-describedby":
|
|
118
|
-
onClick: () =>
|
|
119
|
-
className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${
|
|
120
|
-
style: { borderColor:
|
|
133
|
+
"aria-describedby": m,
|
|
134
|
+
onClick: () => O((t) => !t),
|
|
135
|
+
className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${I}`,
|
|
136
|
+
style: { borderColor: $ },
|
|
121
137
|
children: [
|
|
122
|
-
/* @__PURE__ */ r(
|
|
138
|
+
/* @__PURE__ */ r(i, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", children: X(p, a.length, A) }),
|
|
123
139
|
/* @__PURE__ */ r("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ r(
|
|
124
|
-
|
|
140
|
+
j,
|
|
125
141
|
{
|
|
126
142
|
size: 12,
|
|
127
143
|
className: "transition-transform",
|
|
128
|
-
style: { transform:
|
|
144
|
+
style: { transform: p ? "rotate(180deg)" : void 0 }
|
|
129
145
|
}
|
|
130
146
|
) })
|
|
131
147
|
]
|
|
@@ -136,7 +152,7 @@ const w = 5, I = 2e3, T = 360, F = "var(--malachite-card-border,rgb(232,232,232)
|
|
|
136
152
|
);
|
|
137
153
|
};
|
|
138
154
|
export {
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
te as CodePreview,
|
|
156
|
+
te as default
|
|
141
157
|
};
|
|
142
158
|
//# sourceMappingURL=CodePreview.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodePreview.js","sources":["../../src/components/CodePreview.tsx"],"sourcesContent":["import type React from 'react';\nimport { useId, useMemo, useState } from 'react';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport Text from './Typography/Text';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\n\nexport interface CodePreviewProps {\n /** Names the payload in the header and its body and toggle for assistive tech, e.g. `Request`. */\n title: string;\n /** At the right of the header in the mono face, e.g. `POST · acc_8f2…`. */\n meta?: React.ReactNode;\n code: string;\n /** How many lines show until the reader asks for all of them. `Infinity` shows them all. */\n previewLines?: number;\n /** 1-based line numbers to flag, such as the fields a scanner caught. Colour alone, so say why nearby. */\n highlightLines?: readonly number[];\n showLineNumbers?: boolean;\n /** The most lines the expanded body mounts; past it a note says how many are not shown. */\n maxRenderedLines?: number;\n className?: string;\n}\n\nconst DEFAULT_PREVIEW_LINES = 5;\nconst DEFAULT_MAX_RENDERED_LINES = 2000;\n\n// Past this the body scrolls, folded or open, so a long preview never crowds out what is around it.\nconst MAX_BODY_HEIGHT = 360;\n\nconst BORDER = 'var(--malachite-card-border,rgb(232,232,232))';\nconst DIVIDER = 'var(--malachite-card-subtle-divider,rgb(241,241,241))';\n\n// Any line ending, and no empty last line for a trailing newline.\nconst linesOf = (code: string): string[] =>\n code === '' ? [] : code.replace(/\\r?\\n$/, '').split(/\\r\\n|\\r|\\n/);\n\nconst countOf = (value: number, fallback: number): number =>\n !Number.isNaN(value) && value >= 1 ? Math.floor(value) : fallback;\n\nconst lineClasses = (flagged: boolean): string =>\n flagged\n ? 'flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]'\n : 'flex border-0 border-s-[3px] border-solid border-transparent';\n\nconst toggleLabel = (expanded: boolean, total: number, hiddenFlags: number): string => {\n if (expanded) {\n return 'Show Less';\n }\n const flags = hiddenFlags > 0 ? ` · ${hiddenFlags} flagged` : '';\n return `Show All ${total} Lines${flags}`;\n};\n\n/**\n * A framed payload: a header naming it, its first lines, and a toggle for the rest. For the raw\n * request or response under a step of a trace, where the whole body would crowd out the steps.\n */\nconst CodePreview: React.FC<CodePreviewProps> = ({\n title,\n meta,\n code,\n previewLines = DEFAULT_PREVIEW_LINES,\n highlightLines = [],\n showLineNumbers = true,\n maxRenderedLines = DEFAULT_MAX_RENDERED_LINES,\n className = '',\n}) => {\n const [expanded, setExpanded] = useState(false);\n const titleId = useId();\n const bodyId = useId();\n const lines = useMemo(() => linesOf(code), [code]);\n const flagged = useMemo(\n () =>\n new Set(\n highlightLines.filter(\n (line) => Number.isInteger(line) && line >= 1 && line <= lines.length,\n ),\n ),\n [highlightLines, lines.length],\n );\n const limit = countOf(previewLines, DEFAULT_PREVIEW_LINES);\n const foldable = lines.length > limit;\n const open = expanded || !foldable;\n const rendered = Math.min(\n open ? lines.length : limit,\n countOf(maxRenderedLines, DEFAULT_MAX_RENDERED_LINES),\n );\n const shown = lines.slice(0, rendered);\n const hiddenFlags = [...flagged].filter((line) => line > limit).length;\n // 40px as designed, wider only when the last line's number would crowd the code.\n const gutter = `max(40px, calc(${String(lines.length).length}ch + 14px))`;\n return (\n <div\n className={`overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${className}`}\n style={{ borderColor: BORDER }}\n >\n <div\n className=\"flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]\"\n style={{ borderColor: DIVIDER }}\n >\n <span id={titleId} className=\"flex min-w-0\">\n <Text size=\"xsmall\" color=\"secondary\" fontWeight=\"semi-bold\">\n {title}\n </Text>\n </span>\n {isRenderableNode(meta) && (\n <Text\n size=\"xsmall\"\n color=\"secondary\"\n font=\"mono\"\n wrap={false}\n className=\"truncate\"\n >\n {meta}\n </Text>\n )}\n </div>\n {lines.length === 0 ? (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] py-[8px]\">\n Empty\n </Text>\n ) : (\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n <pre\n id={bodyId}\n role=\"region\"\n aria-labelledby={titleId}\n tabIndex={0}\n // Numbered rows sit tight like an editor's; a bare payload keeps code spacing, as designed.\n className={`m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${showLineNumbers ? 'py-[6px] leading-[14px]' : 'py-[10px] leading-[1.65]'} text-[var(--malachite-text-primary,rgb(10,10,10))] ${FOCUS_RING_INSET}`}\n style={{ maxHeight: MAX_BODY_HEIGHT }}\n >\n <span className=\"block\" style={rowsWrapperStyle(false)}>\n {shown.map((line, index) => (\n // A line's position is its identity: its text can repeat.\n <span\n key={index}\n data-flagged={flagged.has(index + 1) || undefined}\n className={lineClasses(flagged.has(index + 1))}\n >\n {showLineNumbers && (\n <span\n aria-hidden=\"true\"\n className=\"flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n style={{ width: gutter }}\n >\n {index + 1}\n </span>\n )}\n <span\n className={`min-w-0 whitespace-pre ${showLineNumbers ? '' : 'px-[11px]'}`}\n >\n {flagged.has(index + 1) && (\n <span className=\"sr-only select-none\">Flagged: </span>\n )}\n {line || ' '}\n </span>\n </span>\n ))}\n {!open && !showLineNumbers && (\n <span aria-hidden=\"true\" className=\"block select-none px-[14px]\">\n …\n </span>\n )}\n </span>\n </pre>\n )}\n {open && rendered < lines.length && (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] pb-[8px]\">\n {`Showing the first ${rendered.toLocaleString()} of ${lines.length.toLocaleString()} lines.`}\n </Text>\n )}\n {foldable && (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-describedby={titleId}\n onClick={() => setExpanded((isOpen) => !isOpen)}\n className={`m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING_INSET}`}\n style={{ borderColor: DIVIDER }}\n >\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\">\n {toggleLabel(expanded, lines.length, hiddenFlags)}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <CaretDownIcon\n size={12}\n className=\"transition-transform\"\n style={{ transform: expanded ? 'rotate(180deg)' : undefined }}\n />\n </span>\n </button>\n )}\n </div>\n );\n};\n\nexport default CodePreview;\nexport { CodePreview };\n"],"names":["DEFAULT_PREVIEW_LINES","DEFAULT_MAX_RENDERED_LINES","MAX_BODY_HEIGHT","BORDER","DIVIDER","linesOf","code","countOf","value","fallback","lineClasses","flagged","toggleLabel","expanded","total","hiddenFlags","flags","CodePreview","title","meta","previewLines","highlightLines","showLineNumbers","maxRenderedLines","className","setExpanded","useState","titleId","useId","bodyId","lines","useMemo","line","limit","foldable","open","rendered","shown","gutter","jsxs","jsx","Text","isRenderableNode","FOCUS_RING_INSET","rowsWrapperStyle","index","isOpen","CaretDownIcon"],"mappings":";;;;;;;AAwBA,MAAMA,IAAwB,GACxBC,IAA6B,KAG7BC,IAAkB,KAElBC,IAAS,iDACTC,IAAU,yDAGVC,IAAU,CAACC,MACbA,MAAS,KAAK,CAAA,IAAKA,EAAK,QAAQ,UAAU,EAAE,EAAE,MAAM,YAAY,GAE9DC,IAAU,CAACC,GAAeC,MAC5B,CAAC,OAAO,MAAMD,CAAK,KAAKA,KAAS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AK,MAAK,UAAS,YAAW,aAAY,OAAM,WAC5C,UAAA7B,EAAYC,GAAUiB,EAAM,QAAQf,CAAW,GACpD;AAAA,cACA,gBAAAyB,EAAC,QAAA,EAAK,eAAY,QAAO,WAAU,QAC/B,UAAA,gBAAAA;AAAA,gBAACO;AAAA,gBAAA;AAAA,kBACG,MAAM;AAAA,kBACN,WAAU;AAAA,kBACV,OAAO,EAAE,WAAWlC,IAAW,mBAAmB,OAAA;AAAA,gBAAU;AAAA,cAAA,EAChE,CACJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAIhB;"}
|
|
1
|
+
{"version":3,"file":"CodePreview.js","sources":["../../src/components/CodePreview.tsx"],"sourcesContent":["import type React from 'react';\nimport { useId, useMemo, useState } from 'react';\nimport CopyOverlayButton from './CopyOverlayButton';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport Text from './Typography/Text';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\nimport { canCopyToClipboard } from './useClipboardCopy';\n\nexport interface CodePreviewProps {\n /** Names the payload in the header and its body and toggle for assistive tech, e.g. `Request`. */\n title: string;\n /** At the right of the header in the mono face, e.g. `POST · acc_8f2…`. */\n meta?: React.ReactNode;\n /** Drops the header, `meta` with it, for a payload whose surroundings already name it. The\n * title still names it for assistive tech. */\n titleHidden?: boolean;\n code: string;\n /** How many lines show until the reader asks for all of them. `Infinity` shows them all. */\n previewLines?: number;\n /** 1-based line numbers to flag, such as the fields a scanner caught. Colour alone, so say why nearby. */\n highlightLines?: readonly number[];\n showLineNumbers?: boolean;\n /** A button over the body copies the whole payload, folded lines too. */\n copyable?: boolean;\n /** The most lines the expanded body mounts; past it a note says how many are not shown. */\n maxRenderedLines?: number;\n className?: string;\n}\n\nconst DEFAULT_PREVIEW_LINES = 5;\nconst DEFAULT_MAX_RENDERED_LINES = 2000;\n\n// Past this the body scrolls, folded or open, so a long preview never crowds out what is around it.\nconst MAX_BODY_HEIGHT = 360;\n\nconst BORDER = 'var(--malachite-card-border,rgb(232,232,232))';\nconst DIVIDER = 'var(--malachite-card-subtle-divider,rgb(241,241,241))';\n\n// Any line ending, and no empty last line for a trailing newline.\nconst linesOf = (code: string): string[] =>\n code === '' ? [] : code.replace(/\\r?\\n$/, '').split(/\\r\\n|\\r|\\n/);\n\nconst countOf = (value: number, fallback: number): number =>\n !Number.isNaN(value) && value >= 1 ? Math.floor(value) : fallback;\n\nconst lineClasses = (flagged: boolean): string =>\n flagged\n ? 'flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]'\n : 'flex border-0 border-s-[3px] border-solid border-transparent';\n\nconst toggleLabel = (expanded: boolean, total: number, hiddenFlags: number): string => {\n if (expanded) {\n return 'Show Less';\n }\n const flags = hiddenFlags > 0 ? ` · ${hiddenFlags} flagged` : '';\n return `Show All ${total} Lines${flags}`;\n};\n\n/**\n * A framed payload: a header naming it, its first lines, and a toggle for the rest. For the raw\n * request or response under a step of a trace, where the whole body would crowd out the steps.\n */\nconst CodePreview: React.FC<CodePreviewProps> = ({\n title,\n meta,\n titleHidden = false,\n code,\n previewLines = DEFAULT_PREVIEW_LINES,\n highlightLines = [],\n showLineNumbers = true,\n copyable = false,\n maxRenderedLines = DEFAULT_MAX_RENDERED_LINES,\n className = '',\n}) => {\n const [expanded, setExpanded] = useState(false);\n const showsCopy = copyable && canCopyToClipboard();\n const titleId = useId();\n const bodyId = useId();\n const lines = useMemo(() => linesOf(code), [code]);\n const flagged = useMemo(\n () =>\n new Set(\n highlightLines.filter(\n (line) => Number.isInteger(line) && line >= 1 && line <= lines.length,\n ),\n ),\n [highlightLines, lines.length],\n );\n const limit = countOf(previewLines, DEFAULT_PREVIEW_LINES);\n const foldable = lines.length > limit;\n const open = expanded || !foldable;\n const rendered = Math.min(\n open ? lines.length : limit,\n countOf(maxRenderedLines, DEFAULT_MAX_RENDERED_LINES),\n );\n const shown = lines.slice(0, rendered);\n const hiddenFlags = [...flagged].filter((line) => line > limit).length;\n // 40px as designed, wider only when the last line's number would crowd the code.\n const gutter = `max(40px, calc(${String(lines.length).length}ch + 14px))`;\n return (\n <div\n className={`overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${className}`}\n style={{ borderColor: BORDER }}\n >\n {titleHidden ? (\n <span id={titleId} className=\"sr-only\">\n {title}\n </span>\n ) : (\n <div\n className=\"flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]\"\n style={{ borderColor: DIVIDER }}\n >\n <span id={titleId} className=\"flex min-w-0\">\n <Text size=\"xsmall\" color=\"secondary\" fontWeight=\"semi-bold\">\n {title}\n </Text>\n </span>\n {isRenderableNode(meta) && (\n <Text\n size=\"xsmall\"\n color=\"secondary\"\n font=\"mono\"\n wrap={false}\n className=\"truncate\"\n >\n {meta}\n </Text>\n )}\n </div>\n )}\n {lines.length === 0 ? (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] py-[8px]\">\n Empty\n </Text>\n ) : (\n <div className=\"relative\">\n {/* Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own. */}\n <pre\n id={bodyId}\n role=\"region\"\n aria-labelledby={titleId}\n tabIndex={0}\n // Numbered rows sit tight like an editor's; a bare payload keeps code spacing, as designed.\n className={`m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${showLineNumbers ? 'py-[6px] leading-[14px]' : 'py-[10px] leading-[1.65]'} text-[var(--malachite-text-primary,rgb(10,10,10))] ${FOCUS_RING_INSET}`}\n style={{\n maxHeight: MAX_BODY_HEIGHT,\n paddingInlineEnd: showsCopy ? 40 : undefined,\n }}\n >\n <span className=\"block\" style={rowsWrapperStyle(false)}>\n {shown.map((line, index) => (\n // A line's position is its identity: its text can repeat.\n <span\n key={index}\n data-flagged={flagged.has(index + 1) || undefined}\n className={lineClasses(flagged.has(index + 1))}\n >\n {showLineNumbers && (\n <span\n aria-hidden=\"true\"\n className=\"flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n style={{ width: gutter }}\n >\n {index + 1}\n </span>\n )}\n <span\n className={`min-w-0 whitespace-pre ${showLineNumbers ? '' : 'px-[11px]'}`}\n >\n {flagged.has(index + 1) && (\n <span className=\"sr-only select-none\">Flagged: </span>\n )}\n {line || ' '}\n </span>\n </span>\n ))}\n {!open && !showLineNumbers && (\n <span aria-hidden=\"true\" className=\"block select-none px-[14px]\">\n …\n </span>\n )}\n </span>\n </pre>\n {showsCopy && (\n <CopyOverlayButton\n text={code}\n aria-label={`Copy ${title}`}\n iconSize={12}\n className={`absolute end-[6px] top-[6px] z-[1] flex cursor-pointer items-center justify-center rounded-md border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] p-[5px] text-[var(--malachite-text-secondary,rgb(115,115,115))] hover:text-[var(--malachite-text-primary,rgb(10,10,10))] ${FOCUS_RING}`}\n style={{ borderColor: BORDER }}\n />\n )}\n </div>\n )}\n {open && rendered < lines.length && (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] pb-[8px]\">\n {`Showing the first ${rendered.toLocaleString()} of ${lines.length.toLocaleString()} lines.`}\n </Text>\n )}\n {foldable && (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-describedby={titleId}\n onClick={() => setExpanded((isOpen) => !isOpen)}\n className={`m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING_INSET}`}\n style={{ borderColor: DIVIDER }}\n >\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\">\n {toggleLabel(expanded, lines.length, hiddenFlags)}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <CaretDownIcon\n size={12}\n className=\"transition-transform\"\n style={{ transform: expanded ? 'rotate(180deg)' : undefined }}\n />\n </span>\n </button>\n )}\n </div>\n );\n};\n\nexport default CodePreview;\nexport { CodePreview };\n"],"names":["DEFAULT_PREVIEW_LINES","DEFAULT_MAX_RENDERED_LINES","MAX_BODY_HEIGHT","BORDER","DIVIDER","linesOf","code","countOf","value","fallback","lineClasses","flagged","toggleLabel","expanded","total","hiddenFlags","flags","CodePreview","title","meta","titleHidden","previewLines","highlightLines","showLineNumbers","copyable","maxRenderedLines","className","setExpanded","useState","showsCopy","canCopyToClipboard","titleId","useId","bodyId","lines","useMemo","line","limit","foldable","open","rendered","shown","gutter","jsxs","jsx","Text","isRenderableNode","FOCUS_RING_INSET","rowsWrapperStyle","index","CopyOverlayButton","FOCUS_RING","isOpen","CaretDownIcon"],"mappings":";;;;;;;;;AA+BA,MAAMA,IAAwB,GACxBC,IAA6B,KAG7BC,IAAkB,KAElBC,IAAS,iDACTC,IAAU,yDAGVC,IAAU,CAACC,MACbA,MAAS,KAAK,CAAA,IAAKA,EAAK,QAAQ,UAAU,EAAE,EAAE,MAAM,YAAY,GAE9DC,IAAU,CAACC,GAAeC,MAC5B,CAAC,OAAO,MAAMD,CAAK,KAAKA,KAAS,IAAI,KAAK,MAAMA,CAAK,IAAIC,GAEvDC,IAAc,CAACC,MACjBA,IACM,0KACA,gEAEJC,IAAc,CAACC,GAAmBC,GAAeC,MAAgC;AACnF,MAAIF;AACA,WAAO;AAEX,QAAMG,IAAQD,IAAc,IAAI,MAAMA,CAAW,aAAa;AAC9D,SAAO,YAAYD,CAAK,SAASE,CAAK;AAC1C,GAMMC,KAA0C,CAAC;AAAA,EAC7C,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,MAAAd;AAAA,EACA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;AAAA,YACvP,OAAO,EAAE,aAAa3C,EAAA;AAAA,YAEtB,UAAA;AAAA,cAAA,gBAAAwC,EAACC,GAAA,EAAK,MAAK,UAAS,YAAW,aAAY,OAAM,WAC5C,UAAAjC,EAAYC,GAAUqB,EAAM,QAAQnB,CAAW,GACpD;AAAA,cACA,gBAAA6B,EAAC,QAAA,EAAK,eAAY,QAAO,WAAU,QAC/B,UAAA,gBAAAA;AAAA,gBAACS;AAAA,gBAAA;AAAA,kBACG,MAAM;AAAA,kBACN,WAAU;AAAA,kBACV,OAAO,EAAE,WAAWxC,IAAW,mBAAmB,OAAA;AAAA,gBAAU;AAAA,cAAA,EAChE,CACJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAIhB;"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { jsxs as p, jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { useState as $, useId as d, Children as
|
|
2
|
+
import { useState as $, useId as d, Children as oe } from "react";
|
|
3
3
|
import { Button as z } from "./Button.js";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { FieldMessage as
|
|
12
|
-
import { IconBadge as
|
|
13
|
-
import { Modal as
|
|
4
|
+
import te from "./CalloutStrip.js";
|
|
5
|
+
import ie from "./CustomIcons/CheckCircleFilled.js";
|
|
6
|
+
import le from "./CustomIcons/CheckmarkIcon.js";
|
|
7
|
+
import re from "./CustomIcons/CopyIcon.js";
|
|
8
|
+
import se from "./CustomIcons/ErrorCircleFilled.js";
|
|
9
|
+
import ae from "./CustomIcons/InfoCircleFilled.js";
|
|
10
|
+
import ne from "./CustomIcons/WarningCircleFilled.js";
|
|
11
|
+
import { FieldMessage as ce } from "./FieldMessage.js";
|
|
12
|
+
import { IconBadge as de } from "./IconBadge.js";
|
|
13
|
+
import { Modal as pe } from "./Modal.js";
|
|
14
14
|
import { Typography as G } from "./Typography/index.js";
|
|
15
|
-
import { useClipboardCopy as
|
|
16
|
-
import { CONFIRMATION_DIALOG_VARIANTS as
|
|
17
|
-
import
|
|
18
|
-
const h = 12, I = (e) => e.replace(/\s+/g, " "),
|
|
15
|
+
import { useClipboardCopy as me } from "./useClipboardCopy.js";
|
|
16
|
+
import { CONFIRMATION_DIALOG_VARIANTS as fe } from "./confirmationDialogVariants.js";
|
|
17
|
+
import ue from "./Input/Input.js";
|
|
18
|
+
const h = 12, I = (e) => e.replace(/\s+/g, " "), ye = (e, t) => {
|
|
19
19
|
if (!(t === "" || e === "" || e === t) && I(e).toLowerCase() === I(t).toLowerCase())
|
|
20
20
|
return I(e) === I(t) ? "The spacing has to match exactly." : "This is case-sensitive.";
|
|
21
|
-
},
|
|
21
|
+
}, xe = "Could not copy. Enter the phrase manually.", Ce = (e, t) => {
|
|
22
22
|
const l = typeof e == "object" && e !== null ? e : void 0;
|
|
23
23
|
return l ? { parts: l, text: [l.prefix, t, l.suffix].filter(Boolean).join(" ") } : { text: typeof e == "string" ? e : `Type ${t} to confirm` };
|
|
24
|
-
},
|
|
25
|
-
const { outcome: m, canCopy: f, copy: a } =
|
|
24
|
+
}, be = (e, t) => e === "copied" ? `${t} copied to clipboard` : "", ve = (e, t, l, c) => {
|
|
25
|
+
const { outcome: m, canCopy: f, copy: a } = me(`${t}|${e}`), s = async () => {
|
|
26
26
|
e && await a(e) && queueMicrotask(() => c == null ? void 0 : c(e));
|
|
27
27
|
};
|
|
28
28
|
return { outcome: m, canCopy: f && !l, copy: () => void s() };
|
|
29
|
-
}, T = ({ children: e }) => /* @__PURE__ */ o(G.Text, { size: "small", color: "primary", children: e }),
|
|
29
|
+
}, T = ({ children: e }) => /* @__PURE__ */ o(G.Text, { size: "small", color: "primary", children: e }), he = ({
|
|
30
30
|
phrase: e,
|
|
31
31
|
parts: t,
|
|
32
32
|
plainLabel: l,
|
|
@@ -40,7 +40,7 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
40
40
|
onCopy: g,
|
|
41
41
|
nearMissMessage: x
|
|
42
42
|
}) => {
|
|
43
|
-
const u = d(), C = d(), b = d(), v = d(), r = [x, n === "failed" ?
|
|
43
|
+
const u = d(), C = d(), b = d(), v = d(), r = [x, n === "failed" ? xe : void 0].filter(Boolean).join(" ") || void 0, B = t ? [u, t.suffix ? C : void 0].filter(Boolean).join(" ") : void 0;
|
|
44
44
|
return /* @__PURE__ */ p("div", { className: "flex flex-col gap-[6px]", children: [
|
|
45
45
|
t ? /* @__PURE__ */ p("div", { className: "flex flex-wrap items-center gap-[6px] px-2 text-[13px]", children: [
|
|
46
46
|
/* @__PURE__ */ p("span", { id: u, children: [
|
|
@@ -55,7 +55,7 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
55
55
|
size: "small",
|
|
56
56
|
iconOnly: !0,
|
|
57
57
|
"aria-label": `${s} ${e}`,
|
|
58
|
-
icon: n === "copied" ? /* @__PURE__ */ o(
|
|
58
|
+
icon: n === "copied" ? /* @__PURE__ */ o(le, { size: 13 }) : /* @__PURE__ */ o(re, { size: 13 }),
|
|
59
59
|
onClick: g,
|
|
60
60
|
disabled: !i
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
63
63
|
t.suffix ? /* @__PURE__ */ o("span", { id: C, children: /* @__PURE__ */ o(T, { children: t.suffix }) }) : null
|
|
64
64
|
] }) : /* @__PURE__ */ o("label", { id: u, htmlFor: v, className: "px-2 text-[13px]", children: /* @__PURE__ */ o(T, { children: l }) }),
|
|
65
65
|
/* @__PURE__ */ o(
|
|
66
|
-
|
|
66
|
+
ue,
|
|
67
67
|
{
|
|
68
68
|
id: v,
|
|
69
69
|
name: "confirmation-phrase",
|
|
@@ -78,15 +78,15 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
78
78
|
disabled: a
|
|
79
79
|
}
|
|
80
80
|
),
|
|
81
|
-
/* @__PURE__ */ o(
|
|
82
|
-
t ? /* @__PURE__ */ o("span", { role: "status", className: "sr-only", children:
|
|
81
|
+
/* @__PURE__ */ o(ce, { id: b, message: r }),
|
|
82
|
+
t ? /* @__PURE__ */ o("span", { role: "status", className: "sr-only", children: be(n, e) }) : null
|
|
83
83
|
] });
|
|
84
|
-
},
|
|
85
|
-
default: /* @__PURE__ */ o(
|
|
86
|
-
warning: /* @__PURE__ */ o(
|
|
87
|
-
destructive: /* @__PURE__ */ o(
|
|
88
|
-
success: /* @__PURE__ */ o(
|
|
89
|
-
},
|
|
84
|
+
}, Ie = {
|
|
85
|
+
default: /* @__PURE__ */ o(ae, { size: h }),
|
|
86
|
+
warning: /* @__PURE__ */ o(ne, { size: h }),
|
|
87
|
+
destructive: /* @__PURE__ */ o(se, { size: h }),
|
|
88
|
+
success: /* @__PURE__ */ o(ie, { size: h })
|
|
89
|
+
}, $e = ({
|
|
90
90
|
open: e,
|
|
91
91
|
onClose: t,
|
|
92
92
|
onConfirm: l,
|
|
@@ -107,22 +107,23 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
107
107
|
confirmDisabled: B = !1,
|
|
108
108
|
tip: R,
|
|
109
109
|
size: V = "medium",
|
|
110
|
-
|
|
111
|
-
"aria-
|
|
110
|
+
stacking: q,
|
|
111
|
+
"aria-label": Y,
|
|
112
|
+
"aria-labelledby": H,
|
|
112
113
|
children: L
|
|
113
114
|
}) => {
|
|
114
|
-
const [A, S] = $(""), k = d(), w = d(), F =
|
|
115
|
-
(j.open !== e || j.confirmPhrase !== i) && (
|
|
116
|
-
const { parts:
|
|
115
|
+
const [A, S] = $(""), k = d(), w = d(), F = fe[s], [j, W] = $({ open: e, confirmPhrase: i });
|
|
116
|
+
(j.open !== e || j.confirmPhrase !== i) && (W({ open: e, confirmPhrase: i }), e && S(""));
|
|
117
|
+
const { parts: Z, text: E } = Ce(
|
|
117
118
|
g,
|
|
118
119
|
i
|
|
119
120
|
), {
|
|
120
|
-
outcome:
|
|
121
|
-
canCopy:
|
|
122
|
-
copy:
|
|
123
|
-
} =
|
|
121
|
+
outcome: J,
|
|
122
|
+
canCopy: K,
|
|
123
|
+
copy: Q
|
|
124
|
+
} = ve(i, e, r, u), O = A.trim(), N = (i == null ? void 0 : i.trim()) ?? "", _ = !i || (N === "" ? A === i : O === N), U = ye(O, N), D = r || B || !_, X = oe.toArray(L).some(
|
|
124
125
|
(y) => typeof y != "string" || y.trim() !== ""
|
|
125
|
-
), M = !!a ||
|
|
126
|
+
), M = !!a || X || !!i, P = [n ? w : null, a ? k : null].filter(Boolean).join(" ") || void 0, ee = /* @__PURE__ */ p("div", { className: "flex w-full flex-wrap items-center justify-end gap-[8px]", children: [
|
|
126
127
|
/* @__PURE__ */ o(z, { variant: "outline", size: "small", onClick: t, disabled: r, children: v }),
|
|
127
128
|
/* @__PURE__ */ o(
|
|
128
129
|
z,
|
|
@@ -138,33 +139,34 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
138
139
|
)
|
|
139
140
|
] });
|
|
140
141
|
return /* @__PURE__ */ p(
|
|
141
|
-
|
|
142
|
+
pe,
|
|
142
143
|
{
|
|
143
144
|
open: e,
|
|
144
145
|
onClose: t,
|
|
145
146
|
title: c,
|
|
146
147
|
size: V,
|
|
147
|
-
|
|
148
|
+
stacking: q,
|
|
149
|
+
footer: ee,
|
|
148
150
|
busy: r,
|
|
149
151
|
role: s === "destructive" ? "alertdialog" : "dialog",
|
|
150
|
-
"aria-label":
|
|
151
|
-
"aria-labelledby":
|
|
152
|
-
"aria-describedby":
|
|
152
|
+
"aria-label": Y,
|
|
153
|
+
"aria-labelledby": H,
|
|
154
|
+
"aria-describedby": P,
|
|
153
155
|
closeOnOverlayClick: s !== "destructive" && !i,
|
|
154
156
|
headerDivider: !0,
|
|
155
157
|
titleAdornment: m,
|
|
156
158
|
bodyPadding: !1,
|
|
157
159
|
tray: { tone: F.tray, caption: R },
|
|
158
160
|
icon: /* @__PURE__ */ o(
|
|
159
|
-
|
|
161
|
+
de,
|
|
160
162
|
{
|
|
161
163
|
variant: s,
|
|
162
|
-
icon: f ??
|
|
164
|
+
icon: f ?? Ie[s]
|
|
163
165
|
}
|
|
164
166
|
),
|
|
165
167
|
children: [
|
|
166
168
|
n ? /* @__PURE__ */ o(
|
|
167
|
-
|
|
169
|
+
te,
|
|
168
170
|
{
|
|
169
171
|
id: w,
|
|
170
172
|
type: n.type ?? F.calloutType,
|
|
@@ -192,20 +194,20 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
192
194
|
y.preventDefault(), y.stopPropagation(), D || l();
|
|
193
195
|
},
|
|
194
196
|
children: /* @__PURE__ */ o(
|
|
195
|
-
|
|
197
|
+
he,
|
|
196
198
|
{
|
|
197
199
|
phrase: i,
|
|
198
|
-
parts:
|
|
200
|
+
parts: Z,
|
|
199
201
|
plainLabel: E,
|
|
200
202
|
placeholder: C,
|
|
201
203
|
value: A,
|
|
202
204
|
onChange: S,
|
|
203
205
|
disabled: r,
|
|
204
206
|
copyLabel: x,
|
|
205
|
-
copyOutcome:
|
|
206
|
-
canCopy:
|
|
207
|
-
onCopy:
|
|
208
|
-
nearMissMessage:
|
|
207
|
+
copyOutcome: J,
|
|
208
|
+
canCopy: K,
|
|
209
|
+
onCopy: Q,
|
|
210
|
+
nearMissMessage: U
|
|
209
211
|
}
|
|
210
212
|
)
|
|
211
213
|
}
|
|
@@ -217,7 +219,7 @@ const h = 12, I = (e) => e.replace(/\s+/g, " "), ue = (e, t) => {
|
|
|
217
219
|
);
|
|
218
220
|
};
|
|
219
221
|
export {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
$e as ConfirmationDialog,
|
|
223
|
+
$e as default
|
|
222
224
|
};
|
|
223
225
|
//# sourceMappingURL=ConfirmationDialog.js.map
|