@pushwoosh/dumb-components 4.18.3 → 4.20.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.
Files changed (33) hide show
  1. package/AppScreenPlaceholder/AppScreenPlaceholder.d.ts +7 -0
  2. package/AppScreenPlaceholder/AppScreenPlaceholder.js +29 -0
  3. package/AppScreenPlaceholder/constants.d.ts +20 -0
  4. package/AppScreenPlaceholder/constants.js +37 -0
  5. package/AppScreenPlaceholder/index.d.ts +2 -0
  6. package/AppScreenPlaceholder/index.js +1 -0
  7. package/AppScreenPlaceholder/types.d.ts +10 -0
  8. package/AppScreenPlaceholder/types.js +1 -0
  9. package/InlineBannerPreview/InlineBannerPreview.d.ts +7 -0
  10. package/InlineBannerPreview/InlineBannerPreview.js +43 -0
  11. package/InlineBannerPreview/constants.d.ts +5 -0
  12. package/InlineBannerPreview/constants.js +5 -0
  13. package/InlineBannerPreview/index.d.ts +2 -0
  14. package/InlineBannerPreview/index.js +1 -0
  15. package/InlineBannerPreview/styles.d.ts +2 -0
  16. package/InlineBannerPreview/styles.js +7 -0
  17. package/InlineBannerPreview/types.d.ts +7 -0
  18. package/InlineBannerPreview/types.js +1 -0
  19. package/RichMessageEditor/RichMessageEditor.helpers.d.ts +5 -2
  20. package/RichMessageEditor/RichMessageEditor.helpers.js +31 -0
  21. package/RichMessageEditor/RichMessageEditor.js +36 -58
  22. package/RichMessageEditor/RichMessageEditorDrop.d.ts +12 -0
  23. package/RichMessageEditor/RichMessageEditorDrop.js +52 -0
  24. package/RichmediaPreview/RichmediaPreview.js +18 -7
  25. package/RichmediaPreview/types.d.ts +2 -0
  26. package/SandboxedHtmlFrame/SandboxedHtmlFrame.d.ts +2 -1
  27. package/SandboxedHtmlFrame/SandboxedHtmlFrame.js +21 -2
  28. package/SandboxedHtmlFrame/constants.d.ts +7 -0
  29. package/SandboxedHtmlFrame/constants.js +64 -0
  30. package/SandboxedHtmlFrame/types.d.ts +6 -0
  31. package/index.d.ts +2 -0
  32. package/index.js +2 -0
  33. package/package.json +2 -2
