|
@@ -3,6 +3,8 @@ import {Node, Link, Graph} from '../helpers/graph'
|
|
|
import {TreeNode, Tree} from '../helpers/tree'
|
|
|
import ViewSystem from './ViewSystem';
|
|
|
|
|
|
+import BaseSystem from './System';
|
|
|
+
|
|
|
import CSS from 'css';
|
|
|
|
|
|
function log(...m) {
|
|
@@ -14,8 +16,10 @@ const MATCH_CHILD = / *> */gm;
|
|
|
const MATCH_SPACES = / +/gm;
|
|
|
const MATCH_PLUS = / *\+ */gm;
|
|
|
const MATCH_MINUS = / *\- */gm;
|
|
|
-export default class RulingSystem {
|
|
|
+export default class RulingSystem extends BaseSystem {
|
|
|
constructor() {
|
|
|
+ super();
|
|
|
+
|
|
|
this.rules = [];
|
|
|
this.index = {};
|
|
|
}
|
|
@@ -33,15 +37,29 @@ export default class RulingSystem {
|
|
|
}
|
|
|
|
|
|
getCSS(Node, View) {
|
|
|
- let rules = this.match(Node,View);
|
|
|
-
|
|
|
+ let {
|
|
|
+ rules,
|
|
|
+ contentrules
|
|
|
+ } = this.match(Node,View);
|
|
|
let css = rules.map(r => this.getDeclarations(r))
|
|
|
- return css.reduce((acc, curr) => {
|
|
|
+ let main = css.reduce((acc, curr) => {
|
|
|
return {
|
|
|
...acc,
|
|
|
...curr
|
|
|
}
|
|
|
}, {});
|
|
|
+ let contentcss = contentrules.map(r => this.getDeclarations(r))
|
|
|
+ let content = contentcss.reduce((acc, curr) => {
|
|
|
+ return {
|
|
|
+ ...acc,
|
|
|
+ ...curr
|
|
|
+ }
|
|
|
+ }, {});
|
|
|
+
|
|
|
+ return {
|
|
|
+ rules: main,
|
|
|
+ contentrules: content
|
|
|
+ };
|
|
|
}
|
|
|
match(Node, View) {
|
|
|
let rules = [];
|
|
@@ -55,7 +73,11 @@ export default class RulingSystem {
|
|
|
|
|
|
if(!Node.content)return [];
|
|
|
// Index
|
|
|
- let array = [...this.index['*'], ...(this.index[Node.content.value] || [])];
|
|
|
+ let array = [
|
|
|
+ ...(this.index['*'] || []),
|
|
|
+ ...(this.index[Node.content.value] || [])
|
|
|
+ ];
|
|
|
+
|
|
|
for(var i in array) {
|
|
|
let rule = array[i];
|
|
|
if (this.matchRule(rule, Node, View)) {
|
|
@@ -63,10 +85,25 @@ export default class RulingSystem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return rules;
|
|
|
+ let contentrules = [];
|
|
|
+ let contentarray = [
|
|
|
+ ...(this.index['~*'] || []),
|
|
|
+ ...(this.index['~'+Node.content.value] || [])
|
|
|
+ ];
|
|
|
+ for(var i in contentarray) {
|
|
|
+ let rule = contentarray[i];
|
|
|
+ if (this.matchRule(rule, Node, View, "~")) {
|
|
|
+ contentrules.push(rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ rules,
|
|
|
+ contentrules
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
- matchRule(rule, Node, View) {
|
|
|
+ matchRule(rule, Node, View, prefix) {
|
|
|
let {
|
|
|
selectors,
|
|
|
declarations
|
|
@@ -74,7 +111,7 @@ export default class RulingSystem {
|
|
|
|
|
|
for (let i in selectors) {
|
|
|
let selector = selectors[i];
|
|
|
- if (this.matchSelector(selector, Node, View)) {
|
|
|
+ if (this.matchSelector(selector, Node, View, prefix)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -82,7 +119,7 @@ export default class RulingSystem {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- matchSelector(selector, Node, View) {
|
|
|
+ matchSelector(selector, Node, View, prefix = "") {
|
|
|
if((Node.depth+1) < selector.length) return false;
|
|
|
for (let i = selector.length-1; i >= 0; i--) {
|
|
|
let ViewNode = Node.content;
|
|
@@ -94,9 +131,11 @@ export default class RulingSystem {
|
|
|
if(View.isRoot(Node) && nodes.includes('ROOT')) return true;
|
|
|
if(!Node.content)return false;
|
|
|
|
|
|
- if(!nodes.includes(ViewNode.value) && !nodes.includes('*')){
|
|
|
+ if(!nodes.includes(prefix+ViewNode.value) && !nodes.includes(prefix+'*')){
|
|
|
return false;
|
|
|
}
|
|
|
+ prefix = "";
|
|
|
+
|
|
|
if(prenodes.length > 0) {
|
|
|
let preNode = View.getBefore(Node);
|
|
|
let preNodeValue = preNode && preNode.content && preNode.content.value;
|
|
@@ -166,31 +205,18 @@ export default class RulingSystem {
|
|
|
|
|
|
addRuleFile(file){
|
|
|
let ruleCSS = CSS.parse(file);
|
|
|
-
|
|
|
+ console.log("RULECSS", ruleCSS);
|
|
|
for(var i in ruleCSS.stylesheet.rules) {
|
|
|
this.addRule(ruleCSS.stylesheet.rules[i]);
|
|
|
}
|
|
|
+ this.forceUpdate();
|
|
|
}
|
|
|
|
|
|
export() {
|
|
|
-
|
|
|
- let graph = this.topology.export();
|
|
|
-
|
|
|
- return {
|
|
|
- topology: graph,
|
|
|
- home : this.homeNode
|
|
|
- }
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
import(data) {
|
|
|
- let { topology, home } = data;
|
|
|
- try{
|
|
|
- this.topology.import(topology, RouteNode);
|
|
|
- this.setHome(home);
|
|
|
- } catch(e) {
|
|
|
- console.log(e);
|
|
|
- throw new Error("RS Import Failed: ");
|
|
|
- }
|
|
|
return this;
|
|
|
}
|
|
|
}
|