@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.js CHANGED
@@ -168,9 +168,9 @@ Button.displayName = "Button";
168
168
  // src/components/CodeBlock/CodeBlock.tsx
169
169
  import { useEffect, useMemo, useRef, useState as useState2 } from "react";
170
170
  import CodeMirror from "@uiw/react-codemirror";
171
- import { HighlightStyle, LanguageDescription, syntaxHighlighting } from "@codemirror/language";
172
- import { languages } from "@codemirror/language-data";
173
- import { EditorView } from "@codemirror/view";
171
+ import { HighlightStyle, foldGutter, syntaxHighlighting } from "@codemirror/language";
172
+ import { json } from "@codemirror/lang-json";
173
+ import { EditorView, lineNumbers as lineNumberGutter } from "@codemirror/view";
174
174
  import { tags } from "@lezer/highlight";
175
175
  import { Check, Copy } from "@mirror-physics/fractal-icons";
176
176
  import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -190,7 +190,7 @@ var codeTheme = EditorView.theme({
190
190
  ".cm-line": { padding: "0 12px" },
191
191
  ".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--fg-primary)" },
192
192
  ".cm-gutters": {
193
- backgroundColor: "var(--bg-surface-1)",
193
+ backgroundColor: "var(--bg-canvas)",
194
194
  borderRight: "1px solid var(--border-subtle)",
195
195
  color: "var(--fg-tertiary)"
196
196
  },
@@ -215,43 +215,30 @@ var codeTheme = EditorView.theme({
215
215
  var fractalHighlightStyle = HighlightStyle.define([
216
216
  { tag: tags.comment, color: "var(--fg-tertiary)", fontStyle: "italic" },
217
217
  { tag: [tags.keyword, tags.controlKeyword, tags.operatorKeyword], color: "var(--purple-default)" },
218
- { tag: [tags.string, tags.special(tags.string)], color: "var(--success-default)" },
218
+ { tag: [tags.string, tags.special(tags.string)], color: "var(--purple-default)" },
219
219
  { tag: [tags.number, tags.bool, tags.null], color: "var(--orange-default)" },
220
220
  { tag: [tags.function(tags.variableName), tags.labelName], color: "var(--accent-default)" },
221
221
  { tag: [tags.typeName, tags.className, tags.namespace], color: "var(--pink-default)" },
222
- { tag: [tags.propertyName, tags.attributeName], color: "var(--fg-primary)" },
223
- { tag: [tags.operator, tags.punctuation, tags.bracket], color: "var(--fg-secondary)" },
222
+ { tag: [tags.propertyName, tags.attributeName], color: "var(--success-default)" },
223
+ { tag: [tags.operator, tags.punctuation], color: "var(--fg-secondary)" },
224
+ { tag: tags.bracket, color: "var(--accent-default)" },
224
225
  { tag: [tags.heading, tags.strong], color: "var(--fg-primary)", fontWeight: "600" },
225
226
  { tag: tags.emphasis, fontStyle: "italic" },
226
227
  { tag: tags.link, color: "var(--accent-default)", textDecoration: "underline" },
227
228
  { tag: tags.invalid, color: "var(--error-default)", textDecoration: "underline wavy" }
228
229
  ]);
229
- function findLanguage(language, fileName) {
230
- const normalized = language?.trim();
231
- if (normalized && !["text", "txt", "plaintext", "plain"].includes(normalized.toLowerCase())) {
232
- return LanguageDescription.matchLanguageName(languages, normalized, true);
230
+ var jsonSupport = json();
231
+ var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
232
+ function resolveLanguage(language, fileName) {
233
+ const normalized = language?.trim().toLowerCase();
234
+ const extension = fileName?.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase();
235
+ if (normalized && JSON_LANGUAGE_NAMES.has(normalized) || extension && JSON_LANGUAGE_NAMES.has(extension)) {
236
+ return { label: normalized === "jsonl" || extension === "jsonl" ? "JSONL" : "JSON", support: jsonSupport };
233
237
  }
234
- return fileName ? LanguageDescription.matchFilename(languages, fileName) : null;
235
- }
236
- function useLanguageSupport(language, fileName) {
237
- const description = useMemo(() => findLanguage(language, fileName), [fileName, language]);
238
- const [support, setSupport] = useState2(null);
239
- useEffect(() => {
240
- let cancelled = false;
241
- setSupport(null);
242
- if (!description) return () => {
243
- cancelled = true;
244
- };
245
- void description.load().then((loaded) => {
246
- if (!cancelled) setSupport(loaded);
247
- }).catch(() => {
248
- if (!cancelled) setSupport(null);
249
- });
250
- return () => {
251
- cancelled = true;
252
- };
253
- }, [description]);
254
- return { description, support };
238
+ if (normalized && !["text", "txt", "plaintext", "plain"].includes(normalized)) {
239
+ return { label: language?.trim(), support: null };
240
+ }
241
+ return { support: null };
255
242
  }
256
243
  function CodeBlock({
257
244
  value,
@@ -272,7 +259,7 @@ function CodeBlock({
272
259
  className,
273
260
  ...props
274
261
  }) {
275
- const { description, support } = useLanguageSupport(language, fileName);
262
+ const resolvedLanguage = useMemo(() => resolveLanguage(language, fileName), [fileName, language]);
276
263
  const [copyStatus, setCopyStatus] = useState2("idle");
277
264
  const copyResetTimer = useRef(null);
278
265
  useEffect(() => () => {
@@ -281,10 +268,11 @@ function CodeBlock({
281
268
  const extensions = useMemo(() => [
282
269
  codeTheme,
283
270
  syntaxHighlighting(fractalHighlightStyle),
284
- ...support ? [support] : [],
271
+ ...resolvedLanguage.support ? [resolvedLanguage.support] : [],
272
+ ...lineNumbers ? [foldGutter(), lineNumberGutter()] : [],
285
273
  ...wrap ? [EditorView.lineWrapping] : []
286
- ], [support, wrap]);
287
- const languageLabel = language?.trim() || description?.name;
274
+ ], [lineNumbers, resolvedLanguage.support, wrap]);
275
+ const languageLabel = resolvedLanguage.label;
288
276
  const toolbarLabel = label ?? fileName ?? languageLabel;
289
277
  const surfaceLabel = ariaLabel ?? (fileName ? `${fileName} ${editable ? "editor" : "viewer"}` : `Code ${editable ? "editor" : "viewer"}`);
290
278
  const copyCode = async () => {
@@ -340,8 +328,8 @@ function CodeBlock({
340
328
  extensions,
341
329
  theme: "none",
342
330
  basicSetup: {
343
- lineNumbers,
344
- foldGutter: lineNumbers,
331
+ lineNumbers: false,
332
+ foldGutter: false,
345
333
  drawSelection: editable,
346
334
  highlightActiveLine: editable,
347
335
  highlightActiveLineGutter: editable,