@ozguraltan/strapi-content-input 1.0.26 → 1.0.28
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/README.md +8 -2
- package/dist/admin/{AnalyticsHubPage-Crz4vv46.mjs → AnalyticsHubPage-1d4lx37k.mjs} +30 -52
- package/dist/admin/{AnalyticsHubPage-CHlhvUIU.js → AnalyticsHubPage-BzKx8DTv.js} +30 -70
- package/dist/admin/{ContentInputField-BeKDx_bb.mjs → ContentInputField-DQvPlNcD.mjs} +427 -11
- package/dist/admin/{ContentInputField-CNWVLuRt.js → ContentInputField-DgS2wZNb.js} +427 -29
- package/dist/admin/{SurveyWidgetEditor-GKRT3eHj.mjs → SurveyWidgetEditor-BZHyY2eb.mjs} +2445 -3
- package/dist/admin/{SurveyWidgetEditor-BTipBBEU.js → SurveyWidgetEditor-k7kA6LQT.js} +2445 -3
- package/dist/admin/{index-DuJM60tO.js → index-BvofXe07.js} +2 -2
- package/dist/admin/{index-DSDcG4QW.mjs → index-CStmbvTw.mjs} +2 -2
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/analytics/ExcelReportStudioModal.d.ts +17 -0
- package/dist/admin/src/core/xlsxBrowserReader.d.ts +11 -0
- package/dist/server/index.js +3075 -1625
- package/dist/server/index.mjs +3075 -1607
- package/dist/server/src/controllers/ci-form.d.ts +1 -0
- package/dist/server/src/controllers/index.d.ts +1 -0
- package/dist/server/src/index.d.ts +8 -1
- package/dist/server/src/services/ci-form.d.ts +6 -1
- package/dist/server/src/services/ci-survey.d.ts +2 -1
- package/dist/server/src/services/index.d.ts +7 -1
- package/dist/server/src/utils/surveyEngine.d.ts +3 -1
- package/dist/server/src/utils/xlsxReportBuilder.d.ts +38 -0
- package/package.json +13 -6
|
@@ -3,32 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const ReactDOM = require("react-dom");
|
|
6
|
-
const SurveyWidgetEditor = require("./SurveyWidgetEditor-
|
|
7
|
-
const index = require("./index-
|
|
6
|
+
const SurveyWidgetEditor = require("./SurveyWidgetEditor-k7kA6LQT.js");
|
|
7
|
+
const index = require("./index-BvofXe07.js");
|
|
8
8
|
const react = require("swiper/react");
|
|
9
9
|
const modules = require("swiper/modules");
|
|
10
10
|
const admin = require("@strapi/strapi/admin");
|
|
11
|
-
const XLSXNs = require("xlsx");
|
|
12
11
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
13
|
-
function _interopNamespace(e) {
|
|
14
|
-
if (e && e.__esModule) return e;
|
|
15
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
16
|
-
if (e) {
|
|
17
|
-
for (const k in e) {
|
|
18
|
-
if (k !== "default") {
|
|
19
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: () => e[k]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n.default = e;
|
|
28
|
-
return Object.freeze(n);
|
|
29
|
-
}
|
|
30
12
|
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
31
|
-
const XLSXNs__namespace = /* @__PURE__ */ _interopNamespace(XLSXNs);
|
|
32
13
|
function buildRichSampleRows(locale = "en") {
|
|
33
14
|
const tr = locale === "tr";
|
|
34
15
|
return [
|
|
@@ -11754,6 +11735,427 @@ const HeroSliderStudioModal = ({
|
|
|
11754
11735
|
document.body
|
|
11755
11736
|
);
|
|
11756
11737
|
};
|
|
11738
|
+
const MAX_ARCHIVE_BYTES = 20 * 1024 * 1024;
|
|
11739
|
+
const MAX_ENTRIES = 128;
|
|
11740
|
+
const MAX_UNCOMPRESSED_BYTES = 25 * 1024 * 1024;
|
|
11741
|
+
function normalizeZipPath(rawPath) {
|
|
11742
|
+
const cleaned = String(rawPath || "").replace(/\\/g, "/").replace(/^\/+/, "");
|
|
11743
|
+
if (!cleaned || cleaned.includes("\0") || cleaned.split("/").includes("..")) {
|
|
11744
|
+
throw new Error("Unsafe archive entry path detected in .xlsx file.");
|
|
11745
|
+
}
|
|
11746
|
+
return cleaned;
|
|
11747
|
+
}
|
|
11748
|
+
function resolveRelativeZipTarget(baseFile, target) {
|
|
11749
|
+
const cleanTarget = String(target || "").replace(/\\/g, "/");
|
|
11750
|
+
if (cleanTarget.startsWith("/")) {
|
|
11751
|
+
return normalizeZipPath(cleanTarget.slice(1));
|
|
11752
|
+
}
|
|
11753
|
+
const baseParts = baseFile.split("/");
|
|
11754
|
+
baseParts.pop();
|
|
11755
|
+
for (const seg of cleanTarget.split("/")) {
|
|
11756
|
+
if (!seg || seg === ".") continue;
|
|
11757
|
+
if (seg === "..") {
|
|
11758
|
+
baseParts.pop();
|
|
11759
|
+
} else {
|
|
11760
|
+
baseParts.push(seg);
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
return normalizeZipPath(baseParts.join("/"));
|
|
11764
|
+
}
|
|
11765
|
+
function parseCentralDirectory(buf) {
|
|
11766
|
+
if (buf.byteLength < 22) {
|
|
11767
|
+
throw new Error("Invalid or empty spreadsheet file.");
|
|
11768
|
+
}
|
|
11769
|
+
if (buf.byteLength > MAX_ARCHIVE_BYTES) {
|
|
11770
|
+
throw new Error("Excel (.xlsx) file exceeds maximum allowed size (20 MB).");
|
|
11771
|
+
}
|
|
11772
|
+
const view = new DataView(buf);
|
|
11773
|
+
const magic = view.getUint32(0, false);
|
|
11774
|
+
if (magic === 3503231456) {
|
|
11775
|
+
throw new Error(
|
|
11776
|
+
"Legacy Excel 97-2003 (.xls) binary format is not supported. Please save as .xlsx or .csv."
|
|
11777
|
+
);
|
|
11778
|
+
}
|
|
11779
|
+
const minEocdOffset = Math.max(0, buf.byteLength - 65557);
|
|
11780
|
+
let eocdOffset = -1;
|
|
11781
|
+
for (let pos = buf.byteLength - 22; pos >= minEocdOffset; pos--) {
|
|
11782
|
+
if (view.getUint32(pos, true) === 101010256) {
|
|
11783
|
+
eocdOffset = pos;
|
|
11784
|
+
break;
|
|
11785
|
+
}
|
|
11786
|
+
}
|
|
11787
|
+
if (eocdOffset < 0) {
|
|
11788
|
+
throw new Error("Invalid .xlsx archive (ZIP End of Central Directory not found).");
|
|
11789
|
+
}
|
|
11790
|
+
const totalEntries = view.getUint16(eocdOffset + 10, true);
|
|
11791
|
+
if (totalEntries > MAX_ENTRIES) {
|
|
11792
|
+
throw new Error(
|
|
11793
|
+
`Archive contains too many internal files (${totalEntries} > ${MAX_ENTRIES}).`
|
|
11794
|
+
);
|
|
11795
|
+
}
|
|
11796
|
+
const cdSize = view.getUint32(eocdOffset + 12, true);
|
|
11797
|
+
const cdOffset = view.getUint32(eocdOffset + 16, true);
|
|
11798
|
+
if (cdOffset + cdSize > buf.byteLength) {
|
|
11799
|
+
throw new Error("Corrupted .xlsx ZIP Central Directory bounds.");
|
|
11800
|
+
}
|
|
11801
|
+
const dec = new TextDecoder("utf-8");
|
|
11802
|
+
const entries = /* @__PURE__ */ new Map();
|
|
11803
|
+
let ptr = cdOffset;
|
|
11804
|
+
for (let i = 0; i < totalEntries; i++) {
|
|
11805
|
+
if (ptr + 46 > buf.byteLength || view.getUint32(ptr, true) !== 33639248) {
|
|
11806
|
+
throw new Error("Corrupted .xlsx Central Directory header.");
|
|
11807
|
+
}
|
|
11808
|
+
const compressionMethod = view.getUint16(ptr + 10, true);
|
|
11809
|
+
const compressedSize = view.getUint32(ptr + 20, true);
|
|
11810
|
+
const uncompressedSize = view.getUint32(ptr + 24, true);
|
|
11811
|
+
const nameLen = view.getUint16(ptr + 28, true);
|
|
11812
|
+
const extraLen = view.getUint16(ptr + 30, true);
|
|
11813
|
+
const commentLen = view.getUint16(ptr + 32, true);
|
|
11814
|
+
const localHeaderOffset = view.getUint32(ptr + 42, true);
|
|
11815
|
+
if (ptr + 46 + nameLen > buf.byteLength) {
|
|
11816
|
+
throw new Error("Truncated filename in .xlsx Central Directory.");
|
|
11817
|
+
}
|
|
11818
|
+
if (uncompressedSize > MAX_UNCOMPRESSED_BYTES) {
|
|
11819
|
+
throw new Error("Uncompressed entry size exceeds 25 MB safety limit.");
|
|
11820
|
+
}
|
|
11821
|
+
const rawName = dec.decode(new Uint8Array(buf, ptr + 46, nameLen));
|
|
11822
|
+
const path = normalizeZipPath(rawName);
|
|
11823
|
+
entries.set(path, {
|
|
11824
|
+
path,
|
|
11825
|
+
compressionMethod,
|
|
11826
|
+
compressedSize,
|
|
11827
|
+
uncompressedSize,
|
|
11828
|
+
localHeaderOffset
|
|
11829
|
+
});
|
|
11830
|
+
ptr += 46 + nameLen + extraLen + commentLen;
|
|
11831
|
+
}
|
|
11832
|
+
return entries;
|
|
11833
|
+
}
|
|
11834
|
+
async function extractEntryUtf8(buf, entry, budget) {
|
|
11835
|
+
const view = new DataView(buf);
|
|
11836
|
+
const lhPos = entry.localHeaderOffset;
|
|
11837
|
+
if (lhPos + 30 > buf.byteLength || view.getUint32(lhPos, true) !== 67324752) {
|
|
11838
|
+
throw new Error(`Corrupted local ZIP header for ${entry.path}`);
|
|
11839
|
+
}
|
|
11840
|
+
const nameLen = view.getUint16(lhPos + 26, true);
|
|
11841
|
+
const extraLen = view.getUint16(lhPos + 28, true);
|
|
11842
|
+
const dataOffset = lhPos + 30 + nameLen + extraLen;
|
|
11843
|
+
if (dataOffset + entry.compressedSize > buf.byteLength) {
|
|
11844
|
+
throw new Error(`Truncated compressed payload for ${entry.path}`);
|
|
11845
|
+
}
|
|
11846
|
+
const rawSlice = new Uint8Array(buf, dataOffset, entry.compressedSize);
|
|
11847
|
+
const dec = new TextDecoder("utf-8");
|
|
11848
|
+
if (entry.compressionMethod === 0) {
|
|
11849
|
+
budget.totalBytes += rawSlice.byteLength;
|
|
11850
|
+
if (budget.totalBytes > MAX_UNCOMPRESSED_BYTES) {
|
|
11851
|
+
throw new Error("Decompressed .xlsx content exceeds 25 MB safety limit.");
|
|
11852
|
+
}
|
|
11853
|
+
return dec.decode(rawSlice);
|
|
11854
|
+
}
|
|
11855
|
+
if (entry.compressionMethod === 8) {
|
|
11856
|
+
if (typeof DecompressionStream === "undefined") {
|
|
11857
|
+
throw new Error("Browser does not support DecompressionStream for DEFLATE .xlsx files.");
|
|
11858
|
+
}
|
|
11859
|
+
const ds = new DecompressionStream("deflate-raw");
|
|
11860
|
+
const writer = ds.writable.getWriter();
|
|
11861
|
+
const writePromise = writer.write(rawSlice).then(() => writer.close());
|
|
11862
|
+
const reader = ds.readable.getReader();
|
|
11863
|
+
const chunks = [];
|
|
11864
|
+
let entryBytes = 0;
|
|
11865
|
+
while (true) {
|
|
11866
|
+
const { value, done } = await reader.read();
|
|
11867
|
+
if (done) break;
|
|
11868
|
+
if (value) {
|
|
11869
|
+
entryBytes += value.byteLength;
|
|
11870
|
+
budget.totalBytes += value.byteLength;
|
|
11871
|
+
if (budget.totalBytes > MAX_UNCOMPRESSED_BYTES) {
|
|
11872
|
+
try {
|
|
11873
|
+
await reader.cancel();
|
|
11874
|
+
} catch {
|
|
11875
|
+
}
|
|
11876
|
+
throw new Error("Decompressed .xlsx content exceeds 25 MB safety limit.");
|
|
11877
|
+
}
|
|
11878
|
+
chunks.push(value);
|
|
11879
|
+
}
|
|
11880
|
+
}
|
|
11881
|
+
await writePromise;
|
|
11882
|
+
const merged = new Uint8Array(entryBytes);
|
|
11883
|
+
let pos = 0;
|
|
11884
|
+
for (const ch of chunks) {
|
|
11885
|
+
merged.set(ch, pos);
|
|
11886
|
+
pos += ch.byteLength;
|
|
11887
|
+
}
|
|
11888
|
+
return dec.decode(merged);
|
|
11889
|
+
}
|
|
11890
|
+
throw new Error(
|
|
11891
|
+
`Unsupported ZIP compression method (${entry.compressionMethod}) in ${entry.path}.`
|
|
11892
|
+
);
|
|
11893
|
+
}
|
|
11894
|
+
function parseXmlDoc(xml) {
|
|
11895
|
+
if (typeof DOMParser === "undefined") {
|
|
11896
|
+
throw new Error("DOMParser is required to parse .xlsx XML documents.");
|
|
11897
|
+
}
|
|
11898
|
+
const doc = new DOMParser().parseFromString(xml, "application/xml");
|
|
11899
|
+
const parserErr = doc.getElementsByTagName("parsererror")[0];
|
|
11900
|
+
if (parserErr) {
|
|
11901
|
+
throw new Error("Malformed XML inside .xlsx archive.");
|
|
11902
|
+
}
|
|
11903
|
+
return doc;
|
|
11904
|
+
}
|
|
11905
|
+
function descendantsByLocal(root, localName) {
|
|
11906
|
+
const out = [];
|
|
11907
|
+
const all = root.getElementsByTagName("*");
|
|
11908
|
+
for (let i = 0; i < all.length; i++) {
|
|
11909
|
+
const el = all[i];
|
|
11910
|
+
if (el.localName === localName) {
|
|
11911
|
+
out.push(el);
|
|
11912
|
+
}
|
|
11913
|
+
}
|
|
11914
|
+
return out;
|
|
11915
|
+
}
|
|
11916
|
+
function childrenByLocal(parent, localName) {
|
|
11917
|
+
if (!parent) return [];
|
|
11918
|
+
const out = [];
|
|
11919
|
+
const ch = parent.children;
|
|
11920
|
+
for (let i = 0; i < ch.length; i++) {
|
|
11921
|
+
if (ch[i].localName === localName) {
|
|
11922
|
+
out.push(ch[i]);
|
|
11923
|
+
}
|
|
11924
|
+
}
|
|
11925
|
+
return out;
|
|
11926
|
+
}
|
|
11927
|
+
function firstChildByLocal(parent, localName) {
|
|
11928
|
+
if (!parent) return null;
|
|
11929
|
+
const ch = parent.children;
|
|
11930
|
+
for (let i = 0; i < ch.length; i++) {
|
|
11931
|
+
if (ch[i].localName === localName) return ch[i];
|
|
11932
|
+
}
|
|
11933
|
+
return null;
|
|
11934
|
+
}
|
|
11935
|
+
function extractRichOrPlainText(container) {
|
|
11936
|
+
const parts = [];
|
|
11937
|
+
const walk = (node) => {
|
|
11938
|
+
if (node.localName === "rPh") return;
|
|
11939
|
+
if (node.localName === "t") {
|
|
11940
|
+
parts.push(node.textContent || "");
|
|
11941
|
+
return;
|
|
11942
|
+
}
|
|
11943
|
+
const ch = node.children;
|
|
11944
|
+
for (let i = 0; i < ch.length; i++) {
|
|
11945
|
+
walk(ch[i]);
|
|
11946
|
+
}
|
|
11947
|
+
};
|
|
11948
|
+
walk(container);
|
|
11949
|
+
return parts.join("");
|
|
11950
|
+
}
|
|
11951
|
+
function isBuiltInDateNumFmt(id) {
|
|
11952
|
+
return id >= 14 && id <= 22 || id >= 27 && id <= 36 || id >= 45 && id <= 47 || id >= 50 && id <= 58;
|
|
11953
|
+
}
|
|
11954
|
+
function isCustomDateFormatCode(code) {
|
|
11955
|
+
const cleaned = String(code || "").replace(/"[^"]*"/g, "").replace(/\[[^\]]*\]/g, "").replace(/\\./g, "").toLowerCase();
|
|
11956
|
+
if (!cleaned || /[0#?]/.test(cleaned)) return false;
|
|
11957
|
+
return /[ymdhs]/.test(cleaned);
|
|
11958
|
+
}
|
|
11959
|
+
function parseDateStyleFlags(stylesXml) {
|
|
11960
|
+
if (!stylesXml) return [];
|
|
11961
|
+
const doc = parseXmlDoc(stylesXml);
|
|
11962
|
+
const customFmtMap = /* @__PURE__ */ new Map();
|
|
11963
|
+
for (const nf of descendantsByLocal(doc, "numFmt")) {
|
|
11964
|
+
const id = Number(nf.getAttribute("numFmtId"));
|
|
11965
|
+
const code = nf.getAttribute("formatCode") || "";
|
|
11966
|
+
if (!Number.isNaN(id)) {
|
|
11967
|
+
customFmtMap.set(id, code);
|
|
11968
|
+
}
|
|
11969
|
+
}
|
|
11970
|
+
const cellXfs = descendantsByLocal(doc, "cellXfs")[0];
|
|
11971
|
+
if (!cellXfs) return [];
|
|
11972
|
+
return childrenByLocal(cellXfs, "xf").map((xf) => {
|
|
11973
|
+
const fmtId = Number(xf.getAttribute("numFmtId") || "0");
|
|
11974
|
+
if (isBuiltInDateNumFmt(fmtId)) return true;
|
|
11975
|
+
const custom = customFmtMap.get(fmtId);
|
|
11976
|
+
return custom ? isCustomDateFormatCode(custom) : false;
|
|
11977
|
+
});
|
|
11978
|
+
}
|
|
11979
|
+
function excelSerialToIsoString(serial) {
|
|
11980
|
+
const utcMs = Math.round((serial - 25569) * 86400 * 1e3);
|
|
11981
|
+
const dt = new Date(utcMs);
|
|
11982
|
+
if (Number.isNaN(dt.getTime())) return String(serial);
|
|
11983
|
+
const iso = dt.toISOString();
|
|
11984
|
+
const frac = Math.abs(serial - Math.floor(serial));
|
|
11985
|
+
return frac > 1e-4 ? iso.slice(0, 16).replace("T", " ") : iso.slice(0, 10);
|
|
11986
|
+
}
|
|
11987
|
+
function parseColIndexFromRef(cellRef) {
|
|
11988
|
+
let col = 0;
|
|
11989
|
+
let hasLetters = false;
|
|
11990
|
+
for (let i = 0; i < cellRef.length; i++) {
|
|
11991
|
+
const code = cellRef.charCodeAt(i);
|
|
11992
|
+
if (code >= 65 && code <= 90) {
|
|
11993
|
+
col = col * 26 + (code - 64);
|
|
11994
|
+
hasLetters = true;
|
|
11995
|
+
} else if (code >= 97 && code <= 122) {
|
|
11996
|
+
col = col * 26 + (code - 96);
|
|
11997
|
+
hasLetters = true;
|
|
11998
|
+
} else {
|
|
11999
|
+
break;
|
|
12000
|
+
}
|
|
12001
|
+
}
|
|
12002
|
+
return hasLetters ? col - 1 : -1;
|
|
12003
|
+
}
|
|
12004
|
+
function sanitizeHeaderKey(rawHeader, colIdx, used) {
|
|
12005
|
+
let base = String(rawHeader ?? "").trim();
|
|
12006
|
+
if (!base) base = `Column ${colIdx + 1}`;
|
|
12007
|
+
if (base === "__proto__" || base === "constructor" || base === "prototype") {
|
|
12008
|
+
base = `_${base}`;
|
|
12009
|
+
}
|
|
12010
|
+
let candidate = base;
|
|
12011
|
+
let suffix = 1;
|
|
12012
|
+
while (used.has(candidate)) {
|
|
12013
|
+
candidate = `${base}_${suffix}`;
|
|
12014
|
+
suffix += 1;
|
|
12015
|
+
}
|
|
12016
|
+
used.add(candidate);
|
|
12017
|
+
return candidate;
|
|
12018
|
+
}
|
|
12019
|
+
function parseWorksheetRows(sheetXml, sharedStrings, dateStyles) {
|
|
12020
|
+
const doc = parseXmlDoc(sheetXml);
|
|
12021
|
+
const sheetData = descendantsByLocal(doc, "sheetData")[0];
|
|
12022
|
+
if (!sheetData) return [];
|
|
12023
|
+
const rawAoA = [];
|
|
12024
|
+
let maxColCount = 0;
|
|
12025
|
+
for (const rowEl of childrenByLocal(sheetData, "row")) {
|
|
12026
|
+
const rowArr = [];
|
|
12027
|
+
let nextCol = 0;
|
|
12028
|
+
let hasNonEmpty = false;
|
|
12029
|
+
for (const cEl of childrenByLocal(rowEl, "c")) {
|
|
12030
|
+
const refAttr = cEl.getAttribute("r") || "";
|
|
12031
|
+
const parsedCol = refAttr ? parseColIndexFromRef(refAttr) : -1;
|
|
12032
|
+
const colIdx = parsedCol >= 0 ? parsedCol : nextCol;
|
|
12033
|
+
nextCol = colIdx + 1;
|
|
12034
|
+
const tAttr = cEl.getAttribute("t") || "";
|
|
12035
|
+
const sAttr = Number(cEl.getAttribute("s") || "-1");
|
|
12036
|
+
const vEl = firstChildByLocal(cEl, "v");
|
|
12037
|
+
const isEl = firstChildByLocal(cEl, "is");
|
|
12038
|
+
const vText = vEl?.textContent ?? "";
|
|
12039
|
+
let cellVal = "";
|
|
12040
|
+
if (tAttr === "s") {
|
|
12041
|
+
const ssIdx = Number(vText);
|
|
12042
|
+
cellVal = !Number.isNaN(ssIdx) && ssIdx >= 0 && ssIdx < sharedStrings.length ? sharedStrings[ssIdx] : "";
|
|
12043
|
+
} else if (tAttr === "inlineStr") {
|
|
12044
|
+
cellVal = isEl ? extractRichOrPlainText(isEl) : "";
|
|
12045
|
+
} else if (tAttr === "b") {
|
|
12046
|
+
cellVal = vText === "1" || vText.toLowerCase() === "true";
|
|
12047
|
+
} else if (tAttr === "str" || tAttr === "e") {
|
|
12048
|
+
cellVal = vText;
|
|
12049
|
+
} else if (vText !== "") {
|
|
12050
|
+
const num = Number(vText);
|
|
12051
|
+
if (!Number.isNaN(num) && Number.isFinite(num)) {
|
|
12052
|
+
cellVal = sAttr >= 0 && dateStyles[sAttr] ? excelSerialToIsoString(num) : num;
|
|
12053
|
+
} else {
|
|
12054
|
+
cellVal = vText;
|
|
12055
|
+
}
|
|
12056
|
+
}
|
|
12057
|
+
if (cellVal !== "" && cellVal !== null && cellVal !== void 0) {
|
|
12058
|
+
hasNonEmpty = true;
|
|
12059
|
+
}
|
|
12060
|
+
rowArr[colIdx] = cellVal;
|
|
12061
|
+
}
|
|
12062
|
+
if (hasNonEmpty) {
|
|
12063
|
+
if (rowArr.length > maxColCount) maxColCount = rowArr.length;
|
|
12064
|
+
rawAoA.push(rowArr);
|
|
12065
|
+
}
|
|
12066
|
+
}
|
|
12067
|
+
if (rawAoA.length === 0 || maxColCount === 0) return [];
|
|
12068
|
+
const countPopulated = (arr) => arr.reduce(
|
|
12069
|
+
(acc, v) => v !== void 0 && v !== null && String(v).trim() !== "" ? acc + 1 : acc,
|
|
12070
|
+
0
|
|
12071
|
+
);
|
|
12072
|
+
let headerRowIdx = 0;
|
|
12073
|
+
if (countPopulated(rawAoA[0]) <= 1 && maxColCount >= 2) {
|
|
12074
|
+
const scanLimit = Math.min(rawAoA.length, 5);
|
|
12075
|
+
for (let idx = 1; idx < scanLimit; idx++) {
|
|
12076
|
+
if (countPopulated(rawAoA[idx]) >= 2) {
|
|
12077
|
+
headerRowIdx = idx;
|
|
12078
|
+
break;
|
|
12079
|
+
}
|
|
12080
|
+
}
|
|
12081
|
+
}
|
|
12082
|
+
const headerRow = rawAoA[headerRowIdx];
|
|
12083
|
+
const colTotal = Math.max(maxColCount, headerRow.length);
|
|
12084
|
+
const usedHeaders = /* @__PURE__ */ new Set();
|
|
12085
|
+
const headers = [];
|
|
12086
|
+
for (let c = 0; c < colTotal; c++) {
|
|
12087
|
+
headers.push(sanitizeHeaderKey(headerRow[c], c, usedHeaders));
|
|
12088
|
+
}
|
|
12089
|
+
const records = [];
|
|
12090
|
+
for (let r = headerRowIdx + 1; r < rawAoA.length; r++) {
|
|
12091
|
+
const rowVals = rawAoA[r];
|
|
12092
|
+
const rec = {};
|
|
12093
|
+
for (let c = 0; c < headers.length; c++) {
|
|
12094
|
+
const val = rowVals[c] !== void 0 && rowVals[c] !== null ? rowVals[c] : "";
|
|
12095
|
+
Object.defineProperty(rec, headers[c], {
|
|
12096
|
+
value: val,
|
|
12097
|
+
enumerable: true,
|
|
12098
|
+
writable: true,
|
|
12099
|
+
configurable: true
|
|
12100
|
+
});
|
|
12101
|
+
}
|
|
12102
|
+
records.push(rec);
|
|
12103
|
+
}
|
|
12104
|
+
return records;
|
|
12105
|
+
}
|
|
12106
|
+
async function readXlsxWorkbookFromBuffer(buf) {
|
|
12107
|
+
const entries = parseCentralDirectory(buf);
|
|
12108
|
+
const budget = { totalBytes: 0 };
|
|
12109
|
+
const wbEntry = entries.get("xl/workbook.xml");
|
|
12110
|
+
if (!wbEntry) {
|
|
12111
|
+
throw new Error("Invalid .xlsx file: xl/workbook.xml is missing.");
|
|
12112
|
+
}
|
|
12113
|
+
const wbXml = await extractEntryUtf8(buf, wbEntry, budget);
|
|
12114
|
+
const wbDoc = parseXmlDoc(wbXml);
|
|
12115
|
+
const relMap = /* @__PURE__ */ new Map();
|
|
12116
|
+
const wbRelsEntry = entries.get("xl/_rels/workbook.xml.rels");
|
|
12117
|
+
if (wbRelsEntry) {
|
|
12118
|
+
const relsXml = await extractEntryUtf8(buf, wbRelsEntry, budget);
|
|
12119
|
+
const relsDoc = parseXmlDoc(relsXml);
|
|
12120
|
+
for (const relEl of descendantsByLocal(relsDoc, "Relationship")) {
|
|
12121
|
+
const id = relEl.getAttribute("Id") || "";
|
|
12122
|
+
const target = relEl.getAttribute("Target") || "";
|
|
12123
|
+
if (id && target) {
|
|
12124
|
+
relMap.set(id, resolveRelativeZipTarget("xl/workbook.xml", target));
|
|
12125
|
+
}
|
|
12126
|
+
}
|
|
12127
|
+
}
|
|
12128
|
+
const sharedStrings = [];
|
|
12129
|
+
const ssEntry = entries.get("xl/sharedStrings.xml");
|
|
12130
|
+
if (ssEntry) {
|
|
12131
|
+
const ssXml = await extractEntryUtf8(buf, ssEntry, budget);
|
|
12132
|
+
const ssDoc = parseXmlDoc(ssXml);
|
|
12133
|
+
for (const si of descendantsByLocal(ssDoc, "si")) {
|
|
12134
|
+
sharedStrings.push(extractRichOrPlainText(si));
|
|
12135
|
+
}
|
|
12136
|
+
}
|
|
12137
|
+
const stylesEntry = entries.get("xl/styles.xml");
|
|
12138
|
+
const stylesXml = stylesEntry ? await extractEntryUtf8(buf, stylesEntry, budget) : null;
|
|
12139
|
+
const dateStyles = parseDateStyleFlags(stylesXml);
|
|
12140
|
+
const SheetNames = [];
|
|
12141
|
+
const Sheets = {};
|
|
12142
|
+
const sheetEls = descendantsByLocal(wbDoc, "sheet");
|
|
12143
|
+
for (let idx = 0; idx < sheetEls.length; idx++) {
|
|
12144
|
+
const shEl = sheetEls[idx];
|
|
12145
|
+
const name = shEl.getAttribute("name") || `Sheet${idx + 1}`;
|
|
12146
|
+
const rId = shEl.getAttribute("r:id") || shEl.getAttributeNS(
|
|
12147
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
12148
|
+
"id"
|
|
12149
|
+
) || "";
|
|
12150
|
+
const targetPath = rId && relMap.get(rId) || `xl/worksheets/sheet${idx + 1}.xml`;
|
|
12151
|
+
const wsEntry = entries.get(targetPath);
|
|
12152
|
+
if (!wsEntry) continue;
|
|
12153
|
+
const wsXml = await extractEntryUtf8(buf, wsEntry, budget);
|
|
12154
|
+
SheetNames.push(name);
|
|
12155
|
+
Sheets[name] = parseWorksheetRows(wsXml, sharedStrings, dateStyles);
|
|
12156
|
+
}
|
|
12157
|
+
return { SheetNames, Sheets };
|
|
12158
|
+
}
|
|
11757
12159
|
function createDefaultDataTableData() {
|
|
11758
12160
|
return {
|
|
11759
12161
|
title: {
|
|
@@ -12287,12 +12689,8 @@ const DataTableStudioModal = ({
|
|
|
12287
12689
|
}
|
|
12288
12690
|
};
|
|
12289
12691
|
const importFromWorkbookSheet = (wb, sheetName, fileName) => {
|
|
12290
|
-
const
|
|
12291
|
-
if (!
|
|
12292
|
-
const jsonRows = XLSXNs__namespace.utils.sheet_to_json(ws, {
|
|
12293
|
-
defval: "",
|
|
12294
|
-
raw: true
|
|
12295
|
-
});
|
|
12692
|
+
const jsonRows = wb.Sheets[sheetName];
|
|
12693
|
+
if (!jsonRows) return;
|
|
12296
12694
|
setActiveSheetName(sheetName);
|
|
12297
12695
|
buildColumnsAndRowsFromRecords(
|
|
12298
12696
|
jsonRows,
|
|
@@ -12365,10 +12763,10 @@ const DataTableStudioModal = ({
|
|
|
12365
12763
|
return;
|
|
12366
12764
|
}
|
|
12367
12765
|
const reader = new FileReader();
|
|
12368
|
-
reader.onload = () => {
|
|
12766
|
+
reader.onload = async () => {
|
|
12369
12767
|
try {
|
|
12370
12768
|
const buf = reader.result;
|
|
12371
|
-
const wb =
|
|
12769
|
+
const wb = await readXlsxWorkbookFromBuffer(buf);
|
|
12372
12770
|
workbookRef.current = wb;
|
|
12373
12771
|
const names = Array.isArray(wb.SheetNames) ? wb.SheetNames : [];
|
|
12374
12772
|
setSheetNames(names);
|