@slicemachine/adapter-next 0.1.3 → 0.2.0
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.
- package/dist/hooks/project-init.cjs +2 -11
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +2 -11
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +15 -44
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +15 -44
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +34 -25
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +34 -25
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/lib/isSharedSliceModel.d.ts +2 -2
- package/dist/lib/upsertGlobalContentTypes.cjs +3 -2
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +2 -2
- package/dist/lib/upsertGlobalContentTypes.js +4 -3
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/simulator/SliceSimulator.cjs +2 -0
- package/dist/simulator/SliceSimulator.cjs.map +1 -1
- package/dist/simulator/SliceSimulator.js +2 -0
- package/dist/simulator/SliceSimulator.js.map +1 -1
- package/package.json +6 -5
- package/src/hooks/project-init.ts +2 -12
- package/src/hooks/sliceSimulator-setup-read.ts +20 -55
- package/src/hooks/snippet-read.ts +47 -33
- package/src/lib/upsertGlobalContentTypes.ts +4 -5
- package/src/simulator/SliceSimulator.tsx +2 -0
|
@@ -29,17 +29,10 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
29
29
|
await installDependencies2({
|
|
30
30
|
dependencies: {
|
|
31
31
|
"@prismicio/client": "latest",
|
|
32
|
-
"@prismicio/helpers": "latest",
|
|
33
32
|
"@prismicio/react": "latest",
|
|
34
33
|
"@prismicio/next": "latest"
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
|
-
await installDependencies2({
|
|
38
|
-
dependencies: {
|
|
39
|
-
"@prismicio/types": "latest"
|
|
40
|
-
},
|
|
41
|
-
dev: true
|
|
42
|
-
});
|
|
43
36
|
};
|
|
44
37
|
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
45
38
|
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
@@ -172,15 +165,13 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
172
165
|
|
|
173
166
|
import { components } from "../slices";
|
|
174
167
|
|
|
175
|
-
|
|
168
|
+
export default function SliceSimulatorPage() {
|
|
176
169
|
return (
|
|
177
170
|
<SliceSimulator
|
|
178
171
|
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
179
172
|
/>
|
|
180
173
|
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default SliceSimulatorPage;
|
|
174
|
+
}
|
|
184
175
|
`;
|
|
185
176
|
if (options.format) {
|
|
186
177
|
contents = await helpers.format(contents, filePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/
|
|
1
|
+
{"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tisTypeScriptProject ? \"prismicio.ts\" : \"prismicio.js\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"./slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field\n\t\t\t * is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"./slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field\n\t\t\t * is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tlet contents = stripIndent`\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\timport { components } from \"../slices\";\n\n\t\texport default function SliceSimulatorPage() {\n\t\t\treturn (\n\t\t\t\t<SliceSimulator\n\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tawait installDependencies({ installDependencies: _installDependencies }),\n\t\t\tawait createPrismicIOFile(context),\n\t\t\tawait createSliceSimulatorPage(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkIsTypeScriptProject","checkPathExists","stripIndent","fs","getJSOrTSXFileExtension","path","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,QAAM,WAAW,QAAQ,iBACxB,sBAAsB,iBAAiB,cAAc;AAGlD,MAAA,MAAMC,gBAAAA,gBAAgB,QAAQ,GAAG;AACpC;AAAA,EACA;AAEG,MAAA;AAEJ,MAAI,qBAAqB;AACb,eAAAC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAA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,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFG,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,MAAM,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACvE,MAAM,oBAAoB,OAAO;AAAA,IACjC,MAAM,yBAAyB,OAAO;AAAA,EACtC,CAAA,CAAC;AAEJ;;"}
|
|
@@ -9,17 +9,10 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
9
9
|
await installDependencies2({
|
|
10
10
|
dependencies: {
|
|
11
11
|
"@prismicio/client": "latest",
|
|
12
|
-
"@prismicio/helpers": "latest",
|
|
13
12
|
"@prismicio/react": "latest",
|
|
14
13
|
"@prismicio/next": "latest"
|
|
15
14
|
}
|
|
16
15
|
});
|
|
17
|
-
await installDependencies2({
|
|
18
|
-
dependencies: {
|
|
19
|
-
"@prismicio/types": "latest"
|
|
20
|
-
},
|
|
21
|
-
dev: true
|
|
22
|
-
});
|
|
23
16
|
};
|
|
24
17
|
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
25
18
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
@@ -152,15 +145,13 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
152
145
|
|
|
153
146
|
import { components } from "../slices";
|
|
154
147
|
|
|
155
|
-
|
|
148
|
+
export default function SliceSimulatorPage() {
|
|
156
149
|
return (
|
|
157
150
|
<SliceSimulator
|
|
158
151
|
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
159
152
|
/>
|
|
160
153
|
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default SliceSimulatorPage;
|
|
154
|
+
}
|
|
164
155
|
`;
|
|
165
156
|
if (options.format) {
|
|
166
157
|
contents = await helpers.format(contents, filePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/
|
|
1
|
+
{"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tisTypeScriptProject ? \"prismicio.ts\" : \"prismicio.js\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"./slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field\n\t\t\t * is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"./slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field\n\t\t\t * is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tlet contents = stripIndent`\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\timport { components } from \"../slices\";\n\n\t\texport default function SliceSimulatorPage() {\n\t\t\treturn (\n\t\t\t\t<SliceSimulator\n\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tawait installDependencies({ installDependencies: _installDependencies }),\n\t\t\tawait createPrismicIOFile(context),\n\t\t\tawait createSliceSimulatorPage(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;AAoBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAM,yB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AEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AAE1D,MAAI,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAef,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,MAAM,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACvE,MAAM,oBAAoB,OAAO;AAAA,IACjC,MAAM,yBAAyB,OAAO;AAAA,EACtC,CAAA,CAAC;AAEJ;"}
|
|
@@ -3,13 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
4
|
const node_module = require("node:module");
|
|
5
5
|
const index = require('./../_node_modules/node-fetch/src/index.cjs');
|
|
6
|
-
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
7
6
|
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
8
|
-
const REQUIRED_DEPENDENCIES = [
|
|
9
|
-
"@prismicio/react",
|
|
10
|
-
"@prismicio/client",
|
|
11
|
-
"@prismicio/helpers"
|
|
12
|
-
];
|
|
7
|
+
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
13
8
|
const createStep1 = async ({ project, helpers }) => {
|
|
14
9
|
const require2 = node_module.createRequire(project.root);
|
|
15
10
|
return {
|
|
@@ -61,46 +56,22 @@ const createStep2 = async ({ helpers, options }) => {
|
|
|
61
56
|
options
|
|
62
57
|
})}`;
|
|
63
58
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
options
|
|
68
|
-
});
|
|
69
|
-
if (isTypeScriptProject) {
|
|
70
|
-
fileContents = await helpers.format(commonTags.source`
|
|
71
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
72
|
-
import { SliceZone } from "@prismicio/react";
|
|
73
|
-
|
|
74
|
-
import { components } from "../slices";
|
|
75
|
-
|
|
76
|
-
export default function SliceSimulatorPage(): JSX.Element {
|
|
77
|
-
return (
|
|
78
|
-
<SliceSimulator
|
|
79
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
`, filePath, {
|
|
84
|
-
includeNewlineAtEnd: false
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
fileContents = await helpers.format(commonTags.source`
|
|
88
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
89
|
-
import { SliceZone } from "@prismicio/react";
|
|
59
|
+
const fileContents = await helpers.format(commonTags.source`
|
|
60
|
+
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
61
|
+
import { SliceZone } from "@prismicio/react";
|
|
90
62
|
|
|
91
|
-
|
|
63
|
+
import { components } from "../slices";
|
|
92
64
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
65
|
+
export default function SliceSimulatorPage() {
|
|
66
|
+
return (
|
|
67
|
+
<SliceSimulator
|
|
68
|
+
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
`, filePath, {
|
|
73
|
+
includeNewlineAtEnd: false
|
|
74
|
+
});
|
|
104
75
|
return {
|
|
105
76
|
title: "Create a page for the simulator",
|
|
106
77
|
description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/react\"];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","getJSOrTSXFileExtension","fetch"],"mappings":";;;;;;AAaA,MAAM,wBAAwB,CAAC,kBAAkB;AAIjD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAUC,YAAAA,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA;AAAA;AAAA,IAGb,MAAMC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,wBAIgB,sBAAsB,KAAK,GAAG;AAAA;AAAA;AAAA,IAGpD,UAAU,YAAW;AACpB,Y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AClCA,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,KAKA,UACA;AAAA,IACC,qBAAqB;AAAA,EAAA,CACrB;AAGK,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAMA,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,KAIH;AAAA;AAAA;AAAA,IAGH,UAAU,YAAW;AACd,YAAA,UAAU,MAAM,QAAQ;AAE1B,UAAA,EAAE,4BAA4B,QAAQ,SAAS;AAC3C,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGG,UAAA;AACC,YAAA,QAAQ,OAAO,wBAAwB;AACtC,cAAA,IAAI,QAAQ,OAAO,sBAAsB;AAAA,QAAA,OACvC;AACA,gBAAA,IAAI,MAAM,+BAA+B;AAAA,QAC/C;AAAA,MAAA,QACA;AACM,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASA,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAGD,UAAI,MAA4B;AAC5B,UAAA;AACH,cAAM,MAAME,MAAA,QAAM,QAAQ,OAAO,sBAAsB;AAAA,eAC/C;MAER;AAED,UAAI,CAAC,OAAO,CAAC,IAAI,IAAI;AACb,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASF,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;;"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { source } from "common-tags";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fetch from './../_node_modules/node-fetch/src/index.js';
|
|
4
|
-
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
5
4
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
6
|
-
const REQUIRED_DEPENDENCIES = [
|
|
7
|
-
"@prismicio/react",
|
|
8
|
-
"@prismicio/client",
|
|
9
|
-
"@prismicio/helpers"
|
|
10
|
-
];
|
|
5
|
+
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
11
6
|
const createStep1 = async ({ project, helpers }) => {
|
|
12
7
|
const require2 = createRequire(project.root);
|
|
13
8
|
return {
|
|
@@ -59,46 +54,22 @@ const createStep2 = async ({ helpers, options }) => {
|
|
|
59
54
|
options
|
|
60
55
|
})}`;
|
|
61
56
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
options
|
|
66
|
-
});
|
|
67
|
-
if (isTypeScriptProject) {
|
|
68
|
-
fileContents = await helpers.format(source`
|
|
69
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
70
|
-
import { SliceZone } from "@prismicio/react";
|
|
71
|
-
|
|
72
|
-
import { components } from "../slices";
|
|
73
|
-
|
|
74
|
-
export default function SliceSimulatorPage(): JSX.Element {
|
|
75
|
-
return (
|
|
76
|
-
<SliceSimulator
|
|
77
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
78
|
-
/>
|
|
79
|
-
);
|
|
80
|
-
};
|
|
81
|
-
`, filePath, {
|
|
82
|
-
includeNewlineAtEnd: false
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
fileContents = await helpers.format(source`
|
|
86
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
87
|
-
import { SliceZone } from "@prismicio/react";
|
|
57
|
+
const fileContents = await helpers.format(source`
|
|
58
|
+
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
59
|
+
import { SliceZone } from "@prismicio/react";
|
|
88
60
|
|
|
89
|
-
|
|
61
|
+
import { components } from "../slices";
|
|
90
62
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
63
|
+
export default function SliceSimulatorPage() {
|
|
64
|
+
return (
|
|
65
|
+
<SliceSimulator
|
|
66
|
+
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
`, filePath, {
|
|
71
|
+
includeNewlineAtEnd: false
|
|
72
|
+
});
|
|
102
73
|
return {
|
|
103
74
|
title: "Create a page for the simulator",
|
|
104
75
|
description: `In your \`pages\` directory, create a file called \`${fileName}\` containing this code.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\"@prismicio/react\"];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":";;;;AAaA,MAAM,wBAAwB,CAAC,kBAAkB;AAIjD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAU,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA;AAAA;AAAA,IAGb,MAAM;AAAA;AAAA;AAAA;AAAA,wBAIgB,sBAAsB,KAAK,GAAG;AAAA;AAAA;AAAA,IAGpD,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAA,SAAQ,QAAQ,YAAY;AAAA,YAC3B,OAAO,CAAC,QAAQ,iBAAiB,cAAc,CAAC;AAAA,UAAA,CAChD;AAAA,QAAA,QACA;AACD,8BAAoB,KAAK,UAAU;AAAA,QACnC;AAAA,MACD;AAEG,UAAA,oBAAoB,UAAU,sBAAsB,QAAQ;AACxD,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAEG,UAAA,oBAAoB,SAAS,GAAG;AAC7B,cAAA,+BAA+B,oBACnC,IAAI,CAAC,sBAAsB,KAAK,qBAAqB,EACrD,KAAK,IAAI;AAEJ,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA,gDACkC;AAAA;AAAA,QAAA;AAAA,MAG5C;AAAA,IACF;AAAA,EAAA;AAEF;AAEA,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAA,WAAW,mBAAmB,MAAM,wBAAwB;AAAA,IACjE;AAAA,IACA;AAAA,EACA,CAAA;AACD,QAAM,WAAW,QAAQ,iBAAiB,SAAS,QAAQ;AAErD,QAAA,eAAe,MAAM,QAAQ,OAClC;AAAA;AAAA;AAAA;A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AAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
|
-
const dotPath = (segments) => {
|
|
5
|
-
return segments.join(".");
|
|
4
|
+
const dotPath = (...segments) => {
|
|
5
|
+
return segments.flat().join(".");
|
|
6
6
|
};
|
|
7
7
|
const format = async (input, helpers) => {
|
|
8
8
|
const formattedInput = await helpers.format(input, void 0, {
|
|
@@ -18,40 +18,40 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
18
18
|
const label = "React";
|
|
19
19
|
switch (data.model.type) {
|
|
20
20
|
case "StructuredText": {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
label: `${label} (components)`,
|
|
24
|
+
language: "tsx",
|
|
25
|
+
code: await format(commonTags.stripIndent`
|
|
26
|
+
<PrismicRichText field={${dotPath(fieldPath)}} />
|
|
27
|
+
`, helpers)
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: `${label} (plain text)`,
|
|
31
|
+
language: "tsx",
|
|
32
|
+
code: await format(commonTags.stripIndent`
|
|
33
|
+
<PrismicText field={${dotPath(fieldPath)}} />
|
|
34
|
+
`, helpers)
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
case "Link": {
|
|
21
39
|
return {
|
|
22
40
|
label,
|
|
23
41
|
language: "tsx",
|
|
24
42
|
code: await format(commonTags.stripIndent`
|
|
25
|
-
<
|
|
43
|
+
<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>
|
|
26
44
|
`, helpers)
|
|
27
45
|
};
|
|
28
46
|
}
|
|
29
|
-
case "
|
|
47
|
+
case "Image": {
|
|
30
48
|
return {
|
|
31
49
|
label,
|
|
32
50
|
language: "tsx",
|
|
33
51
|
code: await format(commonTags.stripIndent`
|
|
34
|
-
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
|
|
35
|
-
`, helpers)
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
case "Image": {
|
|
39
|
-
return [
|
|
40
|
-
{
|
|
41
|
-
label: `${label} (next/image)`,
|
|
42
|
-
language: "tsx",
|
|
43
|
-
code: await format(commonTags.stripIndent`
|
|
44
52
|
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
45
53
|
`, helpers)
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
label,
|
|
49
|
-
language: "tsx",
|
|
50
|
-
code: await format(commonTags.stripIndent`
|
|
51
|
-
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
52
|
-
`, helpers)
|
|
53
|
-
}
|
|
54
|
-
];
|
|
54
|
+
};
|
|
55
55
|
}
|
|
56
56
|
case "Group": {
|
|
57
57
|
const code = await format(commonTags.stripIndent`
|
|
@@ -78,10 +78,19 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
78
78
|
code
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
case "GeoPoint":
|
|
81
|
+
case "GeoPoint": {
|
|
82
|
+
const code = await format(commonTags.stripIndent`
|
|
83
|
+
<>{${dotPath(fieldPath, "latitude")}}, {${dotPath(fieldPath, "longitude")}}</>
|
|
84
|
+
`, helpers);
|
|
85
|
+
return {
|
|
86
|
+
label,
|
|
87
|
+
language: "tsx",
|
|
88
|
+
code
|
|
89
|
+
};
|
|
90
|
+
}
|
|
82
91
|
case "Embed": {
|
|
83
92
|
const code = await format(commonTags.stripIndent`
|
|
84
|
-
|
|
93
|
+
<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, "html")} }} />
|
|
85
94
|
`, helpers);
|
|
86
95
|
return {
|
|
87
96
|
label,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-read.cjs","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (segments: string[]): string => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn {\n\t\t\t\tlabel
|
|
1
|
+
{"version":3,"file":"snippet-read.cjs","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (components)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (plain text)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Image\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"GeoPoint\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath, \"latitude\")}}, {${dotPath(fieldPath, \"longitude\")}}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Embed\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, \"html\")} }} />\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":["stripIndent"],"mappings":";;;AAQA,MAAM,UAAU,IAAI,aAA2C;AAC9D,SAAO,SAAS,KAAA,EAAO,KAAK,GAAG;AAChC;AAEA,MAAM,SAA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Ea,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClBA;UACM,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEzE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;+CAC2C,QAAQ,WAAW,MAAM;AAAA,OAEpE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stripIndent } from "common-tags";
|
|
2
|
-
const dotPath = (segments) => {
|
|
3
|
-
return segments.join(".");
|
|
2
|
+
const dotPath = (...segments) => {
|
|
3
|
+
return segments.flat().join(".");
|
|
4
4
|
};
|
|
5
5
|
const format = async (input, helpers) => {
|
|
6
6
|
const formattedInput = await helpers.format(input, void 0, {
|
|
@@ -16,40 +16,40 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
16
16
|
const label = "React";
|
|
17
17
|
switch (data.model.type) {
|
|
18
18
|
case "StructuredText": {
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
label: `${label} (components)`,
|
|
22
|
+
language: "tsx",
|
|
23
|
+
code: await format(stripIndent`
|
|
24
|
+
<PrismicRichText field={${dotPath(fieldPath)}} />
|
|
25
|
+
`, helpers)
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: `${label} (plain text)`,
|
|
29
|
+
language: "tsx",
|
|
30
|
+
code: await format(stripIndent`
|
|
31
|
+
<PrismicText field={${dotPath(fieldPath)}} />
|
|
32
|
+
`, helpers)
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
case "Link": {
|
|
19
37
|
return {
|
|
20
38
|
label,
|
|
21
39
|
language: "tsx",
|
|
22
40
|
code: await format(stripIndent`
|
|
23
|
-
<
|
|
41
|
+
<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>
|
|
24
42
|
`, helpers)
|
|
25
43
|
};
|
|
26
44
|
}
|
|
27
|
-
case "
|
|
45
|
+
case "Image": {
|
|
28
46
|
return {
|
|
29
47
|
label,
|
|
30
48
|
language: "tsx",
|
|
31
49
|
code: await format(stripIndent`
|
|
32
|
-
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
|
|
33
|
-
`, helpers)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
case "Image": {
|
|
37
|
-
return [
|
|
38
|
-
{
|
|
39
|
-
label: `${label} (next/image)`,
|
|
40
|
-
language: "tsx",
|
|
41
|
-
code: await format(stripIndent`
|
|
42
50
|
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
43
51
|
`, helpers)
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
label,
|
|
47
|
-
language: "tsx",
|
|
48
|
-
code: await format(stripIndent`
|
|
49
|
-
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
50
|
-
`, helpers)
|
|
51
|
-
}
|
|
52
|
-
];
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
case "Group": {
|
|
55
55
|
const code = await format(stripIndent`
|
|
@@ -76,10 +76,19 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
76
76
|
code
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
case "GeoPoint":
|
|
79
|
+
case "GeoPoint": {
|
|
80
|
+
const code = await format(stripIndent`
|
|
81
|
+
<>{${dotPath(fieldPath, "latitude")}}, {${dotPath(fieldPath, "longitude")}}</>
|
|
82
|
+
`, helpers);
|
|
83
|
+
return {
|
|
84
|
+
label,
|
|
85
|
+
language: "tsx",
|
|
86
|
+
code
|
|
87
|
+
};
|
|
88
|
+
}
|
|
80
89
|
case "Embed": {
|
|
81
90
|
const code = await format(stripIndent`
|
|
82
|
-
|
|
91
|
+
<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, "html")} }} />
|
|
83
92
|
`, helpers);
|
|
84
93
|
return {
|
|
85
94
|
label,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-read.js","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (segments: string[]): string => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn {\n\t\t\t\tlabel
|
|
1
|
+
{"version":3,"file":"snippet-read.js","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (components)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (plain text)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Image\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"GeoPoint\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath, \"latitude\")}}, {${dotPath(fieldPath, \"longitude\")}}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Embed\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, \"html\")} }} />\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\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AGT;AAAA,IAED,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,kCAC6B,QAAQ,SAAS;AAAA,SAE9C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClB;AAAA;AAAA,iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClB;AAAA,UACM,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEzE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,+CAC2C,QAAQ,WAAW,MAAM;AAAA,OAEpE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;"}
|
|
@@ -135,7 +135,7 @@ export declare const isSharedSliceModel: (input: any) => input is {
|
|
|
135
135
|
label?: string | null | undefined;
|
|
136
136
|
useAsTitle?: boolean | undefined;
|
|
137
137
|
placeholder?: string | undefined;
|
|
138
|
-
select?: "
|
|
138
|
+
select?: "media" | "document" | "web" | null | undefined;
|
|
139
139
|
customtypes?: readonly string[] | undefined;
|
|
140
140
|
masks?: readonly string[] | undefined;
|
|
141
141
|
tags?: readonly string[] | undefined;
|
|
@@ -294,7 +294,7 @@ export declare const isSharedSliceModel: (input: any) => input is {
|
|
|
294
294
|
label?: string | null | undefined;
|
|
295
295
|
useAsTitle?: boolean | undefined;
|
|
296
296
|
placeholder?: string | undefined;
|
|
297
|
-
select?: "
|
|
297
|
+
select?: "media" | "document" | "web" | null | undefined;
|
|
298
298
|
customtypes?: readonly string[] | undefined;
|
|
299
299
|
masks?: readonly string[] | undefined;
|
|
300
300
|
tags?: readonly string[] | undefined;
|
|
@@ -22,7 +22,7 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
}
|
|
23
23
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
24
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
25
|
-
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
25
|
+
const upsertGlobalContentTypes = async ({ actions, helpers, options, project }) => {
|
|
26
26
|
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
27
27
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
28
28
|
actions.readAllCustomTypeModels(),
|
|
@@ -40,7 +40,8 @@ const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
|
40
40
|
clientIntegration: {
|
|
41
41
|
includeCreateClientInterface: true,
|
|
42
42
|
includeContentNamespace: true
|
|
43
|
-
}
|
|
43
|
+
},
|
|
44
|
+
typesProvider: await prismicTsCodegen.detectTypesProvider({ cwd: project.root })
|
|
44
45
|
});
|
|
45
46
|
contents = `${constants.NON_EDITABLE_FILE_BANNER}
|
|
46
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs =
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { detectTypesProvider, generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n\tproject,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio-types.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t\ttypesProvider: await detectTypesProvider({ cwd: project.root }),\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors","generateTypes","detectTypesProvider","NON_EDITABLE_FILE_BANNER","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,sBAAsB;AAEhE,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAWC,iBAAAA,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,IACD,eAAe,MAAMC,iBAAAA,oBAAoB,EAAE,KAAK,QAAQ,MAAM;AAAA,EAAA,CAC9D;AAED,aAAW,GAAGC;;EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,MAAMC,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAAD,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -3,10 +3,10 @@ import type { PluginOptions } from "../types";
|
|
|
3
3
|
/**
|
|
4
4
|
* Arguments for `upsertGlobalContentTypes()`.
|
|
5
5
|
*/
|
|
6
|
-
type UpsertGlobalTypesArgs =
|
|
6
|
+
type UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;
|
|
7
7
|
/**
|
|
8
8
|
* Creates a globally accessible TypeScript file containing types representing
|
|
9
9
|
* the Prismic repository's content.
|
|
10
10
|
*/
|
|
11
|
-
export declare const upsertGlobalContentTypes: ({ actions, helpers, options, }: UpsertGlobalTypesArgs) => Promise<void>;
|
|
11
|
+
export declare const upsertGlobalContentTypes: ({ actions, helpers, options, project, }: UpsertGlobalTypesArgs) => Promise<void>;
|
|
12
12
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { generateTypes } from "prismic-ts-codegen";
|
|
1
|
+
import { generateTypes, detectTypesProvider } from "prismic-ts-codegen";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
5
|
-
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
5
|
+
const upsertGlobalContentTypes = async ({ actions, helpers, options, project }) => {
|
|
6
6
|
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
7
7
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
8
8
|
actions.readAllCustomTypeModels(),
|
|
@@ -20,7 +20,8 @@ const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
|
20
20
|
clientIntegration: {
|
|
21
21
|
includeCreateClientInterface: true,
|
|
22
22
|
includeContentNamespace: true
|
|
23
|
-
}
|
|
23
|
+
},
|
|
24
|
+
typesProvider: await detectTypesProvider({ cwd: project.root })
|
|
24
25
|
});
|
|
25
26
|
contents = `${NON_EDITABLE_FILE_BANNER}
|
|
26
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs =
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { detectTypesProvider, generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n\tproject,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio-types.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t\ttypesProvider: await detectTypesProvider({ cwd: project.root }),\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors"],"mappings":";;;;AAiBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,sBAAsB;AAEhE,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAW,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,IACD,eAAe,MAAM,oBAAoB,EAAE,KAAK,QAAQ,MAAM;AAAA,EAAA,CAC9D;AAED,aAAW,GAAG;AAAA;AAAA,EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.cjs","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"SliceSimulator.cjs","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & Omit<BaseSliceSimulatorProps, \"state\">;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(defaultProps.state);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBA;AA6Ba;AAMZ;AAEM;AAGA;AACA;AAENA;AACC;AAGE;AAA6B;AAI/B;AAGE;AAAiB;AAInB;AAGE;AAAmB;AAKT;AAEZ;AACC;AAKA;AAKA;AAEoB;AAAA;AAKtB;AAGS;AAIQ;AACJ;AACL;AACC;AACC;AACC;AACE;AAIQ;AAwBtB;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use client';
|
|
1
3
|
import { jsx } from "react/jsx-runtime";
|
|
2
4
|
import * as React from "react";
|
|
3
5
|
import { CoreManager, getDefaultProps, getDefaultManagedState, getDefaultSlices, getDefaultMessage, StateManagerEventType, simulatorClass, simulatorRootClass, StateManagerStatus, onClickHandler, disableEventHandler } from "@prismicio/slice-simulator-core";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.js","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"SliceSimulator.js","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & Omit<BaseSliceSimulatorProps, \"state\">;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(defaultProps.state);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":[],"mappings":";;;;;AAmBA;AA6Ba;AAMZ;AAEM;AAGA;AACA;AAEN;AACC;AAGE;AAA6B;AAI/B;AAGE;AAAiB;AAInB;AAGE;AAAmB;AAKT;AAEZ;AACC;AAKA;AAKA;AAEoB;AAAA;AAKtB;AAGS;AAIQ;AACJ;AACL;AACC;AACC;AACC;AACE;AAIQ;AAwBtB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Slice Machine adapter for Next.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@prismicio/slice-simulator-core": "^0.2.7",
|
|
61
|
-
"@prismicio/types-internal": "2.0.0-
|
|
62
|
-
"@slicemachine/plugin-kit": "0.
|
|
61
|
+
"@prismicio/types-internal": "2.0.0-beta.1",
|
|
62
|
+
"@slicemachine/plugin-kit": "0.3.0",
|
|
63
63
|
"common-tags": "^1.8.2",
|
|
64
64
|
"fs-extra": "^11.1.0",
|
|
65
65
|
"node-fetch": "^3.3.1",
|
|
66
66
|
"pascal-case": "^3.1.2",
|
|
67
|
-
"prismic-ts-codegen": "
|
|
67
|
+
"prismic-ts-codegen": "0.1.9"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@prismicio/mock": "^0.2.0",
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"prettier": "^2.8.4",
|
|
88
88
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
89
89
|
"react": "^18.2.0",
|
|
90
|
+
"rollup-plugin-preserve-directives": "^0.1.1",
|
|
90
91
|
"size-limit": "^8.2.4",
|
|
91
92
|
"ts-morph": "^17.0.1",
|
|
92
93
|
"typescript": "^4.9.5",
|
|
@@ -104,5 +105,5 @@
|
|
|
104
105
|
"publishConfig": {
|
|
105
106
|
"access": "public"
|
|
106
107
|
},
|
|
107
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "97b84b052a08d28f9cb7cd93826e812054b73ee3"
|
|
108
109
|
}
|
|
@@ -24,18 +24,10 @@ const installDependencies = async ({
|
|
|
24
24
|
await installDependencies({
|
|
25
25
|
dependencies: {
|
|
26
26
|
"@prismicio/client": "latest",
|
|
27
|
-
"@prismicio/helpers": "latest",
|
|
28
27
|
"@prismicio/react": "latest",
|
|
29
28
|
"@prismicio/next": "latest",
|
|
30
29
|
},
|
|
31
30
|
});
|
|
32
|
-
|
|
33
|
-
await installDependencies({
|
|
34
|
-
dependencies: {
|
|
35
|
-
"@prismicio/types": "latest",
|
|
36
|
-
},
|
|
37
|
-
dev: true,
|
|
38
|
-
});
|
|
39
31
|
};
|
|
40
32
|
|
|
41
33
|
type CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;
|
|
@@ -197,15 +189,13 @@ const createSliceSimulatorPage = async ({
|
|
|
197
189
|
|
|
198
190
|
import { components } from "../slices";
|
|
199
191
|
|
|
200
|
-
|
|
192
|
+
export default function SliceSimulatorPage() {
|
|
201
193
|
return (
|
|
202
194
|
<SliceSimulator
|
|
203
195
|
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
204
196
|
/>
|
|
205
197
|
);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export default SliceSimulatorPage;
|
|
198
|
+
}
|
|
209
199
|
`;
|
|
210
200
|
|
|
211
201
|
if (options.format) {
|
|
@@ -7,16 +7,11 @@ import { source } from "common-tags";
|
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import fetch, { Response } from "node-fetch";
|
|
9
9
|
|
|
10
|
-
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
11
10
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
12
11
|
|
|
13
12
|
import type { PluginOptions } from "../types";
|
|
14
13
|
|
|
15
|
-
const REQUIRED_DEPENDENCIES = [
|
|
16
|
-
"@prismicio/react",
|
|
17
|
-
"@prismicio/client",
|
|
18
|
-
"@prismicio/helpers",
|
|
19
|
-
];
|
|
14
|
+
const REQUIRED_DEPENDENCIES = ["@prismicio/react"];
|
|
20
15
|
|
|
21
16
|
type Args = SliceMachineContext<PluginOptions>;
|
|
22
17
|
|
|
@@ -90,56 +85,26 @@ const createStep2 = async ({
|
|
|
90
85
|
})}`;
|
|
91
86
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
92
87
|
|
|
93
|
-
|
|
88
|
+
const fileContents = await helpers.format(
|
|
89
|
+
source`
|
|
90
|
+
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
91
|
+
import { SliceZone } from "@prismicio/react";
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<SliceSimulator
|
|
111
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
112
|
-
/>
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
`,
|
|
116
|
-
filePath,
|
|
117
|
-
{
|
|
118
|
-
includeNewlineAtEnd: false,
|
|
119
|
-
},
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
fileContents = await helpers.format(
|
|
123
|
-
source`
|
|
124
|
-
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
125
|
-
import { SliceZone } from "@prismicio/react";
|
|
126
|
-
|
|
127
|
-
import { components } from "../slices";
|
|
128
|
-
|
|
129
|
-
export default function SliceSimulatorPage() {
|
|
130
|
-
return (
|
|
131
|
-
<SliceSimulator
|
|
132
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
133
|
-
/>
|
|
134
|
-
);
|
|
135
|
-
};
|
|
136
|
-
`,
|
|
137
|
-
filePath,
|
|
138
|
-
{
|
|
139
|
-
includeNewlineAtEnd: false,
|
|
140
|
-
},
|
|
141
|
-
);
|
|
142
|
-
}
|
|
93
|
+
import { components } from "../slices";
|
|
94
|
+
|
|
95
|
+
export default function SliceSimulatorPage() {
|
|
96
|
+
return (
|
|
97
|
+
<SliceSimulator
|
|
98
|
+
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
99
|
+
/>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
`,
|
|
103
|
+
filePath,
|
|
104
|
+
{
|
|
105
|
+
includeNewlineAtEnd: false,
|
|
106
|
+
},
|
|
107
|
+
);
|
|
143
108
|
|
|
144
109
|
return {
|
|
145
110
|
title: "Create a page for the simulator",
|
|
@@ -6,8 +6,8 @@ import { stripIndent } from "common-tags";
|
|
|
6
6
|
|
|
7
7
|
import type { PluginOptions } from "../types";
|
|
8
8
|
|
|
9
|
-
const dotPath = (segments: string[]): string => {
|
|
10
|
-
return segments.join(".");
|
|
9
|
+
const dotPath = (...segments: (string | string[])[]): string => {
|
|
10
|
+
return segments.flat().join(".");
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const format = async (input: string, helpers: SliceMachineHelpers) => {
|
|
@@ -33,56 +33,56 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
33
33
|
|
|
34
34
|
switch (data.model.type) {
|
|
35
35
|
case "StructuredText": {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
label: `${label} (components)`,
|
|
39
|
+
language: "tsx",
|
|
40
|
+
code: await format(
|
|
41
|
+
stripIndent`
|
|
42
|
+
<PrismicRichText field={${dotPath(fieldPath)}} />
|
|
43
|
+
`,
|
|
44
|
+
helpers,
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: `${label} (plain text)`,
|
|
49
|
+
language: "tsx",
|
|
50
|
+
code: await format(
|
|
51
|
+
stripIndent`
|
|
52
|
+
<PrismicText field={${dotPath(fieldPath)}} />
|
|
53
|
+
`,
|
|
54
|
+
helpers,
|
|
55
|
+
),
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
case "Link": {
|
|
36
61
|
return {
|
|
37
62
|
label,
|
|
38
63
|
language: "tsx",
|
|
39
64
|
code: await format(
|
|
40
65
|
stripIndent`
|
|
41
|
-
<
|
|
66
|
+
<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>
|
|
42
67
|
`,
|
|
43
68
|
helpers,
|
|
44
69
|
),
|
|
45
70
|
};
|
|
46
71
|
}
|
|
47
72
|
|
|
48
|
-
case "
|
|
73
|
+
case "Image": {
|
|
49
74
|
return {
|
|
50
75
|
label,
|
|
51
76
|
language: "tsx",
|
|
52
77
|
code: await format(
|
|
53
78
|
stripIndent`
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
80
|
+
`,
|
|
56
81
|
helpers,
|
|
57
82
|
),
|
|
58
83
|
};
|
|
59
84
|
}
|
|
60
85
|
|
|
61
|
-
case "Image": {
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
label: `${label} (next/image)`,
|
|
65
|
-
language: "tsx",
|
|
66
|
-
code: await format(
|
|
67
|
-
stripIndent`
|
|
68
|
-
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
69
|
-
`,
|
|
70
|
-
helpers,
|
|
71
|
-
),
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
label,
|
|
75
|
-
language: "tsx",
|
|
76
|
-
code: await format(
|
|
77
|
-
stripIndent`
|
|
78
|
-
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
79
|
-
`,
|
|
80
|
-
helpers,
|
|
81
|
-
),
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
86
|
case "Group": {
|
|
87
87
|
const code = await format(
|
|
88
88
|
stripIndent`
|
|
@@ -118,11 +118,25 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
case "GeoPoint":
|
|
121
|
+
case "GeoPoint": {
|
|
122
|
+
const code = await format(
|
|
123
|
+
stripIndent`
|
|
124
|
+
<>{${dotPath(fieldPath, "latitude")}}, {${dotPath(fieldPath, "longitude")}}</>
|
|
125
|
+
`,
|
|
126
|
+
helpers,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
label,
|
|
131
|
+
language: "tsx",
|
|
132
|
+
code,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
122
136
|
case "Embed": {
|
|
123
137
|
const code = await format(
|
|
124
138
|
stripIndent`
|
|
125
|
-
|
|
139
|
+
<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, "html")} }} />
|
|
126
140
|
`,
|
|
127
141
|
helpers,
|
|
128
142
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import { generateTypes } from "prismic-ts-codegen";
|
|
2
|
+
import { detectTypesProvider, generateTypes } from "prismic-ts-codegen";
|
|
3
3
|
import * as fs from "node:fs/promises";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
@@ -9,10 +9,7 @@ import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
|
9
9
|
/**
|
|
10
10
|
* Arguments for `upsertGlobalContentTypes()`.
|
|
11
11
|
*/
|
|
12
|
-
type UpsertGlobalTypesArgs =
|
|
13
|
-
SliceMachineContext<PluginOptions>,
|
|
14
|
-
"actions" | "helpers" | "options"
|
|
15
|
-
>;
|
|
12
|
+
type UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* Creates a globally accessible TypeScript file containing types representing
|
|
@@ -22,6 +19,7 @@ export const upsertGlobalContentTypes = async ({
|
|
|
22
19
|
actions,
|
|
23
20
|
helpers,
|
|
24
21
|
options,
|
|
22
|
+
project,
|
|
25
23
|
}: UpsertGlobalTypesArgs): Promise<void> => {
|
|
26
24
|
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
27
25
|
|
|
@@ -49,6 +47,7 @@ export const upsertGlobalContentTypes = async ({
|
|
|
49
47
|
includeCreateClientInterface: true,
|
|
50
48
|
includeContentNamespace: true,
|
|
51
49
|
},
|
|
50
|
+
typesProvider: await detectTypesProvider({ cwd: project.root }),
|
|
52
51
|
});
|
|
53
52
|
|
|
54
53
|
contents = `${NON_EDITABLE_FILE_BANNER}\n\n${contents}`;
|