Add button shortcuts and typings

pull/141/head
Jeroen Akkerman 4 years ago
parent 8c01edd7cd
commit b85bdde0ed

@ -320,7 +320,7 @@
.editor-toolbar .easymde-dropdown { .editor-toolbar .easymde-dropdown {
position: relative; position: relative;
background: linear-gradient(to bottom right, #fff 0%, #fff 84%, #333 50%, #333 100%); background: linear-gradient(to bottom right, #fff 0%, #fff 84%, #333 50%, #333 100%);
border-radius: 0px; border-radius: 0;
border: 1px solid #fff; border: 1px solid #fff;
} }
@ -332,7 +332,7 @@
display: none; display: none;
position: absolute; position: absolute;
background-color: #f9f9f9; background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
padding: 8px; padding: 8px;
z-index: 2; z-index: 2;
top: 30px; top: 30px;

@ -119,8 +119,17 @@ function createToolbarDropdown(options, enableTooltips, shortcuts, parent) {
var content = document.createElement('div'); var content = document.createElement('div');
content.className = 'easymde-dropdown-content'; content.className = 'easymde-dropdown-content';
for (var childrenIndex = 0; childrenIndex < options.children.length; childrenIndex++) { for (var childrenIndex = 0; childrenIndex < options.children.length; childrenIndex++) {
var child = createToolbarButton(options.children[childrenIndex], true, enableTooltips, shortcuts, 'button', parent);
content.appendChild(child); var child = options.children[childrenIndex];
var childElement;
if (typeof child === 'string' && child in toolbarBuiltInButtons) {
childElement = createToolbarButton(toolbarBuiltInButtons[child], true, enableTooltips, shortcuts, 'button', parent);
} else {
childElement = createToolbarButton(child, true, enableTooltips, shortcuts, 'button', parent);
}
content.appendChild(childElement);
} }
el.appendChild(content); el.appendChild(content);
return el; return el;
@ -1791,7 +1800,7 @@ EasyMDE.prototype.markdown = function (text) {
// Convert the markdown to HTML // Convert the markdown to HTML
var htmlText = marked(text); var htmlText = marked(text);
// Sanitize HTML // Sanitize HTML
if (this.options.renderingConfig && typeof this.options.renderingConfig.sanitizerFunction === 'function') { if (this.options.renderingConfig && typeof this.options.renderingConfig.sanitizerFunction === 'function') {
htmlText = this.options.renderingConfig.sanitizerFunction.call(this, htmlText); htmlText = this.options.renderingConfig.sanitizerFunction.call(this, htmlText);

@ -43,18 +43,18 @@ const editor2 = new EasyMDE({
{ {
name: 'bold', name: 'bold',
action: EasyMDE.toggleBold, action: EasyMDE.toggleBold,
className: 'fa fa-bolt', className: 'fa fas fa-bolt',
title: 'Bold' title: 'Bold'
}, },
'|', '|',
'undo',
{ {
// Separator
name: 'alert', name: 'alert',
action: (editor: EasyMDE) => { action: (editor: EasyMDE) => {
alert('This is from a custom button action!'); alert('This is from a custom button action!');
// Custom functions have access to the `editor` instance. // Custom functions have access to the `editor` instance.
}, },
className: 'fa fa-star', className: 'fa fas fa-star',
title: 'A Custom Button', title: 'A Custom Button',
noDisable: undefined, noDisable: undefined,
noMobile: false noMobile: false
@ -67,6 +67,29 @@ const editor2 = new EasyMDE({
title: 'A Custom Link', title: 'A Custom Link',
noDisable: true, noDisable: true,
noMobile: true noMobile: true
},
'preview',
{
name: 'links',
className: 'fa fas fa-arrow-down',
title: 'A Custom Link',
children: [
{
name: 'link',
action: 'https://github.com/Ionaru/easy-markdown-editor',
className: 'fa fab fa-github',
title: 'A Custom Link',
noDisable: true,
noMobile: true
},
'preview',
{
name: 'bold',
action: EasyMDE.toggleBold,
className: 'fa fas fa-bold',
title: 'Bold'
},
]
} }
] ]
}); });

34
types/easymde.d.ts vendored

@ -22,6 +22,29 @@
/// <reference types="codemirror"/> /// <reference types="codemirror"/>
/// <reference types="marked"/> /// <reference types="marked"/>
interface ArrayOneOrMore<T> extends Array<T> {
0: T
}
type ToolbarButton =
'strikethrough'
| 'code'
| 'table'
| 'redo'
| 'heading'
| 'undo'
| 'heading-bigger'
| 'heading-smaller'
| 'heading-1'
| 'heading-2'
| 'heading-3'
| 'clean-block'
| 'horizontal-rule'
| 'preview'
| 'side-by-side'
| 'fullscreen'
| 'guide';
declare namespace EasyMDE { declare namespace EasyMDE {
interface AutoSaveOptions { interface AutoSaveOptions {
enabled?: boolean; enabled?: boolean;
@ -87,6 +110,15 @@ declare namespace EasyMDE {
onUpdate: (element: HTMLElement) => void; onUpdate: (element: HTMLElement) => void;
} }
interface ToolbarDropdownIcon {
name: string;
children: ArrayOneOrMore<ToolbarIcon | ToolbarButton>;
className: string;
title: string;
noDisable?: boolean;
noMobile?: boolean;
}
interface ToolbarIcon { interface ToolbarIcon {
name: string; name: string;
action: string | ((editor: EasyMDE) => void); action: string | ((editor: EasyMDE) => void);
@ -139,7 +171,7 @@ declare namespace EasyMDE {
status?: boolean | ReadonlyArray<string | StatusBarItem>; status?: boolean | ReadonlyArray<string | StatusBarItem>;
styleSelectedText?: boolean; styleSelectedText?: boolean;
tabSize?: number; tabSize?: number;
toolbar?: boolean | ReadonlyArray<'|' | ToolbarIcon>; toolbar?: boolean | ReadonlyArray<'|' | ToolbarButton | ToolbarIcon | ToolbarDropdownIcon>;
toolbarTips?: boolean; toolbarTips?: boolean;
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void; onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
theme?: string; theme?: string;

Loading…
Cancel
Save