Skip to content

Commit

Permalink
fix(module): deduplicate default safelist as components may share sam…
Browse files Browse the repository at this point in the history
…e rules
  • Loading branch information
benjamincanac committed Jun 13, 2023
1 parent 5f7de8e commit 2cfa1f8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,28 @@ const colorsAsRegex = (colors: string[]): string => colors.join('|')

export const excludeColors = (colors: object) => Object.keys(omit(colors, colorsToExclude)).map(color => kebabCase(color)) as string[]

export const generateSafelist = (colors: string[]) => ['avatar', 'badge', 'button', 'input', 'notification'].flatMap(component => safelistByComponent[component](colorsAsRegex(colors)))
const mergeSafelist = (safelist) => {
return safelist.reduce((result, current) => {
const found = result.find(obj => obj.pattern.toString() === current.pattern.toString())
if (found) {
if (Array.isArray(found.variants) && Array.isArray(current.variants)) {
const mergedVariants = [...new Set([...found.variants, ...current.variants])]
found.variants = mergedVariants
} else if (Array.isArray(current.variants)) {
found.variants = current.variants
}
} else {
result.push(current)
}
return result
}, [])
}

export const generateSafelist = (colors: string[]) => {
const safelist = ['avatar', 'badge', 'button', 'input', 'notification'].flatMap(component => safelistByComponent[component](colorsAsRegex(colors)))

return mergeSafelist(safelist)
}

export const customSafelistExtractor = (prefix, content: string, colors: string[]) => {
const classes = []
Expand Down

1 comment on commit 2cfa1f8

@vercel
Copy link

@vercel vercel bot commented on 2cfa1f8 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxtlabs.vercel.app
ui-git-dev-nuxtlabs.vercel.app
ui.nuxtlabs.com

Please sign in to comment.