@base2datadesign/viewer-kit 0.2.22 → 0.2.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grasshopper.d.ts","sourceRoot":"","sources":["../../src/uploads/grasshopper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"grasshopper.d.ts","sourceRoot":"","sources":["../../src/uploads/grasshopper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA0D1F,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAuBF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,EAAE,QAA0B,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAE,uBAA4B,GACtF,OAAO,CAAC,sBAAsB,CAAC,CAgCjC;AAED,eAAO,MAAM,uBAAuB,GAAI,YAAY,MAAM,KAAG,MAM5D,CAAC;AAsBF,eAAO,MAAM,sBAAsB,GACjC,QAAQ,gBAAgB,EAAE,EAC1B,aAAa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,KAC/D,gBAAgB,EAmBlB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,QAAQ,gBAAgB,EAAE,EAC1B,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,KAC/D,MAAM,CAAC,MAAM,EAAE,OAAO,CAexB,CAAC"}
|
|
@@ -1,3 +1,56 @@
|
|
|
1
|
+
const isGhxFile = (file) => /\.ghx$/i.test(file.name);
|
|
2
|
+
const normalizeGhxInputs = async (file, onStatus) => {
|
|
3
|
+
if (typeof DOMParser === "undefined" || typeof XMLSerializer === "undefined")
|
|
4
|
+
return file;
|
|
5
|
+
if (!isGhxFile(file))
|
|
6
|
+
return file;
|
|
7
|
+
try {
|
|
8
|
+
onStatus?.("normalizing ghx inputs");
|
|
9
|
+
const text = await file.text();
|
|
10
|
+
const parser = new DOMParser();
|
|
11
|
+
const doc = parser.parseFromString(text, "text/xml");
|
|
12
|
+
if (doc.getElementsByTagName("parsererror").length > 0)
|
|
13
|
+
return file;
|
|
14
|
+
const chunks = Array.from(doc.getElementsByTagName("chunk")).filter((chunk) => chunk.getAttribute("name") === "param_input");
|
|
15
|
+
const entries = [];
|
|
16
|
+
for (const chunk of chunks) {
|
|
17
|
+
let nameItem = null;
|
|
18
|
+
let guidItem = null;
|
|
19
|
+
const items = Array.from(chunk.getElementsByTagName("item"));
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
const key = item.getAttribute("name");
|
|
22
|
+
if (key === "Name")
|
|
23
|
+
nameItem = item;
|
|
24
|
+
if (key === "InstanceGuid")
|
|
25
|
+
guidItem = item;
|
|
26
|
+
}
|
|
27
|
+
const name = nameItem?.textContent?.trim();
|
|
28
|
+
const guid = guidItem?.textContent?.trim();
|
|
29
|
+
if (name && guid && nameItem) {
|
|
30
|
+
entries.push({ name, guid, item: nameItem });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const seen = new Map();
|
|
34
|
+
let mutated = false;
|
|
35
|
+
entries.forEach((entry) => {
|
|
36
|
+
const count = (seen.get(entry.name) ?? 0) + 1;
|
|
37
|
+
seen.set(entry.name, count);
|
|
38
|
+
if (count > 1) {
|
|
39
|
+
const suffix = entry.guid.slice(-6);
|
|
40
|
+
entry.item.textContent = `${entry.name}__${suffix}`;
|
|
41
|
+
mutated = true;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (!mutated)
|
|
45
|
+
return file;
|
|
46
|
+
const serializer = new XMLSerializer();
|
|
47
|
+
const normalized = serializer.serializeToString(doc);
|
|
48
|
+
return new File([normalized], file.name, { type: file.type || "application/xml" });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return file;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
1
54
|
const normalizeInputs = (inputs) => {
|
|
2
55
|
if (!Array.isArray(inputs))
|
|
3
56
|
return [];
|
|
@@ -22,8 +75,9 @@ const extractSolvePayload = (payload) => {
|
|
|
22
75
|
};
|
|
23
76
|
export async function solveGrasshopperFile(file, { apiRoute = "/api/gh-solve", values, preview, onStatus } = {}) {
|
|
24
77
|
onStatus?.("preparing payload");
|
|
78
|
+
const uploadFile = await normalizeGhxInputs(file, onStatus);
|
|
25
79
|
const formData = new FormData();
|
|
26
|
-
formData.append("algo",
|
|
80
|
+
formData.append("algo", uploadFile);
|
|
27
81
|
formData.append("values", JSON.stringify(values ?? []));
|
|
28
82
|
if (preview) {
|
|
29
83
|
formData.append("preview", JSON.stringify(preview));
|
|
@@ -79,11 +133,18 @@ const formatGrasshopperValue = (name, type, value) => {
|
|
|
79
133
|
};
|
|
80
134
|
};
|
|
81
135
|
export const buildGrasshopperValues = (inputs, valuesByKey, keyResolver) => {
|
|
136
|
+
const nameCounts = new Map();
|
|
137
|
+
inputs.forEach((input) => {
|
|
138
|
+
if (!input.name)
|
|
139
|
+
return;
|
|
140
|
+
nameCounts.set(input.name, (nameCounts.get(input.name) ?? 0) + 1);
|
|
141
|
+
});
|
|
82
142
|
return inputs
|
|
83
143
|
.map((input, index) => {
|
|
84
144
|
const key = keyResolver ? keyResolver(input, index) : input.guid ?? input.name ?? `${index}`;
|
|
85
145
|
const value = Object.prototype.hasOwnProperty.call(valuesByKey, key) ? valuesByKey[key] : input.value;
|
|
86
|
-
const
|
|
146
|
+
const duplicateName = input.name ? (nameCounts.get(input.name) ?? 0) > 1 : false;
|
|
147
|
+
const paramName = duplicateName && input.nickname ? input.nickname : input.name || input.nickname || key;
|
|
87
148
|
if (!paramName)
|
|
88
149
|
return null;
|
|
89
150
|
const type = mapGrasshopperInputType(input.type);
|