@drawbridge/components 0.1.39 → 0.1.41

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.
@@ -136,7 +136,7 @@ const SwitchRow = ({ description, lock, onChange, title, value }) => {
136
136
  "p",
137
137
  {
138
138
  ...{
139
- className: "text-xs text-gray-dark"
139
+ className: "text-sm text-gray-dark"
140
140
  },
141
141
  children: description
142
142
  }
@@ -102,7 +102,7 @@ const SwitchRow = ({ description, lock, onChange, title, value }) => {
102
102
  "p",
103
103
  {
104
104
  ...{
105
- className: "text-xs text-gray-dark"
105
+ className: "text-sm text-gray-dark"
106
106
  },
107
107
  children: description
108
108
  }
@@ -108,7 +108,7 @@ const CardTask = ({
108
108
  className: stack ? "break-word w-full space-y-1" : "break-word space-y-1"
109
109
  },
110
110
  children: [
111
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
111
+ (title || badge) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
112
112
  badge && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
113
113
  import_badge.default,
114
114
  {
@@ -76,7 +76,7 @@ const CardTask = ({
76
76
  className: stack ? "break-word w-full space-y-1" : "break-word space-y-1"
77
77
  },
78
78
  children: [
79
- /* @__PURE__ */ jsxs("p", { children: [
79
+ (title || badge) && /* @__PURE__ */ jsxs("p", { children: [
80
80
  badge && /* @__PURE__ */ jsx(
81
81
  Badge,
82
82
  {
@@ -58,7 +58,10 @@ const railItems = ({
58
58
  };
59
59
  const railCount = (items = []) => required(items).length;
60
60
  const railFirst = (items = []) => required(items)[0];
61
- const railView = ({ guide, panel, support }) => panel === "guide" && !guide || panel === "support" && !support ? "next" : panel || null;
61
+ const railView = ({ guide, opened, panel, path, support }) => {
62
+ if (panel === "guide") return guide && opened === path ? "guide" : null;
63
+ return panel === "support" && !support ? "next" : panel || null;
64
+ };
62
65
  const railSupport = ({ organization, params = {}, path = "" }) => Boolean(params.organization && (organization == null ? void 0 : organization.support) === true && !path.startsWith("/admin"));
63
66
  const railOverlap = (a, b) => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
64
67
  const railOnScreen = (rect, { height, width }) => rect.bottom > 0 && rect.right > 0 && rect.top < height && rect.left < width;
@@ -30,7 +30,10 @@ const railItems = ({
30
30
  };
31
31
  const railCount = (items = []) => required(items).length;
32
32
  const railFirst = (items = []) => required(items)[0];
33
- const railView = ({ guide, panel, support }) => panel === "guide" && !guide || panel === "support" && !support ? "next" : panel || null;
33
+ const railView = ({ guide, opened, panel, path, support }) => {
34
+ if (panel === "guide") return guide && opened === path ? "guide" : null;
35
+ return panel === "support" && !support ? "next" : panel || null;
36
+ };
34
37
  const railSupport = ({ organization, params = {}, path = "" }) => Boolean(params.organization && (organization == null ? void 0 : organization.support) === true && !path.startsWith("/admin"));
35
38
  const railOverlap = (a, b) => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
36
39
  const railOnScreen = (rect, { height, width }) => rect.bottom > 0 && rect.right > 0 && rect.top < height && rect.left < width;
@@ -58,8 +58,8 @@ const titles = {
58
58
  };
59
59
  const RING_MS = 3e3;
60
60
  const RAIL_MS = 200;
61
- const useRail = () => {
62
- var _a;
61
+ const useRail = (path) => {
62
+ var _a, _b;
63
63
  const queryClient = (0, import_react_query.useQueryClient)();
64
64
  const rail = (0, import_react_query.useQuery)({
65
65
  queryFn: () => ({
@@ -68,11 +68,13 @@ const useRail = () => {
68
68
  queryKey: ["rail"]
69
69
  });
70
70
  return {
71
- panel: ((_a = rail.data) == null ? void 0 : _a.panel) || null,
71
+ opened: (_a = rail.data) == null ? void 0 : _a.path,
72
+ panel: ((_b = rail.data) == null ? void 0 : _b.panel) || null,
72
73
  set: (panel) => queryClient.setQueryData(
73
74
  ["rail"],
74
75
  {
75
- panel
76
+ panel,
77
+ path
76
78
  }
77
79
  )
78
80
  };
@@ -223,7 +225,7 @@ const ScreenGuide = ({
223
225
  },
224
226
  key
225
227
  )),
226
- step.target !== "body" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
228
+ step.target !== "body" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
227
229
  import_button.default,
228
230
  {
229
231
  ...{
@@ -234,14 +236,6 @@ const ScreenGuide = ({
234
236
  },
235
237
  children: "Show me"
236
238
  }
237
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
238
- "p",
239
- {
240
- ...{
241
- className: "text-sm text-gray-dark"
242
- },
243
- children: "Applies to the whole screen"
244
- }
245
239
  )
246
240
  ]
247
241
  }
@@ -390,7 +384,7 @@ const TemplateRail = ({
390
384
  path = ""
391
385
  }) => {
392
386
  const queryClient = (0, import_react_query.useQueryClient)();
393
- const { panel, set } = useRail();
387
+ const { opened, panel, set } = useRail(path);
394
388
  const items = (0, import_rail.railItems)({
395
389
  account,
396
390
  campaign,
@@ -406,7 +400,9 @@ const TemplateRail = ({
406
400
  });
407
401
  const view = (0, import_rail.railView)({
408
402
  guide,
403
+ opened,
409
404
  panel,
405
+ path,
410
406
  support
411
407
  });
412
408
  const [previous, setPrevious] = (0, import_react.useState)(view);
@@ -427,7 +423,8 @@ const TemplateRail = ({
427
423
  const toggle = (next) => set(view === next ? null : next);
428
424
  const close = () => set(null);
429
425
  const aside = (0, import_react.useRef)(null);
430
- const opened = (0, import_react.useRef)(Boolean(view));
426
+ const nav = (0, import_react.useRef)(null);
427
+ const wasOpen = (0, import_react.useRef)(Boolean(view));
431
428
  const arrived = (0, import_react.useRef)(Boolean(view));
432
429
  if (!view) arrived.current = false;
433
430
  const opener = (0, import_react.useRef)(null);
@@ -487,8 +484,8 @@ const TemplateRail = ({
487
484
  () => {
488
485
  var _a, _b;
489
486
  const open = Boolean(view);
490
- if (open === opened.current) return;
491
- opened.current = open;
487
+ if (open === wasOpen.current) return;
488
+ wasOpen.current = open;
492
489
  if (open) {
493
490
  opener.current = document.activeElement;
494
491
  (_a = aside.current) == null ? void 0 : _a.focus();
@@ -499,6 +496,25 @@ const TemplateRail = ({
499
496
  },
500
497
  [view]
501
498
  );
499
+ (0, import_react.useEffect)(
500
+ () => {
501
+ if (view !== "guide") return void 0;
502
+ const onPointerDown = ({ target }) => {
503
+ var _a, _b;
504
+ if (((_a = aside.current) == null ? void 0 : _a.contains(target)) || ((_b = nav.current) == null ? void 0 : _b.contains(target))) return;
505
+ opener.current = null;
506
+ queryClient.setQueryData(
507
+ ["rail"],
508
+ {
509
+ panel: null
510
+ }
511
+ );
512
+ };
513
+ document.addEventListener("pointerdown", onPointerDown);
514
+ return () => document.removeEventListener("pointerdown", onPointerDown);
515
+ },
516
+ [queryClient, view]
517
+ );
502
518
  const phone = () => window.matchMedia("(max-width: 767px)").matches;
503
519
  (0, import_focus.useTrap)(
504
520
  Boolean(view),
@@ -649,6 +665,7 @@ const TemplateRail = ({
649
665
  {
650
666
  ...{
651
667
  "aria-label": "Rail",
668
+ ref: nav,
652
669
  className: "hidden md:flex flex-col items-center gap-2 w-12 h-full shrink-0 py-3 bg-white border-l border-gray relative z-20"
653
670
  },
654
671
  children: [
@@ -709,7 +726,7 @@ const useRailRows = ({
709
726
  params = {},
710
727
  path = ""
711
728
  }) => {
712
- const { set } = useRail();
729
+ const { set } = useRail(path);
713
730
  const page = useRailPage({ campaign, params, path });
714
731
  const count = (0, import_rail.railCount)((0, import_rail.railItems)({ account, campaign, organization, page, params, path }));
715
732
  return [
@@ -23,8 +23,8 @@ const titles = {
23
23
  };
24
24
  const RING_MS = 3e3;
25
25
  const RAIL_MS = 200;
26
- const useRail = () => {
27
- var _a;
26
+ const useRail = (path) => {
27
+ var _a, _b;
28
28
  const queryClient = useQueryClient();
29
29
  const rail = useQuery({
30
30
  queryFn: () => ({
@@ -33,11 +33,13 @@ const useRail = () => {
33
33
  queryKey: ["rail"]
34
34
  });
35
35
  return {
36
- panel: ((_a = rail.data) == null ? void 0 : _a.panel) || null,
36
+ opened: (_a = rail.data) == null ? void 0 : _a.path,
37
+ panel: ((_b = rail.data) == null ? void 0 : _b.panel) || null,
37
38
  set: (panel) => queryClient.setQueryData(
38
39
  ["rail"],
39
40
  {
40
- panel
41
+ panel,
42
+ path
41
43
  }
42
44
  )
43
45
  };
@@ -188,7 +190,7 @@ const ScreenGuide = ({
188
190
  },
189
191
  key
190
192
  )),
191
- step.target !== "body" ? /* @__PURE__ */ jsx(
193
+ step.target !== "body" && /* @__PURE__ */ jsx(
192
194
  Button,
193
195
  {
194
196
  ...{
@@ -199,14 +201,6 @@ const ScreenGuide = ({
199
201
  },
200
202
  children: "Show me"
201
203
  }
202
- ) : /* @__PURE__ */ jsx(
203
- "p",
204
- {
205
- ...{
206
- className: "text-sm text-gray-dark"
207
- },
208
- children: "Applies to the whole screen"
209
- }
210
204
  )
211
205
  ]
212
206
  }
@@ -355,7 +349,7 @@ const TemplateRail = ({
355
349
  path = ""
356
350
  }) => {
357
351
  const queryClient = useQueryClient();
358
- const { panel, set } = useRail();
352
+ const { opened, panel, set } = useRail(path);
359
353
  const items = railItems({
360
354
  account,
361
355
  campaign,
@@ -371,7 +365,9 @@ const TemplateRail = ({
371
365
  });
372
366
  const view = railView({
373
367
  guide,
368
+ opened,
374
369
  panel,
370
+ path,
375
371
  support
376
372
  });
377
373
  const [previous, setPrevious] = useState(view);
@@ -392,7 +388,8 @@ const TemplateRail = ({
392
388
  const toggle = (next) => set(view === next ? null : next);
393
389
  const close = () => set(null);
394
390
  const aside = useRef(null);
395
- const opened = useRef(Boolean(view));
391
+ const nav = useRef(null);
392
+ const wasOpen = useRef(Boolean(view));
396
393
  const arrived = useRef(Boolean(view));
397
394
  if (!view) arrived.current = false;
398
395
  const opener = useRef(null);
@@ -452,8 +449,8 @@ const TemplateRail = ({
452
449
  () => {
453
450
  var _a, _b;
454
451
  const open = Boolean(view);
455
- if (open === opened.current) return;
456
- opened.current = open;
452
+ if (open === wasOpen.current) return;
453
+ wasOpen.current = open;
457
454
  if (open) {
458
455
  opener.current = document.activeElement;
459
456
  (_a = aside.current) == null ? void 0 : _a.focus();
@@ -464,6 +461,25 @@ const TemplateRail = ({
464
461
  },
465
462
  [view]
466
463
  );
464
+ useEffect(
465
+ () => {
466
+ if (view !== "guide") return void 0;
467
+ const onPointerDown = ({ target }) => {
468
+ var _a, _b;
469
+ if (((_a = aside.current) == null ? void 0 : _a.contains(target)) || ((_b = nav.current) == null ? void 0 : _b.contains(target))) return;
470
+ opener.current = null;
471
+ queryClient.setQueryData(
472
+ ["rail"],
473
+ {
474
+ panel: null
475
+ }
476
+ );
477
+ };
478
+ document.addEventListener("pointerdown", onPointerDown);
479
+ return () => document.removeEventListener("pointerdown", onPointerDown);
480
+ },
481
+ [queryClient, view]
482
+ );
467
483
  const phone = () => window.matchMedia("(max-width: 767px)").matches;
468
484
  useTrap(
469
485
  Boolean(view),
@@ -614,6 +630,7 @@ const TemplateRail = ({
614
630
  {
615
631
  ...{
616
632
  "aria-label": "Rail",
633
+ ref: nav,
617
634
  className: "hidden md:flex flex-col items-center gap-2 w-12 h-full shrink-0 py-3 bg-white border-l border-gray relative z-20"
618
635
  },
619
636
  children: [
@@ -674,7 +691,7 @@ const useRailRows = ({
674
691
  params = {},
675
692
  path = ""
676
693
  }) => {
677
- const { set } = useRail();
694
+ const { set } = useRail(path);
678
695
  const page = useRailPage({ campaign, params, path });
679
696
  const count = railCount(railItems({ account, campaign, organization, page, params, path }));
680
697
  return [
@@ -72,10 +72,9 @@ const orderCard = (campaign) => {
72
72
  return {
73
73
  button: {
74
74
  href: "/organizations/" + (campaign == null ? void 0 : campaign.organization) + "/campaigns/" + (campaign == null ? void 0 : campaign.id) + "/form",
75
- text: "Go to Order"
75
+ text: "Edit form"
76
76
  },
77
- message: "The giveaway cannot turn on while the form takes orders",
78
- title: "Turn off Order first",
77
+ message: "Giveaway cannot activate while the form accepts orders.",
79
78
  type: "warning"
80
79
  };
81
80
  };
@@ -45,10 +45,9 @@ const orderCard = (campaign) => {
45
45
  return {
46
46
  button: {
47
47
  href: "/organizations/" + (campaign == null ? void 0 : campaign.organization) + "/campaigns/" + (campaign == null ? void 0 : campaign.id) + "/form",
48
- text: "Go to Order"
48
+ text: "Edit form"
49
49
  },
50
- message: "The giveaway cannot turn on while the form takes orders",
51
- title: "Turn off Order first",
50
+ message: "Giveaway cannot activate while the form accepts orders.",
52
51
  type: "warning"
53
52
  };
54
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawbridge/components",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "exports": {
5
5
  "./advertisement": {
6
6
  "types": "./types/advertisement.d.ts",
@@ -1954,7 +1954,7 @@
1954
1954
  "@analytics/google-tag-manager": "0.5.5",
1955
1955
  "@drawbridge/drawbridge-agents": "0.1.104",
1956
1956
  "@drawbridge/drawbridge-telemetry": "0.0.19",
1957
- "@drawbridge/drawbridge-utils": "0.0.236",
1957
+ "@drawbridge/drawbridge-utils": "0.0.238",
1958
1958
  "@headlessui/react": "2.2.9",
1959
1959
  "@hookform/resolvers": "3.1.1",
1960
1960
  "@sentry/nextjs": "10.58.0",