Implement getClassOrder instead of sortClassList (#7459)

* implement `getSortOrder` instead of `sortClassList`

* rename `getSortOrder` to `getClassOrder`

* update changelog
This commit is contained in:
Robin Malfait 2022-02-16 11:03:00 +01:00 • committed by GitHub
parent be5d5c9e66
commit 63537aaa89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 21 deletions

View file

@ -744,33 +744,25 @@ function registerPlugins(plugins, context) {
// sorting could be weird since you still require them in order to make the
// host utitlies work properly. (Thanks Biology)
let parasiteUtilities = new Set([prefix(context, 'group'), prefix(context, 'peer')])
context.sortClassList = function sortClassList(classes) {
context.getClassOrder = function getClassOrder(classes) {
let sortedClassNames = new Map()
for (let [sort, rule] of generateRules(new Set(classes), context)) {
if (sortedClassNames.has(rule.raws.tailwind.candidate)) continue
sortedClassNames.set(rule.raws.tailwind.candidate, sort)
}
return classes
.map((className) => {
let order = sortedClassNames.get(className) ?? null
return classes.map((className) => {
let order = sortedClassNames.get(className) ?? null
if (order === null && parasiteUtilities.has(className)) {
// This will make sure that it is at the very beginning of the
// `components` layer which technically means 'before any
// components'.
order = context.layerOrder.components
}
if (order === null && parasiteUtilities.has(className)) {
// This will make sure that it is at the very beginning of the
// `components` layer which technically means 'before any
// components'.
order = context.layerOrder.components
}
return [className, order]
})
.sort(([, a], [, z]) => {
if (a === z) return 0
if (a === null) return -1
if (z === null) return 1
return bigSign(a - z)
})
.map(([className]) => className)
return [className, order]
})
}
// Generate a list of strings for autocompletion purposes, e.g.