Browse Source

Remove deprecated command options

pull/6397/head
Artur Arseniev 2 years ago
parent
commit
870f574f6b
  1. 4
      packages/core/src/commands/index.ts
  2. 5
      packages/core/src/commands/types.ts
  3. 10
      packages/core/src/commands/view/CommandAbstract.ts

4
packages/core/src/commands/index.ts

@ -383,7 +383,7 @@ export default class CommandsModule extends Module<CommandsConfig & { pStylePref
runCommand(command?: CommandObject, options: CommandOptions = {}) {
let result;
if (command && command.run) {
if (command?.run) {
const { em, config } = this;
const id = command.id as string;
const editor = em.Editor;
@ -411,7 +411,7 @@ export default class CommandsModule extends Module<CommandsConfig & { pStylePref
stopCommand(command?: CommandObject, options: CommandOptions = {}) {
let result;
if (command && command.run) {
if (command?.run) {
const { em, config } = this;
const id = command.id as string;
const editor = em.Editor;

5
packages/core/src/commands/types.ts

@ -8,7 +8,6 @@ export enum CommandsEvents {
* });
*/
run = 'command:run',
_run = 'run',
/**
* @event `command:run:COMMAND-ID` Triggered on run of a specific command.
@ -16,7 +15,6 @@ export enum CommandsEvents {
* editor.on('command:run:my-command', ({ result, options }) => { ... });
*/
runCommand = 'command:run:',
_runCommand = 'run:',
/**
* @event `command:run:before:COMMAND-ID` Triggered before the command is called.
@ -38,7 +36,6 @@ export enum CommandsEvents {
* });
*/
abort = 'command:abort:',
_abort = 'abort:',
/**
* @event `command:stop` Triggered on stop of any command.
@ -48,7 +45,6 @@ export enum CommandsEvents {
* });
*/
stop = 'command:stop',
_stop = 'stop',
/**
* @event `command:stop:COMMAND-ID` Triggered on stop of a specific command.
@ -56,7 +52,6 @@ export enum CommandsEvents {
* editor.on('command:run:my-command', ({ result, options }) => { ... });
*/
stopCommand = 'command:stop:',
_stopCommand = 'stop:',
/**
* @event `command:stop:before:COMMAND-ID` Triggered before the command is called to stop.

10
packages/core/src/commands/view/CommandAbstract.ts

@ -111,11 +111,9 @@ export default class CommandAbstract<O extends ObjectAny = any> extends Model {
callRun(editor: Editor, options: any = {}) {
const { id } = this;
editor.trigger(`${CommandsEvents.runBeforeCommand}${id}`, { options });
editor.trigger(`${CommandsEvents._runCommand}${id}:before`, options);
if (options.abort) {
editor.trigger(`${CommandsEvents.abort}${id}`, { options });
editor.trigger(`${CommandsEvents._abort}${id}`, options);
return;
}
@ -124,9 +122,6 @@ export default class CommandAbstract<O extends ObjectAny = any> extends Model {
const data = { id, result, options };
editor.trigger(`${CommandsEvents.runCommand}${id}`, data);
editor.trigger(CommandsEvents.run, data);
// deprecated
editor.trigger(`${CommandsEvents._runCommand}${id}`, result, options);
editor.trigger(CommandsEvents._run, id, result, options);
return result;
}
@ -140,15 +135,10 @@ export default class CommandAbstract<O extends ObjectAny = any> extends Model {
const { id } = this;
const sender = options.sender || editor;
editor.trigger(`${CommandsEvents.stopBeforeCommand}${id}`, { options });
editor.trigger(`${CommandsEvents._stopCommand}${id}:before`, options);
const result = this.stop(editor, sender, options);
const data = { id, result, options };
editor.trigger(`${CommandsEvents.stopCommand}${id}`, data);
editor.trigger(CommandsEvents.stop, data);
// deprecated
editor.trigger(`${CommandsEvents._stopCommand}${id}`, result, options);
editor.trigger(CommandsEvents._stop, id, result, options);
return result;
}

Loading…
Cancel
Save