@deviceinsight/ng-ui-scale-lib 9.14.0

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,860 @@
1
+ import { at as c, a5 as Et, cY as wt, a_ as kt, ag as et, aV as bt, bn as It } from "./ContextBarContext-f745a63a.js";
2
+ import * as Dt from "react";
3
+ import { createContext as Ot, useState as pt, useEffect as Rt, useContext as At } from "react";
4
+ import { Spinner as Tt, Button as yt, Icon as Lt, Bubble as jt } from "@deviceinsight/ng-ui-basic-components";
5
+ import { ReactableWithClientSidePagination as Nt, FileUpload as Ut } from "@deviceinsight/ng-ui-components";
6
+ import { fetchUnits as Pt, readAccountObject as Ft, writeAccountObject as zt } from "@deviceinsight/ng-ui-api-client";
7
+ import "react-router-dom";
8
+ import "react-dom";
9
+ function Mt(h) {
10
+ const l = h.uploadState || "UPLOAD_PENDING";
11
+ return /* @__PURE__ */ c.jsx("span", { className: `di upload-status ${l.toLowerCase()}`, children: l === "UPLOAD_PENDING" && /* @__PURE__ */ c.jsx(Tt, { size: 16 }) });
12
+ }
13
+ const qt = {
14
+ page: 0,
15
+ size: 10,
16
+ sort: {
17
+ property: "index",
18
+ direction: "ASC"
19
+ }
20
+ }, Kt = (h, l, g) => {
21
+ const d = l.direction === "ASC" ? 1 : -1;
22
+ return l.property === "index" ? h.sort((x, I) => d * (x.idx - I.idx)) : g(h, l);
23
+ }, Bt = [
24
+ {
25
+ name: "index",
26
+ label: "",
27
+ render: (h) => h.idx
28
+ },
29
+ {
30
+ name: "name",
31
+ label: "",
32
+ render: (h) => /* @__PURE__ */ c.jsx("div", { className: "import-datapoint-name-cell-wrapper", children: /* @__PURE__ */ c.jsx("div", { className: "name-wrapper", title: h.data ? h.data.name : "", children: h.data ? h.data.name : "" }) })
33
+ },
34
+ {
35
+ name: "datatype",
36
+ label: "",
37
+ render: (h) => h.data ? h.data.datatype : ""
38
+ },
39
+ {
40
+ name: "unit",
41
+ label: "",
42
+ render: (h) => h.data && h.data.unit ? h.data.unit.print : ""
43
+ },
44
+ {
45
+ name: "threshold1",
46
+ label: "",
47
+ render: (h) => {
48
+ var l, g;
49
+ return h.data && ((l = h.data.thresholds) != null && l.threshold1) ? (g = h.data.thresholds) == null ? void 0 : g.threshold1.toString() : "";
50
+ }
51
+ },
52
+ {
53
+ name: "threshold2",
54
+ label: "",
55
+ render: (h) => {
56
+ var l, g;
57
+ return h.data && ((l = h.data.thresholds) != null && l.threshold2) ? (g = h.data.thresholds) == null ? void 0 : g.threshold2.toString() : "";
58
+ }
59
+ },
60
+ {
61
+ name: "error",
62
+ label: "",
63
+ render: (h) => h.error || ""
64
+ }
65
+ ];
66
+ class Wt extends Dt.PureComponent {
67
+ constructor(l) {
68
+ super(l), this._isMounted = !1, this.state = {
69
+ rowUploadStates: {},
70
+ paginationSettings: { ...qt, size: l.pageSize }
71
+ };
72
+ }
73
+ componentDidMount() {
74
+ this._isMounted = !0;
75
+ }
76
+ componentDidUpdate(l) {
77
+ const { data: g } = this.props;
78
+ !l.data.length && g.length && this.setState(
79
+ {
80
+ rowUploadStates: {}
81
+ },
82
+ () => this.createDatapoint(0)
83
+ ), l.pageSize !== this.props.pageSize && this.setState((d) => ({
84
+ ...d,
85
+ paginationSettings: { ...d.paginationSettings, size: this.props.pageSize }
86
+ }));
87
+ }
88
+ componentWillUnmount() {
89
+ this._isMounted = !1;
90
+ }
91
+ createDatapoint(l) {
92
+ const { data: g, onRowComplete: d } = this.props, { rowUploadStates: x } = this.state;
93
+ if (d(x), l >= g.length)
94
+ return;
95
+ if (!g[l])
96
+ return this.createDatapoint(l + 1);
97
+ const {
98
+ data: { name: I, datatype: P, unit: q, thresholds: a },
99
+ error: Y
100
+ } = g[l];
101
+ if (Y)
102
+ return setTimeout(() => this.updateUploadStateAndContinue(l, "CANNOT_UPLOAD"), 0);
103
+ const N = {
104
+ name: I,
105
+ datatype: P,
106
+ thresholds: a,
107
+ datapointType: "RAW"
108
+ };
109
+ q != null && q.name && (N.unit = q || void 0), (a != null && a.threshold1 || a != null && a.threshold2) && (N.thresholds = a), this.props.createDatapoint(N).then(() => this.updateUploadStateAndContinue(l, "UPLOAD_SUCCESSFUL")).catch(() => this.updateUploadStateAndContinue(l, "UPLOAD_FAILED"));
110
+ }
111
+ updateUploadStateAndContinue(l, g) {
112
+ const { rowUploadStates: d } = this.state;
113
+ this._isMounted && this.setState(
114
+ {
115
+ rowUploadStates: { ...d, [l]: g }
116
+ },
117
+ () => this.createDatapoint(l + 1)
118
+ );
119
+ }
120
+ getColumnDefs() {
121
+ const { rowUploadStates: l } = this.state;
122
+ return [
123
+ ...Bt,
124
+ {
125
+ name: "result",
126
+ label: "",
127
+ render: (g) => /* @__PURE__ */ c.jsx(Mt, { uploadState: l[g.idx] })
128
+ }
129
+ ];
130
+ }
131
+ render() {
132
+ const { data: l, isLoading: g } = this.props;
133
+ return /* @__PURE__ */ c.jsx(
134
+ Nt,
135
+ {
136
+ columnDefs: this.getColumnDefs(),
137
+ uniqueItemKey: (d) => `${d.idx}`,
138
+ customSortFunction: Kt,
139
+ paginationSettings: this.state.paginationSettings,
140
+ items: l,
141
+ isLoading: g,
142
+ onChangeSize: this.props.onPageSizeChange
143
+ }
144
+ );
145
+ }
146
+ }
147
+ var Ct = { exports: {} };
148
+ /* @license
149
+ Papa Parse
150
+ v5.3.0
151
+ https://github.com/mholt/PapaParse
152
+ License: MIT
153
+ */
154
+ (function(h, l) {
155
+ (function(g, d) {
156
+ h.exports = d();
157
+ })(Et, function g() {
158
+ var d = typeof self < "u" ? self : typeof window < "u" ? window : d !== void 0 ? d : {}, x = !d.document && !!d.postMessage, I = x && /blob:/i.test((d.location || {}).protocol), P = {}, q = 0, a = { parse: function(e, t) {
159
+ var n = (t = t || {}).dynamicTyping || !1;
160
+ if (w(n) && (t.dynamicTypingFunction = n, n = {}), t.dynamicTyping = n, t.transform = !!w(t.transform) && t.transform, t.worker && a.WORKERS_SUPPORTED) {
161
+ var i = function() {
162
+ if (!a.WORKERS_SUPPORTED)
163
+ return !1;
164
+ var f = (F = d.URL || d.webkitURL || null, D = g.toString(), a.BLOB_URL || (a.BLOB_URL = F.createObjectURL(new Blob(["(", D, ")();"], { type: "text/javascript" })))), S = new d.Worker(f), F, D;
165
+ return S.onmessage = ft, S.id = q++, P[S.id] = S;
166
+ }();
167
+ return i.userStep = t.step, i.userChunk = t.chunk, i.userComplete = t.complete, i.userError = t.error, t.step = w(t.step), t.chunk = w(t.chunk), t.complete = w(t.complete), t.error = w(t.error), delete t.worker, void i.postMessage({ input: e, config: t, workerId: i.id });
168
+ }
169
+ var s = null;
170
+ return a.NODE_STREAM_INPUT, typeof e == "string" ? s = t.download ? new J(t) : new V(t) : e.readable === !0 && w(e.read) && w(e.on) ? s = new ht(t) : (d.File && e instanceof File || e instanceof Object) && (s = new Z(t)), s.stream(e);
171
+ }, unparse: function(e, t) {
172
+ var n = !1, i = !0, s = ",", f = `\r
173
+ `, S = '"', F = S + S, D = !1, r = null, j = !1;
174
+ (function() {
175
+ if (typeof t == "object") {
176
+ if (typeof t.delimiter != "string" || a.BAD_DELIMITERS.filter(function(C) {
177
+ return t.delimiter.indexOf(C) !== -1;
178
+ }).length || (s = t.delimiter), (typeof t.quotes == "boolean" || typeof t.quotes == "function" || Array.isArray(t.quotes)) && (n = t.quotes), typeof t.skipEmptyLines != "boolean" && typeof t.skipEmptyLines != "string" || (D = t.skipEmptyLines), typeof t.newline == "string" && (f = t.newline), typeof t.quoteChar == "string" && (S = t.quoteChar), typeof t.header == "boolean" && (i = t.header), Array.isArray(t.columns)) {
179
+ if (t.columns.length === 0)
180
+ throw new Error("Option columns is empty");
181
+ r = t.columns;
182
+ }
183
+ t.escapeChar !== void 0 && (F = t.escapeChar + S), typeof t.escapeFormulae == "boolean" && (j = t.escapeFormulae);
184
+ }
185
+ })();
186
+ var o = new RegExp(K(S), "g");
187
+ if (typeof e == "string" && (e = JSON.parse(e)), Array.isArray(e)) {
188
+ if (!e.length || Array.isArray(e[0]))
189
+ return z(null, e, D);
190
+ if (typeof e[0] == "object")
191
+ return z(r || nt(e[0]), e, D);
192
+ } else if (typeof e == "object")
193
+ return typeof e.data == "string" && (e.data = JSON.parse(e.data)), Array.isArray(e.data) && (e.fields || (e.fields = e.meta && e.meta.fields), e.fields || (e.fields = Array.isArray(e.data[0]) ? e.fields : nt(e.data[0])), Array.isArray(e.data[0]) || typeof e.data[0] == "object" || (e.data = [e.data])), z(e.fields || [], e.data || [], D);
194
+ throw new Error("Unable to serialize unrecognized input");
195
+ function nt(C) {
196
+ if (typeof C != "object")
197
+ return [];
198
+ var E = [];
199
+ for (var T in C)
200
+ E.push(T);
201
+ return E;
202
+ }
203
+ function z(C, E, T) {
204
+ var U = "";
205
+ typeof C == "string" && (C = JSON.parse(C)), typeof E == "string" && (E = JSON.parse(E));
206
+ var L = Array.isArray(C) && 0 < C.length, B = !Array.isArray(E[0]);
207
+ if (L && i) {
208
+ for (var u = 0; u < C.length; u++)
209
+ 0 < u && (U += s), U += m(C[u], u);
210
+ 0 < E.length && (U += f);
211
+ }
212
+ for (var _ = 0; _ < E.length; _++) {
213
+ var k = L ? C.length : E[_].length, b = !1, y = L ? Object.keys(E[_]).length === 0 : E[_].length === 0;
214
+ if (T && !L && (b = T === "greedy" ? E[_].join("").trim() === "" : E[_].length === 1 && E[_][0].length === 0), T === "greedy" && L) {
215
+ for (var v = [], O = 0; O < k; O++) {
216
+ var p = B ? C[O] : O;
217
+ v.push(E[_][p]);
218
+ }
219
+ b = v.join("").trim() === "";
220
+ }
221
+ if (!b) {
222
+ for (var R = 0; R < k; R++) {
223
+ 0 < R && !y && (U += s);
224
+ var $ = L && B ? C[R] : R;
225
+ U += m(E[_][$], R);
226
+ }
227
+ _ < E.length - 1 && (!T || 0 < k && !y) && (U += f);
228
+ }
229
+ }
230
+ return U;
231
+ }
232
+ function m(C, E) {
233
+ if (C == null)
234
+ return "";
235
+ if (C.constructor === Date)
236
+ return JSON.stringify(C).slice(1, 25);
237
+ j === !0 && typeof C == "string" && C.match(/^[=+\-@].*$/) !== null && (C = "'" + C);
238
+ var T = C.toString().replace(o, F), U = typeof n == "boolean" && n || typeof n == "function" && n(C, E) || Array.isArray(n) && n[E] || function(L, B) {
239
+ for (var u = 0; u < B.length; u++)
240
+ if (-1 < L.indexOf(B[u]))
241
+ return !0;
242
+ return !1;
243
+ }(T, a.BAD_DELIMITERS) || -1 < T.indexOf(s) || T.charAt(0) === " " || T.charAt(T.length - 1) === " ";
244
+ return U ? S + T + S : T;
245
+ }
246
+ } };
247
+ if (a.RECORD_SEP = String.fromCharCode(30), a.UNIT_SEP = String.fromCharCode(31), a.BYTE_ORDER_MARK = "\uFEFF", a.BAD_DELIMITERS = ["\r", `
248
+ `, '"', a.BYTE_ORDER_MARK], a.WORKERS_SUPPORTED = !x && !!d.Worker, a.NODE_STREAM_INPUT = 1, a.LocalChunkSize = 10485760, a.RemoteChunkSize = 5242880, a.DefaultDelimiter = ",", a.Parser = W, a.ParserHandle = ut, a.NetworkStreamer = J, a.FileStreamer = Z, a.StringStreamer = V, a.ReadableStreamStreamer = ht, d.jQuery) {
249
+ var Y = d.jQuery;
250
+ Y.fn.parse = function(e) {
251
+ var t = e.config || {}, n = [];
252
+ return this.each(function(f) {
253
+ if (!(Y(this).prop("tagName").toUpperCase() === "INPUT" && Y(this).attr("type").toLowerCase() === "file" && d.FileReader) || !this.files || this.files.length === 0)
254
+ return !0;
255
+ for (var S = 0; S < this.files.length; S++)
256
+ n.push({ file: this.files[S], inputElem: this, instanceConfig: Y.extend({}, t) });
257
+ }), i(), this;
258
+ function i() {
259
+ if (n.length !== 0) {
260
+ var f, S, F, D, r = n[0];
261
+ if (w(e.before)) {
262
+ var j = e.before(r.file, r.inputElem);
263
+ if (typeof j == "object") {
264
+ if (j.action === "abort")
265
+ return f = "AbortError", S = r.file, F = r.inputElem, D = j.reason, void (w(e.error) && e.error({ name: f }, S, F, D));
266
+ if (j.action === "skip")
267
+ return void s();
268
+ typeof j.config == "object" && (r.instanceConfig = Y.extend(r.instanceConfig, j.config));
269
+ } else if (j === "skip")
270
+ return void s();
271
+ }
272
+ var o = r.instanceConfig.complete;
273
+ r.instanceConfig.complete = function(nt) {
274
+ w(o) && o(nt, r.file, r.inputElem), s();
275
+ }, a.parse(r.file, r.instanceConfig);
276
+ } else
277
+ w(e.complete) && e.complete();
278
+ }
279
+ function s() {
280
+ n.splice(0, 1), i();
281
+ }
282
+ };
283
+ }
284
+ function N(e) {
285
+ this._handle = null, this._finished = !1, this._completed = !1, this._halted = !1, this._input = null, this._baseIndex = 0, this._partialLine = "", this._rowCount = 0, this._start = 0, this._nextChunk = null, this.isFirstChunk = !0, this._completeResults = { data: [], errors: [], meta: {} }, (function(t) {
286
+ var n = mt(t);
287
+ n.chunkSize = parseInt(n.chunkSize), t.step || t.chunk || (n.chunkSize = null), this._handle = new ut(n), (this._handle.streamer = this)._config = n;
288
+ }).call(this, e), this.parseChunk = function(t, n) {
289
+ if (this.isFirstChunk && w(this._config.beforeFirstChunk)) {
290
+ var i = this._config.beforeFirstChunk(t);
291
+ i !== void 0 && (t = i);
292
+ }
293
+ this.isFirstChunk = !1, this._halted = !1;
294
+ var s = this._partialLine + t;
295
+ this._partialLine = "";
296
+ var f = this._handle.parse(s, this._baseIndex, !this._finished);
297
+ if (!this._handle.paused() && !this._handle.aborted()) {
298
+ var S = f.meta.cursor;
299
+ this._finished || (this._partialLine = s.substring(S - this._baseIndex), this._baseIndex = S), f && f.data && (this._rowCount += f.data.length);
300
+ var F = this._finished || this._config.preview && this._rowCount >= this._config.preview;
301
+ if (I)
302
+ d.postMessage({ results: f, workerId: a.WORKER_ID, finished: F });
303
+ else if (w(this._config.chunk) && !n) {
304
+ if (this._config.chunk(f, this._handle), this._handle.paused() || this._handle.aborted())
305
+ return void (this._halted = !0);
306
+ f = void 0, this._completeResults = void 0;
307
+ }
308
+ return this._config.step || this._config.chunk || (this._completeResults.data = this._completeResults.data.concat(f.data), this._completeResults.errors = this._completeResults.errors.concat(f.errors), this._completeResults.meta = f.meta), this._completed || !F || !w(this._config.complete) || f && f.meta.aborted || (this._config.complete(this._completeResults, this._input), this._completed = !0), F || f && f.meta.paused || this._nextChunk(), f;
309
+ }
310
+ this._halted = !0;
311
+ }, this._sendError = function(t) {
312
+ w(this._config.error) ? this._config.error(t) : I && this._config.error && d.postMessage({ workerId: a.WORKER_ID, error: t, finished: !1 });
313
+ };
314
+ }
315
+ function J(e) {
316
+ var t;
317
+ (e = e || {}).chunkSize || (e.chunkSize = a.RemoteChunkSize), N.call(this, e), this._nextChunk = x ? function() {
318
+ this._readChunk(), this._chunkLoaded();
319
+ } : function() {
320
+ this._readChunk();
321
+ }, this.stream = function(n) {
322
+ this._input = n, this._nextChunk();
323
+ }, this._readChunk = function() {
324
+ if (this._finished)
325
+ this._chunkLoaded();
326
+ else {
327
+ if (t = new XMLHttpRequest(), this._config.withCredentials && (t.withCredentials = this._config.withCredentials), x || (t.onload = at(this._chunkLoaded, this), t.onerror = at(this._chunkError, this)), t.open(this._config.downloadRequestBody ? "POST" : "GET", this._input, !x), this._config.downloadRequestHeaders) {
328
+ var n = this._config.downloadRequestHeaders;
329
+ for (var i in n)
330
+ t.setRequestHeader(i, n[i]);
331
+ }
332
+ if (this._config.chunkSize) {
333
+ var s = this._start + this._config.chunkSize - 1;
334
+ t.setRequestHeader("Range", "bytes=" + this._start + "-" + s);
335
+ }
336
+ try {
337
+ t.send(this._config.downloadRequestBody);
338
+ } catch (f) {
339
+ this._chunkError(f.message);
340
+ }
341
+ x && t.status === 0 && this._chunkError();
342
+ }
343
+ }, this._chunkLoaded = function() {
344
+ t.readyState === 4 && (t.status < 200 || 400 <= t.status ? this._chunkError() : (this._start += this._config.chunkSize ? this._config.chunkSize : t.responseText.length, this._finished = !this._config.chunkSize || this._start >= function(n) {
345
+ var i = n.getResponseHeader("Content-Range");
346
+ return i === null ? -1 : parseInt(i.substring(i.lastIndexOf("/") + 1));
347
+ }(t), this.parseChunk(t.responseText)));
348
+ }, this._chunkError = function(n) {
349
+ var i = t.statusText || n;
350
+ this._sendError(new Error(i));
351
+ };
352
+ }
353
+ function Z(e) {
354
+ var t, n;
355
+ (e = e || {}).chunkSize || (e.chunkSize = a.LocalChunkSize), N.call(this, e);
356
+ var i = typeof FileReader < "u";
357
+ this.stream = function(s) {
358
+ this._input = s, n = s.slice || s.webkitSlice || s.mozSlice, i ? ((t = new FileReader()).onload = at(this._chunkLoaded, this), t.onerror = at(this._chunkError, this)) : t = new FileReaderSync(), this._nextChunk();
359
+ }, this._nextChunk = function() {
360
+ this._finished || this._config.preview && !(this._rowCount < this._config.preview) || this._readChunk();
361
+ }, this._readChunk = function() {
362
+ var s = this._input;
363
+ if (this._config.chunkSize) {
364
+ var f = Math.min(this._start + this._config.chunkSize, this._input.size);
365
+ s = n.call(s, this._start, f);
366
+ }
367
+ var S = t.readAsText(s, this._config.encoding);
368
+ i || this._chunkLoaded({ target: { result: S } });
369
+ }, this._chunkLoaded = function(s) {
370
+ this._start += this._config.chunkSize, this._finished = !this._config.chunkSize || this._start >= this._input.size, this.parseChunk(s.target.result);
371
+ }, this._chunkError = function() {
372
+ this._sendError(t.error);
373
+ };
374
+ }
375
+ function V(e) {
376
+ var t;
377
+ N.call(this, e = e || {}), this.stream = function(n) {
378
+ return t = n, this._nextChunk();
379
+ }, this._nextChunk = function() {
380
+ if (!this._finished) {
381
+ var n, i = this._config.chunkSize;
382
+ return i ? (n = t.substring(0, i), t = t.substring(i)) : (n = t, t = ""), this._finished = !t, this.parseChunk(n);
383
+ }
384
+ };
385
+ }
386
+ function ht(e) {
387
+ N.call(this, e = e || {});
388
+ var t = [], n = !0, i = !1;
389
+ this.pause = function() {
390
+ N.prototype.pause.apply(this, arguments), this._input.pause();
391
+ }, this.resume = function() {
392
+ N.prototype.resume.apply(this, arguments), this._input.resume();
393
+ }, this.stream = function(s) {
394
+ this._input = s, this._input.on("data", this._streamData), this._input.on("end", this._streamEnd), this._input.on("error", this._streamError);
395
+ }, this._checkIsFinished = function() {
396
+ i && t.length === 1 && (this._finished = !0);
397
+ }, this._nextChunk = function() {
398
+ this._checkIsFinished(), t.length ? this.parseChunk(t.shift()) : n = !0;
399
+ }, this._streamData = at(function(s) {
400
+ try {
401
+ t.push(typeof s == "string" ? s : s.toString(this._config.encoding)), n && (n = !1, this._checkIsFinished(), this.parseChunk(t.shift()));
402
+ } catch (f) {
403
+ this._streamError(f);
404
+ }
405
+ }, this), this._streamError = at(function(s) {
406
+ this._streamCleanUp(), this._sendError(s);
407
+ }, this), this._streamEnd = at(function() {
408
+ this._streamCleanUp(), i = !0, this._streamData("");
409
+ }, this), this._streamCleanUp = at(function() {
410
+ this._input.removeListener("data", this._streamData), this._input.removeListener("end", this._streamEnd), this._input.removeListener("error", this._streamError);
411
+ }, this);
412
+ }
413
+ function ut(e) {
414
+ var t, n, i, s = Math.pow(2, 53), f = -s, S = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)(e[-+]?\d+)?\s*$/, F = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/, D = this, r = 0, j = 0, o = !1, nt = !1, z = [], m = { data: [], errors: [], meta: {} };
415
+ if (w(e.step)) {
416
+ var C = e.step;
417
+ e.step = function(u) {
418
+ if (m = u, U())
419
+ T();
420
+ else {
421
+ if (T(), m.data.length === 0)
422
+ return;
423
+ r += u.data.length, e.preview && r > e.preview ? n.abort() : (m.data = m.data[0], C(m, D));
424
+ }
425
+ };
426
+ }
427
+ function E(u) {
428
+ return e.skipEmptyLines === "greedy" ? u.join("").trim() === "" : u.length === 1 && u[0].length === 0;
429
+ }
430
+ function T() {
431
+ if (m && i && (B("Delimiter", "UndetectableDelimiter", "Unable to auto-detect delimiting character; defaulted to '" + a.DefaultDelimiter + "'"), i = !1), e.skipEmptyLines)
432
+ for (var u = 0; u < m.data.length; u++)
433
+ E(m.data[u]) && m.data.splice(u--, 1);
434
+ return U() && function() {
435
+ if (!m)
436
+ return;
437
+ function _(b, y) {
438
+ w(e.transformHeader) && (b = e.transformHeader(b, y)), z.push(b);
439
+ }
440
+ if (Array.isArray(m.data[0])) {
441
+ for (var k = 0; U() && k < m.data.length; k++)
442
+ m.data[k].forEach(_);
443
+ m.data.splice(0, 1);
444
+ } else
445
+ m.data.forEach(_);
446
+ }(), function() {
447
+ if (!m || !e.header && !e.dynamicTyping && !e.transform)
448
+ return m;
449
+ function _(b, y) {
450
+ var v, O = e.header ? {} : [];
451
+ for (v = 0; v < b.length; v++) {
452
+ var p = v, R = b[v];
453
+ e.header && (p = v >= z.length ? "__parsed_extra" : z[v]), e.transform && (R = e.transform(R, p)), R = L(p, R), p === "__parsed_extra" ? (O[p] = O[p] || [], O[p].push(R)) : O[p] = R;
454
+ }
455
+ return e.header && (v > z.length ? B("FieldMismatch", "TooManyFields", "Too many fields: expected " + z.length + " fields but parsed " + v, j + y) : v < z.length && B("FieldMismatch", "TooFewFields", "Too few fields: expected " + z.length + " fields but parsed " + v, j + y)), O;
456
+ }
457
+ var k = 1;
458
+ return !m.data.length || Array.isArray(m.data[0]) ? (m.data = m.data.map(_), k = m.data.length) : m.data = _(m.data, 0), e.header && m.meta && (m.meta.fields = z), j += k, m;
459
+ }();
460
+ }
461
+ function U() {
462
+ return e.header && z.length === 0;
463
+ }
464
+ function L(u, _) {
465
+ return k = u, e.dynamicTypingFunction && e.dynamicTyping[k] === void 0 && (e.dynamicTyping[k] = e.dynamicTypingFunction(k)), (e.dynamicTyping[k] || e.dynamicTyping) === !0 ? _ === "true" || _ === "TRUE" || _ !== "false" && _ !== "FALSE" && (function(b) {
466
+ if (S.test(b)) {
467
+ var y = parseFloat(b);
468
+ if (f < y && y < s)
469
+ return !0;
470
+ }
471
+ return !1;
472
+ }(_) ? parseFloat(_) : F.test(_) ? new Date(_) : _ === "" ? null : _) : _;
473
+ var k;
474
+ }
475
+ function B(u, _, k, b) {
476
+ var y = { type: u, code: _, message: k };
477
+ b !== void 0 && (y.row = b), m.errors.push(y);
478
+ }
479
+ this.parse = function(u, _, k) {
480
+ var b = e.quoteChar || '"';
481
+ if (e.newline || (e.newline = function(O, p) {
482
+ O = O.substring(0, 1048576);
483
+ var R = new RegExp(K(p) + "([^]*?)" + K(p), "gm"), $ = (O = O.replace(R, "")).split("\r"), X = O.split(`
484
+ `), tt = 1 < X.length && X[0].length < $[0].length;
485
+ if ($.length === 1 || tt)
486
+ return `
487
+ `;
488
+ for (var it = 0, H = 0; H < $.length; H++)
489
+ $[H][0] === `
490
+ ` && it++;
491
+ return it >= $.length / 2 ? `\r
492
+ ` : "\r";
493
+ }(u, b)), i = !1, e.delimiter)
494
+ w(e.delimiter) && (e.delimiter = e.delimiter(u), m.meta.delimiter = e.delimiter);
495
+ else {
496
+ var y = function(O, p, R, $, X) {
497
+ var tt, it, H, lt;
498
+ X = X || [",", " ", "|", ";", a.RECORD_SEP, a.UNIT_SEP];
499
+ for (var M = 0; M < X.length; M++) {
500
+ var ot = X[M], dt = 0, A = 0, rt = 0;
501
+ H = void 0;
502
+ for (var G = new W({ comments: $, delimiter: ot, newline: p, preview: 10 }).parse(O), st = 0; st < G.data.length; st++)
503
+ if (R && E(G.data[st]))
504
+ rt++;
505
+ else {
506
+ var Q = G.data[st].length;
507
+ A += Q, H !== void 0 ? 0 < Q && (dt += Math.abs(Q - H), H = Q) : H = Q;
508
+ }
509
+ 0 < G.data.length && (A /= G.data.length - rt), (it === void 0 || dt <= it) && (lt === void 0 || lt < A) && 1.99 < A && (it = dt, tt = ot, lt = A);
510
+ }
511
+ return { successful: !!(e.delimiter = tt), bestDelimiter: tt };
512
+ }(u, e.newline, e.skipEmptyLines, e.comments, e.delimitersToGuess);
513
+ y.successful ? e.delimiter = y.bestDelimiter : (i = !0, e.delimiter = a.DefaultDelimiter), m.meta.delimiter = e.delimiter;
514
+ }
515
+ var v = mt(e);
516
+ return e.preview && e.header && v.preview++, t = u, n = new W(v), m = n.parse(t, _, k), T(), o ? { meta: { paused: !0 } } : m || { meta: { paused: !1 } };
517
+ }, this.paused = function() {
518
+ return o;
519
+ }, this.pause = function() {
520
+ o = !0, n.abort(), t = w(e.chunk) ? "" : t.substring(n.getCharIndex());
521
+ }, this.resume = function() {
522
+ D.streamer._halted ? (o = !1, D.streamer.parseChunk(t, !0)) : setTimeout(D.resume, 3);
523
+ }, this.aborted = function() {
524
+ return nt;
525
+ }, this.abort = function() {
526
+ nt = !0, n.abort(), m.meta.aborted = !0, w(e.complete) && e.complete(m), t = "";
527
+ };
528
+ }
529
+ function K(e) {
530
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
531
+ }
532
+ function W(e) {
533
+ var t, n = (e = e || {}).delimiter, i = e.newline, s = e.comments, f = e.step, S = e.preview, F = e.fastMode, D = t = e.quoteChar === void 0 ? '"' : e.quoteChar;
534
+ if (e.escapeChar !== void 0 && (D = e.escapeChar), (typeof n != "string" || -1 < a.BAD_DELIMITERS.indexOf(n)) && (n = ","), s === n)
535
+ throw new Error("Comment character same as delimiter");
536
+ s === !0 ? s = "#" : (typeof s != "string" || -1 < a.BAD_DELIMITERS.indexOf(s)) && (s = !1), i !== `
537
+ ` && i !== "\r" && i !== `\r
538
+ ` && (i = `
539
+ `);
540
+ var r = 0, j = !1;
541
+ this.parse = function(o, nt, z) {
542
+ if (typeof o != "string")
543
+ throw new Error("Input must be a string");
544
+ var m = o.length, C = n.length, E = i.length, T = s.length, U = w(f), L = [], B = [], u = [], _ = r = 0;
545
+ if (!o)
546
+ return M();
547
+ if (F || F !== !1 && o.indexOf(t) === -1) {
548
+ for (var k = o.split(i), b = 0; b < k.length; b++) {
549
+ if (u = k[b], r += u.length, b !== k.length - 1)
550
+ r += i.length;
551
+ else if (z)
552
+ return M();
553
+ if (!s || u.substring(0, T) !== s) {
554
+ if (U) {
555
+ if (L = [], tt(u.split(n)), ot(), j)
556
+ return M();
557
+ } else
558
+ tt(u.split(n));
559
+ if (S && S <= b)
560
+ return L = L.slice(0, S), M(!0);
561
+ }
562
+ }
563
+ return M();
564
+ }
565
+ for (var y = o.indexOf(n, r), v = o.indexOf(i, r), O = new RegExp(K(D) + K(t), "g"), p = o.indexOf(t, r); ; )
566
+ if (o[r] !== t)
567
+ if (s && u.length === 0 && o.substring(r, r + T) === s) {
568
+ if (v === -1)
569
+ return M();
570
+ r = v + E, v = o.indexOf(i, r), y = o.indexOf(n, r);
571
+ } else {
572
+ if (y !== -1 && (y < v || v === -1)) {
573
+ if (!(y < p)) {
574
+ u.push(o.substring(r, y)), r = y + C, y = o.indexOf(n, r);
575
+ continue;
576
+ }
577
+ var R = dt(y, p, v);
578
+ if (R && R.nextDelim !== void 0) {
579
+ y = R.nextDelim, p = R.quoteSearch, u.push(o.substring(r, y)), r = y + C, y = o.indexOf(n, r);
580
+ continue;
581
+ }
582
+ }
583
+ if (v === -1)
584
+ break;
585
+ if (u.push(o.substring(r, v)), lt(v + E), U && (ot(), j))
586
+ return M();
587
+ if (S && L.length >= S)
588
+ return M(!0);
589
+ }
590
+ else
591
+ for (p = r, r++; ; ) {
592
+ if ((p = o.indexOf(t, p + 1)) === -1)
593
+ return z || B.push({ type: "Quotes", code: "MissingQuotes", message: "Quoted field unterminated", row: L.length, index: r }), H();
594
+ if (p === m - 1)
595
+ return H(o.substring(r, p).replace(O, t));
596
+ if (t !== D || o[p + 1] !== D) {
597
+ if (t === D || p === 0 || o[p - 1] !== D) {
598
+ y !== -1 && y < p + 1 && (y = o.indexOf(n, p + 1)), v !== -1 && v < p + 1 && (v = o.indexOf(i, p + 1));
599
+ var $ = it(v === -1 ? y : Math.min(y, v));
600
+ if (o[p + 1 + $] === n) {
601
+ u.push(o.substring(r, p).replace(O, t)), o[r = p + 1 + $ + C] !== t && (p = o.indexOf(t, r)), y = o.indexOf(n, r), v = o.indexOf(i, r);
602
+ break;
603
+ }
604
+ var X = it(v);
605
+ if (o.substring(p + 1 + X, p + 1 + X + E) === i) {
606
+ if (u.push(o.substring(r, p).replace(O, t)), lt(p + 1 + X + E), y = o.indexOf(n, r), p = o.indexOf(t, r), U && (ot(), j))
607
+ return M();
608
+ if (S && L.length >= S)
609
+ return M(!0);
610
+ break;
611
+ }
612
+ B.push({ type: "Quotes", code: "InvalidQuotes", message: "Trailing quote on quoted field is malformed", row: L.length, index: r }), p++;
613
+ }
614
+ } else
615
+ p++;
616
+ }
617
+ return H();
618
+ function tt(A) {
619
+ L.push(A), _ = r;
620
+ }
621
+ function it(A) {
622
+ var rt = 0;
623
+ if (A !== -1) {
624
+ var G = o.substring(p + 1, A);
625
+ G && G.trim() === "" && (rt = G.length);
626
+ }
627
+ return rt;
628
+ }
629
+ function H(A) {
630
+ return z || (A === void 0 && (A = o.substring(r)), u.push(A), r = m, tt(u), U && ot()), M();
631
+ }
632
+ function lt(A) {
633
+ r = A, tt(u), u = [], v = o.indexOf(i, r);
634
+ }
635
+ function M(A) {
636
+ return { data: L, errors: B, meta: { delimiter: n, linebreak: i, aborted: j, truncated: !!A, cursor: _ + (nt || 0) } };
637
+ }
638
+ function ot() {
639
+ f(M()), L = [], B = [];
640
+ }
641
+ function dt(A, rt, G) {
642
+ var st = { nextDelim: void 0, quoteSearch: void 0 }, Q = o.indexOf(t, rt + 1);
643
+ if (rt < A && A < Q && (Q < G || G === -1)) {
644
+ var gt = o.indexOf(n, Q);
645
+ if (gt === -1)
646
+ return st;
647
+ Q < gt && (Q = o.indexOf(t, Q + 1)), st = dt(gt, Q, G);
648
+ } else
649
+ st = { nextDelim: A, quoteSearch: rt };
650
+ return st;
651
+ }
652
+ }, this.abort = function() {
653
+ j = !0;
654
+ }, this.getCharIndex = function() {
655
+ return r;
656
+ };
657
+ }
658
+ function ft(e) {
659
+ var t = e.data, n = P[t.workerId], i = !1;
660
+ if (t.error)
661
+ n.userError(t.error, t.file);
662
+ else if (t.results && t.results.data) {
663
+ var s = { abort: function() {
664
+ i = !0, ct(t.workerId, { data: [], errors: [], meta: { aborted: !0 } });
665
+ }, pause: _t, resume: _t };
666
+ if (w(n.userStep)) {
667
+ for (var f = 0; f < t.results.data.length && (n.userStep({ data: t.results.data[f], errors: t.results.errors, meta: t.results.meta }, s), !i); f++)
668
+ ;
669
+ delete t.results;
670
+ } else
671
+ w(n.userChunk) && (n.userChunk(t.results, s, t.file), delete t.results);
672
+ }
673
+ t.finished && !i && ct(t.workerId, t.results);
674
+ }
675
+ function ct(e, t) {
676
+ var n = P[e];
677
+ w(n.userComplete) && n.userComplete(t), n.terminate(), delete P[e];
678
+ }
679
+ function _t() {
680
+ throw new Error("Not implemented.");
681
+ }
682
+ function mt(e) {
683
+ if (typeof e != "object" || e === null)
684
+ return e;
685
+ var t = Array.isArray(e) ? [] : {};
686
+ for (var n in e)
687
+ t[n] = mt(e[n]);
688
+ return t;
689
+ }
690
+ function at(e, t) {
691
+ return function() {
692
+ e.apply(t, arguments);
693
+ };
694
+ }
695
+ function w(e) {
696
+ return typeof e == "function";
697
+ }
698
+ return I && (d.onmessage = function(e) {
699
+ var t = e.data;
700
+ if (a.WORKER_ID === void 0 && t && (a.WORKER_ID = t.workerId), typeof t.input == "string")
701
+ d.postMessage({ workerId: a.WORKER_ID, results: a.parse(t.input, t.config), finished: !0 });
702
+ else if (d.File && t.input instanceof File || t.input instanceof Object) {
703
+ var n = a.parse(t.input, t.config);
704
+ n && d.postMessage({ workerId: a.WORKER_ID, results: n, finished: !0 });
705
+ }
706
+ }), (J.prototype = Object.create(N.prototype)).constructor = J, (Z.prototype = Object.create(N.prototype)).constructor = Z, (V.prototype = Object.create(V.prototype)).constructor = V, (ht.prototype = Object.create(N.prototype)).constructor = ht, a;
707
+ });
708
+ })(Ct);
709
+ var Ht = Ct.exports;
710
+ const Gt = 20, Qt = (h) => {
711
+ const l = [];
712
+ let g = 0;
713
+ const d = [...h];
714
+ return h[0][0] === "DATAPOINT_NAME" && d.shift(), d.forEach((x, I) => {
715
+ if (g > Gt)
716
+ throw new Error("INVALID_DOCUMENT");
717
+ const [P, q, a, Y, N, J] = x, Z = {};
718
+ N && !isNaN(parseInt(N)) && (Z.threshold1 = parseInt(N)), J && !isNaN(parseInt(J)) && (Z.threshold2 = parseInt(J));
719
+ const V = {
720
+ idx: I,
721
+ data: {
722
+ name: P,
723
+ datatype: q && q.toUpperCase(),
724
+ unit: Y ? {
725
+ name: Y,
726
+ print: a
727
+ } : null,
728
+ thresholds: Z
729
+ }
730
+ };
731
+ if (l.push(V), x.length < 2)
732
+ return g++, V.error = "INVALID_NUMBER_OF_CELLS";
733
+ if (!wt.includes(q))
734
+ return g++, V.error = "INVALID_DATATYPE";
735
+ }), l;
736
+ }, Yt = (h) => new Promise((l, g) => {
737
+ Ht.parse(h, {
738
+ skipEmptyLines: !0,
739
+ complete: ({ data: d }) => {
740
+ try {
741
+ const x = Qt(d);
742
+ l(x);
743
+ } catch (x) {
744
+ g(x);
745
+ }
746
+ },
747
+ error: (d) => {
748
+ g(d);
749
+ }
750
+ });
751
+ }), $t = (h, l, g) => g.findIndex((d) => (d == null ? void 0 : d.name) === (h == null ? void 0 : h.name)) === l, Jt = async (h, l, g) => {
752
+ const x = l.filter((I) => !I.error).map((I) => I.data.unit).filter((I) => I && !h.some((P) => P.name === I.name)).filter($t).filter(kt).map(g);
753
+ return await Promise.all(x), await Pt();
754
+ }, Vt = [
755
+ "DATAPOINT_NAME,DATAPOINT_TYPE,UNIT_DISPLAY_NAME,UNIT_IDENTIFIER,DATAPOINT_UPPER_THRESHOLD,DATAPOINT_LOWER_THRESHOLD",
756
+ "new_datapoint_1,LONG,°C,degrees-celsius,20,7",
757
+ "new_datapoint_2,LONG,,,,"
758
+ ], vt = {
759
+ marginLeft: 15,
760
+ listStyle: "disc"
761
+ }, Xt = () => /* @__PURE__ */ c.jsxs("ul", { style: { ...vt, width: 345 }, children: [
762
+ /* @__PURE__ */ c.jsxs("li", { children: [
763
+ /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.infoColumns", children: "Columns:" }),
764
+ /* @__PURE__ */ c.jsxs("ul", { style: { ...vt, listStyle: "circle" }, children: [
765
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointNameColumn", children: "Datapoint Name (required)" }) }),
766
+ /* @__PURE__ */ c.jsx(
767
+ "li",
768
+ {
769
+ style: {
770
+ whiteSpace: "normal"
771
+ },
772
+ children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointDatatypeColumn", children: "Datapoint Type (required). Datatypes: 'BOOLEAN', 'DOUBLE', 'LONG', 'TEXT', 'GEO_POSITION'" })
773
+ }
774
+ ),
775
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointUnitPrintColumn", children: "Display name of unit (optional)" }) }),
776
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointUnitPrintColumn", children: "Identifier of unit (optional)" }) }),
777
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointUpperThresholdColumn", children: "Datapoint upper threshold (optional)" }) }),
778
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.datapointLowerThresholdColumn", children: "Datapoint lower threshold (optional)" }) })
779
+ ] })
780
+ ] }),
781
+ /* @__PURE__ */ c.jsx("li", { children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.infoDelimiter", children: 'Csv should use "," as delimiter' }) })
782
+ ] }), xt = Ot({
783
+ pageSize: 10,
784
+ onPageSizeChange: () => {
785
+ }
786
+ }), St = "uiConfigurations/datapointimportpagination";
787
+ function Zt({ children: h }) {
788
+ const [l, g] = pt(10), d = (x) => {
789
+ g(x), zt(St, { pageSize: x });
790
+ };
791
+ return Rt(() => {
792
+ const { promise: x, cancel: I } = bt(Ft(St));
793
+ return x.then((P) => {
794
+ g((P == null ? void 0 : P.pageSize) ?? 10);
795
+ }).catch((P) => {
796
+ }), I;
797
+ }, []), /* @__PURE__ */ c.jsx(xt.Provider, { value: { pageSize: l, onPageSizeChange: d }, children: h });
798
+ }
799
+ function he(h) {
800
+ return /* @__PURE__ */ c.jsx(Zt, { children: /* @__PURE__ */ c.jsx(te, { ...h }) });
801
+ }
802
+ function te({ existingUnits: h, onChangeUploadStatus: l, createDatapoint: g, addUnit: d }) {
803
+ const [x, I] = pt([]), [P, q] = pt(null), { pageSize: a, onPageSizeChange: Y } = At(xt), [N, J] = pt(!1);
804
+ function Z() {
805
+ I([]), q(null);
806
+ }
807
+ function V(K) {
808
+ J(!0), I([]), q(null), Yt(K).then(async (W) => {
809
+ await Jt(h, W, d), I(W), l(!0, 0, 0);
810
+ }).catch((W) => {
811
+ q(W);
812
+ }).finally(() => J(!1));
813
+ }
814
+ function ht(K) {
815
+ const W = Object.values(K), ft = W.filter((ct) => ct === "UPLOAD_SUCCESSFUL");
816
+ l(W.length !== x.length, ft.length, x.length);
817
+ }
818
+ function ut() {
819
+ const K = "datapoint-import-template.csv";
820
+ It.saveAs(
821
+ new Blob([Vt.join(`
822
+ `)], {
823
+ type: "text/csv"
824
+ }),
825
+ K
826
+ );
827
+ }
828
+ return /* @__PURE__ */ c.jsxs(c.Fragment, { children: [
829
+ /* @__PURE__ */ c.jsx(
830
+ Ut,
831
+ {
832
+ onRemoveFile: Z,
833
+ onSelectFile: V,
834
+ previewComponent: ({ file: K, onRemoveFile: W }) => /* @__PURE__ */ c.jsxs("strong", { className: "di delete-file-button", children: [
835
+ K ? K.name : "",
836
+ /* @__PURE__ */ c.jsx(yt, { naked: !0, onClick: W, "data-testid": "delete-file-button", children: /* @__PURE__ */ c.jsx(Lt, { del: !0 }) })
837
+ ] })
838
+ }
839
+ ),
840
+ P && /* @__PURE__ */ c.jsx("div", { className: "di upload-error parsing-error", children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.tooManyParsingErrors", children: "Too many parsing errors" }) }),
841
+ !x.length && /* @__PURE__ */ c.jsxs("div", { className: "di download-csv-section", children: [
842
+ /* @__PURE__ */ c.jsx(yt, { onClick: ut, children: /* @__PURE__ */ c.jsx(et, { i18nKey: "datapointImport.downloadSample", children: "Download template csv file" }) }),
843
+ /* @__PURE__ */ c.jsx("label", { className: "csv-upload-info", children: /* @__PURE__ */ c.jsx(jt, { content: /* @__PURE__ */ c.jsx(Xt, {}), children: /* @__PURE__ */ c.jsx("span", { className: "upload-anchor", children: " ?" }) }) })
844
+ ] }),
845
+ /* @__PURE__ */ c.jsx("div", { className: "datapoint-import-section", children: /* @__PURE__ */ c.jsx(
846
+ Wt,
847
+ {
848
+ onRowComplete: ht,
849
+ data: x,
850
+ isLoading: N,
851
+ createDatapoint: g,
852
+ pageSize: a,
853
+ onPageSizeChange: Y
854
+ }
855
+ ) })
856
+ ] });
857
+ }
858
+ export {
859
+ he as default
860
+ };