@drawbridge/components 0.1.4 → 0.1.6

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 (37) hide show
  1. package/README.md +6 -2
  2. package/dist/bridge/template-subdomain-gallery.js +3 -1
  3. package/dist/bridge/template-subdomain-gallery.mjs +3 -1
  4. package/dist/bridge/template-subdomain.js +8 -2
  5. package/dist/bridge/template-subdomain.mjs +8 -2
  6. package/dist/dashboard/card-task.js +13 -15
  7. package/dist/dashboard/card-task.mjs +13 -15
  8. package/dist/dashboard/drawer-subscription.js +2 -2
  9. package/dist/dashboard/drawer-subscription.mjs +2 -2
  10. package/dist/dashboard/form-action.js +70 -60
  11. package/dist/dashboard/form-action.mjs +71 -61
  12. package/dist/dashboard/form-organization-campaign-link.js +3 -1
  13. package/dist/dashboard/form-organization-campaign-link.mjs +3 -1
  14. package/dist/dashboard/form-organization-connection.js +2 -1
  15. package/dist/dashboard/form-organization-connection.mjs +2 -1
  16. package/dist/dashboard/lib/connection-controls.js +6 -2
  17. package/dist/dashboard/lib/connection-controls.mjs +4 -1
  18. package/dist/dashboard/recharts.js +5 -1
  19. package/dist/dashboard/recharts.mjs +5 -1
  20. package/dist/dashboard/steps.js +67 -10
  21. package/dist/dashboard/steps.mjs +66 -10
  22. package/dist/dashboard/table.js +10 -0
  23. package/dist/dashboard/table.mjs +10 -1
  24. package/dist/dashboard/template-dashboard.js +79 -55
  25. package/dist/dashboard/template-dashboard.mjs +78 -55
  26. package/dist/dashboard/template-socket.js +18 -5
  27. package/dist/dashboard/template-socket.mjs +18 -5
  28. package/dist/shared/lib/video.js +63 -0
  29. package/dist/shared/lib/video.mjs +37 -0
  30. package/dist/video.js +31 -8
  31. package/dist/video.mjs +31 -8
  32. package/package.json +13 -7
  33. package/types/dashboard/form-action.d.ts +5 -2
  34. package/types/dashboard/lib/connection-controls.d.ts +10 -0
  35. package/types/dashboard/recharts.d.ts +3 -0
  36. package/types/dashboard/table.d.ts +2 -0
  37. package/types/shared/lib/video.d.ts +9 -0
@@ -29,10 +29,12 @@ var steps_exports = {};
29
29
  __export(steps_exports, {
30
30
  default: () => steps_default,
31
31
  groupTitle: () => groupTitle,
32
+ replyExcerpt: () => replyExcerpt,
32
33
  rowLabel: () => rowLabel
33
34
  });
34
35
  module.exports = __toCommonJS(steps_exports);
35
36
  var import_jsx_runtime = require("react/jsx-runtime");
37
+ var import_react_query = require("@tanstack/react-query");
36
38
  var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
37
39
  var import_accordion = __toESM(require("./accordion"));
38
40
  var import_paged = __toESM(require("./paged"));
@@ -57,6 +59,14 @@ const indicatorType = (status) => {
57
59
  if (status === "partial" || status === "skipped") return "warning";
58
60
  return "inactive";
59
61
  };
