From cce0ba4c4a7a168dcd98036629affd0f86401db1 Mon Sep 17 00:00:00 2001 From: Naratna Date: Sun, 30 Apr 2023 04:05:31 -0600 Subject: [PATCH 1/7] Add suport for play function --- src/core/parser.ts | 12 ++++++++++++ src/core/transform.ts | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/parser.ts b/src/core/parser.ts index 54a7762e..84003f74 100644 --- a/src/core/parser.ts +++ b/src/core/parser.ts @@ -18,6 +18,7 @@ export interface ParsedStory { id: string title: string template: string + play?: string } export function parse(code: string) { @@ -75,6 +76,8 @@ function parseTemplate(content: string): { const title = extractTitle(story) if (!title) throw new Error('Story is missing a title') + const play = extractPlay(story) + const storyTemplate = parseSFC( story.loc.source .replace(/ Object.assign({render: render${id}}, _sfc_main) - ${id}.storyName = '${title}' + ${id}.storyName = '${title}'${play ? `\n${id}.play = ${play}` : ''} ${id}.parameters = { docs: { source: { code: \`${template.trim()}\` } }, };` From e100f6c9b9ba10009dca8bd1d8ad3428373e6535 Mon Sep 17 00:00:00 2001 From: Naratna Date: Sun, 30 Apr 2023 04:05:48 -0600 Subject: [PATCH 2/7] Added test for play function support --- test/index.test.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index f845ceea..0d643243 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -346,4 +346,46 @@ describe('transform', () => { " `) }) + + it('suupports play functions', async () => { + const code = ` + + + + ` + const result = await transform(code) + expect(result).toMatchInlineSnapshot(` + "function playFunction({ canvasElement }: any) { + console.log(\\"playFunction\\"); + } + + const _sfc_main = {}; + export default { + //decorators: [ ... ], + parameters: {}, + }; + + function renderPrimary(_ctx, _cache, $props, $setup, $data, $options) { + return \\"hello\\"; + } + export const Primary = () => + Object.assign({ render: renderPrimary }, _sfc_main); + Primary.storyName = \\"Primary\\"; + Primary.play = playFunction; + Primary.parameters = { + docs: { source: { code: \`hello\` } }, + }; + " + `) + }) }) From 8973b135bb965bb42b4328b696cfb70e0c662a2f Mon Sep 17 00:00:00 2001 From: Naratna Date: Sun, 30 Apr 2023 06:54:43 -0600 Subject: [PATCH 3/7] Fixed typo in test name --- test/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index 0d643243..934bbd79 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -347,7 +347,7 @@ describe('transform', () => { `) }) - it('suupports play functions', async () => { + it('supports play functions', async () => { const code = `