Initial commit
This commit is contained in:
35
src/utils/resolve-icon.ts
Normal file
35
src/utils/resolve-icon.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as Icons from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
|
||||
type IconInput = string | LucideIcon;
|
||||
|
||||
// Social brand icons removed in lucide-react 1.x — map to neutral alternatives
|
||||
const REMOVED_ICON_ALIASES: Record<string, LucideIcon> = {
|
||||
Linkedin: Icons.Globe,
|
||||
Twitter: Icons.Globe,
|
||||
Instagram: Icons.Globe,
|
||||
Facebook: Icons.Globe,
|
||||
Youtube: Icons.Globe,
|
||||
Github: Icons.Code,
|
||||
Snapchat: Icons.Globe,
|
||||
Pinterest: Icons.Globe,
|
||||
Tiktok: Icons.Globe,
|
||||
Discord: Icons.MessageCircle,
|
||||
};
|
||||
|
||||
const isValidComponent = (value: unknown): boolean =>
|
||||
!!value && (typeof value === "function" || (typeof value === "object" && "$$typeof" in value));
|
||||
|
||||
export function resolveIcon(icon: IconInput): LucideIcon {
|
||||
if (typeof icon === "string") {
|
||||
const alias = REMOVED_ICON_ALIASES[icon];
|
||||
if (alias) return alias;
|
||||
const resolved = (Icons as Record<string, unknown>)[icon];
|
||||
if (isValidComponent(resolved)) return resolved as LucideIcon;
|
||||
return Icons.HelpCircle;
|
||||
}
|
||||
if (!isValidComponent(icon)) return Icons.HelpCircle;
|
||||
return icon;
|
||||
}
|
||||
|
||||
export type { IconInput };
|
||||
20
src/utils/resolve-icon.tsx
Normal file
20
src/utils/resolve-icon.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import { resolveIcon } from "./resolve-icon";
|
||||
import type { IconInput } from "./resolve-icon";
|
||||
|
||||
const DynamicIcon = ({
|
||||
icon,
|
||||
size,
|
||||
className,
|
||||
strokeWidth,
|
||||
}: {
|
||||
icon: IconInput;
|
||||
size?: number;
|
||||
className?: string;
|
||||
strokeWidth?: number;
|
||||
}) => {
|
||||
const Icon = resolveIcon(icon);
|
||||
return <Icon size={size} className={className} strokeWidth={strokeWidth} />;
|
||||
};
|
||||
|
||||
export default DynamicIcon;
|
||||
export type { IconInput };
|
||||
1419
src/utils/visual-edit-script.ts
Normal file
1419
src/utils/visual-edit-script.ts
Normal file
File diff suppressed because it is too large
Load Diff
21
src/utils/visual-edit.ts
Normal file
21
src/utils/visual-edit.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { getVisualEditScript, getVisualEditScriptRaw } from './visual-edit-script'
|
||||
|
||||
export { getVisualEditScript }
|
||||
|
||||
export function initVisualEdit() {
|
||||
// Inside iframe we must actually run the editor code so it can
|
||||
// attach listeners and interact with the DOM.
|
||||
if (window.self !== window.top) {
|
||||
const script = document.createElement('script')
|
||||
script.id = 'webild-visual-edit'
|
||||
script.textContent = getVisualEditScriptRaw()
|
||||
document.head.appendChild(script)
|
||||
return
|
||||
}
|
||||
|
||||
// Expose helper for parent tools/dev.
|
||||
if (import.meta.env.DEV) {
|
||||
window.__getVisualEditScript = getVisualEditScript
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user