webstudio 0.0.0-021f2d4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +145 -0
  3. package/bin.js +5 -0
  4. package/lib/cli.js +6578 -0
  5. package/package.json +88 -0
  6. package/templates/cloudflare/WS_CF_README.md +48 -0
  7. package/templates/cloudflare/functions/[[path]].ts +9 -0
  8. package/templates/cloudflare/load-context.ts +9 -0
  9. package/templates/cloudflare/package.json +22 -0
  10. package/templates/cloudflare/tsconfig.json +18 -0
  11. package/templates/cloudflare/vite.config.ts +21 -0
  12. package/templates/cloudflare/worker-configuration.d.ts +3 -0
  13. package/templates/cloudflare/wrangler.toml +55 -0
  14. package/templates/defaults/app/constants.mjs +12 -0
  15. package/templates/defaults/app/extension.ts +16 -0
  16. package/templates/defaults/app/root.tsx +35 -0
  17. package/templates/defaults/app/route-templates/default-sitemap.tsx +34 -0
  18. package/templates/defaults/app/route-templates/html.tsx +297 -0
  19. package/templates/defaults/app/route-templates/redirect.tsx +6 -0
  20. package/templates/defaults/app/route-templates/xml.tsx +85 -0
  21. package/templates/defaults/app/routes/[robots.txt].tsx +24 -0
  22. package/templates/defaults/package.json +35 -0
  23. package/templates/defaults/public/favicon.ico +0 -0
  24. package/templates/defaults/tsconfig.json +22 -0
  25. package/templates/defaults/vite.config.ts +16 -0
  26. package/templates/internal/package.json +11 -0
  27. package/templates/internal/tsconfig.json +5 -0
  28. package/templates/netlify-edge-functions/app/constants.mjs +29 -0
  29. package/templates/netlify-edge-functions/app/entry.server.tsx +21 -0
  30. package/templates/netlify-edge-functions/netlify.toml +16 -0
  31. package/templates/netlify-edge-functions/package.json +9 -0
  32. package/templates/netlify-edge-functions/vite.config.ts +18 -0
  33. package/templates/netlify-functions/app/constants.mjs +29 -0
  34. package/templates/netlify-functions/app/entry.server.tsx +1 -0
  35. package/templates/netlify-functions/netlify.toml +16 -0
  36. package/templates/netlify-functions/package.json +9 -0
  37. package/templates/netlify-functions/vite.config.ts +18 -0
  38. package/templates/react-router/app/extension.ts +13 -0
  39. package/templates/react-router/app/root.tsx +35 -0
  40. package/templates/react-router/app/route-templates/default-sitemap.tsx +34 -0
  41. package/templates/react-router/app/route-templates/html.tsx +295 -0
  42. package/templates/react-router/app/route-templates/redirect.tsx +6 -0
  43. package/templates/react-router/app/route-templates/xml.tsx +85 -0
  44. package/templates/react-router/app/routes/[robots.txt].tsx +24 -0
  45. package/templates/react-router/app/routes.ts +4 -0
  46. package/templates/react-router/package.json +36 -0
  47. package/templates/react-router/public/favicon.ico +0 -0
  48. package/templates/react-router/tsconfig.json +18 -0
  49. package/templates/react-router/vite.config.ts +6 -0
  50. package/templates/react-router-docker/.dockerignore +4 -0
  51. package/templates/react-router-docker/Dockerfile +19 -0
  52. package/templates/react-router-docker/app/constants.mjs +18 -0
  53. package/templates/react-router-docker/app/routes/[_image].$.ts +24 -0
  54. package/templates/react-router-docker/package.json +7 -0
  55. package/templates/react-router-netlify/app/constants.mjs +29 -0
  56. package/templates/react-router-netlify/netlify.toml +6 -0
  57. package/templates/react-router-netlify/package.json +9 -0
  58. package/templates/react-router-netlify/vite.config.ts +7 -0
  59. package/templates/saas-helpers/package.json +6 -0
  60. package/templates/saas-helpers/tsconfig.json +18 -0
  61. package/templates/ssg/app/constants.mjs +13 -0
  62. package/templates/ssg/app/route-templates/html/+Head.tsx +92 -0
  63. package/templates/ssg/app/route-templates/html/+Page.tsx +21 -0
  64. package/templates/ssg/app/route-templates/html/+data.ts +37 -0
  65. package/templates/ssg/package.json +31 -0
  66. package/templates/ssg/pages/+config.ts +12 -0
  67. package/templates/ssg/public/favicon.ico +0 -0
  68. package/templates/ssg/renderer/+onRenderClient.tsx +30 -0
  69. package/templates/ssg/renderer/+onRenderHtml.tsx +29 -0
  70. package/templates/ssg/tsconfig.json +22 -0
  71. package/templates/ssg/vike.d.ts +25 -0
  72. package/templates/ssg/vite.config.ts +7 -0
  73. package/templates/ssg-netlify/app/constants.mjs +30 -0
  74. package/templates/ssg-vercel/app/constants.mjs +26 -0
  75. package/templates/ssg-vercel/public/vercel.json +11 -0
  76. package/templates/vercel/.vercelignore +8 -0
  77. package/templates/vercel/app/constants.mjs +25 -0
  78. package/templates/vercel/package.json +1 -0
  79. package/templates/vercel/vercel.json +11 -0
