diff --git a/.vscode/launch.json b/.vscode/launch.json index cbace349c8..a0270193ac 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,13 @@ "request": "launch", "type": "node-terminal" }, + { + "command": "pnpm run dev live-preview -- --no-turbo", + "cwd": "${workspaceFolder}", + "name": "Run Dev Live Preview", + "request": "launch", + "type": "node-terminal" + }, { "command": "pnpm run dev plugin-cloud-storage", "cwd": "${workspaceFolder}", diff --git a/test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx b/app/live-preview/(pages)/[slug]/page.client.tsx similarity index 67% rename from test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx rename to app/live-preview/(pages)/[slug]/page.client.tsx index 34137c1724..d44ed30fd3 100644 --- a/test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx +++ b/app/live-preview/(pages)/[slug]/page.client.tsx @@ -1,13 +1,13 @@ 'use client' -import type { Page as PageType } from '@/payload-types' - -import { PAYLOAD_SERVER_URL } from '@/app/_api/serverURL' -import { Blocks } from '@/app/_components/Blocks' -import { Hero } from '@/app/_components/Hero' +import { useLivePreview } from '@payloadcms/live-preview-react' import React from 'react' -import { useLivePreview } from '../../../../../../packages/live-preview-react/src' +import type { Page as PageType } from '../../../../test/live-preview/payload-types.js' + +import { PAYLOAD_SERVER_URL } from '../../_api/serverURL.js' +import { Blocks } from '../../_components/Blocks/index.js' +import { Hero } from '../../_components/Hero/index.js' export const PageClient: React.FC<{ page: PageType diff --git a/test/live-preview/next-app/app/(pages)/[slug]/page.tsx b/app/live-preview/(pages)/[slug]/page.tsx similarity index 62% rename from test/live-preview/next-app/app/(pages)/[slug]/page.tsx rename to app/live-preview/(pages)/[slug]/page.tsx index 51292c77e2..11d1bc8d18 100644 --- a/test/live-preview/next-app/app/(pages)/[slug]/page.tsx +++ b/app/live-preview/(pages)/[slug]/page.tsx @@ -1,12 +1,13 @@ -import { fetchDoc } from '@/app/_api/fetchDoc' -import { fetchDocs } from '@/app/_api/fetchDocs' -import { notFound } from 'next/navigation' +import { notFound } from 'next/navigation.js' import React from 'react' -import type { Page } from '../../../payload-types' +import type { Page } from '../../../../test/live-preview/payload-types.js' -import { PageClient } from './page.client' +import { fetchDoc } from '../../_api/fetchDoc.js' +import { fetchDocs } from '../../_api/fetchDocs.js' +import { PageClient } from './page.client.js' +// eslint-disable-next-line no-restricted-exports export default async function Page({ params: { slug = 'home' } }) { let page: Page | null = null diff --git a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx b/app/live-preview/(pages)/posts/[slug]/page.client.tsx similarity index 83% rename from test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx rename to app/live-preview/(pages)/posts/[slug]/page.client.tsx index 0d8af42139..e5c52f8048 100644 --- a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx +++ b/app/live-preview/(pages)/posts/[slug]/page.client.tsx @@ -1,13 +1,13 @@ 'use client' -import type { Post as PostType } from '@/payload-types' - -import { PAYLOAD_SERVER_URL } from '@/app/_api/serverURL' -import { Blocks } from '@/app/_components/Blocks' -import { PostHero } from '@/app/_heros/PostHero' +import { useLivePreview } from '@payloadcms/live-preview-react' import React from 'react' -import { useLivePreview } from '../../../../../../../packages/live-preview-react/src' +import type { Post as PostType } from '../../../../../test/live-preview/payload-types.js' + +import { PAYLOAD_SERVER_URL } from '../../../_api/serverURL.js' +import { Blocks } from '../../../_components/Blocks/index.js' +import { PostHero } from '../../../_heros/PostHero/index.js' export const PostClient: React.FC<{ post: PostType diff --git a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx b/app/live-preview/(pages)/posts/[slug]/page.tsx similarity index 66% rename from test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx rename to app/live-preview/(pages)/posts/[slug]/page.tsx index 08fe0cbee4..91053d2934 100644 --- a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx +++ b/app/live-preview/(pages)/posts/[slug]/page.tsx @@ -1,11 +1,11 @@ -import { notFound } from 'next/navigation' +import { notFound } from 'next/navigation.js' import React from 'react' -import type { Post } from '../../../../payload-types' +import type { Post } from '../../../../../test/live-preview/payload-types.js' -import { fetchDoc } from '../../../_api/fetchDoc' -import { fetchDocs } from '../../../_api/fetchDocs' -import { PostClient } from './page.client' +import { fetchDoc } from '../../../_api/fetchDoc.js' +import { fetchDocs } from '../../../_api/fetchDocs.js' +import { PostClient } from './page.client.js' export default async function Post({ params: { slug = '' } }) { let post: Post | null = null diff --git a/test/live-preview/next-app/app/_api/fetchDoc.ts b/app/live-preview/_api/fetchDoc.ts similarity index 78% rename from test/live-preview/next-app/app/_api/fetchDoc.ts rename to app/live-preview/_api/fetchDoc.ts index e607ec8e22..d1dc1c2a3a 100644 --- a/test/live-preview/next-app/app/_api/fetchDoc.ts +++ b/app/live-preview/_api/fetchDoc.ts @@ -1,16 +1,14 @@ import QueryString from 'qs' -import type { Config } from '../../payload-types' - -import { PAYLOAD_SERVER_URL } from './serverURL' +import { PAYLOAD_SERVER_URL } from './serverURL.js' export const fetchDoc = async (args: { - collection: keyof Config['collections'] + collection: string depth?: number id?: string slug?: string }): Promise => { - const { collection, slug, id, depth = 2 } = args || {} + const { id, slug, collection, depth = 2 } = args || {} const queryString = QueryString.stringify( { @@ -21,11 +19,11 @@ export const fetchDoc = async (args: { ) const doc: T = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}${queryString}`, { - method: 'GET', cache: 'no-store', headers: { 'Content-Type': 'application/json', }, + method: 'GET', }) ?.then((res) => res.json()) ?.then((res) => { diff --git a/test/live-preview/next-app/app/_api/fetchDocs.ts b/app/live-preview/_api/fetchDocs.ts similarity index 67% rename from test/live-preview/next-app/app/_api/fetchDocs.ts rename to app/live-preview/_api/fetchDocs.ts index 4d21de0218..104f5e2586 100644 --- a/test/live-preview/next-app/app/_api/fetchDocs.ts +++ b/app/live-preview/_api/fetchDocs.ts @@ -1,14 +1,12 @@ -import type { Config } from '../../payload-types' +import { PAYLOAD_SERVER_URL } from './serverURL.js' -import { PAYLOAD_SERVER_URL } from './serverURL' - -export const fetchDocs = async (collection: keyof Config['collections']): Promise => { +export const fetchDocs = async (collection: string): Promise => { const docs: T[] = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}?depth=0&limit=100`, { - method: 'GET', cache: 'no-store', headers: { 'Content-Type': 'application/json', }, + method: 'GET', }) ?.then((res) => res.json()) ?.then((res) => { diff --git a/test/live-preview/next-app/app/_api/fetchFooter.ts b/app/live-preview/_api/fetchFooter.ts similarity index 82% rename from test/live-preview/next-app/app/_api/fetchFooter.ts rename to app/live-preview/_api/fetchFooter.ts index b245212563..26b531b620 100644 --- a/test/live-preview/next-app/app/_api/fetchFooter.ts +++ b/app/live-preview/_api/fetchFooter.ts @@ -1,16 +1,16 @@ -import type { Footer } from '../../payload-types' +import type { Footer } from '../../../test/live-preview/payload-types.js' -import { PAYLOAD_SERVER_URL } from './serverURL' +import { PAYLOAD_SERVER_URL } from './serverURL.js' export async function fetchFooter(): Promise