@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_i18n","_constants","_lockUnlock","_jsxRuntime","ValidatedNumberControl","unlock","privateApis","BetweenControls","id","value","onChange","hideLabelFromVision","min","max","Array","isArray","onChangeMin","useCallback","newValue","Number","onChangeMax","jsx","BaseControl","__nextHasNoMarginBottom","help","__","children","jsxs","Flex","direction","gap","__experimentalNumberControl","label","undefined","__next40pxDefaultSize","Integer","data","field","operator","_field$getValue","description","getValue","item","onChangeControl","includes","OPERATOR_BETWEEN","required","isValid","
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_i18n","_constants","_lockUnlock","_jsxRuntime","ValidatedNumberControl","unlock","privateApis","BetweenControls","id","value","onChange","hideLabelFromVision","min","max","Array","isArray","onChangeMin","useCallback","newValue","Number","onChangeMax","jsx","BaseControl","__nextHasNoMarginBottom","help","__","children","jsxs","Flex","direction","gap","__experimentalNumberControl","label","undefined","__next40pxDefaultSize","Integer","data","field","operator","_field$getValue","description","getValue","item","customValidity","setCustomValidity","useState","onChangeControl","includes","OPERATOR_BETWEEN","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\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QAAQ,EAAGoC,eAAiB;IAC5BZ,qBAAqB;IACrBvB,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -34,20 +34,27 @@ function Text({
|
|
|
34
34
|
const value = field.getValue({
|
|
35
35
|
item: data
|
|
36
36
|
});
|
|
37
|
+
const [customValidity, setCustomValidity] = (0, _element.useState)(undefined);
|
|
37
38
|
const onChangeControl = (0, _element.useCallback)(newValue => onChange({
|
|
38
39
|
[id]: newValue
|
|
39
40
|
}), [id, onChange]);
|
|
40
41
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ValidatedTextControl, {
|
|
41
42
|
required: !!field.isValid?.required,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
onValidate: newValue => {
|
|
44
|
+
const message = field.isValid?.custom?.({
|
|
45
|
+
...data,
|
|
46
|
+
[id]: newValue
|
|
47
|
+
}, field);
|
|
48
|
+
if (message) {
|
|
49
|
+
setCustomValidity({
|
|
50
|
+
type: 'invalid',
|
|
51
|
+
message
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
48
54
|
}
|
|
49
|
-
|
|
55
|
+
setCustomValidity(undefined);
|
|
50
56
|
},
|
|
57
|
+
customValidity: customValidity,
|
|
51
58
|
label: label,
|
|
52
59
|
placeholder: placeholder,
|
|
53
60
|
value: value !== null && value !== void 0 ? value : '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_lockUnlock","_jsxRuntime","ValidatedTextControl","unlock","privateApis","Text","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","onChangeControl","useCallback","newValue","jsx","required","isValid","
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_lockUnlock","_jsxRuntime","ValidatedTextControl","unlock","privateApis","Text","data","field","onChange","hideLabelFromVision","id","label","placeholder","description","value","getValue","item","customValidity","setCustomValidity","useState","undefined","onChangeControl","useCallback","newValue","jsx","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\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UACfF;QACD,CAAE,CAAC;QACH;MACD;MAEAV,iBAAiB,CAAEE,SAAU,CAAC;IAC/B,CAAG;IACHH,cAAc,EAAGA,cAAgB;IACjCN,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3BE,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBiB,IAAI,EAAGlB,WAAa;IACpBL,QAAQ,EAAGa,eAAiB;IAC5BW,qBAAqB;IACrBC,uBAAuB;IACvBxB,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = FormCardField;
|
|
8
|
+
exports.useCollapsibleCard = useCollapsibleCard;
|
|
9
|
+
var _components = require("@wordpress/components");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
var _icons = require("@wordpress/icons");
|
|
12
|
+
var _ = require("..");
|
|
13
|
+
var _dataformContext = _interopRequireDefault(require("../../components/dataform-context"));
|
|
14
|
+
var _dataFormLayout = require("../data-form-layout");
|
|
15
|
+
var _isCombinedField = require("../is-combined-field");
|
|
16
|
+
var _normalizeFormFields = require("../../normalize-form-fields");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
/**
|
|
19
|
+
* External dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WordPress dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Internal dependencies
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function useCollapsibleCard(initialIsOpen = true) {
|
|
31
|
+
const [isOpen, setIsOpen] = (0, _element.useState)(initialIsOpen);
|
|
32
|
+
const toggle = (0, _element.useCallback)(() => {
|
|
33
|
+
setIsOpen(prev => !prev);
|
|
34
|
+
}, []);
|
|
35
|
+
const CollapsibleCardHeader = (0, _element.useCallback)(({
|
|
36
|
+
children,
|
|
37
|
+
...props
|
|
38
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.CardHeader, {
|
|
39
|
+
...props,
|
|
40
|
+
onClick: toggle,
|
|
41
|
+
style: {
|
|
42
|
+
cursor: 'pointer',
|
|
43
|
+
...props.style
|
|
44
|
+
},
|
|
45
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
46
|
+
style: {
|
|
47
|
+
width: '100%',
|
|
48
|
+
display: 'flex',
|
|
49
|
+
justifyContent: 'space-between',
|
|
50
|
+
alignItems: 'center'
|
|
51
|
+
},
|
|
52
|
+
children: children
|
|
53
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
54
|
+
__next40pxDefaultSize: true,
|
|
55
|
+
variant: "tertiary",
|
|
56
|
+
icon: isOpen ? _icons.chevronUp : _icons.chevronDown,
|
|
57
|
+
"aria-expanded": isOpen,
|
|
58
|
+
"aria-label": isOpen ? 'Collapse' : 'Expand'
|
|
59
|
+
})]
|
|
60
|
+
}), [toggle, isOpen]);
|
|
61
|
+
return {
|
|
62
|
+
isOpen,
|
|
63
|
+
CollapsibleCardHeader
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function FormCardField({
|
|
67
|
+
data,
|
|
68
|
+
field,
|
|
69
|
+
onChange,
|
|
70
|
+
hideLabelFromVision
|
|
71
|
+
}) {
|
|
72
|
+
const {
|
|
73
|
+
fields
|
|
74
|
+
} = (0, _element.useContext)(_dataformContext.default);
|
|
75
|
+
const layout = (0, _normalizeFormFields.normalizeLayout)({
|
|
76
|
+
...field.layout,
|
|
77
|
+
type: 'card'
|
|
78
|
+
});
|
|
79
|
+
const form = (0, _element.useMemo)(() => ({
|
|
80
|
+
layout: _normalizeFormFields.DEFAULT_LAYOUT,
|
|
81
|
+
fields: (0, _isCombinedField.isCombinedField)(field) ? field.children : []
|
|
82
|
+
}), [field]);
|
|
83
|
+
const {
|
|
84
|
+
isOpen,
|
|
85
|
+
CollapsibleCardHeader
|
|
86
|
+
} = useCollapsibleCard(layout.isOpened);
|
|
87
|
+
if ((0, _isCombinedField.isCombinedField)(field)) {
|
|
88
|
+
const withHeader = !!field.label && layout.withHeader;
|
|
89
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Card, {
|
|
90
|
+
className: "dataforms-layouts-card__field",
|
|
91
|
+
children: [withHeader && /*#__PURE__*/(0, _jsxRuntime.jsx)(CollapsibleCardHeader, {
|
|
92
|
+
className: "dataforms-layouts-card__field-label",
|
|
93
|
+
children: field.label
|
|
94
|
+
}), (isOpen || !withHeader) &&
|
|
95
|
+
/*#__PURE__*/
|
|
96
|
+
// If it doesn't have a header, keep it open.
|
|
97
|
+
// Otherwise, the card will not be visible.
|
|
98
|
+
(0, _jsxRuntime.jsx)(_components.CardBody, {
|
|
99
|
+
className: "dataforms-layouts-card__field-control",
|
|
100
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataFormLayout.DataFormLayout, {
|
|
101
|
+
data: data,
|
|
102
|
+
form: form,
|
|
103
|
+
onChange: onChange
|
|
104
|
+
})
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const fieldDefinition = fields.find(fieldDef => fieldDef.id === field.id);
|
|
109
|
+
if (!fieldDefinition || !fieldDefinition.Edit) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const RegularLayout = (0, _.getFormFieldLayout)('regular')?.component;
|
|
113
|
+
if (!RegularLayout) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const withHeader = !!fieldDefinition.label && layout.withHeader;
|
|
117
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Card, {
|
|
118
|
+
className: "dataforms-layouts-card__field",
|
|
119
|
+
children: [withHeader && /*#__PURE__*/(0, _jsxRuntime.jsx)(CollapsibleCardHeader, {
|
|
120
|
+
className: "dataforms-layouts-card__field-label",
|
|
121
|
+
children: fieldDefinition.label
|
|
122
|
+
}), (isOpen || !withHeader) &&
|
|
123
|
+
/*#__PURE__*/
|
|
124
|
+
// If it doesn't have a header, keep it open.
|
|
125
|
+
// Otherwise, the card will not be visible.
|
|
126
|
+
(0, _jsxRuntime.jsx)(_components.CardBody, {
|
|
127
|
+
className: "dataforms-layouts-card__field-control",
|
|
128
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RegularLayout, {
|
|
129
|
+
data: data,
|
|
130
|
+
field: field,
|
|
131
|
+
onChange: onChange,
|
|
132
|
+
hideLabelFromVision: hideLabelFromVision || withHeader
|
|
133
|
+
})
|
|
134
|
+
})]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_icons","_","_dataformContext","_interopRequireDefault","_dataFormLayout","_isCombinedField","_normalizeFormFields","_jsxRuntime","useCollapsibleCard","initialIsOpen","isOpen","setIsOpen","useState","toggle","useCallback","prev","CollapsibleCardHeader","children","props","jsxs","CardHeader","onClick","style","cursor","jsx","width","display","justifyContent","alignItems","Button","__next40pxDefaultSize","variant","icon","chevronUp","chevronDown","FormCardField","data","field","onChange","hideLabelFromVision","fields","useContext","DataFormContext","layout","normalizeLayout","type","form","useMemo","DEFAULT_LAYOUT","isCombinedField","isOpened","withHeader","label","Card","className","CardBody","DataFormLayout","fieldDefinition","find","fieldDef","id","Edit","RegularLayout","getFormFieldLayout","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":";;;;;;;;AAOA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAKA,IAAAG,CAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAEA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,gBAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AAA8E,IAAAS,WAAA,GAAAT,OAAA;AAnB9E;AACA;AACA;;AAEA;AACA;AACA;;AAKA;AACA;AACA;;AAQO,SAASU,kBAAkBA,CAAEC,aAAsB,GAAG,IAAI,EAAG;EACnE,MAAM,CAAEC,MAAM,EAAEC,SAAS,CAAE,GAAG,IAAAC,iBAAQ,EAAEH,aAAc,CAAC;EAEvD,MAAMI,MAAM,GAAG,IAAAC,oBAAW,EAAE,MAAM;IACjCH,SAAS,CAAII,IAAI,IAAM,CAAEA,IAAK,CAAC;EAChC,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMC,qBAAqB,GAAG,IAAAF,oBAA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UAAU,GAAG,CAAC,CAAEM,eAAe,CAACL,KAAK,IAAIT,MAAM,CAACQ,UAAU;EAChE,oBACC,IAAA5C,WAAA,CAAAY,IAAA,EAACtB,WAAA,CAAAwD,IAAI;IAACC,SAAS,EAAC,+BAA+B;IAAArC,QAAA,GAC5CkC,UAAU,iBACX,IAAA5C,WAAA,CAAAiB,GAAA,EAACR,qBAAqB;MAACsC,SAAS,EAAC,qCAAqC;MAAArC,QAAA,EACnEwC,eAAe,CAACL;IAAK,CACD,CACvB,EACC,CAAE1C,MAAM,IAAI,CAAEyC,UAAU;IAAA;IACzB;IACA;IACA,IAAA5C,WAAA,CAAAiB,GAAA,EAAC3B,WAAA,CAAA0D,QAAQ;MAACD,SAAS,EAAC,uCAAuC;MAAArC,QAAA,eAC1D,IAAAV,WAAA,CAAAiB,GAAA,EAACsC,aAAa;QACb1B,IAAI,EAAGA,IAAM;QACbC,KAAK,EAAGA,KAAO;QACfC,QAAQ,EAAGA,QAAU;QACrBC,mBAAmB,EAClBA,mBAAmB,IAAIY;MACvB,CACD;IAAC,CACO,CACV;EAAA,CACI,CAAC;AAET","ignoreList":[]}
|
|
@@ -35,9 +35,9 @@ function DataFormLayout({
|
|
|
35
35
|
}
|
|
36
36
|
const normalizedFormFields = (0, _element.useMemo)(() => (0, _normalizeFormFields.default)(form), [form]);
|
|
37
37
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
38
|
-
spacing: form?.type === 'panel' ? 2 : 4,
|
|
38
|
+
spacing: form.layout?.type === 'panel' ? 2 : 4,
|
|
39
39
|
children: normalizedFormFields.map(formField => {
|
|
40
|
-
const FieldLayout = (0, _index.getFormFieldLayout)(formField.layout)?.component;
|
|
40
|
+
const FieldLayout = (0, _index.getFormFieldLayout)(formField.layout.type)?.component;
|
|
41
41
|
if (!FieldLayout) {
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_index","_dataformContext","_interopRequireDefault","_isCombinedField","_normalizeFormFields","_jsxRuntime","DataFormLayout","data","form","onChange","children","fields","fieldDefinitions","useContext","DataFormContext","getFieldDefinition","field","fieldId","id","find","fieldDefinition","normalizedFormFields","useMemo","normalizeFormFields","jsx","__experimentalVStack","spacing","type","map","formField","FieldLayout","getFormFieldLayout","
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_index","_dataformContext","_interopRequireDefault","_isCombinedField","_normalizeFormFields","_jsxRuntime","DataFormLayout","data","form","onChange","children","fields","fieldDefinitions","useContext","DataFormContext","getFieldDefinition","field","fieldId","id","find","fieldDefinition","normalizedFormFields","useMemo","normalizeFormFields","jsx","__experimentalVStack","spacing","layout","type","map","formField","FieldLayout","getFormFieldLayout","component","isCombinedField","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":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AAA2D,IAAAO,WAAA,GAAAP,OAAA;AAb3D;AACA;AACA;;AAIA;AACA;AACA;;AAOO,SAASQ,cAAcA,CAAU;EACvCC,IAAI;EACJC,IAAI;EACJ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XxB,IAAI,EAAGA,IAAM;QACbS,KAAK,EAAGc,SAAW;QACnBrB,QAAQ,EAAGA;MAAU,GAHfqB,SAAS,CAACZ,EAIhB,CAAC;IAEJ,CAAE;EAAC,CACI,CAAC;AAEX","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.getFormFieldLayout = getFormFieldLayout;
|
|
8
8
|
var _regular = _interopRequireDefault(require("./regular"));
|
|
9
9
|
var _panel = _interopRequireDefault(require("./panel"));
|
|
10
|
+
var _card = _interopRequireDefault(require("./card"));
|
|
10
11
|
/**
|
|
11
12
|
* Internal dependencies
|
|
12
13
|
*/
|
|
@@ -17,6 +18,9 @@ const FORM_FIELD_LAYOUTS = [{
|
|
|
17
18
|
}, {
|
|
18
19
|
type: 'panel',
|
|
19
20
|
component: _panel.default
|
|
21
|
+
}, {
|
|
22
|
+
type: 'card',
|
|
23
|
+
component: _card.default
|
|
20
24
|
}];
|
|
21
25
|
function getFormFieldLayout(type) {
|
|
22
26
|
return FORM_FIELD_LAYOUTS.find(layout => layout.type === type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_regular","_interopRequireDefault","require","_panel","FORM_FIELD_LAYOUTS","type","component","FormRegularField","FormPanelField","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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_regular","_interopRequireDefault","require","_panel","_card","FORM_FIELD_LAYOUTS","type","component","FormRegularField","FormPanelField","FormCardField","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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AALA;AACA;AACA;;AAKA,MAAMG,kBAAkB,GAAG,CAC1B;EACCC,IAAI,EAAE,SAAS;EACfC,SAAS,EAAEC;AACZ,CAAC,EACD;EACCF,IAAI,EAAE,OAAO;EACbC,SAAS,EAAEE;AACZ,CAAC,EACD;EACCH,IAAI,EAAE,MAAM;EACZC,SAAS,EAAEG;AACZ,CAAC,CACD;AAEM,SAASC,kBAAkBA,CAAEL,IAAY,EAAG;EAClD,OAAOD,kBAAkB,CAACO,IAAI,CAAIC,MAAM,IAAMA,MAAM,CAACP,IAAI,KAAKA,IAAK,CAAC;AACrE","ignoreList":[]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _icons = require("@wordpress/icons");
|
|
11
|
+
var _dataFormLayout = require("../data-form-layout");
|
|
12
|
+
var _isCombinedField = require("../is-combined-field");
|
|
13
|
+
var _normalizeFormFields = require("../../normalize-form-fields");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
/**
|
|
16
|
+
* WordPress dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function DropdownHeader({
|
|
24
|
+
title,
|
|
25
|
+
onClose
|
|
26
|
+
}) {
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
28
|
+
className: "dataforms-layouts-panel__dropdown-header",
|
|
29
|
+
spacing: 4,
|
|
30
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
31
|
+
alignment: "center",
|
|
32
|
+
children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHeading, {
|
|
33
|
+
level: 2,
|
|
34
|
+
size: 13,
|
|
35
|
+
children: title
|
|
36
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalSpacer, {}), onClose && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
37
|
+
label: (0, _i18n.__)('Close'),
|
|
38
|
+
icon: _icons.closeSmall,
|
|
39
|
+
onClick: onClose,
|
|
40
|
+
size: "small"
|
|
41
|
+
})]
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function PanelDropdown({
|
|
46
|
+
fieldDefinition,
|
|
47
|
+
popoverAnchor,
|
|
48
|
+
labelPosition = 'side',
|
|
49
|
+
data,
|
|
50
|
+
onChange,
|
|
51
|
+
field
|
|
52
|
+
}) {
|
|
53
|
+
const fieldLabel = (0, _isCombinedField.isCombinedField)(field) ? field.label : fieldDefinition?.label;
|
|
54
|
+
const form = (0, _element.useMemo)(() => ({
|
|
55
|
+
layout: _normalizeFormFields.DEFAULT_LAYOUT,
|
|
56
|
+
fields: (0, _isCombinedField.isCombinedField)(field) ? field.children :
|
|
57
|
+
// If not explicit children return the field id itself.
|
|
58
|
+
[{
|
|
59
|
+
id: field.id
|
|
60
|
+
}]
|
|
61
|
+
}), [field]);
|
|
62
|
+
|
|
63
|
+
// Memoize popoverProps to avoid returning a new object every time.
|
|
64
|
+
const popoverProps = (0, _element.useMemo)(() => ({
|
|
65
|
+
// Anchor the popover to the middle of the entire row so that it doesn't
|
|
66
|
+
// move around when the label changes.
|
|
67
|
+
anchor: popoverAnchor,
|
|
68
|
+
placement: 'left-start',
|
|
69
|
+
offset: 36,
|
|
70
|
+
shift: true
|
|
71
|
+
}), [popoverAnchor]);
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, {
|
|
73
|
+
contentClassName: "dataforms-layouts-panel__field-dropdown",
|
|
74
|
+
popoverProps: popoverProps,
|
|
75
|
+
focusOnMount: true,
|
|
76
|
+
toggleProps: {
|
|
77
|
+
size: 'compact',
|
|
78
|
+
variant: 'tertiary',
|
|
79
|
+
tooltipPosition: 'middle left'
|
|
80
|
+
},
|
|
81
|
+
renderToggle: ({
|
|
82
|
+
isOpen,
|
|
83
|
+
onToggle
|
|
84
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
85
|
+
className: "dataforms-layouts-panel__field-control",
|
|
86
|
+
size: "compact",
|
|
87
|
+
variant: ['none', 'top'].includes(labelPosition) ? 'link' : 'tertiary',
|
|
88
|
+
"aria-expanded": isOpen,
|
|
89
|
+
"aria-label": (0, _i18n.sprintf)(
|
|
90
|
+
// translators: %s: Field name.
|
|
91
|
+
(0, _i18n._x)('Edit %s', 'field'), fieldLabel || ''),
|
|
92
|
+
onClick: onToggle,
|
|
93
|
+
disabled: fieldDefinition.readOnly === true,
|
|
94
|
+
accessibleWhenDisabled: true,
|
|
95
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(fieldDefinition.render, {
|
|
96
|
+
item: data,
|
|
97
|
+
field: fieldDefinition
|
|
98
|
+
})
|
|
99
|
+
}),
|
|
100
|
+
renderContent: ({
|
|
101
|
+
onClose
|
|
102
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
103
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownHeader, {
|
|
104
|
+
title: fieldLabel,
|
|
105
|
+
onClose: onClose
|
|
106
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataFormLayout.DataFormLayout, {
|
|
107
|
+
data: data,
|
|
108
|
+
form: form,
|
|
109
|
+
onChange: onChange,
|
|
110
|
+
children: (FieldLayout, nestedField) => {
|
|
111
|
+
var _form$fields;
|
|
112
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(FieldLayout, {
|
|
113
|
+
data: data,
|
|
114
|
+
field: nestedField,
|
|
115
|
+
onChange: onChange,
|
|
116
|
+
hideLabelFromVision: ((_form$fields = form?.fields) !== null && _form$fields !== void 0 ? _form$fields : []).length < 2
|
|
117
|
+
}, nestedField.id);
|
|
118
|
+
}
|
|
119
|
+
})]
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
var _default = exports.default = PanelDropdown;
|
|
124
|
+
//# sourceMappingURL=dropdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_element","_icons","_dataFormLayout","_isCombinedField","_normalizeFormFields","_jsxRuntime","DropdownHeader","title","onClose","jsx","__experimentalVStack","className","spacing","children","jsxs","__experimentalHStack","alignment","__experimentalHeading","level","size","__experimentalSpacer","Button","label","__","icon","closeSmall","onClick","PanelDropdown","fieldDefinition","popoverAnchor","labelPosition","data","onChange","field","fieldLabel","isCombinedField","form","useMemo","layout","DEFAULT_LAYOUT","fields","id","popoverProps","anchor","placement","offset","shift","Dropdown","contentClassName","focusOnMount","toggleProps","variant","tooltipPosition","renderToggle","isOpen","onToggle","includes","sprintf","_x","disabled","readOnly","accessibleWhenDisabled","render","item","renderContent","Fragment","DataFormLayout","FieldLayout","nestedField","_form$fields","hideLabelFromVision","length","_default","exports","default"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/dropdown.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\t__experimentalHeading as Heading,\n\t__experimentalSpacer as Spacer,\n\tDropdown,\n\tButton,\n} from '@wordpress/components';\nimport { sprintf, __, _x } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { Form, FormField, NormalizedField } from '../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { isCombinedField } from '../is-combined-field';\nimport { DEFAULT_LAYOUT } from '../../normalize-form-fields';\n\nfunction DropdownHeader( {\n\ttitle,\n\tonClose,\n}: {\n\ttitle?: string;\n\tonClose: () => void;\n} ) {\n\treturn (\n\t\t<VStack\n\t\t\tclassName=\"dataforms-layouts-panel__dropdown-header\"\n\t\t\tspacing={ 4 }\n\t\t>\n\t\t\t<HStack alignment=\"center\">\n\t\t\t\t{ title && (\n\t\t\t\t\t<Heading level={ 2 } size={ 13 }>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Heading>\n\t\t\t\t) }\n\t\t\t\t<Spacer />\n\t\t\t\t{ onClose && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</HStack>\n\t\t</VStack>\n\t);\n}\n\nfunction PanelDropdown< Item >( {\n\tfieldDefinition,\n\tpopoverAnchor,\n\tlabelPosition = 'side',\n\tdata,\n\tonChange,\n\tfield,\n}: {\n\tfieldDefinition: NormalizedField< Item >;\n\tpopoverAnchor: HTMLElement | null;\n\tlabelPosition: 'side' | 'top' | 'none';\n\tdata: Item;\n\tonChange: ( value: any ) => void;\n\tfield: FormField;\n} ) {\n\tconst fieldLabel = isCombinedField( field )\n\t\t? field.label\n\t\t: fieldDefinition?.label;\n\n\tconst form: Form = useMemo(\n\t\t(): Form => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: isCombinedField( field )\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t\tplacement: 'left-start',\n\t\t\toffset: 36,\n\t\t\tshift: true,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\n\treturn (\n\t\t<Dropdown\n\t\t\tcontentClassName=\"dataforms-layouts-panel__field-dropdown\"\n\t\t\tpopoverProps={ popoverProps }\n\t\t\tfocusOnMount\n\t\t\ttoggleProps={ {\n\t\t\t\tsize: 'compact',\n\t\t\t\tvariant: 'tertiary',\n\t\t\t\ttooltipPosition: 'middle left',\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"dataforms-layouts-panel__field-control\"\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant={\n\t\t\t\t\t\t[ 'none', 'top' ].includes( labelPosition )\n\t\t\t\t\t\t\t? 'link'\n\t\t\t\t\t\t\t: 'tertiary'\n\t\t\t\t\t}\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-label={ sprintf(\n\t\t\t\t\t\t// translators: %s: Field name.\n\t\t\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\t\t\tfieldLabel || ''\n\t\t\t\t\t) }\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t>\n\t\t\t\t\t<fieldDefinition.render\n\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\tfield={ fieldDefinition }\n\t\t\t\t\t/>\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<DropdownHeader title={ fieldLabel } onClose={ onClose } />\n\t\t\t\t\t<DataFormLayout\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tform={ form }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ( FieldLayout, nestedField ) => (\n\t\t\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\t\t\tkey={ nestedField.id }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tfield={ nestedField }\n\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</DataFormLayout>\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default PanelDropdown;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAQA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAMA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,gBA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