@cjlapao/ui-kit 0.2.31 → 0.2.33
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-QDW3hqU0.d.cts} +43 -9
- package/dist/{CapsuleBlueprint-DtgCXUPd.d.ts → CodeBlock-QDW3hqU0.d.ts} +43 -9
- package/dist/index.cjs +912 -231
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +813 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +186 -103
- package/dist/index.d.ts +186 -103
- package/dist/index.js +901 -224
- package/dist/index.js.map +1 -1
- package/dist/markdown.cjs +267 -10
- 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 +264 -9
- 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
|
|
|
@@ -1643,6 +1657,13 @@ function getLocalizedParseNames(locale, catalog) {
|
|
|
1643
1657
|
// ../common/i18n/builtIn/de.ts
|
|
1644
1658
|
var DE_KIT_CATALOG = {
|
|
1645
1659
|
kit: {
|
|
1660
|
+
codeBlock: {
|
|
1661
|
+
code: "Code",
|
|
1662
|
+
edit: "Code bearbeiten",
|
|
1663
|
+
copy: "Code kopieren",
|
|
1664
|
+
copied: "Kopiert",
|
|
1665
|
+
copyFailed: "Kopieren fehlgeschlagen. Code ausw\xE4hlen und manuell kopieren."
|
|
1666
|
+
},
|
|
1646
1667
|
knowledge: {
|
|
1647
1668
|
"library": "Erinnerungsbibliothek",
|
|
1648
1669
|
"map": "Wissenskarte",
|
|
@@ -1915,6 +1936,20 @@ var DE_KIT_CATALOG = {
|
|
|
1915
1936
|
progressspinner: {
|
|
1916
1937
|
loading: "Wird geladen"
|
|
1917
1938
|
},
|
|
1939
|
+
filterbar: {
|
|
1940
|
+
filters: "Filter",
|
|
1941
|
+
search: "Suchen",
|
|
1942
|
+
empty: "Keine Filter angewendet",
|
|
1943
|
+
add: "Filter hinzuf\xFCgen",
|
|
1944
|
+
filterBy: "Filtern nach",
|
|
1945
|
+
back: "Zur\xFCck",
|
|
1946
|
+
clear: "Leeren",
|
|
1947
|
+
done: "Fertig",
|
|
1948
|
+
clearAll: "Alle l\xF6schen",
|
|
1949
|
+
items: "Eintr\xE4ge",
|
|
1950
|
+
summary: "{filtered} von {total} {items}",
|
|
1951
|
+
remove: "Filter {label} entfernen"
|
|
1952
|
+
},
|
|
1918
1953
|
searchbar: {
|
|
1919
1954
|
clearAria: "Suche l\xF6schen",
|
|
1920
1955
|
placeholder: "Suchen..."
|
|
@@ -2139,6 +2174,13 @@ var DE_KIT_CATALOG = {
|
|
|
2139
2174
|
// ../common/i18n/builtIn/en.ts
|
|
2140
2175
|
var EN_KIT_CATALOG = {
|
|
2141
2176
|
kit: {
|
|
2177
|
+
codeBlock: {
|
|
2178
|
+
code: "Code",
|
|
2179
|
+
edit: "Edit code",
|
|
2180
|
+
copy: "Copy code",
|
|
2181
|
+
copied: "Copied",
|
|
2182
|
+
copyFailed: "Could not copy code. Select and copy it manually."
|
|
2183
|
+
},
|
|
2142
2184
|
knowledge: {
|
|
2143
2185
|
"library": "Memory library",
|
|
2144
2186
|
"map": "Knowledge map",
|
|
@@ -2411,6 +2453,20 @@ var EN_KIT_CATALOG = {
|
|
|
2411
2453
|
progressspinner: {
|
|
2412
2454
|
loading: "Loading"
|
|
2413
2455
|
},
|
|
2456
|
+
filterbar: {
|
|
2457
|
+
filters: "Filters",
|
|
2458
|
+
search: "Search",
|
|
2459
|
+
empty: "No filters applied",
|
|
2460
|
+
add: "Add filter",
|
|
2461
|
+
filterBy: "Filter by",
|
|
2462
|
+
back: "Back",
|
|
2463
|
+
clear: "Clear",
|
|
2464
|
+
done: "Done",
|
|
2465
|
+
clearAll: "Clear all",
|
|
2466
|
+
items: "items",
|
|
2467
|
+
summary: "{filtered} of {total} {items}",
|
|
2468
|
+
remove: "Remove {label} filter"
|
|
2469
|
+
},
|
|
2414
2470
|
searchbar: {
|
|
2415
2471
|
clearAria: "Clear search",
|
|
2416
2472
|
placeholder: "Search..."
|
|
@@ -2635,6 +2691,13 @@ var EN_KIT_CATALOG = {
|
|
|
2635
2691
|
// ../common/i18n/builtIn/es.ts
|
|
2636
2692
|
var ES_KIT_CATALOG = {
|
|
2637
2693
|
kit: {
|
|
2694
|
+
codeBlock: {
|
|
2695
|
+
code: "C\xF3digo",
|
|
2696
|
+
edit: "Editar c\xF3digo",
|
|
2697
|
+
copy: "Copiar c\xF3digo",
|
|
2698
|
+
copied: "Copiado",
|
|
2699
|
+
copyFailed: "No se pudo copiar. Selecciona y copia el c\xF3digo manualmente."
|
|
2700
|
+
},
|
|
2638
2701
|
knowledge: {
|
|
2639
2702
|
"library": "Biblioteca de memorias",
|
|
2640
2703
|
"map": "Mapa de conocimiento",
|
|
@@ -2907,6 +2970,20 @@ var ES_KIT_CATALOG = {
|
|
|
2907
2970
|
progressspinner: {
|
|
2908
2971
|
loading: "Cargando"
|
|
2909
2972
|
},
|
|
2973
|
+
filterbar: {
|
|
2974
|
+
filters: "Filtros",
|
|
2975
|
+
search: "Buscar",
|
|
2976
|
+
empty: "Sin filtros aplicados",
|
|
2977
|
+
add: "A\xF1adir filtro",
|
|
2978
|
+
filterBy: "Filtrar por",
|
|
2979
|
+
back: "Volver",
|
|
2980
|
+
clear: "Limpiar",
|
|
2981
|
+
done: "Listo",
|
|
2982
|
+
clearAll: "Borrar todos",
|
|
2983
|
+
items: "elementos",
|
|
2984
|
+
summary: "{filtered} de {total} {items}",
|
|
2985
|
+
remove: "Eliminar filtro {label}"
|
|
2986
|
+
},
|
|
2910
2987
|
searchbar: {
|
|
2911
2988
|
clearAria: "Borrar b\xFAsqueda",
|
|
2912
2989
|
placeholder: "Buscar..."
|
|
@@ -3131,6 +3208,13 @@ var ES_KIT_CATALOG = {
|
|
|
3131
3208
|
// ../common/i18n/builtIn/fr.ts
|
|
3132
3209
|
var FR_KIT_CATALOG = {
|
|
3133
3210
|
kit: {
|
|
3211
|
+
codeBlock: {
|
|
3212
|
+
code: "Code",
|
|
3213
|
+
edit: "Modifier le code",
|
|
3214
|
+
copy: "Copier le code",
|
|
3215
|
+
copied: "Copi\xE9",
|
|
3216
|
+
copyFailed: "Copie impossible. S\xE9lectionnez et copiez le code manuellement."
|
|
3217
|
+
},
|
|
3134
3218
|
knowledge: {
|
|
3135
3219
|
"library": "Biblioth\xE8que de m\xE9moires",
|
|
3136
3220
|
"map": "Carte des connaissances",
|
|
@@ -3403,6 +3487,20 @@ var FR_KIT_CATALOG = {
|
|
|
3403
3487
|
progressspinner: {
|
|
3404
3488
|
loading: "Chargement"
|
|
3405
3489
|
},
|
|
3490
|
+
filterbar: {
|
|
3491
|
+
filters: "Filtres",
|
|
3492
|
+
search: "Rechercher",
|
|
3493
|
+
empty: "Aucun filtre appliqu\xE9",
|
|
3494
|
+
add: "Ajouter un filtre",
|
|
3495
|
+
filterBy: "Filtrer par",
|
|
3496
|
+
back: "Retour",
|
|
3497
|
+
clear: "Effacer",
|
|
3498
|
+
done: "Termin\xE9",
|
|
3499
|
+
clearAll: "Tout effacer",
|
|
3500
|
+
items: "\xE9l\xE9ments",
|
|
3501
|
+
summary: "{filtered} sur {total} {items}",
|
|
3502
|
+
remove: "Supprimer le filtre {label}"
|
|
3503
|
+
},
|
|
3406
3504
|
searchbar: {
|
|
3407
3505
|
clearAria: "Effacer la recherche",
|
|
3408
3506
|
placeholder: "Rechercher..."
|
|
@@ -3627,6 +3725,13 @@ var FR_KIT_CATALOG = {
|
|
|
3627
3725
|
// ../common/i18n/builtIn/pt.ts
|
|
3628
3726
|
var PT_KIT_CATALOG = {
|
|
3629
3727
|
kit: {
|
|
3728
|
+
codeBlock: {
|
|
3729
|
+
code: "C\xF3digo",
|
|
3730
|
+
edit: "Editar c\xF3digo",
|
|
3731
|
+
copy: "Copiar c\xF3digo",
|
|
3732
|
+
copied: "Copiado",
|
|
3733
|
+
copyFailed: "N\xE3o foi poss\xEDvel copiar. Selecione e copie o c\xF3digo manualmente."
|
|
3734
|
+
},
|
|
3630
3735
|
knowledge: {
|
|
3631
3736
|
"library": "Biblioteca de mem\xF3rias",
|
|
3632
3737
|
"map": "Mapa de conhecimento",
|
|
@@ -3899,6 +4004,20 @@ var PT_KIT_CATALOG = {
|
|
|
3899
4004
|
progressspinner: {
|
|
3900
4005
|
loading: "Carregando"
|
|
3901
4006
|
},
|
|
4007
|
+
filterbar: {
|
|
4008
|
+
filters: "Filtros",
|
|
4009
|
+
search: "Pesquisar",
|
|
4010
|
+
empty: "Nenhum filtro aplicado",
|
|
4011
|
+
add: "Adicionar filtro",
|
|
4012
|
+
filterBy: "Filtrar por",
|
|
4013
|
+
back: "Voltar",
|
|
4014
|
+
clear: "Limpar",
|
|
4015
|
+
done: "Conclu\xEDdo",
|
|
4016
|
+
clearAll: "Limpar todos",
|
|
4017
|
+
items: "itens",
|
|
4018
|
+
summary: "{filtered} de {total} {items}",
|
|
4019
|
+
remove: "Remover filtro {label}"
|
|
4020
|
+
},
|
|
3902
4021
|
searchbar: {
|
|
3903
4022
|
clearAria: "Limpar busca",
|
|
3904
4023
|
placeholder: "Buscar..."
|
|
@@ -10224,6 +10343,7 @@ function hasInteractiveDescendant(root) {
|
|
|
10224
10343
|
// src/components/Panel.tsx
|
|
10225
10344
|
var import_jsx_runtime159 = require("react/jsx-runtime");
|
|
10226
10345
|
var variantBaseStyles = {
|
|
10346
|
+
none: "",
|
|
10227
10347
|
elevated: "bg-white shadow-xl ring-1 ring-black/5 dark:bg-neutral-900 dark:ring-white/10",
|
|
10228
10348
|
// A real 1px border, not a ring. `ring-1` with no ring colour resolves to
|
|
10229
10349
|
// currentColor, which painted a near-black rule in light mode.
|
|
@@ -10438,7 +10558,7 @@ var Panel = import_react158.default.forwardRef(function Panel2({
|
|
|
10438
10558
|
if (specularHighlight === false) return "none";
|
|
10439
10559
|
return "classic";
|
|
10440
10560
|
})();
|
|
10441
|
-
const effectiveHoverColor = hoverColor ?? (
|
|
10561
|
+
const effectiveHoverColor = hoverColor ?? (resolvedTone !== "none" && resolvedTone !== "neutral" ? resolvedTone : void 0);
|
|
10442
10562
|
const hoverColorName = effectiveHoverColor ? effectiveHoverColor : void 0;
|
|
10443
10563
|
const borderPalette = borderColor ? getPanelToneStyles(borderColor) : void 0;
|
|
10444
10564
|
const effectiveBorderClass = borderPalette?.border;
|
|
@@ -10473,6 +10593,8 @@ var Panel = import_react158.default.forwardRef(function Panel2({
|
|
|
10473
10593
|
const glassFillClass = getSurfaceGlassFillClass(resolvedTone, glassOpacity);
|
|
10474
10594
|
const variantClasses = getSurfaceTransparencyClasses((0, import_classnames7.default)((() => {
|
|
10475
10595
|
switch (variant) {
|
|
10596
|
+
case "none":
|
|
10597
|
+
return resolvedTone === "none" ? "" : palette.subtleBg;
|
|
10476
10598
|
case "outlined":
|
|
10477
10599
|
return (0, import_classnames7.default)(
|
|
10478
10600
|
variantBaseStyles.outlined,
|
|
@@ -12396,6 +12518,7 @@ var VariablePicker = ({
|
|
|
12396
12518
|
tone = "blue",
|
|
12397
12519
|
size = "md",
|
|
12398
12520
|
variant = "elevated",
|
|
12521
|
+
panelTone = "auto",
|
|
12399
12522
|
corner = "auto",
|
|
12400
12523
|
initialSearch = "",
|
|
12401
12524
|
title,
|
|
@@ -12471,7 +12594,7 @@ var VariablePicker = ({
|
|
|
12471
12594
|
Panel_default,
|
|
12472
12595
|
{
|
|
12473
12596
|
variant,
|
|
12474
|
-
tone: PANEL_TONE_FOR_FIELD,
|
|
12597
|
+
tone: panelTone === "auto" ? PANEL_TONE_FOR_FIELD : panelTone,
|
|
12475
12598
|
corner,
|
|
12476
12599
|
padding: "none",
|
|
12477
12600
|
scrollable: false,
|
|
@@ -13112,6 +13235,7 @@ var HelpButton = ({
|
|
|
13112
13235
|
content,
|
|
13113
13236
|
title,
|
|
13114
13237
|
placement = "auto",
|
|
13238
|
+
tone = "none",
|
|
13115
13239
|
color = "sky",
|
|
13116
13240
|
variant = "elevated",
|
|
13117
13241
|
corner = DEFAULT_SURFACE_CORNER,
|
|
@@ -13173,7 +13297,7 @@ var HelpButton = ({
|
|
|
13173
13297
|
window.removeEventListener("resize", recompute);
|
|
13174
13298
|
};
|
|
13175
13299
|
}, [open, recompute]);
|
|
13176
|
-
const palette = getPanelToneStyles(
|
|
13300
|
+
const palette = getPanelToneStyles(tone);
|
|
13177
13301
|
const surfaceText = getSurfaceTextTokens(variant);
|
|
13178
13302
|
const isMarkdown = typeof content === "string";
|
|
13179
13303
|
return /* @__PURE__ */ (0, import_jsx_runtime167.jsxs)("span", { className: (0, import_classnames15.default)("inline-flex items-center", className), children: [
|
|
@@ -13212,7 +13336,7 @@ var HelpButton = ({
|
|
|
13212
13336
|
Panel_default,
|
|
13213
13337
|
{
|
|
13214
13338
|
variant,
|
|
13215
|
-
tone
|
|
13339
|
+
tone,
|
|
13216
13340
|
corner,
|
|
13217
13341
|
padding: "none",
|
|
13218
13342
|
scrollable: false,
|
|
@@ -13295,9 +13419,142 @@ var HelpButton = ({
|
|
|
13295
13419
|
};
|
|
13296
13420
|
HelpButton.displayName = "HelpButton";
|
|
13297
13421
|
var HelpButton_default = HelpButton;
|
|
13422
|
+
|
|
13423
|
+
// src/CodeBlockMarkdown.tsx
|
|
13424
|
+
var import_react166 = __toESM(require("react"), 1);
|
|
13425
|
+
|
|
13426
|
+
// src/components/CodeBlock.tsx
|
|
13427
|
+
var import_react165 = __toESM(require("react"), 1);
|
|
13428
|
+
var import_refractor = require("refractor");
|
|
13429
|
+
var import_tsx = __toESM(require("refractor/tsx"), 1);
|
|
13430
|
+
var import_jsx_runtime168 = require("react/jsx-runtime");
|
|
13431
|
+
import_refractor.refractor.register(import_tsx.default);
|
|
13432
|
+
function tokenRuns(nodes, inherited = "") {
|
|
13433
|
+
return nodes.flatMap((node) => {
|
|
13434
|
+
if (node.type === "text") return [{ text: node.value, className: inherited }];
|
|
13435
|
+
if (node.type !== "element") return [];
|
|
13436
|
+
const classes = node.properties.className;
|
|
13437
|
+
const className = [inherited, Array.isArray(classes) ? classes.join(" ") : String(classes ?? "")].filter(Boolean).join(" ");
|
|
13438
|
+
return tokenRuns(node.children, className);
|
|
13439
|
+
});
|
|
13440
|
+
}
|
|
13441
|
+
function renderLines(runs, numbered, value) {
|
|
13442
|
+
const lines = [[]];
|
|
13443
|
+
let key = 0;
|
|
13444
|
+
for (const run of runs) {
|
|
13445
|
+
run.text.split("\n").forEach((text, index) => {
|
|
13446
|
+
if (index) lines.push([]);
|
|
13447
|
+
if (text) lines[lines.length - 1].push(/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: run.className || void 0, children: text }, key++));
|
|
13448
|
+
});
|
|
13449
|
+
}
|
|
13450
|
+
const digits = String(value.split("\n").length).length;
|
|
13451
|
+
return lines.map((line, index) => /* @__PURE__ */ (0, import_jsx_runtime168.jsxs)(import_react165.default.Fragment, { children: [
|
|
13452
|
+
index > 0 ? "\n" : null,
|
|
13453
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsxs)("span", { className: "ui-code-block-line", children: [
|
|
13454
|
+
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` } }),
|
|
13455
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "ui-code-block-line-text", children: line })
|
|
13456
|
+
] })
|
|
13457
|
+
] }, index));
|
|
13458
|
+
}
|
|
13459
|
+
function CodeBlock({
|
|
13460
|
+
value,
|
|
13461
|
+
onChange,
|
|
13462
|
+
readOnly = true,
|
|
13463
|
+
language,
|
|
13464
|
+
filename,
|
|
13465
|
+
showTitle = true,
|
|
13466
|
+
showCopy = true,
|
|
13467
|
+
showLineNumbers = false,
|
|
13468
|
+
wrapLines = false,
|
|
13469
|
+
maxHeight,
|
|
13470
|
+
tone = "none",
|
|
13471
|
+
color = "blue",
|
|
13472
|
+
variant = "subtle",
|
|
13473
|
+
corner = "rounded-md",
|
|
13474
|
+
editorLabel,
|
|
13475
|
+
className,
|
|
13476
|
+
...rest
|
|
13477
|
+
}) {
|
|
13478
|
+
const t = useKitT();
|
|
13479
|
+
const [copyState, setCopyState] = (0, import_react165.useState)("idle");
|
|
13480
|
+
const timer = (0, import_react165.useRef)(void 0);
|
|
13481
|
+
const generation = (0, import_react165.useRef)(0);
|
|
13482
|
+
(0, import_react165.useEffect)(() => {
|
|
13483
|
+
generation.current++;
|
|
13484
|
+
setCopyState("idle");
|
|
13485
|
+
clearTimeout(timer.current);
|
|
13486
|
+
return () => {
|
|
13487
|
+
generation.current++;
|
|
13488
|
+
clearTimeout(timer.current);
|
|
13489
|
+
};
|
|
13490
|
+
}, [value]);
|
|
13491
|
+
const highlighted = (0, import_react165.useMemo)(() => {
|
|
13492
|
+
if (!readOnly || !language) return [{ text: value, className: "" }];
|
|
13493
|
+
try {
|
|
13494
|
+
return tokenRuns(import_refractor.refractor.highlight(value, language.toLowerCase()).children);
|
|
13495
|
+
} catch {
|
|
13496
|
+
return [{ text: value, className: "" }];
|
|
13497
|
+
}
|
|
13498
|
+
}, [value, language, readOnly]);
|
|
13499
|
+
const copy = async () => {
|
|
13500
|
+
const current = ++generation.current;
|
|
13501
|
+
clearTimeout(timer.current);
|
|
13502
|
+
try {
|
|
13503
|
+
await navigator.clipboard.writeText(value);
|
|
13504
|
+
if (current !== generation.current) return;
|
|
13505
|
+
setCopyState("success");
|
|
13506
|
+
} catch {
|
|
13507
|
+
if (current !== generation.current) return;
|
|
13508
|
+
setCopyState("error");
|
|
13509
|
+
}
|
|
13510
|
+
timer.current = setTimeout(() => setCopyState("idle"), 2e3);
|
|
13511
|
+
};
|
|
13512
|
+
const copyLabel = t(copyState === "success" ? "kit.codeBlock.copied" : "kit.codeBlock.copy");
|
|
13513
|
+
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: [
|
|
13514
|
+
(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: [
|
|
13515
|
+
showTitle && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("span", { className: "truncate font-mono text-xs", children: filename || language || t("kit.codeBlock.code") }),
|
|
13516
|
+
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 })
|
|
13517
|
+
] }),
|
|
13518
|
+
/* @__PURE__ */ (0, import_jsx_runtime168.jsx)(
|
|
13519
|
+
ScrollArea_default,
|
|
13520
|
+
{
|
|
13521
|
+
variant: "hover",
|
|
13522
|
+
className: "ui-code-block-scroll",
|
|
13523
|
+
"data-wrap": wrapLines || void 0,
|
|
13524
|
+
style: { maxHeight },
|
|
13525
|
+
tabIndex: readOnly ? 0 : -1,
|
|
13526
|
+
role: "region",
|
|
13527
|
+
"aria-label": filename || t("kit.codeBlock.code"),
|
|
13528
|
+
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: [
|
|
13529
|
+
/* @__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" }),
|
|
13530
|
+
/* @__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" })
|
|
13531
|
+
] })
|
|
13532
|
+
}
|
|
13533
|
+
),
|
|
13534
|
+
/* @__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") : "" }),
|
|
13535
|
+
copyState === "error" && /* @__PURE__ */ (0, import_jsx_runtime168.jsx)("p", { className: "px-4 pb-2 text-xs", children: t("kit.codeBlock.copyFailed") })
|
|
13536
|
+
] }) });
|
|
13537
|
+
}
|
|
13538
|
+
|
|
13539
|
+
// src/CodeBlockMarkdown.tsx
|
|
13540
|
+
var import_jsx_runtime169 = require("react/jsx-runtime");
|
|
13541
|
+
function createCodeBlockMarkdownComponents(options = {}) {
|
|
13542
|
+
return {
|
|
13543
|
+
pre: ({ children, node: _node, ref: _ref, ...props }) => {
|
|
13544
|
+
const child = import_react166.default.Children.toArray(children)[0];
|
|
13545
|
+
if (!import_react166.default.isValidElement(child) || typeof child.props.children !== "string") {
|
|
13546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime169.jsx)("pre", { ...props, children });
|
|
13547
|
+
}
|
|
13548
|
+
const language = /(?:^|\s)language-([^\s]+)/.exec(child.props.className ?? "")?.[1];
|
|
13549
|
+
return /* @__PURE__ */ (0, import_jsx_runtime169.jsx)(CodeBlock, { ...options, value: child.props.children, language: language || options.language, readOnly: true });
|
|
13550
|
+
}
|
|
13551
|
+
};
|
|
13552
|
+
}
|
|
13298
13553
|
// Annotate the CommonJS export names for ESM import in node:
|
|
13299
13554
|
0 && (module.exports = {
|
|
13555
|
+
CodeBlock,
|
|
13300
13556
|
HelpButton,
|
|
13301
|
-
MarkdownEditor
|
|
13557
|
+
MarkdownEditor,
|
|
13558
|
+
createCodeBlockMarkdownComponents
|
|
13302
13559
|
});
|
|
13303
13560
|
//# sourceMappingURL=markdown.cjs.map
|