tiptap-extension-code-block-shiki 0.2.1 → 0.4.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 CHANGED
@@ -49,15 +49,21 @@ Which language to use, when no language was provided. See https://shiki.style/la
49
49
 
50
50
  ### Lazy loading
51
51
 
52
- The library loads themes and languages asynchronously.
52
+ The library loads themes and languages asynchronously. You may see that the code is not highlighted for a short moment, while the theme and language is loading.
53
53
 
54
54
  ### Unknown language fallback
55
55
 
56
56
  When you use a language which isn't supported by Shiki, it silently falls back to no syntax highlighting.
57
57
 
58
+ ## [Contributing](CONTRIBUTING.md)
59
+
58
60
  ## Credits
59
61
 
60
62
  Most of this library is just combining code from two other libraries:
61
63
 
62
64
  - [`@tiptap/extension-code-block-lowlight`](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-code-block-lowlight) by [Tiptap](https://tiptap.dev)
63
- - [`prosemirror-highlight`](https://github.com/ocavue/prosemirror-highlight) by [ocavue](https://github.com/ocavue)
65
+ - [`prosemirror-highlight`](https://github.com/ocavue/prosemirror-highlight) by [ocavue](https://github.com/ocavue)
66
+
67
+ ## License
68
+
69
+ MIT
@@ -5,7 +5,7 @@ import { Fragment as L, Slice as be, DOMParser as Me } from "@tiptap/pm/model";
5
5
  import { liftTarget as Ae, joinPoint as ce, canSplit as R, ReplaceStep as Te, ReplaceAroundStep as Ce, canJoin as le } from "@tiptap/pm/transform";
6
6
  import { createParagraphNear as Ee, deleteSelection as Be, exitCode as ve, joinUp as Ie, joinDown as Pe, joinBackward as $e, joinForward as Ne, joinTextblockBackward as Oe, joinTextblockForward as je, lift as Fe, liftEmptyBlock as Le, newlineInCode as Re, selectNodeBackward as De, selectNodeForward as ze, selectParentNode as We, selectTextblockEnd as He, selectTextblockStart as Ke, setBlockType as ee, wrapIn as Ve } from "@tiptap/pm/commands";
7
7
  import { liftListItem as _e, sinkListItem as Je, wrapInList as Ue } from "@tiptap/pm/schema-list";
8
- import { bundledThemes as de, bundledLanguages as ue, getHighlighter as Ge } from "shiki";
8
+ import { bundledThemes as de, bundledLanguages as ue, createHighlighter as Ge } from "shiki";
9
9
  function fe(e) {
10
10
  const { state: t, transaction: n } = e;
11
11
  let { selection: o } = n, { doc: r } = n, { storedMarks: s } = n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiptap-extension-code-block-shiki",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Use Shiki syntax highlighting for codeblocks in TipTap.",
5
5
  "repository": "timomeh/tiptap-extension-code-block-shiki",
6
6
  "author": {
@@ -12,19 +12,20 @@
12
12
  "files": [
13
13
  "dist"
14
14
  ],
15
- "main": "./dist/tiptap-extension-code-block-shiki.cjs",
16
- "module": "./dist/tiptap-extension-code-block-shiki.js",
15
+ "main": "./dist/tiptap-extension-code-block-shiki.js",
17
16
  "types": "./dist/tiptap-extension-code-block-shiki.d.ts",
18
17
  "devDependencies": {
19
18
  "@tiptap/core": "^2.3.0",
20
19
  "@tiptap/extension-code-block": "^2.3.0",
21
20
  "@tiptap/pm": "^2.3.0",
22
21
  "@tiptap/starter-kit": "^2.3.0",
22
+ "happy-dom": "^14.10.1",
23
23
  "prettier": "^3.2.5",
24
- "shiki": "^1.3.0",
24
+ "shiki": "^1.12.1",
25
25
  "typescript": "^5.2.2",
26
26
  "vite": "^5.2.0",
27
- "vite-plugin-dts": "^3.8.3"
27
+ "vite-plugin-dts": "^3.8.3",
28
+ "vitest": "^1.6.0"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "@tiptap/core": "^2.3.0",
@@ -45,6 +46,6 @@
45
46
  "dev": "vite",
46
47
  "build": "tsc && vite build",
47
48
  "preview": "vite preview",
48
- "test": "echo 'No tests defined, soz'"
49
+ "test": "vitest"
49
50
  }
50
51
  }
@@ -1,6 +0,0 @@
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
-
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
-
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;