| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Config editor.
Following modules are needed:
npm install --save @plotdb/konfig @plotdb/semver @plotdb/block @plotdb/rescope @plotdb/csscope @loadingio/debounce.js proxise @loadingio/ldquery ldview
include them:
/* here we use `@zbryikt/template` syntax */
+script({
{name: "proxise"},
{name: "@loadingio/debounce.js"},
{name: "@loadingio/ldquery"},
{name: "ldview"},
{name: "@plotdb/semver"},
{name: "@plotdb/rescope"},
{name: "@plotdb/csscope"},
{name: "@plotdb/block"},
{name: "@plotdb/konfig"},
{name: "@plotdb/konfig", path: "konfig.widget.bootstrap.min.js"}
});
Then the initialization script:
kfg = new konfig({...});
kfg.on("change", function(cfg) { ... });
kfg.init().then(function() { ... });
Constructor options:
we usually use simple names in konfig meta, so typemap is necessary for converting names to bid.
here is an example using typemap along with builtin widget bundle:
typemap: function(name) {
return {name: "@plotdb/konfig", version: "main", path: "bootstrap/" + name};
}
check web/src/pug/blockdefault and web/src/pug/block/bootstrap to see supported widgets in the bundle.
A common sample usage:
kfg = new konfig({
root: document.querySelector('.kfg'),
/* define how blocks are found baed on name */
typemap: function(name) {
return {name: "@plotdb/konfig", version: "main", path: "bootstrap/" + name};
},
view: 'simple',
meta: { sample: { type: 'number' } }
});
kfg.on("change", function() { ... });
kfg.init().then(function() {
});
with this DOM:
.kfg(ld-scope): div(ld-each="ctrl")
kfg = new konfig({
root: document.body,
meta: {
showText: { type: 'boolean' },
textSize: { type: 'number', range: false, min: 10, max: 64, step: 1 },
textAlign: { type: 'choice', values: ["left", "right", "center"], default: 'left' },
textColor: { type: 'color', tab: 'color' }
}
});
Check doc/spec.md for more information.
To correctly render your configuration editor, you have to specify how it should be rendered. This can be done by setting the view option in constructor.
view can be either a string, an object or a function. Following explains the details about the usage of corresponding types.
@plotdb/konfig uses ldview for widget rendering, and provide some builtin views which can be specified by their name, by setting view option to following strings along with the corresponding sample DOM for ldview, for example:
new konfig({
view: "simple"
});
While @plotdb/konfig provides a set of default view dynamics, you still have to define the looks and feels of your views. Following are possible values of view, including simple, default and recurse, along with the corresponding sample DOMs.
Additionally, you may want to scope your DOM if you are also using ldview for UI rendering:
div(ld-scope): div(ld-each="ctrl")
A simple list of controls. sample DOM:
div(ld-each="ctrl")
Controls with tabs. sample DOM:
div(ld-each="tab") div(ld="name") div(ld-each="ctrl")
Controls in recursive tabs. sample DOM:
div(ld="template") div(ld="name") div(ld-each="ctrl") div(ld-each="tab")
DOM will be reused for recursive tabs so you have to specify a template roo node with ld="template".
Note ctrl should be outside of tab.
When view option is an object, it can be anything with following methods:
which can be implemented using ldView.
When view option is a function, it should accept an parameter object with following fields:
Additionally, it should return an object with at least following method:
This function is called everytime a konfig rebuild is necessary ( e.g., when meta is updated ). You should implement singleton by yourself if needed.
Widgets may need to communicate with its controller, but there is no direct access or interface of konfig to widgets. Two way communication is possible with action:
rpc = proxise -> itf.fire \action, {name: \rpc, data: {...}}; return null
new itf action: rpc: -> rpc.resolve it
...
rpc!then -> ...
MIT
| Back | FazBrowse Home | New Git URL |