@storybook/angular 7.0.0-beta.3 → 7.0.0-beta.30
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.
- package/README.md +66 -0
- package/dist/builders/build-storybook/index.d.ts +5 -3
- package/dist/builders/build-storybook/index.js +7 -3
- package/dist/builders/build-storybook/schema.json +3 -3
- package/dist/builders/start-storybook/index.d.ts +5 -3
- package/dist/builders/start-storybook/index.js +9 -5
- package/dist/builders/start-storybook/schema.json +2 -2
- package/dist/builders/utils/run-compodoc.js +11 -27
- package/dist/builders/utils/run-compodoc.spec.js +42 -0
- package/dist/builders/utils/standalone-options.d.ts +2 -2
- package/dist/client/angular-beta/AbstractRenderer.d.ts +1 -1
- package/dist/client/angular-beta/AbstractRenderer.js +17 -26
- package/dist/client/angular-beta/CanvasRenderer.js +1 -1
- package/dist/client/angular-beta/DocsRenderer.js +5 -3
- package/dist/client/angular-beta/RendererFactory.js +1 -1
- package/dist/client/angular-beta/StorybookModule.d.ts +3 -6
- package/dist/client/angular-beta/StorybookModule.js +4 -45
- package/dist/client/angular-beta/StorybookModule.test.js +51 -36
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +3 -2
- package/dist/client/angular-beta/StorybookWrapperComponent.js +47 -2
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +1 -1
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +43 -5
- package/dist/client/decorateStory.js +1 -1
- package/dist/client/docs/compodoc.js +5 -7
- package/dist/client/docs/config.js +1 -2
- package/dist/client/globals.js +2 -6
- package/dist/client/render.d.ts +1 -0
- package/dist/client/render.js +1 -5
- package/dist/client/types.d.ts +0 -2
- package/dist/index.mjs +13 -0
- package/dist/preset.mjs +26 -0
- package/dist/renderer.d.ts +2 -1
- package/dist/renderer.js +4 -2
- package/dist/renderer.mjs +5 -0
- package/dist/server/framework-preset-angular-cli.d.ts +2 -1
- package/dist/server/framework-preset-angular-cli.js +21 -92
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +15 -13
- package/dist/server/preset-options.d.ts +3 -2
- package/dist/types.mjs +1 -0
- package/package.json +45 -44
- package/template/cli/Button.stories.ts +1 -1
- package/template/cli/Header.stories.ts +2 -2
- package/template/cli/button.component.ts +2 -0
- package/template/components/index.js +2 -2
- package/template/stories/angular-mdx.stories.mdx +1 -1
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +1 -1
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
- package/template/stories/basics/ng-module/import-module.stories.ts +2 -13
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +0 -18
- package/template/stories/core/parameters/bootstrap-options.stories.ts +1 -5
- package/dist/client/angular/helpers.d.ts +0 -8
- package/dist/client/angular/helpers.js +0 -150
- package/dist/server/angular-read-workspace.d.ts +0 -13
- package/dist/server/angular-read-workspace.js +0 -78
- package/dist/server/utils/normalize-asset-patterns.d.ts +0 -7
- package/dist/server/utils/normalize-asset-patterns.js +0 -64
- package/dist/server/utils/normalize-optimization.d.ts +0 -3
- package/dist/server/utils/normalize-optimization.js +0 -21
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Storybook for Angular
|
|
2
2
|
|
|
3
|
+
- [Storybook for Angular](#storybook-for-angular)
|
|
4
|
+
- [Getting Started](#getting-started)
|
|
5
|
+
- [Setup Compodoc](#setup-compodoc)
|
|
6
|
+
- [Support for multi-project workspace](#support-for-multi-project-workspace)
|
|
7
|
+
- [Run Storybook](#run-storybook)
|
|
8
|
+
|
|
3
9
|
Storybook for Angular is a UI development environment for your Angular components.
|
|
4
10
|
With it, you can visualize different states of your UI components and develop them interactively.
|
|
5
11
|
|
|
@@ -15,6 +21,66 @@ cd my-angular-app
|
|
|
15
21
|
npx storybook init
|
|
16
22
|
```
|
|
17
23
|
|
|
24
|
+
### Setup Compodoc
|
|
25
|
+
|
|
26
|
+
When installing, you will be given the option to set up Compodoc, which is a tool for creating documentation for Angular projects.
|
|
27
|
+
|
|
28
|
+
You can include JSDoc comments above components, directives, and other parts of your Angular code to include documentation for those elements. Compodoc uses these comments to generate documentation for your application. In Storybook, it is useful to add explanatory comments above @Inputs and @Outputs, since these are the main elements that Storybook displays in its user interface. The @Inputs and @Outputs are the elements that you can interact with in Storybook, such as controls.
|
|
29
|
+
|
|
30
|
+
## Support for multi-project workspace
|
|
31
|
+
|
|
32
|
+
Storybook supports Angular multi-project workspace. You can setup Storybook for each project in the workspace. When running `npx storybook init` you will be asked for which project Storybook should be set up. Essentially, during initialization, the `angular.json` will be edited to add the Storybook configuration for the selected project. The configuration looks approximately like this:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
// angular.json
|
|
36
|
+
{
|
|
37
|
+
...
|
|
38
|
+
"projects": {
|
|
39
|
+
...
|
|
40
|
+
"your-project": {
|
|
41
|
+
...
|
|
42
|
+
"architect": {
|
|
43
|
+
...
|
|
44
|
+
"storybook": {
|
|
45
|
+
"builder": "@storybook/angular:start-storybook",
|
|
46
|
+
"options": {
|
|
47
|
+
"configDir": ".storybook",
|
|
48
|
+
"browserTarget": "your-project:build",
|
|
49
|
+
"compodoc": false,
|
|
50
|
+
"port": 6006
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"build-storybook": {
|
|
54
|
+
"builder": "@storybook/angular:build-storybook",
|
|
55
|
+
"options": {
|
|
56
|
+
"configDir": ".storybook",
|
|
57
|
+
"browserTarget": "your-project:build",
|
|
58
|
+
"compodoc": false,
|
|
59
|
+
"outputDir": "dist/storybook/your-project"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Run Storybook
|
|
69
|
+
|
|
70
|
+
To run Storybook for a particular project, please run:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
ng run your-project:storybook
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
To build Storybook, run:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
ng run your-project:build-storybook
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You will find the output in `dist/storybook/your-project`.
|
|
83
|
+
|
|
18
84
|
For more information visit: [storybook.js.org](https://storybook.js.org)
|
|
19
85
|
|
|
20
86
|
---
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
2
|
import { JsonObject } from '@angular-devkit/core';
|
|
3
3
|
import { CLIOptions } from '@storybook/types';
|
|
4
|
-
import {
|
|
4
|
+
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
5
|
+
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
6
7
|
browserTarget?: string | null;
|
|
7
8
|
tsConfig?: string;
|
|
9
|
+
docsMode: boolean;
|
|
8
10
|
compodoc: boolean;
|
|
9
11
|
compodocArgs: string[];
|
|
10
|
-
styles?:
|
|
12
|
+
styles?: StyleElement[];
|
|
11
13
|
stylePreprocessorOptions?: StylePreprocessorOptions;
|
|
12
|
-
} & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | '
|
|
14
|
+
} & Pick<CLIOptions, 'outputDir' | 'configDir' | 'loglevel' | 'quiet' | 'webpackStatsJson' | 'disableTelemetry'>;
|
|
13
15
|
export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
|
|
14
16
|
declare const _default: import("@angular-devkit/architect/src/internal").Builder<any>;
|
|
15
17
|
export default _default;
|
|
@@ -16,14 +16,15 @@ function commandBuilder(options, context) {
|
|
|
16
16
|
: (0, rxjs_1.of)({});
|
|
17
17
|
return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
|
|
18
18
|
}), (0, operators_1.map)(({ tsConfig }) => {
|
|
19
|
-
const { browserTarget, stylePreprocessorOptions, styles, configDir,
|
|
19
|
+
const { browserTarget, stylePreprocessorOptions, styles, configDir, docsMode, loglevel, outputDir, quiet, webpackStatsJson, disableTelemetry, } = options;
|
|
20
20
|
const standaloneOptions = {
|
|
21
21
|
packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
|
|
22
22
|
configDir,
|
|
23
|
-
|
|
23
|
+
docsMode,
|
|
24
24
|
loglevel,
|
|
25
25
|
outputDir,
|
|
26
26
|
quiet,
|
|
27
|
+
disableTelemetry,
|
|
27
28
|
angularBrowserTarget: browserTarget,
|
|
28
29
|
angularBuilderContext: context,
|
|
29
30
|
angularBuilderOptions: {
|
|
@@ -52,5 +53,8 @@ async function setup(options, context) {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
function runInstance(options) {
|
|
55
|
-
return (0, rxjs_1.from)((0, core_server_1.
|
|
56
|
+
return (0, rxjs_1.from)((0, core_server_1.withTelemetry)('build', {
|
|
57
|
+
cliOptions: options,
|
|
58
|
+
presetOptions: { ...options, corePresets: [], overridePresets: [] },
|
|
59
|
+
}, () => (0, core_server_1.buildStaticStandalone)(options))).pipe((0, operators_1.catchError)((error) => (0, rxjs_1.throwError)((0, build_standalone_errors_handler_1.buildStandaloneErrorHandler)(error))));
|
|
56
60
|
}
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"webpackStatsJson": {
|
|
56
|
-
"type": "boolean",
|
|
56
|
+
"type": ["boolean", "string"],
|
|
57
57
|
"description": "Write Webpack Stats JSON to disk",
|
|
58
58
|
"default": false
|
|
59
59
|
},
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"type": "array",
|
|
62
62
|
"description": "Global styles to be included in the build.",
|
|
63
63
|
"items": {
|
|
64
|
-
"$ref": "#/definitions/
|
|
64
|
+
"$ref": "#/definitions/styleElement"
|
|
65
65
|
},
|
|
66
66
|
"default": ""
|
|
67
67
|
},
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"additionalProperties": false,
|
|
85
85
|
"definitions": {
|
|
86
|
-
"
|
|
86
|
+
"styleElement": {
|
|
87
87
|
"oneOf": [
|
|
88
88
|
{
|
|
89
89
|
"type": "object",
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
2
|
import { JsonObject } from '@angular-devkit/core';
|
|
3
|
-
import {
|
|
3
|
+
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
4
4
|
import { CLIOptions } from '@storybook/types';
|
|
5
|
+
import { StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
6
7
|
browserTarget?: string | null;
|
|
7
8
|
tsConfig?: string;
|
|
9
|
+
docsMode: boolean;
|
|
8
10
|
compodoc: boolean;
|
|
9
11
|
compodocArgs: string[];
|
|
10
|
-
styles?:
|
|
12
|
+
styles?: StyleElement[];
|
|
11
13
|
stylePreprocessorOptions?: StylePreprocessorOptions;
|
|
12
|
-
} & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | '
|
|
14
|
+
} & Pick<CLIOptions, 'port' | 'host' | 'configDir' | 'https' | 'sslCa' | 'sslCert' | 'sslKey' | 'smokeTest' | 'ci' | 'quiet' | 'disableTelemetry'>;
|
|
13
15
|
export type StorybookBuilderOutput = JsonObject & BuilderOutput & {};
|
|
14
16
|
declare const _default: import("@angular-devkit/architect/src/internal").Builder<any>;
|
|
15
17
|
export default _default;
|
|
@@ -16,12 +16,12 @@ function commandBuilder(options, context) {
|
|
|
16
16
|
: (0, rxjs_1.of)({});
|
|
17
17
|
return runCompodoc$.pipe((0, operators_1.mapTo)({ tsConfig }));
|
|
18
18
|
}), (0, operators_1.map)(({ tsConfig }) => {
|
|
19
|
-
const { browserTarget, stylePreprocessorOptions, styles, ci, configDir,
|
|
19
|
+
const { browserTarget, stylePreprocessorOptions, styles, ci, configDir, docsMode, host, https, port, quiet, smokeTest, sslCa, sslCert, sslKey, disableTelemetry, } = options;
|
|
20
20
|
const standaloneOptions = {
|
|
21
21
|
packageJson: (0, read_pkg_up_1.sync)({ cwd: __dirname }).packageJson,
|
|
22
22
|
ci,
|
|
23
23
|
configDir,
|
|
24
|
-
|
|
24
|
+
docsMode,
|
|
25
25
|
host,
|
|
26
26
|
https,
|
|
27
27
|
port,
|
|
@@ -30,6 +30,7 @@ function commandBuilder(options, context) {
|
|
|
30
30
|
sslCa,
|
|
31
31
|
sslCert,
|
|
32
32
|
sslKey,
|
|
33
|
+
disableTelemetry,
|
|
33
34
|
angularBrowserTarget: browserTarget,
|
|
34
35
|
angularBuilderContext: context,
|
|
35
36
|
angularBuilderOptions: {
|
|
@@ -39,8 +40,8 @@ function commandBuilder(options, context) {
|
|
|
39
40
|
tsConfig,
|
|
40
41
|
};
|
|
41
42
|
return standaloneOptions;
|
|
42
|
-
}), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)(() => {
|
|
43
|
-
return { success: true };
|
|
43
|
+
}), (0, operators_1.switchMap)((standaloneOptions) => runInstance(standaloneOptions)), (0, operators_1.map)((port) => {
|
|
44
|
+
return { success: true, info: { port } };
|
|
44
45
|
}));
|
|
45
46
|
}
|
|
46
47
|
async function setup(options, context) {
|
|
@@ -59,6 +60,9 @@ async function setup(options, context) {
|
|
|
59
60
|
function runInstance(options) {
|
|
60
61
|
return new rxjs_1.Observable((observer) => {
|
|
61
62
|
// This Observable intentionally never complete, leaving the process running ;)
|
|
62
|
-
(0, core_server_1.
|
|
63
|
+
(0, core_server_1.withTelemetry)('dev', {
|
|
64
|
+
cliOptions: options,
|
|
65
|
+
presetOptions: { ...options, corePresets: [], overridePresets: [] },
|
|
66
|
+
}, () => (0, core_server_1.buildDevStandalone)(options).then(({ port }) => observer.next(port), (error) => observer.error((0, build_standalone_errors_handler_1.buildStandaloneErrorHandler)(error))));
|
|
63
67
|
});
|
|
64
68
|
}
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"type": "array",
|
|
84
84
|
"description": "Global styles to be included in the build.",
|
|
85
85
|
"items": {
|
|
86
|
-
"$ref": "#/definitions/
|
|
86
|
+
"$ref": "#/definitions/styleElement"
|
|
87
87
|
},
|
|
88
88
|
"default": ""
|
|
89
89
|
},
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
},
|
|
106
106
|
"additionalProperties": false,
|
|
107
107
|
"definitions": {
|
|
108
|
-
"
|
|
108
|
+
"styleElement": {
|
|
109
109
|
"oneOf": [
|
|
110
110
|
{
|
|
111
111
|
"type": "object",
|
|
@@ -24,10 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.runCompodoc = void 0;
|
|
27
|
-
const child_process_1 = require("child_process");
|
|
28
27
|
const rxjs_1 = require("rxjs");
|
|
29
28
|
const path = __importStar(require("path"));
|
|
29
|
+
const cli_1 = require("@storybook/cli");
|
|
30
30
|
const hasTsConfigArg = (args) => args.indexOf('-p') !== -1;
|
|
31
|
+
const hasOutputArg = (args) => args.indexOf('-d') !== -1 || args.indexOf('--output') !== -1;
|
|
31
32
|
// path.relative is necessary to workaround a compodoc issue with
|
|
32
33
|
// absolute paths on windows machines
|
|
33
34
|
const toRelativePath = (pathToTsConfig) => {
|
|
@@ -37,37 +38,20 @@ const runCompodoc = ({ compodocArgs, tsconfig }, context) => {
|
|
|
37
38
|
return new rxjs_1.Observable((observer) => {
|
|
38
39
|
const tsConfigPath = toRelativePath(tsconfig);
|
|
39
40
|
const finalCompodocArgs = [
|
|
40
|
-
'compodoc',
|
|
41
|
-
// Default options
|
|
42
41
|
...(hasTsConfigArg(compodocArgs) ? [] : ['-p', tsConfigPath]),
|
|
43
|
-
'-d',
|
|
44
|
-
`${context.workspaceRoot}`,
|
|
42
|
+
...(hasOutputArg(compodocArgs) ? [] : ['-d', `${context.workspaceRoot || '.'}`]),
|
|
45
43
|
...compodocArgs,
|
|
46
44
|
];
|
|
45
|
+
const packageManager = cli_1.JsPackageManagerFactory.getPackageManager();
|
|
47
46
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
child.stdout.on('data', (data) => {
|
|
54
|
-
context.logger.info(data.toString());
|
|
55
|
-
});
|
|
56
|
-
child.stderr.on('data', (data) => {
|
|
57
|
-
context.logger.error(data.toString());
|
|
58
|
-
});
|
|
59
|
-
child.on('close', (code) => {
|
|
60
|
-
if (code === 0) {
|
|
61
|
-
observer.next();
|
|
62
|
-
observer.complete();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
observer.error();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
47
|
+
const stdout = packageManager.runScript('compodoc', finalCompodocArgs, context.workspaceRoot);
|
|
48
|
+
context.logger.info(stdout);
|
|
49
|
+
observer.next();
|
|
50
|
+
observer.complete();
|
|
68
51
|
}
|
|
69
|
-
catch (
|
|
70
|
-
|
|
52
|
+
catch (e) {
|
|
53
|
+
context.logger.error(e);
|
|
54
|
+
observer.error();
|
|
71
55
|
}
|
|
72
56
|
});
|
|
73
57
|
};
|
|
@@ -56,4 +56,46 @@ describe('runCompodoc', () => {
|
|
|
56
56
|
shell: true,
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
|
+
it('should run compodoc with default output folder.', async () => {
|
|
60
|
+
runCompodoc({
|
|
61
|
+
compodocArgs: [],
|
|
62
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
63
|
+
}, {
|
|
64
|
+
workspaceRoot: 'path/to/project',
|
|
65
|
+
logger: builderContextLoggerMock,
|
|
66
|
+
})
|
|
67
|
+
.pipe((0, operators_1.take)(1))
|
|
68
|
+
.subscribe();
|
|
69
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], {
|
|
70
|
+
cwd: 'path/to/project',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('should run with custom output folder specified with --output compodocArgs', async () => {
|
|
74
|
+
runCompodoc({
|
|
75
|
+
compodocArgs: ['--output', 'path/to/customFolder'],
|
|
76
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
77
|
+
}, {
|
|
78
|
+
workspaceRoot: 'path/to/project',
|
|
79
|
+
logger: builderContextLoggerMock,
|
|
80
|
+
})
|
|
81
|
+
.pipe((0, operators_1.take)(1))
|
|
82
|
+
.subscribe();
|
|
83
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '--output', 'path/to/customFolder'], {
|
|
84
|
+
cwd: 'path/to/project',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should run with custom output folder specified with -d compodocArgs', async () => {
|
|
88
|
+
runCompodoc({
|
|
89
|
+
compodocArgs: ['-d', 'path/to/customFolder'],
|
|
90
|
+
tsconfig: 'path/to/tsconfig.json',
|
|
91
|
+
}, {
|
|
92
|
+
workspaceRoot: 'path/to/project',
|
|
93
|
+
logger: builderContextLoggerMock,
|
|
94
|
+
})
|
|
95
|
+
.pipe((0, operators_1.take)(1))
|
|
96
|
+
.subscribe();
|
|
97
|
+
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('npx', ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/customFolder'], {
|
|
98
|
+
cwd: 'path/to/project',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
59
101
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuilderContext } from '@angular-devkit/architect';
|
|
2
2
|
import { LoadOptions, CLIOptions, BuilderOptions } from '@storybook/types';
|
|
3
|
-
export type StandaloneOptions =
|
|
3
|
+
export type StandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
|
|
4
4
|
mode?: 'static' | 'dev';
|
|
5
5
|
angularBrowserTarget?: string | null;
|
|
6
6
|
angularBuilderOptions?: Record<string, any> & {
|
|
@@ -9,4 +9,4 @@ export type StandaloneOptions = Partial<CLIOptions & LoadOptions & BuilderOption
|
|
|
9
9
|
};
|
|
10
10
|
angularBuilderContext?: BuilderContext | null;
|
|
11
11
|
tsConfig?: string;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
@@ -9,7 +9,7 @@ export declare abstract class AbstractRenderer {
|
|
|
9
9
|
/**
|
|
10
10
|
* Wait and destroy the platform
|
|
11
11
|
*/
|
|
12
|
-
static
|
|
12
|
+
static resetApplications(): void;
|
|
13
13
|
/**
|
|
14
14
|
* Reset compiled components because we often want to compile the same component with
|
|
15
15
|
* more than one NgModule.
|
|
@@ -26,36 +26,23 @@ var _a;
|
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.AbstractRenderer = void 0;
|
|
28
28
|
const core_1 = require("@angular/core");
|
|
29
|
-
const
|
|
29
|
+
const platform_browser_1 = require("@angular/platform-browser");
|
|
30
30
|
const rxjs_1 = require("rxjs");
|
|
31
31
|
const telejson_1 = require("telejson");
|
|
32
32
|
const StorybookModule_1 = require("./StorybookModule");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!platformRef || newPlatform) {
|
|
37
|
-
platformRef = (0, platform_browser_dynamic_1.platformBrowserDynamic)();
|
|
38
|
-
}
|
|
39
|
-
return platformRef;
|
|
40
|
-
}
|
|
33
|
+
const StorybookProvider_1 = require("./StorybookProvider");
|
|
34
|
+
const StorybookWrapperComponent_1 = require("./StorybookWrapperComponent");
|
|
35
|
+
const applicationRefs = new Set();
|
|
41
36
|
class AbstractRenderer {
|
|
42
37
|
/**
|
|
43
38
|
* Wait and destroy the platform
|
|
44
39
|
*/
|
|
45
|
-
static
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
// Destroys the current Angular platform and all Angular applications on the page.
|
|
52
|
-
// So call each angular ngOnDestroy and avoid memory leaks
|
|
53
|
-
platformRef.destroy();
|
|
54
|
-
return;
|
|
40
|
+
static resetApplications() {
|
|
41
|
+
StorybookWrapperComponent_1.componentNgModules.clear();
|
|
42
|
+
applicationRefs.forEach((appRef) => {
|
|
43
|
+
if (!appRef.destroyed) {
|
|
44
|
+
appRef.destroy();
|
|
55
45
|
}
|
|
56
|
-
resolve();
|
|
57
|
-
}).then(() => {
|
|
58
|
-
getPlatform(true);
|
|
59
46
|
});
|
|
60
47
|
}
|
|
61
48
|
constructor(storyId) {
|
|
@@ -84,23 +71,27 @@ class AbstractRenderer {
|
|
|
84
71
|
async render({ storyFnAngular, forced, parameters, component, targetDOMNode, }) {
|
|
85
72
|
const targetSelector = `${this.generateTargetSelectorFromStoryId()}`;
|
|
86
73
|
const newStoryProps$ = new rxjs_1.BehaviorSubject(storyFnAngular.props);
|
|
87
|
-
const moduleMetadata = (0, StorybookModule_1.getStorybookModuleMetadata)({ storyFnAngular, component, targetSelector }, newStoryProps$);
|
|
88
74
|
if (!this.fullRendererRequired({
|
|
89
75
|
storyFnAngular,
|
|
90
|
-
moduleMetadata
|
|
76
|
+
moduleMetadata: {
|
|
77
|
+
...storyFnAngular.moduleMetadata,
|
|
78
|
+
},
|
|
91
79
|
forced,
|
|
92
80
|
})) {
|
|
93
81
|
this.storyProps$.next(storyFnAngular.props);
|
|
94
82
|
return;
|
|
95
83
|
}
|
|
96
|
-
await this.beforeFullRender();
|
|
97
84
|
// Complete last BehaviorSubject and set a new one for the current module
|
|
98
85
|
if (this.storyProps$) {
|
|
99
86
|
this.storyProps$.complete();
|
|
100
87
|
}
|
|
101
88
|
this.storyProps$ = newStoryProps$;
|
|
102
89
|
this.initAngularRootElement(targetDOMNode, targetSelector);
|
|
103
|
-
|
|
90
|
+
const application = (0, StorybookModule_1.getApplication)({ storyFnAngular, component, targetSelector });
|
|
91
|
+
const applicationRef = await (0, platform_browser_1.bootstrapApplication)(application, {
|
|
92
|
+
providers: [(0, StorybookProvider_1.storyPropsProvider)(newStoryProps$)],
|
|
93
|
+
});
|
|
94
|
+
applicationRefs.add(applicationRef);
|
|
104
95
|
await this.afterFullRender();
|
|
105
96
|
}
|
|
106
97
|
/**
|
|
@@ -7,7 +7,7 @@ class CanvasRenderer extends AbstractRenderer_1.AbstractRenderer {
|
|
|
7
7
|
await super.render(options);
|
|
8
8
|
}
|
|
9
9
|
async beforeFullRender() {
|
|
10
|
-
|
|
10
|
+
CanvasRenderer.resetApplications();
|
|
11
11
|
}
|
|
12
12
|
async afterFullRender() {
|
|
13
13
|
await AbstractRenderer_1.AbstractRenderer.resetCompiledComponents();
|
|
@@ -18,7 +18,7 @@ class DocsRenderer extends AbstractRenderer_1.AbstractRenderer {
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
channel.once(core_events_1.STORY_CHANGED, async () => {
|
|
21
|
-
await DocsRenderer.
|
|
21
|
+
await DocsRenderer.resetApplications();
|
|
22
22
|
});
|
|
23
23
|
/**
|
|
24
24
|
* Destroy and recreate the PlatformBrowserDynamic of angular
|
|
@@ -26,11 +26,13 @@ class DocsRenderer extends AbstractRenderer_1.AbstractRenderer {
|
|
|
26
26
|
* for previous component
|
|
27
27
|
*/
|
|
28
28
|
channel.once(core_events_1.DOCS_RENDERED, async () => {
|
|
29
|
-
await DocsRenderer.
|
|
29
|
+
await DocsRenderer.resetApplications();
|
|
30
30
|
});
|
|
31
31
|
await super.render({ ...options, forced: false });
|
|
32
32
|
}
|
|
33
|
-
async beforeFullRender() {
|
|
33
|
+
async beforeFullRender() {
|
|
34
|
+
DocsRenderer.resetApplications();
|
|
35
|
+
}
|
|
34
36
|
async afterFullRender() {
|
|
35
37
|
await AbstractRenderer_1.AbstractRenderer.resetCompiledComponents();
|
|
36
38
|
}
|
|
@@ -18,7 +18,7 @@ class RendererFactory {
|
|
|
18
18
|
const renderType = (0, exports.getRenderType)(targetDOMNode);
|
|
19
19
|
// keep only instances of the same type
|
|
20
20
|
if (this.lastRenderType && this.lastRenderType !== renderType) {
|
|
21
|
-
await AbstractRenderer_1.AbstractRenderer.
|
|
21
|
+
await AbstractRenderer_1.AbstractRenderer.resetApplications();
|
|
22
22
|
clearRootHTMLElement(renderType);
|
|
23
23
|
this.rendererMap.clear();
|
|
24
24
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { ICollection, StoryFnAngularReturnType } from '../types';
|
|
4
|
-
export declare const getStorybookModuleMetadata: ({ storyFnAngular, component, targetSelector, }: {
|
|
1
|
+
import { StoryFnAngularReturnType } from '../types';
|
|
2
|
+
export declare const getApplication: ({ storyFnAngular, component, targetSelector, }: {
|
|
5
3
|
storyFnAngular: StoryFnAngularReturnType;
|
|
6
4
|
component?: any;
|
|
7
5
|
targetSelector: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const createStorybookModule: (ngModule: NgModule) => Type<unknown>;
|
|
6
|
+
}) => import("@angular/core").Type<any>;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
const core_1 = require("@angular/core");
|
|
11
|
-
const platform_browser_1 = require("@angular/platform-browser");
|
|
12
|
-
const StorybookProvider_1 = require("./StorybookProvider");
|
|
13
|
-
const NgModulesAnalyzer_1 = require("./utils/NgModulesAnalyzer");
|
|
14
|
-
const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
|
|
3
|
+
exports.getApplication = void 0;
|
|
15
4
|
const StorybookWrapperComponent_1 = require("./StorybookWrapperComponent");
|
|
16
5
|
const ComputesTemplateFromComponent_1 = require("./ComputesTemplateFromComponent");
|
|
17
|
-
const
|
|
6
|
+
const getApplication = ({ storyFnAngular, component, targetSelector, }) => {
|
|
18
7
|
const { props, styles, moduleMetadata = {} } = storyFnAngular;
|
|
19
8
|
let { template } = storyFnAngular;
|
|
20
9
|
const hasTemplate = !hasNoTemplate(template);
|
|
@@ -24,39 +13,9 @@ const getStorybookModuleMetadata = ({ storyFnAngular, component, targetSelector,
|
|
|
24
13
|
/**
|
|
25
14
|
* Create a component that wraps generated template and gives it props
|
|
26
15
|
*/
|
|
27
|
-
|
|
28
|
-
const isStandalone = (0, NgComponentAnalyzer_1.isStandaloneComponent)(component);
|
|
29
|
-
// Look recursively (deep) if the component is not already declared by an import module
|
|
30
|
-
const requiresComponentDeclaration = (0, NgComponentAnalyzer_1.isDeclarable)(component) &&
|
|
31
|
-
!(0, NgModulesAnalyzer_1.isComponentAlreadyDeclaredInModules)(component, moduleMetadata.declarations, moduleMetadata.imports) &&
|
|
32
|
-
!isStandalone;
|
|
33
|
-
return {
|
|
34
|
-
declarations: [
|
|
35
|
-
...(requiresComponentDeclaration ? [component] : []),
|
|
36
|
-
ComponentToInject,
|
|
37
|
-
...(moduleMetadata.declarations ?? []),
|
|
38
|
-
],
|
|
39
|
-
imports: [
|
|
40
|
-
platform_browser_1.BrowserModule,
|
|
41
|
-
...(isStandalone ? [component] : []),
|
|
42
|
-
...(moduleMetadata.imports ?? []),
|
|
43
|
-
],
|
|
44
|
-
providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$), ...(moduleMetadata.providers ?? [])],
|
|
45
|
-
entryComponents: [...(moduleMetadata.entryComponents ?? [])],
|
|
46
|
-
schemas: [...(moduleMetadata.schemas ?? [])],
|
|
47
|
-
bootstrap: [ComponentToInject],
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.getStorybookModuleMetadata = getStorybookModuleMetadata;
|
|
51
|
-
const createStorybookModule = (ngModule) => {
|
|
52
|
-
let StorybookModule = class StorybookModule {
|
|
53
|
-
};
|
|
54
|
-
StorybookModule = __decorate([
|
|
55
|
-
(0, core_1.NgModule)(ngModule)
|
|
56
|
-
], StorybookModule);
|
|
57
|
-
return StorybookModule;
|
|
16
|
+
return (0, StorybookWrapperComponent_1.createStorybookWrapperComponent)(targetSelector, template, component, styles, moduleMetadata, props);
|
|
58
17
|
};
|
|
59
|
-
exports.
|
|
18
|
+
exports.getApplication = getApplication;
|
|
60
19
|
function hasNoTemplate(template) {
|
|
61
20
|
return template === null || template === undefined;
|
|
62
21
|
}
|