@storybook/angular 6.5.0-alpha.7 → 6.5.0-beta.1
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 +2 -2
- package/dist/ts3.4/builders/build-storybook/index.d.ts +1 -1
- package/dist/ts3.4/client/docs/compodoc.d.ts +18 -0
- package/dist/ts3.4/client/docs/config.d.ts +15 -0
- package/dist/ts3.4/client/docs/index.d.ts +1 -0
- package/dist/ts3.4/client/docs/prepareForInline.d.ts +7 -0
- package/dist/ts3.4/client/docs/sourceDecorator.d.ts +9 -0
- package/dist/ts3.4/client/docs/types.d.ts +102 -0
- package/dist/ts3.4/client/preview/angular-beta/utils/NgComponentAnalyzer.d.ts +4 -2
- package/dist/ts3.4/server/angular-cli-webpack-older.d.ts +2 -1
- package/dist/ts3.4/server/framework-preset-angular-docs.d.ts +2 -0
- package/dist/ts3.4/server/framework-preset-angular.d.ts +3 -2
- package/dist/ts3.4/server/preset.d.ts +1 -1
- package/dist/ts3.9/builders/build-storybook/index.d.ts +2 -2
- package/dist/ts3.9/builders/build-storybook/index.js +34 -84
- package/dist/ts3.9/builders/build-storybook/schema.json +6 -2
- package/dist/ts3.9/builders/start-storybook/index.d.ts +1 -1
- package/dist/ts3.9/builders/start-storybook/index.js +40 -91
- package/dist/ts3.9/builders/start-storybook/schema.json +1 -2
- package/dist/ts3.9/builders/utils/build-standalone-errors-handler.js +13 -11
- package/dist/ts3.9/builders/utils/run-compodoc.js +41 -21
- package/dist/ts3.9/client/docs/compodoc.d.ts +18 -0
- package/dist/ts3.9/client/docs/compodoc.js +247 -0
- package/dist/ts3.9/client/docs/config.d.ts +15 -0
- package/dist/ts3.9/client/docs/config.js +22 -0
- package/dist/ts3.9/client/docs/index.d.ts +1 -0
- package/dist/ts3.9/client/docs/index.js +13 -0
- package/dist/ts3.9/client/docs/prepareForInline.d.ts +7 -0
- package/dist/ts3.9/client/docs/prepareForInline.js +45 -0
- package/dist/ts3.9/client/docs/sourceDecorator.d.ts +9 -0
- package/dist/ts3.9/client/docs/sourceDecorator.js +49 -0
- package/dist/ts3.9/client/docs/types.d.ts +102 -0
- package/dist/ts3.9/client/docs/types.js +2 -0
- 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.d.ts +2 -2
- 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.d.ts +3 -3
- package/dist/ts3.9/client/preview/angular-beta/ComputesTemplateFromComponent.js +75 -69
- 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 +58 -98
- package/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer.d.ts +4 -2
- package/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer.js +30 -77
- package/dist/ts3.9/client/preview/angular-beta/utils/NgModulesAnalyzer.js +10 -14
- package/dist/ts3.9/client/preview/decorateStory.d.ts +2 -2
- package/dist/ts3.9/client/preview/decorateStory.js +16 -36
- package/dist/ts3.9/client/preview/decorators.d.ts +4 -4
- package/dist/ts3.9/client/preview/decorators.js +22 -37
- package/dist/ts3.9/client/preview/globals.js +2 -2
- package/dist/ts3.9/client/preview/index.d.ts +3 -3
- package/dist/ts3.9/client/preview/index.js +8 -21
- package/dist/ts3.9/client/preview/render.d.ts +3 -3
- package/dist/ts3.9/client/preview/render.js +17 -56
- package/dist/ts3.9/client/preview/types-6-0.d.ts +2 -2
- package/dist/ts3.9/client/preview/types-7-0.d.ts +1 -1
- 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/__mocks-ng-workspace__/minimal-config/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/some-config/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/with-angularBrowserTarget/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/with-lib/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/with-nx/tsconfig.json +7 -2
- package/dist/ts3.9/server/__mocks-ng-workspace__/with-nx-workspace/tsconfig.json +7 -2
- package/dist/ts3.9/server/__mocks-ng-workspace__/with-options-styles/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/without-projects-entry/tsconfig.json +4 -1
- package/dist/ts3.9/server/__mocks-ng-workspace__/without-tsConfig/tsconfig.json +4 -1
- 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.d.ts +2 -1
- 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 +3 -3
- package/dist/ts3.9/server/framework-preset-angular-cli.js +111 -179
- package/dist/ts3.9/server/framework-preset-angular-docs.d.ts +2 -0
- package/dist/ts3.9/server/framework-preset-angular-docs.js +13 -0
- package/dist/ts3.9/server/framework-preset-angular-ivy.js +35 -92
- package/dist/ts3.9/server/framework-preset-angular.d.ts +3 -2
- package/dist/ts3.9/server/framework-preset-angular.js +88 -62
- 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.d.ts +1 -1
- package/dist/ts3.9/server/options.js +1 -1
- package/dist/ts3.9/server/preset.d.ts +1 -1
- package/dist/ts3.9/server/preset.js +6 -14
- 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/dist/ts3.9/types/index.d.ts +1 -1
- package/package.json +24 -26
- package/standalone.d.ts +5 -7
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Type } from '@angular/core';
|
|
2
|
-
import { ArgTypes } from '@storybook/api';
|
|
3
|
-
import { ICollection } from '../types';
|
|
1
|
+
import type { Type } from '@angular/core';
|
|
2
|
+
import type { ArgTypes } from '@storybook/api';
|
|
3
|
+
import type { ICollection } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
6
6
|
* @param component
|
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
-
return cooked;
|
|
5
|
-
};
|
|
6
|
-
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
7
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
8
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
9
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
10
|
-
r[k] = a[j];
|
|
11
|
-
return r;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.computesTemplateSourceFromComponent = exports.computesTemplateFromComponent = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
.map(function (o) { return o.templateName; });
|
|
4
|
+
const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
|
|
5
|
+
const separateInputsOutputsAttributes = (ngComponentInputsOutputs, props = {}) => {
|
|
6
|
+
const inputs = ngComponentInputsOutputs.inputs
|
|
7
|
+
.filter((i) => i.templateName in props)
|
|
8
|
+
.map((i) => i.templateName);
|
|
9
|
+
const outputs = ngComponentInputsOutputs.outputs
|
|
10
|
+
.filter((o) => o.templateName in props)
|
|
11
|
+
.map((o) => o.templateName);
|
|
24
12
|
return {
|
|
25
|
-
inputs
|
|
26
|
-
outputs
|
|
27
|
-
otherProps: Object.keys(props).filter(
|
|
13
|
+
inputs,
|
|
14
|
+
outputs,
|
|
15
|
+
otherProps: Object.keys(props).filter((k) => ![...inputs, ...outputs].includes(k)),
|
|
28
16
|
};
|
|
29
17
|
};
|
|
30
18
|
/**
|
|
@@ -33,31 +21,29 @@ var separateInputsOutputsAttributes = function (ngComponentInputsOutputs, props)
|
|
|
33
21
|
* @param initialProps
|
|
34
22
|
* @param innerTemplate
|
|
35
23
|
*/
|
|
36
|
-
exports.computesTemplateFromComponent =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var ngComponentInputsOutputs = NgComponentAnalyzer_1.getComponentInputsOutputs(component);
|
|
24
|
+
exports.computesTemplateFromComponent = (component, initialProps, innerTemplate = '') => {
|
|
25
|
+
const ngComponentMetadata = NgComponentAnalyzer_1.getComponentDecoratorMetadata(component);
|
|
26
|
+
const ngComponentInputsOutputs = NgComponentAnalyzer_1.getComponentInputsOutputs(component);
|
|
40
27
|
if (!ngComponentMetadata.selector) {
|
|
41
28
|
// Allow to add renderer component when NgComponent selector is undefined
|
|
42
|
-
return
|
|
29
|
+
return `<ng-container *ngComponentOutlet="storyComponent"></ng-container>`;
|
|
43
30
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
?
|
|
31
|
+
const { inputs: initialInputs, outputs: initialOutputs } = separateInputsOutputsAttributes(ngComponentInputsOutputs, initialProps);
|
|
32
|
+
const templateInputs = initialInputs.length > 0 ? ` ${initialInputs.map((i) => `[${i}]="${i}"`).join(' ')}` : '';
|
|
33
|
+
const templateOutputs = initialOutputs.length > 0
|
|
34
|
+
? ` ${initialOutputs.map((i) => `(${i})="${i}($event)"`).join(' ')}`
|
|
48
35
|
: '';
|
|
49
36
|
return buildTemplate(ngComponentMetadata.selector, innerTemplate, templateInputs, templateOutputs);
|
|
50
37
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var requiresBrackets = ['object', 'any', 'boolean', 'enum', 'number'].includes(actualType);
|
|
38
|
+
const createAngularInputProperty = ({ propertyName, value, argType, }) => {
|
|
39
|
+
const { name: type = null, summary = null } = (argType === null || argType === void 0 ? void 0 : argType.type) || {};
|
|
40
|
+
let templateValue = type === 'enum' && !!summary ? `${summary}.${value}` : value;
|
|
41
|
+
const actualType = type === 'enum' && summary ? 'enum' : typeof value;
|
|
42
|
+
const requiresBrackets = ['object', 'any', 'boolean', 'enum', 'number'].includes(actualType);
|
|
57
43
|
if (typeof value === 'object') {
|
|
58
44
|
templateValue = propertyName;
|
|
59
45
|
}
|
|
60
|
-
return
|
|
46
|
+
return `${requiresBrackets ? '[' : ''}${propertyName}${requiresBrackets ? ']' : ''}="${templateValue}"`;
|
|
61
47
|
};
|
|
62
48
|
/**
|
|
63
49
|
* Converts a component into a template with inputs/outputs present in initial props
|
|
@@ -65,48 +51,68 @@ var createAngularInputProperty = function (_a) {
|
|
|
65
51
|
* @param initialProps
|
|
66
52
|
* @param innerTemplate
|
|
67
53
|
*/
|
|
68
|
-
exports.computesTemplateSourceFromComponent =
|
|
69
|
-
|
|
54
|
+
exports.computesTemplateSourceFromComponent = (component, initialProps, argTypes) => {
|
|
55
|
+
const ngComponentMetadata = NgComponentAnalyzer_1.getComponentDecoratorMetadata(component);
|
|
70
56
|
if (!ngComponentMetadata) {
|
|
71
57
|
return null;
|
|
72
58
|
}
|
|
73
59
|
if (!ngComponentMetadata.selector) {
|
|
74
60
|
// Allow to add renderer component when NgComponent selector is undefined
|
|
75
|
-
return
|
|
61
|
+
return `<ng-container *ngComponentOutlet="${component.name}"></ng-container>`;
|
|
76
62
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
?
|
|
81
|
-
.map(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
.join(' ')
|
|
63
|
+
const ngComponentInputsOutputs = NgComponentAnalyzer_1.getComponentInputsOutputs(component);
|
|
64
|
+
const { inputs: initialInputs, outputs: initialOutputs } = separateInputsOutputsAttributes(ngComponentInputsOutputs, initialProps);
|
|
65
|
+
const templateInputs = initialInputs.length > 0
|
|
66
|
+
? ` ${initialInputs
|
|
67
|
+
.map((propertyName) => createAngularInputProperty({
|
|
68
|
+
propertyName,
|
|
69
|
+
value: initialProps[propertyName],
|
|
70
|
+
argType: argTypes === null || argTypes === void 0 ? void 0 : argTypes[propertyName],
|
|
71
|
+
}))
|
|
72
|
+
.join(' ')}`
|
|
89
73
|
: '';
|
|
90
|
-
|
|
91
|
-
?
|
|
74
|
+
const templateOutputs = initialOutputs.length > 0
|
|
75
|
+
? ` ${initialOutputs.map((i) => `(${i})="${i}($event)"`).join(' ')}`
|
|
92
76
|
: '';
|
|
93
77
|
return buildTemplate(ngComponentMetadata.selector, '', templateInputs, templateOutputs);
|
|
94
78
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
79
|
+
const buildTemplate = (selector, innerTemplate, inputs, outputs) => {
|
|
80
|
+
// https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#syntax-elements
|
|
81
|
+
const voidElements = [
|
|
82
|
+
'area',
|
|
83
|
+
'base',
|
|
84
|
+
'br',
|
|
85
|
+
'col',
|
|
86
|
+
'command',
|
|
87
|
+
'embed',
|
|
88
|
+
'hr',
|
|
89
|
+
'img',
|
|
90
|
+
'input',
|
|
91
|
+
'keygen',
|
|
92
|
+
'link',
|
|
93
|
+
'meta',
|
|
94
|
+
'param',
|
|
95
|
+
'source',
|
|
96
|
+
'track',
|
|
97
|
+
'wbr',
|
|
98
|
+
];
|
|
99
|
+
const firstSelector = selector.split(',')[0];
|
|
100
|
+
const templateReplacers = [
|
|
98
101
|
[/(^.*?)(?=[,])/, '$1'],
|
|
99
102
|
[/(^\..+)/, 'div$1'],
|
|
100
103
|
[/(^\[.+?])/, 'div$1'],
|
|
101
|
-
[/([\w[\]]+)(\s*,[\w\s-[\],]+)+/,
|
|
102
|
-
[/#([\w-]+)/,
|
|
103
|
-
[/((\.[\w-]+)+)/,
|
|
104
|
-
[/(\[.+?])/g,
|
|
105
|
-
[
|
|
104
|
+
[/([\w[\]]+)(\s*,[\w\s-[\],]+)+/, `$1`],
|
|
105
|
+
[/#([\w-]+)/, ` id="$1"`],
|
|
106
|
+
[/((\.[\w-]+)+)/, (_, c) => ` class="${c.split `.`.join ` `.trim()}"`],
|
|
107
|
+
[/(\[.+?])/g, (_, a) => ` ${a.slice(1, -1)}`],
|
|
108
|
+
[
|
|
109
|
+
/([\S]+)(.*)/,
|
|
110
|
+
(template, elementSelector) => {
|
|
111
|
+
return voidElements.some((element) => elementSelector === element)
|
|
112
|
+
? template.replace(/([\S]+)(.*)/, `<$1$2${inputs}${outputs} />`)
|
|
113
|
+
: template.replace(/([\S]+)(.*)/, `<$1$2${inputs}${outputs}>${innerTemplate}</$1>`);
|
|
114
|
+
},
|
|
115
|
+
],
|
|
106
116
|
];
|
|
107
|
-
return templateReplacers.reduce(
|
|
108
|
-
var searchValue = _a[0], replacer = _a[1];
|
|
109
|
-
return prevSelector.replace(searchValue, replacer);
|
|
110
|
-
}, firstSelector);
|
|
117
|
+
return templateReplacers.reduce((prevSelector, [searchValue, replacer]) => prevSelector.replace(searchValue, replacer), firstSelector);
|
|
111
118
|
};
|
|
112
|
-
var templateObject_1, templateObject_2;
|