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
refactor: move reserved form fields to sdk (#3834)
Bogdan Chadkinc79d56efc72d
diff --git a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsxindex b8a0cf4baf..5616fa5b45 100644--- a/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/routes/[another-page]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsxindex bcc8d52b23..471a41e9bd 100644--- a/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/routes/_index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsxindex 96ea7ae94f..ef72597e6f 100644--- a/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[script-test]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsxindex 8472f5fc59..6a2aea5713 100644--- a/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/[world]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-custom-template/app/routes/_index.tsx b/fixtures/webstudio-custom-template/app/routes/_index.tsxindex bcc8d52b23..471a41e9bd 100644--- a/fixtures/webstudio-custom-template/app/routes/_index.tsx+++ b/fixtures/webstudio-custom-template/app/routes/_index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsxindex b8a0cf4baf..5616fa5b45 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/[another-page]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsxindex bcc8d52b23..471a41e9bd 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/routes/_index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsxindex b8a0cf4baf..5616fa5b45 100644--- a/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/[another-page]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsxindex bcc8d52b23..471a41e9bd 100644--- a/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/routes/_index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsxindex 769cc6a50f..6f3f236e41 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[_route_with_symbols_]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsxindex aef4047d4d..1e3ef05bd8 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[form]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsxindex 5fa1453e95..f2c42210c6 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[heading-with-id]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsxindex 1b0d7e9b8f..7f5e0ba6c4 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[nested].[nested-page]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsxindex a76d753717..42bfb2f46c 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[radix]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsxindex 80e38fe638..1884e1d8bd 100644--- a/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/[resources]._index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx b/fixtures/webstudio-remix-vercel/app/routes/_index.tsxindex bcc8d52b23..471a41e9bd 100644--- a/fixtures/webstudio-remix-vercel/app/routes/_index.tsx+++ b/fixtures/webstudio-remix-vercel/app/routes/_index.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/packages/cli/templates/defaults/app/route-templates/html.tsx b/packages/cli/templates/defaults/app/route-templates/html.tsxindex ea1fa5c0c2..e25d181d6c 100644--- a/packages/cli/templates/defaults/app/route-templates/html.tsx+++ b/packages/cli/templates/defaults/app/route-templates/html.tsx@@ -14,13 +14,11 @@ import {isLocalResource,loadResource,loadResources,-} from "@webstudio-is/sdk";-import { ReactSdkContext } from "@webstudio-is/react-sdk";-import {- n8nHandler,formIdFieldName,formBotFieldName,-} from "@webstudio-is/form-handlers";+} from "@webstudio-is/sdk";+import { ReactSdkContext } from "@webstudio-is/react-sdk";+import { n8nHandler } from "@webstudio-is/form-handlers";import {Page,siteName,diff --git a/packages/form-handlers/src/index.ts b/packages/form-handlers/src/index.tsindex 448db2f464..86725a529b 100644--- a/packages/form-handlers/src/index.ts+++ b/packages/form-handlers/src/index.ts@@ -1,2 +1 @@-export { formIdFieldName, formBotFieldName } from "./shared";export { n8nHandler } from "./n8n";diff --git a/packages/form-handlers/src/shared.ts b/packages/form-handlers/src/shared.tsindex 8520a9c562..615d890500 100644--- a/packages/form-handlers/src/shared.ts+++ b/packages/form-handlers/src/shared.ts@@ -1,8 +1,3 @@-const formHiddenFieldPrefix = "ws--form";-export const formIdFieldName = `${formHiddenFieldPrefix}-id`;-// Used for simlpe protection against non js bots-export const formBotFieldName = `${formHiddenFieldPrefix}-bot`;-// Input data common for all handlersexport type FormInfo = {formId: string;diff --git a/packages/sdk-components-react-remix/package.json b/packages/sdk-components-react-remix/package.jsonindex c5b5e420f3..fbc98cd6fe 100644--- a/packages/sdk-components-react-remix/package.json+++ b/packages/sdk-components-react-remix/package.json@@ -41,9 +41,9 @@"react-dom": "18.3.0-canary-14898b6a9-20240318"},"dependencies": {- "@webstudio-is/form-handlers": "workspace:*","@webstudio-is/icons": "workspace:*","@webstudio-is/react-sdk": "workspace:*",+ "@webstudio-is/sdk": "workspace:*","@webstudio-is/sdk-components-react": "workspace:*"},"devDependencies": {diff --git a/packages/sdk-components-react-remix/src/webhook-form.tsx b/packages/sdk-components-react-remix/src/webhook-form.tsxindex 765b0b8311..89dd4b95c4 100644--- a/packages/sdk-components-react-remix/src/webhook-form.tsx+++ b/packages/sdk-components-react-remix/src/webhook-form.tsx@@ -6,8 +6,7 @@ import {useEffect,} from "react";import { useFetcher, type Fetcher, type FormProps } from "@remix-run/react";-import { formIdFieldName } from "@webstudio-is/form-handlers";-import { formBotFieldName } from "../../form-handlers/src/shared";+import { formIdFieldName, formBotFieldName } from "@webstudio-is/sdk";export const defaultTag = "form";diff --git a/packages/sdk/src/form-fields.ts b/packages/sdk/src/form-fields.tsnew file mode 100644index 0000000000..9d875608b2--- /dev/null+++ b/packages/sdk/src/form-fields.ts@@ -0,0 +1,8 @@+/**+ * Used to identify form inside server handler+ */+export const formIdFieldName = `ws--form-id`;+/**+ * Used for simlpe protection against non js bots+ */+export const formBotFieldName = `ws--form-bot`;diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.tsindex f7b3284bd5..2cad79e292 100644--- a/packages/sdk/src/index.ts+++ b/packages/sdk/src/index.ts@@ -19,3 +19,4 @@ export * from "./expression";export * from "./resources-generator";export * from "./page-meta-generator";export * from "./url-pattern";+export * from "./form-fields";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0e932fbcb4..2ad9724afe 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2016,15 +2016,15 @@ importers:packages/sdk-components-react-remix:dependencies:- '@webstudio-is/form-handlers':- specifier: workspace:*- version: link:../form-handlers'@webstudio-is/icons':specifier: workspace:*version: link:../icons'@webstudio-is/react-sdk':specifier: workspace:*version: link:../react-sdk+ '@webstudio-is/sdk':+ specifier: workspace:*+ version: link:../sdk'@webstudio-is/sdk-components-react':specifier: workspace:*version: link:../sdk-components-react