1 | import { logger } from '@storybook/client-logger';
|
2 | import { getSourceType } from '../modules/refs';
|
3 | export const getEventMetadata = (context, fullAPI) => {
|
4 | const {
|
5 | source,
|
6 | refId,
|
7 | type
|
8 | } = context;
|
9 | const [sourceType, sourceLocation] = getSourceType(source, refId);
|
10 | const ref = refId && fullAPI.getRefs()[refId] ? fullAPI.getRefs()[refId] : fullAPI.findRef(sourceLocation);
|
11 | const meta = {
|
12 | source,
|
13 | sourceType,
|
14 | sourceLocation,
|
15 | refId,
|
16 | ref,
|
17 | type
|
18 | };
|
19 |
|
20 | switch (true) {
|
21 | case typeof refId === 'string':
|
22 | case sourceType === 'local':
|
23 | case sourceType === 'external':
|
24 | {
|
25 | return meta;
|
26 | }
|
27 |
|
28 |
|
29 | default:
|
30 | {
|
31 | logger.warn(`Received a ${type} frame that was not configured as a ref`);
|
32 | return null;
|
33 | }
|
34 | }
|
35 | }; |
\ | No newline at end of file |