-
Notifications
You must be signed in to change notification settings - Fork 13
BasePluginVisor
This object basically works the same way as BasePlugin except that it is design so it is used by the visor and the export tool, so much functionality included in BasePlugin is not needed here.
- The following properties or functions work the same way they do in
BasePlugin: descendant, init, create. -
export: it is the main method of
BasePluginVisorand returns whatever the visor will show. Recieves three parameters, the plugin state (it is stored in the core), its name and if it has children. This last distinction it is done because in case of not having any, the HTML generated by the templated can be return with an small process, meanwhile in the opossing case, it is needed to do more things.
First of all, the definition of the plugin must be instanced (depending on which is defined) that's because the ones stores so far are isntances of BasePlugin or BasePluginVisor and they don't have access to the templates of the plugins and are stored in a variable if the definition was used before or not.
Afterwards, the template it is obtained from the plugin if existing (text based plugins don't need to be defined, in this case __text property it is obtained from the state) and all the text ocurrences $dali$ are searched, and they are use to identify the functions declarations embeded in the HTML. Once found, they make sure they recieve the parameter as the correspondant event, the element itself will listen to the event and the container of the whole template and the text element $dali$ is deleted and the css property ponter-events: none (if is found). After that, if it doesn't have children the result is returned and if it has them, it is transformed into a JSON, it is processed as explained after and returns the result.
- parseJson: this function goes through the generated JSON recursively to deal with it following a series of instructions and recieves three parameters, the JSON, the state, and if it is used the definition of the visor and the editor.
First, if a parent element of a <plugin /> calculates the height that should have depending what is saved in the state in the property "__pluginContainerIds" and assigns to the child of the attribute "data-plugin-height" that will need in the future.
After, all attributes called className are substituted by class, this is only if React is going to be used. This substitution from class to className it is done by the library html2json, so in case of calling export and the element doesn't have children, it is exported directly to the html provided by the template.
Lastly, if the element ispected is a <plugin />, it is assigned the attribute "plugin-data-id" stored in the state and that will be need in the future to render its content properly.
- extraFunctions: it is an "extra" functions dictionary registered inside the plugin to be accessible from other plugins. The key is the alias given to the function and the value assigned is a reference of the itself.
- registerExtraFunction: registers an "extra" function that would be accessible from the rest of the plugins. Recieves two parameters, the function to be registered and an alias to put a more readable name to the function. In case of not providing the alias, the name of the function will be used.
- getExtraFunctions: retruns the object extraFunctions with functions extra previously registered.
- callExtraFunction: recieves two parameters, an alias of the plugin which function extra wants to be invoked and the alias of the function. Invokes this function.