@storybook/addon-interactions 7.0.0-alpha.1 → 7.0.0-alpha.12

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 (64) hide show
  1. package/README.md +9 -6
  2. package/dist/cjs/Panel.js +139 -232
  3. package/dist/cjs/components/AccountForm/AccountForm.js +198 -298
  4. package/dist/cjs/components/AccountForm/addon-interactions.stories.js +181 -647
  5. package/dist/cjs/components/Interaction.js +202 -0
  6. package/dist/cjs/components/Interaction.stories.js +85 -0
  7. package/dist/cjs/components/InteractionsPanel.js +130 -0
  8. package/dist/cjs/components/InteractionsPanel.stories.js +158 -0
  9. package/dist/cjs/components/List.js +28 -79
  10. package/dist/cjs/components/MatcherResult.js +54 -112
  11. package/dist/cjs/components/MatcherResult.stories.js +49 -29
  12. package/dist/cjs/components/MethodCall.js +190 -261
  13. package/dist/cjs/components/MethodCall.stories.js +232 -257
  14. package/dist/cjs/components/StatusBadge.js +55 -0
  15. package/dist/cjs/components/{StatusBadge/StatusBadge.stories.js → StatusBadge.stories.js} +4 -4
  16. package/dist/cjs/components/StatusIcon.js +65 -0
  17. package/dist/cjs/components/{StatusIcon/StatusIcon.stories.js → StatusIcon.stories.js} +3 -3
  18. package/dist/cjs/components/{Subnav/Subnav.js → Subnav.js} +83 -87
  19. package/dist/cjs/components/{Subnav/Subnav.stories.js → Subnav.stories.js} +8 -7
  20. package/dist/cjs/components/TabStatus.js +27 -0
  21. package/dist/cjs/constants.js +2 -2
  22. package/dist/cjs/manager.js +4 -5
  23. package/dist/cjs/mocks/index.js +144 -23
  24. package/dist/cjs/preset/checkActionsLoaded.js +2 -6
  25. package/dist/cjs/preset/preview.js +45 -66
  26. package/dist/cjs/theme.js +3 -3
  27. package/dist/esm/Panel.js +84 -72
  28. package/dist/esm/components/AccountForm/addon-interactions.stories.js +19 -1
  29. package/dist/esm/components/Interaction.js +173 -0
  30. package/dist/esm/components/{Interaction/Interaction.stories.js → Interaction.stories.js} +14 -7
  31. package/dist/esm/components/InteractionsPanel.js +103 -0
  32. package/dist/esm/components/InteractionsPanel.stories.js +130 -0
  33. package/dist/esm/components/List.js +9 -9
  34. package/dist/esm/components/MatcherResult.js +1 -1
  35. package/dist/esm/components/MethodCall.js +61 -61
  36. package/dist/esm/components/MethodCall.stories.js +106 -20
  37. package/dist/esm/components/{StatusBadge/StatusBadge.js → StatusBadge.js} +0 -0
  38. package/dist/esm/components/{StatusBadge/StatusBadge.stories.js → StatusBadge.stories.js} +0 -0
  39. package/dist/esm/components/{StatusIcon/StatusIcon.js → StatusIcon.js} +1 -1
  40. package/dist/esm/components/{StatusIcon/StatusIcon.stories.js → StatusIcon.stories.js} +0 -0
  41. package/dist/esm/components/{Subnav/Subnav.js → Subnav.js} +6 -2
  42. package/dist/esm/components/{Subnav/Subnav.stories.js → Subnav.stories.js} +2 -1
  43. package/dist/esm/components/TabStatus.js +12 -0
  44. package/dist/esm/mocks/index.js +140 -20
  45. package/dist/esm/preset/preview.js +29 -11
  46. package/dist/types/Panel.d.ts +14 -28
  47. package/dist/types/components/Interaction.d.ts +14 -0
  48. package/dist/types/components/InteractionsPanel.d.ts +33 -0
  49. package/dist/types/components/MethodCall.d.ts +17 -16
  50. package/dist/types/components/{StatusBadge/StatusBadge.d.ts → StatusBadge.d.ts} +0 -0
  51. package/dist/types/components/{StatusIcon/StatusIcon.d.ts → StatusIcon.d.ts} +0 -0
  52. package/dist/types/components/{Subnav/Subnav.d.ts → Subnav.d.ts} +1 -1
  53. package/dist/types/components/TabStatus.d.ts +5 -0
  54. package/dist/types/mocks/index.d.ts +22 -1
  55. package/dist/types/preset/preview.d.ts +1 -2
  56. package/package.json +14 -12
  57. package/dist/cjs/Panel.stories.js +0 -125
  58. package/dist/cjs/components/Interaction/Interaction.js +0 -174
  59. package/dist/cjs/components/Interaction/Interaction.stories.js +0 -144
  60. package/dist/cjs/components/StatusBadge/StatusBadge.js +0 -51
  61. package/dist/cjs/components/StatusIcon/StatusIcon.js +0 -53
  62. package/dist/esm/Panel.stories.js +0 -86
  63. package/dist/esm/components/Interaction/Interaction.js +0 -88
  64. package/dist/types/components/Interaction/Interaction.d.ts +0 -9
