@esfaenza/es-table 20.3.48 → 20.3.50

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.
@@ -8427,6 +8427,11 @@ class EsTable2Component {
8427
8427
  selectEverything() {
8428
8428
  if (this.SelectionDisabled() || this.SingleSelection())
8429
8429
  return;
8430
+ this.selectEverythingState();
8431
+ this.emitSelection(this.currentSelection());
8432
+ }
8433
+ /** Porta la selezione a "tutto selezionato" SENZA emettere (vedi setSelectionStatus) */
8434
+ selectEverythingState() {
8430
8435
  const sel = this.currentSelection();
8431
8436
  sel.all = true;
8432
8437
  sel.items = [];
@@ -8435,7 +8440,6 @@ class EsTable2Component {
8435
8440
  r._selected = true;
8436
8441
  this.refreshSelectionCount(sel);
8437
8442
  this.globalCheck.set(true);
8438
- this.emitSelection(sel);
8439
8443
  }
8440
8444
  /** Azzera completamente la selezione */
8441
8445
  clearSelection() {
@@ -9419,6 +9423,103 @@ class EsTable2Component {
9419
9423
  this.refresh();
9420
9424
  this.cdr.markForCheck();
9421
9425
  }
9426
+ /**
9427
+ * Imposta in maniera ARBITRARIA lo stato di selezione. Stessa firma dell'es-table
9428
+ * originale, così un consumer che la chiamava continua a compilare.
9429
+ *
9430
+ * A differenza di `toggleRow` (che INVERTE) qui lo stato viene FORZATO: chiamarla
9431
+ * con `select = true` su righe già selezionate non le deseleziona.
9432
+ *
9433
+ * @param {any[]} items Righe da selezionare/deselezionare (ignorato se `all`)
9434
+ * @param {boolean} all Agisce sull'intera ricerca invece che sulle singole righe
9435
+ * @param {boolean} select `true` per selezionare, `false` per deselezionare
9436
+ * @param {boolean} emit Se `true` emette `onSelectionChanged`
9437
+ */
9438
+ setSelectionStatus(items, all, select, emit = false) {
9439
+ if (all) {
9440
+ if (this.SingleSelection()) {
9441
+ console.error('[es-table2] setSelectionStatus: la selezione totale non ha senso con [SingleSelection]');
9442
+ return;
9443
+ }
9444
+ if (!this.SelectAll()) {
9445
+ console.error("[es-table2] setSelectionStatus: impossibile impostare la selezione totale con [SelectAll] a false");
9446
+ return;
9447
+ }
9448
+ // Deselezionare tutto è esattamente `resetSelection`, che gestisce già l'emit
9449
+ if (!select) {
9450
+ this.resetSelection(emit);
9451
+ return;
9452
+ }
9453
+ this.selectEverythingState();
9454
+ }
9455
+ else {
9456
+ this.setRowsSelected(items, select);
9457
+ }
9458
+ const sel = this.currentSelection();
9459
+ if (emit)
9460
+ this.emitSelection(sel);
9461
+ else {
9462
+ this.changed();
9463
+ this.cdr.markForCheck();
9464
+ }
9465
+ }
9466
+ /**
9467
+ * Forza lo stato di selezione di un gruppo di righe. In modalità "tutto
9468
+ * selezionato" si lavora sulle ESCLUSIONI, come fa `toggleRow`: selezionare
9469
+ * significa toglierle dalle esclusioni, deselezionare aggiungerle.
9470
+ *
9471
+ * Il confronto passa da `selKey`, quindi funziona anche con la cache di selezione
9472
+ * attiva (righe rigenerate dal server) e con le righe aggiunte (`_localId`).
9473
+ */
9474
+ setRowsSelected(items, select) {
9475
+ if (this.SelectionDisabled())
9476
+ return;
9477
+ const rows = (items ?? []).filter(it => it != null && !it._sep && !it._group);
9478
+ if (rows.length === 0)
9479
+ return;
9480
+ const sel = this.currentSelection();
9481
+ if (this.SingleSelection()) {
9482
+ if (rows.length > 1)
9483
+ console.error('[es-table2] setSelectionStatus: con [SingleSelection] si imposta una riga alla volta, uso la prima');
9484
+ const only = rows[0];
9485
+ for (const r of this.selectableRows())
9486
+ r._selected = false;
9487
+ sel.all = false;
9488
+ sel.exclusions = [];
9489
+ sel.items = select ? [only] : [];
9490
+ only._selected = select;
9491
+ }
9492
+ else {
9493
+ for (const it of rows)
9494
+ it._selected = select;
9495
+ // Con `all` la lista di lavoro è quella delle esclusioni, e la riga ci deve
9496
+ // stare quando NON è selezionata: la condizione si inverte.
9497
+ const target = sel.all ? sel.exclusions : sel.items;
9498
+ const wantInTarget = sel.all ? !select : select;
9499
+ if (wantInTarget) {
9500
+ // aggiungo deduplicando per chiave, senza riscandire l'array a ogni push
9501
+ const have = new Set(target.map(i => this.selKey(i)));
9502
+ for (const it of rows) {
9503
+ const k = this.selKey(it);
9504
+ if (!have.has(k)) {
9505
+ have.add(k);
9506
+ target.push(it);
9507
+ }
9508
+ }
9509
+ }
9510
+ else {
9511
+ const drop = new Set(rows.map(i => this.selKey(i)));
9512
+ const kept = target.filter(i => !drop.has(this.selKey(i)));
9513
+ if (sel.all)
9514
+ sel.exclusions = kept;
9515
+ else
9516
+ sel.items = kept;
9517
+ }
9518
+ }
9519
+ this.selectionAnchor = rows[rows.length - 1];
9520
+ this.refreshSelectionCount(sel);
9521
+ this.syncGlobalCheck();
9522
+ }
9422
9523
  /**
9423
9524
  * Azzera la selezione corrente (voci, esclusioni e "tutto selezionato").
9424
9525
  * Come nell'originale l'evento NON viene emesso salvo richiesta esplicita.