Updated shadow control to be able to handle "absolute null" situation

This commit is contained in:
Henry Jameson 2024-09-12 19:31:19 +03:00
parent 2b9968eacd
commit aa7a336183
7 changed files with 179 additions and 126 deletions

View file

@ -314,7 +314,18 @@ export default {
}, },
set (val) { set (val) {
if (val) { if (val) {
this.shadowsLocal[this.shadowSelected] = this.currentShadowFallback.map(_ => Object.assign({}, _)) this.shadowsLocal[this.shadowSelected] = (this.currentShadowFallback || [])
.map(s => ({
name: null,
x: 0,
y: 0,
blur: 0,
spread: 0,
inset: false,
color: '#000000',
alpha: 1,
...s
}))
} else { } else {
delete this.shadowsLocal[this.shadowSelected] delete this.shadowsLocal[this.shadowSelected]
} }
@ -328,6 +339,7 @@ export default {
return this.shadowsLocal[this.shadowSelected] return this.shadowsLocal[this.shadowSelected]
}, },
set (v) { set (v) {
console.log('TT', v)
this.shadowsLocal[this.shadowSelected] = v this.shadowsLocal[this.shadowSelected] = v
} }
}, },

View file

@ -937,24 +937,14 @@
</Select> </Select>
</div> </div>
<div class="override"> <div class="override">
<label <Checkbox
for="override"
class="label"
>
{{ $t('settings.style.shadows.override') }}
</label>
{{ ' ' }}
<input
id="override" id="override"
v-model="currentShadowOverriden" v-model="currentShadowOverriden"
name="override" name="override"
class="input-override" class="input-override"
type="checkbox"
> >
<label {{ $t('settings.style.shadows.override') }}
class="checkbox-label" </Checkbox>
for="override"
/>
</div> </div>
<button <button
class="btn button-default" class="btn button-default"
@ -965,38 +955,10 @@
</div> </div>
<ShadowControl <ShadowControl
v-model="currentShadow" v-model="currentShadow"
:ready="!!currentShadowFallback" :separate-inset="shadowSelected === 'avatar' || shadowSelected === 'avatarStatus'"
:fallback="currentShadowFallback" :fallback="currentShadowFallback"
/> />
<div v-if="shadowSelected === 'avatar' || shadowSelected === 'avatarStatus'">
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.always_drop_shadow"
tag="p"
>
<code>filter: drop-shadow()</code>
</i18n-t>
<p>{{ $t('settings.style.shadows.filter_hint.avatar_inset') }}</p>
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.drop_shadow_syntax"
tag="p"
>
<code>drop-shadow</code>
<code>spread-radius</code>
<code>inset</code>
</i18n-t>
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.inset_classic"
tag="p"
>
<code>box-shadow</code>
</i18n-t>
<p>{{ $t('settings.style.shadows.filter_hint.spread_zero') }}</p>
</div> </div>
</div>
<div <div
:label="$t('settings.style.fonts._tab_label')" :label="$t('settings.style.fonts._tab_label')"
class="fonts-container" class="fonts-container"

View file

