prismic 0.0.0-pr.28.59bf330

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 (158) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +69 -0
  3. package/dist/builders-hKD4IrLX-DsO7BUQw.mjs +97 -0
  4. package/dist/dist-B11B2hHn.mjs +1 -0
  5. package/dist/dist-DT8CtumB.mjs +1 -0
  6. package/dist/framework-CfjEoVk0.mjs +17 -0
  7. package/dist/index.mjs +2537 -0
  8. package/dist/nextjs-9z7YrSnS.mjs +312 -0
  9. package/dist/nuxt-KoJ61G2q.mjs +59 -0
  10. package/dist/sveltekit-DjXKCG78.mjs +226 -0
  11. package/package.json +58 -0
  12. package/src/codegen-types.ts +82 -0
  13. package/src/codegen.ts +45 -0
  14. package/src/custom-type-add-field-boolean.ts +185 -0
  15. package/src/custom-type-add-field-color.ts +168 -0
  16. package/src/custom-type-add-field-date.ts +171 -0
  17. package/src/custom-type-add-field-embed.ts +168 -0
  18. package/src/custom-type-add-field-geo-point.ts +165 -0
  19. package/src/custom-type-add-field-group.ts +142 -0
  20. package/src/custom-type-add-field-image.ts +168 -0
  21. package/src/custom-type-add-field-key-text.ts +168 -0
  22. package/src/custom-type-add-field-link.ts +191 -0
  23. package/src/custom-type-add-field-number.ts +200 -0
  24. package/src/custom-type-add-field-rich-text.ts +192 -0
  25. package/src/custom-type-add-field-select.ts +174 -0
  26. package/src/custom-type-add-field-timestamp.ts +171 -0
  27. package/src/custom-type-add-field-uid.ts +151 -0
  28. package/src/custom-type-add-field.ts +116 -0
  29. package/src/custom-type-connect-slice.ts +178 -0
  30. package/src/custom-type-create.ts +98 -0
  31. package/src/custom-type-disconnect-slice.ts +134 -0
  32. package/src/custom-type-list.ts +110 -0
  33. package/src/custom-type-remove-field.ts +135 -0
  34. package/src/custom-type-remove.ts +103 -0
  35. package/src/custom-type-set-name.ts +102 -0
  36. package/src/custom-type-view.ts +118 -0
  37. package/src/custom-type.ts +85 -0
  38. package/src/docs-fetch.ts +146 -0
  39. package/src/docs-list.ts +131 -0
  40. package/src/docs.ts +54 -0
  41. package/src/env.d.ts +12 -0
  42. package/src/framework/index.ts +399 -0
  43. package/src/framework/nextjs.templates.ts +426 -0
  44. package/src/framework/nextjs.ts +216 -0
  45. package/src/framework/nuxt.templates.ts +74 -0
  46. package/src/framework/nuxt.ts +250 -0
  47. package/src/framework/sveltekit.templates.ts +278 -0
  48. package/src/framework/sveltekit.ts +241 -0
  49. package/src/index.ts +155 -0
  50. package/src/init.ts +173 -0
  51. package/src/lib/auth.ts +200 -0
  52. package/src/lib/browser.ts +11 -0
  53. package/src/lib/config.ts +111 -0
  54. package/src/lib/custom-types-api.ts +385 -0
  55. package/src/lib/field-path.ts +81 -0
  56. package/src/lib/file.ts +49 -0
  57. package/src/lib/json.ts +3 -0
  58. package/src/lib/packageJson.ts +35 -0
  59. package/src/lib/profile.ts +39 -0
  60. package/src/lib/request.ts +116 -0
  61. package/src/lib/segment.ts +145 -0
  62. package/src/lib/sentry.ts +63 -0
  63. package/src/lib/string.ts +10 -0
  64. package/src/lib/url.ts +31 -0
  65. package/src/locale-add.ts +116 -0
  66. package/src/locale-list.ts +107 -0
  67. package/src/locale-remove.ts +88 -0
  68. package/src/locale-set-default.ts +131 -0
  69. package/src/locale.ts +60 -0
  70. package/src/login.ts +45 -0
  71. package/src/logout.ts +36 -0
  72. package/src/page-type-add-field-boolean.ts +179 -0
  73. package/src/page-type-add-field-color.ts +165 -0
  74. package/src/page-type-add-field-date.ts +168 -0
  75. package/src/page-type-add-field-embed.ts +165 -0
  76. package/src/page-type-add-field-geo-point.ts +162 -0
  77. package/src/page-type-add-field-group.ts +139 -0
  78. package/src/page-type-add-field-image.ts +165 -0
  79. package/src/page-type-add-field-key-text.ts +165 -0
  80. package/src/page-type-add-field-link.ts +188 -0
  81. package/src/page-type-add-field-number.ts +197 -0
  82. package/src/page-type-add-field-rich-text.ts +189 -0
  83. package/src/page-type-add-field-select.ts +171 -0
  84. package/src/page-type-add-field-timestamp.ts +168 -0
  85. package/src/page-type-add-field-uid.ts +148 -0
  86. package/src/page-type-add-field.ts +116 -0
  87. package/src/page-type-connect-slice.ts +178 -0
  88. package/src/page-type-create.ts +128 -0
  89. package/src/page-type-disconnect-slice.ts +134 -0
  90. package/src/page-type-list.ts +109 -0
  91. package/src/page-type-remove-field.ts +135 -0
  92. package/src/page-type-remove.ts +103 -0
  93. package/src/page-type-set-name.ts +102 -0
  94. package/src/page-type-set-repeatable.ts +111 -0
  95. package/src/page-type-view.ts +118 -0
  96. package/src/page-type.ts +90 -0
  97. package/src/preview-add.ts +126 -0
  98. package/src/preview-get-simulator.ts +104 -0
  99. package/src/preview-list.ts +106 -0
  100. package/src/preview-remove-simulator.ts +80 -0
  101. package/src/preview-remove.ts +109 -0
  102. package/src/preview-set-name.ts +137 -0
  103. package/src/preview-set-simulator.ts +116 -0
  104. package/src/preview.ts +75 -0
  105. package/src/pull.ts +236 -0
  106. package/src/push.ts +409 -0
  107. package/src/repo-create.ts +175 -0
  108. package/src/repo-get-access.ts +86 -0
  109. package/src/repo-list.ts +100 -0
  110. package/src/repo-set-access.ts +100 -0
  111. package/src/repo-set-name.ts +102 -0
  112. package/src/repo-view.ts +113 -0
  113. package/src/repo.ts +70 -0
  114. package/src/slice-add-field-boolean.ts +219 -0
  115. package/src/slice-add-field-color.ts +205 -0
  116. package/src/slice-add-field-date.ts +205 -0
  117. package/src/slice-add-field-embed.ts +205 -0
  118. package/src/slice-add-field-geo-point.ts +202 -0
  119. package/src/slice-add-field-group.ts +170 -0
  120. package/src/slice-add-field-image.ts +202 -0
  121. package/src/slice-add-field-key-text.ts +205 -0
  122. package/src/slice-add-field-link.ts +224 -0
  123. package/src/slice-add-field-number.ts +205 -0
  124. package/src/slice-add-field-rich-text.ts +229 -0
  125. package/src/slice-add-field-select.ts +211 -0
  126. package/src/slice-add-field-timestamp.ts +205 -0
  127. package/src/slice-add-field.ts +111 -0
  128. package/src/slice-add-variation.ts +142 -0
  129. package/src/slice-create.ts +164 -0
  130. package/src/slice-list-variations.ts +71 -0
  131. package/src/slice-list.ts +60 -0
  132. package/src/slice-remove-field.ts +125 -0
  133. package/src/slice-remove-variation.ts +113 -0
  134. package/src/slice-remove.ts +92 -0
  135. package/src/slice-rename.ts +104 -0
  136. package/src/slice-set-screenshot.ts +239 -0
  137. package/src/slice-view.ts +83 -0
  138. package/src/slice.ts +95 -0
  139. package/src/status.ts +834 -0
  140. package/src/sync.ts +259 -0
  141. package/src/token-create.ts +203 -0
  142. package/src/token-delete.ts +182 -0
  143. package/src/token-list.ts +223 -0
  144. package/src/token-set-name.ts +193 -0
  145. package/src/token.ts +60 -0
  146. package/src/webhook-add-header.ts +118 -0
  147. package/src/webhook-create.ts +152 -0
  148. package/src/webhook-disable.ts +109 -0
  149. package/src/webhook-enable.ts +132 -0
  150. package/src/webhook-list.ts +93 -0
  151. package/src/webhook-remove-header.ts +117 -0
  152. package/src/webhook-remove.ts +106 -0
  153. package/src/webhook-set-triggers.ts +148 -0
  154. package/src/webhook-status.ts +90 -0
  155. package/src/webhook-test.ts +106 -0
  156. package/src/webhook-view.ts +147 -0
  157. package/src/webhook.ts +95 -0
  158. package/src/whoami.ts +62 -0
