@storybook/addon-svelte-csf
Advanced tools
Comparing version 2.0.10 to 3.0.0--canary.77.81d0ea4.0
module.exports = { | ||
presets: ['@babel/preset-env', '@babel/preset-typescript'], | ||
plugins: [ | ||
"@babel/plugin-transform-runtime" | ||
], | ||
env: { | ||
@@ -4,0 +7,0 @@ esm: { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,2 +12,4 @@ value: true | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _svelte = require("svelte"); | ||
@@ -15,6 +19,4 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
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; } | ||
var CONTEXT_KEY = "storybook-registration-context"; | ||
@@ -21,0 +23,0 @@ |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -32,4 +34,2 @@ value: true | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
if (module && module.hot && module.hot.decline) { | ||
@@ -36,0 +36,0 @@ module.hot.decline(); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,2 +10,6 @@ value: true | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _clientLogger = require("@storybook/client-logger"); | ||
@@ -21,20 +27,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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."); } | ||
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); } | ||
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; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
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; } | ||
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; } | ||
/* Called from a webpack loader and a jest transformation. | ||
@@ -113,4 +101,3 @@ * | ||
source = _story$source === void 0 ? false : _story$source, | ||
props = _objectWithoutProperties(story, _excluded); | ||
props = (0, _objectWithoutProperties2["default"])(story, _excluded); | ||
var storyId = (0, _extractId.extractId)(story, allocatedIds); | ||
@@ -144,3 +131,3 @@ | ||
Object.entries(props).forEach(function (_ref2) { | ||
var _ref3 = _slicedToArray(_ref2, 2), | ||
var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2), | ||
k = _ref3[0], | ||
@@ -147,0 +134,0 @@ v = _ref3[1]; |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _collectStories = _interopRequireDefault(require("./collect-stories")); | ||
@@ -7,4 +9,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
describe('parse-stories', function () { | ||
@@ -11,0 +11,0 @@ test('Extract Stories', function () { |
@@ -28,2 +28,6 @@ "use strict"; | ||
if (!name) { | ||
throw new Error("Id or Name should be specified"); | ||
} | ||
var generated = name.replace(/\W+(.|$)/g, function (_, chr) { | ||
@@ -30,0 +34,0 @@ return chr.toUpperCase(); |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -16,2 +18,4 @@ value: true | ||
var _csf = require("@storybook/csf"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -21,4 +25,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function getStaticAttribute(name, node) { | ||
@@ -31,3 +33,3 @@ // extract the attribute | ||
if (!attribute) { | ||
return null; | ||
return undefined; | ||
} | ||
@@ -58,33 +60,39 @@ | ||
Story: 'Story', | ||
Template: 'Template' | ||
Template: 'Template', | ||
Meta: 'Meta' | ||
}; | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
if (node.source.value === '@storybook/addon-svelte-csf') { | ||
node.specifiers.filter(function (n) { | ||
return n.type === 'ImportSpecifier'; | ||
}).forEach(function (n) { | ||
localNames[n.imported.name] = n.local.name; | ||
if (ast.instance) { | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
if (node.source.value === '@storybook/addon-svelte-csf') { | ||
node.specifiers.filter(function (n) { | ||
return n.type === 'ImportSpecifier'; | ||
}).forEach(function (n) { | ||
localNames[n.imported.name] = n.local.name; | ||
}); | ||
} | ||
this.skip(); | ||
} | ||
} | ||
}); // extracts allocated Ids | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
node.specifiers.map(function (n) { | ||
return n.local.name; | ||
}).forEach(function (name) { | ||
return allocatedIds.push(name); | ||
}); | ||
this.skip(); | ||
} | ||
this.skip(); | ||
} | ||
} | ||
}); // extracts allocated Ids | ||
}); | ||
} | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
node.specifiers.map(function (n) { | ||
return n.local.name; | ||
}).forEach(function (name) { | ||
return allocatedIds.push(name); | ||
}); | ||
this.skip(); | ||
} | ||
} | ||
}); | ||
var stories = {}; | ||
var meta = {}; | ||
svelte.walk(ast.html, { | ||
@@ -118,2 +126,3 @@ enter: function enter(node) { | ||
stories[isTemplate ? "tpl:".concat(id) : id] = { | ||
storyId: (0, _csf.toId)(meta.id || meta.title || id, (0, _csf.storyNameFromExport)(id)), | ||
name: name, | ||
@@ -127,2 +136,6 @@ template: isTemplate, | ||
} | ||
} else if (node.type === 'InlineComponent' && node.name === localNames.Meta) { | ||
this.skip(); | ||
meta.title = getStaticAttribute("title", node); | ||
meta.id = getStaticAttribute("id", node); | ||
} | ||
@@ -132,2 +145,3 @@ } | ||
return { | ||
meta: meta, | ||
stories: stories, | ||
@@ -134,0 +148,0 @@ allocatedIds: allocatedIds |
@@ -7,25 +7,25 @@ "use strict"; | ||
test('Simple Story', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"mystory--my-story\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Explicit Id Story', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"myId\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"myid--my-id\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Args Story', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": true,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"mystory--my-story\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Simple Template', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"tpl:MyTemplate\": Object {\n \"hasArgs\": false,\n \"name\": \"MyTemplate\",\n \"source\": \"<div>a template</div>\",\n \"storyId\": \"mytemplate--my-template\",\n \"template\": true,\n },\n },\n }\n "); | ||
}); | ||
test('Unnamed Template', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"tpl:default\": Object {\n \"hasArgs\": false,\n \"name\": \"default\",\n \"source\": \"<div>a template</div>\",\n \"storyId\": \"default--default\",\n \"template\": true,\n },\n },\n }\n "); | ||
}); | ||
test('Multiple Stories', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"storyId\": \"story1--story-1\",\n \"template\": false,\n },\n \"Story2\": Object {\n \"hasArgs\": false,\n \"name\": \"Story2\",\n \"source\": \"<div>story 2</div>\",\n \"storyId\": \"story2--story-2\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Renamed Import', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {\n \"id\": undefined,\n \"title\": \"test\",\n },\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"storyId\": \"test--story-1\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Duplicate Id', function () { | ||
expect((0, _extractStories.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 "); | ||
expect((0, _extractStories.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 \"meta\": Object {},\n \"stories\": Object {\n \"Button77471352\": Object {\n \"hasArgs\": false,\n \"name\": \"Button\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"button77471352--button-77471352\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
}); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,2 +11,6 @@ value: true | ||
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _tsDedent = _interopRequireDefault(require("ts-dedent")); | ||
@@ -18,18 +24,2 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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."); } | ||
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); } | ||
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; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
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 | ||
@@ -69,3 +59,3 @@ // Copied because it is not exported from the compiler | ||
var storyDef = Object.entries(stories).filter(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2), | ||
def = _ref2[1]; | ||
@@ -75,3 +65,3 @@ | ||
}).map(function (_ref3) { | ||
var _ref4 = _slicedToArray(_ref3, 1), | ||
var _ref4 = (0, _slicedToArray2["default"])(_ref3, 1), | ||
id = _ref4[0]; | ||
@@ -82,3 +72,3 @@ | ||
var codeWithoutDefaultExport = code.replace('export default ', '//export default'); | ||
return (0, _tsDedent["default"])(_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); | ||
return (0, _tsDedent["default"])(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["", "\n const { default: parser } = require('", "');\n const __storiesMetaData = parser(", ", ", ");\n export default __storiesMetaData.meta;\n ", ";\n "])), codeWithoutDefaultExport, parser, componentName, JSON.stringify(storiesDef), storyDef); | ||
} | ||
@@ -85,0 +75,0 @@ |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -7,25 +9,22 @@ value: true | ||
exports.managerEntries = managerEntries; | ||
exports.storyIndexers = void 0; | ||
exports.webpack = webpack; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
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; } | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
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."); } | ||
var _indexer = require("./indexer.js"); | ||
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); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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; } | ||
function managerEntries() { | ||
var entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return [].concat(_toConsumableArray(entry), [require.resolve('./manager')]); | ||
return [].concat((0, _toConsumableArray2["default"])(entry), [require.resolve('./manager')]); | ||
} | ||
@@ -36,3 +35,3 @@ | ||
module: _objectSpread(_objectSpread({}, config.module), {}, { | ||
rules: [].concat(_toConsumableArray(config.module.rules), [{ | ||
rules: [].concat((0, _toConsumableArray2["default"])(config.module.rules), [{ | ||
test: /\.stories\.svelte$/, | ||
@@ -46,2 +45,28 @@ enforce: 'post', | ||
}); | ||
} | ||
} | ||
var storyIndexers = /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(indexers) { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", [{ | ||
test: /\.stories\.svelte$/, | ||
indexer: _indexer.svelteIndexer | ||
}].concat((0, _toConsumableArray2["default"])(indexers || []))); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function storyIndexers(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
exports.storyIndexers = storyIndexers; |
@@ -0,1 +1,3 @@ | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
@@ -5,4 +7,2 @@ | ||
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; } | ||
import { getContext, hasContext, setContext } from "svelte"; | ||
@@ -9,0 +9,0 @@ var CONTEXT_KEY = "storybook-registration-context"; |
@@ -0,19 +1,5 @@ | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
var _excluded = ["id", "name", "template", "component", "source"]; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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."); } | ||
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); } | ||
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; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
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; } | ||
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; } | ||
/* eslint-env browser */ | ||
@@ -20,0 +6,0 @@ import { logger } from '@storybook/client-logger'; |
@@ -21,2 +21,6 @@ import { logger } from '@storybook/client-logger'; | ||
if (!name) { | ||
throw new Error("Id or Name should be specified"); | ||
} | ||
var generated = name.replace(/\W+(.|$)/g, function (_, chr) { | ||
@@ -23,0 +27,0 @@ return chr.toUpperCase(); |
import dedent from 'ts-dedent'; | ||
import * as svelte from 'svelte/compiler'; | ||
import { extractId } from './extract-id'; | ||
import { toId, storyNameFromExport } from "@storybook/csf"; | ||
@@ -12,3 +13,3 @@ function getStaticAttribute(name, node) { | ||
if (!attribute) { | ||
return null; | ||
return undefined; | ||
} | ||
@@ -39,33 +40,39 @@ | ||
Story: 'Story', | ||
Template: 'Template' | ||
Template: 'Template', | ||
Meta: 'Meta' | ||
}; | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
if (node.source.value === '@storybook/addon-svelte-csf') { | ||
node.specifiers.filter(function (n) { | ||
return n.type === 'ImportSpecifier'; | ||
}).forEach(function (n) { | ||
localNames[n.imported.name] = n.local.name; | ||
if (ast.instance) { | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
if (node.source.value === '@storybook/addon-svelte-csf') { | ||
node.specifiers.filter(function (n) { | ||
return n.type === 'ImportSpecifier'; | ||
}).forEach(function (n) { | ||
localNames[n.imported.name] = n.local.name; | ||
}); | ||
} | ||
this.skip(); | ||
} | ||
} | ||
}); // extracts allocated Ids | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
node.specifiers.map(function (n) { | ||
return n.local.name; | ||
}).forEach(function (name) { | ||
return allocatedIds.push(name); | ||
}); | ||
this.skip(); | ||
} | ||
this.skip(); | ||
} | ||
} | ||
}); // extracts allocated Ids | ||
}); | ||
} | ||
svelte.walk(ast.instance, { | ||
enter: function enter(node) { | ||
if (node.type === 'ImportDeclaration') { | ||
node.specifiers.map(function (n) { | ||
return n.local.name; | ||
}).forEach(function (name) { | ||
return allocatedIds.push(name); | ||
}); | ||
this.skip(); | ||
} | ||
} | ||
}); | ||
var stories = {}; | ||
var meta = {}; | ||
svelte.walk(ast.html, { | ||
@@ -99,2 +106,3 @@ enter: function enter(node) { | ||
stories[isTemplate ? "tpl:".concat(id) : id] = { | ||
storyId: toId(meta.id || meta.title || id, storyNameFromExport(id)), | ||
name: name, | ||
@@ -108,2 +116,6 @@ template: isTemplate, | ||
} | ||
} else if (node.type === 'InlineComponent' && node.name === localNames.Meta) { | ||
this.skip(); | ||
meta.title = getStaticAttribute("title", node); | ||
meta.id = getStaticAttribute("id", node); | ||
} | ||
@@ -113,2 +125,3 @@ } | ||
return { | ||
meta: meta, | ||
stories: stories, | ||
@@ -115,0 +128,0 @@ allocatedIds: allocatedIds |
import { extractStories } from './extract-stories'; | ||
describe('extractSource', function () { | ||
test('Simple Story', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"mystory--my-story\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Explicit Id Story', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"myId\": Object {\n \"hasArgs\": false,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"myid--my-id\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Args Story', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"MyStory\": Object {\n \"hasArgs\": true,\n \"name\": \"MyStory\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"mystory--my-story\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Simple Template', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"tpl:MyTemplate\": Object {\n \"hasArgs\": false,\n \"name\": \"MyTemplate\",\n \"source\": \"<div>a template</div>\",\n \"storyId\": \"mytemplate--my-template\",\n \"template\": true,\n },\n },\n }\n "); | ||
}); | ||
test('Unnamed Template', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"tpl:default\": Object {\n \"hasArgs\": false,\n \"name\": \"default\",\n \"source\": \"<div>a template</div>\",\n \"storyId\": \"default--default\",\n \"template\": true,\n },\n },\n }\n "); | ||
}); | ||
test('Multiple Stories', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"storyId\": \"story1--story-1\",\n \"template\": false,\n },\n \"Story2\": Object {\n \"hasArgs\": false,\n \"name\": \"Story2\",\n \"source\": \"<div>story 2</div>\",\n \"storyId\": \"story2--story-2\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Renamed Import', function () { | ||
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 "); | ||
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 \"meta\": Object {\n \"id\": undefined,\n \"title\": \"test\",\n },\n \"stories\": Object {\n \"Story1\": Object {\n \"hasArgs\": false,\n \"name\": \"Story1\",\n \"source\": \"<div>story 1</div>\",\n \"storyId\": \"test--story-1\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
test('Duplicate Id', function () { | ||
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 "); | ||
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 \"meta\": Object {},\n \"stories\": Object {\n \"Button77471352\": Object {\n \"hasArgs\": false,\n \"name\": \"Button\",\n \"source\": \"<div>a story</div>\",\n \"storyId\": \"button77471352--button-77471352\",\n \"template\": false,\n },\n },\n }\n "); | ||
}); | ||
}); |
@@ -0,17 +1,6 @@ | ||
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral"; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
var _templateObject; | ||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
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."); } | ||
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); } | ||
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; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
import dedent from 'ts-dedent'; | ||
@@ -18,0 +7,0 @@ import { readFileSync } from 'fs'; |
@@ -0,1 +1,6 @@ | ||
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
@@ -5,16 +10,3 @@ | ||
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; } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
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."); } | ||
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); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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; } | ||
import { svelteIndexer } from "./indexer.js"; | ||
export function managerEntries() { | ||
@@ -36,2 +28,25 @@ var entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
}); | ||
} | ||
} | ||
export var storyIndexers = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(indexers) { | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", [{ | ||
test: /\.stories\.svelte$/, | ||
indexer: svelteIndexer | ||
}].concat(_toConsumableArray(indexers || []))); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function storyIndexers(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); |
{ | ||
"name": "@storybook/addon-svelte-csf", | ||
"version": "2.0.10", | ||
"version": "3.0.0--canary.77.81d0ea4.0", | ||
"description": "Allows to write stories in Svelte syntax", | ||
@@ -31,9 +31,10 @@ "keywords": [ | ||
"lint": "eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives", | ||
"storybook": "start-storybook -p 6006", | ||
"storybook": "sb dev -p 6006", | ||
"start": "concurrently \"yarn storybook -- --no-manager-cache --quiet\" \"yarn build -- --watch\"", | ||
"build-storybook": "build-storybook", | ||
"build-storybook": "sb build", | ||
"release": "yarn build && auto shipit" | ||
}, | ||
"dependencies": { | ||
"ts-dedent": "^2.0.0" | ||
"ts-dedent": "^2.0.0", | ||
"@babel/runtime": "^7.17.5" | ||
}, | ||
@@ -47,9 +48,14 @@ "devDependencies": { | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@storybook/addon-essentials": "^6.4.20", | ||
"@storybook/addon-interactions": "^6.4.20", | ||
"@babel/plugin-transform-runtime": "^7.17.5", | ||
"@storybook/addon-essentials": "^7.0.0-alpha.29", | ||
"@storybook/addon-interactions": "^7.0.0-alpha.29", | ||
"@storybook/jest": "^0.0.10", | ||
"@storybook/testing-library": "^0.0.9", | ||
"@storybook/addon-storyshots": "^6.4.20", | ||
"@storybook/addon-storyshots": "^7.0.0-alpha.29", | ||
"@storybook/eslint-config-storybook": "^3.1.2", | ||
"@storybook/svelte": "^6.4.20", | ||
"@storybook/svelte": "^7.0.0-alpha.29", | ||
"@storybook/core-server": "^7.0.0-alpha.29", | ||
"@storybook/core-client": "^7.0.0-alpha.29", | ||
"@storybook/svelte-webpack5": "7.0.0-alpha.29", | ||
"sb": "7.0.0-alpha.29", | ||
"auto": "^10.3.0", | ||
@@ -67,3 +73,3 @@ "babel-jest": "^29.1.0", | ||
"rimraf": "^3.0.2", | ||
"svelte": "^3.46.6", | ||
"svelte": "^3.50.0", | ||
"svelte-jester": "^2.3.2", | ||
@@ -75,3 +81,4 @@ "svelte-loader": "^3.1.2", | ||
"@storybook/svelte": ">=6.4.20", | ||
"svelte": "^3.46.6", | ||
"@storybook/theming": ">=6.4.20", | ||
"svelte": "^3.50.0", | ||
"svelte-loader": "^3.1.2" | ||
@@ -78,0 +85,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51
1269
77821
6
34
2
4
5
+ Added@babel/runtime@^7.17.5
+ Added@babel/runtime@7.25.6(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)