@analogjs/storybook-angular 2.5.0-beta.35 → 2.5.0-beta.37
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/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { type AngularOptions, type Parameters as AngularParameters, type AngularRenderer, type Decorator, type IStory, type Loader, type Meta, type Preview, type StoryContext, type StoryFn, type StoryObj, applicationConfig, argsToTemplate,
|
|
1
|
+
export { type AngularOptions, type Parameters as AngularParameters, type AngularRenderer, type Decorator, type IStory, type Loader, type Meta, type Preview, type StoryContext, type StoryFn, type StoryObj, applicationConfig, argsToTemplate, moduleMetadata, setProjectAnnotations, } from '@storybook/angular';
|
|
2
|
+
export { componentWrapperDecorator } from './lib/component-wrapper-decorator';
|
|
2
3
|
export { type FrameworkOptions, type StorybookConfig } from './types';
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { applicationConfig, argsToTemplate,
|
|
1
|
+
export { applicationConfig, argsToTemplate, moduleMetadata, setProjectAnnotations, } from '@storybook/angular';
|
|
2
|
+
export { componentWrapperDecorator } from './lib/component-wrapper-decorator';
|
|
2
3
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/storybook-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,iBAAiB,EACjB,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/storybook-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Type } from '@angular/core';
|
|
2
|
+
import { type AngularRenderer, type StoryContext } from '@storybook/angular';
|
|
3
|
+
import type { DecoratorFunction } from 'storybook/internal/types';
|
|
4
|
+
type StoryProps = Record<string, unknown>;
|
|
5
|
+
export declare function componentWrapperDecorator<TArgs = any>(element: Type<unknown> | ((story: string) => string), props?: StoryProps | ((storyContext: StoryContext<TArgs>) => StoryProps)): DecoratorFunction<AngularRenderer, TArgs>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { reflectComponentType, } from '@angular/core';
|
|
2
|
+
import { argsToTemplate, componentWrapperDecorator as originalComponentWrapperDecorator, } from '@storybook/angular';
|
|
3
|
+
const VOID_ELEMENTS = new Set([
|
|
4
|
+
'area',
|
|
5
|
+
'base',
|
|
6
|
+
'br',
|
|
7
|
+
'col',
|
|
8
|
+
'command',
|
|
9
|
+
'embed',
|
|
10
|
+
'hr',
|
|
11
|
+
'img',
|
|
12
|
+
'input',
|
|
13
|
+
'keygen',
|
|
14
|
+
'link',
|
|
15
|
+
'meta',
|
|
16
|
+
'param',
|
|
17
|
+
'source',
|
|
18
|
+
'track',
|
|
19
|
+
'wbr',
|
|
20
|
+
]);
|
|
21
|
+
export function componentWrapperDecorator(element, props) {
|
|
22
|
+
const decorator = originalComponentWrapperDecorator(element, props);
|
|
23
|
+
return (storyFn, storyContext) => decorator(() => ensureStoryTemplate(storyFn(), storyContext), storyContext);
|
|
24
|
+
}
|
|
25
|
+
function ensureStoryTemplate(story, storyContext) {
|
|
26
|
+
if (story.template || !storyContext.component) {
|
|
27
|
+
return story;
|
|
28
|
+
}
|
|
29
|
+
const component = reflectComponentType(storyContext.component);
|
|
30
|
+
if (!component) {
|
|
31
|
+
return story;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...story,
|
|
35
|
+
template: createTemplate(component, story.props ?? storyContext.args),
|
|
36
|
+
userDefinedTemplate: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createTemplate(component, props) {
|
|
40
|
+
const selector = component.selector.split(',')[0]?.trim();
|
|
41
|
+
if (!selector) {
|
|
42
|
+
return '<ng-container *ngComponentOutlet="storyComponent"></ng-container>';
|
|
43
|
+
}
|
|
44
|
+
const bindings = filterTemplateBindings(component, props);
|
|
45
|
+
const attributes = argsToTemplate(bindings);
|
|
46
|
+
return buildTemplate(selector, attributes);
|
|
47
|
+
}
|
|
48
|
+
function filterTemplateBindings(component, props) {
|
|
49
|
+
if (!props || typeof props !== 'object') {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
const supportedBindings = new Set([
|
|
53
|
+
...component.inputs.map((input) => input.templateName),
|
|
54
|
+
...component.outputs.map((output) => output.templateName),
|
|
55
|
+
]);
|
|
56
|
+
return Object.fromEntries(Object.entries(props).filter(([key, value]) => {
|
|
57
|
+
return value !== undefined && supportedBindings.has(key);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
function buildTemplate(selector, attributes) {
|
|
61
|
+
const elementMatch = selector.match(/^[A-Za-z][\w-]*/);
|
|
62
|
+
const tagName = elementMatch?.[0] ?? 'div';
|
|
63
|
+
const id = selector.match(/#([\w-]+)/)?.[1];
|
|
64
|
+
const classes = [...selector.matchAll(/\.([\w-]+)/g)].map((match) => match[1]);
|
|
65
|
+
const selectorAttributes = [...selector.matchAll(/\[([^\]]+)\]/g)].map((match) => match[1].trim());
|
|
66
|
+
const parts = [
|
|
67
|
+
id ? `id="${id}"` : '',
|
|
68
|
+
classes.length > 0 ? `class="${classes.join(' ')}"` : '',
|
|
69
|
+
...selectorAttributes,
|
|
70
|
+
attributes,
|
|
71
|
+
].filter(Boolean);
|
|
72
|
+
const openingTag = parts.length > 0 ? `<${tagName} ${parts.join(' ')}>` : `<${tagName}>`;
|
|
73
|
+
if (VOID_ELEMENTS.has(tagName)) {
|
|
74
|
+
return openingTag.replace(/>$/, ' />');
|
|
75
|
+
}
|
|
76
|
+
return `${openingTag}</${tagName}>`;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=component-wrapper-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-wrapper-decorator.js","sourceRoot":"","sources":["../../../../../packages/storybook-angular/src/lib/component-wrapper-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,cAAc,EACd,yBAAyB,IAAI,iCAAiC,GAI/D,MAAM,oBAAoB,CAAC;AAK5B,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,SAAS;IACT,OAAO;IACP,IAAI;IACJ,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,UAAU,yBAAyB,CACvC,OAAoD,EACpD,KAAwE;IAExE,MAAM,SAAS,GAAG,iCAAiC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAEpE,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,CAC/B,SAAS,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,mBAAmB,CAC1B,KAAa,EACb,YAAiC;IAEjC,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,oBAAoB,CACpC,YAAY,CAAC,SAA0B,CACxC,CAAC;IAEF,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,QAAQ,EAAE,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,IA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