@ -1,8 +1,9 @@
import ColorInput from '../color_input/color_input.vue' import ColorInput from 'src/components/color_input/color_input.vue'
import OpacityInput from '../opacity_input/opacity_input.vue' import OpacityInput from 'src/components/opacity_input/opacity_input.vue'
import Select from '../select/select.vue' import Select from 'src/components/select/select.vue'
import Checkbox from '../checkbox/checkbox.vue' import Checkbox from 'src/components/checkbox/checkbox.vue'
import { getCssShadow } from '../../services/theme_data/theme_data.service.js' import Popover from 'src/components/popover/popover.vue'
import { getCssShadow, getCssShadowFilter } from '../../services/theme_data/theme_data.service.js'
import { hex2rgb } from '../../services/color_convert/color_convert.js' import { hex2rgb } from '../../services/color_convert/color_convert.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { import {
@ -31,12 +32,8 @@ const toModel = (object = {}) => ({
}) })
export default { export default {
// 'modelValue' and 'Fallback' can be undefined, but if they are
// initially vue won't detect it when they become something else
// therefore i'm using "ready" which should be passed as true when
// data becomes available
props: [ props: [
'modelValue', 'fallback', 'ready' 'modelValue', 'fallback', 'separateInset'
], ],
emits: ['update:modelValue'], emits: ['update:modelValue'],
data () { data () {
@ -51,75 +48,86 @@ export default {
ColorInput, ColorInput,
OpacityInput, OpacityInput,
Select, Select,
Checkbox Checkbox,
}, Popover
methods: {
add () {
this.cValue.push(toModel(this.selected))
this.selectedId = this.cValue.length - 1
},
del () {
this.cValue.splice(this.selectedId, 1)
this.selectedId = this.cValue.length === 0 ? undefined : Math.max(this.selectedId - 1, 0)
},
moveUp () {
const movable = this.cValue.splice(this.selectedId, 1)[0]
this.cValue.splice(this.selectedId - 1, 0, movable)
this.selectedId -= 1
},
moveDn () {
const movable = this.cValue.splice(this.selectedId, 1)[0]
this.cValue.splice(this.selectedId + 1, 0, movable)
this.selectedId += 1
}
}, },
beforeUpdate () { beforeUpdate () {
this.cValue = this.modelValue || this.fallback this.cValue = (this.modelValue || this.fallback || []).map(toModel)
}, },
computed: { computed: {
selected () {
const selected = this.cValue[this.selectedId]
if (selected) {
return { ...selected }
}
return null
},
present () {
return this.selected != null && !this.usingFallback
},
shadowsAreNull () {
return this.modelValue == null
},
anyShadows () { anyShadows () {
return this.cValue.length > 0 return this.cValue.length > 0
}, },
anyShadowsFallback () { anyShadowsFallback () {
return this.fallback.length > 0 return this.fallback.length > 0
}, },
selected () {
if (this.ready && this.anyShadows) {
return this.cValue[this.selectedId]
} else {
return toModel({})
}
},
currentFallback () { currentFallback () {
if (this.ready && this.anyShadowsFallback) { return this.fallback?.[this.selectedId]
return this.fallback[this.selectedId]
} else {
return toModel({})
}
}, },
moveUpValid () { moveUpValid () {
return this.ready && this.selectedId > 0 return this.selectedId > 0
}, },
moveDnValid () { moveDnValid () {
return this.ready && this.selectedId < this.cValue.length - 1 return this.selectedId < this.cValue.length - 1
},
present () {
return this.ready &&
typeof this.cValue[this.selectedId] !== 'undefined' &&
!this.usingFallback
}, },
usingFallback () { usingFallback () {
return typeof this.modelValue === 'undefined' return this.modelValue == null
}, },
rgb () { rgb () {
return hex2rgb(this.selected.color) return hex2rgb(this.selected.color)
}, },
style () { style () {
return this.ready if (!this.ready) return {}
? { if (this.separateInset) {
return {
filter: getCssShadowFilter(this.fallback),
boxShadow: getCssShadow(this.fallback, true)
}
}
return {
boxShadow: getCssShadow(this.fallback) boxShadow: getCssShadow(this.fallback)
} }
: {} }
},
methods: {
updateProperty (prop, value) {
this.cValue[this.selectedId][prop] = value
this.$emit('update:modelValue', this.cValue)
},
add () {
this.cValue.push(toModel(this.selected))
this.selectedId = Math.max(this.cValue.length - 1, 0)
this.$emit('update:modelValue', this.cValue)
},
del () {
this.cValue.splice(this.selectedId, 1)
this.selectedId = this.cValue.length === 0 ? undefined : Math.max(this.selectedId - 1, 0)
this.$emit('update:modelValue', this.cValue)
},
moveUp () {
const movable = this.cValue.splice(this.selectedId, 1)[0]
this.cValue.splice(this.selectedId - 1, 0, movable)
this.selectedId -= 1
this.$emit('update:modelValue', this.cValue)
},
moveDn () {
const movable = this.cValue.splice(this.selectedId, 1)[0]
this.cValue.splice(this.selectedId + 1, 0, movable)
this.selectedId += 1
this.$emit('update:modelValue', this.cValue)
} }
} }
} }

View file

@ -69,6 +69,16 @@
} }
} }
.inset-alert {
padding: 0.25em 0.5em;
}
&.disabled {
.inset-alert {
opacity: 0.2;
}
}
.shadow-preview { .shadow-preview {
order: 2; order: 2;
flex: 3 3 15em; flex: 3 3 15em;
@ -94,7 +104,7 @@
.input-light-grid { .input-light-grid {
grid-area: options; grid-area: options;
justify-self: end; justify-self: center;
} }
.input-number { .input-number {
@ -176,3 +186,8 @@
} }
} }
} }
.inset-tooltip {
padding: 0.5em;
max-width: 30em;
}

