@djangocfg/ui-tools 2.1.239 → 2.1.241

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/index.mjs CHANGED
@@ -12,7 +12,7 @@ export { ArrayFieldItemTemplate, ArrayFieldTemplate, BaseInputTemplate, Checkbox
12
12
  export { useLottie } from './chunk-6JTB2X72.mjs';
13
13
  import { __name } from './chunk-CGILA3WO.mjs';
14
14
  import * as React3 from 'react';
15
- import React3__default, { lazy, Suspense, useState, useMemo, useCallback } from 'react';
15
+ import React3__default, { lazy, forwardRef, useRef, useState, useCallback, useImperativeHandle, useEffect, createContext, Suspense, useMemo, useContext } from 'react';
16
16
  import { cn } from '@djangocfg/ui-core/lib';
17
17
  import { useAppT } from '@djangocfg/i18n';
18
18
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -881,6 +881,730 @@ function CronSchedulerFallback() {
881
881
  }
882
882
  __name(CronSchedulerFallback, "CronSchedulerFallback");
883
883
 
884
- export { CardLoadingFallback, CronScheduler, LazyCronScheduler, LazyHybridAudioPlayer, LazyHybridCompactPlayer, LazyHybridSimplePlayer, LazyImageViewer, LazyJsonSchemaForm, LazyJsonTree, LazyLottiePlayer, LazyMapContainer, LazyMapView, LazyMermaid, LazyOpenapiViewer, LazyPrettyCode, LazyVideoPlayer, LazyWrapper, LoadingFallback, LottiePlayer, MapLoadingFallback, MarkdownMessage, Mermaid_default as Mermaid, OpenapiViewer_default as OpenapiViewer, Spinner, createLazyComponent, useCollapsibleContent };
884
+ // src/tools/CodeEditor/workers/setup.ts
885
+ var isSetup = false;
886
+ function setupMonacoWorkers(getWorker) {
887
+ if (isSetup || typeof window === "undefined") return;
888
+ if (getWorker) {
889
+ self.MonacoEnvironment = {
890
+ getWorker: /* @__PURE__ */ __name((_workerId, label) => getWorker(label), "getWorker")
891
+ };
892
+ }
893
+ isSetup = true;
894
+ }
895
+ __name(setupMonacoWorkers, "setupMonacoWorkers");
896
+
897
+ // src/tools/CodeEditor/hooks/useMonaco.ts
898
+ function useMonaco() {
899
+ const [monaco, setMonaco] = useState(null);
900
+ const [isLoading, setIsLoading] = useState(true);
901
+ const [error, setError] = useState(null);
902
+ useEffect(() => {
903
+ let mounted = true;
904
+ async function loadMonaco() {
905
+ try {
906
+ setupMonacoWorkers();
907
+ const monacoModule = await import('monaco-editor');
908
+ if (mounted) {
909
+ setMonaco(monacoModule);
910
+ setIsLoading(false);
911
+ }
912
+ } catch (err) {
913
+ if (mounted) {
914
+ setError(err instanceof Error ? err : new Error("Failed to load Monaco Editor"));
915
+ setIsLoading(false);
916
+ }
917
+ }
918
+ }
919
+ __name(loadMonaco, "loadMonaco");
920
+ loadMonaco();
921
+ return () => {
922
+ mounted = false;
923
+ };
924
+ }, []);
925
+ return { monaco, isLoading, error };
926
+ }
927
+ __name(useMonaco, "useMonaco");
928
+ function useEditorTheme(monaco, themeOverride) {
929
+ const appTheme = useResolvedTheme();
930
+ const registered = useRef(false);
931
+ useEffect(() => {
932
+ if (!monaco || registered.current) return;
933
+ try {
934
+ const colors = _readCSSColors();
935
+ monaco.editor.defineTheme("app-dark", {
936
+ base: "vs-dark",
937
+ inherit: true,
938
+ rules: [
939
+ { token: "comment", foreground: "6A9955", fontStyle: "italic" },
940
+ { token: "keyword", foreground: "C586C0" },
941
+ { token: "string", foreground: "CE9178" },
942
+ { token: "number", foreground: "B5CEA8" },
943
+ { token: "type", foreground: "4EC9B0" },
944
+ { token: "function", foreground: "DCDCAA" },
945
+ { token: "variable", foreground: "9CDCFE" }
946
+ ],
947
+ colors: {
948
+ "editor.background": colors.background,
949
+ "editor.foreground": colors.foreground,
950
+ "editor.lineHighlightBackground": colors.lineHighlight,
951
+ "editor.selectionBackground": colors.selection,
952
+ "editorCursor.foreground": colors.foreground,
953
+ "editorLineNumber.foreground": colors.mutedForeground,
954
+ "editorWidget.background": colors.card,
955
+ "editorWidget.border": colors.border,
956
+ "input.background": colors.card,
957
+ "dropdown.background": colors.card
958
+ }
959
+ });
960
+ monaco.editor.defineTheme("app-light", {
961
+ base: "vs",
962
+ inherit: true,
963
+ rules: [
964
+ { token: "comment", foreground: "008000", fontStyle: "italic" },
965
+ { token: "keyword", foreground: "AF00DB" },
966
+ { token: "string", foreground: "A31515" },
967
+ { token: "number", foreground: "098658" },
968
+ { token: "type", foreground: "267F99" },
969
+ { token: "function", foreground: "795E26" },
970
+ { token: "variable", foreground: "001080" }
971
+ ],
972
+ colors: {
973
+ "editor.background": colors.backgroundLight,
974
+ "editor.foreground": colors.foregroundLight,
975
+ "editor.lineHighlightBackground": colors.lineHighlightLight,
976
+ "editor.selectionBackground": colors.selectionLight,
977
+ "editorLineNumber.foreground": colors.mutedForegroundLight,
978
+ "editorWidget.background": colors.cardLight,
979
+ "editorWidget.border": colors.borderLight
980
+ }
981
+ });
982
+ registered.current = true;
983
+ } catch {
984
+ }
985
+ }, [monaco]);
986
+ if (themeOverride) return themeOverride;
987
+ if (registered.current) {
988
+ return appTheme === "dark" ? "app-dark" : "app-light";
989
+ }
990
+ return appTheme === "dark" ? "vs-dark" : "vs";
991
+ }
992
+ __name(useEditorTheme, "useEditorTheme");
993
+ function _readCSSColors() {
994
+ const get = /* @__PURE__ */ __name((varName) => {
995
+ if (typeof document === "undefined") return "";
996
+ return getComputedStyle(document.documentElement).getPropertyValue(varName).trim();
997
+ }, "get");
998
+ const hslToHex2 = /* @__PURE__ */ __name((hsl) => {
999
+ if (!hsl) return "";
1000
+ const parts = hsl.split(/\s+/).map((s2) => parseFloat(s2.replace("%", "")));
1001
+ if (parts.length < 3 || parts.some(isNaN)) return "";
1002
+ const [h, s, l] = [parts[0], parts[1] / 100, parts[2] / 100];
1003
+ const a = s * Math.min(l, 1 - l);
1004
+ const f = /* @__PURE__ */ __name((n) => {
1005
+ const k = (n + h / 30) % 12;
1006
+ const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
1007
+ return Math.round(255 * color).toString(16).padStart(2, "0");
1008
+ }, "f");
1009
+ return `#${f(0)}${f(8)}${f(4)}`;
1010
+ }, "hslToHex");
1011
+ const background = hslToHex2(get("--background")) || "#0a0a0a";
1012
+ const foreground = hslToHex2(get("--foreground")) || "#f5f5f5";
1013
+ const card = hslToHex2(get("--card")) || "#141414";
1014
+ const border = hslToHex2(get("--border")) || "#262626";
1015
+ const mutedForeground = hslToHex2(get("--muted-foreground")) || "#858585";
1016
+ const lineHighlight = _adjustBrightness(background, 10);
1017
+ const primary = hslToHex2(get("--primary"));
1018
+ const selection = primary ? _adjustBrightness(primary, -40) : "#264F78";
1019
+ return {
1020
+ background,
1021
+ foreground,
1022
+ card,
1023
+ border,
1024
+ mutedForeground,
1025
+ lineHighlight,
1026
+ selection,
1027
+ // Light variants
1028
+ backgroundLight: "#ffffff",
1029
+ foregroundLight: "#1a1a1a",
1030
+ cardLight: "#ffffff",
1031
+ borderLight: "#e5e5e5",
1032
+ mutedForegroundLight: "#737373",
1033
+ lineHighlightLight: "#f5f5f5",
1034
+ selectionLight: "#ADD6FF"
1035
+ };
1036
+ }
1037
+ __name(_readCSSColors, "_readCSSColors");
1038
+ function _adjustBrightness(hex, amount) {
1039
+ const num = parseInt(hex.replace("#", ""), 16);
1040
+ const r = Math.min(255, Math.max(0, (num >> 16 & 255) + amount));
1041
+ const g = Math.min(255, Math.max(0, (num >> 8 & 255) + amount));
1042
+ const b = Math.min(255, Math.max(0, (num & 255) + amount));
1043
+ return `#${(r << 16 | g << 8 | b).toString(16).padStart(6, "0")}`;
1044
+ }
1045
+ __name(_adjustBrightness, "_adjustBrightness");
1046
+ var Editor = forwardRef(/* @__PURE__ */ __name(function Editor2({
1047
+ value = "",
1048
+ language = "plaintext",
1049
+ onChange,
1050
+ onMount,
1051
+ options = {},
1052
+ className = "",
1053
+ height = "100%",
1054
+ width = "100%",
1055
+ autoHeight = false,
1056
+ minHeight = 100,
1057
+ maxHeight = 600
1058
+ }, ref) {
1059
+ const containerRef = useRef(null);
1060
+ const editorRef = useRef(null);
1061
+ const { monaco, isLoading } = useMonaco();
1062
+ const resolvedTheme = useEditorTheme(monaco, options.theme);
1063
+ const [contentHeight, setContentHeight] = useState(null);
1064
+ const updateContentHeight = useCallback((editor) => {
1065
+ if (!autoHeight) return;
1066
+ const h = editor.getContentHeight();
1067
+ setContentHeight(Math.min(Math.max(h, minHeight), maxHeight));
1068
+ }, [autoHeight, minHeight, maxHeight]);
1069
+ const isInternalChangeRef = useRef(false);
1070
+ useImperativeHandle(ref, () => ({
1071
+ getEditor: /* @__PURE__ */ __name(() => editorRef.current, "getEditor"),
1072
+ getValue: /* @__PURE__ */ __name(() => editorRef.current?.getValue() || "", "getValue"),
1073
+ setValue: /* @__PURE__ */ __name((val) => editorRef.current?.setValue(val), "setValue"),
1074
+ focus: /* @__PURE__ */ __name(() => editorRef.current?.focus(), "focus")
1075
+ }));
1076
+ useEffect(() => {
1077
+ if (!monaco || !containerRef.current || editorRef.current) return;
1078
+ const editor = monaco.editor.create(containerRef.current, {
1079
+ value,
1080
+ language,
1081
+ theme: resolvedTheme,
1082
+ fontSize: options.fontSize || 14,
1083
+ fontFamily: options.fontFamily || "'Fira Code', 'Consolas', monospace",
1084
+ tabSize: options.tabSize || 2,
1085
+ insertSpaces: options.insertSpaces !== false,
1086
+ wordWrap: options.wordWrap || "on",
1087
+ minimap: { enabled: options.minimap !== false },
1088
+ lineNumbers: options.lineNumbers || "on",
1089
+ readOnly: options.readOnly || false,
1090
+ automaticLayout: true,
1091
+ scrollBeyondLastLine: autoHeight ? false : false,
1092
+ scrollbar: autoHeight ? { vertical: "hidden", horizontal: "auto" } : void 0,
1093
+ overviewRulerLanes: autoHeight ? 0 : void 0,
1094
+ padding: { top: 16, bottom: 16 },
1095
+ renderLineHighlight: "all",
1096
+ cursorBlinking: "smooth",
1097
+ cursorSmoothCaretAnimation: "on",
1098
+ smoothScrolling: true,
1099
+ bracketPairColorization: { enabled: true },
1100
+ guides: {
1101
+ bracketPairs: true,
1102
+ indentation: true
1103
+ }
1104
+ });
1105
+ editorRef.current = editor;
1106
+ if (onChange) {
1107
+ editor.onDidChangeModelContent(() => {
1108
+ isInternalChangeRef.current = true;
1109
+ onChange(editor.getValue());
1110
+ });
1111
+ }
1112
+ if (autoHeight) {
1113
+ editor.onDidContentSizeChange(() => updateContentHeight(editor));
1114
+ updateContentHeight(editor);
1115
+ }
1116
+ onMount?.(editor);
1117
+ return () => {
1118
+ editor.dispose();
1119
+ editorRef.current = null;
1120
+ };
1121
+ }, [monaco]);
1122
+ useEffect(() => {
1123
+ const editor = editorRef.current;
1124
+ if (!editor) return;
1125
+ if (isInternalChangeRef.current) {
1126
+ isInternalChangeRef.current = false;
1127
+ return;
1128
+ }
1129
+ const currentValue = editor.getValue();
1130
+ if (value !== currentValue) {
1131
+ const position = editor.getPosition();
1132
+ const selections = editor.getSelections();
1133
+ editor.setValue(value);
1134
+ if (position) {
1135
+ editor.setPosition(position);
1136
+ }
1137
+ if (selections && selections.length > 0) {
1138
+ editor.setSelections(selections);
1139
+ }
1140
+ }
1141
+ }, [value]);
1142
+ useEffect(() => {
1143
+ const editor = editorRef.current;
1144
+ if (!editor || !monaco) return;
1145
+ const model = editor.getModel();
1146
+ if (model) {
1147
+ monaco.editor.setModelLanguage(model, language);
1148
+ }
1149
+ }, [language, monaco]);
1150
+ useEffect(() => {
1151
+ const editor = editorRef.current;
1152
+ if (!editor) return;
1153
+ editor.updateOptions({
1154
+ theme: resolvedTheme,
1155
+ fontSize: options.fontSize,
1156
+ readOnly: options.readOnly,
1157
+ minimap: { enabled: options.minimap !== false },
1158
+ wordWrap: options.wordWrap,
1159
+ lineNumbers: options.lineNumbers
1160
+ });
1161
+ }, [options, resolvedTheme]);
1162
+ if (isLoading) {
1163
+ return /* @__PURE__ */ jsx(
1164
+ "div",
1165
+ {
1166
+ className,
1167
+ style: {
1168
+ width,
1169
+ height,
1170
+ display: "flex",
1171
+ alignItems: "center",
1172
+ justifyContent: "center",
1173
+ backgroundColor: "#1e1e1e",
1174
+ color: "#666"
1175
+ },
1176
+ children: "Loading editor..."
1177
+ }
1178
+ );
1179
+ }
1180
+ const resolvedHeight = autoHeight && contentHeight != null ? contentHeight : height;
1181
+ return /* @__PURE__ */ jsx(
1182
+ "div",
1183
+ {
1184
+ ref: containerRef,
1185
+ className,
1186
+ style: {
1187
+ width,
1188
+ height: resolvedHeight,
1189
+ ...autoHeight && { minHeight, maxHeight, overflow: "hidden" }
1190
+ }
1191
+ }
1192
+ );
1193
+ }, "Editor"));
1194
+ function DiffEditor({
1195
+ original,
1196
+ modified,
1197
+ language = "plaintext",
1198
+ options = {},
1199
+ className = "",
1200
+ height = "100%"
1201
+ }) {
1202
+ const containerRef = useRef(null);
1203
+ const editorRef = useRef(null);
1204
+ const { monaco, isLoading } = useMonaco();
1205
+ const resolvedTheme = useEditorTheme(monaco, options.theme);
1206
+ useEffect(() => {
1207
+ if (!monaco || !containerRef.current || editorRef.current) return;
1208
+ const editor = monaco.editor.createDiffEditor(containerRef.current, {
1209
+ theme: resolvedTheme,
1210
+ fontSize: options.fontSize || 14,
1211
+ fontFamily: options.fontFamily || "'Fira Code', 'Consolas', monospace",
1212
+ readOnly: true,
1213
+ automaticLayout: true,
1214
+ renderSideBySide: true,
1215
+ scrollBeyondLastLine: false,
1216
+ minimap: { enabled: false }
1217
+ });
1218
+ const originalModel = monaco.editor.createModel(original, language);
1219
+ const modifiedModel = monaco.editor.createModel(modified, language);
1220
+ editor.setModel({
1221
+ original: originalModel,
1222
+ modified: modifiedModel
1223
+ });
1224
+ editorRef.current = editor;
1225
+ return () => {
1226
+ originalModel.dispose();
1227
+ modifiedModel.dispose();
1228
+ editor.dispose();
1229
+ editorRef.current = null;
1230
+ };
1231
+ }, [monaco]);
1232
+ useEffect(() => {
1233
+ const editor = editorRef.current;
1234
+ if (!editor || !monaco) return;
1235
+ const model = editor.getModel();
1236
+ if (model) {
1237
+ model.original.setValue(original);
1238
+ model.modified.setValue(modified);
1239
+ }
1240
+ }, [original, modified, monaco]);
1241
+ useEffect(() => {
1242
+ const editor = editorRef.current;
1243
+ if (!editor || !monaco) return;
1244
+ const model = editor.getModel();
1245
+ if (model) {
1246
+ monaco.editor.setModelLanguage(model.original, language);
1247
+ monaco.editor.setModelLanguage(model.modified, language);
1248
+ }
1249
+ }, [language, monaco]);
1250
+ if (isLoading) {
1251
+ return /* @__PURE__ */ jsx(
1252
+ "div",
1253
+ {
1254
+ className,
1255
+ style: {
1256
+ width: "100%",
1257
+ height,
1258
+ display: "flex",
1259
+ alignItems: "center",
1260
+ justifyContent: "center",
1261
+ backgroundColor: "#1e1e1e",
1262
+ color: "#666"
1263
+ },
1264
+ children: "Loading diff editor..."
1265
+ }
1266
+ );
1267
+ }
1268
+ return /* @__PURE__ */ jsx(
1269
+ "div",
1270
+ {
1271
+ ref: containerRef,
1272
+ className,
1273
+ style: {
1274
+ width: "100%",
1275
+ height
1276
+ }
1277
+ }
1278
+ );
1279
+ }
1280
+ __name(DiffEditor, "DiffEditor");
1281
+
1282
+ // src/tools/CodeEditor/lib/languages.ts
1283
+ var LANGUAGE_MAP = {
1284
+ // Web
1285
+ ".html": "html",
1286
+ ".htm": "html",
1287
+ ".xhtml": "html",
1288
+ ".vue": "html",
1289
+ ".svelte": "html",
1290
+ // CSS
1291
+ ".css": "css",
1292
+ ".scss": "scss",
1293
+ ".sass": "scss",
1294
+ ".less": "less",
1295
+ // JavaScript/TypeScript
1296
+ ".js": "javascript",
1297
+ ".mjs": "javascript",
1298
+ ".cjs": "javascript",
1299
+ ".jsx": "javascript",
1300
+ ".ts": "typescript",
1301
+ ".tsx": "typescript",
1302
+ ".mts": "typescript",
1303
+ ".cts": "typescript",
1304
+ // Data formats
1305
+ ".json": "json",
1306
+ ".jsonc": "json",
1307
+ ".json5": "json",
1308
+ ".yaml": "yaml",
1309
+ ".yml": "yaml",
1310
+ ".toml": "ini",
1311
+ ".xml": "xml",
1312
+ ".svg": "xml",
1313
+ ".xsl": "xml",
1314
+ ".xsd": "xml",
1315
+ // Markdown & Documentation
1316
+ ".md": "markdown",
1317
+ ".mdx": "markdown",
1318
+ ".markdown": "markdown",
1319
+ ".rst": "restructuredtext",
1320
+ ".txt": "plaintext",
1321
+ ".text": "plaintext",
1322
+ // Programming languages
1323
+ ".py": "python",
1324
+ ".pyw": "python",
1325
+ ".pyi": "python",
1326
+ ".rb": "ruby",
1327
+ ".rake": "ruby",
1328
+ ".gemspec": "ruby",
1329
+ ".php": "php",
1330
+ ".phtml": "php",
1331
+ ".java": "java",
1332
+ ".kt": "kotlin",
1333
+ ".kts": "kotlin",
1334
+ ".scala": "scala",
1335
+ ".go": "go",
1336
+ ".rs": "rust",
1337
+ ".swift": "swift",
1338
+ ".c": "c",
1339
+ ".h": "c",
1340
+ ".cpp": "cpp",
1341
+ ".cc": "cpp",
1342
+ ".cxx": "cpp",
1343
+ ".hpp": "cpp",
1344
+ ".hxx": "cpp",
1345
+ ".cs": "csharp",
1346
+ ".fs": "fsharp",
1347
+ ".fsx": "fsharp",
1348
+ ".vb": "vb",
1349
+ ".lua": "lua",
1350
+ ".r": "r",
1351
+ ".R": "r",
1352
+ ".m": "objective-c",
1353
+ ".mm": "objective-c",
1354
+ ".pl": "perl",
1355
+ ".pm": "perl",
1356
+ ".ex": "elixir",
1357
+ ".exs": "elixir",
1358
+ ".erl": "erlang",
1359
+ ".hrl": "erlang",
1360
+ ".clj": "clojure",
1361
+ ".cljs": "clojure",
1362
+ ".cljc": "clojure",
1363
+ ".hs": "haskell",
1364
+ ".lhs": "haskell",
1365
+ ".ml": "fsharp",
1366
+ ".mli": "fsharp",
1367
+ ".dart": "dart",
1368
+ ".groovy": "groovy",
1369
+ ".gradle": "groovy",
1370
+ ".jl": "julia",
1371
+ // Shell & Scripts
1372
+ ".sh": "shell",
1373
+ ".bash": "shell",
1374
+ ".zsh": "shell",
1375
+ ".fish": "shell",
1376
+ ".ps1": "powershell",
1377
+ ".psm1": "powershell",
1378
+ ".psd1": "powershell",
1379
+ ".bat": "bat",
1380
+ ".cmd": "bat",
1381
+ // Config files
1382
+ ".ini": "ini",
1383
+ ".cfg": "ini",
1384
+ ".conf": "ini",
1385
+ ".properties": "ini",
1386
+ ".env": "ini",
1387
+ ".gitignore": "ini",
1388
+ ".gitattributes": "ini",
1389
+ ".editorconfig": "ini",
1390
+ ".npmrc": "ini",
1391
+ // Database
1392
+ ".sql": "sql",
1393
+ ".mysql": "mysql",
1394
+ ".pgsql": "pgsql",
1395
+ ".plsql": "plsql",
1396
+ ".redis": "redis",
1397
+ // Templates
1398
+ ".hbs": "handlebars",
1399
+ ".handlebars": "handlebars",
1400
+ ".mustache": "handlebars",
1401
+ ".ejs": "html",
1402
+ ".pug": "pug",
1403
+ ".jade": "pug",
1404
+ ".twig": "twig",
1405
+ ".liquid": "liquid",
1406
+ // GraphQL
1407
+ ".graphql": "graphql",
1408
+ ".gql": "graphql",
1409
+ // Docker
1410
+ ".dockerfile": "dockerfile",
1411
+ // Other
1412
+ ".diff": "diff",
1413
+ ".patch": "diff",
1414
+ ".log": "log",
1415
+ ".tex": "latex",
1416
+ ".cls": "latex",
1417
+ ".sty": "latex",
1418
+ ".proto": "protobuf",
1419
+ ".sol": "sol",
1420
+ ".asm": "mips",
1421
+ ".s": "mips",
1422
+ ".wasm": "wasm"
1423
+ };
1424
+ var FILENAME_MAP = {
1425
+ Dockerfile: "dockerfile",
1426
+ "docker-compose.yml": "yaml",
1427
+ "docker-compose.yaml": "yaml",
1428
+ Makefile: "makefile",
1429
+ makefile: "makefile",
1430
+ Gemfile: "ruby",
1431
+ Rakefile: "ruby",
1432
+ Jenkinsfile: "groovy",
1433
+ Vagrantfile: "ruby",
1434
+ ".bashrc": "shell",
1435
+ ".bash_profile": "shell",
1436
+ ".zshrc": "shell",
1437
+ ".profile": "shell",
1438
+ ".vimrc": "plaintext",
1439
+ ".gitconfig": "ini",
1440
+ ".htaccess": "ini",
1441
+ "nginx.conf": "ini",
1442
+ "package.json": "json",
1443
+ "tsconfig.json": "json",
1444
+ "jsconfig.json": "json",
1445
+ ".prettierrc": "json",
1446
+ ".eslintrc": "json",
1447
+ "composer.json": "json",
1448
+ "Cargo.toml": "ini",
1449
+ "go.mod": "go",
1450
+ "go.sum": "plaintext",
1451
+ "requirements.txt": "plaintext",
1452
+ "pyproject.toml": "ini",
1453
+ "setup.py": "python",
1454
+ "setup.cfg": "ini"
1455
+ };
1456
+ function getLanguageByFilename(filename) {
1457
+ if (FILENAME_MAP[filename]) {
1458
+ return FILENAME_MAP[filename];
1459
+ }
1460
+ const lastDot = filename.lastIndexOf(".");
1461
+ if (lastDot === -1) {
1462
+ return "plaintext";
1463
+ }
1464
+ const extension = filename.slice(lastDot).toLowerCase();
1465
+ return LANGUAGE_MAP[extension] || "plaintext";
1466
+ }
1467
+ __name(getLanguageByFilename, "getLanguageByFilename");
1468
+ var EditorContext = createContext(null);
1469
+ function useEditorContext() {
1470
+ const context = useContext(EditorContext);
1471
+ if (!context) {
1472
+ throw new Error("useEditorContext must be used within EditorProvider");
1473
+ }
1474
+ return context;
1475
+ }
1476
+ __name(useEditorContext, "useEditorContext");
1477
+ function EditorProvider({ children, onSave }) {
1478
+ const { monaco } = useMonaco();
1479
+ const [editor, setEditor] = useState(null);
1480
+ const [openFiles, setOpenFiles] = useState([]);
1481
+ const [activeFilePath, setActiveFilePath] = useState(null);
1482
+ const activeFile = useMemo(
1483
+ () => openFiles.find((f) => f.path === activeFilePath) || null,
1484
+ [openFiles, activeFilePath]
1485
+ );
1486
+ const openFile = useCallback(
1487
+ (path, content, language) => {
1488
+ setOpenFiles((files) => {
1489
+ const existing = files.find((f) => f.path === path);
1490
+ if (existing) {
1491
+ return files;
1492
+ }
1493
+ const basename = path.split("/").pop() || path;
1494
+ const detectedLanguage = language || getLanguageByFilename(basename);
1495
+ const newFile = {
1496
+ path,
1497
+ content,
1498
+ language: detectedLanguage,
1499
+ isDirty: false
1500
+ };
1501
+ return [...files, newFile];
1502
+ });
1503
+ setActiveFilePath(path);
1504
+ },
1505
+ []
1506
+ );
1507
+ const closeFile = useCallback(
1508
+ (path) => {
1509
+ setOpenFiles((files) => {
1510
+ const index = files.findIndex((f) => f.path === path);
1511
+ if (index === -1) return files;
1512
+ const newFiles = files.filter((f) => f.path !== path);
1513
+ if (activeFilePath === path && newFiles.length > 0) {
1514
+ const newIndex = Math.min(index, newFiles.length - 1);
1515
+ setActiveFilePath(newFiles[newIndex].path);
1516
+ } else if (newFiles.length === 0) {
1517
+ setActiveFilePath(null);
1518
+ }
1519
+ return newFiles;
1520
+ });
1521
+ },
1522
+ [activeFilePath]
1523
+ );
1524
+ const setActiveFile = useCallback((path) => {
1525
+ setActiveFilePath(path);
1526
+ }, []);
1527
+ const updateContent = useCallback((path, content) => {
1528
+ setOpenFiles(
1529
+ (files) => files.map(
1530
+ (f) => f.path === path ? { ...f, content, isDirty: true } : f
1531
+ )
1532
+ );
1533
+ }, []);
1534
+ const saveFile = useCallback(
1535
+ async (path) => {
1536
+ const file = openFiles.find((f) => f.path === path);
1537
+ if (!file) return;
1538
+ if (onSave) {
1539
+ await onSave(path, file.content);
1540
+ }
1541
+ setOpenFiles(
1542
+ (files) => files.map(
1543
+ (f) => f.path === path ? { ...f, isDirty: false } : f
1544
+ )
1545
+ );
1546
+ },
1547
+ [openFiles, onSave]
1548
+ );
1549
+ const isDirty = useCallback(
1550
+ (path) => {
1551
+ const file = openFiles.find((f) => f.path === path);
1552
+ return file?.isDirty || false;
1553
+ },
1554
+ [openFiles]
1555
+ );
1556
+ const getContent = useCallback(
1557
+ (path) => {
1558
+ const file = openFiles.find((f) => f.path === path);
1559
+ return file?.content || null;
1560
+ },
1561
+ [openFiles]
1562
+ );
1563
+ const getFile = useCallback(
1564
+ (path) => {
1565
+ return openFiles.find((f) => f.path === path) || null;
1566
+ },
1567
+ [openFiles]
1568
+ );
1569
+ const value = {
1570
+ openFiles,
1571
+ activeFile,
1572
+ monaco,
1573
+ editor,
1574
+ isReady: monaco !== null && editor !== null,
1575
+ openFile,
1576
+ closeFile,
1577
+ setActiveFile,
1578
+ updateContent,
1579
+ saveFile,
1580
+ isDirty,
1581
+ getContent,
1582
+ getFile
1583
+ };
1584
+ return /* @__PURE__ */ jsx(EditorContext.Provider, { value, children });
1585
+ }
1586
+ __name(EditorProvider, "EditorProvider");
1587
+ function useEditor() {
1588
+ const [editor, setEditorState] = useState(null);
1589
+ const setEditor = useCallback((editorInstance) => {
1590
+ setEditorState(editorInstance);
1591
+ }, []);
1592
+ return {
1593
+ editor,
1594
+ isReady: editor !== null,
1595
+ setEditor
1596
+ };
1597
+ }
1598
+ __name(useEditor, "useEditor");
1599
+ function useLanguage(filename) {
1600
+ return useMemo(() => {
1601
+ if (!filename) return "plaintext";
1602
+ const basename = filename.split("/").pop() || filename;
1603
+ return getLanguageByFilename(basename);
1604
+ }, [filename]);
1605
+ }
1606
+ __name(useLanguage, "useLanguage");
1607
+
1608
+ export { CardLoadingFallback, CronScheduler, DiffEditor, Editor, EditorProvider, LazyCronScheduler, LazyHybridAudioPlayer, LazyHybridCompactPlayer, LazyHybridSimplePlayer, LazyImageViewer, LazyJsonSchemaForm, LazyJsonTree, LazyLottiePlayer, LazyMapContainer, LazyMapView, LazyMermaid, LazyOpenapiViewer, LazyPrettyCode, LazyVideoPlayer, LazyWrapper, LoadingFallback, LottiePlayer, MapLoadingFallback, MarkdownMessage, Mermaid_default as Mermaid, OpenapiViewer_default as OpenapiViewer, Spinner, createLazyComponent, useCollapsibleContent, useEditor, useEditorContext, useLanguage, useMonaco };
885
1609
  //# sourceMappingURL=index.mjs.map
886
1610
  //# sourceMappingURL=index.mjs.map