@protobase/ui 0.66.0 → 0.66.1

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.
Files changed (23) hide show
  1. package/dist/app/import/csv-chunks.js +70 -0
  2. package/dist/app/import/line-breaks.js +47 -0
  3. package/dist/app/import/sheet-file.js +1 -1
  4. package/dist/package.js +1 -1
  5. package/dist/shell/assets/{app-CdLhzPaH.js → app-D-elg6qm.js} +5 -5
  6. package/dist/shell/assets/{calls-fbu88Iwx.js → calls-DHvl29Pd.js} +2 -2
  7. package/dist/shell/assets/{index-Du6GlNEk.js → index-D8SK4U2s.js} +2 -2
  8. package/dist/shell/assets/parse-worker-CbZA-uNr.js +35 -0
  9. package/dist/shell/assets/{records-map-C1_HI-hA.js → records-map-hxWNR_fi.js} +2 -2
  10. package/dist/shell/assets/{shared-protobase-ui-o_KsAqf7.js → shared-protobase-ui-7FTH3m59.js} +2 -2
  11. package/dist/shell/index.html +3 -3
  12. package/dist/shell/protobase.shell.json +2 -2
  13. package/dist/shell/protobase.sw.js +2 -2
  14. package/dist/shell-source-maps/assets/{app-CdLhzPaH.js.map → app-D-elg6qm.js.map} +1 -1
  15. package/dist/shell-source-maps/assets/{calls-fbu88Iwx.js.map → calls-DHvl29Pd.js.map} +1 -1
  16. package/dist/shell-source-maps/assets/{index-Du6GlNEk.js.map → index-D8SK4U2s.js.map} +1 -1
  17. package/dist/shell-source-maps/assets/parse-worker-CbZA-uNr.js.map +1 -0
  18. package/dist/shell-source-maps/assets/{records-map-C1_HI-hA.js.map → records-map-hxWNR_fi.js.map} +1 -1
  19. package/dist/shell-source-maps/assets/{shared-protobase-ui-o_KsAqf7.js.map → shared-protobase-ui-7FTH3m59.js.map} +1 -1
  20. package/package.json +8 -4
  21. package/dist/app/import/csv-parser.js +0 -119
  22. package/dist/shell/assets/parse-worker-ChfW_ehD.js +0 -18
  23. package/dist/shell-source-maps/assets/parse-worker-ChfW_ehD.js.map +0 -1
@@ -0,0 +1,70 @@
1
+ import { createLineBreakNormalizer } from "./line-breaks.js";
2
+ import Papa from "papaparse";
3
+ //#region src/app/import/csv-chunks.ts
4
+ const headerEnd = (text) => {
5
+ let quoted = false;
6
+ for (let index = 0; index < text.length; index++) {
7
+ const char = text[index];
8
+ if (char === "\"") quoted = !quoted;
9
+ else if (!quoted && (char === "\n" || char === "\r")) return index;
10
+ }
11
+ };
12
+ const headerDelimiter = (header) => Papa.parse(header, { delimitersToGuess: [
13
+ ",",
14
+ ";",
15
+ " "
16
+ ] }).meta.delimiter;
17
+ /**
18
+ * A CSV parser fed text a chunk at a time, so a large file is read without holding it whole: papaparse's (RFC 4180,
19
+ * quoted fields with `""` for a quote and line breaks inside), with the header line's delimiter and rows ended by CRLF,
20
+ * LF or CR, mixed if need be. `push` returns the rows completed by the chunk, `end` the last one; the line break ending
21
+ * the file makes no row of its own. A byte order mark at the start is dropped.
22
+ */
23
+ const createCsvParser = () => {
24
+ let pending = "";
25
+ let started;
26
+ const start = (end) => {
27
+ const delimiter = headerDelimiter(pending.slice(0, end));
28
+ const normalizer = createLineBreakNormalizer(delimiter);
29
+ started = {
30
+ parser: new Papa.Parser({
31
+ delimiter,
32
+ newline: "\n"
33
+ }),
34
+ normalizer
35
+ };
36
+ pending = normalizer.push(pending);
37
+ return started;
38
+ };
39
+ const completed = (parser) => {
40
+ const result = parser.parse(pending, 0, true);
41
+ pending = pending.slice(result.meta.cursor);
42
+ return result.data;
43
+ };
44
+ const push = (chunk) => {
45
+ if (started) {
46
+ pending += started.normalizer.push(chunk);
47
+ return completed(started.parser);
48
+ }
49
+ pending += chunk;
50
+ if (pending.charCodeAt(0) === 65279) pending = pending.slice(1);
51
+ const end = headerEnd(pending);
52
+ if (end === void 0) return [];
53
+ return completed(start(end).parser);
54
+ };
55
+ const end = () => {
56
+ if (!started && pending === "") return [];
57
+ const { parser } = started ?? start(headerEnd(pending) ?? pending.length);
58
+ const rows = completed(parser);
59
+ if (pending === "") return rows;
60
+ const last = parser.parse(pending, 0, false).data;
61
+ pending = "";
62
+ return [...rows, ...last];
63
+ };
64
+ return {
65
+ push,
66
+ end
67
+ };
68
+ };
69
+ //#endregion
70
+ export { createCsvParser };
@@ -0,0 +1,47 @@
1
+ //#region src/app/import/line-breaks.ts
2
+ /**
3
+ * Turns every CR and CRLF between rows into an LF, a chunk of CSV text at a time, so a file whose rows end in mixed
4
+ * line breaks reads as one: papaparse takes a single line break per file. A quote opens a quoted field only at a
5
+ * field's start, as papaparse reads it, and line breaks inside quoted fields are cell text and stay as they are.
6
+ */
7
+ const createLineBreakNormalizer = (delimiter) => {
8
+ let state = "start";
9
+ let crSeen = false;
10
+ const push = (chunk) => {
11
+ let out = "";
12
+ for (const char of chunk) {
13
+ if (crSeen) {
14
+ crSeen = false;
15
+ if (char === "\n") continue;
16
+ }
17
+ if (state === "quoted") {
18
+ if (char === "\"") state = "quoteSeen";
19
+ out += char;
20
+ continue;
21
+ }
22
+ if (state === "quoteSeen") {
23
+ state = "quoted";
24
+ if (char === "\"") {
25
+ out += char;
26
+ continue;
27
+ }
28
+ state = "unquoted";
29
+ }
30
+ if (char === "\r" || char === "\n") {
31
+ crSeen = char === "\r";
32
+ state = "start";
33
+ out += "\n";
34
+ } else if (char === "\"" && state === "start") {
35
+ state = "quoted";
36
+ out += char;
37
+ } else {
38
+ state = char === delimiter ? "start" : "unquoted";
39
+ out += char;
40
+ }
41
+ }
42
+ return out;
43
+ };
44
+ return { push };
45
+ };
46
+ //#endregion
47
+ export { createLineBreakNormalizer };
@@ -1,5 +1,5 @@
1
1
  import { text } from "./messages.js";
2
- import { createCsvParser } from "./csv-parser.js";
2
+ import { createCsvParser } from "./csv-chunks.js";
3
3
  import { openWorkbook } from "./xlsx-reader.js";
4
4
  //#region src/app/import/sheet-file.ts
5
5
  const startsAsZip = async (file) => {
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.66.0";
2
+ var version = "0.66.1";
3
3
  var protobase = { "pluginApi": 1 };
4
4
  //#endregion
5
5
  export { protobase, version };