@datocms/svelte 4.2.5 → 4.2.6

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.
@@ -22,9 +22,7 @@ onMount(() => {
22
22
  ...stripStega !== void 0 ? { stripStega } : {}
23
23
  });
24
24
  if (enableClickToEdit !== void 0) {
25
- controller.enableClickToEdit(
26
- enableClickToEdit === true ? void 0 : enableClickToEdit
27
- );
25
+ controller.enableClickToEdit(enableClickToEdit === true ? void 0 : enableClickToEdit);
28
26
  }
29
27
  });
30
28
  $:
@@ -40,7 +40,9 @@ This drastically improves the editing experience, especially for non-technical u
40
40
  - [StructuredText integration](#structuredtext-integration)
41
41
  - [Edit groups with `data-datocms-content-link-group`](#edit-groups-with-data-datocms-content-link-group)
42
42
  - [Edit boundaries with `data-datocms-content-link-boundary`](#edit-boundaries-with-data-datocms-content-link-boundary)
43
- - [Manual overlays with `data-datocms-content-link-url`](#manual-overlays-with-data-datocms-content-link-url)
43
+ - [Manual overlays](#manual-overlays)
44
+ - [Using `data-datocms-content-link-url`](#using-data-datocms-content-link-url)
45
+ - [Using `data-datocms-content-link-source`](#using-data-datocms-content-link-source)
44
46
  - [Low-level utilities](#low-level-utilities)
45
47
  - [`decodeStega`](#decodestega)
46
48
  - [`stripStega`](#stripstega)
@@ -89,7 +91,7 @@ const result = await executeQuery(query, {
89
91
  });
90
92
  ```
91
93
 
92
- The `contentLink` option encodes invisible metadata into text fields, while `baseEditingUrl` tells DatoCMS where your preview is hosted.
94
+ The `contentLink: 'v1'` option enables stega encoding, which embeds invisible metadata into text fields. The `baseEditingUrl` tells DatoCMS where your project is located so edit URLs can be generated correctly. Both options are required.
93
95
 
94
96
  ### 2. Add ContentLink component to your app
95
97
 
@@ -232,11 +234,13 @@ In this example:
232
234
  - Clicking on the main structured text content opens the structured text field editor
233
235
  - Clicking on an embedded block opens that specific block's record editor
234
236
 
235
- ## Manual overlays with `data-datocms-content-link-url`
237
+ ## Manual overlays
236
238
 
237
- For non-text fields like booleans, numbers, dates, and JSON, the DatoCMS API cannot embed stega-encoded metadata. In these cases, you can manually specify the edit URL using the `data-datocms-content-link-url` attribute.
239
+ In some cases, you may want to manually create click-to-edit overlays for content that doesn't have stega encoding.
238
240
 
239
- The recommended approach is to use the `_editingUrl` field available on all records:
241
+ ### Using `data-datocms-content-link-url`
242
+
243
+ You can add the `data-datocms-content-link-url` attribute with a DatoCMS editing URL:
240
244
 
241
245
  ```graphql
242
246
  query {
@@ -249,8 +253,6 @@ query {
249
253
  }
250
254
  ```
251
255
 
252
- Then add the attribute to your element:
253
-
254
256
  ```svelte
255
257
  <span data-datocms-content-link-url={product._editingUrl}>
256
258
  ${product.price}
@@ -261,7 +263,20 @@ Then add the attribute to your element:
261
263
  </span>
262
264
  ```
263
265
 
264
- This ensures the URL format is always correct and adapts automatically to any future changes.
266
+ ### Using `data-datocms-content-link-source`
267
+
268
+ For elements without visible stega-encoded content, use the [`data-datocms-content-link-source`](https://github.com/datocms/content-link?tab=readme-ov-file#stamping-elements-via-data-datocms-content-link-source) attribute to attach stega metadata directly:
269
+
270
+ ```svelte
271
+ <!-- product.asset.video.alt contains stega-encoded info -->
272
+ <video
273
+ src={product.asset.video.url}
274
+ data-datocms-content-link-source={product.asset.video.alt}
275
+ controls
276
+ />
277
+ ```
278
+
279
+ This is useful for structural elements like `<video>`, `<audio>`, or `<iframe>` where stega encoding in visible text would be problematic.
265
280
 
266
281
  ## Low-level utilities
267
282
 
@@ -80,6 +80,9 @@ const query = gql`
80
80
  # if provided, it shows a blurred placeholder for the video
81
81
  blurUpThumb
82
82
 
83
+ # if provided, it enables DatoCMS Content Link for click-to-edit overlays
84
+ alt
85
+
83
86
  # you can include more data here: they will be ignored by the component
84
87
  }
85
88
  }
@@ -70,6 +70,7 @@ const toHTMLAttrs = (props = {}) => {
70
70
  </script>
71
71
 
72
72
  <script>import { onMount } from "svelte";
73
+ import { decodeStega } from "@datocms/content-link";
73
74
  export let data = {};
74
75
  export let style = void 0;
75
76
  export let preload = "metadata";
@@ -79,9 +80,19 @@ let muxPlayerElementImported = false;
79
80
  let muxPlayerElement;
80
81
  let computedProps;
81
82
  let alt;
83
+ let contentLinkSource;
82
84
  $: {
83
- const { muxPlaybackId, playbackId, title, width, height, blurUpThumb, alt: dataAlt } = data || {};
85
+ const {
86
+ muxPlaybackId,
87
+ playbackId,
88
+ title,
89
+ width,
90
+ height,
91
+ blurUpThumb,
92
+ alt: dataAlt
93
+ } = data || {};
84
94
  alt = dataAlt;
95
+ contentLinkSource = alt && decodeStega(alt) ? alt : void 0;
85
96
  computedProps = {
86
97
  ...computedTitle(title) || {},
87
98
  ...computedPlaybackId(muxPlaybackId, playbackId) || {},
@@ -111,7 +122,7 @@ onMount(async () => {
111
122
  <mux-player
112
123
  bind:this={muxPlayerElement}
113
124
  stream-type="on-demand"
114
- data-datocms-content-link-source={alt}
125
+ data-datocms-content-link-source={contentLinkSource}
115
126
  {...toHTMLAttrs(computedProps)}
116
127
  {...toHTMLAttrs($$restProps)}
117
128
  on:abort
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datocms/svelte",
3
- "version": "4.2.5",
3
+ "version": "4.2.6",
4
4
  "description": "A set of components and utilities to work faster with DatoCMS in Svelte",
5
5
  "license": "MIT",
6
6
  "repository": {