@djangocfg/ui-tools 2.1.268 → 2.1.271

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.
Files changed (41) hide show
  1. package/dist/PlaygroundLayout-G325I6HM.mjs +736 -0
  2. package/dist/PlaygroundLayout-G325I6HM.mjs.map +1 -0
  3. package/dist/PlaygroundLayout-ZO2LO7M5.cjs +743 -0
  4. package/dist/PlaygroundLayout-ZO2LO7M5.cjs.map +1 -0
  5. package/dist/{PrettyCode.client-OO3KAJSM.mjs → PrettyCode.client-DW5LTG47.mjs} +5 -5
  6. package/dist/PrettyCode.client-DW5LTG47.mjs.map +1 -0
  7. package/dist/{PrettyCode.client-V2ZN5DTH.cjs → PrettyCode.client-SGDGQTYT.cjs} +5 -5
  8. package/dist/PrettyCode.client-SGDGQTYT.cjs.map +1 -0
  9. package/dist/{chunk-SZ2CZEQZ.mjs → chunk-QZ55LYK2.mjs} +141 -169
  10. package/dist/chunk-QZ55LYK2.mjs.map +1 -0
  11. package/dist/{chunk-CRHHUOVJ.cjs → chunk-WM4RT5KX.cjs} +139 -169
  12. package/dist/chunk-WM4RT5KX.cjs.map +1 -0
  13. package/dist/index.cjs +8 -8
  14. package/dist/index.mjs +5 -5
  15. package/package.json +6 -6
  16. package/src/tools/OpenapiViewer/README.md +121 -0
  17. package/src/tools/OpenapiViewer/components/PlaygroundLayout/EndpointList.tsx +228 -0
  18. package/src/tools/OpenapiViewer/components/PlaygroundLayout/RequestPanel.tsx +258 -0
  19. package/src/tools/OpenapiViewer/components/PlaygroundLayout/ResponsePanel.tsx +127 -0
  20. package/src/tools/OpenapiViewer/components/PlaygroundLayout/index.tsx +107 -0
  21. package/src/tools/OpenapiViewer/components/PlaygroundLayout/ui.tsx +137 -0
  22. package/src/tools/OpenapiViewer/components/index.ts +0 -9
  23. package/src/tools/OpenapiViewer/context/PlaygroundContext.tsx +198 -208
  24. package/src/tools/OpenapiViewer/types.ts +1 -0
  25. package/src/tools/PrettyCode/PrettyCode.client.tsx +17 -12
  26. package/dist/PlaygroundLayout-FKXSULJ3.cjs +0 -971
  27. package/dist/PlaygroundLayout-FKXSULJ3.cjs.map +0 -1
  28. package/dist/PlaygroundLayout-XMMHPZYP.mjs +0 -964
  29. package/dist/PlaygroundLayout-XMMHPZYP.mjs.map +0 -1
  30. package/dist/PrettyCode.client-OO3KAJSM.mjs.map +0 -1
  31. package/dist/PrettyCode.client-V2ZN5DTH.cjs.map +0 -1
  32. package/dist/chunk-CRHHUOVJ.cjs.map +0 -1
  33. package/dist/chunk-SZ2CZEQZ.mjs.map +0 -1
  34. package/src/tools/OpenapiViewer/components/EndpointInfo.tsx +0 -149
  35. package/src/tools/OpenapiViewer/components/EndpointsLibrary.tsx +0 -278
  36. package/src/tools/OpenapiViewer/components/PlaygroundLayout.tsx +0 -91
  37. package/src/tools/OpenapiViewer/components/PlaygroundStepper.tsx +0 -100
  38. package/src/tools/OpenapiViewer/components/RequestBuilder.tsx +0 -157
  39. package/src/tools/OpenapiViewer/components/RequestParametersForm.tsx +0 -253
  40. package/src/tools/OpenapiViewer/components/ResponseViewer.tsx +0 -173
  41. package/src/tools/OpenapiViewer/components/VersionSelector.tsx +0 -68
