mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-15 08:28:52 +08:00
Ran eslint fix on existing codebase
Had to do some manual fixing of the app.js file due to misplaced comments
This commit is contained in:
@ -10,8 +10,8 @@ function elemIsCodeBlock(elem) {
|
||||
*/
|
||||
function showPopup(editor, code, language, callback) {
|
||||
window.$components.first('code-editor').open(code, language, (newCode, newLang) => {
|
||||
callback(newCode, newLang)
|
||||
editor.focus()
|
||||
callback(newCode, newLang);
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ function defineCodeBlockCustomElement(editor) {
|
||||
}
|
||||
|
||||
getLanguage() {
|
||||
const getLanguageFromClassList = (classes) => {
|
||||
const getLanguageFromClassList = classes => {
|
||||
const langClasses = classes.split(' ').filter(cssClass => cssClass.startsWith('language-'));
|
||||
return (langClasses[0] || '').replace('language-', '');
|
||||
};
|
||||
@ -114,12 +114,12 @@ function defineCodeBlockCustomElement(editor) {
|
||||
this.style.height = `${height}px`;
|
||||
|
||||
const container = this.shadowRoot.querySelector('.CodeMirrorContainer');
|
||||
const renderEditor = (Code) => {
|
||||
const renderEditor = Code => {
|
||||
this.editor = Code.wysiwygView(container, this.shadowRoot, content, this.getLanguage());
|
||||
setTimeout(() => this.style.height = null, 12);
|
||||
};
|
||||
|
||||
window.importVersioned('code').then((Code) => {
|
||||
window.importVersioned('code').then(Code => {
|
||||
const timeout = (Date.now() - connectedTime < 20) ? 20 : 0;
|
||||
setTimeout(() => renderEditor(Code), timeout);
|
||||
});
|
||||
@ -135,26 +135,25 @@ function defineCodeBlockCustomElement(editor) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
win.customElements.define('code-block', CodeBlockElement);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Editor} editor
|
||||
* @param {String} url
|
||||
*/
|
||||
function register(editor, url) {
|
||||
|
||||
editor.ui.registry.addIcon('codeblock', '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1Zm1 2v14h14V5Z"/><path d="M11.103 15.423c.277.277.277.738 0 .922a.692.692 0 0 1-1.106 0l-4.057-3.78a.738.738 0 0 1 0-1.107l4.057-3.872c.276-.277.83-.277 1.106 0a.724.724 0 0 1 0 1.014L7.6 12.012ZM12.897 8.577c-.245-.312-.2-.675.08-.955.28-.281.727-.27 1.027.033l4.057 3.78a.738.738 0 0 1 0 1.107l-4.057 3.872c-.277.277-.83.277-1.107 0a.724.724 0 0 1 0-1.014l3.504-3.412z"/></svg>')
|
||||
editor.ui.registry.addIcon('codeblock', '<svg width="24" height="24"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1Zm1 2v14h14V5Z"/><path d="M11.103 15.423c.277.277.277.738 0 .922a.692.692 0 0 1-1.106 0l-4.057-3.78a.738.738 0 0 1 0-1.107l4.057-3.872c.276-.277.83-.277 1.106 0a.724.724 0 0 1 0 1.014L7.6 12.012ZM12.897 8.577c-.245-.312-.2-.675.08-.955.28-.281.727-.27 1.027.033l4.057 3.78a.738.738 0 0 1 0 1.107l-4.057 3.872c-.277.277-.83.277-1.107 0a.724.724 0 0 1 0-1.014l3.504-3.412z"/></svg>');
|
||||
|
||||
editor.ui.registry.addButton('codeeditor', {
|
||||
tooltip: 'Insert code block',
|
||||
icon: 'codeblock',
|
||||
onAction() {
|
||||
editor.execCommand('codeeditor');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
editor.ui.registry.addButton('editcodeeditor', {
|
||||
@ -162,7 +161,7 @@ function register(editor, url) {
|
||||
icon: 'edit-block',
|
||||
onAction() {
|
||||
editor.execCommand('codeeditor');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
editor.addCommand('codeeditor', () => {
|
||||
@ -185,14 +184,14 @@ function register(editor, url) {
|
||||
});
|
||||
|
||||
editor.on('dblclick', event => {
|
||||
let selectedNode = editor.selection.getNode();
|
||||
const selectedNode = editor.selection.getNode();
|
||||
if (elemIsCodeBlock(selectedNode)) {
|
||||
showPopupForCodeBlock(editor, selectedNode);
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('PreInit', () => {
|
||||
editor.parser.addNodeFilter('pre', function(elms) {
|
||||
editor.parser.addNodeFilter('pre', elms => {
|
||||
for (const el of elms) {
|
||||
const wrapper = tinymce.html.Node.create('code-block', {
|
||||
contenteditable: 'false',
|
||||
@ -207,13 +206,13 @@ function register(editor, url) {
|
||||
}
|
||||
});
|
||||
|
||||
editor.parser.addNodeFilter('code-block', function(elms) {
|
||||
editor.parser.addNodeFilter('code-block', elms => {
|
||||
for (const el of elms) {
|
||||
el.attr('contenteditable', 'false');
|
||||
}
|
||||
});
|
||||
|
||||
editor.serializer.addNodeFilter('code-block', function(elms) {
|
||||
editor.serializer.addNodeFilter('code-block', elms => {
|
||||
for (const el of elms) {
|
||||
el.unwrap();
|
||||
}
|
||||
@ -221,12 +220,12 @@ function register(editor, url) {
|
||||
});
|
||||
|
||||
editor.ui.registry.addContextToolbar('codeeditor', {
|
||||
predicate: function (node) {
|
||||
predicate(node) {
|
||||
return node.nodeName.toLowerCase() === 'code-block';
|
||||
},
|
||||
items: 'editcodeeditor',
|
||||
position: 'node',
|
||||
scope: 'node'
|
||||
scope: 'node',
|
||||
});
|
||||
|
||||
editor.on('PreInit', () => {
|
||||
@ -240,4 +239,4 @@ function register(editor, url) {
|
||||
*/
|
||||
export function getPlugin(options) {
|
||||
return register;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user