@storybook/angular 7.0.0 → 7.0.2
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/client/decorateStory.test.js +0 -31
- package/dist/client/decorators.test.js +1 -4
- package/dist/client/types.d.ts +0 -4
- package/package.json +15 -15
- package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts +2 -4
- package/dist/client/angular/app.component.d.ts +0 -38
- package/dist/client/angular/app.component.js +0 -141
- package/dist/client/angular/app.token.d.ts +0 -3
- package/dist/client/angular/app.token.js +0 -5
|
@@ -169,37 +169,6 @@ describe('decorateStory', () => {
|
|
|
169
169
|
userDefinedTemplate: false,
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
|
-
it('should include legacy story components in decorators', () => {
|
|
173
|
-
const decorators = [
|
|
174
|
-
(s) => {
|
|
175
|
-
const story = s();
|
|
176
|
-
return {
|
|
177
|
-
...story,
|
|
178
|
-
template: `<parent>${story.template}</parent>`,
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
(s) => {
|
|
182
|
-
const story = s();
|
|
183
|
-
return {
|
|
184
|
-
...story,
|
|
185
|
-
template: `<grandparent>${story.template}</grandparent>`,
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
(s) => {
|
|
189
|
-
const story = s();
|
|
190
|
-
return {
|
|
191
|
-
...story,
|
|
192
|
-
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
193
|
-
};
|
|
194
|
-
},
|
|
195
|
-
];
|
|
196
|
-
const decorated = (0, decorateStory_1.default)(() => ({ component: FooComponent }), decorators);
|
|
197
|
-
expect(decorated(makeContext({}))).toEqual({
|
|
198
|
-
template: '<great-grandparent><grandparent><parent><foo></foo></parent></grandparent></great-grandparent>',
|
|
199
|
-
component: FooComponent,
|
|
200
|
-
userDefinedTemplate: false,
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
172
|
it('should keep template with an empty value', () => {
|
|
204
173
|
const decorators = [
|
|
205
174
|
(0, decorators_1.componentWrapperDecorator)(ParentComponent),
|
|
@@ -87,13 +87,10 @@ describe('moduleMetadata', () => {
|
|
|
87
87
|
const result = (0, decorators_1.moduleMetadata)({
|
|
88
88
|
imports: [MockModule],
|
|
89
89
|
providers: [MockService],
|
|
90
|
-
})(() => ({
|
|
91
|
-
component: MockComponent,
|
|
92
|
-
}),
|
|
90
|
+
})(() => ({}),
|
|
93
91
|
// deepscan-disable-next-line
|
|
94
92
|
defaultContext);
|
|
95
93
|
expect(result).toEqual({
|
|
96
|
-
component: MockComponent,
|
|
97
94
|
moduleMetadata: {
|
|
98
95
|
declarations: [],
|
|
99
96
|
entryComponents: [],
|
package/dist/client/types.d.ts
CHANGED
|
@@ -23,11 +23,7 @@ export interface ICollection {
|
|
|
23
23
|
[p: string]: any;
|
|
24
24
|
}
|
|
25
25
|
export interface StoryFnAngularReturnType {
|
|
26
|
-
/** @deprecated `component` story input is deprecated, and will be removed in Storybook 7.0. */
|
|
27
|
-
component?: any;
|
|
28
26
|
props?: ICollection;
|
|
29
|
-
/** @deprecated `propsMeta` story input is deprecated, and will be removed in Storybook 7.0. */
|
|
30
|
-
propsMeta?: ICollection;
|
|
31
27
|
moduleMetadata?: NgModuleMetadata;
|
|
32
28
|
applicationConfig?: ApplicationConfig;
|
|
33
29
|
template?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/angular",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
"prep": "../../../scripts/prepare/tsc.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@storybook/builder-webpack5": "7.0.
|
|
40
|
-
"@storybook/cli": "7.0.
|
|
41
|
-
"@storybook/client-logger": "7.0.
|
|
42
|
-
"@storybook/core-client": "7.0.
|
|
43
|
-
"@storybook/core-common": "7.0.
|
|
44
|
-
"@storybook/core-events": "7.0.
|
|
45
|
-
"@storybook/core-server": "7.0.
|
|
46
|
-
"@storybook/core-webpack": "7.0.
|
|
47
|
-
"@storybook/docs-tools": "7.0.
|
|
39
|
+
"@storybook/builder-webpack5": "7.0.2",
|
|
40
|
+
"@storybook/cli": "7.0.2",
|
|
41
|
+
"@storybook/client-logger": "7.0.2",
|
|
42
|
+
"@storybook/core-client": "7.0.2",
|
|
43
|
+
"@storybook/core-common": "7.0.2",
|
|
44
|
+
"@storybook/core-events": "7.0.2",
|
|
45
|
+
"@storybook/core-server": "7.0.2",
|
|
46
|
+
"@storybook/core-webpack": "7.0.2",
|
|
47
|
+
"@storybook/docs-tools": "7.0.2",
|
|
48
48
|
"@storybook/global": "^5.0.0",
|
|
49
|
-
"@storybook/manager-api": "7.0.
|
|
50
|
-
"@storybook/node-logger": "7.0.
|
|
51
|
-
"@storybook/preview-api": "7.0.
|
|
52
|
-
"@storybook/types": "7.0.
|
|
49
|
+
"@storybook/manager-api": "7.0.2",
|
|
50
|
+
"@storybook/node-logger": "7.0.2",
|
|
51
|
+
"@storybook/preview-api": "7.0.2",
|
|
52
|
+
"@storybook/types": "7.0.2",
|
|
53
53
|
"@types/node": "^16.0.0",
|
|
54
54
|
"@types/react": "^16.14.34",
|
|
55
55
|
"@types/react-dom": "^16.9.14",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"bundler": {
|
|
124
124
|
"tsConfig": "tsconfig.build.json"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "96b498debee8b89d0c4050c13172a5a818c9997a"
|
|
127
127
|
}
|
package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OnDestroy, OnInit, Component } from '@angular/core';
|
|
2
|
-
import { Meta,
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
3
3
|
|
|
4
4
|
@Component({
|
|
5
5
|
selector: 'on-destroy',
|
|
@@ -37,6 +37,4 @@ export default {
|
|
|
37
37
|
},
|
|
38
38
|
} as Meta;
|
|
39
39
|
|
|
40
|
-
export const SimpleComponent:
|
|
41
|
-
component: OnDestroyComponent,
|
|
42
|
-
});
|
|
40
|
+
export const SimpleComponent: StoryObj = {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ViewContainerRef, ChangeDetectorRef, OnInit, ComponentFactoryResolver, OnDestroy } from '@angular/core';
|
|
2
|
-
import { Observable, Subscription } from 'rxjs';
|
|
3
|
-
import { StoryFnAngularReturnType } from '../types';
|
|
4
|
-
export declare class AppComponent implements OnInit, OnDestroy {
|
|
5
|
-
private cfr;
|
|
6
|
-
private changeDetectorRef;
|
|
7
|
-
private data;
|
|
8
|
-
target: ViewContainerRef;
|
|
9
|
-
readonly previousValues: {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
};
|
|
12
|
-
subscription: Subscription;
|
|
13
|
-
propSubscriptions: Map<any, {
|
|
14
|
-
prop: any;
|
|
15
|
-
sub: Subscription;
|
|
16
|
-
}>;
|
|
17
|
-
constructor(cfr: ComponentFactoryResolver, changeDetectorRef: ChangeDetectorRef, data: Observable<StoryFnAngularReturnType>);
|
|
18
|
-
ngOnInit(): void;
|
|
19
|
-
ngOnDestroy(): void;
|
|
20
|
-
/**
|
|
21
|
-
* Set inputs and outputs
|
|
22
|
-
*/
|
|
23
|
-
private setProps;
|
|
24
|
-
/**
|
|
25
|
-
* Manually call 'ngOnChanges' hook because angular doesn't do that for dynamic components
|
|
26
|
-
* Issue: [https://github.com/angular/angular/issues/8903]
|
|
27
|
-
*/
|
|
28
|
-
private callNgOnChangesHook;
|
|
29
|
-
/**
|
|
30
|
-
* If component implements ControlValueAccessor interface try to set ngModel
|
|
31
|
-
*/
|
|
32
|
-
private setNgModel;
|
|
33
|
-
/**
|
|
34
|
-
* Store ref to subscription for cleanup in 'ngOnDestroy' and check if
|
|
35
|
-
* observable needs to be resubscribed to, before creating a new subscription.
|
|
36
|
-
*/
|
|
37
|
-
private setPropSubscription;
|
|
38
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.AppComponent = void 0;
|
|
16
|
-
// We could use NgComponentOutlet here but there's currently no easy way
|
|
17
|
-
// to provide @Inputs and subscribe to @Outputs, see
|
|
18
|
-
// https://github.com/angular/angular/issues/15360
|
|
19
|
-
// For the time being, the ViewContainerRef approach works pretty well.
|
|
20
|
-
const core_1 = require("@angular/core");
|
|
21
|
-
const rxjs_1 = require("rxjs");
|
|
22
|
-
const operators_1 = require("rxjs/operators");
|
|
23
|
-
const app_token_1 = require("./app.token");
|
|
24
|
-
let AppComponent = class AppComponent {
|
|
25
|
-
constructor(cfr, changeDetectorRef, data) {
|
|
26
|
-
this.cfr = cfr;
|
|
27
|
-
this.changeDetectorRef = changeDetectorRef;
|
|
28
|
-
this.data = data;
|
|
29
|
-
this.previousValues = {};
|
|
30
|
-
this.propSubscriptions = new Map();
|
|
31
|
-
}
|
|
32
|
-
ngOnInit() {
|
|
33
|
-
this.data.pipe((0, operators_1.first)()).subscribe((data) => {
|
|
34
|
-
this.target.clear();
|
|
35
|
-
const compFactory = this.cfr.resolveComponentFactory(data.component);
|
|
36
|
-
const componentRef = this.target.createComponent(compFactory);
|
|
37
|
-
const { instance } = componentRef;
|
|
38
|
-
// For some reason, manual change detection ref is only working when getting the ref from the injector (rather than componentRef.changeDetectorRef)
|
|
39
|
-
const childChangeDetectorRef = componentRef.injector.get(core_1.ChangeDetectorRef);
|
|
40
|
-
this.subscription = this.data.subscribe((newData) => {
|
|
41
|
-
this.setProps(instance, newData);
|
|
42
|
-
childChangeDetectorRef.markForCheck();
|
|
43
|
-
// Must detect changes on the current component in order to update any changes in child component's @HostBinding properties (angular/angular#22560)
|
|
44
|
-
this.changeDetectorRef.detectChanges();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
ngOnDestroy() {
|
|
49
|
-
this.target.clear();
|
|
50
|
-
if (this.subscription) {
|
|
51
|
-
this.subscription.unsubscribe();
|
|
52
|
-
}
|
|
53
|
-
this.propSubscriptions.forEach((v) => {
|
|
54
|
-
if (!v.sub.closed) {
|
|
55
|
-
v.sub.unsubscribe();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
this.propSubscriptions.clear();
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Set inputs and outputs
|
|
62
|
-
*/
|
|
63
|
-
setProps(instance, { props = {} }) {
|
|
64
|
-
const changes = {};
|
|
65
|
-
const hasNgOnChangesHook = !!instance.ngOnChanges;
|
|
66
|
-
Object.keys(props).forEach((key) => {
|
|
67
|
-
const value = props[key];
|
|
68
|
-
const instanceProperty = instance[key];
|
|
69
|
-
if (!(instanceProperty instanceof core_1.EventEmitter) && value !== undefined && value !== null) {
|
|
70
|
-
// eslint-disable-next-line no-param-reassign
|
|
71
|
-
instance[key] = value;
|
|
72
|
-
if (hasNgOnChangesHook) {
|
|
73
|
-
const previousValue = this.previousValues[key];
|
|
74
|
-
if (previousValue !== value) {
|
|
75
|
-
changes[key] = new core_1.SimpleChange(previousValue, value, !Object.prototype.hasOwnProperty.call(this.previousValues, key));
|
|
76
|
-
this.previousValues[key] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (typeof value === 'function' && key !== 'ngModelChange') {
|
|
81
|
-
this.setPropSubscription(key, instanceProperty, value);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
this.callNgOnChangesHook(instance, changes);
|
|
85
|
-
this.setNgModel(instance, props);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Manually call 'ngOnChanges' hook because angular doesn't do that for dynamic components
|
|
89
|
-
* Issue: [https://github.com/angular/angular/issues/8903]
|
|
90
|
-
*/
|
|
91
|
-
callNgOnChangesHook(instance, changes) {
|
|
92
|
-
if (Object.keys(changes).length) {
|
|
93
|
-
instance.ngOnChanges(changes);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* If component implements ControlValueAccessor interface try to set ngModel
|
|
98
|
-
*/
|
|
99
|
-
setNgModel(instance, props) {
|
|
100
|
-
if (props.ngModel) {
|
|
101
|
-
instance.writeValue(props.ngModel);
|
|
102
|
-
}
|
|
103
|
-
if (typeof props.ngModelChange === 'function') {
|
|
104
|
-
instance.registerOnChange(props.ngModelChange);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Store ref to subscription for cleanup in 'ngOnDestroy' and check if
|
|
109
|
-
* observable needs to be resubscribed to, before creating a new subscription.
|
|
110
|
-
*/
|
|
111
|
-
setPropSubscription(key, instanceProperty, value) {
|
|
112
|
-
if (this.propSubscriptions.has(key)) {
|
|
113
|
-
const v = this.propSubscriptions.get(key);
|
|
114
|
-
if (v.prop === value) {
|
|
115
|
-
// Prop hasn't changed, so the existing subscription can stay.
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
// Now that the value has changed, unsubscribe from the previous value's subscription.
|
|
119
|
-
if (!v.sub.closed) {
|
|
120
|
-
v.sub.unsubscribe();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const sub = instanceProperty.subscribe(value);
|
|
124
|
-
this.propSubscriptions.set(key, { prop: value, sub });
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
__decorate([
|
|
128
|
-
(0, core_1.ViewChild)('target', { read: core_1.ViewContainerRef, static: true }),
|
|
129
|
-
__metadata("design:type", core_1.ViewContainerRef)
|
|
130
|
-
], AppComponent.prototype, "target", void 0);
|
|
131
|
-
AppComponent = __decorate([
|
|
132
|
-
(0, core_1.Component)({
|
|
133
|
-
selector: 'storybook-dynamic-app-root',
|
|
134
|
-
template: '<ng-template #target></ng-template>',
|
|
135
|
-
}),
|
|
136
|
-
__param(2, (0, core_1.Inject)(app_token_1.STORY)),
|
|
137
|
-
__metadata("design:paramtypes", [core_1.ComponentFactoryResolver,
|
|
138
|
-
core_1.ChangeDetectorRef,
|
|
139
|
-
rxjs_1.Observable])
|
|
140
|
-
], AppComponent);
|
|
141
|
-
exports.AppComponent = AppComponent;
|