@@ -0,0 +1,92 @@
1
+ import type { PageContext } from "vike/types";
2
+ import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
3
+ import {
4
+ favIconAsset,
5
+ pageBackgroundImageAssets,
6
+ pageFontAssets,
7
+ siteName,
8
+ } from "__CLIENT__";
9
+ import "__CSS__";
10
+
11
+ export const Head = ({ data }: { data: PageContext["data"] }) => {
12
+ const { pageMeta } = data;
13
+ const { origin } = new URL(data.url);
14
+ const ldJson = {
15
+ "@context": "https://schema.org",
16
+ "@type": "WebSite",
17
+ name: siteName,
18
+ url: origin,
19
+ };
20
+ let socialImageUrl = pageMeta.socialImageUrl;
21
+ if (pageMeta.socialImageAssetName) {
22
+ socialImageUrl = `${origin}${imageLoader({
23
+ src: pageMeta.socialImageAssetName,
24
+ // Do not transform social image (not enough information do we need to do this)
25
+ format: "raw",
26
+ })}`;
27
+ }
28
+ return (
29
+ <>
30
+ {data.url && <meta property="og:url" content={data.url} />}
31
+ <title>{pageMeta.title}</title>
32
+ <meta property="og:title" content={pageMeta.title} />
33
+ {pageMeta.description && (
34
+ <>
35
+ <meta name="description" content={pageMeta.description} />
36
+ <meta property="og:description" content={pageMeta.description} />
37
+ </>
38
+ )}
39
+ <meta property="og:type" content="website" />
40
+ {siteName && <meta property="og:site_name" content={siteName} />}
41
+ {socialImageUrl && (
42
+ <meta property="og:image" content={pageMeta.socialImageUrl} />
43
+ )}
44
+ {siteName && (
45
+ <script
46
+ type="application/ld+json"
47
+ dangerouslySetInnerHTML={{
48
+ __html: JSON.stringify(ldJson, null, 2),
49
+ }}
50
+ ></script>
51
+ )}
52
+ {pageMeta.excludePageFromSearch && (
53
+ <meta name="robots" content="noindex, nofollow" />
54
+ )}
55
+ {pageMeta.custom.map(({ property, content }) => (
56
+ <meta key={property} property={property} content={content} />
57
+ ))}
58
+
59
+ {favIconAsset && (
60
+ <link
61
+ rel="icon"
62
+ href={imageLoader({
63
+ src: `${assetBaseUrl}${favIconAsset.name}`,
64
+ // width,height must be multiple of 48 https://developers.google.com/search/docs/appearance/favicon-in-search
65
+ width: 144,
66
+ height: 144,
67
+ fit: "pad",
68
+ quality: 100,
69
+ format: "auto",
70
+ })}
71
+ />
72
+ )}
73
+ {pageFontAssets.map((asset) => (
74
+ <link
75
+ key={asset.id}
76
+ rel="preload"
77
+ href={`${assetBaseUrl}${asset.name}`}
78
+ as="font"
79
+ crossOrigin="anonymous"
80
+ />
81
+ ))}
82
+ {pageBackgroundImageAssets.map((asset) => (
83
+ <link
84
+ key={asset.id}
85
+ rel="preload"
86
+ href={`${assetBaseUrl}${asset.name}`}
87
+ as="image"
88
+ />
89
+ ))}
90
+ </>
91
+ );
92
+ };
@@ -0,0 +1,21 @@
1
+ import type { PageContext } from "vike/types";
2
+ import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
3
+ import { assetBaseUrl, imageLoader } from "__CONSTANTS__";
4
+ import { Page } from "__CLIENT__";
5
+
6
+ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
7
+ const { system, resources, url } = data;
8
+ return (
9
+ <ReactSdkContext.Provider
10
+ value={{
11
+ imageLoader,
12
+ assetBaseUrl,
13
+ resources,
14
+ }}
15
+ >
16
+ {/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}
17
+ <Page key={url} system={system} />
18
+ </ReactSdkContext.Provider>
19
+ );
20
+ };
21
+ export default PageComponent;
@@ -0,0 +1,37 @@
1
+ import type { PageContextServer } from "vike/types";
2
+ import { redirect } from "vike/abort";
3
+ import { loadResources } from "@webstudio-is/sdk/runtime";
4
+ import { getPageMeta, getResources } from "__SERVER__";
5
+
6
+ export const data = async (pageContext: PageContextServer) => {
7
+ const url = new URL(pageContext.urlOriginal, "http://url");
8
+ const headers = new Headers(pageContext.headers ?? {});
9
+ const host = headers.get("x-forwarded-host") || headers.get("host") || "";
10
+ url.host = host;
11
+ url.protocol = "https";
12
+
13
+ const params = pageContext.routeParams;
14
+ const system = {
15
+ params,
16
+ search: Object.fromEntries(url.searchParams),
17
+ origin: url.origin,
18
+ };
19
+
20
+ const resources = await loadResources(fetch, getResources({ system }).data);
21
+ const pageMeta = getPageMeta({ system, resources });
22
+
23
+ if (pageMeta.redirect) {
24
+ const status =
25
+ pageMeta.status === 301 || pageMeta.status === 302
26
+ ? pageMeta.status
27
+ : 302;
28
+ throw redirect(pageMeta.redirect, status);
29
+ }
30
+
31
+ return {
32
+ url: url.href,
33
+ system,
34
+ resources,
35
+ pageMeta,
36
+ } satisfies PageContextServer["data"];
37
+ };
@@ -0,0 +1,31 @@
1
+ {
2
+ "type": "module",
3
+ "private": true,
4
+ "sideEffects": false,
5
+ "scripts": {
6
+ "build": "vite build",
7
+ "dev": "vite dev",
8
+ "typecheck": "tsc"
9
+ },
10
+ "dependencies": {
11
+ "@webstudio-is/image": "0.0.0-021f2d4",
12
+ "@webstudio-is/react-sdk": "0.0.0-021f2d4",
13
+ "@webstudio-is/sdk": "0.0.0-021f2d4",
14
+ "@webstudio-is/sdk-components-react": "0.0.0-021f2d4",
15
+ "@webstudio-is/sdk-components-animation": "0.0.0-021f2d4",
16
+ "@webstudio-is/sdk-components-react-radix": "0.0.0-021f2d4",
17
+ "react": "18.3.0-canary-14898b6a9-20240318",
18
+ "react-dom": "18.3.0-canary-14898b6a9-20240318",
19
+ "vike": "^0.4.220"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^18.2.70",
23
+ "@types/react-dom": "^18.2.25",
24
+ "@vitejs/plugin-react": "^4.3.4",
25
+ "typescript": "5.7.3",
26
+ "vite": "^5.4.11"
27
+ },
28
+ "engines": {
29
+ "node": ">=20.0.0"
30
+ }
31
+ }
@@ -0,0 +1,12 @@
1
+ import type { Config } from "vike/types";
2
+
3
+ export default {
4
+ meta: {
5
+ Head: {
6
+ env: { server: true, client: true },
7
+ },
8
+ lang: {
9
+ env: { server: true, client: true },
10
+ },
11
+ },
12
+ } satisfies Config;
Binary file
@@ -0,0 +1,30 @@
1
+ import { type Root, createRoot } from "react-dom/client";
2
+ import type { OnRenderClientSync } from "vike/types";
3
+ // @todo think about how to make __generated__ typeable
4
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
5
+ // @ts-ignore
6
+ import { CustomCode } from "../app/__generated__/_index";
7
+
8
+ let root: Root;
9
+
10
+ export const onRenderClient: OnRenderClientSync = (pageContext) => {
11
+ const lang = pageContext.data.pageMeta.language || "en";
12
+ const Head = pageContext.config.Head ?? (() => <></>);
13
+ const Page = pageContext.Page ?? (() => <></>);
14
+ const htmlContent = (
15
+ <>
16
+ <head>
17
+ <meta charSet="UTF-8" />
18
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
19
+ <Head data={pageContext.data} />
20
+ <CustomCode />
21
+ </head>
22
+ <Page data={pageContext.data} />
23
+ </>
24
+ );
25
+ if (root === undefined) {
26
+ root = createRoot(document.documentElement);
27
+ }
28
+ document.documentElement.lang = lang;
29
+ root.render(htmlContent);
30
+ };
@@ -0,0 +1,29 @@
1
+ import { renderToString } from "react-dom/server";
2
+ import { dangerouslySkipEscape, escapeInject } from "vike/server";
3
+ import type { OnRenderHtmlSync } from "vike/types";
4
+ // @todo think about how to make __generated__ typeable
5
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
6
+ // @ts-ignore
7
+ import { CustomCode } from "../app/__generated__/_index";
8
+
9
+ export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
10
+ const lang = pageContext.data.pageMeta.language || "en";
11
+ const Head = pageContext.config.Head ?? (() => <></>);
12
+ const Page = pageContext.Page ?? (() => <></>);
13
+ const html = dangerouslySkipEscape(
14
+ renderToString(
15
+ <html lang={lang}>
16
+ <head>
17
+ <meta charSet="UTF-8" />
18
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
19
+ <Head data={pageContext.data} />
20
+ <CustomCode />
21
+ </head>
22
+ <Page data={pageContext.data} />
23
+ </html>
24
+ )
25
+ );
26
+ return escapeInject`<!DOCTYPE html>
27
+ ${html}
28
+ `;
29
+ };
@@ -0,0 +1,22 @@
1
+ {
2
+ "include": ["**/*.ts", "**/*.tsx", "**/*.mjs"],
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
5
+ "types": [
6
+ "vite/client",
7
+ "@webstudio-is/react-sdk/placeholder",
8
+ "./vike.d.ts"
9
+ ],
10
+ "isolatedModules": true,
11
+ "esModuleInterop": true,
12
+ "jsx": "react-jsx",
13
+ "module": "ESNext",
14
+ "moduleResolution": "bundler",
15
+ "target": "ES2022",
16
+ "strict": true,
17
+ "allowJs": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "noEmit": true,
20
+ "skipLibCheck": true
21
+ }
22
+ }
@@ -0,0 +1,25 @@
1
+ import type { ImageLoader } from "@webstudio-is/image";
2
+ import type { PageMeta, System } from "@webstudio-is/sdk";
3
+
4
+ declare global {
5
+ namespace Vike {
6
+ interface Config {
7
+ lang?: (props: { data: PageData }) => string;
8
+ Head?: (props: { data: PageData }) => React.ReactNode;
9
+ }
10
+
11
+ interface PageContext {
12
+ constants: {
13
+ assetBaseUrl: string;
14
+ imageLoader: ImageLoader;
15
+ };
16
+ data: {
17
+ url: string;
18
+ system: System;
19
+ resources: Record<string, unknown>;
20
+ pageMeta: PageMeta;
21
+ };
22
+ Page?: (props: { data: PageData }) => React.ReactNode;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import vike from "vike/plugin";
4
+
5
+ export default defineConfig({
6
+ plugins: [react(), vike({ prerender: true })],
7
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * We use mjs extension as constants in this file is shared with the build script
3
+ * and we use `node --eval` to extract the constants.
4
+ */
5
+
6
+ export const assetBaseUrl = "/assets/";
7
+
8
+ /**
9
+ * @type {import("@webstudio-is/image").ImageLoader}
10
+ */
11
+ export const imageLoader = (props) => {
12
+ if (process.env.NODE_ENV !== "production") {
13
+ return props.src;
14
+ }
15
+
16
+ if (props.format === "raw") {
17
+ return props.src;
18
+ }
19
+
20
+ // https://docs.netlify.com/image-cdn/overview/
21
+ const searchParams = new URLSearchParams();
22
+ searchParams.set("url", props.src);
23
+ searchParams.set("w", props.width.toString());
24
+ if (props.height) {
25
+ searchParams.set("h", props.height.toString());
26
+ }
27
+ searchParams.set("q", props.quality.toString());
28
+ // fit=contain by default
29
+ return `/.netlify/images?${searchParams}`;
30
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * We use mjs extension as constants in this file is shared with the build script
3
+ * and we use `node --eval` to extract the constants.
4
+ */
5
+
6
+ export const assetBaseUrl = "/assets/";
7
+
8
+ /**
9
+ * @type {import("@webstudio-is/image").ImageLoader}
10
+ */
11
+ export const imageLoader = (props) => {
12
+ if (process.env.NODE_ENV !== "production") {
13
+ return props.src;
14
+ }
15
+
16
+ if (props.format === "raw") {
17
+ return props.src;
18
+ }
19
+
20
+ // https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
21
+ const searchParams = new URLSearchParams();
22
+ searchParams.set("url", props.src);
23
+ searchParams.set("w", props.width.toString());
24
+ searchParams.set("q", props.quality.toString());
25
+ return `/_vercel/image?${searchParams}`;
26
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "images": {
3
+ "domains": [],
4
+ "sizes": [
5
+ 16, 32, 48, 64, 96, 128, 144, 256, 384, 640, 750, 828, 1080, 1200, 1920,
6
+ 2048, 3840
7
+ ],
8
+ "minimumCacheTTL": 60,
9
+ "formats": ["image/webp", "image/avif"]
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ node_modules
2
+
3
+ .cache
4
+ .env
5
+ .vercel
6
+ .webstudio
7
+ build
8
+ public/build
@@ -0,0 +1,25 @@
1
+ /**
2
+ * We use mjs extension as constants in this file is shared with the build script
3
+ * and we use `node --eval` to extract the constants.
4
+ */
5
+ export const assetBaseUrl = "/assets/";
6
+
7
+ /**
8
+ * @type {import("@webstudio-is/image").ImageLoader}
9
+ */
10
+ export const imageLoader = (props) => {
11
+ if (process.env.NODE_ENV !== "production") {
12
+ return props.src;
13
+ }
14
+
15
+ if (props.format === "raw") {
16
+ return props.src;
17
+ }
18
+
19
+ // https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
20
+ const searchParams = new URLSearchParams();
21
+ searchParams.set("url", props.src);
22
+ searchParams.set("w", props.width.toString());
23
+ searchParams.set("q", props.quality.toString());
24
+ return `/_vercel/image?${searchParams}`;
25
+ };
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,11 @@
1
+ {
2
+ "images": {
3
+ "domains": [],
4
+ "sizes": [
5
+ 16, 32, 48, 64, 96, 128, 144, 256, 384, 640, 750, 828, 1080, 1200, 1920,
6
+ 2048, 3840
7
+ ],
8
+ "minimumCacheTTL": 60,
9
+ "formats": ["image/webp", "image/avif"]
10
+ }
11
+ }