import Validate from 'simput/src/core/Validate';
import Convert from 'simput/src/core/Convert';

// ----------------------------------------------------------------------------

export default {
  name: 'InputCell',
  props: {
    label: {
      type: String,
    },
    domain: {
      required: true,
    },
    index: {
      type: Number,
    },
    type: {
      type: String,
    },
    noempty: {
      type: Boolean,
    },
    value: {}, // type: any
  },
  data() {
    return {
      editing: false,
      valueRep: this.value,
      error: false,
    };
  },
  methods: {
    onChange(value) {
      this.editing = true;

      const isValid = Validate[this.type](value);
      this.error = !isValid;

      if (!this.noEmpty && !value && !isValid) {
        this.$emit('input', undefined);
      } else if (isValid) {
        let propVal = Convert[this.type](value);
        propVal = this.applyDomains(propVal);
        this.$emit('input', propVal);
      }
    },
    applyDomains(val) {
      let newValue = val;

      if (this.domain) {
        if ('range' in this.domain && this.domain.range.length) {
          const size = this.domain.range.length;
          const { min, max, force } = this.domain.range[this.index % size];
          if (force) {
            newValue = min !== undefined ? Math.max(min, newValue) : newValue;
            newValue = max !== undefined ? Math.min(max, newValue) : newValue;
          }
        }
      }

      return newValue;
    },
  },
};

@@ -564,16 +564,83 @@
 %7D;%0A  %7D,%0A
+  watch: %7B%0A    value(val) %7B%0A      this.valueRep = val;%0A    %7D,%0A  %7D,%0A
   method

Fix InputCell reverting to previous name