@pushwoosh/websdk-common 6.21.0 → 6.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/package.json +1 -1
  2. package/web-popups/WebPopupInline.d.ts +1 -1
  3. package/web-popups/WebPopupInline.js +2 -0
  4. package/web-popups/WebPopupReader.d.ts +2 -2
  5. package/web-popups/WebPopupReader.js +56 -22
  6. package/web-popups/constants.d.ts +20 -0
  7. package/web-popups/constants.js +20 -0
  8. package/web-popups/form-slots/ConsentSlotView/ConsentSlotView.d.ts +3 -0
  9. package/web-popups/form-slots/ConsentSlotView/ConsentSlotView.js +42 -0
  10. package/web-popups/form-slots/ConsentSlotView/index.d.ts +2 -0
  11. package/web-popups/form-slots/ConsentSlotView/index.js +1 -0
  12. package/web-popups/form-slots/ConsentSlotView/styles.d.ts +6 -0
  13. package/web-popups/form-slots/ConsentSlotView/styles.js +19 -0
  14. package/web-popups/form-slots/ConsentSlotView/types.d.ts +5 -0
  15. package/web-popups/form-slots/ConsentSlotView/types.js +1 -0
  16. package/web-popups/form-slots/EmailInputSlotView/EmailInputSlotView.d.ts +3 -0
  17. package/web-popups/form-slots/EmailInputSlotView/EmailInputSlotView.js +16 -0
  18. package/web-popups/form-slots/EmailInputSlotView/index.d.ts +2 -0
  19. package/web-popups/form-slots/EmailInputSlotView/index.js +1 -0
  20. package/web-popups/form-slots/EmailInputSlotView/types.d.ts +5 -0
  21. package/web-popups/form-slots/EmailInputSlotView/types.js +1 -0
  22. package/web-popups/form-slots/SubmitSlotView/SubmitSlotView.d.ts +3 -0
  23. package/web-popups/form-slots/SubmitSlotView/SubmitSlotView.js +30 -0
  24. package/web-popups/form-slots/SubmitSlotView/index.d.ts +2 -0
  25. package/web-popups/form-slots/SubmitSlotView/index.js +1 -0
  26. package/web-popups/form-slots/SubmitSlotView/styles.d.ts +4 -0
  27. package/web-popups/form-slots/SubmitSlotView/styles.js +13 -0
  28. package/web-popups/form-slots/SubmitSlotView/types.d.ts +6 -0
  29. package/web-popups/form-slots/SubmitSlotView/types.js +1 -0
  30. package/web-popups/form-slots/TagInputSlotView/TagInputSlotView.d.ts +3 -0
  31. package/web-popups/form-slots/TagInputSlotView/TagInputSlotView.js +15 -0
  32. package/web-popups/form-slots/TagInputSlotView/index.d.ts +2 -0
  33. package/web-popups/form-slots/TagInputSlotView/index.js +1 -0
  34. package/web-popups/form-slots/TagInputSlotView/types.d.ts +5 -0
  35. package/web-popups/form-slots/TagInputSlotView/types.js +1 -0
  36. package/web-popups/form-slots/TextFieldView/TextFieldView.d.ts +3 -0
  37. package/web-popups/form-slots/TextFieldView/TextFieldView.js +46 -0
  38. package/web-popups/form-slots/TextFieldView/index.d.ts +2 -0
  39. package/web-popups/form-slots/TextFieldView/index.js +1 -0
  40. package/web-popups/form-slots/TextFieldView/styles.d.ts +3 -0
  41. package/web-popups/form-slots/TextFieldView/styles.js +7 -0
  42. package/web-popups/form-slots/TextFieldView/types.d.ts +9 -0
  43. package/web-popups/form-slots/TextFieldView/types.js +1 -0
  44. package/web-popups/form-slots/index.d.ts +4 -0
  45. package/web-popups/form-slots/index.js +4 -0
  46. package/web-popups/form-slots/styles.d.ts +6 -0
  47. package/web-popups/form-slots/styles.js +25 -0
  48. package/web-popups/form-slots/types.d.ts +6 -0
  49. package/web-popups/form-slots/types.js +1 -0
  50. package/web-popups/form.d.ts +24 -0
  51. package/web-popups/form.js +74 -0
  52. package/web-popups/formSession.d.ts +23 -0
  53. package/web-popups/formSession.js +117 -0
  54. package/web-popups/helpers.js +48 -1
  55. package/web-popups/index.d.ts +3 -2
  56. package/web-popups/index.js +2 -1
  57. 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.21.0",
