@storybook/angular 6.5.0-alpha.5 → 6.5.0-alpha.52

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.
Files changed (93) hide show
  1. package/dist/ts3.4/client/docs/compodoc.d.ts +18 -0
  2. package/dist/ts3.4/client/docs/config.d.ts +15 -0
  3. package/dist/ts3.4/client/docs/index.d.ts +1 -0
  4. package/dist/ts3.4/client/docs/prepareForInline.d.ts +7 -0
  5. package/dist/ts3.4/client/docs/sourceDecorator.d.ts +9 -0
  6. package/dist/ts3.4/client/docs/types.d.ts +102 -0
  7. package/dist/ts3.4/client/preview/angular-beta/utils/NgComponentAnalyzer.d.ts +4 -2
  8. package/dist/ts3.4/server/angular-cli-webpack-older.d.ts +2 -1
  9. package/dist/ts3.4/server/framework-preset-angular-docs.d.ts +2 -0
  10. package/dist/ts3.4/server/framework-preset-angular.d.ts +3 -2
  11. package/dist/ts3.9/builders/build-storybook/index.d.ts +1 -1
  12. package/dist/ts3.9/builders/build-storybook/index.js +33 -84
  13. package/dist/ts3.9/builders/start-storybook/index.d.ts +1 -1
  14. package/dist/ts3.9/builders/start-storybook/index.js +40 -91
  15. package/dist/ts3.9/builders/utils/build-standalone-errors-handler.js +13 -11
  16. package/dist/ts3.9/builders/utils/run-compodoc.js +45 -20
  17. package/dist/ts3.9/client/docs/compodoc.d.ts +18 -0
  18. package/dist/ts3.9/client/docs/compodoc.js +247 -0
  19. package/dist/ts3.9/client/docs/config.d.ts +15 -0
  20. package/dist/ts3.9/client/docs/config.js +22 -0
  21. package/dist/ts3.9/client/docs/index.d.ts +1 -0
  22. package/dist/ts3.9/client/docs/index.js +13 -0
  23. package/dist/ts3.9/client/docs/prepareForInline.d.ts +7 -0
  24. package/dist/ts3.9/client/docs/prepareForInline.js +45 -0
  25. package/dist/ts3.9/client/docs/sourceDecorator.d.ts +9 -0
  26. package/dist/ts3.9/client/docs/sourceDecorator.js +49 -0
  27. package/dist/ts3.9/client/docs/types.d.ts +102 -0
  28. package/dist/ts3.9/client/docs/types.js +2 -0
  29. package/dist/ts3.9/client/preview/angular/app.token.js +1 -1
  30. package/dist/ts3.9/client/preview/angular/components/app.component.js +55 -59
  31. package/dist/ts3.9/client/preview/angular/helpers.d.ts +2 -2
  32. package/dist/ts3.9/client/preview/angular/helpers.js +66 -80
  33. package/dist/ts3.9/client/preview/angular-beta/AbstractRenderer.js +77 -125
  34. package/dist/ts3.9/client/preview/angular-beta/CanvasRenderer.js +18 -81
  35. package/dist/ts3.9/client/preview/angular-beta/ComputesTemplateFromComponent.d.ts +3 -3
  36. package/dist/ts3.9/client/preview/angular-beta/ComputesTemplateFromComponent.js +75 -69
  37. package/dist/ts3.9/client/preview/angular-beta/DocsRenderer.js +41 -127
  38. package/dist/ts3.9/client/preview/angular-beta/RendererFactory.js +30 -66
  39. package/dist/ts3.9/client/preview/angular-beta/StorybookModule.js +42 -46
  40. package/dist/ts3.9/client/preview/angular-beta/StorybookProvider.js +15 -17
  41. package/dist/ts3.9/client/preview/angular-beta/StorybookWrapperComponent.js +58 -98
  42. package/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer.d.ts +4 -2
  43. package/dist/ts3.9/client/preview/angular-beta/utils/NgComponentAnalyzer.js +30 -77
  44. package/dist/ts3.9/client/preview/angular-beta/utils/NgModulesAnalyzer.js +10 -14
  45. package/dist/ts3.9/client/preview/decorateStory.d.ts +2 -2
  46. package/dist/ts3.9/client/preview/decorateStory.js +16 -36
  47. package/dist/ts3.9/client/preview/decorators.d.ts +4 -4
  48. package/dist/ts3.9/client/preview/decorators.js +22 -37
  49. package/dist/ts3.9/client/preview/globals.js +2 -2
  50. package/dist/ts3.9/client/preview/index.d.ts +3 -3
  51. package/dist/ts3.9/client/preview/index.js +8 -21
  52. package/dist/ts3.9/client/preview/render.d.ts +3 -3
  53. package/dist/ts3.9/client/preview/render.js +17 -56
  54. package/dist/ts3.9/client/preview/types-6-0.d.ts +2 -2
  55. package/dist/ts3.9/client/preview/types-7-0.d.ts +1 -1
  56. package/dist/ts3.9/demo/button.component.js +31 -22
  57. package/dist/ts3.9/demo/welcome.component.js +85 -18
  58. package/dist/ts3.9/server/__mocks-ng-workspace__/minimal-config/tsconfig.json +4 -1
  59. package/dist/ts3.9/server/__mocks-ng-workspace__/some-config/tsconfig.json +4 -1
  60. package/dist/ts3.9/server/__mocks-ng-workspace__/with-angularBrowserTarget/tsconfig.json +4 -1
  61. package/dist/ts3.9/server/__mocks-ng-workspace__/with-lib/tsconfig.json +4 -1
  62. package/dist/ts3.9/server/__mocks-ng-workspace__/with-nx/tsconfig.json +7 -2
  63. package/dist/ts3.9/server/__mocks-ng-workspace__/with-nx-workspace/tsconfig.json +7 -2
  64. package/dist/ts3.9/server/__mocks-ng-workspace__/with-options-styles/tsconfig.json +4 -1
  65. package/dist/ts3.9/server/__mocks-ng-workspace__/without-projects-entry/tsconfig.json +4 -1
  66. package/dist/ts3.9/server/__mocks-ng-workspace__/without-tsConfig/tsconfig.json +4 -1
  67. package/dist/ts3.9/server/angular-cli-webpack-12.2.x.js +38 -81
  68. package/dist/ts3.9/server/angular-cli-webpack-13.x.x.js +42 -85
  69. package/dist/ts3.9/server/angular-cli-webpack-older.d.ts +2 -1
  70. package/dist/ts3.9/server/angular-cli-webpack-older.js +77 -123
  71. package/dist/ts3.9/server/angular-devkit-build-webpack.js +72 -133
  72. package/dist/ts3.9/server/angular-read-workspace.js +44 -78
  73. package/dist/ts3.9/server/build.js +10 -47
  74. package/dist/ts3.9/server/create-fork-ts-checker-plugin.js +3 -3
  75. package/dist/ts3.9/server/framework-preset-angular-cli.js +111 -179
  76. package/dist/ts3.9/server/framework-preset-angular-docs.d.ts +2 -0
  77. package/dist/ts3.9/server/framework-preset-angular-docs.js +13 -0
  78. package/dist/ts3.9/server/framework-preset-angular-ivy.js +35 -92
  79. package/dist/ts3.9/server/framework-preset-angular.d.ts +3 -2
  80. package/dist/ts3.9/server/framework-preset-angular.js +88 -62
  81. package/dist/ts3.9/server/index.js +2 -2
  82. package/dist/ts3.9/server/ngx-template-loader/index.js +15 -15
  83. package/dist/ts3.9/server/options.d.ts +1 -1
  84. package/dist/ts3.9/server/options.js +1 -1
  85. package/dist/ts3.9/server/preset.js +5 -13
  86. package/dist/ts3.9/server/ts_config.js +5 -5
  87. package/dist/ts3.9/server/utils/filter-out-styling-rules.js +4 -4
  88. package/dist/ts3.9/server/utils/module-is-available.js +1 -1
  89. package/dist/ts3.9/server/utils/normalize-asset-patterns.js +16 -31
  90. package/dist/ts3.9/server/utils/normalize-optimization.js +3 -3
  91. package/dist/ts3.9/types/index.d.ts +1 -1
  92. package/package.json +22 -25
  93. 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
