react-markdown-table-ts 0.5.11 → 0.5.13

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 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
- 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);
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,52 @@ 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 validateInputData = function (inputData) {
18568
+ if (inputData === null || !Array.isArray(inputData) || inputData.length === 0) {
18569
+ throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
18570
+ }
18571
+ };
18572
+ var getTableData = function (inputData, hasHeader) {
18573
+ return hasHeader
18574
+ ? { inputDataHeader: inputData[0], inputDataBody: inputData.slice(1) }
18575
+ : { inputDataHeader: generateAlphabetHeaders(inputData[0].length), inputDataBody: inputData };
18576
+ };
18577
+ var generateTableSyntax = function (inputData, hasHeader, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding) {
18578
+ try {
18579
+ validateInputData(inputData);
18580
+ var nonNullInputData = inputData;
18581
+ var _a = getTableData(nonNullInputData, hasHeader), inputDataHeader = _a.inputDataHeader, inputDataBody = _a.inputDataBody;
18582
+ return generateMarkdownTableString({ inputDataHeader: inputDataHeader, inputDataBody: inputDataBody }, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
18583
+ }
18584
+ catch (error) {
18585
+ if (error instanceof MarkdownTableError) {
18586
+ return "Error: ".concat(error.message);
18587
+ }
18588
+ throw error;
18589
+ }
18590
+ };
18591
+ var applySyntaxHighlighting = function (preElementRef, markdownTableSyntax) {
18592
+ React.useEffect(function () {
18593
+ var _a;
18594
+ var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
18595
+ if (codeElement && markdownTableSyntax) {
18596
+ requestAnimationFrame(function () {
18597
+ Prism$1.highlightElement(codeElement);
18598
+ });
18599
+ }
18600
+ }, [markdownTableSyntax]);
18601
+ };
18602
+ var handleCopyAction = function (markdownTableSyntax, setIsCopied) {
18603
+ navigator.clipboard.writeText(markdownTableSyntax);
18604
+ setIsCopied(true);
18605
+ setTimeout(function () { return setIsCopied(false); }, 2000);
18606
+ };
18567
18607
  var MarkdownTable = function (_a) {
18568
18608
  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
18609
  var adjustColumnWidths = !isCompact;
18570
18610
  var preElementRef = React.useRef(null);
18571
18611
  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
- }, [
18612
+ var markdownTableSyntax = React.useMemo(function () { return generateTableSyntax(inputData, hasHeader, __spreadArray([], columnAlignments, true), adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding); }, [
18589
18613
  inputData,
18590
18614
  hasHeader,
18591
18615
  columnAlignments,
@@ -18599,24 +18623,11 @@ var MarkdownTable = function (_a) {
18599
18623
  onTableCreate(markdownTableSyntax);
18600
18624
  }
18601
18625
  }, [markdownTableSyntax, onTableCreate]);
18602
- React.useEffect(function () {
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
- };
18626
+ applySyntaxHighlighting(preElementRef, markdownTableSyntax);
18616
18627
  return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: theme === 'light' ? LIGHT_THEME_CSS : DARK_THEME_CSS }), jsxRuntimeExports.jsxs("div", { style: {
18617
18628
  position: 'relative',
18618
18629
  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: handleCopy, sx: {
18630
+ }, 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
18631
  position: 'absolute',
18621
18632
  top: '12px',
18622
18633
  right: '8px',