@webstudio-is/sdk-components-react-radix 0.193.0 → 0.195.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.
@@ -1,13 +1,13 @@
1
- import { AccordionIcon as i, ItemIcon as s, HeaderIcon as l, TriggerIcon as p, ContentIcon as d, ChevronDownIcon as m } from "@webstudio-is/icons/svg";
1
+ import { AccordionIcon as a, ItemIcon as s, HeaderIcon as d, TriggerIcon as l, ContentIcon as p, ChevronDownIcon as m } from "@webstudio-is/icons/svg";
2
2
  import { defaultStates as y } from "@webstudio-is/react-sdk";
3
3
  import { h3 as h, button as A, div as g } from "@webstudio-is/sdk/normalize.css";
4
- import { borderB as u, overflow as f, text as I, pb as b, my as v, flex as e, items as x, justify as C, py as H, font as T, hover as w, underline as S, property as t, state as M, h as q, w as $, shrink as k, transition as Y, duration as B } from "./theme/tailwind-classes.js";
4
+ import { borderB as u, overflow as I, text as f, pb as b, my as v, flex as e, items as C, justify as x, py as H, font as T, hover as q, underline as $, property as t, state as w, h as S, w as M, shrink as k, transition as Y, duration as B } from "./theme/tailwind-classes.js";
5
5
  import { buttonReset as P } from "./theme/styles.js";
6
6
  import { propsAccordion as R, propsAccordionItem as W, propsAccordionHeader as j, propsAccordionTrigger as D, propsAccordionContent as E } from "./__generated__/accordion.props.js";
