@djangocfg/ui-tools 2.1.434 → 2.1.435
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-tools",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.435",
|
|
4
4
|
"description": "Heavy React tools with lazy loading - for Electron, Vite, CRA, Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-tools",
|
|
@@ -334,8 +334,8 @@
|
|
|
334
334
|
"test:watch": "vitest"
|
|
335
335
|
},
|
|
336
336
|
"peerDependencies": {
|
|
337
|
-
"@djangocfg/i18n": "^2.1.
|
|
338
|
-
"@djangocfg/ui-core": "^2.1.
|
|
337
|
+
"@djangocfg/i18n": "^2.1.435",
|
|
338
|
+
"@djangocfg/ui-core": "^2.1.435",
|
|
339
339
|
"consola": "^3.4.2",
|
|
340
340
|
"lodash-es": "^4.18.1",
|
|
341
341
|
"lucide-react": "^0.545.0",
|
|
@@ -418,9 +418,9 @@
|
|
|
418
418
|
"@maplibre/maplibre-gl-geocoder": "^1.7.0"
|
|
419
419
|
},
|
|
420
420
|
"devDependencies": {
|
|
421
|
-
"@djangocfg/i18n": "^2.1.
|
|
422
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
423
|
-
"@djangocfg/ui-core": "^2.1.
|
|
421
|
+
"@djangocfg/i18n": "^2.1.435",
|
|
422
|
+
"@djangocfg/typescript-config": "^2.1.435",
|
|
423
|
+
"@djangocfg/ui-core": "^2.1.435",
|
|
424
424
|
"@types/lodash-es": "^4.17.12",
|
|
425
425
|
"@types/mapbox__mapbox-gl-draw": "^1.4.8",
|
|
426
426
|
"@types/node": "^25.2.3",
|
|
@@ -4,17 +4,18 @@ import { Highlight, Language, themes } from 'prism-react-renderer';
|
|
|
4
4
|
import React, { useMemo, useRef } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useAppT } from '@djangocfg/i18n';
|
|
7
|
+
import { useResolvedTheme } from '@djangocfg/ui-core/hooks';
|
|
7
8
|
import { CodePanelHeader } from '../../../../common/CodePanelHeader';
|
|
8
9
|
|
|
9
|
-
// Surface palette —
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
const CODE_SURFACE_BG = '
|
|
16
|
-
const CODE_SURFACE_BORDER = '
|
|
17
|
-
const CODE_INLINE_BG = '
|
|
10
|
+
// Surface palette — driven by the ui-core `--code*` semantic tokens so the
|
|
11
|
+
// code panel matches the rest of the theme system (neutral, preset-aware)
|
|
12
|
+
// instead of a hard-coded GitHub blue. The tokens are already tuned per
|
|
13
|
+
// theme (`light.css` / `dark.css`): a near-white gray in light, a near-black
|
|
14
|
+
// gray in dark — so the surface stays a calm neutral in either mode and never
|
|
15
|
+
// reads blue. Syntax colors still come from Prism's vsDark/github palettes.
|
|
16
|
+
const CODE_SURFACE_BG = 'var(--code)';
|
|
17
|
+
const CODE_SURFACE_BORDER = 'var(--code-border)';
|
|
18
|
+
const CODE_INLINE_BG = 'var(--code-inline)';
|
|
18
19
|
|
|
19
20
|
// Load extra Prism grammars (``bash``, ``ruby``, ``java``, ``php``)
|
|
20
21
|
// that aren't in ``prism-react-renderer``'s default bundle. The hook
|
|
@@ -28,11 +29,11 @@ interface PrettyCodeProps {
|
|
|
28
29
|
language: Language;
|
|
29
30
|
className?: string;
|
|
30
31
|
/**
|
|
31
|
-
* Force a specific Prism palette. **
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* Force a specific Prism palette + surface. **Defaults to the resolved
|
|
33
|
+
* host theme** (light → light surface + GitHub palette, dark → dark
|
|
34
|
+
* surface + vsDark palette), so the panel matches the rest of the UI and
|
|
35
|
+
* its `--code*` tokens. Pass `mode` explicitly only to pin a palette
|
|
36
|
+
* regardless of theme — e.g. printing a PDF on a light page.
|
|
36
37
|
*/
|
|
37
38
|
mode?: 'dark' | 'light';
|
|
38
39
|
inline?: boolean;
|
|
@@ -62,10 +63,15 @@ interface PrettyCodeProps {
|
|
|
62
63
|
variant?: 'card' | 'plain';
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
const PrettyCode = ({ data, language, className, mode
|
|
66
|
+
const PrettyCode = ({ data, language, className, mode, inline = false, customBg, isCompact = false, maxLines, onExpand, variant = 'card' }: PrettyCodeProps) => {
|
|
66
67
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
67
68
|
const t = useAppT();
|
|
68
69
|
|
|
70
|
+
// Default to the host theme so the surface (`--code*` tokens) and the Prism
|
|
71
|
+
// palette move together; an explicit `mode` prop still pins a palette.
|
|
72
|
+
const resolvedTheme = useResolvedTheme();
|
|
73
|
+
const effectiveMode = mode ?? (resolvedTheme === 'light' ? 'light' : 'dark');
|
|
74
|
+
|
|
69
75
|
// Subscribe to the extra-grammars ready state. When ``bash`` /
|
|
70
76
|
// ``ruby`` / ``java`` / ``php`` finish loading, this hook triggers a
|
|
71
77
|
// re-render so the code block picks up the new grammar.
|
|
@@ -79,12 +85,14 @@ const PrettyCode = ({ data, language, className, mode = 'dark', inline = false,
|
|
|
79
85
|
// Font size based on compact mode
|
|
80
86
|
const fontSize = isCompact ? '0.75rem' : '0.875rem'; // 12px vs 14px
|
|
81
87
|
|
|
82
|
-
const isDarkMode =
|
|
88
|
+
const isDarkMode = effectiveMode !== 'light';
|
|
83
89
|
const prismTheme = isDarkMode ? themes.vsDark : themes.github;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
// The surface now reads the `--code*` tokens in BOTH modes — they already
|
|
91
|
+
// carry the right neutral per theme, so the panel matches the UI and never
|
|
92
|
+
// reads blue. (Previously light mode fell back to `bg-card` and dark mode
|
|
93
|
+
// hard-coded GitHub's #0d1117.)
|
|
94
|
+
const surfaceStyle = { backgroundColor: CODE_SURFACE_BG, borderColor: CODE_SURFACE_BORDER };
|
|
95
|
+
const inlineSurfaceStyle = { backgroundColor: CODE_INLINE_BG };
|
|
88
96
|
|
|
89
97
|
// Convert form object to JSON string with proper formatting
|
|
90
98
|
const contentJson = typeof data === 'string' ? data : JSON.stringify(data || {}, null, 2);
|
|
@@ -104,17 +112,16 @@ const PrettyCode = ({ data, language, className, mode = 'dark', inline = false,
|
|
|
104
112
|
|
|
105
113
|
// Handle empty content
|
|
106
114
|
if (!contentJson || contentJson.trim() === '') {
|
|
107
|
-
const emptyBgClass = customBg ||
|
|
115
|
+
const emptyBgClass = customBg || '';
|
|
108
116
|
return (
|
|
109
117
|
<div
|
|
110
|
-
className={`relative h-full ${emptyBgClass} rounded-sm border ${
|
|
118
|
+
className={`relative h-full ${emptyBgClass} rounded-sm border ${className || ''}`}
|
|
111
119
|
style={customBg ? undefined : surfaceStyle}
|
|
112
120
|
>
|
|
113
121
|
<div className="h-full overflow-auto p-4">
|
|
114
122
|
<p
|
|
115
|
-
className="text-sm italic"
|
|
123
|
+
className="text-sm italic text-muted-foreground"
|
|
116
124
|
role="status"
|
|
117
|
-
style={{ color: isDarkMode ? '#9ca3af' : undefined }}
|
|
118
125
|
>
|
|
119
126
|
{labels.noContent}
|
|
120
127
|
</p>
|
|
@@ -279,7 +286,8 @@ const PrettyCode = ({ data, language, className, mode = 'dark', inline = false,
|
|
|
279
286
|
}
|
|
280
287
|
|
|
281
288
|
if (inline) {
|
|
282
|
-
|
|
289
|
+
// Inline chip surface also comes from `--code-inline` via inlineSurfaceStyle.
|
|
290
|
+
const inlineBgClass = customBg || '';
|
|
283
291
|
return (
|
|
284
292
|
<Highlight theme={prismTheme} code={contentJson} language={normalizedLanguage as Language}>
|
|
285
293
|
{({ className: prismClassName, style, tokens, getTokenProps }) => (
|
|
@@ -304,13 +312,13 @@ const PrettyCode = ({ data, language, className, mode = 'dark', inline = false,
|
|
|
304
312
|
}
|
|
305
313
|
|
|
306
314
|
// Code surface is fixed (dark by default). Falls back to semantic
|
|
307
|
-
//
|
|
308
|
-
const bgClass = customBg ||
|
|
315
|
+
// Surface comes from the `--code*` tokens via `surfaceStyle` (both modes).
|
|
316
|
+
const bgClass = customBg || '';
|
|
309
317
|
|
|
310
318
|
return (
|
|
311
319
|
<div
|
|
312
320
|
ref={containerRef}
|
|
313
|
-
className={`group relative overflow-hidden ${bgClass} rounded-lg border ${
|
|
321
|
+
className={`group relative overflow-hidden ${bgClass} rounded-lg border ${className || ''}`}
|
|
314
322
|
style={customBg ? undefined : surfaceStyle}
|
|
315
323
|
>
|
|
316
324
|
{/* Persistent header bar (GitHub / ChatGPT style): language label
|