@pushwoosh/websdk-common 6.21.0 → 6.22.0
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/package.json +1 -1
- package/web-popups/WebPopupInline.d.ts +1 -1
- package/web-popups/WebPopupInline.js +2 -0
- package/web-popups/WebPopupReader.d.ts +2 -2
- package/web-popups/WebPopupReader.js +56 -22
- package/web-popups/constants.d.ts +20 -0
- package/web-popups/constants.js +20 -0
- package/web-popups/form-slots/ConsentSlotView/ConsentSlotView.d.ts +3 -0
- package/web-popups/form-slots/ConsentSlotView/ConsentSlotView.js +42 -0
- package/web-popups/form-slots/ConsentSlotView/index.d.ts +2 -0
- package/web-popups/form-slots/ConsentSlotView/index.js +1 -0
- package/web-popups/form-slots/ConsentSlotView/styles.d.ts +6 -0
- package/web-popups/form-slots/ConsentSlotView/styles.js +19 -0
- package/web-popups/form-slots/ConsentSlotView/types.d.ts +5 -0
- package/web-popups/form-slots/ConsentSlotView/types.js +1 -0
- package/web-popups/form-slots/EmailInputSlotView/EmailInputSlotView.d.ts +3 -0
- package/web-popups/form-slots/EmailInputSlotView/EmailInputSlotView.js +16 -0
- package/web-popups/form-slots/EmailInputSlotView/index.d.ts +2 -0
- package/web-popups/form-slots/EmailInputSlotView/index.js +1 -0
- package/web-popups/form-slots/EmailInputSlotView/types.d.ts +5 -0
- package/web-popups/form-slots/EmailInputSlotView/types.js +1 -0
- package/web-popups/form-slots/SubmitSlotView/SubmitSlotView.d.ts +3 -0
- package/web-popups/form-slots/SubmitSlotView/SubmitSlotView.js +30 -0
- package/web-popups/form-slots/SubmitSlotView/index.d.ts +2 -0
- package/web-popups/form-slots/SubmitSlotView/index.js +1 -0
- package/web-popups/form-slots/SubmitSlotView/styles.d.ts +4 -0
- package/web-popups/form-slots/SubmitSlotView/styles.js +13 -0
- package/web-popups/form-slots/SubmitSlotView/types.d.ts +6 -0
- package/web-popups/form-slots/SubmitSlotView/types.js +1 -0
- package/web-popups/form-slots/TagInputSlotView/TagInputSlotView.d.ts +3 -0
- package/web-popups/form-slots/TagInputSlotView/TagInputSlotView.js +15 -0
- package/web-popups/form-slots/TagInputSlotView/index.d.ts +2 -0
- package/web-popups/form-slots/TagInputSlotView/index.js +1 -0
- package/web-popups/form-slots/TagInputSlotView/types.d.ts +5 -0
- package/web-popups/form-slots/TagInputSlotView/types.js +1 -0
- package/web-popups/form-slots/TextFieldView/TextFieldView.d.ts +3 -0
- package/web-popups/form-slots/TextFieldView/TextFieldView.js +46 -0
- package/web-popups/form-slots/TextFieldView/index.d.ts +2 -0
- package/web-popups/form-slots/TextFieldView/index.js +1 -0
- package/web-popups/form-slots/TextFieldView/styles.d.ts +3 -0
- package/web-popups/form-slots/TextFieldView/styles.js +7 -0
- package/web-popups/form-slots/TextFieldView/types.d.ts +9 -0
- package/web-popups/form-slots/TextFieldView/types.js +1 -0
- package/web-popups/form-slots/index.d.ts +4 -0
- package/web-popups/form-slots/index.js +4 -0
- package/web-popups/form-slots/styles.d.ts +6 -0
- package/web-popups/form-slots/styles.js +25 -0
- package/web-popups/form-slots/types.d.ts +6 -0
- package/web-popups/form-slots/types.js +1 -0
- package/web-popups/form.d.ts +20 -0
- package/web-popups/form.js +64 -0
- package/web-popups/formSession.d.ts +23 -0
- package/web-popups/formSession.js +117 -0
- package/web-popups/helpers.js +48 -1
- package/web-popups/index.d.ts +2 -2
- package/web-popups/index.js +1 -1
- package/web-popups/types.d.ts +59 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.22.0",
|
|
4
4
|
"description": "Code shared by the Pushwoosh WebSDK and the Control Panel, one entry point per module (web-popups: web popup model and renderer; subscription-widget: push subscription widget model and renderer; inbox: web inbox widget and inbox cell previews)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -5,4 +5,4 @@ import { type WebPopupInlineProps } from './types';
|
|
|
5
5
|
* `<img>` is capped by a `<style>` scoped to the wrapper's attribute, so the rule never reaches
|
|
6
6
|
* the host page, in a shadow root or in the light DOM. Page navigation is internal.
|
|
7
7
|
*/
|
|
8
|
-
export declare function WebPopupInline({ params, mode, colorScheme, onSubmitForm, onSubmitChoice, onSubmitRating, onRequestSubscribe, }: WebPopupInlineProps): import("react").JSX.Element | null;
|
|
8
|
+
export declare function WebPopupInline({ params, mode, colorScheme, onSubmitForm, onSubmitFormValues, onSubmitChoice, onSubmitRating, onRequestSubscribe, }: WebPopupInlineProps): import("react").JSX.Element | null;
|
|
@@ -16,6 +16,7 @@ export function WebPopupInline({
|
|
|
16
16
|
mode = 'live',
|
|
17
17
|
colorScheme = 'auto',
|
|
18
18
|
onSubmitForm,
|
|
19
|
+
onSubmitFormValues,
|
|
19
20
|
onSubmitChoice,
|
|
20
21
|
onSubmitRating,
|
|
21
22
|
onRequestSubscribe
|
|
@@ -38,6 +39,7 @@ export function WebPopupInline({
|
|
|
38
39
|
colorScheme: scheme,
|
|
39
40
|
onPageChange: setPageKey,
|
|
40
41
|
onSubmitForm: onSubmitForm,
|
|
42
|
+
onSubmitFormValues: onSubmitFormValues,
|
|
41
43
|
onSubmitChoice: onSubmitChoice,
|
|
42
44
|
onSubmitRating: onSubmitRating,
|
|
43
45
|
onRequestSubscribe: onRequestSubscribe
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type WebPopupBoxProps, type WebPopupReaderProps, type WebPopupSlotViewProps } from './types';
|
|
2
2
|
export declare function WebPopupSlotView({ slot, align, inverse, colors, mode, onRequestClose, onPageChange, onSubmitForm, onSubmitChoice, onSubmitRating, onRequestSubscribe, }: WebPopupSlotViewProps): import("react").JSX.Element;
|
|
3
|
-
export declare function WebPopupBox({ page, params, mode, colorScheme, leafRenderers, animatePage, onRequestClose, onPageChange, onSubmitForm, onSubmitChoice, onSubmitRating, onRequestSubscribe, }: WebPopupBoxProps): import("react").JSX.Element;
|
|
4
|
-
export declare function WebPopupReader({ params, mode, colorScheme, onRequestClose, onSubmitForm, onSubmitChoice, onSubmitRating, onRequestSubscribe, leafRenderers, }: WebPopupReaderProps): import("react").JSX.Element | null;
|
|
3
|
+
export declare function WebPopupBox({ page, params, mode, colorScheme, leafRenderers, animatePage, onRequestClose, onPageChange, onSubmitForm, onSubmitFormValues, onSubmitChoice, onSubmitRating, onRequestSubscribe, }: WebPopupBoxProps): import("react").JSX.Element;
|
|
4
|
+
export declare function WebPopupReader({ params, mode, colorScheme, onRequestClose, onSubmitForm, onSubmitFormValues, onSubmitChoice, onSubmitRating, onRequestSubscribe, leafRenderers, }: WebPopupReaderProps): import("react").JSX.Element | null;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useContext, useEffect, useState } from 'react';
|
|
3
3
|
import { useColorScheme } from './colorScheme';
|
|
4
|
-
import { webPopupButtonPillStyle, webPopupFormInputStyle, webPopupRatingScores, webPopupTextColor, webPopupSlotGap, webPopupSlotRole, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_BUTTON_SLOT_PADDING, WEB_POPUP_FONT_STACK, WEB_POPUP_KEYFRAMES, WEB_POPUP_PAGE_TRANSITION_MS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_TEXT_VARIANT_STYLES } from './constants';
|
|
4
|
+
import { webPopupButtonPillStyle, webPopupFormInputStyle, webPopupRatingScores, webPopupTextColor, webPopupSlotGap, webPopupSlotRole, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_BUTTON_SLOT_PADDING, WEB_POPUP_FONT_STACK, WEB_POPUP_EMAIL_PATTERN, WEB_POPUP_KEYFRAMES, WEB_POPUP_PAGE_TRANSITION_MS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_TEXT_VARIANT_STYLES } from './constants';
|
|
5
|
+
import { ConsentSlotView, EmailInputSlotView, SubmitSlotView, TagInputSlotView } from './form-slots';
|
|
6
|
+
import { useWebPopupFormSession, WebPopupFormSessionContext } from './formSession';
|
|
5
7
|
import { WEB_POPUP_GLYPH_PATHS, WEB_POPUP_THUMB_UP_PATH } from './glyphs';
|
|
6
8
|
import { placementMaxSize, resolveWebPopupPages, safeUrl, sanitizeWebPopupHtml, startPageOf, webPopupLinkTargetAttrs } from './helpers';
|
|
7
9
|
import { webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupScrimGradient } from './layout';
|
|
@@ -48,6 +50,7 @@ function ButtonSlotView({
|
|
|
48
50
|
onPageChange,
|
|
49
51
|
onRequestSubscribe
|
|
50
52
|
}) {
|
|
53
|
+
const form = useContext(WebPopupFormSessionContext);
|
|
51
54
|
const [askPhase, setAskPhase] = useState('idle');
|
|
52
55
|
const pill = webPopupButtonPillStyle(slot.variant, colors);
|
|
53
56
|
const wrapper = {};
|
|
@@ -69,7 +72,7 @@ function ButtonSlotView({
|
|
|
69
72
|
children: _jsx("button", {
|
|
70
73
|
type: "button",
|
|
71
74
|
style: pill,
|
|
72
|
-
onClick: () =>
|
|
75
|
+
onClick: () => form.turnPage(target, onPageChange),
|
|
73
76
|
children: slot.label
|
|
74
77
|
})
|
|
75
78
|
});
|
|
@@ -149,7 +152,6 @@ function SlotMessageView({
|
|
|
149
152
|
children: message
|
|
150
153
|
});
|
|
151
154
|
}
|
|
152
|
-
const FORM_EMAIL_PATTERN = /^\S+@\S+\.\S+$/;
|
|
153
155
|
const FORM_INPUT_TYPES = {
|
|
154
156
|
email: 'email',
|
|
155
157
|
phone: 'tel'
|
|
@@ -216,7 +218,7 @@ function FormSlotView({
|
|
|
216
218
|
const found = {};
|
|
217
219
|
for (const field of slot.fields) {
|
|
218
220
|
const value = (values[field.key] ?? '').trim();
|
|
219
|
-
if (field.required && !value) found[field.key] = 'Required';else if (field.kind === 'email' && value && !
|
|
221
|
+
if (field.required && !value) found[field.key] = 'Required';else if (field.kind === 'email' && value && !WEB_POPUP_EMAIL_PATTERN.test(value)) {
|
|
220
222
|
found[field.key] = 'Enter a valid email';
|
|
221
223
|
}
|
|
222
224
|
}
|
|
@@ -872,6 +874,30 @@ export function WebPopupSlotView({
|
|
|
872
874
|
inverse: inverse,
|
|
873
875
|
colors: colors
|
|
874
876
|
});
|
|
877
|
+
case 'email-input':
|
|
878
|
+
return _jsx(EmailInputSlotView, {
|
|
879
|
+
slot: slot,
|
|
880
|
+
inverse: inverse,
|
|
881
|
+
colors: colors
|
|
882
|
+
});
|
|
883
|
+
case 'tag-input':
|
|
884
|
+
return _jsx(TagInputSlotView, {
|
|
885
|
+
slot: slot,
|
|
886
|
+
inverse: inverse,
|
|
887
|
+
colors: colors
|
|
888
|
+
});
|
|
889
|
+
case 'consent':
|
|
890
|
+
return _jsx(ConsentSlotView, {
|
|
891
|
+
slot: slot,
|
|
892
|
+
inverse: inverse,
|
|
893
|
+
colors: colors
|
|
894
|
+
});
|
|
895
|
+
case 'submit':
|
|
896
|
+
return _jsx(SubmitSlotView, {
|
|
897
|
+
slot: slot,
|
|
898
|
+
align: align,
|
|
899
|
+
colors: colors
|
|
900
|
+
});
|
|
875
901
|
}
|
|
876
902
|
}
|
|
877
903
|
// A Content leaf: the named zone's slots (texts, buttons and forms in order)
|
|
@@ -1168,10 +1194,12 @@ export function WebPopupBox({
|
|
|
1168
1194
|
onRequestClose,
|
|
1169
1195
|
onPageChange,
|
|
1170
1196
|
onSubmitForm,
|
|
1197
|
+
onSubmitFormValues,
|
|
1171
1198
|
onSubmitChoice,
|
|
1172
1199
|
onSubmitRating,
|
|
1173
1200
|
onRequestSubscribe
|
|
1174
1201
|
}) {
|
|
1202
|
+
const formSession = useWebPopupFormSession(params, page.key, onPageChange, onSubmitFormValues);
|
|
1175
1203
|
const colors = resolveWebPopupColors(params, colorScheme);
|
|
1176
1204
|
const box = resolveWebPopupBoxChrome(params, colorScheme);
|
|
1177
1205
|
const style = {
|
|
@@ -1207,23 +1235,26 @@ export function WebPopupBox({
|
|
|
1207
1235
|
};
|
|
1208
1236
|
return _jsx("div", {
|
|
1209
1237
|
style: style,
|
|
1210
|
-
children: _jsx(
|
|
1211
|
-
|
|
1212
|
-
children: _jsx(
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1238
|
+
children: _jsx(WebPopupFormSessionContext.Provider, {
|
|
1239
|
+
value: formSession,
|
|
1240
|
+
children: _jsx("div", {
|
|
1241
|
+
style: pageStyle,
|
|
1242
|
+
children: _jsx(LayoutNodeView, {
|
|
1243
|
+
node: page.layout,
|
|
1244
|
+
page: page,
|
|
1245
|
+
colors: colors,
|
|
1246
|
+
mode: mode,
|
|
1247
|
+
scheme: colors.scheme,
|
|
1248
|
+
leaf: leafRenderers,
|
|
1249
|
+
onRequestClose: onRequestClose,
|
|
1250
|
+
onPageChange: onPageChange ?? (() => {}),
|
|
1251
|
+
onSubmitForm: onSubmitForm,
|
|
1252
|
+
onSubmitChoice: onSubmitChoice,
|
|
1253
|
+
onSubmitRating: onSubmitRating,
|
|
1254
|
+
onRequestSubscribe: onRequestSubscribe
|
|
1255
|
+
})
|
|
1256
|
+
}, page.key)
|
|
1257
|
+
})
|
|
1227
1258
|
});
|
|
1228
1259
|
}
|
|
1229
1260
|
function CloseButton({
|
|
@@ -1301,6 +1332,7 @@ export function WebPopupReader({
|
|
|
1301
1332
|
colorScheme = 'auto',
|
|
1302
1333
|
onRequestClose,
|
|
1303
1334
|
onSubmitForm,
|
|
1335
|
+
onSubmitFormValues,
|
|
1304
1336
|
onSubmitChoice,
|
|
1305
1337
|
onSubmitRating,
|
|
1306
1338
|
onRequestSubscribe,
|
|
@@ -1348,6 +1380,7 @@ export function WebPopupReader({
|
|
|
1348
1380
|
onRequestClose: onRequestClose,
|
|
1349
1381
|
onPageChange: setPageKey,
|
|
1350
1382
|
onSubmitForm: onSubmitForm,
|
|
1383
|
+
onSubmitFormValues: onSubmitFormValues,
|
|
1351
1384
|
onSubmitChoice: onSubmitChoice,
|
|
1352
1385
|
onSubmitRating: onSubmitRating,
|
|
1353
1386
|
onRequestSubscribe: onRequestSubscribe
|
|
@@ -1382,6 +1415,7 @@ export function WebPopupReader({
|
|
|
1382
1415
|
onRequestClose: onRequestClose,
|
|
1383
1416
|
onPageChange: setPageKey,
|
|
1384
1417
|
onSubmitForm: onSubmitForm,
|
|
1418
|
+
onSubmitFormValues: onSubmitFormValues,
|
|
1385
1419
|
onSubmitChoice: onSubmitChoice,
|
|
1386
1420
|
onSubmitRating: onSubmitRating,
|
|
1387
1421
|
onRequestSubscribe: onRequestSubscribe
|
|
@@ -69,5 +69,25 @@ export declare function webPopupRatingScores(scale: WebPopupRatingScale): number
|
|
|
69
69
|
export declare const WEB_POPUP_MAX_CHOICE_OPTIONS = 12;
|
|
70
70
|
/** What a slot says when the host callback rejected: nothing actionable, so it's retryable. */
|
|
71
71
|
export declare const WEB_POPUP_RETRY_ERROR = "Something went wrong. Please try again.";
|
|
72
|
+
/** Email shape both form paths accept; the server runs the real check. */
|
|
73
|
+
export declare const WEB_POPUP_EMAIL_PATTERN: RegExp;
|
|
74
|
+
/** Copy a Form's Email input falls back to — also the editor's defaults for a fresh block. */
|
|
75
|
+
export declare const WEB_POPUP_EMAIL_INPUT_DEFAULTS: {
|
|
76
|
+
readonly invalidMessage: "Enter a valid email";
|
|
77
|
+
readonly requiredMessage: "Required";
|
|
78
|
+
};
|
|
79
|
+
/** Copy a Form's Tag input falls back to. */
|
|
80
|
+
export declare const WEB_POPUP_TAG_INPUT_DEFAULTS: {
|
|
81
|
+
readonly requiredMessage: "Required";
|
|
82
|
+
};
|
|
83
|
+
/** Copy a Form's Consent falls back to. */
|
|
84
|
+
export declare const WEB_POPUP_CONSENT_DEFAULTS: {
|
|
85
|
+
readonly requiredMessage: "Please accept the privacy policy";
|
|
86
|
+
};
|
|
87
|
+
/** Copy a Form's Submit falls back to; the error is the retry line every submitting slot shows. */
|
|
88
|
+
export declare const WEB_POPUP_SUBMIT_DEFAULTS: {
|
|
89
|
+
readonly label: "Submit";
|
|
90
|
+
readonly errorMessage: "Something went wrong. Please try again.";
|
|
91
|
+
};
|
|
72
92
|
export declare const WEB_POPUP_KEYFRAMES = "\n@keyframes pw-vpopup-fade { from { opacity: 0; } }\n@keyframes pw-vpopup-slide { from { opacity: 0; translate: 0 28px; } }\n@keyframes pw-vpopup-overlay { from { opacity: 0; } }\n@keyframes pw-vpopup-page { from { opacity: 0; } }\n";
|
|
73
93
|
export declare const WEB_POPUP_PAGE_TRANSITION_MS = 300;
|
package/web-popups/constants.js
CHANGED
|
@@ -206,6 +206,26 @@ export function webPopupRatingScores(scale) {
|
|
|
206
206
|
export const WEB_POPUP_MAX_CHOICE_OPTIONS = 12;
|
|
207
207
|
/** What a slot says when the host callback rejected: nothing actionable, so it's retryable. */
|
|
208
208
|
export const WEB_POPUP_RETRY_ERROR = 'Something went wrong. Please try again.';
|
|
209
|
+
/** Email shape both form paths accept; the server runs the real check. */
|
|
210
|
+
export const WEB_POPUP_EMAIL_PATTERN = /^\S+@\S+\.\S+$/;
|
|
211
|
+
/** Copy a Form's Email input falls back to — also the editor's defaults for a fresh block. */
|
|
212
|
+
export const WEB_POPUP_EMAIL_INPUT_DEFAULTS = {
|
|
213
|
+
invalidMessage: 'Enter a valid email',
|
|
214
|
+
requiredMessage: 'Required'
|
|
215
|
+
};
|
|
216
|
+
/** Copy a Form's Tag input falls back to. */
|
|
217
|
+
export const WEB_POPUP_TAG_INPUT_DEFAULTS = {
|
|
218
|
+
requiredMessage: 'Required'
|
|
219
|
+
};
|
|
220
|
+
/** Copy a Form's Consent falls back to. */
|
|
221
|
+
export const WEB_POPUP_CONSENT_DEFAULTS = {
|
|
222
|
+
requiredMessage: 'Please accept the privacy policy'
|
|
223
|
+
};
|
|
224
|
+
/** Copy a Form's Submit falls back to; the error is the retry line every submitting slot shows. */
|
|
225
|
+
export const WEB_POPUP_SUBMIT_DEFAULTS = {
|
|
226
|
+
label: 'Submit',
|
|
227
|
+
errorMessage: WEB_POPUP_RETRY_ERROR
|
|
228
|
+
};
|
|
209
229
|
export const WEB_POPUP_KEYFRAMES = `
|
|
210
230
|
@keyframes pw-vpopup-fade { from { opacity: 0; } }
|
|
211
231
|
@keyframes pw-vpopup-slide { from { opacity: 0; translate: 0 28px; } }
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { webPopupFormFieldId } from '../../form';
|
|
4
|
+
import { WebPopupFormSessionContext } from '../../formSession';
|
|
5
|
+
import { safeUrl, webPopupLinkTargetAttrs } from '../../helpers';
|
|
6
|
+
import { errorStyle, fieldSlotStyle } from '../styles';
|
|
7
|
+
import { checkboxStyle, labelStyle, linkStyle } from './styles';
|
|
8
|
+
/** A Form's Consent checkbox with its policy link. */
|
|
9
|
+
export function ConsentSlotView({
|
|
10
|
+
slot,
|
|
11
|
+
...look
|
|
12
|
+
}) {
|
|
13
|
+
const session = useContext(WebPopupFormSessionContext);
|
|
14
|
+
const id = webPopupFormFieldId(session.pageKey, slot.key);
|
|
15
|
+
const error = session.errors[id];
|
|
16
|
+
const href = safeUrl(slot.url);
|
|
17
|
+
return _jsxs("div", {
|
|
18
|
+
style: fieldSlotStyle,
|
|
19
|
+
children: [_jsxs("label", {
|
|
20
|
+
style: labelStyle(look),
|
|
21
|
+
children: [_jsx("input", {
|
|
22
|
+
type: "checkbox",
|
|
23
|
+
checked: session.checks[id] === true,
|
|
24
|
+
disabled: session.phase === 'submitting',
|
|
25
|
+
style: checkboxStyle,
|
|
26
|
+
onChange: event => session.setCheck(id, event.currentTarget.checked)
|
|
27
|
+
}), _jsxs("span", {
|
|
28
|
+
children: [slot.checkboxLabel, href && _jsxs(_Fragment, {
|
|
29
|
+
children: [' ', _jsx("a", {
|
|
30
|
+
href: href,
|
|
31
|
+
...webPopupLinkTargetAttrs(undefined),
|
|
32
|
+
style: linkStyle(look.colors),
|
|
33
|
+
children: slot.linkLabel || slot.url
|
|
34
|
+
})]
|
|
35
|
+
})]
|
|
36
|
+
})]
|
|
37
|
+
}), error && _jsx("div", {
|
|
38
|
+
style: errorStyle(look.colors),
|
|
39
|
+
children: error
|
|
40
|
+
})]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ConsentSlotView } from './ConsentSlotView';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
import { type WebPopupResolvedColors } from '../../types';
|
|
3
|
+
import { type FieldLook } from '../types';
|
|
4
|
+
export declare const checkboxStyle: CSSProperties;
|
|
5
|
+
export declare function labelStyle(look: FieldLook): CSSProperties;
|
|
6
|
+
export declare function linkStyle(colors: WebPopupResolvedColors): CSSProperties;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { captionStyle } from '../styles';
|
|
2
|
+
export const checkboxStyle = {
|
|
3
|
+
margin: '2px 0 0',
|
|
4
|
+
flexShrink: 0
|
|
5
|
+
};
|
|
6
|
+
export function labelStyle(look) {
|
|
7
|
+
return {
|
|
8
|
+
...captionStyle(look),
|
|
9
|
+
display: 'flex',
|
|
10
|
+
alignItems: 'flex-start',
|
|
11
|
+
gap: 8,
|
|
12
|
+
cursor: 'pointer'
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function linkStyle(colors) {
|
|
16
|
+
return {
|
|
17
|
+
color: colors.accent
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TextFieldView } from '../TextFieldView';
|
|
3
|
+
/** A Form's Email input, drawn the runtime's way. */
|
|
4
|
+
export function EmailInputSlotView({
|
|
5
|
+
slot,
|
|
6
|
+
...look
|
|
7
|
+
}) {
|
|
8
|
+
return _jsx(TextFieldView, {
|
|
9
|
+
slotKey: slot.key,
|
|
10
|
+
label: slot.label,
|
|
11
|
+
placeholder: slot.placeholder,
|
|
12
|
+
inputType: "email",
|
|
13
|
+
autoComplete: "email",
|
|
14
|
+
look: look
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EmailInputSlotView } from './EmailInputSlotView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { WebPopupFormSessionContext } from '../../formSession';
|
|
4
|
+
import { errorStyle } from '../styles';
|
|
5
|
+
import { pillStyle, slotStyle } from './styles';
|
|
6
|
+
/** A Form's Submit: sends every field of the popup; shows errorMessage after a refusal. */
|
|
7
|
+
export function SubmitSlotView({
|
|
8
|
+
slot,
|
|
9
|
+
align,
|
|
10
|
+
colors
|
|
11
|
+
}) {
|
|
12
|
+
const session = useContext(WebPopupFormSessionContext);
|
|
13
|
+
const submitting = session.phase === 'submitting';
|
|
14
|
+
return _jsxs("div", {
|
|
15
|
+
style: slotStyle,
|
|
16
|
+
children: [_jsx("button", {
|
|
17
|
+
type: "button",
|
|
18
|
+
disabled: submitting,
|
|
19
|
+
style: pillStyle(slot.variant, colors, submitting),
|
|
20
|
+
onClick: session.submit,
|
|
21
|
+
children: slot.label
|
|
22
|
+
}), session.phase === 'error' && _jsx("div", {
|
|
23
|
+
style: {
|
|
24
|
+
...errorStyle(colors),
|
|
25
|
+
textAlign: align
|
|
26
|
+
},
|
|
27
|
+
children: slot.errorMessage
|
|
28
|
+
})]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SubmitSlotView } from './SubmitSlotView';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
import { type WebPopupButtonVariant, type WebPopupResolvedColors } from '../../types';
|
|
3
|
+
export declare const slotStyle: CSSProperties;
|
|
4
|
+
export declare function pillStyle(variant: WebPopupButtonVariant, colors: WebPopupResolvedColors, submitting: boolean): CSSProperties;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { webPopupButtonPillStyle, WEB_POPUP_BUTTON_SLOT_PADDING } from '../../constants';
|
|
2
|
+
export const slotStyle = {
|
|
3
|
+
padding: WEB_POPUP_BUTTON_SLOT_PADDING
|
|
4
|
+
};
|
|
5
|
+
export function pillStyle(variant, colors, submitting) {
|
|
6
|
+
return {
|
|
7
|
+
...webPopupButtonPillStyle(variant, colors),
|
|
8
|
+
...(submitting ? {
|
|
9
|
+
opacity: 0.6,
|
|
10
|
+
cursor: 'default'
|
|
11
|
+
} : {})
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TextFieldView } from '../TextFieldView';
|
|
3
|
+
/** A Form's Tag input, drawn the runtime's way. */
|
|
4
|
+
export function TagInputSlotView({
|
|
5
|
+
slot,
|
|
6
|
+
...look
|
|
7
|
+
}) {
|
|
8
|
+
return _jsx(TextFieldView, {
|
|
9
|
+
slotKey: slot.key,
|
|
10
|
+
label: slot.label,
|
|
11
|
+
placeholder: slot.placeholder,
|
|
12
|
+
inputType: "text",
|
|
13
|
+
look: look
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TagInputSlotView } from './TagInputSlotView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type TextFieldViewProps } from './types';
|
|
2
|
+
/** The text field a Form's Email and Tag inputs share; Enter advances the Form. */
|
|
3
|
+
export declare function TextFieldView({ slotKey, label, placeholder, inputType, autoComplete, look }: TextFieldViewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useState } from 'react';
|
|
3
|
+
import { webPopupFormInputStyle } from '../../constants';
|
|
4
|
+
import { webPopupFormFieldId } from '../../form';
|
|
5
|
+
import { WebPopupFormSessionContext } from '../../formSession';
|
|
6
|
+
import { errorStyle, fieldSlotStyle } from '../styles';
|
|
7
|
+
import { labelStyle } from './styles';
|
|
8
|
+
/** The text field a Form's Email and Tag inputs share; Enter advances the Form. */
|
|
9
|
+
export function TextFieldView({
|
|
10
|
+
slotKey,
|
|
11
|
+
label,
|
|
12
|
+
placeholder,
|
|
13
|
+
inputType,
|
|
14
|
+
autoComplete,
|
|
15
|
+
look
|
|
16
|
+
}) {
|
|
17
|
+
const session = useContext(WebPopupFormSessionContext);
|
|
18
|
+
const [focused, setFocused] = useState(false);
|
|
19
|
+
const id = webPopupFormFieldId(session.pageKey, slotKey);
|
|
20
|
+
const error = session.errors[id];
|
|
21
|
+
let borderColor;
|
|
22
|
+
if (error) borderColor = look.colors.error;else if (focused) borderColor = look.colors.accent;
|
|
23
|
+
return _jsxs("div", {
|
|
24
|
+
style: fieldSlotStyle,
|
|
25
|
+
children: [label && _jsx("div", {
|
|
26
|
+
style: labelStyle(look),
|
|
27
|
+
children: label
|
|
28
|
+
}), _jsx("input", {
|
|
29
|
+
type: inputType,
|
|
30
|
+
autoComplete: autoComplete,
|
|
31
|
+
placeholder: placeholder || undefined,
|
|
32
|
+
value: session.texts[id] ?? '',
|
|
33
|
+
disabled: session.phase === 'submitting',
|
|
34
|
+
style: webPopupFormInputStyle(look.colors, borderColor),
|
|
35
|
+
onFocus: () => setFocused(true),
|
|
36
|
+
onBlur: () => setFocused(false),
|
|
37
|
+
onChange: event => session.setText(id, event.currentTarget.value),
|
|
38
|
+
onKeyDown: event => {
|
|
39
|
+
if (event.key === 'Enter') session.advance();
|
|
40
|
+
}
|
|
41
|
+
}), error && _jsx("div", {
|
|
42
|
+
style: errorStyle(look.colors),
|
|
43
|
+
children: error
|
|
44
|
+
})]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TextFieldView } from './TextFieldView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CSSProperties } from 'react';
|
|
2
|
+
import { type WebPopupResolvedColors } from '../types';
|
|
3
|
+
import { type FieldLook } from './types';
|
|
4
|
+
export declare const fieldSlotStyle: CSSProperties;
|
|
5
|
+
export declare function captionStyle({ inverse, colors }: FieldLook): CSSProperties;
|
|
6
|
+
export declare function errorStyle(colors: WebPopupResolvedColors): CSSProperties;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { webPopupTextColor, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_TEXT_VARIANT_STYLES } from '../constants';
|
|
2
|
+
export const fieldSlotStyle = {
|
|
3
|
+
padding: WEB_POPUP_TEXT_SLOT_PADDING,
|
|
4
|
+
textAlign: 'left'
|
|
5
|
+
};
|
|
6
|
+
export function captionStyle({
|
|
7
|
+
inverse,
|
|
8
|
+
colors
|
|
9
|
+
}) {
|
|
10
|
+
const color = webPopupTextColor('caption', colors, inverse);
|
|
11
|
+
return {
|
|
12
|
+
...WEB_POPUP_TEXT_VARIANT_STYLES.caption,
|
|
13
|
+
...(color ? {
|
|
14
|
+
color
|
|
15
|
+
} : {})
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function errorStyle(colors) {
|
|
19
|
+
return {
|
|
20
|
+
fontSize: 12,
|
|
21
|
+
lineHeight: 1.4,
|
|
22
|
+
color: colors.error,
|
|
23
|
+
paddingTop: 2
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type WebPopupConsentSlot, type WebPopupEmailInputSlot, type WebPopupFormValues, type WebPopupResolvedPage, type WebPopupTagInputSlot } from './types';
|
|
2
|
+
/** A Form field with the page it sits on; `id` is unique across the popup. */
|
|
3
|
+
export type WebPopupFormFieldEntry = {
|
|
4
|
+
id: string;
|
|
5
|
+
pageKey: string;
|
|
6
|
+
slot: WebPopupEmailInputSlot | WebPopupTagInputSlot | WebPopupConsentSlot;
|
|
7
|
+
};
|
|
8
|
+
/** What the visitor has entered so far, by field id. */
|
|
9
|
+
export type WebPopupFormInput = {
|
|
10
|
+
texts: Record<string, string>;
|
|
11
|
+
checks: Record<string, boolean>;
|
|
12
|
+
};
|
|
13
|
+
/** A field id: slot keys are unique within a page, not across pages. */
|
|
14
|
+
export declare function webPopupFormFieldId(pageKey: string, slotKey: string): string;
|
|
15
|
+
/** Every Form field of the popup, in page and stack order. */
|
|
16
|
+
export declare function collectWebPopupFormFields(pages: WebPopupResolvedPage[]): WebPopupFormFieldEntry[];
|
|
17
|
+
/** The block text of every field that blocks a submit, by field id; empty = the Form can be sent. */
|
|
18
|
+
export declare function validateWebPopupForm(fields: WebPopupFormFieldEntry[], input: WebPopupFormInput): Record<string, string>;
|
|
19
|
+
/** The values a valid Form submits (contracts §10). */
|
|
20
|
+
export declare function webPopupFormValues(fields: WebPopupFormFieldEntry[], input: WebPopupFormInput): WebPopupFormValues;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { WEB_POPUP_EMAIL_PATTERN } from './constants';
|
|
2
|
+
/** A field id: slot keys are unique within a page, not across pages. */
|
|
3
|
+
export function webPopupFormFieldId(pageKey, slotKey) {
|
|
4
|
+
return `${pageKey}/${slotKey}`;
|
|
5
|
+
}
|
|
6
|
+
/** Every Form field of the popup, in page and stack order. */
|
|
7
|
+
export function collectWebPopupFormFields(pages) {
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const page of pages) {
|
|
10
|
+
for (const zone of page.contents) {
|
|
11
|
+
for (const slot of zone.slots) {
|
|
12
|
+
if (slot.type !== 'email-input' && slot.type !== 'tag-input' && slot.type !== 'consent') continue;
|
|
13
|
+
out.push({
|
|
14
|
+
id: webPopupFormFieldId(page.key, slot.key),
|
|
15
|
+
pageKey: page.key,
|
|
16
|
+
slot
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function fieldError(field, input) {
|
|
24
|
+
const {
|
|
25
|
+
slot
|
|
26
|
+
} = field;
|
|
27
|
+
if (slot.type === 'consent') return input.checks[field.id] ? undefined : slot.requiredMessage;
|
|
28
|
+
const value = (input.texts[field.id] ?? '').trim();
|
|
29
|
+
if (slot.type === 'tag-input') return slot.required && !value ? slot.requiredMessage : undefined;
|
|
30
|
+
if (!value) return slot.requiredMessage;
|
|
31
|
+
return WEB_POPUP_EMAIL_PATTERN.test(value) ? undefined : slot.invalidMessage;
|
|
32
|
+
}
|
|
33
|
+
/** The block text of every field that blocks a submit, by field id; empty = the Form can be sent. */
|
|
34
|
+
export function validateWebPopupForm(fields, input) {
|
|
35
|
+
const errors = {};
|
|
36
|
+
for (const field of fields) {
|
|
37
|
+
const error = fieldError(field, input);
|
|
38
|
+
if (error) errors[field.id] = error;
|
|
39
|
+
}
|
|
40
|
+
return errors;
|
|
41
|
+
}
|
|
42
|
+
/** The values a valid Form submits (contracts §10). */
|
|
43
|
+
export function webPopupFormValues(fields, input) {
|
|
44
|
+
const values = {
|
|
45
|
+
tags: {},
|
|
46
|
+
policyAccepted: true
|
|
47
|
+
};
|
|
48
|
+
for (const field of fields) {
|
|
49
|
+
const {
|
|
50
|
+
slot
|
|
51
|
+
} = field;
|
|
52
|
+
if (slot.type === 'consent') {
|
|
53
|
+
values.policyAccepted = values.policyAccepted && input.checks[field.id] === true;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const value = (input.texts[field.id] ?? '').trim();
|
|
57
|
+
if (slot.type === 'email-input') {
|
|
58
|
+
values.email = value;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (value && slot.tagName) values.tags[slot.tagName] = value;
|
|
62
|
+
}
|
|
63
|
+
return values;
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type WebPopupFormValuesSubmitHandler, type WebPopupParams } from './types';
|
|
2
|
+
/** A Form's live state, shared by its field and Submit slots across every page. */
|
|
3
|
+
export type WebPopupFormSession = {
|
|
4
|
+
pageKey: string;
|
|
5
|
+
texts: Record<string, string>;
|
|
6
|
+
checks: Record<string, boolean>;
|
|
7
|
+
errors: Record<string, string>;
|
|
8
|
+
phase: 'idle' | 'submitting' | 'error';
|
|
9
|
+
setText: (id: string, value: string) => void;
|
|
10
|
+
setCheck: (id: string, checked: boolean) => void;
|
|
11
|
+
submit: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* A `page`-action button: a jump forward goes through `go` only when the current page is valid,
|
|
14
|
+
* a jump onto Success submits the Form; no turn while a submit is in flight.
|
|
15
|
+
*/
|
|
16
|
+
turnPage: (target: string, go: (page: string) => void) => void;
|
|
17
|
+
/** Enter in a field: Submit on the Form's last page, the next page otherwise; nothing while a submit is in flight. */
|
|
18
|
+
advance: () => void;
|
|
19
|
+
};
|
|
20
|
+
/** What a Form slot reads; a slot outside any WebPopupBox gets this inert session. */
|
|
21
|
+
export declare const WebPopupFormSessionContext: import("react").Context<WebPopupFormSession>;
|
|
22
|
+
/** The Form session a WebPopupBox owns: it sees every page and can switch them. */
|
|
23
|
+
export declare function useWebPopupFormSession(params: WebPopupParams, pageKey: string, onPageChange: ((page: string) => void) | undefined, onSubmitFormValues: WebPopupFormValuesSubmitHandler | undefined): WebPopupFormSession;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createContext, useMemo, useState } from 'react';
|
|
2
|
+
import { collectWebPopupFormFields, validateWebPopupForm, webPopupFormValues } from './form';
|
|
3
|
+
import { resolveWebPopupPages } from './helpers';
|
|
4
|
+
const INERT_SESSION = {
|
|
5
|
+
pageKey: '',
|
|
6
|
+
texts: {},
|
|
7
|
+
checks: {},
|
|
8
|
+
errors: {},
|
|
9
|
+
phase: 'idle',
|
|
10
|
+
setText: () => {},
|
|
11
|
+
setCheck: () => {},
|
|
12
|
+
submit: () => {},
|
|
13
|
+
turnPage: (target, go) => go(target),
|
|
14
|
+
advance: () => {}
|
|
15
|
+
};
|
|
16
|
+
/** What a Form slot reads; a slot outside any WebPopupBox gets this inert session. */
|
|
17
|
+
export const WebPopupFormSessionContext = createContext(INERT_SESSION);
|
|
18
|
+
function withoutKey(record, key) {
|
|
19
|
+
if (!(key in record)) return record;
|
|
20
|
+
return Object.fromEntries(Object.entries(record).filter(([candidate]) => candidate !== key));
|
|
21
|
+
}
|
|
22
|
+
/** The Form session a WebPopupBox owns: it sees every page and can switch them. */
|
|
23
|
+
export function useWebPopupFormSession(params, pageKey, onPageChange, onSubmitFormValues) {
|
|
24
|
+
const pages = useMemo(() => resolveWebPopupPages(params), [params]);
|
|
25
|
+
const fields = useMemo(() => collectWebPopupFormFields(pages), [pages]);
|
|
26
|
+
const [texts, setTexts] = useState({});
|
|
27
|
+
const [checks, setChecks] = useState({});
|
|
28
|
+
const [errors, setErrors] = useState({});
|
|
29
|
+
const [phase, setPhase] = useState('idle');
|
|
30
|
+
const pageIndex = key => pages.findIndex(candidate => candidate.key === key);
|
|
31
|
+
const pageValid = () => {
|
|
32
|
+
const found = validateWebPopupForm(fields.filter(field => field.pageKey === pageKey), {
|
|
33
|
+
texts,
|
|
34
|
+
checks
|
|
35
|
+
});
|
|
36
|
+
setErrors(found);
|
|
37
|
+
return Object.keys(found).length === 0;
|
|
38
|
+
};
|
|
39
|
+
// A page button can skip a page, so Submit checks every page and shows the first broken one.
|
|
40
|
+
const formValid = () => {
|
|
41
|
+
const found = validateWebPopupForm(fields, {
|
|
42
|
+
texts,
|
|
43
|
+
checks
|
|
44
|
+
});
|
|
45
|
+
setErrors(found);
|
|
46
|
+
const invalid = fields.find(field => field.id in found);
|
|
47
|
+
if (invalid) onPageChange?.(invalid.pageKey);
|
|
48
|
+
return !invalid;
|
|
49
|
+
};
|
|
50
|
+
const showInvalidEmail = () => {
|
|
51
|
+
const email = fields.find(field => field.slot.type === 'email-input');
|
|
52
|
+
if (email?.slot.type !== 'email-input') return;
|
|
53
|
+
setErrors({
|
|
54
|
+
[email.id]: email.slot.invalidMessage
|
|
55
|
+
});
|
|
56
|
+
onPageChange?.(email.pageKey);
|
|
57
|
+
};
|
|
58
|
+
const submit = () => {
|
|
59
|
+
if (!onSubmitFormValues || phase === 'submitting') return;
|
|
60
|
+
if (!formValid()) {
|
|
61
|
+
setPhase('idle');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setPhase('submitting');
|
|
65
|
+
Promise.resolve().then(() => onSubmitFormValues(webPopupFormValues(fields, {
|
|
66
|
+
texts,
|
|
67
|
+
checks
|
|
68
|
+
}))).then(result => {
|
|
69
|
+
setPhase('idle');
|
|
70
|
+
if (result === 'invalid-email') {
|
|
71
|
+
showInvalidEmail();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const success = pages.find(candidate => candidate.role === 'success');
|
|
75
|
+
if (success) onPageChange?.(success.key);
|
|
76
|
+
}, () => setPhase('error'));
|
|
77
|
+
};
|
|
78
|
+
const turnPage = (target, go) => {
|
|
79
|
+
if (phase === 'submitting') return;
|
|
80
|
+
const targetIndex = pageIndex(target);
|
|
81
|
+
const forward = targetIndex > pageIndex(pageKey);
|
|
82
|
+
if (!onSubmitFormValues || !forward) {
|
|
83
|
+
go(target);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (pages[targetIndex].role === 'success') submit();else if (pageValid()) go(target);
|
|
87
|
+
};
|
|
88
|
+
const advance = () => {
|
|
89
|
+
if (!onSubmitFormValues || phase === 'submitting') return;
|
|
90
|
+
const next = pages[pageIndex(pageKey) + 1];
|
|
91
|
+
if (!next || next.role === 'success') submit();else if (pageValid()) onPageChange?.(next.key);
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
pageKey,
|
|
95
|
+
texts,
|
|
96
|
+
checks,
|
|
97
|
+
errors,
|
|
98
|
+
phase,
|
|
99
|
+
setText: (id, value) => {
|
|
100
|
+
setTexts(prev => ({
|
|
101
|
+
...prev,
|
|
102
|
+
[id]: value
|
|
103
|
+
}));
|
|
104
|
+
setErrors(prev => withoutKey(prev, id));
|
|
105
|
+
},
|
|
106
|
+
setCheck: (id, checked) => {
|
|
107
|
+
setChecks(prev => ({
|
|
108
|
+
...prev,
|
|
109
|
+
[id]: checked
|
|
110
|
+
}));
|
|
111
|
+
setErrors(prev => withoutKey(prev, id));
|
|
112
|
+
},
|
|
113
|
+
submit,
|
|
114
|
+
turnPage,
|
|
115
|
+
advance
|
|
116
|
+
};
|
|
117
|
+
}
|
package/web-popups/helpers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SAFE_URL_PROTOCOL, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_DEFAULT_COLORS, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_VERSION } from './constants';
|
|
1
|
+
import { SAFE_URL_PROTOCOL, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_CONSENT_DEFAULTS, WEB_POPUP_DEFAULT_COLORS, WEB_POPUP_EMAIL_INPUT_DEFAULTS, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_SUBMIT_DEFAULTS, WEB_POPUP_TAG_INPUT_DEFAULTS, WEB_POPUP_VERSION } from './constants';
|
|
2
2
|
import { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_SIZES } from './glyphs';
|
|
3
3
|
import { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN } from './layout';
|
|
4
4
|
import { autoDarkWebPopupColors } from './palette';
|
|
@@ -549,6 +549,50 @@ function normalizeSlots(raw) {
|
|
|
549
549
|
});
|
|
550
550
|
continue;
|
|
551
551
|
}
|
|
552
|
+
if (slot.type === 'email-input') {
|
|
553
|
+
out.push({
|
|
554
|
+
type: 'email-input',
|
|
555
|
+
key: slot.key,
|
|
556
|
+
label: slotString(slot.label),
|
|
557
|
+
placeholder: slotString(slot.placeholder),
|
|
558
|
+
invalidMessage: slotStringOr(slot.invalidMessage, WEB_POPUP_EMAIL_INPUT_DEFAULTS.invalidMessage),
|
|
559
|
+
requiredMessage: slotStringOr(slot.requiredMessage, WEB_POPUP_EMAIL_INPUT_DEFAULTS.requiredMessage)
|
|
560
|
+
});
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (slot.type === 'tag-input') {
|
|
564
|
+
out.push({
|
|
565
|
+
type: 'tag-input',
|
|
566
|
+
key: slot.key,
|
|
567
|
+
tagName: slotString(slot.tagName),
|
|
568
|
+
label: slotString(slot.label),
|
|
569
|
+
placeholder: slotString(slot.placeholder),
|
|
570
|
+
required: slot.required === true,
|
|
571
|
+
requiredMessage: slotStringOr(slot.requiredMessage, WEB_POPUP_TAG_INPUT_DEFAULTS.requiredMessage)
|
|
572
|
+
});
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (slot.type === 'consent') {
|
|
576
|
+
out.push({
|
|
577
|
+
type: 'consent',
|
|
578
|
+
key: slot.key,
|
|
579
|
+
checkboxLabel: slotString(slot.checkboxLabel, MAX_SLOT_MESSAGE),
|
|
580
|
+
linkLabel: slotString(slot.linkLabel),
|
|
581
|
+
url: slotString(slot.url, MAX_SLOT_MESSAGE),
|
|
582
|
+
requiredMessage: slotStringOr(slot.requiredMessage, WEB_POPUP_CONSENT_DEFAULTS.requiredMessage)
|
|
583
|
+
});
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (slot.type === 'submit') {
|
|
587
|
+
out.push({
|
|
588
|
+
type: 'submit',
|
|
589
|
+
key: slot.key,
|
|
590
|
+
variant: BUTTON_VARIANTS.includes(slot.variant) ? slot.variant : 'primary',
|
|
591
|
+
label: slotStringOr(slot.label, WEB_POPUP_SUBMIT_DEFAULTS.label),
|
|
592
|
+
errorMessage: slotStringOr(slot.errorMessage, WEB_POPUP_SUBMIT_DEFAULTS.errorMessage, MAX_SLOT_MESSAGE)
|
|
593
|
+
});
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
552
596
|
if (slot.type === 'email-subscription-form') {
|
|
553
597
|
out.push({
|
|
554
598
|
type: 'email-subscription-form',
|
|
@@ -673,6 +717,9 @@ export function resolveWebPopupPages(params) {
|
|
|
673
717
|
} : {}),
|
|
674
718
|
...(height !== undefined ? {
|
|
675
719
|
height
|
|
720
|
+
} : {}),
|
|
721
|
+
...(page.role === 'success' ? {
|
|
722
|
+
role: 'success'
|
|
676
723
|
} : {})
|
|
677
724
|
});
|
|
678
725
|
}
|
package/web-popups/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { WEB_POPUP_TEMPLATES, findWebPopupTemplate } from './templates';
|
|
|
4
4
|
export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons, } from './helpers';
|
|
5
5
|
export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs, type WebPopupTimerLabels, } from './timer';
|
|
6
6
|
export { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN, webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupCssLength, webPopupPaddingValue, webPopupTracksValue, } from './layout';
|
|
7
|
-
export { WEB_POPUP_VERSION, WEB_POPUP_FONT_STACK, WEB_POPUP_TEXT_COLOR, WEB_POPUP_TEXT_SECONDARY_COLOR, WEB_POPUP_ACCENT_COLOR, WEB_POPUP_BACKGROUND_COLOR, WEB_POPUP_DEFAULT_COLORS, webPopupTextColor, WEB_POPUP_TEXT_VARIANT_STYLES, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_BUTTON_SLOT_PADDING, webPopupSlotGap, webPopupSlotRole, type WebPopupSlotRole, WEB_POPUP_DEFAULT_WIDTH, WEB_POPUP_INLINE_IMAGE_MAX_HEIGHT, WEB_POPUP_LAYOUT_MAX_DEPTH, WEB_POPUP_LAYOUT_MAX_NODES, webPopupButtonPillStyle, webPopupFormInputStyle, WEB_POPUP_FORM_INPUT_BORDER, WEB_POPUP_FORM_ERROR_COLOR, WEB_POPUP_FORM_ERROR_COLOR_DARK, WEB_POPUP_ON_ACCENT_COLOR, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_RETRY_ERROR, webPopupRatingScores, } from './constants';
|
|
7
|
+
export { WEB_POPUP_VERSION, WEB_POPUP_FONT_STACK, WEB_POPUP_TEXT_COLOR, WEB_POPUP_TEXT_SECONDARY_COLOR, WEB_POPUP_ACCENT_COLOR, WEB_POPUP_BACKGROUND_COLOR, WEB_POPUP_DEFAULT_COLORS, webPopupTextColor, WEB_POPUP_TEXT_VARIANT_STYLES, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_BUTTON_SLOT_PADDING, webPopupSlotGap, webPopupSlotRole, type WebPopupSlotRole, WEB_POPUP_DEFAULT_WIDTH, WEB_POPUP_INLINE_IMAGE_MAX_HEIGHT, WEB_POPUP_LAYOUT_MAX_DEPTH, WEB_POPUP_LAYOUT_MAX_NODES, webPopupButtonPillStyle, webPopupFormInputStyle, WEB_POPUP_FORM_INPUT_BORDER, WEB_POPUP_FORM_ERROR_COLOR, WEB_POPUP_FORM_ERROR_COLOR_DARK, WEB_POPUP_ON_ACCENT_COLOR, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_EMAIL_INPUT_DEFAULTS, WEB_POPUP_TAG_INPUT_DEFAULTS, WEB_POPUP_CONSENT_DEFAULTS, WEB_POPUP_SUBMIT_DEFAULTS, webPopupRatingScores, } from './constants';
|
|
8
8
|
export { resolveWebPopupBoxChrome, resolveWebPopupColors, autoDarkWebPopupColors, webPopupColorAlpha, webPopupDarkColors, webPopupDarkEnabled, webPopupEffectiveScheme, webPopupImageSrc, webPopupMixColor, webPopupShiftColor, } from './palette';
|
|
9
9
|
export { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_PATHS, WEB_POPUP_GLYPH_SIZES, WEB_POPUP_THUMB_UP_PATH, } from './glyphs';
|
|
10
|
-
export { type WebPopupJson, type WebPopupKind, type WebPopupParams, type WebPopupColors, type WebPopupChrome, type WebPopupPageParams, type WebPopupResolvedPage, type WebPopupDark, type WebPopupResolvedColors, type WebPopupColorScheme, type WebPopupColorSchemePref, type WebPopupSlot, type WebPopupImage, type WebPopupVideo, type WebPopupPlacement, type WebPopupOverlay, type WebPopupAnimation, type WebPopupButtonAction, type WebPopupButtonVariant, type WebPopupTextVariant, type WebPopupTextAlign, type WebPopupVAnchor, type WebPopupHAnchor, type WebPopupReaderMode, type WebPopupReaderProps, type WebPopupLeafRenderers, type WebPopupBoxProps, type WebPopupInlineProps, type WebPopupLayoutNode, type WebPopupContainerNode, type WebPopupContentNode, type WebPopupImageNode, type WebPopupContainerType, type WebPopupContainerProps, type WebPopupContentZone, type WebPopupContentTone, type WebPopupCssLength, type WebPopupBoxSides, type WebPopupAlignItems, type WebPopupJustifyContent, type WebPopupValueParam, type WebPopupValueControl, type WebPopupLengthUnit, type WebPopupLengthRange, type WebPopupValueRef, type WebPopupTemplate, type WebPopupFormField, type WebPopupFormFieldKind, type WebPopupFormPrivacy, type WebPopupFormSubmitPayload, type WebPopupFormSubmitResult, type WebPopupFormSubmitHandler, type WebPopupTimerSlot, type WebPopupTimerExpireAction, type WebPopupTimerRemaining, type WebPopupChoiceSlot, type WebPopupChoiceOption, type WebPopupChoiceControl, type WebPopupChoiceSubmitPayload, type WebPopupChoiceSubmitHandler, type WebPopupRatingSlot, type WebPopupRatingScale, type WebPopupRatingSubmitMode, type WebPopupRatingSubmitPayload, type WebPopupRatingSubmitHandler, type WebPopupSubscribeResult, type WebPopupGlyphSlot, type WebPopupGlyphName, type WebPopupGlyphSize, type WebPopupSlotViewProps, } from './types';
|
|
10
|
+
export { type WebPopupJson, type WebPopupKind, type WebPopupParams, type WebPopupColors, type WebPopupChrome, type WebPopupPageParams, type WebPopupResolvedPage, type WebPopupDark, type WebPopupResolvedColors, type WebPopupColorScheme, type WebPopupColorSchemePref, type WebPopupSlot, type WebPopupImage, type WebPopupVideo, type WebPopupPlacement, type WebPopupOverlay, type WebPopupAnimation, type WebPopupButtonAction, type WebPopupButtonVariant, type WebPopupTextVariant, type WebPopupTextAlign, type WebPopupVAnchor, type WebPopupHAnchor, type WebPopupReaderMode, type WebPopupReaderProps, type WebPopupLeafRenderers, type WebPopupBoxProps, type WebPopupInlineProps, type WebPopupLayoutNode, type WebPopupContainerNode, type WebPopupContentNode, type WebPopupImageNode, type WebPopupContainerType, type WebPopupContainerProps, type WebPopupContentZone, type WebPopupContentTone, type WebPopupCssLength, type WebPopupBoxSides, type WebPopupAlignItems, type WebPopupJustifyContent, type WebPopupValueParam, type WebPopupValueControl, type WebPopupLengthUnit, type WebPopupLengthRange, type WebPopupValueRef, type WebPopupTemplate, type WebPopupFormField, type WebPopupFormFieldKind, type WebPopupFormPrivacy, type WebPopupFormSubmitPayload, type WebPopupFormSubmitResult, type WebPopupFormSubmitHandler, type WebPopupEmailInputSlot, type WebPopupTagInputSlot, type WebPopupConsentSlot, type WebPopupSubmitSlot, type WebPopupFormValues, type WebPopupFormValuesSubmitResult, type WebPopupFormValuesSubmitHandler, type WebPopupTimerSlot, type WebPopupTimerExpireAction, type WebPopupTimerRemaining, type WebPopupChoiceSlot, type WebPopupChoiceOption, type WebPopupChoiceControl, type WebPopupChoiceSubmitPayload, type WebPopupChoiceSubmitHandler, type WebPopupRatingSlot, type WebPopupRatingScale, type WebPopupRatingSubmitMode, type WebPopupRatingSubmitPayload, type WebPopupRatingSubmitHandler, type WebPopupSubscribeResult, type WebPopupGlyphSlot, type WebPopupGlyphName, type WebPopupGlyphSize, type WebPopupSlotViewProps, } from './types';
|
package/web-popups/index.js
CHANGED
|
@@ -4,6 +4,6 @@ export { WEB_POPUP_TEMPLATES, findWebPopupTemplate } from './templates';
|
|
|
4
4
|
export { parseWebPopupJson, stringifyWebPopup, resolveWebPopupPages, resolveWebPopupPageSize, startPageOf, safeUrl, sanitizeWebPopupHtml, normalizeWebPopupColors, normalizeWebPopupValues, webPopupValuesMap, collectWebPopupFormCodes, webPopupExpired, normalizeWebPopupDark, WEB_POPUP_MAX_SIZE_PX, isWebPopupCloseButton, webPopupPageWithoutCloseButtons, webPopupParamsWithoutCloseButtons } from './helpers';
|
|
5
5
|
export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs } from './timer';
|
|
6
6
|
export { normalizeWebPopupLayout, substituteWebPopupLayoutValues, WEB_POPUP_VALUE_KEY_PATTERN, webPopupBackgroundImageStyle, webPopupContainerStyle, webPopupCssLength, webPopupPaddingValue, webPopupTracksValue } from './layout';
|
|
7
|
-
export { WEB_POPUP_VERSION, WEB_POPUP_FONT_STACK, WEB_POPUP_TEXT_COLOR, WEB_POPUP_TEXT_SECONDARY_COLOR, WEB_POPUP_ACCENT_COLOR, WEB_POPUP_BACKGROUND_COLOR, WEB_POPUP_DEFAULT_COLORS, webPopupTextColor, WEB_POPUP_TEXT_VARIANT_STYLES, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_BUTTON_SLOT_PADDING, webPopupSlotGap, webPopupSlotRole, WEB_POPUP_DEFAULT_WIDTH, WEB_POPUP_INLINE_IMAGE_MAX_HEIGHT, WEB_POPUP_LAYOUT_MAX_DEPTH, WEB_POPUP_LAYOUT_MAX_NODES, webPopupButtonPillStyle, webPopupFormInputStyle, WEB_POPUP_FORM_INPUT_BORDER, WEB_POPUP_FORM_ERROR_COLOR, WEB_POPUP_FORM_ERROR_COLOR_DARK, WEB_POPUP_ON_ACCENT_COLOR, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_RETRY_ERROR, webPopupRatingScores } from './constants';
|
|
7
|
+
export { WEB_POPUP_VERSION, WEB_POPUP_FONT_STACK, WEB_POPUP_TEXT_COLOR, WEB_POPUP_TEXT_SECONDARY_COLOR, WEB_POPUP_ACCENT_COLOR, WEB_POPUP_BACKGROUND_COLOR, WEB_POPUP_DEFAULT_COLORS, webPopupTextColor, WEB_POPUP_TEXT_VARIANT_STYLES, WEB_POPUP_BG_SECTION_FALLBACK, WEB_POPUP_TEXT_SLOT_PADDING, WEB_POPUP_BUTTON_SLOT_PADDING, webPopupSlotGap, webPopupSlotRole, WEB_POPUP_DEFAULT_WIDTH, WEB_POPUP_INLINE_IMAGE_MAX_HEIGHT, WEB_POPUP_LAYOUT_MAX_DEPTH, WEB_POPUP_LAYOUT_MAX_NODES, webPopupButtonPillStyle, webPopupFormInputStyle, WEB_POPUP_FORM_INPUT_BORDER, WEB_POPUP_FORM_ERROR_COLOR, WEB_POPUP_FORM_ERROR_COLOR_DARK, WEB_POPUP_ON_ACCENT_COLOR, WEB_POPUP_FORM_DEFAULTS, WEB_POPUP_CHOICE_DEFAULTS, WEB_POPUP_MAX_CHOICE_OPTIONS, WEB_POPUP_RATING_DEFAULTS, WEB_POPUP_RETRY_ERROR, WEB_POPUP_EMAIL_INPUT_DEFAULTS, WEB_POPUP_TAG_INPUT_DEFAULTS, WEB_POPUP_CONSENT_DEFAULTS, WEB_POPUP_SUBMIT_DEFAULTS, webPopupRatingScores } from './constants';
|
|
8
8
|
export { resolveWebPopupBoxChrome, resolveWebPopupColors, autoDarkWebPopupColors, webPopupColorAlpha, webPopupDarkColors, webPopupDarkEnabled, webPopupEffectiveScheme, webPopupImageSrc, webPopupMixColor, webPopupShiftColor } from './palette';
|
|
9
9
|
export { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_PATHS, WEB_POPUP_GLYPH_SIZES, WEB_POPUP_THUMB_UP_PATH } from './glyphs';
|
package/web-popups/types.d.ts
CHANGED
|
@@ -126,6 +126,42 @@ export type WebPopupGlyphSlot = {
|
|
|
126
126
|
/** Hex '#rrggbb'; '' = the palette accent. */
|
|
127
127
|
color: string;
|
|
128
128
|
};
|
|
129
|
+
/** A Form's email field; always required, so it carries no `required` flag. */
|
|
130
|
+
export type WebPopupEmailInputSlot = {
|
|
131
|
+
type: 'email-input';
|
|
132
|
+
key: string;
|
|
133
|
+
label: string;
|
|
134
|
+
placeholder: string;
|
|
135
|
+
invalidMessage: string;
|
|
136
|
+
requiredMessage: string;
|
|
137
|
+
};
|
|
138
|
+
/** A Form field written to an existing device tag of any type; `tagName` '' = the value is not sent. */
|
|
139
|
+
export type WebPopupTagInputSlot = {
|
|
140
|
+
type: 'tag-input';
|
|
141
|
+
key: string;
|
|
142
|
+
tagName: string;
|
|
143
|
+
label: string;
|
|
144
|
+
placeholder: string;
|
|
145
|
+
required: boolean;
|
|
146
|
+
requiredMessage: string;
|
|
147
|
+
};
|
|
148
|
+
/** A Form's required privacy-policy checkbox; `url` renders through safeUrl. */
|
|
149
|
+
export type WebPopupConsentSlot = {
|
|
150
|
+
type: 'consent';
|
|
151
|
+
key: string;
|
|
152
|
+
checkboxLabel: string;
|
|
153
|
+
linkLabel: string;
|
|
154
|
+
url: string;
|
|
155
|
+
requiredMessage: string;
|
|
156
|
+
};
|
|
157
|
+
/** Sends every Form field of the popup at once; `errorMessage` covers network and server refusals. */
|
|
158
|
+
export type WebPopupSubmitSlot = {
|
|
159
|
+
type: 'submit';
|
|
160
|
+
key: string;
|
|
161
|
+
variant: WebPopupButtonVariant;
|
|
162
|
+
label: string;
|
|
163
|
+
errorMessage: string;
|
|
164
|
+
};
|
|
129
165
|
/** One entry of a page's content stack, in display order. */
|
|
130
166
|
export type WebPopupSlot = {
|
|
131
167
|
type: 'text';
|
|
@@ -164,7 +200,7 @@ export type WebPopupSlot = {
|
|
|
164
200
|
successMessage: string;
|
|
165
201
|
/** Replaces the form after the double-opt-in confirm-email result. */
|
|
166
202
|
confirmEmailMessage: string;
|
|
167
|
-
} | WebPopupTimerSlot | WebPopupChoiceSlot | WebPopupRatingSlot | WebPopupGlyphSlot;
|
|
203
|
+
} | WebPopupTimerSlot | WebPopupChoiceSlot | WebPopupRatingSlot | WebPopupGlyphSlot | WebPopupEmailInputSlot | WebPopupTagInputSlot | WebPopupConsentSlot | WebPopupSubmitSlot;
|
|
168
204
|
/** What a media param plays instead of drawing its image; the param's `src` stays the poster, so engines predating video degrade to it. */
|
|
169
205
|
export type WebPopupVideo = {
|
|
170
206
|
/** Video url, rendered through safeUrl like every popup link. */
|
|
@@ -473,6 +509,8 @@ export type WebPopupPageParams = {
|
|
|
473
509
|
/** See `width`; auto height = grow with content, a number = fixed
|
|
474
510
|
* (scrolls), 'stretch' = fill the viewport height. */
|
|
475
511
|
height?: number | 'stretch' | null;
|
|
512
|
+
/** 'success' = the page a Form opens after an accepted submit; absent = an ordinary page. */
|
|
513
|
+
role?: 'success';
|
|
476
514
|
};
|
|
477
515
|
export type WebPopupParams = WebPopupChrome & {
|
|
478
516
|
/** The pages, in order; at least one. Only one shows at a time. */
|
|
@@ -522,6 +560,8 @@ export type WebPopupResolvedPage = {
|
|
|
522
560
|
/** Final box height: px, or 'stretch' = fill the viewport height; absent =
|
|
523
561
|
* grow with content. */
|
|
524
562
|
height?: number | 'stretch';
|
|
563
|
+
/** 'success' = the page a Form opens after an accepted submit; absent = an ordinary page. */
|
|
564
|
+
role?: 'success';
|
|
525
565
|
};
|
|
526
566
|
/** The stored format — PopupFormContent.json parses into this. */
|
|
527
567
|
export type WebPopupJson = {
|
|
@@ -561,6 +601,18 @@ export type WebPopupFormSubmitResult = 'subscribed' | 'confirm-email' | 'already
|
|
|
561
601
|
* network/server failure — the slot shows a generic retryable error.
|
|
562
602
|
*/
|
|
563
603
|
export type WebPopupFormSubmitHandler = (formCode: string, payload: WebPopupFormSubmitPayload) => Promise<WebPopupFormSubmitResult>;
|
|
604
|
+
/** What a Form submits: the email (only when the Form has an Email input) and tag values from every page. */
|
|
605
|
+
export type WebPopupFormValues = {
|
|
606
|
+
email?: string;
|
|
607
|
+
/** tagName → trimmed value; empty fields are left out. */
|
|
608
|
+
tags: Record<string, unknown>;
|
|
609
|
+
/** True when the Form has no Consent. */
|
|
610
|
+
policyAccepted: boolean;
|
|
611
|
+
};
|
|
612
|
+
/** 'ok' opens the Success page; 'invalid-email' shows the Email input's invalidMessage. */
|
|
613
|
+
export type WebPopupFormValuesSubmitResult = 'ok' | 'invalid-email';
|
|
614
|
+
/** Sends a Form's values; a rejection shows the Submit errorMessage and leaves the Form retryable. */
|
|
615
|
+
export type WebPopupFormValuesSubmitHandler = (values: WebPopupFormValues) => Promise<WebPopupFormValuesSubmitResult>;
|
|
564
616
|
/** What a `choice` slot submits: the picked options' tag values, in option order. */
|
|
565
617
|
export type WebPopupChoiceSubmitPayload = {
|
|
566
618
|
slotKey: string;
|
|
@@ -608,6 +660,8 @@ export type WebPopupReaderProps = {
|
|
|
608
660
|
onRequestClose?: () => void;
|
|
609
661
|
/** Form-slot submits; absent = form slots render inert (previews, editor). */
|
|
610
662
|
onSubmitForm?: WebPopupFormSubmitHandler;
|
|
663
|
+
/** Form (FORM content) submits; absent = the fields take input, but nothing validates, advances or submits. */
|
|
664
|
+
onSubmitFormValues?: WebPopupFormValuesSubmitHandler;
|
|
611
665
|
/** Choice-slot submits; absent = choice slots render inert. */
|
|
612
666
|
onSubmitChoice?: WebPopupChoiceSubmitHandler;
|
|
613
667
|
/** Rating-slot submits; absent = rating slots render inert. */
|
|
@@ -651,6 +705,8 @@ export type WebPopupBoxProps = {
|
|
|
651
705
|
onPageChange?: (page: string) => void;
|
|
652
706
|
/** Form-slot submits; absent = form slots render inert (previews, editor). */
|
|
653
707
|
onSubmitForm?: WebPopupFormSubmitHandler;
|
|
708
|
+
/** Form (FORM content) submits; absent = the fields take input, but nothing validates, advances or submits. */
|
|
709
|
+
onSubmitFormValues?: WebPopupFormValuesSubmitHandler;
|
|
654
710
|
/** Choice-slot submits; absent = choice slots render inert. */
|
|
655
711
|
onSubmitChoice?: WebPopupChoiceSubmitHandler;
|
|
656
712
|
/** Rating-slot submits; absent = rating slots render inert. */
|
|
@@ -667,6 +723,8 @@ export type WebPopupInlineProps = {
|
|
|
667
723
|
colorScheme?: WebPopupColorSchemePref;
|
|
668
724
|
/** Form-slot submits; absent = form slots render inert. */
|
|
669
725
|
onSubmitForm?: WebPopupFormSubmitHandler;
|
|
726
|
+
/** Form (FORM content) submits; absent = the fields take input, but nothing validates, advances or submits. */
|
|
727
|
+
onSubmitFormValues?: WebPopupFormValuesSubmitHandler;
|
|
670
728
|
/** Choice-slot submits; absent = choice slots render inert. */
|
|
671
729
|
onSubmitChoice?: WebPopupChoiceSubmitHandler;
|
|
672
730
|
/** Rating-slot submits; absent = rating slots render inert. */
|