Skip to content

Commit 2f461ea

Browse files
fix(convertUtilitiesToV4): drop js-regexp-lookbehind for improved browser support (#1555)
* refactor(ui~convertUtilitiesToV4): drop `js-regexp-lookbehind` in favor of more simpler regex for improved browser support * chore: remove invalid mdx frontmatter field * chore: add changeset
1 parent e6753c4 commit 2f461ea

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

.changeset/open-toys-sniff.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"flowbite-react": patch
3+
---
4+
5+
refactor(ui~convertUtilitiesToV4): drop `js-regexp-lookbehind` in favor of more simpler regex for improved browser support

apps/web/content/docs/getting-started/ai-integration.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: AI and LLM Integration with Flowbite React
33
description: Learn how to integrate Flowbite React with AI models, LLMs, and chatbots using our specialized documentation routes and markdown accessibility features
4-
keywords: AI integration, LLM integration, React AI, AI documentation, ChatGPT integration, AI components, language models, machine learning, documentation API, markdown API
54
---
65

76
Flowbite React provides powerful, built-in support for AI and Large Language Model (LLM) integration through specialized routes that expose documentation in machine-readable formats. These features enable seamless integration with ChatGPT, Claude, and other AI assistants.

packages/ui/src/helpers/convert-utilities-to-v4.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,29 @@ export function convertUtilitiesToV4(classNames: string): string {
1818
return cacheValue;
1919
}
2020

21-
let result = classNames;
21+
const parts = classNames.split(/(\s+)/);
22+
const result = parts
23+
.map((part) => {
24+
if (/^\s+$/.test(part)) {
25+
return part;
26+
}
2227

23-
for (const [regex, replacement] of regexMap) {
24-
result = result.replace(regex, replacement);
25-
}
28+
const processed = part;
29+
const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);
30+
31+
if (modifierMatch) {
32+
const [, modifier = "", baseClass] = modifierMatch;
33+
34+
for (const [regex, replacement] of regexMap) {
35+
if (regex.test(baseClass)) {
36+
return modifier + baseClass.replace(regex, replacement);
37+
}
38+
}
39+
}
40+
41+
return processed;
42+
})
43+
.join("");
2644

2745
cache.set(cacheKey, result);
2846

@@ -44,15 +62,15 @@ export function convertUtilitiesToV4(classNames: string): string {
4462
| ring | ring-3 |
4563
*/
4664
const regexMap = [
47-
[/\b(shadow-sm)\b/g, "shadow-xs"],
48-
[/(?<!-)(shadow)(?!-)\b/g, "shadow-sm"],
49-
[/\b(drop-shadow-sm)\b/g, "drop-shadow-xs"],
50-
[/\b(drop-shadow)\b(?!-)/g, "drop-shadow-sm"],
51-
[/\b(blur-sm)\b/g, "blur-xs"],
52-
[/\b(blur)\b(?!-)/g, "blur-sm"],
53-
[/\b(rounded-sm)\b/g, "rounded-xs"],
54-
[/\b(rounded)\b(?!-)/g, "rounded-sm"],
65+
[/^shadow-sm$/, "shadow-xs"],
66+
[/^shadow$/, "shadow-sm"],
67+
[/^drop-shadow-sm$/, "drop-shadow-xs"],
68+
[/^drop-shadow$/, "drop-shadow-sm"],
69+
[/^blur-sm$/, "blur-xs"],
70+
[/^blur$/, "blur-sm"],
71+
[/^rounded-sm$/, "rounded-xs"],
72+
[/^rounded$/, "rounded-sm"],
5573
// TODO: revisit this - it breaks anything focused using tab
56-
// [/\b(outline-none)\b/g, "outline-hidden"],
57-
[/\b(ring)\b(?!-)/g, "ring-3"],
74+
// [/^outline-none$/, "outline-hidden"],
75+
[/^ring$/, "ring-3"],
5876
] as const;

0 commit comments

Comments
 (0)