/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../core/dist/index.js"),t=require("../../../prosemirror-state/dist/index.js");var n=/^```([a-z]+)?[\s\n]$/,r=/^~~~([a-z]+)?[\s\n]$/,o=e.Node.create({name:"codeBlock",addOptions:()=>({languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:4,HTMLAttributes:{}}),content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{var t;const{languageClassPrefix:n}=this.options;if(!n)return null;const r=[...(null==(t=e.firstElementChild)?void 0:t.classList)||[]].filter(e=>e.startsWith(n)).map(e=>e.replace(n,""))[0];return r||null},rendered:!1}}},parseHTML:()=>[{tag:"pre",preserveWhitespace:"full"}],renderHTML({node:t,HTMLAttributes:n}){return["pre",e.mergeAttributes(this.options.HTMLAttributes,n),["code",{class:t.attrs.language?this.options.languageClassPrefix+t.attrs.language:null},0]]},markdownTokenName:"code",parseMarkdown:(e,t)=>{var n;return!1===(null==(n=e.raw)?void 0:n.startsWith("```"))&&"indented"!==e.codeBlockStyle?[]:t.createNode("codeBlock",{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[])},renderMarkdown:(e,t)=>{var n;let r="";const o=(null==(n=e.attrs)?void 0:n.language)||"";if(e.content){r=[`\`\`\`${o}`,t.renderChildren(e.content),"```"].join("\n")}else r=`\`\`\`${o}\n\n\`\`\``;return r},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=1===t.pos;return!(!e||t.parent.type.name!==this.name)&&(!(!n&&t.parent.textContent.length)&&this.editor.commands.clearNodes())},Tab:({editor:e})=>{var t;if(!this.options.enableTabIndentation)return!1;const n=null!=(t=this.options.tabSize)?t:4,{state:r}=e,{selection:o}=r,{$from:a,empty:s}=o;if(a.parent.type!==this.type)return!1;const i=" ".repeat(n);return s?e.commands.insertContent(i):e.commands.command(({tr:e})=>{const{from:t,to:n}=o,a=r.doc.textBetween(t,n,"\n","\n").split("\n").map(e=>i+e).join("\n");return e.replaceWith(t,n,r.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{var n;if(!this.options.enableTabIndentation)return!1;const r=null!=(n=this.options.tabSize)?n:4,{state:o}=e,{selection:a}=o,{$from:s,empty:i}=a;return s.parent.type===this.type&&(i?e.commands.command(({tr:e})=>{var n;const{pos:a}=s,i=s.start(),l=s.end(),d=o.doc.textBetween(i,l,"\n","\n").split("\n");let c=0,p=0;const u=a-i;for(let t=0;t<d.length;t+=1){if(p+d[t].length>=u){c=t;break}p+=d[t].length+1}const m=(null==(n=d[c].match(/^ */))?void 0:n[0])||"",g=Math.min(m.length,r);if(0===g)return!0;let h=i;for(let t=0;t<c;t+=1)h+=d[t].length+1;e.delete(h,h+g);return a-h<=g&&e.setSelection(t.TextSelection.create(e.doc,h)),!0}):e.commands.command(({tr:e})=>{const{from:t,to:n}=a,s=o.doc.textBetween(t,n,"\n","\n").split("\n").map(e=>{var t;const n=(null==(t=e.match(/^ */))?void 0:t[0])||"",o=Math.min(n.length,r);return e.slice(o)}).join("\n");return e.replaceWith(t,n,o.schema.text(s)),!0}))},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:t}=e,{selection:n}=t,{$from:r,empty:o}=n;if(!o||r.parent.type!==this.type)return!1;const a=r.parentOffset===r.parent.nodeSize-2,s=r.parent.textContent.endsWith("\n\n");return!(!a||!s)&&e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;const{state:n}=e,{selection:r,doc:o}=n,{$from:a,empty:s}=r;if(!s||a.parent.type!==this.type)return!1;if(!(a.parentOffset===a.parent.nodeSize-2))return!1;const i=a.after();if(void 0===i)return!1;return o.nodeAt(i)?e.commands.command(({tr:e})=>(e.setSelection(t.Selection.near(o.resolve(i))),!0)):e.commands.exitCode()}}},addInputRules(){return[e.textblockTypeInputRule({find:n,type:this.type,getAttributes:e=>({language:e[1]})}),e.textblockTypeInputRule({find:r,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new t.Plugin({key:new t.PluginKey("codeBlockVSCodeHandler"),props:{handlePaste:(e,n)=>{if(!n.clipboardData)return!1;if(this.editor.isActive(this.type.name))return!1;const r=n.clipboardData.getData("text/plain"),o=n.clipboardData.getData("vscode-editor-data"),a=o?JSON.parse(o):void 0,s=null==a?void 0:a.mode;if(!r||!s)return!1;const{tr:i,schema:l}=e.state,d=l.text(r.replace(/\r\n?/g,"\n"));return i.replaceSelectionWith(this.type.create({language:s},d)),i.selection.$from.parent.type!==this.type&&i.setSelection(t.TextSelection.near(i.doc.resolve(Math.max(0,i.selection.from-2)))),i.setMeta("paste",!0),e.dispatch(i),!0}}})]}});exports.CodeBlock=o,exports.backtickInputRegex=n,exports.tildeInputRegex=r;