@django-stack/svelte 0.0.0-stage → 0.4.0
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/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/Blocks.svelte +35 -0
- package/dist/Blocks.svelte.d.ts +11 -0
- package/dist/Image.svelte +32 -0
- package/dist/Image.svelte.d.ts +14 -0
- package/dist/RichText.svelte +16 -0
- package/dist/RichText.svelte.d.ts +7 -0
- package/dist/Seo.svelte +30 -0
- package/dist/Seo.svelte.d.ts +13 -0
- package/dist/blocks/CallToActionBlock.svelte +13 -0
- package/dist/blocks/CallToActionBlock.svelte.d.ts +7 -0
- package/dist/blocks/ImageBlock.svelte +13 -0
- package/dist/blocks/ImageBlock.svelte.d.ts +7 -0
- package/dist/blocks/QuoteBlock.svelte +12 -0
- package/dist/blocks/QuoteBlock.svelte.d.ts +7 -0
- package/dist/blocks/TextBlock.svelte +8 -0
- package/dist/blocks/TextBlock.svelte.d.ts +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/package.json +58 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leon van der Grient
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @django-stack/svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte components for DjangoStack frontends: blocks, rich text, images and
|
|
4
|
+
SEO tags, for content from Django Headless and Django Content Studio.
|
|
5
|
+
|
|
6
|
+
Part of [DjangoStack](https://github.com/dwarsbit/django-stack). The
|
|
7
|
+
SvelteKit frontend of `npx @django-stack/cli init --frontend sveltekit`
|
|
8
|
+
uses it.
|
|
9
|
+
|
|
10
|
+
```svelte
|
|
11
|
+
<!-- src/routes/[...path]/+page.svelte -->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Blocks } from "@django-stack/svelte";
|
|
14
|
+
import Gallery from "$lib/components/Gallery.svelte";
|
|
15
|
+
|
|
16
|
+
let { data } = $props();
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<h1>{data.page.title}</h1>
|
|
20
|
+
<Blocks blocks={data.page.body} components={{ gallery: Gallery }} />
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
| Component | What it renders |
|
|
24
|
+
|-----------|-----------------|
|
|
25
|
+
| `Blocks` | A block field. `components` adds or replaces block types; unknown types render nothing. |
|
|
26
|
+
| `RichText` | HTML from an `HTMLField`, which Django sanitizes when it is saved. |
|
|
27
|
+
| `Image` | A responsive `<img>` with `srcset` from the image sizes and the focal point. |
|
|
28
|
+
| `Seo` | The title, description, canonical URL, Open Graph and Twitter tags, in `<svelte:head>`. |
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Renders a Content Studio block field. `components` maps a block type to a
|
|
3
|
+
component that takes a `block` prop; it adds types or replaces the
|
|
4
|
+
built-in ones. Unknown types render nothing.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Block } from "@django-stack/utils";
|
|
8
|
+
import type { Component } from "svelte";
|
|
9
|
+
import CallToActionBlock from "./blocks/CallToActionBlock.svelte";
|
|
10
|
+
import ImageBlock from "./blocks/ImageBlock.svelte";
|
|
11
|
+
import QuoteBlock from "./blocks/QuoteBlock.svelte";
|
|
12
|
+
import TextBlock from "./blocks/TextBlock.svelte";
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
blocks: Block[] | null | undefined;
|
|
16
|
+
components?: Record<string, Component<{ block: any }>>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let { blocks, components = {} }: Props = $props();
|
|
20
|
+
|
|
21
|
+
const registry = $derived<Record<string, Component<{ block: any }>>>({
|
|
22
|
+
text: TextBlock,
|
|
23
|
+
image: ImageBlock,
|
|
24
|
+
quote: QuoteBlock,
|
|
25
|
+
call_to_action: CallToActionBlock,
|
|
26
|
+
...components,
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#each blocks ?? [] as block (block.id)}
|
|
31
|
+
{@const BlockComponent = registry[block.type]}
|
|
32
|
+
{#if BlockComponent}
|
|
33
|
+
<BlockComponent {block} />
|
|
34
|
+
{/if}
|
|
35
|
+
{/each}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Block } from "@django-stack/utils";
|
|
2
|
+
import type { Component } from "svelte";
|
|
3
|
+
interface Props {
|
|
4
|
+
blocks: Block[] | null | undefined;
|
|
5
|
+
components?: Record<string, Component<{
|
|
6
|
+
block: any;
|
|
7
|
+
}>>;
|
|
8
|
+
}
|
|
9
|
+
declare const Blocks: Component<Props, {}, "">;
|
|
10
|
+
type Blocks = ReturnType<typeof Blocks>;
|
|
11
|
+
export default Blocks;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { imageAttributes, type Media } from "@django-stack/utils";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
media: Media | string | null | undefined;
|
|
6
|
+
/** An image size from IMAGE_SIZES, such as card or hero. */
|
|
7
|
+
size?: string;
|
|
8
|
+
/** The sizes attribute, for the browser to pick from the srcset. */
|
|
9
|
+
sizes?: string;
|
|
10
|
+
alt?: string;
|
|
11
|
+
class?: string;
|
|
12
|
+
eager?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let { media, size, sizes = "100vw", alt, class: className, eager = false }: Props = $props();
|
|
16
|
+
const attributes = $derived(imageAttributes(media, { size, alt }));
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#if attributes}
|
|
20
|
+
<img
|
|
21
|
+
src={attributes.src}
|
|
22
|
+
srcset={attributes.srcset}
|
|
23
|
+
sizes={attributes.srcset ? sizes : undefined}
|
|
24
|
+
width={attributes.width}
|
|
25
|
+
height={attributes.height}
|
|
26
|
+
alt={attributes.alt}
|
|
27
|
+
class={className}
|
|
28
|
+
style:object-position={attributes.objectPosition}
|
|
29
|
+
loading={eager ? "eager" : "lazy"}
|
|
30
|
+
decoding="async"
|
|
31
|
+
/>
|
|
32
|
+
{/if}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Media } from "@django-stack/utils";
|
|
2
|
+
interface Props {
|
|
3
|
+
media: Media | string | null | undefined;
|
|
4
|
+
/** An image size from IMAGE_SIZES, such as card or hero. */
|
|
5
|
+
size?: string;
|
|
6
|
+
/** The sizes attribute, for the browser to pick from the srcset. */
|
|
7
|
+
sizes?: string;
|
|
8
|
+
alt?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
eager?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const Image: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type Image = ReturnType<typeof Image>;
|
|
14
|
+
export default Image;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
HTML from a Content Studio HTMLField. Django sanitizes it with an
|
|
3
|
+
allowlist when it is saved, so it is safe to render as is.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
interface Props {
|
|
7
|
+
html: string | null | undefined;
|
|
8
|
+
class?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let { html, class: className = "prose" }: Props = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
{#if html}
|
|
15
|
+
<div class={className}>{@html html}</div>
|
|
16
|
+
{/if}
|
package/dist/Seo.svelte
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { type SeoInput, type SiteSettings, seo } from "@django-stack/utils";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
page?: SeoInput | null;
|
|
6
|
+
settings: SiteSettings | null;
|
|
7
|
+
/** The site's public URL, such as https://example.com. */
|
|
8
|
+
siteUrl: string;
|
|
9
|
+
/** The path of the page, for the canonical URL. */
|
|
10
|
+
path: string;
|
|
11
|
+
type?: "website" | "article";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let { page, settings, siteUrl, path, type }: Props = $props();
|
|
15
|
+
const meta = $derived(seo({ page, settings, siteUrl, path, type }));
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<svelte:head>
|
|
19
|
+
<title>{meta.title}</title>
|
|
20
|
+
{#if meta.description}
|
|
21
|
+
<meta name="description" content={meta.description} />
|
|
22
|
+
{/if}
|
|
23
|
+
<link rel="canonical" href={meta.canonical} />
|
|
24
|
+
{#each Object.entries(meta.openGraph) as [property, content] (property)}
|
|
25
|
+
<meta {property} {content} />
|
|
26
|
+
{/each}
|
|
27
|
+
{#each Object.entries(meta.twitter) as [name, content] (name)}
|
|
28
|
+
<meta {name} {content} />
|
|
29
|
+
{/each}
|
|
30
|
+
</svelte:head>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type SeoInput, type SiteSettings } from "@django-stack/utils";
|
|
2
|
+
interface Props {
|
|
3
|
+
page?: SeoInput | null;
|
|
4
|
+
settings: SiteSettings | null;
|
|
5
|
+
/** The site's public URL, such as https://example.com. */
|
|
6
|
+
siteUrl: string;
|
|
7
|
+
/** The path of the page, for the canonical URL. */
|
|
8
|
+
path: string;
|
|
9
|
+
type?: "website" | "article";
|
|
10
|
+
}
|
|
11
|
+
declare const Seo: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type Seo = ReturnType<typeof Seo>;
|
|
13
|
+
export default Seo;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { CallToActionBlock } from "@django-stack/utils";
|
|
3
|
+
|
|
4
|
+
let { block }: { block: CallToActionBlock } = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<aside class="cta">
|
|
8
|
+
<h2>{block.value.title}</h2>
|
|
9
|
+
{#if block.value.text}
|
|
10
|
+
<p>{block.value.text}</p>
|
|
11
|
+
{/if}
|
|
12
|
+
<a class="button" href={block.value.button_url}>{block.value.button_label}</a>
|
|
13
|
+
</aside>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CallToActionBlock } from "@django-stack/utils";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
block: CallToActionBlock;
|
|
4
|
+
};
|
|
5
|
+
declare const CallToActionBlock: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type CallToActionBlock = ReturnType<typeof CallToActionBlock>;
|
|
7
|
+
export default CallToActionBlock;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ImageBlock } from "@django-stack/utils";
|
|
3
|
+
import Image from "../Image.svelte";
|
|
4
|
+
|
|
5
|
+
let { block }: { block: ImageBlock } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<figure class="block-image">
|
|
9
|
+
<Image media={block.value.image} size="content" sizes="(min-width: 48rem) 44rem, 100vw" />
|
|
10
|
+
{#if block.value.caption}
|
|
11
|
+
<figcaption class="muted">{block.value.caption}</figcaption>
|
|
12
|
+
{/if}
|
|
13
|
+
</figure>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ImageBlock } from "@django-stack/utils";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
block: ImageBlock;
|
|
4
|
+
};
|
|
5
|
+
declare const ImageBlock: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type ImageBlock = ReturnType<typeof ImageBlock>;
|
|
7
|
+
export default ImageBlock;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { QuoteBlock } from "@django-stack/utils";
|
|
3
|
+
|
|
4
|
+
let { block }: { block: QuoteBlock } = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<blockquote class="prose">
|
|
8
|
+
<p>{block.value.text}</p>
|
|
9
|
+
{#if block.value.attribution}
|
|
10
|
+
<footer class="muted">{block.value.attribution}</footer>
|
|
11
|
+
{/if}
|
|
12
|
+
</blockquote>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QuoteBlock } from "@django-stack/utils";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
block: QuoteBlock;
|
|
4
|
+
};
|
|
5
|
+
declare const QuoteBlock: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type QuoteBlock = ReturnType<typeof QuoteBlock>;
|
|
7
|
+
export default QuoteBlock;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Blocks } from "./Blocks.svelte";
|
|
2
|
+
export { default as CallToActionBlock } from "./blocks/CallToActionBlock.svelte";
|
|
3
|
+
export { default as ImageBlock } from "./blocks/ImageBlock.svelte";
|
|
4
|
+
export { default as QuoteBlock } from "./blocks/QuoteBlock.svelte";
|
|
5
|
+
export { default as TextBlock } from "./blocks/TextBlock.svelte";
|
|
6
|
+
export { default as Image } from "./Image.svelte";
|
|
7
|
+
export { default as RichText } from "./RichText.svelte";
|
|
8
|
+
export { default as Seo } from "./Seo.svelte";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Blocks } from "./Blocks.svelte";
|
|
2
|
+
export { default as CallToActionBlock } from "./blocks/CallToActionBlock.svelte";
|
|
3
|
+
export { default as ImageBlock } from "./blocks/ImageBlock.svelte";
|
|
4
|
+
export { default as QuoteBlock } from "./blocks/QuoteBlock.svelte";
|
|
5
|
+
export { default as TextBlock } from "./blocks/TextBlock.svelte";
|
|
6
|
+
export { default as Image } from "./Image.svelte";
|
|
7
|
+
export { default as RichText } from "./RichText.svelte";
|
|
8
|
+
export { default as Seo } from "./Seo.svelte";
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@django-stack/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Svelte components for DjangoStack frontends: blocks, rich text, images and SEO.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Leon van der Grient",
|
|
7
|
+
"homepage": "https://github.com/dwarsbit/django-stack/tree/main/packages/svelte#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/dwarsbit/django-stack.git",
|
|
11
|
+
"directory": "packages/svelte"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/dwarsbit/django-stack/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"django",
|
|
16
|
+
"django-stack",
|
|
17
|
+
"headless-cms",
|
|
18
|
+
"svelte",
|
|
19
|
+
"sveltekit"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"svelte": "./dist/index.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"svelte": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"svelte": "^5.0.0",
|
|
42
|
+
"@django-stack/utils": "^0.4.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@sveltejs/package": "^3.0.2",
|
|
46
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
47
|
+
"svelte": "^5.57.3",
|
|
48
|
+
"svelte-check": "^4.7.8",
|
|
49
|
+
"typescript": "~6.0.3",
|
|
50
|
+
"vite": "^8.3.0",
|
|
51
|
+
"@django-stack/utils": "0.4.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "svelte-package --input src --output dist",
|
|
58
|
+
"typecheck": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings",
|
|
59
|
+
"test": "vitest run"
|
|
60
|
+
}
|
|
6
61
|
}
|