{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "csv-docs",
  "title": "Serializing CSV",
  "description": "Documentation for Serializing CSV",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(serializing)/csv.mdx",
      "content": "---\ntitle: Serializing CSV\n---\n\n<ComponentPreview name=\"csv-demo\" />\n\n<PackageInfo>\n\n## Features\n\n- Convert CSV content to Plate table format\n- Configurable error tolerance for parsing malformed CSV data\n\n<Callout className=\"my-4\" type=\"note\">\n  Converting a Plate value to CSV is not yet supported.\n</Callout>\n\n</PackageInfo>\n\n## Manual Usage\n\n<Steps>\n\n### Installation\n\n```bash\nnpm install @platejs/csv\n```\n\n### Add Plugin\n\n```tsx\nimport { CsvPlugin } from '@platejs/csv';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    CsvPlugin,\n  ],\n});\n```\n\n### Configure Plugin\n\n```tsx\nimport { CsvPlugin } from '@platejs/csv';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    CsvPlugin.configure({\n      options: {\n        errorTolerance: 0.1,\n        parseOptions: {\n          header: true,\n          skipEmptyLines: true,\n          delimiter: ',',\n        },\n      },\n    }),\n  ],\n});\n```\n\n- `options.errorTolerance`: Percentage of rows that can contain errors (default: `0.25` for 25%)\n- `options.parseOptions`: Configuration passed to PapaParse library for CSV parsing\n- `options.parseOptions.header`: Treat first row as headers (default: `true`)\n\n</Steps>\n\n## Usage\n\n### CSV to Plate\n\nUse the API method to deserialize CSV data:\n\n```tsx\n// Deserialize CSV string to Plate format\nconst csvData = `Name,Age,City\nJohn,30,New York\nJane,25,Boston`;\n\nconst nodes = editor.api.csv.deserialize({ data: csvData });\n```\n\n## Plugins\n\n### CsvPlugin\n\nPlugin for CSV deserialization functionality.\n\n<API name=\"CsvPlugin\">\n<APIOptions>\n  <APIItem name=\"errorTolerance\" type=\"number\" optional>\n    The tolerance for errors in the CSV data, represented as a percentage in decimal form. This value is calculated as the ratio of errors to the total number of rows.\n\n    - **Default:** `0.25` (This indicates that up to 25% of the rows can contain errors.)\n  </APIItem>\n  <APIItem name=\"parseOptions\" type=\"ParseConfig\" optional>\n    Options to be passed to the PapaParse library for parsing CSV data.\n\n    - **Default:** `{ header: true }` (Indicating that the first row of the CSV data should be treated as a header.)\n    - See [PapaParse documentation](https://www.papaparse.com/docs#config) for more details about these options.\n  </APIItem>\n</APIOptions>\n</API>\n\n## API\n\n### api.csv.deserialize\n\nTakes a CSV (Comma Separated Values) string and converts it into a Plate compatible format. This function uses the `papaparse` library to parse the CSV data.\n\n<API name=\"deserialize\">\n<APIParameters>\n  <APIItem name=\"data\" type=\"string\">\n    The CSV data string to be deserialized.\n  </APIItem>\n  <APIItem name=\"errorTolerance\" type=\"number\" optional>\n    Percentage in decimal form, from 0 to ∞, 0 for no errors allowed. Percentage is based on number of errors compared to number of rows.\n    - **Default:** `0.25`\n  </APIItem>\n  <APIItem name=\"parseOptions\" type=\"ParseConfig\">\n    Options to be passed to the PapaParse library for parsing CSV data.\n    - **Default:** `{ header: true }`\n    - See [PapaParse documentation](https://www.papaparse.com/docs#config)\n  </APIItem>\n</APIParameters>\n\n<APIReturns type=\"Descendant[]\">\n  Array of `Descendant` nodes representing the CSV data in Plate format. Returns `undefined` if parsing fails.\n</APIReturns>\n</API>\n\nCreates a table representation of the CSV data:\n- Headers (if present) become the first row\n- Each CSV row becomes a table row\n- Uses plugins: `TablePlugin`, `TableCellHeaderPlugin`, `TableRowPlugin`, and `TableCellPlugin`\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(serializing)/csv.mdx"
    }
  ],
  "type": "registry:file"
}