@slicemachine/adapter-nuxt2 0.3.57-alpha.repeatable-link.2 → 0.3.57-beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ const format = async (input, helpers) => {
14
14
  return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
15
15
  };
16
16
  const snippetRead = async (data, { helpers }) => {
17
- var _a, _b;
17
+ var _a;
18
18
  const { fieldPath, itemName } = data;
19
19
  const label = "Vue";
20
20
  switch (data.model.type) {
@@ -37,36 +37,14 @@ const snippetRead = async (data, { helpers }) => {
37
37
  ];
38
38
  }
39
39
  case "Link": {
40
- const repeat = ((_a = data.model.config) == null ? void 0 : _a.repeat) ?? false;
41
- const allowText = ((_b = data.model.config) == null ? void 0 : _b.allowText) ?? false;
42
- let codeText;
43
- if (!repeat && !allowText) {
44
- codeText = commonTags.stripIndent`
45
- <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
46
- `;
47
- } else if (!repeat && allowText) {
48
- codeText = commonTags.stripIndent`
49
- <PrismicLink :field="${dotPath(fieldPath)}" />
50
- `;
51
- } else if (repeat && !allowText) {
52
- codeText = commonTags.stripIndent`
53
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
54
- <PrismicLink :field="link">Link</PrismicLink>
55
- </template>
56
- `;
57
- } else if (repeat && allowText) {
58
- codeText = commonTags.stripIndent`
59
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
60
- <PrismicLink :field="link" />
61
- </template>
62
- `;
63
- } else {
64
- throw new Error("Invalid configuration.");
65
- }
66
40
  return {
67
41
  label,
68
42
  language: "vue",
69
- code: await format(codeText, helpers)
43
+ code: await format(((_a = data.model.config) == null ? void 0 : _a.allowText) ? commonTags.stripIndent`
44
+ <PrismicLink :field="${dotPath(fieldPath)}" />
45
+ ` : commonTags.stripIndent`
46
+ <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
47
+ `, helpers)
70
48
  };
71
49
  }
72
50
  case "Image": {
@@ -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: \"vue\",\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, itemName } = data;\n\n\tconst label = \"Vue\";\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} (rich)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText :field=\"${dotPath(fieldPath)}\" />\n\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)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicText :field=\"${dotPath(fieldPath)}\" />\n\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\tconst repeat = data.model.config?.repeat ?? false;\n\t\t\tconst allowText = data.model.config?.allowText ?? false;\n\n\t\t\tlet codeText;\n\t\t\tif (!repeat && !allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\">Link</PrismicLink>\n\t\t\t\t`;\n\t\t\t} else if (!repeat && allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\" />\n\t\t\t\t`;\n\t\t\t} else if (repeat && !allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<template v-for=\"(link, index) in ${dotPath(fieldPath)}\" :key=\"index\">\n\t\t\t\t\t\t<PrismicLink :field=\"link\">Link</PrismicLink>\n\t\t\t\t\t</template>\n\t\t\t\t`;\n\t\t\t} else if (repeat && allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<template v-for=\"(link, index) in ${dotPath(fieldPath)}\" :key=\"index\">\n\t\t\t\t\t\t<PrismicLink :field=\"link\" />\n\t\t\t\t\t</template>\n\t\t\t\t`;\n\t\t\t} else {\n\t\t\t\tthrow new Error(\"Invalid configuration.\");\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(codeText, helpers),\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: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage :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 \"Embed\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicEmbed :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\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<template v-for=\"${itemName} in ${dotPath(fieldPath)}\">\n\t\t\t\t\t\t\t{{ ${itemName} }}\n\t\t\t\t\t\t</template>\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 \"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\t:slices=\"${dotPath(fieldPath)}\"\n\t\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: \"vue\",\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: \"vue\",\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,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA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,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;+BAC0B,QAAQ,SAAS;AAAA,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;yBACoB,eAAe,QAAQ,SAAS;AAAA,YAC7C;AAAA;AAAA,QAGP,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClBA;;iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;AAAA,IAEA,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;UACK,QAAQ,SAAS;AAAA,QAEtB,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,EACD;AACD;;"}
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: \"vue\",\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, itemName } = data;\n\n\tconst label = \"Vue\";\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} (rich)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText :field=\"${dotPath(fieldPath)}\" />\n\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)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicText :field=\"${dotPath(fieldPath)}\" />\n\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: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tdata.model.config?.allowText\n\t\t\t\t\t\t? stripIndent`\n\t\t\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\" />\n\t\t\t\t\t\t`\n\t\t\t\t\t\t: stripIndent`\n\t\t\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\">Link</PrismicLink>\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 \"Image\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage :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 \"Embed\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicEmbed :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\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<template v-for=\"${itemName} in ${dotPath(fieldPath)}\">\n\t\t\t\t\t\t\t{{ ${itemName} }}\n\t\t\t\t\t\t</template>\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 \"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\t:slices=\"${dotPath(fieldPath)}\"\n\t\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: \"vue\",\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: \"vue\",\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,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAA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AAU;AAAA,QACV,MAAM,MAAM,OACXA;yBACoB,eAAe,QAAQ,SAAS;AAAA,YAC7C;AAAA;AAAA,QAGP,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClBA;;iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;AAAA,IAEA,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;UACK,QAAQ,SAAS;AAAA,QAEtB,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,EACD;AACD;;"}
@@ -12,7 +12,7 @@ const format = async (input, helpers) => {
12
12
  return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
13
13
  };
