@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 +47 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -170,7 +170,12 @@ import { useEffect, useMemo, useRef, useState as useState2 } from "react";
|
|
|
170
170
|
import CodeMirror from "@uiw/react-codemirror";
|
|
171
171
|
import { HighlightStyle, foldGutter, foldService, syntaxHighlighting } from "@codemirror/language";
|
|
172
172
|
import { json } from "@codemirror/lang-json";
|
|
173
|
-
import {
|
|
173
|
+
import {
|
|
174
|
+
Decoration,
|
|
175
|
+
EditorView,
|
|
176
|
+
ViewPlugin,
|
|
177
|
+
lineNumbers as lineNumberGutter
|
|
178
|
+
} from "@codemirror/view";
|
|
174
179
|
import { tags } from "@lezer/highlight";
|
|
175
180
|
import { Check, Copy } from "@mirror-physics/fractal-icons";
|
|
176
181
|
import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
@@ -187,7 +192,10 @@ var codeTheme = EditorView.theme({
|
|
|
187
192
|
overscrollBehavior: "none"
|
|
188
193
|
},
|
|
189
194
|
".cm-content": { padding: "10px 0" },
|
|
190
|
-
".cm-line": {
|
|
195
|
+
".cm-line": {
|
|
196
|
+
padding: "0 12px 0 calc(12px + var(--fractal-code-wrap-indent, 0ch))",
|
|
197
|
+
textIndent: "calc(0px - var(--fractal-code-wrap-indent, 0ch))"
|
|
198
|
+
},
|
|
191
199
|
".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--fg-primary)" },
|
|
192
200
|
".cm-gutters": {
|
|
193
201
|
backgroundColor: "var(--bg-canvas)",
|
|
@@ -252,6 +260,48 @@ var jsonSupport = json();
|
|
|
252
260
|
var JSON_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["json", "jsonl", "ndjson", "geojson"]);
|
|
253
261
|
var JSON_LINES_LANGUAGE_NAMES = /* @__PURE__ */ new Set(["jsonl", "ndjson"]);
|
|
254
262
|
var JSON_LINES_PRETTY_PRINT_THRESHOLD = 160;
|
|
263
|
+
var JSON_PROPERTY_PREFIX = /^(\s*"(?:\\.|[^"\\])*"\s*:\s*)/;
|
|
264
|
+
function countVisualColumns(value) {
|
|
265
|
+
let columns = 0;
|
|
266
|
+
for (const character of value) columns += character === " " ? 2 : 1;
|
|
267
|
+
return columns;
|
|
268
|
+
}
|
|
269
|
+
function getWrappedLineIndent(line) {
|
|
270
|
+
const propertyPrefix = line.match(JSON_PROPERTY_PREFIX)?.[1];
|
|
271
|
+
if (propertyPrefix) return Math.min(countVisualColumns(propertyPrefix), 24);
|
|
272
|
+
const leadingWhitespace = line.match(/^\s*/)?.[0] ?? "";
|
|
273
|
+
return Math.min(countVisualColumns(leadingWhitespace) + 2, 12);
|
|
274
|
+
}
|
|
275
|
+
function buildWrappedLineIndentation(view) {
|
|
276
|
+
const decorations = [];
|
|
277
|
+
const decoratedLines = /* @__PURE__ */ new Set();
|
|
278
|
+
for (const visibleRange of view.visibleRanges) {
|
|
279
|
+
let position = visibleRange.from;
|
|
280
|
+
while (position <= visibleRange.to) {
|
|
281
|
+
const line = view.state.doc.lineAt(position);
|
|
282
|
+
if (!decoratedLines.has(line.from)) {
|
|
283
|
+
const indent = getWrappedLineIndent(line.text);
|
|
284
|
+
decorations.push(Decoration.line({
|
|
285
|
+
attributes: { style: `--fractal-code-wrap-indent: ${indent}ch` }
|
|
286
|
+
}).range(line.from));
|
|
287
|
+
decoratedLines.add(line.from);
|
|
288
|
+
}
|
|
289
|
+
if (line.to >= visibleRange.to) break;
|
|
290
|
+
position = line.to + 1;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return Decoration.set(decorations, true);
|
|
294
|
+
}
|
|
295
|
+
var wrappedLineIndentation = ViewPlugin.fromClass(class {
|
|
296
|
+
constructor(view) {
|
|
297
|
+
this.decorations = buildWrappedLineIndentation(view);
|
|
298
|
+
}
|
|
299
|
+
update(update) {
|
|
300
|
+
this.decorations = buildWrappedLineIndentation(update.view);
|
|
301
|
+
}
|
|
302
|
+
}, {
|
|
303
|
+
decorations: (plugin) => plugin.decorations
|
|
304
|
+
});
|
|
255
305
|
function formatJsonLinesForDisplay(value) {
|
|
256
306
|
return value.split(/\r?\n/).map((line) => {
|
|
257
307
|
const firstContentIndex = line.search(/\S/);
|
|
@@ -367,7 +417,7 @@ function CodeBlock({
|
|
|
367
417
|
...resolvedLanguage.support ? [resolvedLanguage.support] : [],
|
|
368
418
|
...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
|
|
369
419
|
...lineNumbers ? [foldGutter(), lineNumberGutter()] : [],
|
|
370
|
-
...wrap ? [EditorView.lineWrapping] : []
|
|
420
|
+
...wrap ? [EditorView.lineWrapping, wrappedLineIndentation] : []
|
|
371
421
|
], [lineNumbers, resolvedLanguage.isJsonLines, resolvedLanguage.support, wrap]);
|
|
372
422
|
const languageLabel = resolvedLanguage.label;
|
|
373
423
|
const toolbarLabel = label ?? fileName ?? languageLabel;
|