@nivaro/react 0.3.32 → 0.3.33

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.
@@ -9,7 +9,7 @@ import { noteReplayEvent as _e, createReplayCheckoutState as De } from "../share
9
9
  import { emitReplayTap as Te, setReplayRecorderMode as N, registerReplayCapture as qe, clipEndOffset as Le, withClipKind as Pe } from "../shared/lib/replay-capture.js";
10
10
  import { instrumentConsole as Ne, instrumentRequests as Fe, redactSecrets as Me } from "../shared/lib/replay-context.js";
11
11
  import { instrumentSocket as Oe } from "../shared/lib/replay-socket.js";
12
- const Ue = "nivaro-react@0.3.32", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
12
+ const Ue = "nivaro-react@0.3.33", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
13
13
  function Be(n) {
14
14
  return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
15
15
  const u = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
package/dist/index.d.ts CHANGED
@@ -5003,6 +5003,8 @@ export declare function isCodeError(err: unknown): boolean;
5003
5003
  */
5004
5004
  export declare function isListTimeout(err: unknown): boolean;
5005
5005
 
5006
+ export declare function isReloadingForUpdate(): boolean;
5007
+
5006
5008
  /** True once a 401 said this tab is signed out, until a sign-in is heard. */
5007
5009
  export declare function isSignedOut(): boolean;
5008
5010
 
@@ -8490,7 +8492,7 @@ export declare function registerReplayCapture(fn: Capture, snap?: Snapshot): ()
8490
8492
  export declare function registerRoomOpener(fn: RoomOpener): () => void;
8491
8493
 
8492
8494
  /** Report a source of unsaved work; the returned function removes it. */
8493
- export declare function registerUnsavedWork(label: string, dirty: () => boolean): () => void;
8495
+ export declare function registerUnsavedWork(label: string, dirty: () => boolean, opts?: UnsavedWorkOptions): () => void;
8494
8496
 
8495
8497
  /** Register the host's opener. Returns an unregister function. */
8496
8498
  export declare function registerViewAsOpener(fn: ViewAsOpener): () => void;
@@ -10182,6 +10184,10 @@ declare interface UnsavedSummary {
10182
10184
  /** What would be lost, by label (empty = nothing). */
10183
10185
  export declare function unsavedWorkLabels(): string[];
10184
10186
 
10187
+ declare interface UnsavedWorkOptions {
10188
+ saveForReload?: () => boolean | Promise<boolean>;
10189
+ }
10190
+
10185
10191
  /** The ids an update covers: one, a coalesced list, or null = "too many — refresh it all". */
10186
10192
  export declare function updateItemIds(ev: CollectionUpdateEvent): Array<string | number> | null;
10187
10193
 
@@ -11079,8 +11085,9 @@ export declare function useTypingIndicator(room: string | null): {
11079
11085
 
11080
11086
  export declare function useUnreadChirp(totalUnread: number, rooms?: RoomInfo[]): void;
11081
11087
 
11082
- /** A form reports its dirty state while mounted. */
11083
- export declare function useUnsavedWork(dirty: boolean, label?: string): void;
11088
+ /** A form reports its dirty state while mounted (and, optionally, how to keep it through a
11089
+ * pushed reload — the latest function is always the one called). */
11090
+ export declare function useUnsavedWork(dirty: boolean, label?: string, saveForReload?: () => boolean | Promise<boolean>): void;
11084
11091
 
11085
11092
  /** Directory of users to add to a private channel. */
11086
11093
  export declare function useUserSearch(search: string, enabled: boolean): {
package/dist/index.js CHANGED
@@ -228,35 +228,35 @@ import { formatReplayTail as ru, getReplayTail as tu, installReplayTail as iu }
228
228
  import { getApiUpdate as su, startApiVersionWatch as nu, useApiUpdate as pu } from "./shared/lib/api-version.js";
229
229
  import { getFieldInterface as mu, listFieldInterfaces as fu, onFieldInterfacesChange as uu, registerFieldInterface as xu } from "./shared/lib/field-interfaces.js";
230
230
  import { guardIdentityCall as cu, isSignedOut as Cu, isSignedOutError as Ru, noteCredentialChanged as Su, noteSignedIn as gu, noteUnauthorized as hu, onSignedIn as Pu } from "./shared/lib/signed-out.js";
231
- import { hasUnsavedWork as Tu, registerUnsavedWork as wu, subscribeUnsavedWork as Au, unsavedWorkLabels as Iu, useUnsavedWork as Eu } from "./shared/lib/unsaved-work.js";
232
- import { helpVideoApi as ku, helpVideoKeys as Fu, useHelpVideo as Ou, useHelpVideoWalk as Vu, useHelpVideosFor as vu, useRequiredVideos as bu } from "./shared/components/help-videos/api.js";
233
- import { holdNotification as Nu, huddleHolds as Bu, releaseHeld as Hu } from "./shared/components/chat/huddle/huddle-hold.js";
234
- import { installStaleChunkRecovery as _u, isStaleChunkError as Wu } from "./shared/lib/stale-chunk.js";
235
- import { isListTimeout as Uu, listLoadErrorText as Qu, loadErrorText as Ku } from "./shared/lib/load-error.js";
236
- import { measureClockOffset as qu, serverNow as Yu, setServerClockOffset as Ju } from "./shared/lib/server-clock.js";
237
- import { normalizeFieldType as Xu } from "./hooks/schemaBuilder.js";
238
- import { obligationQueryParams as $u, toneForOutcome as ex } from "./shared/lib/obligation-filters.js";
239
- import { pageAtPayload as rx, usePageAt as tx } from "./shared/lib/use-page-at.js";
240
- import { playNotificationSound as ax } from "./shared/lib/notification-sound.js";
241
- import { rankTeamForFilters as nx, useScopeDimensions as px } from "./shared/components/pipeline/teamScopes.js";
242
- import { resolveNotificationTarget as mx, resolveNotificationTargetFor as fx, runNotificationTarget as ux } from "./shared/lib/notification-target.js";
243
- import { restoreMetadata as dx, startMetadataPersistence as cx, wipeMetadataCache as Cx } from "./shared/lib/metadata-persist.js";
244
- import { rowPresenceKey as Sx, useFieldFocus as gx, usePresence as hx, useRowPresence as Px, useTyping as yx } from "./shared/lib/presence-hooks.js";
245
- import { rumRouteChange as wx, rumWidget as Ax, startRum as Ix } from "./shared/lib/rum.js";
246
- import { seedQuickPickerSteps as Dx } from "./shared/components/item-edit/helpers.js";
247
- import { signalSentence as Fx, useRecordSignalPeers as Ox, useRecordSignalWhile as Vx, useTopicPresence as vx } from "./shared/lib/presence-signals.js";
248
- import { stuckText as Lx } from "./shared/lib/presence-state.js";
249
- import { tapReplaySocket as Bx } from "./shared/lib/replay-socket.js";
250
- import { useAfterIdle as Mx } from "./shared/lib/defer.js";
251
- import { useBackgroundRun as Wx } from "./shared/lib/background-runs.js";
252
- import { useClientChaos as Ux, useClientChaosGate as Qx } from "./shared/components/client-chaos-gate.js";
253
- import { useDebounced as zx } from "./shared/hooks/useDebounced.js";
254
- import { useElapsedLoading as Yx } from "./shared/hooks/useElapsedLoading.js";
255
- import { useEventPath as jx, usePartner as Xx, usePartners as Zx, useRecordIntegrationActivity as $x, useRefreshSignals as ed, useSignalAction as od, useSignals as rd, useSnooze as td } from "./shared/components/integrations/console/api.js";
256
- import { useFeatureFlag as ad, useFeatureFlags as sd } from "./shared/lib/feature-flags.js";
257
- import { useFileHealth as pd } from "./shared/hooks/useFileHealth.js";
258
- import { useOnlineUsers as md } from "./shared/lib/use-online-users.js";
259
- import { usePersonProfile as ud } from "./shared/components/profile/types.js";
231
+ import { hasUnsavedWork as Tu, isReloadingForUpdate as wu, registerUnsavedWork as Au, subscribeUnsavedWork as Iu, unsavedWorkLabels as Eu, useUnsavedWork as Du } from "./shared/lib/unsaved-work.js";
232
+ import { helpVideoApi as Fu, helpVideoKeys as Ou, useHelpVideo as Vu, useHelpVideoWalk as vu, useHelpVideosFor as bu, useRequiredVideos as Lu } from "./shared/components/help-videos/api.js";
233
+ import { holdNotification as Bu, huddleHolds as Hu, releaseHeld as Mu } from "./shared/components/chat/huddle/huddle-hold.js";
234
+ import { installStaleChunkRecovery as Wu, isStaleChunkError as Gu } from "./shared/lib/stale-chunk.js";
235
+ import { isListTimeout as Qu, listLoadErrorText as Ku, loadErrorText as zu } from "./shared/lib/load-error.js";
236
+ import { measureClockOffset as Yu, serverNow as Ju, setServerClockOffset as ju } from "./shared/lib/server-clock.js";
237
+ import { normalizeFieldType as Zu } from "./hooks/schemaBuilder.js";
238
+ import { obligationQueryParams as ex, toneForOutcome as ox } from "./shared/lib/obligation-filters.js";
239
+ import { pageAtPayload as tx, usePageAt as ix } from "./shared/lib/use-page-at.js";
240
+ import { playNotificationSound as sx } from "./shared/lib/notification-sound.js";
241
+ import { rankTeamForFilters as px, useScopeDimensions as lx } from "./shared/components/pipeline/teamScopes.js";
242
+ import { resolveNotificationTarget as fx, resolveNotificationTargetFor as ux, runNotificationTarget as xx } from "./shared/lib/notification-target.js";
243
+ import { restoreMetadata as cx, startMetadataPersistence as Cx, wipeMetadataCache as Rx } from "./shared/lib/metadata-persist.js";
244
+ import { rowPresenceKey as gx, useFieldFocus as hx, usePresence as Px, useRowPresence as yx, useTyping as Tx } from "./shared/lib/presence-hooks.js";
245
+ import { rumRouteChange as Ax, rumWidget as Ix, startRum as Ex } from "./shared/lib/rum.js";
246
+ import { seedQuickPickerSteps as kx } from "./shared/components/item-edit/helpers.js";
247
+ import { signalSentence as Ox, useRecordSignalPeers as Vx, useRecordSignalWhile as vx, useTopicPresence as bx } from "./shared/lib/presence-signals.js";
248
+ import { stuckText as Nx } from "./shared/lib/presence-state.js";
249
+ import { tapReplaySocket as Hx } from "./shared/lib/replay-socket.js";
250
+ import { useAfterIdle as _x } from "./shared/lib/defer.js";
251
+ import { useBackgroundRun as Gx } from "./shared/lib/background-runs.js";
252
+ import { useClientChaos as Qx, useClientChaosGate as Kx } from "./shared/components/client-chaos-gate.js";
253
+ import { useDebounced as qx } from "./shared/hooks/useDebounced.js";
254
+ import { useElapsedLoading as Jx } from "./shared/hooks/useElapsedLoading.js";
255
+ import { useEventPath as Xx, usePartner as Zx, usePartners as $x, useRecordIntegrationActivity as ed, useRefreshSignals as od, useSignalAction as rd, useSignals as td, useSnooze as id } from "./shared/components/integrations/console/api.js";
256
+ import { useFeatureFlag as sd, useFeatureFlags as nd } from "./shared/lib/feature-flags.js";
257
+ import { useFileHealth as ld } from "./shared/hooks/useFileHealth.js";
258
+ import { useOnlineUsers as fd } from "./shared/lib/use-online-users.js";
259
+ import { usePersonProfile as xd } from "./shared/components/profile/types.js";
260
260
  export {
261
261
  X as ACTIVE_GAMEDAYS_KEY,
262
262
  oe as ACTIVE_USER_OPTION_FILTER,
@@ -587,41 +587,42 @@ export {
587
587
  tu as getReplayTail,
588
588
  cu as guardIdentityCall,
589
589
  Tu as hasUnsavedWork,
590
- ku as helpVideoApi,
591
- Fu as helpVideoKeys,
592
- Nu as holdNotification,
590
+ Fu as helpVideoApi,
591
+ Ou as helpVideoKeys,
592
+ Bu as holdNotification,
593
593
  Vi as huddleCallLayerMounted,
594
- Bu as huddleHolds,
594
+ Hu as huddleHolds,
595
595
  Li as idleState,
596
596
  No as installClientChaosFetch,
597
597
  Ps as installIntentPrefetch,
598
598
  iu as installReplayTail,
599
- _u as installStaleChunkRecovery,
599
+ Wu as installStaleChunkRecovery,
600
600
  ur as isChatPanelPinned,
601
601
  Io as isCleanRecording,
602
602
  fl as isCodeError,
603
- Uu as isListTimeout,
603
+ Qu as isListTimeout,
604
+ wu as isReloadingForUpdate,
604
605
  Cu as isSignedOut,
605
606
  Ru as isSignedOutError,
606
- Wu as isStaleChunkError,
607
+ Gu as isStaleChunkError,
607
608
  Zs as layoutPretendDownOptions,
608
609
  fu as listFieldInterfaces,
609
- Qu as listLoadErrorText,
610
+ Ku as listLoadErrorText,
610
611
  M as liveListKey,
611
612
  Da as liveQueryMeta,
612
613
  _ as liveRecordKey,
613
614
  ka as liveRefetchInterval,
614
- Ku as loadErrorText,
615
+ zu as loadErrorText,
615
616
  Nm as maskInputsIn,
616
617
  yf as matchScopeDimension,
617
- qu as measureClockOffset,
618
+ Yu as measureClockOffset,
618
619
  Nf as networkdaysBetween,
619
- Xu as normalizeFieldType,
620
+ Zu as normalizeFieldType,
620
621
  Su as noteCredentialChanged,
621
622
  gu as noteSignedIn,
622
623
  hu as noteUnauthorized,
623
624
  $f as numericIntlOptions,
624
- $u as obligationQueryParams,
625
+ ex as obligationQueryParams,
625
626
  uu as onFieldInterfacesChange,
626
627
  Ni as onIdleChange,
627
628
  Pu as onSignedIn,
@@ -630,14 +631,14 @@ export {
630
631
  Hn as openChatRoom,
631
632
  Ko as openClientChaosToolbar,
632
633
  Mn as openDmWith,
633
- rx as pageAtPayload,
634
+ tx as pageAtPayload,
634
635
  Bf as parseExpression,
635
- ax as playNotificationSound,
636
+ sx as playNotificationSound,
636
637
  eu as precisionOf,
637
638
  ys as prefetchRecord,
638
639
  _m as prepareReplayClip,
639
640
  ii as rankSignals,
640
- nx as rankTeamForFilters,
641
+ px as rankTeamForFilters,
641
642
  Ts as recordQueryKeys,
642
643
  km as registerCatalogItemOpener,
643
644
  _n as registerDmOpener,
@@ -646,57 +647,57 @@ export {
646
647
  Uf as registerLayoutSlot,
647
648
  Wm as registerReplayCapture,
648
649
  Wn as registerRoomOpener,
649
- wu as registerUnsavedWork,
650
+ Au as registerUnsavedWork,
650
651
  Vm as registerViewAsOpener,
651
652
  ef as releaseGatedReads,
652
653
  of as releaseGatedReadsOnSharedFetch,
653
- Hu as releaseHeld,
654
+ Mu as releaseHeld,
654
655
  Gm as replayHref,
655
656
  ym as reportClientCrash,
656
657
  ul as reportCodeError,
657
658
  le as resolveCollectionIcon,
658
- mx as resolveNotificationTarget,
659
- fx as resolveNotificationTargetFor,
660
- dx as restoreMetadata,
659
+ fx as resolveNotificationTarget,
660
+ ux as resolveNotificationTargetFor,
661
+ cx as restoreMetadata,
661
662
  Cp as rowHighlightClass,
662
663
  Rp as rowHighlightTextClass,
663
- Sx as rowPresenceKey,
664
- wx as rumRouteChange,
665
- Ax as rumWidget,
666
- ux as runNotificationTarget,
667
- Dx as seedQuickPickerSteps,
668
- Yu as serverNow,
664
+ gx as rowPresenceKey,
665
+ Ax as rumRouteChange,
666
+ Ix as rumWidget,
667
+ xx as runNotificationTarget,
668
+ kx as seedQuickPickerSteps,
669
+ Ju as serverNow,
669
670
  me as setDisplayTimezone,
670
671
  Jf as setFiscalStartMonth,
671
672
  Hf as setFormulaConstants,
672
673
  fe as setNumberFormat,
673
674
  Eo as setRecordingSelf,
674
- Ju as setServerClockOffset,
675
+ ju as setServerClockOffset,
675
676
  ue as setTimeDisplay,
676
677
  mf as sharedWorkerSupported,
677
678
  ff as shouldUseWorkerSocket,
678
- Fx as signalSentence,
679
+ Ox as signalSentence,
679
680
  Gn as splitMessageTokens,
680
681
  nu as startApiVersionWatch,
681
682
  Cf as startAutofillRun,
682
683
  Bo as startClientChaos,
683
684
  Df as startHelpVideoWalk,
684
- cx as startMetadataPersistence,
685
- Ix as startRum,
685
+ Cx as startMetadataPersistence,
686
+ Ex as startRum,
686
687
  Ho as stopClientChaos,
687
- Lx as stuckText,
688
+ Nx as stuckText,
688
689
  Mo as subscribeClientChaos,
689
- Au as subscribeUnsavedWork,
690
- Bx as tapReplaySocket,
690
+ Iu as subscribeUnsavedWork,
691
+ Hx as tapReplaySocket,
691
692
  xe as titleCase,
692
- ex as toneForOutcome,
693
+ ox as toneForOutcome,
693
694
  Bi as trackActivity,
694
695
  Tf as translateScopeValues,
695
- Iu as unsavedWorkLabels,
696
+ Eu as unsavedWorkLabels,
696
697
  hp as updateItemIds,
697
698
  Pp as updateTouches,
698
699
  $ as useActiveGamedays,
699
- Mx as useAfterIdle,
700
+ _x as useAfterIdle,
700
701
  Dt as useApiFetchConfig,
701
702
  pu as useApiUpdate,
702
703
  xt as useArmedFaults,
@@ -704,7 +705,7 @@ export {
704
705
  w as useAutoRecord,
705
706
  Rf as useAutofillRuns,
706
707
  So as useAvailableBulkActions,
707
- Wx as useBackgroundRun,
708
+ Gx as useBackgroundRun,
708
709
  Un as useChannelAdmin,
709
710
  Qn as useChannelDirectory,
710
711
  Kn as useChannelMembers,
@@ -714,12 +715,12 @@ export {
714
715
  Jn as useChatRooms,
715
716
  jn as useChatSearch,
716
717
  Do as useCleanRecording,
717
- Ux as useClientChaos,
718
- Qx as useClientChaosGate,
718
+ Qx as useClientChaos,
719
+ Kx as useClientChaosGate,
719
720
  Xn as useCreateChannel,
720
721
  Zn as useCreateGroupDm,
721
722
  kf as useCurrentHelpVideoPage,
722
- zx as useDebounced,
723
+ qx as useDebounced,
723
724
  $n as useDeleteMessage,
724
725
  cm as useDisplayPreferences,
725
726
  pt as useDndActive,
@@ -727,23 +728,23 @@ export {
727
728
  kt as useDrilldown,
728
729
  Ft as useDrilldownViews,
729
730
  ep as useEditMessage,
730
- Yx as useElapsedLoading,
731
+ Jx as useElapsedLoading,
731
732
  op as useEntityRoomLink,
732
- jx as useEventPath,
733
- ad as useFeatureFlag,
734
- sd as useFeatureFlags,
733
+ Xx as useEventPath,
734
+ sd as useFeatureFlag,
735
+ nd as useFeatureFlags,
735
736
  F as useFieldArray,
736
- gx as useFieldFocus,
737
+ hx as useFieldFocus,
737
738
  O as useFieldState,
738
- pd as useFileHealth,
739
+ ld as useFileHealth,
739
740
  V as useFormDirty,
740
741
  D as useFormSchema,
741
742
  v as useFormStatus,
742
743
  Ot as useGridFlush,
743
- Ou as useHelpVideo,
744
+ Vu as useHelpVideo,
744
745
  Ti as useHelpVideoRecording,
745
- Vu as useHelpVideoWalk,
746
- vu as useHelpVideosFor,
746
+ vu as useHelpVideoWalk,
747
+ bu as useHelpVideosFor,
747
748
  ws as useIdleNextPage,
748
749
  qi as useImportHealth,
749
750
  As as useIntentPrefetch,
@@ -763,49 +764,49 @@ export {
763
764
  Lt as useNivaroClient,
764
765
  Q as useNivaroForm,
765
766
  tp as useNotificationSoundPreference,
766
- md as useOnlineUsers,
767
+ fd as useOnlineUsers,
767
768
  ip as useOpenRoomRegistration,
768
769
  Nt as useOptionalNivaroClient,
769
770
  yp as useOptionalRealtime,
770
771
  b as useOrderedLayout,
771
772
  Bt as useOverlayState,
772
- tx as usePageAt,
773
- Xx as usePartner,
774
- Zx as usePartners,
773
+ ix as usePageAt,
774
+ Zx as usePartner,
775
+ $x as usePartners,
775
776
  ap as usePeerReadAt,
776
- ud as usePersonProfile,
777
+ xd as usePersonProfile,
777
778
  Ks as usePlanGridHost,
778
- hx as usePresence,
779
+ Px as usePresence,
779
780
  $s as usePretendDownScope,
780
781
  Ze as usePublishAskContext,
781
782
  En as useQuickPickerSteps,
782
783
  Tp as useRealtimeStatus,
783
- $x as useRecordIntegrationActivity,
784
- Ox as useRecordSignalPeers,
785
- Vx as useRecordSignalWhile,
786
- ed as useRefreshSignals,
784
+ ed as useRecordIntegrationActivity,
785
+ Vx as useRecordSignalPeers,
786
+ vx as useRecordSignalWhile,
787
+ od as useRefreshSignals,
787
788
  z as useRelationOptions,
788
- bu as useRequiredVideos,
789
+ Lu as useRequiredVideos,
789
790
  sp as useRoomMembership,
790
791
  np as useRoomPins,
791
- Px as useRowPresence,
792
- px as useScopeDimensions,
792
+ yx as useRowPresence,
793
+ lx as useScopeDimensions,
793
794
  L as useSectionState,
794
795
  pp as useSendChatMessage,
795
796
  J as useSessionRecorder,
796
797
  Yi as useSetImportCadence,
797
- od as useSignalAction,
798
- rd as useSignals,
799
- td as useSnooze,
798
+ rd as useSignalAction,
799
+ td as useSignals,
800
+ id as useSnooze,
800
801
  kl as useSubscriptionMutations,
801
802
  N as useTabState,
802
803
  lp as useTogglePin,
803
804
  mp as useToggleReaction,
804
- vx as useTopicPresence,
805
- yx as useTyping,
805
+ bx as useTopicPresence,
806
+ Tx as useTyping,
806
807
  fp as useTypingIndicator,
807
808
  up as useUnreadChirp,
808
- Eu as useUnsavedWork,
809
+ Du as useUnsavedWork,
809
810
  xp as useUserSearch,
810
811
  jm as useUserSync,
811
812
  B as useWatchFields,
@@ -813,7 +814,7 @@ export {
813
814
  de as userOptionFilter,
814
815
  Mf as validateExpression,
815
816
  vm as viewAs,
816
- Cx as wipeMetadataCache,
817
+ Rx as wipeMetadataCache,
817
818
  _o as withClientChaos,
818
819
  Um as withClipKind,
819
820
  rf as withGetCoalescing,
@@ -1,41 +1,51 @@
1
- import { jsxs as c, jsx as s, Fragment as x } from "react/jsx-runtime";
2
- import { PauseCircle as N, RotateCw as F } from "lucide-react";
3
- import { useState as h, useRef as w, useEffect as k } from "react";
4
- import { markReloadFor as E } from "../lib/client-version.js";
5
- import { shouldObeyForceReload as j, thisTabForReload as T } from "../lib/force-reload.js";
6
- import { subscribeUnsavedWork as C, unsavedWorkLabels as D } from "../lib/unsaved-work.js";
7
- const L = "nvr:force-refresh";
8
- function W() {
9
- const [e, R] = h(null), [y, b] = h(() => Date.now()), [g, l] = h([]), o = w(!1), m = w(!1), p = w(/* @__PURE__ */ new Set());
10
- k(() => {
11
- const i = (r) => {
12
- const t = r.detail ?? {}, n = typeof t.id == "string" && t.id ? t.id : null;
13
- if (n && p.current.has(n) || !j(t, T())) return;
14
- n && p.current.add(n), m.current = !1, l([]);
15
- const d = Math.max(5, Number(t.seconds) || 30), a = Date.now();
16
- R({ deadline: a + d * 1e3, message: String(t.message ?? ""), id: n }), b(a);
1
+ import { jsxs as c, jsx as d, Fragment as k } from "react/jsx-runtime";
2
+ import { PauseCircle as T, RotateCw as C } from "lucide-react";
3
+ import { useState as p, useRef as b, useEffect as E } from "react";
4
+ import { markReloadFor as R } from "../lib/client-version.js";
5
+ import { shouldObeyForceReload as D, thisTabForReload as M } from "../lib/force-reload.js";
6
+ import { subscribeUnsavedWork as O, prepareForReload as y, beginReloadForUpdate as L, unsavedWorkLabels as S } from "../lib/unsaved-work.js";
7
+ const F = "nvr:force-refresh";
8
+ function B() {
9
+ const [r, N] = p(null), [j, g] = p(() => Date.now()), [w, l] = p([]), n = b(!1), m = b(!1), v = b(/* @__PURE__ */ new Set());
10
+ E(() => {
11
+ const o = (s) => {
12
+ const e = s.detail ?? {}, t = typeof e.id == "string" && e.id ? e.id : null;
13
+ if (t && v.current.has(t) || !D(e, M())) return;
14
+ t && v.current.add(t), m.current = !1, l([]);
15
+ const h = Math.max(5, Number(e.seconds) || 30), i = Date.now();
16
+ N({ deadline: i + h * 1e3, message: String(e.message ?? ""), id: t }), g(i);
17
17
  };
18
- return window.addEventListener(L, i), () => window.removeEventListener(L, i);
19
- }, []), k(() => {
20
- if (!e) return;
21
- const i = () => {
22
- o.current || (o.current = !0, e.id && E(e.id), window.location.reload(), setTimeout(() => {
23
- o.current = !1, m.current = !0, l(["unsaved changes on this page"]);
18
+ return window.addEventListener(F, o), () => window.removeEventListener(F, o);
19
+ }, []), E(() => {
20
+ if (!r) return;
21
+ const o = () => {
22
+ n.current || (n.current = !0, r.id && R(r.id), window.location.reload(), setTimeout(() => {
23
+ n.current = !1, m.current = !0, l(["unsaved changes on this page"]);
24
24
  }, 1500));
25
- }, r = () => {
26
- const d = Date.now();
27
- if (b(d), d < e.deadline || o.current || m.current) return;
28
- const a = D();
29
- l((v) => v.join("|") === a.join("|") ? v : a), a.length === 0 && i();
30
- }, t = setInterval(r, 1e3);
31
- document.addEventListener("visibilitychange", r), window.addEventListener("focus", r), window.addEventListener("pageshow", r);
32
- const n = C(() => setTimeout(r, 0));
25
+ };
26
+ let s = !1;
27
+ const e = () => {
28
+ const i = Date.now();
29
+ if (g(i), !(i < r.deadline || n.current || m.current || s)) {
30
+ if (S().length === 0) {
31
+ l((a) => a.length ? [] : a), o();
32
+ return;
33
+ }
34
+ s = !0, y().then((a) => {
35
+ l((x) => x.join("|") === a.join("|") ? x : a), a.length === 0 && (L(), o());
36
+ }).finally(() => {
37
+ s = !1;
38
+ });
39
+ }
40
+ }, t = setInterval(e, 1e3);
41
+ document.addEventListener("visibilitychange", e), window.addEventListener("focus", e), window.addEventListener("pageshow", e);
42
+ const h = O(() => setTimeout(e, 0));
33
43
  return () => {
34
- clearInterval(t), document.removeEventListener("visibilitychange", r), window.removeEventListener("focus", r), window.removeEventListener("pageshow", r), n();
44
+ clearInterval(t), document.removeEventListener("visibilitychange", e), window.removeEventListener("focus", e), window.removeEventListener("pageshow", e), h();
35
45
  };
36
- }, [e]);
37
- const u = e ? Math.max(0, Math.ceil((e.deadline - y) / 1e3)) : 0, f = u === 0 && g.length > 0;
38
- return e ? /* @__PURE__ */ c(
46
+ }, [r]);
47
+ const u = r ? Math.max(0, Math.ceil((r.deadline - j) / 1e3)) : 0, f = u === 0 && w.length > 0;
48
+ return r ? /* @__PURE__ */ c(
39
49
  "div",
40
50
  {
41
51
  role: "alert",
@@ -44,27 +54,27 @@ function W() {
44
54
  "data-nvr-recording-hide": !0,
45
55
  className: "fixed inset-x-0 top-0 z-[150] flex items-center justify-center gap-3 border-b border-amber-300 bg-amber-50 px-4 py-2.5 text-[13px] text-amber-900 dark:border-amber-500/40 dark:bg-[#3a2e10] dark:text-amber-200",
46
56
  children: [
47
- f ? /* @__PURE__ */ s(N, { className: "h-4 w-4 shrink-0" }) : /* @__PURE__ */ s(F, { className: "h-4 w-4 shrink-0 animate-spin" }),
48
- /* @__PURE__ */ s("span", { children: f ? /* @__PURE__ */ c(x, { children: [
49
- /* @__PURE__ */ s("span", { className: "font-semibold", children: "A reload is waiting" }),
57
+ f ? /* @__PURE__ */ d(T, { className: "h-4 w-4 shrink-0" }) : /* @__PURE__ */ d(C, { className: "h-4 w-4 shrink-0 animate-spin" }),
58
+ /* @__PURE__ */ d("span", { children: f ? /* @__PURE__ */ c(k, { children: [
59
+ /* @__PURE__ */ d("span", { className: "font-semibold", children: "A reload is waiting" }),
50
60
  " — save or discard your changes (",
51
- g.join(", ").toLowerCase(),
61
+ w.join(", ").toLowerCase(),
52
62
  ") and the page reloads."
53
- ] }) : /* @__PURE__ */ c(x, { children: [
63
+ ] }) : /* @__PURE__ */ c(k, { children: [
54
64
  /* @__PURE__ */ c("span", { className: "font-semibold", children: [
55
65
  "This page will reload in ",
56
66
  u,
57
67
  "s"
58
68
  ] }),
59
- e.message ? ` — ${e.message}` : " — an administrator pushed an update."
69
+ r.message ? ` — ${r.message}` : " — an administrator pushed an update."
60
70
  ] }) }),
61
- /* @__PURE__ */ s(
71
+ /* @__PURE__ */ d(
62
72
  "button",
63
73
  {
64
74
  type: "button",
65
- onClick: () => {
66
- o.current = !0, e.id && E(e.id), window.location.reload(), setTimeout(() => {
67
- o.current = !1;
75
+ onClick: async () => {
76
+ n.current = !0, r.id && R(r.id), (await y()).length === 0 && L(), window.location.reload(), setTimeout(() => {
77
+ n.current = !1;
68
78
  }, 1500);
69
79
  },
70
80
  className: "shrink-0 rounded-md border border-amber-400 bg-white px-2.5 py-1 text-[12px] font-medium text-amber-800 hover:bg-amber-100 dark:bg-transparent dark:text-amber-200",
@@ -76,6 +86,6 @@ function W() {
76
86
  ) : null;
77
87
  }
78
88
  export {
79
- L as FORCE_RELOAD_EVENT,
80
- W as ForceReloadBanner
89
+ F as FORCE_RELOAD_EVENT,
90
+ B as ForceReloadBanner
81
91
  };