@mirror-physics/fractal-ui 0.2.0-next.54 → 0.2.0-next.56
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 +18 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -173,6 +173,7 @@ import { json } from "@codemirror/lang-json";
|
|
|
173
173
|
import {
|
|
174
174
|
Decoration,
|
|
175
175
|
EditorView,
|
|
176
|
+
MatchDecorator,
|
|
176
177
|
ViewPlugin,
|
|
177
178
|
lineNumbers as lineNumberGutter
|
|
178
179
|
} from "@codemirror/view";
|
|
@@ -222,9 +223,11 @@ var codeTheme = EditorView.theme({
|
|
|
222
223
|
padding: "0",
|
|
223
224
|
color: "var(--fg-tertiary)",
|
|
224
225
|
lineHeight: "14px",
|
|
226
|
+
transform: "translateY(-3px)",
|
|
225
227
|
transition: "color 120ms ease"
|
|
226
228
|
},
|
|
227
229
|
".cm-foldGutter .cm-gutterElement > span:hover": { color: "var(--fg-secondary)" },
|
|
230
|
+
".fractal-code-block__escape": { color: "var(--fg-secondary)" },
|
|
228
231
|
".cm-activeLine, .cm-activeLineGutter": { backgroundColor: "var(--bg-surface-1)" },
|
|
229
232
|
".cm-selectionBackground, &.cm-focused .cm-selectionBackground, ::selection": {
|
|
230
233
|
backgroundColor: "var(--accent-surface-stroke) !important"
|
|
@@ -267,9 +270,8 @@ function countVisualColumns(value) {
|
|
|
267
270
|
return columns;
|
|
268
271
|
}
|
|
269
272
|
function getWrappedLineIndent(line) {
|
|
270
|
-
const propertyPrefix = line.match(JSON_PROPERTY_PREFIX)?.[1];
|
|
271
|
-
if (propertyPrefix) return Math.min(countVisualColumns(propertyPrefix), 24);
|
|
272
273
|
const leadingWhitespace = line.match(/^\s*/)?.[0] ?? "";
|
|
274
|
+
if (JSON_PROPERTY_PREFIX.test(line)) return Math.min(countVisualColumns(leadingWhitespace), 24);
|
|
273
275
|
return Math.min(countVisualColumns(leadingWhitespace) + 2, 12);
|
|
274
276
|
}
|
|
275
277
|
function buildWrappedLineIndentation(view) {
|
|
@@ -302,6 +304,20 @@ var wrappedLineIndentation = ViewPlugin.fromClass(class {
|
|
|
302
304
|
}, {
|
|
303
305
|
decorations: (plugin) => plugin.decorations
|
|
304
306
|
});
|
|
307
|
+
var jsonEscapeMatcher = new MatchDecorator({
|
|
308
|
+
regexp: /\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})/g,
|
|
309
|
+
decoration: Decoration.mark({ class: "fractal-code-block__escape" })
|
|
310
|
+
});
|
|
311
|
+
var jsonEscapeHighlighting = ViewPlugin.fromClass(class {
|
|
312
|
+
constructor(view) {
|
|
313
|
+
this.decorations = jsonEscapeMatcher.createDeco(view);
|
|
314
|
+
}
|
|
315
|
+
update(update) {
|
|
316
|
+
this.decorations = jsonEscapeMatcher.updateDeco(update, this.decorations);
|
|
317
|
+
}
|
|
318
|
+
}, {
|
|
319
|
+
decorations: (plugin) => plugin.decorations
|
|
320
|
+
});
|
|
305
321
|
function formatJsonLinesForDisplay(value) {
|
|
306
322
|
return value.split(/\r?\n/).map((line) => {
|
|
307
323
|
const firstContentIndex = line.search(/\S/);
|
|
@@ -415,6 +431,7 @@ function CodeBlock({
|
|
|
415
431
|
codeTheme,
|
|
416
432
|
syntaxHighlighting(fractalHighlightStyle),
|
|
417
433
|
...resolvedLanguage.support ? [resolvedLanguage.support] : [],
|
|
434
|
+
...resolvedLanguage.support ? [jsonEscapeHighlighting] : [],
|
|
418
435
|
...resolvedLanguage.isJsonLines ? [jsonLinesFoldSupport] : [],
|
|
419
436
|
...lineNumbers ? [foldGutter(), lineNumberGutter()] : [],
|
|
420
437
|
...wrap ? [EditorView.lineWrapping, wrappedLineIndentation] : []
|