- var core_1 = require("@angular/core");
61
- var platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic");
62
- var rxjs_1 = require("rxjs");
63
- var telejson_1 = require("telejson");
64
- var StorybookModule_1 = require("./StorybookModule");
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
- var platformRef;
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
- var AbstractRenderer = /** @class */ (function () {
74
- function AbstractRenderer(storyId) {
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
- AbstractRenderer.resetPlatformBrowserDynamic = function () {
91
- var _this = this;
92
- return new Promise(function (resolve) {
63
+ static resetPlatformBrowserDynamic() {
64
+ return new Promise((resolve) => {
93
65
  if (platformRef && !platformRef.destroyed) {
94
- platformRef.onDestroy(function () { return __awaiter(_this, void 0, void 0, function () {
95
- return __generator(this, function (_a) {
96
- resolve();
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(function () {
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
- AbstractRenderer.prototype.render = function (_a) {
121
- var _b;
122
- var storyFnAngular = _a.storyFnAngular, forced = _a.forced, parameters = _a.parameters, component = _a.component, targetDOMNode = _a.targetDOMNode;
123
- return __awaiter(this, void 0, void 0, function () {
124
- var targetSelector, newStoryProps$, moduleMetadata;
125
- return __generator(this, function (_c) {
126
- switch (_c.label) {
127
- case 0:
128
- targetSelector = "" + this.generateTargetSelectorFromStoryId();
129
- newStoryProps$ = new rxjs_1.BehaviorSubject(storyFnAngular.props);
130
- moduleMetadata = StorybookModule_1.getStorybookModuleMetadata({ storyFnAngular: storyFnAngular, component: component, targetSelector: targetSelector }, newStoryProps$);
131
- if (!this.fullRendererRequired({
132
- storyFnAngular: storyFnAngular,
133
- moduleMetadata: moduleMetadata,
134
- forced: forced,
135
- })) {
136
- this.storyProps$.next(storyFnAngular.props);
137
- return [2 /*return*/];
138
- }
139
- return [4 /*yield*/, this.beforeFullRender()];
140
- case 1:
141
- _c.sent();
142
- // Complete last BehaviorSubject and set a new one for the current module
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
- AbstractRenderer.prototype.generateTargetSelectorFromStoryId = function () {
172
- var invalidHtmlTag = /[^A-Za-z0-9-]/g;
173
- var storyIdIsInvalidHtmlTagName = invalidHtmlTag.test(this.storyId);
126
+ generateTargetSelectorFromStoryId() {
127
+ const invalidHtmlTag = /[^A-Za-z0-9-]/g;
128
+ const storyIdIsInvalidHtmlTagName = invalidHtmlTag.test(this.storyId);
174
129
  return storyIdIsInvalidHtmlTagName
175
- ? "sb-" + this.storyId.replace(invalidHtmlTag, '') + "-component"
130
+ ? `sb-${this.storyId.replace(invalidHtmlTag, '')}-component`
176
131
  : this.storyId;
177
- };
178
- AbstractRenderer.prototype.initAngularRootElement = function (targetDOMNode, targetSelector) {
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
- AbstractRenderer.prototype.fullRendererRequired = function (_a) {
185
- var _b;
186
- var storyFnAngular = _a.storyFnAngular, moduleMetadata = _a.moduleMetadata, forced = _a.forced;
187
- var previousStoryRenderInfo = this.previousStoryRenderInfo;
188
- var currentStoryRender = {
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
- var hasChangedTemplate = !!(storyFnAngular === null || storyFnAngular === void 0 ? void 0 : storyFnAngular.template) &&
202
- ((_b = previousStoryRenderInfo === null || previousStoryRenderInfo === void 0 ? void 0 : previousStoryRenderInfo.storyFnAngular) === null || _b === void 0 ? void 0 : _b.template) !== storyFnAngular.template;
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
- var hasChangedModuleMetadata = currentStoryRender.moduleMetadataSnapshot !== (previousStoryRenderInfo === null || previousStoryRenderInfo === void 0 ? void 0 : previousStoryRenderInfo.moduleMetadataSnapshot);
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
- var AbstractRenderer_1 = require("./AbstractRenderer");
54
- var CanvasRenderer = /** @class */ (function (_super) {
55
- __extends(CanvasRenderer, _super);
56
- function CanvasRenderer() {
57
- return _super !== null && _super.apply(this, arguments) || this;
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
- CanvasRenderer.prototype.beforeFullRender = function () {
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
- CanvasRenderer.prototype.afterFullRender = function () {
84
- return __awaiter(this, void 0, void 0, function () {
85
- return __generator(this, function (_a) {
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
- return CanvasRenderer;
96
- }(AbstractRenderer_1.AbstractRenderer));
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
- var NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
16
- var separateInputsOutputsAttributes = function (ngComponentInputsOutputs, props) {
17
- if (props === void 0) { props = {}; }
18
- var inputs = ngComponentInputsOutputs.inputs
19
- .filter(function (i) { return i.templateName in props; })
20
- .map(function (i) { return i.templateName; });
21
- var outputs = ngComponentInputsOutputs.outputs
22
- .filter(function (o) { return o.templateName in props; })
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: inputs,
26
- outputs: outputs,
27
- otherProps: Object.keys(props).filter(function (k) { return !__spreadArrays(inputs, outputs).includes(k); }),
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 = function (component, initialProps, innerTemplate) {
37
- if (innerTemplate === void 0) { innerTemplate = ''; }
38
- var ngComponentMetadata = NgComponentAnalyzer_1.getComponentDecoratorMetadata(component);
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 "<ng-container *ngComponentOutlet=\"storyComponent\"></ng-container>";
29
+ return `<ng-container *ngComponentOutlet="storyComponent"></ng-container>`;
43
30
  }
44
- var _a = separateInputsOutputsAttributes(ngComponentInputsOutputs, initialProps), initialInputs = _a.inputs, initialOutputs = _a.outputs;
45
- var templateInputs = initialInputs.length > 0 ? " " + initialInputs.map(function (i) { return "[" + i + "]=\"" + i + "\""; }).join(' ') : '';
46
- var templateOutputs = initialOutputs.length > 0
47
- ? " " + initialOutputs.map(function (i) { return "(" + i + ")=\"" + i + "($event)\""; }).join(' ')
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
- var createAngularInputProperty = function (_a) {
52
- var propertyName = _a.propertyName, value = _a.value, argType = _a.argType;
53
- var _b = (argType === null || argType === void 0 ? void 0 : argType.type) || {}, _c = _b.name, type = _c === void 0 ? null : _c, _d = _b.summary, summary = _d === void 0 ? null : _d;
54
- var templateValue = type === 'enum' && !!summary ? summary + "." + value : value;
55
- var actualType = type === 'enum' && summary ? 'enum' : typeof value;
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 "" + (requiresBrackets ? '[' : '') + propertyName + (requiresBrackets ? ']' : '') + "=\"" + templateValue + "\"";
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 = function (component, initialProps, argTypes) {
69
- var ngComponentMetadata = NgComponentAnalyzer_1.getComponentDecoratorMetadata(component);
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 "<ng-container *ngComponentOutlet=\"" + component.name + "\"></ng-container>";
61
+ return `<ng-container *ngComponentOutlet="${component.name}"></ng-container>`;
76
62
  }
77
- var ngComponentInputsOutputs = NgComponentAnalyzer_1.getComponentInputsOutputs(component);
78
- var _a = separateInputsOutputsAttributes(ngComponentInputsOutputs, initialProps), initialInputs = _a.inputs, initialOutputs = _a.outputs;
79
- var templateInputs = initialInputs.length > 0
80
- ? " " + initialInputs
81
- .map(function (propertyName) {
82
- return createAngularInputProperty({
83
- propertyName: propertyName,
84
- value: initialProps[propertyName],
85
- argType: argTypes === null || argTypes === void 0 ? void 0 : argTypes[propertyName],
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
- var templateOutputs = initialOutputs.length > 0
91
- ? " " + initialOutputs.map(function (i) { return "(" + i + ")=\"" + i + "($event)\""; }).join(' ')
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
- var buildTemplate = function (selector, innerTemplate, inputs, outputs) {
96
- var firstSelector = selector.split(',')[0];
97
- var templateReplacers = [
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-[\],]+)+/, "$1"],
102
- [/#([\w-]+)/, " id=\"$1\""],
103
- [/((\.[\w-]+)+)/, function (_, c) { return " class=\"" + c.split(templateObject_1 || (templateObject_1 = __makeTemplateObject(["."], ["."]))).join(templateObject_2 || (templateObject_2 = __makeTemplateObject([" "], [" "]))).trim() + "\""; }],
104
- [/(\[.+?])/g, function (_, a) { return " " + a.slice(1, -1); }],
105
- [/([\S]+)(.*)/, "<$1$2" + inputs + outputs + ">" + innerTemplate + "</$1>"],
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(function (prevSelector, _a) {
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;