@mirror-physics/fractal-ui 0.2.0-next.51 → 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
@@ -358,16 +358,40 @@ var fractalHighlightStyle = import_language.HighlightStyle.define([
358
358
  ]);
359
359
  var jsonSupport = (0, import_lang_json.json)();
360
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
+ });
361
382
  function resolveLanguage(language, fileName) {
362
383
  const normalized = language?.trim().toLowerCase();
363
384
  const extension = fileName?.split(/[?#]/, 1)[0].split(".").pop()?.toLowerCase();
364
385
  if (normalized && JSON_LANGUAGE_NAMES.has(normalized) || extension && JSON_LANGUAGE_NAMES.has(extension)) {
365
- 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 };
366
390
  }
367
391
  if (normalized && !["text", "txt", "plaintext", "plain"].includes(normalized)) {
368
- return { label: language?.trim(), support: null };
392
+ return { label: language?.trim(), support: null, isJsonLines: false };
369
393
  }
370
- return { support: null };
394
+ return { support: null, isJsonLines: false };
371
395
  }
372
396
  function CodeBlock({
373
397
  value,
@@ -398,9 +422,10 @@ function CodeBlock({
398
422
  codeTheme,
399
423
  (0, import_language.syntaxHighlighting)(fractalHighlightStyle),
400
424
  ...resolvedLanguage.support ? [resolvedLanguage.support] : [],
425
+ ...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
401
426
  ...lineNumbers ? [(0, import_language.foldGutter)(), (0, import_view.lineNumbers)()] : [],
402
427
  ...wrap ? [import_view.EditorView.lineWrapping] : []
403
- ], [lineNumbers, resolvedLanguage.support, wrap]);
428
+ ], [lineNumbers, resolvedLanguage.isJsonLines, resolvedLanguage.support, wrap]);
404
429
  const languageLabel = resolvedLanguage.label;
405
430
  const toolbarLabel = label ?? fileName ?? languageLabel;
406
431
  const surfaceLabel = ariaLabel ?? (fileName ? `${fileName} ${editable ? "editor" : "viewer"}` : `Code ${editable ? "editor" : "viewer"}`);