Skip to content

Commit

Permalink
Ensure resorted plugins take into account all plugins they need to so…
Browse files Browse the repository at this point in the history
…rt relative to (#4852)
  • Loading branch information
adamwathan authored Jul 1, 2021
1 parent b417e33 commit 369c7b5
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 630 deletions.
41 changes: 35 additions & 6 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import * as plugins from './plugins/index.js'
import configurePlugins from './util/configurePlugins'

function move(items, item, before) {
if (items.indexOf(item) === -1) {
function move(items, item, befores) {
let lowestBefore = -1

for (let before of befores) {
let index = items.indexOf(before)
if (index >= 0 && (index < lowestBefore || lowestBefore === -1)) {
lowestBefore = index
}
}

if (items.indexOf(item) === -1 || lowestBefore === -1) {
return items
}

items = [...items]
let fromIndex = items.indexOf(item)
let toIndex = items.indexOf(before)
let toIndex = lowestBefore
items.splice(fromIndex, 1)
items.splice(toIndex, 0, item)
return items
Expand All @@ -18,9 +27,29 @@ export default function ({ corePlugins: corePluginConfig }) {
let pluginOrder = Object.keys(plugins)

pluginOrder = configurePlugins(corePluginConfig, pluginOrder)
pluginOrder = move(pluginOrder, 'transform', 'transformOrigin')
pluginOrder = move(pluginOrder, 'filter', 'blur')
pluginOrder = move(pluginOrder, 'backdropFilter', 'backdropBlur')
pluginOrder = move(pluginOrder, 'transform', ['translate', 'rotate', 'skew', 'scale'])
pluginOrder = move(pluginOrder, 'filter', [
'blur',
'brightness',
'contrast',
'dropShadow',
'grayscale',
'hueRotate',
'invert',
'saturate',
'sepia',
])
pluginOrder = move(pluginOrder, 'backdropFilter', [
'backdropBlur',
'backdropBrightness',
'backdropContrast',
'backdropGrayscale',
'backdropHueRotate',
'backdropInvert',
'backdropOpacity',
'backdropSaturate',
'backdropSepia',
])

return pluginOrder.map((pluginName) => {
return plugins[pluginName]()
Expand Down
Loading

0 comments on commit 369c7b5

Please sign in to comment.