@micromag/screen-conversation 0.3.541 → 0.3.562

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 (3) hide show
  1. package/es/index.js +6 -8
  2. package/package.json +14 -15
  3. package/lib/index.js +0 -716
package/es/index.js CHANGED
@@ -105,7 +105,6 @@ var ConversationAudioAttachment = function ConversationAudioAttachment(_ref) {
105
105
  };
106
106
  ConversationAudioAttachment.propTypes = propTypes$2;
107
107
  ConversationAudioAttachment.defaultProps = defaultProps$2;
108
- var ConversationAudioAttachment$1 = ConversationAudioAttachment;
109
108
 
110
109
  var propTypes$1 = {
111
110
  message: PropTypes.conversationMessage,
@@ -218,7 +217,7 @@ var ConversationMessage = function ConversationMessage(_ref) {
218
217
  }, [messageState]);
219
218
  var betweenStyle = isNextSpeakerTheSame && nextMessageState;
220
219
  var buildAudioAttachment = function buildAudioAttachment() {
221
- return /*#__PURE__*/React.createElement(ConversationAudioAttachment$1, {
220
+ return /*#__PURE__*/React.createElement(ConversationAudioAttachment, {
222
221
  audio: audio,
223
222
  messageId: messageId,
224
223
  nextAudioMessageId: nextAudioMessageId,
@@ -275,7 +274,6 @@ var ConversationMessage = function ConversationMessage(_ref) {
275
274
  };
276
275
  ConversationMessage.propTypes = propTypes$1;
277
276
  ConversationMessage.defaultProps = defaultProps$1;
278
- var ConversationMessage$1 = ConversationMessage;
279
277
 
280
278
  var propTypes = {
281
279
  // id: PropTypes.string,
@@ -419,7 +417,8 @@ var ConversationScreen = function ConversationScreen(_ref) {
419
417
 
420
418
  // if the current message has an audio attachment, use the time it takes to record that message
421
419
  if (audio) {
422
- return audio.metadata.duration;
420
+ var _audio$metadata;
421
+ return (_audio$metadata = audio.metadata) === null || _audio$metadata === void 0 ? void 0 : _audio$metadata.duration;
423
422
  }
424
423
 
425
424
  // counting words: only keep whitespaces and alphanumeric characters, then split of whitespaces
@@ -525,7 +524,7 @@ var ConversationScreen = function ConversationScreen(_ref) {
525
524
  return c.audio != null;
526
525
  });
527
526
  var nextAudioMessageId = nextAudioMessage ? "".concat(m.message, "-").concat(messagesUniqueId[filteredMessages.indexOf(nextAudioMessage)]) : null;
528
- return /*#__PURE__*/React.createElement(ConversationMessage$1, {
527
+ return /*#__PURE__*/React.createElement(ConversationMessage, {
529
528
  key: messageId,
530
529
  message: m,
531
530
  messageId: messageId,
@@ -569,7 +568,6 @@ var ConversationScreen = function ConversationScreen(_ref) {
569
568
  };
570
569
  ConversationScreen.propTypes = propTypes;
571
570
  ConversationScreen.defaultProps = defaultProps;
572
- var ConversationScreen$1 = ConversationScreen;
573
571
 
574
572
  var definition = {
575
573
  id: 'conversation',
@@ -591,7 +589,7 @@ var definition = {
591
589
  "value": "Conversation"
592
590
  }]
593
591
  }),
594
- component: ConversationScreen$1,
592
+ component: ConversationScreen,
595
593
  layouts: ['normal'],
596
594
  fields: [
597
595
  // {
@@ -708,4 +706,4 @@ var definition = {
708
706
  }]
709
707
  };
710
708
 
711
- export { ConversationScreen$1 as ConversationScreen, definition as default };
709
+ export { ConversationScreen, definition as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-conversation",
3
- "version": "0.3.541",
3
+ "version": "0.3.562",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -30,12 +30,11 @@
30
30
  }
31
31
  ],
32
32
  "license": "ISC",
33
- "main": "lib/index.js",
33
+ "type": "module",
34
34
  "module": "es/index.js",
35
35
  "style": "assets/css/styles.css",
36
36
  "exports": {
37
37
  ".": {
38
- "require": "./lib/index.js",
39
38
  "import": "./es/index.js"
40
39
  },
41
40
  "./assets/css/styles": "./assets/css/styles.css",
@@ -61,17 +60,17 @@
61
60
  },
62
61
  "dependencies": {
63
62
  "@babel/runtime": "^7.13.10",
64
- "@micromag/core": "^0.3.541",
65
- "@micromag/element-background": "^0.3.541",
66
- "@micromag/element-container": "^0.3.541",
67
- "@micromag/element-footer": "^0.3.541",
68
- "@micromag/element-header": "^0.3.541",
69
- "@micromag/element-heading": "^0.3.541",
70
- "@micromag/element-layout": "^0.3.541",
71
- "@micromag/element-scroll": "^0.3.541",
72
- "@micromag/element-text": "^0.3.541",
73
- "@micromag/element-visual": "^0.3.541",
74
- "@micromag/transforms": "^0.3.541",
63
+ "@micromag/core": "^0.3.547",
64
+ "@micromag/element-background": "^0.3.547",
65
+ "@micromag/element-container": "^0.3.547",
66
+ "@micromag/element-footer": "^0.3.547",
67
+ "@micromag/element-header": "^0.3.547",
68
+ "@micromag/element-heading": "^0.3.547",
69
+ "@micromag/element-layout": "^0.3.547",
70
+ "@micromag/element-scroll": "^0.3.547",
71
+ "@micromag/element-text": "^0.3.547",
72
+ "@micromag/element-visual": "^0.3.547",
73
+ "@micromag/transforms": "^0.3.547",
75
74
  "classnames": "^2.2.6",
76
75
  "lodash": "^4.17.21",
77
76
  "prop-types": "^15.7.2",
@@ -82,5 +81,5 @@
82
81
  "access": "public",
83
82
  "registry": "https://registry.npmjs.org/"
84
83
  },
85
- "gitHead": "6c04a7e327b5fbc096785c11320b3fbd3c5751c8"
84
+ "gitHead": "ca2600647087ca7ebd0517686562d6db252845b1"
86
85
  }
package/lib/index.js DELETED
@@ -1,716 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var reactIntl = require('react-intl');
6
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
7
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
8
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
9
- var classNames = require('classnames');
10
- var PropTypes = require('prop-types');
11
- var React = require('react');
12
- var uuid = require('uuid');
13
- var core = require('@micromag/core');
14
- var components = require('@micromag/core/components');
15
- var contexts = require('@micromag/core/contexts');
16
- var hooks = require('@micromag/core/hooks');
17
- var utils = require('@micromag/core/utils');
18
- var Background = require('@micromag/element-background');
19
- var Container = require('@micromag/element-container');
20
- var Footer = require('@micromag/element-footer');
21
- var Header = require('@micromag/element-header');
22
- var Heading = require('@micromag/element-heading');
23
- var Layout = require('@micromag/element-layout');
24
- var Scroll = require('@micromag/element-scroll');
25
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
26
- var Text = require('@micromag/element-text');
27
- var Visual = require('@micromag/element-visual');
28
- var Audio = require('@micromag/element-audio');
29
-
30
- var styles = {"container":"micromag-screen-conversation-container","background":"micromag-screen-conversation-background","disabled":"micromag-screen-conversation-disabled","hidden":"micromag-screen-conversation-hidden","placeholder":"micromag-screen-conversation-placeholder","content":"micromag-screen-conversation-content","conversationHeader":"micromag-screen-conversation-conversationHeader","empty":"micromag-screen-conversation-empty","title":"micromag-screen-conversation-title","footer":"micromag-screen-conversation-footer","layout":"micromag-screen-conversation-layout","messageContainer":"micromag-screen-conversation-messageContainer","message":"micromag-screen-conversation-message","normalLeft":"micromag-screen-conversation-normalLeft","inBetweenLeft":"micromag-screen-conversation-inBetweenLeft","normalRight":"micromag-screen-conversation-normalRight","inBetweenRight":"micromag-screen-conversation-inBetweenRight","last":"micromag-screen-conversation-last","speakerDetails":"micromag-screen-conversation-speakerDetails","right":"micromag-screen-conversation-right","avatarContainer":"micromag-screen-conversation-avatarContainer","avatar":"micromag-screen-conversation-avatar","imageContainer":"micromag-screen-conversation-imageContainer","withAnimation":"micromag-screen-conversation-withAnimation","appear":"micromag-screen-conversation-appear","loadingContainer":"micromag-screen-conversation-loadingContainer","loading":"micromag-screen-conversation-loading","dot":"micromag-screen-conversation-dot","bounce":"micromag-screen-conversation-bounce","loadingSpeakerName":"micromag-screen-conversation-loadingSpeakerName","audioMessageContainer":"micromag-screen-conversation-audioMessageContainer","playButtonContainer":"micromag-screen-conversation-playButtonContainer","audioMessage":"micromag-screen-conversation-audioMessage","audioAttachment":"micromag-screen-conversation-audioAttachment","beforeText":"micromag-screen-conversation-beforeText","afterText":"micromag-screen-conversation-afterText"};
31
-
32
- var propTypes$2 = {
33
- audio: core.PropTypes.audioMedia,
34
- audioEventsChannelName: PropTypes.string,
35
- messageId: PropTypes.string,
36
- nextAudioMessageId: PropTypes.string
37
- };
38
- var defaultProps$2 = {
39
- audio: null,
40
- audioEventsChannelName: null,
41
- messageId: null,
42
- nextAudioMessageId: null
43
- };
44
- var ConversationAudioAttachment = function ConversationAudioAttachment(_ref) {
45
- var audio = _ref.audio,
46
- audioEventsChannelName = _ref.audioEventsChannelName,
47
- messageId = _ref.messageId,
48
- nextAudioMessageId = _ref.nextAudioMessageId;
49
- var _useState = React.useState(true),
50
- _useState2 = _slicedToArray(_useState, 2),
51
- paused = _useState2[0],
52
- setPaused = _useState2[1];
53
- var audioEventsChannel = React.useMemo(function () {
54
- return new BroadcastChannel(audioEventsChannelName);
55
- }, [audioEventsChannelName]);
56
- React.useEffect(function () {
57
- var onMessage = function onMessage(message) {
58
- var _message$data = message.data,
59
- type = _message$data.type,
60
- id = _message$data.id;
61
- switch (type) {
62
- case 'play':
63
- {
64
- setPaused(id !== messageId);
65
- }
66
- }
67
- };
68
- audioEventsChannel.addEventListener("message", onMessage);
69
- return function () {
70
- return audioEventsChannel.removeEventListener("message", onMessage);
71
- };
72
- }, [audioEventsChannel]);
73
- var togglePaused = function togglePaused() {
74
- if (paused) {
75
- setPaused(false);
76
- audioEventsChannel.postMessage({
77
- type: 'play',
78
- id: messageId
79
- });
80
- } else {
81
- setPaused(true);
82
- }
83
- };
84
- var onAudioEnded = function onAudioEnded() {
85
- if (nextAudioMessageId) {
86
- audioEventsChannel.postMessage({
87
- type: 'play',
88
- id: nextAudioMessageId
89
- });
90
- }
91
- setPaused(true);
92
- };
93
- return /*#__PURE__*/React.createElement("div", {
94
- className: classNames([styles.audioMessageContainer])
95
- }, /*#__PURE__*/React.createElement("div", {
96
- className: styles.playButtonContainer
97
- }, /*#__PURE__*/React.createElement(components.Button, {
98
- onClick: togglePaused,
99
- icon: paused ? /*#__PURE__*/React.createElement(components.PlayIcon, null) : /*#__PURE__*/React.createElement(components.PauseIcon, null)
100
- })), /*#__PURE__*/React.createElement(Audio, {
101
- withWave: true,
102
- autoWaveHeight: true,
103
- className: styles.audioMessage,
104
- media: audio,
105
- paused: paused,
106
- updateInterval: 100,
107
- onEnded: onAudioEnded
108
- }));
109
- };
110
- ConversationAudioAttachment.propTypes = propTypes$2;
111
- ConversationAudioAttachment.defaultProps = defaultProps$2;
112
- var ConversationAudioAttachment$1 = ConversationAudioAttachment;
113
-
114
- var propTypes$1 = {
115
- message: core.PropTypes.conversationMessage,
116
- messageId: PropTypes.string,
117
- previousMessage: core.PropTypes.conversationMessage,
118
- nextMessage: core.PropTypes.conversationMessage,
119
- nextAudioMessageId: PropTypes.string,
120
- nextMessageState: PropTypes.bool,
121
- currentSpeaker: core.PropTypes.speaker,
122
- // state: PropTypes.oneOf(['pause', 'typing', 'send']),
123
- conversationTiming: PropTypes.number,
124
- typingTiming: PropTypes.number,
125
- onChange: PropTypes.func,
126
- withAnimation: PropTypes.bool,
127
- active: PropTypes.bool,
128
- isPlaying: PropTypes.bool,
129
- speakerStyle: core.PropTypes.textStyle,
130
- messageStyle: core.PropTypes.textStyle,
131
- className: PropTypes.string,
132
- audioEventsChannelName: PropTypes.string
133
- };
134
- var defaultProps$1 = {
135
- message: null,
136
- messageId: null,
137
- previousMessage: null,
138
- nextMessage: null,
139
- nextAudioMessageId: null,
140
- nextMessageState: null,
141
- currentSpeaker: null,
142
- conversationTiming: null,
143
- typingTiming: null,
144
- onChange: null,
145
- withAnimation: false,
146
- active: false,
147
- isPlaying: false,
148
- messageStyle: null,
149
- speakerStyle: null,
150
- className: null,
151
- audioEventsChannelName: null
152
- };
153
- var ConversationMessage = function ConversationMessage(_ref) {
154
- var message = _ref.message,
155
- messageId = _ref.messageId,
156
- previousMessage = _ref.previousMessage,
157
- nextMessage = _ref.nextMessage,
158
- nextAudioMessageId = _ref.nextAudioMessageId,
159
- nextMessageState = _ref.nextMessageState,
160
- currentSpeaker = _ref.currentSpeaker,
161
- conversationTiming = _ref.conversationTiming,
162
- typingTiming = _ref.typingTiming,
163
- onChange = _ref.onChange,
164
- withAnimation = _ref.withAnimation,
165
- active = _ref.active,
166
- isPlaying = _ref.isPlaying,
167
- messageStyle = _ref.messageStyle,
168
- speakerStyle = _ref.speakerStyle,
169
- className = _ref.className,
170
- audioEventsChannelName = _ref.audioEventsChannelName;
171
- var _ref2 = message || {},
172
- messageBody = _ref2.message,
173
- _ref2$image = _ref2.image,
174
- image = _ref2$image === void 0 ? null : _ref2$image,
175
- audio = _ref2.audio,
176
- putAudioBeforeText = _ref2.putAudioBeforeText;
177
- var _ref3 = currentSpeaker || {},
178
- _ref3$avatar = _ref3.avatar,
179
- _ref3$avatar2 = _ref3$avatar === void 0 ? {} : _ref3$avatar,
180
- _ref3$avatar2$url = _ref3$avatar2.url,
181
- avatarUrl = _ref3$avatar2$url === void 0 ? null : _ref3$avatar2$url,
182
- speakerName = _ref3.name,
183
- _ref3$side = _ref3.side,
184
- side = _ref3$side === void 0 ? 'left' : _ref3$side,
185
- currentSpeakerId = _ref3.id,
186
- color = _ref3.color;
187
- var right = side === 'right';
188
- var isPrevSpeakerTheSame = previousMessage !== null && previousMessage.speaker === currentSpeakerId;
189
- var isNextSpeakerTheSame = nextMessage !== null && nextMessage.speaker === currentSpeakerId;
190
-
191
- // Timing
192
- var _useState = React.useState(withAnimation ? 'pause' : 'send'),
193
- _useState2 = _slicedToArray(_useState, 2),
194
- messageState = _useState2[0],
195
- setMessageState = _useState2[1];
196
- var pauseBeforeTyping = conversationTiming;
197
- var typingDuration = typingTiming;
198
- React.useEffect(function () {
199
- if (!withAnimation || !isPlaying) {
200
- return function () {};
201
- }
202
- var timeout = null;
203
- if (messageState === 'pause') {
204
- timeout = setTimeout(function () {
205
- return setMessageState('typing');
206
- }, pauseBeforeTyping);
207
- } else if (messageState === 'typing') {
208
- timeout = setTimeout(function () {
209
- return setMessageState('send');
210
- }, typingDuration);
211
- }
212
- return function () {
213
- if (timeout !== null) {
214
- clearTimeout(timeout);
215
- }
216
- };
217
- }, [withAnimation, isPlaying, messageState, setMessageState, pauseBeforeTyping, typingDuration]);
218
- React.useEffect(function () {
219
- if (messageState !== 'pause' && onChange !== null) {
220
- onChange(messageState);
221
- }
222
- }, [messageState]);
223
- var betweenStyle = isNextSpeakerTheSame && nextMessageState;
224
- var buildAudioAttachment = function buildAudioAttachment() {
225
- return /*#__PURE__*/React.createElement(ConversationAudioAttachment$1, {
226
- audio: audio,
227
- messageId: messageId,
228
- nextAudioMessageId: nextAudioMessageId,
229
- audioEventsChannelName: audioEventsChannelName
230
- });
231
- };
232
- return messageState !== 'pause' ? /*#__PURE__*/React.createElement("div", {
233
- className: classNames([styles.messageContainer, _defineProperty(_defineProperty(_defineProperty({}, className, className !== null), styles.withAnimation, withAnimation === true), styles.right, right)])
234
- }, messageState === 'typing' ? /*#__PURE__*/React.createElement("div", {
235
- className: styles.loadingContainer
236
- }, /*#__PURE__*/React.createElement("div", {
237
- className: styles.loading
238
- }, /*#__PURE__*/React.createElement("div", {
239
- className: styles.dot
240
- }), /*#__PURE__*/React.createElement("div", {
241
- className: styles.dot
242
- }), /*#__PURE__*/React.createElement("div", {
243
- className: styles.dot
244
- })), /*#__PURE__*/React.createElement("div", {
245
- className: styles.loadingSpeakerName
246
- }, speakerName)) : /*#__PURE__*/React.createElement("div", {
247
- className: classNames([styles.message, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.normalRight, right), styles.nextTheSame, isNextSpeakerTheSame === true && isPrevSpeakerTheSame), styles.inBetweenRight, betweenStyle && right), styles.normalLeft, !right), styles.inBetweenLeft, betweenStyle && !right), styles.last, isNextSpeakerTheSame === false)]),
248
- style: _objectSpread({}, utils.getStyleFromColor(color))
249
- }, !isPrevSpeakerTheSame ? /*#__PURE__*/React.createElement("div", {
250
- className: classNames([styles.speakerDetails, _defineProperty({}, styles.right, side === 'right')])
251
- }, avatarUrl !== null ? /*#__PURE__*/React.createElement("div", {
252
- className: classNames([styles.avatarContainer, _defineProperty({}, styles.right, side === 'right')])
253
- }, /*#__PURE__*/React.createElement("img", {
254
- className: styles.avatar,
255
- src: avatarUrl,
256
- alt: speakerName,
257
- loading: "lazy"
258
- })) : null, /*#__PURE__*/React.createElement(Text, {
259
- body: speakerName,
260
- textStyle: speakerStyle
261
- })) : null, /*#__PURE__*/React.createElement("div", null), /*#__PURE__*/React.createElement("div", {
262
- className: styles.messageBody
263
- }, image !== null ? /*#__PURE__*/React.createElement("div", {
264
- className: styles.imageContainer
265
- }, /*#__PURE__*/React.createElement(Visual, {
266
- media: image,
267
- width: "100%",
268
- playing: isPlaying,
269
- active: active
270
- })) : null, audio && putAudioBeforeText ? /*#__PURE__*/React.createElement("div", {
271
- className: classNames(styles.audioAttachment, styles.beforeText)
272
- }, buildAudioAttachment()) : null, /*#__PURE__*/React.createElement(Text, {
273
- className: styles.messageBody,
274
- body: messageBody,
275
- textStyle: messageStyle
276
- }), audio && !putAudioBeforeText ? /*#__PURE__*/React.createElement("div", {
277
- className: classNames(styles.audioAttachment, styles.afterText)
278
- }, buildAudioAttachment()) : null))) : null;
279
- };
280
- ConversationMessage.propTypes = propTypes$1;
281
- ConversationMessage.defaultProps = defaultProps$1;
282
- var ConversationMessage$1 = ConversationMessage;
283
-
284
- var propTypes = {
285
- // id: PropTypes.string,
286
- // layout: PropTypes.oneOf(['normal']),
287
- title: core.PropTypes.headingElement,
288
- timing: PropTypes.oneOf(['instant', 'sequence']),
289
- readingSpeed: PropTypes.number,
290
- spacing: PropTypes.number,
291
- background: core.PropTypes.backgroundElement,
292
- header: core.PropTypes.header,
293
- footer: core.PropTypes.footer,
294
- current: PropTypes.bool,
295
- active: PropTypes.bool,
296
- type: PropTypes.string,
297
- conversation: core.PropTypes.conversation,
298
- transitions: core.PropTypes.transitions,
299
- className: PropTypes.string
300
- };
301
- var defaultProps = {
302
- // layout: 'normal',
303
- title: null,
304
- timing: 'sequence',
305
- readingSpeed: 255,
306
- spacing: 20,
307
- background: null,
308
- header: null,
309
- footer: null,
310
- current: true,
311
- active: true,
312
- type: null,
313
- conversation: null,
314
- transitions: null,
315
- className: null
316
- };
317
- var ConversationScreen = function ConversationScreen(_ref) {
318
- var title = _ref.title,
319
- timingMode = _ref.timing,
320
- readingSpeed = _ref.readingSpeed,
321
- spacing = _ref.spacing,
322
- background = _ref.background,
323
- header = _ref.header,
324
- footer = _ref.footer,
325
- current = _ref.current,
326
- active = _ref.active,
327
- type = _ref.type,
328
- conversation = _ref.conversation,
329
- transitions = _ref.transitions,
330
- className = _ref.className;
331
- var _useScreenSize = contexts.useScreenSize(),
332
- width = _useScreenSize.width,
333
- height = _useScreenSize.height,
334
- resolution = _useScreenSize.resolution;
335
- var _useViewerContext = contexts.useViewerContext(),
336
- viewerTopHeight = _useViewerContext.topHeight,
337
- viewerBottomHeight = _useViewerContext.bottomHeight,
338
- viewerBottomSidesWidth = _useViewerContext.bottomSidesWidth;
339
- var _useViewerWebView = contexts.useViewerWebView(),
340
- openWebView = _useViewerWebView.open;
341
- var trackScreenEvent = hooks.useTrackScreenEvent(type);
342
- var _usePlaybackContext = contexts.usePlaybackContext(),
343
- muted = _usePlaybackContext.muted;
344
- var mediaRef = contexts.usePlaybackMediaRef(current);
345
- var audioEventsChannel = new BroadcastChannel("conversation_".concat(uuid.v1(), "_audioEvents"));
346
- var _useScreenRenderConte = contexts.useScreenRenderContext(),
347
- isView = _useScreenRenderConte.isView,
348
- isPreview = _useScreenRenderConte.isPreview,
349
- isPlaceholder = _useScreenRenderConte.isPlaceholder,
350
- isEdit = _useScreenRenderConte.isEdit,
351
- isStatic = _useScreenRenderConte.isStatic,
352
- isCapture = _useScreenRenderConte.isCapture;
353
- var backgroundPlaying = current && (isView || isEdit);
354
- var mediaShouldLoad = current || active;
355
- var withAnimation = isView && !isStatic && timingMode === 'sequence';
356
- var _ref2 = conversation || {},
357
- _ref2$speakers = _ref2.speakers,
358
- speakers = _ref2$speakers === void 0 ? null : _ref2$speakers,
359
- _ref2$messages = _ref2.messages,
360
- messages = _ref2$messages === void 0 ? [] : _ref2$messages,
361
- messageStyle = _ref2.messageStyle,
362
- speakerStyle = _ref2.speakerStyle;
363
- var _useState = React.useState([]),
364
- _useState2 = _slicedToArray(_useState, 2),
365
- conversationState = _useState2[0],
366
- setConversationState = _useState2[1];
367
- var chatBottomRef = React.useRef(null);
368
- var hasHeader = utils.isHeaderFilled(header);
369
- var hasFooter = utils.isFooterFilled(footer);
370
- var footerProps = utils.getFooterProps(footer, {
371
- isView: isView,
372
- current: current,
373
- openWebView: openWebView,
374
- isPreview: isPreview
375
- });
376
- var hasTitle = utils.isTextFilled(title);
377
- var _useDimensionObserver = hooks.useDimensionObserver(),
378
- contentRef = _useDimensionObserver.ref,
379
- scrollHeight = _useDimensionObserver.height;
380
- var scrollRef = React.useRef(null);
381
- React.useEffect(function () {
382
- if (withAnimation && scrollRef.current !== null) {
383
- scrollRef.current.scrollTo({
384
- top: scrollHeight,
385
- behavior: 'smooth'
386
- });
387
- }
388
- }, [scrollHeight, withAnimation]);
389
- var animationFinished = messages.length === conversationState.length;
390
- var conversationStateChange = React.useCallback(function (state) {
391
- var newConversationState = _toConsumableArray(conversationState);
392
- if (state === 'send') {
393
- newConversationState.push(true);
394
- setConversationState(newConversationState);
395
- }
396
- }, [conversationState, setConversationState]);
397
-
398
- // sequence timings
399
- var defaultHesitationDelay = 1500;
400
- var imageReadDelay = 5000; // 5 seconds
401
- var millisecondsPerWord = 60 * 1000 / readingSpeed;
402
- var filteredMessages = (messages || []).filter(function (m) {
403
- return m !== null;
404
- });
405
- var timings = filteredMessages.map(function (messageParams, messageIndex) {
406
- if (messageIndex === 0) {
407
- return 0;
408
- }
409
- var _ref3 = messageParams || {},
410
- _ref3$timing = _ref3.timing,
411
- timing = _ref3$timing === void 0 ? null : _ref3$timing,
412
- _ref3$message = _ref3.message,
413
- message = _ref3$message === void 0 ? null : _ref3$message,
414
- image = _ref3.image,
415
- audio = _ref3.audio,
416
- timingOverrides = _ref3.timingOverrides;
417
- if (timing !== null) {
418
- return timing;
419
- }
420
- if (timingOverrides !== null && timingOverrides !== void 0 && timingOverrides.enabled && Number.isFinite(timingOverrides === null || timingOverrides === void 0 ? void 0 : timingOverrides.writingDuration)) {
421
- return timingOverrides.writingDuration * 1000; // seconds to milliseconds
422
- }
423
-
424
- // if the current message has an audio attachment, use the time it takes to record that message
425
- if (audio) {
426
- return audio.metadata.duration;
427
- }
428
-
429
- // counting words: only keep whitespaces and alphanumeric characters, then split of whitespaces
430
- var wordCount = message ? message.replace(/[^\w\d\s]/g, '').trim().split(/\s/g).length : 0;
431
- var finalTimeMs = wordCount * millisecondsPerWord;
432
-
433
- // if the message includes an image, add some more time to "read" it
434
- if (image) {
435
- finalTimeMs += imageReadDelay;
436
- }
437
- return finalTimeMs;
438
- });
439
- var hesitationTimings = filteredMessages.map(function (messageParams, messageIndex) {
440
- var timingOverrides = messageParams.timingOverrides;
441
- if (messageIndex !== 0 && timingOverrides !== null && timingOverrides !== void 0 && timingOverrides.enabled && Number.isFinite(timingOverrides === null || timingOverrides === void 0 ? void 0 : timingOverrides.appearDelay)) {
442
- return timingOverrides.appearDelay * 1000; // seconds to milliseconds
443
- }
444
- return defaultHesitationDelay;
445
- });
446
- var messagesUniqueId = React.useMemo(function () {
447
- return (messages || []).map(function () {
448
- return uuid.v1();
449
- });
450
- }, [messages]);
451
-
452
- // scroll
453
- var transitionDisabled = isStatic || isCapture || isPlaceholder || isPreview || isEdit;
454
- var scrollingDisabled = !isEdit && transitionDisabled || !current;
455
- var _useState3 = React.useState(false),
456
- _useState4 = _slicedToArray(_useState3, 2),
457
- scrolledBottom = _useState4[0],
458
- setScrolledBottom = _useState4[1];
459
- var showFooter = animationFinished && !isPlaceholder && hasFooter || !withAnimation;
460
- var onScrolledBottom = React.useCallback(function (_ref4) {
461
- var initial = _ref4.initial;
462
- if (initial) {
463
- trackScreenEvent('scroll', 'Screen');
464
- }
465
- setScrolledBottom(true);
466
- }, [trackScreenEvent]);
467
- var onScrolledNotBottom = React.useCallback(function () {
468
- setScrolledBottom(false);
469
- }, [setScrolledBottom]);
470
- return /*#__PURE__*/React.createElement("div", {
471
- className: classNames([styles.container, _defineProperty(_defineProperty({}, className, className !== null), styles.isPlaceholder, isPlaceholder)]),
472
- "data-screen-ready": true
473
- }, /*#__PURE__*/React.createElement(Container, {
474
- width: width,
475
- height: height,
476
- className: styles.content
477
- }, /*#__PURE__*/React.createElement(Scroll, {
478
- ref: scrollRef,
479
- disabled: scrollingDisabled,
480
- onScrolledBottom: onScrolledBottom,
481
- onScrolledNotBottom: onScrolledNotBottom,
482
- withShadow: true
483
- }, /*#__PURE__*/React.createElement("div", {
484
- ref: contentRef
485
- }, /*#__PURE__*/React.createElement(Layout, {
486
- className: styles.layout,
487
- style: !isPlaceholder ? {
488
- padding: spacing,
489
- paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing / 2,
490
- paddingBottom: (current && !isPreview ? viewerBottomHeight : 0) + spacing / 2
491
- } : null
492
- }, !isPlaceholder && hasHeader ? /*#__PURE__*/React.createElement("div", {
493
- key: "header",
494
- style: {
495
- paddingBottom: spacing
496
- }
497
- }, /*#__PURE__*/React.createElement(Header, header)) : null, /*#__PURE__*/React.createElement(components.ScreenElement, {
498
- placeholder: "conversation",
499
- emptyLabel: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
500
- id: "NmCfTO",
501
- defaultMessage: [{
502
- "type": 0,
503
- "value": "Conversation"
504
- }]
505
- }),
506
- emptyClassName: styles.empty,
507
- isEmpty: messages.length === 0 && title === null
508
- }, /*#__PURE__*/React.createElement(components.Transitions, {
509
- transitions: transitions,
510
- playing: current,
511
- disabled: transitionDisabled
512
- }, hasTitle ? /*#__PURE__*/React.createElement(Heading, Object.assign({}, title, {
513
- className: styles.title,
514
- isEmpty: title === null
515
- })) : null, /*#__PURE__*/React.createElement("div", {
516
- className: styles.conversation
517
- }, filteredMessages.map(function (m, messageI) {
518
- var previousMessage = messageI !== 0 ? messages[messageI - 1] : null;
519
- var nextMessage = messageI + 1 < messages.length ? messages[messageI + 1] : null;
520
- var speaker = m.speaker;
521
- var currentSpeaker = (speakers || []).find(function (s) {
522
- return s.id === speaker;
523
- }) || null;
524
- var shouldPlay = messageI === 0 || conversationState[messageI - 1] === true;
525
- var pauseTiming = hesitationTimings[messageI];
526
- var typingTiming = timings[messageI];
527
- var messageId = "".concat(m.message, "-").concat(messagesUniqueId[messageI]);
528
- var nextAudioMessage = filteredMessages.slice(messageI + 1).find(function (c) {
529
- return c.audio != null;
530
- });
531
- var nextAudioMessageId = nextAudioMessage ? "".concat(m.message, "-").concat(messagesUniqueId[filteredMessages.indexOf(nextAudioMessage)]) : null;
532
- return /*#__PURE__*/React.createElement(ConversationMessage$1, {
533
- key: messageId,
534
- message: m,
535
- messageId: messageId,
536
- previousMessage: previousMessage,
537
- nextMessage: nextMessage,
538
- nextAudioMessageId: nextAudioMessageId,
539
- nextMessageState: conversationState[messageI + 1] || !withAnimation,
540
- currentSpeaker: currentSpeaker,
541
- conversationTiming: pauseTiming,
542
- typingTiming: typingTiming,
543
- onChange: conversationStateChange,
544
- withAnimation: withAnimation,
545
- isPlaying: current && shouldPlay,
546
- shouldLoad: mediaShouldLoad,
547
- withoutVideo: isPreview,
548
- messageStyle: messageStyle,
549
- speakerStyle: speakerStyle,
550
- audioEventsChannelName: audioEventsChannel.name
551
- });
552
- })), showFooter ? /*#__PURE__*/React.createElement("div", {
553
- className: classNames([styles.footer, _defineProperty({}, styles.disabled, !scrolledBottom)]),
554
- style: {
555
- paddingLeft: Math.max(viewerBottomSidesWidth - spacing, 0),
556
- paddingRight: Math.max(viewerBottomSidesWidth - spacing, 0),
557
- paddingTop: spacing
558
- }
559
- }, /*#__PURE__*/React.createElement(Footer, footerProps)) : null, /*#__PURE__*/React.createElement("div", {
560
- ref: chatBottomRef
561
- }))))))), !isPlaceholder ? /*#__PURE__*/React.createElement(Background, {
562
- background: background,
563
- width: width,
564
- height: height,
565
- resolution: resolution,
566
- playing: backgroundPlaying,
567
- muted: muted,
568
- shouldLoad: mediaShouldLoad,
569
- mediaRef: mediaRef,
570
- withoutVideo: isPreview,
571
- className: styles.background
572
- }) : null);
573
- };
574
- ConversationScreen.propTypes = propTypes;
575
- ConversationScreen.defaultProps = defaultProps;
576
- var ConversationScreen$1 = ConversationScreen;
577
-
578
- var definition = {
579
- id: 'conversation',
580
- type: 'screen',
581
- group: {
582
- label: reactIntl.defineMessage({
583
- id: "fIawTr",
584
- defaultMessage: [{
585
- "type": 0,
586
- "value": "Text"
587
- }]
588
- }),
589
- order: 3
590
- },
591
- title: reactIntl.defineMessage({
592
- id: "rBPIgw",
593
- defaultMessage: [{
594
- "type": 0,
595
- "value": "Conversation"
596
- }]
597
- }),
598
- component: ConversationScreen$1,
599
- layouts: ['normal'],
600
- fields: [
601
- // {
602
- // name: 'theme',
603
- // type: 'select',
604
- // options: [
605
- // {
606
- // value: 'ios',
607
- // label: 'iOS',
608
- // },
609
- // ],
610
- // label: defineMessage({
611
- // defaultMessage: 'Theme',
612
- // description: 'Theme field label',
613
- // }),
614
- // },
615
- {
616
- name: 'timing',
617
- type: 'select',
618
- options: [{
619
- value: 'instant',
620
- label: 'Instant'
621
- }, {
622
- value: 'sequence',
623
- label: 'Sequence'
624
- }],
625
- label: reactIntl.defineMessage({
626
- id: "6DV50M",
627
- defaultMessage: [{
628
- "type": 0,
629
- "value": "Timing"
630
- }]
631
- })
632
- }, {
633
- name: 'title',
634
- type: 'heading-element',
635
- theme: {
636
- textStyle: 'heading1'
637
- },
638
- label: reactIntl.defineMessage({
639
- id: "N25iDO",
640
- defaultMessage: [{
641
- "type": 0,
642
- "value": "Title"
643
- }]
644
- })
645
- }, {
646
- name: 'conversation',
647
- type: 'conversation',
648
- label: reactIntl.defineMessage({
649
- id: "8tANs8",
650
- defaultMessage: [{
651
- "type": 0,
652
- "value": "Conversation"
653
- }]
654
- })
655
- }, {
656
- name: 'readingSpeed',
657
- type: 'number',
658
- defaultValue: 255,
659
- label: reactIntl.defineMessage({
660
- id: "QjbLZ9",
661
- defaultMessage: [{
662
- "type": 0,
663
- "value": "Reading speed (in Words Per Minute)"
664
- }]
665
- })
666
- }, {
667
- name: 'background',
668
- type: 'background',
669
- label: reactIntl.defineMessage({
670
- id: "+MPZRu",
671
- defaultMessage: [{
672
- "type": 0,
673
- "value": "Background"
674
- }]
675
- })
676
- }, {
677
- name: 'header',
678
- type: 'header',
679
- label: reactIntl.defineMessage({
680
- id: "rhuDxI",
681
- defaultMessage: [{
682
- "type": 0,
683
- "value": "Header"
684
- }]
685
- }),
686
- theme: {
687
- badge: {
688
- label: {
689
- textStyle: 'badge'
690
- },
691
- boxStyle: 'badge'
692
- }
693
- }
694
- }, {
695
- name: 'footer',
696
- type: 'footer',
697
- label: reactIntl.defineMessage({
698
- id: "g4nybp",
699
- defaultMessage: [{
700
- "type": 0,
701
- "value": "Footer"
702
- }]
703
- }),
704
- theme: {
705
- callToAction: {
706
- label: {
707
- textStyle: 'cta'
708
- },
709
- boxStyle: 'cta'
710
- }
711
- }
712
- }]
713
- };
714
-
715
- exports.ConversationScreen = ConversationScreen$1;
716
- exports.default = definition;