@ditrit/leto-modelizer-plugin-core
v0.28.0
Published
Library that contains all models for modelling tools in Leto's projects.
Downloads
9
Readme
leto-modelizer-plugin-core
Library that contains all models for modeling tools in Leto's projects.
This library is used to create your own plugin for the Leto Modelizer tool.
Get started
Requirements
Install
npm install --save @ditrit/leto-modelizer-plugin-core
Run demo
git clone [email protected]:ditrit/leto-modelizer-plugin-core.git
cd leto-modelizer-plugin-core
npm install
npm run demo
:warning: If you have this error when trying to run demo:
npm warn reify The "linked" install strategy is EXPERIMENTAL and may contain bugs.
npm error Cannot read properties of undefined (reading 'path')
You have to configure npm with:
npm config set install-strategy hoisted
Then
rm -rf node_modules
npm install
npm run demo
Usage
Here are all imports you can use in your plugin:
import {
Component,
ComponentDefinition,
ComponentAttributeDefinition,
ComponentDrawOption,
ComponentAttribute,
ComponentLink,
ComponentLinkDefinition,
DefaultDrawer,
DefaultMetadata,
DefaultParser,
DefaultRender,
ParserLog,
FileInformation,
FileInput,
DefaultData,
DefaultPlugin,
DefaultConfiguration,
Tag,
Variable,
} from "leto-modelizer-plugin-core";
For more information about all imports please refer to technical documentation and project template.
You can use it in that way:
import { DefaultParser } from 'leto-modelizer-plugin-core';
class FruitParser extends DefaultParser {
parse(inputs) {
// Write your own parser here
return {
components: [/* ... */], // Generated components from parser
links: [/* ... */] // Generated component links from parser
}
}
}
export default FruitParser;
To see a complete example, please refer to iactor.
How to create your plugin
You can use this template repository to create your own plugin.
The project template leto-modelizer-plugin-template provides you the default structure of a plugin and all useful scripts to generate resources and other.
It is strongly recommended to use it and the following documentation will make references to it.
Furthermore, in this template there are code comments to explain how to override methods/classes and usages.
How to create your own models
You can read the template documentation to see how to create your own models.
Default Plugin structure
For your plugin to be used by Leto Modelizer
, it needs to have this structure:
// src/index.js
export default new DefaultPlugin({
pluginData: MyPluginData, // MyPluginData has to extend DefaultData
pluginDrawer: MyPluginDrawer, // MyPluginDrawer has to extend DefaultDrawer
pluginMetadata: MyPluginMetadata, // MyPluginMetadata has to extend DefaultMetadata
pluginParser: MyPluginParser, // MyPluginParser has to extend DefaultParser
pluginRenderer: MyPluginRenderer, // MyPluginRenderer has to extend DefaultRender
});
How it works
| Plugin lifecycle | | :--: | | |
This is the default lifecycle of plugin usage in Leto Modelizer.
Plugin creation
Create you plugin project from leto-modelizer-plugin-template and follow the readme section of the template project.
Plugin configuration
The configuration.md explains how you can configure your plugin.
Events
By default, the plugin sends events if you provide a next()
function in DefaultData, like:
new DefaultPlugin({
event: {
next: () => {},
}
})
If you do not, events are still stored in the DefaultData.eventLogs
.
When you create your plugin, you can send events to Leto-modelizer to see the progression of your parsing or rendering action.
See EventLog
in technical documentation for more information.
Technical documentation
Technical documentation can be found here.