@italia/transfer 1.0.0-alpha.9 → 1.0.0-beta.1

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # <it-transfer>
2
+
3
+ This package is part of [dev-kit-italia](https://italia.github.io/dev-kit-italia), a Web Components kit for the **.italia** design-system.
4
+
5
+ ## Installation and usage
6
+
7
+ Most users want to install the full kit by installing [`@italia/dev-kit-italia`](https://npmjs.com/package/@italia/dev-kit-italia), but you have the option of installing this single Web Component separately if needed. Please find detailed installation and usage instructions in the [official documentation](https://italia.github.io/dev-kit-italia/?path=/docs/introduzione--documentazione).
8
+
9
+ ## Documentation
10
+
11
+ Find the usage instructions for this specific component in its [dedicated documentation page](https://italia.github.io/dev-kit-italia/?path=/docs/componenti-form-transfer--documentazione).
@@ -347,7 +347,7 @@
347
347
  "privacy": "private",
348
348
  "return": {
349
349
  "type": {
350
- "text": "boolean"
350
+ "text": "void"
351
351
  }
352
352
  },
353
353
  "parameters": [
@@ -374,6 +374,12 @@
374
374
  "type": {
375
375
  "text": "TransferItemData[]"
376
376
  }
377
+ },
378
+ {
379
+ "name": "defaultAction",
380
+ "type": {
381
+ "text": "() => void"
382
+ }
377
383
  }
378
384
  ]
379
385
  },
@@ -392,6 +398,24 @@
392
398
  "name": "reset",
393
399
  "description": "Reset both lists to their initial state."
394
400
  },
401
+ {
402
+ "kind": "method",
403
+ "name": "commit",
404
+ "return": {
405
+ "type": {
406
+ "text": "void"
407
+ }
408
+ },
409
+ "parameters": [
410
+ {
411
+ "name": "detail",
412
+ "type": {
413
+ "text": "TransferEventDetail"
414
+ }
415
+ }
416
+ ],
417
+ "description": "Applies the proposed state from a previously cancelled `it-transfer` event,\nwithout re-dispatching the event.\n\nUse this after calling `event.preventDefault()` in an `it-transfer` listener\nto resume the action once your async logic (validation, confirmation, etc.) resolves:\n\n```js\nel.addEventListener('it-transfer', async (e) => {\n e.preventDefault();\n const ok = await confirm('Procedere con il trasferimento?');\n if (ok) el.commit(e.detail);\n});\n```"
418
+ },
395
419
  {
396
420
  "kind": "method",
397
421
  "name": "_toggleItem",
@@ -556,10 +580,6 @@
556
580
  },
557
581
  "tagName": "it-transfer",
558
582
  "customElement": true
559
- },
560
- {
561
- "kind": "variable",
562
- "name": "items"
563
583
  }
564
584
  ],
565
585
  "exports": [
@@ -597,7 +617,7 @@
597
617
  "type": {
598
618
  "text": "Meta<TransferProps>"
599
619
  },
600
- "default": "{ title: 'Componenti/Form/Transfer', tags: ['a11y-ok', 'web-component', 'alpha'], component: 'it-transfer', args: { name: 'transfer-items', sourceLabel: '', targetLabel: '', disabled: false, required: false, customValidation: false, validityMessage: '', }, argTypes: { name: { control: 'text', description: 'Il nome del campo nel form, usato nella sottomissione.', }, sourceLabel: { control: 'text', description: 'Etichetta descrittiva per la lista sorgente (sinistra). Sovrascrive il default i18n.', name: 'source-label', table: { defaultValue: { summary: 'Sorgente' } }, }, targetLabel: { control: 'text', description: 'Etichetta descrittiva per la lista destinazione (destra). Sovrascrive il default i18n.', name: 'target-label', table: { defaultValue: { summary: 'Destinazione' } }, }, disabled: { control: 'boolean', description: 'Disabilita il componente.', table: { defaultValue: { summary: 'false' } }, }, required: { control: 'boolean', description: 'Rende il campo obbligatorio: la lista destinazione non può essere vuota alla sottomissione del form.', table: { defaultValue: { summary: 'false' } }, }, customValidation: { control: 'boolean', description: 'Disabilita la validazione nativa e usa `validity-message` per mostrare un errore personalizzato.', name: 'custom-validation', table: { defaultValue: { summary: 'false' } }, }, validityMessage: { control: 'text', description: 'Messaggio di errore personalizzato (richiede `custom-validation`).', name: 'validity-message', table: { defaultValue: { summary: '' } }, }, }, parameters: { layout: 'padded', pageLayout: 'w-100', docs: { canvas: { sourceState: 'shown' }, }, }, }"
620
+ "default": "{ title: 'Componenti/Form/Transfer', tags: ['a11y-ok', 'web-component'], component: 'it-transfer', args: { name: 'transfer-items', sourceLabel: '', targetLabel: '', disabled: false, required: false, customValidation: false, validityMessage: '', }, argTypes: { name: { control: 'text', description: 'Il nome del campo nel form, usato nella sottomissione.', }, sourceLabel: { control: 'text', description: 'Etichetta descrittiva per la lista sorgente (sinistra). Sovrascrive il default i18n.', name: 'source-label', table: { defaultValue: { summary: 'Sorgente' } }, }, targetLabel: { control: 'text', description: 'Etichetta descrittiva per la lista destinazione (destra). Sovrascrive il default i18n.', name: 'target-label', table: { defaultValue: { summary: 'Destinazione' } }, }, disabled: { control: 'boolean', description: 'Disabilita il componente.', table: { defaultValue: { summary: 'false' } }, }, required: { control: 'boolean', description: 'Rende il campo obbligatorio: la lista destinazione non può essere vuota alla sottomissione del form.', table: { defaultValue: { summary: 'false' } }, }, customValidation: { control: 'boolean', description: 'Disabilita la validazione nativa e usa `validity-message` per mostrare un errore personalizzato.', name: 'custom-validation', table: { defaultValue: { summary: 'false' } }, }, validityMessage: { control: 'text', description: 'Messaggio di errore personalizzato (richiede `custom-validation`).', name: 'validity-message', table: { defaultValue: { summary: '' } }, }, }, parameters: { layout: 'padded', pageLayout: 'w-100', docs: { canvas: { sourceState: 'shown' }, }, }, }"
601
621
  },
