@marianmeres/stuic 3.138.0 → 3.140.0
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.
|
@@ -12,7 +12,7 @@ import { defaultKeymap, history, historyKeymap, redo, undo } from "@codemirror/c
|
|
|
12
12
|
import { markdown } from "@codemirror/lang-markdown";
|
|
13
13
|
import { languages } from "@codemirror/language-data";
|
|
14
14
|
import { EditorState } from "@codemirror/state";
|
|
15
|
-
import { EditorView, keymap, placeholder as cmPlaceholder } from "@codemirror/view";
|
|
15
|
+
import { drawSelection, EditorView, keymap, placeholder as cmPlaceholder, } from "@codemirror/view";
|
|
16
16
|
/** Theme that inherits STUIC look via CSS vars rather than hard-coded values. */
|
|
17
17
|
const stuicTheme = EditorView.theme({
|
|
18
18
|
"&": {
|
|
@@ -23,7 +23,6 @@ const stuicTheme = EditorView.theme({
|
|
|
23
23
|
".cm-content": {
|
|
24
24
|
fontFamily: "var(--stuic-markdown-editor-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",
|
|
25
25
|
padding: "0",
|
|
26
|
-
caretColor: "currentColor",
|
|
27
26
|
},
|
|
28
27
|
"&.cm-focused": { outline: "none" },
|
|
29
28
|
".cm-line": { padding: "0" },
|
|
@@ -33,6 +32,30 @@ const stuicTheme = EditorView.theme({
|
|
|
33
32
|
color: "var(--stuic-input-placeholder, currentColor)",
|
|
34
33
|
opacity: "0.5",
|
|
35
34
|
},
|
|
35
|
+
// Caret + selection are DRAWN by `drawSelection()` (see the extensions below)
|
|
36
|
+
// instead of left to the browser. The native caret is unreliable on an EMPTY
|
|
37
|
+
// document that carries a placeholder widget — Chrome/Safari won't render it
|
|
38
|
+
// (the cursor sits before a `contenteditable=false` widget with no editable
|
|
39
|
+
// text beside it) until you start typing, which reads as a broken focus.
|
|
40
|
+
// Drawing the caret ourselves fixes that. Colors use `currentColor` / a
|
|
41
|
+
// mode-neutral translucent selection on purpose: CM's own light/dark detection
|
|
42
|
+
// is inert here (STUIC themes via `:root.dark`, not CM's dark facet), so its
|
|
43
|
+
// built-in dark caret/selection colors would never kick in.
|
|
44
|
+
//
|
|
45
|
+
// `borderLeftWidth: 2px` is deliberate: CM's default ~1.2px caret lands on a
|
|
46
|
+
// fractional device-pixel boundary at many layout offsets (the cursor also
|
|
47
|
+
// carries a `-0.6px` margin) and anti-aliases into invisibility on a light
|
|
48
|
+
// background — the very "no caret" symptom this fix targets. 2px always paints.
|
|
49
|
+
".cm-cursor, .cm-dropCursor": {
|
|
50
|
+
borderLeftColor: "currentColor",
|
|
51
|
+
borderLeftWidth: "2px",
|
|
52
|
+
},
|
|
53
|
+
"& .cm-selectionBackground": {
|
|
54
|
+
background: "var(--stuic-markdown-editor-selection-bg, rgb(128 128 128 / 0.3))",
|
|
55
|
+
},
|
|
56
|
+
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
57
|
+
background: "var(--stuic-markdown-editor-selection-bg, rgb(128 128 128 / 0.3))",
|
|
58
|
+
},
|
|
36
59
|
});
|
|
37
60
|
/** Wrap the current selection with `before`/`after` markers (e.g. `**bold**`). */
|
|
38
61
|
function wrapSelection(view, before, after = before) {
|
|
@@ -162,6 +185,7 @@ export function mountCodeMirror(host, opts) {
|
|
|
162
185
|
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
163
186
|
markdown({ codeLanguages: languages }),
|
|
164
187
|
EditorView.lineWrapping,
|
|
188
|
+
drawSelection(),
|
|
165
189
|
EditorView.editable.of(!opts.disabled),
|
|
166
190
|
EditorState.readOnly.of(!!opts.disabled),
|
|
167
191
|
...(opts.placeholder ? [cmPlaceholder(opts.placeholder)] : []),
|
|
@@ -82,6 +82,12 @@ Collapsing a branch also collapses all of its descendants.
|
|
|
82
82
|
</Tree>
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
> **Icon sizing tip:** render `renderIcon` SVGs at their native `viewBox` size (or an
|
|
86
|
+
> integer divisor of it) — e.g. `16` for Bootstrap icons (`0 0 16 16`), `24`/`16`/`12`
|
|
87
|
+
> for Lucide (`0 0 24 24`). A fractional downscale (e.g. a 16-unit icon at `size: 14`)
|
|
88
|
+
> renders 1px strokes at sub-pixel width, which looks like the icon is clipped ~1px —
|
|
89
|
+
> most visibly on icons whose shape touches the viewBox edge, such as file glyphs.
|
|
90
|
+
|
|
85
91
|
## Props
|
|
86
92
|
|
|
87
93
|
| Prop | Type | Default | Description |
|
|
@@ -117,6 +117,14 @@
|
|
|
117
117
|
opacity: var(--stuic-tree-icon-opacity);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/* Render icons as block so they sit on the pixel grid instead of the text
|
|
121
|
+
baseline. Inline SVGs (the default vertical-align: baseline) land on a
|
|
122
|
+
fractional pixel and shear ~1px off the bottom of full-viewBox glyphs
|
|
123
|
+
(e.g. file icons whose shape touches the bottom edge). */
|
|
124
|
+
.stuic-tree-item svg {
|
|
125
|
+
display: block;
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
/* =============================================================================
|
|
121
129
|
ITEM STATE STYLES
|
|
122
130
|
============================================================================= */
|