3
+ "version": "6.22.1",
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: () => onPageChange(target),
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 && !FORM_EMAIL_PATTERN.test(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("div", {
1211
- style: pageStyle,
1212
- children: _jsx(LayoutNodeView, {
1213
- node: page.layout,
1214
- page: page,
1215
- colors: colors,
1216
- mode: mode,
1217
- scheme: colors.scheme,
1218
- leaf: leafRenderers,
1219
- onRequestClose: onRequestClose,
1220
- onPageChange: onPageChange ?? (() => {}),
1221
- onSubmitForm: onSubmitForm,
1222
- onSubmitChoice: onSubmitChoice,
1223
- onSubmitRating: onSubmitRating,
1224
- onRequestSubscribe: onRequestSubscribe
1225
- })
1226
- }, page.key)
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;
@@ -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,3 @@
1
+ import { type ConsentSlotViewProps } from './types';
2
+ /** A Form's Consent checkbox with its policy link. */
3
+ export declare function ConsentSlotView({ slot, ...look }: ConsentSlotViewProps): import("react").JSX.Element;
@@ -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,2 @@
1
+ export { ConsentSlotView } from './ConsentSlotView';
2
+ export type { ConsentSlotViewProps } from './types';
@@ -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,5 @@
1
+ import { type WebPopupConsentSlot } from '../../types';
2
+ import { type FieldLook } from '../types';
3
+ export type ConsentSlotViewProps = FieldLook & {
4
+ slot: WebPopupConsentSlot;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type EmailInputSlotViewProps } from './types';
2
+ /** A Form's Email input, drawn the runtime's way. */
3
+ export declare function EmailInputSlotView({ slot, ...look }: EmailInputSlotViewProps): import("react").JSX.Element;
@@ -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,2 @@
1
+ export { EmailInputSlotView } from './EmailInputSlotView';
2
+ export type { EmailInputSlotViewProps } from './types';
@@ -0,0 +1 @@
1
+ export { EmailInputSlotView } from './EmailInputSlotView';
@@ -0,0 +1,5 @@
1
+ import { type WebPopupEmailInputSlot } from '../../types';
2
+ import { type FieldLook } from '../types';
3
+ export type EmailInputSlotViewProps = FieldLook & {
4
+ slot: WebPopupEmailInputSlot;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type SubmitSlotViewProps } from './types';
2
+ /** A Form's Submit: sends every field of the popup; shows errorMessage after a refusal. */
3
+ export declare function SubmitSlotView({ slot, align, colors }: SubmitSlotViewProps): import("react").JSX.Element;
@@ -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,2 @@
1
+ export { SubmitSlotView } from './SubmitSlotView';
2
+ export type { SubmitSlotViewProps } from './types';
@@ -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,6 @@
1
+ import { type WebPopupResolvedColors, type WebPopupSubmitSlot, type WebPopupTextAlign } from '../../types';
2
+ export type SubmitSlotViewProps = {
3
+ slot: WebPopupSubmitSlot;
4
+ align: WebPopupTextAlign;
5
+ colors: WebPopupResolvedColors;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type TagInputSlotViewProps } from './types';
2
+ /** A Form's Tag input, drawn the runtime's way. */
3
+ export declare function TagInputSlotView({ slot, ...look }: TagInputSlotViewProps): import("react").JSX.Element;
@@ -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,2 @@
1
+ export { TagInputSlotView } from './TagInputSlotView';
2
+ export type { TagInputSlotViewProps } from './types';
@@ -0,0 +1 @@
1
+ export { TagInputSlotView } from './TagInputSlotView';
@@ -0,0 +1,5 @@
1
+ import { type WebPopupTagInputSlot } from '../../types';
2
+ import { type FieldLook } from '../types';
3
+ export type TagInputSlotViewProps = FieldLook & {
4
+ slot: WebPopupTagInputSlot;
5
+ };
@@ -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,2 @@
1
+ export { TextFieldView } from './TextFieldView';
2
+ export type { TextFieldViewProps } from './types';
@@ -0,0 +1 @@
1
+ export { TextFieldView } from './TextFieldView';
@@ -0,0 +1,3 @@
1
+ import { type CSSProperties } from 'react';
2
+ import { type FieldLook } from '../types';
3
+ export declare function labelStyle(look: FieldLook): CSSProperties;
@@ -0,0 +1,7 @@
1
+ import { captionStyle } from '../styles';
2
+ export function labelStyle(look) {
3
+ return {
4
+ ...captionStyle(look),
5
+ paddingBottom: 4
6
+ };
7
+ }
@@ -0,0 +1,9 @@
1
+ import { type FieldLook } from '../types';
2
+ export type TextFieldViewProps = {
3
+ slotKey: string;
4
+ label: string;
5
+ placeholder: string;
6
+ inputType: 'email' | 'text';
7
+ autoComplete?: string;
8
+ look: FieldLook;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export { ConsentSlotView } from './ConsentSlotView';
2
+ export { EmailInputSlotView } from './EmailInputSlotView';
3
+ export { SubmitSlotView } from './SubmitSlotView';
4
+ export { TagInputSlotView } from './TagInputSlotView';
@@ -0,0 +1,4 @@
1
+ export { ConsentSlotView } from './ConsentSlotView';
2
+ export { EmailInputSlotView } from './EmailInputSlotView';
3
+ export { SubmitSlotView } from './SubmitSlotView';
4
+ export { TagInputSlotView } from './TagInputSlotView';
@@ -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,6 @@
1
+ import { type WebPopupResolvedColors } from '../types';
2
+ /** How a Form field reads its zone: tone and the resolved palette. */
3
+ export type FieldLook = {
4
+ inverse: boolean;
5
+ colors: WebPopupResolvedColors;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { type WebPopupConsentSlot, type WebPopupEmailInputSlot, type WebPopupFormValues, type WebPopupParams, type WebPopupResolvedPage, type WebPopupTagInputSlot } from './types';
2
+ type WebPopupFormFieldSlot = WebPopupEmailInputSlot | WebPopupTagInputSlot | WebPopupConsentSlot;
3
+ /** A Form field with the page it sits on; `id` is unique across the popup. */
4
+ export type WebPopupFormFieldEntry = {
5
+ id: string;
6
+ pageKey: string;
7
+ slot: WebPopupFormFieldSlot;
8
+ };
9
+ /** What the visitor has entered so far, by field id. */
10
+ export type WebPopupFormInput = {
11
+ texts: Record<string, string>;
12
+ checks: Record<string, boolean>;
13
+ };
14
+ /** A field id: slot keys are unique within a page, not across pages. */
15
+ export declare function webPopupFormFieldId(pageKey: string, slotKey: string): string;
16
+ /** Every Form field of the popup, in page and stack order. */
17
+ export declare function collectWebPopupFormFields(pages: WebPopupResolvedPage[]): WebPopupFormFieldEntry[];
18
+ /** Does any page carry a FORM slot (`email-input`, `tag-input`, `consent`, `submit`)? */
19
+ export declare function webPopupHasForm(params: WebPopupParams): boolean;
20
+ /** The block text of every field that blocks a submit, by field id; empty = the Form can be sent. */
21
+ export declare function validateWebPopupForm(fields: WebPopupFormFieldEntry[], input: WebPopupFormInput): Record<string, string>;
22
+ /** The values a valid Form submits (contracts §10). */
23
+ export declare function webPopupFormValues(fields: WebPopupFormFieldEntry[], input: WebPopupFormInput): WebPopupFormValues;
24
+ export {};
@@ -0,0 +1,74 @@
1
+ import { WEB_POPUP_EMAIL_PATTERN } from './constants';
2
+ import { resolveWebPopupPages } from './helpers';
3
+ const FORM_FIELD_SLOT_TYPES = new Set(['email-input', 'tag-input', 'consent']);
4
+ const FORM_SLOT_TYPES = new Set([...FORM_FIELD_SLOT_TYPES, 'submit']);
5
+ function isFormFieldSlot(slot) {
6
+ return FORM_FIELD_SLOT_TYPES.has(slot.type);
7
+ }
8
+ /** A field id: slot keys are unique within a page, not across pages. */
9
+ export function webPopupFormFieldId(pageKey, slotKey) {
10
+ return `${pageKey}/${slotKey}`;
11
+ }
12
+ /** Every Form field of the popup, in page and stack order. */
13
+ export function collectWebPopupFormFields(pages) {
14
+ const out = [];
15
+ for (const page of pages) {
16
+ for (const zone of page.contents) {
17
+ for (const slot of zone.slots) {
18
+ if (!isFormFieldSlot(slot)) continue;
19
+ out.push({
20
+ id: webPopupFormFieldId(page.key, slot.key),
21
+ pageKey: page.key,
22
+ slot
23
+ });
24
+ }
25
+ }
26
+ }
27
+ return out;
28
+ }
29
+ /** Does any page carry a FORM slot (`email-input`, `tag-input`, `consent`, `submit`)? */
30
+ export function webPopupHasForm(params) {
31
+ return resolveWebPopupPages(params).some(page => page.contents.some(zone => zone.slots.some(slot => FORM_SLOT_TYPES.has(slot.type))));
32
+ }
33
+ function fieldError(field, input) {
34
+ const {
35
+ slot
36
+ } = field;
37
+ if (slot.type === 'consent') return input.checks[field.id] ? undefined : slot.requiredMessage;
38
+ const value = (input.texts[field.id] ?? '').trim();
39
+ if (slot.type === 'tag-input') return slot.required && !value ? slot.requiredMessage : undefined;
40
+ if (!value) return slot.requiredMessage;
41
+ return WEB_POPUP_EMAIL_PATTERN.test(value) ? undefined : slot.invalidMessage;
42
+ }
43
+ /** The block text of every field that blocks a submit, by field id; empty = the Form can be sent. */
44
+ export function validateWebPopupForm(fields, input) {
45
+ const errors = {};
46
+ for (const field of fields) {
47
+ const error = fieldError(field, input);
48
+ if (error) errors[field.id] = error;
49
+ }
50
+ return errors;
51
+ }
52
+ /** The values a valid Form submits (contracts §10). */
53
+ export function webPopupFormValues(fields, input) {
54
+ const values = {
55
+ tags: {},
56
+ policyAccepted: true
57
+ };
58
+ for (const field of fields) {
59
+ const {
60
+ slot
61
+ } = field;
62
+ if (slot.type === 'consent') {
63
+ values.policyAccepted = values.policyAccepted && input.checks[field.id] === true;
64
+ continue;
65
+ }
66
+ const value = (input.texts[field.id] ?? '').trim();
67
+ if (slot.type === 'email-input') {
68
+ values.email = value;
69
+ continue;
70
+ }
71
+ if (value && slot.tagName) values.tags[slot.tagName] = value;
72
+ }
73
+ return values;
74
+ }
@@ -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
+ }
@@ -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
  }
@@ -2,9 +2,10 @@ export { WebPopupReader, WebPopupBox, WebPopupSlotView } from './WebPopupReader'
2
2
  export { WebPopupInline } from './WebPopupInline';
3
3
  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
+ export { webPopupHasForm } from './form';
5
6
  export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs, type WebPopupTimerLabels, } from './timer';
