2014-12-03 02:02:48 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2014-12-17 16:53:04 +00:00
|
|
|
export default {
|
2014-12-08 02:16:23 +00:00
|
|
|
type: 'subexp',
|
|
|
|
|
2014-12-17 21:04:55 +00:00
|
|
|
definedProperties: {
|
|
|
|
_anchor: {
|
|
|
|
get: function() {
|
2015-04-16 21:13:12 +00:00
|
|
|
var anchor = this.regexp.getBBox(),
|
2014-12-17 21:04:55 +00:00
|
|
|
matrix = this.transform().localMatrix;
|
|
|
|
|
2014-12-24 04:27:09 +00:00
|
|
|
return {
|
2014-12-17 21:04:55 +00:00
|
|
|
ax: matrix.x(anchor.ax, anchor.ay),
|
|
|
|
ax2: matrix.x(anchor.ax2, anchor.ay),
|
|
|
|
ay: matrix.y(anchor.ax, anchor.ay)
|
2014-12-24 04:27:09 +00:00
|
|
|
};
|
2014-12-17 21:04:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-12-08 02:16:23 +00:00
|
|
|
labelMap: {
|
|
|
|
'?:': '',
|
|
|
|
'?=': 'positive lookahead',
|
|
|
|
'?!': 'negative lookahead'
|
|
|
|
},
|
|
|
|
|
2014-12-11 00:01:57 +00:00
|
|
|
_render() {
|
2015-03-14 00:18:46 +00:00
|
|
|
// NOTE: this.label() MUST be called here, in _render and before any child
|
|
|
|
// nodes are rendered. This is to keep the group numbers in the correct
|
|
|
|
// order.
|
|
|
|
var label = this.label();
|
|
|
|
|
2014-12-17 20:12:04 +00:00
|
|
|
return this.regexp.render(this.container.group())
|
2014-12-21 17:05:55 +00:00
|
|
|
.then(() => {
|
2015-03-14 00:18:46 +00:00
|
|
|
return this.renderLabeledBox(label, this.regexp, {
|
2014-12-21 17:05:55 +00:00
|
|
|
padding: 10
|
|
|
|
});
|
|
|
|
});
|
2014-12-08 02:16:23 +00:00
|
|
|
},
|
|
|
|
|
2015-03-14 00:18:46 +00:00
|
|
|
label() {
|
|
|
|
if (typeof this._label === 'undefined') {
|
|
|
|
if (_.has(this.labelMap, this.properties.capture.textValue)) {
|
|
|
|
this._label = this.labelMap[this.properties.capture.textValue];
|
|
|
|
} else {
|
|
|
|
this._label = 'group #' + (this.state.groupCounter++);
|
|
|
|
}
|
2014-12-17 19:44:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 00:18:46 +00:00
|
|
|
return this._label;
|
|
|
|
},
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
// NOTE: DO NOT call this.label() in setup. It will lead to groups being
|
|
|
|
// numbered in reverse order
|
2014-12-17 19:44:48 +00:00
|
|
|
this.regexp = this.properties.regexp;
|
2014-12-17 20:12:04 +00:00
|
|
|
|
2015-03-14 00:18:46 +00:00
|
|
|
if (this.properties.capture.textValue == '?:') {
|
2014-12-17 20:12:04 +00:00
|
|
|
this.proxy = this.regexp;
|
|
|
|
}
|
2014-12-15 00:08:14 +00:00
|
|
|
}
|
2014-12-17 16:53:04 +00:00
|
|
|
};
|