various functions used to create ui component.
creates a drop down that closes when clicked outside.
args:
Boolean) optional: whether to close when click outside it, default true.returns [dropDown, open, close].
HTMLElement): the drop down element.Function): function to open the drop down.Function): function to close the drop down.
create a drop down that open with a button
var [dropDown, open, close] = createDropDown();
dropDown.append('test');
editor.addButton('open drop down', {
icon: '<span>open</span>',
title: 'open',
action: () => open()
});
editor.mainEl.prepend(dropDown)
add a button that open a drop down with input.
args:
HyperRTE): an editor instance.String): the button name.Object): the definition object, inherit title, state, and icon from the button definition.
String): the input type or "textarea" for a textarea element.Boolean) optional: whether to add a reset button, call action with "initial", default: false.Function): a function called to produce an action, called by (value: String, editor: HyperRTE).any additional property is assign to the input element.
add an input for inserting html.
addInput(editor, 'insert html', {
title: 'insert html',
icon: '<span>insert html</span>',
action: (str) => $edit.insert(str, 'html')
})
type set to "color".type set to "number".add a button that open a drop down with multiple inputs.
args:
HyperRTE): an editor instance.String): the button name.Object): the definition object, inherit title, state, and icon from the button definition.
Object[]): an array of objects containing properties of input elements.Function): a function called to produce an action, called by (...value: String, editor: HyperRTE).add inputs for inserting image.
addInputs(editor, 'insert image', {
title: 'insert image',
icon: '<span>insert image</span>',
inputs: [
{type: 'text', placeholder: 'url'},
{type: 'number', placeholder: 'height'},
{type: 'number', placeholder: 'width'}
],
action: (url, height, width) => {
var img = document.createElement('img');
img.src = url;
img.width = width + 'px';
img.height = height + 'px';
$edit.insert(img, 'node')
}
})
add a button that open a drop down with a list of items.
args:
HyperRTE): an editor instance.String): the button name.Object): the definition object, inherit title, state, and icon from the button definition.
Array): the data array.Function): a function called to construct the list item, must return HTMLElement, called by (value: any, editor: HyperRTE).Function): a function called to produce an action, called by (...value: String, editor: HyperRTE).add list for adding headings.
addList(editor, 'heading', {
title: 'heading',
icon: '<span>heading</span>',
data: [1, 2, 3, 4, 5, 6],
item: (size) => {
var el = document.createElement('h' + size);
el.innerText = 'size ' + size;
return el
},
action: (size) => $edit.heading(size)
})
creates a dialog that closes when clicked outside.
args:
Boolean) optional: whether to close when click outside it, default true.returns [dialog, open, close].
HTMLElement): the dialog element.Function): function to open the dialog.Function): function to close the dialog.
create a dialog that open with a button
var [dialog, open, close] = createDialog();
dialog.append('test');
editor.addButton('open dialog', {
icon: '<span>open</span>',
title: 'open',
action: () => open()
});
editor.mainEl.prepend(dialog)
add a button that hide the main editor view and show a panel. args:
HyperRTE): an editor instance.String): the button name.Object): the definition object, inherit title, and icon from the button definition.
Function): a function that creates the panel, called by (editor: HyperRTE, back: Function)
and returns [panel: HTMLElement, onopen: Function].
Function): a function to close the panel.HTMLElement): the panel element.Function): a function called when opening the panel, to update the state of it, called by (editor: HyperRTE).add an panel to show source.
addPanel(editor, 'source', {
title: 'view source',
icon: '<span>source</span>',
creator: (editor, back) => {
var panel = document.createElement('div');
var backButton = document.createElement('button');
backButton.innerText = 'back';
backButton.addEventListener('click', back);
var sourceEl = document.createElement('div');
panel.append(backButton, sourceEl);
return [panel, () => sourceEl.innerText = editor.content]
}
})
create a menu that can be opened and closed.
args:
HyperRTE): an editor instance.Object): object of functions named according to the item name inside menu, called when clicked with (editor: HyperRTE).add a button that opens a menu.
args:
HyperRTE): an editor instance.String): the button name.Object): the definition object, inherit title, state, and icon from the button definition,
any additonal properties are traited as menu items.creates a button that open a menu of text snippets:
addMenu(editor, 'snippets', {
title: 'insert snippets',
icon: '<span>snippets</span>',
'hello world': () => editor.doAction('snippet', () => $edit.insert('hello world', 'text')),
'js is good': () => editor.doAction('snippet', () => $edit.insert('js is good', 'text')),
'hyper is better': () => editor.doAction('snippet', () => $edit.insert('hyper is better', 'text'))
})