devnonla-ui 0.19.0 → 0.19.2
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/package.json +1 -1
- package/src/lib/markdownScale.ts +16 -7
- package/src/markdown-editor/MarkdownEditor.tsx +9 -1
- package/src/markdown-editor/MarkdownPreview.tsx +83 -16
- package/src/markdown-editor/MarkdownViewer.tsx +16 -8
- package/src/styles.css +9 -9
- package/src/typography/Typography.tsx +3 -5
package/package.json
CHANGED
package/src/lib/markdownScale.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { CSSProperties } from "react";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* One markdown scale. Body reads
|
|
4
|
+
* One markdown scale. Body reads `--nonla-base-text-size` (`text-base`). Leading is 1.6.
|
|
5
5
|
* Tables always use `text-base`.
|
|
6
|
-
*
|
|
6
|
+
* Fenced code reads `--nonla-mono-text-size`, which is `text-sm`.
|
|
7
|
+
* Inline code is `0.875em` of the surrounding text, so the chip stays inside the line.
|
|
7
8
|
* Class fallbacks match these values when the variables are not set.
|
|
8
9
|
*/
|
|
9
10
|
export const markdownScaleStyle = {
|
|
10
|
-
"--md-body-size": "var(--nonla-
|
|
11
|
-
"--md-body-leading": "calc(var(--nonla-
|
|
11
|
+
"--md-body-size": "var(--nonla-base-text-size)",
|
|
12
|
+
"--md-body-leading": "calc(var(--nonla-base-text-size) * 1.6)",
|
|
12
13
|
"--md-h1-size": "32px",
|
|
13
14
|
"--md-h1-leading": "1.25",
|
|
14
15
|
"--md-h1-weight": "800",
|
|
@@ -56,7 +57,7 @@ export const markdownScaleStyle = {
|
|
|
56
57
|
"--md-code-my": "8px",
|
|
57
58
|
"--md-code-size": "var(--nonla-mono-text-size)",
|
|
58
59
|
"--md-code-leading": "calc(var(--nonla-mono-text-size) * 1.6)",
|
|
59
|
-
"--md-inline-size": "
|
|
60
|
+
"--md-inline-size": "0.875em",
|
|
60
61
|
"--md-item-pl": "4px",
|
|
61
62
|
"--md-nest": "1.25rem",
|
|
62
63
|
} as CSSProperties;
|
|
@@ -77,7 +78,15 @@ export function headingClass(level: number): string {
|
|
|
77
78
|
export const pageTitleClass = "text-foreground mt-(--md-h1-mt,0px) mb-(--md-h1-mb,1px) pt-(--md-h1-py,3px) pb-(--md-h1-py,3px) text-(length:--md-h1-size,32px) leading-(--md-h1-leading,1.25) font-(--md-h1-weight,800) tracking-tight";
|
|
78
79
|
|
|
79
80
|
/** Body line. Same size and color as a markdown paragraph. */
|
|
80
|
-
export const markdownBodyClass = "text-(length:--md-body-size,var(--nonla-
|
|
81
|
+
export const markdownBodyClass = "text-(length:--md-body-size,var(--nonla-base-text-size,15px)) leading-(--md-body-leading,calc(var(--nonla-base-text-size,15px)*1.6)) text-foreground";
|
|
81
82
|
|
|
82
83
|
/** Paragraph box. Same rhythm as `MarkdownViewer` `p`. */
|
|
83
|
-
export const markdownParagraphClass = "nonla-typo m-0 my-(--md-p-my,1px) py-(--md-p-py,4px) text-(length:--md-body-size,var(--nonla-
|
|
84
|
+
export const markdownParagraphClass = "nonla-typo m-0 my-(--md-p-my,1px) py-(--md-p-py,4px) text-(length:--md-body-size,var(--nonla-base-text-size,15px)) leading-(--md-p-leading,1.6) text-foreground";
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Inline code. Smaller than the line, normal weight, with a light wash.
|
|
88
|
+
* The wash is ink on whatever sits behind, so it stays visible on the page and on a card.
|
|
89
|
+
* A token stays whole; the line breaks before it.
|
|
90
|
+
*/
|
|
91
|
+
export const markdownInlineCodeClass =
|
|
92
|
+
"nonla-inline-code rounded-[4px] bg-[color-mix(in_oklab,var(--nonla-text-main)_6%,transparent)] px-[0.25em] py-px align-baseline font-mono text-(length:--md-inline-size,0.875em) leading-none whitespace-nowrap";
|
|
@@ -27,6 +27,12 @@ export type MarkdownEditorProps = {
|
|
|
27
27
|
defaultDiffLayout?: MarkdownDiffLayout;
|
|
28
28
|
onDiffLayoutChange?: (layout: MarkdownDiffLayout) => void;
|
|
29
29
|
readOnly?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Show Preview / Edit / Diff in the header. Default `true`.
|
|
32
|
+
* Set `false` for inline-only editing (stay on `mode` / `defaultMode`, usually `preview`).
|
|
33
|
+
* Hidden automatically when `readOnly`.
|
|
34
|
+
*/
|
|
35
|
+
showModes?: boolean;
|
|
30
36
|
placeholder?: string;
|
|
31
37
|
title?: ReactNode;
|
|
32
38
|
originalLabel?: ReactNode;
|
|
@@ -73,6 +79,7 @@ function useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (v
|
|
|
73
79
|
* Preview renders the document. Click a heading, list item, or paragraph to edit that text in place.
|
|
74
80
|
* Mermaid fences and registered fence components render in place and stay view only.
|
|
75
81
|
* Edit is the full-file text buffer. Diff compares `original` and `value` like Monaco.
|
|
82
|
+
* `showModes={false}` hides the mode switcher for inline-only editing.
|
|
76
83
|
* `readOnly` locks editing and hides the mode switcher.
|
|
77
84
|
* A finished document with no editor chrome uses `MarkdownViewer`.
|
|
78
85
|
*/
|
|
@@ -88,6 +95,7 @@ export function MarkdownEditor({
|
|
|
88
95
|
defaultDiffLayout = "side-by-side",
|
|
89
96
|
onDiffLayoutChange,
|
|
90
97
|
readOnly = false,
|
|
98
|
+
showModes: showModesProp = true,
|
|
91
99
|
placeholder = "Write markdown…",
|
|
92
100
|
title,
|
|
93
101
|
originalLabel = "Original",
|
|
@@ -243,7 +251,7 @@ export function MarkdownEditor({
|
|
|
243
251
|
|
|
244
252
|
const doc = live?.doc ?? parseMarkdownDoc(valueRef.current);
|
|
245
253
|
const model = useMemo(() => (mode === "diff" && original !== undefined ? diffMarkdown(original, value) : null), [mode, original, value]);
|
|
246
|
-
const showModes = !readOnly;
|
|
254
|
+
const showModes = !readOnly && showModesProp;
|
|
247
255
|
const showHeader = Boolean(title) || showModes || model !== null;
|
|
248
256
|
|
|
249
257
|
return (
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { type MouseEvent, useLayoutEffect, useRef } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
|
+
import { markdownParagraphClass } from "../lib/markdownScale";
|
|
3
4
|
import { OverlayScroll } from "../scroll/OverlayScroll";
|
|
4
5
|
import { type MarkdownDoc, readInlineEdit, writeInlineEdit } from "./blocks";
|
|
5
|
-
import { BlockBody, headingClass, isCustomFence, ListItem, type MarkdownComponents, markdownScaleStyle, spaceBefore } from "./MarkdownViewer";
|
|
6
|
+
import { BlockBody, headingClass, isCustomFence, ListItem, type MarkdownComponents, markdownScaleStyle, RichText, spaceBefore } from "./MarkdownViewer";
|
|
6
7
|
|
|
7
|
-
function BlockEditor({
|
|
8
|
+
function BlockEditor({
|
|
9
|
+
value,
|
|
10
|
+
mono,
|
|
11
|
+
className,
|
|
12
|
+
caret = "end",
|
|
13
|
+
autoSize = true,
|
|
14
|
+
onChange,
|
|
15
|
+
onBlur,
|
|
16
|
+
onEnter,
|
|
17
|
+
}: {
|
|
18
|
+
value: string;
|
|
19
|
+
mono?: boolean;
|
|
20
|
+
className?: string;
|
|
21
|
+
caret?: "start" | "end";
|
|
22
|
+
/** When false, height comes from the layout sizer behind the field (list overlay). */
|
|
23
|
+
autoSize?: boolean;
|
|
24
|
+
onChange: (value: string) => void;
|
|
25
|
+
onBlur: () => void;
|
|
26
|
+
onEnter?: (before: string, after: string) => void;
|
|
27
|
+
}) {
|
|
8
28
|
const ref = useRef<HTMLTextAreaElement>(null);
|
|
9
29
|
|
|
10
30
|
useLayoutEffect(() => {
|
|
@@ -16,11 +36,12 @@ function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur,
|
|
|
16
36
|
}, []);
|
|
17
37
|
|
|
18
38
|
useLayoutEffect(() => {
|
|
39
|
+
if (!autoSize) return;
|
|
19
40
|
const el = ref.current;
|
|
20
41
|
if (!el) return;
|
|
21
42
|
el.style.height = "auto";
|
|
22
43
|
el.style.height = `${el.scrollHeight}px`;
|
|
23
|
-
}, [value]);
|
|
44
|
+
}, [value, autoSize]);
|
|
24
45
|
|
|
25
46
|
return (
|
|
26
47
|
<textarea
|
|
@@ -57,8 +78,10 @@ function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur,
|
|
|
57
78
|
});
|
|
58
79
|
}}
|
|
59
80
|
className={cn(
|
|
60
|
-
"block w-full resize-none overflow-hidden border-0 bg-transparent
|
|
61
|
-
|
|
81
|
+
"block w-full resize-none overflow-hidden border-0 bg-transparent font-[inherit] text-foreground shadow-none outline-none ring-0 placeholder:text-quaternary-foreground focus:outline-none focus:ring-0",
|
|
82
|
+
// Match rendered paragraph rhythm so the block does not jump when editing starts.
|
|
83
|
+
mono ? "p-0 font-mono text-(length:--md-code-size,var(--nonla-mono-text-size)) leading-(--md-code-leading,calc(var(--nonla-mono-text-size)*1.6))" : markdownParagraphClass,
|
|
84
|
+
!autoSize && "h-full",
|
|
62
85
|
className,
|
|
63
86
|
)}
|
|
64
87
|
aria-label="Edit markdown"
|
|
@@ -70,6 +93,10 @@ function interactiveTarget(target: EventTarget | null): boolean {
|
|
|
70
93
|
return target instanceof Element && !!target.closest("a, button, textarea, input");
|
|
71
94
|
}
|
|
72
95
|
|
|
96
|
+
/** Soft pad behind the active block. Pseudo-element keeps layout from shifting. */
|
|
97
|
+
const editingSurfaceClass =
|
|
98
|
+
"relative z-0 before:pointer-events-none before:absolute before:-inset-x-2 before:-inset-y-0.5 before:-z-10 before:rounded-md before:bg-ink-hover before:content-['']";
|
|
99
|
+
|
|
73
100
|
export type MarkdownPreviewProps = {
|
|
74
101
|
doc: MarkdownDoc;
|
|
75
102
|
editingIndex: number | null;
|
|
@@ -95,16 +122,6 @@ export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Wr
|
|
|
95
122
|
const editing = editingIndex === index;
|
|
96
123
|
const locked = block.kind === "mermaid" || (block.kind === "code" && isCustomFence(block.body, components)) || readOnly;
|
|
97
124
|
const view = block.kind === "text" ? readInlineEdit(block.body) : null;
|
|
98
|
-
const editor =
|
|
99
|
-
view?.kind === "heading" ? (
|
|
100
|
-
<BlockEditor value={view.text} className={headingClass(view.level)} caret={caret} onChange={(text) => onChangeBody(writeInlineEdit(block.body, text))} onBlur={onBlurBlock} />
|
|
101
|
-
) : view?.kind === "list" ? (
|
|
102
|
-
<ListItem view={view}>
|
|
103
|
-
<BlockEditor value={view.text} caret={caret} onEnter={onEnterList} onChange={(text) => onChangeBody(writeInlineEdit(block.body, text))} onBlur={onBlurBlock} />
|
|
104
|
-
</ListItem>
|
|
105
|
-
) : (
|
|
106
|
-
<BlockEditor value={block.body} mono={block.kind === "code"} caret={caret} onChange={onChangeBody} onBlur={onBlurBlock} />
|
|
107
|
-
);
|
|
108
125
|
const gap = spaceBefore(block, doc.blocks[index - 1]);
|
|
109
126
|
if (locked) {
|
|
110
127
|
return (
|
|
@@ -118,6 +135,56 @@ export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Wr
|
|
|
118
135
|
</div>
|
|
119
136
|
);
|
|
120
137
|
}
|
|
138
|
+
// List keeps the rendered row as a sizer so the bullet and neighbors do not shift on edit.
|
|
139
|
+
if (view?.kind === "list") {
|
|
140
|
+
return (
|
|
141
|
+
<div
|
|
142
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: block position is the edit identity
|
|
143
|
+
key={`${index}:${block.kind}`}
|
|
144
|
+
role="button"
|
|
145
|
+
data-md-block={block.kind}
|
|
146
|
+
tabIndex={0}
|
|
147
|
+
className={cn("cursor-text outline-none", gap, editing && editingSurfaceClass)}
|
|
148
|
+
onMouseDown={(event) => onEditMouseDown(index, event)}
|
|
149
|
+
onClick={(event) => {
|
|
150
|
+
if (editing || interactiveTarget(event.target)) return;
|
|
151
|
+
const selection = window.getSelection();
|
|
152
|
+
if (selection && selection.toString().length > 0) return;
|
|
153
|
+
onStartEdit(index);
|
|
154
|
+
}}
|
|
155
|
+
onKeyDown={(event) => {
|
|
156
|
+
if (editing || event.key !== "Enter") return;
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
onStartEdit(index);
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<ListItem view={view}>
|
|
162
|
+
<div className="relative">
|
|
163
|
+
<div className={cn(editing && "invisible")} aria-hidden={editing || undefined}>
|
|
164
|
+
<RichText source={view.text} />
|
|
165
|
+
</div>
|
|
166
|
+
{editing ? (
|
|
167
|
+
<BlockEditor
|
|
168
|
+
value={view.text}
|
|
169
|
+
autoSize={false}
|
|
170
|
+
className="absolute inset-0"
|
|
171
|
+
caret={caret}
|
|
172
|
+
onEnter={onEnterList}
|
|
173
|
+
onChange={(text) => onChangeBody(writeInlineEdit(block.body, text))}
|
|
174
|
+
onBlur={onBlurBlock}
|
|
175
|
+
/>
|
|
176
|
+
) : null}
|
|
177
|
+
</div>
|
|
178
|
+
</ListItem>
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const editor =
|
|
183
|
+
view?.kind === "heading" ? (
|
|
184
|
+
<BlockEditor value={view.text} className={headingClass(view.level)} caret={caret} onChange={(text) => onChangeBody(writeInlineEdit(block.body, text))} onBlur={onBlurBlock} />
|
|
185
|
+
) : (
|
|
186
|
+
<BlockEditor value={block.body} mono={block.kind === "code"} caret={caret} onChange={onChangeBody} onBlur={onBlurBlock} />
|
|
187
|
+
);
|
|
121
188
|
return (
|
|
122
189
|
<div
|
|
123
190
|
// biome-ignore lint/suspicious/noArrayIndexKey: block position is the edit identity
|
|
@@ -125,7 +192,7 @@ export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Wr
|
|
|
125
192
|
role="button"
|
|
126
193
|
data-md-block={block.kind}
|
|
127
194
|
tabIndex={0}
|
|
128
|
-
className={cn("cursor-text outline-none", gap)}
|
|
195
|
+
className={cn("cursor-text outline-none", gap, editing && editingSurfaceClass)}
|
|
129
196
|
onMouseDown={(event) => onEditMouseDown(index, event)}
|
|
130
197
|
onClick={(event) => {
|
|
131
198
|
if (editing || interactiveTarget(event.target)) return;
|
|
@@ -4,7 +4,7 @@ import remarkGfm from "remark-gfm";
|
|
|
4
4
|
import { Checkbox } from "../checkbox/Checkbox";
|
|
5
5
|
import { CodeBlock } from "../codeblock/CodeBlock";
|
|
6
6
|
import { cn } from "../lib/cn";
|
|
7
|
-
import { headingClass, markdownScaleStyle } from "../lib/markdownScale";
|
|
7
|
+
import { headingClass, markdownInlineCodeClass, markdownScaleStyle } from "../lib/markdownScale";
|
|
8
8
|
import { type InlineEdit, type MarkdownBlock, parseMarkdownDoc, readFence, readInlineEdit } from "./blocks";
|
|
9
9
|
import { MarkdownTable } from "./MarkdownTable";
|
|
10
10
|
import { MermaidBlock } from "./MermaidBlock";
|
|
@@ -18,7 +18,7 @@ const taskCheckClass =
|
|
|
18
18
|
"data-[state=checked]:border-foreground! data-[state=checked]:bg-foreground! data-[state=checked]:text-background! data-[state=indeterminate]:border-foreground! data-[state=indeterminate]:bg-foreground! data-[state=indeterminate]:text-background!";
|
|
19
19
|
|
|
20
20
|
const documentClass = cn(
|
|
21
|
-
"min-w-0 wrap-anywhere text-(length:--md-body-size,var(--nonla-
|
|
21
|
+
"min-w-0 wrap-anywhere text-(length:--md-body-size,var(--nonla-base-text-size,15px)) leading-(--md-body-leading,calc(var(--nonla-base-text-size,15px)*1.6)) text-foreground",
|
|
22
22
|
"[&_:is(h1,h2,h3,h4,h5,h6)]:text-foreground",
|
|
23
23
|
"[&_:is(h1,h2)]:mt-(--md-h2-mt,24px) [&_h1]:mb-(--md-h1-mb,12px) [&_h2]:mb-(--md-h2-mb,8px) [&_:is(h1,h2)]:pt-(--md-h2-py,3px) [&_:is(h1,h2)]:pb-(--md-h2-py,3px) [&_:is(h1,h2)]:text-(length:--md-h2-size,26px) [&_:is(h1,h2)]:leading-(--md-h2-leading,32px) [&_:is(h1,h2)]:font-(--md-h2-weight,600) [&_:is(h1,h2)]:tracking-normal",
|
|
24
24
|
"[&_h3]:mt-(--md-h3-mt,22px) [&_h3]:mb-(--md-h3-mb,8px) [&_h3]:text-(length:--md-h3-size,24px) [&_h3]:leading-(--md-h3-leading,32px) [&_h3]:font-(--md-h3-weight,600)",
|
|
@@ -47,7 +47,7 @@ const previewComponents: Components = {
|
|
|
47
47
|
const codeText = String(children).replace(/\n$/, "");
|
|
48
48
|
const isBlock = codeText.includes("\n") || !!match;
|
|
49
49
|
if (!isBlock) {
|
|
50
|
-
return <code className=
|
|
50
|
+
return <code className={markdownInlineCodeClass}>{children}</code>;
|
|
51
51
|
}
|
|
52
52
|
if (lang.toLowerCase() === "mermaid") return <MermaidView code={codeText} />;
|
|
53
53
|
return <CodeBlock code={codeText} language={lang || undefined} className="my-(--md-code-my,8px)" />;
|
|
@@ -65,7 +65,7 @@ const previewComponents: Components = {
|
|
|
65
65
|
input({ type, checked }) {
|
|
66
66
|
if (type !== "checkbox") return <input type={type} checked={checked} readOnly />;
|
|
67
67
|
return (
|
|
68
|
-
<span className="nonla-md-task-check pointer-events-none inline-flex h-(--md-body-leading,calc(var(--nonla-
|
|
68
|
+
<span className="nonla-md-task-check pointer-events-none inline-flex h-(--md-body-leading,calc(var(--nonla-base-text-size,15px)*1.6)) items-center">
|
|
69
69
|
<Checkbox checked={Boolean(checked)} tabIndex={-1} className={taskCheckClass} />
|
|
70
70
|
</span>
|
|
71
71
|
);
|
|
@@ -122,7 +122,7 @@ function splitSoftBreaks(node: MdNode): MdNode[] {
|
|
|
122
122
|
return out;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
function RichText({ source }: { source: string }) {
|
|
125
|
+
export function RichText({ source }: { source: string }) {
|
|
126
126
|
return (
|
|
127
127
|
<div className={documentClass}>
|
|
128
128
|
<ReactMarkdown remarkPlugins={[remarkGfm, remarkKeepLineBreaks]} components={previewComponents}>
|
|
@@ -132,10 +132,17 @@ function RichText({ source }: { source: string }) {
|
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* List body keeps paragraph leading so wrapped lines stay readable.
|
|
137
|
+
* View and edit share the same rhythm so the block does not jump.
|
|
138
|
+
*/
|
|
139
|
+
const listBodyClass =
|
|
140
|
+
"[&_p]:my-0! [&_p]:py-0.5! [&_p]:leading-(--md-p-leading,1.6)! [&_textarea]:my-0! [&_textarea]:py-0.5! [&_textarea]:leading-(--md-p-leading,1.6)!";
|
|
141
|
+
|
|
135
142
|
export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind: "list" }>; children: ReactNode }) {
|
|
136
143
|
const level = Math.floor(view.indent.length / 2);
|
|
137
144
|
const ordinal = Number(/^(\d+)/.exec(view.marker)?.[1] ?? "1");
|
|
138
|
-
const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,var(--nonla-
|
|
145
|
+
const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,var(--nonla-base-text-size,15px)) leading-(--md-p-leading,1.6)";
|
|
139
146
|
return (
|
|
140
147
|
<div data-md-list="" className="flex items-start gap-1.5 pl-(--md-item-pl,4px)" style={level > 0 ? { marginLeft: `calc(${level} * var(--md-nest, 1.25rem))` } : undefined}>
|
|
141
148
|
{view.task ? (
|
|
@@ -151,7 +158,7 @@ export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind:
|
|
|
151
158
|
<span className="mt-[calc((1lh-0.375rem)/2)] size-1.5 rounded-full bg-current" />
|
|
152
159
|
</span>
|
|
153
160
|
)}
|
|
154
|
-
<div className="min-w-0 flex-1
|
|
161
|
+
<div className={cn("min-w-0 flex-1", listBodyClass)}>{children}</div>
|
|
155
162
|
</div>
|
|
156
163
|
);
|
|
157
164
|
}
|
|
@@ -163,8 +170,9 @@ function isListBlock(block: MarkdownBlock): boolean {
|
|
|
163
170
|
export function spaceBefore(block: MarkdownBlock, prev?: MarkdownBlock): string {
|
|
164
171
|
if (!prev) return "";
|
|
165
172
|
if (isListBlock(block) && isListBlock(prev)) return "mt-0.5";
|
|
166
|
-
|
|
173
|
+
// List rows keep their own padding model; do not reuse the paragraph-after-heading trim.
|
|
167
174
|
if (isListBlock(block) && prev.kind === "text") return "mt-1";
|
|
175
|
+
if (prev.kind === "text" && readInlineEdit(prev.body).kind === "heading") return "[&_p:first-child]:mt-0! [&_p:first-child]:pt-0.5! [&_textarea]:mt-0! [&_textarea]:pt-0.5!";
|
|
168
176
|
if (block.kind === "text" && prev.kind === "text") return "";
|
|
169
177
|
return "mt-3";
|
|
170
178
|
}
|
package/src/styles.css
CHANGED
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
|
|
44
44
|
--nonla-font: "Inter Variable", ui-sans-serif, -apple-system, system-ui, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", "Noto Sans Arabic", "Noto Sans Hebrew", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
|
|
45
45
|
--nonla-mono-font: "Geist Mono Variable", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
|
|
46
|
-
/* Default body size. Tailwind `text-base`
|
|
46
|
+
/* Default body size. Markdown body and Tailwind `text-base` follow this. Leading is 1.6. */
|
|
47
47
|
--nonla-base-text-size: 15px;
|
|
48
|
-
/* `text-md`.
|
|
48
|
+
/* `text-md`. One step above the body. */
|
|
49
49
|
--nonla-md-text-size: 16px;
|
|
50
50
|
/* `text-sm`. Composer, tool lines, and errors use this. User bubbles use `text-base`. */
|
|
51
51
|
--nonla-sm-text-size: 14px;
|
|
52
|
-
/*
|
|
53
|
-
--nonla-mono-text-size:
|
|
52
|
+
/* Fenced code. Same size as `text-sm`. */
|
|
53
|
+
--nonla-mono-text-size: var(--nonla-sm-text-size);
|
|
54
54
|
--nonla-radius: 8px;
|
|
55
55
|
--nonla-height: 32px;
|
|
56
56
|
--nonla-height-sm: 24px;
|
|
@@ -136,12 +136,12 @@
|
|
|
136
136
|
.nonla-ui.light {
|
|
137
137
|
color-scheme: light;
|
|
138
138
|
|
|
139
|
-
/*
|
|
139
|
+
/* Page is white. Text is warm stone, same family as dark. Sidebar and cards stay neutral-50. */
|
|
140
140
|
--nonla-bg: #ffffff; /* white */
|
|
141
|
-
--nonla-text-main: #
|
|
142
|
-
--nonla-text-secondary: #
|
|
143
|
-
--nonla-text-tertiary: #
|
|
144
|
-
--nonla-text-quaternary: #
|
|
141
|
+
--nonla-text-main: #1e1d1b;
|
|
142
|
+
--nonla-text-secondary: #564f48;
|
|
143
|
+
--nonla-text-tertiary: #6f6a63;
|
|
144
|
+
--nonla-text-quaternary: #8a847c;
|
|
145
145
|
--nonla-text-on-solid: #ffffff; /* white */
|
|
146
146
|
--nonla-brand: #f18d00;
|
|
147
147
|
--nonla-danger: #dc3b3b;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AnchorHTMLAttributes, type CSSProperties, createElement, type HTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
|
-
import { headingClass, markdownBodyClass, markdownParagraphClass, markdownScaleStyle, pageTitleClass } from "../lib/markdownScale";
|
|
3
|
+
import { headingClass, markdownBodyClass, markdownInlineCodeClass, markdownParagraphClass, markdownScaleStyle, pageTitleClass } from "../lib/markdownScale";
|
|
4
4
|
|
|
5
5
|
export type TypographyType = "secondary" | "success" | "warning" | "danger";
|
|
6
6
|
|
|
@@ -40,11 +40,9 @@ const TITLE_TAG = {
|
|
|
40
40
|
6: "h6",
|
|
41
41
|
} as const;
|
|
42
42
|
|
|
43
|
-
/** Same scale as MarkdownViewer. Body size is `text-
|
|
43
|
+
/** Same scale as MarkdownViewer. Body size is `text-base`. Inline code uses the viewer chip. */
|
|
44
44
|
const BODY = markdownBodyClass;
|
|
45
45
|
|
|
46
|
-
const INLINE_CODE = "nonla-inline-code rounded-[4px] bg-muted px-[2px] py-px align-baseline font-mono text-(length:--md-inline-size,var(--nonla-mono-text-size)) leading-none whitespace-nowrap [box-decoration-break:clone] [-webkit-box-decoration-break:clone]";
|
|
47
|
-
|
|
48
46
|
const TITLE_SPACE = "nonla-typo";
|
|
49
47
|
|
|
50
48
|
function decorationLine(underline?: boolean, deleted?: boolean) {
|
|
@@ -60,7 +58,7 @@ function wrapDecorations(children: ReactNode, props: Decorations) {
|
|
|
60
58
|
node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-warn)_40%,transparent)] px-0.5 text-inherit">{node}</mark>;
|
|
61
59
|
}
|
|
62
60
|
if (props.code) {
|
|
63
|
-
node = <code className={
|
|
61
|
+
node = <code className={markdownInlineCodeClass}>{node}</code>;
|
|
64
62
|
}
|
|
65
63
|
if (props.keyboard) {
|
|
66
64
|
node = <kbd className="inline-block rounded-md border border-b-2 border-border bg-muted px-1.5 font-mono text-[0.85em] leading-5">{node}</kbd>;
|