62
+ const replyExcerpt = (response, length = 300) => {
63
+ const wrapped = response && typeof response === "object" && !Array.isArray(response) && Object.keys(response).length === 1 && "body" in response;
64
+ const reply = wrapped ? response.body : response;
65
+ if (reply === void 0 || reply === null) return null;
66
+ const text = (typeof reply === "string" ? reply : JSON.stringify(reply)).replace(/<(script|style)\b[\s\S]*?<\/\1>/gi, " ").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
67
+ if (!text) return null;
68
+ return text.length > length ? text.slice(0, length) + "\u2026" : text;
69
+ };
60
70
  const StepItem = ({
61
71
  updatedAt,
62
72
  error: chunkError,
@@ -69,6 +79,7 @@ const StepItem = ({
69
79
  }) => {
70
80
  const error = chunkError || status === "failed" && message || null;
71
81
  const notice = error || status === "skipped" && message || null;
82
+ const reply = error ? replyExcerpt(response) : null;
72
83
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
73
84
  "div",
74
85
  {
@@ -136,13 +147,51 @@ const StepItem = ({
136
147
  }
137
148
  )
138
149
  },
139
- children: notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
140
- import_card_task.default,
150
+ children: notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
151
+ "div",
141
152
  {
142
153
  ...{
143
- message: notice,
144
- type: error ? "error" : "warning"
145
- }
154
+ className: "space-y-3"
155
+ },
156
+ children: [
157
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
158
+ import_card_task.default,
159
+ {
160
+ ...{
161
+ message: notice,
162
+ type: error ? "error" : "warning"
163
+ }
164
+ }
165
+ ),
166
+ reply && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
167
+ "div",
168
+ {
169
+ ...{
170
+ className: "space-y-1"
171
+ },
172
+ children: [
173
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
174
+ "p",
175
+ {
176
+ ...{
177
+ className: "text-xs text-gray-dark"
178
+ },
179
+ children: "Response"
180
+ }
181
+ ),
182
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
183
+ "p",
184
+ {
185
+ ...{
186
+ className: "text-xs break-words"
187
+ },
188
+ children: reply
189
+ }
190
+ )
191
+ ]
192
+ }
193
+ )
194
+ ]
146
195
  }
147
196
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
197
  import_code_formatter.default,
@@ -175,11 +224,15 @@ const groupTitle = ({ count, email, items, kind, pending }) => {
175
224
  const entries = count + " new " + (count === 1 ? "entry" : "entries");
176
225
  return "Team notification \u2014 " + entries + (pending ? ", sending" : "");
177
226
  };
