// Copyright (c) ppy Pty Ltd . Licensed under the GNU Affero General Public License v3.0. // See the LICENCE file in the repository root for full licence text. import { snakeCase } from 'lodash'; import * as React from 'react'; import { classWithModifiers, Modifiers } from 'utils/css'; import { trans } from 'utils/lang'; import { wikiUrl } from 'utils/url'; type ChangeType = 'cancel' | 'save'; export interface OnChangeProps { event?: React.SyntheticEvent; hasChanged: boolean; type: ChangeType; value: string | undefined; } interface Props { disabled: boolean; ignoreEsc: boolean; modifiers?: Modifiers; onChange: (props: OnChangeProps) => void; placeholder?: string; rawValue: string; } export default class BbcodeEditor extends React.Component { static readonly defaultProps = { disabled: false, ignoreEsc: false, }; private readonly bodyRef = React.createRef(); private readonly sizeSelectRef = React.createRef(); readonly cancel = (event?: React.SyntheticEvent) => { if (this.bodyRef.current?.value !== this.props.rawValue && !confirm(trans('common.confirmation_unsaved'))) { return; } if (this.bodyRef.current != null) { this.bodyRef.current.value = this.props.rawValue; } this.sendOnChange({ event, type: 'cancel' }); }; componentDidMount() { if (this.sizeSelectRef.current != null) { this.sizeSelectRef.current.value = ''; } if (this.bodyRef.current != null) { this.bodyRef.current.selectionEnd = 0; this.bodyRef.current.focus(); } } render() { let blockClass = classWithModifiers('bbcode-editor', this.props.modifiers); blockClass += ' js-bbcode-preview--form'; return (