Line data Source code
1 : // @ts-check 2 : 3 : import Vue from "vue"; 4 : import { clone } from "lodash"; 5 : import { parser } from "@cern/ssvg-engine"; 6 : import draggable from "vuedraggable"; 7 : 8 : 9 1 : const component = /** @type {V.Constructor<any, any>} */(Vue).extend({ 10 : name: "PropertyEnumValuesEdit", 11 : components: { draggable }, 12 : props: { 13 : value: { type: String, default: null }, 14 : inEdit: { type: Boolean, default: false } 15 : }, 16 : /** 17 : * @return {{ editValueList: string[]|null }} 18 : */ 19 : data() { 20 3 : return { editValueList: null }; 21 : }, 22 : computed: { 23 : /** @return {string[]} */ 24 : valueList() { 25 5 : try { 26 5 : return parser.parseList({ index: 0, value: this.value }, 27 : parser.parseString); 28 : } 29 : catch { 30 1 : return []; 31 : } 32 : } 33 : }, 34 : watch: { 35 : /** @param {string[]|null} value */ 36 : editValueList(value) { 37 9 : this.$emit("edit", value); 38 : }, 39 : /** @param {boolean} value */ 40 : inEdit(value) { 41 1 : if (value) { 42 1 : this.editValueList = clone(this.valueList); 43 : } 44 : } 45 : }, 46 : mounted() { 47 3 : this.editValueList = clone(this.valueList); 48 : }, 49 : methods: { 50 : /** 51 : * @param {number} idx 52 : */ 53 : removeAt(idx) { 54 2 : if (this.editValueList) { 55 2 : this.editValueList.splice(idx, 1); 56 : } 57 : }, 58 : /** 59 : * @param {string} [value=undefined] 60 : */ 61 : add(value = undefined) { 62 3 : if (this.editValueList) { 63 3 : this.editValueList.push(value ? value : ""); 64 : } 65 : }, 66 : /** 67 : * @param {number} idx 68 : * @param {string} value 69 : */ 70 : setAt(idx, value) { 71 2 : Vue.set(/** @type {object} */(this.editValueList), idx, value); 72 : } 73 : } 74 : }); 75 : 76 : export default component;