@applicaster/zapp-react-native-utils 16.0.0-alpha.3683430391 → 16.0.0-alpha.4004661200

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 (102) hide show
  1. package/actionsExecutor/ActionExecutor.ts +40 -2
  2. package/actionsExecutor/ActionExecutorContext.tsx +86 -16
  3. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  4. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
  5. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  6. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  7. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +100 -0
  11. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  12. package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
  13. package/actionsExecutor/actions/goBack.ts +60 -0
  14. package/actionsExecutor/actions/goHome.ts +31 -0
  15. package/actionsExecutor/actions/index.ts +8 -0
  16. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  17. package/actionsExecutor/actions/openBottomSheet.ts +320 -0
  18. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  19. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  20. package/actionsExecutor/actions/showToast.ts +64 -8
  21. package/actionsExecutor/consts.ts +25 -0
  22. package/actionsExecutor/feedDecorator.ts +6 -6
  23. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  24. package/appUtils/HooksManager/index.ts +9 -0
  25. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
  26. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  27. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
  28. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  29. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  30. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
  31. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  32. package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
  33. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  34. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  35. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  36. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  37. package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
  38. package/appUtils/playerManager/index.ts +1 -1
  39. package/appUtils/playerManager/player.ts +115 -3
  40. package/appUtils/playerManager/playerFactory.ts +1 -1
  41. package/appUtils/playerManager/playerNative.ts +6 -4
  42. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  43. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  44. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  45. package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
  46. package/arrayUtils/index.ts +79 -0
  47. package/cellUtils/index.ts +30 -3
  48. package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
  49. package/configurationUtils/manifestKeyParser.ts +38 -9
  50. package/configurationUtils/modalBlocksParser.ts +178 -0
  51. package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
  52. package/entryActions/aliasPresentation.ts +124 -0
  53. package/entryActions/buildEntryActions.ts +166 -0
  54. package/entryActions/index.ts +17 -0
  55. package/entryActions/types.ts +39 -0
  56. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  57. package/manifestUtils/_internals/index.js +8 -3
  58. package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
  59. package/manifestUtils/index.js +3 -0
  60. package/manifestUtils/modalBlocks.js +304 -0
  61. package/modalState/ContentViewModel.ts +113 -0
  62. package/modalState/EditableCollection.ts +17 -0
  63. package/modalState/EditableCollectionRegistry.ts +51 -0
  64. package/modalState/ModalOrchestrator.ts +199 -0
  65. package/modalState/RemoteEditableCollection.ts +227 -0
  66. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  67. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  68. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  69. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
  70. package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
  71. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  72. package/modalState/index.ts +30 -83
  73. package/modalState/store.ts +102 -0
  74. package/modalState/types.ts +133 -0
  75. package/modalState/useBottomSheetContent.ts +102 -0
  76. package/package.json +2 -2
  77. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  78. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  79. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  80. package/playerUtils/contentDataKeys.ts +134 -0
  81. package/playerUtils/index.ts +37 -16
  82. package/playerUtils/isAudioItem.ts +26 -0
  83. package/playerUtils/resolvePlayerActions.ts +71 -0
  84. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  85. package/reactHooks/actions/index.ts +67 -2
  86. package/reactHooks/index.ts +2 -0
  87. package/reactHooks/layout/index.ts +1 -1
  88. package/reactHooks/usePluginConfiguration.ts +4 -1
  89. package/reactHooks/utils/__tests__/index.test.js +22 -2
  90. package/reactHooks/utils/index.ts +11 -1
  91. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  92. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  93. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  94. package/uiActionsRegistrator/index.ts +25 -203
  95. package/uiActionsRegistrator/registry.ts +335 -0
  96. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  97. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  98. package/zappFrameworkUtils/localStorageHelper.ts +10 -2
  99. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  100. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  101. package/playerUtils/getPlayerActionButtons.ts +0 -17
  102. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -1,83 +1,30 @@
