regexper-static/src/js/parser/javascript/root.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

import _ from 'lodash';
export default {
type: 'root',
2014-12-23 01:35:49 +00:00
flagLabels: {
i: 'Ignore Case',
g: 'Global',
m: 'Multiline'
},
2014-12-16 15:14:37 +00:00
2014-12-23 01:35:49 +00:00
_render() {
var flagText;
2014-12-16 15:14:37 +00:00
2014-12-23 01:35:49 +00:00
if (this.flags.length > 0) {
flagText = this.container.text(0, 0, `Flags: ${this.flags.join(', ')}`);
2014-12-16 15:14:37 +00:00
}
return this.regexp.render(this.container.group())
2014-12-16 03:00:24 +00:00
.then(() => {
2014-12-23 01:35:49 +00:00
var box;
if (flagText) {
this.regexp.transform(Snap.matrix()
.translate(10, flagText.getBBox().height));
} else {
this.regexp.transform(Snap.matrix()
.translate(10, 0));
2014-12-16 15:14:37 +00:00
}
box = this.regexp.getBBox();
2014-12-23 01:35:49 +00:00
this.container.path(`M${box.ax},${box.ay}H0M${box.ax2},${box.ay}H${box.x2 + 10}`);
this.container.circle(0, box.ay, 5);
this.container.circle(box.x2 + 10, box.ay, 5);
2014-12-16 03:00:24 +00:00
});
},
setup() {
2014-12-23 01:35:49 +00:00
this.flags = _(this.properties.flags.textValue).unique().sort().map(flag => {
return this.flagLabels[flag];
}).value();
this.regexp = this.properties.regexp
}
};