@datum-cloud/datum-ui 0.3.2-dev.5bd364b → 0.5.0
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/README.md +118 -49
- package/dist/alert/index.mjs +2 -3
- package/dist/{alert-BC2Mccfo.mjs → alert-BDj6od5I.mjs} +2 -4
- package/dist/app-navigation/index.mjs +4 -12
- package/dist/{app-navigation-CCvjPijd.mjs → app-navigation-84ro28PU.mjs} +5 -8
- package/dist/autocomplete/index.mjs +2 -7
- package/dist/{autocomplete-DcKO7pj5.mjs → autocomplete-V5-qslzS.mjs} +5 -7
- package/dist/avatar/index.mjs +2 -0
- package/dist/avatar-BtKVcvO4.mjs +28 -0
- package/dist/avatar-stack/index.mjs +2 -5
- package/dist/{avatar-stack-B21McFeb.mjs → avatar-stack-oVr8tsU7.mjs} +4 -31
- package/dist/badge/index.mjs +2 -3
- package/dist/{badge-bFgeYceE.mjs → badge-DJR33ftJ.mjs} +2 -4
- package/dist/breadcrumb/index.mjs +2 -4
- package/dist/{breadcrumb-BGYJgom_.mjs → breadcrumb-B-9G347O.mjs} +2 -4
- package/dist/button/index.mjs +3 -4
- package/dist/{button-C1wRfGtT.mjs → button-BllvE9Lm.mjs} +3 -5
- package/dist/{button-AzpnV-WB.mjs → button-D3RrsMfQ.mjs} +2 -4
- package/dist/{link-button-TIF2Zdrk.mjs → button-fO8nazJE.mjs} +3 -5
- package/dist/button-group/index.mjs +2 -5
- package/dist/{button-group-C1IB2K5s.mjs → button-group-CYPka2zz.mjs} +3 -5
- package/dist/calendar/index.mjs +2 -5
- package/dist/{calendar-DlIHeWb0.mjs → calendar-DEkCw7I1.mjs} +4 -6
- package/dist/{calendar-date-picker-Bw6Mrr-P.mjs → calendar-date-picker-DWK94_DC.mjs} +6 -8
- package/dist/card/index.mjs +2 -4
- package/dist/{card-3Kd0VdNf.mjs → card-DKG1Cwlj.mjs} +3 -6
- package/dist/chart/index.mjs +2 -4
- package/dist/{chart-BZqUKpkh.mjs → chart-CUa21ynK.mjs} +2 -4
- package/dist/checkbox/index.mjs +2 -4
- package/dist/{checkbox-LG1OKTpG.mjs → checkbox-I5BvrMPe.mjs} +3 -6
- package/dist/{close.icon-CMNMoXM_.mjs → close.icon-HCfS4Y-N.mjs} +2 -4
- package/dist/{cn-DWCc1QRE.mjs → cn-D2KYQ917.mjs} +1 -3
- package/dist/code-editor/index.mjs +2 -0
- package/dist/{col-DCneNxQj.mjs → col-q-J99UHe.mjs} +2 -7
- package/dist/collapsible/index.mjs +2 -3
- package/dist/{collapsible-Bt9UYfv3.mjs → collapsible-CUphkSBt.mjs} +1 -3
- package/dist/command/index.mjs +2 -5
- package/dist/{command-s0Yv3abE.mjs → command-DqHWukGK.mjs} +3 -5
- package/dist/components/base/avatar/index.d.ts +2 -0
- package/dist/components/base/avatar/index.d.ts.map +1 -0
- package/dist/components/base/index.d.ts +1 -0
- package/dist/components/base/index.d.ts.map +1 -1
- package/dist/components/features/code-editor/code-editor-tabs.d.ts +63 -0
- package/dist/components/features/code-editor/code-editor-tabs.d.ts.map +1 -0
- package/dist/components/features/code-editor/code-editor.d.ts +58 -0
- package/dist/components/features/code-editor/code-editor.d.ts.map +1 -0
- package/dist/components/features/code-editor/index.d.ts +6 -0
- package/dist/components/features/code-editor/index.d.ts.map +1 -0
- package/dist/components/features/code-editor/lib/editor.d.ts +7 -0
- package/dist/components/features/code-editor/lib/editor.d.ts.map +1 -0
- package/dist/components/features/code-editor/types.d.ts +98 -0
- package/dist/components/features/code-editor/types.d.ts.map +1 -0
- package/dist/components/features/index.d.ts +1 -0
- package/dist/components/features/index.d.ts.map +1 -1
- package/dist/components/toast.d.ts +2 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/data-table/index.mjs +21 -51
- package/dist/date-picker/index.mjs +3 -10
- package/dist/dialog/index.mjs +2 -5
- package/dist/{dialog-bnMMf9GD.mjs → dialog-Bm2H9lrx.mjs} +4 -6
- package/dist/{dialog-DXBaT9gA.mjs → dialog-DASRaFxD.mjs} +2 -4
- package/dist/dropdown/index.mjs +2 -3
- package/dist/{dropdown-Dgm_b6Mm.mjs → dropdown-DZiAt-jS.mjs} +3 -5
- package/dist/{dropdown-menu-DAFyO-qD.mjs → dropdown-menu-lALvDnab.mjs} +5 -7
- package/dist/dropzone/index.mjs +2 -5
- package/dist/{dropzone-DR6O9OdU.mjs → dropzone-ogtpQ4fy.mjs} +5 -8
- package/dist/empty-content/index.mjs +2 -3
- package/dist/{empty-content-Dm7_5jO9.mjs → empty-content-C63GPJ5d.mjs} +3 -9
- package/dist/form/index.mjs +2 -146
- package/dist/{use-stepper-DJd8o9dV.mjs → form-Co3fM4B7.mjs} +148 -51
- package/dist/grid/index.mjs +2 -3
- package/dist/hooks/index.mjs +3 -4
- package/dist/{use-debounce-Dc95PFRX.mjs → hooks-Cb7YlxN4.mjs} +1 -3
- package/dist/hover-card/index.mjs +2 -4
- package/dist/{hover-card-CUPfFUqE.mjs → hover-card-DDWWD5Hx.mjs} +2 -4
- package/dist/{icon-wrapper-9ticVbRL.mjs → icon-wrapper-DuLp3RM1.mjs} +1 -3
- package/dist/icons/index.mjs +4 -5
- package/dist/index.mjs +65 -70
- package/dist/input/index.mjs +2 -5
- package/dist/{input-DuyjEKEW.mjs → input-DOmNpcQJ.mjs} +2 -4
- package/dist/{input-fzXBheCN.mjs → input-FKGqZypx.mjs} +3 -5
- package/dist/input-group/index.mjs +2 -7
- package/dist/{input-group-CPaFSTEV.mjs → input-group-DDtz-RT7.mjs} +5 -7
- package/dist/input-number/index.mjs +2 -6
- package/dist/{input-number-D1HCcTXO.mjs → input-number-mDB-5M5C.mjs} +4 -6
- package/dist/input-with-addons/index.mjs +28 -3
- package/dist/label/index.mjs +2 -4
- package/dist/{label-_ste_Re3.mjs → label-cnAhY-ej.mjs} +3 -6
- package/dist/loader-overlay/index.mjs +2 -3
- package/dist/{loader-overlay-CpA0zV8D.mjs → loader-overlay-BTFdkp7W.mjs} +3 -5
- package/dist/map/index.mjs +2 -14
- package/dist/{map-2RG9pYZR.mjs → map-ClxB41Hg.mjs} +10 -14
- package/dist/{map-leaflet-imports-CgEyVRnp.mjs → map-leaflet-imports-CaMm_rdF.mjs} +1 -2
- package/dist/more-actions/index.mjs +2 -5
- package/dist/{more-actions-BODYgG1C.mjs → more-actions-CGagbIDT.mjs} +5 -7
- package/dist/nprogress/index.mjs +1 -3
- package/dist/page-title/index.mjs +2 -3
- package/dist/{page-title-D62FV6vD.mjs → page-title-R7QbfbWp.mjs} +2 -4
- package/dist/popover/index.mjs +2 -4
- package/dist/{popover-Ds9624qY.mjs → popover-FJAcbYoH.mjs} +2 -4
- package/dist/radio-group/index.mjs +2 -4
- package/dist/{radio-group-B9Hm77LQ.mjs → radio-group-CiITR0LO.mjs} +3 -6
- package/dist/select/index.mjs +2 -4
- package/dist/{select-CwVIFWFO.mjs → select-CiLR_DiQ.mjs} +3 -6
- package/dist/separator/index.mjs +2 -4
- package/dist/{separator-T2ppyD-8.mjs → separator-DXVTncCK.mjs} +2 -4
- package/dist/sheet/index.mjs +3 -5
- package/dist/{sheet-mx5XjyEY.mjs → sheet-BzXksqYY.mjs} +4 -6
- package/dist/{sheet-Cemwh78x.mjs → sheet-Di3b-oPu.mjs} +2 -4
- package/dist/sidebar/index.mjs +2 -10
- package/dist/{sidebar-BW76ss_f.mjs → sidebar-BnhnjvfO.mjs} +10 -14
- package/dist/skeleton/index.mjs +2 -5
- package/dist/{skeleton-CkE23wsL.mjs → skeleton-BKl4mfJt.mjs} +2 -4
- package/dist/{skeleton-DZ31pU4B.mjs → skeleton-D1MUhAVo.mjs} +3 -5
- package/dist/spinner/index.mjs +2 -4
- package/dist/{spinner-earfjpJs.mjs → spinner-OyOf9-Yu.mjs} +2 -4
- package/dist/{spinner.icon-Bg8zgGh0.mjs → spinner.icon-C-vjSM6o.mjs} +2 -4
- package/dist/stepper/index.mjs +321 -5
- package/dist/switch/index.mjs +2 -4
- package/dist/{switch-Cn9IM2gC.mjs → switch-DQJQhPIQ.mjs} +3 -6
- package/dist/table/index.mjs +2 -4
- package/dist/{table-Dpzh0VPK.mjs → table-Cdsh-39-.mjs} +2 -4
- package/dist/tabs/index.mjs +50 -3
- package/dist/tag-input/index.mjs +2 -5
- package/dist/{tag-input-DorFQ9bA.mjs → tag-input-BVSwNcRd.mjs} +5 -7
- package/dist/task-queue/index.mjs +2 -7
- package/dist/{task-queue-dropdown-DtS0IKci.mjs → task-queue-dropdown-DyM5R8KF.mjs} +10 -30
- package/dist/textarea/index.mjs +2 -5
- package/dist/{textarea-QYRcDEpK.mjs → textarea-94vq_G_S.mjs} +2 -4
- package/dist/{textarea-KZUKGHlO.mjs → textarea-BwD-MmTV.mjs} +3 -5
- package/dist/theme/index.mjs +2 -3
- package/dist/{theme.provider-BG3cS9xe.mjs → themes-DG1md8FI.mjs} +1 -6
- package/dist/{to-api-format-CzPt5UAX.mjs → to-api-format-BnbRFYQI.mjs} +9 -18
- package/dist/toast/index.mjs +3 -3
- package/dist/{use-toast-DBmysDS6.mjs → toast-BWnN5fax.mjs} +5 -42
- package/dist/toast-DpxlFNNx.mjs +37 -0
- package/dist/tooltip/index.mjs +2 -4
- package/dist/{tooltip-U3XxlW4l.mjs → tooltip-Cruvl5F6.mjs} +3 -6
- package/dist/types-BZNk3q65.mjs +357 -0
- package/dist/typography/index.mjs +2 -3
- package/dist/{typography-DdrxIJMd.mjs → typography-ClB8k55E.mjs} +2 -4
- package/dist/{use-copy-to-clipboard-C9cT2Qb-.mjs → use-copy-to-clipboard-BGdTmkFV.mjs} +2 -4
- package/dist/utils/index.mjs +2 -3
- package/dist/{utils-Bfgoe-Gm.mjs → utils-C8KwMfT_.mjs} +1 -3
- package/dist/visually-hidden/index.mjs +2 -3
- package/dist/{visuallyhidden-CfBnXfvh.mjs → visuallyhidden-BLUsJpYH.mjs} +1 -3
- package/package.json +30 -4
- package/dist/input-with-addons-DN9LGwUU.mjs +0 -30
- package/dist/stepper-CZeks9Ex.mjs +0 -323
- package/dist/tabs-OYVCDOif.mjs +0 -52
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { t as cn } from "./cn-D2KYQ917.mjs";
|
|
2
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from "./tabs/index.mjs";
|
|
3
|
+
import { n as useTheme } from "./themes-DG1md8FI.mjs";
|
|
4
|
+
import { t as toast } from "./toast-BWnN5fax.mjs";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import Editor from "@monaco-editor/react";
|
|
8
|
+
import yaml from "js-yaml";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
//#region src/components/features/code-editor/code-editor.tsx
|
|
11
|
+
/**
|
|
12
|
+
* CodeEditor - Monaco-based code editor component
|
|
13
|
+
*
|
|
14
|
+
* A Monaco Editor wrapper with single language support, theme integration,
|
|
15
|
+
* and form compatibility. Provides a VS Code-like editing experience with
|
|
16
|
+
* automatic formatting, responsive layout, and error state handling.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Monaco Editor with VS Code experience
|
|
20
|
+
* - Theme-aware (automatic light/dark mode)
|
|
21
|
+
* - Form-compatible (hidden input for React Hook Form)
|
|
22
|
+
* - Responsive layout with automatic resizing
|
|
23
|
+
* - Read-only mode support
|
|
24
|
+
* - Custom error state styling
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { CodeEditor } from '@datum-cloud/datum-ui/code-editor'
|
|
29
|
+
*
|
|
30
|
+
* // Basic usage
|
|
31
|
+
* <CodeEditor
|
|
32
|
+
* value={code}
|
|
33
|
+
* onChange={(newValue) => setCode(newValue)}
|
|
34
|
+
* language="yaml"
|
|
35
|
+
* minHeight="400px"
|
|
36
|
+
* />
|
|
37
|
+
*
|
|
38
|
+
* // With error state
|
|
39
|
+
* <CodeEditor
|
|
40
|
+
* value={invalidJson}
|
|
41
|
+
* onChange={handleChange}
|
|
42
|
+
* language="json"
|
|
43
|
+
* error="Invalid JSON format"
|
|
44
|
+
* />
|
|
45
|
+
*
|
|
46
|
+
* // Read-only mode
|
|
47
|
+
* <CodeEditor
|
|
48
|
+
* value={config}
|
|
49
|
+
* language="yaml"
|
|
50
|
+
* readOnly={true}
|
|
51
|
+
* />
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param props - Component props
|
|
55
|
+
* @param props.value - Editor content
|
|
56
|
+
* @param props.onChange - Content change callback
|
|
57
|
+
* @param props.language - Syntax highlighting language
|
|
58
|
+
* @param props.id - Input element ID for form integration
|
|
59
|
+
* @param props.name - Input element name for form submission (default: 'code-editor')
|
|
60
|
+
* @param props.error - Error message to display below the editor
|
|
61
|
+
* @param props.className - Additional CSS classes
|
|
62
|
+
* @param props.readOnly - Read-only mode (default: false)
|
|
63
|
+
* @param props.minHeight - Minimum editor height (default: '200px')
|
|
64
|
+
* @returns Rendered Monaco editor with form integration
|
|
65
|
+
*/
|
|
66
|
+
function CodeEditor({ value, onChange, language, id, name = "code-editor", error, className, readOnly = false, minHeight = "200px" }) {
|
|
67
|
+
const { theme } = useTheme();
|
|
68
|
+
const editorRef = useRef(null);
|
|
69
|
+
const [mounted, setMounted] = useState(false);
|
|
70
|
+
const monacoTheme = theme === "dark" ? "vs-dark" : "light";
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (editorRef.current && !mounted) {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
editorRef.current?.getAction("editor.action.formatDocument")?.run();
|
|
75
|
+
}, 300);
|
|
76
|
+
setMounted(true);
|
|
77
|
+
}
|
|
78
|
+
}, [mounted]);
|
|
79
|
+
const handleEditorChange = (newValue) => {
|
|
80
|
+
onChange?.(newValue || "");
|
|
81
|
+
};
|
|
82
|
+
const handleEditorDidMount = (editor) => {
|
|
83
|
+
editorRef.current = editor;
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
86
|
+
className: cn("relative", className),
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ jsx(Editor, {
|
|
89
|
+
height: minHeight,
|
|
90
|
+
language,
|
|
91
|
+
value,
|
|
92
|
+
theme: monacoTheme,
|
|
93
|
+
onChange: handleEditorChange,
|
|
94
|
+
onMount: handleEditorDidMount,
|
|
95
|
+
options: {
|
|
96
|
+
readOnly,
|
|
97
|
+
minimap: { enabled: false },
|
|
98
|
+
fontSize: 14,
|
|
99
|
+
tabSize: 2,
|
|
100
|
+
wordWrap: "on",
|
|
101
|
+
lineNumbers: "on",
|
|
102
|
+
folding: true,
|
|
103
|
+
automaticLayout: true
|
|
104
|
+
},
|
|
105
|
+
className: cn(error && "border border-destructive rounded-md")
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ jsx("input", {
|
|
108
|
+
type: "hidden",
|
|
109
|
+
id,
|
|
110
|
+
name,
|
|
111
|
+
value
|
|
112
|
+
}),
|
|
113
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
114
|
+
className: "text-sm text-destructive mt-1",
|
|
115
|
+
children: error
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/components/features/code-editor/lib/editor.ts
|
|
122
|
+
function isValidJson(jsonStr) {
|
|
123
|
+
try {
|
|
124
|
+
JSON.parse(jsonStr);
|
|
125
|
+
return true;
|
|
126
|
+
} catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isValidYaml(yamlStr) {
|
|
131
|
+
try {
|
|
132
|
+
yaml.load(yamlStr, { schema: yaml.FAILSAFE_SCHEMA });
|
|
133
|
+
return true;
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function formatJson(jsonStr) {
|
|
139
|
+
try {
|
|
140
|
+
const parsed = JSON.parse(jsonStr);
|
|
141
|
+
return JSON.stringify(parsed, null, 2);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw new Error(`Invalid JSON format: ${error instanceof Error ? error.message : String(error)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function formatYaml(yamlStr) {
|
|
147
|
+
try {
|
|
148
|
+
const parsed = yaml.load(yamlStr, { schema: yaml.FAILSAFE_SCHEMA });
|
|
149
|
+
return yaml.dump(parsed, {
|
|
150
|
+
indent: 2,
|
|
151
|
+
lineWidth: -1,
|
|
152
|
+
noRefs: true
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
throw new Error(`Invalid YAML format: ${error instanceof Error ? error.message : String(error)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function jsonToYaml(jsonStr) {
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(jsonStr);
|
|
161
|
+
return yaml.dump(parsed, {
|
|
162
|
+
indent: 2,
|
|
163
|
+
lineWidth: -1,
|
|
164
|
+
noRefs: true
|
|
165
|
+
});
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw new Error(`Invalid JSON format: ${error instanceof Error ? error.message : String(error)}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function yamlToJson(yamlStr) {
|
|
171
|
+
try {
|
|
172
|
+
const parsed = yaml.load(yamlStr, { schema: yaml.FAILSAFE_SCHEMA });
|
|
173
|
+
return JSON.stringify(parsed, null, 2);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw new Error(`Invalid YAML format: ${error instanceof Error ? error.message : String(error)}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/components/features/code-editor/code-editor-tabs.tsx
|
|
180
|
+
/**
|
|
181
|
+
* CodeEditorTabs - Dual-format code editor with JSON ↔ YAML conversion
|
|
182
|
+
*
|
|
183
|
+
* A tabbed interface that provides JSON and YAML editing with automatic
|
|
184
|
+
* bidirectional conversion and validation. Prevents tab switching when
|
|
185
|
+
* content has syntax errors and shows error toasts for conversion failures.
|
|
186
|
+
*
|
|
187
|
+
* Features:
|
|
188
|
+
* - Dual-format editing (JSON ↔ YAML)
|
|
189
|
+
* - Automatic bidirectional conversion
|
|
190
|
+
* - Real-time validation before conversion
|
|
191
|
+
* - Error toasts for conversion failures
|
|
192
|
+
* - Maintains sync between both formats
|
|
193
|
+
* - Hidden format field for form submission
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* import { CodeEditorTabs } from '@datum-cloud/datum-ui/code-editor'
|
|
198
|
+
*
|
|
199
|
+
* // Basic usage
|
|
200
|
+
* <CodeEditorTabs
|
|
201
|
+
* value={config}
|
|
202
|
+
* format="yaml"
|
|
203
|
+
* onChange={(value, format) => {
|
|
204
|
+
* setConfig(value)
|
|
205
|
+
* setFormat(format)
|
|
206
|
+
* }}
|
|
207
|
+
* name="configuration"
|
|
208
|
+
* minHeight="500px"
|
|
209
|
+
* />
|
|
210
|
+
*
|
|
211
|
+
* // With React Hook Form
|
|
212
|
+
* const { watch, setValue } = useForm()
|
|
213
|
+
*
|
|
214
|
+
* <CodeEditorTabs
|
|
215
|
+
* value={watch('config')}
|
|
216
|
+
* onChange={(value) => setValue('config', value)}
|
|
217
|
+
* name="config"
|
|
218
|
+
* />
|
|
219
|
+
*
|
|
220
|
+
* // With format change handler
|
|
221
|
+
* <CodeEditorTabs
|
|
222
|
+
* value={data}
|
|
223
|
+
* format={currentFormat}
|
|
224
|
+
* onChange={(value, format) => console.log({ value, format })}
|
|
225
|
+
* onFormatChange={(format) => setCurrentFormat(format)}
|
|
226
|
+
* />
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* @param props - Component props
|
|
230
|
+
* @param props.value - Editor content
|
|
231
|
+
* @param props.onChange - Content and format change callback
|
|
232
|
+
* @param props.format - Active format ('json' or 'yaml', default: 'yaml')
|
|
233
|
+
* @param props.onFormatChange - Format change callback
|
|
234
|
+
* @param props.error - Error message to display below the editor
|
|
235
|
+
* @param props.id - Input element ID for form integration
|
|
236
|
+
* @param props.name - Input element name for form submission (default: 'code-editor')
|
|
237
|
+
* @param props.minHeight - Minimum editor height (default: '300px')
|
|
238
|
+
* @returns Rendered tabbed editor with JSON/YAML conversion
|
|
239
|
+
*/
|
|
240
|
+
function CodeEditorTabs({ value, onChange, format = "yaml", onFormatChange, error, id, name = "code-editor", minHeight = "300px" }) {
|
|
241
|
+
const [jsonContent, setJsonContent] = useState("");
|
|
242
|
+
const [yamlContent, setYamlContent] = useState("");
|
|
243
|
+
const [activeTab, setActiveTab] = useState(format);
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
if (format === "json") {
|
|
246
|
+
setJsonContent(value);
|
|
247
|
+
try {
|
|
248
|
+
setYamlContent(jsonToYaml(value));
|
|
249
|
+
} catch {}
|
|
250
|
+
} else {
|
|
251
|
+
setYamlContent(value);
|
|
252
|
+
try {
|
|
253
|
+
setJsonContent(yamlToJson(value));
|
|
254
|
+
} catch {}
|
|
255
|
+
}
|
|
256
|
+
}, [value, format]);
|
|
257
|
+
const handleJsonChange = (newValue) => {
|
|
258
|
+
setJsonContent(newValue);
|
|
259
|
+
try {
|
|
260
|
+
setYamlContent(jsonToYaml(newValue));
|
|
261
|
+
if (activeTab === "json") onChange?.(newValue, "json");
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error("Failed to convert JSON to YAML:", error);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const handleYamlChange = (newValue) => {
|
|
267
|
+
setYamlContent(newValue);
|
|
268
|
+
try {
|
|
269
|
+
setJsonContent(yamlToJson(newValue));
|
|
270
|
+
if (activeTab === "yaml") onChange?.(newValue, "yaml");
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error("Failed to convert YAML to JSON:", error);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const handleTabChange = (newTab) => {
|
|
276
|
+
const newFormat = newTab;
|
|
277
|
+
const currentContent = activeTab === "json" ? jsonContent : yamlContent;
|
|
278
|
+
try {
|
|
279
|
+
if (activeTab === "json") jsonToYaml(currentContent);
|
|
280
|
+
else yamlToJson(currentContent);
|
|
281
|
+
setActiveTab(newFormat);
|
|
282
|
+
onFormatChange?.(newFormat);
|
|
283
|
+
onChange?.(newFormat === "json" ? jsonContent : yamlContent, newFormat);
|
|
284
|
+
} catch {
|
|
285
|
+
const errorMsg = activeTab === "json" ? "Invalid JSON format. Please fix errors before switching tabs." : "Invalid YAML format. Please fix errors before switching tabs.";
|
|
286
|
+
toast.error(errorMsg, { id: `${activeTab}-to-${newFormat}-error` });
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
return /* @__PURE__ */ jsxs(Tabs, {
|
|
290
|
+
value: activeTab,
|
|
291
|
+
onValueChange: handleTabChange,
|
|
292
|
+
children: [
|
|
293
|
+
/* @__PURE__ */ jsxs(TabsList, { children: [/* @__PURE__ */ jsx(TabsTrigger, {
|
|
294
|
+
value: "yaml",
|
|
295
|
+
children: "YAML"
|
|
296
|
+
}), /* @__PURE__ */ jsx(TabsTrigger, {
|
|
297
|
+
value: "json",
|
|
298
|
+
children: "JSON"
|
|
299
|
+
})] }),
|
|
300
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
301
|
+
value: "yaml",
|
|
302
|
+
children: /* @__PURE__ */ jsx(CodeEditor, {
|
|
303
|
+
value: yamlContent,
|
|
304
|
+
onChange: handleYamlChange,
|
|
305
|
+
language: "yaml",
|
|
306
|
+
minHeight,
|
|
307
|
+
error
|
|
308
|
+
})
|
|
309
|
+
}),
|
|
310
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
311
|
+
value: "json",
|
|
312
|
+
children: /* @__PURE__ */ jsx(CodeEditor, {
|
|
313
|
+
value: jsonContent,
|
|
314
|
+
onChange: handleJsonChange,
|
|
315
|
+
language: "json",
|
|
316
|
+
minHeight,
|
|
317
|
+
error
|
|
318
|
+
})
|
|
319
|
+
}),
|
|
320
|
+
/* @__PURE__ */ jsx("input", {
|
|
321
|
+
type: "hidden",
|
|
322
|
+
id,
|
|
323
|
+
name,
|
|
324
|
+
value: activeTab === "json" ? jsonContent : yamlContent
|
|
325
|
+
}),
|
|
326
|
+
/* @__PURE__ */ jsx("input", {
|
|
327
|
+
type: "hidden",
|
|
328
|
+
name: `${name}-format`,
|
|
329
|
+
value: activeTab
|
|
330
|
+
})
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/components/features/code-editor/types.ts
|
|
336
|
+
const jsonSchema = z.object({ jsonContent: z.string().min(1, "JSON content is required").refine(isValidJson, { message: "Invalid JSON format" }) });
|
|
337
|
+
const yamlSchema = z.object({ yamlContent: z.string().min(1, "YAML content is required").refine(isValidYaml, { message: "Invalid YAML format" }) });
|
|
338
|
+
function createCodeEditorSchema(name = "code-editor") {
|
|
339
|
+
return z.object({
|
|
340
|
+
[name]: z.string().min(1, `${name} content is required`),
|
|
341
|
+
format: z.enum(["json", "yaml"])
|
|
342
|
+
}).superRefine((data, ctx) => {
|
|
343
|
+
const content = data[name];
|
|
344
|
+
if (data.format === "json" && !isValidJson(content)) ctx.addIssue({
|
|
345
|
+
code: z.ZodIssueCode.custom,
|
|
346
|
+
message: "Invalid JSON format",
|
|
347
|
+
path: [name]
|
|
348
|
+
});
|
|
349
|
+
else if (data.format === "yaml" && !isValidYaml(content)) ctx.addIssue({
|
|
350
|
+
code: z.ZodIssueCode.custom,
|
|
351
|
+
message: "Invalid YAML format",
|
|
352
|
+
path: [name]
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
export { formatJson as a, isValidYaml as c, CodeEditor as d, CodeEditorTabs as i, jsonToYaml as l, jsonSchema as n, formatYaml as o, yamlSchema as r, isValidJson as s, createCodeEditorSchema as t, yamlToJson as u };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { a as ListItem, c as Title, d as titleVariants, i as List, l as paragraphVariants, n as Code, o as Paragraph, r as Link, s as Text, t as Blockquote, u as textVariants } from "../typography-
|
|
2
|
-
|
|
3
|
-
export { Blockquote, Code, Link, List, ListItem, Paragraph, Text, Title, paragraphVariants, textVariants, titleVariants };
|
|
1
|
+
import { a as ListItem, c as Title, d as titleVariants, i as List, l as paragraphVariants, n as Code, o as Paragraph, r as Link, s as Text, t as Blockquote, u as textVariants } from "../typography-ClB8k55E.mjs";
|
|
2
|
+
export { Blockquote, Code, Link, List, ListItem, Paragraph, Text, Title, paragraphVariants, textVariants, titleVariants };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { t as cn } from "./cn-
|
|
1
|
+
import { t as cn } from "./cn-D2KYQ917.mjs";
|
|
2
2
|
import { cva } from "class-variance-authority";
|
|
3
3
|
import { CopyIcon } from "lucide-react";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
6
|
//#region src/components/base/typography/typography.tsx
|
|
8
7
|
const titleVariants = cva("font-semibold leading-tight tracking-tight", {
|
|
9
8
|
variants: {
|
|
@@ -195,6 +194,5 @@ function Code({ className, as = "code", children, ...props }) {
|
|
|
195
194
|
children
|
|
196
195
|
});
|
|
197
196
|
}
|
|
198
|
-
|
|
199
197
|
//#endregion
|
|
200
|
-
export { ListItem as a, Title as c, titleVariants as d, List as i, paragraphVariants as l, Code as n, Paragraph as o, Link as r, Text as s, Blockquote as t, textVariants as u };
|
|
198
|
+
export { ListItem as a, Title as c, titleVariants as d, List as i, paragraphVariants as l, Code as n, Paragraph as o, Link as r, Text as s, Blockquote as t, textVariants as u };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as toast } from "./toast-BWnN5fax.mjs";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/hooks/use-copy-to-clipboard.ts
|
|
5
4
|
function useCopyToClipboard() {
|
|
6
5
|
const [isCopied, setIsCopied] = useState(false);
|
|
@@ -26,6 +25,5 @@ function useCopyToClipboard() {
|
|
|
26
25
|
}
|
|
27
26
|
}, [])];
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
|
-
export { useCopyToClipboard as t };
|
|
29
|
+
export { useCopyToClipboard as t };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { t as cn } from "../cn-
|
|
2
|
-
|
|
3
|
-
export { cn };
|
|
1
|
+
import { t as cn } from "../cn-D2KYQ917.mjs";
|
|
2
|
+
export { cn };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { clsx } from "clsx";
|
|
2
2
|
import { twMerge } from "tailwind-merge";
|
|
3
|
-
|
|
4
3
|
//#region ../shadcn/lib/utils.ts
|
|
5
4
|
/**
|
|
6
5
|
* shadcn/ui Utilities
|
|
@@ -15,6 +14,5 @@ import { twMerge } from "tailwind-merge";
|
|
|
15
14
|
function cn(...inputs) {
|
|
16
15
|
return twMerge(clsx(inputs));
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
//#endregion
|
|
20
|
-
export { cn as t };
|
|
18
|
+
export { cn as t };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { t as VisuallyHidden } from "../visuallyhidden-
|
|
2
|
-
|
|
3
|
-
export { VisuallyHidden };
|
|
1
|
+
import { t as VisuallyHidden } from "../visuallyhidden-BLUsJpYH.mjs";
|
|
2
|
+
export { VisuallyHidden };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datum-cloud/datum-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "https://github.com/datum-cloud/datum-ui"
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"types": "./dist/components/base/alert/index.d.ts",
|
|
45
45
|
"default": "./dist/alert/index.mjs"
|
|
46
46
|
},
|
|
47
|
+
"./avatar": {
|
|
48
|
+
"source": "./src/components/base/avatar/index.ts",
|
|
49
|
+
"types": "./dist/components/base/avatar/index.d.ts",
|
|
50
|
+
"default": "./dist/avatar/index.mjs"
|
|
51
|
+
},
|
|
47
52
|
"./badge": {
|
|
48
53
|
"source": "./src/components/base/badge/index.ts",
|
|
49
54
|
"types": "./dist/components/base/badge/index.d.ts",
|
|
@@ -79,6 +84,11 @@
|
|
|
79
84
|
"types": "./dist/components/base/chart/index.d.ts",
|
|
80
85
|
"default": "./dist/chart/index.mjs"
|
|
81
86
|
},
|
|
87
|
+
"./code-editor": {
|
|
88
|
+
"source": "./src/components/features/code-editor/index.ts",
|
|
89
|
+
"types": "./dist/components/features/code-editor/index.d.ts",
|
|
90
|
+
"default": "./dist/code-editor/index.mjs"
|
|
91
|
+
},
|
|
82
92
|
"./checkbox": {
|
|
83
93
|
"source": "./src/components/base/checkbox/index.ts",
|
|
84
94
|
"types": "./dist/components/base/checkbox/index.d.ts",
|
|
@@ -311,16 +321,19 @@
|
|
|
311
321
|
"peerDependencies": {
|
|
312
322
|
"@conform-to/react": ">=1",
|
|
313
323
|
"@conform-to/zod": ">=1",
|
|
324
|
+
"@monaco-editor/react": "^4.7.0",
|
|
314
325
|
"@stepperize/react": ">=4",
|
|
315
326
|
"@tanstack/react-table": ">=8",
|
|
316
327
|
"@tanstack/react-virtual": ">=3",
|
|
317
328
|
"date-fns": ">=4",
|
|
318
329
|
"date-fns-tz": ">=3",
|
|
330
|
+
"js-yaml": "^4.1.0",
|
|
319
331
|
"leaflet": ">=1.9",
|
|
320
332
|
"leaflet-draw": ">=1",
|
|
321
333
|
"leaflet.fullscreen": ">=5",
|
|
322
334
|
"leaflet.markercluster": ">=1.5",
|
|
323
335
|
"lucide-react": ">=0.400",
|
|
336
|
+
"monaco-editor": ">=0.44.0",
|
|
324
337
|
"motion": ">=11",
|
|
325
338
|
"nprogress": ">=0.2",
|
|
326
339
|
"nuqs": ">=2",
|
|
@@ -342,6 +355,9 @@
|
|
|
342
355
|
"@conform-to/zod": {
|
|
343
356
|
"optional": true
|
|
344
357
|
},
|
|
358
|
+
"@monaco-editor/react": {
|
|
359
|
+
"optional": true
|
|
360
|
+
},
|
|
345
361
|
"@stepperize/react": {
|
|
346
362
|
"optional": true
|
|
347
363
|
},
|
|
@@ -357,6 +373,9 @@
|
|
|
357
373
|
"date-fns-tz": {
|
|
358
374
|
"optional": true
|
|
359
375
|
},
|
|
376
|
+
"js-yaml": {
|
|
377
|
+
"optional": true
|
|
378
|
+
},
|
|
360
379
|
"leaflet": {
|
|
361
380
|
"optional": true
|
|
362
381
|
},
|
|
@@ -370,6 +389,9 @@
|
|
|
370
389
|
"optional": true
|
|
371
390
|
},
|
|
372
391
|
"lucide-react": {},
|
|
392
|
+
"monaco-editor": {
|
|
393
|
+
"optional": true
|
|
394
|
+
},
|
|
373
395
|
"motion": {
|
|
374
396
|
"optional": true
|
|
375
397
|
},
|
|
@@ -430,12 +452,14 @@
|
|
|
430
452
|
"devDependencies": {
|
|
431
453
|
"@conform-to/react": "^1.17.1",
|
|
432
454
|
"@conform-to/zod": "^1.17.1",
|
|
455
|
+
"@monaco-editor/react": "^4.7.0",
|
|
433
456
|
"@stepperize/react": "^6.1.0",
|
|
434
457
|
"@tanstack/react-table": "^8.21.3",
|
|
435
458
|
"@tanstack/react-virtual": "^3.13.19",
|
|
436
459
|
"@testing-library/jest-dom": "^6",
|
|
437
460
|
"@testing-library/react": "^16",
|
|
438
461
|
"@testing-library/user-event": "^14",
|
|
462
|
+
"@types/js-yaml": "^4.0.9",
|
|
439
463
|
"@types/leaflet": "^1.9.21",
|
|
440
464
|
"@types/leaflet-draw": "^1.0.13",
|
|
441
465
|
"@types/leaflet.fullscreen": "^5.2.0",
|
|
@@ -446,12 +470,14 @@
|
|
|
446
470
|
"date-fns": "^4.1.0",
|
|
447
471
|
"date-fns-tz": "^3.2.0",
|
|
448
472
|
"eslint": "^9.39.3",
|
|
473
|
+
"js-yaml": "^4.1.1",
|
|
449
474
|
"jsdom": "^26",
|
|
450
475
|
"leaflet": "^1.9.4",
|
|
451
476
|
"leaflet-draw": "^1.0.4",
|
|
452
477
|
"leaflet.fullscreen": "^5.3.0",
|
|
453
478
|
"leaflet.markercluster": "^1.5.3",
|
|
454
479
|
"lucide-react": "^0.556",
|
|
480
|
+
"monaco-editor": "^0.55.1",
|
|
455
481
|
"motion": "^12.34.4",
|
|
456
482
|
"nprogress": "^0.2.0",
|
|
457
483
|
"nuqs": "^2.8.9",
|
|
@@ -464,12 +490,12 @@
|
|
|
464
490
|
"react-number-format": "^5.4.4",
|
|
465
491
|
"sonner": "^2.0.7",
|
|
466
492
|
"tailwindcss": "^4.2.1",
|
|
467
|
-
"tsdown": "^0.
|
|
493
|
+
"tsdown": "^0.21.5",
|
|
468
494
|
"typescript": "^5.9",
|
|
469
495
|
"vitest": "^3",
|
|
470
496
|
"zod": "^4.3.6",
|
|
471
|
-
"@repo/
|
|
472
|
-
"@repo/
|
|
497
|
+
"@repo/config": "0.0.0",
|
|
498
|
+
"@repo/shadcn": "0.0.0"
|
|
473
499
|
},
|
|
474
500
|
"publishConfig": {
|
|
475
501
|
"access": "public"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as cn } from "./cn-DWCc1QRE.mjs";
|
|
2
|
-
import "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
-
//#region src/components/features/input-with-addons/input-with-addons.tsx
|
|
6
|
-
function InputWithAddons({ ref, leading, trailing, containerClassName, className, ...props }) {
|
|
7
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
8
|
-
className: cn("border-input-border bg-input-background/50 text-input-foreground placeholder:text-input-placeholder", "focus-within:border-input-focus-border focus-within:shadow-(--input-focus-shadow)", "group flex h-10 w-full items-stretch overflow-hidden rounded-lg border transition-all", "focus-within:ring-0 focus-within:ring-offset-0 focus-within:outline-hidden", containerClassName),
|
|
9
|
-
children: [
|
|
10
|
-
leading ? /* @__PURE__ */ jsx("div", {
|
|
11
|
-
className: "text-muted-foreground flex items-center bg-transparent pl-3",
|
|
12
|
-
children: leading
|
|
13
|
-
}) : null,
|
|
14
|
-
/* @__PURE__ */ jsx("input", {
|
|
15
|
-
className: cn("flex-1 bg-transparent px-3 text-base md:text-sm", "placeholder:text-input-placeholder text-input-foreground", "focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-hidden", "focus-visible:border-transparent focus-visible:shadow-none", "read-only:cursor-not-allowed read-only:opacity-50 disabled:cursor-not-allowed disabled:opacity-50", "file:text-foreground file:border-0 file:bg-transparent file:text-sm file:font-medium", leading && "pl-2", trailing && "pr-2", className),
|
|
16
|
-
"data-slot": "input-with-addons",
|
|
17
|
-
ref,
|
|
18
|
-
...props
|
|
19
|
-
}),
|
|
20
|
-
trailing ? /* @__PURE__ */ jsx("div", {
|
|
21
|
-
className: "text-muted-foreground flex items-center bg-transparent pr-3",
|
|
22
|
-
children: trailing
|
|
23
|
-
}) : null
|
|
24
|
-
]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
InputWithAddons.displayName = "InputWithAddons";
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { InputWithAddons as t };
|