@stackone/malachite 2.130.0 → 2.130.1

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.
@@ -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 CopyOverlayButton from './CopyOverlayButton';\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';\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 // 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 <CopyOverlayButton\n text={textToCopy}\n aria-label=\"Copy\"\n iconSize={14}\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 );\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","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,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,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OAAO,KAAKA,CAAK,EAAE,SAAS,GAGxEC,IAAc,CAACC,GAAeF,GAAgBG,MAChDA,EAAK,SAAS,KAAKJ,EAAWC,CAAK,IAAIE,GAErCE,IAAS,CAACJ,MAA2B;AACvC,QAAMK,IAAQN,EAAWC,CAAK;AAC9B,SAAO,GAAGK,CAAK,IAAIA,MAAU,IAAI,SAAS,OAAO;AACrD,GAGMC,IAAS,CAACH,MACZA,EAAK,IAAI,CAACI,MAAQ,OAAOA,CAAG,KAAK,IAAI,EAAE,KAAK,GAAG,GAG7CC,IACF,CAACN,MACD,CACIO,GACA,EAAE,OAAAT,GAAO,MAAAG,EAAA,MAETM,KAAeR,EAAYC,GAAOF,GAAOG,CAAI,GAI/CO,IACF,CAACR,MACD,CACIN,GACA,EAAE,OAAAI,GAAO,MAAAG,QACR;;AACD,MAAI,CAACF,EAAYC,GAAOF,GAAOG,KAAQ,CAAA,CAAE;AACrC,WAAO;AAEX,QAAMQ,IAAY,SAAOC,IAAAhB,EAAM,UAAN,gBAAAgB,EAAa,cAAa,EAAE,EAAE,SAAS,KAAK;AACrE,SACI,gBAAAd;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,iBAAe,CAACa;AAAA,MAChB,cAAY,GAAGL,EAAOH,KAAQ,CAAA,CAAE,CAAC,KAAKC,EAAOJ,CA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AAA,GAER,IAIDK,EAAiBT,GAAUU,CAAQ;AAAA,EAC9C,GAGMU,IAAoB,MACjBnC,IAIDO,sBAEKpB,EAAM,UAAN,EAAe,UAAU6C,KACtB,UAAA,gBAAAhE;AAAA,IAACkB;AAAA,IAAA;AAAA,MACG,MAAAc;AAAA,MACA,UAAAO;AAAA,MACA,iBAAAX;AAAA,MACA,WAAAU;AAAA,MACA,eAAAiB;AAAA,MACA,eAAAJ;AAAA,IAAA;AAAA,EAAA,GAER,IAIDa,EAAA,IAlBI;AAqBf,SACI,gBAAAX;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,QAAAc;AAAA,QACAJ,IAAWoB,EAAWpB,CAAQ,IAAIsB,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 CopyOverlayButton from './CopyOverlayButton';\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';\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, and the copy button as \"Copy\" and this. Defaults to \"Code\". */\n 'aria-label'?: string;\n /** Names the scrollable region and the copy button 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 copyId = React.useId();\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 // 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 <CopyOverlayButton\n text={textToCopy}\n // Named after the block, so a page of blocks has a \"Copy\" for each rather than\n // several alike. Its own id leads the list to keep the word \"Copy\" in the name.\n {...(ariaLabelledBy\n ? {\n id: copyId,\n 'aria-label': 'Copy',\n 'aria-labelledby': `${copyId} ${ariaLabelledBy}`,\n }\n : { 'aria-label': ariaLabel ? `Copy ${ariaLabel}` : 'Copy' })}\n iconSize={14}\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 );\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","copyId","devWarning","diffRows","diffHunks","diffText","textToCopy","copyButton","CopyOverlayButton","viewportProps","FOCUS_RING_INSET","jsxs","JsonView","copyClearance","renderPlainLines","decorate","lines","rowsWrapperStyle","line","index","decoration","CodeLine","renderPlainCode","renderDiff","rows","renderCodeContent"],"mappings":";;;;;;;;;AAcA,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,MAGNK,IAAa,CAACC,MAChBA,MAAU,QAAQ,OAAOA,KAAU,WAAW,OAAO,KAAKA,CAAK,EAAE,SAAS,GAGxEC,IAAc,CAACC,GAAeF,GAAgBG,MAChD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A,GAER,IAIDa,EAAA,IAlBI;AAqBf,SACI,gBAAAX;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,2DAA2DpB,CAAS;AAAA,MAC/E,OAAO;AAAA,QACH,iBAAiB;AAAA,QACjB,aAAa;AAAA,QACb,QAAAE;AAAA,QACA,GAAGD;AAAA,MAAA;AAAA,MAGN,UAAA;AAAA,QAAAe;AAAA,QACAJ,IAAWoB,EAAWpB,CAAQ,IAAIsB,EAAA;AAAA,MAAkB;AAAA,IAAA;AAAA,EAAA;AAGjE;"}
@@ -1,31 +1,35 @@
1
- import { jsxs as n, Fragment as s, jsx as o } from "react/jsx-runtime";
2
- import m from "./CustomIcons/CheckmarkIcon.js";
3
- import d from "./CustomIcons/CopyIcon.js";
1
+ import { jsxs as d, Fragment as m, jsx as o } from "react/jsx-runtime";
2
+ import b from "./CustomIcons/CheckmarkIcon.js";
3
+ import y from "./CustomIcons/CopyIcon.js";
4
4
  import { useClipboardCopy as u } from "./useClipboardCopy.js";
