@drawbridge/components 0.1.31 → 0.1.33

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 (69) hide show
  1. package/dist/bridge/template-modal.js +2 -1
  2. package/dist/bridge/template-modal.mjs +2 -1
  3. package/dist/dashboard/buttons-subscription.js +65 -20
  4. package/dist/dashboard/buttons-subscription.mjs +64 -20
  5. package/dist/dashboard/card-payment-method.js +1 -1
  6. package/dist/dashboard/card-payment-method.mjs +1 -1
  7. package/dist/dashboard/card-section.js +2 -2
  8. package/dist/dashboard/card-section.mjs +2 -2
  9. package/dist/dashboard/card-setting.js +4 -3
  10. package/dist/dashboard/card-setting.mjs +4 -3
  11. package/dist/dashboard/card-task.js +22 -4
  12. package/dist/dashboard/card-task.mjs +22 -4
  13. package/dist/dashboard/card-tile.js +6 -6
  14. package/dist/dashboard/card-tile.mjs +6 -6
  15. package/dist/dashboard/drawer.js +7 -2
  16. package/dist/dashboard/drawer.mjs +8 -3
  17. package/dist/dashboard/form-organization-workflow.js +87 -65
  18. package/dist/dashboard/form-organization-workflow.mjs +87 -65
  19. package/dist/dashboard/input-combobox.js +7 -2
  20. package/dist/dashboard/input-combobox.mjs +7 -2
  21. package/dist/dashboard/lib/escape.js +48 -0
  22. package/dist/dashboard/lib/escape.mjs +25 -0
  23. package/dist/dashboard/lib/rail.js +75 -0
  24. package/dist/dashboard/lib/rail.mjs +46 -0
  25. package/dist/dashboard/lib/throttle.js +57 -0
  26. package/dist/dashboard/lib/throttle.mjs +34 -0
  27. package/dist/dashboard/list.js +1 -1
  28. package/dist/dashboard/list.mjs +1 -1
  29. package/dist/dashboard/menu.js +188 -96
  30. package/dist/dashboard/menu.mjs +189 -97
  31. package/dist/dashboard/modal.js +9 -3
  32. package/dist/dashboard/modal.mjs +10 -4
  33. package/dist/dashboard/notice.js +5 -3
  34. package/dist/dashboard/notice.mjs +5 -3
  35. package/dist/dashboard/table-cell-title.js +2 -0
  36. package/dist/dashboard/table-cell-title.mjs +2 -0
  37. package/dist/dashboard/table.js +61 -20
  38. package/dist/dashboard/table.mjs +61 -20
  39. package/dist/dashboard/template-dashboard.js +35 -133
  40. package/dist/dashboard/template-dashboard.mjs +36 -134
  41. package/dist/dashboard/template-rail.js +674 -0
  42. package/dist/dashboard/template-rail.mjs +640 -0
  43. package/dist/dashboard/template-socket.js +19 -3
  44. package/dist/dashboard/template-socket.mjs +19 -3
  45. package/dist/dashboard/template-ui.js +150 -186
  46. package/dist/dashboard/template-ui.mjs +151 -187
  47. package/dist/icons/book-open.js +46 -0
  48. package/dist/icons/book-open.mjs +27 -0
  49. package/dist/icons/task.js +46 -0
  50. package/dist/icons/task.mjs +27 -0
  51. package/dist/shared/lib/helpers.js +9 -2
  52. package/dist/shared/lib/helpers.mjs +9 -2
  53. package/dist/shared/lib/motion.js +27 -0
  54. package/dist/shared/lib/motion.mjs +4 -0
  55. package/dist/shared/overlay.js +5 -3
  56. package/dist/shared/overlay.mjs +5 -3
  57. package/package.json +28 -13
  58. package/types/dashboard/card-task.d.ts +5 -1
  59. package/types/dashboard/lib/rail.d.ts +32 -0
  60. package/types/dashboard/lib/throttle.d.ts +5 -0
  61. package/types/dashboard/table.d.ts +3 -1
  62. package/types/dashboard/template-dashboard.d.ts +4 -1
  63. package/types/dashboard/template-rail.d.ts +36 -0
  64. package/types/dashboard/template-ui.d.ts +2 -2
  65. package/types/icons/book-open.d.ts +5 -0
  66. package/types/icons/task.d.ts +5 -0
  67. package/dist/dashboard/guide.js +0 -238
  68. package/dist/dashboard/guide.mjs +0 -209
  69. package/types/dashboard/guide.d.ts +0 -23
