Skip to content

Commit cc6bddf

Browse files
committed
fix: collect safelist of listCssClass
1 parent c635d48 commit cc6bddf

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

adminforth/documentation/docs/tutorial/03-Customization/13-standardPagesTuning.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export default {
145145
### Custom list column class
146146

147147
You can add a custom CSS class to any list column with `listCssClass`. AdminForth applies it to both the header cell and the data cells for that column.
148+
Static Tailwind utility classes used here are collected into the generated Tailwind safelist during bundling, so you can use normal utility strings in the resource config.
148149

149150
```typescript title="./resources/apartments.ts"
150151
export default {

adminforth/modules/codeInjector.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ class CodeInjector implements ICodeInjector {
140140
this.allComponentNames[filePath] = componentName;
141141
}
142142

143+
collectTailwindSafelist(): string[] {
144+
const classes = new Set<string>();
145+
146+
for (const resource of this.adminforth.config.resources) {
147+
for (const column of resource.columns || []) {
148+
if (!column.listCssClass) {
149+
continue;
150+
}
151+
152+
column.listCssClass
153+
.split(/\s+/)
154+
.filter(Boolean)
155+
.forEach((className) => classes.add(className));
156+
}
157+
}
158+
159+
return Array.from(classes);
160+
}
161+
143162
cleanup() {
144163
console.log('Cleaning up...');
145164
this.allWatchers.forEach((watcher) => {
@@ -698,9 +717,11 @@ class CodeInjector implements ICodeInjector {
698717
// generate tailwind extend styles
699718
const stylesGenerator = new StylesGenerator(this.adminforth.config.customization?.styles);
700719
const stylesText = JSON.stringify(stylesGenerator.mergeStyles(), null, 2).slice(1, -1);
720+
const safelistText = JSON.stringify(this.collectTailwindSafelist(), null, 2).slice(1, -1);
701721
let tailwindConfigPath = path.join(this.spaTmpPath(), 'tailwind.config.js');
702722
let tailwindConfigContent = await fs.promises.readFile(tailwindConfigPath, 'utf-8');
703723
tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND STYLES */', stylesText);
724+
tailwindConfigContent = tailwindConfigContent.replace('/* IMPORTANT:ADMINFORTH TAILWIND SAFELIST */', safelistText);
704725
await fs.promises.writeFile(tailwindConfigPath, tailwindConfigContent);
705726

706727

adminforth/spa/tailwind.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
export default {
44
content: ["./src/**/*.{vue, js, ts, tsx}","./src/*.{vue, js, ts, tsx}", "./index.html", "./node_modules/flowbite/**/*.js"],
5+
safelist: [
6+
/* IMPORTANT:ADMINFORTH TAILWIND SAFELIST */
7+
],
58
theme: {
69
extend: {
710
/* IMPORTANT:ADMINFORTH TAILWIND STYLES */
@@ -13,4 +16,3 @@ export default {
1316
require('@tailwindcss/typography'),
1417
],
1518
}
16-

0 commit comments

Comments
 (0)