@notectl/core 2.2.2 → 2.2.3
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/dist/chunks/{CodeBlockPlugin-Uv6EXaH1.mjs → CodeBlockPlugin-CcB0WaIz.mjs} +2 -2
- package/dist/chunks/{CodeBlockPlugin-Uv6EXaH1.mjs.map → CodeBlockPlugin-CcB0WaIz.mjs.map} +1 -1
- package/dist/chunks/{Commands-CyT1Li7_.mjs → Commands-BIIpx_Zd.mjs} +2 -2
- package/dist/chunks/Commands-BIIpx_Zd.mjs.map +1 -0
- package/dist/chunks/{FormulaPlugin-UA-9tRpY.mjs → FormulaPlugin-66Cc9sH2.mjs} +2 -2
- package/dist/chunks/{FormulaPlugin-UA-9tRpY.mjs.map → FormulaPlugin-66Cc9sH2.mjs.map} +1 -1
- package/dist/chunks/{HardBreakPlugin-BkgoJkjC.mjs → HardBreakPlugin-9DOyCyyM.mjs} +2 -2
- package/dist/chunks/{HardBreakPlugin-BkgoJkjC.mjs.map → HardBreakPlugin-9DOyCyyM.mjs.map} +1 -1
- package/dist/chunks/{InlineCodePlugin-D3QulApr.mjs → InlineCodePlugin-Cj1EZ3x2.mjs} +2 -2
- package/dist/chunks/{InlineCodePlugin-D3QulApr.mjs.map → InlineCodePlugin-Cj1EZ3x2.mjs.map} +1 -1
- package/dist/chunks/{SimpleMark-Db8ir_z2.mjs → SimpleMark-Bdqjcz0G.mjs} +2 -2
- package/dist/chunks/{SimpleMark-Db8ir_z2.mjs.map → SimpleMark-Bdqjcz0G.mjs.map} +1 -1
- package/dist/chunks/{SmartPastePlugin-Db1RcNJf.mjs → SmartPastePlugin-BhkoH03E.mjs} +2 -2
- package/dist/chunks/{SmartPastePlugin-Db1RcNJf.mjs.map → SmartPastePlugin-BhkoH03E.mjs.map} +1 -1
- package/dist/chunks/{StrikethroughPlugin-Bsg7Ma4I.mjs → StrikethroughPlugin-DRuwEZhu.mjs} +2 -2
- package/dist/chunks/{StrikethroughPlugin-Bsg7Ma4I.mjs.map → StrikethroughPlugin-DRuwEZhu.mjs.map} +1 -1
- package/dist/chunks/{SuperSubPlugin-ChEga-b_.mjs → SuperSubPlugin-IZ_x8GS-.mjs} +2 -2
- package/dist/chunks/{SuperSubPlugin-ChEga-b_.mjs.map → SuperSubPlugin-IZ_x8GS-.mjs.map} +1 -1
- package/dist/chunks/{TextFormattingPlugin-Db5SCNOF.mjs → TextFormattingPlugin-CpyZgtLi.mjs} +2 -2
- package/dist/chunks/{TextFormattingPlugin-Db5SCNOF.mjs.map → TextFormattingPlugin-CpyZgtLi.mjs.map} +1 -1
- package/dist/chunks/{full--GEBZ2xU.mjs → full-CHkwduuY.mjs} +2 -2
- package/dist/chunks/{full--GEBZ2xU.mjs.map → full-CHkwduuY.mjs.map} +1 -1
- package/dist/chunks/{src-C5Lblp2i.mjs → src-gVRDR_79.mjs} +2 -2
- package/dist/chunks/{src-C5Lblp2i.mjs.map → src-gVRDR_79.mjs.map} +1 -1
- package/dist/commands/Commands.d.ts.map +1 -1
- package/dist/full.mjs +1 -1
- package/dist/notectl-core.mjs +1 -1
- package/dist/notectl-core.umd.js +1 -1
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/formula.mjs +1 -1
- package/dist/plugins/hard-break.mjs +1 -1
- package/dist/plugins/inline-code.mjs +1 -1
- package/dist/plugins/smart-paste.mjs +1 -1
- package/dist/plugins/strikethrough.mjs +1 -1
- package/dist/plugins/super-sub.mjs +1 -1
- package/dist/plugins/text-formatting.mjs +1 -1
- package/dist/presets/full.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/package.json +415 -423
- package/dist/chunks/Commands-CyT1Li7_.mjs.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{S as t,T as e,h as n,o,p as r,u as c,v as s}from"./Document-r7vLOAGA.mjs";import{a as i,d as a,i as l,o as d,s as u,t as g,u as p}from"./Selection-HYoVFpAx.mjs";import{t as f}from"./Commands-CyT1Li7_.mjs";import{a as h}from"./TypeBrands-Ch9856Gb.mjs";import{n as k}from"./DomUtils-Bf7JLFlx.mjs";import{r as b}from"./HTMLUtils-C6B4UT00.mjs";import{r as m}from"./NodeResolver-ChgLF_IP.mjs";import{C as v,S as x,_ as C,v as y,y as S}from"./BlockInsertion-6rR9tIGP.mjs";import{i as w,r as _,t as I}from"./Decoration-ZeyVfwJB.mjs";import{s as B}from"./StyleRuntime-BAutwDZT.mjs";import{n as A}from"./TypedKeys-CA4bfw9O.mjs";import{t as T}from"./SyntaxTokenTypes-BUCOMtL8.mjs";import{a as L,s as M}from"./PluginHelpers-D4quRJ5a.mjs";import{t as P}from"./ShortcutFormatting-TwiufqeV.mjs";import{t as O}from"./PopupManager-CyOfZUab.mjs";import{c as N,l as j}from"./XmlDetector-D7TQpw-e.mjs";import{a as E,r as z,s as $,t as D}from"./XmlSupport-BYiRwlkK.mjs";import{n as q}from"./PopupKeyboardPatterns-tUrT9TyV.mjs";var H=`\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 4px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 2px 6px;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\ttransition: background 0.15s;\n}\n\n.notectl-code-block__language-btn:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-code-block__language-btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__chevron {\n\tdisplay: inline-flex;\n\talign-items: center;\n\topacity: 0.6;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Language picker popup */\n.notectl-language-picker {\n\tmin-width: 120px;\n\tmax-height: 200px;\n\toverflow-y: auto;\n\tpadding: 4px;\n\tbackground: var(--notectl-surface-raised, #fff);\n\tborder: 1px solid var(--notectl-border, #e0e0e0);\n\tborder-radius: 6px;\n\tbox-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);\n}\n\n.notectl-language-picker__option {\n\tpadding: 6px 10px;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg, #333);\n\twhite-space: nowrap;\n}\n\n.notectl-language-picker__option:hover {\n\tbackground: rgba(128, 128, 128, 0.1);\n}\n\n.notectl-language-picker__option:focus {\n\toutline: none;\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-language-picker__option[aria-selected="true"] {\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary, #2563eb);\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${T.map(t=>`.notectl-token--${t} {\n\tcolor: var(--notectl-code-token-${t});\n\tfont-style: var(--notectl-code-token-${t}-font-style, inherit);\n\tfont-weight: var(--notectl-code-token-${t}-font-weight, inherit);\n}`).join("\n")}\n`,R=[{open:"(",close:")",kind:"bracket"},{open:"[",close:"]",kind:"bracket"},{open:"{",close:"}",kind:"bracket"},{open:'"',close:'"',kind:"quote"},{open:"'",close:"'",kind:"quote"},{open:"`",close:"`",kind:"quote"}],V=new Map(R.map(t=>[t.open,t])),F=new Map(R.filter(t=>"bracket"===t.kind).map(t=>[t.close,t]));var K=new Set(["{","[","("]),W={"}":"{","]":"[",")":"("};function U(t,e){const n=t.lastIndexOf("\n",e-1)+1,o=t.indexOf("\n",e);return{start:n,end:-1===o?t.length:o}}function X(t,e){const{start:n,end:o}=U(t,e);let r=n;for(;r<o;){const e=t[r];if(" "!==e&&"\t"!==e)break;r++}return t.slice(n,r)}function J(t,e){return t?" ".repeat(e):"\t"}function Q(t,e,n){if(0===t.length)return{removed:"",rest:t};if(!e&&"\t"===t[0])return{removed:"\t",rest:t.slice(1)};let o=0;for(;o<n&&" "===t[o];)o++;return{removed:t.slice(0,o),rest:t.slice(o)}}var Z=class{buckets=/* @__PURE__ */new Map;push(t,e){const n=this.buckets.get(t.blockId)??[];n.push({pos:t,char:e}),this.buckets.set(t.blockId,n)}take(t,e){const n=this.buckets.get(t);if(n)for(let o=n.length-1;o>=0;o--){const r=n[o];if(r&&r.pos.offset===e)return n.splice(o,1),0===n.length&&this.buckets.delete(t),r}}peek(t,e){const n=this.buckets.get(t);if(n)for(let o=n.length-1;o>=0;o--){const t=n[o];if(t&&t.pos.offset===e)return t}}clearBlock(t){this.buckets.delete(t)}clear(){this.buckets.clear()}sizeForBlock(t){return this.buckets.get(t)?.length??0}get size(){let t=0;for(const e of this.buckets.values())t+=e.length;return t}migrate(t){if(t.isEmpty)return;const e=/* @__PURE__ */new Map;for(const n of this.buckets.values())for(const o of n){const n=t.mapResult(o.pos,1);if(n.deleted)continue;const r={pos:n.pos,char:o.char},c=n.pos.blockId,s=e.get(c)??[];s.push(r),e.set(c,s)}this.buckets.clear();for(const[n,o]of e)this.buckets.set(n,o)}static makePos(t,e){return l(t,e)}},G=class{resolvedIndent;resolvedPairing;getTokenAt;getCompositionState;pairs=new Z;pendingPairOps=[];constructor(t){this.resolvedIndent=t.resolvedIndent,this.resolvedPairing=t.resolvedPairing,this.getTokenAt=t.getTokenAt,this.getCompositionState=t.getCompositionState}get pairStack(){return this.pairs}clear(){this.pairs.clear(),this.pendingPairOps.length=0}syncOnStateChange(t,e){this.pairs.size>0&&!e.mapping.isEmpty&&this.pairs.migrate(e.mapping);for(const n of this.pendingPairOps)"push"===n.kind?this.pairs.push(l(n.blockId,n.offset),n.char):this.pairs.take(n.blockId,n.offset);this.pendingPairOps.length=0;for(const n of e.steps){if("setBlockType"!==n.type)continue;const e=t.getBlock(n.blockId);e&&"code_block"===e.type||this.pairs.clearBlock(n.blockId)}}handleTextInput=(t,e)=>{this.pendingPairOps.length=0;const o=this.getCompositionState();if(!o)return null;if(o.isComposing)return null;if(!p(e.selection))return null;if(1!==t.length)return null;const r=e.selection,c=e.getBlock(r.anchor.blockId);if(!c||"code_block"!==c.type)return null;const s=this.tryDedentOnCloseBracket(e,c,t);if(s)return s;const i=function(t){const{state:e,char:o,config:r}=t;if(!p(e.selection))return{kind:"passthrough"};const c=e.selection,s=V.get(o);if(s&&!d(c)&&function(t,e){switch(e.surround){case"never":return!1;case"brackets":return"bracket"===t.kind;case"quotes":return"quote"===t.kind;case"languageDefined":return!0}}(s,r)){const e=function(t,e,n){const{state:o}=n,r=a(e,o.getBlockOrder());return r.from.blockId!==r.to.blockId||r.from.blockId!==n.blockId?null:{kind:"wrap",open:t.open,close:t.close}}(s,c,t);if(e)return e}return d(c)?r.overtype&&function(t,e){if(!function(t){const e=V.get(t);return"quote"===e?.kind?e:F.get(t)}(e))return!1;const o=t.state.selection;if(!p(o))return!1;const r=n(t.block),c=o.anchor.offset;if(r[c]!==e)return!1;const s=t.pairStack.peek(t.blockId,c);return Boolean(s&&s.char===e)}(t,o)?{kind:"overtype"}:s&&function(t,e){const o="quote"===t.kind?e.config.quotes:e.config.brackets;if("never"===o)return!1;const r=e.state.selection;if(!p(r))return!0;const c=n(e.block),s=r.anchor.offset;if("quote"===t.kind&&"'"===t.open&&function(t,e){if(e<=0)return!1;const n=t[e-1];return!!n&&/[A-Za-z0-9_]/.test(n)}(c,s))return!1;if("always"===o)return!0;if("beforeWhitespace"===o)return function(t,e){if(e>=t.length)return!0;const n=t[e];return!n||!!/\s/.test(n)||!!F.has(n)}(c,s);if("quote"===t.kind){const t=e.getTokenAt(e.blockId,s);return!t||"string"!==t.type&&"comment"!==t.type}return!0}(s,t)?{kind:"pair",close:s.close}:{kind:"passthrough"}:{kind:"passthrough"}}({state:e,block:c,blockId:r.anchor.blockId,char:t,config:this.resolvedPairing,pairStack:this.pairs,getTokenAt:this.getTokenAt});switch(i.kind){case"pair":return this.buildAutoPairTransaction(e,r.anchor.blockId,i.close,t);case"overtype":return this.buildOvertypeTransaction(e,r.anchor.blockId);case"wrap":return this.buildWrapTransaction(e,r.anchor.blockId,i.open,i.close);case"passthrough":return null}};tryDedentOnCloseBracket(t,e,o){if("brackets"!==this.resolvedIndent.mode)return null;if("}"!==o&&"]"!==o&&")"!==o)return null;const r=t.selection;if(!p(r)||!d(r))return null;const c=n(e),s=r.anchor.offset;if(!function(t,e){const{start:n}=U(t,e);for(let o=n;o<e;o++){const e=t[o];if(" "!==e&&"\t"!==e)return!1}return!0}(c,s))return null;const{start:i}=U(c,s);if(i===s)return null;const a=r.anchor.blockId,l=this.findTrackedCloseAfter(c,s,o,a);if(null!==l)return t.transaction("input").deleteTextAt(a,i,l).setSelection(g(a,i+1)).build();const u=Q(c.slice(i,s),this.resolvedIndent.useSpaces,this.resolvedIndent.spaceCount);if(0===u.removed.length)return null;const f=s-u.removed.length;return t.transaction("input").deleteTextAt(a,f,s).insertText(a,f,o,[]).setSelection(g(a,f+1)).build()}findTrackedCloseAfter(t,e,n,o){for(let r=e;r<t.length;r++){const e=t[r];if(" "!==e&&"\t"!==e&&"\n"!==e){if(e===n){const t=this.pairs.peek(o,r);if(t&&t.char===n)return r}return null}}return null}buildAutoPairTransaction(t,e,n,o){const r=t.selection;if(!p(r))throw new Error("buildAutoPairTransaction requires a text selection");const c=r.anchor.offset,s=`${o}${n}`,i=t.transaction("input").insertText(e,c,s,[]).setSelection(g(e,c+1)).build();return this.pendingPairOps.push({kind:"push",blockId:e,offset:c+1,char:n}),i}buildOvertypeTransaction(t,e){const n=t.selection;if(!p(n))throw new Error("buildOvertypeTransaction requires a text selection");const o=n.anchor.offset;return this.pendingPairOps.push({kind:"take",blockId:e,offset:o}),t.transaction("input").setSelection(g(e,o+1)).build()}buildWrapTransaction(t,e,n,o){const r=t.selection;if(!p(r))throw new Error("buildWrapTransaction requires a text selection");const c=function(t,e){const n=a(t,e);return{fromOffset:n.from.offset,toOffset:n.to.offset}}(r,t.getBlockOrder()),s=a(r,t.getBlockOrder()).from===r.anchor,i=c.fromOffset+1,l=c.toOffset+1,d=s?i:l,u=s?l:i;return t.transaction("input").insertText(e,c.toOffset,o,[]).insertText(e,c.fromOffset,n,[]).setSelection({anchor:{blockId:e,offset:d},head:{blockId:e,offset:u}}).build()}};function Y(t,e){const n=t.getState();if(!p(n.selection))return!1;const o=n.selection,r=n.getBlock(o.anchor.blockId);return!(!r||"code_block"!==r.type)&&e({state:n,sel:o,block:r,blockId:o.anchor.blockId,offset:o.anchor.offset})}function tt(t,e,o,r){const s={Enter:()=>function(t,e){return Y(t,({state:o,block:r,blockId:s,offset:i})=>{if(!d(o.selection))return!1;const a=n(r);if(a.endsWith("\n")&&i===a.length)return function(t,e,n){const o=t.getState(),r=n.length-1,s=c(),i=o.transaction("input").deleteTextAt(e,r,n.length).splitBlock(e,r,s).setBlockType(s,h("paragraph")).setSelection(g(s,0)).build();return t.dispatch(i),!0}(t,s,a);const l=J(e.indent.useSpaces,e.indent.spaceCount);if("brackets"===e.indent.mode&&function(t,e){return function(t,e){if(e<=0||e>=t.length)return!1;const n=t[e-1],o=t[e];return!(!n||!o)&&W[o]===n}(t,e)}(a,i)){const e=X(a,i),n=`\n${e}${l}\n${e}`,r=i+1+e.length+l.length,c=o.transaction("input").insertText(s,i,n,[]).setSelection(g(s,r)).build();return t.dispatch(c),!0}const u=`\n${function(t,e,n,o){if("none"===n)return"";const r=X(t,e);return"keep"===n?r:function(t,e){const n=function(t,e){const{start:n}=U(t,e);for(let o=e-1;o>=n;o--){const e=t[o];if(e&&" "!==e&&"\t"!==e)return e}return""}(t,e);return K.has(n)}(t,e)?r+o:r}(a,i,e.indent.mode,l)}`,p=o.transaction("input").insertText(s,i,u,[]).setSelection(g(s,i+u.length)).build();return t.dispatch(p),!0})}(t,r),Backspace:()=>function(t,e){return Y(t,({state:o,block:r,blockId:c,offset:s})=>{if(!d(o.selection))return!1;if(e.pairing.deletePair&&s>0){const i=n(r),a=i[s-1],l=i[s];if(a&&l&&function(t,e){switch(t){case"(":return")"===e;case"[":return"]"===e;case"{":return"}"===e;case'"':case"'":case"`":return e===t;default:return!1}}(a,l)){const n=e.pairStack.peek(c,s);if(n&&n.char===l){const e=o.transaction("input").deleteTextAt(c,s-1,s+1).setSelection(g(c,s-1)).build();return t.dispatch(e),!0}}}if(0!==s)return!1;const i=o.transaction("input").setBlockType(c,h("paragraph")).setSelection(o.selection).build();return t.dispatch(i),!0})}(t,r),Tab:()=>function(t,e){return Y(t,({state:o,sel:r,block:c,blockId:s,offset:l})=>{const p=J(e.indent.useSpaces,e.indent.spaceCount);if(d(r)){const e=o.transaction("input").insertText(s,l,p,[]).setSelection(g(s,l+p.length)).build();return t.dispatch(e),!0}if(r.anchor.blockId!==s||r.head.blockId!==s)return!1;const f=n(c),h=a(r,o.getBlockOrder()),k=h.from.offset,b=h.to.offset;if(!f.slice(k,b).includes("\n")){const e=o.transaction("input").deleteTextAt(s,k,b).insertText(s,k,p,[]).setSelection(g(s,k+p.length)).build();return t.dispatch(e),!0}const m=function(t,e,n,o){const r=t.lastIndexOf("\n",e-1)+1,c=[];let s=0,i=r;for(;i<n;){c.push({offset:i,text:o}),s++;const e=t.indexOf("\n",i);if(-1===e||e>=n)break;i=e+1}return{inserts:c,totalInserted:s*o.length,lineCount:s,lineStart:r}}(f,k,b,p),v=o.transaction("input");for(let t=m.inserts.length-1;t>=0;t--){const e=m.inserts[t];e&&v.insertText(s,e.offset,e.text,[])}const x=u(r,o.getBlockOrder()),C=m.lineStart,y=b+m.totalInserted,S=x?C:y,w=x?y:C;return v.setSelection(i({blockId:s,offset:S},{blockId:s,offset:w})),t.dispatch(v.build()),m.lineCount>=2&&t.announce(e.locale().indentedNLines(m.lineCount)),!0})}(t,r),"Shift-Tab":()=>function(t,e){return Y(t,({state:o,sel:r,block:c,blockId:s,offset:l})=>{const g=n(c);if(d(r))return et(t,o,s,l,g,e);if(r.anchor.blockId!==s||r.head.blockId!==s)return!1;const p=a(r,o.getBlockOrder()),f=p.from.offset,h=p.to.offset;if(!g.slice(f,h).includes("\n"))return et(t,o,s,l,g,e);const k=function(t,e,n,o,r){const c=t.lastIndexOf("\n",e-1)+1,s=[];let i=0,a=0,l=c;for(;l<n;){a++;const e=Q(t.slice(l),o,r);e.removed.length>0&&(s.push({from:l,to:l+e.removed.length}),i+=e.removed.length);const c=t.indexOf("\n",l);if(-1===c||c>=n)break;l=c+1}return{deletes:s,totalRemoved:i,lineCount:a,lineStart:c}}(g,f,h,e.indent.useSpaces,e.indent.spaceCount);if(0===k.totalRemoved)return!0;const b=o.transaction("input");for(let t=k.deletes.length-1;t>=0;t--){const e=k.deletes[t];e&&b.deleteTextAt(s,e.from,e.to)}const m=u(r,o.getBlockOrder()),v=k.lineStart,x=h-k.totalRemoved,C=m?v:Math.max(v,x),y=m?Math.max(v,x):v;return b.setSelection(i({blockId:s,offset:C},{blockId:s,offset:y})),t.dispatch(b.build()),k.lineCount>=2&&t.announce(e.locale().dedentedNLines(k.lineCount)),!0})}(t,r),Escape:()=>nt(t),ArrowDown:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>!!d(e.selection)&&-1===n(o).indexOf("\n",c)&&(rt(t,e,r),!0))}(t),ArrowUp:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>{if(!d(e.selection))return!1;const s=n(o).indexOf("\n");return!(-1!==s&&c>s)&&ct(t,e,r)})}(t),ArrowRight:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>!!d(e.selection)&&c===n(o).length&&(rt(t,e,r),!0))}(t),ArrowLeft:()=>function(t){return Y(t,({state:e,blockId:n,offset:o})=>!!d(e.selection)&&0===o&&ct(t,e,n))}(t)},{insertAfter:l,toggle:p}=o;l&&(s[l]=()=>function(t){return Y(t,({blockId:e})=>(ot(t,e),!0))}(t)),p&&(s[p]=()=>t.executeCommand("toggleCodeBlock")),t.registerKeymap(s,{priority:"context"})}function et(t,e,n,o,r,c){const{start:s}=U(r,o),i=Q(r.slice(s),c.indent.useSpaces,c.indent.spaceCount);if(0===i.removed.length)return!0;const a=e.transaction("input").deleteTextAt(n,s,s+i.removed.length).setSelection(g(n,Math.max(s,o-i.removed.length))).build();return t.dispatch(a),!0}function nt(t){return Y(t,({state:e,blockId:n})=>(rt(t,e,n),!0))}function ot(t,e){const n=t.getState(),o=n.getBlock(e);if(!o)return;const s=r(o),i=c(),a=n.transaction("command").splitBlock(e,s,i).setBlockType(i,h("paragraph")).setSelection(g(i,0)).build();t.dispatch(a)}function rt(t,e,n){const o=e.getBlockOrder(),r=o.indexOf(n);if(r<o.length-1){const n=o[r+1],c=e.transaction("command").setSelection(g(n,0)).build();return void t.dispatch(c)}ot(t,n)}function ct(t,e,n){const o=e.getBlockOrder(),c=o.indexOf(n);if(c<=0)return!1;const s=o[c-1],i=e.getBlock(s),a=i?r(i):0,l=e.transaction("command").setSelection(g(s,a)).build();return t.dispatch(l),!0}function st(t,n){const o=t.getState(),c=o.selection;if(!p(c))return!1;const i=o.getBlock(c.anchor.blockId);if(!i||"code_block"===i.type)return!1;const a={language:n.defaultLanguage??"",backgroundColor:""},l=o.transaction("command");return function(t,n){if(0===r(n))return;const o=s(n);let c=0;for(const r of o)if(e(r)){if(r.text.length>0)for(const e of r.marks)t.removeMark(n.id,c,c+r.text.length,e);c+=r.text.length}else c+=1}(l,i),l.setBlockType(c.anchor.blockId,h("code_block"),a).setSelection(g(c.anchor.blockId,0)),t.dispatch(l.build()),!0}function it(e,n){const r=m(e.doc,n);if(!r)return null;const s=S(r),i=v(e,s),a=x(i,n);if(a<0)return null;const l=e.transaction("command");if(1===i.length){const t=c();return l.insertNode(s,0,o(t)),l.removeNode(s,1),l.setSelection(g(t,0)),l.build()}l.removeNode(s,a);const d=function(e,n,r,s){const i=r[s-1];if(i&&t(i)){const t=C(e,i.id,"end");if(t)return t}const a=r[s+1];if(a&&t(a)){const t=C(e,a.id,"start");if(t)return t}const l=r[s],d=y(e,"start",l&&t(l)?l.id:void 0);if(d)return d;const u=c();return n.insertNode([],0,o(u)),g(u,0)}(e,l,i,a);return l.setSelection(d),l.build()}var at=class{bundles=/* @__PURE__ */new Map;listeners=[];register(t){this.bundles.set(t.id,t);for(const e of this.listeners)e(t)}onRegister(t){this.listeners.push(t);for(const e of this.bundles.values())t(e)}get(t){return this.bundles.get(t)}getAll(){return[...this.bundles.values()]}},lt={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},dt={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},ut=new A("codeBlock"),gt=new A("syntaxHighlighter"),pt=class{languageMap=/* @__PURE__ */new Map;constructor(t){if(t)for(const e of t)this.registerLanguageInternal(e)}registerLanguage(t){this.registerLanguageInternal(t)}tokenize(t,e){const n=this.languageMap.get(e.toLowerCase());if(!n)return[];const o=[];for(const r of N(t,n))o.push({from:r.from,to:r.to,type:r.type});return o}getSupportedLanguages(){const t=/* @__PURE__ */new Set;for(const e of this.languageMap.values()){t.add(e.name);for(const n of e.aliases)t.add(n)}return[...t]}registerLanguageInternal(t){this.languageMap.set(t.name.toLowerCase(),t);for(const e of t.aliases)this.languageMap.set(e.toLowerCase(),t)}},ft={label:"Code Block",tooltip:t=>t?`Code Block (${t})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:t=>`${t} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard",copyFailed:"Failed to copy code",deleteCodeBlockAria:"Delete code block",deletedCodeBlock:"Code block deleted",selectLanguageAria:"Select language",languageChanged:t=>`Language changed to ${t}`,plainText:"plain",indentedNLines:t=>1===t?"1 line indented":`${t} lines indented`,dedentedNLines:t=>1===t?"1 line dedented":`${t} lines dedented`},ht=/* #__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar--Isa9OHJ.mjs"),"./locales/de.ts":()=>import("./de-Dl4QFHMa.mjs"),"./locales/es.ts":()=>import("./es-DD01rZ6N.mjs"),"./locales/fr.ts":()=>import("./fr-CfhyYN-t.mjs"),"./locales/hi.ts":()=>import("./hi-B2YB3Bo4.mjs"),"./locales/pt.ts":()=>import("./pt-DYMyMgKQ.mjs"),"./locales/ru.ts":()=>import("./ru-l73diFXn.mjs"),"./locales/zh.ts":()=>import("./zh-Baxh6v0j.mjs")});async function kt(t){return M(ht,t,ft)}var bt='[role="option"]';function mt(t,e,n,o){const r=document.createElement("div");r.className="notectl-language-picker__option",r.setAttribute("role","option"),r.setAttribute("data-language",n),r.setAttribute("aria-selected",String(o)),r.setAttribute("tabindex",o?"0":"-1"),r.textContent=e,t.appendChild(r)}function vt(t,e,n,o){const r=t.getState(),c=r.getBlock(e);if(!c||"code_block"!==c.type)return;const s=r.getNodePath(e);if(!s)return;const i={...c.attrs,[n]:o},a=r.transaction("command").setNodeAttr(s,i).build();t.dispatch(a)}var xt=class{entries=/* @__PURE__ */new Map;getTokens(t,e,n,o){const r=this.entries.get(t);if(r&&r.text===e&&r.language===n)return r.tokens;const c=o?.tokenize(e,n)??[];return this.entries.set(t,{text:e,language:n,tokens:c}),c}findTokenAt(t,e){const n=this.entries.get(t);if(!n)return;const o=n.tokens;let r=0,c=o.length-1;for(;r<=c;){const t=r+c>>>1,n=o[t];if(!n)return;if(e<n.from)c=t-1;else{if(!(e>=n.to))return n;r=t+1}}}retain(t){for(const e of this.entries.keys())t.has(e)||this.entries.delete(e)}clear(){this.entries.clear()}},Ct=class{id="code-block";name="Code Block";priority=36;config;resolvedIndent;resolvedPairing;resolvedKeymap;context=null;locale;highlighter=null;tokenCache=new xt;autoPair;constructor(t){this.config={...dt,...t},this.resolvedIndent=function(t){const e=t.indent?.useSpaces??t.useSpaces??false,n=t.indent?.spaceCount??t.spaceCount??2,o=Math.max(1,Math.min(16,Math.trunc(n)));return{mode:t.indent?.mode??"brackets",useSpaces:e,spaceCount:o}}(this.config),this.resolvedPairing=function(t){const e=t.pairing;return{brackets:e?.brackets??"languageDefined",quotes:e?.quotes??"languageDefined",overtype:e?.overtype??true,deletePair:e?.deletePair??true,surround:e?.surround??"languageDefined"}}(this.config),this.resolvedKeymap={...lt,...t?.keymap},this.autoPair=new G({resolvedIndent:this.resolvedIndent,resolvedPairing:this.resolvedPairing,getTokenAt:(t,e)=>this.tokenCache.findTokenAt(t,e),getCompositionState:()=>this.context?.getCompositionState()??null})}async init(t){this.locale=await L(t,this.config.locale,ft,kt),t.registerStyleSheet(H),this.context=t,this.highlighter=function(t,e,n){const o=e.highlighter??new pt,r=new at;return r.onRegister(t=>{t.highlighting&&o.registerLanguage&&(o.registerLanguage(t.highlighting),n.clear())}),t.registerService(j,r),r.register($),r.register(E),r.register(z),r.register(D),t.registerService(gt,{registerLanguage:t=>{o.registerLanguage?.(t),n.clear()},getSupportedLanguages:()=>o.getSupportedLanguages(),tokenize:(t,e)=>o.tokenize(t,e),getTokenAt:(t,e)=>n.findTokenAt(t,e)}),o}(t,this.config,this.tokenCache),function(t){t.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(t){const e=k("pre",t.id);e.className="notectl-code-block",e.setAttribute("dir","ltr"),e.setAttribute("part","code-block");const n=document.createElement("code");return n.className="notectl-code-block__content",n.setAttribute("part","code-block-content"),e.appendChild(n),e},toHTML(t,e,n){const o=b(t.attrs?.language??""),r=b(t.attrs?.backgroundColor??""),c=o?` class="language-${o}"`:"";return`<pre dir="ltr"${r?n?.styleAttr(`background-color: ${r}`)??` style="background-color: ${r}"`:""}><code${c}>${e||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(t){const e=t.querySelector("code"),n=e?.className.match(/language-(\S+)/)?.[1]??"";return{language:(e?.getAttribute("data-language")??"")||n}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}(t),this.registerNodeView(t),function(t,e){t.registerCommand("toggleCodeBlock",()=>function(t,e){const n=t.getState();if(!p(n.selection))return!1;const o=n.getBlock(n.selection.anchor.blockId);if(!o)return!1;if("code_block"===o.type){const e=n.transaction("command").setBlockType(n.selection.anchor.blockId,h("paragraph")).setSelection(n.selection).build();return t.dispatch(e),!0}return st(t,e)}(t,e)),t.registerCommand("insertCodeBlock",()=>st(t,e)),t.registerCommand("setCodeBlockLanguage",()=>!1),t.registerCommand("setCodeBlockBackground",()=>!1),t.registerCommand("exitCodeBlock",()=>nt(t)),t.registerCommand("deleteCodeBlock",()=>function(t){const e=t.getState();if(!p(e.selection))return!1;const n=e.getBlock(e.selection.anchor.blockId);if(!n||"code_block"!==n.type)return!1;const o=it(e,n.id);return!!o&&(t.dispatch(o),!0)}(t))}(t,this.config),tt(t,this.config,this.resolvedKeymap,{indent:this.resolvedIndent,pairing:this.resolvedPairing,pairStack:this.autoPair.pairStack,locale:()=>this.locale}),function(t){t.registerInputRule({pattern:/^```(\w*) $/,handler:(t,e,n,o)=>{const r=t.selection;if(!p(r))return null;if(!d(r))return null;const c=t.getBlock(r.anchor.blockId);if(!c||"paragraph"!==c.type)return null;const s={language:e[1]??"",backgroundColor:""};return t.transaction("input").deleteTextAt(r.anchor.blockId,n,n+e[0].length).setBlockType(r.anchor.blockId,h("code_block"),s).setSelection(g(r.anchor.blockId,0)).build()}})}(t),function(t,e,n){t.registerToolbarItem({id:"code_block",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z"/><path d="M11 14.17L8.83 12 11 9.83 9.59 8.41 6 12l3.59 3.59L11 14.17zm3.41 1.42L18 12l-3.59-3.59L13 9.83 15.17 12 13 14.17l1.41 1.42z"/></svg>',label:e.label,tooltip:e.tooltip(n?P(n):void 0),command:"toggleCodeBlock",isActive:t=>!!p(t.selection)&&"code_block"===t.getBlock(t.selection.anchor.blockId)?.type})}(t,this.locale,this.resolvedKeymap.toggle),function(t){t.registerMiddleware((t,e,n)=>{if(!t.steps.some(t=>"addMark"===t.type&&"code_block"===e.getBlock(t.blockId)?.type))return void n(t);const o=t.steps.filter(t=>"addMark"!==t.type||"code_block"!==e.getBlock(t.blockId)?.type);n({...t,steps:o})},{name:"code-block:mark-guard",priority:50})}(t),function(t,e,n){t.registerService(ut,{setLanguage(e,n){vt(t,e,"language",n)},getLanguage(t){const e=n();if(!e)return"";const o=e.getState().getBlock(t);return o&&"code_block"===o.type?o.attrs?.language??"":""},setBackground(e,n){vt(t,e,"backgroundColor",n)},getBackground(t){const e=n();if(!e)return"";const o=e.getState().getBlock(t);return o&&"code_block"===o.type?o.attrs?.backgroundColor??"":""},isCodeBlock(t){const e=n();return!!e&&"code_block"===e.getState().getBlock(t)?.type},getSupportedLanguages(){const t=e();return t?t.getSupportedLanguages():[]}})}(t,()=>this.highlighter,()=>this.context),function(t){t.registerPasteInterceptor((t,e,n)=>{if(!t)return null;if(!p(n.selection))return null;const o=n.getBlock(n.selection.anchor.blockId);if(!o||"code_block"!==o.type)return null;const r=n.transaction("paste");let c=n.selection.anchor.blockId,s=n.selection.anchor.offset;if(!d(n.selection)){const t=f(n,r);t&&(c=t,s=0)}return r.insertText(c,s,t,[]),r.setSelection(g(c,s+t.length)),r.build()},{name:"code-block:paste",priority:10})}(t),t.registerTextInputInterceptor(this.autoPair.handleTextInput,{name:"code-block:auto-pair",priority:10}),function(t){const e=t.getSchemaRegistry(),n=e.getNodeSpec("table_cell");if(!n?.content)return;const o=n.content.allow??[];o.includes("code_block")||(e.removeNodeSpec("table_cell"),e.registerNodeSpec({...n,content:{...n.content,allow:[...o,"code_block"]}}))}(t)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear(),this.autoPair.clear()}onStateChange(t,e,n){if(this.autoPair.syncOnStateChange(e,n),!this.context)return;const o=p(t.selection)?t.selection.anchor.blockId:null,r=p(e.selection)?e.selection.anchor.blockId:null,c=o?t.getBlock(o):void 0,s=r?e.getBlock(r):void 0,i="code_block"===c?.type,a="code_block"===s?.type;!i&&a?this.context.announce(this.locale.enteredCodeBlock):i&&!a&&this.context.announce(this.locale.leftCodeBlock)}decorations(t){return function(t,e){const o=[],r=function(t){if(!p(t.selection))return null;const e=t.selection.anchor.blockId;return"code_block"===t.getBlock(e)?.type?e:null}(t);if(r&&o.push(w(r,{class:"notectl-code-block--focused"})),e.highlighter){const r=/* @__PURE__ */new Set;for(const c of t.getBlockOrder()){const s=t.getBlock(c);if(!s||"code_block"!==s.type)continue;const i=s.attrs?.language??"";if(!i)continue;const a=n(s);if(!a)continue;r.add(c);const l=e.tokenCache.getTokens(c,a,i,e.highlighter);for(const t of l)o.push(_(c,t.from,t.to,{class:`notectl-token--${t.type}`}))}e.tokenCache.retain(r)}return 0===o.length?I.empty:I.create(o)}(t,{highlighter:this.highlighter,tokenCache:this.tokenCache})}registerNodeView(t){const e=new O(t.getContainer()),o=this.highlighter,r={popupManager:e,getSupportedLanguages:()=>o?.getSupportedLanguages()??[]};t.registerNodeView("code_block",function(t,e=ft,o){return(r,c,s)=>{const i=document.createElement("pre");i.className="notectl-code-block",i.setAttribute("data-block-id",r.id),i.setAttribute("dir","ltr"),i.setAttribute("role","group"),i.setAttribute("aria-roledescription","code block"),i.setAttribute("part","code-block");const a=document.createElement("div");a.className="notectl-code-block__header",a.setAttribute("contenteditable","false"),a.setAttribute("part","code-block-header");const l=document.createElement("button");l.className="notectl-code-block__language-btn",l.type="button",l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",e.selectLanguageAria);let d=null;!1!==t.showCopyButton&&(d=document.createElement("button"),d.className="notectl-code-block__copy",d.setAttribute("aria-label",e.copyCodeAria),d.setAttribute("data-notectl-no-print",""),d.type="button",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>');const u=document.createElement("button");u.className="notectl-code-block__delete",u.setAttribute("aria-label",e.deleteCodeBlockAria),u.title=e.deleteCodeBlockAria,u.setAttribute("data-notectl-no-print",""),u.type="button",u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>';const g=document.createElement("span");g.className="notectl-sr-only",g.setAttribute("aria-live","assertive"),g.setAttribute("aria-atomic","true");const p=document.createElement("div");p.className="notectl-code-block__actions",d&&p.appendChild(d),p.appendChild(u),a.appendChild(l),a.appendChild(p),a.appendChild(g);const f=document.createElement("code");f.className="notectl-code-block__content",f.setAttribute("part","code-block-content");const h=document.createElement("div");h.className="notectl-code-block__esc-hint",h.setAttribute("contenteditable","false"),h.setAttribute("aria-hidden","true"),h.setAttribute("data-notectl-no-print",""),h.textContent=e.escToExit,i.appendChild(a),i.appendChild(f),i.appendChild(h),t.background&&B(i,"--notectl-code-block-bg",t.background),t.headerBackground&&B(i,"--notectl-code-block-header-bg",t.headerBackground),t.textColor&&B(i,"--notectl-code-block-color",t.textColor),t.headerColor&&B(i,"--notectl-code-block-header-color",t.headerColor);let k=r.id;function b(t){const n=t.attrs?.language??"",r=n||e.plainText;l.innerHTML="";const c=document.createElement("span");if(c.className="notectl-code-block__language",c.textContent=r,l.appendChild(c),o){const t=document.createElement("span");t.className="notectl-code-block__chevron",t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="10" height="10"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>',l.appendChild(t)}i.setAttribute("aria-label",e.codeBlockAriaLabel(r)),n?f.setAttribute("data-language",n):f.removeAttribute("data-language"),B(i,"backgroundColor",(t.attrs?.backgroundColor??"")||"")}function m(t){g.textContent=t,setTimeout(()=>{g.textContent=""},1e3)}return b(r),d&&d.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const o=c().getBlock(k);o&&function(t){const e=globalThis.navigator?.clipboard;return e&&"function"==typeof e.writeText?e.writeText(t):Promise.reject(/* @__PURE__ */new Error("Clipboard API unavailable"))}(n(o)).then(()=>m(e.copiedToClipboard),()=>m(e.copyFailed))}),u.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const n=it(c(),k);n&&(g.textContent=e.deletedCodeBlock,s(n))}),o&&l.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const n=c().getBlock(k);if(!n)return;const r=n.attrs?.language??"";!function(t){const{anchor:e,languages:n,currentLanguage:o,onSelect:r,popupManager:c,locale:s}=t;c.open({anchor:e,ariaRole:"listbox",ariaLabel:s.selectLanguageAria,className:"notectl-language-picker",position:"below-start",restoreFocusTo:e,content(t,e){const c=o.toLowerCase();mt(t,s.plainText,"",""===c);const i=[...n].sort((t,e)=>t.localeCompare(e));for(const n of i)mt(t,n,n,c===n.toLowerCase());q({container:t,itemSelector:bt,onSelect(t){r(t.getAttribute("data-language")??""),e()},onClose(){e()}}),t.addEventListener("click",t=>{const n=t.target.closest(bt);n&&(r(n.getAttribute("data-language")??""),e())})},onClose(){e.setAttribute("aria-expanded","false")}}),e.setAttribute("aria-expanded","true")}({anchor:l,languages:o.getSupportedLanguages(),currentLanguage:r,locale:e,popupManager:o.popupManager,onSelect(t){if(t===r)return;const n=c(),o=n.getBlock(k);if(!o)return;const i=n.getNodePath(k);if(!i)return;const a={...o.attrs,language:t};s(n.transaction("command").setNodeAttr(i,a).build());const l=t||e.plainText;m(e.languageChanged(l))}})}),{dom:i,contentDOM:f,update:t=>"code_block"===t.type&&(k=t.id,i.setAttribute("data-block-id",t.id),b(t),!0),selectNode(){i.classList.add("notectl-code-block--selected")},deselectNode(){i.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale,r))}};export{ut as a,pt as i,ft as n,gt as o,kt as r,Ct as t};
|
|
2
|
-
//# sourceMappingURL=CodeBlockPlugin-
|
|
1
|
+
import{S as t,T as e,h as n,o,p as r,u as c,v as s}from"./Document-r7vLOAGA.mjs";import{a as i,d as a,i as l,o as d,s as u,t as g,u as p}from"./Selection-HYoVFpAx.mjs";import{t as f}from"./Commands-BIIpx_Zd.mjs";import{a as h}from"./TypeBrands-Ch9856Gb.mjs";import{n as k}from"./DomUtils-Bf7JLFlx.mjs";import{r as b}from"./HTMLUtils-C6B4UT00.mjs";import{r as m}from"./NodeResolver-ChgLF_IP.mjs";import{C as v,S as x,_ as C,v as y,y as S}from"./BlockInsertion-6rR9tIGP.mjs";import{i as w,r as _,t as I}from"./Decoration-ZeyVfwJB.mjs";import{s as B}from"./StyleRuntime-BAutwDZT.mjs";import{n as A}from"./TypedKeys-CA4bfw9O.mjs";import{t as T}from"./SyntaxTokenTypes-BUCOMtL8.mjs";import{a as L,s as M}from"./PluginHelpers-D4quRJ5a.mjs";import{t as P}from"./ShortcutFormatting-TwiufqeV.mjs";import{t as O}from"./PopupManager-CyOfZUab.mjs";import{c as N,l as j}from"./XmlDetector-D7TQpw-e.mjs";import{a as E,r as z,s as $,t as D}from"./XmlSupport-BYiRwlkK.mjs";import{n as q}from"./PopupKeyboardPatterns-tUrT9TyV.mjs";var H=`\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n\tposition: relative;\n\tmargin: 8px 0;\n\tborder-radius: 6px;\n\tbackground: var(--notectl-code-block-bg);\n\tcolor: var(--notectl-code-block-color);\n\tfont-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n\tfont-size: 14px;\n\tline-height: 1.5;\n\toverflow: hidden;\n}\n\n.notectl-code-block__header {\n\tdisplay: flex;\n\talign-items: center;\n\tjustify-content: space-between;\n\tpadding: 6px 12px;\n\tbackground: var(--notectl-code-block-header-bg);\n\tborder-bottom: 1px solid var(--notectl-code-block-header-border);\n\tfont-size: 12px;\n\tcolor: var(--notectl-code-block-header-color);\n\tuser-select: none;\n}\n\n.notectl-code-block__language-btn {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tgap: 4px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 2px 6px;\n\tfont-size: inherit;\n\tfont-family: inherit;\n\ttransition: background 0.15s;\n}\n\n.notectl-code-block__language-btn:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-code-block__language-btn:focus-visible {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 1px;\n}\n\n.notectl-code-block__language {\n\tfont-weight: 500;\n\tletter-spacing: 0.02em;\n}\n\n.notectl-code-block__chevron {\n\tdisplay: inline-flex;\n\talign-items: center;\n\topacity: 0.6;\n}\n\n.notectl-code-block__actions {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 2px;\n}\n\n.notectl-code-block__copy,\n.notectl-code-block__delete {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 24px;\n\theight: 24px;\n\tborder: none;\n\tborder-radius: 4px;\n\tbackground: transparent;\n\tcolor: var(--notectl-code-block-header-color);\n\tcursor: pointer;\n\tpadding: 0;\n\ttransition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover,\n.notectl-code-block__delete:hover {\n\tbackground: rgba(128, 128, 128, 0.15);\n\tcolor: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg,\n.notectl-code-block__delete svg {\n\tfill: currentColor;\n}\n\n.notectl-code-block__content {\n\tdisplay: block;\n\tpadding: 12px 16px;\n\twhite-space: pre-wrap;\n\tword-wrap: break-word;\n\ttab-size: 4;\n\t-moz-tab-size: 4;\n\toutline: none;\n\tmin-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n\toutline: 2px solid var(--notectl-primary);\n\toutline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n\tdisplay: none;\n\tposition: absolute;\n\tbottom: 4px;\n\tinset-inline-end: 8px;\n\tfont-size: 11px;\n\tcolor: var(--notectl-code-block-header-color);\n\topacity: 0.5;\n\tpointer-events: none;\n\tuser-select: none;\n\tfont-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n\tdisplay: block;\n}\n\n/* Language picker popup */\n.notectl-language-picker {\n\tmin-width: 120px;\n\tmax-height: 200px;\n\toverflow-y: auto;\n\tpadding: 4px;\n\tbackground: var(--notectl-surface-raised, #fff);\n\tborder: 1px solid var(--notectl-border, #e0e0e0);\n\tborder-radius: 6px;\n\tbox-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);\n}\n\n.notectl-language-picker__option {\n\tpadding: 6px 10px;\n\tborder-radius: 4px;\n\tcursor: pointer;\n\tfont-size: 13px;\n\tcolor: var(--notectl-fg, #333);\n\twhite-space: nowrap;\n}\n\n.notectl-language-picker__option:hover {\n\tbackground: rgba(128, 128, 128, 0.1);\n}\n\n.notectl-language-picker__option:focus {\n\toutline: none;\n\tbackground: rgba(128, 128, 128, 0.15);\n}\n\n.notectl-language-picker__option[aria-selected="true"] {\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary, #2563eb);\n}\n\n/* Syntax highlighting token classes — generated from canonical token type list */\n${T.map(t=>`.notectl-token--${t} {\n\tcolor: var(--notectl-code-token-${t});\n\tfont-style: var(--notectl-code-token-${t}-font-style, inherit);\n\tfont-weight: var(--notectl-code-token-${t}-font-weight, inherit);\n}`).join("\n")}\n`,R=[{open:"(",close:")",kind:"bracket"},{open:"[",close:"]",kind:"bracket"},{open:"{",close:"}",kind:"bracket"},{open:'"',close:'"',kind:"quote"},{open:"'",close:"'",kind:"quote"},{open:"`",close:"`",kind:"quote"}],V=new Map(R.map(t=>[t.open,t])),F=new Map(R.filter(t=>"bracket"===t.kind).map(t=>[t.close,t]));var K=new Set(["{","[","("]),W={"}":"{","]":"[",")":"("};function U(t,e){const n=t.lastIndexOf("\n",e-1)+1,o=t.indexOf("\n",e);return{start:n,end:-1===o?t.length:o}}function X(t,e){const{start:n,end:o}=U(t,e);let r=n;for(;r<o;){const e=t[r];if(" "!==e&&"\t"!==e)break;r++}return t.slice(n,r)}function J(t,e){return t?" ".repeat(e):"\t"}function Q(t,e,n){if(0===t.length)return{removed:"",rest:t};if(!e&&"\t"===t[0])return{removed:"\t",rest:t.slice(1)};let o=0;for(;o<n&&" "===t[o];)o++;return{removed:t.slice(0,o),rest:t.slice(o)}}var Z=class{buckets=/* @__PURE__ */new Map;push(t,e){const n=this.buckets.get(t.blockId)??[];n.push({pos:t,char:e}),this.buckets.set(t.blockId,n)}take(t,e){const n=this.buckets.get(t);if(n)for(let o=n.length-1;o>=0;o--){const r=n[o];if(r&&r.pos.offset===e)return n.splice(o,1),0===n.length&&this.buckets.delete(t),r}}peek(t,e){const n=this.buckets.get(t);if(n)for(let o=n.length-1;o>=0;o--){const t=n[o];if(t&&t.pos.offset===e)return t}}clearBlock(t){this.buckets.delete(t)}clear(){this.buckets.clear()}sizeForBlock(t){return this.buckets.get(t)?.length??0}get size(){let t=0;for(const e of this.buckets.values())t+=e.length;return t}migrate(t){if(t.isEmpty)return;const e=/* @__PURE__ */new Map;for(const n of this.buckets.values())for(const o of n){const n=t.mapResult(o.pos,1);if(n.deleted)continue;const r={pos:n.pos,char:o.char},c=n.pos.blockId,s=e.get(c)??[];s.push(r),e.set(c,s)}this.buckets.clear();for(const[n,o]of e)this.buckets.set(n,o)}static makePos(t,e){return l(t,e)}},G=class{resolvedIndent;resolvedPairing;getTokenAt;getCompositionState;pairs=new Z;pendingPairOps=[];constructor(t){this.resolvedIndent=t.resolvedIndent,this.resolvedPairing=t.resolvedPairing,this.getTokenAt=t.getTokenAt,this.getCompositionState=t.getCompositionState}get pairStack(){return this.pairs}clear(){this.pairs.clear(),this.pendingPairOps.length=0}syncOnStateChange(t,e){this.pairs.size>0&&!e.mapping.isEmpty&&this.pairs.migrate(e.mapping);for(const n of this.pendingPairOps)"push"===n.kind?this.pairs.push(l(n.blockId,n.offset),n.char):this.pairs.take(n.blockId,n.offset);this.pendingPairOps.length=0;for(const n of e.steps){if("setBlockType"!==n.type)continue;const e=t.getBlock(n.blockId);e&&"code_block"===e.type||this.pairs.clearBlock(n.blockId)}}handleTextInput=(t,e)=>{this.pendingPairOps.length=0;const o=this.getCompositionState();if(!o)return null;if(o.isComposing)return null;if(!p(e.selection))return null;if(1!==t.length)return null;const r=e.selection,c=e.getBlock(r.anchor.blockId);if(!c||"code_block"!==c.type)return null;const s=this.tryDedentOnCloseBracket(e,c,t);if(s)return s;const i=function(t){const{state:e,char:o,config:r}=t;if(!p(e.selection))return{kind:"passthrough"};const c=e.selection,s=V.get(o);if(s&&!d(c)&&function(t,e){switch(e.surround){case"never":return!1;case"brackets":return"bracket"===t.kind;case"quotes":return"quote"===t.kind;case"languageDefined":return!0}}(s,r)){const e=function(t,e,n){const{state:o}=n,r=a(e,o.getBlockOrder());return r.from.blockId!==r.to.blockId||r.from.blockId!==n.blockId?null:{kind:"wrap",open:t.open,close:t.close}}(s,c,t);if(e)return e}return d(c)?r.overtype&&function(t,e){if(!function(t){const e=V.get(t);return"quote"===e?.kind?e:F.get(t)}(e))return!1;const o=t.state.selection;if(!p(o))return!1;const r=n(t.block),c=o.anchor.offset;if(r[c]!==e)return!1;const s=t.pairStack.peek(t.blockId,c);return Boolean(s&&s.char===e)}(t,o)?{kind:"overtype"}:s&&function(t,e){const o="quote"===t.kind?e.config.quotes:e.config.brackets;if("never"===o)return!1;const r=e.state.selection;if(!p(r))return!0;const c=n(e.block),s=r.anchor.offset;if("quote"===t.kind&&"'"===t.open&&function(t,e){if(e<=0)return!1;const n=t[e-1];return!!n&&/[A-Za-z0-9_]/.test(n)}(c,s))return!1;if("always"===o)return!0;if("beforeWhitespace"===o)return function(t,e){if(e>=t.length)return!0;const n=t[e];return!n||!!/\s/.test(n)||!!F.has(n)}(c,s);if("quote"===t.kind){const t=e.getTokenAt(e.blockId,s);return!t||"string"!==t.type&&"comment"!==t.type}return!0}(s,t)?{kind:"pair",close:s.close}:{kind:"passthrough"}:{kind:"passthrough"}}({state:e,block:c,blockId:r.anchor.blockId,char:t,config:this.resolvedPairing,pairStack:this.pairs,getTokenAt:this.getTokenAt});switch(i.kind){case"pair":return this.buildAutoPairTransaction(e,r.anchor.blockId,i.close,t);case"overtype":return this.buildOvertypeTransaction(e,r.anchor.blockId);case"wrap":return this.buildWrapTransaction(e,r.anchor.blockId,i.open,i.close);case"passthrough":return null}};tryDedentOnCloseBracket(t,e,o){if("brackets"!==this.resolvedIndent.mode)return null;if("}"!==o&&"]"!==o&&")"!==o)return null;const r=t.selection;if(!p(r)||!d(r))return null;const c=n(e),s=r.anchor.offset;if(!function(t,e){const{start:n}=U(t,e);for(let o=n;o<e;o++){const e=t[o];if(" "!==e&&"\t"!==e)return!1}return!0}(c,s))return null;const{start:i}=U(c,s);if(i===s)return null;const a=r.anchor.blockId,l=this.findTrackedCloseAfter(c,s,o,a);if(null!==l)return t.transaction("input").deleteTextAt(a,i,l).setSelection(g(a,i+1)).build();const u=Q(c.slice(i,s),this.resolvedIndent.useSpaces,this.resolvedIndent.spaceCount);if(0===u.removed.length)return null;const f=s-u.removed.length;return t.transaction("input").deleteTextAt(a,f,s).insertText(a,f,o,[]).setSelection(g(a,f+1)).build()}findTrackedCloseAfter(t,e,n,o){for(let r=e;r<t.length;r++){const e=t[r];if(" "!==e&&"\t"!==e&&"\n"!==e){if(e===n){const t=this.pairs.peek(o,r);if(t&&t.char===n)return r}return null}}return null}buildAutoPairTransaction(t,e,n,o){const r=t.selection;if(!p(r))throw new Error("buildAutoPairTransaction requires a text selection");const c=r.anchor.offset,s=`${o}${n}`,i=t.transaction("input").insertText(e,c,s,[]).setSelection(g(e,c+1)).build();return this.pendingPairOps.push({kind:"push",blockId:e,offset:c+1,char:n}),i}buildOvertypeTransaction(t,e){const n=t.selection;if(!p(n))throw new Error("buildOvertypeTransaction requires a text selection");const o=n.anchor.offset;return this.pendingPairOps.push({kind:"take",blockId:e,offset:o}),t.transaction("input").setSelection(g(e,o+1)).build()}buildWrapTransaction(t,e,n,o){const r=t.selection;if(!p(r))throw new Error("buildWrapTransaction requires a text selection");const c=function(t,e){const n=a(t,e);return{fromOffset:n.from.offset,toOffset:n.to.offset}}(r,t.getBlockOrder()),s=a(r,t.getBlockOrder()).from===r.anchor,i=c.fromOffset+1,l=c.toOffset+1,d=s?i:l,u=s?l:i;return t.transaction("input").insertText(e,c.toOffset,o,[]).insertText(e,c.fromOffset,n,[]).setSelection({anchor:{blockId:e,offset:d},head:{blockId:e,offset:u}}).build()}};function Y(t,e){const n=t.getState();if(!p(n.selection))return!1;const o=n.selection,r=n.getBlock(o.anchor.blockId);return!(!r||"code_block"!==r.type)&&e({state:n,sel:o,block:r,blockId:o.anchor.blockId,offset:o.anchor.offset})}function tt(t,e,o,r){const s={Enter:()=>function(t,e){return Y(t,({state:o,block:r,blockId:s,offset:i})=>{if(!d(o.selection))return!1;const a=n(r);if(a.endsWith("\n")&&i===a.length)return function(t,e,n){const o=t.getState(),r=n.length-1,s=c(),i=o.transaction("input").deleteTextAt(e,r,n.length).splitBlock(e,r,s).setBlockType(s,h("paragraph")).setSelection(g(s,0)).build();return t.dispatch(i),!0}(t,s,a);const l=J(e.indent.useSpaces,e.indent.spaceCount);if("brackets"===e.indent.mode&&function(t,e){return function(t,e){if(e<=0||e>=t.length)return!1;const n=t[e-1],o=t[e];return!(!n||!o)&&W[o]===n}(t,e)}(a,i)){const e=X(a,i),n=`\n${e}${l}\n${e}`,r=i+1+e.length+l.length,c=o.transaction("input").insertText(s,i,n,[]).setSelection(g(s,r)).build();return t.dispatch(c),!0}const u=`\n${function(t,e,n,o){if("none"===n)return"";const r=X(t,e);return"keep"===n?r:function(t,e){const n=function(t,e){const{start:n}=U(t,e);for(let o=e-1;o>=n;o--){const e=t[o];if(e&&" "!==e&&"\t"!==e)return e}return""}(t,e);return K.has(n)}(t,e)?r+o:r}(a,i,e.indent.mode,l)}`,p=o.transaction("input").insertText(s,i,u,[]).setSelection(g(s,i+u.length)).build();return t.dispatch(p),!0})}(t,r),Backspace:()=>function(t,e){return Y(t,({state:o,block:r,blockId:c,offset:s})=>{if(!d(o.selection))return!1;if(e.pairing.deletePair&&s>0){const i=n(r),a=i[s-1],l=i[s];if(a&&l&&function(t,e){switch(t){case"(":return")"===e;case"[":return"]"===e;case"{":return"}"===e;case'"':case"'":case"`":return e===t;default:return!1}}(a,l)){const n=e.pairStack.peek(c,s);if(n&&n.char===l){const e=o.transaction("input").deleteTextAt(c,s-1,s+1).setSelection(g(c,s-1)).build();return t.dispatch(e),!0}}}if(0!==s)return!1;const i=o.transaction("input").setBlockType(c,h("paragraph")).setSelection(o.selection).build();return t.dispatch(i),!0})}(t,r),Tab:()=>function(t,e){return Y(t,({state:o,sel:r,block:c,blockId:s,offset:l})=>{const p=J(e.indent.useSpaces,e.indent.spaceCount);if(d(r)){const e=o.transaction("input").insertText(s,l,p,[]).setSelection(g(s,l+p.length)).build();return t.dispatch(e),!0}if(r.anchor.blockId!==s||r.head.blockId!==s)return!1;const f=n(c),h=a(r,o.getBlockOrder()),k=h.from.offset,b=h.to.offset;if(!f.slice(k,b).includes("\n")){const e=o.transaction("input").deleteTextAt(s,k,b).insertText(s,k,p,[]).setSelection(g(s,k+p.length)).build();return t.dispatch(e),!0}const m=function(t,e,n,o){const r=t.lastIndexOf("\n",e-1)+1,c=[];let s=0,i=r;for(;i<n;){c.push({offset:i,text:o}),s++;const e=t.indexOf("\n",i);if(-1===e||e>=n)break;i=e+1}return{inserts:c,totalInserted:s*o.length,lineCount:s,lineStart:r}}(f,k,b,p),v=o.transaction("input");for(let t=m.inserts.length-1;t>=0;t--){const e=m.inserts[t];e&&v.insertText(s,e.offset,e.text,[])}const x=u(r,o.getBlockOrder()),C=m.lineStart,y=b+m.totalInserted,S=x?C:y,w=x?y:C;return v.setSelection(i({blockId:s,offset:S},{blockId:s,offset:w})),t.dispatch(v.build()),m.lineCount>=2&&t.announce(e.locale().indentedNLines(m.lineCount)),!0})}(t,r),"Shift-Tab":()=>function(t,e){return Y(t,({state:o,sel:r,block:c,blockId:s,offset:l})=>{const g=n(c);if(d(r))return et(t,o,s,l,g,e);if(r.anchor.blockId!==s||r.head.blockId!==s)return!1;const p=a(r,o.getBlockOrder()),f=p.from.offset,h=p.to.offset;if(!g.slice(f,h).includes("\n"))return et(t,o,s,l,g,e);const k=function(t,e,n,o,r){const c=t.lastIndexOf("\n",e-1)+1,s=[];let i=0,a=0,l=c;for(;l<n;){a++;const e=Q(t.slice(l),o,r);e.removed.length>0&&(s.push({from:l,to:l+e.removed.length}),i+=e.removed.length);const c=t.indexOf("\n",l);if(-1===c||c>=n)break;l=c+1}return{deletes:s,totalRemoved:i,lineCount:a,lineStart:c}}(g,f,h,e.indent.useSpaces,e.indent.spaceCount);if(0===k.totalRemoved)return!0;const b=o.transaction("input");for(let t=k.deletes.length-1;t>=0;t--){const e=k.deletes[t];e&&b.deleteTextAt(s,e.from,e.to)}const m=u(r,o.getBlockOrder()),v=k.lineStart,x=h-k.totalRemoved,C=m?v:Math.max(v,x),y=m?Math.max(v,x):v;return b.setSelection(i({blockId:s,offset:C},{blockId:s,offset:y})),t.dispatch(b.build()),k.lineCount>=2&&t.announce(e.locale().dedentedNLines(k.lineCount)),!0})}(t,r),Escape:()=>nt(t),ArrowDown:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>!!d(e.selection)&&-1===n(o).indexOf("\n",c)&&(rt(t,e,r),!0))}(t),ArrowUp:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>{if(!d(e.selection))return!1;const s=n(o).indexOf("\n");return!(-1!==s&&c>s)&&ct(t,e,r)})}(t),ArrowRight:()=>function(t){return Y(t,({state:e,block:o,blockId:r,offset:c})=>!!d(e.selection)&&c===n(o).length&&(rt(t,e,r),!0))}(t),ArrowLeft:()=>function(t){return Y(t,({state:e,blockId:n,offset:o})=>!!d(e.selection)&&0===o&&ct(t,e,n))}(t)},{insertAfter:l,toggle:p}=o;l&&(s[l]=()=>function(t){return Y(t,({blockId:e})=>(ot(t,e),!0))}(t)),p&&(s[p]=()=>t.executeCommand("toggleCodeBlock")),t.registerKeymap(s,{priority:"context"})}function et(t,e,n,o,r,c){const{start:s}=U(r,o),i=Q(r.slice(s),c.indent.useSpaces,c.indent.spaceCount);if(0===i.removed.length)return!0;const a=e.transaction("input").deleteTextAt(n,s,s+i.removed.length).setSelection(g(n,Math.max(s,o-i.removed.length))).build();return t.dispatch(a),!0}function nt(t){return Y(t,({state:e,blockId:n})=>(rt(t,e,n),!0))}function ot(t,e){const n=t.getState(),o=n.getBlock(e);if(!o)return;const s=r(o),i=c(),a=n.transaction("command").splitBlock(e,s,i).setBlockType(i,h("paragraph")).setSelection(g(i,0)).build();t.dispatch(a)}function rt(t,e,n){const o=e.getBlockOrder(),r=o.indexOf(n);if(r<o.length-1){const n=o[r+1],c=e.transaction("command").setSelection(g(n,0)).build();return void t.dispatch(c)}ot(t,n)}function ct(t,e,n){const o=e.getBlockOrder(),c=o.indexOf(n);if(c<=0)return!1;const s=o[c-1],i=e.getBlock(s),a=i?r(i):0,l=e.transaction("command").setSelection(g(s,a)).build();return t.dispatch(l),!0}function st(t,n){const o=t.getState(),c=o.selection;if(!p(c))return!1;const i=o.getBlock(c.anchor.blockId);if(!i||"code_block"===i.type)return!1;const a={language:n.defaultLanguage??"",backgroundColor:""},l=o.transaction("command");return function(t,n){if(0===r(n))return;const o=s(n);let c=0;for(const r of o)if(e(r)){if(r.text.length>0)for(const e of r.marks)t.removeMark(n.id,c,c+r.text.length,e);c+=r.text.length}else c+=1}(l,i),l.setBlockType(c.anchor.blockId,h("code_block"),a).setSelection(g(c.anchor.blockId,0)),t.dispatch(l.build()),!0}function it(e,n){const r=m(e.doc,n);if(!r)return null;const s=S(r),i=v(e,s),a=x(i,n);if(a<0)return null;const l=e.transaction("command");if(1===i.length){const t=c();return l.insertNode(s,0,o(t)),l.removeNode(s,1),l.setSelection(g(t,0)),l.build()}l.removeNode(s,a);const d=function(e,n,r,s){const i=r[s-1];if(i&&t(i)){const t=C(e,i.id,"end");if(t)return t}const a=r[s+1];if(a&&t(a)){const t=C(e,a.id,"start");if(t)return t}const l=r[s],d=y(e,"start",l&&t(l)?l.id:void 0);if(d)return d;const u=c();return n.insertNode([],0,o(u)),g(u,0)}(e,l,i,a);return l.setSelection(d),l.build()}var at=class{bundles=/* @__PURE__ */new Map;listeners=[];register(t){this.bundles.set(t.id,t);for(const e of this.listeners)e(t)}onRegister(t){this.listeners.push(t);for(const e of this.bundles.values())t(e)}get(t){return this.bundles.get(t)}getAll(){return[...this.bundles.values()]}},lt={insertAfter:"Mod-Enter",toggle:"Mod-Shift-M"},dt={defaultLanguage:"",useSpaces:!1,spaceCount:2,showCopyButton:!0},ut=new A("codeBlock"),gt=new A("syntaxHighlighter"),pt=class{languageMap=/* @__PURE__ */new Map;constructor(t){if(t)for(const e of t)this.registerLanguageInternal(e)}registerLanguage(t){this.registerLanguageInternal(t)}tokenize(t,e){const n=this.languageMap.get(e.toLowerCase());if(!n)return[];const o=[];for(const r of N(t,n))o.push({from:r.from,to:r.to,type:r.type});return o}getSupportedLanguages(){const t=/* @__PURE__ */new Set;for(const e of this.languageMap.values()){t.add(e.name);for(const n of e.aliases)t.add(n)}return[...t]}registerLanguageInternal(t){this.languageMap.set(t.name.toLowerCase(),t);for(const e of t.aliases)this.languageMap.set(e.toLowerCase(),t)}},ft={label:"Code Block",tooltip:t=>t?`Code Block (${t})`:"Code Block",enteredCodeBlock:"Entered code block. Press Escape to exit.",leftCodeBlock:"Left code block.",copyCodeAria:"Copy code",escToExit:"Esc to exit",codeBlockAriaLabel:t=>`${t} code block. Press Escape to exit.`,copiedToClipboard:"Copied to clipboard",copyFailed:"Failed to copy code",deleteCodeBlockAria:"Delete code block",deletedCodeBlock:"Code block deleted",selectLanguageAria:"Select language",languageChanged:t=>`Language changed to ${t}`,plainText:"plain",indentedNLines:t=>1===t?"1 line indented":`${t} lines indented`,dedentedNLines:t=>1===t?"1 line dedented":`${t} lines dedented`},ht=/* #__PURE__ */Object.assign({"./locales/ar.ts":()=>import("./ar--Isa9OHJ.mjs"),"./locales/de.ts":()=>import("./de-Dl4QFHMa.mjs"),"./locales/es.ts":()=>import("./es-DD01rZ6N.mjs"),"./locales/fr.ts":()=>import("./fr-CfhyYN-t.mjs"),"./locales/hi.ts":()=>import("./hi-B2YB3Bo4.mjs"),"./locales/pt.ts":()=>import("./pt-DYMyMgKQ.mjs"),"./locales/ru.ts":()=>import("./ru-l73diFXn.mjs"),"./locales/zh.ts":()=>import("./zh-Baxh6v0j.mjs")});async function kt(t){return M(ht,t,ft)}var bt='[role="option"]';function mt(t,e,n,o){const r=document.createElement("div");r.className="notectl-language-picker__option",r.setAttribute("role","option"),r.setAttribute("data-language",n),r.setAttribute("aria-selected",String(o)),r.setAttribute("tabindex",o?"0":"-1"),r.textContent=e,t.appendChild(r)}function vt(t,e,n,o){const r=t.getState(),c=r.getBlock(e);if(!c||"code_block"!==c.type)return;const s=r.getNodePath(e);if(!s)return;const i={...c.attrs,[n]:o},a=r.transaction("command").setNodeAttr(s,i).build();t.dispatch(a)}var xt=class{entries=/* @__PURE__ */new Map;getTokens(t,e,n,o){const r=this.entries.get(t);if(r&&r.text===e&&r.language===n)return r.tokens;const c=o?.tokenize(e,n)??[];return this.entries.set(t,{text:e,language:n,tokens:c}),c}findTokenAt(t,e){const n=this.entries.get(t);if(!n)return;const o=n.tokens;let r=0,c=o.length-1;for(;r<=c;){const t=r+c>>>1,n=o[t];if(!n)return;if(e<n.from)c=t-1;else{if(!(e>=n.to))return n;r=t+1}}}retain(t){for(const e of this.entries.keys())t.has(e)||this.entries.delete(e)}clear(){this.entries.clear()}},Ct=class{id="code-block";name="Code Block";priority=36;config;resolvedIndent;resolvedPairing;resolvedKeymap;context=null;locale;highlighter=null;tokenCache=new xt;autoPair;constructor(t){this.config={...dt,...t},this.resolvedIndent=function(t){const e=t.indent?.useSpaces??t.useSpaces??false,n=t.indent?.spaceCount??t.spaceCount??2,o=Math.max(1,Math.min(16,Math.trunc(n)));return{mode:t.indent?.mode??"brackets",useSpaces:e,spaceCount:o}}(this.config),this.resolvedPairing=function(t){const e=t.pairing;return{brackets:e?.brackets??"languageDefined",quotes:e?.quotes??"languageDefined",overtype:e?.overtype??true,deletePair:e?.deletePair??true,surround:e?.surround??"languageDefined"}}(this.config),this.resolvedKeymap={...lt,...t?.keymap},this.autoPair=new G({resolvedIndent:this.resolvedIndent,resolvedPairing:this.resolvedPairing,getTokenAt:(t,e)=>this.tokenCache.findTokenAt(t,e),getCompositionState:()=>this.context?.getCompositionState()??null})}async init(t){this.locale=await L(t,this.config.locale,ft,kt),t.registerStyleSheet(H),this.context=t,this.highlighter=function(t,e,n){const o=e.highlighter??new pt,r=new at;return r.onRegister(t=>{t.highlighting&&o.registerLanguage&&(o.registerLanguage(t.highlighting),n.clear())}),t.registerService(j,r),r.register($),r.register(E),r.register(z),r.register(D),t.registerService(gt,{registerLanguage:t=>{o.registerLanguage?.(t),n.clear()},getSupportedLanguages:()=>o.getSupportedLanguages(),tokenize:(t,e)=>o.tokenize(t,e),getTokenAt:(t,e)=>n.findTokenAt(t,e)}),o}(t,this.config,this.tokenCache),function(t){t.registerNodeSpec({type:"code_block",group:"block",content:{allow:["text"]},selectable:!0,attrs:{language:{default:""},backgroundColor:{default:""}},toDOM(t){const e=k("pre",t.id);e.className="notectl-code-block",e.setAttribute("dir","ltr"),e.setAttribute("part","code-block");const n=document.createElement("code");return n.className="notectl-code-block__content",n.setAttribute("part","code-block-content"),e.appendChild(n),e},toHTML(t,e,n){const o=b(t.attrs?.language??""),r=b(t.attrs?.backgroundColor??""),c=o?` class="language-${o}"`:"";return`<pre dir="ltr"${r?n?.styleAttr(`background-color: ${r}`)??` style="background-color: ${r}"`:""}><code${c}>${e||""}</code></pre>`},parseHTML:[{tag:"pre",getAttrs(t){const e=t.querySelector("code"),n=e?.className.match(/language-(\S+)/)?.[1]??"";return{language:(e?.getAttribute("data-language")??"")||n}}}],sanitize:{tags:["pre","code"],attrs:["data-language","class","style"]}})}(t),this.registerNodeView(t),function(t,e){t.registerCommand("toggleCodeBlock",()=>function(t,e){const n=t.getState();if(!p(n.selection))return!1;const o=n.getBlock(n.selection.anchor.blockId);if(!o)return!1;if("code_block"===o.type){const e=n.transaction("command").setBlockType(n.selection.anchor.blockId,h("paragraph")).setSelection(n.selection).build();return t.dispatch(e),!0}return st(t,e)}(t,e)),t.registerCommand("insertCodeBlock",()=>st(t,e)),t.registerCommand("setCodeBlockLanguage",()=>!1),t.registerCommand("setCodeBlockBackground",()=>!1),t.registerCommand("exitCodeBlock",()=>nt(t)),t.registerCommand("deleteCodeBlock",()=>function(t){const e=t.getState();if(!p(e.selection))return!1;const n=e.getBlock(e.selection.anchor.blockId);if(!n||"code_block"!==n.type)return!1;const o=it(e,n.id);return!!o&&(t.dispatch(o),!0)}(t))}(t,this.config),tt(t,this.config,this.resolvedKeymap,{indent:this.resolvedIndent,pairing:this.resolvedPairing,pairStack:this.autoPair.pairStack,locale:()=>this.locale}),function(t){t.registerInputRule({pattern:/^```(\w*) $/,handler:(t,e,n,o)=>{const r=t.selection;if(!p(r))return null;if(!d(r))return null;const c=t.getBlock(r.anchor.blockId);if(!c||"paragraph"!==c.type)return null;const s={language:e[1]??"",backgroundColor:""};return t.transaction("input").deleteTextAt(r.anchor.blockId,n,n+e[0].length).setBlockType(r.anchor.blockId,h("code_block"),s).setSelection(g(r.anchor.blockId,0)).build()}})}(t),function(t,e,n){t.registerToolbarItem({id:"code_block",group:"block",icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z"/><path d="M11 14.17L8.83 12 11 9.83 9.59 8.41 6 12l3.59 3.59L11 14.17zm3.41 1.42L18 12l-3.59-3.59L13 9.83 15.17 12 13 14.17l1.41 1.42z"/></svg>',label:e.label,tooltip:e.tooltip(n?P(n):void 0),command:"toggleCodeBlock",isActive:t=>!!p(t.selection)&&"code_block"===t.getBlock(t.selection.anchor.blockId)?.type})}(t,this.locale,this.resolvedKeymap.toggle),function(t){t.registerMiddleware((t,e,n)=>{if(!t.steps.some(t=>"addMark"===t.type&&"code_block"===e.getBlock(t.blockId)?.type))return void n(t);const o=t.steps.filter(t=>"addMark"!==t.type||"code_block"!==e.getBlock(t.blockId)?.type);n({...t,steps:o})},{name:"code-block:mark-guard",priority:50})}(t),function(t,e,n){t.registerService(ut,{setLanguage(e,n){vt(t,e,"language",n)},getLanguage(t){const e=n();if(!e)return"";const o=e.getState().getBlock(t);return o&&"code_block"===o.type?o.attrs?.language??"":""},setBackground(e,n){vt(t,e,"backgroundColor",n)},getBackground(t){const e=n();if(!e)return"";const o=e.getState().getBlock(t);return o&&"code_block"===o.type?o.attrs?.backgroundColor??"":""},isCodeBlock(t){const e=n();return!!e&&"code_block"===e.getState().getBlock(t)?.type},getSupportedLanguages(){const t=e();return t?t.getSupportedLanguages():[]}})}(t,()=>this.highlighter,()=>this.context),function(t){t.registerPasteInterceptor((t,e,n)=>{if(!t)return null;if(!p(n.selection))return null;const o=n.getBlock(n.selection.anchor.blockId);if(!o||"code_block"!==o.type)return null;const r=n.transaction("paste");let c=n.selection.anchor.blockId,s=n.selection.anchor.offset;if(!d(n.selection)){const t=f(n,r);t&&(c=t,s=0)}return r.insertText(c,s,t,[]),r.setSelection(g(c,s+t.length)),r.build()},{name:"code-block:paste",priority:10})}(t),t.registerTextInputInterceptor(this.autoPair.handleTextInput,{name:"code-block:auto-pair",priority:10}),function(t){const e=t.getSchemaRegistry(),n=e.getNodeSpec("table_cell");if(!n?.content)return;const o=n.content.allow??[];o.includes("code_block")||(e.removeNodeSpec("table_cell"),e.registerNodeSpec({...n,content:{...n.content,allow:[...o,"code_block"]}}))}(t)}destroy(){this.context=null,this.highlighter=null,this.tokenCache.clear(),this.autoPair.clear()}onStateChange(t,e,n){if(this.autoPair.syncOnStateChange(e,n),!this.context)return;const o=p(t.selection)?t.selection.anchor.blockId:null,r=p(e.selection)?e.selection.anchor.blockId:null,c=o?t.getBlock(o):void 0,s=r?e.getBlock(r):void 0,i="code_block"===c?.type,a="code_block"===s?.type;!i&&a?this.context.announce(this.locale.enteredCodeBlock):i&&!a&&this.context.announce(this.locale.leftCodeBlock)}decorations(t){return function(t,e){const o=[],r=function(t){if(!p(t.selection))return null;const e=t.selection.anchor.blockId;return"code_block"===t.getBlock(e)?.type?e:null}(t);if(r&&o.push(w(r,{class:"notectl-code-block--focused"})),e.highlighter){const r=/* @__PURE__ */new Set;for(const c of t.getBlockOrder()){const s=t.getBlock(c);if(!s||"code_block"!==s.type)continue;const i=s.attrs?.language??"";if(!i)continue;const a=n(s);if(!a)continue;r.add(c);const l=e.tokenCache.getTokens(c,a,i,e.highlighter);for(const t of l)o.push(_(c,t.from,t.to,{class:`notectl-token--${t.type}`}))}e.tokenCache.retain(r)}return 0===o.length?I.empty:I.create(o)}(t,{highlighter:this.highlighter,tokenCache:this.tokenCache})}registerNodeView(t){const e=new O(t.getContainer()),o=this.highlighter,r={popupManager:e,getSupportedLanguages:()=>o?.getSupportedLanguages()??[]};t.registerNodeView("code_block",function(t,e=ft,o){return(r,c,s)=>{const i=document.createElement("pre");i.className="notectl-code-block",i.setAttribute("data-block-id",r.id),i.setAttribute("dir","ltr"),i.setAttribute("role","group"),i.setAttribute("aria-roledescription","code block"),i.setAttribute("part","code-block");const a=document.createElement("div");a.className="notectl-code-block__header",a.setAttribute("contenteditable","false"),a.setAttribute("part","code-block-header");const l=document.createElement("button");l.className="notectl-code-block__language-btn",l.type="button",l.setAttribute("aria-haspopup","listbox"),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",e.selectLanguageAria);let d=null;!1!==t.showCopyButton&&(d=document.createElement("button"),d.className="notectl-code-block__copy",d.setAttribute("aria-label",e.copyCodeAria),d.setAttribute("data-notectl-no-print",""),d.type="button",d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>');const u=document.createElement("button");u.className="notectl-code-block__delete",u.setAttribute("aria-label",e.deleteCodeBlockAria),u.title=e.deleteCodeBlockAria,u.setAttribute("data-notectl-no-print",""),u.type="button",u.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/></svg>';const g=document.createElement("span");g.className="notectl-sr-only",g.setAttribute("aria-live","assertive"),g.setAttribute("aria-atomic","true");const p=document.createElement("div");p.className="notectl-code-block__actions",d&&p.appendChild(d),p.appendChild(u),a.appendChild(l),a.appendChild(p),a.appendChild(g);const f=document.createElement("code");f.className="notectl-code-block__content",f.setAttribute("part","code-block-content");const h=document.createElement("div");h.className="notectl-code-block__esc-hint",h.setAttribute("contenteditable","false"),h.setAttribute("aria-hidden","true"),h.setAttribute("data-notectl-no-print",""),h.textContent=e.escToExit,i.appendChild(a),i.appendChild(f),i.appendChild(h),t.background&&B(i,"--notectl-code-block-bg",t.background),t.headerBackground&&B(i,"--notectl-code-block-header-bg",t.headerBackground),t.textColor&&B(i,"--notectl-code-block-color",t.textColor),t.headerColor&&B(i,"--notectl-code-block-header-color",t.headerColor);let k=r.id;function b(t){const n=t.attrs?.language??"",r=n||e.plainText;l.innerHTML="";const c=document.createElement("span");if(c.className="notectl-code-block__language",c.textContent=r,l.appendChild(c),o){const t=document.createElement("span");t.className="notectl-code-block__chevron",t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="10" height="10"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>',l.appendChild(t)}i.setAttribute("aria-label",e.codeBlockAriaLabel(r)),n?f.setAttribute("data-language",n):f.removeAttribute("data-language"),B(i,"backgroundColor",(t.attrs?.backgroundColor??"")||"")}function m(t){g.textContent=t,setTimeout(()=>{g.textContent=""},1e3)}return b(r),d&&d.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const o=c().getBlock(k);o&&function(t){const e=globalThis.navigator?.clipboard;return e&&"function"==typeof e.writeText?e.writeText(t):Promise.reject(/* @__PURE__ */new Error("Clipboard API unavailable"))}(n(o)).then(()=>m(e.copiedToClipboard),()=>m(e.copyFailed))}),u.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const n=it(c(),k);n&&(g.textContent=e.deletedCodeBlock,s(n))}),o&&l.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const n=c().getBlock(k);if(!n)return;const r=n.attrs?.language??"";!function(t){const{anchor:e,languages:n,currentLanguage:o,onSelect:r,popupManager:c,locale:s}=t;c.open({anchor:e,ariaRole:"listbox",ariaLabel:s.selectLanguageAria,className:"notectl-language-picker",position:"below-start",restoreFocusTo:e,content(t,e){const c=o.toLowerCase();mt(t,s.plainText,"",""===c);const i=[...n].sort((t,e)=>t.localeCompare(e));for(const n of i)mt(t,n,n,c===n.toLowerCase());q({container:t,itemSelector:bt,onSelect(t){r(t.getAttribute("data-language")??""),e()},onClose(){e()}}),t.addEventListener("click",t=>{const n=t.target.closest(bt);n&&(r(n.getAttribute("data-language")??""),e())})},onClose(){e.setAttribute("aria-expanded","false")}}),e.setAttribute("aria-expanded","true")}({anchor:l,languages:o.getSupportedLanguages(),currentLanguage:r,locale:e,popupManager:o.popupManager,onSelect(t){if(t===r)return;const n=c(),o=n.getBlock(k);if(!o)return;const i=n.getNodePath(k);if(!i)return;const a={...o.attrs,language:t};s(n.transaction("command").setNodeAttr(i,a).build());const l=t||e.plainText;m(e.languageChanged(l))}})}),{dom:i,contentDOM:f,update:t=>"code_block"===t.type&&(k=t.id,i.setAttribute("data-block-id",t.id),b(t),!0),selectNode(){i.classList.add("notectl-code-block--selected")},deselectNode(){i.classList.remove("notectl-code-block--selected")},destroy(){}}}}(this.config,this.locale,r))}};export{ut as a,pt as i,ft as n,gt as o,kt as r,Ct as t};
|
|
2
|
+
//# sourceMappingURL=CodeBlockPlugin-CcB0WaIz.mjs.map
|