1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-06 09:19:22 +02:00

Tools: Apply rule @typescript-eslint/type-annotation-spacing

This commit is contained in:
Laurent Cozic
2020-11-12 19:13:28 +00:00
parent 62feb7ff60
commit d20694e52c
291 changed files with 2205 additions and 2203 deletions

View File

@@ -100,7 +100,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
resetScroll: () => {
resetScroll();
},
scrollTo: (options:ScrollOptions) => {
scrollTo: (options: ScrollOptions) => {
if (options.type === ScrollOptionTypes.Hash) {
if (!webviewRef.current) return;
webviewRef.current.wrappedInstance.send('scrollToHash', options.value as string);
@@ -156,7 +156,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
selectedHtml: () => {
return selectedText();
},
replaceSelection: (value:any) => {
replaceSelection: (value: any) => {
return editorRef.current.replaceSelection(value);
},
textBold: () => wrapSelectionWithStrings('**', '**', _('strong text')),
@@ -293,9 +293,9 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
menu.popup(bridge().window());
}, [props.content, editorCutText, editorPasteText, editorCopyText, onEditorPaste]);
const loadScript = async (script:any) => {
const loadScript = async (script: any) => {
return new Promise((resolve) => {
let element:any = document.createElement('script');
let element: any = document.createElement('script');
if (script.src.indexOf('.css') >= 0) {
element = document.createElement('link');
element.rel = 'stylesheet';
@@ -324,7 +324,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
let cancelled = false;
async function loadScripts() {
const scriptsToLoad:{src: string, id:string, loaded: boolean}[] = [
const scriptsToLoad: {src: string, id: string, loaded: boolean}[] = [
{
src: 'node_modules/codemirror/addon/dialog/dialog.css',
id: 'codemirrorDialogStyle',

View File

@@ -13,7 +13,7 @@ interface ToolbarProps {
toolbarButtonInfos: ToolbarButtonInfo[],
}
function styles_(props:ToolbarProps) {
function styles_(props: ToolbarProps) {
return buildStyle('CodeMirrorToolbar', props.themeId, () => {
return {
root: {
@@ -26,7 +26,7 @@ function styles_(props:ToolbarProps) {
const toolbarButtonUtils = new ToolbarButtonUtils(CommandService.instance());
function Toolbar(props:ToolbarProps) {
function Toolbar(props: ToolbarProps) {
const styles = styles_(props);
return <ToolbarBase style={styles.root} items={props.toolbarButtonInfos} />;
}

View File

@@ -85,7 +85,7 @@ export function useScrollHandler(editorRef: any, webviewRef: any, onScroll: Func
}
export function useRootSize(dependencies:any) {
export function useRootSize(dependencies: any) {
const { rootRef } = dependencies;
const [rootSize, setRootSize] = useState({ width: 0, height: 0 });

View File

@@ -22,7 +22,7 @@ const { themeStyle } = require('@joplin/lib/theme');
const { clipboard } = require('electron');
const supportedLocales = require('./supportedLocales');
function markupRenderOptions(override:any = null) {
function markupRenderOptions(override: any = null) {
return {
plugins: {
checkbox: {
@@ -37,7 +37,7 @@ function markupRenderOptions(override:any = null) {
};
}
function findBlockSource(node:any) {
function findBlockSource(node: any) {
const sources = node.getElementsByClassName('joplin-source');
if (!sources.length) throw new Error('No source for node');
const source = sources[0];
@@ -51,7 +51,7 @@ function findBlockSource(node:any) {
};
}
function newBlockSource(language:string = '', content:string = ''):any {
function newBlockSource(language: string = '', content: string = ''): any {
const fence = language === 'katex' ? '$$' : '```';
const fenceLanguage = language === 'katex' ? '' : language;
@@ -64,7 +64,7 @@ function newBlockSource(language:string = '', content:string = ''):any {
};
}
function findEditableContainer(node:any):any {
function findEditableContainer(node: any): any {
while (node) {
if (node.classList && node.classList.contains('joplin-editable')) return node;
node = node.parentNode;
@@ -72,7 +72,7 @@ function findEditableContainer(node:any):any {
return null;
}
function editableInnerHtml(html:string):string {
function editableInnerHtml(html: string): string {
const temp = document.createElement('div');
temp.innerHTML = html;
const editable = temp.getElementsByClassName('joplin-editable');
@@ -80,14 +80,14 @@ function editableInnerHtml(html:string):string {
return editable[0].innerHTML;
}
function dialogTextArea_keyDown(event:any) {
function dialogTextArea_keyDown(event: any) {
if (event.key === 'Tab') {
window.requestAnimationFrame(() => event.target.focus());
}
}
let markupToHtml_ = new MarkupToHtml();
function stripMarkup(markupLanguage:number, markup:string, options:any = null) {
function stripMarkup(markupLanguage: number, markup: string, options: any = null) {
if (!markupToHtml_) markupToHtml_ = new MarkupToHtml();
return markupToHtml_.stripMarkup(markupLanguage, markup, options);
}
@@ -95,7 +95,7 @@ function stripMarkup(markupLanguage:number, markup:string, options:any = null) {
// Allows pressing tab in a textarea to input an actual tab (instead of changing focus)
// taboverride will take care of actually inserting the tab character, while the keydown
// event listener will override the default behaviour, which is to focus the next field.
function enableTextAreaTab(enable:boolean) {
function enableTextAreaTab(enable: boolean) {
const textAreas = document.getElementsByClassName('tox-textarea');
for (const textArea of textAreas) {
taboverride.set(textArea, enable);
@@ -115,22 +115,22 @@ interface TinyMceCommand {
}
interface JoplinCommandToTinyMceCommands {
[key:string]: TinyMceCommand,
[key: string]: TinyMceCommand,
}
const joplinCommandToTinyMceCommands:JoplinCommandToTinyMceCommands = {
const joplinCommandToTinyMceCommands: JoplinCommandToTinyMceCommands = {
'textBold': { name: 'mceToggleFormat', value: 'bold' },
'textItalic': { name: 'mceToggleFormat', value: 'italic' },
'textLink': { name: 'mceLink' },
'search': { name: 'SearchReplace' },
};
let loadedCssFiles_:string[] = [];
let loadedJsFiles_:string[] = [];
let dispatchDidUpdateIID_:any = null;
let changeId_:number = 1;
let loadedCssFiles_: string[] = [];
let loadedJsFiles_: string[] = [];
let dispatchDidUpdateIID_: any = null;
let changeId_: number = 1;
const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
const TinyMCE = (props: NoteBodyEditorProps, ref: any) => {
const [editor, setEditor] = useState(null);
const [scriptLoaded, setScriptLoaded] = useState(false);
const [editorReady, setEditorReady] = useState(false);
@@ -162,7 +162,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
usePluginServiceRegistration(ref);
const dispatchDidUpdate = (editor:any) => {
const dispatchDidUpdate = (editor: any) => {
if (dispatchDidUpdateIID_) shim.clearTimeout(dispatchDidUpdateIID_);
dispatchDidUpdateIID_ = shim.setTimeout(() => {
dispatchDidUpdateIID_ = null;
@@ -170,7 +170,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
}, 10);
};
const insertResourcesIntoContent = useCallback(async (filePaths:string[] = null, options:any = null) => {
const insertResourcesIntoContent = useCallback(async (filePaths: string[] = null, options: any = null) => {
const resourceMd = await commandAttachFileToBody('', filePaths, options);
if (!resourceMd) return;
const result = await props.markupToHtml(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, resourceMd, markupRenderOptions({ bodyOnly: true }));
@@ -182,7 +182,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
const insertResourcesIntoContentRef = useRef(null);
insertResourcesIntoContentRef.current = insertResourcesIntoContent;
const onEditorContentClick = useCallback((event:any) => {
const onEditorContentClick = useCallback((event: any) => {
const nodeName = event.target ? event.target.nodeName : '';
if (nodeName === 'INPUT' && event.target.getAttribute('type') === 'checkbox') {
@@ -216,7 +216,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
resetScroll: () => {
if (editor) editor.getWin().scrollTo(0,0);
},
scrollTo: (options:ScrollOptions) => {
scrollTo: (options: ScrollOptions) => {
if (!editor) return;
if (options.type === ScrollOptionTypes.Hash) {
@@ -232,11 +232,11 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
throw new Error(`Unsupported scroll options: ${options.type}`);
}
},
supportsCommand: (name:string) => {
supportsCommand: (name: string) => {
// TODO: should also handle commands that are not in this map (insertText, focus, etc);
return !!joplinCommandToTinyMceCommands[name];
},
execCommand: async (cmd:EditorCommand) => {
execCommand: async (cmd: EditorCommand) => {
if (!editor) return false;
reg.logger().debug('TinyMce: execCommand', cmd);
@@ -263,14 +263,14 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
if (commandProcessed) return true;
const additionalCommands:any = {
const additionalCommands: any = {
selectedText: () => {
return stripMarkup(MarkupToHtml.MARKUP_LANGUAGE_HTML, editor.selection.getContent());
},
selectedHtml: () => {
return editor.selection.getContent();
},
replaceSelection: (value:any) => {
replaceSelection: (value: any) => {
editor.selection.setContent(value);
},
};
@@ -284,7 +284,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
return false;
}
const tinyMceCmd:TinyMceCommand = { ...joplinCommandToTinyMceCommands[cmd.name] };
const tinyMceCmd: TinyMceCommand = { ...joplinCommandToTinyMceCommands[cmd.name] };
if (!('ui' in tinyMceCmd)) tinyMceCmd.ui = false;
if (!('value' in tinyMceCmd)) tinyMceCmd.value = null;
@@ -301,9 +301,9 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
// module would not load these extra files.
// -----------------------------------------------------------------------------------------
const loadScript = async (script:any) => {
const loadScript = async (script: any) => {
return new Promise((resolve) => {
let element:any = document.createElement('script');
let element: any = document.createElement('script');
if (script.src.indexOf('.css') >= 0) {
element = document.createElement('link');
element.rel = 'stylesheet';
@@ -332,7 +332,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
let cancelled = false;
async function loadScripts() {
const scriptsToLoad:any[] = [
const scriptsToLoad: any[] = [
{
src: 'node_modules/tinymce/tinymce.min.js',
id: 'tinyMceScript',
@@ -510,7 +510,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
const loadEditor = async () => {
const language = closestSupportedLocale(props.locale, true, supportedLocales);
const pluginCommandNames:string[] = [];
const pluginCommandNames: string[] = [];
const infos = pluginUtils.viewInfosByType(props.plugins, 'toolbarButton');
@@ -551,9 +551,9 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
localization_function: _,
contextmenu: false,
browser_spellcheck: true,
setup: (editor:any) => {
setup: (editor: any) => {
function openEditDialog(editable:any) {
function openEditDialog(editable: any) {
const source = editable ? findBlockSource(editable) : newBlockSource();
editor.windowManager.open({
@@ -563,7 +563,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
codeTextArea: source.content,
languageInput: source.language,
},
onSubmit: async (dialogApi:any) => {
onSubmit: async (dialogApi: any) => {
const newSource = newBlockSource(dialogApi.getData().languageInput, dialogApi.getData().codeTextArea);
const md = `${newSource.openCharacters}${newSource.content.trim()}${newSource.closeCharacters}`;
const result = await markupToHtml.current(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, md, { bodyOnly: true });
@@ -638,7 +638,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
onAction: function() {
editor.execCommand('mceToggleFormat', false, 'code', { class: 'inline-code' });
},
onSetup: function(api:any) {
onSetup: function(api: any) {
api.setActive(editor.formatter.match('code'));
const unbind = editor.formatter.formatChanged('code', api.setActive).unbind;
@@ -669,17 +669,17 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
setupContextMenu(editor);
// TODO: remove event on unmount?
editor.on('DblClick', (event:any) => {
editor.on('DblClick', (event: any) => {
const editable = findEditableContainer(event.target);
if (editable) openEditDialog(editable);
});
// This is triggered when an external file is dropped on the editor
editor.on('drop', (event:any) => {
editor.on('drop', (event: any) => {
props_onDrop.current(event);
});
editor.on('ObjectResized', function(event:any) {
editor.on('ObjectResized', function(event: any) {
if (event.target.nodeName === 'IMG') {
editor.fire('joplinChange');
dispatchDidUpdate(editor);
@@ -706,7 +706,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
// Set the initial content and load the plugin CSS and JS files
// -----------------------------------------------------------------------------------------
const loadDocumentAssets = (editor:any, pluginAssets:any[]) => {
const loadDocumentAssets = (editor: any, pluginAssets: any[]) => {
// Note: The way files are cached is not correct because it assumes there's only one version
// of each file. However, when the theme change, a new CSS file, specific to the theme, is
// created. That file should not be loaded on top of the previous one, but as a replacement.
@@ -720,7 +720,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
const theme = themeStyle(props.themeId);
let docHead_:any = null;
let docHead_: any = null;
function docHead() {
if (docHead_) return docHead_;
@@ -733,15 +733,15 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
`gui/note-viewer/pluginAssets/highlight.js/${theme.codeThemeCss}`,
].concat(
pluginAssets
.filter((a:any) => a.mime === 'text/css')
.map((a:any) => a.path)
).filter((path:string) => !loadedCssFiles_.includes(path));
.filter((a: any) => a.mime === 'text/css')
.map((a: any) => a.path)
).filter((path: string) => !loadedCssFiles_.includes(path));
const jsFiles = [].concat(
pluginAssets
.filter((a:any) => a.mime === 'application/javascript')
.map((a:any) => a.path)
).filter((path:string) => !loadedJsFiles_.includes(path));
.filter((a: any) => a.mime === 'application/javascript')
.map((a: any) => a.path)
).filter((path: string) => !loadedJsFiles_.includes(path));
for (const cssFile of cssFiles) loadedCssFiles_.push(cssFile);
for (const jsFile of jsFiles) loadedJsFiles_.push(jsFile);
@@ -937,8 +937,8 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
}, 1000);
}
function onExecCommand(event:any) {
const c:string = event.command;
function onExecCommand(event: any) {
const c: string = event.command;
if (!c) return;
// We need to dispatch onChange for these commands:
@@ -972,13 +972,13 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
// onChange even though nothing is changed. The alternative would be to
// check the content before and after, but this is too slow, so let's
// keep it this way for now.
function onKeyUp(event:any) {
function onKeyUp(event: any) {
if (['Backspace', 'Delete', 'Enter', 'Tab'].includes(event.key)) {
onChangeHandler();
}
}
async function onPaste(event:any) {
async function onPaste(event: any) {
const resourceMds = await handlePasteEvent(event);
if (resourceMds.length) {
const result = await markupToHtml.current(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, resourceMds.join('\n'), markupRenderOptions({ bodyOnly: true }));
@@ -1000,7 +1000,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
}
}
function onKeyDown(event:any) {
function onKeyDown(event: any) {
// Handle "paste as text". Note that when pressing CtrlOrCmd+Shift+V it's going
// to trigger the "keydown" event but not the "paste" event, so it's ok to process
// it here and we don't need to do anything special in onPaste
@@ -1053,7 +1053,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
};
}, []);
function renderExtraToolbarButton(key:string, info:ToolbarButtonInfo) {
function renderExtraToolbarButton(key: string, info: ToolbarButtonInfo) {
return <ToolbarButton
key={key}
themeId={props.themeId}

View File

@@ -1,8 +1,8 @@
import { NoteBodyEditorProps } from '../../../utils/types';
const { buildStyle } = require('@joplin/lib/theme');
export default function styles(props:NoteBodyEditorProps) {
return buildStyle(['TinyMCE', props.style.width, props.style.height], props.themeId, (theme:any) => {
export default function styles(props: NoteBodyEditorProps) {
return buildStyle(['TinyMCE', props.style.width, props.style.height], props.themeId, (theme: any) => {
const extraToolbarContainer = {
backgroundColor: theme.backgroundColor3,
display: 'flex',

View File

@@ -6,7 +6,7 @@ const Resource = require('@joplin/lib/models/Resource');
// x and y are the absolute coordinates, as returned by the context-menu event
// handler on the webContent. This function will return null if the point is
// not within the TinyMCE editor.
function contextMenuElement(editor:any, x:number, y:number) {
function contextMenuElement(editor: any, x: number, y: number) {
if (!editor || !editor.getDoc()) return null;
const iframes = document.getElementsByClassName('tox-edit-area__iframe');
@@ -27,16 +27,16 @@ interface ContextMenuActionOptions {
current: ContextMenuOptions,
}
const contextMenuActionOptions:ContextMenuActionOptions = { current: null };
const contextMenuActionOptions: ContextMenuActionOptions = { current: null };
export default function(editor:any) {
export default function(editor: any) {
const contextMenuItems = menuItems();
bridge().window().webContents.on('context-menu', (_event:any, params:any) => {
bridge().window().webContents.on('context-menu', (_event: any, params: any) => {
const element = contextMenuElement(editor, params.x, params.y);
if (!element) return;
let itemType:ContextMenuItemType = ContextMenuItemType.None;
let itemType: ContextMenuItemType = ContextMenuItemType.None;
let resourceId = '';
let linkToCopy = null;
@@ -57,7 +57,7 @@ export default function(editor:any) {
linkToCopy,
textToCopy: null,
htmlToCopy: editor.selection ? editor.selection.getContent() : '',
insertContent: (content:string) => {
insertContent: (content: string) => {
editor.insertContent(content);
},
isReadOnly: false,

View File

@@ -2,11 +2,11 @@ import { useEffect, useCallback, useRef } from 'react';
import shim from '@joplin/lib/shim';
interface HookDependencies {
editor:any,
editor: any,
onScroll: Function,
}
export default function useScroll(dependencies:HookDependencies) {
export default function useScroll(dependencies: HookDependencies) {
const { editor, onScroll } = dependencies;
const scrollTimeoutId_ = useRef(null);
@@ -37,7 +37,7 @@ export default function useScroll(dependencies:HookDependencies) {
return m <= 0 ? 0 : t / m;
}, [maxScrollTop, scrollTop]);
const scrollToPercent = useCallback((percent:number) => {
const scrollToPercent = useCallback((percent: number) => {
if (!editor) return;
editor.getWin().scrollTo(0, maxScrollTop() * percent);
}, [editor, maxScrollTop]);

View File

@@ -55,7 +55,7 @@ function NoteEditor(props: NoteEditorProps) {
const isMountedRef = useRef(true);
const noteSearchBarRef = useRef(null);
const formNote_beforeLoad = useCallback(async (event:OnLoadEvent) => {
const formNote_beforeLoad = useCallback(async (event: OnLoadEvent) => {
await saveNoteIfWillChange(event.formNote);
setShowRevisions(false);
}, []);
@@ -106,7 +106,7 @@ function NoteEditor(props: NoteEditorProps) {
return async function() {
const note = await formNoteToNote(formNote);
reg.logger().debug('Saving note...', note);
const savedNote:any = await Note.save(note);
const savedNote: any = await Note.save(note);
setFormNote((prev: FormNote) => {
return { ...prev, user_updated_time: savedNote.user_updated_time };
@@ -334,7 +334,7 @@ function NoteEditor(props: NoteEditorProps) {
});
}, [props.dispatch, formNote]);
function renderNoNotes(rootStyle:any) {
function renderNoNotes(rootStyle: any) {
const emptyDivStyle = Object.assign(
{
backgroundColor: 'black',
@@ -365,7 +365,7 @@ function NoteEditor(props: NoteEditorProps) {
const searchMarkers = useSearchMarkers(showLocalSearch, localSearchMarkerOptions, props.searches, props.selectedSearchId, props.highlightedWords);
const editorProps:NoteBodyEditorProps = {
const editorProps: NoteBodyEditorProps = {
ref: editorRef,
contentKey: formNote.id,
style: styles.tinyMCE,
@@ -417,7 +417,7 @@ function NoteEditor(props: NoteEditorProps) {
if (showRevisions) {
const theme = themeStyle(props.themeId);
const revStyle:any = {
const revStyle: any = {
// ...props.style,
display: 'inline-flex',
padding: theme.margin,

View File

@@ -13,7 +13,7 @@ interface Props {
noteIsTodo: number,
isProvisional: boolean,
titleInputRef: any,
onTitleChange(event: ChangeEvent<HTMLInputElement>):void,
onTitleChange(event: ChangeEvent<HTMLInputElement>): void,
}
function styles_(props: Props) {
@@ -52,10 +52,10 @@ function styles_(props: Props) {
});
}
export default function NoteTitleBar(props:Props) {
export default function NoteTitleBar(props: Props) {
const styles = styles_(props);
const onTitleKeydown = useCallback((event:any) => {
const onTitleKeydown = useCallback((event: any) => {
const keyCode = event.keyCode;
if (keyCode === 9) { // TAB

View File

@@ -1,7 +1,7 @@
import { CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
const declarations:CommandDeclaration[] = [
const declarations: CommandDeclaration[] = [
{
name: 'insertText',
},

View File

@@ -1,13 +1,13 @@
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration:CommandDeclaration = {
export const declaration: CommandDeclaration = {
name: 'focusElementNoteBody',
label: () => _('Note body'),
parentLabel: () => _('Focus'),
};
export const runtime = (comp:any):CommandRuntime => {
export const runtime = (comp: any): CommandRuntime => {
return {
execute: async () => {
comp.editorRef.current.execCommand({ name: 'focus' });

View File

@@ -1,13 +1,13 @@
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration:CommandDeclaration = {
export const declaration: CommandDeclaration = {
name: 'focusElementNoteTitle',
label: () => _('Note title'),
parentLabel: () => _('Focus'),
};
export const runtime = (comp:any):CommandRuntime => {
export const runtime = (comp: any): CommandRuntime => {
return {
execute: async () => {
if (!comp.titleInputRef.current) return;

View File

@@ -1,12 +1,12 @@
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
export const declaration:CommandDeclaration = {
export const declaration: CommandDeclaration = {
name: 'showLocalSearch',
label: () => _('Search in current note'),
};
export const runtime = (comp:any):CommandRuntime => {
export const runtime = (comp: any): CommandRuntime => {
return {
execute: async () => {
if (comp.editorRef.current && comp.editorRef.current.supportsCommand('search')) {

View File

@@ -1,10 +1,10 @@
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
export const declaration:CommandDeclaration = {
export const declaration: CommandDeclaration = {
name: 'showRevisions',
};
export const runtime = (comp:any):CommandRuntime => {
export const runtime = (comp: any): CommandRuntime => {
return {
execute: async () => {
comp.setShowRevisions(true);

View File

@@ -34,16 +34,16 @@ interface ContextMenuItem {
}
interface ContextMenuItems {
[key:string]: ContextMenuItem;
[key: string]: ContextMenuItem;
}
async function resourceInfo(options:ContextMenuOptions):Promise<any> {
async function resourceInfo(options: ContextMenuOptions): Promise<any> {
const resource = options.resourceId ? await Resource.load(options.resourceId) : null;
const resourcePath = resource ? Resource.fullPath(resource) : '';
return { resource, resourcePath };
}
function handleCopyToClipboard(options:ContextMenuOptions) {
function handleCopyToClipboard(options: ContextMenuOptions) {
if (options.textToCopy) {
clipboard.writeText(options.textToCopy);
} else if (options.htmlToCopy) {
@@ -51,11 +51,11 @@ function handleCopyToClipboard(options:ContextMenuOptions) {
}
}
export function menuItems():ContextMenuItems {
export function menuItems(): ContextMenuItems {
return {
open: {
label: _('Open...'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
try {
await ResourceEditWatcher.instance().openAndWatch(options.resourceId);
} catch (error) {
@@ -63,11 +63,11 @@ export function menuItems():ContextMenuItems {
bridge().showErrorMessageBox(error.message);
}
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
},
saveAs: {
label: _('Save as...'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
const { resourcePath, resource } = await resourceInfo(options);
const filePath = bridge().showSaveDialog({
defaultPath: resource.filename ? resource.filename : resource.title,
@@ -75,58 +75,58 @@ export function menuItems():ContextMenuItems {
if (!filePath) return;
await fs.copy(resourcePath, filePath);
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
},
revealInFolder: {
label: _('Reveal file in folder'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
const { resourcePath } = await resourceInfo(options);
bridge().showItemInFolder(resourcePath);
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
},
copyPathToClipboard: {
label: _('Copy path to clipboard'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
const { resourcePath } = await resourceInfo(options);
clipboard.writeText(toSystemSlashes(resourcePath));
},
isActive: (itemType:ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource,
},
cut: {
label: _('Cut'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
handleCopyToClipboard(options);
options.insertContent('');
},
isActive: (_itemType:ContextMenuItemType, options:ContextMenuOptions) => !options.isReadOnly && (!!options.textToCopy || !!options.htmlToCopy),
isActive: (_itemType: ContextMenuItemType, options: ContextMenuOptions) => !options.isReadOnly && (!!options.textToCopy || !!options.htmlToCopy),
},
copy: {
label: _('Copy'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
handleCopyToClipboard(options);
},
isActive: (_itemType:ContextMenuItemType, options:ContextMenuOptions) => !!options.textToCopy || !!options.htmlToCopy,
isActive: (_itemType: ContextMenuItemType, options: ContextMenuOptions) => !!options.textToCopy || !!options.htmlToCopy,
},
paste: {
label: _('Paste'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
const content = clipboard.readHTML() ? clipboard.readHTML() : clipboard.readText();
options.insertContent(content);
},
isActive: (_itemType:ContextMenuItemType, options:ContextMenuOptions) => !options.isReadOnly && (!!clipboard.readText() || !!clipboard.readHTML()),
isActive: (_itemType: ContextMenuItemType, options: ContextMenuOptions) => !options.isReadOnly && (!!clipboard.readText() || !!clipboard.readHTML()),
},
copyLinkUrl: {
label: _('Copy Link Address'),
onAction: async (options:ContextMenuOptions) => {
onAction: async (options: ContextMenuOptions) => {
clipboard.writeText(options.linkToCopy !== null ? options.linkToCopy : options.textToCopy);
},
isActive: (itemType:ContextMenuItemType, options:ContextMenuOptions) => itemType === ContextMenuItemType.Link || !!options.linkToCopy,
isActive: (itemType: ContextMenuItemType, options: ContextMenuOptions) => itemType === ContextMenuItemType.Link || !!options.linkToCopy,
},
};
}
export default async function contextMenu(options:ContextMenuOptions) {
export default async function contextMenu(options: ContextMenuOptions) {
const menu = new Menu();
const items = menuItems();

View File

@@ -4,7 +4,7 @@ const HtmlToMd = require('@joplin/lib/HtmlToMd');
const Note = require('@joplin/lib/models/Note');
const { MarkupToHtml } = require('@joplin/renderer');
export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss:string): Promise<string> {
export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string): Promise<string> {
let newBody = '';
if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) {

View File

@@ -52,7 +52,7 @@ export async function attachedResources(noteBody: string): Promise<any> {
return output;
}
export async function commandAttachFileToBody(body:string, filePaths:string[] = null, options:any = null) {
export async function commandAttachFileToBody(body: string, filePaths: string[] = null, options: any = null) {
options = {
createFileURL: false,
position: 0,
@@ -101,7 +101,7 @@ export function resourcesStatus(resourceInfos: any) {
return joplinRendererUtils.resourceStatusName(lowestIndex);
}
export async function handlePasteEvent(event:any) {
export async function handlePasteEvent(event: any) {
const output = [];
const formats = clipboard.availableFormats();
for (let i = 0; i < formats.length; i++) {

View File

@@ -4,7 +4,7 @@ import { ToolbarButtonInfo } from '@joplin/lib/services/commands/ToolbarButtonUt
import { PluginStates } from '@joplin/lib/services/plugins/reducer';
export interface ToolbarButtonInfos {
[key:string]: ToolbarButtonInfo;
[key: string]: ToolbarButtonInfo;
}
export interface NoteEditorProps {
@@ -109,7 +109,7 @@ export interface FormNote {
originalCss: string,
}
export function defaultFormNote():FormNote {
export function defaultFormNote(): FormNote {
return {
id: '',
parent_id: '',
@@ -133,7 +133,7 @@ export interface ResourceInfo {
}
export interface ResourceInfos {
[index:string]: ResourceInfo,
[index: string]: ResourceInfo,
}
export enum ScrollOptionTypes {

View File

@@ -2,13 +2,13 @@ import { useCallback } from 'react';
const Note = require('@joplin/lib/models/Note.js');
interface HookDependencies {
editorRef:any,
editorRef: any,
}
export default function useDropHandler(dependencies:HookDependencies) {
export default function useDropHandler(dependencies: HookDependencies) {
const { editorRef } = dependencies;
return useCallback(async (event:any) => {
return useCallback(async (event: any) => {
const dt = event.dataTransfer;
dt.dropEffect = 'copy';
const createFileURL = event.altKey;

View File

@@ -5,7 +5,7 @@ interface HookDependencies {
folderId: string,
}
export default function(dependencies:HookDependencies) {
export default function(dependencies: HookDependencies) {
const { folderId } = dependencies;
const [folder, setFolder] = useState(null);

View File

@@ -23,8 +23,8 @@ interface HookDependencies {
isProvisional: boolean,
titleInputRef: any,
editorRef: any,
onBeforeLoad(event:OnLoadEvent):void,
onAfterLoad(event:OnLoadEvent):void,
onBeforeLoad(event: OnLoadEvent): void,
onAfterLoad(event: OnLoadEvent): void,
}
function installResourceChangeHandler(onResourceChangeHandler: Function) {
@@ -41,7 +41,7 @@ function uninstallResourceChangeHandler(onResourceChangeHandler: Function) {
ResourceEditWatcher.instance().off('resourceChange', onResourceChangeHandler);
}
function resourceInfosChanged(a:ResourceInfos, b:ResourceInfos):boolean {
function resourceInfosChanged(a: ResourceInfos, b: ResourceInfos): boolean {
if (Object.keys(a).length !== Object.keys(b).length) return true;
for (const id in a) {
@@ -57,7 +57,7 @@ function resourceInfosChanged(a:ResourceInfos, b:ResourceInfos):boolean {
return false;
}
export default function useFormNote(dependencies:HookDependencies) {
export default function useFormNote(dependencies: HookDependencies) {
const { syncStarted, noteId, isProvisional, titleInputRef, editorRef, onBeforeLoad, onAfterLoad } = dependencies;
const [formNote, setFormNote] = useState<FormNote>(defaultFormNote());
@@ -186,7 +186,7 @@ export default function useFormNote(dependencies:HookDependencies) {
};
}, [noteId, isProvisional, formNote]);
const onResourceChange = useCallback(async function(event:any = null) {
const onResourceChange = useCallback(async function(event: any = null) {
const resourceIds = await Note.linkedResourceIds(formNote.body);
if (!event || resourceIds.indexOf(event.id) >= 0) {
clearResourceCache();
@@ -213,7 +213,7 @@ export default function useFormNote(dependencies:HookDependencies) {
async function runEffect() {
const r = await attachedResources(formNote.body);
if (cancelled) return;
setResourceInfos((previous:ResourceInfos) => {
setResourceInfos((previous: ResourceInfos) => {
return resourceInfosChanged(previous, r) ? r : previous;
});
}

View File

@@ -19,7 +19,7 @@ interface MarkupToHtmlOptions {
resourceInfos?: ResourceInfos,
}
export default function useMarkupToHtml(deps:HookDependencies) {
export default function useMarkupToHtml(deps: HookDependencies) {
const { themeId, customCss, plugins } = deps;
const markupToHtml = useMemo(() => {

View File

@@ -12,7 +12,7 @@ const urlUtils = require('@joplin/lib/urlUtils');
const ResourceFetcher = require('@joplin/lib/services/ResourceFetcher.js');
const { reg } = require('@joplin/lib/registry.js');
export default function useMessageHandler(scrollWhenReady:any, setScrollWhenReady:Function, editorRef:any, setLocalSearchResultCount:Function, dispatch:Function, formNote:FormNote) {
export default function useMessageHandler(scrollWhenReady: any, setScrollWhenReady: Function, editorRef: any, setLocalSearchResultCount: Function, dispatch: Function, formNote: FormNote) {
return useCallback(async (event: any) => {
const msg = event.channel ? event.channel : '';
const args = event.args;

View File

@@ -9,7 +9,7 @@ interface LocalSearch {
timestamp: number,
}
function defaultLocalSearch():LocalSearch {
function defaultLocalSearch(): LocalSearch {
return {
query: '',
selectedIndex: 0,
@@ -23,8 +23,8 @@ export default function useNoteSearchBar() {
const [showLocalSearch, setShowLocalSearch] = useState(false);
const [localSearch, setLocalSearch] = useState<LocalSearch>(defaultLocalSearch());
const onChange = useCallback((query:string) => {
setLocalSearch((prev:LocalSearch) => {
const onChange = useCallback((query: string) => {
setLocalSearch((prev: LocalSearch) => {
return {
query: query,
selectedIndex: 0,
@@ -35,8 +35,8 @@ export default function useNoteSearchBar() {
});
}, []);
const noteSearchBarNextPrevious = useCallback((inc:number) => {
setLocalSearch((prev:LocalSearch) => {
const noteSearchBarNextPrevious = useCallback((inc: number) => {
setLocalSearch((prev: LocalSearch) => {
const ls = Object.assign({}, prev);
ls.selectedIndex += inc;
ls.timestamp = Date.now();
@@ -59,8 +59,8 @@ export default function useNoteSearchBar() {
setLocalSearch(defaultLocalSearch());
}, []);
const setResultCount = useCallback((count:number) => {
setLocalSearch((prev:LocalSearch) => {
const setResultCount = useCallback((count: number) => {
setLocalSearch((prev: LocalSearch) => {
if (prev.resultCount === count && !prev.searching) return prev;
return {
@@ -71,7 +71,7 @@ export default function useNoteSearchBar() {
});
}, []);
const searchMarkers = useCallback(():SearchMarkers => {
const searchMarkers = useCallback((): SearchMarkers => {
return {
options: {
selectedIndex: localSearch.selectedIndex,

View File

@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import PlatformImplementation from '../../../services/plugins/PlatformImplementation';
export default function usePluginServiceRegistration(ref:any) {
export default function usePluginServiceRegistration(ref: any) {
useEffect(() => {
PlatformImplementation.instance().registerComponent('textEditor', ref);

View File

@@ -11,7 +11,7 @@ export interface SearchMarkers {
options: SearchMarkersOptions,
}
function defaultSearchMarkers():SearchMarkers {
function defaultSearchMarkers(): SearchMarkers {
return {
keywords: [],
options: {
@@ -23,8 +23,8 @@ function defaultSearchMarkers():SearchMarkers {
}
export default function useSearchMarkers(showLocalSearch:boolean, localSearchMarkerOptions:Function, searches:any[], selectedSearchId:string, highlightedWords: any[] = []) {
return useMemo(():SearchMarkers => {
export default function useSearchMarkers(showLocalSearch: boolean, localSearchMarkerOptions: Function, searches: any[], selectedSearchId: string, highlightedWords: any[] = []) {
return useMemo((): SearchMarkers => {
if (showLocalSearch) return localSearchMarkerOptions();
const output = defaultSearchMarkers();

View File

@@ -12,18 +12,18 @@ const commandsWithDependencies = [
];
interface HookDependencies {
formNote:FormNote,
setShowLocalSearch:Function,
dispatch:Function,
noteSearchBarRef:any,
editorRef:any,
titleInputRef:any,
formNote: FormNote,
setShowLocalSearch: Function,
dispatch: Function,
noteSearchBarRef: any,
editorRef: any,
titleInputRef: any,
saveNoteAndWait: Function,
}
function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):CommandRuntime {
function editorCommandRuntime(declaration: CommandDeclaration, editorRef: any): CommandRuntime {
return {
execute: async (_context:CommandContext, ...args:any[]) => {
execute: async (_context: CommandContext, ...args: any[]) => {
if (!editorRef.current.execCommand) {
reg.logger().warn('Received command, but editor cannot execute commands', declaration.name);
return;
@@ -50,7 +50,7 @@ function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):Com
};
}
export default function useWindowCommandHandler(dependencies:HookDependencies) {
export default function useWindowCommandHandler(dependencies: HookDependencies) {
const { setShowLocalSearch, noteSearchBarRef, editorRef, titleInputRef } = dependencies;
useEffect(() => {