@@ -0,0 +1,46 @@
1
+ const required = (items = []) => items.filter(({ kind }) => kind === "required");
2
+ const railItems = ({
3
+ account,
4
+ campaign,
5
+ organization,
6
+ page,
7
+ params = {},
8
+ path = ""
9
+ }) => {
10
+ var _a, _b, _c, _d, _e, _f;
11
+ if (path.startsWith("/admin")) return [];
12
+ if (!params.organization) return ((_a = account == null ? void 0 : account.tasks) == null ? void 0 : _a.items) || [];
13
+ if (!params.campaign) return ((_b = organization == null ? void 0 : organization.tasks) == null ? void 0 : _b.items) || [];
14
+ const list = ((_c = organization == null ? void 0 : organization.tasks) == null ? void 0 : _c.list) || {};
15
+ const others = Object.keys(list).filter((key) => !["billing", "campaigns"].includes(key));
16
+ return [
17
+ ...params.page ? ((_d = page == null ? void 0 : page.tasks) == null ? void 0 : _d.items) || [] : [],
18
+ ...required((_e = list.billing) == null ? void 0 : _e.items),
19
+ ...((_f = campaign == null ? void 0 : campaign.tasks) == null ? void 0 : _f.items) || [],
20
+ ...others.flatMap((key) => {
21
+ var _a2;
22
+ return required((_a2 = list[key]) == null ? void 0 : _a2.items);
23
+ })
24
+ ];
25
+ };
26
+ const railCount = (items = []) => required(items).length;
27
+ const railFirst = (items = []) => required(items)[0] || items[0];
28
+ const railView = ({ guide, panel }) => panel === "guide" && !guide ? "next" : panel || null;
29
+ const railOverlap = (a, b) => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
30
+ const railOnScreen = (rect, { height, width }) => rect.bottom > 0 && rect.right > 0 && rect.top < height && rect.left < width;
31
+ const railTabTarget = ({ active, items, shift }) => {
32
+ if (items.length === 0) return null;
33
+ const first = items[0];
34
+ const last = items[items.length - 1];
35
+ if (shift) return active === first || !items.includes(active) ? last : null;
36
+ return active === last ? first : null;
37
+ };
38
+ export {
39
+ railCount,
40
+ railFirst,
41
+ railItems,
42
+ railOnScreen,
43
+ railOverlap,
44
+ railTabTarget,
45
+ railView
46
+ };
@@ -0,0 +1,57 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var throttle_exports = {};
19
+ __export(throttle_exports, {
20
+ trailingThrottle: () => trailingThrottle
21
+ });
22
+ module.exports = __toCommonJS(throttle_exports);
23
+ const trailingThrottle = ({
24
+ now = Date.now,
25
+ schedule = setTimeout,
26
+ wait
27
+ }) => {
28
+ const entries = /* @__PURE__ */ new Map();
29
+ return (key, run) => {
30
+ const entry = entries.get(key) || {
31
+ last: -Infinity,
32
+ pending: false
33
+ };
34
+ entries.set(key, entry);
35
+ entry.run = run;
36
+ if (entry.pending) return;
37
+ const left = entry.last + wait - now();
38
+ if (left <= 0) {
39
+ entry.last = now();
40
+ run();
41
+ return;
42
+ }
43
+ entry.pending = true;
44
+ schedule(
45
+ () => {
46
+ entry.last = now();
47
+ entry.pending = false;
48
+ entry.run();
49
+ },
50
+ left
51
+ );
52
+ };
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ trailingThrottle
57
+ });
@@ -0,0 +1,34 @@
1
+ const trailingThrottle = ({
2
+ now = Date.now,
3
+ schedule = setTimeout,
4
+ wait
5
+ }) => {
6
+ const entries = /* @__PURE__ */ new Map();
7
+ return (key, run) => {
8
+ const entry = entries.get(key) || {
9
+ last: -Infinity,
10
+ pending: false
11
+ };
12
+ entries.set(key, entry);
13
+ entry.run = run;
14
+ if (entry.pending) return;
15
+ const left = entry.last + wait - now();
16
+ if (left <= 0) {
17
+ entry.last = now();
18
+ run();
19
+ return;
20
+ }
21
+ entry.pending = true;
22
+ schedule(
23
+ () => {
24
+ entry.last = now();
25
+ entry.pending = false;
26
+ entry.run();
27
+ },
28
+ left
29
+ );
30
+ };
31
+ };
32
+ export {
33
+ trailingThrottle
34
+ };
@@ -49,7 +49,7 @@ const List = ({
49
49
  className
50
50
  },
51
51
  // icon and element shape the row; left in rest they reach the DOM.
52
- children: items.map(({ complete, element, icon, increment, title, ...rest }, key) => {
52
+ children: items.map(({ complete, element, icon, title, ...rest }, key) => {
53
53
  const same = Boolean(rest == null ? void 0 : rest.href) && rest.href === pathname;
54
54
  const linked = Boolean(rest == null ? void 0 : rest.href) && !same;
55
55
  const IconComponent = icon || import_arrow_right.default;
@@ -17,7 +17,7 @@ const List = ({
17
17
  className
18
18
  },
19
19
  // icon and element shape the row; left in rest they reach the DOM.
20
- children: items.map(({ complete, element, icon, increment, title, ...rest }, key) => {
20
+ children: items.map(({ complete, element, icon, title, ...rest }, key) => {
21
21
  const same = Boolean(rest == null ? void 0 : rest.href) && rest.href === pathname;
22
22
  const linked = Boolean(rest == null ? void 0 : rest.href) && !same;
23
23
  const IconComponent = icon || ArrowRight;
@@ -82,6 +82,79 @@ const icons = {
82
82
  star: import_star.default,
83
83
  users: import_users.default
84
84
  };
85
+ const Reveal = ({
86
+ children,
87
+ className,
88
+ shown
89
+ }) => {
90
+ const box = (0, import_react.useRef)(null);
91
+ (0, import_react.useEffect)(
92
+ () => {
93
+ if (box.current) box.current.inert = !shown;
94
+ },
95
+ [shown]
96
+ );
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
+ "div",
99
+ {
100
+ ...{
101
+ className: "grid transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none " + (shown ? "grid-rows-[1fr]" : "grid-rows-[0fr]"),
102
+ ref: box
103
+ },
104
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
+ "div",
106
+ {
107
+ ...{
108
+ className: "min-h-0 overflow-hidden"
109
+ },
110
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
111
+ "div",
112
+ {
113
+ ...{
114
+ className
115
+ },
116
+ children: children.map((child, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
+ "div",
118
+ {
119
+ ...{
120
+ className: "transition-opacity ease-out motion-reduce:transition-none " + (shown ? "opacity-100 duration-150" : "opacity-0 duration-75"),
121
+ ...shown && {
122
+ style: {
123
+ transitionDelay: index * 30 + "ms"
124
+ }
125
+ }
126
+ },
127
+ children: child
128
+ },
129
+ index
130
+ ))
131
+ }
132
+ )
133
+ }
134
+ )
135
+ }
136
+ );
137
+ };
138
+ const opened = /* @__PURE__ */ new Set();
139
+ let primed = false;
140
+ const useShown = (key, open, enabled) => {
141
+ const [shown, setShown] = (0, import_react.useState)(() => primed ? opened.has(key) : open);
142
+ (0, import_react.useEffect)(
143
+ () => {
144
+ if (!enabled) return void 0;
145
+ primed = true;
146
+ if (open) {
147
+ opened.add(key);
148
+ } else {
149
+ opened.delete(key);
150
+ }
151
+ const frame = window.requestAnimationFrame(() => setShown(open));
152
+ return () => window.cancelAnimationFrame(frame);
153
+ },
154
+ [enabled, key, open]
155
+ );
156
+ return shown;
157
+ };
85
158
  const MenuItem = ({
86
159
  active,
87
160
  badge,
@@ -100,6 +173,7 @@ const MenuItem = ({
100
173
  ...rest
101
174
  }) => {
102
175
  const Icon = icons[icon];
176
+ const shown = useShown(rest.href || title, open, children.length > 0);
103
177
  const classes = {
104
178
  row: [
105
179
  "flex items-center justify-between w-full transform duration-300 text-left py-1 rounded",
@@ -215,11 +289,12 @@ const MenuItem = ({
215
289
  children: content
216
290
  }
217
291
  ),
218
- open && children.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
219
- "div",
292
+ children.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
+ Reveal,
220
294
  {
221
295
  ...{
222
- className: "mt-0.5 mb-2"
296
+ className: "pt-0.5 pb-2",
297
+ shown
223
298
  },
224
299
  children: children.map(({ key: childKey, exact, ...props }, key) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
225
300
  MenuItem,
@@ -621,11 +696,10 @@ const MenuAccountDropdown = ({
621
696
  account,
622
697
  balance,
623
698
  actions,
624
- guide,
625
699
  modal,
626
700
  onClick
627
701
  }) => {
628
- var _a, _b, _c, _d, _e, _f, _g;
702
+ var _a, _b, _c, _d, _e;
629
703
  const app = (0, import_react_query.useQuery)({
630
704
  queryKey: ["app"]
631
705
  });
@@ -645,15 +719,6 @@ const MenuAccountDropdown = ({
645
719
  title: "Account"
646
720
  }
647
721
  ];
648
- if (guide) {
649
- items.push({
650
- "data-guide": "menu-item-account-guide",
651
- element: "button",
652
- onClick: actions.guide,
653
- title: "Screen guide"
654
- });
655
- }
656
- ;
657
722
  if (process.env.NEXT_PUBLIC_SUPPORT_URI) {
658
723
  items.push({
659
724
  "data-guide": "menu-item-account-support",
@@ -782,95 +847,122 @@ const MenuAccountDropdown = ({
782
847
  "div",
783
848
  {
784
849
  ...{
785
- className: "flex flex-col justify-between p-6 space-y-4" + (banded ? "" : " border-t border-gray-dark")
850
+ // No space-y: the always-drawn panel would leave its gap under a closed menu;
851
+ // the gap rides inside the panel's reveal.
852
+ className: "flex flex-col justify-between p-6" + (banded ? "" : " border-t border-gray-dark")
786
853
  },
787
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react2.Disclosure, { children: [
788
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
789
- import_react2.DisclosureButton,
790
- {
791
- ...{
792
- as: import_button.default,
793
- variant: "link"
794
- },
795
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
796
- "span",
797
- {
798
- ...{
799
- className: "flex items-center w-full space-x-3"
800
- },
801
- children: [
802
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
803
- "span",
804
- {
805
- ...{
806
- className: "relative w-8 h-8 shrink-0"
807
- },
808
- children: [
809
- Boolean(inbox) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
810
- "span",
811
- {
812
- ...{
813
- className: "w-3 h-3 z-10 flex items-center justify-center absolute -top-[3px] -right-[3px] border-2 border-black rounded-full overflow-hidden"
814
- },
815
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
816
- import_indicator.default,
817
- {
818
- ...{
819
- type: "warning"
854
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Disclosure, { children: ({ open }) => {
855
+ var _a2, _b2;
856
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
857
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
858
+ import_react2.DisclosureButton,
859
+ {
860
+ ...{
861
+ as: import_button.default,
862
+ variant: "link"
863
+ },
864
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
865
+ "span",
866
+ {
867
+ ...{
868
+ className: "flex items-center w-full space-x-3"
869
+ },
870
+ children: [
871
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
872
+ "span",
873
+ {
874
+ ...{
875
+ // The avatar's own size: a fixed w-8 box let the 40 px avatar
876
+ // spill down and right, off the text's centre and into the gap.
877
+ // A gray ring: the black initials circle is otherwise lost on
878
+ // the black sidebar, leaving the dot floating.
879
+ className: "relative flex shrink-0 rounded-full ring-1 ring-gray-dark"
880
+ },
881
+ children: [
882
+ Boolean(inbox) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
883
+ "span",
884
+ {
885
+ ...{
886
+ // On the circle's edge, at its top right.
887
+ className: "w-3 h-3 z-10 flex items-center justify-center absolute top-0 right-0 border-2 border-black rounded-full overflow-hidden"
888
+ },
889
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
890
+ import_indicator.default,
891
+ {
892
+ ...{
893
+ type: "warning"
894
+ }
820
895
  }
896
+ )
897
+ }
898
+ ),
899
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
900
+ import_avatar.default,
901
+ {
902
+ ...{
903
+ email: (_a2 = account == null ? void 0 : account.data) == null ? void 0 : _a2.email,
904
+ image: (_b2 = account == null ? void 0 : account.data) == null ? void 0 : _b2.image,
905
+ name: (0, import_helpers.formatUserName)(account == null ? void 0 : account.data)
821
906
  }
822
- )
823
- }
824
- ),
825
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
826
- import_avatar.default,
827
- {
828
- ...{
829
- email: (_f = account == null ? void 0 : account.data) == null ? void 0 : _f.email,
830
- image: (_g = account == null ? void 0 : account.data) == null ? void 0 : _g.image,
831
- name: (0, import_helpers.formatUserName)(account == null ? void 0 : account.data)
832
907
  }
833
- }
834
- )
835
- ]
836
- }
837
- ),
838
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
839
- "span",
908
+ )
909
+ ]
910
+ }
911
+ ),
912
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
913
+ "span",
914
+ {
915
+ ...{
916
+ className: "w-full flex flex-col text-left leading-none space-y-[3px]"
917
+ },
918
+ children: [
919
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
920
+ "span",
921
+ {
922
+ ...{
923
+ className: "block text-white"
924
+ },
925
+ children: (0, import_helpers.formatUserName)(account == null ? void 0 : account.data)
926
+ }
927
+ ),
928
+ renderStatus()
929
+ ]
930
+ }
931
+ )
932
+ ]
933
+ }
934
+ )
935
+ }
936
+ ),
937
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
938
+ import_react2.DisclosurePanel,
939
+ {
940
+ ...{
941
+ static: true
942
+ },
943
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
944
+ Reveal,
945
+ {
946
+ ...{
947
+ className: "pt-4",
948
+ shown: open
949
+ },
950
+ children: items.map((item, key) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
951
+ MenuItem,
840
952
  {
841
953
  ...{
842
- className: "w-full flex flex-col text-left leading-none space-y-[3px]"
843
- },
844
- children: [
845
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
846
- "span",
847
- {
848
- ...{
849
- className: "block text-white"
850
- },
851
- children: (0, import_helpers.formatUserName)(account == null ? void 0 : account.data)
852
- }
853
- ),
854
- renderStatus()
855
- ]
856
- }
857
- )
858
- ]
859
- }
860
- )
861
- }
862
- ),
863
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.DisclosurePanel, { children: items.map((item, key) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
864
- MenuItem,
865
- {
866
- ...{
867
- ...item,
868
- onClick: item.onClick || onClick
954
+ ...item,
955
+ onClick: item.onClick || onClick
956
+ }
957
+ },
958
+ key
959
+ ))
960
+ }
961
+ )
869
962
  }
870
- },
871
- key
872
- )) })
873
- ] })
963
+ )
964
+ ] });
965
+ } })
874
966
  }
875
967
  )
876
968
  ] });