@wordpress/dataviews 9.0.1-next.6f42e1382.0 → 9.1.1-next.f56bd8138.0

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.
Files changed (201) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/README.md +107 -11
  3. package/build/components/dataviews-filters/input-widget.js +48 -4
  4. package/build/components/dataviews-filters/input-widget.js.map +1 -1
  5. package/build/components/dataviews-view-config/index.js +22 -3
  6. package/build/components/dataviews-view-config/index.js.map +1 -1
  7. package/build/dataform-controls/array.js +117 -29
  8. package/build/dataform-controls/array.js.map +1 -1
  9. package/build/dataform-controls/checkbox.js +31 -20
  10. package/build/dataform-controls/checkbox.js.map +1 -1
  11. package/build/dataform-controls/color.js +29 -24
  12. package/build/dataform-controls/color.js.map +1 -1
  13. package/build/dataform-controls/date.js +32 -24
  14. package/build/dataform-controls/date.js.map +1 -1
  15. package/build/dataform-controls/datetime.js +133 -19
  16. package/build/dataform-controls/datetime.js.map +1 -1
  17. package/build/dataform-controls/email.js +7 -1
  18. package/build/dataform-controls/email.js.map +1 -1
  19. package/build/dataform-controls/index.js +23 -0
  20. package/build/dataform-controls/index.js.map +1 -1
  21. package/build/dataform-controls/integer.js +47 -34
  22. package/build/dataform-controls/integer.js.map +1 -1
  23. package/build/dataform-controls/radio.js +42 -9
  24. package/build/dataform-controls/radio.js.map +1 -1
  25. package/build/dataform-controls/relative-date-control.js +6 -10
  26. package/build/dataform-controls/relative-date-control.js.map +1 -1
  27. package/build/dataform-controls/select.js +41 -10
  28. package/build/dataform-controls/select.js.map +1 -1
  29. package/build/dataform-controls/telephone.js +7 -1
  30. package/build/dataform-controls/telephone.js.map +1 -1
  31. package/build/dataform-controls/text.js +14 -2
  32. package/build/dataform-controls/text.js.map +1 -1
  33. package/build/dataform-controls/textarea.js +33 -20
  34. package/build/dataform-controls/textarea.js.map +1 -1
  35. package/build/dataform-controls/toggle-group.js +36 -6
  36. package/build/dataform-controls/toggle-group.js.map +1 -1
  37. package/build/dataform-controls/toggle.js +33 -22
  38. package/build/dataform-controls/toggle.js.map +1 -1
  39. package/build/dataform-controls/url.js +7 -1
  40. package/build/dataform-controls/url.js.map +1 -1
  41. package/build/dataform-controls/utils/validated-input.js +34 -32
  42. package/build/dataform-controls/utils/validated-input.js.map +1 -1
  43. package/build/dataforms-layouts/panel/dropdown.js +10 -14
  44. package/build/dataforms-layouts/panel/dropdown.js.map +1 -1
  45. package/build/dataforms-layouts/panel/index.js +24 -11
  46. package/build/dataforms-layouts/panel/index.js.map +1 -1
  47. package/build/dataforms-layouts/panel/modal.js +22 -27
  48. package/build/dataforms-layouts/panel/modal.js.map +1 -1
  49. package/build/dataforms-layouts/panel/summary-button.js +67 -0
  50. package/build/dataforms-layouts/panel/summary-button.js.map +1 -0
  51. package/build/field-types/array.js +0 -6
  52. package/build/field-types/array.js.map +1 -1
  53. package/build/index.js +7 -0
  54. package/build/index.js.map +1 -1
  55. package/build/normalize-fields.js +17 -0
  56. package/build/normalize-fields.js.map +1 -1
  57. package/build/types.js.map +1 -1
  58. package/build/validation.js +18 -1
  59. package/build/validation.js.map +1 -1
  60. package/build-module/components/dataviews-filters/input-widget.js +48 -4
  61. package/build-module/components/dataviews-filters/input-widget.js.map +1 -1
  62. package/build-module/components/dataviews-view-config/index.js +22 -3
  63. package/build-module/components/dataviews-view-config/index.js.map +1 -1
  64. package/build-module/dataform-controls/array.js +120 -32
  65. package/build-module/dataform-controls/array.js.map +1 -1
  66. package/build-module/dataform-controls/checkbox.js +31 -21
  67. package/build-module/dataform-controls/checkbox.js.map +1 -1
  68. package/build-module/dataform-controls/color.js +28 -24
  69. package/build-module/dataform-controls/color.js.map +1 -1
  70. package/build-module/dataform-controls/date.js +32 -24
  71. package/build-module/dataform-controls/date.js.map +1 -1
  72. package/build-module/dataform-controls/datetime.js +135 -21
  73. package/build-module/dataform-controls/datetime.js.map +1 -1
  74. package/build-module/dataform-controls/email.js +7 -1
  75. package/build-module/dataform-controls/email.js.map +1 -1
  76. package/build-module/dataform-controls/index.js +23 -0
  77. package/build-module/dataform-controls/index.js.map +1 -1
  78. package/build-module/dataform-controls/integer.js +46 -34
  79. package/build-module/dataform-controls/integer.js.map +1 -1
  80. package/build-module/dataform-controls/radio.js +44 -11
  81. package/build-module/dataform-controls/radio.js.map +1 -1
  82. package/build-module/dataform-controls/relative-date-control.js +6 -10
  83. package/build-module/dataform-controls/relative-date-control.js.map +1 -1
  84. package/build-module/dataform-controls/select.js +43 -12
  85. package/build-module/dataform-controls/select.js.map +1 -1
  86. package/build-module/dataform-controls/telephone.js +7 -1
  87. package/build-module/dataform-controls/telephone.js.map +1 -1
  88. package/build-module/dataform-controls/text.js +14 -2
  89. package/build-module/dataform-controls/text.js.map +1 -1
  90. package/build-module/dataform-controls/textarea.js +32 -20
  91. package/build-module/dataform-controls/textarea.js.map +1 -1
  92. package/build-module/dataform-controls/toggle-group.js +38 -8
  93. package/build-module/dataform-controls/toggle-group.js.map +1 -1
  94. package/build-module/dataform-controls/toggle.js +33 -23
  95. package/build-module/dataform-controls/toggle.js.map +1 -1
  96. package/build-module/dataform-controls/url.js +7 -1
  97. package/build-module/dataform-controls/url.js.map +1 -1
  98. package/build-module/dataform-controls/utils/validated-input.js +34 -33
  99. package/build-module/dataform-controls/utils/validated-input.js.map +1 -1
  100. package/build-module/dataforms-layouts/panel/dropdown.js +10 -15
  101. package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -1
  102. package/build-module/dataforms-layouts/panel/index.js +24 -11
  103. package/build-module/dataforms-layouts/panel/index.js.map +1 -1
  104. package/build-module/dataforms-layouts/panel/modal.js +22 -28
  105. package/build-module/dataforms-layouts/panel/modal.js.map +1 -1
  106. package/build-module/dataforms-layouts/panel/summary-button.js +60 -0
  107. package/build-module/dataforms-layouts/panel/summary-button.js.map +1 -0
  108. package/build-module/field-types/array.js +0 -6
  109. package/build-module/field-types/array.js.map +1 -1
  110. package/build-module/index.js +1 -0
  111. package/build-module/index.js.map +1 -1
  112. package/build-module/normalize-fields.js +15 -0
  113. package/build-module/normalize-fields.js.map +1 -1
  114. package/build-module/types.js.map +1 -1
  115. package/build-module/validation.js +18 -1
  116. package/build-module/validation.js.map +1 -1
  117. package/build-types/components/dataform/stories/index.story.d.ts +3 -0
  118. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
  119. package/build-types/components/dataviews/stories/fixtures.d.ts +4 -2
  120. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
  121. package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
  122. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  123. package/build-types/dataform-controls/array.d.ts.map +1 -1
  124. package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
  125. package/build-types/dataform-controls/color.d.ts.map +1 -1
  126. package/build-types/dataform-controls/date.d.ts.map +1 -1
  127. package/build-types/dataform-controls/datetime.d.ts.map +1 -1
  128. package/build-types/dataform-controls/email.d.ts.map +1 -1
  129. package/build-types/dataform-controls/index.d.ts +1 -1
  130. package/build-types/dataform-controls/index.d.ts.map +1 -1
  131. package/build-types/dataform-controls/integer.d.ts.map +1 -1
  132. package/build-types/dataform-controls/radio.d.ts.map +1 -1
  133. package/build-types/dataform-controls/relative-date-control.d.ts +6 -5
  134. package/build-types/dataform-controls/relative-date-control.d.ts.map +1 -1
  135. package/build-types/dataform-controls/select.d.ts.map +1 -1
  136. package/build-types/dataform-controls/telephone.d.ts.map +1 -1
  137. package/build-types/dataform-controls/text.d.ts +1 -1
  138. package/build-types/dataform-controls/text.d.ts.map +1 -1
  139. package/build-types/dataform-controls/textarea.d.ts +1 -1
  140. package/build-types/dataform-controls/textarea.d.ts.map +1 -1
  141. package/build-types/dataform-controls/toggle-group.d.ts.map +1 -1
  142. package/build-types/dataform-controls/toggle.d.ts.map +1 -1
  143. package/build-types/dataform-controls/url.d.ts.map +1 -1
  144. package/build-types/dataform-controls/utils/validated-input.d.ts +4 -4
  145. package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -1
  146. package/build-types/dataforms-layouts/panel/dropdown.d.ts +2 -1
  147. package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -1
  148. package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
  149. package/build-types/dataforms-layouts/panel/modal.d.ts +2 -1
  150. package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -1
  151. package/build-types/dataforms-layouts/panel/summary-button.d.ts +15 -0
  152. package/build-types/dataforms-layouts/panel/summary-button.d.ts.map +1 -0
  153. package/build-types/field-types/array.d.ts.map +1 -1
  154. package/build-types/field-types/stories/index.story.d.ts.map +1 -1
  155. package/build-types/index.d.ts +1 -0
  156. package/build-types/index.d.ts.map +1 -1
  157. package/build-types/normalize-fields.d.ts +3 -0
  158. package/build-types/normalize-fields.d.ts.map +1 -1
  159. package/build-types/types.d.ts +68 -4
  160. package/build-types/types.d.ts.map +1 -1
  161. package/build-types/validation.d.ts.map +1 -1
  162. package/build-wp/index.js +2009 -1489
  163. package/package.json +16 -15
  164. package/src/components/dataform/stories/index.story.tsx +509 -8
  165. package/src/components/dataviews/stories/fixtures.tsx +99 -41
  166. package/src/components/dataviews/stories/index.story.tsx +1 -1
  167. package/src/components/dataviews-filters/input-widget.tsx +44 -5
  168. package/src/components/dataviews-picker/stories/index.story.tsx +1 -1
  169. package/src/components/dataviews-view-config/index.tsx +18 -3
  170. package/src/dataform-controls/array.tsx +139 -44
  171. package/src/dataform-controls/checkbox.tsx +41 -24
  172. package/src/dataform-controls/color.tsx +33 -24
  173. package/src/dataform-controls/date.tsx +47 -21
  174. package/src/dataform-controls/datetime.tsx +171 -23
  175. package/src/dataform-controls/email.tsx +9 -1
  176. package/src/dataform-controls/index.tsx +26 -0
  177. package/src/dataform-controls/integer.tsx +82 -49
  178. package/src/dataform-controls/radio.tsx +53 -11
  179. package/src/dataform-controls/relative-date-control.tsx +11 -10
  180. package/src/dataform-controls/select.tsx +53 -10
  181. package/src/dataform-controls/telephone.tsx +9 -1
  182. package/src/dataform-controls/text.tsx +18 -1
  183. package/src/dataform-controls/textarea.tsx +38 -24
  184. package/src/dataform-controls/toggle-group.tsx +50 -10
  185. package/src/dataform-controls/toggle.tsx +41 -24
  186. package/src/dataform-controls/url.tsx +9 -1
  187. package/src/dataform-controls/utils/validated-input.tsx +50 -50
  188. package/src/dataforms-layouts/panel/dropdown.tsx +12 -23
  189. package/src/dataforms-layouts/panel/index.tsx +39 -16
  190. package/src/dataforms-layouts/panel/modal.tsx +24 -30
  191. package/src/dataforms-layouts/panel/summary-button.tsx +92 -0
  192. package/src/field-types/array.tsx +0 -8
  193. package/src/field-types/stories/index.story.tsx +89 -1
  194. package/src/index.ts +1 -0
  195. package/src/normalize-fields.ts +18 -0
  196. package/src/test/filter-and-sort-data-view.js +148 -138
  197. package/src/test/normalize-fields.ts +114 -0
  198. package/src/test/validation.ts +192 -0
  199. package/src/types.ts +75 -4
  200. package/src/validation.ts +30 -0
  201. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_i18n","_element","_dataFormLayout","_isCombinedField","_normalizeFormFields","_jsxRuntime","ModalContent","data","form","fieldLabel","onChange","onClose","changes","setChanges","useState","onApply","handleOnChange","value","prev","displayData","jsxs","Modal","className","onRequestClose","isFullScreen","title","size","children","jsx","DataFormLayout","FieldLayout","nestedField","_form$fields","field","hideLabelFromVision","fields","length","id","__experimentalHStack","spacing","__experimentalSpacer","Button","variant","onClick","__next40pxDefaultSize","__","PanelModal","fieldDefinition","labelPosition","isOpen","setIsOpen","isCombinedField","label","useMemo","layout","DEFAULT_LAYOUT","Fragment","includes","sprintf","_x","disabled","readOnly","accessibleWhenDisabled","render","item","_default","exports","default"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/modal.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n\tButton,\n\tModal,\n} from '@wordpress/components';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { Form, FormField, NormalizedField } from '../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { isCombinedField } from '../is-combined-field';\nimport { DEFAULT_LAYOUT } from '../../normalize-form-fields';\n\nfunction ModalContent< Item >( {\n\tdata,\n\tform,\n\tfieldLabel,\n\tonChange,\n\tonClose,\n}: {\n\tdata: Item;\n\tform: Form;\n\tfieldLabel: string;\n\tonChange: ( data: Partial< Item > ) => void;\n\tonClose: () => void;\n} ) {\n\tconst [ changes, setChanges ] = useState< Partial< Item > >( {} );\n\n\tconst onApply = () => {\n\t\tonChange( changes );\n\t\tonClose();\n\t};\n\n\tconst handleOnChange = ( value: Partial< Item > ) => {\n\t\tsetChanges( ( prev ) => ( { ...prev, ...value } ) );\n\t};\n\n\t// Merge original data with local changes for display\n\tconst displayData = { ...data, ...changes };\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"dataforms-layouts-panel__modal\"\n\t\t\tonRequestClose={ onClose }\n\t\t\tisFullScreen={ false }\n\t\t\ttitle={ fieldLabel }\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<DataFormLayout\n\t\t\t\tdata={ displayData }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ handleOnChange }\n\t\t\t>\n\t\t\t\t{ ( FieldLayout, nestedField ) => (\n\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\tkey={ nestedField.id }\n\t\t\t\t\t\tdata={ displayData }\n\t\t\t\t\t\tfield={ nestedField }\n\t\t\t\t\t\tonChange={ handleOnChange }\n\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</DataFormLayout>\n\t\t\t<HStack\n\t\t\t\tclassName=\"dataforms-layouts-panel__modal-footer\"\n\t\t\t\tspacing={ 3 }\n\t\t\t>\n\t\t\t\t<Spacer />\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\tonClick={ onApply }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Apply' ) }\n\t\t\t\t</Button>\n\t\t\t</HStack>\n\t\t</Modal>\n\t);\n}\n\nfunction PanelModal< Item >( {\n\tfieldDefinition,\n\tlabelPosition,\n\tdata,\n\tonChange,\n\tfield,\n}: {\n\tfieldDefinition: NormalizedField< Item >;\n\tlabelPosition: 'side' | 'top' | 'none';\n\tdata: Item;\n\tonChange: ( value: any ) => void;\n\tfield: FormField;\n} ) {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\n\tconst fieldLabel = isCombinedField( field )\n\t\t? field.label\n\t\t: fieldDefinition?.label;\n\n\tconst form: Form = useMemo(\n\t\t(): Form => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: isCombinedField( field )\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tclassName=\"dataforms-layouts-modal__field-control\"\n\t\t\t\tsize=\"compact\"\n\t\t\t\tvariant={\n\t\t\t\t\t[ 'none', 'top' ].includes( labelPosition )\n\t\t\t\t\t\t? 'link'\n\t\t\t\t\t\t: 'tertiary'\n\t\t\t\t}\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t// translators: %s: Field name.\n\t\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\t\tfieldLabel || ''\n\t\t\t\t) }\n\t\t\t\tonClick={ () => setIsOpen( true ) }\n\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t>\n\t\t\t\t<fieldDefinition.render\n\t\t\t\t\titem={ data }\n\t\t\t\t\tfield={ fieldDefinition }\n\t\t\t\t/>\n\t\t\t</Button>\n\t\t\t{ isOpen && (\n\t\t\t\t<ModalContent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tform={ form as Form }\n\t\t\t\t\tfieldLabel={ fieldLabel ?? '' }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ () => setIsOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PanelModal;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAMA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AAA6D,IAAAM,WAAA,GAAAN,OAAA;AAlB7D;AACA;AACA;;AAUA;AACA;AACA;;AAMA,SAASO,YAAYA,CAAU;EAC9BC,IAAI;EACJC,IAAI;EACJC,UAAU;EACVC,QAAQ;EACRC;AAOD,CAAC,EAAG;EACH,MAAM,CAAEC,OAAO,EAAEC,UAAU,CAAE,GAAG,IAAAC,iBAAQ,EAAqB,CAAC,CAAE,CAAC;EAEjE,MAAMC,OAAO,GAAGA,CAAA,KAAM;IACrBL,QAAQ,CAAEE,OAAQ,CAAC;IACnBD,OAAO,CAAC,CAAC;EACV,CAAC;EAED,MAAMK,cAAc,GAAKC,KAAsB,IAAM;IACpDJ,UAAU,CAAIK,IAAI,KAAQ;MAAE,GAAGA,IAAI;MAAE,GAAGD;IAAM,CAAC,CAAG,CAAC;EACpD,CAAC;;EAED;EACA,MAAME,WAAW,GAAG;IAAE,GAAGZ,IAAI;IAA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CAAE,IAAK,CAAG;MACnCU,QAAQ,EAAGb,eAAe,CAACc,QAAQ,KAAK,IAAM;MAC9CC,sBAAsB;MAAAnC,QAAA,eAEtB,IAAAtB,WAAA,CAAAuB,GAAA,EAACmB,eAAe,CAACgB,MAAM;QACtBC,IAAI,EAAGzD,IAAM;QACb0B,KAAK,EAAGc;MAAiB,CACzB;IAAC,CACK,CAAC,EACPE,MAAM,iBACP,IAAA5C,WAAA,CAAAuB,GAAA,EAACtB,YAAY;MACZC,IAAI,EAAGA,IAAM;MACbC,IAAI,EAAGA,IAAc;MACrBC,UAAU,EAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,EAAI;MAC/BC,QAAQ,EAAGA,QAAU;MACrBC,OAAO,EAAGA,CAAA,KAAMuC,SAAS,CAAE,KAAM;IAAG,CACpC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAe,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcrB,UAAU","ignoreList":[]}
1
+ {"version":3,"names":["_deepmerge","_interopRequireDefault","require","_components","_i18n","_element","_dataFormLayout","_isCombinedField","_normalizeFormFields","_summaryButton","_jsxRuntime","ModalContent","data","form","fieldLabel","onChange","onClose","changes","setChanges","useState","modalData","useMemo","deepMerge","onApply","handleOnChange","newValue","prev","jsxs","Modal","className","onRequestClose","isFullScreen","title","size","children","jsx","DataFormLayout","FieldLayout","nestedField","_form$fields","field","hideLabelFromVision","fields","length","id","__experimentalHStack","spacing","__experimentalSpacer","Button","variant","onClick","__next40pxDefaultSize","__","PanelModal","fieldDefinition","summaryFields","labelPosition","isOpen","setIsOpen","isCombinedField","label","layout","DEFAULT_LAYOUT","Fragment","default","disabled","readOnly","_default","exports"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/modal.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n\tButton,\n\tModal,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { Form, FormField, NormalizedField } from '../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { isCombinedField } from '../is-combined-field';\nimport { DEFAULT_LAYOUT } from '../../normalize-form-fields';\nimport SummaryButton from './summary-button';\n\nfunction ModalContent< Item >( {\n\tdata,\n\tform,\n\tfieldLabel,\n\tonChange,\n\tonClose,\n}: {\n\tdata: Item;\n\tform: Form;\n\tfieldLabel: string;\n\tonChange: ( data: Partial< Item > ) => void;\n\tonClose: () => void;\n} ) {\n\tconst [ changes, setChanges ] = useState< Partial< Item > >( {} );\n\tconst modalData = useMemo( () => {\n\t\treturn deepMerge( data, changes );\n\t}, [ data, changes ] );\n\n\tconst onApply = () => {\n\t\tonChange( changes );\n\t\tonClose();\n\t};\n\n\tconst handleOnChange = ( newValue: Partial< Item > ) => {\n\t\tsetChanges( ( prev ) => deepMerge( prev, newValue ) );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"dataforms-layouts-panel__modal\"\n\t\t\tonRequestClose={ onClose }\n\t\t\tisFullScreen={ false }\n\t\t\ttitle={ fieldLabel }\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<DataFormLayout\n\t\t\t\tdata={ modalData }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ handleOnChange }\n\t\t\t>\n\t\t\t\t{ ( FieldLayout, nestedField ) => (\n\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\tkey={ nestedField.id }\n\t\t\t\t\t\tdata={ modalData }\n\t\t\t\t\t\tfield={ nestedField }\n\t\t\t\t\t\tonChange={ handleOnChange }\n\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</DataFormLayout>\n\t\t\t<HStack\n\t\t\t\tclassName=\"dataforms-layouts-panel__modal-footer\"\n\t\t\t\tspacing={ 3 }\n\t\t\t>\n\t\t\t\t<Spacer />\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\tonClick={ onApply }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Apply' ) }\n\t\t\t\t</Button>\n\t\t\t</HStack>\n\t\t</Modal>\n\t);\n}\n\nfunction PanelModal< Item >( {\n\tfieldDefinition,\n\tsummaryFields,\n\tlabelPosition,\n\tdata,\n\tonChange,\n\tfield,\n}: {\n\tfieldDefinition: NormalizedField< Item >;\n\tsummaryFields: NormalizedField< Item >[];\n\tlabelPosition: 'side' | 'top' | 'none';\n\tdata: Item;\n\tonChange: ( value: any ) => void;\n\tfield: FormField;\n} ) {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\n\tconst fieldLabel = isCombinedField( field )\n\t\t? field.label\n\t\t: fieldDefinition?.label;\n\n\tconst form: Form = useMemo(\n\t\t(): Form => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: isCombinedField( field )\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<SummaryButton\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tdata={ data }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t\tfieldLabel={ fieldLabel }\n\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\tonClick={ () => setIsOpen( true ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<ModalContent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tform={ form as Form }\n\t\t\t\t\tfieldLabel={ fieldLabel ?? '' }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonClose={ () => setIsOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PanelModal;\n"],"mappings":";;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAMA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6C,IAAAQ,WAAA,GAAAR,OAAA;AAxB7C;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;;AAOA,SAASS,YAAYA,CAAU;EAC9BC,IAAI;EACJC,IAAI;EACJC,UAAU;EACVC,QAAQ;EACRC;AAOD,CAAC,EAAG;EACH,MAAM,CAAEC,OAAO,EAAEC,UAAU,CAAE,GAAG,IAAAC,iBAAQ,EAAqB,CAAC,CAAE,CAAC;EACjE,MAAMC,SAAS,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAChC,OAAO,IAAAC,kBAAS,EAAEV,IAAI,EAAEK,OAAQ,CAAC;EAClC,CAAC,EAAE,CAAEL,IAAI,EAAEK,OAAO,CAAG,CAAC;EAEtB,MAAMM,OAAO,GAAGA,CAAA,KAAM;IACrBR,QAAQ,CAAEE,OAAQ,CAAC;IACnBD,OAAO,CAAC,CAAC;EACV,CAAC;EAED,MAAMQ,cAAc,GAAKC,QAAyB,IAAM;IACvDP,UAAU,CAAIQ,IAAI,IAAM,IAAAJ,kBAAS,EAAEI,IAAI,EAAED,QAAS,CAAE,CAAC;EACt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,IAAI,EAAGA,IAAM;MACbC,IAAI,EAAGA,IAAc;MACrBC,UAAU,EAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,EAAI;MAC/BC,QAAQ,EAAGA,QAAU;MACrBC,OAAO,EAAGA,CAAA,KAAM0C,SAAS,CAAE,KAAM;IAAG,CACpC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAAJ,OAAA,GAEcX,UAAU","ignoreList":[]}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _components = require("@wordpress/components");
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ /**
11
+ * WordPress dependencies
12
+ */
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+
18
+ function SummaryButton({
19
+ summaryFields,
20
+ data,
21
+ labelPosition,
22
+ fieldLabel,
23
+ disabled,
24
+ onClick,
25
+ 'aria-expanded': ariaExpanded
26
+ }) {
27
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
28
+ className: "dataforms-layouts-panel__summary-button",
29
+ size: "compact",
30
+ variant: ['none', 'top'].includes(labelPosition) ? 'link' : 'tertiary',
31
+ "aria-expanded": ariaExpanded,
32
+ "aria-label": (0, _i18n.sprintf)(
33
+ // translators: %s: Field name.
34
+ (0, _i18n._x)('Edit %s', 'field'), fieldLabel || ''),
35
+ onClick: onClick,
36
+ disabled: disabled,
37
+ accessibleWhenDisabled: true,
38
+ style: summaryFields.length > 1 ? {
39
+ minHeight: 'auto',
40
+ height: 'auto',
41
+ alignItems: 'flex-start'
42
+ } : undefined,
43
+ children: summaryFields.length > 1 ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
44
+ style: {
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ alignItems: 'flex-start',
48
+ width: '100%',
49
+ gap: '2px'
50
+ },
51
+ children: summaryFields.map(summaryField => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
52
+ style: {
53
+ width: '100%'
54
+ },
55
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(summaryField.render, {
56
+ item: data,
57
+ field: summaryField
58
+ })
59
+ }, summaryField.id))
60
+ }) : summaryFields.map(summaryField => /*#__PURE__*/(0, _jsxRuntime.jsx)(summaryField.render, {
61
+ item: data,
62
+ field: summaryField
63
+ }, summaryField.id))
64
+ });
65
+ }
66
+ var _default = exports.default = SummaryButton;
67
+ //# sourceMappingURL=summary-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_components","require","_i18n","_jsxRuntime","SummaryButton","summaryFields","data","labelPosition","fieldLabel","disabled","onClick","ariaExpanded","jsx","Button","className","size","variant","includes","sprintf","_x","accessibleWhenDisabled","style","length","minHeight","height","alignItems","undefined","children","display","flexDirection","width","gap","map","summaryField","render","item","field","id","_default","exports","default"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/summary-button.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../types';\n\nfunction SummaryButton< Item >( {\n\tsummaryFields,\n\tdata,\n\tlabelPosition,\n\tfieldLabel,\n\tdisabled,\n\tonClick,\n\t'aria-expanded': ariaExpanded,\n}: {\n\tsummaryFields: NormalizedField< Item >[];\n\tdata: Item;\n\tlabelPosition: 'side' | 'top' | 'none';\n\tfieldLabel?: string;\n\tdisabled?: boolean;\n\tonClick: () => void;\n\t'aria-expanded'?: boolean;\n} ) {\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"dataforms-layouts-panel__summary-button\"\n\t\t\tsize=\"compact\"\n\t\t\tvariant={\n\t\t\t\t[ 'none', 'top' ].includes( labelPosition )\n\t\t\t\t\t? 'link'\n\t\t\t\t\t: 'tertiary'\n\t\t\t}\n\t\t\taria-expanded={ ariaExpanded }\n\t\t\taria-label={ sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t\t) }\n\t\t\tonClick={ onClick }\n\t\t\tdisabled={ disabled }\n\t\t\taccessibleWhenDisabled\n\t\t\tstyle={\n\t\t\t\tsummaryFields.length > 1\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tminHeight: 'auto',\n\t\t\t\t\t\t\theight: 'auto',\n\t\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t }\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t>\n\t\t\t{ summaryFields.length > 1 ? (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\tflexDirection: 'column',\n\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\tgap: '2px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ summaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t) : (\n\t\t\t\tsummaryFields.map( ( summaryField ) => (\n\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t/>\n\t\t\t\t) )\n\t\t\t) }\n\t\t</Button>\n\t);\n}\n\nexport default SummaryButton;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAA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qB,YAAY,CAACC,MAAM;UACnBC,IAAI,EAAG7B,IAAM;UACb8B,KAAK,EAAGH;QAAc,CACtB;MAAC,GANIA,YAAY,CAACI,EAOf,CACJ;IAAC,CACC,CAAC,GAENhC,aAAa,CAAC2B,GAAG,CAAIC,YAAY,iBAChC,IAAA9B,WAAA,CAAAS,GAAA,EAACqB,YAAY,CAACC,MAAM;MAEnBC,IAAI,EAAG7B,IAAM;MACb8B,KAAK,EAAGH;IAAc,GAFhBA,YAAY,CAACI,EAGnB,CACA;EACF,CACM,CAAC;AAEX;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcpC,aAAa","ignoreList":[]}
@@ -49,12 +49,6 @@ const arrayFieldType = {
49
49
  if (!value.every(v => typeof v === 'string')) {
50
50
  return (0, _i18n.__)('Every value must be a string.');
51
51
  }
52
- if (field?.elements) {
53
- const validValues = field.elements.map(f => f.value);
54
- if (!value.every(v => validValues.includes(v))) {
55
- return (0, _i18n.__)('Value must be one of the elements.');
56
- }
57
- }
58
52
  return null;
59
53
  }
