p-elements-core 2.1.0-rc8 → 2.1.0
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/p-elements-core.js +1 -1
- package/package.json +15 -5
- package/readme.md +13 -13
- package/typings/custom-element-controller.d.ts +18 -0
- package/typings/custom-element-controller.d.ts.map +1 -0
- package/typings/custom-element.d.ts +140 -0
- package/typings/custom-element.d.ts.map +1 -0
- package/typings/decorators/bind.d.ts +6 -0
- package/typings/decorators/bind.d.ts.map +1 -0
- package/typings/decorators/custom-element-config.d.ts +8 -0
- package/typings/decorators/custom-element-config.d.ts.map +1 -0
- package/typings/decorators/property.d.ts +213 -0
- package/typings/decorators/property.d.ts.map +1 -0
- package/typings/decorators/query.d.ts +2 -0
- package/typings/decorators/query.d.ts.map +1 -0
- package/typings/decorators/render-property-on-set.d.ts +2 -0
- package/typings/decorators/render-property-on-set.d.ts.map +1 -0
- package/typings/maquette/cache.d.ts +10 -0
- package/typings/maquette/cache.d.ts.map +1 -0
- package/typings/maquette/dom.d.ts +60 -0
- package/typings/maquette/dom.d.ts.map +1 -0
- package/typings/maquette/h.d.ts +35 -0
- package/typings/maquette/h.d.ts.map +1 -0
- package/{src/maquette/index.ts → typings/maquette/index.d.ts} +1 -1
- package/typings/maquette/index.d.ts.map +1 -0
- package/typings/maquette/interfaces.d.ts +475 -0
- package/typings/maquette/interfaces.d.ts.map +1 -0
- package/typings/maquette/jsx.d.ts +6 -0
- package/typings/maquette/jsx.d.ts.map +1 -0
- package/typings/maquette/mapping.d.ts +14 -0
- package/typings/maquette/mapping.d.ts.map +1 -0
- package/typings/maquette/projection.d.ts +9 -0
- package/typings/maquette/projection.d.ts.map +1 -0
- package/typings/maquette/projector.d.ts +27 -0
- package/typings/maquette/projector.d.ts.map +1 -0
- package/typings/p-elements-core.d.ts +239 -0
- package/typings/p-elements-core.d.ts.map +1 -0
- package/.babelrc +0 -21
- package/.editorconfig +0 -17
- package/.gitlab-ci.yml +0 -18
- package/demo/sample.js +0 -1
- package/demo/screen.css +0 -6
- package/demo/theme.css +0 -14
- package/docs/.eleventy.js +0 -109
- package/docs/package.json +0 -27
- package/docs/src/404.md +0 -8
- package/docs/src/_data/demos/animation/animation.tsx +0 -216
- package/docs/src/_data/demos/animation/index.html +0 -10
- package/docs/src/_data/demos/animation/project.json +0 -7
- package/docs/src/_data/demos/hello-world/hello-world.tsx +0 -35
- package/docs/src/_data/demos/hello-world/index.html +0 -10
- package/docs/src/_data/demos/hello-world/project.json +0 -7
- package/docs/src/_data/demos/timer/demo-timer.tsx +0 -120
- package/docs/src/_data/demos/timer/icons.tsx +0 -62
- package/docs/src/_data/demos/timer/index.html +0 -12
- package/docs/src/_data/demos/timer/project.json +0 -8
- package/docs/src/_data/global.js +0 -14
- package/docs/src/_data/helpers.js +0 -19
- package/docs/src/_includes/layouts/base.njk +0 -31
- package/docs/src/_includes/layouts/playground.njk +0 -40
- package/docs/src/_includes/partials/app-header.njk +0 -9
- package/docs/src/_includes/partials/head.njk +0 -15
- package/docs/src/_includes/partials/nav.njk +0 -20
- package/docs/src/_includes/partials/top-nav.njk +0 -52
- package/docs/src/assets/favicon.png +0 -0
- package/docs/src/assets/logo.svg +0 -9
- package/docs/src/documentation/custom-element-controller.md +0 -294
- package/docs/src/documentation/custom-element.md +0 -221
- package/docs/src/documentation/decorators/bind.md +0 -71
- package/docs/src/documentation/decorators/custom-element-config.md +0 -63
- package/docs/src/documentation/decorators/property.md +0 -83
- package/docs/src/documentation/decorators/query.md +0 -66
- package/docs/src/documentation/decorators/render-property-on-set.md +0 -60
- package/docs/src/documentation/decorators.md +0 -9
- package/docs/src/documentation/getting-started.md +0 -60
- package/docs/src/documentation/index.md +0 -33
- package/docs/src/documentation/reactive-properties.md +0 -54
- package/docs/src/index.d.ts +0 -25
- package/docs/src/index.md +0 -3
- package/docs/src/playground/animation.njk +0 -10
- package/docs/src/playground/index.njk +0 -10
- package/docs/src/playground/timer.njk +0 -10
- package/docs/src/scripts/components/app-drawer/app-drawer.css +0 -92
- package/docs/src/scripts/components/app-drawer/app-drawer.tsx +0 -67
- package/docs/src/scripts/components/app-mobile-menu/app-mobile-menu.css +0 -48
- package/docs/src/scripts/components/app-mobile-menu/app-mobile-menu.tsx +0 -112
- package/docs/src/scripts/components/app-mode-switch/app-mode-switch.css +0 -78
- package/docs/src/scripts/components/app-mode-switch/app-mode-switch.tsx +0 -166
- package/docs/src/scripts/components/app-playground/app-playground.tsx +0 -190
- package/docs/src/scripts/components/app-split-panel/app-split-panel.css +0 -33
- package/docs/src/scripts/components/app-split-panel/app-split-panel.tsx +0 -73
- package/docs/src/scripts/components/app-split-panel/resize-bar.tsx +0 -155
- package/docs/src/scripts/components/lazy-svg/lazy-svg.tsx +0 -94
- package/docs/src/scripts/index.ts +0 -6
- package/docs/src/scripts/playground.ts +0 -1
- package/docs/src/styles/main.css +0 -699
- package/docs/tsconfig.json +0 -22
- package/index.html +0 -49
- package/src/custom-element-controller.ts +0 -31
- package/src/custom-element.ts +0 -588
- package/src/decorators/bind.ts +0 -46
- package/src/decorators/custom-element-config.ts +0 -17
- package/src/decorators/property.ts +0 -684
- package/src/decorators/query.ts +0 -12
- package/src/decorators/render-property-on-set.ts +0 -3
- package/src/maquette/cache.ts +0 -35
- package/src/maquette/dom.ts +0 -115
- package/src/maquette/h.ts +0 -100
- package/src/maquette/interfaces.ts +0 -536
- package/src/maquette/jsx.ts +0 -61
- package/src/maquette/mapping.ts +0 -56
- package/src/maquette/projection.ts +0 -666
- package/src/maquette/projector.ts +0 -200
- package/src/p-elements-core.ts +0 -260
- package/src/sample/animate.tsx +0 -199
- package/src/sample/mixin/highlight.tsx +0 -33
- package/src/sample/sample.tsx +0 -450
- package/storybook/storybook-demo/.storybook/main.ts +0 -30
- package/storybook/storybook-demo/.storybook/preview-head.html +0 -1
- package/storybook/storybook-demo/.storybook/preview.ts +0 -20
- package/storybook/storybook-demo/package.json +0 -23
- package/storybook/storybook-demo/stories/bar.stories.tsx +0 -27
- package/storybook/storybook-demo/stories/baz.stories.tsx +0 -37
- package/storybook/storybook-demo/stories/foo.mdx +0 -11
- package/storybook/storybook-demo/stories/foo.stories.tsx +0 -27
- package/storybook/storybook-demo/stories/foo.tsx +0 -24
- package/storybook/storybook-demo/tsconfig.json +0 -30
- package/storybook/storybook-p-element-vite/README.md +0 -97
- package/storybook/storybook-p-element-vite/package.json +0 -81
- package/storybook/storybook-p-element-vite/preset.js +0 -2
- package/storybook/storybook-p-element-vite/src/docs/index.ts +0 -8
- package/storybook/storybook-p-element-vite/src/docs/source-decorator.ts +0 -55
- package/storybook/storybook-p-element-vite/src/entry-preview-docs.ts +0 -16
- package/storybook/storybook-p-element-vite/src/entry-preview.ts +0 -8
- package/storybook/storybook-p-element-vite/src/index.ts +0 -9
- package/storybook/storybook-p-element-vite/src/node/index.ts +0 -5
- package/storybook/storybook-p-element-vite/src/portable-stories.ts +0 -35
- package/storybook/storybook-p-element-vite/src/preset.ts +0 -69
- package/storybook/storybook-p-element-vite/src/render.ts +0 -96
- package/storybook/storybook-p-element-vite/src/types.ts +0 -99
- package/storybook/storybook-p-element-vite/tsconfig.json +0 -14
- package/storybook/storybook-p-element-vite/tsdown.config.ts +0 -26
- package/tsconfig.json +0 -67
- package/tsconfig.sample.json +0 -20
- package/webpack.config.js +0 -76
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# P-Element Storybook Plugin
|
|
2
|
-
|
|
3
|
-
A Storybook framework plugin for [p-elements](https://github.com/outsystems/p-elements-core), enabling seamless integration of p-element web components in Storybook.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🧩 **Component Support**: Full support for p-element web components
|
|
8
|
-
- 📖 **Auto Documentation**: Automatic source code extraction for Docs tab
|
|
9
|
-
- 🎨 **TypeScript**: Complete TypeScript support with proper type definitions
|
|
10
|
-
- ⚡ **Vite Integration**: Optimized build configuration with Vite
|
|
11
|
-
- 🔄 **Portable Stories**: Support for portable stories across different environments
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install --save-dev p-element-storybook-plugin
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Configuration
|
|
20
|
-
|
|
21
|
-
Add the framework to your `.storybook/main.ts`:
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import type { StorybookConfig } from '@storybook/html-vite';
|
|
25
|
-
|
|
26
|
-
const config: StorybookConfig = {
|
|
27
|
-
stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
|
|
28
|
-
framework: {
|
|
29
|
-
name: 'p-element-storybook-plugin',
|
|
30
|
-
options: {}
|
|
31
|
-
},
|
|
32
|
-
addons: [
|
|
33
|
-
'@storybook/addon-docs'
|
|
34
|
-
]
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default config;
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
41
|
-
|
|
42
|
-
### Writing Stories
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import type { Meta, StoryObj } from 'p-element-storybook-plugin';
|
|
46
|
-
import './my-component'; // Import your p-element component
|
|
47
|
-
|
|
48
|
-
type Args = {
|
|
49
|
-
name: string;
|
|
50
|
-
disabled: boolean;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const meta: Meta<Args> = {
|
|
54
|
-
title: 'Components/MyComponent',
|
|
55
|
-
tags: ['autodocs'],
|
|
56
|
-
argTypes: {
|
|
57
|
-
name: { control: 'text' },
|
|
58
|
-
disabled: { control: 'boolean' }
|
|
59
|
-
},
|
|
60
|
-
render: (args: Args) => <my-component name={args.name} disabled={args.disabled ? "disabled" : undefined}></my-component>,
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default meta;
|
|
64
|
-
type Story = StoryObj<Args>;
|
|
65
|
-
|
|
66
|
-
export const Default: Story = {
|
|
67
|
-
args: {
|
|
68
|
-
name: 'Hello World',
|
|
69
|
-
disabled: false
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Component Types
|
|
75
|
-
|
|
76
|
-
The plugin supports multiple component types:
|
|
77
|
-
|
|
78
|
-
1. **String Templates**: Simple HTML strings with argument interpolation
|
|
79
|
-
2. **HTML Elements**: Direct HTMLElement instances
|
|
80
|
-
3. **Function Components**: Functions that return VNode
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
The plugin uses [tsdown](https://github.com/sxzz/tsdown) for building both ESM and CJS outputs with TypeScript declaration files.
|
|
84
|
-
|
|
85
|
-
## Development
|
|
86
|
-
|
|
87
|
-
### Building
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
npm run build
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Watching for Changes
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
npm run watch
|
|
97
|
-
```
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "storybook-p-element-vite",
|
|
3
|
-
"version": "2.0.0-rc1",
|
|
4
|
-
"description": "Storybook plugin for p-element",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"storybook",
|
|
8
|
-
"p-elements-core",
|
|
9
|
-
"webcomponents",
|
|
10
|
-
"components",
|
|
11
|
-
"framework"
|
|
12
|
-
],
|
|
13
|
-
"type": "module",
|
|
14
|
-
"main": "dist/index.js",
|
|
15
|
-
"module": "dist/index.js",
|
|
16
|
-
"types": "dist/index.d.ts",
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"template",
|
|
20
|
-
"@types",
|
|
21
|
-
"preset.js"
|
|
22
|
-
],
|
|
23
|
-
"exports": {
|
|
24
|
-
".": {
|
|
25
|
-
"types": "./dist/index.d.ts",
|
|
26
|
-
"import": "./dist/index.js",
|
|
27
|
-
"require": "./dist/index.cjs"
|
|
28
|
-
},
|
|
29
|
-
"./preset": {
|
|
30
|
-
"types": "./dist/preset.d.ts",
|
|
31
|
-
"import": "./dist/preset.js",
|
|
32
|
-
"require": "./dist/preset.cjs"
|
|
33
|
-
},
|
|
34
|
-
"./preview": {
|
|
35
|
-
"types": "./dist/preview.d.ts",
|
|
36
|
-
"import": "./dist/preview.js",
|
|
37
|
-
"require": "./dist/preview.cjs"
|
|
38
|
-
},
|
|
39
|
-
"./dist/preview.js": {
|
|
40
|
-
"types": "./dist/preview.d.ts",
|
|
41
|
-
"import": "./dist/preview.js",
|
|
42
|
-
"require": "./dist/preview.cjs"
|
|
43
|
-
},
|
|
44
|
-
"./node": {
|
|
45
|
-
"types": "./dist/node/index.d.ts",
|
|
46
|
-
"import": "./dist/node/index.js",
|
|
47
|
-
"require": "./dist/node/index.cjs"
|
|
48
|
-
},
|
|
49
|
-
"./package.json": "./package.json"
|
|
50
|
-
},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"build": "tsdown",
|
|
53
|
-
"dev": "tsdown --watch",
|
|
54
|
-
"watch": "tsdown --watch",
|
|
55
|
-
"clean": "rm -rf dist",
|
|
56
|
-
"prepublishOnly": "npm run build",
|
|
57
|
-
"lint": "echo 'Add linting here'",
|
|
58
|
-
"test": "echo 'Add tests here'"
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"@storybook/builder-vite": "^10.2.7",
|
|
62
|
-
"@storybook/global": "^5.0.0",
|
|
63
|
-
"@storybook/html": "^10.2.7",
|
|
64
|
-
"p-elements-core": "2.1.0-rc6"
|
|
65
|
-
},
|
|
66
|
-
"peerDependencies": {
|
|
67
|
-
"storybook": "^10.2.7"
|
|
68
|
-
},
|
|
69
|
-
"devDependencies": {
|
|
70
|
-
"@types/node": "^22.19.10",
|
|
71
|
-
"tsdown": "^0.20.3",
|
|
72
|
-
"typescript": "~5.9.3",
|
|
73
|
-
"vite": "^7.3.1"
|
|
74
|
-
},
|
|
75
|
-
"engines": {
|
|
76
|
-
"node": ">=20"
|
|
77
|
-
},
|
|
78
|
-
"publishConfig": {
|
|
79
|
-
"access": "public"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { emitTransformCode, useEffect } from 'storybook/internal/preview-api';
|
|
2
|
-
import type { DecoratorFunction } from 'storybook/internal/types';
|
|
3
|
-
import type { PElementRenderer } from '../types';
|
|
4
|
-
import { instance } from 'storybook/internal/node-logger';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Source decorator for p-element stories
|
|
8
|
-
*
|
|
9
|
-
* This decorator extracts the rendered HTML from stories and displays it
|
|
10
|
-
* in the Docs tab as source code. It handles different source languages
|
|
11
|
-
* and provides error handling for edge cases.
|
|
12
|
-
*/
|
|
13
|
-
export const sourceDecorator: DecoratorFunction<PElementRenderer<unknown>> = (storyFn, context) => {
|
|
14
|
-
const story = storyFn();
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
try {
|
|
18
|
-
const sourceLanguage = context.parameters.docs?.source?.language;
|
|
19
|
-
|
|
20
|
-
switch (sourceLanguage) {
|
|
21
|
-
case 'html': {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (context.unboundStoryFn && typeof context.unboundStoryFn(context) === "object") {
|
|
25
|
-
const vnode = context.unboundStoryFn(context);
|
|
26
|
-
if (vnode instanceof HTMLElement) {
|
|
27
|
-
emitTransformCode(vnode.outerHTML, context);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
emitTransformCode(Maquette.dom.create(vnode).domNode.outerHTML, context);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const element = context.canvasElement?.firstChild as HTMLElement;
|
|
34
|
-
if (element?.outerHTML) {
|
|
35
|
-
emitTransformCode(element.outerHTML, context);
|
|
36
|
-
|
|
37
|
-
} else {
|
|
38
|
-
console.warn('No HTML element found to extract source code from');
|
|
39
|
-
emitTransformCode('<!-- No HTML content found -->', context);
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
default: {
|
|
44
|
-
console.warn(`Unsupported source language: ${sourceLanguage}`);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('Error in source decorator:', error);
|
|
50
|
-
emitTransformCode('<!-- Error extracting source code -->', context);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return story;
|
|
55
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SourceType } from 'storybook/internal/docs-tools';
|
|
2
|
-
import type { DecoratorFunction, Parameters } from 'storybook/internal/types';
|
|
3
|
-
import { sourceDecorator } from './docs/source-decorator';
|
|
4
|
-
import type { PElementRenderer } from './types';
|
|
5
|
-
|
|
6
|
-
export const decorators: DecoratorFunction<PElementRenderer<unknown>>[] = [sourceDecorator];
|
|
7
|
-
|
|
8
|
-
export const parameters: Parameters = {
|
|
9
|
-
docs: {
|
|
10
|
-
story: { inline: true },
|
|
11
|
-
source: {
|
|
12
|
-
type: SourceType.DYNAMIC,
|
|
13
|
-
language: 'html',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { enhanceArgTypes } from 'storybook/internal/docs-tools';
|
|
2
|
-
import type { ArgTypesEnhancer, Parameters } from 'storybook/internal/types';
|
|
3
|
-
|
|
4
|
-
export const parameters: Parameters = { renderer: 'p-element' };
|
|
5
|
-
|
|
6
|
-
export { render, renderToCanvas } from './render';
|
|
7
|
-
|
|
8
|
-
export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main entry point for the p-element Storybook plugin
|
|
3
|
-
*
|
|
4
|
-
* This module exports the core types and portable stories functionality
|
|
5
|
-
* needed to use p-element components in Storybook.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './types.js';
|
|
9
|
-
export * from './portable-stories.js';
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
setProjectAnnotations as originalSetProjectAnnotations,
|
|
5
|
-
setDefaultProjectAnnotations,
|
|
6
|
-
} from 'storybook/preview-api';
|
|
7
|
-
|
|
8
|
-
import * as pElementAnnotations from './entry-preview';
|
|
9
|
-
import type { PElementRenderer } from './types';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Function that sets the globalConfig of your storybook. The global config is the preview module of
|
|
13
|
-
* your .storybook folder.
|
|
14
|
-
*
|
|
15
|
-
* It should be run a single time, so that your global config (e.g. decorators) is applied to your
|
|
16
|
-
* stories when using `composeStories` or `composeStory`.
|
|
17
|
-
*
|
|
18
|
-
* Example:
|
|
19
|
-
*
|
|
20
|
-
* ```jsx
|
|
21
|
-
* // setup-file.js
|
|
22
|
-
* import { setProjectAnnotations } from '@storybook/web-components';
|
|
23
|
-
* import projectAnnotations from './.storybook/preview';
|
|
24
|
-
*
|
|
25
|
-
* setProjectAnnotations(projectAnnotations);
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')
|
|
29
|
-
*/
|
|
30
|
-
export function setProjectAnnotations(
|
|
31
|
-
projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[],
|
|
32
|
-
): NormalizedProjectAnnotations<PElementRenderer<unknown>> {
|
|
33
|
-
setDefaultProjectAnnotations(pElementAnnotations);
|
|
34
|
-
return originalSetProjectAnnotations(projectAnnotations) as NormalizedProjectAnnotations<PElementRenderer<unknown>>;
|
|
35
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Storybook preset configuration for p-element framework
|
|
3
|
-
*
|
|
4
|
-
* Note: We can't prefix Node.js imports with `node:` because it will break
|
|
5
|
-
* within Storybook due to its Vite setup.
|
|
6
|
-
*/
|
|
7
|
-
import { createRequire } from 'module';
|
|
8
|
-
import { dirname, join } from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
import { mergeConfig } from 'vite';
|
|
11
|
-
import { StorybookConfig } from './types';
|
|
12
|
-
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Helper function to resolve absolute paths for Storybook dependencies
|
|
17
|
-
*/
|
|
18
|
-
const getAbsolutePath = <I extends string>(input: I): I =>
|
|
19
|
-
dirname(require.resolve(join(input, 'package.json'))) as I;
|
|
20
|
-
|
|
21
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
22
|
-
const renderer = join(__dirname, 'entry-preview.mjs');
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Core Storybook configuration
|
|
26
|
-
*/
|
|
27
|
-
export const core: StorybookConfig['core'] = {
|
|
28
|
-
builder: '@storybook/builder-vite',
|
|
29
|
-
renderer,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Vite configuration customization
|
|
34
|
-
*/
|
|
35
|
-
export const viteFinal: StorybookConfig['viteFinal'] = async (defaultConfig, { configType }) => {
|
|
36
|
-
const baseConfig = mergeConfig(defaultConfig, {
|
|
37
|
-
build: {
|
|
38
|
-
target: 'es2020',
|
|
39
|
-
},
|
|
40
|
-
plugins: [],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (configType === 'DEVELOPMENT') {
|
|
44
|
-
return mergeConfig(baseConfig, {
|
|
45
|
-
build: {
|
|
46
|
-
rollupOptions: {
|
|
47
|
-
// Add development-specific rollup options here if needed
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return baseConfig;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Preview annotations configuration
|
|
58
|
-
* Determines which preview files to load based on enabled features
|
|
59
|
-
*/
|
|
60
|
-
export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input = [], options) => {
|
|
61
|
-
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
|
|
62
|
-
const annotations: string[] = [renderer];
|
|
63
|
-
|
|
64
|
-
if (docsEnabled) {
|
|
65
|
-
annotations.push(join(__dirname, 'entry-preview-docs.mjs'));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return [...input, ...annotations];
|
|
69
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { ArgsStoryFn, RenderContext } from 'storybook/internal/types';
|
|
2
|
-
import { simulatePageLoad } from 'storybook/preview-api';
|
|
3
|
-
|
|
4
|
-
import type { PElementRenderer } from './types';
|
|
5
|
-
import { instance } from 'storybook/internal/node-logger';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Main render function for p-element stories
|
|
9
|
-
* Handles different component types: string templates, HTML elements, and functions
|
|
10
|
-
*/
|
|
11
|
-
export const render: ArgsStoryFn<PElementRenderer<unknown>> = (args, context) => {
|
|
12
|
-
const { id, component: Component } = context;
|
|
13
|
-
|
|
14
|
-
// Handle string templates with argument interpolation
|
|
15
|
-
if (typeof Component === 'string') {
|
|
16
|
-
return interpolateStringTemplate(Component, args);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Handle HTML elements by cloning and setting attributes
|
|
20
|
-
if (Component instanceof HTMLElement) {
|
|
21
|
-
return cloneElementWithArgs(Component, args);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Handle function components
|
|
25
|
-
if (typeof Component === 'function') {
|
|
26
|
-
return Component(args, context);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const errorMessage = `Storybook's p-element renderer only supports rendering DOM elements, strings, and functions. Received: ${typeof Component}`;
|
|
30
|
-
console.error(errorMessage, Component);
|
|
31
|
-
throw new Error(`Unable to render story ${id}: ${errorMessage}`);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Interpolates args into a string template
|
|
36
|
-
*/
|
|
37
|
-
function interpolateStringTemplate(template: string, args: Record<string, any>): string {
|
|
38
|
-
return Object.entries(args).reduce((output, [key, value]) => {
|
|
39
|
-
const placeholder = `{{${key}}}`;
|
|
40
|
-
return output.replace(new RegExp(placeholder, 'g'), String(value));
|
|
41
|
-
}, template);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Clones an HTML element and sets attributes from args
|
|
46
|
-
*/
|
|
47
|
-
function cloneElementWithArgs(element: HTMLElement, args: Record<string, any>): HTMLElement {
|
|
48
|
-
const output = element.cloneNode(true) as HTMLElement;
|
|
49
|
-
|
|
50
|
-
Object.entries(args).forEach(([key, value]) => {
|
|
51
|
-
const attributeValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
52
|
-
output.setAttribute(key, attributeValue);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return output;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Renders the story to the canvas element
|
|
60
|
-
*/
|
|
61
|
-
export function renderToCanvas(
|
|
62
|
-
{ storyFn, showMain }: RenderContext<PElementRenderer<unknown>>,
|
|
63
|
-
canvasElement: PElementRenderer<unknown>['canvasElement'],
|
|
64
|
-
): void {
|
|
65
|
-
const vdom = storyFn();
|
|
66
|
-
showMain();
|
|
67
|
-
|
|
68
|
-
// Clear existing content
|
|
69
|
-
while (canvasElement.firstChild) {
|
|
70
|
-
canvasElement.removeChild(canvasElement.firstChild);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Create and append new content
|
|
74
|
-
if (typeof vdom === 'string') {
|
|
75
|
-
const element = document.createElement('div');
|
|
76
|
-
element.innerHTML = vdom;
|
|
77
|
-
canvasElement.appendChild(element);
|
|
78
|
-
simulatePageLoad(element);
|
|
79
|
-
} else if (vdom instanceof HTMLElement) {
|
|
80
|
-
canvasElement.appendChild(vdom);
|
|
81
|
-
simulatePageLoad(vdom);
|
|
82
|
-
} else if (vdom && 'vnodeSelector' in vdom) {
|
|
83
|
-
if (!Maquette) {
|
|
84
|
-
throw new Error('Maquette DOM library is required for rendering VNodes');
|
|
85
|
-
}
|
|
86
|
-
const vnode = Maquette.dom.create(vdom);
|
|
87
|
-
const element = vnode.domNode;
|
|
88
|
-
canvasElement.appendChild(element);
|
|
89
|
-
simulatePageLoad(element);
|
|
90
|
-
} else if (vdom instanceof Element) {
|
|
91
|
-
canvasElement.appendChild(vdom);
|
|
92
|
-
simulatePageLoad(vdom);
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error('Render function returned an unsupported type');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { StorybookConfigVite } from '@storybook/builder-vite';
|
|
2
|
-
import type {
|
|
3
|
-
AnnotatedStoryFn,
|
|
4
|
-
Args,
|
|
5
|
-
ComponentAnnotations,
|
|
6
|
-
DecoratorFunction,
|
|
7
|
-
StoryContext as GenericStoryContext,
|
|
8
|
-
LoaderFunction,
|
|
9
|
-
ProjectAnnotations,
|
|
10
|
-
StoryAnnotations,
|
|
11
|
-
StorybookConfig as StorybookConfigBase,
|
|
12
|
-
StrictArgs,
|
|
13
|
-
WebRenderer,
|
|
14
|
-
} from 'storybook/internal/types';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Utility type to extract public properties from a component props type
|
|
18
|
-
* Excludes properties that end with '$' (considered private)
|
|
19
|
-
*/
|
|
20
|
-
type PublicProps<PROPS> = (PROPS extends Record<any, any>
|
|
21
|
-
? Omit<PROPS, `${string}$`>
|
|
22
|
-
: unknown extends PROPS
|
|
23
|
-
? {}
|
|
24
|
-
: PROPS)
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Function component type for p-element components
|
|
28
|
-
*/
|
|
29
|
-
type FunctionComponent<P = unknown> = {
|
|
30
|
-
renderFn(props: P, key: string | null, flags: number): VNode | string | Element;
|
|
31
|
-
}['renderFn'];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Generic component type that can be either a function component or any other component
|
|
35
|
-
*/
|
|
36
|
-
type Component<PROPS = unknown> = FunctionComponent<PublicProps<PROPS>>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* P-Element renderer interface extending Storybook's WebRenderer
|
|
40
|
-
* Defines the shape of components, story results, and args for p-element stories
|
|
41
|
-
*/
|
|
42
|
-
export interface PElementRenderer<T> extends WebRenderer {
|
|
43
|
-
component: Component<T> | any;
|
|
44
|
-
storyResult: ReturnType<Component<T>>;
|
|
45
|
-
args: T;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Preview configuration type for p-element projects
|
|
50
|
-
* Used to configure global decorators, parameters, and other project-wide settings
|
|
51
|
-
*/
|
|
52
|
-
export type Preview = ProjectAnnotations<PElementRenderer<unknown>>;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Metadata to configure the stories for a component.
|
|
56
|
-
*
|
|
57
|
-
* @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
|
|
58
|
-
*/
|
|
59
|
-
export type Meta<TArgs = Args> = ComponentAnnotations<PElementRenderer<TArgs>, TArgs>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Story function that represents a CSFv2 component example.
|
|
63
|
-
*
|
|
64
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
65
|
-
*/
|
|
66
|
-
export type StoryFn<TArgs = Args> = AnnotatedStoryFn<PElementRenderer<TArgs>, TArgs>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Story object that represents a CSFv3 component example.
|
|
70
|
-
*
|
|
71
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
72
|
-
*/
|
|
73
|
-
export type StoryObj<TArgs = Args> = StoryAnnotations<PElementRenderer<TArgs>, TArgs>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Decorator function type for p-element stories
|
|
77
|
-
* Used to wrap stories with additional functionality or styling
|
|
78
|
-
*/
|
|
79
|
-
export type Decorator<TArgs = StrictArgs> = DecoratorFunction<PElementRenderer<TArgs>, TArgs>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Loader function type for p-element stories
|
|
83
|
-
* Used to load data or perform setup before story rendering
|
|
84
|
-
*/
|
|
85
|
-
export type Loader<TArgs = StrictArgs> = LoaderFunction<PElementRenderer<TArgs>, TArgs>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Story context type providing access to story metadata and configuration
|
|
89
|
-
*/
|
|
90
|
-
export type StoryContext<TArgs = StrictArgs> = GenericStoryContext<PElementRenderer<TArgs>, TArgs>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Storybook configuration type specific to p-element framework
|
|
94
|
-
* Extends the base Storybook config with Vite-specific options
|
|
95
|
-
*/
|
|
96
|
-
export type StorybookConfig = Omit<StorybookConfigBase, 'framework'> & {
|
|
97
|
-
framework: 'storybook-p-element-vite' | { name: 'storybook-p-element-vite' };
|
|
98
|
-
} & StorybookConfigVite;
|
|
99
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"jsx": "react",
|
|
6
|
-
"jsxFactory": "h",
|
|
7
|
-
"jsxFragmentFactory": "h.Fragment",
|
|
8
|
-
"moduleResolution": "bundler",
|
|
9
|
-
"target": "ES2020",
|
|
10
|
-
"module": "ES2020",
|
|
11
|
-
"types": ["p-elements-core"]
|
|
12
|
-
},
|
|
13
|
-
"include": ["src/**/*"]
|
|
14
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsdown';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: [
|
|
5
|
-
'./src/index.ts',
|
|
6
|
-
'./src/preset.ts',
|
|
7
|
-
'./src/entry-preview.ts',
|
|
8
|
-
'./src/entry-preview-docs.ts',
|
|
9
|
-
'./src/docs/index.ts',
|
|
10
|
-
'./src/node/index.ts',
|
|
11
|
-
],
|
|
12
|
-
// Externalize native modules and problematic dependencies
|
|
13
|
-
external: [
|
|
14
|
-
'fsevents', // macOS file watching native module
|
|
15
|
-
'esbuild', // Contains native binaries
|
|
16
|
-
'vite', // May contain native dependencies
|
|
17
|
-
],
|
|
18
|
-
outDir: './dist',
|
|
19
|
-
format: ['esm', 'cjs'],
|
|
20
|
-
target: 'es2020',
|
|
21
|
-
platform: 'node',
|
|
22
|
-
sourcemap: true,
|
|
23
|
-
clean: true,
|
|
24
|
-
dts: true,
|
|
25
|
-
tsconfig: './tsconfig.json',
|
|
26
|
-
});
|