7
7
  const r = {
8
8
  div: g
9
9
  }, o = [u()].flat(), n = ({
10
- children: a
10
+ children: i
11
11
  }) => ({
12
12
  type: "instance",
13
13
  component: "AccordionHeader",
@@ -21,13 +21,13 @@ const r = {
21
21
  styles: [
22
22
  e(),
23
23
  e(1),
24
- x("center"),
25
- C("between"),
24
+ C("center"),
25
+ x("between"),
26
26
  H(4),
27
27
  T("medium"),
28
- w([S()].flat()),
28
+ q([$()].flat()),
29
29
  t("--accordion-trigger-icon-transform", "0deg"),
30
- M(
30
+ w(
31
31
  [t("--accordion-trigger-icon-transform", "180deg")],
32
32
  "[data-state=open]"
33
33
  )
@@ -36,7 +36,7 @@ const r = {
36
36
  {
37
37
  type: "instance",
38
38
  component: "Text",
39
- children: a
39
+ children: i
40
40
  },
41
41
  {
42
42
  type: "instance",
@@ -45,8 +45,8 @@ const r = {
45
45
  // h-4 w-4 shrink-0 transition-transform duration-200
46
46
  styles: [
47
47
  t("rotate", "--accordion-trigger-icon-transform"),
48
- q(4),
49
- $(4),
48
+ S(4),
49
+ M(4),
50
50
  k(0),
51
51
  Y("all"),
52
52
  B(200)
@@ -71,8 +71,8 @@ const r = {
71
71
  }
72
72
  ]
73
73
  }), c = [
74
- f("hidden"),
75
- I("sm"),
74
+ I("hidden"),
75
+ f("sm"),
76
76
  // transition does not work with display: none
77
77
  // tc.transition("all"),
78
78
  b(4)
@@ -80,9 +80,15 @@ const r = {
80
80
  category: "radix",
81
81
  order: 3,
82
82
  type: "container",
83
- icon: i,
83
+ icon: a,
84
84
  presetStyle: r,
85
85
  description: "A vertically stacked set of interactive headings that each reveal an associated section of content. Clicking on the heading will open the item and close other items.",
86
+ constraints: [
87
+ {
88
+ relation: "descendant",
89
+ component: { $eq: "AccordionItem" }
90
+ }
91
+ ],
86
92
  template: [
87
93
  {
88
94
  type: "instance",
@@ -172,22 +178,37 @@ const r = {
172
178
  type: "container",
173
179
  label: "Item",
174
180
  icon: s,
175
- constraints: {
176
- relation: "ancestor",
177
- component: { $eq: "Accordion" }
178
- },
181
+ constraints: [
182
+ {
183
+ relation: "ancestor",
184
+ component: { $eq: "Accordion" }
185
+ },
186
+ {
187
+ relation: "descendant",
188
+ component: { $eq: "AccordionHeader" }
189
+ },
190
+ {
191
+ relation: "descendant",
192
+ component: { $eq: "AccordionContent" }
193
+ }
194
+ ],
179
195
  indexWithinAncestor: "Accordion",
180
196
  presetStyle: r
181
197
  }, N = {
182
198
  category: "hidden",
183
199
  type: "container",
184
200
  label: "Item Header",
185
- icon: l,
186
- constraints: {
187
- relation: "ancestor",
188
- component: { $eq: "AccordionItem" }
189
- },
190
- detachable: !1,
201
+ icon: d,
202
+ constraints: [
203
+ {
204
+ relation: "ancestor",
205
+ component: { $eq: "AccordionItem" }
206
+ },
207
+ {
208
+ relation: "descendant",
209
+ component: { $eq: "AccordionTrigger" }
210
+ }
211
+ ],
191
212
  presetStyle: {
192
213
  h3: [h, v(0)].flat()
193
214
  }
@@ -195,12 +216,11 @@ const r = {
195
216
  category: "hidden",
196
217
  type: "container",
197
218
  label: "Item Trigger",
198
- icon: p,
219
+ icon: l,
199
220
  constraints: {
200
221
  relation: "ancestor",
201
222
  component: { $eq: "AccordionHeader" }
202
223
  },
203
- detachable: !1,
204
224
  states: [
205
225
  ...y,
206
226
  {
@@ -216,12 +236,11 @@ const r = {
216
236
  category: "hidden",
217
237
  type: "container",
218
238
  label: "Item Content",
219
- icon: d,
239
+ icon: p,
220
240
  constraints: {
221
241
  relation: "ancestor",
222
242
  component: { $eq: "AccordionItem" }
223
243
  },
224
- detachable: !1,
225
244
  presetStyle: r
226
245
  }, X = {
227
246
  props: R,
@@ -1,17 +1,21 @@
1
- import { CheckboxCheckedIcon as n, CheckMarkIcon as r, TriggerIcon as s } from "@webstudio-is/icons/svg";
2
- import { defaultStates as a } from "@webstudio-is/react-sdk";
1
+ import { CheckboxCheckedIcon as a, CheckMarkIcon as r, TriggerIcon as s } from "@webstudio-is/icons/svg";
2
+ import { defaultStates as n } from "@webstudio-is/react-sdk";
3
3
  import { button as i, span as p } from "@webstudio-is/sdk/normalize.css";
4
- import { flex as e, gap as l, items as t, h as d, w as h, shrink as b, rounded as k, border as o, focusVisible as m, outline as y, ring as u, disabled as x, cursor as f, opacity as g, state as C, bg as I, text as c, justify as v } from "./theme/tailwind-classes.js";
4
+ import { flex as e, gap as l, items as t, h as d, w as h, shrink as k, rounded as m, border as o, focusVisible as b, outline as y, ring as u, disabled as x, cursor as C, opacity as g, state as f, bg as I, text as c, justify as v } from "./theme/tailwind-classes.js";
5
5
  import { buttonReset as w } from "./theme/styles.js";
6
- import { propsCheckbox as M, propsCheckboxIndicator as S } from "./__generated__/checkbox.props.js";
7
- const j = {
6
+ import { propsCheckbox as q, propsCheckboxIndicator as M } from "./__generated__/checkbox.props.js";
7
+ const V = {
8
8
  category: "radix",
9
9
  order: 101,
10
10
  type: "container",
11
- icon: n,
11
+ constraints: {
12
+ relation: "descendant",
13
+ component: { $eq: "CheckboxIndicator" }
14
+ },
15
+ icon: a,
12
16
  description: "Use within a form to allow your users to toggle between checked and not checked. Group checkboxes by matching their “Name” properties. Unlike radios, any number of checkboxes in a group can be checked.",
13
17
  states: [
14
- ...a,
18
+ ...n,
15
19
  {
16
20
  label: "Checked",
17
21
  selector: "[data-state=checked]",
@@ -66,15 +70,15 @@ const j = {
66
70
  // We are not supporting peer like styles yet
67
71
  d(4),
68
72
  h(4),
69
- b(0),
70
- k("sm"),
73
+ k(0),
74
+ m("sm"),
71
75
  o(),
72
76
  o("primary"),
73
- m(
77
+ b(
74
78
  [y(), u("ring", 2, "background", 2)].flat()
75
79
  ),
76
- x([f("not-allowed"), g(50)].flat()),
77
- C(
80
+ x([C("not-allowed"), g(50)].flat()),
81
+ f(
78
82
  [I("primary"), c("primaryForeground")].flat(),
79
83
  "[data-state=checked]"
80
84
  )
@@ -118,24 +122,27 @@ const j = {
118
122
  ]
119
123
  }
120
124
  ]
121
- }, q = {
125
+ }, $ = {
122
126
  category: "hidden",
123
127
  type: "container",
124
- detachable: !1,
128
+ constraints: {
129
+ relation: "ancestor",
130
+ component: { $eq: "Checkbox" }
131
+ },
125
132
  icon: s,
126
- states: a,
133
+ states: n,
127
134
  presetStyle: {
128
135
  span: p
129
136
  }
130
- }, E = {
131
- props: M,
137
+ }, j = {
138
+ props: q,
132
139
  initialProps: ["id", "className", "name", "value", "required", "checked"]
133
- }, G = {
134
- props: S
140
+ }, E = {
141
+ props: M
135
142
  };
136
143
  export {
137
- j as metaCheckbox,
138
- q as metaCheckboxIndicator,
139
- E as propsMetaCheckbox,
140
- G as propsMetaCheckboxIndicator
144
+ V as metaCheckbox,
145
+ $ as metaCheckboxIndicator,
146
+ j as propsMetaCheckbox,
147
+ E as propsMetaCheckboxIndicator
141
148
  };
@@ -1,20 +1,31 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { forwardRef as i, Children as l } from "react";
3
- import { Root as a, Trigger as c, Content as p } from "@radix-ui/react-collapsible";
4
- import { getClosestInstance as C } from "@webstudio-is/react-sdk/runtime";
5
- const h = a, g = i(({ children: n, ...o }, t) => {
6
- const e = l.toArray(n)[0];
7
- return /* @__PURE__ */ r(c, { asChild: !0, ref: t, ...o, children: e ?? /* @__PURE__ */ r("button", { children: "Add button" }) });
8
- }), u = p, s = "@webstudio-is/sdk-components-react-radix", x = {
9
- onNavigatorSelect: (n, o) => {
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { forwardRef as r, Children as a } from "react";
3
+ import { Root as c, Trigger as p, Content as C } from "@radix-ui/react-collapsible";
4
+ import { getClosestInstance as l } from "@webstudio-is/react-sdk/runtime";
5
+ const h = c, g = r(({ children: e, ...o }, t) => {
6
+ const n = a.toArray(e)[0];
7
+ return /* @__PURE__ */ i(p, { asChild: !0, ref: t, ...o, children: n ?? /* @__PURE__ */ i("button", { children: "Add button" }) });
8
+ }), u = C, s = "@webstudio-is/sdk-components-react-radix", P = {
9
+ onNavigatorSelect: (e, o) => {
10
10
  for (const t of o.instancePath)
11
11
  if (t.component === `${s}:CollapsibleContent`) {
12
- const e = C(
12
+ const n = l(
13
13
  o.instancePath,
14
14
  t,
15
15
  `${s}:Collapsible`
16
16
  );
17
- e && n.setMemoryProp(e, "open", !0);
17
+ n && e.setMemoryProp(n, "open", !0);
18
+ }
19
+ },
20
+ onNavigatorUnselect: (e, o) => {
21
+ for (const t of o.instancePath)
22
+ if (t.component === `${s}:CollapsibleContent`) {
23
+ const n = l(
24
+ o.instancePath,
25
+ t,
26
+ `${s}:Collapsible`
27
+ );
28
+ n && e.setMemoryProp(n, "open", void 0);
18
29
  }
19
30
  }
20
31
  };
@@ -22,5 +33,5 @@ export {
22
33
  h as Collapsible,
23
34
  u as CollapsibleContent,
24
35
  g as CollapsibleTrigger,
25
- x as hooksCollapsible
36
+ P as hooksCollapsible
26
37
  };
@@ -1,15 +1,25 @@
1
- import { CollapsibleIcon as t, TriggerIcon as o, ContentIcon as n } from "@webstudio-is/icons/svg";
1
+ import { CollapsibleIcon as o, TriggerIcon as t, ContentIcon as n } from "@webstudio-is/icons/svg";
2
2
  import { div as l } from "@webstudio-is/sdk/normalize.css";
3
- import { propsCollapsible as p, propsCollapsibleTrigger as i, propsCollapsibleContent as a } from "./__generated__/collapsible.props.js";
4
- import { getButtonStyles as r } from "./theme/styles.js";
3
+ import { propsCollapsible as p, propsCollapsibleTrigger as i, propsCollapsibleContent as r } from "./__generated__/collapsible.props.js";
4
+ import { getButtonStyles as a } from "./theme/styles.js";
5
5
  const e = {
6
6
  div: l
7
- }, g = {
7
+ }, m = {
8
8
  category: "radix",
9
9
  order: 5,
10
10
  type: "container",
11
+ constraints: [
12
+ {
13
+ relation: "descendant",
14
+ component: { $eq: "CollapsibleTrigger" }
15
+ },
16
+ {
17
+ relation: "descendant",
18
+ component: { $eq: "CollapsibleContent" }
19
+ }
20
+ ],
11
21
  presetStyle: e,
12
- icon: t,
22
+ icon: o,
13
23
  description: "An interactive component which expands and collapses some content, triggered by a button.",
14
24
  template: [
15
25
  {
@@ -24,7 +34,7 @@ const e = {
24
34
  {
25
35
  type: "instance",
26
36
  component: "Button",
27
- styles: r("outline"),
37
+ styles: a("outline"),
28
38
  children: [
29
39
  {
30
40
  type: "text",
@@ -55,18 +65,24 @@ const e = {
55
65
  ]
56
66
  }
57
67
  ]
58
- }, b = {
68
+ }, g = {
59
69
  category: "hidden",
60
70
  type: "container",
61
- icon: o,
71
+ icon: t,
62
72
  stylable: !1,
63
- detachable: !1
64
- }, m = {
73
+ constraints: {
74
+ relation: "ancestor",
75
+ component: { $eq: "Collapsible" }
76
+ }
77
+ }, b = {
65
78
  category: "hidden",
66
79
  type: "container",
67
80
  presetStyle: e,
68
81
  icon: n,
69
- detachable: !1
82
+ constraints: {
83
+ relation: "ancestor",
84
+ component: { $eq: "Collapsible" }
85
+ }
70
86
  }, y = {
71
87
  props: {
72
88
  ...p,
@@ -80,12 +96,12 @@ const e = {
80
96
  }, h = {
81
97
  props: i
82
98
  }, u = {
83
- props: a
99
+ props: r
84
100
  };
85
101
  export {
86
- g as metaCollapsible,
87
- m as metaCollapsibleContent,
88
- b as metaCollapsibleTrigger,
102
+ m as metaCollapsible,
103
+ b as metaCollapsibleContent,
104
+ g as metaCollapsibleTrigger,
89
105
  y as propsMetaCollapsible,
90
106
  u as propsMetaCollapsibleContent,
91
107
  h as propsMetaCollapsibleTrigger
package/lib/dialog.js CHANGED
@@ -1,45 +1,63 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as c, useContext as g, useEffect as h, Children as p, useRef as C } from "react";
3
- import * as i from "@radix-ui/react-dialog";
4
- import { ReactSdkContext as m, getClosestInstance as d } from "@webstudio-is/react-sdk/runtime";
5
- const D = (t) => {
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { forwardRef as c, useContext as h, useCallback as D, useEffect as m, Children as v, useRef as k } from "react";
3
+ import * as a from "@radix-ui/react-dialog";
4
+ import { ReactSdkContext as p, getClosestInstance as d } from "@webstudio-is/react-sdk/runtime";
5
+ import { useControllableState as w } from "@radix-ui/react-use-controllable-state";
6
+ import y from "await-interaction-response";
7
+ const C = (t) => {
6
8
  const { target: e } = t;
7
9
  return !(!(e instanceof HTMLAnchorElement) || e.hasAttribute("href") === !1 || e.href === "#" || e.hasAttribute("target") && e.target === "_blank" || t.ctrlKey || t.metaKey);
8
- }, A = c((t, e) => {
9
- const { open: o, onOpenChange: r } = t, { renderer: s } = g(m);
10
- return h(() => {
11
- if (s !== void 0 || o === !1)
10
+ }, O = c((t, e) => {
11
+ const { renderer: o } = h(p), [n, s] = w({
12
+ prop: t.open,
13
+ defaultProp: !1,
14
+ onChange: t.onOpenChange
15
+ }), r = D(
16
+ async (l) => {
17
+ await y(), s(l);
18
+ },
19
+ [s]
20
+ );
21
+ return m(() => {
22
+ if (o !== void 0 || n === !1)
12
23
  return;
13
- const a = (l) => {
14
- const { target: u } = l;
15
- if (D(l) !== !1) {
16
- if (!(u instanceof HTMLAnchorElement))
24
+ const l = (u) => {
25
+ const { target: g } = u;
26
+ if (C(u) !== !1) {
27
+ if (!(g instanceof HTMLAnchorElement))
17
28
  return !1;
18
- u.closest('[role="dialog"]') && (r == null || r(!1));
29
+ g.closest('[role="dialog"]') && (r == null || r(!1));
19
30
  }
20
31
  };
21
- return window.addEventListener("click", a), () => window.removeEventListener("click", a);
22
- }, [o, r, s]), /* @__PURE__ */ n(i.Root, { ...t });
23
- }), E = c(({ children: t, ...e }, o) => {
24
- const r = p.toArray(t)[0];
25
- return /* @__PURE__ */ n(i.Trigger, { ref: o, asChild: !0, ...e, children: r ?? /* @__PURE__ */ n("button", { children: "Add button or link" }) });
26
- }), P = c((t, e) => /* @__PURE__ */ n(i.DialogPortal, { children: /* @__PURE__ */ n(i.Overlay, { ref: e, ...t }) })), T = c((t, e) => {
27
- const o = C(!1), { renderer: r } = g(m);
28
- return h(() => {
29
- if (r !== void 0)
32
+ return window.addEventListener("click", l), () => window.removeEventListener("click", l);
33
+ }, [n, r, o]), /* @__PURE__ */ i(
34
+ a.Root,
35
+ {
36
+ ...t,
37
+ onOpenChange: r,
38
+ open: n
39
+ }
40
+ );
41
+ }), x = c(({ children: t, ...e }, o) => {
42
+ const n = v.toArray(t)[0];
43
+ return /* @__PURE__ */ i(a.Trigger, { ref: o, asChild: !0, ...e, children: n ?? /* @__PURE__ */ i("button", { children: "Add button or link" }) });
44
+ }), M = c((t, e) => /* @__PURE__ */ i(a.DialogPortal, { children: /* @__PURE__ */ i(a.Overlay, { ref: e, ...t }) })), R = c((t, e) => {
45
+ const o = k(!1), { renderer: n } = h(p);
46
+ return m(() => {
47
+ if (n !== void 0)
30
48
  return;
31
49
  o.current = !1;
32
- const s = (a) => {
33
- const { target: l } = a;
34
- if (D(a) !== !1) {
50
+ const s = (r) => {
51
+ const { target: l } = r;
52
+ if (C(r) !== !1) {
35
53
  if (!(l instanceof HTMLAnchorElement))
36
54
  return !1;
37
55
  l.closest('[role="dialog"]') && (o.current = !0);
38
56
  }
39
57
  };
40
58
  return window.addEventListener("click", s), () => window.removeEventListener("click", s);
41
- }, [r]), /* @__PURE__ */ n(
42
- i.Content,
59
+ }, [n]), /* @__PURE__ */ i(
60
+ a.Content,
43
61
  {
44
62
  ref: e,
45
63
  ...t,
@@ -48,37 +66,37 @@ const D = (t) => {
48
66
  }
49
67
  }
50
68
  );
51
- }), L = i.Close, v = "h1", b = c(({ tag: t = v, children: e, ...o }, r) => /* @__PURE__ */ n(i.DialogTitle, { asChild: !0, children: /* @__PURE__ */ n(t, { ref: r, ...o, children: e }) })), x = i.Description, f = "@webstudio-is/sdk-components-react-radix", M = {
69
+ }), $ = a.Close, A = "h1", N = c(({ tag: t = A, children: e, ...o }, n) => /* @__PURE__ */ i(a.DialogTitle, { asChild: !0, children: /* @__PURE__ */ i(t, { ref: n, ...o, children: e }) })), S = a.Description, f = "@webstudio-is/sdk-components-react-radix", F = {
52
70
  onNavigatorUnselect: (t, e) => {
53
71
  for (const o of e.instancePath)
54
72
  if (o.component === `${f}:DialogOverlay`) {
55
- const r = d(
73
+ const n = d(
56
74
  e.instancePath,
57
75
  o,
58
76
  `${f}:Dialog`
59
77
  );
60
- r && t.setMemoryProp(r, "open", void 0);
78
+ n && t.setMemoryProp(n, "open", void 0);
61
79
  }
62
80
  },
63
81
  onNavigatorSelect: (t, e) => {
64
82
  for (const o of e.instancePath)
65
83
  if (o.component === `${f}:DialogOverlay`) {
66
- const r = d(
84
+ const n = d(
67
85
  e.instancePath,
68
86
  o,
69
87
  `${f}:Dialog`
70
88
  );
71
- r && t.setMemoryProp(r, "open", !0);
89
+ n && t.setMemoryProp(n, "open", !0);
72
90
  }
73
91
  }
74
92
  };
75
93
  export {
76
- A as Dialog,
77
- L as DialogClose,
78
- T as DialogContent,
79
- x as DialogDescription,
80
- P as DialogOverlay,
81
- b as DialogTitle,
82
- E as DialogTrigger,
83
- M as hooksDialog
94
+ O as Dialog,
95
+ $ as DialogClose,
96
+ R as DialogContent,
97
+ S as DialogDescription,
98
+ M as DialogOverlay,
99
+ N as DialogTitle,
100
+ x as DialogTrigger,
101
+ F as hooksDialog
84
102
  };