@mirror-physics/fractal-ui 0.2.0-next.50 → 0.2.0-next.52

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 CHANGED
@@ -293,7 +293,7 @@ var codeTheme = import_view.EditorView.theme({
293
293
  ".cm-scroller": {
294
294
  fontFamily: "var(--font-mono)",
295
295
  lineHeight: "1.55",
296
- overscrollBehavior: "contain"
296
+ overscrollBehavior: "none"
297
297
  },
298
298
  ".cm-content": { padding: "10px 0" },
299
299
  ".cm-line": { padding: "0 12px" },
@@ -303,8 +303,28 @@ var codeTheme = import_view.EditorView.theme({
303
303
  borderRight: "1px solid var(--border-subtle)",
304
304
  color: "var(--fg-tertiary)"
305
305
  },
306
- ".cm-lineNumbers .cm-gutterElement": { padding: "0 10px 0 12px" },
307
- ".cm-foldGutter .cm-gutterElement": { padding: "0 8px 0 2px" },
306
+ ".cm-lineNumbers .cm-gutterElement": { padding: "0 10px 0 4px" },
307
+ ".cm-foldGutter": { width: "14px" },
308
+ ".cm-foldGutter .cm-gutterElement": {
309
+ display: "flex",
310
+ width: "14px",
311
+ alignItems: "center",
312
+ justifyContent: "flex-end",
313
+ padding: "0 1px 0 0"
314
+ },
315
+ ".cm-foldGutter .cm-gutterElement > span": {
316
+ display: "inline-flex",
317
+ width: "12px",
318
+ height: "100%",
319
+ alignItems: "center",
320
+ justifyContent: "center",
321
+ padding: "0",
322
+ color: "var(--fg-tertiary)",
323
+ lineHeight: "1",
324
+ transform: "translateY(-1px)",
325
+ transition: "color 120ms ease"
326
+ },
327
+ ".cm-foldGutter .cm-gutterElement > span:hover": { color: "var(--fg-secondary)" },
308
328
  ".cm-activeLine, .cm-activeLineGutter": { backgroundColor: "var(--bg-surface-1)" },
309
329
  ".cm-selectionBackground, &.cm-focused .cm-selectionBackground, ::selection": {
310
330
  backgroundColor: "var(--accent-surface-stroke) !important"
@@ -338,16 +358,40 @@ var fractalHighlightStyle = import_language.HighlightStyle.define([
338
358
  ]);
339
359
  var jsonSupport = (0, import_lang_json.json)();
340
360
  var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
361
+ var JSON_LINES_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["jsonl", "ndjson"]);
362
+ var jsonLinesFoldSupport = import_language.foldService.of((state, lineStart, lineEnd) => {
363
+ const line = state.doc.sliceString(lineStart, lineEnd);
364
+ const firstContentIndex = line.search(/\S/);
365
+ if (firstContentIndex < 0) return null;
366
+ const lastContentIndex = line.search(/\s*$/) - 1;
367
+ const openingCharacter = line[firstContentIndex];
368
+ const closingCharacter = line[lastContentIndex];
369
+ const isContainer = openingCharacter === "{" && closingCharacter === "}" || openingCharacter === "[" && closingCharacter === "]";
370
+ if (!isContainer || lastContentIndex - firstContentIndex < 2) return null;
371
+ try {
372
+ const parsed = JSON.parse(line.slice(firstContentIndex, lastContentIndex + 1));
373
+ if (parsed === null || typeof parsed !== "object") return null;
374
+ } catch {
375
+ return null;
376
+ }
377
+ return {
378
+ from: lineStart + firstContentIndex + 1,
379
+ to: lineStart + lastContentIndex
380
+ };
381
+ });
341
382
  function resolveLanguage(language, fileName) {
342
383
  const normalized = language?.trim().toLowerCase();
343
384
  const extension = fileName?.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase();
344
385
  if (normalized && JSON_LANGUAGE_NAMES.has(normalized) || extension && JSON_LANGUAGE_NAMES.has(extension)) {
345
- return { label: normalized === "jsonl" || extension === "jsonl" ? "JSONL" : "JSON", support: jsonSupport };
386
+ const isJsonLines = Boolean(
387
+ normalized && JSON_LINES_LANGUAGE_NAMES.has(normalized) || extension && JSON_LINES_LANGUAGE_NAMES.has(extension)
388
+ );
389
+ return { label: isJsonLines ? "JSONL" : "JSON", support: jsonSupport, isJsonLines };
346
390
  }
347
391
  if (normalized && !["text", "txt", "plaintext", "plain"].includes(normalized)) {
348
- return { label: language?.trim(), support: null };
392
+ return { label: language?.trim(), support: null, isJsonLines: false };
349
393
  }
350
- return { support: null };
394
+ return { support: null, isJsonLines: false };
351
395
  }
352
396
  function CodeBlock({
353
397
  value,
@@ -378,9 +422,10 @@ function CodeBlock({
378
422
  codeTheme,
379
423
  (0, import_language.syntaxHighlighting)(fractalHighlightStyle),
380
424
  ...resolvedLanguage.support ? [resolvedLanguage.support] : [],
425
+ ...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
381
426
  ...lineNumbers ? [(0, import_language.foldGutter)(), (0, import_view.lineNumbers)()] : [],
382
427
  ...wrap ? [import_view.EditorView.lineWrapping] : []
383
- ], [lineNumbers, resolvedLanguage.support, wrap]);
428
+ ], [lineNumbers, resolvedLanguage.isJsonLines, resolvedLanguage.support, wrap]);
384
429
  const languageLabel = resolvedLanguage.label;
385
430
  const toolbarLabel = label ?? fileName ?? languageLabel;
386
431
  const surfaceLabel = ariaLabel ?? (fileName ? `${fileName} ${editable ? "editor" : "viewer"}` : `Code ${editable ? "editor" : "viewer"}`);