@wordpress/dataviews 9.0.1-next.6f42e1382.0 → 9.1.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.
- package/CHANGELOG.md +25 -2
- package/README.md +112 -15
- package/build/components/dataviews/index.js +4 -6
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-filters/filters-toggled.js +32 -0
- package/build/components/dataviews-filters/filters-toggled.js.map +1 -0
- package/build/components/dataviews-filters/filters.js +73 -0
- package/build/components/dataviews-filters/filters.js.map +1 -0
- package/build/components/dataviews-filters/index.js +26 -190
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/input-widget.js +48 -4
- package/build/components/dataviews-filters/input-widget.js.map +1 -1
- package/build/components/dataviews-filters/toggle.js +99 -0
- package/build/components/dataviews-filters/toggle.js.map +1 -0
- package/build/components/dataviews-filters/use-filters.js +63 -0
- package/build/components/dataviews-filters/use-filters.js.map +1 -0
- package/build/components/dataviews-picker/index.js +4 -6
- package/build/components/dataviews-picker/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +22 -3
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataform-controls/array.js +117 -29
- package/build/dataform-controls/array.js.map +1 -1
- package/build/dataform-controls/checkbox.js +31 -20
- package/build/dataform-controls/checkbox.js.map +1 -1
- package/build/dataform-controls/color.js +29 -24
- package/build/dataform-controls/color.js.map +1 -1
- package/build/dataform-controls/date.js +32 -24
- package/build/dataform-controls/date.js.map +1 -1
- package/build/dataform-controls/datetime.js +133 -19
- package/build/dataform-controls/datetime.js.map +1 -1
- package/build/dataform-controls/email.js +7 -1
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-controls/index.js +25 -0
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/integer.js +7 -106
- package/build/dataform-controls/integer.js.map +1 -1
- package/build/dataform-controls/number.js +21 -0
- package/build/dataform-controls/number.js.map +1 -0
- package/build/dataform-controls/radio.js +42 -9
- package/build/dataform-controls/radio.js.map +1 -1
- package/build/dataform-controls/relative-date-control.js +6 -10
- package/build/dataform-controls/relative-date-control.js.map +1 -1
- package/build/dataform-controls/select.js +41 -10
- package/build/dataform-controls/select.js.map +1 -1
- package/build/dataform-controls/telephone.js +7 -1
- package/build/dataform-controls/telephone.js.map +1 -1
- package/build/dataform-controls/text.js +14 -2
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataform-controls/textarea.js +33 -20
- package/build/dataform-controls/textarea.js.map +1 -1
- package/build/dataform-controls/toggle-group.js +36 -6
- package/build/dataform-controls/toggle-group.js.map +1 -1
- package/build/dataform-controls/toggle.js +33 -22
- package/build/dataform-controls/toggle.js.map +1 -1
- package/build/dataform-controls/url.js +7 -1
- package/build/dataform-controls/url.js.map +1 -1
- package/build/dataform-controls/utils/validated-input.js +34 -32
- package/build/dataform-controls/utils/validated-input.js.map +1 -1
- package/build/dataform-controls/utils/validated-number.js +146 -0
- package/build/dataform-controls/utils/validated-number.js.map +1 -0
- package/build/dataforms-layouts/panel/dropdown.js +10 -14
- package/build/dataforms-layouts/panel/dropdown.js.map +1 -1
- package/build/dataforms-layouts/panel/index.js +24 -11
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/panel/modal.js +22 -27
- package/build/dataforms-layouts/panel/modal.js.map +1 -1
- package/build/dataforms-layouts/panel/summary-button.js +67 -0
- package/build/dataforms-layouts/panel/summary-button.js.map +1 -0
- package/build/dataviews-layouts/picker-grid/index.js +4 -1
- package/build/dataviews-layouts/picker-grid/index.js.map +1 -1
- package/build/field-types/array.js +0 -6
- package/build/field-types/array.js.map +1 -1
- package/build/field-types/index.js +4 -0
- package/build/field-types/index.js.map +1 -1
- package/build/field-types/number.js +71 -0
- package/build/field-types/number.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/normalize-fields.js +17 -0
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/validation.js +18 -1
- package/build/validation.js.map +1 -1
- package/build-module/components/dataviews/index.js +5 -7
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-filters/filters-toggled.js +24 -0
- package/build-module/components/dataviews-filters/filters-toggled.js.map +1 -0
- package/build-module/components/dataviews-filters/filters.js +65 -0
- package/build-module/components/dataviews-filters/filters.js.map +1 -0
- package/build-module/components/dataviews-filters/index.js +4 -186
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/input-widget.js +48 -4
- package/build-module/components/dataviews-filters/input-widget.js.map +1 -1
- package/build-module/components/dataviews-filters/toggle.js +91 -0
- package/build-module/components/dataviews-filters/toggle.js.map +1 -0
- package/build-module/components/dataviews-filters/use-filters.js +56 -0
- package/build-module/components/dataviews-filters/use-filters.js.map +1 -0
- package/build-module/components/dataviews-picker/index.js +5 -7
- package/build-module/components/dataviews-picker/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +22 -3
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataform-controls/array.js +120 -32
- package/build-module/dataform-controls/array.js.map +1 -1
- package/build-module/dataform-controls/checkbox.js +31 -21
- package/build-module/dataform-controls/checkbox.js.map +1 -1
- package/build-module/dataform-controls/color.js +28 -24
- package/build-module/dataform-controls/color.js.map +1 -1
- package/build-module/dataform-controls/date.js +32 -24
- package/build-module/dataform-controls/date.js.map +1 -1
- package/build-module/dataform-controls/datetime.js +135 -21
- package/build-module/dataform-controls/datetime.js.map +1 -1
- package/build-module/dataform-controls/email.js +7 -1
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-controls/index.js +25 -0
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/integer.js +7 -106
- package/build-module/dataform-controls/integer.js.map +1 -1
- package/build-module/dataform-controls/number.js +14 -0
- package/build-module/dataform-controls/number.js.map +1 -0
- package/build-module/dataform-controls/radio.js +44 -11
- package/build-module/dataform-controls/radio.js.map +1 -1
- package/build-module/dataform-controls/relative-date-control.js +6 -10
- package/build-module/dataform-controls/relative-date-control.js.map +1 -1
- package/build-module/dataform-controls/select.js +43 -12
- package/build-module/dataform-controls/select.js.map +1 -1
- package/build-module/dataform-controls/telephone.js +7 -1
- package/build-module/dataform-controls/telephone.js.map +1 -1
- package/build-module/dataform-controls/text.js +14 -2
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataform-controls/textarea.js +32 -20
- package/build-module/dataform-controls/textarea.js.map +1 -1
- package/build-module/dataform-controls/toggle-group.js +38 -8
- package/build-module/dataform-controls/toggle-group.js.map +1 -1
- package/build-module/dataform-controls/toggle.js +33 -23
- package/build-module/dataform-controls/toggle.js.map +1 -1
- package/build-module/dataform-controls/url.js +7 -1
- package/build-module/dataform-controls/url.js.map +1 -1
- package/build-module/dataform-controls/utils/validated-input.js +34 -33
- package/build-module/dataform-controls/utils/validated-input.js.map +1 -1
- package/build-module/dataform-controls/utils/validated-number.js +138 -0
- package/build-module/dataform-controls/utils/validated-number.js.map +1 -0
- package/build-module/dataforms-layouts/panel/dropdown.js +10 -15
- package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -1
- package/build-module/dataforms-layouts/panel/index.js +24 -11
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/modal.js +22 -28
- package/build-module/dataforms-layouts/panel/modal.js.map +1 -1
- package/build-module/dataforms-layouts/panel/summary-button.js +60 -0
- package/build-module/dataforms-layouts/panel/summary-button.js.map +1 -0
- package/build-module/dataviews-layouts/picker-grid/index.js +4 -1
- package/build-module/dataviews-layouts/picker-grid/index.js.map +1 -1
- package/build-module/field-types/array.js +0 -6
- package/build-module/field-types/array.js.map +1 -1
- package/build-module/field-types/index.js +4 -0
- package/build-module/field-types/index.js.map +1 -1
- package/build-module/field-types/number.js +65 -0
- package/build-module/field-types/number.js.map +1 -0
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/normalize-fields.js +15 -0
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/validation.js +18 -1
- package/build-module/validation.js.map +1 -1
- package/build-types/components/dataform/stories/index.story.d.ts +3 -0
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts +3 -2
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts +4 -2
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/filters-toggled.d.ts +5 -0
- package/build-types/components/dataviews-filters/filters-toggled.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/filters.d.ts +6 -0
- package/build-types/components/dataviews-filters/filters.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/index.d.ts +4 -8
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/toggle.d.ts +3 -0
- package/build-types/components/dataviews-filters/toggle.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/use-filters.d.ts +4 -0
- package/build-types/components/dataviews-filters/use-filters.d.ts.map +1 -0
- package/build-types/components/dataviews-picker/index.d.ts +3 -2
- package/build-types/components/dataviews-picker/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataform-controls/array.d.ts.map +1 -1
- package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
- package/build-types/dataform-controls/color.d.ts.map +1 -1
- package/build-types/dataform-controls/date.d.ts.map +1 -1
- package/build-types/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts.map +1 -1
- package/build-types/dataform-controls/index.d.ts +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/integer.d.ts +4 -1
- package/build-types/dataform-controls/integer.d.ts.map +1 -1
- package/build-types/dataform-controls/number.d.ts +6 -0
- package/build-types/dataform-controls/number.d.ts.map +1 -0
- package/build-types/dataform-controls/radio.d.ts.map +1 -1
- package/build-types/dataform-controls/relative-date-control.d.ts +6 -5
- package/build-types/dataform-controls/relative-date-control.d.ts.map +1 -1
- package/build-types/dataform-controls/select.d.ts.map +1 -1
- package/build-types/dataform-controls/telephone.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataform-controls/textarea.d.ts +1 -1
- package/build-types/dataform-controls/textarea.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle-group.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle.d.ts.map +1 -1
- package/build-types/dataform-controls/url.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-input.d.ts +4 -4
- package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-number.d.ts +9 -0
- package/build-types/dataform-controls/utils/validated-number.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/dropdown.d.ts +2 -1
- package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts +2 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/summary-button.d.ts +15 -0
- package/build-types/dataforms-layouts/panel/summary-button.d.ts.map +1 -0
- package/build-types/dataviews-layouts/picker-grid/index.d.ts.map +1 -1
- package/build-types/field-types/array.d.ts.map +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/number.d.ts +20 -0
- package/build-types/field-types/number.d.ts.map +1 -0
- package/build-types/field-types/stories/index.story.d.ts +106 -57
- package/build-types/field-types/stories/index.story.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts +3 -0
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +69 -5
- package/build-types/types.d.ts.map +1 -1
- package/build-types/validation.d.ts.map +1 -1
- package/build-wp/index.js +2354 -1717
- package/package.json +16 -15
- package/src/components/dataform/stories/index.story.tsx +528 -8
- package/src/components/dataviews/index.tsx +8 -14
- package/src/components/dataviews/stories/fixtures.tsx +99 -41
- package/src/components/dataviews/stories/index.story.tsx +2 -2
- package/src/components/dataviews-filters/filters-toggled.tsx +20 -0
- package/src/components/dataviews-filters/filters.tsx +73 -0
- package/src/components/dataviews-filters/index.tsx +4 -246
- package/src/components/dataviews-filters/input-widget.tsx +44 -5
- package/src/components/dataviews-filters/toggle.tsx +118 -0
- package/src/components/dataviews-filters/use-filters.ts +73 -0
- package/src/components/dataviews-picker/index.tsx +8 -14
- package/src/components/dataviews-picker/stories/index.story.tsx +1 -1
- package/src/components/dataviews-view-config/index.tsx +18 -3
- package/src/dataform-controls/array.tsx +139 -44
- package/src/dataform-controls/checkbox.tsx +41 -24
- package/src/dataform-controls/color.tsx +33 -24
- package/src/dataform-controls/date.tsx +47 -21
- package/src/dataform-controls/datetime.tsx +171 -23
- package/src/dataform-controls/email.tsx +9 -1
- package/src/dataform-controls/index.tsx +28 -0
- package/src/dataform-controls/integer.tsx +3 -146
- package/src/dataform-controls/number.tsx +10 -0
- package/src/dataform-controls/radio.tsx +53 -11
- package/src/dataform-controls/relative-date-control.tsx +11 -10
- package/src/dataform-controls/select.tsx +53 -10
- package/src/dataform-controls/telephone.tsx +9 -1
- package/src/dataform-controls/text.tsx +18 -1
- package/src/dataform-controls/textarea.tsx +38 -24
- package/src/dataform-controls/toggle-group.tsx +50 -10
- package/src/dataform-controls/toggle.tsx +41 -24
- package/src/dataform-controls/url.tsx +9 -1
- package/src/dataform-controls/utils/validated-input.tsx +50 -50
- package/src/dataform-controls/utils/validated-number.tsx +209 -0
- package/src/dataforms-layouts/panel/dropdown.tsx +12 -23
- package/src/dataforms-layouts/panel/index.tsx +39 -16
- package/src/dataforms-layouts/panel/modal.tsx +24 -30
- package/src/dataforms-layouts/panel/summary-button.tsx +92 -0
- package/src/dataviews-layouts/picker-grid/index.tsx +15 -8
- package/src/field-types/array.tsx +0 -8
- package/src/field-types/index.tsx +5 -0
- package/src/field-types/number.tsx +104 -0
- package/src/field-types/stories/index.story.tsx +170 -16
- package/src/index.ts +1 -0
- package/src/normalize-fields.ts +18 -0
- package/src/test/dataform.tsx +36 -0
- package/src/test/filter-and-sort-data-view.js +182 -138
- package/src/test/normalize-fields.ts +136 -0
- package/src/test/validation.ts +235 -0
- package/src/types.ts +76 -4
- package/src/validation.ts +32 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deepMerge from 'deepmerge';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -17,43 +22,50 @@ export default function Textarea({
|
|
|
17
22
|
data,
|
|
18
23
|
field,
|
|
19
24
|
onChange,
|
|
20
|
-
hideLabelFromVision
|
|
25
|
+
hideLabelFromVision,
|
|
26
|
+
config
|
|
21
27
|
}) {
|
|
22
28
|
const {
|
|
23
|
-
|
|
29
|
+
rows = 4
|
|
30
|
+
} = config || {};
|
|
31
|
+
const {
|
|
24
32
|
label,
|
|
25
33
|
placeholder,
|
|
26
|
-
description
|
|
34
|
+
description,
|
|
35
|
+
setValue
|
|
27
36
|
} = field;
|
|
28
37
|
const value = field.getValue({
|
|
29
38
|
item: data
|
|
30
39
|
});
|
|
31
40
|
const [customValidity, setCustomValidity] = useState(undefined);
|
|
32
|
-
const onChangeControl = useCallback(newValue => onChange({
|
|
33
|
-
|
|
34
|
-
|
|
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]);
|
|
35
59
|
return /*#__PURE__*/_jsx(ValidatedTextareaControl, {
|
|
36
60
|
required: !!field.isValid?.required,
|
|
37
|
-
onValidate:
|
|
38
|
-
const message = field.isValid?.custom?.({
|
|
39
|
-
...data,
|
|
40
|
-
[id]: newValue
|
|
41
|
-
}, field);
|
|
42
|
-
if (message) {
|
|
43
|
-
setCustomValidity({
|
|
44
|
-
type: 'invalid',
|
|
45
|
-
message
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
setCustomValidity(undefined);
|
|
50
|
-
},
|
|
61
|
+
onValidate: onValidateControl,
|
|
51
62
|
customValidity: customValidity,
|
|
52
63
|
label: label,
|
|
53
64
|
placeholder: placeholder,
|
|
54
65
|
value: value !== null && value !== void 0 ? value : '',
|
|
55
66
|
help: description,
|
|
56
67
|
onChange: onChangeControl,
|
|
68
|
+
rows: rows,
|
|
57
69
|
__next40pxDefaultSize: true,
|
|
58
70
|
__nextHasNoMarginBottom: true,
|
|
59
71
|
hideLabelFromVision: hideLabelFromVision
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedTextareaControl","Textarea","data","field","onChange","hideLabelFromVision","
|
|
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 {
|
|
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
|
-
|
|
28
|
+
getValue,
|
|
29
|
+
setValue
|
|
19
30
|
} = field;
|
|
20
|
-
const
|
|
31
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
32
|
+
const value = getValue({
|
|
21
33
|
item: data
|
|
22
34
|
});
|
|
23
|
-
const onChangeControl = useCallback(newValue => onChange({
|
|
24
|
-
|
|
25
|
-
|
|
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(
|
|
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":["
|
|
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,o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,IAAI,CACvCC,EAAE,IAAMA,EAAE,CAACZ,KAAK,KAAKA,KACxB,CAAC;IACD,oBACCZ,IAAA,CAACC,2BAA2B;MAC3BwB,QAAQ,EAAG,CAAC,CAAErB,KAAK,CAACc,OAAO,EAAEO,QAAU;MACvCC,UAAU,EAAGV,iBAAmB;MAChCP,cAAc,EAAGA,cAAgB;MACjCkB,qBAAqB;MACrBC,uBAAuB;MACvBC,OAAO;MACPC,KAAK,EAAG1B,KAAK,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:
|
|
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:
|
|
54
|
-
[id]: !getValue({
|
|
55
|
-
item: data
|
|
56
|
-
})
|
|
57
|
-
})
|
|
67
|
+
onChange: onChangeControl
|
|
58
68
|
});
|
|
59
69
|
}
|
|
60
70
|
//# sourceMappingURL=toggle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","useState","unlock","jsx","_jsx","ValidatedToggleControl","Toggle","field","onChange","data","hideLabelFromVision","
|
|
1
|
+
{"version":3,"names":["deepMerge","privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedToggleControl","Toggle","field","onChange","data","hideLabelFromVision","label","description","getValue","setValue","customValidity","setCustomValidity","undefined","onChangeControl","item","value","onValidateControl","newValue","message","isValid","custom","type","required","onValidate","hidden","__nextHasNoMarginBottom","help","checked"],"sources":["@wordpress/dataviews/src/dataform-controls/toggle.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 { ValidatedToggleControl } = unlock( privateApis );\n\nexport default function Toggle< Item >( {\n\tfield,\n\tonChange,\n\tdata,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { label, description, getValue, setValue } = field;\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedToggleControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst onChangeControl = useCallback( () => {\n\t\tonChange(\n\t\t\tsetValue( { item: data, value: ! getValue( { item: data } ) } )\n\t\t);\n\t}, [ onChange, setValue, data, getValue ] );\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<ValidatedToggleControl\n\t\t\trequired={ !! field.isValid.required }\n\t\t\tonValidate={ onValidateControl }\n\t\t\tcustomValidity={ customValidity }\n\t\t\thidden={ hideLabelFromVision }\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\thelp={ description }\n\t\t\tchecked={ getValue( { item: data } ) }\n\t\t\tonChange={ onChangeControl }\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;AAAuB,CAAC,GAAGH,MAAM,CAAEH,WAAY,CAAC;AAExD,eAAe,SAASO,MAAMA,CAAU;EACvCC,KAAK;EACLC,QAAQ;EACRC,IAAI;EACJC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,KAAK;IAAEC,WAAW;IAAEC,QAAQ;IAAEC;EAAS,CAAC,GAAGP,KAAK;EACxD,MAAM,CAAEQ,cAAc,EAAEC,iBAAiB,CAAE,GAC1Cf,QAAQ,CAILgB,SAAU,CAAC;EAEf,MAAMC,eAAe,GAAGlB,WAAW,CAAE,MAAM;IAC1CQ,QAAQ,CACPM,QAAQ,CAAE;MAAEK,IAAI,EAAEV,IAAI;MAAEW,KAAK,EAAE,CAAEP,QAAQ,CAAE;QAAEM,IAAI,EAAEV;MAAK,CAAE;IAAE,CAAE,CAC/D,CAAC;EACF,CAAC,EAAE,CAAED,QAAQ,EAAEM,QAAQ,EAAEL,IAAI,EAAEI,QAAQ,CAAG,CAAC;EAE3C,MAAMQ,iBAAiB,GAAGrB,WAAW,CAClCsB,QAAa,IAAM;IACpB,MAAMC,OAAO,GAAGhB,KAAK,CAACiB,OAAO,EAAEC,MAAM,GACpC3B,SAAS,CACRW,IAAI,EACJK,QAAQ,CAAE;MACTK,IAAI,EAAEV,IAAI;MACVW,KAAK,EAAEE;IACR,CAAE,CACH,CAAC,EACDf,KACD,CAAC;IAED,IAAKgB,OAAO,EAAG;MACdP,iBAAiB,CAAE;QAClBU,IAAI,EAAE,SAAS;QACfH;MACD,CAAE,CAAC;MACH;IACD;IAEAP,iBAAiB,CAAEC,SAAU,CAAC;EAC/B,CAAC,EACD,CAAER,IAAI,EAAEF,KAAK,EAAEO,QAAQ,CACxB,CAAC;EAED,oBACCV,IAAA,CAACC,sBAAsB;IACtBsB,QAAQ,EAAG,CAAC,CAAEpB,KAAK,CAACiB,OAAO,CAACG,QAAU;IACtCC,UAAU,EAAGP,iBAAmB;IAChCN,cAAc,EAAGA,cAAgB;IACjCc,MAAM,EAAGnB,mBAAqB;IAC9BoB,uBAAuB;IACvBnB,KAAK,EAAGA,KAAO;IACfoB,IAAI,EAAGnB,WAAa;IACpBoB,OAAO,EAAGnB,QAAQ,CAAE;MAAEM,IAAI,EAAEV;IAAK,CAAE,CAAG;IACtCD,QAAQ,EAAGU;EAAiB,CAC5B,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { Icon, __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper } from '@wordpress/components';
|
|
4
5
|
import { link } from '@wordpress/icons';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -21,7 +22,12 @@ export default function Url({
|
|
|
21
22
|
onChange,
|
|
22
23
|
hideLabelFromVision,
|
|
23
24
|
type: 'url',
|
|
24
|
-
|
|
25
|
+
prefix: /*#__PURE__*/_jsx(InputControlPrefixWrapper, {
|
|
26
|
+
variant: "icon",
|
|
27
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
28
|
+
icon: link
|
|
29
|
+
})
|
|
30
|
+
})
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
33
|
//# sourceMappingURL=url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["link","ValidatedText","jsx","_jsx","Url","data","field","onChange","hideLabelFromVision","type","icon"],"sources":["@wordpress/dataviews/src/dataform-controls/url.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { link } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-input';\n\nexport default function Url< 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: 'url',\n\t\t\t\
|
|
1
|
+
{"version":3,"names":["Icon","__experimentalInputControlPrefixWrapper","InputControlPrefixWrapper","link","ValidatedText","jsx","_jsx","Url","data","field","onChange","hideLabelFromVision","type","prefix","variant","children","icon"],"sources":["@wordpress/dataviews/src/dataform-controls/url.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\t__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,\n} from '@wordpress/components';\nimport { link } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\nimport ValidatedText from './utils/validated-input';\n\nexport default function Url< 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: 'url',\n\t\t\t\tprefix: (\n\t\t\t\t\t<InputControlPrefixWrapper variant=\"icon\">\n\t\t\t\t\t\t<Icon icon={ link } />\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,IAAI,QAAQ,kBAAkB;;AAEvC;AACA;AACA;;AAEA,OAAOC,aAAa,MAAM,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEpD,eAAe,SAASC,GAAGA,CAAU;EACpCC,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;MAAM,CAAE;IAAC,CACI;EAC3B,CAEF,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deepMerge from 'deepmerge';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
4
|
-
import {
|
|
9
|
+
import { privateApis } from '@wordpress/components';
|
|
5
10
|
import { useCallback, useState } from '@wordpress/element';
|
|
6
11
|
|
|
7
12
|
/**
|
|
@@ -19,38 +24,42 @@ export default function ValidatedText({
|
|
|
19
24
|
onChange,
|
|
20
25
|
hideLabelFromVision,
|
|
21
26
|
type,
|
|
22
|
-
|
|
27
|
+
prefix,
|
|
23
28
|
suffix
|
|
24
29
|
}) {
|
|
25
30
|
const {
|
|
26
|
-
id,
|
|
27
31
|
label,
|
|
28
32
|
placeholder,
|
|
29
|
-
description
|
|
33
|
+
description,
|
|
34
|
+
getValue,
|
|
35
|
+
setValue,
|
|
36
|
+
isValid
|
|
30
37
|
} = field;
|
|
31
|
-
const value =
|
|
38
|
+
const value = getValue({
|
|
32
39
|
item: data
|
|
33
40
|
});
|
|
34
41
|
const [customValidity, setCustomValidity] = useState(undefined);
|
|
35
|
-
const onChangeControl = useCallback(newValue => onChange({
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
const onChangeControl = useCallback(newValue => onChange(setValue({
|
|
43
|
+
item: data,
|
|
44
|
+
value: newValue
|
|
45
|
+
})), [data, setValue, onChange]);
|
|
46
|
+
const onValidateControl = useCallback(newValue => {
|
|
47
|
+
const message = isValid?.custom?.(deepMerge(data, setValue({
|
|
48
|
+
item: data,
|
|
49
|
+
value: newValue
|
|
50
|
+
})), field);
|
|
51
|
+
if (message) {
|
|
52
|
+
setCustomValidity({
|
|
53
|
+
type: 'invalid',
|
|
54
|
+
message
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setCustomValidity(undefined);
|
|
59
|
+
}, [data, field, isValid, setValue]);
|
|
38
60
|
return /*#__PURE__*/_jsx(ValidatedInputControl, {
|
|
39
|
-
required: !!
|
|
40
|
-
onValidate:
|
|
41
|
-
const message = field.isValid?.custom?.({
|
|
42
|
-
...data,
|
|
43
|
-
[id]: newValue
|
|
44
|
-
}, field);
|
|
45
|
-
if (message) {
|
|
46
|
-
setCustomValidity({
|
|
47
|
-
type: 'invalid',
|
|
48
|
-
message
|
|
49
|
-
});
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
setCustomValidity(undefined);
|
|
53
|
-
},
|
|
61
|
+
required: !!isValid?.required,
|
|
62
|
+
onValidate: onValidateControl,
|
|
54
63
|
customValidity: customValidity,
|
|
55
64
|
label: label,
|
|
56
65
|
placeholder: placeholder,
|
|
@@ -59,16 +68,8 @@ export default function ValidatedText({
|
|
|
59
68
|
onChange: onChangeControl,
|
|
60
69
|
hideLabelFromVision: hideLabelFromVision,
|
|
61
70
|
type: type,
|
|
62
|
-
prefix:
|
|
63
|
-
|
|
64
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
|
65
|
-
icon: icon
|
|
66
|
-
})
|
|
67
|
-
}) : undefined,
|
|
68
|
-
suffix: suffix ? /*#__PURE__*/_jsx(InputControlSuffixWrapper, {
|
|
69
|
-
variant: "control",
|
|
70
|
-
children: suffix
|
|
71
|
-
}) : undefined,
|
|
71
|
+
prefix: prefix,
|
|
72
|
+
suffix: suffix,
|
|
72
73
|
__next40pxDefaultSize: true
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["deepMerge","privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedInputControl","ValidatedText","data","field","onChange","hideLabelFromVision","type","prefix","suffix","label","placeholder","description","getValue","setValue","isValid","value","item","customValidity","setCustomValidity","undefined","onChangeControl","newValue","onValidateControl","message","custom","required","onValidate","help","__next40pxDefaultSize"],"sources":["@wordpress/dataviews/src/dataform-controls/utils/validated-input.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 { ValidatedInputControl } = unlock( privateApis );\n\nexport type DataFormValidatedTextControlProps< Item > =\n\tDataFormControlProps< Item > & {\n\t\t/**\n\t\t * The input type of the control.\n\t\t */\n\t\ttype?: 'text' | 'email' | 'tel' | 'url' | 'password';\n\t\t/**\n\t\t * Optional prefix element to display before the input.\n\t\t */\n\t\tprefix?: React.ReactElement;\n\t\t/**\n\t\t * Optional suffix element to display after the input.\n\t\t */\n\t\tsuffix?: React.ReactElement;\n\t};\n\nexport default function ValidatedText< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\ttype,\n\tprefix,\n\tsuffix,\n}: DataFormValidatedTextControlProps< Item > ) {\n\tconst { label, placeholder, description, getValue, setValue, isValid } =\n\t\tfield;\n\tconst value = getValue( { item: data } );\n\tconst [ customValidity, setCustomValidity ] =\n\t\tuseState<\n\t\t\tReact.ComponentProps<\n\t\t\t\ttypeof ValidatedInputControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange(\n\t\t\t\tsetValue( {\n\t\t\t\t\titem: data,\n\t\t\t\t\tvalue: newValue,\n\t\t\t\t} )\n\t\t\t),\n\t\t[ data, setValue, onChange ]\n\t);\n\n\tconst onValidateControl = useCallback(\n\t\t( newValue: any ) => {\n\t\t\tconst message = 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, isValid, setValue ]\n\t);\n\n\treturn (\n\t\t<ValidatedInputControl\n\t\t\trequired={ !! 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\thideLabelFromVision={ hideLabelFromVision }\n\t\t\ttype={ type }\n\t\t\tprefix={ prefix }\n\t\t\tsuffix={ suffix }\n\t\t\t__next40pxDefaultSize\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,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,MAAM;EAAEC;AAAsB,CAAC,GAAGH,MAAM,CAAEH,WAAY,CAAC;AAkBvD,eAAe,SAASO,aAAaA,CAAU;EAC9CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC,mBAAmB;EACnBC,IAAI;EACJC,MAAM;EACNC;AAC0C,CAAC,EAAG;EAC9C,MAAM;IAAEC,KAAK;IAAEC,WAAW;IAAEC,WAAW;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,GACrEX,KAAK;EACN,MAAMY,KAAK,GAAGH,QAAQ,CAAE;IAAEI,IAAI,EAAEd;EAAK,CAAE,CAAC;EACxC,MAAM,CAAEe,cAAc,EAAEC,iBAAiB,CAAE,GAC1CtB,QAAQ,CAILuB,SAAU,CAAC;EAEf,MAAMC,eAAe,GAAGzB,WAAW,CAChC0B,QAAgB,IACjBjB,QAAQ,CACPS,QAAQ,CAAE;IACTG,IAAI,EAAEd,IAAI;IACVa,KAAK,EAAEM;EACR,CAAE,CACH,CAAC,EACF,CAAEnB,IAAI,EAAEW,QAAQ,EAAET,QAAQ,CAC3B,CAAC;EAED,MAAMkB,iBAAiB,GAAG3B,WAAW,CAClC0B,QAAa,IAAM;IACpB,MAAME,OAAO,GAAGT,OAAO,EAAEU,MAAM,GAC9B/B,SAAS,CACRS,IAAI,EACJW,QAAQ,CAAE;MACTG,IAAI,EAAEd,IAAI;MACVa,KAAK,EAAEM;IACR,CAAE,CACH,CAAC,EACDlB,KACD,CAAC;IAED,IAAKoB,OAAO,EAAG;MACdL,iBAAiB,CAAE;QAClBZ,IAAI,EAAE,SAAS;QACfiB;MACD,CAAE,CAAC;MACH;IACD;IAEAL,iBAAiB,CAAEC,SAAU,CAAC;EAC/B,CAAC,EACD,CAAEjB,IAAI,EAAEC,KAAK,EAAEW,OAAO,EAAED,QAAQ,CACjC,CAAC;EAED,oBACCd,IAAA,CAACC,qBAAqB;IACrByB,QAAQ,EAAG,CAAC,CAAEX,OAAO,EAAEW,QAAU;IACjCC,UAAU,EAAGJ,iBAAmB;IAChCL,cAAc,EAAGA,cAAgB;IACjCR,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3BK,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBY,IAAI,EAAGhB,WAAa;IACpBP,QAAQ,EAAGgB,eAAiB;IAC5Bf,mBAAmB,EAAGA,mBAAqB;IAC3CC,IAAI,EAAGA,IAAM;IACbC,MAAM,EAAGA,MAAQ;IACjBC,MAAM,EAAGA,MAAQ;IACjBoB,qBAAqB;EAAA,CACrB,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deepMerge from 'deepmerge';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Flex, BaseControl, __experimentalNumberControl as NumberControl, privateApis } from '@wordpress/components';
|
|
10
|
+
import { useCallback, useState } from '@wordpress/element';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { OPERATOR_BETWEEN } from '../../constants';
|
|
17
|
+
import { unlock } from '../../lock-unlock';
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
const {
|
|
20
|
+
ValidatedNumberControl
|
|
21
|
+
} = unlock(privateApis);
|
|
22
|
+
function toNumberOrEmpty(value) {
|
|
23
|
+
if (value === '' || value === undefined) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
const number = Number(value);
|
|
27
|
+
return Number.isFinite(number) ? number : '';
|
|
28
|
+
}
|
|
29
|
+
function BetweenControls({
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
hideLabelFromVision,
|
|
33
|
+
step
|
|
34
|
+
}) {
|
|
35
|
+
const [min = '', max = ''] = value;
|
|
36
|
+
const onChangeMin = useCallback(newValue => onChange([toNumberOrEmpty(newValue), max]), [onChange, max]);
|
|
37
|
+
const onChangeMax = useCallback(newValue => onChange([min, toNumberOrEmpty(newValue)]), [onChange, min]);
|
|
38
|
+
return /*#__PURE__*/_jsx(BaseControl, {
|
|
39
|
+
__nextHasNoMarginBottom: true,
|
|
40
|
+
help: __('The max. value must be greater than the min. value.'),
|
|
41
|
+
children: /*#__PURE__*/_jsxs(Flex, {
|
|
42
|
+
direction: "row",
|
|
43
|
+
gap: 4,
|
|
44
|
+
children: [/*#__PURE__*/_jsx(NumberControl, {
|
|
45
|
+
label: __('Min.'),
|
|
46
|
+
value: min,
|
|
47
|
+
max: max ? Number(max) - step : undefined,
|
|
48
|
+
onChange: onChangeMin,
|
|
49
|
+
__next40pxDefaultSize: true,
|
|
50
|
+
hideLabelFromVision: hideLabelFromVision,
|
|
51
|
+
step: step
|
|
52
|
+
}), /*#__PURE__*/_jsx(NumberControl, {
|
|
53
|
+
label: __('Max.'),
|
|
54
|
+
value: max,
|
|
55
|
+
min: min ? Number(min) + step : undefined,
|
|
56
|
+
onChange: onChangeMax,
|
|
57
|
+
__next40pxDefaultSize: true,
|
|
58
|
+
hideLabelFromVision: hideLabelFromVision,
|
|
59
|
+
step: step
|
|
60
|
+
})]
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export default function ValidatedNumber({
|
|
65
|
+
data,
|
|
66
|
+
field,
|
|
67
|
+
onChange,
|
|
68
|
+
hideLabelFromVision,
|
|
69
|
+
operator,
|
|
70
|
+
decimals
|
|
71
|
+
}) {
|
|
72
|
+
var _getValue;
|
|
73
|
+
const step = Math.pow(10, Math.abs(decimals) * -1);
|
|
74
|
+
const {
|
|
75
|
+
label,
|
|
76
|
+
description,
|
|
77
|
+
getValue,
|
|
78
|
+
setValue
|
|
79
|
+
} = field;
|
|
80
|
+
const value = (_getValue = getValue({
|
|
81
|
+
item: data
|
|
82
|
+
})) !== null && _getValue !== void 0 ? _getValue : '';
|
|
83
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
84
|
+
const onChangeControl = useCallback(newValue => {
|
|
85
|
+
onChange(setValue({
|
|
86
|
+
item: data,
|
|
87
|
+
// Do not convert an empty string or undefined to a number,
|
|
88
|
+
// otherwise there's a mismatch between the UI control (empty)
|
|
89
|
+
// and the data relied by onChange (0).
|
|
90
|
+
value: ['', undefined].includes(newValue) ? undefined : Number(newValue)
|
|
91
|
+
}));
|
|
92
|
+
}, [data, onChange, setValue]);
|
|
93
|
+
const onChangeBetweenControls = useCallback(newValue => {
|
|
94
|
+
onChange(setValue({
|
|
95
|
+
item: data,
|
|
96
|
+
value: newValue
|
|
97
|
+
}));
|
|
98
|
+
}, [data, onChange, setValue]);
|
|
99
|
+
const onValidateControl = useCallback(newValue => {
|
|
100
|
+
const message = field.isValid?.custom?.(deepMerge(data, setValue({
|
|
101
|
+
item: data,
|
|
102
|
+
value: [undefined, '', null].includes(newValue) ? undefined : Number(newValue)
|
|
103
|
+
})), field);
|
|
104
|
+
if (message) {
|
|
105
|
+
setCustomValidity({
|
|
106
|
+
type: 'invalid',
|
|
107
|
+
message
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
setCustomValidity(undefined);
|
|
112
|
+
}, [data, field, setValue]);
|
|
113
|
+
if (operator === OPERATOR_BETWEEN) {
|
|
114
|
+
let valueBetween = ['', ''];
|
|
115
|
+
if (Array.isArray(value) && value.length === 2 && value.every(element => typeof element === 'number' || element === '')) {
|
|
116
|
+
valueBetween = value;
|
|
117
|
+
}
|
|
118
|
+
return /*#__PURE__*/_jsx(BetweenControls, {
|
|
119
|
+
value: valueBetween,
|
|
120
|
+
onChange: onChangeBetweenControls,
|
|
121
|
+
hideLabelFromVision: hideLabelFromVision,
|
|
122
|
+
step: step
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return /*#__PURE__*/_jsx(ValidatedNumberControl, {
|
|
126
|
+
required: !!field.isValid?.required,
|
|
127
|
+
onValidate: onValidateControl,
|
|
128
|
+
customValidity: customValidity,
|
|
129
|
+
label: label,
|
|
130
|
+
help: description,
|
|
131
|
+
value: value,
|
|
132
|
+
onChange: onChangeControl,
|
|
133
|
+
__next40pxDefaultSize: true,
|
|
134
|
+
hideLabelFromVision: hideLabelFromVision,
|
|
135
|
+
step: step
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=validated-number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["deepMerge","Flex","BaseControl","__experimentalNumberControl","NumberControl","privateApis","useCallback","useState","__","OPERATOR_BETWEEN","unlock","jsx","_jsx","jsxs","_jsxs","ValidatedNumberControl","toNumberOrEmpty","value","undefined","number","Number","isFinite","BetweenControls","onChange","hideLabelFromVision","step","min","max","onChangeMin","newValue","onChangeMax","__nextHasNoMarginBottom","help","children","direction","gap","label","__next40pxDefaultSize","ValidatedNumber","data","field","operator","decimals","_getValue","Math","pow","abs","description","getValue","setValue","item","customValidity","setCustomValidity","onChangeControl","includes","onChangeBetweenControls","onValidateControl","message","isValid","custom","type","valueBetween","Array","isArray","length","every","element","required","onValidate"],"sources":["@wordpress/dataviews/src/dataform-controls/utils/validated-number.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tFlex,\n\tBaseControl,\n\t__experimentalNumberControl as NumberControl,\n\tprivateApis,\n} from '@wordpress/components';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { OPERATOR_BETWEEN } from '../../constants';\nimport type { DataFormControlProps } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nconst { ValidatedNumberControl } = unlock( privateApis );\n\ntype NumberBetween = [ number | string, number | string ];\n\nfunction toNumberOrEmpty( value?: string ) {\n\tif ( value === '' || value === undefined ) {\n\t\treturn '';\n\t}\n\tconst number = Number( value );\n\treturn Number.isFinite( number ) ? number : '';\n}\n\nfunction BetweenControls( {\n\tvalue,\n\tonChange,\n\thideLabelFromVision,\n\tstep,\n}: {\n\tvalue: NumberBetween;\n\tonChange: ( [ min, max ]: NumberBetween ) => void;\n\thideLabelFromVision?: boolean;\n\tstep: number;\n} ) {\n\tconst [ min = '', max = '' ] = value;\n\n\tconst onChangeMin = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( [ toNumberOrEmpty( newValue ), max ] ),\n\t\t[ onChange, max ]\n\t);\n\n\tconst onChangeMax = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( [ min, toNumberOrEmpty( newValue ) ] ),\n\t\t[ onChange, min ]\n\t);\n\n\treturn (\n\t\t<BaseControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\thelp={ __( 'The max. value must be greater than the min. value.' ) }\n\t\t>\n\t\t\t<Flex direction=\"row\" gap={ 4 }>\n\t\t\t\t<NumberControl\n\t\t\t\t\tlabel={ __( 'Min.' ) }\n\t\t\t\t\tvalue={ min }\n\t\t\t\t\tmax={ max ? Number( max ) - step : undefined }\n\t\t\t\t\tonChange={ onChangeMin }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\t\tstep={ step }\n\t\t\t\t/>\n\t\t\t\t<NumberControl\n\t\t\t\t\tlabel={ __( 'Max.' ) }\n\t\t\t\t\tvalue={ max }\n\t\t\t\t\tmin={ min ? Number( min ) + step : undefined }\n\t\t\t\t\tonChange={ onChangeMax }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\t\tstep={ step }\n\t\t\t\t/>\n\t\t\t</Flex>\n\t\t</BaseControl>\n\t);\n}\n\nexport type DataFormValidatedNumberControlProps< Item > =\n\tDataFormControlProps< Item > & {\n\t\t/**\n\t\t * Number of decimals, acceps non-negative integer.\n\t\t */\n\t\tdecimals: number;\n\t};\n\nexport default function ValidatedNumber< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\toperator,\n\tdecimals,\n}: DataFormValidatedNumberControlProps< Item > ) {\n\tconst step = Math.pow( 10, Math.abs( decimals ) * -1 );\n\tconst { label, description, 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 ValidatedNumberControl\n\t\t\t>[ 'customValidity' ]\n\t\t>( undefined );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string | undefined ) => {\n\t\t\tonChange(\n\t\t\t\tsetValue( {\n\t\t\t\t\titem: data,\n\t\t\t\t\t// Do not convert an empty string or undefined to a number,\n\t\t\t\t\t// otherwise there's a mismatch between the UI control (empty)\n\t\t\t\t\t// and the data relied by onChange (0).\n\t\t\t\t\tvalue: [ '', undefined ].includes( newValue )\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: Number( newValue ),\n\t\t\t\t} )\n\t\t\t);\n\t\t},\n\t\t[ data, onChange, setValue ]\n\t);\n\n\tconst onChangeBetweenControls = useCallback(\n\t\t( newValue: NumberBetween ) => {\n\t\t\tonChange(\n\t\t\t\tsetValue( {\n\t\t\t\t\titem: data,\n\t\t\t\t\tvalue: newValue,\n\t\t\t\t} )\n\t\t\t);\n\t\t},\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: [ undefined, '', null ].includes( newValue )\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: Number( 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 ( operator === OPERATOR_BETWEEN ) {\n\t\tlet valueBetween: NumberBetween = [ '', '' ];\n\t\tif (\n\t\t\tArray.isArray( value ) &&\n\t\t\tvalue.length === 2 &&\n\t\t\tvalue.every(\n\t\t\t\t( element ) => typeof element === 'number' || element === ''\n\t\t\t)\n\t\t) {\n\t\t\tvalueBetween = value as NumberBetween;\n\t\t}\n\t\treturn (\n\t\t\t<BetweenControls\n\t\t\t\tvalue={ valueBetween }\n\t\t\t\tonChange={ onChangeBetweenControls }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\tstep={ step }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ValidatedNumberControl\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\thelp={ description }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\tstep={ step }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SACCC,IAAI,EACJC,WAAW,EACXC,2BAA2B,IAAIC,aAAa,EAC5CC,WAAW,QACL,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC1D,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,iBAAiB;AAElD,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE3C,MAAM;EAAEC;AAAuB,CAAC,GAAGL,MAAM,CAAEL,WAAY,CAAC;AAIxD,SAASW,eAAeA,CAAEC,KAAc,EAAG;EAC1C,IAAKA,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAKC,SAAS,EAAG;IAC1C,OAAO,EAAE;EACV;EACA,MAAMC,MAAM,GAAGC,MAAM,CAAEH,KAAM,CAAC;EAC9B,OAAOG,MAAM,CAACC,QAAQ,CAAEF,MAAO,CAAC,GAAGA,MAAM,GAAG,EAAE;AAC/C;AAEA,SAASG,eAAeA,CAAE;EACzBL,KAAK;EACLM,QAAQ;EACRC,mBAAmB;EACnBC;AAMD,CAAC,EAAG;EACH,MAAM,CAAEC,GAAG,GAAG,EAAE,EAAEC,GAAG,GAAG,EAAE,CAAE,GAAGV,KAAK;EAEpC,MAAMW,WAAW,GAAGtB,WAAW,CAC5BuB,QAA4B,IAC7BN,QAAQ,CAAE,CAAEP,eAAe,CAAEa,QAAS,CAAC,EAAEF,GAAG,CAAG,CAAC,EACjD,CAAEJ,QAAQ,EA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