14
14
  const snippetRead = async (data, { helpers }) => {
15
- var _a, _b;
15
+ var _a;
16
16
  const { fieldPath, itemName } = data;
17
17
  const label = "Vue";
18
18
  switch (data.model.type) {
@@ -35,36 +35,14 @@ const snippetRead = async (data, { helpers }) => {
35
35
  ];
36
36
  }
37
37
  case "Link": {
38
- const repeat = ((_a = data.model.config) == null ? void 0 : _a.repeat) ?? false;
39
- const allowText = ((_b = data.model.config) == null ? void 0 : _b.allowText) ?? false;
40
- let codeText;
41
- if (!repeat && !allowText) {
42
- codeText = stripIndent`
43
- <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
44
- `;
45
- } else if (!repeat && allowText) {
46
- codeText = stripIndent`
47
- <PrismicLink :field="${dotPath(fieldPath)}" />
48
- `;
49
- } else if (repeat && !allowText) {
50
- codeText = stripIndent`
51
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
52
- <PrismicLink :field="link">Link</PrismicLink>
53
- </template>
54
- `;
55
- } else if (repeat && allowText) {
56
- codeText = stripIndent`
57
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
58
- <PrismicLink :field="link" />
59
- </template>
60
- `;
61
- } else {
62
- throw new Error("Invalid configuration.");
63
- }
64
38
  return {
65
39
  label,
66
40
  language: "vue",
67
- code: await format(codeText, helpers)
41
+ code: await format(((_a = data.model.config) == null ? void 0 : _a.allowText) ? stripIndent`
42
+ <PrismicLink :field="${dotPath(fieldPath)}" />
43
+ ` : stripIndent`
44
+ <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
45
+ `, helpers)
68
46
  };
69
47
  }
70
48
  case "Image": {
@@ -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: \"vue\",\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, itemName } = data;\n\n\tconst label = \"Vue\";\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} (rich)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText :field=\"${dotPath(fieldPath)}\" />\n\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)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicText :field=\"${dotPath(fieldPath)}\" />\n\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\tconst repeat = data.model.config?.repeat ?? false;\n\t\t\tconst allowText = data.model.config?.allowText ?? false;\n\n\t\t\tlet codeText;\n\t\t\tif (!repeat && !allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\">Link</PrismicLink>\n\t\t\t\t`;\n\t\t\t} else if (!repeat && allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\" />\n\t\t\t\t`;\n\t\t\t} else if (repeat && !allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<template v-for=\"(link, index) in ${dotPath(fieldPath)}\" :key=\"index\">\n\t\t\t\t\t\t<PrismicLink :field=\"link\">Link</PrismicLink>\n\t\t\t\t\t</template>\n\t\t\t\t`;\n\t\t\t} else if (repeat && allowText) {\n\t\t\t\tcodeText = stripIndent`\n\t\t\t\t\t<template v-for=\"(link, index) in ${dotPath(fieldPath)}\" :key=\"index\">\n\t\t\t\t\t\t<PrismicLink :field=\"link\" />\n\t\t\t\t\t</template>\n\t\t\t\t`;\n\t\t\t} else {\n\t\t\t\tthrow new Error(\"Invalid configuration.\");\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(codeText, helpers),\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: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage :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 \"Embed\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicEmbed :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\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<template v-for=\"${itemName} in ${dotPath(fieldPath)}\">\n\t\t\t\t\t\t\t{{ ${itemName} }}\n\t\t\t\t\t\t</template>\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 \"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\t:slices=\"${dotPath(fieldPath)}\"\n\t\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: \"vue\",\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: \"vue\",\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":[],"mappings":";AAQA,MAAM,UAAU,CAA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S;AAAA;AAAA;AAAA;AAAA,MAAA,OAIhD;AACA,cAAA,IAAI,MAAM,wBAAwB;AAAA,MACzC;AAEO,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OAAO,UAAU,OAAO;AAAA,MAAA;AAAA,IAEtC;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,+BAC0B,QAAQ,SAAS;AAAA,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,+BAC0B,QAAQ,SAAS;AAAA,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,yBACoB,eAAe,QAAQ,SAAS;AAAA,YAC7C;AAAA;AAAA,QAGP,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,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,IAEF;AAAA,IAEA,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,UACK,QAAQ,SAAS;AAAA,QAEtB,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,EACD;AACD;"}
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: \"vue\",\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, itemName } = data;\n\n\tconst label = \"Vue\";\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} (rich)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText :field=\"${dotPath(fieldPath)}\" />\n\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)`,\n\t\t\t\t\tlanguage: \"vue\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicText :field=\"${dotPath(fieldPath)}\" />\n\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: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tdata.model.config?.allowText\n\t\t\t\t\t\t? stripIndent`\n\t\t\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\" />\n\t\t\t\t\t\t`\n\t\t\t\t\t\t: stripIndent`\n\t\t\t\t\t\t\t<PrismicLink :field=\"${dotPath(fieldPath)}\">Link</PrismicLink>\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 \"Image\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage :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 \"Embed\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicEmbed :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\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"vue\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<template v-for=\"${itemName} in ${dotPath(fieldPath)}\">\n\t\t\t\t\t\t\t{{ ${itemName} }}\n\t\t\t\t\t\t</template>\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 \"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\t:slices=\"${dotPath(fieldPath)}\"\n\t\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: \"vue\",\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: \"vue\",\n\t\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N;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,+BAC0B,QAAQ,SAAS;AAAA,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,+BAC0B,QAAQ,SAAS;AAAA,SAE3C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,yBACoB,eAAe,QAAQ,SAAS;AAAA,YAC7C;AAAA;AAAA,QAGP,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,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,IAEF;AAAA,IAEA,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,UACK,QAAQ,SAAS;AAAA,QAEtB,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,EACD;AACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/adapter-nuxt2",
3
- "version": "0.3.57-alpha.repeatable-link.2",
3
+ "version": "0.3.57-beta.1",
4
4
  "description": "Slice Machine adapter for Nuxt 2.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -60,8 +60,8 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@prismicio/simulator": "^0.1.4",
63
- "@prismicio/types-internal": "2.9.0-alpha.3",
64
- "@slicemachine/plugin-kit": "0.4.57-alpha.repeatable-link.2",
63
+ "@prismicio/types-internal": "^2.8.0",
64
+ "@slicemachine/plugin-kit": "0.4.57-beta.1",
65
65
  "common-tags": "^1.8.2",
66
66
  "fp-ts": "^2.13.1",
67
67
  "io-ts": "^2.2.20",
@@ -85,7 +85,7 @@
85
85
  "nuxt": "2.16.3",
86
86
  "prettier": "3.0.3",
87
87
  "prettier-plugin-jsdoc": "1.1.1",
88
- "prismic-ts-codegen": "0.1.23-alpha.0",
88
+ "prismic-ts-codegen": "^0.1.22",
89
89
  "size-limit": "8.2.4",
90
90
  "ts-morph": "17.0.1",
91
91
  "typescript": "4.9.5",
@@ -58,38 +58,19 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
58
58
  }
