Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package not include the utils/react module mentioned in the README #60

Open
VarPDev opened this issue Jan 23, 2025 · 3 comments
Open

package not include the utils/react module mentioned in the README #60

VarPDev opened this issue Jan 23, 2025 · 3 comments
Assignees

Comments

@VarPDev
Copy link

VarPDev commented Jan 23, 2025

Brief bug description

The “utils/react” react module is not included in the package.

the documentation says to import the components for react this way:

import {
  PortableTextReactResolvers,
  PortableText,
  TableComponent,
  ImageComponent,
} from "@kontent-ai/rich-text-resolver/utils/react";

Repro steps

npm i @kontent-ai/rich-text-resolver
go to node_modules/@kontent-ai/rich-text-resolver folder
see that the modules are missing

Screenshots

Image

@pokornyd
Copy link
Member

hello @VarPDev. assuming you installed the package with npm i @kontent-ai/rich-text-resolver, you likely installed the latest stable release (v1.2.2), which didn't specify exports for react utils in package.json.

main branch of the repository is already merged with latest version updates (2.0.0), however, it's only pre-released on NPM as 2.0.0-rc1. this is because I'm waiting on updates in Kontent.ai documentation before actual release, which is likely to happen next week.

I suggest you install the release candidate (npm i @kontent-ai/[email protected]) and follow the readme for guidance. it should not differ from actual 2.0.0 version when it goes live.

if you're interested in the older version, follow its readme: https://github.com/kontent-ai/rich-text-resolver-js/tree/e6f3384cc5a046344042e1b247af95ebd6848285

@pokornyd pokornyd self-assigned this Jan 24, 2025
@VarPDev
Copy link
Author

VarPDev commented Jan 24, 2025

@pokornyd

in the documentation it says to use nodeParse for the SSR. With the old version it worked now instead with version 2.0.0-rc1 I think the library does not export it.

here the example from documentation:

const MyComponent = ({ props }) => {
  // https://github.com/portabletext/react-portabletext#customizing-components

  const parsedTree = browserParse(props.element.value); // or nodeParse for SSR
  const portableText = transformToPortableText(parsedTree);

  return (
    <PortableText value={portableText} components={portableTextComponents} />
  );
};

@pokornyd
Copy link
Member

version 2.0.0 got rid of separate nodeParse and browserParse methods for parsing. you can now use parseHTML, which is environment-aware (node.js or browser) and picks the suitable parser for you.

if your goal is to work with portable text, you can (and have to) omit parseHTML altogether and simply use transformToPortableText function, which now accepts a rich text HTML string directly and does the parsing for you.

parseHTML function returns the DomNode array, which is intended primarily for transformation of external HTML/rich text into a Kontent.ai-valid format (in migration purposes). no method for transforming DomNode array into PortableTextObject[] is provided anymore, so it's really either parseHTML or transformToPortableText now.

Readme of the main branch is up-to-date and explains the reworked usage. Update to TS rich text resolution guide in Kontent.ai documentation is under review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants