react-markdown-table-ts 1.1.8 → 1.2.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/README.md +90 -56
- package/dist/cellFormatter.d.ts +9 -0
- package/dist/index.cjs.js +51 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +51 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/types.d.ts +16 -4
- package/dist/utils.d.ts +4 -4
- package/package.json +1 -1
- package/dist/MarkdownTable.stories.d.ts +0 -156
- package/dist/jest.setup.d.ts +0 -2
- package/dist/jest.setup.js +0 -3
- package/dist/jest.setup.js.map +0 -1
- package/dist/src/MarkdownTable.stories.d.ts +0 -156
- package/dist/src/MarkdownTable.stories.js +0 -172
- package/dist/src/MarkdownTable.stories.js.map +0 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +0 -78
- package/dist/src/index.js.map +0 -1
- package/dist/src/types.d.ts +0 -123
- package/dist/src/types.js +0 -3
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.d.ts +0 -8
- package/dist/src/utils.js +0 -176
- package/dist/src/utils.js.map +0 -1
- package/dist/src/validation.d.ts +0 -19
- package/dist/src/validation.js +0 -106
- package/dist/src/validation.js.map +0 -1
- package/dist/stories/Button.d.ts +0 -15
- package/dist/stories/Button.stories.d.ts +0 -23
- package/dist/stories/Header.d.ts +0 -12
- package/dist/stories/Header.stories.d.ts +0 -18
- package/dist/stories/Page.d.ts +0 -3
- package/dist/stories/Page.stories.d.ts +0 -13
- package/dist/test/MarkdownTable.test.d.ts +0 -1
- package/dist/test/MarkdownTable.test.js +0 -91
- package/dist/test/MarkdownTable.test.js.map +0 -1
- package/dist/test/utils.test.d.ts +0 -1
- package/dist/test/utils.test.js +0 -234
- package/dist/test/utils.test.js.map +0 -1
- package/dist/test/validation.test.d.ts +0 -1
- package/dist/test/validation.test.js +0 -86
- package/dist/test/validation.test.js.map +0 -1
package/dist/types.d.ts
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
/**
|
3
3
|
* Represents a single row in a table, consisting of cells.
|
4
4
|
*/
|
5
|
-
export type TableRow = readonly string[];
|
5
|
+
export type TableRow = readonly (string | CellData)[];
|
6
6
|
/**
|
7
7
|
* Represents the structure of a Markdown table.
|
8
8
|
*/
|
9
9
|
export interface InputData {
|
10
|
-
inputDataHeader: string[];
|
11
|
-
inputDataBody: readonly string[][];
|
10
|
+
inputDataHeader: (string | CellData)[];
|
11
|
+
inputDataBody: readonly (string | CellData)[][];
|
12
12
|
}
|
13
13
|
/**
|
14
14
|
* Props for the MarkdownTable component.
|
@@ -16,10 +16,11 @@ export interface InputData {
|
|
16
16
|
export interface MarkdownTableProps {
|
17
17
|
/**
|
18
18
|
* The entire table data as a two-dimensional array.
|
19
|
+
* Can be either string[][] or CellData[][].
|
19
20
|
* If `hasHeader` is true, the first row is treated as the header.
|
20
21
|
* @default null
|
21
22
|
*/
|
22
|
-
inputData?: string[][] | null;
|
23
|
+
inputData?: (string | CellData)[][] | null;
|
23
24
|
/**
|
24
25
|
* Optional array specifying the alignment for each column.
|
25
26
|
* Acceptable values are 'left', 'center', 'right', or 'none'.
|
@@ -110,6 +111,17 @@ export interface MarkdownTableProps {
|
|
110
111
|
* Represents the alignment options for table columns.
|
111
112
|
*/
|
112
113
|
export type Alignment = 'left' | 'right' | 'center' | 'none' | 'justify';
|
114
|
+
/**
|
115
|
+
* Represents cell data with content and formatting options.
|
116
|
+
*/
|
117
|
+
export interface CellData {
|
118
|
+
content: string;
|
119
|
+
alignment?: Alignment;
|
120
|
+
bold?: boolean;
|
121
|
+
italic?: boolean;
|
122
|
+
code?: boolean;
|
123
|
+
link?: string;
|
124
|
+
}
|
113
125
|
/**
|
114
126
|
* Configuration for table formatting.
|
115
127
|
*/
|
package/dist/utils.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
export declare function calculateColumnWidths(tableRows: readonly
|
1
|
+
import { InputData, Alignment, CellData } from './types';
|
2
|
+
export declare function calculateColumnWidths(tableRows: readonly (string | CellData)[][], maxColumnCount: number): number[];
|
3
3
|
export declare function generateMarkdownTableString(inputData: InputData, columnAlignments: readonly Alignment[], canAdjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean, hasPadding?: boolean): string;
|
4
|
-
export declare function replaceNewlinesInCell(cell: string): string;
|
4
|
+
export declare function replaceNewlinesInCell(cell: string | CellData): string;
|
5
5
|
export declare function getColumnName(index: number): string;
|
6
6
|
export declare function generateAlphabetHeaders(columnCount: number): string[];
|
7
|
-
export declare function formatMarkdownRow(columnCount: number, currentRow:
|
7
|
+
export declare function formatMarkdownRow(columnCount: number, currentRow: (string | CellData)[], columnAlignments: readonly Alignment[], columnWidths?: readonly number[], useTabs?: boolean, canReplaceNewlines?: boolean, hasPadding?: boolean): string;
|
8
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": "1.
|
3
|
+
"version": "1.2.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",
|
@@ -1,156 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Storybook stories for the MarkdownTable component, demonstrating
|
3
|
-
* various configurations and use cases for markdown table generation and display.
|
4
|
-
*/
|
5
|
-
/// <reference types="react" />
|
6
|
-
import type { StoryObj } from '@storybook/react';
|
7
|
-
import { MarkdownTable } from './index';
|
8
|
-
declare const meta: {
|
9
|
-
title: string;
|
10
|
-
component: import("react").FC<import("./types").MarkdownTableProps>;
|
11
|
-
parameters: {
|
12
|
-
layout: string;
|
13
|
-
};
|
14
|
-
tags: string[];
|
15
|
-
args: {
|
16
|
-
inputData: null;
|
17
|
-
columnAlignments: never[];
|
18
|
-
isCompact: false;
|
19
|
-
hasPadding: true;
|
20
|
-
hasTabs: false;
|
21
|
-
hasHeader: true;
|
22
|
-
convertLineBreaks: false;
|
23
|
-
topPadding: number;
|
24
|
-
theme: "light";
|
25
|
-
};
|
26
|
-
argTypes: {
|
27
|
-
inputData: {
|
28
|
-
control: {
|
29
|
-
type: "object";
|
30
|
-
};
|
31
|
-
description: string;
|
32
|
-
table: {
|
33
|
-
category: string;
|
34
|
-
type: {
|
35
|
-
summary: string;
|
36
|
-
};
|
37
|
-
};
|
38
|
-
};
|
39
|
-
columnAlignments: {
|
40
|
-
control: {
|
41
|
-
type: "object";
|
42
|
-
};
|
43
|
-
description: string;
|
44
|
-
table: {
|
45
|
-
category: string;
|
46
|
-
type: {
|
47
|
-
summary: string;
|
48
|
-
detail: string;
|
49
|
-
};
|
50
|
-
};
|
51
|
-
};
|
52
|
-
isCompact: {
|
53
|
-
control: "boolean";
|
54
|
-
description: string;
|
55
|
-
table: {
|
56
|
-
category: string;
|
57
|
-
type: {
|
58
|
-
summary: string;
|
59
|
-
};
|
60
|
-
};
|
61
|
-
};
|
62
|
-
hasPadding: {
|
63
|
-
control: "boolean";
|
64
|
-
description: string;
|
65
|
-
table: {
|
66
|
-
category: string;
|
67
|
-
type: {
|
68
|
-
summary: string;
|
69
|
-
};
|
70
|
-
};
|
71
|
-
};
|
72
|
-
hasTabs: {
|
73
|
-
control: "boolean";
|
74
|
-
description: string;
|
75
|
-
table: {
|
76
|
-
category: string;
|
77
|
-
type: {
|
78
|
-
summary: string;
|
79
|
-
};
|
80
|
-
};
|
81
|
-
};
|
82
|
-
hasHeader: {
|
83
|
-
control: "boolean";
|
84
|
-
description: string;
|
85
|
-
table: {
|
86
|
-
category: string;
|
87
|
-
type: {
|
88
|
-
summary: string;
|
89
|
-
};
|
90
|
-
};
|
91
|
-
};
|
92
|
-
convertLineBreaks: {
|
93
|
-
control: "boolean";
|
94
|
-
description: string;
|
95
|
-
table: {
|
96
|
-
category: string;
|
97
|
-
type: {
|
98
|
-
summary: string;
|
99
|
-
};
|
100
|
-
};
|
101
|
-
};
|
102
|
-
topPadding: {
|
103
|
-
control: {
|
104
|
-
type: "number";
|
105
|
-
};
|
106
|
-
description: string;
|
107
|
-
table: {
|
108
|
-
category: string;
|
109
|
-
type: {
|
110
|
-
summary: string;
|
111
|
-
};
|
112
|
-
};
|
113
|
-
};
|
114
|
-
theme: {
|
115
|
-
options: string[];
|
116
|
-
control: {
|
117
|
-
type: "select";
|
118
|
-
};
|
119
|
-
description: string;
|
120
|
-
table: {
|
121
|
-
category: string;
|
122
|
-
type: {
|
123
|
-
summary: string;
|
124
|
-
};
|
125
|
-
defaultValue: {
|
126
|
-
summary: string;
|
127
|
-
};
|
128
|
-
};
|
129
|
-
};
|
130
|
-
className: {
|
131
|
-
control: "text";
|
132
|
-
description: string;
|
133
|
-
table: {
|
134
|
-
category: string;
|
135
|
-
type: {
|
136
|
-
summary: string;
|
137
|
-
};
|
138
|
-
};
|
139
|
-
};
|
140
|
-
preStyle: {
|
141
|
-
control: {
|
142
|
-
type: "object";
|
143
|
-
};
|
144
|
-
description: string;
|
145
|
-
table: {
|
146
|
-
category: string;
|
147
|
-
type: {
|
148
|
-
summary: string;
|
149
|
-
};
|
150
|
-
};
|
151
|
-
};
|
152
|
-
};
|
153
|
-
};
|
154
|
-
export default meta;
|
155
|
-
type Story = StoryObj<typeof MarkdownTable>;
|
156
|
-
export declare const Default: Story;
|
package/dist/jest.setup.d.ts
DELETED
package/dist/jest.setup.js
DELETED
package/dist/jest.setup.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"jest.setup.js","sourceRoot":"","sources":["../jest.setup.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC"}
|
@@ -1,156 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Storybook stories for the MarkdownTable component, demonstrating
|
3
|
-
* various configurations and use cases for markdown table generation and display.
|
4
|
-
*/
|
5
|
-
/// <reference types="react" />
|
6
|
-
import type { StoryObj } from '@storybook/react';
|
7
|
-
import { MarkdownTable } from './index';
|
8
|
-
declare const meta: {
|
9
|
-
title: string;
|
10
|
-
component: import("react").FC<import("./types").MarkdownTableProps>;
|
11
|
-
parameters: {
|
12
|
-
layout: string;
|
13
|
-
};
|
14
|
-
tags: string[];
|
15
|
-
args: {
|
16
|
-
inputData: null;
|
17
|
-
columnAlignments: never[];
|
18
|
-
isCompact: false;
|
19
|
-
hasPadding: true;
|
20
|
-
hasTabs: false;
|
21
|
-
hasHeader: true;
|
22
|
-
convertLineBreaks: false;
|
23
|
-
topPadding: number;
|
24
|
-
theme: "light";
|
25
|
-
};
|
26
|
-
argTypes: {
|
27
|
-
inputData: {
|
28
|
-
control: {
|
29
|
-
type: "object";
|
30
|
-
};
|
31
|
-
description: string;
|
32
|
-
table: {
|
33
|
-
category: string;
|
34
|
-
type: {
|
35
|
-
summary: string;
|
36
|
-
};
|
37
|
-
};
|
38
|
-
};
|
39
|
-
columnAlignments: {
|
40
|
-
control: {
|
41
|
-
type: "object";
|
42
|
-
};
|
43
|
-
description: string;
|
44
|
-
table: {
|
45
|
-
category: string;
|
46
|
-
type: {
|
47
|
-
summary: string;
|
48
|
-
detail: string;
|
49
|
-
};
|
50
|
-
};
|
51
|
-
};
|
52
|
-
isCompact: {
|
53
|
-
control: "boolean";
|
54
|
-
description: string;
|
55
|
-
table: {
|
56
|
-
category: string;
|
57
|
-
type: {
|
58
|
-
summary: string;
|
59
|
-
};
|
60
|
-
};
|
61
|
-
};
|
62
|
-
hasPadding: {
|
63
|
-
control: "boolean";
|
64
|
-
description: string;
|
65
|
-
table: {
|
66
|
-
category: string;
|
67
|
-
type: {
|
68
|
-
summary: string;
|
69
|
-
};
|
70
|
-
};
|
71
|
-
};
|
72
|
-
hasTabs: {
|
73
|
-
control: "boolean";
|
74
|
-
description: string;
|
75
|
-
table: {
|
76
|
-
category: string;
|
77
|
-
type: {
|
78
|
-
summary: string;
|
79
|
-
};
|
80
|
-
};
|
81
|
-
};
|
82
|
-
hasHeader: {
|
83
|
-
control: "boolean";
|
84
|
-
description: string;
|
85
|
-
table: {
|
86
|
-
category: string;
|
87
|
-
type: {
|
88
|
-
summary: string;
|
89
|
-
};
|
90
|
-
};
|
91
|
-
};
|
92
|
-
convertLineBreaks: {
|
93
|
-
control: "boolean";
|
94
|
-
description: string;
|
95
|
-
table: {
|
96
|
-
category: string;
|
97
|
-
type: {
|
98
|
-
summary: string;
|
99
|
-
};
|
100
|
-
};
|
101
|
-
};
|
102
|
-
topPadding: {
|
103
|
-
control: {
|
104
|
-
type: "number";
|
105
|
-
};
|
106
|
-
description: string;
|
107
|
-
table: {
|
108
|
-
category: string;
|
109
|
-
type: {
|
110
|
-
summary: string;
|
111
|
-
};
|
112
|
-
};
|
113
|
-
};
|
114
|
-
theme: {
|
115
|
-
options: string[];
|
116
|
-
control: {
|
117
|
-
type: "select";
|
118
|
-
};
|
119
|
-
description: string;
|
120
|
-
table: {
|
121
|
-
category: string;
|
122
|
-
type: {
|
123
|
-
summary: string;
|
124
|
-
};
|
125
|
-
defaultValue: {
|
126
|
-
summary: string;
|
127
|
-
};
|
128
|
-
};
|
129
|
-
};
|
130
|
-
className: {
|
131
|
-
control: "text";
|
132
|
-
description: string;
|
133
|
-
table: {
|
134
|
-
category: string;
|
135
|
-
type: {
|
136
|
-
summary: string;
|
137
|
-
};
|
138
|
-
};
|
139
|
-
};
|
140
|
-
preStyle: {
|
141
|
-
control: {
|
142
|
-
type: "object";
|
143
|
-
};
|
144
|
-
description: string;
|
145
|
-
table: {
|
146
|
-
category: string;
|
147
|
-
type: {
|
148
|
-
summary: string;
|
149
|
-
};
|
150
|
-
};
|
151
|
-
};
|
152
|
-
};
|
153
|
-
};
|
154
|
-
export default meta;
|
155
|
-
type Story = StoryObj<typeof MarkdownTable>;
|
156
|
-
export declare const Default: Story;
|
@@ -1,172 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Storybook stories for the MarkdownTable component, demonstrating
|
3
|
-
* various configurations and use cases for markdown table generation and display.
|
4
|
-
*/
|
5
|
-
import { MarkdownTable } from './index';
|
6
|
-
var meta = {
|
7
|
-
title: 'Components/MarkdownTable',
|
8
|
-
component: MarkdownTable,
|
9
|
-
parameters: {
|
10
|
-
layout: 'centered'
|
11
|
-
},
|
12
|
-
tags: ['autodocs'],
|
13
|
-
args: {
|
14
|
-
inputData: null,
|
15
|
-
columnAlignments: [],
|
16
|
-
isCompact: false,
|
17
|
-
hasPadding: true,
|
18
|
-
hasTabs: false,
|
19
|
-
hasHeader: true,
|
20
|
-
convertLineBreaks: false,
|
21
|
-
topPadding: 16,
|
22
|
-
theme: 'light'
|
23
|
-
},
|
24
|
-
argTypes: {
|
25
|
-
inputData: {
|
26
|
-
control: {
|
27
|
-
type: 'object'
|
28
|
-
},
|
29
|
-
description: 'The outer array represents rows. The inner array represent cells within each row.',
|
30
|
-
table: {
|
31
|
-
category: 'Core Data Props',
|
32
|
-
type: {
|
33
|
-
summary: 'string[][] | null'
|
34
|
-
}
|
35
|
-
}
|
36
|
-
},
|
37
|
-
columnAlignments: {
|
38
|
-
control: {
|
39
|
-
type: 'object'
|
40
|
-
},
|
41
|
-
description: 'An array specifying the alignment for each column.',
|
42
|
-
table: {
|
43
|
-
category: 'Core Data Props',
|
44
|
-
type: {
|
45
|
-
summary: 'readonly Alignment[]',
|
46
|
-
detail: 'export type Alignment = "left" | "right" | "center" | "none";'
|
47
|
-
}
|
48
|
-
}
|
49
|
-
},
|
50
|
-
isCompact: {
|
51
|
-
control: 'boolean',
|
52
|
-
description: 'Disables column width alignment to provide a more compact markdown table string.',
|
53
|
-
table: {
|
54
|
-
category: 'Configuration Props',
|
55
|
-
type: {
|
56
|
-
summary: 'boolean'
|
57
|
-
}
|
58
|
-
}
|
59
|
-
},
|
60
|
-
hasPadding: {
|
61
|
-
control: 'boolean',
|
62
|
-
description: 'Optional flag to add a single space around cell content in the markdown table.',
|
63
|
-
table: {
|
64
|
-
category: 'Configuration Props',
|
65
|
-
type: {
|
66
|
-
summary: 'boolean'
|
67
|
-
}
|
68
|
-
}
|
69
|
-
},
|
70
|
-
hasTabs: {
|
71
|
-
control: 'boolean',
|
72
|
-
description: 'Optional flag to add tabs as additional padding between column pipes.',
|
73
|
-
table: {
|
74
|
-
category: 'Configuration Props',
|
75
|
-
type: {
|
76
|
-
summary: 'boolean'
|
77
|
-
}
|
78
|
-
}
|
79
|
-
},
|
80
|
-
hasHeader: {
|
81
|
-
control: 'boolean',
|
82
|
-
description: 'Indicates whether the first row of `data` is a header.',
|
83
|
-
table: {
|
84
|
-
category: 'Configuration Props',
|
85
|
-
type: {
|
86
|
-
summary: 'boolean'
|
87
|
-
}
|
88
|
-
}
|
89
|
-
},
|
90
|
-
convertLineBreaks: {
|
91
|
-
control: 'boolean',
|
92
|
-
description: 'Optional flag to replace newlines with `<br>` tags in table cells.',
|
93
|
-
table: {
|
94
|
-
category: 'Configuration Props',
|
95
|
-
type: {
|
96
|
-
summary: 'boolean'
|
97
|
-
}
|
98
|
-
}
|
99
|
-
},
|
100
|
-
topPadding: {
|
101
|
-
control: {
|
102
|
-
type: 'number'
|
103
|
-
},
|
104
|
-
description: 'Controls the padding-top (in pixels) of the pre element display.',
|
105
|
-
table: {
|
106
|
-
category: 'Visual/UI Props',
|
107
|
-
type: {
|
108
|
-
summary: 'number'
|
109
|
-
}
|
110
|
-
}
|
111
|
-
},
|
112
|
-
theme: {
|
113
|
-
options: ['light', 'dark'],
|
114
|
-
control: { type: 'select' },
|
115
|
-
description: 'Switch between light and dark mode.',
|
116
|
-
table: {
|
117
|
-
category: 'Visual/UI Props',
|
118
|
-
type: {
|
119
|
-
summary: "'light' | 'dark'"
|
120
|
-
},
|
121
|
-
defaultValue: { summary: 'light' }
|
122
|
-
}
|
123
|
-
},
|
124
|
-
className: {
|
125
|
-
control: 'text',
|
126
|
-
description: 'Optional CSS class for styling the rendered Markdown table.',
|
127
|
-
table: {
|
128
|
-
category: 'Visual/UI Props',
|
129
|
-
type: {
|
130
|
-
summary: 'string'
|
131
|
-
}
|
132
|
-
}
|
133
|
-
},
|
134
|
-
preStyle: {
|
135
|
-
control: {
|
136
|
-
type: 'object'
|
137
|
-
},
|
138
|
-
description: 'Optional inline styles for the pre element.',
|
139
|
-
table: {
|
140
|
-
category: 'Visual/UI Props',
|
141
|
-
type: {
|
142
|
-
summary: 'React.CSSProperties'
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}
|
146
|
-
}
|
147
|
-
};
|
148
|
-
export default meta;
|
149
|
-
// Move sample data before its usage
|
150
|
-
var sampleData = [
|
151
|
-
['Package ID', 'Weight (kg)', 'Status', 'Destination'],
|
152
|
-
['PKG-2024-001', '12.50', 'In Transit', 'Dublin, IE'],
|
153
|
-
['PKG-2024-002', '3.75', 'Delivered', 'New York, US'],
|
154
|
-
['PKG-2024-003', '8.20', 'Processing', 'Frankfurt, DE'],
|
155
|
-
['PKG-2024-004', '5.60', 'In Transit', 'London, GB']
|
156
|
-
];
|
157
|
-
export var Default = {
|
158
|
-
args: {
|
159
|
-
inputData: sampleData,
|
160
|
-
columnAlignments: ['left', 'right', 'center', 'none'],
|
161
|
-
isCompact: false,
|
162
|
-
hasPadding: true,
|
163
|
-
hasTabs: false,
|
164
|
-
hasHeader: true,
|
165
|
-
convertLineBreaks: false,
|
166
|
-
topPadding: 16,
|
167
|
-
theme: 'light',
|
168
|
-
className: undefined,
|
169
|
-
preStyle: undefined
|
170
|
-
}
|
171
|
-
};
|
172
|
-
//# sourceMappingURL=MarkdownTable.stories.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"MarkdownTable.stories.js","sourceRoot":"","sources":["../../src/MarkdownTable.stories.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,IAAM,IAAI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EAAE,6CAA6C;YAC1D,KAAK,EAAE;gBACL,QAAQ,EAAE,iBAAiB;gBAC3B,IAAI,EAAE;oBACJ,OAAO,EAAE,qBAAqB;iBAC/B;aACF;SACF;KACF;CACmC,CAAA;AAEtC,eAAe,IAAI,CAAA;AAGnB,oCAAoC;AACpC,IAAM,UAAU,GAAG;IACjB,CAAC,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,CAAC;IACtD,CAAC,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC;IACrD,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC;IACrD,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,CAAC;IACvD,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC;CACrD,CAAA;AAED,MAAM,CAAC,IAAM,OAAO,GAAU;IAC5B,IAAI,EAAE;QACJ,SAAS,EAAE,UAAU;QACrB,gBAAgB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC;QACrD,SAAS,EAAE,KAAK;QAChB,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;QACf,iBAAiB,EAAE,KAAK;QACxB,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,OAAO;QACd,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,SAAS;KACpB;CACF,CAAA"}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
2
|
-
__assign = Object.assign || function(t) {
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
-
s = arguments[i];
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
-
t[p] = s[p];
|
7
|
-
}
|
8
|
-
return t;
|
9
|
-
};
|
10
|
-
return __assign.apply(this, arguments);
|
11
|
-
};
|
12
|
-
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
13
|
-
// src/index.tsx
|
14
|
-
import { useEffect, useMemo, useRef } from 'react';
|
15
|
-
import Prism from 'prismjs';
|
16
|
-
import 'prismjs/components/prism-markdown';
|
17
|
-
import 'prismjs/plugins/line-numbers/prism-line-numbers';
|
18
|
-
import { generateMarkdownTableString, generateAlphabetHeaders } from './utils';
|
19
|
-
import { validateInputData, MarkdownTableError } from './validation';
|
20
|
-
// CSS styles
|
21
|
-
var LIGHT_THEME_CSS = "\ncode[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}pre[class*=language-].line-numbers{position:relative;padding-left:2.4em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.5em;text-align:right}\n";
|
22
|
-
var DARK_THEME_CSS = "\ncode[class*=language-],pre[class*=language-]{color:#f8f8f2;background:0 0;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background:#282a36}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}pre[class*=language-].line-numbers{position:relative;padding-left:2.4em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.5em;text-align:right}\n";
|
23
|
-
var getTableData = function (inputData, hasHeader) {
|
24
|
-
return hasHeader
|
25
|
-
? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
|
26
|
-
: { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData };
|
27
|
-
};
|
28
|
-
var generateTableSyntax = function (inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding) {
|
29
|
-
try {
|
30
|
-
validateInputData(inputData);
|
31
|
-
var _a = getTableData(inputData, hasHeader), inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
|
32
|
-
return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
33
|
-
}
|
34
|
-
catch (error) {
|
35
|
-
if (error instanceof MarkdownTableError) {
|
36
|
-
return "Error: ".concat(error.message);
|
37
|
-
}
|
38
|
-
throw error;
|
39
|
-
}
|
40
|
-
};
|
41
|
-
var applySyntaxHighlighting = function (preElementRef, markdownTableSyntax) {
|
42
|
-
useEffect(function () {
|
43
|
-
var _a;
|
44
|
-
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
45
|
-
if (codeElement && markdownTableSyntax) {
|
46
|
-
requestAnimationFrame(function () {
|
47
|
-
Prism.highlightElement(codeElement);
|
48
|
-
});
|
49
|
-
}
|
50
|
-
}, [markdownTableSyntax]);
|
51
|
-
};
|
52
|
-
export var MarkdownTable = function (_a) {
|
53
|
-
var _b = _a.inputData, inputData = _b === void 0 ? null : _b, _c = _a.hasHeader, hasHeader = _c === void 0 ? true : _c, _d = _a.columnAlignments, columnAlignments = _d === void 0 ? [] : _d, _e = _a.isCompact, isCompact = _e === void 0 ? false : _e, _f = _a.hasTabs, hasTabs = _f === void 0 ? false : _f, _g = _a.hasPadding, hasPadding = _g === void 0 ? true : _g, _h = _a.convertLineBreaks, convertLineBreaks = _h === void 0 ? false : _h, className = _a.className, onGenerate = _a.onGenerate, _j = _a.theme, theme = _j === void 0 ? 'light' : _j, preStyle = _a.preStyle, _k = _a.topPadding, topPadding = _k === void 0 ? 16 : _k;
|
54
|
-
var adjustColumnWidths = !isCompact;
|
55
|
-
var preElementRef = useRef(null);
|
56
|
-
var markdownTableSyntax = useMemo(function () { return generateTableSyntax(inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, convertLineBreaks, hasPadding); }, [
|
57
|
-
inputData,
|
58
|
-
hasHeader,
|
59
|
-
columnAlignments,
|
60
|
-
isCompact,
|
61
|
-
hasTabs,
|
62
|
-
convertLineBreaks,
|
63
|
-
hasPadding,
|
64
|
-
]);
|
65
|
-
useEffect(function () {
|
66
|
-
if (onGenerate) {
|
67
|
-
onGenerate(markdownTableSyntax);
|
68
|
-
}
|
69
|
-
}, [markdownTableSyntax, onGenerate]);
|
70
|
-
applySyntaxHighlighting(preElementRef, markdownTableSyntax);
|
71
|
-
return (_jsxs(_Fragment, { children: [_jsxs("style", { children: [theme === 'light' ? LIGHT_THEME_CSS : DARK_THEME_CSS, "\n pre {\n position: relative;\n padding-top: ".concat(topPadding, "px !important;\n }\n pre::before {\n position: absolute;\n top: 8px;\n left: 12px;\n color: ").concat(theme === 'light' ? '#666' : '#999', ";\n letter-spacing: 2px;\n font-size: 12px;\n }\n ")] }), _jsx("div", { style: {
|
72
|
-
position: 'relative',
|
73
|
-
isolation: 'isolate',
|
74
|
-
display: 'flex',
|
75
|
-
justifyContent: 'center'
|
76
|
-
}, children: _jsx("pre", { ref: preElementRef, className: "".concat(className, " language-markdown line-numbers ").concat(theme === 'dark' ? 'dark-theme' : ''), style: __assign({ width: 'fit-content', minWidth: 'min-content', margin: 0 }, preStyle), children: _jsx("code", { className: "language-markdown", role: "code", children: markdownTableSyntax }) }) })] }));
|
77
|
-
};
|
78
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gBAAgB;AAEhB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iDAAiD,CAAC;AAEzD,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAErE,aAAa;AACb,IAAM,eAAe,GAAG,8nDAEvB,CAAC;AAEF,IAA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