@fewchurs/react 1.5.0 → 1.6.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.
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
5
5
 
6
6
  // src/client/version.ts
7
- var SDK_VERSION = "1.5.0";
7
+ var SDK_VERSION = "1.6.0";
8
8
 
9
9
  // src/client/constants.ts
10
10
  var SDK_HEADER = `react/${SDK_VERSION}`;
@@ -733,7 +733,8 @@ function useFewchurs() {
733
733
  }
734
734
 
735
735
  // src/components/Board.tsx
736
- import { useEffect as useEffect6, useMemo as useMemo3, useState as useState10 } from "react";
736
+ import { useEffect as useEffect6, useMemo as useMemo3, useRef as useRef2, useState as useState10 } from "react";
737
+ import { flushSync } from "react-dom";
737
738
 
738
739
  // src/hooks/useFewchursConfig.ts
739
740
  import { useEffect as useEffect2 } from "react";
@@ -1440,7 +1441,16 @@ function useSubmitFeature() {
1440
1441
  // src/components/SubmitForm.tsx
1441
1442
  import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
1442
1443
  function SubmitForm() {
1443
- const { labels, emailField, userEmail, isSubscriber, setFormOpen, setJustSubmitted, cx } = useBoard();
1444
+ const {
1445
+ labels,
1446
+ emailField,
1447
+ userEmail,
1448
+ isSubscriber,
1449
+ isFormOpen,
1450
+ setFormOpen,
1451
+ setJustSubmitted,
1452
+ cx
1453
+ } = useBoard();
1444
1454
  const { submit, isPending, error } = useSubmitFeature();
1445
1455
  const [title, setTitle] = useState9("");
1446
1456
  const [description, setDescription] = useState9("");
@@ -1462,8 +1472,10 @@ function SubmitForm() {
1462
1472
  isSubscriber
1463
1473
  });
1464
1474
  if (!created) return;
1465
- setTitle("");
1466
- setDescription("");
1475
+ if (!isFormOpen) {
1476
+ setTitle("");
1477
+ setDescription("");
1478
+ }
1467
1479
  setJustSubmitted(true);
1468
1480
  setFormOpen(false);
1469
1481
  },
@@ -1657,19 +1669,92 @@ function BoardRoot({
1657
1669
  ) });
1658
1670
  }
1659
1671
  function DefaultBoard() {
1660
- const { isFormOpen, justSubmitted, labels, renderHeader, cx } = useBoard();
1672
+ const { renderHeader } = useBoard();
1661
1673
  return /* @__PURE__ */ jsxs8(Fragment3, { children: [
1662
1674
  renderHeader ? renderHeader() : /* @__PURE__ */ jsx11(BoardHeading, {}),
1663
- /* @__PURE__ */ jsxs8("div", { className: cx("fw-toolbar"), children: [
1664
- /* @__PURE__ */ jsx11(BoardTabs, {}),
1665
- /* @__PURE__ */ jsx11(SubmitTrigger, {})
1666
- ] }),
1667
- justSubmitted && /* @__PURE__ */ jsx11("p", { className: cx("fw-alert"), role: "status", children: labels.submitted }),
1668
- isFormOpen && /* @__PURE__ */ jsx11(SubmitForm, {}),
1669
- /* @__PURE__ */ jsx11(FeatureList, {}),
1675
+ /* @__PURE__ */ jsx11(BoardPanels, {}),
1670
1676
  /* @__PURE__ */ jsx11(Branding, {})
1671
1677
  ] });
1672
1678
  }