6
7
  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';
8
+ 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
9
  export { resolveWebPopupBoxChrome, resolveWebPopupColors, autoDarkWebPopupColors, webPopupColorAlpha, webPopupDarkColors, webPopupDarkEnabled, webPopupEffectiveScheme, webPopupImageSrc, webPopupMixColor, webPopupShiftColor, } from './palette';
9
10
  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';
11
+ 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';
@@ -2,8 +2,9 @@ export { WebPopupReader, WebPopupBox, WebPopupSlotView } from './WebPopupReader'
2
2
  export { WebPopupInline } from './WebPopupInline';
3
3
  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
+ export { webPopupHasForm } from './form';
5
6
  export { webPopupTimerLabels, webPopupTimerRemaining, webPopupTimeZoneSupported, webPopupWallClockMs } from './timer';
6
7
  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';
8
+ 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
9
  export { resolveWebPopupBoxChrome, resolveWebPopupColors, autoDarkWebPopupColors, webPopupColorAlpha, webPopupDarkColors, webPopupDarkEnabled, webPopupEffectiveScheme, webPopupImageSrc, webPopupMixColor, webPopupShiftColor } from './palette';
9
10
  export { WEB_POPUP_GLYPH_NAMES, WEB_POPUP_GLYPH_PATHS, WEB_POPUP_GLYPH_SIZES, WEB_POPUP_THUMB_UP_PATH } from './glyphs';
@@ -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. */