1- import { jsxs as ne , jsx as T } from "react/jsx-runtime" ;
2- import pe , { useState as k , useMemo as ce , useCallback as y } from "react" ;
3- import he , { get as F , set as O , isEmpty as D , isNil as ae } from "lodash" ;
4- import de from "classnames" ;
5- import o from "prop-types" ;
6- import fe from "./FormChipCellView.mjs" ;
7- import { CHIP_OPTIONS as me } from "../../types.mjs" ;
8- import { CLICK as Ce , TAB as H , TAB_SHIFT as U } from "../../constants.mjs" ;
9- import { areArraysEqual as Ie } from "../../utils/common.util.mjs" ;
10- import { checkPatternsValidity as ge } from "../../utils/validation.util.mjs" ;
11- import { generateChipsList as ye } from "../../utils/generateChipsList.util.mjs" ;
12- import { uniquenessError as z } from "./formChipCell.util.mjs" ;
1+ import { jsxs as pe , jsx as T } from "react/jsx-runtime" ;
2+ import ce , { useState as k , useMemo as he , useCallback as y } from "react" ;
3+ import ae , { get as F , set as O , isEmpty as D , isNil as de } from "lodash" ;
4+ import fe from "classnames" ;
5+ import r from "prop-types" ;
6+ import me from "./FormChipCellView.mjs" ;
7+ import { CHIP_OPTIONS as Ce } from "../../types.mjs" ;
8+ import { CLICK as Ie , TAB as H , TAB_SHIFT as U } from "../../constants.mjs" ;
9+ import { areArraysEqual as ge } from "../../utils/common.util.mjs" ;
10+ import { checkPatternsValidity as ye } from "../../utils/validation.util.mjs" ;
11+ import { generateChipsList as Fe } from "../../utils/generateChipsList.util.mjs" ;
12+ import { uniquenessError as b } from "./formChipCell.util.mjs" ;
1313import "../../hooks/index.mjs" ;
1414/* empty css */
15- import { useChipCell as Fe } from "../../hooks/useChipCell.hook.mjs" ;
16- let R = ( {
17- chipOptions : B = {
15+ import { useChipCell as Ne } from "../../hooks/useChipCell.hook.mjs" ;
16+ let w = ( {
17+ chipOptions : z = {
1818 background : "purple" ,
1919 boldValue : ! 1 ,
2020 borderRadius : "primary" ,
2121 borderColor : "transparent" ,
2222 density : "dense" ,
2323 font : "purple"
2424 } ,
25- className : b = "" ,
25+ className : B = "" ,
2626 delimiter : _ = null ,
2727 formState : n ,
2828 initialValues : q ,
2929 isEditable : m = ! 1 ,
30- label : V = null ,
31- name : r ,
32- onClick : w = ( ) => {
30+ label : R = null ,
31+ name : o ,
32+ onClick : V = ( ) => {
3333 } ,
34- shortChips : $ = ! 1 ,
35- validationRules : v = { } ,
36- validator : x = null ,
3734 onExitEditModeCallback : d = null ,
38- visibleChipsMaxLength : I = null
35+ shortChips : W = ! 1 ,
36+ validationRules : P = { } ,
37+ validator : x = null ,
38+ visibleChipsMaxLength : I = null ,
39+ withInitialParentWidth : $ = ! 1
3940} ) => {
40- const W = de ( "chips" , b ) , [ X , Y ] = k ( ! 1 ) , {
41- chipsCellRef : A ,
42- chipsWrapperRef : G ,
43- handleShowElements : J ,
44- hiddenChipsCounterRef : L ,
45- hiddenChipsPopUpRef : Q ,
46- setChipsSizes : Z ,
41+ const X = fe ( "chips" , B ) , [ Y , A ] = k ( ! 1 ) , {
42+ chipsCellRef : G ,
43+ chipsWrapperRef : J ,
44+ handleShowElements : L ,
45+ hiddenChipsCounterRef : Q ,
46+ hiddenChipsPopUpRef : Z ,
47+ setChipsSizes : S ,
4748 setShowHiddenChips : K ,
48- showChips : S ,
49- showHiddenChips : P ,
49+ showChips : E ,
50+ showHiddenChips : v ,
5051 visibleChipsCount : j
51- } = Fe ( m , I ) , [ p , C ] = k ( {
52+ } = Ne ( m , I , $ ) , [ p , C ] = k ( {
5253 chipIndex : null ,
5354 isEdit : ! 1 ,
5455 isKeyFocused : ! 1 ,
5556 isValueFocused : ! 1 ,
5657 isNewChip : ! 1
5758 } ) ;
58- let E = ce ( ( ) => m || I === "all" ? {
59- visibleChips : F ( n . values , r ) ,
59+ let M = he ( ( ) => m || I === "all" ? {
60+ visibleChips : F ( n . values , o ) ,
6061 hiddenChips : [ ]
61- } : ye (
62- F ( n . values , r ) ,
62+ } : Fe (
63+ F ( n . values , o ) ,
6364 I || j
64- ) , [ I , m , j , n . values , r ] ) ;
65+ ) , [ I , m , j , n . values , o ] ) ;
6566 const N = y (
6667 ( e ) => {
67- Ie ( F ( q , r ) , e , [ "id" ] ) && O ( n . initialValues , r , e ) , n . form . mutators . setFieldState ( r , { modified : ! 0 } ) , n . form . mutators . setFieldState ( r , { touched : ! 0 } ) ;
68+ ge ( F ( q , o ) , e , [ "id" ] ) && O ( n . initialValues , o , e ) , n . form . mutators . setFieldState ( o , { modified : ! 0 } ) , n . form . mutators . setFieldState ( o , { touched : ! 0 } ) ;
6869 } ,
69- [ q , r , n ]
70- ) , M = y (
70+ [ q , o , n ]
71+ ) , ee = y (
7172 ( e , i ) => {
7273 var t ;
7374 const u = ( ( t = i . value ) == null ? void 0 : t . length ) || 0 ;
74- ! p . isEdit && ! p . chipIndex && n . form . mutators . push ( r , {
75+ ! p . isEdit && ! p . chipIndex && n . form . mutators . push ( o , {
7576 id : u + /* @__PURE__ */ new Date ( ) ,
7677 key : "" ,
7778 value : "" ,
7879 delimiter : _
79- } ) , P && K ( ! 1 ) , C ( {
80+ } ) , v && K ( ! 1 ) , C ( {
8081 chipIndex : u ,
8182 isEdit : ! 0 ,
8283 isKeyFocused : ! 0 ,
@@ -87,23 +88,23 @@ let R = ({
8788 [
8889 p . isEdit ,
8990 p . chipIndex ,
90- P ,
91+ v ,
9192 n . form . mutators ,
92- r ,
93+ o ,
9394 _ ,
9495 K
9596 ]
9697 ) , g = y (
9798 ( e , i , u , t = ! 1 ) => {
9899 N (
99- he . chain ( n ) . get ( [ "values" , r ] ) . filter ( ( s , l ) => l !== u ) . value ( )
100- ) , i . length === 1 ? n . form . change ( r , [ ] ) : i . remove ( u ) , d && d ( ) , e && ! t && e . stopPropagation ( ) ;
100+ ae . chain ( n ) . get ( [ "values" , o ] ) . filter ( ( s , l ) => l !== u ) . value ( )
101+ ) , i . length === 1 ? n . form . change ( o , [ ] ) : i . remove ( u ) , d && d ( ) , e && ! t && e . stopPropagation ( ) ;
101102 } ,
102- [ N , n , r , d ]
103- ) , ee = y (
103+ [ N , n , o , d ]
104+ ) , ie = y (
104105 ( e , i , u , t ) => {
105106 const { key : s , value : l } = i . value [ p . chipIndex ] , h = ! ! ( s != null && s . trim ( ) && ( l != null && l . trim ( ) ) ) ;
106- u === Ce ? ( h || g ( e , i , p . chipIndex , t ) , C ( {
107+ u === Ie ? ( h || g ( e , i , p . chipIndex , t ) , C ( {
107108 chipIndex : null ,
108109 isEdit : ! 1 ,
109110 isKeyFocused : ! 1 ,
@@ -127,30 +128,30 @@ let R = ({
127128 isValueFocused : ! c ,
128129 isNewChip : ! 1
129130 } ;
130- } ) ) , N ( F ( n . values , r ) ) , ( p . chipIndex > 0 && p . chipIndex < i . value . length - 1 || i . value . length > 1 && p . chipIndex === 0 && u !== U || i . value . length > 1 && p . chipIndex === i . value . length - 1 && u !== H ) && e && e . preventDefault ( ) ;
131+ } ) ) , N ( F ( n . values , o ) ) , ( p . chipIndex > 0 && p . chipIndex < i . value . length - 1 || i . value . length > 1 && p . chipIndex === 0 && u !== U || i . value . length > 1 && p . chipIndex === i . value . length - 1 && u !== H ) && e && e . preventDefault ( ) ;
131132 } ,
132133 [
133134 p . chipIndex ,
134135 N ,
135136 n . values ,
136- r ,
137+ o ,
137138 d ,
138139 g
139140 ]
140- ) , ie = y (
141+ ) , se = y (
141142 ( e , i , u ) => {
142143 if ( m ) {
143144 const { clientX : t , clientY : s } = e ;
144145 let l = ! 1 ;
145146 const h = ( a , c , f ) => {
146147 if ( f ) {
147148 const {
148- top : te ,
149- left : re ,
149+ top : re ,
150+ left : oe ,
150151 right : ue ,
151- bottom : oe
152+ bottom : ne
152153 } = f . getBoundingClientRect ( ) ;
153- return ! ( a > ue || a < re || c > oe || c < te ) ;
154+ return ! ( a > ue || a < oe || c > ne || c < re ) ;
154155 }
155156 } ;
156157 e . stopPropagation ( ) , e . target . nodeName !== "INPUT" ? e . target . firstElementChild && ( l = h (
@@ -165,78 +166,79 @@ let R = ({
165166 isValueFocused : ! l
166167 } ) ) ;
167168 }
168- w && w ( ) ;
169+ V && V ( ) ;
169170 } ,
170- [ m , w ]
171- ) , se = ( e ) => {
171+ [ m , V ]
172+ ) , le = ( e ) => {
172173 if ( ! e ) return null ;
173174 let i = [ ] ;
174175 const u = ( t , s ) => ! e . some ( ( { key : l } , h ) => t === l && h !== s ) ;
175- return D ( v ) || ( i = e . map ( ( t ) => {
176- const [ s , l ] = le ( t ) ;
176+ return D ( P ) || ( i = e . map ( ( t ) => {
177+ const [ s , l ] = te ( t ) ;
177178 return s && l ? { key : s , value : l } : s ? { key : s } : l ? { value : l } : null ;
178179 } ) ) , e . forEach ( ( t , s ) => {
179- u ( t . key , s ) || ( F ( i , [ s , "key" ] , ! 1 ) ? i . at ( s ) . key . push ( z ) : O ( i , [ s , "key" ] , [ z ] ) ) ;
180- } ) , D ( i ) && x && ( i = x ( e ) ) , i . every ( ( t ) => ae ( t ) ) ? null : i ;
181- } , le = ( { key : e , value : i , disabled : u } ) => {
180+ u ( t . key , s ) || ( F ( i , [ s , "key" ] , ! 1 ) ? i . at ( s ) . key . push ( b ) : O ( i , [ s , "key" ] , [ b ] ) ) ;
181+ } ) , D ( i ) && x && ( i = x ( e ) ) , i . every ( ( t ) => de ( t ) ) ? null : i ;
182+ } , te = ( { key : e , value : i , disabled : u } ) => {
182183 const t = ( s , l ) => {
183- const [ h , a ] = ge (
184- v [ l ] . filter ( ( f ) => f . pattern ) ,
184+ const [ h , a ] = ye (
185+ P [ l ] . filter ( ( f ) => f . pattern ) ,
185186 s
186187 ) ;
187188 return a ? null : h . filter ( ( f ) => ! f . isValid ) . map ( ( f ) => ( { name : f . name , label : f . label } ) ) ;
188189 } ;
189190 return u ? [ null , null ] : [ t ( e , "key" ) , t ( i , "value" ) ] ;
190191 } ;
191- return /* @__PURE__ */ ne ( "div" , { className : W , "data-testid" : `${ r } -chips` , children : [
192- V && /* @__PURE__ */ T ( "div" , { className : "chips__label" , children : V } ) ,
193- /* @__PURE__ */ T ( "div" , { className : V ? "chips__wrapper" : "" , children : /* @__PURE__ */ T (
194- fe ,
192+ return /* @__PURE__ */ pe ( "div" , { className : X , "data-testid" : `${ o } -chips` , children : [
193+ R && /* @__PURE__ */ T ( "div" , { className : "chips__label" , children : R } ) ,
194+ /* @__PURE__ */ T ( "div" , { className : R ? "chips__wrapper" : "" , children : /* @__PURE__ */ T (
195+ me ,
195196 {
196- chipOptions : B ,
197- chipSizeIsRecalculated : X ,
198- chips : E ,
197+ chipOptions : z ,
198+ chipSizeIsRecalculated : Y ,
199+ chips : M ,
199200 editConfig : p ,
200201 formState : n ,
201- handleAddNewChip : M ,
202- handleEditChip : ee ,
202+ handleAddNewChip : ee ,
203+ handleEditChip : ie ,
203204 handleRemoveChip : g ,
204- handleShowElements : J ,
205- handleToEditMode : ie ,
205+ handleShowElements : L ,
206+ handleToEditMode : se ,
206207 isEditable : m ,
207- name : r ,
208- ref : { chipsCellRef : A , chipsWrapperRef : G , hiddenChipsCounterRef : L , hiddenChipsPopUpRef : Q } ,
209- setChipSizeIsRecalculated : Y ,
210- setChipsSizes : Z ,
208+ name : o ,
209+ ref : { chipsCellRef : G , chipsWrapperRef : J , hiddenChipsCounterRef : Q , hiddenChipsPopUpRef : Z } ,
210+ setChipSizeIsRecalculated : A ,
211+ setChipsSizes : S ,
211212 setEditConfig : C ,
212- shortChips : $ ,
213- showChips : S ,
214- showHiddenChips : P ,
215- validateFields : se ,
216- validationRules : v
213+ shortChips : W ,
214+ showChips : E ,
215+ showHiddenChips : v ,
216+ validateFields : le ,
217+ validationRules : P
217218 }
218219 ) } )
219220 ] } ) ;
220221} ;
221- R . propTypes = {
222- chipOptions : me ,
223- className : o . string ,
224- delimiter : o . oneOfType ( [ o . string , o . element ] ) ,
225- formState : o . object . isRequired ,
226- initialValues : o . object . isRequired ,
227- isEditable : o . bool ,
228- label : o . string ,
229- name : o . string . isRequired ,
230- onClick : o . func ,
231- onExitEditModeCallback : o . func ,
232- shortChips : o . bool ,
233- validationRules : o . object ,
234- validator : o . func ,
235- visibleChipsMaxLength : o . oneOfType ( [ o . string , o . number ] )
222+ w . propTypes = {
223+ chipOptions : Ce ,
224+ className : r . string ,
225+ delimiter : r . oneOfType ( [ r . string , r . element ] ) ,
226+ formState : r . object . isRequired ,
227+ initialValues : r . object . isRequired ,
228+ isEditable : r . bool ,
229+ label : r . string ,
230+ name : r . string . isRequired ,
231+ onClick : r . func ,
232+ onExitEditModeCallback : r . func ,
233+ shortChips : r . bool ,
234+ validationRules : r . object ,
235+ validator : r . func ,
236+ visibleChipsMaxLength : r . oneOfType ( [ r . string , r . number ] ) ,
237+ withInitialParentWidth : r . bool
236238} ;
237- R = pe . memo ( R ) ;
238- const He = R ;
239+ w = ce . memo ( w ) ;
240+ const Ue = w ;
239241export {
240- He as default
242+ Ue as default
241243} ;
242244//# sourceMappingURL=FormChipCell.mjs.map
0 commit comments