@slicemachine/adapter-sveltekit 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.
@@ -15,7 +15,7 @@ const format = async (input, helpers) => {
15
15
  return formattedInput;
16
16
  };
17
17
  const snippetRead = async (data, { helpers }) => {
18
- var _a, _b;
18
+ var _a;
19
19
  const { fieldPath, itemName } = data;
20
20
  const label = "Svelte";
21
21
  switch (data.model.type) {
@@ -38,36 +38,14 @@ const snippetRead = async (data, { helpers }) => {
38
38
  ];
39
39
  }
40
40
  case "Link": {
41
- const repeat = ((_a = data.model.config) == null ? void 0 : _a.repeat) ?? false;
42
- const allowText = ((_b = data.model.config) == null ? void 0 : _b.allowText) ?? false;
43
- let codeText;
44
- if (!repeat && !allowText) {
45
- codeText = commonTags.stripIndent`
46
- <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
47
- `;
48
- } else if (!repeat && allowText) {
49
- codeText = commonTags.stripIndent`
50
- <PrismicLink field={${dotPath(fieldPath)}} />
51
- `;
52
- } else if (repeat && !allowText) {
53
- codeText = commonTags.stripIndent`
54
- {#each ${dotPath(fieldPath)} as link, index (index)}
55
- <PrismicLink field={link}>Link</PrismicLink>
56
- {/each}
57
- `;
58
- } else if (repeat && allowText) {
59
- codeText = commonTags.stripIndent`
60
- {#each ${dotPath(fieldPath)} as link, index (index)}
61
- <PrismicLink field={link} />
62
- {/each}
63
- `;
64
- } else {
65
- throw new Error("Invalid configuration.");
66
- }
67
41
  return {
68
42
  label,
69
43
  language: "svelte",
70
- code: await format(codeText, helpers)
44
+ code: await format(((_a = data.model.config) == null ? void 0 : _a.allowText) ? commonTags.stripIndent`
45
+ <PrismicLink field={${dotPath(fieldPath)}} />
46
+ ` : commonTags.stripIndent`
47
+ <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
48
+ `, helpers)
71
49
  };
72
50
  }
73
51
  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[])[]): 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\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\tparser: \"svelte\",\n\t\t},\n\t});\n\n\treturn formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath, itemName } = data;\n\n\tconst label = \"Svelte\";\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: \"svelte\",\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: \"svelte\",\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\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{#each ${dotPath(fieldPath)} as link, index (index)}\n\t\t\t\t\t\t<PrismicLink field={link}>Link</PrismicLink>\n\t\t\t\t\t{/each}\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{#each ${dotPath(fieldPath)} as link, index (index)}\n\t\t\t\t\t\t<PrismicLink field={link} />\n\t\t\t\t\t{/each}\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: \"svelte\",\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: \"svelte\",\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{#each ${dotPath(fieldPath)} as ${itemName}}\n\t\t\t\t\t\t<!-- Render content for ${itemName} -->\n\t\t\t\t\t{/each}\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: \"svelte\",\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}\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: \"svelte\",\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: \"svelte\",\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{@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: \"svelte\",\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: \"svelte\",\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,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,SAAS,CAAC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S;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;8BACyB,QAAQ,SAAS;AAAA,SAE1C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;cACU,QAAQ,SAAS,QAAQ;AAAA,gCACP;AAAA;AAAA,OAG5B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;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,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClBA;QACI,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEvE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;AAAA,IAEA,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;cACU,QAAQ,WAAW,MAAM;AAAA,OAEnC,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;SACI,QAAQ,SAAS;AAAA,QAErB,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[])[]): 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\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\tparser: \"svelte\",\n\t\t},\n\t});\n\n\treturn formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath, itemName } = data;\n\n\tconst label = \"Svelte\";\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: \"svelte\",\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: \"svelte\",\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: \"svelte\",\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: \"svelte\",\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{#each ${dotPath(fieldPath)} as ${itemName}}\n\t\t\t\t\t\t<!-- Render content for ${itemName} -->\n\t\t\t\t\t{/each}\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: \"svelte\",\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}\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: \"svelte\",\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: \"svelte\",\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{@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: \"svelte\",\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: \"svelte\",\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,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,SAAS,CAAC,wBAAwB;AAAA,MAClC,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA;AACR;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;;AACG,QAAA,EAAE,WAAW,SAAa,IAAA;AAEhC,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;iCAC2B,QAAQ,SAAS;AAAA,SAE5C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;6BACuB,QAAQ,SAAS;AAAA,SAExC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEH;AAAA,IAEA,KAAK,QAAQ;AACL,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,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@@ const format = async (input, helpers) => {
