MCPcopy
hub / github.com/GrapesJS/grapesjs / append

Method append

packages/core/src/dom_components/model/Component.ts:1131–1147  ·  view source on GitHub ↗

* Add new component children * @param {Component|String} components Component to add * @param {Object} [opts={}] Options for the append action * @return {Array} Array of appended components * @example * someComponent.get('components').length // -> 0 * const videoComponent = someCo

(components: ComponentAdd, opts: AddOptions = {})

Source from the content-addressed store, hash-verified

1129 * someComponent.append(otherComponent, { at: 0 });
1130 */
1131 append<T extends Component = Component>(components: ComponentAdd, opts: AddOptions = {}): T[] {
1132 const compArr = isArray(components) ? [...components] : [components];
1133 const toAppend = compArr.map((comp) => {
1134 if (isString(comp)) {
1135 return comp;
1136 } else {
1137 // I have to remove components from the old container before adding them to a new one
1138 comp.collection && (comp as Component).collection.remove(comp, { temporary: true } as any);
1139 return comp;
1140 }
1141 });
1142 const result = this.components().add(toAppend, {
1143 action: ActionLabelComponents.add,
1144 ...opts,
1145 });
1146 return result as T[];
1147 }
1148
1149 /**
1150 * Set new collection if `components` are provided, otherwise the

Callers 11

componentsMethod · 0.95
renderMethod · 0.45
addMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
getColorElMethod · 0.45
canMoveMethod · 0.45
updateSymbolCompsFunction · 0.45
moveMethod · 0.45
insertComponentMethod · 0.45
renderMethod · 0.45

Calls 4

componentsMethod · 0.95
isStringFunction · 0.50
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected