@glodon-aiot/dataset-annotation 3.14.0-alpha.33 → 3.14.0-alpha.34

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,445 @@
1
+ var He = Object.defineProperty, Ke = Object.defineProperties;
2
+ var Oe = Object.getOwnPropertyDescriptors;
3
+ var ze = Object.getOwnPropertySymbols;
4
+ var We = Object.prototype.hasOwnProperty, Je = Object.prototype.propertyIsEnumerable;
5
+ var Re = (w, y, f) => y in w ? He(w, y, { enumerable: !0, configurable: !0, writable: !0, value: f }) : w[y] = f, N = (w, y) => {
6
+ for (var f in y || (y = {}))
7
+ We.call(y, f) && Re(w, f, y[f]);
8
+ if (ze)
9
+ for (var f of ze(y))
10
+ Je.call(y, f) && Re(w, f, y[f]);
11
+ return w;
12
+ }, E = (w, y) => Ke(w, Oe(y));
13
+ var T = (w, y, f) => new Promise((R, h) => {
14
+ var m = (x) => {
15
+ try {
16
+ V(f.next(x));
17
+ } catch (F) {
18
+ h(F);
19
+ }
20
+ }, re = (x) => {
21
+ try {
22
+ V(f.throw(x));
23
+ } catch (F) {
24
+ h(F);
25
+ }
26
+ }, V = (x) => x.done ? R(x.value) : Promise.resolve(x.value).then(m, re);
27
+ V((f = f.apply(w, y)).next());
28
+ });
29
+ import { jsxs as j, jsx as c, Fragment as Xe } from "react/jsx-runtime";
30
+ import { Tabs as ye, message as M, Spin as Ye, Space as qe, Button as ie, Modal as Ze } from "antd";
31
+ import { forwardRef as _e, useContext as et, useRef as Q, useState as g, useEffect as X, useImperativeHandle as tt } from "react";
32
+ import "./style.less.mjs";
33
+ import nt from "../../DataEmpty/index.mjs";
34
+ import it from "../../../DatasetContext/index.mjs";
35
+ import rt from "../../VLMAnnotation/index.mjs";
36
+ import ot from "axios";
37
+ import st from "../MarkVLMBoxModal/AttributeDetail/index.mjs";
38
+ import at from "../MarkVLMBoxModal/QADetail/index.mjs";
39
+ const {
40
+ TabPane: K
41
+ } = ye, vt = _e((w, y) => {
42
+ const {
43
+ visible: f,
44
+ selectSampleId: R,
45
+ datasetId: h,
46
+ versionId: m,
47
+ onClose: re,
48
+ onSave: V,
49
+ externalSamples: x,
50
+ externalPagination: F,
51
+ externalCurrentIndex: oe,
52
+ externalFilterMode: ve,
53
+ onFilterModeChange: se
54
+ } = w, {
55
+ services: {
56
+ cvforceDatahub: l
57
+ },
58
+ token: Ne,
59
+ apiUrl: Ce
60
+ } = et(it), B = Q(null), [i, C] = g(), I = Q(void 0), [ct, ae] = g(0), [S, P] = g(() => R && (x != null && x.length) ? x : []), [ce, U] = g(() => R && oe !== void 0 ? oe : -1), [d, G] = g(() => R && F ? N({}, F) : {
61
+ current: 1,
62
+ pageSize: 100
63
+ }), [Ie, be] = g(0), [we, ke] = g(0), [k, le] = g(() => R && ve ? ve : R ? "" : "nocode"), [de, O] = g(), [fe, Ae] = g([]), [p, Y] = g("textAnnotation"), [W, H] = g(), [Z, q] = g(!1), _ = Q(0), ue = Q(0), [ge, Te] = g(!1), [ee, te] = g(!1), [he, pe] = g(!1), [De, Le] = g(!1), [ne, me] = g(!1), $ = Q(null), z = Q(null), xe = Q(!1), [Me, Ue] = g(() => Date.now()), [Ge, Pe] = g(() => Date.now());
64
+ X(() => {
65
+ f && (!h || !m || l == null || l.getDatasetsIdVersionsVidConfigs(h, m).then((e) => {
66
+ Ae(e || []), (e == null ? void 0 : e.length) > 0 ? Y("textAnnotation") : Y("attributeDefinition");
67
+ }));
68
+ }, [f]), X(() => {
69
+ const e = d.current || 1, t = d.pageSize || 100, n = d.type;
70
+ if (!h || !m)
71
+ return;
72
+ if (!xe.current && R && (x != null && x.length) && F && oe !== void 0) {
73
+ const v = x.find((s) => s.id === R);
74
+ if (v) {
75
+ xe.current = !0, C(v), ae(x.length), D();
76
+ return;
77
+ }
78
+ }
79
+ const o = ++_.current;
80
+ pe(!0);
81
+ const u = S || [], r = xe.current ? de : R || de;
82
+ l == null || l.getDatasetsIdVersionsVidSamples(h, m, {
83
+ labels: k ? [k] : void 0,
84
+ pageNo: e,
85
+ pageSize: t
86
+ }).then((v) => {
87
+ if (o !== _.current)
88
+ return;
89
+ const s = v.recordList || [], a = e === 1 && !n ? s : n === "prev" ? [...s, ...u] : n === "next" ? [...u, ...s] : s;
90
+ P(a), G(E(N({}, d), {
91
+ current: e,
92
+ pageSize: t,
93
+ total: v.totalResults,
94
+ type: void 0
95
+ }));
96
+ let b = 0, A = a[0];
97
+ if (n === "next" && s.length)
98
+ b = u.length, A = s[0];
99
+ else if (n === "prev" && s.length)
100
+ b = s.length - 1, A = s[s.length - 1];
101
+ else if (r) {
102
+ const L = a.findIndex((J) => J.id === r);
103
+ if (L !== -1)
104
+ b = L, A = a[L];
105
+ else {
106
+ l == null || l.getDatasetsIdVersionsVidSsamplesSid(h, m, r).then((J) => {
107
+ o === _.current && J && (P([J, ...a]), C(J), U(0), ae(a.length + 1), O(void 0));
108
+ });
109
+ return;
110
+ }
111
+ }
112
+ A && (C(A), U(b), ae(a.length), de && O(void 0));
113
+ }).finally(() => {
114
+ o === _.current && pe(!1);
115
+ }), D();
116
+ }, [d.current, k, h, m]);
117
+ const D = () => {
118
+ !h || !m || l == null || l.getDatasetsIdVersionsVidLabelcount(h, m).then((e) => {
119
+ const t = e.find((o) => o.id === "allcodeid"), n = e.find((o) => o.id === "nocodeid");
120
+ be(t ? t.count : 0), ke(n ? n.count : 0);
121
+ });
122
+ }, Se = () => {
123
+ S && P((e) => {
124
+ var v, s, a, b;
125
+ const t = I.current || i, n = [...e];
126
+ let o;
127
+ if (t) {
128
+ const A = n.findIndex((L) => L.id === t.id);
129
+ A > -1 && n.splice(A, 1, t);
130
+ }
131
+ const u = !t || (v = t.labels) != null && v.length && k === "hascode" || !((s = t.labels) != null && s.length) && k === "nocode" || k === "" ? ce + 1 : ce;
132
+ if (t && ((a = t.labels) != null && a.length && k === "nocode" || !((b = t.labels) != null && b.length) && k === "hascode")) {
133
+ const A = n.findIndex((L) => L.id === t.id);
134
+ A > -1 && (n.splice(A, 1), o = [...n], G((L) => E(N({}, L), {
135
+ total: L.total ? L.total - 1 : L.total
136
+ })));
137
+ }
138
+ const r = o || n;
139
+ return u >= r.length ? ((d.current - 1) * d.pageSize + u, d.total && u >= d.total ? M.error("已经是最后一个了") : G({
140
+ current: d.current + 1,
141
+ pageSize: d.pageSize,
142
+ type: "next"
143
+ })) : setTimeout(() => {
144
+ U(u);
145
+ const A = r[u];
146
+ C(A);
147
+ }, 0), r;
148
+ });
149
+ }, Ve = () => {
150
+ var r, v;
151
+ if (!S)
152
+ return;
153
+ const e = I.current || i, t = [...S];
154
+ let n;
155
+ if (e && S) {
156
+ const s = t.findIndex((a) => a.id === e.id);
157
+ if (s > -1 && t.splice(s, 1, e), (r = e.labels) != null && r.length && k === "nocode" || !((v = e.labels) != null && v.length) && k === "hascode") {
158
+ const a = t.findIndex((b) => b.id === e.id);
159
+ a > -1 && (t.splice(a, 1), n = [...t], G((b) => E(N({}, b), {
160
+ total: b.total ? b.total - 1 : b.total
161
+ })));
162
+ }
163
+ }
164
+ const o = n || t, u = ce - 1;
165
+ if (u < 0)
166
+ (d.current - 1) * d.pageSize + u < 0 ? M.error("已经是第一个了") : G({
167
+ current: d.current - 1,
168
+ pageSize: d.pageSize,
169
+ type: "prev"
170
+ });
171
+ else {
172
+ U(u);
173
+ const s = o[u];
174
+ C(s);
175
+ }
176
+ n && P(n);
177
+ };
178
+ X(() => {
179
+ if (!f || !h || !m || !i)
180
+ return;
181
+ const e = ++ue.current;
182
+ Le(!0), l == null || l.getDatasetsIdVersionsVidSsamplesSid(h, m, i.id).then((t) => {
183
+ e === ue.current && C(t);
184
+ }).finally(() => {
185
+ e === ue.current && Le(!1);
186
+ });
187
+ }, [f, i == null ? void 0 : i.id]);
188
+ const $e = () => T(void 0, null, function* () {
189
+ p === "attributeDefinition" && $.current && !(yield $.current.checkDirtyAndConfirm()) || p === "qaGeneration" && z.current && !(yield z.current.checkDirtyAndConfirm()) || re();
190
+ });
191
+ tt(y, () => ({
192
+ handleModalCancel: $e
193
+ })), X(() => {
194
+ B.current && (B.current.width = B.current.offsetWidth, B.current.height = B.current.offsetHeight);
195
+ }, [B.current]);
196
+ const Ee = () => T(void 0, null, function* () {
197
+ if (Z)
198
+ return;
199
+ if (q(!0), p === "qaGeneration" && z.current && !(yield z.current.checkDirtyAndConfirm())) {
200
+ q(!1);
201
+ return;
202
+ }
203
+ const e = I.current || i;
204
+ if (!e) {
205
+ q(!1);
206
+ return;
207
+ }
208
+ console.log("onPrevClick sampleToUse", e), p === "textAnnotation" && W ? (te(!0), V(e).then((t) => {
209
+ t ? (H(void 0), Ve(), D()) : M.error("保存失败");
210
+ }).finally(() => {
211
+ te(!1), q(!1);
212
+ })) : (Ve(), q(!1));
213
+ }), Fe = () => T(void 0, null, function* () {
214
+ if (Z)
215
+ return;
216
+ if (q(!0), p === "qaGeneration" && z.current && !(yield z.current.checkDirtyAndConfirm())) {
217
+ q(!1);
218
+ return;
219
+ }
220
+ const e = I.current || i;
221
+ if (!e) {
222
+ q(!1);
223
+ return;
224
+ }
225
+ console.log("onNextClick sampleToUse", e), p === "textAnnotation" && W ? (te(!0), V(e).then((t) => {
226
+ t ? (H(void 0), Se(), D()) : M.error("保存失败");
227
+ }).finally(() => {
228
+ te(!1), q(!1);
229
+ })) : (Se(), q(!1));
230
+ });
231
+ X(() => {
232
+ I.current = i;
233
+ }, [i]);
234
+ const je = (e) => (console.log("ocrRecognize apiUrl", Ce), ot.post(`${Ce}/aishop/v2/infer?serviceId=Actpkb4pi3vxg`, {
235
+ pages: [{
236
+ image: e,
237
+ no: 0
238
+ }]
239
+ }, {
240
+ headers: {
241
+ Authorization: `Bearer ${Ne}`
242
+ }
243
+ }).then((t) => (console.log("ocrRecognize res", t.data.data), t.data.data.pages[0].layout.filter((o) => o.content))).catch((t) => {
244
+ console.error("ocrRecognize error", t);
245
+ })), Qe = () => T(void 0, null, function* () {
246
+ const e = I.current || i;
247
+ !e || !h || !m || Ze.confirm({
248
+ title: "确认要删除此数据吗?",
249
+ content: "删除后不可恢复,请慎重操作",
250
+ onOk: () => T(void 0, null, function* () {
251
+ console.log("handleDeleteClick currentSample", e);
252
+ try {
253
+ yield l == null ? void 0 : l.delDatasetsIdVersionsVidSamplesId(h, m, e.id), M.success("删除成功"), P((t) => {
254
+ var s;
255
+ const n = t.findIndex((a) => a.id === e.id);
256
+ if (n === -1)
257
+ return t;
258
+ const o = [...t.slice(0, n), ...t.slice(n + 1)], u = d.pageSize || 1, r = Math.max(((s = d.total) != null ? s : t.length) - 1, 0), v = o.length === 0 && r > d.current * u;
259
+ if (G((a) => N(E(N({}, a), {
260
+ total: r
261
+ }), v ? {
262
+ current: a.current + 1,
263
+ pageSize: u,
264
+ type: "next"
265
+ } : {
266
+ type: v ? "next" : void 0
267
+ })), o.length) {
268
+ const a = Math.min(n, o.length - 1);
269
+ U(a), C(o[a]);
270
+ } else
271
+ U(-1), C(void 0);
272
+ return o;
273
+ }), D();
274
+ } catch (t) {
275
+ M.error("删除失败");
276
+ }
277
+ })
278
+ });
279
+ }), Be = () => T(void 0, null, function* () {
280
+ if (!h || !m || !(i != null && i.id))
281
+ return;
282
+ const e = yield l == null ? void 0 : l.getDatasetsIdVersionsVidSsamplesSid(h, m, i.id);
283
+ e && (C(e), I.current = e);
284
+ });
285
+ return /* @__PURE__ */ j("div", {
286
+ className: "vlm-records-content",
287
+ children: [/* @__PURE__ */ c("div", {
288
+ className: "records-content-tabs-container",
289
+ children: /* @__PURE__ */ j(ye, {
290
+ className: "records-content-tabs",
291
+ activeKey: k,
292
+ onChange: (e) => T(void 0, null, function* () {
293
+ var n, o, u;
294
+ let t = !1;
295
+ if (!(p === "attributeDefinition" && $.current && (t = !!((o = (n = $.current).hasUnsavedChanges) != null && o.call(n)), !(yield $.current.checkDirtyAndConfirm()))) && !(p === "qaGeneration" && z.current && !(yield z.current.checkDirtyAndConfirm()))) {
296
+ if (p === "textAnnotation" && W) {
297
+ const r = I.current || i;
298
+ if (r && V) {
299
+ if (!(yield V(r))) {
300
+ M.error("保存失败,已阻止切换筛选");
301
+ return;
302
+ }
303
+ C(r), I.current = r, H(void 0), D == null || D(), k === "nocode" && ((u = r == null ? void 0 : r.labels) != null && u.length) && (P([]), C(r), U(-1), O(r.id), G(E(N({}, d), {
304
+ current: 1,
305
+ total: void 0,
306
+ type: void 0
307
+ })), le("hascode"));
308
+ }
309
+ }
310
+ t && Ue(Date.now()), Pe(Date.now()), p !== "attributeDefinition" && (pe(!0), P([]), C(void 0), U(-1), O(void 0)), G(E(N({}, d), {
311
+ current: 1,
312
+ total: void 0,
313
+ type: void 0
314
+ })), le(e), se == null || se(e);
315
+ }
316
+ }),
317
+ children: [/* @__PURE__ */ c(K, {
318
+ tab: `全部(${Ie})`
319
+ }, ""), /* @__PURE__ */ c(K, {
320
+ tab: `未标注(${we})`
321
+ }, "nocode"), /* @__PURE__ */ c(K, {
322
+ tab: `已标注(${Ie - we})`
323
+ }, "hascode")]
324
+ })
325
+ }), S != null && S.length ? /* @__PURE__ */ j("div", {
326
+ className: "sample-detail",
327
+ children: [/* @__PURE__ */ c("div", {
328
+ className: "content-mode-buttons",
329
+ children: /* @__PURE__ */ j(ye, {
330
+ activeKey: p,
331
+ onChange: (e) => T(void 0, null, function* () {
332
+ var t;
333
+ if (!(p === "attributeDefinition" && $.current && !(yield $.current.checkDirtyAndConfirm())) && !(p === "qaGeneration" && z.current && !(yield z.current.checkDirtyAndConfirm()))) {
334
+ if (p === "textAnnotation" && V && W && (I.current || i)) {
335
+ const n = I.current || i;
336
+ if (!(yield V(n))) {
337
+ M.error("保存失败,已阻止切换页签");
338
+ return;
339
+ }
340
+ C(n), I.current = n, H(void 0), D == null || D(), k === "nocode" && ((t = n == null ? void 0 : n.labels) != null && t.length) && (P([]), C(n), U(-1), O(n.id), G(E(N({}, d), {
341
+ current: 1,
342
+ total: void 0,
343
+ type: void 0
344
+ })), le("hascode"));
345
+ }
346
+ e === "textAnnotation" && (i != null && i.id) && (yield Be()), Y(e);
347
+ }
348
+ }),
349
+ children: [/* @__PURE__ */ c(K, {
350
+ tab: "属性定义",
351
+ disabled: ge
352
+ }, "attributeDefinition"), /* @__PURE__ */ c(K, {
353
+ tab: "文本标注",
354
+ disabled: ge
355
+ }, "textAnnotation"), /* @__PURE__ */ c(K, {
356
+ tab: "QA生成",
357
+ disabled: ge
358
+ }, "qaGeneration")]
359
+ })
360
+ }), p === "textAnnotation" && i && /* @__PURE__ */ c("div", {
361
+ className: "container",
362
+ children: /* @__PURE__ */ c(rt, {
363
+ sample: i,
364
+ labelDefinitions: fe,
365
+ onChange: (e) => {
366
+ console.log("VLMAnnotation onChange", e), I.current = e, H(e);
367
+ },
368
+ ocrRecognize: je
369
+ })
370
+ }), p === "attributeDefinition" && /* @__PURE__ */ c(st, {
371
+ ref: $,
372
+ datasetId: h,
373
+ versionId: m,
374
+ onAttributesChange: (e) => {
375
+ Ae(e), e.length > 0 && fe.length === 0 && Y("textAnnotation");
376
+ },
377
+ onLoadingChange: (e) => {
378
+ Te(e);
379
+ }
380
+ }, `attribute-${Me}`), p === "qaGeneration" && /* @__PURE__ */ c(at, {
381
+ ref: z,
382
+ sample: i,
383
+ labels: fe,
384
+ datasetId: h,
385
+ visionId: m
386
+ }, `qa-${Ge}`)]
387
+ }) : he ? /* @__PURE__ */ c("div", {
388
+ style: {
389
+ padding: "48px 0",
390
+ textAlign: "center"
391
+ },
392
+ children: /* @__PURE__ */ c(Ye, {})
393
+ }) : /* @__PURE__ */ c(nt, {}), p !== "attributeDefinition" ? /* @__PURE__ */ j("div", {
394
+ className: "vlm-detail-footer",
395
+ children: [/* @__PURE__ */ c("div", {
396
+ style: {
397
+ flex: 1
398
+ }
399
+ }), /* @__PURE__ */ j(qe, {
400
+ size: 24,
401
+ children: [(S == null ? void 0 : S.length) > 0 && /* @__PURE__ */ c(ie, {
402
+ type: "default",
403
+ disabled: De || he || ee || Z || ne,
404
+ onClick: Ee,
405
+ children: "上一张"
406
+ }, "prev"), (S == null ? void 0 : S.length) > 0 && /* @__PURE__ */ c(ie, {
407
+ type: "default",
408
+ disabled: De || he || ee || Z || ne,
409
+ onClick: Fe,
410
+ children: "下一张"
411
+ }, "next")]
412
+ }), /* @__PURE__ */ c("div", {
413
+ style: {
414
+ flex: 1,
415
+ display: "flex",
416
+ justifyContent: "flex-end"
417
+ },
418
+ children: /* @__PURE__ */ c(qe, {
419
+ children: p === "textAnnotation" && (S == null ? void 0 : S.length) > 0 ? /* @__PURE__ */ j(Xe, {
420
+ children: [/* @__PURE__ */ c(ie, {
421
+ disabled: !i || !W || ee,
422
+ type: "primary",
423
+ onClick: () => {
424
+ const e = I.current || i;
425
+ e && (me(!0), console.log("save currentSample", e), V(e).then((t) => T(void 0, null, function* () {
426
+ t ? (M.success("保存成功"), H(void 0), Se(), D(), me(!1)) : (M.error("保存失败"), me(!1));
427
+ })));
428
+ },
429
+ loading: ne,
430
+ children: "保存标注"
431
+ }, "save"), /* @__PURE__ */ c(ie, {
432
+ type: "default",
433
+ disabled: ne || ee,
434
+ onClick: Qe,
435
+ children: "删除数据"
436
+ })]
437
+ }) : null
438
+ })
439
+ })]
440
+ }) : null]
441
+ });
442
+ });
443
+ export {
444
+ vt as default
445
+ };