@mirror-physics/fractal-ui 0.2.0-next.53 → 0.2.0-next.54

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
@@ -296,7 +296,10 @@ var codeTheme = import_view.EditorView.theme({
296
296
  overscrollBehavior: "none"
297
297
  },
298
298
  ".cm-content": { padding: "10px 0" },
299
- ".cm-line": { padding: "0 12px" },
299
+ ".cm-line": {
300
+ padding: "0 12px 0 calc(12px + var(--fractal-code-wrap-indent, 0ch))",
301
+ textIndent: "calc(0px - var(--fractal-code-wrap-indent, 0ch))"
302
+ },
300
303
  ".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--fg-primary)" },
301
304
  ".cm-gutters": {
302
305
  backgroundColor: "var(--bg-canvas)",
@@ -361,6 +364,48 @@ var jsonSupport = (0, import_lang_json.json)();
361
364
  var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
362
365
  var JSON_LINES_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["jsonl", "ndjson"]);
363
366
  var JSON_LINES_PRETTY_PRINT_THRESHOLD = 160;
367
+ var JSON_PROPERTY_PREFIX = /^(\s*"(?:\\.|[^"\\])*"\s*:\s*)/;
368
+ function countVisualColumns(value) {
369
+ let columns = 0;
370
+ for (const character of value) columns += character === " " ? 2 : 1;
371
+ return columns;
372
+ }
373
+ function getWrappedLineIndent(line) {
374
+ const propertyPrefix = line.match(JSON_PROPERTY_PREFIX)?.[1];
375
+ if (propertyPrefix) return Math.min(countVisualColumns(propertyPrefix), 24);
376
+ const leadingWhitespace = line.match(/^\s*/)?.[0] ?? "";
377
+ return Math.min(countVisualColumns(leadingWhitespace) + 2, 12);
378
+ }
379
+ function buildWrappedLineIndentation(view) {
380
+ const decorations = [];
381
+ const decoratedLines = /* @__PURE__ */ new Set();
382
+ for (const visibleRange of view.visibleRanges) {
383
+ let position = visibleRange.from;
384
+ while (position <= visibleRange.to) {
385
+ const line = view.state.doc.lineAt(position);
386
+ if (!decoratedLines.has(line.from)) {
387
+ const indent = getWrappedLineIndent(line.text);
388
+ decorations.push(import_view.Decoration.line({
389
+ attributes: { style: `--fractal-code-wrap-indent: ${indent}ch` }
390
+ }).range(line.from));
391
+ decoratedLines.add(line.from);
392
+ }
393
+ if (line.to >= visibleRange.to) break;
394
+ position = line.to + 1;
395
+ }
396
+ }
397
+ return import_view.Decoration.set(decorations, true);
398
+ }
399
+ var wrappedLineIndentation = import_view.ViewPlugin.fromClass(class {
400
+ constructor(view) {
401
+ this.decorations = buildWrappedLineIndentation(view);
402
+ }
403
+ update(update) {
404
+ this.decorations = buildWrappedLineIndentation(update.view);
405
+ }
406
+ }, {
407
+ decorations: (plugin) => plugin.decorations
408
+ });
364
409
  function formatJsonLinesForDisplay(value) {
365
410
  return value.split(/\r?\n/).map((line) => {
366
411
  const firstContentIndex = line.search(/\S/);
@@ -476,7 +521,7 @@ function CodeBlock({
476
521
  ...resolvedLanguage.support ? [resolvedLanguage.support] : [],
477
522
  ...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
478
523
  ...lineNumbers ? [(0, import_language.foldGutter)(), (0, import_view.lineNumbers)()] : [],
479
- ...wrap ? [import_view.EditorView.lineWrapping] : []
524
+ ...wrap ? [import_view.EditorView.lineWrapping, wrappedLineIndentation] : []
480
525
  ], [lineNumbers, resolvedLanguage.isJsonLines, resolvedLanguage.support, wrap]);
481
526
  const languageLabel = resolvedLanguage.label;
482
527
  const toolbarLabel = label ?? fileName ?? languageLabel;