fimo-sveltekit 2.4.1 → 2.5.0-staging.2
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/Boolean.svelte +2 -1
- package/components/Date.svelte +2 -1
- package/components/DateTime.svelte +2 -1
- package/components/Image.svelte +3 -2
- package/components/Json.svelte +2 -1
- package/components/Number.svelte +2 -1
- package/components/RichText.svelte +2 -1
- package/components/Text.svelte +3 -2
- package/components/Video.svelte +3 -2
- package/dist/data-id.js +23 -7
- package/package.json +4 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLAttributes, SvelteHTMLElements } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoBoolean } from 'fimo-sveltekit';
|
|
@@ -15,5 +16,5 @@
|
|
|
15
16
|
</script>
|
|
16
17
|
|
|
17
18
|
{#if value != null}
|
|
18
|
-
<svelte:element this={as} {...props} data-fimo-source={source}>{String(value.valueOf())}</svelte:element>
|
|
19
|
+
<svelte:element this={as} {...withoutFimoEditingMetadata(props)} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}>{String(value.valueOf())}</svelte:element>
|
|
19
20
|
{/if}
|
package/components/Date.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLTimeAttributes } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoString } from 'fimo-sveltekit';
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
</script>
|
|
30
31
|
|
|
31
32
|
{#if rendered}
|
|
32
|
-
<time {...props} datetime={rendered.datetime} data-fimo-source={source}>{rendered.text}</time>
|
|
33
|
+
<time {...withoutFimoEditingMetadata(props)} datetime={rendered.datetime} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}>{rendered.text}</time>
|
|
33
34
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLTimeAttributes } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoString } from 'fimo-sveltekit';
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
</script>
|
|
32
33
|
|
|
33
34
|
{#if rendered}
|
|
34
|
-
<time {...props} datetime={rendered.datetime} data-fimo-source={source}>{rendered.text}</time>
|
|
35
|
+
<time {...withoutFimoEditingMetadata(props)} datetime={rendered.datetime} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}>{rendered.text}</time>
|
|
35
36
|
{/if}
|
package/components/Image.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLImgAttributes } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoMedia } from 'fimo-sveltekit';
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
|
|
68
69
|
{#if image}
|
|
69
70
|
<img
|
|
70
|
-
{...props}
|
|
71
|
+
{...withoutFimoEditingMetadata(props)}
|
|
71
72
|
src={image.src}
|
|
72
73
|
alt={image.alt}
|
|
73
74
|
width={image.width}
|
|
@@ -75,6 +76,6 @@
|
|
|
75
76
|
sizes={image.sizes}
|
|
76
77
|
srcset={image.srcSet}
|
|
77
78
|
style={imageStyle}
|
|
78
|
-
data-fimo-source={source}
|
|
79
|
+
data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}
|
|
79
80
|
/>
|
|
80
81
|
{/if}
|
package/components/Json.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLAttributes, SvelteHTMLElements } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import { getFimoSource } from 'fimo-sveltekit';
|
|
@@ -14,5 +15,5 @@
|
|
|
14
15
|
</script>
|
|
15
16
|
|
|
16
17
|
{#if value != null}
|
|
17
|
-
<svelte:element this={as} {...props} data-fimo-source={source}>{JSON.stringify(value)}</svelte:element>
|
|
18
|
+
<svelte:element this={as} {...withoutFimoEditingMetadata(props)} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}>{JSON.stringify(value)}</svelte:element>
|
|
18
19
|
{/if}
|
package/components/Number.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLAttributes, SvelteHTMLElements } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
// Content numbers stay plain JS numbers (there is no FimoNumber wrapper), so
|
|
@@ -17,5 +18,5 @@
|
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
20
|
{#if rendered != null}
|
|
20
|
-
<svelte:element this={as} {...props}>{rendered}</svelte:element>
|
|
21
|
+
<svelte:element this={as} {...withoutFimoEditingMetadata(props)}>{rendered}</svelte:element>
|
|
21
22
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoRichText } from 'fimo-sveltekit';
|
|
@@ -15,5 +16,5 @@
|
|
|
15
16
|
</script>
|
|
16
17
|
|
|
17
18
|
{#if value}
|
|
18
|
-
<div {...props} data-fimo-source={source} data-fimo-richtext="">{@html html}</div>
|
|
19
|
+
<div {...withoutFimoEditingMetadata(props)} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined} data-fimo-richtext={isFimoEditingMetadataEnabled() ? "" : undefined}>{@html html}</div>
|
|
19
20
|
{/if}
|
package/components/Text.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLAttributes, SvelteHTMLElements } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoString } from 'fimo-sveltekit';
|
|
@@ -15,11 +16,11 @@
|
|
|
15
16
|
const source = $derived(getFimoSource(value));
|
|
16
17
|
</script>
|
|
17
18
|
|
|
18
|
-
<svelte:element this={as} {...props} data-fimo-source={source}>
|
|
19
|
+
<svelte:element this={as} {...withoutFimoEditingMetadata(props)} data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}>
|
|
19
20
|
{#if parts && parts.length > 1}
|
|
20
21
|
{#each parts as part}
|
|
21
22
|
{#if part.source}
|
|
22
|
-
<span data-fimo-source={part.source}>{part.text}</span>
|
|
23
|
+
<span data-fimo-source={isFimoEditingMetadataEnabled() ? part.source : undefined}>{part.text}</span>
|
|
23
24
|
{:else}
|
|
24
25
|
{part.text}
|
|
25
26
|
{/if}
|
package/components/Video.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { isFimoEditingMetadataEnabled, withoutFimoEditingMetadata } from 'fimo/preview';
|
|
2
3
|
import type { HTMLVideoAttributes } from 'svelte/elements';
|
|
3
4
|
|
|
4
5
|
import type { FimoMedia } from 'fimo-sveltekit';
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
{#if value}
|
|
25
26
|
<!-- svelte-ignore a11y_media_has_caption -->
|
|
26
27
|
<video
|
|
27
|
-
{...props}
|
|
28
|
+
{...withoutFimoEditingMetadata(props)}
|
|
28
29
|
src={overrideSrc ?? value.url}
|
|
29
30
|
width={value.width}
|
|
30
31
|
height={value.height}
|
|
@@ -32,6 +33,6 @@
|
|
|
32
33
|
{loop}
|
|
33
34
|
{muted}
|
|
34
35
|
{playsinline}
|
|
35
|
-
data-fimo-source={source}
|
|
36
|
+
data-fimo-source={isFimoEditingMetadataEnabled() ? source : undefined}
|
|
36
37
|
></video>
|
|
37
38
|
{/if}
|
package/dist/data-id.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { FIMO_EDITING_ATTRIBUTES, resolveFimoEditingMetadata } from 'fimo/preview';
|
|
4
5
|
import { getLineColumn } from 'fimo/vite/data-id';
|
|
5
6
|
// Native DOM elements are always taggable. Fimo's editable primitives are the
|
|
6
7
|
// only component exception: they forward arbitrary element attributes to the
|
|
@@ -44,7 +45,11 @@ export default function svelteDataIdPlugin() {
|
|
|
44
45
|
config = resolvedConfig;
|
|
45
46
|
},
|
|
46
47
|
async transform(code, id) {
|
|
47
|
-
|
|
48
|
+
const configured = config.define?.['process.env.FIMO_EDITING_METADATA'];
|
|
49
|
+
const editing = configured === undefined
|
|
50
|
+
? resolveFimoEditingMetadata(config.command === 'serve' && !config.isProduction ? 'development' : undefined, process.env.FIMO_EDITING_METADATA)
|
|
51
|
+
: configured === JSON.stringify('true');
|
|
52
|
+
if (!editing && !code.includes('data-fimo-')) {
|
|
48
53
|
return null;
|
|
49
54
|
}
|
|
50
55
|
// Query'd sub-requests (`+page.svelte?svelte&type=style…`) carry
|
|
@@ -71,31 +76,42 @@ export default function svelteDataIdPlugin() {
|
|
|
71
76
|
const relativePath = id.startsWith(`${config.root}/`) ? id.slice(config.root.length + 1) : id;
|
|
72
77
|
const insertions = [];
|
|
73
78
|
const primitiveComponents = collectFimoPrimitiveComponents(parsed.instance, parsed.module);
|
|
74
|
-
collectInsertions(parsed.fragment, code, relativePath, primitiveComponents, insertions);
|
|
79
|
+
collectInsertions(parsed.fragment, code, relativePath, primitiveComponents, insertions, editing);
|
|
75
80
|
if (insertions.length === 0) {
|
|
76
81
|
return null;
|
|
77
82
|
}
|
|
78
83
|
insertions.sort((a, b) => b.offset - a.offset);
|
|
79
84
|
let transformed = code;
|
|
80
85
|
for (const insertion of insertions) {
|
|
81
|
-
transformed =
|
|
86
|
+
transformed =
|
|
87
|
+
transformed.slice(0, insertion.offset) +
|
|
88
|
+
insertion.value +
|
|
89
|
+
transformed.slice(insertion.end ?? insertion.offset);
|
|
82
90
|
}
|
|
83
91
|
return { code: transformed, map: null };
|
|
84
92
|
},
|
|
85
93
|
};
|
|
86
94
|
}
|
|
87
|
-
function collectInsertions(node, code, relativePath, primitiveComponents, insertions) {
|
|
95
|
+
function collectInsertions(node, code, relativePath, primitiveComponents, insertions, editing) {
|
|
88
96
|
if (!node || typeof node !== 'object') {
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
91
99
|
if (Array.isArray(node)) {
|
|
92
100
|
for (const item of node) {
|
|
93
|
-
collectInsertions(item, code, relativePath, primitiveComponents, insertions);
|
|
101
|
+
collectInsertions(item, code, relativePath, primitiveComponents, insertions, editing);
|
|
94
102
|
}
|
|
95
103
|
return;
|
|
96
104
|
}
|
|
97
105
|
const element = node;
|
|
98
|
-
if (
|
|
106
|
+
if (!editing && Array.isArray(element.attributes)) {
|
|
107
|
+
for (const attr of element.attributes) {
|
|
108
|
+
if (attr.type === 'Attribute' && FIMO_EDITING_ATTRIBUTES.has(attr.name)) {
|
|
109
|
+
insertions.push({ offset: attr.start, end: attr.end, value: '' });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (editing &&
|
|
114
|
+
typeof element.type === 'string' &&
|
|
99
115
|
(TAGGABLE_ELEMENT_TYPES.has(element.type) ||
|
|
100
116
|
(element.type === 'Component' && typeof element.name === 'string' && primitiveComponents.has(element.name))) &&
|
|
101
117
|
typeof element.start === 'number' &&
|
|
@@ -115,7 +131,7 @@ function collectInsertions(node, code, relativePath, primitiveComponents, insert
|
|
|
115
131
|
if (key === 'parent' || key === 'metadata') {
|
|
116
132
|
continue;
|
|
117
133
|
}
|
|
118
|
-
collectInsertions(child, code, relativePath, primitiveComponents, insertions);
|
|
134
|
+
collectInsertions(child, code, relativePath, primitiveComponents, insertions, editing);
|
|
119
135
|
}
|
|
120
136
|
}
|
|
121
137
|
function collectFimoPrimitiveComponents(...instances) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-sveltekit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-staging.2",
|
|
4
4
|
"description": "Fimo runtime and hosting adapter for SvelteKit projects. Pairs with the fimo package at the same version.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"@sveltejs/adapter-vercel": "6.3.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@fimo/tsconfig": "2.
|
|
51
|
+
"@fimo/tsconfig": "2.5.0-staging.2",
|
|
52
52
|
"@types/node": "22.18.6",
|
|
53
|
-
"fimo": "2.
|
|
53
|
+
"fimo": "2.5.0-staging.2",
|
|
54
54
|
"typescript": "7.0.2",
|
|
55
55
|
"vite": "8.2.2",
|
|
56
56
|
"vitest": "5.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@sveltejs/kit": "^2.0.0",
|
|
60
|
-
"fimo": "
|
|
60
|
+
"fimo": "2.5.0-staging.2",
|
|
61
61
|
"svelte": "^5.0.0",
|
|
62
62
|
"vite": "^7.0.0 || ^8.0.0"
|
|
63
63
|
},
|