package/README.md CHANGED
@@ -41,22 +41,25 @@ Interactions relies on "instrumented" versions of Jest and Testing Library, that
41
41
  `@storybook/testing-library` instead of their original package. You can then use these libraries in your `play` function.
42
42
 
43
43
  ```js
44
+ import { Button } from './Button';
44
45
  import { expect } from '@storybook/jest';
45
46
  import { within, userEvent } from '@storybook/testing-library';
46
47
 
47
48
  export default {
48
49
  title: 'Button',
50
+ component: Button,
49
51
  argTypes: {
50
52
  onClick: { action: true },
51
53
  },
52
54
  };
53
55
 
54
- export const Demo = {
55
- play: async ({ args, canvasElement }) => {
56
- const canvas = within(canvasElement);
57
- await userEvent.click(canvas.getByRole('button'));
58
- await expect(args.onClick).toHaveBeenCalled();
59
- },
56
+ const Template = (args) => <Button {...args} />;
57
+
58
+ export const Demo = Template.bind({});
59
+ Demo.play = async ({ args, canvasElement }) => {
60
+ const canvas = within(canvasElement);
61
+ await userEvent.click(canvas.getByRole('button'));
62
+ await expect(args.onClick).toHaveBeenCalled();
60
63
  };
61
64
  ```
62
65
 
package/dist/cjs/Panel.js CHANGED
@@ -1,102 +1,37 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- require("core-js/modules/es.object.keys.js");
6
-
7
- require("core-js/modules/es.symbol.js");
8
-
9
- require("core-js/modules/es.symbol.description.js");
10
-
11
- require("core-js/modules/es.symbol.iterator.js");
12
-
13
- require("core-js/modules/es.function.name.js");
14
-
15
- require("core-js/modules/es.array.from.js");
16
-
17
- require("core-js/modules/es.weak-map.js");
18
-
19
- require("core-js/modules/es.object.get-own-property-descriptor.js");
20
-
21
3
  Object.defineProperty(exports, "__esModule", {
22
4
  value: true
23
5
  });
24
- exports.Panel = exports.AddonPanelPure = void 0;
25
-
26
- require("core-js/modules/es.array.map.js");
27
-
28
- require("core-js/modules/es.array.iterator.js");
29
-
30
- require("core-js/modules/es.map.js");
31
-
32
- require("core-js/modules/es.object.to-string.js");
33
-
34
- require("core-js/modules/es.string.iterator.js");
35
-
36
- require("core-js/modules/web.dom-collections.iterator.js");
37
-
38
- require("core-js/modules/es.object.assign.js");
39
-
40
- require("core-js/modules/es.array.slice.js");
41
-
42
- require("core-js/modules/es.regexp.exec.js");
43
-
44
- require("core-js/modules/es.string.split.js");
45
-
46
- require("core-js/modules/es.regexp.to-string.js");
6
+ exports.getInteractions = exports.Panel = void 0;
47
7
 
48
8
  var _global = _interopRequireDefault(require("global"));
49
9
 
50
10
  var React = _interopRequireWildcard(require("react"));
51
11
 
52
- var _reactDom = _interopRequireDefault(require("react-dom"));
53
-
54
12
  var _api = require("@storybook/api");
55
13
 
56
14
  var _coreEvents = require("@storybook/core-events");
57
15
 
58
- var _components = require("@storybook/components");
59
-
60
16
  var _instrumenter = require("@storybook/instrumenter");
