Skip to content

Commit

Permalink
Support passing down a node
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Aug 14, 2024
1 parent d43c9c1 commit f2ae81b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/lib/components/StructuredText/StructuredText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
import {
type StructuredText,
type Document,
isStructuredText
type Node as DastNode,
isStructuredText,
isDocument,
isNode
} from 'datocms-structured-text-utils';
import type { PredicateComponentTuple } from '$lib';
import Node from './Node.svelte';
/** The actual field value you get from DatoCMS **/
export let data: StructuredText | Document | null = null;
export let data: StructuredText | Document | DastNode | null | undefined = null;
export let components: PredicateComponentTuple[] = [];
$: node = data != null && (isStructuredText(data) ? data.value : data).document;
$: node = !data
? null
: isStructuredText(data) && isDocument(data.value)
? data.value.document
: isDocument(data)
? data.document
: isNode(data)
? data
: undefined;
$: blocks = isStructuredText(data) ? data?.blocks : undefined;
$: links = isStructuredText(data) ? data?.links : undefined;
</script>
Expand Down
1 change: 0 additions & 1 deletion src/lib/stores/querySubscription/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Live updates are great both to get instant previews of your content while editin
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Table of Contents](#table-of-contents)
- [Reference](#reference)
- [Initialization options](#initialization-options)
- [Connection status](#connection-status)
Expand Down

0 comments on commit f2ae81b

Please sign in to comment.