@pushwoosh/dumb-components 4.11.0 → 4.12.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.
@@ -12,7 +12,8 @@ export function ChatPreview(props) {
12
12
  content,
13
13
  status,
14
14
  issues,
15
- senderName
15
+ senderName,
16
+ name
16
17
  } = props;
17
18
  const look = CHAT_CHANNELS[channel];
18
19
  const view = viewOf(channel, status);
@@ -25,7 +26,8 @@ export function ChatPreview(props) {
25
26
  content: delivered,
26
27
  dropped: dropped,
27
28
  look: look,
28
- rcs: channel === 'rcs' ? content.rcs : undefined
29
+ rcs: channel === 'rcs' ? content.rcs : undefined,
30
+ name: name
29
31
  });
30
32
  return _jsxs(Screen, {
31
33
  "$skin": look.skin,
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Carousel, FlexBox } from './styles';
3
- import { cardsOf, fallbackTextOf } from '../../helpers';
3
+ import { altTextOf, cardsOf } from '../../helpers';
4
4
  import { Lang } from '../../polyglot';
5
5
  import { ChatCardView } from '../ChatCardView';
6
6
  import { ChatText } from '../ChatText';
@@ -14,18 +14,20 @@ export function NativeMessage(props) {
14
14
  content,
15
15
  look,
16
16
  dropped,
17
- rcs
17
+ rcs,
18
+ name
18
19
  } = props;
19
20
  const cards = cardsOf(content);
20
21
  if (content.type === 'custom_flex') {
22
+ const altText = altTextOf(content, name);
21
23
  return _jsxs(FlexBox, {
22
24
  children: [_jsx("strong", {
23
25
  children: _jsx(Lang, {
24
26
  message: "DUMB.CHAT_PREVIEW.FLEX"
25
27
  })
26
- }), fallbackTextOf(content) && _jsx(ChatText, {
28
+ }), altText && _jsx(ChatText, {
27
29
  markup: look.markup,
28
- text: fallbackTextOf(content)
30
+ text: altText
29
31
  })]
30
32
  });
31
33
  }
@@ -4,4 +4,6 @@ import type { ChatPartProps } from '../types';
4
4
  export type NativeMessageProps = ChatPartProps & {
5
5
  /** RCS card layout, passed only on RCS. */
6
6
  rcs?: ChatRcsLayout;
7
+ /** Preset name, the Flex alt text when the message carries no text. */
8
+ name?: string;
7
9
  };
@@ -8,6 +8,8 @@ export type ChatView = 'native'
8
8
  export declare function viewOf(channel: ChatChannel, status: ChatCompatibility | undefined): ChatView;
9
9
  /** Text the channel receives when it cannot render the content type. */
10
10
  export declare function fallbackTextOf(content: ChatContent): string;
11
+ /** LINE's Flex alt text, as the backend builds it: the message or first card text, else the fallback, else the preset name. */
12
+ export declare function altTextOf(content: ChatContent, name?: string): string;
11
13
  /** Buttons drawn below the bubble text: quick replies, call-to-action links and phone numbers. */
12
14
  export declare function bubbleButtonsOf(content: ChatContent): ChatButton[];
13
15
  /** Cards of a card or carousel message; a plain card is a one-slide carousel. */
@@ -13,6 +13,11 @@ export function viewOf(channel, status) {
13
13
  export function fallbackTextOf(content) {
14
14
  return content.fallback || content.body || '';
15
15
  }
16
+ /** LINE's Flex alt text, as the backend builds it: the message or first card text, else the fallback, else the preset name. */
17
+ export function altTextOf(content, name = '') {
18
+ const card = content.cards?.[0];
19
+ return content.body || card?.title || card?.body || content.fallback || name;
20
+ }
16
21
  /** Buttons drawn below the bubble text: quick replies, call-to-action links and phone numbers. */
17
22
  export function bubbleButtonsOf(content) {
18
23
  return content.type === 'quick_reply' || content.type === 'call_to_action' ? content.buttons ?? [] : [];
@@ -131,4 +131,6 @@ export interface ChatPreviewProps {
131
131
  issues?: ChatIssue[];
132
132
  /** Sender shown in the chat header. */
133
133
  senderName?: string;
134
+ /** Preset name: LINE's Flex alt text when the message carries no text. */
135
+ name?: string;
134
136
  }
@@ -65,6 +65,7 @@ export const DropdownMenu = ({
65
65
  rects
66
66
  }) {
67
67
  if (fullWidth) {
68
+ // eslint-disable-next-line react/dom-no-flush-sync -- floating-ui size() needs the width applied before it measures
68
69
  flushSync(() => setWidth(rects.reference.width));
69
70
  }
70
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "4.11.0",
3
+ "version": "4.12.1",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -36,8 +36,8 @@
36
36
  "@codemirror/view": "^6.43.11",
37
37
  "@floating-ui/react-dom": "^2.1.2",
38
38
  "@lezer/highlight": "^1.2.1",
39
- "@pushwoosh/kit-constants": "^3.0.0",
40
- "@pushwoosh/kit-helpers": "^4.16.1",
39
+ "@pushwoosh/kit-constants": "^3.1.0",
40
+ "@pushwoosh/kit-helpers": "^4.16.2",
41
41
  "@pushwoosh/kit-icons": "^2.3.15",
42
42
  "@pushwoosh/kit-typography": "^2.0.0",
43
43
  "@tippyjs/react": "^4.2.6",
@@ -255,13 +255,11 @@ function parseTokens(tokensArg) {
255
255
  Control: () => {
256
256
  const controlNodeName = token.value;
257
257
  const chidrens = [[], []];
258
- let args = '';
259
258
  currentTokenIndex++;
260
- if (tokens[currentTokenIndex] && tokens[currentTokenIndex].type === 'ControlArg') {
261
- args = tokens[currentTokenIndex].value;
262
- } else {
259
+ if (!tokens[currentTokenIndex] || tokens[currentTokenIndex].type !== 'ControlArg') {
263
260
  throw new Error(`Syntax error: expected argument for ${controlNodeName} at line ${token.lineNo}`);
264
261
  }
262
+ const args = tokens[currentTokenIndex].value;
265
263
  currentTokenIndex++;
266
264
  if (pairedControlTokens[controlNodeName]) {
267
265
  const controlChildren = parseUntil(tokens, 'ControlEnd');
@@ -1,4 +1,3 @@
1
- import { createElement as _createElement } from "react";
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import styled from 'styled-components';
4
3
  import { Color } from '@pushwoosh/kit-constants';
@@ -104,7 +103,7 @@ const Txt = styled.span.withConfig({
104
103
  export function renderToReact(ast, context) {
105
104
  return renderNodesToArray(ast, context, (tagNode, children, key) => {
106
105
  const TagName = tagNode.name;
107
- const props = Object.fromEntries(Object.entries(tagNode.params).map(([key, value]) => [key, unpackScalarOrValue(value, context)]));
106
+ const props = Object.fromEntries(Object.entries(tagNode.params).filter(([name]) => name !== 'key').map(([name, value]) => [name, unpackScalarOrValue(value, context)]));
108
107
  if (TagName === 'text') {
109
108
  return [_jsx(Txt, {
110
109
  "$variant": props.variant,
@@ -115,14 +114,13 @@ export function renderToReact(ast, context) {
115
114
  }, key)];
116
115
  }
117
116
  if (voidTags.has(TagName)) {
118
- return [_createElement(TagName, {
119
- ...props,
120
- key: key
121
- })];
117
+ return [_jsx(TagName, {
118
+ ...props
119
+ }, key)];
122
120
  }
123
- return [_createElement(TagName, {
121
+ return [_jsx(TagName, {
124
122
  ...props,
125
- key: key
126
- }, children)];
123
+ children: children
124
+ }, key)];
127
125
  });
128
126
  }