@getuserfeedback/react-native 1.3.2 → 1.3.3

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.js CHANGED
@@ -13,6 +13,7 @@ import { assertNoSegmentExternalIdsInValueArgument, CommandSettlementError, Comm
13
13
  import { parseWebViewTransportNativeMessage } from "@getuserfeedback/protocol/webview-transport";
14
14
  import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
15
15
  import { useResolvedHostViewport } from "./host-viewport.js";
16
+ import { applyProviderOverlayFlowState, applyProviderOverlayHandleInvalidated, createDefaultProviderOverlayState, DEFAULT_PROVIDER_OVERLAY_VISIBILITY, updateProviderOverlayReadySequence, } from "./provider-overlay-state.js";
16
17
  import { REACT_NATIVE_SDK_VERSION } from "./version.js";
17
18
  import { WidgetHost, } from "./widget-host.js";
18
19
  export { REACT_NATIVE_SDK_VERSION } from "./version.js";
@@ -102,14 +103,6 @@ const VISIBLE_WIDGET_HOST_LAYOUT_STYLE_KEYS = new Set([
102
103
  ]);
103
104
  const DEFAULT_WIDGET_SHEET_HEIGHT_RATIO = 0.86;
104
105
  const DEFAULT_WIDGET_SHEET_MIN_HEIGHT = 320;
105
- const DEFAULT_WIDGET_HOST_VISIBILITY = {
106
- flowHandleId: null,
107
- hostSourceVersion: null,
108
- isVisible: false,
109
- origin: null,
110
- readySequence: null,
111
- sourceKey: null,
112
- };
113
106
  const createUniqueId = (prefix) => {
114
107
  if (typeof globalThis.crypto !== "undefined" &&
115
108
  typeof globalThis.crypto.randomUUID === "function") {
@@ -258,7 +251,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
258
251
  const NativeView = useMemo(resolveNativeView, []);
259
252
  const [instanceId] = useState(() => { var _a; return (_a = normalizeOptionalString(instanceIdProp)) !== null && _a !== void 0 ? _a : createUniqueId("rn"); });
260
253
  const [nativeMessages, setNativeMessages] = useState([]);
261
- const [widgetHostVisibility, setWidgetHostVisibility] = useState(DEFAULT_WIDGET_HOST_VISIBILITY);
254
+ const [widgetHostVisibility, setWidgetHostVisibility] = useState(DEFAULT_PROVIDER_OVERLAY_VISIBILITY);
262
255
  const resolvedHostViewport = useResolvedHostViewport(hostViewport);
263
256
  const nativeMessagesRef = useRef([]);
264
257
  const pendingCommandsRef = useRef(new Map());
@@ -266,7 +259,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
266
259
  const flowHandleCacheEpochRef = useRef(0);
267
260
  const flowHandleIdsByFlowIdRef = useRef(new Map());
268
261
  const flowCommandSequencesByFlowIdRef = useRef(new Map());
269
- const visibleFlowHandleIdsRef = useRef(new Set());
262
+ const providerOverlayStateRef = useRef(createDefaultProviderOverlayState());
270
263
  const initOptionsRef = useRef(initOptions);
271
264
  const configureOptionsRef = useRef(configureOptions);
272
265
  const initOptionsKey = useMemo(() => toJsonKey(initOptions), [initOptions]);
@@ -293,7 +286,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
293
286
  startupQueuedKeyRef.current = null;
294
287
  flowHandleCacheEpochRef.current += 1;
295
288
  flowHandleIdsByFlowIdRef.current.clear();
296
- visibleFlowHandleIdsRef.current.clear();
289
+ providerOverlayStateRef.current = createDefaultProviderOverlayState();
297
290
  }
298
291
  initOptionsRef.current = initOptions;
299
292
  configureOptionsRef.current = configureOptions;
@@ -528,14 +521,16 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
528
521
  didReissueDeliveredCommands = reissueDeliveredPendingActionCommands();
529
522
  }
530
523
  lastReadyRef.current = Object.assign(Object.assign({}, event), { hostEpoch: hostEpochRef.current });
531
- setWidgetHostVisibility((visibility) => {
532
- if (!visibility.isVisible ||
533
- visibility.sourceKey !== event.sourceKey ||
534
- visibility.hostSourceVersion !== hostSourceVersionRef.current) {
535
- return visibility;
536
- }
537
- return Object.assign(Object.assign({}, visibility), { readySequence: event.readySequence });
524
+ const nextVisibility = updateProviderOverlayReadySequence({
525
+ ready: {
526
+ hostSourceVersion: hostSourceVersionRef.current,
527
+ readySequence: event.readySequence,
528
+ sourceKey: event.sourceKey,
529
+ },
530
+ visibility: providerOverlayStateRef.current.visibility,
538
531
  });
532
+ providerOverlayStateRef.current = Object.assign(Object.assign({}, providerOverlayStateRef.current), { visibility: nextVisibility });
533
+ setWidgetHostVisibility(nextVisibility);
539
534
  enqueueStartupCommands({ force: previous !== null });
540
535
  startPendingCommandTimeouts();
541
536
  return didReissueDeliveredCommands;
@@ -562,8 +557,8 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
562
557
  reissueDeliveredPendingActionCommands();
563
558
  }
564
559
  lastReadyRef.current = null;
565
- setWidgetHostVisibility(DEFAULT_WIDGET_HOST_VISIBILITY);
566
- visibleFlowHandleIdsRef.current.clear();
560
+ providerOverlayStateRef.current = createDefaultProviderOverlayState();
561
+ setWidgetHostVisibility(providerOverlayStateRef.current.visibility);
567
562
  pausePendingCommandTimeouts();
568
563
  }, [
569
564
  handleWidgetReady,
@@ -580,26 +575,14 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
580
575
  }, []);
