@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.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-QDW3hqU0.cjs';
|
|
3
|
+
export { $ as CodeBlock, an as HelpButton } from './CodeBlock-QDW3hqU0.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-QDW3hqU0.js';
|
|
3
|
+
export { $ as CodeBlock, an as HelpButton } from './CodeBlock-QDW3hqU0.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
|
|
|
@@ -1613,6 +1625,13 @@ function getLocalizedParseNames(locale, catalog) {
|
|
|
1613
1625
|
// ../common/i18n/builtIn/de.ts
|
|
1614
1626
|
var DE_KIT_CATALOG = {
|
|
1615
1627
|
kit: {
|
|
1628
|
+
codeBlock: {
|
|
1629
|
+
code: "Code",
|
|
1630
|
+
edit: "Code bearbeiten",
|
|
1631
|
+
copy: "Code kopieren",
|
|
1632
|
+
copied: "Kopiert",
|
|
1633
|
+
copyFailed: "Kopieren fehlgeschlagen. Code ausw\xE4hlen und manuell kopieren."
|
|
1634
|
+
},
|
|
1616
1635
|
knowledge: {
|
|
1617
1636
|
"library": "Erinnerungsbibliothek",
|
|
1618
1637
|
"map": "Wissenskarte",
|
|
@@ -1885,6 +1904,20 @@ var DE_KIT_CATALOG = {
|
|
|
1885
1904
|
progressspinner: {
|
|
1886
1905
|
loading: "Wird geladen"
|
|
1887
1906
|
},
|
|
1907
|
+
filterbar: {
|
|
1908
|
+
filters: "Filter",
|
|
1909
|
+
search: "Suchen",
|
|
1910
|
+
empty: "Keine Filter angewendet",
|
|
1911
|
+
add: "Filter hinzuf\xFCgen",
|
|
1912
|
+
filterBy: "Filtern nach",
|
|
1913
|
+
back: "Zur\xFCck",
|
|
1914
|
+
clear: "Leeren",
|
|
1915
|
+
done: "Fertig",
|
|
1916
|
+
clearAll: "Alle l\xF6schen",
|
|
1917
|
+
items: "Eintr\xE4ge",
|
|
1918
|
+
summary: "{filtered} von {total} {items}",
|
|
1919
|
+
remove: "Filter {label} entfernen"
|
|
1920
|
+
},
|
|
1888
1921
|
searchbar: {
|
|
1889
1922
|
clearAria: "Suche l\xF6schen",
|
|
1890
1923
|
placeholder: "Suchen..."
|
|
@@ -2109,6 +2142,13 @@ var DE_KIT_CATALOG = {
|
|
|
2109
2142
|
// ../common/i18n/builtIn/en.ts
|
|
2110
2143
|
var EN_KIT_CATALOG = {
|
|
2111
2144
|
kit: {
|
|
2145
|
+
codeBlock: {
|
|
2146
|
+
code: "Code",
|
|
2147
|
+
edit: "Edit code",
|
|
2148
|
+
copy: "Copy code",
|
|
2149
|
+
copied: "Copied",
|
|
2150
|
+
copyFailed: "Could not copy code. Select and copy it manually."
|
|
2151
|
+
},
|
|
2112
2152
|
knowledge: {
|
|
2113
2153
|
"library": "Memory library",
|
|
2114
2154
|
"map": "Knowledge map",
|
|
@@ -2381,6 +2421,20 @@ var EN_KIT_CATALOG = {
|
|
|
2381
2421
|
progressspinner: {
|
|
2382
2422
|
loading: "Loading"
|
|
2383
2423
|
},
|
|
2424
|
+
filterbar: {
|
|
2425
|
+
filters: "Filters",
|
|
2426
|
+
search: "Search",
|
|
2427
|
+
empty: "No filters applied",
|
|
2428
|
+
add: "Add filter",
|
|
2429
|
+
filterBy: "Filter by",
|
|
2430
|
+
back: "Back",
|
|
2431
|
+
clear: "Clear",
|
|
2432
|
+
done: "Done",
|
|
2433
|
+
clearAll: "Clear all",
|
|
2434
|
+
items: "items",
|
|
2435
|
+
summary: "{filtered} of {total} {items}",
|
|
2436
|
+
remove: "Remove {label} filter"
|
|
2437
|
+
},
|
|
2384
2438
|
searchbar: {
|
|
2385
2439
|
clearAria: "Clear search",
|
|
2386
2440
|
placeholder: "Search..."
|
|
@@ -2605,6 +2659,13 @@ var EN_KIT_CATALOG = {
|
|
|
2605
2659
|
// ../common/i18n/builtIn/es.ts
|
|
2606
2660
|
var ES_KIT_CATALOG = {
|
|
2607
2661
|
kit: {
|
|
2662
|
+
codeBlock: {
|
|
2663
|
+
code: "C\xF3digo",
|
|
2664
|
+
edit: "Editar c\xF3digo",
|
|
2665
|
+
copy: "Copiar c\xF3digo",
|
|
2666
|
+
copied: "Copiado",
|
|
2667
|
+
copyFailed: "No se pudo copiar. Selecciona y copia el c\xF3digo manualmente."
|
|
2668
|
+
},
|
|
2608
2669
|
knowledge: {
|
|
2609
2670
|
"library": "Biblioteca de memorias",
|
|
2610
2671
|
"map": "Mapa de conocimiento",
|
|
@@ -2877,6 +2938,20 @@ var ES_KIT_CATALOG = {
|
|
|
2877
2938
|
progressspinner: {
|
|
2878
2939
|
loading: "Cargando"
|
|
2879
2940
|
},
|
|
2941
|
+
filterbar: {
|
|
2942
|
+
filters: "Filtros",
|
|
2943
|
+
search: "Buscar",
|
|
2944
|
+
empty: "Sin filtros aplicados",
|
|
2945
|
+
add: "A\xF1adir filtro",
|
|
2946
|
+
filterBy: "Filtrar por",
|
|
2947
|
+
back: "Volver",
|
|
2948
|
+
clear: "Limpiar",
|
|
2949
|
+
done: "Listo",
|
|
2950
|
+
clearAll: "Borrar todos",
|
|
2951
|
+
items: "elementos",
|
|
2952
|
+
summary: "{filtered} de {total} {items}",
|
|
2953
|
+
remove: "Eliminar filtro {label}"
|
|
2954
|
+
},
|
|
2880
2955
|
searchbar: {
|
|
2881
2956
|
clearAria: "Borrar b\xFAsqueda",
|
|
2882
2957
|
placeholder: "Buscar..."
|
|
@@ -3101,6 +3176,13 @@ var ES_KIT_CATALOG = {
|
|
|
3101
3176
|
// ../common/i18n/builtIn/fr.ts
|
|
3102
3177
|
var FR_KIT_CATALOG = {
|
|
3103
3178
|
kit: {
|
|
3179
|
+
codeBlock: {
|
|
3180
|
+
code: "Code",
|
|
3181
|
+
edit: "Modifier le code",
|
|
3182
|
+
copy: "Copier le code",
|
|
3183
|
+
copied: "Copi\xE9",
|
|
3184
|
+
copyFailed: "Copie impossible. S\xE9lectionnez et copiez le code manuellement."
|
|
3185
|
+
},
|
|
3104
3186
|
knowledge: {
|
|
3105
3187
|
"library": "Biblioth\xE8que de m\xE9moires",
|
|
3106
3188
|
"map": "Carte des connaissances",
|
|
@@ -3373,6 +3455,20 @@ var FR_KIT_CATALOG = {
|
|
|
3373
3455
|
progressspinner: {
|
|
3374
3456
|
loading: "Chargement"
|
|
3375
3457
|
},
|
|
3458
|
+
filterbar: {
|
|
3459
|
+
filters: "Filtres",
|
|
3460
|
+
search: "Rechercher",
|
|
3461
|
+
empty: "Aucun filtre appliqu\xE9",
|
|
3462
|
+
add: "Ajouter un filtre",
|
|
3463
|
+
filterBy: "Filtrer par",
|
|
3464
|
+
back: "Retour",
|
|
3465
|
+
clear: "Effacer",
|
|
3466
|
+
done: "Termin\xE9",
|
|
3467
|
+
clearAll: "Tout effacer",
|
|
3468
|
+
items: "\xE9l\xE9ments",
|
|
3469
|
+
summary: "{filtered} sur {total} {items}",
|
|
3470
|
+
remove: "Supprimer le filtre {label}"
|
|
3471
|
+
},
|
|
3376
3472
|
searchbar: {
|
|
3377
3473
|
clearAria: "Effacer la recherche",
|
|
3378
3474
|
placeholder: "Rechercher..."
|
|
@@ -3597,6 +3693,13 @@ var FR_KIT_CATALOG = {
|
|
|
3597
3693
|
// ../common/i18n/builtIn/pt.ts
|
|
3598
3694
|
var PT_KIT_CATALOG = {
|
|
3599
3695
|
kit: {
|
|
3696
|
+
codeBlock: {
|
|
3697
|
+
code: "C\xF3digo",
|
|
3698
|
+
edit: "Editar c\xF3digo",
|
|
3699
|
+
copy: "Copiar c\xF3digo",
|
|
3700
|
+
copied: "Copiado",
|
|
3701
|
+
copyFailed: "N\xE3o foi poss\xEDvel copiar. Selecione e copie o c\xF3digo manualmente."
|
|
3702
|
+
},
|
|
3600
3703
|
knowledge: {
|
|
3601
3704
|
"library": "Biblioteca de mem\xF3rias",
|
|
3602
3705
|
"map": "Mapa de conhecimento",
|
|
@@ -3869,6 +3972,20 @@ var PT_KIT_CATALOG = {
|
|
|
3869
3972
|
progressspinner: {
|
|
3870
3973
|
loading: "Carregando"
|
|
3871
3974
|
},
|
|
3975
|
+
filterbar: {
|
|
3976
|
+
filters: "Filtros",
|
|
3977
|
+
search: "Pesquisar",
|
|
3978
|
+
empty: "Nenhum filtro aplicado",
|
|
3979
|
+
add: "Adicionar filtro",
|
|
3980
|
+
filterBy: "Filtrar por",
|
|
3981
|
+
back: "Voltar",
|
|
3982
|
+
clear: "Limpar",
|
|
3983
|
+
done: "Conclu\xEDdo",
|
|
3984
|
+
clearAll: "Limpar todos",
|
|
3985
|
+
items: "itens",
|
|
3986
|
+
summary: "{filtered} de {total} {items}",
|
|
3987
|
+
remove: "Remover filtro {label}"
|
|
3988
|
+
},
|
|
3872
3989
|
searchbar: {
|
|
3873
3990
|
clearAria: "Limpar busca",
|
|
3874
3991
|
placeholder: "Buscar..."
|
|
@@ -10202,6 +10319,7 @@ function hasInteractiveDescendant(root) {
|
|
|
10202
10319
|
// src/components/Panel.tsx
|
|
10203
10320
|
import { Fragment as Fragment3, jsx as jsx159, jsxs as jsxs60 } from "react/jsx-runtime";
|
|
10204
10321
|
var variantBaseStyles = {
|
|
10322
|
+
none: "",
|
|
10205
10323
|
elevated: "bg-white shadow-xl ring-1 ring-black/5 dark:bg-neutral-900 dark:ring-white/10",
|
|
10206
10324
|
// A real 1px border, not a ring. `ring-1` with no ring colour resolves to
|
|
10207
10325
|
// currentColor, which painted a near-black rule in light mode.
|
|
@@ -10416,7 +10534,7 @@ var Panel = React10.forwardRef(function Panel2({
|
|
|
10416
10534
|
if (specularHighlight === false) return "none";
|
|
10417
10535
|
return "classic";
|
|
10418
10536
|
})();
|
|
10419
|
-
const effectiveHoverColor = hoverColor ?? (
|
|
10537
|
+
const effectiveHoverColor = hoverColor ?? (resolvedTone !== "none" && resolvedTone !== "neutral" ? resolvedTone : void 0);
|
|
10420
10538
|
const hoverColorName = effectiveHoverColor ? effectiveHoverColor : void 0;
|
|
10421
10539
|
const borderPalette = borderColor ? getPanelToneStyles(borderColor) : void 0;
|
|
10422
10540
|
const effectiveBorderClass = borderPalette?.border;
|
|
@@ -10451,6 +10569,8 @@ var Panel = React10.forwardRef(function Panel2({
|
|
|
10451
10569
|
const glassFillClass = getSurfaceGlassFillClass(resolvedTone, glassOpacity);
|
|
10452
10570
|
const variantClasses = getSurfaceTransparencyClasses(classNames7((() => {
|
|
10453
10571
|
switch (variant) {
|
|
10572
|
+
case "none":
|
|
10573
|
+
return resolvedTone === "none" ? "" : palette.subtleBg;
|
|
10454
10574
|
case "outlined":
|
|
10455
10575
|
return classNames7(
|
|
10456
10576
|
variantBaseStyles.outlined,
|
|
@@ -12385,6 +12505,7 @@ var VariablePicker = ({
|
|
|
12385
12505
|
tone = "blue",
|
|
12386
12506
|
size = "md",
|
|
12387
12507
|
variant = "elevated",
|
|
12508
|
+
panelTone = "auto",
|
|
12388
12509
|
corner = "auto",
|
|
12389
12510
|
initialSearch = "",
|
|
12390
12511
|
title,
|
|
@@ -12460,7 +12581,7 @@ var VariablePicker = ({
|
|
|
12460
12581
|
Panel_default,
|
|
12461
12582
|
{
|
|
12462
12583
|
variant,
|
|
12463
|
-
tone: PANEL_TONE_FOR_FIELD,
|
|
12584
|
+
tone: panelTone === "auto" ? PANEL_TONE_FOR_FIELD : panelTone,
|
|
12464
12585
|
corner,
|
|
12465
12586
|
padding: "none",
|
|
12466
12587
|
scrollable: false,
|
|
@@ -13101,6 +13222,7 @@ var HelpButton = ({
|
|
|
13101
13222
|
content,
|
|
13102
13223
|
title,
|
|
13103
13224
|
placement = "auto",
|
|
13225
|
+
tone = "none",
|
|
13104
13226
|
color = "sky",
|
|
13105
13227
|
variant = "elevated",
|
|
13106
13228
|
corner = DEFAULT_SURFACE_CORNER,
|
|
@@ -13162,7 +13284,7 @@ var HelpButton = ({
|
|
|
13162
13284
|
window.removeEventListener("resize", recompute);
|
|
13163
13285
|
};
|
|
13164
13286
|
}, [open, recompute]);
|
|
13165
|
-
const palette = getPanelToneStyles(
|
|
13287
|
+
const palette = getPanelToneStyles(tone);
|
|
13166
13288
|
const surfaceText = getSurfaceTextTokens(variant);
|
|
13167
13289
|
const isMarkdown = typeof content === "string";
|
|
13168
13290
|
return /* @__PURE__ */ jsxs68("span", { className: classNames15("inline-flex items-center", className), children: [
|
|
@@ -13201,7 +13323,7 @@ var HelpButton = ({
|
|
|
13201
13323
|
Panel_default,
|
|
13202
13324
|
{
|
|
13203
13325
|
variant,
|
|
13204
|
-
tone
|
|
13326
|
+
tone,
|
|
13205
13327
|
corner,
|
|
13206
13328
|
padding: "none",
|
|
13207
13329
|
scrollable: false,
|
|
@@ -13284,8 +13406,141 @@ var HelpButton = ({
|
|
|
13284
13406
|
};
|
|
13285
13407
|
HelpButton.displayName = "HelpButton";
|
|
13286
13408
|
var HelpButton_default = HelpButton;
|
|
13409
|
+
|
|
13410
|
+
// src/CodeBlockMarkdown.tsx
|
|
13411
|
+
import React17 from "react";
|
|
13412
|
+
|
|
13413
|
+
// src/components/CodeBlock.tsx
|
|
13414
|
+
import React16, { useEffect as useEffect7, useMemo as useMemo6, useRef as useRef8, useState as useState8 } from "react";
|
|
13415
|
+
import { refractor } from "refractor";
|
|
13416
|
+
import tsx from "refractor/tsx";
|
|
13417
|
+
import { jsx as jsx168, jsxs as jsxs69 } from "react/jsx-runtime";
|
|
13418
|
+
refractor.register(tsx);
|
|
13419
|
+
function tokenRuns(nodes, inherited = "") {
|
|
13420
|
+
return nodes.flatMap((node) => {
|
|
13421
|
+
if (node.type === "text") return [{ text: node.value, className: inherited }];
|
|
13422
|
+
if (node.type !== "element") return [];
|
|
13423
|
+
const classes = node.properties.className;
|
|
13424
|
+
const className = [inherited, Array.isArray(classes) ? classes.join(" ") : String(classes ?? "")].filter(Boolean).join(" ");
|
|
13425
|
+
return tokenRuns(node.children, className);
|
|
13426
|
+
});
|
|
13427
|
+
}
|
|
13428
|
+
function renderLines(runs, numbered, value) {
|
|
13429
|
+
const lines = [[]];
|
|
13430
|
+
let key = 0;
|
|
13431
|
+
for (const run of runs) {
|
|
13432
|
+
run.text.split("\n").forEach((text, index) => {
|
|
13433
|
+
if (index) lines.push([]);
|
|
13434
|
+
if (text) lines[lines.length - 1].push(/* @__PURE__ */ jsx168("span", { className: run.className || void 0, children: text }, key++));
|
|
13435
|
+
});
|
|
13436
|
+
}
|
|
13437
|
+
const digits = String(value.split("\n").length).length;
|
|
13438
|
+
return lines.map((line, index) => /* @__PURE__ */ jsxs69(React16.Fragment, { children: [
|
|
13439
|
+
index > 0 ? "\n" : null,
|
|
13440
|
+
/* @__PURE__ */ jsxs69("span", { className: "ui-code-block-line", children: [
|
|
13441
|
+
numbered && /* @__PURE__ */ jsx168("span", { className: "ui-code-block-line-number", "aria-hidden": "true", "data-line": index + 1, style: { width: `${digits}ch` } }),
|
|
13442
|
+
/* @__PURE__ */ jsx168("span", { className: "ui-code-block-line-text", children: line })
|
|
13443
|
+
] })
|
|
13444
|
+
] }, index));
|
|
13445
|
+
}
|
|
13446
|
+
function CodeBlock({
|
|
13447
|
+
value,
|
|
13448
|
+
onChange,
|
|
13449
|
+
readOnly = true,
|
|
13450
|
+
language,
|
|
13451
|
+
filename,
|
|
13452
|
+
showTitle = true,
|
|
13453
|
+
showCopy = true,
|
|
13454
|
+
showLineNumbers = false,
|
|
13455
|
+
wrapLines = false,
|
|
13456
|
+
maxHeight,
|
|
13457
|
+
tone = "none",
|
|
13458
|
+
color = "blue",
|
|
13459
|
+
variant = "subtle",
|
|
13460
|
+
corner = "rounded-md",
|
|
13461
|
+
editorLabel,
|
|
13462
|
+
className,
|
|
13463
|
+
...rest
|
|
13464
|
+
}) {
|
|
13465
|
+
const t = useKitT();
|
|
13466
|
+
const [copyState, setCopyState] = useState8("idle");
|
|
13467
|
+
const timer = useRef8(void 0);
|
|
13468
|
+
const generation = useRef8(0);
|
|
13469
|
+
useEffect7(() => {
|
|
13470
|
+
generation.current++;
|
|
13471
|
+
setCopyState("idle");
|
|
13472
|
+
clearTimeout(timer.current);
|
|
13473
|
+
return () => {
|
|
13474
|
+
generation.current++;
|
|
13475
|
+
clearTimeout(timer.current);
|
|
13476
|
+
};
|
|
13477
|
+
}, [value]);
|
|
13478
|
+
const highlighted = useMemo6(() => {
|
|
13479
|
+
if (!readOnly || !language) return [{ text: value, className: "" }];
|
|
13480
|
+
try {
|
|
13481
|
+
return tokenRuns(refractor.highlight(value, language.toLowerCase()).children);
|
|
13482
|
+
} catch {
|
|
13483
|
+
return [{ text: value, className: "" }];
|
|
13484
|
+
}
|
|
13485
|
+
}, [value, language, readOnly]);
|
|
13486
|
+
const copy = async () => {
|
|
13487
|
+
const current = ++generation.current;
|
|
13488
|
+
clearTimeout(timer.current);
|
|
13489
|
+
try {
|
|
13490
|
+
await navigator.clipboard.writeText(value);
|
|
13491
|
+
if (current !== generation.current) return;
|
|
13492
|
+
setCopyState("success");
|
|
13493
|
+
} catch {
|
|
13494
|
+
if (current !== generation.current) return;
|
|
13495
|
+
setCopyState("error");
|
|
13496
|
+
}
|
|
13497
|
+
timer.current = setTimeout(() => setCopyState("idle"), 2e3);
|
|
13498
|
+
};
|
|
13499
|
+
const copyLabel = t(copyState === "success" ? "kit.codeBlock.copied" : "kit.codeBlock.copy");
|
|
13500
|
+
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: [
|
|
13501
|
+
(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: [
|
|
13502
|
+
showTitle && /* @__PURE__ */ jsx168("span", { className: "truncate font-mono text-xs", children: filename || language || t("kit.codeBlock.code") }),
|
|
13503
|
+
showCopy && /* @__PURE__ */ jsx168(IconButton_default, { icon: copyState === "success" ? "Check" : "CopyClipboard", color, variant: "ghost", size: "xs", srLabel: copyLabel, tooltip: copyLabel, onClick: copy })
|
|
13504
|
+
] }),
|
|
13505
|
+
/* @__PURE__ */ jsx168(
|
|
13506
|
+
ScrollArea_default,
|
|
13507
|
+
{
|
|
13508
|
+
variant: "hover",
|
|
13509
|
+
className: "ui-code-block-scroll",
|
|
13510
|
+
"data-wrap": wrapLines || void 0,
|
|
13511
|
+
style: { maxHeight },
|
|
13512
|
+
tabIndex: readOnly ? 0 : -1,
|
|
13513
|
+
role: "region",
|
|
13514
|
+
"aria-label": filename || t("kit.codeBlock.code"),
|
|
13515
|
+
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: [
|
|
13516
|
+
/* @__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" }),
|
|
13517
|
+
/* @__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" })
|
|
13518
|
+
] })
|
|
13519
|
+
}
|
|
13520
|
+
),
|
|
13521
|
+
/* @__PURE__ */ jsx168("span", { className: "sr-only", role: "status", children: copyState === "success" ? t("kit.codeBlock.copied") : copyState === "error" ? t("kit.codeBlock.copyFailed") : "" }),
|
|
13522
|
+
copyState === "error" && /* @__PURE__ */ jsx168("p", { className: "px-4 pb-2 text-xs", children: t("kit.codeBlock.copyFailed") })
|
|
13523
|
+
] }) });
|
|
13524
|
+
}
|
|
13525
|
+
|
|
13526
|
+
// src/CodeBlockMarkdown.tsx
|
|
13527
|
+
import { jsx as jsx169 } from "react/jsx-runtime";
|
|
13528
|
+
function createCodeBlockMarkdownComponents(options = {}) {
|
|
13529
|
+
return {
|
|
13530
|
+
pre: ({ children, node: _node, ref: _ref, ...props }) => {
|
|
13531
|
+
const child = React17.Children.toArray(children)[0];
|
|
13532
|
+
if (!React17.isValidElement(child) || typeof child.props.children !== "string") {
|
|
13533
|
+
return /* @__PURE__ */ jsx169("pre", { ...props, children });
|
|
13534
|
+
}
|
|
13535
|
+
const language = /(?:^|\s)language-([^\s]+)/.exec(child.props.className ?? "")?.[1];
|
|
13536
|
+
return /* @__PURE__ */ jsx169(CodeBlock, { ...options, value: child.props.children, language: language || options.language, readOnly: true });
|
|
13537
|
+
}
|
|
13538
|
+
};
|
|
13539
|
+
}
|
|
13287
13540
|
export {
|
|
13541
|
+
CodeBlock,
|
|
13288
13542
|
HelpButton_default as HelpButton,
|
|
13289
|
-
MarkdownEditor_default as MarkdownEditor
|
|
13543
|
+
MarkdownEditor_default as MarkdownEditor,
|
|
13544
|
+
createCodeBlockMarkdownComponents
|
|
13290
13545
|
};
|
|
13291
13546
|
//# sourceMappingURL=markdown.js.map
|