@datocms/svelte 1.1.1 → 1.2.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/components/Head/Head.svelte.d.ts +1 -1
- package/components/StructuredText/__tests__/StructuredText.svelte.test.js +9 -1
- package/components/StructuredText/__tests__/__fixtures__/structuredText.d.ts +1 -0
- package/components/StructuredText/__tests__/__fixtures__/structuredText.js +38 -0
- package/components/StructuredText/__tests__/__snapshots__/StructuredText.svelte.test.ts.snap +68 -0
- package/components/StructuredText/nodes/Link.svelte +16 -2
- package/package.json +21 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
export interface TitleMetaLinkTag {
|
|
3
3
|
/** the tag for the meta information */
|
|
4
|
-
tag:
|
|
4
|
+
tag: "title" | "meta" | "link";
|
|
5
5
|
/** the inner content of the meta tag */
|
|
6
6
|
content?: string | null | undefined;
|
|
7
7
|
/** the HTML attributes to attach to the meta tag */
|
|
@@ -3,7 +3,7 @@ import '@testing-library/jest-dom';
|
|
|
3
3
|
import { render } from '@testing-library/svelte';
|
|
4
4
|
import { isBlock, isHeading, isInlineItem, isItemLink, isSpan } from 'datocms-structured-text-utils';
|
|
5
5
|
import { StructuredText } from '../../..';
|
|
6
|
-
import { heading, structuredTextWithBlocksAndLinks } from './__fixtures__/structuredText';
|
|
6
|
+
import { heading, paragraphWithLink, structuredTextWithBlocksAndLinks } from './__fixtures__/structuredText';
|
|
7
7
|
import CustomSpan from './__fixtures__/CustomSpan.svelte';
|
|
8
8
|
import IncreasedLevelHeading from './__fixtures__/IncreasedLevelHeading.svelte';
|
|
9
9
|
import ItemLink from './__fixtures__/ItemLink.svelte';
|
|
@@ -48,6 +48,14 @@ describe('StructuredText', () => {
|
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
});
|
|
51
|
+
describe('with a dast which has a link inside', () => {
|
|
52
|
+
describe('with default rules', () => {
|
|
53
|
+
it('renders the document', () => {
|
|
54
|
+
const { container } = render(StructuredText, { props: { data: paragraphWithLink } });
|
|
55
|
+
expect(container).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
51
59
|
describe('with a dast with no links nor blocks', () => {
|
|
52
60
|
describe('with default rules', () => {
|
|
53
61
|
it('renders the document', () => {
|
|
@@ -2,5 +2,6 @@ import type { StructuredText } from 'datocms-structured-text-utils';
|
|
|
2
2
|
import type { BlogPostRecord, DocPageRecord, ImageRecord, QuoteRecord } from './types';
|
|
3
3
|
export declare const paragraph: StructuredText;
|
|
4
4
|
export declare const heading: StructuredText;
|
|
5
|
+
export declare const paragraphWithLink: StructuredText;
|
|
5
6
|
export declare const structuredTextWithBlocksAndLinks: StructuredText<QuoteRecord, DocPageRecord>;
|
|
6
7
|
export declare const full: StructuredText<ImageRecord | BlogPostRecord>;
|
|
@@ -47,6 +47,44 @@ export const heading = {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
export const paragraphWithLink = {
|
|
51
|
+
value: {
|
|
52
|
+
schema: 'dast',
|
|
53
|
+
document: {
|
|
54
|
+
type: 'root',
|
|
55
|
+
children: [
|
|
56
|
+
{
|
|
57
|
+
type: 'paragraph',
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
type: 'span',
|
|
61
|
+
value: 'This is a paragraph with a '
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
url: 'https://random.link',
|
|
65
|
+
type: 'link',
|
|
66
|
+
meta: [
|
|
67
|
+
{ id: 'rel', value: 'nofollow' },
|
|
68
|
+
{ id: 'foo', value: '123' },
|
|
69
|
+
{ id: 'target', value: '_blank' }
|
|
70
|
+
],
|
|
71
|
+
children: [
|
|
72
|
+
{
|
|
73
|
+
type: 'span',
|
|
74
|
+
value: 'very cool link'
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'span',
|
|
80
|
+
value: '. And the link has the target and the rel attributes set.'
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
50
88
|
export const structuredTextWithBlocksAndLinks = {
|
|
51
89
|
value: {
|
|
52
90
|
schema: 'dast',
|
package/components/StructuredText/__tests__/__snapshots__/StructuredText.svelte.test.ts.snap
CHANGED
|
@@ -111,6 +111,74 @@ exports[`StructuredText > with a dast including links and blocks > with missing
|
|
|
111
111
|
|
|
112
112
|
exports[`StructuredText > with a dast including links and blocks > with missing links > raises an error 1`] = `"The Structured Text document contains an 'itemLink' node, but cannot find a record with ID 123 inside data.links!"`;
|
|
113
113
|
|
|
114
|
+
exports[`StructuredText > with a dast which has a link inside > with default rules > renders the document 1`] = `
|
|
115
|
+
<body>
|
|
116
|
+
<div>
|
|
117
|
+
<p>
|
|
118
|
+
This is a paragraph with a
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
<!--<Lines>-->
|
|
122
|
+
|
|
123
|
+
<!--<Span>-->
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
<!--<Node>-->
|
|
128
|
+
<a
|
|
129
|
+
href="https://random.link"
|
|
130
|
+
rel="nofollow"
|
|
131
|
+
target="_blank"
|
|
132
|
+
>
|
|
133
|
+
very cool link
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
<!--<Lines>-->
|
|
137
|
+
|
|
138
|
+
<!--<Span>-->
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
<!--<Node>-->
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
</a>
|
|
146
|
+
<!--<Link>-->
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
<!--<Node>-->
|
|
151
|
+
. And the link has the target and the rel attributes set.
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
<!--<Lines>-->
|
|
155
|
+
|
|
156
|
+
<!--<Span>-->
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
<!--<Node>-->
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
</p>
|
|
164
|
+
<!--<Paragraph>-->
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
<!--<Node>-->
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
<!--<Root>-->
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
<!--<Node>-->
|
|
176
|
+
|
|
177
|
+
<!--<StructuredText>-->
|
|
178
|
+
</div>
|
|
179
|
+
</body>
|
|
180
|
+
`;
|
|
181
|
+
|
|
114
182
|
exports[`StructuredText > with a dast with no links nor blocks > with custom rules > renders the document 1`] = `
|
|
115
183
|
<body>
|
|
116
184
|
<div>
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
<script>export let node;
|
|
2
2
|
$:
|
|
3
|
-
({ url } = node);
|
|
3
|
+
({ url, meta } = node);
|
|
4
|
+
let target = void 0;
|
|
5
|
+
$: {
|
|
6
|
+
const targetMetaEntry = meta?.find((metaEntry) => metaEntry.id === "target");
|
|
7
|
+
if (targetMetaEntry?.value) {
|
|
8
|
+
target = targetMetaEntry.value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
let rel = void 0;
|
|
12
|
+
$: {
|
|
13
|
+
const relMetaEntry = meta?.find((metaEntry) => metaEntry.id === "rel");
|
|
14
|
+
if (relMetaEntry?.value) {
|
|
15
|
+
rel = relMetaEntry.value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
4
18
|
</script>
|
|
5
19
|
|
|
6
|
-
<a href={url}><slot /></a>
|
|
20
|
+
<a href={url} {target} {rel}><slot /></a>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datocms/svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A set of components and utilities to work faster with DatoCMS in Svelte",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,33 +14,33 @@
|
|
|
14
14
|
"datocms"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@sveltejs/adapter-auto": "^1.0.
|
|
18
|
-
"@sveltejs/kit": "
|
|
19
|
-
"@sveltejs/package": "^1.0.
|
|
20
|
-
"@testing-library/jest-dom": "^5.
|
|
17
|
+
"@sveltejs/adapter-auto": "^1.0.3",
|
|
18
|
+
"@sveltejs/kit": "^1.30.3",
|
|
19
|
+
"@sveltejs/package": "^1.0.2",
|
|
20
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
21
21
|
"@testing-library/svelte": "^3.2.2",
|
|
22
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
23
|
-
"@typescript-eslint/parser": "^5.
|
|
24
|
-
"csstype": "^3.1.
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
23
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
24
|
+
"csstype": "^3.1.3",
|
|
25
25
|
"datocms-structured-text-generic-html-renderer": "^2.0.4",
|
|
26
|
-
"eslint": "^8.
|
|
27
|
-
"eslint-config-prettier": "^8.
|
|
26
|
+
"eslint": "^8.56.0",
|
|
27
|
+
"eslint-config-prettier": "^8.10.0",
|
|
28
28
|
"eslint-plugin-svelte3": "^4.0.0",
|
|
29
|
-
"jsdom": "^21.1.
|
|
30
|
-
"jsdom-testing-mocks": "^1.
|
|
31
|
-
"prettier": "^2.8.
|
|
32
|
-
"prettier-plugin-svelte": "^2.
|
|
33
|
-
"svelte": "^3.
|
|
34
|
-
"svelte-check": "^3.
|
|
35
|
-
"tslib": "^2.
|
|
36
|
-
"typescript": "^4.9.
|
|
37
|
-
"vite": "^4.
|
|
38
|
-
"vitest": "^0.25.
|
|
29
|
+
"jsdom": "^21.1.2",
|
|
30
|
+
"jsdom-testing-mocks": "^1.11.0",
|
|
31
|
+
"prettier": "^2.8.8",
|
|
32
|
+
"prettier-plugin-svelte": "^2.10.1",
|
|
33
|
+
"svelte": "^3.59.2",
|
|
34
|
+
"svelte-check": "^3.6.2",
|
|
35
|
+
"tslib": "^2.6.2",
|
|
36
|
+
"typescript": "^4.9.5",
|
|
37
|
+
"vite": "^4.5.1",
|
|
38
|
+
"vitest": "^0.25.8"
|
|
39
39
|
},
|
|
40
40
|
"type": "module",
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"datocms-structured-text-utils": "^2.0.4",
|
|
43
|
-
"svelte-intersection-observer": "^0.10.
|
|
43
|
+
"svelte-intersection-observer": "^0.10.1",
|
|
44
44
|
"universal-base64": "^2.1.0"
|
|
45
45
|
},
|
|
46
46
|
"exports": {
|