@storybook-tiny/webcomponent 1.1.3 → 1.1.5
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/bin/storybook-tiny.js +6 -1
- package/package.json +11 -9
- package/src/Storybook.js +55 -32
- package/src/Storybook.module.css +9 -9
package/bin/storybook-tiny.js
CHANGED
|
@@ -5,7 +5,12 @@ import { fileURLToPath } from 'url'
|
|
|
5
5
|
|
|
6
6
|
const config = {
|
|
7
7
|
rootDir: fileURLToPath(new URL('..', import.meta.url)),
|
|
8
|
-
devDependencies: [
|
|
8
|
+
devDependencies: [
|
|
9
|
+
'@storybook-tiny/webcomponent',
|
|
10
|
+
'mi-element',
|
|
11
|
+
'vite',
|
|
12
|
+
'split.js@^1'
|
|
13
|
+
],
|
|
9
14
|
files: ['stories/*', 'vite.config.js'],
|
|
10
15
|
post: [
|
|
11
16
|
{
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook-tiny/webcomponent",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A tiny storybook for
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"description": "A tiny storybook for web-components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
7
7
|
"storybook-tiny",
|
|
8
|
-
"webcomponent"
|
|
8
|
+
"webcomponent",
|
|
9
|
+
"web-component"
|
|
9
10
|
],
|
|
10
11
|
"homepage": "https://github.com/commenthol/storybook-tiny/tree/main/packages/webcomponent#readme",
|
|
11
12
|
"bugs": {
|
|
@@ -33,14 +34,15 @@
|
|
|
33
34
|
"vite.config.js"
|
|
34
35
|
],
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"mi-element": "^0.
|
|
37
|
-
"
|
|
37
|
+
"mi-element": "^0.6.0",
|
|
38
|
+
"split.js": "^1.6.5",
|
|
39
|
+
"@storybook-tiny/setup": "1.0.2"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@eslint/js": "^9.
|
|
41
|
-
"eslint": "^9.
|
|
42
|
-
"globals": "^
|
|
43
|
-
"vite": "^
|
|
42
|
+
"@eslint/js": "^9.33.0",
|
|
43
|
+
"eslint": "^9.33.0",
|
|
44
|
+
"globals": "^16.3.0",
|
|
45
|
+
"vite": "^7.1.2"
|
|
44
46
|
},
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=20.0.0"
|
package/src/Storybook.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import styles from './Storybook.module.css'
|
|
2
|
-
import
|
|
2
|
+
import split from 'split.js'
|
|
3
|
+
import { MiElement, define, refsBySelector, esc as html, refsById } from 'mi-element'
|
|
3
4
|
|
|
4
5
|
const getLocationHash = () => decodeURIComponent(location.hash.substring(1))
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
target="_blanc"
|
|
22
|
-
rel="norel noreferrer"
|
|
23
|
-
>
|
|
24
|
-
webcomponents
|
|
25
|
-
</a>
|
|
26
|
-
</p>
|
|
7
|
+
const STORE_ITEM = 'tiny-storybook-x'
|
|
8
|
+
|
|
9
|
+
const getXperc = (px = 130) => (px * 100) / window.innerWidth
|
|
10
|
+
|
|
11
|
+
const defaultStory = html`
|
|
12
|
+
<p class="${styles.storybookSectionP}">
|
|
13
|
+
The tiny storybook for
|
|
14
|
+
<a
|
|
15
|
+
href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components"
|
|
16
|
+
target="_blanc"
|
|
17
|
+
rel="norel noreferrer"
|
|
18
|
+
>
|
|
19
|
+
Web Components
|
|
20
|
+
</a>
|
|
21
|
+
</p>
|
|
27
22
|
`
|
|
28
23
|
|
|
29
24
|
class Storybook extends MiElement {
|
|
@@ -41,17 +36,46 @@ class Storybook extends MiElement {
|
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
static template = `
|
|
39
|
+
<style>
|
|
40
|
+
.${styles.storybook} > .gutter {
|
|
41
|
+
background-color: #eee;
|
|
42
|
+
background-repeat: no-repeat;
|
|
43
|
+
background-position: 50%;
|
|
44
|
+
}
|
|
45
|
+
.${styles.storybook} > .gutter.gutter-horizontal {
|
|
46
|
+
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg==');
|
|
47
|
+
cursor: col-resize;
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
44
50
|
<main class="${styles.storybook}">
|
|
45
|
-
<aside>
|
|
51
|
+
<aside id="split-0">
|
|
46
52
|
<h4><a></a></h4>
|
|
47
53
|
<nav></nav>
|
|
48
54
|
</aside>
|
|
49
|
-
<section class="stories">
|
|
55
|
+
<section id="split-1" class="stories">
|
|
50
56
|
</section>
|
|
51
57
|
</main>
|
|
52
58
|
`
|
|
53
59
|
|
|
54
60
|
render() {
|
|
61
|
+
let xperc = getXperc()
|
|
62
|
+
try {
|
|
63
|
+
xperc = JSON.parse(localStorage.getItem(STORE_ITEM)) || xperc
|
|
64
|
+
if (isNaN(xperc)) {
|
|
65
|
+
xperc = getXperc()
|
|
66
|
+
}
|
|
67
|
+
} catch (_err) {
|
|
68
|
+
// noop
|
|
69
|
+
}
|
|
70
|
+
split(['#split-0', '#split-1'], {
|
|
71
|
+
sizes: [xperc, 100 - xperc],
|
|
72
|
+
minSize: 0,
|
|
73
|
+
gutterSize: 4,
|
|
74
|
+
onDragEnd: (sizes) => {
|
|
75
|
+
const [xperc] = sizes
|
|
76
|
+
localStorage.setItem(STORE_ITEM, xperc)
|
|
77
|
+
}
|
|
78
|
+
})
|
|
55
79
|
this.refs = refsBySelector(this.renderRoot, {
|
|
56
80
|
aside: 'main > aside',
|
|
57
81
|
h4: 'main > aside h4 a',
|
|
@@ -65,7 +89,6 @@ class Storybook extends MiElement {
|
|
|
65
89
|
const { refs } = this
|
|
66
90
|
refs.h4.textContent = this.header
|
|
67
91
|
refs.h4.href = this.href
|
|
68
|
-
refs.aside.style.flexBasis = cssUnit(this.width)
|
|
69
92
|
refs.nav.innerHTML = ''
|
|
70
93
|
for (const story of this.stories) {
|
|
71
94
|
const $el = document.createElement('storybook-tiny-story')
|
|
@@ -104,11 +127,11 @@ class Storybook extends MiElement {
|
|
|
104
127
|
// try rendering the story
|
|
105
128
|
refs.story.innerHTML = ''
|
|
106
129
|
try {
|
|
107
|
-
switch (
|
|
108
|
-
case '
|
|
130
|
+
switch (toString.call(renderStory).slice(8, -1)) {
|
|
131
|
+
case 'String':
|
|
109
132
|
refs.story.innerHTML = renderStory
|
|
110
133
|
break
|
|
111
|
-
case '
|
|
134
|
+
case 'Function':
|
|
112
135
|
refs.story.appendChild(renderStory())
|
|
113
136
|
break
|
|
114
137
|
default:
|
|
@@ -146,10 +169,10 @@ class Story extends MiElement {
|
|
|
146
169
|
|
|
147
170
|
const { title } = this.story
|
|
148
171
|
|
|
149
|
-
this.renderRoot.innerHTML =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
172
|
+
this.renderRoot.innerHTML = html`
|
|
173
|
+
<div>
|
|
174
|
+
<a href="#${title}">${title}</a>
|
|
175
|
+
</div>
|
|
153
176
|
`
|
|
154
177
|
this.refs = { a: this.querySelector('a') }
|
|
155
178
|
this.refs.a.className = this.active ? styles.active : ''
|
package/src/Storybook.module.css
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
.storybook {
|
|
2
2
|
font-family: Arial, Helvetica, sans-serif;
|
|
3
3
|
display: flex;
|
|
4
|
+
flex-direction: row;
|
|
4
5
|
}
|
|
5
6
|
|
|
6
|
-
.storybook>aside {
|
|
7
|
+
.storybook > aside {
|
|
7
8
|
border-right: 1px solid rgba(0, 0, 0, 0.1);
|
|
8
|
-
overflow-y:
|
|
9
|
+
overflow-y: hidden;
|
|
9
10
|
max-height: calc(100vh - 3em);
|
|
10
11
|
flex-grow: 0;
|
|
11
12
|
flex-shrink: 0;
|
|
12
|
-
flex-basis: 130px;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
.storybook>aside
|
|
15
|
+
.storybook > aside > * {
|
|
16
16
|
padding-left: 5px;
|
|
17
17
|
padding-right: 5px;
|
|
18
18
|
}
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
font-weight: bold;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
.storybook>aside>small {
|
|
29
|
+
.storybook > aside > small {
|
|
30
30
|
padding-top: 0.5em;
|
|
31
31
|
padding-bottom: 0.25em;
|
|
32
32
|
display: block;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
.storybook>aside>h4 {
|
|
35
|
+
.storybook > aside > h4 {
|
|
36
36
|
padding-top: 5px;
|
|
37
37
|
margin-top: 0;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
.storybook>aside>h4 a,
|
|
41
|
-
.storybook>aside>h4 a:visited {
|
|
40
|
+
.storybook > aside > h4 a,
|
|
41
|
+
.storybook > aside > h4 a:visited {
|
|
42
42
|
text-decoration: none;
|
|
43
43
|
color: unset;
|
|
44
44
|
}
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
.error {
|
|
61
61
|
padding: 0 1em 1em;
|
|
62
62
|
background-color: rgb(255, 0, 115, 0.1);
|
|
63
|
-
}
|
|
63
|
+
}
|