Skip to content

Commit 6ee99eb

Browse files
committed
refactor(formkit-nuxt): Replace plugin installation of formkit with formkit-nuxt
BREAKING CHANGE: With the use of formkit-nuxt path to a formkit.config.ts must be provided or a formkit.config.ts must exits in your base path - formkitAutoConfig module option is replaced by installFormKit
1 parent 34d0681 commit 6ee99eb

File tree

6 files changed

+69
-122
lines changed

6 files changed

+69
-122
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ Based on [sfxcode/formkit-primevue](https://github.com/sfxcode/formkit-primevue)
1414

1515
## Features
1616

17-
<!-- Highlight some of the features your module provide here -->
1817
-&nbsp;Validation by FormKit
1918
- 🚠 &nbsp;UI by PrimeVue
2019
- 🏎 &nbsp;Auto import for formkit-primevue components and composables
21-
-
20+
21+
## Nuxt Module Dependencies
22+
23+
- primevue-nuxt Module
24+
- formkit-nuxt Module
25+
26+
Both are auto installed by default, this can be disabled in the module options.
27+
2228
## Quick Setup
2329

2430
Install the module to your Nuxt application with one command:
@@ -29,43 +35,37 @@ npx nuxi module add @sfxcode/formkit-primevue-nuxt
2935

3036
That's it! You can now use FormKit PrimeVue Nuxt Module in your Nuxt app ✨
3137

38+
3239
## Module Options
3340

3441
- **includePrimeIcons** (default: `true`): Add PrimeIcons CSS to the project.
3542
- **includeStyles** (default: `true`): Add custom FormKit CSS to the project.
36-
- **formkitAutoConfig** (default: `true`): Automatically configure FormKit.
37-
- **formkitLocale** (default: `'en'`): Set the FormKit local (Only hen formkitAutoConfig is `true`).
38-
- **formkitPluginAnimate** (default: `true`): Enable FormKit animate plugin (Only hen formkitAutoConfig is `true`).
39-
- **formkitPluginAsterisk** (default: `true`): Enable FormKit asterisk plugin (Only hen formkitAutoConfig is `true`).
4043
- **installI18N** (default: `true`): Install nuxt i18n module automatically.
44+
- **installFormKit** (default: `true`): Install nuxt formkit module automatically.
4145

42-
### Custom Global FormKit Configuration
46+
### Removed options since 1.2.0
47+
- **formkitAutoConfig** : Automatically configure FormKit. => Removed in favor of **installFormKit**
48+
- **formkitLocale** ,**formkitPluginAnimate**, **formkitPluginAsterisk** : use **formkit.config.ts** for custom configuration
4349

44-
You can also provide a custom FormKit configuration by adding the following configuration to your `nuxt.config.ts`:
50+
### FormKit Configuration
4551

46-
```ts
47-
formkitPrimevue: {
48-
formkitAutoConfig: false
49-
}
50-
```
51-
52-
and creating a custom nuxt plugin in the `plugins` directory:
52+
Use a formkit.config.ts file to configure FormKit.
5353

54-
for example `plugins/formkit.ts`:
5554
```ts
56-
import { defaultConfig, plugin } from '@formkit/vue'
55+
// formkit.config.ts
56+
import type { DefaultConfigOptions } from '@formkit/vue'
5757
import { primeInputs, primeOutputs } from '@sfxcode/formkit-primevue'
5858

59-
export default defineNuxtPlugin((nuxtApp) => {
60-
// Doing something with nuxtApp
61-
const app = nuxtApp.vueApp
62-
app.use(plugin, defaultConfig({
63-
inputs: { ...primeInputs, ...primeOutputs },
64-
// ... additional configurations like locales, plugins, custom validations etc.
65-
}))
66-
})
59+
const config: DefaultConfigOptions = {
60+
// Define the active locale
61+
inputs: { ...primeInputs, ...primeOutputs },
62+
}
63+
64+
export default config
6765

6866
````
67+
68+
6969
## Additional Configuration
7070

7171
For i18n support, you can add the following configuration to your `nuxt.config.ts`:

playground/formkit.config.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

playground/nuxt.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export default defineNuxtConfig({
44
modules: ['../src/module'],
55
devtools: { enabled: true },
66
compatibilityDate: '2024-11-03',
7+
formkit: {
8+
configFile: '../src/runtime/formkit.config.ts',
9+
},
710
formkitPrimevue: {
811
includePrimeIcons: true,
912
includeStyles: true,
10-
formkitAutoConfig: true,
11-
formkitLocale: 'en',
12-
formkitPluginAnimate: true,
13-
formkitPluginAsterisk: true,
13+
installFormKit: true,
1414
installI18N: true,
1515
},
1616
i18n: {

src/module.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import defu from 'defu'
1111
export interface ModuleOptions {
1212
includePrimeIcons: boolean
1313
includeStyles: boolean
14-
formkitAutoConfig: boolean
15-
formkitLocale: 'en' | 'de' | 'fr' | 'es' | 'tr'
16-
formkitPluginAsterisk: boolean
17-
formkitPluginAnimate: boolean
14+
installFormKit: boolean
1815
installI18N: boolean
1916
}
2017

@@ -30,28 +27,17 @@ export default defineNuxtModule<ModuleOptions>({
3027
defaults: {
3128
includePrimeIcons: true,
3229
includeStyles: true,
33-
formkitAutoConfig: true,
34-
formkitLocale: 'en',
35-
formkitPluginAnimate: true,
36-
formkitPluginAsterisk: true,
30+
installFormKit: true,
3731
installI18N: true,
3832
},
3933
async setup(_options, _nuxt) {
40-
_nuxt.options.runtimeConfig.public.formkitPrimevue = defu(_nuxt.options.runtimeConfig.public.formkitPrimevue,
41-
{
42-
formkitAutoConfig: _options.formkitAutoConfig,
43-
formkitLocale: _options.formkitLocale,
44-
formkitPluginAnimate: _options.formkitPluginAnimate,
45-
formkitPluginAsterisk: _options.formkitPluginAsterisk,
46-
},
47-
)
48-
4934
const resolver = createResolver(import.meta.url)
5035
await installModule('@primevue/nuxt-module')
5136
// Do not add the extension since the `.ts` will be transpiled to `.mjs` after `npm run prepack`
5237
addPlugin(resolver.resolve('./runtime/plugin'))
5338

54-
await installModule('@formkit/nuxt', { defaultConfig: true, configFile: 'formkit.config.ts', autoImport: true })
39+
if (_options.installFormKit)
40+
await installModule('@formkit/nuxt')
5541

5642
if (_options.installI18N)
5743
await installModule('@nuxtjs/i18n')

src/runtime/formkit.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// formkit.config.ts
2+
import type { DefaultConfigOptions } from '@formkit/vue'
3+
import { createAutoAnimatePlugin } from '@formkit/addons'
4+
import { de, en } from '@formkit/i18n'
5+
import { primeInputs, primeOutputs } from '@sfxcode/formkit-primevue'
6+
import { addPrimeAsteriskPlugin } from '@sfxcode/formkit-primevue/plugins'
7+
8+
const config: DefaultConfigOptions = {
9+
locales: { en, de },
10+
// Define the active locale
11+
locale: 'de',
12+
inputs: { ...primeInputs, ...primeOutputs },
13+
14+
plugins: [
15+
createAutoAnimatePlugin(
16+
{
17+
/* optional AutoAnimate config */
18+
// default:
19+
duration: 250,
20+
easing: 'ease-in-out',
21+
},
22+
{
23+
/* optional animation targets object */
24+
// default:
25+
global: ['outer', 'inner'],
26+
form: ['form'],
27+
repeater: ['items'],
28+
},
29+
),
30+
addPrimeAsteriskPlugin,
31+
],
32+
}
33+
34+
export default config

src/runtime/plugin.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import { primeInputs, primeOutputs, usePrimeInputs } from '@sfxcode/formkit-primevue'
2-
import { addPrimeAsteriskPlugin } from '@sfxcode/formkit-primevue/plugins'
3-
import { createAutoAnimatePlugin } from '@formkit/addons'
4-
import { de, en, es, fr, tr } from '@formkit/i18n'
5-
import { defaultConfig, plugin, ssrComplete, resetCount } from '@formkit/vue'
6-
import type { FormKitPlugin } from '@formkit/core'
7-
import { useRuntimeConfig } from '#app/nuxt'
1+
import { usePrimeInputs } from '@sfxcode/formkit-primevue'
2+
83
import { defineNuxtPlugin } from '#app'
94

105
export default defineNuxtPlugin((_nuxtApp) => {
@@ -14,40 +9,4 @@ export default defineNuxtPlugin((_nuxtApp) => {
149

1510
const { registerInputs } = usePrimeInputs()
1611
registerInputs(app)
17-
//
18-
// if (runtimeConfig.public.formkitPrimevue.formkitAutoConfig) {
19-
// const formkitPlugins: FormKitPlugin[] = []
20-
// if (runtimeConfig.public.formkitPrimevue.formkitPluginAsterisk) {
21-
// formkitPlugins.push(addPrimeAsteriskPlugin)
22-
// }
23-
// if (runtimeConfig.public.formkitPrimevue.formkitPluginAnimate) {
24-
// formkitPlugins.push(createAutoAnimatePlugin(
25-
// {
26-
// /* optional AutoAnimate config */
27-
// // default:
28-
// duration: 250,
29-
// easing: 'ease-in-out',
30-
// },
31-
// {
32-
// /* optional animation targets object */
33-
// // default:
34-
// global: ['outer', 'inner'],
35-
// form: ['form'],
36-
// repeater: ['items'],
37-
// },
38-
// ))
39-
// }
40-
// app.use(plugin, defaultConfig({
41-
// locales: { de, en, es, fr, tr },
42-
// // Define the active locale
43-
// locale: runtimeConfig.public.formkitPrimevue.formkitLocale,
44-
// inputs: { ...primeInputs, ...primeOutputs },
45-
// plugins: formkitPlugins,
46-
// }))
47-
// }
48-
//
49-
// _nuxtApp.hook('app:rendered', () => {
50-
// resetCount()
51-
// ssrComplete(_nuxtApp.vueApp)
52-
// })
5312
})

0 commit comments

Comments
 (0)