@datocms/svelte 4.2.4 → 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
 
@@ -285,15 +300,27 @@ if (decoded) {
285
300
 
286
301
  ### `stripStega`
287
302
 
288
- Removes stega encoding from text, returning clean text:
303
+ Removes stega encoding from any data type:
289
304
 
290
305
  ```typescript
291
306
  import { stripStega } from '@datocms/svelte';
292
307
 
293
- const text = "Hello, world!"; // Contains invisible stega data
294
- const clean = stripStega(text);
308
+ // Works with strings
309
+ stripStega("Hello‎World") // "HelloWorld"
310
+
311
+ // Works with objects
312
+ stripStega({ name: "John‎", age: 30 })
313
+
314
+ // Works with nested structures - removes ALL stega encodings
315
+ stripStega({
316
+ users: [
317
+ { name: "Alice‎", email: "alice‎.com" },
318
+ { name: "Bob‎", email: "bob‎.co" }
319
+ ]
320
+ })
295
321
 
296
- console.log(clean); // "Hello, world!" without encoding
322
+ // Works with arrays
323
+ stripStega(["First‎", "Second‎", "Third‎"])
297
324
  ```
298
325
 
299
326
  These utilities are useful when you need to:
@@ -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";
@@ -78,8 +79,20 @@ export let disableTracking = true;
78
79
  let muxPlayerElementImported = false;
79
80
  let muxPlayerElement;
80
81
  let computedProps;
82
+ let alt;
83
+ let contentLinkSource;
81
84
  $: {
82
- const { muxPlaybackId, playbackId, title, width, height, blurUpThumb } = data || {};
85
+ const {
86
+ muxPlaybackId,
87
+ playbackId,
88
+ title,
89
+ width,
90
+ height,
91
+ blurUpThumb,
92
+ alt: dataAlt
93
+ } = data || {};
94
+ alt = dataAlt;
95
+ contentLinkSource = alt && decodeStega(alt) ? alt : void 0;
83
96
  computedProps = {
84
97
  ...computedTitle(title) || {},
85
98
  ...computedPlaybackId(muxPlaybackId, playbackId) || {},
@@ -109,6 +122,7 @@ onMount(async () => {
109
122
  <mux-player
110
123
  bind:this={muxPlayerElement}
111
124
  stream-type="on-demand"
125
+ data-datocms-content-link-source={contentLinkSource}
112
126
  {...toHTMLAttrs(computedProps)}
113
127
  {...toHTMLAttrs($$restProps)}
114
128
  on:abort
@@ -75,6 +75,8 @@ export type MuxPlayerProps = {
75
75
  export type Video = {
76
76
  /** Title attribute (`title`) for the video */
77
77
  title?: Maybe<string>;
78
+ /** Alt attribute used for content link integration (passed as data-datocms-content-link-source) */
79
+ alt?: Maybe<string>;
78
80
  /** The height of the video */
79
81
  height?: Maybe<number>;
80
82
  /** The width of the video */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datocms/svelte",
3
- "version": "4.2.4",
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": {
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "type": "module",
68
68
  "dependencies": {
69
- "@datocms/content-link": "^0.3.9",
69
+ "@datocms/content-link": "^0.3.10",
70
70
  "datocms-listen": "^1.0.2",
71
71
  "datocms-structured-text-utils": "^5.1.6",
72
72
  "svelte-intersection-observer": "^1.0.0"