@updog/data-editor 0.1.39 → 0.1.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@updog/data-editor",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "description": "Client-side CSV importer and spreadsheet editor for React. Import CSV, Excel, JSON, TSV, and XML, match columns, validate, and edit 1M+ rows entirely in the browser.",
5
5
  "author": "Mikhail Kutateladze <admin@updog.tech>",
6
6
  "homepage": "https://updog.tech",
@@ -22,7 +22,7 @@
22
22
  "*.css"
23
23
  ],
24
24
  "files": [
25
- "index.js",
25
+ "*.js",
26
26
  "index.css",
27
27
  "index.d.ts",
28
28
  "assets",
@@ -0,0 +1,63 @@
1
+ import { i as e, n as t, r as n, t as r } from "./encoding-DUtZMwy0.js";
2
+ import i from "papaparse";
3
+ //#endregion
4
+ //#region src/core/io/parsers/index.ts
5
+ var a = {
6
+ csv: async ({ file: a }) => {
7
+ let { encoding: o, delimiter: s } = await t(a), c = await n(a), l = new TextDecoder(o).decode(c), u = i.parse(l, {
8
+ header: !1,
9
+ skipEmptyLines: !1,
10
+ delimiter: s
11
+ }), d = u.data;
12
+ for (let t of d) for (let n = 0; n < t.length; n++) t[n] = e(t[n]);
13
+ let f = u.errors.map((e) => ({
14
+ code: e.code,
15
+ row: e.row
16
+ }));
17
+ return {
18
+ kind: "rows",
19
+ rows: r(d, s),
20
+ delimiter: s,
21
+ errors: f
22
+ };
23
+ },
24
+ json: async ({ file: r }) => {
25
+ let { encoding: i, bomLength: a } = await t(r), o = await n(r), s = new TextDecoder(i).decode(o).slice(a), c = JSON.parse(s).map((t) => {
26
+ let n = {};
27
+ for (let r of Object.keys(t)) n[e(r)] = t[r];
28
+ return n;
29
+ }), l = /* @__PURE__ */ new Set();
30
+ for (let e of c) for (let t of Object.keys(e)) l.add(t);
31
+ let u = Array.from(l);
32
+ return {
33
+ kind: "records",
34
+ headers: u,
35
+ rows: c.map((t) => {
36
+ let n = {};
37
+ for (let r of u) {
38
+ let i = t[r];
39
+ n[r] = i == null ? "" : e(String(i));
40
+ }
41
+ return n;
42
+ })
43
+ };
44
+ },
45
+ xml: async ({ file: r }) => {
46
+ let { encoding: i, bomLength: a } = await t(r), o = await n(r), s = new TextDecoder(i).decode(o).slice(a), c = new DOMParser().parseFromString(s, "application/xml");
47
+ if (c.querySelector("parsererror")) throw Error("Failed to parse XML file");
48
+ let l = Array.from(c.documentElement.children), u = /* @__PURE__ */ new Set();
49
+ for (let e of l) for (let t of Array.from(e.children)) u.add(t.tagName);
50
+ let d = Array.from(u);
51
+ return {
52
+ kind: "records",
53
+ headers: d,
54
+ rows: l.map((t) => {
55
+ let n = {};
56
+ for (let r of d) n[r] = e(t.querySelector(r)?.textContent ?? "");
57
+ return n;
58
+ })
59
+ };
60
+ }
61
+ };
62
+ //#endregion
63
+ export { a as PARSERS };
@@ -0,0 +1,51 @@
1
+ //#region src/core/io/serializers/text.ts
2
+ var e = /^[=@+\-\t\r]/, t = /^[+-][\d.,'\s  ]*$/;
3
+ function n(n) {
4
+ return !e.test(n) || t.test(n) ? n : `'${n}`;
5
+ }
6
+ function r(e) {
7
+ let t = n(e);
8
+ return t.includes(",") || t.includes("\"") || t.includes("\n") || t.includes("\r") ? `"${t.replace(/"/g, "\"\"")}"` : t;
9
+ }
10
+ function i(e, t) {
11
+ let n = t ?? (e.length > 0 ? Object.keys(e[0]) : []);
12
+ if (n.length === 0) return new Blob([""], { type: "text/csv" });
13
+ let i = n.map(r).join(","), a = e.map((e) => n.map((t) => r(e[t] ?? "")).join(",")), o = a.length > 0 ? `${i}\n${a.join("\n")}` : `${i}\n`;
14
+ return new Blob([`${o}`], { type: "text/csv;charset=utf-8" });
15
+ }
16
+ function a(e) {
17
+ let t = n(e);
18
+ return t.includes(" ") || t.includes("\"") || t.includes("\n") || t.includes("\r") ? `"${t.replace(/"/g, "\"\"")}"` : t;
19
+ }
20
+ function o(e, t) {
21
+ let n = t ?? (e.length > 0 ? Object.keys(e[0]) : []);
22
+ if (n.length === 0) return new Blob([""], { type: "text/tab-separated-values" });
23
+ let r = n.map(a).join(" "), i = e.map((e) => n.map((t) => a(e[t] ?? "")).join(" ")), o = i.length > 0 ? `${r}\n${i.join("\n")}` : `${r}\n`;
24
+ return new Blob([`${o}`], { type: "text/tab-separated-values;charset=utf-8" });
25
+ }
26
+ function s(e) {
27
+ return new Blob([JSON.stringify(e, null, 2)], { type: "application/json;charset=utf-8" });
28
+ }
29
+ function c(e) {
30
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
31
+ }
32
+ function l(e, t) {
33
+ let n = t ?? (e.length > 0 ? Object.keys(e[0]) : []), r = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rows>\n";
34
+ for (let t of e) {
35
+ r += " <row>\n";
36
+ for (let e of n) {
37
+ let n = e.replace(/\s+/g, "_");
38
+ r += ` <${n}>${c(t[e] ?? "")}</${n}>\n`;
39
+ }
40
+ r += " </row>\n";
41
+ }
42
+ return r += "</rows>", new Blob([r], { type: "application/xml;charset=utf-8" });
43
+ }
44
+ var u = (e) => e.columns.map((e) => e.title), d = {
45
+ csv: (e) => i(e.rows, u(e)),
46
+ tsv: (e) => o(e.rows, u(e)),
47
+ json: (e) => s(e.rows),
48
+ xml: (e) => l(e.rows, u(e))
49
+ };
50
+ //#endregion
51
+ export { d as SERIALIZERS };