@storybook/addon-svelte-csf 1.0.1 → 1.1.1
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/.babelrc.js +12 -0
- package/CHANGELOG.md +28 -0
- package/dist/{components → cjs/components}/Meta.svelte +0 -0
- package/dist/{components → cjs/components}/RegisterContext.svelte +0 -0
- package/dist/{components → cjs/components}/RenderContext.svelte +0 -0
- package/dist/{components → cjs/components}/Story.svelte +0 -0
- package/dist/{components → cjs/components}/Template.svelte +0 -0
- package/dist/{components → cjs/components}/__tests__/TestStories.svelte +0 -0
- package/dist/{components → cjs/components}/context.js +0 -0
- package/dist/{constants.js → cjs/constants.js} +0 -0
- package/dist/{index.js → cjs/index.js} +10 -1
- package/dist/{jest-transform.js → cjs/jest-transform.js} +0 -0
- package/dist/{parser → cjs/parser}/collect-stories.js +0 -0
- package/dist/{parser → cjs/parser}/collect-stories.test.js +0 -0
- package/dist/{parser → cjs/parser}/extract-id.js +9 -8
- package/dist/{parser → cjs/parser}/extract-id.test.js +5 -0
- package/dist/{parser → cjs/parser}/extract-stories.js +0 -0
- package/dist/{parser → cjs/parser}/extract-stories.test.js +0 -0
- package/dist/{parser → cjs/parser}/svelte-stories-loader.js +0 -0
- package/dist/{preset → cjs/preset}/index.js +0 -0
- package/dist/{preset → cjs/preset}/manager.js +0 -0
- package/dist/esm/components/Meta.svelte +6 -0
- package/dist/esm/components/RegisterContext.svelte +11 -0
- package/dist/esm/components/RenderContext.svelte +13 -0
- package/dist/esm/components/Story.svelte +24 -0
- package/dist/esm/components/Template.svelte +15 -0
- package/dist/esm/components/__tests__/TestStories.svelte +21 -0
- package/dist/esm/components/context.js +39 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/jest-transform.js +19 -0
- package/dist/esm/parser/collect-stories.js +167 -0
- package/dist/esm/parser/collect-stories.test.js +21 -0
- package/dist/esm/parser/extract-id.js +31 -0
- package/dist/esm/parser/extract-id.test.js +18 -0
- package/dist/esm/parser/extract-stories.js +112 -0
- package/dist/esm/parser/extract-stories.test.js +27 -0
- package/dist/esm/parser/svelte-stories-loader.js +69 -0
- package/dist/esm/preset/index.js +35 -0
- package/dist/esm/preset/manager.js +4 -0
- package/index.d.ts +66 -0
- package/package.json +33 -22
- package/preset.js +1 -1
package/.babelrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# v1.1.1 (Fri Apr 08 2022)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- Fix generated id [#43](https://github.com/storybookjs/addon-svelte-csf/pull/43) ([@j3rem1e](https://github.com/j3rem1e))
|
|
6
|
+
- Update yarn.lock [#48](https://github.com/storybookjs/addon-svelte-csf/pull/48) ([@shilman](https://github.com/shilman))
|
|
7
|
+
- Add auto release workflow [#48](https://github.com/storybookjs/addon-svelte-csf/pull/48) ([@shilman](https://github.com/shilman))
|
|
8
|
+
|
|
9
|
+
#### Authors: 2
|
|
10
|
+
|
|
11
|
+
- Jérémie ([@j3rem1e](https://github.com/j3rem1e))
|
|
12
|
+
- Michael Shilman ([@shilman](https://github.com/shilman))
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# v1.1.0 (Thu Jun 10 2021)
|
|
17
|
+
|
|
18
|
+
#### 🚀 Enhancement
|
|
19
|
+
|
|
20
|
+
- Add ESM support [#30](https://github.com/storybookjs/addon-svelte-csf/pull/30) ([@TheComputerM](https://github.com/TheComputerM) [@shilman](https://github.com/shilman))
|
|
21
|
+
|
|
22
|
+
#### Authors: 2
|
|
23
|
+
|
|
24
|
+
- Michael Shilman ([@shilman](https://github.com/shilman))
|
|
25
|
+
- TheComputerM ([@TheComputerM](https://github.com/TheComputerM))
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
1
29
|
# v1.0.1 (Wed Jun 09 2021)
|
|
2
30
|
|
|
3
31
|
#### 🐛 Bug Fix
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "Template", {
|
|
|
21
21
|
return _Template["default"];
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
exports["default"] = void 0;
|
|
24
25
|
|
|
25
26
|
var _Meta = _interopRequireDefault(require("./components/Meta.svelte"));
|
|
26
27
|
|
|
@@ -28,4 +29,12 @@ var _Story = _interopRequireDefault(require("./components/Story.svelte"));
|
|
|
28
29
|
|
|
29
30
|
var _Template = _interopRequireDefault(require("./components/Template.svelte"));
|
|
30
31
|
|
|
31
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
33
|
+
|
|
34
|
+
if (module && module.hot && module.hot.decline) {
|
|
35
|
+
module.hot.decline();
|
|
36
|
+
} // make it work with --isolatedModules
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var _default = {};
|
|
40
|
+
exports["default"] = _default;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -7,7 +7,15 @@ exports.extractId = extractId;
|
|
|
7
7
|
|
|
8
8
|
var _clientLogger = require("@storybook/client-logger");
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
function hashCode(str) {
|
|
11
|
+
var h = str.split('') // eslint-disable-next-line no-bitwise
|
|
12
|
+
.reduce(function (prevHash, currVal) {
|
|
13
|
+
return (prevHash << 5) - prevHash + currVal.charCodeAt(0) | 0;
|
|
14
|
+
}, 0);
|
|
15
|
+
return Math.abs(h).toString(16);
|
|
16
|
+
} // extract a story id
|
|
17
|
+
|
|
18
|
+
|
|
11
19
|
function extractId(_ref) {
|
|
12
20
|
var id = _ref.id,
|
|
13
21
|
name = _ref.name;
|
|
@@ -28,11 +36,4 @@ function extractId(_ref) {
|
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
return generated;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function hashCode(str) {
|
|
34
|
-
return str.split('').reduce(function (prevHash, currVal) {
|
|
35
|
-
return (prevHash << 5) - prevHash + currVal.charCodeAt(0) | 0;
|
|
36
|
-
}, 0) // eslint-disable-line
|
|
37
|
-
.toString(16);
|
|
38
39
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { useContext } from './context';
|
|
3
|
+
|
|
4
|
+
const context = useContext();
|
|
5
|
+
|
|
6
|
+
export let name;
|
|
7
|
+
export let template = null;
|
|
8
|
+
|
|
9
|
+
if (!name) {
|
|
10
|
+
throw new Error('Missing Story name');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
context.register({
|
|
14
|
+
name,
|
|
15
|
+
...$$restProps,
|
|
16
|
+
template: template != null ? template : !$$slots.default ? 'default' : null,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
$: render = context.render && !context.templateName && context.storyName == name;
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
{#if render}
|
|
23
|
+
<slot args={context.args} {...context.args}/>
|
|
24
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { useContext } from './context';
|
|
3
|
+
|
|
4
|
+
const context = useContext();
|
|
5
|
+
|
|
6
|
+
export let id = 'default';
|
|
7
|
+
|
|
8
|
+
context.register({id, isTemplate: true});
|
|
9
|
+
|
|
10
|
+
$: render = context.render && context.templateId === id;
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
{#if render}
|
|
14
|
+
<slot args={context.args} {...context.args}/>
|
|
15
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Meta from '../Meta.svelte';
|
|
3
|
+
import Story from '../Story.svelte';
|
|
4
|
+
import Template from '../Template.svelte';
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<Meta title="Test"/>
|
|
8
|
+
|
|
9
|
+
<Template id="tpl1">
|
|
10
|
+
<div>tpl1</div>
|
|
11
|
+
</Template>
|
|
12
|
+
|
|
13
|
+
<Template id="tpl2">
|
|
14
|
+
<div>tpl2</div>
|
|
15
|
+
</Template>
|
|
16
|
+
|
|
17
|
+
<Story name="Story1" template="tpl1" args={{tpl1:true}}/>
|
|
18
|
+
<Story name="Story2" template="tpl2" source args={{tpl1:true}}/>
|
|
19
|
+
<Story name="Story3" source="xyz">
|
|
20
|
+
<div>story3</div>
|
|
21
|
+
</Story>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import { getContext, hasContext, setContext } from "svelte";
|
|
8
|
+
var CONTEXT_KEY = "storybook-registration-context";
|
|
9
|
+
export function createRenderContext() {
|
|
10
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
|
+
setContext(CONTEXT_KEY, _objectSpread({
|
|
12
|
+
render: true,
|
|
13
|
+
register: function register() {},
|
|
14
|
+
meta: {},
|
|
15
|
+
args: {}
|
|
16
|
+
}, props));
|
|
17
|
+
}
|
|
18
|
+
export function createRegistrationContext(repositories) {
|
|
19
|
+
setContext(CONTEXT_KEY, {
|
|
20
|
+
render: false,
|
|
21
|
+
register: function register(story) {
|
|
22
|
+
repositories.stories.push(story);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
set meta(value) {
|
|
26
|
+
// eslint-disable-next-line no-param-reassign
|
|
27
|
+
repositories.meta = value;
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
args: {}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function useContext() {
|
|
34
|
+
if (!hasContext(CONTEXT_KEY)) {
|
|
35
|
+
createRenderContext();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return getContext(CONTEXT_KEY);
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var ADDON_ID = 'storybook/svelte-csf';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Meta } from './components/Meta.svelte';
|
|
2
|
+
export { default as Story } from './components/Story.svelte';
|
|
3
|
+
export { default as Template } from './components/Template.svelte';
|
|
4
|
+
|
|
5
|
+
if (module && module.hot && module.hot.decline) {
|
|
6
|
+
module.hot.decline();
|
|
7
|
+
} // make it work with --isolatedModules
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var svelte = require('svelte/compiler');
|
|
2
|
+
|
|
3
|
+
var parser = require.resolve('./parser/collect-stories').replace(/[/\\]/g, '/');
|
|
4
|
+
|
|
5
|
+
function process(src, filename) {
|
|
6
|
+
var result = svelte.compile(src, {
|
|
7
|
+
format: 'cjs',
|
|
8
|
+
filename: filename,
|
|
9
|
+
dev: true
|
|
10
|
+
});
|
|
11
|
+
var code = result.js ? result.js.code : result.code;
|
|
12
|
+
var z = {
|
|
13
|
+
code: "".concat(code, "\n const { default: parser } = require('").concat(parser, "');\n const md = parser(module.exports.default, {});\n module.exports = { default: md.meta, ...md.stories };\n Object.defineProperty(exports, \"__esModule\", { value: true });"),
|
|
14
|
+
map: result.js ? result.js.map : result.map
|
|
15
|
+
};
|
|
16
|
+
return z;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.process = process;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
+
|
|
15
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
|
+
|
|
17
|
+
/* eslint-env browser */
|
|
18
|
+
import { logger } from '@storybook/client-logger';
|
|
19
|
+
import { combineParameters } from '@storybook/client-api';
|
|
20
|
+
import { extractId } from './extract-id';
|
|
21
|
+
import RegisterContext from '../components/RegisterContext.svelte';
|
|
22
|
+
import RenderContext from '../components/RenderContext.svelte';
|
|
23
|
+
/* Called from a webpack loader and a jest transformation.
|
|
24
|
+
*
|
|
25
|
+
* It mounts a Stories component in a context which disables
|
|
26
|
+
* the rendering of every <Story/> and <Template/> but instead
|
|
27
|
+
* collects names and properties.
|
|
28
|
+
*
|
|
29
|
+
* For every discovered <Story/>, it creates a storyFn which
|
|
30
|
+
* instantiate the main Stories component: Every Story but
|
|
31
|
+
* the one selected is disabled.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
var createFragment = document.createDocumentFragment ? function () {
|
|
35
|
+
return document.createDocumentFragment();
|
|
36
|
+
} : function () {
|
|
37
|
+
return document.createElement('div');
|
|
38
|
+
};
|
|
39
|
+
export default (function (StoriesComponent, _ref) {
|
|
40
|
+
var _ref$stories = _ref.stories,
|
|
41
|
+
stories = _ref$stories === void 0 ? {} : _ref$stories,
|
|
42
|
+
allocatedIds = _ref.allocatedIds;
|
|
43
|
+
var repositories = {
|
|
44
|
+
meta: null,
|
|
45
|
+
stories: []
|
|
46
|
+
}; // extract all stories
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
var context = new RegisterContext({
|
|
50
|
+
target: createFragment(),
|
|
51
|
+
props: {
|
|
52
|
+
Stories: StoriesComponent,
|
|
53
|
+
repositories: repositories
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
context.$destroy();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
logger.error("Error extracting stories ".concat(e.toString()), e);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var meta = repositories.meta;
|
|
62
|
+
|
|
63
|
+
if (!meta) {
|
|
64
|
+
logger.error('Missing <Meta/> tag');
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var globalComponent = meta.component; // collect templates id
|
|
69
|
+
|
|
70
|
+
var templatesId = repositories.stories.filter(function (story) {
|
|
71
|
+
return story.isTemplate;
|
|
72
|
+
}).map(function (story) {
|
|
73
|
+
return story.id;
|
|
74
|
+
}); // check for duplicate templates
|
|
75
|
+
|
|
76
|
+
var duplicateTemplatesId = templatesId.filter(function (item, index) {
|
|
77
|
+
return templatesId.indexOf(item) !== index;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (duplicateTemplatesId.length > 0) {
|
|
81
|
+
logger.warn("Found duplicates templates id for stories '".concat(meta.name, "': ").concat(duplicateTemplatesId));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
meta: meta,
|
|
86
|
+
stories: repositories.stories.filter(function (story) {
|
|
87
|
+
return !story.isTemplate;
|
|
88
|
+
}).reduce(function (all, story) {
|
|
89
|
+
var id = story.id,
|
|
90
|
+
name = story.name,
|
|
91
|
+
template = story.template,
|
|
92
|
+
component = story.component,
|
|
93
|
+
_story$source = story.source,
|
|
94
|
+
source = _story$source === void 0 ? false : _story$source,
|
|
95
|
+
props = _objectWithoutProperties(story, ["id", "name", "template", "component", "source"]);
|
|
96
|
+
|
|
97
|
+
var storyId = extractId(story, allocatedIds);
|
|
98
|
+
|
|
99
|
+
if (!storyId) {
|
|
100
|
+
return all;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var unknownTemplate = template != null && templatesId.indexOf(template) < 0;
|
|
104
|
+
|
|
105
|
+
var storyFn = function storyFn(args) {
|
|
106
|
+
if (unknownTemplate) {
|
|
107
|
+
throw new Error("Story ".concat(name, " is referencing an unknown template ").concat(template));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
Component: RenderContext,
|
|
112
|
+
props: {
|
|
113
|
+
Stories: StoriesComponent,
|
|
114
|
+
storyName: name,
|
|
115
|
+
templateId: template,
|
|
116
|
+
args: args,
|
|
117
|
+
sourceComponent: component || globalComponent
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
storyFn.storyName = name;
|
|
123
|
+
Object.entries(props).forEach(function (_ref2) {
|
|
124
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
125
|
+
k = _ref3[0],
|
|
126
|
+
v = _ref3[1];
|
|
127
|
+
|
|
128
|
+
storyFn[k] = v;
|
|
129
|
+
}); // inject story sources
|
|
130
|
+
|
|
131
|
+
var storyDef = stories[template ? "tpl:".concat(template) : storyId];
|
|
132
|
+
var hasArgs = storyDef ? storyDef.hasArgs : true; // inject source snippet
|
|
133
|
+
|
|
134
|
+
var rawSource = storyDef ? storyDef.source : null;
|
|
135
|
+
|
|
136
|
+
if (rawSource) {
|
|
137
|
+
storyFn.parameters = combineParameters(storyFn.parameters || {}, {
|
|
138
|
+
storySource: {
|
|
139
|
+
source: rawSource
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
var snippet;
|
|
145
|
+
|
|
146
|
+
if (source === true || source === false && !hasArgs) {
|
|
147
|
+
snippet = rawSource;
|
|
148
|
+
} else if (typeof source === 'string') {
|
|
149
|
+
snippet = source;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (snippet) {
|
|
153
|
+
storyFn.parameters = combineParameters(storyFn.parameters || {}, {
|
|
154
|
+
docs: {
|
|
155
|
+
source: {
|
|
156
|
+
code: snippet
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
} // eslint-disable-next-line no-param-reassign
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
all[storyId] = storyFn;
|
|
164
|
+
return all;
|
|
165
|
+
}, {})
|
|
166
|
+
};
|
|
167
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import collectStories from './collect-stories';
|
|
2
|
+
import TestStories from '../components/__tests__/TestStories.svelte';
|
|
3
|
+
describe('parse-stories', function () {
|
|
4
|
+
test('Extract Stories', function () {
|
|
5
|
+
var data = collectStories(TestStories, {
|
|
6
|
+
stories: {
|
|
7
|
+
'tpl:tpl2': 'tpl2src'
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
var stories = data.stories,
|
|
11
|
+
meta = data.meta;
|
|
12
|
+
expect(meta).toMatchInlineSnapshot("\n Object {\n \"title\": \"Test\",\n }\n ");
|
|
13
|
+
expect(stories).toMatchInlineSnapshot("\n Object {\n \"Story1\": [Function],\n \"Story2\": [Function],\n \"Story3\": [Function],\n }\n ");
|
|
14
|
+
expect(stories.Story1.storyName).toBe('Story1');
|
|
15
|
+
expect(stories.Story1.parameters).toMatchInlineSnapshot("undefined");
|
|
16
|
+
expect(stories.Story2.storyName).toBe('Story2');
|
|
17
|
+
expect(stories.Story2.parameters).toMatchInlineSnapshot("undefined");
|
|
18
|
+
expect(stories.Story3.storyName).toBe('Story3');
|
|
19
|
+
expect(stories.Story3.parameters).toMatchInlineSnapshot("\n Object {\n \"docs\": Object {\n \"source\": Object {\n \"code\": \"xyz\",\n },\n },\n }\n ");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { logger } from '@storybook/client-logger';
|
|
2
|
+
|
|
3
|
+
function hashCode(str) {
|
|
4
|
+
var h = str.split('') // eslint-disable-next-line no-bitwise
|
|
5
|
+
.reduce(function (prevHash, currVal) {
|
|
6
|
+
return (prevHash << 5) - prevHash + currVal.charCodeAt(0) | 0;
|
|
7
|
+
}, 0);
|
|
8
|
+
return Math.abs(h).toString(16);
|
|
9
|
+
} // extract a story id
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function extractId(_ref) {
|
|
13
|
+
var id = _ref.id,
|
|
14
|
+
name = _ref.name;
|
|
15
|
+
var allocatedIds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
16
|
+
|
|
17
|
+
if (id) {
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var generated = name.replace(/\W+(.)/g, function (_, chr) {
|
|
22
|
+
return chr.toUpperCase();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (allocatedIds.indexOf(generated) >= 0) {
|
|
26
|
+
logger.warn("Story name conflict with exports - Please add an explicit id for story ".concat(name));
|
|
27
|
+
generated += hashCode(name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return generated;
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { extractId } from './extract-id';
|
|
2
|
+
describe('extract-id', function () {
|
|
3
|
+
test('name with spaces', function () {
|
|
4
|
+
expect(extractId({
|
|
5
|
+
name: 'Name with spaces'
|
|
6
|
+
})).toBe('NameWithSpaces');
|
|
7
|
+
});
|
|
8
|
+
test('duplicates id', function () {
|
|
9
|
+
expect(extractId({
|
|
10
|
+
name: 'Button'
|
|
11
|
+
}, ['Button'])).toBe('Button77471352');
|
|
12
|
+
});
|
|
13
|
+
test('No negative hash', function () {
|
|
14
|
+
expect(extractId({
|
|
15
|
+
name: 'Navbar'
|
|
16
|
+
}, ['Navbar'])).toBe('Navbar7557f7d0');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import dedent from 'ts-dedent';
|
|
2
|
+
import * as svelte from 'svelte/compiler';
|
|
3
|
+
import { extractId } from './extract-id';
|
|
4
|
+
|
|
5
|
+
function getStaticAttribute(name, node) {
|
|
6
|
+
// extract the attribute
|
|
7
|
+
var attribute = node.attributes.find(function (att) {
|
|
8
|
+
return att.type === 'Attribute' && att.name === name;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
if (!attribute) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var value = attribute.value; // expect the attribute to be static, ie only one Text node
|
|
16
|
+
|
|
17
|
+
if (value && value.length === 1 && value[0].type === 'Text') {
|
|
18
|
+
return value[0].data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
throw new Error("Attribute ".concat(name, " is not static"));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse a Svelte component and extract stories.
|
|
25
|
+
* @param component Component Source
|
|
26
|
+
* @returns Map of storyName -> source
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export function extractStories(component) {
|
|
31
|
+
// compile
|
|
32
|
+
var _svelte$compile = svelte.compile(component),
|
|
33
|
+
ast = _svelte$compile.ast;
|
|
34
|
+
|
|
35
|
+
var allocatedIds = ['default'];
|
|
36
|
+
var localNames = {
|
|
37
|
+
Story: 'Story',
|
|
38
|
+
Template: 'Template'
|
|
39
|
+
};
|
|
40
|
+
svelte.walk(ast.instance, {
|
|
41
|
+
enter: function enter(node) {
|
|
42
|
+
if (node.type === 'ImportDeclaration') {
|
|
43
|
+
if (node.source.value === '@storybook/addon-svelte-csf') {
|
|
44
|
+
node.specifiers.filter(function (n) {
|
|
45
|
+
return n.type === 'ImportSpecifier';
|
|
46
|
+
}).forEach(function (n) {
|
|
47
|
+
localNames[n.imported.name] = n.local.name;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.skip();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}); // extracts allocated Ids
|
|
55
|
+
|
|
56
|
+
svelte.walk(ast.instance, {
|
|
57
|
+
enter: function enter(node) {
|
|
58
|
+
if (node.type === 'ImportDeclaration') {
|
|
59
|
+
node.specifiers.map(function (n) {
|
|
60
|
+
return n.local.name;
|
|
61
|
+
}).forEach(function (name) {
|
|
62
|
+
return allocatedIds.push(name);
|
|
63
|
+
});
|
|
64
|
+
this.skip();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
var stories = {};
|
|
69
|
+
svelte.walk(ast.html, {
|
|
70
|
+
enter: function enter(node) {
|
|
71
|
+
if (node.type === 'InlineComponent' && (node.name === localNames.Story || node.name === localNames.Template)) {
|
|
72
|
+
this.skip();
|
|
73
|
+
var isTemplate = node.name === 'Template'; // extract the 'name' attribute
|
|
74
|
+
|
|
75
|
+
var name = getStaticAttribute('name', node); // templates has a default name
|
|
76
|
+
|
|
77
|
+
if (!name && isTemplate) {
|
|
78
|
+
name = 'default';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var id = extractId({
|
|
82
|
+
id: getStaticAttribute('id', node),
|
|
83
|
+
name: name
|
|
84
|
+
}, isTemplate ? undefined : allocatedIds);
|
|
85
|
+
|
|
86
|
+
if (name && id) {
|
|
87
|
+
// ignore stories without children
|
|
88
|
+
var source;
|
|
89
|
+
|
|
90
|
+
if (node.children.length > 0) {
|
|
91
|
+
var start = node.children[0].start;
|
|
92
|
+
var end = node.children[node.children.length - 1].end;
|
|
93
|
+
source = dedent(component.substr(start, end - start));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
stories[isTemplate ? "tpl:".concat(id) : id] = {
|
|
97
|
+
name: name,
|
|
98
|
+
template: isTemplate,
|
|
99
|
+
source: source,
|
|
100
|
+
hasArgs: node.attributes.find(function (att) {
|
|
101
|
+
return att.type === 'Let';
|
|
102
|
+
}) != null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
stories: stories,
|
|
110
|
+
allocatedIds: allocatedIds
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { extractStories } from './extract-stories';
|
|
2
|
+
describe('extractSource', function () {
|
|
3
|
+
test('Simple Story', function () {
|
|
4
|
+
expect(extractStories("\n <script>\n import { Story } from '@storybook/svelte';\n </script>\n\n <Story name=\"MyStory\">\n <div>a story</div>\n </Story>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Story\",\n ],\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
5
|
+
});
|
|
6
|
+
test('Explicit Id Story', function () {
|
|
7
|
+
expect(extractStories("\n <script>\n import { Story } from '@storybook/svelte';\n </script>\n\n <Story id=\"myId\" name=\"MyStory\">\n <div>a story</div>\n </Story>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Story\",\n ],\n \"stories\": Object {\n \"myId\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
8
|
+
});
|
|
9
|
+
test('Args Story', function () {
|
|
10
|
+
expect(extractStories("\n <script>\n import { Story } from '@storybook/svelte';\n </script>\n\n <Story name=\"MyStory\" let:args>\n <div>a story</div>\n </Story>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Story\",\n ],\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": true,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
11
|
+
});
|
|
12
|
+
test('Simple Template', function () {
|
|
13
|
+
expect(extractStories("\n <script>\n import { Template } from '@storybook/svelte';\n </script>\n\n <Template name=\"MyTemplate\">\n <div>a template</div>\n </Template>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Template\",\n ],\n \"stories\": Object {\n \"tpl:MyTemplate\": Object {\n \"hasArgs\": false,\n \"name\": \"MyTemplate\",\n \"source\": \"<div>a template</div>\",\n \"template\": true,\n },\n },\n }\n ");
|
|
14
|
+
});
|
|
15
|
+
test('Unnamed Template', function () {
|
|
16
|
+
expect(extractStories("\n <script>\n import { Template } from '@storybook/svelte';\n </script>\n\n <Template>\n <div>a template</div>\n </Template>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Template\",\n ],\n \"stories\": Object {\n \"tpl:default\": Object {\n \"hasArgs\": false,\n \"name\": \"default\",\n \"source\": \"<div>a template</div>\",\n \"template\": true,\n },\n },\n }\n ");
|
|
17
|
+
});
|
|
18
|
+
test('Multiple Stories', function () {
|
|
19
|
+
expect(extractStories("\n <script>\n import { Template } from '@storybook/svelte';\n </script>\n\n <Story name=\"Story1\">\n <div>story 1</div>\n </Story>\n <Story name=\"Story2\">\n <div>story 2</div>\n </Story>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Template\",\n ],\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"template\": false,\n },\n \"Story2\": Object {\n \"hasArgs\": false,\n \"name\": \"Story2\",\n \"source\": \"<div>story 2</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
20
|
+
});
|
|
21
|
+
test('Renamed Import', function () {
|
|
22
|
+
expect(extractStories("\n <script>\n import { Story as SBStory, Meta as SBMeta } from '@storybook/addon-svelte-csf';\n </script>\n\n <SBMeta title='test'/>\n\n <SBStory name=\"Story1\">\n <div>story 1</div>\n </SBStory>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"SBStory\",\n \"SBMeta\",\n ],\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
23
|
+
});
|
|
24
|
+
test('Duplicate Id', function () {
|
|
25
|
+
expect(extractStories("\n <script>\n import { Story } from '@storybook/svelte';\n import Button from './Button.svelte';\n </script>\n\n <Story name=\"Button\">\n <div>a story</div>\n </Story>\n ")).toMatchInlineSnapshot("\n Object {\n \"allocatedIds\": Array [\n \"default\",\n \"Story\",\n \"Button\",\n ],\n \"stories\": Object {\n \"Button77471352\": Object {\n \"hasArgs\": false,\n \"name\": \"Button\",\n \"source\": \"<div>a story</div>\",\n \"template\": false,\n },\n },\n }\n ");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var _templateObject;
|
|
2
|
+
|
|
3
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
4
|
+
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
|
|
7
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
|
+
|
|
13
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
14
|
+
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
|
|
17
|
+
import dedent from 'ts-dedent';
|
|
18
|
+
import { readFileSync } from 'fs';
|
|
19
|
+
import { extractStories } from './extract-stories';
|
|
20
|
+
|
|
21
|
+
var parser = require.resolve('./collect-stories').replace(/[/\\]/g, '/'); // From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts
|
|
22
|
+
// Copied because it is not exported from the compiler
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export function getNameFromFilename(filename) {
|
|
26
|
+
if (!filename) return null;
|
|
27
|
+
var parts = filename.split(/[/\\]/).map(encodeURI);
|
|
28
|
+
|
|
29
|
+
if (parts.length > 1) {
|
|
30
|
+
var index_match = parts[parts.length - 1].match(/^index(\.\w+)/);
|
|
31
|
+
|
|
32
|
+
if (index_match) {
|
|
33
|
+
parts.pop();
|
|
34
|
+
parts[parts.length - 1] += index_match[1];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var base = parts.pop().replace(/%/g, 'u').replace(/\.[^.]+$/, '').replace(/[^a-zA-Z_$0-9]+/g, '_').replace(/^_/, '').replace(/_$/, '').replace(/^(\d)/, '_$1');
|
|
39
|
+
|
|
40
|
+
if (!base) {
|
|
41
|
+
throw new Error("Could not derive component name from file ".concat(filename));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return base[0].toUpperCase() + base.slice(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function transformSvelteStories(code) {
|
|
48
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
49
|
+
var resource = this._module.resource;
|
|
50
|
+
var componentName = getNameFromFilename(resource);
|
|
51
|
+
var source = readFileSync(resource).toString();
|
|
52
|
+
var storiesDef = extractStories(source);
|
|
53
|
+
var stories = storiesDef.stories;
|
|
54
|
+
var storyDef = Object.entries(stories).filter(function (_ref) {
|
|
55
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
56
|
+
def = _ref2[1];
|
|
57
|
+
|
|
58
|
+
return !def.template;
|
|
59
|
+
}).map(function (_ref3) {
|
|
60
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
61
|
+
id = _ref4[0];
|
|
62
|
+
|
|
63
|
+
return "export const ".concat(id, " = __storiesMetaData.stories[").concat(JSON.stringify(id), "]");
|
|
64
|
+
}).join('\n');
|
|
65
|
+
var codeWithoutDefaultExport = code.replace('export default ', '//export default');
|
|
66
|
+
return dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["", "\n const { default: parser } = require('", "');\n const __storiesMetaData = parser(", ", ", ");\n export default __storiesMetaData.meta;\n ", ";\n "])), codeWithoutDefaultExport, parser, componentName, JSON.stringify(storiesDef), storyDef);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default transformSvelteStories;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
14
|
+
|
|
15
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
16
|
+
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
+
|
|
19
|
+
export function managerEntries() {
|
|
20
|
+
var entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
21
|
+
return [].concat(_toConsumableArray(entry), [require.resolve('./manager')]);
|
|
22
|
+
}
|
|
23
|
+
export function webpack(config) {
|
|
24
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
25
|
+
module: _objectSpread(_objectSpread({}, config.module), {}, {
|
|
26
|
+
rules: [].concat(_toConsumableArray(config.module.rules), [{
|
|
27
|
+
test: /\.stories\.svelte$/,
|
|
28
|
+
enforce: 'post',
|
|
29
|
+
use: [{
|
|
30
|
+
loader: require.resolve('../parser/svelte-stories-loader')
|
|
31
|
+
}]
|
|
32
|
+
}])
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SvelteComponentTyped, SvelteComponent } from 'svelte';
|
|
2
|
+
import type { BaseMeta, BaseAnnotations } from '@storybook/addons';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
type DecoratorReturnType = void|SvelteComponent|{
|
|
6
|
+
Component: any,
|
|
7
|
+
props?: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface StoryProps extends BaseAnnotations<any, DecoratorReturnType> {
|
|
11
|
+
/**
|
|
12
|
+
* Id of the story.
|
|
13
|
+
*
|
|
14
|
+
* Optional, auto-generated from name if not specified.
|
|
15
|
+
*/
|
|
16
|
+
id?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Name of the story.
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Id of the template used by this story.
|
|
23
|
+
*
|
|
24
|
+
* Optional. Used if the story has no body.
|
|
25
|
+
* If not specified, use the 'default' template.
|
|
26
|
+
*/
|
|
27
|
+
template?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Specify which sources should be shown.
|
|
30
|
+
*
|
|
31
|
+
* By default, sources for an args story are auto-generated.
|
|
32
|
+
* If source is true, then the source of the story will be used instead.
|
|
33
|
+
* If source is a string, it replaces the source of the story.
|
|
34
|
+
*/
|
|
35
|
+
source?: boolean|string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface TemplateProps extends BaseAnnotations<any, DecoratorReturnType> {
|
|
39
|
+
/**
|
|
40
|
+
* Id of the template.
|
|
41
|
+
*
|
|
42
|
+
* Optional. Use 'default' if not specified.
|
|
43
|
+
*/
|
|
44
|
+
id?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Slots {
|
|
48
|
+
default: {
|
|
49
|
+
args: any;
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Meta.
|
|
55
|
+
*/
|
|
56
|
+
export class Meta extends SvelteComponentTyped<BaseMeta<any> & BaseAnnotations<any, DecoratorReturnType>> {}
|
|
57
|
+
/**
|
|
58
|
+
* Story.
|
|
59
|
+
*/
|
|
60
|
+
export class Story extends SvelteComponentTyped<StoryProps, {}, Slots> {}
|
|
61
|
+
/**
|
|
62
|
+
* Template.
|
|
63
|
+
*
|
|
64
|
+
* Allow to reuse definition between stories.
|
|
65
|
+
*/
|
|
66
|
+
export class Template extends SvelteComponentTyped<TemplateProps, {}, Slots> {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-svelte-csf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Allows to write stories in Svelte syntax",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook-addons",
|
|
@@ -11,43 +11,48 @@
|
|
|
11
11
|
"url": "https://github.com/storybookjs/addon-svelte-csf"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"main": "dist/
|
|
15
|
-
"
|
|
14
|
+
"main": "dist/cjs/index.js",
|
|
15
|
+
"module": "dist/esm/index.js",
|
|
16
|
+
"browser": "dist/cjs/index.js",
|
|
16
17
|
"files": [
|
|
17
18
|
"dist/**/*",
|
|
18
19
|
"README.md",
|
|
19
|
-
"*.js"
|
|
20
|
+
"*.js",
|
|
21
|
+
"*.d.ts"
|
|
20
22
|
],
|
|
21
23
|
"scripts": {
|
|
22
24
|
"clean": "rimraf ./dist",
|
|
23
|
-
"build": "
|
|
24
|
-
"
|
|
25
|
+
"build": "concurrently \"yarn build:cjs\" \"yarn build:esm\"",
|
|
26
|
+
"build:cjs": "babel ./src -d ./dist/cjs --extensions \".js,.ts\" --copy-files",
|
|
27
|
+
"build:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.ts\" --copy-files",
|
|
28
|
+
"prepublish": "yarn clean && yarn build",
|
|
25
29
|
"test": "jest",
|
|
26
30
|
"lint": "eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives",
|
|
27
31
|
"storybook": "start-storybook -p 6006",
|
|
28
|
-
"start": "concurrently \"
|
|
32
|
+
"start": "concurrently \"yarn storybook -- --no-manager-cache --quiet\" \"yarn build -- --watch\"",
|
|
29
33
|
"build-storybook": "build-storybook",
|
|
30
|
-
"release": "
|
|
34
|
+
"release": "yarn build && auto shipit"
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"ts-dedent": "^2.0.0"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
40
|
+
"@auto-it/released": "^10.32.6",
|
|
36
41
|
"@babel/cli": "^7.12.1",
|
|
37
42
|
"@babel/core": "^7.12.3",
|
|
38
43
|
"@babel/preset-env": "^7.12.1",
|
|
39
44
|
"@babel/preset-react": "^7.12.5",
|
|
40
45
|
"@babel/preset-typescript": "^7.12.5",
|
|
41
|
-
"@storybook/addon-essentials": "^6.2.
|
|
42
|
-
"@storybook/addon-knobs": "^6.2.
|
|
43
|
-
"@storybook/addon-storyshots": "^6.2.
|
|
44
|
-
"@storybook/eslint-config-storybook": "^
|
|
45
|
-
"@storybook/svelte": "^6.2.
|
|
46
|
+
"@storybook/addon-essentials": "^6.2.9",
|
|
47
|
+
"@storybook/addon-knobs": "^6.2.9",
|
|
48
|
+
"@storybook/addon-storyshots": "^6.2.9",
|
|
49
|
+
"@storybook/eslint-config-storybook": "^3.0.0",
|
|
50
|
+
"@storybook/svelte": "^6.2.9",
|
|
46
51
|
"auto": "^10.3.0",
|
|
47
52
|
"babel-jest": "^26.6.3",
|
|
48
53
|
"babel-loader": "^8.1.0",
|
|
49
54
|
"chromatic": "^5.6.1",
|
|
50
|
-
"concurrently": "^
|
|
55
|
+
"concurrently": "^6.2.0",
|
|
51
56
|
"eslint": "^7.17.0",
|
|
52
57
|
"jest": "^26.6.3",
|
|
53
58
|
"jest-environment-jsdom-thirteen": "^1.0.1",
|
|
@@ -61,14 +66,14 @@
|
|
|
61
66
|
"typescript": "^3.3.3333"
|
|
62
67
|
},
|
|
63
68
|
"peerDependencies": {
|
|
64
|
-
"@storybook/addons": "^6.2.
|
|
65
|
-
"@storybook/api": "^6.2.
|
|
66
|
-
"@storybook/client-api": "^6.2.
|
|
67
|
-
"@storybook/client-logger": "^6.2.
|
|
68
|
-
"@storybook/components": "^6.2.
|
|
69
|
-
"@storybook/core-events": "^6.2.
|
|
70
|
-
"@storybook/svelte": "^6.2.
|
|
71
|
-
"@storybook/theming": "^6.2.
|
|
69
|
+
"@storybook/addons": "^6.2.9",
|
|
70
|
+
"@storybook/api": "^6.2.9",
|
|
71
|
+
"@storybook/client-api": "^6.2.9",
|
|
72
|
+
"@storybook/client-logger": "^6.2.9",
|
|
73
|
+
"@storybook/components": "^6.2.9",
|
|
74
|
+
"@storybook/core-events": "^6.2.9",
|
|
75
|
+
"@storybook/svelte": "^6.2.9",
|
|
76
|
+
"@storybook/theming": "^6.2.9",
|
|
72
77
|
"react": "^16.8.0 || ^17.0.0",
|
|
73
78
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
74
79
|
"svelte": "^3.35.0",
|
|
@@ -85,6 +90,12 @@
|
|
|
85
90
|
"optional": true
|
|
86
91
|
}
|
|
87
92
|
},
|
|
93
|
+
"auto": {
|
|
94
|
+
"plugins": [
|
|
95
|
+
"npm",
|
|
96
|
+
"released"
|
|
97
|
+
]
|
|
98
|
+
},
|
|
88
99
|
"publishConfig": {
|
|
89
100
|
"access": "public"
|
|
90
101
|
},
|
package/preset.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/preset');
|
|
1
|
+
module.exports = require('./dist/cjs/preset');
|