@fluixi-ui/bulk-editor 0.3.0-alpha.12 → 0.3.0-alpha.14

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/formula.js CHANGED
@@ -1,12 +1,6 @@
1
1
  import { evaluateFormula } from "@fluixi-ui/formula";
2
2
  function formulaEvaluator(options) {
3
- return ({
4
- raw,
5
- get
6
- }) => evaluateFormula(raw, {
7
- resolve: get,
8
- functions: options?.functions
9
- });
3
+ return ({ raw, get }) => evaluateFormula(raw, { resolve: get, functions: options?.functions });
10
4
  }
11
5
  export {
12
6
  formulaEvaluator
package/dist/state.js CHANGED
@@ -69,10 +69,7 @@ function labelToCol(label) {
69
69
  function parseAddress(address) {
70
70
  const m = /^([A-Za-z]+)(\d+)$/.exec(address.trim());
71
71
  if (!m) return null;
72
- return {
73
- row: Number(m[2]) - 1,
74
- col: labelToCol(m[1])
75
- };
72
+ return { row: Number(m[2]) - 1, col: labelToCol(m[1]) };
76
73
  }
77
74
  function createBulkEditorState(options) {
78
75
  const evaluate = options.evaluate ?? ((ctx) => ctx.raw);
@@ -196,14 +193,15 @@ function createBulkEditorState(options) {
196
193
  if (!rng) return;
197
194
  setLockedCells((prev) => {
198
195
  const next = new Set(prev);
199
- for (let r = rng.r1; r <= rng.r2; r++) for (let c = rng.c1; c <= rng.c2; c++) {
200
- const row = rowAt(r);
201
- const col = colAt(c);
202
- if (!row || !col || isColumnReadOnly(col)) continue;
203
- const k = key(row.id, col.key);
204
- if (locked) next.add(k);
205
- else next.delete(k);
206
- }
196
+ for (let r = rng.r1; r <= rng.r2; r++)
197
+ for (let c = rng.c1; c <= rng.c2; c++) {
198
+ const row = rowAt(r);
199
+ const col = colAt(c);
200
+ if (!row || !col || isColumnReadOnly(col)) continue;
201
+ const k = key(row.id, col.key);
202
+ if (locked) next.add(k);
203
+ else next.delete(k);
204
+ }
207
205
  return next;
208
206
  });
209
207
  };
@@ -224,17 +222,8 @@ function createBulkEditorState(options) {
224
222
  if (visited.has(self)) return ERR.cycle;
225
223
  visited.add(self);
226
224
  try {
227
- if (col.compute) return col.compute({
228
- row,
229
- col,
230
- get: (a) => resolveRef(a, visited)
231
- });
232
- return evaluate({
233
- raw: getRaw(rowId, colKey),
234
- row,
235
- col,
236
- get: (a) => resolveRef(a, visited)
237
- });
225
+ if (col.compute) return col.compute({ row, col, get: (a) => resolveRef(a, visited) });
226
+ return evaluate({ raw: getRaw(rowId, colKey), row, col, get: (a) => resolveRef(a, visited) });
238
227
  } finally {
239
228
  visited.delete(self);
240
229
  }
@@ -243,10 +232,7 @@ function createBulkEditorState(options) {
243
232
  const computed = getComputed(rowId, colKey);
244
233
  const col = columns().find((c) => c.key === colKey);
245
234
  const row = rowById().get(rowId);
246
- return col?.format && row ? col.format(computed, {
247
- row,
248
- col
249
- }) : computed;
235
+ return col?.format && row ? col.format(computed, { row, col }) : computed;
250
236
  };
251
237
  const [sort, setSortState] = createSignal(null);
252
238
  const [columnFilters, setColumnFilters] = createSignal(/* @__PURE__ */ new Map());
@@ -255,9 +241,7 @@ function createBulkEditorState(options) {
255
241
  const va = getComputed(a.id, colKey);
256
242
  const vb = getComputed(b.id, colKey);
257
243
  if (col?.type === "number") return (Number(va) || 0) - (Number(vb) || 0);
258
- return va.localeCompare(vb, void 0, {
259
- numeric: true
260
- });
244
+ return va.localeCompare(vb, void 0, { numeric: true });
261
245
  };
262
246
  function applyView() {
263
247
  let rows = baseData();
@@ -271,13 +255,9 @@ function createBulkEditorState(options) {
271
255
  }
272
256
  const isViewActive = createMemo(() => sort() !== null || [...columnFilters().values()].some((t) => t));
273
257
  const viewRows = createMemo(() => isViewActive() ? applyView() : options.rows());
274
- const sortBy = (colKey) => setSortState((cur) => !cur || cur.colKey !== colKey ? {
275
- colKey,
276
- dir: "asc"
277
- } : cur.dir === "asc" ? {
278
- colKey,
279
- dir: "desc"
280
- } : null);
258
+ const sortBy = (colKey) => setSortState(
259
+ (cur) => !cur || cur.colKey !== colKey ? { colKey, dir: "asc" } : cur.dir === "asc" ? { colKey, dir: "desc" } : null
260
+ );
281
261
  const setSort = (next) => setSortState(next);
282
262
  const getColumnFilter = (colKey) => columnFilters().get(colKey) ?? "";
283
263
  const setColumnFilter = (colKey, text) => setColumnFilters((prev) => {
@@ -313,10 +293,7 @@ function createBulkEditorState(options) {
313
293
  if (!col?.aggregate) return "";
314
294
  const rows = dataRows();
315
295
  const values = rows.map((r) => getComputed(r.id, colKey));
316
- return typeof col.aggregate === "function" ? col.aggregate(values, {
317
- col,
318
- rows
319
- }) : aggregateValues(col.aggregate, values);
296
+ return typeof col.aggregate === "function" ? col.aggregate(values, { col, rows }) : aggregateValues(col.aggregate, values);
320
297
  };
321
298
  const getRawAt = (r, c) => {
322
299
  const row = rowAt(r);
@@ -357,20 +334,12 @@ function createBulkEditorState(options) {
357
334
  };
358
335
  const writeCell = (rowId, colKey, value) => {
359
336
  const before = getRaw(rowId, colKey);
360
- if (recording) recording.push({
361
- rowId,
362
- colKey,
363
- before,
364
- after: value
365
- });
337
+ if (recording) recording.push({ rowId, colKey, before, after: value });
366
338
  ensure(rowId, colKey, value)[1](value);
367
339
  const col = columns().find((c) => c.key === colKey);
368
340
  const row = rowById().get(rowId);
369
341
  if (col?.validate && row) {
370
- const message = col.validate(value, {
371
- row,
372
- col
373
- }) || void 0;
342
+ const message = col.validate(value, { row, col }) || void 0;
374
343
  setErrors((prev) => {
375
344
  const next = new Map(prev);
376
345
  if (message) next.set(key(rowId, colKey), message);
@@ -432,90 +401,32 @@ function createBulkEditorState(options) {
432
401
  const selectCell = (r, c, extend = false) => {
433
402
  r = cr(r);
434
403
  c = cc(c);
435
- setSelection((p) => extend && p ? {
436
- anchor: p.anchor,
437
- focus: {
438
- row: r,
439
- col: c
440
- }
441
- } : {
442
- anchor: {
443
- row: r,
444
- col: c
445
- },
446
- focus: {
447
- row: r,
448
- col: c
449
- }
450
- });
404
+ setSelection(
405
+ (p) => extend && p ? { anchor: p.anchor, focus: { row: r, col: c } } : { anchor: { row: r, col: c }, focus: { row: r, col: c } }
406
+ );
451
407
  };
452
408
  const move = (dr, dc, extend = false) => {
453
409
  if (rowCount() === 0 || colCount() === 0) return;
454
410
  const cur = selection();
455
- const from = extend && cur ? cur.focus : cur ? cur.anchor : {
456
- row: 0,
457
- col: 0
458
- };
411
+ const from = extend && cur ? cur.focus : cur ? cur.anchor : { row: 0, col: 0 };
459
412
  const nr = cr(from.row + dr);
460
413
  const nc = cc(from.col + dc);
461
- if (extend && cur) setSelection({
462
- anchor: cur.anchor,
463
- focus: {
464
- row: nr,
465
- col: nc
466
- }
467
- });
468
- else setSelection({
469
- anchor: {
470
- row: nr,
471
- col: nc
472
- },
473
- focus: {
474
- row: nr,
475
- col: nc
476
- }
477
- });
414
+ if (extend && cur) setSelection({ anchor: cur.anchor, focus: { row: nr, col: nc } });
415
+ else setSelection({ anchor: { row: nr, col: nc }, focus: { row: nr, col: nc } });
478
416
  };
479
417
  const selectRow = (r) => {
480
418
  if (colCount() === 0) return;
481
419
  r = cr(r);
482
- setSelection({
483
- anchor: {
484
- row: r,
485
- col: 0
486
- },
487
- focus: {
488
- row: r,
489
- col: colCount() - 1
490
- }
491
- });
420
+ setSelection({ anchor: { row: r, col: 0 }, focus: { row: r, col: colCount() - 1 } });
492
421
  };
493
422
  const selectColumn = (c) => {
494
423
  if (rowCount() === 0) return;
495
424
  c = cc(c);
496
- setSelection({
497
- anchor: {
498
- row: 0,
499
- col: c
500
- },
501
- focus: {
502
- row: rowCount() - 1,
503
- col: c
504
- }
505
- });
425
+ setSelection({ anchor: { row: 0, col: c }, focus: { row: rowCount() - 1, col: c } });
506
426
  };
507
427
  const selectAll = () => {
508
428
  if (rowCount() === 0 || colCount() === 0) return;
509
- setSelection({
510
- anchor: {
511
- row: 0,
512
- col: 0
513
- },
514
- focus: {
515
- row: rowCount() - 1,
516
- col: colCount() - 1
517
- }
518
- });
429
+ setSelection({ anchor: { row: 0, col: 0 }, focus: { row: rowCount() - 1, col: colCount() - 1 } });
519
430
  };
520
431
  const clearSelection = () => setSelection(null);
521
432
  const [editing, setEditing] = createSignal(null);
@@ -529,10 +440,7 @@ function createBulkEditorState(options) {
529
440
  const row = rowAt(r);
530
441
  if (!col || !row || isColumnReadOnly(col) || col.type === "checkbox" || isCellLocked(row.id, col.key)) return false;
531
442
  batch(() => {
532
- setEditing({
533
- row: r,
534
- col: c
535
- });
443
+ setEditing({ row: r, col: c });
536
444
  setEditBuffer(initChar !== void 0 ? initChar : getRaw(row.id, col.key));
537
445
  });
538
446
  return true;
@@ -577,10 +485,7 @@ function createBulkEditorState(options) {
577
485
  const row = rowAt(r);
578
486
  const col = colAt(c);
579
487
  if (!row || !col || col.type !== "checkbox" || col.readOnly) return;
580
- if (col.disable?.({
581
- row,
582
- col
583
- }) || isCellLocked(row.id, col.key)) return;
488
+ if (col.disable?.({ row, col }) || isCellLocked(row.id, col.key)) return;
584
489
  const next = getRaw(row.id, col.key) === "1" ? "0" : "1";
585
490
  withHistory(() => writeCell(row.id, col.key, next));
586
491
  };
@@ -598,10 +503,7 @@ function createBulkEditorState(options) {
598
503
  const value = getColumnCheckedState(colKey) === "all" ? "0" : "1";
599
504
  withHistory(() => {
600
505
  for (const row of baseData()) {
601
- if (isCellLocked(row.id, colKey) || col.disable?.({
602
- row,
603
- col
604
- })) continue;
506
+ if (isCellLocked(row.id, colKey) || col.disable?.({ row, col })) continue;
605
507
  writeCell(row.id, colKey, value);
606
508
  }
607
509
  });
@@ -632,14 +534,12 @@ function createBulkEditorState(options) {
632
534
  untrack(() => {
633
535
  const cols = columns();
634
536
  const initial = /* @__PURE__ */ new Map();
635
- for (const row of dataRows()) for (const col of cols) {
636
- if (!col.validate) continue;
637
- const msg = col.validate(getRaw(row.id, col.key), {
638
- row,
639
- col
640
- }) || void 0;
641
- if (msg) initial.set(key(row.id, col.key), msg);
642
- }
537
+ for (const row of dataRows())
538
+ for (const col of cols) {
539
+ if (!col.validate) continue;
540
+ const msg = col.validate(getRaw(row.id, col.key), { row, col }) || void 0;
541
+ if (msg) initial.set(key(row.id, col.key), msg);
542
+ }
643
543
  if (initial.size) setErrors(initial);
644
544
  });
645
545
  return {