diff --git a/src/index.ts b/src/index.ts
index 5f057e6..129ecc6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -107,14 +107,16 @@ function injectProviderComponent(
const template = getRootBlock(root, 'template')
if (!template) {
console.warn(
- `To block found in ${id}. Skipping FormKitLazyProvider injection.`,
+ `No block found in ${id}. Skipping FormKitLazyProvider injection.`,
)
return { code, map: null }
}
const startInsertAt = template.children[0].loc.start.offset
+ const endInsertAt =
+ template.children[template.children.length - 1].loc.end.offset
const before = code.substring(0, startInsertAt)
- const content = code.substring(startInsertAt, template.loc.end.offset - 11)
- const after = code.substring(template.loc.end.offset - 11)
+ const content = code.substring(startInsertAt, endInsertAt)
+ const after = code.substring(endInsertAt)
code = `${before}\n${open}\n${content}\n${close}\n${after}`
return { code, map: null }
}
diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap
index 5c1f82d..717fcf4 100644
--- a/test/__snapshots__/index.test.ts.snap
+++ b/test/__snapshots__/index.test.ts.snap
@@ -14,8 +14,8 @@ import { FormKit } from '@formkit/vue'
label=\\"Your name\\"
help=\\"Enter your name\\"
/>
-
+
"
`;
@@ -48,9 +48,38 @@ function handleLoginSubmit(values: any) {
-
-t>
+
+
+
+"
+`;
+
+exports[`index > injects inside root node with multiple child elements 1`] = `
+"
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Here we go
+
+
"
@@ -73,9 +102,9 @@ export default {
Nothing to see here
-
-/>
+
"
`;
@@ -86,7 +115,7 @@ exports[`index > injects the template block into an normally structured sfc 1`]
-
+
"
`;
diff --git a/test/index.test.ts b/test/index.test.ts
index 6853b20..8ee2ef0 100644
--- a/test/index.test.ts
+++ b/test/index.test.ts
@@ -67,6 +67,36 @@ function handleLoginSubmit(values: any) {
).toMatchSnapshot()
})
+ it('injects inside root node with multiple child elements', async () => {
+ expect(
+ (
+ await plugin.transform(
+ `
+
+
+
+
+
+
+
+
+
+
+
+
Here we go
+
+
+`,
+ 'test.vue',
+ )
+ ).code,
+ ).toMatchSnapshot()
+ })
+
it('injects import into script setup block', async () => {
expect(
(await plugin.transform(aboutSFCFile, 'about.vue')).code,