From 57615b9d8b88d66d92953a175afe45ef81fc3795 Mon Sep 17 00:00:00 2001 From: TristanHoladay <40547442+TristanHoladay@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:52:07 -0600 Subject: [PATCH] #227 - updated name of transition vars in onMounts to be unique for each transition. --- .../transition-preprocessor.test.ts | 20 +- .../transition-preprocessor.ts | 8 +- website/src/routes/test/+page.svelte | 4 +- website/svelte.config.js | 282 +++++++++++------- 4 files changed, 192 insertions(+), 122 deletions(-) diff --git a/website/custom-preprocessor/transition-preprocessor.test.ts b/website/custom-preprocessor/transition-preprocessor.test.ts index 3dacbf5..68a84fe 100644 --- a/website/custom-preprocessor/transition-preprocessor.test.ts +++ b/website/custom-preprocessor/transition-preprocessor.test.ts @@ -65,11 +65,11 @@ describe('preprocessing transition directives passed to custom components (i.e. const finalContent = ''; - const result = tPreproc.writeTransFnToScript(content, 'transition:fade', 'transRef'); + const result = tPreproc.writeTransFnToScript(content, 'transition:fade', 'transRef1'); expect(result).toEqual(finalContent); }); @@ -86,13 +86,13 @@ describe('preprocessing transition directives passed to custom components (i.e. ''; - const result = tPreproc.writeTransFnToScript(content, 'transition:fade', 'transRef'); + const result = tPreproc.writeTransFnToScript(content, 'transition:fade', 'transRef1'); expect(result).toEqual(finalContent); }); @@ -153,11 +153,11 @@ describe('preprocessing transition directives passed to custom components (i.e. '\n let transRef1: HTMLElement;' + '\n' + '\n internal.onMount(() => {' + - '\n const trans = transRef2 && internal.create_bidirectional_transition(transRef2, fade, {}, true);' + - '\n trans.run(1);' + + '\n const transFortransRef2 = transRef2 && internal.create_bidirectional_transition(transRef2, fade, {}, true);' + + '\n transFortransRef2.run(1);' + '\n' + - '\n const trans = transRef1 && internal.create_bidirectional_transition(transRef1, fade, {}, true);' + - '\n trans.run(1);' + + '\n const transFortransRef1 = transRef1 && internal.create_bidirectional_transition(transRef1, fade, {}, true);' + + '\n transFortransRef1.run(1);' + '\n });' + '\n' + '\n let transRef2: HTMLElement;' + diff --git a/website/custom-preprocessor/transition-preprocessor.ts b/website/custom-preprocessor/transition-preprocessor.ts index 55ee10b..f6f79dc 100644 --- a/website/custom-preprocessor/transition-preprocessor.ts +++ b/website/custom-preprocessor/transition-preprocessor.ts @@ -166,17 +166,17 @@ export default class TransitionPreprocessor { } writeToOnMount(content: string, startingInd: number, transition: string, ref: string) { - const transFunc = `\n const trans = ${ref} && internal.create_bidirectional_transition(${ref}, ${ + const transFunc = `\n const transFor${ref} = ${ref} && internal.create_bidirectional_transition(${ref}, ${ transition.split(':')[1] - }, {}, true);\n trans.run(1);\n`; + }, {}, true);\n transFor${ref}.run(1);\n`; return content.slice(0, startingInd) + transFunc + content.slice(startingInd); } createOnMount(scriptContent: string, transition: string, ref: string) { const end_script_tag = scriptContent.search(/<\/script>/); - const onMount = `\n internal.onMount(() => {\n const trans = ${ref} && internal.create_bidirectional_transition(${ref}, ${ + const onMount = `\n internal.onMount(() => {\n const transFor${ref} = ${ref} && internal.create_bidirectional_transition(${ref}, ${ transition.split(':')[1] - }, {}, true);\n trans.run(1);\n });\n`; + }, {}, true);\n transFor${ref}.run(1);\n });\n`; return scriptContent.slice(0, end_script_tag) + onMount + scriptContent.slice(end_script_tag); } diff --git a/website/src/routes/test/+page.svelte b/website/src/routes/test/+page.svelte index fbc39c9..6059008 100644 --- a/website/src/routes/test/+page.svelte +++ b/website/src/routes/test/+page.svelte @@ -3,6 +3,8 @@ import { fade } from 'svelte/transition'; -TeSTING +TeSTING1 +TeSTING2 +TeSTING3
Element Test
diff --git a/website/svelte.config.js b/website/svelte.config.js index bc5252e..8108164 100644 --- a/website/svelte.config.js +++ b/website/svelte.config.js @@ -1,25 +1,25 @@ import adapter from '@sveltejs/adapter-auto'; import preprocess from 'svelte-preprocess'; -const transitionPreprocessor = { - markup({ content, filename }) { - console.log('transition pre-processing ', filename); - let result = content; - const compOpeningTag = getInlineCompOpenTag(content); - - if (compOpeningTag) { - const transPos = getTransPos(compOpeningTag); - if (transPos > -1) { - const transition = getTransition(compOpeningTag, transPos); - if (transition) result = removeTransFromCompTag(content, transition); - result = writeTransFnToScript(result, transition); - console.log('***** FILE: ', filename, '\n', transition, '\n', result); - } - } - - return { code: result }; +let scriptContent = ''; + let styleContent = ''; + const transitionRefs = []; + + const transitionPreprocessor = { markup({content, filename}) { + scriptContent = content.slice(0, content.search(/<\/script>/) + ''.length); + styleContent = content.slice(content.search(/