Line data Source code
1 : // @ts-check 2 : 3 : import Vue from "vue"; 4 : import { forEach, get, invoke, isEmpty } from "lodash"; 5 : 6 : import PropertyNumber from "./PropertyNumber.vue"; 7 : import PropertyBoolean from "./PropertyBoolean.vue"; 8 : import PropertyEnumerated from "./PropertyEnumerated.vue"; 9 : import PropertyAuto from "./PropertyAuto.vue"; 10 : import d from "debug"; 11 : 12 1 : const debug = d("app:proplist"); 13 : 14 : export default /** @type {V.Constructor<any, any>} */ (Vue).extend({ 15 : name: "Property", 16 : components: { PropertyNumber, PropertyBoolean, PropertyEnumerated, PropertyAuto }, 17 : props: { 18 : /* eslint-disable-next-line vue/require-prop-types */ 19 : state: { /* type: SVGElement, VueX typecheck issues */ default: null }, 20 : /* eslint-disable-next-line vue/require-prop-types */ 21 : property: { /* type: SVGElement, VueX typecheck issues */ default: null } 22 : }, 23 : /** 24 : * @return {{ 25 : * relations: { [index: string]: Element }|null, 26 : * transforms: { [index: string]: Element }|null 27 : * }} 28 : */ 29 : data() { 30 12 : return { relations: null, transforms: null }; 31 : }, 32 : computed: { 33 : /** @return {string} */ 34 17 : type() { return invoke(this.property, "getAttribute", "type"); } 35 : }, 36 : watch: { 37 5 : property() { this.load(); } 38 : }, 39 : mounted() { 40 12 : this.load(); 41 : }, 42 : methods: { 43 : load() { 44 : /** @type {{ [index: string]: Element }} */ 45 17 : const relations = {}; 46 : /** @type {{ [index: string]: Element }} */ 47 17 : const transforms = {}; 48 : 49 17 : forEach(get(this, [ "property", "children" ]), (elt, idx) => { 50 17 : if (elt.tagName === "relation") { 51 17 : relations[idx] = elt; 52 : } 53 0 : else if (elt.tagName === "transform") { 54 0 : transforms[idx] = elt; 55 : } 56 : else { 57 0 : debug("unknown property child element: %s", elt.tagName); 58 : } 59 : }); 60 17 : this.relations = isEmpty(relations) ? null : relations; 61 17 : this.transforms = isEmpty(transforms) ? null : transforms; 62 : } 63 : } 64 : });