@storybook/angular 6.5.0-alpha.27 → 6.5.0-alpha.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/dist/ts3.9/builders/build-storybook/index.js +33 -84
- package/dist/ts3.9/builders/start-storybook/index.js +40 -91
- package/dist/ts3.9/builders/utils/build-standalone-errors-handler.js +13 -11
- package/dist/ts3.9/builders/utils/run-compodoc.js +19 -25
- package/dist/ts3.9/client/preview/angular/app.token.js +1 -1
- package/dist/ts3.9/client/preview/angular/components/app.component.js +55 -59
- package/dist/ts3.9/client/preview/angular/helpers.js +66 -80
- package/dist/ts3.9/client/preview/angular-beta/AbstractRenderer.js +77 -125
- package/dist/ts3.9/client/preview/angular-beta/CanvasRenderer.js +18 -81
- package/dist/ts3.9/client/preview/angular-beta/ComputesTemplateFromComponent.js +53 -73
- package/dist/ts3.9/client/preview/angular-beta/DocsRenderer.js +41 -127
- package/dist/ts3.9/client/preview/angular-beta/RendererFactory.js +30 -66
- package/dist/ts3.9/client/preview/angular-beta/StorybookModule.js +42 -46
- package/dist/ts3.9/client/preview/angular-beta/StorybookProvider.js +15 -17
- package/dist/ts3.9/client/preview/angular-beta/StorybookWrapperComponent.js +63 -92
- package/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer.js +29 -49
- package/dist/ts3.9/client/preview/angular-beta/utils/NgModulesAnalyzer.js +10 -10
- package/dist/ts3.9/client/preview/decorateStory.js +18 -40
- package/dist/ts3.9/client/preview/decorators.js +27 -46
- package/dist/ts3.9/client/preview/globals.js +2 -2
- package/dist/ts3.9/client/preview/index.js +8 -21
- package/dist/ts3.9/client/preview/render.js +17 -56
- package/dist/ts3.9/demo/button.component.js +31 -22
- package/dist/ts3.9/demo/welcome.component.js +85 -18
- package/dist/ts3.9/server/angular-cli-webpack-12.2.x.js +38 -81
- package/dist/ts3.9/server/angular-cli-webpack-13.x.x.js +42 -85
- package/dist/ts3.9/server/angular-cli-webpack-older.js +77 -123
- package/dist/ts3.9/server/angular-devkit-build-webpack.js +72 -133
- package/dist/ts3.9/server/angular-read-workspace.js +44 -78
- package/dist/ts3.9/server/build.js +10 -47
- package/dist/ts3.9/server/create-fork-ts-checker-plugin.js +2 -2
- package/dist/ts3.9/server/framework-preset-angular-cli.js +111 -188
- package/dist/ts3.9/server/framework-preset-angular-ivy.js +35 -92
- package/dist/ts3.9/server/framework-preset-angular.js +62 -115
- package/dist/ts3.9/server/index.js +2 -2
- package/dist/ts3.9/server/ngx-template-loader/index.js +15 -15
- package/dist/ts3.9/server/options.js +1 -1
- package/dist/ts3.9/server/preset.js +4 -13
- package/dist/ts3.9/server/ts_config.js +5 -5
- package/dist/ts3.9/server/utils/filter-out-styling-rules.js +4 -4
- package/dist/ts3.9/server/utils/module-is-available.js +1 -1
- package/dist/ts3.9/server/utils/normalize-asset-patterns.js +16 -31
- package/dist/ts3.9/server/utils/normalize-optimization.js +3 -3
- package/package.json +9 -9
- package/standalone.d.ts +3 -5
|
@@ -1,82 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
-
r[k] = a[j];
|
|
7
|
-
return r;
|
|
8
|
-
};
|
|
9
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
4
|
};
|
|
12
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
6
|
exports.renderNgApp = void 0;
|
|
14
7
|
// @ts-ignore
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}());
|
|
32
|
-
var componentClass = /** @class */ (function () {
|
|
33
|
-
function DynamicComponent() {
|
|
34
|
-
}
|
|
35
|
-
return DynamicComponent;
|
|
36
|
-
}());
|
|
8
|
+
const global_1 = __importDefault(require("global"));
|
|
9
|
+
const core_1 = require("@angular/core");
|
|
10
|
+
const forms_1 = require("@angular/forms");
|
|
11
|
+
const platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic");
|
|
12
|
+
const platform_browser_1 = require("@angular/platform-browser");
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const app_component_1 = require("./components/app.component");
|
|
15
|
+
const app_token_1 = require("./app.token");
|
|
16
|
+
const { document } = global_1.default;
|
|
17
|
+
let platform = null;
|
|
18
|
+
let promises = [];
|
|
19
|
+
let storyData = new rxjs_1.ReplaySubject(1);
|
|
20
|
+
const moduleClass = class DynamicModule {
|
|
21
|
+
};
|
|
22
|
+
const componentClass = class DynamicComponent {
|
|
23
|
+
};
|
|
37
24
|
function storyDataFactory(data) {
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ngZone.run(function () { return subscriber.complete(); });
|
|
46
|
-
});
|
|
47
|
-
return function () {
|
|
48
|
-
sub.unsubscribe();
|
|
49
|
-
};
|
|
25
|
+
return (ngZone) => new rxjs_1.Observable((subscriber) => {
|
|
26
|
+
const sub = data.subscribe((v) => {
|
|
27
|
+
ngZone.run(() => subscriber.next(v));
|
|
28
|
+
}, (err) => {
|
|
29
|
+
ngZone.run(() => subscriber.error(err));
|
|
30
|
+
}, () => {
|
|
31
|
+
ngZone.run(() => subscriber.complete());
|
|
50
32
|
});
|
|
51
|
-
|
|
33
|
+
return () => {
|
|
34
|
+
sub.unsubscribe();
|
|
35
|
+
};
|
|
36
|
+
});
|
|
52
37
|
}
|
|
53
|
-
|
|
38
|
+
const getModule = (declarations, entryComponents, bootstrap, data, moduleMetadata) => {
|
|
54
39
|
// Complete last ReplaySubject and create a new one for the current module
|
|
55
40
|
storyData.complete();
|
|
56
41
|
storyData = new rxjs_1.ReplaySubject(1);
|
|
57
42
|
storyData.next(data);
|
|
58
|
-
|
|
59
|
-
declarations:
|
|
60
|
-
imports:
|
|
61
|
-
providers:
|
|
62
|
-
{ provide: app_token_1.STORY, useFactory: storyDataFactory(storyData.asObservable()), deps: [core_1.NgZone] }
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
const moduleMeta = {
|
|
44
|
+
declarations: [...declarations, ...(moduleMetadata.declarations || [])],
|
|
45
|
+
imports: [platform_browser_1.BrowserModule, forms_1.FormsModule, ...(moduleMetadata.imports || [])],
|
|
46
|
+
providers: [
|
|
47
|
+
{ provide: app_token_1.STORY, useFactory: storyDataFactory(storyData.asObservable()), deps: [core_1.NgZone] },
|
|
48
|
+
...(moduleMetadata.providers || []),
|
|
49
|
+
],
|
|
50
|
+
entryComponents: [...entryComponents, ...(moduleMetadata.entryComponents || [])],
|
|
51
|
+
schemas: [...(moduleMetadata.schemas || [])],
|
|
52
|
+
bootstrap: [...bootstrap],
|
|
67
53
|
};
|
|
68
54
|
return core_1.NgModule(moduleMeta)(moduleClass);
|
|
69
55
|
};
|
|
70
|
-
|
|
56
|
+
const createComponentFromTemplate = (template, styles) => {
|
|
71
57
|
return core_1.Component({
|
|
72
|
-
template
|
|
73
|
-
styles
|
|
58
|
+
template,
|
|
59
|
+
styles,
|
|
74
60
|
})(componentClass);
|
|
75
61
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
const extractNgModuleMetadata = (importItem) => {
|
|
63
|
+
const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
|
|
64
|
+
const decoratorKey = '__annotations__';
|
|
65
|
+
const decorators = Reflect &&
|
|
80
66
|
Reflect.getOwnPropertyDescriptor &&
|
|
81
67
|
Reflect.getOwnPropertyDescriptor(target, decoratorKey)
|
|
82
68
|
? Reflect.getOwnPropertyDescriptor(target, decoratorKey).value
|
|
@@ -84,22 +70,22 @@ var extractNgModuleMetadata = function (importItem) {
|
|
|
84
70
|
if (!decorators || decorators.length === 0) {
|
|
85
71
|
return null;
|
|
86
72
|
}
|
|
87
|
-
|
|
73
|
+
const ngModuleDecorator = decorators.find((decorator) => decorator instanceof core_1.NgModule);
|
|
88
74
|
if (!ngModuleDecorator) {
|
|
89
75
|
return null;
|
|
90
76
|
}
|
|
91
77
|
return ngModuleDecorator;
|
|
92
78
|
};
|
|
93
|
-
|
|
94
|
-
if (declarations && declarations.some(
|
|
79
|
+
const getExistenceOfComponentInModules = (component, declarations, imports) => {
|
|
80
|
+
if (declarations && declarations.some((declaration) => declaration === component)) {
|
|
95
81
|
// Found component in declarations array
|
|
96
82
|
return true;
|
|
97
83
|
}
|
|
98
84
|
if (!imports) {
|
|
99
85
|
return false;
|
|
100
86
|
}
|
|
101
|
-
return imports.some(
|
|
102
|
-
|
|
87
|
+
return imports.some((importItem) => {
|
|
88
|
+
const extractedNgModuleMetadata = extractNgModuleMetadata(importItem);
|
|
103
89
|
if (!extractedNgModuleMetadata) {
|
|
104
90
|
// Not an NgModule
|
|
105
91
|
return false;
|
|
@@ -107,31 +93,31 @@ var getExistenceOfComponentInModules = function (component, declarations, import
|
|
|
107
93
|
return getExistenceOfComponentInModules(component, extractedNgModuleMetadata.declarations, extractedNgModuleMetadata.imports);
|
|
108
94
|
});
|
|
109
95
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
96
|
+
const initModule = (storyFn) => {
|
|
97
|
+
const storyObj = storyFn();
|
|
98
|
+
const { component, template, props, styles, moduleMetadata = {} } = storyObj;
|
|
99
|
+
const isCreatingComponentFromTemplate = Boolean(template);
|
|
100
|
+
const AnnotatedComponent = isCreatingComponentFromTemplate
|
|
115
101
|
? createComponentFromTemplate(template, styles)
|
|
116
102
|
: component;
|
|
117
|
-
|
|
103
|
+
const componentRequiresDeclaration = isCreatingComponentFromTemplate ||
|
|
118
104
|
!getExistenceOfComponentInModules(component, moduleMetadata.declarations, moduleMetadata.imports);
|
|
119
|
-
|
|
105
|
+
const componentDeclarations = componentRequiresDeclaration
|
|
120
106
|
? [app_component_1.AppComponent, AnnotatedComponent]
|
|
121
107
|
: [app_component_1.AppComponent];
|
|
122
|
-
|
|
108
|
+
const story = {
|
|
123
109
|
component: AnnotatedComponent,
|
|
124
|
-
props
|
|
110
|
+
props,
|
|
125
111
|
};
|
|
126
112
|
return getModule(componentDeclarations, [AnnotatedComponent], [app_component_1.AppComponent], story, moduleMetadata);
|
|
127
113
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
const staticRoot = document.getElementById('root');
|
|
115
|
+
const insertDynamicRoot = () => {
|
|
116
|
+
const app = document.createElement('storybook-dynamic-app-root');
|
|
131
117
|
staticRoot.innerHTML = '';
|
|
132
118
|
staticRoot.appendChild(app);
|
|
133
119
|
};
|
|
134
|
-
|
|
120
|
+
const draw = (newModule) => {
|
|
135
121
|
if (!platform) {
|
|
136
122
|
insertDynamicRoot();
|
|
137
123
|
// eslint-disable-next-line no-undef
|
|
@@ -147,15 +133,15 @@ var draw = function (newModule) {
|
|
|
147
133
|
promises.push(platform.bootstrapModule(newModule));
|
|
148
134
|
}
|
|
149
135
|
else {
|
|
150
|
-
Promise.all(promises).then(
|
|
151
|
-
modules.forEach(
|
|
136
|
+
Promise.all(promises).then((modules) => {
|
|
137
|
+
modules.forEach((mod) => mod.destroy());
|
|
152
138
|
insertDynamicRoot();
|
|
153
139
|
promises = [];
|
|
154
140
|
promises.push(platform.bootstrapModule(newModule));
|
|
155
141
|
});
|
|
156
142
|
}
|
|
157
143
|
};
|
|
158
|
-
exports.renderNgApp =
|
|
144
|
+
exports.renderNgApp = (storyFn, forced) => {
|
|
159
145
|
if (!forced) {
|
|
160
146
|
draw(initModule(storyFn));
|
|
161
147
|
}
|
|
@@ -27,51 +27,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
-
function step(op) {
|
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
37
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
-
switch (op[0]) {
|
|
40
|
-
case 0: case 1: t = op; break;
|
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
-
default:
|
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
-
if (t[2]) _.ops.pop();
|
|
50
|
-
_.trys.pop(); continue;
|
|
51
|
-
}
|
|
52
|
-
op = body.call(thisArg, _);
|
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
31
|
exports.AbstractRenderer = void 0;
|
|
59
32
|
/* eslint-disable no-undef */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
33
|
+
const core_1 = require("@angular/core");
|
|
34
|
+
const platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic");
|
|
35
|
+
const rxjs_1 = require("rxjs");
|
|
36
|
+
const telejson_1 = require("telejson");
|
|
37
|
+
const StorybookModule_1 = require("./StorybookModule");
|
|
65
38
|
// platform must be init only if render is called at least once
|
|
66
|
-
|
|
39
|
+
let platformRef;
|
|
67
40
|
function getPlatform(newPlatform) {
|
|
68
41
|
if (!platformRef || newPlatform) {
|
|
69
42
|
platformRef = platform_browser_dynamic_1.platformBrowserDynamic();
|
|
70
43
|
}
|
|
71
44
|
return platformRef;
|
|
72
45
|
}
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
class AbstractRenderer {
|
|
47
|
+
constructor(storyId) {
|
|
75
48
|
this.storyId = storyId;
|
|
76
49
|
if (typeof NODE_ENV === 'string' && NODE_ENV !== 'development') {
|
|
77
50
|
try {
|
|
@@ -87,26 +60,22 @@ var AbstractRenderer = /** @class */ (function () {
|
|
|
87
60
|
/**
|
|
88
61
|
* Wait and destroy the platform
|
|
89
62
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return new Promise(function (resolve) {
|
|
63
|
+
static resetPlatformBrowserDynamic() {
|
|
64
|
+
return new Promise((resolve) => {
|
|
93
65
|
if (platformRef && !platformRef.destroyed) {
|
|
94
|
-
platformRef.onDestroy(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return [2 /*return*/];
|
|
98
|
-
});
|
|
99
|
-
}); });
|
|
66
|
+
platformRef.onDestroy(() => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
resolve();
|
|
68
|
+
}));
|
|
100
69
|
// Destroys the current Angular platform and all Angular applications on the page.
|
|
101
70
|
// So call each angular ngOnDestroy and avoid memory leaks
|
|
102
71
|
platformRef.destroy();
|
|
103
72
|
return;
|
|
104
73
|
}
|
|
105
74
|
resolve();
|
|
106
|
-
}).then(
|
|
75
|
+
}).then(() => {
|
|
107
76
|
getPlatform(true);
|
|
108
77
|
});
|
|
109
|
-
}
|
|
78
|
+
}
|
|
110
79
|
/**
|
|
111
80
|
* Bootstrap main angular module with main component or send only new `props` with storyProps$
|
|
112
81
|
*
|
|
@@ -117,45 +86,31 @@ var AbstractRenderer = /** @class */ (function () {
|
|
|
117
86
|
* @param component {Component}
|
|
118
87
|
* @param parameters {Parameters}
|
|
119
88
|
*/
|
|
120
|
-
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (this.storyProps$) {
|
|
144
|
-
this.storyProps$.complete();
|
|
145
|
-
}
|
|
146
|
-
this.storyProps$ = newStoryProps$;
|
|
147
|
-
this.initAngularRootElement(targetDOMNode, targetSelector);
|
|
148
|
-
return [4 /*yield*/, getPlatform().bootstrapModule(StorybookModule_1.createStorybookModule(moduleMetadata), (_b = parameters.bootstrapModuleOptions) !== null && _b !== void 0 ? _b : undefined)];
|
|
149
|
-
case 2:
|
|
150
|
-
_c.sent();
|
|
151
|
-
return [4 /*yield*/, this.afterFullRender()];
|
|
152
|
-
case 3:
|
|
153
|
-
_c.sent();
|
|
154
|
-
return [2 /*return*/];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
89
|
+
render({ storyFnAngular, forced, parameters, component, targetDOMNode, }) {
|
|
90
|
+
var _a;
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const targetSelector = `${this.generateTargetSelectorFromStoryId()}`;
|
|
93
|
+
const newStoryProps$ = new rxjs_1.BehaviorSubject(storyFnAngular.props);
|
|
94
|
+
const moduleMetadata = StorybookModule_1.getStorybookModuleMetadata({ storyFnAngular, component, targetSelector }, newStoryProps$);
|
|
95
|
+
if (!this.fullRendererRequired({
|
|
96
|
+
storyFnAngular,
|
|
97
|
+
moduleMetadata,
|
|
98
|
+
forced,
|
|
99
|
+
})) {
|
|
100
|
+
this.storyProps$.next(storyFnAngular.props);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
yield this.beforeFullRender();
|
|
104
|
+
// Complete last BehaviorSubject and set a new one for the current module
|
|
105
|
+
if (this.storyProps$) {
|
|
106
|
+
this.storyProps$.complete();
|
|
107
|
+
}
|
|
108
|
+
this.storyProps$ = newStoryProps$;
|
|
109
|
+
this.initAngularRootElement(targetDOMNode, targetSelector);
|
|
110
|
+
yield getPlatform().bootstrapModule(StorybookModule_1.createStorybookModule(moduleMetadata), (_a = parameters.bootstrapModuleOptions) !== null && _a !== void 0 ? _a : undefined);
|
|
111
|
+
yield this.afterFullRender();
|
|
157
112
|
});
|
|
158
|
-
}
|
|
113
|
+
}
|
|
159
114
|
/**
|
|
160
115
|
* Only ASCII alphanumerics can be used as HTML tag name.
|
|
161
116
|
* https://html.spec.whatwg.org/#elements-2
|
|
@@ -168,25 +123,24 @@ var AbstractRenderer = /** @class */ (function () {
|
|
|
168
123
|
* @protected
|
|
169
124
|
* @memberof AbstractRenderer
|
|
170
125
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
126
|
+
generateTargetSelectorFromStoryId() {
|
|
127
|
+
const invalidHtmlTag = /[^A-Za-z0-9-]/g;
|
|
128
|
+
const storyIdIsInvalidHtmlTagName = invalidHtmlTag.test(this.storyId);
|
|
174
129
|
return storyIdIsInvalidHtmlTagName
|
|
175
|
-
?
|
|
130
|
+
? `sb-${this.storyId.replace(invalidHtmlTag, '')}-component`
|
|
176
131
|
: this.storyId;
|
|
177
|
-
}
|
|
178
|
-
|
|
132
|
+
}
|
|
133
|
+
initAngularRootElement(targetDOMNode, targetSelector) {
|
|
179
134
|
// Adds DOM element that angular will use as bootstrap component
|
|
180
135
|
// eslint-disable-next-line no-param-reassign
|
|
181
136
|
targetDOMNode.innerHTML = '';
|
|
182
137
|
targetDOMNode.appendChild(document.createElement(targetSelector));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
var
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
storyFnAngular: storyFnAngular,
|
|
138
|
+
}
|
|
139
|
+
fullRendererRequired({ storyFnAngular, moduleMetadata, forced, }) {
|
|
140
|
+
var _a;
|
|
141
|
+
const { previousStoryRenderInfo } = this;
|
|
142
|
+
const currentStoryRender = {
|
|
143
|
+
storyFnAngular,
|
|
190
144
|
moduleMetadataSnapshot: telejson_1.stringify(moduleMetadata),
|
|
191
145
|
};
|
|
192
146
|
this.previousStoryRenderInfo = currentStoryRender;
|
|
@@ -198,37 +152,35 @@ var AbstractRenderer = /** @class */ (function () {
|
|
|
198
152
|
return true;
|
|
199
153
|
}
|
|
200
154
|
// force the rendering if the template has changed
|
|
201
|
-
|
|
202
|
-
((
|
|
155
|
+
const hasChangedTemplate = !!(storyFnAngular === null || storyFnAngular === void 0 ? void 0 : storyFnAngular.template) &&
|
|
156
|
+
((_a = previousStoryRenderInfo === null || previousStoryRenderInfo === void 0 ? void 0 : previousStoryRenderInfo.storyFnAngular) === null || _a === void 0 ? void 0 : _a.template) !== storyFnAngular.template;
|
|
203
157
|
if (hasChangedTemplate) {
|
|
204
158
|
return true;
|
|
205
159
|
}
|
|
206
160
|
// force the rendering if the metadata structure has changed
|
|
207
|
-
|
|
161
|
+
const hasChangedModuleMetadata = currentStoryRender.moduleMetadataSnapshot !== (previousStoryRenderInfo === null || previousStoryRenderInfo === void 0 ? void 0 : previousStoryRenderInfo.moduleMetadataSnapshot);
|
|
208
162
|
return hasChangedModuleMetadata;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
* Reset compiled components because we often want to compile the same component with
|
|
212
|
-
* more than one NgModule.
|
|
213
|
-
*/
|
|
214
|
-
AbstractRenderer.resetCompiledComponents = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
215
|
-
var ɵresetCompiledComponents, e_1;
|
|
216
|
-
return __generator(this, function (_a) {
|
|
217
|
-
switch (_a.label) {
|
|
218
|
-
case 0:
|
|
219
|
-
_a.trys.push([0, 2, , 3]);
|
|
220
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('@angular/core')); })];
|
|
221
|
-
case 1:
|
|
222
|
-
ɵresetCompiledComponents = (_a.sent()).ɵresetCompiledComponents;
|
|
223
|
-
ɵresetCompiledComponents();
|
|
224
|
-
return [3 /*break*/, 3];
|
|
225
|
-
case 2:
|
|
226
|
-
e_1 = _a.sent();
|
|
227
|
-
return [3 /*break*/, 3];
|
|
228
|
-
case 3: return [2 /*return*/];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}); };
|
|
232
|
-
return AbstractRenderer;
|
|
233
|
-
}());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
234
165
|
exports.AbstractRenderer = AbstractRenderer;
|
|
166
|
+
/**
|
|
167
|
+
* Reset compiled components because we often want to compile the same component with
|
|
168
|
+
* more than one NgModule.
|
|
169
|
+
*/
|
|
170
|
+
AbstractRenderer.resetCompiledComponents = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
171
|
+
try {
|
|
172
|
+
// Clear global Angular component cache in order to be able to re-render the same component across multiple stories
|
|
173
|
+
//
|
|
174
|
+
// References:
|
|
175
|
+
// https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/webpack/plugins/hmr/hmr-accept.ts#L50
|
|
176
|
+
// https://github.com/angular/angular/blob/2ebe2bcb2fe19bf672316b05f15241fd7fd40803/packages/core/src/render3/jit/module.ts#L377-L384
|
|
177
|
+
const { ɵresetCompiledComponents } = yield Promise.resolve().then(() => __importStar(require('@angular/core')));
|
|
178
|
+
ɵresetCompiledComponents();
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
/**
|
|
182
|
+
* noop catch
|
|
183
|
+
* This means angular removed or modified ɵresetCompiledComponents
|
|
184
|
+
*/
|
|
185
|
+
}
|
|
186
|
+
});
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -21,77 +8,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
21
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
9
|
});
|
|
23
10
|
};
|
|
24
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
26
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
-
function step(op) {
|
|
29
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
-
while (_) try {
|
|
31
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
32
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
-
switch (op[0]) {
|
|
34
|
-
case 0: case 1: t = op; break;
|
|
35
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
-
default:
|
|
39
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
-
if (t[2]) _.ops.pop();
|
|
44
|
-
_.trys.pop(); continue;
|
|
45
|
-
}
|
|
46
|
-
op = body.call(thisArg, _);
|
|
47
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
12
|
exports.CanvasRenderer = void 0;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
CanvasRenderer.prototype.render = function (options) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, _super.prototype.render.call(this, options)];
|
|
64
|
-
case 1:
|
|
65
|
-
_a.sent();
|
|
66
|
-
return [2 /*return*/];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
13
|
+
const AbstractRenderer_1 = require("./AbstractRenderer");
|
|
14
|
+
class CanvasRenderer extends AbstractRenderer_1.AbstractRenderer {
|
|
15
|
+
render(options) {
|
|
16
|
+
const _super = Object.create(null, {
|
|
17
|
+
render: { get: () => super.render }
|
|
69
18
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0: return [4 /*yield*/, CanvasRenderer.resetPlatformBrowserDynamic()];
|
|
76
|
-
case 1:
|
|
77
|
-
_a.sent();
|
|
78
|
-
return [2 /*return*/];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
yield _super.render.call(this, options);
|
|
81
21
|
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, AbstractRenderer_1.AbstractRenderer.resetCompiledComponents()];
|
|
88
|
-
case 1:
|
|
89
|
-
_a.sent();
|
|
90
|
-
return [2 /*return*/];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
22
|
+
}
|
|
23
|
+
beforeFullRender() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
yield CanvasRenderer.resetPlatformBrowserDynamic();
|
|
93
26
|
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
27
|
+
}
|
|
28
|
+
afterFullRender() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
yield AbstractRenderer_1.AbstractRenderer.resetCompiledComponents();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
97
34
|
exports.CanvasRenderer = CanvasRenderer;
|