Skip to content

Commit

Permalink
Merge pull request #1505 from prismicio/dani/link-variant
Browse files Browse the repository at this point in the history
Link variant
  • Loading branch information
dani-mp authored Jan 10, 2025
2 parents 14beaf1 + 458c2a4 commit bc2d382
Show file tree
Hide file tree
Showing 30 changed files with 367 additions and 142 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"resolutions": {
"connected-next-router/react-redux": "8.0.7",
"react-beautiful-dnd/react-redux": "8.0.7",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"express": "4.20.0"
},
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"dependencies": {
"@prismicio/simulator": "^0.1.4",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@slicemachine/plugin-kit": "workspace:*",
"common-tags": "^1.8.2",
"fp-ts": "^2.13.1",
Expand Down
39 changes: 27 additions & 12 deletions packages/adapter-next/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,48 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
const repeat = data.model.config?.repeat ?? false;
const allowText = data.model.config?.allowText ?? false;

const allowVariants = Boolean(data.model.config?.variants);
const variant = (path: string, prefix: "" | "\n " = "") =>
allowVariants ? `${prefix}className={${path}.variant}` : "";

const path = dotPath(fieldPath);

let code;
if (!repeat && !allowText) {
code = await format(
stripIndent`
<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>
<PrismicNextLink field={${path}} ${variant(path)}>Link</PrismicNextLink>
`,
helpers,
);
} else if (!repeat && allowText) {
code = await format(
stripIndent`
<PrismicNextLink field={${dotPath(fieldPath)}} />
<PrismicNextLink field={${path}} ${variant(path)}/>
`,
helpers,
);
} else if (repeat && !allowText) {
code = stripIndent`
{${dotPath(fieldPath)}.map((link) => (
<PrismicNextLink key={link.key} field={link}>Link</PrismicNextLink>
))}
`;
// We cannot use `format` since this snippet contains invalid syntax.
// Please ensure this snippet is manually formatted correctly.
// Make sure to use spaces instead of tabs.
code = stripIndent`{${path}.map((link) => (
<PrismicNextLink
key={link.key}
field={link}${variant("link", "\n ")}>
Link
</PrismicNextLink>
))}`;
} else if (repeat && allowText) {
code = stripIndent`
{${dotPath(fieldPath)}.map((link) => (
<PrismicNextLink key={link.key} field={link} />
))}
`;
// We cannot use `format` since this snippet contains invalid syntax.
// Please ensure this snippet is manually formatted correctly.
// Make sure to use spaces instead of tabs.
code = stripIndent`{${path}.map((link) => (
<PrismicNextLink
key={link.key}
field={link}${variant("link", "\n ")}
/>
))}`;
} else {
throw new Error("Invalid configuration.");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"dependencies": {
"@prismicio/simulator": "^0.1.4",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@slicemachine/plugin-kit": "workspace:*",
"common-tags": "^1.8.2",
"fp-ts": "^2.13.1",
Expand Down
18 changes: 12 additions & 6 deletions packages/adapter-nuxt/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,31 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
const repeat = data.model.config?.repeat ?? false;
const allowText = data.model.config?.allowText ?? false;

const allowVariants = Boolean(data.model.config?.variants);
const variant = (path: string) =>
allowVariants ? ` :class="${path}.variant"` : "";

const path = dotPath(fieldPath);

let codeText;
if (!repeat && !allowText) {
codeText = stripIndent`
<PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
<PrismicLink :field="${path}"${variant(path)}>Link</PrismicLink>
`;
} else if (!repeat && allowText) {
codeText = stripIndent`
<PrismicLink :field="${dotPath(fieldPath)}" />
<PrismicLink :field="${path}"${variant(path)} />
`;
} else if (repeat && !allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link">Link</PrismicLink>
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")}>Link</PrismicLink>
</template>
`;
} else if (repeat && allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link" />
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")} />
</template>
`;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"dependencies": {
"@prismicio/simulator": "^0.1.4",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@slicemachine/plugin-kit": "workspace:*",
"common-tags": "^1.8.2",
"fp-ts": "^2.13.1",
Expand Down
18 changes: 12 additions & 6 deletions packages/adapter-nuxt2/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,31 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
const repeat = data.model.config?.repeat ?? false;
const allowText = data.model.config?.allowText ?? false;

const allowVariants = Boolean(data.model.config?.variants);
const variant = (path: string) =>
allowVariants ? ` :class="${path}.variant"` : "";

const path = dotPath(fieldPath);

let codeText;
if (!repeat && !allowText) {
codeText = stripIndent`
<PrismicLink :field="${dotPath(fieldPath)}">Link</PrismicLink>
<PrismicLink :field="${path}"${variant(path)}>Link</PrismicLink>
`;
} else if (!repeat && allowText) {
codeText = stripIndent`
<PrismicLink :field="${dotPath(fieldPath)}" />
<PrismicLink :field="${path}"${variant(path)} />
`;
} else if (repeat && !allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link">Link</PrismicLink>
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")}>Link</PrismicLink>
</template>
`;
} else if (repeat && allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link" />
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")} />
</template>
`;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"@prismicio/simulator": "^0.1.4",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@slicemachine/plugin-kit": "workspace:*",
"common-tags": "^1.8.2",
"fp-ts": "^2.13.1",
Expand Down
18 changes: 12 additions & 6 deletions packages/adapter-sveltekit/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,31 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
const repeat = data.model.config?.repeat ?? false;
const allowText = data.model.config?.allowText ?? false;

const allowVariants = Boolean(data.model.config?.variants);
const variant = (path: string) =>
allowVariants ? ` class={${path}.variant}` : "";

const path = dotPath(fieldPath);

let codeText;
if (!repeat && !allowText) {
codeText = stripIndent`
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
<PrismicLink field={${path}}${variant(path)}>Link</PrismicLink>
`;
} else if (!repeat && allowText) {
codeText = stripIndent`
<PrismicLink field={${dotPath(fieldPath)}} />
<PrismicLink field={${path}}${variant(path)} />
`;
} else if (repeat && !allowText) {
codeText = stripIndent`
{#each ${dotPath(fieldPath)} as link (link.key)}
<PrismicLink field={link}>Link</PrismicLink>
{#each ${path} as link (link.key)}
<PrismicLink field={link}${variant("link")}>Link</PrismicLink>
{/each}
`;
} else if (repeat && allowText) {
codeText = stripIndent`
{#each ${dotPath(fieldPath)} as link (link.key)}
<PrismicLink field={link} />
{#each ${path} as link (link.key)}
<PrismicLink field={link}${variant("link")} />
{/each}
`;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"@antfu/ni": "^0.20.0",
"@prismicio/client": "^7.11.0",
"@prismicio/custom-types-client": "2.1.0",
"@prismicio/mocks": "2.5.0",
"@prismicio/types-internal": "3.2.0",
"@prismicio/mocks": "2.8.0",
"@prismicio/types-internal": "3.3.0",
"@segment/analytics-node": "^2.1.2",
"@slicemachine/plugin-kit": "workspace:*",
"cookie": "^1.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/managers/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type FieldAddedSegmentEvent = SegmentEvent<
contentType: "page type" | "custom type" | "slice";
allowText?: boolean;
repeat?: boolean;
variants?: string[];
}
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ it("ignores plugins that implement `custom-type-library:read`", async (ctx) => {
const res = await manager.customTypes.readCustomType({ id: model.id });

expect(res).toStrictEqual({
// TODO: update prismic/mocks
model: { ...model, format: "custom" },
errors: [],
});
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
"devDependencies": {
"@prismicio/mock": "0.3.7",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@size-limit/preset-small-lib": "8.2.4",
"@types/common-tags": "1.8.1",
"@types/fs-extra": "11.0.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/slice-machine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"@emotion/react": "11.11.1",
"@extractus/oembed-extractor": "3.1.8",
"@prismicio/client": "7.11.0",
"@prismicio/editor-fields": "0.4.59",
"@prismicio/editor-support": "0.4.59",
"@prismicio/editor-ui": "0.4.59",
"@prismicio/editor-fields": "0.4.60",
"@prismicio/editor-support": "0.4.60",
"@prismicio/editor-ui": "0.4.60",
"@prismicio/mock": "0.3.3",
"@prismicio/mocks": "2.5.0",
"@prismicio/mocks": "2.8.0",
"@prismicio/simulator": "0.1.4",
"@prismicio/types-internal": "3.2.0",
"@prismicio/types-internal": "3.3.0",
"@radix-ui/react-hover-card": "1.0.6",
"@radix-ui/react-tabs": "1.0.4",
"@reach/menu-button": "0.18.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export function UIDEditor() {
</Box>
<DialogActions>
<DialogCancelButton size="medium" />
<DialogActionButton size="medium" disabled={Boolean(error)}>
<DialogActionButton
type="submit"
size="medium"
disabled={Boolean(error)}
>
Save
</DialogActionButton>
</DialogActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const ConvertLegacySliceAsNewSliceDialog: FC<DialogProps> = ({
<DialogActions>
<DialogCancelButton size="medium" />
<DialogActionButton
type="submit"
size="medium"
loading={isLoading}
disabled={errors && Object.keys(errors).length > 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const ConvertLegacySliceAsNewVariationDialog: FC<DialogProps> = ({
<DialogActions>
<DialogCancelButton size="medium" />
<DialogActionButton
type="submit"
size="medium"
loading={isLoading}
disabled={Object.keys(errors).length > 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const ConvertLegacySliceMergeWithIdenticalDialog: FC<DialogProps> = ({
<DialogActions>
<DialogCancelButton size="medium" />
<DialogActionButton
type="submit"
size="medium"
loading={isLoading}
disabled={Boolean(error)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const RenameVariationModal: FC<RenameVariationModalProps> = ({
<DialogActions>
<DialogCancelButton size="medium" />
<DialogActionButton
type="submit"
size="medium"
loading={isRenaming}
disabled={Boolean(error)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ const AddVariationModal: React.FunctionComponent<{
<Button onClick={handleClose} color="grey">
Cancel
</Button>
<Button loading={isAddingVariation}>Submit</Button>
<Button type="submit" loading={isAddingVariation}>
Submit
</Button>
</Box>
}
close={handleClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Hint: React.FC<HintProps> = ({
if (item.value.config?.allowText ?? false)
snippetCacheKey.push("allowText");
if (item.value.config?.repeat ?? false) snippetCacheKey.push("repeat");
if (Boolean(item.value.config?.variants)) snippetCacheKey.push("variants");
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
Loading

0 comments on commit bc2d382

Please sign in to comment.