From 9fbceff07094af783aa6005c33dbb86ef75169c1 Mon Sep 17 00:00:00 2001 From: andrerpena Date: Mon, 2 May 2022 11:03:26 +0100 Subject: [PATCH] Improvements in the text APIs --- demo/index.tsx | 39 +++--- src/commands/command-controller.ts | 32 ++--- src/commands/command.ts | 10 +- src/commands/markdown-commands/bold.tsx | 31 ++++- src/commands/markdown-commands/code.tsx | 68 +++++------ src/commands/markdown-commands/header.tsx | 10 +- src/commands/markdown-commands/image.tsx | 7 +- src/commands/markdown-commands/italic.tsx | 30 ++++- src/commands/markdown-commands/link.tsx | 11 +- src/commands/markdown-commands/list.tsx | 25 ++-- src/commands/markdown-commands/quote.tsx | 13 +- .../markdown-commands/strikethrough.tsx | 11 +- src/helpers/markdown-helpers.ts | 113 ------------------ src/hooks/use-markdown-editor.ts | 8 +- src/index.ts | 8 +- src/text/textarea-text-controller.ts | 6 +- src/types/CommandOptions.ts | 4 - src/types/TextSection.ts | 6 - 18 files changed, 179 insertions(+), 253 deletions(-) delete mode 100644 src/helpers/markdown-helpers.ts delete mode 100644 src/types/TextSection.ts diff --git a/demo/index.tsx b/demo/index.tsx index 76ed0da..37af6ea 100644 --- a/demo/index.tsx +++ b/demo/index.tsx @@ -1,24 +1,20 @@ import * as React from "react"; import ReactDOM from "react-dom"; -import { - Box, - Button, - ChakraProvider, - HStack, - Textarea -} from "@chakra-ui/react"; +import { Box, ChakraProvider, HStack, Textarea } from "@chakra-ui/react"; import { useTextAreaMarkdownEditor } from "../src/hooks/use-markdown-editor"; -import { faBold, faItalic } from "@fortawesome/free-solid-svg-icons"; +import { faBold, faItalic, faCode } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { bold, italic } from "../src"; +import { bold, code, italic } from "../src"; +import { ToolbarButton } from "./toolbar-button"; export type DemoProps = {}; -export const Demo: React.FunctionComponent = props => { +export const Demo: React.FunctionComponent = () => { const { ref, commandController } = useTextAreaMarkdownEditor({ commandMap: { bold: bold, - italic: italic + italic: italic, + code: code } }); @@ -26,26 +22,27 @@ export const Demo: React.FunctionComponent = props => { - - + + { + await commandController.executeCommand("code"); + }} + > + +