61
17
 
62
- var _theming = require("@storybook/theming");
63
-
64
- var _StatusIcon = require("./components/StatusIcon/StatusIcon");
65
-
66
- var _Subnav = require("./components/Subnav/Subnav");
18
+ var _InteractionsPanel = require("./components/InteractionsPanel");
67
19
 
68
- var _Interaction = require("./components/Interaction/Interaction");
20
+ var _TabStatus = require("./components/TabStatus");
69
21
 
70
- var _excluded = ["calls", "controls", "controlStates", "interactions", "fileName", "hasException", "isPlaying", "onScrollToEnd", "endRef", "isRerunAnimating", "setIsRerunAnimating"],
71
- _excluded2 = ["status"];
22
+ const _excluded = ["status"];
72
23
 
73
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
74
25
 
75
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
76
27
 
77
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
78
29
 
79
30
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
80
31
 
81
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
82
-
83
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
84
-
85
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
86
-
87
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
88
-
89
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
90
-
91
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
92
-
93
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
94
-
95
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
96
-
97
32
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
98
33
 
99
- var INITIAL_CONTROL_STATES = {
34
+ const INITIAL_CONTROL_STATES = {
100
35
  debugger: false,
101
36
  start: false,
102
37
  back: false,
@@ -104,203 +39,175 @@ var INITIAL_CONTROL_STATES = {
104
39
  next: false,
105
40
  end: false
106
41
  };
107
- var TabIcon = (0, _theming.styled)(_StatusIcon.StatusIcon)({
108
- marginLeft: 5
109
- });
110
-
111
- var TabStatus = function TabStatus(_ref) {
112
- var children = _ref.children;
113
-
114
- var container = _global.default.document.getElementById('tabbutton-interactions');
115
-
116
- return container && /*#__PURE__*/_reactDom.default.createPortal(children, container);
117
- };
118
42
 
119
- var AddonPanelPure = /*#__PURE__*/React.memo(function (_ref2) {
120
- var calls = _ref2.calls,
121
- controls = _ref2.controls,
122
- controlStates = _ref2.controlStates,
123
- interactions = _ref2.interactions,
124
- fileName = _ref2.fileName,
125
- hasException = _ref2.hasException,
126
- isPlaying = _ref2.isPlaying,
127
- onScrollToEnd = _ref2.onScrollToEnd,
128
- endRef = _ref2.endRef,
129
- isRerunAnimating = _ref2.isRerunAnimating,
130
- setIsRerunAnimating = _ref2.setIsRerunAnimating,
131
- panelProps = _objectWithoutProperties(_ref2, _excluded);
132
-
133
- return /*#__PURE__*/React.createElement(_components.AddonPanel, panelProps, controlStates.debugger && interactions.length > 0 && /*#__PURE__*/React.createElement(_Subnav.Subnav, {
134
- controls: controls,
135
- controlStates: controlStates,
136
- status: // eslint-disable-next-line no-nested-ternary
137
- isPlaying ? _instrumenter.CallStates.ACTIVE : hasException ? _instrumenter.CallStates.ERROR : _instrumenter.CallStates.DONE,
138
- storyFileName: fileName,
139
- onScrollToEnd: onScrollToEnd,
140
- isRerunAnimating: isRerunAnimating,
141
- setIsRerunAnimating: setIsRerunAnimating
142
- }), interactions.map(function (call) {
143
- return /*#__PURE__*/React.createElement(_Interaction.Interaction, {
144
- key: call.id,
145
- call: call,
146
- callsById: calls,
147
- controls: controls,
148
- controlStates: controlStates
43
+ const getInteractions = ({
44
+ log,
45
+ calls,
46
+ collapsed,
47
+ setCollapsed
48
+ }) => {
49
+ const callsById = new Map();
50
+ const childCallMap = new Map();
51
+ return log.filter(({
52
+ callId,
53
+ parentId
54
+ }) => {
55
+ if (!parentId) return true;
56
+ childCallMap.set(parentId, (childCallMap.get(parentId) || []).concat(callId));
57
+ return !collapsed.has(parentId);
58
+ }).map(({
59
+ callId,
60
+ status
61
+ }) => Object.assign({}, calls.get(callId), {
62
+ status
63
+ })).map(call => {
64
+ var _callsById$get;
65
+
66
+ const status = call.status === _instrumenter.CallStates.ERROR && ((_callsById$get = callsById.get(call.parentId)) === null || _callsById$get === void 0 ? void 0 : _callsById$get.status) === _instrumenter.CallStates.ACTIVE ? _instrumenter.CallStates.ACTIVE : call.status;
67
+ callsById.set(call.id, Object.assign({}, call, {
68
+ status
69
+ }));
70
+ return Object.assign({}, call, {
71
+ status,
72
+ childCallIds: childCallMap.get(call.id),
73
+ isCollapsed: collapsed.has(call.id),
74
+ toggleCollapsed: () => setCollapsed(ids => {
75
+ if (ids.has(call.id)) ids.delete(call.id);else ids.add(call.id);
76
+ return new Set(ids);
77
+ })
149
78
  });
150
- }), /*#__PURE__*/React.createElement("div", {
151
- ref: endRef
152
- }), !isPlaying && interactions.length === 0 && /*#__PURE__*/React.createElement(_components.Placeholder, null, "No interactions found", /*#__PURE__*/React.createElement(_components.Link, {
153
- href: "https://github.com/storybookjs/storybook/blob/next/addons/interactions/README.md",
154
- target: "_blank",
155
- withArrow: true
156
- }, "Learn how to add interactions to your story")));
157
- });
158
- exports.AddonPanelPure = AddonPanelPure;
159
-
160
- var Panel = function Panel(props) {
161
- var _useChannel;
162
-
163
- var _React$useState = React.useState(),
164
- _React$useState2 = _slicedToArray(_React$useState, 2),
165
- storyId = _React$useState2[0],
166
- setStoryId = _React$useState2[1];
167
-
168
- var _React$useState3 = React.useState(INITIAL_CONTROL_STATES),
169
- _React$useState4 = _slicedToArray(_React$useState3, 2),
170
- controlStates = _React$useState4[0],
171
- setControlStates = _React$useState4[1];
172
-
173
- var _React$useState5 = React.useState(false),
174
- _React$useState6 = _slicedToArray(_React$useState5, 2),
175
- isPlaying = _React$useState6[0],
176
- setPlaying = _React$useState6[1];
177
-
178
- var _React$useState7 = React.useState(false),
179
- _React$useState8 = _slicedToArray(_React$useState7, 2),
180
- isRerunAnimating = _React$useState8[0],
181
- setIsRerunAnimating = _React$useState8[1];
79
+ });
80
+ };
182
81
 
183
- var _React$useState9 = React.useState(),
184
- _React$useState10 = _slicedToArray(_React$useState9, 2),
185
- scrollTarget = _React$useState10[0],
186
- setScrollTarget = _React$useState10[1]; // Calls are tracked in a ref so we don't needlessly rerender.
82
+ exports.getInteractions = getInteractions;
187
83
 
84
+ const Panel = props => {
85
+ const [storyId, setStoryId] = React.useState();
86
+ const [controlStates, setControlStates] = React.useState(INITIAL_CONTROL_STATES);
87
+ const [pausedAt, setPausedAt] = React.useState();
88
+ const [isErrored, setErrored] = React.useState(false);
89
+ const [isPlaying, setPlaying] = React.useState(false);
90
+ const [isRerunAnimating, setIsRerunAnimating] = React.useState(false);
91
+ const [scrollTarget, setScrollTarget] = React.useState();
92
+ const [collapsed, setCollapsed] = React.useState(new Set());
93
+ const [caughtException, setCaughtException] = React.useState();
94
+ const [interactions, setInteractions] = React.useState([]);
95
+ const [interactionsCount, setInteractionsCount] = React.useState(); // Calls are tracked in a ref so we don't needlessly rerender.
188
96
 
189
- var calls = React.useRef(new Map());
97
+ const calls = React.useRef(new Map());
190
98
 
191
- var setCall = function setCall(_ref3) {
192
- var status = _ref3.status,
193
- call = _objectWithoutProperties(_ref3, _excluded2);
99
+ const setCall = _ref => {
100
+ let call = _objectWithoutPropertiesLoose(_ref, _excluded);
194
101
 
195
102
  return calls.current.set(call.id, call);
196
103
  };
197
104
 
198
- var _React$useState11 = React.useState([]),
199
- _React$useState12 = _slicedToArray(_React$useState11, 2),
200
- log = _React$useState12[0],
201
- setLog = _React$useState12[1];
202
-
203
- var interactions = log.map(function (_ref4) {
204
- var callId = _ref4.callId,
205
- status = _ref4.status;
206
- return Object.assign({}, calls.current.get(callId), {
207
- status: status
208
- });
209
- });
210
- var endRef = React.useRef();
211
- React.useEffect(function () {
212
- var observer;
105
+ const endRef = React.useRef();
106
+ React.useEffect(() => {
107
+ let observer;
213
108
 
214
109
  if (_global.default.window.IntersectionObserver) {
215
- observer = new _global.default.window.IntersectionObserver(function (_ref5) {
216
- var _ref6 = _slicedToArray(_ref5, 1),
217
- end = _ref6[0];
218
-
219
- return setScrollTarget(end.isIntersecting ? undefined : end.target);
220
- }, {
110
+ observer = new _global.default.window.IntersectionObserver(([end]) => setScrollTarget(end.isIntersecting ? undefined : end.target), {
221
111
  root: _global.default.window.document.querySelector('#panel-tab-content')
222
112
  });
223
113
  if (endRef.current) observer.observe(endRef.current);
224
114
  }
225
115
 
226
- return function () {
116
+ return () => {
227
117
  var _observer;
228
118
 
229
119
  return (_observer = observer) === null || _observer === void 0 ? void 0 : _observer.disconnect();
230
120
  };
231
121
  }, []);
232
- var emit = (0, _api.useChannel)((_useChannel = {}, _defineProperty(_useChannel, _instrumenter.EVENTS.CALL, setCall), _defineProperty(_useChannel, _instrumenter.EVENTS.SYNC, function (payload) {
233
- setControlStates(payload.controlStates);
234
- setLog(payload.logItems);
235
- }), _defineProperty(_useChannel, _coreEvents.STORY_RENDER_PHASE_CHANGED, function (event) {
236
- setStoryId(event.storyId);
237
- setPlaying(event.newPhase === 'playing');
238
- }), _useChannel), []);
239
- var controls = React.useMemo(function () {
240
- return {
241
- start: function start() {
242
- return emit(_instrumenter.EVENTS.START, {
243
- storyId: storyId
244
- });
245
- },
246
- back: function back() {
247
- return emit(_instrumenter.EVENTS.BACK, {
248
- storyId: storyId
249
- });
250
- },
251
- goto: function goto(callId) {
252
- return emit(_instrumenter.EVENTS.GOTO, {
253
- storyId: storyId,
254
- callId: callId
255
- });
256
- },
257
- next: function next() {
258
- return emit(_instrumenter.EVENTS.NEXT, {
259
- storyId: storyId
260
- });
261
- },
262
- end: function end() {
263
- return emit(_instrumenter.EVENTS.END, {
264
- storyId: storyId
265
- });
266
- },
267
- rerun: function rerun() {
268
- setIsRerunAnimating(true);
269
- emit(_coreEvents.FORCE_REMOUNT, {
270
- storyId: storyId
271
- });
122
+ const emit = (0, _api.useChannel)({
123
+ [_instrumenter.EVENTS.CALL]: setCall,
124
+ [_instrumenter.EVENTS.SYNC]: payload => {
125
+ setControlStates(payload.controlStates);
126
+ setPausedAt(payload.pausedAt);
127
+ setInteractions(getInteractions({
128
+ log: payload.logItems,
129
+ calls: calls.current,
130
+ collapsed,
131
+ setCollapsed
132
+ }));
133
+ },
134
+ [_coreEvents.STORY_RENDER_PHASE_CHANGED]: event => {
135
+ setStoryId(event.storyId);
136
+ setPlaying(event.newPhase === 'playing');
137
+ setPausedAt(undefined);
138
+
139
+ if (event.newPhase === 'rendering') {
140
+ setErrored(false);
141
+ setCaughtException(undefined);
272
142
  }
273
- };
274
- }, [storyId]);
275
- var storyFilePath = (0, _api.useParameter)('fileName', '');
143
+ },
144
+ [_coreEvents.STORY_THREW_EXCEPTION]: () => {
145
+ setErrored(true);
146
+ },
147
+ [_coreEvents.PLAY_FUNCTION_THREW_EXCEPTION]: e => {
148
+ console.log('PLAY_FUNCTION_THREW_EXCEPTION');
149
+ if ((e === null || e === void 0 ? void 0 : e.message) !== _coreEvents.IGNORED_EXCEPTION.message) setCaughtException(e);else setCaughtException(undefined);
150
+ }
151
+ }, [collapsed]);
152
+ React.useEffect(() => {
153
+ if (isPlaying || isRerunAnimating) return;
154
+ setInteractionsCount(interactions.length);
155
+ }, [interactions, isPlaying, isRerunAnimating]);
156
+ const controls = React.useMemo(() => ({
157
+ start: () => emit(_instrumenter.EVENTS.START, {
158
+ storyId
159
+ }),
160
+ back: () => emit(_instrumenter.EVENTS.BACK, {
161
+ storyId
162
+ }),
163
+ goto: callId => emit(_instrumenter.EVENTS.GOTO, {
164
+ storyId,
165
+ callId
166
+ }),
167
+ next: () => emit(_instrumenter.EVENTS.NEXT, {
168
+ storyId
169
+ }),
170
+ end: () => emit(_instrumenter.EVENTS.END, {
171
+ storyId
172
+ }),
173
+ rerun: () => {
174
+ setIsRerunAnimating(true);
175
+ emit(_coreEvents.FORCE_REMOUNT, {
176
+ storyId
177
+ });
178
+ }
179
+ }), [storyId]);
180
+ const storyFilePath = (0, _api.useParameter)('fileName', '');
181
+ const [fileName] = storyFilePath.toString().split('/').slice(-1);
276
182
 
277
- var _storyFilePath$toStri = storyFilePath.toString().split('/').slice(-1),
278
- _storyFilePath$toStri2 = _slicedToArray(_storyFilePath$toStri, 1),
279
- fileName = _storyFilePath$toStri2[0];
183
+ const scrollToTarget = () => scrollTarget === null || scrollTarget === void 0 ? void 0 : scrollTarget.scrollIntoView({
184
+ behavior: 'smooth',
185
+ block: 'end'
186
+ });
280
187
 
281
- var scrollToTarget = function scrollToTarget() {
282
- return scrollTarget === null || scrollTarget === void 0 ? void 0 : scrollTarget.scrollIntoView({
283
- behavior: 'smooth',
284
- block: 'end'
188
+ const showStatus = interactionsCount > 0 || !!caughtException || isRerunAnimating;
189
+ const hasException = !!caughtException || interactions.some(v => v.status === _instrumenter.CallStates.ERROR);
190
+
191
+ if (isErrored) {
192
+ return /*#__PURE__*/React.createElement(React.Fragment, {
193
+ key: "interactions"
285
194
  });
286
- };
195
+ }
287
196
 
288
- var showStatus = log.length > 0 && !isPlaying;
289
- var hasException = log.some(function (item) {
290
- return item.status === _instrumenter.CallStates.ERROR;
291
- });
292
197
  return /*#__PURE__*/React.createElement(React.Fragment, {
293
198
  key: "interactions"
294
- }, /*#__PURE__*/React.createElement(TabStatus, null, showStatus && (hasException ? /*#__PURE__*/React.createElement(TabIcon, {
199
+ }, /*#__PURE__*/React.createElement(_TabStatus.TabStatus, null, showStatus && (hasException ? /*#__PURE__*/React.createElement(_TabStatus.TabIcon, {
295
200
  status: _instrumenter.CallStates.ERROR
296
- }) : " (".concat(interactions.length, ")"))), /*#__PURE__*/React.createElement(AddonPanelPure, _extends({
201
+ }) : ` (${interactionsCount})`)), /*#__PURE__*/React.createElement(_InteractionsPanel.InteractionsPanel, _extends({
297
202
  calls: calls.current,
298
203
  controls: controls,
299
204
  controlStates: controlStates,
300
205
  interactions: interactions,
301
206
  fileName: fileName,
302
207
  hasException: hasException,
208
+ caughtException: caughtException,
303
209
  isPlaying: isPlaying,
210
+ pausedAt: pausedAt,
304
211
  endRef: endRef,
305
212
  onScrollToEnd: scrollTarget && scrollToTarget,
306
213
  isRerunAnimating: isRerunAnimating,