5
- const h = ({
5
+ const v = ({
6
6
  text: r,
7
- "aria-label": t,
8
- iconSize: e,
9
- className: a,
10
- style: p
7
+ "aria-label": l,
8
+ "aria-labelledby": i,
9
+ id: t,
10
+ iconSize: a,
11
+ className: p,
12
+ style: c
11
13
  }) => {
12
- const { outcome: l, copy: c } = u(r), i = l === "copied";
13
- return /* @__PURE__ */ n(s, { children: [
14
+ const { outcome: n, copy: s } = u(r), e = n === "copied";
15
+ return /* @__PURE__ */ d(m, { children: [
14
16
  /* @__PURE__ */ o(
15
17
  "button",
16
18
  {
17
19
  type: "button",
18
- "aria-label": t,
19
- onClick: () => void c(r),
20
- className: a,
21
- style: p,
22
- children: i ? /* @__PURE__ */ o(m, { size: e }) : /* @__PURE__ */ o(d, { size: e })
20
+ id: t,
21
+ "aria-label": l,
22
+ "aria-labelledby": i,
23
+ onClick: () => void s(r),
24
+ className: p,
25
+ style: c,
26
+ children: e ? /* @__PURE__ */ o(b, { size: a }) : /* @__PURE__ */ o(y, { size: a })
23
27
  }
24
28
  ),
25
- /* @__PURE__ */ o("span", { "aria-live": "polite", className: "sr-only", children: i ? "Copied to clipboard" : "" })
29
+ /* @__PURE__ */ o("span", { "aria-live": "polite", className: "sr-only", children: e ? "Copied to clipboard" : "" })
26
30
  ] });
27
31
  };
28
32
  export {
29
- h as default
33
+ v as default
30
34
  };
31
35
  //# sourceMappingURL=CopyOverlayButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CopyOverlayButton.js","sources":["../../src/components/CopyOverlayButton.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { useClipboardCopy } from './useClipboardCopy';\n\ninterface CopyOverlayButtonProps {\n text: string;\n 'aria-label': string;\n iconSize: number;\n className: string;\n style?: React.CSSProperties;\n}\n\nconst CopyOverlayButton: React.FC<CopyOverlayButtonProps> = ({\n text,\n 'aria-label': ariaLabel,\n iconSize,\n className,\n style,\n}) => {\n const { outcome, copy } = useClipboardCopy(text);\n const copied = outcome === 'copied';\n return (\n <>\n <button\n type=\"button\"\n aria-label={ariaLabel}\n onClick={() => void copy(text)}\n className={className}\n style={style}\n >\n {copied ? <CheckmarkIcon size={iconSize} /> : <CopyIcon size={iconSize} />}\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\nexport default CopyOverlayButton;\n"],"names":["CopyOverlayButton","text","ariaLabel","iconSize","className","style","outcome","copy","useClipboardCopy","copied","jsxs","Fragment","jsx","CheckmarkIcon","CopyIcon"],"mappings":";;;;AAaA,MAAMA,IAAsD,CAAC;AAAA,EACzD,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACJ,MAAM;AACF,QAAM,EAAE,SAAAC,GAAS,MAAAC,MAASC,EAAiBP,CAAI,GACzCQ,IAASH,MAAY;AAC3B,SACI,gBAAAI,EAAAC,GAAA,EACI,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,cAAYV;AAAA,QACZ,SAAS,MAAM,KAAKK,EAAKN,CAAI;AAAA,QAC7B,WAAAG;AAAA,QACA,OAAAC;AAAA,QAEC,UAAAI,sBAAUI,GAAA,EAAc,MAAMV,GAAU,IAAK,gBAAAS,EAACE,GAAA,EAAS,MAAMX,EAAA,CAAU;AAAA,MAAA;AAAA,IAAA;AAAA,IAG5E,gBAAAS,EAAC,UAAK,aAAU,UAAS,WAAU,WAC9B,UAAAH,IAAS,wBAAwB,GAAA,CACtC;AAAA,EAAA,GACJ;AAER;"}
1
+ {"version":3,"file":"CopyOverlayButton.js","sources":["../../src/components/CopyOverlayButton.tsx"],"sourcesContent":["import type React from 'react';\nimport CheckmarkIcon from './CustomIcons/CheckmarkIcon';\nimport CopyIcon from './CustomIcons/CopyIcon';\nimport { useClipboardCopy } from './useClipboardCopy';\n\ninterface CopyOverlayButtonProps {\n text: string;\n 'aria-label': string;\n /** Names the button by these ids instead; list the button's own `id` first to keep its label. */\n 'aria-labelledby'?: string;\n id?: string;\n iconSize: number;\n className: string;\n style?: React.CSSProperties;\n}\n\nconst CopyOverlayButton: React.FC<CopyOverlayButtonProps> = ({\n text,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n id,\n iconSize,\n className,\n style,\n}) => {\n const { outcome, copy } = useClipboardCopy(text);\n const copied = outcome === 'copied';\n return (\n <>\n <button\n type=\"button\"\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n onClick={() => void copy(text)}\n className={className}\n style={style}\n >\n {copied ? <CheckmarkIcon size={iconSize} /> : <CopyIcon size={iconSize} />}\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\nexport default CopyOverlayButton;\n"],"names":["CopyOverlayButton","text","ariaLabel","ariaLabelledBy","id","iconSize","className","style","outcome","copy","useClipboardCopy","copied","jsxs","Fragment","jsx","CheckmarkIcon","CopyIcon"],"mappings":";;;;AAgBA,MAAMA,IAAsD,CAAC;AAAA,EACzD,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,IAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AACJ,MAAM;AACF,QAAM,EAAE,SAAAC,GAAS,MAAAC,MAASC,EAAiBT,CAAI,GACzCU,IAASH,MAAY;AAC3B,SACI,gBAAAI,EAAAC,GAAA,EACI,UAAA;AAAA,IAAA,gBAAAC;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,IAAAV;AAAA,QACA,cAAYF;AAAA,QACZ,mBAAiBC;AAAA,QACjB,SAAS,MAAM,KAAKM,EAAKR,CAAI;AAAA,QAC7B,WAAAK;AAAA,QACA,OAAAC;AAAA,QAEC,UAAAI,sBAAUI,GAAA,EAAc,MAAMV,GAAU,IAAK,gBAAAS,EAACE,GAAA,EAAS,MAAMX,EAAA,CAAU;AAAA,MAAA;AAAA,IAAA;AAAA,IAG5E,gBAAAS,EAAC,UAAK,aAAU,UAAS,WAAU,WAC9B,UAAAH,IAAS,wBAAwB,GAAA,CACtC;AAAA,EAAA,GACJ;AAER;"}
@@ -1,28 +1,29 @@
1
- import { jsx as a, jsxs as s, Fragment as Q } from "react/jsx-runtime";
1
+ import { jsx as a, jsxs as s, Fragment as K } from "react/jsx-runtime";
2
2
  import { useState as T, useEffect as ye, useRef as Ne } from "react";
3
3
  import Ce, { useFormFieldIds as Ee } from "../BaseFormComponent.js";
4
- import { Button as Y } from "../Button.js";
4
+ import { Button as Q } from "../Button.js";
5
5
  import { CopyButton as ke } from "../CopyButton.js";
6
6
  import Se from "../CustomIcons/EyeClosedIcon.js";
7
7
  import ze from "../CustomIcons/EyeIcon.js";
8
- import je from "../CustomIcons/InfoIcon.js";
9
- import { FieldMessage as Re } from "../FieldMessage.js";
8
+ import Re from "../CustomIcons/InfoIcon.js";
9
+ import { FieldMessage as je } from "../FieldMessage.js";
10
10
  import Te from "../LoadingInput.js";
11
- import Ve from "../Tooltip.js";
12
- import { paintedFieldValue as $e } from "../devWarning.js";
13
- const O = {
11
+ import $e from "../Tooltip.js";
12
+ import { paintedFieldValue as Ve } from "../devWarning.js";
13
+ import { FOCUS_BORDER as _e } from "../focusRing.js";
14
+ const J = {
14
15
  small: "h-[var(--malachite-control-height-small,28px)]",
15
16
  medium: "h-[var(--malachite-control-height-medium,32px)]",
16
17
  large: "h-[var(--malachite-control-height-large,42px)]"
17
- }, Me = {
18
+ }, De = {
18
19
  small: "text-[length:var(--malachite-font-size-small,13px)]",
19
20
  medium: "text-[length:var(--malachite-font-size-small,13px)]",
20
21
  large: "text-[length:var(--malachite-font-size-15,15px)] leading-[1.4]"
21
- }, Ze = {
22
+ }, Me = {
22
23
  small: "px-[10px]",
23
24
  medium: "px-[10px]",
24
25
  large: "px-[16px]"
25
- }, _e = {
26
+ }, Ze = {
26
27
  small: "rounded-[var(--malachite-radius-10,10px)]",
27
28
  medium: "rounded-xl",
28
29
  large: "rounded-[var(--malachite-radius-xxl,14px)]"
@@ -43,13 +44,13 @@ const O = {
43
44
  wrapper: [
44
45
  "border border-solid",
45
46
  e ? "border-[var(--malachite-destructive-border)]" : "border-[var(--malachite-card-border)]",
46
- e ? "focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]" : "focus-within:border-[var(--malachite-control-border-hover)] hover:border-[var(--malachite-control-border-hover)]"
47
+ e ? "focus-within:border-[var(--malachite-destructive-border-hover)] hover:border-[var(--malachite-destructive-border-hover)]" : `${_e} hover:not-focus-within:border-[var(--malachite-control-border-hover)]`
47
48
  ],
48
49
  shadow: e ? "shadow-error" : "shadow-default",
49
50
  borderRadius: ""
50
51
  };
51
52
  }
52
- }, Fe = ({
53
+ }, aa = ({
53
54
  label: r,
54
55
  hint: e,
55
56
  hintIcon: i,
@@ -59,22 +60,22 @@ const O = {
59
60
  name: o,
60
61
  required: h,
61
62
  requiredIndicator: w,
62
- error: V,
63
- description: $,
64
- loading: F = !1,
65
- readOnly: M = !1,
63
+ error: $,
64
+ description: V,
65
+ loading: Y = !1,
66
+ readOnly: _ = !1,
66
67
  type: d = "text",
67
68
  size: n = "large",
68
69
  variant: ee = "default",
69
- defaultValue: Z,
70
+ defaultValue: D,
70
71
  disabled: p,
71
- prefixValue: _,
72
- prefixSecondaryValue: A,
72
+ prefixValue: M,
73
+ prefixSecondaryValue: Z,
73
74
  ellipsis: ae = !1,
74
75
  copyOnClick: re = !1,
75
- formControl: D,
76
+ formControl: A,
76
77
  buttons: u,
77
- onCopyClick: P,
78
+ onCopyClick: B,
78
79
  showCopyButton: te,
79
80
  onChange: I,
80
81
  value: ie,
@@ -88,17 +89,17 @@ const O = {
88
89
  "aria-labelledby": ne,
89
90
  "aria-describedby": ce
90
91
  }) => {
91
- const { controlId: B, labelId: me, descriptionId: G, hintId: H, helperTextId: C } = Ee({
92
+ const { controlId: P, labelId: me, descriptionId: G, hintId: H, helperTextId: C } = Ee({
92
93
  id: le,
93
94
  label: r,
94
- description: $,
95
+ description: V,
95
96
  hint: e,
96
97
  helperText: !0
97
- }), [E, he] = T(!1), [pe, ue] = T(Z || ""), [k, L] = T(!1);
98
+ }), [E, he] = T(!1), [pe, ue] = T(D || ""), [k, O] = T(!1);
98
99
  ye(() => {
99
100
  if (k) {
100
101
  const t = setTimeout(() => {
101
- L(!1);
102
+ O(!1);
102
103
  }, 1e3);
103
104
  return () => clearTimeout(t);
104
105
  }
@@ -106,29 +107,29 @@ const O = {
106
107
  const ve = (t) => (l) => {
107
108
  const c = l.target.value;
108
109
  ue(c), I == null || I(c), t == null || t(c);
109
- }, U = Ne(void 0), W = (t) => $e({
110
+ }, U = Ne(void 0), L = (t) => Ve({
110
111
  component: "Input",
111
112
  name: o,
112
113
  value: ie,
113
114
  formValue: t,
114
- defaultValue: Z,
115
- bound: !!D,
115
+ defaultValue: D,
116
+ bound: !!A,
116
117
  uncontrolledValue: pe
117
- }), f = P ? () => {
118
- const t = W(U.current);
119
- t && (navigator.clipboard.writeText(t), L(!0), P());
120
- } : void 0, fe = d === "password" ? E ? "text" : "password" : d, xe = m || _ || A, ge = O[n], be = (t) => {
118
+ }), f = B ? () => {
119
+ const t = L(U.current);
120
+ t && (navigator.clipboard.writeText(t), O(!0), B());
121
+ } : void 0, fe = d === "password" ? E ? "text" : "password" : d, xe = m || M || Z, ge = J[n], be = (t) => {
121
122
  const l = Ae(ee, t);
122
123
  return [
123
124
  "relative",
124
125
  "flex items-center",
125
126
  "w-full",
126
- l.borderRadius || _e[n],
127
+ l.borderRadius || Ze[n],
127
128
  p ? "bg-[var(--malachite-card-dimmed-background)]" : "bg-[var(--malachite-card-background)]",
128
129
  "transition-colors duration-200 ease-in-out",
129
130
  l.shadow,
130
131
  ...p ? [] : l.wrapper,
131
- O[n]
132
+ J[n]
132
133
  ].filter(Boolean).join(" ");
133
134
  };
134
135
  return /* @__PURE__ */ a(
@@ -141,10 +142,10 @@ const O = {
141
142
  name: o,
142
143
  required: h,
143
144
  requiredIndicator: w,
144
- loading: F,
145
- formControl: D,
146
- description: $,
147
- controlId: B,
145
+ loading: Y,
146
+ formControl: A,
147
+ description: V,
148
+ controlId: P,
148
149
  labelId: me,
149
150
  descriptionId: G,
150
151
  hintId: H,
@@ -156,18 +157,18 @@ const O = {
156
157
  helperTextMarginTop: !0
157
158
  }
158
159
  ),
159
- children: ({ error: t, message: l, onFieldChange: c, onFieldBlur: S, value: X }) => {
160
- U.current = X;
161
- const x = W(X), z = te ?? !!(f && p && x), j = V ?? t, R = V === !1 ? void 0 : l, q = j && !R, we = q || z || (u == null ? void 0 : u.length) || d === "password" && N, J = `${C}-error`, Ie = [
160
+ children: ({ error: t, message: l, onFieldChange: c, onFieldBlur: S, value: W }) => {
161
+ U.current = W;
162
+ const x = L(W), z = te ?? !!(f && p && x), R = $ ?? t, j = $ === !1 ? void 0 : l, X = R && !j, we = X || z || (u == null ? void 0 : u.length) || d === "password" && N, q = `${C}-error`, Ie = [
162
163
  G,
163
164
  H,
164
165
  v ? C : void 0,
165
- R ? J : void 0,
166
+ j ? q : void 0,
166
167
  ce
167
- ].filter(Boolean).join(" ") || void 0, K = /* @__PURE__ */ a(
168
+ ].filter(Boolean).join(" ") || void 0, F = /* @__PURE__ */ a(
168
169
  "input",
169
170
  {
170
- id: B,
171
+ id: P,
171
172
  type: fe,
172
173
  placeholder: b,
173
174
  value: x,
@@ -175,31 +176,31 @@ const O = {
175
176
  onBlur: () => {
176
177
  y == null || y(), S == null || S();
177
178
  },
178
- disabled: p || M,
179
- readOnly: M,
179
+ disabled: p || _,
180
+ readOnly: _,
180
181
  autoComplete: oe,
181
182
  autoFocus: se,
182
183
  "aria-label": de,
183
184
  "aria-labelledby": ne,
184
- "aria-invalid": j || void 0,
185
+ "aria-invalid": R || void 0,
185
186
  "aria-required": h || void 0,
186
187
  "aria-describedby": Ie,
187
- className: `flex-1 bg-transparent border-none outline-none text-[var(--malachite-text-primary)] placeholder:text-[var(--malachite-text-placeholder)] disabled:text-[var(--malachite-text-primary)] disabled:cursor-not-allowed ${Me[n]} ${Ze[n]} ${ae ? "min-w-0 truncate" : ""}`,
188
+ className: `flex-1 bg-transparent border-none outline-none text-[var(--malachite-text-primary)] placeholder:text-[var(--malachite-text-placeholder)] disabled:text-[var(--malachite-text-primary)] disabled:cursor-not-allowed ${De[n]} ${Me[n]} ${ae ? "min-w-0 truncate" : ""}`,
188
189
  name: o
189
190
  }
190
191
  );
191
- return /* @__PURE__ */ s(Q, { children: [
192
- /* @__PURE__ */ s("div", { className: be(j), children: [
192
+ return /* @__PURE__ */ s(K, { children: [
193
+ /* @__PURE__ */ s("div", { className: be(R), children: [
193
194
  xe && /* @__PURE__ */ a("div", { className: "flex items-center pl-3 pr-1 flex-shrink-0 pointer-events-none", children: /* @__PURE__ */ a(
194
- De,
195
+ Be,
195
196
  {
196
- prefixValue: _,
197
- prefixSecondaryValue: A,
197
+ prefixValue: M,
198
+ prefixSecondaryValue: Z,
198
199
  icon: m
199
200
  }
200
201
  ) }),
201
202
  re && z && f ? /* @__PURE__ */ a(
202
- Ve,
203
+ $e,
203
204
  {
204
205
  text: x,
205
206
  fill: !0,
@@ -207,7 +208,7 @@ const O = {
207
208
  describesTrigger: !1,
208
209
  showOnFocus: !1,
209
210
  children: /* @__PURE__ */ s("div", { className: "relative flex min-w-0 flex-1", children: [
210
- K,
211
+ F,
211
212
  /* @__PURE__ */ a(
212
213
  "button",
213
214
  {
@@ -220,7 +221,7 @@ const O = {
220
221
  )
221
222
  ] })
222
223
  }
223
- ) : K,
224
+ ) : F,
224
225
  we && /* @__PURE__ */ s(
225
226
  "div",
226
227
  {
@@ -229,7 +230,7 @@ const O = {
229
230
  /* @__PURE__ */ a(
230
231
  Pe,
231
232
  {
232
- error: q,
233
+ error: X,
233
234
  defaultValue: x,
234
235
  onCopyClick: f,
235
236
  showCopyButton: z,
@@ -240,7 +241,7 @@ const O = {
240
241
  onTogglePassword: () => he(!E)
241
242
  }
242
243
  ),
243
- /* @__PURE__ */ a(Be, { buttons: u })
244
+ /* @__PURE__ */ a(Ge, { buttons: u })
244
245
  ]
245
246
  }
246
247
  )
@@ -253,12 +254,12 @@ const O = {
253
254
  children: v
254
255
  }
255
256
  ),
256
- /* @__PURE__ */ a(Re, { id: J, message: R, spaced: !0 })
257
+ /* @__PURE__ */ a(je, { id: q, message: j, spaced: !0 })
257
258
  ] });
258
259
  }
259
260
  }
260
261
  );
261
- }, De = ({ prefixValue: r, prefixSecondaryValue: e, icon: i }) => /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: [
262
+ }, Be = ({ prefixValue: r, prefixSecondaryValue: e, icon: i }) => /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: [
262
263
  i && /* @__PURE__ */ a("span", { className: "flex items-center justify-center text-[var(--malachite-text-dimmed)] w-4 h-4 flex-shrink-0", children: i }),
263
264
  r && /* @__PURE__ */ a("span", { className: "text-[length:var(--malachite-font-size-medium,14px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap", children: r }),
264
265
  e && /* @__PURE__ */ a("span", { className: "text-[length:var(--malachite-font-size-medium,14px)] leading-[1.4] text-[var(--malachite-text-dimmed)] whitespace-nowrap", children: e })
@@ -281,7 +282,7 @@ const O = {
281
282
  "aria-hidden": "true",
282
283
  className: "flex items-center justify-center w-5 h-5 flex-shrink-0",
283
284
  children: /* @__PURE__ */ a(
284
- je,
285
+ Re,
285
286
  {
286
287
  size: 16,
287
288
  className: "text-[var(--malachite-destructive-foreground,rgb(196,62,62))]"
@@ -290,15 +291,15 @@ const O = {
290
291
  }
291
292
  ),
292
293
  g && i && e && /* @__PURE__ */ a(ke, { copied: b, onCopy: i }),
293
- m === "password" && h && /* @__PURE__ */ a(Y, { variant: "no-style", onClick: w, type: "button", size: "small", children: o ? /* @__PURE__ */ a(
294
+ m === "password" && h && /* @__PURE__ */ a(Q, { variant: "no-style", onClick: w, type: "button", size: "small", children: o ? /* @__PURE__ */ a(
294
295
  Se,
295
296
  {
296
297
  size: 16,
297
298
  style: { color: "var(--malachite-text-dimmed)" }
298
299
  }
299
300
  ) : /* @__PURE__ */ a(ze, { size: 16, style: { color: "var(--malachite-text-dimmed)" } }) })
300
- ] }), Be = ({ buttons: r }) => r != null && r.length ? /* @__PURE__ */ a(Q, { children: r.map((e) => /* @__PURE__ */ a(
301
- Y,
301
+ ] }), Ge = ({ buttons: r }) => r != null && r.length ? /* @__PURE__ */ a(K, { children: r.map((e) => /* @__PURE__ */ a(
302
+ Q,
302
303
  {
303
304
  variant: e.variant || (e.danger ? "destructive" : "outline"),
304
305
  size: e.size || "small",
@@ -312,6 +313,6 @@ const O = {
312
313
  e.label
313
314
  )) }) : null;
314
315
  export {
315
- Fe as default
316
+ aa as default
316
317
  };
317
318
  //# sourceMappingURL=Input.js.map