2022-06-05 17:10:44 +03:00
|
|
|
import Select from 'src/components/select/select.vue'
|
2023-03-12 14:32:13 +02:00
|
|
|
import Setting from './setting.js'
|
2022-06-05 17:10:44 +03:00
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
export const allCssUnits = [
|
|
|
|
|
'cm',
|
|
|
|
|
'mm',
|
|
|
|
|
'in',
|
|
|
|
|
'px',
|
|
|
|
|
'pt',
|
|
|
|
|
'pc',
|
|
|
|
|
'em',
|
|
|
|
|
'ex',
|
|
|
|
|
'ch',
|
|
|
|
|
'rem',
|
|
|
|
|
'vw',
|
|
|
|
|
'vh',
|
|
|
|
|
'vmin',
|
|
|
|
|
'vmax',
|
|
|
|
|
'%',
|
|
|
|
|
]
|
2022-06-05 17:10:44 +03:00
|
|
|
export const defaultHorizontalUnits = ['px', 'rem', 'vw']
|
|
|
|
|
export const defaultVerticalUnits = ['px', 'rem', 'vh']
|
|
|
|
|
|
|
|
|
|
export default {
|
2023-03-16 23:18:55 +02:00
|
|
|
...Setting,
|
2022-06-05 17:10:44 +03:00
|
|
|
components: {
|
2023-03-16 23:18:55 +02:00
|
|
|
...Setting.components,
|
2026-01-06 16:22:52 +02:00
|
|
|
Select,
|
2022-06-05 17:10:44 +03:00
|
|
|
},
|
|
|
|
|
props: {
|
2023-03-12 14:32:13 +02:00
|
|
|
...Setting.props,
|
2022-06-05 17:10:44 +03:00
|
|
|
min: Number,
|
|
|
|
|
units: {
|
2023-03-12 14:32:13 +02:00
|
|
|
type: Array,
|
2026-01-06 16:22:52 +02:00
|
|
|
default: () => allCssUnits,
|
2024-04-24 15:58:26 +03:00
|
|
|
},
|
|
|
|
|
unitSet: {
|
|
|
|
|
type: String,
|
2026-01-06 16:22:52 +02:00
|
|
|
default: 'none',
|
2024-05-22 19:54:19 +03:00
|
|
|
},
|
|
|
|
|
step: {
|
|
|
|
|
type: Number,
|
2026-01-06 16:22:52 +02:00
|
|
|
default: 1,
|
2024-05-22 19:54:19 +03:00
|
|
|
},
|
|
|
|
|
resetDefault: {
|
|
|
|
|
type: Object,
|
2026-01-06 16:22:52 +02:00
|
|
|
default: null,
|
|
|
|
|
},
|
2022-06-05 17:10:44 +03:00
|
|
|
},
|
|
|
|
|
computed: {
|
2023-03-12 14:32:13 +02:00
|
|
|
...Setting.computed,
|
2026-01-06 16:22:52 +02:00
|
|
|
stateUnit() {
|
|
|
|
|
return typeof this.state === 'string'
|
|
|
|
|
? this.state.replace(/[0-9,.]+/, '')
|
|
|
|
|
: ''
|
|
|
|
|
},
|
|
|
|
|
stateValue() {
|
|
|
|
|
return typeof this.state === 'string'
|
|
|
|
|
? this.state.replace(/[^0-9,.]+/, '')
|
|
|
|
|
: ''
|
2022-06-05 17:10:44 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2023-03-12 14:32:13 +02:00
|
|
|
...Setting.methods,
|
2026-01-06 16:22:52 +02:00
|
|
|
getUnitString(value) {
|
2024-04-24 15:58:26 +03:00
|
|
|
if (this.unitSet === 'none') return value
|
|
|
|
|
return this.$t(['settings', 'units', this.unitSet, value].join('.'))
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateValue(e) {
|
2026-08-04 19:55:44 +03:00
|
|
|
this.configSink(this.path, Number.parseFloat(e.target.value) + this.stateUnit)
|
2022-06-05 17:10:44 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
updateUnit(e) {
|
2024-05-22 19:54:19 +03:00
|
|
|
let value = this.stateValue
|
|
|
|
|
const newUnit = e.target.value
|
|
|
|
|
if (this.resetDefault) {
|
|
|
|
|
const replaceValue = this.resetDefault[newUnit]
|
|
|
|
|
if (replaceValue != null) {
|
|
|
|
|
value = replaceValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.configSink(this.path, value + newUnit)
|
2026-01-06 16:22:52 +02:00
|
|
|
},
|
|
|
|
|
},
|
2022-06-05 17:10:44 +03:00
|
|
|
}
|