602
622
  {
603
623
  "kind": "variable",
@@ -671,13 +691,29 @@
671
691
  },
672
692
  "default": "{ name: 'i18n', tags: ['!dev'], render: () => html`<div class=\"hide-preview\"></div>`, parameters: { viewMode: 'docs', docs: { description: { story: ` Per questo componente sono disponibili alcune stringhe traducibili tramite l'[utility di internazionalizzazione](/docs/i18n-internazionalizzazione--documentazione). \\`\\`\\`js const translation = ${JSON.stringify(i18nIT, null, 2)} \\`\\`\\` `, }, }, }, }"
673
693
  },
694
+ {
695
+ "kind": "variable",
696
+ "name": "EventoAnnullabile",
697
+ "type": {
698
+ "text": "Story"
699
+ },
700
+ "default": "{ name: 'Evento annullabile', parameters: { docs: { description: { story: `L'evento \\`it-transfer\\` è annullabile. Chiamando \\`event.preventDefault()\\` puoi bloccare l'azione in corso (transfer, backtransfer, reset) ed eseguire una logica di validazione personalizzata. Questo esempio mostra come bloccare il trasferimento quando il numero di elementi nella lista di destinazione supererebbe il limite di 3 elementi. Per riprendere l'azione dopo logica asincrona (validazione remota, conferma dell'utente), usa il metodo pubblico \\`commit(event.detail)\\`. Vedi la sezione dedicata per un esempio completo.`, }, }, }, render: () => html` <div id=\"transfer-cancelable-example\"> <it-transfer name=\"max-items-transfer\"> <it-transfer-item value=\"a\">Voce A</it-transfer-item> <it-transfer-item value=\"b\">Voce B</it-transfer-item> <it-transfer-item value=\"c\">Voce C</it-transfer-item> <it-transfer-item value=\"d\">Voce D</it-transfer-item> <it-transfer-item value=\"e\">Voce E</it-transfer-item> <it-transfer-item value=\"f\">Voce F</it-transfer-item> </it-transfer> <p role=\"status\" aria-live=\"polite\" style=\"margin-top: 1rem; color: #d32f2f;\"></p> </div> <script> const el = document.querySelector('#transfer-cancelable-example it-transfer'); const statusEl = document.querySelector('#transfer-cancelable-example p[role=\"status\"]'); el.addEventListener('it-transfer', (e) => { if (e.detail.action === 'transfer' && e.detail.target.length > 3) { e.preventDefault(); statusEl.textContent = 'Limite di 3 elementi nel target raggiunto.'; } else { statusEl.textContent = ''; } }); </script> `, }"
701
+ },
702
+ {
703
+ "kind": "variable",
704
+ "name": "EventoAnnullabileConRipresa",
705
+ "type": {
706
+ "text": "Story"
707
+ },
708
+ "default": "{ name: 'Evento annullabile con ripresa', parameters: { docs: { description: { story: `Chiama \\`event.preventDefault()\\` per bloccare l'azione, poi usa il metodo pubblico \\`commit(event.detail)\\` per applicarla in modo programmatico dopo la tua logica asincrona — senza rieseguire l'evento.`, }, }, }, render: () => html` <div id=\"transfer-resume-example\"> <it-transfer name=\"resume-transfer\"> <it-transfer-item value=\"a\">Voce A</it-transfer-item> <it-transfer-item value=\"b\">Voce B</it-transfer-item> <it-transfer-item value=\"c\">Voce C</it-transfer-item> <it-transfer-item value=\"d\">Voce D</it-transfer-item> </it-transfer> <p role=\"status\" aria-live=\"polite\" id=\"transfer-resume-status\" style=\"margin-top: 1rem;\"></p> </div> <script> const el2 = document.querySelector('#transfer-resume-example it-transfer'); const statusEl2 = document.querySelector('#transfer-resume-status'); el2.addEventListener('it-transfer', (e) => { if (e.detail.action === 'transfer') { e.preventDefault(); statusEl2.textContent = 'Attendere conferma…'; // Simula logica asincrona (es. chiamata API, conferma utente) setTimeout(() => { el2.commit(e.detail); // applica lo stato proposto senza rieseguire l'evento statusEl2.textContent = ''; }, 4000); } }); </script> `, }"
709
+ },
674
710
  {
675
711
  "kind": "variable",
676
712
  "name": "MetodiEPropPubblici",
677
713
  "type": {
678
714
  "text": "Story"
679
715
  },
680
- "default": "{ ...StoryFormControlMethodAndProps({ componentName: 'it-transfer', otherProps: `|\\`value\\`| Array JSON dei valori degli elementi presenti nella lista destinazione. |`, otherEvents: `|\\`it-transfer\\`| Emesso prima di ogni azione (transfer, backtransfer, reset). Annullabile con \\`event.preventDefault()\\`. Detail: \\`{ action, items, source, target }\\`. |`, }), tags: ['!dev'], }"
716
+ "default": "{ ...StoryFormControlMethodAndProps({ componentName: 'it-transfer', otherProps: `|\\`value\\`| Array JSON dei valori degli elementi presenti nella lista destinazione. |`, otherMethods: `|\\`transfer()\\`| Sposta gli elementi selezionati dalla lista sorgente alla lista destinazione. Equivale al click sul pulsante →. | - | |\\`backtransfer()\\`| Riporta gli elementi selezionati dalla lista destinazione alla lista sorgente. Equivale al click sul pulsante ←. | - | |\\`reset()\\`| Ripristina entrambe le liste allo stato iniziale. Equivale al click sul pulsante ↺. | - | |\\`commit(detail)\\`| Applica lo stato proposto da un evento \\`it-transfer\\` precedentemente annullato, senza rieseguire l'evento. Usare dopo \\`event.preventDefault()\\` per riprendere l'azione in modo programmatico. | detail: \\`TransferEventDetail\\` |`, otherEvents: `|\\`it-transfer\\`| Emesso prima di ogni azione (transfer, backtransfer, reset). Annullabile con \\`event.preventDefault()\\`. Il \\`detail\\` contiene \\`{ action, items, source, target }\\` che descrive lo stato proposto. | |\\`it-change\\`| Emesso dopo ogni modifica delle liste. Il \\`detail\\` contiene \\`{ value, el }\\`. |`, }), tags: ['!dev'], }"
681
717
  }
