@platejs/code-block
Advanced tools
+11
-2
@@ -60,3 +60,3 @@ import * as platejs2 from "platejs"; | ||
| declare const isValidSyntax: (code: string, lang?: string) => boolean; | ||
| declare const formatCodeBlock: (editor: Editor, { | ||
| declare const formatCodeBlock: (editor: SlateEditor, { | ||
| element | ||
@@ -155,2 +155,11 @@ }: { | ||
| //#endregion | ||
| //#region src/lib/transforms/setCodeBlockContent.d.ts | ||
| declare const setCodeBlockContent: (editor: SlateEditor, { | ||
| code, | ||
| element | ||
| }: { | ||
| code: string; | ||
| element: TCodeBlockElement; | ||
| }) => void; | ||
| //#endregion | ||
| //#region src/lib/transforms/toggleCodeBlock.d.ts | ||
@@ -162,2 +171,2 @@ declare const toggleCodeBlock: (editor: SlateEditor) => void; | ||
| //#endregion | ||
| export { BaseCodeBlockPlugin, BaseCodeLinePlugin, BaseCodeSyntaxPlugin, CODE_LINE_TO_DECORATIONS, CodeBlockConfig, CodeBlockInsertOptions, IndentCodeLineOptions, OutdentCodeLineOptions, codeBlockToDecorations, deleteStartSpace, formatCodeBlock, formatJson, getCodeLineEntry, getIndentDepth, htmlDeserializerCodeBlock, indentCodeLine, insertCodeBlock, insertCodeLine, insertEmptyCodeBlock, isCodeBlockEmpty, isLangSupported, isSelectionAtCodeBlockStart, isValidJson, isValidSyntax, outdentCodeLine, resetCodeBlockDecorations, setCodeBlockToDecorations, toggleCodeBlock, unwrapCodeBlock, withCodeBlock, withInsertDataCodeBlock, withInsertFragmentCodeBlock, withNormalizeCodeBlock }; | ||
| export { BaseCodeBlockPlugin, BaseCodeLinePlugin, BaseCodeSyntaxPlugin, CODE_LINE_TO_DECORATIONS, CodeBlockConfig, CodeBlockInsertOptions, IndentCodeLineOptions, OutdentCodeLineOptions, codeBlockToDecorations, deleteStartSpace, formatCodeBlock, formatJson, getCodeLineEntry, getIndentDepth, htmlDeserializerCodeBlock, indentCodeLine, insertCodeBlock, insertCodeLine, insertEmptyCodeBlock, isCodeBlockEmpty, isLangSupported, isSelectionAtCodeBlockStart, isValidJson, isValidSyntax, outdentCodeLine, resetCodeBlockDecorations, setCodeBlockContent, setCodeBlockToDecorations, toggleCodeBlock, unwrapCodeBlock, withCodeBlock, withInsertDataCodeBlock, withInsertFragmentCodeBlock, withNormalizeCodeBlock }; |
+18
-5
@@ -68,2 +68,15 @@ import { _ as getIndentDepth, a as withNormalizeCodeBlock, c as unwrapCodeBlock, d as deleteStartSpace, f as CODE_LINE_TO_DECORATIONS, g as isCodeBlockEmpty, h as setCodeBlockToDecorations, i as withCodeBlock, l as outdentCodeLine, m as resetCodeBlockDecorations, n as BaseCodeLinePlugin, o as withInsertFragmentCodeBlock, p as codeBlockToDecorations, r as BaseCodeSyntaxPlugin, s as withInsertDataCodeBlock, t as BaseCodeBlockPlugin, u as indentCodeLine, v as getCodeLineEntry, y as htmlDeserializerCodeBlock } from "./BaseCodeBlockPlugin-CAamjco6.js"; | ||
| //#endregion | ||
| //#region src/lib/transforms/setCodeBlockContent.ts | ||
| const setCodeBlockContent = (editor, { code, element }) => { | ||
| editor.tf.replaceNodes(code.split("\n").map((line) => ({ | ||
| children: [{ text: line }], | ||
| type: editor.getType(KEYS.codeLine) | ||
| })), { | ||
| at: element, | ||
| children: true | ||
| }); | ||
| editor.api.redecorate(); | ||
| }; | ||
| //#endregion | ||
| //#region src/lib/transforms/toggleCodeBlock.ts | ||
@@ -121,6 +134,6 @@ const toggleCodeBlock = (editor) => { | ||
| const code = editor.api.string(element); | ||
| if (isValidSyntax(code, lang)) { | ||
| const formattedCode = formatCode(code, lang); | ||
| editor.tf.insertText(formattedCode, { at: element }); | ||
| } | ||
| if (isValidSyntax(code, lang)) setCodeBlockContent(editor, { | ||
| code: formatCode(code, lang), | ||
| element | ||
| }); | ||
| }; | ||
@@ -135,2 +148,2 @@ const formatCode = (code, lang) => { | ||
| //#endregion | ||
| export { BaseCodeBlockPlugin, BaseCodeLinePlugin, BaseCodeSyntaxPlugin, CODE_LINE_TO_DECORATIONS, codeBlockToDecorations, deleteStartSpace, formatCodeBlock, formatJson, getCodeLineEntry, getIndentDepth, htmlDeserializerCodeBlock, indentCodeLine, insertCodeBlock, insertCodeLine, insertEmptyCodeBlock, isCodeBlockEmpty, isLangSupported, isSelectionAtCodeBlockStart, isValidJson, isValidSyntax, outdentCodeLine, resetCodeBlockDecorations, setCodeBlockToDecorations, toggleCodeBlock, unwrapCodeBlock, withCodeBlock, withInsertDataCodeBlock, withInsertFragmentCodeBlock, withNormalizeCodeBlock }; | ||
| export { BaseCodeBlockPlugin, BaseCodeLinePlugin, BaseCodeSyntaxPlugin, CODE_LINE_TO_DECORATIONS, codeBlockToDecorations, deleteStartSpace, formatCodeBlock, formatJson, getCodeLineEntry, getIndentDepth, htmlDeserializerCodeBlock, indentCodeLine, insertCodeBlock, insertCodeLine, insertEmptyCodeBlock, isCodeBlockEmpty, isLangSupported, isSelectionAtCodeBlockStart, isValidJson, isValidSyntax, outdentCodeLine, resetCodeBlockDecorations, setCodeBlockContent, setCodeBlockToDecorations, toggleCodeBlock, unwrapCodeBlock, withCodeBlock, withInsertDataCodeBlock, withInsertFragmentCodeBlock, withNormalizeCodeBlock }; |
+2
-2
| { | ||
| "name": "@platejs/code-block", | ||
| "version": "52.3.10", | ||
| "version": "52.3.14", | ||
| "description": "Code block plugin for Plate", | ||
@@ -34,3 +34,3 @@ "keywords": [ | ||
| "@plate/scripts": "1.0.0", | ||
| "platejs": "^52.3.9" | ||
| "platejs": "^52.3.11" | ||
| }, | ||
@@ -37,0 +37,0 @@ "peerDependencies": { |
32698
1.71%782
2.76%