New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@platejs/code-block

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@platejs/code-block - npm Package Compare versions

Comparing version
51.0.0
to
51.1.2
+6
-6
dist/index.d.mts

@@ -68,7 +68,7 @@ import * as platejs from 'platejs';

interface IndentCodeLineOptions {
type IndentCodeLineOptions = {
codeBlock: ElementEntry;
codeLine: ElementEntry;
indentDepth?: number;
}
};
/**

@@ -91,6 +91,6 @@ * Indent if:

interface OutdentCodeLineOptions {
type OutdentCodeLineOptions = {
codeBlock: ElementEntry;
codeLine: ElementEntry;
}
};
/** Outdent the code line. Remove 2 whitespace characters if any. */

@@ -111,6 +111,6 @@ declare const outdentCodeLine: (editor: Editor, { codeBlock, codeLine }: OutdentCodeLineOptions) => void;

interface CodeBlockInsertOptions {
type CodeBlockInsertOptions = {
defaultType?: string;
insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;
}
};
/**

@@ -117,0 +117,0 @@ * Called by toolbars to make sure a code-block gets inserted below a paragraph

@@ -68,7 +68,7 @@ import * as platejs from 'platejs';

interface IndentCodeLineOptions {
type IndentCodeLineOptions = {
codeBlock: ElementEntry;
codeLine: ElementEntry;
indentDepth?: number;
}
};
/**

@@ -91,6 +91,6 @@ * Indent if:

interface OutdentCodeLineOptions {
type OutdentCodeLineOptions = {
codeBlock: ElementEntry;
codeLine: ElementEntry;
}
};
/** Outdent the code line. Remove 2 whitespace characters if any. */

@@ -111,6 +111,6 @@ declare const outdentCodeLine: (editor: Editor, { codeBlock, codeLine }: OutdentCodeLineOptions) => void;

interface CodeBlockInsertOptions {
type CodeBlockInsertOptions = {
defaultType?: string;
insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;
}
};
/**

@@ -117,0 +117,0 @@ * Called by toolbars to make sure a code-block gets inserted below a paragraph

@@ -120,6 +120,7 @@ "use strict";

// src/lib/queries/getIndentDepth.ts
var nonWhitespaceOrEndRegex = /\S|$/;
var getIndentDepth = (editor, { codeLine }) => {
const [, codeLinePath] = codeLine;
const text = editor.api.string(codeLinePath);
return text.search(/\S|$/);
return text.search(nonWhitespaceOrEndRegex);
};

@@ -259,2 +260,3 @@

// src/lib/transforms/deleteStartSpace.ts
var whitespaceRegex = /\s/;
var deleteStartSpace = (editor, { codeLine }) => {

@@ -266,3 +268,3 @@ const [, codeLinePath] = codeLine;

const spaceText = editor.api.string(spaceRange);
if (/\s/.test(spaceText)) {
if (whitespaceRegex.test(spaceText)) {
editor.tf.delete({ at: spaceRange });

@@ -275,2 +277,3 @@ return true;

// src/lib/transforms/indentCodeLine.ts
var nonWhitespaceRegex = /\S/;
var indentCodeLine = (editor, { codeLine, indentDepth = 2 }) => {

@@ -284,3 +287,3 @@ const [, codeLinePath] = codeLine;

const text = editor.api.string(range);
if (/\S/.test(text)) {
if (nonWhitespaceRegex.test(text)) {
editor.tf.insertText(indent, { at: editor.selection });

@@ -357,3 +360,5 @@ return;

const deleted = deleteStartSpace(editor, { codeBlock, codeLine });
deleted && deleteStartSpace(editor, { codeBlock, codeLine });
if (deleted) {
deleteStartSpace(editor, { codeBlock, codeLine });
}
};

@@ -456,3 +461,3 @@

return;
} catch (error) {
} catch (_error) {
}

@@ -681,5 +686,3 @@ }

},
match: ({ editor, rule }) => {
return ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor);
}
match: ({ editor, rule }) => ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor)
},

@@ -707,3 +710,3 @@ decorate: ({ editor, entry: [node, path], getOptions, type }) => {

return JSON.stringify(JSON.parse(code), null, 2);
} catch (error) {
} catch (_error) {
return code;

@@ -716,3 +719,3 @@ }

return true;
} catch (error) {
} catch (_error) {
return false;

@@ -719,0 +722,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/index.ts","../src/lib/BaseCodeBlockPlugin.ts","../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../src/lib/queries/getCodeLineEntry.ts","../src/lib/queries/getIndentDepth.ts","../src/lib/queries/isCodeBlockEmpty.ts","../src/lib/queries/isSelectionAtCodeBlockStart.ts","../src/lib/setCodeBlockToDecorations.ts","../src/lib/transforms/deleteStartSpace.ts","../src/lib/transforms/indentCodeLine.ts","../src/lib/transforms/insertCodeBlock.ts","../src/lib/transforms/insertCodeLine.ts","../src/lib/transforms/insertEmptyCodeBlock.ts","../src/lib/transforms/outdentCodeLine.ts","../src/lib/transforms/toggleCodeBlock.ts","../src/lib/transforms/unwrapCodeBlock.ts","../src/lib/withInsertDataCodeBlock.ts","../src/lib/withInsertFragmentCodeBlock.ts","../src/lib/withNormalizeCodeBlock.tsx","../src/lib/withCodeBlock.ts","../src/lib/formatter/jsonFormatter.ts","../src/lib/formatter/formatter.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './lib/index';\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations as setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) => {\n return (\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor)\n );\n },\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(/\\S|$/);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection at the start of the first code line in a code block */\nexport const isSelectionAtCodeBlockStart = (editor: SlateEditor) => {\n const { selection } = editor;\n\n if (!selection || editor.api.isExpanded()) return false;\n\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n return editor.api.isStart(selection.anchor, codeBlock[1]);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (/\\s/.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nexport interface IndentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n}\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (/\\S/.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { InsertNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/**\n * Insert a code block: set the node to code line and wrap it with a code block.\n * If the cursor is not at the block start, insert break before.\n */\nexport const insertCodeBlock = (\n editor: SlateEditor,\n insertNodesOptions: Omit<InsertNodesOptions, 'match'> = {}\n) => {\n if (!editor.selection || editor.api.isExpanded()) return;\n\n const matchCodeElements = (node: TElement) =>\n node.type === KEYS.codeBlock || node.type === KEYS.codeLine;\n\n if (\n editor.api.some({\n match: matchCodeElements,\n })\n ) {\n return;\n }\n if (!editor.api.isAt({ start: true })) {\n editor.tf.insertBreak();\n }\n\n editor.tf.setNodes(\n {\n children: [{ text: '' }],\n type: KEYS.codeLine,\n },\n insertNodesOptions\n );\n\n editor.tf.wrapNodes<TElement>(\n {\n children: [],\n type: KEYS.codeBlock,\n },\n insertNodesOptions\n );\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/** Insert a code line starting with indentation. */\nexport const insertCodeLine = (editor: SlateEditor, indentDepth = 0) => {\n if (editor.selection) {\n const indent = ' '.repeat(indentDepth);\n\n editor.tf.insertNodes({\n children: [{ text: indent }],\n type: editor.getType(KEYS.codeLine),\n });\n }\n};\n","import { type InsertNodesOptions, type SlateEditor, KEYS } from 'platejs';\n\nimport { insertCodeBlock } from './insertCodeBlock';\n\nexport interface CodeBlockInsertOptions {\n defaultType?: string;\n insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;\n}\n\n/**\n * Called by toolbars to make sure a code-block gets inserted below a paragraph\n * rather than awkwardly splitting the current selection.\n */\nexport const insertEmptyCodeBlock = (\n editor: SlateEditor,\n {\n defaultType = editor.getType(KEYS.p),\n insertNodesOptions,\n }: CodeBlockInsertOptions = {}\n) => {\n if (!editor.selection) return;\n if (\n editor.api.isExpanded() ||\n !editor.api.isEmpty(editor.selection, { block: true })\n ) {\n editor.tf.insertNodes(\n editor.api.create.block({ children: [{ text: '' }], type: defaultType }),\n {\n nextBlock: true,\n select: true,\n ...insertNodesOptions,\n }\n );\n }\n\n insertCodeBlock(editor, insertNodesOptions);\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport interface OutdentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n}\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n deleted && deleteStartSpace(editor, { codeBlock, codeLine });\n};\n","import type { SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport { unwrapCodeBlock } from './unwrapCodeBlock';\n\nexport const toggleCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n\n const isActive = editor.api.some({\n match: { type: codeBlockType },\n });\n\n editor.tf.withoutNormalizing(() => {\n unwrapCodeBlock(editor);\n\n if (!isActive) {\n editor.tf.setNodes({\n type: codeLineType,\n });\n\n const codeBlock = {\n children: [],\n type: codeBlockType,\n };\n\n editor.tf.wrapNodes<TElement>(codeBlock);\n }\n });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n","export const formatJson = (code: string): string => {\n try {\n return JSON.stringify(JSON.parse(code), null, 2);\n } catch (error) {\n return code;\n }\n};\n\nexport const isValidJson = (code: string): boolean => {\n try {\n JSON.parse(code);\n\n return true;\n } catch (error) {\n return false;\n }\n};\n","import type { Editor, TCodeBlockElement } from 'platejs';\n\nimport { formatJson, isValidJson } from './jsonFormatter';\n\nconst supportedLanguages = new Set(['json']);\n\nexport const isLangSupported = (lang?: string): boolean =>\n Boolean(lang && supportedLanguages.has(lang));\n\nexport const isValidSyntax = (code: string, lang?: string): boolean => {\n if (!isLangSupported(lang)) {\n return false;\n }\n\n switch (lang) {\n case 'json': {\n return isValidJson(code);\n }\n default: {\n return false;\n }\n }\n};\n\nexport const formatCodeBlock = (\n editor: Editor,\n {\n element,\n }: {\n element: TCodeBlockElement;\n }\n) => {\n const { lang } = element;\n\n if (!lang || !isLangSupported(lang)) {\n return;\n }\n\n const code = editor.api.string(element);\n\n if (isValidSyntax(code, lang)) {\n const formattedCode = formatCode(code, lang);\n editor.tf.insertText(formattedCode, { at: element });\n }\n};\n\nconst formatCode = (code: string, lang?: string): string => {\n switch (lang) {\n case 'json': {\n return formatJson(code);\n }\n default: {\n return code;\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,mBAOO;;;ACPP,qBAAqB;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAAoB,KAAK,aAAa;AAAA,IACzC,GAAG,eAAe;AAEpB,UAAM,cACJ,QAAQ,aAAa,QAAQ,sBAAsB,EAAE,KAAK;AAE5D,QAAI,QAAQ,YAAY,MAAM,IAAI;AAElC,QAAI,CAAC,OAAO,QAAQ;AAClB,cAAQ,CAAC,WAAW;AAAA,IACtB;AAEA,UAAM,YAAY,MAAM,IAAI,CAAC,UAAU;AAAA,MACrC,UAAU,CAAC,EAAE,MAAM,KAAK,CAAC;AAAA,MACzB,MAAM,oBAAK;AAAA,IACb,EAAE;AAEF,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM,oBAAK;AAAA,IACb;AAAA,EACF;AACF;;;ACzCA,IAAAC,kBAQO;AAGA,IAAM,mBAAmB,CAC9B,QACA,EAAE,KAAK,OAAO,UAAU,IA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A,EACT;AACF;;;ACZA,IAAM,qBAAqB,oBAAI,IAAI,CAAC,MAAM,CAAC;AAEpC,IAAM,kBAAkB,CAAC,SAC9B,QAAQ,QAAQ,mBAAmB,IAAI,IAAI,CAAC;AAEvC,IAAM,gBAAgB,CAAC,MAAc,SAA2B;AACrE,MAAI,CAAC,gBAAgB,IAAI,GAAG;AAC1B,WAAO;AAAA,EACT;AAEA,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,YAAY,IAAI;AAAA,IACzB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,kBAAkB,CAC7B,QACA;AAAA,EACE;AACF,MAGG;AACH,QAAM,EAAE,KAAK,IAAI;AAEjB,MAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG;AACnC;AAAA,EACF;AAEA,QAAM,OAAO,OAAO,IAAI,OAAO,OAAO;AAEtC,MAAI,cAAc,MAAM,IAAI,GAAG;AAC7B,UAAM,gBAAgB,WAAW,MAAM,IAAI;AAC3C,WAAO,GAAG,WAAW,eAAe,EAAE,IAAI,QAAQ,CAAC;AAAA,EACrD;AACF;AAEA,IAAM,aAAa,CAAC,MAAc,SAA0B;AAC1D,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,WAAW,IAAI;AAAA,IACxB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","blockAbove","import_platejs","import_platejs","apply"]}
{"version":3,"sources":["../src/index.ts","../src/lib/BaseCodeBlockPlugin.ts","../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../src/lib/queries/getCodeLineEntry.ts","../src/lib/queries/getIndentDepth.ts","../src/lib/queries/isCodeBlockEmpty.ts","../src/lib/queries/isSelectionAtCodeBlockStart.ts","../src/lib/setCodeBlockToDecorations.ts","../src/lib/transforms/deleteStartSpace.ts","../src/lib/transforms/indentCodeLine.ts","../src/lib/transforms/insertCodeBlock.ts","../src/lib/transforms/insertCodeLine.ts","../src/lib/transforms/insertEmptyCodeBlock.ts","../src/lib/transforms/outdentCodeLine.ts","../src/lib/transforms/toggleCodeBlock.ts","../src/lib/transforms/unwrapCodeBlock.ts","../src/lib/withInsertDataCodeBlock.ts","../src/lib/withInsertFragmentCodeBlock.ts","../src/lib/withNormalizeCodeBlock.tsx","../src/lib/withCodeBlock.ts","../src/lib/formatter/jsonFormatter.ts","../src/lib/formatter/formatter.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './lib/index';\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) =>\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor),\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nconst nonWhitespaceOrEndRegex = /\\S|$/;\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(nonWhitespaceOrEndRegex);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection at the start of the first code line in a code block */\nexport const isSelectionAtCodeBlockStart = (editor: SlateEditor) => {\n const { selection } = editor;\n\n if (!selection || editor.api.isExpanded()) return false;\n\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n return editor.api.isStart(selection.anchor, codeBlock[1]);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted: any;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\nconst whitespaceRegex = /\\s/;\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (whitespaceRegex.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nconst nonWhitespaceRegex = /\\S/;\n\nexport type IndentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n};\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (nonWhitespaceRegex.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { InsertNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/**\n * Insert a code block: set the node to code line and wrap it with a code block.\n * If the cursor is not at the block start, insert break before.\n */\nexport const insertCodeBlock = (\n editor: SlateEditor,\n insertNodesOptions: Omit<InsertNodesOptions, 'match'> = {}\n) => {\n if (!editor.selection || editor.api.isExpanded()) return;\n\n const matchCodeElements = (node: TElement) =>\n node.type === KEYS.codeBlock || node.type === KEYS.codeLine;\n\n if (\n editor.api.some({\n match: matchCodeElements,\n })\n ) {\n return;\n }\n if (!editor.api.isAt({ start: true })) {\n editor.tf.insertBreak();\n }\n\n editor.tf.setNodes(\n {\n children: [{ text: '' }],\n type: KEYS.codeLine,\n },\n insertNodesOptions\n );\n\n editor.tf.wrapNodes<TElement>(\n {\n children: [],\n type: KEYS.codeBlock,\n },\n insertNodesOptions\n );\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/** Insert a code line starting with indentation. */\nexport const insertCodeLine = (editor: SlateEditor, indentDepth = 0) => {\n if (editor.selection) {\n const indent = ' '.repeat(indentDepth);\n\n editor.tf.insertNodes({\n children: [{ text: indent }],\n type: editor.getType(KEYS.codeLine),\n });\n }\n};\n","import { type InsertNodesOptions, type SlateEditor, KEYS } from 'platejs';\n\nimport { insertCodeBlock } from './insertCodeBlock';\n\nexport type CodeBlockInsertOptions = {\n defaultType?: string;\n insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;\n};\n\n/**\n * Called by toolbars to make sure a code-block gets inserted below a paragraph\n * rather than awkwardly splitting the current selection.\n */\nexport const insertEmptyCodeBlock = (\n editor: SlateEditor,\n {\n defaultType = editor.getType(KEYS.p),\n insertNodesOptions,\n }: CodeBlockInsertOptions = {}\n) => {\n if (!editor.selection) return;\n if (\n editor.api.isExpanded() ||\n !editor.api.isEmpty(editor.selection, { block: true })\n ) {\n editor.tf.insertNodes(\n editor.api.create.block({ children: [{ text: '' }], type: defaultType }),\n {\n nextBlock: true,\n select: true,\n ...insertNodesOptions,\n }\n );\n }\n\n insertCodeBlock(editor, insertNodesOptions);\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport type OutdentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n};\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n if (deleted) {\n deleteStartSpace(editor, { codeBlock, codeLine });\n }\n};\n","import type { SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport { unwrapCodeBlock } from './unwrapCodeBlock';\n\nexport const toggleCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n\n const isActive = editor.api.some({\n match: { type: codeBlockType },\n });\n\n editor.tf.withoutNormalizing(() => {\n unwrapCodeBlock(editor);\n\n if (!isActive) {\n editor.tf.setNodes({\n type: codeLineType,\n });\n\n const codeBlock = {\n children: [],\n type: codeBlockType,\n };\n\n editor.tf.wrapNodes<TElement>(codeBlock);\n }\n });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (_error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n","export const formatJson = (code: string): string => {\n try {\n return JSON.stringify(JSON.parse(code), null, 2);\n } catch (_error) {\n return code;\n }\n};\n\nexport const isValidJson = (code: string): boolean => {\n try {\n JSON.parse(code);\n\n return true;\n } catch (_error) {\n return false;\n }\n};\n","import type { Editor, TCodeBlockElement } from 'platejs';\n\nimport { formatJson, isValidJson } from './jsonFormatter';\n\nconst supportedLanguages = new Set(['json']);\n\nexport const isLangSupported = (lang?: string): boolean =>\n Boolean(lang && supportedLanguages.has(lang));\n\nexport const isValidSyntax = (code: string, lang?: string): boolean => {\n if (!isLangSupported(lang)) {\n return false;\n }\n\n switch (lang) {\n case 'json': {\n return isValidJson(code);\n }\n default: {\n return false;\n }\n }\n};\n\nexport const formatCodeBlock = (\n editor: Editor,\n {\n element,\n }: {\n element: TCodeBlockElement;\n }\n) => {\n const { lang } = element;\n\n if (!lang || !isLangSupported(lang)) {\n return;\n }\n\n const code = editor.api.string(element);\n\n if (isValidSyntax(code, lang)) {\n const formattedCode = formatCode(code, lang);\n editor.tf.insertText(formattedCode, { at: element });\n }\n};\n\nconst formatCode = (code: string, lang?: string): string => {\n switch (lang) {\n case 'json': {\n return formatJson(code);\n }\n default: {\n return code;\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,mBAOO;;;ACPP,qBAAqB;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAAoB,KAAK,aAAa;AAAA,IACzC,GAAG,eAAe;AAEpB,UAAM,cACJ,QAAQ,aAAa,QAAQ,sBAAsB,EAAE,KAAK;AAE5D,QAAI,QAAQ,YAAY,MAAM,IAAI;AAElC,QAAI,CAAC,OAAO,QAAQ;AAClB,cAAQ,CAAC,WAAW;AAAA,IACtB;AAEA,UAAM,YAAY,MAAM,IAAI,CAAC,UAAU;AAAA,MACrC,UAAU,CAAC,EAAE,MAAM,KAAK,CAAC;AAAA,MACzB,MAAM,oBAAK;AAAA,IACb,EAAE;AAEF,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM,oBAAK;AAAA,IACb;AAAA,EACF;AACF;;;ACzCA,IAAAC,kBAQO;AAGA,IAAM,mBAAmB,CAC9B,QACA,EAAE,KAAK,OAAO,UAAU,IAA+B,CAAC,MACrD;AACH,MACE,MACA,OAAO,IAAI,KAAK;AAAA,IACd;AAAA,IACA,OAAO,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EACT;AACF;;;ACZA,IAAM,qBAAqB,oBAAI,IAAI,CAAC,MAAM,CAAC;AAEpC,IAAM,kBAAkB,CAAC,SAC9B,QAAQ,QAAQ,mBAAmB,IAAI,IAAI,CAAC;AAEvC,IAAM,gBAAgB,CAAC,MAAc,SAA2B;AACrE,MAAI,CAAC,gBAAgB,IAAI,GAAG;AAC1B,WAAO;AAAA,EACT;AAEA,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,YAAY,IAAI;AAAA,IACzB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,kBAAkB,CAC7B,QACA;AAAA,EACE;AACF,MAGG;AACH,QAAM,EAAE,KAAK,IAAI;AAEjB,MAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG;AACnC;AAAA,EACF;AAEA,QAAM,OAAO,OAAO,IAAI,OAAO,OAAO;AAEtC,MAAI,cAAc,MAAM,IAAI,GAAG;AAC7B,UAAM,gBAAgB,WAAW,MAAM,IAAI;AAC3C,WAAO,GAAG,WAAW,eAAe,EAAE,IAAI,QAAQ,CAAC;AAAA,EACrD;AACF;AAEA,IAAM,aAAa,CAAC,MAAc,SAA0B;AAC1D,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,WAAW,IAAI;AAAA,IACxB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","blockAbove","import_platejs","import_platejs","apply"]}

@@ -73,6 +73,7 @@ // src/lib/BaseCodeBlockPlugin.ts

// src/lib/queries/getIndentDepth.ts
var nonWhitespaceOrEndRegex = /\S|$/;
var getIndentDepth = (editor, { codeLine }) => {
const [, codeLinePath] = codeLine;
const text = editor.api.string(codeLinePath);
return text.search(/\S|$/);
return text.search(nonWhitespaceOrEndRegex);
};

@@ -215,2 +216,3 @@

// src/lib/transforms/deleteStartSpace.ts
var whitespaceRegex = /\s/;
var deleteStartSpace = (editor, { codeLine }) => {

@@ -222,3 +224,3 @@ const [, codeLinePath] = codeLine;

const spaceText = editor.api.string(spaceRange);
if (/\s/.test(spaceText)) {
if (whitespaceRegex.test(spaceText)) {
editor.tf.delete({ at: spaceRange });

@@ -231,2 +233,3 @@ return true;

// src/lib/transforms/indentCodeLine.ts
var nonWhitespaceRegex = /\S/;
var indentCodeLine = (editor, { codeLine, indentDepth = 2 }) => {

@@ -240,3 +243,3 @@ const [, codeLinePath] = codeLine;

const text = editor.api.string(range);
if (/\S/.test(text)) {
if (nonWhitespaceRegex.test(text)) {
editor.tf.insertText(indent, { at: editor.selection });

@@ -313,3 +316,5 @@ return;

const deleted = deleteStartSpace(editor, { codeBlock, codeLine });
deleted && deleteStartSpace(editor, { codeBlock, codeLine });
if (deleted) {
deleteStartSpace(editor, { codeBlock, codeLine });
}
};

@@ -412,3 +417,3 @@

return;
} catch (error) {
} catch (_error) {
}

@@ -641,5 +646,3 @@ }

},
match: ({ editor, rule }) => {
return ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor);
}
match: ({ editor, rule }) => ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor)
},

@@ -667,3 +670,3 @@ decorate: ({ editor, entry: [node, path], getOptions, type }) => {

return JSON.stringify(JSON.parse(code), null, 2);
} catch (error) {
} catch (_error) {
return code;

@@ -676,3 +679,3 @@ }

return true;
} catch (error) {
} catch (_error) {
return false;

@@ -679,0 +682,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/lib/BaseCodeBlockPlugin.ts","../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../src/lib/queries/getCodeLineEntry.ts","../src/lib/queries/getIndentDepth.ts","../src/lib/queries/isCodeBlockEmpty.ts","../src/lib/queries/isSelectionAtCodeBlockStart.ts","../src/lib/setCodeBlockToDecorations.ts","../src/lib/transforms/deleteStartSpace.ts","../src/lib/transforms/indentCodeLine.ts","../src/lib/transforms/insertCodeBlock.ts","../src/lib/transforms/insertCodeLine.ts","../src/lib/transforms/insertEmptyCodeBlock.ts","../src/lib/transforms/outdentCodeLine.ts","../src/lib/transforms/toggleCodeBlock.ts","../src/lib/transforms/unwrapCodeBlock.ts","../src/lib/withInsertDataCodeBlock.ts","../src/lib/withInsertFragmentCodeBlock.ts","../src/lib/withNormalizeCodeBlock.tsx","../src/lib/withCodeBlock.ts","../src/lib/formatter/jsonFormatter.ts","../src/lib/formatter/formatter.ts"],"sourcesContent":["import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations as setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) => {\n return (\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor)\n );\n },\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(/\\S|$/);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection at the start of the first code line in a code block */\nexport const isSelectionAtCodeBlockStart = (editor: SlateEditor) => {\n const { selection } = editor;\n\n if (!selection || editor.api.isExpanded()) return false;\n\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n return editor.api.isStart(selection.anchor, codeBlock[1]);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (/\\s/.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nexport interface IndentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n}\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (/\\S/.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { InsertNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/**\n * Insert a code block: set the node to code line and wrap it with a code block.\n * If the cursor is not at the block start, insert break before.\n */\nexport const insertCodeBlock = (\n editor: SlateEditor,\n insertNodesOptions: Omit<InsertNodesOptions, 'match'> = {}\n) => {\n if (!editor.selection || editor.api.isExpanded()) return;\n\n const matchCodeElements = (node: TElement) =>\n node.type === KEYS.codeBlock || node.type === KEYS.codeLine;\n\n if (\n editor.api.some({\n match: matchCodeElements,\n })\n ) {\n return;\n }\n if (!editor.api.isAt({ start: true })) {\n editor.tf.insertBreak();\n }\n\n editor.tf.setNodes(\n {\n children: [{ text: '' }],\n type: KEYS.codeLine,\n },\n insertNodesOptions\n );\n\n editor.tf.wrapNodes<TElement>(\n {\n children: [],\n type: KEYS.codeBlock,\n },\n insertNodesOptions\n );\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/** Insert a code line starting with indentation. */\nexport const insertCodeLine = (editor: SlateEditor, indentDepth = 0) => {\n if (editor.selection) {\n const indent = ' '.repeat(indentDepth);\n\n editor.tf.insertNodes({\n children: [{ text: indent }],\n type: editor.getType(KEYS.codeLine),\n });\n }\n};\n","import { type InsertNodesOptions, type SlateEditor, KEYS } from 'platejs';\n\nimport { insertCodeBlock } from './insertCodeBlock';\n\nexport interface CodeBlockInsertOptions {\n defaultType?: string;\n insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;\n}\n\n/**\n * Called by toolbars to make sure a code-block gets inserted below a paragraph\n * rather than awkwardly splitting the current selection.\n */\nexport const insertEmptyCodeBlock = (\n editor: SlateEditor,\n {\n defaultType = editor.getType(KEYS.p),\n insertNodesOptions,\n }: CodeBlockInsertOptions = {}\n) => {\n if (!editor.selection) return;\n if (\n editor.api.isExpanded() ||\n !editor.api.isEmpty(editor.selection, { block: true })\n ) {\n editor.tf.insertNodes(\n editor.api.create.block({ children: [{ text: '' }], type: defaultType }),\n {\n nextBlock: true,\n select: true,\n ...insertNodesOptions,\n }\n );\n }\n\n insertCodeBlock(editor, insertNodesOptions);\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport interface OutdentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n}\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n deleted && deleteStartSpace(editor, { codeBlock, codeLine });\n};\n","import type { SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport { unwrapCodeBlock } from './unwrapCodeBlock';\n\nexport const toggleCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n\n const isActive = editor.api.some({\n match: { type: codeBlockType },\n });\n\n editor.tf.withoutNormalizing(() => {\n unwrapCodeBlock(editor);\n\n if (!isActive) {\n editor.tf.setNodes({\n type: codeLineType,\n });\n\n const codeBlock = {\n children: [],\n type: codeBlockType,\n };\n\n editor.tf.wrapNodes<TElement>(codeBlock);\n }\n });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n","export const formatJson = (code: string): string => {\n try {\n return JSON.stringify(JSON.parse(code), null, 2);\n } catch (error) {\n return code;\n }\n};\n\nexport const isValidJson = (code: string): boolean => {\n try {\n JSON.parse(code);\n\n return true;\n } catch (error) {\n return false;\n }\n};\n","import type { Editor, TCodeBlockElement } from 'platejs';\n\nimport { formatJson, isValidJson } from './jsonFormatter';\n\nconst supportedLanguages = new Set(['json']);\n\nexport const isLangSupported = (lang?: string): boolean =>\n Boolean(lang && supportedLanguages.has(lang));\n\nexport const isValidSyntax = (code: string, lang?: string): boolean => {\n if (!isLangSupported(lang)) {\n return false;\n }\n\n switch (lang) {\n case 'json': {\n return isValidJson(code);\n }\n default: {\n return false;\n }\n }\n};\n\nexport const formatCodeBlock = (\n editor: Editor,\n {\n element,\n }: {\n element: TCodeBlockElement;\n }\n) => {\n const { lang } = element;\n\n if (!lang || !isLangSupported(lang)) {\n return;\n }\n\n const code = editor.api.string(element);\n\n if (isValidSyntax(code, lang)) {\n const formattedCode = formatCode(code, lang);\n editor.tf.insertText(formattedCode, { at: element });\n }\n};\n\nconst formatCode = (code: string, lang?: string): string => {\n switch (lang) {\n case 'json': {\n return formatJson(code);\n }\n default: {\n return code;\n }\n }\n};\n"],"mappings":";AAEA;AAAA,EAIE;AAAA,EACA;AAAA,EACA,QAAAA;AAAA,OACK;;;ACPP,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,YAAY,IAAI;AAAA,IACzB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,kBAAkB,CAC7B,QACA;AAAA,EACE;AACF,MAGG;AACH,QAAM,EAAE,KAAK,IAAI;AAEjB,MAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG;AACnC;AAAA,EACF;AAEA,QAAM,OAAO,OAAO,IAAI,OAAO,OAAO;AAEtC,MAAI,cAAc,MAAM,IAAI,GAAG;AAC7B,UAAM,gBAAgB,WAAW,MAAM,IAAI;AAC3C,WAAO,GAAG,WAAW,eAAe,EAAE,IAAI,QAAQ,CAAC;AAAA,EACrD;AACF;AAEA,IAAM,aAAa,CAAC,MAAc,SAA0B;AAC1D,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,WAAW,IAAI;AAAA,IACxB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["KEYS","KEYS","KEYS","NodeApi","NodeApi","KEYS","KEYS","KEYS","KEYS","KEYS","KEYS","KEYS","NodeApi","KEYS","KEYS","blockAbove","KEYS","NodeApi","ElementApi","KEYS","NodeApi","ElementApi","KEYS","NodeApi","apply","KEYS"]}
{"version":3,"sources":["../src/lib/BaseCodeBlockPlugin.ts","../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../src/lib/queries/getCodeLineEntry.ts","../src/lib/queries/getIndentDepth.ts","../src/lib/queries/isCodeBlockEmpty.ts","../src/lib/queries/isSelectionAtCodeBlockStart.ts","../src/lib/setCodeBlockToDecorations.ts","../src/lib/transforms/deleteStartSpace.ts","../src/lib/transforms/indentCodeLine.ts","../src/lib/transforms/insertCodeBlock.ts","../src/lib/transforms/insertCodeLine.ts","../src/lib/transforms/insertEmptyCodeBlock.ts","../src/lib/transforms/outdentCodeLine.ts","../src/lib/transforms/toggleCodeBlock.ts","../src/lib/transforms/unwrapCodeBlock.ts","../src/lib/withInsertDataCodeBlock.ts","../src/lib/withInsertFragmentCodeBlock.ts","../src/lib/withNormalizeCodeBlock.tsx","../src/lib/withCodeBlock.ts","../src/lib/formatter/jsonFormatter.ts","../src/lib/formatter/formatter.ts"],"sourcesContent":["import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) =>\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor),\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nconst nonWhitespaceOrEndRegex = /\\S|$/;\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(nonWhitespaceOrEndRegex);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection at the start of the first code line in a code block */\nexport const isSelectionAtCodeBlockStart = (editor: SlateEditor) => {\n const { selection } = editor;\n\n if (!selection || editor.api.isExpanded()) return false;\n\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n return editor.api.isStart(selection.anchor, codeBlock[1]);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted: any;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\nconst whitespaceRegex = /\\s/;\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (whitespaceRegex.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nconst nonWhitespaceRegex = /\\S/;\n\nexport type IndentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n};\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (nonWhitespaceRegex.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { InsertNodesOptions, SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/**\n * Insert a code block: set the node to code line and wrap it with a code block.\n * If the cursor is not at the block start, insert break before.\n */\nexport const insertCodeBlock = (\n editor: SlateEditor,\n insertNodesOptions: Omit<InsertNodesOptions, 'match'> = {}\n) => {\n if (!editor.selection || editor.api.isExpanded()) return;\n\n const matchCodeElements = (node: TElement) =>\n node.type === KEYS.codeBlock || node.type === KEYS.codeLine;\n\n if (\n editor.api.some({\n match: matchCodeElements,\n })\n ) {\n return;\n }\n if (!editor.api.isAt({ start: true })) {\n editor.tf.insertBreak();\n }\n\n editor.tf.setNodes(\n {\n children: [{ text: '' }],\n type: KEYS.codeLine,\n },\n insertNodesOptions\n );\n\n editor.tf.wrapNodes<TElement>(\n {\n children: [],\n type: KEYS.codeBlock,\n },\n insertNodesOptions\n );\n};\n","import type { SlateEditor } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\n/** Insert a code line starting with indentation. */\nexport const insertCodeLine = (editor: SlateEditor, indentDepth = 0) => {\n if (editor.selection) {\n const indent = ' '.repeat(indentDepth);\n\n editor.tf.insertNodes({\n children: [{ text: indent }],\n type: editor.getType(KEYS.codeLine),\n });\n }\n};\n","import { type InsertNodesOptions, type SlateEditor, KEYS } from 'platejs';\n\nimport { insertCodeBlock } from './insertCodeBlock';\n\nexport type CodeBlockInsertOptions = {\n defaultType?: string;\n insertNodesOptions?: Omit<InsertNodesOptions, 'match'>;\n};\n\n/**\n * Called by toolbars to make sure a code-block gets inserted below a paragraph\n * rather than awkwardly splitting the current selection.\n */\nexport const insertEmptyCodeBlock = (\n editor: SlateEditor,\n {\n defaultType = editor.getType(KEYS.p),\n insertNodesOptions,\n }: CodeBlockInsertOptions = {}\n) => {\n if (!editor.selection) return;\n if (\n editor.api.isExpanded() ||\n !editor.api.isEmpty(editor.selection, { block: true })\n ) {\n editor.tf.insertNodes(\n editor.api.create.block({ children: [{ text: '' }], type: defaultType }),\n {\n nextBlock: true,\n select: true,\n ...insertNodesOptions,\n }\n );\n }\n\n insertCodeBlock(editor, insertNodesOptions);\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport type OutdentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n};\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n if (deleted) {\n deleteStartSpace(editor, { codeBlock, codeLine });\n }\n};\n","import type { SlateEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nimport { unwrapCodeBlock } from './unwrapCodeBlock';\n\nexport const toggleCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n\n const isActive = editor.api.some({\n match: { type: codeBlockType },\n });\n\n editor.tf.withoutNormalizing(() => {\n unwrapCodeBlock(editor);\n\n if (!isActive) {\n editor.tf.setNodes({\n type: codeLineType,\n });\n\n const codeBlock = {\n children: [],\n type: codeBlockType,\n };\n\n editor.tf.wrapNodes<TElement>(codeBlock);\n }\n });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (_error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n","export const formatJson = (code: string): string => {\n try {\n return JSON.stringify(JSON.parse(code), null, 2);\n } catch (_error) {\n return code;\n }\n};\n\nexport const isValidJson = (code: string): boolean => {\n try {\n JSON.parse(code);\n\n return true;\n } catch (_error) {\n return false;\n }\n};\n","import type { Editor, TCodeBlockElement } from 'platejs';\n\nimport { formatJson, isValidJson } from './jsonFormatter';\n\nconst supportedLanguages = new Set(['json']);\n\nexport const isLangSupported = (lang?: string): boolean =>\n Boolean(lang && supportedLanguages.has(lang));\n\nexport const isValidSyntax = (code: string, lang?: string): boolean => {\n if (!isLangSupported(lang)) {\n return false;\n }\n\n switch (lang) {\n case 'json': {\n return isValidJson(code);\n }\n default: {\n return false;\n }\n }\n};\n\nexport const formatCodeBlock = (\n editor: Editor,\n {\n element,\n }: {\n element: TCodeBlockElement;\n }\n) => {\n const { lang } = element;\n\n if (!lang || !isLangSupported(lang)) {\n return;\n }\n\n const code = editor.api.string(element);\n\n if (isValidSyntax(code, lang)) {\n const formattedCode = formatCode(code, lang);\n editor.tf.insertText(formattedCode, { at: element });\n }\n};\n\nconst formatCode = (code: string, lang?: string): string => {\n switch (lang) {\n case 'json': {\n return formatJson(code);\n }\n default: {\n return code;\n }\n }\n};\n"],"mappings":";AAEA;AAAA,EAIE;AAAA,EACA;AAAA,EACA,QAAAA;AAAA,OACK;;;ACPP,SAAS,YAAY;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;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ACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,IAAM,kBAAkB,CAC7B,QACA;AAAA,EACE;AACF,MAGG;AACH,QAAM,EAAE,KAAK,IAAI;AAEjB,MAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,GAAG;AACnC;AAAA,EACF;AAEA,QAAM,OAAO,OAAO,IAAI,OAAO,OAAO;AAEtC,MAAI,cAAc,MAAM,IAAI,GAAG;AAC7B,UAAM,gBAAgB,WAAW,MAAM,IAAI;AAC3C,WAAO,GAAG,WAAW,eAAe,EAAE,IAAI,QAAQ,CAAC;AAAA,EACrD;AACF;AAEA,IAAM,aAAa,CAAC,MAAc,SAA0B;AAC1D,UAAQ,MAAM;AAAA,IACZ,KAAK,QAAQ;AACX,aAAO,WAAW,IAAI;AAAA,IACxB;AAAA,IACA,SAAS;AACP,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["KEYS","KEYS","KEYS","NodeApi","NodeApi","KEYS","KEYS","KEYS","KEYS","KEYS","KEYS","KEYS","NodeApi","KEYS","KEYS","blockAbove","KEYS","NodeApi","ElementApi","KEYS","NodeApi","ElementApi","KEYS","NodeApi","apply","KEYS"]}

@@ -97,6 +97,7 @@ "use strict";

// src/lib/queries/getIndentDepth.ts
var nonWhitespaceOrEndRegex = /\S|$/;
var getIndentDepth = (editor, { codeLine }) => {
const [, codeLinePath] = codeLine;
const text = editor.api.string(codeLinePath);
return text.search(/\S|$/);
return text.search(nonWhitespaceOrEndRegex);
};

@@ -227,2 +228,3 @@

// src/lib/transforms/deleteStartSpace.ts
var whitespaceRegex = /\s/;
var deleteStartSpace = (editor, { codeLine }) => {

@@ -234,3 +236,3 @@ const [, codeLinePath] = codeLine;

const spaceText = editor.api.string(spaceRange);
if (/\s/.test(spaceText)) {
if (whitespaceRegex.test(spaceText)) {
editor.tf.delete({ at: spaceRange });

@@ -243,2 +245,3 @@ return true;

// src/lib/transforms/indentCodeLine.ts
var nonWhitespaceRegex = /\S/;
var indentCodeLine = (editor, { codeLine, indentDepth = 2 }) => {

@@ -252,3 +255,3 @@ const [, codeLinePath] = codeLine;

const text = editor.api.string(range);
if (/\S/.test(text)) {
if (nonWhitespaceRegex.test(text)) {
editor.tf.insertText(indent, { at: editor.selection });

@@ -264,3 +267,5 @@ return;

const deleted = deleteStartSpace(editor, { codeBlock, codeLine });
deleted && deleteStartSpace(editor, { codeBlock, codeLine });
if (deleted) {
deleteStartSpace(editor, { codeBlock, codeLine });
}
};

@@ -337,3 +342,3 @@

return;
} catch (error) {
} catch (_error) {
}

@@ -562,5 +567,3 @@ }

},
match: ({ editor, rule }) => {
return ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor);
}
match: ({ editor, rule }) => ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor)
},

@@ -567,0 +570,0 @@ decorate: ({ editor, entry: [node, path], getOptions, type }) => {

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../src/react/index.ts","../../src/react/CodeBlockPlugin.tsx","../../src/lib/BaseCodeBlockPlugin.ts","../../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../../src/lib/queries/getCodeLineEntry.ts","../../src/lib/queries/getIndentDepth.ts","../../src/lib/queries/isCodeBlockEmpty.ts","../../src/lib/setCodeBlockToDecorations.ts","../../src/lib/transforms/deleteStartSpace.ts","../../src/lib/transforms/indentCodeLine.ts","../../src/lib/transforms/outdentCodeLine.ts","../../src/lib/transforms/unwrapCodeBlock.ts","../../src/lib/withInsertDataCodeBlock.ts","../../src/lib/withInsertFragmentCodeBlock.ts","../../src/lib/withNormalizeCodeBlock.tsx","../../src/lib/withCodeBlock.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './CodeBlockPlugin';\n","import { toPlatePlugin } from 'platejs/react';\n\nimport {\n BaseCodeBlockPlugin,\n BaseCodeLinePlugin,\n BaseCodeSyntaxPlugin,\n} from '../lib/BaseCodeBlockPlugin';\n\nexport const CodeSyntaxPlugin = toPlatePlugin(BaseCodeSyntaxPlugin);\n\nexport const CodeLinePlugin = toPlatePlugin(BaseCodeLinePlugin);\n\n/** Enables support for pre-formatted code blocks. */\nexport const CodeBlockPlugin = toPlatePlugin(BaseCodeBlockPlugin, {\n plugins: [CodeLinePlugin, CodeSyntaxPlugin],\n});\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations as setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) => {\n return (\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor)\n );\n },\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(/\\S|$/);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (/\\s/.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nexport interface IndentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n}\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (/\\S/.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport interface OutdentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n}\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n deleted && deleteStartSpace(editor, { codeBlock, codeLine });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA8B;;;ACE9B,IAAAA,kBAOO;;;ACPP,qBAAqB;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAAoB,KAAK,aAAa;AAAA,IACzC,GAAG,eAAe;AAEpB,UAAM,cACJ,QAAQ,aAAa,QAAQ,sBAAsB,EAAE,KAAK;AAE5D,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IAAI,CAAC;AAAA,IACrE;AAEA,QAAI,KAAK,SAAS,cAAc;AAC9B,aAAO,yBAAyB,IAAI,IAAgB,KAAK,CAAC;AAAA,IAC5D;AAEA,WAAO,CAAC;AAAA,EACV;AACF,CAAC,EACE,eAAe,aAAa,EAC5B,iBAAiB,CAAC,EAAE,OAAO,OAAO;AAAA,EACjC,QAAQ,MAAM;AACZ,WAAO,GAAG,YAAY,OAAO,QAAQ,qBAAK,SAAS,CAAC;AAAA,EACtD;AACF,EAAE;;;ADjGG,IAAM,uBAAmB,4BAAc,oBAAoB;AAE3D,IAAM,qBAAiB,4BAAc,kBAAkB;AAGvD,IAAM,sBAAkB,4BAAc,qBAAqB;AAAA,EAChE,SAAS,CAAC,gBAAgB,gBAAgB;AAC5C,CAAC;","names":["import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","blockAbove","import_platejs","import_platejs","apply"]}
{"version":3,"sources":["../../src/react/index.ts","../../src/react/CodeBlockPlugin.tsx","../../src/lib/BaseCodeBlockPlugin.ts","../../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../../src/lib/queries/getCodeLineEntry.ts","../../src/lib/queries/getIndentDepth.ts","../../src/lib/queries/isCodeBlockEmpty.ts","../../src/lib/setCodeBlockToDecorations.ts","../../src/lib/transforms/deleteStartSpace.ts","../../src/lib/transforms/indentCodeLine.ts","../../src/lib/transforms/outdentCodeLine.ts","../../src/lib/transforms/unwrapCodeBlock.ts","../../src/lib/withInsertDataCodeBlock.ts","../../src/lib/withInsertFragmentCodeBlock.ts","../../src/lib/withNormalizeCodeBlock.tsx","../../src/lib/withCodeBlock.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './CodeBlockPlugin';\n","import { toPlatePlugin } from 'platejs/react';\n\nimport {\n BaseCodeBlockPlugin,\n BaseCodeLinePlugin,\n BaseCodeSyntaxPlugin,\n} from '../lib/BaseCodeBlockPlugin';\n\nexport const CodeSyntaxPlugin = toPlatePlugin(BaseCodeSyntaxPlugin);\n\nexport const CodeLinePlugin = toPlatePlugin(BaseCodeLinePlugin);\n\n/** Enables support for pre-formatted code blocks. */\nexport const CodeBlockPlugin = toPlatePlugin(BaseCodeBlockPlugin, {\n plugins: [CodeLinePlugin, CodeSyntaxPlugin],\n});\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) =>\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor),\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nconst nonWhitespaceOrEndRegex = /\\S|$/;\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(nonWhitespaceOrEndRegex);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted: any;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\nconst whitespaceRegex = /\\s/;\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (whitespaceRegex.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nconst nonWhitespaceRegex = /\\S/;\n\nexport type IndentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n};\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (nonWhitespaceRegex.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport type OutdentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n};\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n if (deleted) {\n deleteStartSpace(editor, { codeBlock, codeLine });\n }\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (_error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA8B;;;ACE9B,IAAAA,kBAOO;;;ACPP,qBAAqB;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAAoB,KAAK,aAAa;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AAEpC,UAAM,eAAe,OAAO,QAAQ,qBAAK,QAAQ;AAGjD,QACE,KAAK,SAAS,QACd,CAAC,yBAAyB,IAAK,KAAK,SAAwB,CAAC,CAAC,GAC9D;AACA,gCAA0B,QAAQ,CAAC,MAA2B,IAAI,CAAC;AAAA,IACrE;AAEA,QAAI,KAAK,SAAS,cAAc;AAC9B,aAAO,yBAAyB,IAAI,IAAgB,KAAK,CAAC;AAAA,IAC5D;AAEA,WAAO,CAAC;AAAA,EACV;AACF,CAAC,EACE,eAAe,aAAa,EAC5B,iBAAiB,CAAC,EAAE,OAAO,OAAO;AAAA,EACjC,QAAQ,MAAM;AACZ,WAAO,GAAG,YAAY,OAAO,QAAQ,qBAAK,SAAS,CAAC;AAAA,EACtD;AACF,EAAE;;;AD9FG,IAAM,uBAAmB,4BAAc,oBAAoB;AAE3D,IAAM,qBAAiB,4BAAc,kBAAkB;AAGvD,IAAM,sBAAkB,4BAAc,qBAAqB;AAAA,EAChE,SAAS,CAAC,gBAAgB,gBAAgB;AAC5C,CAAC;","names":["import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","import_platejs","blockAbove","import_platejs","import_platejs","apply"]}

@@ -76,6 +76,7 @@ // src/react/CodeBlockPlugin.tsx

// src/lib/queries/getIndentDepth.ts
var nonWhitespaceOrEndRegex = /\S|$/;
var getIndentDepth = (editor, { codeLine }) => {
const [, codeLinePath] = codeLine;
const text = editor.api.string(codeLinePath);
return text.search(/\S|$/);
return text.search(nonWhitespaceOrEndRegex);
};

@@ -209,2 +210,3 @@

// src/lib/transforms/deleteStartSpace.ts
var whitespaceRegex = /\s/;
var deleteStartSpace = (editor, { codeLine }) => {

@@ -216,3 +218,3 @@ const [, codeLinePath] = codeLine;

const spaceText = editor.api.string(spaceRange);
if (/\s/.test(spaceText)) {
if (whitespaceRegex.test(spaceText)) {
editor.tf.delete({ at: spaceRange });

@@ -225,2 +227,3 @@ return true;

// src/lib/transforms/indentCodeLine.ts
var nonWhitespaceRegex = /\S/;
var indentCodeLine = (editor, { codeLine, indentDepth = 2 }) => {

@@ -234,3 +237,3 @@ const [, codeLinePath] = codeLine;

const text = editor.api.string(range);
if (/\S/.test(text)) {
if (nonWhitespaceRegex.test(text)) {
editor.tf.insertText(indent, { at: editor.selection });

@@ -246,3 +249,5 @@ return;

const deleted = deleteStartSpace(editor, { codeBlock, codeLine });
deleted && deleteStartSpace(editor, { codeBlock, codeLine });
if (deleted) {
deleteStartSpace(editor, { codeBlock, codeLine });
}
};

@@ -319,3 +324,3 @@

return;
} catch (error) {
} catch (_error) {
}

@@ -548,5 +553,3 @@ }

},
match: ({ editor, rule }) => {
return ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor);
}
match: ({ editor, rule }) => ["break.empty", "delete.empty"].includes(rule) && isCodeBlockEmpty(editor)
},

@@ -553,0 +556,0 @@ decorate: ({ editor, entry: [node, path], getOptions, type }) => {

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../src/react/CodeBlockPlugin.tsx","../../src/lib/BaseCodeBlockPlugin.ts","../../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../../src/lib/queries/getCodeLineEntry.ts","../../src/lib/queries/getIndentDepth.ts","../../src/lib/queries/isCodeBlockEmpty.ts","../../src/lib/setCodeBlockToDecorations.ts","../../src/lib/transforms/deleteStartSpace.ts","../../src/lib/transforms/indentCodeLine.ts","../../src/lib/transforms/outdentCodeLine.ts","../../src/lib/transforms/unwrapCodeBlock.ts","../../src/lib/withInsertDataCodeBlock.ts","../../src/lib/withInsertFragmentCodeBlock.ts","../../src/lib/withNormalizeCodeBlock.tsx","../../src/lib/withCodeBlock.ts"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport {\n BaseCodeBlockPlugin,\n BaseCodeLinePlugin,\n BaseCodeSyntaxPlugin,\n} from '../lib/BaseCodeBlockPlugin';\n\nexport const CodeSyntaxPlugin = toPlatePlugin(BaseCodeSyntaxPlugin);\n\nexport const CodeLinePlugin = toPlatePlugin(BaseCodeLinePlugin);\n\n/** Enables support for pre-formatted code blocks. */\nexport const CodeBlockPlugin = toPlatePlugin(BaseCodeBlockPlugin, {\n plugins: [CodeLinePlugin, CodeSyntaxPlugin],\n});\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations as setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) => {\n return (\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor)\n );\n },\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(/\\S|$/);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (/\\s/.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nexport interface IndentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n}\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (/\\S/.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport interface OutdentCodeLineOptions {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n}\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n deleted && deleteStartSpace(editor, { codeBlock, codeLine });\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n"],"mappings":";AAAA,SAAS,qBAAqB;;;ACE9B;AAAA,EAIE;AAAA,EACA;AAAA,EACA,QAAAA;AAAA,OACK;;;ACPP,SAAS,YAAY;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAAoB,KAAK,aAAa;AAAA,IACzC,GAAG,eAAe;AAEpB,UAAM,cACJ,QAAQ,aAAa,QAAQ,sBAAsB,EAAE,KAAK;AAE5D,QAAI,QAAQ,YAAY,MAAM,IAAI;AAElC,QAAI,CAAC,OAAO,QAAQ;AAClB,cAAQ,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C,CAAC,GAC9D;AACA,gCAA0B,QAAQ,CAAC,MAA2B,IAAI,CAAC;AAAA,IACrE;AAEA,QAAI,KAAK,SAAS,cAAc;AAC9B,aAAO,yBAAyB,IAAI,IAAgB,KAAK,CAAC;AAAA,IAC5D;AAEA,WAAO,CAAC;AAAA,EACV;AACF,CAAC,EACE,eAAe,aAAa,EAC5B,iBAAiB,CAAC,EAAE,OAAO,OAAO;AAAA,EACjC,QAAQ,MAAM;AACZ,WAAO,GAAG,YAAY,OAAO,QAAQA,MAAK,SAAS,CAAC;AAAA,EACtD;AACF,EAAE;;;ADjGG,IAAM,mBAAmB,cAAc,oBAAoB;AAE3D,IAAM,iBAAiB,cAAc,kBAAkB;AAGvD,IAAM,kBAAkB,cAAc,qBAAqB;AAAA,EAChE,SAAS,CAAC,gBAAgB,gBAAgB;AAC5C,CAAC;","names":["KEYS","KEYS","KEYS","NodeApi","NodeApi","KEYS","KEYS","NodeApi","KEYS","blockAbove","KEYS","NodeApi","ElementApi","KEYS","NodeApi","ElementApi","KEYS","NodeApi","apply","KEYS"]}
{"version":3,"sources":["../../src/react/CodeBlockPlugin.tsx","../../src/lib/BaseCodeBlockPlugin.ts","../../src/lib/deserializer/htmlDeserializerCodeBlock.ts","../../src/lib/queries/getCodeLineEntry.ts","../../src/lib/queries/getIndentDepth.ts","../../src/lib/queries/isCodeBlockEmpty.ts","../../src/lib/setCodeBlockToDecorations.ts","../../src/lib/transforms/deleteStartSpace.ts","../../src/lib/transforms/indentCodeLine.ts","../../src/lib/transforms/outdentCodeLine.ts","../../src/lib/transforms/unwrapCodeBlock.ts","../../src/lib/withInsertDataCodeBlock.ts","../../src/lib/withInsertFragmentCodeBlock.ts","../../src/lib/withNormalizeCodeBlock.tsx","../../src/lib/withCodeBlock.ts"],"sourcesContent":["import { toPlatePlugin } from 'platejs/react';\n\nimport {\n BaseCodeBlockPlugin,\n BaseCodeLinePlugin,\n BaseCodeSyntaxPlugin,\n} from '../lib/BaseCodeBlockPlugin';\n\nexport const CodeSyntaxPlugin = toPlatePlugin(BaseCodeSyntaxPlugin);\n\nexport const CodeLinePlugin = toPlatePlugin(BaseCodeLinePlugin);\n\n/** Enables support for pre-formatted code blocks. */\nexport const CodeBlockPlugin = toPlatePlugin(BaseCodeBlockPlugin, {\n plugins: [CodeLinePlugin, CodeSyntaxPlugin],\n});\n","import type { createLowlight } from 'lowlight';\n\nimport {\n type PluginConfig,\n type TCodeBlockElement,\n type TElement,\n createSlatePlugin,\n createTSlatePlugin,\n KEYS,\n} from 'platejs';\n\nimport { htmlDeserializerCodeBlock } from './deserializer/htmlDeserializerCodeBlock';\nimport { isCodeBlockEmpty } from './queries';\nimport {\n CODE_LINE_TO_DECORATIONS,\n setCodeBlockToDecorations,\n} from './setCodeBlockToDecorations';\nimport { withCodeBlock } from './withCodeBlock';\n\nexport type CodeBlockConfig = PluginConfig<\n 'code_block',\n {\n /**\n * Default language to use when no language is specified. Set to null to\n * disable syntax highlighting by default.\n */\n defaultLanguage?: string | null;\n /**\n * Lowlight instance to use for highlighting. If not provided, syntax\n * highlighting will be disabled.\n */\n lowlight?: ReturnType<typeof createLowlight> | null;\n }\n>;\n\nexport const BaseCodeLinePlugin = createTSlatePlugin({\n key: KEYS.codeLine,\n node: { isElement: true, isStrictSiblings: true },\n});\n\nexport const BaseCodeSyntaxPlugin = createSlatePlugin({\n key: KEYS.codeSyntax,\n node: { isLeaf: true },\n});\n\nexport const BaseCodeBlockPlugin = createTSlatePlugin<CodeBlockConfig>({\n key: KEYS.codeBlock,\n inject: {\n plugins: {\n [KEYS.html]: {\n parser: {\n query: ({ editor }) =>\n !editor.api.some({\n match: { type: editor.getType(KEYS.codeLine) },\n }),\n },\n },\n },\n },\n node: {\n isElement: true,\n },\n options: {\n defaultLanguage: null,\n lowlight: null,\n },\n parsers: { html: { deserializer: htmlDeserializerCodeBlock } },\n plugins: [BaseCodeLinePlugin, BaseCodeSyntaxPlugin],\n render: { as: 'pre' },\n rules: {\n delete: {\n empty: 'reset',\n },\n match: ({ editor, rule }) =>\n ['break.empty', 'delete.empty'].includes(rule) &&\n isCodeBlockEmpty(editor),\n },\n decorate: ({ editor, entry: [node, path], getOptions, type }) => {\n if (!getOptions().lowlight) return [];\n\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Initialize decorations for the code block, we assume code line decorate will be called next.\n if (\n node.type === type &&\n !CODE_LINE_TO_DECORATIONS.get((node.children as TElement[])[0])\n ) {\n setCodeBlockToDecorations(editor, [node as TCodeBlockElement, path]);\n }\n\n if (node.type === codeLineType) {\n return CODE_LINE_TO_DECORATIONS.get(node as TElement) || [];\n }\n\n return [];\n },\n})\n .overrideEditor(withCodeBlock)\n .extendTransforms(({ editor }) => ({\n toggle: () => {\n editor.tf.toggleBlock(editor.getType(KEYS.codeBlock));\n },\n }));\n","import type { HtmlDeserializer } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const htmlDeserializerCodeBlock: HtmlDeserializer = {\n rules: [\n {\n validNodeName: 'PRE',\n },\n {\n validNodeName: 'P',\n validStyle: {\n fontFamily: 'Consolas',\n },\n },\n ],\n parse: ({ element }) => {\n const languageSelectorText =\n [...element.childNodes].find(\n (node: ChildNode) => node.nodeName === 'SELECT'\n )?.textContent || '';\n\n const textContent =\n element.textContent?.replace(languageSelectorText, '') || '';\n\n let lines = textContent.split('\\n');\n\n if (!lines?.length) {\n lines = [textContent];\n }\n\n const codeLines = lines.map((line) => ({\n children: [{ text: line }],\n type: KEYS.codeLine,\n }));\n\n return {\n children: codeLines,\n type: KEYS.codeBlock,\n };\n },\n};\n","import {\n type ElementOf,\n type NodeEntry,\n type SlateEditor,\n type TElement,\n type TLocation,\n ElementApi,\n KEYS,\n} from 'platejs';\n\n/** If at (default = selection) is in ul>li>p, return li and ul node entries. */\nexport const getCodeLineEntry = <N extends ElementOf<E>, E extends SlateEditor>(\n editor: E,\n { at = editor.selection }: { at?: TLocation | null } = {}\n) => {\n if (\n at &&\n editor.api.some({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n })\n ) {\n const selectionParent = editor.api.parent(at);\n\n if (!selectionParent) return;\n\n const [, parentPath] = selectionParent;\n\n const codeLine =\n editor.api.above<TElement>({\n at,\n match: { type: editor.getType(KEYS.codeLine) },\n }) || editor.api.parent<N>(parentPath);\n\n if (!codeLine) return;\n\n const [codeLineNode, codeLinePath] = codeLine;\n\n if (\n ElementApi.isElement(codeLineNode) &&\n codeLineNode.type !== editor.getType(KEYS.codeLine)\n )\n return;\n\n const codeBlock = editor.api.parent<N>(codeLinePath);\n\n if (!codeBlock) return;\n\n return {\n codeBlock,\n codeLine: codeLine as NodeEntry<N>,\n };\n }\n};\n","import type { Editor } from 'platejs';\n\nimport type { IndentCodeLineOptions } from '../transforms/indentCodeLine';\n\nconst nonWhitespaceOrEndRegex = /\\S|$/;\n\nexport const getIndentDepth = (\n editor: Editor,\n { codeLine }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const text = editor.api.string(codeLinePath);\n\n return text.search(nonWhitespaceOrEndRegex);\n};\n","import { type SlateEditor, NodeApi } from 'platejs';\n\nimport { getCodeLineEntry } from './getCodeLineEntry';\n\n/** Is the selection inside an empty code block */\nexport const isCodeBlockEmpty = (editor: SlateEditor) => {\n const { codeBlock } = getCodeLineEntry(editor) ?? {};\n\n if (!codeBlock) return false;\n\n const codeLines = Array.from(NodeApi.children(editor, codeBlock[1]));\n\n if (codeLines.length === 0) return true;\n if (codeLines.length > 1) return false;\n\n const firstCodeLineNode = codeLines[0][0];\n\n return !NodeApi.string(firstCodeLineNode);\n};\n","import {\n type DecoratedRange,\n type NodeEntry,\n type SlateEditor,\n type TCodeBlockElement,\n type TElement,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport { BaseCodeBlockPlugin } from './BaseCodeBlockPlugin';\n\n// Cache for storing decorations per code line element\nexport const CODE_LINE_TO_DECORATIONS = new WeakMap<\n TElement,\n DecoratedRange[]\n>();\n\n// Helper function to get highlight nodes from Lowlight result\nfunction getHighlightNodes(result: any) {\n return result.value || result.children || [];\n}\n\n// Helper function to parse nodes from Lowlight's hast tree\nfunction parseNodes(\n nodes: any[],\n className: string[] = []\n): { classes: string[]; text: string }[] {\n return nodes.flatMap((node) => {\n const classes = [\n ...className,\n ...(node.properties ? node.properties.className : []),\n ];\n if (node.children) {\n return parseNodes(node.children, classes);\n }\n return { classes, text: node.value };\n });\n}\n\n// Helper function to normalize tokens by line\nfunction normalizeTokens(tokens: { classes: string[]; text: string }[]) {\n const lines: { classes: string[]; content: string }[][] = [[]];\n let currentLine = lines[0];\n\n for (const token of tokens) {\n const tokenLines = token.text.split('\\n');\n\n for (let i = 0; i < tokenLines.length; i++) {\n const content = tokenLines[i];\n\n if (content) {\n currentLine.push({ classes: token.classes, content });\n }\n\n // Create a new line unless we're on the last line\n if (i < tokenLines.length - 1) {\n lines.push([]);\n currentLine = lines.at(-1) as any;\n }\n }\n }\n\n return lines;\n}\n\n// Helper function to compute decorations for a code block\nexport function codeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const { defaultLanguage, ...options } =\n editor.getOptions(BaseCodeBlockPlugin);\n const lowlight = options.lowlight!;\n\n // Get all code lines and combine their text\n const text = block.children.map((line) => NodeApi.string(line)).join('\\n');\n const language = block.lang;\n const effectiveLanguage = language || defaultLanguage;\n\n let highlighted: any;\n try {\n // Skip highlighting for plaintext or when no language is specified\n if (!effectiveLanguage || effectiveLanguage === 'plaintext') {\n highlighted = { value: [] }; // Empty result for plaintext\n } else if (effectiveLanguage === 'auto') {\n highlighted = lowlight.highlightAuto(text);\n } else {\n highlighted = lowlight.highlight(effectiveLanguage, text);\n }\n } catch (error) {\n // Verify if language is registered, fallback to plaintext if not\n const availableLanguages = lowlight.listLanguages();\n const isLanguageRegistered =\n effectiveLanguage && availableLanguages.includes(effectiveLanguage);\n if (isLanguageRegistered) {\n editor.api.debug.error(error, 'CODE_HIGHLIGHT');\n highlighted = { value: [] }; // Empty result on error\n } else {\n editor.api.debug.warn(\n `Language \"${effectiveLanguage}\" is not registered. Falling back to plaintext`\n );\n highlighted = { value: [] };\n }\n }\n\n // Parse and normalize tokens\n const tokens = parseNodes(getHighlightNodes(highlighted));\n const normalizedTokens = normalizeTokens(tokens);\n const blockChildren = block.children as TElement[];\n\n // Create decorations map\n const nodeToDecorations = new Map<TElement, DecoratedRange[]>();\n\n // Safety check: don't process more lines than we have children\n const numLines = Math.min(normalizedTokens.length, blockChildren.length);\n\n // Process each line's tokens\n for (let index = 0; index < numLines; index++) {\n const lineTokens = normalizedTokens[index];\n const element = blockChildren[index];\n\n if (!nodeToDecorations.has(element)) {\n nodeToDecorations.set(element, []);\n }\n\n let start = 0;\n for (const token of lineTokens) {\n const length = token.content.length;\n if (!length) continue;\n\n const end = start + length;\n\n const decoration: DecoratedRange = {\n anchor: {\n offset: start,\n path: [...blockPath, index, 0],\n },\n className: token.classes.join(' '),\n focus: {\n offset: end,\n path: [...blockPath, index, 0],\n },\n [KEYS.codeSyntax]: true,\n } as any;\n\n nodeToDecorations.get(element)!.push(decoration);\n start = end;\n }\n }\n\n return nodeToDecorations;\n}\n\nexport function setCodeBlockToDecorations(\n editor: SlateEditor,\n [block, blockPath]: NodeEntry<TCodeBlockElement>\n) {\n const decorations = codeBlockToDecorations(editor, [block, blockPath]);\n\n // Update the global cache with the new decorations\n for (const [node, decs] of decorations.entries()) {\n CODE_LINE_TO_DECORATIONS.set(node, decs);\n }\n}\n\nexport function resetCodeBlockDecorations(codeBlock: TCodeBlockElement) {\n codeBlock.children.forEach((line) => {\n CODE_LINE_TO_DECORATIONS.delete(line as TElement);\n });\n}\n","import type { Editor } from 'platejs';\n\nimport type { OutdentCodeLineOptions } from './outdentCodeLine';\n\nconst whitespaceRegex = /\\s/;\n\n/** If there is a whitespace character at the start of the code line, delete it. */\nexport const deleteStartSpace = (\n editor: Editor,\n { codeLine }: OutdentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath);\n const codeLineEnd = codeLineStart && editor.api.after(codeLineStart);\n const spaceRange =\n codeLineEnd && editor.api.range(codeLineStart, codeLineEnd);\n const spaceText = editor.api.string(spaceRange);\n\n if (whitespaceRegex.test(spaceText)) {\n editor.tf.delete({ at: spaceRange });\n\n return true;\n }\n\n return false;\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nconst nonWhitespaceRegex = /\\S/;\n\nexport type IndentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n indentDepth?: number;\n};\n\n/**\n * Indent if:\n *\n * - The selection is expanded OR\n * - There are no non-whitespace characters left of the cursor Indentation = 2\n * spaces.\n */\nexport const indentCodeLine = (\n editor: Editor,\n { codeLine, indentDepth = 2 }: IndentCodeLineOptions\n) => {\n const [, codeLinePath] = codeLine;\n const codeLineStart = editor.api.start(codeLinePath)!;\n const indent = ' '.repeat(indentDepth);\n\n if (!editor.api.isExpanded()) {\n const cursor = editor.selection?.anchor;\n const range = editor.api.range(codeLineStart, cursor);\n const text = editor.api.string(range);\n\n if (nonWhitespaceRegex.test(text)) {\n editor.tf.insertText(indent, { at: editor.selection! });\n\n return;\n }\n }\n\n editor.tf.insertText(indent, { at: codeLineStart });\n};\n","import type { Editor, ElementEntry } from 'platejs';\n\nimport { deleteStartSpace } from './deleteStartSpace';\n\nexport type OutdentCodeLineOptions = {\n codeBlock: ElementEntry;\n codeLine: ElementEntry;\n};\n\n/** Outdent the code line. Remove 2 whitespace characters if any. */\nexport const outdentCodeLine = (\n editor: Editor,\n { codeBlock, codeLine }: OutdentCodeLineOptions\n) => {\n const deleted = deleteStartSpace(editor, { codeBlock, codeLine });\n if (deleted) {\n deleteStartSpace(editor, { codeBlock, codeLine });\n }\n};\n","import { type SlateEditor, type TLocation, KEYS, NodeApi } from 'platejs';\n\nexport const unwrapCodeBlock = (editor: SlateEditor) => {\n if (!editor.selection) return;\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const defaultType = editor.getType(KEYS.p);\n\n editor.tf.withoutNormalizing(() => {\n const codeBlockEntries = editor.api.nodes({\n at: editor.selection as TLocation,\n match: { type: codeBlockType },\n });\n\n const reversedCodeBlockEntries = Array.from(codeBlockEntries).reverse();\n\n for (const codeBlockEntry of reversedCodeBlockEntries) {\n const codeLineEntries = NodeApi.children(editor, codeBlockEntry[1]);\n\n for (const [, path] of codeLineEntries) {\n editor.tf.setNodes({ type: defaultType }, { at: path });\n }\n\n editor.tf.unwrapNodes({\n at: codeBlockEntry[1],\n match: { type: codeBlockType },\n split: true,\n });\n }\n });\n};\n","import type { OverrideEditor, TElement } from 'platejs';\n\nimport { KEYS } from 'platejs';\n\nexport const withInsertDataCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertData },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertData(data) {\n const text = data.getData('text/plain');\n const vscodeDataString = data.getData('vscode-editor-data');\n const codeLineType = editor.getType(KEYS.codeLine);\n\n // Handle VSCode paste with language\n if (vscodeDataString) {\n try {\n const vscodeData = JSON.parse(vscodeDataString);\n const lines = text.split('\\n');\n\n // Check if we're in a code block\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const isInCodeBlock =\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type);\n\n if (isInCodeBlock) {\n // If in code block, insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n } else {\n // Create new code block\n const node = {\n children: lines.map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n })),\n lang: vscodeData?.mode,\n type: codeBlockType,\n };\n\n editor.tf.insertNodes(node, {\n select: true,\n });\n }\n\n return;\n } catch (_error) {}\n }\n\n // Handle plain text paste into code block only if there are line breaks\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type) &&\n text?.includes('\\n')\n ) {\n const lines = text.split('\\n');\n\n // Insert first line as text at cursor\n if (lines[0]) {\n editor.tf.insertText(lines[0]);\n }\n\n // Insert remaining lines as new code lines\n if (lines.length > 1) {\n const nodes = lines.slice(1).map((line) => ({\n children: [{ text: line }],\n type: codeLineType,\n }));\n editor.tf.insertNodes(nodes);\n }\n return;\n }\n\n insertData(data);\n },\n },\n});\n","import { type OverrideEditor, type TElement, KEYS, NodeApi } from 'platejs';\n\nfunction extractCodeLinesFromCodeBlock(node: TElement) {\n return node.children as TElement[];\n}\n\nexport const withInsertFragmentCodeBlock: OverrideEditor = ({\n editor,\n tf: { insertFragment },\n type: codeBlockType,\n}) => ({\n transforms: {\n insertFragment(fragment) {\n const [blockAbove] = editor.api.block<TElement>() ?? [];\n const codeLineType = editor.getType(KEYS.codeLine);\n\n function convertNodeToCodeLine(node: TElement): TElement {\n return {\n children: [{ text: NodeApi.string(node) }],\n type: codeLineType,\n };\n }\n\n if (\n blockAbove &&\n [codeBlockType, codeLineType].includes(blockAbove?.type)\n ) {\n return insertFragment(\n fragment.flatMap((node) => {\n const element = node as TElement;\n\n return element.type === codeBlockType\n ? extractCodeLinesFromCodeBlock(element)\n : convertNodeToCodeLine(element);\n })\n );\n }\n\n return insertFragment(fragment);\n },\n },\n});\n","import {\n type NodeEntry,\n type OverrideEditor,\n type TCodeBlockElement,\n ElementApi,\n KEYS,\n NodeApi,\n} from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { setCodeBlockToDecorations } from './setCodeBlockToDecorations';\n\n/** Normalize code block node to force the pre>code>div.codeline structure. */\nexport const withNormalizeCodeBlock: OverrideEditor<CodeBlockConfig> = ({\n editor,\n getOptions,\n tf: { normalizeNode },\n type,\n}) => ({\n transforms: {\n normalizeNode([node, path]) {\n // Decorate is called on selection change as well, so we prefer to only run this on code block changes.\n if (node.type === type && getOptions().lowlight) {\n setCodeBlockToDecorations(editor, [\n node,\n path,\n ] as NodeEntry<TCodeBlockElement>);\n }\n\n normalizeNode([node, path]);\n\n if (!ElementApi.isElement(node)) {\n return;\n }\n\n const codeBlockType = editor.getType(KEYS.codeBlock);\n const codeLineType = editor.getType(KEYS.codeLine);\n const isCodeBlockRoot = node.type === codeBlockType;\n\n if (isCodeBlockRoot) {\n // Children should all be code lines\n const nonCodeLine = Array.from(NodeApi.children(editor, path)).find(\n ([child]) => child.type !== codeLineType\n );\n\n if (nonCodeLine) {\n editor.tf.setNodes({ type: codeLineType }, { at: nonCodeLine[1] });\n }\n }\n },\n },\n});\n","import type { OverrideEditor, TCodeBlockElement, TElement } from 'platejs';\n\nimport type { CodeBlockConfig } from './BaseCodeBlockPlugin';\n\nimport { getCodeLineEntry, getIndentDepth } from './queries';\nimport { resetCodeBlockDecorations } from './setCodeBlockToDecorations';\nimport { indentCodeLine, outdentCodeLine, unwrapCodeBlock } from './transforms';\nimport { withInsertDataCodeBlock } from './withInsertDataCodeBlock';\nimport { withInsertFragmentCodeBlock } from './withInsertFragmentCodeBlock';\nimport { withNormalizeCodeBlock } from './withNormalizeCodeBlock';\n\nexport const withCodeBlock: OverrideEditor<CodeBlockConfig> = (ctx) => {\n const {\n editor,\n getOptions,\n tf: { apply, insertBreak, resetBlock, selectAll, tab },\n type,\n } = ctx;\n\n return {\n transforms: {\n apply(operation) {\n if (getOptions().lowlight && operation.type === 'set_node') {\n const entry = editor.api.node(operation.path);\n\n if (entry?.[0].type === type && operation.newProperties?.lang) {\n // Clear decorations for all code lines in this block\n resetCodeBlockDecorations(entry[0] as TCodeBlockElement);\n }\n }\n\n apply(operation);\n },\n insertBreak() {\n const apply = () => {\n if (!editor.selection) return;\n\n const res = getCodeLineEntry(editor, {});\n\n if (!res) return;\n\n const { codeBlock, codeLine } = res;\n const indentDepth = getIndentDepth(editor, {\n codeBlock,\n codeLine,\n });\n\n insertBreak();\n\n indentCodeLine(editor, {\n codeBlock,\n codeLine,\n indentDepth,\n });\n\n return true;\n };\n\n if (apply()) return;\n\n insertBreak();\n },\n resetBlock(options) {\n if (\n editor.api.block({\n at: options?.at,\n match: { type },\n })\n ) {\n unwrapCodeBlock(editor);\n return;\n }\n\n return resetBlock(options);\n },\n selectAll: () => {\n const apply = () => {\n const codeBlock = editor.api.above({\n match: { type },\n });\n\n if (!codeBlock) return;\n\n if (\n editor.api.isAt({ end: true }) &&\n editor.api.isAt({ start: true })\n ) {\n return;\n }\n\n // Select the whole code block\n editor.tf.select(codeBlock[1]);\n return true;\n };\n\n if (apply()) return true;\n\n return selectAll();\n },\n tab: (options) => {\n const apply = () => {\n const _codeLines = editor.api.nodes<TElement>({\n match: { type },\n });\n const codeLines = Array.from(_codeLines);\n\n if (codeLines.length > 0) {\n const [, firstLinePath] = codeLines[0];\n const codeBlock = editor.api.parent<TElement>(firstLinePath);\n\n if (!codeBlock) return;\n\n editor.tf.withoutNormalizing(() => {\n for (const codeLine of codeLines) {\n if (options.reverse) {\n outdentCodeLine(editor, { codeBlock, codeLine });\n } else {\n indentCodeLine(editor, { codeBlock, codeLine });\n }\n }\n });\n\n return true; // Prevent default\n }\n };\n\n if (apply()) return true;\n\n return tab(options);\n },\n ...withInsertDataCodeBlock(ctx).transforms,\n ...withInsertFragmentCodeBlock(ctx).transforms,\n ...withNormalizeCodeBlock(ctx).transforms,\n },\n };\n};\n"],"mappings":";AAAA,SAAS,qBAAqB;;;ACE9B;AAAA,EAIE;AAAA,EACA;AAAA,EACA,QAAAA;AAAA,OACK;;;ACPP,SAAS,YAAY;AAEd,IAAM,4BAA8C;AAAA,EACzD,OAAO;AAAA,IACL;AAAA,MACE,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf,YAAY;AAAA,QACV,YAAY;AAAA,MACd;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,CAAC,EAAE,QAAQ,MAAM;AACtB,UAAM,uBACJ,CAAC,GAAG,QAAQ,UAAU,EAAE;AAAA,MACtB,CAAC,SAA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,EAC3B;AAAA,EACA,UAAU,CAAC,EAAE,QAAQ,OAAO,CAAC,MAAM,IAAI,GAAG,YAAY,KAAK,MAAM;AAC/D,QAAI,CAAC,WAAW,EAAE,SAAU,QAAO,CAAC;AAEpC,UAAM,eAAe,OAAO,QAAQA,MAAK,QAAQ;AAGjD,QACE,KAAK,SAAS,QACd,CAAC,yBAAyB,IAAK,KAAK,SAAwB,CAAC,CAAC,GAC9D;AACA,gCAA0B,QAAQ,CAAC,MAA2B,IAAI,CAAC;AAAA,IACrE;AAEA,QAAI,KAAK,SAAS,cAAc;AAC9B,aAAO,yBAAyB,IAAI,IAAgB,KAAK,CAAC;AAAA,IAC5D;AAEA,WAAO,CAAC;AAAA,EACV;AACF,CAAC,EACE,eAAe,aAAa,EAC5B,iBAAiB,CAAC,EAAE,OAAO,OAAO;AAAA,EACjC,QAAQ,MAAM;AACZ,WAAO,GAAG,YAAY,OAAO,QAAQA,MAAK,SAAS,CAAC;AAAA,EACtD;AACF,EAAE;;;AD9FG,IAAM,mBAAmB,cAAc,oBAAoB;AAE3D,IAAM,iBAAiB,cAAc,kBAAkB;AAGvD,IAAM,kBAAkB,cAAc,qBAAqB;AAAA,EAChE,SAAS,CAAC,gBAAgB,gBAAgB;AAC5C,CAAC;","names":["KEYS","KEYS","KEYS","NodeApi","NodeApi","KEYS","KEYS","NodeApi","KEYS","blockAbove","KEYS","NodeApi","ElementApi","KEYS","NodeApi","ElementApi","KEYS","NodeApi","apply","KEYS"]}
{
"name": "@platejs/code-block",
"version": "51.0.0",
"version": "51.1.2",
"description": "Code block plugin for Plate",

@@ -57,3 +57,3 @@ "keywords": [

"peerDependencies": {
"platejs": ">=51.0.0",
"platejs": ">=51.1.2",
"react": ">=18.0.0",

@@ -60,0 +60,0 @@ "react-dom": ">=18.0.0"