Socket
Socket
Sign inDemoInstall

@prismicio/richtext

Package Overview
Dependencies
1
Maintainers
20
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.4 to 2.2.0-alpha.0

2

dist/composeSerializers.d.ts

@@ -14,2 +14,2 @@ import { RichTextFunctionSerializer } from "./types";

*/
export declare const composeSerializers: <SerializerReturnType>(...serializers: (RichTextFunctionSerializer<SerializerReturnType> | undefined)[]) => RichTextFunctionSerializer<SerializerReturnType>;
export declare const composeSerializers: <SerializerReturnType, SerializerChildType = SerializerReturnType>(...serializers: (RichTextFunctionSerializer<SerializerReturnType, SerializerChildType> | undefined)[]) => RichTextFunctionSerializer<SerializerReturnType, SerializerChildType>;

@@ -7,2 +7,2 @@ export { asTree } from "./asTree";

export { RichTextNodeType as Element } from "@prismicio/types";
export type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction, } from "./types";
export type { RichTextFunctionSerializer, RichTextMapSerializer, RichTextMapSerializerFunction, Tree, TreeNode, } from "./types";

@@ -16,2 +16,2 @@ import { RichTextField } from "@prismicio/types";

*/
export declare const serialize: <SerializerReturnType>(richTextField: RichTextField, serializer: RichTextFunctionSerializer<SerializerReturnType>) => SerializerReturnType[];
export declare const serialize: <SerializerReturnType, SerializerChildType = SerializerReturnType>(richTextField: RichTextField, serializer: RichTextFunctionSerializer<SerializerReturnType, SerializerChildType>) => SerializerReturnType[];

@@ -8,3 +8,3 @@ import { RichTextNodeType, RTAnyNode, RTEmbedNode, RTEmNode, RTHeading1Node, RTHeading2Node, RTHeading3Node, RTHeading4Node, RTHeading5Node, RTHeading6Node, RTImageNode, RTLabelNode, RTLinkNode, RTListItemNode, RTListNode, RTOListItemNode, RTOListNode, RTParagraphNode, RTPreformattedNode, RTSpanNode, RTStrongNode } from "@prismicio/types";

