react-markdown-table-ts 0.6.3 → 1.1.0

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/dist/types.d.ts CHANGED
@@ -20,57 +20,98 @@ export interface MarkdownTableProps {
20
20
  * @default null
21
21
  */
22
22
  inputData?: string[][] | null;
23
- /**
24
- * Indicates whether the first row of `data` is a header.
25
- * @default true
26
- */
27
- hasHeader?: boolean;
28
23
  /**
29
24
  * Optional array specifying the alignment for each column.
30
25
  * Acceptable values are 'left', 'center', 'right', or 'none'.
26
+ * @default []
31
27
  */
32
- columnAlignments?: readonly ('left' | 'center' | 'right' | 'none')[];
28
+ columnAlignments?: readonly Alignment[];
33
29
  /**
34
- * Optional flag to provide a compact version of the table with minimal column widths.
35
- * When `true`, column widths are not adjusted based on content.
30
+ * Disables column width alignment to provide a more compact markdown table string.
36
31
  * @default false
37
32
  */
38
33
  isCompact?: boolean;
39
34
  /**
40
- * Optional flag to add tabs between columns in the Markdown table.
35
+ * Optional flag to add a single space around cell content in the markdown table.
36
+ * When true, one space is added before and after the content in each cell.
37
+ * @default true
38
+ */
39
+ hasPadding?: boolean;
40
+ /**
41
+ * Optional flag to add tabs as additional padding between column pipes.
42
+ * When true, adds a tab character after each | and before the content.
41
43
  * @default false
42
44
  */
43
45
  hasTabs?: boolean;
44
46
  /**
45
- * Optional CSS class for styling the rendered Markdown table.
47
+ * Indicates whether the first row of `data` is a header.
48
+ * @default true
46
49
  */
47
- className?: string;
50
+ hasHeader?: boolean;
48
51
  /**
49
52
  * Optional flag to replace newlines with <br> tags in table cells.
50
53
  * @default false
51
54
  */
52
- canReplaceNewlines?: boolean;
53
- /**
54
- * Optional callback function to receive the generated Markdown table string.
55
- */
56
- onTableCreate?: (markdownTableString: string) => void;
55
+ convertLineBreaks?: boolean;
57
56
  /**
58
57
  * Optional theme for the Markdown table.
59
58
  * Acceptable values are 'light' or 'dark'.
59
+ * @default 'light'
60
60
  */
61
61
  theme?: 'light' | 'dark';
62
62
  /**
63
- * Optional flag to add padding spaces around cell content.
64
- * @default true
63
+ * Optional CSS class for styling the rendered Markdown table.
64
+ * This class will be applied to the <pre> element containing the table.
65
+ * It will be combined with built-in classes for syntax highlighting.
66
+ * @default undefined
67
+ * @example
68
+ * <MarkdownTable
69
+ * inputData={data}
70
+ * className="custom-table-style"
71
+ * />
65
72
  */
66
- hasPadding?: boolean;
73
+ className?: string;
67
74
  /**
68
75
  * Optional CSS properties to apply to the pre element containing the Markdown table.
76
+ * Allows direct styling of the table container using React's style prop.
77
+ * @default undefined
78
+ * @example
79
+ * <MarkdownTable
80
+ * inputData={data}
81
+ * preStyle={{
82
+ * maxHeight: '300px',
83
+ * overflow: 'auto',
84
+ * backgroundColor: '#f5f5f5'
85
+ * }}
86
+ * />
69
87
  */
70
88
  preStyle?: React.CSSProperties;
71
89
  /**
72
- * Optional flag to show the copy button.
73
- * @default false
90
+ * Optional callback function to receive the generated Markdown table string.
74
91
  */
75
- showCopyButton?: boolean;
92
+ onGenerate?: (markdownTableString: string) => void;
93
+ }
94
+ /**
95
+ * Represents the alignment options for table columns.
96
+ */
97
+ export type Alignment = 'left' | 'right' | 'center' | 'none';
98
+ /**
99
+ * Configuration for table formatting.
100
+ */
101
+ export interface TableConfig {
102
+ columnCount: number;
103
+ columnAlignments: readonly Alignment[];
104
+ columnWidths?: readonly number[];
105
+ useTabs: boolean;
106
+ replaceNewlines: boolean;
107
+ hasPadding: boolean;
108
+ }
109
+ /**
110
+ * Functions to generate alignment indicators for table columns.
111
+ */
112
+ export interface AlignmentIndicator {
113
+ left: (width: number) => string;
114
+ right: (width: number) => string;
115
+ center: (width: number) => string;
116
+ none: (width: number) => string;
76
117
  }
