@blocknote/server-util
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
3 lines (2 loc) • 2.93 kB
JavaScript
"use strict";var d=Object.defineProperty;var u=(t,e,o)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var n=(t,e,o)=>u(t,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@blocknote/core"),s=require("@blocknote/core/yjs"),m=require("@blocknote/react"),h=require("jsdom"),a=require("react"),T=require("react-dom"),w=require("react-dom/client");function y(t){if(t&&typeof t=="object"&&"default"in t)return t;const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,r.get?r:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const k=y(h);class c{constructor(e){n(this,"editor");n(this,"jsdom",new k.JSDOM);this.editor=i.BlockNoteEditor.create(e)}async _withJSDOM(e){const o=globalThis.window,r=globalThis.document;globalThis.document=this.jsdom.window.document,globalThis.window=this.jsdom.window,globalThis.window.__TEST_OPTIONS=o==null?void 0:o.__TEST_OPTIONS;try{return await e()}finally{globalThis.document=r,globalThis.window=o}}static create(e={}){return new c(e)}_prosemirrorNodeToBlocks(e){return i.docToBlocks(e)}_prosemirrorJSONToBlocks(e){return s._prosemirrorJSONToBlocks(this.editor,e)}_blocksToProsemirrorNode(e){return s._blocksToProsemirrorNode(this.editor,e)}yXmlFragmentToBlocks(e){return s.yXmlFragmentToBlocks(this.editor,e)}blocksToYXmlFragment(e,o){return s.blocksToYXmlFragment(this.editor,e,o)}yDocToBlocks(e,o="prosemirror"){return s.yDocToBlocks(this.editor,e,o)}blocksToYDoc(e,o="prosemirror"){return s.blocksToYDoc(this.editor,e,o)}async blocksToHTMLLossy(e){return this._withJSDOM(async()=>i.createExternalHTMLExporter(this.editor.pmSchema,this.editor).exportBlocks(e,{document:this.jsdom.window.document}))}async blocksToFullHTML(e){return this._withJSDOM(async()=>i.createInternalHTMLSerializer(this.editor.pmSchema,this.editor).serializeBlocks(e,{document:this.jsdom.window.document}))}async tryParseHTMLToBlocks(e){return this._withJSDOM(async()=>this.editor.tryParseHTMLToBlocks(e))}async blocksToMarkdownLossy(e){return this._withJSDOM(async()=>i.blocksToMarkdown(e,this.editor.pmSchema,this.editor,{document:this.jsdom.window.document}))}async tryParseMarkdownToBlocks(e){return this._withJSDOM(async()=>this.editor.tryParseMarkdownToBlocks(e))}async withReactContext(e,o){return this._withJSDOM(async()=>{const r=w.createRoot(this.jsdom.window.document.createElement("div"));T.flushSync(()=>{r.render(a.createElement(e,{},a.createElement(m.BlockNoteViewRaw,{editor:this.editor,formattingToolbar:!1,linkToolbar:!1,slashMenu:!1,emojiPicker:!1,sideMenu:!1,filePanel:!1,tableHandles:!1,comments:!1})))});try{return await o()}finally{r.unmount(),await new Promise(l=>setTimeout(l,3))}})}}exports.ServerBlockNoteEditor=c;
//# sourceMappingURL=blocknote-server-util.cjs.map