From 721d2ae7cb2df0be05345701075a229e12a6417f Mon Sep 17 00:00:00 2001 From: lassespilling Date: Tue, 18 Jun 2024 10:37:10 +0200 Subject: [PATCH] merge https://github.com/zenoamaro/react-quill/pull/980 --- src/index.tsx | 177 +++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 87 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index f83a11db..5047508f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,8 +3,7 @@ React-Quill https://github.com/zenoamaro/react-quill */ -import React from 'react'; -import ReactDOM from 'react-dom'; +import React, { createRef } from 'react'; import isEqual from 'lodash/isEqual'; import Quill, { @@ -23,49 +22,49 @@ namespace ReactQuill { export type Range = RangeStatic | null; export interface QuillOptions extends QuillOptionsStatic { - tabIndex?: number, + tabIndex?: number; } export interface ReactQuillProps { - bounds?: string | HTMLElement, - children?: React.ReactElement, - className?: string, - defaultValue?: Value, - formats?: string[], - id?: string, - modules?: StringMap, + bounds?: string | HTMLElement; + children?: React.ReactElement; + className?: string; + defaultValue?: Value; + formats?: string[]; + id?: string; + modules?: StringMap; onChange?( value: string, delta: DeltaStatic, source: Sources, - editor: UnprivilegedEditor, - ): void, + editor: UnprivilegedEditor + ): void; onChangeSelection?( selection: Range, source: Sources, - editor: UnprivilegedEditor, - ): void, + editor: UnprivilegedEditor + ): void; onFocus?( selection: Range, source: Sources, - editor: UnprivilegedEditor, - ): void, + editor: UnprivilegedEditor + ): void; onBlur?( previousSelection: Range, source: Sources, - editor: UnprivilegedEditor, - ): void, - onKeyDown?: React.EventHandler, - onKeyPress?: React.EventHandler, - onKeyUp?: React.EventHandler, - placeholder?: string, - preserveWhitespace?: boolean, - readOnly?: boolean, - scrollingContainer?: string | HTMLElement, - style?: React.CSSProperties, - tabIndex?: number, - theme?: string, - value?: Value, + editor: UnprivilegedEditor + ): void; + onKeyDown?: React.EventHandler; + onKeyPress?: React.EventHandler; + onKeyUp?: React.EventHandler; + placeholder?: string; + preserveWhitespace?: boolean; + readOnly?: boolean; + scrollingContainer?: string | HTMLElement; + style?: React.CSSProperties; + tabIndex?: number; + theme?: string; + value?: Value; } export interface UnprivilegedEditor { @@ -86,12 +85,13 @@ import ReactQuillProps = ReactQuill.ReactQuillProps; import UnprivilegedEditor = ReactQuill.UnprivilegedEditor; interface ReactQuillState { - generation: number, + generation: number; } class ReactQuill extends React.Component { + editingAreaRef = createRef(); - static displayName = 'React Quill' + static displayName = 'React Quill'; /* Export Quill to be able to call `register` @@ -108,7 +108,7 @@ class ReactQuill extends React.Component { 'bounds', 'theme', 'children', - ] + ]; /* Changing one of these props should cause a regular update. These are mostly @@ -127,86 +127,89 @@ class ReactQuill extends React.Component { 'onKeyPress', 'onKeyDown', 'onKeyUp', - ] + ]; static defaultProps = { theme: 'snow', modules: {}, readOnly: false, - } + }; state: ReactQuillState = { generation: 0, - } + }; /* The Quill Editor instance. */ - editor?: Quill + editor?: Quill; /* Reference to the element holding the Quill editing area. */ - editingArea?: React.ReactInstance | null + editingArea?: React.ReactInstance | null; /* Tracks the internal value of the Quill editor */ - value: Value + value: Value; /* Tracks the internal selection of the Quill editor */ - selection: Range = null + selection: Range = null; /* Used to compare whether deltas from `onChange` are being used as `value`. */ - lastDeltaChangeSet?: DeltaStatic + lastDeltaChangeSet?: DeltaStatic; /* Stores the contents of the editor to be restored after regeneration. */ regenerationSnapshot?: { - delta: DeltaStatic, - selection: Range, - } + delta: DeltaStatic; + selection: Range; + }; /* A weaker, unprivileged proxy for the editor that does not allow accidentally modifying editor state. */ - unprivilegedEditor?: UnprivilegedEditor + unprivilegedEditor?: UnprivilegedEditor; constructor(props: ReactQuillProps) { super(props); - const value = this.isControlled()? props.value : props.defaultValue; + const value = this.isControlled() ? props.value : props.defaultValue; this.value = value ?? ''; } validateProps(props: ReactQuillProps): void { - if (React.Children.count(props.children) > 1) throw new Error( - 'The Quill editing area can only be composed of a single React element.' - ); + if (React.Children.count(props.children) > 1) + throw new Error( + 'The Quill editing area can only be composed of a single React element.' + ); if (React.Children.count(props.children)) { const child = React.Children.only(props.children); - if (child?.type === 'textarea') throw new Error( - 'Quill does not support editing on a