@wordpress/dataviews 6.0.0 → 7.0.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 -1
- package/README.md +42 -14
- package/build/components/dataviews/index.js +38 -6
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +4 -1
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-item-actions/index.js +1 -10
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +1 -1
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +8 -5
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/components/dataviews-view-config/infinite-scroll-toggle.js +47 -0
- package/build/components/dataviews-view-config/infinite-scroll-toggle.js.map +1 -0
- package/build/dataform-controls/array.js +70 -0
- package/build/dataform-controls/array.js.map +1 -0
- package/build/dataform-controls/boolean.js +15 -7
- package/build/dataform-controls/boolean.js.map +1 -1
- package/build/dataform-controls/email.js +14 -7
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-controls/index.js +3 -1
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/integer.js +14 -7
- package/build/dataform-controls/integer.js.map +1 -1
- package/build/dataform-controls/text.js +14 -7
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataforms-layouts/card/index.js +137 -0
- package/build/dataforms-layouts/card/index.js.map +1 -0
- package/build/dataforms-layouts/data-form-layout.js +2 -2
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/index.js +4 -0
- package/build/dataforms-layouts/index.js.map +1 -1
- package/build/dataforms-layouts/panel/dropdown.js +124 -0
- package/build/dataforms-layouts/panel/dropdown.js.map +1 -0
- package/build/dataforms-layouts/panel/index.js +34 -149
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/panel/modal.js +125 -0
- package/build/dataforms-layouts/panel/modal.js.map +1 -0
- package/build/dataforms-layouts/regular/index.js +10 -21
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +24 -7
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/grid/preview-size-picker.js +11 -11
- package/build/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +45 -27
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +3 -0
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +23 -8
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/field-types/array.js +2 -2
- package/build/field-types/array.js.map +1 -1
- package/build/normalize-form-fields.js +52 -13
- package/build/normalize-form-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews/index.js +40 -8
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +4 -1
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-item-actions/index.js +1 -10
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +1 -1
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +8 -5
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.js +39 -0
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.js.map +1 -0
- package/build-module/dataform-controls/array.js +63 -0
- package/build-module/dataform-controls/array.js.map +1 -0
- package/build-module/dataform-controls/boolean.js +15 -7
- package/build-module/dataform-controls/boolean.js.map +1 -1
- package/build-module/dataform-controls/email.js +15 -8
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-controls/index.js +3 -1
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/integer.js +15 -8
- package/build-module/dataform-controls/integer.js.map +1 -1
- package/build-module/dataform-controls/text.js +15 -8
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataforms-layouts/card/index.js +128 -0
- package/build-module/dataforms-layouts/card/index.js.map +1 -0
- package/build-module/dataforms-layouts/data-form-layout.js +2 -2
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/index.js +4 -0
- package/build-module/dataforms-layouts/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/dropdown.js +118 -0
- package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -0
- package/build-module/dataforms-layouts/panel/index.js +37 -152
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/modal.js +119 -0
- package/build-module/dataforms-layouts/panel/modal.js.map +1 -0
- package/build-module/dataforms-layouts/regular/index.js +10 -21
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +25 -8
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/preview-size-picker.js +11 -11
- package/build-module/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +47 -29
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +3 -0
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +23 -8
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/field-types/array.js +2 -2
- package/build-module/field-types/array.js.map +1 -1
- package/build-module/normalize-form-fields.js +50 -13
- package/build-module/normalize-form-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +53 -16
- package/build-style/style.css +53 -16
- package/build-types/components/dataform/stories/index.story.d.ts +41 -17
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts +5 -2
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +2 -1
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +4 -1
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts +2 -0
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts.map +1 -0
- package/build-types/dataform-controls/array.d.ts +6 -0
- package/build-types/dataform-controls/array.d.ts.map +1 -0
- package/build-types/dataform-controls/boolean.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts.map +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/integer.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataforms-layouts/card/index.d.ts +13 -0
- package/build-types/dataforms-layouts/card/index.d.ts.map +1 -0
- package/build-types/dataforms-layouts/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/dropdown.d.ts +14 -0
- package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts +13 -0
- package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -0
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.d.ts +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/field-types/boolean.d.ts +1 -1
- package/build-types/normalize-form-fields.d.ts +10 -3
- package/build-types/normalize-form-fields.d.ts.map +1 -1
- package/build-types/test/normalize-form-fields.d.ts +2 -0
- package/build-types/test/normalize-form-fields.d.ts.map +1 -0
- package/build-types/types.d.ts +54 -6
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +3062 -1147
- package/package.json +15 -15
- package/src/components/dataform/stories/index.story.tsx +478 -91
- package/src/components/dataviews/index.tsx +50 -14
- package/src/components/dataviews/stories/fixtures.tsx +98 -7
- package/src/components/dataviews/stories/index.story.tsx +137 -4
- package/src/components/dataviews/style.scss +4 -0
- package/src/components/dataviews-context/index.ts +6 -2
- package/src/components/dataviews-item-actions/index.tsx +7 -16
- package/src/components/dataviews-pagination/index.tsx +1 -1
- package/src/components/dataviews-view-config/index.tsx +13 -5
- package/src/components/dataviews-view-config/infinite-scroll-toggle.tsx +39 -0
- package/src/dataform-controls/array.tsx +85 -0
- package/src/dataform-controls/boolean.tsx +24 -10
- package/src/dataform-controls/email.tsx +24 -11
- package/src/dataform-controls/index.tsx +3 -1
- package/src/dataform-controls/integer.tsx +27 -13
- package/src/dataform-controls/text.tsx +24 -11
- package/src/dataforms-layouts/card/index.tsx +154 -0
- package/src/dataforms-layouts/card/style.scss +3 -0
- package/src/dataforms-layouts/data-form-layout.tsx +2 -2
- package/src/dataforms-layouts/index.tsx +5 -0
- package/src/dataforms-layouts/panel/dropdown.tsx +160 -0
- package/src/dataforms-layouts/panel/index.tsx +49 -189
- package/src/dataforms-layouts/panel/modal.tsx +165 -0
- package/src/dataforms-layouts/panel/style.scss +4 -0
- package/src/dataforms-layouts/regular/index.tsx +20 -23
- package/src/dataviews-layouts/grid/index.tsx +32 -5
- package/src/dataviews-layouts/grid/preview-size-picker.tsx +15 -13
- package/src/dataviews-layouts/grid/style.scss +3 -1
- package/src/dataviews-layouts/list/index.tsx +65 -31
- package/src/dataviews-layouts/list/style.scss +7 -3
- package/src/dataviews-layouts/table/column-header-menu.tsx +4 -0
- package/src/dataviews-layouts/table/index.tsx +27 -1
- package/src/field-types/array.tsx +1 -1
- package/src/normalize-form-fields.ts +63 -17
- package/src/test/dataform.tsx +181 -3
- package/src/test/dataviews.tsx +38 -0
- package/src/test/filter-and-sort-data-view.js +123 -64
- package/src/test/normalize-form-fields.ts +247 -0
- package/src/types.ts +72 -6
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ToggleControl","__","useContext","DataViewsContext","jsx","_jsx","InfiniteScrollToggle","_view$infiniteScrollE","context","view","onChangeView","infiniteScrollEnabled","hasInfiniteScrollHandler","__nextHasNoMarginBottom","label","help","checked","onChange","newValue"],"sources":["@wordpress/dataviews/src/components/dataviews-view-config/infinite-scroll-toggle.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { ToggleControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\n\nexport default function InfiniteScrollToggle() {\n\tconst context = useContext( DataViewsContext );\n\tconst { view, onChangeView } = context;\n\tconst infiniteScrollEnabled = view.infiniteScrollEnabled ?? false;\n\n\t// Only render the toggle if an infinite scroll handler is available\n\tif ( ! context.hasInfiniteScrollHandler ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ToggleControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Enable infinite scroll' ) }\n\t\t\thelp={ __(\n\t\t\t\t'Automatically load more content as you scroll, instead of showing pagination links.'\n\t\t\t) }\n\t\t\tchecked={ infiniteScrollEnabled }\n\t\t\tonChange={ ( newValue ) => {\n\t\t\t\tonChangeView( {\n\t\t\t\t\t...view,\n\t\t\t\t\tinfiniteScrollEnabled: newValue,\n\t\t\t\t} );\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,uBAAuB;AACrD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,OAAOC,gBAAgB,MAAM,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEpD,eAAe,SAASC,oBAAoBA,CAAA,EAAG;EAAA,IAAAC,qBAAA;EAC9C,MAAMC,OAAO,GAAGN,UAAU,CAAEC,gBAAiB,CAAC;EAC9C,MAAM;IAAEM,IAAI;IAAEC;EAAa,CAAC,GAAGF,OAAO;EACtC,MAAMG,qBAAqB,IAAAJ,qBAAA,GAAGE,IAAI,CAACE,qBAAqB,cAAAJ,qBAAA,cAAAA,qBAAA,GAAI,KAAK;;EAEjE;EACA,IAAK,CAAEC,OAAO,CAACI,wBAAwB,EAAG;IACzC,OAAO,IAAI;EACZ;EAEA,oBACCP,IAAA,CAACL,aAAa;IACba,uBAAuB;IACvBC,KAAK,EAAGb,EAAE,CAAE,wBAAyB,CAAG;IACxCc,IAAI,EAAGd,EAAE,CACR,qFACD,CAAG;IACHe,OAAO,EAAGL,qBAAuB;IACjCM,QAAQ,EAAKC,QAAQ,IAAM;MAC1BR,YAAY,CAAE;QACb,GAAGD,IAAI;QACPE,qBAAqB,EAAEO;MACxB,CAAE,CAAC;IACJ;EAAG,CACH,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { FormTokenField } from '@wordpress/components';
|
|
5
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
export default function ArrayControl({
|
|
12
|
+
data,
|
|
13
|
+
field,
|
|
14
|
+
onChange,
|
|
15
|
+
hideLabelFromVision
|
|
16
|
+
}) {
|
|
17
|
+
var _elements$map;
|
|
18
|
+
const {
|
|
19
|
+
id,
|
|
20
|
+
label,
|
|
21
|
+
placeholder,
|
|
22
|
+
elements
|
|
23
|
+
} = field;
|
|
24
|
+
const value = field.getValue({
|
|
25
|
+
item: data
|
|
26
|
+
});
|
|
27
|
+
const findElementByValue = useCallback(suggestionValue => {
|
|
28
|
+
return elements?.find(suggestion => suggestion.value === suggestionValue);
|
|
29
|
+
}, [elements]);
|
|
30
|
+
const findElementByLabel = useCallback(suggestionLabel => {
|
|
31
|
+
return elements?.find(suggestion => suggestion.label === suggestionLabel);
|
|
32
|
+
}, [elements]);
|
|
33
|
+
|
|
34
|
+
// Ensure value is an array
|
|
35
|
+
const arrayValue = useMemo(() => Array.isArray(value) ? value.map(token => {
|
|
36
|
+
const tokenLabel = findElementByValue(token)?.label;
|
|
37
|
+
return tokenLabel || token;
|
|
38
|
+
}) : [], [value, findElementByValue]);
|
|
39
|
+
const onChangeControl = useCallback(tokens => {
|
|
40
|
+
// Convert TokenItem objects to strings
|
|
41
|
+
const stringTokens = tokens.map(token => {
|
|
42
|
+
if (typeof token !== 'string') {
|
|
43
|
+
return token.value;
|
|
44
|
+
}
|
|
45
|
+
const tokenByLabel = findElementByLabel(token);
|
|
46
|
+
return tokenByLabel?.value || token;
|
|
47
|
+
});
|
|
48
|
+
onChange({
|
|
49
|
+
[id]: stringTokens
|
|
50
|
+
});
|
|
51
|
+
}, [id, onChange, findElementByLabel]);
|
|
52
|
+
return /*#__PURE__*/_jsx(FormTokenField, {
|
|
53
|
+
label: hideLabelFromVision ? undefined : label,
|
|
54
|
+
value: arrayValue,
|
|
55
|
+
onChange: onChangeControl,
|
|
56
|
+
placeholder: placeholder,
|
|
57
|
+
suggestions: (_elements$map = elements?.map(suggestion => suggestion.label)) !== null && _elements$map !== void 0 ? _elements$map : [],
|
|
58
|
+
__experimentalExpandOnFocus: elements && elements.length > 0,
|
|
59
|
+
__next40pxDefaultSize: true,
|
|
60
|
+
__nextHasNoMarginBottom: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FormTokenField","useCallback","useMemo","jsx","_jsx","ArrayControl","data","field","onChange","hideLabelFromVision","_elements$map","id","label","placeholder","elements","value","getValue","item","findElementByValue","suggestionValue","find","suggestion","findElementByLabel","suggestionLabel","arrayValue","Array","isArray","map","token","tokenLabel","onChangeControl","tokens","stringTokens","tokenByLabel","undefined","suggestions","__experimentalExpandOnFocus","length","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/dataviews/src/dataform-controls/array.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { FormTokenField } from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../types';\n\nexport default function ArrayControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, placeholder, elements } = field;\n\tconst value = field.getValue( { item: data } );\n\n\tconst findElementByValue = useCallback(\n\t\t( suggestionValue: string ) => {\n\t\t\treturn elements?.find(\n\t\t\t\t( suggestion ) => suggestion.value === suggestionValue\n\t\t\t);\n\t\t},\n\t\t[ elements ]\n\t);\n\n\tconst findElementByLabel = useCallback(\n\t\t( suggestionLabel: string ) => {\n\t\t\treturn elements?.find(\n\t\t\t\t( suggestion ) => suggestion.label === suggestionLabel\n\t\t\t);\n\t\t},\n\t\t[ elements ]\n\t);\n\n\t// Ensure value is an array\n\tconst arrayValue = useMemo(\n\t\t() =>\n\t\t\tArray.isArray( value )\n\t\t\t\t? value.map( ( token ) => {\n\t\t\t\t\t\tconst tokenLabel = findElementByValue( token )?.label;\n\t\t\t\t\t\treturn tokenLabel || token;\n\t\t\t\t } )\n\t\t\t\t: [],\n\t\t[ value, findElementByValue ]\n\t);\n\n\tconst onChangeControl = useCallback(\n\t\t( tokens: ( string | { value: string } )[] ) => {\n\t\t\t// Convert TokenItem objects to strings\n\t\t\tconst stringTokens = tokens.map( ( token ) => {\n\t\t\t\tif ( typeof token !== 'string' ) {\n\t\t\t\t\treturn token.value;\n\t\t\t\t}\n\n\t\t\t\tconst tokenByLabel = findElementByLabel( token );\n\n\t\t\t\treturn tokenByLabel?.value || token;\n\t\t\t} );\n\n\t\t\tonChange( {\n\t\t\t\t[ id ]: stringTokens,\n\t\t\t} );\n\t\t},\n\t\t[ id, onChange, findElementByLabel ]\n\t);\n\n\treturn (\n\t\t<FormTokenField\n\t\t\tlabel={ hideLabelFromVision ? undefined : label }\n\t\t\tvalue={ arrayValue }\n\t\t\tonChange={ onChangeControl }\n\t\t\tplaceholder={ placeholder }\n\t\t\tsuggestions={\n\t\t\t\telements?.map( ( suggestion ) => suggestion.label ) ?? []\n\t\t\t}\n\t\t\t__experimentalExpandOnFocus={ elements && elements.length > 0 }\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,uBAAuB;AACtD,SAASC,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAKA,eAAe,SAASC,YAAYA,CAAU;EAC7CC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EAAA,IAAAC,aAAA;EACjC,MAAM;IAAEC,EAAE;IAAEC,KAAK;IAAEC,WAAW;IAAEC;EAAS,CAAC,GAAGP,KAAK;EAClD,MAAMQ,KAAK,GAAGR,KAAK,CAACS,QAAQ,CAAE;IAAEC,IAAI,EAAEX;EAAK,CAAE,CAAC;EAE9C,MAAMY,kBAAkB,GAAGjB,WAAW,CACnCkB,eAAuB,IAAM;IAC9B,OAAOL,QAAQ,EAAEM,IAAI,CAClBC,UAAU,IAAMA,UAAU,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AAzB,aAAA,GACVI,QAAQ,EAAEa,GAAG,CAAIN,UAAU,IAAMA,UAAU,CAACT,KAAM,CAAC,cAAAF,aAAA,cAAAA,aAAA,GAAI,EACvD;IACD0B,2BAA2B,EAAGtB,QAAQ,IAAIA,QAAQ,CAACuB,MAAM,GAAG,CAAG;IAC/DC,qBAAqB;IACrBC,uBAAuB;EAAA,CACvB,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { privateApis } from '@wordpress/components';
|
|
5
|
+
import { useState } from '@wordpress/element';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
@@ -23,17 +24,24 @@ export default function Boolean({
|
|
|
23
24
|
getValue,
|
|
24
25
|
label
|
|
25
26
|
} = field;
|
|
27
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
26
28
|
return /*#__PURE__*/_jsx(ValidatedToggleControl, {
|
|
27
29
|
required: !!field.isValid.required,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
onValidate: newValue => {
|
|
31
|
+
const message = field.isValid?.custom?.({
|
|
32
|
+
...data,
|
|
33
|
+
[id]: newValue
|
|
34
|
+
}, field);
|
|
35
|
+
if (message) {
|
|
36
|
+
setCustomValidity({
|
|
37
|
+
type: 'invalid',
|
|
38
|
+
message
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
34
41
|
}
|
|
35
|
-
|
|
42
|
+
setCustomValidity(undefined);
|
|
36
43
|
},
|
|
44
|
+
customValidity: customValidity,
|
|
37
45
|
hidden: hideLabelFromVision,
|
|
38
46
|
__nextHasNoMarginBottom: true,
|
|
39
47
|
label: label,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","unlock","jsx","_jsx","ValidatedToggleControl","Boolean","field","onChange","data","hideLabelFromVision","id","getValue","label","required","isValid","
|
|
1
|
+
{"version":3,"names":["privateApis","useState","unlock","jsx","_jsx","ValidatedToggleControl","Boolean","field","onChange","data","hideLabelFromVision","id","getValue","label","customValidity","setCustomValidity","undefined","required","isValid","onValidate","newValue","message","custom","type","hidden","__nextHasNoMarginBottom","checked","item"],"sources":["@wordpress/dataviews/src/dataform-controls/boolean.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { 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 Boolean< Item >( {\n\tfield,\n\tonChange,\n\tdata,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, getValue, label } = 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\treturn (\n\t\t<ValidatedToggleControl\n\t\t\trequired={ !! field.isValid.required }\n\t\t\tonValidate={ ( newValue: any ) => {\n\t\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\t\t{\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t[ id ]: newValue,\n\t\t\t\t\t},\n\t\t\t\t\tfield\n\t\t\t\t);\n\n\t\t\t\tif ( message ) {\n\t\t\t\t\tsetCustomValidity( {\n\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetCustomValidity( undefined );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\thidden={ hideLabelFromVision }\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ label }\n\t\t\tchecked={ getValue( { item: data } ) }\n\t\t\tonChange={ () =>\n\t\t\t\tonChange( { [ id ]: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AAI,EAAElB;MAAK,CAAE;IAAE,CAAE;EACnD,CACD,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { privateApis } from '@wordpress/components';
|
|
5
|
-
import { useCallback } from '@wordpress/element';
|
|
5
|
+
import { useCallback, useState } from '@wordpress/element';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
@@ -28,20 +28,27 @@ export default function Email({
|
|
|
28
28
|
const value = field.getValue({
|
|
29
29
|
item: data
|
|
30
30
|
});
|
|
31
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
31
32
|
const onChangeControl = useCallback(newValue => onChange({
|
|
32
33
|
[id]: newValue
|
|
33
34
|
}), [id, onChange]);
|
|
34
35
|
return /*#__PURE__*/_jsx(ValidatedTextControl, {
|
|
35
36
|
required: !!field.isValid?.required,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
onValidate: newValue => {
|
|
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;
|
|
42
48
|
}
|
|
43
|
-
|
|
49
|
+
setCustomValidity(undefined);
|
|
44
50
|
},
|
|
51
|
+
customValidity: customValidity,
|
|
45
52
|
type: "email",
|
|
46
53
|
label: label,
|
|
47
54
|
placeholder: placeholder,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","useCallback","unlock","jsx","_jsx","ValidatedTextControl","Email","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","onChangeControl","newValue","required","isValid","
|
|
1
|
+
{"version":3,"names":["privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedTextControl","Email","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","customValidity","setCustomValidity","undefined","onChangeControl","newValue","required","isValid","onValidate","message","custom","type","help","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/dataviews/src/dataform-controls/email.tsx"],"sourcesContent":["/**\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 { ValidatedTextControl } = unlock( privateApis );\n\nexport default function Email< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, placeholder, description } = 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 ValidatedTextControl\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\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<ValidatedTextControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tonValidate={ ( newValue: any ) => {\n\t\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\t\t{\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t[ id ]: newValue,\n\t\t\t\t\t},\n\t\t\t\t\tfield\n\t\t\t\t);\n\n\t\t\t\tif ( message ) {\n\t\t\t\t\tsetCustomValidity( {\n\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetCustomValidity( undefined );\n\t\t\t} }\n\t\t\tcustomValidity={ customValidity }\n\t\t\ttype=\"email\"\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\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,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;AAAqB,CAAC,GAAGH,MAAM,CAAEH,WAAY,CAAC;AAEtD,eAAe,SAASO,KAAKA,CAAU;EACtCC,IAAI;EACJC,KAAK;EACLC,QAAQ;EACRC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,EAAE;IAAEC,KAAK;IAAEC,WAAW;IAAEC;EAAY,CAAC,GAAGN,KAAK;EACrD,MAAMO,KAAK,GAAGP,KAAK,CAACQ,QAAQ,CAAE;IAAEC,IAAI,EAAEV;EAAK,CAAE,CAAC;EAC9C,MAAM,CAAEW,cAAc,EAAEC,iBAAiB,CAAE,GAC1ClB,QAAQ,CAILmB,SAAU,CAAC;EAEf,MAAMC,eAAe,GAAGrB,WAAW,CAChCsB,QAAgB,IACjBb,QAAQ,CAAE;IACT,CAAEE,EAAE,GAAIW;EACT,CAAE,CAAC,EACJ,CAAEX,EAAE,EAAEF,QAAQ,CACf,CAAC;EAED,oBACCL,IAAA,CAACC,oBAAoB;IACpBkB,QAAQ,EAAG,CAAC,CAAEf,KAAK,CAACgB,OAAO,EAAED,QAAU;IACvCE,UAAU,EAAKH,QAAa,IAAM;MACjC,MAAMI,OAAO,GAAGlB,KAAK,CAACgB,OAAO,EAAEG,MAAM,GACpC;QACC,GAAGpB,IAAI;QACP,CAAEI,EAAE,GAAIW;MACT,CAAC,EACDd,KACD,CAAC;MAED,IAAKkB,OAAO,EAAG;QACdP,iBAAiB,CAAE;UAClBS,IAAI,EAAE,SAAS;UACfF;QACD,CAAE,CAAC;QACH;MACD;MAEAP,iBAAiB,CAAEC,SAAU,CAAC;IAC/B,CAAG;IACHF,cAAc,EAAGA,cAAgB;IACjCU,IAAI,EAAC,OAAO;IACZhB,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3BE,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBc,IAAI,EAAGf,WAAa;IACpBL,QAAQ,EAAGY,eAAiB;IAC5BS,qBAAqB;IACrBC,uBAAuB;IACvBrB,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -16,7 +16,9 @@ import select from './select';
|
|
|
16
16
|
import text from './text';
|
|
17
17
|
import toggleGroup from './toggle-group';
|
|
18
18
|
import boolean from './boolean';
|
|
19
|
+
import array from './array';
|
|
19
20
|
const FORM_CONTROLS = {
|
|
21
|
+
array,
|
|
20
22
|
boolean,
|
|
21
23
|
checkbox,
|
|
22
24
|
datetime,
|
|
@@ -35,7 +37,7 @@ export function getControl(field, fieldTypeDefinition) {
|
|
|
35
37
|
if (typeof field.Edit === 'string') {
|
|
36
38
|
return getControlByType(field.Edit);
|
|
37
39
|
}
|
|
38
|
-
if (field.elements) {
|
|
40
|
+
if (field.elements && field.type !== 'array') {
|
|
39
41
|
return getControlByType('select');
|
|
40
42
|
}
|
|
41
43
|
if (typeof fieldTypeDefinition.Edit === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["checkbox","datetime","date","email","integer","radio","select","text","toggleGroup","boolean","FORM_CONTROLS","getControl","field","fieldTypeDefinition","Edit","getControlByType","elements","type","Object","keys","includes"],"sources":["@wordpress/dataviews/src/dataform-controls/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataFormControlProps,\n\tField,\n\tFieldTypeDefinition,\n} from '../types';\nimport checkbox from './checkbox';\nimport datetime from './datetime';\nimport date from './date';\nimport email from './email';\nimport integer from './integer';\nimport radio from './radio';\nimport select from './select';\nimport text from './text';\nimport toggleGroup from './toggle-group';\nimport boolean from './boolean';\n\ninterface FormControls {\n\t[ key: string ]: ComponentType< DataFormControlProps< any > >;\n}\n\nconst FORM_CONTROLS: FormControls = {\n\tboolean,\n\tcheckbox,\n\tdatetime,\n\tdate,\n\temail,\n\tinteger,\n\tradio,\n\tselect,\n\ttext,\n\ttoggleGroup,\n};\n\nexport function getControl< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n) {\n\tif ( typeof field.Edit === 'function' ) {\n\t\treturn field.Edit;\n\t}\n\n\tif ( typeof field.Edit === 'string' ) {\n\t\treturn getControlByType( field.Edit );\n\t}\n\n\tif ( field.elements ) {\n\t\treturn getControlByType( 'select' );\n\t}\n\n\tif ( typeof fieldTypeDefinition.Edit === 'string' ) {\n\t\treturn getControlByType( fieldTypeDefinition.Edit );\n\t}\n\n\treturn fieldTypeDefinition.Edit;\n}\n\nexport function getControlByType( type: string ) {\n\tif ( Object.keys( FORM_CONTROLS ).includes( type ) ) {\n\t\treturn FORM_CONTROLS[ type ];\n\t}\n\n\tthrow 'Control ' + type + ' not found';\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAMA,OAAOA,QAAQ,MAAM,YAAY;AACjC,OAAOC,QAAQ,MAAM,YAAY;AACjC,OAAOC,IAAI,MAAM,QAAQ;AACzB,OAAOC,KAAK,MAAM,SAAS;AAC3B,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAOC,KAAK,MAAM,SAAS;AAC3B,OAAOC,MAAM,MAAM,UAAU;AAC7B,OAAOC,IAAI,MAAM,QAAQ;AACzB,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,OAAO,MAAM,WAAW;
|
|
1
|
+
{"version":3,"names":["checkbox","datetime","date","email","integer","radio","select","text","toggleGroup","boolean","array","FORM_CONTROLS","getControl","field","fieldTypeDefinition","Edit","getControlByType","elements","type","Object","keys","includes"],"sources":["@wordpress/dataviews/src/dataform-controls/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataFormControlProps,\n\tField,\n\tFieldTypeDefinition,\n} from '../types';\nimport checkbox from './checkbox';\nimport datetime from './datetime';\nimport date from './date';\nimport email from './email';\nimport integer from './integer';\nimport radio from './radio';\nimport select from './select';\nimport text from './text';\nimport toggleGroup from './toggle-group';\nimport boolean from './boolean';\nimport array from './array';\n\ninterface FormControls {\n\t[ key: string ]: ComponentType< DataFormControlProps< any > >;\n}\n\nconst FORM_CONTROLS: FormControls = {\n\tarray,\n\tboolean,\n\tcheckbox,\n\tdatetime,\n\tdate,\n\temail,\n\tinteger,\n\tradio,\n\tselect,\n\ttext,\n\ttoggleGroup,\n};\n\nexport function getControl< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n) {\n\tif ( typeof field.Edit === 'function' ) {\n\t\treturn field.Edit;\n\t}\n\n\tif ( typeof field.Edit === 'string' ) {\n\t\treturn getControlByType( field.Edit );\n\t}\n\n\tif ( field.elements && field.type !== 'array' ) {\n\t\treturn getControlByType( 'select' );\n\t}\n\n\tif ( typeof fieldTypeDefinition.Edit === 'string' ) {\n\t\treturn getControlByType( fieldTypeDefinition.Edit );\n\t}\n\n\treturn fieldTypeDefinition.Edit;\n}\n\nexport function getControlByType( type: string ) {\n\tif ( Object.keys( FORM_CONTROLS ).includes( type ) ) {\n\t\treturn FORM_CONTROLS[ type ];\n\t}\n\n\tthrow 'Control ' + type + ' not found';\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAMA,OAAOA,QAAQ,MAAM,YAAY;AACjC,OAAOC,QA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GA,IAAI,GAAG,YAAY;AACvC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { Flex, BaseControl, __experimentalNumberControl as NumberControl, privateApis } from '@wordpress/components';
|
|
5
|
-
import { useCallback } from '@wordpress/element';
|
|
5
|
+
import { useCallback, useState } from '@wordpress/element';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -67,6 +67,7 @@ export default function Integer({
|
|
|
67
67
|
const value = (_field$getValue = field.getValue({
|
|
68
68
|
item: data
|
|
69
69
|
})) !== null && _field$getValue !== void 0 ? _field$getValue : '';
|
|
70
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
70
71
|
const onChangeControl = useCallback(newValue => {
|
|
71
72
|
onChange({
|
|
72
73
|
// Do not convert an empty string or undefined to a number,
|
|
@@ -85,15 +86,21 @@ export default function Integer({
|
|
|
85
86
|
}
|
|
86
87
|
return /*#__PURE__*/_jsx(ValidatedNumberControl, {
|
|
87
88
|
required: !!field.isValid?.required,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
onValidate: newValue => {
|
|
90
|
+
const message = field.isValid?.custom?.({
|
|
91
|
+
...data,
|
|
92
|
+
[id]: [undefined, '', null].includes(newValue) ? undefined : Number(newValue)
|
|
93
|
+
}, field);
|
|
94
|
+
if (message) {
|
|
95
|
+
setCustomValidity({
|
|
96
|
+
type: 'invalid',
|
|
97
|
+
message
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
94
100
|
}
|
|
95
|
-
|
|
101
|
+
setCustomValidity(undefined);
|
|
96
102
|
},
|
|
103
|
+
customValidity: customValidity,
|
|
97
104
|
label: label,
|
|
98
105
|
help: description,
|
|
99
106
|
value: value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Flex","BaseControl","__experimentalNumberControl","NumberControl","privateApis","useCallback","__","OPERATOR_BETWEEN","unlock","jsx","_jsx","jsxs","_jsxs","ValidatedNumberControl","BetweenControls","id","value","onChange","hideLabelFromVision","min","max","Array","isArray","onChangeMin","newValue","Number","onChangeMax","__nextHasNoMarginBottom","help","children","direction","gap","label","undefined","__next40pxDefaultSize","Integer","data","field","operator","_field$getValue","description","getValue","item","onChangeControl","includes","required","isValid","
|
|
1
|
+
{"version":3,"names":["Flex","BaseControl","__experimentalNumberControl","NumberControl","privateApis","useCallback","useState","__","OPERATOR_BETWEEN","unlock","jsx","_jsx","jsxs","_jsxs","ValidatedNumberControl","BetweenControls","id","value","onChange","hideLabelFromVision","min","max","Array","isArray","onChangeMin","newValue","Number","onChangeMax","__nextHasNoMarginBottom","help","children","direction","gap","label","undefined","__next40pxDefaultSize","Integer","data","field","operator","_field$getValue","description","getValue","item","customValidity","setCustomValidity","onChangeControl","includes","required","isValid","onValidate","message","custom","type"],"sources":["@wordpress/dataviews/src/dataform-controls/integer.tsx"],"sourcesContent":["/**\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\nfunction BetweenControls< Item >( {\n\tid,\n\tvalue,\n\tonChange,\n\thideLabelFromVision,\n}: {\n\tid: string;\n\tvalue: any;\n\tonChange: DataFormControlProps< Item >[ 'onChange' ];\n\thideLabelFromVision?: boolean;\n} ) {\n\tconst [ min = '', max = '' ] = Array.isArray( value ) ? value : [];\n\n\tconst onChangeMin = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: [ Number( newValue ), max ],\n\t\t\t} ),\n\t\t[ id, onChange, max ]\n\t);\n\n\tconst onChangeMax = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: [ min, Number( newValue ) ],\n\t\t\t} ),\n\t\t[ id, 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 ) - 1 : 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/>\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 ) + 1 : 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/>\n\t\t\t</Flex>\n\t\t</BaseControl>\n\t);\n}\n\nexport default function Integer< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\toperator,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, description } = 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 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\t// Do not convert an empty string or undefined to a number,\n\t\t\t\t// otherwise there's a mismatch between the UI control (empty)\n\t\t\t\t// and the data relied by onChange (0).\n\t\t\t\t[ id ]: [ '', undefined ].includes( newValue )\n\t\t\t\t\t? undefined\n\t\t\t\t\t: Number( newValue ),\n\t\t\t} );\n\t\t},\n\t\t[ id, onChange ]\n\t);\n\n\tif ( operator === OPERATOR_BETWEEN ) {\n\t\treturn (\n\t\t\t<BetweenControls\n\t\t\t\tid={ id }\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\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={ ( newValue: any ) => {\n\t\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\t\t{\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t[ id ]: [ 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},\n\t\t\t\t\tfield\n\t\t\t\t);\n\n\t\t\t\tif ( message ) {\n\t\t\t\t\tsetCustomValidity( {\n\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetCustomValidity( undefined );\n\t\t\t} }\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/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,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,cA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,EAAGA,QAAU;MACrBC,mBAAmB,EAAGA;IAAqB,CAC3C,CAAC;EAEJ;EAEA,oBACCR,IAAA,CAACG,sBAAsB;IACtBkC,QAAQ,EAAG,CAAC,CAAEV,KAAK,CAACW,OAAO,EAAED,QAAU;IACvCE,UAAU,EAAKzB,QAAa,IAAM;MACjC,MAAM0B,OAAO,GAAGb,KAAK,CAACW,OAAO,EAAEG,MAAM,GACpC;QACC,GAAGf,IAAI;QACP,CAAErB,EAAE,GAAI,CAAEkB,SAAS,EAAE,EAAE,EAAE,IAAI,CAAE,CAACa,QAAQ,CAAEtB,QAAS,CAAC,GACjDS,SAAS,GACTR,MAAM,CAAED,QAAS;MACrB,CAAC,EACDa,KACD,CAAC;MAED,IAAKa,OAAO,EAAG;QACdN,iBAAiB,CAAE;UAClBQ,IAAI,EAAE,SAAS;UACfF;QACD,CAAE,CAAC;QACH;MACD;MAEAN,iBAAiB,CAAEX,SAAU,CAAC;IAC/B,CAAG;IACHU,cAAc,EAAGA,cAAgB;IACjCX,KAAK,EAAGA,KAAO;IACfJ,IAAI,EAAGY,WAAa;IACpBxB,KAAK,EAAGA,KAAO;IACfC,QAAQ,EAAG4B,eAAiB;IAC5BX,qBAAqB;IACrBhB,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { privateApis } from '@wordpress/components';
|
|
5
|
-
import { useCallback } from '@wordpress/element';
|
|
5
|
+
import { useCallback, useState } from '@wordpress/element';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
@@ -28,20 +28,27 @@ export default function Text({
|
|
|
28
28
|
const value = field.getValue({
|
|
29
29
|
item: data
|
|
30
30
|
});
|
|
31
|
+
const [customValidity, setCustomValidity] = useState(undefined);
|
|
31
32
|
const onChangeControl = useCallback(newValue => onChange({
|
|
32
33
|
[id]: newValue
|
|
33
34
|
}), [id, onChange]);
|
|
34
35
|
return /*#__PURE__*/_jsx(ValidatedTextControl, {
|
|
35
36
|
required: !!field.isValid?.required,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
onValidate: newValue => {
|
|
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;
|
|
42
48
|
}
|
|
43
|
-
|
|
49
|
+
setCustomValidity(undefined);
|
|
44
50
|
},
|
|
51
|
+
customValidity: customValidity,
|
|
45
52
|
label: label,
|
|
46
53
|
placeholder: placeholder,
|
|
47
54
|
value: value !== null && value !== void 0 ? value : '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["privateApis","useCallback","unlock","jsx","_jsx","ValidatedTextControl","Text","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","onChangeControl","newValue","required","isValid","
|
|
1
|
+
{"version":3,"names":["privateApis","useCallback","useState","unlock","jsx","_jsx","ValidatedTextControl","Text","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","customValidity","setCustomValidity","undefined","onChangeControl","newValue","required","isValid","onValidate","message","custom","type","help","__next40pxDefaultSize","__nextHasNoMarginBottom"],"sources":["@wordpress/dataviews/src/dataform-controls/text.tsx"],"sourcesContent":["/**\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 { ValidatedTextControl } = unlock( privateApis );\n\nexport default function Text< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, placeholder, description } = 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 ValidatedTextControl\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\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<ValidatedTextControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tonValidate={ ( newValue: any ) => {\n\t\t\t\tconst message = field.isValid?.custom?.(\n\t\t\t\t\t{\n\t\t\t\t\t\t...data,\n\t\t\t\t\t\t[ id ]: newValue,\n\t\t\t\t\t},\n\t\t\t\t\tfield\n\t\t\t\t);\n\n\t\t\t\tif ( message ) {\n\t\t\t\t\tsetCustomValidity( {\n\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetCustomValidity( undefined );\n\t\t\t} }\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\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,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;AAAqB,CAAC,GAAGH,MAAM,CAAEH,WAAY,CAAC;AAEtD,eAAe,SAASO,I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
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* WordPress dependencies
|
|
7
|
+
*/
|
|
8
|
+
import { Button, Card, CardBody, CardHeader } from '@wordpress/components';
|
|
9
|
+
import { useCallback, useContext, useMemo, useState } from '@wordpress/element';
|
|
10
|
+
import { chevronDown, chevronUp } from '@wordpress/icons';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { getFormFieldLayout } from '..';
|
|
16
|
+
import DataFormContext from '../../components/dataform-context';
|
|
17
|
+
import { DataFormLayout } from '../data-form-layout';
|
|
18
|
+
import { isCombinedField } from '../is-combined-field';
|
|
19
|
+
import { DEFAULT_LAYOUT, normalizeLayout } from '../../normalize-form-fields';
|
|
20
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
export function useCollapsibleCard(initialIsOpen = true) {
|
|
22
|
+
const [isOpen, setIsOpen] = useState(initialIsOpen);
|
|
23
|
+
const toggle = useCallback(() => {
|
|
24
|
+
setIsOpen(prev => !prev);
|
|
25
|
+
}, []);
|
|
26
|
+
const CollapsibleCardHeader = useCallback(({
|
|
27
|
+
children,
|
|
28
|
+
...props
|
|
29
|
+
}) => /*#__PURE__*/_jsxs(CardHeader, {
|
|
30
|
+
...props,
|
|
31
|
+
onClick: toggle,
|
|
32
|
+
style: {
|
|
33
|
+
cursor: 'pointer',
|
|
34
|
+
...props.style
|
|
35
|
+
},
|
|
36
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
37
|
+
style: {
|
|
38
|
+
width: '100%',
|
|
39
|
+
display: 'flex',
|
|
40
|
+
justifyContent: 'space-between',
|
|
41
|
+
alignItems: 'center'
|
|
42
|
+
},
|
|
43
|
+
children: children
|
|
44
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
45
|
+
__next40pxDefaultSize: true,
|
|
46
|
+
variant: "tertiary",
|
|
47
|
+
icon: isOpen ? chevronUp : chevronDown,
|
|
48
|
+
"aria-expanded": isOpen,
|
|
49
|
+
"aria-label": isOpen ? 'Collapse' : 'Expand'
|
|
50
|
+
})]
|
|
51
|
+
}), [toggle, isOpen]);
|
|
52
|
+
return {
|
|
53
|
+
isOpen,
|
|
54
|
+
CollapsibleCardHeader
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export default function FormCardField({
|
|
58
|
+
data,
|
|
59
|
+
field,
|
|
60
|
+
onChange,
|
|
61
|
+
hideLabelFromVision
|
|
62
|
+
}) {
|
|
63
|
+
const {
|
|
64
|
+
fields
|
|
65
|
+
} = useContext(DataFormContext);
|
|
66
|
+
const layout = normalizeLayout({
|
|
67
|
+
...field.layout,
|
|
68
|
+
type: 'card'
|
|
69
|
+
});
|
|
70
|
+
const form = useMemo(() => ({
|
|
71
|
+
layout: DEFAULT_LAYOUT,
|
|
72
|
+
fields: isCombinedField(field) ? field.children : []
|
|
73
|
+
}), [field]);
|
|
74
|
+
const {
|
|
75
|
+
isOpen,
|
|
76
|
+
CollapsibleCardHeader
|
|
77
|
+
} = useCollapsibleCard(layout.isOpened);
|
|
78
|
+
if (isCombinedField(field)) {
|
|
79
|
+
const withHeader = !!field.label && layout.withHeader;
|
|
80
|
+
return /*#__PURE__*/_jsxs(Card, {
|
|
81
|
+
className: "dataforms-layouts-card__field",
|
|
82
|
+
children: [withHeader && /*#__PURE__*/_jsx(CollapsibleCardHeader, {
|
|
83
|
+
className: "dataforms-layouts-card__field-label",
|
|
84
|
+
children: field.label
|
|
85
|
+
}), (isOpen || !withHeader) &&
|
|
86
|
+
/*#__PURE__*/
|
|
87
|
+
// If it doesn't have a header, keep it open.
|
|
88
|
+
// Otherwise, the card will not be visible.
|
|
89
|
+
_jsx(CardBody, {
|
|
90
|
+
className: "dataforms-layouts-card__field-control",
|
|
91
|
+
children: /*#__PURE__*/_jsx(DataFormLayout, {
|
|
92
|
+
data: data,
|
|
93
|
+
form: form,
|
|
94
|
+
onChange: onChange
|
|
95
|
+
})
|
|
96
|
+
})]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const fieldDefinition = fields.find(fieldDef => fieldDef.id === field.id);
|
|
100
|
+
if (!fieldDefinition || !fieldDefinition.Edit) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const RegularLayout = getFormFieldLayout('regular')?.component;
|
|
104
|
+
if (!RegularLayout) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const withHeader = !!fieldDefinition.label && layout.withHeader;
|
|
108
|
+
return /*#__PURE__*/_jsxs(Card, {
|
|
109
|
+
className: "dataforms-layouts-card__field",
|
|
110
|
+
children: [withHeader && /*#__PURE__*/_jsx(CollapsibleCardHeader, {
|
|
111
|
+
className: "dataforms-layouts-card__field-label",
|
|
112
|
+
children: fieldDefinition.label
|
|
113
|
+
}), (isOpen || !withHeader) &&
|
|
114
|
+
/*#__PURE__*/
|
|
115
|
+
// If it doesn't have a header, keep it open.
|
|
116
|
+
// Otherwise, the card will not be visible.
|
|
117
|
+
_jsx(CardBody, {
|
|
118
|
+
className: "dataforms-layouts-card__field-control",
|
|
119
|
+
children: /*#__PURE__*/_jsx(RegularLayout, {
|
|
120
|
+
data: data,
|
|
121
|
+
field: field,
|
|
122
|
+
onChange: onChange,
|
|
123
|
+
hideLabelFromVision: hideLabelFromVision || withHeader
|
|
124
|
+
})
|
|
125
|
+
})]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Button","Card","CardBody","CardHeader","useCallback","useContext","useMemo","useState","chevronDown","chevronUp","getFormFieldLayout","DataFormContext","DataFormLayout","isCombinedField","DEFAULT_LAYOUT","normalizeLayout","jsx","_jsx","jsxs","_jsxs","useCollapsibleCard","initialIsOpen","isOpen","setIsOpen","toggle","prev","CollapsibleCardHeader","children","props","onClick","style","cursor","width","display","justifyContent","alignItems","__next40pxDefaultSize","variant","icon","FormCardField","data","field","onChange","hideLabelFromVision","fields","layout","type","form","isOpened","withHeader","label","className","fieldDefinition","find","fieldDef","id","Edit","RegularLayout","component"],"sources":["@wordpress/dataviews/src/dataforms-layouts/card/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n\n/**\n * WordPress dependencies\n */\nimport { Button, Card, CardBody, CardHeader } from '@wordpress/components';\nimport { useCallback, useContext, useMemo, useState } from '@wordpress/element';\nimport { chevronDown, chevronUp } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getFormFieldLayout } from '..';\nimport DataFormContext from '../../components/dataform-context';\nimport type { NormalizedCardLayout, FieldLayoutProps, Form } from '../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { isCombinedField } from '../is-combined-field';\nimport { DEFAULT_LAYOUT, normalizeLayout } from '../../normalize-form-fields';\n\nexport function useCollapsibleCard( initialIsOpen: boolean = true ) {\n\tconst [ isOpen, setIsOpen ] = useState( initialIsOpen );\n\n\tconst toggle = useCallback( () => {\n\t\tsetIsOpen( ( prev ) => ! prev );\n\t}, [] );\n\n\tconst CollapsibleCardHeader = useCallback(\n\t\t( {\n\t\t\tchildren,\n\t\t\t...props\n\t\t}: {\n\t\t\tchildren: React.ReactNode;\n\t\t\t[ key: string ]: any;\n\t\t} ) => (\n\t\t\t<CardHeader\n\t\t\t\t{ ...props }\n\t\t\t\tonClick={ toggle }\n\t\t\t\tstyle={ {\n\t\t\t\t\tcursor: 'pointer',\n\t\t\t\t\t...props.style,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\tjustifyContent: 'space-between',\n\t\t\t\t\t\talignItems: 'center',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ children }\n\t\t\t\t</div>\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\ticon={ isOpen ? chevronUp : chevronDown }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-label={ isOpen ? 'Collapse' : 'Expand' }\n\t\t\t\t/>\n\t\t\t</CardHeader>\n\t\t),\n\t\t[ toggle, isOpen ]\n\t);\n\n\treturn { isOpen, CollapsibleCardHeader };\n}\n\nexport default function FormCardField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: FieldLayoutProps< Item > ) {\n\tconst { fields } = useContext( DataFormContext );\n\n\tconst layout: NormalizedCardLayout = normalizeLayout( {\n\t\t...field.layout,\n\t\ttype: 'card',\n\t} ) as NormalizedCardLayout;\n\n\tconst form: Form = useMemo(\n\t\t(): Form => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: isCombinedField( field ) ? field.children : [],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\tconst { isOpen, CollapsibleCardHeader } = useCollapsibleCard(\n\t\tlayout.isOpened\n\t);\n\tif ( isCombinedField( field ) ) {\n\t\tconst withHeader = !! field.label && layout.withHeader;\n\t\treturn (\n\t\t\t<Card className=\"dataforms-layouts-card__field\">\n\t\t\t\t{ withHeader && (\n\t\t\t\t\t<CollapsibleCardHeader className=\"dataforms-layouts-card__field-label\">\n\t\t\t\t\t\t{ field.label }\n\t\t\t\t\t</CollapsibleCardHeader>\n\t\t\t\t) }\n\t\t\t\t{ ( isOpen || ! withHeader ) && (\n\t\t\t\t\t// If it doesn't have a header, keep it open.\n\t\t\t\t\t// Otherwise, the card will not be visible.\n\t\t\t\t\t<CardBody className=\"dataforms-layouts-card__field-control\">\n\t\t\t\t\t\t<DataFormLayout\n\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\tform={ form }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</CardBody>\n\t\t\t\t) }\n\t\t\t</Card>\n\t\t);\n\t}\n\n\tconst fieldDefinition = fields.find(\n\t\t( fieldDef ) => fieldDef.id === field.id\n\t);\n\n\tif ( ! fieldDefinition || ! fieldDefinition.Edit ) {\n\t\treturn null;\n\t}\n\n\tconst RegularLayout = getFormFieldLayout( 'regular' )?.component;\n\tif ( ! RegularLayout ) {\n\t\treturn null;\n\t}\n\tconst withHeader = !! fieldDefinition.label && layout.withHeader;\n\treturn (\n\t\t<Card className=\"dataforms-layouts-card__field\">\n\t\t\t{ withHeader && (\n\t\t\t\t<CollapsibleCardHeader className=\"dataforms-layouts-card__field-label\">\n\t\t\t\t\t{ fieldDefinition.label }\n\t\t\t\t</CollapsibleCardHeader>\n\t\t\t) }\n\t\t\t{ ( isOpen || ! withHeader ) && (\n\t\t\t\t// If it doesn't have a header, keep it open.\n\t\t\t\t// Otherwise, the card will not be visible.\n\t\t\t\t<CardBody className=\"dataforms-layouts-card__field-control\">\n\t\t\t\t\t<RegularLayout\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\thideLabelFromVision || withHeader\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</CardBody>\n\t\t\t) }\n\t\t</Card>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,uBAAuB;AAC1E,SAASC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AAC/E,SAASC,WAAW,EAAEC,SAAS,QAAQ,kBAAkB;;AAEzD;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,IAAI;AACvC,OAAOC,eAAe,MAAM,mCAAmC;AAE/D,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,eAAe,QAAQ,sBAAsB;AAC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ClD,OAAO,IAAI;EACZ;EAEA,MAAMC,aAAa,GAAG/C,kBAAkB,CAAE,SAAU,CAAC,EAAEgD,SAAS;EAChE,IAAK,CAAED,aAAa,EAAG;IACtB,OAAO,IAAI;EACZ;EACA,MAAMR,UAAU,GAAG,CAAC,CAAEG,eAAe,CAACF,KAAK,IAAIL,MAAM,CAACI,UAAU;EAChE,oBACC9B,KAAA,CAAClB,IAAI;IAACkD,SAAS,EAAC,+BAA+B;IAAAxB,QAAA,GAC5CsB,UAAU,iBACXhC,IAAA,CAACS,qBAAqB;MAACyB,SAAS,EAAC,qCAAqC;MAAAxB,QAAA,EACnEyB,eAAe,CAACF;IAAK,CACD,CACvB,EACC,CAAE5B,MAAM,IAAI,CAAE2B,UAAU;IAAA;IACzB;IACA;IACAhC,IAAA,CAACf,QAAQ;MAACiD,SAAS,EAAC,uCAAuC;MAAAxB,QAAA,eAC1DV,IAAA,CAACwC,aAAa;QACbjB,IAAI,EAAGA,IAAM;QACbC,KAAK,EAAGA,KAAO;QACfC,QAAQ,EAAGA,QAAU;QACrBC,mBAAmB,EAClBA,mBAAmB,IAAIM;MACvB,CACD;IAAC,CACO,CACV;EAAA,CACI,CAAC;AAET","ignoreList":[]}
|
|
@@ -28,9 +28,9 @@ export function DataFormLayout({
|
|
|
28
28
|
}
|
|
29
29
|
const normalizedFormFields = useMemo(() => normalizeFormFields(form), [form]);
|
|
30
30
|
return /*#__PURE__*/_jsx(VStack, {
|
|
31
|
-
spacing: form?.type === 'panel' ? 2 : 4,
|
|
31
|
+
spacing: form.layout?.type === 'panel' ? 2 : 4,
|
|
32
32
|
children: normalizedFormFields.map(formField => {
|
|
33
|
-
const FieldLayout = getFormFieldLayout(formField.layout)?.component;
|
|
33
|
+
const FieldLayout = getFormFieldLayout(formField.layout.type)?.component;
|
|
34
34
|
if (!FieldLayout) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__experimentalVStack","VStack","useContext","useMemo","getFormFieldLayout","DataFormContext","isCombinedField","normalizeFormFields","jsx","_jsx","DataFormLayout","data","form","onChange","children","fields","fieldDefinitions","getFieldDefinition","field","fieldId","id","find","fieldDefinition","normalizedFormFields","spacing","type","map","formField","FieldLayout","
|
|
1
|
+
{"version":3,"names":["__experimentalVStack","VStack","useContext","useMemo","getFormFieldLayout","DataFormContext","isCombinedField","normalizeFormFields","jsx","_jsx","DataFormLayout","data","form","onChange","children","fields","fieldDefinitions","getFieldDefinition","field","fieldId","id","find","fieldDefinition","normalizedFormFields","spacing","layout","type","map","formField","FieldLayout","component","undefined","isVisible"],"sources":["@wordpress/dataviews/src/dataforms-layouts/data-form-layout.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalVStack as VStack } from '@wordpress/components';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { Form, FormField, SimpleFormField } from '../types';\nimport { getFormFieldLayout } from './index';\nimport DataFormContext from '../components/dataform-context';\nimport { isCombinedField } from './is-combined-field';\nimport normalizeFormFields from '../normalize-form-fields';\n\nexport function DataFormLayout< Item >( {\n\tdata,\n\tform,\n\tonChange,\n\tchildren,\n}: {\n\tdata: Item;\n\tform: Form;\n\tonChange: ( value: any ) => void;\n\tchildren?: (\n\t\tFieldLayout: ( props: {\n\t\t\tdata: Item;\n\t\t\tfield: FormField;\n\t\t\tonChange: ( value: any ) => void;\n\t\t\thideLabelFromVision?: boolean;\n\t\t} ) => React.JSX.Element | null,\n\t\tfield: FormField\n\t) => React.JSX.Element;\n} ) {\n\tconst { fields: fieldDefinitions } = useContext( DataFormContext );\n\n\tfunction getFieldDefinition( field: SimpleFormField | string ) {\n\t\tconst fieldId = typeof field === 'string' ? field : field.id;\n\n\t\treturn fieldDefinitions.find(\n\t\t\t( fieldDefinition ) => fieldDefinition.id === fieldId\n\t\t);\n\t}\n\n\tconst normalizedFormFields = useMemo(\n\t\t() => normalizeFormFields( form ),\n\t\t[ form ]\n\t);\n\n\treturn (\n\t\t<VStack spacing={ form.layout?.type === 'panel' ? 2 : 4 }>\n\t\t\t{ normalizedFormFields.map( ( formField ) => {\n\t\t\t\tconst FieldLayout = getFormFieldLayout( formField.layout.type )\n\t\t\t\t\t?.component;\n\n\t\t\t\tif ( ! FieldLayout ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tconst fieldDefinition = ! isCombinedField( formField )\n\t\t\t\t\t? getFieldDefinition( formField )\n\t\t\t\t\t: undefined;\n\n\t\t\t\tif (\n\t\t\t\t\tfieldDefinition &&\n\t\t\t\t\tfieldDefinition.isVisible &&\n\t\t\t\t\t! fieldDefinition.isVisible( data )\n\t\t\t\t) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tif ( children ) {\n\t\t\t\t\treturn children( FieldLayout, formField );\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\tkey={ formField.id }\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tfield={ formField }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</VStack>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,oBAAoB,IAAIC,MAAM,QAAQ,uBAAuB;AACtE,SAASC,UAAU,EAAEC,OAAO,QAAQ,oBAAoB;;AAExD;AACA;AACA;;AAEA,SAASC,kBAAkB,QAAQ,SAAS;AAC5C,OAAOC,eAAe,MAAM,gCAAgC;AAC5D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,OAAOC,mBAAmB,MAAM,0BAA0B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3D,OAAO,SAASC,cAAcA,CAAU;EACvCC,IAAI;EACJC,IAAI;EACJC,QAAQ;EACRC;AAcD,CAAC,EAAG;EACH,MAAM;IAAEC,MAAM,EAAEC;EAAiB,CAAC,GAAGd,UAAU,CAAEG,eAAg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/
|
|
4
4
|
import FormRegularField from './regular';
|
|
5
5
|
import FormPanelField from './panel';
|
|
6
|
+
import FormCardField from './card';
|
|
6
7
|
const FORM_FIELD_LAYOUTS = [{
|
|
7
8
|
type: 'regular',
|
|
8
9
|
component: FormRegularField
|
|
9
10
|
}, {
|
|
10
11
|
type: 'panel',
|
|
11
12
|
component: FormPanelField
|
|
13
|
+
}, {
|
|
14
|
+
type: 'card',
|
|
15
|
+
component: FormCardField
|
|
12
16
|
}];
|
|
13
17
|
export function getFormFieldLayout(type) {
|
|
14
18
|
return FORM_FIELD_LAYOUTS.find(layout => layout.type === type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FormRegularField","FormPanelField","FORM_FIELD_LAYOUTS","type","component","getFormFieldLayout","find","layout"],"sources":["@wordpress/dataviews/src/dataforms-layouts/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport FormRegularField from './regular';\nimport FormPanelField from './panel';\n\nconst FORM_FIELD_LAYOUTS = [\n\t{\n\t\ttype: 'regular',\n\t\tcomponent: FormRegularField,\n\t},\n\t{\n\t\ttype: 'panel',\n\t\tcomponent: FormPanelField,\n\t},\n];\n\nexport function getFormFieldLayout( type: string ) {\n\treturn FORM_FIELD_LAYOUTS.find( ( layout ) => layout.type === type );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,WAAW;AACxC,OAAOC,cAAc,MAAM,SAAS;
|
|
1
|
+
{"version":3,"names":["FormRegularField","FormPanelField","FormCardField","FORM_FIELD_LAYOUTS","type","component","getFormFieldLayout","find","layout"],"sources":["@wordpress/dataviews/src/dataforms-layouts/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport FormRegularField from './regular';\nimport FormPanelField from './panel';\nimport FormCardField from './card';\n\nconst FORM_FIELD_LAYOUTS = [\n\t{\n\t\ttype: 'regular',\n\t\tcomponent: FormRegularField,\n\t},\n\t{\n\t\ttype: 'panel',\n\t\tcomponent: FormPanelField,\n\t},\n\t{\n\t\ttype: 'card',\n\t\tcomponent: FormCardField,\n\t},\n];\n\nexport function getFormFieldLayout( type: string ) {\n\treturn FORM_FIELD_LAYOUTS.find( ( layout ) => layout.type === type );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,WAAW;AACxC,OAAOC,cAAc,MAAM,SAAS;AACpC,OAAOC,aAAa,MAAM,QAAQ;AAElC,MAAMC,kBAAkB,GAAG,CAC1B;EACCC,IAAI,EAAE,SAAS;EACfC,SAAS,EAAEL;AACZ,CAAC,EACD;EACCI,IAAI,EAAE,OAAO;EACbC,SAAS,EAAEJ;AACZ,CAAC,EACD;EACCG,IAAI,EAAE,MAAM;EACZC,SAAS,EAAEH;AACZ,CAAC,CACD;AAED,OAAO,SAASI,kBAAkBA,CAAEF,IAAY,EAAG;EAClD,OAAOD,kBAAkB,CAACI,IAAI,CAAIC,MAAM,IAAMA,MAAM,CAACJ,IAAI,KAAKA,IAAK,CAAC;AACrE","ignoreList":[]}
|