@webstudio-is/sdk-components-react-remix 0.91.0 → 0.92.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.
Files changed (44) hide show
  1. package/lib/__generated__/form.props.js +2 -4
  2. package/lib/__generated__/link.props.js +2 -4
  3. package/lib/__generated__/rich-text-link.props.js +2 -4
  4. package/lib/components.js +4 -8
  5. package/lib/form.js +3 -6
  6. package/lib/form.ws.js +3 -6
  7. package/lib/link.js +2 -4
  8. package/lib/link.ws.js +3 -6
  9. package/lib/metas.js +2 -4
  10. package/lib/props.js +4 -8
  11. package/lib/rich-text-link.js +2 -4
  12. package/lib/rich-text-link.ws.js +3 -6
  13. package/lib/shared/remix-link.js +2 -4
  14. package/lib/types/__generated__/form.props.d.ts +1 -1
  15. package/lib/types/__generated__/link.props.d.ts +1 -1
  16. package/lib/types/__generated__/rich-text-link.props.d.ts +1 -1
  17. package/package.json +15 -19
  18. package/lib/cjs/__generated__/form.props.js +0 -591
  19. package/lib/cjs/__generated__/link.props.js +0 -594
  20. package/lib/cjs/__generated__/rich-text-link.props.js +0 -593
  21. package/lib/cjs/components.js +0 -28
  22. package/lib/cjs/form.js +0 -55
  23. package/lib/cjs/form.ws.js +0 -157
  24. package/lib/cjs/link.js +0 -26
  25. package/lib/cjs/link.ws.js +0 -37
  26. package/lib/cjs/metas.js +0 -24
  27. package/lib/cjs/package.json +0 -1
  28. package/lib/cjs/props.js +0 -28
  29. package/lib/cjs/rich-text-link.js +0 -26
  30. package/lib/cjs/rich-text-link.ws.js +0 -27
  31. package/lib/cjs/shared/remix-link.js +0 -46
  32. package/src/__generated__/form.props.ts +0 -642
  33. package/src/__generated__/link.props.ts +0 -641
  34. package/src/__generated__/rich-text-link.props.ts +0 -639
  35. package/src/components.ts +0 -3
  36. package/src/form.tsx +0 -67
  37. package/src/form.ws.tsx +0 -144
  38. package/src/link.tsx +0 -4
  39. package/src/link.ws.ts +0 -16
  40. package/src/metas.ts +0 -1
  41. package/src/props.ts +0 -3
  42. package/src/rich-text-link.tsx +0 -4
  43. package/src/rich-text-link.ws.tsx +0 -6
  44. package/src/shared/remix-link.tsx +0 -46