@@ -0,0 +1,250 @@
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { builders, loadFile, writeFile as magicastWriteFile } from "magicast";
4
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
+ import { relative } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ import type { Framework } from ".";
9
+
10
+ import { FrameworkAdapter } from ".";
11
+ import { readConfig, updateConfig } from "../lib/config";
12
+ import { exists } from "../lib/file";
13
+ import { sliceSimulatorPageTemplate, sliceTemplate } from "./nuxt.templates";
14
+ import { getNpmPackageVersion } from "../lib/packageJson";
15
+ import { dedent } from "../lib/string";
16
+
17
+ const NUXT_PRISMIC = "@nuxtjs/prismic";
18
+
19
+ export class NuxtFramework extends FrameworkAdapter {
20
+ readonly id: Framework = "nuxt";
21
+
22
+ async getDependencies(): Promise<Record<string, string>> {
23
+ return {
24
+ "@prismicio/client": `^${await getNpmPackageVersion("@prismicio/client")}`,
25
+ [NUXT_PRISMIC]: `^${await getNpmPackageVersion(NUXT_PRISMIC)}`,
26
+ };
27
+ }
28
+
29
+ async initProject(): Promise<void> {
30
+ await super.initProject();
31
+
32
+ await this.#configureNuxtModule();
33
+ await this.#createSliceSimulatorPage();
34
+ await this.#moveOrDeleteAppVue();
35
+ await this.#modifySliceLibraryPath();
36
+ }
37
+
38
+ async createSliceComponent(
39
+ model: SharedSlice,
40
+ sliceDirectory: URL,
41
+ ): Promise<{ componentPath: URL }> {
42
+ const componentPath = new URL("index.vue", sliceDirectory);
43
+ const contents = sliceTemplate({
44
+ name: model.name,
45
+ typescript: await this.checkIsTypeScriptProject(),
46
+ });
47
+ await writeFile(componentPath, contents);
48
+ return { componentPath };
49
+ }
50
+
51
+ getSliceImportPath(relativeDirectory: string): string {
52
+ return `./${relativeDirectory}/index.vue`;
53
+ }
54
+
55
+ async getDefaultSliceLibraryPath(_projectRoot: URL): Promise<URL> {
56
+ const srcDir = await this.#getSrcDir();
57
+ return new URL("slices/", srcDir);
58
+ }
59
+
60
+ async getClientFilePath(): Promise<string | null> {
61
+ return null;
62
+ }
63
+
64
+ async getSlicesDirectoryPath(): Promise<string> {
65
+ const projectRoot = await this.getProjectRoot();
66
+ const appDir = new URL("app/", projectRoot);
67
+ if (await exists(appDir)) return "app/slices/";
68
+ const srcDir = new URL("src/", projectRoot);
69
+ if (await exists(srcDir)) return "src/slices/";
70
+ return "slices/";
71
+ }
72
+
73
+ getSliceComponentExtensions(): string[] {
74
+ return [".vue"];
75
+ }
76
+
77
+ async getRoutePath(route: string): Promise<{ path: string; extensions: string[] } | null> {
78
+ if (route === "/slice-simulator") {
79
+ return { path: "pages/slice-simulator", extensions: [".vue"] };
80
+ }
81
+ return null;
82
+ }
83
+
84
+ protected override async generateSliceLibraryIndexContents(
85
+ slices: { library: URL; directory: URL; model: SharedSlice }[],
86
+ ): Promise<string> {
87
+ const componentLines = await Promise.all(
88
+ slices.map(async (slice) => {
89
+ const relativeDirectory = relative(
90
+ fileURLToPath(slice.library),
91
+ fileURLToPath(slice.directory),
92
+ );
93
+ return `${slice.model.id}: defineAsyncComponent(() => import("./${relativeDirectory}/index.vue"))`;
94
+ }),
95
+ );
96
+
97
+ return dedent`
98
+ // Code generated by Prismic. DO NOT EDIT.
99
+
100
+ import { defineAsyncComponent } from "vue";
101
+ import { defineSliceZoneComponents } from "@prismicio/vue";
102
+
103
+ export const components = defineSliceZoneComponents({
104
+ ${componentLines.join(",\n")}
105
+ });
106
+ `;
107
+ }
108
+
109
+ async #getSrcDir(): Promise<URL> {
110
+ const projectRoot = await this.getProjectRoot();
111
+ const appDir = new URL("app/", projectRoot);
112
+ if (await exists(appDir)) return appDir;
113
+ const srcDir = new URL("src/", projectRoot);
114
+ if (await exists(srcDir)) return srcDir;
115
+ return projectRoot;
116
+ }
117
+
118
+ async #configureNuxtModule(): Promise<void> {
119
+ const projectRoot = await this.getProjectRoot();
120
+
121
+ let configUrl = new URL("nuxt.config.js", projectRoot);
122
+ if (!(await exists(configUrl))) {
123
+ configUrl = new URL("nuxt.config.ts", projectRoot);
124
+ }
125
+ if (!(await exists(configUrl))) {
126
+ return;
127
+ }
128
+
129
+ const filepath = fileURLToPath(configUrl);
130
+ const mod = await loadFile(filepath);
131
+ const config =
132
+ mod.exports.default.$type === "function-call"
133
+ ? mod.exports.default.$args[0]
134
+ : mod.exports.default;
135
+
136
+ // Check if @nuxtjs/prismic is already registered
137
+ let hasInlinedConfiguration = false;
138
+ const hasPrismicModuleRegistered = (config.modules || []).find(
139
+ (registration: string | [string, unknown]) => {
140
+ if (typeof registration === "string") {
141
+ return registration === NUXT_PRISMIC;
142
+ } else if (Array.isArray(registration)) {
143
+ hasInlinedConfiguration = !!registration[1];
144
+ return registration[0] === NUXT_PRISMIC;
145
+ }
146
+ return false;
147
+ },
148
+ );
149
+
150
+ if (!hasPrismicModuleRegistered) {
151
+ config.modules ||= [];
152
+ config.modules.push(NUXT_PRISMIC);
153
+ }
154
+
155
+ // Append Prismic module configuration if not inlined
156
+ if (!hasInlinedConfiguration) {
157
+ mod.imports.$prepend({
158
+ from: "./prismic.config.json",
159
+ imported: "repositoryName",
160
+ });
161
+
162
+ config.prismic ||= {};
163
+ config.prismic.endpoint = builders.raw("repositoryName");
164
+ }
165
+
166
+ await magicastWriteFile(mod, filepath);
167
+ }
168
+
169
+ async #createSliceSimulatorPage(): Promise<void> {
170
+ const projectRoot = await this.getProjectRoot();
171
+ const typescript = await this.checkIsTypeScriptProject();
172
+
173
+ // Check for existing pages directories in priority order
174
+ const appPagesDir = new URL("app/pages/", projectRoot);
175
+ const srcPagesDir = new URL("src/pages/", projectRoot);
176
+ const pagesDir = new URL("pages/", projectRoot);
177
+
178
+ let targetDir: URL;
179
+ if (await exists(appPagesDir)) {
180
+ targetDir = appPagesDir;
181
+ } else if (await exists(srcPagesDir)) {
182
+ targetDir = srcPagesDir;
183
+ } else if (await exists(pagesDir)) {
184
+ targetDir = pagesDir;
185
+ } else {
186
+ targetDir = new URL("pages/", await this.#getSrcDir());
187
+ }
188
+
189
+ const filePath = new URL("slice-simulator.vue", targetDir);
190
+
191
+ if (await exists(filePath)) {
192
+ return;
193
+ }
194
+
195
+ const contents = sliceSimulatorPageTemplate({ typescript });
196
+ await mkdir(targetDir, { recursive: true });
197
+ await writeFile(filePath, contents);
198
+ }
199
+
200
+ async #moveOrDeleteAppVue(): Promise<void> {
201
+ const srcDir = await this.#getSrcDir();
202
+ const appVuePath = new URL("app.vue", srcDir);
203
+
204
+ if (!(await exists(appVuePath))) {
205
+ return;
206
+ }
207
+
208
+ const contents = await readFile(appVuePath, "utf8");
209
+
210
+ if (!contents.includes("<NuxtWelcome")) {
211
+ return;
212
+ }
213
+
214
+ const indexVuePath = new URL("pages/index.vue", srcDir);
215
+
216
+ if (!(await exists(indexVuePath))) {
217
+ await mkdir(new URL(".", indexVuePath), { recursive: true });
218
+ await writeFile(indexVuePath, contents);
219
+ }
220
+
221
+ await rm(appVuePath);
222
+ }
223
+
224
+ async #modifySliceLibraryPath(): Promise<void> {
225
+ const projectRoot = await this.getProjectRoot();
226
+ const hasAppDir = await exists(new URL("app/", projectRoot));
227
+ const hasSrcDir = await exists(new URL("src/", projectRoot));
228
+
229
+ if (!hasAppDir && !hasSrcDir) {
230
+ return;
231
+ }
232
+
233
+ const configResult = await readConfig();
234
+ if (!configResult.ok) return;
235
+
236
+ const libraries = configResult.config.libraries;
237
+ if (!libraries || JSON.stringify(libraries) !== JSON.stringify(["./slices"])) {
238
+ return;
239
+ }
240
+
241
+ // Only modify if the default library has no slices yet
242
+ const slices = await this.getSlices();
243
+ if (slices.length > 0) {
244
+ return;
245
+ }
246
+
247
+ const newLibrary = hasAppDir ? "./app/slices" : "./src/slices";
248
+ await updateConfig({ libraries: [newLibrary] });
249
+ }
250
+ }
@@ -0,0 +1,278 @@
1
+ import { pascalCase } from "change-case";
2
+
3
+ import { dedent } from "../lib/string";
4
+
5
+ export function prismicIOFileTemplate(args: { typescript: boolean }): string {
6
+ const { typescript } = args;
7
+
8
+ if (typescript) {
9
+ return dedent`
10
+ import { createClient as baseCreateClient, type Route } from "@prismicio/client";
11
+ import { type CreateClientConfig, enableAutoPreviews } from '@prismicio/svelte/kit';
12
+ import prismicConfig from "../../prismic.config.json";
13
+
14
+ /**
15
+ * The project's Prismic repository name.
16
+ */
17
+ export const repositoryName = prismicConfig.repositoryName;
18
+
19
+ /**
20
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
21
+ *
22
+ * {@link https://prismic.io/docs/route-resolver}
23
+ *
24
+ * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
25
+ * to edit these to match your site's routing structure.
26
+ */
27
+ // TODO: Update the routes array to match your project's route structure.
28
+ const routes: Route[] = [
29
+ // Examples:
30
+ // { type: "homepage", path: "/" },
31
+ // { type: "page", path: "/:uid" },
32
+ ];
33
+
34
+ /**
35
+ * Creates a Prismic client for the project's repository. The client is used to
36
+ * query content from the Prismic API.
37
+ *
38
+ * @param config - Configuration for the Prismic client.
39
+ */
40
+ export const createClient = ({ cookies, ...config }: CreateClientConfig = {}) => {
41
+ const client = baseCreateClient(repositoryName, {
42
+ routes,
43
+ ...config,
44
+ });
45
+
46
+ enableAutoPreviews({ client, cookies });
47
+
48
+ return client;
49
+ };
50
+ `;
51
+ }
52
+
53
+ return dedent`
54
+ import { createClient as baseCreateClient } from "@prismicio/client";
55
+ import { enableAutoPreviews } from '@prismicio/svelte/kit';
56
+ import prismicConfig from "../../prismic.config.json";
57
+
58
+ /**
59
+ * The project's Prismic repository name.
60
+ */
61
+ export const repositoryName = prismicConfig.repositoryName;
62
+
63
+ /**
64
+ * A list of Route Resolver objects that define how a document's \`url\` field is resolved.
65
+ *
66
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
67
+ *
68
+ * Note: \`prismic sync\` may append new default routes for Page Types. Feel free
69
+ * to edit these to match your site's routing structure.
70
+ *
71
+ * @type {import("@prismicio/client").Route[]}
72
+ */
73
+ // TODO: Update the routes array to match your project's route structure.
74
+ const routes = [
75
+ // Examples:
76
+ // { type: "homepage", path: "/" },
77
+ // { type: "page", path: "/:uid" },
78
+ ];
79
+
80
+ /**
81
+ * Creates a Prismic client for the project's repository. The client is used to
82
+ * query content from the Prismic API.
83
+ *
84
+ * @param {import('@prismicio/svelte/kit').CreateClientConfig} config - Configuration for the Prismic client.
85
+ */
86
+ export const createClient = ({ cookies, ...config } = {}) => {
87
+ const client = baseCreateClient(repositoryName, {
88
+ routes,
89
+ ...config,
90
+ });
91
+
92
+ enableAutoPreviews({ client, cookies });
93
+
94
+ return client;
95
+ };
96
+ `;
97
+ }
98
+
99
+ export function sliceSimulatorPageTemplate(args: { version: number }): string {
100
+ const { version } = args;
101
+
102
+ const v5 = dedent`
103
+ <script>
104
+ import { SliceSimulator, SliceZone } from '@prismicio/svelte';
105
+ import { components } from '$lib/slices';
106
+ </script>
107
+
108
+ <!-- Slot syntax is used for backward compatibility with Svelte <=4. -->
109
+ <SliceSimulator let:slices>
110
+ <SliceZone {slices} {components} />
111
+ </SliceSimulator>
112
+ `;
113
+
114
+ const v4 = dedent`
115
+ <script>
116
+ import { SliceSimulator, SliceZone } from '@prismicio/svelte';
117
+ import { components } from '$lib/slices';
118
+ </script>
119
+
120
+ <SliceSimulator let:slices>
121
+ <SliceZone {slices} {components} />
122
+ </SliceSimulator>
123
+ `;
124
+
125
+ return version <= 4 ? v4 : v5;
126
+ }
127
+
128
+ export function previewAPIRouteTemplate(args: { typescript: boolean }): string {
129
+ const { typescript } = args;
130
+
131
+ if (typescript) {
132
+ return dedent`
133
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
134
+ import { createClient } from '$lib/prismicio';
135
+ import type { RequestHandler } from "./$types";
136
+
137
+ export const GET: RequestHandler = async ({ fetch, request, cookies }) => {
138
+ const client = createClient({ fetch });
139
+
140
+ return await redirectToPreviewURL({ client, request, cookies });
141
+ }
142
+ `;
143
+ }
144
+
145
+ return dedent`
146
+ import { redirectToPreviewURL } from '@prismicio/svelte/kit';
147
+ import { createClient } from '$lib/prismicio';
148
+
149
+ /* @type {import("./$types").RequestHandler} */
150
+ export async function GET({ fetch, request, cookies }) {
151
+ const client = createClient({ fetch });
152
+
153
+ return await redirectToPreviewURL({ client, request, cookies });
154
+ }
155
+ `;
156
+ }
157
+
158
+ export function rootLayoutTemplate(args: { version: number }): string {
159
+ const { version } = args;
160
+
161
+ const v5 = dedent`
162
+ <script>
163
+ import { isFilled, asImageSrc } from '@prismicio/client';
164
+ import { PrismicPreview } from '@prismicio/svelte/kit';
165
+ import { page } from '$app/state';
166
+ import { repositoryName } from '$lib/prismicio';
167
+
168
+ const { children } = $props();
169
+ </script>
170
+
171
+ <svelte:head>
172
+ <title>{page.data.page?.data.meta_title}</title>
173
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
174
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
175
+ <meta name="description" content={page.data.page.data.meta_description} />
176
+ <meta property="og:description" content={page.data.page.data.meta_description} />
177
+ {/if}
178
+ {#if isFilled.image(page.data.page?.data.meta_image)}
179
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
180
+ {/if}
181
+ </svelte:head>
182
+ {@render children()}
183
+ <PrismicPreview {repositoryName} />
184
+ `;
185
+
186
+ const v4 = dedent`
187
+ <script>
188
+ import { isFilled, asImageSrc } from '@prismicio/client';
189
+ import { PrismicPreview } from '@prismicio/svelte/kit';
190
+ import { page } from '$app/state';
191
+ import { repositoryName } from '$lib/prismicio';
192
+ </script>
193
+
194
+ <svelte:head>
195
+ <title>{page.data.page?.data.meta_title}</title>
196
+ <meta property="og:title" content={page.data.page?.data.meta_title} />
197
+ {#if isFilled.keyText(page.data.page?.data.meta_description)}
198
+ <meta name="description" content={page.data.page.data.meta_description} />
199
+ <meta property="og:description" content={page.data.page.data.meta_description} />
200
+ {/if}
201
+ {#if isFilled.image(page.data.page?.data.meta_image)}
202
+ <meta property="og:image" content={asImageSrc(page.data.page.data.meta_image)} />
203
+ {/if}
204
+ </svelte:head>
205
+ <slot />
206
+ <PrismicPreview {repositoryName} />
207
+ `;
208
+
209
+ return version <= 4 ? v4 : v5;
210
+ }
211
+
212
+ const SLICE_MARKUP = dedent`
213
+ <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
214
+ Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
215
+ <br />
216
+ <strong>You can edit this slice directly in your code editor.</strong>
217
+ </section>
218
+ `;
219
+
220
+ export function sliceTemplate(args: {
221
+ name: string;
222
+ typescript: boolean;
223
+ version: number;
224
+ }): string {
225
+ const { name, typescript, version } = args;
226
+
227
+ const pascalName = pascalCase(name);
228
+
229
+ const v5TS = dedent`
230
+ <script lang="ts">
231
+ import type { Content } from '@prismicio/client';
232
+ import type { SliceComponentProps } from '@prismicio/svelte';
233
+
234
+ type Props = SliceComponentProps<Content.${pascalName}Slice>;
235
+
236
+ const { slice }: Props = $props();
237
+ </script>
238
+
239
+ ${SLICE_MARKUP}
240
+ `;
241
+
242
+ const v5JS = dedent`
243
+ <script>
244
+ /* @typedef {import("@prismicio/client").Content} Content */
245
+ /* @typedef {import("@prismicio/svelte").SliceComponentProps} SliceComponentProps */
246
+
247
+ /* @type {SliceComponentProps<Content.${pascalName}Slice>} */
248
+ const { slice } = $props();
249
+ </script>
250
+
251
+ ${SLICE_MARKUP}
252
+ `;
253
+
254
+ const v4TS = dedent`
255
+ <script lang="ts">
256
+ import type { Content } from '@prismicio/client';
257
+
258
+ export let slice: Content.${pascalName}Slice;
259
+ </script>
260
+
261
+ ${SLICE_MARKUP}
262
+ `;
263
+
264
+ const v4JS = dedent`
265
+ <script>
266
+ /** @type {import("@prismicio/client").Content.${pascalName}Slice} */
267
+ export let slice;
268
+ </script>
269
+
270
+ ${SLICE_MARKUP}
271
+ `;
272
+
273
+ if (typescript) {
274
+ return version <= 4 ? v4TS : v5TS;
275
+ }
276
+
277
+ return version <= 4 ? v4JS : v5JS;
278
+ }