View file

@ -11,20 +11,22 @@
{{ $t('settings.style.shadows.offset') }} {{ $t('settings.style.shadows.offset') }}
</label> </label>
<input <input
v-model="selected.y" :value="selected?.y"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-number y-shift-number" class="input input-number y-shift-number"
type="number" type="number"
@input="e => updateProperty('y', e.target.value)"
> >
<input <input
v-model="selected.y" :value="selected?.y"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-range y-shift-slider" class="input input-range y-shift-slider"
type="range" type="range"
max="20" max="20"
min="-20" min="-20"
@input="e => updateProperty('y', e.target.value)"
> >
<div <div
class="preview-window" class="preview-window"
@ -36,20 +38,22 @@
/> />
</div> </div>
<input <input
v-model="selected.x" :value="selected?.x"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-number x-shift-number" class="input input-number x-shift-number"
type="number" type="number"
@input="e => updateProperty('x', e.target.value)"
> >
<input <input
v-model="selected.x" :value="selected?.x"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-range x-shift-slider" class="input input-range x-shift-slider"
type="range" type="range"
max="20" max="20"
min="-20" min="-20"
@input="e => updateProperty('x', e.target.value)"
> >
<Checkbox <Checkbox
id="inset" id="inset"
@ -67,7 +71,7 @@
v-model="selectedId" v-model="selectedId"
class="shadow-list" class="shadow-list"
size="10" size="10"
:disabled="!ready || usingFallback" :disabled="shadowsAreNull"
> >
<option <option
v-for="(shadow, index) in cValue" v-for="(shadow, index) in cValue"
@ -75,28 +79,26 @@
:value="index" :value="index"
:class="{ '-active': index === Number(selectedId) }" :class="{ '-active': index === Number(selectedId) }"
> >
{{ shadow.name ?? $t('settings.style.shadows.shadow_id', { value: index }) }} {{ shadow?.name ?? $t('settings.style.shadows.shadow_id', { value: index }) }}
</option> </option>
</Select> </Select>
<div <div
:disabled="usingFallback"
class="id-control arrange-buttons" class="id-control arrange-buttons"
> >
<button <button
class="btn button-default" class="btn button-default"
:disabled="!ready || !present" :disabled="shadowsAreNull"
:class="{ disabled: !present }" @click="add"
@click="del"
> >
<FAIcon <FAIcon
fixed-width fixed-width
icon="times" icon="plus"
/> />
</button> </button>
<button <button
class="btn button-default" class="btn button-default"
:disabled="!moveUpValid" :disabled="!moveUpValid"
:class="{ disabled: !present }" :class="{ disabled: !moveUpValid }"
@click="moveUp" @click="moveUp"
> >
<FAIcon <FAIcon
@ -107,6 +109,7 @@
<button <button
class="btn button-default" class="btn button-default"
:disabled="!moveDnValid" :disabled="!moveDnValid"
:class="{ disabled: !moveDnValid }"
@click="moveDn" @click="moveDn"
> >
<FAIcon <FAIcon
@ -116,12 +119,13 @@
</button> </button>
<button <button
class="btn button-default" class="btn button-default"
:disabled="usingFallback || !present" :disabled="!present"
@click="add" :class="{ disabled: !present }"
@click="del"
> >
<FAIcon <FAIcon
fixed-width fixed-width
icon="plus" icon="times"
/> />
</button> </button>
</div> </div>
@ -141,11 +145,12 @@
</label> </label>
<input <input
id="name" id="name"
v-model="selected.name" :value="selected?.name"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
name="name" name="name"
class="input input-string" class="input input-string"
@input="e => updateProperty('name', e.target.value)"
> >
</div> </div>
<div <div
@ -154,10 +159,11 @@
> >
<Checkbox <Checkbox
id="inset" id="inset"
v-model="selected.inset" :value="selected?.inset"
:disabled="!present" :disabled="!present"
name="inset" name="inset"
class="input-inset input-boolean" class="input-inset input-boolean"
@input="e => updateProperty('inset', e.target.value)"
> >
<template #before> <template #before>
{{ $t('settings.style.shadows.inset') }} {{ $t('settings.style.shadows.inset') }}
@ -178,7 +184,7 @@
</label> </label>
<input <input
id="blur" id="blur"
v-model="selected.blur" :value="selected?.blur"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
name="blur" name="blur"
@ -186,14 +192,16 @@
type="range" type="range"
max="20" max="20"
min="0" min="0"
@input="e => updateProperty('blur', e.target.value)"
> >
<input <input
v-model="selected.blur" :value="selected?.blur"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-number" class="input input-number"
type="number" type="number"
min="0" min="0"
@input="e => updateProperty('blur', e.target.value)"
> >
</div> </div>
<div <div
@ -210,7 +218,7 @@
</label> </label>
<input <input
id="spread" id="spread"
v-model="selected.spread" :value="selected?.spread"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
name="spread" name="spread"
@ -218,26 +226,30 @@
type="range" type="range"
max="20" max="20"
min="-20" min="-20"
@input="e => updateProperty('spread', e.target.value)"
> >
<input <input
v-model="selected.spread" :value="selected?.spread"
:disabled="!present" :disabled="!present"
:class="{ disabled: !present }" :class="{ disabled: !present }"
class="input input-number" class="input input-number"
type="number" type="number"
@input="e => updateProperty('spread', e.target.value)"
> >
</div> </div>
<ColorInput <ColorInput
v-model="selected.color" :modelValue="selected?.color"
:disabled="!present" :disabled="!present"
:label="$t('settings.style.common.color')" :label="$t('settings.style.common.color')"
:fallback="currentFallback.color" :fallback="currentFallback?.color"
:show-optional-tickbox="false" :show-optional-tickbox="false"
name="shadow" name="shadow"
@update:modelValue="e => updateProperty('color', e.target.value)"
/> />
<OpacityInput <OpacityInput
v-model="selected.alpha" :modelValue="selected?.alpha"
:disabled="!present" :disabled="!present"
@update:modelValue="e => updateProperty('alpha', e.target.value)"
/> />
<i18n-t <i18n-t
scope="global" scope="global"
@ -247,6 +259,49 @@
> >
<code>--variable,mod</code> <code>--variable,mod</code>
</i18n-t> </i18n-t>
<Popover
trigger="hover"
v-if="separateInset"
>
<template #trigger>
<div
class="inset-alert alert warning"
>
<FAIcon icon="exclamation-triangle" />
&nbsp;
{{ $t('settings.style.shadows.filter_hint.avatar_inset_short') }}
</div>
</template>
<template #content>
<div class="inset-tooltip">
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.always_drop_shadow"
tag="p"
>
<code>filter: drop-shadow()</code>
</i18n-t>
<p>{{ $t('settings.style.shadows.filter_hint.avatar_inset') }}</p>
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.drop_shadow_syntax"
tag="p"
>
<code>drop-shadow</code>
<code>spread-radius</code>
<code>inset</code>
</i18n-t>
<i18n-t
scope="global"
keypath="settings.style.shadows.filter_hint.inset_classic"
tag="p"
>
<code>box-shadow</code>
</i18n-t>
<p>{{ $t('settings.style.shadows.filter_hint.spread_zero') }}</p>
</div>
</template>
</Popover>
</div> </div>
</div> </div>
</template> </template>