package/src/form.tsx DELETED
@@ -1,67 +0,0 @@
1
- import {
2
- type ElementRef,
3
- type ComponentProps,
4
- forwardRef,
5
- useRef,
6
- useEffect,
7
- useContext,
8
- } from "react";
9
- import { useFetcher, type Fetcher, type FormProps } from "@remix-run/react";
10
- import { formIdFieldName } from "@webstudio-is/form-handlers";
11
- import {
12
- ReactSdkContext,
13
- getInstanceIdFromComponentProps,
14
- } from "@webstudio-is/react-sdk";
15
-
16
- export const defaultTag = "form";
17
-
18
- const useOnFetchEnd = <Data,>(
19
- fetcher: Fetcher<Data>,
20
- handler: (data: Data) => void
21
- ) => {
22
- const latestHandler = useRef(handler);
23
- latestHandler.current = handler;
24
-
25
- const prevFetcher = useRef(fetcher);
26
- useEffect(() => {
27
- if (
28
- prevFetcher.current.state !== fetcher.state &&
29
- fetcher.state === "idle" &&
30
- fetcher.data !== undefined
31
- ) {
32
- latestHandler.current(fetcher.data);
33
- }
34
- prevFetcher.current = fetcher;
35
- }, [fetcher]);
36
- };
37
-
38
- type State = "initial" | "success" | "error";
39
-
40
- export const Form = forwardRef<
41
- ElementRef<typeof defaultTag>,
42
- ComponentProps<typeof defaultTag> & {
43
- /** Use this property to reveal the Success and Error states on the canvas so they can be styled. The Initial state is displayed when the page first opens. The Success and Error states are displayed depending on whether the Form submits successfully or unsuccessfully. */
44
- state?: State;
45
- encType?: FormProps["encType"];
46
- }
47
- >(({ children, action, method, state = "initial", ...rest }, ref) => {
48
- const { setBoundDataSourceValue } = useContext(ReactSdkContext);
49
-
50
- const fetcher = useFetcher();
51
-
52
- const instanceId = getInstanceIdFromComponentProps(rest);
53
-
54
- useOnFetchEnd(fetcher, (data) => {
55
- const state: State = data?.success === true ? "success" : "error";
56
- setBoundDataSourceValue(instanceId, "state", state);
57
- });
58
-
59
- return (
60
- <fetcher.Form {...rest} method="post" data-state={state} ref={ref}>
61
- <input type="hidden" name={formIdFieldName} value={instanceId} />
62
- {children}
63
- </fetcher.Form>
64
- );
65
- });
66
-
67
- Form.displayName = "Form";
package/src/form.ws.tsx DELETED
@@ -1,144 +0,0 @@
1
- import { FormIcon } from "@webstudio-is/icons/svg";
2
- import { form } from "@webstudio-is/react-sdk/css-normalize";
3
- import {
4
- type PresetStyle,
5
- type WsComponentMeta,
6
- type WsComponentPropsMeta,
7
- showAttribute,
8
- } from "@webstudio-is/react-sdk";
9
- import type { defaultTag } from "./form";
10
- import { props } from "./__generated__/form.props";
11
-
12
- const presetStyle = {
13
- form: [
14
- ...form,
15
- { property: "minHeight", value: { type: "unit", unit: "px", value: 20 } },
16
- ],
17
- } satisfies PresetStyle<typeof defaultTag>;
18
-
19
- export const meta: WsComponentMeta = {
20
- category: "forms",
21
- type: "container",
22
- invalidAncestors: ["Form"],
23
- label: "Form",
24
- description: "Collect information from your users using validation rules.",
25
- icon: FormIcon,
26
- presetStyle,
27
- order: 0,
28
- states: [
29
- { selector: "[data-state=error]", label: "Error" },
30
- { selector: "[data-state=success]", label: "Success" },
31
- ],
32
- template: [
33
- {
34
- type: "instance",
35
- component: "Form",
36
- dataSources: {
37
- formState: { type: "variable", initialValue: "initial" },
38
- },
39
- props: [
40
- {
41
- type: "dataSource",
42
- name: "state",
43
- dataSourceName: "formState",
44
- },
45
- ],
46
- children: [
47
- {
48
- type: "instance",
49
- label: "Form Content",
50
- component: "Box",
51
- dataSources: {
52
- formInitial: {
53
- type: "expression",
54
- code: `formState === 'initial' || formState === 'error'`,
55
- },
56
- },
57
- props: [
58
- {
59
- type: "dataSource",
60
- name: showAttribute,
61
- dataSourceName: "formInitial",
62
- },
63
- ],
64
- children: [
65
- {
66
- type: "instance",
67
- component: "Label",
68
- children: [{ type: "text", value: "Name" }],
69
- },
70
- {
71
- type: "instance",
72
- component: "Input",
73
- props: [{ type: "string", name: "name", value: "name" }],
74
- children: [],
75
- },
76
- {
77
- type: "instance",
78
- component: "Label",
79
- children: [{ type: "text", value: "Email" }],
80
- },
81
- {
82
- type: "instance",
83
- component: "Input",
84
- props: [{ type: "string", name: "name", value: "email" }],
85
- children: [],
86
- },
87
- {
88
- type: "instance",
89
- component: "Button",
90
- children: [{ type: "text", value: "Submit" }],
91
- },
92
- ],
93
- },
94
-
95
- {
96
- type: "instance",
97
- label: "Success Message",
98
- component: "Box",
99
- dataSources: {
100
- formSuccess: {
101
- type: "expression",
102
- code: `formState === 'success'`,
103
- },
104
- },
105
- props: [
106
- {
107
- type: "dataSource",
108
- name: showAttribute,
109
- dataSourceName: "formSuccess",
110
- },
111
- ],
112
- children: [
113
- { type: "text", value: "Thank you for getting in touch!" },
114
- ],
115
- },
116
-
117
- {
118
- type: "instance",
119
- label: "Error Message",
120
- component: "Box",
121
- dataSources: {
122
- formError: {
123
- type: "expression",
124
- code: `formState === 'error'`,
125
- },
126
- },
127
- props: [
128
- {
129
- type: "dataSource",
130
- name: showAttribute,
131
- dataSourceName: "formError",
132
- },
133
- ],
134
- children: [{ type: "text", value: "Sorry, something went wrong." }],
135
- },
136
- ],
137
- },
138
- ],
139
- };
140
-
141
- export const propsMeta: WsComponentPropsMeta = {
142
- props,
143
- initialProps: ["id", "state", "action"],
144
- };
package/src/link.tsx DELETED
@@ -1,4 +0,0 @@
1
- import { Link as BaseLink } from "@webstudio-is/sdk-components-react";
2
- import { wrapLinkComponent } from "./shared/remix-link";
3
-
4
- export const Link = wrapLinkComponent(BaseLink);
package/src/link.ws.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { WsComponentPropsMeta } from "@webstudio-is/react-sdk";
2
- import { props } from "./__generated__/link.props";
3
-
4
- export { Link as meta } from "@webstudio-is/sdk-components-react/metas";
5
-
6
- export const propsMeta: WsComponentPropsMeta = {
7
- props: {
8
- ...props,
9
- href: {
10
- type: "string",
11
- control: "url",
12
- required: false,
13
- },
14
- },
15
- initialProps: ["id", "href", "target", "prefetch"],
16
- };
package/src/metas.ts DELETED
@@ -1 +0,0 @@
1
- export { meta as Form } from "./form.ws";
package/src/props.ts DELETED
@@ -1,3 +0,0 @@
1
- export { propsMeta as Form } from "./form.ws";
2
- export { propsMeta as Link } from "./link.ws";
3
- export { propsMeta as RichTextLink } from "./rich-text-link.ws";
@@ -1,4 +0,0 @@
1
- import { RichTextLink as BaseLink } from "@webstudio-is/sdk-components-react";
2
- import { wrapLinkComponent } from "./shared/remix-link";
3
-
4
- export const RichTextLink = wrapLinkComponent(BaseLink);
@@ -1,6 +0,0 @@
1
- import type { WsComponentPropsMeta } from "@webstudio-is/react-sdk";
2
- import { propsMeta as linkPropsMeta } from "./link.ws";
3
-
4
- export { RichTextLink as meta } from "@webstudio-is/sdk-components-react/metas";
5
-
6
- export const propsMeta: WsComponentPropsMeta = linkPropsMeta;
@@ -1,46 +0,0 @@
1
- import { forwardRef, type ComponentPropsWithoutRef } from "react";
2
- import { NavLink as RemixLink } from "@remix-run/react";
3
- import {
4
- usePropUrl,
5
- getInstanceIdFromComponentProps,
6
- } from "@webstudio-is/react-sdk";
7
- import type { Link } from "@webstudio-is/sdk-components-react";
8
-
9
- type Props = Omit<ComponentPropsWithoutRef<typeof Link>, "target"> & {
10
- // override (string & {}) in target to generate keywords
11
- target?: "_self" | "_blank" | "_parent" | "_top";
12
-
13
- // useful remix props
14
- prefetch?: "none" | "intent" | "render" | "viewport";
15
- reloadDocument?: boolean;
16
- replace?: boolean;
17
- preventScrollReset?: boolean;
18
- };
19
-
20
- export const wrapLinkComponent = (BaseLink: typeof Link) => {
21
- const Component = forwardRef<HTMLAnchorElement, Props>((props, ref) => {
22
- const href = usePropUrl(getInstanceIdFromComponentProps(props), "href");
23
-
24
- if (href?.type === "page") {
25
- let to = href.page.path === "" ? "/" : href.page.path;
26
- const urlTo = new URL(to, "https://any-valid.url");
27
- to = urlTo.pathname;
28
-
29
- if (href.hash !== undefined) {
30
- urlTo.hash = encodeURIComponent(href.hash);
31
- to = `${urlTo.pathname}${urlTo.hash}`;
32
- }
33
-
34
- return <RemixLink {...props} to={to} ref={ref} />;
35
- }
36
-
37
- const { prefetch, reloadDocument, replace, preventScrollReset, ...rest } =
38
- props;
39
-
40
- return <BaseLink {...rest} ref={ref} />;
41
- });
42
-
43
- Component.displayName = BaseLink.displayName;
44
-
45
- return Component;
46
- };