Skip to content

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.

Image (#502)

Ivan Starkov843467a69142
diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.ts
index 266105b0be..b6935292a1 100755
--- a/packages/css-data/bin/mdn-data.ts
+++ b/packages/css-data/bin/mdn-data.ts
@@ -147,6 +147,10 @@ for (property in filteredProperties) {
const targetDir = path.join(process.cwd(), process.argv.pop() as string);
+if (!fs.existsSync(targetDir)) {
+ fs.mkdirSync(targetDir, { recursive: true });
+}
+
const writeToFile = (fileName: string, constant: string, data: unknown) => {
const autogeneratedHint = "// This file was generated by yarn mdn-data\n";
const content =
diff --git a/packages/css-data/package.json b/packages/css-data/package.json
index 18565a4bd1..3d8ec09d58 100644
--- a/packages/css-data/package.json
+++ b/packages/css-data/package.json
@@ -11,7 +11,7 @@
"dev": "tsup --watch",
"build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
- "build:mdn-data": "tsx ./bin/mdn-data.ts ./src",
+ "build:mdn-data": "tsx ./bin/mdn-data.ts ./src/__generated__",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
"publish-to-npm": "bash ../../bin/publish-to-npm.sh"
},
diff --git a/packages/css-data/src/keyword-values.ts b/packages/css-data/src/__generated__/keyword-values.ts
similarity index 100%
rename from packages/css-data/src/keyword-values.ts
rename to packages/css-data/src/__generated__/keyword-values.ts
diff --git a/packages/css-data/src/properties.ts b/packages/css-data/src/__generated__/properties.ts
similarity index 100%
rename from packages/css-data/src/properties.ts
rename to packages/css-data/src/__generated__/properties.ts
diff --git a/packages/css-data/src/units.ts b/packages/css-data/src/__generated__/units.ts
similarity index 100%
rename from packages/css-data/src/units.ts
rename to packages/css-data/src/__generated__/units.ts
diff --git a/packages/css-data/src/index.ts b/packages/css-data/src/index.ts
index 01bda2c79f..fc002f35ac 100644
--- a/packages/css-data/src/index.ts
+++ b/packages/css-data/src/index.ts
@@ -1,4 +1,4 @@
-export * from "./keyword-values";
-export * from "./properties";
-export * from "./units";
+export * from "./__generated__/keyword-values";
+export * from "./__generated__/properties";
+export * from "./__generated__/units";
export * from "./schema";
diff --git a/packages/css-data/src/schema.ts b/packages/css-data/src/schema.ts
index da933df1de..97d1872450 100644
--- a/packages/css-data/src/schema.ts
+++ b/packages/css-data/src/schema.ts
@@ -1,5 +1,5 @@
-import { units } from "./units";
-import { properties } from "./properties";
+import { units } from "./__generated__/units";
+import { properties } from "./__generated__/properties";
import { z } from "zod";
type Properties = typeof properties;
diff --git a/packages/generate-arg-types/package.json b/packages/generate-arg-types/package.json
new file mode 100644
index 0000000000..487a984bee
--- /dev/null
+++ b/packages/generate-arg-types/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "@webstudio-is/generate-arg-types",
+ "version": "0.0.1",
+ "description": "Generate components property types",
+ "author": "Webstudio <[email protected]>",
+ "homepage": "https://webstudio.is",
+ "type": "module",
+ "scripts": {
+ "typecheck": "tsc --noEmit",
+ "checks": "yarn typecheck && yarn lint",
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
+ },
+ "dependencies": {
+ "@types/fs-extra": "^9.0.13",
+ "fast-glob": "^3.2.12",
+ "fs-extra": "^10.1.0",
+ "react-docgen-typescript": "^2.2.2",
+ "zod": "^3.19.1"
+ },
+ "devDependencies": {
+ "typescript": "4.7.4",
+ "esbuild": "^0.14.25"
+ },
+ "files": [
+ "src/*",
+ "README.md",
+ "!*.test.*"
+ ],
+ "bin": {
+ "generate-arg-types": "./src/index.ts"
+ },
+ "license": "MIT",
+ "private": false,
+ "sideEffects": false
+}
diff --git a/packages/react-sdk/src/arg-types/utils.ts b/packages/generate-arg-types/src/arg-types.ts
similarity index 100%
rename from packages/react-sdk/src/arg-types/utils.ts
rename to packages/generate-arg-types/src/arg-types.ts
diff --git a/packages/react-sdk/bin/generate-arg-types.ts b/packages/generate-arg-types/src/index.ts
similarity index 67%
rename from packages/react-sdk/bin/generate-arg-types.ts
rename to packages/generate-arg-types/src/index.ts
index 487b38af7e..28b0f2fe08 100755
--- a/packages/react-sdk/bin/generate-arg-types.ts
+++ b/packages/generate-arg-types/src/index.ts
@@ -1,9 +1,15 @@
+#!/usr/bin/env -S node --experimental-specifier-resolution=node --loader=tsx
+/* eslint-disable no-console */
+
import path from "path";
import { z } from "zod";
import { withCustomConfig } from "react-docgen-typescript";
import fg from "fast-glob";
+
import fs from "fs-extra";
-import { propsToArgTypes } from "../src/arg-types/utils";
+import { propsToArgTypes } from "./arg-types";
+
+const GENERATED_FILES_DIR = "__generated__";
const options = {
shouldExtractLiteralValuesFromEnum: true,
@@ -45,11 +51,22 @@ const ArgTypes = z.record(
// For each component file generate argTypes based on the propTypes
componentFiles.forEach((filePath) => {
- const jsonPath = filePath.replace(".tsx", ".props.json");
+ const generatedJsonDir = path.join(
+ path.dirname(filePath),
+ GENERATED_FILES_DIR
+ );
+
+ if (!fs.existsSync(generatedJsonDir)) {
+ fs.mkdirSync(generatedJsonDir, { recursive: true });
+ }
+
+ const generateJsonFile = `${path.basename(filePath, ".tsx")}.props.json`;
+ const generateJsonPath = path.join(generatedJsonDir, generateJsonFile);
+
const res = tsConfigParser.parse(filePath);
const argTypes = propsToArgTypes(res[0].props);
ArgTypes.parse(argTypes);
- fs.ensureFileSync(jsonPath);
- fs.writeJsonSync(jsonPath, argTypes, { spaces: 2 });
- console.log(`Done generating argTypes for ${jsonPath}`);
+ fs.ensureFileSync(generateJsonPath);
+ fs.writeJsonSync(generateJsonPath, argTypes, { spaces: 2 });
+ console.log(`Done generating argTypes for ${generateJsonPath}`);
});
diff --git a/packages/generate-arg-types/tsconfig.json b/packages/generate-arg-types/tsconfig.json
new file mode 100644
index 0000000000..a360eabd33
--- /dev/null
+++ b/packages/generate-arg-types/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ // Extends can't use node's resolution rn https://github.com/dividab/tsconfig-paths/issues/209#issuecomment-1177261091
+ "extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
+ "include": ["src"],
+ "compilerOptions": {
+ "module": "ES2020",
+ "target": "ES2020",
+ "strict": true,
+ "baseUrl": ".",
+ "rootDir": "./src",
+ "outDir": "./.bin"
+ },
+ // this is auto-generated by update-ts-project-references.ts
+ "references": []
+}
diff --git a/packages/icons/package.json b/packages/icons/package.json
index ea17784bb4..66ecd93488 100644
--- a/packages/icons/package.json
+++ b/packages/icons/package.json
@@ -9,7 +9,7 @@
"dev": "tsup --watch",
"build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
"build": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
- "generate": "rm -fr src/gen && NODE_OPTIONS='--loader=tsx' svgo-jsx svgo-jsx.config.ts",
+ "generate": "rm -fr src/__generated__ && NODE_OPTIONS='--loader=tsx' svgo-jsx svgo-jsx.config.ts",
"typecheck": "tsc --noEmit",
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
"checks": "yarn typecheck && yarn lint",
diff --git a/packages/icons/src/gen/format-clear.tsx b/packages/icons/src/__generated__/format-clear.tsx
similarity index 100%
rename from packages/icons/src/gen/format-clear.tsx
rename to packages/icons/src/__generated__/format-clear.tsx
diff --git a/packages/icons/src/gen/index.ts b/packages/icons/src/__generated__/index.ts
similarity index 100%
rename from packages/icons/src/gen/index.ts
rename to packages/icons/src/__generated__/index.ts
diff --git a/packages/icons/src/gen/subscript.tsx b/packages/icons/src/__generated__/subscript.tsx
similarity index 100%
rename from packages/icons/src/gen/subscript.tsx
rename to packages/icons/src/__generated__/subscript.tsx
diff --git a/packages/icons/src/gen/superscript.tsx b/packages/icons/src/__generated__/superscript.tsx
similarity index 100%
rename from packages/icons/src/gen/superscript.tsx
rename to packages/icons/src/__generated__/superscript.tsx
diff --git a/packages/icons/src/index.ts b/packages/icons/src/index.ts
index 94842ae9ef..7e491bd74d 100644
--- a/packages/icons/src/index.ts
+++ b/packages/icons/src/index.ts
@@ -1,5 +1,5 @@
export * from "./legacy";
-export * from "./gen";
+export * from "./__generated__";
export * from "./list-nested";
export * from "./brush";
export * from "./form";
diff --git a/packages/icons/svgo-jsx.config.ts b/packages/icons/svgo-jsx.config.ts
index b2bf638d75..655f22d2b5 100644
--- a/packages/icons/svgo-jsx.config.ts
+++ b/packages/icons/svgo-jsx.config.ts
@@ -29,7 +29,7 @@ const transformFilename = (filename: string) => {
export const config: Config = {
inputDir: "./icons",
- outputDir: "./src/gen",
+ outputDir: "./src/__generated__",
template,
transformFilename,
svgProps: {
@@ -58,6 +58,9 @@ export const config: Config = {
const tsFile = path.basename(file, path.extname(file));
result += `export * from "./${tsFile}";\n`;
}
- await fs.writeFile(path.join(process.cwd(), "./src/gen/index.ts"), result);
+ await fs.writeFile(
+ path.join(process.cwd(), "./src/__generated__/index.ts"),
+ result
+ );
},
};
diff --git a/packages/image/.storybook/main.cjs b/packages/image/.storybook/main.cjs
new file mode 100644
index 0000000000..f16eac6b1f
--- /dev/null
+++ b/packages/image/.storybook/main.cjs
@@ -0,0 +1,9 @@
+module.exports = {
+ stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
+ addons: [
+ "@storybook/addon-links",
+ "@storybook/addon-essentials",
+ "@storybook/addon-interactions",
+ ],
+ framework: "@storybook/react",
+};
diff --git a/packages/image/.storybook/preview.js b/packages/image/.storybook/preview.js
new file mode 100644
index 0000000000..f089c7f9d5
--- /dev/null
+++ b/packages/image/.storybook/preview.js
@@ -0,0 +1,9 @@
+export const parameters = {
+ actions: { argTypesRegex: "^on[A-Z].*" },
+ controls: {
+ matchers: {
+ color: /(background|color)$/i,
+ date: /Date$/,
+ },
+ },
+};
diff --git a/packages/image/jest.config.js b/packages/image/jest.config.js
new file mode 100644
index 0000000000..e7fc137533
--- /dev/null
+++ b/packages/image/jest.config.js
@@ -0,0 +1 @@
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/image/package.json b/packages/image/package.json
new file mode 100644
index 0000000000..bc7846dc16
--- /dev/null
+++ b/packages/image/package.json
@@ -0,0 +1,60 @@
+{
+ "name": "@webstudio-is/image",
+ "version": "0.0.1",
+ "description": "Image optimization",
+ "author": "Webstudio <[email protected]>",
+ "homepage": "https://webstudio.is",
+ "type": "module",
+ "scripts": {
+ "typecheck": "tsc --noEmit",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
+ "checks": "yarn typecheck && yarn lint && yarn test",
+ "dev": "tsup --watch",
+ "build:args": "generate-arg-types './src/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.json\"",
+ "build": "rm -fr lib tsconfig.tsbuildinfo && tsc",
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
+ "storybook:run": "start-storybook -p 6006",
+ "storybook:build": "build-storybook",
+ "generate-types": "generate-arg-types"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "@storybook/addon-actions": "^6.5.6",
+ "@storybook/addon-essentials": "^6.5.6",
+ "@storybook/addon-interactions": "^6.5.12",
+ "@storybook/addon-links": "^6.5.6",
+ "@storybook/builder-webpack4": "^6.5.6",
+ "@storybook/jest": "^0.0.10",
+ "@storybook/manager-webpack4": "^6.5.6",
+ "@storybook/react": "^6.5.6",
+ "@storybook/testing-library": "^0.0.13",
+ "@webstudio-is/jest-config": "*",
+ "typescript": "4.7.4",
+ "@webstudio-is/generate-arg-types": "*"
+ },
+ "peerDependencies": {
+ "react": "^17.0.2",
+ "react-dom": "^17.0.2"
+ },
+ "module": "./lib/index.js",
+ "exports": {
+ ".": "./lib/index.js",
+ "./server": "./server.js"
+ },
+ "types": "lib/index.d.ts",
+ "files": [
+ "lib/*",
+ "README.md",
+ "!*.test.*"
+ ],
+ "license": "MIT",
+ "private": false,
+ "sideEffects": false,
+ "tsup": {
+ "entry": [
+ "src/index.ts"
+ ],
+ "format": "esm",
+ "outDir": "lib"
+ }
+}
diff --git a/packages/react-sdk/src/components/image.props.json b/packages/image/src/__generated__/image.props.json
similarity index 99%
rename from packages/react-sdk/src/components/image.props.json
rename to packages/image/src/__generated__/image.props.json
index fee6f4b4a0..362978733f 100644
--- a/packages/react-sdk/src/components/image.props.json
+++ b/packages/image/src/__generated__/image.props.json
@@ -15,7 +15,7 @@
"type": "text"
},
"alt": {
- "defaultValue": "",
+ "defaultValue": null,
"required": false,
"type": "text"
},
@@ -32,7 +32,7 @@
"type": "radio"
},
"height": {
- "defaultValue": "",
+ "defaultValue": null,
"required": false,
"type": "text"
},
@@ -79,7 +79,7 @@
"type": "text"
},
"width": {
- "defaultValue": "",
+ "defaultValue": null,
"required": false,
"type": "text"
},
@@ -564,7 +564,7 @@
},
"loader": {
"defaultValue": null,
- "required": false,
+ "required": true,
"type": "text"
},
"optimize": {
diff --git a/packages/image/src/image-dev.stories.tsx b/packages/image/src/image-dev.stories.tsx
new file mode 100644
index 0000000000..d1573f1279
--- /dev/null
+++ b/packages/image/src/image-dev.stories.tsx
@@ -0,0 +1,132 @@
+// Story for image development, see https://github.com/webstudio-is/webstudio-designer/issues/387
+
+import React, { type ComponentProps, type HTMLAttributes } from "react";
+import type { ComponentMeta, ComponentStory } from "@storybook/react";
+import {
+ Image as ImagePrimitive,
+ cloudflareImageLoader,
+ localImageLoader,
+} from "./";
+
+// to not allow include local assets everywhere, just enable it for this file
+// eslint-disable-next-line @typescript-eslint/ban-ts-comment
+// @ts-ignore
+import localLogoImage from "../storybook-assets/logo.webp";
+
+export default {
+ title: "Components/ImageDev",
+} as ComponentMeta<typeof ImagePrimitive>;
+
+type ImageProps = ComponentProps<typeof ImagePrimitive>;
+
+/**
+ * In case you need to test img with real cloudflare trasforms
+ * set USE_CLOUDFLARE_IMAGE_TRANSFORM = true
+ **/
+const USE_CLOUDFLARE_IMAGE_TRANSFORM = false;
+
+// For cloudflare image transform testing, logo should be the most consistent image on the site
+const REMOTE_SELF_DOMAIN_IMAGE = "https://webstudio.is/logo.webp";
+
+const imageSrc = USE_CLOUDFLARE_IMAGE_TRANSFORM
+ ? REMOTE_SELF_DOMAIN_IMAGE
+ : localLogoImage;
+
+const imageLoader = USE_CLOUDFLARE_IMAGE_TRANSFORM
+ ? cloudflareImageLoader({ resizeOrigin: "https://webstudio.is" })
+ : localImageLoader();
+
+const ImageBase: ComponentStory<
+ React.ForwardRefExoticComponent<
+ Omit<ImageProps, "loader"> & { style?: HTMLAttributes<"img">["style"] }
+ >
+> = (args) => {
+ const style = {
+ maxWidth: "100%",
+ display: "block",
+ ...args.style,
+ };
+
+ return (
+ <ImagePrimitive
+ {...args}
+ optimize={true}
+ loader={imageLoader}
+ style={style}
+ />
+ );
+};
+
+/**
+ * Load images depending on image width and device per pixel ratio.
+ **/
+export const FixedWidthImage: ComponentStory<React.FunctionComponent> = () => (
+ <ImageBase src={imageSrc} width="300" height="400" />
+);
+
+/**
+ * Preserve ratio using object-fit: cover. Load images depending on image width and device per pixel ratio.
+ **/
+export const FixedWidthImageCover: ComponentStory<
+ React.FunctionComponent
+> = () => (
+ <ImageBase
+ src={imageSrc}
+ width="300"
+ height="400"
+ style={{ objectFit: "cover" }}
+ />
+);
+
+/**
+ * Load images depending on the viewport width.
+ **/
+export const UnknownWidthImage: ComponentStory<
+ React.FunctionComponent
+> = () => <ImageBase src={imageSrc} />;
+
+/**
+ * Fit width of the parent container, has own aspect-ratio and object-fit=cover.
+ * Load images depending on the viewport width.
+ **/
+export const AspectRatioImage: ComponentStory<React.FunctionComponent> = () => (
+ <div style={{ width: "50%" }}>
+ <ImageBase
+ src={imageSrc}
+ style={{ aspectRatio: "2/1", objectFit: "cover", width: "100%" }}
+ />
+ </div>
+);
+
+/**
+ * Fill width and height of the relative parent container, object-fit=cover. Load images depending on the viewport width.
+ **/
+export const FillParentImage: ComponentStory<React.FunctionComponent> = () => (
+ <div style={{ width: "50%", aspectRatio: "2/1", position: "relative" }}>
+ <ImageBase
+ src={imageSrc}
+ style={{
+ objectFit: "cover",
+ position: "absolute",
+ width: "100%",
+ height: "100%",
+ }}
+ />
+ </div>
+);
+
+/**
+ * "sizes" attribute explicitly equal to 100vw allowing to skip the default behavior.
+ * See DEFAULT_SIZES in the Image component. Load images depending on the viewport width.
+ **/
+export const HeroImage: ComponentStory<React.FunctionComponent> = () => (
+ <ImageBase
+ src={imageSrc}
+ sizes="100vw"
+ style={{
+ aspectRatio: "3/1",
+ objectFit: "cover",
+ width: "100%",
+ }}
+ />
+);
diff --git a/packages/image/src/image-loaders.ts b/packages/image/src/image-loaders.ts
new file mode 100644
index 0000000000..145694d0bd
--- /dev/null
+++ b/packages/image/src/image-loaders.ts
@@ -0,0 +1,47 @@
+import warnOnce from "warn-once";
+import { allSizes, type ImageLoader } from "./image-optimize";
+
+export type CloudflareImageLoaderOptions = {
+ resizeOrigin?: string | null;
+};
+
+/**
+ * Default image loader in case of no loader provided
+ * https://developers.cloudflare.com/images/image-resizing/url-format/
+ **/
+export const cloudflareImageLoader: (
+ ops: CloudflareImageLoaderOptions | null
+) => ImageLoader =
+ (loaderOptions) =>
+ ({ width, src, quality }) => {
+ if (process.env.NODE_ENV !== "production") {
+ warnOnce(
+ allSizes.includes(width) === false,
+ "Width must be only from allowed values"
+ );
+ }
+
+ const options = `width=${width},quality=${quality},format=auto`;
+ // Cloudflare docs say that we don't need to urlencode the path params
+ const pathname = `/cdn-cgi/image/${options}/${src}`;
+
+ if (loaderOptions?.resizeOrigin != null) {
+ const url = new URL(pathname, loaderOptions.resizeOrigin);
+ return url.href;
+ } else {
+ return pathname;
+ }
+ };
+
+/**
+ * Fake pseudo loader for local testing purposes
+ **/
+export const localImageLoader: () => ImageLoader =
+ () =>
+ ({ width, src, quality }) => {
+ // Just emulate like we really resize the image
+ const params = new URLSearchParams();
+ params.set("width", `${width}`);
+ params.set("quality", `${quality}`);
+ return `${src}?${params.toString()}`;
+ };
diff --git a/packages/image/src/image-optimize.test.ts b/packages/image/src/image-optimize.test.ts
new file mode 100644
index 0000000000..58c259d8f7
--- /dev/null
+++ b/packages/image/src/image-optimize.test.ts
@@ -0,0 +1,174 @@
+import { getImageAttributes } from "./image-optimize";
+import { cloudflareImageLoader } from "./image-loaders";
+
+describe("Image optimizations applied", () => {
+ test("width is number, create pixel density descriptor 'x'", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: 100,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: undefined,
+ quality: 100,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "sizes": undefined,
+ "src": "/cdn-cgi/image/width=256,quality=100,format=auto/https://webstudio.is/logo.webp",
+ "srcSet": "/cdn-cgi/image/width=128,quality=100,format=auto/https://webstudio.is/logo.webp 1x, /cdn-cgi/image/width=256,quality=100,format=auto/https://webstudio.is/logo.webp 2x",
+ }
+ `);
+ });
+
+ test("width is undefined, create 'w' descriptor and sizes prop", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: undefined,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: undefined,
+ quality: 90,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "sizes": "(min-width: 1280px) 50vw, 100vw",
+ "src": "/cdn-cgi/image/width=3840,quality=90,format=auto/https://webstudio.is/logo.webp",
+ "srcSet": "/cdn-cgi/image/width=384,quality=90,format=auto/https://webstudio.is/logo.webp 384w, /cdn-cgi/image/width=640,quality=90,format=auto/https://webstudio.is/logo.webp 640w, /cdn-cgi/image/width=750,quality=90,format=auto/https://webstudio.is/logo.webp 750w, /cdn-cgi/image/width=828,quality=90,format=auto/https://webstudio.is/logo.webp 828w, /cdn-cgi/image/width=1080,quality=90,format=auto/https://webstudio.is/logo.webp 1080w, /cdn-cgi/image/width=1200,quality=90,format=auto/https://webstudio.is/logo.webp 1200w, /cdn-cgi/image/width=1920,quality=90,format=auto/https://webstudio.is/logo.webp 1920w, /cdn-cgi/image/width=2048,quality=90,format=auto/https://webstudio.is/logo.webp 2048w, /cdn-cgi/image/width=3840,quality=90,format=auto/https://webstudio.is/logo.webp 3840w",
+ }
+ `);
+ });
+
+ test("width is undefined and size defined, creates 'w' descriptor and use input sizes props", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: undefined,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: "100vw",
+ quality: 70,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "sizes": "100vw",
+ "src": "/cdn-cgi/image/width=3840,quality=70,format=auto/https://webstudio.is/logo.webp",
+ "srcSet": "/cdn-cgi/image/width=640,quality=70,format=auto/https://webstudio.is/logo.webp 640w, /cdn-cgi/image/width=750,quality=70,format=auto/https://webstudio.is/logo.webp 750w, /cdn-cgi/image/width=828,quality=70,format=auto/https://webstudio.is/logo.webp 828w, /cdn-cgi/image/width=1080,quality=70,format=auto/https://webstudio.is/logo.webp 1080w, /cdn-cgi/image/width=1200,quality=70,format=auto/https://webstudio.is/logo.webp 1200w, /cdn-cgi/image/width=1920,quality=70,format=auto/https://webstudio.is/logo.webp 1920w, /cdn-cgi/image/width=2048,quality=70,format=auto/https://webstudio.is/logo.webp 2048w, /cdn-cgi/image/width=3840,quality=70,format=auto/https://webstudio.is/logo.webp 3840w",
+ }
+ `);
+ });
+
+ test("width is undefined and size defined, creates 'w' descriptor and use input sizes props, resizeOrigin defined", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: undefined,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: "100vw",
+ quality: 70,
+ loader: cloudflareImageLoader({
+ resizeOrigin: "https://resize-origin.is",
+ }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "sizes": "100vw",
+ "src": "https://resize-origin.is/cdn-cgi/image/width=3840,quality=70,format=auto/https://webstudio.is/logo.webp",
+ "srcSet": "https://resize-origin.is/cdn-cgi/image/width=640,quality=70,format=auto/https://webstudio.is/logo.webp 640w, https://resize-origin.is/cdn-cgi/image/width=750,quality=70,format=auto/https://webstudio.is/logo.webp 750w, https://resize-origin.is/cdn-cgi/image/width=828,quality=70,format=auto/https://webstudio.is/logo.webp 828w, https://resize-origin.is/cdn-cgi/image/width=1080,quality=70,format=auto/https://webstudio.is/logo.webp 1080w, https://resize-origin.is/cdn-cgi/image/width=1200,quality=70,format=auto/https://webstudio.is/logo.webp 1200w, https://resize-origin.is/cdn-cgi/image/width=1920,quality=70,format=auto/https://webstudio.is/logo.webp 1920w, https://resize-origin.is/cdn-cgi/image/width=2048,quality=70,format=auto/https://webstudio.is/logo.webp 2048w, https://resize-origin.is/cdn-cgi/image/width=3840,quality=70,format=auto/https://webstudio.is/logo.webp 3840w",
+ }
+ `);
+ });
+
+ test("custom loader", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: undefined,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: "100vw",
+ quality: 70,
+ loader: ({ width, src, quality }) =>
+ `${new URL(src).pathname}?w=${width}&q=${quality}`,
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "sizes": "100vw",
+ "src": "/logo.webp?w=3840&q=70",
+ "srcSet": "/logo.webp?w=640&q=70 640w, /logo.webp?w=750&q=70 750w, /logo.webp?w=828&q=70 828w, /logo.webp?w=1080&q=70 1080w, /logo.webp?w=1200&q=70 1200w, /logo.webp?w=1920&q=70 1920w, /logo.webp?w=2048&q=70 2048w, /logo.webp?w=3840&q=70 3840w",
+ }
+ `);
+ });
+});
+
+describe("Image optimizations not applied", () => {
+ test("optimize is false", () => {
+ const imgAttr = getImageAttributes({
+ optimize: false,
+ width: 100,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: undefined,
+ sizes: undefined,
+ quality: 100,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "src": "https://webstudio.is/logo.webp",
+ }
+ `);
+ });
+
+ test("srcSet is defined", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: 100,
+ src: "https://webstudio.is/logo.webp",
+ srcSet: "user-defined-srcset",
+ sizes: undefined,
+ quality: 100,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`
+ {
+ "src": "https://webstudio.is/logo.webp",
+ "srcSet": "user-defined-srcset",
+ }
+ `);
+ });
+
+ test("src is empty", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: 100,
+ src: "",
+ srcSet: undefined,
+ sizes: undefined,
+ quality: 100,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`null`);
+ });
+
+ test("src is undefined", () => {
+ const imgAttr = getImageAttributes({
+ optimize: true,
+ width: 100,
+ src: undefined,
+ srcSet: undefined,
+ sizes: undefined,
+ quality: 100,
+ loader: cloudflareImageLoader({ resizeOrigin: null }),
+ });
+
+ expect(imgAttr).toMatchInlineSnapshot(`null`);
+ });
+});
diff --git a/packages/image/src/image-optimize.ts b/packages/image/src/image-optimize.ts
new file mode 100644
index 0000000000..4888859305
--- /dev/null
+++ b/packages/image/src/image-optimize.ts
@@ -0,0 +1,260 @@
+/**
+ * # Responsive Image component helpers.
+ *
+ * ## Quick summary about img srcset and sizes attributes:
+ *
+ * There are 2 ways to define what image will be loaded in the img property srcset.
+ *
+ * 1. via pixel density descriptor 'x', like `srcset="photo-small.jpg 1x, photo-medium.jpg 1.5x, photo-huge.jpg 2x"`
+ * src will be selected depending on `device-pixel-ratio`.
+ *
+ * 2. via viewport width descriptor 'w' and sizes property containing source size descriptors, like
+ * `srcset="photo-small.jpg 320w, photo-medium.jpg 640w, photo-huge.jpg 1280w"`
+ * `sizes="(max-width: 600px) 400px, (max-width: 1200px) 70vw, 50vw"`
+ *
+ * The browser finds the first matching media query from source size descriptors,
+ * then use source size value to generate internally srcset
+ * with pixel density descriptors dividing width descriptor value by source size value.
+ *
+ * Using the example above for viewport width 800px.
+ * The first matching media query is (max-width: 1200px)
+ * source size value is 70vw equal to 800px * 0,7 = 560px
+ *
+ * browser internal srcset will be (we divide `w` descriptor by source size value):
+ * photo-small.jpg 320/560x, photo-medium.jpg 640/560x, photo-huge.jpg 1280/560x =>
+ * photo-small.jpg 0.57x, photo-medium.jpg 1.14x, photo-huge.jpg 2.28x
+ *
+ * Finally same rules as for pixel density descriptor 'x' are applied.
+ *
+ * ## Algorithm (without optimizations):
+ *
+ * We have a predefined array of all supported image sizes allSizes, this is the real width of an image in pixels.
+ * This is good for caching, as we can cache image with specific width and then use it for different devices.
+ *
+ * > allSizes array is a tradeoff between cache and the best possible image size you deliver to the user.
+ * > If allSizes.length is too small, you will deliver too big images to the user,
+ * > if allSizes.length is too big, you will have many caches misses.
+ *
+ * If img has a defined width property.
+ * 1. find the first value from allSizes which is greater or equal to the width property
+ * 2. use found value to generate srcset with pixel density descriptor 'x'
+ *
+ *
+ * If img has no defined width property.
+ * 1. Generate srcset = allSizes.map((w) => `${getImageSrcAtWidth(w)} ${w}w`)
+ * 2. Use sizes property, or if it is not defined use opinionated DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
+ *
+ * Optimizations applied now:
+ *
+ * - If the sizes property is defined, we can exclude from `srcsets` all images
+ * which are smaller than the `smallestRatio * smallesDeviceSize`
+ *
+ * Future (not implemented) optimizations and improvements:
+ *
+ * - Knowing image size on different viewport widths we can provide nondefault sizes property
+ * - Knowledge of Image aspect-ratio would allow cropping images serverside.
+ * - Early hints for high priority images https://blog.cloudflare.com/early-hints/
+ * - Slow networks optimizations
+ * - 404 etc processing with CSS - https://bitsofco.de/styling-broken-images/ (has some opinionated issues) or js solution with custom user fallback.
+ *
+ * # Attributions
+ *
+ * The MIT License (MIT)
+ *
+ * applies to:
+ *
+ * - https://github.com/vercel/next.js, Copyright (c) 2022 Vercel, Inc.
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2022 Vercel, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+ * is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+export type ImageLoader = (props: {
+ width: number;
+ quality: number;
+ src: string;
+}) => string;
+
+/**
+ * max(...imageSizes) must be less then min(...deviceSizes)
+ **/
+const imageSizes = [16, 32, 48, 64, 96, 128, 256, 384];
+const deviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
+
+export const allSizes = [...imageSizes, ...deviceSizes];
+
+/**
+ * https://github.com/vercel/next.js/blob/canary/packages/next/client/image.tsx
+ **/
+const getWidths = (
+ width: number | undefined,
+ sizes: string | undefined
+): { widths: number[]; kind: "w" | "x" } => {
+ if (sizes) {
+ // Find all the "vw" percent sizes used in the sizes prop
+ const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
+ const percentSizes = [];
+ for (let match; (match = viewportWidthRe.exec(sizes)); match) {
+ percentSizes.push(parseInt(match[2], 10));
+ }
+
+ if (percentSizes.length) {
+ // we can exclude from srcSets all images which are smaller than the smallestRatio * smallesDeviceSize
+ const smallestRatio = Math.min(...percentSizes) * 0.01;
+ return {
+ widths: allSizes.filter((s) => s >= deviceSizes[0] * smallestRatio),
+ kind: "w",
+ };
+ }
+ return { widths: allSizes, kind: "w" };
+ }
+
+ if (width == null) {
+ return { widths: deviceSizes, kind: "w" };
+ }
+
+ const widths = [
+ ...new Set(
+ [width, width * 2].map(
+ (w) => allSizes.find((p) => p >= w) || allSizes[allSizes.length - 1]
+ )
+ ),
+ ];
+ return { widths, kind: "x" };
+};
+
+const generateImgAttrs = ({
+ src,
+ width,
+ quality,
+ sizes,
+ loader,
+}: {
+ src: string;
+ quality: number;
+ width: number | undefined;
+ sizes: string | undefined;
+ loader: ImageLoader;
+}): {
+ src: string;
+ srcSet: string | undefined;
+ sizes: string | undefined;
+} => {
+ const { widths, kind } = getWidths(width, sizes);
+
+ return {
+ sizes: !sizes && kind === "w" ? "100vw" : sizes,
+ srcSet: widths
+ .map(
+ (w, i) =>
+ `${loader({ src, quality, width: w })} ${
+ kind === "w" ? w : i + 1
+ }${kind}`
+ )
+ .join(", "),
+
+ // Must be last, to prevent Safari to load images twice
+ src: loader({
+ src,
+ quality,
+ width: widths[widths.length - 1],
+ }),
+ };
+};
+
+const getInt = (value: unknown): number | undefined => {
+ if (typeof value === "number") {
+ return Math.round(value);
+ }
+
+ if (typeof value === "string") {
+ const vNum = Number.parseFloat(value);
+
+ if (!Number.isNaN(vNum)) {
+ return Math.round(vNum);
+ }
+ }
+
+ return undefined;
+};
+
+/**
+ * DEFAULT_SIZES Just an assumption that most images (except hero and icons) are 100% wide on mobile and 50% on desktop.
+ * For icons width are usually set explicitly so DEFAULT_SIZES is not applied.
+ * For hero images, we can allow in UI to select sizes=100vw explicitly.
+ * Anyway, the best would be to calculate this based on canvas data from different breakpoints.
+ * See ../component-utils/image for detailed description
+ **/
+const DEFAULT_SIZES = "(min-width: 1280px) 50vw, 100vw";
+
+const DEFAULT_QUALITY = 80;
+
+export const getImageAttributes = (props: {
+ src: string | undefined;
+ srcSet: string | undefined;
+ sizes: string | undefined;
+ width: string | number | undefined;
+ quality: string | number | undefined;
+ loader: ImageLoader;
+ optimize: boolean;
+}): {
+ src: string;
+ srcSet?: string;
+ sizes?: string;
+} | null => {
+ const width = getInt(props.width);
+ const quality = Math.max(
+ Math.min(getInt(props.quality) ?? DEFAULT_QUALITY, 100),
+ 0
+ );
+
+ if (props.src != null && props.src != "") {
+ if (props.srcSet == null && props.optimize) {
+ const sizes =
+ props.sizes ?? (props.width == null ? DEFAULT_SIZES : undefined);
+
+ return generateImgAttrs({
+ src: props.src,
+ width,
+ quality,
+ sizes,
+ loader: props.loader,
+ });
+ }
+
+ const resAttrs: {
+ src: string;
+ srcSet?: string;
+ sizes?: string;
+ } = { src: props.src };
+
+ if (props.srcSet != null) {
+ resAttrs.srcSet = props.srcSet;
+ }
+
+ if (props.sizes != null) {
+ resAttrs.sizes = props.sizes;
+ }
+
+ return resAttrs;
+ }
+
+ return null;
+};
diff --git a/packages/image/src/image.tsx b/packages/image/src/image.tsx
new file mode 100644
index 0000000000..c7752d6229
--- /dev/null
+++ b/packages/image/src/image.tsx
@@ -0,0 +1,62 @@
+import { forwardRef, type ElementRef, type ComponentProps } from "react";
+import { getImageAttributes, type ImageLoader } from "./image-optimize";
+
+const defaultTag = "img";
+
+type ImageProps = ComponentProps<typeof defaultTag> & {
+ quality?: number;
+ optimize?: boolean;
+ loader: ImageLoader;
+};
+
+export const Image = forwardRef<ElementRef<typeof defaultTag>, ImageProps>(
+ ({ quality, loader, optimize, ...imageProps }, ref) => {
+ // Temporary set to false, to support previous image behaviour
+ const DEFAULT_OPTIMIZE = false;
+
+ const imageAttributes = getImageAttributes({
+ src: imageProps.src,
+ srcSet: imageProps.srcSet,
+ sizes: imageProps.sizes,
+ width: imageProps.width,
+ quality,
+ loader,
+ optimize: optimize ?? DEFAULT_OPTIMIZE,
+ }) ?? { src: imagePlaceholderSvg };
+
+ return (
+ <img {...imageProps} {...imageAttributes} decoding="async" ref={ref} />
+ );
+ }
+);
+
+Image.defaultProps = {
+ src: "",
+ loading: "lazy",
+};
+
+Image.displayName = "Image";
+
+const imagePlaceholderSvg = `data:image/svg+xml;base64,${btoa(`<svg
+ width="140"
+ height="140"
+ viewBox="0 0 600 600"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <rect width="600" height="600" fill="#CCCCCC" />
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M450 170H150C141.716 170 135 176.716 135 185V415C135 423.284 141.716 430 150 430H450C458.284 430 465 423.284 465 415V185C465 176.716 458.284 170 450 170ZM150 145C127.909 145 110 162.909 110 185V415C110 437.091 127.909 455 150 455H450C472.091 455 490 437.091 490 415V185C490 162.909 472.091 145 450 145H150Z"
+ fill="#A2A2A2"
+ />
+ <path
+ d="M237.135 235.012C237.135 255.723 220.345 272.512 199.635 272.512C178.924 272.512 162.135 255.723 162.135 235.012C162.135 214.301 178.924 197.512 199.635 197.512C220.345 197.512 237.135 214.301 237.135 235.012Z"
+ fill="#A2A2A2"
+ />
+ <path
+ d="M160 405V367.205L221.609 306.364L256.552 338.628L358.161 234L440 316.043V405H160Z"
+ fill="#A2A2A2"
+ />
+</svg>`)}`;
diff --git a/packages/image/src/index.ts b/packages/image/src/index.ts
new file mode 100644
index 0000000000..1049e16356
--- /dev/null
+++ b/packages/image/src/index.ts
@@ -0,0 +1,4 @@
+export { Image } from "./image";
+export type { ImageLoader } from "./image-optimize";
+export { cloudflareImageLoader, localImageLoader } from "./image-loaders";
+export { default as imageProps } from "./__generated__/image.props.json";
diff --git a/packages/react-sdk/storybook-assets/logo.webp b/packages/image/storybook-assets/logo.webp
similarity index 100%
rename from packages/react-sdk/storybook-assets/logo.webp
rename to packages/image/storybook-assets/logo.webp
diff --git a/packages/image/tsconfig.json b/packages/image/tsconfig.json
new file mode 100644
index 0000000000..31fcdc1455
--- /dev/null
+++ b/packages/image/tsconfig.json
@@ -0,0 +1,19 @@
+{
+ // Extends can't use node's resolution rn https://github.com/dividab/tsconfig-paths/issues/209#issuecomment-1177261091
+ "extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
+ "include": ["src", "./src/**/__generated__/*.json"],
+ "compilerOptions": {
+ "module": "ES2020",
+ "target": "ES2020",
+ "strict": true,
+ "baseUrl": ".",
+ "rootDir": "./src",
+ "outDir": "./lib"
+ },
+ // this is auto-generated by update-ts-project-references.ts
+ "references": [
+ {
+ "path": "../generate-arg-types"
+ }
+ ]
+}
diff --git a/packages/jest-config/index.js b/packages/jest-config/index.js
index 4d00255cf3..ef3532e9e2 100644
--- a/packages/jest-config/index.js
+++ b/packages/jest-config/index.js
@@ -8,6 +8,9 @@ module.exports = {
"^.+\\.tsx?$": [
require.resolve("esbuild-jest"),
{
+ // This is needed for inline snapshots to work
+ // See: https://github.com/aelbore/esbuild-jest#setting-up-jest-config-file-with-transformoptions
+ sourcemap: true,
format: "esm",
},
],
diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json
index 6e27b36400..75a168b75b 100644
--- a/packages/react-sdk/package.json
+++ b/packages/react-sdk/package.json
@@ -8,7 +8,7 @@
"scripts": {
"dev": "tsup --watch",
"build": "yarn build:lib",
- "build:args": "tsx ./bin/generate-arg-types.ts './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx'",
+ "build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.json\"",
"typecheck": "tsc --noEmit",
"build:cjs": "tsc --module commonjs --outDir lib/cjs && find lib/cjs -name '*.js' | while read NAME; do mv $NAME ${NAME%.js}.cjs; done",
"build:lib": "rm -fr lib tsconfig.tsbuildinfo && tsc && yarn build:cjs",
@@ -33,15 +33,14 @@
"@storybook/manager-webpack4": "^6.5.6",
"@storybook/react": "^6.5.6",
"@storybook/testing-library": "^0.0.11",
- "@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.21",
"@webstudio-is/jest-config": "*",
"@webstudio-is/prisma-client": "*",
+ "@webstudio-is/generate-arg-types": "*",
"babel-loader": "^8.2.5",
"esbuild": "^0.14.25",
"esbuild-node-externals": "^1.4.1",
"react": "^17.0.2",
- "react-docgen-typescript": "^2.2.2",
"react-dom": "^17.0.2",
"remix-utils": "^4.1.0",
"tsup": "^6.1.3",
diff --git a/packages/react-sdk/src/components/body.props.json b/packages/react-sdk/src/components/__generated__/body.props.json
similarity index 100%
rename from packages/react-sdk/src/components/body.props.json
rename to packages/react-sdk/src/components/__generated__/body.props.json
diff --git a/packages/react-sdk/src/components/bold.props.json b/packages/react-sdk/src/components/__generated__/bold.props.json
similarity index 100%
rename from packages/react-sdk/src/components/bold.props.json
rename to packages/react-sdk/src/components/__generated__/bold.props.json
diff --git a/packages/react-sdk/src/components/box.props.json b/packages/react-sdk/src/components/__generated__/box.props.json
similarity index 100%
rename from packages/react-sdk/src/components/box.props.json
rename to packages/react-sdk/src/components/__generated__/box.props.json
diff --git a/packages/react-sdk/src/components/button.props.json b/packages/react-sdk/src/components/__generated__/button.props.json
similarity index 100%
rename from packages/react-sdk/src/components/button.props.json
rename to packages/react-sdk/src/components/__generated__/button.props.json
diff --git a/packages/react-sdk/src/components/form.props.json b/packages/react-sdk/src/components/__generated__/form.props.json
similarity index 100%
rename from packages/react-sdk/src/components/form.props.json
rename to packages/react-sdk/src/components/__generated__/form.props.json
diff --git a/packages/react-sdk/src/components/heading.props.json b/packages/react-sdk/src/components/__generated__/heading.props.json
similarity index 100%
rename from packages/react-sdk/src/components/heading.props.json
rename to packages/react-sdk/src/components/__generated__/heading.props.json
diff --git a/packages/react-sdk/src/components/__generated__/image.props.json b/packages/react-sdk/src/components/__generated__/image.props.json
new file mode 100644
index 0000000000..cef3c0f367
--- /dev/null
+++ b/packages/react-sdk/src/components/__generated__/image.props.json
@@ -0,0 +1,560 @@
+{
+ "slot": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "style": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "title": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "alt": {
+ "defaultValue": "",
+ "required": false,
+ "type": "text"
+ },
+ "crossOrigin": {
+ "defaultValue": null,
+ "options": ["\"\"", "anonymous", "use-credentials"],
+ "required": false,
+ "type": "radio"
+ },
+ "decoding": {
+ "defaultValue": null,
+ "options": ["async", "auto", "sync"],
+ "required": false,
+ "type": "radio"
+ },
+ "height": {
+ "defaultValue": "",
+ "required": false,
+ "type": "text"
+ },
+ "loading": {
+ "defaultValue": "lazy",
+ "options": ["eager", "lazy"],
+ "required": false,
+ "type": "radio"
+ },
+ "referrerPolicy": {
+ "defaultValue": null,
+ "options": [
+ "\"\"",
+ "no-referrer",
+ "no-referrer-when-downgrade",
+ "origin",
+ "origin-when-cross-origin",
+ "same-origin",
+ "strict-origin",
+ "strict-origin-when-cross-origin",
+ "unsafe-url"
+ ],
+ "required": false,
+ "type": "select"
+ },
+ "sizes": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "src": {
+ "defaultValue": "",
+ "required": false,
+ "type": "text"
+ },
+ "srcSet": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "useMap": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "width": {
+ "defaultValue": "",
+ "required": false,
+ "type": "text"
+ },
+ "defaultChecked": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "defaultValue": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "suppressContentEditableWarning": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "suppressHydrationWarning": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "accessKey": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "className": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "contentEditable": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "contextMenu": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "dir": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "draggable": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "hidden": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "id": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "lang": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "placeholder": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "spellCheck": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "tabIndex": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "translate": {
+ "defaultValue": null,
+ "options": ["yes", "no"],
+ "required": false,
+ "type": "radio"
+ },
+ "radioGroup": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "role": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "about": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "datatype": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "inlist": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "prefix": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "property": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "resource": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "typeof": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "vocab": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "autoCapitalize": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "autoCorrect": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "autoSave": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "color": {
+ "defaultValue": null,
+ "required": false,
+ "type": "color"
+ },
+ "itemProp": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "itemScope": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "itemType": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "itemID": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "itemRef": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "results": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "security": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "unselectable": {
+ "defaultValue": null,
+ "options": ["on", "off"],
+ "required": false,
+ "type": "radio"
+ },
+ "inputMode": {
+ "defaultValue": null,
+ "options": [
+ "text",
+ "none",
+ "search",
+ "tel",
+ "url",
+ "email",
+ "numeric",
+ "decimal"
+ ],
+ "required": false,
+ "type": "select"
+ },
+ "is": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-activedescendant": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-atomic": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-autocomplete": {
+ "defaultValue": null,
+ "options": ["list", "none", "inline", "both"],
+ "required": false,
+ "type": "radio"
+ },
+ "aria-busy": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-checked": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-colcount": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-colindex": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-colspan": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-controls": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-current": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-describedby": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-details": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-disabled": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-dropeffect": {
+ "defaultValue": null,
+ "options": ["link", "none", "copy", "execute", "move", "popup"],
+ "required": false,
+ "type": "select"
+ },
+ "aria-errormessage": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-expanded": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-flowto": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-grabbed": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-haspopup": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-hidden": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-invalid": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-keyshortcuts": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-label": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-labelledby": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-level": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-live": {
+ "defaultValue": null,
+ "options": ["off", "assertive", "polite"],
+ "required": false,
+ "type": "radio"
+ },
+ "aria-modal": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-multiline": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-multiselectable": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-orientation": {
+ "defaultValue": null,
+ "options": ["horizontal", "vertical"],
+ "required": false,
+ "type": "radio"
+ },
+ "aria-owns": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-placeholder": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-posinset": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-pressed": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-readonly": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-relevant": {
+ "defaultValue": null,
+ "options": [
+ "text",
+ "additions",
+ "additions removals",
+ "additions text",
+ "all",
+ "removals",
+ "removals additions",
+ "removals text",
+ "text additions",
+ "text removals"
+ ],
+ "required": false,
+ "type": "select"
+ },
+ "aria-required": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-roledescription": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ },
+ "aria-rowcount": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-rowindex": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-rowspan": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-selected": {
+ "defaultValue": null,
+ "required": false,
+ "type": "boolean"
+ },
+ "aria-setsize": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-sort": {
+ "defaultValue": null,
+ "options": ["none", "ascending", "descending", "other"],
+ "required": false,
+ "type": "radio"
+ },
+ "aria-valuemax": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-valuemin": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-valuenow": {
+ "defaultValue": null,
+ "required": false,
+ "type": "number"
+ },
+ "aria-valuetext": {
+ "defaultValue": null,
+ "required": false,
+ "type": "text"
+ }
+}
diff --git a/packages/react-sdk/src/components/input.props.json b/packages/react-sdk/src/components/__generated__/input.props.json
similarity index 100%
rename from packages/react-sdk/src/components/input.props.json
rename to packages/react-sdk/src/components/__generated__/input.props.json
diff --git a/packages/react-sdk/src/components/italic.props.json b/packages/react-sdk/src/components/__generated__/italic.props.json
similarity index 100%
rename from packages/react-sdk/src/components/italic.props.json
rename to packages/react-sdk/src/components/__generated__/italic.props.json
diff --git a/packages/react-sdk/src/components/link.props.json b/packages/react-sdk/src/components/__generated__/link.props.json
similarity index 100%
rename from packages/react-sdk/src/components/link.props.json
rename to packages/react-sdk/src/components/__generated__/link.props.json
diff --git a/packages/react-sdk/src/components/paragraph.props.json b/packages/react-sdk/src/components/__generated__/paragraph.props.json
similarity index 100%
rename from packages/react-sdk/src/components/paragraph.props.json
rename to packages/react-sdk/src/components/__generated__/paragraph.props.json
diff --git a/packages/react-sdk/src/components/span.props.json b/packages/react-sdk/src/components/__generated__/span.props.json
similarity index 100%
rename from packages/react-sdk/src/components/span.props.json
rename to packages/react-sdk/src/components/__generated__/span.props.json
diff --git a/packages/react-sdk/src/components/subscript.props.json b/packages/react-sdk/src/components/__generated__/subscript.props.json
similarity index 100%
rename from packages/react-sdk/src/components/subscript.props.json
rename to packages/react-sdk/src/components/__generated__/subscript.props.json
diff --git a/packages/react-sdk/src/components/superscript.props.json b/packages/react-sdk/src/components/__generated__/superscript.props.json
similarity index 100%
rename from packages/react-sdk/src/components/superscript.props.json
rename to packages/react-sdk/src/components/__generated__/superscript.props.json
diff --git a/packages/react-sdk/src/components/text-block.props.json b/packages/react-sdk/src/components/__generated__/text-block.props.json
similarity index 100%
rename from packages/react-sdk/src/components/text-block.props.json
rename to packages/react-sdk/src/components/__generated__/text-block.props.json
diff --git a/packages/react-sdk/src/components/meta.ts b/packages/react-sdk/src/components/meta.ts
index 3b1aeeae34..9ecd091efe 100644
--- a/packages/react-sdk/src/components/meta.ts
+++ b/packages/react-sdk/src/components/meta.ts
@@ -1,18 +1,18 @@
-import Body from "./body.props.json";
-import Button from "./button.props.json";
-import Bold from "./bold.props.json";
-import Box from "./box.props.json";
-import Form from "./form.props.json";
-import Heading from "./heading.props.json";
-import Input from "./input.props.json";
-import Italic from "./italic.props.json";
-import Superscript from "./superscript.props.json";
-import Subscript from "./subscript.props.json";
-import Link from "./link.props.json";
-import Paragraph from "./paragraph.props.json";
-import Span from "./span.props.json";
-import TextBlock from "./text-block.props.json";
-import Image from "./image.props.json";
+import Body from "./__generated__/body.props.json";
+import Button from "./__generated__/button.props.json";
+import Bold from "./__generated__/bold.props.json";
+import Box from "./__generated__/box.props.json";
+import Form from "./__generated__/form.props.json";
+import Heading from "./__generated__/heading.props.json";
+import Input from "./__generated__/input.props.json";
+import Italic from "./__generated__/italic.props.json";
+import Superscript from "./__generated__/superscript.props.json";
+import Subscript from "./__generated__/subscript.props.json";
+import Link from "./__generated__/link.props.json";
+import Paragraph from "./__generated__/paragraph.props.json";
+import Span from "./__generated__/span.props.json";
+import TextBlock from "./__generated__/text-block.props.json";
+import Image from "./__generated__/image.props.json";
const meta = {
Body,
diff --git a/packages/react-sdk/tsconfig.json b/packages/react-sdk/tsconfig.json
index 840839883c..651a772bea 100644
--- a/packages/react-sdk/tsconfig.json
+++ b/packages/react-sdk/tsconfig.json
@@ -1,7 +1,7 @@
{
// Extends can't use node's resolution rn https://github.com/dividab/tsconfig-paths/issues/209#issuecomment-1177261091
"extends": "../../node_modules/@webstudio-is/tsconfig/base.json",
- "include": ["./src", "./src/**/*.json", "./@types/**/*.d.ts"],
+ "include": ["./src", "./src/**/__generated__/*.json", "./@types/**/*.d.ts"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"module": "ES2020",
@@ -27,6 +27,10 @@
"path": "../fonts"
},
+ {
+ "path": "../generate-arg-types"
+ },
+
{
"path": "../icons"
},
diff --git a/tsconfig.json b/tsconfig.json
index d9a15062f3..927e224b54 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -9,9 +9,17 @@
{ "path": "packages/css-vars" },
{ "path": "packages/design-system" },
{ "path": "packages/fonts" },
+ { "path": "packages/generate-arg-types" },
{ "path": "packages/http-client" },
{ "path": "packages/icons" },
- { "path": "packages/prisma-client" },
+
+ {
+ "path": "packages/image"
+ },
+
+ {
+ "path": "packages/prisma-client"
+ },
{
"path": "packages/project"
diff --git a/yarn.lock b/yarn.lock
index fcbbbb3d82..ffa83ca1eb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -9641,6 +9641,17 @@ fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"
+fast-glob@^3.2.12:
+ version "3.2.12"
+ resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80"
+ integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==
+ dependencies:
+ "@nodelib/fs.stat" "^2.0.2"
+ "@nodelib/fs.walk" "^1.2.3"
+ glob-parent "^5.1.2"
+ merge2 "^1.3.0"
+ micromatch "^4.0.4"
+
fast-json-parse@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/fast-json-parse/-/fast-json-parse-1.0.3.tgz#43e5c61ee4efa9265633046b770fb682a7577c4d"