mirror of https://github.com/artf/grapesjs.git
committed by
GitHub
43 changed files with 7586 additions and 1055 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
@ -1,27 +1,23 @@ |
|||
import { isArray } from 'underscore'; |
|||
|
|||
export default { |
|||
run(ed, sender, opts = {}) { |
|||
run(ed, s, opts = {}) { |
|||
const toSelect = []; |
|||
let components = opts.component || ed.getSelectedAll(); |
|||
components = isArray(components) ? [...components] : [components]; |
|||
|
|||
// It's important to deselect components first otherwise,
|
|||
// with undo, the component will be set with the wrong `collection`
|
|||
ed.select(null); |
|||
|
|||
components.forEach(component => { |
|||
if (!component || !component.get('removable')) { |
|||
components.filter(Boolean).forEach(component => { |
|||
if (!component.get('removable')) { |
|||
toSelect.push(component); |
|||
return this.em.logWarning('The element is not removable', { |
|||
component |
|||
component, |
|||
}); |
|||
} |
|||
component.remove(); |
|||
component.collection && toSelect.push(component); |
|||
}); |
|||
|
|||
toSelect.length && ed.select(toSelect); |
|||
ed.select(toSelect); |
|||
|
|||
return components; |
|||
} |
|||
}, |
|||
}; |
|||
|
|||
@ -1,3 +1,4 @@ |
|||
export { default as Model } from './Model'; |
|||
export { default as Collection } from './Collection'; |
|||
export { default as View } from './View'; |
|||
export { default as Module } from './module'; |
|||
|
|||
@ -1,53 +1,41 @@ |
|||
import Component from './ComponentText'; |
|||
import { forEach } from 'underscore'; |
|||
import { toLowerCase } from 'utils/mixins'; |
|||
import ComponentText from './ComponentText'; |
|||
|
|||
export default Component.extend( |
|||
{ |
|||
defaults: { |
|||
...Component.prototype.defaults, |
|||
type: 'link', |
|||
tagName: 'a', |
|||
traits: ['title', 'href', 'target'] |
|||
}, |
|||
|
|||
/** |
|||
* Returns object of attributes for HTML |
|||
* @return {Object} |
|||
* @private |
|||
*/ |
|||
getAttrToHTML(...args) { |
|||
const attr = Component.prototype.getAttrToHTML.apply(this, args); |
|||
delete attr.onmousedown; |
|||
return attr; |
|||
} |
|||
}, |
|||
{ |
|||
isComponent(el) { |
|||
let result; |
|||
|
|||
if (toLowerCase(el.tagName) === 'a') { |
|||
result = { |
|||
type: 'link', |
|||
editable: 0 |
|||
}; |
|||
|
|||
// The link is editable only if, at least, one of its
|
|||
// children is a text node (not empty one)
|
|||
const children = el.childNodes; |
|||
const len = children.length; |
|||
if (!len) delete result.editable; |
|||
|
|||
for (let i = 0; i < len; i++) { |
|||
const child = children[i]; |
|||
|
|||
if (child.nodeType == 3 && child.textContent.trim() != '') { |
|||
delete result.editable; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
const type = 'link'; |
|||
|
|||
export default class ComponentLink extends ComponentText {} |
|||
|
|||
ComponentLink.prototype.defaults = { |
|||
...ComponentText.getDefaults(), |
|||
type, |
|||
tagName: 'a', |
|||
traits: ['title', 'href', 'target'], |
|||
}; |
|||
|
|||
ComponentLink.isComponent = (el, opts = {}) => { |
|||
let result; |
|||
|
|||
return result; |
|||
} |
|||
if (toLowerCase(el.tagName) === 'a') { |
|||
const textTags = opts.textTags || []; |
|||
result = { type, editable: false }; |
|||
|
|||
// The link is editable only if, at least, one of its
|
|||
// children is a text node (not empty one)
|
|||
const children = el.childNodes; |
|||
const len = children.length; |
|||
if (!len) delete result.editable; |
|||
|
|||
forEach(children, child => { |
|||
const { tagName } = child; |
|||
if ( |
|||
(child.nodeType == 3 && child.textContent.trim() !== '') || |
|||
(tagName && textTags.indexOf(toLowerCase(tagName)) >= 0) |
|||
) { |
|||
delete result.editable; |
|||
} |
|||
}); |
|||
} |
|||
); |
|||
|
|||
return result; |
|||
}; |
|||
|
|||
@ -0,0 +1,7 @@ |
|||
import ComponentView from './ComponentView'; |
|||
|
|||
export default class ComponentWrapperView extends ComponentView { |
|||
tagName() { |
|||
return 'div'; |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue