@contentful/experiences-svelte 0.4.1 → 0.5.1
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.
- package/CHANGELOG.md +99 -0
- package/README.md +39 -8
- package/dist/ClientExperienceRenderer.svelte +3 -3
- package/dist/DebugExperience.svelte +3 -1
- package/dist/DebugExperience.svelte.d.ts.map +1 -1
- package/dist/DebugExperience.test.js +6 -6
- package/dist/MissingComponent.svelte +6 -6
- package/dist/NodeRenderer.svelte +5 -5
- package/dist/NodeRenderer.svelte.d.ts +1 -1
- package/dist/NodeRenderer.svelte.d.ts.map +1 -1
- package/dist/NodesRenderer.svelte +29 -21
- package/dist/NodesRenderer.svelte.d.ts +0 -1
- package/dist/NodesRenderer.svelte.d.ts.map +1 -1
- package/dist/ServerExperienceRenderer.svelte +3 -3
- package/dist/WrapWithExperienceTemplate.svelte +87 -0
- package/dist/WrapWithExperienceTemplate.svelte.d.ts +13 -0
- package/dist/WrapWithExperienceTemplate.svelte.d.ts.map +1 -0
- package/dist/component-props.d.ts +1 -1
- package/dist/component-props.d.ts.map +1 -1
- package/dist/context.d.ts +6 -5
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/server-renderer.test.js +90 -29
- package/dist/test-fixtures/ContainerFixture.svelte +4 -2
- package/dist/test-fixtures/ContainerFixture.svelte.d.ts +1 -1
- package/dist/test-fixtures/ContainerFixture.svelte.d.ts.map +1 -1
- package/dist/test-fixtures/{TemplateFixture.svelte → ExperienceTemplateFixture.svelte} +1 -1
- package/dist/test-fixtures/ExperienceTemplateFixture.svelte.d.ts +9 -0
- package/dist/test-fixtures/ExperienceTemplateFixture.svelte.d.ts.map +1 -0
- package/dist/test-fixtures/WrappingContainerFixture.svelte +27 -0
- package/dist/test-fixtures/WrappingContainerFixture.svelte.d.ts +8 -0
- package/dist/test-fixtures/WrappingContainerFixture.svelte.d.ts.map +1 -0
- package/dist/types.d.ts +13 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/package.json +5 -5
- package/dist/WrapWithTemplate.svelte +0 -87
- package/dist/WrapWithTemplate.svelte.d.ts +0 -13
- package/dist/WrapWithTemplate.svelte.d.ts.map +0 -1
- package/dist/test-fixtures/TemplateFixture.svelte.d.ts +0 -9
- package/dist/test-fixtures/TemplateFixture.svelte.d.ts.map +0 -1
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
* Wraps the rendered Experience nodes with the page-level template when the
|
|
3
|
-
* plan carries one and the customer registered a template config under that
|
|
4
|
-
* id. When the template is referenced but unregistered, warns once and
|
|
5
|
-
* renders children unwrapped — graceful degradation matches the
|
|
6
|
-
* unknown-component fallback story.
|
|
7
|
-
-->
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import type { Snippet } from 'svelte';
|
|
10
|
-
|
|
11
|
-
import type { PortableTemplate } from '@contentful/experiences-sdk-core';
|
|
12
|
-
import { applyTokenResolver, resolveDesignProperties } from '@contentful/experiences-design';
|
|
13
|
-
|
|
14
|
-
import { setContentfulTemplate, setResolvedDesign } from './context.js';
|
|
15
|
-
import {
|
|
16
|
-
normalizeTemplateRegistration,
|
|
17
|
-
type ContentfulTemplate,
|
|
18
|
-
type Config,
|
|
19
|
-
type RenderContext,
|
|
20
|
-
} from './types.js';
|
|
21
|
-
|
|
22
|
-
interface WrapWithTemplateProps {
|
|
23
|
-
template: PortableTemplate | undefined;
|
|
24
|
-
config: Config;
|
|
25
|
-
experience: RenderContext;
|
|
26
|
-
children: Snippet;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let { template, config, experience, children }: WrapWithTemplateProps = $props();
|
|
30
|
-
|
|
31
|
-
// setContext must run during synchronous component init — call once with
|
|
32
|
-
// the initial template value (templates don't toggle on/off mid-mount).
|
|
33
|
-
if (template) {
|
|
34
|
-
setContentfulTemplate({
|
|
35
|
-
templateId: template.templateId,
|
|
36
|
-
content: template.props.content,
|
|
37
|
-
design: template.props.design,
|
|
38
|
-
resolved: template.props.resolved,
|
|
39
|
-
} satisfies ContentfulTemplate);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const entry = $derived(template ? config.templates?.[template.templateId] : undefined);
|
|
43
|
-
const templateConfig = $derived(entry ? normalizeTemplateRegistration(entry) : null);
|
|
44
|
-
|
|
45
|
-
const tokenResolvedDesign = $derived.by(() => {
|
|
46
|
-
if (!template) return {};
|
|
47
|
-
const resolvedDesign = resolveDesignProperties(
|
|
48
|
-
template.props.design,
|
|
49
|
-
experience.viewports,
|
|
50
|
-
experience.activeViewportIndex
|
|
51
|
-
);
|
|
52
|
-
const { props, unresolved } = applyTokenResolver(resolvedDesign, config.resolveToken);
|
|
53
|
-
if (unresolved.length && typeof console !== 'undefined') {
|
|
54
|
-
console.warn(
|
|
55
|
-
`[@contentful/experiences-svelte] resolveToken returned undefined for token id(s) on template "${template.templateId}": ${unresolved.join(', ')}. getDesignValues() will omit those keys.`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return props;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// A getter (not a snapshot) so getDesignValues() stays reactive; not merged into props.
|
|
62
|
-
setResolvedDesign(() => tokenResolvedDesign);
|
|
63
|
-
|
|
64
|
-
const composed = $derived.by(() => {
|
|
65
|
-
if (!template || !templateConfig) return null;
|
|
66
|
-
return {
|
|
67
|
-
...templateConfig.defaults,
|
|
68
|
-
...template.props.content,
|
|
69
|
-
...template.props.resolved,
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
$effect(() => {
|
|
74
|
-
if (template && !templateConfig && typeof console !== 'undefined') {
|
|
75
|
-
console.warn(
|
|
76
|
-
`[@contentful/experiences-svelte] No template registered for id "${template.templateId}". Rendering nodes without the template wrapper.`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
</script>
|
|
81
|
-
|
|
82
|
-
{#if template && templateConfig && composed}
|
|
83
|
-
{@const Tpl = templateConfig.component}
|
|
84
|
-
<Tpl {...composed} {children} />
|
|
85
|
-
{:else}
|
|
86
|
-
{@render children()}
|
|
87
|
-
{/if}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from 'svelte';
|
|
2
|
-
import type { PortableTemplate } from '@contentful/experiences-sdk-core';
|
|
3
|
-
import { type Config, type RenderContext } from './types.js';
|
|
4
|
-
interface WrapWithTemplateProps {
|
|
5
|
-
template: PortableTemplate | undefined;
|
|
6
|
-
config: Config;
|
|
7
|
-
experience: RenderContext;
|
|
8
|
-
children: Snippet;
|
|
9
|
-
}
|
|
10
|
-
declare const WrapWithTemplate: import("svelte").Component<WrapWithTemplateProps, {}, "">;
|
|
11
|
-
type WrapWithTemplate = ReturnType<typeof WrapWithTemplate>;
|
|
12
|
-
export default WrapWithTemplate;
|
|
13
|
-
//# sourceMappingURL=WrapWithTemplate.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WrapWithTemplate.svelte.d.ts","sourceRoot":"","sources":["../src/WrapWithTemplate.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAGpB,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,aAAa,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;CACnB;AA0EH,QAAA,MAAM,gBAAgB,2DAAwC,CAAC;AAC/D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC5D,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from 'svelte';
|
|
2
|
-
type $$ComponentProps = {
|
|
3
|
-
title?: string;
|
|
4
|
-
children: Snippet;
|
|
5
|
-
};
|
|
6
|
-
declare const TemplateFixture: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
-
type TemplateFixture = ReturnType<typeof TemplateFixture>;
|
|
8
|
-
export default TemplateFixture;
|
|
9
|
-
//# sourceMappingURL=TemplateFixture.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateFixture.svelte.d.ts","sourceRoot":"","sources":["../../src/test-fixtures/TemplateFixture.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAIrC,KAAK,gBAAgB,GAAI;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAmBJ,QAAA,MAAM,eAAe,sDAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|