import type { ComponentResolver, SideEffectsInfo } from 'unplugin-vue-components' const components = [ // Form 'AutoComplete', 'Calendar', 'CascadeSelect', 'Checkbox', 'Chips', 'ColorPicker', 'Dropdown', 'Editor', 'FloatLabel', 'IconField', 'InputGroup', 'InputMask', 'InputNumber', 'InputOtp', 'InputSwitch', 'InputText', 'Knob', 'Listbox', 'MultiSelect', 'Password', 'RadioButton', 'Rating', 'SelectButton', 'Slider', 'Textarea', 'ToggleButton', 'TreeSelect', // Button 'Button', 'SpeedDial', 'SplitButton', // Data 'DataTable', 'DataView', 'OrderList', 'OrgChart', 'Paginator', 'PickList', 'Tree', 'TreeTable', 'Timeline', 'VirtualScroller', // Panel 'Accordion', 'Card', 'Deferred', 'Divider', 'Fieldset', 'Panel', 'ScrollPanel', 'Splitter', 'Stepper', 'TabView', 'TabPanel', 'Toolbar', // Overlay 'ConfirmDialog', 'ConfirmPopup', 'DynamicDialog', 'Tooltip', // need to add directive // must be registered globally in order for the XXX service to work properly 'OverlayPanel', 'Sidebar', // File 'FileUpload', // Menu 'Breadcrumb', 'ContextMenu', 'Dock', 'Menu', 'Menubar', 'MegaMenu', 'PanelMenu', 'Steps', 'TabMenu', 'TieredMenu', // Messages 'Toast', // Toast must be registered globally in order for the XXX service to work properly 'Message', 'InlineMessage', // Media 'Carousel', 'Galleria', 'Image', // Misc 'Avatar', 'Badge', 'BlockUI', 'Chip', 'FocusTrap', 'Inplace', 'MeterGroup', 'ScrollTop', 'Skeleton', 'ProgressBar', 'ProgressSpinner', 'AnimateOnScroll', 'Ripple', 'StyleClass', 'Tag', 'Terminal', ] export interface PrimeVueResolverOptions { /** * import style along with components * * @default true */ importStyle?: boolean /** * import `primeicons' icons * * requires package `primeicons` * * @default true */ importIcons?: boolean /** * imports a free theme - set theme name here (e.g. saga-blue) * * @default '' */ importTheme?: string /** * prefix for components (e.g. 'P' to resolve Menu from PMenu) * * @default '' */ prefix?: string } /** * Resolver for PrimeVue - If you're using a component with the same tag as an native HTML element (e.g. button) the component must be in uppercase * * @link https://github.com/primefaces/primevue */ export function PrimeVueResolver(options: PrimeVueResolverOptions = {}): ComponentResolver { return { type: 'component', resolve: (name: string) => { const sideEffects: SideEffectsInfo = [] if (options.importStyle) { sideEffects.push('primevue/resources/primevue.min.css') } if (options.importIcons) { sideEffects.push('primeicons/primeicons.css') } if (options.importTheme) { sideEffects.push( `primevue/resources/themes/${options.importTheme}/theme.css`, ) } if (options.prefix) { if (!name.startsWith(options.prefix)) { return } name = name.substring(options.prefix.length) } if (components.includes(name)) { return { from: `primevue/${name.toLowerCase()}`, sideEffects, } } }, } }