tiptap-extension-code-block-shiki 0.1.0 → 0.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
- # Shiki TipTap Extension
1
+ # Shiki Tiptap Extension
2
2
 
3
- Use [Shiki](https://shiki.style/) syntax highlighting for codeblocks in [TipTap](https://tiptap.dev/).
3
+ Use [Shiki](https://shiki.style/) syntax highlighting for codeblocks in [Tiptap](https://tiptap.dev/).
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,6 +29,10 @@ new Editor({
29
29
 
30
30
  Go into your TipTap editor, write `` ```ts ``, press <kbd>Enter</kbd>, and write some code! It loads the language on the fly.
31
31
 
32
+ ## Demo
33
+
34
+ I posted a small screen recording here: https://mastodon.social/@timomeh/112282962825285237
35
+
32
36
  ## Settings
33
37
 
34
38
  The extension extends [CodeBlock](https://tiptap.dev/docs/editor/api/nodes/code-block) and forwards its settings. It additionally adds the following settings:
@@ -55,5 +59,5 @@ When you use a language which isn't supported by Shiki, it silently falls back t
55
59
 
56
60
  Most of this library is just combining code from two other libraries:
57
61
 
58
- - [`@tiptap/extension-code-block-lowlight`](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-code-block-lowlight) by [TipTap](https://tiptap.dev)
62
+ - [`@tiptap/extension-code-block-lowlight`](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-code-block-lowlight) by [Tiptap](https://tiptap.dev)
59
63
  - [`prosemirror-highlight`](https://github.com/ocavue/prosemirror-highlight) by [ocavue](https://github.com/ocavue)
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("@tiptap/pm/state"),ee=require("@tiptap/pm/view");require("@tiptap/pm/keymap");const N=require("@tiptap/pm/model"),T=require("@tiptap/pm/transform"),k=require("@tiptap/pm/commands"),U=require("@tiptap/pm/schema-list"),K=require("shiki");function ae(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:o}=n,{storedMarks:s}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return o},get tr(){return r=n.selection,o=n.doc,s=n.storedMarks,n}}}class me{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:e,editor:n,state:r}=this,{view:o}=n,{tr:s}=r,i=this.buildProps(s);return Object.fromEntries(Object.entries(e).map(([a,c])=>[a,(...f)=>{const l=c(...f)(i);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(s),l}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,n=!0){const{rawCommands:r,editor:o,state:s}=this,{view:i}=o,a=[],c=!!e,d=e||s.tr,f=()=>(!c&&n&&!d.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(d),a.every(u=>u===!0)),l={...Object.fromEntries(Object.entries(r).map(([u,p])=>[u,(...g)=>{const y=this.buildProps(d,n),x=p(...g)(y);return a.push(x),l}])),run:f};return l}createCan(e){const{rawCommands:n,state:r}=this,o=!1,s=e||r.tr,i=this.buildProps(s,o);return{...Object.fromEntries(Object.entries(n).map(([c,d])=>[c,(...f)=>d(...f)({...i,dispatch:void 0})])),chain:()=>this.createChain(s,o)}}buildProps(e,n=!0){const{rawCommands:r,editor:o,state:s}=this,{view:i}=o,a={tr:e,editor:o,view:i,state:ae({state:s,transaction:e}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(e,n),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(r).map(([c,d])=>[c,(...f)=>d(...f)(a)]))}};return a}}function w(t,e,n){return t.config[e]===void 0&&t.parent?w(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?w(t.parent,e,n):null}):t.config[e]}function he(t){const e=t.filter(o=>o.type==="extension"),n=t.filter(o=>o.type==="node"),r=t.filter(o=>o.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function S(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}function ge(...t){return t.filter(e=>!!e).reduce((e,n)=>{const r={...e};return Object.entries(n).forEach(([o,s])=>{if(!r[o]){r[o]=s;return}if(o==="class"){const a=s?s.split(" "):[],c=r[o]?r[o].split(" "):[],d=a.filter(f=>!c.includes(f));r[o]=[...c,...d].join(" ")}else o==="style"?r[o]=[r[o],s].join("; "):r[o]=s}),r},{})}function ye(t){return typeof t=="function"}function b(t,e=void 0,...n){return ye(t)?e?t.bind(e)(...n):t(...n):t}function ke(t){return Object.prototype.toString.call(t)==="[object RegExp]"}class xe{constructor(e){this.find=e.find,this.handler=e.handler}}function Se(t){return Object.prototype.toString.call(t).slice(8,-1)}function W(t){return Se(t)!=="Object"?!1:t.constructor===Object&&Object.getPrototypeOf(t)===Object.prototype}function Q(t,e){const n={...t};return W(t)&&W(e)&&Object.keys(e).forEach(r=>{W(e[r])?r in t?n[r]=Q(t[r],e[r]):Object.assign(n,{[r]:e[r]}):Object.assign(n,{[r]:e[r]})}),n}class v{constructor(e={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=b(w(this,"addOptions",{name:this.name}))),this.storage=b(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new v(e)}configure(e={}){const n=this.extend();return n.options=Q(this.options,e),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new v({...this.config,...e});return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=b(w(n,"addOptions",{name:n.name})),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}}function we(t,e,n){const{from:r,to:o}=e,{blockSeparator:s=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("@tiptap/pm/state"),ee=require("@tiptap/pm/view");require("@tiptap/pm/keymap");const j=require("@tiptap/pm/model"),T=require("@tiptap/pm/transform"),y=require("@tiptap/pm/commands"),U=require("@tiptap/pm/schema-list"),F=require("shiki");function ae(e){const{state:t,transaction:n}=e;let{selection:o}=n,{doc:r}=n,{storedMarks:s}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return s},get selection(){return o},get doc(){return r},get tr(){return o=n.selection,r=n.doc,s=n.storedMarks,n}}}class ge{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:n,state:o}=this,{view:r}=n,{tr:s}=o,a=this.buildProps(s);return Object.fromEntries(Object.entries(t).map(([i,c])=>[i,(...u)=>{const d=c(...u)(a);return!s.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(s),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,n=!0){const{rawCommands:o,editor:r,state:s}=this,{view:a}=r,i=[],c=!!t,l=t||s.tr,u=()=>(!c&&n&&!l.getMeta("preventDispatch")&&!this.hasCustomState&&a.dispatch(l),i.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(o).map(([f,p])=>[f,(...h)=>{const k=this.buildProps(l,n),S=p(...h)(k);return i.push(S),d}])),run:u};return d}createCan(t){const{rawCommands:n,state:o}=this,r=!1,s=t||o.tr,a=this.buildProps(s,r);return{...Object.fromEntries(Object.entries(n).map(([c,l])=>[c,(...u)=>l(...u)({...a,dispatch:void 0})])),chain:()=>this.createChain(s,r)}}buildProps(t,n=!0){const{rawCommands:o,editor:r,state:s}=this,{view:a}=r,i={tr:t,editor:r,view:a,state:ae({state:s,transaction:t}),dispatch:n?()=>{}:void 0,chain:()=>this.createChain(t,n),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(o).map(([c,l])=>[c,(...u)=>l(...u)(i)]))}};return i}}function w(e,t,n){return e.config[t]===void 0&&e.parent?w(e.parent,t,n):typeof e.config[t]=="function"?e.config[t].bind({...n,parent:e.parent?w(e.parent,t,n):null}):e.config[t]}function ke(e){const t=e.filter(r=>r.type==="extension"),n=e.filter(r=>r.type==="node"),o=e.filter(r=>r.type==="mark");return{baseExtensions:t,nodeExtensions:n,markExtensions:o}}function x(e,t){if(typeof e=="string"){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}function ye(...e){return e.filter(t=>!!t).reduce((t,n)=>{const o={...t};return Object.entries(n).forEach(([r,s])=>{if(!o[r]){o[r]=s;return}if(r==="class"){const i=s?s.split(" "):[],c=o[r]?o[r].split(" "):[],l=i.filter(u=>!c.includes(u));o[r]=[...c,...l].join(" ")}else r==="style"?o[r]=[o[r],s].join("; "):o[r]=s}),o},{})}function Se(e){return typeof e=="function"}function b(e,t=void 0,...n){return Se(e)?t?e.bind(t)(...n):e(...n):e}function xe(e){return Object.prototype.toString.call(e)==="[object RegExp]"}class we{constructor(t){this.find=t.find,this.handler=t.handler}}function be(e){return Object.prototype.toString.call(e).slice(8,-1)}function H(e){return be(e)!=="Object"?!1:e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Q(e,t){const n={...e};return H(e)&&H(t)&&Object.keys(t).forEach(o=>{H(t[o])?o in e?n[o]=Q(e[o],t[o]):Object.assign(n,{[o]:t[o]}):Object.assign(n,{[o]:t[o]})}),n}class v{constructor(t={}){this.type="extension",this.name="extension",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=b(w(this,"addOptions",{name:this.name}))),this.storage=b(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new v(t)}configure(t={}){const n=this.extend();return n.options=Q(this.options,t),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new v({...this.config,...t});return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=b(w(n,"addOptions",{name:n.name})),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}}function Me(e,t,n){const{from:o,to:r}=t,{blockSeparator:s=`
2
2
 
3
- `,textSerializers:i={}}=n||{};let a="",c=!0;return t.nodesBetween(r,o,(d,f,l,u)=>{var p;const m=i==null?void 0:i[d.type.name];if(m)return d.isBlock&&!c&&(a+=s,c=!0),l&&(a+=m({node:d,pos:f,parent:l,index:u,range:e})),!1;d.isText?(a+=(p=d==null?void 0:d.text)===null||p===void 0?void 0:p.slice(Math.max(r,f)-f,o-f),c=!1):d.isBlock&&!c&&(a+=s,c=!0)}),a}function be(t){return Object.fromEntries(Object.entries(t.nodes).filter(([,e])=>e.spec.toText).map(([e,n])=>[e,n.spec.toText]))}v.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new h.Plugin({key:new h.PluginKey("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:t}=this,{state:e,schema:n}=t,{doc:r,selection:o}=e,{ranges:s}=o,i=Math.min(...s.map(f=>f.$from.pos)),a=Math.max(...s.map(f=>f.$to.pos)),c=be(n);return we(r,{from:i,to:a},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}});const Me=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Te=(t=!1)=>({commands:e})=>e.setContent("",t),Ae=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:o}=r;return n&&o.forEach(({$from:s,$to:i})=>{t.doc.nodesBetween(s.pos,i.pos,(a,c)=>{if(a.type.isText)return;const{doc:d,mapping:f}=e,l=d.resolve(f.map(c)),u=d.resolve(f.map(c+a.nodeSize)),p=l.blockRange(u);if(!p)return;const m=T.liftTarget(p);if(a.type.isTextblock){const{defaultType:g}=l.parent.contentMatchAt(l.index());e.setNodeMarkup(p.start,g)}(m||m===0)&&e.lift(p,m)})}),!0},Ce=t=>e=>t(e),ve=()=>({state:t,dispatch:e})=>k.createParagraphNear(t,e),Pe=(t,e)=>({editor:n,tr:r})=>{const{state:o}=n,s=o.doc.slice(t.from,t.to);r.deleteRange(t.from,t.to);const i=r.mapping.map(e);return r.insert(i,s.content),r.setSelection(new h.TextSelection(r.doc.resolve(i-1))),!0},Ee=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const o=t.selection.$anchor;for(let s=o.depth;s>0;s-=1)if(o.node(s).type===r.type){if(e){const a=o.before(s),c=o.after(s);t.delete(a,c).scrollIntoView()}return!0}return!1},Be=t=>({tr:e,state:n,dispatch:r})=>{const o=S(t,n.schema),s=e.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===o){if(r){const c=s.before(i),d=s.after(i);e.delete(c,d).scrollIntoView()}return!0}return!1},Ie=t=>({tr:e,dispatch:n})=>{const{from:r,to:o}=t;return n&&e.delete(r,o),!0},Oe=()=>({state:t,dispatch:e})=>k.deleteSelection(t,e),Ne=()=>({commands:t})=>t.keyboardShortcut("Enter"),je=()=>({state:t,dispatch:e})=>k.exitCode(t,e);function R(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(o=>n.strict?e[o]===t[o]:ke(e[o])?e[o].test(t[o]):e[o]===t[o]):!0}function _(t,e,n={}){return t.find(r=>r.type===e&&R(r.attrs,n))}function $e(t,e,n={}){return!!_(t,e,n)}function ce(t,e,n={}){if(!t||!e)return;let r=t.parent.childAfter(t.parentOffset);if(t.parentOffset===r.offset&&r.offset!==0&&(r=t.parent.childBefore(t.parentOffset)),!r.node)return;const o=_([...r.node.marks],e,n);if(!o)return;let s=r.index,i=t.start()+r.offset,a=s+1,c=i+r.node.nodeSize;for(_([...r.node.marks],e,n);s>0&&o.isInSet(t.parent.child(s-1).marks);)s-=1,i-=t.parent.child(s).nodeSize;for(;a<t.parent.childCount&&$e([...t.parent.child(a).marks],e,n);)c+=t.parent.child(a).nodeSize,a+=1;return{from:i,to:c}}function I(t,e){if(typeof t=="string"){if(!e.marks[t])throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);return e.marks[t]}return t}const Fe=(t,e={})=>({tr:n,state:r,dispatch:o})=>{const s=I(t,r.schema),{doc:i,selection:a}=n,{$from:c,from:d,to:f}=a;if(o){const l=ce(c,s,e);if(l&&l.from<=d&&l.to>=f){const u=h.TextSelection.create(i,l.from,l.to);n.setSelection(u)}}return!0},Re=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r<n.length;r+=1)if(n[r](e))return!0;return!1};function le(t){return t instanceof h.TextSelection}function O(t=0,e=0,n=0){return Math.min(Math.max(t,e),n)}function Le(t,e=null){if(!e)return null;const n=h.Selection.atStart(t),r=h.Selection.atEnd(t);if(e==="start"||e===!0)return n;if(e==="end")return r;const o=n.from,s=r.to;return e==="all"?h.TextSelection.create(t,O(0,o,s),O(t.content.size,o,s)):h.TextSelection.create(t,O(e,o,s),O(e,o,s))}function X(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const ze=(t=null,e={})=>({editor:n,view:r,tr:o,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{X()&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e!=null&&e.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(s&&t===null&&!le(n.state.selection))return i(),!0;const a=Le(o.doc,t)||n.state.selection,c=n.state.selection.eq(a);return s&&(c||o.setSelection(a),c&&o.storedMarks&&o.setStoredMarks(o.storedMarks),i()),!0},De=(t,e)=>n=>t.every((r,o)=>e(r,{...n,index:o})),Ke=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),de=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const r=e[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?t.removeChild(r):r.nodeType===1&&de(r)}return t};function te(t){const e=`<body>${t}</body>`,n=new window.DOMParser().parseFromString(e,"text/html").body;return de(n)}function L(t,e,n){if(n={slice:!0,parseOptions:{},...n},typeof t=="object"&&t!==null)try{return Array.isArray(t)&&t.length>0?N.Fragment.fromArray(t.map(r=>e.nodeFromJSON(r))):e.nodeFromJSON(t)}catch(r){return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",r),L("",e,n)}if(typeof t=="string"){const r=N.DOMParser.fromSchema(e);return n.slice?r.parseSlice(te(t),n.parseOptions).content:r.parse(te(t),n.parseOptions)}return L("",e,n)}function We(t,e,n){const r=t.steps.length-1;if(r<e)return;const o=t.steps[r];if(!(o instanceof T.ReplaceStep||o instanceof T.ReplaceAroundStep))return;const s=t.mapping.maps[r];let i=0;s.forEach((a,c,d,f)=>{i===0&&(i=f)}),t.setSelection(h.Selection.near(t.doc.resolve(i),n))}const He=t=>t.toString().startsWith("<"),Ve=(t,e,n)=>({tr:r,dispatch:o,editor:s})=>{if(o){n={parseOptions:{},updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};const i=L(e,s.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(i.toString()==="<>")return!0;let{from:a,to:c}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},d=!0,f=!0;if((He(i)?i:[i]).forEach(p=>{p.check(),d=d?p.isText&&p.marks.length===0:!1,f=f?p.isBlock:!1}),a===c&&f){const{parent:p}=r.doc.resolve(a);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(a-=1,c+=1)}let u;d?(Array.isArray(e)?u=e.map(p=>p.text||"").join(""):typeof e=="object"&&e&&e.text?u=e.text:u=e,r.insertText(u,a,c)):(u=i,r.replaceWith(a,c,u)),n.updateSelection&&We(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:a,text:u}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:a,text:u})}return!0},qe=()=>({state:t,dispatch:e})=>k.joinUp(t,e),_e=()=>({state:t,dispatch:e})=>k.joinDown(t,e),Je=()=>({state:t,dispatch:e})=>k.joinBackward(t,e),Ge=()=>({state:t,dispatch:e})=>k.joinForward(t,e),Ue=()=>({tr:t,state:e,dispatch:n})=>{try{const r=T.joinPoint(e.doc,e.selection.$from.pos,-1);return r==null?!1:(t.join(r,2),n&&n(t),!0)}catch{return!1}},Qe=()=>({state:t,dispatch:e,tr:n})=>{try{const r=T.joinPoint(t.doc,t.selection.$from.pos,1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},Xe=()=>({state:t,dispatch:e})=>k.joinTextblockBackward(t,e),Ye=()=>({state:t,dispatch:e})=>k.joinTextblockForward(t,e);function ue(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Ze(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,o,s,i;for(let a=0;a<e.length-1;a+=1){const c=e[a];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))o=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))X()||ue()?i=!0:o=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return r&&(n=`Alt-${n}`),o&&(n=`Ctrl-${n}`),i&&(n=`Meta-${n}`),s&&(n=`Shift-${n}`),n}const et=t=>({editor:e,view:n,tr:r,dispatch:o})=>{const s=Ze(t).split(/-(?!$)/),i=s.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),a=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),c=e.captureTransaction(()=>{n.someProp("handleKeyDown",d=>d(n,a))});return c==null||c.steps.forEach(d=>{const f=d.map(r.mapping);f&&o&&r.maybeStep(f)}),!0};function Y(t,e,n={}){const{from:r,to:o,empty:s}=t.selection,i=e?S(e,t.schema):null,a=[];t.doc.nodesBetween(r,o,(l,u)=>{if(l.isText)return;const p=Math.max(r,u),m=Math.min(o,u+l.nodeSize);a.push({node:l,from:p,to:m})});const c=o-r,d=a.filter(l=>i?i.name===l.node.type.name:!0).filter(l=>R(l.node.attrs,n,{strict:!1}));return s?!!d.length:d.reduce((l,u)=>l+u.to-u.from,0)>=c}const tt=(t,e={})=>({state:n,dispatch:r})=>{const o=S(t,n.schema);return Y(n,o,e)?k.lift(n,r):!1},nt=()=>({state:t,dispatch:e})=>k.liftEmptyBlock(t,e),rt=t=>({state:e,dispatch:n})=>{const r=S(t,e.schema);return U.liftListItem(r)(e,n)},ot=()=>({state:t,dispatch:e})=>k.newlineInCode(t,e);function fe(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function ne(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,o)=>(n.includes(o)||(r[o]=t[o]),r),{})}const st=(t,e)=>({tr:n,state:r,dispatch:o})=>{let s=null,i=null;const a=fe(typeof t=="string"?t:t.name,r.schema);return a?(a==="node"&&(s=S(t,r.schema)),a==="mark"&&(i=I(t,r.schema)),o&&n.selection.ranges.forEach(c=>{r.doc.nodesBetween(c.$from.pos,c.$to.pos,(d,f)=>{s&&s===d.type&&n.setNodeMarkup(f,void 0,ne(d.attrs,e)),i&&d.marks.length&&d.marks.forEach(l=>{i===l.type&&n.addMark(f,f+d.nodeSize,i.create(ne(l.attrs,e)))})})}),!0):!1},it=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),at=()=>({tr:t,commands:e})=>e.setTextSelection({from:0,to:t.doc.content.size}),ct=()=>({state:t,dispatch:e})=>k.selectNodeBackward(t,e),lt=()=>({state:t,dispatch:e})=>k.selectNodeForward(t,e),dt=()=>({state:t,dispatch:e})=>k.selectParentNode(t,e),ut=()=>({state:t,dispatch:e})=>k.selectTextblockEnd(t,e),ft=()=>({state:t,dispatch:e})=>k.selectTextblockStart(t,e);function pt(t,e,n={}){return L(t,e,{slice:!1,parseOptions:n})}const mt=(t,e=!1,n={})=>({tr:r,editor:o,dispatch:s})=>{const{doc:i}=r,a=pt(t,o.schema,n);return s&&r.replaceWith(0,i.content.size,a).setMeta("preventUpdate",!e),!0};function ht(t,e){const n=I(e,t.schema),{from:r,to:o,empty:s}=t.selection,i=[];s?(t.storedMarks&&i.push(...t.storedMarks),i.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,o,c=>{i.push(...c.marks)});const a=i.find(c=>c.type.name===n.name);return a?{...a.attrs}:{}}function gt(t){for(let e=0;e<t.edgeCount;e+=1){const{type:n}=t.edge(e);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function J(t,e){const n=[];return t.descendants((r,o)=>{e(r)&&n.push({node:r,pos:o})}),n}function yt(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function Z(t){return e=>yt(e.$from,t)}function F(t,e,n){return Object.fromEntries(Object.entries(n).filter(([r])=>{const o=t.find(s=>s.type===e&&s.name===r);return o?o.attribute.keepOnSplit:!1}))}function kt(t,e,n={}){const{empty:r,ranges:o}=t.selection,s=e?I(e,t.schema):null;if(r)return!!(t.storedMarks||t.selection.$from.marks()).filter(l=>s?s.name===l.type.name:!0).find(l=>R(l.attrs,n,{strict:!1}));let i=0;const a=[];if(o.forEach(({$from:l,$to:u})=>{const p=l.pos,m=u.pos;t.doc.nodesBetween(p,m,(g,y)=>{if(!g.isText&&!g.marks.length)return;const x=Math.max(p,y),P=Math.min(m,y+g.nodeSize),A=P-x;i+=A,a.push(...g.marks.map(E=>({mark:E,from:x,to:P})))})}),i===0)return!1;const c=a.filter(l=>s?s.name===l.mark.type.name:!0).filter(l=>R(l.mark.attrs,n,{strict:!1})).reduce((l,u)=>l+u.to-u.from,0),d=a.filter(l=>s?l.mark.type!==s&&l.mark.type.excludes(s):!0).reduce((l,u)=>l+u.to-u.from,0);return(c>0?c+d:c)>=i}function re(t,e){const{nodeExtensions:n}=he(e),r=n.find(i=>i.name===t);if(!r)return!1;const o={name:r.name,options:r.options,storage:r.storage},s=b(w(r,"group",o));return typeof s!="string"?!1:s.split(" ").includes("list")}function xt(t,e,n){var r;const{selection:o}=e;let s=null;if(le(o)&&(s=o.$cursor),s){const a=(r=t.storedMarks)!==null&&r!==void 0?r:s.marks();return!!n.isInSet(a)||!a.some(c=>c.type.excludes(n))}const{ranges:i}=o;return i.some(({$from:a,$to:c})=>{let d=a.depth===0?t.doc.inlineContent&&t.doc.type.allowsMarkType(n):!1;return t.doc.nodesBetween(a.pos,c.pos,(f,l,u)=>{if(d)return!1;if(f.isInline){const p=!u||u.type.allowsMarkType(n),m=!!n.isInSet(f.marks)||!f.marks.some(g=>g.type.excludes(n));d=p&&m}return!d}),d})}const St=(t,e={})=>({tr:n,state:r,dispatch:o})=>{const{selection:s}=n,{empty:i,ranges:a}=s,c=I(t,r.schema);if(o)if(i){const d=ht(r,c);n.addStoredMark(c.create({...d,...e}))}else a.forEach(d=>{const f=d.$from.pos,l=d.$to.pos;r.doc.nodesBetween(f,l,(u,p)=>{const m=Math.max(p,f),g=Math.min(p+u.nodeSize,l);u.marks.find(x=>x.type===c)?u.marks.forEach(x=>{c===x.type&&n.addMark(m,g,c.create({...x.attrs,...e}))}):n.addMark(m,g,c.create(e))})});return xt(r,n,c)},wt=(t,e)=>({tr:n})=>(n.setMeta(t,e),!0),bt=(t,e={})=>({state:n,dispatch:r,chain:o})=>{const s=S(t,n.schema);return s.isTextblock?o().command(({commands:i})=>k.setBlockType(s,e)(n)?!0:i.clearNodes()).command(({state:i})=>k.setBlockType(s,e)(i,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Mt=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,o=O(t,0,r.content.size),s=h.NodeSelection.create(r,o);e.setSelection(s)}return!0},Tt=t=>({tr:e,dispatch:n})=>{if(n){const{doc:r}=e,{from:o,to:s}=typeof t=="number"?{from:t,to:t}:t,i=h.TextSelection.atStart(r).from,a=h.TextSelection.atEnd(r).to,c=O(o,i,a),d=O(s,i,a),f=h.TextSelection.create(r,c,d);e.setSelection(f)}return!0},At=t=>({state:e,dispatch:n})=>{const r=S(t,e.schema);return U.sinkListItem(r)(e,n)};function oe(t,e){const n=t.storedMarks||t.selection.$to.parentOffset&&t.selection.$from.marks();if(n){const r=n.filter(o=>e==null?void 0:e.includes(o.type.name));t.tr.ensureMarks(r)}}const Ct=({keepMarks:t=!0}={})=>({tr:e,state:n,dispatch:r,editor:o})=>{const{selection:s,doc:i}=e,{$from:a,$to:c}=s,d=o.extensionManager.attributes,f=F(d,a.node().type.name,a.node().attrs);if(s instanceof h.NodeSelection&&s.node.isBlock)return!a.parentOffset||!T.canSplit(i,a.pos)?!1:(r&&(t&&oe(n,o.extensionManager.splittableMarks),e.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;if(r){const l=c.parentOffset===c.parent.content.size;s instanceof h.TextSelection&&e.deleteSelection();const u=a.depth===0?void 0:gt(a.node(-1).contentMatchAt(a.indexAfter(-1)));let p=l&&u?[{type:u,attrs:f}]:void 0,m=T.canSplit(e.doc,e.mapping.map(a.pos),1,p);if(!p&&!m&&T.canSplit(e.doc,e.mapping.map(a.pos),1,u?[{type:u}]:void 0)&&(m=!0,p=u?[{type:u,attrs:f}]:void 0),m&&(e.split(e.mapping.map(a.pos),1,p),u&&!l&&!a.parentOffset&&a.parent.type!==u)){const g=e.mapping.map(a.before()),y=e.doc.resolve(g);a.node(-1).canReplaceWith(y.index(),y.index()+1,u)&&e.setNodeMarkup(e.mapping.map(a.before()),u)}t&&oe(n,o.extensionManager.splittableMarks),e.scrollIntoView()}return!0},vt=t=>({tr:e,state:n,dispatch:r,editor:o})=>{var s;const i=S(t,n.schema),{$from:a,$to:c}=n.selection,d=n.selection.node;if(d&&d.isBlock||a.depth<2||!a.sameParent(c))return!1;const f=a.node(-1);if(f.type!==i)return!1;const l=o.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==i||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let y=N.Fragment.empty;const x=a.index(-1)?1:a.index(-2)?2:3;for(let B=a.depth-x;B>=a.depth-3;B-=1)y=N.Fragment.from(a.node(B).copy(y));const P=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,A=F(l,a.node().type.name,a.node().attrs),E=((s=i.contentMatch.defaultType)===null||s===void 0?void 0:s.createAndFill(A))||void 0;y=y.append(N.Fragment.from(i.createAndFill(null,E)||void 0));const M=a.before(a.depth-(x-1));e.replace(M,a.after(-P),new N.Slice(y,4-x,0));let C=-1;e.doc.nodesBetween(M,e.doc.content.size,(B,D)=>{if(C>-1)return!1;B.isTextblock&&B.content.size===0&&(C=D+1)}),C>-1&&e.setSelection(h.TextSelection.near(e.doc.resolve(C))),e.scrollIntoView()}return!0}const u=c.pos===a.end()?f.contentMatchAt(0).defaultType:null,p=F(l,f.type.name,f.attrs),m=F(l,a.node().type.name,a.node().attrs);e.delete(a.pos,c.pos);const g=u?[{type:i,attrs:p},{type:u,attrs:m}]:[{type:i,attrs:p}];if(!T.canSplit(e.doc,a.pos,2))return!1;if(r){const{selection:y,storedMarks:x}=n,{splittableMarks:P}=o.extensionManager,A=x||y.$to.parentOffset&&y.$from.marks();if(e.split(a.pos,2,g).scrollIntoView(),!A||!r)return!0;const E=A.filter(M=>P.includes(M.type.name));e.ensureMarks(E)}return!0},H=(t,e)=>{const n=Z(i=>i.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;const o=t.doc.nodeAt(r);return n.node.type===(o==null?void 0:o.type)&&T.canJoin(t.doc,n.pos)&&t.join(n.pos),!0},V=(t,e)=>{const n=Z(i=>i.type===e)(t.selection);if(!n)return!0;const r=t.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;const o=t.doc.nodeAt(r);return n.node.type===(o==null?void 0:o.type)&&T.canJoin(t.doc,r)&&t.join(r),!0},Pt=(t,e,n,r={})=>({editor:o,tr:s,state:i,dispatch:a,chain:c,commands:d,can:f})=>{const{extensions:l,splittableMarks:u}=o.extensionManager,p=S(t,i.schema),m=S(e,i.schema),{selection:g,storedMarks:y}=i,{$from:x,$to:P}=g,A=x.blockRange(P),E=y||g.$to.parentOffset&&g.$from.marks();if(!A)return!1;const M=Z(C=>re(C.type.name,l))(g);if(A.depth>=1&&M&&A.depth-M.depth<=1){if(M.node.type===p)return d.liftListItem(m);if(re(M.node.type.name,l)&&p.validContent(M.node.content)&&a)return c().command(()=>(s.setNodeMarkup(M.pos,p),!0)).command(()=>H(s,p)).command(()=>V(s,p)).run()}return!n||!E||!a?c().command(()=>f().wrapInList(p,r)?!0:d.clearNodes()).wrapInList(p,r).command(()=>H(s,p)).command(()=>V(s,p)).run():c().command(()=>{const C=f().wrapInList(p,r),B=E.filter(D=>u.includes(D.type.name));return s.ensureMarks(B),C?!0:d.clearNodes()}).wrapInList(p,r).command(()=>H(s,p)).command(()=>V(s,p)).run()},Et=(t,e={},n={})=>({state:r,commands:o})=>{const{extendEmptyMarkRange:s=!1}=n,i=I(t,r.schema);return kt(r,i,e)?o.unsetMark(i,{extendEmptyMarkRange:s}):o.setMark(i,e)},Bt=(t,e,n={})=>({state:r,commands:o})=>{const s=S(t,r.schema),i=S(e,r.schema);return Y(r,s,n)?o.setNode(i):o.setNode(s,n)},It=(t,e={})=>({state:n,commands:r})=>{const o=S(t,n.schema);return Y(n,o,e)?r.lift(o):r.wrapIn(o,e)},Ot=()=>({state:t,dispatch:e})=>{const n=t.plugins;for(let r=0;r<n.length;r+=1){const o=n[r];let s;if(o.spec.isInputRules&&(s=o.getState(t))){if(e){const i=t.tr,a=s.transform;for(let c=a.steps.length-1;c>=0;c-=1)i.step(a.steps[c].invert(a.docs[c]));if(s.text){const c=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,t.schema.text(s.text,c))}else i.delete(s.from,s.to)}return!0}}return!1},Nt=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,{empty:r,ranges:o}=n;return r||e&&o.forEach(s=>{t.removeMark(s.$from.pos,s.$to.pos)}),!0},jt=(t,e={})=>({tr:n,state:r,dispatch:o})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:a}=n,c=I(t,r.schema),{$from:d,empty:f,ranges:l}=a;if(!o)return!0;if(f&&i){let{from:u,to:p}=a;const m=(s=d.marks().find(y=>y.type===c))===null||s===void 0?void 0:s.attrs,g=ce(d,c,m);g&&(u=g.from,p=g.to),n.removeMark(u,p,c)}else l.forEach(u=>{n.removeMark(u.$from.pos,u.$to.pos,c)});return n.removeStoredMark(c),!0},$t=(t,e={})=>({tr:n,state:r,dispatch:o})=>{let s=null,i=null;const a=fe(typeof t=="string"?t:t.name,r.schema);return a?(a==="node"&&(s=S(t,r.schema)),a==="mark"&&(i=I(t,r.schema)),o&&n.selection.ranges.forEach(c=>{const d=c.$from.pos,f=c.$to.pos;r.doc.nodesBetween(d,f,(l,u)=>{s&&s===l.type&&n.setNodeMarkup(u,void 0,{...l.attrs,...e}),i&&l.marks.length&&l.marks.forEach(p=>{if(i===p.type){const m=Math.max(u,d),g=Math.min(u+l.nodeSize,f);n.addMark(m,g,i.create({...p.attrs,...e}))}})})}),!0):!1},Ft=(t,e={})=>({state:n,dispatch:r})=>{const o=S(t,n.schema);return k.wrapIn(o,e)(n,r)},Rt=(t,e={})=>({state:n,dispatch:r})=>{const o=S(t,n.schema);return U.wrapInList(o,e)(n,r)};var Lt=Object.freeze({__proto__:null,blur:Me,clearContent:Te,clearNodes:Ae,command:Ce,createParagraphNear:ve,cut:Pe,deleteCurrentNode:Ee,deleteNode:Be,deleteRange:Ie,deleteSelection:Oe,enter:Ne,exitCode:je,extendMarkRange:Fe,first:Re,focus:ze,forEach:De,insertContent:Ke,insertContentAt:Ve,joinUp:qe,joinDown:_e,joinBackward:Je,joinForward:Ge,joinItemBackward:Ue,joinItemForward:Qe,joinTextblockBackward:Xe,joinTextblockForward:Ye,keyboardShortcut:et,lift:tt,liftEmptyBlock:nt,liftListItem:rt,newlineInCode:ot,resetAttributes:st,scrollIntoView:it,selectAll:at,selectNodeBackward:ct,selectNodeForward:lt,selectParentNode:dt,selectTextblockEnd:ut,selectTextblockStart:ft,setContent:mt,setMark:St,setMeta:wt,setNode:bt,setNodeSelection:Mt,setTextSelection:Tt,sinkListItem:At,splitBlock:Ct,splitListItem:vt,toggleList:Pt,toggleMark:Et,toggleNode:Bt,toggleWrap:It,undoInputRule:Ot,unsetAllMarks:Nt,unsetMark:jt,updateAttributes:$t,wrapIn:Ft,wrapInList:Rt});v.create({name:"commands",addCommands(){return{...Lt}}});v.create({name:"editable",addProseMirrorPlugins(){return[new h.Plugin({key:new h.PluginKey("editable"),props:{editable:()=>this.editor.options.editable}})]}});v.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:t}=this;return[new h.Plugin({key:new h.PluginKey("focusEvents"),props:{handleDOMEvents:{focus:(e,n)=>{t.isFocused=!0;const r=t.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1},blur:(e,n)=>{t.isFocused=!1;const r=t.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return e.dispatch(r),!1}}}})]}});v.create({name:"keymap",addKeyboardShortcuts(){const t=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:a})=>{const{selection:c,doc:d}=a,{empty:f,$anchor:l}=c,{pos:u,parent:p}=l,m=l.parent.isTextblock&&u>0?a.doc.resolve(u-1):l,g=m.parent.type.spec.isolating,y=l.pos-l.parentOffset,x=g&&m.parent.childCount===1?y===l.pos:h.Selection.atStart(d).from===u;return!f||!x||!p.type.isTextblock||p.textContent.length?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),r={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:t,"Mod-Backspace":t,"Shift-Backspace":t,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},o={...r},s={...r,"Ctrl-h":t,"Alt-Backspace":t,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return X()||ue()?s:o},addProseMirrorPlugins(){return[new h.Plugin({key:new h.PluginKey("clearDocument"),appendTransaction:(t,e,n)=>{if(!(t.some(m=>m.docChanged)&&!e.doc.eq(n.doc)))return;const{empty:o,from:s,to:i}=e.selection,a=h.Selection.atStart(e.doc).from,c=h.Selection.atEnd(e.doc).to;if(o||!(s===a&&i===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const l=n.tr,u=ae({state:n,transaction:l}),{commands:p}=new me({editor:this.editor,state:u});if(p.clearNodes(),!!l.steps.length)return l}})]}});v.create({name:"tabindex",addProseMirrorPlugins(){return[new h.Plugin({key:new h.PluginKey("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});function se(t){return new xe({find:t.find,handler:({state:e,range:n,match:r})=>{const o=e.doc.resolve(n.from),s=b(t.getAttributes,void 0,r)||{};if(!o.node(-1).canReplaceWith(o.index(-1),o.indexAfter(-1),t.type))return null;e.tr.delete(n.from,n.to).setBlockType(n.from,n.from,t.type,s)}})}class z{constructor(e={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...e},this.name=this.config.name,e.defaultOptions&&Object.keys(e.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=b(w(this,"addOptions",{name:this.name}))),this.storage=b(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(e={}){return new z(e)}configure(e={}){const n=this.extend();return n.options=Q(this.options,e),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}extend(e={}){const n=new z({...this.config,...e});return n.parent=this,this.child=n,n.name=e.name?e.name:n.parent.name,e.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=b(w(n,"addOptions",{name:n.name})),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}}const zt=/^```([a-z]+)?[\s\n]$/,Dt=/^~~~([a-z]+)?[\s\n]$/,Kt=z.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:null,parseHTML:t=>{var e;const{languageClassPrefix:n}=this.options,s=[...((e=t.firstElementChild)===null||e===void 0?void 0:e.classList)||[]].filter(i=>i.startsWith(n)).map(i=>i.replace(n,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:t,HTMLAttributes:e}){return["pre",ge(this.options.HTMLAttributes,e),["code",{class:t.attrs.language?this.options.languageClassPrefix+t.attrs.language:null},0]]},addCommands(){return{setCodeBlock:t=>({commands:e})=>e.setNode(this.name,t),toggleCodeBlock:t=>({commands:e})=>e.toggleNode(this.name,"paragraph",t)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:t,$anchor:e}=this.editor.state.selection,n=e.pos===1;return!t||e.parent.type.name!==this.name?!1:n||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:t})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=t,{selection:n}=e,{$from:r,empty:o}=n;if(!o||r.parent.type!==this.type)return!1;const s=r.parentOffset===r.parent.nodeSize-2,i=r.parent.textContent.endsWith(`
3
+ `,textSerializers:a={}}=n||{};let i="",c=!0;return e.nodesBetween(o,r,(l,u,d,f)=>{var p;const m=a==null?void 0:a[l.type.name];if(m)return l.isBlock&&!c&&(i+=s,c=!0),d&&(i+=m({node:l,pos:u,parent:d,index:f,range:t})),!1;l.isText?(i+=(p=l==null?void 0:l.text)===null||p===void 0?void 0:p.slice(Math.max(o,u)-u,r-u),c=!1):l.isBlock&&!c&&(i+=s,c=!0)}),i}function Te(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,t])=>t.spec.toText).map(([t,n])=>[t,n.spec.toText]))}v.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new g.Plugin({key:new g.PluginKey("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:e}=this,{state:t,schema:n}=e,{doc:o,selection:r}=t,{ranges:s}=r,a=Math.min(...s.map(u=>u.$from.pos)),i=Math.max(...s.map(u=>u.$to.pos)),c=Te(n);return Me(o,{from:a,to:i},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}});const Ae=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),(n=window==null?void 0:window.getSelection())===null||n===void 0||n.removeAllRanges())}),!0),Ce=(e=!1)=>({commands:t})=>t.setContent("",e),Pe=()=>({state:e,tr:t,dispatch:n})=>{const{selection:o}=t,{ranges:r}=o;return n&&r.forEach(({$from:s,$to:a})=>{e.doc.nodesBetween(s.pos,a.pos,(i,c)=>{if(i.type.isText)return;const{doc:l,mapping:u}=t,d=l.resolve(u.map(c)),f=l.resolve(u.map(c+i.nodeSize)),p=d.blockRange(f);if(!p)return;const m=T.liftTarget(p);if(i.type.isTextblock){const{defaultType:h}=d.parent.contentMatchAt(d.index());t.setNodeMarkup(p.start,h)}(m||m===0)&&t.lift(p,m)})}),!0},ve=e=>t=>e(t),Ee=()=>({state:e,dispatch:t})=>y.createParagraphNear(e,t),Be=(e,t)=>({editor:n,tr:o})=>{const{state:r}=n,s=r.doc.slice(e.from,e.to);o.deleteRange(e.from,e.to);const a=o.mapping.map(t);return o.insert(a,s.content),o.setSelection(new g.TextSelection(o.doc.resolve(a-1))),!0},Ie=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,o=n.$anchor.node();if(o.content.size>0)return!1;const r=e.selection.$anchor;for(let s=r.depth;s>0;s-=1)if(r.node(s).type===o.type){if(t){const i=r.before(s),c=r.after(s);e.delete(i,c).scrollIntoView()}return!0}return!1},Oe=e=>({tr:t,state:n,dispatch:o})=>{const r=x(e,n.schema),s=t.selection.$anchor;for(let a=s.depth;a>0;a-=1)if(s.node(a).type===r){if(o){const c=s.before(a),l=s.after(a);t.delete(c,l).scrollIntoView()}return!0}return!1},Ne=e=>({tr:t,dispatch:n})=>{const{from:o,to:r}=e;return n&&t.delete(o,r),!0},je=()=>({state:e,dispatch:t})=>y.deleteSelection(e,t),$e=()=>({commands:e})=>e.keyboardShortcut("Enter"),Fe=()=>({state:e,dispatch:t})=>y.exitCode(e,t);function D(e,t,n={strict:!0}){const o=Object.keys(t);return o.length?o.every(r=>n.strict?t[r]===e[r]:xe(t[r])?t[r].test(e[r]):t[r]===e[r]):!0}function G(e,t,n={}){return e.find(o=>o.type===t&&D(o.attrs,n))}function Le(e,t,n={}){return!!G(e,t,n)}function ce(e,t,n={}){if(!e||!t)return;let o=e.parent.childAfter(e.parentOffset);if(e.parentOffset===o.offset&&o.offset!==0&&(o=e.parent.childBefore(e.parentOffset)),!o.node)return;const r=G([...o.node.marks],t,n);if(!r)return;let s=o.index,a=e.start()+o.offset,i=s+1,c=a+o.node.nodeSize;for(G([...o.node.marks],t,n);s>0&&r.isInSet(e.parent.child(s-1).marks);)s-=1,a-=e.parent.child(s).nodeSize;for(;i<e.parent.childCount&&Le([...e.parent.child(i).marks],t,n);)c+=e.parent.child(i).nodeSize,i+=1;return{from:a,to:c}}function O(e,t){if(typeof e=="string"){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}const Re=(e,t={})=>({tr:n,state:o,dispatch:r})=>{const s=O(e,o.schema),{doc:a,selection:i}=n,{$from:c,from:l,to:u}=i;if(r){const d=ce(c,s,t);if(d&&d.from<=l&&d.to>=u){const f=g.TextSelection.create(a,d.from,d.to);n.setSelection(f)}}return!0},De=e=>t=>{const n=typeof e=="function"?e(t):e;for(let o=0;o<n.length;o+=1)if(n[o](t))return!0;return!1};function le(e){return e instanceof g.TextSelection}function N(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function ze(e,t=null){if(!t)return null;const n=g.Selection.atStart(e),o=g.Selection.atEnd(e);if(t==="start"||t===!0)return n;if(t==="end")return o;const r=n.from,s=o.to;return t==="all"?g.TextSelection.create(e,N(0,r,s),N(e.content.size,r,s)):g.TextSelection.create(e,N(t,r,s),N(t,r,s))}function X(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}const Ke=(e=null,t={})=>({editor:n,view:o,tr:r,dispatch:s})=>{t={scrollIntoView:!0,...t};const a=()=>{X()&&o.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(o.focus(),t!=null&&t.scrollIntoView&&n.commands.scrollIntoView())})};if(o.hasFocus()&&e===null||e===!1)return!0;if(s&&e===null&&!le(n.state.selection))return a(),!0;const i=ze(r.doc,e)||n.state.selection,c=n.state.selection.eq(i);return s&&(c||r.setSelection(i),c&&r.storedMarks&&r.setStoredMarks(r.storedMarks),a()),!0},We=(e,t)=>n=>e.every((o,r)=>t(o,{...n,index:r})),He=(e,t)=>({tr:n,commands:o})=>o.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),de=e=>{const t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){const o=t[n];o.nodeType===3&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?e.removeChild(o):o.nodeType===1&&de(o)}return e};function te(e){const t=`<body>${e}</body>`,n=new window.DOMParser().parseFromString(t,"text/html").body;return de(n)}function z(e,t,n){if(n={slice:!0,parseOptions:{},...n},typeof e=="object"&&e!==null)try{return Array.isArray(e)&&e.length>0?j.Fragment.fromArray(e.map(o=>t.nodeFromJSON(o))):t.nodeFromJSON(e)}catch(o){return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",o),z("",t,n)}if(typeof e=="string"){const o=j.DOMParser.fromSchema(t);return n.slice?o.parseSlice(te(e),n.parseOptions).content:o.parse(te(e),n.parseOptions)}return z("",t,n)}function Ve(e,t,n){const o=e.steps.length-1;if(o<t)return;const r=e.steps[o];if(!(r instanceof T.ReplaceStep||r instanceof T.ReplaceAroundStep))return;const s=e.mapping.maps[o];let a=0;s.forEach((i,c,l,u)=>{a===0&&(a=u)}),e.setSelection(g.Selection.near(e.doc.resolve(a),n))}const qe=e=>e.toString().startsWith("<"),_e=(e,t,n)=>({tr:o,dispatch:r,editor:s})=>{if(r){n={parseOptions:{},updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};const a=z(t,s.schema,{parseOptions:{preserveWhitespace:"full",...n.parseOptions}});if(a.toString()==="<>")return!0;let{from:i,to:c}=typeof e=="number"?{from:e,to:e}:{from:e.from,to:e.to},l=!0,u=!0;if((qe(a)?a:[a]).forEach(p=>{p.check(),l=l?p.isText&&p.marks.length===0:!1,u=u?p.isBlock:!1}),i===c&&u){const{parent:p}=o.doc.resolve(i);p.isTextblock&&!p.type.spec.code&&!p.childCount&&(i-=1,c+=1)}let f;l?(Array.isArray(t)?f=t.map(p=>p.text||"").join(""):typeof t=="object"&&t&&t.text?f=t.text:f=t,o.insertText(f,i,c)):(f=a,o.replaceWith(i,c,f)),n.updateSelection&&Ve(o,o.steps.length-1,-1),n.applyInputRules&&o.setMeta("applyInputRules",{from:i,text:f}),n.applyPasteRules&&o.setMeta("applyPasteRules",{from:i,text:f})}return!0},Je=()=>({state:e,dispatch:t})=>y.joinUp(e,t),Ge=()=>({state:e,dispatch:t})=>y.joinDown(e,t),Ue=()=>({state:e,dispatch:t})=>y.joinBackward(e,t),Qe=()=>({state:e,dispatch:t})=>y.joinForward(e,t),Xe=()=>({tr:e,state:t,dispatch:n})=>{try{const o=T.joinPoint(t.doc,t.selection.$from.pos,-1);return o==null?!1:(e.join(o,2),n&&n(e),!0)}catch{return!1}},Ye=()=>({state:e,dispatch:t,tr:n})=>{try{const o=T.joinPoint(e.doc,e.selection.$from.pos,1);return o==null?!1:(n.join(o,2),t&&t(n),!0)}catch{return!1}},Ze=()=>({state:e,dispatch:t})=>y.joinTextblockBackward(e,t),et=()=>({state:e,dispatch:t})=>y.joinTextblockForward(e,t);function ue(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function tt(e){const t=e.split(/-(?!$)/);let n=t[t.length-1];n==="Space"&&(n=" ");let o,r,s,a;for(let i=0;i<t.length-1;i+=1){const c=t[i];if(/^(cmd|meta|m)$/i.test(c))a=!0;else if(/^a(lt)?$/i.test(c))o=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))X()||ue()?a=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return o&&(n=`Alt-${n}`),r&&(n=`Ctrl-${n}`),a&&(n=`Meta-${n}`),s&&(n=`Shift-${n}`),n}const nt=e=>({editor:t,view:n,tr:o,dispatch:r})=>{const s=tt(e).split(/-(?!$)/),a=s.find(l=>!["Alt","Ctrl","Meta","Shift"].includes(l)),i=new KeyboardEvent("keydown",{key:a==="Space"?" ":a,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),c=t.captureTransaction(()=>{n.someProp("handleKeyDown",l=>l(n,i))});return c==null||c.steps.forEach(l=>{const u=l.map(o.mapping);u&&r&&o.maybeStep(u)}),!0};function Y(e,t,n={}){const{from:o,to:r,empty:s}=e.selection,a=t?x(t,e.schema):null,i=[];e.doc.nodesBetween(o,r,(d,f)=>{if(d.isText)return;const p=Math.max(o,f),m=Math.min(r,f+d.nodeSize);i.push({node:d,from:p,to:m})});const c=r-o,l=i.filter(d=>a?a.name===d.node.type.name:!0).filter(d=>D(d.node.attrs,n,{strict:!1}));return s?!!l.length:l.reduce((d,f)=>d+f.to-f.from,0)>=c}const ot=(e,t={})=>({state:n,dispatch:o})=>{const r=x(e,n.schema);return Y(n,r,t)?y.lift(n,o):!1},rt=()=>({state:e,dispatch:t})=>y.liftEmptyBlock(e,t),st=e=>({state:t,dispatch:n})=>{const o=x(e,t.schema);return U.liftListItem(o)(t,n)},it=()=>({state:e,dispatch:t})=>y.newlineInCode(e,t);function fe(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function ne(e,t){const n=typeof t=="string"?[t]:t;return Object.keys(e).reduce((o,r)=>(n.includes(r)||(o[r]=e[r]),o),{})}const at=(e,t)=>({tr:n,state:o,dispatch:r})=>{let s=null,a=null;const i=fe(typeof e=="string"?e:e.name,o.schema);return i?(i==="node"&&(s=x(e,o.schema)),i==="mark"&&(a=O(e,o.schema)),r&&n.selection.ranges.forEach(c=>{o.doc.nodesBetween(c.$from.pos,c.$to.pos,(l,u)=>{s&&s===l.type&&n.setNodeMarkup(u,void 0,ne(l.attrs,t)),a&&l.marks.length&&l.marks.forEach(d=>{a===d.type&&n.addMark(u,u+l.nodeSize,a.create(ne(d.attrs,t)))})})}),!0):!1},ct=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),lt=()=>({tr:e,commands:t})=>t.setTextSelection({from:0,to:e.doc.content.size}),dt=()=>({state:e,dispatch:t})=>y.selectNodeBackward(e,t),ut=()=>({state:e,dispatch:t})=>y.selectNodeForward(e,t),ft=()=>({state:e,dispatch:t})=>y.selectParentNode(e,t),pt=()=>({state:e,dispatch:t})=>y.selectTextblockEnd(e,t),mt=()=>({state:e,dispatch:t})=>y.selectTextblockStart(e,t);function ht(e,t,n={}){return z(e,t,{slice:!1,parseOptions:n})}const gt=(e,t=!1,n={})=>({tr:o,editor:r,dispatch:s})=>{const{doc:a}=o,i=ht(e,r.schema,n);return s&&o.replaceWith(0,a.content.size,i).setMeta("preventUpdate",!t),!0};function kt(e,t){const n=O(t,e.schema),{from:o,to:r,empty:s}=e.selection,a=[];s?(e.storedMarks&&a.push(...e.storedMarks),a.push(...e.selection.$head.marks())):e.doc.nodesBetween(o,r,c=>{a.push(...c.marks)});const i=a.find(c=>c.type.name===n.name);return i?{...i.attrs}:{}}function yt(e){for(let t=0;t<e.edgeCount;t+=1){const{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}function L(e,t){const n=[];return e.descendants((o,r)=>{t(o)&&n.push({node:o,pos:r})}),n}function St(e,t){for(let n=e.depth;n>0;n-=1){const o=e.node(n);if(t(o))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:o}}}function Z(e){return t=>St(t.$from,e)}function R(e,t,n){return Object.fromEntries(Object.entries(n).filter(([o])=>{const r=e.find(s=>s.type===t&&s.name===o);return r?r.attribute.keepOnSplit:!1}))}function xt(e,t,n={}){const{empty:o,ranges:r}=e.selection,s=t?O(t,e.schema):null;if(o)return!!(e.storedMarks||e.selection.$from.marks()).filter(d=>s?s.name===d.type.name:!0).find(d=>D(d.attrs,n,{strict:!1}));let a=0;const i=[];if(r.forEach(({$from:d,$to:f})=>{const p=d.pos,m=f.pos;e.doc.nodesBetween(p,m,(h,k)=>{if(!h.isText&&!h.marks.length)return;const S=Math.max(p,k),E=Math.min(m,k+h.nodeSize),A=E-S;a+=A,i.push(...h.marks.map(B=>({mark:B,from:S,to:E})))})}),a===0)return!1;const c=i.filter(d=>s?s.name===d.mark.type.name:!0).filter(d=>D(d.mark.attrs,n,{strict:!1})).reduce((d,f)=>d+f.to-f.from,0),l=i.filter(d=>s?d.mark.type!==s&&d.mark.type.excludes(s):!0).reduce((d,f)=>d+f.to-f.from,0);return(c>0?c+l:c)>=a}function oe(e,t){const{nodeExtensions:n}=ke(t),o=n.find(a=>a.name===e);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=b(w(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function wt(e,t,n){var o;const{selection:r}=t;let s=null;if(le(r)&&(s=r.$cursor),s){const i=(o=e.storedMarks)!==null&&o!==void 0?o:s.marks();return!!n.isInSet(i)||!i.some(c=>c.type.excludes(n))}const{ranges:a}=r;return a.some(({$from:i,$to:c})=>{let l=i.depth===0?e.doc.inlineContent&&e.doc.type.allowsMarkType(n):!1;return e.doc.nodesBetween(i.pos,c.pos,(u,d,f)=>{if(l)return!1;if(u.isInline){const p=!f||f.type.allowsMarkType(n),m=!!n.isInSet(u.marks)||!u.marks.some(h=>h.type.excludes(n));l=p&&m}return!l}),l})}const bt=(e,t={})=>({tr:n,state:o,dispatch:r})=>{const{selection:s}=n,{empty:a,ranges:i}=s,c=O(e,o.schema);if(r)if(a){const l=kt(o,c);n.addStoredMark(c.create({...l,...t}))}else i.forEach(l=>{const u=l.$from.pos,d=l.$to.pos;o.doc.nodesBetween(u,d,(f,p)=>{const m=Math.max(p,u),h=Math.min(p+f.nodeSize,d);f.marks.find(S=>S.type===c)?f.marks.forEach(S=>{c===S.type&&n.addMark(m,h,c.create({...S.attrs,...t}))}):n.addMark(m,h,c.create(t))})});return wt(o,n,c)},Mt=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Tt=(e,t={})=>({state:n,dispatch:o,chain:r})=>{const s=x(e,n.schema);return s.isTextblock?r().command(({commands:a})=>y.setBlockType(s,t)(n)?!0:a.clearNodes()).command(({state:a})=>y.setBlockType(s,t)(a,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},At=e=>({tr:t,dispatch:n})=>{if(n){const{doc:o}=t,r=N(e,0,o.content.size),s=g.NodeSelection.create(o,r);t.setSelection(s)}return!0},Ct=e=>({tr:t,dispatch:n})=>{if(n){const{doc:o}=t,{from:r,to:s}=typeof e=="number"?{from:e,to:e}:e,a=g.TextSelection.atStart(o).from,i=g.TextSelection.atEnd(o).to,c=N(r,a,i),l=N(s,a,i),u=g.TextSelection.create(o,c,l);t.setSelection(u)}return!0},Pt=e=>({state:t,dispatch:n})=>{const o=x(e,t.schema);return U.sinkListItem(o)(t,n)};function re(e,t){const n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){const o=n.filter(r=>t==null?void 0:t.includes(r.type.name));e.tr.ensureMarks(o)}}const vt=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:o,editor:r})=>{const{selection:s,doc:a}=t,{$from:i,$to:c}=s,l=r.extensionManager.attributes,u=R(l,i.node().type.name,i.node().attrs);if(s instanceof g.NodeSelection&&s.node.isBlock)return!i.parentOffset||!T.canSplit(a,i.pos)?!1:(o&&(e&&re(n,r.extensionManager.splittableMarks),t.split(i.pos).scrollIntoView()),!0);if(!i.parent.isBlock)return!1;if(o){const d=c.parentOffset===c.parent.content.size;s instanceof g.TextSelection&&t.deleteSelection();const f=i.depth===0?void 0:yt(i.node(-1).contentMatchAt(i.indexAfter(-1)));let p=d&&f?[{type:f,attrs:u}]:void 0,m=T.canSplit(t.doc,t.mapping.map(i.pos),1,p);if(!p&&!m&&T.canSplit(t.doc,t.mapping.map(i.pos),1,f?[{type:f}]:void 0)&&(m=!0,p=f?[{type:f,attrs:u}]:void 0),m&&(t.split(t.mapping.map(i.pos),1,p),f&&!d&&!i.parentOffset&&i.parent.type!==f)){const h=t.mapping.map(i.before()),k=t.doc.resolve(h);i.node(-1).canReplaceWith(k.index(),k.index()+1,f)&&t.setNodeMarkup(t.mapping.map(i.before()),f)}e&&re(n,r.extensionManager.splittableMarks),t.scrollIntoView()}return!0},Et=e=>({tr:t,state:n,dispatch:o,editor:r})=>{var s;const a=x(e,n.schema),{$from:i,$to:c}=n.selection,l=n.selection.node;if(l&&l.isBlock||i.depth<2||!i.sameParent(c))return!1;const u=i.node(-1);if(u.type!==a)return!1;const d=r.extensionManager.attributes;if(i.parent.content.size===0&&i.node(-1).childCount===i.indexAfter(-1)){if(i.depth===2||i.node(-3).type!==a||i.index(-2)!==i.node(-2).childCount-1)return!1;if(o){let k=j.Fragment.empty;const S=i.index(-1)?1:i.index(-2)?2:3;for(let I=i.depth-S;I>=i.depth-3;I-=1)k=j.Fragment.from(i.node(I).copy(k));const E=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3,A=R(d,i.node().type.name,i.node().attrs),B=((s=a.contentMatch.defaultType)===null||s===void 0?void 0:s.createAndFill(A))||void 0;k=k.append(j.Fragment.from(a.createAndFill(null,B)||void 0));const M=i.before(i.depth-(S-1));t.replace(M,i.after(-E),new j.Slice(k,4-S,0));let P=-1;t.doc.nodesBetween(M,t.doc.content.size,(I,W)=>{if(P>-1)return!1;I.isTextblock&&I.content.size===0&&(P=W+1)}),P>-1&&t.setSelection(g.TextSelection.near(t.doc.resolve(P))),t.scrollIntoView()}return!0}const f=c.pos===i.end()?u.contentMatchAt(0).defaultType:null,p=R(d,u.type.name,u.attrs),m=R(d,i.node().type.name,i.node().attrs);t.delete(i.pos,c.pos);const h=f?[{type:a,attrs:p},{type:f,attrs:m}]:[{type:a,attrs:p}];if(!T.canSplit(t.doc,i.pos,2))return!1;if(o){const{selection:k,storedMarks:S}=n,{splittableMarks:E}=r.extensionManager,A=S||k.$to.parentOffset&&k.$from.marks();if(t.split(i.pos,2,h).scrollIntoView(),!A||!o)return!0;const B=A.filter(M=>E.includes(M.type.name));t.ensureMarks(B)}return!0},V=(e,t)=>{const n=Z(a=>a.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(o===void 0)return!0;const r=e.doc.nodeAt(o);return n.node.type===(r==null?void 0:r.type)&&T.canJoin(e.doc,n.pos)&&e.join(n.pos),!0},q=(e,t)=>{const n=Z(a=>a.type===t)(e.selection);if(!n)return!0;const o=e.doc.resolve(n.start).after(n.depth);if(o===void 0)return!0;const r=e.doc.nodeAt(o);return n.node.type===(r==null?void 0:r.type)&&T.canJoin(e.doc,o)&&e.join(o),!0},Bt=(e,t,n,o={})=>({editor:r,tr:s,state:a,dispatch:i,chain:c,commands:l,can:u})=>{const{extensions:d,splittableMarks:f}=r.extensionManager,p=x(e,a.schema),m=x(t,a.schema),{selection:h,storedMarks:k}=a,{$from:S,$to:E}=h,A=S.blockRange(E),B=k||h.$to.parentOffset&&h.$from.marks();if(!A)return!1;const M=Z(P=>oe(P.type.name,d))(h);if(A.depth>=1&&M&&A.depth-M.depth<=1){if(M.node.type===p)return l.liftListItem(m);if(oe(M.node.type.name,d)&&p.validContent(M.node.content)&&i)return c().command(()=>(s.setNodeMarkup(M.pos,p),!0)).command(()=>V(s,p)).command(()=>q(s,p)).run()}return!n||!B||!i?c().command(()=>u().wrapInList(p,o)?!0:l.clearNodes()).wrapInList(p,o).command(()=>V(s,p)).command(()=>q(s,p)).run():c().command(()=>{const P=u().wrapInList(p,o),I=B.filter(W=>f.includes(W.type.name));return s.ensureMarks(I),P?!0:l.clearNodes()}).wrapInList(p,o).command(()=>V(s,p)).command(()=>q(s,p)).run()},It=(e,t={},n={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=n,a=O(e,o.schema);return xt(o,a,t)?r.unsetMark(a,{extendEmptyMarkRange:s}):r.setMark(a,t)},Ot=(e,t,n={})=>({state:o,commands:r})=>{const s=x(e,o.schema),a=x(t,o.schema);return Y(o,s,n)?r.setNode(a):r.setNode(s,n)},Nt=(e,t={})=>({state:n,commands:o})=>{const r=x(e,n.schema);return Y(n,r,t)?o.lift(r):o.wrapIn(r,t)},jt=()=>({state:e,dispatch:t})=>{const n=e.plugins;for(let o=0;o<n.length;o+=1){const r=n[o];let s;if(r.spec.isInputRules&&(s=r.getState(e))){if(t){const a=e.tr,i=s.transform;for(let c=i.steps.length-1;c>=0;c-=1)a.step(i.steps[c].invert(i.docs[c]));if(s.text){const c=a.doc.resolve(s.from).marks();a.replaceWith(s.from,s.to,e.schema.text(s.text,c))}else a.delete(s.from,s.to)}return!0}}return!1},$t=()=>({tr:e,dispatch:t})=>{const{selection:n}=e,{empty:o,ranges:r}=n;return o||t&&r.forEach(s=>{e.removeMark(s.$from.pos,s.$to.pos)}),!0},Ft=(e,t={})=>({tr:n,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:a=!1}=t,{selection:i}=n,c=O(e,o.schema),{$from:l,empty:u,ranges:d}=i;if(!r)return!0;if(u&&a){let{from:f,to:p}=i;const m=(s=l.marks().find(k=>k.type===c))===null||s===void 0?void 0:s.attrs,h=ce(l,c,m);h&&(f=h.from,p=h.to),n.removeMark(f,p,c)}else d.forEach(f=>{n.removeMark(f.$from.pos,f.$to.pos,c)});return n.removeStoredMark(c),!0},Lt=(e,t={})=>({tr:n,state:o,dispatch:r})=>{let s=null,a=null;const i=fe(typeof e=="string"?e:e.name,o.schema);return i?(i==="node"&&(s=x(e,o.schema)),i==="mark"&&(a=O(e,o.schema)),r&&n.selection.ranges.forEach(c=>{const l=c.$from.pos,u=c.$to.pos;o.doc.nodesBetween(l,u,(d,f)=>{s&&s===d.type&&n.setNodeMarkup(f,void 0,{...d.attrs,...t}),a&&d.marks.length&&d.marks.forEach(p=>{if(a===p.type){const m=Math.max(f,l),h=Math.min(f+d.nodeSize,u);n.addMark(m,h,a.create({...p.attrs,...t}))}})})}),!0):!1},Rt=(e,t={})=>({state:n,dispatch:o})=>{const r=x(e,n.schema);return y.wrapIn(r,t)(n,o)},Dt=(e,t={})=>({state:n,dispatch:o})=>{const r=x(e,n.schema);return U.wrapInList(r,t)(n,o)};var zt=Object.freeze({__proto__:null,blur:Ae,clearContent:Ce,clearNodes:Pe,command:ve,createParagraphNear:Ee,cut:Be,deleteCurrentNode:Ie,deleteNode:Oe,deleteRange:Ne,deleteSelection:je,enter:$e,exitCode:Fe,extendMarkRange:Re,first:De,focus:Ke,forEach:We,insertContent:He,insertContentAt:_e,joinUp:Je,joinDown:Ge,joinBackward:Ue,joinForward:Qe,joinItemBackward:Xe,joinItemForward:Ye,joinTextblockBackward:Ze,joinTextblockForward:et,keyboardShortcut:nt,lift:ot,liftEmptyBlock:rt,liftListItem:st,newlineInCode:it,resetAttributes:at,scrollIntoView:ct,selectAll:lt,selectNodeBackward:dt,selectNodeForward:ut,selectParentNode:ft,selectTextblockEnd:pt,selectTextblockStart:mt,setContent:gt,setMark:bt,setMeta:Mt,setNode:Tt,setNodeSelection:At,setTextSelection:Ct,sinkListItem:Pt,splitBlock:vt,splitListItem:Et,toggleList:Bt,toggleMark:It,toggleNode:Ot,toggleWrap:Nt,undoInputRule:jt,unsetAllMarks:$t,unsetMark:Ft,updateAttributes:Lt,wrapIn:Rt,wrapInList:Dt});v.create({name:"commands",addCommands(){return{...zt}}});v.create({name:"editable",addProseMirrorPlugins(){return[new g.Plugin({key:new g.PluginKey("editable"),props:{editable:()=>this.editor.options.editable}})]}});v.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:e}=this;return[new g.Plugin({key:new g.PluginKey("focusEvents"),props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;const o=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1},blur:(t,n)=>{e.isFocused=!1;const o=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(o),!1}}}})]}});v.create({name:"keymap",addKeyboardShortcuts(){const e=()=>this.editor.commands.first(({commands:a})=>[()=>a.undoInputRule(),()=>a.command(({tr:i})=>{const{selection:c,doc:l}=i,{empty:u,$anchor:d}=c,{pos:f,parent:p}=d,m=d.parent.isTextblock&&f>0?i.doc.resolve(f-1):d,h=m.parent.type.spec.isolating,k=d.pos-d.parentOffset,S=h&&m.parent.childCount===1?k===d.pos:g.Selection.atStart(l).from===f;return!u||!S||!p.type.isTextblock||p.textContent.length?!1:a.clearNodes()}),()=>a.deleteSelection(),()=>a.joinBackward(),()=>a.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:a})=>[()=>a.deleteSelection(),()=>a.deleteCurrentNode(),()=>a.joinForward(),()=>a.selectNodeForward()]),o={Enter:()=>this.editor.commands.first(({commands:a})=>[()=>a.newlineInCode(),()=>a.createParagraphNear(),()=>a.liftEmptyBlock(),()=>a.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...o},s={...o,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return X()||ue()?s:r},addProseMirrorPlugins(){return[new g.Plugin({key:new g.PluginKey("clearDocument"),appendTransaction:(e,t,n)=>{if(!(e.some(m=>m.docChanged)&&!t.doc.eq(n.doc)))return;const{empty:r,from:s,to:a}=t.selection,i=g.Selection.atStart(t.doc).from,c=g.Selection.atEnd(t.doc).to;if(r||!(s===i&&a===c)||!(n.doc.textBetween(0,n.doc.content.size," "," ").length===0))return;const d=n.tr,f=ae({state:n,transaction:d}),{commands:p}=new ge({editor:this.editor,state:f});if(p.clearNodes(),!!d.steps.length)return d}})]}});v.create({name:"tabindex",addProseMirrorPlugins(){return[new g.Plugin({key:new g.PluginKey("tabindex"),props:{attributes:this.editor.isEditable?{tabindex:"0"}:{}}})]}});function se(e){return new we({find:e.find,handler:({state:t,range:n,match:o})=>{const r=t.doc.resolve(n.from),s=b(e.getAttributes,void 0,o)||{};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,s)}})}class K{constructor(t={}){this.type="node",this.name="node",this.parent=null,this.child=null,this.config={name:this.name,defaultOptions:{}},this.config={...this.config,...t},this.name=this.config.name,t.defaultOptions&&Object.keys(t.defaultOptions).length>0&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`),this.options=this.config.defaultOptions,this.config.addOptions&&(this.options=b(w(this,"addOptions",{name:this.name}))),this.storage=b(w(this,"addStorage",{name:this.name,options:this.options}))||{}}static create(t={}){return new K(t)}configure(t={}){const n=this.extend();return n.options=Q(this.options,t),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}extend(t={}){const n=new K({...this.config,...t});return n.parent=this,this.child=n,n.name=t.name?t.name:n.parent.name,t.defaultOptions&&console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`),n.options=b(w(n,"addOptions",{name:n.name})),n.storage=b(w(n,"addStorage",{name:n.name,options:n.options})),n}}const Kt=/^```([a-z]+)?[\s\n]$/,Wt=/^~~~([a-z]+)?[\s\n]$/,Ht=K.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:null,parseHTML:e=>{var t;const{languageClassPrefix:n}=this.options,s=[...((t=e.firstElementChild)===null||t===void 0?void 0:t.classList)||[]].filter(a=>a.startsWith(n)).map(a=>a.replace(n,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:e,HTMLAttributes:t}){return["pre",ye(this.options.HTMLAttributes,t),["code",{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,"paragraph",e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:t}=e,{selection:n}=t,{$from:o,empty:r}=n;if(!r||o.parent.type!==this.type)return!1;const s=o.parentOffset===o.parent.nodeSize-2,a=o.parent.textContent.endsWith(`
4
4
 
