fix themes3 specificity sorting
This commit is contained in:
parent
30c6eec1a1
commit
a586b9f6d2
|
@ -96,6 +96,17 @@ export default {
|
||||||
textOpacity: 0.25,
|
textOpacity: 0.25,
|
||||||
textOpacityMode: 'blend'
|
textOpacityMode: 'blend'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Icon',
|
||||||
|
parent: {
|
||||||
|
component: 'Button',
|
||||||
|
state: ['disabled']
|
||||||
|
},
|
||||||
|
directives: {
|
||||||
|
textOpacity: 0.25,
|
||||||
|
textOpacityMode: 'blend'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,18 @@ const hoverGlow = {
|
||||||
export default {
|
export default {
|
||||||
name: 'Input',
|
name: 'Input',
|
||||||
selector: '.input',
|
selector: '.input',
|
||||||
variant: {
|
states: {
|
||||||
|
hover: ':hover:not(.disabled)',
|
||||||
|
focused: ':focus-within',
|
||||||
|
disabled: '.disabled'
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
checkbox: '.-checkbox',
|
checkbox: '.-checkbox',
|
||||||
radio: '.-radio'
|
radio: '.-radio'
|
||||||
},
|
},
|
||||||
states: {
|
|
||||||
disabled: ':disabled',
|
|
||||||
hover: ':hover:not(:disabled)',
|
|
||||||
focused: ':focus-within'
|
|
||||||
},
|
|
||||||
validInnerComponents: [
|
validInnerComponents: [
|
||||||
'Text'
|
'Text',
|
||||||
|
'Icon'
|
||||||
],
|
],
|
||||||
defaultRules: [
|
defaultRules: [
|
||||||
{
|
{
|
||||||
|
@ -55,6 +56,34 @@ export default {
|
||||||
directives: {
|
directives: {
|
||||||
shadow: [hoverGlow, '--defaultInputBevel']
|
shadow: [hoverGlow, '--defaultInputBevel']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
state: ['disabled'],
|
||||||
|
directives: {
|
||||||
|
background: '$blend(--inheritedBackground, 0.25, --parent)'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Text',
|
||||||
|
parent: {
|
||||||
|
component: 'Input',
|
||||||
|
state: ['disabled']
|
||||||
|
},
|
||||||
|
directives: {
|
||||||
|
textOpacity: 0.25,
|
||||||
|
textOpacityMode: 'blend'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Icon',
|
||||||
|
parent: {
|
||||||
|
component: 'Input',
|
||||||
|
state: ['disabled']
|
||||||
|
},
|
||||||
|
directives: {
|
||||||
|
textOpacity: 0.25,
|
||||||
|
textOpacityMode: 'blend'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ export const init = ({
|
||||||
|
|
||||||
const rulesetUnsorted = [
|
const rulesetUnsorted = [
|
||||||
...Object.values(components)
|
...Object.values(components)
|
||||||
.map(c => (c.defaultRules || []).map(r => ({ component: c.name, ...r, source: 'Built-in' })))
|
.map(c => (c.defaultRules || []).map(r => ({ source: 'Built-in', component: c.name, ...r })))
|
||||||
.reduce((acc, arr) => [...acc, ...arr], []),
|
.reduce((acc, arr) => [...acc, ...arr], []),
|
||||||
...inputRuleset
|
...inputRuleset
|
||||||
].map(rule => {
|
].map(rule => {
|
||||||
|
@ -198,18 +198,33 @@ export const init = ({
|
||||||
|
|
||||||
const ruleset = rulesetUnsorted
|
const ruleset = rulesetUnsorted
|
||||||
.map((data, index) => ({ data, index }))
|
.map((data, index) => ({ data, index }))
|
||||||
.sort(({ data: a, index: ai }, { data: b, index: bi }) => {
|
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
|
||||||
const parentsA = unroll(a).length
|
const parentsA = unroll(a).length
|
||||||
const parentsB = unroll(b).length
|
const parentsB = unroll(b).length
|
||||||
|
|
||||||
if (parentsA === parentsB) {
|
let aScore = 0
|
||||||
if (a.component === 'Text') return -1
|
let bScore = 0
|
||||||
if (b.component === 'Text') return 1
|
|
||||||
|
aScore += parentsA * 1000
|
||||||
|
bScore += parentsB * 1000
|
||||||
|
|
||||||
|
aScore += a.variant !== 'normal' ? 100 : 0
|
||||||
|
bScore += b.variant !== 'normal' ? 100 : 0
|
||||||
|
|
||||||
|
aScore += a.state.filter(x => x !== 'normal').length * 1000
|
||||||
|
bScore += b.state.filter(x => x !== 'normal').length * 1000
|
||||||
|
|
||||||
|
aScore += a.component === 'Text' ? 1 : 0
|
||||||
|
bScore += b.component === 'Text' ? 1 : 0
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
a.specifityScore = aScore
|
||||||
|
b.specifityScore = bScore
|
||||||
|
|
||||||
|
if (aScore === bScore) {
|
||||||
return ai - bi
|
return ai - bi
|
||||||
}
|
}
|
||||||
if (parentsA === 0 && parentsB !== 0) return -1
|
return aScore - bScore
|
||||||
if (parentsB === 0 && parentsA !== 0) return 1
|
|
||||||
return parentsA - parentsB
|
|
||||||
})
|
})
|
||||||
.map(({ data }) => data)
|
.map(({ data }) => data)
|
||||||
|
|
||||||
|
@ -235,7 +250,10 @@ export const init = ({
|
||||||
|
|
||||||
// Inheriting all of the applicable rules
|
// Inheriting all of the applicable rules
|
||||||
const existingRules = ruleset.filter(findRules(combination))
|
const existingRules = ruleset.filter(findRules(combination))
|
||||||
const computedDirectives = existingRules.map(r => r.directives).reduce((acc, directives) => ({ ...acc, ...directives }), {})
|
const computedDirectives =
|
||||||
|
existingRules
|
||||||
|
.map(r => r.directives)
|
||||||
|
.reduce((acc, directives) => ({ ...acc, ...directives }), {})
|
||||||
const computedRule = {
|
const computedRule = {
|
||||||
...combination,
|
...combination,
|
||||||
directives: computedDirectives
|
directives: computedDirectives
|
||||||
|
|
Loading…
Reference in a new issue