@datocms/svelte 4.2.9 → 4.2.11
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.
|
@@ -23,13 +23,10 @@ onMount(() => {
|
|
|
23
23
|
// Control stega encoding stripping behavior
|
|
24
24
|
...stripStega !== void 0 ? { stripStega } : {}
|
|
25
25
|
});
|
|
26
|
-
if (enableClickToEdit && typeof window !== "undefined" && window.self === window.top) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
enableClickToEdit === true ? void 0 : { scrollToNearestTarget: enableClickToEdit.scrollToNearestTarget ?? false }
|
|
31
|
-
);
|
|
32
|
-
}
|
|
26
|
+
if (enableClickToEdit && typeof window !== "undefined" && window.self === window.top && (enableClickToEdit === true || !enableClickToEdit.hoverOnly || window.matchMedia("(hover: hover)").matches)) {
|
|
27
|
+
controller.enableClickToEdit(
|
|
28
|
+
enableClickToEdit === true ? void 0 : { scrollToNearestTarget: enableClickToEdit.scrollToNearestTarget ?? false }
|
|
29
|
+
);
|
|
33
30
|
}
|
|
34
31
|
});
|
|
35
32
|
$:
|
|
@@ -38,12 +38,19 @@ This drastically improves the editing experience, especially for non-technical u
|
|
|
38
38
|
- [Flash-all highlighting](#flash-all-highlighting)
|
|
39
39
|
- [Props](#props)
|
|
40
40
|
- [ClickToEditOptions](#clicktoeditoptions)
|
|
41
|
-
- [
|
|
42
|
-
- [
|
|
43
|
-
|
|
44
|
-
- [
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
- [Data attributes reference](#data-attributes-reference)
|
|
42
|
+
- [Developer-specified attributes](#developer-specified-attributes)
|
|
43
|
+
- [`data-datocms-content-link-url`](#data-datocms-content-link-url)
|
|
44
|
+
- [`data-datocms-content-link-source`](#data-datocms-content-link-source)
|
|
45
|
+
- [`data-datocms-content-link-group`](#data-datocms-content-link-group)
|
|
46
|
+
- [`data-datocms-content-link-boundary`](#data-datocms-content-link-boundary)
|
|
47
|
+
- [Library-managed attributes](#library-managed-attributes)
|
|
48
|
+
- [`data-datocms-contains-stega`](#data-datocms-contains-stega)
|
|
49
|
+
- [`data-datocms-auto-content-link-url`](#data-datocms-auto-content-link-url)
|
|
50
|
+
- [How group and boundary resolution works](#how-group-and-boundary-resolution-works)
|
|
51
|
+
- [Structured Text fields](#structured-text-fields)
|
|
52
|
+
- [Rule 1: Always wrap the Structured Text component in a group](#rule-1-always-wrap-the-structured-text-component-in-a-group)
|
|
53
|
+
- [Rule 2: Wrap embedded blocks, inline blocks, and inline records in a boundary](#rule-2-wrap-embedded-blocks-inline-blocks-and-inline-records-in-a-boundary)
|
|
47
54
|
- [Low-level utilities](#low-level-utilities)
|
|
48
55
|
- [`decodeStega`](#decodestega)
|
|
49
56
|
- [`stripStega`](#stripstega)
|
|
@@ -51,6 +58,7 @@ This drastically improves the editing experience, especially for non-technical u
|
|
|
51
58
|
- [Click-to-edit overlays not appearing](#click-to-edit-overlays-not-appearing)
|
|
52
59
|
- [Navigation not syncing with Web Previews plugin](#navigation-not-syncing-with-web-previews-plugin)
|
|
53
60
|
- [StructuredText blocks not clickable](#structuredtext-blocks-not-clickable)
|
|
61
|
+
- [Layout issues caused by stega encoding](#layout-issues-caused-by-stega-encoding)
|
|
54
62
|
|
|
55
63
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
56
64
|
|
|
@@ -173,124 +181,309 @@ The `scrollToNearestTarget` parameter scrolls to the nearest editable element, u
|
|
|
173
181
|
|
|
174
182
|
## Props
|
|
175
183
|
|
|
176
|
-
| Prop | Type
|
|
177
|
-
| ------------------- |
|
|
178
|
-
| `onNavigateTo` | `(path: string) => void`
|
|
179
|
-
| `currentPath` | `string`
|
|
180
|
-
| `enableClickToEdit` | `boolean \| ClickToEditOptions` | - | Enable click-to-edit overlays on mount. Pass `true` or an object with options. If undefined or false, click-to-edit is disabled
|
|
181
|
-
| `stripStega` | `boolean`
|
|
182
|
-
| `root` | `ParentNode`
|
|
184
|
+
| Prop | Type | Default | Description |
|
|
185
|
+
| ------------------- | ------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
186
|
+
| `onNavigateTo` | `(path: string) => void` | - | Callback when [Web Previews plugin](https://www.datocms.com/marketplace/plugins/i/datocms-plugin-web-previews) requests navigation to a different page |
|
|
187
|
+
| `currentPath` | `string` | - | Current pathname to sync with [Web Previews plugin](https://www.datocms.com/marketplace/plugins/i/datocms-plugin-web-previews) |
|
|
188
|
+
| `enableClickToEdit` | `boolean \| ClickToEditOptions` | - | Enable click-to-edit overlays on mount. Pass `true` or an object with options. If undefined or false, click-to-edit is disabled |
|
|
189
|
+
| `stripStega` | `boolean` | - | Whether to strip stega encoding from text nodes after stamping |
|
|
190
|
+
| `root` | `ParentNode` | - | Root element to limit scanning to instead of the entire document |
|
|
183
191
|
|
|
184
192
|
### ClickToEditOptions
|
|
185
193
|
|
|
186
194
|
When passing an object to `enableClickToEdit`, the following options are available:
|
|
187
195
|
|
|
188
|
-
| Option | Type | Default | Description
|
|
189
|
-
| ----------------------- | --------- | ------- |
|
|
196
|
+
| Option | Type | Default | Description |
|
|
197
|
+
| ----------------------- | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
190
198
|
| `scrollToNearestTarget` | `boolean` | `false` | Automatically scroll to the nearest editable element if none is currently visible in the viewport when click-to-edit mode is enabled. Also triggers the flash-all highlighting effect. |
|
|
191
199
|
| `hoverOnly` | `boolean` | `false` | Only enable click-to-edit on devices that support hover (non-touch devices). Uses `window.matchMedia('(hover: hover)')` to detect hover capability. Useful to avoid overlays interfering with touch scrolling. |
|
|
192
200
|
|
|
193
|
-
##
|
|
201
|
+
## Data attributes reference
|
|
194
202
|
|
|
195
|
-
|
|
203
|
+
This library uses several `data-datocms-*` attributes. Some are **developer-specified** (you add them to your markup), and some are **library-managed** (added automatically during DOM stamping). Here's a complete reference.
|
|
196
204
|
|
|
197
|
-
###
|
|
205
|
+
### Developer-specified attributes
|
|
198
206
|
|
|
199
|
-
|
|
207
|
+
These attributes are added by you in your templates/components to control how editable regions behave.
|
|
208
|
+
|
|
209
|
+
#### `data-datocms-content-link-url`
|
|
210
|
+
|
|
211
|
+
Manually marks an element as editable with an explicit edit URL. Use this for non-text fields (booleans, numbers, dates, JSON) that cannot contain stega encoding. The recommended approach is to use the `_editingUrl` field available on all records:
|
|
212
|
+
|
|
213
|
+
```graphql
|
|
214
|
+
query {
|
|
215
|
+
product {
|
|
216
|
+
id
|
|
217
|
+
price
|
|
218
|
+
isActive
|
|
219
|
+
_editingUrl
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
200
223
|
|
|
201
224
|
```svelte
|
|
202
|
-
<
|
|
203
|
-
|
|
204
|
-
</
|
|
225
|
+
<span data-datocms-content-link-url={product._editingUrl}>
|
|
226
|
+
${product.price}
|
|
227
|
+
</span>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `data-datocms-content-link-source`
|
|
231
|
+
|
|
232
|
+
Attaches stega-encoded metadata without the need to render it as content. Useful for structural elements that cannot contain text (like `<video>`, `<audio>`, `<iframe>`, etc.) or when stega encoding in visible text would be problematic:
|
|
233
|
+
|
|
234
|
+
```svelte
|
|
235
|
+
<div data-datocms-content-link-source={video.alt}>
|
|
236
|
+
<video src={video.url} poster={video.posterImage.url} controls />
|
|
237
|
+
</div>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The value must be a stega-encoded string (any text field from the API will work). The library decodes the stega metadata from the attribute value and makes the element clickable to edit.
|
|
241
|
+
|
|
242
|
+
#### `data-datocms-content-link-group`
|
|
243
|
+
|
|
244
|
+
Expands the clickable area to a parent element. When the library encounters stega-encoded content, by default it makes the immediate parent of the text node clickable to edit. Adding this attribute to an ancestor makes that ancestor the clickable target instead:
|
|
245
|
+
|
|
246
|
+
```svelte
|
|
247
|
+
<article data-datocms-content-link-group>
|
|
248
|
+
<!-- product.title contains stega encoding -->
|
|
249
|
+
<h2>{product.title}</h2>
|
|
250
|
+
<p>${product.price}</p>
|
|
251
|
+
</article>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Here, clicking anywhere in the `<article>` opens the editor, rather than requiring users to click precisely on the `<h2>`.
|
|
255
|
+
|
|
256
|
+
**Important:** A group should contain only one stega-encoded source. If multiple stega strings resolve to the same group, the library logs a collision warning and only the last URL wins.
|
|
257
|
+
|
|
258
|
+
#### `data-datocms-content-link-boundary`
|
|
259
|
+
|
|
260
|
+
Stops the upward DOM traversal that looks for a `data-datocms-content-link-group`, making the element where stega was found the clickable target instead. This creates an independent editable region that won't merge into a parent group (see [How group and boundary resolution works](#how-group-and-boundary-resolution-works) below for details):
|
|
261
|
+
|
|
262
|
+
```svelte
|
|
263
|
+
<div data-datocms-content-link-group>
|
|
264
|
+
<!-- page.title contains stega encoding → resolves to URL A -->
|
|
265
|
+
<h1>{page.title}</h1>
|
|
266
|
+
<section data-datocms-content-link-boundary>
|
|
267
|
+
<!-- page.author contains stega encoding → resolves to URL B -->
|
|
268
|
+
<span>{page.author}</span>
|
|
269
|
+
</section>
|
|
270
|
+
</div>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Without the boundary, clicking `page.author` would open URL A (the outer group). With the boundary, the `<span>` becomes the clickable target opening URL B.
|
|
274
|
+
|
|
275
|
+
The boundary can also be placed directly on the element that contains the stega text:
|
|
276
|
+
|
|
277
|
+
```svelte
|
|
278
|
+
<div data-datocms-content-link-group>
|
|
279
|
+
<!-- page.title contains stega encoding → resolves to URL A -->
|
|
280
|
+
<h1>{page.title}</h1>
|
|
281
|
+
<!-- page.author contains stega encoding → resolves to URL B -->
|
|
282
|
+
<span data-datocms-content-link-boundary>{page.author}</span>
|
|
283
|
+
</div>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Here, the `<span>` has the boundary and directly contains the stega text, so the `<span>` itself becomes the clickable target (since the starting element and the boundary element are the same).
|
|
287
|
+
|
|
288
|
+
### Library-managed attributes
|
|
289
|
+
|
|
290
|
+
These attributes are added automatically by the library during DOM stamping. You do not need to add them yourself, but you can target them in CSS or JavaScript.
|
|
291
|
+
|
|
292
|
+
#### `data-datocms-contains-stega`
|
|
293
|
+
|
|
294
|
+
Added to elements whose text content contains stega-encoded invisible characters. This attribute is only present when `stripStega` is `false` (the default), since with `stripStega: true` the characters are removed entirely. Useful for CSS workarounds — the zero-width characters can sometimes cause unexpected letter-spacing or text overflow:
|
|
295
|
+
|
|
296
|
+
```css
|
|
297
|
+
[data-datocms-contains-stega] {
|
|
298
|
+
letter-spacing: 0 !important;
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### `data-datocms-auto-content-link-url`
|
|
303
|
+
|
|
304
|
+
Added automatically to elements that the library has identified as editable targets (through stega decoding and group/boundary resolution). Contains the resolved edit URL.
|
|
305
|
+
|
|
306
|
+
This is the automatic counterpart to the developer-specified `data-datocms-content-link-url`. The library adds `data-datocms-auto-content-link-url` wherever it can extract an edit URL from stega encoding, while `data-datocms-content-link-url` is needed for non-text fields (booleans, numbers, dates, etc.) where stega encoding cannot be embedded. Both attributes are used by the click-to-edit overlay system to determine which elements are clickable and where they link to.
|
|
307
|
+
|
|
308
|
+
## How group and boundary resolution works
|
|
309
|
+
|
|
310
|
+
When the library encounters stega-encoded content inside an element, it walks up the DOM tree from that element:
|
|
311
|
+
|
|
312
|
+
1. If it finds a `data-datocms-content-link-group`, it stops and stamps **that** element as the clickable target.
|
|
313
|
+
2. If it finds a `data-datocms-content-link-boundary`, it stops and stamps the **starting element** as the clickable target — further traversal is prevented.
|
|
314
|
+
3. If it reaches the root without finding either, it stamps the **starting element**.
|
|
315
|
+
|
|
316
|
+
Here are some concrete examples to illustrate:
|
|
317
|
+
|
|
318
|
+
**Example 1: Nested groups**
|
|
319
|
+
|
|
320
|
+
```svelte
|
|
321
|
+
<div data-datocms-content-link-group>
|
|
322
|
+
<!-- page.title contains stega encoding → resolves to URL A -->
|
|
323
|
+
<h1>{page.title}</h1>
|
|
324
|
+
<div data-datocms-content-link-group>
|
|
325
|
+
<!-- page.subtitle contains stega encoding → resolves to URL B -->
|
|
326
|
+
<p>{page.subtitle}</p>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
- **`page.title`**: walks up from `<h1>`, finds the outer group → the **outer `<div>`** becomes clickable (opens URL A).
|
|
332
|
+
- **`page.subtitle`**: walks up from `<p>`, finds the inner group first → the **inner `<div>`** becomes clickable (opens URL B). The outer group is never reached.
|
|
333
|
+
|
|
334
|
+
Each nested group creates an independent clickable region. The innermost group always wins for its own content.
|
|
205
335
|
|
|
336
|
+
**Example 2: Boundary preventing group propagation**
|
|
337
|
+
|
|
338
|
+
```svelte
|
|
339
|
+
<div data-datocms-content-link-group>
|
|
340
|
+
<!-- page.title contains stega encoding → resolves to URL A -->
|
|
341
|
+
<h1>{page.title}</h1>
|
|
342
|
+
<section data-datocms-content-link-boundary>
|
|
343
|
+
<!-- page.author contains stega encoding → resolves to URL B -->
|
|
344
|
+
<span>{page.author}</span>
|
|
345
|
+
</section>
|
|
346
|
+
</div>
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
- **`page.title`**: walks up from `<h1>`, finds the outer group → the **outer `<div>`** becomes clickable (opens URL A).
|
|
350
|
+
- **`page.author`**: walks up from `<span>`, hits the `<section>` boundary → traversal stops, the **`<span>`** itself becomes clickable (opens URL B). The outer group is not reached.
|
|
351
|
+
|
|
352
|
+
**Example 3: Boundary inside a group**
|
|
353
|
+
|
|
354
|
+
```svelte
|
|
355
|
+
<div data-datocms-content-link-group>
|
|
356
|
+
<!-- page.description contains stega encoding → resolves to URL A -->
|
|
357
|
+
<p>{page.description}</p>
|
|
358
|
+
<div data-datocms-content-link-boundary>
|
|
359
|
+
<!-- page.footnote contains stega encoding → resolves to URL B -->
|
|
360
|
+
<p>{page.footnote}</p>
|
|
361
|
+
</div>
|
|
362
|
+
</div>
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
- **`page.description`**: walks up from `<p>`, finds the outer group → the **outer `<div>`** becomes clickable (opens URL A).
|
|
366
|
+
- **`page.footnote`**: walks up from `<p>`, hits the boundary → traversal stops, the **`<p>`** itself becomes clickable (opens URL B). The outer group is not reached.
|
|
367
|
+
|
|
368
|
+
**Example 4: Multiple stega strings without groups (collision warning)**
|
|
369
|
+
|
|
370
|
+
```svelte
|
|
371
|
+
<p>
|
|
372
|
+
<!-- Both product.name and product.tagline contain stega encoding -->
|
|
373
|
+
{product.name}
|
|
374
|
+
{product.tagline}
|
|
375
|
+
</p>
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Both stega-encoded strings resolve to the same `<p>` element. The library logs a console warning and the last URL wins. To fix this, wrap each piece of content in its own element:
|
|
379
|
+
|
|
380
|
+
```svelte
|
|
381
|
+
<p>
|
|
382
|
+
<span>{product.name}</span>
|
|
383
|
+
<span>{product.tagline}</span>
|
|
384
|
+
</p>
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## Structured Text fields
|
|
388
|
+
|
|
389
|
+
Structured Text fields require special attention because of how stega encoding works within them:
|
|
390
|
+
|
|
391
|
+
- The DatoCMS API encodes stega information inside a single `<span>` within the structured text output. Without any configuration, only that small span would be clickable.
|
|
392
|
+
- Structured Text fields can contain **embedded blocks** and **inline records**, each with their own editing URL that should open a different record in the editor.
|
|
393
|
+
|
|
394
|
+
Here are the rules to follow:
|
|
395
|
+
|
|
396
|
+
### Rule 1: Always wrap the Structured Text component in a group
|
|
397
|
+
|
|
398
|
+
This makes the entire structured text area clickable, instead of just the tiny stega-encoded span:
|
|
399
|
+
|
|
400
|
+
```svelte
|
|
206
401
|
<div data-datocms-content-link-group>
|
|
207
|
-
<StructuredText data={content
|
|
402
|
+
<StructuredText data={page.content} />
|
|
208
403
|
</div>
|
|
209
404
|
```
|
|
210
405
|
|
|
211
|
-
|
|
406
|
+
### Rule 2: Wrap embedded blocks, inline blocks, and inline records in a boundary
|
|
212
407
|
|
|
213
|
-
|
|
408
|
+
Embedded blocks, inline blocks, and inline records each have their own edit URL (pointing to the block/record). Without a boundary, clicking them would bubble up to the parent group and open the structured text field editor instead. Add `data-datocms-content-link-boundary` to the root element of your custom components to prevent them from merging into the parent group.
|
|
214
409
|
|
|
215
|
-
|
|
410
|
+
**Note on record links (item links):** Record links (`isItemLink`) typically do **not** need a boundary. They render as `<a>` tags wrapping text that already belongs to the surrounding structured text. Unlike embedded blocks or inline records, record links don't introduce a separate editing target with its own stega-encoded URL, so there's no URL collision and no reason to isolate them from the parent group. When an editor clicks on that text, it correctly opens the structured text field editor (the parent group). Only add a boundary to a record link if you specifically want clicking it to open the linked record's editor instead.
|
|
216
411
|
|
|
217
412
|
```svelte
|
|
218
413
|
<script>
|
|
219
414
|
import { StructuredText } from '@datocms/svelte';
|
|
220
|
-
import
|
|
415
|
+
import { isBlock, isInlineBlock, isInlineItem, isItemLink } from 'datocms-structured-text-utils';
|
|
416
|
+
import Block from './Block.svelte';
|
|
417
|
+
import InlineBlock from './InlineBlock.svelte';
|
|
418
|
+
import InlineItem from './InlineItem.svelte';
|
|
419
|
+
import ItemLink from './ItemLink.svelte';
|
|
221
420
|
</script>
|
|
222
421
|
|
|
223
422
|
<div data-datocms-content-link-group>
|
|
224
423
|
<StructuredText
|
|
225
|
-
data={content
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// Wrap the block with a boundary
|
|
233
|
-
useBoundary: true,
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
}}
|
|
424
|
+
data={page.content}
|
|
425
|
+
components={[
|
|
426
|
+
[isBlock, Block],
|
|
427
|
+
[isInlineBlock, InlineBlock],
|
|
428
|
+
[isInlineItem, InlineItem],
|
|
429
|
+
[isItemLink, ItemLink],
|
|
430
|
+
]}
|
|
237
431
|
/>
|
|
238
432
|
</div>
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Then, in your custom components, wrap the root element with `data-datocms-content-link-boundary`:
|
|
436
|
+
|
|
437
|
+
```svelte
|
|
438
|
+
<!-- Block.svelte -->
|
|
439
|
+
<script>
|
|
440
|
+
export let block;
|
|
441
|
+
</script>
|
|
239
442
|
|
|
240
|
-
<!-- In BlockComponent.svelte -->
|
|
241
443
|
<div data-datocms-content-link-boundary>
|
|
242
444
|
<h2>{block.title}</h2>
|
|
243
445
|
<p>{block.description}</p>
|
|
244
446
|
</div>
|
|
245
447
|
```
|
|
246
448
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
In some cases, you may want to manually create click-to-edit overlays for content that doesn't have stega encoding.
|
|
254
|
-
|
|
255
|
-
### Using `data-datocms-content-link-url`
|
|
256
|
-
|
|
257
|
-
You can add the `data-datocms-content-link-url` attribute with a DatoCMS editing URL:
|
|
449
|
+
```svelte
|
|
450
|
+
<!-- InlineBlock.svelte -->
|
|
451
|
+
<script>
|
|
452
|
+
export let block;
|
|
453
|
+
</script>
|
|
258
454
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
id
|
|
263
|
-
price
|
|
264
|
-
isActive
|
|
265
|
-
_editingUrl
|
|
266
|
-
}
|
|
267
|
-
}
|
|
455
|
+
<span data-datocms-content-link-boundary>
|
|
456
|
+
<em>{block.username}</em>
|
|
457
|
+
</span>
|
|
268
458
|
```
|
|
269
459
|
|
|
270
460
|
```svelte
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
461
|
+
<!-- InlineItem.svelte -->
|
|
462
|
+
<script>
|
|
463
|
+
export let link;
|
|
464
|
+
</script>
|
|
274
465
|
|
|
275
|
-
<span data-datocms-content-link-
|
|
276
|
-
{
|
|
466
|
+
<span data-datocms-content-link-boundary>
|
|
467
|
+
{link.title}
|
|
277
468
|
</span>
|
|
278
469
|
```
|
|
279
470
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
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:
|
|
471
|
+
Record links don't need a boundary — their content belongs to the surrounding structured text:
|
|
283
472
|
|
|
284
473
|
```svelte
|
|
285
|
-
<!--
|
|
286
|
-
<
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
474
|
+
<!-- ItemLink.svelte -->
|
|
475
|
+
<script>
|
|
476
|
+
export let link;
|
|
477
|
+
</script>
|
|
478
|
+
|
|
479
|
+
<a href={`/posts/${link.slug}`}>
|
|
480
|
+
<slot />
|
|
481
|
+
</a>
|
|
291
482
|
```
|
|
292
483
|
|
|
293
|
-
|
|
484
|
+
With this setup:
|
|
485
|
+
- Clicking the main text (paragraphs, headings, lists) — including record links — opens the **structured text field editor**
|
|
486
|
+
- Clicking an embedded block, inline block, or inline record opens **that record's editor**
|
|
294
487
|
|
|
295
488
|
## Low-level utilities
|
|
296
489
|
|
|
@@ -398,4 +591,22 @@ These utilities are useful when you need to:
|
|
|
398
591
|
</div>
|
|
399
592
|
```
|
|
400
593
|
|
|
401
|
-
2. Add `data-datocms-content-link-boundary` to custom blocks to prevent them from bubbling to the parent field
|
|
594
|
+
2. Add `data-datocms-content-link-boundary` to custom blocks, inline blocks, and inline records to prevent them from bubbling to the parent field (record links typically don't need a boundary)
|
|
595
|
+
|
|
596
|
+
### Layout issues caused by stega encoding
|
|
597
|
+
|
|
598
|
+
**Problem**: The invisible zero-width characters can cause unexpected letter-spacing or text breaking out of containers.
|
|
599
|
+
|
|
600
|
+
**Solutions**:
|
|
601
|
+
1. Use the `stripStega` prop to remove stega encoding after processing:
|
|
602
|
+
```svelte
|
|
603
|
+
<ContentLink stripStega={true} />
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
2. Use CSS to reset letter-spacing on elements with stega-encoded content:
|
|
607
|
+
```css
|
|
608
|
+
[data-datocms-contains-stega] {
|
|
609
|
+
letter-spacing: 0 !important;
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
This attribute is automatically added to elements with stega-encoded content when `stripStega: false` (the default)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datocms/svelte",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.11",
|
|
4
4
|
"description": "A set of components and utilities to work faster with DatoCMS in Svelte",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@mux/mux-player": "^
|
|
39
|
-
"@mux/playback-core": "^0.
|
|
38
|
+
"@mux/mux-player": "^3.11.4",
|
|
39
|
+
"@mux/playback-core": "^0.33.1",
|
|
40
40
|
"@sveltejs/adapter-auto": "^3.0.0",
|
|
41
41
|
"@sveltejs/kit": "^2.0.0",
|
|
42
42
|
"@sveltejs/package": "^2.0.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"type": "module",
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@datocms/content-link": "^0.3.
|
|
69
|
+
"@datocms/content-link": "^0.3.13",
|
|
70
70
|
"datocms-listen": "^1.0.2",
|
|
71
71
|
"datocms-structured-text-utils": "^5.1.6",
|
|
72
72
|
"svelte-intersection-observer": "^1.0.0"
|