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

Method setRule

packages/core/src/css_composer/index.ts:393–414  ·  view source on GitHub ↗

* Add/update the CssRule. * @param {String} selectors Selector string, eg. `.myclass` * @param {Object} style Style properties and values. If the rule exists, styles will be replaced unless `addStyles` option is used. * @param {Object} [opts={}] Additional properties. * @param {String}

(selectors: any, style: CssRuleProperties['style'] = {}, opts: SetRuleOptions = {})

Source from the content-addressed store, hash-verified

391 * // output: .class1 { color: blue; background: red }
392 */
393 setRule(selectors: any, style: CssRuleProperties['style'] = {}, opts: SetRuleOptions = {}) {
394 const { atRuleType, atRuleParams } = opts;
395 const node = this.em.Parser.parserCss.checkNode({
396 selectors,
397 style,
398 })[0];
399 const { state, selectorsAdd } = node;
400 const sm = this.em.Selectors;
401 const selector = sm.add(node.selectors as any);
402 const rule = this.add(selector, state, atRuleParams, {
403 selectorsAdd,
404 atRule: atRuleType,
405 });
406
407 if (opts.addStyles) {
408 rule.addStyle(style, opts);
409 } else {
410 rule.setStyle(style, opts);
411 }
412
413 return rule;
414 }
415
416 /**
417 * Get the CssRule.

Callers 3

index.tsFile · 0.80
index.tsFile · 0.80
selectMethod · 0.80

Calls 4

addMethod · 0.95
checkNodeMethod · 0.80
addStyleMethod · 0.45
setStyleMethod · 0.45

Tested by

no test coverage detected