var p=globalThis.__LEPTOS_TIPTAP_BRIDGE__;if(p==null||p.modules==null)throw new Error("leptos-tiptap bridge bindings are unavailable");var e=p.modules["@tiptap/core"];if(e==null)throw new Error('leptos-tiptap bridge module "@tiptap/core" is unavailable');var O=e.CommandManager,v=e.Editor,M=e.Extension,D=e.InputRule,I=e.Mark,_=e.Node,F=e.NodePos,L=e.NodeView,j=e.PasteRule,H=e.Tracker,K=e.callOrReturn,G=e.canInsertNode,q=e.combineTransactionSteps,z=e.createChainableState,$=e.createDocument,J=e.createNodeFromContent,W=e.createStyleTag,V=e.defaultBlockAt,U=e.deleteProps,Y=e.elementFromString,Q=e.escapeForRegEx,X=e.extensions,Z=e.findChildren,ee=e.findChildrenInRange,te=e.findDuplicates,ne=e.findParentNode,oe=e.findParentNodeClosestToPos,re=e.fromString,ie=e.generateHTML,se=e.generateJSON,le=e.generateText,ae=e.getAttributes,de=e.getAttributesFromExtensions,pe=e.getChangedRanges,ce=e.getDebugJSON,ue=e.getExtensionField,ge=e.getHTMLFromFragment,_e=e.getMarkAttributes,xe=e.getMarkRange,me=e.getMarkType,ke=e.getMarksBetween,be=e.getNodeAtPosition,ye=e.getNodeAttributes,fe=e.getNodeType,he=e.getRenderedAttributes,Ee=e.getSchema,Ae=e.getSchemaByResolvedExtensions,Se=e.getSchemaTypeByName,Pe=e.getSchemaTypeNameByName,Ce=e.getSplittedAttributes,Re=e.getText,Te=e.getTextBetween,we=e.getTextContentFromNodes,Be=e.getTextSerializersFromSchema,Ne=e.injectExtensionAttributesToParseRule,Oe=e.inputRulesPlugin,ve=e.isActive,Me=e.isAtEndOfNode,De=e.isAtStartOfNode,Ie=e.isEmptyObject,Fe=e.isExtensionRulesEnabled,Le=e.isFunction,je=e.isList,He=e.isMacOS,Ke=e.isMarkActive,Ge=e.isNodeActive,qe=e.isNodeEmpty,ze=e.isNodeSelection,$e=e.isNumber,Je=e.isPlainObject,We=e.isRegExp,Ve=e.isSafari,Ue=e.isString,Ye=e.isTextSelection,Qe=e.isiOS,Xe=e.markInputRule,Ze=e.markPasteRule,x=e.mergeAttributes,et=e.mergeDeep,tt=e.minMax,nt=e.nodeInputRule,ot=e.nodePasteRule,rt=e.objectIncludes,it=e.pasteRulesPlugin,st=e.posToDOMRect,lt=e.removeDuplicates,at=e.resolveFocusPosition,dt=e.rewriteUnknownContent,pt=e.selectionToInsertionEnd,ct=e.splitExtensions,ut=e.textInputRule,gt=e.textPasteRule,c=e.textblockTypeInputRule,_t=e.wrappingInputRule;var u=globalThis.__LEPTOS_TIPTAP_BRIDGE__;if(u==null||u.modules==null)throw new Error("leptos-tiptap bridge bindings are unavailable");var l=u.modules["@tiptap/pm/state"];if(l==null)throw new Error('leptos-tiptap bridge module "@tiptap/pm/state" is unavailable');var mt=l.AllSelection,kt=l.EditorState,bt=l.NodeSelection,m=l.Plugin,k=l.PluginKey,b=l.Selection,yt=l.SelectionRange,y=l.TextSelection,ft=l.Transaction;var C=/^```([a-z]+)?[\s\n]$/,R=/^~~~([a-z]+)?[\s\n]$/,f=_.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:t=>{var n;let{languageClassPrefix:o}=this.options,a=[...((n=t.firstElementChild)===null||n===void 0?void 0:n.classList)||[]].filter(r=>r.startsWith(o)).map(r=>r.replace(o,""))[0];return a||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:t,HTMLAttributes:n}){return["pre",x(this.options.HTMLAttributes,n),["code",{class:t.attrs.language?this.options.languageClassPrefix+t.attrs.language:null},0]]},addCommands(){return{setCodeBlock:t=>({commands:n})=>n.setNode(this.name,t),toggleCodeBlock:t=>({commands:n})=>n.toggleNode(this.name,"paragraph",t)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:t,$anchor:n}=this.editor.state.selection,o=n.pos===1;return!t||n.parent.type.name!==this.name?!1:o||!n.parent.textContent.length?this.editor.commands.clearNodes():!1},Enter:({editor:t})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:n}=t,{selection:o}=n,{$from:i,empty:s}=o;if(!s||i.parent.type!==this.type)return!1;let a=i.parentOffset===i.parent.nodeSize-2,r=i.parent.textContent.endsWith(`

`);return!a||!r?!1:t.chain().command(({tr:d})=>(d.delete(i.pos-2,i.pos),!0)).exitCode().run()},ArrowDown:({editor:t})=>{if(!this.options.exitOnArrowDown)return!1;let{state:n}=t,{selection:o,doc:i}=n,{$from:s,empty:a}=o;if(!a||s.parent.type!==this.type||!(s.parentOffset===s.parent.nodeSize-2))return!1;let d=s.after();return d===void 0?!1:i.nodeAt(d)?t.commands.command(({tr:P})=>(P.setSelection(b.near(i.resolve(d))),!0)):t.commands.exitCode()}}},addInputRules(){return[c({find:C,type:this.type,getAttributes:t=>({language:t[1]})}),c({find:R,type:this.type,getAttributes:t=>({language:t[1]})})]},addProseMirrorPlugins(){return[new m({key:new k("codeBlockVSCodeHandler"),props:{handlePaste:(t,n)=>{if(!n.clipboardData||this.editor.isActive(this.type.name))return!1;let o=n.clipboardData.getData("text/plain"),i=n.clipboardData.getData("vscode-editor-data"),s=i?JSON.parse(i):void 0,a=s?.mode;if(!o||!a)return!1;let{tr:r,schema:d}=t.state,g=d.text(o.replace(/\r\n?/g,`
`));return r.replaceSelectionWith(this.type.create({language:a},g)),r.selection.$from.parent.type!==this.type&&r.setSelection(y.near(r.doc.resolve(Math.max(0,r.selection.from-2)))),r.setMeta("paste",!0),t.dispatch(r),!0}}})]}});var h="__LEPTOS_TIPTAP_BRIDGE__";function T(){let t=globalThis,n=t[h];if(n!=null)return n;let o={modules:{},registerExtension:()=>{throw new Error("leptos-tiptap bridge runtime is not initialized")}};return t[h]=o,o}function E(){return T()}function A(t){E().registerExtension(t)}function w(t){return typeof t=="string"&&t.length>0?{"data-block-id":t,id:t}:{}}function S(t){if(t?.language!=null)return{language:t.language}}var B=f.extend({addAttributes(){return{...this.parent?.(),blockId:{default:null,parseHTML:t=>t.getAttribute("data-block-id"),renderHTML:t=>w(t.blockId)}}}}),N={name:"code_block",create:()=>B,commands:{set_code_block:(t,n)=>n.kind==="set_code_block"?t.chain().focus().setCodeBlock(S(n.attributes)).run():!1,toggle_code_block:(t,n)=>n.kind==="toggle_code_block"?t.chain().focus().toggleCodeBlock(S(n.attributes)).run():!1}};function Bt(){A(N)}export{Bt as register_code_block};
