From b4435b11ef2d9013913768a32148b3a76d06a5cc Mon Sep 17 00:00:00 2001 From: Jeff See Date: Thu, 18 May 2023 13:09:44 -0700 Subject: [PATCH 1/4] Add vercel edit info data attribute --- components/blocks-renderer.tsx | 4 ++-- package.json | 1 + pages/[filename].tsx | 25 ++++++++++++++++++++++++- yarn.lock | 13 +++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/components/blocks-renderer.tsx b/components/blocks-renderer.tsx index fa52f9d2..ee50c3ed 100644 --- a/components/blocks-renderer.tsx +++ b/components/blocks-renderer.tsx @@ -3,7 +3,7 @@ import { Content } from "./blocks/content"; import { Features } from "./blocks/features"; import { Hero } from "./blocks/hero"; import { Testimonial } from "./blocks/testimonial"; -import { tinaField } from "tinacms/dist/react"; +import { vercelEditInfo } from "@tinacms/vercel-previews"; export const Blocks = (props: Omit) => { return ( @@ -11,7 +11,7 @@ export const Blocks = (props: Omit) => { {props.blocks ? props.blocks.map(function (block, i) { return ( -
+
); diff --git a/package.json b/package.json index b686796e..5cc41484 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "dependencies": { "@headlessui/react": "1.7.5", "@tailwindcss/typography": "^0.5.8", + "@tinacms/vercel-previews": "^0.0.1", "date-fns": "^2.23.0", "next": "^13.3.1", "react": "^18.2.0", diff --git a/pages/[filename].tsx b/pages/[filename].tsx index 4fba4513..f93e9e98 100644 --- a/pages/[filename].tsx +++ b/pages/[filename].tsx @@ -4,11 +4,34 @@ import { Blocks } from "../components/blocks-renderer"; import { useTina } from "tinacms/dist/react"; import { Layout } from "../components/layout"; import { client } from "../tina/__generated__/client"; +import { useVisualEditing } from "@tinacms/vercel-previews"; export default function HomePage( props: InferGetStaticPropsType ) { - const { data } = useTina(props); + const { data: tinaData } = useTina(props); + const data = useVisualEditing({ + data: tinaData, + // metadata is derived from the query and variables + query: props.query, + variables: props.variables, + // When clicking on an editable element for the first time, redirect to the TinaCMS app + redirect: "/admin", + // Only enable visual editing on preview deploys + enabled: true, + // stringEncoding automatically adds metadata to strings + stringEncoding: false, + // Alternatively, you can skip some strings from being encoded + // stringEncoding: { + // skipPaths: (path) => { + // if ('page.blocks.0.image' === path) { + // return true + // } + + // return false + // } + // } + }); return ( diff --git a/yarn.lock b/yarn.lock index 601c40f7..d15ae4e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2610,6 +2610,14 @@ slate-react "^0.81.0" webfontloader "1.6.28" +"@tinacms/vercel-previews@^0.0.1": + version "0.0.1" + resolved "https://registry.yarnpkg.com/@tinacms/vercel-previews/-/vercel-previews-0.0.1.tgz#f595ab9c2b4e68faa9fd4b63c74c1bdce5409cdc" + integrity sha512-74hS/J2uZmKz06NluE4/0SZNsWwfhGT7TSE4QfGZi17NC10dCeTT1bHTekmAPW5a6glNUw0dJcau3LLNtIX9pg== + dependencies: + "@vercel/stega" "^0.0.4" + tinacms "1.5.6" + "@trysound/sax@0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" @@ -3266,6 +3274,11 @@ immer "^9.0.6" react-tracked "^1.7.9" +"@vercel/stega@^0.0.4": + version "0.0.4" + resolved "https://registry.yarnpkg.com/@vercel/stega/-/stega-0.0.4.tgz#1c44ec91d9eda78b4803b95502413d7120e80d51" + integrity sha512-4c9AibBOJ9oGvvev0f5QFbdcDPmOjkxdlrKb5Y70DnAc0ThtFujod8DRGA/RLFQ5lAvgRTdpvoczl8GhHuxFJQ== + "@vitejs/plugin-react@3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@vitejs/plugin-react/-/plugin-react-3.1.0.tgz#d1091f535eab8b83d6e74034d01e27d73c773240" From eb0348a7c9e98b5799b2b5b2a6e4ff0cec753a08 Mon Sep 17 00:00:00 2001 From: Jeff See Date: Thu, 18 May 2023 13:19:00 -0700 Subject: [PATCH 2/4] Use vercelEditInfo helper --- components/blocks/content.tsx | 4 ++-- components/blocks/features.tsx | 10 +++++----- components/blocks/hero.tsx | 10 +++++----- components/blocks/testimonial.tsx | 6 +++--- components/layout/header.tsx | 10 ++++++---- components/posts/post.tsx | 16 ++++++++-------- components/util/actions.tsx | 6 +++--- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/components/blocks/content.tsx b/components/blocks/content.tsx index e0ccdf4c..6e1dcfa0 100644 --- a/components/blocks/content.tsx +++ b/components/blocks/content.tsx @@ -4,7 +4,7 @@ import { Section } from "../util/section"; import { TinaMarkdown } from "tinacms/dist/rich-text"; import type { TinaTemplate } from "tinacms"; import { PageBlocksContent } from "../../tina/__generated__/types"; -import { tinaField } from "tinacms/dist/react"; +import { vercelEditInfo } from "@tinacms/vercel-previews"; export const Content = ({ data }: { data: PageBlocksContent }) => { return ( @@ -13,7 +13,7 @@ export const Content = ({ data }: { data: PageBlocksContent }) => { className={`prose prose-lg ${ data.color === "primary" ? `prose-primary` : `dark:prose-dark` }`} - data-tina-field={tinaField(data, "body")} + data-vercel-edit-info={vercelEditInfo(data, "body")} size="large" width="medium" > diff --git a/components/blocks/features.tsx b/components/blocks/features.tsx index 70c59fa1..fe160c16 100644 --- a/components/blocks/features.tsx +++ b/components/blocks/features.tsx @@ -6,7 +6,7 @@ import { PageBlocksFeatures, PageBlocksFeaturesItems, } from "../../tina/__generated__/types"; -import { tinaField } from "tinacms/dist/react"; +import { vercelEditInfo } from "@tinacms/vercel-previews"; export const Feature = ({ featuresColor, @@ -17,20 +17,20 @@ export const Feature = ({ }) => { return (
{data.icon && ( )} {data.title && (

{data.title} @@ -38,7 +38,7 @@ export const Feature = ({ )} {data.text && (

{data.text} diff --git a/components/blocks/hero.tsx b/components/blocks/hero.tsx index 055f4c08..8d11af17 100644 --- a/components/blocks/hero.tsx +++ b/components/blocks/hero.tsx @@ -6,7 +6,7 @@ import { useTheme } from "../layout"; import { TinaMarkdown } from "tinacms/dist/rich-text"; import type { TinaTemplate } from "tinacms"; import { PageBlocksHero } from "../../tina/__generated__/types"; -import { tinaField } from "tinacms/dist/react"; +import { vercelEditInfo } from "@tinacms/vercel-previews"; export const Hero = ({ data }: { data: PageBlocksHero }) => { const theme = useTheme(); @@ -30,7 +30,7 @@ export const Hero = ({ data }: { data: PageBlocksHero }) => {

{data.tagline && (

{data.tagline} @@ -39,7 +39,7 @@ export const Hero = ({ data }: { data: PageBlocksHero }) => { )} {data.headline && (

{ )} {data.text && (
{
{data.image && (
{ return ( @@ -23,7 +23,7 @@ export const Testimonial = ({ data }: { data: PageBlocksTestimonial }) => { “

{data.quote} @@ -45,7 +45,7 @@ export const Testimonial = ({ data }: { data: PageBlocksTestimonial }) => {

{ @@ -73,7 +73,7 @@ export const Header = ({ data }: { data: GlobalHeader }) => { className="flex gap-1 items-center whitespace-nowrap tracking-[.002em]" > { style: data.icon.style, }} /> - {data.name} + + {data.name} +

    @@ -99,7 +101,7 @@ export const Header = ({ data }: { data: GlobalHeader }) => { }`} > {

    {

    {props.author && ( <>
    {props.author.name}

    {props.author.name} @@ -175,7 +175,7 @@ export const Post = (props: PostType) => { )}

    {formattedDate} @@ -185,7 +185,7 @@ export const Post = (props: PostType) => { {props.heroImg && (

    { )}
    diff --git a/components/util/actions.tsx b/components/util/actions.tsx index 39be6d02..50269e1c 100644 --- a/components/util/actions.tsx +++ b/components/util/actions.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import { BiRightArrowAlt } from "react-icons/bi"; import { useTheme } from "../layout"; import { PageBlocksHeroActions } from "../../tina/__generated__/types"; -import { tinaField } from "tinacms/dist/react"; +import { vercelEditInfo } from "@tinacms/vercel-previews"; export const Actions = ({ parentColor = "default", @@ -69,7 +69,7 @@ export const Actions = ({ element = (