<commit_before>import getExpression from './getExpression'

export default {
  props: {
    value: { required: true },
    title: { type: String, default: null },
    subtitle: { type: String, default: null },
    name: { type: String, default: null },
    inputName: { type: String, default: null },
    errors: {
      validator (errors) {
        return typeof (errors) === 'object' && typeof (errors.has) === 'function'
      },
      default: null
    },
    inputClass: String,
    placeholder: String,
    autofill: [String, Boolean],
    autocomplete: [String, Boolean],
    autofocus: [Boolean],
    min: {},
    max: {}
  },

  data () {
    return {
      expression: null,
      required: null
    }
  },

  computed: {
    /**
     * Unique ID.
     *
     * @property id
     * @return {string}
     */
    id () {
      return `text${this._uid}`
    },

    /**
     * Input field name.
     *
     * @property nameKey
     * @type {string}
     */
    nameKey () {
      const inputName = this.inputName
      const expression = this.expression

      if (inputName) return inputName

      return expression
    },

    /**
     * Get error or feedback for the input field.
     *
     * @property feedback
     * @type {string|null}
     */
    feedback () {
      const errors = this.errors
      const name = this.nameKey

      if (errors) {
        return errors.get(name)
      }

      return null
    }
  },

  methods: {
    /**
     * Mirror attributes from root element.
     *
     * @return {void}
     */
    updateAttributes () {
      if (!this.$vnode || !this.$vnode.data || !this.$vnode.data.attrs) return

      this.required = this.$vnode.data.attrs.hasOwnProperty('required')
    }
  },

  mounted () {
    const model = this.getExpression('model')

    if (model) {
      this.expression = model.split('.').pop()
    }
    this.updateAttributes()

    if (this.autofocus !== false) {
      this.$nextTick(() => {
        const el = this.$el.querySelector('[autofocus]')
        if (el) el.focus()
      })
    }
  },

  beforeUpdate () {
    this.updateAttributes()
  },

  mixins: [getExpression]
}<commit_msg>Use Vue 2.2 model for expression<commit_after>export default {
  props: {
    value: { required: true },
    title: { type: String, default: null },
    subtitle: { type: String, default: null },
    name: { type: String, default: null },
    inputName: { type: String, default: null },
    errors: {
      validator (errors) {
        return typeof (errors) === 'object' && typeof (errors.has) === 'function'
      },
      default: null
    },
    inputClass: String,
    placeholder: String,
    autofill: [String, Boolean],
    autocomplete: [String, Boolean],
    autofocus: [Boolean],
    min: {},
    max: {}
  },

  data () {
    return {
      expression: null,
      required: null
    }
  },

  computed: {

    id () {
      return `text${this._uid}`
    },

    nameKey () {
      const inputName = this.inputName
      const expression = this.expression

      if (inputName) return inputName

      return expression
    },

    feedback () {
      const errors = this.errors
      const name = this.nameKey

      if (errors) {
        return errors.get(name)
      }

      return null
    }
  },

  methods: {
    /**
     * Mirror attributes from root element.
     *
     * @return {void}
     */
    updateAttributes () {
      if (!this.$vnode || !this.$vnode.data || !this.$vnode.data.attrs) return

      this.required = this.$vnode.data.attrs.hasOwnProperty('required')
    }
  },

  mounted () {
    const model = this.$vnode.data.model.expression

    if (model) {
      this.expression = model.split('.').pop()
    }
    this.updateAttributes()

    if (this.autofocus !== false) {
      this.$nextTick(() => {
        const el = this.$el.querySelector('[autofocus]')
        if (el) el.focus()
      })
    }
  },

  beforeUpdate () {
    this.updateAttributes()
  }
}
{'fraction_non_alphanumeric': 0.14644033443121357, 'fraction_numerical': 0.0005067139599695972, 'mean_word_length': 2.032258064516129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7216895', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1208, 'n_words': 286}