From ff2de13f9965d508eb9171388513d9f4ed57d402 Mon Sep 17 00:00:00 2001 From: Rami Bitar Date: Sat, 6 Jun 2026 18:56:07 -0400 Subject: [PATCH] remove editor routes, these will be served by the platform --- app/about/editor/page.tsx | 6 -- app/collections/[handle]/editor/page.tsx | 6 -- app/editor/page.tsx | 6 -- app/products/[handle]/editor/page.tsx | 6 -- app/search/editor/page.tsx | 6 -- components/page-editor.tsx | 92 ------------------------ lib/use-demo-data.ts | 54 -------------- 7 files changed, 176 deletions(-) delete mode 100644 app/about/editor/page.tsx delete mode 100644 app/collections/[handle]/editor/page.tsx delete mode 100644 app/editor/page.tsx delete mode 100644 app/products/[handle]/editor/page.tsx delete mode 100644 app/search/editor/page.tsx delete mode 100644 components/page-editor.tsx delete mode 100644 lib/use-demo-data.ts diff --git a/app/about/editor/page.tsx b/app/about/editor/page.tsx deleted file mode 100644 index 2540752..0000000 --- a/app/about/editor/page.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import PageEditor from "@/components/page-editor"; -import page from "../page.json"; - -export default function EditorPage() { - return ; -} diff --git a/app/collections/[handle]/editor/page.tsx b/app/collections/[handle]/editor/page.tsx deleted file mode 100644 index b985a15..0000000 --- a/app/collections/[handle]/editor/page.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import PageEditor from "@/components/page-editor"; -import page from "../page.json"; - -export default function EditorPage() { - return ; -} diff --git a/app/editor/page.tsx b/app/editor/page.tsx deleted file mode 100644 index 4339cb0..0000000 --- a/app/editor/page.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import PageEditor from "@/components/page-editor"; -import page from "../page.json"; - -export default function EditorPage() { - return ; -} diff --git a/app/products/[handle]/editor/page.tsx b/app/products/[handle]/editor/page.tsx deleted file mode 100644 index ae62909..0000000 --- a/app/products/[handle]/editor/page.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import PageEditor from "@/components/page-editor"; -import page from "../page.json"; - -export default function EditorPage() { - return ; -} diff --git a/app/search/editor/page.tsx b/app/search/editor/page.tsx deleted file mode 100644 index b2872e1..0000000 --- a/app/search/editor/page.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import PageEditor from "@/components/page-editor"; -import page from "../page.json"; - -export default function EditorPage() { - return ; -} diff --git a/components/page-editor.tsx b/components/page-editor.tsx deleted file mode 100644 index be41d77..0000000 --- a/components/page-editor.tsx +++ /dev/null @@ -1,92 +0,0 @@ -"use client"; - -import { useMemo } from "react"; -import { usePathname, useParams } from "next/navigation"; -import { Editor, blocksPlugin, outlinePlugin } from "@reacteditor/core"; -import createTailwindCdnPlugin from "@reacteditor/plugin-tailwind-cdn"; -import { createShopifyPlugin } from "@reacteditor/plugin-shopify"; -import { mediaPlugin } from "@reacteditor/plugin-media"; -import { mediaAdapter } from "@/lib/adapters/media-adapter"; -import { appConfig } from "@/editor.config"; -import globals from "@/app.globals.json"; -import type { PageData } from "@/components/page-render"; - -/** - * Shared editor for a route. In an editor route's `page.tsx`, import the - * sibling public route's `page.json` and pass it through with the route key: - * - * import page from "../page.json"; - * export default () => ; - * - * `routeKey` is the Next.js app-directory path of the route (e.g. - * "/app/products/[handle]"); the host resolves it to `/page.json` - * to know which file to save. The concrete public path and params are derived - * separately from the live URL. - */ -export default function PageEditor({ - page, - routeKey, -}: { - page: PageData; - routeKey: string; -}) { - const pathname = usePathname() ?? "/editor"; - const params = useParams(); - - // Each editor route is a `.../editor` child of its public route; the - // published path drops that trailing segment. - const path = pathname.replace(/\/editor$/, "") || "/"; - const routeParams: Record = {}; - for (const [key, value] of Object.entries(params ?? {})) { - if (typeof value === "string") routeParams[key] = value; - } - - const data = { root: page.root, content: page.content, globals }; - - const plugins = useMemo( - () => [ - blocksPlugin(), - outlinePlugin(), - mediaPlugin({ - adapter: mediaAdapter, - }), - createTailwindCdnPlugin(), - createShopifyPlugin({ - storeDomain: process.env.NEXT_PUBLIC_SHOPIFY_DOMAIN ?? "mock.shop", - publicAccessToken: - process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN, - }), - ], - [], - ); - - const handlePublish = async (nextData: any, route?: any) => { - // The page we save is always the public route — i.e. the live path with - // the trailing `/editor` segment stripped, never the `.../editor` URL. - const resolved = { - key: routeKey, - params: routeParams, - ...(route ?? {}), - path, - }; - if (typeof window !== "undefined" && window.parent !== window) { - window.parent.postMessage( - { type: "PUBLISH", data: { data: nextData, route: resolved } }, - "*", - ); - } - await new Promise((resolve) => setTimeout(resolve, 1000)); - }; - - return ( -
- -
- ); -} diff --git a/lib/use-demo-data.ts b/lib/use-demo-data.ts deleted file mode 100644 index d7a0ce3..0000000 --- a/lib/use-demo-data.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { useEffect, useState } from "react"; -import config, { componentKey } from "../config"; -import { getInitialData, initialData } from "../config/initial-data"; -import { Metadata, resolveAllData } from "@reacteditor/core"; -import { Components, UserData } from "../config/types"; -import { RootProps } from "../config/root"; - -const isBrowser = typeof window !== "undefined"; - -export const useDemoData = ({ - path, - isEdit, - metadata = {}, -}: { - path: string; - isEdit: boolean; - metadata?: Metadata; -}) => { - // unique b64 key that updates each time we add / remove components - const key = `react-editor-demo:${componentKey}:${path}`; - - const [data] = useState>(() => { - if (isBrowser) { - const dataStr = localStorage.getItem(key); - - if (dataStr) { - return JSON.parse(dataStr); - } - - return getInitialData(path); - } - }); - - // Normally this would happen on the server, but we can't - // do that because we're using local storage as a database - const [resolvedData, setResolvedData] = useState>(data); - - useEffect(() => { - if (data && !isEdit) { - resolveAllData(data, config, metadata).then( - setResolvedData - ); - } - }, [data, isEdit]); - - useEffect(() => { - if (!isEdit) { - const title = data?.root?.props?.title || data?.root?.title; - document.title = title || ""; - } - }, [data, isEdit]); - - return { data, resolvedData, key }; -};