@storybook/web-components 6.5.9 → 7.0.0-alpha.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/README.md +1 -71
- package/dist/cjs/config.js +43 -0
- package/dist/cjs/{client/customElements.js → customElements.js} +2 -1
- package/dist/cjs/{client/docs → docs}/config.js +3 -6
- package/dist/cjs/{client/docs → docs}/custom-elements.js +47 -73
- package/dist/{modern/client → cjs}/docs/sourceDecorator.js +24 -14
- package/dist/cjs/{client/index.js → index.js} +22 -25
- package/dist/cjs/{client/preview → preview}/config.js +2 -8
- package/dist/cjs/{client/preview → preview}/globals.js +3 -1
- package/dist/cjs/preview/index.js +42 -0
- package/dist/cjs/{client/preview → preview}/render.js +22 -25
- package/dist/cjs/{client/preview → preview}/types-6-0.js +0 -0
- package/dist/cjs/{client/preview → preview}/types-7-0.js +0 -0
- package/dist/cjs/{client/preview → preview}/types.js +0 -0
- package/dist/esm/config.js +6 -0
- package/dist/{modern/client → esm}/customElements.js +0 -0
- package/dist/{modern/client → esm}/docs/config.js +0 -2
- package/dist/{modern/client → esm}/docs/custom-elements.js +29 -37
- package/dist/esm/docs/sourceDecorator.js +45 -0
- package/dist/{modern/client → esm}/index.js +0 -0
- package/dist/esm/preview/config.js +1 -0
- package/dist/{modern/client → esm}/preview/globals.js +0 -0
- package/dist/{modern/client → esm}/preview/index.js +1 -1
- package/dist/{modern/client → esm}/preview/render.js +0 -0
- package/dist/esm/{client/preview → preview}/types-6-0.js +0 -0
- package/dist/esm/{client/preview → preview}/types-7-0.js +0 -0
- package/dist/esm/{client/preview → preview}/types.js +0 -0
- package/dist/types/config.d.ts +16 -0
- package/dist/{ts3.9/client → types}/customElements.d.ts +0 -0
- package/dist/{ts3.9/client → types}/docs/config.d.ts +2 -3
- package/dist/{ts3.9/client → types}/docs/custom-elements.d.ts +0 -0
- package/dist/{ts3.9/client → types}/docs/sourceDecorator.d.ts +0 -0
- package/dist/{ts3.9/client → types}/index.d.ts +0 -0
- package/dist/types/preview/config.d.ts +1 -0
- package/dist/{ts3.9/client → types}/preview/globals.d.ts +0 -0
- package/dist/{ts3.9/client → types}/preview/index.d.ts +0 -0
- package/dist/{ts3.9/client → types}/preview/render.d.ts +0 -0
- package/dist/{ts3.9/client → types}/preview/types-6-0.d.ts +0 -0
- package/dist/{ts3.9/client → types}/preview/types-7-0.d.ts +0 -0
- package/dist/{ts3.9/client → types}/preview/types.d.ts +1 -1
- package/package.json +15 -37
- package/preview.js +1 -0
- package/bin/build.js +0 -4
- package/bin/index.js +0 -3
- package/dist/cjs/client/docs/prepareForInline.js +0 -96
- package/dist/cjs/client/docs/sourceDecorator.js +0 -63
- package/dist/cjs/client/preview/index.js +0 -50
- package/dist/cjs/server/build.js +0 -9
- package/dist/cjs/server/framework-preset-web-components-docs.js +0 -17
- package/dist/cjs/server/framework-preset-web-components.js +0 -46
- package/dist/cjs/server/index.js +0 -9
- package/dist/cjs/server/options.js +0 -17
- package/dist/cjs/server/preset.js +0 -8
- package/dist/esm/client/customElements.js +0 -41
- package/dist/esm/client/docs/config.js +0 -18
- package/dist/esm/client/docs/custom-elements.js +0 -140
- package/dist/esm/client/docs/prepareForInline.js +0 -74
- package/dist/esm/client/docs/sourceDecorator.js +0 -52
- package/dist/esm/client/index.js +0 -24
- package/dist/esm/client/preview/config.js +0 -4
- package/dist/esm/client/preview/globals.js +0 -3
- package/dist/esm/client/preview/index.js +0 -27
- package/dist/esm/client/preview/render.js +0 -58
- package/dist/esm/server/build.js +0 -3
- package/dist/esm/server/framework-preset-web-components-docs.js +0 -6
- package/dist/esm/server/framework-preset-web-components.js +0 -34
- package/dist/esm/server/index.js +0 -3
- package/dist/esm/server/options.js +0 -8
- package/dist/esm/server/preset.js +0 -1
- package/dist/modern/client/docs/prepareForInline.js +0 -23
- package/dist/modern/client/preview/config.js +0 -4
- package/dist/modern/client/preview/types-6-0.js +0 -1
- package/dist/modern/client/preview/types-7-0.js +0 -1
- package/dist/modern/client/preview/types.js +0 -1
- package/dist/modern/server/build.js +0 -3
- package/dist/modern/server/framework-preset-web-components-docs.js +0 -6
- package/dist/modern/server/framework-preset-web-components.js +0 -34
- package/dist/modern/server/index.js +0 -3
- package/dist/modern/server/options.js +0 -8
- package/dist/modern/server/preset.js +0 -1
- package/dist/ts3.4/client/customElements.d.ts +0 -8
- package/dist/ts3.4/client/docs/config.d.ts +0 -18
- package/dist/ts3.4/client/docs/custom-elements.d.ts +0 -36
- package/dist/ts3.4/client/docs/prepareForInline.d.ts +0 -4
- package/dist/ts3.4/client/docs/sourceDecorator.d.ts +0 -3
- package/dist/ts3.4/client/index.d.ts +0 -3
- package/dist/ts3.4/client/preview/config.d.ts +0 -4
- package/dist/ts3.4/client/preview/globals.d.ts +0 -1
- package/dist/ts3.4/client/preview/index.d.ts +0 -24
- package/dist/ts3.4/client/preview/render.d.ts +0 -3
- package/dist/ts3.4/client/preview/types-6-0.d.ts +0 -34
- package/dist/ts3.4/client/preview/types-7-0.d.ts +0 -9
- package/dist/ts3.4/client/preview/types.d.ts +0 -16
- package/dist/ts3.4/server/build.d.ts +0 -1
- package/dist/ts3.4/server/framework-preset-web-components-docs.d.ts +0 -2
- package/dist/ts3.4/server/framework-preset-web-components.d.ts +0 -4
- package/dist/ts3.4/server/index.d.ts +0 -1
- package/dist/ts3.4/server/options.d.ts +0 -3
- package/dist/ts3.4/server/preset.d.ts +0 -2
- package/dist/ts3.9/client/docs/prepareForInline.d.ts +0 -4
- package/dist/ts3.9/client/preview/config.d.ts +0 -4
- package/dist/ts3.9/server/build.d.ts +0 -1
- package/dist/ts3.9/server/framework-preset-web-components-docs.d.ts +0 -2
- package/dist/ts3.9/server/framework-preset-web-components.d.ts +0 -4
- package/dist/ts3.9/server/index.d.ts +0 -1
- package/dist/ts3.9/server/options.d.ts +0 -3
- package/dist/ts3.9/server/preset.d.ts +0 -2
- package/preset.js +0 -1
- package/standalone.js +0 -8
- package/types-6-0.d.ts +0 -1
- package/types-7-0.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,71 +1 @@
|
|
|
1
|
-
# Storybook
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Storybook for web-components is a UI development environment for your plain web-component snippets.
|
|
6
|
-
With it, you can visualize different states of your UI components and develop them interactively.
|
|
7
|
-
|
|
8
|
-

