@webstudio-is/sdk-components-react-remix 0.151.0 → 0.167.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 +70 -10
- package/lib/metas.js +15 -5
- package/lib/props.js +15 -5
- package/lib/types/form-handlers/src/shared.d.ts +33 -0
- package/package.json +10 -13
- /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,11 @@ 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 (
|
|
25
|
+
const href = String(props.href ?? "");
|
|
26
|
+
if (
|
|
27
|
+
// remix appends ?index in runtime but not in ssr
|
|
28
|
+
href === "" || href.startsWith("?") || href.startsWith("#") || href.startsWith("/") && href.startsWith(assetBaseUrl) === false
|
|
29
|
+
) {
|
|
27
30
|
if (renderer !== "canvas" && renderer !== "preview") {
|
|
28
31
|
return /* @__PURE__ */ jsx2(RemixLink, { ...props, to: href, ref });
|
|
29
32
|
}
|
|
@@ -49,8 +52,15 @@ import {
|
|
|
49
52
|
useEffect
|
|
50
53
|
} from "react";
|
|
51
54
|
import { useFetcher } from "@remix-run/react";
|
|
52
|
-
import { formIdFieldName } from "@webstudio-is/form-handlers";
|
|
55
|
+
import { formIdFieldName as formIdFieldName2 } from "@webstudio-is/form-handlers";
|
|
53
56
|
import { getInstanceIdFromComponentProps } from "@webstudio-is/react-sdk";
|
|
57
|
+
|
|
58
|
+
// ../form-handlers/src/shared.ts
|
|
59
|
+
var formHiddenFieldPrefix = "ws--form";
|
|
60
|
+
var formIdFieldName = `${formHiddenFieldPrefix}-id`;
|
|
61
|
+
var formBotFieldName = `${formHiddenFieldPrefix}-bot`;
|
|
62
|
+
|
|
63
|
+
// src/webhook-form.tsx
|
|
54
64
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
55
65
|
var useOnFetchEnd = (fetcher, handler) => {
|
|
56
66
|
const latestHandler = useRef(handler);
|
|
@@ -63,6 +73,32 @@ var useOnFetchEnd = (fetcher, handler) => {
|
|
|
63
73
|
prevFetcher.current = fetcher;
|
|
64
74
|
}, [fetcher]);
|
|
65
75
|
};
|
|
76
|
+
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
77
|
+
var getAspectRatioString = (width, height) => {
|
|
78
|
+
const r = gcd(width, height);
|
|
79
|
+
const aspectRatio = `${width / r}/${height / r}`;
|
|
80
|
+
return aspectRatio;
|
|
81
|
+
};
|
|
82
|
+
var isJSDom = () => {
|
|
83
|
+
if (typeof matchMedia === "undefined") {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
const { width, height } = screen;
|
|
87
|
+
const deviceAspectRatio = getAspectRatioString(width, height);
|
|
88
|
+
const matchAspectRatio = matchMedia(
|
|
89
|
+
`(device-aspect-ratio: ${deviceAspectRatio})`
|
|
90
|
+
).matches;
|
|
91
|
+
const matchWidthHeight = matchMedia(
|
|
92
|
+
`(device-width: ${width}px) and (device-height: ${height}px)`
|
|
93
|
+
).matches;
|
|
94
|
+
const matchWidthHeightFail = matchMedia(
|
|
95
|
+
`(device-width: ${width - 1}px) and (device-height: ${height}px)`
|
|
96
|
+
).matches;
|
|
97
|
+
const matchLight = matchMedia("(prefers-color-scheme: light)").matches;
|
|
98
|
+
const matchDark = matchMedia("(prefers-color-scheme: dark)").matches;
|
|
99
|
+
const hasMatchMedia = matchAspectRatio && matchWidthHeight && !matchWidthHeightFail && matchLight !== matchDark;
|
|
100
|
+
return hasMatchMedia === false;
|
|
101
|
+
};
|
|
66
102
|
var WebhookForm = forwardRef3(
|
|
67
103
|
({ children, action, method, state = "initial", onStateChange, ...rest }, ref) => {
|
|
68
104
|
const fetcher = useFetcher();
|
|
@@ -71,21 +107,45 @@ var WebhookForm = forwardRef3(
|
|
|
71
107
|
const state2 = data?.success === true ? "success" : "error";
|
|
72
108
|
onStateChange?.(state2);
|
|
73
109
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
110
|
+
const handleSubmitAndAddHiddenJsField = (event) => {
|
|
111
|
+
const hiddenInput = document.createElement("input");
|
|
112
|
+
hiddenInput.type = "hidden";
|
|
113
|
+
hiddenInput.name = formBotFieldName;
|
|
114
|
+
hiddenInput.value = isJSDom() ? "jsdom" : Date.now().toString(16);
|
|
115
|
+
event.currentTarget.appendChild(hiddenInput);
|
|
116
|
+
};
|
|
117
|
+
return /* @__PURE__ */ jsxs2(
|
|
118
|
+
fetcher.Form,
|
|
119
|
+
{
|
|
120
|
+
...rest,
|
|
121
|
+
method: "post",
|
|
122
|
+
"data-state": state,
|
|
123
|
+
ref,
|
|
124
|
+
onSubmit: handleSubmitAndAddHiddenJsField,
|
|
125
|
+
children: [
|
|
126
|
+
/* @__PURE__ */ jsx3("input", { type: "hidden", name: formIdFieldName2, value: instanceId }),
|
|
127
|
+
children
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
);
|
|
78
131
|
}
|
|
79
132
|
);
|
|
80
133
|
WebhookForm.displayName = "WebhookForm";
|
|
81
134
|
|
|
82
135
|
// src/remix-form.tsx
|
|
83
|
-
import {
|
|
136
|
+
import {
|
|
137
|
+
forwardRef as forwardRef4,
|
|
138
|
+
useContext as useContext2
|
|
139
|
+
} from "react";
|
|
84
140
|
import { Form } from "@remix-run/react";
|
|
141
|
+
import { ReactSdkContext as ReactSdkContext2 } from "@webstudio-is/react-sdk";
|
|
85
142
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
86
143
|
var RemixForm = forwardRef4((props, ref) => {
|
|
87
|
-
|
|
88
|
-
|
|
144
|
+
const { renderer } = useContext2(ReactSdkContext2);
|
|
145
|
+
if (props.action === void 0 || props.action === "" || props.action?.startsWith("/")) {
|
|
146
|
+
if (renderer !== "canvas" && renderer !== "preview") {
|
|
147
|
+
return /* @__PURE__ */ jsx4(Form, { ...props, ref });
|
|
148
|
+
}
|
|
89
149
|
}
|
|
90
150
|
return /* @__PURE__ */ jsx4("form", { ...props, ref });
|
|
91
151
|
});
|
package/lib/metas.js
CHANGED
|
@@ -639,7 +639,7 @@ var meta = {
|
|
|
639
639
|
{
|
|
640
640
|
type: "instance",
|
|
641
641
|
component: "Label",
|
|
642
|
-
children: [{ type: "text", value: "Name" }]
|
|
642
|
+
children: [{ type: "text", value: "Name", placeholder: true }]
|
|
643
643
|
},
|
|
644
644
|
{
|
|
645
645
|
type: "instance",
|
|
@@ -650,7 +650,7 @@ var meta = {
|
|
|
650
650
|
{
|
|
651
651
|
type: "instance",
|
|
652
652
|
component: "Label",
|
|
653
|
-
children: [{ type: "text", value: "Email" }]
|
|
653
|
+
children: [{ type: "text", value: "Email", placeholder: true }]
|
|
654
654
|
},
|
|
655
655
|
{
|
|
656
656
|
type: "instance",
|
|
@@ -661,7 +661,7 @@ var meta = {
|
|
|
661
661
|
{
|
|
662
662
|
type: "instance",
|
|
663
663
|
component: "Button",
|
|
664
|
-
children: [{ type: "text", value: "Submit" }]
|
|
664
|
+
children: [{ type: "text", value: "Submit", placeholder: true }]
|
|
665
665
|
}
|
|
666
666
|
]
|
|
667
667
|
},
|
|
@@ -677,7 +677,11 @@ var meta = {
|
|
|
677
677
|
}
|
|
678
678
|
],
|
|
679
679
|
children: [
|
|
680
|
-
{
|
|
680
|
+
{
|
|
681
|
+
type: "text",
|
|
682
|
+
value: "Thank you for getting in touch!",
|
|
683
|
+
placeholder: true
|
|
684
|
+
}
|
|
681
685
|
]
|
|
682
686
|
},
|
|
683
687
|
{
|
|
@@ -691,7 +695,13 @@ var meta = {
|
|
|
691
695
|
code: "formState === 'error'"
|
|
692
696
|
}
|
|
693
697
|
],
|
|
694
|
-
children: [
|
|
698
|
+
children: [
|
|
699
|
+
{
|
|
700
|
+
type: "text",
|
|
701
|
+
value: "Sorry, something went wrong.",
|
|
702
|
+
placeholder: true
|
|
703
|
+
}
|
|
704
|
+
]
|
|
695
705
|
}
|
|
696
706
|
]
|
|
697
707
|
}
|
package/lib/props.js
CHANGED
|
@@ -1205,7 +1205,7 @@ var meta = {
|
|
|
1205
1205
|
{
|
|
1206
1206
|
type: "instance",
|
|
1207
1207
|
component: "Label",
|
|
1208
|
-
children: [{ type: "text", value: "Name" }]
|
|
1208
|
+
children: [{ type: "text", value: "Name", placeholder: true }]
|
|
1209
1209
|
},
|
|
1210
1210
|
{
|
|
1211
1211
|
type: "instance",
|
|
@@ -1216,7 +1216,7 @@ var meta = {
|
|
|
1216
1216
|
{
|
|
1217
1217
|
type: "instance",
|
|
1218
1218
|
component: "Label",
|
|
1219
|
-
children: [{ type: "text", value: "Email" }]
|
|
1219
|
+
children: [{ type: "text", value: "Email", placeholder: true }]
|
|
1220
1220
|
},
|
|
1221
1221
|
{
|
|
1222
1222
|
type: "instance",
|
|
@@ -1227,7 +1227,7 @@ var meta = {
|
|
|
1227
1227
|
{
|
|
1228
1228
|
type: "instance",
|
|
1229
1229
|
component: "Button",
|
|
1230
|
-
children: [{ type: "text", value: "Submit" }]
|
|
1230
|
+
children: [{ type: "text", value: "Submit", placeholder: true }]
|
|
1231
1231
|
}
|
|
1232
1232
|
]
|
|
1233
1233
|
},
|
|
@@ -1243,7 +1243,11 @@ var meta = {
|
|
|
1243
1243
|
}
|
|
1244
1244
|
],
|
|
1245
1245
|
children: [
|
|
1246
|
-
{
|
|
1246
|
+
{
|
|
1247
|
+
type: "text",
|
|
1248
|
+
value: "Thank you for getting in touch!",
|
|
1249
|
+
placeholder: true
|
|
1250
|
+
}
|
|
1247
1251
|
]
|
|
1248
1252
|
},
|
|
1249
1253
|
{
|
|
@@ -1257,7 +1261,13 @@ var meta = {
|
|
|
1257
1261
|
code: "formState === 'error'"
|
|
1258
1262
|
}
|
|
1259
1263
|
],
|
|
1260
|
-
children: [
|
|
1264
|
+
children: [
|
|
1265
|
+
{
|
|
1266
|
+
type: "text",
|
|
1267
|
+
value: "Sorry, something went wrong.",
|
|
1268
|
+
placeholder: true
|
|
1269
|
+
}
|
|
1270
|
+
]
|
|
1261
1271
|
}
|
|
1262
1272
|
]
|
|
1263
1273
|
}
|
|
@@ -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.167.0",
|
|
4
4
|
"description": "Webstudio components for Remix",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -16,35 +16,32 @@
|
|
|
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": {
|
|
36
|
-
"@remix-run/react": "^2.9.
|
|
33
|
+
"@remix-run/react": "^2.9.2",
|
|
37
34
|
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
38
35
|
"react-dom": "18.3.0-canary-14898b6a9-20240318"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
|
-
"@webstudio-is/form-handlers": "0.
|
|
42
|
-
"@webstudio-is/
|
|
43
|
-
"@webstudio-is/
|
|
44
|
-
"@webstudio-is/react-sdk": "0.
|
|
38
|
+
"@webstudio-is/form-handlers": "0.167.0",
|
|
39
|
+
"@webstudio-is/sdk-components-react": "0.167.0",
|
|
40
|
+
"@webstudio-is/icons": "0.167.0",
|
|
41
|
+
"@webstudio-is/react-sdk": "0.167.0"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
|
-
"@remix-run/react": "^2.9.
|
|
44
|
+
"@remix-run/react": "^2.9.2",
|
|
48
45
|
"@types/node": "^20.12.7",
|
|
49
46
|
"@types/react": "^18.2.70",
|
|
50
47
|
"@types/react-dom": "^18.2.25",
|
/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
|