@blocknote/core 0.43.0 → 0.44.0
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/{BlockNoteSchema-D8TyvlfU.cjs → BlockNoteSchema-B4gm-Qco.cjs} +2 -2
- package/dist/{BlockNoteSchema-D8TyvlfU.cjs.map → BlockNoteSchema-B4gm-Qco.cjs.map} +1 -1
- package/dist/{BlockNoteSchema-CbSavEwr.js → BlockNoteSchema-C-l154WP.js} +2 -2
- package/dist/{BlockNoteSchema-CbSavEwr.js.map → BlockNoteSchema-C-l154WP.js.map} +1 -1
- package/dist/{TrailingNode-BUhuMJrB.js → TrailingNode-B_zPMWxw.js} +235 -233
- package/dist/{TrailingNode-BUhuMJrB.js.map → TrailingNode-B_zPMWxw.js.map} +1 -1
- package/dist/TrailingNode-CRHrgOnK.cjs +2 -0
- package/dist/{TrailingNode-CaT_wbho.cjs.map → TrailingNode-CRHrgOnK.cjs.map} +1 -1
- package/dist/blocknote.cjs +4 -4
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +508 -506
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/defaultBlocks-DLJ4Q1_J.cjs +6 -0
- package/dist/{defaultBlocks-BxFclIGP.cjs.map → defaultBlocks-DLJ4Q1_J.cjs.map} +1 -1
- package/dist/{defaultBlocks-BJtxTOM2.js → defaultBlocks-DgA_mtQV.js} +463 -460
- package/dist/{defaultBlocks-BJtxTOM2.js.map → defaultBlocks-DgA_mtQV.js.map} +1 -1
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +3 -3
- package/dist/webpack-stats.json +1 -1
- package/package.json +1 -1
- package/dist/TrailingNode-CaT_wbho.cjs +0 -2
- package/dist/defaultBlocks-BxFclIGP.cjs +0 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";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-
|
|
2
|
-
//# sourceMappingURL=BlockNoteSchema-
|
|
1
|
+
"use strict";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-DLJ4Q1_J.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;
|
|
2
|
+
//# sourceMappingURL=BlockNoteSchema-B4gm-Qco.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNoteSchema-D8TyvlfU.cjs","sources":["../src/util/topo-sort.ts","../src/schema/schema.ts","../src/blocks/PageBreak/block.ts","../src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts","../src/blocks/PageBreak/getPageBreakSlashMenuItems.ts","../src/blocks/BlockNoteSchema.ts"],"sourcesContent":["/**\n * Instead of depending on the NPM package, we vendor this file from https://github.com/n1ru4l/toposort/blob/main/src/toposort.ts (MIT)\n *\n * There was a recent publish, despite not having been updated in 2 years, which is suspicious.\n *\n * This file is also simple enough that we can maintain it ourselves.\n */\n\nexport type DirectedAcyclicGraph = Map<string, Iterable<string>>;\nexport type DependencyGraph = DirectedAcyclicGraph;\n\nexport type TaskList = Array<Set<string>>;\n\n// Add more specific types for better type safety\nexport type NodeId = string;\nexport type DependencyMap = Map<NodeId, Set<NodeId>>;\n\nexport function toposort(dag: DirectedAcyclicGraph): TaskList {\n const inDegrees = countInDegrees(dag);\n\n let { roots, nonRoots } = getRootsAndNonRoots(inDegrees);\n\n const sorted: TaskList = [];\n\n while (roots.size) {\n sorted.push(roots);\n\n const newRoots = new Set<NodeId>();\n for (const root of roots) {\n const dependents = dag.get(root);\n if (!dependents) {\n // Handle case where node has no dependents\n continue;\n }\n\n for (const dependent of dependents) {\n const currentDegree = inDegrees.get(dependent);\n if (currentDegree === undefined) {\n // Handle case where dependent node is not in inDegrees\n continue;\n }\n\n const newDegree = currentDegree - 1;\n inDegrees.set(dependent, newDegree);\n\n if (newDegree === 0) {\n newRoots.add(dependent);\n }\n }\n }\n\n roots = newRoots;\n }\n nonRoots = getRootsAndNonRoots(inDegrees).nonRoots;\n\n if (nonRoots.size) {\n throw new Error(\n `Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(nonRoots).join(\", \")}`,\n );\n }\n\n return sorted;\n}\n\nexport function toposortReverse(deps: DependencyGraph): TaskList {\n const dag = reverse(deps);\n return toposort(dag);\n}\n\ntype InDegrees = Map<NodeId, number>;\n\nfunction countInDegrees(dag: DirectedAcyclicGraph): InDegrees {\n const counts: InDegrees = new Map();\n\n for (const [vx, dependents] of dag.entries()) {\n // Initialize count for current node if not present\n if (!counts.has(vx)) {\n counts.set(vx, 0);\n }\n\n for (const dependent of dependents) {\n const currentCount = counts.get(dependent) ?? 0;\n counts.set(dependent, currentCount + 1);\n }\n }\n\n return counts;\n}\n\nfunction getRootsAndNonRoots(counts: InDegrees) {\n const roots = new Set<NodeId>();\n const nonRoots = new Set<NodeId>();\n\n for (const [id, deg] of counts.entries()) {\n if (deg === 0) {\n roots.add(id);\n } else {\n nonRoots.add(id);\n }\n }\n\n return { roots, nonRoots };\n}\n\nfunction reverse(deps: DirectedAcyclicGraph): DependencyGraph {\n const reversedDeps: DependencyMap = new Map();\n\n for (const [name, dependsOn] of deps.entries()) {\n // Ensure the source node exists in the reversed map\n if (!reversedDeps.has(name)) {\n reversedDeps.set(name, new Set());\n }\n\n for (const dependsOnName of dependsOn) {\n if (!reversedDeps.has(dependsOnName)) {\n reversedDeps.set(dependsOnName, new Set());\n }\n reversedDeps.get(dependsOnName)!.add(name);\n }\n }\n\n return reversedDeps;\n}\n\nexport function createDependencyGraph(): DependencyMap {\n return new Map();\n}\n\nexport function addDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): DependencyMap {\n if (!graph.has(from)) {\n graph.set(from, new Set());\n }\n graph.get(from)!.add(to);\n return graph;\n}\n\nexport function removeDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n if (!dependents) {\n return false;\n }\n return dependents.delete(to);\n}\n\nexport function hasDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n return dependents ? dependents.has(to) : false;\n}\n\n/**\n * Sorts a list of items by their dependencies\n * @returns A function which can retrieve the priority of an item\n */\nexport function sortByDependencies(\n items: { key: string; runsBefore?: ReadonlyArray<string> }[],\n) {\n const dag = createDependencyGraph();\n\n for (const item of items) {\n if (Array.isArray(item.runsBefore) && item.runsBefore.length > 0) {\n item.runsBefore.forEach((runBefore) => {\n addDependency(dag, item.key, runBefore);\n });\n } else {\n addDependency(dag, \"default\", item.key);\n }\n }\n const sortedSpecs = toposortReverse(dag);\n const defaultIndex = sortedSpecs.findIndex((set) => set.has(\"default\"));\n\n /**\n * The priority of an item is described relative to the \"default\" (an arbitrary string which can be used as the reference)\n *\n * Since items are topologically sorted, we can see what their relative position is to the \"default\"\n * Each layer away from the default is 10 priority points (arbitrarily chosen)\n * The default is fixed at 101 (1 point higher than any tiptap extension, giving priority to custom blocks than any defaults)\n *\n * This is a bit of a hack, but it's a simple way to ensure that custom items are always rendered with higher priority than default items\n * and that custom items are rendered in the order they are defined in the list\n */\n\n /**\n * Retrieves the priority of an item based on its position in the topologically sorted list\n * @param key - The key of the item to get the priority of\n * @returns The priority of the item\n */\n return (key: string) => {\n const index = sortedSpecs.findIndex((set) => set.has(key));\n // the default index should map to 101\n // one before the default index is 91\n // one after is 111\n return 91 + (index + defaultIndex) * 10;\n };\n}\n","import { BlockNoteEditor } from \"../editor/BlockNoteEditor.js\";\nimport { sortByDependencies } from \"../util/topo-sort.js\";\nimport {\n BlockNoDefaults,\n BlockSchema,\n BlockSpecs,\n InlineContentConfig,\n InlineContentSchema,\n InlineContentSpec,\n InlineContentSpecs,\n LooseBlockSpec,\n PartialBlockNoDefaults,\n StyleSchema,\n StyleSpecs,\n addNodeAndExtensionsToSpec,\n getInlineContentSchemaFromSpecs,\n getStyleSchemaFromSpecs,\n} from \"./index.js\";\n\nfunction removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {\n if (!obj) {\n return obj;\n }\n return Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as T;\n}\n\nexport class CustomBlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> {\n // Helper so that you can use typeof schema.BlockNoteEditor\n public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly PartialBlock: PartialBlockNoDefaults<\n BSchema,\n ISchema,\n SSchema\n > = \"only for types\" as any;\n\n public inlineContentSpecs: InlineContentSpecs;\n public styleSpecs: StyleSpecs;\n public blockSpecs: {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n public blockSchema: BSchema;\n public inlineContentSchema: ISchema;\n public styleSchema: SSchema;\n\n constructor(\n private opts: {\n blockSpecs: BlockSpecs;\n inlineContentSpecs: InlineContentSpecs;\n styleSpecs: StyleSpecs;\n },\n ) {\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n }\n\n private init() {\n const getPriority = sortByDependencies(\n Object.entries({\n ...this.opts.blockSpecs,\n ...this.opts.inlineContentSpecs,\n ...this.opts.styleSpecs,\n }).map(([key, val]) => ({\n key: key,\n runsBefore: val.implementation?.runsBefore ?? [],\n })),\n );\n\n const blockSpecs = Object.fromEntries(\n Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {\n return [\n key,\n addNodeAndExtensionsToSpec(\n blockSpec.config,\n blockSpec.implementation,\n blockSpec.extensions,\n getPriority(key),\n ),\n ];\n }),\n ) as {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n const inlineContentSpecs = Object.fromEntries(\n Object.entries(this.opts.inlineContentSpecs).map(\n ([key, inlineContentSpec]) => {\n // Case for text and links.\n if (typeof inlineContentSpec.config !== \"object\") {\n return [key, inlineContentSpec];\n }\n\n return [\n key,\n {\n ...inlineContentSpec,\n implementation: {\n ...inlineContentSpec.implementation,\n node: inlineContentSpec.implementation?.node.extend({\n priority: getPriority(key),\n }),\n },\n },\n ];\n },\n ),\n ) as InlineContentSpecs;\n\n const styleSpecs = Object.fromEntries(\n Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [\n key,\n {\n ...styleSpec,\n implementation: {\n ...styleSpec.implementation,\n mark: styleSpec.implementation?.mark.extend({\n priority: getPriority(key),\n }),\n },\n },\n ]),\n ) as StyleSpecs;\n\n return {\n blockSpecs,\n blockSchema: Object.fromEntries(\n Object.entries(blockSpecs).map(([key, blockDef]) => {\n return [key, blockDef.config];\n }),\n ) as any,\n inlineContentSpecs: removeUndefined(inlineContentSpecs),\n styleSpecs: removeUndefined(styleSpecs),\n inlineContentSchema: getInlineContentSchemaFromSpecs(\n inlineContentSpecs,\n ) as any,\n styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,\n };\n }\n\n /**\n * Adds additional block specs to the current schema in a builder pattern.\n * This method allows extending the schema after it has been created.\n *\n * @param additionalBlockSpecs - Additional block specs to add to the schema\n * @returns The current schema instance for chaining\n */\n public extend<\n AdditionalBlockSpecs extends BlockSpecs = Record<string, never>,\n AdditionalInlineContentSpecs extends Record<\n string,\n InlineContentSpec<InlineContentConfig>\n > = Record<string, never>,\n AdditionalStyleSpecs extends StyleSpecs = Record<string, never>,\n >(opts: {\n blockSpecs?: AdditionalBlockSpecs;\n inlineContentSpecs?: AdditionalInlineContentSpecs;\n styleSpecs?: AdditionalStyleSpecs;\n }): CustomBlockNoteSchema<\n AdditionalBlockSpecs extends undefined | Record<string, never>\n ? BSchema\n : BSchema & {\n [K in keyof AdditionalBlockSpecs]: K extends string\n ? AdditionalBlockSpecs[K][\"config\"]\n : never;\n },\n AdditionalInlineContentSpecs extends undefined | Record<string, never>\n ? ISchema\n : ISchema & {\n [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K][\"config\"];\n },\n AdditionalStyleSpecs extends undefined | Record<string, never>\n ? SSchema\n : SSchema & {\n [K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K][\"config\"];\n }\n > {\n // Merge the new specs with existing ones\n Object.assign(this.opts.blockSpecs, opts.blockSpecs);\n Object.assign(this.opts.inlineContentSpecs, opts.inlineContentSpecs);\n Object.assign(this.opts.styleSpecs, opts.styleSpecs);\n\n // Reinitialize the block specs with the merged specs\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n\n return this as any;\n }\n}\n","import {\n BlockSchema,\n createBlockConfig,\n createBlockSpec,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { BlockNoteSchema } from \"../BlockNoteSchema.js\";\n\nexport type PageBreakBlockConfig = ReturnType<\n typeof createPageBreakBlockConfig\n>;\n\nexport const createPageBreakBlockConfig = createBlockConfig(\n () =>\n ({\n type: \"pageBreak\" as const,\n propSchema: {},\n content: \"none\",\n }) as const,\n);\n\nexport const createPageBreakBlockSpec = createBlockSpec(\n createPageBreakBlockConfig,\n {\n parse(element) {\n if (\n element.tagName === \"DIV\" &&\n element.hasAttribute(\"data-page-break\")\n ) {\n return {};\n }\n\n return undefined;\n },\n render() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n toExternalHTML() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n },\n);\n\n/**\n * Adds page break support to the given schema.\n */\nexport const withPageBreak = <\n B extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n schema: BlockNoteSchema<B, I, S>,\n) => {\n return schema.extend({\n blockSpecs: {\n pageBreak: createPageBreakBlockSpec(),\n },\n });\n};\n","/**\n * Uploads a file to tmpfiles.org and returns the URL to the uploaded file.\n *\n * @warning This function should only be used for development purposes, replace with your own backend!\n */\nexport const uploadToTmpFilesDotOrg_DEV_ONLY = async (\n file: File,\n): Promise<string> => {\n const body = new FormData();\n body.append(\"file\", file);\n\n const ret = await fetch(\"https://tmpfiles.org/api/v1/upload\", {\n method: \"POST\",\n body: body,\n });\n return (await ret.json()).data.url.replace(\n \"tmpfiles.org/\",\n \"tmpfiles.org/dl/\",\n );\n};\n","import { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\nimport { DefaultSuggestionItem } from \"../../extensions/SuggestionMenu/DefaultSuggestionItem.js\";\nimport { insertOrUpdateBlockForSlashMenu } from \"../../extensions/SuggestionMenu/getDefaultSlashMenuItems.js\";\nimport {\n BlockSchema,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { createPageBreakBlockConfig } from \"./block.js\";\n\nexport function checkPageBreakBlocksInSchema<\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n editor: BlockNoteEditor<any, I, S>,\n): editor is BlockNoteEditor<\n {\n pageBreak: ReturnType<typeof createPageBreakBlockConfig>;\n },\n I,\n S\n> {\n return \"pageBreak\" in editor.schema.blockSchema;\n}\n\nexport function getPageBreakSlashMenuItems<\n BSchema extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, I, S>) {\n const items: (Omit<DefaultSuggestionItem, \"key\"> & { key: \"page_break\" })[] =\n [];\n\n if (checkPageBreakBlocksInSchema(editor)) {\n items.push({\n ...editor.dictionary.slash_menu.page_break,\n onItemClick: () => {\n insertOrUpdateBlockForSlashMenu(editor, {\n type: \"pageBreak\",\n });\n },\n key: \"page_break\",\n });\n }\n\n return items;\n}\n","import {\n BlockSchema,\n BlockSchemaFromSpecs,\n BlockSpecs,\n CustomBlockNoteSchema,\n InlineContentSchema,\n InlineContentSchemaFromSpecs,\n InlineContentSpecs,\n StyleSchema,\n StyleSchemaFromSpecs,\n StyleSpecs,\n} from \"../schema/index.js\";\nimport {\n defaultBlockSpecs,\n defaultInlineContentSpecs,\n defaultStyleSpecs,\n} from \"./defaultBlocks.js\";\n\nexport class BlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> extends CustomBlockNoteSchema<BSchema, ISchema, SSchema> {\n public static create<\n BSpecs extends BlockSpecs | undefined = undefined,\n ISpecs extends InlineContentSpecs | undefined = undefined,\n SSpecs extends StyleSpecs | undefined = undefined,\n >(options?: {\n /**\n * A list of custom block types that should be available in the editor.\n */\n blockSpecs?: BSpecs;\n /**\n * A list of custom InlineContent types that should be available in the editor.\n */\n inlineContentSpecs?: ISpecs;\n /**\n * A list of custom Styles that should be available in the editor.\n */\n styleSpecs?: SSpecs;\n }): BlockNoteSchema<\n BSpecs extends undefined\n ? BlockSchemaFromSpecs<typeof defaultBlockSpecs>\n : BlockSchemaFromSpecs<NonNullable<BSpecs>>,\n ISpecs extends undefined\n ? InlineContentSchemaFromSpecs<typeof defaultInlineContentSpecs>\n : InlineContentSchemaFromSpecs<NonNullable<ISpecs>>,\n SSpecs extends undefined\n ? StyleSchemaFromSpecs<typeof defaultStyleSpecs>\n : StyleSchemaFromSpecs<NonNullable<SSpecs>>\n > {\n return new BlockNoteSchema<any, any, any>({\n blockSpecs: options?.blockSpecs ?? defaultBlockSpecs,\n inlineContentSpecs:\n options?.inlineContentSpecs ?? defaultInlineContentSpecs,\n styleSpecs: options?.styleSpecs ?? defaultStyleSpecs,\n });\n }\n}\n"],"names":["toposort","dag","inDegrees","countInDegrees","roots","nonRoots","getRootsAndNonRoots","sorted","newRoots","root","dependents","dependent","currentDegree","newDegree","toposortReverse","deps","reverse","counts","vx","currentCount","id","deg","reversedDeps","name","dependsOn","dependsOnName","createDependencyGraph","addDependency","graph","from","to","sortByDependencies","items","item","runBefore","sortedSpecs","defaultIndex","set","key","removeUndefined","obj","value","CustomBlockNoteSchema","opts","__publicField","blockSpecs","inlineContentSpecs","styleSpecs","blockSchema","inlineContentSchema","styleSchema","getPriority","val","_a","blockSpec","addNodeAndExtensionsToSpec","inlineContentSpec","styleSpec","blockDef","getInlineContentSchemaFromSpecs","getStyleSchemaFromSpecs","createPageBreakBlockConfig","createBlockConfig","createPageBreakBlockSpec","createBlockSpec","element","pageBreak","withPageBreak","schema","uploadToTmpFilesDotOrg_DEV_ONLY","file","body","checkPageBreakBlocksInSchema","editor","getPageBreakSlashMenuItems","insertOrUpdateBlockForSlashMenu","BlockNoteSchema","options","defaultBlockSpecs","defaultInlineContentSpecs","defaultStyleSpecs"],"mappings":"iOAiBO,SAASA,EAASC,EAAqC,CAC5D,MAAMC,EAAYC,EAAeF,CAAG,EAEpC,GAAI,CAAE,MAAAG,EAAO,SAAAC,GAAaC,EAAoBJ,CAAS,EAEvD,MAAMK,EAAmB,CAAA,EAEzB,KAAOH,EAAM,MAAM,CACjBG,EAAO,KAAKH,CAAK,EAEjB,MAAMI,MAAe,IACrB,UAAWC,KAAQL,EAAO,CACxB,MAAMM,EAAaT,EAAI,IAAIQ,CAAI,EAC/B,GAAKC,EAKL,UAAWC,KAAaD,EAAY,CAClC,MAAME,EAAgBV,EAAU,IAAIS,CAAS,EAC7C,GAAIC,IAAkB,OAEpB,SAGF,MAAMC,EAAYD,EAAgB,EAClCV,EAAU,IAAIS,EAAWE,CAAS,EAE9BA,IAAc,GAChBL,EAAS,IAAIG,CAAS,CAE1B,CACF,CAEAP,EAAQI,CACV,CAGA,GAFAH,EAAWC,EAAoBJ,CAAS,EAAE,SAEtCG,EAAS,KACX,MAAM,IAAI,MACR,2EAA2E,MAAM,KAAKA,CAAQ,EAAE,KAAK,IAAI,CAAC,EAAA,EAI9G,OAAOE,CACT,CAEO,SAASO,EAAgBC,EAAiC,CAC/D,MAAMd,EAAMe,EAAQD,CAAI,EACxB,OAAOf,EAASC,CAAG,CACrB,CAIA,SAASE,EAAeF,EAAsC,CAC5D,MAAMgB,MAAwB,IAE9B,SAAW,CAACC,EAAIR,CAAU,IAAKT,EAAI,UAAW,CAEvCgB,EAAO,IAAIC,CAAE,GAChBD,EAAO,IAAIC,EAAI,CAAC,EAGlB,UAAWP,KAAaD,EAAY,CAClC,MAAMS,EAAeF,EAAO,IAAIN,CAAS,GAAK,EA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ACnC,oBACED,GAAA,YAAAA,EAAS,qBAAsBE,EAAAA,0BACjC,YAAYF,GAAA,YAAAA,EAAS,aAAcG,EAAAA,iBAAA,CACpC,CACH,CACF"}
|
|
1
|
+
{"version":3,"file":"BlockNoteSchema-B4gm-Qco.cjs","sources":["../src/util/topo-sort.ts","../src/schema/schema.ts","../src/blocks/PageBreak/block.ts","../src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts","../src/blocks/PageBreak/getPageBreakSlashMenuItems.ts","../src/blocks/BlockNoteSchema.ts"],"sourcesContent":["/**\n * Instead of depending on the NPM package, we vendor this file from https://github.com/n1ru4l/toposort/blob/main/src/toposort.ts (MIT)\n *\n * There was a recent publish, despite not having been updated in 2 years, which is suspicious.\n *\n * This file is also simple enough that we can maintain it ourselves.\n */\n\nexport type DirectedAcyclicGraph = Map<string, Iterable<string>>;\nexport type DependencyGraph = DirectedAcyclicGraph;\n\nexport type TaskList = Array<Set<string>>;\n\n// Add more specific types for better type safety\nexport type NodeId = string;\nexport type DependencyMap = Map<NodeId, Set<NodeId>>;\n\nexport function toposort(dag: DirectedAcyclicGraph): TaskList {\n const inDegrees = countInDegrees(dag);\n\n let { roots, nonRoots } = getRootsAndNonRoots(inDegrees);\n\n const sorted: TaskList = [];\n\n while (roots.size) {\n sorted.push(roots);\n\n const newRoots = new Set<NodeId>();\n for (const root of roots) {\n const dependents = dag.get(root);\n if (!dependents) {\n // Handle case where node has no dependents\n continue;\n }\n\n for (const dependent of dependents) {\n const currentDegree = inDegrees.get(dependent);\n if (currentDegree === undefined) {\n // Handle case where dependent node is not in inDegrees\n continue;\n }\n\n const newDegree = currentDegree - 1;\n inDegrees.set(dependent, newDegree);\n\n if (newDegree === 0) {\n newRoots.add(dependent);\n }\n }\n }\n\n roots = newRoots;\n }\n nonRoots = getRootsAndNonRoots(inDegrees).nonRoots;\n\n if (nonRoots.size) {\n throw new Error(\n `Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(nonRoots).join(\", \")}`,\n );\n }\n\n return sorted;\n}\n\nexport function toposortReverse(deps: DependencyGraph): TaskList {\n const dag = reverse(deps);\n return toposort(dag);\n}\n\ntype InDegrees = Map<NodeId, number>;\n\nfunction countInDegrees(dag: DirectedAcyclicGraph): InDegrees {\n const counts: InDegrees = new Map();\n\n for (const [vx, dependents] of dag.entries()) {\n // Initialize count for current node if not present\n if (!counts.has(vx)) {\n counts.set(vx, 0);\n }\n\n for (const dependent of dependents) {\n const currentCount = counts.get(dependent) ?? 0;\n counts.set(dependent, currentCount + 1);\n }\n }\n\n return counts;\n}\n\nfunction getRootsAndNonRoots(counts: InDegrees) {\n const roots = new Set<NodeId>();\n const nonRoots = new Set<NodeId>();\n\n for (const [id, deg] of counts.entries()) {\n if (deg === 0) {\n roots.add(id);\n } else {\n nonRoots.add(id);\n }\n }\n\n return { roots, nonRoots };\n}\n\nfunction reverse(deps: DirectedAcyclicGraph): DependencyGraph {\n const reversedDeps: DependencyMap = new Map();\n\n for (const [name, dependsOn] of deps.entries()) {\n // Ensure the source node exists in the reversed map\n if (!reversedDeps.has(name)) {\n reversedDeps.set(name, new Set());\n }\n\n for (const dependsOnName of dependsOn) {\n if (!reversedDeps.has(dependsOnName)) {\n reversedDeps.set(dependsOnName, new Set());\n }\n reversedDeps.get(dependsOnName)!.add(name);\n }\n }\n\n return reversedDeps;\n}\n\nexport function createDependencyGraph(): DependencyMap {\n return new Map();\n}\n\nexport function addDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): DependencyMap {\n if (!graph.has(from)) {\n graph.set(from, new Set());\n }\n graph.get(from)!.add(to);\n return graph;\n}\n\nexport function removeDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n if (!dependents) {\n return false;\n }\n return dependents.delete(to);\n}\n\nexport function hasDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n return dependents ? dependents.has(to) : false;\n}\n\n/**\n * Sorts a list of items by their dependencies\n * @returns A function which can retrieve the priority of an item\n */\nexport function sortByDependencies(\n items: { key: string; runsBefore?: ReadonlyArray<string> }[],\n) {\n const dag = createDependencyGraph();\n\n for (const item of items) {\n if (Array.isArray(item.runsBefore) && item.runsBefore.length > 0) {\n item.runsBefore.forEach((runBefore) => {\n addDependency(dag, item.key, runBefore);\n });\n } else {\n addDependency(dag, \"default\", item.key);\n }\n }\n const sortedSpecs = toposortReverse(dag);\n const defaultIndex = sortedSpecs.findIndex((set) => set.has(\"default\"));\n\n /**\n * The priority of an item is described relative to the \"default\" (an arbitrary string which can be used as the reference)\n *\n * Since items are topologically sorted, we can see what their relative position is to the \"default\"\n * Each layer away from the default is 10 priority points (arbitrarily chosen)\n * The default is fixed at 101 (1 point higher than any tiptap extension, giving priority to custom blocks than any defaults)\n *\n * This is a bit of a hack, but it's a simple way to ensure that custom items are always rendered with higher priority than default items\n * and that custom items are rendered in the order they are defined in the list\n */\n\n /**\n * Retrieves the priority of an item based on its position in the topologically sorted list\n * @param key - The key of the item to get the priority of\n * @returns The priority of the item\n */\n return (key: string) => {\n const index = sortedSpecs.findIndex((set) => set.has(key));\n // the default index should map to 101\n // one before the default index is 91\n // one after is 111\n return 91 + (index + defaultIndex) * 10;\n };\n}\n","import { BlockNoteEditor } from \"../editor/BlockNoteEditor.js\";\nimport { sortByDependencies } from \"../util/topo-sort.js\";\nimport {\n BlockNoDefaults,\n BlockSchema,\n BlockSpecs,\n InlineContentConfig,\n InlineContentSchema,\n InlineContentSpec,\n InlineContentSpecs,\n LooseBlockSpec,\n PartialBlockNoDefaults,\n StyleSchema,\n StyleSpecs,\n addNodeAndExtensionsToSpec,\n getInlineContentSchemaFromSpecs,\n getStyleSchemaFromSpecs,\n} from \"./index.js\";\n\nfunction removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {\n if (!obj) {\n return obj;\n }\n return Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as T;\n}\n\nexport class CustomBlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> {\n // Helper so that you can use typeof schema.BlockNoteEditor\n public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly PartialBlock: PartialBlockNoDefaults<\n BSchema,\n ISchema,\n SSchema\n > = \"only for types\" as any;\n\n public inlineContentSpecs: InlineContentSpecs;\n public styleSpecs: StyleSpecs;\n public blockSpecs: {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n public blockSchema: BSchema;\n public inlineContentSchema: ISchema;\n public styleSchema: SSchema;\n\n constructor(\n private opts: {\n blockSpecs: BlockSpecs;\n inlineContentSpecs: InlineContentSpecs;\n styleSpecs: StyleSpecs;\n },\n ) {\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n }\n\n private init() {\n const getPriority = sortByDependencies(\n Object.entries({\n ...this.opts.blockSpecs,\n ...this.opts.inlineContentSpecs,\n ...this.opts.styleSpecs,\n }).map(([key, val]) => ({\n key: key,\n runsBefore: val.implementation?.runsBefore ?? [],\n })),\n );\n\n const blockSpecs = Object.fromEntries(\n Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {\n return [\n key,\n addNodeAndExtensionsToSpec(\n blockSpec.config,\n blockSpec.implementation,\n blockSpec.extensions,\n getPriority(key),\n ),\n ];\n }),\n ) as {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n const inlineContentSpecs = Object.fromEntries(\n Object.entries(this.opts.inlineContentSpecs).map(\n ([key, inlineContentSpec]) => {\n // Case for text and links.\n if (typeof inlineContentSpec.config !== \"object\") {\n return [key, inlineContentSpec];\n }\n\n return [\n key,\n {\n ...inlineContentSpec,\n implementation: {\n ...inlineContentSpec.implementation,\n node: inlineContentSpec.implementation?.node.extend({\n priority: getPriority(key),\n }),\n },\n },\n ];\n },\n ),\n ) as InlineContentSpecs;\n\n const styleSpecs = Object.fromEntries(\n Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [\n key,\n {\n ...styleSpec,\n implementation: {\n ...styleSpec.implementation,\n mark: styleSpec.implementation?.mark.extend({\n priority: getPriority(key),\n }),\n },\n },\n ]),\n ) as StyleSpecs;\n\n return {\n blockSpecs,\n blockSchema: Object.fromEntries(\n Object.entries(blockSpecs).map(([key, blockDef]) => {\n return [key, blockDef.config];\n }),\n ) as any,\n inlineContentSpecs: removeUndefined(inlineContentSpecs),\n styleSpecs: removeUndefined(styleSpecs),\n inlineContentSchema: getInlineContentSchemaFromSpecs(\n inlineContentSpecs,\n ) as any,\n styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,\n };\n }\n\n /**\n * Adds additional block specs to the current schema in a builder pattern.\n * This method allows extending the schema after it has been created.\n *\n * @param additionalBlockSpecs - Additional block specs to add to the schema\n * @returns The current schema instance for chaining\n */\n public extend<\n AdditionalBlockSpecs extends BlockSpecs = Record<string, never>,\n AdditionalInlineContentSpecs extends Record<\n string,\n InlineContentSpec<InlineContentConfig>\n > = Record<string, never>,\n AdditionalStyleSpecs extends StyleSpecs = Record<string, never>,\n >(opts: {\n blockSpecs?: AdditionalBlockSpecs;\n inlineContentSpecs?: AdditionalInlineContentSpecs;\n styleSpecs?: AdditionalStyleSpecs;\n }): CustomBlockNoteSchema<\n AdditionalBlockSpecs extends undefined | Record<string, never>\n ? BSchema\n : BSchema & {\n [K in keyof AdditionalBlockSpecs]: K extends string\n ? AdditionalBlockSpecs[K][\"config\"]\n : never;\n },\n AdditionalInlineContentSpecs extends undefined | Record<string, never>\n ? ISchema\n : ISchema & {\n [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K][\"config\"];\n },\n AdditionalStyleSpecs extends undefined | Record<string, never>\n ? SSchema\n : SSchema & {\n [K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K][\"config\"];\n }\n > {\n // Merge the new specs with existing ones\n Object.assign(this.opts.blockSpecs, opts.blockSpecs);\n Object.assign(this.opts.inlineContentSpecs, opts.inlineContentSpecs);\n Object.assign(this.opts.styleSpecs, opts.styleSpecs);\n\n // Reinitialize the block specs with the merged specs\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n\n return this as any;\n }\n}\n","import {\n BlockSchema,\n createBlockConfig,\n createBlockSpec,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { BlockNoteSchema } from \"../BlockNoteSchema.js\";\n\nexport type PageBreakBlockConfig = ReturnType<\n typeof createPageBreakBlockConfig\n>;\n\nexport const createPageBreakBlockConfig = createBlockConfig(\n () =>\n ({\n type: \"pageBreak\" as const,\n propSchema: {},\n content: \"none\",\n }) as const,\n);\n\nexport const createPageBreakBlockSpec = createBlockSpec(\n createPageBreakBlockConfig,\n {\n parse(element) {\n if (\n element.tagName === \"DIV\" &&\n element.hasAttribute(\"data-page-break\")\n ) {\n return {};\n }\n\n return undefined;\n },\n render() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n toExternalHTML() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n },\n);\n\n/**\n * Adds page break support to the given schema.\n */\nexport const withPageBreak = <\n B extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n schema: BlockNoteSchema<B, I, S>,\n) => {\n return schema.extend({\n blockSpecs: {\n pageBreak: createPageBreakBlockSpec(),\n },\n });\n};\n","/**\n * Uploads a file to tmpfiles.org and returns the URL to the uploaded file.\n *\n * @warning This function should only be used for development purposes, replace with your own backend!\n */\nexport const uploadToTmpFilesDotOrg_DEV_ONLY = async (\n file: File,\n): Promise<string> => {\n const body = new FormData();\n body.append(\"file\", file);\n\n const ret = await fetch(\"https://tmpfiles.org/api/v1/upload\", {\n method: \"POST\",\n body: body,\n });\n return (await ret.json()).data.url.replace(\n \"tmpfiles.org/\",\n \"tmpfiles.org/dl/\",\n );\n};\n","import { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\nimport { DefaultSuggestionItem } from \"../../extensions/SuggestionMenu/DefaultSuggestionItem.js\";\nimport { insertOrUpdateBlockForSlashMenu } from \"../../extensions/SuggestionMenu/getDefaultSlashMenuItems.js\";\nimport {\n BlockSchema,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { createPageBreakBlockConfig } from \"./block.js\";\n\nexport function checkPageBreakBlocksInSchema<\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n editor: BlockNoteEditor<any, I, S>,\n): editor is BlockNoteEditor<\n {\n pageBreak: ReturnType<typeof createPageBreakBlockConfig>;\n },\n I,\n S\n> {\n return \"pageBreak\" in editor.schema.blockSchema;\n}\n\nexport function getPageBreakSlashMenuItems<\n BSchema extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, I, S>) {\n const items: (Omit<DefaultSuggestionItem, \"key\"> & { key: \"page_break\" })[] =\n [];\n\n if (checkPageBreakBlocksInSchema(editor)) {\n items.push({\n ...editor.dictionary.slash_menu.page_break,\n onItemClick: () => {\n insertOrUpdateBlockForSlashMenu(editor, {\n type: \"pageBreak\",\n });\n },\n key: \"page_break\",\n });\n }\n\n return items;\n}\n","import {\n BlockSchema,\n BlockSchemaFromSpecs,\n BlockSpecs,\n CustomBlockNoteSchema,\n InlineContentSchema,\n InlineContentSchemaFromSpecs,\n InlineContentSpecs,\n StyleSchema,\n StyleSchemaFromSpecs,\n StyleSpecs,\n} from \"../schema/index.js\";\nimport {\n defaultBlockSpecs,\n defaultInlineContentSpecs,\n defaultStyleSpecs,\n} from \"./defaultBlocks.js\";\n\nexport class BlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> extends CustomBlockNoteSchema<BSchema, ISchema, SSchema> {\n public static create<\n BSpecs extends BlockSpecs | undefined = undefined,\n ISpecs extends InlineContentSpecs | undefined = undefined,\n SSpecs extends StyleSpecs | undefined = undefined,\n >(options?: {\n /**\n * A list of custom block types that should be available in the editor.\n */\n blockSpecs?: BSpecs;\n /**\n * A list of custom InlineContent types that should be available in the editor.\n */\n inlineContentSpecs?: ISpecs;\n /**\n * A list of custom Styles that should be available in the editor.\n */\n styleSpecs?: SSpecs;\n }): BlockNoteSchema<\n BSpecs extends undefined\n ? BlockSchemaFromSpecs<typeof defaultBlockSpecs>\n : BlockSchemaFromSpecs<NonNullable<BSpecs>>,\n ISpecs extends undefined\n ? InlineContentSchemaFromSpecs<typeof defaultInlineContentSpecs>\n : InlineContentSchemaFromSpecs<NonNullable<ISpecs>>,\n SSpecs extends undefined\n ? StyleSchemaFromSpecs<typeof defaultStyleSpecs>\n : StyleSchemaFromSpecs<NonNullable<SSpecs>>\n > {\n return new BlockNoteSchema<any, any, any>({\n blockSpecs: options?.blockSpecs ?? defaultBlockSpecs,\n inlineContentSpecs:\n options?.inlineContentSpecs ?? defaultInlineContentSpecs,\n styleSpecs: options?.styleSpecs ?? defaultStyleSpecs,\n });\n }\n}\n"],"names":["toposort","dag","inDegrees","countInDegrees","roots","nonRoots","getRootsAndNonRoots","sorted","newRoots","root","dependents","dependent","currentDegree","newDegree","toposortReverse","deps","reverse","counts","vx","currentCount","id","deg","reversedDeps","name","dependsOn","dependsOnName","createDependencyGraph","addDependency","graph","from","to","sortByDependencies","items","item","runBefore","sortedSpecs","defaultIndex","set","key","removeUndefined","obj","value","CustomBlockNoteSchema","opts","__publicField","blockSpecs","inlineContentSpecs","styleSpecs","blockSchema","inlineContentSchema","styleSchema","getPriority","val","_a","blockSpec","addNodeAndExtensionsToSpec","inlineContentSpec","styleSpec","blockDef","getInlineContentSchemaFromSpecs","getStyleSchemaFromSpecs","createPageBreakBlockConfig","createBlockConfig","createPageBreakBlockSpec","createBlockSpec","element","pageBreak","withPageBreak","schema","uploadToTmpFilesDotOrg_DEV_ONLY","file","body","checkPageBreakBlocksInSchema","editor","getPageBreakSlashMenuItems","insertOrUpdateBlockForSlashMenu","BlockNoteSchema","options","defaultBlockSpecs","defaultInlineContentSpecs","defaultStyleSpecs"],"mappings":"iOAiBO,SAASA,EAASC,EAAqC,CAC5D,MAAMC,EAAYC,EAAeF,CAAG,EAEpC,GAAI,CAAE,MAAAG,EAAO,SAAAC,GAAaC,EAAoBJ,CAAS,EAEvD,MAAMK,EAAmB,CAAA,EAEzB,KAAOH,EAAM,MAAM,CACjBG,EAAO,KAAKH,CAAK,EAEjB,MAAMI,MAAe,IACrB,UAAWC,KAAQL,EAAO,CACxB,MAAMM,EAAaT,EAAI,IAAIQ,CAAI,EAC/B,GAAKC,EAKL,UAAWC,KAAaD,EAAY,CAClC,MAAME,EAAgBV,EAAU,IAAIS,CAAS,EAC7C,GAAIC,IAAkB,OAEpB,SAGF,MAAMC,EAAYD,EAAgB,EAClCV,EAAU,IAAIS,EAAWE,CAAS,EAE9BA,IAAc,GAChBL,EAAS,IAAIG,CAAS,CAE1B,CACF,CAEAP,EAAQI,CACV,CAGA,GAFAH,EAAWC,EAAoBJ,CAA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,kBAAA,CAEJ,ECTO,SAASC,EAIdC,EAOA,CACA,MAAO,cAAeA,EAAO,OAAO,WACtC,CAEO,SAASC,EAIdD,EAAwC,CACxC,MAAMzC,EACJ,CAAA,EAEF,OAAIwC,EAA6BC,CAAM,GACrCzC,EAAM,KAAK,CACT,GAAGyC,EAAO,WAAW,WAAW,WAChC,YAAa,IAAM,CACjBE,EAAAA,gCAAgCF,EAAQ,CACtC,KAAM,WAAA,CACP,CACH,EACA,IAAK,YAAA,CACN,EAGIzC,CACT,CC5BO,MAAM4C,UAIHlC,CAAiD,CACzD,OAAc,OAIZmC,EAuBA,CACA,OAAO,IAAID,EAA+B,CACxC,YAAYC,GAAA,YAAAA,EAAS,aAAcC,EAAAA,kBACnC,oBACED,GAAA,YAAAA,EAAS,qBAAsBE,EAAAA,0BACjC,YAAYF,GAAA,YAAAA,EAAS,aAAcG,EAAAA,iBAAA,CACpC,CACH,CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
2
|
var k = (t, e, n) => e in t ? u(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var i = (t, e, n) => k(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { ad as g, ae as y, af as b, ag as B, ah as C, aa as w, X as O, Z as j, W as x } from "./defaultBlocks-
|
|
4
|
+
import { ad as g, ae as y, af as b, ag as B, ah as C, aa as w, X as O, Z as j, W as x } from "./defaultBlocks-DgA_mtQV.js";
|
|
5
5
|
function E(t) {
|
|
6
6
|
const e = v(t);
|
|
7
7
|
let { roots: n, nonRoots: r } = f(e);
|
|
@@ -267,4 +267,4 @@ export {
|
|
|
267
267
|
L as u,
|
|
268
268
|
z as w
|
|
269
269
|
};
|
|
270
|
-
//# sourceMappingURL=BlockNoteSchema-
|
|
270
|
+
//# sourceMappingURL=BlockNoteSchema-C-l154WP.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNoteSchema-CbSavEwr.js","sources":["../src/util/topo-sort.ts","../src/schema/schema.ts","../src/blocks/PageBreak/block.ts","../src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts","../src/blocks/PageBreak/getPageBreakSlashMenuItems.ts","../src/blocks/BlockNoteSchema.ts"],"sourcesContent":["/**\n * Instead of depending on the NPM package, we vendor this file from https://github.com/n1ru4l/toposort/blob/main/src/toposort.ts (MIT)\n *\n * There was a recent publish, despite not having been updated in 2 years, which is suspicious.\n *\n * This file is also simple enough that we can maintain it ourselves.\n */\n\nexport type DirectedAcyclicGraph = Map<string, Iterable<string>>;\nexport type DependencyGraph = DirectedAcyclicGraph;\n\nexport type TaskList = Array<Set<string>>;\n\n// Add more specific types for better type safety\nexport type NodeId = string;\nexport type DependencyMap = Map<NodeId, Set<NodeId>>;\n\nexport function toposort(dag: DirectedAcyclicGraph): TaskList {\n const inDegrees = countInDegrees(dag);\n\n let { roots, nonRoots } = getRootsAndNonRoots(inDegrees);\n\n const sorted: TaskList = [];\n\n while (roots.size) {\n sorted.push(roots);\n\n const newRoots = new Set<NodeId>();\n for (const root of roots) {\n const dependents = dag.get(root);\n if (!dependents) {\n // Handle case where node has no dependents\n continue;\n }\n\n for (const dependent of dependents) {\n const currentDegree = inDegrees.get(dependent);\n if (currentDegree === undefined) {\n // Handle case where dependent node is not in inDegrees\n continue;\n }\n\n const newDegree = currentDegree - 1;\n inDegrees.set(dependent, newDegree);\n\n if (newDegree === 0) {\n newRoots.add(dependent);\n }\n }\n }\n\n roots = newRoots;\n }\n nonRoots = getRootsAndNonRoots(inDegrees).nonRoots;\n\n if (nonRoots.size) {\n throw new Error(\n `Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(nonRoots).join(\", \")}`,\n );\n }\n\n return sorted;\n}\n\nexport function toposortReverse(deps: DependencyGraph): TaskList {\n const dag = reverse(deps);\n return toposort(dag);\n}\n\ntype InDegrees = Map<NodeId, number>;\n\nfunction countInDegrees(dag: DirectedAcyclicGraph): InDegrees {\n const counts: InDegrees = new Map();\n\n for (const [vx, dependents] of dag.entries()) {\n // Initialize count for current node if not present\n if (!counts.has(vx)) {\n counts.set(vx, 0);\n }\n\n for (const dependent of dependents) {\n const currentCount = counts.get(dependent) ?? 0;\n counts.set(dependent, currentCount + 1);\n }\n }\n\n return counts;\n}\n\nfunction getRootsAndNonRoots(counts: InDegrees) {\n const roots = new Set<NodeId>();\n const nonRoots = new Set<NodeId>();\n\n for (const [id, deg] of counts.entries()) {\n if (deg === 0) {\n roots.add(id);\n } else {\n nonRoots.add(id);\n }\n }\n\n return { roots, nonRoots };\n}\n\nfunction reverse(deps: DirectedAcyclicGraph): DependencyGraph {\n const reversedDeps: DependencyMap = new Map();\n\n for (const [name, dependsOn] of deps.entries()) {\n // Ensure the source node exists in the reversed map\n if (!reversedDeps.has(name)) {\n reversedDeps.set(name, new Set());\n }\n\n for (const dependsOnName of dependsOn) {\n if (!reversedDeps.has(dependsOnName)) {\n reversedDeps.set(dependsOnName, new Set());\n }\n reversedDeps.get(dependsOnName)!.add(name);\n }\n }\n\n return reversedDeps;\n}\n\nexport function createDependencyGraph(): DependencyMap {\n return new Map();\n}\n\nexport function addDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): DependencyMap {\n if (!graph.has(from)) {\n graph.set(from, new Set());\n }\n graph.get(from)!.add(to);\n return graph;\n}\n\nexport function removeDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n if (!dependents) {\n return false;\n }\n return dependents.delete(to);\n}\n\nexport function hasDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n return dependents ? dependents.has(to) : false;\n}\n\n/**\n * Sorts a list of items by their dependencies\n * @returns A function which can retrieve the priority of an item\n */\nexport function sortByDependencies(\n items: { key: string; runsBefore?: ReadonlyArray<string> }[],\n) {\n const dag = createDependencyGraph();\n\n for (const item of items) {\n if (Array.isArray(item.runsBefore) && item.runsBefore.length > 0) {\n item.runsBefore.forEach((runBefore) => {\n addDependency(dag, item.key, runBefore);\n });\n } else {\n addDependency(dag, \"default\", item.key);\n }\n }\n const sortedSpecs = toposortReverse(dag);\n const defaultIndex = sortedSpecs.findIndex((set) => set.has(\"default\"));\n\n /**\n * The priority of an item is described relative to the \"default\" (an arbitrary string which can be used as the reference)\n *\n * Since items are topologically sorted, we can see what their relative position is to the \"default\"\n * Each layer away from the default is 10 priority points (arbitrarily chosen)\n * The default is fixed at 101 (1 point higher than any tiptap extension, giving priority to custom blocks than any defaults)\n *\n * This is a bit of a hack, but it's a simple way to ensure that custom items are always rendered with higher priority than default items\n * and that custom items are rendered in the order they are defined in the list\n */\n\n /**\n * Retrieves the priority of an item based on its position in the topologically sorted list\n * @param key - The key of the item to get the priority of\n * @returns The priority of the item\n */\n return (key: string) => {\n const index = sortedSpecs.findIndex((set) => set.has(key));\n // the default index should map to 101\n // one before the default index is 91\n // one after is 111\n return 91 + (index + defaultIndex) * 10;\n };\n}\n","import { BlockNoteEditor } from \"../editor/BlockNoteEditor.js\";\nimport { sortByDependencies } from \"../util/topo-sort.js\";\nimport {\n BlockNoDefaults,\n BlockSchema,\n BlockSpecs,\n InlineContentConfig,\n InlineContentSchema,\n InlineContentSpec,\n InlineContentSpecs,\n LooseBlockSpec,\n PartialBlockNoDefaults,\n StyleSchema,\n StyleSpecs,\n addNodeAndExtensionsToSpec,\n getInlineContentSchemaFromSpecs,\n getStyleSchemaFromSpecs,\n} from \"./index.js\";\n\nfunction removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {\n if (!obj) {\n return obj;\n }\n return Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as T;\n}\n\nexport class CustomBlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> {\n // Helper so that you can use typeof schema.BlockNoteEditor\n public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly PartialBlock: PartialBlockNoDefaults<\n BSchema,\n ISchema,\n SSchema\n > = \"only for types\" as any;\n\n public inlineContentSpecs: InlineContentSpecs;\n public styleSpecs: StyleSpecs;\n public blockSpecs: {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n public blockSchema: BSchema;\n public inlineContentSchema: ISchema;\n public styleSchema: SSchema;\n\n constructor(\n private opts: {\n blockSpecs: BlockSpecs;\n inlineContentSpecs: InlineContentSpecs;\n styleSpecs: StyleSpecs;\n },\n ) {\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n }\n\n private init() {\n const getPriority = sortByDependencies(\n Object.entries({\n ...this.opts.blockSpecs,\n ...this.opts.inlineContentSpecs,\n ...this.opts.styleSpecs,\n }).map(([key, val]) => ({\n key: key,\n runsBefore: val.implementation?.runsBefore ?? [],\n })),\n );\n\n const blockSpecs = Object.fromEntries(\n Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {\n return [\n key,\n addNodeAndExtensionsToSpec(\n blockSpec.config,\n blockSpec.implementation,\n blockSpec.extensions,\n getPriority(key),\n ),\n ];\n }),\n ) as {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n const inlineContentSpecs = Object.fromEntries(\n Object.entries(this.opts.inlineContentSpecs).map(\n ([key, inlineContentSpec]) => {\n // Case for text and links.\n if (typeof inlineContentSpec.config !== \"object\") {\n return [key, inlineContentSpec];\n }\n\n return [\n key,\n {\n ...inlineContentSpec,\n implementation: {\n ...inlineContentSpec.implementation,\n node: inlineContentSpec.implementation?.node.extend({\n priority: getPriority(key),\n }),\n },\n },\n ];\n },\n ),\n ) as InlineContentSpecs;\n\n const styleSpecs = Object.fromEntries(\n Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [\n key,\n {\n ...styleSpec,\n implementation: {\n ...styleSpec.implementation,\n mark: styleSpec.implementation?.mark.extend({\n priority: getPriority(key),\n }),\n },\n },\n ]),\n ) as StyleSpecs;\n\n return {\n blockSpecs,\n blockSchema: Object.fromEntries(\n Object.entries(blockSpecs).map(([key, blockDef]) => {\n return [key, blockDef.config];\n }),\n ) as any,\n inlineContentSpecs: removeUndefined(inlineContentSpecs),\n styleSpecs: removeUndefined(styleSpecs),\n inlineContentSchema: getInlineContentSchemaFromSpecs(\n inlineContentSpecs,\n ) as any,\n styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,\n };\n }\n\n /**\n * Adds additional block specs to the current schema in a builder pattern.\n * This method allows extending the schema after it has been created.\n *\n * @param additionalBlockSpecs - Additional block specs to add to the schema\n * @returns The current schema instance for chaining\n */\n public extend<\n AdditionalBlockSpecs extends BlockSpecs = Record<string, never>,\n AdditionalInlineContentSpecs extends Record<\n string,\n InlineContentSpec<InlineContentConfig>\n > = Record<string, never>,\n AdditionalStyleSpecs extends StyleSpecs = Record<string, never>,\n >(opts: {\n blockSpecs?: AdditionalBlockSpecs;\n inlineContentSpecs?: AdditionalInlineContentSpecs;\n styleSpecs?: AdditionalStyleSpecs;\n }): CustomBlockNoteSchema<\n AdditionalBlockSpecs extends undefined | Record<string, never>\n ? BSchema\n : BSchema & {\n [K in keyof AdditionalBlockSpecs]: K extends string\n ? AdditionalBlockSpecs[K][\"config\"]\n : never;\n },\n AdditionalInlineContentSpecs extends undefined | Record<string, never>\n ? ISchema\n : ISchema & {\n [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K][\"config\"];\n },\n AdditionalStyleSpecs extends undefined | Record<string, never>\n ? SSchema\n : SSchema & {\n [K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K][\"config\"];\n }\n > {\n // Merge the new specs with existing ones\n Object.assign(this.opts.blockSpecs, opts.blockSpecs);\n Object.assign(this.opts.inlineContentSpecs, opts.inlineContentSpecs);\n Object.assign(this.opts.styleSpecs, opts.styleSpecs);\n\n // Reinitialize the block specs with the merged specs\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n\n return this as any;\n }\n}\n","import {\n BlockSchema,\n createBlockConfig,\n createBlockSpec,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { BlockNoteSchema } from \"../BlockNoteSchema.js\";\n\nexport type PageBreakBlockConfig = ReturnType<\n typeof createPageBreakBlockConfig\n>;\n\nexport const createPageBreakBlockConfig = createBlockConfig(\n () =>\n ({\n type: \"pageBreak\" as const,\n propSchema: {},\n content: \"none\",\n }) as const,\n);\n\nexport const createPageBreakBlockSpec = createBlockSpec(\n createPageBreakBlockConfig,\n {\n parse(element) {\n if (\n element.tagName === \"DIV\" &&\n element.hasAttribute(\"data-page-break\")\n ) {\n return {};\n }\n\n return undefined;\n },\n render() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n toExternalHTML() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n },\n);\n\n/**\n * Adds page break support to the given schema.\n */\nexport const withPageBreak = <\n B extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n schema: BlockNoteSchema<B, I, S>,\n) => {\n return schema.extend({\n blockSpecs: {\n pageBreak: createPageBreakBlockSpec(),\n },\n });\n};\n","/**\n * Uploads a file to tmpfiles.org and returns the URL to the uploaded file.\n *\n * @warning This function should only be used for development purposes, replace with your own backend!\n */\nexport const uploadToTmpFilesDotOrg_DEV_ONLY = async (\n file: File,\n): Promise<string> => {\n const body = new FormData();\n body.append(\"file\", file);\n\n const ret = await fetch(\"https://tmpfiles.org/api/v1/upload\", {\n method: \"POST\",\n body: body,\n });\n return (await ret.json()).data.url.replace(\n \"tmpfiles.org/\",\n \"tmpfiles.org/dl/\",\n );\n};\n","import { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\nimport { DefaultSuggestionItem } from \"../../extensions/SuggestionMenu/DefaultSuggestionItem.js\";\nimport { insertOrUpdateBlockForSlashMenu } from \"../../extensions/SuggestionMenu/getDefaultSlashMenuItems.js\";\nimport {\n BlockSchema,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { createPageBreakBlockConfig } from \"./block.js\";\n\nexport function checkPageBreakBlocksInSchema<\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n editor: BlockNoteEditor<any, I, S>,\n): editor is BlockNoteEditor<\n {\n pageBreak: ReturnType<typeof createPageBreakBlockConfig>;\n },\n I,\n S\n> {\n return \"pageBreak\" in editor.schema.blockSchema;\n}\n\nexport function getPageBreakSlashMenuItems<\n BSchema extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, I, S>) {\n const items: (Omit<DefaultSuggestionItem, \"key\"> & { key: \"page_break\" })[] =\n [];\n\n if (checkPageBreakBlocksInSchema(editor)) {\n items.push({\n ...editor.dictionary.slash_menu.page_break,\n onItemClick: () => {\n insertOrUpdateBlockForSlashMenu(editor, {\n type: \"pageBreak\",\n });\n },\n key: \"page_break\",\n });\n }\n\n return items;\n}\n","import {\n BlockSchema,\n BlockSchemaFromSpecs,\n BlockSpecs,\n CustomBlockNoteSchema,\n InlineContentSchema,\n InlineContentSchemaFromSpecs,\n InlineContentSpecs,\n StyleSchema,\n StyleSchemaFromSpecs,\n StyleSpecs,\n} from \"../schema/index.js\";\nimport {\n defaultBlockSpecs,\n defaultInlineContentSpecs,\n defaultStyleSpecs,\n} from \"./defaultBlocks.js\";\n\nexport class BlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> extends CustomBlockNoteSchema<BSchema, ISchema, SSchema> {\n public static create<\n BSpecs extends BlockSpecs | undefined = undefined,\n ISpecs extends InlineContentSpecs | undefined = undefined,\n SSpecs extends StyleSpecs | undefined = undefined,\n >(options?: {\n /**\n * A list of custom block types that should be available in the editor.\n */\n blockSpecs?: BSpecs;\n /**\n * A list of custom InlineContent types that should be available in the editor.\n */\n inlineContentSpecs?: ISpecs;\n /**\n * A list of custom Styles that should be available in the editor.\n */\n styleSpecs?: SSpecs;\n }): BlockNoteSchema<\n BSpecs extends undefined\n ? BlockSchemaFromSpecs<typeof defaultBlockSpecs>\n : BlockSchemaFromSpecs<NonNullable<BSpecs>>,\n ISpecs extends undefined\n ? InlineContentSchemaFromSpecs<typeof defaultInlineContentSpecs>\n : InlineContentSchemaFromSpecs<NonNullable<ISpecs>>,\n SSpecs extends undefined\n ? StyleSchemaFromSpecs<typeof defaultStyleSpecs>\n : StyleSchemaFromSpecs<NonNullable<SSpecs>>\n > {\n return new BlockNoteSchema<any, any, any>({\n blockSpecs: options?.blockSpecs ?? defaultBlockSpecs,\n inlineContentSpecs:\n options?.inlineContentSpecs ?? defaultInlineContentSpecs,\n styleSpecs: options?.styleSpecs ?? defaultStyleSpecs,\n });\n }\n}\n"],"names":["toposort","dag","inDegrees","countInDegrees","roots","nonRoots","getRootsAndNonRoots","sorted","newRoots","root","dependents","dependent","currentDegree","newDegree","toposortReverse","deps","reverse","counts","vx","currentCount","id","deg","reversedDeps","name","dependsOn","dependsOnName","createDependencyGraph","addDependency","graph","from","to","sortByDependencies","items","item","runBefore","sortedSpecs","defaultIndex","set","key","removeUndefined","obj","value","CustomBlockNoteSchema","opts","__publicField","blockSpecs","inlineContentSpecs","styleSpecs","blockSchema","inlineContentSchema","styleSchema","getPriority","val","_a","blockSpec","addNodeAndExtensionsToSpec","inlineContentSpec","styleSpec","blockDef","getInlineContentSchemaFromSpecs","getStyleSchemaFromSpecs","createPageBreakBlockConfig","createBlockConfig","createPageBreakBlockSpec","createBlockSpec","element","pageBreak","withPageBreak","schema","uploadToTmpFilesDotOrg_DEV_ONLY","file","body","checkPageBreakBlocksInSchema","editor","getPageBreakSlashMenuItems","insertOrUpdateBlockForSlashMenu","BlockNoteSchema","options","defaultBlockSpecs","defaultInlineContentSpecs","defaultStyleSpecs"],"mappings":";;;;AAiBO,SAASA,EAASC,GAAqC;AAC5D,QAAMC,IAAYC,EAAeF,CAAG;AAEpC,MAAI,EAAE,OAAAG,GAAO,UAAAC,MAAaC,EAAoBJ,CAAS;AAEvD,QAAMK,IAAmB,CAAA;AAEzB,SAAOH,EAAM,QAAM;AACjB,IAAAG,EAAO,KAAKH,CAAK;AAEjB,UAAMI,wBAAe,IAAA;AACrB,eAAWC,KAAQL,GAAO;AACxB,YAAMM,IAAaT,EAAI,IAAIQ,CAAI;AAC/B,UAAKC;AAKL,mBAAWC,KAAaD,GAAY;AAClC,gBAAME,IAAgBV,EAAU,IAAIS,CAAS;AAC7C,cAAIC,MAAkB;AAEpB;AAGF,gBAAMC,IAAYD,IAAgB;AAClC,UAAAV,EAAU,IAAIS,GAAWE,CAAS,GAE9BA,MAAc,KAChBL,EAAS,IAAIG,CAAS;AAAA,QAE1B;AAAA,IACF;AAEA,IAAAP,IAAQI;AAAA,EACV;AAGA,MAFAH,IAAWC,EAAoBJ,CAAS,EAAE,UAEtCG,EAAS;AACX,UAAM,IAAI;AAAA,MACR,2EAA2E,MAAM,KAAKA,CAAQ,EAAE,KAAK,IAAI,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ACA,WAAO,IAAID,EAA+B;AAAA,MACxC,aAAYC,KAAA,gBAAAA,EAAS,eAAcC;AAAA,MACnC,qBACED,KAAA,gBAAAA,EAAS,uBAAsBE;AAAA,MACjC,aAAYF,KAAA,gBAAAA,EAAS,eAAcG;AAAA,IAAA,CACpC;AAAA,EACH;AACF;"}
|
|
1
|
+
{"version":3,"file":"BlockNoteSchema-C-l154WP.js","sources":["../src/util/topo-sort.ts","../src/schema/schema.ts","../src/blocks/PageBreak/block.ts","../src/blocks/File/helpers/uploadToTmpFilesDotOrg_DEV_ONLY.ts","../src/blocks/PageBreak/getPageBreakSlashMenuItems.ts","../src/blocks/BlockNoteSchema.ts"],"sourcesContent":["/**\n * Instead of depending on the NPM package, we vendor this file from https://github.com/n1ru4l/toposort/blob/main/src/toposort.ts (MIT)\n *\n * There was a recent publish, despite not having been updated in 2 years, which is suspicious.\n *\n * This file is also simple enough that we can maintain it ourselves.\n */\n\nexport type DirectedAcyclicGraph = Map<string, Iterable<string>>;\nexport type DependencyGraph = DirectedAcyclicGraph;\n\nexport type TaskList = Array<Set<string>>;\n\n// Add more specific types for better type safety\nexport type NodeId = string;\nexport type DependencyMap = Map<NodeId, Set<NodeId>>;\n\nexport function toposort(dag: DirectedAcyclicGraph): TaskList {\n const inDegrees = countInDegrees(dag);\n\n let { roots, nonRoots } = getRootsAndNonRoots(inDegrees);\n\n const sorted: TaskList = [];\n\n while (roots.size) {\n sorted.push(roots);\n\n const newRoots = new Set<NodeId>();\n for (const root of roots) {\n const dependents = dag.get(root);\n if (!dependents) {\n // Handle case where node has no dependents\n continue;\n }\n\n for (const dependent of dependents) {\n const currentDegree = inDegrees.get(dependent);\n if (currentDegree === undefined) {\n // Handle case where dependent node is not in inDegrees\n continue;\n }\n\n const newDegree = currentDegree - 1;\n inDegrees.set(dependent, newDegree);\n\n if (newDegree === 0) {\n newRoots.add(dependent);\n }\n }\n }\n\n roots = newRoots;\n }\n nonRoots = getRootsAndNonRoots(inDegrees).nonRoots;\n\n if (nonRoots.size) {\n throw new Error(\n `Cycle(s) detected; toposort only works on acyclic graphs. Cyclic nodes: ${Array.from(nonRoots).join(\", \")}`,\n );\n }\n\n return sorted;\n}\n\nexport function toposortReverse(deps: DependencyGraph): TaskList {\n const dag = reverse(deps);\n return toposort(dag);\n}\n\ntype InDegrees = Map<NodeId, number>;\n\nfunction countInDegrees(dag: DirectedAcyclicGraph): InDegrees {\n const counts: InDegrees = new Map();\n\n for (const [vx, dependents] of dag.entries()) {\n // Initialize count for current node if not present\n if (!counts.has(vx)) {\n counts.set(vx, 0);\n }\n\n for (const dependent of dependents) {\n const currentCount = counts.get(dependent) ?? 0;\n counts.set(dependent, currentCount + 1);\n }\n }\n\n return counts;\n}\n\nfunction getRootsAndNonRoots(counts: InDegrees) {\n const roots = new Set<NodeId>();\n const nonRoots = new Set<NodeId>();\n\n for (const [id, deg] of counts.entries()) {\n if (deg === 0) {\n roots.add(id);\n } else {\n nonRoots.add(id);\n }\n }\n\n return { roots, nonRoots };\n}\n\nfunction reverse(deps: DirectedAcyclicGraph): DependencyGraph {\n const reversedDeps: DependencyMap = new Map();\n\n for (const [name, dependsOn] of deps.entries()) {\n // Ensure the source node exists in the reversed map\n if (!reversedDeps.has(name)) {\n reversedDeps.set(name, new Set());\n }\n\n for (const dependsOnName of dependsOn) {\n if (!reversedDeps.has(dependsOnName)) {\n reversedDeps.set(dependsOnName, new Set());\n }\n reversedDeps.get(dependsOnName)!.add(name);\n }\n }\n\n return reversedDeps;\n}\n\nexport function createDependencyGraph(): DependencyMap {\n return new Map();\n}\n\nexport function addDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): DependencyMap {\n if (!graph.has(from)) {\n graph.set(from, new Set());\n }\n graph.get(from)!.add(to);\n return graph;\n}\n\nexport function removeDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n if (!dependents) {\n return false;\n }\n return dependents.delete(to);\n}\n\nexport function hasDependency(\n graph: DependencyMap,\n from: NodeId,\n to: NodeId,\n): boolean {\n const dependents = graph.get(from);\n return dependents ? dependents.has(to) : false;\n}\n\n/**\n * Sorts a list of items by their dependencies\n * @returns A function which can retrieve the priority of an item\n */\nexport function sortByDependencies(\n items: { key: string; runsBefore?: ReadonlyArray<string> }[],\n) {\n const dag = createDependencyGraph();\n\n for (const item of items) {\n if (Array.isArray(item.runsBefore) && item.runsBefore.length > 0) {\n item.runsBefore.forEach((runBefore) => {\n addDependency(dag, item.key, runBefore);\n });\n } else {\n addDependency(dag, \"default\", item.key);\n }\n }\n const sortedSpecs = toposortReverse(dag);\n const defaultIndex = sortedSpecs.findIndex((set) => set.has(\"default\"));\n\n /**\n * The priority of an item is described relative to the \"default\" (an arbitrary string which can be used as the reference)\n *\n * Since items are topologically sorted, we can see what their relative position is to the \"default\"\n * Each layer away from the default is 10 priority points (arbitrarily chosen)\n * The default is fixed at 101 (1 point higher than any tiptap extension, giving priority to custom blocks than any defaults)\n *\n * This is a bit of a hack, but it's a simple way to ensure that custom items are always rendered with higher priority than default items\n * and that custom items are rendered in the order they are defined in the list\n */\n\n /**\n * Retrieves the priority of an item based on its position in the topologically sorted list\n * @param key - The key of the item to get the priority of\n * @returns The priority of the item\n */\n return (key: string) => {\n const index = sortedSpecs.findIndex((set) => set.has(key));\n // the default index should map to 101\n // one before the default index is 91\n // one after is 111\n return 91 + (index + defaultIndex) * 10;\n };\n}\n","import { BlockNoteEditor } from \"../editor/BlockNoteEditor.js\";\nimport { sortByDependencies } from \"../util/topo-sort.js\";\nimport {\n BlockNoDefaults,\n BlockSchema,\n BlockSpecs,\n InlineContentConfig,\n InlineContentSchema,\n InlineContentSpec,\n InlineContentSpecs,\n LooseBlockSpec,\n PartialBlockNoDefaults,\n StyleSchema,\n StyleSpecs,\n addNodeAndExtensionsToSpec,\n getInlineContentSchemaFromSpecs,\n getStyleSchemaFromSpecs,\n} from \"./index.js\";\n\nfunction removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {\n if (!obj) {\n return obj;\n }\n return Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as T;\n}\n\nexport class CustomBlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> {\n // Helper so that you can use typeof schema.BlockNoteEditor\n public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =\n \"only for types\" as any;\n\n public readonly PartialBlock: PartialBlockNoDefaults<\n BSchema,\n ISchema,\n SSchema\n > = \"only for types\" as any;\n\n public inlineContentSpecs: InlineContentSpecs;\n public styleSpecs: StyleSpecs;\n public blockSpecs: {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n public blockSchema: BSchema;\n public inlineContentSchema: ISchema;\n public styleSchema: SSchema;\n\n constructor(\n private opts: {\n blockSpecs: BlockSpecs;\n inlineContentSpecs: InlineContentSpecs;\n styleSpecs: StyleSpecs;\n },\n ) {\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n }\n\n private init() {\n const getPriority = sortByDependencies(\n Object.entries({\n ...this.opts.blockSpecs,\n ...this.opts.inlineContentSpecs,\n ...this.opts.styleSpecs,\n }).map(([key, val]) => ({\n key: key,\n runsBefore: val.implementation?.runsBefore ?? [],\n })),\n );\n\n const blockSpecs = Object.fromEntries(\n Object.entries(this.opts.blockSpecs).map(([key, blockSpec]) => {\n return [\n key,\n addNodeAndExtensionsToSpec(\n blockSpec.config,\n blockSpec.implementation,\n blockSpec.extensions,\n getPriority(key),\n ),\n ];\n }),\n ) as {\n [K in keyof BSchema]: K extends string\n ? LooseBlockSpec<K, BSchema[K][\"propSchema\"], BSchema[K][\"content\"]>\n : never;\n };\n\n const inlineContentSpecs = Object.fromEntries(\n Object.entries(this.opts.inlineContentSpecs).map(\n ([key, inlineContentSpec]) => {\n // Case for text and links.\n if (typeof inlineContentSpec.config !== \"object\") {\n return [key, inlineContentSpec];\n }\n\n return [\n key,\n {\n ...inlineContentSpec,\n implementation: {\n ...inlineContentSpec.implementation,\n node: inlineContentSpec.implementation?.node.extend({\n priority: getPriority(key),\n }),\n },\n },\n ];\n },\n ),\n ) as InlineContentSpecs;\n\n const styleSpecs = Object.fromEntries(\n Object.entries(this.opts.styleSpecs).map(([key, styleSpec]) => [\n key,\n {\n ...styleSpec,\n implementation: {\n ...styleSpec.implementation,\n mark: styleSpec.implementation?.mark.extend({\n priority: getPriority(key),\n }),\n },\n },\n ]),\n ) as StyleSpecs;\n\n return {\n blockSpecs,\n blockSchema: Object.fromEntries(\n Object.entries(blockSpecs).map(([key, blockDef]) => {\n return [key, blockDef.config];\n }),\n ) as any,\n inlineContentSpecs: removeUndefined(inlineContentSpecs),\n styleSpecs: removeUndefined(styleSpecs),\n inlineContentSchema: getInlineContentSchemaFromSpecs(\n inlineContentSpecs,\n ) as any,\n styleSchema: getStyleSchemaFromSpecs(styleSpecs) as any,\n };\n }\n\n /**\n * Adds additional block specs to the current schema in a builder pattern.\n * This method allows extending the schema after it has been created.\n *\n * @param additionalBlockSpecs - Additional block specs to add to the schema\n * @returns The current schema instance for chaining\n */\n public extend<\n AdditionalBlockSpecs extends BlockSpecs = Record<string, never>,\n AdditionalInlineContentSpecs extends Record<\n string,\n InlineContentSpec<InlineContentConfig>\n > = Record<string, never>,\n AdditionalStyleSpecs extends StyleSpecs = Record<string, never>,\n >(opts: {\n blockSpecs?: AdditionalBlockSpecs;\n inlineContentSpecs?: AdditionalInlineContentSpecs;\n styleSpecs?: AdditionalStyleSpecs;\n }): CustomBlockNoteSchema<\n AdditionalBlockSpecs extends undefined | Record<string, never>\n ? BSchema\n : BSchema & {\n [K in keyof AdditionalBlockSpecs]: K extends string\n ? AdditionalBlockSpecs[K][\"config\"]\n : never;\n },\n AdditionalInlineContentSpecs extends undefined | Record<string, never>\n ? ISchema\n : ISchema & {\n [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K][\"config\"];\n },\n AdditionalStyleSpecs extends undefined | Record<string, never>\n ? SSchema\n : SSchema & {\n [K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K][\"config\"];\n }\n > {\n // Merge the new specs with existing ones\n Object.assign(this.opts.blockSpecs, opts.blockSpecs);\n Object.assign(this.opts.inlineContentSpecs, opts.inlineContentSpecs);\n Object.assign(this.opts.styleSpecs, opts.styleSpecs);\n\n // Reinitialize the block specs with the merged specs\n const {\n blockSpecs,\n inlineContentSpecs,\n styleSpecs,\n blockSchema,\n inlineContentSchema,\n styleSchema,\n } = this.init();\n this.blockSpecs = blockSpecs;\n this.styleSpecs = styleSpecs;\n this.styleSchema = styleSchema;\n this.inlineContentSpecs = inlineContentSpecs;\n this.blockSchema = blockSchema;\n this.inlineContentSchema = inlineContentSchema;\n\n return this as any;\n }\n}\n","import {\n BlockSchema,\n createBlockConfig,\n createBlockSpec,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { BlockNoteSchema } from \"../BlockNoteSchema.js\";\n\nexport type PageBreakBlockConfig = ReturnType<\n typeof createPageBreakBlockConfig\n>;\n\nexport const createPageBreakBlockConfig = createBlockConfig(\n () =>\n ({\n type: \"pageBreak\" as const,\n propSchema: {},\n content: \"none\",\n }) as const,\n);\n\nexport const createPageBreakBlockSpec = createBlockSpec(\n createPageBreakBlockConfig,\n {\n parse(element) {\n if (\n element.tagName === \"DIV\" &&\n element.hasAttribute(\"data-page-break\")\n ) {\n return {};\n }\n\n return undefined;\n },\n render() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n toExternalHTML() {\n const pageBreak = document.createElement(\"div\");\n\n pageBreak.setAttribute(\"data-page-break\", \"\");\n\n return {\n dom: pageBreak,\n };\n },\n },\n);\n\n/**\n * Adds page break support to the given schema.\n */\nexport const withPageBreak = <\n B extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n schema: BlockNoteSchema<B, I, S>,\n) => {\n return schema.extend({\n blockSpecs: {\n pageBreak: createPageBreakBlockSpec(),\n },\n });\n};\n","/**\n * Uploads a file to tmpfiles.org and returns the URL to the uploaded file.\n *\n * @warning This function should only be used for development purposes, replace with your own backend!\n */\nexport const uploadToTmpFilesDotOrg_DEV_ONLY = async (\n file: File,\n): Promise<string> => {\n const body = new FormData();\n body.append(\"file\", file);\n\n const ret = await fetch(\"https://tmpfiles.org/api/v1/upload\", {\n method: \"POST\",\n body: body,\n });\n return (await ret.json()).data.url.replace(\n \"tmpfiles.org/\",\n \"tmpfiles.org/dl/\",\n );\n};\n","import { BlockNoteEditor } from \"../../editor/BlockNoteEditor.js\";\nimport { DefaultSuggestionItem } from \"../../extensions/SuggestionMenu/DefaultSuggestionItem.js\";\nimport { insertOrUpdateBlockForSlashMenu } from \"../../extensions/SuggestionMenu/getDefaultSlashMenuItems.js\";\nimport {\n BlockSchema,\n InlineContentSchema,\n StyleSchema,\n} from \"../../schema/index.js\";\nimport { createPageBreakBlockConfig } from \"./block.js\";\n\nexport function checkPageBreakBlocksInSchema<\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(\n editor: BlockNoteEditor<any, I, S>,\n): editor is BlockNoteEditor<\n {\n pageBreak: ReturnType<typeof createPageBreakBlockConfig>;\n },\n I,\n S\n> {\n return \"pageBreak\" in editor.schema.blockSchema;\n}\n\nexport function getPageBreakSlashMenuItems<\n BSchema extends BlockSchema,\n I extends InlineContentSchema,\n S extends StyleSchema,\n>(editor: BlockNoteEditor<BSchema, I, S>) {\n const items: (Omit<DefaultSuggestionItem, \"key\"> & { key: \"page_break\" })[] =\n [];\n\n if (checkPageBreakBlocksInSchema(editor)) {\n items.push({\n ...editor.dictionary.slash_menu.page_break,\n onItemClick: () => {\n insertOrUpdateBlockForSlashMenu(editor, {\n type: \"pageBreak\",\n });\n },\n key: \"page_break\",\n });\n }\n\n return items;\n}\n","import {\n BlockSchema,\n BlockSchemaFromSpecs,\n BlockSpecs,\n CustomBlockNoteSchema,\n InlineContentSchema,\n InlineContentSchemaFromSpecs,\n InlineContentSpecs,\n StyleSchema,\n StyleSchemaFromSpecs,\n StyleSpecs,\n} from \"../schema/index.js\";\nimport {\n defaultBlockSpecs,\n defaultInlineContentSpecs,\n defaultStyleSpecs,\n} from \"./defaultBlocks.js\";\n\nexport class BlockNoteSchema<\n BSchema extends BlockSchema,\n ISchema extends InlineContentSchema,\n SSchema extends StyleSchema,\n> extends CustomBlockNoteSchema<BSchema, ISchema, SSchema> {\n public static create<\n BSpecs extends BlockSpecs | undefined = undefined,\n ISpecs extends InlineContentSpecs | undefined = undefined,\n SSpecs extends StyleSpecs | undefined = undefined,\n >(options?: {\n /**\n * A list of custom block types that should be available in the editor.\n */\n blockSpecs?: BSpecs;\n /**\n * A list of custom InlineContent types that should be available in the editor.\n */\n inlineContentSpecs?: ISpecs;\n /**\n * A list of custom Styles that should be available in the editor.\n */\n styleSpecs?: SSpecs;\n }): BlockNoteSchema<\n BSpecs extends undefined\n ? BlockSchemaFromSpecs<typeof defaultBlockSpecs>\n : BlockSchemaFromSpecs<NonNullable<BSpecs>>,\n ISpecs extends undefined\n ? InlineContentSchemaFromSpecs<typeof defaultInlineContentSpecs>\n : InlineContentSchemaFromSpecs<NonNullable<ISpecs>>,\n SSpecs extends undefined\n ? StyleSchemaFromSpecs<typeof defaultStyleSpecs>\n : StyleSchemaFromSpecs<NonNullable<SSpecs>>\n > {\n return new BlockNoteSchema<any, any, any>({\n blockSpecs: options?.blockSpecs ?? defaultBlockSpecs,\n inlineContentSpecs:\n options?.inlineContentSpecs ?? defaultInlineContentSpecs,\n styleSpecs: options?.styleSpecs ?? defaultStyleSpecs,\n });\n }\n}\n"],"names":["toposort","dag","inDegrees","countInDegrees","roots","nonRoots","getRootsAndNonRoots","sorted","newRoots","root","dependents","dependent","currentDegree","newDegree","toposortReverse","deps","reverse","counts","vx","currentCount","id","deg","reversedDeps","name","dependsOn","dependsOnName","createDependencyGraph","addDependency","graph","from","to","sortByDependencies","items","item","runBefore","sortedSpecs","defaultIndex","set","key","removeUndefined","obj","value","CustomBlockNoteSchema","opts","__publicField","blockSpecs","inlineContentSpecs","styleSpecs","blockSchema","inlineContentSchema","styleSchema","getPriority","val","_a","blockSpec","addNodeAndExtensionsToSpec","inlineContentSpec","styleSpec","blockDef","getInlineContentSchemaFromSpecs","getStyleSchemaFromSpecs","createPageBreakBlockConfig","createBlockConfig","createPageBreakBlockSpec","createBlockSpec","element","pageBreak","withPageBreak","schema","uploadToTmpFilesDotOrg_DEV_ONLY","file","body","checkPageBreakBlocksInSchema","editor","getPageBreakSlashMenuItems","insertOrUpdateBlockForSlashMenu","BlockNoteSchema","options","defaultBlockSpecs","defaultInlineContentSpecs","defaultStyleSpecs"],"mappings":";;;;AAiBO,SAASA,EAASC,GAAqC;AAC5D,QAAMC,IAAYC,EAAeF,CAAG;AAEpC,MAAI,EAAE,OAAAG,GAAO,UAAAC,MAAaC,EAAoBJ,CAAS;AAEvD,QAAMK,IAAmB,CAAA;AAEzB,SAAOH,EAAM,QAAM;AACjB,IAAAG,EAAO,KAAKH,CAAK;AAEjB,UAAMI,wBAAe,IAAA;AACrB,eAAWC,KAAQL,GAAO;AACxB,YAAMM,IAAaT,EAAI,IAAIQ,CAAI;AAC/B,UAAKC;AAKL,mBAAWC,KAAaD,GAAY;AAClC,gBAAME,IAAgBV,EAAU,IAAIS,CAAS;AAC7C,cAAIC,MAAkB;AAEpB;AAGF,gBAAMC,IAAYD,IAAgB;AAClC,UAAAV,EAAU,IAAIS,GAAWE,CAAS,GAE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