@storybook/web-components 11.0.0-alpha.6 → 11.0.0-alpha.8
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/_browser-chunks/{chunk-TXUT6K6E.js → chunk-4CVRUPXU.js} +9 -6
- package/dist/_browser-chunks/{chunk-BNL7LBNI.js → chunk-XOX44XZE.js} +18 -11
- package/dist/_node-chunks/{chunk-X7F7EONQ.js → chunk-7DGX2RHV.js} +527 -117
- package/dist/_node-chunks/chunk-A2ZEEPU6.js +76 -0
- package/dist/docgen/docgen-worker.js +8 -8
- package/dist/docgen/index.d.ts +13 -15
- package/dist/docgen/index.js +8 -11
- package/dist/entry-preview-argtypes.js +7 -5
- package/dist/entry-preview.js +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +2 -2
- package/dist/preset.js +131 -559
- package/package.json +7 -4
- package/template/stories_lit-vite-default-ts/demo-wc-counter/DemoWcCounter.js +176 -0
- package/template/stories_lit-vite-default-ts/demo-wc-counter/index.js +3 -0
- package/template/stories_lit-vite-default-ts/demo-wc-counter.stories.js +217 -0
- package/dist/_node-chunks/chunk-GDY64HEP.js +0 -87
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/web-components",
|
|
3
|
-
"version": "11.0.0-alpha.
|
|
3
|
+
"version": "11.0.0-alpha.8",
|
|
4
4
|
"description": "Storybook Web Components renderer: Develop, document, and test UI components in isolation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -54,9 +54,12 @@
|
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@storybook/global": "^5.0.0",
|
|
57
|
+
"@wc-toolkit/cem-generator": "^0.2.1",
|
|
58
|
+
"@wc-toolkit/cem-generator-lit": "^0.1.16",
|
|
57
59
|
"custom-elements-manifest": "^2.1.0",
|
|
58
60
|
"tiny-invariant": "^1.3.1",
|
|
59
|
-
"ts-dedent": "^2.
|
|
61
|
+
"ts-dedent": "^2.2.0",
|
|
62
|
+
"typescript": "^6.0.3"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
65
|
"@types/cross-spawn": "^6.0.6",
|
|
@@ -65,13 +68,13 @@
|
|
|
65
68
|
"cross-spawn": "^7.0.6",
|
|
66
69
|
"es-toolkit": "^1.43.0",
|
|
67
70
|
"lit": "2.3.1",
|
|
71
|
+
"pathe": "^1.1.2",
|
|
68
72
|
"tmp": "^0.2.3",
|
|
69
|
-
"typescript": "^6.0.3",
|
|
70
73
|
"web-component-analyzer": "^1.1.6"
|
|
71
74
|
},
|
|
72
75
|
"peerDependencies": {
|
|
73
76
|
"lit": "^2.0.0 || ^3.0.0",
|
|
74
|
-
"storybook": "^11.0.0-alpha.
|
|
77
|
+
"storybook": "^11.0.0-alpha.8"
|
|
75
78
|
},
|
|
76
79
|
"publishConfig": {
|
|
77
80
|
"access": "public"
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A counter that exposes every Custom Elements Manifest category the default render binds.
|
|
5
|
+
*
|
|
6
|
+
* @fires count-changed - Fires after the count changes, with the new count as `detail.count`
|
|
7
|
+
* @slot - Label shown next to the value
|
|
8
|
+
* @slot prefix - Content rendered before the label
|
|
9
|
+
* @cssprop {<color>} [--demo-wc-counter-accent=rgb(0, 95, 204)] - Background of the increment button
|
|
10
|
+
* @cssprop {<number>} [--demo-wc-counter-badge-opacity=1] - Opacity of the badges
|
|
11
|
+
* @csspart badge - A badge rendered next to the current count
|
|
12
|
+
* @csspart button - The increment button
|
|
13
|
+
* @csspart deadline - The deadline, when set
|
|
14
|
+
* @csspart value - The current count
|
|
15
|
+
* @cssstate at-max - Set while the count has reached `max`
|
|
16
|
+
*/
|
|
17
|
+
export class DemoWcCounter extends LitElement {
|
|
18
|
+
static properties = {
|
|
19
|
+
count: { type: Number, reflect: true },
|
|
20
|
+
step: { type: Number },
|
|
21
|
+
max: { type: Number },
|
|
22
|
+
disabled: { type: Boolean, reflect: true },
|
|
23
|
+
size: { type: String, reflect: true },
|
|
24
|
+
tone: { type: String, reflect: true },
|
|
25
|
+
label: { type: String },
|
|
26
|
+
badges: { attribute: false },
|
|
27
|
+
unit: { attribute: false },
|
|
28
|
+
deadline: { attribute: false },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
static styles = css`
|
|
32
|
+
:host {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 8px;
|
|
36
|
+
font-family: sans-serif;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
button {
|
|
40
|
+
border: none;
|
|
41
|
+
border-radius: 4px;
|
|
42
|
+
padding: 4px 12px;
|
|
43
|
+
color: white;
|
|
44
|
+
background: var(--demo-wc-counter-accent, rgb(0, 95, 204));
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:host([tone='success']) [part='value'] {
|
|
49
|
+
color: rgb(0, 128, 0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
:host([tone='danger']) [part='value'] {
|
|
53
|
+
color: rgb(220, 20, 60);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[part='badge'] {
|
|
57
|
+
opacity: var(--demo-wc-counter-badge-opacity, 1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:host([size='small']) button {
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
padding: 2px 8px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
:host([size='large']) button {
|
|
66
|
+
font-size: 20px;
|
|
67
|
+
padding: 8px 16px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
button:disabled {
|
|
71
|
+
opacity: 0.5;
|
|
72
|
+
cursor: not-allowed;
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
#internals = this.attachInternals();
|
|
77
|
+
|
|
78
|
+
constructor() {
|
|
79
|
+
super();
|
|
80
|
+
|
|
81
|
+
/** Current value */
|
|
82
|
+
this.count = 0;
|
|
83
|
+
|
|
84
|
+
/** Amount added on every increment */
|
|
85
|
+
this.step = 1;
|
|
86
|
+
|
|
87
|
+
/** Highest value the counter can reach */
|
|
88
|
+
this.max = 10;
|
|
89
|
+
|
|
90
|
+
/** Prevents incrementing */
|
|
91
|
+
this.disabled = false;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Button size
|
|
95
|
+
*
|
|
96
|
+
* @type {'small' | 'medium' | 'large'}
|
|
97
|
+
*/
|
|
98
|
+
this.size = 'medium';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Color of the value
|
|
102
|
+
*
|
|
103
|
+
* @type {'neutral' | 'info' | 'success' | 'warning' | 'danger' | 'brand'}
|
|
104
|
+
*/
|
|
105
|
+
this.tone = 'neutral';
|
|
106
|
+
|
|
107
|
+
/** Accessible name of the increment button */
|
|
108
|
+
this.label = 'Increment';
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Badges shown after the value, only settable as a property
|
|
112
|
+
*
|
|
113
|
+
* @type {Array<'new' | 'hot' | 'sale'>}
|
|
114
|
+
*/
|
|
115
|
+
this.badges = [];
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Words used after the value, only settable as a property
|
|
119
|
+
*
|
|
120
|
+
* @type {{ singular: string, plural: string }}
|
|
121
|
+
*/
|
|
122
|
+
this.unit = { singular: 'click', plural: 'clicks' };
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Date shown after the value, only settable as a property
|
|
126
|
+
*
|
|
127
|
+
* @type {Date | undefined}
|
|
128
|
+
*/
|
|
129
|
+
this.deadline = undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Whether the count has reached `max` */
|
|
133
|
+
get atMax() {
|
|
134
|
+
return this.count >= this.max;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Adds `step` to the count, up to `max` */
|
|
138
|
+
increment() {
|
|
139
|
+
if (this.disabled || this.atMax) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.count = Math.min(this.count + this.step, this.max);
|
|
143
|
+
this.dispatchEvent(new CustomEvent('count-changed', { detail: { count: this.count } }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
updated() {
|
|
147
|
+
if (this.atMax) {
|
|
148
|
+
this.#internals.states.add('at-max');
|
|
149
|
+
} else {
|
|
150
|
+
this.#internals.states.delete('at-max');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
render() {
|
|
155
|
+
const unit = this.count === 1 ? this.unit.singular : this.unit.plural;
|
|
156
|
+
return html`
|
|
157
|
+
<slot name="prefix"></slot>
|
|
158
|
+
<slot></slot>
|
|
159
|
+
<span part="value">${this.count} ${unit}</span>
|
|
160
|
+
${this.badges.map((badge) => html`<span part="badge">${badge}</span>`)}
|
|
161
|
+
${
|
|
162
|
+
this.deadline === undefined
|
|
163
|
+
? nothing
|
|
164
|
+
: html`<time part="deadline">${new Date(this.deadline).toISOString().slice(0, 10)}</time>`
|
|
165
|
+
}
|
|
166
|
+
<button
|
|
167
|
+
part="button"
|
|
168
|
+
aria-label=${this.label}
|
|
169
|
+
?disabled=${this.disabled || this.atMax}
|
|
170
|
+
@click=${this.increment}
|
|
171
|
+
>
|
|
172
|
+
+${this.step}
|
|
173
|
+
</button>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { expect, fn, userEvent, waitFor } from 'storybook/test';
|
|
2
|
+
|
|
3
|
+
import './demo-wc-counter';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every story uses the default render, which binds each arg by the category its key encodes in the
|
|
7
|
+
* Custom Elements Manifest: attributes and properties, `-event`, `-slot`, `-part`, `-state`, and
|
|
8
|
+
* `--` CSS custom properties.
|
|
9
|
+
*/
|
|
10
|
+
export default {
|
|
11
|
+
component: 'demo-wc-counter',
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Attributes = {
|
|
16
|
+
args: { count: 3, step: 2, disabled: true },
|
|
17
|
+
play: async ({ canvasElement }) => {
|
|
18
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
19
|
+
await counter.updateComplete;
|
|
20
|
+
|
|
21
|
+
await expect(counter).toHaveAttribute('count', '3');
|
|
22
|
+
await expect(counter).toHaveAttribute('disabled');
|
|
23
|
+
await expect(counter.shadowRoot.querySelector('[part="value"]')).toHaveTextContent('3 clicks');
|
|
24
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toBeDisabled();
|
|
25
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toHaveTextContent('+2');
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const BooleanAttributeOff = {
|
|
30
|
+
args: { disabled: false },
|
|
31
|
+
play: async ({ canvasElement }) => {
|
|
32
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
33
|
+
await counter.updateComplete;
|
|
34
|
+
|
|
35
|
+
await expect(counter).not.toHaveAttribute('disabled');
|
|
36
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toBeEnabled();
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const EnumAttribute = {
|
|
41
|
+
args: { size: 'large' },
|
|
42
|
+
play: async ({ canvasElement }) => {
|
|
43
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
44
|
+
await counter.updateComplete;
|
|
45
|
+
|
|
46
|
+
const button = counter.shadowRoot.querySelector('[part="button"]');
|
|
47
|
+
await expect(counter).toHaveAttribute('size', 'large');
|
|
48
|
+
await expect(getComputedStyle(button).fontSize).toBe('20px');
|
|
49
|
+
await expect(getComputedStyle(button).paddingTop).toBe('8px');
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const TextAttribute = {
|
|
54
|
+
args: { label: 'Add a point' },
|
|
55
|
+
play: async ({ canvasElement }) => {
|
|
56
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
57
|
+
await counter.updateComplete;
|
|
58
|
+
|
|
59
|
+
await expect(counter.label).toBe('Add a point');
|
|
60
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toHaveAccessibleName(
|
|
61
|
+
'Add a point'
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const SelectAttribute = {
|
|
67
|
+
args: { tone: 'danger' },
|
|
68
|
+
play: async ({ canvasElement }) => {
|
|
69
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
70
|
+
await counter.updateComplete;
|
|
71
|
+
|
|
72
|
+
const value = counter.shadowRoot.querySelector('[part="value"]');
|
|
73
|
+
await expect(counter).toHaveAttribute('tone', 'danger');
|
|
74
|
+
await expect(getComputedStyle(value).color).toBe('rgb(220, 20, 60)');
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const Properties = {
|
|
79
|
+
args: { count: 1, unit: { singular: 'point', plural: 'points' } },
|
|
80
|
+
play: async ({ canvasElement }) => {
|
|
81
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
82
|
+
await counter.updateComplete;
|
|
83
|
+
|
|
84
|
+
await expect(counter.unit).toEqual({ singular: 'point', plural: 'points' });
|
|
85
|
+
await expect(counter.shadowRoot.querySelector('[part="value"]')).toHaveTextContent('1 point');
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const ArrayProperty = {
|
|
90
|
+
args: { badges: ['new', 'hot'] },
|
|
91
|
+
play: async ({ args, canvasElement }) => {
|
|
92
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
93
|
+
await counter.updateComplete;
|
|
94
|
+
|
|
95
|
+
const badges = [...counter.shadowRoot.querySelectorAll('[part="badge"]')];
|
|
96
|
+
await expect(counter.badges).toEqual(args.badges);
|
|
97
|
+
await expect(counter).not.toHaveAttribute('badges');
|
|
98
|
+
await expect(badges).toHaveLength(2);
|
|
99
|
+
await expect(badges.map((badge) => badge.textContent)).toEqual(['new', 'hot']);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const DateProperty = {
|
|
104
|
+
args: { deadline: new Date('2026-12-24T00:00:00.000Z') },
|
|
105
|
+
play: async ({ canvasElement }) => {
|
|
106
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
107
|
+
await counter.updateComplete;
|
|
108
|
+
|
|
109
|
+
await expect(counter).not.toHaveAttribute('deadline');
|
|
110
|
+
await expect(counter.shadowRoot.querySelector('[part="deadline"]')).toHaveTextContent(
|
|
111
|
+
'2026-12-24'
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const Events = {
|
|
117
|
+
args: { 'count-changed-event': fn() },
|
|
118
|
+
play: async ({ args, canvasElement }) => {
|
|
119
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
120
|
+
await counter.updateComplete;
|
|
121
|
+
|
|
122
|
+
await userEvent.click(counter.shadowRoot.querySelector('[part="button"]'));
|
|
123
|
+
|
|
124
|
+
await expect(args['count-changed-event']).toHaveBeenCalledWith(
|
|
125
|
+
expect.objectContaining({ type: 'count-changed', detail: { count: 1 } })
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const Slots = {
|
|
131
|
+
args: {
|
|
132
|
+
'default-slot': '<strong>Score</strong>',
|
|
133
|
+
'prefix-slot': '★',
|
|
134
|
+
},
|
|
135
|
+
play: async ({ canvasElement }) => {
|
|
136
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
137
|
+
await counter.updateComplete;
|
|
138
|
+
|
|
139
|
+
await expect(counter.querySelector(':scope > strong:not([slot])')).toHaveTextContent('Score');
|
|
140
|
+
await expect(counter.querySelector(':scope > [slot="prefix"]')).toHaveTextContent('★');
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const CssCustomProperties = {
|
|
145
|
+
args: { '--demo-wc-counter-accent': 'rgb(102, 51, 153)' },
|
|
146
|
+
play: async ({ canvasElement }) => {
|
|
147
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
148
|
+
await counter.updateComplete;
|
|
149
|
+
|
|
150
|
+
const button = counter.shadowRoot.querySelector('[part="button"]');
|
|
151
|
+
await expect(getComputedStyle(button).backgroundColor).toBe('rgb(102, 51, 153)');
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const NumberCssCustomProperty = {
|
|
156
|
+
args: { badges: ['new'], '--demo-wc-counter-badge-opacity': 0.5 },
|
|
157
|
+
play: async ({ canvasElement }) => {
|
|
158
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
159
|
+
await counter.updateComplete;
|
|
160
|
+
|
|
161
|
+
const badge = counter.shadowRoot.querySelector('[part="badge"]');
|
|
162
|
+
await expect(counter.style.getPropertyValue('--demo-wc-counter-badge-opacity')).toBe('0.5');
|
|
163
|
+
await expect(getComputedStyle(badge).opacity).toBe('0.5');
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const CssParts = {
|
|
168
|
+
args: { 'value-part': 'color: rgb(220, 20, 60); font-weight: 700;' },
|
|
169
|
+
play: async ({ canvasElement }) => {
|
|
170
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
171
|
+
await counter.updateComplete;
|
|
172
|
+
|
|
173
|
+
const value = counter.shadowRoot.querySelector('[part="value"]');
|
|
174
|
+
await expect(getComputedStyle(value).color).toBe('rgb(220, 20, 60)');
|
|
175
|
+
await expect(getComputedStyle(value).fontWeight).toBe('700');
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const CssStates = {
|
|
180
|
+
args: {
|
|
181
|
+
count: 4,
|
|
182
|
+
max: 5,
|
|
183
|
+
'at-max-state': 'outline: 2px solid rgb(0, 128, 0);',
|
|
184
|
+
},
|
|
185
|
+
play: async ({ canvasElement }) => {
|
|
186
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
187
|
+
await counter.updateComplete;
|
|
188
|
+
|
|
189
|
+
await expect(getComputedStyle(counter).outlineStyle).toBe('none');
|
|
190
|
+
|
|
191
|
+
await userEvent.click(counter.shadowRoot.querySelector('[part="button"]'));
|
|
192
|
+
|
|
193
|
+
await waitFor(() => expect(counter.matches(':state(at-max)')).toBe(true));
|
|
194
|
+
await expect(getComputedStyle(counter).outlineColor).toBe('rgb(0, 128, 0)');
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const AllCategories = {
|
|
199
|
+
args: {
|
|
200
|
+
count: 2,
|
|
201
|
+
step: 3,
|
|
202
|
+
disabled: false,
|
|
203
|
+
size: 'small',
|
|
204
|
+
tone: 'success',
|
|
205
|
+
label: 'Add a star',
|
|
206
|
+
badges: ['sale'],
|
|
207
|
+
unit: { singular: 'star', plural: 'stars' },
|
|
208
|
+
deadline: new Date('2026-12-24T00:00:00.000Z'),
|
|
209
|
+
'count-changed-event': fn(),
|
|
210
|
+
'default-slot': 'Rating',
|
|
211
|
+
'prefix-slot': '★',
|
|
212
|
+
'--demo-wc-counter-accent': 'rgb(178, 34, 34)',
|
|
213
|
+
'--demo-wc-counter-badge-opacity': 0.8,
|
|
214
|
+
'value-part': 'font-variant-numeric: tabular-nums;',
|
|
215
|
+
'at-max-state': 'opacity: 0.6;',
|
|
216
|
+
},
|
|
217
|
+
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import CJS_COMPAT_NODE_URL_3ov4ld79bt3 from 'node:url';
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_3ov4ld79bt3 from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_3ov4ld79bt3 from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_3ov4ld79bt3.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_3ov4ld79bt3.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_3ov4ld79bt3.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
// src/docgen/component-docgen/utils.ts
|
|
14
|
-
function isRecord(value) {
|
|
15
|
-
return value !== null && typeof value == "object";
|
|
16
|
-
}
|
|
17
|
-
function namedItems(value) {
|
|
18
|
-
return Array.isArray(value) ? value.filter((item) => isRecord(item) && typeof item.name == "string") : [];
|
|
19
|
-
}
|
|
20
|
-
function errorMessage(error) {
|
|
21
|
-
return error instanceof Error ? error.message : String(error);
|
|
22
|
-
}
|
|
23
|
-
var trimmedOrUndefined = (text) => typeof text == "string" && text.trim() || void 0;
|
|
24
|
-
function deprecationMessage(deprecated) {
|
|
25
|
-
if (deprecated)
|
|
26
|
-
return typeof deprecated == "string" ? trimmedOrUndefined(deprecated) : "deprecated";
|
|
27
|
-
}
|
|
28
|
-
function firstValue(sources, read) {
|
|
29
|
-
for (let source of sources) {
|
|
30
|
-
let value = read(source);
|
|
31
|
-
if (value !== void 0)
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/docgen/component-docgen/arg-types/alt-type.ts
|
|
37
|
-
var DEFAULT_TYPE_PROPERTY = "parsedType";
|
|
38
|
-
function readTypeText(item, typeProperty) {
|
|
39
|
-
let alternate = Reflect.get(item, typeProperty);
|
|
40
|
-
return isRecord(alternate) && typeof alternate.text == "string" && alternate.text.trim() ? alternate.text : typeof item.type?.text == "string" ? item.type.text : void 0;
|
|
41
|
-
}
|
|
42
|
-
function readCssPropertySyntax(property, typeProperty) {
|
|
43
|
-
return property.syntax ?? readTypeText(property, typeProperty);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/docgen/component-docgen/resolve-component/resolve-component.ts
|
|
47
|
-
import { loadCsf, unwrapExpression } from "storybook/internal/csf-tools";
|
|
48
|
-
import { recast, types as t } from "storybook/internal/babel";
|
|
49
|
-
import { readFileSync } from "node:fs";
|
|
50
|
-
function parseStoryFile(storyFilePath, title) {
|
|
51
|
-
try {
|
|
52
|
-
let source = readFileSync(storyFilePath, "utf8");
|
|
53
|
-
return loadCsf(source, { makeTitle: () => title }).parse();
|
|
54
|
-
} catch {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
var expressionFor = (node) => recast.print(node).code;
|
|
59
|
-
function tagFromNode(node) {
|
|
60
|
-
let expression = expressionFor(node), unwrapped = unwrapExpression(node);
|
|
61
|
-
if (t.isStringLiteral(unwrapped) && unwrapped.value !== "")
|
|
62
|
-
return { tag: unwrapped.value };
|
|
63
|
-
if (t.isTemplateLiteral(unwrapped) && unwrapped.expressions.length === 0) {
|
|
64
|
-
let tag = unwrapped.quasis[0]?.value.cooked;
|
|
65
|
-
if (tag)
|
|
66
|
-
return { tag };
|
|
67
|
-
}
|
|
68
|
-
return { reason: "component-not-a-tag", expression };
|
|
69
|
-
}
|
|
70
|
-
function resolveStoryComponent(csf) {
|
|
71
|
-
let component = csf._metaAnnotations.component;
|
|
72
|
-
return component ? tagFromNode(component) : { reason: "no-meta-component" };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
isRecord,
|
|
77
|
-
namedItems,
|
|
78
|
-
errorMessage,
|
|
79
|
-
trimmedOrUndefined,
|
|
80
|
-
deprecationMessage,
|
|
81
|
-
firstValue,
|
|
82
|
-
DEFAULT_TYPE_PROPERTY,
|
|
83
|
-
readTypeText,
|
|
84
|
-
readCssPropertySyntax,
|
|
85
|
-
parseStoryFile,
|
|
86
|
-
resolveStoryComponent
|
|
87
|
-
};
|