2014-12-03 02:02:48 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
2014-12-10 11:18:55 +00:00
|
|
|
var groupCounter = 1;
|
|
|
|
|
2014-12-03 02:02:48 +00:00
|
|
|
export default _.extend({}, Base, {
|
2014-12-08 02:16:23 +00:00
|
|
|
type: 'subexp',
|
|
|
|
|
|
|
|
labelMap: {
|
|
|
|
'?:': '',
|
|
|
|
'?=': 'positive lookahead',
|
|
|
|
'?!': 'negative lookahead'
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
var label = this.groupLabel();
|
|
|
|
|
|
|
|
if (label) {
|
|
|
|
this.label = this.container.text()
|
|
|
|
.addClass('subexp-label')
|
|
|
|
.attr({
|
|
|
|
text: label
|
|
|
|
});
|
|
|
|
|
|
|
|
this.outline = this.container.rect()
|
|
|
|
.addClass('subexp-outline')
|
|
|
|
.attr({
|
|
|
|
rx: 3,
|
|
|
|
ry: 3
|
|
|
|
});
|
|
|
|
|
2014-12-10 21:57:42 +00:00
|
|
|
this.regexp.setContainer(this.container.group());
|
2014-12-08 02:16:23 +00:00
|
|
|
this.regexp.render();
|
|
|
|
} else {
|
2014-12-10 21:57:42 +00:00
|
|
|
this.regexp.setContainer(this.container);
|
2014-12-08 02:16:23 +00:00
|
|
|
this.regexp.render();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
position() {
|
|
|
|
var box;
|
|
|
|
|
|
|
|
this.regexp.position();
|
|
|
|
|
|
|
|
if (this.outline) {
|
2014-12-10 01:22:44 +00:00
|
|
|
box = this.label.getBBox();
|
|
|
|
|
|
|
|
this.label.transform(Snap.matrix()
|
|
|
|
.translate(0, box.height));
|
|
|
|
|
|
|
|
this.regexp.container.transform(Snap.matrix()
|
|
|
|
.translate(10, 10 + box.height));
|
|
|
|
|
2014-12-10 00:02:31 +00:00
|
|
|
box = this.regexp.getBBox();
|
2014-12-08 02:16:23 +00:00
|
|
|
|
2014-12-10 01:22:44 +00:00
|
|
|
this.outline
|
|
|
|
.transform(Snap.matrix()
|
|
|
|
.translate(box.x - 10, box.y - 10))
|
|
|
|
.attr({
|
|
|
|
width: box.width + 20,
|
|
|
|
height: box.height + 20
|
|
|
|
});
|
2014-12-08 02:16:23 +00:00
|
|
|
|
|
|
|
this.container.path(Snap.format('M0,{content.cy}h10M{content.x2},{content.cy}H{container.x2}', {
|
2014-12-10 00:02:31 +00:00
|
|
|
container: this.getBBox(),
|
2014-12-08 02:16:23 +00:00
|
|
|
content: box
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
groupLabel() {
|
|
|
|
if (_.has(this.labelMap, this._capture.textValue)) {
|
|
|
|
return this.labelMap[this._capture.textValue];
|
|
|
|
} else {
|
2014-12-10 11:18:55 +00:00
|
|
|
return 'group #' + (groupCounter++);
|
2014-12-08 02:16:23 +00:00
|
|
|
}
|
2014-12-10 11:18:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resetCounter() {
|
|
|
|
groupCounter = 1;
|
|
|
|
},
|
2014-12-03 02:02:48 +00:00
|
|
|
});
|