@shware/workflow-ui 1.0.1 → 2.0.1

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.
package/dist/index.mjs CHANGED
@@ -5,8 +5,8 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Background, BaseEdge, Controls, EdgeLabelRenderer, Handle, Position, ReactFlow } from "@xyflow/react";
6
6
  import { AlarmClock, AppWindow, ArrowDown, ArrowUp, BellRing, Bot, Calendar, CalendarClock, Camera, ChevronDown, ClipboardList, Filter, Flashlight, GitBranch, Globe, Hourglass, Lock, LogOut, Mail, MessageCircle, MessageSquareText, MessagesSquare, Minus, Monitor, Moon, Plus, Send, Shuffle, Smartphone, SquareFunction, Sun, User, Webhook, Workflow, Zap } from "lucide-react";
7
7
  import { Fragment as Fragment$1, createContext, useContext, useId, useMemo, useState } from "react";
8
+ import { TemplateValidationError, formatEmailAddress, renderDiscordContent, renderPushContent, renderSlackContent, resolveEmail } from "@shware/workflow";
8
9
  import { useTranslation } from "react-i18next";
9
- import { TemplateValidationError, renderDiscordContent, renderPushContent, renderSlackContent } from "@shware/workflow";
10
10
  import { FloatingFocusManager, autoUpdate, flip, offset, shift, useClick, useDismiss, useFloating, useInteractions, useRole } from "@floating-ui/react";
11
11
  //#region \0rolldown/runtime.js
12
12
  var __create = Object.create;
@@ -1453,38 +1453,38 @@ const textOf = (value) => {
1453
1453
  const object = value;
1454
1454
  return typeof object.text === "string" ? object : void 0;
1455
1455
  };
1456
+ const linkClass = "text-[#1d9bd1] hover:underline";
1457
+ const Text = ({ value, className }) => value === void 0 ? null : /* @__PURE__ */ jsx("div", {
1458
+ className: `break-words whitespace-pre-wrap ${className ?? ""}`,
1459
+ children: value.type === "mrkdwn" ? /* @__PURE__ */ jsx(ChatMarkup, {
1460
+ text: value.text,
1461
+ dialect: "slack",
1462
+ linkClass
1463
+ }) : value.text
1464
+ });
1465
+ const Button$1 = ({ element, colors }) => {
1466
+ const style = element.style;
1467
+ return /* @__PURE__ */ jsx("span", {
1468
+ className: "inline-flex h-8 items-center rounded-lg border px-3 text-[13px] font-bold",
1469
+ style: style === "primary" ? {
1470
+ background: "#007a5a",
1471
+ borderColor: "#007a5a",
1472
+ color: "#fff"
1473
+ } : style === "danger" ? {
1474
+ background: "#e01e5a",
1475
+ borderColor: "#e01e5a",
1476
+ color: "#fff"
1477
+ } : {
1478
+ borderColor: colors.border,
1479
+ color: colors.name
1480
+ },
1481
+ children: textOf(element.text)?.text
1482
+ });
1483
+ };
1456
1484
  function SlackPreview({ message, appName, scheme, zoom }) {
1457
1485
  const { t } = useTranslation();
1458
1486
  const colors = PALETTE[scheme];
1459
1487
  const name = message.username ?? appName;
1460
- const linkClass = "text-[#1d9bd1] hover:underline";
1461
- const Text = ({ value, className }) => value === void 0 ? null : /* @__PURE__ */ jsx("div", {
1462
- className: `break-words whitespace-pre-wrap ${className ?? ""}`,
1463
- children: value.type === "mrkdwn" ? /* @__PURE__ */ jsx(ChatMarkup, {
1464
- text: value.text,
1465
- dialect: "slack",
1466
- linkClass
1467
- }) : value.text
1468
- });
1469
- const Button = ({ element }) => {
1470
- const style = element.style;
1471
- return /* @__PURE__ */ jsx("span", {
1472
- className: "inline-flex h-8 items-center rounded-lg border px-3 text-[13px] font-bold",
1473
- style: style === "primary" ? {
1474
- background: "#007a5a",
1475
- borderColor: "#007a5a",
1476
- color: "#fff"
1477
- } : style === "danger" ? {
1478
- background: "#e01e5a",
1479
- borderColor: "#e01e5a",
1480
- color: "#fff"
1481
- } : {
1482
- borderColor: colors.border,
1483
- color: colors.name
1484
- },
1485
- children: textOf(element.text)?.text
1486
- });
1487
- };
1488
1488
  const blocks = message.blocks ?? [];
1489
1489
  return /* @__PURE__ */ jsx("div", {
1490
1490
  className: "mx-auto w-full max-w-2xl overflow-hidden rounded-2xl border shadow-sm",
@@ -1562,7 +1562,10 @@ function SlackPreview({ message, appName, scheme, zoom }) {
1562
1562
  alt: accessory.alt_text ?? "",
1563
1563
  className: "size-[88px] shrink-0 rounded-lg object-cover"
1564
1564
  }),
1565
- accessory?.type === "button" && /* @__PURE__ */ jsx(Button, { element: accessory })
1565
+ accessory?.type === "button" && /* @__PURE__ */ jsx(Button$1, {
1566
+ element: accessory,
1567
+ colors
1568
+ })
1566
1569
  ]
1567
1570
  }, key);
