react-markdown-table-ts 0.5.10 → 0.5.12
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/index.cjs.js +97 -93
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +82 -78
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -3,6 +3,52 @@ import React__default, { forwardRef, useContext, Children, isValidElement, clone
|
|
3
3
|
import * as ReactDOM from 'react-dom';
|
4
4
|
import ReactDOM__default from 'react-dom';
|
5
5
|
|
6
|
+
/******************************************************************************
|
7
|
+
Copyright (c) Microsoft Corporation.
|
8
|
+
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
10
|
+
purpose with or without fee is hereby granted.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
***************************************************************************** */
|
20
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
21
|
+
|
22
|
+
var extendStatics = function(d, b) {
|
23
|
+
extendStatics = Object.setPrototypeOf ||
|
24
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
25
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
26
|
+
return extendStatics(d, b);
|
27
|
+
};
|
28
|
+
|
29
|
+
function __extends(d, b) {
|
30
|
+
if (typeof b !== "function" && b !== null)
|
31
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
32
|
+
extendStatics(d, b);
|
33
|
+
function __() { this.constructor = d; }
|
34
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
35
|
+
}
|
36
|
+
|
37
|
+
function __spreadArray(to, from, pack) {
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
39
|
+
if (ar || !(i in from)) {
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
41
|
+
ar[i] = from[i];
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
45
|
+
}
|
46
|
+
|
47
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
48
|
+
var e = new Error(message);
|
49
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
50
|
+
};
|
51
|
+
|
6
52
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
7
53
|
|
8
54
|
function getDefaultExportFromCjs (x) {
|
@@ -4006,52 +4052,6 @@ var Prism$1 = /*@__PURE__*/getDefaultExportFromCjs(prismExports);
|
|
4006
4052
|
|
4007
4053
|
}());
|
4008
4054
|
|
4009
|
-
/******************************************************************************
|
4010
|
-
Copyright (c) Microsoft Corporation.
|
4011
|
-
|
4012
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
4013
|
-
purpose with or without fee is hereby granted.
|
4014
|
-
|
4015
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
4016
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
4017
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
4018
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
4019
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
4020
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
4021
|
-
PERFORMANCE OF THIS SOFTWARE.
|
4022
|
-
***************************************************************************** */
|
4023
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
4024
|
-
|
4025
|
-
var extendStatics = function(d, b) {
|
4026
|
-
extendStatics = Object.setPrototypeOf ||
|
4027
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
4028
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
4029
|
-
return extendStatics(d, b);
|
4030
|
-
};
|
4031
|
-
|
4032
|
-
function __extends(d, b) {
|
4033
|
-
if (typeof b !== "function" && b !== null)
|
4034
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
4035
|
-
extendStatics(d, b);
|
4036
|
-
function __() { this.constructor = d; }
|
4037
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
4038
|
-
}
|
4039
|
-
|
4040
|
-
function __spreadArray(to, from, pack) {
|
4041
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4042
|
-
if (ar || !(i in from)) {
|
4043
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
4044
|
-
ar[i] = from[i];
|
4045
|
-
}
|
4046
|
-
}
|
4047
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
4048
|
-
}
|
4049
|
-
|
4050
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
4051
|
-
var e = new Error(message);
|
4052
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
4053
|
-
};
|
4054
|
-
|
4055
4055
|
// src/validation.ts
|
4056
4056
|
/**
|
4057
4057
|
* Custom error class for handling Markdown table generation errors.
|
@@ -18537,28 +18537,45 @@ var Tooltip$1 = Tooltip;
|
|
18537
18537
|
// CSS styles
|
18538
18538
|
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";
|
18539
18539
|
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";
|
18540
|
+
var generateTableSyntax = function (inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding) {
|
18541
|
+
if (inputData === null) {
|
18542
|
+
return 'Error: No data provided for the table.';
|
18543
|
+
}
|
18544
|
+
try {
|
18545
|
+
if (!Array.isArray(inputData) || inputData.length === 0) {
|
18546
|
+
throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
|
18547
|
+
}
|
18548
|
+
var _a = hasHeader
|
18549
|
+
? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
|
18550
|
+
: { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData }, inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
|
18551
|
+
return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
18552
|
+
}
|
18553
|
+
catch (error) {
|
18554
|
+
return error instanceof MarkdownTableError ? "Error: ".concat(error.message) : (function () { throw error; })();
|
18555
|
+
}
|
18556
|
+
};
|
18557
|
+
var applySyntaxHighlighting = function (preElementRef, markdownTableSyntax) {
|
18558
|
+
useEffect(function () {
|
18559
|
+
var _a;
|
18560
|
+
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18561
|
+
if (codeElement && markdownTableSyntax) {
|
18562
|
+
requestAnimationFrame(function () {
|
18563
|
+
Prism$1.highlightElement(codeElement);
|
18564
|
+
});
|
18565
|
+
}
|
18566
|
+
}, [markdownTableSyntax]);
|
18567
|
+
};
|
18568
|
+
var handleCopyAction = function (markdownTableSyntax, setIsCopied) {
|
18569
|
+
navigator.clipboard.writeText(markdownTableSyntax);
|
18570
|
+
setIsCopied(true);
|
18571
|
+
setTimeout(function () { return setIsCopied(false); }, 2000);
|
18572
|
+
};
|
18540
18573
|
var MarkdownTable = function (_a) {
|
18541
18574
|
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.canReplaceNewlines, canReplaceNewlines = _h === void 0 ? false : _h, className = _a.className, onTableCreate = _a.onTableCreate, _j = _a.theme, theme = _j === void 0 ? 'light' : _j, preStyle = _a.preStyle, _k = _a.showCopyButton, showCopyButton = _k === void 0 ? false : _k;
|
18542
18575
|
var adjustColumnWidths = !isCompact;
|
18543
18576
|
var preElementRef = useRef(null);
|
18544
18577
|
var _l = useState(false), isCopied = _l[0], setIsCopied = _l[1];
|
18545
|
-
var markdownTableSyntax = useMemo(function () {
|
18546
|
-
if (inputData === null) {
|
18547
|
-
return 'Error: No data provided for the table.';
|
18548
|
-
}
|
18549
|
-
try {
|
18550
|
-
if (!Array.isArray(inputData) || inputData.length === 0) {
|
18551
|
-
throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
|
18552
|
-
}
|
18553
|
-
var _a = hasHeader
|
18554
|
-
? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
|
18555
|
-
: { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData }, inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
|
18556
|
-
return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
18557
|
-
}
|
18558
|
-
catch (error) {
|
18559
|
-
return error instanceof MarkdownTableError ? "Error: ".concat(error.message) : (function () { throw error; })();
|
18560
|
-
}
|
18561
|
-
}, [
|
18578
|
+
var markdownTableSyntax = useMemo(function () { return generateTableSyntax(inputData, hasHeader, __spreadArray([], columnAlignments, true), adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding); }, [
|
18562
18579
|
inputData,
|
18563
18580
|
hasHeader,
|
18564
18581
|
columnAlignments,
|
@@ -18572,24 +18589,11 @@ var MarkdownTable = function (_a) {
|
|
18572
18589
|
onTableCreate(markdownTableSyntax);
|
18573
18590
|
}
|
18574
18591
|
}, [markdownTableSyntax, onTableCreate]);
|
18575
|
-
|
18576
|
-
var _a;
|
18577
|
-
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18578
|
-
if (codeElement && markdownTableSyntax) {
|
18579
|
-
requestAnimationFrame(function () {
|
18580
|
-
Prism$1.highlightElement(codeElement);
|
18581
|
-
});
|
18582
|
-
}
|
18583
|
-
}, [markdownTableSyntax]);
|
18584
|
-
var handleCopy = function () {
|
18585
|
-
navigator.clipboard.writeText(markdownTableSyntax);
|
18586
|
-
setIsCopied(true);
|
18587
|
-
setTimeout(function () { return setIsCopied(false); }, 2000);
|
18588
|
-
};
|
18592
|
+
applySyntaxHighlighting(preElementRef, markdownTableSyntax);
|
18589
18593
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: theme === 'light' ? LIGHT_THEME_CSS : DARK_THEME_CSS }), jsxRuntimeExports.jsxs("div", { style: {
|
18590
18594
|
position: 'relative',
|
18591
18595
|
isolation: 'isolate'
|
18592
|
-
}, children: [showCopyButton && (jsxRuntimeExports.jsx(Tooltip$1, { title: isCopied ? 'Copied!' : 'Copy markdown table syntax', placement: "left-end", arrow: true, children: jsxRuntimeExports.jsx(IconButton$1, { onClick:
|
18596
|
+
}, children: [showCopyButton && (jsxRuntimeExports.jsx(Tooltip$1, { title: isCopied ? 'Copied!' : 'Copy markdown table syntax', placement: "left-end", arrow: true, children: jsxRuntimeExports.jsx(IconButton$1, { onClick: function () { return handleCopyAction(markdownTableSyntax, setIsCopied); }, sx: {
|
18593
18597
|
position: 'absolute',
|
18594
18598
|
top: '12px',
|
18595
18599
|
right: '8px',
|