diff --git a/packages/adapter-next/src/hooks/snippet-read.ts b/packages/adapter-next/src/hooks/snippet-read.ts index e491c12a1..853cdce54 100644 --- a/packages/adapter-next/src/hooks/snippet-read.ts +++ b/packages/adapter-next/src/hooks/snippet-read.ts @@ -59,19 +59,38 @@ export const snippetRead: SnippetReadHook = async ( } case "Link": { + const repeat = data.model.config?.repeat ?? false; + const allowText = data.model.config?.allowText ?? false; + + let codeText; + if (!repeat && !allowText) { + codeText = stripIndent` + Link + `; + } else if (!repeat && allowText) { + codeText = stripIndent` + + `; + } else if (repeat && !allowText) { + codeText = stripIndent` + {${dotPath(fieldPath)}.map((link, index) => ( + Link + ))} + `; + } else if (repeat && allowText) { + codeText = stripIndent` + {${dotPath(fieldPath)}.map((link, index) => ( + + ))} + `; + } else { + throw new Error("Invalid configuration."); + } + return { label, language: "tsx", - code: await format( - data.model.config?.allowText - ? stripIndent` - - ` - : stripIndent` - Link - `, - helpers, - ), + code: await format(codeText, helpers), }; } diff --git a/packages/adapter-nuxt/src/hooks/snippet-read.ts b/packages/adapter-nuxt/src/hooks/snippet-read.ts index 0cbe0ee06..fab4e24c2 100644 --- a/packages/adapter-nuxt/src/hooks/snippet-read.ts +++ b/packages/adapter-nuxt/src/hooks/snippet-read.ts @@ -58,19 +58,38 @@ export const snippetRead: SnippetReadHook = async ( } case "Link": { + const repeat = data.model.config?.repeat ?? false; + const allowText = data.model.config?.allowText ?? false; + + let codeText; + if (!repeat && !allowText) { + codeText = stripIndent` + Link + `; + } else if (!repeat && allowText) { + codeText = stripIndent` + + `; + } else if (repeat && !allowText) { + codeText = stripIndent` + + `; + } else if (repeat && allowText) { + codeText = stripIndent` + + `; + } else { + throw new Error("Invalid configuration."); + } + return { label, language: "vue", - code: await format( - data.model.config?.allowText - ? stripIndent` - - ` - : stripIndent` - Link - `, - helpers, - ), + code: await format(codeText, helpers), }; } diff --git a/packages/adapter-nuxt2/src/hooks/snippet-read.ts b/packages/adapter-nuxt2/src/hooks/snippet-read.ts index 0cbe0ee06..fab4e24c2 100644 --- a/packages/adapter-nuxt2/src/hooks/snippet-read.ts +++ b/packages/adapter-nuxt2/src/hooks/snippet-read.ts @@ -58,19 +58,38 @@ export const snippetRead: SnippetReadHook = async ( } case "Link": { + const repeat = data.model.config?.repeat ?? false; + const allowText = data.model.config?.allowText ?? false; + + let codeText; + if (!repeat && !allowText) { + codeText = stripIndent` + Link + `; + } else if (!repeat && allowText) { + codeText = stripIndent` + + `; + } else if (repeat && !allowText) { + codeText = stripIndent` + + `; + } else if (repeat && allowText) { + codeText = stripIndent` + + `; + } else { + throw new Error("Invalid configuration."); + } + return { label, language: "vue", - code: await format( - data.model.config?.allowText - ? stripIndent` - - ` - : stripIndent` - Link - `, - helpers, - ), + code: await format(codeText, helpers), }; } diff --git a/packages/adapter-sveltekit/src/hooks/snippet-read.ts b/packages/adapter-sveltekit/src/hooks/snippet-read.ts index 798cf9e24..15583133b 100644 --- a/packages/adapter-sveltekit/src/hooks/snippet-read.ts +++ b/packages/adapter-sveltekit/src/hooks/snippet-read.ts @@ -57,19 +57,38 @@ export const snippetRead: SnippetReadHook = async ( } case "Link": { + const repeat = data.model.config?.repeat ?? false; + const allowText = data.model.config?.allowText ?? false; + + let codeText; + if (!repeat && !allowText) { + codeText = stripIndent` + Link + `; + } else if (!repeat && allowText) { + codeText = stripIndent` + + `; + } else if (repeat && !allowText) { + codeText = stripIndent` + {#each ${dotPath(fieldPath)} as link, index (index)} + Link + {/each} + `; + } else if (repeat && allowText) { + codeText = stripIndent` + {#each ${dotPath(fieldPath)} as link, index (index)} + + {/each} + `; + } else { + throw new Error("Invalid configuration."); + } + return { label, language: "svelte", - code: await format( - data.model.config?.allowText - ? stripIndent` - - ` - : stripIndent` - Link - `, - helpers, - ), + code: await format(codeText, helpers), }; } diff --git a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx index bb694ee36..73c0890d8 100644 --- a/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +++ b/packages/slice-machine/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx @@ -24,6 +24,7 @@ const Hint: React.FC = ({ if (item.value.type === "Link") { if (item.value.config?.allowText ?? false) snippetCacheKey.push("allowText"); + if (item.value.config?.repeat ?? false) snippetCacheKey.push("repeat"); } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment