@webstudio-is/sdk-components-react-remix 0.219.0 → 0.221.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 CHANGED
@@ -1,11 +1,148 @@
1
- import { Body as m } from "./body.js";
2
- import { Link as x, Link as i } from "./link.js";
3
- import { WebhookForm as f } from "./webhook-form.js";
4
- import { RemixForm as p } from "./remix-form.js";
1
+ // src/body.tsx
2
+ import { forwardRef } from "react";
3
+ import { Scripts, ScrollRestoration } from "@remix-run/react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ var Body = forwardRef(
6
+ ({ children, ...props }, ref) => /* @__PURE__ */ jsxs("body", { ...props, ref, children: [
7
+ children,
8
+ /* @__PURE__ */ jsx(Scripts, {}),
9
+ /* @__PURE__ */ jsx(ScrollRestoration, {})
10
+ ] })
11
+ );
12
+ Body.displayName = "Body";
13
+
14
+ // src/link.tsx
15
+ import { forwardRef as forwardRef2, useContext } from "react";
16
+ import { NavLink as RemixLink } from "@remix-run/react";
17
+ import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
18
+ import { Link as BaseLink } from "@webstudio-is/sdk-components-react";
19
+ import { jsx as jsx2 } from "react/jsx-runtime";
20
+ var Link = forwardRef2((props, ref) => {
21
+ const { assetBaseUrl } = useContext(ReactSdkContext);
22
+ const href = String(props.href ?? "");
23
+ if (
24
+ // remix appends ?index in runtime but not in ssr
25
+ href === "" || href.startsWith("?") || href.startsWith("/") && href.startsWith(assetBaseUrl) === false
26
+ ) {
27
+ return /* @__PURE__ */ jsx2(RemixLink, { ...props, to: href, ref, end: true });
28
+ }
29
+ const { prefetch, reloadDocument, replace, preventScrollReset, ...rest } = props;
30
+ return /* @__PURE__ */ jsx2(BaseLink, { ...rest, ref });
31
+ });
32
+ Link.displayName = BaseLink.displayName;
33
+
34
+ // src/webhook-form.tsx
35
+ import {
36
+ forwardRef as forwardRef3,
37
+ useRef,
38
+ useEffect
39
+ } from "react";
40
+ import { useFetcher } from "@remix-run/react";
41
+ import { formIdFieldName, formBotFieldName } from "@webstudio-is/sdk/runtime";
42
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
43
+ var useOnFetchEnd = (fetcher, handler) => {
44
+ const latestHandler = useRef(handler);
45
+ latestHandler.current = handler;
46
+ const prevFetcher = useRef(fetcher);
47
+ useEffect(() => {
48
+ if (prevFetcher.current.state !== fetcher.state && fetcher.state === "idle" && fetcher.data !== void 0) {
49
+ latestHandler.current(fetcher.data);
50
+ }
51
+ prevFetcher.current = fetcher;
52
+ }, [fetcher]);
53
+ };
54
+ var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
55
+ var getAspectRatioString = (width, height) => {
56
+ const r = gcd(width, height);
57
+ const aspectRatio = `${width / r}/${height / r}`;
58
+ return aspectRatio;
59
+ };
60
+ var isJSDom = () => {
61
+ if (typeof matchMedia === "undefined") {
62
+ return true;
63
+ }
64
+ const { width, height } = screen;
65
+ const deviceAspectRatio = getAspectRatioString(width, height);
66
+ const matchAspectRatio = matchMedia(
67
+ `(device-aspect-ratio: ${deviceAspectRatio})`
68
+ ).matches;
69
+ const matchWidthHeight = matchMedia(
70
+ `(device-width: ${width}px) and (device-height: ${height}px)`
71
+ ).matches;
72
+ const matchWidthHeightFail = matchMedia(
73
+ `(device-width: ${width - 1}px) and (device-height: ${height}px)`
74
+ ).matches;
75
+ const matchLight = matchMedia("(prefers-color-scheme: light)").matches;
76
+ const matchDark = matchMedia("(prefers-color-scheme: dark)").matches;
77
+ const hasMatchMedia = matchAspectRatio && matchWidthHeight && !matchWidthHeightFail && matchLight !== matchDark;
78
+ return hasMatchMedia === false;
79
+ };
80
+ var WebhookForm = forwardRef3(
81
+ ({ children, action, method, state = "initial", onStateChange, ...rest }, ref) => {
82
+ const fetcher = useFetcher();
83
+ useOnFetchEnd(fetcher, (data) => {
84
+ const state2 = data?.success === true ? "success" : "error";
85
+ onStateChange?.(state2);
86
+ });
87
+ const handleSubmitAndAddHiddenJsField = (event) => {
88
+ const hiddenInput = document.createElement("input");
89
+ hiddenInput.type = "hidden";
90
+ hiddenInput.name = formBotFieldName;
91
+ hiddenInput.value = isJSDom() ? "jsdom" : Date.now().toString(16);
92
+ event.currentTarget.appendChild(hiddenInput);
93
+ };
94
+ return /* @__PURE__ */ jsxs2(
95
+ fetcher.Form,
96
+ {
97
+ ...rest,
98
+ method: "post",
99
+ "data-state": state,
100
+ ref,
101
+ onSubmit: handleSubmitAndAddHiddenJsField,
102
+ children: [
103
+ /* @__PURE__ */ jsx3(
104
+ "input",
105
+ {
106
+ type: "hidden",
107
+ name: formIdFieldName,
108
+ value: action?.toString()
109
+ }
110
+ ),
111
+ children
112
+ ]
113
+ }
114
+ );
115
+ }
116
+ );
117
+ WebhookForm.displayName = "WebhookForm";
118
+
119
+ // src/remix-form.tsx
120
+ import { forwardRef as forwardRef4 } from "react";
121
+ import { Form } from "@remix-run/react";
122
+ import { jsx as jsx4 } from "react/jsx-runtime";
123
+ var RemixForm = forwardRef4(({ action, method, ...props }, ref) => {
124
+ if (method === "dialog") {
125
+ return /* @__PURE__ */ jsx4("form", { ...props, ref });
126
+ }
127
+ if (action === void 0 || action === "" || typeof action === "string" && action?.startsWith("/")) {
128
+ return /* @__PURE__ */ jsx4(
129
+ Form,
130
+ {
131
+ action,
132
+ method,
133
+ ...props,
134
+ ref,
135
+ preventScrollReset: action === void 0 || action === ""
136
+ }
137
+ );
138
+ }
139
+ return /* @__PURE__ */ jsx4("form", { ...props, ref });
140
+ });
141
+ RemixForm.displayName = "Form";
5
142
  export {
6
- m as Body,
7
- f as Form,
8
- x as Link,
9
- p as RemixForm,
10
- i as RichTextLink
143
+ Body,
144
+ WebhookForm as Form,
145
+ Link,
146
+ RemixForm,
147
+ Link as RichTextLink
11
148
  };
@@ -1,6 +1,6 @@
1
1
  import { type FormProps } from "@remix-run/react";
2
2
  export declare const defaultTag = "form";
3
3
  export declare const RemixForm: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "action"> & Pick<FormProps, "encType"> & {
4
- method?: Lowercase<NonNullable<FormProps["method"]>>;
4
+ method?: Lowercase<NonNullable<FormProps["method"]>> | "dialog";
5
5
  action?: string;
6
6
  }, "ref"> & import("react").RefAttributes<HTMLFormElement>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/sdk-components-react-remix",
3
- "version": "0.219.0",
3
+ "version": "0.221.0",
4
4
  "description": "Webstudio components for Remix",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -17,16 +17,6 @@
17
17
  "webstudio": "./src/components.ts",
18
18
  "types": "./lib/types/components.d.ts",
19
19
  "import": "./lib/components.js"
20
- },
21
- "./metas": {
22
- "webstudio": "./src/metas.ts",
23
- "types": "./lib/types/metas.d.ts",
24
- "import": "./lib/metas.js"
25
- },
26
- "./props": {
27
- "webstudio": "./src/props.ts",
28
- "types": "./lib/types/props.d.ts",
29
- "import": "./lib/props.js"
30
20
  }
31
21
  },
32
22
  "peerDependencies": {
@@ -35,9 +25,9 @@
35
25
  "react-dom": "18.3.0-canary-14898b6a9-20240318"
36
26
  },
37
27
  "dependencies": {
38
- "@webstudio-is/react-sdk": "0.219.0",
39
- "@webstudio-is/sdk": "0.219.0",
40
- "@webstudio-is/sdk-components-react": "0.219.0"
28
+ "@webstudio-is/react-sdk": "0.221.0",
29
+ "@webstudio-is/sdk": "0.221.0",
30
+ "@webstudio-is/sdk-components-react": "0.221.0"
41
31
  },
42
32
  "devDependencies": {
43
33
  "@remix-run/react": "^2.16.5",
@@ -48,7 +38,7 @@
48
38
  "@webstudio-is/tsconfig": "1.0.7"
49
39
  },
50
40
  "scripts": {
51
- "build": "vite build --config ../../vite.sdk-components.config.ts",
41
+ "build": "rm -rf lib && esbuild src/components.ts --outdir=lib --bundle --format=esm --packages=external",
52
42
  "dts": "tsc --project tsconfig.dts.json",
53
43
  "typecheck": "tsc"
54
44
  }
package/lib/body.js DELETED
@@ -1,14 +0,0 @@
1
- import { jsxs as m, jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as s } from "react";
3
- import { Scripts as d, ScrollRestoration as p } from "@remix-run/react";
4
- const e = s(
5
- ({ children: r, ...t }, i) => /* @__PURE__ */ m("body", { ...t, ref: i, children: [
6
- r,
7
- /* @__PURE__ */ o(d, {}),
8
- /* @__PURE__ */ o(p, {})
9
- ] })
10
- );
11
- e.displayName = "Body";
12
- export {
13
- e as Body
14
- };
package/lib/hooks.js DELETED
@@ -1 +0,0 @@
1
-
package/lib/link.js DELETED
@@ -1,19 +0,0 @@
1
- import { jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as n, useContext as m } from "react";
3
- import { NavLink as f } from "@remix-run/react";
4
- import { ReactSdkContext as c } from "@webstudio-is/react-sdk/runtime";
5
- import { Link as s } from "@webstudio-is/sdk-components-react";
6
- const l = n((r, e) => {
7
- const { assetBaseUrl: a } = m(c), t = String(r.href ?? "");
8
- if (
9
- // remix appends ?index in runtime but not in ssr
10
- t === "" || t.startsWith("?") || t.startsWith("/") && t.startsWith(a) === !1
11
- )
12
- return /* @__PURE__ */ o(f, { ...r, to: t, ref: e, end: !0 });
13
- const { prefetch: p, reloadDocument: d, replace: h, preventScrollReset: k, ...i } = r;
14
- return /* @__PURE__ */ o(s, { ...i, ref: e });
15
- });
16
- l.displayName = s.displayName;
17
- export {
18
- l as Link
19
- };
package/lib/metas.js DELETED
@@ -1,8 +0,0 @@
1
- import { Body as m, Form as r, Link as e, RemixForm as x, RichTextLink as k } from "@webstudio-is/sdk-components-react/metas";
2
- export {
3
- m as Body,
4
- r as Form,
5
- e as Link,
6
- x as RemixForm,
7
- k as RichTextLink
8
- };
package/lib/props.js DELETED
@@ -1 +0,0 @@
1
-
package/lib/remix-form.js DELETED
@@ -1,16 +0,0 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import { forwardRef as o } from "react";
3
- import { Form as s } from "@remix-run/react";
4
- const p = o(({ action: r, ...m }, e) => r === void 0 || r === "" || typeof r == "string" && (r != null && r.startsWith("/")) ? /* @__PURE__ */ f(
5
- s,
6
- {
7
- action: r,
8
- ...m,
9
- ref: e,
10
- preventScrollReset: r === void 0 || r === ""
11
- }
12
- ) : /* @__PURE__ */ f("form", { ...m, ref: e }));
13
- p.displayName = "Form";
14
- export {
15
- p as RemixForm
16
- };
package/lib/templates.js DELETED
@@ -1 +0,0 @@
1
-
File without changes
@@ -1 +0,0 @@
1
- export { Body, Link, RichTextLink, Form, RemixForm, } from "@webstudio-is/sdk-components-react/metas";
File without changes
File without changes
@@ -1,63 +0,0 @@
1
- import { jsxs as u, jsx as l } from "react/jsx-runtime";
2
- import { forwardRef as f, useRef as h, useEffect as v } from "react";
3
- import { useFetcher as F } from "@remix-run/react";
4
- import { formIdFieldName as M, formBotFieldName as g } from "@webstudio-is/sdk/runtime";
5
- const x = (t, e) => {
6
- const c = h(e);
7
- c.current = e;
8
- const s = h(t);
9
- v(() => {
10
- s.current.state !== t.state && t.state === "idle" && t.data !== void 0 && c.current(t.data), s.current = t;
11
- }, [t]);
12
- }, p = (t, e) => e === 0 ? t : p(e, t % e), R = (t, e) => {
13
- const c = p(t, e);
14
- return `${t / c}/${e / c}`;
15
- }, $ = () => {
16
- if (typeof matchMedia > "u")
17
- return !0;
18
- const { width: t, height: e } = screen, c = R(t, e), s = matchMedia(
19
- `(device-aspect-ratio: ${c})`
20
- ).matches, o = matchMedia(
21
- `(device-width: ${t}px) and (device-height: ${e}px)`
22
- ).matches, a = matchMedia(
23
- `(device-width: ${t - 1}px) and (device-height: ${e}px)`
24
- ).matches, n = matchMedia("(prefers-color-scheme: light)").matches, d = matchMedia("(prefers-color-scheme: dark)").matches;
25
- return (s && o && !a && n !== d) === !1;
26
- }, A = f(
27
- ({ children: t, action: e, method: c, state: s = "initial", onStateChange: o, ...a }, n) => {
28
- const d = F();
29
- x(d, (r) => {
30
- const i = (r == null ? void 0 : r.success) === !0 ? "success" : "error";
31
- o == null || o(i);
32
- });
33
- const m = (r) => {
34
- const i = document.createElement("input");
35
- i.type = "hidden", i.name = g, i.value = $() ? "jsdom" : Date.now().toString(16), r.currentTarget.appendChild(i);
36
- };
37
- return /* @__PURE__ */ u(
38
- d.Form,
39
- {
40
- ...a,
41
- method: "post",
42
- "data-state": s,
43
- ref: n,
44
- onSubmit: m,
45
- children: [
46
- /* @__PURE__ */ l(
47
- "input",
48
- {
49
- type: "hidden",
50
- name: M,
51
- value: e == null ? void 0 : e.toString()
52
- }
53
- ),
54
- t
55
- ]
56
- }
57
- );
58
- }
59
- );
60
- A.displayName = "WebhookForm";
61
- export {
62
- A as WebhookForm
63
- };