import React from 'react';
import { type ICommand, type TextState, TextAreaTextApi } from './';
import { type ContextStore, type ExecuteCommandState } from '../Context';
export const codePreview: ICommand = {
name: 'preview',
keyCommand: 'preview',
value: 'preview',
shortcuts: 'ctrlcmd+9',
buttonProps: { 'aria-label': 'Preview code (ctrl + 9)', title: 'Preview code (ctrl + 9)' },
icon: (
),
execute: (
state: TextState,
api: TextAreaTextApi,
dispatch?: React.Dispatch,
executeCommandState?: ExecuteCommandState,
shortcuts?: string[],
) => {
api.textArea.focus();
if (shortcuts && dispatch && executeCommandState) {
dispatch({ preview: 'preview' });
}
},
};
export const codeEdit: ICommand = {
name: 'edit',
keyCommand: 'preview',
value: 'edit',
shortcuts: 'ctrlcmd+7',
buttonProps: { 'aria-label': 'Edit code (ctrl + 7)', title: 'Edit code (ctrl + 7)' },
icon: (
),
execute: (
state: TextState,
api: TextAreaTextApi,
dispatch?: React.Dispatch,
executeCommandState?: ExecuteCommandState,
shortcuts?: string[],
) => {
api.textArea.focus();
if (shortcuts && dispatch && executeCommandState) {
dispatch({ preview: 'edit' });
}
},
};
export const codeLive: ICommand = {
name: 'live',
keyCommand: 'preview',
value: 'live',
shortcuts: 'ctrlcmd+8',
buttonProps: { 'aria-label': 'Live code (ctrl + 8)', title: 'Live code (ctrl + 8)' },
icon: (
),
execute: (
state: TextState,
api: TextAreaTextApi,
dispatch?: React.Dispatch,
executeCommandState?: ExecuteCommandState,
shortcuts?: string[],
) => {
api.textArea.focus();
if (shortcuts && dispatch && executeCommandState) {
dispatch({ preview: 'live' });
}
},
};