@applicaster/zapp-react-native-utils 16.0.0-alpha.1205023347 → 16.0.0-alpha.1218188693
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/ActionExecutorContext.tsx +26 -1
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +113 -1
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +6 -0
- package/actionsExecutor/actions/openBottomSheet.ts +20 -11
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/consts.ts +3 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- package/appUtils/playerManager/playerNative.ts +5 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +153 -0
- package/configurationUtils/manifestKeyParser.ts +12 -1
- package/configurationUtils/modalBlocksParser.ts +118 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +195 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/player.js +22 -1
- package/modalState/ModalOrchestrator.ts +21 -9
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/index.ts +6 -1
- package/modalState/types.ts +29 -2
- package/modalState/useBottomSheetContent.ts +9 -7
- package/package.json +2 -2
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/index.ts +17 -1
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/reactHooks/actions/index.ts +67 -2
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- 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/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/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation defaults for backend action aliases.
|
|
3
|
+
*
|
|
4
|
+
* Entries may declare an action by `alias` alone, without a label or an icon.
|
|
5
|
+
* These maps are the last-resort labels/icons for the aliases we know about; an
|
|
6
|
+
* unknown alias falls back to a humanized version of the alias itself.
|
|
7
|
+
*
|
|
8
|
+
* They are defaults, not a framework guarantee: an app that speaks a different
|
|
9
|
+
* alias vocabulary, needs other languages, or does not want to depend on these
|
|
10
|
+
* icon hosts passes its own through `EntryActionDeps.aliasPresentation`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { EntryAction } from "./types";
|
|
14
|
+
|
|
15
|
+
const ADD_TO_PLAYLIST_ICON =
|
|
16
|
+
"https://assets-secure.applicaster.com/zapp/assets/app_family/1710/906728572617/playlist_add_24dp_FFFFFF_FILL0_wght400_GRAD0_opsz24.png";
|
|
17
|
+
|
|
18
|
+
const REMOVE_ICON =
|
|
19
|
+
"https://assets-secure.applicaster.com/zapp/assets/app_family/1710/372097240191/remove_24dp_EA3323_FILL0_wght400_GRAD0_opsz24.png";
|
|
20
|
+
|
|
21
|
+
const EDIT_ICON =
|
|
22
|
+
"https://upload.wikimedia.org/wikipedia/commons/b/b6/Edit-icon.png";
|
|
23
|
+
|
|
24
|
+
/** Known backend action alias labels. */
|
|
25
|
+
export const ALIAS_LABELS: Record<string, string> = {
|
|
26
|
+
add_to_playlist: "Add to Playlist",
|
|
27
|
+
add_to_queue: "Add to Queue",
|
|
28
|
+
add_all_to_queue: "Add all to Queue",
|
|
29
|
+
play_all: "Play All",
|
|
30
|
+
remove_item: "Remove item",
|
|
31
|
+
delete_collection: "Delete collection",
|
|
32
|
+
create_collection: "Create collection",
|
|
33
|
+
edit: "Edit",
|
|
34
|
+
edit_name: "Edit Name & Details",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Known backend action alias image assets. */
|
|
38
|
+
export const ALIAS_ASSETS: Record<string, string> = {
|
|
39
|
+
add_to_playlist: ADD_TO_PLAYLIST_ICON,
|
|
40
|
+
add_to_queue: ADD_TO_PLAYLIST_ICON,
|
|
41
|
+
add_all_to_queue: ADD_TO_PLAYLIST_ICON,
|
|
42
|
+
play_all: ADD_TO_PLAYLIST_ICON,
|
|
43
|
+
remove_item: REMOVE_ICON,
|
|
44
|
+
delete_collection: REMOVE_ICON,
|
|
45
|
+
edit: EDIT_ICON,
|
|
46
|
+
edit_name: EDIT_ICON,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Per-app overrides for the maps above. */
|
|
50
|
+
export type AliasPresentation = {
|
|
51
|
+
labels?: Record<string, string>;
|
|
52
|
+
assets?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function formatAliasLabel(
|
|
56
|
+
alias: string,
|
|
57
|
+
overrides?: AliasPresentation
|
|
58
|
+
): string {
|
|
59
|
+
const label = overrides?.labels?.[alias] ?? ALIAS_LABELS[alias];
|
|
60
|
+
|
|
61
|
+
if (label) {
|
|
62
|
+
return label;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const formatted = alias.replace(/_/g, " ");
|
|
66
|
+
|
|
67
|
+
return formatted.charAt(0).toUpperCase() + formatted.slice(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const nonEmptyString = (value: unknown): value is string =>
|
|
71
|
+
typeof value === "string" && value.length > 0;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Label the backend stated outright, if any. Distinct from
|
|
75
|
+
* {@link resolveButtonLabel} because an explicit label outranks the executor's
|
|
76
|
+
* action state, while the alias fallback does not.
|
|
77
|
+
*/
|
|
78
|
+
export function resolveExplicitLabel(
|
|
79
|
+
button: EntryAction["button"]
|
|
80
|
+
): string | undefined {
|
|
81
|
+
if (nonEmptyString(button?.title)) {
|
|
82
|
+
return button.title;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (nonEmptyString(button?.label)) {
|
|
86
|
+
return button.label;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Label to show for an entry action: explicit title/label, else the alias. */
|
|
93
|
+
export function resolveButtonLabel(
|
|
94
|
+
button: EntryAction["button"],
|
|
95
|
+
overrides?: AliasPresentation
|
|
96
|
+
): string {
|
|
97
|
+
const explicit = resolveExplicitLabel(button);
|
|
98
|
+
|
|
99
|
+
if (explicit) {
|
|
100
|
+
return explicit;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (nonEmptyString(button?.alias)) {
|
|
104
|
+
return formatAliasLabel(button.alias, overrides);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Icon to show for an entry action: explicit iconURL, else the alias default. */
|
|
111
|
+
export function resolveButtonAsset(
|
|
112
|
+
button: EntryAction["button"],
|
|
113
|
+
overrides?: AliasPresentation
|
|
114
|
+
): string | undefined {
|
|
115
|
+
if (button?.iconURL) {
|
|
116
|
+
return button.iconURL;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!button?.alias) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return overrides?.assets?.[button.alias] ?? ALIAS_ASSETS[button.alias];
|
|
124
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { createLogger } from "../logger";
|
|
3
|
+
import { ActionExecutionContext } from "../actionsExecutor/types";
|
|
4
|
+
import { RegisteredAction } from "../uiActionsRegistrator";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
resolveButtonAsset,
|
|
8
|
+
resolveButtonLabel,
|
|
9
|
+
resolveExplicitLabel,
|
|
10
|
+
} from "./aliasPresentation";
|
|
11
|
+
import { EntryAction, EntryActionDeps } from "./types";
|
|
12
|
+
|
|
13
|
+
const { log_info, log_warning, log_error } = createLogger({
|
|
14
|
+
subsystem: "EntryActions",
|
|
15
|
+
category: "EntryAction",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const ENTRY_ACTION_IDENTIFIER_PREFIX = "entry_action";
|
|
19
|
+
|
|
20
|
+
/** True for actions inflated from `entry.extensions.entry_action`. */
|
|
21
|
+
export function isEntryAction(item: RegisteredAction): boolean {
|
|
22
|
+
return item?.source === "entry";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isValidEntryAction(value: unknown): value is EntryAction {
|
|
26
|
+
if (typeof value !== "object" || value === null) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { button, actions } = value as EntryAction;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
(typeof button?.title === "string" ||
|
|
34
|
+
typeof button?.label === "string" ||
|
|
35
|
+
typeof button?.alias === "string") &&
|
|
36
|
+
Array.isArray(actions)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createEntryAction(
|
|
41
|
+
entryAction: EntryAction,
|
|
42
|
+
index: number,
|
|
43
|
+
entry: ZappEntry | ZappFeed,
|
|
44
|
+
deps: EntryActionDeps
|
|
45
|
+
): RegisteredAction {
|
|
46
|
+
const { button, actions, dismiss_on_action } = entryAction;
|
|
47
|
+
|
|
48
|
+
const identifier = `${ENTRY_ACTION_IDENTIFIER_PREFIX}_${index}`;
|
|
49
|
+
const primaryAction = actions.length > 0 ? actions[0] : null;
|
|
50
|
+
|
|
51
|
+
const actionState = primaryAction
|
|
52
|
+
? deps.actionExecutor?.getActionState?.(primaryAction.type, entry)
|
|
53
|
+
: null;
|
|
54
|
+
|
|
55
|
+
// An explicit title/label outranks the executor's action state; the
|
|
56
|
+
// alias-derived defaults only fill in when neither produced anything.
|
|
57
|
+
const label: CellActionEntryState["label"] =
|
|
58
|
+
resolveExplicitLabel(button) ||
|
|
59
|
+
actionState?.label ||
|
|
60
|
+
resolveButtonLabel(button, deps.aliasPresentation);
|
|
61
|
+
|
|
62
|
+
const asset: CellActionEntryState["asset"] =
|
|
63
|
+
button?.iconURL ||
|
|
64
|
+
actionState?.asset ||
|
|
65
|
+
resolveButtonAsset(button, deps.aliasPresentation);
|
|
66
|
+
|
|
67
|
+
const initialState = { state: 0, label, asset };
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
identifier,
|
|
71
|
+
source: "entry",
|
|
72
|
+
action: {
|
|
73
|
+
initialEntryState: () => initialState,
|
|
74
|
+
invokeAction: async (
|
|
75
|
+
invokedEntry: ZappEntry,
|
|
76
|
+
options: InvokeArgsOptions = {}
|
|
77
|
+
) => {
|
|
78
|
+
if (dismiss_on_action === true) {
|
|
79
|
+
options.dismiss?.();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
log_info(
|
|
83
|
+
`invokeAction: entry action "${identifier}" triggered for entry "${invokedEntry?.id}"`,
|
|
84
|
+
{ identifier, entryId: invokedEntry?.id, actionCount: actions.length }
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Both of these leave the user with a button that does nothing when
|
|
88
|
+
// tapped, and neither throws, so they would otherwise be invisible.
|
|
89
|
+
if (actions.length === 0) {
|
|
90
|
+
log_warning(
|
|
91
|
+
`invokeAction: entry action "${identifier}" on entry "${invokedEntry?.id}" declares no actions - the tap does nothing`,
|
|
92
|
+
{ identifier, entryId: invokedEntry?.id }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof deps.actionExecutor?.handleActions !== "function") {
|
|
97
|
+
log_warning(
|
|
98
|
+
`invokeAction: no action executor available for entry action "${identifier}" - the tap does nothing`,
|
|
99
|
+
{ identifier, entryId: invokedEntry?.id }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await deps.actionExecutor?.handleActions(actions, {
|
|
105
|
+
entry: invokedEntry,
|
|
106
|
+
entryContext: invokedEntry,
|
|
107
|
+
...deps.actionContext,
|
|
108
|
+
...(options.component ? { component: options.component } : {}),
|
|
109
|
+
} as ActionExecutionContext);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
log_error(
|
|
112
|
+
`invokeAction: entry action "${identifier}" failed for entry "${invokedEntry?.id}"`,
|
|
113
|
+
{
|
|
114
|
+
identifier,
|
|
115
|
+
entryId: invokedEntry?.id,
|
|
116
|
+
// Types only - the action payloads are backend supplied and may
|
|
117
|
+
// carry user data.
|
|
118
|
+
actionTypes: actions.map((action) => action?.type),
|
|
119
|
+
error,
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Builds the list of actions declared on an entry via
|
|
130
|
+
* `entry.extensions.entry_action`.
|
|
131
|
+
*/
|
|
132
|
+
export function buildEntryActions(
|
|
133
|
+
entry: ZappEntry | ZappFeed,
|
|
134
|
+
deps: EntryActionDeps
|
|
135
|
+
): RegisteredAction[] {
|
|
136
|
+
const entryId = (entry as ZappEntry)?.id;
|
|
137
|
+
const raw = (entry as any)?.extensions?.entry_action;
|
|
138
|
+
|
|
139
|
+
// Most entries simply declare no actions. This provider is resolved for
|
|
140
|
+
// every entry on every render, so saying so would drown everything else.
|
|
141
|
+
if (raw === undefined || raw === null) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!Array.isArray(raw)) {
|
|
146
|
+
log_warning(
|
|
147
|
+
`buildEntryActions: entry "${entryId}" has extensions.entry_action of type ${typeof raw} instead of an array - no entry actions will be shown`,
|
|
148
|
+
{ entryId, receivedType: typeof raw }
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const valid = raw.filter(isValidEntryAction);
|
|
155
|
+
const invalid = raw.length - valid.length;
|
|
156
|
+
|
|
157
|
+
if (invalid > 0) {
|
|
158
|
+
log_warning(
|
|
159
|
+
`buildEntryActions: ${invalid} invalid entry action(s) skipped for entry "${entryId}"`,
|
|
160
|
+
{ entryId, total: raw.length, invalid }
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return valid.map((entryAction, index) =>
|
|
165
|
+
createEntryAction(entryAction, index, entry, deps)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { buildEntryActions, isEntryAction } from "./buildEntryActions";
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
ALIAS_ASSETS,
|
|
5
|
+
ALIAS_LABELS,
|
|
6
|
+
resolveButtonAsset,
|
|
7
|
+
resolveButtonLabel,
|
|
8
|
+
resolveExplicitLabel,
|
|
9
|
+
} from "./aliasPresentation";
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
EntryAction,
|
|
13
|
+
EntryActionDeps,
|
|
14
|
+
EntryActionExecutionContext,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
export type { AliasPresentation } from "./aliasPresentation";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import type { ActionExecutorContextType } from "../actionsExecutor/ActionExecutorContext";
|
|
3
|
+
import type { AliasPresentation } from "./aliasPresentation";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A single action declared by the backend on an entry, under
|
|
7
|
+
* `entry.extensions.entry_action`.
|
|
8
|
+
*/
|
|
9
|
+
export type EntryAction = {
|
|
10
|
+
button: {
|
|
11
|
+
title?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
alias?: string;
|
|
14
|
+
iconURL?: string;
|
|
15
|
+
};
|
|
16
|
+
actions: ZappActionType[];
|
|
17
|
+
dismiss_on_action?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Everything `buildEntryActions` needs from the surrounding React tree in order
|
|
22
|
+
* to execute an entry action. Supplied lazily so the registered provider always
|
|
23
|
+
* reads the freshest screen context.
|
|
24
|
+
*/
|
|
25
|
+
export type EntryActionDeps = {
|
|
26
|
+
actionExecutor: ActionExecutorContextType;
|
|
27
|
+
actionContext: EntryActionExecutionContext;
|
|
28
|
+
/** App-supplied labels/icons for backend aliases; defaults are used without it. */
|
|
29
|
+
aliasPresentation?: AliasPresentation;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The screen the action is executed against, spread into the execution context. */
|
|
33
|
+
export type EntryActionExecutionContext = {
|
|
34
|
+
screenData?: unknown;
|
|
35
|
+
screenState?: unknown;
|
|
36
|
+
screenRoute?: string;
|
|
37
|
+
screenStateStore?: unknown;
|
|
38
|
+
screenEntry?: unknown;
|
|
39
|
+
};
|
|
@@ -135,7 +135,8 @@ function generateFieldsFromDefaults(label, defaults, fields) {
|
|
|
135
135
|
function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
136
136
|
label,
|
|
137
137
|
defaults,
|
|
138
|
-
fields
|
|
138
|
+
fields,
|
|
139
|
+
{ withStyle = false } = {}
|
|
139
140
|
) {
|
|
140
141
|
const keyPrefix = toSnakeCase(label);
|
|
141
142
|
|
|
@@ -151,7 +152,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
151
152
|
const generatedField = {
|
|
152
153
|
...fieldProps,
|
|
153
154
|
label: capitalizeFirstLetter(field.suffix),
|
|
154
|
-
key:
|
|
155
|
+
key: withStyle
|
|
156
|
+
? `${keyPrefix}_style_${toSnakeCase(field.suffix)}`
|
|
157
|
+
: `${keyPrefix}_${toSnakeCase(field.suffix)}`,
|
|
155
158
|
initial_value: R.when(R.is(Array), R.head)(initialValue),
|
|
156
159
|
};
|
|
157
160
|
|
|
@@ -164,7 +167,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
164
167
|
const section = condition.section ? `${condition.section}/` : "";
|
|
165
168
|
|
|
166
169
|
return {
|
|
167
|
-
key:
|
|
170
|
+
key: withStyle
|
|
171
|
+
? `${section}${keyPrefix}_style_${toSnakeCase(condition.key)}`
|
|
172
|
+
: `${section}${keyPrefix}_${toSnakeCase(condition.key)}`,
|
|
168
173
|
condition_value: condition.value,
|
|
169
174
|
};
|
|
170
175
|
});
|
|
@@ -204,6 +204,20 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
204
204
|
label_tooltip: "Label for close button accessibility",
|
|
205
205
|
type: "text_input",
|
|
206
206
|
},
|
|
207
|
+
{
|
|
208
|
+
key: "accessibility_overflow_label",
|
|
209
|
+
label: "Accessibility overflow label",
|
|
210
|
+
initial_value: "More actions",
|
|
211
|
+
label_tooltip: "Label for the overflow (…) button accessibility",
|
|
212
|
+
type: "text_input",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
key: "accessibility_overflow_hint",
|
|
216
|
+
label: "Accessibility overflow hint",
|
|
217
|
+
initial_value: "Opens the remaining player actions",
|
|
218
|
+
label_tooltip: "Hint for the overflow (…) button accessibility",
|
|
219
|
+
type: "text_input",
|
|
220
|
+
},
|
|
207
221
|
{
|
|
208
222
|
key: "accessibility_close_hint",
|
|
209
223
|
label: "Accessibility close hint",
|
|
@@ -791,7 +805,7 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
791
805
|
label: "Player action buttons",
|
|
792
806
|
initial_value: null,
|
|
793
807
|
label_tooltip:
|
|
794
|
-
"
|
|
808
|
+
"Comma-separated action identifiers. The entry_actions token expands from the playing entry's extensions.entry_action. When more than 2 actions resolve, the video and fullscreen audio players show Overflow (…) plus one companion - the first action that did not come from the entry, otherwise the first one - and the Overflow sheet lists every resolved action. A repeated identifier is counted once. No extra plugin is required.",
|
|
795
809
|
type: "text_input",
|
|
796
810
|
},
|
|
797
811
|
{
|
|
@@ -1091,6 +1105,13 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
1091
1105
|
type: "uploader",
|
|
1092
1106
|
label_tooltip: "Override default close badge / icon",
|
|
1093
1107
|
},
|
|
1108
|
+
{
|
|
1109
|
+
key: "overflow",
|
|
1110
|
+
label: "Overflow badge",
|
|
1111
|
+
type: "uploader",
|
|
1112
|
+
label_tooltip:
|
|
1113
|
+
"Override default overflow (…) badge / icon, shown when more action buttons resolve than fit on the player overlay",
|
|
1114
|
+
},
|
|
1094
1115
|
{
|
|
1095
1116
|
key: "lock",
|
|
1096
1117
|
label: "Lock player badge",
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { dismissModal, modalStore, openBottomSheetModal } from "./store";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getMenuItemActions,
|
|
4
|
+
isPresentSubMenuAction,
|
|
5
|
+
Menu,
|
|
6
|
+
MenuItem,
|
|
7
|
+
PresentSubMenuAction,
|
|
8
|
+
} from "./types";
|
|
3
9
|
import { ContentViewModel } from "./ContentViewModel";
|
|
4
10
|
|
|
5
11
|
export type { Menu, MenuItem };
|
|
6
12
|
|
|
7
|
-
export { isPresentSubMenuAction };
|
|
13
|
+
export { isPresentSubMenuAction, getMenuItemActions };
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Converts a Menu model into the props expected by BottomSheetModalContent.
|
|
@@ -136,15 +142,21 @@ class ModalOrchestrator {
|
|
|
136
142
|
private _buildOnPress(
|
|
137
143
|
onItemPress?: (item: MenuItem) => void | Promise<void>
|
|
138
144
|
): (item: MenuItem) => void | Promise<void> {
|
|
139
|
-
return (item: MenuItem) => {
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
this.open(item.action.menu, onItemPress);
|
|
143
|
-
|
|
144
|
-
return;
|
|
145
|
+
return async (item: MenuItem) => {
|
|
146
|
+
if (onItemPress) {
|
|
147
|
+
await onItemPress(item);
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
|
|
150
|
+
const actions = getMenuItemActions(item);
|
|
151
|
+
|
|
152
|
+
const subMenuAction = actions.find(isPresentSubMenuAction) as
|
|
153
|
+
| PresentSubMenuAction
|
|
154
|
+
| undefined;
|
|
155
|
+
|
|
156
|
+
if (subMenuAction) {
|
|
157
|
+
// Navigate deeper into the sub-menu
|
|
158
|
+
this.open(subMenuAction.menu, onItemPress);
|
|
159
|
+
}
|
|
148
160
|
};
|
|
149
161
|
}
|
|
150
162
|
|
|
@@ -123,7 +123,14 @@ export class RemoteEditableCollection implements EditableCollection {
|
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
125
|
for (const action of addEvents) {
|
|
126
|
-
|
|
126
|
+
if (this.content.context) {
|
|
127
|
+
await actionExecutor.handleAction(
|
|
128
|
+
action as any,
|
|
129
|
+
this.content.context
|
|
130
|
+
);
|
|
131
|
+
} else {
|
|
132
|
+
await actionExecutor.handleAction(action as any);
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
} catch (e) {
|
|
129
136
|
actionFailed = true;
|
|
@@ -219,6 +226,7 @@ export class RemoteEditableCollection implements EditableCollection {
|
|
|
219
226
|
await actionExecutor.handleAction(
|
|
220
227
|
actionToExecute as any,
|
|
221
228
|
{
|
|
229
|
+
...this.content.context,
|
|
222
230
|
entry: item as any,
|
|
223
231
|
} as any
|
|
224
232
|
);
|
|
@@ -34,16 +34,26 @@ const itemPlain: MenuItem = { id: "2", title: "B" };
|
|
|
34
34
|
function makeCollection(
|
|
35
35
|
items: MenuItem[],
|
|
36
36
|
refetch = jest.fn().mockResolvedValue(undefined),
|
|
37
|
-
operations = ["remove", "reorder"]
|
|
37
|
+
operations = ["remove", "reorder"],
|
|
38
|
+
context?: Record<string, unknown>
|
|
38
39
|
) {
|
|
39
40
|
const content = {
|
|
40
41
|
items,
|
|
42
|
+
context,
|
|
41
43
|
dynamicCollection: { operations, postUrl: "https://x/cloud-events" },
|
|
42
44
|
} as unknown as Content;
|
|
43
45
|
|
|
44
46
|
return { col: new RemoteEditableCollection(content, refetch), refetch };
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
const openingContext = {
|
|
50
|
+
component: {
|
|
51
|
+
id: "list-1",
|
|
52
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
53
|
+
},
|
|
54
|
+
screenData: { id: "playlist-screen" },
|
|
55
|
+
};
|
|
56
|
+
|
|
47
57
|
describe("RemoteEditableCollection", () => {
|
|
48
58
|
beforeEach(() => jest.clearAllMocks());
|
|
49
59
|
|
|
@@ -118,6 +128,24 @@ describe("RemoteEditableCollection", () => {
|
|
|
118
128
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
119
129
|
expect(currentItems(col)).toEqual([itemWithRemove]);
|
|
120
130
|
});
|
|
131
|
+
|
|
132
|
+
it("forwards stored sheet context plus the removed item as entry", async () => {
|
|
133
|
+
handleAction.mockResolvedValue("success");
|
|
134
|
+
|
|
135
|
+
const { col } = makeCollection(
|
|
136
|
+
[itemWithRemove, itemPlain],
|
|
137
|
+
jest.fn().mockResolvedValue(undefined),
|
|
138
|
+
["remove", "reorder"],
|
|
139
|
+
openingContext
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
await col.remove(0);
|
|
143
|
+
|
|
144
|
+
expect(handleAction).toHaveBeenCalledWith(removeAction, {
|
|
145
|
+
...openingContext,
|
|
146
|
+
entry: itemWithRemove,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
121
149
|
});
|
|
122
150
|
|
|
123
151
|
describe("move", () => {
|
|
@@ -164,6 +192,35 @@ describe("RemoteEditableCollection", () => {
|
|
|
164
192
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
165
193
|
});
|
|
166
194
|
|
|
195
|
+
it("forwards stored sheet context plus the moved item as entry", async () => {
|
|
196
|
+
handleAction.mockResolvedValue("success");
|
|
197
|
+
|
|
198
|
+
const itemA: MenuItem = {
|
|
199
|
+
id: "2",
|
|
200
|
+
title: "B",
|
|
201
|
+
entryActions: [
|
|
202
|
+
{ button: { alias: "reorder_item" }, actions: [removeAction] },
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const { col } = makeCollection(
|
|
207
|
+
[itemA],
|
|
208
|
+
jest.fn().mockResolvedValue(undefined),
|
|
209
|
+
["remove", "reorder"],
|
|
210
|
+
openingContext
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
await col.move(["2"]);
|
|
214
|
+
|
|
215
|
+
expect(handleAction).toHaveBeenCalledWith(
|
|
216
|
+
expect.objectContaining({ type: "sendCloudEvent" }),
|
|
217
|
+
{
|
|
218
|
+
...openingContext,
|
|
219
|
+
entry: itemA,
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
167
224
|
it("rolls back on failure", async () => {
|
|
168
225
|
handleAction.mockRejectedValue(new Error("nope"));
|
|
169
226
|
|
|
@@ -322,5 +379,37 @@ describe("RemoteEditableCollection", () => {
|
|
|
322
379
|
expect(handleAction).toHaveBeenCalledWith(addAction);
|
|
323
380
|
expect(refetch).toHaveBeenCalledTimes(1);
|
|
324
381
|
});
|
|
382
|
+
|
|
383
|
+
it("forwards stored sheet context into events.add actions", async () => {
|
|
384
|
+
handleAction.mockResolvedValue("success");
|
|
385
|
+
|
|
386
|
+
const addAction = {
|
|
387
|
+
type: "showTextInput",
|
|
388
|
+
options: {
|
|
389
|
+
headerTitle: "Create Playlist",
|
|
390
|
+
buttonLabel: "Create",
|
|
391
|
+
actions: [{ type: "sendCloudEvent" }],
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const content = {
|
|
396
|
+
items: [],
|
|
397
|
+
context: openingContext,
|
|
398
|
+
dynamicCollection: {
|
|
399
|
+
operations: ["add"],
|
|
400
|
+
postUrl: "https://x/cloud-events",
|
|
401
|
+
events: {
|
|
402
|
+
add: [addAction],
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
} as any;
|
|
406
|
+
|
|
407
|
+
const refetch = jest.fn().mockResolvedValue(undefined);
|
|
408
|
+
const col = new RemoteEditableCollection(content, refetch);
|
|
409
|
+
|
|
410
|
+
await col.add();
|
|
411
|
+
|
|
412
|
+
expect(handleAction).toHaveBeenCalledWith(addAction, openingContext);
|
|
413
|
+
});
|
|
325
414
|
});
|
|
326
415
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { modalStore } from "../";
|
|
1
|
+
import { modalStore, getMenuItemActions } from "../";
|
|
2
2
|
|
|
3
3
|
describe("Modal State", () => {
|
|
4
4
|
it("should have initial state", () => {
|
|
@@ -48,4 +48,33 @@ describe("Modal State", () => {
|
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
describe("getMenuItemActions", () => {
|
|
53
|
+
it("returns actions array when actions is provided", () => {
|
|
54
|
+
const actions = [{ type: "action1" }, { type: "action2" }];
|
|
55
|
+
const item = { id: "1", title: "Item", actions };
|
|
56
|
+
|
|
57
|
+
expect(getMenuItemActions(item)).toEqual(actions);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("returns [action] when single action is provided", () => {
|
|
61
|
+
const action = { type: "action1" };
|
|
62
|
+
const item = { id: "1", title: "Item", action };
|
|
63
|
+
|
|
64
|
+
expect(getMenuItemActions(item)).toEqual([action]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("returns action when action is passed as an array", () => {
|
|
68
|
+
const actions = [{ type: "action1" }];
|
|
69
|
+
const item = { id: "1", title: "Item", action: actions as any };
|
|
70
|
+
|
|
71
|
+
expect(getMenuItemActions(item)).toEqual(actions);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("returns empty array when no action or actions are provided", () => {
|
|
75
|
+
expect(getMenuItemActions({ id: "1", title: "Item" })).toEqual([]);
|
|
76
|
+
expect(getMenuItemActions(null)).toEqual([]);
|
|
77
|
+
expect(getMenuItemActions(undefined)).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
51
80
|
});
|
package/modalState/index.ts
CHANGED
|
@@ -25,6 +25,11 @@ export type {
|
|
|
25
25
|
SelectionBehavior,
|
|
26
26
|
} from "./types";
|
|
27
27
|
|
|
28
|
-
export {
|
|
28
|
+
export {
|
|
29
|
+
isPresentSubMenuAction,
|
|
30
|
+
getMenuItemActions,
|
|
31
|
+
OPERATIONS,
|
|
32
|
+
hasOperation,
|
|
33
|
+
} from "./types";
|
|
29
34
|
|
|
30
35
|
export { useBottomSheetContent } from "./useBottomSheetContent";
|