View file

@ -880,6 +880,7 @@
"filter_hint": { "filter_hint": {
"always_drop_shadow": "Warning, this shadow always uses {0} when browser supports it.", "always_drop_shadow": "Warning, this shadow always uses {0} when browser supports it.",
"drop_shadow_syntax": "{0} does not support {1} parameter and {2} keyword.", "drop_shadow_syntax": "{0} does not support {1} parameter and {2} keyword.",
"avatar_inset_short": "Separate inset shadow",
"avatar_inset": "Please note that combining both inset and non-inset shadows on avatars might give unexpected results with transparent avatars.", "avatar_inset": "Please note that combining both inset and non-inset shadows on avatars might give unexpected results with transparent avatars.",
"spread_zero": "Shadows with spread > 0 will appear as if it was set to zero", "spread_zero": "Shadows with spread > 0 will appear as if it was set to zero",
"inset_classic": "Inset shadows will be using {0}" "inset_classic": "Inset shadows will be using {0}"

View file

@ -452,7 +452,7 @@ export const getCssShadow = (input, usesDropShadow) => {
]).join(' ')).join(', ') ]).join(' ')).join(', ')
} }
const getCssShadowFilter = (input) => { export const getCssShadowFilter = (input) => {
if (input.length === 0) { if (input.length === 0) {
return 'none' return 'none'
} }