@storybook/addon-svelte-csf 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  interface StoryDef {
2
- storyId: string;
3
2
  name: string;
4
3
  template: boolean;
5
4
  source: string;
@@ -1,5 +1,4 @@
1
1
  import * as svelte from 'svelte/compiler';
2
- import { storyNameFromExport, toId } from '@storybook/csf';
3
2
  import dedent from 'dedent';
4
3
  import { extractId } from './extract-id.js';
5
4
  function getStaticAttribute(name, node) {
@@ -85,7 +84,6 @@ export function extractStories(component) {
85
84
  source = dedent `${component.substr(start, end - start)}`;
86
85
  }
87
86
  stories[isTemplate ? `tpl:${id}` : id] = {
88
- storyId: toId(meta.id || meta.title || id, storyNameFromExport(id)),
89
87
  name,
90
88
  template: isTemplate,
91
89
  source,
@@ -1,9 +1,8 @@
1
- import dedent from 'dedent';
2
1
  import { extractStories } from './extract-stories.js';
3
2
  import { fileURLToPath } from 'url';
4
3
  import { readFileSync } from 'fs';
5
4
  const parser = fileURLToPath(new URL('./collect-stories.js', import.meta.url))
6
- .replace(/\\/g, "\\\\"); // For Windows paths;
5
+ .replace(/\\/g, '/'); // For Windows paths;
7
6
  // From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts
8
7
  // Copied because it is not exported from the compiler
9
8
  export function getNameFromFilename(filename) {
@@ -44,9 +43,7 @@ function transformSvelteStories(code) {
44
43
  .map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}]`)
45
44
  .join('\n');
46
45
  const codeWithoutDefaultExport = code.replace('export default ', '//export default');
47
- // throws dedent expression is not callable.
48
- // @ts-ignore
49
- return dedent `${codeWithoutDefaultExport}
46
+ return `${codeWithoutDefaultExport}
50
47
  const { default: parser } = require('${parser}');
51
48
  const __storiesMetaData = parser(${componentName}, ${JSON.stringify(storiesDef)});
52
49
  export default __storiesMetaData.meta;
@@ -3,6 +3,7 @@ export declare function svelteIndexer(fileName: any, { makeTitle }: {
3
3
  }): Promise<{
4
4
  meta: {
5
5
  title: any;
6
+ id?: string | undefined;
6
7
  };
7
8
  stories: {
8
9
  id: string;
@@ -2,6 +2,7 @@ import * as svelte from 'svelte/compiler';
2
2
  import { extractStories } from '../parser/extract-stories.js';
3
3
  import fs from 'fs-extra';
4
4
  import { loadSvelteConfig } from '../config-loader.js';
5
+ import { storyNameFromExport, toId } from '@storybook/csf';
5
6
  export async function svelteIndexer(fileName, { makeTitle }) {
6
7
  let code = (await fs.readFile(fileName, 'utf-8')).toString();
7
8
  const svelteOptions = await loadSvelteConfig();
@@ -9,12 +10,13 @@ export async function svelteIndexer(fileName, { makeTitle }) {
9
10
  code = (await svelte.preprocess(code, svelteOptions.preprocess, { filename: fileName })).code;
10
11
  }
11
12
  const defs = extractStories(code);
13
+ const meta = { ...defs.meta, title: makeTitle(defs.meta.title) };
12
14
  return {
13
- meta: { title: makeTitle(defs.meta.title) },
15
+ meta,
14
16
  stories: Object.entries(defs.stories)
15
17
  .filter(([id, story]) => !story.template)
16
18
  .map(([id, story]) => ({
17
- id: story.storyId,
19
+ id: toId(meta.id || meta.title || id, storyNameFromExport(id)),
18
20
  name: story.name,
19
21
  })),
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-svelte-csf",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Allows to write stories in Svelte syntax",
5
5
  "keywords": [
6
6
  "storybook-addons",