From 9ae58f6a2f255462e7adc2c18d2e3ebd34a80b4b Mon Sep 17 00:00:00 2001 From: yousefed Date: Tue, 15 Oct 2024 07:01:36 +0200 Subject: [PATCH 1/2] clean nodeconversions --- .../commands/insertBlocks/insertBlocks.ts | 7 +- .../commands/removeBlocks/removeBlocks.ts | 4 +- .../commands/replaceBlocks/replaceBlocks.ts | 13 +- .../commands/updateBlock/updateBlock.ts | 5 +- .../textCursorPosition/textCursorPosition.ts | 2 +- .../clipboard/toClipboard/copyExtension.ts | 2 +- .../html/util/sharedHTMLConversion.ts | 2 +- .../src/api/nodeConversions/blockToNode.ts | 257 ++++++++++++++++++ .../api/nodeConversions/fragmentToBlocks.ts | 2 +- .../nodeConversions/nodeConversions.test.ts | 3 +- .../{nodeConversions.ts => nodeToBlock.ts} | 247 +---------------- .../core/src/api/parsers/html/parseHTML.ts | 2 +- .../core/src/blocks/defaultBlockHelpers.ts | 2 +- packages/core/src/editor/BlockNoteEditor.ts | 7 +- .../core/src/editor/BlockNoteTipTapEditor.ts | 2 +- .../TableHandles/TableHandlesPlugin.ts | 2 +- packages/core/src/index.ts | 3 +- .../src/schema/inlineContent/createSpec.ts | 6 +- 18 files changed, 290 insertions(+), 278 deletions(-) create mode 100644 packages/core/src/api/nodeConversions/blockToNode.ts rename packages/core/src/api/nodeConversions/{nodeConversions.ts => nodeToBlock.ts} (61%) diff --git a/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts b/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts index b63a1439d..0ae26fa40 100644 --- a/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +++ b/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts @@ -8,10 +8,9 @@ import { InlineContentSchema, StyleSchema, } from "../../../../schema/index.js"; -import { - blockToNode, - nodeToBlock, -} from "../../../nodeConversions/nodeConversions.js"; + +import { blockToNode } from "../../../nodeConversions/blockToNode.js"; +import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { getNodeById } from "../../../nodeUtil.js"; export function insertBlocks< diff --git a/packages/core/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts b/packages/core/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts index d38ea3622..550e20ecc 100644 --- a/packages/core/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +++ b/packages/core/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts @@ -1,15 +1,15 @@ import { Node } from "prosemirror-model"; import { Transaction } from "prosemirror-state"; -import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor"; import { Block } from "../../../../blocks/defaultBlocks.js"; +import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor"; import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema, } from "../../../../schema/index.js"; -import { nodeToBlock } from "../../../nodeConversions/nodeConversions.js"; +import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; export function removeBlocksWithCallback< BSchema extends BlockSchema, diff --git a/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts b/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts index bf81b6bce..27123b9b6 100644 --- a/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +++ b/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts @@ -1,16 +1,15 @@ +import { Node } from "prosemirror-model"; +import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js"; +import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor"; import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema, } from "../../../../schema/index.js"; -import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js"; -import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor"; -import { Node } from "prosemirror-model"; -import { - blockToNode, - nodeToBlock, -} from "../../../nodeConversions/nodeConversions.js"; + +import { blockToNode } from "../../../nodeConversions/blockToNode.js"; +import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { removeBlocksWithCallback } from "../removeBlocks/removeBlocks.js"; export function replaceBlocks< diff --git a/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts b/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts index ab1a9c89c..112ee8a61 100644 --- a/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +++ b/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts @@ -11,12 +11,13 @@ import { InlineContentSchema } from "../../../../schema/inlineContent/types.js"; import { StyleSchema } from "../../../../schema/styles/types.js"; import { UnreachableCaseError } from "../../../../util/typescript.js"; import { getBlockInfoFromResolvedPos } from "../../../getBlockInfoFromPos.js"; + import { blockToNode, inlineContentToNodes, - nodeToBlock, tableContentToNodes, -} from "../../../nodeConversions/nodeConversions.js"; +} from "../../../nodeConversions/blockToNode.js"; +import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { getNodeById } from "../../../nodeUtil.js"; export const updateBlockCommand = diff --git a/packages/core/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts b/packages/core/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts index c397c2d87..d7237b0b2 100644 --- a/packages/core/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +++ b/packages/core/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts @@ -13,7 +13,7 @@ import { getBlockInfo, getBlockInfoFromSelection, } from "../../../getBlockInfoFromPos.js"; -import { nodeToBlock } from "../../../nodeConversions/nodeConversions.js"; +import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { getNodeById } from "../../../nodeUtil.js"; export function getTextCursorPosition< diff --git a/packages/core/src/api/clipboard/toClipboard/copyExtension.ts b/packages/core/src/api/clipboard/toClipboard/copyExtension.ts index 14d7fbad1..14df07902 100644 --- a/packages/core/src/api/clipboard/toClipboard/copyExtension.ts +++ b/packages/core/src/api/clipboard/toClipboard/copyExtension.ts @@ -18,7 +18,7 @@ import { fragmentToBlocks } from "../../nodeConversions/fragmentToBlocks.js"; import { contentNodeToInlineContent, contentNodeToTableContent, -} from "../../nodeConversions/nodeConversions.js"; +} from "../../nodeConversions/nodeToBlock.js"; async function fragmentToExternalHTML< BSchema extends BlockSchema, diff --git a/packages/core/src/api/exporters/html/util/sharedHTMLConversion.ts b/packages/core/src/api/exporters/html/util/sharedHTMLConversion.ts index 62e89a14a..ac8ff29f1 100644 --- a/packages/core/src/api/exporters/html/util/sharedHTMLConversion.ts +++ b/packages/core/src/api/exporters/html/util/sharedHTMLConversion.ts @@ -11,7 +11,7 @@ import { UnreachableCaseError } from "../../../../util/typescript.js"; import { inlineContentToNodes, tableContentToNodes, -} from "../../../nodeConversions/nodeConversions.js"; +} from "../../../nodeConversions/blockToNode.js"; export function serializeInlineContent< BSchema extends BlockSchema, diff --git a/packages/core/src/api/nodeConversions/blockToNode.ts b/packages/core/src/api/nodeConversions/blockToNode.ts new file mode 100644 index 000000000..f63ee0997 --- /dev/null +++ b/packages/core/src/api/nodeConversions/blockToNode.ts @@ -0,0 +1,257 @@ +import { Mark, Node, Schema } from "@tiptap/pm/model"; + +import UniqueID from "../../extensions/UniqueID/UniqueID.js"; +import type { + InlineContentSchema, + PartialCustomInlineContentFromConfig, + PartialInlineContent, + PartialLink, + PartialTableContent, + StyleSchema, + StyledText, +} from "../../schema"; + +import type { PartialBlock } from "../../blocks/defaultBlocks"; +import { + isPartialLinkInlineContent, + isStyledTextInlineContent, +} from "../../schema/inlineContent/types.js"; +import { UnreachableCaseError } from "../../util/typescript.js"; + +/** + * Convert a StyledText inline element to a + * prosemirror text node with the appropriate marks + */ +function styledTextToNodes( + styledText: StyledText, + schema: Schema, + styleSchema: T +): Node[] { + const marks: Mark[] = []; + + for (const [style, value] of Object.entries(styledText.styles)) { + const config = styleSchema[style]; + if (!config) { + throw new Error(`style ${style} not found in styleSchema`); + } + + if (config.propSchema === "boolean") { + marks.push(schema.mark(style)); + } else if (config.propSchema === "string") { + marks.push(schema.mark(style, { stringValue: value })); + } else { + throw new UnreachableCaseError(config.propSchema); + } + } + + return ( + styledText.text + // Splits text & line breaks. + .split(/(\n)/g) + // If the content ends with a line break, an empty string is added to the + // end, which this removes. + .filter((text) => text.length > 0) + // Converts text & line breaks to nodes. + .map((text) => { + if (text === "\n") { + return schema.nodes["hardBreak"].create(); + } else { + return schema.text(text, marks); + } + }) + ); +} + +/** + * Converts a Link inline content element to + * prosemirror text nodes with the appropriate marks + */ +function linkToNodes( + link: PartialLink, + schema: Schema, + styleSchema: StyleSchema +): Node[] { + const linkMark = schema.marks.link.create({ + href: link.href, + }); + + return styledTextArrayToNodes(link.content, schema, styleSchema).map( + (node) => { + if (node.type.name === "text") { + return node.mark([...node.marks, linkMark]); + } + + if (node.type.name === "hardBreak") { + return node; + } + throw new Error("unexpected node type"); + } + ); +} + +/** + * Converts an array of StyledText inline content elements to + * prosemirror text nodes with the appropriate marks + */ +function styledTextArrayToNodes( + content: string | StyledText[], + schema: Schema, + styleSchema: S +): Node[] { + const nodes: Node[] = []; + + if (typeof content === "string") { + nodes.push( + ...styledTextToNodes( + { type: "text", text: content, styles: {} }, + schema, + styleSchema + ) + ); + return nodes; + } + + for (const styledText of content) { + nodes.push(...styledTextToNodes(styledText, schema, styleSchema)); + } + return nodes; +} + +/** + * converts an array of inline content elements to prosemirror nodes + */ +export function inlineContentToNodes< + I extends InlineContentSchema, + S extends StyleSchema +>( + blockContent: PartialInlineContent, + schema: Schema, + styleSchema: S +): Node[] { + const nodes: Node[] = []; + + for (const content of blockContent) { + if (typeof content === "string") { + nodes.push(...styledTextArrayToNodes(content, schema, styleSchema)); + } else if (isPartialLinkInlineContent(content)) { + nodes.push(...linkToNodes(content, schema, styleSchema)); + } else if (isStyledTextInlineContent(content)) { + nodes.push(...styledTextArrayToNodes([content], schema, styleSchema)); + } else { + nodes.push( + blockOrInlineContentToContentNode(content, schema, styleSchema) + ); + } + } + return nodes; +} + +/** + * converts an array of inline content elements to prosemirror nodes + */ +export function tableContentToNodes< + I extends InlineContentSchema, + S extends StyleSchema +>( + tableContent: PartialTableContent, + schema: Schema, + styleSchema: StyleSchema +): Node[] { + const rowNodes: Node[] = []; + + for (const row of tableContent.rows) { + const columnNodes: Node[] = []; + for (const cell of row.cells) { + let pNode: Node; + if (!cell) { + pNode = schema.nodes["tableParagraph"].create({}); + } else if (typeof cell === "string") { + pNode = schema.nodes["tableParagraph"].create({}, schema.text(cell)); + } else { + const textNodes = inlineContentToNodes(cell, schema, styleSchema); + pNode = schema.nodes["tableParagraph"].create({}, textNodes); + } + + const cellNode = schema.nodes["tableCell"].create({}, pNode); + columnNodes.push(cellNode); + } + const rowNode = schema.nodes["tableRow"].create({}, columnNodes); + rowNodes.push(rowNode); + } + return rowNodes; +} + +function blockOrInlineContentToContentNode( + block: + | PartialBlock + | PartialCustomInlineContentFromConfig, + schema: Schema, + styleSchema: StyleSchema +) { + let contentNode: Node; + let type = block.type; + + // TODO: needed? came from previous code + if (type === undefined) { + type = "paragraph"; + } + + if (!schema.nodes[type]) { + throw new Error(`node type ${type} not found in schema`); + } + + if (!block.content) { + contentNode = schema.nodes[type].create(block.props); + } else if (typeof block.content === "string") { + const nodes = inlineContentToNodes([block.content], schema, styleSchema); + contentNode = schema.nodes[type].create(block.props, nodes); + } else if (Array.isArray(block.content)) { + const nodes = inlineContentToNodes(block.content, schema, styleSchema); + contentNode = schema.nodes[type].create(block.props, nodes); + } else if (block.content.type === "tableContent") { + const nodes = tableContentToNodes(block.content, schema, styleSchema); + contentNode = schema.nodes[type].create(block.props, nodes); + } else { + throw new UnreachableCaseError(block.content.type); + } + return contentNode; +} + +/** + * Converts a BlockNote block to a TipTap node. + */ +export function blockToNode( + block: PartialBlock, + schema: Schema, + styleSchema: StyleSchema +) { + let id = block.id; + + if (id === undefined) { + id = UniqueID.options.generateID(); + } + + const contentNode = blockOrInlineContentToContentNode( + block, + schema, + styleSchema + ); + + const children: Node[] = []; + + if (block.children) { + for (const child of block.children) { + children.push(blockToNode(child, schema, styleSchema)); + } + } + + const groupNode = schema.nodes["blockGroup"].create({}, children); + + return schema.nodes["blockContainer"].create( + { + id: id, + ...block.props, + }, + children.length > 0 ? [contentNode, groupNode] : contentNode + ); +} diff --git a/packages/core/src/api/nodeConversions/fragmentToBlocks.ts b/packages/core/src/api/nodeConversions/fragmentToBlocks.ts index dcbfeeb8b..8b0cd2103 100644 --- a/packages/core/src/api/nodeConversions/fragmentToBlocks.ts +++ b/packages/core/src/api/nodeConversions/fragmentToBlocks.ts @@ -6,7 +6,7 @@ import { InlineContentSchema, StyleSchema, } from "../../schema/index.js"; -import { nodeToBlock } from "./nodeConversions.js"; +import { nodeToBlock } from "./nodeToBlock.js"; /** * Converts all Blocks within a fragment to BlockNote blocks. diff --git a/packages/core/src/api/nodeConversions/nodeConversions.test.ts b/packages/core/src/api/nodeConversions/nodeConversions.test.ts index b2a84c931..b196af924 100644 --- a/packages/core/src/api/nodeConversions/nodeConversions.test.ts +++ b/packages/core/src/api/nodeConversions/nodeConversions.test.ts @@ -11,7 +11,8 @@ import { addIdsToBlock, partialBlockToBlockForTesting, } from "../testUtil/partialBlockTestUtil.js"; -import { blockToNode, nodeToBlock } from "./nodeConversions.js"; +import { blockToNode } from "./blockToNode.js"; +import { nodeToBlock } from "./nodeToBlock.js"; function validateConversion( block: PartialBlock, diff --git a/packages/core/src/api/nodeConversions/nodeConversions.ts b/packages/core/src/api/nodeConversions/nodeToBlock.ts similarity index 61% rename from packages/core/src/api/nodeConversions/nodeConversions.ts rename to packages/core/src/api/nodeConversions/nodeToBlock.ts index 5978cc6bf..55cfa045a 100644 --- a/packages/core/src/api/nodeConversions/nodeConversions.ts +++ b/packages/core/src/api/nodeConversions/nodeToBlock.ts @@ -1,4 +1,4 @@ -import { Mark, Node, Schema } from "@tiptap/pm/model"; +import { Mark, Node } from "@tiptap/pm/model"; import UniqueID from "../../extensions/UniqueID/UniqueID.js"; import type { @@ -8,262 +8,19 @@ import type { InlineContent, InlineContentFromConfig, InlineContentSchema, - PartialCustomInlineContentFromConfig, - PartialInlineContent, - PartialLink, - PartialTableContent, StyleSchema, - StyledText, Styles, TableContent, } from "../../schema/index.js"; import { getBlockInfoWithManualOffset } from "../getBlockInfoFromPos.js"; -import type { Block, PartialBlock } from "../../blocks/defaultBlocks.js"; +import type { Block } from "../../blocks/defaultBlocks.js"; import { isLinkInlineContent, - isPartialLinkInlineContent, isStyledTextInlineContent, } from "../../schema/inlineContent/types.js"; import { UnreachableCaseError } from "../../util/typescript.js"; -/** - * Convert a StyledText inline element to a - * prosemirror text node with the appropriate marks - */ -function styledTextToNodes( - styledText: StyledText, - schema: Schema, - styleSchema: T -): Node[] { - const marks: Mark[] = []; - - for (const [style, value] of Object.entries(styledText.styles)) { - const config = styleSchema[style]; - if (!config) { - throw new Error(`style ${style} not found in styleSchema`); - } - - if (config.propSchema === "boolean") { - marks.push(schema.mark(style)); - } else if (config.propSchema === "string") { - marks.push(schema.mark(style, { stringValue: value })); - } else { - throw new UnreachableCaseError(config.propSchema); - } - } - - return ( - styledText.text - // Splits text & line breaks. - .split(/(\n)/g) - // If the content ends with a line break, an empty string is added to the - // end, which this removes. - .filter((text) => text.length > 0) - // Converts text & line breaks to nodes. - .map((text) => { - if (text === "\n") { - return schema.nodes["hardBreak"].create(); - } else { - return schema.text(text, marks); - } - }) - ); -} - -/** - * Converts a Link inline content element to - * prosemirror text nodes with the appropriate marks - */ -function linkToNodes( - link: PartialLink, - schema: Schema, - styleSchema: StyleSchema -): Node[] { - const linkMark = schema.marks.link.create({ - href: link.href, - }); - - return styledTextArrayToNodes(link.content, schema, styleSchema).map( - (node) => { - if (node.type.name === "text") { - return node.mark([...node.marks, linkMark]); - } - - if (node.type.name === "hardBreak") { - return node; - } - throw new Error("unexpected node type"); - } - ); -} - -/** - * Converts an array of StyledText inline content elements to - * prosemirror text nodes with the appropriate marks - */ -function styledTextArrayToNodes( - content: string | StyledText[], - schema: Schema, - styleSchema: S -): Node[] { - const nodes: Node[] = []; - - if (typeof content === "string") { - nodes.push( - ...styledTextToNodes( - { type: "text", text: content, styles: {} }, - schema, - styleSchema - ) - ); - return nodes; - } - - for (const styledText of content) { - nodes.push(...styledTextToNodes(styledText, schema, styleSchema)); - } - return nodes; -} - -/** - * converts an array of inline content elements to prosemirror nodes - */ -export function inlineContentToNodes< - I extends InlineContentSchema, - S extends StyleSchema ->( - blockContent: PartialInlineContent, - schema: Schema, - styleSchema: S -): Node[] { - const nodes: Node[] = []; - - for (const content of blockContent) { - if (typeof content === "string") { - nodes.push(...styledTextArrayToNodes(content, schema, styleSchema)); - } else if (isPartialLinkInlineContent(content)) { - nodes.push(...linkToNodes(content, schema, styleSchema)); - } else if (isStyledTextInlineContent(content)) { - nodes.push(...styledTextArrayToNodes([content], schema, styleSchema)); - } else { - nodes.push( - blockOrInlineContentToContentNode(content, schema, styleSchema) - ); - } - } - return nodes; -} - -/** - * converts an array of inline content elements to prosemirror nodes - */ -export function tableContentToNodes< - I extends InlineContentSchema, - S extends StyleSchema ->( - tableContent: PartialTableContent, - schema: Schema, - styleSchema: StyleSchema -): Node[] { - const rowNodes: Node[] = []; - - for (const row of tableContent.rows) { - const columnNodes: Node[] = []; - for (const cell of row.cells) { - let pNode: Node; - if (!cell) { - pNode = schema.nodes["tableParagraph"].create({}); - } else if (typeof cell === "string") { - pNode = schema.nodes["tableParagraph"].create({}, schema.text(cell)); - } else { - const textNodes = inlineContentToNodes(cell, schema, styleSchema); - pNode = schema.nodes["tableParagraph"].create({}, textNodes); - } - - const cellNode = schema.nodes["tableCell"].create({}, pNode); - columnNodes.push(cellNode); - } - const rowNode = schema.nodes["tableRow"].create({}, columnNodes); - rowNodes.push(rowNode); - } - return rowNodes; -} - -export function blockOrInlineContentToContentNode( - block: - | PartialBlock - | PartialCustomInlineContentFromConfig, - schema: Schema, - styleSchema: StyleSchema -) { - let contentNode: Node; - let type = block.type; - - // TODO: needed? came from previous code - if (type === undefined) { - type = "paragraph"; - } - - if (!schema.nodes[type]) { - throw new Error(`node type ${type} not found in schema`); - } - - if (!block.content) { - contentNode = schema.nodes[type].create(block.props); - } else if (typeof block.content === "string") { - const nodes = inlineContentToNodes([block.content], schema, styleSchema); - contentNode = schema.nodes[type].create(block.props, nodes); - } else if (Array.isArray(block.content)) { - const nodes = inlineContentToNodes(block.content, schema, styleSchema); - contentNode = schema.nodes[type].create(block.props, nodes); - } else if (block.content.type === "tableContent") { - const nodes = tableContentToNodes(block.content, schema, styleSchema); - contentNode = schema.nodes[type].create(block.props, nodes); - } else { - throw new UnreachableCaseError(block.content.type); - } - return contentNode; -} -/** - * Converts a BlockNote block to a TipTap node. - */ -export function blockToNode( - block: PartialBlock, - schema: Schema, - styleSchema: StyleSchema -) { - let id = block.id; - - if (id === undefined) { - id = UniqueID.options.generateID(); - } - - const contentNode = blockOrInlineContentToContentNode( - block, - schema, - styleSchema - ); - - const children: Node[] = []; - - if (block.children) { - for (const child of block.children) { - children.push(blockToNode(child, schema, styleSchema)); - } - } - - const groupNode = schema.nodes["blockGroup"].create({}, children); - - return schema.nodes["blockContainer"].create( - { - id: id, - ...block.props, - }, - children.length > 0 ? [contentNode, groupNode] : contentNode - ); -} - /** * Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent */ diff --git a/packages/core/src/api/parsers/html/parseHTML.ts b/packages/core/src/api/parsers/html/parseHTML.ts index 24852c47e..04f8b0f02 100644 --- a/packages/core/src/api/parsers/html/parseHTML.ts +++ b/packages/core/src/api/parsers/html/parseHTML.ts @@ -6,7 +6,7 @@ import { } from "../../../schema/index.js"; import { Block } from "../../../blocks/defaultBlocks.js"; -import { nodeToBlock } from "../../nodeConversions/nodeConversions.js"; +import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js"; import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js"; export async function HTMLToBlocks< BSchema extends BlockSchema, diff --git a/packages/core/src/blocks/defaultBlockHelpers.ts b/packages/core/src/blocks/defaultBlockHelpers.ts index 1c5cbcae7..4e758bd16 100644 --- a/packages/core/src/blocks/defaultBlockHelpers.ts +++ b/packages/core/src/blocks/defaultBlockHelpers.ts @@ -1,4 +1,4 @@ -import { blockToNode } from "../api/nodeConversions/nodeConversions.js"; +import { blockToNode } from "../api/nodeConversions/blockToNode.js"; import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js"; import type { BlockNoDefaults, diff --git a/packages/core/src/editor/BlockNoteEditor.ts b/packages/core/src/editor/BlockNoteEditor.ts index 155665135..f30004d6e 100644 --- a/packages/core/src/editor/BlockNoteEditor.ts +++ b/packages/core/src/editor/BlockNoteEditor.ts @@ -18,10 +18,7 @@ import { import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js"; import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js"; import { getBlockInfoFromSelection } from "../api/getBlockInfoFromPos.js"; -import { - inlineContentToNodes, - nodeToBlock, -} from "../api/nodeConversions/nodeConversions.js"; + import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js"; import { markdownToBlocks } from "../api/parsers/markdown/parseMarkdown.js"; import { @@ -72,6 +69,8 @@ import { en } from "../i18n/locales/index.js"; import { Transaction } from "@tiptap/pm/state"; import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js"; +import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js"; +import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js"; import { NodeSelectionKeyboardPlugin } from "../extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js"; import { PreviousBlockTypePlugin } from "../extensions/PreviousBlockType/PreviousBlockTypePlugin.js"; import "../style.css"; diff --git a/packages/core/src/editor/BlockNoteTipTapEditor.ts b/packages/core/src/editor/BlockNoteTipTapEditor.ts index 22aa626f1..fab4469e1 100644 --- a/packages/core/src/editor/BlockNoteTipTapEditor.ts +++ b/packages/core/src/editor/BlockNoteTipTapEditor.ts @@ -7,7 +7,7 @@ import { Node } from "@tiptap/pm/model"; import { EditorView } from "@tiptap/pm/view"; import { EditorState, Transaction } from "@tiptap/pm/state"; -import { blockToNode } from "../api/nodeConversions/nodeConversions.js"; +import { blockToNode } from "../api/nodeConversions/blockToNode.js"; import { PartialBlock } from "../blocks/defaultBlocks.js"; import { StyleSchema } from "../schema/index.js"; diff --git a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts index 9b7b65062..77af68523 100644 --- a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts +++ b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts @@ -1,6 +1,6 @@ import { Plugin, PluginKey, PluginView } from "prosemirror-state"; import { Decoration, DecorationSet, EditorView } from "prosemirror-view"; -import { nodeToBlock } from "../../api/nodeConversions/nodeConversions.js"; +import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js"; import { checkBlockIsDefaultType } from "../../blocks/defaultBlockTypeGuards.js"; import { Block, DefaultBlockSchema } from "../../blocks/defaultBlocks.js"; import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js"; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index da6ddc9f0..ae98dff89 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -39,7 +39,8 @@ export { UnreachableCaseError, assertEmpty } from "./util/typescript.js"; export { locales }; // for testing from react (TODO: move): -export * from "./api/nodeConversions/nodeConversions.js"; +export * from "./api/nodeConversions/blockToNode.js"; +export * from "./api/nodeConversions/nodeToBlock.js"; export * from "./api/testUtil/partialBlockTestUtil.js"; export * from "./extensions/UniqueID/UniqueID.js"; diff --git a/packages/core/src/schema/inlineContent/createSpec.ts b/packages/core/src/schema/inlineContent/createSpec.ts index e8f13540b..ba37d8904 100644 --- a/packages/core/src/schema/inlineContent/createSpec.ts +++ b/packages/core/src/schema/inlineContent/createSpec.ts @@ -1,10 +1,8 @@ import { Node } from "@tiptap/core"; import { TagParseRule } from "@tiptap/pm/model"; -import { - inlineContentToNodes, - nodeToCustomInlineContent, -} from "../../api/nodeConversions/nodeConversions.js"; +import { inlineContentToNodes } from "../../api/nodeConversions/blockToNode.js"; +import { nodeToCustomInlineContent } from "../../api/nodeConversions/nodeToBlock.js"; import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js"; import { propsToAttributes } from "../blocks/internal.js"; import { Props } from "../propTypes.js"; From 3d0e80ea7e77f91efcfa86413bbec0d720ddd5e8 Mon Sep 17 00:00:00 2001 From: matthewlipski Date: Wed, 16 Oct 2024 18:24:48 +0200 Subject: [PATCH 2/2] Tiny changes --- .../api/blockManipulation/commands/insertBlocks/insertBlocks.ts | 1 - .../blockManipulation/commands/replaceBlocks/replaceBlocks.ts | 2 +- .../api/blockManipulation/commands/updateBlock/updateBlock.ts | 1 - packages/core/src/editor/BlockNoteEditor.ts | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts b/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts index 0ae26fa40..66474cef0 100644 --- a/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +++ b/packages/core/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts @@ -8,7 +8,6 @@ import { InlineContentSchema, StyleSchema, } from "../../../../schema/index.js"; - import { blockToNode } from "../../../nodeConversions/blockToNode.js"; import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { getNodeById } from "../../../nodeUtil.js"; diff --git a/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts b/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts index 27123b9b6..536c8b5d8 100644 --- a/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +++ b/packages/core/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts @@ -1,4 +1,5 @@ import { Node } from "prosemirror-model"; + import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js"; import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor"; import { @@ -7,7 +8,6 @@ import { InlineContentSchema, StyleSchema, } from "../../../../schema/index.js"; - import { blockToNode } from "../../../nodeConversions/blockToNode.js"; import { nodeToBlock } from "../../../nodeConversions/nodeToBlock.js"; import { removeBlocksWithCallback } from "../removeBlocks/removeBlocks.js"; diff --git a/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts b/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts index 112ee8a61..9536e6a9a 100644 --- a/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +++ b/packages/core/src/api/blockManipulation/commands/updateBlock/updateBlock.ts @@ -11,7 +11,6 @@ import { InlineContentSchema } from "../../../../schema/inlineContent/types.js"; import { StyleSchema } from "../../../../schema/styles/types.js"; import { UnreachableCaseError } from "../../../../util/typescript.js"; import { getBlockInfoFromResolvedPos } from "../../../getBlockInfoFromPos.js"; - import { blockToNode, inlineContentToNodes, diff --git a/packages/core/src/editor/BlockNoteEditor.ts b/packages/core/src/editor/BlockNoteEditor.ts index f30004d6e..0b16a2cb4 100644 --- a/packages/core/src/editor/BlockNoteEditor.ts +++ b/packages/core/src/editor/BlockNoteEditor.ts @@ -18,7 +18,6 @@ import { import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js"; import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js"; import { getBlockInfoFromSelection } from "../api/getBlockInfoFromPos.js"; - import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js"; import { markdownToBlocks } from "../api/parsers/markdown/parseMarkdown.js"; import {