@slicemachine/adapter-sveltekit 0.3.78-beta.8 → 0.3.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/AlternateGrid/javascript.4.svelte +227 -0
  2. package/dist/AlternateGrid/javascript.svelte +6 -5
  3. package/dist/AlternateGrid/typescript.4.svelte +224 -0
  4. package/dist/AlternateGrid/typescript.svelte +9 -4
  5. package/dist/CallToAction/javascript.4.svelte +127 -0
  6. package/dist/CallToAction/javascript.svelte +6 -5
  7. package/dist/CallToAction/typescript.4.svelte +124 -0
  8. package/dist/CallToAction/typescript.svelte +4 -2
  9. package/dist/CustomerLogos/javascript.4.svelte +124 -0
  10. package/dist/CustomerLogos/javascript.svelte +6 -5
  11. package/dist/CustomerLogos/typescript.4.svelte +121 -0
  12. package/dist/CustomerLogos/typescript.svelte +4 -2
  13. package/dist/Hero/javascript.4.svelte +190 -0
  14. package/dist/Hero/javascript.svelte +5 -4
  15. package/dist/Hero/typescript.4.svelte +187 -0
  16. package/dist/Hero/typescript.svelte +4 -2
  17. package/dist/hooks/documentation-read.cjs +14 -51
  18. package/dist/hooks/documentation-read.cjs.map +1 -1
  19. package/dist/hooks/documentation-read.js +14 -51
  20. package/dist/hooks/documentation-read.js.map +1 -1
  21. package/dist/hooks/documentation-read.templates.cjs +114 -0
  22. package/dist/hooks/documentation-read.templates.cjs.map +1 -0
  23. package/dist/hooks/documentation-read.templates.d.ts +9 -0
  24. package/dist/hooks/documentation-read.templates.js +114 -0
  25. package/dist/hooks/documentation-read.templates.js.map +1 -0
  26. package/dist/hooks/project-init.cjs +44 -143
  27. package/dist/hooks/project-init.cjs.map +1 -1
  28. package/dist/hooks/project-init.js +44 -143
  29. package/dist/hooks/project-init.js.map +1 -1
  30. package/dist/hooks/project-init.templates.cjs +181 -0
  31. package/dist/hooks/project-init.templates.cjs.map +1 -0
  32. package/dist/hooks/project-init.templates.d.ts +12 -0
  33. package/dist/hooks/project-init.templates.js +181 -0
  34. package/dist/hooks/project-init.templates.js.map +1 -0
  35. package/dist/hooks/slice-create.cjs +5 -52
  36. package/dist/hooks/slice-create.cjs.map +1 -1
  37. package/dist/hooks/slice-create.js +5 -52
  38. package/dist/hooks/slice-create.js.map +1 -1
  39. package/dist/hooks/slice-create.templates.cjs +61 -0
  40. package/dist/hooks/slice-create.templates.cjs.map +1 -0
  41. package/dist/hooks/slice-create.templates.d.ts +6 -0
  42. package/dist/hooks/slice-create.templates.js +61 -0
  43. package/dist/hooks/slice-create.templates.js.map +1 -0
  44. package/dist/hooks/snippet-read.cjs.map +1 -1
  45. package/dist/hooks/snippet-read.js.map +1 -1
  46. package/dist/lib/getSvelteMajor.cjs +38 -0
  47. package/dist/lib/getSvelteMajor.cjs.map +1 -0
  48. package/dist/lib/getSvelteMajor.d.ts +1 -0
  49. package/dist/lib/getSvelteMajor.js +16 -0
  50. package/dist/lib/getSvelteMajor.js.map +1 -0
  51. package/dist/lib/requireResolve.cjs +16 -0
  52. package/dist/lib/requireResolve.cjs.map +1 -0
  53. package/dist/lib/requireResolve.d.ts +10 -0
  54. package/dist/lib/requireResolve.js +16 -0
  55. package/dist/lib/requireResolve.js.map +1 -0
  56. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  57. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  58. package/dist/plugin.cjs +6 -3
  59. package/dist/plugin.cjs.map +1 -1
  60. package/dist/plugin.js +4 -2
  61. package/dist/plugin.js.map +1 -1
  62. package/dist/simulator/SliceSimulator.svelte +3 -2
  63. package/dist/simulator/SliceSimulator.svelte.d.ts +7 -19
  64. package/package.json +9 -9
  65. package/src/hooks/documentation-read.templates.ts +170 -0
  66. package/src/hooks/documentation-read.ts +21 -59
  67. package/src/hooks/project-init.templates.ts +208 -0
  68. package/src/hooks/project-init.ts +57 -147
  69. package/src/hooks/slice-create.templates.ts +103 -0
  70. package/src/hooks/slice-create.ts +7 -66
  71. package/src/lib/getSvelteMajor.ts +23 -0
  72. package/src/lib/requireResolve.ts +30 -0
  73. package/src/plugin.ts +5 -2
  74. package/src/simulator/SliceSimulator.svelte +3 -2
