@applicaster/zapp-react-native-utils 14.0.0-alpha.5621117258 → 14.0.0-alpha.5974411329

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.
Files changed (91) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -83
  2. package/actionsExecutor/ScreenActions.ts +163 -0
  3. package/actionsExecutor/StorageActions.ts +110 -0
  4. package/actionsExecutor/feedDecorator.ts +171 -0
  5. package/actionsExecutor/screenResolver.ts +11 -0
  6. package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
  7. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  8. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  9. package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
  10. package/analyticsUtils/__tests__/analyticsUtils.test.js +14 -0
  11. package/analyticsUtils/events.ts +8 -0
  12. package/analyticsUtils/index.tsx +3 -4
  13. package/analyticsUtils/manager.ts +1 -1
  14. package/appUtils/HooksManager/Hook.ts +4 -4
  15. package/appUtils/HooksManager/index.ts +11 -1
  16. package/appUtils/accessibilityManager/index.ts +7 -4
  17. package/appUtils/contextKeysManager/contextResolver.ts +31 -1
  18. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  19. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
  20. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  21. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  22. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  23. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  24. package/arrayUtils/index.ts +8 -3
  25. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  26. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  27. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  28. package/audioPlayerUtils/assets/index.ts +2 -0
  29. package/audioPlayerUtils/index.ts +242 -0
  30. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  31. package/componentsUtils/index.ts +4 -1
  32. package/conf/player/__tests__/selectors.test.ts +34 -0
  33. package/conf/player/selectors.ts +10 -0
  34. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  35. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  36. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  37. package/configurationUtils/__tests__/manifestKeyParser.test.ts +547 -0
  38. package/configurationUtils/index.ts +63 -34
  39. package/configurationUtils/manifestKeyParser.ts +57 -32
  40. package/focusManager/FocusManager.ts +26 -16
  41. package/focusManager/Tree.ts +25 -21
  42. package/focusManager/__tests__/FocusManager.test.ts +50 -8
  43. package/index.d.ts +0 -9
  44. package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
  45. package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
  46. package/manifestUtils/createConfig.js +4 -1
  47. package/manifestUtils/defaultManifestConfigurations/player.js +1239 -200
  48. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
  49. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  50. package/navigationUtils/index.ts +6 -4
  51. package/package.json +2 -3
  52. package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
  53. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
  54. package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
  55. package/playerUtils/_internals/index.ts +1 -0
  56. package/playerUtils/_internals/utils.ts +31 -0
  57. package/playerUtils/configurationUtils.ts +0 -44
  58. package/playerUtils/getPlayerActionButtons.ts +17 -0
  59. package/playerUtils/index.ts +2 -0
  60. package/playerUtils/useValidatePlayerConfig.tsx +22 -19
  61. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  62. package/reactHooks/cell-click/index.ts +8 -1
  63. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
  64. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -0
  65. package/reactHooks/feed/useBatchLoading.ts +11 -9
  66. package/reactHooks/feed/useFeedLoader.tsx +25 -12
  67. package/reactHooks/feed/usePipesCacheReset.ts +3 -3
  68. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  69. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  70. package/reactHooks/layout/isTablet/index.ts +12 -5
  71. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  72. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  73. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  74. package/reactHooks/navigation/index.ts +7 -5
  75. package/reactHooks/navigation/useIsScreenActive.ts +9 -5
  76. package/reactHooks/navigation/useRoute.ts +7 -2
  77. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  78. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  79. package/reactHooks/screen/useScreenContext.ts +1 -1
  80. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
  81. package/reactHooks/state/useRivers.ts +7 -8
  82. package/riverComponetsMeasurementProvider/index.tsx +1 -1
  83. package/services/js2native.ts +1 -0
  84. package/storage/ScreenSingleValueProvider.ts +201 -0
  85. package/storage/ScreenStateMultiSelectProvider.ts +290 -0
  86. package/storage/StorageMultiSelectProvider.ts +192 -0
  87. package/storage/StorageSingleSelectProvider.ts +108 -0
  88. package/testUtils/index.tsx +7 -8
  89. package/time/BackgroundTimer.ts +6 -4
  90. package/utils/index.ts +17 -1
  91. package/playerUtils/configurationGenerator.ts +0 -2572
