Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prismicio/slice-machine
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4237a136ff93ee5089ce823d103372beb20da254
Choose a base ref
..
head repository: prismicio/slice-machine
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b53b2f68143336192b5ff94dc3e8c985b356d6ee
Choose a head ref
Showing with 318 additions and 55 deletions.
  1. +1 −1 e2e-projects/next-upgrade/package.json
  2. +2 −4 e2e-projects/next-upgrade/slicemachine.config.json
  3. +1 −1 e2e-projects/next/package.json
  4. +1 −1 e2e-projects/sveltekit/package.json
  5. +1 −1 packages/adapter-next/package.json
  6. +1 −1 packages/adapter-nuxt/package.json
  7. +1 −1 packages/adapter-nuxt2/package.json
  8. +1 −1 packages/adapter-sveltekit/package.json
  9. +1 −1 packages/init/package.json
  10. +1 −1 packages/manager/package.json
  11. +1 −0 packages/manager/src/lib/decodeSliceMachineConfig.ts
  12. +1 −0 packages/manager/src/types.ts
  13. +1 −1 packages/plugin-kit/package.json
  14. +1 −0 packages/plugin-kit/src/lib/decodeSliceMachineConfig.ts
  15. +1 −0 packages/plugin-kit/src/types.ts
  16. +18 −7 packages/slice-machine/lib/builders/CustomTypeBuilder/SliceZone/List.tsx
  17. +1 −1 packages/slice-machine/package.json
  18. +1 −0 packages/slice-machine/pages/labs.tsx
  19. +71 −0 packages/slice-machine/src/features/labs/labsList/LabsList.tsx
  20. +36 −0 packages/slice-machine/src/features/labs/labsList/LabsListItem.tsx
  21. +70 −0 packages/slice-machine/src/features/labs/labsList/LabsPage.tsx
  22. +32 −0 packages/slice-machine/src/features/labs/labsList/useLab.tsx
  23. +4 −1 packages/slice-machine/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewSliceDialog.tsx
  24. +4 −1 ...s/slice-machine/src/features/slices/convertLegacySlice/ConvertLegacySliceAsNewVariationDialog.tsx
  25. +4 −1 ...ice-machine/src/features/slices/convertLegacySlice/ConvertLegacySliceMergeWithIdenticalDialog.tsx
  26. +32 −29 packages/slice-machine/src/features/slices/sliceCards/NonSharedSliceViewCard.tsx
  27. +24 −0 packages/slice-machine/src/hooks/useSliceMachineConfig.ts
  28. +1 −1 packages/start-slicemachine/package.json
  29. +4 −0 packages/start-slicemachine/src/lib/createSliceMachineExpressApp.ts
