@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
3 lines (2 loc) • 5.03 kB
JavaScript
;var C=Object.defineProperty;var O=(t,e,n)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var a=(t,e,n)=>O(t,typeof e!="symbol"?e+"":e,n);const l=require("./defaultBlocks-D1cc0lV9.cjs");function w(t){const e=D(t);let{roots:n,nonRoots:r}=f(e);const s=[];for(;n.size;){s.push(n);const o=new Set;for(const c of n){const i=t.get(c);if(i)for(const p of i){const m=e.get(p);if(m===void 0)continue;const S=m-1;e.set(p,S),S===0&&o.add(p)}}n=o}if(r=f(e).nonRoots,r.size)throw new Error(`Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(r).join(", ")}`);return s}function j(t){const e=x(t);return w(e)}function D(t){const e=new Map;for(const[n,r]of t.entries()){e.has(n)||e.set(n,0);for(const s of r){const o=e.get(s)??0;e.set(s,o+1)}}return e}function f(t){const e=new Set,n=new Set;for(const[r,s]of t.entries())s===0?e.add(r):n.add(r);return{roots:e,nonRoots:n}}function x(t){const e=new Map;for(const[n,r]of t.entries()){e.has(n)||e.set(n,new Set);for(const s of r)e.has(s)||e.set(s,new Set),e.get(s).add(n)}return e}function E(){return new Map}function h(t,e,n){return t.has(e)||t.set(e,new Set),t.get(e).add(n),t}function k(t){const e=E();for(const s of t)Array.isArray(s.runsBefore)&&s.runsBefore.length>0?s.runsBefore.forEach(o=>{h(e,s.key,o)}):h(e,"default",s.key);const n=j(e),r=n.findIndex(s=>s.has("default"));return s=>91+(n.findIndex(c=>c.has(s))+r)*10}function u(t){return t&&Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}class g{constructor(e){a(this,"BlockNoteEditor","only for types");a(this,"Block","only for types");a(this,"PartialBlock","only for types");a(this,"inlineContentSpecs");a(this,"styleSpecs");a(this,"blockSpecs");a(this,"blockSchema");a(this,"inlineContentSchema");a(this,"styleSchema");this.opts=e;const{blockSpecs:n,inlineContentSpecs:r,styleSpecs:s,blockSchema:o,inlineContentSchema:c,styleSchema:i}=this.init();this.blockSpecs=n,this.styleSpecs=s,this.styleSchema=i,this.inlineContentSpecs=r,this.blockSchema=o,this.inlineContentSchema=c}init(){const e=k(Object.entries({...this.opts.blockSpecs,...this.opts.inlineContentSpecs,...this.opts.styleSpecs}).map(([o,c])=>{var i;return{key:o,runsBefore:((i=c.implementation)==null?void 0:i.runsBefore)??[]}})),n=Object.fromEntries(Object.entries(this.opts.blockSpecs).map(([o,c])=>[o,l.addNodeAndExtensionsToSpec(c.config,c.implementation,c.extensions,e(o))])),r=Object.fromEntries(Object.entries(this.opts.inlineContentSpecs).map(([o,c])=>{var i;return typeof c.config!="object"?[o,c]:[o,{...c,implementation:{...c.implementation,node:(i=c.implementation)==null?void 0:i.node.extend({priority:e(o)})}}]})),s=Object.fromEntries(Object.entries(this.opts.styleSpecs).map(([o,c])=>{var i;return[o,{...c,implementation:{...c.implementation,mark:(i=c.implementation)==null?void 0:i.mark.extend({priority:e(o)})}}]}));return{blockSpecs:n,blockSchema:Object.fromEntries(Object.entries(n).map(([o,c])=>[o,c.config])),inlineContentSpecs:u(r),styleSpecs:u(s),inlineContentSchema:l.getInlineContentSchemaFromSpecs(r),styleSchema:l.getStyleSchemaFromSpecs(s)}}extend(e){Object.assign(this.opts.blockSpecs,e.blockSpecs),Object.assign(this.opts.inlineContentSpecs,e.inlineContentSpecs),Object.assign(this.opts.styleSpecs,e.styleSpecs);const{blockSpecs:n,inlineContentSpecs:r,styleSpecs:s,blockSchema:o,inlineContentSchema:c,styleSchema:i}=this.init();return this.blockSpecs=n,this.styleSpecs=s,this.styleSchema=i,this.inlineContentSpecs=r,this.blockSchema=o,this.inlineContentSchema=c,this}}const y=l.createBlockConfig(()=>({type:"pageBreak",propSchema:{},content:"none"})),b=l.createBlockSpec(y,{parse(t){if(t.tagName==="DIV"&&t.hasAttribute("data-page-break"))return{}},render(){const t=document.createElement("div");return t.setAttribute("data-page-break",""),{dom:t}},toExternalHTML(){const t=document.createElement("div");return t.setAttribute("data-page-break",""),{dom:t}}}),P=t=>t.extend({blockSpecs:{pageBreak:b()}}),I=async t=>{const e=new FormData;return e.append("file",t),(await(await fetch("https://tmpfiles.org/api/v1/upload",{method:"POST",body:e})).json()).data.url.replace("tmpfiles.org/","tmpfiles.org/dl/")};function B(t){return"pageBreak"in t.schema.blockSchema}function v(t){const e=[];return B(t)&&e.push({...t.dictionary.slash_menu.page_break,onItemClick:()=>{l.insertOrUpdateBlockForSlashMenu(t,{type:"pageBreak"})},key:"page_break"}),e}class d extends g{static create(e){return new d({blockSpecs:(e==null?void 0:e.blockSpecs)??l.defaultBlockSpecs,inlineContentSpecs:(e==null?void 0:e.inlineContentSpecs)??l.defaultInlineContentSpecs,styleSpecs:(e==null?void 0:e.styleSpecs)??l.defaultStyleSpecs})}}exports.BlockNoteSchema=d;exports.CustomBlockNoteSchema=g;exports.checkPageBreakBlocksInSchema=B;exports.createPageBreakBlockConfig=y;exports.createPageBreakBlockSpec=b;exports.getPageBreakSlashMenuItems=v;exports.sortByDependencies=k;exports.uploadToTmpFilesDotOrg_DEV_ONLY=I;exports.withPageBreak=P;
//# sourceMappingURL=BlockNoteSchema-CzZbr4Ed.cjs.map