mirror of https://github.com/artf/grapesjs.git
4 changed files with 39 additions and 2 deletions
@ -0,0 +1,28 @@ |
|||||
|
import { isArray } from 'underscore'; |
||||
|
|
||||
|
module.exports = { |
||||
|
run(ed, sender, opts = {}) { |
||||
|
const { target } = opts; |
||||
|
const dc = ed.DomComponents; |
||||
|
const type = target.get('type'); |
||||
|
const len = dc.getWrapper().find(`[data-gjs-type="${type}"]`).length; |
||||
|
const toRemove = []; |
||||
|
|
||||
|
if (!len) { |
||||
|
const rules = ed.CssComposer.getAll(); |
||||
|
let toClear = target.get('style-clear'); |
||||
|
toClear = isArray(toClear) ? toClear : [toClear]; |
||||
|
|
||||
|
rules.forEach(rule => { |
||||
|
const selector = rule.selectorsToString(); |
||||
|
toClear.forEach(part => { |
||||
|
part && selector.indexOf(part) >= 0 && toRemove.push(rule); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
rules.remove(toRemove); |
||||
|
} |
||||
|
|
||||
|
return toRemove; |
||||
|
} |
||||
|
}; |
||||
Loading…
Reference in new issue