2023-06-30 10:55:56 +02:00
|
|
|
/* eslint-disable multiline-comment-style */
|
|
|
|
|
2020-11-05 18:58:23 +02:00
|
|
|
import InteropService from '../../interop/InteropService';
|
2023-07-12 11:30:38 +02:00
|
|
|
import InteropService_Exporter_Custom from '../../interop/InteropService_Exporter_Custom';
|
|
|
|
import InteropService_Importer_Custom from '../../interop/InteropService_Importer_Custom';
|
|
|
|
import { makeExportModule, makeImportModule } from '../../interop/Module';
|
|
|
|
import { ModuleType } from '../../interop/types';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { ExportModule, ImportModule } from './types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a way to create modules to import external data into Joplin or to export notes into any arbitrary format.
|
|
|
|
*
|
2020-11-05 18:58:23 +02:00
|
|
|
* [View the demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/json_export)
|
2020-10-09 19:35:46 +02:00
|
|
|
*
|
|
|
|
* To implement an import or export module, you would simply define an object with various event handlers that are called
|
|
|
|
* by the application during the import/export process.
|
|
|
|
*
|
|
|
|
* See the documentation of the [[ExportModule]] and [[ImportModule]] for more information.
|
|
|
|
*
|
2023-11-05 19:56:30 +02:00
|
|
|
* You may also want to refer to the Joplin API documentation to see the list of properties for each item (note, notebook, etc.) - https://joplinapp.org/help/api/references/rest_api
|
2024-03-26 13:36:15 +02:00
|
|
|
*
|
|
|
|
* <span class="platform-desktop">desktop</span>: While it is possible to register import and export
|
|
|
|
* modules on mobile, there is no GUI to activate them.
|
2020-10-09 19:35:46 +02:00
|
|
|
*/
|
|
|
|
export default class JoplinInterop {
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public async registerExportModule(module: ExportModule) {
|
2023-07-12 11:30:38 +02:00
|
|
|
const internalModule = makeExportModule({
|
2023-12-15 20:18:11 +02:00
|
|
|
...module as any,
|
2020-10-09 19:35:46 +02:00
|
|
|
type: ModuleType.Exporter,
|
|
|
|
fileExtensions: module.fileExtensions ? module.fileExtensions : [],
|
2023-07-12 11:30:38 +02:00
|
|
|
}, () => new InteropService_Exporter_Custom(module));
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
return InteropService.instance().registerModule(internalModule);
|
|
|
|
}
|
|
|
|
|
2023-03-06 16:22:01 +02:00
|
|
|
public async registerImportModule(module: ImportModule) {
|
2023-07-12 11:30:38 +02:00
|
|
|
const internalModule = makeImportModule({
|
2020-10-09 19:35:46 +02:00
|
|
|
...module,
|
|
|
|
type: ModuleType.Importer,
|
|
|
|
fileExtensions: module.fileExtensions ? module.fileExtensions : [],
|
2023-07-12 11:30:38 +02:00
|
|
|
}, () => {
|
|
|
|
return new InteropService_Importer_Custom(module);
|
|
|
|
});
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
return InteropService.instance().registerModule(internalModule);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|