react-inline-markdown-editor 2.0.4
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/LICENSE +22 -0
- package/README.md +89 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2025
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# react-inline-markdown-editor
|
|
2
|
+
|
|
3
|
+
A React markdown editor with live preview, built on [CodeMirror 6](https://codemirror.net/). Syntax markers (`**`, `#`, `` ` ``) stay hidden while you read and reveal only on the line your cursor is on — so the document looks rendered, but every character is still directly editable.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Live preview — headings, **bold**, *italic*, ~~strikethrough~~, `inline code`, links, images, blockquotes, lists and fenced code render in place
|
|
10
|
+
- Syntax markers reveal on the active line and hide everywhere else
|
|
11
|
+
- Bullet lists render with a `•` marker
|
|
12
|
+
- Dark and light themes, swappable at runtime without remounting
|
|
13
|
+
- GitHub Flavored Markdown
|
|
14
|
+
- Controlled component — you own the markdown string
|
|
15
|
+
- CodeMirror is a peer-installed dependency, not bundled (keeps your build lean)
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm i react-inline-markdown-editor
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Peer deps: `react` and `react-dom` (>= 18). CodeMirror 6 packages install automatically.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import React from "react";
|
|
29
|
+
import { InlineMarkdownEditor } from "react-inline-markdown-editor";
|
|
30
|
+
|
|
31
|
+
export default function App() {
|
|
32
|
+
const [value, setValue] = React.useState(`# Heading\n\nSome **bold** text.\n\n- a list item`);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<InlineMarkdownEditor
|
|
36
|
+
value={value}
|
|
37
|
+
onChange={setValue}
|
|
38
|
+
theme="dark"
|
|
39
|
+
height="400px"
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
export type InlineMarkdownEditorProps = {
|
|
49
|
+
/** Controlled markdown content. */
|
|
50
|
+
value: string;
|
|
51
|
+
/** Called on every change with the full new markdown string. */
|
|
52
|
+
onChange: (next: string) => void;
|
|
53
|
+
/** Visual theme. Defaults to "dark". */
|
|
54
|
+
theme?: "dark" | "light";
|
|
55
|
+
/** Class applied to the outer container div. */
|
|
56
|
+
className?: string;
|
|
57
|
+
/** Inline styles for the outer container div. */
|
|
58
|
+
style?: React.CSSProperties;
|
|
59
|
+
/** Editor height. Defaults to "100%". Accepts any CSS length. */
|
|
60
|
+
height?: string;
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Keyboard behavior
|
|
65
|
+
|
|
66
|
+
Standard CodeMirror editing keymaps: arrow-key navigation, undo/redo, `Tab` to indent, and the usual text-editing shortcuts.
|
|
67
|
+
|
|
68
|
+
## Theming
|
|
69
|
+
|
|
70
|
+
`theme` switches between bundled dark and light palettes. Changing the prop at runtime swaps the theme via a CodeMirror compartment — no remount, no loss of focus or content. Wire it to your app's theme however you like:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
<InlineMarkdownEditor value={value} onChange={setValue} theme={isDark ? "dark" : "light"} />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Security
|
|
77
|
+
|
|
78
|
+
The editor renders text as text — markdown is never converted to HTML and never injected into the DOM. Pasting `<script>` or any HTML shows it as literal characters. To display the markdown elsewhere, render it yourself with a sanitizing pipeline (e.g. `marked` + `DOMPurify`).
|
|
79
|
+
|
|
80
|
+
## Build & publish (maintainers)
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm run build
|
|
84
|
+
npm publish --access public
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var m=require('react'),view=require('@codemirror/view'),state=require('@codemirror/state'),langMarkdown=require('@codemirror/lang-markdown'),commands=require('@codemirror/commands'),language=require('@codemirror/language'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var m__namespace=/*#__PURE__*/_interopNamespace(m);var p=view.Decoration.replace({}),k=class extends view.WidgetType{toDOM(){let n=document.createElement("span");return n.textContent="\u2022",n.className="ob-list-mark",n}eq(){return true}};function l(a,n,d){for(let t of a.selection.ranges)if(t.from>=n&&t.to<=d||t.from<=d&&t.to>=n)return true;return false}function g(a,n){let d=a.doc.lineAt(n);for(let t of a.selection.ranges)if(t.from>=d.from&&t.from<=d.to)return true;return false}function E(a){let{state:n}=a,d=[],t=(i,r,o)=>{i<r&&d.push({from:i,to:r,deco:o});},c=i=>view.Decoration.mark({class:i});return language.syntaxTree(n).cursor().iterate(i=>{let{name:r,from:o,to:e}=i;if(/^ATXHeading[1-6]$/.test(r)){let s=r.slice(-1);t(o,e,c(`ob-h${s}`));}if(r==="HeaderMark"&&(g(n,o)?t(o,e,c("ob-syntax")):t(o,e,p)),r==="StrongEmphasis"&&(l(n,o,e)||t(o,e,c("ob-bold"))),r==="Emphasis"&&(l(n,o,e)||t(o,e,c("ob-italic"))),r==="EmphasisMark"){let s=i.node.parent?.from??o,f=i.node.parent?.to??e;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Strikethrough"&&(l(n,o,e)||t(o,e,c("ob-strikethrough"))),r==="StrikethroughMark"){let s=i.node.parent?.from??o,f=i.node.parent?.to??e;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="InlineCode"&&(l(n,o,e)||t(o,e,c("ob-code"))),r==="CodeMark"&&i.node.parent?.name==="InlineCode"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Link"&&(l(n,o,e)||t(o,e,c("ob-link"))),r==="LinkMark"&&i.node.parent?.name==="Link"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="URL"&&i.node.parent?.name==="Link"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Image"&&(l(n,o,e)||t(o,e,c("ob-image"))),r==="LinkMark"&&i.node.parent?.name==="Image"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="URL"&&i.node.parent?.name==="Image"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Blockquote"&&t(o,e,c("ob-blockquote")),r==="BlockquoteMark"&&(g(n,o),t(o,e,c("ob-blockquote-mark"))),r==="ListMark"){let s=n.doc.sliceString(o,e);(s==="-"||s==="*"||s==="+")&&!g(n,o)?t(o,e,view.Decoration.replace({widget:new k})):t(o,e,c("ob-list-mark"));}r==="FencedCode"&&t(o,e,c("ob-code-block")),r==="CodeMark"&&i.node.parent?.name==="FencedCode"&&t(o,e,c("ob-fence-mark")),r==="CodeInfo"&&t(o,e,c("ob-code-info")),r==="HorizontalRule"&&t(o,e,c("ob-hr"));}),view.Decoration.set(d.map(({from:i,to:r,deco:o})=>o.range(i,r)),true)}var C=view.ViewPlugin.fromClass(class{constructor(a){this.decorations=E(a);}update(a){(a.docChanged||a.selectionSet||a.viewportChanged||language.syntaxTree(a.startState)!==language.syntaxTree(a.state))&&(this.decorations=E(a.view));}},{decorations:a=>a.decorations});var w=view.EditorView.theme({"&":{backgroundColor:"#1e1e2e",color:"#cdd6f4",fontFamily:"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif",fontSize:"16px",lineHeight:"1.7",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{padding:"24px 32px",caretColor:"#cdd6f4",maxWidth:"800px",margin:"0 auto"},".cm-focused":{outline:"none"},".cm-line":{padding:"1px 0"},".cm-cursor":{borderLeftColor:"#cdd6f4",borderLeftWidth:"2px"},".cm-selectionBackground, ::selection":{backgroundColor:"#313244 !important"},".ob-h1":{color:"#cba6f7",fontSize:"2em",fontWeight:"700",lineHeight:"1.3",marginBottom:"4px"},".ob-h2":{color:"#cba6f7",fontSize:"1.5em",fontWeight:"700",lineHeight:"1.3"},".ob-h3":{color:"#cba6f7",fontSize:"1.25em",fontWeight:"700",lineHeight:"1.3"},".ob-h4":{color:"#cba6f7",fontSize:"1.1em",fontWeight:"700"},".ob-h5":{color:"#cba6f7",fontWeight:"700"},".ob-h6":{color:"#a6adc8",fontWeight:"700"},".ob-bold":{fontWeight:"700",color:"#cdd6f4"},".ob-italic":{fontStyle:"italic",color:"#cdd6f4"},".ob-strikethrough":{textDecoration:"line-through",color:"#6c7086"},".ob-code":{color:"#f38ba8",backgroundColor:"#313244",borderRadius:"4px",padding:"1px 5px",fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"0.9em"},".ob-link":{color:"#89b4fa",textDecoration:"underline",cursor:"pointer"},".ob-link-text":{color:"#89b4fa"},".ob-syntax":{color:"#45475a",opacity:"0.7"},".ob-blockquote":{borderLeft:"3px solid #585b70",paddingLeft:"16px",color:"#9399b2",fontStyle:"italic"},".ob-blockquote-mark":{color:"#45475a"},".ob-list-mark":{color:"#89b4fa",fontWeight:"600"},".ob-hr":{color:"#45475a",letterSpacing:"4px"},".ob-code-block":{backgroundColor:"#181825",borderRadius:"6px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace",fontSize:"0.9em",color:"#cdd6f4"},".ob-fence-mark":{color:"#45475a"},".ob-code-info":{color:"#a6e3a1",fontSize:"0.8em"},".ob-image":{color:"#f9e2af"}},{dark:true});var M=view.EditorView.theme({"&":{backgroundColor:"#fafafa",color:"#1a1a1a",fontFamily:"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif",fontSize:"16px",lineHeight:"1.7",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{padding:"24px 32px",caretColor:"#1a1a1a",maxWidth:"800px",margin:"0 auto"},".cm-focused":{outline:"none"},".cm-line":{padding:"1px 0"},".cm-cursor":{borderLeftColor:"#1a1a1a",borderLeftWidth:"2px"},".cm-selectionBackground, ::selection":{backgroundColor:"#e5e7eb !important"},".ob-h1":{color:"#7c3aed",fontSize:"2em",fontWeight:"700",lineHeight:"1.3",marginBottom:"4px"},".ob-h2":{color:"#7c3aed",fontSize:"1.5em",fontWeight:"700",lineHeight:"1.3"},".ob-h3":{color:"#7c3aed",fontSize:"1.25em",fontWeight:"700",lineHeight:"1.3"},".ob-h4":{color:"#7c3aed",fontSize:"1.1em",fontWeight:"700"},".ob-h5":{color:"#7c3aed",fontWeight:"700"},".ob-h6":{color:"#9333ea",fontWeight:"700"},".ob-bold":{fontWeight:"700",color:"#1a1a1a"},".ob-italic":{fontStyle:"italic",color:"#1a1a1a"},".ob-strikethrough":{textDecoration:"line-through",color:"#9ca3af"},".ob-code":{color:"#dc2626",backgroundColor:"#f3f4f6",borderRadius:"4px",padding:"1px 5px",fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"0.9em"},".ob-link":{color:"#2563eb",textDecoration:"underline",cursor:"pointer"},".ob-link-text":{color:"#2563eb"},".ob-syntax":{color:"#d1d5db",opacity:"0.9"},".ob-blockquote":{borderLeft:"3px solid #d1d5db",paddingLeft:"16px",color:"#6b7280",fontStyle:"italic"},".ob-blockquote-mark":{color:"#d1d5db"},".ob-list-mark":{color:"#2563eb",fontWeight:"600"},".ob-hr":{color:"#d1d5db",letterSpacing:"4px"},".ob-code-block":{backgroundColor:"#f3f4f6",borderRadius:"6px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace",fontSize:"0.9em",color:"#1a1a1a"},".ob-fence-mark":{color:"#d1d5db"},".ob-code-info":{color:"#16a34a",fontSize:"0.8em"},".ob-image":{color:"#d97706"}},{dark:false});var x=new state.Compartment;function S(a){return a==="dark"?w:M}function F(a){return [langMarkdown.markdown({base:langMarkdown.markdownLanguage}),commands.history(),view.keymap.of([...commands.defaultKeymap,...commands.historyKeymap,commands.indentWithTab]),view.EditorView.lineWrapping,view.EditorView.contentAttributes.of({spellcheck:"true"}),view.drawSelection(),view.dropCursor(),view.rectangularSelection(),view.crosshairCursor(),C,x.of(S(a))]}var $=({value:a,onChange:n,theme:d="dark",className:t,style:c,height:i="100%"})=>{let r=m__namespace.useRef(null),o=m__namespace.useRef(null),e=m__namespace.useRef(n);m__namespace.useLayoutEffect(()=>{e.current=n;});let s=m__namespace.useRef(false);return m__namespace.useEffect(()=>{if(!r.current)return;let f=view.EditorView.updateListener.of(y=>{y.docChanged&&(s.current=true,e.current(y.state.doc.toString()));}),b=new view.EditorView({state:state.EditorState.create({doc:a,extensions:[...F(d),f]}),parent:r.current});return o.current=b,()=>{b.destroy(),o.current=null;}},[]),m__namespace.useEffect(()=>{let f=o.current;if(!f)return;if(s.current){s.current=false;return}let b=f.state.doc.toString();b!==a&&f.dispatch({changes:{from:0,to:b.length,insert:a},annotations:[]});},[a]),m__namespace.useEffect(()=>{let f=o.current;f&&f.dispatch({effects:x.reconfigure(S(d))});},[d]),jsxRuntime.jsx("div",{ref:r,className:t,style:{height:i,...c}})};exports.InlineMarkdownEditor=$;//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorations.ts","../src/theme-dark.ts","../src/theme-light.ts","../src/editor.ts","../src/InlineMarkdownEditor.tsx"],"names":["HIDE","Decoration","BulletWidget","WidgetType","s","isCursorInRange","state","from","to","range","isCursorOnLine","line","buildDecorations","view","entries","add","deco","mark","cls","syntaxTree","node","name","level","parentFrom","parentTo","markText","liveMarkdownDecorations","ViewPlugin","update","instance","darkTheme","EditorView","lightTheme","themeCompartment","Compartment","getThemeExtension","theme","buildExtensions","markdown","markdownLanguage","history","keymap","defaultKeymap","historyKeymap","indentWithTab","drawSelection","dropCursor","rectangularSelection","crosshairCursor","InlineMarkdownEditor","value","onChange","className","style","height","containerRef","m","viewRef","onChangeRef","skipNextSync","updateListener","EditorState","current","jsx"],"mappings":"0nBAgBA,IAAMA,CAAAA,CAAOC,gBAAW,OAAA,CAAQ,EAAE,CAAA,CAG5BC,CAAAA,CAAN,cAA2BC,eAAW,CACpC,OAAqB,CACnB,IAAMC,EAAI,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA,CACvC,OAAAA,EAAE,WAAA,CAAc,QAAA,CAChBA,EAAE,SAAA,CAAY,cAAA,CACPA,CACT,CACA,EAAA,EAAc,CACZ,OAAO,KACT,CACF,CAAA,CAIA,SAASC,EAAgBC,CAAAA,CAAoBC,CAAAA,CAAcC,EAAqB,CAC9E,IAAA,IAAWC,KAASH,CAAAA,CAAM,SAAA,CAAU,OAElC,GADIG,CAAAA,CAAM,MAAQF,CAAAA,EAAQE,CAAAA,CAAM,IAAMD,CAAAA,EAClCC,CAAAA,CAAM,MAAQD,CAAAA,EAAMC,CAAAA,CAAM,IAAMF,CAAAA,CAAM,OAAO,MAEnD,OAAO,MACT,CAEA,SAASG,CAAAA,CAAeJ,EAAoBC,CAAAA,CAAuB,CACjE,IAAMI,CAAAA,CAAOL,CAAAA,CAAM,IAAI,MAAA,CAAOC,CAAI,EAClC,IAAA,IAAWE,CAAAA,IAASH,EAAM,SAAA,CAAU,MAAA,CAClC,GAAIG,CAAAA,CAAM,IAAA,EAAQE,EAAK,IAAA,EAAQF,CAAAA,CAAM,MAAQE,CAAAA,CAAK,EAAA,CAAI,OAAO,KAAA,CAE/D,OAAO,MACT,CAEA,SAASC,EAAiBC,CAAAA,CAAiC,CACzD,GAAM,CAAE,KAAA,CAAAP,CAAM,CAAA,CAAIO,CAAAA,CACZC,EAAuB,EAAC,CAExBC,EAAM,CAACR,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,YAAA,CAAA,SAAA,CAAU,IAAM,CACpB,IAAM3C,EAAO4C,CAAAA,CAAQ,OAAA,CACrB,GAAI,CAAC5C,CAAAA,CAAM,OAGX,GAAI8C,CAAAA,CAAa,QAAS,CACxBA,CAAAA,CAAa,QAAU,KAAA,CACvB,MACF,CAEA,IAAMG,CAAAA,CAAUjD,EAAK,KAAA,CAAM,GAAA,CAAI,UAAS,CACpCiD,CAAAA,GAAYZ,GACdrC,CAAAA,CAAK,QAAA,CAAS,CACZ,OAAA,CAAS,CAAE,KAAM,CAAA,CAAG,EAAA,CAAIiD,EAAQ,MAAA,CAAQ,MAAA,CAAQZ,CAAM,CAAA,CAEtD,WAAA,CAAa,EACf,CAAC,EAEL,CAAA,CAAG,CAACA,CAAK,CAAC,CAAA,CAGJM,uBAAU,IAAM,CACpB,IAAM3C,CAAAA,CAAO4C,CAAAA,CAAQ,QAChB5C,CAAAA,EACLA,CAAAA,CAAK,SAAS,CACZ,OAAA,CAASoB,EAAiB,WAAA,CAAYE,CAAAA,CAAkBC,CAAK,CAAC,CAChE,CAAC,EACH,CAAA,CAAG,CAACA,CAAK,CAAC,EAGR2B,cAAAA,CAAC,KAAA,CAAA,CACC,IAAKR,CAAAA,CACL,SAAA,CAAWH,EACX,KAAA,CAAO,CAAE,OAAAE,CAAAA,CAAQ,GAAGD,CAAM,CAAA,CAC5B,CAEJ","file":"index.cjs","sourcesContent":["// src/decorations.ts\nimport {\n ViewPlugin,\n DecorationSet,\n Decoration,\n ViewUpdate,\n WidgetType,\n EditorView,\n} from \"@codemirror/view\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { EditorState } from \"@codemirror/state\";\n\n// A widgetless replace decoration collapses the range out of layout entirely —\n// the same mechanism code-folding uses. A display:none widget would instead\n// leave a DOM node whose getBoundingClientRect is all-zeros, which breaks\n// posAtCoords hit-testing and makes vertical cursor motion skip lines.\nconst HIDE = Decoration.replace({});\n\n// Renders a list marker (-, *, +) as a typographic bullet.\nclass BulletWidget extends WidgetType {\n toDOM(): HTMLElement {\n const s = document.createElement(\"span\");\n s.textContent = \"•\";\n s.className = \"ob-list-mark\";\n return s;\n }\n eq(): boolean {\n return true;\n }\n}\n\ntype DecoEntry = { from: number; to: number; deco: Decoration };\n\nfunction isCursorInRange(state: EditorState, from: number, to: number): boolean {\n for (const range of state.selection.ranges) {\n if (range.from >= from && range.to <= to) return true;\n if (range.from <= to && range.to >= from) return true;\n }\n return false;\n}\n\nfunction isCursorOnLine(state: EditorState, from: number): boolean {\n const line = state.doc.lineAt(from);\n for (const range of state.selection.ranges) {\n if (range.from >= line.from && range.from <= line.to) return true;\n }\n return false;\n}\n\nfunction buildDecorations(view: EditorView): DecorationSet {\n const { state } = view;\n const entries: DecoEntry[] = [];\n\n const add = (from: number, to: number, deco: Decoration) => {\n if (from < to) entries.push({ from, to, deco });\n };\n\n const mark = (cls: string) => Decoration.mark({ class: cls });\n\n syntaxTree(state).cursor().iterate((node) => {\n const { name, from, to } = node;\n\n // ── ATX Headings ──────────────────────────────────────────────────────\n // Level derived from node name: ATXHeading1 → h1, etc.\n if (/^ATXHeading[1-6]$/.test(name)) {\n const level = name.slice(-1); // \"1\"–\"6\"\n add(from, to, mark(`ob-h${level}`));\n }\n\n // HeaderMark = the leading `# ` characters in ATX headings\n if (name === \"HeaderMark\") {\n if (isCursorOnLine(state, from)) {\n add(from, to, mark(\"ob-syntax\")); // show dimmed\n } else {\n add(from, to, HIDE); // hide when cursor is elsewhere\n }\n }\n\n // ── Strong emphasis (bold): **text** or __text__ ───────────────────\n if (name === \"StrongEmphasis\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-bold\"));\n }\n }\n\n // ── Emphasis (italic): *text* or _text_ ────────────────────────────\n if (name === \"Emphasis\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-italic\"));\n }\n }\n\n // EmphasisMark = ** / * / __ / _ markers (shared by bold and italic)\n if (name === \"EmphasisMark\") {\n const parentFrom = node.node.parent?.from ?? from;\n const parentTo = node.node.parent?.to ?? to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\")); // show dimmed\n } else {\n add(from, to, HIDE); // hide\n }\n }\n\n // ── Strikethrough: ~~text~~ (GFM) ─────────────────────────────────\n if (name === \"Strikethrough\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-strikethrough\"));\n }\n }\n if (name === \"StrikethroughMark\") {\n const parentFrom = node.node.parent?.from ?? from;\n const parentTo = node.node.parent?.to ?? to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n\n // ── Inline code: `code` ───────────────────────────────────────────\n if (name === \"InlineCode\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-code\"));\n }\n }\n // CodeMark inside InlineCode = the backtick(s)\n if (name === \"CodeMark\" && node.node.parent?.name === \"InlineCode\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n\n // ── Links: [text](url) ────────────────────────────────────────────\n if (name === \"Link\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-link\"));\n }\n }\n // LinkMark = [ ] ( ) characters in links\n if (name === \"LinkMark\" && node.node.parent?.name === \"Link\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n // URL inside Link (the url part) — hide when cursor away\n if (name === \"URL\" && node.node.parent?.name === \"Link\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (!isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, HIDE);\n } else {\n add(from, to, mark(\"ob-syntax\"));\n }\n }\n\n // ── Images:  ──────────────────────────────────────────\n if (name === \"Image\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-image\"));\n }\n }\n if (name === \"LinkMark\" && node.node.parent?.name === \"Image\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n if (name === \"URL\" && node.node.parent?.name === \"Image\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (!isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, HIDE);\n } else {\n add(from, to, mark(\"ob-syntax\"));\n }\n }\n\n // ── Blockquote ────────────────────────────────────────────────────\n if (name === \"Blockquote\") {\n add(from, to, mark(\"ob-blockquote\"));\n }\n if (name === \"BlockquoteMark\") {\n if (isCursorOnLine(state, from)) {\n add(from, to, mark(\"ob-blockquote-mark\"));\n } else {\n add(from, to, mark(\"ob-blockquote-mark\")); // always show `>` but styled\n }\n }\n\n // ── List markers ─────────────────────────────────────────────────\n if (name === \"ListMark\") {\n const markText = state.doc.sliceString(from, to);\n const isBullet =\n markText === \"-\" || markText === \"*\" || markText === \"+\";\n if (isBullet && !isCursorOnLine(state, from)) {\n add(from, to, Decoration.replace({ widget: new BulletWidget() }));\n } else {\n add(from, to, mark(\"ob-list-mark\"));\n }\n }\n\n // ── Fenced code blocks ───────────────────────────────────────────\n if (name === \"FencedCode\") {\n add(from, to, mark(\"ob-code-block\"));\n }\n // CodeMark inside FencedCode = the ``` or ~~~ fence lines\n if (name === \"CodeMark\" && node.node.parent?.name === \"FencedCode\") {\n add(from, to, mark(\"ob-fence-mark\"));\n }\n // CodeInfo = language specifier after opening fence\n if (name === \"CodeInfo\") {\n add(from, to, mark(\"ob-code-info\"));\n }\n\n // ── Horizontal rule ──────────────────────────────────────────────\n if (name === \"HorizontalRule\") {\n add(from, to, mark(\"ob-hr\"));\n }\n });\n\n // Decoration.set sorts by `from` AND `startSide` — RangeSetBuilder cannot,\n // since mark and replace decorations carry different sides at the same offset.\n return Decoration.set(\n entries.map(({ from, to, deco }) => deco.range(from, to)),\n true\n );\n}\n\nexport const liveMarkdownDecorations = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = buildDecorations(view);\n }\n\n update(update: ViewUpdate) {\n // Rebuild on background-parse progress too: syntaxTree() returns a new\n // tree as the parser advances, and the initial mount often only has the\n // first viewport parsed — without this, off-screen lines never decorate.\n if (\n update.docChanged ||\n update.selectionSet ||\n update.viewportChanged ||\n syntaxTree(update.startState) !== syntaxTree(update.state)\n ) {\n this.decorations = buildDecorations(update.view);\n }\n }\n },\n { decorations: (instance) => instance.decorations }\n);\n","// src/theme-dark.ts\nimport { EditorView } from \"@codemirror/view\";\nimport { Extension } from \"@codemirror/state\";\n\nexport const darkTheme: Extension = EditorView.theme(\n {\n \"&\": {\n backgroundColor: \"#1e1e2e\",\n color: \"#cdd6f4\",\n fontFamily:\n \"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif\",\n fontSize: \"16px\",\n lineHeight: \"1.7\",\n height: \"100%\",\n },\n \".cm-scroller\": { overflow: \"auto\" },\n \".cm-content\": {\n padding: \"24px 32px\",\n caretColor: \"#cdd6f4\",\n maxWidth: \"800px\",\n margin: \"0 auto\",\n },\n \".cm-focused\": { outline: \"none\" },\n \".cm-line\": { padding: \"1px 0\" },\n \".cm-cursor\": { borderLeftColor: \"#cdd6f4\", borderLeftWidth: \"2px\" },\n \".cm-selectionBackground, ::selection\": {\n backgroundColor: \"#313244 !important\",\n },\n // Headings\n \".ob-h1\": {\n color: \"#cba6f7\",\n fontSize: \"2em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n marginBottom: \"4px\",\n },\n \".ob-h2\": {\n color: \"#cba6f7\",\n fontSize: \"1.5em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n },\n \".ob-h3\": {\n color: \"#cba6f7\",\n fontSize: \"1.25em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n },\n \".ob-h4\": { color: \"#cba6f7\", fontSize: \"1.1em\", fontWeight: \"700\" },\n \".ob-h5\": { color: \"#cba6f7\", fontWeight: \"700\" },\n \".ob-h6\": { color: \"#a6adc8\", fontWeight: \"700\" },\n // Inline formatting\n \".ob-bold\": { fontWeight: \"700\", color: \"#cdd6f4\" },\n \".ob-italic\": { fontStyle: \"italic\", color: \"#cdd6f4\" },\n \".ob-strikethrough\": { textDecoration: \"line-through\", color: \"#6c7086\" },\n \".ob-code\": {\n color: \"#f38ba8\",\n backgroundColor: \"#313244\",\n borderRadius: \"4px\",\n padding: \"1px 5px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace\",\n fontSize: \"0.9em\",\n },\n \".ob-link\": { color: \"#89b4fa\", textDecoration: \"underline\", cursor: \"pointer\" },\n \".ob-link-text\": { color: \"#89b4fa\" },\n // Syntax markers (shown dimmed when cursor is active in the span)\n \".ob-syntax\": { color: \"#45475a\", opacity: \"0.7\" },\n // Blockquote\n \".ob-blockquote\": {\n borderLeft: \"3px solid #585b70\",\n paddingLeft: \"16px\",\n color: \"#9399b2\",\n fontStyle: \"italic\",\n },\n \".ob-blockquote-mark\": { color: \"#45475a\" },\n // List markers\n \".ob-list-mark\": { color: \"#89b4fa\", fontWeight: \"600\" },\n // Horizontal rule\n \".ob-hr\": { color: \"#45475a\", letterSpacing: \"4px\" },\n // Code block (fenced)\n \".ob-code-block\": {\n backgroundColor: \"#181825\",\n borderRadius: \"6px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', monospace\",\n fontSize: \"0.9em\",\n color: \"#cdd6f4\",\n },\n \".ob-fence-mark\": { color: \"#45475a\" },\n \".ob-code-info\": { color: \"#a6e3a1\", fontSize: \"0.8em\" },\n // Image alt text\n \".ob-image\": { color: \"#f9e2af\" },\n },\n { dark: true }\n);\n","// src/theme-light.ts\nimport { EditorView } from \"@codemirror/view\";\nimport { Extension } from \"@codemirror/state\";\n\nexport const lightTheme: Extension = EditorView.theme(\n {\n \"&\": {\n backgroundColor: \"#fafafa\",\n color: \"#1a1a1a\",\n fontFamily:\n \"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif\",\n fontSize: \"16px\",\n lineHeight: \"1.7\",\n height: \"100%\",\n },\n \".cm-scroller\": { overflow: \"auto\" },\n \".cm-content\": {\n padding: \"24px 32px\",\n caretColor: \"#1a1a1a\",\n maxWidth: \"800px\",\n margin: \"0 auto\",\n },\n \".cm-focused\": { outline: \"none\" },\n \".cm-line\": { padding: \"1px 0\" },\n \".cm-cursor\": { borderLeftColor: \"#1a1a1a\", borderLeftWidth: \"2px\" },\n \".cm-selectionBackground, ::selection\": {\n backgroundColor: \"#e5e7eb !important\",\n },\n // Headings\n \".ob-h1\": {\n color: \"#7c3aed\",\n fontSize: \"2em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n marginBottom: \"4px\",\n },\n \".ob-h2\": { color: \"#7c3aed\", fontSize: \"1.5em\", fontWeight: \"700\", lineHeight: \"1.3\" },\n \".ob-h3\": { color: \"#7c3aed\", fontSize: \"1.25em\", fontWeight: \"700\", lineHeight: \"1.3\" },\n \".ob-h4\": { color: \"#7c3aed\", fontSize: \"1.1em\", fontWeight: \"700\" },\n \".ob-h5\": { color: \"#7c3aed\", fontWeight: \"700\" },\n \".ob-h6\": { color: \"#9333ea\", fontWeight: \"700\" },\n // Inline formatting\n \".ob-bold\": { fontWeight: \"700\", color: \"#1a1a1a\" },\n \".ob-italic\": { fontStyle: \"italic\", color: \"#1a1a1a\" },\n \".ob-strikethrough\": { textDecoration: \"line-through\", color: \"#9ca3af\" },\n \".ob-code\": {\n color: \"#dc2626\",\n backgroundColor: \"#f3f4f6\",\n borderRadius: \"4px\",\n padding: \"1px 5px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace\",\n fontSize: \"0.9em\",\n },\n \".ob-link\": { color: \"#2563eb\", textDecoration: \"underline\", cursor: \"pointer\" },\n \".ob-link-text\": { color: \"#2563eb\" },\n // Syntax markers (dimmed when cursor is in span)\n \".ob-syntax\": { color: \"#d1d5db\", opacity: \"0.9\" },\n // Blockquote\n \".ob-blockquote\": {\n borderLeft: \"3px solid #d1d5db\",\n paddingLeft: \"16px\",\n color: \"#6b7280\",\n fontStyle: \"italic\",\n },\n \".ob-blockquote-mark\": { color: \"#d1d5db\" },\n // List markers\n \".ob-list-mark\": { color: \"#2563eb\", fontWeight: \"600\" },\n // Horizontal rule\n \".ob-hr\": { color: \"#d1d5db\", letterSpacing: \"4px\" },\n // Code block (fenced)\n \".ob-code-block\": {\n backgroundColor: \"#f3f4f6\",\n borderRadius: \"6px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', monospace\",\n fontSize: \"0.9em\",\n color: \"#1a1a1a\",\n },\n \".ob-fence-mark\": { color: \"#d1d5db\" },\n \".ob-code-info\": { color: \"#16a34a\", fontSize: \"0.8em\" },\n // Image\n \".ob-image\": { color: \"#d97706\" },\n },\n { dark: false }\n);\n","// src/editor.ts\nimport { markdown, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport { history, defaultKeymap, historyKeymap, indentWithTab } from \"@codemirror/commands\";\nimport { EditorView, keymap, drawSelection, dropCursor, rectangularSelection, crosshairCursor } from \"@codemirror/view\";\nimport { EditorState, Extension, Compartment } from \"@codemirror/state\";\nimport { liveMarkdownDecorations } from \"./decorations\";\nimport { darkTheme } from \"./theme-dark\";\nimport { lightTheme } from \"./theme-light\";\n\nexport const themeCompartment = new Compartment();\n\nexport function getThemeExtension(theme: \"dark\" | \"light\"): Extension {\n return theme === \"dark\" ? darkTheme : lightTheme;\n}\n\nexport function buildExtensions(theme: \"dark\" | \"light\"): Extension[] {\n return [\n // Markdown language with GFM extensions\n markdown({ base: markdownLanguage }),\n\n // Undo/redo history\n history(),\n\n // Keyboard shortcuts: standard editing + history shortcuts\n keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),\n\n // Soft line wrapping\n EditorView.lineWrapping,\n\n // Spell check\n EditorView.contentAttributes.of({ spellcheck: \"true\" }),\n\n // Selection and cursor rendering\n drawSelection(),\n dropCursor(),\n\n // Allow rectangular selection with Alt+drag\n rectangularSelection(),\n crosshairCursor(),\n\n // Live-preview syntax decorations\n liveMarkdownDecorations,\n\n // Theme via Compartment (swappable at runtime)\n themeCompartment.of(getThemeExtension(theme)),\n ];\n}\n","// src/InlineMarkdownEditor.tsx\n\"use client\";\n\nimport * as React from \"react\";\nimport { EditorView, ViewUpdate } from \"@codemirror/view\";\nimport { EditorState } from \"@codemirror/state\";\nimport { buildExtensions, themeCompartment, getThemeExtension } from \"./editor\";\n\nexport type InlineMarkdownEditorProps = {\n /** Controlled markdown content */\n value: string;\n /** Called on every document change with the full new markdown string */\n onChange: (next: string) => void;\n /** Visual theme. Defaults to \"dark\". */\n theme?: \"dark\" | \"light\";\n /** Class applied to the outer container div */\n className?: string;\n /** Inline styles for the outer container div */\n style?: React.CSSProperties;\n /** Initial height. Defaults to \"100%\". Override with a px/vh value. */\n height?: string;\n};\n\nexport const InlineMarkdownEditor: React.FC<InlineMarkdownEditorProps> = ({\n value,\n onChange,\n theme = \"dark\",\n className,\n style,\n height = \"100%\",\n}) => {\n const containerRef = React.useRef<HTMLDivElement>(null);\n const viewRef = React.useRef<EditorView | null>(null);\n\n // Keep onChange stable in a ref so the CM6 listener never goes stale\n const onChangeRef = React.useRef(onChange);\n React.useLayoutEffect(() => { onChangeRef.current = onChange; });\n\n // Flag: was the last doc change initiated from inside CM6?\n // Used to skip the value-sync effect when we already have the latest content.\n const skipNextSync = React.useRef(false);\n\n // ── Mount the editor once ────────────────────────────────────────────\n React.useEffect(() => {\n if (!containerRef.current) return;\n\n const updateListener = EditorView.updateListener.of((update: ViewUpdate) => {\n if (update.docChanged) {\n skipNextSync.current = true;\n onChangeRef.current(update.state.doc.toString());\n }\n });\n\n const view = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [...buildExtensions(theme), updateListener],\n }),\n parent: containerRef.current,\n });\n\n viewRef.current = view;\n\n return () => {\n view.destroy();\n viewRef.current = null;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // intentionally empty — mount once\n\n // ── Sync external value changes into CM6 ────────────────────────────\n React.useEffect(() => {\n const view = viewRef.current;\n if (!view) return;\n\n // Skip if CM6 itself caused this value change\n if (skipNextSync.current) {\n skipNextSync.current = false;\n return;\n }\n\n const current = view.state.doc.toString();\n if (current !== value) {\n view.dispatch({\n changes: { from: 0, to: current.length, insert: value },\n // Don't push this onto the undo stack — it's an external change\n annotations: [],\n });\n }\n }, [value]);\n\n // ── Swap theme at runtime via Compartment (no remount needed) ────────\n React.useEffect(() => {\n const view = viewRef.current;\n if (!view) return;\n view.dispatch({\n effects: themeCompartment.reconfigure(getThemeExtension(theme)),\n });\n }, [theme]);\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{ height, ...style }}\n />\n );\n};\n"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type InlineMarkdownEditorProps = {
|
|
4
|
+
/** Controlled markdown content */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Called on every document change with the full new markdown string */
|
|
7
|
+
onChange: (next: string) => void;
|
|
8
|
+
/** Visual theme. Defaults to "dark". */
|
|
9
|
+
theme?: "dark" | "light";
|
|
10
|
+
/** Class applied to the outer container div */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Inline styles for the outer container div */
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
/** Initial height. Defaults to "100%". Override with a px/vh value. */
|
|
15
|
+
height?: string;
|
|
16
|
+
};
|
|
17
|
+
declare const InlineMarkdownEditor: React.FC<InlineMarkdownEditorProps>;
|
|
18
|
+
|
|
19
|
+
export { InlineMarkdownEditor, type InlineMarkdownEditorProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type InlineMarkdownEditorProps = {
|
|
4
|
+
/** Controlled markdown content */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Called on every document change with the full new markdown string */
|
|
7
|
+
onChange: (next: string) => void;
|
|
8
|
+
/** Visual theme. Defaults to "dark". */
|
|
9
|
+
theme?: "dark" | "light";
|
|
10
|
+
/** Class applied to the outer container div */
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Inline styles for the outer container div */
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
/** Initial height. Defaults to "100%". Override with a px/vh value. */
|
|
15
|
+
height?: string;
|
|
16
|
+
};
|
|
17
|
+
declare const InlineMarkdownEditor: React.FC<InlineMarkdownEditorProps>;
|
|
18
|
+
|
|
19
|
+
export { InlineMarkdownEditor, type InlineMarkdownEditorProps };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as m from'react';import {Decoration,ViewPlugin,EditorView,WidgetType,keymap,drawSelection,dropCursor,rectangularSelection,crosshairCursor}from'@codemirror/view';import {Compartment,EditorState}from'@codemirror/state';import {markdown,markdownLanguage}from'@codemirror/lang-markdown';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {syntaxTree}from'@codemirror/language';import {jsx}from'react/jsx-runtime';var p=Decoration.replace({}),k=class extends WidgetType{toDOM(){let n=document.createElement("span");return n.textContent="\u2022",n.className="ob-list-mark",n}eq(){return true}};function l(a,n,d){for(let t of a.selection.ranges)if(t.from>=n&&t.to<=d||t.from<=d&&t.to>=n)return true;return false}function g(a,n){let d=a.doc.lineAt(n);for(let t of a.selection.ranges)if(t.from>=d.from&&t.from<=d.to)return true;return false}function E(a){let{state:n}=a,d=[],t=(i,r,o)=>{i<r&&d.push({from:i,to:r,deco:o});},c=i=>Decoration.mark({class:i});return syntaxTree(n).cursor().iterate(i=>{let{name:r,from:o,to:e}=i;if(/^ATXHeading[1-6]$/.test(r)){let s=r.slice(-1);t(o,e,c(`ob-h${s}`));}if(r==="HeaderMark"&&(g(n,o)?t(o,e,c("ob-syntax")):t(o,e,p)),r==="StrongEmphasis"&&(l(n,o,e)||t(o,e,c("ob-bold"))),r==="Emphasis"&&(l(n,o,e)||t(o,e,c("ob-italic"))),r==="EmphasisMark"){let s=i.node.parent?.from??o,f=i.node.parent?.to??e;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Strikethrough"&&(l(n,o,e)||t(o,e,c("ob-strikethrough"))),r==="StrikethroughMark"){let s=i.node.parent?.from??o,f=i.node.parent?.to??e;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="InlineCode"&&(l(n,o,e)||t(o,e,c("ob-code"))),r==="CodeMark"&&i.node.parent?.name==="InlineCode"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Link"&&(l(n,o,e)||t(o,e,c("ob-link"))),r==="LinkMark"&&i.node.parent?.name==="Link"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="URL"&&i.node.parent?.name==="Link"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Image"&&(l(n,o,e)||t(o,e,c("ob-image"))),r==="LinkMark"&&i.node.parent?.name==="Image"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="URL"&&i.node.parent?.name==="Image"){let s=i.node.parent.from,f=i.node.parent.to;l(n,s,f)?t(o,e,c("ob-syntax")):t(o,e,p);}if(r==="Blockquote"&&t(o,e,c("ob-blockquote")),r==="BlockquoteMark"&&(g(n,o),t(o,e,c("ob-blockquote-mark"))),r==="ListMark"){let s=n.doc.sliceString(o,e);(s==="-"||s==="*"||s==="+")&&!g(n,o)?t(o,e,Decoration.replace({widget:new k})):t(o,e,c("ob-list-mark"));}r==="FencedCode"&&t(o,e,c("ob-code-block")),r==="CodeMark"&&i.node.parent?.name==="FencedCode"&&t(o,e,c("ob-fence-mark")),r==="CodeInfo"&&t(o,e,c("ob-code-info")),r==="HorizontalRule"&&t(o,e,c("ob-hr"));}),Decoration.set(d.map(({from:i,to:r,deco:o})=>o.range(i,r)),true)}var C=ViewPlugin.fromClass(class{constructor(a){this.decorations=E(a);}update(a){(a.docChanged||a.selectionSet||a.viewportChanged||syntaxTree(a.startState)!==syntaxTree(a.state))&&(this.decorations=E(a.view));}},{decorations:a=>a.decorations});var w=EditorView.theme({"&":{backgroundColor:"#1e1e2e",color:"#cdd6f4",fontFamily:"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif",fontSize:"16px",lineHeight:"1.7",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{padding:"24px 32px",caretColor:"#cdd6f4",maxWidth:"800px",margin:"0 auto"},".cm-focused":{outline:"none"},".cm-line":{padding:"1px 0"},".cm-cursor":{borderLeftColor:"#cdd6f4",borderLeftWidth:"2px"},".cm-selectionBackground, ::selection":{backgroundColor:"#313244 !important"},".ob-h1":{color:"#cba6f7",fontSize:"2em",fontWeight:"700",lineHeight:"1.3",marginBottom:"4px"},".ob-h2":{color:"#cba6f7",fontSize:"1.5em",fontWeight:"700",lineHeight:"1.3"},".ob-h3":{color:"#cba6f7",fontSize:"1.25em",fontWeight:"700",lineHeight:"1.3"},".ob-h4":{color:"#cba6f7",fontSize:"1.1em",fontWeight:"700"},".ob-h5":{color:"#cba6f7",fontWeight:"700"},".ob-h6":{color:"#a6adc8",fontWeight:"700"},".ob-bold":{fontWeight:"700",color:"#cdd6f4"},".ob-italic":{fontStyle:"italic",color:"#cdd6f4"},".ob-strikethrough":{textDecoration:"line-through",color:"#6c7086"},".ob-code":{color:"#f38ba8",backgroundColor:"#313244",borderRadius:"4px",padding:"1px 5px",fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"0.9em"},".ob-link":{color:"#89b4fa",textDecoration:"underline",cursor:"pointer"},".ob-link-text":{color:"#89b4fa"},".ob-syntax":{color:"#45475a",opacity:"0.7"},".ob-blockquote":{borderLeft:"3px solid #585b70",paddingLeft:"16px",color:"#9399b2",fontStyle:"italic"},".ob-blockquote-mark":{color:"#45475a"},".ob-list-mark":{color:"#89b4fa",fontWeight:"600"},".ob-hr":{color:"#45475a",letterSpacing:"4px"},".ob-code-block":{backgroundColor:"#181825",borderRadius:"6px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace",fontSize:"0.9em",color:"#cdd6f4"},".ob-fence-mark":{color:"#45475a"},".ob-code-info":{color:"#a6e3a1",fontSize:"0.8em"},".ob-image":{color:"#f9e2af"}},{dark:true});var M=EditorView.theme({"&":{backgroundColor:"#fafafa",color:"#1a1a1a",fontFamily:"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif",fontSize:"16px",lineHeight:"1.7",height:"100%"},".cm-scroller":{overflow:"auto"},".cm-content":{padding:"24px 32px",caretColor:"#1a1a1a",maxWidth:"800px",margin:"0 auto"},".cm-focused":{outline:"none"},".cm-line":{padding:"1px 0"},".cm-cursor":{borderLeftColor:"#1a1a1a",borderLeftWidth:"2px"},".cm-selectionBackground, ::selection":{backgroundColor:"#e5e7eb !important"},".ob-h1":{color:"#7c3aed",fontSize:"2em",fontWeight:"700",lineHeight:"1.3",marginBottom:"4px"},".ob-h2":{color:"#7c3aed",fontSize:"1.5em",fontWeight:"700",lineHeight:"1.3"},".ob-h3":{color:"#7c3aed",fontSize:"1.25em",fontWeight:"700",lineHeight:"1.3"},".ob-h4":{color:"#7c3aed",fontSize:"1.1em",fontWeight:"700"},".ob-h5":{color:"#7c3aed",fontWeight:"700"},".ob-h6":{color:"#9333ea",fontWeight:"700"},".ob-bold":{fontWeight:"700",color:"#1a1a1a"},".ob-italic":{fontStyle:"italic",color:"#1a1a1a"},".ob-strikethrough":{textDecoration:"line-through",color:"#9ca3af"},".ob-code":{color:"#dc2626",backgroundColor:"#f3f4f6",borderRadius:"4px",padding:"1px 5px",fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"0.9em"},".ob-link":{color:"#2563eb",textDecoration:"underline",cursor:"pointer"},".ob-link-text":{color:"#2563eb"},".ob-syntax":{color:"#d1d5db",opacity:"0.9"},".ob-blockquote":{borderLeft:"3px solid #d1d5db",paddingLeft:"16px",color:"#6b7280",fontStyle:"italic"},".ob-blockquote-mark":{color:"#d1d5db"},".ob-list-mark":{color:"#2563eb",fontWeight:"600"},".ob-hr":{color:"#d1d5db",letterSpacing:"4px"},".ob-code-block":{backgroundColor:"#f3f4f6",borderRadius:"6px",fontFamily:"'JetBrains Mono', 'Fira Code', monospace",fontSize:"0.9em",color:"#1a1a1a"},".ob-fence-mark":{color:"#d1d5db"},".ob-code-info":{color:"#16a34a",fontSize:"0.8em"},".ob-image":{color:"#d97706"}},{dark:false});var x=new Compartment;function S(a){return a==="dark"?w:M}function F(a){return [markdown({base:markdownLanguage}),history(),keymap.of([...defaultKeymap,...historyKeymap,indentWithTab]),EditorView.lineWrapping,EditorView.contentAttributes.of({spellcheck:"true"}),drawSelection(),dropCursor(),rectangularSelection(),crosshairCursor(),C,x.of(S(a))]}var $=({value:a,onChange:n,theme:d="dark",className:t,style:c,height:i="100%"})=>{let r=m.useRef(null),o=m.useRef(null),e=m.useRef(n);m.useLayoutEffect(()=>{e.current=n;});let s=m.useRef(false);return m.useEffect(()=>{if(!r.current)return;let f=EditorView.updateListener.of(y=>{y.docChanged&&(s.current=true,e.current(y.state.doc.toString()));}),b=new EditorView({state:EditorState.create({doc:a,extensions:[...F(d),f]}),parent:r.current});return o.current=b,()=>{b.destroy(),o.current=null;}},[]),m.useEffect(()=>{let f=o.current;if(!f)return;if(s.current){s.current=false;return}let b=f.state.doc.toString();b!==a&&f.dispatch({changes:{from:0,to:b.length,insert:a},annotations:[]});},[a]),m.useEffect(()=>{let f=o.current;f&&f.dispatch({effects:x.reconfigure(S(d))});},[d]),jsx("div",{ref:r,className:t,style:{height:i,...c}})};export{$ as InlineMarkdownEditor};//# sourceMappingURL=index.mjs.map
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorations.ts","../src/theme-dark.ts","../src/theme-light.ts","../src/editor.ts","../src/InlineMarkdownEditor.tsx"],"names":["HIDE","Decoration","BulletWidget","WidgetType","s","isCursorInRange","state","from","to","range","isCursorOnLine","line","buildDecorations","view","entries","add","deco","mark","cls","syntaxTree","node","name","level","parentFrom","parentTo","markText","liveMarkdownDecorations","ViewPlugin","update","instance","darkTheme","EditorView","lightTheme","themeCompartment","Compartment","getThemeExtension","theme","buildExtensions","markdown","markdownLanguage","history","keymap","defaultKeymap","historyKeymap","indentWithTab","drawSelection","dropCursor","rectangularSelection","crosshairCursor","InlineMarkdownEditor","value","onChange","className","style","height","containerRef","viewRef","onChangeRef","skipNextSync","updateListener","EditorState","current","jsx"],"mappings":"ycAgBA,IAAMA,CAAAA,CAAOC,WAAW,OAAA,CAAQ,EAAE,CAAA,CAG5BC,CAAAA,CAAN,cAA2BC,UAAW,CACpC,OAAqB,CACnB,IAAMC,EAAI,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA,CACvC,OAAAA,EAAE,WAAA,CAAc,QAAA,CAChBA,EAAE,SAAA,CAAY,cAAA,CACPA,CACT,CACA,EAAA,EAAc,CACZ,OAAO,KACT,CACF,CAAA,CAIA,SAASC,EAAgBC,CAAAA,CAAoBC,CAAAA,CAAcC,EAAqB,CAC9E,IAAA,IAAWC,KAASH,CAAAA,CAAM,SAAA,CAAU,OAElC,GADIG,CAAAA,CAAM,MAAQF,CAAAA,EAAQE,CAAAA,CAAM,IAAMD,CAAAA,EAClCC,CAAAA,CAAM,MAAQD,CAAAA,EAAMC,CAA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ACX,KAAA,CAAO,CAAE,OAAAE,CAAAA,CAAQ,GAAGD,CAAM,CAAA,CAC5B,CAEJ","file":"index.mjs","sourcesContent":["// src/decorations.ts\nimport {\n ViewPlugin,\n DecorationSet,\n Decoration,\n ViewUpdate,\n WidgetType,\n EditorView,\n} from \"@codemirror/view\";\nimport { syntaxTree } from \"@codemirror/language\";\nimport { EditorState } from \"@codemirror/state\";\n\n// A widgetless replace decoration collapses the range out of layout entirely —\n// the same mechanism code-folding uses. A display:none widget would instead\n// leave a DOM node whose getBoundingClientRect is all-zeros, which breaks\n// posAtCoords hit-testing and makes vertical cursor motion skip lines.\nconst HIDE = Decoration.replace({});\n\n// Renders a list marker (-, *, +) as a typographic bullet.\nclass BulletWidget extends WidgetType {\n toDOM(): HTMLElement {\n const s = document.createElement(\"span\");\n s.textContent = \"•\";\n s.className = \"ob-list-mark\";\n return s;\n }\n eq(): boolean {\n return true;\n }\n}\n\ntype DecoEntry = { from: number; to: number; deco: Decoration };\n\nfunction isCursorInRange(state: EditorState, from: number, to: number): boolean {\n for (const range of state.selection.ranges) {\n if (range.from >= from && range.to <= to) return true;\n if (range.from <= to && range.to >= from) return true;\n }\n return false;\n}\n\nfunction isCursorOnLine(state: EditorState, from: number): boolean {\n const line = state.doc.lineAt(from);\n for (const range of state.selection.ranges) {\n if (range.from >= line.from && range.from <= line.to) return true;\n }\n return false;\n}\n\nfunction buildDecorations(view: EditorView): DecorationSet {\n const { state } = view;\n const entries: DecoEntry[] = [];\n\n const add = (from: number, to: number, deco: Decoration) => {\n if (from < to) entries.push({ from, to, deco });\n };\n\n const mark = (cls: string) => Decoration.mark({ class: cls });\n\n syntaxTree(state).cursor().iterate((node) => {\n const { name, from, to } = node;\n\n // ── ATX Headings ──────────────────────────────────────────────────────\n // Level derived from node name: ATXHeading1 → h1, etc.\n if (/^ATXHeading[1-6]$/.test(name)) {\n const level = name.slice(-1); // \"1\"–\"6\"\n add(from, to, mark(`ob-h${level}`));\n }\n\n // HeaderMark = the leading `# ` characters in ATX headings\n if (name === \"HeaderMark\") {\n if (isCursorOnLine(state, from)) {\n add(from, to, mark(\"ob-syntax\")); // show dimmed\n } else {\n add(from, to, HIDE); // hide when cursor is elsewhere\n }\n }\n\n // ── Strong emphasis (bold): **text** or __text__ ───────────────────\n if (name === \"StrongEmphasis\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-bold\"));\n }\n }\n\n // ── Emphasis (italic): *text* or _text_ ────────────────────────────\n if (name === \"Emphasis\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-italic\"));\n }\n }\n\n // EmphasisMark = ** / * / __ / _ markers (shared by bold and italic)\n if (name === \"EmphasisMark\") {\n const parentFrom = node.node.parent?.from ?? from;\n const parentTo = node.node.parent?.to ?? to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\")); // show dimmed\n } else {\n add(from, to, HIDE); // hide\n }\n }\n\n // ── Strikethrough: ~~text~~ (GFM) ─────────────────────────────────\n if (name === \"Strikethrough\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-strikethrough\"));\n }\n }\n if (name === \"StrikethroughMark\") {\n const parentFrom = node.node.parent?.from ?? from;\n const parentTo = node.node.parent?.to ?? to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n\n // ── Inline code: `code` ───────────────────────────────────────────\n if (name === \"InlineCode\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-code\"));\n }\n }\n // CodeMark inside InlineCode = the backtick(s)\n if (name === \"CodeMark\" && node.node.parent?.name === \"InlineCode\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n\n // ── Links: [text](url) ────────────────────────────────────────────\n if (name === \"Link\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-link\"));\n }\n }\n // LinkMark = [ ] ( ) characters in links\n if (name === \"LinkMark\" && node.node.parent?.name === \"Link\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n // URL inside Link (the url part) — hide when cursor away\n if (name === \"URL\" && node.node.parent?.name === \"Link\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (!isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, HIDE);\n } else {\n add(from, to, mark(\"ob-syntax\"));\n }\n }\n\n // ── Images:  ──────────────────────────────────────────\n if (name === \"Image\") {\n if (!isCursorInRange(state, from, to)) {\n add(from, to, mark(\"ob-image\"));\n }\n }\n if (name === \"LinkMark\" && node.node.parent?.name === \"Image\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, mark(\"ob-syntax\"));\n } else {\n add(from, to, HIDE);\n }\n }\n if (name === \"URL\" && node.node.parent?.name === \"Image\") {\n const parentFrom = node.node.parent.from;\n const parentTo = node.node.parent.to;\n if (!isCursorInRange(state, parentFrom, parentTo)) {\n add(from, to, HIDE);\n } else {\n add(from, to, mark(\"ob-syntax\"));\n }\n }\n\n // ── Blockquote ────────────────────────────────────────────────────\n if (name === \"Blockquote\") {\n add(from, to, mark(\"ob-blockquote\"));\n }\n if (name === \"BlockquoteMark\") {\n if (isCursorOnLine(state, from)) {\n add(from, to, mark(\"ob-blockquote-mark\"));\n } else {\n add(from, to, mark(\"ob-blockquote-mark\")); // always show `>` but styled\n }\n }\n\n // ── List markers ─────────────────────────────────────────────────\n if (name === \"ListMark\") {\n const markText = state.doc.sliceString(from, to);\n const isBullet =\n markText === \"-\" || markText === \"*\" || markText === \"+\";\n if (isBullet && !isCursorOnLine(state, from)) {\n add(from, to, Decoration.replace({ widget: new BulletWidget() }));\n } else {\n add(from, to, mark(\"ob-list-mark\"));\n }\n }\n\n // ── Fenced code blocks ───────────────────────────────────────────\n if (name === \"FencedCode\") {\n add(from, to, mark(\"ob-code-block\"));\n }\n // CodeMark inside FencedCode = the ``` or ~~~ fence lines\n if (name === \"CodeMark\" && node.node.parent?.name === \"FencedCode\") {\n add(from, to, mark(\"ob-fence-mark\"));\n }\n // CodeInfo = language specifier after opening fence\n if (name === \"CodeInfo\") {\n add(from, to, mark(\"ob-code-info\"));\n }\n\n // ── Horizontal rule ──────────────────────────────────────────────\n if (name === \"HorizontalRule\") {\n add(from, to, mark(\"ob-hr\"));\n }\n });\n\n // Decoration.set sorts by `from` AND `startSide` — RangeSetBuilder cannot,\n // since mark and replace decorations carry different sides at the same offset.\n return Decoration.set(\n entries.map(({ from, to, deco }) => deco.range(from, to)),\n true\n );\n}\n\nexport const liveMarkdownDecorations = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = buildDecorations(view);\n }\n\n update(update: ViewUpdate) {\n // Rebuild on background-parse progress too: syntaxTree() returns a new\n // tree as the parser advances, and the initial mount often only has the\n // first viewport parsed — without this, off-screen lines never decorate.\n if (\n update.docChanged ||\n update.selectionSet ||\n update.viewportChanged ||\n syntaxTree(update.startState) !== syntaxTree(update.state)\n ) {\n this.decorations = buildDecorations(update.view);\n }\n }\n },\n { decorations: (instance) => instance.decorations }\n);\n","// src/theme-dark.ts\nimport { EditorView } from \"@codemirror/view\";\nimport { Extension } from \"@codemirror/state\";\n\nexport const darkTheme: Extension = EditorView.theme(\n {\n \"&\": {\n backgroundColor: \"#1e1e2e\",\n color: \"#cdd6f4\",\n fontFamily:\n \"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif\",\n fontSize: \"16px\",\n lineHeight: \"1.7\",\n height: \"100%\",\n },\n \".cm-scroller\": { overflow: \"auto\" },\n \".cm-content\": {\n padding: \"24px 32px\",\n caretColor: \"#cdd6f4\",\n maxWidth: \"800px\",\n margin: \"0 auto\",\n },\n \".cm-focused\": { outline: \"none\" },\n \".cm-line\": { padding: \"1px 0\" },\n \".cm-cursor\": { borderLeftColor: \"#cdd6f4\", borderLeftWidth: \"2px\" },\n \".cm-selectionBackground, ::selection\": {\n backgroundColor: \"#313244 !important\",\n },\n // Headings\n \".ob-h1\": {\n color: \"#cba6f7\",\n fontSize: \"2em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n marginBottom: \"4px\",\n },\n \".ob-h2\": {\n color: \"#cba6f7\",\n fontSize: \"1.5em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n },\n \".ob-h3\": {\n color: \"#cba6f7\",\n fontSize: \"1.25em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n },\n \".ob-h4\": { color: \"#cba6f7\", fontSize: \"1.1em\", fontWeight: \"700\" },\n \".ob-h5\": { color: \"#cba6f7\", fontWeight: \"700\" },\n \".ob-h6\": { color: \"#a6adc8\", fontWeight: \"700\" },\n // Inline formatting\n \".ob-bold\": { fontWeight: \"700\", color: \"#cdd6f4\" },\n \".ob-italic\": { fontStyle: \"italic\", color: \"#cdd6f4\" },\n \".ob-strikethrough\": { textDecoration: \"line-through\", color: \"#6c7086\" },\n \".ob-code\": {\n color: \"#f38ba8\",\n backgroundColor: \"#313244\",\n borderRadius: \"4px\",\n padding: \"1px 5px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace\",\n fontSize: \"0.9em\",\n },\n \".ob-link\": { color: \"#89b4fa\", textDecoration: \"underline\", cursor: \"pointer\" },\n \".ob-link-text\": { color: \"#89b4fa\" },\n // Syntax markers (shown dimmed when cursor is active in the span)\n \".ob-syntax\": { color: \"#45475a\", opacity: \"0.7\" },\n // Blockquote\n \".ob-blockquote\": {\n borderLeft: \"3px solid #585b70\",\n paddingLeft: \"16px\",\n color: \"#9399b2\",\n fontStyle: \"italic\",\n },\n \".ob-blockquote-mark\": { color: \"#45475a\" },\n // List markers\n \".ob-list-mark\": { color: \"#89b4fa\", fontWeight: \"600\" },\n // Horizontal rule\n \".ob-hr\": { color: \"#45475a\", letterSpacing: \"4px\" },\n // Code block (fenced)\n \".ob-code-block\": {\n backgroundColor: \"#181825\",\n borderRadius: \"6px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', monospace\",\n fontSize: \"0.9em\",\n color: \"#cdd6f4\",\n },\n \".ob-fence-mark\": { color: \"#45475a\" },\n \".ob-code-info\": { color: \"#a6e3a1\", fontSize: \"0.8em\" },\n // Image alt text\n \".ob-image\": { color: \"#f9e2af\" },\n },\n { dark: true }\n);\n","// src/theme-light.ts\nimport { EditorView } from \"@codemirror/view\";\nimport { Extension } from \"@codemirror/state\";\n\nexport const lightTheme: Extension = EditorView.theme(\n {\n \"&\": {\n backgroundColor: \"#fafafa\",\n color: \"#1a1a1a\",\n fontFamily:\n \"'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, system-ui, sans-serif\",\n fontSize: \"16px\",\n lineHeight: \"1.7\",\n height: \"100%\",\n },\n \".cm-scroller\": { overflow: \"auto\" },\n \".cm-content\": {\n padding: \"24px 32px\",\n caretColor: \"#1a1a1a\",\n maxWidth: \"800px\",\n margin: \"0 auto\",\n },\n \".cm-focused\": { outline: \"none\" },\n \".cm-line\": { padding: \"1px 0\" },\n \".cm-cursor\": { borderLeftColor: \"#1a1a1a\", borderLeftWidth: \"2px\" },\n \".cm-selectionBackground, ::selection\": {\n backgroundColor: \"#e5e7eb !important\",\n },\n // Headings\n \".ob-h1\": {\n color: \"#7c3aed\",\n fontSize: \"2em\",\n fontWeight: \"700\",\n lineHeight: \"1.3\",\n marginBottom: \"4px\",\n },\n \".ob-h2\": { color: \"#7c3aed\", fontSize: \"1.5em\", fontWeight: \"700\", lineHeight: \"1.3\" },\n \".ob-h3\": { color: \"#7c3aed\", fontSize: \"1.25em\", fontWeight: \"700\", lineHeight: \"1.3\" },\n \".ob-h4\": { color: \"#7c3aed\", fontSize: \"1.1em\", fontWeight: \"700\" },\n \".ob-h5\": { color: \"#7c3aed\", fontWeight: \"700\" },\n \".ob-h6\": { color: \"#9333ea\", fontWeight: \"700\" },\n // Inline formatting\n \".ob-bold\": { fontWeight: \"700\", color: \"#1a1a1a\" },\n \".ob-italic\": { fontStyle: \"italic\", color: \"#1a1a1a\" },\n \".ob-strikethrough\": { textDecoration: \"line-through\", color: \"#9ca3af\" },\n \".ob-code\": {\n color: \"#dc2626\",\n backgroundColor: \"#f3f4f6\",\n borderRadius: \"4px\",\n padding: \"1px 5px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace\",\n fontSize: \"0.9em\",\n },\n \".ob-link\": { color: \"#2563eb\", textDecoration: \"underline\", cursor: \"pointer\" },\n \".ob-link-text\": { color: \"#2563eb\" },\n // Syntax markers (dimmed when cursor is in span)\n \".ob-syntax\": { color: \"#d1d5db\", opacity: \"0.9\" },\n // Blockquote\n \".ob-blockquote\": {\n borderLeft: \"3px solid #d1d5db\",\n paddingLeft: \"16px\",\n color: \"#6b7280\",\n fontStyle: \"italic\",\n },\n \".ob-blockquote-mark\": { color: \"#d1d5db\" },\n // List markers\n \".ob-list-mark\": { color: \"#2563eb\", fontWeight: \"600\" },\n // Horizontal rule\n \".ob-hr\": { color: \"#d1d5db\", letterSpacing: \"4px\" },\n // Code block (fenced)\n \".ob-code-block\": {\n backgroundColor: \"#f3f4f6\",\n borderRadius: \"6px\",\n fontFamily: \"'JetBrains Mono', 'Fira Code', monospace\",\n fontSize: \"0.9em\",\n color: \"#1a1a1a\",\n },\n \".ob-fence-mark\": { color: \"#d1d5db\" },\n \".ob-code-info\": { color: \"#16a34a\", fontSize: \"0.8em\" },\n // Image\n \".ob-image\": { color: \"#d97706\" },\n },\n { dark: false }\n);\n","// src/editor.ts\nimport { markdown, markdownLanguage } from \"@codemirror/lang-markdown\";\nimport { history, defaultKeymap, historyKeymap, indentWithTab } from \"@codemirror/commands\";\nimport { EditorView, keymap, drawSelection, dropCursor, rectangularSelection, crosshairCursor } from \"@codemirror/view\";\nimport { EditorState, Extension, Compartment } from \"@codemirror/state\";\nimport { liveMarkdownDecorations } from \"./decorations\";\nimport { darkTheme } from \"./theme-dark\";\nimport { lightTheme } from \"./theme-light\";\n\nexport const themeCompartment = new Compartment();\n\nexport function getThemeExtension(theme: \"dark\" | \"light\"): Extension {\n return theme === \"dark\" ? darkTheme : lightTheme;\n}\n\nexport function buildExtensions(theme: \"dark\" | \"light\"): Extension[] {\n return [\n // Markdown language with GFM extensions\n markdown({ base: markdownLanguage }),\n\n // Undo/redo history\n history(),\n\n // Keyboard shortcuts: standard editing + history shortcuts\n keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),\n\n // Soft line wrapping\n EditorView.lineWrapping,\n\n // Spell check\n EditorView.contentAttributes.of({ spellcheck: \"true\" }),\n\n // Selection and cursor rendering\n drawSelection(),\n dropCursor(),\n\n // Allow rectangular selection with Alt+drag\n rectangularSelection(),\n crosshairCursor(),\n\n // Live-preview syntax decorations\n liveMarkdownDecorations,\n\n // Theme via Compartment (swappable at runtime)\n themeCompartment.of(getThemeExtension(theme)),\n ];\n}\n","// src/InlineMarkdownEditor.tsx\n\"use client\";\n\nimport * as React from \"react\";\nimport { EditorView, ViewUpdate } from \"@codemirror/view\";\nimport { EditorState } from \"@codemirror/state\";\nimport { buildExtensions, themeCompartment, getThemeExtension } from \"./editor\";\n\nexport type InlineMarkdownEditorProps = {\n /** Controlled markdown content */\n value: string;\n /** Called on every document change with the full new markdown string */\n onChange: (next: string) => void;\n /** Visual theme. Defaults to \"dark\". */\n theme?: \"dark\" | \"light\";\n /** Class applied to the outer container div */\n className?: string;\n /** Inline styles for the outer container div */\n style?: React.CSSProperties;\n /** Initial height. Defaults to \"100%\". Override with a px/vh value. */\n height?: string;\n};\n\nexport const InlineMarkdownEditor: React.FC<InlineMarkdownEditorProps> = ({\n value,\n onChange,\n theme = \"dark\",\n className,\n style,\n height = \"100%\",\n}) => {\n const containerRef = React.useRef<HTMLDivElement>(null);\n const viewRef = React.useRef<EditorView | null>(null);\n\n // Keep onChange stable in a ref so the CM6 listener never goes stale\n const onChangeRef = React.useRef(onChange);\n React.useLayoutEffect(() => { onChangeRef.current = onChange; });\n\n // Flag: was the last doc change initiated from inside CM6?\n // Used to skip the value-sync effect when we already have the latest content.\n const skipNextSync = React.useRef(false);\n\n // ── Mount the editor once ────────────────────────────────────────────\n React.useEffect(() => {\n if (!containerRef.current) return;\n\n const updateListener = EditorView.updateListener.of((update: ViewUpdate) => {\n if (update.docChanged) {\n skipNextSync.current = true;\n onChangeRef.current(update.state.doc.toString());\n }\n });\n\n const view = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [...buildExtensions(theme), updateListener],\n }),\n parent: containerRef.current,\n });\n\n viewRef.current = view;\n\n return () => {\n view.destroy();\n viewRef.current = null;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // intentionally empty — mount once\n\n // ── Sync external value changes into CM6 ────────────────────────────\n React.useEffect(() => {\n const view = viewRef.current;\n if (!view) return;\n\n // Skip if CM6 itself caused this value change\n if (skipNextSync.current) {\n skipNextSync.current = false;\n return;\n }\n\n const current = view.state.doc.toString();\n if (current !== value) {\n view.dispatch({\n changes: { from: 0, to: current.length, insert: value },\n // Don't push this onto the undo stack — it's an external change\n annotations: [],\n });\n }\n }, [value]);\n\n // ── Swap theme at runtime via Compartment (no remount needed) ────────\n React.useEffect(() => {\n const view = viewRef.current;\n if (!view) return;\n view.dispatch({\n effects: themeCompartment.reconfigure(getThemeExtension(theme)),\n });\n }, [theme]);\n\n return (\n <div\n ref={containerRef}\n className={className}\n style={{ height, ...style }}\n />\n );\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-inline-markdown-editor",
|
|
3
|
+
"version": "2.0.4",
|
|
4
|
+
"description": "A React markdown editor with live preview, built on CodeMirror 6 — syntax markers reveal only on the active line.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"markdown",
|
|
8
|
+
"editor",
|
|
9
|
+
"codemirror",
|
|
10
|
+
"live-preview",
|
|
11
|
+
"wysiwyg"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Anas Syed",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/anasyd/react-inline-markdown-editor.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/anasyd/react-inline-markdown-editor/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/anasyd/react-inline-markdown-editor#readme",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": ">=18",
|
|
40
|
+
"react-dom": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tailwindcss/typography": "^0.5.16",
|
|
44
|
+
"@types/node": "^24.3.1",
|
|
45
|
+
"@types/react": "^19.2.15",
|
|
46
|
+
"@types/react-dom": "^19.2.3",
|
|
47
|
+
"react": "^19.2.6",
|
|
48
|
+
"react-dom": "^19.2.6",
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup src/index.ts --dts --format cjs,esm --sourcemap --clean",
|
|
54
|
+
"prepublishOnly": "npm run build"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@codemirror/commands": "^6.10.3",
|
|
58
|
+
"@codemirror/lang-markdown": "^6.5.0",
|
|
59
|
+
"@codemirror/language": "^6.12.3",
|
|
60
|
+
"@codemirror/state": "^6.6.0",
|
|
61
|
+
"@codemirror/view": "^6.43.0"
|
|
62
|
+
}
|
|
63
|
+
}
|