@applicaster/zapp-react-native-utils 16.0.0-alpha.6861239588 → 16.0.0-alpha.6918106967
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/actionsExecutor/ActionExecutor.ts +40 -2
- package/actionsExecutor/ActionExecutorContext.tsx +96 -17
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +10 -0
- package/actionsExecutor/actions/navigateToScreen.ts +18 -4
- package/actionsExecutor/actions/openBottomSheet.ts +325 -0
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/actions/showToast.ts +64 -8
- package/actionsExecutor/consts.ts +26 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +1 -1
- package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -53
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +49 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +11 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +54 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +20 -0
- package/appUtils/playerManager/index.ts +1 -1
- package/appUtils/playerManager/player.ts +115 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +6 -4
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +136 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/index.ts +30 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +260 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +296 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +166 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/player.js +349 -20
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +211 -0
- package/modalState/RemoteEditableCollection.ts +227 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +47 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +159 -0
- package/modalState/useBottomSheetContent.ts +104 -0
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +37 -16
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/actions/index.ts +67 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__tests__/index.test.tsx +48 -0
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +2 -0
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +14 -1
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +11 -1
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import {
|
|
3
|
+
PipesClientResponseHelper,
|
|
4
|
+
RequestBuilder,
|
|
5
|
+
} from "@applicaster/zapp-pipes-v2-client";
|
|
6
|
+
import uuidv4 from "uuid/v4";
|
|
7
|
+
import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
|
|
8
|
+
import { openBottomSheetModal } from "../../modalState/store";
|
|
9
|
+
import {
|
|
10
|
+
DynamicCollectionOptions,
|
|
11
|
+
getMenuItemActions,
|
|
12
|
+
isPresentSubMenuAction,
|
|
13
|
+
Menu,
|
|
14
|
+
MenuItem,
|
|
15
|
+
Operation,
|
|
16
|
+
SelectionBehavior,
|
|
17
|
+
} from "../../modalState/types";
|
|
18
|
+
import { actionExecutor, ActionResult } from "../ActionExecutor";
|
|
19
|
+
import { createLogger } from "../../logger";
|
|
20
|
+
|
|
21
|
+
const { log_info, log_error } = createLogger({
|
|
22
|
+
subsystem: "ActionExecutorContext",
|
|
23
|
+
category: "General",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type LoadedSheetContent = {
|
|
27
|
+
items: MenuItem[];
|
|
28
|
+
role?: string;
|
|
29
|
+
behavior?: SelectionBehavior;
|
|
30
|
+
dynamicCollection?: DynamicCollectionOptions;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Parse a raw `dynamic_collection_options` block (feed or inline content) into
|
|
35
|
+
* the typed `DynamicCollectionOptions`. `operations` accepts either a CSV
|
|
36
|
+
* string (feed) or an array (already parsed).
|
|
37
|
+
*/
|
|
38
|
+
export function parseDynamicCollectionOptions(
|
|
39
|
+
raw:
|
|
40
|
+
| {
|
|
41
|
+
operations?: string | string[];
|
|
42
|
+
postUrl?: string;
|
|
43
|
+
provider?: string;
|
|
44
|
+
events?: Record<string, any[]>;
|
|
45
|
+
}
|
|
46
|
+
| undefined
|
|
47
|
+
): DynamicCollectionOptions | undefined {
|
|
48
|
+
if (!raw) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const operations = Array.isArray(raw.operations)
|
|
53
|
+
? (raw.operations as Operation[])
|
|
54
|
+
: ((raw.operations || "").split(",").filter(Boolean) as Operation[]);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
operations,
|
|
58
|
+
postUrl: raw.postUrl,
|
|
59
|
+
provider: raw.provider,
|
|
60
|
+
events: raw.events,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts a ZappEntry from a pipes feed into a MenuItem.
|
|
66
|
+
* - Icon: first src found in the image media_group.
|
|
67
|
+
* - Primary action: taken from tap_actions.actions[0].
|
|
68
|
+
* - isSelected: true when entry.id is in currentSelection.
|
|
69
|
+
*/
|
|
70
|
+
export function entryToMenuItem(
|
|
71
|
+
entry: ZappEntry,
|
|
72
|
+
currentSelection: string[] = []
|
|
73
|
+
): MenuItem {
|
|
74
|
+
const imageGroup = entry.media_group?.find((g) => g.type === "image");
|
|
75
|
+
|
|
76
|
+
const firstImage = Array.isArray(imageGroup?.media_item)
|
|
77
|
+
? imageGroup.media_item[0]
|
|
78
|
+
: imageGroup?.media_item;
|
|
79
|
+
|
|
80
|
+
// Primary action — first tap_action on the entry
|
|
81
|
+
const tapActions = entry.extensions?.tap_actions?.actions || [];
|
|
82
|
+
const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
|
|
83
|
+
|
|
84
|
+
const summary = entry.summary as string;
|
|
85
|
+
|
|
86
|
+
const itemId = String(entry.id ?? entry.title ?? uuidv4());
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
id: itemId,
|
|
90
|
+
title: entry.title as string,
|
|
91
|
+
summary,
|
|
92
|
+
icon: firstImage?.src,
|
|
93
|
+
isSelected: currentSelection.includes(itemId),
|
|
94
|
+
action: primaryAction,
|
|
95
|
+
actions: tapActions,
|
|
96
|
+
entryActions: entry.extensions?.entry_action || [],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function parseCurrentSelection(rawSelection: unknown): string[] {
|
|
101
|
+
if (Array.isArray(rawSelection)) {
|
|
102
|
+
return (rawSelection as any[]).map(String);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (rawSelection !== undefined && rawSelection !== null) {
|
|
106
|
+
return [String(rawSelection)];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function parseBehaviorFromFeed(
|
|
113
|
+
feed: ZappFeed | undefined,
|
|
114
|
+
currentSelection: string[]
|
|
115
|
+
): SelectionBehavior | undefined {
|
|
116
|
+
const raw = feed?.extensions?.behavior;
|
|
117
|
+
|
|
118
|
+
if (!raw && currentSelection.length === 0) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
selectMode: raw?.select_mode,
|
|
124
|
+
currentSelection,
|
|
125
|
+
selector: raw?.selector,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function parseBehaviorFromContentOptions(
|
|
130
|
+
content: Record<string, any> | undefined
|
|
131
|
+
): SelectionBehavior | undefined {
|
|
132
|
+
const raw = content?.behavior ?? content?.extensions?.behavior;
|
|
133
|
+
|
|
134
|
+
if (!raw) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
selectMode: raw.selectMode ?? raw.select_mode,
|
|
140
|
+
currentSelection: parseCurrentSelection(
|
|
141
|
+
raw.currentSelection ?? raw.current_selection
|
|
142
|
+
),
|
|
143
|
+
selector: raw.selector,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
|
|
148
|
+
export async function loadItemsFromSource(
|
|
149
|
+
source: string,
|
|
150
|
+
context?: Record<string, any>
|
|
151
|
+
): Promise<LoadedSheetContent> {
|
|
152
|
+
const requestBuilder = new RequestBuilder()
|
|
153
|
+
.setEntryContext(context?.entry || {})
|
|
154
|
+
.setScreenContext(context?.screenData || {})
|
|
155
|
+
.setUrl(source);
|
|
156
|
+
|
|
157
|
+
await requestBuilder.buildAxiosRequest();
|
|
158
|
+
|
|
159
|
+
const responseData = await requestBuilder.call<ZappFeed>();
|
|
160
|
+
|
|
161
|
+
const responseHelper = new PipesClientResponseHelper(responseData);
|
|
162
|
+
|
|
163
|
+
if (responseHelper.error) {
|
|
164
|
+
throw responseHelper.error;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const feed = responseData?.response as ZappFeed;
|
|
168
|
+
|
|
169
|
+
const currentSelection = parseCurrentSelection(
|
|
170
|
+
feed?.extensions?.behavior?.current_selection
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const items = (feed?.entry || []).map((entry) =>
|
|
174
|
+
entryToMenuItem(entry, currentSelection)
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const dynamicCollectionOptions = feed?.extensions?.dynamic_collection_options;
|
|
178
|
+
|
|
179
|
+
const dynamicCollection = parseDynamicCollectionOptions(
|
|
180
|
+
dynamicCollectionOptions
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
items,
|
|
185
|
+
role: feed?.extensions?.role,
|
|
186
|
+
behavior: parseBehaviorFromFeed(feed, currentSelection),
|
|
187
|
+
dynamicCollection,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function openBottomSheetAction(
|
|
192
|
+
action: ActionType,
|
|
193
|
+
context?: Record<string, any>
|
|
194
|
+
): Promise<ActionResult> {
|
|
195
|
+
try {
|
|
196
|
+
const { content, header, themePluginId, styleOverrides } =
|
|
197
|
+
action.options || {};
|
|
198
|
+
|
|
199
|
+
// Custom body component — keep default ModalComponent so standard header
|
|
200
|
+
// (dismiss x) is used; content.component is body-only (e.g. TextInputContent).
|
|
201
|
+
if (content?.component) {
|
|
202
|
+
log_info("openBottomSheet: using custom content component");
|
|
203
|
+
|
|
204
|
+
openBottomSheetModal({
|
|
205
|
+
modalBottomSheetContentProps: {
|
|
206
|
+
title: header?.title,
|
|
207
|
+
summary: header?.subtitle,
|
|
208
|
+
items: [],
|
|
209
|
+
onPress: () => {},
|
|
210
|
+
contentComponent: content.component,
|
|
211
|
+
contentComponentProps: content.props || {},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return ActionResult.Success;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const inlineItems: ZappEntry[] = content?.items;
|
|
219
|
+
const itemsUrl: string = content?.itemsUrl;
|
|
220
|
+
|
|
221
|
+
let items: MenuItem[];
|
|
222
|
+
let role: string | undefined;
|
|
223
|
+
let behavior: SelectionBehavior | undefined;
|
|
224
|
+
|
|
225
|
+
let dynamicCollection: DynamicCollectionOptions | undefined;
|
|
226
|
+
|
|
227
|
+
if (Array.isArray(inlineItems) && inlineItems.length > 0) {
|
|
228
|
+
log_info("openBottomSheet: using inline items from action options", {
|
|
229
|
+
count: inlineItems.length,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
role = content?.role ?? content?.extensions?.role;
|
|
233
|
+
behavior = parseBehaviorFromContentOptions(content);
|
|
234
|
+
|
|
235
|
+
items = inlineItems.map((entry) =>
|
|
236
|
+
entryToMenuItem(entry, behavior?.currentSelection ?? [])
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
dynamicCollection = parseDynamicCollectionOptions(
|
|
240
|
+
content?.dynamicCollection ??
|
|
241
|
+
content?.extensions?.dynamic_collection_options
|
|
242
|
+
);
|
|
243
|
+
} else if (itemsUrl) {
|
|
244
|
+
log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
|
|
245
|
+
|
|
246
|
+
const loaded = await loadItemsFromSource(itemsUrl, context);
|
|
247
|
+
items = loaded.items;
|
|
248
|
+
role = loaded.role ?? content?.role ?? content?.extensions?.role;
|
|
249
|
+
behavior = loaded.behavior ?? parseBehaviorFromContentOptions(content);
|
|
250
|
+
dynamicCollection = loaded.dynamicCollection;
|
|
251
|
+
|
|
252
|
+
log_info(
|
|
253
|
+
`openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
|
|
254
|
+
);
|
|
255
|
+
} else {
|
|
256
|
+
log_error(
|
|
257
|
+
"openBottomSheet: no itemsUrl, items, or content.component provided in action options"
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return ActionResult.Error;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const menu: Menu = {
|
|
264
|
+
header: header
|
|
265
|
+
? {
|
|
266
|
+
title: header.title,
|
|
267
|
+
subtitle: header.subtitle,
|
|
268
|
+
icon: header.icon,
|
|
269
|
+
}
|
|
270
|
+
: undefined,
|
|
271
|
+
content: {
|
|
272
|
+
title: content?.title ?? "",
|
|
273
|
+
items,
|
|
274
|
+
itemsUrl, // stored so the component can reload after an action
|
|
275
|
+
role,
|
|
276
|
+
behavior,
|
|
277
|
+
dynamicCollection,
|
|
278
|
+
themePluginId,
|
|
279
|
+
styleOverrides: styleOverrides ?? content?.styleOverrides,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Called when the user taps a menu item.
|
|
285
|
+
*
|
|
286
|
+
* - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
|
|
287
|
+
* - Any other Action type → forwarded to the action executor, keeping the
|
|
288
|
+
* original execution context so screen/entry data is available to handlers.
|
|
289
|
+
* The pressed item is also added as `entry` so downstream actions can
|
|
290
|
+
* reference it.
|
|
291
|
+
*/
|
|
292
|
+
const onItemPress = async (item: MenuItem): Promise<void> => {
|
|
293
|
+
const actions = getMenuItemActions(item);
|
|
294
|
+
|
|
295
|
+
const executableActions = actions.filter(
|
|
296
|
+
(action) => !isPresentSubMenuAction(action)
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (executableActions.length > 0) {
|
|
300
|
+
await actionExecutor.handleActions(
|
|
301
|
+
executableActions as ActionType[],
|
|
302
|
+
{
|
|
303
|
+
...context,
|
|
304
|
+
entry: item as any,
|
|
305
|
+
} as any
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
if (action.options?.replace) {
|
|
311
|
+
modalOrchestrator.replace(menu, onItemPress);
|
|
312
|
+
} else {
|
|
313
|
+
modalOrchestrator.open(menu, onItemPress);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return ActionResult.Success;
|
|
317
|
+
} catch (error) {
|
|
318
|
+
log_error("openBottomSheet: failed to open bottom sheet", {
|
|
319
|
+
error,
|
|
320
|
+
action,
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return ActionResult.Error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { ActionResult } from "../ActionExecutor";
|
|
3
|
+
import { ActionHandler, ActionExecutionContext } from "../types";
|
|
4
|
+
import type { PresentScreenFn } from "../../reactHooks/navigation/usePresentScreen";
|
|
5
|
+
import { createLogger } from "../../logger";
|
|
6
|
+
|
|
7
|
+
const { log_error } = createLogger({
|
|
8
|
+
subsystem: "ActionExecutorContext",
|
|
9
|
+
category: "General",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Options for the presentScreen action.
|
|
14
|
+
*/
|
|
15
|
+
export interface PresentScreenOptions {
|
|
16
|
+
/** The screen type to present (from content types mapping) */
|
|
17
|
+
typeMapping: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Entry to present the screen with. Can be:
|
|
21
|
+
* - "@{entry/}" to use the context entry
|
|
22
|
+
* - A ZappEntry object
|
|
23
|
+
* - undefined to present the screen without an entry
|
|
24
|
+
*/
|
|
25
|
+
entry?: "@{entry/}" | ZappEntry;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a present-screen action handler with the provided dependencies.
|
|
30
|
+
*
|
|
31
|
+
* Unlike navigateToScreen, this action does not return until the presented
|
|
32
|
+
* screen reports a result, so a screen that gates the flow (a parental lock,
|
|
33
|
+
* for example) can stop the remaining actions by being cancelled.
|
|
34
|
+
*
|
|
35
|
+
* @param presentScreen - Presents a screen as a modal and resolves with its result
|
|
36
|
+
* @returns An action handler that presents a screen and awaits its outcome
|
|
37
|
+
*/
|
|
38
|
+
export function createPresentScreenAction(
|
|
39
|
+
presentScreen: PresentScreenFn
|
|
40
|
+
): ActionHandler<PresentScreenOptions> {
|
|
41
|
+
return async function presentScreenAction(
|
|
42
|
+
action,
|
|
43
|
+
context?: ActionExecutionContext
|
|
44
|
+
): Promise<ActionResult> {
|
|
45
|
+
const typeMapping = action.options?.typeMapping;
|
|
46
|
+
|
|
47
|
+
if (!typeMapping) {
|
|
48
|
+
log_error("presentScreen: typeMapping option is missing");
|
|
49
|
+
|
|
50
|
+
return ActionResult.Error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const entrySource = action.options?.entry;
|
|
54
|
+
|
|
55
|
+
const entry = entrySource
|
|
56
|
+
? entrySource === "@{entry/}"
|
|
57
|
+
? context?.entry
|
|
58
|
+
: entrySource
|
|
59
|
+
: undefined;
|
|
60
|
+
|
|
61
|
+
if (entry && typeof entry !== "object") {
|
|
62
|
+
log_error(
|
|
63
|
+
`presentScreen: entry option is not an object, entry: ${entry}`
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return ActionResult.Error;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const result = await presentScreen({ typeMapping, entry });
|
|
70
|
+
|
|
71
|
+
if (result.error) {
|
|
72
|
+
return ActionResult.Error;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Anything short of success stops the remaining actions in the chain.
|
|
76
|
+
return result.success ? ActionResult.Success : ActionResult.Cancel;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -57,6 +57,12 @@ export const refreshComponentAction: ActionHandler = async (
|
|
|
57
57
|
}) || source;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
if (!dataSource) {
|
|
61
|
+
log_info("handleAction: refreshComponent skipped: no dataSource found");
|
|
62
|
+
|
|
63
|
+
return ActionResult.Success;
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
|
|
61
67
|
source,
|
|
62
68
|
inflatedUrl: dataSource,
|
|
@@ -62,10 +62,15 @@ export const sendCloudEventAction: ActionHandler<
|
|
|
62
62
|
subject: options.subject || String((entry as ZappEntry)?.id || ""),
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
log_info("handleAction: sendCloudEvent
|
|
65
|
+
log_info("handleAction: sending sendCloudEvent to URL", {
|
|
66
|
+
url: options.url,
|
|
67
|
+
cloudEvent,
|
|
68
|
+
});
|
|
66
69
|
|
|
67
70
|
const { error, code } = await sendCloudEvent(cloudEvent, options.url);
|
|
68
71
|
|
|
72
|
+
log_info("handleAction: sendCloudEvent result", { code, error });
|
|
73
|
+
|
|
69
74
|
if (error) {
|
|
70
75
|
log_error("sendCloudEvent: error sending cloud event", { error });
|
|
71
76
|
|
|
@@ -3,12 +3,65 @@ import { ActionResult } from "../ActionExecutor";
|
|
|
3
3
|
import { ActionHandler } from "../types";
|
|
4
4
|
import { postEvent } from "../../reactHooks/useSubscriberFor";
|
|
5
5
|
|
|
6
|
+
export const CONFIRMATION_TOAST_SOURCE = "confirmation";
|
|
7
|
+
|
|
8
|
+
export const CONFIRMATION_TOAST_DEFAULT_TIMEOUT = 1000;
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Shows a mobile confirmation toast with Theme defaults from
|
|
12
|
+
* `Confirmation Toast / Message` in the base theme plugin.
|
|
13
|
+
*
|
|
14
|
+
* This action is confirmation-only by design: it always stamps
|
|
15
|
+
* `source: "confirmation"` (so Theme confirmation styles apply) and defaults
|
|
16
|
+
* `timeout` to 1000 ms. Non-confirmation toasts (e.g. Offline Experience)
|
|
17
|
+
* must post on the shared `"showToast"` event bus directly and omit `source`.
|
|
18
|
+
* Callers may override individual style fields; Theme supplies the rest.
|
|
19
|
+
*
|
|
20
|
+
* @example From React via ActionExecutorContext
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import React, { useContext } from "react";
|
|
23
|
+
* import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
|
|
24
|
+
*
|
|
25
|
+
* function QueueButton() {
|
|
26
|
+
* const { handleAction } = useContext(ActionExecutorContext);
|
|
27
|
+
*
|
|
28
|
+
* const onPress = () => {
|
|
29
|
+
* void handleAction({
|
|
30
|
+
* type: "showToast",
|
|
31
|
+
* options: { message: "Added to queue" },
|
|
32
|
+
* });
|
|
33
|
+
* };
|
|
34
|
+
*
|
|
35
|
+
* return <Button onPress={onPress} title="Add to queue" />;
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example From code via the actionExecutor singleton
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
|
|
42
|
+
*
|
|
43
|
+
* await actionExecutor.handleAction({
|
|
44
|
+
* type: "showToast",
|
|
45
|
+
* options: {
|
|
46
|
+
* message: "Playlist created",
|
|
47
|
+
* style: { backgroundColor: "#00AA55" }, // optional partial override
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example From entry / pipes actions JSON
|
|
53
|
+
* ```json
|
|
54
|
+
* {
|
|
55
|
+
* "type": "showToast",
|
|
56
|
+
* "options": {
|
|
57
|
+
* "message": "Item removed from playlist"
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
8
61
|
*/
|
|
9
62
|
export interface ShowToastActionOptions {
|
|
10
|
-
id
|
|
11
|
-
message
|
|
63
|
+
id?: string;
|
|
64
|
+
message?: string;
|
|
12
65
|
extraMessage?: string;
|
|
13
66
|
style?: any;
|
|
14
67
|
timeout?: number;
|
|
@@ -17,13 +70,16 @@ export interface ShowToastActionOptions {
|
|
|
17
70
|
export const showToastAction: ActionHandler<ShowToastActionOptions> = async (
|
|
18
71
|
action
|
|
19
72
|
): Promise<ActionResult> => {
|
|
73
|
+
const options = action?.options;
|
|
74
|
+
|
|
20
75
|
postEvent("showToast", [
|
|
21
76
|
{
|
|
22
|
-
id:
|
|
23
|
-
message:
|
|
24
|
-
extraMessage:
|
|
25
|
-
style:
|
|
26
|
-
timeout:
|
|
77
|
+
id: options?.id,
|
|
78
|
+
message: options?.message,
|
|
79
|
+
extraMessage: options?.extraMessage,
|
|
80
|
+
style: options?.style,
|
|
81
|
+
timeout: options?.timeout ?? CONFIRMATION_TOAST_DEFAULT_TIMEOUT,
|
|
82
|
+
source: CONFIRMATION_TOAST_SOURCE,
|
|
27
83
|
},
|
|
28
84
|
]);
|
|
29
85
|
|
|
@@ -2,3 +2,29 @@ export const TOGGLE_FLAG_MAX_ITEMS_REACHED_EVENT =
|
|
|
2
2
|
"action.localStorageToggleFlag.maxItemsReached";
|
|
3
3
|
|
|
4
4
|
export const ACTION_EXECUTOR_EVENT_SOURCE = "ActionExecutor";
|
|
5
|
+
|
|
6
|
+
export const ACTION_TYPES = {
|
|
7
|
+
OPEN_BOTTOM_SHEET: "openBottomSheet",
|
|
8
|
+
DISMISS_BOTTOM_SHEET: "dismissBottomSheet",
|
|
9
|
+
PRESENT_SUB_MENU: "presentSubMenu",
|
|
10
|
+
SEND_CLOUD_EVENT: "sendCloudEvent",
|
|
11
|
+
NAVIGATE_TO_SCREEN: "navigateToScreen",
|
|
12
|
+
PRESENT_SCREEN: "presentScreen",
|
|
13
|
+
GO_BACK: "goBack",
|
|
14
|
+
GO_HOME: "goHome",
|
|
15
|
+
SHOW_TOAST: "showToast",
|
|
16
|
+
LOCAL_STORAGE_SET: "localStorageSet",
|
|
17
|
+
LOCAL_STORAGE_REMOVE: "localStorageRemove",
|
|
18
|
+
LOCAL_STORAGE_TOGGLE_FLAG: "localStorageToggleFlag",
|
|
19
|
+
SESSION_STORAGE_SET: "sessionStorageSet",
|
|
20
|
+
SESSION_STORAGE_REMOVE: "sessionStorageRemove",
|
|
21
|
+
SESSION_STORAGE_TOGGLE_FLAG: "sessionStorageToggleFlag",
|
|
22
|
+
REFRESH_COMPONENT: "refreshComponent",
|
|
23
|
+
SWITCH_LAYOUT: "switchLayout",
|
|
24
|
+
APP_RESTART: "appRestart",
|
|
25
|
+
CONFIRM_DIALOG: "confirmDialog",
|
|
26
|
+
SCREEN_SET_VARIABLE: "screenSetVariable",
|
|
27
|
+
SCREEN_TOGGLE_FLAG: "screenToggleFlag",
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export type KnownActionType = (typeof ACTION_TYPES)[keyof typeof ACTION_TYPES];
|
|
@@ -159,13 +159,13 @@ export const decorateFeed = (feed: ZappFeed) => {
|
|
|
159
159
|
|
|
160
160
|
const decoratedFeed = R.clone(feed);
|
|
161
161
|
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
const selectMode =
|
|
163
|
+
feed.extensions?.preference_editor_options?.select_mode ||
|
|
164
|
+
feed.extensions?.behavior?.select_mode;
|
|
165
165
|
|
|
166
|
-
if (
|
|
166
|
+
if (selectMode === "single") {
|
|
167
167
|
return makeSingleSelect(feed, key, decoratedFeed);
|
|
168
|
-
} else {
|
|
169
|
-
return makeMultiSelect(feed, key, decoratedFeed);
|
|
170
168
|
}
|
|
169
|
+
|
|
170
|
+
return makeMultiSelect(feed, key, decoratedFeed);
|
|
171
171
|
};
|
package/actionsExecutor/types.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface ActionExecutionContext {
|
|
|
33
33
|
/** Callback function for action completion */
|
|
34
34
|
callback?: (result: { success: boolean; error: any; abort: boolean }) => void;
|
|
35
35
|
|
|
36
|
-
screenState
|
|
36
|
+
screenState?: Record<any, any>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "../appUtils/playerManager";
|
|
9
9
|
import { Player } from "../appUtils/playerManager/player";
|
|
10
10
|
import { AnalyticPlayerListener } from "./AnalyticPlayerListener";
|
|
11
|
-
import { PlayerRole } from "../appUtils/playerManager/
|
|
11
|
+
import { PlayerRole } from "../appUtils/playerManager/const";
|
|
12
12
|
|
|
13
13
|
enum PlayerAnalyticsTrackerType {
|
|
14
14
|
PlayerAnalyticsTracker = "PlayerAnalyticsTracker",
|
|
@@ -498,6 +498,15 @@ export function HooksManager({
|
|
|
498
498
|
presentUI
|
|
499
499
|
);
|
|
500
500
|
} catch (e) {
|
|
501
|
+
// Without this the failure is invisible: the hook stops right after the
|
|
502
|
+
// "Executing hook" line, with nothing in the log explaining why and no
|
|
503
|
+
// remaining hook ever running.
|
|
504
|
+
logHookEvent(
|
|
505
|
+
hooksManagerLogger.error,
|
|
506
|
+
`runInBackground: hook ${hookPlugin.identifier} threw: ${e?.message}`,
|
|
507
|
+
{ hook: hookPlugin, payload, error: e, stack: e?.stack }
|
|
508
|
+
);
|
|
509
|
+
|
|
501
510
|
hookPlugin.setStateAndNotify(HOOKS_EVENTS.ERROR, {
|
|
502
511
|
error: e,
|
|
503
512
|
hookPlugin,
|