react-table-edit 0.1.1 → 0.1.3
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/dist/index.js +27 -19
- package/dist/index.mjs +27 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -290,23 +290,26 @@ var generateUUID = () => {
|
|
|
290
290
|
});
|
|
291
291
|
};
|
|
292
292
|
var formartNumberic = (str, decimalSeparator, thousandSeparator, fraction = 10, isDone) => {
|
|
293
|
+
if (isDone) {
|
|
294
|
+
str = roundNumber(Number(str), fraction);
|
|
295
|
+
}
|
|
293
296
|
if (str || str == "0") {
|
|
294
297
|
str = str.toString();
|
|
295
298
|
const value = decimalSeparator !== "." ? str.toString().replaceAll(".", decimalSeparator ?? "") : str;
|
|
296
299
|
const arr = value.toString().split(decimalSeparator ?? "", 2);
|
|
297
300
|
let flag = value.toString().includes(decimalSeparator ?? "");
|
|
298
|
-
if (
|
|
301
|
+
if (arr[0].length < 3) {
|
|
299
302
|
return flag ? `${arr[0]}${decimalSeparator}${arr[1]?.substring(0, fraction) ?? ""}` : arr[0];
|
|
300
303
|
} else {
|
|
301
304
|
let count = 0;
|
|
302
|
-
for (let i =
|
|
303
|
-
if ((
|
|
304
|
-
arr[0] = `${arr[0]
|
|
305
|
+
for (let i = arr[0].length - 2; i >= 0; i--) {
|
|
306
|
+
if ((arr[0].length - i - count) % 3 === 0 && i > 0) {
|
|
307
|
+
arr[0] = `${arr[0].substring(0, i)}${thousandSeparator}${arr[0].substring(i, arr[0].length)}`;
|
|
305
308
|
count++;
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
|
-
if (arr[0]
|
|
309
|
-
arr[0] = arr[0]
|
|
311
|
+
if (arr[0].lastIndexOf(thousandSeparator ?? "") === arr[0].length - 1) {
|
|
312
|
+
arr[0] = arr[0].slice(0, arr[0].length - 1);
|
|
310
313
|
}
|
|
311
314
|
if (isDone) {
|
|
312
315
|
flag = (arr[1]?.substring(0, fraction) ?? "") !== "";
|
|
@@ -317,6 +320,11 @@ var formartNumberic = (str, decimalSeparator, thousandSeparator, fraction = 10,
|
|
|
317
320
|
return "";
|
|
318
321
|
}
|
|
319
322
|
};
|
|
323
|
+
var roundNumber = (num, fraction) => {
|
|
324
|
+
const base = 10 ** fraction;
|
|
325
|
+
const result = Math.round(num * base) / base;
|
|
326
|
+
return result;
|
|
327
|
+
};
|
|
320
328
|
|
|
321
329
|
// test-app/src/component/icon/index.tsx
|
|
322
330
|
var Icon = __toESM(require("becoxy-icons"));
|
|
@@ -2234,8 +2242,8 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
2234
2242
|
}
|
|
2235
2243
|
setDataSource([...data]);
|
|
2236
2244
|
};
|
|
2237
|
-
|
|
2238
|
-
|
|
2245
|
+
(0, import_react12.useEffect)(() => {
|
|
2246
|
+
setIndexFocus(-1);
|
|
2239
2247
|
if (setSelectedItem) {
|
|
2240
2248
|
if (isMulti) {
|
|
2241
2249
|
if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
|
|
@@ -2251,7 +2259,7 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
2251
2259
|
}
|
|
2252
2260
|
}
|
|
2253
2261
|
}
|
|
2254
|
-
};
|
|
2262
|
+
}, [selectedRows]);
|
|
2255
2263
|
(0, import_react12.useEffect)(() => {
|
|
2256
2264
|
if (!isMulti) {
|
|
2257
2265
|
if (dataSource && selectedItem && selectedItem[fieldKey]) {
|
|
@@ -2371,15 +2379,15 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
2371
2379
|
if (index > -1) {
|
|
2372
2380
|
if (isMulti) {
|
|
2373
2381
|
selectedRows?.splice(index, 1);
|
|
2374
|
-
|
|
2382
|
+
setSelectedRows([...selectedRows]);
|
|
2375
2383
|
} else {
|
|
2376
|
-
|
|
2384
|
+
setSelectedRows([]);
|
|
2377
2385
|
}
|
|
2378
2386
|
} else {
|
|
2379
2387
|
if (isMulti) {
|
|
2380
|
-
|
|
2388
|
+
setSelectedRows([...selectedRows, row]);
|
|
2381
2389
|
} else {
|
|
2382
|
-
|
|
2390
|
+
setSelectedRows([row]);
|
|
2383
2391
|
}
|
|
2384
2392
|
}
|
|
2385
2393
|
e.stopPropagation();
|
|
@@ -2442,15 +2450,15 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
2442
2450
|
if (index > -1) {
|
|
2443
2451
|
if (isMulti) {
|
|
2444
2452
|
selectedRows?.splice(index, 1);
|
|
2445
|
-
|
|
2453
|
+
setSelectedRows([...selectedRows]);
|
|
2446
2454
|
} else {
|
|
2447
|
-
|
|
2455
|
+
setSelectedRows([]);
|
|
2448
2456
|
}
|
|
2449
2457
|
} else {
|
|
2450
2458
|
if (isMulti) {
|
|
2451
|
-
|
|
2459
|
+
setSelectedRows([...selectedRows, row]);
|
|
2452
2460
|
} else {
|
|
2453
|
-
|
|
2461
|
+
setSelectedRows([row]);
|
|
2454
2462
|
}
|
|
2455
2463
|
}
|
|
2456
2464
|
}
|
|
@@ -2510,9 +2518,9 @@ var TableEdit = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
2510
2518
|
const arr = dataSource?.map((item) => {
|
|
2511
2519
|
return item;
|
|
2512
2520
|
});
|
|
2513
|
-
|
|
2521
|
+
setSelectedRows(arr);
|
|
2514
2522
|
} else {
|
|
2515
|
-
|
|
2523
|
+
setSelectedRows([]);
|
|
2516
2524
|
}
|
|
2517
2525
|
}
|
|
2518
2526
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -245,23 +245,26 @@ var generateUUID = () => {
|
|
|
245
245
|
});
|
|
246
246
|
};
|
|
247
247
|
var formartNumberic = (str, decimalSeparator, thousandSeparator, fraction = 10, isDone) => {
|
|
248
|
+
if (isDone) {
|
|
249
|
+
str = roundNumber(Number(str), fraction);
|
|
250
|
+
}
|
|
248
251
|
if (str || str == "0") {
|
|
249
252
|
str = str.toString();
|
|
250
253
|
const value = decimalSeparator !== "." ? str.toString().replaceAll(".", decimalSeparator ?? "") : str;
|
|
251
254
|
const arr = value.toString().split(decimalSeparator ?? "", 2);
|
|
252
255
|
let flag = value.toString().includes(decimalSeparator ?? "");
|
|
253
|
-
if (
|
|
256
|
+
if (arr[0].length < 3) {
|
|
254
257
|
return flag ? `${arr[0]}${decimalSeparator}${arr[1]?.substring(0, fraction) ?? ""}` : arr[0];
|
|
255
258
|
} else {
|
|
256
259
|
let count = 0;
|
|
257
|
-
for (let i =
|
|
258
|
-
if ((
|
|
259
|
-
arr[0] = `${arr[0]
|
|
260
|
+
for (let i = arr[0].length - 2; i >= 0; i--) {
|
|
261
|
+
if ((arr[0].length - i - count) % 3 === 0 && i > 0) {
|
|
262
|
+
arr[0] = `${arr[0].substring(0, i)}${thousandSeparator}${arr[0].substring(i, arr[0].length)}`;
|
|
260
263
|
count++;
|
|
261
264
|
}
|
|
262
265
|
}
|
|
263
|
-
if (arr[0]
|
|
264
|
-
arr[0] = arr[0]
|
|
266
|
+
if (arr[0].lastIndexOf(thousandSeparator ?? "") === arr[0].length - 1) {
|
|
267
|
+
arr[0] = arr[0].slice(0, arr[0].length - 1);
|
|
265
268
|
}
|
|
266
269
|
if (isDone) {
|
|
267
270
|
flag = (arr[1]?.substring(0, fraction) ?? "") !== "";
|
|
@@ -272,6 +275,11 @@ var formartNumberic = (str, decimalSeparator, thousandSeparator, fraction = 10,
|
|
|
272
275
|
return "";
|
|
273
276
|
}
|
|
274
277
|
};
|
|
278
|
+
var roundNumber = (num, fraction) => {
|
|
279
|
+
const base = 10 ** fraction;
|
|
280
|
+
const result = Math.round(num * base) / base;
|
|
281
|
+
return result;
|
|
282
|
+
};
|
|
275
283
|
|
|
276
284
|
// test-app/src/component/icon/index.tsx
|
|
277
285
|
import * as Icon from "becoxy-icons";
|
|
@@ -2207,8 +2215,8 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2207
2215
|
}
|
|
2208
2216
|
setDataSource([...data]);
|
|
2209
2217
|
};
|
|
2210
|
-
|
|
2211
|
-
|
|
2218
|
+
useEffect5(() => {
|
|
2219
|
+
setIndexFocus(-1);
|
|
2212
2220
|
if (setSelectedItem) {
|
|
2213
2221
|
if (isMulti) {
|
|
2214
2222
|
if (dataSource && selectedRows && selectedRows?.length !== selectedItem?.length) {
|
|
@@ -2224,7 +2232,7 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2224
2232
|
}
|
|
2225
2233
|
}
|
|
2226
2234
|
}
|
|
2227
|
-
};
|
|
2235
|
+
}, [selectedRows]);
|
|
2228
2236
|
useEffect5(() => {
|
|
2229
2237
|
if (!isMulti) {
|
|
2230
2238
|
if (dataSource && selectedItem && selectedItem[fieldKey]) {
|
|
@@ -2344,15 +2352,15 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2344
2352
|
if (index > -1) {
|
|
2345
2353
|
if (isMulti) {
|
|
2346
2354
|
selectedRows?.splice(index, 1);
|
|
2347
|
-
|
|
2355
|
+
setSelectedRows([...selectedRows]);
|
|
2348
2356
|
} else {
|
|
2349
|
-
|
|
2357
|
+
setSelectedRows([]);
|
|
2350
2358
|
}
|
|
2351
2359
|
} else {
|
|
2352
2360
|
if (isMulti) {
|
|
2353
|
-
|
|
2361
|
+
setSelectedRows([...selectedRows, row]);
|
|
2354
2362
|
} else {
|
|
2355
|
-
|
|
2363
|
+
setSelectedRows([row]);
|
|
2356
2364
|
}
|
|
2357
2365
|
}
|
|
2358
2366
|
e.stopPropagation();
|
|
@@ -2415,15 +2423,15 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2415
2423
|
if (index > -1) {
|
|
2416
2424
|
if (isMulti) {
|
|
2417
2425
|
selectedRows?.splice(index, 1);
|
|
2418
|
-
|
|
2426
|
+
setSelectedRows([...selectedRows]);
|
|
2419
2427
|
} else {
|
|
2420
|
-
|
|
2428
|
+
setSelectedRows([]);
|
|
2421
2429
|
}
|
|
2422
2430
|
} else {
|
|
2423
2431
|
if (isMulti) {
|
|
2424
|
-
|
|
2432
|
+
setSelectedRows([...selectedRows, row]);
|
|
2425
2433
|
} else {
|
|
2426
|
-
|
|
2434
|
+
setSelectedRows([row]);
|
|
2427
2435
|
}
|
|
2428
2436
|
}
|
|
2429
2437
|
}
|
|
@@ -2483,9 +2491,9 @@ var TableEdit = forwardRef2((props, ref) => {
|
|
|
2483
2491
|
const arr = dataSource?.map((item) => {
|
|
2484
2492
|
return item;
|
|
2485
2493
|
});
|
|
2486
|
-
|
|
2494
|
+
setSelectedRows(arr);
|
|
2487
2495
|
} else {
|
|
2488
|
-
|
|
2496
|
+
setSelectedRows([]);
|
|
2489
2497
|
}
|
|
2490
2498
|
}
|
|
2491
2499
|
}
|