From e06e02c6f97172d078661b0d0b7bd082f21a0786 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 22 Mar 2024 22:55:34 +0400 Subject: [PATCH] Up docs --- docs/api/commands.md | 61 +++++++++++++++++++++++++++++++++++++------ src/commands/index.ts | 9 +------ 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/docs/api/commands.md b/docs/api/commands.md index 192b661b3..e4f388633 100644 --- a/docs/api/commands.md +++ b/docs/api/commands.md @@ -23,14 +23,59 @@ const commands = editor.Commands; commands.add(...); ``` -* ## Available Events -* `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview')) -* `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview')) -* `run:{commandName}:before` - Triggered before the command is called -* `stop:{commandName}:before` - Triggered before the command is called to stop -* `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`) -* `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback -* `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback +## Available Events +* `command:run` Triggered on run of any command. + +```javascript +editor.on('command:run', ({ id, result, options }) => { + console.log('Command id', id, 'command result', result); +}); +``` + +* `command:run:COMMAND_ID` Triggered on run of a specific command. + +```javascript +editor.on('command:run:my-command', ({ result, options }) => { ... }); +``` + +* `command:run:before:COMMAND_ID` Triggered before the command is called. + +```javascript +editor.on('command:run:before:my-command', ({ options }) => { ... }); +``` + +* `command:abort:COMMAND_ID` Triggered when the command execution is aborted. + +```javascript +editor.on('command:abort:my-command', ({ options }) => { ... }); + +// The command could be aborted during the before event +editor.on('command:run:before:my-command', ({ options }) => { + if (someCondition) { + options.abort = true; + } +}); +``` + +* `command:stop` Triggered on stop of any command. + +```javascript +editor.on('command:stop', ({ id, result, options }) => { + console.log('Command id', id, 'command result', result); +}); +``` + +* `command:stop:COMMAND_ID` Triggered on stop of a specific command. + +```javascript +editor.on('command:run:my-command', ({ result, options }) => { ... }); +``` + +* `command:stop:before:COMMAND_ID` Triggered before the command is called to stop. + +```javascript +editor.on('command:stop:before:my-command', ({ options }) => { ... }); +``` ## Methods diff --git a/src/commands/index.ts b/src/commands/index.ts index 47aeb75ab..693a27f42 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -19,14 +19,7 @@ * commands.add(...); * ``` * - ** ## Available Events - * * `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview')) - * * `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview')) - * * `run:{commandName}:before` - Triggered before the command is called - * * `stop:{commandName}:before` - Triggered before the command is called to stop - * * `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`) - * * `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback - * * `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback + * {REPLACE_EVENTS} * * ## Methods * * [add](#add)