1679
+ var LEAVE_MS = 110;
1680
+ var ENTER_MS = 300;
1681
+ var ENTER_EASING = "cubic-bezier(0.22, 1, 0.36, 1)";
1682
+ function canAnimate(element) {
1683
+ if (!element || typeof element.animate !== "function") return false;
1684
+ return !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
1685
+ }
1686
+ function BoardPanels() {
1687
+ const { isFormOpen, setFormOpen, justSubmitted, setJustSubmitted, labels, unstyled, cx } = useBoard();
1688
+ const [showForm, setShowForm] = useState10(isFormOpen);
1689
+ const panel = useRef2(null);
1690
+ const trigger = useRef2(null);
1691
+ const entering = useRef2(null);
1692
+ const hasSwapped = useRef2(false);
1693
+ useEffect6(() => {
1694
+ if (isFormOpen === showForm) return;
1695
+ hasSwapped.current = true;
1696
+ const element = panel.current;
1697
+ if (unstyled || !canAnimate(element)) {
1698
+ setShowForm(isFormOpen);
1699
+ return;
1700
+ }
1701
+ entering.current?.cancel();
1702
+ const leaving = element.animate(
1703
+ { opacity: [1, 0], transform: ["translateY(0)", "translateY(-4px)"] },
1704
+ { duration: LEAVE_MS, easing: "ease-in", fill: "forwards" }
1705
+ );
1706
+ leaving.onfinish = () => {
1707
+ const from = element.offsetHeight;
1708
+ flushSync(() => setShowForm(isFormOpen));
1709
+ leaving.cancel();
1710
+ const to = element.offsetHeight;
1711
+ element.style.overflow = "hidden";
1712
+ const enter = element.animate(
1713
+ {
1714
+ opacity: [0, 1],
1715
+ transform: ["translateY(6px)", "translateY(0)"],
1716
+ height: [`${from}px`, `${to}px`]
1717
+ },
1718
+ { duration: ENTER_MS, easing: ENTER_EASING }
1719
+ );
1720
+ const finish = () => {
1721
+ element.style.overflow = "";
1722
+ };
1723
+ enter.onfinish = finish;
1724
+ enter.oncancel = finish;
1725
+ entering.current = enter;
1726
+ };
1727
+ return () => leaving.cancel();
1728
+ }, [isFormOpen, showForm, unstyled]);
1729
+ useEffect6(() => {
1730
+ if (!hasSwapped.current) return;
1731
+ const target = showForm ? panel.current?.querySelector("#fw-title") : trigger.current;
1732
+ target?.focus({ preventScroll: true });
1733
+ }, [showForm]);
1734
+ return /* @__PURE__ */ jsxs8("div", { ref: panel, children: [
1735
+ /* @__PURE__ */ jsxs8("div", { hidden: showForm, children: [
1736
+ /* @__PURE__ */ jsxs8("div", { className: cx("fw-toolbar"), children: [
1737
+ /* @__PURE__ */ jsx11(BoardTabs, {}),
1738
+ /* @__PURE__ */ jsx11(
1739
+ "button",
1740
+ {
1741
+ ref: trigger,
1742
+ type: "button",
1743
+ className: cx("fw-btn"),
1744
+ onClick: () => {
1745
+ setJustSubmitted(false);
1746
+ setFormOpen(true);
1747
+ },
1748
+ children: labels.newRequest
1749
+ }
1750
+ )
1751
+ ] }),
1752
+ justSubmitted && /* @__PURE__ */ jsx11("p", { className: cx("fw-alert"), role: "status", children: labels.submitted }),
1753
+ /* @__PURE__ */ jsx11(FeatureList, {})
1754
+ ] }),
1755
+ showForm && /* @__PURE__ */ jsx11(SubmitForm, {})
1756
+ ] });
1757
+ }
1673
1758
  function BoardHeading() {
1674
1759
  const { labels, cx } = useBoard();
1675
1760
  return /* @__PURE__ */ jsx11("h2", { className: cx("fw-heading"), children: labels.title });
@@ -1733,7 +1818,7 @@ var FewchursBoard = Object.assign(BoardRoot, {
1733
1818
  });
1734
1819
 
1735
1820
  // src/components/BoardDialog.tsx
1736
- import { useEffect as useEffect7, useRef as useRef2 } from "react";
1821
+ import { useEffect as useEffect7, useRef as useRef3 } from "react";
1737
1822
  import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
1738
1823
  function FewchursBoardDialog({
1739
1824
  open,
@@ -1742,8 +1827,8 @@ function FewchursBoardDialog({
1742
1827
  variant = "dialog",
1743
1828
  ...boardProps
1744
1829
  }) {
1745
- const dialogRef = useRef2(null);
1746
- const openerRef = useRef2(null);
1830
+ const dialogRef = useRef3(null);
1831
+ const openerRef = useRef3(null);
1747
1832
  useEffect7(() => {
1748
1833
  if (!open) return;
1749
1834
  openerRef.current = document.activeElement;