13
13
  return formattedInput;
14
14
  };
15
15
  const snippetRead = async (data, { helpers }) => {
16
- var _a, _b;
16
+ var _a;
17
17
  const { fieldPath, itemName } = data;
18
18
  const label = "Svelte";
19
19
  switch (data.model.type) {
@@ -36,36 +36,14 @@ const snippetRead = async (data, { helpers }) => {
36
36
  ];
37
37
  }
38
38
  case "Link": {
39
- const repeat = ((_a = data.model.config) == null ? void 0 : _a.repeat) ?? false;
40
- const allowText = ((_b = data.model.config) == null ? void 0 : _b.allowText) ?? false;
41
- let codeText;
42
- if (!repeat && !allowText) {
43
- codeText = stripIndent`
44
- <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
45
- `;
46
- } else if (!repeat && allowText) {
47
- codeText = stripIndent`
48
- <PrismicLink field={${dotPath(fieldPath)}} />
49
- `;
50
- } else if (repeat && !allowText) {
51
- codeText = stripIndent`
52
- {#each ${dotPath(fieldPath)} as link, index (index)}
53
- <PrismicLink field={link}>Link</PrismicLink>
54
- {/each}
55
- `;
56
- } else if (repeat && allowText) {
57
- codeText = stripIndent`
58
- {#each ${dotPath(fieldPath)} as link, index (index)}
59
- <PrismicLink field={link} />
60
- {/each}
61
- `;
62
- } else {
63
- throw new Error("Invalid configuration.");
64
- }
65
39
  return {
66
40
  label,
67
41
  language: "svelte",
68
- code: await format(codeText, helpers)
42
+ code: await format(((_a = data.model.config) == null ? void 0 : _a.allowText) ? stripIndent`
43
+ <PrismicLink field={${dotPath(fieldPath)}} />
44
+ ` : stripIndent`
45
+ <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
46
+ `, helpers)
69
47
  };
70
48
  }
71
49
  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[])[]): 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\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\tparser: \"svelte\",\n\t\t},\n\t});\n\n\treturn formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath, itemName } = data;\n\n\tconst label = \"Svelte\";\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: \"svelte\",\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: \"svelte\",\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\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{#each ${dotPath(fieldPath)} as link, index (index)}\n\t\t\t\t\t\t<PrismicLink field={link}>Link</PrismicLink>\n\t\t\t\t\t{/each}\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{#each ${dotPath(fieldPath)} as link, index (index)}\n\t\t\t\t\t\t<PrismicLink field={link} />\n\t\t\t\t\t{/each}\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: \"svelte\",\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: \"svelte\",\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{#each ${dotPath(fieldPath)} as ${itemName}}\n\t\t\t\t\t\t<!-- Render content for ${itemName} -->\n\t\t\t\t\t{/each}\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: \"svelte\",\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}\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: \"svelte\",\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: \"svelte\",\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{@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: \"svelte\",\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: \"svelte\",\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,IAAI,aAA2C;AAC9D,SAAO,SAAS,KAAA,EAAO,KAAK,GAAG;AAChC;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,SAAS,CAAC,wBAAwB;AAAA,MAClC,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA;AACR;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;;AACG,QAAA,EAAE,WAAW,SAAa,IAAA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MAAM,OAClB;AAAA,cACU,QAAQ,SAAS,QAAQ;AAAA,gCACP;AAAA;AAAA,OAG5B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;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,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClB;AAAA,QACI,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEvE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;AAAA,IAEA,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,cACU,QAAQ,WAAW,MAAM;AAAA,OAEnC,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,SACI,QAAQ,SAAS;AAAA,QAErB,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[])[]): 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\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\tparser: \"svelte\",\n\t\t},\n\t});\n\n\treturn formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath, itemName } = data;\n\n\tconst label = \"Svelte\";\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: \"svelte\",\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: \"svelte\",\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: \"svelte\",\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: \"svelte\",\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t{#each ${dotPath(fieldPath)} as ${itemName}}\n\t\t\t\t\t\t<!-- Render content for ${itemName} -->\n\t\t\t\t\t{/each}\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: \"svelte\",\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}\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: \"svelte\",\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: \"svelte\",\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{@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: \"svelte\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdef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AA,IAEA,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,8BACyB,QAAQ,SAAS;AAAA,SAE1C,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,IAEA,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,cACU,QAAQ,SAAS,QAAQ;AAAA,gCACP;AAAA;AAAA,OAG5B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;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,KAAK,YAAY;AACV,YAAA,OAAO,MAAM,OAClB;AAAA,QACI,QAAQ,WAAW,UAAU,QAAQ,QAAQ,WAAW,WAAW;AAAA,OAEvE,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAEF;AAAA,IAEA,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,cACU,QAAQ,WAAW,MAAM;AAAA,OAEnC,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,SACI,QAAQ,SAAS;AAAA,QAErB,OAAO;AAAA,MAAA;AAAA,IAGV;AAAA,EACD;AACD;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/adapter-sveltekit",