@@ -1,46 +1,48 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
2
  import { Dimensions, StatusBar } from "react-native";
3
+ import { useDimensions } from "../useDimensions";
4
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux";
3
5
 
4
- const mockUsePickFromState = jest.fn();
5
- const mockUseIsScreenActive = jest.fn();
6
- const mockGetInitialDimensions = jest.fn();
7
- const mockGetDeviceInfo = jest.fn();
6
+ import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
8
7
 
9
- jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
10
- ...(jest.requireActual("@applicaster/zapp-react-native-redux/hooks") as {}),
11
- usePickFromState: mockUsePickFromState,
12
- }));
13
-
14
- jest.mock("../../../navigation", () => ({
15
- useIsScreenActive: mockUseIsScreenActive,
16
- }));
8
+ jest.mock("@applicaster/zapp-react-native-redux/hooks", () => {
9
+ return {
10
+ ...jest.requireActual("@applicaster/zapp-react-native-redux/hooks"),
11
+ usePickFromState: jest.fn(),
12
+ };
13
+ });
17
14
 
18
- jest.mock("../helpers", () => ({
19
- getInitialDimensions: mockGetInitialDimensions,
15
+ jest.mock(
16
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive",
17
+ () => ({
18
+ useIsScreenActive: jest.fn().mockReturnValue(true),
19
+ })
20
+ );
21
+
22
+ jest.doMock("../helpers", () => ({
23
+ getInitialDimensions: jest
24
+ .fn()
25
+ .mockReturnValue({ width: 100, height: 200, scale: 1, fontScale: 1 }),
20
26
  }));
21
27
 
22
28
  jest.mock("../../getDeviceInfo", () => ({
23
- getDeviceInfo: mockGetDeviceInfo,
29
+ getDeviceInfo: jest.fn().mockReturnValue({ deviceInfo: "testDeviceInfo" }),
24
30
  }));
25
31
 
26
- const { useDimensions } = require("../useDimensions");
32
+ const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
33
+
34
+ Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
35
+
36
+ Dimensions.addEventListener = jest.fn().mockReturnValue({
37
+ remove: jest.fn(),
38
+ });
27
39
 
28
40
  describe("useDimensions", () => {
29
- const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
30
41
  const mockAppData = { someData: "test" };
31
42
 
32
43
  beforeEach(() => {
33
- jest.clearAllMocks();
34
- Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
35
-
36
- Dimensions.addEventListener = jest.fn().mockReturnValue({
37
- remove: jest.fn(),
38
- });
39
-
40
- mockUsePickFromState.mockReturnValue({ appData: mockAppData });
41
- mockUseIsScreenActive.mockReturnValue(true);
42
- mockGetInitialDimensions.mockReturnValue(mockDimensions);
43
- mockGetDeviceInfo.mockReturnValue({ deviceInfo: "testDeviceInfo" });
44
+ StatusBar.currentHeight = 20;
45
+ (usePickFromState as jest.Mock).mockReturnValue({ appData: mockAppData });
44
46
  });
45
47
 
46
48
  it("returns correct initial dimensions", () => {
@@ -48,12 +50,9 @@ describe("useDimensions", () => {
48
50
  useDimensions("window", { fullDimensions: false })
49
51
  );
50
52
 
51
- expect(result.current).toEqual({
52
- ...mockDimensions,
53
+ expect(result.current).toMatchObject({
53
54
  statusBarHeight: StatusBar.currentHeight,
54
55
  });
55
-
56
- expect(mockGetInitialDimensions).toHaveBeenCalledWith("window");
57
56
  });
58
57
 
59
58
  it("calls handler on mount", () => {
@@ -70,7 +69,7 @@ describe("useDimensions", () => {
70
69
  useDimensions("window", { fullDimensions: false })
71
70
  );
72
71
 
73
- mockUseIsScreenActive.mockReturnValue(false);
72
+ (useIsScreenActive as jest.Mock).mockReturnValue(false);
74
73
  rerender();
75
74
 
76
75
  expect(Dimensions.addEventListener).toHaveBeenCalledWith(
@@ -84,8 +83,7 @@ describe("useDimensions", () => {
84
83
  useDimensions("window", { fullDimensions: true })
85
84
  );
86
85
 
87
- expect(result.current).toEqual({
88
- ...mockDimensions,
86
+ expect(result.current).toMatchObject({
89
87
  scale: 1,
90
88
  fontScale: 1,
91
89
  statusBarHeight: StatusBar.currentHeight,
@@ -98,7 +96,7 @@ describe("useDimensions", () => {
98
96
  );
99
97
 
100
98
  expect(result.current.height).toBe(
101
- mockDimensions.height - StatusBar.currentHeight ?? 0
99
+ mockDimensions.height - (StatusBar?.currentHeight ?? 0)
102
100
  );
103
101
  });
104
102
 
@@ -10,7 +10,7 @@ import { isTV } from "../../../reactUtils";
10
10
  import { Options, UseDimensions } from "../types";
11
11
  import { getDeviceInfo } from "../getDeviceInfo";
12
12
  import { getInitialDimensions } from "./helpers";
13
- import { useIsScreenActive } from "../../navigation";
13
+ import { useIsScreenActive } from "../../navigation/useIsScreenActive";
14
14
 
15
15
  function compensateForScaleIfNeeded(context) {
16
16
  return function () {
@@ -24,8 +24,6 @@ const applyScaleToDimensions = R.unless(R.propEq("scale", 1), (dimensions) => ({
24
24
  scale: 1,
25
25
  }));
26
26
 
27
- const statusBarHeight = StatusBar?.currentHeight;
28
-
29
27
  /**
30
28
  * Returns React-native Dimensions object and updates it on any dimension change
31
29
  * @param {('screen'|'window')} [context=window] - Dimensions context passed to Dimensions.get method
@@ -37,6 +35,7 @@ export const useDimensions: UseDimensions = (
37
35
  context = "window",
38
36
  fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
39
37
  ) => {
38
+ const statusBarHeight = StatusBar?.currentHeight;
40
39
  const isActive = useIsScreenActive();
41
40
  const { appData } = usePickFromState(["appData"]);
42
41
 
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable no-redeclare */
2
- import { useSelector } from "react-redux";
3
- import * as R from "ramda";
2
+ import {
3
+ useAppSelector,
4
+ selectLayoutVersion,
5
+ } from "@applicaster/zapp-react-native-redux";
4
6
 
5
7
  export function useLayoutVersion(): ZappLayoutVersions;
6
8
 
@@ -23,9 +25,7 @@ export function useLayoutVersion({
23
25
  isV2?: boolean;
24
26
  isV1?: boolean;
25
27
  } = {}): boolean | ZappLayoutVersions {
26
- const layoutVersion = useSelector<any, ZappLayoutVersions>(
27
- R.path(["appData", "layoutVersion"])
28
- );
28
+ const layoutVersion = useAppSelector(selectLayoutVersion);
29
29
 
30
30
  if (isV2) {
31
31
  return layoutVersion === "v2";
@@ -14,7 +14,7 @@ import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
14
14
  import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
15
15
  import { useConnectionInfo } from "../connection";
16
16
 
17
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
17
+ import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
18
18
  import { useNavbarState } from "../screen";
19
19
 
20
20
  export { useNavigation } from "./useNavigation";
@@ -127,11 +127,13 @@ export function isNavBarVisible(
127
127
 
128
128
  export const useBackHandler = (cb: () => boolean) => {
129
129
  useEffect(() => {
130
- BackHandler.addEventListener("hardwareBackPress", cb);
130
+ if (!isWeb()) {
131
+ const unsubscribe = BackHandler.addEventListener("hardwareBackPress", cb);
131
132
 
132
- return () => {
133
- BackHandler.removeEventListener("hardwareBackPress", cb);
134
- };
133
+ return () => {
134
+ unsubscribe.remove();
135
+ };
136
+ }
135
137
  }, [cb]);
136
138
  };
137
139
 
@@ -1,3 +1,4 @@
1
+ import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
1
2
  import { useNavigation } from "./useNavigation";
2
3
  import { usePathname } from "./usePathname";
3
4
 
@@ -6,11 +7,14 @@ export const useIsScreenActive = () => {
6
7
  const pathname = usePathname();
7
8
  const { currentRoute, videoModalState } = useNavigation();
8
9
 
9
- if (
10
- videoModalState.visible &&
11
- ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
12
- ) {
13
- return false;
10
+ if (videoModalState.visible) {
11
+ if (pathname.includes(ROUTE_TYPES.VIDEO_MODAL)) {
12
+ return true;
13
+ }
14
+
15
+ if (["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)) {
16
+ return false;
17
+ }
14
18
  }
15
19
 
16
20
  return pathname === currentRoute;
@@ -28,14 +28,19 @@ const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
28
28
 
29
29
  type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
30
30
 
31
- export const useRoute = (): {
31
+ export const useRoute = (
32
+ useLegacy = true
33
+ ): {
32
34
  screenData: VariousScreenData;
33
35
  pathname: string;
34
36
  } => {
35
37
  const pathname = usePathname() || "";
36
38
  const navigator = useNavigation();
39
+ const screenContext = useContext(ScreenDataContext);
37
40
 
38
- const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
41
+ const screenDataContext = useLegacy
42
+ ? legacyScreenData(screenContext)
43
+ : screenContext;
39
44
 
40
45
  const { plugins, contentTypes, rivers } = usePickFromState([
41
46
  "plugins",
@@ -0,0 +1,8 @@
1
+ import { useRoute } from "./useRoute";
2
+ import { useMemo } from "react";
3
+
4
+ export const useScreenStateStore = () => {
5
+ const route = useRoute(false);
6
+
7
+ return useMemo(() => route.screenData["screenStateStore"], [route.pathname]);
8
+ };
@@ -14,6 +14,10 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
14
14
 
15
15
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
16
 
17
+ jest.mock(
18
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
19
+ );
20
+
17
21
  const { useCellResolver } = require("../useCellResolver");
18
22
 
19
23
  describe("cellResolver", () => {
@@ -2,7 +2,7 @@ import { useContext, useMemo } from "react";
2
2
 
3
3
  import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
4
4
  import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
5
- import { useNavigation } from "../navigation/useNavigation";
5
+ import { useNavigation } from "../navigation";
6
6
 
7
7
  import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
8
8
  import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
@@ -1,7 +1,8 @@
1
+ /* eslint-disable no-console */
1
2
  import React from "react";
2
3
  import { render, screen } from "@testing-library/react-native";
3
4
  import { Text } from "react-native";
4
- import { ZStoreProvider, useZStore } from "../ZStoreProvider";
5
+ import { useZStore, ZStoreProvider } from "../ZStoreProvider";
5
6
  import { useStore } from "zustand";
6
7
 
7
8
  interface TestState {
@@ -1,9 +1,8 @@
1
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import {
2
+ useAppSelector,
3
+ selectRivers,
4
+ } from "@applicaster/zapp-react-native-redux";
2
5
 
3
- const riversSelector = ["rivers"];
4
-
5
- export const useRivers = () => {
6
- const { rivers } = usePickFromState(riversSelector as any);
7
-
8
- return rivers;
9
- };
6
+ export function useRivers(): Record<string, ZappRiver> {
7
+ return useAppSelector(selectRivers);
8
+ }
@@ -3,7 +3,7 @@ import { NativeModules, StyleSheet, View } from "react-native";
3
3
  import { getXray } from "@applicaster/zapp-react-native-utils/logger";
4
4
 
5
5
  import { isApplePlatform, isWeb } from "../reactUtils";
6
- import { useRivers } from "../reactHooks/state";
6
+ import { useRivers } from "../reactHooks";
7
7
 
8
8
  const layoutReducer = (state, { payload }) => {
9
9
  return state.map((item, index, _state) => ({
@@ -496,6 +496,7 @@ async function removeStorageListenerHandler(payload: { listenerId?: string }) {
496
496
  function log({ level, messages }) {
497
497
  try {
498
498
  const parsedMessages = parseJsonIfNeeded(messages);
499
+ // eslint-disable-next-line no-console
499
500
  const logFn = console[level] || console.log;
500
501
 
501
502
  if (Array.isArray(parsedMessages)) {
@@ -0,0 +1,201 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+ import { SingleValueProvider } from "./StorageSingleSelectProvider";
3
+ import { createLogger } from "../logger";
4
+ import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
5
+
6
+ export const { log_debug, log_error } = createLogger({
7
+ category: "ScreenSingleValueProvider",
8
+ subsystem: "zapp-react-native-bridge",
9
+ parent: bridgeLogger,
10
+ });
11
+
12
+ export class ScreenSingleValueProvider implements SingleValueProvider {
13
+ // @ts-ignore
14
+ private valueSubject: BehaviorSubject<string | null>;
15
+ private screenStateStoreUnsubscribe: (() => void) | null = null;
16
+
17
+ private static providers: Record<
18
+ string,
19
+ Record<string, SingleValueProvider>
20
+ > = {};
21
+
22
+ public static getProvider(
23
+ key: string,
24
+ screenRoute: string,
25
+ screenStateStore: ScreenStateStore
26
+ ): SingleValueProvider {
27
+ if (!key) {
28
+ throw new Error("ScreenSingleValueProvider: Key is required");
29
+ }
30
+
31
+ if (!screenRoute) {
32
+ throw new Error("ScreenSingleValueProvider: Screen route is required");
33
+ }
34
+
35
+ if (!screenStateStore) {
36
+ throw new Error(
37
+ "ScreenSingleValueProvider: screen state store is required"
38
+ );
39
+ }
40
+
41
+ if (!this.providers[screenRoute]) {
42
+ this.providers[screenRoute] = {};
43
+ }
44
+
45
+ try {
46
+ if (!this.providers[screenRoute][key]) {
47
+ this.providers[screenRoute][key] = new ScreenSingleValueProvider(
48
+ key,
49
+ screenRoute,
50
+ screenStateStore
51
+ );
52
+ } else {
53
+ (
54
+ this.providers[screenRoute][key] as ScreenSingleValueProvider
55
+ ).updateStore(screenStateStore);
56
+ }
57
+ } catch (error) {
58
+ log_error("Failed to create provider", { key, screenRoute, error });
59
+ throw error;
60
+ }
61
+
62
+ return this.providers[screenRoute][key];
63
+ }
64
+
65
+ // @ts-ignore
66
+ private constructor(
67
+ private key: string,
68
+ route: string,
69
+ private screenStateStore: ScreenStateStore
70
+ ) {
71
+ if (!key) {
72
+ throw new Error("ScreenSingleValueProvider: Key is required");
73
+ }
74
+
75
+ if (!screenStateStore) {
76
+ throw new Error(
77
+ "ScreenSingleValueProvider: screen state store is required"
78
+ );
79
+ }
80
+
81
+ this.key = key;
82
+ this.valueSubject = new BehaviorSubject<string | null>(null);
83
+
84
+ this.setupScreenStateSubscription();
85
+
86
+ void this.getValueAsync();
87
+
88
+ log_debug("ScreenSingleValueProvider: Initializing", { key, route });
89
+ }
90
+
91
+ private updateStore(screenStateStore: ScreenStateStore): void {
92
+ this.cleanup();
93
+ this.screenStateStore = screenStateStore;
94
+ this.setupScreenStateSubscription();
95
+ void this.getValueAsync();
96
+ }
97
+
98
+ private setupScreenStateSubscription(): void {
99
+ this.screenStateStoreUnsubscribe = this.screenStateStore.subscribe(
100
+ (state) => ({
101
+ value: state.data[this.key],
102
+ exists: this.key in state.data,
103
+ }),
104
+ (current, previous) => {
105
+ if (!current.exists && previous.exists) {
106
+ log_debug(
107
+ `ScreenSingleValueProvider: Key deleted from store: ${this.key}`
108
+ );
109
+
110
+ // TODO: If we need to handle deletion, we can do it here
111
+ }
112
+
113
+ if (current.value !== previous.value) {
114
+ this.valueSubject.next(current.value || null);
115
+
116
+ log_debug(`ScreenSingleValueProvider: Key updated: ${this.key}`, {
117
+ previous: previous.value,
118
+ current: current.value,
119
+ });
120
+ }
121
+ }
122
+ );
123
+
124
+ log_debug(
125
+ `ScreenSingleValueProvider: screen state store subscription setup for key: ${this.key}`
126
+ );
127
+ }
128
+
129
+ private cleanup(): void {
130
+ if (this.screenStateStoreUnsubscribe) {
131
+ this.screenStateStoreUnsubscribe();
132
+ this.screenStateStoreUnsubscribe = null;
133
+
134
+ log_debug(
135
+ `ScreenSingleValueProvider: Unsubscribed from screen state store for key: ${this.key}`
136
+ );
137
+ }
138
+ }
139
+
140
+ clearValue(): Promise<void> {
141
+ this.screenStateStore.getState().removeValue(this.key);
142
+ this.valueSubject.next(null);
143
+
144
+ log_debug(`clearValue: value cleared for key: ${this.key}`);
145
+
146
+ return Promise.resolve();
147
+ }
148
+
149
+ getObservable(): BehaviorSubject<string | null> {
150
+ return this.valueSubject;
151
+ }
152
+
153
+ getValue(): string | null {
154
+ return this.valueSubject.value;
155
+ }
156
+
157
+ getValueAsync(): Promise<string | null> {
158
+ const currentValue = this.screenStateStore.getState().data[this.key];
159
+ const value = currentValue || null;
160
+ const selected = this.getValue();
161
+ const valuesAreEqual = value === selected;
162
+
163
+ const bothEmpty =
164
+ (value === null || value === "") &&
165
+ (selected === null || selected === "");
166
+
167
+ if (!this.valueSubject.closed && !valuesAreEqual && !bothEmpty) {
168
+ this.valueSubject.next(value);
169
+ }
170
+
171
+ return Promise.resolve(value);
172
+ }
173
+
174
+ setValue(value: string): Promise<void> {
175
+ this.screenStateStore.getState().setValue(this.key, value);
176
+ this.valueSubject.next(value);
177
+
178
+ log_debug(`setValue: value set for key: ${this.key}`, { value });
179
+
180
+ return Promise.resolve();
181
+ }
182
+
183
+ // TODO: remove if not needed
184
+
185
+ public static cleanupRoute(screenRoute: string): void {
186
+ if (this.providers[screenRoute]) {
187
+ Object.values(this.providers[screenRoute]).forEach((provider) => {
188
+ (provider as ScreenSingleValueProvider).destroy();
189
+ });
190
+
191
+ delete this.providers[screenRoute];
192
+ }
193
+ }
194
+
195
+ // TODO: remove if not needed
196
+
197
+ public destroy(): void {
198
+ this.valueSubject.complete();
199
+ this.cleanup();
200
+ }
201
+ }