also called HyperRTE is the main class of the library that wrap all the functionality in a simple api.
takes options and return editor.
args:
returns: an instance of HyperRTE class.
a plain object containing options.
String | HTMLElement): the selector or the element to wrap the editor.Function[]): an array of functions containing the plugins to use, called with (rte: HyperRTE, options: Object).String[]): an array of string cotaining the layout of the toolbar, each item is a button name or "separator" for a button separator, if empty use all defined buttons according to insertion order.String): a path for the icons folder.Object): for clean configs.
Boolean): whether to clean after each action, default true.String[]): an array containing the tag name of element to not merge.String[]): an array containing the tag name of element to not clean.String[]): an array containing the tag name of element to skip cleaning.the editor class has a simple event system that allow for easy event based programming.
listen for an event and invoke a callback.
args:
String): the event name.Function): the callback function to be called.unlisten for an event by removing the callback.
args:
String): the event name.Function): the callback function to be called.listen for an event and invoke a callback one time.
args:
String): the event name.Function): the callback function to be called.triggers an event supplied with arguments.
args:
String): the event name....any): the argument to be supplied.the listners are called with the current instance as first argumment.
"stateChange": triggered to update the state of the buttons."beforeAction": triggered before every action, use it to do pre-action activities, called with (actionName: String)."afterAction": triggered after every action, use it to do post-action activities, called with (actionName: String)."input": triggered on every input event, called with (event: InputEvent)."cut": triggered on every cut event, called with (event: ClipboardEvent)."copy": triggered on every copy event, called with (event: ClipboardEvent)."paste": triggered on every paste event, called with (event: ClipboardEvent)."export": triggered when exporting the content, called with shared html element cloned from the content element (el: HTMLElement)."showMain": triggered on closing a panel."hideMain": triggered on opening a panel.add a button to the button definitions.
args:
String): the button name.Object): the button definition.
String) optional: title to show on hover.Function) optional: a function called on every state change, called with (editor: HyperRTE, el: HTMLElement), and must return a boolean whether to highlight the button.action (Function) optional: a function called on when clicked to start and action, called with (editor: HyperRTE).
and one of:
String): a html string represent the icon.Function): a function to construct the button, called with the button element.a simple button with icon:
editor.addButton('log', {
title: 'log the content',
icon: '<img src="info.svg">',
state: (editor) => editor.content.length > 50, //highlight when content above 50 characters
action: (editor) => console.log(editor.content)
})
an example on creator:
editor.addButton('log', {
title: 'log the content',
creator: (el) => el.append('log'),
action: (editor) => console.log(editor.content)
})
actions are key component of the editor structure, they imply an change in format (like bold/italic) or insertion or removing of items or a big change in the content (like undo/redo).
actions are not done unless the input is focus or if they are forced.
trigger an action of type “name”.
args:
String): the name of the action.Function): the handler of the action.Boolean): whether to trigger even if input is not focus, default false.there are various method and fields responsible for content managment.
return the content of the editor as html string.
set the content of the editor as html string
return the content of the editor as html string, without any edit time content (like elements and classes used internally not part of the content).
cleaning managment is very usefull feature in HyperRTE as it is responsible for producing clean and non-empty html structure.
clean the dom.
various methods to manage the selection
focus the content element.
capture the selection and return a funtion, once called reselect the selection.