|
|
|
@ -20,6 +20,9 @@ |
|
|
|
* * [clear](#clear) |
|
|
|
* * [load](#load) |
|
|
|
* * [store](#store) |
|
|
|
* * [addType](#addtype) |
|
|
|
* * [getType](#gettype) |
|
|
|
* * [getTypes](#gettypes) |
|
|
|
* * [render](#render) |
|
|
|
* |
|
|
|
* @module DomComponents |
|
|
|
@ -506,9 +509,11 @@ module.exports = () => { |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Add new component type |
|
|
|
* @param {string} type |
|
|
|
* @param {Object} methods |
|
|
|
* Add new component type. |
|
|
|
* Read more about this in [Define New Component](https://grapesjs.com/docs/modules/Components.html#define-new-component)
|
|
|
|
* @param {string} type Component ID |
|
|
|
* @param {Object} methods Component methods |
|
|
|
* @return {this} |
|
|
|
*/ |
|
|
|
addType(type, methods) { |
|
|
|
const compType = this.getType(type); |
|
|
|
@ -519,15 +524,18 @@ module.exports = () => { |
|
|
|
|
|
|
|
// If the model/view is a simple object I need to extend it
|
|
|
|
if (typeof model === 'object') { |
|
|
|
methods.model = modelToExt.extend({ |
|
|
|
...model, |
|
|
|
defaults: { |
|
|
|
...modelToExt.prototype.defaults, |
|
|
|
...(model.defaults || {}), |
|
|
|
methods.model = modelToExt.extend( |
|
|
|
{ |
|
|
|
...model, |
|
|
|
defaults: { |
|
|
|
...modelToExt.prototype.defaults, |
|
|
|
...(model.defaults || {}) |
|
|
|
} |
|
|
|
}, |
|
|
|
}, { |
|
|
|
isComponent: isComponent || (() => 0), |
|
|
|
}); |
|
|
|
{ |
|
|
|
isComponent: isComponent || (() => 0) |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof view === 'object') { |
|
|
|
@ -541,11 +549,15 @@ module.exports = () => { |
|
|
|
methods.id = type; |
|
|
|
componentTypes.unshift(methods); |
|
|
|
} |
|
|
|
|
|
|
|
return this; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Get component type |
|
|
|
* @param {string} type |
|
|
|
* Get component type. |
|
|
|
* Read more about this in [Define New Component](https://grapesjs.com/docs/modules/Components.html#define-new-component)
|
|
|
|
* @param {string} type Component ID |
|
|
|
* @return {Object} Component type defintion, eg. `{ model: ..., view: ... }` |
|
|
|
*/ |
|
|
|
getType(type) { |
|
|
|
var df = componentTypes; |
|
|
|
@ -559,6 +571,14 @@ module.exports = () => { |
|
|
|
return; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Return the array of all types |
|
|
|
* @return {Array} |
|
|
|
*/ |
|
|
|
getTypes() { |
|
|
|
return componentTypes; |
|
|
|
}, |
|
|
|
|
|
|
|
selectAdd(component, opts = {}) { |
|
|
|
if (component) { |
|
|
|
component.set({ |
|
|
|
|