package/dist/utils.d.ts CHANGED
@@ -1,32 +1,8 @@
1
- import { TableRow, InputData } from './types';
2
- /**
3
- * Calculates the maximum width for each column based on the content.
4
- * @param tableRows - All rows (header and body) of the table.
5
- * @param maxColumnCount - The maximum number of columns in the table.
6
- * @returns An array of maximum widths for each column.
7
- */
1
+ import { TableRow, InputData, Alignment } from './types';
8
2
  export declare function calculateColumnWidths(tableRows: readonly TableRow[], maxColumnCount: number): number[];
9
- type Alignment = 'left' | 'right' | 'center' | 'none';
10
- export declare function formatMarkdownRow(columnCount: number, currentRow: TableRow, columnAlignments: readonly Alignment[], columnWidths?: readonly number[], useTabs?: boolean, canReplaceNewlines?: boolean, hasPadding?: boolean): string;
11
- export declare function formatAlignmentRow(columnCount: number, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths?: readonly number[], useTabs?: boolean, hasPadding?: boolean): string;
12
- export declare function generateMarkdownTableString(inputData: InputData, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], canAdjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean, hasPadding?: boolean): string;
13
- /**
14
- * Replaces newline characters in a string with <br> tags.
15
- * @param cell - The cell content to process.
16
- * @returns The processed cell content with newlines replaced.
17
- */
3
+ export declare function generateMarkdownTableString(inputData: InputData, columnAlignments: readonly Alignment[], canAdjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean, hasPadding?: boolean): string;
18
4
  export declare function replaceNewlinesInCell(cell: string): string;
19
- /**
20
- * Converts a zero-based column index to its corresponding Excel-style column name.
21
- * For example, 0 -> 'A', 1 -> 'B', ..., 25 -> 'Z', 26 -> 'AA', etc.
22
- * @param index - The zero-based column index.
23
- * @returns The corresponding column name.
24
- */
25
5
  export declare function getColumnName(index: number): string;
26
- /**
27
- * Generates an array of alphabetic headers based on the specified column count.
28
- * @param columnCount - The number of columns.
29
- * @returns An array of column header names.
30
- */
31
6
  export declare function generateAlphabetHeaders(columnCount: number): string[];
32
- export {};
7
+ export declare function formatMarkdownRow(columnCount: number, currentRow: TableRow, columnAlignments: readonly Alignment[], columnWidths?: readonly number[], useTabs?: boolean, canReplaceNewlines?: boolean, hasPadding?: boolean): string;
8
+ export declare function formatAlignmentRow(columnCount: number, columnAlignments: readonly Alignment[], columnWidths?: readonly number[], useTabs?: boolean, hasPadding?: boolean): string;
@@ -5,6 +5,12 @@ import { MarkdownTableProps } from './types';
5
5
  export declare class MarkdownTableError extends Error {
6
6
  constructor(message: string);
7
7
  }
8
+ /**
9
+ * Validates that the input data is a non-empty two-dimensional array.
10
+ * @param inputData - The data to validate
11
+ * @throws {MarkdownTableError} If validation fails
12
+ */
13
+ export declare function validateInputData(inputData: unknown): void;
8
14
  /**
9
15
  * Validates the structure of the table data based on the `hasHeader` flag.
10
16
  * Throws an error if validation fails.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-markdown-table-ts",
3
- "version": "0.6.3",
3
+ "version": "1.1.0",
4
4
  "description": "A React component that converts structured data into Markdown table syntax and displays it within a `<pre>` tag.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -72,8 +72,6 @@
72
72
  "dependencies": {
73
73
  "@emotion/react": "^11.13.5",
74
74
  "@emotion/styled": "^11.13.5",
75
- "@mui/icons-material": "^6.1.8",
76
- "@mui/material": "^6.1.8",
77
75
  "prismjs": "^1.29.0"
78
76
  }
79
77
  }