@datocms/svelte 0.0.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/components/Head/Head.svelte +14 -0
  4. package/components/Head/Head.svelte.d.ts +61 -0
  5. package/components/Head/README.md +68 -0
  6. package/components/Head/__tests__/Head.test.d.ts +1 -0
  7. package/components/Head/__tests__/Head.test.js +11 -0
  8. package/components/Head/__tests__/__fixtures__/head.d.ts +2 -0
  9. package/components/Head/__tests__/__fixtures__/head.js +280 -0
  10. package/components/Head/__tests__/__snapshots__/Head.test.ts.snap +221 -0
  11. package/components/Image/Image.svelte +172 -0
  12. package/components/Image/Image.svelte.d.ts +83 -0
  13. package/components/Image/Placeholder.svelte +31 -0
  14. package/components/Image/Placeholder.svelte.d.ts +22 -0
  15. package/components/Image/README.md +167 -0
  16. package/components/Image/Sizer.svelte +17 -0
  17. package/components/Image/Sizer.svelte.d.ts +19 -0
  18. package/components/Image/Source.svelte +6 -0
  19. package/components/Image/Source.svelte.d.ts +18 -0
  20. package/components/Image/__tests__/Image.svelte.test.d.ts +1 -0
  21. package/components/Image/__tests__/Image.svelte.test.js +44 -0
  22. package/components/Image/__tests__/__fixtures__/image.d.ts +40 -0
  23. package/components/Image/__tests__/__fixtures__/image.js +40 -0
  24. package/components/Image/__tests__/__snapshots__/Image.svelte.test.ts.snap +927 -0
  25. package/components/StructuredText/Node.svelte +112 -0
  26. package/components/StructuredText/Node.svelte.d.ts +22 -0
  27. package/components/StructuredText/README.md +201 -0
  28. package/components/StructuredText/StructuredText.svelte +15 -0
  29. package/components/StructuredText/StructuredText.svelte.d.ts +19 -0
  30. package/components/StructuredText/__tests__/StructuredText.svelte.test.d.ts +1 -0
  31. package/components/StructuredText/__tests__/StructuredText.svelte.test.js +163 -0
  32. package/components/StructuredText/__tests__/__fixtures__/Block.svelte +11 -0
  33. package/components/StructuredText/__tests__/__fixtures__/Block.svelte.d.ts +19 -0
  34. package/components/StructuredText/__tests__/__fixtures__/CustomSpan.svelte +49 -0
  35. package/components/StructuredText/__tests__/__fixtures__/CustomSpan.svelte.d.ts +19 -0
  36. package/components/StructuredText/__tests__/__fixtures__/IncreasedLevelHeading.svelte +8 -0
  37. package/components/StructuredText/__tests__/__fixtures__/IncreasedLevelHeading.svelte.d.ts +19 -0
  38. package/components/StructuredText/__tests__/__fixtures__/InlineItem.svelte +8 -0
  39. package/components/StructuredText/__tests__/__fixtures__/InlineItem.svelte.d.ts +19 -0
  40. package/components/StructuredText/__tests__/__fixtures__/ItemLink.svelte +15 -0
  41. package/components/StructuredText/__tests__/__fixtures__/ItemLink.svelte.d.ts +21 -0
  42. package/components/StructuredText/__tests__/__fixtures__/structuredText.d.ts +6 -0
  43. package/components/StructuredText/__tests__/__fixtures__/structuredText.js +537 -0
  44. package/components/StructuredText/__tests__/__fixtures__/types.d.ts +27 -0
  45. package/components/StructuredText/__tests__/__fixtures__/types.js +1 -0
  46. package/components/StructuredText/__tests__/__snapshots__/StructuredText.svelte.test.ts.snap +463 -0
  47. package/components/StructuredText/nodes/Blockquote.svelte +5 -0
  48. package/components/StructuredText/nodes/Blockquote.svelte.d.ts +19 -0
  49. package/components/StructuredText/nodes/Code.svelte +6 -0
  50. package/components/StructuredText/nodes/Code.svelte.d.ts +17 -0
  51. package/components/StructuredText/nodes/Heading.svelte +8 -0
  52. package/components/StructuredText/nodes/Heading.svelte.d.ts +19 -0
  53. package/components/StructuredText/nodes/Link.svelte +6 -0
  54. package/components/StructuredText/nodes/Link.svelte.d.ts +19 -0
  55. package/components/StructuredText/nodes/List.svelte +10 -0
  56. package/components/StructuredText/nodes/List.svelte.d.ts +19 -0
  57. package/components/StructuredText/nodes/ListItem.svelte +5 -0
  58. package/components/StructuredText/nodes/ListItem.svelte.d.ts +19 -0
  59. package/components/StructuredText/nodes/Paragraph.svelte +5 -0
  60. package/components/StructuredText/nodes/Paragraph.svelte.d.ts +19 -0
  61. package/components/StructuredText/nodes/Root.svelte +5 -0
  62. package/components/StructuredText/nodes/Root.svelte.d.ts +19 -0
  63. package/components/StructuredText/nodes/Span.svelte +49 -0
  64. package/components/StructuredText/nodes/Span.svelte.d.ts +19 -0
  65. package/components/StructuredText/nodes/ThematicBreak.svelte +5 -0
  66. package/components/StructuredText/nodes/ThematicBreak.svelte.d.ts +17 -0
  67. package/components/StructuredText/utils/Lines.svelte +11 -0
  68. package/components/StructuredText/utils/Lines.svelte.d.ts +16 -0
  69. package/index.d.ts +9 -0
  70. package/index.js +3 -0
  71. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 DatoCMS
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 ADDED
@@ -0,0 +1,51 @@
1
+ # @datocms/svelte
2
+
3
+ ![MIT](https://img.shields.io/npm/l/@datocms/svelte?style=for-the-badge) ![NPM](https://img.shields.io/npm/v/@datocms/svelte?style=for-the-badge) [![Build Status](https://img.shields.io/github/actions/workflow/status/datocms/datocms-svelte/node.js.yml?branch=main&style=for-the-badge)](https://github.com/datocms/datocms-svelte/actions/workflows/node.js.yml)
4
+
5
+ A set of components to work faster with [DatoCMS](https://www.datocms.com/) in Svelte projects.
6
+
7
+ - Works with Svelte and SvelteKit;
8
+ - Written in TypeScript;
9
+ - Usable both client and server side;
10
+
11
+ <br /><br />
12
+ <a href="https://www.datocms.com/">
13
+ <img src="https://www.datocms.com/images/full_logo.svg" height="60">
14
+ </a>
15
+ <br /><br />
16
+
17
+ ## Table of Contents
18
+
19
+ - [Features](#features)
20
+ - [Installation](#installation)
21
+ - [Development](#development)
22
+
23
+ ## Features
24
+
25
+ `@datocms/svelte` contains ready-to-use Svelte components and usage examples.
26
+
27
+ Components:
28
+
29
+ - [`<Image />`](src/lib/components/Image)
30
+ - [`<StructuredText />`](src/lib/components/StructuredText)
31
+ - [`<Head />`](src/lib/components/Head)
32
+
33
+ ## Installation
34
+
35
+ ```
36
+ npm install @datocms/svelte
37
+ ```
38
+ ## Development
39
+
40
+ This repository contains some examples in the `app/routes` folder. You can use them to locally test your changes to the package:
41
+
42
+ ```bash
43
+ npm run dev
44
+ ```
45
+ ## Building
46
+
47
+ To create a production version of this library:
48
+
49
+ ```bash
50
+ npm run build
51
+ ```
@@ -0,0 +1,14 @@
1
+ <script context="module"></script>
2
+
3
+ <script>export let data = [];
4
+ </script>
5
+
6
+ <svelte:head>
7
+ {#each data as { tag, attributes, content }}
8
+ {#if content}
9
+ <svelte:element this={tag} {...attributes}>{content}</svelte:element>
10
+ {:else}
11
+ <svelte:element this={tag} {...attributes} />
12
+ {/if}
13
+ {/each}
14
+ </svelte:head>
@@ -0,0 +1,61 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ export interface TitleMetaLinkTag {
3
+ /** the tag for the meta information */
4
+ tag: string;
5
+ /** the inner content of the meta tag */
6
+ content?: string | null | undefined;
7
+ /** the HTML attributes to attach to the meta tag */
8
+ attributes?: Record<string, string> | null | undefined;
9
+ }
10
+ export interface SeoTitleTag {
11
+ tag: 'title';
12
+ content: string | null;
13
+ attributes?: null;
14
+ }
15
+ export interface RegularMetaAttributes {
16
+ name: string;
17
+ content: string;
18
+ }
19
+ export interface OgMetaAttributes {
20
+ property: string;
21
+ content: string;
22
+ }
23
+ export interface SeoMetaTag {
24
+ tag: 'meta';
25
+ content?: null;
26
+ attributes: RegularMetaAttributes | OgMetaAttributes;
27
+ }
28
+ export interface FaviconAttributes {
29
+ sizes: string;
30
+ type: string;
31
+ rel: string;
32
+ href: string;
33
+ }
34
+ export interface AppleTouchIconAttributes {
35
+ sizes: string;
36
+ rel: 'apple-touch-icon';
37
+ href: string;
38
+ }
39
+ export interface SeoLinkTag {
40
+ tag: 'link';
41
+ content?: null;
42
+ attributes: FaviconAttributes | AppleTouchIconAttributes;
43
+ }
44
+ export type SeoTag = SeoTitleTag | SeoMetaTag;
45
+ export type FaviconTag = SeoMetaTag | SeoLinkTag;
46
+ export type SeoOrFaviconTag = SeoTag | FaviconTag;
47
+ declare const __propDef: {
48
+ props: {
49
+ data?: (TitleMetaLinkTag | SeoOrFaviconTag)[] | undefined;
50
+ };
51
+ events: {
52
+ [evt: string]: CustomEvent<any>;
53
+ };
54
+ slots: {};
55
+ };
56
+ export type HeadProps = typeof __propDef.props;
57
+ export type HeadEvents = typeof __propDef.events;
58
+ export type HeadSlots = typeof __propDef.slots;
59
+ export default class Head extends SvelteComponentTyped<HeadProps, HeadEvents, HeadSlots> {
60
+ }
61
+ export {};
@@ -0,0 +1,68 @@
1
+ ## Social share, SEO and Favicon meta tags
2
+
3
+ Just like the image component, `<Head />` is a component specially designed to work seamlessly with DatoCMS’s [`_seoMetaTags` and `faviconMetaTags` GraphQL queries](https://www.datocms.com/docs/content-delivery-api/seo) so that you can handle proper SEO in your pages.
4
+
5
+ You can use `<Head />` your components, and it will inject title, meta and link tags in the document's `<head></head>` tag.
6
+
7
+ ### Table of contents
8
+
9
+ - [Usage](#usage)
10
+ - [Example](#example)
11
+
12
+ ### Usage
13
+
14
+ `<Head />`'s `data` prop takes an array of `Tag`s in the exact form they're returned by the following [DatoCMS GraphQL API](https://www.datocms.com/docs/content-delivery-api/seo) queries:
15
+
16
+ - `_seoMetaTags` query on any record, or
17
+ - `faviconMetaTags` on the global `_site` object.
18
+
19
+ ### Example
20
+
21
+ Here is an example:
22
+
23
+ ```svelte
24
+ <script>
25
+ import { onMount } from 'svelte';
26
+
27
+ import { Head } from '@datocms/svelte';
28
+
29
+ const query = gql`
30
+ query {
31
+ page: homepage {
32
+ title
33
+ seo: _seoMetaTags {
34
+ attributes
35
+ content
36
+ tag
37
+ }
38
+ }
39
+ site: _site {
40
+ favicon: faviconMetaTags {
41
+ attributes
42
+ content
43
+ tag
44
+ }
45
+ }
46
+ }
47
+ `;
48
+
49
+ export let data = null;
50
+
51
+ onMount(async () => {
52
+ const response = await fetch('https://graphql.datocms.com/', {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json',
56
+ Authorization: 'Bearer faeb9172e232a75339242faafb9e56de8c8f13b735f7090964'
57
+ },
58
+ body: JSON.stringify({ query })
59
+ });
60
+
61
+ const json = await response.json();
62
+
63
+ data = [...json.data.page.seo, ...json.data.site.favicon];
64
+ });
65
+ </script>
66
+
67
+ <Head {data} />
68
+ ```
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,11 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import '@testing-library/jest-dom';
3
+ import { render, } from '@testing-library/svelte';
4
+ import { Head } from '../../..';
5
+ import { metaTags } from './__fixtures__/head';
6
+ describe('Head', () => {
7
+ it('renders meta tags', () => {
8
+ const { container } = render(Head, { props: { data: metaTags } });
9
+ expect(container.ownerDocument.head).toMatchSnapshot();
10
+ });
11
+ });
@@ -0,0 +1,2 @@
1
+ import type { TitleMetaLinkTag } from '../../Head.svelte';
2
+ export declare const metaTags: TitleMetaLinkTag[];
@@ -0,0 +1,280 @@
1
+ export const metaTags = [
2
+ {
3
+ content: 'Remix CMS - The easiest way to manage content with Remix',
4
+ attributes: null,
5
+ tag: 'title'
6
+ },
7
+ {
8
+ content: null,
9
+ attributes: {
10
+ property: 'og:title',
11
+ content: 'Remix CMS - The easiest way to manage content with Remix'
12
+ },
13
+ tag: 'meta'
14
+ },
15
+ {
16
+ content: null,
17
+ attributes: {
18
+ name: 'twitter:title',
19
+ content: 'Remix CMS - The easiest way to manage content with Remix'
20
+ },
21
+ tag: 'meta'
22
+ },
23
+ {
24
+ content: null,
25
+ attributes: {
26
+ name: 'description',
27
+ content: 'Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now.'
28
+ },
29
+ tag: 'meta'
30
+ },
31
+ {
32
+ content: null,
33
+ attributes: {
34
+ property: 'og:description',
35
+ content: 'Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now.'
36
+ },
37
+ tag: 'meta'
38
+ },
39
+ {
40
+ content: null,
41
+ attributes: {
42
+ name: 'twitter:description',
43
+ content: 'Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now.'
44
+ },
45
+ tag: 'meta'
46
+ },
47
+ {
48
+ content: null,
49
+ attributes: {
50
+ property: 'og:image',
51
+ content: 'https://www.datocms-assets.com/205/1642515293-full-logo.svg?fit=max&fm=jpg&w=1000'
52
+ },
53
+ tag: 'meta'
54
+ },
55
+ {
56
+ content: null,
57
+ attributes: {
58
+ property: 'og:image:width',
59
+ content: '746'
60
+ },
61
+ tag: 'meta'
62
+ },
63
+ {
64
+ content: null,
65
+ attributes: {
66
+ property: 'og:image:height',
67
+ content: '186'
68
+ },
69
+ tag: 'meta'
70
+ },
71
+ {
72
+ content: null,
73
+ attributes: {
74
+ name: 'twitter:image',
75
+ content: 'https://www.datocms-assets.com/205/1642515293-full-logo.svg?fit=max&fm=jpg&w=1000'
76
+ },
77
+ tag: 'meta'
78
+ },
79
+ {
80
+ content: null,
81
+ attributes: {
82
+ property: 'og:locale',
83
+ content: 'en'
84
+ },
85
+ tag: 'meta'
86
+ },
87
+ {
88
+ content: null,
89
+ attributes: {
90
+ property: 'og:type',
91
+ content: 'article'
92
+ },
93
+ tag: 'meta'
94
+ },
95
+ {
96
+ content: null,
97
+ attributes: {
98
+ property: 'og:site_name',
99
+ content: 'DatoCMS'
100
+ },
101
+ tag: 'meta'
102
+ },
103
+ {
104
+ content: null,
105
+ attributes: {
106
+ property: 'article:modified_time',
107
+ content: '2022-01-18T14:02:47Z'
108
+ },
109
+ tag: 'meta'
110
+ },
111
+ {
112
+ content: null,
113
+ attributes: {
114
+ name: 'twitter:card',
115
+ content: 'summary_large_image'
116
+ },
117
+ tag: 'meta'
118
+ },
119
+ {
120
+ content: null,
121
+ attributes: {
122
+ name: 'twitter:site',
123
+ content: '@datocms'
124
+ },
125
+ tag: 'meta'
126
+ },
127
+ {
128
+ attributes: {
129
+ sizes: '16x16',
130
+ type: 'image/png',
131
+ rel: 'icon',
132
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=16&w=16'
133
+ },
134
+ content: null,
135
+ tag: 'link'
136
+ },
137
+ {
138
+ attributes: {
139
+ sizes: '32x32',
140
+ type: 'image/png',
141
+ rel: 'icon',
142
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=32&w=32'
143
+ },
144
+ content: null,
145
+ tag: 'link'
146
+ },
147
+ {
148
+ attributes: {
149
+ sizes: '96x96',
150
+ type: 'image/png',
151
+ rel: 'icon',
152
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=96&w=96'
153
+ },
154
+ content: null,
155
+ tag: 'link'
156
+ },
157
+ {
158
+ attributes: {
159
+ sizes: '192x192',
160
+ type: 'image/png',
161
+ rel: 'icon',
162
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=192&w=192'
163
+ },
164
+ content: null,
165
+ tag: 'link'
166
+ },
167
+ {
168
+ attributes: {
169
+ sizes: '57x57',
170
+ rel: 'apple-touch-icon',
171
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=57&w=57'
172
+ },
173
+ content: null,
174
+ tag: 'link'
175
+ },
176
+ {
177
+ attributes: {
178
+ sizes: '60x60',
179
+ rel: 'apple-touch-icon',
180
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=60&w=60'
181
+ },
182
+ content: null,
183
+ tag: 'link'
184
+ },
185
+ {
186
+ attributes: {
187
+ sizes: '72x72',
188
+ rel: 'apple-touch-icon',
189
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=72&w=72'
190
+ },
191
+ content: null,
192
+ tag: 'link'
193
+ },
194
+ {
195
+ attributes: {
196
+ sizes: '76x76',
197
+ rel: 'apple-touch-icon',
198
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=76&w=76'
199
+ },
200
+ content: null,
201
+ tag: 'link'
202
+ },
203
+ {
204
+ attributes: {
205
+ sizes: '114x114',
206
+ rel: 'apple-touch-icon',
207
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=114&w=114'
208
+ },
209
+ content: null,
210
+ tag: 'link'
211
+ },
212
+ {
213
+ attributes: {
214
+ sizes: '120x120',
215
+ rel: 'apple-touch-icon',
216
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=120&w=120'
217
+ },
218
+ content: null,
219
+ tag: 'link'
220
+ },
221
+ {
222
+ attributes: {
223
+ sizes: '144x144',
224
+ rel: 'apple-touch-icon',
225
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=144&w=144'
226
+ },
227
+ content: null,
228
+ tag: 'link'
229
+ },
230
+ {
231
+ attributes: {
232
+ sizes: '152x152',
233
+ rel: 'apple-touch-icon',
234
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=152&w=152'
235
+ },
236
+ content: null,
237
+ tag: 'link'
238
+ },
239
+ {
240
+ attributes: {
241
+ sizes: '180x180',
242
+ rel: 'apple-touch-icon',
243
+ href: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=180&w=180'
244
+ },
245
+ content: null,
246
+ tag: 'link'
247
+ },
248
+ {
249
+ attributes: {
250
+ name: 'msapplication-square70x70logo',
251
+ content: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=70&w=70'
252
+ },
253
+ content: null,
254
+ tag: 'meta'
255
+ },
256
+ {
257
+ attributes: {
258
+ name: 'msapplication-square150x150logo',
259
+ content: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=150&w=150'
260
+ },
261
+ content: null,
262
+ tag: 'meta'
263
+ },
264
+ {
265
+ attributes: {
266
+ name: 'msapplication-square310x310logo',
267
+ content: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=310&w=310'
268
+ },
269
+ content: null,
270
+ tag: 'meta'
271
+ },
272
+ {
273
+ attributes: {
274
+ name: 'msapplication-square310x150logo',
275
+ content: 'https://www.datocms-assets.com/205/1525789775-dato.png?h=150&w=310'
276
+ },
277
+ content: null,
278
+ tag: 'meta'
279
+ }
280
+ ];