@contensis/canvas-react 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -120,7 +120,7 @@ type Book = { cover: string; name: string };
120
120
  // Render a "book" component within the canvas data
121
121
  const MyBookComponent = (props: RenderBlockProps<ComponentBlock<Book>) => {
122
122
  const book = props.block?.value;
123
- if (!book) return <></>;
123
+ if (!book) return null;
124
124
  return (
125
125
  <div className="card mb-3">
126
126
  <div className="row g-0">
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import React, { FunctionComponent, ClassType, Component as Component$1, ComponentClass } from 'react';
2
2
 
3
3
  type InlineBlock = FragmentBlock | AnchorBlock | LinkBlock | InlineEntryBlock;
4
4
  type InlineChildren = string | InlineBlock[];
@@ -297,7 +297,7 @@ type TableRowBlock = {
297
297
 
298
298
  type Attributes = Record<string, any>;
299
299
  type WithChildren = {
300
- children?: JSX.Element;
300
+ children?: JSX.Element | undefined;
301
301
  };
302
302
  type RendererProps = {
303
303
  data: Block[];
@@ -309,7 +309,7 @@ type RenderBlockPropsWithChildren<T extends Block> = RenderBlockProps<T> & WithC
309
309
  type TypedBlock<TType extends Block['type']> = Extract<Block, {
310
310
  type: TType;
311
311
  }>;
312
- type BlockRenderer<T extends Block> = (props: RenderBlockPropsWithChildren<T>) => JSX.Element;
312
+ type BlockRenderer<T extends Block> = Renderer<RenderBlockPropsWithChildren<T>>;
313
313
  type BlockRenderers = {
314
314
  [TType in Block['type']]: BlockRenderer<TypedBlock<TType>>;
315
315
  };
@@ -319,9 +319,9 @@ type RenderDecoratorProps = {
319
319
  otherDecorators: undefined | DecoratorType[];
320
320
  };
321
321
  type RenderDecoratorPropsWithChildren = RenderDecoratorProps & WithChildren & Attributes;
322
- type DecoratorRenderer = (props: RenderDecoratorPropsWithChildren) => JSX.Element;
322
+ type DecoratorRenderer = Renderer<RenderDecoratorPropsWithChildren>;
323
323
  type DecoratorRenderers = Record<DecoratorType, DecoratorRenderer>;
324
- type ComponentRenderer = (props: RenderBlockPropsWithChildren<ComponentBlock>) => JSX.Element;
324
+ type ComponentRenderer = Renderer<RenderBlockPropsWithChildren<ComponentBlock>>;
325
325
  type ComponentRenderers = Record<string, ComponentRenderer>;
326
326
  type RendererContextValue = {
327
327
  blocks?: BlockRenderers;
@@ -333,12 +333,34 @@ type RendererOverridesContextValue = {
333
333
  decorators?: Partial<DecoratorRenderers>;
334
334
  components?: ComponentRenderers;
335
335
  };
336
- type RendererContextProviderProps = {
337
- children: JSX.Element;
338
- } & RendererOverridesContextValue;
336
+ type RendererContextProviderProps = WithChildren & RendererOverridesContextValue;
339
337
 
340
- declare const RendererContext: react.Context<RendererContextValue>;
338
+ declare const RendererContext: React.Context<RendererContextValue>;
339
+ /**
340
+ * Provides context to the <Renderer> component to return Canvas data as React components
341
+ *
342
+ * @link https://www.npmjs.com/package/@contensis/canvas-react#usage
343
+ *
344
+ * @param blocks - Override the default rendering of Canvas content blocks
345
+ * @param components - Render method for Contensis Components within the Canvas field
346
+ * @param decorators - Override the rendering of HTML elements within a text field
347
+ *
348
+ * @example
349
+ * <RenderContextProvider blocks={{ _table: Table }} components={{ banner: Banner }} decorators={{ strong: Strong }}>
350
+ * <Renderer data={data} />
351
+ * </RenderContextProvider>
352
+ *
353
+ */
341
354
  declare function RenderContextProvider(props: RendererContextProviderProps): JSX.Element;
355
+ type Renderer<TProps> = FunctionComponent<TProps> | ClassType<TProps, Component$1<TProps>, ComponentClass<TProps>>;
356
+ /**
357
+ * The default render method for processing Canvas data
358
+ *
359
+ * @link https://www.npmjs.com/package/@contensis/canvas-react#usage
360
+ *
361
+ * @param data - Accepts Canvas data
362
+ *
363
+ * */
342
364
  declare function Renderer(props: RendererProps): JSX.Element;
343
365
  declare function Anchor(props: RenderBlockPropsWithChildren<AnchorBlock>): JSX.Element;
344
366
  declare namespace Anchor {
@@ -392,6 +414,10 @@ declare function Paragraph(props: RenderBlockPropsWithChildren<ParagraphBlock>):
392
414
  declare namespace Paragraph {
393
415
  var Children: (props: RenderBlockProps<ParagraphBlock>) => JSX.Element;
394
416
  }
417
+ declare function Quote(props: RenderBlockPropsWithChildren<QuoteBlock>): JSX.Element;
418
+ declare namespace Quote {
419
+ var Children: (props: RenderBlockProps<QuoteBlock>) => JSX.Element;
420
+ }
395
421
  declare function Table(props: RenderBlockPropsWithChildren<TableBlock>): JSX.Element;
396
422
  declare namespace Table {
397
423
  var Children: (props: RenderBlockProps<TableBlock>) => JSX.Element;
@@ -478,4 +504,4 @@ declare namespace Variable {
478
504
  var Children: typeof DecoratorChildren;
479
505
  }
480
506
 
481
- export { Anchor, type AnchorBlock, type Block, type BlockRenderer, Code, type CodeBlock, Component, type ComponentBlock, type DecoratorType, Delete, Divider, type DividerBlock, Emphasis, Fragment, type FragmentBlock, Heading, type HeadingBlock, Image, type ImageBlock, InlineCode, InlineEntry, type InlineEntryBlock, Insert, Keyboard, LineBreak, Link, type LinkBlock, List, type ListBlock, ListItem, type ListItemBlock, Mark, Panel, type PanelBlock, Paragraph, type ParagraphBlock, type QuoteBlock, type RenderBlockProps, type RenderBlockPropsWithChildren, RenderContextProvider, type RenderDecoratorProps, type RenderDecoratorPropsWithChildren, Renderer, RendererContext, Strikethrough, Strong, Subscript, Superscript, Table, type TableBlock, TableBody, type TableBodyBlock, TableCaption, type TableCaptionBlock, TableCell, type TableCellBlock, TableFooter, type TableFooterBlock, TableHeader, type TableHeaderBlock, TableHeaderCell, type TableHeaderCellBlock, TableRow, type TableRowBlock, Underline, Variable };
507
+ export { Anchor, type AnchorBlock, type Block, type BlockRenderer, Code, type CodeBlock, Component, type ComponentBlock, type DecoratorType, Delete, Divider, type DividerBlock, Emphasis, Fragment, type FragmentBlock, Heading, type HeadingBlock, Image, type ImageBlock, InlineCode, InlineEntry, type InlineEntryBlock, Insert, Keyboard, LineBreak, Link, type LinkBlock, List, type ListBlock, ListItem, type ListItemBlock, Mark, Panel, type PanelBlock, Paragraph, type ParagraphBlock, Quote, type QuoteBlock, type RenderBlockProps, type RenderBlockPropsWithChildren, RenderContextProvider, type RenderDecoratorProps, type RenderDecoratorPropsWithChildren, Renderer, RendererContext, Strikethrough, Strong, Subscript, Superscript, Table, type TableBlock, TableBody, type TableBodyBlock, TableCaption, type TableCaptionBlock, TableCell, type TableCellBlock, TableFooter, type TableFooterBlock, TableHeader, type TableHeaderBlock, TableHeaderCell, type TableHeaderCellBlock, TableRow, type TableRowBlock, Underline, Variable };
@@ -1,4 +1,4 @@
1
- import * as react from 'react';
1
+ import React, { FunctionComponent, ClassType, Component as Component$1, ComponentClass } from 'react';
2
2
 
3
3
  type InlineBlock = FragmentBlock | AnchorBlock | LinkBlock | InlineEntryBlock;
4
4
  type InlineChildren = string | InlineBlock[];
@@ -297,7 +297,7 @@ type TableRowBlock = {
297
297
 
298
298
  type Attributes = Record<string, any>;
299
299
  type WithChildren = {
300
- children?: JSX.Element;
300
+ children?: JSX.Element | undefined;
301
301
  };
302
302
  type RendererProps = {
303
303
  data: Block[];
@@ -309,7 +309,7 @@ type RenderBlockPropsWithChildren<T extends Block> = RenderBlockProps<T> & WithC
309
309
  type TypedBlock<TType extends Block['type']> = Extract<Block, {
310
310
  type: TType;
311
311
  }>;
312
- type BlockRenderer<T extends Block> = (props: RenderBlockPropsWithChildren<T>) => JSX.Element;
312
+ type BlockRenderer<T extends Block> = Renderer<RenderBlockPropsWithChildren<T>>;
313
313
  type BlockRenderers = {
314
314
  [TType in Block['type']]: BlockRenderer<TypedBlock<TType>>;
315
315
  };
@@ -319,9 +319,9 @@ type RenderDecoratorProps = {
319
319
  otherDecorators: undefined | DecoratorType[];
320
320
  };
321
321
  type RenderDecoratorPropsWithChildren = RenderDecoratorProps & WithChildren & Attributes;
322
- type DecoratorRenderer = (props: RenderDecoratorPropsWithChildren) => JSX.Element;
322
+ type DecoratorRenderer = Renderer<RenderDecoratorPropsWithChildren>;
323
323
  type DecoratorRenderers = Record<DecoratorType, DecoratorRenderer>;
324
- type ComponentRenderer = (props: RenderBlockPropsWithChildren<ComponentBlock>) => JSX.Element;
324
+ type ComponentRenderer = Renderer<RenderBlockPropsWithChildren<ComponentBlock>>;
325
325
  type ComponentRenderers = Record<string, ComponentRenderer>;
326
326
  type RendererContextValue = {
327
327
  blocks?: BlockRenderers;
@@ -333,12 +333,34 @@ type RendererOverridesContextValue = {
333
333
  decorators?: Partial<DecoratorRenderers>;
334
334
  components?: ComponentRenderers;
335
335
  };
336
- type RendererContextProviderProps = {
337
- children: JSX.Element;
338
- } & RendererOverridesContextValue;
336
+ type RendererContextProviderProps = WithChildren & RendererOverridesContextValue;
339
337
 
340
- declare const RendererContext: react.Context<RendererContextValue>;
338
+ declare const RendererContext: React.Context<RendererContextValue>;
339
+ /**
340
+ * Provides context to the <Renderer> component to return Canvas data as React components
341
+ *
342
+ * @link https://www.npmjs.com/package/@contensis/canvas-react#usage
343
+ *
344
+ * @param blocks - Override the default rendering of Canvas content blocks
345
+ * @param components - Render method for Contensis Components within the Canvas field
346
+ * @param decorators - Override the rendering of HTML elements within a text field
347
+ *
348
+ * @example
349
+ * <RenderContextProvider blocks={{ _table: Table }} components={{ banner: Banner }} decorators={{ strong: Strong }}>
350
+ * <Renderer data={data} />
351
+ * </RenderContextProvider>
352
+ *
353
+ */
341
354
  declare function RenderContextProvider(props: RendererContextProviderProps): JSX.Element;
355
+ type Renderer<TProps> = FunctionComponent<TProps> | ClassType<TProps, Component$1<TProps>, ComponentClass<TProps>>;
356
+ /**
357
+ * The default render method for processing Canvas data
358
+ *
359
+ * @link https://www.npmjs.com/package/@contensis/canvas-react#usage
360
+ *
361
+ * @param data - Accepts Canvas data
362
+ *
363
+ * */
342
364
  declare function Renderer(props: RendererProps): JSX.Element;
343
365
  declare function Anchor(props: RenderBlockPropsWithChildren<AnchorBlock>): JSX.Element;
344
366
  declare namespace Anchor {
@@ -392,6 +414,10 @@ declare function Paragraph(props: RenderBlockPropsWithChildren<ParagraphBlock>):
392
414
  declare namespace Paragraph {
393
415
  var Children: (props: RenderBlockProps<ParagraphBlock>) => JSX.Element;
394
416
  }
417
+ declare function Quote(props: RenderBlockPropsWithChildren<QuoteBlock>): JSX.Element;
418
+ declare namespace Quote {
419
+ var Children: (props: RenderBlockProps<QuoteBlock>) => JSX.Element;
420
+ }
395
421
  declare function Table(props: RenderBlockPropsWithChildren<TableBlock>): JSX.Element;
396
422
  declare namespace Table {
397
423
  var Children: (props: RenderBlockProps<TableBlock>) => JSX.Element;
@@ -478,4 +504,4 @@ declare namespace Variable {
478
504
  var Children: typeof DecoratorChildren;
479
505
  }
480
506
 
481
- export { Anchor, type AnchorBlock, type Block, type BlockRenderer, Code, type CodeBlock, Component, type ComponentBlock, type DecoratorType, Delete, Divider, type DividerBlock, Emphasis, Fragment, type FragmentBlock, Heading, type HeadingBlock, Image, type ImageBlock, InlineCode, InlineEntry, type InlineEntryBlock, Insert, Keyboard, LineBreak, Link, type LinkBlock, List, type ListBlock, ListItem, type ListItemBlock, Mark, Panel, type PanelBlock, Paragraph, type ParagraphBlock, type QuoteBlock, type RenderBlockProps, type RenderBlockPropsWithChildren, RenderContextProvider, type RenderDecoratorProps, type RenderDecoratorPropsWithChildren, Renderer, RendererContext, Strikethrough, Strong, Subscript, Superscript, Table, type TableBlock, TableBody, type TableBodyBlock, TableCaption, type TableCaptionBlock, TableCell, type TableCellBlock, TableFooter, type TableFooterBlock, TableHeader, type TableHeaderBlock, TableHeaderCell, type TableHeaderCellBlock, TableRow, type TableRowBlock, Underline, Variable };
507
+ export { Anchor, type AnchorBlock, type Block, type BlockRenderer, Code, type CodeBlock, Component, type ComponentBlock, type DecoratorType, Delete, Divider, type DividerBlock, Emphasis, Fragment, type FragmentBlock, Heading, type HeadingBlock, Image, type ImageBlock, InlineCode, InlineEntry, type InlineEntryBlock, Insert, Keyboard, LineBreak, Link, type LinkBlock, List, type ListBlock, ListItem, type ListItemBlock, Mark, Panel, type PanelBlock, Paragraph, type ParagraphBlock, Quote, type QuoteBlock, type RenderBlockProps, type RenderBlockPropsWithChildren, RenderContextProvider, type RenderDecoratorProps, type RenderDecoratorPropsWithChildren, Renderer, RendererContext, Strikethrough, Strong, Subscript, Superscript, Table, type TableBlock, TableBody, type TableBodyBlock, TableCaption, type TableCaptionBlock, TableCell, type TableCellBlock, TableFooter, type TableFooterBlock, TableHeader, type TableHeaderBlock, TableHeaderCell, type TableHeaderCellBlock, TableRow, type TableRowBlock, Underline, Variable };