react-markdown-table-ts 0.6.4 → 1.1.1
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 +88 -49
- package/dist/MarkdownTable.stories.d.ts +143 -0
- package/dist/index.cjs.js +131 -14495
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +125 -14470
- package/dist/index.esm.js.map +1 -1
- package/dist/stories/Button.d.ts +15 -0
- package/dist/stories/Button.stories.d.ts +23 -0
- package/dist/stories/Header.d.ts +12 -0
- package/dist/stories/Header.stories.d.ts +18 -0
- package/dist/stories/Page.d.ts +3 -0
- package/dist/stories/Page.stories.d.ts +13 -0
- package/dist/types.d.ts +63 -22
- package/dist/utils.d.ts +4 -31
- package/package.json +14 -4
@@ -0,0 +1,15 @@
|
|
1
|
+
import './button.css';
|
2
|
+
export interface ButtonProps {
|
3
|
+
/** Is this the principal call to action on the page? */
|
4
|
+
primary?: boolean;
|
5
|
+
/** What background color to use */
|
6
|
+
backgroundColor?: string;
|
7
|
+
/** How large should the button be? */
|
8
|
+
size?: 'small' | 'medium' | 'large';
|
9
|
+
/** Button contents */
|
10
|
+
label: string;
|
11
|
+
/** Optional click handler */
|
12
|
+
onClick?: () => void;
|
13
|
+
}
|
14
|
+
/** Primary UI component for user interaction */
|
15
|
+
export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
2
|
+
declare const meta: {
|
3
|
+
title: string;
|
4
|
+
component: ({ primary, size, backgroundColor, label, ...props }: import("./Button").ButtonProps) => import("react/jsx-runtime").JSX.Element;
|
5
|
+
parameters: {
|
6
|
+
layout: string;
|
7
|
+
};
|
8
|
+
tags: string[];
|
9
|
+
argTypes: {
|
10
|
+
backgroundColor: {
|
11
|
+
control: "color";
|
12
|
+
};
|
13
|
+
};
|
14
|
+
args: {
|
15
|
+
onClick: import("@vitest/spy").Mock<(...args: any[]) => any>;
|
16
|
+
};
|
17
|
+
};
|
18
|
+
export default meta;
|
19
|
+
type Story = StoryObj<typeof meta>;
|
20
|
+
export declare const Primary: Story;
|
21
|
+
export declare const Secondary: Story;
|
22
|
+
export declare const Large: Story;
|
23
|
+
export declare const Small: Story;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import './header.css';
|
2
|
+
type User = {
|
3
|
+
name: string;
|
4
|
+
};
|
5
|
+
export interface HeaderProps {
|
6
|
+
user?: User;
|
7
|
+
onLogin?: () => void;
|
8
|
+
onLogout?: () => void;
|
9
|
+
onCreateAccount?: () => void;
|
10
|
+
}
|
11
|
+
export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => import("react/jsx-runtime").JSX.Element;
|
12
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
2
|
+
declare const meta: {
|
3
|
+
title: string;
|
4
|
+
component: ({ user, onLogin, onLogout, onCreateAccount }: import("./Header").HeaderProps) => import("react/jsx-runtime").JSX.Element;
|
5
|
+
tags: string[];
|
6
|
+
parameters: {
|
7
|
+
layout: string;
|
8
|
+
};
|
9
|
+
args: {
|
10
|
+
onLogin: import("@vitest/spy").Mock<(...args: any[]) => any>;
|
11
|
+
onLogout: import("@vitest/spy").Mock<(...args: any[]) => any>;
|
12
|
+
onCreateAccount: import("@vitest/spy").Mock<(...args: any[]) => any>;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
export default meta;
|
16
|
+
type Story = StoryObj<typeof meta>;
|
17
|
+
export declare const LoggedIn: Story;
|
18
|
+
export declare const LoggedOut: Story;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import type { StoryObj } from '@storybook/react';
|
3
|
+
declare const meta: {
|
4
|
+
title: string;
|
5
|
+
component: import("react").FC<{}>;
|
6
|
+
parameters: {
|
7
|
+
layout: string;
|
8
|
+
};
|
9
|
+
};
|
10
|
+
export default meta;
|
11
|
+
type Story = StoryObj<typeof meta>;
|
12
|
+
export declare const LoggedOut: Story;
|
13
|
+
export declare const LoggedIn: Story;
|
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
|
28
|
+
columnAlignments?: readonly Alignment[];
|
33
29
|
/**
|
34
|
-
*
|
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
|
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
|
-
*
|
47
|
+
* Indicates whether the first row of `data` is a header.
|
48
|
+
* @default true
|
46
49
|
*/
|
47
|
-
|
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
|
-
|
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
|
64
|
-
*
|
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
|
-
|
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
|
73
|
-
* @default false
|
90
|
+
* Optional callback function to receive the generated Markdown table string.
|
74
91
|
*/
|
75
|
-
|
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,35 +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
|
-
|
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 formatHeaderAndAlignment(inputData: InputData, maxColumnCount: number, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths: number[] | undefined, useTabs: boolean, replaceNewlines: boolean, hasPadding: boolean): string;
|
13
|
-
export declare function formatBodyRows(inputData: InputData, maxColumnCount: number, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths: number[] | undefined, useTabs: boolean, replaceNewlines: boolean, hasPadding: boolean): string;
|
14
|
-
export declare function formatTableRows(inputData: InputData, maxColumnCount: number, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths: number[] | undefined, useTabs: boolean, replaceNewlines: boolean, hasPadding: boolean): string;
|
15
|
-
export declare function generateMarkdownTableString(inputData: InputData, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], canAdjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean, hasPadding?: boolean): string;
|
16
|
-
/**
|
17
|
-
* Replaces newline characters in a string with <br> tags.
|
18
|
-
* @param cell - The cell content to process.
|
19
|
-
* @returns The processed cell content with newlines replaced.
|
20
|
-
*/
|
3
|
+
export declare function generateMarkdownTableString(inputData: InputData, columnAlignments: readonly Alignment[], canAdjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean, hasPadding?: boolean): string;
|
21
4
|
export declare function replaceNewlinesInCell(cell: string): string;
|
22
|
-
/**
|
23
|
-
* Converts a zero-based column index to its corresponding Excel-style column name.
|
24
|
-
* For example, 0 -> 'A', 1 -> 'B', ..., 25 -> 'Z', 26 -> 'AA', etc.
|
25
|
-
* @param index - The zero-based column index.
|
26
|
-
* @returns The corresponding column name.
|
27
|
-
*/
|
28
5
|
export declare function getColumnName(index: number): string;
|
29
|
-
/**
|
30
|
-
* Generates an array of alphabetic headers based on the specified column count.
|
31
|
-
* @param columnCount - The number of columns.
|
32
|
-
* @returns An array of column header names.
|
33
|
-
*/
|
34
6
|
export declare function generateAlphabetHeaders(columnCount: number): string[];
|
35
|
-
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;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-markdown-table-ts",
|
3
|
-
"version": "
|
3
|
+
"version": "1.1.1",
|
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",
|
@@ -22,7 +22,9 @@
|
|
22
22
|
"test": "jest --config jest.config.js --coverage",
|
23
23
|
"test:watch": "jest --config jest.config.js --watch",
|
24
24
|
"test:ci": "jest --config jest.config.js --coverage --ci",
|
25
|
-
"release": "standard-version"
|
25
|
+
"release": "standard-version",
|
26
|
+
"storybook": "storybook dev -p 6006",
|
27
|
+
"build-storybook": "storybook build"
|
26
28
|
},
|
27
29
|
"keywords": [
|
28
30
|
"markdown",
|
@@ -47,9 +49,16 @@
|
|
47
49
|
"react-dom": "^18.2.0"
|
48
50
|
},
|
49
51
|
"devDependencies": {
|
52
|
+
"@chromatic-com/storybook": "^3.2.2",
|
50
53
|
"@rollup/plugin-commonjs": "^26.0.3",
|
51
54
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
52
55
|
"@rollup/plugin-typescript": "^11.1.6",
|
56
|
+
"@storybook/addon-essentials": "^8.4.5",
|
57
|
+
"@storybook/addon-interactions": "^8.4.5",
|
58
|
+
"@storybook/addon-onboarding": "^8.4.5",
|
59
|
+
"@storybook/blocks": "^8.4.5",
|
60
|
+
"@storybook/react-vite": "^8.4.5",
|
61
|
+
"@storybook/test": "^8.4.5",
|
53
62
|
"@testing-library/jest-dom": "^6.5.0",
|
54
63
|
"@testing-library/react": "^16.0.1",
|
55
64
|
"@types/jest": "^29.5.13",
|
@@ -57,6 +66,7 @@
|
|
57
66
|
"@types/prismjs": "^1.26.4",
|
58
67
|
"@types/react": "^18.3.8",
|
59
68
|
"@types/react-dom": "^18.3.0",
|
69
|
+
"eslint-plugin-storybook": "^0.11.1",
|
60
70
|
"gts": "^5.3.1",
|
61
71
|
"identity-obj-proxy": "^3.0.0",
|
62
72
|
"jest": "^29.7.0",
|
@@ -66,14 +76,14 @@
|
|
66
76
|
"rollup": "^2.79.1",
|
67
77
|
"rollup-plugin-typescript2": "^0.36.0",
|
68
78
|
"standard-version": "^9.5.0",
|
79
|
+
"storybook": "^8.4.5",
|
69
80
|
"ts-jest": "^29.2.5",
|
70
81
|
"typescript": "^5.1.6"
|
71
82
|
},
|
72
83
|
"dependencies": {
|
73
84
|
"@emotion/react": "^11.13.5",
|
74
85
|
"@emotion/styled": "^11.13.5",
|
75
|
-
"@
|
76
|
-
"@mui/material": "^6.1.8",
|
86
|
+
"@storybook/react": "^8.4.5",
|
77
87
|
"prismjs": "^1.29.0"
|
78
88
|
}
|
79
89
|
}
|