'actions': 'section', // Horizontal button list, can only submit, uses buttons as items
'tagsinput': 'section', // For entering short text tags
// See: http://ulion.github.io/jsonform/playground/?example=fields-checkboxbuttons
// Widgets included for compatibility with React JSON Schema Form API
'updown': 'number',
'date-time': 'datetime-local',
'alt-datetime': 'datetime-local',
'alt-date': 'date',
// Widgets included for compatibility with Angular Schema Form API
'wizard': 'section', // TODO: Sequential panels with "Next" and "Previous" buttons
// Widgets included for compatibility with other libraries
'textline': 'text',
// Recommended 3rd-party add-on widgets (TODO: create wrappers for these...)
// 'ng2-select': Select control replacement - http://valor-software.com/ng2-select/
// 'flatpickr': Flatpickr date picker - https://github.com/chmln/flatpickr
// 'pikaday': Pikaday date picker - https://github.com/dbushell/Pikaday
// 'spectrum': Spectrum color picker - http://bgrins.github.io/spectrum
// 'bootstrap-slider': Bootstrap Slider range control - https://github.com/seiyria/bootstrap-slider
// 'ace': ACE code editor - https://ace.c9.io
// 'ckeditor': CKEditor HTML / rich text editor - http://ckeditor.com
// 'tinymce': TinyMCE HTML / rich text editor - https://www.tinymce.com
// 'imageselect': Bootstrap drop-down image selector - http://silviomoreto.github.io/bootstrap-select
// 'wysihtml5': HTML editor - http://jhollingworth.github.io/bootstrap-wysihtml5
// 'quill': Quill HTML / rich text editor (?) - https://quilljs.com
};
registeredWidgets: any = { };
frameworkWidgets: any = { };
activeWidgets: any = { };
constructor() {
this.setActiveWidgets();
}
setActiveWidgets(): boolean {
this.activeWidgets = Object.assign(
{ }, this.widgetLibrary, this.frameworkWidgets, this.registeredWidgets
);
for (const widgetName of Object.keys(this.activeWidgets)) {
let widget: any = this.activeWidgets[widgetName];
// Resolve aliases
if (typeof widget === 'string') {
const usedAliases: string[] = [];
while (typeof widget === 'string' && !usedAliases.includes(widget)) {
usedAliases.push(widget);
widget = this.activeWidgets[widget];
}
if (typeof widget !== 'string') {
this.activeWidgets[widgetName] = widget;
}
}
}
return true;
}
setDefaultWidget(type: string): boolean {
if (!this.hasWidget(type)) { return false; }
this.defaultWidget = type;
return true;
}
hasWidget(type: string, widgetSet = 'activeWidgets'): boolean {
if (!type || typeof type !== 'string') { return false; }
return hasOwn(this[widgetSet], type);
}
hasDefaultWidget(type: string): boolean {
return this.hasWidget(type, 'widgetLibrary');
}
registerWidget(type: string, widget: any): boolean {
if (!type || !widget || typeof type !== 'string') { return false; }
this.registeredWidgets[type] = widget;
return this.setActiveWidgets();
}
unRegisterWidget(type: string): boolean {
if (!hasOwn(this.registeredWidgets, type)) { return false; }
delete this.registeredWidgets[type];
return this.setActiveWidgets();
}
unRegisterAllWidgets(unRegisterFrameworkWidgets = true): boolean {
this.registeredWidgets = { };
if (unRegisterFrameworkWidgets) { this.frameworkWidgets = { }; }
return this.setActiveWidgets();
}
registerFrameworkWidgets(widgets: any): boolean {
if (widgets === null || typeof widgets !== 'object') { widgets = { }; }
this.frameworkWidgets = widgets;
return this.setActiveWidgets();
}
unRegisterFrameworkWidgets(): boolean {
if (Object.keys(this.frameworkWidgets).length) {
this.frameworkWidgets = { };
return this.setActiveWidgets();
}
return false;
}
getWidget(type?: string, widgetSet = 'activeWidgets'): any {
if (this.hasWidget(type, widgetSet)) {
return this[widgetSet][type];
} else if (this.hasWidget(this.defaultWidget, widgetSet)) {
return this[widgetSet][this.defaultWidget];
} else {
return null;
}
}
getAllWidgets(): any {
return {
widgetLibrary: this.widgetLibrary,
registeredWidgets: this.registeredWidgets,
frameworkWidgets: this.frameworkWidgets,
activeWidgets: this.activeWidgets,
};
}
}