@cjlapao/ui-kit 0.2.30 → 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 +521 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +150 -0
- package/dist/index.d.cts +83 -100
- package/dist/index.d.ts +83 -100
- package/dist/index.js +509 -197
- 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.cjs
CHANGED
|
@@ -32,8 +32,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
32
32
|
// src/markdown.ts
|
|
33
33
|
var markdown_exports = {};
|
|
34
34
|
__export(markdown_exports, {
|
|
35
|
+
CodeBlock: () => CodeBlock,
|
|
35
36
|
HelpButton: () => HelpButton_default,
|
|
36
|
-
MarkdownEditor: () => MarkdownEditor_default
|
|
37
|
+
MarkdownEditor: () => MarkdownEditor_default,
|
|
38
|
+
createCodeBlockMarkdownComponents: () => createCodeBlockMarkdownComponents
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(markdown_exports);
|
|
39
41
|
|
|
@@ -113,6 +115,7 @@ var getSurfaceGlassFillClass = (color, opacity) => {
|
|
|
113
115
|
if (opacity === "clear") return 5;
|
|
114
116
|
return 15;
|
|
115
117
|
})();
|
|
118
|
+
if (color === "none") return `bg-white/${litOpacity} dark:bg-neutral-900/${drkOpacity}`;
|
|
116
119
|
const safeBase = GLASS_COLOR_SAFELIST.has(color) ? color : "neutral";
|
|
117
120
|
return `bg-${safeBase}-100/${litOpacity} dark:bg-${safeBase}-500/${drkOpacity}`;
|
|
118
121
|
};
|
|
@@ -219,6 +222,8 @@ var TRUE_COLORS = [
|
|
|
219
222
|
"neutral",
|
|
220
223
|
"stone"
|
|
221
224
|
];
|
|
225
|
+
var SURFACE_TONES = ["none", ...TRUE_COLORS];
|
|
226
|
+
var getSurfaceAccentColor = (tone) => tone === "none" ? "neutral" : tone;
|
|
222
227
|
var CONTROL_SIZES = ["xs", "sm", "md", "lg", "xl"];
|
|
223
228
|
var controlSizeTokens = {
|
|
224
229
|
xs: {
|
|
@@ -415,6 +420,7 @@ var FIELD_SIZE_STYLES = {
|
|
|
415
420
|
};
|
|
416
421
|
var getFieldSizeTokens = (size) => FIELD_SIZE_STYLES[size] ?? FIELD_SIZE_STYLES.md;
|
|
417
422
|
var SURFACE_VARIANTS = [
|
|
423
|
+
"none",
|
|
418
424
|
"elevated",
|
|
419
425
|
"outlined",
|
|
420
426
|
"subtle",
|
|
@@ -457,7 +463,7 @@ var surfaceTriggerTokens = Object.fromEntries(
|
|
|
457
463
|
}
|
|
458
464
|
])
|
|
459
465
|
);
|
|
460
|
-
var getSurfaceTriggerTokens = (color) => surfaceTriggerTokens[color] ?? surfaceTriggerTokens.
|
|
466
|
+
var getSurfaceTriggerTokens = (color) => surfaceTriggerTokens[getSurfaceAccentColor(color)] ?? surfaceTriggerTokens.neutral;
|
|
461
467
|
var collapsibleHelpToneTokens = Object.fromEntries(
|
|
462
468
|
TRUE_COLORS.map((color) => [
|
|
463
469
|
color,
|
|
@@ -485,8 +491,8 @@ var surfaceCornerClasses = {
|
|
|
485
491
|
};
|
|
486
492
|
var DEFAULT_SURFACE_CORNER = "rounded-md";
|
|
487
493
|
var isGlassSurface = (variant) => variant === "glass" || variant === "liquid-glass";
|
|
488
|
-
var PANEL_TONE_FOR_FIELD = "
|
|
489
|
-
var DEFAULT_SURFACE_TONE = "
|
|
494
|
+
var PANEL_TONE_FOR_FIELD = "none";
|
|
495
|
+
var DEFAULT_SURFACE_TONE = "none";
|
|
490
496
|
var getSurfaceCornerClass = (corner) => surfaceCornerClasses[corner === "auto" ? DEFAULT_SURFACE_CORNER : corner];
|
|
491
497
|
var SURFACE_PADDINGS = ["none", ...CONTROL_SIZES];
|
|
492
498
|
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";
|
|
@@ -861,7 +867,15 @@ var progressSpinnerToneTokens = Object.fromEntries(
|
|
|
861
867
|
);
|
|
862
868
|
var getLoaderProgressColors = (color) => currentTheme.loader[color] ?? currentTheme.loader.blue;
|
|
863
869
|
var getTabsColorTokens = (color) => currentTheme.tabs[color] ?? currentTheme.tabs.blue;
|
|
864
|
-
var getPanelToneStyles = (tone) =>
|
|
870
|
+
var getPanelToneStyles = (tone = DEFAULT_SURFACE_TONE) => tone === "none" ? {
|
|
871
|
+
...currentTheme.panel.neutral,
|
|
872
|
+
subtleBg: "bg-white dark:bg-neutral-900",
|
|
873
|
+
tonalBg: "bg-white dark:bg-neutral-900",
|
|
874
|
+
glassBg: "bg-white/40 dark:bg-neutral-900/20",
|
|
875
|
+
liquidBg: "bg-white/45 dark:bg-neutral-900/15",
|
|
876
|
+
decorationShape: "",
|
|
877
|
+
decorationGradient: ""
|
|
878
|
+
} : currentTheme.panel[tone] ?? currentTheme.panel.neutral;
|
|
865
879
|
var getBadgeColorClasses = (color) => currentTheme.badge[color] ?? currentTheme.badge.blue;
|
|
866
880
|
var getPillColorClasses = (color, variant) => currentTheme.pill[color]?.[variant] ?? currentTheme.pill.blue[variant];
|
|
867
881
|
|
|
@@ -2139,6 +2153,13 @@ var DE_KIT_CATALOG = {
|
|
|
2139
2153
|
// ../common/i18n/builtIn/en.ts
|
|
2140
2154
|
var EN_KIT_CATALOG = {
|
|
2141
2155
|
kit: {
|
|
2156
|
+
codeBlock: {
|
|
2157
|
+
code: "Code",
|
|
2158
|
+
edit: "Edit code",
|
|
2159
|
+
copy: "Copy code",
|
|
2160
|
+
copied: "Copied",
|
|
2161
|
+
copyFailed: "Could not copy code. Select and copy it manually."
|
|
2162
|
+
},
|
|
2142
2163
|
knowledge: {
|
|
2143
2164
|
"library": "Memory library",
|
|
2144
2165
|
"map": "Knowledge map",
|
|
@@ -10224,6 +10245,7 @@ function hasInteractiveDescendant(root) {
|
|
|
10224
10245
|
// src/components/Panel.tsx
|
|
10225
10246
|
var import_jsx_runtime159 = require("react/jsx-runtime");
|
|
10226
10247
|
var variantBaseStyles = {
|
|
10248
|
+
none: "",
|
|
10227
10249
|
elevated: "bg-white shadow-xl ring-1 ring-black/5 dark:bg-neutral-900 dark:ring-white/10",
|
|
10228
10250
|
// A real 1px border, not a ring. `ring-1` with no ring colour resolves to
|
|
10229
10251
|
// currentColor, which painted a near-black rule in light mode.
|
|
@@ -10473,6 +10495,8 @@ var Panel = import_react158.default.forwardRef(function Panel2({
|
|
|
10473
10495
|
const glassFillClass = getSurfaceGlassFillClass(resolvedTone, glassOpacity);
|
|
10474
10496
|
const variantClasses = getSurfaceTransparencyClasses((0, import_classnames7.default)((() => {
|
|
10475
10497
|
switch (variant) {
|
|
10498
|
+
case "none":
|
|
10499
|
+
return resolvedTone === "none" ? "" : palette.subtleBg;
|
|
10476
10500
|
case "outlined":
|
|
10477
10501
|
return (0, import_classnames7.default)(
|
|
10478
10502
|
variantBaseStyles.outlined,
|
|
@@ -13112,6 +13136,7 @@ var HelpButton = ({
|
|
|
13112
13136
|
content,
|
|
13113
13137
|
title,
|
|
13114
13138
|
placement = "auto",
|
|
13139
|
+
tone = "none",
|
|
13115
13140
|
color = "sky",
|
|
13116
13141
|
variant = "elevated",
|
|
13117
13142
|
corner = DEFAULT_SURFACE_CORNER,
|
|
@@ -13212,7 +13237,7 @@ var HelpButton = ({
|
|
|
13212
13237
|
Panel_default,
|
|
13213
13238
|
{
|
|
13214
13239
|
variant,
|
|
13215
|
-
tone
|
|
13240
|
+
tone,
|
|
13216
13241
|
corner,
|
|
13217
13242
|
padding: "none",
|
|
13218
13243
|
scrollable: false,
|
|
@@ -13295,9 +13320,142 @@ var HelpButton = ({
|
|
|
13295
13320
|
};
|
|
13296
13321
|
HelpButton.displayName = "HelpButton";
|
|
13297
13322
|
var HelpButton_default = HelpButton;
|
|
13323
|
+
|
|
13324
|
+
// src/CodeBlockMarkdown.tsx
|
|
13325
|
+
var import_react166 = __toESM(require("react"), 1);
|
|
13326
|
+
|
|
13327
|
+
// src/components/CodeBlock.tsx
|
|
13328
|
+
var import_react165 = __toESM(require("react"), 1);
|
|
13329
|
+
var import_refractor = require("refractor");
|
|
13330
|
+
var import_tsx = __toESM(require("refractor/tsx"), 1);
|
|
13331
|
+
var import_jsx_runtime168 = require("react/jsx-runtime");
|
|
13332
|
+
import_refractor.refractor.register(import_tsx.default);
|
|
13333
|
+
function tokenRuns(nodes, inherited = "") {
|
|
13334
|
+
return nodes.flatMap((node) => {
|
|
13335
|
+
if (node.type === "text") return [{ text: node.value, className: inherited }];
|
|
13336
|
+
if (node.type !== "element") return [];
|
|
13337
|
+
const classes = node.properties.className;
|
|
13338
|
+
const className = [inherited, Array.isArray(classes) ? classes.join(" ") : String(classes ?? "")].filter(Boolean).join(" ");
|
|
13339
|
+
return tokenRuns(node.children, className);
|
|
13340
|
+
});
|
|
13341
|
+
}
|
|
13342
|
+
function renderLines(runs, numbered, value) {
|
|
13343
|
+
const lines = [[]];
|
|
13344
|
+
let key = 0;
|
|
13345
|
+
for (const run of runs) {
|
|
13346
|
+
run.text.split("\n").forEach((text, index) => {
|
|
13347
|
+
if (index) lines.push([]);
|
|
13348
|
+
if (text) lines[lines.length - 1].push(/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: run.className || void 0, children: text }, key++));
|
|
13349
|
+
});
|
|
13350
|
+
}
|
|
13351
|
+
const digits = String(value.split("\n").length).length;
|
|
13352
|
+
return lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime168.jsxs)(import_react165.default.Fragment, { children: [
|
|
13353
|
+
index > 0 ? "\n" : null,
|
|
13354
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsxs)("span", { className: "ui-code-block-line", children: [
|
|
13355
|
+
numbered && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "ui-code-block-line-number", "aria-hidden": "true", "data-line": index + 1, style: { width: `${digits}ch` } }),
|
|
13356
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "ui-code-block-line-text", children: line })
|
|
13357
|
+
] })
|
|
13358
|
+
] }, index));
|
|
13359
|
+
}
|
|
13360
|
+
function CodeBlock({
|
|
13361
|
+
value,
|
|
13362
|
+
onChange,
|
|
13363
|
+
readOnly = true,
|
|
13364
|
+
language,
|
|
13365
|
+
filename,
|
|
13366
|
+
showTitle = true,
|
|
13367
|
+
showCopy = true,
|
|
13368
|
+
showLineNumbers = false,
|
|
13369
|
+
wrapLines = false,
|
|
13370
|
+
maxHeight,
|
|
13371
|
+
tone = "none",
|
|
13372
|
+
color = "blue",
|
|
13373
|
+
variant = "subtle",
|
|
13374
|
+
corner = "rounded-md",
|
|
13375
|
+
editorLabel,
|
|
13376
|
+
className,
|
|
13377
|
+
...rest
|
|
13378
|
+
}) {
|
|
13379
|
+
const t = useKitT();
|
|
13380
|
+
const [copyState, setCopyState] = (0, import_react165.useState)("idle");
|
|
13381
|
+
const timer = (0, import_react165.useRef)(void 0);
|
|
13382
|
+
const generation = (0, import_react165.useRef)(0);
|
|
13383
|
+
(0, import_react165.useEffect)(() => {
|
|
13384
|
+
generation.current++;
|
|
13385
|
+
setCopyState("idle");
|
|
13386
|
+
clearTimeout(timer.current);
|
|
13387
|
+
return () => {
|
|
13388
|
+
generation.current++;
|
|
13389
|
+
clearTimeout(timer.current);
|
|
13390
|
+
};
|
|
13391
|
+
}, [value]);
|
|
13392
|
+
const highlighted = (0, import_react165.useMemo)(() => {
|
|
13393
|
+
if (!readOnly || !language) return [{ text: value, className: "" }];
|
|
13394
|
+
try {
|
|
13395
|
+
return tokenRuns(import_refractor.refractor.highlight(value, language.toLowerCase()).children);
|
|
13396
|
+
} catch {
|
|
13397
|
+
return [{ text: value, className: "" }];
|
|
13398
|
+
}
|
|
13399
|
+
}, [value, language, readOnly]);
|
|
13400
|
+
const copy = async () => {
|
|
13401
|
+
const current = ++generation.current;
|
|
13402
|
+
clearTimeout(timer.current);
|
|
13403
|
+
try {
|
|
13404
|
+
await navigator.clipboard.writeText(value);
|
|
13405
|
+
if (current !== generation.current) return;
|
|
13406
|
+
setCopyState("success");
|
|
13407
|
+
} catch {
|
|
13408
|
+
if (current !== generation.current) return;
|
|
13409
|
+
setCopyState("error");
|
|
13410
|
+
}
|
|
13411
|
+
timer.current = setTimeout(() => setCopyState("idle"), 2e3);
|
|
13412
|
+
};
|
|
13413
|
+
const copyLabel = t(copyState === "success" ? "kit.codeBlock.copied" : "kit.codeBlock.copy");
|
|
13414
|
+
return /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("div", { ...rest, className: ["ui-code-block relative w-full min-w-0", className].filter(Boolean).join(" "), children: /* @__PURE__ */ (0, import_jsx_runtime168.jsxs)(Panel_default, { className: "ui-code-block-surface", tone, variant, corner, padding: "none", bodyClassName: "min-w-0 overflow-hidden", children: [
|
|
13415
|
+
(showTitle || showCopy) && /* @__PURE__ */ (0, import_jsx_runtime168.jsxs)("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: [
|
|
13416
|
+
showTitle && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "truncate font-mono text-xs", children: filename || language || t("kit.codeBlock.code") }),
|
|
13417
|
+
showCopy && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)(IconButton_default, { icon: copyState === "success" ? "Check" : "CopyClipboard", color, variant: "ghost", size: "xs", srLabel: copyLabel, tooltip: copyLabel, onClick: copy })
|
|
13418
|
+
] }),
|
|
13419
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)(
|
|
13420
|
+
ScrollArea_default,
|
|
13421
|
+
{
|
|
13422
|
+
variant: "hover",
|
|
13423
|
+
className: "ui-code-block-scroll",
|
|
13424
|
+
"data-wrap": wrapLines || void 0,
|
|
13425
|
+
style: { maxHeight },
|
|
13426
|
+
tabIndex: readOnly ? 0 : -1,
|
|
13427
|
+
role: "region",
|
|
13428
|
+
"aria-label": filename || t("kit.codeBlock.code"),
|
|
13429
|
+
children: readOnly ? /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("pre", { className: "ui-code-block-source", style: { whiteSpace: wrapLines ? "pre-wrap" : "pre", overflowWrap: wrapLines ? "anywhere" : void 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("code", { className: language ? `language-${language}` : void 0, children: renderLines(highlighted, showLineNumbers, value) }) }) : /* @__PURE__ */ (0, import_jsx_runtime168.jsxs)("div", { className: "ui-code-block-editor-layout", "data-wrap": wrapLines || void 0, children: [
|
|
13430
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("pre", { "aria-hidden": "true", className: "ui-code-block-editor-mirror", style: { whiteSpace: wrapLines ? "pre-wrap" : "pre", overflowWrap: wrapLines ? "anywhere" : void 0 }, children: value + "\n" }),
|
|
13431
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("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" })
|
|
13432
|
+
] })
|
|
13433
|
+
}
|
|
13434
|
+
),
|
|
13435
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "sr-only", role: "status", children: copyState === "success" ? t("kit.codeBlock.copied") : copyState === "error" ? t("kit.codeBlock.copyFailed") : "" }),
|
|
13436
|
+
copyState === "error" && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("p", { className: "px-4 pb-2 text-xs", children: t("kit.codeBlock.copyFailed") })
|
|
13437
|
+
] }) });
|
|
13438
|
+
}
|
|
13439
|
+
|
|
13440
|
+
// src/CodeBlockMarkdown.tsx
|
|
13441
|
+
var import_jsx_runtime169 = require("react/jsx-runtime");
|
|
13442
|
+
function createCodeBlockMarkdownComponents(options = {}) {
|
|
13443
|
+
return {
|
|
13444
|
+
pre: ({ children, node: _node, ref: _ref, ...props }) => {
|
|
13445
|
+
const child = import_react166.default.Children.toArray(children)[0];
|
|
13446
|
+
if (!import_react166.default.isValidElement(child) || typeof child.props.children !== "string") {
|
|
13447
|
+
return /* @__PURE__ */ (0, import_jsx_runtime169.jsx)("pre", { ...props, children });
|
|
13448
|
+
}
|
|
13449
|
+
const language = /(?:^|\s)language-([^\s]+)/.exec(child.props.className ?? "")?.[1];
|
|
13450
|
+
return /* @__PURE__ */ (0, import_jsx_runtime169.jsx)(CodeBlock, { ...options, value: child.props.children, language: language || options.language, readOnly: true });
|
|
13451
|
+
}
|
|
13452
|
+
};
|
|
13453
|
+
}
|
|
13298
13454
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13299
13455
|
0 && (module.exports = {
|
|
13456
|
+
CodeBlock,
|
|
13300
13457
|
HelpButton,
|
|
13301
|
-
MarkdownEditor
|
|
13458
|
+
MarkdownEditor,
|
|
13459
|
+
createCodeBlockMarkdownComponents
|
|
13302
13460
|
});
|
|
13303
13461
|
//# sourceMappingURL=markdown.cjs.map
|