Skip to main content

CSV

Installation#

npm install @udecode/plate
# or
npm install @udecode/plate-serializer-csv

Deserializer Usage#

import React from 'react';
import {
  createDeserializeCsvPlugin,
  createHighlightPlugin,
  createImagePlugin,
  createLinkPlugin,
  createListPlugin,
  createMediaEmbedPlugin,
  createMentionPlugin,
  createSoftBreakPlugin,
  createTablePlugin,
  createTodoListPlugin,
  Plate,
} from '@udecode/plate';
import { createExcalidrawPlugin } from '@udecode/plate-ui-excalidraw';
import { basicNodesPlugins } from './basic-nodes/basicNodesPlugins';
import { editableProps } from './common/editableProps';
import { plateUI } from './common/plateUI';
import { deserializeCsvValue } from './serializing-csv/deserializeCsvValue';
import { softBreakPlugin } from './soft-break/softBreakPlugin';
import { createMyPlugins, MyValue } from './typescript/plateTypes';

const plugins = createMyPlugins(
  [
    ...basicNodesPlugins,
    createImagePlugin(),
    createLinkPlugin(),
    createListPlugin(),
    createTablePlugin(),
    createTodoListPlugin(),
    createMediaEmbedPlugin(),
    createExcalidrawPlugin(),
    createHighlightPlugin(),
    createMentionPlugin(),
    createSoftBreakPlugin(softBreakPlugin),
    createDeserializeCsvPlugin(),
  ],
  {
    components: plateUI,
  }
);

export default () => (
  <Plate<MyValue>
    editableProps={editableProps}
    plugins={plugins}
    initialValue={deserializeCsvValue}
  />
);

Options#

export interface DeserializeCsvPlugin {
/**
* Percentage in decimal form, from 0 to a very large number, 0 for no errors allowed,
* Percentage based on number of errors compared to number of rows
* @default 0.25
*/
errorTolerance?: number;
}

Source Code#