prosemirror-codemirror-block 0.2.4 → 0.2.5
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/index.es.js +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function q(t,e,o,r){return new(o||(o=Promise))((function(n,a){function c(t){try{s(r.next(t))}catch(t){a(t)}}function i(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(c,i)}s((r=r.apply(t,e||[])).next())}))}function z(t,e){if(t===e)return null;let o=0,r=t.length,n=e.length;for(;o<r&&t.charCodeAt(o)===e.charCodeAt(o);)o+=1;for(;r>o&&n>o&&t.charCodeAt(r-1)===e.charCodeAt(n-1);)r-=1,n-=1;return{from:o,to:r,text:e.slice(o,n)}}const L=(t,o,r)=>{if(!t.hasFocus)return;const n=((t,o,r)=>{const n=("function"==typeof r&&r()||0)+1,a=o.state.selection.main.from+n,c=o.state.selection.main.to+n;return e.create(t,a,c)})(o.state.doc,t,r);n.eq(o.state.selection)||o.dispatch(o.state.tr.setSelection(n))},N=(e,o,r,n,a)=>{const c=r.state.selection.main,i=r.state.doc.lineAt(c.from),s=r.state.doc.lines;if(c.to!==c.from||i.number!==(o<0?1:s)||"char"===e&&c.from!==(o<0?0:i.to)||"function"!=typeof a)return!1;n.focus();const l=n.state.doc.nodeAt(a());if(!l)return!1;const m=a()+(o<0?0:l.nodeSize),d=t.near(n.state.doc.resolve(m),o);return n.dispatch(n.state.tr.setSelection(d).scrollIntoView()),n.focus(),!0},O=(t,e)=>{const{selection:o}=e.state;return!(!o.main.empty||0!==o.main.from)&&(C(t.state.schema.nodes.paragraph)(t.state,t.dispatch),setTimeout((()=>t.focus()),20),!0)},T=(t,e,o,r)=>q(void 0,void 0,void 0,(function*(){var n,a;const c=yield null===(a=null===(n=o.languageLoaders)||void 0===n?void 0:n[t])||void 0===a?void 0:a.call(n);c&&e.dispatch({effects:r.reconfigure(c)})})),B=e=>(o,r,n)=>{if(o.selection.empty&&(null==n?void 0:n.endOfTextblock(e))){const n="left"===e||"up"===e?-1:1,{$head:a}=o.selection,c=t.near(o.doc.resolve(n>0?a.after():a.before()),n);if(c.$head&&"code_block"===c.$head.parent.type.name)return null==r||r(o.tr.setSelection(c)),!0}return!1},D={ArrowLeft:B("left"),ArrowRight:B("right"),ArrowUp:B("up"),ArrowDown:B("down")},H=t=>(e,o,r)=>{let C=e,q=!1;const B=document.createElement("div");B.className="codeblock-root";const D=new A,H=M.create({extensions:[n(),a(),f(),S(),c(),p(),v(),b(),s({cursorBlinkRate:1e3}),M.allowMultipleSelections.of(!0),l(),j.fallback,D.of([]),g(),m.domEventHandlers({blur(t,e){e.dispatch({selection:{anchor:0}})}}),d.of([{key:"Mod-d",run:u,preventDefault:!0},{key:"ArrowUp",run:t=>N("line",-1,t,o,r)},{key:"ArrowLeft",run:t=>N("char",-1,t,o,r)},{key:"ArrowDown",run:t=>N("line",1,t,o,r)},{key:"ArrowRight",run:t=>N("char",1,t,o,r)},{key:"Mod-z",run:()=>{var e;return(null===(e=t.undo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0},shift:()=>{var e;return(null===(e=t.redo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0}},{key:"Mod-y",run:()=>{var e;return(null===(e=t.redo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0}},{key:"Backspace",run:t=>O(o,t)},{key:"Mod-Backspace",run:t=>O(o,t)},{key:"Mod-a",run:()=>{const t=E(o.state,o.dispatch);return o.focus(),t}},...w,...h,...i,...y,...x,k])],doc:C.textContent}),R=new m({state:H,dispatch:t=>{if(
|
|
15
|
+
***************************************************************************** */function q(t,e,o,r){return new(o||(o=Promise))((function(n,a){function c(t){try{s(r.next(t))}catch(t){a(t)}}function i(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(c,i)}s((r=r.apply(t,e||[])).next())}))}function z(t,e){if(t===e)return null;let o=0,r=t.length,n=e.length;for(;o<r&&t.charCodeAt(o)===e.charCodeAt(o);)o+=1;for(;r>o&&n>o&&t.charCodeAt(r-1)===e.charCodeAt(n-1);)r-=1,n-=1;return{from:o,to:r,text:e.slice(o,n)}}const L=(t,o,r)=>{if(!t.hasFocus)return;const n=((t,o,r)=>{const n=("function"==typeof r&&r()||0)+1,a=o.state.selection.main.from+n,c=o.state.selection.main.to+n;return e.create(t,a,c)})(o.state.doc,t,r);n.eq(o.state.selection)||o.dispatch(o.state.tr.setSelection(n))},N=(e,o,r,n,a)=>{const c=r.state.selection.main,i=r.state.doc.lineAt(c.from),s=r.state.doc.lines;if(c.to!==c.from||i.number!==(o<0?1:s)||"char"===e&&c.from!==(o<0?0:i.to)||"function"!=typeof a)return!1;n.focus();const l=n.state.doc.nodeAt(a());if(!l)return!1;const m=a()+(o<0?0:l.nodeSize),d=t.near(n.state.doc.resolve(m),o);return n.dispatch(n.state.tr.setSelection(d).scrollIntoView()),n.focus(),!0},O=(t,e)=>{const{selection:o}=e.state;return!(!o.main.empty||0!==o.main.from)&&(C(t.state.schema.nodes.paragraph)(t.state,t.dispatch),setTimeout((()=>t.focus()),20),!0)},T=(t,e,o,r)=>q(void 0,void 0,void 0,(function*(){var n,a;const c=yield null===(a=null===(n=o.languageLoaders)||void 0===n?void 0:n[t])||void 0===a?void 0:a.call(n);c&&e.dispatch({effects:r.reconfigure(c)})})),B=e=>(o,r,n)=>{if(o.selection.empty&&(null==n?void 0:n.endOfTextblock(e))){const n="left"===e||"up"===e?-1:1,{$head:a}=o.selection,c=t.near(o.doc.resolve(n>0?a.after():a.before()),n);if(c.$head&&"code_block"===c.$head.parent.type.name)return null==r||r(o.tr.setSelection(c)),!0}return!1},D={ArrowLeft:B("left"),ArrowRight:B("right"),ArrowUp:B("up"),ArrowDown:B("down")},H=t=>(e,o,r)=>{let C=e,q=!1;const B=document.createElement("div");B.className="codeblock-root";const D=new A,H=M.create({extensions:[n(),a(),f(),S(),c(),p(),v(),b(),s({cursorBlinkRate:1e3}),M.allowMultipleSelections.of(!0),l(),j.fallback,D.of([]),g(),m.domEventHandlers({blur(t,e){e.dispatch({selection:{anchor:0}})}}),d.of([{key:"Mod-d",run:u,preventDefault:!0},{key:"ArrowUp",run:t=>N("line",-1,t,o,r)},{key:"ArrowLeft",run:t=>N("char",-1,t,o,r)},{key:"ArrowDown",run:t=>N("line",1,t,o,r)},{key:"ArrowRight",run:t=>N("char",1,t,o,r)},{key:"Mod-z",run:()=>{var e;return(null===(e=t.undo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0},shift:()=>{var e;return(null===(e=t.redo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0}},{key:"Mod-y",run:()=>{var e;return(null===(e=t.redo)||void 0===e?void 0:e.call(t,o.state,o.dispatch))||!0}},{key:"Backspace",run:t=>O(o,t)},{key:"Mod-Backspace",run:t=>O(o,t)},{key:"Mod-a",run:()=>{const t=E(o.state,o.dispatch);return o.focus(),t}},...w,...h,...i,...y,...x,k]),...t.theme?t.theme:[]],doc:C.textContent}),R=new m({state:H,dispatch:t=>{if(R.update([t]),!q){((t,e,o,r)=>{const n=z(e.textContent,t);if(n&&"function"==typeof o){const t=o()+1,e=r.state.tr.replaceWith(t+n.from,t+n.to,n.text?r.state.schema.text(n.text):null);r.dispatch(e)}})(t.state.toJSON().doc,C,r,o),L(R,o,r)}}});B.append(R.dom);const W=t.createSelect(t,B,C,o,r);return T(C.attrs.lang,R,t,D),{dom:B,selectNode(){R.focus()},stopEvent:()=>!0,setSelection:(t,e)=>{R.focus(),L(R,o,r),q=!0;const n="function"==typeof r?r():0;R.dispatch({selection:{anchor:t-n,head:e-n}}),q=!1},update:e=>{if(e.type.name!==C.type.name)return!1;e.attrs.lang!==C.attrs.lang&&T(e.attrs.lang,R,t,D);const n=C;C=e;const a=z(R.state.doc.toString(),C.textContent);return a&&(q=!0,R.dispatch({changes:{from:a.from,to:a.to,insert:a.text},selection:{anchor:a.from+a.text.length}}),q=!1),t.updateSelect(t,B,e,o,r,n),!0},ignoreMutation:()=>!0,destroy:()=>{W()}}};var R;!function(t){t.javascript="javascript",t.html="html",t.css="css",t.sql="sql",t.python="python",t.rust="rust",t.xml="xml",t.json="json",t.markdown="markdown",t.java="java",t.cpp="cpp",t.lezer="lezer",t.php="php",t.wast="wast"}(R||(R={}));const W={createSelect:(t,e,o,r,n)=>{var a;if(!t.languageLoaders)return()=>{};const{languageLoaders:c}=t,i=document.createElement("select");i.className="codeblock-select";const s=document.createElement("option");return s.value="none",s.textContent=(null===(a=t.languageNameMap)||void 0===a?void 0:a.none)||"none",i.append(s),Object.keys(c).sort().forEach((e=>{var o;if(t.languageWhitelist&&!t.languageWhitelist.includes(e))return;const r=document.createElement("option");r.value=e,r.textContent=(null===(o=t.languageNameMap)||void 0===o?void 0:o[e])||e,i.append(r)})),i.value=o.attrs.lang||"none",e.prepend(i),i.onchange=t=>q(void 0,void 0,void 0,(function*(){if(!(t.target instanceof HTMLSelectElement))return;const e=t.target.value;"function"==typeof n&&r.dispatch(r.state.tr.setNodeMarkup(n(),void 0,Object.assign(Object.assign({},o.attrs),{lang:e})))})),()=>{}},updateSelect:(t,e,o,r,n,a)=>{if(a.attrs.lang!==o.attrs.lang){const t=e.querySelector(".codeblock-select");if(!(t instanceof HTMLSelectElement))return;t.value=o.attrs.lang||"none"}}},$={[R.cpp]:()=>import("@codemirror/lang-cpp").then((t=>t.cpp())),[R.css]:()=>import("@codemirror/lang-css").then((t=>t.css())),[R.html]:()=>import("@codemirror/lang-html").then((t=>t.html())),[R.php]:()=>import("@codemirror/lang-php").then((t=>t.php())),[R.sql]:()=>import("@codemirror/lang-sql").then((t=>t.sql())),[R.xml]:()=>import("@codemirror/lang-xml").then((t=>t.xml())),[R.javascript]:()=>import("@codemirror/lang-javascript").then((t=>t.javascript())),[R.java]:()=>import("@codemirror/lang-java").then((t=>t.java())),[R.json]:()=>import("@codemirror/lang-json").then((t=>t.json())),[R.lezer]:()=>import("@codemirror/lang-lezer").then((t=>t.lezer())),[R.markdown]:()=>import("@codemirror/lang-markdown").then((t=>t.markdown())),[R.python]:()=>import("@codemirror/lang-python").then((t=>t.python())),[R.rust]:()=>import("@codemirror/lang-rust").then((t=>t.rust())),[R.wast]:()=>import("@codemirror/lang-wast").then((t=>t.wast()))},U=new o("codemirror-block"),V=t=>new r({key:U,props:{nodeViews:{code_block:H(t)}}});export{R as CodeBlockLanguages,D as codeBlockArrowHandlers,U as codeMirrorBlockKey,H as codeMirrorBlockNodeView,V as codeMirrorBlockPlugin,V as default,W as defaultSettings,$ as languageLoaders};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("prosemirror-state"),t=require("@codemirror/gutter"),r=require("@codemirror/closebrackets"),o=require("@codemirror/view"),n=require("@codemirror/search"),a=require("@codemirror/fold"),c=require("@codemirror/language"),s=require("@codemirror/autocomplete"),i=require("@codemirror/commands"),l=require("@codemirror/comment"),u=require("@codemirror/highlight"),d=require("@codemirror/rectangular-selection"),p=require("@codemirror/matchbrackets"),m=require("@codemirror/state"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("prosemirror-state"),t=require("@codemirror/gutter"),r=require("@codemirror/closebrackets"),o=require("@codemirror/view"),n=require("@codemirror/search"),a=require("@codemirror/fold"),c=require("@codemirror/language"),s=require("@codemirror/autocomplete"),i=require("@codemirror/commands"),l=require("@codemirror/comment"),u=require("@codemirror/highlight"),d=require("@codemirror/rectangular-selection"),p=require("@codemirror/matchbrackets"),m=require("@codemirror/state"),h=require("prosemirror-commands");function g(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function f(e,t,r,o){return new(r||(r=Promise))((function(n,a){function c(e){try{i(o.next(e))}catch(e){a(e)}}function s(e){try{i(o.throw(e))}catch(e){a(e)}}function i(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,s)}i((o=o.apply(e,t||[])).next())}))}function v(e,t){if(e===t)return null;let r=0,o=e.length,n=t.length;for(;r<o&&e.charCodeAt(r)===t.charCodeAt(r);)r+=1;for(;o>r&&n>r&&e.charCodeAt(o-1)===t.charCodeAt(n-1);)o-=1,n-=1;return{from:r,to:o,text:t.slice(r,n)}}const k=(t,r,o)=>{if(!t.hasFocus)return;const n=((t,r,o)=>{const n=("function"==typeof o&&o()||0)+1,a=r.state.selection.main.from+n,c=r.state.selection.main.to+n;return e.TextSelection.create(t,a,c)})(r.state.doc,t,o);n.eq(r.state.selection)||r.dispatch(r.state.tr.setSelection(n))},y=(t,r,o,n,a)=>{const c=o.state.selection.main,s=o.state.doc.lineAt(c.from),i=o.state.doc.lines;if(c.to!==c.from||s.number!==(r<0?1:i)||"char"===t&&c.from!==(r<0?0:s.to)||"function"!=typeof a)return!1;n.focus();const l=n.state.doc.nodeAt(a());if(!l)return!1;const u=a()+(r<0?0:l.nodeSize),d=e.Selection.near(n.state.doc.resolve(u),r);return n.dispatch(n.state.tr.setSelection(d).scrollIntoView()),n.focus(),!0},x=(e,t)=>{const{selection:r}=t.state;return!(!r.main.empty||0!==r.main.from)&&(
|
|
15
|
+
***************************************************************************** */function f(e,t,r,o){return new(r||(r=Promise))((function(n,a){function c(e){try{i(o.next(e))}catch(e){a(e)}}function s(e){try{i(o.throw(e))}catch(e){a(e)}}function i(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(c,s)}i((o=o.apply(e,t||[])).next())}))}function v(e,t){if(e===t)return null;let r=0,o=e.length,n=t.length;for(;r<o&&e.charCodeAt(r)===t.charCodeAt(r);)r+=1;for(;o>r&&n>r&&e.charCodeAt(o-1)===t.charCodeAt(n-1);)o-=1,n-=1;return{from:r,to:o,text:t.slice(r,n)}}const k=(t,r,o)=>{if(!t.hasFocus)return;const n=((t,r,o)=>{const n=("function"==typeof o&&o()||0)+1,a=r.state.selection.main.from+n,c=r.state.selection.main.to+n;return e.TextSelection.create(t,a,c)})(r.state.doc,t,o);n.eq(r.state.selection)||r.dispatch(r.state.tr.setSelection(n))},y=(t,r,o,n,a)=>{const c=o.state.selection.main,s=o.state.doc.lineAt(c.from),i=o.state.doc.lines;if(c.to!==c.from||s.number!==(r<0?1:i)||"char"===t&&c.from!==(r<0?0:s.to)||"function"!=typeof a)return!1;n.focus();const l=n.state.doc.nodeAt(a());if(!l)return!1;const u=a()+(r<0?0:l.nodeSize),d=e.Selection.near(n.state.doc.resolve(u),r);return n.dispatch(n.state.tr.setSelection(d).scrollIntoView()),n.focus(),!0},x=(e,t)=>{const{selection:r}=t.state;return!(!r.main.empty||0!==r.main.from)&&(h.setBlockType(e.state.schema.nodes.paragraph)(e.state,e.dispatch),setTimeout((()=>e.focus()),20),!0)},w=(e,t,r,o)=>f(void 0,void 0,void 0,(function*(){var n,a;const c=yield null===(a=null===(n=r.languageLoaders)||void 0===n?void 0:n[e])||void 0===a?void 0:a.call(n);c&&t.dispatch({effects:o.reconfigure(c)})})),q=t=>(r,o,n)=>{if(r.selection.empty&&(null==n?void 0:n.endOfTextblock(t))){const n="left"===t||"up"===t?-1:1,{$head:a}=r.selection,c=e.Selection.near(r.doc.resolve(n>0?a.after():a.before()),n);if(c.$head&&"code_block"===c.$head.parent.type.name)return null==o||o(r.tr.setSelection(c)),!0}return!1},B={ArrowLeft:q("left"),ArrowRight:q("right"),ArrowUp:q("up"),ArrowDown:q("down")},C=e=>(g,f,q)=>{let B=g,C=!1;const L=document.createElement("div");L.className="codeblock-root";const b=new m.Compartment,S=m.EditorState.create({extensions:[t.lineNumbers(),t.highlightActiveLineGutter(),a.foldGutter(),p.bracketMatching(),r.closeBrackets(),n.highlightSelectionMatches(),s.autocompletion(),d.rectangularSelection(),o.drawSelection({cursorBlinkRate:1e3}),m.EditorState.allowMultipleSelections.of(!0),o.highlightActiveLine(),u.defaultHighlightStyle.fallback,b.of([]),c.indentOnInput(),o.EditorView.domEventHandlers({blur(e,t){t.dispatch({selection:{anchor:0}})}}),o.keymap.of([{key:"Mod-d",run:n.selectNextOccurrence,preventDefault:!0},{key:"ArrowUp",run:e=>y("line",-1,e,f,q)},{key:"ArrowLeft",run:e=>y("char",-1,e,f,q)},{key:"ArrowDown",run:e=>y("line",1,e,f,q)},{key:"ArrowRight",run:e=>y("char",1,e,f,q)},{key:"Mod-z",run:()=>{var t;return(null===(t=e.undo)||void 0===t?void 0:t.call(e,f.state,f.dispatch))||!0},shift:()=>{var t;return(null===(t=e.redo)||void 0===t?void 0:t.call(e,f.state,f.dispatch))||!0}},{key:"Mod-y",run:()=>{var t;return(null===(t=e.redo)||void 0===t?void 0:t.call(e,f.state,f.dispatch))||!0}},{key:"Backspace",run:e=>x(f,e)},{key:"Mod-Backspace",run:e=>x(f,e)},{key:"Mod-a",run:()=>{const e=h.selectAll(f.state,f.dispatch);return f.focus(),e}},...i.defaultKeymap,...a.foldKeymap,...r.closeBracketsKeymap,...s.completionKeymap,...l.commentKeymap,i.indentWithTab]),...e.theme?e.theme:[]],doc:B.textContent}),j=new o.EditorView({state:S,dispatch:e=>{if(j.update([e]),!C){((e,t,r,o)=>{const n=v(t.textContent,e);if(n&&"function"==typeof r){const e=r()+1,t=o.state.tr.replaceWith(e+n.from,e+n.to,n.text?o.state.schema.text(n.text):null);o.dispatch(t)}})(e.state.toJSON().doc,B,q,f),k(j,f,q)}}});L.append(j.dom);const P=e.createSelect(e,L,B,f,q);return w(B.attrs.lang,j,e,b),{dom:L,selectNode(){j.focus()},stopEvent:()=>!0,setSelection:(e,t)=>{j.focus(),k(j,f,q),C=!0;const r="function"==typeof q?q():0;j.dispatch({selection:{anchor:e-r,head:t-r}}),C=!1},update:t=>{if(t.type.name!==B.type.name)return!1;t.attrs.lang!==B.attrs.lang&&w(t.attrs.lang,j,e,b);const r=B;B=t;const o=v(j.state.doc.toString(),B.textContent);return o&&(C=!0,j.dispatch({changes:{from:o.from,to:o.to,insert:o.text},selection:{anchor:o.from+o.text.length}}),C=!1),e.updateSelect(e,L,t,f,q,r),!0},ignoreMutation:()=>!0,destroy:()=>{P()}}};var L;exports.CodeBlockLanguages=void 0,(L=exports.CodeBlockLanguages||(exports.CodeBlockLanguages={})).javascript="javascript",L.html="html",L.css="css",L.sql="sql",L.python="python",L.rust="rust",L.xml="xml",L.json="json",L.markdown="markdown",L.java="java",L.cpp="cpp",L.lezer="lezer",L.php="php",L.wast="wast";const b={createSelect:(e,t,r,o,n)=>{var a;if(!e.languageLoaders)return()=>{};const{languageLoaders:c}=e,s=document.createElement("select");s.className="codeblock-select";const i=document.createElement("option");return i.value="none",i.textContent=(null===(a=e.languageNameMap)||void 0===a?void 0:a.none)||"none",s.append(i),Object.keys(c).sort().forEach((t=>{var r;if(e.languageWhitelist&&!e.languageWhitelist.includes(t))return;const o=document.createElement("option");o.value=t,o.textContent=(null===(r=e.languageNameMap)||void 0===r?void 0:r[t])||t,s.append(o)})),s.value=r.attrs.lang||"none",t.prepend(s),s.onchange=e=>f(void 0,void 0,void 0,(function*(){if(!(e.target instanceof HTMLSelectElement))return;const t=e.target.value;"function"==typeof n&&o.dispatch(o.state.tr.setNodeMarkup(n(),void 0,Object.assign(Object.assign({},r.attrs),{lang:t})))})),()=>{}},updateSelect:(e,t,r,o,n,a)=>{if(a.attrs.lang!==r.attrs.lang){const e=t.querySelector(".codeblock-select");if(!(e instanceof HTMLSelectElement))return;e.value=r.attrs.lang||"none"}}},S={[exports.CodeBlockLanguages.cpp]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-cpp"))})).then((e=>e.cpp())),[exports.CodeBlockLanguages.css]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-css"))})).then((e=>e.css())),[exports.CodeBlockLanguages.html]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-html"))})).then((e=>e.html())),[exports.CodeBlockLanguages.php]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-php"))})).then((e=>e.php())),[exports.CodeBlockLanguages.sql]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-sql"))})).then((e=>e.sql())),[exports.CodeBlockLanguages.xml]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-xml"))})).then((e=>e.xml())),[exports.CodeBlockLanguages.javascript]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-javascript"))})).then((e=>e.javascript())),[exports.CodeBlockLanguages.java]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-java"))})).then((e=>e.java())),[exports.CodeBlockLanguages.json]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-json"))})).then((e=>e.json())),[exports.CodeBlockLanguages.lezer]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-lezer"))})).then((e=>e.lezer())),[exports.CodeBlockLanguages.markdown]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-markdown"))})).then((e=>e.markdown())),[exports.CodeBlockLanguages.python]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-python"))})).then((e=>e.python())),[exports.CodeBlockLanguages.rust]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-rust"))})).then((e=>e.rust())),[exports.CodeBlockLanguages.wast]:()=>Promise.resolve().then((function(){return g(require("@codemirror/lang-wast"))})).then((e=>e.wast()))},j=new e.PluginKey("codemirror-block"),P=t=>new e.Plugin({key:j,props:{nodeViews:{code_block:C(t)}}});exports.codeBlockArrowHandlers=B,exports.codeMirrorBlockKey=j,exports.codeMirrorBlockNodeView=C,exports.codeMirrorBlockPlugin=P,exports.default=P,exports.defaultSettings=b,exports.languageLoaders=S;
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Node } from "prosemirror-model";
|
|
|
3
3
|
import { EditorView } from "prosemirror-view";
|
|
4
4
|
import { LanguageSupport } from "@codemirror/language";
|
|
5
5
|
export declare type LanguageLoaders = Record<string, () => Promise<LanguageSupport>>;
|
|
6
|
+
import { Extension } from "@codemirror/state";
|
|
6
7
|
export declare type CodeBlockSettings = {
|
|
7
8
|
createSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean) => () => void;
|
|
8
9
|
updateSelect: (settings: CodeBlockSettings, dom: HTMLElement, node: Node, view: EditorView, getPos: (() => number) | boolean, oldNode: Node) => void;
|
|
@@ -11,4 +12,5 @@ export declare type CodeBlockSettings = {
|
|
|
11
12
|
languageWhitelist?: string[];
|
|
12
13
|
undo?: (state: EditorState, dispatch: (tr: Transaction) => void) => void;
|
|
13
14
|
redo?: (state: EditorState, dispatch: (tr: Transaction) => void) => void;
|
|
15
|
+
theme?: Extension[];
|
|
14
16
|
};
|