59
59
 
60
60
  case "Link": {
61
- const repeat = data.model.config?.repeat ?? false;
62
- const allowText = data.model.config?.allowText ?? false;
63
-
64
- let codeText;
65
- if (!repeat && !allowText) {
66
- codeText = stripIndent`
67
- <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
68
- `;
69
- } else if (!repeat && allowText) {
70
- codeText = stripIndent`
71
- <PrismicLink :field="${dotPath(fieldPath)}" />
72
- `;
73
- } else if (repeat && !allowText) {
74
- codeText = stripIndent`
75
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
76
- <PrismicLink :field="link">Link</PrismicLink>
77
- </template>
78
- `;
79
- } else if (repeat && allowText) {
80
- codeText = stripIndent`
81
- <template v-for="(link, index) in ${dotPath(fieldPath)}" :key="index">
82
- <PrismicLink :field="link" />
83
- </template>
84
- `;
85
- } else {
86
- throw new Error("Invalid configuration.");
87
- }
88
-
89
61
  return {
90
62
  label,
91
63
  language: "vue",
92
- code: await format(codeText, helpers),
64
+ code: await format(
65
+ data.model.config?.allowText
66
+ ? stripIndent`
67
+ <PrismicLink :field="${dotPath(fieldPath)}" />
68
+ `
69
+ : stripIndent`
70
+ <PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
71
+ `,
72
+ helpers,
73
+ ),
93
74
  };
94
75
  }
95
76