Comparing version 5.0.0-next.188 to 5.0.0-next.189
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0-next.188", | ||
"version": "5.0.0-next.189", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "types": "./types/index.d.ts", |
@@ -1111,3 +1111,3 @@ /* This file is generated by scripts/process-messages/index.js. Do not edit! */ | ||
/** | ||
* snippets do not support rest parameters; use an array instead | ||
* Snippets do not support rest parameters; use an array instead | ||
* @param {null | number | NodeLike} node | ||
@@ -1117,3 +1117,3 @@ * @returns {never} | ||
export function snippet_invalid_rest_parameter(node) { | ||
e(node, "snippet_invalid_rest_parameter", "snippets do not support rest parameters; use an array instead"); | ||
e(node, "snippet_invalid_rest_parameter", "Snippets do not support rest parameters; use an array instead"); | ||
} | ||
@@ -1120,0 +1120,0 @@ |
@@ -677,2 +677,8 @@ import is_reference from 'is-reference'; | ||
for (const arg of node.parameters) { | ||
if (arg.type === 'RestElement') { | ||
e.snippet_invalid_rest_parameter(arg); | ||
} | ||
} | ||
context.next({ ...context.state, parent_element: null }); | ||
@@ -679,0 +685,0 @@ |
@@ -193,1 +193,3 @@ import { current_component_context, flush_sync, untrack } from './internal/client/runtime.js'; | ||
} from './internal/client/runtime.js'; | ||
export { createRawSnippet } from './internal/client/dom/blocks/snippet.js'; |
@@ -38,1 +38,3 @@ import { current_component } from './internal/server/context.js'; | ||
export { getAllContexts, getContext, hasContext, setContext } from './internal/server/context.js'; | ||
export { createRawSnippet } from './internal/server/blocks/snippet.js'; |
@@ -0,5 +1,7 @@ | ||
/** @import { Snippet } from 'svelte' */ | ||
/** @import { Effect, TemplateNode } from '#client' */ | ||
/** @import { Getters } from '#shared' */ | ||
import { add_snippet_symbol } from '../../../shared/validate.js'; | ||
import { EFFECT_TRANSPARENT } from '../../constants.js'; | ||
import { branch, block, destroy_effect } from '../../reactivity/effects.js'; | ||
import { branch, block, destroy_effect, teardown } from '../../reactivity/effects.js'; | ||
import { | ||
@@ -9,3 +11,5 @@ dev_current_component_function, | ||
} from '../../runtime.js'; | ||
import { hydrate_node, hydrating } from '../hydration.js'; | ||
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js'; | ||
import { create_fragment_from_html } from '../reconciler.js'; | ||
import { assign_nodes } from '../template.js'; | ||
@@ -64,1 +68,38 @@ /** | ||
} | ||
/** | ||
* Create a snippet programmatically | ||
* @template {unknown[]} Params | ||
* @param {(...params: Getters<Params>) => { | ||
* render: () => string | ||
* setup?: (element: Element) => void | ||
* }} fn | ||
* @returns {Snippet<Params>} | ||
*/ | ||
export function createRawSnippet(fn) { | ||
return add_snippet_symbol( | ||
(/** @type {TemplateNode} */ anchor, /** @type {Getters<Params>} */ ...params) => { | ||
var snippet = fn(...params); | ||
/** @type {Element} */ | ||
var element; | ||
if (hydrating) { | ||
element = /** @type {Element} */ (hydrate_node); | ||
hydrate_next(); | ||
} else { | ||
var html = snippet.render().trim(); | ||
var fragment = create_fragment_from_html(html); | ||
element = /** @type {Element} */ (fragment.firstChild); | ||
anchor.before(element); | ||
} | ||
const result = snippet.setup?.(element); | ||
assign_nodes(element, element); | ||
if (typeof result === 'function') { | ||
teardown(result); | ||
} | ||
} | ||
); | ||
} |
@@ -10,2 +10,6 @@ export type Store<V> = { | ||
export type Getters<T> = { | ||
[K in keyof T]: () => T[K]; | ||
}; | ||
export type Snapshot<T> = ReturnType<typeof $state.snapshot<T>>; |
@@ -0,1 +1,3 @@ | ||
/** @import { TemplateNode } from '#client' */ | ||
/** @import { Getters } from '#shared' */ | ||
import { is_void } from '../../constants.js'; | ||
@@ -9,2 +11,3 @@ import * as w from './warnings.js'; | ||
* @param {any} fn | ||
* @returns {import('svelte').Snippet} | ||
*/ | ||
@@ -11,0 +14,0 @@ export function add_snippet_symbol(fn) { |
@@ -9,3 +9,3 @@ // generated during release, do not modify | ||
*/ | ||
export const VERSION = '5.0.0-next.188'; | ||
export const VERSION = '5.0.0-next.189'; | ||
export const PUBLIC_VERSION = '5'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
2147409
216
47267