Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyd committed Dec 6, 2023
1 parent d8f5ef3 commit 5c95b19
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
PortableTextListItemType,
PortableTextBlock,
} from '@portabletext/types';
import { PortableTextBlock,PortableTextListItemType } from '@portabletext/types'

import { IDomHtmlNode, IDomNode, IOutputResult } from "../../parser/index.js"
import {
ExtendPortableTextFunction,
PortableTextLink,
Expand All @@ -12,48 +11,43 @@ import {
Reference,
} from "../../transformers/index.js"
import {
IDomHtmlNode,
IDomNode,
IOutputResult,
} from "../../parser/index.js"
import {
compose,
createBlock,
createComponentBlock,
createExternalLink,
createImageBlock,
createItemLink,
createLinkMark,
createListBlock,
createSpan,
createTable,
createTableCell,
createTableRow,
createStyleMark,
isElement,
isExternalLink,
isListBlock,
isListItem,
isText,
isUnorderedListBlock,
textStyleElements,
blockElements,
ignoredElements,
MergePortableTextItemsFunction,
TransformElementFunction,
TransformLinkFunction,
TransformListItemFunction,
TransformTextFunction,
lineBreakElement,
uid,
TextStyleElement,
markElements,
MarkElement,
ValidElement,
BlockElement,
IgnoredElement,
TransformFunction,
TransformTableCellFunction
BlockElement,
blockElements,
compose,
createBlock,
createComponentBlock,
createExternalLink,
createImageBlock,
createItemLink,
createLinkMark,
createListBlock,
createSpan,
createStyleMark,
createTable,
createTableCell,
createTableRow,
IgnoredElement,
ignoredElements,
isElement,
isExternalLink,
isListBlock,
isListItem,
isText,
isUnorderedListBlock,
lineBreakElement,
MarkElement,
markElements,
MergePortableTextItemsFunction,
TextStyleElement,
textStyleElements,
TransformElementFunction,
TransformFunction,
TransformLinkFunction,
TransformListItemFunction,
TransformTableCellFunction,
TransformTextFunction,
uid,
ValidElement
} from "../../utils/index.js"

/**
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/transformer-models.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ArbitraryTypedObject,
PortableTextBlock,
PortableTextListItemBlock,
PortableTextMarkDefinition,
ArbitraryTypedObject,
PortableTextSpan,
PortableTextListItemBlock,
} from "@portabletext/types";

/**
Expand Down
16 changes: 6 additions & 10 deletions src/utils/transformer-utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { PortableTextBlockStyle, PortableTextListItemType, PortableTextMarkDefinition, PortableTextSpan } from "@portabletext/types"
import ShortUniqueId from "short-unique-id";

import { IDomHtmlNode, IDomTextNode } from "../parser/index.js";
import {
PortableTextBlockStyle,
PortableTextListItemType,
PortableTextMarkDefinition,
PortableTextSpan,
} from "@portabletext/types";
import {
ExtendPortableTextFunction,
PortableTextComponent,
PortableTextLink,
PortableTextExternalLink,
PortableTextImage,
PortableTextInternalLink,
PortableTextLink,
PortableTextLinkMark,
PortableTextMark,
PortableTextObject,
Expand All @@ -20,10 +19,7 @@ import {
PortableTextTableCell,
PortableTextTableRow,
Reference,
ExtendPortableTextFunction,
} from "../transformers/transformer-models.js";
import { IDomHtmlNode, IDomTextNode } from "../parser/index.js";
import ShortUniqueId from "short-unique-id";

export const textStyleElements = ['strong', 'em', 'sub', 'sup', 'code'] as const;
export const blockElements = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
Expand Down
21 changes: 18 additions & 3 deletions tests/components/portable-text.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { Elements, ElementType } from '@kontent-ai/delivery-sdk';
import { PortableText, PortableTextMarkComponentProps, PortableTextReactComponents, PortableTextTypeComponentProps, toPlainText } from '@portabletext/react';
import {
PortableText,
PortableTextMarkComponentProps,
PortableTextReactComponents,
PortableTextTypeComponentProps,
toPlainText
} from '@portabletext/react'
import React from 'react';
import TestRenderer from 'react-test-renderer';

import { nodeParse, PortableTextComponent, PortableTextExternalLink, PortableTextImage, PortableTextInternalLink, PortableTextLink, PortableTextTable, resolveTable, transformToPortableText } from '../../src';
import {
nodeParse,
PortableTextComponent,
PortableTextExternalLink,
PortableTextImage,
PortableTextInternalLink,
PortableTextTable,
resolveTable,
transformToPortableText
} from '../../src'

const dummyRichText: Elements.RichTextElement = {
value: "<p>some text in a paragraph</p>",
Expand Down Expand Up @@ -54,7 +69,7 @@ const portableTextComponents: Partial<PortableTextReactComponents> = {
link: ({ value, children }: PortableTextMarkComponentProps<PortableTextExternalLink>) => {
const target = (value?.href || '').startsWith('http') ? '_blank' : undefined
return (
<a href={value?.href} target={target} rel={value?.rel} title={value?.title} data-new-window={value && value['data-new-window']}>
<a href={value?.href} target={target} rel={value?.rel} title={value?.title} data-new-window={value?.['data-new-window']}>
{children}
</a>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { PortableTextBlock } from "@portabletext/types";
import { ExtendPortableTextFunction, PortableTextObject, browserParse, extendPortableText, nodeParse, transformToPortableText } from "../../../src";

import {
browserParse,
ExtendPortableTextFunction,
nodeParse,
PortableTextObject,
transformToPortableText
} from "../../../src"

jest.mock('short-unique-id', () => {
return {
Expand Down Expand Up @@ -345,7 +352,7 @@ describe("portable text transformer", () => {
})

it("extends link nested in a table with additional data", () => {
const input = `<table><tbody><tr><td><a href=\"http://google.com\">tablelink</a></td></tr></tbody></table>`;
const input = `<table><tbody><tr><td><a href="http://google.com">tablelink</a></td></tr></tbody></table>`;

const extendPortableText: ExtendPortableTextFunction<PortableTextObject> = (obj) => {
if (obj._type === 'link') {
Expand Down

0 comments on commit 5c95b19

Please sign in to comment.