@meowdown/core 0.8.1 → 0.10.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/README.md +4 -0
- package/dist/index.d.ts +33 -9
- package/dist/index.js +7 -7
- package/dist/style.css +20 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -59,6 +59,10 @@ Wikilinks (`[[target]]`) render with a dashed underline via the `.md-wikilink` c
|
|
|
59
59
|
|
|
60
60
|
Inline images (``) stay literal text and render beneath their line as a widget decoration when a host resolves the `src` to a URL. Add it with `defineImages({ resolveImageUrl, onImagePaste })` (or `@meowdown/react`'s image props).
|
|
61
61
|
|
|
62
|
+
Pasting a lone tweet or YouTube link can auto-embed it. `defineEmbedPaste()` (or `@meowdown/react`'s `embedPaste` prop) rewrites the pasted link to `` so it renders as an embed; one undo turns the embed back into the raw link. It is not part of `defineEditorExtension`; add it explicitly.
|
|
63
|
+
|
|
64
|
+
Pressing Enter at the end of the document's first heading (the title line) can start a fresh empty bullet on the next line instead of a plain paragraph. `defineBulletAfterHeading()` binds this. It is not part of `defineEditorExtension`; add it explicitly.
|
|
65
|
+
|
|
62
66
|
## License
|
|
63
67
|
|
|
64
68
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, PlainExtension } from "@prosekit/core";
|
|
1
|
+
import { Editor, ExtractNodeBuilders, PlainExtension } from "@prosekit/core";
|
|
2
2
|
import { CodeBlockAttrs } from "@prosekit/extensions/code-block";
|
|
3
3
|
import { ProseMirrorNode } from "@prosekit/pm/model";
|
|
4
4
|
import { PlaceholderOptions, definePlaceholder } from "@prosekit/extensions/placeholder";
|
|
@@ -90,6 +90,23 @@ interface ImageOptions {
|
|
|
90
90
|
/** Inline image rendering (widget decorations) plus paste/drop persistence. */
|
|
91
91
|
declare function defineImages(options: ImageOptions): PlainExtension;
|
|
92
92
|
//#endregion
|
|
93
|
+
//#region src/extensions/embed-paste.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Auto-embed a pasted tweet or YouTube link. When the clipboard holds exactly
|
|
96
|
+
* one such URL, the link is rewritten to ``, which the image pipeline
|
|
97
|
+
* renders as a rich embed. Not part of `defineEditorExtension`; the React
|
|
98
|
+
* package applies it via the `embedPaste` prop (on by default).
|
|
99
|
+
*/
|
|
100
|
+
declare function defineEmbedPaste(): PlainExtension;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/extensions/bullet-after-heading.d.ts
|
|
103
|
+
/**
|
|
104
|
+
* "Type a title, press Return, start bullets." When this extension is applied,
|
|
105
|
+
* pressing Enter at the end of the document's first heading (the title line)
|
|
106
|
+
* drops the caret into a fresh empty bullet instead of a plain paragraph.
|
|
107
|
+
*/
|
|
108
|
+
declare function defineBulletAfterHeading(): PlainExtension;
|
|
109
|
+
//#endregion
|
|
93
110
|
//#region src/extensions/key-bindings.d.ts
|
|
94
111
|
/** Human-readable descriptions of the editor's formatting and heading shortcuts. */
|
|
95
112
|
declare const EDITOR_KEY_BINDINGS: {
|
|
@@ -132,18 +149,25 @@ declare const codeBlockLanguages: ReadonlyArray<{
|
|
|
132
149
|
*/
|
|
133
150
|
declare function docToMarkdown(node: ProseMirrorNode): string;
|
|
134
151
|
//#endregion
|
|
152
|
+
//#region src/extensions/schema.d.ts
|
|
153
|
+
type TypedNodeBuilders = ExtractNodeBuilders<EditorExtension>;
|
|
154
|
+
//#endregion
|
|
135
155
|
//#region src/converters/md-to-pm.d.ts
|
|
136
156
|
/**
|
|
137
|
-
* Convert a markdown string into a ProseMirror document node
|
|
138
|
-
*
|
|
157
|
+
* Convert a markdown string into a ProseMirror document node.
|
|
158
|
+
*
|
|
159
|
+
* By default the document is built with the shared schema's node builders, so
|
|
160
|
+
* no editor is required. When the result will be loaded into a specific editor,
|
|
161
|
+
* pass that editor's `nodes` so the document uses the editor's own schema
|
|
162
|
+
* instance and can be inserted without a JSON round trip.
|
|
139
163
|
*
|
|
140
|
-
* The output follows the extension set defined in
|
|
141
|
-
* paragraph, text, heading, blockquote, list, codeBlock, table, tableRow,
|
|
164
|
+
* The output follows the extension set defined in `../extensions/extension.ts`
|
|
165
|
+
* (doc, paragraph, text, heading, blockquote, list, codeBlock, table, tableRow,
|
|
142
166
|
* tableCell, tableHeaderCell, horizontalRule). The function does not produce
|
|
143
|
-
* inline marks because
|
|
144
|
-
* inline-code characters survive
|
|
167
|
+
* inline marks because the markdown stays literal text - emphasis / link /
|
|
168
|
+
* inline-code characters survive verbatim.
|
|
145
169
|
*/
|
|
146
|
-
declare function markdownToDoc(
|
|
170
|
+
declare function markdownToDoc(markdown: string, nodes?: TypedNodeBuilders): ProseMirrorNode;
|
|
147
171
|
//#endregion
|
|
148
172
|
//#region src/converters/check-roundtrip.d.ts
|
|
149
173
|
/**
|
|
@@ -156,4 +180,4 @@ type RoundTripFidelity = 'exact' | 'normalizing' | 'lossy';
|
|
|
156
180
|
/** Classify how `markdown` survives the editor's parse-then-serialize round trip. */
|
|
157
181
|
declare function checkRoundTrip(markdown: string): RoundTripFidelity;
|
|
158
182
|
//#endregion
|
|
159
|
-
export { type CodeBlockAttrs, EDITOR_KEY_BINDINGS, type EditorExtension, type ImageOptions, type MarkMode, type PlaceholderOptions, type RoundTripFidelity, type TypedEditor, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defineEditorExtension, defineImages, defineMarkMode, definePlaceholder, defineReadonly, defineWikilinkClickHandler, docToMarkdown, markdownToDoc };
|
|
183
|
+
export { type CodeBlockAttrs, EDITOR_KEY_BINDINGS, type EditorExtension, type ImageOptions, type MarkMode, type PlaceholderOptions, type RoundTripFidelity, type TypedEditor, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defineBulletAfterHeading, defineEditorExtension, defineEmbedPaste, defineImages, defineMarkMode, definePlaceholder, defineReadonly, defineWikilinkClickHandler, docToMarkdown, markdownToDoc };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{Priority as e,createEditor as t,defineBaseCommands as n,defineBaseKeymap as r,defineCommands as i,defineHistory as a,defineKeymap as o,defineMarkSpec as s,definePlugin as c,getMarkType as l,isApple as u,isAtBlockStart as d,toggleNode as ee,union as f,unsetBlockType as te,withPriority as ne,withSkipCodeBlock as re}from"@prosekit/core";import{defineBlockquote as ie}from"@prosekit/extensions/blockquote";import{defineCodeBlock as ae,defineCodeBlockHighlight as oe}from"@prosekit/extensions/code-block";import{defineDoc as se}from"@prosekit/extensions/doc";import{defineGapCursor as ce}from"@prosekit/extensions/gap-cursor";import{defineHorizontalRule as le}from"@prosekit/extensions/horizontal-rule";import{defineList as ue}from"@prosekit/extensions/list";import{defineModClickPrevention as de}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as fe}from"@prosekit/extensions/paragraph";import{defineText as pe}from"@prosekit/extensions/text";import{defineVirtualSelection as me}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as he}from"@codemirror/language";import{languages as ge}from"@codemirror/language-data";import{classHighlighter as _e}from"@lezer/highlight";import{createParser as ve}from"prosemirror-highlight/lezer";import{defineHeadingCommands as ye,defineHeadingInputRule as be,defineHeadingSpec as xe}from"@prosekit/extensions/heading";import{Plugin as p,PluginKey as m,TextSelection as h}from"@prosekit/pm/state";import{ReplaceStep as Se,Step as Ce,StepResult as g,Transform as _}from"@prosekit/pm/transform";import{Mark as we}from"@prosekit/pm/model";import{GFM as Te,parser as Ee}from"@lezer/markdown";import{defineTableCellSpec as De,defineTableCommands as Oe,defineTableDropIndicator as ke,defineTableHeaderCellSpec as Ae,defineTableRowSpec as je,defineTableSpec as Me}from"@prosekit/extensions/table";import{tableEditing as Ne}from"prosemirror-tables";import{Decoration as v,DecorationSet as y}from"@prosekit/pm/view";import{definePlaceholder as Pe}from"@prosekit/extensions/placeholder";import{defineReadonly as Fe}from"@prosekit/extensions/readonly";const b=new Map;async function Ie(e){let t=he.matchLanguageName(ge,e,!0);if(!t){b.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),b.set(e,null)}if(b.has(e))return;if(!n){b.set(e,null);return}let r=ve({parse:e=>n.language.parser.parse(e.content),highlighter:_e});b.set(e,r)}const Le=e=>{let t=e.language?.trim();if(!t)return[];let n=b.get(t);return n?n(e):n===null?[]:Ie(t)};function Re(){return oe({parser:Le,nodeTypes:[`codeBlock`]})}function x(e){return re(ee({type:`heading`,attrs:{level:e}}))}const ze=(e,t,n)=>d(e,n)?.parent.type.name===`heading`?te()(e,t,n):!1;function Be(){return o({"Mod-1":x(1),"Mod-2":x(2),"Mod-3":x(3),"Mod-4":x(4),"Mod-5":x(5),"Mod-6":x(6),Backspace:ze})}function Ve(){return f(xe(),be(),ye(),Be())}function He(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ue(e,t){let[n,r,i]=t;return[n,r,i.map(t=>we.fromJSON(e,t))]}var S=class e extends Ce{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return g.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 _(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new _(e),n.addMark(i,c,t));return!1})}return g.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return We;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 Se(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(He)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ue(t,e)))}};Ce.jsonID(`batchSetMark`,S);const We=new S([]);function Ge(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Ke(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const qe={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Ge(t))break;i||=Ke(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Je={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Ye(e){return e.end}const C=Ee.configure([Te,qe,Je]),Xe=C.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ye}]});function w(e){return C.parseInline(e,0)}function T(e,t,n=[]){for(let r of e)t(r)&&n.push(r),T(r.children,t,n);return n}function Ze(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const E=Ze(C);function Qe(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([[E.Emphasis,`mdEm`],[E.StrongEmphasis,`mdStrong`],[E.InlineCode,`mdCode`],[E.Strikethrough,`mdDel`],[E.EmphasisMark,`mdMark`],[E.CodeMark,`mdMark`],[E.LinkMark,`mdMark`],[E.StrikethroughMark,`mdMark`],[E.URL,`mdLinkUri`],[E.Hashtag,`mdTag`],[E.Wikilink,`mdWikilink`],[E.WikilinkMark,`mdMark`]]);function $e(e,t){let n=w(t),r=[];return O(n,[],0,t.length,t,e,r),r}function O(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&k(o,s,n.from,t),n.type===E.Link||n.type===E.Image)et(n,t,i,a,o);else{let e=D.get(n.type),r=e?[...t,a.marks[e].create()]:t;n.children.length===0?k(o,n.from,n.to,r):O(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&k(o,s,r,t)}function et(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===E.LinkMark?(s++,s===2&&(a=t.from)):t.type===E.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;k(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?k(i,a.from,a.to,s):O(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&k(i,d,e.to,t)}function k(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Qe(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const A=`inline-marks-applied`,j=new WeakMap;let tt=0,nt=0;function rt(e,t,n){let r=j.get(e);if(r?nt++:(tt++,r=$e(n,e.textContent),j.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 it(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 at(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=rt(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function ot(){return new p({key:new m(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(A))return null;let r=at(n,it(e,n));if(r.length===0)return null;let i=n.tr.step(new S(r));return i.setMeta(A,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(st(e.state)),{}}})}function st(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ct(){return c(ot())}function lt(){return s({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ut(){return s({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function dt(){return s({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function ft(){return s({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function pt(){return s({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 mt(){return s({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function ht(){return s({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function gt(){return s({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function _t(){return s({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function vt(){return f(lt(),ut(),dt(),ft(),pt(),mt(),ht(),gt(),_t())}function M(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const N={em:{node:E.Emphasis,delim:`*`},strong:{node:E.StrongEmphasis,delim:`**`},code:{node:E.InlineCode,delim:"`"},del:{node:E.Strikethrough,delim:`~~`}},yt=new Set([E.EmphasisMark,E.CodeMark,E.LinkMark,E.StrikethroughMark]);function P(e){return[e.children[0],e.children.at(-1)]}function bt(e){let{type:t,children:n}=e;if(t===E.Emphasis||t===E.StrongEmphasis||t===E.Strikethrough)return[n[0].to,n.at(-1).from];if(t===E.Link||t===E.Image){let e=n.find((e,t)=>t>0&&e.type===E.LinkMark);return e?[n[0].to,e.from]:null}return null}function F(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=bt(r);return i&&i[0]<=t&&n<=i[1]?F(r.children,t,n):F(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function I(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return I(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const L=e=>e===` `||e===` `;function xt(e,t,n){for(;t<n&&L(e[t]);)t++;for(;n>t&&L(e[n-1]);)n--;return[t,n]}function St(e,t,n,r){let i=T(w(e),e=>e.type===r.node||yt.has(e.type));for(let r=t;r<n;r++)if(!L(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Ct(e,t,n,r,i){let a=w(e),o=T(a,e=>e.type===r.node);return i?Et(e,o,t,n):wt(e,a,o,t,n,r)}function wt(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=F(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=P(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Tt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Tt(e,t,n,r,i){if(i.node!==E.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(M(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Et(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=P(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=I(a.children.slice(1,-1),s,c);s>t.to&&L(e[s-1]);)s--;for(;c<o.from&&L(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Dt(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=w(e),o=T(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=P(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return R(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function R(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=bt(n);return!e||t<e[0]||t>e[1]?!0:R(n.children,t)}return!1}function z(e){return(t,n)=>{if(t.selection.empty)return Ot(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=xt(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:St(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ct(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(h.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Ot(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Dt(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(h.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(h.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function kt(){return i({toggleEm:()=>z(N.em),toggleStrong:()=>z(N.strong),toggleCode:()=>z(N.code),toggleDel:()=>z(N.del)})}function At(){return o({"Mod-b":z(N.strong),"Mod-i":z(N.em),"Mod-e":z(N.code),"Mod-Shift-x":z(N.del)})}function jt(){return f(kt(),At())}function Mt(){return f(Me(),je(),De(),Ae(),c(Ne()),Oe(),ke())}function Nt(){return f(fe(),se(),pe(),ie(),ue(),Ve(),Mt(),ae(),le(),vt(),Re(),ct(),jt(),r(),n(),a(),ce(),me(),de())}function B(){return Nt()}const Pt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Ft=new Set([`mdMark`,`mdLinkUri`]),It=new Set([`mdMark`,`mdLinkUri`]),V=new Set([`mdLinkText`,`mdLinkUri`]),Lt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Rt(e){return new p({key:new m(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>Vt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Bt}})}function zt(e){return c(Rt(e))}function Bt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>It.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
|
|
2
|
-
`)}function
|
|
1
|
+
import{Priority as e,createMarkBuilders as t,createNodeBuilders as n,defineBaseCommands as r,defineBaseKeymap as i,defineCommands as a,defineHistory as o,defineKeymap as s,defineMarkSpec as c,definePlugin as l,getMarkType as u,getNodeType as d,isApple as ee,isAtBlockStart as te,toggleNode as ne,union as f,unsetBlockType as re,withPriority as p,withSkipCodeBlock as ie}from"@prosekit/core";import{defineBlockquote as ae}from"@prosekit/extensions/blockquote";import{defineCodeBlock as oe,defineCodeBlockHighlight as se}from"@prosekit/extensions/code-block";import{defineDoc as ce}from"@prosekit/extensions/doc";import{defineGapCursor as le}from"@prosekit/extensions/gap-cursor";import{defineHorizontalRule as ue}from"@prosekit/extensions/horizontal-rule";import{defineList as de}from"@prosekit/extensions/list";import{defineModClickPrevention as fe}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as pe}from"@prosekit/extensions/paragraph";import{defineText as me}from"@prosekit/extensions/text";import{defineVirtualSelection as he}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as ge}from"@codemirror/language";import{languages as m}from"@codemirror/language-data";import{classHighlighter as _e}from"@lezer/highlight";import{createParser as ve}from"prosemirror-highlight/lezer";import{defineHeadingCommands as ye,defineHeadingInputRule as be,defineHeadingSpec as xe}from"@prosekit/extensions/heading";import{Plugin as h,PluginKey as g,TextSelection as _}from"@prosekit/pm/state";import{ReplaceStep as Se,Step as v,StepResult as y,Transform as b}from"@prosekit/pm/transform";import{Mark as Ce}from"@prosekit/pm/model";import{GFM as we,parser as Te}from"@lezer/markdown";import{once as x}from"@ocavue/utils";import{defineTableCellSpec as Ee,defineTableCommands as De,defineTableDropIndicator as Oe,defineTableEditingPlugin as ke,defineTableHeaderCellSpec as Ae,defineTableRowSpec as je,defineTableSpec as Me}from"@prosekit/extensions/table";import{Decoration as S,DecorationSet as C}from"@prosekit/pm/view";import{closeHistory as Ne}from"@prosekit/pm/history";import{definePlaceholder as Pe}from"@prosekit/extensions/placeholder";import{defineReadonly as Fe}from"@prosekit/extensions/readonly";const w=new Map;async function Ie(e){let t=ge.matchLanguageName(m,e,!0);if(!t){w.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),w.set(e,null)}if(w.has(e))return;if(!n){w.set(e,null);return}let r=ve({parse:e=>n.language.parser.parse(e.content),highlighter:_e});w.set(e,r)}const Le=e=>{let t=e.language?.trim();if(!t)return[];let n=w.get(t);return n?n(e):n===null?[]:Ie(t)};function Re(){return se({parser:Le,nodeTypes:[`codeBlock`]})}function T(e){return ie(ne({type:`heading`,attrs:{level:e}}))}const ze=(e,t,n)=>te(e,n)?.parent.type.name===`heading`?re()(e,t,n):!1;function Be(){return s({"Mod-1":T(1),"Mod-2":T(2),"Mod-3":T(3),"Mod-4":T(4),"Mod-5":T(5),"Mod-6":T(6),Backspace:ze})}function Ve(){return f(xe(),be(),ye(),Be())}function He(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ue(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ce.fromJSON(e,t))]}var E=class e extends v{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return y.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 b(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new b(e),n.addMark(i,c,t));return!1})}return y.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return We;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 Se(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(He)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ue(t,e)))}};v.jsonID(`batchSetMark`,E);const We=new E([]);function Ge(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Ke(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const qe={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Ge(t))break;i||=Ke(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Je={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Ye(e){return e.end}const D=Te.configure([we,qe,Je]),Xe=D.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ye}]});function O(e){return D.parseInline(e,0)}function k(e,t,n=[]){for(let r of e)t(r)&&n.push(r),k(r.children,t,n);return n}function Ze(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const A=Ze(D);function Qe(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 j=new Map([[A.Emphasis,`mdEm`],[A.StrongEmphasis,`mdStrong`],[A.InlineCode,`mdCode`],[A.Strikethrough,`mdDel`],[A.EmphasisMark,`mdMark`],[A.CodeMark,`mdMark`],[A.LinkMark,`mdMark`],[A.StrikethroughMark,`mdMark`],[A.URL,`mdLinkUri`],[A.Hashtag,`mdTag`],[A.Wikilink,`mdWikilink`],[A.WikilinkMark,`mdMark`]]);function $e(e,t){let n=O(t),r=[];return M(n,[],0,t.length,t,e,r),r}function et(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e))return`https://${e}`}function M(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&N(o,s,n.from,t),n.type===A.Link||n.type===A.Image)tt(n,t,i,a,o);else if(n.type===A.URL){let e=et(i.slice(n.from,n.to)),r=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();N(o,n.from,n.to,[...t,r])}else{let e=j.get(n.type),r=e?[...t,a[e].create()]:t;n.children.length===0?N(o,n.from,n.to,r):M(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&N(o,s,r,t)}function tt(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===A.LinkMark?(s++,s===2&&(a=t.from)):t.type===A.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c?r.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;N(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=j.get(a.type),s=o?[...e,r[o].create()]:e;a.children.length===0?N(i,a.from,a.to,s):M(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&N(i,d,e.to,t)}function N(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Qe(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const nt=x(()=>{let e=U().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),rt=x(()=>n(nt())),P=`meowdown_mark_builders`;function it(e){let n=e.cached[P];if(n)return n;let r=t(e);return e.cached[P]=r,r}const at=`inline-marks-applied`,ot=new WeakMap;let st=0,ct=0;function lt(e,t,n){let r=ot.get(e);if(r?ct++:(st++,r=$e(it(n),e.textContent),ot.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 ut(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 dt(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=lt(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function ft(){return new h({key:new g(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(at))return null;let r=dt(n,ut(e,n));if(r.length===0)return null;let i=n.tr.step(new E(r));return i.setMeta(at,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(pt(e.state)),{}}})}function pt(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function mt(){return l(ft())}function ht(){return c({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function gt(){return c({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function _t(){return c({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function vt(){return c({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function yt(){return c({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 bt(){return c({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function xt(){return c({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function St(){return c({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Ct(){return c({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function wt(){return f(ht(),gt(),_t(),vt(),yt(),bt(),xt(),St(),Ct())}function Tt(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const F={em:{node:A.Emphasis,delim:`*`},strong:{node:A.StrongEmphasis,delim:`**`},code:{node:A.InlineCode,delim:"`"},del:{node:A.Strikethrough,delim:`~~`}},Et=new Set([A.EmphasisMark,A.CodeMark,A.LinkMark,A.StrikethroughMark]);function I(e){return[e.children[0],e.children.at(-1)]}function L(e){let{type:t,children:n}=e;if(t===A.Emphasis||t===A.StrongEmphasis||t===A.Strikethrough)return[n[0].to,n.at(-1).from];if(t===A.Link||t===A.Image){let e=n.find((e,t)=>t>0&&e.type===A.LinkMark);return e?[n[0].to,e.from]:null}return null}function R(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=L(r);return i&&i[0]<=t&&n<=i[1]?R(r.children,t,n):R(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function z(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return z(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const B=e=>e===` `||e===` `;function Dt(e,t,n){for(;t<n&&B(e[t]);)t++;for(;n>t&&B(e[n-1]);)n--;return[t,n]}function Ot(e,t,n,r){let i=k(O(e),e=>e.type===r.node||Et.has(e.type));for(let r=t;r<n;r++)if(!B(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function kt(e,t,n,r,i){let a=O(e),o=k(a,e=>e.type===r.node);return i?Mt(e,o,t,n):At(e,a,o,t,n,r)}function At(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=R(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=I(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=jt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function jt(e,t,n,r,i){if(i.node!==A.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(Tt(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Mt(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=I(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=z(a.children.slice(1,-1),s,c);s>t.to&&B(e[s-1]);)s--;for(;c<o.from&&B(e[c]);)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Nt(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=O(e),o=k(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=I(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return V(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function V(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=L(n);return!e||t<e[0]||t>e[1]?!0:V(n.children,t)}return!1}function H(e){return(t,n)=>{if(t.selection.empty)return Pt(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=Dt(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:Ot(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>kt(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(_.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Pt(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Nt(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(_.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(_.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Ft(){return a({toggleEm:()=>H(F.em),toggleStrong:()=>H(F.strong),toggleCode:()=>H(F.code),toggleDel:()=>H(F.del)})}function It(){return s({"Mod-b":H(F.strong),"Mod-i":H(F.em),"Mod-e":H(F.code),"Mod-Shift-x":H(F.del)})}function Lt(){return f(Ft(),It())}function Rt(){return f(Me(),je(),Ee(),Ae(),ke({allowTableNodeSelection:!0}),De(),Oe())}function zt(){return f(pe(),ce(),me(),ae(),de(),Ve(),Rt(),oe(),ue(),wt(),Re(),mt(),Lt(),i(),r(),o(),le(),he(),fe())}function U(){return zt()}const Bt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Vt=new Set([`mdMark`,`mdLinkUri`]),Ht=new Set([`mdMark`,`mdLinkUri`]),W=new Set([`mdLinkText`,`mdLinkUri`]),Ut=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Wt(e){return new h({key:new g(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>qt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Kt}})}function Gt(e){return l(Wt(e))}function Kt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Ht.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
|
|
2
|
+
`)}function qt(e){let{$anchor:t,empty:n}=e.selection;if(!n)return C.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=Jt(r,a);if(o.size===0)return C.empty;let s=[],c=new Set,l=!1;for(let e of o)if(W.has(e)){if(l)continue;l=!0,Xt(r,i,a,s,c)}else Yt(r,i,e,a,s,c);let u=s.map(([e,t])=>S.inline(e,t,{class:`show`}));return C.create(e.doc,u)}function Jt(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;Bt.has(e)&&n.add(e)}r=i}),n}function Yt(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&&K(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&K(e,t,c,o,i,a)}function Xt(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=>W.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&G(e.child(c-1));)c--;let l=o;for(;l<a-1&&G(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;K(e,t,u,d,r,i)}function G(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:W.has(e)?n=!0:Ut.has(e)&&(r=!0)}return!!(n||t&&!r)}function K(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(Vt.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const Zt=new g(`meowdown-wikilink-click`);function Qt(e,t){let n=u(e.schema,`mdWikilink`),r=e.doc.resolve(t),i=r.parent;if(!i.isTextblock||i.type.spec.code)return;let a=r.start(),o=-1,s=-1,c,l=0;if(i.forEach(e=>{let r=a+l;l+=e.nodeSize;let i=a+l;n.isInSet(e.marks)?(o<0&&(o=r),s=i):(o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),o=-1)}),o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),c)return{from:c.from,to:c.to,target:$t(e.doc.textBetween(c.from,c.to))}}function $t(e){let t=e.replace(/^\[\[/u,``).replace(/\]\]$/u,``),n=t.indexOf(`|`);return(n>=0?t.slice(0,n):t).trim()}function en(e){let t;return l(new h({key:Zt,props:{handleDOMEvents:{mousedown:e=>{let{from:n,to:r,empty:i}=e.state.selection;return t={from:n,to:r,empty:i},!1}},handleClick:(n,r,i)=>{if(!i.target?.closest?.(`.md-wikilink`))return!1;let a=Qt(n.state,r);return!a||!(ee?i.metaKey:i.ctrlKey)&&t?.empty&&t.from>=a.from&&t.to<=a.to?!1:(e({target:a.target,event:i}),!0)}}}))}function tn(e){let t=[],n=k(O(e),e=>e.type===A.Image);for(let r of n){let n=r.children.find(e=>e.type===A.URL),i=r.children.filter(e=>e.type===A.LinkMark);!n||i.length<2||t.push({from:r.from,to:r.to,alt:e.slice(i[0].to,i[1].from),src:e.slice(n.from,n.to)})}return t}function nn(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const rn=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,an=/\/status(?:es)?\/(\d+)/;function on(e){let t;try{t=new URL(e)}catch{return}if(rn.test(t.hostname))return an.exec(t.pathname)?.[1]}const sn=e=>{let t=on(e);if(t)return{key:`tweet:${t}`,render:()=>{let e=nn()?`dark`:`light`,n=document.createElement(`iframe`);return n.src=`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${e}&dnt=true`,n.title=`Tweet`,n.className=`md-embed md-embed-tweet`,n.dataset.testid=`tweet-embed`,n.loading=`lazy`,n.referrerPolicy=`strict-origin-when-cross-origin`,n.setAttribute(`frameborder`,`0`),cn(n),n}}};function cn(e){let t=t=>{if(t.source===e.contentWindow)try{let n=t.data?.[`twttr.embed`]?.params?.[0]?.height;typeof n==`number`&&(e.style.height=`${n}px`)}catch(e){console.warn(`[meowdown] failed to parse tweet resize message:`,e)}};window.addEventListener(`message`,t);let n=new MutationObserver(()=>{e.isConnected||(window.removeEventListener(`message`,t),n.disconnect())});n.observe(document.body,{childList:!0,subtree:!0})}const ln=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,un=/^(?:www\.)?youtu\.be$/i,dn=/^[\w-]{11}$/;function fn(e){let t;try{t=new URL(e)}catch{return}let n=null;if(un.test(t.hostname))n=t.pathname.slice(1);else if(ln.test(t.hostname)){let[,e,r]=t.pathname.split(`/`);t.pathname===`/watch`?n=t.searchParams.get(`v`):(e===`shorts`||e===`embed`||e===`live`)&&(n=r??null)}if(!n||!dn.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?pn(r):void 0;return{videoId:n,startSeconds:i}}function pn(e){if(/^\d+$/.test(e))return Number(e);let t=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(e);if(!(!t||!t[1]&&!t[2]&&!t[3]))return Number(t[1]??0)*3600+Number(t[2]??0)*60+Number(t[3]??0)}const mn=[e=>{let t=fn(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{key:`youtube:${t.videoId}:${t.startSeconds??0}`,render:()=>{let e=document.createElement(`iframe`);return e.src=`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,e.title=`YouTube video`,e.className=`md-embed md-embed-youtube`,e.dataset.testid=`youtube-embed`,e.loading=`lazy`,e.referrerPolicy=`strict-origin-when-cross-origin`,e.setAttribute(`frameborder`,`0`),e.allow=`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,e.allowFullscreen=!0,e}}},sn];function q(e){for(let t of mn){let n=t(e);if(n)return n}}const J=new g(`meowdown-images`);function hn(e){let t=[];return e.doc.descendants((e,n)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;if(e.childCount===0)return!1;let r=!0;if(e.forEach(e=>{e.isText||(r=!1)}),!r)return!1;for(let r of tn(e.textContent))t.push({widgetAt:n+e.nodeSize-1,alt:r.alt,src:r.src});return!1}),t}function Y(e,t){let n=[];for(let r of hn(e)){let e=q(r.src);if(e){n.push(gn(r,e));continue}let i=t.resolveImageUrl(r.src);i&&n.push(_n(r,i))}return C.create(e.doc,n)}function gn(e,t){return S.widget(e.widgetAt,()=>{let e=document.createElement(`div`);return e.className=`md-embed-wrapper`,e.contentEditable=`false`,e.appendChild(t.render()),e},{key:`md-embed:${t.key}`,side:1})}function _n(e,t){return S.widget(e.widgetAt,()=>{let n=document.createElement(`div`);n.className=`md-image`,n.contentEditable=`false`;let r=document.createElement(`img`);return r.src=t,r.alt=e.alt,r.draggable=!1,n.appendChild(r),n},{key:`md-image:${t}`,side:1})}function vn(e){return new h({key:J,state:{init:(t,n)=>Y(n,e),apply:(t,n,r,i)=>t.docChanged?Y(i,e):n},props:{decorations:e=>J.getState(e)}})}function X(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const yn=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function bn(e,t,n,r=yn,i){let a=i;for(let i of t){let t;try{t=await n(i)}catch(e){r(e,i);continue}if(!t||e.isDestroyed)continue;let o=``,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function xn(e){return new h({props:{handlePaste:(t,n)=>{let r=X(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(bn(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=X(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(bn(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Sn(t){return f(l(vn(t)),p(l(xn(t)),e.high))}const Cn=new g(`meowdown-embed-paste`);function wn(e){let t=e.trim();if(!(!t||/\s/.test(t)))return q(t)?t:void 0}function Tn(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Ne(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Ne(i))}function En(){return l(new h({key:Cn,props:{handlePaste:(e,t)=>{let n=e.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return!1;let r=t.clipboardData?.getData(`text/plain`);if(!r)return!1;let i=wn(r);return i?(Tn(e,i),!0):!1}}}))}const Dn=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=d(e.schema,`list`),i=d(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(_.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function On(){return p(s({Enter:Dn}),e.high)}const kn={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`},An=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),jn=m.map(e=>e.name).filter(e=>!An.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function Mn(e){let t=new Pn;return Fn(e,t),t.finish()}const Nn=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var Pn=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
3
|
`)){this.parts.push(e);return}let t=e.split(`
|
|
4
4
|
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
5
5
|
`,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart||this.parts.push(`
|
|
6
6
|
`),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}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
7
|
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
|
|
8
|
-
`),this.deferredBlankPrefix=null)}};function
|
|
8
|
+
`),this.deferredBlankPrefix=null)}};function Fn(e,t){switch(e.type.name){case`doc`:Z(e,t);return;case`paragraph`:Rn(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(Nn[n]??`# `),Rn(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>Z(e,t)),t.closeBlock();return;case`list`:zn(e,t,Ln(e));return;case`codeBlock`:Bn(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:Vn(e,t);return;case`text`:e.text&&t.write(e.text);return}}function Z(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),Fn(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=In(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),zn(e.child(r),t,s);i=o}}function In(e,t,n){for(let r=t;r<n;r++)if(!Ln(e.child(r)))return!1;return!0}function Ln(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function Rn(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 zn(e,t,n){let r=e.attrs,i=r.kind===`ordered`?`${r.order??1}. `:r.kind===`task`?r.checked?`- [x] `:`- [ ] `:`- `,a=` `.repeat(r.kind===`task`?2:i.length);t.withPrefix(a,i,()=>Z(e,t,n)),t.closeBlock()}function Bn(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(Tt(r,2)+1);t.write(i),n&&t.write(n),t.write(`
|
|
9
9
|
`),t.write(r),t.write(`
|
|
10
|
-
`),t.write(i),t.closeBlock()}function
|
|
10
|
+
`),t.write(i),t.closeBlock()}function Vn(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(Un(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(Hn(s,i)),t.write(`
|
|
11
11
|
`),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
12
|
-
`),t.write(
|
|
12
|
+
`),t.write(Hn(r[e],i)));t.closeBlock()}function Hn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Un(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
13
13
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
14
|
-
`,` `)}function
|
|
15
|
-
`).filter(e=>e.trim()!==``)}function
|
|
14
|
+
`,` `)}function Wn(e,t=rt()){let n=Gn(t,Xe.parse(e).cursor(),e);return t.doc(n)}function Gn(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Q(e,t,n));while(t.nextSibling());return t.parent(),r}function Q(e,t,n){switch(t.type.id){case A.ATXHeading1:return[$(e,t,n,1)];case A.ATXHeading2:return[$(e,t,n,2)];case A.ATXHeading3:return[$(e,t,n,3)];case A.ATXHeading4:return[$(e,t,n,4)];case A.ATXHeading5:return[$(e,t,n,5)];case A.ATXHeading6:return[$(e,t,n,6)];case A.SetextHeading1:return[$(e,t,n,1)];case A.SetextHeading2:return[$(e,t,n,2)];case A.Paragraph:return[Kn(e,t,n)];case A.Blockquote:return[qn(e,t,n)];case A.BulletList:return Jn(e,t,n,`bullet`,1);case A.OrderedList:return Yn(e,t,n);case A.FencedCode:case A.CodeBlock:return[Qn(e,t,n)];case A.HorizontalRule:return[e.horizontalRule()];case A.Table:return[$n(e,t,n)];case A.Task:return[Kn(e,t,n)];default:return[]}}function $(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===A.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===A.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.heading({level:r},o)}function Kn(e,t,n){let r=n.slice(t.from,t.to);return e.paragraph(r)}function qn(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===A.QuoteMark)continue;r.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Jn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===A.ListItem&&a.push(Xn(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function Yn(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===A.ListItem&&t.firstChild()){if(t.type.id===A.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return Jn(e,t,n,`ordered`,r)}function Xn(e,t,n,r,i){let a=[],o=null;if(t.firstChild()){do{if(t.type.id===A.ListMark)continue;if(r===`bullet`&&t.type.id===A.Task){let r=Zn(e,t,n);o=r.checked,a.push(r.paragraph);continue}a.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.list({kind:o===null?r:`task`,order:r===`ordered`?i:null,checked:o??!1,collapsed:!1},a)}function Zn(e,t,n){let r=!1,i=t.from,a=t.to;t.firstChild()&&(t.type.id===A.TaskMarker&&(r=n.slice(t.from,t.to).toLowerCase().includes(`x`),i=t.to),t.parent());let o=n.slice(i,a);return o.startsWith(` `)&&(o=o.slice(1)),{checked:r,paragraph:o===``?e.paragraph():e.paragraph(o)}}function Qn(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case A.CodeInfo:r=n.slice(t.from,t.to);break;case A.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function $n(e,t,n){let r=0;if(t.firstChild()){do t.type.id===A.TableDelimiter&&(r=er(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===A.TableHeader?i.push(tr(e,t,n,!0,r)):a===A.TableRow&&i.push(tr(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function er(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function tr(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===A.TableDelimiter,r=0;do if(t.type.id===A.TableDelimiter)r++;else if(t.type.id===A.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim())}while(t.nextSibling());t.parent()}let o=a.map(t=>{let n=e.paragraph(t);return r?e.tableHeaderCell(n):e.tableCell(n)});return e.tableRow(o)}function nr(e){return e.replace(/\n+$/u,``)}function rr(e){return e.split(`
|
|
15
|
+
`).filter(e=>e.trim()!==``)}function ir(e){let t=Mn(Wn(e));if(nr(t)===nr(e))return`exact`;let n=rr(e),r=rr(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{kn as EDITOR_KEY_BINDINGS,ir as checkRoundTrip,jn as codeBlockLanguages,On as defineBulletAfterHeading,U as defineEditorExtension,En as defineEmbedPaste,Sn as defineImages,Gt as defineMarkMode,Pe as definePlaceholder,Fe as defineReadonly,en as defineWikilinkClickHandler,Mn as docToMarkdown,Wn as markdownToDoc};
|
package/dist/style.css
CHANGED
|
@@ -395,6 +395,26 @@ img.ProseMirror-separator {
|
|
|
395
395
|
max-width: 100%;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
.ProseMirror .md-embed-wrapper {
|
|
399
|
+
margin-block: .5rem;
|
|
400
|
+
display: block;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.ProseMirror .md-embed-youtube {
|
|
404
|
+
aspect-ratio: 16 / 9;
|
|
405
|
+
border-radius: var(--meowdown-image-radius, .5rem);
|
|
406
|
+
border: 0;
|
|
407
|
+
width: 100%;
|
|
408
|
+
display: block;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.ProseMirror .md-embed-tweet {
|
|
412
|
+
border: 0;
|
|
413
|
+
width: 100%;
|
|
414
|
+
max-width: 550px;
|
|
415
|
+
display: block;
|
|
416
|
+
}
|
|
417
|
+
|
|
398
418
|
.ProseMirror .prosekit-placeholder:before {
|
|
399
419
|
content: attr(data-placeholder);
|
|
400
420
|
float: left;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"@lezer/common": "^1.5.2",
|
|
23
23
|
"@lezer/highlight": "^1.2.3",
|
|
24
24
|
"@lezer/markdown": "^1.6.4",
|
|
25
|
-
"@
|
|
26
|
-
"@prosekit/
|
|
25
|
+
"@ocavue/utils": "^1.7.0",
|
|
26
|
+
"@prosekit/core": "^0.13.0-beta.1",
|
|
27
|
+
"@prosekit/extensions": "^0.17.5-beta.2",
|
|
27
28
|
"@prosekit/pm": "^0.1.18",
|
|
28
|
-
"prosemirror-highlight": "^0.15.2"
|
|
29
|
-
"prosemirror-tables": "^1.8.5"
|
|
29
|
+
"prosemirror-highlight": "^0.15.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ocavue/tsconfig": "^0.7.1",
|