datocms-structured-text-utils
Advanced tools
Comparing version 1.0.4 to 1.0.5
"use strict"; | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.allowedMarks = exports.allowedAttributes = exports.inlineNodeTypes = exports.allowedChildren = exports.allowedNodeTypes = exports.spanNodeType = exports.rootNodeType = exports.paragraphNodeType = exports.listNodeType = exports.listItemNodeType = exports.linkNodeType = exports.itemLinkNodeType = exports.inlineItemNodeType = exports.headingNodeType = exports.codeNodeType = exports.blockNodeType = exports.blockquoteNodeType = void 0; | ||
exports.allowedMarks = exports.allowedAttributes = exports.inlineNodeTypes = exports.allowedChildren = exports.allowedNodeTypes = exports.thematicBreakNodeType = exports.spanNodeType = exports.rootNodeType = exports.paragraphNodeType = exports.listNodeType = exports.listItemNodeType = exports.linkNodeType = exports.itemLinkNodeType = exports.inlineItemNodeType = exports.headingNodeType = exports.codeNodeType = exports.blockNodeType = exports.blockquoteNodeType = void 0; | ||
exports.blockquoteNodeType = 'blockquote'; | ||
@@ -17,2 +17,3 @@ exports.blockNodeType = 'block'; | ||
exports.spanNodeType = 'span'; | ||
exports.thematicBreakNodeType = 'thematicBreak'; | ||
exports.allowedNodeTypes = [ | ||
@@ -31,2 +32,3 @@ exports.blockquoteNodeType, | ||
exports.spanNodeType, | ||
exports.thematicBreakNodeType, | ||
]; | ||
@@ -51,4 +53,6 @@ exports.allowedChildren = (_a = {}, | ||
exports.blockNodeType, | ||
exports.thematicBreakNodeType, | ||
], | ||
_a[exports.spanNodeType] = [], | ||
_a[exports.thematicBreakNodeType] = [], | ||
_a); | ||
@@ -67,4 +71,4 @@ exports.inlineNodeTypes = [ | ||
_b[exports.inlineItemNodeType] = ['item'], | ||
_b[exports.itemLinkNodeType] = ['item', 'children'], | ||
_b[exports.linkNodeType] = ['url', 'children'], | ||
_b[exports.itemLinkNodeType] = ['item', 'children', 'meta'], | ||
_b[exports.linkNodeType] = ['url', 'children', 'meta'], | ||
_b[exports.listItemNodeType] = ['children'], | ||
@@ -75,2 +79,3 @@ _b[exports.listNodeType] = ['style', 'children'], | ||
_b[exports.spanNodeType] = ['value', 'marks'], | ||
_b[exports.thematicBreakNodeType] = [], | ||
_b); | ||
@@ -77,0 +82,0 @@ exports.allowedMarks = [ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isStructuredText = exports.isInlineItem = exports.isItemLink = exports.isLink = exports.isCode = exports.isBlock = exports.isBlockquote = exports.isListItem = exports.isList = exports.isParagraph = exports.isRoot = exports.isSpan = exports.isHeading = exports.isInlineNode = exports.hasChildren = void 0; | ||
exports.isStructuredText = exports.isThematicBreak = exports.isInlineItem = exports.isItemLink = exports.isLink = exports.isCode = exports.isBlock = exports.isBlockquote = exports.isListItem = exports.isList = exports.isParagraph = exports.isRoot = exports.isSpan = exports.isHeading = exports.isInlineNode = exports.hasChildren = void 0; | ||
var definitions_1 = require("./definitions"); | ||
@@ -61,2 +61,6 @@ function hasChildren(node) { | ||
exports.isInlineItem = isInlineItem; | ||
function isThematicBreak(node) { | ||
return node.type === definitions_1.thematicBreakNodeType; | ||
} | ||
exports.isThematicBreak = isThematicBreak; | ||
function isStructuredText( | ||
@@ -63,0 +67,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types |
@@ -29,3 +29,7 @@ "use strict"; | ||
var _loop_1 = function () { | ||
node = nodes.pop(); | ||
var next = nodes.pop(); | ||
if (!next) { | ||
return "break"; | ||
} | ||
node = next; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -89,2 +93,4 @@ var type = node.type, attributes = __rest(node, ["type"]); | ||
return state_1.value; | ||
if (state_1 === "break") | ||
break; | ||
} | ||
@@ -91,0 +97,0 @@ return { |
@@ -14,2 +14,3 @@ import { Mark, NodeType } from './types'; | ||
export declare const spanNodeType: "span"; | ||
export declare const thematicBreakNodeType: "thematicBreak"; | ||
export declare const allowedNodeTypes: NodeType[]; | ||
@@ -16,0 +17,0 @@ export declare type AllowedChildren = Record<NodeType, 'inlineNodes' | NodeType[]>; |
@@ -1,2 +0,2 @@ | ||
import { Root, List, Blockquote, Block, Link, ItemLink, InlineItem, Code, ListItem, Paragraph, Heading, Node, Span, WithChildrenNode, InlineNode, Record, StructuredText } from './types'; | ||
import { Root, List, Blockquote, Block, Link, ItemLink, InlineItem, Code, ListItem, Paragraph, Heading, Node, Span, WithChildrenNode, InlineNode, Record, StructuredText, ThematicBreak } from './types'; | ||
export declare function hasChildren(node: Node): node is WithChildrenNode; | ||
@@ -16,2 +16,3 @@ export declare function isInlineNode(node: Node): node is InlineNode; | ||
export declare function isInlineItem(node: Node): node is InlineItem; | ||
export declare function isThematicBreak(node: Node): node is ThematicBreak; | ||
export declare function isStructuredText<R extends Record>(obj: any): obj is StructuredText<R>; |
@@ -13,3 +13,3 @@ import { Node, Record, StructuredText } from './types'; | ||
key: string; | ||
children: RenderResult<H, T, F>[] | undefined; | ||
children: Exclude<RenderResult<H, T, F>, null | undefined>[] | undefined; | ||
}; | ||
@@ -16,0 +16,0 @@ export interface RenderRule<H extends TrasformFn, T extends TrasformFn, F extends TrasformFn> { |
export declare type Node = BlockNode | InlineNode; | ||
export declare type BlockNode = Root | Paragraph | Heading | Block | List | ListItem | Blockquote | Code; | ||
export declare type BlockNode = Root | Paragraph | Heading | Block | List | ListItem | Blockquote | Code | ThematicBreak; | ||
export declare type InlineNode = Span | Link | ItemLink | InlineItem; | ||
export declare type NodeWithMeta = Link | ItemLink; | ||
export declare type RootType = 'root'; | ||
@@ -37,3 +38,3 @@ /** | ||
type: RootType; | ||
children: Array<Paragraph | Heading | List | Code | Blockquote | Block>; | ||
children: Array<Paragraph | Heading | List | Code | Blockquote | Block | ThematicBreak>; | ||
}; | ||
@@ -141,2 +142,16 @@ export declare type ParagraphType = 'paragraph'; | ||
}; | ||
export declare type ThematicBreakType = 'thematicBreak'; | ||
/** | ||
* A `thematicBreak` node represents a thematic break between paragraph-level elements: | ||
* for example, a change of scene in a story, or a shift of topic within a section. | ||
* | ||
* ```json | ||
* { | ||
* "type": "thematicBreak" | ||
* } | ||
* ``` | ||
*/ | ||
export declare type ThematicBreak = { | ||
type: ThematicBreakType; | ||
}; | ||
export declare type CodeType = 'code'; | ||
@@ -234,6 +249,10 @@ /** | ||
value: string; | ||
meta?: { | ||
[prop: string]: unknown; | ||
}; | ||
}; | ||
export declare type LinkType = 'link'; | ||
/** | ||
* A `link` node represents a normal hyperlink. You can also link to DatoCMS records using | ||
* A `link` node represents a normal hyperlink. It might optionally contain a number of additional | ||
* custom information under the `meta` key. You can also link to DatoCMS records using | ||
* the [`itemLink`](#itemLink) node. | ||
@@ -245,2 +264,5 @@ * | ||
* "url": "https://www.datocms.com/" | ||
* "meta": { | ||
* "openInNewWindow": true | ||
* }, | ||
* "children": [ | ||
@@ -259,2 +281,8 @@ * { | ||
children: Array<Span>; | ||
/** | ||
* Object containing custom meta-information for the link. | ||
*/ | ||
meta?: { | ||
[prop: string]: unknown; | ||
}; | ||
}; | ||
@@ -267,2 +295,5 @@ export declare type ItemLinkType = 'itemLink'; | ||
* | ||
* It might optionally contain a number of additional custom information under | ||
* the `meta` key. | ||
* | ||
* If you want to link to a DatoCMS record without having to specify some | ||
@@ -274,3 +305,6 @@ * inner content, then please use the [`inlineItem`](#inlineItem) node. | ||
* "type": "itemLink", | ||
* "item": "38945648" | ||
* "item": "38945648", | ||
* "meta": { | ||
* "openInNewWindow": true, | ||
* }, | ||
* "children": [ | ||
@@ -290,2 +324,8 @@ * { | ||
children: Array<Span>; | ||
/** | ||
* Object containing custom meta-information for the link. | ||
*/ | ||
meta?: { | ||
[prop: string]: unknown; | ||
}; | ||
}; | ||
@@ -313,3 +353,3 @@ export declare type InlineItemType = 'inlineItem'; | ||
}; | ||
export declare type WithChildrenNode = Exclude<Node, Code | Span | Block | InlineItem>; | ||
export declare type WithChildrenNode = Exclude<Node, Code | Span | Block | InlineItem | ThematicBreak>; | ||
/** | ||
@@ -323,3 +363,3 @@ * A Structured Text `dast`-compatible value, composed by the `dast` document | ||
}; | ||
export declare type NodeType = ParagraphType | HeadingType | LinkType | ItemLinkType | InlineItemType | BlockType | ListType | ListItemType | BlockquoteType | CodeType | RootType | SpanType; | ||
export declare type NodeType = ParagraphType | HeadingType | LinkType | ItemLinkType | InlineItemType | BlockType | ListType | ListItemType | BlockquoteType | CodeType | RootType | SpanType | ThematicBreakType; | ||
/** | ||
@@ -326,0 +366,0 @@ * Structured Text enables authors to create rich text content, on par with |
{ | ||
"name": "datocms-structured-text-utils", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A set of Typescript types and helpers to work with DatoCMS Structured Text fields", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "7f39864c4987d37a2676c06def2eaf914dacf84f" | ||
"gitHead": "f03a62f2d53133ebbadd3266c0b9116489688bdf" | ||
} |
@@ -21,3 +21,3 @@ # `datocms-structured-text-utils` | ||
You can use the `validate()` function to check if an object is compatible with the `dast` specification: | ||
You can use the `validate()` function to check if an object is compatible with the [`dast` specification](https://www.datocms.com/docs/structured-text/dast): | ||
@@ -58,3 +58,3 @@ ```js | ||
The package exports a number of constants that represents the rules of the `dast` specification. | ||
The package exports a number of constants that represents the rules of the [`dast` specification](https://www.datocms.com/docs/structured-text/dast). | ||
@@ -77,3 +77,3 @@ Take a look a the [definitions.ts](https://github.com/datocms/structured-text/blob/main/packages/utils/src/definitions.ts) file for their definition: | ||
export const allowedNodeTypes = [ | ||
const allowedNodeTypes = [ | ||
'paragraph', | ||
@@ -84,3 +84,3 @@ 'list', | ||
export const allowedChildren = { | ||
const allowedChildren = { | ||
paragraph: 'inlineNodes', | ||
@@ -91,3 +91,3 @@ list: ['listItem'], | ||
export const inlineNodeTypes = [ | ||
const inlineNodeTypes = [ | ||
'span', | ||
@@ -98,3 +98,3 @@ 'link', | ||
export const allowedAttributes = { | ||
const allowedAttributes = { | ||
heading: ['level', 'children'], | ||
@@ -104,3 +104,3 @@ // ... | ||
export const allowedMarks = [ | ||
const allowedMarks = [ | ||
'strong', | ||
@@ -114,3 +114,3 @@ 'code', | ||
The package exports Typescript types for all the different nodes that a `dast` document can contain. | ||
The package exports Typescript types for all the different nodes that a [`dast` document](https://www.datocms.com/docs/structured-text/dast) can contain. | ||
@@ -117,0 +117,0 @@ Take a look a the [types.ts](https://github.com/datocms/structured-text/blob/main/packages/utils/src/types.ts) file for their definition: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43225
802