60
54
  },
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","_constants","sort","valueA","valueB","direction","arrA","Array","isArray","arrB","length","joinedA","join","joinedB","localeCompare","render","item","field","value","getValue","arrayFieldType","isValid","custom","undefined","includes","__","every","v","elements","validValues","map","f","Edit","enableSorting","filterBy","defaultOperators","OPERATOR_IS_ANY","OPERATOR_IS_NONE","validOperators","OPERATOR_IS_ALL","OPERATOR_IS_NOT_ALL","_default","exports","default"],"sources":["@wordpress/dataviews/src/field-types/array.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tFieldTypeDefinition,\n\tNormalizedField,\n} from '../types';\nimport {\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_NOT_ALL,\n} from '../constants';\n\n// Sort arrays by length, then alphabetically by joined string\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\tconst arrA = Array.isArray( valueA ) ? valueA : [];\n\tconst arrB = Array.isArray( valueB ) ? valueB : [];\n\tif ( arrA.length !== arrB.length ) {\n\t\treturn direction === 'asc'\n\t\t\t? arrA.length - arrB.length\n\t\t\t: arrB.length - arrA.length;\n\t}\n\n\tconst joinedA = arrA.join( ',' );\n\tconst joinedB = arrB.join( ',' );\n\treturn direction === 'asc'\n\t\t? joinedA.localeCompare( joinedB )\n\t\t: joinedB.localeCompare( joinedA );\n}\n\nfunction render( { item, field }: DataViewRenderFieldProps< any > ) {\n\tconst value = field.getValue( { item } ) || [];\n\treturn value.join( ', ' );\n}\n\nconst arrayFieldType: FieldTypeDefinition< any > = {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\n\t\t\tif (\n\t\t\t\t! [ undefined, '', null ].includes( value ) &&\n\t\t\t\t! Array.isArray( value )\n\t\t\t) {\n\t\t\t\treturn __( 'Value must be an array.' );\n\t\t\t}\n\n\t\t\t// Only allow strings for now. Can be extended to other types in the future.\n\t\t\tif ( ! value.every( ( v: any ) => typeof v === 'string' ) ) {\n\t\t\t\treturn __( 'Every value must be a string.' );\n\t\t\t}\n\n\t\t\tif ( field?.elements ) {\n\t\t\t\tconst validValues = field.elements.map( ( f ) => f.value );\n\t\t\t\tif (\n\t\t\t\t\t! value.every( ( v: any ) => validValues.includes( v ) )\n\t\t\t\t) {\n\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'array', // Use array control\n\trender,\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ],\n\t\tvalidOperators: [\n\t\t\tOPERATOR_IS_ANY,\n\t\t\tO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,IAAS,EAAEC,KAA6B,KAAM;MACvD,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;QAAEH;MAAK,CAAE,CAAC;MAExC,IACC,CAAE,CAAEO,SAAS,EAAE,EAAE,EAAE,IAAI,CAAE,CAACC,QAAQ,CAAEN,KAAM,CAAC,IAC3C,CAAEX,KAAK,CAACC,OAAO,CAAEU,KAAM,CAAC,EACvB;QACD,OAAO,IAAAO,QAAE,EAAE,yBAA0B,CAAC;MACvC;;MAEA;MACA,IAAK,CAAEP,KAAK,CAACQ,KAAK,CAAIC,CAAM,IAAM,OAAOA,CAAC,KAAK,QAAS,CAAC,EAAG;QAC3D,OAAO,IAAAF,QAAE,EAAE,+BAAgC,CAAC;MAC7C;MAEA,IAAKR,KAAK,EAAEW,QAAQ,EAAG;QACtB,MAAMC,WAAW,GAAGZ,KAAK,CAACW,QAAQ,CAACE,GAAG,CAAIC,CAAC,IAAMA,CAAC,CAACb,KAAM,CAAC;QAC1D,IACC,CAAEA,KAAK,CAACQ,KAAK,CAAIC,CAAM,IAAME,WAAW,CAACL,QAAQ,CAAEG,CAAE,CAAE,CAAC,EACvD;UACD,OAAO,IAAAF,QAAE,EAAE,oCAAqC,CAAC;QAClD;MACD;MACA,OAAO,IAAI;IACZ;EACD,CAAC;EACDO,IAAI,EAAE,OAAO;EAAE;EACfjB,MAAM;EACNkB,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,0BAAe,EAAEC,2BAAgB,CAAE;IACvDC,cAAc,EAAE,CACfF,0BAAe,EACfC,2BAAgB,EAChBE,0BAAe,EACfC,8BAAmB;EAErB;AACD,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEavB,cAAc","ignoreList":[]}
1
+ {"version":3,"names":["_i18n","require","_constants","sort","valueA","valueB","direction","arrA","Array","isArray","arrB","length","joinedA","join","joinedB","localeCompare","render","item","field","value","getValue","arrayFieldType","isValid","custom","undefined","includes","__","every","v","Edit","enableSorting","filterBy","defaultOperators","OPERATOR_IS_ANY","OPERATOR_IS_NONE","validOperators","OPERATOR_IS_ALL","OPERATOR_IS_NOT_ALL","_default","exports","default"],"sources":["@wordpress/dataviews/src/field-types/array.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tFieldTypeDefinition,\n\tNormalizedField,\n} from '../types';\nimport {\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_NOT_ALL,\n} from '../constants';\n\n// Sort arrays by length, then alphabetically by joined string\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\tconst arrA = Array.isArray( valueA ) ? valueA : [];\n\tconst arrB = Array.isArray( valueB ) ? valueB : [];\n\tif ( arrA.length !== arrB.length ) {\n\t\treturn direction === 'asc'\n\t\t\t? arrA.length - arrB.length\n\t\t\t: arrB.length - arrA.length;\n\t}\n\n\tconst joinedA = arrA.join( ',' );\n\tconst joinedB = arrB.join( ',' );\n\treturn direction === 'asc'\n\t\t? joinedA.localeCompare( joinedB )\n\t\t: joinedB.localeCompare( joinedA );\n}\n\nfunction render( { item, field }: DataViewRenderFieldProps< any > ) {\n\tconst value = field.getValue( { item } ) || [];\n\treturn value.join( ', ' );\n}\n\nconst arrayFieldType: FieldTypeDefinition< any > = {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\n\t\t\tif (\n\t\t\t\t! [ undefined, '', null ].includes( value ) &&\n\t\t\t\t! Array.isArray( value )\n\t\t\t) {\n\t\t\t\treturn __( 'Value must be an array.' );\n\t\t\t}\n\n\t\t\t// Only allow strings for now. Can be extended to other types in the future.\n\t\t\tif ( ! value.every( ( v: any ) => typeof v === 'string' ) ) {\n\t\t\t\treturn __( 'Every value must be a string.' );\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'array', // Use array control\n\trender,\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ],\n\t\tvalidOperators: [\n\t\t\tOPERATOR_IS_ANY,\n\t\t\tOPERATOR_IS_NONE,\n\t\t\tOPERATOR_IS_ALL,\n\t\t\tOPERATOR_IS_NOT_ALL,\n\t\t],\n\t},\n};\n\nexport default arrayFieldType;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAWA,IAAAC,UAAA,GAAAD,OAAA;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA,SAASE,IAAIA,CAAEC,MAAW,EAAEC,MAAW,EAAEC,SAAwB,EAAG;EACnE,MAAMC,IAAI,GAAGC,KAAK,CAACC,OAAO,CAAEL,MAAO,CAAC,GAAGA,MAAM,GAAG,EAAE;EAClD,MAAMM,IAAI,GAAGF,KAAK,CAACC,OAAO,CAAEJ,MAAO,CAAC,GAAGA,MAAM,GAAG,EAAE;EAClD,IAAKE,IAAI,CAACI,MAAM,KAAKD,IAAI,CAACC,MAAM,EAAG;IAClC,OAAOL,SAAS,KAAK,KAAK,GACvBC,IAAI,CAACI,MAAM,GAAGD,IAAI,CAACC,MAAM,GACzBD,IAAI,CAACC,MAAM,GAAGJ,IAAI,CAACI,MAAM;EAC7B;EAEA,MAAMC,OAAO,GAAGL,IAAI,CAACM,IAAI,CAAE,GAAI,CAAC;EAChC,MAAMC,OAAO,GAAGJ,IAAI,CAACG,IAAI,CAAE,GAAI,CAAC;EAChC,OAAOP,SAAS,KAAK,KAAK,GACvBM,OAAO,CAACG,aAAa,CAAED,OAAQ,CAAC,GAChCA,OAAO,CAACC,aAAa,CAAEH,OAAQ,CAAC;AACpC;AAEA,SAASI,MAAMA,CAAE;EAAEC,IAAI;EAAEC;AAAuC,CAAC,EAAG;EACnE,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;IAAEH;EAAK,CAAE,CAAC,IAAI,EAAE;EAC9C,OAAOE,KAAK,CAACN,IAAI,CAAE,IAAK,CAAC;AAC1B;AAEA,MAAMQ,cAA0C,GAAG;EAClDlB,IAAI;EACJmB,OAAO,EAAE;IACRC,MAAM,EAAEA,CAAEN,IAAS,EAAEC,KAA6B,KAAM;MACvD,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;QAAEH;MAAK,CAAE,CAAC;MAExC,IACC,CAAE,CAAEO,SAAS,EAAE,EAAE,EAAE,IAAI,CAAE,CAACC,QAAQ,CAAEN,KAAM,CAAC,IAC3C,CAAEX,KAAK,CAACC,OAAO,CAAEU,KAAM,CAAC,EACvB;QACD,OAAO,IAAAO,QAAE,EAAE,yBAA0B,CAAC;MACvC;;MAEA;MACA,IAAK,CAAEP,KAAK,CAACQ,KAAK,CAAIC,CAAM,IAAM,OAAOA,CAAC,KAAK,QAAS,CAAC,EAAG;QAC3D,OAAO,IAAAF,QAAE,EAAE,+BAAgC,CAAC;MAC7C;MAEA,OAAO,IAAI;IACZ;EACD,CAAC;EACDG,IAAI,EAAE,OAAO;EAAE;EACfb,MAAM;EACNc,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,0BAAe,EAAEC,2BAAgB,CAAE;IACvDC,cAAc,EAAE,CACfF,0BAAe,EACfC,2BAAgB,EAChBE,0BAAe,EACfC,8BAAmB;EAErB;AACD,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanB,cAAc","ignoreList":[]}
package/build/index.js CHANGED
@@ -16,6 +16,12 @@ Object.defineProperty(exports, "DataViews", {
16
16
  return _dataviews.default;
17
17
  }
18
18
  });
19
+ Object.defineProperty(exports, "DataViewsPicker", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _dataviewsPicker.default;
23
+ }
24
+ });
19
25
  Object.defineProperty(exports, "VIEW_LAYOUTS", {
20
26
  enumerable: true,
21
27
  get: function () {
@@ -35,6 +41,7 @@ Object.defineProperty(exports, "isItemValid", {
35
41
  }
36
42
  });
37
43
  var _dataviews = _interopRequireDefault(require("./components/dataviews"));
44
+ var _dataviewsPicker = _interopRequireDefault(require("./components/dataviews-picker"));
38
45
  var _dataform = _interopRequireDefault(require("./components/dataform"));
39
46
  var _dataviewsLayouts = require("./dataviews-layouts");
40
47
  var _filterAndSortDataView = require("./filter-and-sort-data-view");
@@ -1 +1 @@
1
- {"version":3,"names":["_dataviews","_interopRequireDefault","require","_dataform","_dataviewsLayouts","_filterAndSortDataView","_validation"],"sources":["@wordpress/dataviews/src/index.ts"],"sourcesContent":["export { default as DataViews } from './components/dataviews';\nexport { default as DataForm } from './components/dataform';\nexport { VIEW_LAYOUTS } from './dataviews-layouts';\nexport { filterSortAndPaginate } from './filter-and-sort-data-view';\nexport type * from './types';\nexport { isItemValid } from './validation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AAEA,IAAAI,WAAA,GAAAJ,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_dataviews","_interopRequireDefault","require","_dataviewsPicker","_dataform","_dataviewsLayouts","_filterAndSortDataView","_validation"],"sources":["@wordpress/dataviews/src/index.ts"],"sourcesContent":["export { default as DataViews } from './components/dataviews';\nexport { default as DataViewsPicker } from './components/dataviews-picker';\nexport { default as DataForm } from './components/dataform';\nexport { VIEW_LAYOUTS } from './dataviews-layouts';\nexport { filterSortAndPaginate } from './filter-and-sort-data-view';\nexport type * from './types';\nexport { isItemValid } from './validation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AAEA,IAAAK,WAAA,GAAAL,OAAA","ignoreList":[]}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.normalizeFields = normalizeFields;
8
+ exports.setValueFromId = void 0;
8
9
  var _fieldTypes = _interopRequireDefault(require("./field-types"));
9
10
  var _dataformControls = require("./dataform-controls");
10
11
  var _constants = require("./constants");
@@ -30,6 +31,20 @@ const getValueFromId = id => ({
30
31
  }
31
32
  return value;
32
33
  };
34
+ const setValueFromId = id => ({
35
+ value
36
+ }) => {
37
+ const path = id.split('.');
38
+ const result = {};
39
+ let current = result;
40
+ for (const segment of path.slice(0, -1)) {
41
+ current[segment] = {};
42
+ current = current[segment];
43
+ }
44
+ current[path.at(-1)] = value;
45
+ return result;
46
+ };
47
+ exports.setValueFromId = setValueFromId;
33
48
  function getFilterBy(field, fieldTypeDefinition) {
34
49
  if (field.filterBy === false) {
35
50
  return false;
@@ -97,6 +112,7 @@ function normalizeFields(fields) {
97
112
  var _field$sort, _field$render, _field$enableHiding, _ref, _field$enableSorting, _ref2, _field$readOnly;
98
113
  const fieldTypeDefinition = (0, _fieldTypes.default)(field.type);
99
114
  const getValue = field.getValue || getValueFromId(field.id);
115
+ const setValue = field.setValue || setValueFromId(field.id);
100
116
  const sort = (_field$sort = field.sort) !== null && _field$sort !== void 0 ? _field$sort : function sort(a, b, direction) {
101
117
  return fieldTypeDefinition.sort(getValue({
102
118
  item: a
@@ -124,6 +140,7 @@ function normalizeFields(fields) {
124
140
  label: field.label || field.id,
125
141
  header: field.header || field.label || field.id,
126
142
  getValue,
143
+ setValue,
127
144
  render,
128
145
  sort,
129
146
  isValid,
@@ -1 +1 @@
1
- {"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","_constants","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","ALL_OPERATORS","filter","operator","includes","elements","OPERATOR_BETWEEN","hasSingleSelectionOperator","some","SINGLE_SELECTION_OPERATORS","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","getFieldTypeDefinition","type","getValue","sort","a","b","direction","isValid","Edit","getControl","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ??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,KAAK,CAACyC,KAAK,IAAIzC,KAAK,CAACT,EAAE;MAC9BmD,MAAM,EAAE1C,KAAK,CAAC0C,MAAM,IAAI1C,KAAK,CAACyC,KAAK,IAAIzC,KAAK,CAACT,EAAE;MAC/CwC,QAAQ;MACRQ,MAAM;MACNP,IAAI;MACJI,OAAO;MACPC,IAAI;MACJM,YAAY,GAAAnB,mBAAA,GAAExB,KAAK,CAAC2C,YAAY,cAAAnB,mBAAA,cAAAA,mBAAA,GAAI,IAAI;MACxCoB,aAAa,GAAAnB,IAAA,IAAAC,oBAAA,GACZ1B,KAAK,CAAC4C,aAAa,cAAAlB,oBAAA,cAAAA,oBAAA,GACnBzB,mBAAmB,CAAC2C,aAAa,cAAAnB,IAAA,cAAAA,IAAA,GACjC,IAAI;MACLvB,QAAQ;MACR2C,QAAQ,GAAAlB,KAAA,IAAAC,eAAA,GAAE5B,KAAK,CAAC6C,QAAQ,cAAAjB,eAAA,cAAAA,eAAA,GAAI3B,mBAAmB,CAAC4C,QAAQ,cAAAlB,KAAA,cAAAA,KAAA,GAAI;IAC7D,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","_constants","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","setValueFromId","result","current","slice","at","exports","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","ALL_OPERATORS","filter","operator","includes","elements","OPERATOR_BETWEEN","hasSingleSelectionOperator","some","SINGLE_SELECTION_OPERATORS","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","getFieldTypeDefinition","type","getValue","setValue","sort","a","b","direction","isValid","Edit","getControl","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nexport const setValueFromId =\n\t( id: string ) =>\n\t( { value }: { value: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tconst result: any = {};\n\t\tlet current = result;\n\n\t\tfor ( const segment of path.slice( 0, -1 ) ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t\tcurrent = current[ segment ];\n\t\t}\n\n\t\tcurrent[ path.at( -1 )! ] = value;\n\t\treturn result;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\t\tconst setValue = field.setValue || setValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\tsetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAjBA;AACA;AACA;;AAGA;AACA;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esContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tReactNode,\n\tComponentType,\n\tComponentProps,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string | null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\tcustom?: ( item: Item, field: NormalizedField< Item > ) => null | string;\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n};\n\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: Rules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable | ViewPickerGrid;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport type ViewPickerProps< Item > = ViewPickerGridProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n}\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n};\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n};\n\nexport type Layout = RegularLayout | PanelLayout | CardLayout | RowLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout;\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: Layout;\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tReactNode,\n\tComponentType,\n\tComponentProps,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit:\n\t\t| ComponentType< DataFormControlProps< Item > >\n\t\t| string\n\t\t| EditConfig\n\t\t| null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\telements?: boolean;\n\tcustom?: ( item: Item, field: NormalizedField< Item > ) => null | string;\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldType, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field can be hidden in the UI.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n};\n\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\tsetValue: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: Rules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: DeepPartial< Item > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n\t/**\n\t * Configuration object for the control.\n\t */\n\tconfig?: {\n\t\tprefix?: React.ComponentType;\n\t\tsuffix?: React.ComponentType;\n\t\trows?: number;\n\t};\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable | ViewPickerGrid;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport type ViewPickerProps< Item > = ViewPickerGridProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n}\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n};\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n};\n\nexport type Layout = RegularLayout | PanelLayout | CardLayout | RowLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout;\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: Layout;\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren: Array< FormField | string >;\n\tsummary?: string | string[];\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
@@ -23,18 +23,35 @@ function isItemValid(item, fields, form) {
23
23
  id
24
24
  }) => !!form.fields?.includes(id)));
25
25
  const isEmptyNullOrUndefined = value => [undefined, '', null].includes(value);
26
+ const isArrayOrElementsEmptyNullOrUndefined = value => {
27
+ return !Array.isArray(value) || value.length === 0 || value.every(element => isEmptyNullOrUndefined(element));
28
+ };
26
29
  return _fields.every(field => {
27
30
  const value = field.getValue({
28
31
  item
29
32
  });
30
33
  if (field.isValid.required) {
31
- if (field.type === 'text' && isEmptyNullOrUndefined(value) || field.type === 'email' && isEmptyNullOrUndefined(value) || field.type === 'url' && isEmptyNullOrUndefined(value) || field.type === 'telephone' && isEmptyNullOrUndefined(value) || field.type === 'password' && isEmptyNullOrUndefined(value) || field.type === 'integer' && isEmptyNullOrUndefined(value) || field.type === undefined && isEmptyNullOrUndefined(value)) {
34
+ if (field.type === 'text' && isEmptyNullOrUndefined(value) || field.type === 'email' && isEmptyNullOrUndefined(value) || field.type === 'url' && isEmptyNullOrUndefined(value) || field.type === 'telephone' && isEmptyNullOrUndefined(value) || field.type === 'password' && isEmptyNullOrUndefined(value) || field.type === 'integer' && isEmptyNullOrUndefined(value) || field.type === 'array' && isArrayOrElementsEmptyNullOrUndefined(value) || field.type === undefined && isEmptyNullOrUndefined(value)) {
32
35
  return false;
33
36
  }
34
37
  if (field.type === 'boolean' && value !== true) {
35
38
  return false;
36
39
  }
37
40
  }
41
+ if (field.isValid.elements) {
42
+ if (field.elements) {
43
+ const validValues = field.elements.map(element => element.value);
44
+ if (field.type === 'array') {
45
+ // For arrays, check if all values are valid elements
46
+ if (Array.isArray(value)) {
47
+ return value.every(arrayItem => validValues.includes(arrayItem));
48
+ }
49
+ return false;
50
+ }
51
+ // For single-value fields, check if the value is a valid element
52
+ return validValues.includes(value);
53
+ }
54
+ }
38
55
  if (typeof field.isValid.custom === 'function' && field.isValid.custom(item, field) !== null) {
39
56
  return false;
40
57
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_normalizeFields","require","isItemValid","item","fields","form","_fields","normalizeFields","filter","id","includes","isEmptyNullOrUndefined","value","undefined","every","field","getValue","isValid","required","type","custom"],"sources":["@wordpress/dataviews/src/validation.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, Form } from './types';\n\n/**\n * Whether or not the given item's value is valid according to the fields and form config.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return A boolean indicating if the item is valid (true) or not (false).\n */\nexport function isItemValid< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): boolean {\n\tconst _fields = normalizeFields(\n\t\tfields.filter( ( { id } ) => !! form.fields?.includes( id ) )\n\t);\n\n\tconst isEmptyNullOrUndefined = ( value: any ) =>\n\t\t[ undefined, '', null ].includes( value );\n\n\treturn _fields.every( ( field ) => {\n\t\tconst value = field.getValue( { item } );\n\n\t\tif ( field.isValid.required ) {\n\t\t\tif (\n\t\t\t\t( field.type === 'text' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'email' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'url' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'telephone' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'password' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'integer' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === undefined && isEmptyNullOrUndefined( value ) )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif ( field.type === 'boolean' && value !== true ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\ttypeof field.isValid.custom === 'function' &&\n\t\t\tfield.isValid.custom( item, field ) !== null\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAC1BC,IAAU,EACVC,MAAuB,EACvBC,IAAU,EACA;EACV,MAAMC,OAAO,GAAG,IAAAC,gCAAe,EAC9BH,MAAM,CAACI,MAAM,CAAE,CAAE;IAAEC;EAAG,CAAC,KAAM,CAAC,CAAEJ,IAAI,CAACD,MAAM,EAAEM,QAAQ,CAAED,EAAG,CAAE,CAC7D,CAAC;EAED,MAAME,sBAAsB,GAAKC,KAAU,IAC1C,CAAEC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAE,CAACH,QAAQ,CAAEE,KAAM,CAAC;EAE1C,OAAON,OAAO,CAACQ,KAAK,CAAIC,KAAK,IAAM;IAClC,MAAMH,KAAK,GAAGG,KAAK,CAACC,QAAQ,CAAE;MAAEb;IAAK,CAAE,CAAC;IAExC,IAAKY,KAAK,CAACE,OAAO,CAACC,QAAQ,EAAG;MAC7B,IACGH,KAAK,CAACI,IAAI,KAAK,MAAM,IAAIR,sBAAsB,CAAEC,KAAM,CAAC,IACxDG,KAAK,CAACI,IAAI,KAAK,OAAO,IAAIR,sBAAsB,CAAEC,KAAM,CAAG,IAC3DG,KAAK,CAACI,IAAI,KAAK,KAAK,IAAIR,sBAAsB,CAAEC,KAAM,CAAG,IACzDG,KAAK,CAACI,IAAI,KAAK,WAAW,IAC3BR,sBAAsB,CAAEC,KAAM,CAAG,IAChCG,KAAK,CAACI,IAAI,KAAK,UAAU,IAC1BR,sBAAsB,CAAEC,KAAM,CAAG,IAChCG,KAAK,CAACI,IAAI,KAAK,SAAS,IACzBR,sBAAsB,CAAEC,KAAM,CAAG,IAChCG,KAAK,CAACI,IAAI,KAAKN,SAAS,IAAIF,sBAAsB,CAAEC,KAAM,CAAG,EAC9D;QACD,OAAO,KAAK;MACb;MAEA,IAAKG,KAAK,CAACI,IAAI,KAAK,SAAS,IAAIP,KAAK,KAAK,IAAI,EAAG;QACjD,OAAO,KAAK;MACb;IACD;IAEA,IACC,OAAOG,KAAK,CAACE,OAAO,CAACG,MAAM,KAAK,UAAU,IAC1CL,KAAK,CAACE,OAAO,CAACG,MAAM,CAAEjB,IAAI,EAAEY,KAAM,CAAC,KAAK,IAAI,EAC3C;MACD,OAAO,KAAK;IACb;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_normalizeFields","require","isItemValid","item","fields","form","_fields","normalizeFields","filter","id","includes","isEmptyNullOrUndefined","value","undefined","isArrayOrElementsEmptyNullOrUndefined","Array","isArray","length","every","element","field","getValue","isValid","required","type","elements","validValues","map","arrayItem","custom"],"sources":["@wordpress/dataviews/src/validation.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, Form } from './types';\n\n/**\n * Whether or not the given item's value is valid according to the fields and form config.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return A boolean indicating if the item is valid (true) or not (false).\n */\nexport function isItemValid< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): boolean {\n\tconst _fields = normalizeFields(\n\t\tfields.filter( ( { id } ) => !! form.fields?.includes( id ) )\n\t);\n\n\tconst isEmptyNullOrUndefined = ( value: any ) =>\n\t\t[ undefined, '', null ].includes( value );\n\n\tconst isArrayOrElementsEmptyNullOrUndefined = ( value: any ) => {\n\t\treturn (\n\t\t\t! Array.isArray( value ) ||\n\t\t\tvalue.length === 0 ||\n\t\t\tvalue.every( ( element: any ) => isEmptyNullOrUndefined( element ) )\n\t\t);\n\t};\n\n\treturn _fields.every( ( field ) => {\n\t\tconst value = field.getValue( { item } );\n\n\t\tif ( field.isValid.required ) {\n\t\t\tif (\n\t\t\t\t( field.type === 'text' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'email' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'url' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'telephone' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'password' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'integer' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'array' &&\n\t\t\t\t\tisArrayOrElementsEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === undefined && isEmptyNullOrUndefined( value ) )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif ( field.type === 'boolean' && value !== true ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif ( field.isValid.elements ) {\n\t\t\tif ( field.elements ) {\n\t\t\t\tconst validValues = field.elements.map(\n\t\t\t\t\t( element ) => element.value\n\t\t\t\t);\n\n\t\t\t\tif ( field.type === 'array' ) {\n\t\t\t\t\t// For arrays, check if all values are valid elements\n\t\t\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\t\t\treturn value.every( ( arrayItem ) =>\n\t\t\t\t\t\t\tvalidValues.includes( arrayItem )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\t// For single-value fields, check if the value is a valid element\n\t\t\t\treturn validValues.includes( value );\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\ttypeof field.isValid.custom === 'function' &&\n\t\t\tfield.isValid.custom( item, field ) !== null\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAC1BC,IAAU,EACVC,MAAuB,EACvBC,IAAU,EACA;EACV,MAAMC,OAAO,GAAG,IAAAC,gCAAe,EAC9BH,MAAM,CAACI,MAAM,CAAE,CAAE;IAAEC;EAAG,CAAC,KAAM,CAAC,CAAEJ,IAAI,CAACD,MAAM,EAAEM,QAAQ,CAAED,EAAG,CAAE,CAC7D,CAAC;EAED,MAAME,sBAAsB,GAAKC,KAAU,IAC1C,CAAEC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAE,CAACH,QAAQ,CAAEE,KAAM,CAAC;EAE1C,MAAME,qCAAqC,GAAKF,KAAU,IAAM;IAC/D,OACC,CAAEG,KAAK,CAACC,OAAO,CAAEJ,KAAM,CAAC,IACxBA,KAAK,CAACK,MAAM,KAAK,CAAC,IAClBL,KAAK,CAACM,KAAK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B;UACA,IAAKT,KAAK,CAACC,OAAO,CAAEJ,KAAM,CAAC,EAAG;YAC7B,OAAOA,KAAK,CAACM,KAAK,CAAIU,SAAS,IAC9BF,WAAW,CAAChB,QAAQ,CAAEkB,SAAU,CACjC,CAAC;UACF;UACA,OAAO,KAAK;QACb;QACA;QACA,OAAOF,WAAW,CAAChB,QAAQ,CAAEE,KAAM,CAAC;MACrC;IACD;IAEA,IACC,OAAOQ,KAAK,CAACE,OAAO,CAACO,MAAM,KAAK,UAAU,IAC1CT,KAAK,CAACE,OAAO,CAACO,MAAM,CAAE1B,IAAI,EAAEiB,KAAM,CAAC,KAAK,IAAI,EAC3C;MACD,OAAO,KAAK;IACb;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -23,12 +23,54 @@ export default function InputWidget({
23
23
  fields
24
24
  }) {
25
25
  const currentFilter = view.filters?.find(f => f.field === filter.field);
26
- const field = fields.find(f => f.id === filter.field);
27
26
  const currentValue = getCurrentValue(filter, currentFilter);
27
+
28
+ /*
29
+ * We are reusing the field.Edit component for filters. By doing so,
30
+ * we get for free a filter control specific to the field type
31
+ * and other aspects of the field API (Edit control configuration, etc.).
32
+ *
33
+ * This approach comes with an issue: the field.Edit controls work with getValue
34
+ * and setValue methods, which take an item (Item) as parameter. But, at this point,
35
+ * we don't have an item and we don't know how to create one, either.
36
+ *
37
+ * So, what we do is to prepare the data and the relevant field configuration
38
+ * as if Item was a plain object whose keys are the field ids:
39
+ *
40
+ * {
41
+ * [ fieldOne.id ]: value,
42
+ * [ fieldTwo.id ]: value,
43
+ * }
44
+ *
45
+ */
46
+ const field = useMemo(() => {
47
+ const currentField = fields.find(f => f.id === filter.field);
48
+ if (currentField) {
49
+ return {
50
+ ...currentField,
51
+ // Deactivate validation for filters.
52
+ isValid: {
53
+ required: false,
54
+ custom: () => null
55
+ },
56
+ // Configure getValue/setValue as if Item was a plain object.
57
+ getValue: ({
58
+ item
59
+ }) => item[currentField.id],
60
+ setValue: ({
61
+ value
62
+ }) => ({
63
+ [currentField.id]: value
64
+ })
65
+ };
66
+ }
67
+ return currentField;
68
+ }, [fields, filter.field]);
28
69
  const data = useMemo(() => {
29
70
  var _view$filters;
30
- return ((_view$filters = view.filters) !== null && _view$filters !== void 0 ? _view$filters : []).reduce((acc, f) => {
31
- acc[f.field] = f.value;
71
+ return ((_view$filters = view.filters) !== null && _view$filters !== void 0 ? _view$filters : []).reduce((acc, activeFilter) => {
72
+ // We can now assume the field is stored as a Item prop.
73
+ acc[activeFilter.field] = activeFilter.value;
32
74
  return acc;
33
75
  }, {});
34
76
  }, [view.filters]);
@@ -37,7 +79,9 @@ export default function InputWidget({
37
79
  if (!field || !currentFilter) {
38
80
  return;
39
81
  }
40
- const nextValue = updatedData[field.id];
82
+ const nextValue = field.getValue({
83
+ item: updatedData
84
+ });
41
85
  if (fastDeepEqual(nextValue, currentValue)) {
42
86
  return;
43
87
  }
@@ -1 +1 @@
1
- {"version":3,"names":["fastDeepEqual","useEvent","useMemo","Flex","getCurrentValue","jsx","_jsx","InputWidget","filter","view","onChangeView","fields","currentFilter","filters","find","f","field","id","currentValue","data","_view$filters","reduce","acc","value","handleChange","updatedData","_view$filters2","nextValue","map","_filter","operator","operators","undefined","Edit","className","gap","direction","children","hideLabelFromVision","onChange"],"sources":["@wordpress/dataviews/src/components/dataviews-filters/input-widget.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { View, NormalizedFilter, NormalizedField } from '../../types';\nimport { getCurrentValue } from './utils';\n\ninterface UserInputWidgetProps {\n\tview: View;\n\tfilter: NormalizedFilter;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< any >[];\n}\n\nexport default function InputWidget( {\n\tfilter,\n\tview,\n\tonChangeView,\n\tfields,\n}: UserInputWidgetProps ) {\n\tconst currentFilter = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tconst field = fields.find( ( f ) => f.id === filter.field );\n\tconst currentValue = getCurrentValue( filter, currentFilter );\n\tconst data = useMemo( () => {\n\t\treturn ( view.filters ?? [] ).reduce(\n\t\t\t( acc, f ) => {\n\t\t\t\tacc[ f.field ] = f.value;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, any >\n\t\t);\n\t}, [ view.filters ] );\n\n\tconst handleChange = useEvent( ( updatedData: Record< string, any > ) => {\n\t\tif ( ! field || ! currentFilter ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValue = updatedData[ field.id ];\n\t\tif ( fastDeepEqual( nextValue, currentValue ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChangeView( {\n\t\t\t...view,\n\t\t\tfilters: ( view.filters ?? [] ).map( ( _filter ) =>\n\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\toperator:\n\t\t\t\t\t\t\t\tcurrentFilter.operator || filter.operators[ 0 ],\n\t\t\t\t\t\t\t// Consider empty strings as undefined:\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records\n\t\t\t\t\t\t\t// - empty string as value means \"search empty string\": returns only the records that have an empty string as value\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// In practice, this means the filter will not be able to find an empty string as the value.\n\t\t\t\t\t\t\tvalue: nextValue === '' ? undefined : nextValue,\n\t\t\t\t\t }\n\t\t\t\t\t: _filter\n\t\t\t),\n\t\t} );\n\t} );\n\n\tif ( ! field || ! field.Edit || ! currentFilter ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"dataviews-filters__user-input-widget\"\n\t\t\tgap={ 2.5 }\n\t\t\tdirection=\"column\"\n\t\t>\n\t\t\t<field.Edit\n\t\t\t\thideLabelFromVision\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\toperator={ currentFilter.operator }\n\t\t\t\tonChange={ handleChange }\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,IAAI,QAAQ,uBAAuB;;AAE5C;AACA;AACA;;AAEA,SAASC,eAAe,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAS1C,eAAe,SAASC,WAAWA,CAAE;EACpCC,MAAM;EACNC,IAAI;EACJC,YAAY;EACZC;AACqB,CAAC,EAAG;EACzB,MAAMC,aAAa,GAAGH,IAAI,CAACI,OAAO,EAAEC,IAAI,CACrCC,CAAC,IAAMA,CAAC,CAACC,KAAK,KAAKR,MAAM,CAACQ,KAC7B,CAAC;EAED,MAAMA,KAAK,GAAGL,MAAM,CAACG,IAAI,CAAIC,CAAC,IAAMA,CAAC,CAACE,EAAE,KAAKT,MAAM,CAACQ,KAAM,CAAC;EAC3D,MAAME,YAAY,GAAGd,eAAe,CAAEI,MAAM,EAAEI,aAAc,CAAC;EAC7D,MAAMO,IAAI,GAAGjB,OAAO,CAAE,MAAM;IAAA,IAAAkB,aAAA;IAC3B,OAAO,EAAAA,aAAA,GAAEX,IAAI,CAACI,OAAO,cAAAO,aAAA,cAAAA,aAAA,GAAI,EAAE,EAAGC,MAAM,CACnC,CAAEC,GAAG,EAAEP,CAAC,KAAM;MACbO,GAAG,CAAEP,CAAC,CAACC,KAAK,CAAE,GAAGD,CAAC,CAACQ,KAAK;MACxB,OAAOD,GAAG;IACX,CAAC,EACD,CAAC,CACF,CAAC;EACF,CAAC,EAAE,CAAEb,IAAI,CAACI,OAAO,CAAG,CAAC;EAErB,MAAM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sx","_jsx","InputWidget","filter","view","onChangeView","fields","currentFilter","filters","find","f","field","currentValue","currentField","id","isValid","required","custom","getValue","item","setValue","value","data","_view$filters","reduce","acc","activeFilter","handleChange","updatedData","_view$filters2","nextValue","map","_filter","operator","operators","undefined","Edit","className","gap","direction","children","hideLabelFromVision","onChange"],"sources":["@wordpress/dataviews/src/components/dataviews-filters/input-widget.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { View, NormalizedFilter, NormalizedField } from '../../types';\nimport { getCurrentValue } from './utils';\n\ninterface UserInputWidgetProps {\n\tview: View;\n\tfilter: NormalizedFilter;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< any >[];\n}\n\nexport default function InputWidget( {\n\tfilter,\n\tview,\n\tonChangeView,\n\tfields,\n}: UserInputWidgetProps ) {\n\tconst currentFilter = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\tconst currentValue = getCurrentValue( filter, currentFilter );\n\n\t/*\n\t * We are reusing the field.Edit component for filters. By doing so,\n\t * we get for free a filter control specific to the field type\n\t * and other aspects of the field API (Edit control configuration, etc.).\n\t *\n\t * This approach comes with an issue: the field.Edit controls work with getValue\n\t * and setValue methods, which take an item (Item) as parameter. But, at this point,\n\t * we don't have an item and we don't know how to create one, either.\n\t *\n\t * So, what we do is to prepare the data and the relevant field configuration\n\t * as if Item was a plain object whose keys are the field ids:\n\t *\n\t * {\n\t * [ fieldOne.id ]: value,\n\t * [ fieldTwo.id ]: value,\n\t * }\n\t *\n\t */\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Deactivate validation for filters.\n\t\t\t\tisValid: {\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcustom: () => null,\n\t\t\t\t},\n\t\t\t\t// Configure getValue/setValue as if Item was a plain object.\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t\tsetValue: ( { value }: { value: any } ) => ( {\n\t\t\t\t\t[ currentField.id ]: value,\n\t\t\t\t} ),\n\t\t\t};\n\t\t}\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst data = useMemo( () => {\n\t\treturn ( view.filters ?? [] ).reduce(\n\t\t\t( acc, activeFilter ) => {\n\t\t\t\t// We can now assume the field is stored as a Item prop.\n\t\t\t\tacc[ activeFilter.field ] = activeFilter.value;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, any >\n\t\t);\n\t}, [ view.filters ] );\n\n\tconst handleChange = useEvent( ( updatedData: Record< string, any > ) => {\n\t\tif ( ! field || ! currentFilter ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValue = field.getValue( { item: updatedData } );\n\t\tif ( fastDeepEqual( nextValue, currentValue ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChangeView( {\n\t\t\t...view,\n\t\t\tfilters: ( view.filters ?? [] ).map( ( _filter ) =>\n\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\toperator:\n\t\t\t\t\t\t\t\tcurrentFilter.operator || filter.operators[ 0 ],\n\t\t\t\t\t\t\t// Consider empty strings as undefined:\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records\n\t\t\t\t\t\t\t// - empty string as value means \"search empty string\": returns only the records that have an empty string as value\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// In practice, this means the filter will not be able to find an empty string as the value.\n\t\t\t\t\t\t\tvalue: nextValue === '' ? undefined : nextValue,\n\t\t\t\t\t }\n\t\t\t\t\t: _filter\n\t\t\t),\n\t\t} );\n\t} );\n\n\tif ( ! field || ! field.Edit || ! currentFilter ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"dataviews-filters__user-input-widget\"\n\t\t\tgap={ 2.5 }\n\t\t\tdirection=\"column\"\n\t\t>\n\t\t\t<field.Edit\n\t\t\t\thideLabelFromVision\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\toperator={ currentFilter.operator }\n\t\t\t\tonChange={ handleChange }\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,qBAAqB;;AAE/C;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,IAAI,QAAQ,uBAAuB;;AAE5C;AACA;AACA;;AAEA,SAASC,eAAe,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAS1C,eAAe,SAASC,WAAWA,CAAE;EACpCC,MAAM;EACNC,IAAI;EACJC,YAAY;EACZC;AACqB,CAAC,EAAG;EACzB,MAAMC,aAAa,GAAGH,IAAI,CAACI,OAAO,EAAEC,IAAI,CACrCC,CAAC,IAAMA,CAAC,CAACC,KAAK,KAAKR,MAAM,CAACQ,KAC7B,CAAC;EACD,MAAMC,YAAY,GAAGb,eAAe,CAAEI,MAAM,EAAEI,aAAc,CAAC;;EAE7D;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAMI,KAAK,GAAGd,OAAO,CAAE,MAAM;IAC5B,MAAMgB,YAAY,GAAGP,MAAM,CAACG,IAAI,CAAIC,CAAC,IAAMA,CAAC,CAACI,EAAE,KAAKX,MAAM,CAACQ,KAAM,CAAC;IAClE,IAAKE,YAAY,EAAG;MACnB,OAAO;QACN,GAAGA,YAAY;QACf;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