3
- "version": "0.3.57-alpha.repeatable-link.2",
3
+ "version": "0.3.57-beta.1",
4
4
  "description": "Slice Machine adapter for SvelteKit.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -63,8 +63,8 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@prismicio/simulator": "^0.1.4",
66
- "@prismicio/types-internal": "2.9.0-alpha.3",
67
- "@slicemachine/plugin-kit": "0.4.57-alpha.repeatable-link.2",
66
+ "@prismicio/types-internal": "^2.8.0",
67
+ "@slicemachine/plugin-kit": "0.4.57-beta.1",
68
68
  "common-tags": "^1.8.2",
69
69
  "fp-ts": "^2.13.1",
70
70
  "io-ts": "^2.2.20",
@@ -93,7 +93,7 @@
93
93
  "eslint-plugin-tsdoc": "0.2.17",
94
94
  "prettier": "3.0.3",
95
95
  "prettier-plugin-jsdoc": "1.1.1",
96
- "prismic-ts-codegen": "0.1.23-alpha.0",
96
+ "prismic-ts-codegen": "^0.1.22",
97
97
  "size-limit": "8.2.4",
98
98
  "svelte": "4.2.0",
99
99
  "typescript": "4.9.5",
@@ -57,38 +57,19 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
57
57
  }
58
58
 
59
59
  case "Link": {
60
- const repeat = data.model.config?.repeat ?? false;
61
- const allowText = data.model.config?.allowText ?? false;
62
-
63
- let codeText;
64
- if (!repeat && !allowText) {
65
- codeText = stripIndent`
66
- <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
67
- `;
68
- } else if (!repeat && allowText) {
69
- codeText = stripIndent`
70
- <PrismicLink field={${dotPath(fieldPath)}} />
71
- `;
72
- } else if (repeat && !allowText) {
73
- codeText = stripIndent`
74
- {#each ${dotPath(fieldPath)} as link, index (index)}
75
- <PrismicLink field={link}>Link</PrismicLink>
76
- {/each}
77
- `;
78
- } else if (repeat && allowText) {
79
- codeText = stripIndent`
80
- {#each ${dotPath(fieldPath)} as link, index (index)}
81
- <PrismicLink field={link} />
82
- {/each}
83
- `;
84
- } else {
85
- throw new Error("Invalid configuration.");
86
- }
87
-
88
60
  return {
89
61
  label,
90
62
  language: "svelte",
91
- code: await format(codeText, helpers),
63
+ code: await format(
64
+ data.model.config?.allowText
65
+ ? stripIndent`
66
+ <PrismicLink field={${dotPath(fieldPath)}} />
67
+ `
68
+ : stripIndent`
69
+ <PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
70
+ `,
71
+ helpers,
72
+ ),
92
73
  };
93
74
  }
94
75