Line data Source code
1 : // @ts-check 2 : 3 : import { mapGetters, mapState } from "vuex"; 4 : import { get, noop } from "lodash"; 5 : import { getAttribute } from "../../utils/element"; 6 : import RelationList from "./RelationList.vue"; 7 : import { mixinMaker } from "../../utils"; 8 : 9 : export default mixinMaker({ 10 : name: "PropertyMixin", 11 : components: { RelationList }, 12 : props: { 13 : state: { type: SVGElement, default: null }, 14 : property: { type: SVGElement, default: null } 15 : }, 16 : computed: { 17 : /** @return {string} */ 18 17 : name() { return getAttribute(this.property, "name"); }, 19 : .../** @type {{ value(): any }} */( 20 : mapState("engine", { 21 41 : value: function(state) { return get(state, [ "state", this.name ]); } 22 : })), 23 : .../** @type {{ selectedProperty(): Element|null }} */( 24 : mapState("selection", { selectedProperty: "property" })), 25 : .../** @type {{ selectedElement(): Element|null }} */( 26 : mapGetters("selection", [ "selectedElement" ])), 27 : /** @return {boolean} */ 28 : isSelected() { 29 21 : return this.property === this.selectedElement; 30 : }, 31 : /** @return {boolean} */ 32 : isInSelection() { 33 21 : return this.property === this.selectedProperty; 34 : } 35 : }, 36 : methods: { 37 : /** @returns {Promise<void>} */ 38 : async setSelected() { 39 0 : await this.$store.dispatch("selection/select", { 40 : state: this.state, property: this.property, relation: null 41 : }).catch(noop); 42 : } 43 : } 44 : });