@cjlapao/ui-kit 0.2.31 → 0.2.32
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/dist/{CapsuleBlueprint-DtgCXUPd.d.cts → CodeBlock-Dm0yAxf-.d.cts} +42 -8
- package/dist/{CapsuleBlueprint-DtgCXUPd.d.ts → CodeBlock-Dm0yAxf-.d.ts} +42 -8
- package/dist/index.cjs +458 -200
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +138 -0
- package/dist/index.d.cts +67 -100
- package/dist/index.d.ts +67 -100
- package/dist/index.js +447 -192
- package/dist/index.js.map +1 -1
- package/dist/markdown.cjs +165 -7
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +7 -3
- package/dist/markdown.d.ts +7 -3
- package/dist/markdown.js +162 -6
- package/dist/markdown.js.map +1 -1
- package/package.json +4 -2
package/dist/markdown.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { w as CapsuleBlueprintParameter, a0 as CodeBlockProps } from './CodeBlock-Dm0yAxf-.cjs';
|
|
3
|
+
export { $ as CodeBlock, an as HelpButton } from './CodeBlock-Dm0yAxf-.cjs';
|
|
4
|
+
import { Components } from 'react-markdown';
|
|
4
5
|
|
|
5
6
|
interface MarkdownEditorProps {
|
|
6
7
|
value?: string;
|
|
@@ -19,4 +20,7 @@ interface MarkdownEditorProps {
|
|
|
19
20
|
}
|
|
20
21
|
declare const MarkdownEditor: React__default.FC<MarkdownEditorProps>;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
/** Override React Markdown's pre renderer; inline code keeps its native renderer. */
|
|
24
|
+
declare function createCodeBlockMarkdownComponents(options?: Omit<CodeBlockProps, "value" | "onChange" | "readOnly">): Components;
|
|
25
|
+
|
|
26
|
+
export { CodeBlockProps, MarkdownEditor, createCodeBlockMarkdownComponents };
|
package/dist/markdown.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React__default from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { w as CapsuleBlueprintParameter, a0 as CodeBlockProps } from './CodeBlock-Dm0yAxf-.js';
|
|
3
|
+
export { $ as CodeBlock, an as HelpButton } from './CodeBlock-Dm0yAxf-.js';
|
|
4
|
+
import { Components } from 'react-markdown';
|
|
4
5
|
|
|
5
6
|
interface MarkdownEditorProps {
|
|
6
7
|
value?: string;
|
|
@@ -19,4 +20,7 @@ interface MarkdownEditorProps {
|
|
|
19
20
|
}
|
|
20
21
|
declare const MarkdownEditor: React__default.FC<MarkdownEditorProps>;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
/** Override React Markdown's pre renderer; inline code keeps its native renderer. */
|
|
24
|
+
declare function createCodeBlockMarkdownComponents(options?: Omit<CodeBlockProps, "value" | "onChange" | "readOnly">): Components;
|
|
25
|
+
|
|
26
|
+
export { CodeBlockProps, MarkdownEditor, createCodeBlockMarkdownComponents };
|
package/dist/markdown.js
CHANGED
|
@@ -78,6 +78,7 @@ var getSurfaceGlassFillClass = (color, opacity) => {
|
|
|
78
78
|
if (opacity === "clear") return 5;
|
|
79
79
|
return 15;
|
|
80
80
|
})();
|
|
81
|
+
if (color === "none") return `bg-white/${litOpacity} dark:bg-neutral-900/${drkOpacity}`;
|
|
81
82
|
const safeBase = GLASS_COLOR_SAFELIST.has(color) ? color : "neutral";
|
|
82
83
|
return `bg-${safeBase}-100/${litOpacity} dark:bg-${safeBase}-500/${drkOpacity}`;
|
|
83
84
|
};
|
|
@@ -184,6 +185,8 @@ var TRUE_COLORS = [
|
|
|
184
185
|
"neutral",
|
|
185
186
|
"stone"
|
|
186
187
|
];
|
|
188
|
+
var SURFACE_TONES = ["none", ...TRUE_COLORS];
|
|
189
|
+
var getSurfaceAccentColor = (tone) => tone === "none" ? "neutral" : tone;
|
|
187
190
|
var CONTROL_SIZES = ["xs", "sm", "md", "lg", "xl"];
|
|
188
191
|
var controlSizeTokens = {
|
|
189
192
|
xs: {
|
|
@@ -380,6 +383,7 @@ var FIELD_SIZE_STYLES = {
|
|
|
380
383
|
};
|
|
381
384
|
var getFieldSizeTokens = (size) => FIELD_SIZE_STYLES[size] ?? FIELD_SIZE_STYLES.md;
|
|
382
385
|
var SURFACE_VARIANTS = [
|
|
386
|
+
"none",
|
|
383
387
|
"elevated",
|
|
384
388
|
"outlined",
|
|
385
389
|
"subtle",
|
|
@@ -422,7 +426,7 @@ var surfaceTriggerTokens = Object.fromEntries(
|
|
|
422
426
|
}
|
|
423
427
|
])
|
|
424
428
|
);
|
|
425
|
-
var getSurfaceTriggerTokens = (color) => surfaceTriggerTokens[color] ?? surfaceTriggerTokens.
|
|
429
|
+
var getSurfaceTriggerTokens = (color) => surfaceTriggerTokens[getSurfaceAccentColor(color)] ?? surfaceTriggerTokens.neutral;
|
|
426
430
|
var collapsibleHelpToneTokens = Object.fromEntries(
|
|
427
431
|
TRUE_COLORS.map((color) => [
|
|
428
432
|
color,
|
|
@@ -450,8 +454,8 @@ var surfaceCornerClasses = {
|
|
|
450
454
|
};
|
|
451
455
|
var DEFAULT_SURFACE_CORNER = "rounded-md";
|
|
452
456
|
var isGlassSurface = (variant) => variant === "glass" || variant === "liquid-glass";
|
|
453
|
-
var PANEL_TONE_FOR_FIELD = "
|
|
454
|
-
var DEFAULT_SURFACE_TONE = "
|
|
457
|
+
var PANEL_TONE_FOR_FIELD = "none";
|
|
458
|
+
var DEFAULT_SURFACE_TONE = "none";
|
|
455
459
|
var getSurfaceCornerClass = (corner) => surfaceCornerClasses[corner === "auto" ? DEFAULT_SURFACE_CORNER : corner];
|
|
456
460
|
var SURFACE_PADDINGS = ["none", ...CONTROL_SIZES];
|
|
457
461
|
var THIN_SCROLLBAR = "[&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-neutral-200 dark:[&::-webkit-scrollbar-thumb]:bg-neutral-700 hover:[&::-webkit-scrollbar-thumb]:bg-neutral-300 dark:hover:[&::-webkit-scrollbar-thumb]:bg-neutral-600 [&::-webkit-scrollbar-track]:bg-transparent";
|
|
@@ -826,7 +830,15 @@ var progressSpinnerToneTokens = Object.fromEntries(
|
|
|
826
830
|
);
|
|
827
831
|
var getLoaderProgressColors = (color) => currentTheme.loader[color] ?? currentTheme.loader.blue;
|
|
828
832
|
var getTabsColorTokens = (color) => currentTheme.tabs[color] ?? currentTheme.tabs.blue;
|
|
829
|
-
var getPanelToneStyles = (tone) =>
|
|
833
|
+
var getPanelToneStyles = (tone = DEFAULT_SURFACE_TONE) => tone === "none" ? {
|
|
834
|
+
...currentTheme.panel.neutral,
|
|
835
|
+
subtleBg: "bg-white dark:bg-neutral-900",
|
|
836
|
+
tonalBg: "bg-white dark:bg-neutral-900",
|
|
837
|
+
glassBg: "bg-white/40 dark:bg-neutral-900/20",
|
|
838
|
+
liquidBg: "bg-white/45 dark:bg-neutral-900/15",
|
|
839
|
+
decorationShape: "",
|
|
840
|
+
decorationGradient: ""
|
|
841
|
+
} : currentTheme.panel[tone] ?? currentTheme.panel.neutral;
|
|
830
842
|
var getBadgeColorClasses = (color) => currentTheme.badge[color] ?? currentTheme.badge.blue;
|
|
831
843
|
var getPillColorClasses = (color, variant) => currentTheme.pill[color]?.[variant] ?? currentTheme.pill.blue[variant];
|
|
832
844
|
|
|
@@ -2109,6 +2121,13 @@ var DE_KIT_CATALOG = {
|
|
|
2109
2121
|
// ../common/i18n/builtIn/en.ts
|
|
2110
2122
|
var EN_KIT_CATALOG = {
|
|
2111
2123
|
kit: {
|
|
2124
|
+
codeBlock: {
|
|
2125
|
+
code: "Code",
|
|
2126
|
+
edit: "Edit code",
|
|
2127
|
+
copy: "Copy code",
|
|
2128
|
+
copied: "Copied",
|
|
2129
|
+
copyFailed: "Could not copy code. Select and copy it manually."
|
|
2130
|
+
},
|
|
2112
2131
|
knowledge: {
|
|
2113
2132
|
"library": "Memory library",
|
|
2114
2133
|
"map": "Knowledge map",
|
|
@@ -10202,6 +10221,7 @@ function hasInteractiveDescendant(root) {
|
|
|
10202
10221
|
// src/components/Panel.tsx
|
|
10203
10222
|
import { Fragment as Fragment3, jsx as jsx159, jsxs as jsxs60 } from "react/jsx-runtime";
|
|
10204
10223
|
var variantBaseStyles = {
|
|
10224
|
+
none: "",
|
|
10205
10225
|
elevated: "bg-white shadow-xl ring-1 ring-black/5 dark:bg-neutral-900 dark:ring-white/10",
|
|
10206
10226
|
// A real 1px border, not a ring. `ring-1` with no ring colour resolves to
|
|
10207
10227
|
// currentColor, which painted a near-black rule in light mode.
|
|
@@ -10451,6 +10471,8 @@ var Panel = React10.forwardRef(function Panel2({
|
|
|
10451
10471
|
const glassFillClass = getSurfaceGlassFillClass(resolvedTone, glassOpacity);
|
|
10452
10472
|
const variantClasses = getSurfaceTransparencyClasses(classNames7((() => {
|
|
10453
10473
|
switch (variant) {
|
|
10474
|
+
case "none":
|
|
10475
|
+
return resolvedTone === "none" ? "" : palette.subtleBg;
|
|
10454
10476
|
case "outlined":
|
|
10455
10477
|
return classNames7(
|
|
10456
10478
|
variantBaseStyles.outlined,
|
|
@@ -13101,6 +13123,7 @@ var HelpButton = ({
|
|
|
13101
13123
|
content,
|
|
13102
13124
|
title,
|
|
13103
13125
|
placement = "auto",
|
|
13126
|
+
tone = "none",
|
|
13104
13127
|
color = "sky",
|
|
13105
13128
|
variant = "elevated",
|
|
13106
13129
|
corner = DEFAULT_SURFACE_CORNER,
|
|
@@ -13201,7 +13224,7 @@ var HelpButton = ({
|
|
|
13201
13224
|
Panel_default,
|
|
13202
13225
|
{
|
|
13203
13226
|
variant,
|
|
13204
|
-
tone
|
|
13227
|
+
tone,
|
|
13205
13228
|
corner,
|
|
13206
13229
|
padding: "none",
|
|
13207
13230
|
scrollable: false,
|
|
@@ -13284,8 +13307,141 @@ var HelpButton = ({
|
|
|
13284
13307
|
};
|
|
13285
13308
|
HelpButton.displayName = "HelpButton";
|
|
13286
13309
|
var HelpButton_default = HelpButton;
|
|
13310
|
+
|
|
13311
|
+
// src/CodeBlockMarkdown.tsx
|
|
13312
|
+
import React17 from "react";
|
|
13313
|
+
|
|
13314
|
+
// src/components/CodeBlock.tsx
|
|
13315
|
+
import React16, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef8, useState as useState8 } from "react";
|
|
13316
|
+
import { refractor } from "refractor";
|
|
13317
|
+
import tsx from "refractor/tsx";
|
|
13318
|
+
import { jsx as jsx168, jsxs as jsxs69 } from "react/jsx-runtime";
|
|
13319
|
+
refractor.register(tsx);
|
|
13320
|
+
function tokenRuns(nodes, inherited = "") {
|
|
13321
|
+
return nodes.flatMap((node) => {
|
|
13322
|
+
if (node.type === "text") return [{ text: node.value, className: inherited }];
|
|
13323
|
+
if (node.type !== "element") return [];
|
|
13324
|
+
const classes = node.properties.className;
|
|
13325
|
+
const className = [inherited, Array.isArray(classes) ? classes.join(" ") : String(classes ?? "")].filter(Boolean).join(" ");
|
|
13326
|
+
return tokenRuns(node.children, className);
|
|
13327
|
+
});
|
|
13328
|
+
}
|
|
13329
|
+
function renderLines(runs, numbered, value) {
|
|
13330
|
+
const lines = [[]];
|
|
13331
|
+
let key = 0;
|
|
13332
|
+
for (const run of runs) {
|
|
13333
|
+
run.text.split("\n").forEach((text, index) => {
|
|
13334
|
+
if (index) lines.push([]);
|
|
13335
|
+
if (text) lines[lines.length - 1].push(/* @__PURE__ */ jsx168("span", { className: run.className || void 0, children: text }, key++));
|
|
13336
|
+
});
|
|
13337
|
+
}
|
|
13338
|
+
const digits = String(value.split("\n").length).length;
|
|
13339
|
+
return lines.map((line, index) => /* @__PURE__ */ jsxs69(React16.Fragment, { children: [
|
|
13340
|
+
index > 0 ? "\n" : null,
|
|
13341
|
+
/* @__PURE__ */ jsxs69("span", { className: "ui-code-block-line", children: [
|
|
13342
|
+
numbered && /* @__PURE__ */ jsx168("span", { className: "ui-code-block-line-number", "aria-hidden": "true", "data-line": index + 1, style: { width: `${digits}ch` } }),
|
|
13343
|
+
/* @__PURE__ */ jsx168("span", { className: "ui-code-block-line-text", children: line })
|
|
13344
|
+
] })
|
|
13345
|
+
] }, index));
|
|
13346
|
+
}
|
|
13347
|
+
function CodeBlock({
|
|
13348
|
+
value,
|
|
13349
|
+
onChange,
|
|
13350
|
+
readOnly = true,
|
|
13351
|
+
language,
|
|
13352
|
+
filename,
|
|
13353
|
+
showTitle = true,
|
|
13354
|
+
showCopy = true,
|
|
13355
|
+
showLineNumbers = false,
|
|
13356
|
+
wrapLines = false,
|
|
13357
|
+
maxHeight,
|
|
13358
|
+
tone = "none",
|
|
13359
|
+
color = "blue",
|
|
13360
|
+
variant = "subtle",
|
|
13361
|
+
corner = "rounded-md",
|
|
13362
|
+
editorLabel,
|
|
13363
|
+
className,
|
|
13364
|
+
...rest
|
|
13365
|
+
}) {
|
|
13366
|
+
const t = useKitT();
|
|
13367
|
+
const [copyState, setCopyState] = useState8("idle");
|
|
13368
|
+
const timer = useRef8(void 0);
|
|
13369
|
+
const generation = useRef8(0);
|
|
13370
|
+
useEffect7(() => {
|
|
13371
|
+
generation.current++;
|
|
13372
|
+
setCopyState("idle");
|
|
13373
|
+
clearTimeout(timer.current);
|
|
13374
|
+
return () => {
|
|
13375
|
+
generation.current++;
|
|
13376
|
+
clearTimeout(timer.current);
|
|
13377
|
+
};
|
|
13378
|
+
}, [value]);
|
|
13379
|
+
const highlighted = useMemo6(() => {
|
|
13380
|
+
if (!readOnly || !language) return [{ text: value, className: "" }];
|
|
13381
|
+
try {
|
|
13382
|
+
return tokenRuns(refractor.highlight(value, language.toLowerCase()).children);
|
|
13383
|
+
} catch {
|
|
13384
|
+
return [{ text: value, className: "" }];
|
|
13385
|
+
}
|
|
13386
|
+
}, [value, language, readOnly]);
|
|
13387
|
+
const copy = async () => {
|
|
13388
|
+
const current = ++generation.current;
|
|
13389
|
+
clearTimeout(timer.current);
|
|
13390
|
+
try {
|
|
13391
|
+
await navigator.clipboard.writeText(value);
|
|
13392
|
+
if (current !== generation.current) return;
|
|
13393
|
+
setCopyState("success");
|
|
13394
|
+
} catch {
|
|
13395
|
+
if (current !== generation.current) return;
|
|
13396
|
+
setCopyState("error");
|
|
13397
|
+
}
|
|
13398
|
+
timer.current = setTimeout(() => setCopyState("idle"), 2e3);
|
|
13399
|
+
};
|
|
13400
|
+
const copyLabel = t(copyState === "success" ? "kit.codeBlock.copied" : "kit.codeBlock.copy");
|
|
13401
|
+
return /* @__PURE__ */ jsx168("div", { ...rest, className: ["ui-code-block relative w-full min-w-0", className].filter(Boolean).join(" "), children: /* @__PURE__ */ jsxs69(Panel_default, { className: "ui-code-block-surface", tone, variant, corner, padding: "none", bodyClassName: "min-w-0 overflow-hidden", children: [
|
|
13402
|
+
(showTitle || showCopy) && /* @__PURE__ */ jsxs69("div", { "data-slot": "code-block-header", className: `relative flex min-w-0 items-center gap-3 px-4 py-2 ${showTitle ? "justify-between border-b border-current/10" : "justify-end"}`, children: [
|
|
13403
|
+
showTitle && /* @__PURE__ */ jsx168("span", { className: "truncate font-mono text-xs", children: filename || language || t("kit.codeBlock.code") }),
|
|
13404
|
+
showCopy && /* @__PURE__ */ jsx168(IconButton_default, { icon: copyState === "success" ? "Check" : "CopyClipboard", color, variant: "ghost", size: "xs", srLabel: copyLabel, tooltip: copyLabel, onClick: copy })
|
|
13405
|
+
] }),
|
|
13406
|
+
/* @__PURE__ */ jsx168(
|
|
13407
|
+
ScrollArea_default,
|
|
13408
|
+
{
|
|
13409
|
+
variant: "hover",
|
|
13410
|
+
className: "ui-code-block-scroll",
|
|
13411
|
+
"data-wrap": wrapLines || void 0,
|
|
13412
|
+
style: { maxHeight },
|
|
13413
|
+
tabIndex: readOnly ? 0 : -1,
|
|
13414
|
+
role: "region",
|
|
13415
|
+
"aria-label": filename || t("kit.codeBlock.code"),
|
|
13416
|
+
children: readOnly ? /* @__PURE__ */ jsx168("pre", { className: "ui-code-block-source", style: { whiteSpace: wrapLines ? "pre-wrap" : "pre", overflowWrap: wrapLines ? "anywhere" : void 0 }, children: /* @__PURE__ */ jsx168("code", { className: language ? `language-${language}` : void 0, children: renderLines(highlighted, showLineNumbers, value) }) }) : /* @__PURE__ */ jsxs69("div", { className: "ui-code-block-editor-layout", "data-wrap": wrapLines || void 0, children: [
|
|
13417
|
+
/* @__PURE__ */ jsx168("pre", { "aria-hidden": "true", className: "ui-code-block-editor-mirror", style: { whiteSpace: wrapLines ? "pre-wrap" : "pre", overflowWrap: wrapLines ? "anywhere" : void 0 }, children: value + "\n" }),
|
|
13418
|
+
/* @__PURE__ */ jsx168("textarea", { className: "ui-code-block-editor", "aria-label": editorLabel || t("kit.codeBlock.edit"), value, onChange: (event) => onChange?.(event.target.value), spellCheck: false, autoCapitalize: "off", autoCorrect: "off", wrap: wrapLines ? "soft" : "off" })
|
|
13419
|
+
] })
|
|
13420
|
+
}
|
|
13421
|
+
),
|
|
13422
|
+
/* @__PURE__ */ jsx168("span", { className: "sr-only", role: "status", children: copyState === "success" ? t("kit.codeBlock.copied") : copyState === "error" ? t("kit.codeBlock.copyFailed") : "" }),
|
|
13423
|
+
copyState === "error" && /* @__PURE__ */ jsx168("p", { className: "px-4 pb-2 text-xs", children: t("kit.codeBlock.copyFailed") })
|
|
13424
|
+
] }) });
|
|
13425
|
+
}
|
|
13426
|
+
|
|
13427
|
+
// src/CodeBlockMarkdown.tsx
|
|
13428
|
+
import { jsx as jsx169 } from "react/jsx-runtime";
|
|
13429
|
+
function createCodeBlockMarkdownComponents(options = {}) {
|
|
13430
|
+
return {
|
|
13431
|
+
pre: ({ children, node: _node, ref: _ref, ...props }) => {
|
|
13432
|
+
const child = React17.Children.toArray(children)[0];
|
|
13433
|
+
if (!React17.isValidElement(child) || typeof child.props.children !== "string") {
|
|
13434
|
+
return /* @__PURE__ */ jsx169("pre", { ...props, children });
|
|
13435
|
+
}
|
|
13436
|
+
const language = /(?:^|\s)language-([^\s]+)/.exec(child.props.className ?? "")?.[1];
|
|
13437
|
+
return /* @__PURE__ */ jsx169(CodeBlock, { ...options, value: child.props.children, language: language || options.language, readOnly: true });
|
|
13438
|
+
}
|
|
13439
|
+
};
|
|
13440
|
+
}
|
|
13287
13441
|
export {
|
|
13442
|
+
CodeBlock,
|
|
13288
13443
|
HelpButton_default as HelpButton,
|
|
13289
|
-
MarkdownEditor_default as MarkdownEditor
|
|
13444
|
+
MarkdownEditor_default as MarkdownEditor,
|
|
13445
|
+
createCodeBlockMarkdownComponents
|
|
13290
13446
|
};
|
|
13291
13447
|
//# sourceMappingURL=markdown.js.map
|