@webstudio-is/sdk-components-react-remix 0.151.0 → 0.163.0
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.
- package/lib/components.js +58 -8
- package/lib/types/form-handlers/src/shared.d.ts +33 -0
- package/package.json +8 -11
- /package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/body.props.d.ts +0 -0
- /package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/link.props.d.ts +0 -0
- /package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/remix-form.props.d.ts +0 -0
- /package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/rich-text-link.props.d.ts +0 -0
- /package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/webhook-form.props.d.ts +0 -0
- /package/lib/types/{body.d.ts → sdk-components-react-remix/src/body.d.ts} +0 -0
- /package/lib/types/{body.ws.d.ts → sdk-components-react-remix/src/body.ws.d.ts} +0 -0
- /package/lib/types/{components.d.ts → sdk-components-react-remix/src/components.d.ts} +0 -0
- /package/lib/types/{link.d.ts → sdk-components-react-remix/src/link.d.ts} +0 -0
- /package/lib/types/{link.ws.d.ts → sdk-components-react-remix/src/link.ws.d.ts} +0 -0
- /package/lib/types/{metas.d.ts → sdk-components-react-remix/src/metas.d.ts} +0 -0
- /package/lib/types/{props.d.ts → sdk-components-react-remix/src/props.d.ts} +0 -0
- /package/lib/types/{remix-form.d.ts → sdk-components-react-remix/src/remix-form.d.ts} +0 -0
- /package/lib/types/{remix-form.ws.d.ts → sdk-components-react-remix/src/remix-form.ws.d.ts} +0 -0
- /package/lib/types/{rich-text-link.d.ts → sdk-components-react-remix/src/rich-text-link.d.ts} +0 -0
- /package/lib/types/{rich-text-link.ws.d.ts → sdk-components-react-remix/src/rich-text-link.ws.d.ts} +0 -0
- /package/lib/types/{shared → sdk-components-react-remix/src/shared}/remix-link.d.ts +0 -0
- /package/lib/types/{webhook-form.d.ts → sdk-components-react-remix/src/webhook-form.d.ts} +0 -0
- /package/lib/types/{webhook-form.ws.d.ts → sdk-components-react-remix/src/webhook-form.ws.d.ts} +0 -0
package/lib/components.js
CHANGED
|
@@ -22,8 +22,8 @@ import { jsx as jsx2 } from "react/jsx-runtime";
|
|
|
22
22
|
var wrapLinkComponent = (BaseLink3) => {
|
|
23
23
|
const Component = forwardRef2((props, ref) => {
|
|
24
24
|
const { assetBaseUrl, renderer } = useContext(ReactSdkContext);
|
|
25
|
-
const href = props.href;
|
|
26
|
-
if (href === "" || href
|
|
25
|
+
const href = String(props.href ?? "");
|
|
26
|
+
if (href === "" || href.startsWith("/") && href.startsWith(assetBaseUrl) === false) {
|
|
27
27
|
if (renderer !== "canvas" && renderer !== "preview") {
|
|
28
28
|
return /* @__PURE__ */ jsx2(RemixLink, { ...props, to: href, ref });
|
|
29
29
|
}
|
|
@@ -49,8 +49,15 @@ import {
|
|
|
49
49
|
useEffect
|
|
50
50
|
} from "react";
|
|
51
51
|
import { useFetcher } from "@remix-run/react";
|
|
52
|
-
import { formIdFieldName } from "@webstudio-is/form-handlers";
|
|
52
|
+
import { formIdFieldName as formIdFieldName2 } from "@webstudio-is/form-handlers";
|
|
53
53
|
import { getInstanceIdFromComponentProps } from "@webstudio-is/react-sdk";
|
|
54
|
+
|
|
55
|
+
// ../form-handlers/src/shared.ts
|
|
56
|
+
var formHiddenFieldPrefix = "ws--form";
|
|
57
|
+
var formIdFieldName = `${formHiddenFieldPrefix}-id`;
|
|
58
|
+
var formBotFieldName = `${formHiddenFieldPrefix}-bot`;
|
|
59
|
+
|
|
60
|
+
// src/webhook-form.tsx
|
|
54
61
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
55
62
|
var useOnFetchEnd = (fetcher, handler) => {
|
|
56
63
|
const latestHandler = useRef(handler);
|
|
@@ -63,6 +70,32 @@ var useOnFetchEnd = (fetcher, handler) => {
|
|
|
63
70
|
prevFetcher.current = fetcher;
|
|
64
71
|
}, [fetcher]);
|
|
65
72
|
};
|
|
73
|
+
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
74
|
+
var getAspectRatioString = (width, height) => {
|
|
75
|
+
const r = gcd(width, height);
|
|
76
|
+
const aspectRatio = `${width / r}/${height / r}`;
|
|
77
|
+
return aspectRatio;
|
|
78
|
+
};
|
|
79
|
+
var isJSDom = () => {
|
|
80
|
+
if (typeof matchMedia === "undefined") {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
const { width, height } = screen;
|
|
84
|
+
const deviceAspectRatio = getAspectRatioString(width, height);
|
|
85
|
+
const matchAspectRatio = matchMedia(
|
|
86
|
+
`(device-aspect-ratio: ${deviceAspectRatio})`
|
|
87
|
+
).matches;
|
|
88
|
+
const matchWidthHeight = matchMedia(
|
|
89
|
+
`(device-width: ${width}px) and (device-height: ${height}px)`
|
|
90
|
+
).matches;
|
|
91
|
+
const matchWidthHeightFail = matchMedia(
|
|
92
|
+
`(device-width: ${width - 1}px) and (device-height: ${height}px)`
|
|
93
|
+
).matches;
|
|
94
|
+
const matchLight = matchMedia("(prefers-color-scheme: light)").matches;
|
|
95
|
+
const matchDark = matchMedia("(prefers-color-scheme: dark)").matches;
|
|
96
|
+
const hasMatchMedia = matchAspectRatio && matchWidthHeight && !matchWidthHeightFail && matchLight !== matchDark;
|
|
97
|
+
return hasMatchMedia === false;
|
|
98
|
+
};
|
|
66
99
|
var WebhookForm = forwardRef3(
|
|
67
100
|
({ children, action, method, state = "initial", onStateChange, ...rest }, ref) => {
|
|
68
101
|
const fetcher = useFetcher();
|
|
@@ -71,10 +104,27 @@ var WebhookForm = forwardRef3(
|
|
|
71
104
|
const state2 = data?.success === true ? "success" : "error";
|
|
72
105
|
onStateChange?.(state2);
|
|
73
106
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
const handleSubmitAndAddHiddenJsField = (event) => {
|
|
108
|
+
const hiddenInput = document.createElement("input");
|
|
109
|
+
hiddenInput.type = "hidden";
|
|
110
|
+
hiddenInput.name = formBotFieldName;
|
|
111
|
+
hiddenInput.value = isJSDom() ? "jsdom" : Date.now().toString(16);
|
|
112
|
+
event.currentTarget.appendChild(hiddenInput);
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsxs2(
|
|
115
|
+
fetcher.Form,
|
|
116
|
+
{
|
|
117
|
+
...rest,
|
|
118
|
+
method: "post",
|
|
119
|
+
"data-state": state,
|
|
120
|
+
ref,
|
|
121
|
+
onSubmit: handleSubmitAndAddHiddenJsField,
|
|
122
|
+
children: [
|
|
123
|
+
/* @__PURE__ */ jsx3("input", { type: "hidden", name: formIdFieldName2, value: instanceId }),
|
|
124
|
+
children
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
78
128
|
}
|
|
79
129
|
);
|
|
80
130
|
WebhookForm.displayName = "WebhookForm";
|
|
@@ -84,7 +134,7 @@ import { forwardRef as forwardRef4 } from "react";
|
|
|
84
134
|
import { Form } from "@remix-run/react";
|
|
85
135
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
86
136
|
var RemixForm = forwardRef4((props, ref) => {
|
|
87
|
-
if (props.action === "" || props.action?.startsWith("/")) {
|
|
137
|
+
if (props.action === void 0 || props.action === "" || props.action?.startsWith("/")) {
|
|
88
138
|
return /* @__PURE__ */ jsx4(Form, { ...props, ref });
|
|
89
139
|
}
|
|
90
140
|
return /* @__PURE__ */ jsx4("form", { ...props, ref });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const formIdFieldName = "ws--form-id";
|
|
2
|
+
export declare const formBotFieldName = "ws--form-bot";
|
|
3
|
+
export type FormInfo = {
|
|
4
|
+
projectId: string;
|
|
5
|
+
pageUrl: string;
|
|
6
|
+
formData: FormData;
|
|
7
|
+
toEmail: string;
|
|
8
|
+
fromEmail: string;
|
|
9
|
+
action: string | null;
|
|
10
|
+
method: "get" | "post";
|
|
11
|
+
};
|
|
12
|
+
export type EmailInfo = {
|
|
13
|
+
from: string;
|
|
14
|
+
to: string;
|
|
15
|
+
txt: string;
|
|
16
|
+
/** Only the body content, requers wrapping into `<!DOCTYPE html><html><body>...</body></html>` */
|
|
17
|
+
html: string;
|
|
18
|
+
subject: string;
|
|
19
|
+
};
|
|
20
|
+
export type Result = {
|
|
21
|
+
success: true;
|
|
22
|
+
} | {
|
|
23
|
+
success: false;
|
|
24
|
+
errors: string[];
|
|
25
|
+
};
|
|
26
|
+
/** Returns form entries that should be send in email: removes `File` entries and `formId` */
|
|
27
|
+
export declare const getFormEntries: (formData: FormData) => [string, string][];
|
|
28
|
+
export declare const formToEmail: ({ formData, pageUrl, toEmail, fromEmail, }: FormInfo) => EmailInfo;
|
|
29
|
+
export declare const getResponseBody: (response: Response) => Promise<{
|
|
30
|
+
text: string;
|
|
31
|
+
json?: Record<string, unknown>;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const getErrors: (json: Record<string, unknown> | undefined) => string[] | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/sdk-components-react-remix",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.163.0",
|
|
4
4
|
"description": "Webstudio components for Remix",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -16,20 +16,17 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"webstudio": "./src/components.ts",
|
|
18
18
|
"types": "./lib/types/components.d.ts",
|
|
19
|
-
"import": "./lib/components.js"
|
|
20
|
-
"require": "./lib/components.js"
|
|
19
|
+
"import": "./lib/components.js"
|
|
21
20
|
},
|
|
22
21
|
"./metas": {
|
|
23
22
|
"webstudio": "./src/metas.ts",
|
|
24
23
|
"types": "./lib/types/metas.d.ts",
|
|
25
|
-
"import": "./lib/metas.js"
|
|
26
|
-
"require": "./lib/metas.js"
|
|
24
|
+
"import": "./lib/metas.js"
|
|
27
25
|
},
|
|
28
26
|
"./props": {
|
|
29
27
|
"webstudio": "./src/props.ts",
|
|
30
28
|
"types": "./lib/types/props.d.ts",
|
|
31
|
-
"import": "./lib/props.js"
|
|
32
|
-
"require": "./lib/props.js"
|
|
29
|
+
"import": "./lib/props.js"
|
|
33
30
|
}
|
|
34
31
|
},
|
|
35
32
|
"peerDependencies": {
|
|
@@ -38,10 +35,10 @@
|
|
|
38
35
|
"react-dom": "18.3.0-canary-14898b6a9-20240318"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
|
-
"@webstudio-is/form-handlers": "0.
|
|
42
|
-
"@webstudio-is/icons": "0.
|
|
43
|
-
"@webstudio-is/sdk
|
|
44
|
-
"@webstudio-is/react
|
|
38
|
+
"@webstudio-is/form-handlers": "0.163.0",
|
|
39
|
+
"@webstudio-is/icons": "0.163.0",
|
|
40
|
+
"@webstudio-is/react-sdk": "0.163.0",
|
|
41
|
+
"@webstudio-is/sdk-components-react": "0.163.0"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
44
|
"@remix-run/react": "^2.9.1",
|
/package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/body.props.d.ts
RENAMED
|
File without changes
|
/package/lib/types/{__generated__ → sdk-components-react-remix/src/__generated__}/link.props.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/types/{rich-text-link.d.ts → sdk-components-react-remix/src/rich-text-link.d.ts}
RENAMED
|
File without changes
|
/package/lib/types/{rich-text-link.ws.d.ts → sdk-components-react-remix/src/rich-text-link.ws.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/types/{webhook-form.ws.d.ts → sdk-components-react-remix/src/webhook-form.ws.d.ts}
RENAMED
|
File without changes
|