@fewchurs/react 1.0.1 → 1.2.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.0.1";
7
+ var SDK_VERSION = "1.2.0";
8
8
 
9
9
  // src/client/constants.ts
10
10
  var SDK_HEADER = `react/${SDK_VERSION}`;
@@ -47,6 +47,8 @@ function errorFromResponse(status, body) {
47
47
  switch (code) {
48
48
  case "invalid_key":
49
49
  return { code: "invalid_key", status: 401, message };
50
+ case "wrong_app":
51
+ return { code: "invalid_key", status: 403, message };
50
52
  // missing_device_id is a client mistake the caller fixes the same way a bad field is fixed,
51
53
  // so it collapses into validation_failed rather than widening the public union.
52
54
  case "missing_device_id":
@@ -196,6 +198,7 @@ function createFewchursClient(options = {}) {
196
198
  const deviceId = getDeviceId();
197
199
  if (deviceId) result["X-Device-Id"] = deviceId;
198
200
  if (options.language) result["Accept-Language"] = options.language;
201
+ if (options.appId) result["X-Fewchurs-App-Id"] = options.appId;
199
202
  return result;
200
203
  }
201
204
  function url(path, query) {
@@ -234,7 +237,7 @@ function createFewchursClient(options = {}) {
234
237
  continue;
235
238
  }
236
239
  const failure = errorFromResponse(response.status, await readJson(response));
237
- warnAboutKey(failure.code);
240
+ warnAboutKey(failure);
238
241
  return { ok: false, error: failure };
239
242
  }
240
243
  return { ok: false, error: networkError() };
@@ -326,12 +329,12 @@ function messageOf(error) {
326
329
  return error instanceof Error ? error.message : "Network request failed.";
327
330
  }
328
331
  var warnedAboutKey = false;
329
- function warnAboutKey(code) {
330
- if (code !== "invalid_key" || warnedAboutKey) return;
332
+ function warnAboutKey(error) {
333
+ if (error.code !== "invalid_key" || warnedAboutKey) return;
331
334
  if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
332
335
  warnedAboutKey = true;
333
336
  console.error(
334
- "[fewchurs] The API key was rejected. Check FEWCHURS_API_KEY (server) or the apiKey passed to FewchursProvider, and that the key is active in your Fewchurs dashboard."
337
+ error.status === 403 ? `[fewchurs] ${error.message}` : "[fewchurs] The API key was rejected. Check FEWCHURS_API_KEY (server) or the apiKey passed to FewchursProvider, and that the key is active in your Fewchurs dashboard."
335
338
  );
336
339
  }
337
340
 
@@ -1646,6 +1649,7 @@ function FewchursBoardDialog({
1646
1649
  open,
1647
1650
  onClose,
1648
1651
  ariaLabel = "Feature requests",
1652
+ variant = "dialog",
1649
1653
  ...boardProps
1650
1654
  }) {
1651
1655
  const dialogRef = useRef2(null);
@@ -1664,11 +1668,14 @@ function FewchursBoardDialog({
1664
1668
  };
1665
1669
  }, [open, onClose]);
1666
1670
  if (!open) return null;
1667
- return /* @__PURE__ */ jsx12("div", { className: "fw-overlay", onClick: onClose, children: /* @__PURE__ */ jsxs9(
1671
+ const isSheet = variant === "sheet";
1672
+ const { colorScheme } = boardProps;
1673
+ return /* @__PURE__ */ jsx12("div", { className: isSheet ? "fw-overlay fw-overlay--sheet" : "fw-overlay", onClick: onClose, children: /* @__PURE__ */ jsxs9(
1668
1674
  "div",
1669
1675
  {
1670
1676
  ref: dialogRef,
1671
- className: "fw-dialog",
1677
+ className: isSheet ? "fw-dialog fw-dialog--sheet" : "fw-dialog",
1678
+ "data-theme": colorScheme === "system" ? void 0 : colorScheme,
1672
1679
  role: "dialog",
1673
1680
  "aria-modal": "true",
1674
1681
  "aria-label": ariaLabel,
@@ -1681,6 +1688,49 @@ function FewchursBoardDialog({
1681
1688
  }
1682
1689
  ) });
1683
1690
  }
1691
+
1692
+ // src/components/BoardButton.tsx
1693
+ import { useCallback as useCallback7, useState as useState11 } from "react";
1694
+ import { createPortal } from "react-dom";
1695
+ import { Fragment as Fragment3, jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
1696
+ function FewchursButton({
1697
+ children = "Feedback",
1698
+ className,
1699
+ style,
1700
+ ariaLabel,
1701
+ ...board
1702
+ }) {
1703
+ const [open, setOpen] = useState11(false);
1704
+ const close = useCallback7(() => setOpen(false), []);
1705
+ const classes = [board.unstyled ? "" : "fw-launcher", className].filter(Boolean).join(" ");
1706
+ return /* @__PURE__ */ jsxs10(Fragment3, { children: [
1707
+ /* @__PURE__ */ jsx13(
1708
+ "button",
1709
+ {
1710
+ type: "button",
1711
+ className: classes || void 0,
1712
+ style: { ...themeToStyle(board.theme), ...style },
1713
+ "aria-haspopup": "dialog",
1714
+ "aria-expanded": open,
1715
+ onClick: () => setOpen(true),
1716
+ children
1717
+ }
1718
+ ),
1719
+ open ? createPortal(
1720
+ /* @__PURE__ */ jsx13(
1721
+ FewchursBoardDialog,
1722
+ {
1723
+ ...board,
1724
+ variant: "sheet",
1725
+ ariaLabel,
1726
+ open: true,
1727
+ onClose: close
1728
+ }
1729
+ ),
1730
+ document.body
1731
+ ) : null
1732
+ ] });
1733
+ }
1684
1734
  export {
1685
1735
  BoardRoot,
1686
1736
  BoardTabs,
@@ -1695,6 +1745,7 @@ export {
1695
1745
  FeatureList,
1696
1746
  FewchursBoard,
1697
1747
  FewchursBoardDialog,
1748
+ FewchursButton,
1698
1749
  FewchursProvider,
1699
1750
  FollowForm,
1700
1751
  LIMITS,