tiptap-extension-code-block-shiki 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Timo Mämecke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Shiki TipTap Extension
2
+
3
+ Use [Shiki](https://shiki.style/) syntax highlighting for codeblocks in [TipTap](https://tiptap.dev/).
4
+
5
+ ## Installation
6
+
7
+ ```console
8
+ npm install shiki tiptap-extension-code-block-shiki
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The extension extends [CodeBlock](https://tiptap.dev/docs/editor/api/nodes/code-block).
14
+
15
+ ```ts
16
+ import { Editor } from '@tiptap/core'
17
+ import StarterKit from '@tiptap/starter-kit'
18
+ import CodeBlockShiki from 'tiptap-extension-code-block-shiki'
19
+
20
+ new Editor({
21
+ extensions: [
22
+ StarterKit.configure({ codeBlock: false }),
23
+ CodeBlockShiki.configure({
24
+ defaultTheme: 'tokyo-night'
25
+ }),
26
+ ],
27
+ })
28
+ ```
29
+
30
+ Go into your TipTap editor, write `` ```ts ``, press <kbd>Enter</kbd>, and write some code! It loads the language on the fly.
31
+
32
+ ## Settings
33
+
34
+ The extension extends [CodeBlock](https://tiptap.dev/docs/editor/api/nodes/code-block) and forwards its settings. It additionally adds the following settings:
35
+
36
+ ### `defaultTheme`
37
+
38
+ Which theme to use by default. See https://shiki.style/themes.
39
+
40
+ ### `defaultLanguage`
41
+
42
+ Which language to use, when no language was provided. See https://shiki.style/languages.
43
+
44
+ ## Notes
45
+
46
+ ### Lazy loading
47
+
48
+ The library loads themes and languages asynchronously.
49
+
50
+ ### Unknown language fallback
51
+
52
+ When you use a language which isn't supported by Shiki, it silently falls back to no syntax highlighting.
53
+
54
+ ## Credits
55
+
56
+ Most of this library is just combining code from two other libraries:
57
+
58
+ - [`@tiptap/extension-code-block-lowlight`](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-code-block-lowlight) by [TipTap](https://tiptap.dev)
59
+ - [`prosemirror-highlight`](https://github.com/ocavue/prosemirror-highlight) by [ocavue](https://github.com/ocavue)
@@ -0,0 +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=`
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(`
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;
@@ -0,0 +1,15 @@
1
+ import { BundledLanguage } from 'shiki';
2
+ import { BundledTheme } from 'shiki';
3
+ import { CodeBlockOptions } from '@tiptap/extension-code-block';
4
+ import { Node as Node_2 } from '@tiptap/core';
5
+
6
+ declare const CodeBlockShiki: Node_2<CodeBlockShikiOptions, any>;
7
+ export { CodeBlockShiki }
8
+ export default CodeBlockShiki;
9
+
10
+ export declare interface CodeBlockShikiOptions extends CodeBlockOptions {
11
+ defaultLanguage: BundledLanguage | null | undefined;
12
+ defaultTheme: BundledTheme;
13
+ }
14
+
15
+ export { }