@meowdown/core 0.1.0 → 0.2.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.
- package/dist/index.d.ts +82 -4
- package/dist/index.js +14 -1
- package/dist/style.css +194 -0
- package/package.json +17 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Editor, PlainExtension } from "@prosekit/core";
|
|
2
|
+
import { ProseMirrorNode } from "@prosekit/pm/model";
|
|
3
|
+
|
|
4
|
+
//#region src/extensions/extension.d.ts
|
|
5
|
+
declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<readonly [import("@prosekit/extensions/paragraph").ParagraphExtension, import("@prosekit/extensions/doc").DocExtension, import("@prosekit/extensions/text").TextExtension, import("@prosekit/extensions/blockquote").BlockquoteExtension, import("@prosekit/extensions/list").ListExtension, import("@prosekit/extensions/heading").HeadingExtension, import("@prosekit/extensions/table").TableExtension, import("@prosekit/extensions/code-block").CodeBlockExtension, import("@prosekit/extensions/horizontal-rule").HorizontalRuleExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
|
|
6
|
+
Marks: {
|
|
7
|
+
mdMark: import("@prosekit/pm/model").Attrs;
|
|
8
|
+
};
|
|
9
|
+
}>, import("@prosekit/core").Extension<{
|
|
10
|
+
Marks: {
|
|
11
|
+
mdEm: import("@prosekit/pm/model").Attrs;
|
|
12
|
+
};
|
|
13
|
+
}>, import("@prosekit/core").Extension<{
|
|
14
|
+
Marks: {
|
|
15
|
+
mdStrong: import("@prosekit/pm/model").Attrs;
|
|
16
|
+
};
|
|
17
|
+
}>, import("@prosekit/core").Extension<{
|
|
18
|
+
Marks: {
|
|
19
|
+
mdCode: import("@prosekit/pm/model").Attrs;
|
|
20
|
+
};
|
|
21
|
+
}>, import("@prosekit/core").Extension<{
|
|
22
|
+
Marks: {
|
|
23
|
+
mdLinkText: {
|
|
24
|
+
href: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}>, import("@prosekit/core").Extension<{
|
|
28
|
+
Marks: {
|
|
29
|
+
mdLinkUri: import("@prosekit/pm/model").Attrs;
|
|
30
|
+
};
|
|
31
|
+
}>, import("@prosekit/core").Extension<{
|
|
32
|
+
Marks: {
|
|
33
|
+
mdDel: import("@prosekit/pm/model").Attrs;
|
|
34
|
+
};
|
|
35
|
+
}>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>;
|
|
36
|
+
type EditorExtension = ReturnType<typeof defineEditorExtensionImpl>;
|
|
37
|
+
declare function defineEditorExtension(): EditorExtension;
|
|
38
|
+
type TypedEditor = Editor<EditorExtension>;
|
|
4
39
|
//#endregion
|
|
5
|
-
|
|
40
|
+
//#region src/extensions/mark-mode.d.ts
|
|
41
|
+
/**
|
|
42
|
+
* Controls how markdown syntax characters are rendered and how the
|
|
43
|
+
* editor serializes content to the clipboard.
|
|
44
|
+
*
|
|
45
|
+
* - 'hide': syntax chars never visible; copy strips them.
|
|
46
|
+
* - 'focus': syntax chars hidden by default; revealed near cursor; copy strips them.
|
|
47
|
+
* - 'show': syntax chars always visible (dim grey); copy keeps them.
|
|
48
|
+
*/
|
|
49
|
+
type MarkMode = 'hide' | 'focus' | 'show';
|
|
50
|
+
declare function defineMarkMode(mode: MarkMode): PlainExtension;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/converters/pm-to-md.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* Convert a ProseMirror document into a Markdown string.
|
|
55
|
+
*
|
|
56
|
+
* Performance design:
|
|
57
|
+
* - Output accumulates in a `string[]` buffer; joined once at the end.
|
|
58
|
+
* Avoids per-block intermediate strings while keeping the
|
|
59
|
+
* function-per-node-type readability of a switch dispatch.
|
|
60
|
+
* - Indent stack lives as a mutable `linePrefix` on the buffer object,
|
|
61
|
+
* restored via local variables across nested calls - no fresh
|
|
62
|
+
* context objects per recursion.
|
|
63
|
+
* - Inline content is walked directly (not via `node.textContent`) to
|
|
64
|
+
* skip one intermediate string allocation per leaf block.
|
|
65
|
+
* - Backtick fence width and cell escaping use single linear loops, no
|
|
66
|
+
* regex on the hot path.
|
|
67
|
+
*/
|
|
68
|
+
declare function docToMarkdown(node: ProseMirrorNode): string;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/converters/md-to-pm.d.ts
|
|
71
|
+
/**
|
|
72
|
+
* Convert a markdown string into a ProseMirror document node, built against
|
|
73
|
+
* the schema of the given editor.
|
|
74
|
+
*
|
|
75
|
+
* The output follows the extension set defined in `./prosekit.ts` (doc,
|
|
76
|
+
* paragraph, text, heading, blockquote, list, codeBlock, table, tableRow,
|
|
77
|
+
* tableCell, tableHeaderCell, horizontalRule). The function does not produce
|
|
78
|
+
* inline marks because `prosekit.ts` doesn't register any - emphasis / link /
|
|
79
|
+
* inline-code characters survive as literal text.
|
|
80
|
+
*/
|
|
81
|
+
declare function markdownToDoc(editor: TypedEditor, markdown: string): ProseMirrorNode;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { type EditorExtension, type MarkMode, type TypedEditor, defineEditorExtension, defineMarkMode, docToMarkdown, markdownToDoc };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
const e=1,t=2;
|
|
1
|
+
import{defineBaseCommands as e,defineBaseKeymap as t,defineHistory as n,defineMarkSpec as r,definePlugin as i,union as a}from"@prosekit/core";import{defineBlockquote as o}from"@prosekit/extensions/blockquote";import{defineCodeBlock as s}from"@prosekit/extensions/code-block";import{defineDoc as c}from"@prosekit/extensions/doc";import{defineGapCursor as l}from"@prosekit/extensions/gap-cursor";import{defineHeading as u}from"@prosekit/extensions/heading";import{defineHorizontalRule as d}from"@prosekit/extensions/horizontal-rule";import{defineList as ee}from"@prosekit/extensions/list";import{defineModClickPrevention as te}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as f}from"@prosekit/extensions/paragraph";import{defineTable as p}from"@prosekit/extensions/table";import{defineText as m}from"@prosekit/extensions/text";import{defineVirtualSelection as ne}from"@prosekit/extensions/virtual-selection";import{Plugin as h,PluginKey as g}from"@prosekit/pm/state";import{ReplaceStep as re,Step as _,StepResult as v,Transform as y}from"@prosekit/pm/transform";import{Mark as b}from"@prosekit/pm/model";import{GFM as x,parser as ie}from"@lezer/markdown";import{Decoration as ae,DecorationSet as S}from"@prosekit/pm/view";function oe(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function se(e,t){let[n,r,i]=t;return[n,r,i.map(t=>b.fromJSON(e,t))]}var C=class e extends _{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return v.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new y(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new y(e),n.addMark(i,c,t));return!1})}return v.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return ce;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new re(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(oe)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>se(t,e)))}};_.jsonID(`batchSetMark`,C);const ce=new C([]);function le(e){return e.end}const w=ie.configure([x]),ue=w.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:le}]});function de(e){return w.parseInline(e,0)}function fe(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const T=fe(w);function E(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}const D=new Map([[T.Emphasis,`mdEm`],[T.StrongEmphasis,`mdStrong`],[T.InlineCode,`mdCode`],[T.Strikethrough,`mdDel`],[T.EmphasisMark,`mdMark`],[T.CodeMark,`mdMark`],[T.LinkMark,`mdMark`],[T.StrikethroughMark,`mdMark`],[T.URL,`mdLinkUri`]]);function O(e,t){let n=de(t),r=[];return k(n,[],0,t.length,t,e,r),r}function k(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&j(o,s,n.from,t),n.type===T.Link||n.type===T.Image)A(n,t,i,a,o);else{let e=D.get(n.type),r=e?[...t,a.marks[e].create()]:t;n.children.length===0?j(o,n.from,n.to,r):k(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&j(o,s,r,t)}function A(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===T.LinkMark?(s++,s===2&&(a=t.from)):t.type===T.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c&&r.marks.mdLinkText?r.marks.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=e.from;for(let a of e.children){if(a.from>d){let e=u(d)?[...t,l]:t;j(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=D.get(a.type),s=o?[...e,r.marks[o].create()]:e;a.children.length===0?j(i,a.from,a.to,s):k(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&j(i,d,e.to,t)}function j(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&E(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const M=`inline-marks-applied`,N=new WeakMap;let P=0,F=0;function I(e,t,n){let r=N.get(e);if(r?F++:(P++,r=O(n,e.textContent),N.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function L(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function R(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=I(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function z(){return new h({key:new g(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(M))return null;let r=R(n,L(e,n));if(r.length===0)return null;let i=n.tr.step(new C(r));return i.setMeta(M,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(B(e.state)),{}}})}function B(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function V(){return i(z())}function pe(){return r({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function me(){return r({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function he(){return r({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function ge(){return r({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function _e(){return r({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function ve(){return r({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function ye(){return r({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function be(){return a(pe(),me(),he(),ge(),_e(),ve(),ye())}function xe(){return a(f(),c(),m(),o(),ee(),u(),p(),s(),d(),be(),V(),t(),e(),n(),l(),ne(),te())}function Se(){return xe()}const Ce=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`]),we=new Set([`mdMark`,`mdLinkUri`]),Te=new Set([`mdMark`,`mdLinkUri`]),H=new Set([`mdLinkText`,`mdLinkUri`]),Ee=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`]);function De(e){return new h({key:new g(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>Ae(e):void 0,clipboardTextSerializer:e===`show`?void 0:ke}})}function Oe(e){return i(De(e))}function ke(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Te.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
|
|
2
|
+
`)}function Ae(e){let{$anchor:t,empty:n}=e.selection;if(!n)return S.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=je(r,a);if(o.size===0)return S.empty;let s=[],c=new Set,l=!1;for(let e of o)if(H.has(e)){if(l)continue;l=!0,Ne(r,i,a,s,c)}else Me(r,i,e,a,s,c);let u=s.map(([e,t])=>ae.inline(e,t,{class:`show`}));return S.create(e.doc,u)}function je(e,t){let n=new Set,r=0;return e.forEach(e=>{let i=r+e.nodeSize;if(t>=r&&t<=i)for(let t of e.marks){let e=t.type.name;Ce.has(e)&&n.add(e)}r=i}),n}function Me(e,t,n,r,i,a){let o=t,s=0,c=-1,l=-1;e.forEach(u=>{let d=u.marks.some(e=>e.type.name===n);d&&c===-1&&(c=o,l=s),!d&&c!==-1&&(r>=l&&r<=s&&W(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&W(e,t,c,o,i,a)}function Ne(e,t,n,r,i){let a=e.childCount;if(a===0)return;let o=-1,s=0;for(let t=0;t<a;t++){let r=e.child(t),i=s+r.nodeSize;if(n>=s&&n<=i&&r.marks.some(e=>H.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&U(e.child(c-1));)c--;let l=o;for(;l<a-1&&U(e.child(l+1));)l++;let u=t;for(let t=0;t<c;t++)u+=e.child(t).nodeSize;let d=u;for(let t=c;t<=l;t++)d+=e.child(t).nodeSize;W(e,t,u,d,r,i)}function U(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:H.has(e)?n=!0:Ee.has(e)&&(r=!0)}return!!(n||t&&!r)}function W(e,t,n,r,i,a){let o=t;e.forEach(e=>{let t=o,s=o+e.nodeSize;if(t>=n&&s<=r)for(let n of e.marks){let e=n.type.name;if(we.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}function Pe(e){let t=new Ie;return G(e,t),t.finish()}const Fe=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var Ie=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
|
|
3
|
+
`)){this.parts.push(e);return}let t=e.split(`
|
|
4
|
+
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
5
|
+
`,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart||this.parts.push(`
|
|
6
|
+
`),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=i}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
|
|
7
|
+
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e,`
|
|
8
|
+
`),this.deferredBlankPrefix=null)}};function G(e,t){switch(e.type.name){case`doc`:K(e,t);return;case`paragraph`:q(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(Fe[n]??`# `),q(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>K(e,t)),t.closeBlock();return;case`list`:Le(e,t);return;case`codeBlock`:Re(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:Be(e,t);return;case`text`:e.text&&t.write(e.text);return}}function K(e,t){let n=e.childCount;for(let r=0;r<n;r++)G(e.child(r),t)}function q(e,t){let n=e.childCount;for(let r=0;r<n;r++){let n=e.child(r);n.isText&&n.text&&t.write(n.text)}}function Le(e,t){let n=e.attrs,r=n.kind===`ordered`?`${n.order??1}. `:n.kind===`task`?n.checked?`- [x] `:`- [ ] `:`- `,i=` `.repeat(r.length);t.withPrefix(i,r,()=>K(e,t)),t.closeBlock()}function Re(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(ze(r)+1);t.write(i),n&&t.write(n),t.write(`
|
|
9
|
+
`),t.write(r),t.write(`
|
|
10
|
+
`),t.write(i),t.closeBlock()}function ze(e){let t=2,n=0;for(let r=0;r<e.length;r++)e.charCodeAt(r)===96?(n++,n>t&&(t=n)):n=0;return t}function Be(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(Ve(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(J(s,i)),t.write(`
|
|
11
|
+
`),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
12
|
+
`),t.write(J(r[e],i)));t.closeBlock()}function J(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Ve(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
13
|
+
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
14
|
+
`,` `)}function Y(e,t){let n=He(e,ue.parse(t).cursor(),t);return e.nodes.doc(n)}function He(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...X(e,t,n));while(t.nextSibling());return t.parent(),r}function X(e,t,n){switch(t.type.id){case T.ATXHeading1:return[Z(e,t,n,1)];case T.ATXHeading2:return[Z(e,t,n,2)];case T.ATXHeading3:return[Z(e,t,n,3)];case T.ATXHeading4:return[Z(e,t,n,4)];case T.ATXHeading5:return[Z(e,t,n,5)];case T.ATXHeading6:return[Z(e,t,n,6)];case T.SetextHeading1:return[Z(e,t,n,1)];case T.SetextHeading2:return[Z(e,t,n,2)];case T.Paragraph:return[Ue(e,t,n)];case T.Blockquote:return[We(e,t,n)];case T.BulletList:return Q(e,t,n,`bullet`,1);case T.OrderedList:return Ge(e,t,n);case T.FencedCode:case T.CodeBlock:return[qe(e,t,n)];case T.HorizontalRule:return[e.nodes.horizontalRule()];case T.Table:return[Je(e,t,n)];default:return[]}}function Z(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===T.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===T.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.nodes.heading({level:r},o)}function Ue(e,t,n){let r=n.slice(t.from,t.to);return e.nodes.paragraph(r)}function We(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===T.QuoteMark)continue;r.push(...X(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.blockquote(r)}function Q(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===T.ListItem&&a.push(Ke(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function Ge(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===T.ListItem&&t.firstChild()){if(t.type.id===T.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return Q(e,t,n,`ordered`,r)}function Ke(e,t,n,r,i){let a=[];if(t.firstChild()){do{if(t.type.id===T.ListMark)continue;a.push(...X(e,t,n))}while(t.nextSibling());t.parent()}return e.nodes.list({kind:r,order:r===`ordered`?i:null,checked:!1,collapsed:!1},a)}function qe(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case T.CodeInfo:r=n.slice(t.from,t.to);break;case T.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.nodes.codeBlock({language:r},i)}function Je(e,t,n){let r=[];if(t.firstChild()){do{let i=t.type.id;i===T.TableHeader?r.push($(e,t,n,!0)):i===T.TableRow&&r.push($(e,t,n,!1))}while(t.nextSibling());t.parent()}return e.nodes.table(r)}function $(e,t,n,r){let i=[];if(t.firstChild()){do if(t.type.id===T.TableCell){let a=n.slice(t.from,t.to).trim(),o=e.nodes.paragraph(a);i.push(r?e.nodes.tableHeaderCell(o):e.nodes.tableCell(o))}while(t.nextSibling());t.parent()}return e.nodes.tableRow(i)}export{Se as defineEditorExtension,Oe as defineMarkMode,Pe as docToMarkdown,Y as markdownToDoc};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
.ProseMirror {
|
|
2
|
+
word-wrap: break-word;
|
|
3
|
+
white-space: pre-wrap;
|
|
4
|
+
white-space: break-spaces;
|
|
5
|
+
-webkit-font-variant-ligatures: none;
|
|
6
|
+
font-variant-ligatures: none;
|
|
7
|
+
font-feature-settings: "liga" 0;
|
|
8
|
+
position: relative;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.ProseMirror pre {
|
|
12
|
+
white-space: pre-wrap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.ProseMirror li {
|
|
16
|
+
position: relative;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ProseMirror-hideselection ::selection {
|
|
20
|
+
background: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ProseMirror-hideselection {
|
|
24
|
+
caret-color: #0000;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ProseMirror [draggable][contenteditable="false"] {
|
|
28
|
+
user-select: text;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.ProseMirror-selectednode {
|
|
32
|
+
outline: 2px solid #8cf;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
li.ProseMirror-selectednode {
|
|
36
|
+
outline: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
li.ProseMirror-selectednode:after {
|
|
40
|
+
content: "";
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
border: 2px solid #8cf;
|
|
43
|
+
position: absolute;
|
|
44
|
+
inset: -2px -2px -2px -32px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
img.ProseMirror-separator {
|
|
48
|
+
border: none !important;
|
|
49
|
+
margin: 0 !important;
|
|
50
|
+
display: inline !important;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:root {
|
|
54
|
+
--prosekit-list-bullet-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='2.5' fill='currentColor'/%3E%3C/svg%3E");
|
|
55
|
+
--prosekit-list-toggle-open-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpolygon points='8,10 12,14 16,10' fill='currentColor'/%3E%3C/svg%3E");
|
|
56
|
+
--prosekit-list-toggle-closed-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpolygon points='10,8 14,12 10,16' fill='currentColor'/%3E%3C/svg%3E");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.prosemirror-flat-list {
|
|
60
|
+
margin: 0;
|
|
61
|
+
padding: 0;
|
|
62
|
+
list-style: none;
|
|
63
|
+
position: relative;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.prosemirror-flat-list > .list-marker {
|
|
67
|
+
text-align: center;
|
|
68
|
+
width: 1lh;
|
|
69
|
+
height: 1lh;
|
|
70
|
+
position: absolute;
|
|
71
|
+
inset-inline-start: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.prosemirror-flat-list > .list-content {
|
|
75
|
+
margin-inline-start: 1lh;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.prosemirror-flat-list[data-list-kind="bullet"] > .list-marker, .prosemirror-flat-list[data-list-kind="toggle"] > .list-marker {
|
|
79
|
+
background-color: currentColor;
|
|
80
|
+
mask-position: center;
|
|
81
|
+
mask-size: contain;
|
|
82
|
+
mask-repeat: no-repeat;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.prosemirror-flat-list[data-list-kind="bullet"] > .list-marker {
|
|
86
|
+
mask-image: var(--prosekit-list-bullet-icon);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.prosemirror-flat-list[data-list-kind="toggle"] > .list-marker {
|
|
90
|
+
mask-image: var(--prosekit-list-toggle-open-icon);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.prosemirror-flat-list[data-list-kind="toggle"][data-list-collapsable][data-list-collapsed] > .list-marker {
|
|
94
|
+
mask-image: var(--prosekit-list-toggle-closed-icon);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.prosemirror-flat-list[data-list-kind="ordered"] > * {
|
|
98
|
+
contain: style;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.prosemirror-flat-list[data-list-kind="ordered"]:before {
|
|
102
|
+
content: counter(prosemirror-flat-list-counter, decimal) ". ";
|
|
103
|
+
font-variant-numeric: tabular-nums;
|
|
104
|
+
position: absolute;
|
|
105
|
+
inset-inline-end: calc(100% - 1lh);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.prosemirror-flat-list[data-list-kind="ordered"] {
|
|
109
|
+
counter-increment: prosemirror-flat-list-counter;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.prosemirror-flat-list[data-list-kind="ordered"]:first-child, :not(.prosemirror-flat-list[data-list-kind="ordered"]) + .prosemirror-flat-list[data-list-kind="ordered"] {
|
|
113
|
+
counter-reset: prosemirror-flat-list-counter;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@supports (counter-set: prosemirror-flat-list-counter 1) {
|
|
117
|
+
:is(.prosemirror-flat-list[data-list-kind="ordered"]:first-child, :not(.prosemirror-flat-list[data-list-kind="ordered"]) + .prosemirror-flat-list[data-list-kind="ordered"])[data-list-order] {
|
|
118
|
+
counter-set: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@supports not (counter-set: prosemirror-flat-list-counter 1) {
|
|
123
|
+
:is(.prosemirror-flat-list[data-list-kind="ordered"]:first-child, :not(.prosemirror-flat-list[data-list-kind="ordered"]) + .prosemirror-flat-list[data-list-kind="ordered"])[data-list-order] {
|
|
124
|
+
counter-increment: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.prosemirror-flat-list[data-list-kind="task"] > .list-marker, .prosemirror-flat-list[data-list-kind="task"] > .list-marker * {
|
|
129
|
+
cursor: pointer;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
align-items: center;
|
|
132
|
+
margin: 0;
|
|
133
|
+
padding: 0;
|
|
134
|
+
display: flex;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.prosemirror-flat-list[data-list-kind="toggle"][data-list-collapsable] > .list-marker {
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.prosemirror-flat-list[data-list-kind="toggle"]:not([data-list-collapsable]) > .list-marker {
|
|
142
|
+
opacity: .4;
|
|
143
|
+
pointer-events: none;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.prosemirror-flat-list[data-list-kind="toggle"][data-list-collapsable][data-list-collapsed] > .list-content > :nth-child(n+2) {
|
|
147
|
+
display: none;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.ProseMirror .tableWrapper {
|
|
151
|
+
overflow-x: auto;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.ProseMirror table {
|
|
155
|
+
border-collapse: collapse;
|
|
156
|
+
table-layout: fixed;
|
|
157
|
+
width: 100%;
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.ProseMirror td, .ProseMirror th {
|
|
162
|
+
box-sizing: border-box;
|
|
163
|
+
vertical-align: top;
|
|
164
|
+
border-width: 1px;
|
|
165
|
+
padding-left: .75rem;
|
|
166
|
+
padding-right: .75rem;
|
|
167
|
+
position: relative;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
prosekit-table-handle-drop-indicator {
|
|
171
|
+
background-color: highlighttext;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.ProseMirror .column-resize-handle {
|
|
175
|
+
z-index: 20;
|
|
176
|
+
pointer-events: none;
|
|
177
|
+
background-color: highlighttext;
|
|
178
|
+
width: 4px;
|
|
179
|
+
position: absolute;
|
|
180
|
+
top: 0;
|
|
181
|
+
bottom: 0;
|
|
182
|
+
right: -2px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.ProseMirror.resize-cursor {
|
|
186
|
+
cursor: ew-resize;
|
|
187
|
+
cursor: col-resize;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.ProseMirror .selectedCell {
|
|
191
|
+
--color: 210, 100%, 56%;
|
|
192
|
+
border: 1px double hsl(var(--color));
|
|
193
|
+
background-color: hsla(var(--color), 20%);
|
|
194
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/prosekit/meowdown"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
|
-
".":
|
|
12
|
-
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
}
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./style.css": "./dist/style.css"
|
|
15
13
|
},
|
|
16
14
|
"files": [
|
|
17
15
|
"./dist/**/*.js",
|
|
18
|
-
"./dist/**/*.d.ts"
|
|
16
|
+
"./dist/**/*.d.ts",
|
|
17
|
+
"./dist/**/*.css"
|
|
19
18
|
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@lezer/common": "^1.5.2",
|
|
21
|
+
"@lezer/markdown": "^1.6.4",
|
|
22
|
+
"@prosekit/core": "^0.12.3",
|
|
23
|
+
"@prosekit/extensions": "^0.17.4",
|
|
24
|
+
"@prosekit/pm": "^0.1.18"
|
|
25
|
+
},
|
|
20
26
|
"devDependencies": {
|
|
21
|
-
"@ocavue/tsconfig": "^0.7.
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
27
|
+
"@ocavue/tsconfig": "^0.7.1",
|
|
28
|
+
"@tsdown/css": "^0.22.2",
|
|
29
|
+
"@vitest/browser-playwright": "^4.1.8",
|
|
30
|
+
"tsdown": "^0.22.2",
|
|
31
|
+
"vitest": "^4.1.8"
|
|
25
32
|
},
|
|
26
33
|
"publishConfig": {
|
|
27
34
|
"access": "public"
|