@@ -0,0 +1,7 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { AppScreenPlaceholderProps } from './types';
3
+ /**
4
+ * Stand-in for the content of an app screen around an inline banner slot: bars of text and blocks.
5
+ * Render one above the slot (`side="top"`) and one below it (`side="bottom"`).
6
+ */
7
+ export declare function AppScreenPlaceholder({ side, size }: AppScreenPlaceholderProps): ReactElement;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Color } from '@pushwoosh/kit-constants';
3
+ import { Vertical } from '@pushwoosh/kit-helpers';
4
+ import { BARS, SIZES } from './constants';
5
+ /**
6
+ * Stand-in for the content of an app screen around an inline banner slot: bars of text and blocks.
7
+ * Render one above the slot (`side="top"`) and one below it (`side="bottom"`).
8
+ */
9
+ export function AppScreenPlaceholder({
10
+ side,
11
+ size
12
+ }) {
13
+ const metrics = SIZES[size];
14
+ return _jsx(Vertical, {
15
+ "$gap": metrics.gap,
16
+ "aria-hidden": true,
17
+ children: BARS[side].map(({
18
+ kind,
19
+ width
20
+ }, index) => _jsx(Vertical
21
+ // eslint-disable-next-line react/no-array-index-key
22
+ , {
23
+ "$width": width,
24
+ "$height": metrics[kind],
25
+ "$borderRadius": kind === 'block' ? metrics.blockRadius : metrics.lineRadius,
26
+ "$bgColor": Color.SOFT_LIGHT
27
+ }, index))
28
+ });
29
+ }
@@ -0,0 +1,20 @@
1
+ import type { AppScreenPlaceholderBar } from './types';
2
+ export declare const SIZES: {
3
+ small: {
4
+ gap: number;
5
+ title: number;
6
+ line: number;
7
+ block: number;
8
+ lineRadius: number;
9
+ blockRadius: number;
10
+ };
11
+ large: {
12
+ gap: number;
13
+ title: number;
14
+ line: number;
15
+ block: number;
16
+ lineRadius: number;
17
+ blockRadius: number;
18
+ };
19
+ };
20
+ export declare const BARS: Record<'top' | 'bottom', AppScreenPlaceholderBar[]>;
@@ -0,0 +1,37 @@
1
+ export const SIZES = {
2
+ small: {
3
+ gap: 8,
4
+ title: 14,
5
+ line: 8,
6
+ block: 70,
7
+ lineRadius: 4,
8
+ blockRadius: 8
9
+ },
10
+ large: {
11
+ gap: 12,
12
+ title: 22,
13
+ line: 13,
14
+ block: 104,
15
+ lineRadius: 6,
16
+ blockRadius: 12
17
+ }
18
+ };
19
+ export const BARS = {
20
+ top: [{
21
+ kind: 'title',
22
+ width: '50%'
23
+ }, {
24
+ kind: 'line',
25
+ width: '80%'
26
+ }],
27
+ bottom: [{
28
+ kind: 'line'
29
+ }, {
30
+ kind: 'line',
31
+ width: '70%'
32
+ }, {
33
+ kind: 'block'
34
+ }, {
35
+ kind: 'block'
36
+ }]
37
+ };
@@ -0,0 +1,2 @@
1
+ export { AppScreenPlaceholder } from './AppScreenPlaceholder';
2
+ export type { AppScreenPlaceholderProps } from './types';
@@ -0,0 +1 @@
1
+ export { AppScreenPlaceholder } from './AppScreenPlaceholder';
@@ -0,0 +1,10 @@
1
+ export interface AppScreenPlaceholderProps {
2
+ /** Which part of the screen to stand in for: the content above the slot or below it. */
3
+ side: 'top' | 'bottom';
4
+ /** `small` fits a phone preview, `large` a full-width canvas. */
5
+ size: 'small' | 'large';
6
+ }
7
+ export type AppScreenPlaceholderBar = {
8
+ kind: 'title' | 'line' | 'block';
9
+ width?: string;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { InlineBannerPreviewProps } from './types';
3
+ /**
4
+ * Inline banner in a slot of an app screen: the banner, as tall as its content, between two
5
+ * {@link AppScreenPlaceholder}. The HTML runs in an isolated {@link SandboxedHtmlFrame}.
6
+ */
7
+ export declare function InlineBannerPreview({ html, title }: InlineBannerPreviewProps): ReactElement;
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Color } from '@pushwoosh/kit-constants';
4
+ import { Vertical } from '@pushwoosh/kit-helpers';
5
+ import { AppScreenPlaceholder } from '../AppScreenPlaceholder';
6
+ import { SLOT_MIN_HEIGHT, SLOT_SCALE, SLOT_VIEWPORT_HEIGHT } from './constants';
7
+ import { SlotFrame } from './styles';
8
+ /**
9
+ * Inline banner in a slot of an app screen: the banner, as tall as its content, between two
10
+ * {@link AppScreenPlaceholder}. The HTML runs in an isolated {@link SandboxedHtmlFrame}.
11
+ */
12
+ export function InlineBannerPreview({
13
+ html,
14
+ title
15
+ }) {
16
+ const [contentHeight, setContentHeight] = useState(0);
17
+ return _jsxs(Vertical, {
18
+ "$gap": 16,
19
+ children: [_jsx(AppScreenPlaceholder, {
20
+ side: "top",
21
+ size: "small"
22
+ }), _jsx(Vertical, {
23
+ "$border": `1px solid ${Color.FORM}`,
24
+ "$borderRadius": 12,
25
+ "$bgColor": Color.CLEAR,
26
+ "$overflow": "hidden",
27
+ children: _jsx(Vertical, {
28
+ "$position": "relative",
29
+ "$height": Math.min(contentHeight, SLOT_VIEWPORT_HEIGHT) * SLOT_SCALE,
30
+ "$minHeight": SLOT_MIN_HEIGHT,
31
+ children: _jsx(SlotFrame, {
32
+ mode: "isolated",
33
+ title: title,
34
+ html: html,
35
+ onContentHeight: setContentHeight
36
+ })
37
+ })
38
+ }), _jsx(AppScreenPlaceholder, {
39
+ side: "bottom",
40
+ size: "small"
41
+ })]
42
+ });
43
+ }
@@ -0,0 +1,5 @@
1
+ export declare const SLOT_SCALE = 0.5;
2
+ /** Height of the frame viewport: like the SDK, the banner shows its top part up to it. */
3
+ export declare const SLOT_VIEWPORT_HEIGHT = 800;
4
+ /** A frame clipped to nothing is not rendered by the browser and never reports its height: the slot always shows a strip of it. */
5
+ export declare const SLOT_MIN_HEIGHT = 1;
@@ -0,0 +1,5 @@
1
+ export const SLOT_SCALE = 0.5;
2
+ /** Height of the frame viewport: like the SDK, the banner shows its top part up to it. */
3
+ export const SLOT_VIEWPORT_HEIGHT = 800;
4
+ /** A frame clipped to nothing is not rendered by the browser and never reports its height: the slot always shows a strip of it. */
5
+ export const SLOT_MIN_HEIGHT = 1;
@@ -0,0 +1,2 @@
1
+ export { InlineBannerPreview } from './InlineBannerPreview';
2
+ export type { InlineBannerPreviewProps } from './types';
@@ -0,0 +1 @@
1
+ export { InlineBannerPreview } from './InlineBannerPreview';
@@ -0,0 +1,2 @@
1
+ import { SandboxedHtmlFrame } from '../SandboxedHtmlFrame';
2
+ export declare const SlotFrame: import("styled-components/dist/types").IStyledComponentBase<"web", import("..").SandboxedHtmlFrameProps & import("styled-components/dist/types").BaseObject> & string & Omit<typeof SandboxedHtmlFrame, keyof import("react").Component<any, {}, any>>;
@@ -0,0 +1,7 @@
1
+ import styled from 'styled-components';
2
+ import { SandboxedHtmlFrame } from '../SandboxedHtmlFrame';
3
+ import { SLOT_SCALE, SLOT_VIEWPORT_HEIGHT } from './constants';
4
+ export const SlotFrame = styled(SandboxedHtmlFrame).withConfig({
5
+ displayName: "SlotFrame",
6
+ componentId: "sc-1of1618-0"
7
+ })(["position:absolute;top:0;left:0;width:", "%;height:", "px;border:0;transform:scale(", ");transform-origin:0 0;"], 100 / SLOT_SCALE, SLOT_VIEWPORT_HEIGHT, SLOT_SCALE);
@@ -0,0 +1,7 @@
1
+ /** Props of {@link InlineBannerPreview}. */
2
+ export interface InlineBannerPreviewProps {
3
+ /** Untrusted HTML of the banner. */
4
+ html: string;
5
+ /** Accessible title of the banner frame. */
6
+ title: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,6 @@
1
- import { type Placement } from '@floating-ui/react-dom';
2
- import { type ArrowDirection } from './RichMessageEditor.types';
1
+ import { type Placement, type ReferenceElement } from '@floating-ui/react-dom';
2
+ import { type ArrowDirection, type DropValue } from './RichMessageEditor.types';
3
+ import { type CustomEditor } from './slate/custom-types';
3
4
  export declare function placementToDirection(placement: Placement): ArrowDirection;
5
+ /** Element the drop is positioned against: the edited chip, the emoji action or the caret where a new chip goes. */
6
+ export declare function getDropAnchor(editor: CustomEditor, drop: DropValue, box: HTMLElement, emojiAction: HTMLElement | null): ReferenceElement;
@@ -1,3 +1,5 @@
1
+ import { Node as SlateNode } from 'slate';
2
+ import { ReactEditor } from 'slate-react';
1
3
  export function placementToDirection(placement) {
2
4
  if (placement.startsWith('left')) {
3
5
  return 'right';
@@ -9,4 +11,33 @@ export function placementToDirection(placement) {
9
11
  return 'bottom';
10
12
  }
11
13
  return 'top';
14
+ }
15
+ function attempt(read) {
16
+ try {
17
+ return read();
18
+ } catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ function caretReference(editor, box) {
23
+ return {
24
+ contextElement: box,
25
+ getBoundingClientRect: () => {
26
+ const {
27
+ selection
28
+ } = editor;
29
+ const rect = selection ? attempt(() => ReactEditor.toDOMRange(editor, selection).getBoundingClientRect()) : undefined;
30
+ return rect && rect.height > 0 ? rect : box.getBoundingClientRect();
31
+ }
32
+ };
33
+ }
34
+ function nodeReference(editor, path, box) {
35
+ return attempt(() => ReactEditor.toDOMNode(editor, SlateNode.get(editor, path))) ?? box;
36
+ }
37
+ /** Element the drop is positioned against: the edited chip, the emoji action or the caret where a new chip goes. */
38
+ export function getDropAnchor(editor, drop, box, emojiAction) {
39
+ if (drop.type === 'emoji') {
40
+ return emojiAction ?? box;
41
+ }
42
+ return drop.path ? nodeReference(editor, drop.path, box) : caretReference(editor, box);
12
43
  }
@@ -1,18 +1,16 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { arrow, autoPlacement, offset, useFloating } from '@floating-ui/react-dom';
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
2
  import { isEqual } from 'es-toolkit';
4
3
  import { useEffect, useState } from 'react';
5
4
  import { Transforms } from 'slate';
6
5
  import { Collapse, elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
7
6
  import { FieldBox } from '../FieldBox';
8
- import ArrowIcon from './assets/arrow.svg';
9
7
  import EmojiIcon from './assets/EmojiIcon.svg';
10
8
  import PersonalizationIcon from './assets/PersonalizationIcon.svg';
11
9
  import { EditorEmojiPicker } from './EditorEmojiPicker';
12
- import { placementToDirection } from './RichMessageEditor.helpers';
10
+ import { RichMessageEditorDrop } from './RichMessageEditorDrop';
13
11
  import { getDcByPath } from './slate/helpers';
14
12
  import { SlateEditable, SlateEditor } from './slate/SlateEditor';
15
- import { Arrow, DropArea, DropContent, ImSpan } from './styles';
13
+ import { DropContent, ImSpan } from './styles';
16
14
  /**
17
15
  * Slate-based message editor with optional personalization (dynamic-content) tokens
18
16
  * and an emoji picker; serializes to a string via `onChange`. Render the result with
@@ -38,25 +36,8 @@ export const RichMessageEditor = ({
38
36
  }) => {
39
37
  const [showDrop, setShowDrop] = useState();
40
38
  const [isFocused, setIsFocused] = useState(false);
41
- const [arrowElement, setArrowElement] = useState(null);
42
- const {
43
- refs: {
44
- reference,
45
- setReference,
46
- setFloating
47
- },
48
- floatingStyles,
49
- update,
50
- middlewareData,
51
- placement
52
- } = useFloating({
53
- strategy: 'fixed',
54
- middleware: [offset(8), autoPlacement({
55
- allowedPlacements: ['right', 'right-start', 'right-end', 'left', 'left-start', 'left-end']
56
- }), arrow({
57
- element: arrowElement
58
- })]
59
- });
39
+ const [box, setBox] = useState(null);
40
+ const [emojiAction, setEmojiAction] = useState(null);
60
41
  const onSelectionChange = (selection, isFocusing = false) => {
61
42
  if (disabled) {
62
43
  return;
@@ -103,11 +84,11 @@ export const RichMessageEditor = ({
103
84
  return;
104
85
  }
105
86
  return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
106
- if (reference.current instanceof HTMLElement && !reference.current.contains(event.target)) {
87
+ if (box && !box.contains(event.target)) {
107
88
  clickAwayHandler();
108
89
  }
109
90
  });
110
- }, [clickAwayHandler, isFocused, reference]);
91
+ }, [clickAwayHandler, isFocused, box]);
111
92
  return _jsx(SlateEditor, {
112
93
  initialValue: initialValue,
113
94
  onChange: onChange,
@@ -116,7 +97,7 @@ export const RichMessageEditor = ({
116
97
  editor
117
98
  }) => _jsxs(FieldBox, {
118
99
  title: title,
119
- boxRef: setReference,
100
+ boxRef: setBox,
120
101
  error: error,
121
102
  actions: _jsx(Collapse, {
122
103
  expanded: isFocused,
@@ -128,6 +109,7 @@ export const RichMessageEditor = ({
128
109
  }),
129
110
  children: [_jsx(PersonalizationIcon, {}), "Personalization"]
130
111
  }), canUseEmoji && _jsxs(ImSpan, {
112
+ ref: setEmojiAction,
131
113
  onClick: () => setShowDrop({
132
114
  type: 'emoji'
133
115
  }),
@@ -145,37 +127,33 @@ export const RichMessageEditor = ({
145
127
  onDelete: () => {
146
128
  setShowDrop(undefined);
147
129
  }
148
- }), showDrop && _jsxs(DropArea, {
149
- style: floatingStyles,
150
- ref: setFloating,
151
- children: [showDrop.type === 'personalization' && _jsx(DropContent, {
152
- children: renderDynamicContent?.({
153
- dc: showDrop.path ? getDcByPath(editor.children, showDrop.path)?.dc : undefined,
154
- onChange: newDC => {
155
- if (showDrop.path) {
156
- Transforms.setNodes(editor, {
157
- dc: newDC
158
- }, {
159
- at: showDrop.path
160
- });
161
- } else {
162
- insertDynamicContent(editor, newDC);
163
- }
164
- },
165
- onClose,
166
- update
167
- })
168
- }), showDrop.type === 'emoji' && _jsx(EditorEmojiPicker, {
169
- onEmojiSelect: s => editor.insertText(s)
170
- }), _jsx(Arrow, {
171
- "$direction": placementToDirection(placement),
172
- ref: setArrowElement,
173
- style: {
174
- left: middlewareData.arrow?.x,
175
- top: middlewareData.arrow?.y
176
- },
177
- children: _jsx(ArrowIcon, {})
178
- })]
130
+ }), showDrop && box && _jsx(RichMessageEditorDrop, {
131
+ editor: editor,
132
+ drop: showDrop,
133
+ box: box,
134
+ emojiAction: emojiAction,
135
+ children: update => _jsxs(_Fragment, {
136
+ children: [showDrop.type === 'personalization' && _jsx(DropContent, {
137
+ children: renderDynamicContent?.({
138
+ dc: showDrop.path ? getDcByPath(editor.children, showDrop.path)?.dc : undefined,
139
+ onChange: newDC => {
140
+ if (showDrop.path) {
141
+ Transforms.setNodes(editor, {
142
+ dc: newDC
143
+ }, {
144
+ at: showDrop.path
145
+ });
146
+ } else {
147
+ insertDynamicContent(editor, newDC);
148
+ }
149
+ },
150
+ onClose,
151
+ update
152
+ })
153
+ }), showDrop.type === 'emoji' && _jsx(EditorEmojiPicker, {
154
+ onEmojiSelect: s => editor.insertText(s)
155
+ })]
156
+ })
179
157
  }, showDrop.type)]
180
158
  })
181
159
  });
@@ -0,0 +1,12 @@
1
+ import { type FC, type ReactNode } from 'react';
2
+ import { type DropValue } from './RichMessageEditor.types';
3
+ import { type CustomEditor } from './slate/custom-types';
4
+ type RichMessageEditorDropProps = {
5
+ editor: CustomEditor;
6
+ drop: DropValue;
7
+ box: HTMLElement;
8
+ emojiAction: HTMLElement | null;
9
+ children: (update: () => void) => ReactNode;
10
+ };
11
+ export declare const RichMessageEditorDrop: FC<RichMessageEditorDropProps>;
12
+ export {};
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { arrow, autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/react-dom';
3
+ import { useMemo, useState } from 'react';
4
+ import ArrowIcon from './assets/arrow.svg';
5
+ import { getDropAnchor, placementToDirection } from './RichMessageEditor.helpers';
6
+ import { Arrow, DropArea } from './styles';
7
+ export const RichMessageEditorDrop = ({
8
+ editor,
9
+ drop,
10
+ box,
11
+ emojiAction,
12
+ children
13
+ }) => {
14
+ const [arrowElement, setArrowElement] = useState(null);
15
+ const anchor = useMemo(() => getDropAnchor(editor, drop, box, emojiAction), [editor, drop, box, emojiAction]);
16
+ const {
17
+ refs: {
18
+ setFloating
19
+ },
20
+ floatingStyles,
21
+ update,
22
+ middlewareData,
23
+ placement
24
+ } = useFloating({
25
+ strategy: 'fixed',
26
+ placement: 'bottom',
27
+ elements: {
28
+ reference: anchor
29
+ },
30
+ whileElementsMounted: autoUpdate,
31
+ middleware: [offset(8), flip({
32
+ fallbackPlacements: ['top', 'right', 'left']
33
+ }), shift({
34
+ padding: 8
35
+ }), arrow({
36
+ element: arrowElement
37
+ })]
38
+ });
39
+ return _jsxs(DropArea, {
40
+ style: floatingStyles,
41
+ ref: setFloating,
42
+ children: [children(update), _jsx(Arrow, {
43
+ "$direction": placementToDirection(placement),
44
+ ref: setArrowElement,
45
+ style: {
46
+ left: middlewareData.arrow?.x,
47
+ top: middlewareData.arrow?.y
48
+ },
49
+ children: _jsx(ArrowIcon, {})
50
+ })]
51
+ });
52
+ };
@@ -1,5 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Color } from '@pushwoosh/kit-constants';
3
+ import { Vertical } from '@pushwoosh/kit-helpers';
4
+ import { InlineBannerPreview } from '../InlineBannerPreview';
3
5
  import { Spinner } from '../Spinner';
4
6
  import { useRichmediaHtml } from './hooks';
5
7
  import { RichMediaPreviewContainer, RichMediaPreviewIframe } from './styles';
@@ -23,7 +25,8 @@ export function RichmediaPreview(props) {
23
25
  baseUrl = '',
24
26
  width = 304,
25
27
  height = 480,
26
- isLoading = false
28
+ isLoading = false,
29
+ inline = false
27
30
  } = props;
28
31
  const richmediaHtml = useRichmediaHtml({
29
32
  content,
@@ -32,19 +35,27 @@ export function RichmediaPreview(props) {
32
35
  defaultLanguage,
33
36
  baseUrl
34
37
  });
35
- return _jsx(RichMediaPreviewContainer, {
38
+ const isInlineScreen = inline && !isLoading;
39
+ return _jsxs(RichMediaPreviewContainer, {
36
40
  ...LIGHT_ISLAND_PROPS,
37
41
  "$width": width,
38
42
  "$height": height,
39
43
  "$isLoading": isLoading,
40
- "$placeItems": "center",
41
- children: isLoading ? _jsx(Spinner, {
44
+ "$alignItems": isInlineScreen ? 'start' : 'center',
45
+ "$justifyItems": isInlineScreen ? 'stretch' : 'center',
46
+ children: [isLoading && _jsx(Spinner, {
42
47
  size: "medium",
43
48
  color: Color.LOCKED
44
- }) : _jsx(RichMediaPreviewIframe, {
49
+ }), isInlineScreen && _jsx(Vertical, {
50
+ "$padding": "16px 8px 0",
51
+ children: _jsx(InlineBannerPreview, {
52
+ title: name,
53
+ html: richmediaHtml
54
+ })
55
+ }), !isLoading && !inline && _jsx(RichMediaPreviewIframe, {
45
56
  mode: "isolated",
46
57
  title: name,
47
58
  html: richmediaHtml
48
- })
59
+ })]
49
60
  });
50
61
  }
@@ -30,4 +30,6 @@ export type RichmediaPreviewProps = BuildRichmediaHtmlArgs & {
30
30
  height?: string | number;
31
31
  /** Show the loading spinner. */
32
32
  isLoading?: boolean;
33
+ /** Draw the template as an inline banner in a slot of an app screen, not as a full-screen popup. */
34
+ inline?: boolean;
33
35
  };
@@ -5,7 +5,8 @@ import type { SandboxedHtmlFrameProps } from './types';
5
5
  * boundary so scripts and same-origin access can never be granted together:
6
6
  *
7
7
  * - `isolated` — `sandbox="allow-scripts"`; scripts run in an opaque origin and cannot
8
- * touch the embedding page. The parent gets no DOM access.
8
+ * touch the embedding page. The parent gets no DOM access; with `onContentHeight` the frame
9
+ * reports the height of its content instead.
9
10
  * - `inspectable` — `sandbox="allow-same-origin"`; scripts are disabled, but the parent
10
11
  * keeps read access to the frame document via `onReady`.
11
12
  *
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { CONTENT_HEIGHT_MESSAGE, CONTENT_HEIGHT_SCRIPT } from './constants';
3
4
  const SANDBOX = {
4
5
  isolated: 'allow-scripts',
5
6
  inspectable: 'allow-same-origin'
@@ -9,7 +10,8 @@ const SANDBOX = {
9
10
  * boundary so scripts and same-origin access can never be granted together:
10
11
  *
11
12
  * - `isolated` — `sandbox="allow-scripts"`; scripts run in an opaque origin and cannot
12
- * touch the embedding page. The parent gets no DOM access.
13
+ * touch the embedding page. The parent gets no DOM access; with `onContentHeight` the frame
14
+ * reports the height of its content instead.
13
15
  * - `inspectable` — `sandbox="allow-same-origin"`; scripts are disabled, but the parent
14
16
  * keeps read access to the frame document via `onReady`.
15
17
  *
@@ -25,6 +27,7 @@ export function SandboxedHtmlFrame(props) {
25
27
  className
26
28
  } = props;
27
29
  const onReady = mode === 'inspectable' ? props.onReady : undefined;
30
+ const onContentHeight = mode === 'isolated' ? props.onContentHeight : undefined;
28
31
  const $ref = useRef(null);
29
32
  const [isReady, setIsReady] = useState(false);
30
33
  const htmlDeps = [html];
@@ -46,11 +49,27 @@ export function SandboxedHtmlFrame(props) {
46
49
  }
47
50
  return onReady(frameDocument);
48
51
  }, [isReady, onReady]);
52
+ useEffect(() => {
53
+ if (!onContentHeight) {
54
+ return undefined;
55
+ }
56
+ const handleMessage = event => {
57
+ if (event.source !== $ref.current?.contentWindow || event.data?.type !== CONTENT_HEIGHT_MESSAGE) {
58
+ return;
59
+ }
60
+ const height = Number(event.data.height);
61
+ if (Number.isFinite(height) && height >= 0) {
62
+ onContentHeight(height);
63
+ }
64
+ };
65
+ window.addEventListener('message', handleMessage);
66
+ return () => window.removeEventListener('message', handleMessage);
67
+ }, [onContentHeight]);
49
68
  return _jsx("iframe", {
50
69
  ref: $ref,
51
70
  className: className,
52
71
  title: title,
53
- srcDoc: html,
72
+ srcDoc: onContentHeight ? `${html}${CONTENT_HEIGHT_SCRIPT}` : html,
54
73
  sandbox: SANDBOX[mode],
55
74
  onLoad: handleLoad
56
75
  });
@@ -0,0 +1,7 @@
1
+ /** `type` of the message an isolated frame posts to the embedding page with its content height. */
2
+ export declare const CONTENT_HEIGHT_MESSAGE = "pushwooshSandboxedFrameHeight";
3
+ /**
4
+ * Appended to an isolated frame document: posts the content height the way the mobile SDK measures
5
+ * an inline banner, so a preview is as tall as the banner on a device.
6
+ */
7
+ export declare const CONTENT_HEIGHT_SCRIPT = "<script>\n(function() {\n var root = document.documentElement, reported = -1;\n function bottomOf(rect, bottom) {\n return rect.width || rect.height ? Math.max(bottom, rect.bottom) : bottom;\n }\n function quirksBottom(body) {\n var range = document.createRange(), bottom = 0;\n for (var i = 0; i < body.childNodes.length; i++) {\n var node = body.childNodes[i];\n if (node.nodeType === 1) {\n bottom = bottomOf(node.getBoundingClientRect(), bottom);\n } else if (node.nodeType === 3) {\n range.selectNode(node);\n bottom = bottomOf(range.getBoundingClientRect(), bottom);\n }\n }\n if (!bottom) return 0;\n var style = getComputedStyle(body);\n return bottom + parseFloat(style.paddingBottom) + parseFloat(style.borderBottomWidth) +\n parseFloat(style.marginBottom);\n }\n function positionedBottom(body) {\n var bottom = 0, nodes = body.getElementsByTagName('*');\n for (var i = 0; i < nodes.length; i++) {\n var position = getComputedStyle(nodes[i]).position;\n if (position === 'absolute' || position === 'fixed') {\n bottom = bottomOf(nodes[i].getBoundingClientRect(), bottom);\n }\n }\n return bottom;\n }\n function report() {\n var body = document.body, height = 0;\n if (document.compatMode === 'CSS1Compat') {\n height = root.getBoundingClientRect().height;\n } else if (body) {\n height = quirksBottom(body);\n }\n if (body) height = Math.max(height, positionedBottom(body));\n height = Math.ceil(height + window.scrollY);\n if (height !== reported) {\n reported = height;\n parent.postMessage({ type: 'pushwooshSandboxedFrameHeight', height: height }, '*');\n }\n }\n var resizes = new ResizeObserver(report);\n function observe() {\n resizes.observe(root);\n var nodes = root.getElementsByTagName('*');\n for (var i = 0; i < nodes.length; i++) resizes.observe(nodes[i]);\n }\n new MutationObserver(function() { observe(); report(); }).observe(root, { childList: true, subtree: true });\n window.addEventListener('load', report);\n observe();\n report();\n})();\n</script>";
@@ -0,0 +1,64 @@
1
+ /** `type` of the message an isolated frame posts to the embedding page with its content height. */
2
+ export const CONTENT_HEIGHT_MESSAGE = 'pushwooshSandboxedFrameHeight';
3
+ /**
4
+ * Appended to an isolated frame document: posts the content height the way the mobile SDK measures
5
+ * an inline banner, so a preview is as tall as the banner on a device.
6
+ */
7
+ export const CONTENT_HEIGHT_SCRIPT = `<script>
8
+ (function() {
9
+ var root = document.documentElement, reported = -1;
10
+ function bottomOf(rect, bottom) {
11
+ return rect.width || rect.height ? Math.max(bottom, rect.bottom) : bottom;
12
+ }
13
+ function quirksBottom(body) {
14
+ var range = document.createRange(), bottom = 0;
15
+ for (var i = 0; i < body.childNodes.length; i++) {
16
+ var node = body.childNodes[i];
17
+ if (node.nodeType === 1) {
18
+ bottom = bottomOf(node.getBoundingClientRect(), bottom);
19
+ } else if (node.nodeType === 3) {
20
+ range.selectNode(node);
21
+ bottom = bottomOf(range.getBoundingClientRect(), bottom);
22
+ }
23
+ }
24
+ if (!bottom) return 0;
25
+ var style = getComputedStyle(body);
26
+ return bottom + parseFloat(style.paddingBottom) + parseFloat(style.borderBottomWidth) +
27
+ parseFloat(style.marginBottom);
28
+ }
29
+ function positionedBottom(body) {
30
+ var bottom = 0, nodes = body.getElementsByTagName('*');
31
+ for (var i = 0; i < nodes.length; i++) {
32
+ var position = getComputedStyle(nodes[i]).position;
33
+ if (position === 'absolute' || position === 'fixed') {
34
+ bottom = bottomOf(nodes[i].getBoundingClientRect(), bottom);
35
+ }
36
+ }
37
+ return bottom;
38
+ }
39
+ function report() {
40
+ var body = document.body, height = 0;
41
+ if (document.compatMode === 'CSS1Compat') {
42
+ height = root.getBoundingClientRect().height;
43
+ } else if (body) {
44
+ height = quirksBottom(body);
45
+ }
46
+ if (body) height = Math.max(height, positionedBottom(body));
47
+ height = Math.ceil(height + window.scrollY);
48
+ if (height !== reported) {
49
+ reported = height;
50
+ parent.postMessage({ type: '${CONTENT_HEIGHT_MESSAGE}', height: height }, '*');
51
+ }
52
+ }
53
+ var resizes = new ResizeObserver(report);
54
+ function observe() {
55
+ resizes.observe(root);
56
+ var nodes = root.getElementsByTagName('*');
57
+ for (var i = 0; i < nodes.length; i++) resizes.observe(nodes[i]);
58
+ }
59
+ new MutationObserver(function() { observe(); report(); }).observe(root, { childList: true, subtree: true });
60
+ window.addEventListener('load', report);
61
+ observe();
62
+ report();
63
+ })();
64
+ </script>`;
@@ -14,6 +14,11 @@ type SandboxedHtmlFrameBaseProps = {
14
14
  export type IsolatedSandboxedHtmlFrameProps = SandboxedHtmlFrameBaseProps & {
15
15
  mode: 'isolated';
16
16
  onReady?: never;
17
+ /**
18
+ * Called with the height of the frame content in CSS pixels, on load and on every change.
19
+ * The value comes from the untrusted document: clamp it before using it for layout.
20
+ */
21
+ onContentHeight?: (height: number) => void;
17
22
  };
18
23
  /**
19
24
  * Inspectable rendering: scripts are disabled entirely, but the embedding page keeps
@@ -22,6 +27,7 @@ export type IsolatedSandboxedHtmlFrameProps = SandboxedHtmlFrameBaseProps & {
22
27
  */
23
28
  export type InspectableSandboxedHtmlFrameProps = SandboxedHtmlFrameBaseProps & {
24
29
  mode: 'inspectable';
30
+ onContentHeight?: never;
25
31
  /**
26
32
  * Called with the frame document once it has loaded, and again whenever the callback
27
33
  * identity changes. May return a cleanup run before the next call and on unmount.
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AccessForbidden } from './AccessForbidden';
2
+ export { AppScreenPlaceholder, type AppScreenPlaceholderProps } from './AppScreenPlaceholder';
2
3
  export { Badge, type BadgeColor } from './Badge';
3
4
  export { Banner, type BannerType } from './Banner';
4
5
  export { Button, GhostButton, RemoveButton, type RequiredButtonProps, } from './Button';
@@ -58,6 +59,7 @@ export { CodeEditor, json as jsonLanguage, html as htmlLanguage } from './CodeEd
58
59
  export { EnhancedInput, SearchInput } from './EnhancedInput';
59
60
  export { Chip, type ChipProps, type ChipVariant } from './Chip';
60
61
  export { PillSelector, Pill, type PillProps, type PillSelectorProps, type PillSelectorRadioProps, type PillSelectorCheckboxProps, type PillSelectorItem, } from './PillSelector';
62
+ export { InlineBannerPreview, type InlineBannerPreviewProps } from './InlineBannerPreview';
61
63
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
62
64
  export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type IsolatedSandboxedHtmlFrameProps, type InspectableSandboxedHtmlFrameProps, } from './SandboxedHtmlFrame';
63
65
  export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES, } from './NativeRichMediaPreview';
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AccessForbidden } from './AccessForbidden';
2
+ export { AppScreenPlaceholder } from './AppScreenPlaceholder';
2
3
  export { Badge } from './Badge';
3
4
  export { Banner } from './Banner';
4
5
  export { Button, GhostButton, RemoveButton } from './Button';
@@ -52,6 +53,7 @@ export { CodeEditor, json as jsonLanguage, html as htmlLanguage } from './CodeEd
52
53
  export { EnhancedInput, SearchInput } from './EnhancedInput';
53
54
  export { Chip } from './Chip';
54
55
  export { PillSelector, Pill } from './PillSelector';
56
+ export { InlineBannerPreview } from './InlineBannerPreview';
55
57
  export { RichmediaPreview, useRichmediaHtml } from './RichmediaPreview';
56
58
  export { SandboxedHtmlFrame } from './SandboxedHtmlFrame';
57
59
  export { NativeRichMediaPreview, parseNativeRichMediaConfig, parseLocalizationParams, NATIVE_RICH_MEDIA_DISPLAY_TYPES, EDITABLE_NATIVE_RICH_MEDIA_DISPLAY_TYPES } from './NativeRichMediaPreview';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "4.18.3",
3
+ "version": "4.20.0",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -35,7 +35,7 @@
35
35
  "react": "19.3.0",
36
36
  "react-dom": "19.3.0",
37
37
  "styled-components": "6.6.0",
38
- "vitest": "^4.1.12"
38
+ "vitest": "^5.1.1"
39
39
  },
40
40
  "dependencies": {
41
41
  "@codemirror/lang-html": "^6.4.12",