diff --git a/package.json b/package.json index 16e90cf..79065a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-mde", - "version": "11.5.0", + "version": "12.0.0", "description": "React Markdown Editor", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", @@ -10,7 +10,7 @@ "dev": "vite", "lint": "pretty-quick", "tsc": "tsc", - "rollup": "rollup -c", + "build": "rollup -c", "typecheck": "tsc --noEmit" }, "repository": { diff --git a/rollup.config.js b/rollup.config.js index 4520f44..1f3aed0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,11 +8,11 @@ export default [ { input: "src/index.ts", output: [ - // { - // file: packageJson.main, - // format: "cjs", - // sourcemap: true, - // }, + { + file: packageJson.main, + format: "cjs", + sourcemap: true + }, { file: packageJson.module, format: "esm", diff --git a/src/commands/command-controller.ts b/src/commands/command-controller.ts index bf80620..a378d00 100644 --- a/src/commands/command-controller.ts +++ b/src/commands/command-controller.ts @@ -1,35 +1,25 @@ -import { extractKeyActivatedCommands } from "./command-utils"; import { TextController } from "../types/CommandOptions"; -import { Command, CommandContext, CommandMap } from "./command"; +import { CommandContext, CommandMap } from "./command"; -export class CommandController { +export class CommandController { private readonly textController: TextController; - private readonly commandMap: CommandMap; - /** - * Names of commands that can be activated by the keyboard - */ - keyActivatedCommands: string[]; + private readonly commandMap: CommandMap; + /** * Indicates whether there is a command currently executing */ isExecuting: boolean = false; - constructor(textController: TextController, commandMap: CommandMap) { + constructor( + textController: TextController, + commandMap: CommandMap + ) { this.textController = textController; this.commandMap = commandMap; - this.keyActivatedCommands = extractKeyActivatedCommands(commandMap); } - getCommand = (name: string): Command => { - const command = this.commandMap[name]; - if (!command) { - throw new Error(`Cannot execute command. Command not found: ${name}`); - } - return command; - }; - async executeCommand( - commandName: string, + commandName: CommandName, context?: CommandContext ): Promise { if (this.isExecuting) { diff --git a/src/commands/command-utils.ts b/src/commands/command-utils.ts deleted file mode 100644 index aa2d56b..0000000 --- a/src/commands/command-utils.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Returns a flat array of commands that can be activated by the keyboard. - * When key-downs happen, these commands 'handleKeyCommand' will be executed, in this order, - * and the first that returns true will be executed. - */ -import { CommandMap } from "./command"; - -export function extractKeyActivatedCommands( - commandMap: CommandMap -): Array { - const result: Array = []; - for (const command in commandMap) { - if (commandMap.hasOwnProperty(command)) { - result.push(command); - } - } - return result; -} diff --git a/src/hooks/use-markdown-editor.ts b/src/hooks/use-markdown-editor.ts index 9b1e940..df5421e 100644 --- a/src/hooks/use-markdown-editor.ts +++ b/src/hooks/use-markdown-editor.ts @@ -4,10 +4,10 @@ import { TextAreaTextController } from "../text/textarea-text-controller"; import { TextController } from "../types/CommandOptions"; import { CommandMap } from "../commands/command"; -export type UseTextAreaMarkdownEditorResult = { +export type UseTextAreaMarkdownEditorResult = { ref: React.RefObject; textController: TextController; - commandController: CommandController; + commandController: CommandController; }; export type UseTextAreaMarkdownEditorOptions = { @@ -16,7 +16,7 @@ export type UseTextAreaMarkdownEditorOptions = { export function useTextAreaMarkdownEditor( options: UseTextAreaMarkdownEditorOptions -): UseTextAreaMarkdownEditorResult { +): UseTextAreaMarkdownEditorResult { const textAreaRef = useRef(null); const textController = useMemo(() => {