2 changes: 1 addition & 1 deletion e2e-projects/next-upgrade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-upgrade",
"version": "1.14.1-dev-next-release.2",
"version": "1.17.0",
"private": true,
"scripts": {
"dev": "next dev",
6 changes: 2 additions & 4 deletions e2e-projects/next-upgrade/slicemachine.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"repositoryName": "upgrade-optimize-full-legacy",
"adapter": "@slicemachine/adapter-next",
"libraries": [
"./slices"
],
"libraries": ["./slices"],
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}
}
2 changes: 1 addition & 1 deletion e2e-projects/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cimsirp",
"version": "1.16.1-dev-next-release.3",
"version": "1.17.0",
"private": true,
"scripts": {
"dev": "next dev",
2 changes: 1 addition & 1 deletion e2e-projects/sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit",
"version": "1.16.1-dev-next-release.3",
"version": "1.17.0",
"private": true,
"scripts": {
"dev": "vite dev",
2 changes: 1 addition & 1 deletion packages/adapter-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-next",
"version": "0.3.20-dev-next-release.3",
"version": "0.3.20",
"description": "Slice Machine adapter for Next.js.",
"keywords": [
"typescript",
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-nuxt",
"version": "0.3.20-dev-next-release.3",
"version": "0.3.20",
"description": "Slice Machine adapter for Nuxt 3.",
"keywords": [
"typescript",
2 changes: 1 addition & 1 deletion packages/adapter-nuxt2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-nuxt2",
"version": "0.3.20-dev-next-release.3",
"version": "0.3.20",
"description": "Slice Machine adapter for Nuxt 2.",
"keywords": [
"typescript",
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-sveltekit",
"version": "0.3.20-dev-next-release.3",
"version": "0.3.20",
"description": "Slice Machine adapter for SvelteKit.",
"keywords": [
"typescript",
2 changes: 1 addition & 1 deletion packages/init/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/init",
"version": "2.7.3-dev-next-release.3",
"version": "2.8.0",
"description": "Init Prismic Slice Machine in your project",
"keywords": [
"typescript",
2 changes: 1 addition & 1 deletion packages/manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/manager",
"version": "0.13.1-dev-next-release.3",
"version": "0.14.0",
"description": "Manage all aspects of a Slice Machine project.",
"repository": {
"type": "git",
1 change: 1 addition & 0 deletions packages/manager/src/lib/decodeSliceMachineConfig.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const SliceMachineConfigCodec = t.intersection([
libraries: t.array(t.string),
localSliceSimulatorURL: t.string,
plugins: t.array(SliceMachineConfigPluginRegistrationCodec),
labs: t.partial({ legacySliceUpgrader: t.boolean }),
}),
]);

1 change: 1 addition & 0 deletions packages/manager/src/types.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ export type SliceMachineConfig = {
libraries?: string[];
adapter: SliceMachineConfigPluginRegistration;
plugins?: SliceMachineConfigPluginRegistration[];
labs?: { legacySliceUpgrader?: boolean };
};

export type OnlyHookErrors<
2 changes: 1 addition & 1 deletion packages/plugin-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/plugin-kit",
"version": "0.4.20-dev-next-release.3",
"version": "0.4.20",
"description": "A set of helpers to develop and run Slice Machine plugins",
"keywords": [
"typescript",
1 change: 1 addition & 0 deletions packages/plugin-kit/src/lib/decodeSliceMachineConfig.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const SliceMachineConfigCodec = t.intersection([
libraries: t.array(t.string),
localSliceSimulatorURL: t.string,
plugins: t.array(SliceMachineConfigPluginRegistrationCodec),
labs: t.partial({ legacySliceUpgrader: t.boolean }),
}),
]);

1 change: 1 addition & 0 deletions packages/plugin-kit/src/types.ts
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ export type SliceMachineConfig = {
libraries?: string[];
adapter: SliceMachineConfigPluginRegistration;
plugins?: SliceMachineConfigPluginRegistration[];
labs?: { legacySliceUpgrader?: boolean };
};

/**
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import { CustomTypeFormat } from "@slicemachine/manager";
import { CUSTOM_TYPES_MESSAGES } from "@src/features/customTypes/customTypesMessages";
import { NonSharedSliceViewCard } from "@src/features/slices/sliceCards/NonSharedSliceViewCard";
import { SharedSliceViewCard } from "@src/features/slices/sliceCards/SharedSliceViewCard";
import { useLab } from "@src/features/labs/labsList/useLab";

interface SlicesListProps {
format: CustomTypeFormat;
@@ -33,17 +34,27 @@ export const SlicesList: React.FC<SlicesListProps> = ({
const hasLegacySlices = slices.some((slice) => slice.type !== "SharedSlice");
const customTypesMessages = CUSTOM_TYPES_MESSAGES[format];

const [legacySliceUpgraderLab] = useLab("legacySliceUpgrader");

const { openToaster } = useSliceMachineActions();

useEffect(() => {
if (hasLegacySlices)
openToaster(
`This ${customTypesMessages.name({
start: false,
plural: false,
})} contains legacy slices that can be upgraded.`,
ToasterType.INFO
);
legacySliceUpgraderLab.enabled
? openToaster(
`This ${customTypesMessages.name({
start: false,
plural: false,
})} contains legacy slices that can be upgraded.`,
ToasterType.INFO
)
: openToaster(
`This ${customTypesMessages.name({
start: false,
plural: false,
})} contains slices that are incompatible.`,
ToasterType.WARNING
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasLegacySlices]);

2 changes: 1 addition & 1 deletion packages/slice-machine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slice-machine-ui",
"version": "1.16.1-dev-next-release.3",
"version": "1.17.0",
"license": "MIT",
"description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.",
"repository": {
1 change: 1 addition & 0 deletions packages/slice-machine/pages/labs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LabsPage as default } from "@src/features/labs/labsList/LabsPage";
71 changes: 71 additions & 0 deletions packages/slice-machine/src/features/labs/labsList/LabsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { FC } from "react";
import { Box, Text } from "@prismicio/editor-ui";

import useSliceMachineActions from "@src/modules/useSliceMachineActions";
import { ToasterType } from "@src/modules/toaster";

import { LabsListItem } from "./LabsListItem";
import { type UseLabArgs, type UseLabReturnType, useLab } from "./useLab";

export const LabsList: FC = () => {
const [legacySliceUpgraderLab, setLegacySliceUpgraderLab] = useLabWithToast(
"legacySliceUpgrader",
"Legacy Slice Upgrader"
);

return (
<Box flexDirection="column" gap={32}>
<header>
<Text variant="normal">
Slice Machine Labs gives you early access to new features before
they're widely released. Experimental features are works-in-progress
and potentially unstable, so you may find some bugs and breaking
changes along the way.
</Text>
</header>
<Box flexDirection="column" gap={16}>
<LabsListItem
title="Legacy Slice Upgrader"
enabled={legacySliceUpgraderLab.enabled}
onToggle={(enabled) => void setLegacySliceUpgraderLab(enabled)}
>
The Legacy Slice Upgrader allows you to convert old slices (legacy and
composite slices) to slices managed by Slice Machine (shared slices).
This feature is experimental, and we strongly recommend that you test
it with a{" "}
<a href="https://prismic.io/docs/environments" target="_blank">
Prismic environment
</a>{" "}
or you'll be at risk of losing past content.
</LabsListItem>
</Box>
</Box>
);
};

function useLabWithToast(key: UseLabArgs, name: string): UseLabReturnType {
const { openToaster } = useSliceMachineActions();
const [lab, setLab] = useLab(key);

const setLabWithToast = async (enabled: boolean) => {
try {
await setLab(enabled);

openToaster(
enabled ? `Labs: enabled ${name}` : `Labs: disabled ${name}`,
ToasterType.SUCCESS
);
} catch (error) {
console.error(error);

openToaster(
enabled
? `Labs: failed to enable ${name}`
: `Labs: failed to disable ${name}`,
ToasterType.ERROR
);
}
};

return [lab, setLabWithToast];
}
36 changes: 36 additions & 0 deletions packages/slice-machine/src/features/labs/labsList/LabsListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { type FC, type PropsWithChildren } from "react";
import { Switch, Box, Card, Icon, Text } from "@prismicio/editor-ui";

type LabsListItemProps = PropsWithChildren<{
title: string;
enabled: boolean;
onToggle: (enabled: boolean) => void;
}>;

export const LabsListItem: FC<LabsListItemProps> = ({
title,
enabled,
onToggle,
children,
}) => {
return (
<Card variant="outlined" style={{ padding: 0 }}>
<Box gap={8} padding={16}>
<Box padding={{ top: 6 }}>
<Icon name="viewDay" size="medium" color="grey11" />
</Box>
<Box flexDirection="column" flexGrow={1}>
<Text variant="h3">{title}</Text>
<Text variant="normal">{children}</Text>
</Box>
<Box width={128} justifyContent="end">
<Switch
size="medium"
checked={enabled}
onCheckedChange={(checked) => onToggle(checked)}
/>
</Box>
</Box>
</Card>
);
};
70 changes: 70 additions & 0 deletions packages/slice-machine/src/features/labs/labsList/LabsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { type FC, ReactNode, Suspense } from "react";
import {
ErrorBoundary,
Box,
ProgressCircle,
DefaultErrorMessage,
} from "@prismicio/editor-ui";
import Head from "next/head";

import {
AppLayout,
AppLayoutBreadcrumb,
AppLayoutContent,
AppLayoutHeader,
} from "@components/AppLayout";

import { LabsList } from "./LabsList";

export const LabsPage: FC = () => {
return (
<>
<Head>
<title>Labs - Slice Machine</title>
</Head>
<ErrorBoundary
renderError={() => (
<LabsPageLayout>
<Box alignItems="center" justifyContent="center">
<DefaultErrorMessage
title="Request failed"
description="An error occurred while fetching your labs configuration."
/>
</Box>
</LabsPageLayout>
)}
>
<Suspense
fallback={
<LabsPageLayout withHeader>
<ProgressCircle />
</LabsPageLayout>
}
>
<LabsPageLayout withHeader>
<LabsList />
</LabsPageLayout>
</Suspense>
</ErrorBoundary>
</>
);
};

type LabsPageLayoutProps = {
children: ReactNode;
withHeader?: boolean;
};

const LabsPageLayout: FC<LabsPageLayoutProps> = ({
children,
withHeader = false,
}) => (
<AppLayout>
{withHeader ? (
<AppLayoutHeader>
<AppLayoutBreadcrumb folder="Labs" />
</AppLayoutHeader>
) : null}
<AppLayoutContent>{children}</AppLayoutContent>
</AppLayout>
);
32 changes: 32 additions & 0 deletions packages/slice-machine/src/features/labs/labsList/useLab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { SliceMachineConfig } from "@slicemachine/manager";

import { useSliceMachineConfig } from "@src/hooks/useSliceMachineConfig";

export type UseLabArgs = keyof Required<SliceMachineConfig>["labs"];

export type UseLabReturnType = [
lab: { enabled: boolean },
setLab: (enabled: boolean) => Promise<void>
];

export function useLab(key: UseLabArgs): UseLabReturnType {
const [config, setConfig] = useSliceMachineConfig();

const setLab = async (enabled: boolean) => {
const updatedConfig = { ...config, labs: { ...config.labs } };

if (enabled) {
updatedConfig.labs[key] = enabled;
} else if (key in updatedConfig.labs) {
delete updatedConfig.labs[key];
}

if (Object.keys(updatedConfig.labs).length === 0) {
delete (updatedConfig as SliceMachineConfig).labs;
}

await setConfig(updatedConfig);
};

return [{ enabled: config?.labs?.[key] ?? false }, setLab];
}
Loading