Skip to content

2.0.0

Compare
Choose a tag to compare
@pokornyd pokornyd released this 28 Jan 14:26
· 1 commit to main since this release

Kontent.ai Rich Text Resolver 2.0.0

New version of the primary tool for Kontent.ai rich text resolution in JS/TS-based frameworks, including more accurate typing, reworked transformation logic with focus on streamlining migration of external rich text and HTML and performance improvements.

Changes

Since the deprecation of rich text resolution built into the JS SDK, this package has become the primary solution for resolving rich text. To align with familiar naming conventions, a large number of types, properties and functions have been renamed. Some methods were removed altogether, while others have updated signatures. See changes below.

Note

Changes marked with ⚠️ are breaking or potentially breaking

Changes marked with ℹ️ are non-breaking

Functions

  1. ⚠️ transformToPortableText – updated signature. previously accepted a ParseResult object from either nodeParse or browserParse functions. Now accepts string representation of the rich text HTML. Parsing happens internally and is environment-aware (Node.js vs browser).
  2. ⚠️ nodeParse, browserParse – removed in favor of parseHTML, which picks a correct parser based on the environment it's called from. The result is now directly DomNode[] rather than ParseResult, which contained the resulting DomNode array in a nested children property.
  3. ⚠️ transformToJson – removed. See reworked transformation entry below.

Types

  1. ⚠️ PortableTextComponent renamed → PortableTextComponentOrItem

    • ⚠️_type literal changed to componentOrItem
    • ⚠️component property renamed to componentOrItem
  2. ⚠️ PortableTextInternalLink renamed → PortableTextItemLink

    • ⚠️reference property renamed to contentItemLink
  3. PortableTextTable

    • ⚠️numColumns property removed
  4. PortableTextTableCell

    • ⚠️childBlocksCount property removed
  5. Reference, AssetReference

    • ℹ️ added a referenceType property, informing whether the value references codename, id or external-id
  6. ⚠️ ParseResult – removed, parseHTML function now returns directly DomNode[]

  7. ⚠️ ResolveDomTextNodeType, ResolveDomHtmlNodeType, TransformDomNodeType – removed

Features

Reworked HTML parsing and transformation (formerly JSON)

Parsing has been unified under a new, environment-aware (Node.js and browser) parseHTML function. The result is now directly a DomNode array, which can be transformed and composed back to HTML using new nodesToHTML and nodesToHTMLAsync functions.

The revamped logic is specifically tailored for transforming external rich text and HTML in order to make it compatible with Kontent.ai rich text format. See dedicated transformer documentation for details.

More accurate resolution types

Resolution to React and HTML has been improved by addition of modified types from the respective external packages. The new types (PortableTextReactResolvers and PortableTextHtmlResolvers respectively) now natively support custom Kontent.ai portable text objects without the need for explicit typing.

Default resolution improvements for HTML and React

<PortableText> component and toHTML functions from respective external packages have been modified and re-exported from the module itself. They now provide default fallback for resolution of tables, images, URL links and previously unsupported sub and sup tags, without the need to specify transformations for them explicitly. Existing helper functions (such as resolveImage and resolveTable) remain unchanged, but no longer have to be used, as the process will supply them automatically, if no custom resolution was provided.

Reworked internal portable text transformation logic

The transformation logic from DomNode[] to Portable Text has been simplified and optimized, removing some redundancy and lowering the number of recursive traversals, which may result in slight performance gain with large HTML inputs.

Pull requests

Full Changelog: 1.2.2...2.0.0