react-markdown-table-ts 1.1.2 → 1.1.4
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 +7 -4
- package/dist/MarkdownTable.stories.d.ts +13 -0
- package/dist/index.cjs.js +24 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +24 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/jest.setup.d.ts +2 -0
- package/dist/jest.setup.js +3 -0
- package/dist/jest.setup.js.map +1 -0
- package/dist/src/MarkdownTable.stories.d.ts +156 -0
- package/dist/src/MarkdownTable.stories.js +172 -0
- package/dist/src/MarkdownTable.stories.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +78 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +123 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +8 -0
- package/dist/src/utils.js +176 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validation.d.ts +19 -0
- package/dist/src/validation.js +106 -0
- package/dist/src/validation.js.map +1 -0
- package/dist/test/MarkdownTable.test.d.ts +1 -0
- package/dist/test/MarkdownTable.test.js +91 -0
- package/dist/test/MarkdownTable.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +1 -0
- package/dist/test/utils.test.js +234 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/validation.test.d.ts +1 -0
- package/dist/test/validation.test.js +86 -0
- package/dist/test/validation.test.js.map +1 -0
- package/dist/types.d.ts +7 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -26,13 +26,14 @@ interface MarkdownTableProps {
|
|
26
26
|
theme?: 'light' | 'dark';
|
27
27
|
className?: string;
|
28
28
|
preStyle?: React.CSSProperties;
|
29
|
+
topPadding?: number;
|
29
30
|
onGenerate?: (markdownTableString: string) => void;
|
30
31
|
}
|
31
32
|
```
|
32
33
|
| Prop | Type | Default | Description |
|
33
34
|
|----------------------|-----------------------------------------|-------------|------------------------------------------------------------------------------------|
|
34
35
|
| `inputData` | `string[][] \| null` | `null` | The outer array represents rows. The inner array represent cells within each row. |
|
35
|
-
| `columnAlignments` | `readonly Alignment[]` | `[]` | Acceptable values are 'left', 'center', 'right', or 'none'.
|
36
|
+
| `columnAlignments` | `readonly Alignment[]` | `[]` | Acceptable values are 'left', 'center', 'right', 'justify', or 'none'. Defaults to 'none' when unspecified. |
|
36
37
|
| `isCompact` | `boolean` | `false` | Disables column width alignment to provide a more compact markdown table string. |
|
37
38
|
| `hasPadding` | `boolean` | `true` | One space added before and after the content in each cell. |
|
38
39
|
| `hasTabs` | `boolean` | `false` | Adds a tab character after each \| and before the content. |
|
@@ -41,6 +42,7 @@ interface MarkdownTableProps {
|
|
41
42
|
| `theme` | `'light' \| 'dark'` | `light` | Controls the color scheme of the \<pre\> element display. |
|
42
43
|
| `className` | `string` | `undefined` | Class will be applied to the \<pre\> element display. |
|
43
44
|
| `preStyle` | `React.CSSProperties` | `undefined` | Allows direct styling of the display with CSS properties. |
|
45
|
+
| `topPadding` | `number` | `16` | Controls the padding-top (in pixels) of the \<pre\> element display. |
|
44
46
|
| `onGenerate` | `(markdownTableString: string) => void` | `undefined` | Callback to receive the generated Markdown table string. |
|
45
47
|
## Usage Patterns
|
46
48
|
|
@@ -57,7 +59,7 @@ interface MarkdownTableProps {
|
|
57
59
|
```typescript
|
58
60
|
<MarkdownTable
|
59
61
|
inputData={data}
|
60
|
-
columnAlignments={['left', 'center', 'right']}
|
62
|
+
columnAlignments={['left', 'center', 'right', 'justify']}
|
61
63
|
/>
|
62
64
|
```
|
63
65
|
3. **Auto-Generated Headers**:
|
@@ -74,12 +76,13 @@ interface MarkdownTableProps {
|
|
74
76
|
- Input must be non-null 2D string array
|
75
77
|
- All rows should contain string values
|
76
78
|
- Empty arrays are not allowed
|
77
|
-
- Column alignments must be valid ('left', 'center', 'right', 'none')
|
79
|
+
- Column alignments must be valid ('left', 'center', 'right', 'justify', 'none')
|
78
80
|
|
79
81
|
2. **Column Width Handling**:
|
80
|
-
- Default: Adjusts columns to fit content
|
82
|
+
- Default: Adjusts columns to fit content with 'none' alignment
|
81
83
|
- `isCompact={true}`: Minimizes column widths
|
82
84
|
- Maintains minimum width of 3 characters for alignment indicators
|
85
|
+
- 'justify' alignment behaves same as 'none' for markdown compatibility
|
83
86
|
|
84
87
|
3. **Error Handling**:
|
85
88
|
- Returns error message string if validation fails
|
@@ -20,6 +20,7 @@ declare const meta: {
|
|
20
20
|
hasTabs: false;
|
21
21
|
hasHeader: true;
|
22
22
|
convertLineBreaks: false;
|
23
|
+
topPadding: number;
|
23
24
|
theme: "light";
|
24
25
|
};
|
25
26
|
argTypes: {
|
@@ -98,6 +99,18 @@ declare const meta: {
|
|
98
99
|
};
|
99
100
|
};
|
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
|
+
};
|
101
114
|
theme: {
|
102
115
|
options: string[];
|
103
116
|
control: {
|
package/dist/index.cjs.js
CHANGED
@@ -39,6 +39,17 @@ function __extends(d, b) {
|
|
39
39
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
40
40
|
}
|
41
41
|
|
42
|
+
var __assign = function() {
|
43
|
+
__assign = Object.assign || function __assign(t) {
|
44
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
45
|
+
s = arguments[i];
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
47
|
+
}
|
48
|
+
return t;
|
49
|
+
};
|
50
|
+
return __assign.apply(this, arguments);
|
51
|
+
};
|
52
|
+
|
42
53
|
function __spreadArray(to, from, pack) {
|
43
54
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
44
55
|
if (ar || !(i in from)) {
|
@@ -4090,6 +4101,7 @@ var AlignmentFormatter = /** @class */ (function () {
|
|
4090
4101
|
right: function (width) { return "".concat('-'.repeat(width - 1), ":"); },
|
4091
4102
|
center: function (width) { return ":".concat('-'.repeat(width - 2), ":"); },
|
4092
4103
|
none: function (width) { return '-'.repeat(width); },
|
4104
|
+
justify: function (width) { return '-'.repeat(width); }
|
4093
4105
|
};
|
4094
4106
|
return AlignmentFormatter;
|
4095
4107
|
}());
|
@@ -4100,9 +4112,12 @@ var TableFormatter = /** @class */ (function () {
|
|
4100
4112
|
this.adjustedAlignments = this.getAdjustedAlignments();
|
4101
4113
|
}
|
4102
4114
|
TableFormatter.prototype.getAdjustedAlignments = function () {
|
4103
|
-
var defaultAlignment = '
|
4115
|
+
var defaultAlignment = 'none';
|
4116
|
+
var sanitizeAlignment = function (alignment) {
|
4117
|
+
return alignment === 'justify' ? 'none' : alignment;
|
4118
|
+
};
|
4104
4119
|
return this.config.columnAlignments.length < this.config.columnCount
|
4105
|
-
? __spreadArray(__spreadArray([], Array.from(this.config.columnAlignments), true), Array(this.config.columnCount - this.config.columnAlignments.length).fill(defaultAlignment), true) : Array.from(this.config.columnAlignments);
|
4120
|
+
? __spreadArray(__spreadArray([], Array.from(this.config.columnAlignments).map(sanitizeAlignment), true), Array(this.config.columnCount - this.config.columnAlignments.length).fill(defaultAlignment), true) : Array.from(this.config.columnAlignments).map(sanitizeAlignment);
|
4106
4121
|
};
|
4107
4122
|
TableFormatter.prototype.formatRow = function (row) {
|
4108
4123
|
var _this = this;
|
@@ -4252,10 +4267,10 @@ var applySyntaxHighlighting = function (preElementRef, markdownTableSyntax) {
|
|
4252
4267
|
}, [markdownTableSyntax]);
|
4253
4268
|
};
|
4254
4269
|
var MarkdownTable = function (_a) {
|
4255
|
-
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;
|
4270
|
+
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;
|
4256
4271
|
var adjustColumnWidths = !isCompact;
|
4257
4272
|
var preElementRef = require$$0.useRef(null);
|
4258
|
-
var markdownTableSyntax = require$$0.useMemo(function () { return generateTableSyntax(inputData, hasHeader,
|
4273
|
+
var markdownTableSyntax = require$$0.useMemo(function () { return generateTableSyntax(inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, convertLineBreaks, hasPadding); }, [
|
4259
4274
|
inputData,
|
4260
4275
|
hasHeader,
|
4261
4276
|
columnAlignments,
|
@@ -4270,10 +4285,12 @@ var MarkdownTable = function (_a) {
|
|
4270
4285
|
}
|
4271
4286
|
}, [markdownTableSyntax, onGenerate]);
|
4272
4287
|
applySyntaxHighlighting(preElementRef, markdownTableSyntax);
|
4273
|
-
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.
|
4288
|
+
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.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 ")] }), jsxRuntimeExports.jsx("div", { style: {
|
4274
4289
|
position: 'relative',
|
4275
|
-
isolation: 'isolate'
|
4276
|
-
|
4290
|
+
isolation: 'isolate',
|
4291
|
+
display: 'flex',
|
4292
|
+
justifyContent: 'center'
|
4293
|
+
}, children: jsxRuntimeExports.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: jsxRuntimeExports.jsx("code", { className: "language-markdown", role: "code", children: markdownTableSyntax }) }) })] }));
|
4277
4294
|
};
|
4278
4295
|
|
4279
4296
|
exports.MarkdownTable = MarkdownTable;
|