@applicaster/zapp-react-native-utils 15.1.14 → 15.1.15-alpha.4236143002
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 +70 -16
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +212 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/index.ts +4 -0
- package/actionsExecutor/actions/openBottomSheet.ts +329 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/consts.ts +23 -0
- package/actionsExecutor/types.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +5 -2
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +55 -2
- 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 +51 -20
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/index.ts +79 -0
- 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 +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/defaultManifestConfigurations/player.js +22 -1
- 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 +235 -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 +415 -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 +160 -0
- package/modalState/useBottomSheetContent.ts +104 -0
- 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/usePluginConfiguration.ts +6 -3
- 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
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -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
|
+
};
|
|
@@ -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",
|
|
@@ -747,7 +761,7 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
747
761
|
label: "Player action buttons",
|
|
748
762
|
initial_value: null,
|
|
749
763
|
label_tooltip:
|
|
750
|
-
"
|
|
764
|
+
"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.",
|
|
751
765
|
type: "text_input",
|
|
752
766
|
},
|
|
753
767
|
{
|
|
@@ -1047,6 +1061,13 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
1047
1061
|
type: "uploader",
|
|
1048
1062
|
label_tooltip: "Override default close badge / icon",
|
|
1049
1063
|
},
|
|
1064
|
+
{
|
|
1065
|
+
key: "overflow",
|
|
1066
|
+
label: "Overflow badge",
|
|
1067
|
+
type: "uploader",
|
|
1068
|
+
label_tooltip:
|
|
1069
|
+
"Override default overflow (…) badge / icon, shown when more action buttons resolve than fit on the player overlay",
|
|
1070
|
+
},
|
|
1050
1071
|
{
|
|
1051
1072
|
key: "lock",
|
|
1052
1073
|
label: "Lock player badge",
|
package/manifestUtils/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
const { buttonKey } = require("./buttons");
|
|
24
24
|
const { tvBadges } = require("./tvBadges");
|
|
25
25
|
const { mobileProgressBar, tvProgressBar } = require("./progressBar");
|
|
26
|
+
const { getModalBlockStyles, getModalLocalizations } = require("./modalBlocks");
|
|
26
27
|
|
|
27
28
|
const {
|
|
28
29
|
secondaryImage,
|
|
@@ -52,4 +53,6 @@ module.exports = {
|
|
|
52
53
|
getUpdatedSecondaryImageKeys,
|
|
53
54
|
DEFAULT_GRADIENT_IMAGE,
|
|
54
55
|
compact,
|
|
56
|
+
getModalBlockStyles,
|
|
57
|
+
getModalLocalizations,
|
|
55
58
|
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
function getModalBlockStyles({ prefix }) {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
group: true,
|
|
5
|
+
label: "Header Styles",
|
|
6
|
+
folded: true,
|
|
7
|
+
fields: [
|
|
8
|
+
{
|
|
9
|
+
type: "color_picker_rgba",
|
|
10
|
+
key: `${prefix}_style_header_container_default_backgroundColor`,
|
|
11
|
+
label: "Header Background Color",
|
|
12
|
+
initial_value: "rgba(30,30,30,1)",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: "color_picker_rgba",
|
|
16
|
+
key: `${prefix}_style_header_container_default_borderBottomColor`,
|
|
17
|
+
label: "Header Border Bottom Color",
|
|
18
|
+
initial_value: "transparent",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: "number_input",
|
|
22
|
+
key: `${prefix}_style_header_container_default_borderBottomSize`,
|
|
23
|
+
label: "Header Border Bottom Size",
|
|
24
|
+
initial_value: 0,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "color_picker_rgba",
|
|
28
|
+
key: `${prefix}_style_header_title_default_fontColor`,
|
|
29
|
+
label: "Header Title Color",
|
|
30
|
+
initial_value: "#EFEFEF",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "number_input",
|
|
34
|
+
key: `${prefix}_style_header_title_default_fontSize`,
|
|
35
|
+
label: "Header Title Font Size",
|
|
36
|
+
initial_value: 18,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "number_input",
|
|
40
|
+
key: `${prefix}_style_header_title_default_lineHeight`,
|
|
41
|
+
label: "Header Title Line Height",
|
|
42
|
+
initial_value: 32,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "color_picker_rgba",
|
|
46
|
+
key: `${prefix}_style_header_close_button_default_backgroundColor`,
|
|
47
|
+
label: "Close Button Background Color",
|
|
48
|
+
initial_value: "transparent",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: "color_picker_rgba",
|
|
52
|
+
key: `${prefix}_style_header_close_button_hover_backgroundColor`,
|
|
53
|
+
label: "Close Button Hover Background Color",
|
|
54
|
+
initial_value: "rgba(46,46,46,1)",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "uploader",
|
|
58
|
+
key: `${prefix}_style_header_close_button_asset`,
|
|
59
|
+
label: "Close Button Icon Asset",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "color_picker_rgba",
|
|
63
|
+
key: `${prefix}_style_header_action_buttons_default_backgroundColor`,
|
|
64
|
+
label: "Header Action Button Background Color",
|
|
65
|
+
initial_value: "rgba(46,46,46,1)",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "color_picker_rgba",
|
|
69
|
+
key: `${prefix}_style_header_action_buttons_hover_backgroundColor`,
|
|
70
|
+
label: "Header Action Button Hover Color",
|
|
71
|
+
initial_value: "rgba(62,62,62,1)",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: "color_picker_rgba",
|
|
75
|
+
key: `${prefix}_style_header_action_buttons_default_fontColor`,
|
|
76
|
+
label: "Header Action Button Title Color",
|
|
77
|
+
initial_value: "#EFEFEF",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "number_input",
|
|
81
|
+
key: `${prefix}_style_header_action_buttons_default_fontSize`,
|
|
82
|
+
label: "Header Action Button Font Size",
|
|
83
|
+
initial_value: 14,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "number_input",
|
|
87
|
+
key: `${prefix}_style_header_action_buttons_default_borderRadius`,
|
|
88
|
+
label: "Header Action Button Radius",
|
|
89
|
+
initial_value: 16,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
group: true,
|
|
95
|
+
label: "Item Styles",
|
|
96
|
+
folded: true,
|
|
97
|
+
fields: [
|
|
98
|
+
{
|
|
99
|
+
type: "color_picker_rgba",
|
|
100
|
+
key: `${prefix}_style_item_background_default_backgroundColor`,
|
|
101
|
+
label: "Item Background Color",
|
|
102
|
+
initial_value: "transparent",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: "color_picker_rgba",
|
|
106
|
+
key: `${prefix}_style_item_background_focus_backgroundColor`,
|
|
107
|
+
label: "Item Focus/Touch Color",
|
|
108
|
+
initial_value: "rgba(62,62,62,1)",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: "number_input",
|
|
112
|
+
key: `${prefix}_style_item_background_default_borderRadius`,
|
|
113
|
+
label: "Item Corner Radius",
|
|
114
|
+
initial_value: 12,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: "number_input",
|
|
118
|
+
key: `${prefix}_style_item_background_default_paddingTop`,
|
|
119
|
+
label: "Item Padding Top",
|
|
120
|
+
initial_value: 8,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "number_input",
|
|
124
|
+
key: `${prefix}_style_item_background_default_paddingBottom`,
|
|
125
|
+
label: "Item Padding Bottom",
|
|
126
|
+
initial_value: 8,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "number_input",
|
|
130
|
+
key: `${prefix}_style_item_background_default_paddingLeft`,
|
|
131
|
+
label: "Item Padding Left",
|
|
132
|
+
initial_value: 10,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: "number_input",
|
|
136
|
+
key: `${prefix}_style_item_background_default_paddingRight`,
|
|
137
|
+
label: "Item Padding Right",
|
|
138
|
+
initial_value: 10,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: "number_input",
|
|
142
|
+
key: `${prefix}_style_item_image_default_width`,
|
|
143
|
+
label: "Item Image Width",
|
|
144
|
+
initial_value: 48,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: "number_input",
|
|
148
|
+
key: `${prefix}_style_item_image_default_height`,
|
|
149
|
+
label: "Item Image Height",
|
|
150
|
+
initial_value: 48,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: "number_input",
|
|
154
|
+
key: `${prefix}_style_item_image_default_borderRadius`,
|
|
155
|
+
label: "Item Image Radius",
|
|
156
|
+
initial_value: 6,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: "color_picker_rgba",
|
|
160
|
+
key: `${prefix}_style_item_text_label_1_default_fontColor`,
|
|
161
|
+
label: "Item Title Color",
|
|
162
|
+
initial_value: "#FFFFFF",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: "number_input",
|
|
166
|
+
key: `${prefix}_style_item_text_label_1_default_fontSize`,
|
|
167
|
+
label: "Item Title Font Size",
|
|
168
|
+
initial_value: 15,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: "color_picker_rgba",
|
|
172
|
+
key: `${prefix}_style_item_text_label_2_default_fontColor`,
|
|
173
|
+
label: "Item Subtitle Color",
|
|
174
|
+
initial_value: "#999999",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: "number_input",
|
|
178
|
+
key: `${prefix}_style_item_text_label_2_default_fontSize`,
|
|
179
|
+
label: "Item Subtitle Font Size",
|
|
180
|
+
initial_value: 13,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
group: true,
|
|
186
|
+
label: "Action Styles",
|
|
187
|
+
folded: true,
|
|
188
|
+
fields: [
|
|
189
|
+
{
|
|
190
|
+
type: "color_picker_rgba",
|
|
191
|
+
key: `${prefix}_style_action_background_default_backgroundColor`,
|
|
192
|
+
label: "Action Background Color",
|
|
193
|
+
initial_value: "transparent",
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
type: "color_picker_rgba",
|
|
197
|
+
key: `${prefix}_style_action_background_hover_backgroundColor`,
|
|
198
|
+
label: "Action Hover/Touch Color",
|
|
199
|
+
initial_value: "rgba(46,46,46,1)",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
type: "number_input",
|
|
203
|
+
key: `${prefix}_style_action_background_default_borderRadius`,
|
|
204
|
+
label: "Action Corner Radius",
|
|
205
|
+
initial_value: 12,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: "number_input",
|
|
209
|
+
key: `${prefix}_style_action_background_default_paddingTop`,
|
|
210
|
+
label: "Action Padding Top",
|
|
211
|
+
initial_value: 14,
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: "number_input",
|
|
215
|
+
key: `${prefix}_style_action_background_default_paddingBottom`,
|
|
216
|
+
label: "Action Padding Bottom",
|
|
217
|
+
initial_value: 14,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
type: "color_picker_rgba",
|
|
221
|
+
key: `${prefix}_style_action_title_default_fontColor`,
|
|
222
|
+
label: "Action Title Color",
|
|
223
|
+
initial_value: "#EFEFEF",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: "number_input",
|
|
227
|
+
key: `${prefix}_style_action_title_default_fontSize`,
|
|
228
|
+
label: "Action Title Font Size",
|
|
229
|
+
initial_value: 14,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: "uploader",
|
|
233
|
+
key: `${prefix}_style_action_trailing_icon_chevron_asset`,
|
|
234
|
+
label: "Action Chevron Asset",
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
group: true,
|
|
240
|
+
label: "Button Styles",
|
|
241
|
+
folded: true,
|
|
242
|
+
fields: [
|
|
243
|
+
{
|
|
244
|
+
type: "color_picker_rgba",
|
|
245
|
+
key: `${prefix}_style_button_background_default_backgroundColor`,
|
|
246
|
+
label: "Button Background Color",
|
|
247
|
+
initial_value: "#FFFFFF",
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: "color_picker_rgba",
|
|
251
|
+
key: `${prefix}_style_button_background_focus_backgroundColor`,
|
|
252
|
+
label: "Button Focus Color",
|
|
253
|
+
initial_value: "#E0E0E0",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
type: "color_picker_rgba",
|
|
257
|
+
key: `${prefix}_style_button_background_inactive_backgroundColor`,
|
|
258
|
+
label: "Button Inactive Color",
|
|
259
|
+
initial_value: "#999999",
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
type: "number_input",
|
|
263
|
+
key: `${prefix}_style_button_background_default_borderRadius`,
|
|
264
|
+
label: "Button Corner Radius",
|
|
265
|
+
initial_value: 12,
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
type: "color_picker_rgba",
|
|
269
|
+
key: `${prefix}_style_button_title_default_fontColor`,
|
|
270
|
+
label: "Button Title Color",
|
|
271
|
+
initial_value: "#000000",
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
type: "number_input",
|
|
275
|
+
key: `${prefix}_style_button_title_default_fontSize`,
|
|
276
|
+
label: "Button Title Font Size",
|
|
277
|
+
initial_value: 15,
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
},
|
|
281
|
+
];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getModalLocalizations({ prefix }) {
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
type: "text_input",
|
|
288
|
+
label: "Queue Header Title",
|
|
289
|
+
key: `${prefix}_header_title`,
|
|
290
|
+
initial_value: "Queue",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "text_input",
|
|
294
|
+
label: "Go To Queue Action Label",
|
|
295
|
+
key: `${prefix}_label_go_to_queue`,
|
|
296
|
+
initial_value: "Go To Queue",
|
|
297
|
+
},
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
module.exports = {
|
|
302
|
+
getModalBlockStyles,
|
|
303
|
+
getModalLocalizations,
|
|
304
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
+
import {
|
|
3
|
+
Content,
|
|
4
|
+
MenuItem,
|
|
5
|
+
SelectionBehavior,
|
|
6
|
+
DynamicCollectionOptions,
|
|
7
|
+
} from "./types";
|
|
8
|
+
import { loadItemsFromSource } from "../actionsExecutor/actions/openBottomSheet";
|
|
9
|
+
import { resolveEditableCollection } from "./EditableCollectionRegistry";
|
|
10
|
+
import { EditableCollection } from "./EditableCollection";
|
|
11
|
+
|
|
12
|
+
export interface ContentState {
|
|
13
|
+
items: MenuItem[];
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error?: Error | string;
|
|
16
|
+
role?: string;
|
|
17
|
+
behavior?: SelectionBehavior;
|
|
18
|
+
dynamicCollection?: DynamicCollectionOptions;
|
|
19
|
+
themePluginId?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ContentViewModel {
|
|
23
|
+
private state$: BehaviorSubject<ContentState>;
|
|
24
|
+
readonly itemsUrl?: string;
|
|
25
|
+
public editableCollection: EditableCollection | null = null;
|
|
26
|
+
private content: Content;
|
|
27
|
+
|
|
28
|
+
constructor(content: Content) {
|
|
29
|
+
this.content = content;
|
|
30
|
+
this.itemsUrl = content.itemsUrl;
|
|
31
|
+
|
|
32
|
+
this.state$ = new BehaviorSubject<ContentState>({
|
|
33
|
+
items: content.items || [],
|
|
34
|
+
isLoading: false,
|
|
35
|
+
role: content.role,
|
|
36
|
+
behavior: content.behavior,
|
|
37
|
+
dynamicCollection: content.dynamicCollection,
|
|
38
|
+
themePluginId: content.themePluginId,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this.initEditableCollection(content);
|
|
42
|
+
|
|
43
|
+
if (this.itemsUrl && this.state$.value.items.length === 0) {
|
|
44
|
+
this.refetch();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private initEditableCollection(content: Content) {
|
|
49
|
+
this.editableCollection = resolveEditableCollection(content, this.refetch);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getState = (): ContentState => this.state$.value;
|
|
53
|
+
|
|
54
|
+
get stateObservable(): Observable<ContentState> {
|
|
55
|
+
return this.state$.asObservable();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
subscribe = (listener: (state: ContentState) => void) => {
|
|
59
|
+
const subscription = this.state$.subscribe(listener);
|
|
60
|
+
|
|
61
|
+
return () => subscription.unsubscribe();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
private updateState(partialState: Partial<ContentState>) {
|
|
65
|
+
this.state$.next({ ...this.state$.value, ...partialState });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
refetch = async () => {
|
|
69
|
+
if (!this.itemsUrl) return;
|
|
70
|
+
|
|
71
|
+
this.updateState({ isLoading: true, error: undefined });
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const separator = this.itemsUrl.includes("?") ? "&" : "?";
|
|
75
|
+
const cacheBustedUrl = `${this.itemsUrl}${separator}_t=${Date.now()}`;
|
|
76
|
+
|
|
77
|
+
const { items, role, behavior, dynamicCollection } =
|
|
78
|
+
await loadItemsFromSource(cacheBustedUrl);
|
|
79
|
+
|
|
80
|
+
this.content = {
|
|
81
|
+
...this.content,
|
|
82
|
+
items,
|
|
83
|
+
role,
|
|
84
|
+
behavior,
|
|
85
|
+
dynamicCollection,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
this.updateState({
|
|
89
|
+
items,
|
|
90
|
+
role,
|
|
91
|
+
behavior,
|
|
92
|
+
dynamicCollection,
|
|
93
|
+
isLoading: false,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (this.editableCollection) {
|
|
97
|
+
// Reuse the existing collection instance. Pushing the freshly loaded
|
|
98
|
+
// server items replaces any optimistic local state with the
|
|
99
|
+
// authoritative result (and rolls forward a successful mutation).
|
|
100
|
+
this.editableCollection.sync?.(items);
|
|
101
|
+
} else {
|
|
102
|
+
// The collection may only become resolvable once options arrive from
|
|
103
|
+
// the feed (e.g. inline content had none). Create it lazily here.
|
|
104
|
+
this.initEditableCollection(this.content);
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
this.updateState({
|
|
108
|
+
error: err?.message || "Failed to load",
|
|
109
|
+
isLoading: false,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|