Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/addons/viewport/src/Tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const ViewportTool: FC = memo(
styles={{
[`iframe[data-is-storybook="true"]`]: {
margin: `auto`,
transition: 'width .3s, height .3s',
transition: 'none',
position: 'relative',
border: `1px solid black`,
boxShadow: '0 0 100px 100vw rgba(0,0,0,0.5)',
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@storybook/manager-api": "7.0.2",
"@storybook/node-logger": "7.0.2",
"@storybook/preview-api": "7.0.2",
"@storybook/telemetry": "7.0.2",
"@storybook/types": "7.0.2",
"@types/node": "^16.0.0",
"@types/react": "^16.14.34",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { sync as readUpSync } from 'read-pkg-up';
import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit/build-angular';

import { CLIOptions } from '@storybook/types';
import { getEnvConfig } from '@storybook/cli';
import { getEnvConfig, versions } from '@storybook/cli';
import { addToGlobalContext } from '@storybook/telemetry';

import { buildStaticStandalone, withTelemetry } from '@storybook/core-server';
import {
Expand All @@ -24,6 +25,8 @@ import { StandaloneOptions } from '../utils/standalone-options';
import { runCompodoc } from '../utils/run-compodoc';
import { errorSummary, printErrorDetails } from '../utils/error-handler';

addToGlobalContext('cliVersion', versions.storybook);

export type StorybookBuilderOptions = JsonObject & {
browserTarget?: string | null;
tsConfig?: string;
Expand Down
6 changes: 4 additions & 2 deletions code/frameworks/angular/src/builders/start-storybook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { sync as findUpSync } from 'find-up';
import { sync as readUpSync } from 'read-pkg-up';

import { CLIOptions } from '@storybook/types';
import { getEnvConfig } from '@storybook/cli';

import { getEnvConfig, versions } from '@storybook/cli';
import { addToGlobalContext } from '@storybook/telemetry';
import { buildDevStandalone, withTelemetry } from '@storybook/core-server';
import {
AssetPattern,
Expand All @@ -24,6 +24,8 @@ import { StandaloneOptions } from '../utils/standalone-options';
import { runCompodoc } from '../utils/run-compodoc';
import { printErrorDetails, errorSummary } from '../utils/error-handler';

addToGlobalContext('cliVersion', versions.storybook);

export type StorybookBuilderOptions = JsonObject & {
browserTarget?: string | null;
tsConfig?: string;
Expand Down
4 changes: 4 additions & 0 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import leven from 'leven';
import { sync as readUpSync } from 'read-pkg-up';

import { logger } from '@storybook/node-logger';
import { addToGlobalContext } from '@storybook/telemetry';

import type { CommandOptions } from './generators/types';
import { initiate } from './initiate';
Expand All @@ -20,6 +21,9 @@ import { generateStorybookBabelConfigInCWD } from './babel-config';
import { dev } from './dev';
import { build } from './build';
import { parseList, getEnvConfig } from './utils';
import versions from './versions';

addToGlobalContext('cliVersion', versions.storybook);

const pkg = readUpSync({ cwd: __dirname }).packageJson;
const consoleLogger = console;
Expand Down
4 changes: 4 additions & 0 deletions code/lib/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import versions from './versions';

export { versions };

export * from './js-package-manager';
export * from './utils';
9 changes: 8 additions & 1 deletion code/lib/manager-api/src/modules/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { global } from '@storybook/global';
import { PREVIEW_KEYDOWN } from '@storybook/core-events';
import { FORCE_REMOUNT, PREVIEW_KEYDOWN } from '@storybook/core-events';

import type { ModuleFn } from '../index';

Expand Down Expand Up @@ -57,6 +57,7 @@ export interface API_Shortcuts {
escape: API_KeyCollection;
collapseAll: API_KeyCollection;
expandAll: API_KeyCollection;
remount: API_KeyCollection;
}

export type API_Action = keyof API_Shortcuts;
Expand Down Expand Up @@ -91,6 +92,7 @@ export const defaultShortcuts: API_Shortcuts = Object.freeze({
escape: ['escape'], // This one is not customizable
collapseAll: [controlOrMetaKey(), 'shift', 'ArrowUp'],
expandAll: [controlOrMetaKey(), 'shift', 'ArrowDown'],
remount: ['alt', 'R'],
});

const addonsShortcuts: API_AddonShortcuts = {};
Expand Down Expand Up @@ -177,6 +179,7 @@ export const init: ModuleFn = ({ store, fullAPI }) => {
const {
layout: { isFullscreen, showNav, showPanel },
ui: { enableShortcuts },
storyId,
} = store.getState();
if (!enableShortcuts) {
return;
Expand Down Expand Up @@ -320,6 +323,10 @@ export const init: ModuleFn = ({ store, fullAPI }) => {
fullAPI.expandAll();
break;
}
case 'remount': {
fullAPI.emit(FORCE_REMOUNT, { storyId });
break;
}
default:
addonsShortcuts[feature].action();
break;
Expand Down
2 changes: 2 additions & 0 deletions code/lib/telemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export { getStorybookCoreVersion } from './package-json';

export { getPrecedingUpgrade } from './event-cache';

export { addToGlobalContext } from './telemetry';

export const telemetry = async (
eventType: EventType,
payload: Payload = {},
Expand Down
17 changes: 14 additions & 3 deletions code/lib/telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ let tasks: Promise<any>[] = [];
// send telemetry
const sessionId = nanoid();

export const addToGlobalContext = (key: string, value: any) => {
globalContext[key] = value;
};

// context info sent with all events, provided
// by the app. currently:
// - cliVersion
const globalContext = {
inCI: Boolean(process.env.CI),
isTTY: process.stdout.isTTY,
} as Record<string, any>;

export async function sendTelemetry(
data: TelemetryData,
options: Partial<Options> = { retryDelay: 1000, immediate: false }
Expand All @@ -27,11 +39,10 @@ export async function sendTelemetry(
// flatten the data before we send it
const { eventType, payload, metadata, ...rest } = data;
const context = options.stripMetadata
? {}
? globalContext
: {
...globalContext,
anonymousId: getAnonymousProjectId(),
inCI: Boolean(process.env.CI),
isTTY: process.stdout.isTTY,
};
const eventId = nanoid();
const body = { ...rest, eventType, eventId, sessionId, metadata, payload, context };
Expand Down
3 changes: 1 addition & 2 deletions code/presets/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.630821.0",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
"@storybook/types": "7.0.2",
"@types/babel__core": "^7.1.7",
"babel-plugin-react-docgen": "^4.1.0",
Expand All @@ -59,7 +59,6 @@
"devDependencies": {
"@storybook/node-logger": "7.0.2",
"@types/node": "^16.0.0",
"@types/semver": "^7.3.6",
"typescript": "~4.9.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion code/presets/react-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@storybook/docs-tools": "7.0.2",
"@storybook/node-logger": "7.0.2",
"@storybook/react": "7.0.2",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.630821.0",
"@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
"@types/node": "^16.0.0",
"@types/semver": "^7.3.4",
"babel-plugin-add-react-displayname": "^0.0.5",
Expand Down
1 change: 1 addition & 0 deletions code/ui/manager/src/components/layout/app.mockdata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const shortcuts: State['shortcuts'] = {
escape: ['escape'],
collapseAll: ['ctrl', 'shift', 'ArrowUp'],
expandAll: ['ctrl', 'shift', 'ArrowDown'],
remount: ['alt', 'R'],
};

export const panels: Addon_Collection = {
Expand Down
12 changes: 8 additions & 4 deletions code/ui/manager/src/components/preview/tools/remount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const menuMapper = ({ api, state }: Combo) => {
return {
storyId,
remount: () => api.emit(FORCE_REMOUNT, { storyId: state.storyId }),
api,
};
};

Expand All @@ -33,19 +34,22 @@ export const remountTool: Addon = {
match: ({ viewMode }) => viewMode === 'story',
render: () => (
<Consumer filter={menuMapper}>
{({ remount, storyId }) => {
{({ remount, storyId, api }) => {
const [isAnimating, setIsAnimating] = useState(false);
const animateAndReplay = () => {
const remountComponent = () => {
if (!storyId) return;
setIsAnimating(true);
remount();
};

api.on(FORCE_REMOUNT, () => {
setIsAnimating(true);
});

return (
<StyledAnimatedIconButton
key="remount"
title="Remount component"
onClick={animateAndReplay}
onClick={remountComponent}
onAnimationEnd={() => setIsAnimating(false)}
animating={isAnimating}
disabled={!storyId}
Expand Down
1 change: 1 addition & 0 deletions code/ui/manager/src/settings/shortcuts.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defaultShortcuts = {
escape: ['escape'], // This one is not customizable
collapseAll: ['ctrl', 'shift', 'ArrowUp'],
expandAll: ['ctrl', 'shift', 'ArrowDown'],
remount: ['alt', 'R'],
};

const actions = makeActions(
Expand Down
1 change: 1 addition & 0 deletions code/ui/manager/src/settings/shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const shortcutLabels = {
aboutPage: 'Go to about page',
collapseAll: 'Collapse all items on sidebar',
expandAll: 'Expand all items on sidebar',
remount: 'Remount component',
};

export type Feature = keyof typeof shortcutLabels;
Expand Down
16 changes: 8 additions & 8 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5636,6 +5636,7 @@ __metadata:
"@storybook/manager-api": 7.0.2
"@storybook/node-logger": 7.0.2
"@storybook/preview-api": 7.0.2
"@storybook/telemetry": 7.0.2
"@storybook/types": 7.0.2
"@types/node": ^16.0.0
"@types/react": ^16.14.34
Expand Down Expand Up @@ -6663,11 +6664,10 @@ __metadata:
dependencies:
"@pmmmwh/react-refresh-webpack-plugin": ^0.5.1
"@storybook/node-logger": 7.0.2
"@storybook/react-docgen-typescript-plugin": 1.0.6--canary.9.630821.0
"@storybook/react-docgen-typescript-plugin": 1.0.6--canary.9.0c3f3b7.0
"@storybook/types": 7.0.2
"@types/babel__core": ^7.1.7
"@types/node": ^16.0.0
"@types/semver": ^7.3.6
babel-plugin-react-docgen: ^4.1.0
pnp-webpack-plugin: ^1.7.0
semver: ^7.3.5
Expand Down Expand Up @@ -6719,7 +6719,7 @@ __metadata:
"@storybook/docs-tools": 7.0.2
"@storybook/node-logger": 7.0.2
"@storybook/react": 7.0.2
"@storybook/react-docgen-typescript-plugin": 1.0.6--canary.9.630821.0
"@storybook/react-docgen-typescript-plugin": 1.0.6--canary.9.0c3f3b7.0
"@types/node": ^16.0.0
"@types/semver": ^7.3.4
babel-plugin-add-react-displayname: ^0.0.5
Expand Down Expand Up @@ -6894,9 +6894,9 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/react-docgen-typescript-plugin@npm:1.0.6--canary.9.630821.0":
version: 1.0.6--canary.9.630821.0
resolution: "@storybook/react-docgen-typescript-plugin@npm:1.0.6--canary.9.630821.0"
"@storybook/react-docgen-typescript-plugin@npm:1.0.6--canary.9.0c3f3b7.0":
version: 1.0.6--canary.9.0c3f3b7.0
resolution: "@storybook/react-docgen-typescript-plugin@npm:1.0.6--canary.9.0c3f3b7.0"
dependencies:
debug: ^4.1.1
endent: ^2.0.1
Expand All @@ -6908,7 +6908,7 @@ __metadata:
peerDependencies:
typescript: ">= 4.x"
webpack: ">= 4"
checksum: e444a6f2ef67a631ebd35f78a1637c2adbb964d5063a4a088ccf3027c65ca2430826906c70e4972049ef1603aa01ce9c38393704fc2d6de293a627cc40ddc3b2
checksum: 505a728f36df3f519f4985bdf18f2078ea18a1a8f7f837fc831f971363fb7643a182f01a6857a9729ac5a1246d370526fca5a19017f82e7493af4ca945cb7235
languageName: node
linkType: hard

Expand Down Expand Up @@ -8689,7 +8689,7 @@ __metadata:
languageName: node
linkType: hard

"@types/semver@npm:^7.3.12, @types/semver@npm:^7.3.4, @types/semver@npm:^7.3.6":
"@types/semver@npm:^7.3.12, @types/semver@npm:^7.3.4":
version: 7.3.13
resolution: "@types/semver@npm:7.3.13"
checksum: 73295bb1fee46f8c76c7a759feeae5a3022f5bedfdc17d16982092e4b33af17560234fb94861560c20992a702a1e1b9a173bb623a96f95f80892105f5e7d25e3
Expand Down
Loading