1568
1571
  }
@@ -1577,7 +1580,10 @@ function SlackPreview({ message, appName, scheme, zoom }) {
1577
1580
  }, key);
1578
1581
  case "actions": return /* @__PURE__ */ jsx("div", {
1579
1582
  className: "mt-1 flex flex-wrap gap-2",
1580
- children: (block.elements ?? []).map((element, i) => element.type === "button" ? /* @__PURE__ */ jsx(Button, { element }, i) : null)
1583
+ children: (block.elements ?? []).map((element, i) => element.type === "button" ? /* @__PURE__ */ jsx(Button$1, {
1584
+ element,
1585
+ colors
1586
+ }, i) : null)
1581
1587
  }, key);
1582
1588
  case "image": return /* @__PURE__ */ jsxs("figure", {
1583
1589
  className: "mt-1",
@@ -1725,7 +1731,7 @@ function ToolButton({ active = false, label, onClick, children }) {
1725
1731
  children
1726
1732
  });
1727
1733
  }
1728
- function TemplatesPage({ refs, emails, pushes = {}, discords = {}, slacks = {}, appName, selected, selectedChannel, preview, emailDefaults, previewProps, onPreviewPropsChange, defaultScheme }) {
1734
+ function TemplatesPage({ refs, emails, pushes = {}, discords = {}, slacks = {}, appName, selected, selectedChannel, preview, emailConfig, previewProps, onPreviewPropsChange, defaultScheme }) {
1729
1735
  const { t } = useTranslation();
1730
1736
  const [schemeOverride, setSchemeOverride] = useState(void 0);
1731
1737
  const scheme = schemeOverride ?? defaultScheme ?? "light";
@@ -1737,6 +1743,7 @@ function TemplatesPage({ refs, emails, pushes = {}, discords = {}, slacks = {},
1737
1743
  const isPush = active?.channel === "push";
1738
1744
  const isEmail = active?.channel === "email";
1739
1745
  const activeEmail = active !== void 0 && isEmail ? emails[active.key] : void 0;
1746
+ const resolved = activeEmail === void 0 ? void 0 : resolveEmail(activeEmail, emailConfig);
1740
1747
  const activePush = active !== void 0 && isPush ? pushes[active.key] : void 0;
1741
1748
  const isDiscord = active?.channel === "discord";
1742
1749
  const isSlack = active?.channel === "slack";
@@ -1775,18 +1782,22 @@ function TemplatesPage({ refs, emails, pushes = {}, discords = {}, slacks = {},
1775
1782
  className: "border-border bg-card border-b px-6 py-4",
1776
1783
  children: /* @__PURE__ */ jsxs("dl", {
1777
1784
  className: "grid grid-cols-[max-content_1fr] gap-x-8 gap-y-2.5 text-sm",
1778
- children: [isEmail && activeEmail !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1785
+ children: [isEmail && activeEmail !== void 0 && resolved !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1779
1786
  /* @__PURE__ */ jsx(Field, {
1780
1787
  label: t("emails.from"),
1781
- children: emailDefaults?.from ?? t("common.none")
1788
+ children: formatEmailAddress(resolved.from)
1782
1789
  }),
1783
- emailDefaults?.replyTo !== void 0 && /* @__PURE__ */ jsx(Field, {
1790
+ resolved.replyTo !== void 0 && /* @__PURE__ */ jsx(Field, {
1784
1791
  label: t("emails.replyTo"),
1785
- children: emailDefaults.replyTo
1792
+ children: formatEmailAddress(resolved.replyTo)
1786
1793
  }),
1787
1794
  /* @__PURE__ */ jsx(Field, {
1788
1795
  label: t("emails.subject"),
1789
1796
  children: subject ?? activeEmail.subject
1797
+ }),
1798
+ /* @__PURE__ */ jsx(Field, {
1799
+ label: t("emails.unsubscribeUrl"),
1800
+ children: resolved.unsubscribeUrl ?? t("common.none")
1790
1801
  })
1791
1802
  ] }), push !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
1792
1803
  /* @__PURE__ */ jsx(Field, {
@@ -2510,6 +2521,7 @@ function DateRangePicker({ value, onChange, className }) {
2510
2521
  shift({ padding: 8 })
2511
2522
  ]
2512
2523
  });
2524
+ const { setFloating, setReference } = refs;
2513
2525
  const { getReferenceProps, getFloatingProps } = useInteractions([
2514
2526
  useClick(context),
2515
2527
  useDismiss(context),
@@ -2529,7 +2541,7 @@ function DateRangePicker({ value, onChange, className }) {
2529
2541
  });
2530
2542
  };
2531
2543
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Button, {
2532
- ref: refs.setReference,
2544
+ ref: setReference,
2533
2545
  size: "sm",
2534
2546
  variant: "outline",
2535
2547
  className: cn("gap-2 font-normal", className),
@@ -2551,7 +2563,7 @@ function DateRangePicker({ value, onChange, className }) {
2551
2563
  context,
2552
2564
  modal: false,
2553
2565
  children: /* @__PURE__ */ jsxs("div", {
2554
- ref: refs.setFloating,
2566
+ ref: setFloating,
2555
2567
  style: {
2556
2568
  ...floatingStyles,
2557
2569
  ...superellipse