@mirror-physics/fractal-ui 0.2.0-next.49 → 0.2.0-next.50
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.cjs +24 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -38
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -278,7 +278,7 @@ Button.displayName = "Button";
|
|
|
278
278
|
var import_react = require("react");
|
|
279
279
|
var import_react_codemirror = __toESM(require("@uiw/react-codemirror"), 1);
|
|
280
280
|
var import_language = require("@codemirror/language");
|
|
281
|
-
var
|
|
281
|
+
var import_lang_json = require("@codemirror/lang-json");
|
|
282
282
|
var import_view = require("@codemirror/view");
|
|
283
283
|
var import_highlight = require("@lezer/highlight");
|
|
284
284
|
var import_fractal_icons = require("@mirror-physics/fractal-icons");
|
|
@@ -299,7 +299,7 @@ var codeTheme = import_view.EditorView.theme({
|
|
|
299
299
|
".cm-line": { padding: "0 12px" },
|
|
300
300
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--fg-primary)" },
|
|
301
301
|
".cm-gutters": {
|
|
302
|
-
backgroundColor: "var(--bg-
|
|
302
|
+
backgroundColor: "var(--bg-canvas)",
|
|
303
303
|
borderRight: "1px solid var(--border-subtle)",
|
|
304
304
|
color: "var(--fg-tertiary)"
|
|
305
305
|
},
|
|
@@ -324,43 +324,30 @@ var codeTheme = import_view.EditorView.theme({
|
|
|
324
324
|
var fractalHighlightStyle = import_language.HighlightStyle.define([
|
|
325
325
|
{ tag: import_highlight.tags.comment, color: "var(--fg-tertiary)", fontStyle: "italic" },
|
|
326
326
|
{ tag: [import_highlight.tags.keyword, import_highlight.tags.controlKeyword, import_highlight.tags.operatorKeyword], color: "var(--purple-default)" },
|
|
327
|
-
{ tag: [import_highlight.tags.string, import_highlight.tags.special(import_highlight.tags.string)], color: "var(--
|
|
327
|
+
{ tag: [import_highlight.tags.string, import_highlight.tags.special(import_highlight.tags.string)], color: "var(--purple-default)" },
|
|
328
328
|
{ tag: [import_highlight.tags.number, import_highlight.tags.bool, import_highlight.tags.null], color: "var(--orange-default)" },
|
|
329
329
|
{ tag: [import_highlight.tags.function(import_highlight.tags.variableName), import_highlight.tags.labelName], color: "var(--accent-default)" },
|
|
330
330
|
{ tag: [import_highlight.tags.typeName, import_highlight.tags.className, import_highlight.tags.namespace], color: "var(--pink-default)" },
|
|
331
|
-
{ tag: [import_highlight.tags.propertyName, import_highlight.tags.attributeName], color: "var(--
|
|
332
|
-
{ tag: [import_highlight.tags.operator, import_highlight.tags.punctuation
|
|
331
|
+
{ tag: [import_highlight.tags.propertyName, import_highlight.tags.attributeName], color: "var(--success-default)" },
|
|
332
|
+
{ tag: [import_highlight.tags.operator, import_highlight.tags.punctuation], color: "var(--fg-secondary)" },
|
|
333
|
+
{ tag: import_highlight.tags.bracket, color: "var(--accent-default)" },
|
|
333
334
|
{ tag: [import_highlight.tags.heading, import_highlight.tags.strong], color: "var(--fg-primary)", fontWeight: "600" },
|
|
334
335
|
{ tag: import_highlight.tags.emphasis, fontStyle: "italic" },
|
|
335
336
|
{ tag: import_highlight.tags.link, color: "var(--accent-default)", textDecoration: "underline" },
|
|
336
337
|
{ tag: import_highlight.tags.invalid, color: "var(--error-default)", textDecoration: "underline wavy" }
|
|
337
338
|
]);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
var jsonSupport = (0, import_lang_json.json)();
|
|
340
|
+
var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
|
|
341
|
+
function resolveLanguage(language, fileName) {
|
|
342
|
+
const normalized = language?.trim().toLowerCase();
|
|
343
|
+
const extension = fileName?.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase();
|
|
344
|
+
if (normalized && JSON_LANGUAGE_NAMES.has(normalized) || extension && JSON_LANGUAGE_NAMES.has(extension)) {
|
|
345
|
+
return { label: normalized === "jsonl" || extension === "jsonl" ? "JSONL" : "JSON", support: jsonSupport };
|
|
342
346
|
}
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const [support, setSupport] = (0, import_react.useState)(null);
|
|
348
|
-
(0, import_react.useEffect)(() => {
|
|
349
|
-
let cancelled = false;
|
|
350
|
-
setSupport(null);
|
|
351
|
-
if (!description) return () => {
|
|
352
|
-
cancelled = true;
|
|
353
|
-
};
|
|
354
|
-
void description.load().then((loaded) => {
|
|
355
|
-
if (!cancelled) setSupport(loaded);
|
|
356
|
-
}).catch(() => {
|
|
357
|
-
if (!cancelled) setSupport(null);
|
|
358
|
-
});
|
|
359
|
-
return () => {
|
|
360
|
-
cancelled = true;
|
|
361
|
-
};
|
|
362
|
-
}, [description]);
|
|
363
|
-
return { description, support };
|
|
347
|
+
if (normalized && !["text", "txt", "plaintext", "plain"].includes(normalized)) {
|
|
348
|
+
return { label: language?.trim(), support: null };
|
|
349
|
+
}
|
|
350
|
+
return { support: null };
|
|
364
351
|
}
|
|
365
352
|
function CodeBlock({
|
|
366
353
|
value,
|
|
@@ -381,7 +368,7 @@ function CodeBlock({
|
|
|
381
368
|
className,
|
|
382
369
|
...props
|
|
383
370
|
}) {
|
|
384
|
-
const
|
|
371
|
+
const resolvedLanguage = (0, import_react.useMemo)(() => resolveLanguage(language, fileName), [fileName, language]);
|
|
385
372
|
const [copyStatus, setCopyStatus] = (0, import_react.useState)("idle");
|
|
386
373
|
const copyResetTimer = (0, import_react.useRef)(null);
|
|
387
374
|
(0, import_react.useEffect)(() => () => {
|
|
@@ -390,10 +377,11 @@ function CodeBlock({
|
|
|
390
377
|
const extensions = (0, import_react.useMemo)(() => [
|
|
391
378
|
codeTheme,
|
|
392
379
|
(0, import_language.syntaxHighlighting)(fractalHighlightStyle),
|
|
393
|
-
...support ? [support] : [],
|
|
380
|
+
...resolvedLanguage.support ? [resolvedLanguage.support] : [],
|
|
381
|
+
...lineNumbers ? [(0, import_language.foldGutter)(), (0, import_view.lineNumbers)()] : [],
|
|
394
382
|
...wrap ? [import_view.EditorView.lineWrapping] : []
|
|
395
|
-
], [support, wrap]);
|
|
396
|
-
const languageLabel =
|
|
383
|
+
], [lineNumbers, resolvedLanguage.support, wrap]);
|
|
384
|
+
const languageLabel = resolvedLanguage.label;
|
|
397
385
|
const toolbarLabel = label ?? fileName ?? languageLabel;
|
|
398
386
|
const surfaceLabel = ariaLabel ?? (fileName ? `${fileName} ${editable ? "editor" : "viewer"}` : `Code ${editable ? "editor" : "viewer"}`);
|
|
399
387
|
const copyCode = async () => {
|
|
@@ -449,8 +437,8 @@ function CodeBlock({
|
|
|
449
437
|
extensions,
|
|
450
438
|
theme: "none",
|
|
451
439
|
basicSetup: {
|
|
452
|
-
lineNumbers,
|
|
453
|
-
foldGutter:
|
|
440
|
+
lineNumbers: false,
|
|
441
|
+
foldGutter: false,
|
|
454
442
|
drawSelection: editable,
|
|
455
443
|
highlightActiveLine: editable,
|
|
456
444
|
highlightActiveLineGutter: editable,
|