@sidebandai/sideband-react 1.4.5 → 1.4.6-rc.2

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/README.md CHANGED
@@ -4,25 +4,25 @@ Sideband adds in-app Pulse prompts and event tracking to React apps.
4
4
 
5
5
  ## Requirements
6
6
 
7
- - React 19 and React DOM 19
7
+ - React 18.3 or React 19, with React DOM of the same version
8
8
  - A Sideband API key
9
9
  - Your application's version
10
10
 
11
- For React 18 apps, use [`@sidebandai/sideband-web`](https://www.npmjs.com/package/@sidebandai/sideband-web),
11
+ For a site without React, or to start the SDK outside the React tree, use
12
+ [`@sidebandai/sideband-web`](https://www.npmjs.com/package/@sidebandai/sideband-web),
12
13
  which has no framework dependency. Its README has a server-rendered React 18
13
14
  example that starts the SDK once per page load under StrictMode.
14
15
 
15
16
  ## Install
16
17
 
17
18
  ```bash
18
- npm install @sidebandai/sideband-react react@^19 react-dom@^19
19
+ npm install @sidebandai/sideband-react
19
20
  ```
20
21
 
21
22
  ## Configure
22
23
 
23
- Import the stylesheet once and wrap your application content in
24
- `SidebandProvider`. Pass your API key and application version through its
25
- `config` prop:
24
+ Import the stylesheet once and render `SidebandProvider` once, near the root of
25
+ your app. Pass your API key and application version through its `config` prop:
26
26
 
27
27
  ```tsx
28
28
  import { SidebandProvider } from '@sidebandai/sideband-react'
@@ -41,8 +41,65 @@ function App() {
41
41
  your application's version, not the SDK version. `appVersion` must be a
42
42
  non-empty string of at most 64 characters.
43
43
 
44
- The provider presents available Pulses automatically. In server-rendered apps,
45
- place it within a client component.
44
+ The provider presents available Pulses automatically. It renders them in a
45
+ portal on `document.body`, not inside its children, so it can wrap your app as
46
+ above or sit beside it with no children:
47
+
48
+ ```tsx
49
+ function App() {
50
+ return (
51
+ <>
52
+ <SidebandProvider config={{ apiKey: 'YOUR_API_KEY', appVersion: '1.0.0' }} />
53
+ <AppContent />
54
+ </>
55
+ )
56
+ }
57
+ ```
58
+
59
+ Components that call `useSideband()` must be inside the provider. When the
60
+ provider sits beside your app, connect your app to it as shown in
61
+ [Calls from outside the provider](#calls-from-outside-the-provider).
62
+
63
+ The provider reads `config` once, when it mounts, and keeps it until it
64
+ unmounts. A later change to the `config` prop, such as a new API key or
65
+ `context.language`, does not reach the SDK. Some callbacks are exceptions:
66
+
67
+ - `shouldPresentPulse` and `onRateApp`: the provider calls the latest ones.
68
+ - `onError` is split. Errors from showing a pulse go to the latest `onError`:
69
+ for example a pulse that is not valid, or a `shouldPresentPulse` or
70
+ `onRateApp` that throws. Errors from sending and from the SDK's own checks go
71
+ to the `onError` the provider mounted with: for example a failed or rejected
72
+ send, an answer that cannot be stored, or a `tagUser` ID that is too long.
73
+
74
+ To send every error to one handler, pass an `onError` that does not change
75
+ during the provider's life, or one that calls your current handler through a
76
+ ref. To apply a new config, remount the provider, for example with a React
77
+ `key`:
78
+
79
+ ```tsx
80
+ <SidebandProvider key={language} config={{ apiKey: 'YOUR_API_KEY', appVersion: '1.0.0', context: { language } }} />
81
+ ```
82
+
83
+ A remount stops the SDK, discards events not yet sent, and starts it again,
84
+ which sends a new `system_app_launch`. If the provider wraps your app, a new
85
+ `key` also remounts your app; render the provider beside your app to avoid that.
86
+
87
+ The API key goes to the browser, so anyone can read it in your page or its
88
+ network requests, as with a key in a mobile app. That is expected: the key can
89
+ only send events and pulse answers for its channel and receive that channel's
90
+ pulses.
91
+
92
+ ### Server rendering
93
+
94
+ `SidebandProvider` can render on the server. It starts the SDK in an effect, so
95
+ the server render creates no SDK, sends nothing, and renders no pulse. In the
96
+ browser, the SDK starts after hydration.
97
+
98
+ - In frameworks with React Server Components, such as the Next.js App Router,
99
+ render the provider from a Client Component (a file that starts with
100
+ `'use client'`). The package does not mark its modules as client code.
101
+ - In other server-rendering frameworks, such as React Router or Remix, render it
102
+ like any other component.
46
103
 
47
104
  ## Content Security Policy
48
105
 
@@ -66,20 +123,123 @@ that injects CSS as a `<style>` element, as some do in development, changes
66
123
  this: that element then needs whatever your policy requires for inline styles.
67
124
 
68
125
  A blocked send appears in the browser console as a Content Security Policy
69
- error, and `onError` receives a network error. The React package was not run
70
- under these policies; this section comes from its code.
126
+ error, and `onError` receives a network error.
127
+
128
+ What was checked with the React package, in a production build of a
129
+ server-rendered React 18.3 app: its policy had a nonce in `script-src`,
130
+ `style-src 'self' 'unsafe-inline'`, and `img-src` with `data:` and `https:`.
131
+ Adding the API origin to `connect-src` was the only change it needed, and the
132
+ browser reported no policy violation. The bundler extracted `style.css` into a
133
+ stylesheet file, which the app loaded like its other stylesheets, with the
134
+ page's nonce. A `style-src` without `'unsafe-inline'` has not been checked with
135
+ the React package.
71
136
 
72
137
  ## Consent
73
138
 
74
139
  Your app decides when Sideband runs. If Sideband needs consent on your site,
75
140
  render `SidebandProvider` only after the user gives it, and remove it when the
76
- user withdraws it; unmounting the provider stops the SDK. Which consent category
77
- applies is your decision; this README does not give legal advice.
141
+ user withdraws it. Mounting the provider starts the SDK; unmounting it stops the
142
+ SDK and discards events not yet sent. The SDK has no consent setting of its own,
143
+ and there is no `config` setting that pauses it. Which consent category applies
144
+ is your decision; this README does not give legal advice.
78
145
 
79
- A user who declines sends no events and sees no pulses. `useSideband()` throws
80
- outside `SidebandProvider`, so components that track events while the provider
81
- may be absent should call your own wrapper, which does nothing without consent.
82
- The SDK has no consent setting of its own.
146
+ Gate the provider, not your app. If the provider wraps your app, adding or
147
+ removing it remounts your whole app, which loses its state. Render it beside
148
+ your app instead:
149
+
150
+ ```tsx
151
+ function SidebandWhenAllowed({ allowed }: { allowed: boolean }) {
152
+ if (!allowed) return null
153
+ return (
154
+ <SidebandProvider config={{ apiKey: 'YOUR_API_KEY', appVersion: '1.0.0' }}>
155
+ <SidebandBridge />
156
+ </SidebandProvider>
157
+ )
158
+ }
159
+
160
+ function App() {
161
+ const allowed = useAnalyticsConsent() // your app's consent state
162
+ return (
163
+ <>
164
+ <SidebandWhenAllowed allowed={allowed} />
165
+ <AppContent />
166
+ </>
167
+ )
168
+ }
169
+ ```
170
+
171
+ `SidebandBridge` connects your app's code to the provider; see the next section.
172
+ A user who declines sends no events and sees no pulses.
173
+
174
+ ## Calls from outside the provider
175
+
176
+ `useSideband()` works only inside `SidebandProvider`; outside it, it throws. If
177
+ your app tracks events through its own analytics module, or from code that is
178
+ not a React component, give that module the SDK functions from a small
179
+ component inside the provider:
180
+
181
+ ```tsx
182
+ // analytics.ts: your app's analytics module
183
+ type SidebandApi = {
184
+ track: (name: string, metadata?: Record<string, string>) => void
185
+ tagUser: (userId: string) => void
186
+ untagUser: () => void
187
+ }
188
+
189
+ let sideband: SidebandApi | null = null
190
+ let user: { id: string | null } | null = null // null until your app calls identify
191
+
192
+ export function attachSideband(api: SidebandApi | null) {
193
+ sideband = api
194
+ // Apply the current user when Sideband starts, for example after consent.
195
+ if (api && user) {
196
+ if (user.id !== null) api.tagUser(user.id)
197
+ else api.untagUser()
198
+ }
199
+ }
200
+
201
+ export function track(name: string, metadata?: Record<string, string>) {
202
+ sideband?.track(name, metadata) // dropped while Sideband is not running
203
+ }
204
+
205
+ export function identify(id: string | null) {
206
+ user = { id }
207
+ if (id !== null) sideband?.tagUser(id)
208
+ else sideband?.untagUser()
209
+ }
210
+ ```
211
+
212
+ ```tsx
213
+ // SidebandBridge.tsx
214
+ import { useEffect } from 'react'
215
+ import { useSideband } from '@sidebandai/sideband-react'
216
+ import { attachSideband } from './analytics'
217
+
218
+ export function SidebandBridge() {
219
+ const { track, tagUser, untagUser } = useSideband()
220
+ useEffect(() => {
221
+ attachSideband({ track, tagUser, untagUser })
222
+ return () => attachSideband(null)
223
+ }, [track, tagUser, untagUser])
224
+ return null
225
+ }
226
+ ```
227
+
228
+ Render `<SidebandBridge />` inside the provider, as in the consent example.
229
+
230
+ The SDK does not queue calls made outside the provider. Calls that your module
231
+ makes while the bridge is not attached are dropped: before consent, before the
232
+ bridge's effect runs after hydration, and after the provider unmounts. The
233
+ module above keeps the user, so a user who signed in before Sideband started is
234
+ tagged when it starts. If you need events from before Sideband starts, hold a
235
+ short, capped list in your module after your app decides to start Sideband (not
236
+ before consent), and send it when the bridge attaches. The
237
+ `@sidebandai/sideband-web` README shows this pattern under "Events before
238
+ Sideband starts". Inside the provider, calls made before the SDK has finished
239
+ starting are queued and sent once it starts.
240
+
241
+ Metadata values must be strings: convert numbers and booleans in your module
242
+ (for example with `String(value)`).
83
243
 
84
244
  ## Language
85
245
 
@@ -232,6 +392,12 @@ new page load sends `system_app_launch` about one second after the SDK starts,
232
392
  with the default `flushIntervalSeconds`. Tagging the user right after start
233
393
  sends it sooner.
234
394
 
395
+ Each send gets at most one pulse back. When events that trigger different pulses
396
+ go in the same batch, the server serves at most one of those pulses for that
397
+ batch; the others are not served unless their trigger events come again. So
398
+ pulses whose triggers fire together, for example two events that your app
399
+ tracks for one user action, compete.
400
+
235
401
  `SidebandProviderConfig` in the package's type definitions lists the optional
236
402
  settings, such as `shouldPresentPulse` to hold a Pulse back for a better
237
403
  moment and `onError` for background errors. `useSideband()` also returns
@@ -644,7 +644,7 @@ function q() {
644
644
  })
645
645
  });
646
646
  }
647
- function J() {
647
+ function se() {
648
648
  return /* @__PURE__ */ h("svg", {
649
649
  viewBox: "0 0 35.5556 35.5556",
650
650
  "aria-hidden": "true",
@@ -654,7 +654,7 @@ function J() {
654
654
  })
655
655
  });
656
656
  }
657
- function se() {
657
+ function ce() {
658
658
  return /* @__PURE__ */ h("span", {
659
659
  className: "sb-spark-ring",
660
660
  "aria-hidden": "true",
@@ -664,23 +664,23 @@ function se() {
664
664
  }, t))
665
665
  });
666
666
  }
667
- function ce({ question: e, store: t, isSentiment: n }) {
667
+ function le({ question: e, store: t, isSentiment: n }) {
668
668
  let i = t.currentDraft(), a = t.getState(), o = !!(a?.isBusy || a?.isCompleting), s = e.answers?.find((e) => e.id === i?.answer_key);
669
- return s && r(s) ? /* @__PURE__ */ h(fe, {
669
+ return s && r(s) ? /* @__PURE__ */ h(pe, {
670
670
  store: t,
671
671
  disabled: o,
672
672
  placeholder: s.label,
673
673
  autoFocus: !0,
674
674
  ariaLabel: "Other response",
675
675
  isOther: !0
676
- }) : n ? /* @__PURE__ */ h(le, {
676
+ }) : n ? /* @__PURE__ */ h(ue, {
677
677
  store: t,
678
678
  disabled: o || !!a?.sentimentSelectionLocked
679
- }) : e.type === "yes_no" || e.type === "multiple_choice" ? /* @__PURE__ */ h(ue, {
679
+ }) : e.type === "yes_no" || e.type === "multiple_choice" ? /* @__PURE__ */ h(de, {
680
680
  question: e,
681
681
  store: t,
682
682
  disabled: o
683
- }) : /* @__PURE__ */ h(fe, {
683
+ }) : /* @__PURE__ */ h(pe, {
684
684
  store: t,
685
685
  disabled: o,
686
686
  placeholder: e.free_text_placeholder ?? "Please explain more... (Optional)",
@@ -688,7 +688,7 @@ function ce({ question: e, store: t, isSentiment: n }) {
688
688
  ariaLabel: e.prompt
689
689
  });
690
690
  }
691
- function le({ store: e, disabled: t }) {
691
+ function ue({ store: e, disabled: t }) {
692
692
  let r = e.currentDraft();
693
693
  return /* @__PURE__ */ h("div", {
694
694
  className: "sb-question sb-question--sentiment",
@@ -696,7 +696,7 @@ function le({ store: e, disabled: t }) {
696
696
  let a = n(i), o = r?.answer_key === i.id;
697
697
  return /* @__PURE__ */ g("span", {
698
698
  className: "sb-sentiment-control",
699
- children: [o && a ? /* @__PURE__ */ h(se, {}) : null, /* @__PURE__ */ h("button", {
699
+ children: [o && a ? /* @__PURE__ */ h(ce, {}) : null, /* @__PURE__ */ h("button", {
700
700
  type: "button",
701
701
  className: `sb-yesno ${o ? "sb-yesno--selected" : ""}`,
702
702
  "data-choice-value": i.id,
@@ -706,14 +706,14 @@ function le({ store: e, disabled: t }) {
706
706
  "aria-pressed": o,
707
707
  children: /* @__PURE__ */ h("span", {
708
708
  className: "sb-yesno__icon",
709
- children: h(a ? q : J, {})
709
+ children: h(a ? q : se, {})
710
710
  })
711
711
  })]
712
712
  }, i.id);
713
713
  })
714
714
  });
715
715
  }
716
- function ue({ question: e, store: t, disabled: n }) {
716
+ function de({ question: e, store: t, disabled: n }) {
717
717
  let i = e.answers ?? oe, a = t.currentDraft(), o = u(null), [c, l] = d(() => i.every((e) => e.label.trim().length < 20));
718
718
  return s(() => {
719
719
  let e = () => {
@@ -736,7 +736,7 @@ function ue({ question: e, store: t, disabled: n }) {
736
736
  className: `sb-question sb-question--choices ${c ? "sb-question--choices-grid" : "sb-question--choices-list"}`,
737
737
  children: /* @__PURE__ */ h("div", {
738
738
  className: `sb-options-scroll ${(c ? Math.ceil(i.length / 2) : i.length) >= 5 ? "sb-options-scroll--scrolling" : ""}`,
739
- children: i.map((e) => /* @__PURE__ */ h(de, {
739
+ children: i.map((e) => /* @__PURE__ */ h(fe, {
740
740
  choice: e,
741
741
  selected: a?.answer_key === e.id,
742
742
  disabled: n,
@@ -745,7 +745,7 @@ function ue({ question: e, store: t, disabled: n }) {
745
745
  })
746
746
  });
747
747
  }
748
- function de({ choice: e, selected: n, disabled: i, store: a }) {
748
+ function fe({ choice: e, selected: n, disabled: i, store: a }) {
749
749
  let o = r(e);
750
750
  return /* @__PURE__ */ h("button", {
751
751
  type: "button",
@@ -768,7 +768,7 @@ function de({ choice: e, selected: n, disabled: i, store: a }) {
768
768
  })
769
769
  });
770
770
  }
771
- function fe({ store: e, disabled: t, placeholder: n, autoFocus: r, ariaLabel: i, isOther: a = !1 }) {
771
+ function pe({ store: e, disabled: t, placeholder: n, autoFocus: r, ariaLabel: i, isOther: a = !1 }) {
772
772
  let o = u(null);
773
773
  return s(() => {
774
774
  r && !t && o.current?.focus({ preventScroll: !0 });
@@ -792,7 +792,7 @@ function fe({ store: e, disabled: t, placeholder: n, autoFocus: r, ariaLabel: i,
792
792
  }
793
793
  //#endregion
794
794
  //#region src/lib/components/SurveyThankYou.tsx
795
- function pe({ completion: e, store: t, isBusy: n, headingId: r, bodyId: i }) {
795
+ function me({ completion: e, store: t, isBusy: n, headingId: r, bodyId: i }) {
796
796
  let a = u(null), [o, c] = d(!1);
797
797
  return s(() => {
798
798
  let e = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? !1, t = setTimeout(() => c(!0), e ? 0 : 890);
@@ -845,7 +845,7 @@ function pe({ completion: e, store: t, isBusy: n, headingId: r, bodyId: i }) {
845
845
  }
846
846
  //#endregion
847
847
  //#region src/lib/components/SurveySheet.tsx
848
- var me = a(function({ session: e, store: t, modal: n, rootRef: r, interactive: i = !0 }) {
848
+ var he = a(function({ session: e, store: t, modal: n, rootRef: r, interactive: i = !0 }) {
849
849
  let a = e.currentNodeId ? e.survey.questions[e.currentNodeId] : void 0, o = !!(a && t.isSentimentStep()), l = a?.answers?.find((e) => e.id === t.currentDraft()?.answer_key), d = l?.comment?.trim() || null, f = l?.id === "system_other", p = u(null), _ = c();
850
850
  s(() => {
851
851
  if (!i) return;
@@ -884,7 +884,7 @@ var me = a(function({ session: e, store: t, modal: n, rootRef: r, interactive: i
884
884
  "aria-labelledby": v,
885
885
  "aria-describedby": e.completion?.body ? y : void 0,
886
886
  "aria-busy": e.isCompleting || void 0,
887
- children: e.completion ? /* @__PURE__ */ h(pe, {
887
+ children: e.completion ? /* @__PURE__ */ h(me, {
888
888
  completion: e.completion,
889
889
  store: t,
890
890
  isBusy: e.isBusy,
@@ -913,7 +913,7 @@ var me = a(function({ session: e, store: t, modal: n, rootRef: r, interactive: i
913
913
  "aria-live": o && d ? "polite" : void 0,
914
914
  children: o && d ? d : a.prompt
915
915
  })]
916
- }), /* @__PURE__ */ h(ce, {
916
+ }), /* @__PURE__ */ h(le, {
917
917
  question: a,
918
918
  store: t,
919
919
  isSentiment: o
@@ -943,11 +943,15 @@ var me = a(function({ session: e, store: t, modal: n, rootRef: r, interactive: i
943
943
  }, `${a.node_id}:${f ? "text" : "options"}`)] }) : null
944
944
  })]
945
945
  });
946
- }), he = typeof window > "u" ? s : l, Y = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? !1;
947
- function ge(e, t, n, r) {
946
+ }), ge = typeof window > "u" ? s : l, _e = (e) => {
947
+ e && (e.inert = !0, e.toggleAttribute("inert", !0));
948
+ }, ve = (e) => {
949
+ e && (e.inert = !1, e.toggleAttribute("inert", !1));
950
+ }, J = (e) => e ? _e : ve, Y = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? !1;
951
+ function ye(e, t, n, r) {
948
952
  t.current === r || document.visibilityState === "hidden" || (t.current = r, n.current?.(), n.current = null, e.confirmPresentation("expanded_fab", r));
949
953
  }
950
- function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
954
+ function be({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
951
955
  let c = u(null), l = u(null), f = u(null), [p, v] = d("entering"), { presentationId: y, survey: b, snackbar: x, isOpen: S } = e, C = e.sentimentPresentation === "bar", w = C ? e.barPosition : void 0, T = o ? "exiting" : S && (p === "entering" || p === "compact") ? "widening" : p, E = b.questions[b.root_node_id], D = i(E, b.fab), O = b.fab?.timerStyle ?? "none", k = C && e.barBehavior === "dismiss" && x?.selectedKey != null, [A, j] = d(!1);
952
956
  s(() => {
953
957
  if (o) return;
@@ -968,7 +972,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
968
972
  C,
969
973
  o
970
974
  ]);
971
- let M = () => ge(t, l, f, y), N = () => {
975
+ let M = () => ye(t, l, f, y), N = () => {
972
976
  M(), t.closeSurvey();
973
977
  };
974
978
  s(() => {
@@ -984,7 +988,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
984
988
  y,
985
989
  t,
986
990
  o
987
- ]), he(() => {
991
+ ]), ge(() => {
988
992
  let e = c.current;
989
993
  if (!e || o) return;
990
994
  let t = () => {
@@ -1046,7 +1050,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1046
1050
  ]), s(() => {
1047
1051
  if (S || o) return;
1048
1052
  let e = (e) => {
1049
- e.key === "Escape" && c.current?.contains(document.activeElement) && (ge(t, l, f, y), t.closeSurvey());
1053
+ e.key === "Escape" && c.current?.contains(document.activeElement) && (ye(t, l, f, y), t.closeSurvey());
1050
1054
  };
1051
1055
  return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
1052
1056
  }, [
@@ -1077,7 +1081,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1077
1081
  onClick: () => {
1078
1082
  M(), t.answerSnackbar(y, e.id);
1079
1083
  },
1080
- children: n(e) ? /* @__PURE__ */ h(q, {}) : /* @__PURE__ */ h(J, {})
1084
+ children: n(e) ? /* @__PURE__ */ h(q, {}) : /* @__PURE__ */ h(se, {})
1081
1085
  }, e.id))
1082
1086
  })] });
1083
1087
  return /* @__PURE__ */ g("div", {
@@ -1117,7 +1121,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1117
1121
  role: "group",
1118
1122
  "aria-label": E.prompt,
1119
1123
  "aria-hidden": S || T === "entering" || o,
1120
- inert: S || T === "entering" || o,
1124
+ ref: J(S || T === "entering" || o),
1121
1125
  children: [
1122
1126
  O === "fill" || C && O === "bar" ? G : null,
1123
1127
  C ? null : /* @__PURE__ */ g("span", {
@@ -1140,7 +1144,7 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1140
1144
  }),
1141
1145
  C ? /* @__PURE__ */ h("div", {
1142
1146
  className: "sb-bar-content",
1143
- inert: B,
1147
+ ref: J(B),
1144
1148
  "aria-hidden": B,
1145
1149
  children: K
1146
1150
  }) : K,
@@ -1162,9 +1166,9 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1162
1166
  ]
1163
1167
  }), S ? /* @__PURE__ */ h("div", {
1164
1168
  className: "sb-snackbar-card",
1165
- inert: T !== "ready",
1169
+ ref: J(T !== "ready"),
1166
1170
  "aria-hidden": T !== "ready",
1167
- children: /* @__PURE__ */ h(me, {
1171
+ children: /* @__PURE__ */ h(he, {
1168
1172
  session: e,
1169
1173
  store: t,
1170
1174
  modal: a,
@@ -1193,44 +1197,44 @@ function _e({ session: e, store: t, placement: r, modal: a, exiting: o = !1 }) {
1193
1197
  }
1194
1198
  //#endregion
1195
1199
  //#region src/lib/components/SurveyRenderer.tsx
1196
- var X = typeof window > "u" ? s : l, ve = 1969.207, ye = 2169.207, be = 856.839, xe = 450;
1197
- function Z(e) {
1200
+ var X = typeof window > "u" ? s : l, xe = 1969.207, Se = 2169.207, Ce = 856.839, Z = 450;
1201
+ function Q(e) {
1198
1202
  let t = Number.parseFloat(e);
1199
1203
  return Number.isFinite(t) ? Math.max(0, t) : 0;
1200
1204
  }
1201
- function Se(e) {
1205
+ function we(e) {
1202
1206
  let t = 0;
1203
1207
  for (let n of e) t += /[MW@#%&]/.test(n) ? 11 : /[ilI1.,' ]/.test(n) ? 4 : 7.5;
1204
1208
  return Math.ceil(t);
1205
1209
  }
1206
- function Q() {
1210
+ function $() {
1207
1211
  return typeof window < "u" && (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? !1);
1208
1212
  }
1209
- function $(e) {
1213
+ function Te(e) {
1210
1214
  if (!e) return null;
1211
1215
  let { pulse_id: t, version: n, impression_id: r } = e.survey;
1212
1216
  return typeof r == "string" ? `${t}:${n}:${r}` : `${t}:${n}`;
1213
1217
  }
1214
- function Ce(e) {
1218
+ function Ee(e) {
1215
1219
  if (!e) return;
1216
1220
  let t = getComputedStyle(e), n = Number.parseFloat(t.width) || e.offsetWidth || 86, r = Number.parseFloat(e.style.getPropertyValue("--sb-fab-expanded-width")) || n, i = Number.parseFloat(e.style.getPropertyValue("--sb-fab-anchor-offset")) || 0, a = r === 60 ? 0 : i / (r - 60), o = e.querySelector(".sb-fab__label"), s = e.querySelector(".sb-fab__timer");
1217
1221
  e.style.setProperty("--sb-fab-exit-width", `${n}px`), e.style.setProperty("--sb-fab-exit-offset", `${(r - n) * a}px`), e.style.setProperty("--sb-fab-exit-scale", t.getPropertyValue("scale") || "1"), e.style.setProperty("--sb-fab-exit-label-opacity", o ? getComputedStyle(o).opacity : "0"), e.style.setProperty("--sb-fab-exit-timer-opacity", s ? getComputedStyle(s).opacity : "0");
1218
1222
  }
1219
- function we({ session: e, store: t, fabRef: n, onClick: r }) {
1220
- let [i, a] = d(e), [o, c] = d(null), l = $(e), u = e?.survey.fab, f = (u?.timerStyle === "bar" || u?.timerStyle === "fill") && typeof u.expandedTimeout == "number" && Number.isFinite(u.expandedTimeout) && u.expandedTimeout > 0, p = e ?? i;
1223
+ function De({ session: e, store: t, fabRef: n, onClick: r }) {
1224
+ let [i, a] = d(e), [o, c] = d(null), l = Te(e), u = e?.survey.fab, f = (u?.timerStyle === "bar" || u?.timerStyle === "fill") && typeof u.expandedTimeout == "number" && Number.isFinite(u.expandedTimeout) && u.expandedTimeout > 0, p = e ?? i;
1221
1225
  return X(() => {
1222
1226
  e && a(e);
1223
1227
  }, [e]), X(() => {
1224
- !e && i && Ce(n.current);
1228
+ !e && i && Ee(n.current);
1225
1229
  }, [
1226
1230
  n,
1227
1231
  i,
1228
1232
  e
1229
1233
  ]), s(() => {
1230
1234
  if (!l) return;
1231
- let e = Q(), n = setTimeout(() => {
1235
+ let e = $(), n = setTimeout(() => {
1232
1236
  t.confirmPresentation("expanded_fab"), t.confirmFabEntranceCompleted();
1233
- }, e ? 0 : ve), r = setTimeout(() => c(l), e ? 0 : f ? ye : ve);
1237
+ }, e ? 0 : xe), r = setTimeout(() => c(l), e ? 0 : f ? Se : xe);
1234
1238
  return () => {
1235
1239
  clearTimeout(n), clearTimeout(r);
1236
1240
  };
@@ -1240,7 +1244,7 @@ function we({ session: e, store: t, fabRef: n, onClick: r }) {
1240
1244
  t
1241
1245
  ]), s(() => {
1242
1246
  if (e || !i) return;
1243
- let t = setTimeout(() => a(null), Q() ? 0 : be);
1247
+ let t = setTimeout(() => a(null), $() ? 0 : Ce);
1244
1248
  return () => clearTimeout(t);
1245
1249
  }, [i, e]), p ? /* @__PURE__ */ h(ie, {
1246
1250
  session: p,
@@ -1249,7 +1253,7 @@ function we({ session: e, store: t, fabRef: n, onClick: r }) {
1249
1253
  animationState: e ? o === l ? "visible" : "entering" : "exiting"
1250
1254
  }) : null;
1251
1255
  }
1252
- function Te({ session: e, store: t, modal: n }) {
1256
+ function Oe({ session: e, store: t, modal: n }) {
1253
1257
  let [r, i] = d(e), a = u(null), o = e ?? r;
1254
1258
  return X(() => {
1255
1259
  e && i(e);
@@ -1260,24 +1264,24 @@ function Te({ session: e, store: t, modal: n }) {
1260
1264
  }));
1261
1265
  }, [e]), s(() => {
1262
1266
  if (e || !r) return;
1263
- let t = setTimeout(() => i(null), Q() ? 0 : xe);
1267
+ let t = setTimeout(() => i(null), $() ? 0 : Z);
1264
1268
  return () => clearTimeout(t);
1265
- }, [r, e]), o ? /* @__PURE__ */ h(me, {
1269
+ }, [r, e]), o ? /* @__PURE__ */ h(he, {
1266
1270
  session: o,
1267
1271
  store: t,
1268
1272
  modal: n,
1269
1273
  rootRef: a
1270
- }, $(o)) : null;
1274
+ }, Te(o)) : null;
1271
1275
  }
1272
- function Ee({ session: e, store: t, placement: n, modal: r }) {
1276
+ function ke({ session: e, store: t, placement: n, modal: r }) {
1273
1277
  let [i, a] = d(e), o = e ?? i;
1274
1278
  return X(() => {
1275
1279
  e && a(e);
1276
1280
  }, [e]), s(() => {
1277
1281
  if (e || !i) return;
1278
- let t = i.sentimentPresentation === "bar" ? Q() ? z.reduced : z.removal : 0, n = setTimeout(() => a(null), t);
1282
+ let t = i.sentimentPresentation === "bar" ? $() ? z.reduced : z.removal : 0, n = setTimeout(() => a(null), t);
1279
1283
  return () => clearTimeout(n);
1280
- }, [e, i]), !o || !e && o.sentimentPresentation !== "bar" ? null : /* @__PURE__ */ h(_e, {
1284
+ }, [e, i]), !o || !e && o.sentimentPresentation !== "bar" ? null : /* @__PURE__ */ h(be, {
1281
1285
  session: o,
1282
1286
  store: t,
1283
1287
  placement: n,
@@ -1285,7 +1289,7 @@ function Ee({ session: e, store: t, placement: n, modal: r }) {
1285
1289
  exiting: !e
1286
1290
  }, o.presentationId);
1287
1291
  }
1288
- function De({ store: e, portal: t = !0, placement: n = "fixed" }) {
1292
+ function Ae({ store: e, portal: t = !0, placement: n = "fixed" }) {
1289
1293
  let r = f(o((t) => e.subscribe(t), [e]), o(() => e.getSnapshot(), [e]), o(() => e.getServerSnapshot(), [e])).state, i = u(null), a = u(null), c = u(null), l = u(null), d = r ? r.completion ? "completion" : r.isOpen ? `sheet:${r.currentNodeId}` : `fab:${r.fabState}` : "none";
1290
1294
  X(() => {
1291
1295
  if (!r || !i.current) return;
@@ -1294,10 +1298,10 @@ function De({ store: e, portal: t = !0, placement: n = "fixed" }) {
1294
1298
  }, [r]), s(() => {
1295
1299
  let t = e.getState();
1296
1300
  if (!t) {
1297
- let e = i.current?.querySelector("[data-presentation=\"bar\"][data-exiting=\"true\"]"), t = i.current?.querySelector(".sb-fab--exiting") ? be : xe, n = setTimeout(() => {
1301
+ let e = i.current?.querySelector("[data-presentation=\"bar\"][data-exiting=\"true\"]"), t = i.current?.querySelector(".sb-fab--exiting") ? Ce : Z, n = setTimeout(() => {
1298
1302
  let e = l.current;
1299
1303
  e?.isConnected ? e.focus() : e && i.current?.focus(), l.current = null;
1300
- }, e ? Q() ? z.reduced : z.removal : Q() ? 0 : t);
1304
+ }, e ? $() ? z.reduced : z.removal : $() ? 0 : t);
1301
1305
  return () => clearTimeout(n);
1302
1306
  }
1303
1307
  if (t.isOpen || t.completion) {
@@ -1312,11 +1316,11 @@ function De({ store: e, portal: t = !0, placement: n = "fixed" }) {
1312
1316
  let e = a.current;
1313
1317
  if (!e || !c.current) return;
1314
1318
  let i = window.visualViewport, o = n === "inline" ? t.getBoundingClientRect() : null, s = n === "inline" ? t.clientWidth || o.width : i?.width && i.width > 0 ? i.width : window.innerWidth, l = n === "inline" ? t.clientHeight || o.height : i?.height && i.height > 0 ? i.height : window.innerHeight, u = e.getBoundingClientRect(), d = getComputedStyle(c.current), f = {
1315
- top: Z(d.paddingTop),
1316
- right: Z(d.paddingRight),
1317
- bottom: Z(d.paddingBottom),
1318
- left: Z(d.paddingLeft)
1319
- }, p = Math.max(0, s - f.left - f.right), m = e.querySelector(".sb-fab__label"), h = m ? m.scrollWidth || m.getBoundingClientRect().width || Se(m.textContent ?? "") : 0, g = Math.min(p, Math.max(86, 86 + Math.ceil(h))), _ = e.offsetHeight || u.height || 60;
1319
+ top: Q(d.paddingTop),
1320
+ right: Q(d.paddingRight),
1321
+ bottom: Q(d.paddingBottom),
1322
+ left: Q(d.paddingLeft)
1323
+ }, p = Math.max(0, s - f.left - f.right), m = e.querySelector(".sb-fab__label"), h = m ? m.scrollWidth || m.getBoundingClientRect().width || we(m.textContent ?? "") : 0, g = Math.min(p, Math.max(86, 86 + Math.ceil(h))), _ = e.offsetHeight || u.height || 60;
1320
1324
  e.style.setProperty("--sb-fab-expanded-width", `${g}px`), e.style.setProperty("--sb-fab-label-width", `${Math.max(0, g - 86)}px`);
1321
1325
  let v = Math.max(0, Math.min(1, r.survey.fab?.placement?.anchor.x ?? 1));
1322
1326
  e.style.setProperty("--sb-fab-anchor-offset", `${(g - 60) * v}px`);
@@ -1367,21 +1371,21 @@ function De({ store: e, portal: t = !0, placement: n = "fixed" }) {
1367
1371
  ref: c,
1368
1372
  className: "sb-safe-area-probe"
1369
1373
  }),
1370
- /* @__PURE__ */ h(Ee, {
1374
+ /* @__PURE__ */ h(ke, {
1371
1375
  session: r?.snackbar ? r : null,
1372
1376
  store: e,
1373
1377
  placement: n,
1374
1378
  modal: t
1375
1379
  }),
1376
- /* @__PURE__ */ h(we, {
1380
+ /* @__PURE__ */ h(De, {
1377
1381
  session: r && !r.snackbar && !r.isOpen && !r.completion && r.fabState === "expanded" ? r : null,
1378
1382
  store: e,
1379
1383
  fabRef: a,
1380
1384
  onClick: () => {
1381
- Ce(a.current), l.current = a.current, e.openSurvey();
1385
+ Ee(a.current), l.current = a.current, e.openSurvey();
1382
1386
  }
1383
1387
  }),
1384
- /* @__PURE__ */ h(Te, {
1388
+ /* @__PURE__ */ h(Oe, {
1385
1389
  session: r && !r.snackbar && (r.isOpen || r.completion) ? r : null,
1386
1390
  store: e,
1387
1391
  modal: t
@@ -1391,4 +1395,4 @@ function De({ store: e, portal: t = !0, placement: n = "fixed" }) {
1391
1395
  return t && typeof document < "u" ? p(m, document.body) : m;
1392
1396
  }
1393
1397
  //#endregion
1394
- export { De as t };
1398
+ export { Ae as t };
@@ -1 +1 @@
1
- {"version":3,"file":"SurveySnackbar.d.ts","sourceRoot":"","sources":["../../src/lib/components/SurveySnackbar.tsx"],"names":[],"mappings":"AACA,OAAO,EAA0D,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAuBpJ,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAe,EAAE,EAAE;IACpF,OAAO,EAAE,kBAAkB,CAAA;IAC3B,KAAK,EAAE,kBAAkB,CAAA;IACzB,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAA;IAC7B,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,+BA+LA"}
1
+ {"version":3,"file":"SurveySnackbar.d.ts","sourceRoot":"","sources":["../../src/lib/components/SurveySnackbar.tsx"],"names":[],"mappings":"AACA,OAAO,EAA0D,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AA+BpJ,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAe,EAAE,EAAE;IACpF,OAAO,EAAE,kBAAkB,CAAA;IAC3B,KAAK,EAAE,kBAAkB,CAAA;IACzB,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAA;IAC7B,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,+BA+LA"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./SurveyRenderer-fWml4rfW.js";
1
+ import { t as e } from "./SurveyRenderer-BhNcL0CG.js";
2
2
  import { PendingInteractionStorageError as t, SidebandApiError as n, SurveySessionStore as r, SurveySessionStore as i, buildFabTitle as a, createSidebandClient as o, createSidebandClient as s, createSidebandRuntime as c, getChoiceValue as l } from "@sidebandai/sideband-core";
3
3
  import { createContext as u, useCallback as d, useContext as f, useEffect as p, useMemo as m, useRef as h, useState as g, useSyncExternalStore as _ } from "react";
4
4
  import { jsx as v, jsxs as y } from "react/jsx-runtime";
@@ -42,7 +42,7 @@ function k(e, t) {
42
42
  }
43
43
  }), a = c({
44
44
  ...e,
45
- libraryVersion: "1.4.5",
45
+ libraryVersion: "1.4.6-rc.2",
46
46
  onSyncResponse: (e) => r.handleSyncResponse(e)
47
47
  });
48
48
  return n.current = a, {
package/dist/preview.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./SurveyRenderer-fWml4rfW.js";
1
+ import { t as e } from "./SurveyRenderer-BhNcL0CG.js";
2
2
  import { SurveySessionStore as t } from "@sidebandai/sideband-core";
3
3
  import { createElement as n } from "react";
4
4
  import { flushSync as r } from "react-dom";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sidebandai/sideband-react",
3
- "version": "1.4.5",
3
+ "version": "1.4.6-rc.2",
4
4
  "description": "React SDK for Sideband client sync surveys and prompts.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,11 +35,11 @@
35
35
  }
36
36
  },
37
37
  "peerDependencies": {
38
- "react": "^19.0.0",
39
- "react-dom": "^19.0.0"
38
+ "react": "^18.3.0 || ^19.0.0",
39
+ "react-dom": "^18.3.0 || ^19.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@sidebandai/sideband-core": "1.4.5"
42
+ "@sidebandai/sideband-core": "1.4.6-rc.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "vite build --config ../../vite.react.config.ts && tsc -p tsconfig.lib.json && node ../../scripts/prepare-react-package.mjs",