@@ -9,14 +9,21 @@ import {
9
9
  writeProjectFile,
10
10
  } from "@slicemachine/plugin-kit/fs";
11
11
  import { source } from "common-tags";
12
+ import { loadFile } from "magicast";
12
13
 
13
14
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
14
15
  import { getJSFileExtension } from "../lib/getJSFileExtension";
16
+ import { getSvelteMajor } from "../lib/getSvelteMajor";
15
17
  import { rejectIfNecessary } from "../lib/rejectIfNecessary";
16
18
  import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
17
19
 
18
20
  import type { PluginOptions } from "../types";
19
- import { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from "../constants";
21
+ import {
22
+ previewAPIRouteTemplate,
23
+ prismicIOFileTemplate,
24
+ rootLayoutTemplate,
25
+ sliceSimulatorPageTemplate,
26
+ } from "./project-init.templates";
20
27
 
21
28
  type InstallDependenciesArgs = {
22
29
  installDependencies: ProjectInitHookData["installDependencies"];
@@ -39,10 +46,6 @@ const createPrismicIOFile = async ({
39
46
  helpers,
40
47
  options,
41
48
  }: CreatePrismicIOFileArgs) => {
42
- const isTypeScriptProject = await checkIsTypeScriptProject({
43
- helpers,
44
- options,
45
- });
46
49
  const extension = await getJSFileExtension({ helpers, options });
47
50
  const filename = path.join(`src/lib/prismicio.${extension}`);
48
51
 
@@ -50,105 +53,8 @@ const createPrismicIOFile = async ({
50
53
  return;
51
54
  }
52
55
 
53
- let contents: string;
54
-
55
- if (isTypeScriptProject) {
56
- contents = source`
57
- import * as prismic from "@prismicio/client";
58
- import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
59
- import config from "../../slicemachine.config.json";
60
-
61
- /**
62
- * The project's Prismic repository name.
63
- */
64
- export const repositoryName =
65
- import${"."}meta${"."}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;
66
-
67
- /**
68
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
69
- *
70
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
71
- */
72
- // TODO: Update the routes array to match your project's route structure.
73
- const routes: prismic.ClientConfig["routes"] = [
74
- // Examples:
75
- // {
76
- // type: "homepage",
77
- // path: "/",
78
- // },
79
- // {
80
- // type: "page",
81
- // path: "/:uid",
82
- // },
83
- ];
84
-
85
- /**
86
- * Creates a Prismic client for the project's repository. The client is used to
87
- * query content from the Prismic API.
88
- *
89
- * @param config - Configuration for the Prismic client.
90
- */
91
- export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
92
- const client = prismic.createClient(repositoryName, {
93
- routes,
94
- ...config,
95
- });
96
-
97
- enableAutoPreviews({ client, cookies });
98
-
99
- return client;
100
- };
101
- `;
102
- } else {
103
- contents = source`
104
- import * as prismic from "@prismicio/client";
105
- import { enableAutoPreviews } from '@prismicio/svelte/kit';
106
- import config from "../../slicemachine.config.json";
107
-
108
- /**
109
- * The project's Prismic repository name.
110
- */
111
- export const repositoryName =
112
- import${"."}meta${"."}env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;
113
-
114
- /**
115
- * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
116
- *
117
- * {@link https://prismic.io/docs/route-resolver#route-resolver}
118
- *
119
- * @type {prismic.ClientConfig["routes"]}
120
- */
121
- // TODO: Update the routes array to match your project's route structure.
122
- const routes = [
123
- // Examples:
124
- // {
125
- // type: "homepage",
126
- // path: "/",
127
- // },
128
- // {
129
- // type: "page",
130
- // path: "/:uid",
131
- // },
132
- ];
133
-
134
- /**
135
- * Creates a Prismic client for the project's repository. The client is used to
136
- * query content from the Prismic API.
137
- *
138
- * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
139
- */
140
- export const createClient = ({ cookies, ...config } = {}) => {
141
- const client = prismic.createClient(repositoryName, {
142
- routes,
143
- ...config,
144
- });
145
-
146
- enableAutoPreviews({ client, cookies });
147
-
148
- return client;
149
- };
150
- `;
151
- }
56
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
57
+ const contents = prismicIOFileTemplate({ typescript });
152
58
 
153
59
  await writeProjectFile({
154
60
  filename,
@@ -173,17 +79,9 @@ const createSliceSimulatorPage = async ({
173
79
  return;
174
80
  }
175
81
 
176
- const contents = source`
177
- <script>
178
- import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';
179
- import { SliceZone } from '@prismicio/svelte';
180
- import { components } from '$lib/slices';
181
- </script>
182
-
183
- <SliceSimulator let:slices>
184
- <SliceZone {slices} {components} />
185
- </SliceSimulator>
186
- `;
82
+ const contents = sliceSimulatorPageTemplate({
83
+ version: await getSvelteMajor(),
84
+ });
187
85
 
188
86
  await writeProjectFile({
189
87
  filename,
@@ -241,16 +139,8 @@ const createPreviewAPIRoute = async ({
241
139
  return;
242
140
  }
243
141
 
244
- const contents = source`
245
- import { redirectToPreviewURL } from '@prismicio/svelte/kit';
246
- import { createClient } from '$lib/prismicio';
247
-
248
- export async function GET({ fetch, request, cookies }) {
249
- const client = createClient({ fetch });
250
-
251
- return await redirectToPreviewURL({ client, request, cookies });
252
- }
253
- `;
142
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
143
+ const contents = previewAPIRouteTemplate({ typescript });
254
144
 
255
145
  await writeProjectFile({
256
146
  filename,
@@ -327,28 +217,7 @@ const createRootLayoutFile = async ({
327
217
  return;
328
218
  }
329
219
 
330
- const contents = source`
331
- <script>
332
- import { isFilled, asImageSrc } from '@prismicio/client';
333
- import { PrismicPreview } from '@prismicio/svelte/kit';
334
- import { page } from '$app/state';
335
- import { repositoryName } from '$lib/prismicio';
336
- </script>
337
-
338
- <svelte:head>
339
- <title>{page.data.page?.data.meta_title}</title>
340
- <meta property="og:title" content={page.data.page?.data.meta_title} />
341
- {#if isFilled.keyText(page.data.page?.data.meta_description)}
342
- <meta name="description" content={page.data.page.data.meta_description} />
343
- <meta property="og:description" content={page.data.page.data.meta_description} />
344
- {/if}
345
- {#if isFilled.image(page.data.page?.data.meta_image)}
346
- <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
347
- {/if}
348
- </svelte:head>
349
- <slot />
350
- <PrismicPreview {repositoryName} />
351
- `;
220
+ const contents = rootLayoutTemplate({ version: await getSvelteMajor() });
352
221
 
353
222
  await writeProjectFile({
354
223
  filename,
@@ -421,6 +290,46 @@ const upsertSliceLibraryIndexFiles = async (
421
290
  );
422
291
  };
423
292
 
293
+ const modifyViteConfig = async ({
294
+ helpers,
295
+ options,
296
+ }: SliceMachineContext<PluginOptions>) => {
297
+ let filename = "vite.config.js";
298
+ if (!(await checkHasProjectFile({ filename, helpers }))) {
299
+ filename = "vite.config.ts";
300
+ }
301
+ if (!(await checkHasProjectFile({ filename, helpers }))) {
302
+ // Couldn't find the config file.
303
+ return;
304
+ }
305
+ const filepath = helpers.joinPathFromRoot(filename);
306
+
307
+ const mod = await loadFile(filepath);
308
+ if (mod.exports.default.$type !== "function-call") {
309
+ // Invalid config file.
310
+ return;
311
+ }
312
+
313
+ // Add `./slicemachine.config.json` to allowed files.
314
+ const config = mod.exports.default.$args[0];
315
+ config.server ??= {};
316
+ config.server.fs ??= {};
317
+ config.server.fs.allow ??= [];
318
+ if (!config.server.fs.allow.includes("./slicemachine.config.json")) {
319
+ config.server.fs.allow.push("./slicemachine.config.json");
320
+ }
321
+
322
+ // Remove an empty line above the `server` property.
323
+ const contents = mod.generate().code.replace(/\n\s*\n(?=\s*server:)/, "\n");
324
+
325
+ await writeProjectFile({
326
+ filename,
327
+ contents,
328
+ format: options.format,
329
+ helpers,
330
+ });
331
+ };
332
+
424
333
  export const projectInit: ProjectInitHook<PluginOptions> = async (
425
334
  { installDependencies: _installDependencies },
426
335
  context,
@@ -436,6 +345,7 @@ export const projectInit: ProjectInitHook<PluginOptions> = async (
436
345
  createPreviewRouteMatcherFile(context),
437
346
  createRootLayoutServerFile(context),
438
347
  createRootLayoutFile(context),
348
+ modifyViteConfig(context),
439
349
  ]),
440
350
  );
441
351
 
@@ -0,0 +1,103 @@
1
+ import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+ import { source as svelte } from "common-tags";
3
+
4
+ import { pascalCase } from "../lib/pascalCase";
5
+
6
+ const PLACEHOLDER = `
7
+ Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
8
+ <br />
9
+ <strong>You can edit this slice directly in your code editor.</strong>
10
+ <!--
11
+ 💡 Use Prismic MCP with your code editor
12
+
13
+ Get AI-powered help to build your slice components — based on your actual model.
14
+
15
+ ▶️ Setup:
16
+ 1. Add a new MCP Server in your code editor:
17
+
18
+ {
19
+ "mcpServers": {
20
+ "Prismic MCP": {
21
+ "command": "npx",
22
+ "args": ["-y", "@prismicio/mcp-server"]
23
+ }
24
+ }
25
+ }
26
+
27
+ 2. Select a model optimized for coding (e.g. Claude 3.7 Sonnet or similar)
28
+
29
+ ✅ Then open your slice file and ask your code editor:
30
+ "Code this slice"
31
+
32
+ Your code editor reads your slice model and helps you code faster ⚡
33
+ 📚 Give your feedback: https://community.prismic.io/t/help-us-shape-the-future-of-slice-creation/19505
34
+ -->
35
+ `;
36
+
37
+ export function sliceTemplate(args: {
38
+ model: SharedSlice;
39
+ typescript: boolean;
40
+ version: number;
41
+ }): string {
42
+ const { model, typescript, version } = args;
43
+
44
+ const pascalName = pascalCase(model.name);
45
+
46
+ const v5TS = svelte`
47
+ <script lang="ts">
48
+ import type { Content } from '@prismicio/client';
49
+ import type { SliceComponentProps } from '@prismicio/svelte';
50
+
51
+ type Props = SliceComponentProps<Content.${pascalName}Slice>;
52
+
53
+ const { slice }: Props = $props();
54
+ </script>
55
+
56
+ <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
57
+ ${PLACEHOLDER}
58
+ </section>
59
+ `;
60
+
61
+ const v5JS = svelte`
62
+ <script>
63
+ /* @typedef {import("@prismicio/client").Content} Content */
64
+ /* @typedef {import("@prismicio/svelte").SliceComponentProps} SliceComponentProps */
65
+
66
+ /* @type {SliceComponentProps<Content.${pascalName}Slice>} */
67
+ const { slice } = $props();
68
+ </script>
69
+
70
+ <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
71
+ ${PLACEHOLDER}
72
+ </section>
73
+ `;
74
+
75
+ const v4TS = svelte`
76
+ <script lang="ts">
77
+ import type { Content } from '@prismicio/client';
78
+
79
+ export let slice: Content.${pascalName}Slice;
80
+ </script>
81
+
82
+ <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
83
+ ${PLACEHOLDER}
84
+ </section>
85
+ `;
86
+
87
+ const v4JS = svelte`
88
+ <script>
89
+ /** @type {import("@prismicio/client").Content.${pascalName}Slice} */
90
+ export let slice;
91
+ </script>
92
+
93
+ <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
94
+ ${PLACEHOLDER}
95
+ </section>
96
+ `;
97
+
98
+ if (typescript) {
99
+ return version <= 4 ? v4TS : v5TS;
100
+ }
101
+
102
+ return version <= 4 ? v4JS : v5JS;
103
+ }
@@ -8,14 +8,14 @@ import {
8
8
  writeSliceFile,
9
9
  writeSliceModel,
10
10
  } from "@slicemachine/plugin-kit/fs";
11
- import { source } from "common-tags";
12
11
 
13
12
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
14
- import { pascalCase } from "../lib/pascalCase";
13
+ import { getSvelteMajor } from "../lib/getSvelteMajor";
15
14
  import { rejectIfNecessary } from "../lib/rejectIfNecessary";
16
15
  import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
17
16
 
18
17
  import type { PluginOptions } from "../types";
18
+ import { sliceTemplate } from "./slice-create.templates";
19
19
 
20
20
  type Args = {
21
21
  data: SliceCreateHookData;
@@ -27,71 +27,12 @@ const createComponentFile = async ({
27
27
  actions,
28
28
  options,
29
29
  }: Args) => {
30
- const pascalName = pascalCase(data.model.name);
30
+ const { model, componentContents } = data;
31
31
 
32
- let contents: string;
33
-
34
- const isTypeScriptProject = await checkIsTypeScriptProject({
35
- helpers,
36
- options,
37
- });
38
-
39
- const placeholder = `
40
- Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
41
- <br />
42
- <strong>You can edit this slice directly in your code editor.</strong>
43
- <!--
44
- 💡 Use Prismic MCP with your code editor
45
-
46
- Get AI-powered help to build your slice components — based on your actual model.
47
-
48
- ▶️ Setup:
49
- 1. Add a new MCP Server in your code editor:
50
-
51
- {
52
- "mcpServers": {
53
- "Prismic MCP": {
54
- "command": "npx",
55
- "args": ["-y", "@prismicio/mcp-server"]
56
- }
57
- }
58
- }
59
-
60
- 2. Select a model optimized for coding (e.g. Claude 3.7 Sonnet or similar)
61
-
62
- ✅ Then open your slice file and ask your code editor:
63
- "Code this slice"
64
-
65
- Your code editor reads your slice model and helps you code faster ⚡
66
- 📚 Give your feedback: https://community.prismic.io/t/help-us-shape-the-future-of-slice-creation/19505
67
- -->`;
68
-
69
- if (data.componentContents) {
70
- contents = data.componentContents;
71
- } else if (isTypeScriptProject) {
72
- contents = source`
73
- <script lang="ts">
74
- import type { Content } from '@prismicio/client';
75
-
76
- export let slice: Content.${pascalName}Slice;
77
- </script>
78
-
79
- <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
80
- ${placeholder}
81
- </section>
82
- `;
83
- } else {
84
- contents = source`
85
- <script>
86
- /** @type {import("@prismicio/client").Content.${pascalName}Slice} */
87
- export let slice;
88
- </script>
89
-
90
- <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
91
- ${placeholder}
92
- </section>
93
- `;
94
- }
32
+ const typescript = await checkIsTypeScriptProject({ helpers, options });
33
+ const contents =
34
+ componentContents ??
35
+ sliceTemplate({ model, typescript, version: await getSvelteMajor() });
95
36
 
96
37
  await writeSliceFile({
97
38
  libraryID: data.libraryID,
@@ -0,0 +1,23 @@
1
+ import { join } from "node:path";
2
+
3
+ import { requireResolve } from "./requireResolve";
4
+
5
+ export const getSvelteMajor = async (): Promise<number> => {
6
+ // A dynamic import lets us easily mock the module.
7
+ const { readFile } = await import("node:fs/promises");
8
+
9
+ const packageJSONPath = requireResolve(
10
+ "svelte/package.json",
11
+ join(process.cwd(), "package.json"),
12
+ );
13
+ const { version } = JSON.parse(await readFile(packageJSONPath, "utf8"));
14
+
15
+ const major = Number.parseInt(version.split(".")[0]);
16
+ if (major === Number.NaN) {
17
+ throw new Error(
18
+ `Unable to parse svelte's installed version number: "${version}"`,
19
+ );
20
+ }
21
+
22
+ return major;
23
+ };
@@ -0,0 +1,30 @@
1
+ import _module, { createRequire } from "node:module";
2
+
3
+ /**
4
+ * Resolves a module path with `createRequire().resolve()` with Yarn PnP
5
+ * support.
6
+ *
7
+ * @param id - Module to resolve.
8
+ * @param from - Location to resolve the module from.
9
+ *
10
+ * @returns - Resolved module path.
11
+ */
12
+ export const requireResolve = (id: string, from: string): string => {
13
+ let resolvedID = id;
14
+
15
+ // Support Yarn PnP
16
+ if (
17
+ process.versions.pnp &&
18
+ "findPnpApi" in _module &&
19
+ typeof _module.findPnpApi === "function"
20
+ ) {
21
+ const pnpApi = _module.findPnpApi(from);
22
+ if (pnpApi) {
23
+ resolvedID = pnpApi.resolveRequest(id, from);
24
+ }
25
+ }
26
+
27
+ const require = createRequire(from);
28
+
29
+ return require.resolve(resolvedID);
30
+ };
package/src/plugin.ts CHANGED
@@ -44,6 +44,7 @@ import * as Hero from "./sliceTemplates/Hero";
44
44
  import * as CallToAction from "./sliceTemplates/CallToAction";
45
45
  import * as AlternateGrid from "./sliceTemplates/AlternateGrid";
46
46
  import * as CustomerLogos from "./sliceTemplates/CustomerLogos";
47
+ import { getSvelteMajor } from "./lib/getSvelteMajor";
47
48
 
48
49
  export const plugin = defineSliceMachinePlugin<PluginOptions>({
49
50
  meta: {
@@ -200,14 +201,16 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
200
201
  ////////////////////////////////////////////////////////////////
201
202
 
202
203
  hook("slice-template-library:read", async (data, context) => {
204
+ const version = await getSvelteMajor();
205
+
203
206
  return await readSliceTemplateLibrary({
204
207
  ...data,
205
208
  ...context,
206
209
  dirName: path.dirname(fileURLToPath(new URL(import.meta.url))),
207
210
  templates: [Hero, CustomerLogos, AlternateGrid, CallToAction],
208
211
  componentFileNames: {
209
- js: "javascript.svelte",
210
- ts: "typescript.svelte",
212
+ js: version <= 4 ? "javascript.4.svelte" : "javascript.svelte",
213
+ ts: version <= 4 ? "typescript.4.svelte" : "typescript.svelte",
211
214
  },
212
215
  });
213
216
  });
@@ -1,4 +1,4 @@
1
- <script>
1
+ <script lang="ts">
2
2
  import {
3
3
  SimulatorManager,
4
4
  StateEventType,
@@ -10,13 +10,14 @@
10
10
  simulatorClass,
11
11
  simulatorRootClass,
12
12
  } from "@prismicio/simulator/kit";
13
+ import { type SliceZone } from "@prismicio/client";
13
14
 
14
15
  const defaultProps = getDefaultProps();
15
16
 
16
17
  export let zIndex = defaultProps.zIndex;
17
18
  export let background = defaultProps.background;
18
19
 
19
- let slices = getDefaultSlices();
20
+ let slices: SliceZone = getDefaultSlices();
20
21
  let message = getDefaultMessage();
21
22
 
22
23
  if (typeof window !== "undefined") {