581
576
  const handleFlowHandleInvalidated = useCallback((flowHandleId) => {
582
577
  deleteCachedFlowHandleId(flowHandleId);
583
- visibleFlowHandleIdsRef.current.delete(flowHandleId);
584
- if (visibleFlowHandleIdsRef.current.size > 0) {
585
- return;
586
- }
587
- setWidgetHostVisibility((visibility) => {
588
- if (visibility.origin !== "handle") {
589
- return visibility;
590
- }
591
- return {
592
- flowHandleId: null,
593
- hostSourceVersion: visibility.hostSourceVersion,
594
- isVisible: false,
595
- origin: null,
596
- readySequence: visibility.readySequence,
597
- sourceKey: visibility.sourceKey,
598
- };
578
+ const nextState = applyProviderOverlayHandleInvalidated({
579
+ flowHandleId,
580
+ state: providerOverlayStateRef.current,
599
581
  });
582
+ providerOverlayStateRef.current = nextState;
583
+ setWidgetHostVisibility(nextState.visibility);
600
584
  }, [deleteCachedFlowHandleId]);
601
585
  const handleFlowStateChanged = useCallback((detail, options) => {
602
- var _a, _b;
603
586
  if (detail.instanceId !== instanceId) {
604
587
  return;
605
588
  }
@@ -607,83 +590,18 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
607
590
  if (!readyState) {
608
591
  return;
609
592
  }
610
- const isVisible = detail.isOpen || detail.isLoading;
611
- if (options.origin === "aggregate") {
612
- if (isVisible) {
613
- visibleFlowHandleIdsRef.current.clear();
614
- }
615
- else if (visibleFlowHandleIdsRef.current.size > 0) {
616
- const flowHandleId = (_a = visibleFlowHandleIdsRef.current.values().next().value) !== null && _a !== void 0 ? _a : null;
617
- setWidgetHostVisibility({
618
- flowHandleId,
619
- hostSourceVersion: hostSourceVersionRef.current,
620
- isVisible: true,
621
- origin: "handle",
622
- readySequence: readyState.readySequence,
623
- sourceKey: readyState.sourceKey,
624
- });
625
- return;
626
- }
627
- }
628
- if (options.origin === "handle") {
629
- if (detail.flowHandleId === undefined) {
630
- return;
631
- }
632
- if (isVisible) {
633
- visibleFlowHandleIdsRef.current.add(detail.flowHandleId);
634
- }
635
- else {
636
- visibleFlowHandleIdsRef.current.delete(detail.flowHandleId);
637
- }
638
- }
639
- if (!isVisible && options.origin === "handle") {
640
- if (visibleFlowHandleIdsRef.current.size > 0) {
641
- return;
642
- }
643
- setWidgetHostVisibility((visibility) => {
644
- if (visibility.origin !== "handle") {
645
- return visibility;
646
- }
647
- return {
648
- flowHandleId: null,
649
- hostSourceVersion: hostSourceVersionRef.current,
650
- isVisible: false,
651
- origin: null,
652
- readySequence: readyState.readySequence,
653
- sourceKey: readyState.sourceKey,
654
- };
655
- });
656
- return;
657
- }
658
- if (isVisible && options.origin === "handle") {
659
- setWidgetHostVisibility((visibility) => {
660
- var _a;
661
- if (visibility.isVisible &&
662
- visibility.origin === "aggregate" &&
663
- visibility.hostSourceVersion === hostSourceVersionRef.current &&
664
- visibility.readySequence === readyState.readySequence &&
665
- visibility.sourceKey === readyState.sourceKey) {
666
- return visibility;
667
- }
668
- return {
669
- flowHandleId: (_a = detail.flowHandleId) !== null && _a !== void 0 ? _a : null,
670
- hostSourceVersion: hostSourceVersionRef.current,
671
- isVisible: true,
672
- origin: "handle",
673
- readySequence: readyState.readySequence,
674
- sourceKey: readyState.sourceKey,
675
- };
676
- });
677
- return;
678
- }
679
- setWidgetHostVisibility({
680
- flowHandleId: options.origin === "handle" ? ((_b = detail.flowHandleId) !== null && _b !== void 0 ? _b : null) : null,
681
- hostSourceVersion: hostSourceVersionRef.current,
682
- isVisible,
593
+ const nextState = applyProviderOverlayFlowState({
594
+ detail,
683
595
  origin: options.origin,
684
- readySequence: readyState.readySequence,
685
- sourceKey: readyState.sourceKey,
596
+ ready: {
597
+ hostSourceVersion: hostSourceVersionRef.current,
598
+ readySequence: readyState.readySequence,
599
+ sourceKey: readyState.sourceKey,
600
+ },
601
+ state: providerOverlayStateRef.current,
686
602
  });
603
+ providerOverlayStateRef.current = nextState;
604
+ setWidgetHostVisibility(nextState.visibility);
687
605
  }, [instanceId]);
688
606
  const handleWebMessage = useCallback((message) => {
689
607
  var _a;
@@ -778,7 +696,8 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
778
696
  return;
779
697
  }
780
698
  visibilitySourceKeyRef.current = hostSourceKey;
781
- setWidgetHostVisibility(DEFAULT_WIDGET_HOST_VISIBILITY);
699
+ providerOverlayStateRef.current = createDefaultProviderOverlayState();
700
+ setWidgetHostVisibility(providerOverlayStateRef.current.visibility);
782
701
  }, [hostSourceKey]);
783
702
  const contextValue = useMemo(() => ({
784
703
  instanceId,
@@ -0,0 +1,43 @@
1
+ export type ProviderOverlayVisibilityOrigin = "aggregate" | "handle";
2
+ export type ProviderOverlayVisibility = {
3
+ flowHandleId: string | null;
4
+ hostSourceVersion: number | null;
5
+ isVisible: boolean;
6
+ origin: ProviderOverlayVisibilityOrigin | null;
7
+ readySequence: number | null;
8
+ sourceKey: string | null;
9
+ };
10
+ export type ProviderOverlayReadyIdentity = {
11
+ hostSourceVersion: number;
12
+ readySequence: number;
13
+ sourceKey: string;
14
+ };
15
+ export type ProviderOverlayFlowStateDetail = {
16
+ flowHandleId?: string;
17
+ isLoading: boolean;
18
+ isOpen: boolean;
19
+ };
20
+ export type ProviderOverlayState = {
21
+ visibility: ProviderOverlayVisibility;
22
+ visibleFlowHandleIds: Set<string>;
23
+ };
24
+ export type ProviderOverlayStateInput = {
25
+ visibility: ProviderOverlayVisibility;
26
+ visibleFlowHandleIds: ReadonlySet<string>;
27
+ };
28
+ export declare const DEFAULT_PROVIDER_OVERLAY_VISIBILITY: ProviderOverlayVisibility;
29
+ export declare const createDefaultProviderOverlayState: () => ProviderOverlayState;
30
+ export declare function updateProviderOverlayReadySequence({ ready, visibility, }: {
31
+ ready: ProviderOverlayReadyIdentity;
32
+ visibility: ProviderOverlayVisibility;
33
+ }): ProviderOverlayVisibility;
34
+ export declare function applyProviderOverlayFlowState({ detail, origin, ready, state, }: {
35
+ detail: ProviderOverlayFlowStateDetail;
36
+ origin: ProviderOverlayVisibilityOrigin;
37
+ ready: ProviderOverlayReadyIdentity;
38
+ state: ProviderOverlayStateInput;
39
+ }): ProviderOverlayState;
40
+ export declare function applyProviderOverlayHandleInvalidated({ flowHandleId, state, }: {
41
+ flowHandleId: string;
42
+ state: ProviderOverlayStateInput;
43
+ }): ProviderOverlayState;
@@ -0,0 +1,134 @@
1
+ export const DEFAULT_PROVIDER_OVERLAY_VISIBILITY = {
2
+ flowHandleId: null,
3
+ hostSourceVersion: null,
4
+ isVisible: false,
5
+ origin: null,
6
+ readySequence: null,
7
+ sourceKey: null,
8
+ };
9
+ export const createDefaultProviderOverlayState = () => ({
10
+ visibility: DEFAULT_PROVIDER_OVERLAY_VISIBILITY,
11
+ visibleFlowHandleIds: new Set(),
12
+ });
13
+ const toVisibleProviderOverlayVisibility = ({ flowHandleId, origin, ready, }) => ({
14
+ flowHandleId,
15
+ hostSourceVersion: ready.hostSourceVersion,
16
+ isVisible: true,
17
+ origin,
18
+ readySequence: ready.readySequence,
19
+ sourceKey: ready.sourceKey,
20
+ });
21
+ const toHiddenProviderOverlayVisibility = (visibility) => ({
22
+ flowHandleId: null,
23
+ hostSourceVersion: visibility.hostSourceVersion,
24
+ isVisible: false,
25
+ origin: null,
26
+ readySequence: visibility.readySequence,
27
+ sourceKey: visibility.sourceKey,
28
+ });
29
+ const isVisibilityForReadyIdentity = (visibility, ready) => visibility.hostSourceVersion === ready.hostSourceVersion &&
30
+ visibility.readySequence === ready.readySequence &&
31
+ visibility.sourceKey === ready.sourceKey;
32
+ export function updateProviderOverlayReadySequence({ ready, visibility, }) {
33
+ if (!visibility.isVisible ||
34
+ visibility.sourceKey !== ready.sourceKey ||
35
+ visibility.hostSourceVersion !== ready.hostSourceVersion) {
36
+ return visibility;
37
+ }
38
+ return Object.assign(Object.assign({}, visibility), { readySequence: ready.readySequence });
39
+ }
40
+ export function applyProviderOverlayFlowState({ detail, origin, ready, state, }) {
41
+ var _a;
42
+ const isVisible = detail.isOpen || detail.isLoading;
43
+ const visibleFlowHandleIds = new Set(state.visibleFlowHandleIds);
44
+ if (origin === "aggregate") {
45
+ if (isVisible) {
46
+ visibleFlowHandleIds.clear();
47
+ return {
48
+ visibleFlowHandleIds,
49
+ visibility: toVisibleProviderOverlayVisibility({
50
+ flowHandleId: null,
51
+ origin,
52
+ ready,
53
+ }),
54
+ };
55
+ }
56
+ if (visibleFlowHandleIds.size > 0) {
57
+ return {
58
+ visibleFlowHandleIds,
59
+ visibility: toVisibleProviderOverlayVisibility({
60
+ flowHandleId: (_a = visibleFlowHandleIds.values().next().value) !== null && _a !== void 0 ? _a : null,
61
+ origin: "handle",
62
+ ready,
63
+ }),
64
+ };
65
+ }
66
+ return {
67
+ visibleFlowHandleIds,
68
+ visibility: {
69
+ flowHandleId: null,
70
+ hostSourceVersion: ready.hostSourceVersion,
71
+ isVisible: false,
72
+ origin,
73
+ readySequence: ready.readySequence,
74
+ sourceKey: ready.sourceKey,
75
+ },
76
+ };
77
+ }
78
+ if (detail.flowHandleId === undefined) {
79
+ return {
80
+ visibleFlowHandleIds,
81
+ visibility: state.visibility,
82
+ };
83
+ }
84
+ if (isVisible) {
85
+ visibleFlowHandleIds.add(detail.flowHandleId);
86
+ if (state.visibility.isVisible &&
87
+ state.visibility.origin === "aggregate" &&
88
+ isVisibilityForReadyIdentity(state.visibility, ready)) {
89
+ return {
90
+ visibleFlowHandleIds,
91
+ visibility: state.visibility,
92
+ };
93
+ }
94
+ return {
95
+ visibleFlowHandleIds,
96
+ visibility: toVisibleProviderOverlayVisibility({
97
+ flowHandleId: detail.flowHandleId,
98
+ origin,
99
+ ready,
100
+ }),
101
+ };
102
+ }
103
+ visibleFlowHandleIds.delete(detail.flowHandleId);
104
+ if (visibleFlowHandleIds.size > 0) {
105
+ return {
106
+ visibleFlowHandleIds,
107
+ visibility: state.visibility,
108
+ };
109
+ }
110
+ if (state.visibility.origin !== "handle") {
111
+ return {
112
+ visibleFlowHandleIds,
113
+ visibility: state.visibility,
114
+ };
115
+ }
116
+ return {
117
+ visibleFlowHandleIds,
118
+ visibility: toHiddenProviderOverlayVisibility(state.visibility),
119
+ };
120
+ }
121
+ export function applyProviderOverlayHandleInvalidated({ flowHandleId, state, }) {
122
+ const visibleFlowHandleIds = new Set(state.visibleFlowHandleIds);
123
+ visibleFlowHandleIds.delete(flowHandleId);
124
+ if (visibleFlowHandleIds.size > 0 || state.visibility.origin !== "handle") {
125
+ return {
126
+ visibleFlowHandleIds,
127
+ visibility: state.visibility,
128
+ };
129
+ }
130
+ return {
131
+ visibleFlowHandleIds,
132
+ visibility: toHiddenProviderOverlayVisibility(state.visibility),
133
+ };
134
+ }
package/dist/version.js CHANGED
@@ -3,4 +3,4 @@ const reactNativeSdkVersion = typeof __GX_REACT_NATIVE_SDK_VERSION__ === "string
3
3
  : "";
4
4
  // Build scripts patch this fallback to the package version for published artifacts.
5
5
  // Source-linked workspace usage keeps the local fallback.
6
- export const REACT_NATIVE_SDK_VERSION = reactNativeSdkVersion.length > 0 ? reactNativeSdkVersion : "1.3.2";
6
+ export const REACT_NATIVE_SDK_VERSION = reactNativeSdkVersion.length > 0 ? reactNativeSdkVersion : "1.3.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getuserfeedback/react-native",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "getuserfeedback React Native SDK",
5
5
  "keywords": [
6
6
  "getuserfeedback",