@blocknote/core 0.46.0 → 0.46.2
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-DsMVJZv4.js → BlockNoteSchema-BkXw8HJ6.js} +2 -2
- package/dist/{BlockNoteSchema-DsMVJZv4.js.map → BlockNoteSchema-BkXw8HJ6.js.map} +1 -1
- package/dist/{BlockNoteSchema-qt4Czo0-.cjs → BlockNoteSchema-DmFDeA0n.cjs} +2 -2
- package/dist/{BlockNoteSchema-qt4Czo0-.cjs.map → BlockNoteSchema-DmFDeA0n.cjs.map} +1 -1
- package/dist/{TrailingNode-C-Kyrtf1.js → TrailingNode-CxM966vN.js} +50 -42
- package/dist/TrailingNode-CxM966vN.js.map +1 -0
- package/dist/TrailingNode-D-CZ76FS.cjs +2 -0
- package/dist/TrailingNode-D-CZ76FS.cjs.map +1 -0
- package/dist/blocknote.cjs +4 -4
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +681 -621
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/{defaultBlocks-CXOCngjC.js → defaultBlocks-DE5GNdJH.js} +31 -27
- package/dist/defaultBlocks-DE5GNdJH.js.map +1 -0
- package/dist/{defaultBlocks-IsUGVZIq.cjs → defaultBlocks-DosClM5E.cjs} +2 -2
- package/dist/defaultBlocks-DosClM5E.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +3 -3
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +1 -1
- package/src/api/exporters/html/internalHTMLSerializer.ts +146 -2
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +3 -0
- package/src/blocks/Code/block.ts +12 -8
- package/src/editor/Block.css +5 -1
- package/src/editor/editor.css +1 -0
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboard.ts +1 -0
- package/src/extensions/TableHandles/TableHandles.ts +6 -2
- package/src/schema/blocks/createSpec.ts +4 -2
- package/src/schema/blocks/types.ts +9 -0
- package/types/src/schema/blocks/types.d.ts +9 -3
- package/dist/TrailingNode-C-Kyrtf1.js.map +0 -1
- package/dist/TrailingNode-W7GJVng5.cjs +0 -2
- package/dist/TrailingNode-W7GJVng5.cjs.map +0 -1
- package/dist/defaultBlocks-CXOCngjC.js.map +0 -1
- package/dist/defaultBlocks-IsUGVZIq.cjs.map +0 -1
|
@@ -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-DE5GNdJH.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-BkXw8HJ6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNoteSchema-DsMVJZv4.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,CAAC;AAAA,IAAA;AAI9G,SAAOE;AACT;AAEO,SAASO,EAAgBC,GAAiC;AAC/D,QAAMd,IAAMe,EAAQD,CAAI;AACxB,SAAOf,EAASC,CAAG;AACrB;AAIA,SAASE,EAAeF,GAAsC;AAC5D,QAAMgB,wBAAwB,IAAA;AAE9B,aAAW,CAACC,GAAIR,CAAU,KAAKT,EAAI,WAAW;AAE5C,IA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.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,CAAC;AAAA,IAAA;AAI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;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,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-DosClM5E.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-DmFDeA0n.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNoteSchema-qt4Czo0-.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,OA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AAO,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
|
+
{"version":3,"file":"BlockNoteSchema-DmFDeA0n.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,E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OAAO,CACnB,WAAY,CACV,UAAWL,EAAA,CAAyB,CACtC,CACD,ECjEUM,EAAkC,MAC7CC,GACoB,CACpB,MAAMC,EAAO,IAAI,SACjB,OAAAA,EAAK,OAAO,OAAQD,CAAI,GAMhB,MAJI,MAAM,MAAM,qCAAsC,CAC5D,OAAQ,OACR,KAAAC,CAAA,CACD,GACiB,KAAA,GAAQ,KAAK,IAAI,QACjC,gBACA,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"}
|
|
@@ -5,7 +5,7 @@ import { Plugin as T, PluginKey as P, NodeSelection as le, TextSelection as ce,
|
|
|
5
5
|
import { combineTransactionSteps as Te, getMarkRange as Pe, posToDOMRect as Oe, findChildren as j } from "@tiptap/core";
|
|
6
6
|
import De from "fast-deep-equal";
|
|
7
7
|
import { i as q, t as Ae, U as Me, n as Ne, g as R, a as L, c as de, m as Re, e as ue, f as Le, h as Ve, j as He, k as Fe, l as $e, o as W, p as G } from "./blockToNode-BNoNIXU7.js";
|
|
8
|
-
import { ai as he, a2 as J, aj as me, $ as Ue, a1 as Q } from "./defaultBlocks-
|
|
8
|
+
import { ai as he, a2 as J, aj as me, $ as Ue, a1 as Q } from "./defaultBlocks-DE5GNdJH.js";
|
|
9
9
|
import { c as k, a as H } from "./BlockNoteExtension-C2X7LW-V.js";
|
|
10
10
|
import { yCursorPlugin as _e, defaultSelectionBuilder as ze, ySyncPlugin as Ke, redoCommand as Ye, undoCommand as Xe, yUndoPlugin as je, yUndoPluginKey as Z } from "y-prosemirror";
|
|
11
11
|
import * as I from "yjs";
|
|
@@ -99,22 +99,25 @@ function be(n, e, t, o) {
|
|
|
99
99
|
return i.childNodes.length === 1 && ((a = i.firstChild) == null ? void 0 : a.nodeType) === 1 && ye(i.firstChild), i;
|
|
100
100
|
}
|
|
101
101
|
function bt(n, e, t, o, r, s, i, a) {
|
|
102
|
-
var w, y,
|
|
102
|
+
var w, y, C, O, _, z, K, Y, X;
|
|
103
103
|
const c = (a == null ? void 0 : a.document) ?? document, l = e.pmSchema.nodes.blockContainer, u = t.props || {};
|
|
104
|
-
for (const [v,
|
|
104
|
+
for (const [v, x] of Object.entries(
|
|
105
105
|
e.schema.blockSchema[t.type].propSchema
|
|
106
106
|
))
|
|
107
|
-
!(v in u) &&
|
|
107
|
+
!(v in u) && x.default !== void 0 && (u[v] = x.default);
|
|
108
108
|
const h = (y = (w = l.spec) == null ? void 0 : w.toDOM) == null ? void 0 : y.call(
|
|
109
109
|
w,
|
|
110
110
|
l.create({
|
|
111
111
|
id: t.id,
|
|
112
112
|
...u
|
|
113
113
|
})
|
|
114
|
-
), g = Array.from(h.dom.attributes), m = e.blockImplementations[t.type].implementation, p = ((
|
|
114
|
+
), g = Array.from(h.dom.attributes), m = e.blockImplementations[t.type].implementation, p = ((C = m.toExternalHTML) == null ? void 0 : C.call(
|
|
115
115
|
{},
|
|
116
116
|
{ ...t, props: u },
|
|
117
|
-
e
|
|
117
|
+
e,
|
|
118
|
+
{
|
|
119
|
+
nestingLevel: i
|
|
120
|
+
}
|
|
118
121
|
)) || m.render.call(
|
|
119
122
|
{},
|
|
120
123
|
{ ...t, props: u },
|
|
@@ -125,10 +128,10 @@ function bt(n, e, t, o, r, s, i, a) {
|
|
|
125
128
|
...g,
|
|
126
129
|
...Array.from(p.dom.attributes)
|
|
127
130
|
].filter(
|
|
128
|
-
(
|
|
131
|
+
(x) => x.name.startsWith("data") && x.name !== "data-content-type" && x.name !== "data-file-block" && x.name !== "data-node-view-wrapper" && x.name !== "data-node-type" && x.name !== "data-id" && x.name !== "data-editable"
|
|
129
132
|
);
|
|
130
|
-
for (const
|
|
131
|
-
p.dom.firstChild.setAttribute(
|
|
133
|
+
for (const x of v)
|
|
134
|
+
p.dom.firstChild.setAttribute(x.name, x.value);
|
|
132
135
|
ye(p.dom.firstChild), i > 0 && p.dom.firstChild.setAttribute(
|
|
133
136
|
"data-nesting-level",
|
|
134
137
|
i.toString()
|
|
@@ -264,8 +267,8 @@ function St(n, e) {
|
|
|
264
267
|
const a = r.map((d) => i[d]), c = a.length, l = [], u = [], h = new Array(c).fill(-1), g = (d, f) => {
|
|
265
268
|
let w = 0, y = d.length;
|
|
266
269
|
for (; w < y; ) {
|
|
267
|
-
const
|
|
268
|
-
d[
|
|
270
|
+
const C = w + y >>> 1;
|
|
271
|
+
d[C] < f ? w = C + 1 : y = C;
|
|
269
272
|
}
|
|
270
273
|
return w;
|
|
271
274
|
};
|
|
@@ -334,14 +337,14 @@ function xt(n, e = []) {
|
|
|
334
337
|
l[m]
|
|
335
338
|
);
|
|
336
339
|
p.size !== 0 && p.forEach((d) => {
|
|
337
|
-
var
|
|
340
|
+
var C, O;
|
|
338
341
|
const f = r.byId[d], w = s.byId[d];
|
|
339
342
|
!f || !w || f.parentId !== w.parentId || a.has(d) || (f.parentId ?? u) !== m || g.has(d) || (g.add(d), i.push({
|
|
340
343
|
type: "move",
|
|
341
344
|
block: w.block,
|
|
342
345
|
prevBlock: f.block,
|
|
343
346
|
source: t,
|
|
344
|
-
prevParent: f.parentId ? (
|
|
347
|
+
prevParent: f.parentId ? (C = r.byId[f.parentId]) == null ? void 0 : C.block : void 0,
|
|
345
348
|
currentParent: w.parentId ? (O = s.byId[w.parentId]) == null ? void 0 : O.block : void 0
|
|
346
349
|
}), a.add(d));
|
|
347
350
|
});
|
|
@@ -768,7 +771,7 @@ const go = k(
|
|
|
768
771
|
return !1;
|
|
769
772
|
if (e.key.length === 1)
|
|
770
773
|
return e.preventDefault(), !0;
|
|
771
|
-
if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
774
|
+
if (e.key === "Enter" && !e.isComposing && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
772
775
|
const t = n.state.tr;
|
|
773
776
|
return n.dispatch(
|
|
774
777
|
t.insert(
|
|
@@ -1074,7 +1077,7 @@ class B extends N {
|
|
|
1074
1077
|
}
|
|
1075
1078
|
}
|
|
1076
1079
|
N.jsonID("multiple-node", B);
|
|
1077
|
-
let
|
|
1080
|
+
let E;
|
|
1078
1081
|
function Lt(n, e) {
|
|
1079
1082
|
let t, o;
|
|
1080
1083
|
const r = e.resolve(n.from).node().type.spec.group === "blockContent", s = e.resolve(n.to).node().type.spec.group === "blockContent", i = Math.min(n.$anchor.depth, n.$head.depth);
|
|
@@ -1098,8 +1101,8 @@ function re(n, e, t = e) {
|
|
|
1098
1101
|
);
|
|
1099
1102
|
for (let h = r.childElementCount - 1; h >= 0; h--)
|
|
1100
1103
|
(h > a || h < i) && o.removeChild(o.children[h]);
|
|
1101
|
-
Ee(n.root),
|
|
1102
|
-
const c =
|
|
1104
|
+
Ee(n.root), E = o;
|
|
1105
|
+
const c = E.getElementsByTagName("iframe");
|
|
1103
1106
|
for (let h = 0; h < c.length; h++) {
|
|
1104
1107
|
const g = c[h], m = g.parentElement;
|
|
1105
1108
|
m && m.removeChild(g);
|
|
@@ -1107,10 +1110,10 @@ function re(n, e, t = e) {
|
|
|
1107
1110
|
const u = n.dom.className.split(" ").filter(
|
|
1108
1111
|
(h) => h !== "ProseMirror" && h !== "bn-root" && h !== "bn-editor"
|
|
1109
1112
|
).join(" ");
|
|
1110
|
-
|
|
1113
|
+
E.className = E.className + " bn-drag-preview " + u, n.root instanceof ShadowRoot ? n.root.appendChild(E) : n.root.body.appendChild(E);
|
|
1111
1114
|
}
|
|
1112
1115
|
function Ee(n) {
|
|
1113
|
-
|
|
1116
|
+
E !== void 0 && (n instanceof ShadowRoot ? n.removeChild(E) : n.body.removeChild(E), E = void 0);
|
|
1114
1117
|
}
|
|
1115
1118
|
function Vt(n, e, t) {
|
|
1116
1119
|
if (!n.dataTransfer || t.headless)
|
|
@@ -1127,7 +1130,7 @@ function Vt(n, e, t) {
|
|
|
1127
1130
|
o.state.tr.setSelection(le.create(o.state.doc, s))
|
|
1128
1131
|
), re(o, s));
|
|
1129
1132
|
const g = o.state.selection.content(), m = t.pmSchema, p = o.serializeForClipboard(g).dom.innerHTML, d = ke(m, t), f = Rt(g.content), w = d.exportBlocks(f, {}), y = xe(w);
|
|
1130
|
-
n.dataTransfer.clearData(), n.dataTransfer.setData("blocknote/html", p), n.dataTransfer.setData("text/html", w), n.dataTransfer.setData("text/plain", y), n.dataTransfer.effectAllowed = "move", n.dataTransfer.setDragImage(
|
|
1133
|
+
n.dataTransfer.clearData(), n.dataTransfer.setData("blocknote/html", p), n.dataTransfer.setData("text/html", w), n.dataTransfer.setData("text/plain", y), n.dataTransfer.effectAllowed = "move", n.dataTransfer.setDragImage(E, 0, 0);
|
|
1131
1134
|
}
|
|
1132
1135
|
}
|
|
1133
1136
|
const se = 250;
|
|
@@ -1509,12 +1512,12 @@ const $t = new pe("SideMenuPlugin"), To = k(({ editor: n }) => {
|
|
|
1509
1512
|
}
|
|
1510
1513
|
};
|
|
1511
1514
|
});
|
|
1512
|
-
let
|
|
1515
|
+
let S;
|
|
1513
1516
|
function ie(n) {
|
|
1514
|
-
|
|
1517
|
+
S || (S = document.createElement("div"), S.innerHTML = "_", S.style.opacity = "0", S.style.height = "1px", S.style.width = "1px", n instanceof Document ? n.body.appendChild(S) : n.appendChild(S));
|
|
1515
1518
|
}
|
|
1516
1519
|
function Ut(n) {
|
|
1517
|
-
|
|
1520
|
+
S && (n instanceof Document ? n.body.removeChild(S) : n.removeChild(S), S = void 0);
|
|
1518
1521
|
}
|
|
1519
1522
|
function M(n) {
|
|
1520
1523
|
return Array.prototype.indexOf.call(n.parentElement.childNodes, n);
|
|
@@ -1561,7 +1564,7 @@ class Kt {
|
|
|
1561
1564
|
this.mouseState = "up", this.mouseMoveHandler(e);
|
|
1562
1565
|
});
|
|
1563
1566
|
b(this, "mouseMoveHandler", (e) => {
|
|
1564
|
-
var l, u, h, g, m, p, d;
|
|
1567
|
+
var l, u, h, g, m, p, d, f;
|
|
1565
1568
|
if (this.menuFrozen || this.mouseState === "selecting" || !(e.target instanceof Element) || !this.pmView.dom.contains(e.target))
|
|
1566
1569
|
return;
|
|
1567
1570
|
const t = _t(e.target);
|
|
@@ -1581,7 +1584,7 @@ class Kt {
|
|
|
1581
1584
|
this.tableElement = r.node;
|
|
1582
1585
|
let s;
|
|
1583
1586
|
const i = this.editor.transact(
|
|
1584
|
-
(
|
|
1587
|
+
(w) => me(r.id, w.doc)
|
|
1585
1588
|
);
|
|
1586
1589
|
if (!i)
|
|
1587
1590
|
throw new Error(`Block with ID ${r.id} not found`);
|
|
@@ -1597,34 +1600,39 @@ class Kt {
|
|
|
1597
1600
|
this.tableId = r.id;
|
|
1598
1601
|
const c = (g = t.domNode.closest(".tableWrapper")) == null ? void 0 : g.querySelector(".table-widgets-container");
|
|
1599
1602
|
if ((t == null ? void 0 : t.type) === "wrapper") {
|
|
1600
|
-
const
|
|
1601
|
-
e.clientY < o.bottom + 20,
|
|
1603
|
+
const w = e.clientY >= o.bottom - 1 && // -1 to account for fractions of pixels in "bottom"
|
|
1604
|
+
e.clientY < o.bottom + 20, y = e.clientX >= o.right - 1 && e.clientX < o.right + 20, C = (
|
|
1605
|
+
// always hide handles when the actively hovered table changed
|
|
1606
|
+
((m = this.state) == null ? void 0 : m.block.id) !== s.id || // make sure we don't hide existing handles (keep col / row index) when
|
|
1607
|
+
// we're hovering just above or to the right of a table
|
|
1608
|
+
e.clientX > o.right || e.clientY > o.bottom
|
|
1609
|
+
);
|
|
1602
1610
|
this.state = {
|
|
1603
1611
|
...this.state,
|
|
1604
1612
|
show: !0,
|
|
1605
|
-
showAddOrRemoveRowsButton:
|
|
1606
|
-
showAddOrRemoveColumnsButton:
|
|
1613
|
+
showAddOrRemoveRowsButton: w,
|
|
1614
|
+
showAddOrRemoveColumnsButton: y,
|
|
1607
1615
|
referencePosTable: o,
|
|
1608
1616
|
block: s,
|
|
1609
1617
|
widgetContainer: c,
|
|
1610
|
-
colIndex:
|
|
1611
|
-
rowIndex:
|
|
1612
|
-
referencePosCell:
|
|
1618
|
+
colIndex: C || (p = this.state) == null ? void 0 : p.colIndex,
|
|
1619
|
+
rowIndex: C || (d = this.state) == null ? void 0 : d.rowIndex,
|
|
1620
|
+
referencePosCell: C || (f = this.state) == null ? void 0 : f.referencePosCell
|
|
1613
1621
|
};
|
|
1614
1622
|
} else {
|
|
1615
|
-
const
|
|
1616
|
-
if (this.state !== void 0 && this.state.show && this.tableId === r.id && this.state.rowIndex ===
|
|
1623
|
+
const w = M(t.domNode), y = M(t.domNode.parentElement), C = t.domNode.getBoundingClientRect();
|
|
1624
|
+
if (this.state !== void 0 && this.state.show && this.tableId === r.id && this.state.rowIndex === y && this.state.colIndex === w)
|
|
1617
1625
|
return;
|
|
1618
1626
|
this.state = {
|
|
1619
1627
|
show: !0,
|
|
1620
|
-
showAddOrRemoveColumnsButton:
|
|
1621
|
-
showAddOrRemoveRowsButton:
|
|
1628
|
+
showAddOrRemoveColumnsButton: w === s.content.rows[0].cells.length - 1,
|
|
1629
|
+
showAddOrRemoveRowsButton: y === s.content.rows.length - 1,
|
|
1622
1630
|
referencePosTable: o,
|
|
1623
1631
|
block: s,
|
|
1624
1632
|
draggingState: void 0,
|
|
1625
|
-
referencePosCell:
|
|
1626
|
-
colIndex:
|
|
1627
|
-
rowIndex:
|
|
1633
|
+
referencePosCell: C,
|
|
1634
|
+
colIndex: w,
|
|
1635
|
+
rowIndex: y,
|
|
1628
1636
|
widgetContainer: c
|
|
1629
1637
|
};
|
|
1630
1638
|
}
|
|
@@ -1845,7 +1853,7 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => {
|
|
|
1845
1853
|
newIndex: e.state.colIndex,
|
|
1846
1854
|
tablePos: e.tablePos
|
|
1847
1855
|
})
|
|
1848
|
-
), !n.headless && (ie(n.prosemirrorView.root), o.dataTransfer.setDragImage(
|
|
1856
|
+
), !n.headless && (ie(n.prosemirrorView.root), o.dataTransfer.setDragImage(S, 0, 0), o.dataTransfer.effectAllowed = "move");
|
|
1849
1857
|
},
|
|
1850
1858
|
/**
|
|
1851
1859
|
* Callback that should be set on the `dragStart` event for whichever element
|
|
@@ -1867,7 +1875,7 @@ const D = new P("TableHandlesPlugin"), Po = k(({ editor: n }) => {
|
|
|
1867
1875
|
newIndex: e.state.rowIndex,
|
|
1868
1876
|
tablePos: e.tablePos
|
|
1869
1877
|
})
|
|
1870
|
-
), !n.headless && (ie(n.prosemirrorView.root), o.dataTransfer.setDragImage(
|
|
1878
|
+
), !n.headless && (ie(n.prosemirrorView.root), o.dataTransfer.setDragImage(S, 0, 0), o.dataTransfer.effectAllowed = "copyMove");
|
|
1871
1879
|
},
|
|
1872
1880
|
/**
|
|
1873
1881
|
* Callback that should be set on the `dragEnd` event for both the element
|
|
@@ -2101,4 +2109,4 @@ export {
|
|
|
2101
2109
|
$t as s,
|
|
2102
2110
|
D as t
|
|
2103
2111
|
};
|
|
2104
|
-
//# sourceMappingURL=TrailingNode-
|
|
2112
|
+
//# sourceMappingURL=TrailingNode-CxM966vN.js.map
|