178
- const rowLabel = ({ item, kind }) => {
179
- if (kind !== "notify") return item == null ? void 0 : item.slug;
227
+ const rowLabel = ({ item, kind, labels = [] }) => {
228
+ var _a;
229
+ if (kind !== "notify") return ((_a = labels.find((option) => option.value === (item == null ? void 0 : item.slug))) == null ? void 0 : _a.key) || (item == null ? void 0 : item.slug);
180
230
  return NOTIFY_LABELS[item == null ? void 0 : item.status] || NOTIFY_LABELS.succeeded;
181
231
  };
182
- const Group = ({ group }) => {
232
+ const Group = ({
233
+ group,
234
+ labels
235
+ }) => {
183
236
  const { items, kind } = group;
184
237
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
185
238
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -206,7 +259,7 @@ const Group = ({ group }) => {
206
259
  {
207
260
  ...{
208
261
  ...item,
209
- label: rowLabel({ item, kind })
262
+ label: rowLabel({ item, kind, labels })
210
263
  }
211
264
  },
212
265
  key
@@ -220,6 +273,8 @@ const Steps = ({
220
273
  limit = 24,
221
274
  organization
222
275
  }) => {
276
+ var _a, _b, _c, _d;
277
+ const labels = (_d = (_c = (_b = (_a = (0, import_react_query.useQueryClient)().getQueryData(["app"])) == null ? void 0 : _a.enums) == null ? void 0 : _b.step) == null ? void 0 : _c.type) == null ? void 0 : _d.options;
223
278
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
224
279
  import_paged.default,
225
280
  {
@@ -245,7 +300,8 @@ const Steps = ({
245
300
  Group,
246
301
  {
247
302
  ...{
248
- group
303
+ group,
304
+ labels
249
305
  }
250
306
  },
251
307
  key
@@ -259,5 +315,6 @@ var steps_default = Steps;
259
315
  // Annotate the CommonJS export names for ESM import in node:
260
316
  0 && (module.exports = {
261
317
  groupTitle,
318
+ replyExcerpt,
262
319
  rowLabel
263
320
  });
@@ -1,4 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useQueryClient } from "@tanstack/react-query";
2
3
  import { capitalize, formatDateString } from "@drawbridge/drawbridge-utils";
3
4
  import Accordion from "./accordion.mjs";
4
5
  import Paged from "./paged.mjs";
@@ -23,6 +24,14 @@ const indicatorType = (status) => {
23
24
  if (status === "partial" || status === "skipped") return "warning";
24
25
  return "inactive";
25
26
  };
27
+ const replyExcerpt = (response, length = 300) => {
28
+ const wrapped = response && typeof response === "object" && !Array.isArray(response) && Object.keys(response).length === 1 && "body" in response;
29
+ const reply = wrapped ? response.body : response;
30
+ if (reply === void 0 || reply === null) return null;
31
+ const text = (typeof reply === "string" ? reply : JSON.stringify(reply)).replace(/<(script|style)\b[\s\S]*?<\/\1>/gi, " ").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
32
+ if (!text) return null;
33
+ return text.length > length ? text.slice(0, length) + "\u2026" : text;
34
+ };
26
35
  const StepItem = ({
27
36
  updatedAt,
28
37
  error: chunkError,
@@ -35,6 +44,7 @@ const StepItem = ({
35
44
  }) => {
36
45
  const error = chunkError || status === "failed" && message || null;
37
46
  const notice = error || status === "skipped" && message || null;
47
+ const reply = error ? replyExcerpt(response) : null;
38
48
  return /* @__PURE__ */ jsxs(
39
49
  "div",
40
50
  {
@@ -102,13 +112,51 @@ const StepItem = ({
102
112
  }
103
113
  )
104
114
  },
105
- children: notice ? /* @__PURE__ */ jsx(
106
- CardTask,
115
+ children: notice ? /* @__PURE__ */ jsxs(
116
+ "div",
107
117
  {
108
118
  ...{
109
- message: notice,
110
- type: error ? "error" : "warning"
111
- }
119
+ className: "space-y-3"
120
+ },
121
+ children: [
122
+ /* @__PURE__ */ jsx(
123
+ CardTask,
124
+ {
125
+ ...{
126
+ message: notice,
127
+ type: error ? "error" : "warning"
128
+ }
129
+ }
130
+ ),
131
+ reply && /* @__PURE__ */ jsxs(
132
+ "div",
133
+ {
134
+ ...{
135
+ className: "space-y-1"
136
+ },
137
+ children: [
138
+ /* @__PURE__ */ jsx(
139
+ "p",
140
+ {
141
+ ...{
142
+ className: "text-xs text-gray-dark"
143
+ },
144
+ children: "Response"
145
+ }
146
+ ),
147
+ /* @__PURE__ */ jsx(
148
+ "p",
149
+ {
150
+ ...{
151
+ className: "text-xs break-words"
152
+ },
153
+ children: reply
154
+ }
155
+ )
156
+ ]
157
+ }
158
+ )
159
+ ]
112
160
  }
113
161
  ) : /* @__PURE__ */ jsx(
114
162
  CodeFormater,
@@ -141,11 +189,15 @@ const groupTitle = ({ count, email, items, kind, pending }) => {
141
189
  const entries = count + " new " + (count === 1 ? "entry" : "entries");
142
190
  return "Team notification \u2014 " + entries + (pending ? ", sending" : "");
143
191
  };
144
- const rowLabel = ({ item, kind }) => {
145
- if (kind !== "notify") return item == null ? void 0 : item.slug;
192
+ const rowLabel = ({ item, kind, labels = [] }) => {
193
+ var _a;
194
+ if (kind !== "notify") return ((_a = labels.find((option) => option.value === (item == null ? void 0 : item.slug))) == null ? void 0 : _a.key) || (item == null ? void 0 : item.slug);
146
195
  return NOTIFY_LABELS[item == null ? void 0 : item.status] || NOTIFY_LABELS.succeeded;
147
196
  };
148
- const Group = ({ group }) => {
197
+ const Group = ({
198
+ group,
199
+ labels
200
+ }) => {
149
201
  const { items, kind } = group;
150
202
  return /* @__PURE__ */ jsxs("div", { children: [
151
203
  /* @__PURE__ */ jsx(
@@ -172,7 +224,7 @@ const Group = ({ group }) => {
172
224
  {
173
225
  ...{
174
226
  ...item,
175
- label: rowLabel({ item, kind })
227
+ label: rowLabel({ item, kind, labels })
176
228
  }
177
229
  },
178
230
  key
@@ -186,6 +238,8 @@ const Steps = ({
186
238
  limit = 24,
187
239
  organization
188
240
  }) => {
241
+ var _a, _b, _c, _d;
242
+ const labels = (_d = (_c = (_b = (_a = useQueryClient().getQueryData(["app"])) == null ? void 0 : _a.enums) == null ? void 0 : _b.step) == null ? void 0 : _c.type) == null ? void 0 : _d.options;
189
243
  return /* @__PURE__ */ jsx(
190
244
  Paged,
191
245
  {
@@ -211,7 +265,8 @@ const Steps = ({
211
265
  Group,
212
266
  {
213
267
  ...{
214
- group
268
+ group,
269
+ labels
215
270
  }
216
271
  },
217
272
  key
@@ -225,5 +280,6 @@ var steps_default = Steps;
225
280
  export {
226
281
  steps_default as default,
227
282
  groupTitle,
283
+ replyExcerpt,
228
284
  rowLabel
229
285
  };
@@ -35,6 +35,7 @@ __export(table_exports, {
35
35
  TableContainer: () => TableContainer,
36
36
  TableHeader: () => TableHeader,
37
37
  TableRow: () => TableRow,
38
+ currencyCell: () => currencyCell,
38
39
  dateCell: () => dateCell,
39
40
  dateTimeCell: () => dateTimeCell,
40
41
  default: () => table_default,
@@ -94,6 +95,14 @@ const rateCell = ({ getValue, row }) => {
94
95
  if (((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.type) === "redemption") return "\u2014";
95
96
  return rate || rate === 0 ? rate + "%" : "\u2014";
96
97
  };
98
+ const currencyCell = ({ getValue, row }) => {
99
+ var _a;
100
+ return (0, import_drawbridge_utils.formatCurrency)({
101
+ // A null code would reach Intl and throw; undefined takes the USD default.
102
+ code: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.currency) || void 0,
103
+ value: getValue() || 0
104
+ });
105
+ };
97
106
  const dateTimeCell = ({ getValue }) => {
98
107
  const value = getValue();
99
108
  return value ? (0, import_drawbridge_utils.formatDateString)({
@@ -759,6 +768,7 @@ var table_default = Table;
759
768
  TableContainer,
760
769
  TableHeader,
761
770
  TableRow,
771
+ currencyCell,
762
772
  dateCell,
763
773
  dateTimeCell,
764
774
  rateCell
@@ -2,7 +2,7 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
4
4
  import { useQueryClient } from "@tanstack/react-query";
5
- import { formatDateString } from "@drawbridge/drawbridge-utils";
5
+ import { formatCurrency, formatDateString } from "@drawbridge/drawbridge-utils";
6
6
  import { request } from "@drawbridge/drawbridge-utils/fetch";
7
7
  import Link from "./link.mjs";
8
8
  import { forwardRef, useMemo } from "react";
@@ -52,6 +52,14 @@ const rateCell = ({ getValue, row }) => {
52
52
  if (((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.type) === "redemption") return "\u2014";
53
53
  return rate || rate === 0 ? rate + "%" : "\u2014";
54
54
  };
55
+ const currencyCell = ({ getValue, row }) => {
56
+ var _a;
57
+ return formatCurrency({
58
+ // A null code would reach Intl and throw; undefined takes the USD default.
59
+ code: ((_a = row == null ? void 0 : row.original) == null ? void 0 : _a.currency) || void 0,
60
+ value: getValue() || 0
61
+ });
62
+ };
55
63
  const dateTimeCell = ({ getValue }) => {
56
64
  const value = getValue();
57
65
  return value ? formatDateString({
@@ -716,6 +724,7 @@ export {
716
724
  TableContainer,
717
725
  TableHeader,
718
726
  TableRow,
727
+ currencyCell,
719
728
  dateCell,
720
729
  dateTimeCell,
721
730
  table_default as default,
@@ -30,6 +30,7 @@ __export(template_dashboard_exports, {
30
30
  Refetch: () => Refetch,
31
31
  TemplateDashboardError: () => TemplateDashboardError,
32
32
  TemplateDashboardResource: () => TemplateDashboardResource,
33
+ TemplateDashboardTasks: () => TemplateDashboardTasks,
33
34
  default: () => template_dashboard_default
34
35
  });
35
36
  module.exports = __toCommonJS(template_dashboard_exports);
@@ -382,55 +383,74 @@ const TemplateDashboardTasks = ({
382
383
  });
383
384
  const array = [...items];
384
385
  const first = array.shift();
385
- const openAll = () => {
386
- open({
387
- title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
388
- "span",
389
- {
390
- ...{
391
- className: "flex items-center space-x-3"
392
- },
393
- children: [
394
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Next steps" }),
395
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
396
- import_badge.default,
397
- {
398
- ...{
399
- type: "warning"
400
- },
401
- children: array.length + 1
402
- }
403
- )
404
- ]
405
- }
406
- ),
407
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
408
- "div",
409
- {
410
- ...{
411
- className: "p-6"
412
- },
413
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
414
- import_list.default,
386
+ const nextSteps = () => ({
387
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
388
+ "span",
389
+ {
390
+ ...{
391
+ className: "flex items-center space-x-3"
392
+ },
393
+ children: [
394
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Next steps" }),
395
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
396
+ import_badge.default,
415
397
  {
416
398
  ...{
417
- items: [
418
- {
419
- ...first,
420
- onClick: () => close()
421
- },
422
- ...array.map((props) => ({
423
- ...props,
424
- onClick: () => close()
425
- }))
426
- ]
427
- }
399
+ type: "warning"
400
+ },
401
+ children: array.length + 1
428
402
  }
429
403
  )
430
- }
431
- )
432
- });
404
+ ]
405
+ }
406
+ ),
407
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
408
+ "div",
409
+ {
410
+ ...{
411
+ className: "p-6"
412
+ },
413
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
414
+ import_list.default,
415
+ {
416
+ ...{
417
+ items: [
418
+ {
419
+ ...first,
420
+ onClick: () => close()
421
+ },
422
+ ...array.map((props) => ({
423
+ ...props,
424
+ onClick: () => close()
425
+ }))
426
+ ]
427
+ }
428
+ }
429
+ )
430
+ }
431
+ )
432
+ });
433
+ const shown = (0, import_react.useRef)(null);
434
+ const openAll = () => {
435
+ const props = nextSteps();
436
+ shown.current = props.children;
437
+ open(props);
433
438
  };
439
+ (0, import_react.useEffect)(
440
+ () => {
441
+ const drawer = queryClient.getQueryData(["drawer"]);
442
+ if (!shown.current || !(drawer == null ? void 0 : drawer.active) || drawer.children !== shown.current) return;
443
+ if (!first) {
444
+ shown.current = null;
445
+ close();
446
+ return;
447
+ }
448
+ openAll();
449
+ },
450
+ // The tasks are the trigger; the rest follows them.
451
+ // eslint-disable-next-line react-hooks/exhaustive-deps
452
+ [items]
453
+ );
434
454
  if (first) {
435
455
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
436
456
  "div",
@@ -620,19 +640,23 @@ const TemplateDashboardResource = ({
620
640
  refetchOnMount,
621
641
  ...chrome
622
642
  }) => {
643
+ const dynamic = Object.values(chrome).some((value) => value instanceof Function);
623
644
  const errorHandler = error || ((query) => {
624
645
  var _a, _b, _c;
625
- if (((_a = query == null ? void 0 : query.error) == null ? void 0 : _a.status) === 403 || (0, import_fetch.isTransientError)(query == null ? void 0 : query.error)) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TemplateDashboard, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
626
- TemplateDashboardError,
627
- {
628
- ...{
629
- error: {
630
- ...(_b = query == null ? void 0 : query.error) == null ? void 0 : _b.data,
631
- message: (_c = query == null ? void 0 : query.error) == null ? void 0 : _c.message
646
+ if (((_a = query == null ? void 0 : query.error) == null ? void 0 : _a.status) === 403 || (0, import_fetch.isTransientError)(query == null ? void 0 : query.error)) {
647
+ const panel = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
648
+ TemplateDashboardError,
649
+ {
650
+ ...{
651
+ error: {
652
+ ...(_b = query == null ? void 0 : query.error) == null ? void 0 : _b.data,
653
+ message: (_c = query == null ? void 0 : query.error) == null ? void 0 : _c.message
654
+ }
632
655
  }
633
656
  }
634
- }
635
- ) });
657
+ );
658
+ return dynamic ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TemplateDashboard, { children: panel }) : panel;
659
+ }
636
660
  (0, import_navigation.notFound)();
637
661
  });
638
662
  const provider = {
@@ -654,7 +678,6 @@ const TemplateDashboardResource = ({
654
678
  }
655
679
  };
656
680
  const resolve = (value, data) => value instanceof Function ? value(data) : value;
657
- const dynamic = Object.values(chrome).some((value) => value instanceof Function);
658
681
  if (!dynamic) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
659
682
  TemplateDashboard,
660
683
  {
@@ -730,5 +753,6 @@ var template_dashboard_default = TemplateDashboard;
730
753
  0 && (module.exports = {
731
754
  Refetch,
732
755
  TemplateDashboardError,
733
- TemplateDashboardResource
756
+ TemplateDashboardResource,
757
+ TemplateDashboardTasks
734
758
  });