@wordpress/dataviews 9.0.1-next.6870dfe5b.0 → 9.0.1-next.a730c9c8c.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 (255) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +107 -12
  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-layout/index.js +3 -1
  6. package/build/components/dataviews-layout/index.js.map +1 -1
  7. package/build/dataform-controls/array.js +9 -7
  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 +9 -3
  18. package/build/dataform-controls/email.js.map +1 -1
  19. package/build/dataform-controls/index.js +27 -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/password.js +47 -0
  24. package/build/dataform-controls/password.js.map +1 -0
  25. package/build/dataform-controls/radio.js +42 -9
  26. package/build/dataform-controls/radio.js.map +1 -1
  27. package/build/dataform-controls/relative-date-control.js +6 -10
  28. package/build/dataform-controls/relative-date-control.js.map +1 -1
  29. package/build/dataform-controls/select.js +41 -10
  30. package/build/dataform-controls/select.js.map +1 -1
  31. package/build/dataform-controls/telephone.js +9 -3
  32. package/build/dataform-controls/telephone.js.map +1 -1
  33. package/build/dataform-controls/text.js +16 -4
  34. package/build/dataform-controls/text.js.map +1 -1
  35. package/build/dataform-controls/textarea.js +81 -0
  36. package/build/dataform-controls/textarea.js.map +1 -0
  37. package/build/dataform-controls/toggle-group.js +36 -6
  38. package/build/dataform-controls/toggle-group.js.map +1 -1
  39. package/build/dataform-controls/toggle.js +33 -22
  40. package/build/dataform-controls/toggle.js.map +1 -1
  41. package/build/dataform-controls/url.js +9 -3
  42. package/build/dataform-controls/url.js.map +1 -1
  43. package/build/dataform-controls/utils/{validated-text.js → validated-input.js} +36 -29
  44. package/build/dataform-controls/utils/validated-input.js.map +1 -0
  45. package/build/dataforms-layouts/panel/dropdown.js +10 -14
  46. package/build/dataforms-layouts/panel/dropdown.js.map +1 -1
  47. package/build/dataforms-layouts/panel/index.js +24 -11
  48. package/build/dataforms-layouts/panel/index.js.map +1 -1
  49. package/build/dataforms-layouts/panel/modal.js +22 -27
  50. package/build/dataforms-layouts/panel/modal.js.map +1 -1
  51. package/build/dataforms-layouts/panel/summary-button.js +67 -0
  52. package/build/dataforms-layouts/panel/summary-button.js.map +1 -0
  53. package/build/dataforms-layouts/regular/index.js +7 -9
  54. package/build/dataforms-layouts/regular/index.js.map +1 -1
  55. package/build/dataviews-layouts/grid/index.js +5 -15
  56. package/build/dataviews-layouts/grid/index.js.map +1 -1
  57. package/build/dataviews-layouts/list/index.js +47 -2
  58. package/build/dataviews-layouts/list/index.js.map +1 -1
  59. package/build/dataviews-layouts/picker-grid/index.js +5 -15
  60. package/build/dataviews-layouts/picker-grid/index.js.map +1 -1
  61. package/build/dataviews-layouts/table/index.js +5 -17
  62. package/build/dataviews-layouts/table/index.js.map +1 -1
  63. package/build/dataviews-layouts/utils/get-data-by-group.js +23 -0
  64. package/build/dataviews-layouts/utils/get-data-by-group.js.map +1 -0
  65. package/build/field-types/index.js +4 -0
  66. package/build/field-types/index.js.map +1 -1
  67. package/build/field-types/password.js +51 -0
  68. package/build/field-types/password.js.map +1 -0
  69. package/build/normalize-fields.js +17 -0
  70. package/build/normalize-fields.js.map +1 -1
  71. package/build/types.js.map +1 -1
  72. package/build/validation.js +1 -1
  73. package/build/validation.js.map +1 -1
  74. package/build-module/components/dataviews-filters/input-widget.js +48 -4
  75. package/build-module/components/dataviews-filters/input-widget.js.map +1 -1
  76. package/build-module/components/dataviews-layout/index.js +3 -1
  77. package/build-module/components/dataviews-layout/index.js.map +1 -1
  78. package/build-module/dataform-controls/array.js +9 -7
  79. package/build-module/dataform-controls/array.js.map +1 -1
  80. package/build-module/dataform-controls/checkbox.js +31 -21
  81. package/build-module/dataform-controls/checkbox.js.map +1 -1
  82. package/build-module/dataform-controls/color.js +28 -24
  83. package/build-module/dataform-controls/color.js.map +1 -1
  84. package/build-module/dataform-controls/date.js +32 -24
  85. package/build-module/dataform-controls/date.js.map +1 -1
  86. package/build-module/dataform-controls/datetime.js +135 -21
  87. package/build-module/dataform-controls/datetime.js.map +1 -1
  88. package/build-module/dataform-controls/email.js +8 -2
  89. package/build-module/dataform-controls/email.js.map +1 -1
  90. package/build-module/dataform-controls/index.js +27 -0
  91. package/build-module/dataform-controls/index.js.map +1 -1
  92. package/build-module/dataform-controls/integer.js +46 -34
  93. package/build-module/dataform-controls/integer.js.map +1 -1
  94. package/build-module/dataform-controls/password.js +38 -0
  95. package/build-module/dataform-controls/password.js.map +1 -0
  96. package/build-module/dataform-controls/radio.js +44 -11
  97. package/build-module/dataform-controls/radio.js.map +1 -1
  98. package/build-module/dataform-controls/relative-date-control.js +6 -10
  99. package/build-module/dataform-controls/relative-date-control.js.map +1 -1
  100. package/build-module/dataform-controls/select.js +43 -12
  101. package/build-module/dataform-controls/select.js.map +1 -1
  102. package/build-module/dataform-controls/telephone.js +8 -2
  103. package/build-module/dataform-controls/telephone.js.map +1 -1
  104. package/build-module/dataform-controls/text.js +15 -3
  105. package/build-module/dataform-controls/text.js.map +1 -1
  106. package/build-module/dataform-controls/textarea.js +74 -0
  107. package/build-module/dataform-controls/textarea.js.map +1 -0
  108. package/build-module/dataform-controls/toggle-group.js +38 -8
  109. package/build-module/dataform-controls/toggle-group.js.map +1 -1
  110. package/build-module/dataform-controls/toggle.js +33 -23
  111. package/build-module/dataform-controls/toggle.js.map +1 -1
  112. package/build-module/dataform-controls/url.js +8 -2
  113. package/build-module/dataform-controls/url.js.map +1 -1
  114. package/build-module/dataform-controls/utils/validated-input.js +76 -0
  115. package/build-module/dataform-controls/utils/validated-input.js.map +1 -0
  116. package/build-module/dataforms-layouts/panel/dropdown.js +10 -15
  117. package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -1
  118. package/build-module/dataforms-layouts/panel/index.js +24 -11
  119. package/build-module/dataforms-layouts/panel/index.js.map +1 -1
  120. package/build-module/dataforms-layouts/panel/modal.js +22 -28
  121. package/build-module/dataforms-layouts/panel/modal.js.map +1 -1
  122. package/build-module/dataforms-layouts/panel/summary-button.js +60 -0
  123. package/build-module/dataforms-layouts/panel/summary-button.js.map +1 -0
  124. package/build-module/dataforms-layouts/regular/index.js +8 -10
  125. package/build-module/dataforms-layouts/regular/index.js.map +1 -1
  126. package/build-module/dataviews-layouts/grid/index.js +6 -16
  127. package/build-module/dataviews-layouts/grid/index.js.map +1 -1
  128. package/build-module/dataviews-layouts/list/index.js +48 -3
  129. package/build-module/dataviews-layouts/list/index.js.map +1 -1
  130. package/build-module/dataviews-layouts/picker-grid/index.js +6 -16
  131. package/build-module/dataviews-layouts/picker-grid/index.js.map +1 -1
  132. package/build-module/dataviews-layouts/table/index.js +5 -17
  133. package/build-module/dataviews-layouts/table/index.js.map +1 -1
  134. package/build-module/dataviews-layouts/utils/get-data-by-group.js +17 -0
  135. package/build-module/dataviews-layouts/utils/get-data-by-group.js.map +1 -0
  136. package/build-module/field-types/index.js +4 -0
  137. package/build-module/field-types/index.js.map +1 -1
  138. package/build-module/field-types/password.js +46 -0
  139. package/build-module/field-types/password.js.map +1 -0
  140. package/build-module/normalize-fields.js +15 -0
  141. package/build-module/normalize-fields.js.map +1 -1
  142. package/build-module/types.js.map +1 -1
  143. package/build-module/validation.js +1 -1
  144. package/build-module/validation.js.map +1 -1
  145. package/build-style/style-rtl.css +9 -6
  146. package/build-style/style.css +9 -6
  147. package/build-types/components/dataform/stories/index.story.d.ts +3 -14
  148. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
  149. package/build-types/components/dataviews/stories/fixtures.d.ts +4 -2
  150. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
  151. package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
  152. package/build-types/dataform-controls/array.d.ts.map +1 -1
  153. package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
  154. package/build-types/dataform-controls/color.d.ts.map +1 -1
  155. package/build-types/dataform-controls/date.d.ts.map +1 -1
  156. package/build-types/dataform-controls/datetime.d.ts.map +1 -1
  157. package/build-types/dataform-controls/email.d.ts.map +1 -1
  158. package/build-types/dataform-controls/index.d.ts +1 -1
  159. package/build-types/dataform-controls/index.d.ts.map +1 -1
  160. package/build-types/dataform-controls/integer.d.ts.map +1 -1
  161. package/build-types/dataform-controls/password.d.ts +3 -0
  162. package/build-types/dataform-controls/password.d.ts.map +1 -0
  163. package/build-types/dataform-controls/radio.d.ts.map +1 -1
  164. package/build-types/dataform-controls/relative-date-control.d.ts +6 -5
  165. package/build-types/dataform-controls/relative-date-control.d.ts.map +1 -1
  166. package/build-types/dataform-controls/select.d.ts.map +1 -1
  167. package/build-types/dataform-controls/telephone.d.ts.map +1 -1
  168. package/build-types/dataform-controls/text.d.ts +1 -1
  169. package/build-types/dataform-controls/text.d.ts.map +1 -1
  170. package/build-types/dataform-controls/textarea.d.ts +6 -0
  171. package/build-types/dataform-controls/textarea.d.ts.map +1 -0
  172. package/build-types/dataform-controls/toggle-group.d.ts.map +1 -1
  173. package/build-types/dataform-controls/toggle.d.ts.map +1 -1
  174. package/build-types/dataform-controls/url.d.ts.map +1 -1
  175. package/build-types/dataform-controls/utils/validated-input.d.ts +20 -0
  176. package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -0
  177. package/build-types/dataforms-layouts/panel/dropdown.d.ts +2 -1
  178. package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -1
  179. package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
  180. package/build-types/dataforms-layouts/panel/modal.d.ts +2 -1
  181. package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -1
  182. package/build-types/dataforms-layouts/panel/summary-button.d.ts +15 -0
  183. package/build-types/dataforms-layouts/panel/summary-button.d.ts.map +1 -0
  184. package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
  185. package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
  186. package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
  187. package/build-types/dataviews-layouts/picker-grid/index.d.ts.map +1 -1
  188. package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
  189. package/build-types/dataviews-layouts/utils/get-data-by-group.d.ts +6 -0
  190. package/build-types/dataviews-layouts/utils/get-data-by-group.d.ts.map +1 -0
  191. package/build-types/field-types/index.d.ts.map +1 -1
  192. package/build-types/field-types/password.d.ts +17 -0
  193. package/build-types/field-types/password.d.ts.map +1 -0
  194. package/build-types/field-types/stories/index.story.d.ts +5 -1
  195. package/build-types/field-types/stories/index.story.d.ts.map +1 -1
  196. package/build-types/normalize-fields.d.ts +3 -0
  197. package/build-types/normalize-fields.d.ts.map +1 -1
  198. package/build-types/types.d.ts +67 -4
  199. package/build-types/types.d.ts.map +1 -1
  200. package/build-types/validation.d.ts.map +1 -1
  201. package/build-wp/index.js +1670 -1350
  202. package/package.json +16 -15
  203. package/src/components/dataform/stories/index.story.tsx +489 -17
  204. package/src/components/dataviews/stories/fixtures.tsx +99 -41
  205. package/src/components/dataviews/stories/index.story.tsx +2 -2
  206. package/src/components/dataviews-filters/input-widget.tsx +44 -5
  207. package/src/components/dataviews-layout/index.tsx +1 -1
  208. package/src/components/dataviews-picker/stories/index.story.tsx +1 -1
  209. package/src/dataform-controls/array.tsx +4 -6
  210. package/src/dataform-controls/checkbox.tsx +41 -24
  211. package/src/dataform-controls/color.tsx +33 -24
  212. package/src/dataform-controls/date.tsx +47 -21
  213. package/src/dataform-controls/datetime.tsx +171 -23
  214. package/src/dataform-controls/email.tsx +10 -2
  215. package/src/dataform-controls/index.tsx +30 -0
  216. package/src/dataform-controls/integer.tsx +82 -49
  217. package/src/dataform-controls/password.tsx +50 -0
  218. package/src/dataform-controls/radio.tsx +53 -11
  219. package/src/dataform-controls/relative-date-control.tsx +11 -10
  220. package/src/dataform-controls/select.tsx +53 -10
  221. package/src/dataform-controls/telephone.tsx +10 -2
  222. package/src/dataform-controls/text.tsx +19 -2
  223. package/src/dataform-controls/textarea.tsx +85 -0
  224. package/src/dataform-controls/toggle-group.tsx +50 -10
  225. package/src/dataform-controls/toggle.tsx +41 -24
  226. package/src/dataform-controls/url.tsx +10 -2
  227. package/src/dataform-controls/utils/validated-input.tsx +109 -0
  228. package/src/dataforms-layouts/panel/dropdown.tsx +12 -23
  229. package/src/dataforms-layouts/panel/index.tsx +39 -16
  230. package/src/dataforms-layouts/panel/modal.tsx +24 -30
  231. package/src/dataforms-layouts/panel/summary-button.tsx +92 -0
  232. package/src/dataforms-layouts/regular/index.tsx +9 -7
  233. package/src/dataforms-layouts/regular/style.scss +0 -6
  234. package/src/dataviews-layouts/grid/index.tsx +9 -14
  235. package/src/dataviews-layouts/grid/style.scss +1 -0
  236. package/src/dataviews-layouts/list/index.tsx +74 -2
  237. package/src/dataviews-layouts/list/style.scss +8 -0
  238. package/src/dataviews-layouts/picker-grid/index.tsx +9 -13
  239. package/src/dataviews-layouts/table/index.tsx +10 -14
  240. package/src/dataviews-layouts/utils/get-data-by-group.ts +18 -0
  241. package/src/field-types/index.tsx +5 -0
  242. package/src/field-types/password.tsx +46 -0
  243. package/src/field-types/stories/index.story.tsx +138 -1
  244. package/src/normalize-fields.ts +18 -0
  245. package/src/test/filter-and-sort-data-view.js +148 -138
  246. package/src/test/normalize-fields.ts +114 -0
  247. package/src/types.ts +74 -3
  248. package/src/validation.ts +2 -0
  249. package/tsconfig.tsbuildinfo +1 -1
  250. package/build/dataform-controls/utils/validated-text.js.map +0 -1
  251. package/build-module/dataform-controls/utils/validated-text.js +0 -70
  252. package/build-module/dataform-controls/utils/validated-text.js.map +0 -1
  253. package/build-types/dataform-controls/utils/validated-text.d.ts +0 -16
  254. package/build-types/dataform-controls/utils/validated-text.d.ts.map +0 -1
  255. package/src/dataform-controls/utils/validated-text.tsx +0 -96
