@teselagen/ui 0.10.23 → 0.10.24

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.
@@ -0,0 +1 @@
1
+ export function tsvToHtmlTable(tsv: any): string;
package/index.cjs.js CHANGED
@@ -17211,10 +17211,25 @@ function requireCopyToClipboard() {
17211
17211
  __name(requireCopyToClipboard, "requireCopyToClipboard");
17212
17212
  var copyToClipboardExports = requireCopyToClipboard();
17213
17213
  const copy = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
17214
+ const HTML_ESCAPES = {
17215
+ "&": "&",
17216
+ "<": "&lt;",
17217
+ ">": "&gt;",
17218
+ '"': "&quot;"
17219
+ };
17220
+ const escapeHtml = /* @__PURE__ */ __name((value) => String(value != null ? value : "").replace(/[&<>"]/g, (c2) => HTML_ESCAPES[c2]), "escapeHtml");
17221
+ const tsvToHtmlTable = /* @__PURE__ */ __name((tsv) => {
17222
+ const rows = String(tsv != null ? tsv : "").split("\n").map((line) => {
17223
+ const cells = line.split(" ").map((v2) => `<td>${escapeHtml(v2)}</td>`).join("");
17224
+ return `<tr>${cells}</tr>`;
17225
+ }).join("");
17226
+ return `<table>${rows}</table>`;
17227
+ }, "tsvToHtmlTable");
17214
17228
  const handleCopyHelper = /* @__PURE__ */ __name((stringToCopy, jsonToCopy, message) => {
17215
17229
  !window.Cypress && copy(stringToCopy, {
17216
17230
  onCopy: /* @__PURE__ */ __name((clipboardData) => {
17217
17231
  clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
17232
+ clipboardData.setData("text/html", tsvToHtmlTable(stringToCopy));
17218
17233
  }, "onCopy"),
17219
17234
  // keep this so that pasting into spreadsheets works.
17220
17235
  format: "text/plain"
package/index.es.js CHANGED
@@ -17193,10 +17193,25 @@ function requireCopyToClipboard() {
17193
17193
  __name(requireCopyToClipboard, "requireCopyToClipboard");
17194
17194
  var copyToClipboardExports = requireCopyToClipboard();
17195
17195
  const copy = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
17196
+ const HTML_ESCAPES = {
17197
+ "&": "&amp;",
17198
+ "<": "&lt;",
17199
+ ">": "&gt;",
17200
+ '"': "&quot;"
17201
+ };
17202
+ const escapeHtml = /* @__PURE__ */ __name((value) => String(value != null ? value : "").replace(/[&<>"]/g, (c2) => HTML_ESCAPES[c2]), "escapeHtml");
17203
+ const tsvToHtmlTable = /* @__PURE__ */ __name((tsv) => {
17204
+ const rows = String(tsv != null ? tsv : "").split("\n").map((line) => {
17205
+ const cells = line.split(" ").map((v2) => `<td>${escapeHtml(v2)}</td>`).join("");
17206
+ return `<tr>${cells}</tr>`;
17207
+ }).join("");
17208
+ return `<table>${rows}</table>`;
17209
+ }, "tsvToHtmlTable");
17196
17210
  const handleCopyHelper = /* @__PURE__ */ __name((stringToCopy, jsonToCopy, message) => {
17197
17211
  !window.Cypress && copy(stringToCopy, {
17198
17212
  onCopy: /* @__PURE__ */ __name((clipboardData) => {
17199
17213
  clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
17214
+ clipboardData.setData("text/html", tsvToHtmlTable(stringToCopy));
17200
17215
  }, "onCopy"),
17201
17216
  // keep this so that pasting into spreadsheets works.
17202
17217
  format: "text/plain"
package/index.umd.js CHANGED
@@ -42656,10 +42656,25 @@ ${latestSubscriptionCallbackError.current.stack}
42656
42656
  __name(requireCopyToClipboard, "requireCopyToClipboard");
42657
42657
  var copyToClipboardExports = requireCopyToClipboard();
42658
42658
  const copy = /* @__PURE__ */ getDefaultExportFromCjs(copyToClipboardExports);
42659
+ const HTML_ESCAPES = {
42660
+ "&": "&amp;",
42661
+ "<": "&lt;",
42662
+ ">": "&gt;",
42663
+ '"': "&quot;"
42664
+ };
42665
+ const escapeHtml = /* @__PURE__ */ __name((value) => String(value != null ? value : "").replace(/[&<>"]/g, (c2) => HTML_ESCAPES[c2]), "escapeHtml");
42666
+ const tsvToHtmlTable = /* @__PURE__ */ __name((tsv) => {
42667
+ const rows = String(tsv != null ? tsv : "").split("\n").map((line) => {
42668
+ const cells = line.split(" ").map((v2) => `<td>${escapeHtml(v2)}</td>`).join("");
42669
+ return `<tr>${cells}</tr>`;
42670
+ }).join("");
42671
+ return `<table>${rows}</table>`;
42672
+ }, "tsvToHtmlTable");
42659
42673
  const handleCopyHelper = /* @__PURE__ */ __name((stringToCopy, jsonToCopy, message) => {
42660
42674
  !window.Cypress && copy(stringToCopy, {
42661
42675
  onCopy: /* @__PURE__ */ __name((clipboardData) => {
42662
42676
  clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
42677
+ clipboardData.setData("text/html", tsvToHtmlTable(stringToCopy));
42663
42678
  }, "onCopy"),
42664
42679
  // keep this so that pasting into spreadsheets works.
42665
42680
  format: "text/plain"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.10.23",
3
+ "version": "0.10.24",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/TeselaGen/tg-oss",
@@ -1,10 +1,12 @@
1
1
  import copy from "copy-to-clipboard";
2
+ import { tsvToHtmlTable } from "./tsvToHtmlTable";
2
3
 
3
4
  export const handleCopyHelper = (stringToCopy, jsonToCopy, message) => {
4
5
  !window.Cypress &&
5
6
  copy(stringToCopy, {
6
7
  onCopy: clipboardData => {
7
8
  clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
9
+ clipboardData.setData("text/html", tsvToHtmlTable(stringToCopy));
8
10
  },
9
11
  // keep this so that pasting into spreadsheets works.
10
12
  format: "text/plain"
@@ -0,0 +1,23 @@
1
+ const HTML_ESCAPES = {
2
+ "&": "&amp;",
3
+ "<": "&lt;",
4
+ ">": "&gt;",
5
+ '"': "&quot;"
6
+ };
7
+
8
+ const escapeHtml = value =>
9
+ String(value ?? "").replace(/[&<>"]/g, c => HTML_ESCAPES[c]);
10
+
11
+ export const tsvToHtmlTable = tsv => {
12
+ const rows = String(tsv ?? "")
13
+ .split("\n")
14
+ .map(line => {
15
+ const cells = line
16
+ .split("\t")
17
+ .map(v => `<td>${escapeHtml(v)}</td>`)
18
+ .join("");
19
+ return `<tr>${cells}</tr>`;
20
+ })
21
+ .join("");
22
+ return `<table>${rows}</table>`;
23
+ };
@@ -0,0 +1,41 @@
1
+ import { tsvToHtmlTable } from "./tsvToHtmlTable";
2
+
3
+ describe("tsvToHtmlTable", () => {
4
+ it("wraps a single row in a <table>", () => {
5
+ expect(tsvToHtmlTable("a\tb\tc")).toBe(
6
+ "<table><tr><td>a</td><td>b</td><td>c</td></tr></table>"
7
+ );
8
+ });
9
+
10
+ it("splits rows on newline and cells on tab", () => {
11
+ expect(tsvToHtmlTable("h1\th2\n1\t2\nA\tB")).toBe(
12
+ "<table>" +
13
+ "<tr><td>h1</td><td>h2</td></tr>" +
14
+ "<tr><td>1</td><td>2</td></tr>" +
15
+ "<tr><td>A</td><td>B</td></tr>" +
16
+ "</table>"
17
+ );
18
+ });
19
+
20
+ it("escapes HTML-significant characters in cell content", () => {
21
+ expect(tsvToHtmlTable('<b>&"x"</b>\tnormal')).toBe(
22
+ "<table><tr><td>&lt;b&gt;&amp;&quot;x&quot;&lt;/b&gt;</td><td>normal</td></tr></table>"
23
+ );
24
+ });
25
+
26
+ it("preserves empty cells and empty rows", () => {
27
+ expect(tsvToHtmlTable("a\t\tb\n\nc")).toBe(
28
+ "<table>" +
29
+ "<tr><td>a</td><td></td><td>b</td></tr>" +
30
+ "<tr><td></td></tr>" +
31
+ "<tr><td>c</td></tr>" +
32
+ "</table>"
33
+ );
34
+ });
35
+
36
+ it("handles empty/null input", () => {
37
+ expect(tsvToHtmlTable("")).toBe("<table><tr><td></td></tr></table>");
38
+ expect(tsvToHtmlTable(null)).toBe("<table><tr><td></td></tr></table>");
39
+ expect(tsvToHtmlTable(undefined)).toBe("<table><tr><td></td></tr></table>");
40
+ });
41
+ });