@visactor/vgrammar-core
Version:
VGrammar is a visual grammar library
60 lines (55 loc) • 2.17 kB
JavaScript
import { DefaultKey } from "../graph/constants";
import { GrammarMarkType, HOOK_EVENT } from "../graph/enums";
import { Factory } from "../core/factory";
import { Mark } from "./mark";
export class Component extends Mark {
constructor(view, componentType, group, mode) {
super(view, GrammarMarkType.component, group), this._componentDatum = {
[DefaultKey]: 0
}, this.componentType = componentType, this.spec.type = "component", this.spec.componentType = componentType,
this.mode = mode, this._updateComponentEncoders();
}
configureComponent(config) {
return this.spec.componentConfig = config, this.commit(), this;
}
addGraphicItem(attrs, groupKey, newGraphicItem) {
const graphicItem = null != newGraphicItem ? newGraphicItem : Factory.createGraphicComponent(this.componentType, attrs, {
mode: this.mode,
skipDefault: this.spec.skipTheme
});
return graphicItem && (this.emit(HOOK_EVENT.BEFORE_ADD_VRENDER_MARK, {
graphicItem: graphicItem
}), this.graphicParent.appendChild(graphicItem), this.emit(HOOK_EVENT.AFTER_ADD_VRENDER_MARK, {
graphicItem: graphicItem
})), graphicItem;
}
join(data) {
return super.join(data, DefaultKey);
}
encodeState(state, channel, value) {
return super.encodeState(state, channel, value), this._updateComponentEncoders(),
this;
}
parseRenderContext() {
return {
large: !1
};
}
_prepareRejoin() {
this._componentDatum[DefaultKey] += 1;
}
evaluateJoin(data) {
return this.spec.key = DefaultKey, data ? (data[DefaultKey] = this._componentDatum[DefaultKey],
this._componentDatum = data) : this._componentDatum = {
[DefaultKey]: this._componentDatum[DefaultKey]
}, super.evaluateJoin([ this._componentDatum ]);
}
_updateComponentEncoders() {
this._encoders = this.spec.encode;
}
_getEncoders() {
var _a;
return null !== (_a = this._encoders) && void 0 !== _a ? _a : {};
}
}
//# sourceMappingURL=component.js.map