682
718
  ],
683
719
  "exports": [
@@ -761,6 +797,22 @@
761
797
  "module": "stories/it-transfer.stories.ts"
762
798
  }
763
799
  },
800
+ {
801
+ "kind": "js",
802
+ "name": "EventoAnnullabile",
803
+ "declaration": {
804
+ "name": "EventoAnnullabile",
805
+ "module": "stories/it-transfer.stories.ts"
806
+ }
807
+ },
808
+ {
809
+ "kind": "js",
810
+ "name": "EventoAnnullabileConRipresa",
811
+ "declaration": {
812
+ "name": "EventoAnnullabileConRipresa",
813
+ "module": "stories/it-transfer.stories.ts"
814
+ }
815
+ },
764
816
  {
765
817
  "kind": "js",
766
818
  "name": "MetodiEPropPubblici",
@@ -1,4 +1,5 @@
1
1
  import { FormControl, FormControlController } from '@italia/globals';
2
+ import type { TransferEventDetail } from './types.js';
2
3
  /**
3
4
  * A dual-list transfer component that allows moving items between a source and a target list.
4
5
  * Integrates with native `<form>` elements via the FormControl API.
@@ -44,6 +45,22 @@ export declare class ItTransfer extends FormControl {
44
45
  backtransfer(): void;
45
46
  /** Reset both lists to their initial state. */
46
47
  reset(): void;
48
+ /**
49
+ * Applies the proposed state from a previously cancelled `it-transfer` event,
50
+ * without re-dispatching the event.
51
+ *
52
+ * Use this after calling `event.preventDefault()` in an `it-transfer` listener
53
+ * to resume the action once your async logic (validation, confirmation, etc.) resolves:
54
+ *
55
+ * ```js
56
+ * el.addEventListener('it-transfer', async (e) => {
57
+ * e.preventDefault();
58
+ * const ok = await confirm('Procedere con il trasferimento?');
59
+ * if (ok) el.commit(e.detail);
60
+ * });
61
+ * ```
62
+ */
63
+ commit(detail: TransferEventDetail): void;
47
64
  private _toggleItem;
48
65
  private _toggleAll;
49
66
  private _getHeaderState;
@@ -1 +1 @@
1
- {"version":3,"file":"it-transfer.d.ts","sourceRoot":"","sources":["../../src/it-transfer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB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