@sevenfold/setto-client 0.47.0 → 0.49.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.
@@ -33,6 +33,17 @@ export interface SettoLanguagesProps {
33
33
  */
34
34
  inline?: boolean;
35
35
  }
36
+ /**
37
+ * Whether an inline switcher has been drawn in this render, ahead of the
38
+ * floating copy (the provider draws that after the site's tree). Set while
39
+ * drawing rather than from an effect, so a page drawn on a server — and the
40
+ * browser's first render of it — leaves the floating copy out from the start
41
+ * (0.49.0). It was in the prerendered HTML of setto.no and vanished once the
42
+ * page's script ran: a «Norsk» pill blinking in the corner of every page.
43
+ */
44
+ export declare const InlineLanguagesContext: import("react").Context<{
45
+ drawn: boolean;
46
+ } | null>;
36
47
  export declare function SettoLanguages({ languages: given, inline }: SettoLanguagesProps): import("react/jsx-runtime").JSX.Element | null;
37
48
  /**
38
49
  * The floating copy, mounted by the provider.
@@ -23,6 +23,7 @@ import { type ComponentType } from 'react';
23
23
  import type { RootContent } from 'mdast';
24
24
  import { type BuiltinSectionProps } from '../pages/SettoPage.js';
25
25
  import { type BlogFrontmatter } from './contract.js';
26
+ import { type BlogPostData } from './data.js';
26
27
  export declare function SettoBlogSection({ sectionId, first }: BuiltinSectionProps): import("react/jsx-runtime").JSX.Element;
27
28
  /**
28
29
  * The blog for a site that routes by hand instead of through `pages.json`
@@ -30,10 +31,26 @@ export declare function SettoBlogSection({ sectionId, first }: BuiltinSectionPro
30
31
  * path to `settoBlog({ blogPath })`.
31
32
  *
32
33
  * <Route path="/blogg/*" element={<SettoBlog basePath="/blogg" />} />
34
+ *
35
+ * Both of the rest are optional, and are what a page drawn ahead of time
36
+ * needs to come out the same on the server and in the browser's first render
37
+ * (0.49.0), so `hydrateRoot` can take it over:
38
+ *
39
+ * <SettoBlog basePath="/blogg" path={useLocation().pathname} initialPost={post} />
40
+ *
41
+ * - `path`: the address within the router (`useLocation().pathname`, the
42
+ * language prefix already taken off). Without it the blog reads
43
+ * `window.location`, which a server does not have.
44
+ * - `initialPost`: the post being shown, already loaded (`blog.load(slug,
45
+ * locale)`). Used when it is the one this address shows, in place of
46
+ * fetching it in an effect; without it the post's first render is «Henter
47
+ * innlegget …», as before.
33
48
  */
34
- export declare function SettoBlog({ basePath, title }: {
49
+ export declare function SettoBlog({ basePath, title, path, initialPost, }: {
35
50
  basePath?: string;
36
51
  title?: string;
52
+ path?: string;
53
+ initialPost?: BlogPostData | null;
37
54
  }): import("react/jsx-runtime").JSX.Element;
38
55
  /** A post not yet published, as setto-server sends it: the frontmatter and the body's tree, each node with `at`. */
39
56
  export interface BlogDraftData {
@@ -12934,6 +12934,21 @@ function refreshOutcome(started, current) {
12934
12934
  if (current.busy || started.turn !== current.turn) return "defer";
12935
12935
  return "apply";
12936
12936
  }
12937
+ const AVAILABILITY_POLL_MS = 3e4;
12938
+ const AVAILABILITY_POLL_LIVE_MS = 12e4;
12939
+ function presenceTopic(value) {
12940
+ return typeof value === "string" && value.length <= 200 && /^chat-presence:\S+$/.test(value) ? value : null;
12941
+ }
12942
+ function nextAvailabilityChange(humans, now) {
12943
+ let next = null;
12944
+ for (const human of humans) {
12945
+ for (const at of [human.online ? human.onlineUntil : null, human.nearbyUntil]) {
12946
+ const time = at ? Date.parse(at) : NaN;
12947
+ if (Number.isFinite(time) && time > now && (next === null || time < next)) next = time;
12948
+ }
12949
+ }
12950
+ return next;
12951
+ }
12937
12952
  const CAPTION_STRINGS = {
12938
12953
  en: { translatedFrom: "Translated from {language}", translated: "Translated", showOriginal: "Show original", showTranslation: "Show translation" },
12939
12954
  no: { translatedFrom: "Oversatt fra {language}", translated: "Oversatt", showOriginal: "Vis original", showTranslation: "Vis oversettelse" },
@@ -13931,6 +13946,23 @@ function SettoChatWidget({ settings }) {
13931
13946
  const palette = useSitePalette(config.brandColors);
13932
13947
  const desktopPopup = useDesktopPopup();
13933
13948
  const pageVisible = usePageVisible();
13949
+ const refreshAvailabilityRef = useRef(() => void 0);
13950
+ const [presenceLive, setPresenceLive] = useState(false);
13951
+ useConversationChannel(loadSupabase, mounted ? presenceTopic(availability.topic) : null, {
13952
+ onStatus(next) {
13953
+ setPresenceLive(next);
13954
+ if (next) refreshAvailabilityRef.current();
13955
+ },
13956
+ onChanged() {
13957
+ refreshAvailabilityRef.current();
13958
+ },
13959
+ onRead() {
13960
+ },
13961
+ onTyping() {
13962
+ },
13963
+ onLeave() {
13964
+ }
13965
+ });
13934
13966
  const channelRef = useConversationChannel(loadSupabase, mounted ? realtime?.topic ?? null : null, {
13935
13967
  onStatus(next) {
13936
13968
  subscribedRef.current = next;
@@ -14221,13 +14253,20 @@ function SettoChatWidget({ settings }) {
14221
14253
  }).then(async (response) => response.ok ? await response.json() : null).then((next) => {
14222
14254
  if (!cancelled && next) setAvailability(next);
14223
14255
  }).catch(() => void 0);
14256
+ refreshAvailabilityRef.current = () => void refresh();
14224
14257
  void refresh();
14225
- const timer = window.setInterval(() => void refresh(), 3e4);
14258
+ const timer = window.setInterval(() => void refresh(), presenceLive ? AVAILABILITY_POLL_LIVE_MS : AVAILABILITY_POLL_MS);
14226
14259
  return () => {
14227
14260
  cancelled = true;
14228
14261
  window.clearInterval(timer);
14229
14262
  };
14230
- }, [apiUrl, config.siteId, settings, mounted]);
14263
+ }, [apiUrl, config.siteId, settings, mounted, presenceLive]);
14264
+ useEffect(() => {
14265
+ const at = nextAvailabilityChange(availability.humans ?? [], Date.now());
14266
+ if (at === null) return;
14267
+ const timer = window.setTimeout(() => refreshAvailabilityRef.current(), at - Date.now() + 1e3);
14268
+ return () => window.clearTimeout(timer);
14269
+ }, [availability]);
14231
14270
  const greeterKey = greeter ? `${greeter.handle}:${greeter.avatarUrl ?? ""}` : "";
14232
14271
  useEffect(() => {
14233
14272
  if (!mounted || !settings || conversationId.current) return;
@@ -14857,4 +14896,4 @@ export {
14857
14896
  sineOut,
14858
14897
  teamRowLabelled
14859
14898
  };
14860
- //# sourceMappingURL=SettoChat-C4QpE5Gm.js.map
14899
+ //# sourceMappingURL=SettoChat-SqJlsGXL.js.map