5
- `);return!s||!i?!1:t.chain().command(({tr:a})=>(a.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:t})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=t,{selection:n,doc:r}=e,{$from:o,empty:s}=n;if(!s||o.parent.type!==this.type||!(o.parentOffset===o.parent.nodeSize-2))return!1;const a=o.after();return a===void 0||r.nodeAt(a)?!1:t.commands.exitCode()}}},addInputRules(){return[se({find:zt,type:this.type,getAttributes:t=>({language:t[1]})}),se({find:Dt,type:this.type,getAttributes:t=>({language:t[1]})})]},addProseMirrorPlugins(){return[new h.Plugin({key:new h.PluginKey("codeBlockVSCodeHandler"),props:{handlePaste:(t,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const n=e.clipboardData.getData("text/plain"),r=e.clipboardData.getData("vscode-editor-data"),o=r?JSON.parse(r):void 0,s=o==null?void 0:o.mode;if(!n||!s)return!1;const{tr:i}=t.state;return i.replaceSelectionWith(this.type.create({language:s})),i.setSelection(h.TextSelection.near(i.doc.resolve(Math.max(0,i.selection.from-2)))),i.insertText(n.replace(/\r\n?/g,`
6
- `)),i.setMeta("paste",!0),t.dispatch(i),!0}}})]}});let $,j;const G=new Set,q=new Set,Wt=t=>{if(!$)return $=K.getHighlighter({themes:[t.defaultTheme],langs:[]}).then(r=>{q.add(t.defaultTheme),j=r}),$;if(!j)return $;const e=t.language;if(e&&!G.has(e)&&e in K.bundledLanguages)return j.loadLanguage(e).then(()=>{G.add(e)});const n=t.theme;if(n&&!q.has(n)&&n in K.bundledThemes)return j.loadTheme(n).then(()=>{q.add(n)})};function ie({doc:t,name:e,defaultLanguage:n,defaultTheme:r}){const o=[];return J(t,s=>s.type.name===e).forEach(s=>{let i=s.pos+1,a=s.node.attrs.language||n,c=s.node.attrs.theme||r;if(Wt({language:a,theme:c,defaultTheme:r}),G.has(a)||(a="plaintext"),!j)return s.node;const d=j.codeToTokensBase(s.node.textContent,{lang:a,theme:c});for(const f of d){for(const l of f){const u=i+l.content.length,p=ee.Decoration.inline(i,u,{style:`color: ${l.color}`});o.push(p),i=u}i+=1}}),ee.DecorationSet.create(t,o)}function Ht({name:t,defaultLanguage:e,defaultTheme:n}){const r=new h.Plugin({key:new h.PluginKey("shiki"),state:{init:(o,{doc:s})=>ie({doc:s,name:t,defaultLanguage:e,defaultTheme:n}),apply:(o,s,i,a)=>{const c=i.selection.$head.parent.type.name,d=a.selection.$head.parent.type.name,f=J(i.doc,u=>u.type.name===t),l=J(a.doc,u=>u.type.name===t);return o.docChanged&&([c,d].includes(t)||l.length!==f.length||o.steps.some(u=>u.from!==void 0&&u.to!==void 0&&f.some(p=>p.pos>=u.from&&p.pos+p.node.nodeSize<=u.to)))?ie({doc:o.doc,name:t,defaultLanguage:e,defaultTheme:n}):s.map(o.mapping,o.doc)}},props:{decorations(o){return r.getState(o)}}});return r}const pe=Kt.extend({addOptions(){var t;return{...(t=this.parent)==null?void 0:t.call(this),defaultLanguage:null,defaultTheme:"github-dark"}},addProseMirrorPlugins(){var t;return[...((t=this.parent)==null?void 0:t.call(this))||[],Ht({name:this.name,defaultLanguage:this.options.defaultLanguage,defaultTheme:this.options.defaultTheme})]}});exports.CodeBlockShiki=pe;exports.default=pe;
5
+ `);return!s||!a?!1:e.chain().command(({tr:i})=>(i.delete(o.pos-2,o.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;const{state:t}=e,{selection:n,doc:o}=t,{$from:r,empty:s}=n;if(!s||r.parent.type!==this.type||!(r.parentOffset===r.parent.nodeSize-2))return!1;const i=r.after();return i===void 0||o.nodeAt(i)?!1:e.commands.exitCode()}}},addInputRules(){return[se({find:Kt,type:this.type,getAttributes:e=>({language:e[1]})}),se({find:Wt,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new g.Plugin({key:new g.PluginKey("codeBlockVSCodeHandler"),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;const n=t.clipboardData.getData("text/plain"),o=t.clipboardData.getData("vscode-editor-data"),r=o?JSON.parse(o):void 0,s=r==null?void 0:r.mode;if(!n||!s)return!1;const{tr:a}=e.state;return a.replaceSelectionWith(this.type.create({language:s})),a.setSelection(g.TextSelection.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.insertText(n.replace(/\r\n?/g,`
6
+ `)),a.setMeta("paste",!0),e.dispatch(a),!0}}})]}});let C,$;const _=new Set,J=new Set;function Vt(){return C}function qt(e){if(!C&&!$){const t=e.themes.filter(o=>!!o&&o in F.bundledThemes),n=e.languages.filter(o=>!!o&&o in F.bundledLanguages);return $=F.getHighlighter({themes:t,langs:n}).then(o=>{C=o}),$}if($)return $}async function pe(e){return C&&!C.getLoadedThemes().includes(e)&&!J.has(e)&&e in F.bundledThemes?(J.add(e),await C.loadTheme(e),J.delete(e),!0):!1}async function me(e){return C&&!C.getLoadedLanguages().includes(e)&&!_.has(e)&&e in F.bundledLanguages?(_.add(e),await C.loadLanguage(e),_.delete(e),!0):!1}async function _t({doc:e,name:t,defaultTheme:n,defaultLanguage:o}){const r=L(e,i=>i.type.name===t),s=[...r.map(i=>i.node.attrs.theme),n],a=[...r.map(i=>i.node.attrs.language),o];C?await Promise.all([...s.flatMap(i=>pe(i)),...a.flatMap(i=>!!i&&me(i))]):await qt({languages:a,themes:s})}function ie({doc:e,name:t,defaultTheme:n,defaultLanguage:o}){const r=[];return L(e,a=>a.type.name===t).forEach(a=>{let i=a.pos+1,c=a.node.attrs.language||o,l=a.node.attrs.theme||n;const u=Vt();if(!u)return;u.getLoadedLanguages().includes(c)||(c="plaintext");const d=u.getLoadedThemes().includes(l)?l:u.getLoadedThemes()[0],f=u.codeToTokensBase(a.node.textContent,{lang:c,theme:d});for(const p of f){for(const m of p){const h=i+m.content.length,k=ee.Decoration.inline(i,h,{style:`color: ${m.color}`});r.push(k),i=h}i+=1}}),ee.DecorationSet.create(e,r)}function Jt({name:e,defaultLanguage:t,defaultTheme:n}){const o=new g.Plugin({key:new g.PluginKey("shiki"),view(r){class s{constructor(){this.initDecorations()}update(){this.checkUndecoratedBlocks()}destroy(){}async initDecorations(){const i=r.state.doc;await _t({doc:i,name:e,defaultLanguage:t,defaultTheme:n});const c=r.state.tr.setMeta("shikiPluginForceDecoration",!0);r.dispatch(c)}async checkUndecoratedBlocks(){const i=L(r.state.doc,u=>u.type.name===e);if((await Promise.all(i.flatMap(u=>[pe(u.node.attrs.theme),me(u.node.attrs.language)]))).includes(!0)){const u=r.state.tr.setMeta("shikiPluginForceDecoration",!0);r.dispatch(u)}}}return new s},state:{init:(r,{doc:s})=>ie({doc:s,name:e,defaultLanguage:t,defaultTheme:n}),apply:(r,s,a,i)=>{const c=a.selection.$head.parent.type.name,l=i.selection.$head.parent.type.name,u=L(a.doc,p=>p.type.name===e),d=L(i.doc,p=>p.type.name===e),f=r.docChanged&&([c,l].includes(e)||d.length!==u.length||r.steps.some(p=>p.from!==void 0&&p.to!==void 0&&u.some(m=>m.pos>=p.from&&m.pos+m.node.nodeSize<=p.to)));return r.getMeta("shikiPluginForceDecoration")||f?ie({doc:r.doc,name:e,defaultLanguage:t,defaultTheme:n}):s.map(r.mapping,r.doc)}},props:{decorations(r){return o.getState(r)}}});return o}const he=Ht.extend({addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),defaultLanguage:null,defaultTheme:"github-dark"}},addProseMirrorPlugins(){var e;return[...((e=this.parent)==null?void 0:e.call(this))||[],Jt({name:this.name,defaultLanguage:this.options.defaultLanguage,defaultTheme:this.options.defaultTheme})]}});exports.CodeBlockShiki=he;exports.default=he;