1
- import { useStore, createStore } from "zustand";
2
-
3
- interface ModalState {
4
- visible: boolean;
5
- screen: any;
6
- options: Record<string, unknown>;
7
- props: Record<string, unknown>;
8
- }
9
-
10
- interface ModalStore {
11
- modalState: ModalState;
12
- setModalState: (newState: Partial<ModalState>) => void;
13
- openModal: (
14
- item: any,
15
- options?: Record<string, unknown>,
16
- props?: Record<string, unknown>
17
- ) => void;
18
- dismissModal: () => void;
19
- }
20
-
21
- const initialModalState: ModalState = {
22
- visible: false,
23
- screen: null,
24
- options: {},
25
- props: {},
26
- };
27
-
28
- export const modalStore = createStore<ModalStore>((set) => ({
29
- modalState: initialModalState,
30
- setModalState: (newState) =>
31
- set((state) => ({
32
- modalState: { ...state.modalState, ...newState },
33
- })),
34
- openModal: ({ item, options = {}, props }: OpenModalArg) =>
35
- set({
36
- modalState: {
37
- visible: true,
38
- screen: item,
39
- options: {
40
- animated: true,
41
- animationType: "slide",
42
- onShow: () => {},
43
- presentationStyle: "overFullScreen",
44
- transparent: true,
45
- ...options,
46
- onDismiss: () => set({ modalState: initialModalState }),
47
- onRequestClose: () => set({ modalState: initialModalState }),
48
- },
49
- props,
50
- },
51
- }),
52
- dismissModal: () => set(() => ({ modalState: initialModalState })),
53
- }));
54
-
55
- export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
56
- useStore(modalStore, selector);
57
-
58
- export const openModal = modalStore.getInitialState().openModal;
59
-
60
- export const dismissModal = modalStore.getInitialState().dismissModal;
61
-
62
- export const openBottomSheetModal = ({
63
- ModalBottomSheetContent,
64
- modalBottomSheetContentProps,
65
- props = {},
66
- options = {},
67
- }: OpenModalBottomSheetArgs) => {
68
- openModal({
69
- item: {
70
- ModalBottomSheetContent,
71
- modalBottomSheetContentProps,
72
- },
73
- props,
74
- options: {
75
- animationType: "none",
76
- animated: false,
77
- ...options,
78
- },
79
- });
80
- };
81
-
82
- export const useModalStoreState = (): ModalState =>
83
- useModalStore<ModalState>((state) => state.modalState);
1
+ export {
2
+ modalStore,
3
+ useModalStore,
4
+ openModal,
5
+ dismissModal,
6
+ openBottomSheetModal,
7
+ useModalStoreState,
8
+ } from "./store";
9
+
10
+ export type { ModalState, ModalStore } from "./store";
11
+
12
+ export { modalOrchestrator } from "./ModalOrchestrator";
13
+
14
+ export { ContentViewModel } from "./ContentViewModel";
15
+
16
+ export type {
17
+ Menu,
18
+ MenuItem,
19
+ Header,
20
+ Content,
21
+ Action,
22
+ PresentSubMenuAction,
23
+ SecondaryAction,
24
+ SelectMode,
25
+ SelectionBehavior,
26
+ } from "./types";
27
+
28
+ export { isPresentSubMenuAction, OPERATIONS, hasOperation } from "./types";
29
+
30
+ export { useBottomSheetContent } from "./useBottomSheetContent";
@@ -0,0 +1,102 @@
1
+ import { createStore, useStore } from "zustand";
2
+
3
+ export interface ModalState {
4
+ visible: boolean;
5
+ screen: any;
6
+ options: Record<string, unknown>;
7
+ props: Record<string, unknown>;
8
+ }
9
+
10
+ export interface ModalStore {
11
+ modalState: ModalState;
12
+ setModalState: (newState: Partial<ModalState>) => void;
13
+ openModal: (
14
+ item: any,
15
+ options?: Record<string, unknown>,
16
+ props?: Record<string, unknown>
17
+ ) => void;
18
+ dismissModal: () => void;
19
+ }
20
+
21
+ const initialModalState: ModalState = {
22
+ visible: false,
23
+ screen: null,
24
+ options: {},
25
+ props: {},
26
+ };
27
+
28
+ export const modalStore = createStore<ModalStore>((set, get) => ({
29
+ modalState: initialModalState,
30
+ setModalState: (newState) =>
31
+ set((state) => ({
32
+ modalState: { ...state.modalState, ...newState },
33
+ })),
34
+ openModal: ({ item, options = {}, props }: OpenModalArg) => {
35
+ const resetStore = () => set({ modalState: initialModalState });
36
+ const { onDismiss, onRequestClose, ...restOptions } = options as any;
37
+
38
+ set({
39
+ modalState: {
40
+ visible: true,
41
+ screen: item,
42
+ options: {
43
+ animated: true,
44
+ animationType: "slide",
45
+ onShow: () => {},
46
+ presentationStyle: "overFullScreen",
47
+ transparent: true,
48
+ ...restOptions,
49
+ // Compose caller-provided callbacks with the store reset so both run
50
+ onDismiss: () => {
51
+ resetStore();
52
+ onDismiss?.();
53
+ },
54
+ onRequestClose: () => {
55
+ resetStore();
56
+ onRequestClose?.();
57
+ },
58
+ },
59
+ props,
60
+ },
61
+ });
62
+ },
63
+ dismissModal: () => {
64
+ const onDismiss = (get().modalState?.options as any)?.onDismiss;
65
+
66
+ if (typeof onDismiss === "function") {
67
+ onDismiss();
68
+ } else {
69
+ set({ modalState: initialModalState });
70
+ }
71
+ },
72
+ }));
73
+
74
+ export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
75
+ useStore(modalStore, selector);
76
+
77
+ export const openModal = modalStore.getInitialState().openModal;
78
+
79
+ export const dismissModal = modalStore.getInitialState().dismissModal;
80
+
81
+ export const openBottomSheetModal = ({
82
+ ModalBottomSheetContent,
83
+ modalBottomSheetContentProps,
84
+ props = {},
85
+ options = {},
86
+ }: OpenModalBottomSheetArgs) => {
87
+ openModal({
88
+ item: {
89
+ ModalBottomSheetContent,
90
+ modalBottomSheetContentProps,
91
+ },
92
+ props,
93
+ options: {
94
+ animationType: "none",
95
+ animated: false,
96
+ ...options,
97
+ },
98
+ });
99
+ };
100
+
101
+ export const useModalStoreState = (): ModalState =>
102
+ useModalStore<ModalState>((state) => state.modalState);
@@ -0,0 +1,133 @@
1
+ export interface Header {
2
+ title: string;
3
+ subtitle?: string;
4
+ icon?: string;
5
+ }
6
+
7
+ export interface Action {
8
+ type: string;
9
+ payload?: any;
10
+ options?: any;
11
+ }
12
+
13
+ // Represented as 3 dots icon on top menu (opens new second level menu on desktop
14
+ // or a new bottom sheet on mobile)
15
+ export interface PresentSubMenuAction extends Action {
16
+ menu: Menu;
17
+ }
18
+
19
+ export interface SecondaryAction {
20
+ action: Action | PresentSubMenuAction;
21
+ icon?: string;
22
+ }
23
+
24
+ /**
25
+ * A group of actions attached to an entry, keyed by a button alias
26
+ * (e.g. "remove_item", "reorder_item"). Injected by the feed decorator and
27
+ * dispatched by the remote EditableCollection when an operation runs.
28
+ */
29
+ export interface EntryActionGroup {
30
+ button?: { alias?: string };
31
+ actions?: Action[];
32
+ }
33
+
34
+ export interface MenuItem {
35
+ id: string;
36
+ title: string;
37
+ summary?: string;
38
+ icon?: string;
39
+ isSelected?: boolean;
40
+ // When item represents an audio item, clicking on it will start playback
41
+ // and secondary action will allow to add it to queue or playlist
42
+ action?: Action | PresentSubMenuAction;
43
+ secondaryAction?: SecondaryAction;
44
+ trailingButton?: any;
45
+ entryActions?: EntryActionGroup[];
46
+ }
47
+
48
+ export type SelectMode = "single" | "multi" | "none";
49
+
50
+ export interface SelectionBehavior {
51
+ selectMode?: SelectMode;
52
+ currentSelection?: string[];
53
+ selector?: string;
54
+ }
55
+
56
+ /**
57
+ * Operations that act on a specific item in the collection.
58
+ * Their action payloads are looked up on the item's entryActions (e.g. "remove_item", "reorder_item").
59
+ */
60
+ export type ItemScopedOperation = "remove" | "reorder";
61
+
62
+ /**
63
+ * Operations that act on the collection as a whole.
64
+ * Their action payloads are looked up on dynamicCollection.events (e.g. events.add, events.clearAll, events.delete).
65
+ */
66
+ export type CollectionScopedOperation = "add" | "clearAll" | "delete";
67
+
68
+ /**
69
+ * UI display or behavior flags that do not require action payloads.
70
+ */
71
+ export type UIOperation = "nowPlaying";
72
+
73
+ export const OPERATIONS = {
74
+ REMOVE: "remove",
75
+ REORDER: "reorder",
76
+ ADD: "add",
77
+ CLEAR_ALL: "clearAll",
78
+ DELETE: "delete",
79
+ NOW_PLAYING: "nowPlaying",
80
+ } as const;
81
+
82
+ export function hasOperation(
83
+ operations: string[] | undefined,
84
+ target: string
85
+ ): boolean {
86
+ if (!Array.isArray(operations)) return false;
87
+
88
+ const targetLower = target.toLowerCase();
89
+
90
+ return operations.some(
91
+ (op) => typeof op === "string" && op.toLowerCase() === targetLower
92
+ );
93
+ }
94
+
95
+ export type Operation =
96
+ | ItemScopedOperation
97
+ | CollectionScopedOperation
98
+ | UIOperation;
99
+
100
+ export interface DynamicCollectionOptions {
101
+ operations: Operation[];
102
+ postUrl?: string;
103
+ provider?: string;
104
+ /**
105
+ * Action handlers for CollectionScopedOperations (e.g. "add", "clearAll", "delete").
106
+ */
107
+ events?: Record<CollectionScopedOperation | string, Action[]>;
108
+ }
109
+
110
+ export interface Content {
111
+ title: string;
112
+ stickyTitle?: boolean;
113
+ items: MenuItem[];
114
+ itemsUrl?: string;
115
+ action?: Action;
116
+ role?: string;
117
+ behavior?: SelectionBehavior;
118
+ dynamicCollection?: DynamicCollectionOptions;
119
+ themePluginId?: string;
120
+ styleOverrides?: Record<string, any>;
121
+ }
122
+
123
+ export interface Menu {
124
+ header?: Header;
125
+ content: Content;
126
+ closeButton?: boolean;
127
+ }
128
+
129
+ export function isPresentSubMenuAction(
130
+ action: any
131
+ ): action is PresentSubMenuAction {
132
+ return !!action && typeof action === "object" && "menu" in action;
133
+ }
@@ -0,0 +1,102 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
+
4
+ import {
5
+ isPresentSubMenuAction,
6
+ MenuItem,
7
+ modalOrchestrator,
8
+ } from "./ModalOrchestrator";
9
+
10
+ import { ContentViewModel } from "./ContentViewModel";
11
+ import type { DynamicCollectionOptions, SelectionBehavior } from "./types";
12
+ import type { EditableCollection } from "./EditableCollection";
13
+
14
+ type Props = {
15
+ viewModel?: ContentViewModel | null;
16
+ onPress: (item: MenuItem) => void | Promise<void>;
17
+ };
18
+
19
+ type Return = {
20
+ items: MenuItem[];
21
+ isLoading: boolean;
22
+ error?: Error | string;
23
+ showCentralLoading: boolean;
24
+ canGoBack: boolean;
25
+ handleItemPress: (item: MenuItem) => Promise<void>;
26
+ goBackOrClose: () => void;
27
+ close: () => void;
28
+ role?: string;
29
+ behavior?: SelectionBehavior;
30
+ dynamicCollection?: DynamicCollectionOptions;
31
+ editableCollection: EditableCollection | null;
32
+ themePluginId?: string;
33
+ };
34
+
35
+ export const useBottomSheetContent = (props: Props): Return => {
36
+ const { onPress, viewModel } = props;
37
+
38
+ const [state, setState] = useState(viewModel?.getState());
39
+
40
+ const [editableItems, setEditableItems] = useState<MenuItem[]>(
41
+ () => viewModel?.getState().items || []
42
+ );
43
+
44
+ // Subscribe to the viewModel state changes
45
+ useEffect(() => {
46
+ return viewModel?.subscribe((nextState) => {
47
+ setState(nextState);
48
+ });
49
+ }, [viewModel]);
50
+
51
+ // Subscribe to editable collection items
52
+ useEffect(() => {
53
+ if (viewModel?.editableCollection) {
54
+ const subscription =
55
+ viewModel.editableCollection.items$.subscribe(setEditableItems);
56
+
57
+ return () => subscription.unsubscribe();
58
+ }
59
+ }, [viewModel?.editableCollection]);
60
+
61
+ /**
62
+ * Handles an item press:
63
+ * - Delegates to the parent onPress (which runs the action and awaits it).
64
+ * - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
65
+ * so that checkmarks (isSelected) reflect the updated server state.
66
+ */
67
+ const handleItemPress = async (item: MenuItem) => {
68
+ const isSubMenu = item.action && isPresentSubMenuAction(item.action);
69
+
70
+ await onPress(item);
71
+
72
+ if (!isSubMenu) {
73
+ await viewModel?.refetch();
74
+ }
75
+ };
76
+
77
+ const goBackOrClose = React.useCallback(() => {
78
+ if (modalOrchestrator.canGoBack) {
79
+ modalOrchestrator.back();
80
+ } else {
81
+ modalOrchestrator.close();
82
+ }
83
+ }, [modalOrchestrator.canGoBack]);
84
+
85
+ return {
86
+ items: viewModel?.editableCollection ? editableItems : state?.items,
87
+ isLoading: toBooleanWithDefaultFalse(state?.isLoading),
88
+ error: state?.error,
89
+ showCentralLoading: toBooleanWithDefaultFalse(
90
+ state?.isLoading && state?.items.length === 0
91
+ ),
92
+ canGoBack: modalOrchestrator.canGoBack,
93
+ handleItemPress,
94
+ goBackOrClose,
95
+ close: () => modalOrchestrator.close(),
96
+ role: state?.role,
97
+ behavior: state?.behavior,
98
+ dynamicCollection: state?.dynamicCollection,
99
+ editableCollection: viewModel?.editableCollection || null,
100
+ themePluginId: state?.themePluginId,
101
+ };
102
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-alpha.3683430391",
3
+ "version": "16.0.0-alpha.4004661200",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-alpha.3683430391",
30
+ "@applicaster/applicaster-types": "16.0.0-alpha.4004661200",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",