The following content script is mostly untested, but should work.
export default (_context: { contentScriptId: string, postMessage: any }) => {
return {
plugin: (codeMirrorWrapper: any) => {
if (!codeMirrorWrapper.cm6) return;
codeMirrorWrapper.registerCommand('scroll-to-line', (lineNumber: number) => {
const editor = codeMirrorWrapper.editor; // as EditorView
const lineInfo = editor.state.doc.line(lineNumber);
editor.dispatch(editor.state.update({
selection: { anchor: lineInfo.from },
scrollIntoView: true,
}));
});
},
};
};
Notes:
Allowing plugins to import sqlite3 on mobile would be difficult for a few reasons:
- The mobile app uses React Native. The SQLite library we use has a different API from the
sqlite3 library available on desktop.
- Currently, plugins are run in mobile within
iframes nested within a WebView. While this gives plugins access to DOM APIs and ES6, this means that any communication with the main React Native process needs to be async.
As such, it could make sense to expose SQLite functionality to plugins, but it would likely need to be a part of Joplin's plugin API, rather than a mock of Node's sqlite3.
Notes:
- It may be possible to use Web SQLite here -- it's roughly 3 MB, so I don't think it would make sense to include in the mobile app by default.
- Ideally, it wouldn't be necessary to always include libraries like this when targeting both desktop and mobile. It might make sense to allow plugin authors to publish different versions of a plugin for different platforms.
- To store larger amounts of information (over a few megabytes), Web SQLite seems to need the Origin Private Filesystem, which, according to their documentation, is only available in web workers. (Presumably, Web SQLite needs the synchronous OPFS methods).
- There's also absurd-sql, which uses
indexedDB for persistent storage.
- It seems to be about 45 MB (based on its NPM page). Libraries this large are not well supported by the plugin loader on mobile.
Thank you for helping test mobile plugin support!
1 Like