@storybook/angular 8.3.0-alpha.0 → 8.3.0-alpha.10
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/dist/builders/build-storybook/index.d.ts +2 -2
- package/dist/builders/build-storybook/index.js +6 -6
- package/dist/builders/build-storybook/index.spec.js +2 -3
- package/dist/builders/start-storybook/index.d.ts +2 -2
- package/dist/builders/start-storybook/index.js +6 -6
- package/dist/builders/start-storybook/index.spec.js +3 -27
- package/dist/builders/utils/run-compodoc.js +4 -27
- package/dist/builders/utils/run-compodoc.spec.js +1 -2
- package/dist/builders/utils/standalone-options.d.ts +1 -1
- package/dist/client/angular-beta/AbstractRenderer.d.ts +16 -15
- package/dist/client/angular-beta/AbstractRenderer.js +17 -16
- package/dist/client/angular-beta/CanvasRenderer.d.ts +1 -1
- package/dist/client/angular-beta/ComputesTemplateFromComponent.d.ts +8 -1
- package/dist/client/angular-beta/ComputesTemplateFromComponent.js +33 -5
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.js +340 -12
- package/dist/client/angular-beta/DocsRenderer.d.ts +1 -1
- package/dist/client/angular-beta/DocsRenderer.js +8 -11
- package/dist/client/angular-beta/RendererFactory.js +1 -1
- package/dist/client/angular-beta/StorybookModule.js +2 -4
- package/dist/client/angular-beta/StorybookModule.test.js +6 -6
- package/dist/client/angular-beta/StorybookProvider.d.ts +1 -1
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +1 -3
- package/dist/client/angular-beta/StorybookWrapperComponent.js +1 -3
- package/dist/client/angular-beta/__testfixtures__/input.component.d.ts +3 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.js +9 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.d.ts +5 -7
- package/dist/client/angular-beta/utils/BootstrapQueue.js +8 -13
- package/dist/client/angular-beta/utils/BootstrapQueue.test.js +5 -4
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.d.ts +4 -11
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +3 -10
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +1 -3
- package/dist/client/angular-beta/utils/PropertyExtractor.js +0 -2
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +2 -2
- package/dist/client/angular-beta/utils/StoryUID.d.ts +8 -9
- package/dist/client/angular-beta/utils/StoryUID.js +9 -12
- package/dist/client/argsToTemplate.d.ts +13 -12
- package/dist/client/argsToTemplate.js +12 -7
- package/dist/client/argsToTemplate.test.js +7 -1
- package/dist/client/decorators.d.ts +5 -6
- package/dist/client/decorators.js +3 -4
- package/dist/client/decorators.test.js +2 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.d.ts +7 -8
- package/dist/client/docs/__testfixtures__/doc-button/input.js +7 -8
- package/dist/client/docs/angular-properties.test.js +9 -12
- package/dist/client/docs/compodoc.d.ts +1 -1
- package/dist/client/docs/compodoc.js +1 -1
- package/dist/client/docs/config.d.ts +1 -1
- package/dist/client/docs/sourceDecorator.d.ts +3 -2
- package/dist/client/docs/sourceDecorator.js +3 -2
- package/dist/client/globals.d.ts +9 -11
- package/dist/client/globals.js +16 -21
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +2 -1
- package/dist/client/portable-stories.d.ts +23 -0
- package/dist/client/portable-stories.js +53 -0
- package/dist/client/render.d.ts +2 -2
- package/dist/client/types.d.ts +7 -7
- package/dist/preset.js +2 -2
- package/dist/preset.mjs +1 -1
- package/dist/server/angular-cli-webpack.js +6 -10
- package/dist/server/framework-preset-angular-cli.js +7 -16
- package/dist/server/framework-preset-angular-ivy.d.ts +2 -2
- package/dist/server/framework-preset-angular-ivy.js +14 -40
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.d.ts +4 -3
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +4 -3
- package/dist/test-setup.js +3 -4
- package/dist/test-setup.mjs +1 -2
- package/dist/types.d.ts +3 -5
- package/package.json +10 -6
- package/scripts/postbuild.js +5 -4
- package/template/cli/button.component.ts +11 -19
- package/template/cli/button.stories.ts +1 -0
- package/template/cli/header.component.ts +47 -50
- package/template/cli/header.stories.ts +1 -1
- package/template/cli/page.component.ts +54 -54
- package/template/cli/page.stories.ts +1 -1
- package/template/components/index.js +1 -1
- package/.eslintrc.js +0 -16
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CLIOptions } from 'storybook/internal/types';
|
|
1
2
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
|
-
import { JsonObject } from '@angular-devkit/core';
|
|
3
3
|
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
4
|
-
import { CLIOptions } from 'storybook/internal/types';
|
|
5
4
|
import { AssetPattern, SourceMapUnion, StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
|
+
import { JsonObject } from '@angular-devkit/core';
|
|
6
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
7
7
|
browserTarget?: string | null;
|
|
8
8
|
tsConfig?: string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("storybook/internal/common");
|
|
4
|
+
const core_server_1 = require("storybook/internal/core-server");
|
|
5
|
+
const telemetry_1 = require("storybook/internal/telemetry");
|
|
3
6
|
const architect_1 = require("@angular-devkit/architect");
|
|
7
|
+
const fd_package_json_1 = require("fd-package-json");
|
|
8
|
+
const find_up_1 = require("find-up");
|
|
4
9
|
const rxjs_1 = require("rxjs");
|
|
5
10
|
const operators_1 = require("rxjs/operators");
|
|
6
|
-
const find_up_1 = require("find-up");
|
|
7
|
-
const fd_package_json_1 = require("fd-package-json");
|
|
8
|
-
const common_1 = require("storybook/internal/common");
|
|
9
|
-
const telemetry_1 = require("storybook/internal/telemetry");
|
|
10
|
-
const core_server_1 = require("storybook/internal/core-server");
|
|
11
|
-
const run_compodoc_1 = require("../utils/run-compodoc");
|
|
12
11
|
const error_handler_1 = require("../utils/error-handler");
|
|
12
|
+
const run_compodoc_1 = require("../utils/run-compodoc");
|
|
13
13
|
(0, telemetry_1.addToGlobalContext)('cliVersion', common_1.versions.storybook);
|
|
14
14
|
const commandBuilder = (options, context) => {
|
|
15
15
|
const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
|
|
@@ -23,12 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
27
|
-
const vitest_1 = require("vitest");
|
|
28
26
|
const architect_1 = require("@angular-devkit/architect");
|
|
29
27
|
const testing_1 = require("@angular-devkit/architect/testing");
|
|
30
28
|
const core_1 = require("@angular-devkit/core");
|
|
31
|
-
const path = __importStar(require("path"));
|
|
29
|
+
const path = __importStar(require("node:path"));
|
|
30
|
+
const vitest_1 = require("vitest");
|
|
32
31
|
const buildDevStandaloneMock = vitest_1.vi.fn();
|
|
33
32
|
const buildStaticStandaloneMock = vitest_1.vi.fn();
|
|
34
33
|
const buildMock = {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CLIOptions } from 'storybook/internal/types';
|
|
1
2
|
import { BuilderOutput } from '@angular-devkit/architect';
|
|
2
|
-
import { JsonObject } from '@angular-devkit/core';
|
|
3
3
|
import { StylePreprocessorOptions } from '@angular-devkit/build-angular';
|
|
4
|
-
import { CLIOptions } from 'storybook/internal/types';
|
|
5
4
|
import { AssetPattern, SourceMapUnion, StyleElement } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
5
|
+
import { JsonObject } from '@angular-devkit/core';
|
|
6
6
|
export type StorybookBuilderOptions = JsonObject & {
|
|
7
7
|
browserTarget?: string | null;
|
|
8
8
|
tsConfig?: string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("storybook/internal/common");
|
|
4
|
+
const core_server_1 = require("storybook/internal/core-server");
|
|
5
|
+
const telemetry_1 = require("storybook/internal/telemetry");
|
|
3
6
|
const architect_1 = require("@angular-devkit/architect");
|
|
7
|
+
const fd_package_json_1 = require("fd-package-json");
|
|
8
|
+
const find_up_1 = require("find-up");
|
|
4
9
|
const rxjs_1 = require("rxjs");
|
|
5
10
|
const operators_1 = require("rxjs/operators");
|
|
6
|
-
const find_up_1 = require("find-up");
|
|
7
|
-
const fd_package_json_1 = require("fd-package-json");
|
|
8
|
-
const common_1 = require("storybook/internal/common");
|
|
9
|
-
const telemetry_1 = require("storybook/internal/telemetry");
|
|
10
|
-
const core_server_1 = require("storybook/internal/core-server");
|
|
11
|
-
const run_compodoc_1 = require("../utils/run-compodoc");
|
|
12
11
|
const error_handler_1 = require("../utils/error-handler");
|
|
12
|
+
const run_compodoc_1 = require("../utils/run-compodoc");
|
|
13
13
|
(0, telemetry_1.addToGlobalContext)('cliVersion', common_1.versions.storybook);
|
|
14
14
|
const commandBuilder = (options, context) => {
|
|
15
15
|
const builder = (0, rxjs_1.from)(setup(options, context)).pipe((0, operators_1.switchMap)(({ tsConfig }) => {
|
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
27
|
-
const vitest_1 = require("vitest");
|
|
28
3
|
const architect_1 = require("@angular-devkit/architect");
|
|
29
4
|
const testing_1 = require("@angular-devkit/architect/testing");
|
|
30
5
|
const core_1 = require("@angular-devkit/core");
|
|
31
|
-
const
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
32
8
|
const buildDevStandaloneMock = vitest_1.vi.fn();
|
|
33
9
|
const buildStaticStandaloneMock = vitest_1.vi.fn();
|
|
34
10
|
const buildMock = {
|
|
@@ -74,7 +50,7 @@ vitest_1.describe.skip('Start Storybook Builder', () => {
|
|
|
74
50
|
});
|
|
75
51
|
// This will either take a Node package name, or a path to the directory
|
|
76
52
|
// for the package.json file.
|
|
77
|
-
await architectHost.addBuilderFromPackage(
|
|
53
|
+
await architectHost.addBuilderFromPackage((0, node_path_1.join)(__dirname, '../../..'));
|
|
78
54
|
});
|
|
79
55
|
(0, vitest_1.beforeEach)(() => {
|
|
80
56
|
buildDevStandaloneMock.mockImplementation((_options) => Promise.resolve(_options));
|
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.runCompodoc = void 0;
|
|
27
|
-
const
|
|
28
|
-
const path = __importStar(require("path"));
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
29
5
|
const common_1 = require("storybook/internal/common");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
30
7
|
const hasTsConfigArg = (args) => args.indexOf('-p') !== -1;
|
|
31
8
|
const hasOutputArg = (args) => args.indexOf('-d') !== -1 || args.indexOf('--output') !== -1;
|
|
32
|
-
//
|
|
9
|
+
// relative is necessary to workaround a compodoc issue with
|
|
33
10
|
// absolute paths on windows machines
|
|
34
11
|
const toRelativePath = (pathToTsConfig) => {
|
|
35
|
-
return
|
|
12
|
+
return (0, node_path_1.isAbsolute)(pathToTsConfig) ? (0, node_path_1.relative)('.', pathToTsConfig) : pathToTsConfig;
|
|
36
13
|
};
|
|
37
14
|
const runCompodoc = ({ compodocArgs, tsconfig }, context) => {
|
|
38
15
|
return new rxjs_1.Observable((observer) => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
-
const vitest_1 = require("vitest");
|
|
5
3
|
const operators_1 = require("rxjs/operators");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
6
5
|
const run_compodoc_1 = require("./run-compodoc");
|
|
7
6
|
const mockRunScript = vitest_1.vi.fn();
|
|
8
7
|
vitest_1.vi.mock('storybook/internal/common', () => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { BuilderOptions, CLIOptions, LoadOptions } from 'storybook/internal/types';
|
|
1
2
|
import { BuilderContext } from '@angular-devkit/architect';
|
|
2
3
|
import { AssetPattern, SourceMapUnion, StyleElement, StylePreprocessorOptions } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
3
|
-
import { LoadOptions, CLIOptions, BuilderOptions } from 'storybook/internal/types';
|
|
4
4
|
export type StandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
|
|
5
5
|
mode?: 'static' | 'dev';
|
|
6
6
|
enableProdMode: boolean;
|
|
@@ -7,14 +7,12 @@ type StoryRenderInfo = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Attribute name for the story UID that may be written to the targetDOMNode.
|
|
9
9
|
*
|
|
10
|
-
* If a target DOM node has a story UID attribute, it will be used as part of
|
|
11
|
-
*
|
|
10
|
+
* If a target DOM node has a story UID attribute, it will be used as part of the selector for the
|
|
11
|
+
* Angular component.
|
|
12
12
|
*/
|
|
13
13
|
export declare const STORY_UID_ATTRIBUTE = "data-sb-story-uid";
|
|
14
14
|
export declare abstract class AbstractRenderer {
|
|
15
|
-
/**
|
|
16
|
-
* Wait and destroy the platform
|
|
17
|
-
*/
|
|
15
|
+
/** Wait and destroy the platform */
|
|
18
16
|
static resetApplications(domNode?: HTMLElement): void;
|
|
19
17
|
protected previousStoryRenderInfo: Map<HTMLElement, StoryRenderInfo>;
|
|
20
18
|
protected storyProps$: Subject<ICollection | undefined>;
|
|
@@ -24,8 +22,12 @@ export declare abstract class AbstractRenderer {
|
|
|
24
22
|
*
|
|
25
23
|
* @param storyFnAngular {StoryFnAngularReturnType}
|
|
26
24
|
* @param forced {boolean} If :
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
*
|
|
26
|
+
* - True render will only use the StoryFn `props' in storyProps observable that will update sotry's
|
|
27
|
+
* component/template properties. Improves performance without reloading the whole
|
|
28
|
+
* module&component if props changes
|
|
29
|
+
* - False fully recharges or initializes angular module & component
|
|
30
|
+
*
|
|
29
31
|
* @param component {Component}
|
|
30
32
|
*/
|
|
31
33
|
render({ storyFnAngular, forced, component, targetDOMNode, }: {
|
|
@@ -35,21 +37,20 @@ export declare abstract class AbstractRenderer {
|
|
|
35
37
|
targetDOMNode: HTMLElement;
|
|
36
38
|
}): Promise<void>;
|
|
37
39
|
/**
|
|
38
|
-
* Only ASCII alphanumerics can be used as HTML tag name.
|
|
39
|
-
* https://html.spec.whatwg.org/#elements-2
|
|
40
|
+
* Only ASCII alphanumerics can be used as HTML tag name. https://html.spec.whatwg.org/#elements-2
|
|
40
41
|
*
|
|
41
42
|
* Therefore, stories break when non-ASCII alphanumerics are included in target selector.
|
|
42
43
|
* https://github.com/storybookjs/storybook/issues/15147
|
|
43
44
|
*
|
|
44
|
-
* This method returns storyId when it doesn't contain any non-ASCII alphanumerics.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* This method returns storyId when it doesn't contain any non-ASCII alphanumerics. Otherwise, it
|
|
46
|
+
* generates a valid HTML tag name from storyId by removing non-ASCII alphanumerics from storyId,
|
|
47
|
+
* prefixing "sb-", and suffixing "-component"
|
|
48
|
+
*
|
|
47
49
|
* @memberof AbstractRenderer
|
|
50
|
+
* @protected
|
|
48
51
|
*/
|
|
49
52
|
protected generateTargetSelectorFromStoryId(id: string): string;
|
|
50
|
-
/**
|
|
51
|
-
* Adds DOM element that angular will use as bootstrap component.
|
|
52
|
-
*/
|
|
53
|
+
/** Adds DOM element that angular will use as bootstrap component. */
|
|
53
54
|
protected initAngularRootElement(targetDOMNode: HTMLElement, targetSelector: string): void;
|
|
54
55
|
private fullRendererRequired;
|
|
55
56
|
}
|
|
@@ -6,23 +6,21 @@ const rxjs_1 = require("rxjs");
|
|
|
6
6
|
const telejson_1 = require("telejson");
|
|
7
7
|
const StorybookModule_1 = require("./StorybookModule");
|
|
8
8
|
const StorybookProvider_1 = require("./StorybookProvider");
|
|
9
|
-
const PropertyExtractor_1 = require("./utils/PropertyExtractor");
|
|
10
9
|
const BootstrapQueue_1 = require("./utils/BootstrapQueue");
|
|
10
|
+
const PropertyExtractor_1 = require("./utils/PropertyExtractor");
|
|
11
11
|
const applicationRefs = new Map();
|
|
12
12
|
/**
|
|
13
13
|
* Attribute name for the story UID that may be written to the targetDOMNode.
|
|
14
14
|
*
|
|
15
|
-
* If a target DOM node has a story UID attribute, it will be used as part of
|
|
16
|
-
*
|
|
15
|
+
* If a target DOM node has a story UID attribute, it will be used as part of the selector for the
|
|
16
|
+
* Angular component.
|
|
17
17
|
*/
|
|
18
18
|
exports.STORY_UID_ATTRIBUTE = 'data-sb-story-uid';
|
|
19
19
|
class AbstractRenderer {
|
|
20
20
|
constructor() {
|
|
21
21
|
this.previousStoryRenderInfo = new Map();
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Wait and destroy the platform
|
|
25
|
-
*/
|
|
23
|
+
/** Wait and destroy the platform */
|
|
26
24
|
static resetApplications(domNode) {
|
|
27
25
|
applicationRefs.forEach((appRef, appDOMNode) => {
|
|
28
26
|
if (!appRef.destroyed && (!domNode || appDOMNode === domNode)) {
|
|
@@ -35,8 +33,12 @@ class AbstractRenderer {
|
|
|
35
33
|
*
|
|
36
34
|
* @param storyFnAngular {StoryFnAngularReturnType}
|
|
37
35
|
* @param forced {boolean} If :
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* - True render will only use the StoryFn `props' in storyProps observable that will update sotry's
|
|
38
|
+
* component/template properties. Improves performance without reloading the whole
|
|
39
|
+
* module&component if props changes
|
|
40
|
+
* - False fully recharges or initializes angular module & component
|
|
41
|
+
*
|
|
40
42
|
* @param component {Component}
|
|
41
43
|
*/
|
|
42
44
|
async render({ storyFnAngular, forced, component, targetDOMNode, }) {
|
|
@@ -86,25 +88,24 @@ class AbstractRenderer {
|
|
|
86
88
|
applicationRefs.set(targetDOMNode, applicationRef);
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
|
-
* Only ASCII alphanumerics can be used as HTML tag name.
|
|
90
|
-
* https://html.spec.whatwg.org/#elements-2
|
|
91
|
+
* Only ASCII alphanumerics can be used as HTML tag name. https://html.spec.whatwg.org/#elements-2
|
|
91
92
|
*
|
|
92
93
|
* Therefore, stories break when non-ASCII alphanumerics are included in target selector.
|
|
93
94
|
* https://github.com/storybookjs/storybook/issues/15147
|
|
94
95
|
*
|
|
95
|
-
* This method returns storyId when it doesn't contain any non-ASCII alphanumerics.
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* This method returns storyId when it doesn't contain any non-ASCII alphanumerics. Otherwise, it
|
|
97
|
+
* generates a valid HTML tag name from storyId by removing non-ASCII alphanumerics from storyId,
|
|
98
|
+
* prefixing "sb-", and suffixing "-component"
|
|
99
|
+
*
|
|
98
100
|
* @memberof AbstractRenderer
|
|
101
|
+
* @protected
|
|
99
102
|
*/
|
|
100
103
|
generateTargetSelectorFromStoryId(id) {
|
|
101
104
|
const invalidHtmlTag = /[^A-Za-z0-9-]/g;
|
|
102
105
|
const storyIdIsInvalidHtmlTagName = invalidHtmlTag.test(id);
|
|
103
106
|
return storyIdIsInvalidHtmlTagName ? `sb-${id.replace(invalidHtmlTag, '')}-component` : id;
|
|
104
107
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Adds DOM element that angular will use as bootstrap component.
|
|
107
|
-
*/
|
|
108
|
+
/** Adds DOM element that angular will use as bootstrap component. */
|
|
108
109
|
initAngularRootElement(targetDOMNode, targetSelector) {
|
|
109
110
|
targetDOMNode.innerHTML = '';
|
|
110
111
|
targetDOMNode.appendChild(document.createElement(targetSelector));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Parameters, StoryFnAngularReturnType } from '../types';
|
|
1
2
|
import { AbstractRenderer } from './AbstractRenderer';
|
|
2
|
-
import { StoryFnAngularReturnType, Parameters } from '../types';
|
|
3
3
|
export declare class CanvasRenderer extends AbstractRenderer {
|
|
4
4
|
render(options: {
|
|
5
5
|
storyFnAngular: StoryFnAngularReturnType;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { Type } from '@angular/core';
|
|
2
1
|
import { ArgTypes } from 'storybook/internal/types';
|
|
2
|
+
import { Type } from '@angular/core';
|
|
3
3
|
import { ICollection } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Returns the property name, if it can be accessed with dot notation. If not, it returns
|
|
6
|
+
* `this['propertyName']`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatPropInTemplate: (propertyName: string) => string;
|
|
4
9
|
/**
|
|
5
10
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
11
|
+
*
|
|
6
12
|
* @param component
|
|
7
13
|
* @param initialProps
|
|
8
14
|
* @param innerTemplate
|
|
@@ -10,6 +16,7 @@ import { ICollection } from '../types';
|
|
|
10
16
|
export declare const computesTemplateFromComponent: (component: Type<unknown>, initialProps?: ICollection, innerTemplate?: string) => string;
|
|
11
17
|
/**
|
|
12
18
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
19
|
+
*
|
|
13
20
|
* @param component
|
|
14
21
|
* @param initialProps
|
|
15
22
|
* @param innerTemplate
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computesTemplateSourceFromComponent = exports.computesTemplateFromComponent = void 0;
|
|
3
|
+
exports.computesTemplateSourceFromComponent = exports.computesTemplateFromComponent = exports.formatPropInTemplate = void 0;
|
|
4
4
|
const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
|
|
5
|
+
/**
|
|
6
|
+
* Check if the name matches the criteria for a valid identifier. A valid identifier can only
|
|
7
|
+
* contain letters, digits, underscores, or dollar signs. It cannot start with a digit.
|
|
8
|
+
*/
|
|
9
|
+
const isValidIdentifier = (name) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
10
|
+
/**
|
|
11
|
+
* Returns the property name, if it can be accessed with dot notation. If not, it returns
|
|
12
|
+
* `this['propertyName']`.
|
|
13
|
+
*/
|
|
14
|
+
const formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']`;
|
|
15
|
+
exports.formatPropInTemplate = formatPropInTemplate;
|
|
5
16
|
const separateInputsOutputsAttributes = (ngComponentInputsOutputs, props = {}) => {
|
|
6
17
|
const inputs = ngComponentInputsOutputs.inputs
|
|
7
18
|
.filter((i) => i.templateName in props)
|
|
@@ -17,6 +28,7 @@ const separateInputsOutputsAttributes = (ngComponentInputsOutputs, props = {}) =
|
|
|
17
28
|
};
|
|
18
29
|
/**
|
|
19
30
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
31
|
+
*
|
|
20
32
|
* @param component
|
|
21
33
|
* @param initialProps
|
|
22
34
|
* @param innerTemplate
|
|
@@ -29,13 +41,28 @@ const computesTemplateFromComponent = (component, initialProps, innerTemplate =
|
|
|
29
41
|
return `<ng-container *ngComponentOutlet="storyComponent"></ng-container>`;
|
|
30
42
|
}
|
|
31
43
|
const { inputs: initialInputs, outputs: initialOutputs } = separateInputsOutputsAttributes(ngComponentInputsOutputs, initialProps);
|
|
32
|
-
const templateInputs = initialInputs.length > 0
|
|
44
|
+
const templateInputs = initialInputs.length > 0
|
|
45
|
+
? ` ${initialInputs.map((i) => `[${i}]="${(0, exports.formatPropInTemplate)(i)}"`).join(' ')}`
|
|
46
|
+
: '';
|
|
33
47
|
const templateOutputs = initialOutputs.length > 0
|
|
34
|
-
? ` ${initialOutputs.map((i) => `(${i})="${i}($event)"`).join(' ')}`
|
|
48
|
+
? ` ${initialOutputs.map((i) => `(${i})="${(0, exports.formatPropInTemplate)(i)}($event)"`).join(' ')}`
|
|
35
49
|
: '';
|
|
36
50
|
return buildTemplate(ngComponentMetadata.selector, innerTemplate, templateInputs, templateOutputs);
|
|
37
51
|
};
|
|
38
52
|
exports.computesTemplateFromComponent = computesTemplateFromComponent;
|
|
53
|
+
/** Stringify an object with a placholder in the circular references. */
|
|
54
|
+
function stringifyCircular(obj) {
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
return JSON.stringify(obj, (key, value) => {
|
|
57
|
+
if (typeof value === 'object' && value !== null) {
|
|
58
|
+
if (seen.has(value)) {
|
|
59
|
+
return '[Circular]';
|
|
60
|
+
}
|
|
61
|
+
seen.add(value);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
39
66
|
const createAngularInputProperty = ({ propertyName, value, argType, }) => {
|
|
40
67
|
let templateValue;
|
|
41
68
|
switch (typeof value) {
|
|
@@ -43,7 +70,7 @@ const createAngularInputProperty = ({ propertyName, value, argType, }) => {
|
|
|
43
70
|
templateValue = `'${value}'`;
|
|
44
71
|
break;
|
|
45
72
|
case 'object':
|
|
46
|
-
templateValue =
|
|
73
|
+
templateValue = stringifyCircular(value)
|
|
47
74
|
.replace(/'/g, '\u2019')
|
|
48
75
|
.replace(/\\"/g, '\u201D')
|
|
49
76
|
.replace(/"([^-"]+)":/g, '$1: ')
|
|
@@ -60,6 +87,7 @@ const createAngularInputProperty = ({ propertyName, value, argType, }) => {
|
|
|
60
87
|
};
|
|
61
88
|
/**
|
|
62
89
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
90
|
+
*
|
|
63
91
|
* @param component
|
|
64
92
|
* @param initialProps
|
|
65
93
|
* @param innerTemplate
|
|
@@ -85,7 +113,7 @@ const computesTemplateSourceFromComponent = (component, initialProps, argTypes)
|
|
|
85
113
|
.join(' ')}`
|
|
86
114
|
: '';
|
|
87
115
|
const templateOutputs = initialOutputs.length > 0
|
|
88
|
-
? ` ${initialOutputs.map((i) => `(${i})="${i}($event)"`).join(' ')}`
|
|
116
|
+
? ` ${initialOutputs.map((i) => `(${i})="${(0, exports.formatPropInTemplate)(i)}($event)"`).join(' ')}`
|
|
89
117
|
: '';
|
|
90
118
|
return buildTemplate(ngComponentMetadata.selector, '', templateInputs, templateOutputs);
|
|
91
119
|
};
|