Skip to content

Commit f75026e

Browse files
committed
feat(projects): add Nuxt module and resolver components with updated paths and types
1 parent cc31cbe commit f75026e

File tree

7 files changed

+136
-11
lines changed

7 files changed

+136
-11
lines changed

headless/src/nuxt/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export interface ModuleOptions {
77

88
export default defineNuxtModule({
99
meta: {
10-
name: 'soybean-headless/nuxt',
11-
configKey: 'soybean-headless',
10+
name: '@soybeanjs/headless/nuxt',
11+
configKey: '@soybeanjs/headless',
1212
compatibility: {
1313
nuxt: '>=3.14'
1414
}
@@ -35,7 +35,7 @@ export default defineNuxtModule({
3535
addComponent({
3636
name: `${component}`,
3737
export: component,
38-
filePath: 'soybean-headless'
38+
filePath: '@soybeanjs/headless'
3939
});
4040
}
4141
}

headless/src/resolver/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { ComponentResolver } from 'unplugin-vue-components';
22
import { components } from '../constants';
3-
import { toKebabCase } from '../shared';
3+
import { toKebabCase, toPascalCase } from '../shared';
44

55
export interface ResolverOptions {
66
/**
77
* Whether to use standalone components
88
*
9-
* "true" means use `import { AccordionRoot } from 'soybean-headless/accordion'`
9+
* "true" means use `import { AccordionRoot } from '@soybeanjs/headless/accordion'`
1010
*
11-
* "false" means use `import { AccordionRoot } from 'soybean-headless'`
11+
* "false" means use `import { AccordionRoot } from '@soybeanjs/headless'`
1212
*
1313
* @defaultValue false
1414
*/
@@ -20,14 +20,15 @@ function createResolver(options: ResolverOptions = {}) {
2020
type: 'component',
2121
resolve: (name: string) => {
2222
const values = Object.values(components).flat();
23+
const $name = toPascalCase(name);
2324

24-
if (values.includes(name)) {
25-
const moduleName = toKebabCase(name).split('-')[0];
25+
if (values.includes($name)) {
26+
const moduleName = toKebabCase($name).split('-')[0];
2627

27-
const $from = options.standalone ? `soybean-headless/${moduleName}` : `soybean-headless`;
28+
const $from = options.standalone ? `@soybeanjs/headless/${moduleName}` : `@soybeanjs/headless`;
2829

2930
return {
30-
name,
31+
name: $name,
3132
from: $from
3233
};
3334
}

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
"import": "./dist/index.js",
2828
"require": "./dist/index.js"
2929
},
30+
"./nuxt": {
31+
"types": "./dist/nuxt/index.d.ts",
32+
"import": "./dist/nuxt/index.js",
33+
"require": "./dist/nuxt/index.js"
34+
},
35+
"./resolver": {
36+
"types": "./dist/resolver/index.d.ts",
37+
"import": "./dist/resolver/index.js",
38+
"require": "./dist/resolver/index.js"
39+
},
3040
"./styles.css": "./dist/styles.css"
3141
},
3242
"main": "./dist/index.js",

src/constants/components.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export const components = {
2+
accordion: ['SAccordion'],
3+
alertDialog: ['SAlertDialog', 'SAlertDialogCancel', 'SAlertDialogAction'],
4+
alert: ['SAlert'],
5+
arrow: ['SArrow'],
6+
avatar: ['SAvatar'],
7+
card: ['SCard'],
8+
breadcrumb: ['SBreadcrumb', 'SBreadcrumbPage', 'SBreadcrumbEllipsis'],
9+
checkbox: ['SCheckboxGroup', 'SCheckbox', 'SCheckboxCardGroup', 'SCheckboxCard'],
10+
badge: ['SBadge'],
11+
collapsible: ['SCollapsible', 'SCollapsibleContent', 'SCollapsibleTrigger'],
12+
configProvider: ['SConfigProvider'],
13+
button: ['SButton', 'SButtonLoading', 'SButtonIcon', 'SButtonLink', 'SButtonGroup'],
14+
command: ['SCommand'],
15+
dialog: ['SDialog', 'SDialogClose', 'SDialogPure'],
16+
aspectRatio: ['SAspectRatio'],
17+
contextMenu: ['SContextMenu', 'SContextMenuCheckbox', 'SContextMenuRadio', 'SContextMenuWrapper'],
18+
drawer: ['SDrawer', 'SDrawerClose'],
19+
form: ['SForm', 'SFormField', 'SFormFieldArray'],
20+
dropdownMenu: ['SDropdownMenu', 'SDropdownMenuCheckbox', 'SDropdownMenuRadio', 'SDropdownMenuWrapper'],
21+
input: ['SInput'],
22+
kbd: ['SKbd'],
23+
label: ['SLabel'],
24+
icon: ['SIcon'],
25+
layout: ['SLayout', 'SLayoutTrigger'],
26+
link: ['SLink'],
27+
list: ['SList', 'SListItem'],
28+
menu: ['SMenuOption', 'SMenuOptions', 'SMenuCheckboxOptions', 'SMenuRadioOptions'],
29+
navigationMenu: ['SNavigationMenu'],
30+
pagination: ['SPagination'],
31+
numberInput: ['SNumberInput'],
32+
password: ['SPassword'],
33+
popover: ['SPopover'],
34+
radioGroup: ['SRadioGroup', 'SRadio', 'SRadioCard', 'SRadioCardGroup'],
35+
segment: ['SSegment'],
36+
separator: ['SSeparator'],
37+
switch: ['SSwitch'],
38+
tabs: ['STabs'],
39+
select: ['SSelect'],
40+
textarea: ['STextarea'],
41+
tag: ['STag'],
42+
tooltip: ['STooltip'],
43+
treeMenu: ['STreeMenu', 'STreeMenuItemWrapper'],
44+
tree: ['STree', 'STreeVirtualizer'],
45+
virtualizer: ['SVirtualizer']
46+
};

src/nuxt/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { addComponent, defineNuxtModule } from '@nuxt/kit';
2+
import { components } from '../constants/components';
3+
4+
export interface ModuleOptions {
5+
components: Partial<Record<keyof typeof components, boolean>> | boolean;
6+
}
7+
8+
export default defineNuxtModule({
9+
meta: {
10+
name: '@soybeanjs/ui/nuxt',
11+
configKey: '@soybeanjs/ui',
12+
compatibility: {
13+
nuxt: '>=3.14'
14+
}
15+
},
16+
defaults: {
17+
components: true
18+
},
19+
setup(options: ModuleOptions) {
20+
function getComponents() {
21+
if (typeof options.components === 'object') {
22+
return Object.entries(components)
23+
.filter(([name]) => (options.components as Record<string, boolean>)[name])
24+
.flatMap(([_, _components]) => _components);
25+
}
26+
27+
if (options.components) {
28+
return Object.values(components).flat();
29+
}
30+
31+
return [];
32+
}
33+
34+
for (const component of getComponents()) {
35+
addComponent({
36+
name: `${component}`,
37+
export: component,
38+
filePath: '@soybeanjs/ui'
39+
});
40+
}
41+
}
42+
});

src/resolver/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { ComponentResolver } from 'unplugin-vue-components';
2+
import { components } from '../constants/components';
3+
4+
function createResolver() {
5+
const resolver: ComponentResolver = {
6+
type: 'component',
7+
resolve: (name: string) => {
8+
const values = Object.values(components).flat();
9+
10+
const $name = name.replace(/(^\w|-\w)/g, char => char.replace('-', '').toUpperCase());
11+
12+
if (values.includes($name)) {
13+
return {
14+
name: $name,
15+
from: '@soybeanjs/ui'
16+
};
17+
}
18+
19+
return null;
20+
}
21+
};
22+
23+
return resolver;
24+
}
25+
26+
export default createResolver;

tsdown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import pkg from './package.json' with { type: 'json' };
55
import headlessPkg from './headless/package.json' with { type: 'json' };
66

77
export default defineConfig({
8-
entry: ['src/index.ts'],
8+
entry: ['src/index.ts', 'src/nuxt/index.ts', 'src/resolver/index.ts'],
99
platform: 'neutral',
1010
external: [
1111
...Object.keys(headlessPkg.dependencies),

0 commit comments

Comments
 (0)