Line data Source code
1 : // @ts-check 2 : 3 : import Vue from "vue"; 4 : import { mapState } from "vuex"; 5 : import { noop } from "lodash"; 6 : import Card from "../Card.vue"; 7 : import { BaseKeyboardEventMixin as KBMixin } from "@cern/base-vue"; 8 : import TransitionCodeEditor from "./TransitionCodeEditor.vue"; 9 : 10 : /** @typedef {{ card: V.Instance<Card>, cm: V.Instance<TransitionCodeEditor> }} Refs */ 11 : 12 : export default /** @type {V.Constructor<any, Refs>} */ (Vue).extend({ 13 : name: "TransitionEdit", 14 : components: { Card, TransitionCodeEditor }, 15 : mixins: [ KBMixin({ local: true }) ], 16 : computed: { 17 : .../** @type {{ transition(): Element|null }} */(mapState("selection", [ "transition" ])), 18 : .../** @type {{ showKeyHints(): boolean }} */(mapState("ui", [ "showKeyHints" ])) 19 : }, 20 : mounted() { 21 0 : this.onKey("ctrl-s-keydown", (/** @type {Event} */e) => { 22 0 : if (this.$refs.card?.isFocused) { 23 0 : e.preventDefault(); this.doApply(); 24 : } 25 : }); 26 : }, 27 : methods: { 28 : async doApply() { 29 0 : if (!this.transition) { return; } 30 0 : this.$refs.cm?.doApply(); 31 : }, 32 : doDelete() { 33 0 : if (!this.transition) { return; } 34 0 : this.$store.dispatch("remove", "transition").catch(noop); 35 : } 36 : } 37 : });