-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bootstrap-vue): add support for aliases and directives (#470)
- Loading branch information
1 parent
f43f073
commit b5f293f
Showing
2 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,86 @@ | ||
import type { ComponentResolver } from '../../types' | ||
|
||
export interface BootstrapVueResolverOptions { | ||
/** | ||
* Auto import for directives. | ||
* | ||
* @default true | ||
*/ | ||
directives?: boolean | ||
} | ||
|
||
const COMPONENT_ALIASES: Record<string, string> = { | ||
BBtn: 'BButton', | ||
BBtnClose: 'BButtonClose', | ||
BBtnGroup: 'BButtonGroup', | ||
BBtnToolbar: 'BButtonToolbar', | ||
BCheck: 'BFormCheckbox', | ||
BCheckbox: 'BFormCheckbox', | ||
BCheckboxGroup: 'BFormCheckboxGroup', | ||
BCheckGroup: 'BFormCheckboxGroup', | ||
BDatalist: 'BFormDatalist', | ||
BDd: 'BDropdown', | ||
BDdDivider: 'BDropdownDivider', | ||
BDdForm: 'BDropdownForm', | ||
BDdGroup: 'BDropdownGroup', | ||
BDdHeader: 'BDropdownHeader', | ||
BDdItem: 'BDropdownItem', | ||
BDdItemButton: 'BDropdownItemButton', | ||
BDdItemBtn: 'BDropdownItemButton', | ||
BDdText: 'BDropdownText', | ||
BDropdownItemBtn: 'BDropdownItemButton', | ||
BFile: 'BFormFile', | ||
BFormDatepicker: 'BDatepicker', | ||
BInput: 'BFormInput', | ||
BNavDd: 'BNavItemDropdown', | ||
BNavDropdown: 'BNavItemDropdown', | ||
BNavItemDd: 'BNavItemDropdown', | ||
BNavToggle: 'BNavbarToggle', | ||
BRadio: 'BFormRadio', | ||
BRadioGroup: 'BFormRadioGroup', | ||
BRating: 'BFormRating', | ||
BSelect: 'BFormSelect', | ||
BSelectOption: 'BFormSelectOption', | ||
BSelectOptionGroup: 'BFormSelectOptionGroup', | ||
BSpinbutton: 'BFormSpinbutton', | ||
BTag: 'BFormTag', | ||
BTags: 'BFormTags', | ||
BTextarea: 'BFormTextarea', | ||
BTimepicker: 'BFormTimepicker', | ||
} | ||
|
||
/** | ||
* Resolver for BootstrapVue | ||
* | ||
* @link https://github.com/bootstrap-vue/bootstrap-vue | ||
*/ | ||
export function BootstrapVueResolver(): ComponentResolver { | ||
return { | ||
export function BootstrapVueResolver(_options: BootstrapVueResolverOptions = {}): ComponentResolver[] { | ||
const options = { directives: true, ..._options } | ||
const resolvers: ComponentResolver[] = [{ | ||
type: 'component', | ||
resolve: (name: string) => { | ||
if (name.match(/^B[A-Z]/)) | ||
return { name, from: 'bootstrap-vue' } | ||
resolve: (name) => { | ||
if (name.match(/^B[A-Z]/)) { | ||
return { | ||
name: COMPONENT_ALIASES[name] || name, | ||
from: 'bootstrap-vue', | ||
} | ||
} | ||
}, | ||
}] | ||
|
||
if (options.directives) { | ||
resolvers.push({ | ||
type: 'directive', | ||
resolve: (name) => { | ||
if (name.match(/^B[A-Z]/)) { | ||
return { | ||
name: `V${name}`, | ||
from: 'bootstrap-vue', | ||
} | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
return resolvers | ||
} |