|
|
9
|
-
|
|
10
|
-
Storybook runs outside of your app.
|
|
11
|
-
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.
|
|
12
|
-
|
|
13
|
-
## Getting Started
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
cd my-app
|
|
17
|
-
npx sb init -t web_components
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
For more information visit: [storybook.js.org](https://storybook.js.org)
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
Storybook also comes with a lot of [addons](https://storybook.js.org/addons) and a great API to customize as you wish.
|
|
25
|
-
You can also build a [static version](https://storybook.js.org/docs/web-components/sharing/publish-storybook) of your storybook and deploy it anywhere you want.
|
|
26
|
-
|
|
27
|
-
# Hot Module Reloading (HMR)
|
|
28
|
-
|
|
29
|
-
As web components register on a global registry which only accepts a certain name/class once it can lead to errors when using classical HMR. There are ideas on how to archive HMR with a static registry but there is no proven solution yet. Therefore the best approach for now is to do full page reloads. If you keep your stories to specific states of components (which we would recommend anyways) this usually means it is fast.
|
|
30
|
-
|
|
31
|
-
# Setup es6/7 dependencies
|
|
32
|
-
|
|
33
|
-
By default storybook only works with precompiled ES5 code but as most web components themselves and their libs are distributed as ES2017 you will need to manually mark those packages as "needs transpilation".
|
|
34
|
-
|
|
35
|
-
For example if you have a library called `my-library` which is in ES2017 then you can add it like so
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
// .storybook/main.js
|
|
39
|
-
|
|
40
|
-
module.exports = {
|
|
41
|
-
webpackFinal: async (config) => {
|
|
42
|
-
// find web-components rule for extra transpilation
|
|
43
|
-
const webComponentsRule = config.module.rules.find(
|
|
44
|
-
(rule) => rule.use && rule.use.options && rule.use.options.babelrc === false
|
|
45
|
-
);
|
|
46
|
-
// add your own `my-library`
|
|
47
|
-
webComponentsRule.test.push(new RegExp(`node_modules(\\/|\\\\)my-library(.*)\\.js$`));
|
|
48
|
-
|
|
49
|
-
return config;
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
By default the following folders are included
|
|
55
|
-
|
|
56
|
-
- `src/*.js`
|
|
57
|
-
- `packages/*/src/*.js`
|
|
58
|
-
- `node_modules/lit-html/*.js`
|
|
59
|
-
- `node_modules/lit-element/*.js`
|
|
60
|
-
- `node_modules/@open-wc/*.js`
|
|
61
|
-
- `node_modules/@polymer/*.js`
|
|
62
|
-
- `node_modules/@vaadin/*.js`
|
|
63
|
-
|
|
64
|
-
As you can see the `src` folder is also included.
|
|
65
|
-
The reason for that is as it has some extra configuration to allow for example `import.meta`.
|
|
66
|
-
If you use a different folder you will need to make sure webpack/babel can handle it.
|
|
67
|
-
|
|
68
|
-
# FAQ
|
|
69
|
-
|
|
70
|
-
- While working on my component I get the error `Failed to execute 'define' on 'CustomElementRegistry': the name "..." has already been used with this registry`
|
|
71
|
-
=> please see <a href="#user-content-setup-page-reload-via-hmr">Setup page reload via HMR</a>
|
|
1
|
+
# Storybook web-components renderer
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
parameters: true,
|
|
8
|
+
decorators: true,
|
|
9
|
+
argTypesEnhancers: true
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "argTypesEnhancers", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _config.argTypesEnhancers;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "decorators", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _config.decorators;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
exports.parameters = void 0;
|
|
24
|
+
|
|
25
|
+
var _config = require("./docs/config");
|
|
26
|
+
|
|
27
|
+
var _config2 = require("./preview/config");
|
|
28
|
+
|
|
29
|
+
Object.keys(_config2).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
+
if (key in exports && exports[key] === _config2[key]) return;
|
|
33
|
+
Object.defineProperty(exports, key, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _config2[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
const parameters = Object.assign({
|
|
41
|
+
framework: 'web-components'
|
|
42
|
+
}, _config.parameters);
|
|
43
|
+
exports.parameters = parameters;
|
|
@@ -33,7 +33,8 @@ function isValidMetaData(customElements) {
|
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
|
|
37
|
+
See the readme of addon-docs for web components for more details.`);
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
39
40
|
* @param customElements any for now as spec is not super stable yet
|
|
@@ -11,16 +11,13 @@ var _customElements = require("./custom-elements");
|
|
|
11
11
|
|
|
12
12
|
var _sourceDecorator = require("./sourceDecorator");
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var decorators = [_sourceDecorator.sourceDecorator];
|
|
14
|
+
const decorators = [_sourceDecorator.sourceDecorator];
|
|
17
15
|
exports.decorators = decorators;
|
|
18
|
-
|
|
16
|
+
const parameters = {
|
|
19
17
|
docs: {
|
|
20
18
|
extractArgTypes: _customElements.extractArgTypes,
|
|
21
19
|
extractComponentDescription: _customElements.extractComponentDescription,
|
|
22
20
|
inlineStories: true,
|
|
23
|
-
prepareForInline: _prepareForInline.prepareForInline,
|
|
24
21
|
source: {
|
|
25
22
|
type: _docsTools.SourceType.DYNAMIC,
|
|
26
23
|
language: 'html'
|
|
@@ -28,5 +25,5 @@ var parameters = {
|
|
|
28
25
|
}
|
|
29
26
|
};
|
|
30
27
|
exports.parameters = parameters;
|
|
31
|
-
|
|
28
|
+
const argTypesEnhancers = [_docsTools.enhanceArgTypes];
|
|
32
29
|
exports.argTypesEnhancers = argTypesEnhancers;
|
|
@@ -5,56 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.extractComponentDescription = exports.extractArgTypesFromElements = exports.extractArgTypes = void 0;
|
|
7
7
|
|
|
8
|
-
require("core-js/modules/es.object.to-string.js");
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.array.filter.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.function.name.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
15
|
-
|
|
16
|
-
require("core-js/modules/es.symbol.js");
|
|
17
|
-
|
|
18
|
-
require("core-js/modules/es.symbol.description.js");
|
|
19
|
-
|
|
20
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
21
|
-
|
|
22
|
-
require("core-js/modules/es.string.replace.js");
|
|
23
|
-
|
|
24
|
-
require("core-js/modules/es.array.find.js");
|
|
25
|
-
|
|
26
|
-
require("core-js/modules/es.object.assign.js");
|
|
27
|
-
|
|
28
8
|
var _clientLogger = require("@storybook/client-logger");
|
|
29
9
|
|
|
30
10
|
var _ = require("..");
|
|
31
11
|
|
|
32
|
-
function mapData(data, category) {
|
|
33
|
-
return data && data.filter(function (item) {
|
|
34
|
-
return item && item.name;
|
|
35
|
-
}).reduce(function (acc, item) {
|
|
36
|
-
if (item.kind === 'method') return acc;
|
|
37
|
-
|
|
38
|
-
switch (category) {
|
|
39
|
-
case 'events':
|
|
40
|
-
mapEvent(item).forEach(function (argType) {
|
|
41
|
-
acc[argType.name] = argType;
|
|
42
|
-
});
|
|
43
|
-
break;
|
|
44
|
-
|
|
45
|
-
default:
|
|
46
|
-
acc[item.name] = mapItem(item, category);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
12
|
function mapItem(item, category) {
|
|
55
13
|
var _item$type, _item$type2;
|
|
56
14
|
|
|
57
|
-
|
|
15
|
+
const type = category === 'properties' ? {
|
|
58
16
|
name: ((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.text) || item.type
|
|
59
17
|
} : {
|
|
60
18
|
name: 'void'
|
|
@@ -63,9 +21,9 @@ function mapItem(item, category) {
|
|
|
63
21
|
name: item.name,
|
|
64
22
|
required: false,
|
|
65
23
|
description: item.description,
|
|
66
|
-
type
|
|
24
|
+
type,
|
|
67
25
|
table: {
|
|
68
|
-
category
|
|
26
|
+
category,
|
|
69
27
|
type: {
|
|
70
28
|
summary: ((_item$type2 = item.type) === null || _item$type2 === void 0 ? void 0 : _item$type2.text) || item.type
|
|
71
29
|
},
|
|
@@ -77,14 +35,12 @@ function mapItem(item, category) {
|
|
|
77
35
|
}
|
|
78
36
|
|
|
79
37
|
function mapEvent(item) {
|
|
80
|
-
|
|
38
|
+
let name = item.name.replace(/(-|_|:|\.|\s)+(.)?/g, (_match, _separator, chr) => {
|
|
81
39
|
return chr ? chr.toUpperCase() : '';
|
|
82
|
-
}).replace(/^([A-Z])/,
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
name = "on".concat(name.charAt(0).toUpperCase() + name.substr(1));
|
|
40
|
+
}).replace(/^([A-Z])/, match => match.toLowerCase());
|
|
41
|
+
name = `on${name.charAt(0).toUpperCase() + name.substr(1)}`;
|
|
86
42
|
return [{
|
|
87
|
-
name
|
|
43
|
+
name,
|
|
88
44
|
action: {
|
|
89
45
|
name: item.name
|
|
90
46
|
},
|
|
@@ -94,34 +50,52 @@ function mapEvent(item) {
|
|
|
94
50
|
}, mapItem(item, 'events')];
|
|
95
51
|
}
|
|
96
52
|
|
|
97
|
-
|
|
53
|
+
function mapData(data, category) {
|
|
54
|
+
return data && data.filter(item => item && item.name).reduce((acc, item) => {
|
|
55
|
+
if (item.kind === 'method') return acc;
|
|
56
|
+
|
|
57
|
+
switch (category) {
|
|
58
|
+
case 'events':
|
|
59
|
+
mapEvent(item).forEach(argType => {
|
|
60
|
+
acc[argType.name] = argType;
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
default:
|
|
65
|
+
acc[item.name] = mapItem(item, category);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return acc;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const getMetaDataExperimental = (tagName, customElements) => {
|
|
98
74
|
if (!(0, _.isValidComponent)(tagName) || !(0, _.isValidMetaData)(customElements)) {
|
|
99
75
|
return null;
|
|
100
76
|
}
|
|
101
77
|
|
|
102
|
-
|
|
103
|
-
return tag.name.toUpperCase() === tagName.toUpperCase();
|
|
104
|
-
});
|
|
78
|
+
const metaData = customElements.tags.find(tag => tag.name.toUpperCase() === tagName.toUpperCase());
|
|
105
79
|
|
|
106
80
|
if (!metaData) {
|
|
107
|
-
_clientLogger.logger.warn(
|
|
81
|
+
_clientLogger.logger.warn(`Component not found in custom-elements.json: ${tagName}`);
|
|
108
82
|
}
|
|
109
83
|
|
|
110
84
|
return metaData;
|
|
111
85
|
};
|
|
112
86
|
|
|
113
|
-
|
|
87
|
+
const getMetaDataV1 = (tagName, customElements) => {
|
|
114
88
|
var _customElements$modul;
|
|
115
89
|
|
|
116
90
|
if (!(0, _.isValidComponent)(tagName) || !(0, _.isValidMetaData)(customElements)) {
|
|
117
91
|
return null;
|
|
118
92
|
}
|
|
119
93
|
|
|
120
|
-
|
|
121
|
-
customElements === null || customElements === void 0 ? void 0 : (_customElements$modul = customElements.modules) === null || _customElements$modul === void 0 ? void 0 : _customElements$modul.forEach(
|
|
94
|
+
let metadata;
|
|
95
|
+
customElements === null || customElements === void 0 ? void 0 : (_customElements$modul = customElements.modules) === null || _customElements$modul === void 0 ? void 0 : _customElements$modul.forEach(_module => {
|
|
122
96
|
var _module$declarations;
|
|
123
97
|
|
|
124
|
-
_module === null || _module === void 0 ? void 0 : (_module$declarations = _module.declarations) === null || _module$declarations === void 0 ? void 0 : _module$declarations.forEach(
|
|
98
|
+
_module === null || _module === void 0 ? void 0 : (_module$declarations = _module.declarations) === null || _module$declarations === void 0 ? void 0 : _module$declarations.forEach(declaration => {
|
|
125
99
|
if (declaration.tagName === tagName) {
|
|
126
100
|
metadata = declaration;
|
|
127
101
|
}
|
|
@@ -129,20 +103,13 @@ var getMetaDataV1 = function getMetaDataV1(tagName, customElements) {
|
|
|
129
103
|
});
|
|
130
104
|
|
|
131
105
|
if (!metadata) {
|
|
132
|
-
_clientLogger.logger.warn(
|
|
106
|
+
_clientLogger.logger.warn(`Component not found in custom-elements.json: ${tagName}`);
|
|
133
107
|
}
|
|
134
108
|
|
|
135
109
|
return metadata;
|
|
136
110
|
};
|
|
137
111
|
|
|
138
|
-
|
|
139
|
-
var metaData = getMetaData(tagName, customElements);
|
|
140
|
-
return metaData && Object.assign({}, mapData(metaData.attributes, 'attributes'), mapData(metaData.members, 'properties'), mapData(metaData.properties, 'properties'), mapData(metaData.events, 'events'), mapData(metaData.slots, 'slots'), mapData(metaData.cssProperties, 'css custom properties'), mapData(metaData.cssParts, 'css shadow parts'));
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
exports.extractArgTypesFromElements = extractArgTypesFromElements;
|
|
144
|
-
|
|
145
|
-
var getMetaData = function getMetaData(tagName, manifest) {
|
|
112
|
+
const getMetaData = (tagName, manifest) => {
|
|
146
113
|
if ((manifest === null || manifest === void 0 ? void 0 : manifest.version) === 'experimental') {
|
|
147
114
|
return getMetaDataExperimental(tagName, manifest);
|
|
148
115
|
}
|
|
@@ -150,15 +117,22 @@ var getMetaData = function getMetaData(tagName, manifest) {
|
|
|
150
117
|
return getMetaDataV1(tagName, manifest);
|
|
151
118
|
};
|
|
152
119
|
|
|
153
|
-
|
|
154
|
-
|
|
120
|
+
const extractArgTypesFromElements = (tagName, customElements) => {
|
|
121
|
+
const metaData = getMetaData(tagName, customElements);
|
|
122
|
+
return metaData && Object.assign({}, mapData(metaData.attributes, 'attributes'), mapData(metaData.members, 'properties'), mapData(metaData.properties, 'properties'), mapData(metaData.events, 'events'), mapData(metaData.slots, 'slots'), mapData(metaData.cssProperties, 'css custom properties'), mapData(metaData.cssParts, 'css shadow parts'));
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
exports.extractArgTypesFromElements = extractArgTypesFromElements;
|
|
126
|
+
|
|
127
|
+
const extractArgTypes = tagName => {
|
|
128
|
+
const cem = (0, _.getCustomElements)();
|
|
155
129
|
return extractArgTypesFromElements(tagName, cem);
|
|
156
130
|
};
|
|
157
131
|
|
|
158
132
|
exports.extractArgTypes = extractArgTypes;
|
|
159
133
|
|
|
160
|
-
|
|
161
|
-
|
|
134
|
+
const extractComponentDescription = tagName => {
|
|
135
|
+
const metaData = getMetaData(tagName, (0, _.getCustomElements)());
|
|
162
136
|
return metaData && metaData.description;
|
|
163
137
|
};
|
|
164
138
|
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sourceDecorator = sourceDecorator;
|
|
7
|
+
|
|
8
|
+
var _litHtml = require("lit-html");
|
|
9
|
+
|
|
10
|
+
var _addons = require("@storybook/addons");
|
|
11
|
+
|
|
12
|
+
var _docsTools = require("@storybook/docs-tools");
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-underscore-dangle */
|
|
15
|
+
|
|
1
16
|
/* global window */
|
|
2
|
-
import { render } from 'lit-html';
|
|
3
|
-
import { addons, useEffect } from '@storybook/addons';
|
|
4
|
-
import { SNIPPET_RENDERED, SourceType } from '@storybook/docs-tools';
|
|
5
17
|
// Taken from https://github.com/lit/lit/blob/main/packages/lit-html/src/test/test-utils/strip-markers.ts
|
|
6
18
|
const LIT_EXPRESSION_COMMENTS = /<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;
|
|
7
19
|
|
|
@@ -11,37 +23,35 @@ function skipSourceRender(context) {
|
|
|
11
23
|
const sourceParams = context === null || context === void 0 ? void 0 : (_context$parameters$d = context.parameters.docs) === null || _context$parameters$d === void 0 ? void 0 : _context$parameters$d.source;
|
|
12
24
|
const isArgsStory = context === null || context === void 0 ? void 0 : context.parameters.__isArgsStory; // always render if the user forces it
|
|
13
25
|
|
|
14
|
-
if ((sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.DYNAMIC) {
|
|
26
|
+
if ((sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === _docsTools.SourceType.DYNAMIC) {
|
|
15
27
|
return false;
|
|
16
28
|
} // never render if the user is forcing the block to render code, or
|
|
17
29
|
// if the user provides code, or if it's not an args story.
|
|
18
30
|
|
|
19
31
|
|
|
20
|
-
return !isArgsStory || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.CODE;
|
|
32
|
+
return !isArgsStory || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === _docsTools.SourceType.CODE;
|
|
21
33
|
}
|
|
22
34
|
|
|
23
35
|
function applyTransformSource(source, context) {
|
|
24
|
-
var _context$parameters$d2;
|
|
25
|
-
|
|
26
36
|
const {
|
|
27
37
|
transformSource
|
|
28
|
-
} =
|
|
38
|
+
} = context.parameters.docs ?? {};
|
|
29
39
|
if (typeof transformSource !== 'function') return source;
|
|
30
40
|
return transformSource(source, context);
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
var _context$parameters$
|
|
43
|
+
function sourceDecorator(storyFn, context) {
|
|
44
|
+
var _context$parameters$d2, _context$parameters$d3;
|
|
35
45
|
|
|
36
|
-
const story = context !== null && context !== void 0 && (_context$parameters$
|
|
46
|
+
const story = context !== null && context !== void 0 && (_context$parameters$d2 = context.parameters.docs) !== null && _context$parameters$d2 !== void 0 && (_context$parameters$d3 = _context$parameters$d2.source) !== null && _context$parameters$d3 !== void 0 && _context$parameters$d3.excludeDecorators ? context.originalStoryFn(context.args, context) : storyFn();
|
|
37
47
|
let source;
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (source) addons.getChannel().emit(SNIPPET_RENDERED, context.id, source);
|
|
48
|
+
(0, _addons.useEffect)(() => {
|
|
49
|
+
if (source) _addons.addons.getChannel().emit(_docsTools.SNIPPET_RENDERED, context.id, source);
|
|
40
50
|
});
|
|
41
51
|
|
|
42
52
|
if (!skipSourceRender(context)) {
|
|
43
53
|
const container = window.document.createElement('div');
|
|
44
|
-
render(story, container);
|
|
54
|
+
(0, _litHtml.render)(story, container);
|
|
45
55
|
source = applyTransformSource(container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, ''), context);
|
|
46
56
|
}
|
|
47
57
|
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.object.to-string.js");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
-
|
|
7
|
-
require("core-js/modules/es.object.keys.js");
|
|
8
|
-
|
|
9
3
|
Object.defineProperty(exports, "__esModule", {
|
|
10
4
|
value: true
|
|
11
5
|
});
|
|
@@ -26,79 +20,79 @@ var _exportNames = {
|
|
|
26
20
|
};
|
|
27
21
|
Object.defineProperty(exports, "addDecorator", {
|
|
28
22
|
enumerable: true,
|
|
29
|
-
get: function
|
|
23
|
+
get: function () {
|
|
30
24
|
return _preview.addDecorator;
|
|
31
25
|
}
|
|
32
26
|
});
|
|
33
27
|
Object.defineProperty(exports, "addParameters", {
|
|
34
28
|
enumerable: true,
|
|
35
|
-
get: function
|
|
29
|
+
get: function () {
|
|
36
30
|
return _preview.addParameters;
|
|
37
31
|
}
|
|
38
32
|
});
|
|
39
33
|
Object.defineProperty(exports, "configure", {
|
|
40
34
|
enumerable: true,
|
|
41
|
-
get: function
|
|
35
|
+
get: function () {
|
|
42
36
|
return _preview.configure;
|
|
43
37
|
}
|
|
44
38
|
});
|
|
45
39
|
Object.defineProperty(exports, "forceReRender", {
|
|
46
40
|
enumerable: true,
|
|
47
|
-
get: function
|
|
41
|
+
get: function () {
|
|
48
42
|
return _preview.forceReRender;
|
|
49
43
|
}
|
|
50
44
|
});
|
|
51
45
|
Object.defineProperty(exports, "getCustomElements", {
|
|
52
46
|
enumerable: true,
|
|
53
|
-
get: function
|
|
47
|
+
get: function () {
|
|
54
48
|
return _customElements.getCustomElements;
|
|
55
49
|
}
|
|
56
50
|
});
|
|
57
51
|
Object.defineProperty(exports, "getStorybook", {
|
|
58
52
|
enumerable: true,
|
|
59
|
-
get: function
|
|
53
|
+
get: function () {
|
|
60
54
|
return _preview.getStorybook;
|
|
61
55
|
}
|
|
62
56
|
});
|
|
63
57
|
Object.defineProperty(exports, "isValidComponent", {
|
|
64
58
|
enumerable: true,
|
|
65
|
-
get: function
|
|
59
|
+
get: function () {
|
|
66
60
|
return _customElements.isValidComponent;
|
|
67
61
|
}
|
|
68
62
|
});
|
|
69
63
|
Object.defineProperty(exports, "isValidMetaData", {
|
|
70
64
|
enumerable: true,
|
|
71
|
-
get: function
|
|
65
|
+
get: function () {
|
|
72
66
|
return _customElements.isValidMetaData;
|
|
73
67
|
}
|
|
74
68
|
});
|
|
75
69
|
Object.defineProperty(exports, "raw", {
|
|
76
70
|
enumerable: true,
|
|
77
|
-
get: function
|
|
71
|
+
get: function () {
|
|
78
72
|
return _preview.raw;
|
|
79
73
|
}
|
|
80
74
|
});
|
|
81
75
|
Object.defineProperty(exports, "setAddon", {
|
|
82
76
|
enumerable: true,
|
|
83
|
-
get: function
|
|
77
|
+
get: function () {
|
|
84
78
|
return _preview.setAddon;
|
|
85
79
|
}
|
|
86
80
|
});
|
|
87
81
|
Object.defineProperty(exports, "setCustomElements", {
|
|
88
82
|
enumerable: true,
|
|
89
|
-
get: function
|
|
83
|
+
get: function () {
|
|
90
84
|
return _customElements.setCustomElements;
|
|
91
85
|
}
|
|
92
86
|
});
|
|
93
87
|
Object.defineProperty(exports, "setCustomElementsManifest", {
|
|
94
88
|
enumerable: true,
|
|
95
|
-
get: function
|
|
89
|
+
get: function () {
|
|
96
90
|
return _customElements.setCustomElementsManifest;
|
|
97
91
|
}
|
|
98
92
|
});
|
|
99
93
|
Object.defineProperty(exports, "storiesOf", {
|
|
100
94
|
enumerable: true,
|
|
101
|
-
get: function
|
|
95
|
+
get: function () {
|
|
102
96
|
return _preview.storiesOf;
|
|
103
97
|
}
|
|
104
98
|
});
|
|
@@ -117,7 +111,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
117
111
|
if (key in exports && exports[key] === _types[key]) return;
|
|
118
112
|
Object.defineProperty(exports, key, {
|
|
119
113
|
enumerable: true,
|
|
120
|
-
get: function
|
|
114
|
+
get: function () {
|
|
121
115
|
return _types[key];
|
|
122
116
|
}
|
|
123
117
|
});
|
|
@@ -125,19 +119,22 @@ Object.keys(_types).forEach(function (key) {
|
|
|
125
119
|
|
|
126
120
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
127
121
|
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
const {
|
|
123
|
+
window,
|
|
124
|
+
EventSource
|
|
125
|
+
} = _global.default;
|
|
130
126
|
|
|
131
127
|
// TODO: disable HMR and do full page loads because of customElements.define
|
|
132
128
|
if (module && module.hot && module.hot.decline) {
|
|
133
129
|
module.hot.decline(); // forcing full reloads for customElements as elements can only be defined once per page
|
|
134
130
|
|
|
135
|
-
|
|
131
|
+
const hmr = new EventSource('__webpack_hmr');
|
|
136
132
|
hmr.addEventListener('message', function fullPageReload(event) {
|
|
137
133
|
try {
|
|
138
134
|
// Only care for built events. Heartbeats are not parsable so we ignore those
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
const {
|
|
136
|
+
action
|
|
137
|
+
} = JSON.parse(event.data);
|
|
141
138
|
|
|
142
139
|
if (action === 'built') {
|
|
143
140
|
window.location.reload();
|
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.parameters = void 0;
|
|
7
6
|
Object.defineProperty(exports, "renderToDOM", {
|
|
8
7
|
enumerable: true,
|
|
9
|
-
get: function
|
|
8
|
+
get: function () {
|
|
10
9
|
return _render.renderToDOM;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
|
|
14
|
-
var _render = require("./render");
|
|
15
|
-
|
|
16
|
-
var parameters = {
|
|
17
|
-
framework: 'web-components'
|
|
18
|
-
};
|
|
19
|
-
exports.parameters = parameters;
|
|
13
|
+
var _render = require("./render");
|
|
@@ -4,5 +4,7 @@ var _global = _interopRequireDefault(require("global"));
|
|
|
4
4
|
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const {
|
|
8
|
+
window: globalWindow
|
|
9
|
+
} = _global.default;
|
|
8
10
|
globalWindow.STORYBOOK_ENV = 'web-components';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.storiesOf = exports.setAddon = exports.raw = exports.getStorybook = exports.forceReRender = exports.configure = exports.clearDecorators = exports.addParameters = exports.addDecorator = void 0;
|
|
7
|
+
|
|
8
|
+
var _coreClient = require("@storybook/core-client");
|
|
9
|
+
|
|
10
|
+
require("./globals");
|
|
11
|
+
|
|
12
|
+
var _render = require("./render");
|
|
13
|
+
|
|
14
|
+
/* eslint-disable prefer-destructuring */
|
|
15
|
+
const framework = 'web-components';
|
|
16
|
+
const api = (0, _coreClient.start)(_render.renderToDOM);
|
|
17
|
+
|
|
18
|
+
const storiesOf = (kind, m) => {
|
|
19
|
+
return api.clientApi.storiesOf(kind, m).addParameters({
|
|
20
|
+
framework
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.storiesOf = storiesOf;
|
|
25
|
+
|
|
26
|
+
const configure = (...args) => api.configure(framework, ...args);
|
|
27
|
+
|
|
28
|
+
exports.configure = configure;
|
|
29
|
+
const addDecorator = api.clientApi.addDecorator;
|
|
30
|
+
exports.addDecorator = addDecorator;
|
|
31
|
+
const addParameters = api.clientApi.addParameters;
|
|
32
|
+
exports.addParameters = addParameters;
|
|
33
|
+
const clearDecorators = api.clientApi.clearDecorators;
|
|
34
|
+
exports.clearDecorators = clearDecorators;
|
|
35
|
+
const setAddon = api.clientApi.setAddon;
|
|
36
|
+
exports.setAddon = setAddon;
|
|
37
|
+
const forceReRender = api.forceReRender;
|
|
38
|
+
exports.forceReRender = forceReRender;
|
|
39
|
+
const getStorybook = api.clientApi.getStorybook;
|
|
40
|
+
exports.getStorybook = getStorybook;
|
|
41
|
+
const raw = api.clientApi.raw;
|
|
42
|
+
exports.raw = raw;
|