diff --git a/site/content/examples/09-transitions/06-deferred-transitions/App.svelte b/site/content/examples/09-transitions/06-deferred-transitions/App.svelte index c46096c204..674f1fb9b0 100644 --- a/site/content/examples/09-transitions/06-deferred-transitions/App.svelte +++ b/site/content/examples/09-transitions/06-deferred-transitions/App.svelte @@ -43,12 +43,6 @@ function remove(todo) { todos = todos.filter(t => t !== todo); } - - function handleKeydown(event) { - if (event.which === 13) { - addTodo(event.target); - } - }
- +

todo

diff --git a/site/src/routes/blog/_posts.js b/site/src/routes/blog/_posts.js index 3b6ec37dab..fc2bed469a 100644 --- a/site/src/routes/blog/_posts.js +++ b/site/src/routes/blog/_posts.js @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { extract_frontmatter, langs } from '../../utils/markdown.js'; +import { extract_frontmatter, langs, link_renderer } from '../../utils/markdown.js'; import marked from 'marked'; import PrismJS from 'prismjs'; import 'prismjs/components/prism-bash'; @@ -20,6 +20,8 @@ export default function() { const renderer = new marked.Renderer(); + renderer.link = link_renderer; + renderer.code = (source, lang) => { const plang = langs[lang]; const highlighted = PrismJS.highlight( diff --git a/site/src/routes/docs/_sections.js b/site/src/routes/docs/_sections.js index fff450dee5..dbef07357d 100644 --- a/site/src/routes/docs/_sections.js +++ b/site/src/routes/docs/_sections.js @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { extract_frontmatter, extract_metadata, langs } from '../../utils/markdown.js'; +import { extract_frontmatter, extract_metadata, langs, link_renderer } from '../../utils/markdown.js'; import marked from 'marked'; import PrismJS from 'prismjs'; import 'prismjs/components/prism-bash'; @@ -50,6 +50,8 @@ export default function() { let block_open = false; + renderer.link = link_renderer; + renderer.hr = (...args) => { block_open = true; diff --git a/site/src/routes/tutorial/[slug]/index.json.js b/site/src/routes/tutorial/[slug]/index.json.js index a44685530d..7076ce1170 100644 --- a/site/src/routes/tutorial/[slug]/index.json.js +++ b/site/src/routes/tutorial/[slug]/index.json.js @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import marked from 'marked'; import PrismJS from 'prismjs'; -import { extract_frontmatter, extract_metadata, langs } from '../../../utils/markdown'; +import { extract_frontmatter, extract_metadata, langs, link_renderer } from '../../../utils/markdown'; const cache = new Map(); @@ -33,6 +33,8 @@ function get_tutorial(slug) { const renderer = new marked.Renderer(); + renderer.link = link_renderer; + renderer.code = (source, lang) => { source = source.replace(/^ +/gm, match => match.split(' ').join('\t') diff --git a/site/src/utils/markdown.js b/site/src/utils/markdown.js index ea0f7d0b2a..e1021664c3 100644 --- a/site/src/utils/markdown.js +++ b/site/src/utils/markdown.js @@ -42,3 +42,20 @@ export const langs = { js: 'javascript', css: 'css' }; + + +// links renderer +export function link_renderer(href,title,text) { + let target_attr = ''; + let title_attr = ''; + + if(href.startsWith("http")) { + target_attr = ' target="_blank"'; + } + + if(title !== null) { + title_attr = ` title="${title}"`; + } + + return `${text}`; +}; \ No newline at end of file diff --git a/src/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compile/render-dom/wrappers/InlineComponent/index.ts index 870296a035..9a93034772 100644 --- a/src/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compile/render-dom/wrappers/InlineComponent/index.ts @@ -324,13 +324,14 @@ export default class InlineComponentWrapper extends Wrapper { contextual_dependencies.push(object, property); } - const args = ['value']; + const value = block.get_unique_name('value'); + const args = [value]; if (contextual_dependencies.length > 0) { args.push(`{ ${contextual_dependencies.join(', ')} }`); block.builders.init.add_block(deindent` - function ${name}(value) { - ctx.${name}.call(null, value, ctx); + function ${name}(${value}) { + ctx.${name}.call(null, ${value}, ctx); ${updating} = true; @add_flush_callback(() => ${updating} = false); } @@ -339,17 +340,18 @@ export default class InlineComponentWrapper extends Wrapper { block.maintain_context = true; // TODO put this somewhere more logical } else { block.builders.init.add_block(deindent` - function ${name}(value) { - ctx.${name}.call(null, value); + function ${name}(${value}) { + ctx.${name}.call(null, ${value}); ${updating} = true; @add_flush_callback(() => ${updating} = false); + } } `); } const body = deindent` function ${name}(${args.join(', ')}) { - ${lhs} = value; + ${lhs} = ${value}; ${component.invalidate(dependencies[0])}; } `; diff --git a/test/runtime/samples/deconflict-value/Widget.svelte b/test/runtime/samples/deconflict-value/Widget.svelte new file mode 100644 index 0000000000..909dc03c89 --- /dev/null +++ b/test/runtime/samples/deconflict-value/Widget.svelte @@ -0,0 +1,3 @@ + diff --git a/test/runtime/samples/deconflict-value/_config.js b/test/runtime/samples/deconflict-value/_config.js new file mode 100644 index 0000000000..ac21772c8c --- /dev/null +++ b/test/runtime/samples/deconflict-value/_config.js @@ -0,0 +1,6 @@ +export default { + html: ` +

Reactive: foo

+

Value: foo

+ ` +}; diff --git a/test/runtime/samples/deconflict-value/main.svelte b/test/runtime/samples/deconflict-value/main.svelte new file mode 100644 index 0000000000..07b7c2e1f0 --- /dev/null +++ b/test/runtime/samples/deconflict-value/main.svelte @@ -0,0 +1,9 @@ + + + +

Reactive: {reactive}

+

Value: {value}