@@ -0,0 +1,127 @@
1
+ 'use client';
2
+
3
+ import { Loader2, Send, Terminal, WifiOff } from 'lucide-react';
4
+ import { useMemo } from 'react';
5
+
6
+ import { CopyButton } from '@djangocfg/ui-core/components';
7
+
8
+ import JsonTree from '../../../JsonTree';
9
+ import { usePlaygroundContext } from '../../context/PlaygroundContext';
10
+ import { EmptyState, ScrollArea, StatusBadge } from './ui';
11
+
12
+ // ─── JsonTree config (static, no re-creation on render) ──────────────────────
13
+
14
+ const JSON_TREE_CONFIG = {
15
+ maxAutoExpandDepth: 2,
16
+ maxAutoExpandArrayItems: 10,
17
+ maxAutoExpandObjectKeys: 5,
18
+ maxStringLength: 200,
19
+ collectionLimit: 50,
20
+ showCollectionInfo: true,
21
+ showExpandControls: true,
22
+ showActionButtons: false,
23
+ preserveKeyOrder: true,
24
+ className: 'border-0 rounded-none',
25
+ } as const;
26
+
27
+ // ─── ResponsePanel ────────────────────────────────────────────────────────────
28
+
29
+ export function ResponsePanel() {
30
+ const { state } = usePlaygroundContext();
31
+ const { response, loading, selectedEndpoint } = state;
32
+
33
+ // ── Normalise response data ───────────────────────────────────────────────
34
+ // Always try to parse as JSON first so JsonTree gets an object, not a string.
35
+ // Falls back to raw text for non-JSON responses (HTML errors, plain text, etc.)
36
+ const { treeData, rawText } = useMemo(() => {
37
+ const d = response?.data;
38
+ if (d == null) return { treeData: null, rawText: '' };
39
+
40
+ if (typeof d === 'string') {
41
+ try {
42
+ return { treeData: JSON.parse(d), rawText: d };
43
+ } catch {
44
+ return { treeData: null, rawText: d };
45
+ }
46
+ }
47
+
48
+ return { treeData: d, rawText: JSON.stringify(d, null, 2) };
49
+ }, [response?.data]);
50
+
51
+ // ── Derived ───────────────────────────────────────────────────────────────
52
+ const sizeKb = rawText ? `${(rawText.length / 1024).toFixed(1)} KB` : '';
53
+ const duration = response?.duration != null ? `${response.duration}ms` : '';
54
+ const hasError = Boolean(response?.error);
55
+ const hasStatus = response?.status != null;
56
+ const hasCopy = Boolean(rawText);
57
+
58
+ // ── Early returns ─────────────────────────────────────────────────────────
59
+ if (loading) {
60
+ return (
61
+ <div className="flex items-center justify-center h-full gap-2">
62
+ <Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
63
+ <span className="text-xs text-muted-foreground">Sending…</span>
64
+ </div>
65
+ );
66
+ }
67
+
68
+ if (!selectedEndpoint) return <EmptyState icon={Terminal} text="Response will appear here" />;
69
+ if (!response) return <EmptyState icon={Send} text='Press "Send Request" to see the response' />;
70
+
71
+ // Pure network error (no HTTP response at all — CORS, offline, timeout)
72
+ if (hasError && !hasStatus) {
73
+ return (
74
+ <EmptyState
75
+ icon={WifiOff}
76
+ text={response.error!}
77
+ className="text-destructive [&_svg]:text-destructive"
78
+ />
79
+ );
80
+ }
81
+
82
+ // ── Render ────────────────────────────────────────────────────────────────
83
+ return (
84
+ <>
85
+ {/* Status bar */}
86
+ <div className="shrink-0 border-b px-4 py-2 flex items-center justify-between gap-3 bg-muted/20">
87
+ <div className="flex items-center gap-2 min-w-0">
88
+ {hasStatus && <StatusBadge status={response.status!} />}
89
+ {response.statusText && (
90
+ <span className="text-xs text-muted-foreground truncate">{response.statusText}</span>
91
+ )}
92
+ {sizeKb && (
93
+ <span className="text-[10px] text-muted-foreground/50 tabular-nums shrink-0">{sizeKb}</span>
94
+ )}
95
+ {duration && (
96
+ <span className="text-[10px] text-muted-foreground/50 tabular-nums shrink-0">{duration}</span>
97
+ )}
98
+ </div>
99
+ {hasCopy && (
100
+ <CopyButton value={rawText} variant="ghost" size="sm" className="h-6 px-2 text-[10px] text-muted-foreground shrink-0">
101
+ Copy
102
+ </CopyButton>
103
+ )}
104
+ </div>
105
+
106
+ {/* HTTP-level error body (4xx/5xx — has status but also error flag) */}
107
+ {hasError && (
108
+ <div className="shrink-0 mx-4 mt-3 rounded border border-destructive/20 bg-destructive/5 px-3 py-2">
109
+ <p className="text-xs text-destructive">{response.error}</p>
110
+ </div>
111
+ )}
112
+
113
+ {/* Body */}
114
+ <ScrollArea>
115
+ {treeData != null ? (
116
+ <JsonTree title="Response Body" data={treeData} config={JSON_TREE_CONFIG} />
117
+ ) : rawText ? (
118
+ <pre className="p-4 text-[11px] font-mono text-foreground/70 whitespace-pre-wrap break-all leading-relaxed">
119
+ {rawText}
120
+ </pre>
121
+ ) : (
122
+ <div className="py-10 text-center text-xs text-muted-foreground">Empty response body</div>
123
+ )}
124
+ </ScrollArea>
125
+ </>
126
+ );
127
+ }
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+
5
+ import { cn } from '@djangocfg/ui-core/lib';
6
+
7
+ import { useMobile } from '../../hooks/useMobile';
8
+ import { usePlaygroundContext } from '../../context/PlaygroundContext';
9
+ import { EndpointList } from './EndpointList';
10
+ import { RequestPanel } from './RequestPanel';
11
+ import { ResponsePanel } from './ResponsePanel';
12
+ import { Panel, PanelHeader } from './ui';
13
+
14
+ // ─── Mobile tab layout ────────────────────────────────────────────────────────
15
+
16
+ type MobileTab = 'endpoints' | 'request' | 'response';
17
+
18
+ const MOBILE_TABS: { id: MobileTab; label: string }[] = [
19
+ { id: 'endpoints', label: 'Endpoints' },
20
+ { id: 'request', label: 'Request' },
21
+ { id: 'response', label: 'Response' },
22
+ ];
23
+
24
+ function MobileView() {
25
+ const { state } = usePlaygroundContext();
26
+ const [tab, setTab] = React.useState<MobileTab>('endpoints');
27
+
28
+ React.useEffect(() => {
29
+ if (state.selectedEndpoint) setTab('request');
30
+ }, [state.selectedEndpoint?.path, state.selectedEndpoint?.method]);
31
+
32
+ React.useEffect(() => {
33
+ if (state.response && !state.loading) setTab('response');
34
+ }, [state.response, state.loading]);
35
+
36
+ const hasResponse = Boolean(state.response) && !state.loading;
37
+
38
+ return (
39
+ <Panel className="h-full">
40
+ <div className="shrink-0 flex border-b">
41
+ {MOBILE_TABS.map((t) => {
42
+ const isActive = tab === t.id;
43
+ const showDot = t.id === 'response' && hasResponse;
44
+ return (
45
+ <button
46
+ key={t.id}
47
+ onClick={() => setTab(t.id)}
48
+ className={cn(
49
+ 'flex-1 py-2.5 text-xs font-medium transition-colors border-b-2 -mb-px relative',
50
+ isActive
51
+ ? 'border-primary text-foreground'
52
+ : 'border-transparent text-muted-foreground hover:text-foreground',
53
+ )}
54
+ >
55
+ {t.label}
56
+ {showDot && (
57
+ <span className="absolute top-2 right-[calc(50%-16px)] h-1.5 w-1.5 rounded-full bg-primary" />
58
+ )}
59
+ </button>
60
+ );
61
+ })}
62
+ </div>
63
+
64
+ <Panel className="flex-1">
65
+ {tab === 'endpoints' && <EndpointList />}
66
+ {tab === 'request' && <RequestPanel />}
67
+ {tab === 'response' && <ResponsePanel />}
68
+ </Panel>
69
+ </Panel>
70
+ );
71
+ }
72
+
73
+ // ─── Desktop 3-column layout ─────────────────────────────────────────────────
74
+
75
+ function DesktopView() {
76
+ return (
77
+ <div className="grid grid-cols-[260px_1fr_1fr] divide-x h-full min-h-0 overflow-hidden">
78
+ <Panel>
79
+ <PanelHeader title="Endpoints" />
80
+ <EndpointList />
81
+ </Panel>
82
+ <Panel>
83
+ <PanelHeader title="Request" />
84
+ <RequestPanel />
85
+ </Panel>
86
+ <Panel>
87
+ <PanelHeader title="Response" />
88
+ <ResponsePanel />
89
+ </Panel>
90
+ </div>
91
+ );
92
+ }
93
+
94
+ // ─── Root ─────────────────────────────────────────────────────────────────────
95
+
96
+ export const PlaygroundLayout: React.FC = () => {
97
+ const { isMobile } = useMobile();
98
+
99
+ return (
100
+ <div
101
+ className="flex flex-col overflow-hidden"
102
+ style={{ height: 'calc(100dvh - var(--navbar-height, 64px))' }}
103
+ >
104
+ {isMobile ? <MobileView /> : <DesktopView />}
105
+ </div>
106
+ );
107
+ };
@@ -0,0 +1,137 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * Shared primitive UI components used across all PlaygroundLayout panels.
5
+ * Keep this file free of any business logic or context reads.
6
+ */
7
+
8
+ import { ChevronRight } from 'lucide-react';
9
+ import React from 'react';
10
+
11
+ import { cn } from '@djangocfg/ui-core/lib';
12
+
13
+ // ─── Style helpers ────────────────────────────────────────────────────────────
14
+
15
+ const METHOD_STYLES: Record<string, string> = {
16
+ GET: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/25',
17
+ POST: 'bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/25',
18
+ PUT: 'bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25',
19
+ PATCH: 'bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/25',
20
+ DELETE: 'bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/25',
21
+ } as const;
22
+
23
+ const METHOD_FALLBACK = 'bg-muted text-muted-foreground border-border';
24
+
25
+ export function getMethodStyle(method: string): string {
26
+ return METHOD_STYLES[method.toUpperCase()] ?? METHOD_FALLBACK;
27
+ }
28
+
29
+ export function getStatusStyle(status: number): string {
30
+ if (status >= 500) return 'bg-red-500/10 text-red-500 dark:text-red-400 border-red-500/25';
31
+ if (status >= 400) return 'bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25';
32
+ if (status >= 300) return 'bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/25';
33
+ return 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/25';
34
+ }
35
+
36
+ export function relativePath(full: string): string {
37
+ try { return new URL(full).pathname; } catch { return full; }
38
+ }
39
+
40
+ // ─── Atoms ────────────────────────────────────────────────────────────────────
41
+
42
+ export function MethodBadge({ method }: { method: string }) {
43
+ return (
44
+ <span className={cn(
45
+ 'inline-flex shrink-0 items-center rounded border px-1.5 py-px',
46
+ 'font-mono text-[10px] font-bold uppercase tracking-wider leading-none',
47
+ getMethodStyle(method),
48
+ )}>
49
+ {method}
50
+ </span>
51
+ );
52
+ }
53
+
54
+ export function StatusBadge({ status }: { status: number }) {
55
+ return (
56
+ <span className={cn(
57
+ 'inline-flex items-center rounded border px-1.5 py-px',
58
+ 'font-mono text-[11px] font-bold leading-none',
59
+ getStatusStyle(status),
60
+ )}>
61
+ {status}
62
+ </span>
63
+ );
64
+ }
65
+
66
+ export function SectionLabel({ children }: { children: React.ReactNode }) {
67
+ return (
68
+ <p className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/60 select-none">
69
+ {children}
70
+ </p>
71
+ );
72
+ }
73
+
74
+ export function Panel({ children, className }: { children: React.ReactNode; className?: string }) {
75
+ return (
76
+ <div className={cn('flex flex-col min-h-0 overflow-hidden', className)}>
77
+ {children}
78
+ </div>
79
+ );
80
+ }
81
+
82
+ export function ScrollArea({ children, className }: { children: React.ReactNode; className?: string }) {
83
+ return (
84
+ <div className={cn('flex-1 overflow-y-auto min-h-0', className)}>
85
+ {children}
86
+ </div>
87
+ );
88
+ }
89
+
90
+ export function PanelHeader({ title }: { title: string }) {
91
+ return (
92
+ <div className="shrink-0 border-b px-4 h-10 flex items-center">
93
+ <span className="text-[11px] font-semibold uppercase tracking-widest text-muted-foreground/50">
94
+ {title}
95
+ </span>
96
+ </div>
97
+ );
98
+ }
99
+
100
+ export function EmptyState({ icon: Icon, text }: { icon: React.ElementType; text: string }) {
101
+ return (
102
+ <div className="flex flex-col items-center justify-center h-full gap-3 px-6 text-center">
103
+ <Icon className="h-7 w-7 text-muted-foreground/25" />
104
+ <p className="text-xs text-muted-foreground">{text}</p>
105
+ </div>
106
+ );
107
+ }
108
+
109
+ export function CollapsibleSection({
110
+ label,
111
+ action,
112
+ children,
113
+ defaultOpen = false,
114
+ }: {
115
+ label: React.ReactNode;
116
+ action?: React.ReactNode;
117
+ children: React.ReactNode;
118
+ defaultOpen?: boolean;
119
+ }) {
120
+ const [open, setOpen] = React.useState(defaultOpen);
121
+ return (
122
+ <div className="space-y-0">
123
+ <div className="flex items-center justify-between">
124
+ <button
125
+ type="button"
126
+ onClick={() => setOpen((v) => !v)}
127
+ className="flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/60 hover:text-muted-foreground transition-colors py-1"
128
+ >
129
+ <ChevronRight className={cn('h-3 w-3 transition-transform', open && 'rotate-90')} />
130
+ {label}
131
+ </button>
132
+ {action && <div className="shrink-0">{action}</div>}
133
+ </div>
134
+ {open && <div>{children}</div>}
135
+ </div>
136
+ );
137
+ }
@@ -1,14 +1,5 @@
1
1
  /**
2
2
  * Playground Components
3
- *
4
- * Centralized exports for all playground components
5
3
  */
6
4
 
7
5
  export { PlaygroundLayout } from './PlaygroundLayout';
8
- export { PlaygroundStepper } from './PlaygroundStepper';
9
- export { EndpointsLibrary } from './EndpointsLibrary';
10
- export { EndpointInfo } from './EndpointInfo';
11
- export { RequestBuilder } from './RequestBuilder';
12
- export { RequestParametersForm } from './RequestParametersForm';
13
- export { ResponseViewer } from './ResponseViewer';
14
- export { VersionSelector } from './VersionSelector';