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.cjs.js
CHANGED
@@ -8,21 +8,21 @@ var ReactDOM = require('react-dom');
|
|
8
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
9
9
|
|
10
10
|
function _interopNamespace(e) {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
if (e && e.__esModule) return e;
|
12
|
+
var n = Object.create(null);
|
13
|
+
if (e) {
|
14
|
+
Object.keys(e).forEach(function (k) {
|
15
|
+
if (k !== 'default') {
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
18
|
+
enumerable: true,
|
19
|
+
get: function () { return e[k]; }
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
n["default"] = e;
|
25
|
+
return Object.freeze(n);
|
26
26
|
}
|
27
27
|
|
28
28
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
@@ -30,6 +30,52 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
30
|
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
31
31
|
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
32
32
|
|
33
|
+
/******************************************************************************
|
34
|
+
Copyright (c) Microsoft Corporation.
|
35
|
+
|
36
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
37
|
+
purpose with or without fee is hereby granted.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
40
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
41
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
42
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
43
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
44
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
45
|
+
PERFORMANCE OF THIS SOFTWARE.
|
46
|
+
***************************************************************************** */
|
47
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
48
|
+
|
49
|
+
var extendStatics = function(d, b) {
|
50
|
+
extendStatics = Object.setPrototypeOf ||
|
51
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
52
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
53
|
+
return extendStatics(d, b);
|
54
|
+
};
|
55
|
+
|
56
|
+
function __extends(d, b) {
|
57
|
+
if (typeof b !== "function" && b !== null)
|
58
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
59
|
+
extendStatics(d, b);
|
60
|
+
function __() { this.constructor = d; }
|
61
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
62
|
+
}
|
63
|
+
|
64
|
+
function __spreadArray(to, from, pack) {
|
65
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
66
|
+
if (ar || !(i in from)) {
|
67
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
68
|
+
ar[i] = from[i];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
72
|
+
}
|
73
|
+
|
74
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
75
|
+
var e = new Error(message);
|
76
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
77
|
+
};
|
78
|
+
|
33
79
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
34
80
|
|
35
81
|
function getDefaultExportFromCjs (x) {
|
@@ -4033,52 +4079,6 @@ var Prism$1 = /*@__PURE__*/getDefaultExportFromCjs(prismExports);
|
|
4033
4079
|
|
4034
4080
|
}());
|
4035
4081
|
|
4036
|
-
/******************************************************************************
|
4037
|
-
Copyright (c) Microsoft Corporation.
|
4038
|
-
|
4039
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
4040
|
-
purpose with or without fee is hereby granted.
|
4041
|
-
|
4042
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
4043
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
4044
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
4045
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
4046
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
4047
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
4048
|
-
PERFORMANCE OF THIS SOFTWARE.
|
4049
|
-
***************************************************************************** */
|
4050
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
4051
|
-
|
4052
|
-
var extendStatics = function(d, b) {
|
4053
|
-
extendStatics = Object.setPrototypeOf ||
|
4054
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
4055
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
4056
|
-
return extendStatics(d, b);
|
4057
|
-
};
|
4058
|
-
|
4059
|
-
function __extends(d, b) {
|
4060
|
-
if (typeof b !== "function" && b !== null)
|
4061
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
4062
|
-
extendStatics(d, b);
|
4063
|
-
function __() { this.constructor = d; }
|
4064
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
4065
|
-
}
|
4066
|
-
|
4067
|
-
function __spreadArray(to, from, pack) {
|
4068
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
4069
|
-
if (ar || !(i in from)) {
|
4070
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
4071
|
-
ar[i] = from[i];
|
4072
|
-
}
|
4073
|
-
}
|
4074
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
4075
|
-
}
|
4076
|
-
|
4077
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
4078
|
-
var e = new Error(message);
|
4079
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
4080
|
-
};
|
4081
|
-
|
4082
4082
|
// src/validation.ts
|
4083
4083
|
/**
|
4084
4084
|
* Custom error class for handling Markdown table generation errors.
|
@@ -18564,28 +18564,45 @@ var Tooltip$1 = Tooltip;
|
|
18564
18564
|
// CSS styles
|
18565
18565
|
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";
|
18566
18566
|
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";
|
18567
|
+
var generateTableSyntax = function (inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding) {
|
18568
|
+
if (inputData === null) {
|
18569
|
+
return 'Error: No data provided for the table.';
|
18570
|
+
}
|
18571
|
+
try {
|
18572
|
+
if (!Array.isArray(inputData) || inputData.length === 0) {
|
18573
|
+
throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
|
18574
|
+
}
|
18575
|
+
var _a = hasHeader
|
18576
|
+
? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
|
18577
|
+
: { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData }, inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
|
18578
|
+
return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
18579
|
+
}
|
18580
|
+
catch (error) {
|
18581
|
+
return error instanceof MarkdownTableError ? "Error: ".concat(error.message) : (function () { throw error; })();
|
18582
|
+
}
|
18583
|
+
};
|
18584
|
+
var applySyntaxHighlighting = function (preElementRef, markdownTableSyntax) {
|
18585
|
+
React.useEffect(function () {
|
18586
|
+
var _a;
|
18587
|
+
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18588
|
+
if (codeElement && markdownTableSyntax) {
|
18589
|
+
requestAnimationFrame(function () {
|
18590
|
+
Prism$1.highlightElement(codeElement);
|
18591
|
+
});
|
18592
|
+
}
|
18593
|
+
}, [markdownTableSyntax]);
|
18594
|
+
};
|
18595
|
+
var handleCopyAction = function (markdownTableSyntax, setIsCopied) {
|
18596
|
+
navigator.clipboard.writeText(markdownTableSyntax);
|
18597
|
+
setIsCopied(true);
|
18598
|
+
setTimeout(function () { return setIsCopied(false); }, 2000);
|
18599
|
+
};
|
18567
18600
|
var MarkdownTable = function (_a) {
|
18568
18601
|
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;
|
18569
18602
|
var adjustColumnWidths = !isCompact;
|
18570
18603
|
var preElementRef = React.useRef(null);
|
18571
18604
|
var _l = React.useState(false), isCopied = _l[0], setIsCopied = _l[1];
|
18572
|
-
var markdownTableSyntax = React.useMemo(function () {
|
18573
|
-
if (inputData === null) {
|
18574
|
-
return 'Error: No data provided for the table.';
|
18575
|
-
}
|
18576
|
-
try {
|
18577
|
-
if (!Array.isArray(inputData) || inputData.length === 0) {
|
18578
|
-
throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
|
18579
|
-
}
|
18580
|
-
var _a = hasHeader
|
18581
|
-
? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
|
18582
|
-
: { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData }, inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
|
18583
|
-
return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
18584
|
-
}
|
18585
|
-
catch (error) {
|
18586
|
-
return error instanceof MarkdownTableError ? "Error: ".concat(error.message) : (function () { throw error; })();
|
18587
|
-
}
|
18588
|
-
}, [
|
18605
|
+
var markdownTableSyntax = React.useMemo(function () { return generateTableSyntax(inputData, hasHeader, __spreadArray([], columnAlignments, true), adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding); }, [
|
18589
18606
|
inputData,
|
18590
18607
|
hasHeader,
|
18591
18608
|
columnAlignments,
|
@@ -18599,24 +18616,11 @@ var MarkdownTable = function (_a) {
|
|
18599
18616
|
onTableCreate(markdownTableSyntax);
|
18600
18617
|
}
|
18601
18618
|
}, [markdownTableSyntax, onTableCreate]);
|
18602
|
-
|
18603
|
-
var _a;
|
18604
|
-
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18605
|
-
if (codeElement && markdownTableSyntax) {
|
18606
|
-
requestAnimationFrame(function () {
|
18607
|
-
Prism$1.highlightElement(codeElement);
|
18608
|
-
});
|
18609
|
-
}
|
18610
|
-
}, [markdownTableSyntax]);
|
18611
|
-
var handleCopy = function () {
|
18612
|
-
navigator.clipboard.writeText(markdownTableSyntax);
|
18613
|
-
setIsCopied(true);
|
18614
|
-
setTimeout(function () { return setIsCopied(false); }, 2000);
|
18615
|
-
};
|
18619
|
+
applySyntaxHighlighting(preElementRef, markdownTableSyntax);
|
18616
18620
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: theme === 'light' ? LIGHT_THEME_CSS : DARK_THEME_CSS }), jsxRuntimeExports.jsxs("div", { style: {
|
18617
18621
|
position: 'relative',
|
18618
18622
|
isolation: 'isolate'
|
18619
|
-
}, children: [showCopyButton && (jsxRuntimeExports.jsx(Tooltip$1, { title: isCopied ? 'Copied!' : 'Copy markdown table syntax', placement: "left-end", arrow: true, children: jsxRuntimeExports.jsx(IconButton$1, { onClick:
|
18623
|
+
}, 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: {
|
18620
18624
|
position: 'absolute',
|
18621
18625
|
top: '12px',
|
18622
18626
|
right: '8px',
|