@@ -1,13 +1,23 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import deepMerge from 'deepmerge';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
- import { RadioControl } from '@wordpress/components';
5
- import { useCallback } from '@wordpress/element';
9
+ import { privateApis } from '@wordpress/components';
10
+ import { useCallback, useState } from '@wordpress/element';
6
11
 
7
12
  /**
8
13
  * Internal dependencies
9
14
  */
15
+
16
+ import { unlock } from '../lock-unlock';
10
17
  import { jsx as _jsx } from "react/jsx-runtime";
18
+ const {
19
+ ValidatedRadioControl
20
+ } = unlock(privateApis);
11
21
  export default function Radio({
12
22
  data,
13
23
  field,
@@ -15,20 +25,43 @@ export default function Radio({
15
25
  hideLabelFromVision
16
26
  }) {
17
27
  const {
18
- id,
19
- label
28
+ label,
29
+ description,
30
+ elements,
31
+ getValue,
32
+ setValue
20
33
  } = field;
21
- const value = field.getValue({
34
+ const value = getValue({
22
35
  item: data
23
36
  });
24
- const onChangeControl = useCallback(newValue => onChange({
25
- [id]: newValue
26
- }), [id, onChange]);
27
- if (field.elements) {
28
- return /*#__PURE__*/_jsx(RadioControl, {
37
+ const [customValidity, setCustomValidity] = useState(undefined);
38
+ const onChangeControl = useCallback(newValue => onChange(setValue({
39
+ item: data,
40
+ value: newValue
41
+ })), [data, onChange, setValue]);
42
+ const onValidateControl = useCallback(newValue => {
43
+ const message = field.isValid?.custom?.(deepMerge(data, setValue({
44
+ item: data,
45
+ value: newValue
46
+ })), field);
47
+ if (message) {
48
+ setCustomValidity({
49
+ type: 'invalid',
50
+ message
51
+ });
52
+ return;
53
+ }
54
+ setCustomValidity(undefined);
55
+ }, [data, field, setValue]);
56
+ if (elements) {
57
+ return /*#__PURE__*/_jsx(ValidatedRadioControl, {
58
+ required: !!field.isValid?.required,
59
+ onValidate: onValidateControl,
60
+ customValidity: customValidity,
29
61
  label: label,
62
+ help: description,
30
63
  onChange: onChangeControl,
31
- options: field.elements,
64
+ options: elements,
32
65
  selected: value,
33
66
  hideLabelFromVision: hideLabelFromVision
34
67
  });
@@ -1 +1 @@
1
- {"version":3,"names":["RadioControl","useCallback","jsx","_jsx","Radio","data","field","onChange","hideLabelFromVision","id","label","value","getValue","item","onChangeControl","newValue","elements","options","selected"],"sources":["@wordpress/dataviews/src/dataform-controls/radio.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RadioControl } from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\n\nexport default function Radio< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label } = field;\n\tconst value = field.getValue( { item: data } );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\tif ( field.elements ) {\n\t\treturn (\n\t\t\t<RadioControl\n\t\t\t\tlabel={ label }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\toptions={ field.elements }\n\t\t\t\tselected={ value }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,uBAAuB;AACpD,SAASC,WAAW,QAAQ,oBAAoB;;AAEhD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAKA,eAAe,SAASC,KAAKA,CAAU;EACtCC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,EAAE;IAAEC;EAAM,CAAC,GAAGJ,KAAK;EAC3B,MAAMK,KAAK,GAAGL,KAAK,CAACM,QAAQ,CAAE;IAAEC,IAAI,EAAER;EAAK,CAAE,CAAC;EAE9C,MAAMS,eAAe,GAAGb,WAAW,CAChCc,QAAgB,IACjBR,QAAQ,CAAE;IACT,CAAEE,EAAE,GAAIM;EACT,CAAE,CAAC,EACJ,CAAEN,EAAE,EAAEF,QAAQ,CACf,CAAC;EAED,IAAKD,KAAK,CAACU,QAAQ,EAAG;IACrB,oBACCb,IAAA,CAACH,YAAY;MACZU,KAAK,EAAGA,KAAO;MACfH,QAAQ,EAAGO,eAAiB;MAC5BG,OAAO,EAAGX,KAAK,CAACU,QAAU;MAC1BE,QAAQ,EAAGP,KAAO;MAClBH,mBAAmB,EAAGA;IAAqB,CAC3C,CAAC;EAEJ;EAEA,OAAO,IAAI;AACZ","ignoreList":[]}
1
+ {"version":3,"names":["deepMerge","privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedRadioControl","Radio","data","field","onChange","hideLabelFromVision","label","description","elements","getValue","setValue","value","item","customValidity","setCustomValidity","undefined","onChangeControl","newValue","onValidateControl","message","isValid","custom","type","required","onValidate","help","options","selected"],"sources":["@wordpress/dataviews/src/dataform-controls/radio.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { useCallback, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport { unlock } from '../lock-unlock';\n\nconst { ValidatedRadioControl } = unlock( privateApis );\n\nexport default function Radio< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { label, description, elements, getValue, setValue } = field;\n\tconst value = getValue( { item: data } );\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedRadioControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\n\tconst onValidateControl = useCallback(\n\t\t( newValue: any ) => {\n\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\tdeepMerge(\n\t\t\t\t\tdata,\n\t\t\t\t\tsetValue( {\n\t\t\t\t\t\titem: data,\n\t\t\t\t\t\tvalue: newValue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tfield\n\t\t\t);\n\n\t\t\tif ( message ) {\n\t\t\t\tsetCustomValidity( {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetCustomValidity( undefined );\n\t\t},\n\t\t[ data, field, setValue ]\n\t);\n\n\tif ( elements ) {\n\t\treturn (\n\t\t\t<ValidatedRadioControl\n\t\t\t\trequired={ !! field.isValid?.required }\n\t\t\t\tonValidate={ onValidateControl }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\tlabel={ label }\n\t\t\t\thelp={ description }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\toptions={ elements }\n\t\t\t\tselected={ value }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;;AAE1D;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAM;EAAEC;AAAsB,CAAC,GAAGH,MAAM,CAAE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P,KAAK,EAAGA,KAAO;MACfmB,IAAI,EAAGlB,WAAa;MACpBH,QAAQ,EAAGY,eAAiB;MAC5BU,OAAO,EAAGlB,QAAU;MACpBmB,QAAQ,EAAGhB,KAAO;MAClBN,mBAAmB,EAAGA;IAAqB,CAC3C,CAAC;EAEJ;EAEA,OAAO,IAAI;AACZ","ignoreList":[]}
@@ -57,17 +57,13 @@ export default function RelativeDateControl({
57
57
  unit = options[0].value
58
58
  } = value;
59
59
  const onChangeValue = useCallback(newValue => onChange({
60
- [id]: {
61
- value: Number(newValue),
62
- unit
63
- }
64
- }), [id, onChange, unit]);
60
+ value: Number(newValue),
61
+ unit
62
+ }), [onChange, unit]);
65
63
  const onChangeUnit = useCallback(newUnit => onChange({
66
- [id]: {
67
- value: relValue,
68
- unit: newUnit
69
- }
70
- }), [id, onChange, relValue]);
64
+ value: relValue,
65
+ unit: newUnit
66
+ }), [onChange, relValue]);
71
67
  return /*#__PURE__*/_jsx(BaseControl, {
72
68
  id: id,
73
69
  __nextHasNoMarginBottom: true,
@@ -1 +1 @@
1
- {"version":3,"names":["clsx","BaseControl","SelectControl","__experimentalNumberControl","NumberControl","__experimentalHStack","HStack","useCallback","__","OPERATOR_IN_THE_PAST","OPERATOR_OVER","jsx","_jsx","jsxs","_jsxs","TIME_UNITS_OPTIONS","value","label","RelativeDateControl","id","onChange","hideLabelFromVision","options","className","relValue","unit","onChangeValue","newValue","Number","onChangeUnit","newUnit","__nextHasNoMarginBottom","children","spacing","__next40pxDefaultSize","spinControls","min","step"],"sources":["@wordpress/dataviews/src/dataform-controls/relative-date-control.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tSelectControl,\n\t__experimentalNumberControl as NumberControl,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { OPERATOR_IN_THE_PAST, OPERATOR_OVER } from '../constants';\n\ninterface RelativeDateControlProps {\n\tid: string;\n\tvalue: { value?: string | number; unit?: string };\n\tonChange: ( value: any ) => void;\n\tlabel: string;\n\thideLabelFromVision?: boolean;\n\toptions: { value: string; label: string }[];\n\tclassName?: string;\n}\n\nexport const TIME_UNITS_OPTIONS = {\n\t[ OPERATOR_IN_THE_PAST ]: [\n\t\t{ value: 'days', label: __( 'Days' ) },\n\t\t{ value: 'weeks', label: __( 'Weeks' ) },\n\t\t{ value: 'months', label: __( 'Months' ) },\n\t\t{ value: 'years', label: __( 'Years' ) },\n\t],\n\t[ OPERATOR_OVER ]: [\n\t\t{ value: 'days', label: __( 'Days ago' ) },\n\t\t{ value: 'weeks', label: __( 'Weeks ago' ) },\n\t\t{ value: 'months', label: __( 'Months ago' ) },\n\t\t{ value: 'years', label: __( 'Years ago' ) },\n\t],\n};\n\nexport default function RelativeDateControl( {\n\tid,\n\tvalue,\n\tonChange,\n\tlabel,\n\thideLabelFromVision,\n\toptions,\n\tclassName,\n}: RelativeDateControlProps ) {\n\tconst { value: relValue = '', unit = options[ 0 ].value } = value;\n\n\tconst onChangeValue = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: { value: Number( newValue ), unit },\n\t\t\t} ),\n\t\t[ id, onChange, unit ]\n\t);\n\n\tconst onChangeUnit = useCallback(\n\t\t( newUnit: string | undefined ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: { value: relValue, unit: newUnit },\n\t\t\t} ),\n\t\t[ id, onChange, relValue ]\n\t);\n\n\treturn (\n\t\t<BaseControl\n\t\t\tid={ id }\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName={ clsx( className, 'dataviews-controls__relative-date' ) }\n\t\t\tlabel={ label }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t>\n\t\t\t<HStack spacing={ 2.5 }>\n\t\t\t\t<NumberControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tclassName=\"dataviews-controls__relative-date-number\"\n\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\tmin={ 1 }\n\t\t\t\t\tstep={ 1 }\n\t\t\t\t\tvalue={ relValue }\n\t\t\t\t\tonChange={ onChangeValue }\n\t\t\t\t/>\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-controls__relative-date-unit\"\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Unit' ) }\n\t\t\t\t\tvalue={ unit }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ onChangeUnit }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t</BaseControl>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,WAAW,EACXC,aAAa,EACbC,2BAA2B,IAAIC,aAAa,EAC5CC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAYnE,OAAO,MAAMC,kBAAkB,GAAG;EACjC,CAAEN,oBAAoB,GAAI,CACzB;IAAEO,KAAK,EAAE,MAAM;IAAEC,KAAK,EAAET,EAAE,CAAE,MAAO;EAAE,CAAC,EACtC;IAAEQ,KAAK,EAAE,OAAO;IAAEC,KAAK,EAAET,EAAE,CAAE,OAAQ;EAAE,CAAC,EACxC;IAAEQ,KAAK,EAAE,QAAQ;IAAEC,KAAK,EAAET,EAAE,CAAE,QAAS;EAAE,CAAC,EAC1C;IAAEQ,KAAK,EAAE,OAAO;IAAEC,KAAK,EAAET,EA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AAEuB,SAAS,EAAE,mCAAoC,CAAG;IACpEN,KAAK,EAAGA,KAAO;IACfI,mBAAmB,EAAGA,mBAAqB;IAAAW,QAAA,eAE3ClB,KAAA,CAACR,MAAM;MAAC2B,OAAO,EAAG,GAAK;MAAAD,QAAA,gBACtBpB,IAAA,CAACR,aAAa;QACb8B,qBAAqB;QACrBX,SAAS,EAAC,0CAA0C;QACpDY,YAAY,EAAC,MAAM;QACnBC,GAAG,EAAG,CAAG;QACTC,IAAI,EAAG,CAAG;QACVrB,KAAK,EAAGQ,QAAU;QAClBJ,QAAQ,EAAGM;MAAe,CAC1B,CAAC,eACFd,IAAA,CAACV,aAAa;QACbqB,SAAS,EAAC,wCAAwC;QAClDW,qBAAqB;QACrBH,uBAAuB;QACvBd,KAAK,EAAGT,EAAE,CAAE,MAAO,CAAG;QACtBQ,KAAK,EAAGS,IAAM;QACdH,OAAO,EAAGA,OAAS;QACnBF,QAAQ,EAAGS,YAAc;QACzBR,mBAAmB;MAAA,CACnB,CAAC;IAAA,CACK;EAAC,CACG,CAAC;AAEhB","ignoreList":[]}
1
+ {"version":3,"names":["clsx","BaseControl","SelectControl","__experimentalNumberControl","NumberControl","__experimentalHStack","HStack","useCallback","__","OPERATOR_IN_THE_PAST","OPERATOR_OVER","jsx","_jsx","jsxs","_jsxs","TIME_UNITS_OPTIONS","value","label","RelativeDateControl","id","onChange","hideLabelFromVision","options","className","relValue","unit","onChangeValue","newValue","Number","onChangeUnit","newUnit","__nextHasNoMarginBottom","children","spacing","__next40pxDefaultSize","spinControls","min","step"],"sources":["@wordpress/dataviews/src/dataform-controls/relative-date-control.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tBaseControl,\n\tSelectControl,\n\t__experimentalNumberControl as NumberControl,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { OPERATOR_IN_THE_PAST, OPERATOR_OVER } from '../constants';\n\nexport type DateRelative = {\n\tvalue?: string | number;\n\tunit?: string;\n};\n\ninterface RelativeDateControlProps {\n\tid: string;\n\tvalue: DateRelative;\n\tonChange: ( args: DateRelative ) => void;\n\tlabel: string;\n\thideLabelFromVision?: boolean;\n\toptions: { value: string; label: string }[];\n\tclassName?: string;\n}\n\nexport const TIME_UNITS_OPTIONS = {\n\t[ OPERATOR_IN_THE_PAST ]: [\n\t\t{ value: 'days', label: __( 'Days' ) },\n\t\t{ value: 'weeks', label: __( 'Weeks' ) },\n\t\t{ value: 'months', label: __( 'Months' ) },\n\t\t{ value: 'years', label: __( 'Years' ) },\n\t],\n\t[ OPERATOR_OVER ]: [\n\t\t{ value: 'days', label: __( 'Days ago' ) },\n\t\t{ value: 'weeks', label: __( 'Weeks ago' ) },\n\t\t{ value: 'months', label: __( 'Months ago' ) },\n\t\t{ value: 'years', label: __( 'Years ago' ) },\n\t],\n};\n\nexport default function RelativeDateControl( {\n\tid,\n\tvalue,\n\tonChange,\n\tlabel,\n\thideLabelFromVision,\n\toptions,\n\tclassName,\n}: RelativeDateControlProps ) {\n\tconst { value: relValue = '', unit = options[ 0 ].value } = value;\n\n\tconst onChangeValue = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( { value: Number( newValue ), unit } ),\n\t\t[ onChange, unit ]\n\t);\n\n\tconst onChangeUnit = useCallback(\n\t\t( newUnit: string | undefined ) =>\n\t\t\tonChange( { value: relValue, unit: newUnit } ),\n\t\t[ onChange, relValue ]\n\t);\n\n\treturn (\n\t\t<BaseControl\n\t\t\tid={ id }\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName={ clsx( className, 'dataviews-controls__relative-date' ) }\n\t\t\tlabel={ label }\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t>\n\t\t\t<HStack spacing={ 2.5 }>\n\t\t\t\t<NumberControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tclassName=\"dataviews-controls__relative-date-number\"\n\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\tmin={ 1 }\n\t\t\t\t\tstep={ 1 }\n\t\t\t\t\tvalue={ relValue }\n\t\t\t\t\tonChange={ onChangeValue }\n\t\t\t\t/>\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-controls__relative-date-unit\"\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Unit' ) }\n\t\t\t\t\tvalue={ unit }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ onChangeUnit }\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t</BaseControl>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,WAAW,EACXC,aAAa,EACbC,2BAA2B,IAAIC,aAAa,EAC5CC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAiBnE,OAAO,MAAMC,kBAAkB,GAAG;EACjC,CAAEN,oBAAoB,GAAI,CACzB;IAAEO,KAAK,EAAE,MAAM;IAAEC,KAAK,EAAET,EAAE,CAAE,MAAO;EAAE,CAAC,EACtC;IAAEQ,KAAK,EAAE,OAAO;IAAEC,KAAK,EAAET,EAAE,CAAE,OAAQ;EAAE,CAAC,EACxC;IAAEQ,KAAK,EAAE,QAAQ;IAAEC,KAAK,EAAET,EAAE,CAAE,QAAS;EAAE,CAAC,EAC1C;IAAEQ,KAAK,EAAE,OAAO;IAAEC,KAAK,EAAET,EAAE,CA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;IAAAW,QAAA,eAE3ClB,KAAA,CAACR,MAAM;MAAC2B,OAAO,EAAG,GAAK;MAAAD,QAAA,gBACtBpB,IAAA,CAACR,aAAa;QACb8B,qBAAqB;QACrBX,SAAS,EAAC,0CAA0C;QACpDY,YAAY,EAAC,MAAM;QACnBC,GAAG,EAAG,CAAG;QACTC,IAAI,EAAG,CAAG;QACVrB,KAAK,EAAGQ,QAAU;QAClBJ,QAAQ,EAAGM;MAAe,CAC1B,CAAC,eACFd,IAAA,CAACV,aAAa;QACbqB,SAAS,EAAC,wCAAwC;QAClDW,qBAAqB;QACrBH,uBAAuB;QACvBd,KAAK,EAAGT,EAAE,CAAE,MAAO,CAAG;QACtBQ,KAAK,EAAGS,IAAM;QACdH,OAAO,EAAGA,OAAS;QACnBF,QAAQ,EAAGS,YAAc;QACzBR,mBAAmB;MAAA,CACnB,CAAC;IAAA,CACK;EAAC,CACG,CAAC;AAEhB","ignoreList":[]}
@@ -1,33 +1,61 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import deepMerge from 'deepmerge';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
- import { SelectControl } from '@wordpress/components';
5
- import { useCallback } from '@wordpress/element';
9
+ import { privateApis } from '@wordpress/components';
10
+ import { useCallback, useState } from '@wordpress/element';
6
11
  import { __ } from '@wordpress/i18n';
7
12
 
8
13
  /**
9
14
  * Internal dependencies
10
15
  */
16
+
17
+ import { unlock } from '../lock-unlock';
11
18
  import { jsx as _jsx } from "react/jsx-runtime";
19
+ const {
20
+ ValidatedSelectControl
21
+ } = unlock(privateApis);
12
22
  export default function Select({
13
23
  data,
14
24
  field,
15
25
  onChange,
16
26
  hideLabelFromVision
17
27
  }) {
18
- var _field$getValue, _field$elements;
28
+ var _getValue, _field$elements;
19
29
  const {
20
- id,
30
+ type,
21
31
  label,
22
- type
32
+ description,
33
+ getValue,
34
+ setValue
23
35
  } = field;
36
+ const [customValidity, setCustomValidity] = useState(undefined);
24
37
  const isMultiple = type === 'array';
25
- const value = (_field$getValue = field.getValue({
38
+ const value = (_getValue = getValue({
26
39
  item: data
27
- })) !== null && _field$getValue !== void 0 ? _field$getValue : isMultiple ? [] : '';
28
- const onChangeControl = useCallback(newValue => onChange({
29
- [id]: newValue
30
- }), [id, onChange]);
40
+ })) !== null && _getValue !== void 0 ? _getValue : isMultiple ? [] : '';
41
+ const onChangeControl = useCallback(newValue => onChange(setValue({
42
+ item: data,
43
+ value: newValue
44
+ })), [data, onChange, setValue]);
45
+ const onValidateControl = useCallback(newValue => {
46
+ const message = field.isValid?.custom?.(deepMerge(data, setValue({
47
+ item: data,
48
+ value: newValue
49
+ })), field);
50
+ if (message) {
51
+ setCustomValidity({
52
+ type: 'invalid',
53
+ message
54
+ });
55
+ return;
56
+ }
57
+ setCustomValidity(undefined);
58
+ }, [data, field, setValue]);
31
59
  const fieldElements = (_field$elements = field?.elements) !== null && _field$elements !== void 0 ? _field$elements : [];
32
60
  const hasEmptyValue = fieldElements.some(({
33
61
  value: elementValue
@@ -44,10 +72,13 @@ export default function Select({
44
72
  label: __('Select item'),
45
73
  value: ''
46
74
  }, ...fieldElements];
47
- return /*#__PURE__*/_jsx(SelectControl, {
75
+ return /*#__PURE__*/_jsx(ValidatedSelectControl, {
76
+ required: !!field.isValid?.required,
77
+ onValidate: onValidateControl,
78
+ customValidity: customValidity,
48
79
  label: label,
49
80
  value: value,
50
- help: field.description,
81
+ help: description,
51
82
  options: elements,
52
83
  onChange: onChangeControl,
53
84
  __next40pxDefaultSize: true,
@@ -1 +1 @@
1
- {"version":3,"names":["SelectControl","useCallback","__","jsx","_jsx","Select","data","field","onChange","hideLabelFromVision","_field$getValue","_field$elements","id","label","type","isMultiple","value","getValue","item","onChangeControl","newValue","fieldElements","elements","hasEmptyValue","some","elementValue","help","description","options","__next40pxDefaultSize","__nextHasNoMarginBottom","multiple"],"sources":["@wordpress/dataviews/src/dataform-controls/select.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SelectControl } from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\n\nexport default function Select< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, type } = field;\n\tconst isMultiple = type === 'array';\n\tconst value = field.getValue( { item: data } ) ?? ( isMultiple ? [] : '' );\n\tconst onChangeControl = useCallback(\n\t\t( newValue: any ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\tconst fieldElements = field?.elements ?? [];\n\tconst hasEmptyValue = fieldElements.some(\n\t\t( { value: elementValue } ) => elementValue === ''\n\t);\n\n\tconst elements =\n\t\thasEmptyValue || isMultiple\n\t\t\t? fieldElements\n\t\t\t: [\n\t\t\t\t\t/*\n\t\t\t\t\t * Value can be undefined when:\n\t\t\t\t\t *\n\t\t\t\t\t * - the field is not required\n\t\t\t\t\t * - in bulk editing\n\t\t\t\t\t *\n\t\t\t\t\t */\n\t\t\t\t\t{ label: __( 'Select item' ), value: '' },\n\t\t\t\t\t...fieldElements,\n\t\t\t ];\n\n\treturn (\n\t\t<SelectControl\n\t\t\tlabel={ label }\n\t\t\tvalue={ value }\n\t\t\thelp={ field.description }\n\t\t\toptions={ elements }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tmultiple={ isMultiple }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,uBAAuB;AACrD,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAKA,eAAe,SAASC,MAAMA,CAAU;EACvCC,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AC;AAEJ","ignoreList":[]}
1
+ {"version":3,"names":["deepMerge","privateApis","useCallback","useState","__","unlock","jsx","_jsx","ValidatedSelectControl","Select","data","field","onChange","hideLabelFromVision","_getValue","_field$elements","type","label","description","getValue","setValue","customValidity","setCustomValidity","undefined","isMultiple","value","item","onChangeControl","newValue","onValidateControl","message","isValid","custom","fieldElements","elements","hasEmptyValue","some","elementValue","required","onValidate","help","options","__next40pxDefaultSize","__nextHasNoMarginBottom","multiple"],"sources":["@wordpress/dataviews/src/dataform-controls/select.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport { unlock } from '../lock-unlock';\n\nconst { ValidatedSelectControl } = unlock( privateApis );\n\nexport default function Select< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { type, label, description, getValue, setValue } = field;\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedSelectControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst isMultiple = type === 'array';\n\tconst value = getValue( { item: data } ) ?? ( isMultiple ? [] : '' );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: any ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\n\tconst onValidateControl = useCallback(\n\t\t( newValue: any ) => {\n\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\tdeepMerge(\n\t\t\t\t\tdata,\n\t\t\t\t\tsetValue( {\n\t\t\t\t\t\titem: data,\n\t\t\t\t\t\tvalue: newValue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tfield\n\t\t\t);\n\n\t\t\tif ( message ) {\n\t\t\t\tsetCustomValidity( {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetCustomValidity( undefined );\n\t\t},\n\t\t[ data, field, setValue ]\n\t);\n\n\tconst fieldElements = field?.elements ?? [];\n\tconst hasEmptyValue = fieldElements.some(\n\t\t( { value: elementValue } ) => elementValue === ''\n\t);\n\n\tconst elements =\n\t\thasEmptyValue || isMultiple\n\t\t\t? fieldElements\n\t\t\t: [\n\t\t\t\t\t/*\n\t\t\t\t\t * Value can be undefined when:\n\t\t\t\t\t *\n\t\t\t\t\t * - the field is not required\n\t\t\t\t\t * - in bulk editing\n\t\t\t\t\t *\n\t\t\t\t\t */\n\t\t\t\t\t{ label: __( 'Select item' ), value: '' },\n\t\t\t\t\t...fieldElements,\n\t\t\t ];\n\n\treturn (\n\t\t<ValidatedSelectControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tonValidate={ onValidateControl }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tlabel={ label }\n\t\t\tvalue={ value }\n\t\t\thelp={ description }\n\t\t\toptions={ elements }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tmultiple={ isMultiple }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAM;EAAEC;AAAuB,CAAC,GAAGH,MAAM,C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AAA,GAAGJ,KAAK,EAAEuB,QAAQ,cAAAnB,eAAA,cAAAA,eAAA,GAAI,EAAE;EAC3C,MAAMoB,aAAa,GAAGF,aAAa,CAACG,IAAI,CACvC,CAAE;IAAEX,KAAK,EAAEY;EAAa,CAAC,KAAMA,YAAY,KAAK,EACjD,CAAC;EAED,MAAMH,QAAQ,GACbC,aAAa,IAAIX,UAAU,GACxBS,aAAa,GACb;EACA;AACL;AACA;AACA;AACA;AACA;AACA;EACK;IAAEhB,KAAK,EAAEb,EAAE,CAAE,aAAc,CAAC;IAAEqB,KAAK,EAAE;EAAG,CAAC,EACzC,GAAGQ,aAAa,CACf;EAEL,oBACC1B,IAAA,CAACC,sBAAsB;IACtB8B,QAAQ,EAAG,CAAC,CAAE3B,KAAK,CAACoB,OAAO,EAAEO,QAAU;IACvCC,UAAU,EAAGV,iBAAmB;IAChCR,cAAc,EAAGA,cAAgB;IACjCJ,KAAK,EAAGA,KAAO;IACfQ,KAAK,EAAGA,KAAO;IACfe,IAAI,EAAGtB,WAAa;IACpBuB,OAAO,EAAGP,QAAU;IACpBtB,QAAQ,EAAGe,eAAiB;IAC5Be,qBAAqB;IACrBC,uBAAuB;IACvB9B,mBAAmB,EAAGA,mBAAqB;IAC3C+B,QAAQ,EAAGpB;EAAY,CACvB,CAAC;AAEJ","ignoreList":[]}
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
+ import { Icon, __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper } from '@wordpress/components';
4
5
  import { mobile } from '@wordpress/icons';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
10
 
10
- import ValidatedText from './utils/validated-text';
11
+ import ValidatedText from './utils/validated-input';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  export default function Telephone({
13
14
  data,
@@ -21,7 +22,12 @@ export default function Telephone({
21
22
  onChange,
22
23
  hideLabelFromVision,
23
24
  type: 'tel',
24
- icon: mobile
25
+ prefix: /*#__PURE__*/_jsx(InputControlPrefixWrapper, {
26
+ variant: "icon",
27
+ children: /*#__PURE__*/_jsx(Icon, {
28
+ icon: mobile
29
+ })
30
+ })
25
31
  });
26
32
  }
27
33
  //# sourceMappingURL=telephone.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["mobile","ValidatedText","jsx","_jsx","Telephone","data","field","onChange","hideLabelFromVision","type","icon"],"sources":["@wordpress/dataviews/src/dataform-controls/telephone.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { mobile } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-text';\n\nexport default function Telephone< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\treturn (\n\t\t<ValidatedText\n\t\t\t{ ...{\n\t\t\t\tdata,\n\t\t\t\tfield,\n\t\t\t\tonChange,\n\t\t\t\thideLabelFromVision,\n\t\t\t\ttype: 'tel',\n\t\t\t\ticon: mobile,\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,kBAAkB;;AAEzC;AACA;AACA;;AAEA,OAAOC,aAAa,MAAM,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEnD,eAAe,SAASC,SAASA,CAAU;EAC1CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,oBACCL,IAAA,CAACF,aAAa;IAEZI,IAAI;IACJC,KAAK;IACLC,QAAQ;IACRC,mBAAmB;IACnBC,IAAI,EAAE,KAAK;IACXC,IAAI,EAAEV;EAAM,CAEb,CAAC;AAEJ","ignoreList":[]}
1
+ {"version":3,"names":["Icon","__experimentalInputControlPrefixWrapper","InputControlPrefixWrapper","mobile","ValidatedText","jsx","_jsx","Telephone","data","field","onChange","hideLabelFromVision","type","prefix","variant","children","icon"],"sources":["@wordpress/dataviews/src/dataform-controls/telephone.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,\n} from '@wordpress/components';\nimport { mobile } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-input';\n\nexport default function Telephone< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\treturn (\n\t\t<ValidatedText\n\t\t\t{ ...{\n\t\t\t\tdata,\n\t\t\t\tfield,\n\t\t\t\tonChange,\n\t\t\t\thideLabelFromVision,\n\t\t\t\ttype: 'tel',\n\t\t\t\tprefix: (\n\t\t\t\t\t<InputControlPrefixWrapper variant=\"icon\">\n\t\t\t\t\t\t<Icon icon={ mobile } />\n\t\t\t\t\t</InputControlPrefixWrapper>\n\t\t\t\t),\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,IAAI,EACJC,uCAAuC,IAAIC,yBAAyB,QAC9D,uBAAuB;AAC9B,SAASC,MAAM,QAAQ,kBAAkB;;AAEzC;AACA;AACA;;AAEA,OAAOC,aAAa,MAAM,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEpD,eAAe,SAASC,SAASA,CAAU;EAC1CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,oBACCL,IAAA,CAACF,aAAa;IAEZI,IAAI;IACJC,KAAK;IACLC,QAAQ;IACRC,mBAAmB;IACnBC,IAAI,EAAE,KAAK;IACXC,MAAM,eACLP,IAAA,CAACJ,yBAAyB;MAACY,OAAO,EAAC,MAAM;MAAAC,QAAA,eACxCT,IAAA,CAACN,IAAI;QAACgB,IAAI,EAAGb;MAAQ,CAAE;IAAC,CACE;EAC3B,CAEF,CAAC;AAEJ","ignoreList":[]}
@@ -1,20 +1,32 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { createElement } from '@wordpress/element';
5
+
1
6
  /**
2
7
  * Internal dependencies
3
8
  */
4
9
 
5
- import ValidatedText from './utils/validated-text';
10
+ import ValidatedText from './utils/validated-input';
6
11
  import { jsx as _jsx } from "react/jsx-runtime";
7
12
  export default function Text({
8
13
  data,
9
14
  field,
10
15
  onChange,
11
- hideLabelFromVision
16
+ hideLabelFromVision,
17
+ config
12
18
  }) {
19
+ const {
20
+ prefix,
21
+ suffix
22
+ } = config || {};
13
23
  return /*#__PURE__*/_jsx(ValidatedText, {
14
24
  data,
15
25
  field,
16
26
  onChange,
17
- hideLabelFromVision
27
+ hideLabelFromVision,
28
+ prefix: prefix ? createElement(prefix) : undefined,
29
+ suffix: suffix ? createElement(suffix) : undefined
18
30
  });
19
31
  }
20
32
  //# sourceMappingURL=text.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ValidatedText","jsx","_jsx","Text","data","field","onChange","hideLabelFromVision"],"sources":["@wordpress/dataviews/src/dataform-controls/text.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-text';\n\nexport default function Text< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\treturn (\n\t\t<ValidatedText { ...{ data, field, onChange, hideLabelFromVision } } />\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,OAAOA,aAAa,MAAM,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEnD,eAAe,SAASC,IAAIA,CAAU;EACrCC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,oBACCL,IAAA,CAACF,aAAa;IAAQI,IAAI;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAmB,CAAM,CAAC;AAEzE","ignoreList":[]}
1
+ {"version":3,"names":["createElement","ValidatedText","jsx","_jsx","Text","data","field","onChange","hideLabelFromVision","config","prefix","suffix","undefined"],"sources":["@wordpress/dataviews/src/dataform-controls/text.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createElement } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-input';\n\nexport default function Text< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tconfig,\n}: DataFormControlProps< Item > ) {\n\tconst { prefix, suffix } = config || {};\n\n\treturn (\n\t\t<ValidatedText\n\t\t\t{ ...{\n\t\t\t\tdata,\n\t\t\t\tfield,\n\t\t\t\tonChange,\n\t\t\t\thideLabelFromVision,\n\t\t\t\tprefix: prefix ? createElement( prefix ) : undefined,\n\t\t\t\tsuffix: suffix ? createElement( suffix ) : undefined,\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,oBAAoB;;AAElD;AACA;AACA;;AAEA,OAAOC,aAAa,MAAM,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEpD,eAAe,SAASC,IAAIA,CAAU;EACrCC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC,mBAAmB;EACnBC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM,IAAI,CAAC,CAAC;EAEvC,oBACCN,IAAA,CAACF,aAAa;IAEZI,IAAI;IACJC,KAAK;IACLC,QAAQ;IACRC,mBAAmB;IACnBE,MAAM,EAAEA,MAAM,GAAGV,aAAa,CAAEU,MAAO,CAAC,GAAGE,SAAS;IACpDD,MAAM,EAAEA,MAAM,GAAGX,aAAa,CAAEW,MAAO,CAAC,GAAGC;EAAS,CAErD,CAAC;AAEJ","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import deepMerge from 'deepmerge';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { privateApis } from '@wordpress/components';
10
+ import { useCallback, useState } from '@wordpress/element';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+
16
+ import { unlock } from '../lock-unlock';
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ const {
19
+ ValidatedTextareaControl
20
+ } = unlock(privateApis);
21
+ export default function Textarea({
22
+ data,
23
+ field,
24
+ onChange,
25
+ hideLabelFromVision,
26
+ config
27
+ }) {
28
+ const {
29
+ rows = 4
30
+ } = config || {};
31
+ const {
32
+ label,
33
+ placeholder,
34
+ description,
35
+ setValue
36
+ } = field;
37
+ const value = field.getValue({
38
+ item: data
39
+ });
40
+ const [customValidity, setCustomValidity] = useState(undefined);
41
+ const onChangeControl = useCallback(newValue => onChange(setValue({
42
+ item: data,
43
+ value: newValue
44
+ })), [data, onChange, setValue]);
45
+ const onValidateControl = useCallback(newValue => {
46
+ const message = field.isValid?.custom?.(deepMerge(data, setValue({
47
+ item: data,
48
+ value: newValue
49
+ })), field);
50
+ if (message) {
51
+ setCustomValidity({
52
+ type: 'invalid',
53
+ message
54
+ });
55
+ return;
56
+ }
57
+ setCustomValidity(undefined);
58
+ }, [data, field, setValue]);
59
+ return /*#__PURE__*/_jsx(ValidatedTextareaControl, {
60
+ required: !!field.isValid?.required,
61
+ onValidate: onValidateControl,
62
+ customValidity: customValidity,
63
+ label: label,
64
+ placeholder: placeholder,
65
+ value: value !== null && value !== void 0 ? value : '',
66
+ help: description,
67
+ onChange: onChangeControl,
68
+ rows: rows,
69
+ __next40pxDefaultSize: true,
70
+ __nextHasNoMarginBottom: true,
71
+ hideLabelFromVision: hideLabelFromVision
72
+ });
73
+ }
74
+ //# sourceMappingURL=textarea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["deepMerge","privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedTextareaControl","Textarea","data","field","onChange","hideLabelFromVision","config","rows","label","placeholder","description","setValue","value","getValue","item","customValidity","setCustomValidity","undefined","onChangeControl","newValue","onValidateControl","message","isValid","custom","type","required","onValidate","help","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/dataviews/src/dataform-controls/textarea.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { useCallback, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport { unlock } from '../lock-unlock';\n\nconst { ValidatedTextareaControl } = unlock( privateApis );\n\nexport default function Textarea< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tconfig,\n}: DataFormControlProps< Item > ) {\n\tconst { rows = 4 } = config || {};\n\tconst { label, placeholder, description, setValue } = field;\n\tconst value = field.getValue( { item: data } );\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedTextareaControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\n\tconst onValidateControl = useCallback(\n\t\t( newValue: any ) => {\n\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\tdeepMerge(\n\t\t\t\t\tdata,\n\t\t\t\t\tsetValue( {\n\t\t\t\t\t\titem: data,\n\t\t\t\t\t\tvalue: newValue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tfield\n\t\t\t);\n\n\t\t\tif ( message ) {\n\t\t\t\tsetCustomValidity( {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetCustomValidity( undefined );\n\t\t},\n\t\t[ data, field, setValue ]\n\t);\n\n\treturn (\n\t\t<ValidatedTextareaControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tonValidate={ onValidateControl }\n\t\t\tcustomValidity={ customValidity }\n\t\t\tlabel={ label }\n\t\t\tplaceholder={ placeholder }\n\t\t\tvalue={ value ?? '' }\n\t\t\thelp={ description }\n\t\t\tonChange={ onChangeControl }\n\t\t\trows={ rows }\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;;AAE1D;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAM;EAAEC;AAAyB,CAAC,GAAGH,MAAM,CAAEH,WAAY,CAAC;AAE1D,eAAe,SAASO,QAAQA,CAAU;EACzCC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC,mBAAmB;EACnBC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,IAAI,GAAG;EAAE,CAAC,GAAGD,MAAM,IAAI,CAAC,CAAC;EACjC,MAAM;IAAEE,KAAK;IAAEC,WAAW;IAAEC,WAAW;IAAEC;EAAS,CAAC,GAAGR,KAAK;EAC3D,MAAMS,KAAK,GAAGT,KAAK,CAACU,QAAQ,CAAE;IAAEC,IAAI,EAAEZ;EAAK,CAAE,CAAC;EAC9C,MAAM,CAAEa,cAAc,EAAEC,iBAAiB,CAAE,GAC1CpB,QAAQ,CAILqB,SAAU,CAAC;EAEf,MAAMC,eAAe,GAAGvB,WAAW,CAChCwB,QAAgB,IACjBf,QAAQ,CAAEO,QAAQ,CAAE;IAAEG,IAAI,EAAEZ,IAAI;IAAEU,KAAK,EAAEO;EAAS,CAAE,CAAE,CAAC,EACxD,CAAEjB,IAAI,EAAEE,QAAQ,EAAEO,QAAQ,CAC3B,CAAC;EAED,MAAMS,iBAAiB,GAAGzB,WAAW,CAClCwB,QAAa,IAAM;IACpB,MAAME,OAAO,GAAGlB,KAAK,CAACmB,OAAO,EAAEC,MAAM,GACpC9B,SAAS,CACRS,IAAI,EACJS,QAAQ,CAAE;MACTG,IAAI,EAAEZ,IAAI;MACVU,KAAK,EAAEO;IACR,CAAE,CACH,CAAC,EACDhB,KACD,CAAC;IAED,IAAKkB,OAAO,EAAG;MACdL,iBAAiB,CAAE;QAClBQ,IAAI,EAAE,SAAS;QACfH;MACD,CAAE,CAAC;MACH;IACD;IAEAL,iBAAiB,CAAEC,SAAU,CAAC;EAC/B,CAAC,EACD,CAAEf,IAAI,EAAEC,KAAK,EAAEQ,QAAQ,CACxB,CAAC;EAED,oBACCZ,IAAA,CAACC,wBAAwB;IACxByB,QAAQ,EAAG,CAAC,CAAEtB,KAAK,CAACmB,OAAO,EAAEG,QAAU;IACvCC,UAAU,EAAGN,iBAAmB;IAChCL,cAAc,EAAGA,cAAgB;IACjCP,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3BG,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBe,IAAI,EAAGjB,WAAa;IACpBN,QAAQ,EAAGc,eAAiB;IAC5BX,IAAI,EAAGA,IAAM;IACbqB,qBAAqB;IACrBC,uBAAuB;IACvBxB,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ","ignoreList":[]}
@@ -1,13 +1,23 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import deepMerge from 'deepmerge';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
- import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption } from '@wordpress/components';
5
- import { useCallback } from '@wordpress/element';
9
+ import { privateApis, __experimentalToggleGroupControlOption as ToggleGroupControlOption } from '@wordpress/components';
10
+ import { useCallback, useState } from '@wordpress/element';
6
11
 
7
12
  /**
8
13
  * Internal dependencies
9
14
  */
15
+
16
+ import { unlock } from '../lock-unlock';
10
17
  import { jsx as _jsx } from "react/jsx-runtime";
18
+ const {
19
+ ValidatedToggleGroupControl
20
+ } = unlock(privateApis);
11
21
  export default function ToggleGroup({
12
22
  data,
13
23
  field,
@@ -15,17 +25,37 @@ export default function ToggleGroup({
15
25
  hideLabelFromVision
16
26
  }) {
17
27
  const {
18
- id
28
+ getValue,
29
+ setValue
19
30
  } = field;
20
- const value = field.getValue({
31
+ const [customValidity, setCustomValidity] = useState(undefined);
32
+ const value = getValue({
21
33
  item: data
22
34
  });
23
- const onChangeControl = useCallback(newValue => onChange({
24
- [id]: newValue
25
- }), [id, onChange]);
35
+ const onChangeControl = useCallback(newValue => onChange(setValue({
36
+ item: data,
37
+ value: newValue
38
+ })), [data, onChange, setValue]);
39
+ const onValidateControl = useCallback(newValue => {
40
+ const message = field.isValid?.custom?.(deepMerge(data, setValue({
41
+ item: data,
42
+ value: newValue
43
+ })), field);
44
+ if (message) {
45
+ setCustomValidity({
46
+ type: 'invalid',
47
+ message
48
+ });
49
+ return;
50
+ }
51
+ setCustomValidity(undefined);
52
+ }, [data, field, setValue]);
26
53
  if (field.elements) {
27
54
  const selectedOption = field.elements.find(el => el.value === value);
28
- return /*#__PURE__*/_jsx(ToggleGroupControl, {
55
+ return /*#__PURE__*/_jsx(ValidatedToggleGroupControl, {
56
+ required: !!field.isValid?.required,
57
+ onValidate: onValidateControl,
58
+ customValidity: customValidity,
29
59
  __next40pxDefaultSize: true,
30
60
  __nextHasNoMarginBottom: true,
31
61
  isBlock: true,
@@ -1 +1 @@
1
- {"version":3,"names":["__experimentalToggleGroupControl","ToggleGroupControl","__experimentalToggleGroupControlOption","ToggleGroupControlOption","useCallback","jsx","_jsx","ToggleGroup","data","field","onChange","hideLabelFromVision","id","value","getValue","item","onChangeControl","newValue","elements","selectedOption","find","el","__next40pxDefaultSize","__nextHasNoMarginBottom","isBlock","label","help","description","children","map"],"sources":["@wordpress/dataviews/src/dataform-controls/toggle-group.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\n\nexport default function ToggleGroup< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id } = field;\n\tconst value = field.getValue( { item: data } );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string | number | undefined ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\tif ( field.elements ) {\n\t\tconst selectedOption = field.elements.find(\n\t\t\t( el ) => el.value === value\n\t\t);\n\t\treturn (\n\t\t\t<ToggleGroupControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tisBlock\n\t\t\t\tlabel={ field.label }\n\t\t\t\thelp={ selectedOption?.description || field.description }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\tvalue={ value }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t>\n\t\t\t\t{ field.elements.map( ( el ) => (\n\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\tkey={ el.value }\n\t\t\t\t\t\tlabel={ el.label }\n\t\t\t\t\t\tvalue={ el.value }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t\t</ToggleGroupControl>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gCAAgC,IAAIC,kBAAkB,EACtDC,sCAAsC,IAAIC,wBAAwB,QAC5D,uBAAuB;AAC9B,SAASC,WAAW,QAAQ,oBAAoB;;AAEhD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAKA,eAAe,SAASC,WAAWA,CAAU;EAC5CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC;EAAG,CAAC,GAAGH,KAAK;EACpB,MAAMI,KAAK,GAAGJ,KAAK,CAACK,QAAQ,CAAE;IAAEC,IAAI,EAAEP;EAAK,CAAE,CAAC;EAE9C,MAAMQ,eAAe,GAAGZ,WAAW,CAChCa,QAAqC,IACtCP,QAAQ,CAAE;IACT,CAAEE,EAAE,GAAIK;EACT,CAAE,CAAC,EACJ,CAAEL,EAAE,EAAEF,QAAQ,CACf,CAAC;EAED,IAAKD,KAAK,CAACS,QAAQ,EAAG;IACrB,MAAMC,cAAc,GAAGV,KAAK,CAACS,QAAQ,CAACE,IAAI,CACvCC,EAAE,IAAMA,EAAE,CAACR,KAAK,KAAKA,KACxB,CAAC;IACD,oBACCP,IAAA,CAACL,kBAAkB;MAClBqB,qBAAqB;MACrBC,uBAAuB;MACvBC,OAAO;MACPC,KAAK,EAAGhB,KAAK,CAACgB,KAAO;MACrBC,IAAI,EAAGP,cAAc,EAAEQ,WAAW,IAAIlB,KAAK,CAACkB,WAAa;MACzDjB,QAAQ,EAAGM,eAAiB;MAC5BH,KAAK,EAAGA,KAAO;MACfF,mBAAmB,EAAGA,mBAAqB;MAAAiB,QAAA,EAEzCnB,KAAK,CAACS,QAAQ,CAACW,GAAG,CAAIR,EAAE,iBACzBf,IAAA,CAACH,wBAAwB;QAExBsB,KAAK,EAAGJ,EAAE,CAACI,KAAO;QAClBZ,KAAK,EAAGQ,EAAE,CAACR;MAAO,GAFZQ,EAAE,CAACR,KAGT,CACA;IAAC,CACgB,CAAC;EAEvB;EAEA,OAAO,IAAI;AACZ","ignoreList":[]}
1
+ {"version":3,"names":["deepMerge","privateApis","__experimentalToggleGroupControlOption","ToggleGroupControlOption","useCallback","useState","unlock","jsx","_jsx","ValidatedToggleGroupControl","ToggleGroup","data","field","onChange","hideLabelFromVision","getValue","setValue","customValidity","setCustomValidity","undefined","value","item","onChangeControl","newValue","onValidateControl","message","isValid","custom","type","elements","selectedOption","find","el","required","onValidate","__next40pxDefaultSize","__nextHasNoMarginBottom","isBlock","label","help","description","children","map"],"sources":["@wordpress/dataviews/src/dataform-controls/toggle-group.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { useCallback, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport { unlock } from '../lock-unlock';\n\nconst { ValidatedToggleGroupControl } = unlock( privateApis );\n\nexport default function ToggleGroup< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { getValue, setValue } = field;\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedToggleGroupControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\tconst value = getValue( { item: data } );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string | number | undefined ) =>\n\t\t\tonChange( setValue( { item: data, value: newValue } ) ),\n\t\t[ data, onChange, setValue ]\n\t);\n\tconst onValidateControl = useCallback(\n\t\t( newValue: any ) => {\n\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\tdeepMerge(\n\t\t\t\t\tdata,\n\t\t\t\t\tsetValue( {\n\t\t\t\t\t\titem: data,\n\t\t\t\t\t\tvalue: newValue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tfield\n\t\t\t);\n\n\t\t\tif ( message ) {\n\t\t\t\tsetCustomValidity( {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage,\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetCustomValidity( undefined );\n\t\t},\n\t\t[ data, field, setValue ]\n\t);\n\n\tif ( field.elements ) {\n\t\tconst selectedOption = field.elements.find(\n\t\t\t( el ) => el.value === value\n\t\t);\n\t\treturn (\n\t\t\t<ValidatedToggleGroupControl\n\t\t\t\trequired={ !! field.isValid?.required }\n\t\t\t\tonValidate={ onValidateControl }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tisBlock\n\t\t\t\tlabel={ field.label }\n\t\t\t\thelp={ selectedOption?.description || field.description }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\tvalue={ value }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t>\n\t\t\t\t{ field.elements.map( ( el ) => (\n\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\tkey={ el.value }\n\t\t\t\t\t\tlabel={ el.label }\n\t\t\t\t\t\tvalue={ el.value }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t\t</ValidatedToggleGroupControl>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SACCC,WAAW,EACXC,sCAAsC,IAAIC,wBAAwB,QAC5D,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;;AAE1D;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExC,MAAM;EAAEC;AAA4B,CAAC,GAAGH,MAAM,CAAEL,WAAY,CAAC;AAE7D,eAAe,SAASS,WAAWA,CAAU;EAC5CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,QAAQ;IAAEC;EAAS,C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CAAC0B,KAAO;MACrBC,IAAI,EAAGT,cAAc,EAAEU,WAAW,IAAI5B,KAAK,CAAC4B,WAAa;MACzD3B,QAAQ,EAAGS,eAAiB;MAC5BF,KAAK,EAAGA,KAAO;MACfN,mBAAmB,EAAGA,mBAAqB;MAAA2B,QAAA,EAEzC7B,KAAK,CAACiB,QAAQ,CAACa,GAAG,CAAIV,EAAE,iBACzBxB,IAAA,CAACL,wBAAwB;QAExBmC,KAAK,EAAGN,EAAE,CAACM,KAAO;QAClBlB,KAAK,EAAGY,EAAE,CAACZ;MAAO,GAFZY,EAAE,CAACZ,KAGT,CACA;IAAC,CACyB,CAAC;EAEhC;EAEA,OAAO,IAAI;AACZ","ignoreList":[]}
@@ -1,8 +1,13 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import deepMerge from 'deepmerge';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
4
9
  import { privateApis } from '@wordpress/components';
5
- import { useState } from '@wordpress/element';
10
+ import { useCallback, useState } from '@wordpress/element';
6
11
 
7
12
  /**
8
13
  * Internal dependencies
@@ -20,28 +25,37 @@ export default function Toggle({
20
25
  hideLabelFromVision
21
26
  }) {
22
27
  const {
23
- id,
24
- getValue,
25
28
  label,
26
- description
29
+ description,
30
+ getValue,
31
+ setValue
27
32
  } = field;
28
33
  const [customValidity, setCustomValidity] = useState(undefined);
34
+ const onChangeControl = useCallback(() => {
35
+ onChange(setValue({
36
+ item: data,
37
+ value: !getValue({
38
+ item: data
39
+ })
40
+ }));
41
+ }, [onChange, setValue, data, getValue]);
42
+ const onValidateControl = useCallback(newValue => {
43
+ const message = field.isValid?.custom?.(deepMerge(data, setValue({
44
+ item: data,
45
+ value: newValue
46
+ })), field);
47
+ if (message) {
48
+ setCustomValidity({
49
+ type: 'invalid',
50
+ message
51
+ });
52
+ return;
53
+ }
54
+ setCustomValidity(undefined);
55
+ }, [data, field, setValue]);
29
56
  return /*#__PURE__*/_jsx(ValidatedToggleControl, {
30
57
  required: !!field.isValid.required,
31
- onValidate: newValue => {
32
- const message = field.isValid?.custom?.({
33
- ...data,
34
- [id]: newValue
35
- }, field);
36
- if (message) {
37
- setCustomValidity({
38
- type: 'invalid',
39
- message
40
- });
41
- return;
42
- }
43
- setCustomValidity(undefined);
44
- },
58
+ onValidate: onValidateControl,
45
59
  customValidity: customValidity,
46
60
  hidden: hideLabelFromVision,
47
61
  __nextHasNoMarginBottom: true,
@@ -50,11 +64,7 @@ export default function Toggle({
50
64
  checked: getValue({
51
65
  item: data
52
66
  }),
53
- onChange: () => onChange({
54
- [id]: !getValue({
55
- item: data
56
- })
57
- })
67
+ onChange: onChangeControl
58
68
  });
59
69
  }
60
70
  //# sourceMappingURL=toggle.js.map