*/
export type RichTextFunctionSerializer<ReturnType> = (type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType], node: RTAnyNode, text: string | undefined, children: ReturnType[], key: string) => ReturnType | null | undefined;
export type RichTextFunctionSerializer<ReturnType, ChildType = ReturnType> = (type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType], node: RTAnyNode, text: string | undefined, children: ChildType[], key: string) => ReturnType | null | undefined;
/**

@@ -16,7 +16,7 @@ * Map serializer's tag function serializer, can be helpful for typing those

*/
export type RichTextMapSerializerFunction<ReturnType, Node extends RTAnyNode = RTAnyNode, TextType = string | undefined> = (payload: {
export type RichTextMapSerializerFunction<ReturnType, ChildType = ReturnType, Node extends RTAnyNode = RTAnyNode, TextType = string | undefined> = (payload: {
type: Node["type"];
node: Node;
text: TextType;
children: ReturnType[];
children: ChildType[];
key: string;

@@ -33,22 +33,22 @@ }) => ReturnType | null | undefined;

*/
export type RichTextMapSerializer<ReturnType> = {
heading1?: RichTextMapSerializerFunction<ReturnType, RTHeading1Node, undefined>;
heading2?: RichTextMapSerializerFunction<ReturnType, RTHeading2Node, undefined>;
heading3?: RichTextMapSerializerFunction<ReturnType, RTHeading3Node, undefined>;
heading4?: RichTextMapSerializerFunction<ReturnType, RTHeading4Node, undefined>;
heading5?: RichTextMapSerializerFunction<ReturnType, RTHeading5Node, undefined>;
heading6?: RichTextMapSerializerFunction<ReturnType, RTHeading6Node, undefined>;
paragraph?: RichTextMapSerializerFunction<ReturnType, RTParagraphNode, undefined>;
preformatted?: RichTextMapSerializerFunction<ReturnType, RTPreformattedNode, undefined>;
strong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>;
em?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>;
listItem?: RichTextMapSerializerFunction<ReturnType, RTListItemNode, undefined>;
oListItem?: RichTextMapSerializerFunction<ReturnType, RTOListItemNode, undefined>;
list?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>;
oList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>;
image?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>;
embed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>;
hyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>;
label?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>;
span?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>;
export type RichTextMapSerializer<ReturnType, ChildType = ReturnType> = {
heading1?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading1Node, undefined>;
heading2?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading2Node, undefined>;
heading3?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading3Node, undefined>;
heading4?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading4Node, undefined>;
heading5?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading5Node, undefined>;
heading6?: RichTextMapSerializerFunction<ReturnType, ChildType, RTHeading6Node, undefined>;
paragraph?: RichTextMapSerializerFunction<ReturnType, ChildType, RTParagraphNode, undefined>;
preformatted?: RichTextMapSerializerFunction<ReturnType, ChildType, RTPreformattedNode, undefined>;
strong?: RichTextMapSerializerFunction<ReturnType, ChildType, RTStrongNode, string>;
em?: RichTextMapSerializerFunction<ReturnType, ChildType, RTEmNode, string>;
listItem?: RichTextMapSerializerFunction<ReturnType, ChildType, RTListItemNode, undefined>;
oListItem?: RichTextMapSerializerFunction<ReturnType, ChildType, RTOListItemNode, undefined>;
list?: RichTextMapSerializerFunction<ReturnType, ChildType, RTListNode, undefined>;
oList?: RichTextMapSerializerFunction<ReturnType, ChildType, RTOListNode, undefined>;
image?: RichTextMapSerializerFunction<ReturnType, ChildType, RTImageNode, undefined>;
embed?: RichTextMapSerializerFunction<ReturnType, ChildType, RTEmbedNode, undefined>;
hyperlink?: RichTextMapSerializerFunction<ReturnType, ChildType, RTLinkNode, string>;
label?: RichTextMapSerializerFunction<ReturnType, ChildType, RTLabelNode, string>;
span?: RichTextMapSerializerFunction<ReturnType, ChildType, RTSpanNode, string>;
};

@@ -55,0 +55,0 @@ export interface Tree {

@@ -13,2 +13,2 @@ import { RichTextFunctionSerializer, RichTextMapSerializer } from "./types";

*/
export declare const wrapMapSerializer: <SerializerReturnType>(mapSerializer: RichTextMapSerializer<SerializerReturnType>) => RichTextFunctionSerializer<SerializerReturnType>;
export declare const wrapMapSerializer: <SerializerReturnType, SerializerChildType = SerializerReturnType>(mapSerializer: RichTextMapSerializer<SerializerReturnType, SerializerChildType>) => RichTextFunctionSerializer<SerializerReturnType, SerializerChildType>;
{
"name": "@prismicio/richtext",
"version": "2.1.4",
"version": "2.2.0-alpha.0",
"description": "A parser and serializer for Prismic's Rich Text format",

@@ -5,0 +5,0 @@ "keywords": [

@@ -15,8 +15,11 @@ import { RichTextFunctionSerializer } from "./types";

*/
export const composeSerializers = <SerializerReturnType>(
export const composeSerializers = <
SerializerReturnType,
SerializerChildType = SerializerReturnType,
>(
...serializers: (
| RichTextFunctionSerializer<SerializerReturnType>
| RichTextFunctionSerializer<SerializerReturnType, SerializerChildType>
| undefined
)[]
): RichTextFunctionSerializer<SerializerReturnType> => {
): RichTextFunctionSerializer<SerializerReturnType, SerializerChildType> => {
return (...args) => {

@@ -23,0 +26,0 @@ for (let i = 0; i < serializers.length; i++) {

@@ -14,2 +14,4 @@ export { asTree } from "./asTree";

RichTextMapSerializerFunction,
Tree,
TreeNode,
} from "./types";

@@ -18,7 +18,13 @@ import { RichTextField } from "@prismicio/types";

*/
export const serialize = <SerializerReturnType>(
export const serialize = <
SerializerReturnType,
SerializerChildType = SerializerReturnType,
>(
richTextField: RichTextField,
serializer: RichTextFunctionSerializer<SerializerReturnType>,
serializer: RichTextFunctionSerializer<
SerializerReturnType,
SerializerChildType
>,
): SerializerReturnType[] => {
return serializeTreeNodes<SerializerReturnType>(
return serializeTreeNodes<SerializerReturnType, SerializerChildType>(
asTree(richTextField).children,

@@ -29,7 +35,13 @@ serializer,

const serializeTreeNodes = <T>(
const serializeTreeNodes = <
SerializerReturnType,
SerializerChildType = SerializerReturnType,
>(
nodes: TreeNode[],
serializer: RichTextFunctionSerializer<T>,
): T[] => {
const serializedTreeNodes: T[] = [];
serializer: RichTextFunctionSerializer<
SerializerReturnType,
SerializerChildType
>,
): SerializerReturnType[] => {
const serializedTreeNodes: SerializerReturnType[] = [];

@@ -36,0 +48,0 @@ for (let i = 0; i < nodes.length; i++) {

@@ -33,7 +33,7 @@ import {

*/
export type RichTextFunctionSerializer<ReturnType> = (
export type RichTextFunctionSerializer<ReturnType, ChildType = ReturnType> = (
type: (typeof RichTextNodeType)[keyof typeof RichTextNodeType],
node: RTAnyNode,
text: string | undefined,
children: ReturnType[],
children: ChildType[],
key: string,

@@ -50,2 +50,3 @@ ) => ReturnType | null | undefined;

ReturnType,
ChildType = ReturnType,
Node extends RTAnyNode = RTAnyNode,

@@ -57,3 +58,3 @@ TextType = string | undefined,

text: TextType;
children: ReturnType[];
children: ChildType[];
key: string;

@@ -71,5 +72,6 @@ }) => ReturnType | null | undefined;

*/
export type RichTextMapSerializer<ReturnType> = {
export type RichTextMapSerializer<ReturnType, ChildType = ReturnType> = {
heading1?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTHeading1Node,

@@ -80,2 +82,3 @@ undefined

ReturnType,
ChildType,
RTHeading2Node,

@@ -86,2 +89,3 @@ undefined

ReturnType,
ChildType,
RTHeading3Node,

@@ -92,2 +96,3 @@ undefined

ReturnType,
ChildType,
RTHeading4Node,

@@ -98,2 +103,3 @@ undefined

ReturnType,
ChildType,
RTHeading5Node,

@@ -104,2 +110,3 @@ undefined

ReturnType,
ChildType,
RTHeading6Node,

@@ -110,2 +117,3 @@ undefined

ReturnType,
ChildType,
RTParagraphNode,

@@ -116,9 +124,16 @@ undefined

ReturnType,
ChildType,
RTPreformattedNode,
undefined
>;
strong?: RichTextMapSerializerFunction<ReturnType, RTStrongNode, string>;
em?: RichTextMapSerializerFunction<ReturnType, RTEmNode, string>;
strong?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTStrongNode,
string
>;
em?: RichTextMapSerializerFunction<ReturnType, ChildType, RTEmNode, string>;
listItem?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTListItemNode,

@@ -129,12 +144,48 @@ undefined

ReturnType,
ChildType,
RTOListItemNode,
undefined
>;
list?: RichTextMapSerializerFunction<ReturnType, RTListNode, undefined>;
oList?: RichTextMapSerializerFunction<ReturnType, RTOListNode, undefined>;
image?: RichTextMapSerializerFunction<ReturnType, RTImageNode, undefined>;
embed?: RichTextMapSerializerFunction<ReturnType, RTEmbedNode, undefined>;
hyperlink?: RichTextMapSerializerFunction<ReturnType, RTLinkNode, string>;
label?: RichTextMapSerializerFunction<ReturnType, RTLabelNode, string>;
span?: RichTextMapSerializerFunction<ReturnType, RTSpanNode, string>;
list?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTListNode,
undefined
>;
oList?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTOListNode,
undefined
>;
image?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTImageNode,
undefined
>;
embed?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTEmbedNode,
undefined
>;
hyperlink?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTLinkNode,
string
>;
label?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTLabelNode,
string
>;
span?: RichTextMapSerializerFunction<
ReturnType,
ChildType,
RTSpanNode,
string
>;
};

@@ -141,0 +192,0 @@

@@ -18,7 +18,16 @@ import {

*/
export const wrapMapSerializer = <SerializerReturnType>(
mapSerializer: RichTextMapSerializer<SerializerReturnType>,
): RichTextFunctionSerializer<SerializerReturnType> => {
export const wrapMapSerializer = <
SerializerReturnType,
SerializerChildType = SerializerReturnType,
>(
mapSerializer: RichTextMapSerializer<
SerializerReturnType,
SerializerChildType
>,
): RichTextFunctionSerializer<SerializerReturnType, SerializerChildType> => {
return (type, node, text, children, key) => {
const tagSerializer: RichTextMapSerializer<SerializerReturnType>[keyof RichTextMapSerializer<SerializerReturnType>] =
const tagSerializer: RichTextMapSerializer<
SerializerReturnType,
SerializerChildType
>[keyof RichTextMapSerializer<SerializerReturnType, SerializerChildType>] =
mapSerializer[

@@ -25,0 +34,0 @@ (RichTextReversedNodeType[

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc