Some cleanup of Match and MatchFragment in prep for tests
This commit is contained in:
parent
f264eee5f9
commit
e11058688f
@ -8,8 +8,8 @@ export default {
|
|||||||
definedProperties: {
|
definedProperties: {
|
||||||
_anchor: {
|
_anchor: {
|
||||||
get: function() {
|
get: function() {
|
||||||
var start = util.normalizeBBox(_.first(this.items).getBBox()),
|
var start = util.normalizeBBox(this.start.getBBox()),
|
||||||
end = util.normalizeBBox(_.last(this.items).getBBox()),
|
end = util.normalizeBBox(this.end.getBBox()),
|
||||||
matrix = this.transform().localMatrix;
|
matrix = this.transform().localMatrix;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -43,7 +43,9 @@ export default {
|
|||||||
.then(items => {
|
.then(items => {
|
||||||
var prev, next, paths;
|
var prev, next, paths;
|
||||||
|
|
||||||
this.items = items;
|
this.start = _.first(items);
|
||||||
|
this.end = _.last(items);
|
||||||
|
|
||||||
util.spaceHorizontally(items, {
|
util.spaceHorizontally(items, {
|
||||||
padding: 10
|
padding: 10
|
||||||
});
|
});
|
||||||
|
@ -21,37 +21,19 @@ export default {
|
|||||||
_render() {
|
_render() {
|
||||||
return this.content.render(this.container.group())
|
return this.content.render(this.container.group())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var box, paths = [];
|
var box, paths;
|
||||||
|
|
||||||
this.content.transform(this.repeat.contentPosition);
|
this.content.transform(this.repeat.contentPosition);
|
||||||
|
|
||||||
box = this.content.getBBox();
|
box = this.content.getBBox();
|
||||||
|
|
||||||
if (this.repeat.hasSkip) {
|
paths = _.flatten([
|
||||||
let vert = Math.max(0, box.ay - box.y - 10),
|
this.skipPath(box),
|
||||||
horiz = box.width - 10;
|
this.loopPath(box)
|
||||||
|
]);
|
||||||
|
|
||||||
paths.push(`M0,${box.ay}q10,0 10,-10v${-vert}q0,-10 10,-10h${horiz}q10,0 10,10v${vert}q0,10 10,10`);
|
this.container.prepend(
|
||||||
|
this.container.path(paths.join('')));
|
||||||
if (!this.repeat.greedy) {
|
|
||||||
paths.push(`M10,${box.ay - 15}l5,5m-5,-5l-5,5`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.repeat.hasLoop) {
|
|
||||||
let vert = box.y2 - box.ay - 10;
|
|
||||||
|
|
||||||
paths.push(`M${box.x},${box.ay}q-10,0 -10,10v${vert}q0,10 10,10h${box.width}q10,0 10,-10v${-vert}q0,-10 -10,-10`);
|
|
||||||
|
|
||||||
if (this.repeat.greedy) {
|
|
||||||
paths.push(`M${box.x2 + 10},${box.ay + 15}l5,-5m-5,5l-5,-5`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paths.length) {
|
|
||||||
this.container.prepend(
|
|
||||||
this.container.path(paths.join('')));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var labelStr = this.repeat.label,
|
var labelStr = this.repeat.label,
|
||||||
@ -70,13 +52,45 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
skipPath(box) {
|
||||||
|
var paths = [];
|
||||||
|
|
||||||
|
if (this.repeat.hasSkip) {
|
||||||
|
let vert = Math.max(0, box.ay - box.y - 10),
|
||||||
|
horiz = box.width - 10;
|
||||||
|
|
||||||
|
paths.push(`M0,${box.ay}q10,0 10,-10v${-vert}q0,-10 10,-10h${horiz}q10,0 10,10v${vert}q0,10 10,10`);
|
||||||
|
|
||||||
|
if (!this.repeat.greedy) {
|
||||||
|
paths.push(`M10,${box.ay - 15}l5,5m-5,-5l-5,5`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
},
|
||||||
|
|
||||||
|
loopPath(box) {
|
||||||
|
var paths = [];
|
||||||
|
|
||||||
|
if (this.repeat.hasLoop) {
|
||||||
|
let vert = box.y2 - box.ay - 10;
|
||||||
|
|
||||||
|
paths.push(`M${box.x},${box.ay}q-10,0 -10,10v${vert}q0,10 10,10h${box.width}q10,0 10,-10v${-vert}q0,-10 -10,-10`);
|
||||||
|
|
||||||
|
if (this.repeat.greedy) {
|
||||||
|
paths.push(`M${box.x2 + 10},${box.ay + 15}l5,-5m-5,5l-5,-5`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
},
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
this.content = this.properties.content;
|
this.content = this.properties.content;
|
||||||
this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === '');
|
this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === '');
|
||||||
|
this.repeat = this.properties.repeat;
|
||||||
|
|
||||||
if (this.properties.repeat.textValue !== '') {
|
if (!this.repeat.hasLoop && !this.repeat.hasSkip) {
|
||||||
this.repeat = this.properties.repeat;
|
|
||||||
} else {
|
|
||||||
this.proxy = this.content;
|
this.proxy = this.content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user