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

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)",
@@ -323,6 +326,7 @@ var codeTheme = import_view.EditorView.theme({
323
326
  padding: "0",
324
327
  color: "var(--fg-tertiary)",
325
328
  lineHeight: "14px",
329
+ transform: "translateY(-3px)",
326
330
  transition: "color 120ms ease"
327
331
  },
328
332
  ".cm-foldGutter .cm-gutterElement > span:hover": { color: "var(--fg-secondary)" },
@@ -361,6 +365,48 @@ var jsonSupport = (0, import_lang_json.json)();
361
365
  var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
362
366
  var JSON_LINES_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["jsonl", "ndjson"]);
363
367
  var JSON_LINES_PRETTY_PRINT_THRESHOLD = 160;
368
+ var JSON_PROPERTY_PREFIX = /^(\s*"(?:\\.|[^"\\])*"\s*:\s*)/;
369
+ function countVisualColumns(value) {
370
+ let columns = 0;
371
+ for (const character of value) columns += character === " " ? 2 : 1;
372
+ return columns;
373
+ }
374
+ function getWrappedLineIndent(line) {
375
+ const propertyPrefix = line.match(JSON_PROPERTY_PREFIX)?.[1];
376
+ if (propertyPrefix) return Math.min(countVisualColumns(propertyPrefix), 24);
377
+ const leadingWhitespace = line.match(/^\s*/)?.[0] ?? "";
378
+ return Math.min(countVisualColumns(leadingWhitespace) + 2, 12);
379
+ }
380
+ function buildWrappedLineIndentation(view) {
381
+ const decorations = [];
382
+ const decoratedLines = /* @__PURE__ */ new Set();
383
+ for (const visibleRange of view.visibleRanges) {
384
+ let position = visibleRange.from;
385
+ while (position <= visibleRange.to) {
386
+ const line = view.state.doc.lineAt(position);
387
+ if (!decoratedLines.has(line.from)) {
388
+ const indent = getWrappedLineIndent(line.text);
389
+ decorations.push(import_view.Decoration.line({
390
+ attributes: { style: `--fractal-code-wrap-indent: ${indent}ch` }
391
+ }).range(line.from));
392
+ decoratedLines.add(line.from);
393
+ }
394
+ if (line.to >= visibleRange.to) break;
395
+ position = line.to + 1;
396
+ }
397
+ }
398
+ return import_view.Decoration.set(decorations, true);
399
+ }
400
+ var wrappedLineIndentation = import_view.ViewPlugin.fromClass(class {
401
+ constructor(view) {
402
+ this.decorations = buildWrappedLineIndentation(view);
403
+ }
404
+ update(update) {
405
+ this.decorations = buildWrappedLineIndentation(update.view);
406
+ }
407
+ }, {
408
+ decorations: (plugin) => plugin.decorations
409
+ });
364
410
  function formatJsonLinesForDisplay(value) {
365
411
  return value.split(/\r?\n/).map((line) => {
366
412
  const firstContentIndex = line.search(/\S/);
@@ -476,7 +522,7 @@ function CodeBlock({
476
522
  ...resolvedLanguage.support ? [resolvedLanguage.support] : [],
477
523
  ...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
478
524
  ...lineNumbers ? [(0, import_language.foldGutter)(), (0, import_view.lineNumbers)()] : [],
479
- ...wrap ? [import_view.EditorView.lineWrapping] : []
525
+ ...wrap ? [import_view.EditorView.lineWrapping, wrappedLineIndentation] : []
480
526
  ], [lineNumbers, resolvedLanguage.isJsonLines, resolvedLanguage.support, wrap]);
481
527
  const languageLabel = resolvedLanguage.label;
482
528
  const toolbarLabel = label ?? fileName ?? languageLabel;