Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: Add additional page for fixtures (#2819)
Ivan Starkovb31738b586e1
diff --git a/fixtures/webstudio-custom-template/.webstudio/data.json b/fixtures/webstudio-custom-template/.webstudio/data.jsonindex 03101de319..3361e78a1e 100644--- a/fixtures/webstudio-custom-template/.webstudio/data.json+++ b/fixtures/webstudio-custom-template/.webstudio/data.json@@ -1,16 +1,19 @@{"build": {- "id": "33b9a2ff-ce2f-499d-8e9d-121dc35dab8f",+ "id": "b1ec8e54-bf8c-4b76-80cc-df31eb4fd2db","projectId": "0d856812-61d8-4014-a20a-82e01c0eb8ee",- "version": 22,- "createdAt": "2023-11-05T17:42:09.984Z",- "updatedAt": "2023-11-05T17:42:09.984Z",+ "version": 44,+ "createdAt": "2024-01-23T14:21:27.697Z",+ "updatedAt": "2024-01-23T14:21:27.697Z","pages": {"meta": {"siteName": "Fixture Site","faviconAssetId": "cd1e9fad-8df1-45c6-800f-05fda2d2469f","code": "<script>console.log('HELLO')</script>\n<meta property=\"saas:test\" content=\"test\">"},+ "settings": {+ "atomicStyles": true+ },"homePage": {"id": "nfzls_SkTc9jKYyxcZ8Lw","name": "Home",@@ -21,13 +24,32 @@"rootInstanceId": "ibXgMoi9_ipHx1gVrvii0","path": ""},- "pages": [],+ "pages": [+ {+ "id": "xT46WZKzCBTvUCIObMELW",+ "name": "Script Test",+ "title": "Script Test",+ "meta": {+ "description": "",+ "excludePageFromSearch": false,+ "socialImageAssetId": "",+ "custom": [+ {+ "property": "",+ "content": ""+ }+ ]+ },+ "rootInstanceId": "LW98_-srDnnagkR10lsk4",+ "path": "/script-test"+ }+ ],"folders": [{"id": "root","name": "Root","slug": "",- "children": ["nfzls_SkTc9jKYyxcZ8Lw"]+ "children": ["nfzls_SkTc9jKYyxcZ8Lw", "xT46WZKzCBTvUCIObMELW"]}]},@@ -77,6 +99,110 @@"value": 4}}+ ],+ [+ "3h7-JvfKemCCCAoHL0Y5s:mIDIDBHsdlix3RVZAVmv7:marginTop:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "3h7-JvfKemCCCAoHL0Y5s",+ "property": "marginTop",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "3h7-JvfKemCCCAoHL0Y5s:mIDIDBHsdlix3RVZAVmv7:marginBottom:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "3h7-JvfKemCCCAoHL0Y5s",+ "property": "marginBottom",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "3h7-JvfKemCCCAoHL0Y5s:mIDIDBHsdlix3RVZAVmv7:marginRight:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "3h7-JvfKemCCCAoHL0Y5s",+ "property": "marginRight",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "3h7-JvfKemCCCAoHL0Y5s:mIDIDBHsdlix3RVZAVmv7:marginLeft:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "3h7-JvfKemCCCAoHL0Y5s",+ "property": "marginLeft",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "mOA5iiy4M-QrmmO22O02y:mIDIDBHsdlix3RVZAVmv7:marginTop:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "mOA5iiy4M-QrmmO22O02y",+ "property": "marginTop",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "mOA5iiy4M-QrmmO22O02y:mIDIDBHsdlix3RVZAVmv7:marginRight:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "mOA5iiy4M-QrmmO22O02y",+ "property": "marginRight",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "mOA5iiy4M-QrmmO22O02y:mIDIDBHsdlix3RVZAVmv7:marginBottom:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "mOA5iiy4M-QrmmO22O02y",+ "property": "marginBottom",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }+ ],+ [+ "mOA5iiy4M-QrmmO22O02y:mIDIDBHsdlix3RVZAVmv7:marginLeft:",+ {+ "breakpointId": "mIDIDBHsdlix3RVZAVmv7",+ "styleSourceId": "mOA5iiy4M-QrmmO22O02y",+ "property": "marginLeft",+ "value": {+ "type": "unit",+ "unit": "px",+ "value": 15+ }+ }]],"styleSources": [@@ -86,6 +212,20 @@"type": "local","id": "NfeivFkbA_acBLVg7dn9P"}+ ],+ [+ "3h7-JvfKemCCCAoHL0Y5s",+ {+ "type": "local",+ "id": "3h7-JvfKemCCCAoHL0Y5s"+ }+ ],+ [+ "mOA5iiy4M-QrmmO22O02y",+ {+ "type": "local",+ "id": "mOA5iiy4M-QrmmO22O02y"+ }]],"styleSourceSelections": [@@ -95,9 +235,44 @@"instanceId": "7pwqBSgrfuuOfk1JblWcL","values": ["NfeivFkbA_acBLVg7dn9P"]}+ ],+ [+ "LW98_-srDnnagkR10lsk4",+ {+ "instanceId": "LW98_-srDnnagkR10lsk4",+ "values": ["3h7-JvfKemCCCAoHL0Y5s"]+ }+ ],+ [+ "ibXgMoi9_ipHx1gVrvii0",+ {+ "instanceId": "ibXgMoi9_ipHx1gVrvii0",+ "values": ["mOA5iiy4M-QrmmO22O02y"]+ }+ ]+ ],+ "props": [+ [+ "FbOz0nU4WCUd8WVU-Zit_",+ {+ "id": "FbOz0nU4WCUd8WVU-Zit_",+ "instanceId": "QzTSoZnbGD6luZ5xcv893",+ "name": "href",+ "type": "page",+ "value": "xT46WZKzCBTvUCIObMELW"+ }+ ],+ [+ "9gSir7lU2Gr0wxmjoUH5F",+ {+ "id": "9gSir7lU2Gr0wxmjoUH5F",+ "instanceId": "8MXByradrqVRiGSyHI0aH",+ "name": "href",+ "type": "page",+ "value": "nfzls_SkTc9jKYyxcZ8Lw"+ }]],- "props": [],"dataSources": [],"resources": [],"instances": [@@ -111,6 +286,10 @@{"type": "id","value": "7pwqBSgrfuuOfk1JblWcL"+ },+ {+ "type": "id",+ "value": "QzTSoZnbGD6luZ5xcv893"}]}@@ -128,6 +307,66 @@}]}+ ],+ [+ "LW98_-srDnnagkR10lsk4",+ {+ "type": "instance",+ "id": "LW98_-srDnnagkR10lsk4",+ "component": "Body",+ "children": [+ {+ "type": "id",+ "value": "SHXddDLFWST_sy44UfGQO"+ },+ {+ "type": "id",+ "value": "8MXByradrqVRiGSyHI0aH"+ }+ ]+ }+ ],+ [+ "SHXddDLFWST_sy44UfGQO",+ {+ "type": "instance",+ "id": "SHXddDLFWST_sy44UfGQO",+ "component": "Heading",+ "children": [+ {+ "type": "text",+ "value": "Script Test"+ }+ ]+ }+ ],+ [+ "QzTSoZnbGD6luZ5xcv893",+ {+ "type": "instance",+ "id": "QzTSoZnbGD6luZ5xcv893",+ "component": "Link",+ "children": [+ {+ "type": "text",+ "value": "Goto Script Test"+ }+ ]+ }+ ],+ [+ "8MXByradrqVRiGSyHI0aH",+ {+ "type": "instance",+ "id": "8MXByradrqVRiGSyHI0aH",+ "component": "Link",+ "children": [+ {+ "type": "text",+ "value": "Go Home"+ }+ ]+ }]],"deployment": {@@ -155,6 +394,24 @@},"rootInstanceId": "ibXgMoi9_ipHx1gVrvii0","path": ""+ },+ {+ "id": "xT46WZKzCBTvUCIObMELW",+ "name": "Script Test",+ "title": "Script Test",+ "meta": {+ "description": "",+ "excludePageFromSearch": false,+ "socialImageAssetId": "",+ "custom": [+ {+ "property": "",+ "content": ""+ }+ ]+ },+ "rootInstanceId": "LW98_-srDnnagkR10lsk4",+ "path": "/script-test"}],"assets": [diff --git a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsx b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsxnew file mode 100644index 0000000000..05e605bec5--- /dev/null+++ b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.server.tsx@@ -0,0 +1,4 @@+type Params = Record<string, string | undefined>;+export const loadResources = async (_props: { params: Params }) => {+ return {} as Record<string, unknown>;+};diff --git a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsxnew file mode 100644index 0000000000..ff55483bb6--- /dev/null+++ b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx@@ -0,0 +1,86 @@+/* eslint-disable */+/* This is a auto generated file for building the project */++import { Fragment, useState } from "react";+import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";+import { useResource } from "@webstudio-is/react-sdk";+import {+ Body as Body,+ Link as Link,+} from "@webstudio-is/sdk-components-react-remix";+import { Heading as Heading } from "@webstudio-is/sdk-components-react";++import type { PageData } from "~/routes/_index";+export const fontAssets: Asset[] = [];+export const imageAssets: ImageAsset[] = [+ {+ id: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",+ name: "home_wsKvRSqvkajPPBeycZ-C8.svg",+ description: null,+ projectId: "0d856812-61d8-4014-a20a-82e01c0eb8ee",+ size: 3350,+ type: "image",+ format: "svg",+ createdAt: "2023-10-30T20:35:47.113Z",+ meta: { width: 16, height: 16 },+ },+];+export const pageData: PageData = {+ project: {+ siteName: "Fixture Site",+ faviconAssetId: "cd1e9fad-8df1-45c6-800f-05fda2d2469f",+ code: '<script>console.log(\'HELLO\')</script>\n<meta property="saas:test" content="test">',+ },+ page: {+ id: "xT46WZKzCBTvUCIObMELW",+ name: "Script Test",+ title: "Script Test",+ meta: {+ description: "",+ excludePageFromSearch: false,+ socialImageAssetId: "",+ custom: [{ property: "", content: "" }],+ },+ rootInstanceId: "LW98_-srDnnagkR10lsk4",+ path: "/script-test",+ },+};+export const user: { email: string | null } | undefined = {+ email: "[email protected]",+};+export const projectId = "0d856812-61d8-4014-a20a-82e01c0eb8ee";++type Params = Record<string, string | undefined>;+const Page = (_props: { params: Params }) => {+ return (+ <Body+ data-ws-id="LW98_-srDnnagkR10lsk4"+ data-ws-component="Body"+ className="c1vynykc c122cnm9 c15qd3jj c1jp5sfs"+ >+ <Heading data-ws-id="SHXddDLFWST_sy44UfGQO" data-ws-component="Heading">+ {"Script Test"}+ </Heading>+ <Link+ data-ws-id="8MXByradrqVRiGSyHI0aH"+ data-ws-component="Link"+ href={"/"}+ >+ {"Go Home"}+ </Link>+ </Body>+ );+};++export { Page };++export const getRemixParams = ({ ...params }: Params): Params => {+ return params;+};++export const pagesPaths = new Set(["", "/script-test"]);++export const formsProperties = new Map<+ string,+ { method?: string; action?: string }+>([]);diff --git a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].tsindex 22f3662444..1deab4b859 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts+++ b/fixtures/webstudio-custom-template/app/__generated__/[sitemap.xml].ts@@ -2,7 +2,11 @@ export const sitemap = {pages: [{path: "",- lastModified: "2023-11-05T17:42:09.984Z",+ lastModified: "2024-01-23T14:21:27.697Z",+ },+ {+ path: "/script-test",+ lastModified: "2024-01-23T14:21:27.697Z",},],};diff --git a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx b/fixtures/webstudio-custom-template/app/__generated__/_index.tsxindex 1e43000b69..45bce258c7 100644--- a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/_index.tsx@@ -4,7 +4,10 @@import { Fragment, useState } from "react";import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";import { useResource } from "@webstudio-is/react-sdk";-import { Body as Body } from "@webstudio-is/sdk-components-react-remix";+import {+ Body as Body,+ Link as Link,+} from "@webstudio-is/sdk-components-react-remix";import { Heading as Heading } from "@webstudio-is/sdk-components-react";import type { PageData } from "~/routes/_index";@@ -47,7 +50,11 @@ export const projectId = "0d856812-61d8-4014-a20a-82e01c0eb8ee";type Params = Record<string, string | undefined>;const Page = (_props: { params: Params }) => {return (- <Body data-ws-id="ibXgMoi9_ipHx1gVrvii0" data-ws-component="Body">+ <Body+ data-ws-id="ibXgMoi9_ipHx1gVrvii0"+ data-ws-component="Body"+ className="c1vynykc c15qd3jj c122cnm9 c1jp5sfs"+ ><Headingdata-ws-id="7pwqBSgrfuuOfk1JblWcL"data-ws-component="Heading"@@ -55,6 +62,13 @@ const Page = (_props: { params: Params }) => {>{"DO NOT TOUCH THIS PROJECT, IT'S USED FOR FIXTURES"}</Heading>+ <Link+ data-ws-id="QzTSoZnbGD6luZ5xcv893"+ data-ws-component="Link"+ href={"/script-test"}+ >+ {"Goto Script Test"}+ </Link></Body>);};@@ -65,7 +79,7 @@ export const getRemixParams = ({ ...params }: Params): Params => {return params;};-export const pagesPaths = new Set([""]);+export const pagesPaths = new Set(["", "/script-test"]);export const formsProperties = new Map<string,diff --git a/fixtures/webstudio-custom-template/app/__generated__/index.css b/fixtures/webstudio-custom-template/app/__generated__/index.cssindex 8795e00fc4..c2311061c0 100644--- a/fixtures/webstudio-custom-template/app/__generated__/index.css+++ b/fixtures/webstudio-custom-template/app/__generated__/index.css@@ -68,9 +68,31 @@ html {border-left-width: 1px;outline-width: 1px;}+ a:where([data-ws-component="Link"]) {+ box-sizing: border-box;+ border-top-width: 1px;+ border-right-width: 1px;+ border-bottom-width: 1px;+ border-left-width: 1px;+ outline-width: 1px;+ min-height: 1em;+ display: inline-block;+ }}@media all {.c11x2bo2 {font-size: 4em;}+ .c1vynykc {+ margin-top: 15px;+ }+ .c122cnm9 {+ margin-bottom: 15px;+ }+ .c15qd3jj {+ margin-right: 15px;+ }+ .c1jp5sfs {+ margin-left: 15px;+ }}diff --git a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsxnew file mode 100644index 0000000000..96541e80af--- /dev/null+++ b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx@@ -0,0 +1,309 @@+/* eslint-disable camelcase */+import {+ type V2_ServerRuntimeMetaFunction,+ type LinksFunction,+ type LinkDescriptor,+ type ActionArgs,+ type LoaderArgs,+ json,+} from "@remix-run/server-runtime";+import { useLoaderData } from "@remix-run/react";+import type { Page as PageType, ProjectMeta } from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";+import {+ fontAssets,+ pageData,+ user,+ projectId,+ pagesPaths,+ formsProperties,+ Page,+ imageAssets,+ getRemixParams,+} from "../__generated__/[script-test]._index";+import { loadResources } from "../__generated__/[script-test]._index.server";+import css from "../__generated__/index.css";+import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";++export type PageData = {+ project?: ProjectMeta;+ page: PageType;+};++export const loader = async (arg: LoaderArgs) => {+ const params = getRemixParams(arg.params);+ const resources = await loadResources({ params });++ const host =+ arg.request.headers.get("x-forwarded-host") ||+ arg.request.headers.get("host") ||+ "";++ const url = new URL(arg.request.url);+ url.host = host;+ url.protocol = "https";++ // typecheck+ arg.context.EXCLUDE_FROM_SEARCH satisfies boolean;++ return json(+ {+ host,+ url: url.href,+ excludeFromSearch: arg.context.EXCLUDE_FROM_SEARCH,+ params,+ resources,+ },+ // No way for current information to change, so add cache for 10 minutes+ // In case of CRM Data, this should be set to 0+ { headers: { "Cache-Control": "public, max-age=600" } }+ );+};++export const headers = () => {+ return {+ "Cache-Control": "public, max-age=0, must-revalidate",+ };+};++export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {+ const { page, project } = pageData;++ const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];++ if (data?.url) {+ metas.push({+ property: "og:url",+ content: data.url,+ });+ }++ if (page.title) {+ metas.push({ title: page.title });++ metas.push({+ property: "og:title",+ content: page.title,+ });+ }++ metas.push({ property: "og:type", content: "website" });++ const origin = `https://${data?.host}`;++ if (project?.siteName) {+ metas.push({+ property: "og:site_name",+ content: project.siteName,+ });+ metas.push({+ "script:ld+json": {+ "@context": "https://schema.org",+ "@type": "WebSite",+ name: project.siteName,+ url: origin,+ },+ });+ }++ if (page.meta.excludePageFromSearch || data?.excludeFromSearch) {+ metas.push({+ name: "robots",+ content: "noindex, nofollow",+ });+ }++ if (page.meta.description) {+ metas.push({+ name: "description",+ content: page.meta.description,+ });+ metas.push({+ property: "og:description",+ content: page.meta.description,+ });+ }++ if (page.meta.socialImageAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === page.meta.socialImageAssetId+ );++ if (imageAsset) {+ metas.push({+ property: "og:image",+ content: `https://${data?.host}${imageLoader({+ src: imageAsset.name,+ // Do not transform social image (not enough information do we need to do this)+ format: "raw",+ })}`,+ });+ }+ }++ for (const customMeta of page.meta.custom ?? []) {+ if (customMeta.property.trim().length === 0) {+ continue;+ }+ metas.push(customMeta);+ }++ return metas;+};++export const links: LinksFunction = () => {+ const result: LinkDescriptor[] = [];++ result.push({+ rel: "stylesheet",+ href: css,+ });++ const { project } = pageData;++ if (project?.faviconAssetId) {+ const imageAsset = imageAssets.find(+ (asset) => asset.id === project.faviconAssetId+ );++ if (imageAsset) {+ result.push({+ rel: "icon",+ href: imageLoader({+ src: imageAsset.name,+ width: 128,+ quality: 100,+ format: "auto",+ }),+ type: undefined,+ });+ }+ } else {+ result.push({+ rel: "icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });++ result.push({+ rel: "shortcut icon",+ href: "/favicon.ico",+ type: "image/x-icon",+ });+ }++ for (const asset of fontAssets) {+ if (asset.type === "font") {+ result.push({+ rel: "preload",+ href: assetBaseUrl + asset.name,+ as: "font",+ crossOrigin: "anonymous",+ // @todo add mimeType+ // type: asset.mimeType,+ });+ }+ }++ return result;+};++const getRequestHost = (request: Request): string =>+ request.headers.get("x-forwarded-host") || request.headers.get("host") || "";++const getMethod = (value: string | undefined) => {+ if (value === undefined) {+ return "post";+ }++ switch (value.toLowerCase()) {+ case "get":+ return "get";+ default:+ return "post";+ }+};++export const action = async ({ request, context }: ActionArgs) => {+ const formData = await request.formData();++ const formId = getFormId(formData);+ if (formId === undefined) {+ // We're throwing rather than returning { success: false }+ // because this isn't supposed to happen normally: bug or malicious user+ throw json("Form not found", { status: 404 });+ }++ const formProperties = formsProperties.get(formId);++ // form properties are not defined when defaults are used+ const { action, method } = formProperties ?? {};++ const email = user?.email;++ if (email == null) {+ return { success: false };+ }++ // wrapped in try/catch just in cases new URL() throws+ // (should not happen)+ let pageUrl: URL;+ try {+ pageUrl = new URL(request.url);+ pageUrl.host = getRequestHost(request);+ } catch {+ return { success: false };+ }++ if (action !== undefined) {+ try {+ // Test that action is full URL+ new URL(action);+ } catch {+ return json(+ {+ success: false,+ error: "Invalid action URL, must be valid http/https protocol",+ },+ { status: 200 }+ );+ }+ }++ const formInfo = {+ formData,+ projectId,+ action: action ?? null,+ method: getMethod(method),+ pageUrl: pageUrl.toString(),+ toEmail: email,+ fromEmail: pageUrl.hostname + "@webstudio.email",+ } as const;++ const result = await n8nHandler({+ formInfo,+ hookUrl: context.N8N_FORM_EMAIL_HOOK,+ });++ return result;+};++const Outlet = () => {+ const { params, resources } = useLoaderData<typeof loader>();+ return (+ <ReactSdkContext.Provider+ value={{+ imageLoader,+ assetBaseUrl,+ imageBaseUrl,+ pagesPaths,+ resources,+ }}+ >+ <Page params={params} />+ </ReactSdkContext.Provider>+ );+};++export default Outlet;diff --git a/fixtures/webstudio-custom-template/package.json b/fixtures/webstudio-custom-template/package.jsonindex 3fa216aa57..ce6f7935b4 100644--- a/fixtures/webstudio-custom-template/package.json+++ b/fixtures/webstudio-custom-template/package.json@@ -44,7 +44,7 @@"size-limit": [{"path": "public/build/*.js",- "limit": "136 kB",+ "limit": "137 kB","gzip": false}],