/** * Official HugeRTE React component * Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc. * Copyright (c) 2024 HugeRTE contributors * Licensed under the MIT license (https://github.com/hugerte/hugerte-react/blob/main/LICENSE.TXT) */ import * as React from 'react'; import { IEvents } from '../Events'; import type { Editor as HugeRTEEditor, HugeRTE } from 'hugerte'; type OmitStringIndexSignature = { [K in keyof T as string extends K ? never : K]: T[K]; }; interface DoNotUse { __brand: T; } type OmittedInitProps = 'selector' | 'target' | 'readonly'; type EditorOptions = Parameters[0]; export type InitOptions = Omit, OmittedInitProps> & { selector?: DoNotUse<'selector prop is handled internally by the component'>; target?: DoNotUse<'target prop is handled internally by the component'>; readonly?: DoNotUse<'readonly prop is overridden by the component, use the `disabled` prop instead'>; } & { [key: string]: unknown; }; export type Version = `${'1'}${'' | `.${number}` | `.${number}.${number}`}`; export interface IProps { /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#id React Tech Ref - id} * @description The ID of the element to render the editor into. */ id: string; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#inline React Tech Ref - inline} * @description Whether the editor should be rendered inline. Equivalent to the `inline` option in HugeRTE. */ inline: boolean; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#initialvalue React Tech Ref - initialValue} * @description The initial HTML content of the editor. * * IMPORTANT: Ensure that this is **not** updated by `onEditorChange` or the editor will be unusable. */ initialValue: string; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#oneditorchange React Tech Ref - onEditorChange} * @description Used to store the state of the editor outside the component. Typically used for controlled components. * @param a The current HTML content of the editor. * @param editor The HugeRTE editor instance. * @returns void */ onEditorChange: (a: string, editor: HugeRTEEditor) => void; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#value React Tech Ref - value} * @description The current HTML content of the editor. Typically used for controlled components. */ value: string; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#init React Tech Ref - init} * @description Additional settings passed to `hugerte.init()` when initializing the editor. */ init: InitOptions; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#tagname React Tech Ref - tagName} * @description The tag name of the element to render the editor into. Only valid when `inline` is `true`. */ tagName: string; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#tabIndex React Tech Ref - tabIndex} * @description The tab index of the element that the editor wraps. */ tabIndex: number; /** * @description The HugeRTE version to use when loading from jsDelivr CDN. By default, version 1 * (that is, the latest minor and patch release of the major version 1) will be used. * For more info about the possible version formats, see the {@link https://www.jsdelivr.com/documentation#id-npm jsDelivr documentation}. */ cdnVersion: Version; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#plugins React Tech Ref - plugins} * @description The plugins to load into the editor. Equivalent to the `plugins` option in HugeRTE. */ plugins: NonNullable; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#toolbar React Tech Ref - toolbar} * @description The toolbar to load into the editor. Equivalent to the `toolbar` option in HugeRTE. */ toolbar: NonNullable; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#disabled React Tech Ref - disabled} * @description Whether the editor should be "disabled" (read-only). */ disabled: boolean; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#textareaname React Tech Ref - textareaName} * @description Set the `name` attribute of the `textarea` element used for the editor in forms. Only valid in iframe mode. */ textareaName: string; /** * @description The URL of the HugeRTE script to lazy load. */ hugerteScriptSrc: string; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#rollback React Tech Ref - rollback} * @description The number of milliseconds to wait before reverting to the previous value when the editor's content changes. */ rollback: number | false; /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/#scriptloading React Tech Ref - scriptLoading} * @description Options for how the HugeRTE script should be loaded. * @property async Whether the script should be loaded with the `async` attribute. * @property defer Whether the script should be loaded with the `defer` attribute. * @property delay The number of milliseconds to wait before loading the script. */ scriptLoading: { async?: boolean; defer?: boolean; delay?: number; }; } export interface IAllProps extends Partial, Partial { } /** * @see {@link https://www.hugerte.org/docs/hugerte/1/react-ref/ HugeRTE React Technical Reference} */ export declare class Editor extends React.Component { static defaultProps: Partial; editor?: HugeRTEEditor; private id; private elementRef; private inline; private currentContent?; private boundHandlers; private rollbackTimer; private valueCursor; constructor(props: Partial); private get view(); componentDidUpdate(prevProps: Partial): void; componentDidMount(): void; componentWillUnmount(): void; render(): React.ReactElement<{ ref: React.RefObject; id: string; tabIndex: number | undefined; }, string | React.JSXElementConstructor>; private beforeInputEvent; private renderInline; private renderIframe; private getScriptSources; private getInitialValue; private bindHandlers; private rollbackChange; private handleBeforeInput; private handleBeforeInputSpecial; private handleEditorChange; private handleEditorChangeSpecial; private initialise; } export {};